import {z} from 'zod' export type GetApiGoTenantsTenantIdAgentInstancesAgentInstanceIdLogsLogIdArgs = {tenantId: string, agentInstanceId: string, logId: string, detailsKey: string}; export type GetApiGoTenantsTenantIdAgentInstancesAgentInstanceIdLogsLogIdOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const packLogDetails = z.discriminatedUnion("type", [z.object({type: z.literal("fetcher"), request: z.string(), response: z.string().optional()}), z.object({type: z.literal("invocation"), result: z.object({stringVal: z.string(), int64Val: z.number(), doubleVal: z.number(), objectVal: z.string(), boolVal: z.boolean(), dateVal: z.number()}).optional(), resultDetail: z.string().optional(), continuationJson: z.string().optional(), completionJson: z.string().optional(), deletedItemIdsJson: z.string().optional(), permissionsContextJson: z.string().optional()}), z.object({type: z.literal("agentRuntime"), input: z.string().optional(), output: 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 }; /** * Retrieve the information for a specific log. * * GET /go/tenants/{tenantId}/agentInstances/{agentInstanceId}/logs/{logId} */ export const getApiGoTenantsTenantIdAgentInstancesAgentInstanceIdLogsLogId = async (args: GetApiGoTenantsTenantIdAgentInstancesAgentInstanceIdLogsLogIdArgs, options?: GetApiGoTenantsTenantIdAgentInstancesAgentInstanceIdLogsLogIdOptions) => { const {baseUrl = "https://docs.superhuman.com/apis/v1", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.detailsKey != null) query.append("detailsKey", String(args.detailsKey)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/go/tenants/${encodeURIComponent(String(args.tenantId))}/agentInstances/${encodeURIComponent(String(args.agentInstanceId))}/logs/${encodeURIComponent(String(args.logId))}${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(packLogDetails, await res.json()) };