UNPKG

@adonis-agora/agent

Version:

Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.

64 lines • 3.28 kB
import type { MessageAttachment } from '../../../index.js'; import type { AttachmentUploadStrategy, UploadAttachmentOptions } from '../backend.js'; import { type AgentClientOptions } from '../client.js'; import { type AgentRequestError, type ErrorAnswer } from '../http-error.js'; /** Tuning for {@link mediaAttachments}; every field optional. */ export interface MediaAttachmentsOptions { /** Bytes per tus `PATCH`. Default 5 MiB. */ chunkSize?: number; /** Attempts per chunk before the upload fails. Default 3. */ retries?: number; } /** * Resumable attachment uploads through `@adonis-agora/media`, in one line: * * ```tsx * <AgentProvider attachments={{ upload: mediaAttachments() }}> * ``` * * Reuses the client's own connection (origin, path, headers, credentials), so it needs no * configuration. Also takes `new AgentClient({ attachments: { upload: mediaAttachments() } })`. */ export declare function mediaAttachments(options?: MediaAttachmentsOptions): AttachmentUploadStrategy; /** * Where and how {@link createMediaUpload} talks to the server. The connection fields are * {@link AgentClientOptions}' — pass the same ones your `AgentClient` gets, so the tus requests * carry the same cookies / CSRF header / bearer token as the rest of the chat. */ export interface MediaUploadOptions extends AgentClientOptions { /** Bytes per tus `PATCH`. Default 5 MiB (the default). */ chunkSize?: number; /** Attempts per chunk before the upload fails. Default 3. */ retries?: number; } /** What `useAttachments({ upload })` and `AgentBackend.uploadAttachment` both take. */ export type AttachmentUpload = (file: File, options?: UploadAttachmentOptions) => Promise<MessageAttachment>; /** * A non-2xx answer from the agent's upload routes. Carries what `AgentHttpError` does — `status` * (413 too large, 415 type refused, 404 not yours), the server's `message`, `code` and `body` — * as its own class because this subpath is bundled apart from the root entry, where an * `instanceof AgentHttpError` would not match a copy. Both satisfy `AgentRequestError`. */ export declare class MediaUploadError extends Error implements AgentRequestError { readonly status: number; readonly method: string; readonly path: string; readonly body: unknown; readonly code: string | undefined; constructor(status: number, method: string, path: string, statusText: string, answer?: ErrorAnswer); } /** * A resumable `upload` for `useAttachments`, backed by `@adonis-agora/media` on the server * (`MediaAttachmentStaging` from `@adonis-agora/agent/media`): * * 1. `POST <path>/attachments/uploads` — the agent validates the file and opens a tus session the * actor owns; * 2. the bytes stream to the media adapter’s own tus endpoint in chunks (`streamChunks`), reporting * progress and honouring the abort signal; * 3. `POST <path>/attachments/uploads/:mediaId/complete` — the agent confirms the bytes landed and * answers the `MessageAttachment` the turn will reference by `mediaId`. * * An aborted or failed upload is discarded server-side (`DELETE`), best effort. */ export declare function createMediaUpload(options?: MediaUploadOptions): AttachmentUpload; //# sourceMappingURL=index.d.ts.map