import {z} from 'zod' export type GetApiV1TeamsTeamIdLogsArgs = {teamId: string, limit?: number | undefined, cursor?: string | undefined, status?: string | undefined, modelId?: string | undefined, channelId?: string | undefined, startTime?: string | undefined, endTime?: string | undefined}; export type GetApiV1TeamsTeamIdLogsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const teamV1TeamUsageLogInfo = z.object({apiKeyId: z.string().optional(), billedMicros: z.string().optional(), completionTokens: z.string().optional(), createdAt: z.string().optional(), creatorName: z.string().optional(), currency: z.string().optional(), endpoint: z.string().optional(), errorCode: z.string().optional(), httpStatus: z.number().int().optional(), id: z.string().optional(), isStream: z.boolean().optional(), latencyMs: z.string().optional(), modelId: z.string().optional(), modelName: z.string().optional(), promptTokens: z.string().optional(), requestType: z.string().optional(), success: z.boolean().optional(), teamId: z.string().optional(), totalTokens: z.string().optional(), userId: z.string().optional()}); export const teamV1ListTeamLogsReply = z.object({hasMore: z.boolean().optional(), items: z.array(teamV1TeamUsageLogInfo).optional(), limit: z.number().int().optional(), nextCursor: z.string().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * ListTeamLogs 团队 owner 只读查看快照归属本团队的使用日志(按 team_id 快照过滤,含已移除成员历史)。 * * GET /v1/teams/{teamId}/logs */ export const getApiV1TeamsTeamIdLogs = async (args: GetApiV1TeamsTeamIdLogsArgs, options: GetApiV1TeamsTeamIdLogsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (args.status != null) query.append("status", String(args.status)) if (args.modelId != null) query.append("modelId", String(args.modelId)) if (args.channelId != null) query.append("channelId", String(args.channelId)) if (args.startTime != null) query.append("startTime", String(args.startTime)) if (args.endTime != null) query.append("endTime", String(args.endTime)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/teams/${encodeURIComponent(String(args.teamId))}/logs${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(teamV1ListTeamLogsReply, await res.json()) };