/** * EmployeesClient — the unified namespace for chatflows and agentflows. * * Single source of truth for the SDK's task-execution surface. All seven * v1 methods route through TorukClient's ResourceClientContext, which * handles auth, headers, response wrapping, and JWT refresh. * * Every method targets the deployment runtime plane * (/api/v1/deployments/:deploymentId/*); the SDK client only ever knows a * deploymentId and never constructs chatflow-scoped legacy URLs. */ import type { ResourceClientContext } from '../client/toruk-client'; import type { TorukApiResponse } from '../types/api-response'; import type { EmployeeExecuteInput, EmployeeExecuteResult, EmployeeStreamInput, EmployeeConfig, StreamAvailability, EmployeeFeedbackInput, EmployeeAttachInput, EmployeeUpdateFeedbackInput, EmployeeCreateLeadInput, EmployeeDownloadUploadInput, EmployeeSpeechInput, EmployeeAbortInput, EmployeeTranscribeInput } from './employees.types'; export declare class EmployeesClient { private readonly ctx; /** Client-level default used when a call doesn't name a deployment. */ private readonly defaultDeploymentId?; private predictWarned; constructor(ctx: ResourceClientContext, /** Client-level default used when a call doesn't name a deployment. */ defaultDeploymentId?: string | undefined); private runtimePath; /** Validated before any request so a missing id can never reach the URL. */ private resolveId; /** * Execute a task (chatflow or agentflow) without streaming. * Maps to POST /api/v1/deployments/:deploymentId/predictions. */ execute(input: EmployeeExecuteInput): Promise>; /** * @deprecated Use `execute()` — `predict()` is preserved as an alias * for one minor cycle and will be removed in the next major release. */ predict(input: EmployeeExecuteInput): Promise>; /** * Stream a task's response token-by-token. Same endpoint as execute() * (POST /api/v1/prediction/:id) but with `streaming: true` on the wire, * which causes TORUK-CORE to respond with text/event-stream. * * Pass per-event callbacks in the input. Resolves with the final * { chatId, messageId } once 'end' fires, or rejects with TorukSdkError * on structural failure (network, abort, malformed response). * * Silent non-streaming fallback: if the task's underlying chatflow has * isStreaming !== true, TORUK-CORE returns a regular JSON response. * The stream-runner detects this and synthesizes onStart + onToken + * onDone so consumer callbacks fire normally. * * v1 limitation: JWT refresh on 401 is NOT auto-retried for streams. * Pre-refresh before calling stream() or handle the error in onError. */ stream(input: EmployeeStreamInput): Promise<{ chatId?: string; messageId?: string; }>; /** * Fetch the public chatbot config for a task. * Maps to GET /api/v1/deployments/:deploymentId/config. */ getConfig(deploymentId?: string, options?: { signal?: AbortSignal; headers?: Record; }): Promise>; /** * Check whether a task supports streaming, read from the deployment * config. Maps to GET /api/v1/deployments/:deploymentId/config. */ isStreamAvailable(deploymentId?: string, options?: { signal?: AbortSignal; headers?: Record; }): Promise>; /** * Submit feedback (THUMBS_UP/THUMBS_DOWN + optional content) for a * specific message in a chat session. * Maps to POST /api/v1/deployments/:deploymentId/feedback (JSON body). * * Core envelopes this route, so the response is unwrapped to the persisted * feedback record — callers need `data.id` to send the follow-up comment. */ feedback(input: EmployeeFeedbackInput): Promise>; /** * Attach one or more files to a chat session (multipart/form-data). * Maps to POST /api/v1/deployments/:deploymentId/attachments/:chatId. * * Pass File-like Blobs (browser File objects work directly). Each * Blob's `name` property is used as the field filename if present; * the optional `filenames` array overrides per-position if you need * explicit names (e.g. when passing raw Blobs from Node). * * Core envelopes this route, so the response is unwrapped to the extracted * file array — returning the envelope made `data` non-iterable for callers. */ attach(input: EmployeeAttachInput & { filenames?: string[]; }): Promise>; /** * Attach free-text content to feedback already created. * Maps to PUT /api/v1/deployments/:deploymentId/feedback/:feedbackId. * * `feedbackId` comes from the `feedback()` response — which is why that call * unwraps CORE's envelope. Enveloped like `feedback()`, so unwrapped here too. */ updateFeedback(input: EmployeeUpdateFeedbackInput): Promise>; /** * Record a lead-capture submission. * Maps to POST /api/v1/deployments/:deploymentId/leads. */ createLead(input: EmployeeCreateLeadInput): Promise>; /** * Download a file the deployment stored during a conversation, as a Blob. * Maps to GET /api/v1/deployments/:deploymentId/uploads?chatId&fileName. * * Returns the raw Response rather than an envelope: the body is binary, and * `parseResponse` would consume it as text. Callers read `.blob()`. * * Prefer this over rendering the URL into ``: a URL carries no headers, * so it cannot present the visitor identity, and a private deployment will * reject it. */ downloadUpload(input: EmployeeDownloadUploadInput): Promise; /** * Synthesize speech for a message. * Maps to POST /api/v1/deployments/:deploymentId/tts. * * CORE answers with one buffered JSON envelope carrying base64 for the whole * clip — there is no chunked audio protocol. Text over * `capabilities.textToSpeech.maxInputChars` is rejected with 400 rather than * truncated, and a disabled feature (`TTS.NOT_CONFIGURED`) is reported * distinctly from a provider outage (`TTS.SYNTHESIS_FAILED`) so a client can * tell "hide the control" from "offer a retry". */ generateSpeech(input: EmployeeSpeechInput): Promise>; /** * Transcribe a recorded voice clip to text. * Maps to POST /api/v1/deployments/:deploymentId/transcribe. * * Returns the transcript so you can put it in your input box for the user to * review and correct before sending. The clip is transcribed and discarded — it * never becomes a chat message. * * This is a different flow from sending audio as an `uploads[]` entry on * `execute` / `stream`. That also transcribes, but it runs the flow in the same * call and persists the clip as the user's message, so the user never sees what * was heard. Check `capabilities.speechToText.via` to know which the deployment * prefers: `'transcribe-endpoint'` means this method. */ transcribe(input: EmployeeTranscribeInput): Promise>; /** * Cancel an in-flight prediction on this deployment. * Maps to POST /api/v1/deployments/:deploymentId/abort. * * Only `chatId` is sent; CORE resolves the chatflow half of the abort key from * the deployment, so a caller cannot cancel a run on a flow their deployment * does not point at. Without this a cancelled conversation kept generating — * and kept billing — to completion. */ abort(input: EmployeeAbortInput): Promise>; /** * Vector upsert is a management-plane operation and has no deployment * runtime endpoint, so it is not available from this client. */ vectorUpsert(): Promise>; } export type RawExecutionResponse = { chatId: string; text?: string; chatMessageId?: string; sourceDocuments?: unknown[]; usedTools?: unknown[]; agentReasoning?: unknown; [key: string]: unknown; }; /** * Rename chatMessageId → messageId at the SDK boundary (§10.4 mapping). * Other engine-passthrough fields preserved verbatim. */ export declare function mapExecuteResult(envelope: TorukApiResponse): TorukApiResponse; /** Response shape from POST /api/v1/feedback/:id. TORUK-CORE returns the persisted feedback record. */ export type FeedbackResult = { id?: string; [key: string]: unknown; }; /** Response shape from POST /api/v1/attachments/:id/:chatId. */ export type AttachResult = Record | unknown[]; /** Persisted lead record. */ export type LeadResult = { id?: string; [key: string]: unknown; }; /** Buffered speech: `data` is base64 for the whole clip, with no data-URI prefix. */ export type SpeechResult = { data: string; contentType: string; }; /** What `POST …/transcribe` returns. */ export type TranscriptionResult = { text: string; }; export type AbortResult = { aborted?: boolean; [key: string]: unknown; }; /** Response shape from POST /api/v1/vector/upsert/:id. */ export type VectorUpsertResult = { numAdded?: number; numUpdated?: number; numSkipped?: number; numDeleted?: number; [key: string]: unknown; };