import {z} from 'zod' export type RunExecutionConfig = {max_model_turns: number}; export type ApprovalPolicy = {approvers?: Array | undefined, approvers_by_tool?: {[key: string]: Array} | undefined, escalation_rules?: Array | undefined, requires_human_approval?: (boolean | null) | undefined}; export type ScopedSpendCapInput = {amount_usd: number | string, category?: ('llm' | 'tools' | null) | undefined, client_id?: (string | null) | undefined, connection_id?: (string | null) | undefined, currency?: (string | null) | undefined, own_agent?: boolean | undefined, period?: ('run' | null) | undefined, tool?: (string | null) | undefined}; export type BudgetPolicyInput = {agent_monthly_spend_cap_usd?: (number | string | null) | undefined, monthly_spend_cap_usd?: (number | string | null) | undefined, run_budget_usd?: (number | string | null) | undefined, service_budget_usd?: (number | string | null) | undefined, spend_caps?: (Array | null) | undefined}; export type AnswerCheckPolicy = {enabled?: boolean | undefined, language?: (string | null) | undefined, rewrite_instruction?: (string | null) | undefined}; export type ContentSafetyPolicy = {answer_check?: (AnswerCheckPolicy | null) | undefined, prompt_injection_detection_enabled?: (boolean | null) | undefined}; export type ExecutionLimitsPolicy = {max_model_turns?: (number | null) | undefined, max_tool_calls_per_turn?: (number | null) | undefined, max_tool_calls_total?: (number | null) | undefined}; export type TokenPolicy = {max_tokens?: (number | null) | undefined, max_tokens_per_call?: (number | null) | undefined}; export type ToolsPolicy = {allowed?: (Array | null) | undefined, denied?: Array | undefined}; export type PolicyDocument = {approval?: (ApprovalPolicy | null) | undefined, budget?: (BudgetPolicyInput | null) | undefined, content_safety?: (ContentSafetyPolicy | null) | undefined, execution?: (ExecutionLimitsPolicy | null) | undefined, tokens?: (TokenPolicy | null) | undefined, tools?: (ToolsPolicy | null) | undefined}; export type TaskWebhook = {secret?: (string | null) | undefined, url: string}; export type TaskCreate = {attachments?: (Array | null) | undefined, description: string, end_user_id?: (string | null) | undefined, execution?: (RunExecutionConfig | null) | undefined, metadata?: ({[key: string]: unknown} | null) | undefined, parameters?: {[key: string]: unknown} | undefined, project_id?: (string | null) | undefined, requires_human_approval?: (boolean | null) | undefined, task_policy?: (PolicyDocument | null) | undefined, webhook?: (TaskWebhook | null) | undefined}; export type CreateApiV1WorkspacesWorkspaceAgentsAgentIdTasksArgs = {agent_id: string, workspace: string, follow?: boolean | undefined, body: TaskCreate}; export type CreateApiV1WorkspacesWorkspaceAgentsAgentIdTasksOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1WorkspacesWorkspaceAgentsAgentIdTasksResponse = z.unknown(); 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 }; /** * Create Task For Agent With Stream * * POST /v1/workspaces/{workspace}/agents/{agent_id}/tasks/ */ export const createApiV1WorkspacesWorkspaceAgentsAgentIdTasks = async (args: CreateApiV1WorkspacesWorkspaceAgentsAgentIdTasksArgs, options: CreateApiV1WorkspacesWorkspaceAgentsAgentIdTasksOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.follow != null) query.append("follow", String(args.follow)) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/workspaces/${encodeURIComponent(String(args.workspace))}/agents/${encodeURIComponent(String(args.agent_id))}/tasks/${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiV1WorkspacesWorkspaceAgentsAgentIdTasksResponse, await res.json()) };