@dudousxd/nestjs-agent-react 0.19.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +78 -29
- package/dist/client-ePlgRwP-.d.cts +302 -0
- package/dist/client-ePlgRwP-.d.ts +302 -0
- package/dist/{model-gHqjNjLJ.d.cts → generative-ui-9AJNVKBZ.d.cts} +165 -1
- package/dist/{model-gHqjNjLJ.d.ts → generative-ui-9AJNVKBZ.d.ts} +165 -1
- package/dist/genui-json-render.d.cts +1 -2
- package/dist/genui-json-render.d.ts +1 -2
- package/dist/genui.d.cts +2 -3
- package/dist/genui.d.ts +2 -3
- package/dist/index.cjs +928 -353
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +92 -311
- package/dist/index.d.ts +92 -311
- package/dist/index.js +888 -315
- package/dist/index.js.map +1 -1
- package/dist/media.cjs +152 -0
- package/dist/media.cjs.map +1 -0
- package/dist/media.d.cts +61 -0
- package/dist/media.d.ts +61 -0
- package/dist/media.js +127 -0
- package/dist/media.js.map +1 -0
- package/package.json +16 -1
- package/dist/generative-ui-BhXFni8j.d.ts +0 -167
- package/dist/generative-ui-C53b3FoA.d.cts +0 -167
package/dist/index.d.ts
CHANGED
|
@@ -1,134 +1,14 @@
|
|
|
1
1
|
import * as ai from 'ai';
|
|
2
2
|
import { ChatTransport, UIMessage, UIMessageChunk, DataUIPart, UIDataTypes } from 'ai';
|
|
3
|
+
import { A as AgentBackend, U as UploadAttachmentOptions, a as AttachmentUploadStrategy, Q as QuotaToday } from './client-ePlgRwP-.js';
|
|
4
|
+
export { b as AgentBackendUnsupportedError, c as AgentClient, d as AgentClientOptions, e as AgentConnection, f as AgentHttpError, C as CancelResult, g as ChatStreamRequest, h as ChatStreamResponse, M as MessageFeedbackInput, R as ResumeStreamRequest, T as ThreadPatch, r as requireBackendMethod } from './client-ePlgRwP-.js';
|
|
3
5
|
import * as _dudousxd_nestjs_agent_core from '@dudousxd/nestjs-agent-core';
|
|
4
|
-
import {
|
|
6
|
+
import { MessageAttachment, AgentCatalogEntry, ModelCatalogEntry, ModelCatalogView, QuotaReport, QuotaWindow, QuotaBlock, MessageFeedback, MessageFeedbackValue, ThreadSummary, StoredMessage, ToolCatalogEntry, ThreadDetail } from '@dudousxd/nestjs-agent-core';
|
|
5
7
|
export { ElicitationInput, ElicitationInputType, validateElicitationAnswer as validateAnswer, validateElicitationValue as validateAnswerValue } from '@dudousxd/nestjs-agent-core';
|
|
8
|
+
import * as React from 'react';
|
|
6
9
|
import React__default, { ReactNode, Context } from 'react';
|
|
7
|
-
import { T as TranscriptUiBlock,
|
|
8
|
-
export {
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Partial update accepted by `PATCH <base>/threads/:threadId`. `defaultAgent: null` clears a
|
|
12
|
-
* previously-set default back to the module's own default; omitting it leaves the thread's
|
|
13
|
-
* current default untouched.
|
|
14
|
-
*/
|
|
15
|
-
interface ThreadPatch {
|
|
16
|
-
title?: string;
|
|
17
|
-
defaultAgent?: string | null;
|
|
18
|
-
/** Pin a catalog model on the thread; `null` unpins it. */
|
|
19
|
-
model?: string | null;
|
|
20
|
-
}
|
|
21
|
-
/** Starting a turn: the body `POST <base>/chat` takes (see docs/stream-protocol.md). */
|
|
22
|
-
interface ChatStreamRequest {
|
|
23
|
-
/** `{ message, threadId?, agent?, model?, attachments?, pageContext?, regenerate?, … }`. */
|
|
24
|
-
body: Record<string, unknown>;
|
|
25
|
-
/** Per-request headers the AI SDK was handed for this send. */
|
|
26
|
-
headers?: Record<string, string>;
|
|
27
|
-
/** Aborted when the user stops the turn. */
|
|
28
|
-
signal?: AbortSignal;
|
|
29
|
-
}
|
|
30
|
-
/** Attaching to a run that is already streaming: `GET <base>/chat/:runId/stream?after=<seq>`. */
|
|
31
|
-
interface ResumeStreamRequest {
|
|
32
|
-
runId: string;
|
|
33
|
-
/**
|
|
34
|
-
* The sequence number (SSE `id:`) of the last frame the client already has. Omitted → replay
|
|
35
|
-
* from the first frame. A backend that cannot skip may ignore it: the transport also drops frames
|
|
36
|
-
* at or below it.
|
|
37
|
-
*/
|
|
38
|
-
after?: number;
|
|
39
|
-
headers?: Record<string, string>;
|
|
40
|
-
signal?: AbortSignal;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* An open chat stream: the raw `text/event-stream` bytes in the stream-protocol framing, plus the
|
|
44
|
-
* identity a backend may learn before the first frame (the `X-Agent-Run-Id` / `X-Agent-Thread-Id`
|
|
45
|
-
* headers). The body's own `event: meta` frame supplies them otherwise.
|
|
46
|
-
*/
|
|
47
|
-
interface ChatStreamResponse {
|
|
48
|
-
body: ReadableStream<Uint8Array>;
|
|
49
|
-
runId?: string;
|
|
50
|
-
threadId?: string;
|
|
51
|
-
}
|
|
52
|
-
/** What `POST <base>/messages/:id/feedback` takes. `value: null` clears the rating. */
|
|
53
|
-
interface MessageFeedbackInput {
|
|
54
|
-
value: MessageFeedbackValue | null;
|
|
55
|
-
comment?: string;
|
|
56
|
-
}
|
|
57
|
-
interface UploadAttachmentOptions {
|
|
58
|
-
signal?: AbortSignal;
|
|
59
|
-
/** Called with 0..1 as the upload progresses, when the backend can observe it. */
|
|
60
|
-
onProgress?: (fraction: number) => void;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Everything the React layer asks of a server — the seam between `useAgentChat` (and the other
|
|
64
|
-
* hooks) and whatever serves the agent. {@link AgentClient} is the default implementation, over the
|
|
65
|
-
* library's own REST routes with `fetch`. An app with its own client — a generated one, a different
|
|
66
|
-
* auth scheme (cookie session + CSRF header), a backend that is not this library at all but speaks
|
|
67
|
-
* docs/stream-protocol.md — implements this instead and passes it as `useAgentChat({ backend })`.
|
|
68
|
-
*
|
|
69
|
-
* The streaming, thread and cancel members are required: without them there is no chat. The rest
|
|
70
|
-
* are optional; a hook that needs one the backend does not have throws
|
|
71
|
-
* {@link AgentBackendUnsupportedError} when it is called, so a backend only implements what its
|
|
72
|
-
* server supports.
|
|
73
|
-
*/
|
|
74
|
-
interface AgentBackend {
|
|
75
|
-
/** Start a turn and return its SSE stream. Throw on a non-2xx answer. */
|
|
76
|
-
openChatStream(request: ChatStreamRequest): Promise<ChatStreamResponse>;
|
|
77
|
-
/** Attach to a streaming run. Resolve `null` when nothing is streaming under that id (HTTP 404). */
|
|
78
|
-
resumeChatStream(request: ResumeStreamRequest): Promise<ChatStreamResponse | null>;
|
|
79
|
-
/** Hard-stop a run server-side. */
|
|
80
|
-
cancelStream(runId: string): Promise<unknown>;
|
|
81
|
-
listThreads(): Promise<ThreadSummary[]>;
|
|
82
|
-
getThread(id: string): Promise<ThreadDetail>;
|
|
83
|
-
updateThread(id: string, patch: ThreadPatch): Promise<unknown>;
|
|
84
|
-
deleteThread(id: string): Promise<unknown>;
|
|
85
|
-
forkFromMessage?(threadId: string, messageId: string): Promise<ThreadSummary>;
|
|
86
|
-
promoteThread?(id: string): Promise<unknown>;
|
|
87
|
-
truncateFromMessage?(threadId: string, messageId: string): Promise<unknown>;
|
|
88
|
-
approveToolCall?(input: {
|
|
89
|
-
toolCallId: string;
|
|
90
|
-
remember?: boolean;
|
|
91
|
-
via?: string;
|
|
92
|
-
}): Promise<unknown>;
|
|
93
|
-
rejectToolCall?(input: {
|
|
94
|
-
toolCallId: string;
|
|
95
|
-
reason?: string;
|
|
96
|
-
via?: string;
|
|
97
|
-
}): Promise<unknown>;
|
|
98
|
-
answerToolCall?(input: {
|
|
99
|
-
toolCallId: string;
|
|
100
|
-
answers?: Record<string, string[]>;
|
|
101
|
-
}): Promise<unknown>;
|
|
102
|
-
skipToolCall?(input: {
|
|
103
|
-
toolCallId: string;
|
|
104
|
-
}): Promise<unknown>;
|
|
105
|
-
uploadAttachment?(file: File, options?: UploadAttachmentOptions): Promise<MessageAttachment>;
|
|
106
|
-
listTools?(agent?: string): Promise<ToolCatalogEntry[]>;
|
|
107
|
-
listSkills?(threadId?: string): Promise<SkillCatalogEntry[]>;
|
|
108
|
-
getQuotaToday?(): Promise<QuotaView>;
|
|
109
|
-
/** `GET <base>/quota` — every budget window, and which one blocks sends, if any. */
|
|
110
|
-
getQuota?(): Promise<QuotaReport>;
|
|
111
|
-
/** `GET <base>/models?agent=` — what a model picker offers. */
|
|
112
|
-
listModels?(agent?: string): Promise<ModelCatalogView>;
|
|
113
|
-
/** `GET <base>/agents` — what an agent picker offers. */
|
|
114
|
-
listAgents?(): Promise<AgentCatalogEntry[]>;
|
|
115
|
-
setMessageFeedback?(messageId: string, input: MessageFeedbackInput): Promise<{
|
|
116
|
-
feedback: MessageFeedback | null;
|
|
117
|
-
}>;
|
|
118
|
-
}
|
|
119
|
-
/** An optional {@link AgentBackend} member the bound backend does not implement was called. */
|
|
120
|
-
declare class AgentBackendUnsupportedError extends Error {
|
|
121
|
-
readonly method: string;
|
|
122
|
-
constructor(method: string);
|
|
123
|
-
}
|
|
124
|
-
type OptionalMethod = {
|
|
125
|
-
[K in keyof AgentBackend]-?: undefined extends AgentBackend[K] ? K : never;
|
|
126
|
-
}[keyof AgentBackend];
|
|
127
|
-
/**
|
|
128
|
-
* The optional backend method `name`, bound — or a throw naming it. For hook code that has to call
|
|
129
|
-
* something a backend may not offer.
|
|
130
|
-
*/
|
|
131
|
-
declare function requireBackendMethod<K extends OptionalMethod>(backend: AgentBackend, name: K): NonNullable<AgentBackend[K]>;
|
|
10
|
+
import { o as GenuiProviderValue, T as TranscriptUiBlock, t as TranscriptBlock, U as UsageSummary, v as TimestampInfo, C as ChatStatus, M as MessageUsageInfo, w as ToolCatalog, A as ApproveOptions, x as AnyToolUIPart, y as TranscriptFile } from './generative-ui-9AJNVKBZ.js';
|
|
11
|
+
export { z as ApprovalBlockOptions, B as BuildBlocksOptions, D as CoercibleQuestion, E as DescribeToolCallOptions, F as ElicitationBlockOptions, H as GroupToolActivityOptions, I as RawAnswer, J as ResolvedReading, K as ResolvedResultView, L as RetrievedPassage, S as SettleAction, N as ToolActivityGroup, O as ToolCallDescription, P as ToolCallState, Q as ToolCallStatus, V as TranscriptApproval, W as TranscriptApprovalStatus, X as TranscriptElicitationBlock, Y as TranscriptElicitationOutcome, Z as TranscriptFilesBlock, _ as TranscriptQuestion, $ as TranscriptQuestionOption, a0 as TranscriptReasoningBlock, a1 as TranscriptSettleState, a2 as TranscriptSource, a3 as TranscriptSourcesBlock, a4 as TranscriptTextBlock, a5 as TranscriptToolBlock, a6 as TranscriptToolCall, a7 as buildTranscriptBlocks, a8 as coerceAnswer, a9 as correctedCallIds, aa as describeTimestamp, ab as describeToolCall, ac as describeUsage, ad as extractMessageText, ae as fillTemplate, af as formatRelativeTime, ag as groupToolActivity, ah as inferResultView, ai as isActionCall, aj as phraseFor, ak as readPath, al as resolveResultView, am as toolCallState, an as toolCatalogFrom } from './generative-ui-9AJNVKBZ.js';
|
|
132
12
|
|
|
133
13
|
/** Identity surfaced by the backend's `meta` SSE frame / response headers. */
|
|
134
14
|
interface AgentStreamMeta {
|
|
@@ -177,12 +57,10 @@ interface AgentChatTransportOptions {
|
|
|
177
57
|
reconnect?: ReconnectOptions | false;
|
|
178
58
|
/** Fires as a stream drops, reconnects, or gives up. */
|
|
179
59
|
onConnectionChange?: (state: StreamConnectionState) => void;
|
|
180
|
-
/**
|
|
181
|
-
* Origin + base path the agent endpoints hang off, e.g.
|
|
182
|
-
* `https://api.example.com`. Endpoints are appended as
|
|
183
|
-
* `${baseUrl}/agent/chat` etc. Defaults to `''` (same origin).
|
|
184
|
-
*/
|
|
60
|
+
/** The server's origin, e.g. `https://api.example.com`. Defaults to `''` (same origin). */
|
|
185
61
|
baseUrl?: string;
|
|
62
|
+
/** The agent's route prefix (`AgentModule`'s `path`, global prefix included). Default `'agent'`. */
|
|
63
|
+
path?: string;
|
|
186
64
|
/** Static headers merged into every request (e.g. a tenant ref). */
|
|
187
65
|
headers?: Record<string, string>;
|
|
188
66
|
/**
|
|
@@ -353,7 +231,7 @@ interface UseAttachmentsOptions {
|
|
|
353
231
|
* answered; honour `signal` so `remove` can cancel; call `onProgress(0..1)` if you can.
|
|
354
232
|
*/
|
|
355
233
|
upload?: (file: File, options: UploadAttachmentOptions) => Promise<MessageAttachment>;
|
|
356
|
-
/** Used for the default `upload`.
|
|
234
|
+
/** Used for the default `upload`. Default: the enclosing `<AgentProvider>`'s. */
|
|
357
235
|
backend?: AgentBackend;
|
|
358
236
|
/** `<input accept>` grammar: `'image/*,.pdf'` or `['image/*', 'application/pdf']`. */
|
|
359
237
|
accept?: string | readonly string[];
|
|
@@ -424,11 +302,65 @@ interface ClipboardLikeEvent {
|
|
|
424
302
|
* files.clear();
|
|
425
303
|
* ```
|
|
426
304
|
*/
|
|
427
|
-
declare function useAttachments(options
|
|
305
|
+
declare function useAttachments(options?: UseAttachmentsOptions): AttachmentsState;
|
|
306
|
+
|
|
307
|
+
interface AgentProviderProps {
|
|
308
|
+
/**
|
|
309
|
+
* A backend of your own — see {@link AgentBackend}. Omitted → an {@link AgentClient} over this
|
|
310
|
+
* library's REST routes, built from the connection props below (which are ignored when a backend
|
|
311
|
+
* is given). Must be stable across renders.
|
|
312
|
+
*/
|
|
313
|
+
backend?: AgentBackend;
|
|
314
|
+
/** The server's origin, e.g. `https://api.example.com`. Default `''` (same origin). */
|
|
315
|
+
baseUrl?: string;
|
|
316
|
+
/** `AgentModule`'s `path`, global prefix included (`'api/agent'`). Default `'agent'`. */
|
|
317
|
+
path?: string;
|
|
318
|
+
/** Static headers on every request. */
|
|
319
|
+
headers?: Record<string, string>;
|
|
320
|
+
/**
|
|
321
|
+
* Read at every request — a short-lived bearer token, or a CSRF header read from a cookie
|
|
322
|
+
* (`{ 'X-XSRF-TOKEN': readCookie('XSRF-TOKEN') }`).
|
|
323
|
+
*/
|
|
324
|
+
getHeaders?: () => Record<string, string> | Promise<Record<string, string>>;
|
|
325
|
+
/** `'include'` when the API is on another origin and authenticates by cookie. */
|
|
326
|
+
credentials?: RequestCredentials;
|
|
327
|
+
/** Injectable for tests / non-browser runtimes. */
|
|
328
|
+
fetch?: typeof fetch;
|
|
329
|
+
/** Attachment uploads of the built-in client. */
|
|
330
|
+
attachments?: {
|
|
331
|
+
/** e.g. `mediaAttachments()` from `@dudousxd/nestjs-agent-react/media`. */
|
|
332
|
+
upload?: AttachmentUploadStrategy;
|
|
333
|
+
};
|
|
334
|
+
/**
|
|
335
|
+
* Set generative UI up here — the same settings `<GenuiProvider>` takes (registry, catalog,
|
|
336
|
+
* resolver, fallback, …). Every message then draws pushed components with them.
|
|
337
|
+
*/
|
|
338
|
+
genui?: GenuiProviderValue;
|
|
339
|
+
children?: ReactNode;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* The agent connection, once, at the app root. Every hook below it — `useAgentChat`, `useThreads`,
|
|
343
|
+
* `useModels`, `useAgents`, `useQuota`, `useToolCatalog`, `useMessageFeedback`, `useAttachments` —
|
|
344
|
+
* talks to it unless handed a `backend` of its own.
|
|
345
|
+
*
|
|
346
|
+
* ```tsx
|
|
347
|
+
* <AgentProvider baseUrl="https://api.example.com" credentials="include">
|
|
348
|
+
* <App />
|
|
349
|
+
* </AgentProvider>
|
|
350
|
+
* ```
|
|
351
|
+
*
|
|
352
|
+
* Without a provider every hook shares one same-origin client on `/agent`.
|
|
353
|
+
*/
|
|
354
|
+
declare function AgentProvider({ backend, baseUrl, path, headers, getHeaders, credentials, fetch, attachments, genui, children, }: AgentProviderProps): React.JSX.Element;
|
|
355
|
+
/**
|
|
356
|
+
* The backend a hook talks to: `own` when given, else the enclosing {@link AgentProvider}'s, else a
|
|
357
|
+
* shared same-origin client on `/agent`. For your own hooks over the same connection.
|
|
358
|
+
*/
|
|
359
|
+
declare function useAgentBackend<B extends AgentBackend = AgentBackend>(own?: B): B;
|
|
428
360
|
|
|
429
361
|
interface UseAgentsOptions {
|
|
430
|
-
/**
|
|
431
|
-
backend
|
|
362
|
+
/** Default: the enclosing `<AgentProvider>`'s. Must implement `listAgents`. */
|
|
363
|
+
backend?: AgentBackend;
|
|
432
364
|
/** `false` holds the request. Default `true`. */
|
|
433
365
|
enabled?: boolean;
|
|
434
366
|
}
|
|
@@ -445,11 +377,11 @@ interface AgentsState {
|
|
|
445
377
|
* The registered agents (`GET <base>/agents`) — the data behind an agent picker. Send the pick as
|
|
446
378
|
* `useAgentChat({ agent })`, or pin it on a thread with `PATCH <base>/threads/:id { defaultAgent }`.
|
|
447
379
|
*/
|
|
448
|
-
declare function useAgents(options
|
|
380
|
+
declare function useAgents(options?: UseAgentsOptions): AgentsState;
|
|
449
381
|
|
|
450
382
|
interface UseModelsOptions {
|
|
451
|
-
/**
|
|
452
|
-
backend
|
|
383
|
+
/** Default: the enclosing `<AgentProvider>`'s. Must implement `listModels`. */
|
|
384
|
+
backend?: AgentBackend;
|
|
453
385
|
/** The agent to list models for; omitted → the default agent. */
|
|
454
386
|
agent?: string;
|
|
455
387
|
/** `false` holds the request. Default `true`. */
|
|
@@ -479,11 +411,11 @@ interface ModelsState {
|
|
|
479
411
|
* as `useAgentChat({ model })`, `sendMessage(msg, { body: { model } })`, or pin it on the thread
|
|
480
412
|
* with `chat.setThreadModel(id)`.
|
|
481
413
|
*/
|
|
482
|
-
declare function useModels(options
|
|
414
|
+
declare function useModels(options?: UseModelsOptions): ModelsState;
|
|
483
415
|
|
|
484
416
|
interface UseQuotaOptions {
|
|
485
|
-
/**
|
|
486
|
-
backend
|
|
417
|
+
/** Default: the enclosing `<AgentProvider>`'s. Must implement `getQuota`. */
|
|
418
|
+
backend?: AgentBackend;
|
|
487
419
|
/** `false` holds the request. Default `true`. */
|
|
488
420
|
enabled?: boolean;
|
|
489
421
|
/** Re-read every `pollMs` ms as well. Default: only on mount, after runs, and on `refresh`. */
|
|
@@ -507,11 +439,11 @@ interface QuotaState {
|
|
|
507
439
|
* one — if any — blocks sends. Re-read after every run a chat on the same backend settles, so a
|
|
508
440
|
* meter moves with the conversation. Headless: draw the meter yourself.
|
|
509
441
|
*/
|
|
510
|
-
declare function useQuota(options
|
|
442
|
+
declare function useQuota(options?: UseQuotaOptions): QuotaState;
|
|
511
443
|
|
|
512
444
|
interface UseMessageFeedbackOptions {
|
|
513
|
-
/**
|
|
514
|
-
backend
|
|
445
|
+
/** Default: the enclosing `<AgentProvider>`'s. Must implement `setMessageFeedback`. */
|
|
446
|
+
backend?: AgentBackend;
|
|
515
447
|
/**
|
|
516
448
|
* The thread the messages belong to — `useAgentChat(...).getThreadId`, or an id. Needed to rate a
|
|
517
449
|
* message streamed in this session: its id is the client's own, so the persisted row it became is
|
|
@@ -536,7 +468,7 @@ interface MessageFeedbackState {
|
|
|
536
468
|
* Headless: it holds the state and the calls, the host draws the buttons. A rating shows at once
|
|
537
469
|
* and rolls back if the server refuses it.
|
|
538
470
|
*/
|
|
539
|
-
declare function useMessageFeedback(options
|
|
471
|
+
declare function useMessageFeedback(options?: UseMessageFeedbackOptions): MessageFeedbackState;
|
|
540
472
|
|
|
541
473
|
/**
|
|
542
474
|
* What changed about a backend's thread list. `changed` → refetch (a thread was created, or a run
|
|
@@ -560,11 +492,11 @@ declare function onThreadsEvent(backend: AgentBackend, listener: Listener): () =
|
|
|
560
492
|
|
|
561
493
|
interface UseThreadsOptions {
|
|
562
494
|
/**
|
|
563
|
-
* The backend to list
|
|
495
|
+
* The backend to list. Default: the enclosing `<AgentProvider>`'s. Must be STABLE across renders:
|
|
564
496
|
* the list refreshes itself when a chat on the SAME backend creates a thread, settles a run or
|
|
565
497
|
* streams a title.
|
|
566
498
|
*/
|
|
567
|
-
backend
|
|
499
|
+
backend?: AgentBackend;
|
|
568
500
|
/** `false` holds the first request (e.g. until the user is signed in). Default `true`. */
|
|
569
501
|
enabled?: boolean;
|
|
570
502
|
}
|
|
@@ -585,7 +517,7 @@ interface ThreadsState {
|
|
|
585
517
|
* backend reports thread creation and settled runs (refetch) and streamed titles (patched in
|
|
586
518
|
* place). Headless — it renders nothing.
|
|
587
519
|
*/
|
|
588
|
-
declare function useThreads(options
|
|
520
|
+
declare function useThreads(options?: UseThreadsOptions): ThreadsState;
|
|
589
521
|
|
|
590
522
|
/**
|
|
591
523
|
* A sub-agent the conversation started and did not wait for. The chat is free while it works, so a
|
|
@@ -618,141 +550,6 @@ interface BackgroundRun {
|
|
|
618
550
|
*/
|
|
619
551
|
declare function backgroundRunsFromThread(messages: readonly StoredMessage[]): BackgroundRun[];
|
|
620
552
|
|
|
621
|
-
/**
|
|
622
|
-
* Thrown by {@link AgentClient} on a non-2xx response. Carries the HTTP `status` so callers can
|
|
623
|
-
* branch (e.g. 403 → "not your thread", 429 → quota) instead of string-matching a generic Error.
|
|
624
|
-
*/
|
|
625
|
-
declare class AgentHttpError extends Error {
|
|
626
|
-
readonly status: number;
|
|
627
|
-
readonly method: string;
|
|
628
|
-
readonly path: string;
|
|
629
|
-
constructor(status: number, method: string, path: string, statusText: string);
|
|
630
|
-
}
|
|
631
|
-
/** The quota-today read-model: usage, the configured limit (null → unlimited), and USD spend. */
|
|
632
|
-
type QuotaToday = QuotaView;
|
|
633
|
-
interface CancelResult {
|
|
634
|
-
aborted: boolean;
|
|
635
|
-
}
|
|
636
|
-
interface OkResult {
|
|
637
|
-
ok: boolean;
|
|
638
|
-
}
|
|
639
|
-
interface AgentClientOptions {
|
|
640
|
-
/** Origin + base path, e.g. `https://api.example.com`. Defaults to `''`. */
|
|
641
|
-
baseUrl?: string;
|
|
642
|
-
/** Static headers merged into every request. */
|
|
643
|
-
headers?: Record<string, string>;
|
|
644
|
-
/**
|
|
645
|
-
* Resolved per request — for short-lived bearer tokens, or a CSRF header read from a cookie
|
|
646
|
-
* (`{ 'X-XSRF-TOKEN': readCookie('XSRF-TOKEN') }`), which has to be read at request time because
|
|
647
|
-
* the server may rotate it.
|
|
648
|
-
*/
|
|
649
|
-
getHeaders?: () => Record<string, string> | Promise<Record<string, string>>;
|
|
650
|
-
/**
|
|
651
|
-
* Forwarded to fetch so cookie auth works. Same-origin requests send cookies by default; set
|
|
652
|
-
* `'include'` when the API lives on another origin (and have it answer with credentialed CORS).
|
|
653
|
-
*/
|
|
654
|
-
credentials?: RequestCredentials;
|
|
655
|
-
/** Injectable for tests / non-browser runtimes. */
|
|
656
|
-
fetch?: typeof fetch;
|
|
657
|
-
}
|
|
658
|
-
/**
|
|
659
|
-
* Framework-agnostic REST client for the nestjs-agent endpoints — the default {@link AgentBackend}.
|
|
660
|
-
* Used by `useAgentChat`, but standalone-usable (vanilla fetch, no React).
|
|
661
|
-
*/
|
|
662
|
-
declare class AgentClient implements AgentBackend {
|
|
663
|
-
private readonly options;
|
|
664
|
-
constructor(options?: AgentClientOptions);
|
|
665
|
-
/** `POST /agent/chat` → the turn's SSE stream. Throws {@link AgentHttpError} on a non-2xx. */
|
|
666
|
-
openChatStream(request: ChatStreamRequest): Promise<ChatStreamResponse>;
|
|
667
|
-
/**
|
|
668
|
-
* `GET /agent/chat/:runId/stream[?after=<seq>]` → the run's SSE stream, or `null` when nothing is
|
|
669
|
-
* streaming under that id (404).
|
|
670
|
-
*/
|
|
671
|
-
resumeChatStream(request: ResumeStreamRequest): Promise<ChatStreamResponse | null>;
|
|
672
|
-
/**
|
|
673
|
-
* Rate a message (`'up'`/`'down'`, optional comment) or clear its rating (`value: null`). Answers
|
|
674
|
-
* the stored rating.
|
|
675
|
-
*/
|
|
676
|
-
setMessageFeedback(messageId: string, input: MessageFeedbackInput): Promise<{
|
|
677
|
-
feedback: MessageFeedback | null;
|
|
678
|
-
}>;
|
|
679
|
-
listThreads(): Promise<ThreadSummary[]>;
|
|
680
|
-
/**
|
|
681
|
-
* The skills this caller can invoke right now, scope-resolved — the same list, built by the same
|
|
682
|
-
* call, that the model is offered, so what a user can type after a `/` and what the agent can
|
|
683
|
-
* reach cannot drift apart. `threadId` reaches the host's own resolver, which may scope a skill to
|
|
684
|
-
* one conversation; omitted, the server reads it as a brand-new thread.
|
|
685
|
-
*/
|
|
686
|
-
listSkills(threadId?: string): Promise<SkillCatalogEntry[]>;
|
|
687
|
-
/**
|
|
688
|
-
* The tools this caller can reach through `agent` (the default agent when omitted), each with the
|
|
689
|
-
* server-declared `presentation` a chat narrates it by — the same list the model is offered.
|
|
690
|
-
* Prefer {@link useToolCatalog}, which fetches it once and shares it.
|
|
691
|
-
*/
|
|
692
|
-
listTools(agent?: string): Promise<ToolCatalogEntry[]>;
|
|
693
|
-
getThread(id: string): Promise<ThreadDetail>;
|
|
694
|
-
deleteThread(id: string): Promise<void>;
|
|
695
|
-
forkFromMessage(threadId: string, messageId: string): Promise<ThreadSummary>;
|
|
696
|
-
renameThread(id: string, title: string): Promise<OkResult>;
|
|
697
|
-
/** General `PATCH /agent/threads/:threadId` — title and/or the thread's pinned default agent. */
|
|
698
|
-
updateThread(id: string, patch: ThreadPatch): Promise<OkResult>;
|
|
699
|
-
/**
|
|
700
|
-
* Uploads a file (image/PDF) for a vision-capable model turn. Multipart, field name `file` —
|
|
701
|
-
* mirrors the backend's `POST /agent/attachments`. The returned {@link MessageAttachment} is
|
|
702
|
-
* what a caller then rides on `sendMessage({ text }, { body: { attachments: [...] } })`.
|
|
703
|
-
*/
|
|
704
|
-
uploadAttachment(file: File, options?: UploadAttachmentOptions): Promise<MessageAttachment>;
|
|
705
|
-
private uploadWithProgress;
|
|
706
|
-
promoteThread(id: string): Promise<OkResult>;
|
|
707
|
-
truncateFromMessage(threadId: string, messageId: string): Promise<OkResult>;
|
|
708
|
-
/** `GET /agent/models?agent=` — the models this caller may pick, grouped by provider. */
|
|
709
|
-
listModels(agent?: string): Promise<ModelCatalogView>;
|
|
710
|
-
/** `GET /agent/agents` — the registered agents, the default one flagged. */
|
|
711
|
-
listAgents(): Promise<AgentCatalogEntry[]>;
|
|
712
|
-
/** `GET /agent/quota` — the caller's budget windows and the one blocking sends, if any. */
|
|
713
|
-
getQuota(): Promise<QuotaReport>;
|
|
714
|
-
getQuotaToday(): Promise<QuotaToday>;
|
|
715
|
-
cancelStream(runId: string): Promise<CancelResult>;
|
|
716
|
-
/**
|
|
717
|
-
* `remember` approves later calls of the same tool in the same thread; `via` names the surface
|
|
718
|
-
* the decision came through (the server records `'web'` when omitted).
|
|
719
|
-
*/
|
|
720
|
-
approveToolCall(input: {
|
|
721
|
-
toolCallId: string;
|
|
722
|
-
remember?: boolean;
|
|
723
|
-
via?: string;
|
|
724
|
-
}): Promise<void>;
|
|
725
|
-
rejectToolCall(input: {
|
|
726
|
-
toolCallId: string;
|
|
727
|
-
reason?: string;
|
|
728
|
-
via?: string;
|
|
729
|
-
}): Promise<void>;
|
|
730
|
-
/**
|
|
731
|
-
* Settle a parked question set. `answers` is questionId → chosen option values; a question left
|
|
732
|
-
* out takes the pre-picked default the request carried, resolved server-side against the request
|
|
733
|
-
* the run already holds. Omit the whole object and the user has confirmed every pre-picked
|
|
734
|
-
* answer — which is the point of the surface, so it is a valid submission rather than a blank.
|
|
735
|
-
*/
|
|
736
|
-
answerToolCall(input: {
|
|
737
|
-
toolCallId: string;
|
|
738
|
-
answers?: Record<string, string[]>;
|
|
739
|
-
}): Promise<void>;
|
|
740
|
-
/**
|
|
741
|
-
* Decline to answer and let the agent proceed on its own pre-picked values. Lands on the same
|
|
742
|
-
* values a confirmation would, and persists differently on purpose — only one of them is
|
|
743
|
-
* evidence the user chose them.
|
|
744
|
-
*/
|
|
745
|
-
skipToolCall(input: {
|
|
746
|
-
toolCallId: string;
|
|
747
|
-
}): Promise<void>;
|
|
748
|
-
private fetchImpl;
|
|
749
|
-
private baseUrl;
|
|
750
|
-
private resolveHeaders;
|
|
751
|
-
private credentials;
|
|
752
|
-
private request;
|
|
753
|
-
private handleResponse;
|
|
754
|
-
}
|
|
755
|
-
|
|
756
553
|
/** Draws a server-pushed component block. */
|
|
757
554
|
type AmbientRenderUi = (block: TranscriptUiBlock) => ReactNode;
|
|
758
555
|
/**
|
|
@@ -1281,8 +1078,8 @@ interface SkillSuggestionData {
|
|
|
1281
1078
|
shadows?: string[];
|
|
1282
1079
|
}
|
|
1283
1080
|
interface SkillsSourceOptions {
|
|
1284
|
-
/** Any backend with `listSkills` — `useAgentChat(
|
|
1285
|
-
|
|
1081
|
+
/** Any backend with `listSkills` — `useAgentBackend()`, or `useAgentChat().backend`. */
|
|
1082
|
+
backend: Pick<AgentBackend, 'listSkills'>;
|
|
1286
1083
|
/**
|
|
1287
1084
|
* Read at query time, not captured once: a threadless chat learns its id only when the backend
|
|
1288
1085
|
* creates one on the first send, and a skill may be scoped to a conversation.
|
|
@@ -1378,13 +1175,12 @@ declare function useComposerAutocomplete(options: UseComposerAutocompleteOptions
|
|
|
1378
1175
|
|
|
1379
1176
|
/** What the catalog needs of a backend. */
|
|
1380
1177
|
type ToolsBackend = Pick<AgentBackend, 'listTools'>;
|
|
1381
|
-
|
|
1382
1178
|
interface UseToolCatalogOptions {
|
|
1383
1179
|
/**
|
|
1384
|
-
* The
|
|
1385
|
-
*
|
|
1180
|
+
* The backend to ask. Default: the enclosing `<AgentProvider>`'s. Must be STABLE across renders
|
|
1181
|
+
* (the shared copy is keyed by it): a backend constructed inline refetches every render.
|
|
1386
1182
|
*/
|
|
1387
|
-
|
|
1183
|
+
backend?: ToolsBackend;
|
|
1388
1184
|
/** The agent whose tools to list. Omitted → the server's default agent. */
|
|
1389
1185
|
agent?: string;
|
|
1390
1186
|
/** `false` holds the request (e.g. until the user is signed in). Default `true`. */
|
|
@@ -1405,7 +1201,7 @@ interface ToolCatalogState {
|
|
|
1405
1201
|
* `phraseFor`, `describeToolCall` and `groupToolActivity` — or pass `catalog` to
|
|
1406
1202
|
* `useChatTranscript({ toolCatalog })` and read the phrases off the transcript's calls.
|
|
1407
1203
|
*/
|
|
1408
|
-
declare function useToolCatalog(options
|
|
1204
|
+
declare function useToolCatalog(options?: UseToolCatalogOptions): ToolCatalogState;
|
|
1409
1205
|
|
|
1410
1206
|
interface ApprovalCountdown {
|
|
1411
1207
|
/** Milliseconds until the request lapses, floored at 0; `null` when it never does. */
|
|
@@ -1528,11 +1324,10 @@ interface AgentMessageMetadata extends Partial<StoredTurnMetadata> {
|
|
|
1528
1324
|
*/
|
|
1529
1325
|
declare function storedThreadToUiMessages(messages: StoredMessage[]): UIMessage[];
|
|
1530
1326
|
|
|
1531
|
-
interface UseAgentChatOptions<B extends AgentBackend =
|
|
1327
|
+
interface UseAgentChatOptions<B extends AgentBackend = AgentBackend> {
|
|
1532
1328
|
/**
|
|
1533
|
-
* What the chat talks to — see {@link AgentBackend}. Omitted →
|
|
1534
|
-
*
|
|
1535
|
-
* (which are ignored when a backend is given). Must be stable across renders.
|
|
1329
|
+
* What the chat talks to — see {@link AgentBackend}. Omitted → the enclosing `<AgentProvider>`'s,
|
|
1330
|
+
* else a same-origin client on `/agent`. Must be stable across renders.
|
|
1536
1331
|
*/
|
|
1537
1332
|
backend?: B;
|
|
1538
1333
|
/**
|
|
@@ -1541,18 +1336,6 @@ interface UseAgentChatOptions<B extends AgentBackend = AgentClient> {
|
|
|
1541
1336
|
* it off.
|
|
1542
1337
|
*/
|
|
1543
1338
|
reconnect?: ReconnectOptions | false;
|
|
1544
|
-
/** Origin + base path, e.g. `https://api.example.com`. Defaults to `''`. */
|
|
1545
|
-
baseUrl?: string;
|
|
1546
|
-
/** Static headers merged into every request. */
|
|
1547
|
-
headers?: Record<string, string>;
|
|
1548
|
-
/** Resolved per request — for short-lived bearer tokens. */
|
|
1549
|
-
getHeaders?: () => Record<string, string> | Promise<Record<string, string>>;
|
|
1550
|
-
/** Forwarded to fetch so cookie auth/impersonation works. */
|
|
1551
|
-
credentials?: RequestCredentials;
|
|
1552
|
-
/** Injectable for tests / non-browser runtimes. */
|
|
1553
|
-
fetch?: typeof fetch;
|
|
1554
|
-
/** Reuse an existing client instead of constructing one. Prefer {@link backend}. */
|
|
1555
|
-
client?: B;
|
|
1556
1339
|
/** Named agent to run each turn. */
|
|
1557
1340
|
agent?: string;
|
|
1558
1341
|
/**
|
|
@@ -1672,7 +1455,7 @@ interface AddToolResultArgs {
|
|
|
1672
1455
|
* fork, quota, cancel, and HITL approve/reject — all driven through
|
|
1673
1456
|
* `AgentClient`. Mirrors flip's `useAdminChat`, generalized.
|
|
1674
1457
|
*/
|
|
1675
|
-
declare function useAgentChat<B extends AgentBackend =
|
|
1458
|
+
declare function useAgentChat<B extends AgentBackend = AgentBackend>(options?: UseAgentChatOptions<B>): {
|
|
1676
1459
|
status: ChatStatus;
|
|
1677
1460
|
/** Where the live stream stands — see {@link StreamConnectionState}. */
|
|
1678
1461
|
connection: StreamConnectionState;
|
|
@@ -1707,10 +1490,8 @@ declare function useAgentChat<B extends AgentBackend = AgentClient>(options: Use
|
|
|
1707
1490
|
*/
|
|
1708
1491
|
getThreadId: () => string | undefined;
|
|
1709
1492
|
setThreadModel: (model: string | null) => Promise<void>;
|
|
1710
|
-
/** The backend this chat talks to —
|
|
1493
|
+
/** The backend this chat talks to — the same one every other hook under the provider uses. */
|
|
1711
1494
|
backend: B;
|
|
1712
|
-
/** Same object as {@link backend}; kept for callers that read it under its old name. */
|
|
1713
|
-
client: B;
|
|
1714
1495
|
threads: ThreadSummary[];
|
|
1715
1496
|
loadThreads: () => Promise<ThreadSummary[]>;
|
|
1716
1497
|
loadThread: (id: string) => Promise<ThreadDetail>;
|
|
@@ -1757,4 +1538,4 @@ declare class QuotaBlockedError extends Error {
|
|
|
1757
1538
|
constructor(block: QuotaBlock);
|
|
1758
1539
|
}
|
|
1759
1540
|
|
|
1760
|
-
export {
|
|
1541
|
+
export { AgentBackend, AgentChatTransport, type AgentChatTransportOptions, type AgentMessageMetadata, AgentProvider, type AgentProviderProps, type AgentStreamMeta, type AgentsState, type AggregatedTurnUsage, type AmbientRenderUi, AmbientRenderUiContext, AnyToolUIPart, type ApprovalCountdown, ApproveOptions, type AttachmentRejection, AttachmentUploadStrategy, type AttachmentsState, type AutocompleteInputProps, type AutocompleteItem, type AutocompleteListboxProps, type AutocompleteOptionProps, type AutocompleteSource, type BackgroundRun, type ChatBackground, ChatInput, type ChatInputProps, ChatStatus, type ChatTranscript, type ClipboardLikeEvent, type CompletionEdit, type ComposerAutocomplete, DEFAULT_SPEECH_LANG, type DragLikeEvent, type MessageFeedbackState, type MessageFile, type MessageFileKind, MessageItem, type MessageItemClassNames, type MessageItemProps, MessageItemView, type MessageItemViewProps, MessageList, type MessageListClassNames, type MessageListProps, MessageUsageInfo, type ModelOption, type ModelsState, QuotaBlockedError, type QuotaState, QuotaToday, type ReconnectOptions, type RenderFilesFn, type RenderReasoningFn, type RenderTextFn, type RenderToolGroupFn, type RenderToolPartFn, type RenderUiFn, SPEECH_LANGUAGES, type SkillSuggestionData, type SkillsSourceOptions, type SpeechLanguage, type SpeechRecognitionHook, type StagedAttachment, type StagedAttachmentStatus, type StickToBottom, type StickToBottomOptions, type StoredTurnMetadata, type StreamConnectionState, type ThreadsEvent, type ThreadsState, TimestampInfo, ToolCatalog, type ToolCatalogState, type TranscriptActionState, TranscriptBlock, type TranscriptCopyState, type TranscriptEditState, TranscriptFile, type TranscriptItem, type TranscriptItemOptions, type TranscriptStopState, TranscriptUiBlock, type TranscriptWindow, type TriggerMatch, type TriggerPosition, UploadAttachmentOptions, UsageSummary, type UseAgentChatOptions, type UseAgentsOptions, type UseApprovalCountdownOptions, type UseAttachmentsOptions, type UseChatTranscriptOptions, type UseComposerAutocompleteOptions, type UseElapsedOptions, type UseMessageFeedbackOptions, type UseModelsOptions, type UseQuotaOptions, type UseSpeechRecognitionOptions, type UseThreadsOptions, type UseToolCatalogOptions, type UseTranscriptItemOptions, acceptsFile, applyCompletion, approvalCountdown, backgroundRunsFromThread, createSkillsSource, dragHasFiles, fileKind, filesFromClipboard, filterAutocompleteItems, findActiveTrigger, formatElapsed, loadStoredSpeechLang, messageFiles, notifyThreads, onThreadsEvent, persistSpeechLang, readReasoningMs, storedMessageToUiMessage, storedThreadToUiMessages, useAgentBackend, useAgentChat, useAgents, useAmbientRenderUi, useApprovalCountdown, useAttachments, useChatTranscript, useComposerAutocomplete, useElapsed, useMessageFeedback, useModels, useQuota, useSpeechRecognition, useStickToBottom, useThreads, useToolCatalog, useTranscriptItem };
|