import {z} from 'zod' export type GetApiV1AssistantsAgentIdRevisionsRevisionIdEffectiveToolSurfaceArgs = {agent_id: string, revision_id: string}; export type GetApiV1AssistantsAgentIdRevisionsRevisionIdEffectiveToolSurfaceOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const utilityCatalogEntry = z.object({name: z.string(), canonical_key: z.string(), display_name: z.string().nullable().optional(), description: z.string().optional(), parameters: z.record(z.string(), z.unknown()).optional()}); export const effectiveToolSurfaceEntry = z.object({name: z.string(), canonical_key: z.string().nullable().optional(), display_name: z.string().nullable().optional(), mentionable: z.boolean().optional(), description: z.string().optional(), parameters: z.record(z.string(), z.unknown()).optional(), provenance: z.enum(["util", "platform", "ambient", "node", "runtime"]), locked: z.boolean(), dynamic: z.boolean().optional(), selection_sources: z.array(z.enum(["assistant_mention", "node_mention", "node_attachment"])).optional()}); export const effectiveNodeToolSurface = z.object({node_id: z.string(), tools: z.array(effectiveToolSurfaceEntry).optional()}); export const effectiveToolSurfaceResponse = z.object({revision_id: z.string(), workflow_revision_id: z.string().nullable().optional(), graph_version: z.number().int().optional(), utility_catalog: z.array(utilityCatalogEntry).optional(), assistant_tools: z.array(effectiveToolSurfaceEntry).optional(), nodes: z.array(effectiveNodeToolSurface).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 }; /** * Resolve inherited and node-local tools for a revision's flow * * GET /v1/assistants/{agent_id}/revisions/{revision_id}/effective-tool-surface */ export const getApiV1AssistantsAgentIdRevisionsRevisionIdEffectiveToolSurface = async (args: GetApiV1AssistantsAgentIdRevisionsRevisionIdEffectiveToolSurfaceArgs, options: GetApiV1AssistantsAgentIdRevisionsRevisionIdEffectiveToolSurfaceOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (APIKeyHeader !== undefined) headers.set("x-api-key", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/v1/assistants/${encodeURIComponent(String(args.agent_id))}/revisions/${encodeURIComponent(String(args.revision_id))}/effective-tool-surface${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(effectiveToolSurfaceResponse, await res.json()) };