import {z} from 'zod' export type GetApiV1TasksTaskIdSubagentsLookupArgs = {taskId: string, toolCallId?: string | undefined, subagentId?: string | undefined}; export type GetApiV1TasksTaskIdSubagentsLookupOptions = {baseUrl?: string | undefined, personalApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getPublicSubagentResponseDto = z.object({subagent: z.object({subagentId: z.string(), taskId: z.string(), toolCallId: z.string().nullable(), workerName: z.string(), status: z.enum(["idle", "draft", "streaming", "awaiting_tool_result", "completed", "failed"]), stopCause: z.enum(["user", "parent", "parent_stopped"]).nullable(), active: z.boolean(), result: z.string().nullable(), error: z.string().nullable(), files: z.array(z.object({id: z.string(), name: z.string().nullable(), mediaType: z.string()})), createdAt: z.string(), updatedAt: z.string()}).nullable()}); 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 }; /** * Inspect an external task subagent * * GET /v1/tasks/{taskId}/subagents/lookup * * Also accepts auth: adamId */ export const getApiV1TasksTaskIdSubagentsLookup = async (args: GetApiV1TasksTaskIdSubagentsLookupArgs, options?: GetApiV1TasksTaskIdSubagentsLookupOptions) => { const {baseUrl = "https://api.adam.new", fetch: fetchFn = fetch, personalApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.toolCallId != null) query.append("toolCallId", String(args.toolCallId)) if (args.subagentId != null) query.append("subagentId", String(args.subagentId)) if (personalApiKey !== undefined) headers.set('authorization', `Bearer ${personalApiKey}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/tasks/${encodeURIComponent(String(args.taskId))}/subagents/lookup${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(getPublicSubagentResponseDto, await res.json()) };