/** * TorukClient — top-level SDK entry. * * Composes RequestClient + auth + response parsing into a single client * instance that resource clients (employees.*) consume. */ import type { TorukClientConfig } from '../types/common'; import type { TorukApiResponse } from '../types/api-response'; import type { DeploymentCapabilities } from '../types/capabilities'; import { RequestClient, type RequestOptions } from './request-client'; import { EmployeesClient } from '../employees/employees.client'; import { SessionsClient } from '../sessions/sessions.client'; import { ArtifactsClient } from '../artifacts/artifacts.client'; import { VisitorTokenStore } from '../sessions/visitor-store'; export type ResourceRequestOptions = Omit & { method?: string; headers?: Record; /** * Deployment this request is scoped to. Drives which visitor token is sent * and which deployment a returned token is stored under — a token is never * shared across deployments. */ deploymentId?: string; }; /** * Internal handle passed to resource clients (employees.*). Hides the raw * RequestClient and gives resource clients a typed `call` method that * does auth + URL prep + response parsing in one step. */ export type ResourceClientContext = { baseUrl: string; /** Make an authenticated request and return the parsed envelope. */ call: (path: string, options: ResourceRequestOptions) => Promise>; /** * Make an authenticated request and return the raw Response (used by * streaming, where the SSE consumer needs the unparsed body). */ callRaw: (path: string, options: ResourceRequestOptions) => Promise; /** * Build the URL + final headers for a streaming POST without sending it. * The stream-runner consumes this to drive fetch-event-source directly. * Auth headers are resolved at call time so future refresh-callback * support can re-build per-attempt. */ prepareStream: (path: string, perCallHeaders?: Record, deploymentId?: string) => { url: string; headers: Record; }; /** The pre-request hook from client config, to pass through to streams. */ onRequest?: (request: RequestInit) => Promise | void; /** Store a visitor token returned on a streaming response. */ captureVisitor: (deploymentId: string | undefined, response: Response) => void; }; export declare class TorukClient { readonly config: TorukClientConfig; readonly employees: EmployeesClient; /** Deployment-scoped external sessions. Core owns every session fact. */ readonly sessions: SessionsClient; /** * Deployment-scoped external artifacts, addressed through the session they * were generated in. Read-only: artifacts are produced by the flow during a * conversation, never by the client. */ readonly artifacts: ArtifactsClient; /** Per-deployment `x-toruk-visitor` identity, persisted across reloads. */ readonly visitor: VisitorTokenStore; protected readonly http: RequestClient; protected readonly ctx: ResourceClientContext; private workflowsAliasWarned; constructor(config: TorukClientConfig); /** * What this deployment can do, read from `GET :deploymentId/config`. * * One negotiation path for headless consumers and the widget alike, so the * two cannot disagree about whether a feature is on. The returned object is * always fully populated — see `resolveDeploymentCapabilities` — so callers * read `caps.textToSpeech.enabled` without optional chaining and without * branching on the server's version. Against a CORE that predates the * capability envelope every flag is `false` except `streaming`, which falls * back to the long-standing top-level `isStreaming`. * * Not cached: `/config` is one small request, and a stale capability set is * worse than a second call — a deployment's features can be toggled while a * page is open. Cache at the call site if you need to. */ capabilities(deploymentId?: string, options?: { signal?: AbortSignal; headers?: Record; }): Promise>; /** * @deprecated Use `employees` — the `workflows` namespace is preserved * as an alias for one minor cycle and will be removed in the next major * release. Emits one `console.warn` on first access per instance. */ get workflows(): EmployeesClient; protected prepareStream(path: string, perCallHeaders?: Record, deploymentId?: string): { url: string; headers: Record; }; private buildUrl; private prepare; /** Persist any visitor identity Core minted on this response. */ private absorbVisitor; protected call(path: string, options: ResourceRequestOptions): Promise>; protected callRaw(path: string, options: ResourceRequestOptions): Promise; }