@dudousxd/nestjs-agent-react 0.1.0 → 0.3.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/dist/index.cjs +29 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -18
- package/dist/index.d.ts +20 -18
- package/dist/index.js +29 -12
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as ai from 'ai';
|
|
2
2
|
import { ChatTransport, UIMessage, UIMessageChunk, ToolUIPart, DynamicToolUIPart } from 'ai';
|
|
3
|
-
import
|
|
3
|
+
import * as _dudousxd_nestjs_agent_core from '@dudousxd/nestjs-agent-core';
|
|
4
|
+
import { ThreadSummary, ThreadDetail, QuotaView } from '@dudousxd/nestjs-agent-core';
|
|
4
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
6
|
import React from 'react';
|
|
6
7
|
|
|
@@ -28,9 +29,9 @@ interface AgentChatTransportOptions {
|
|
|
28
29
|
/** Named agent to run the turn (backend `agent` field). */
|
|
29
30
|
agent?: string;
|
|
30
31
|
/**
|
|
31
|
-
* Extra body fields evaluated per send — the hook injects `threadId
|
|
32
|
-
*
|
|
33
|
-
*
|
|
32
|
+
* Extra body fields evaluated per send — the hook injects `threadId`
|
|
33
|
+
* and `pageContext` through this. Returned object is spread into the
|
|
34
|
+
* request body after the SDK's own `body`.
|
|
34
35
|
*/
|
|
35
36
|
getBody?: () => Record<string, unknown>;
|
|
36
37
|
/**
|
|
@@ -81,8 +82,6 @@ declare class AgentChatTransport implements ChatTransport<UIMessage> {
|
|
|
81
82
|
private toChunkStream;
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
/** The trimmed persona shape returned by `/agent/threads/personas/catalog`. */
|
|
85
|
-
type PersonaCatalogEntry = Pick<Persona, 'id' | 'label'>;
|
|
86
85
|
/**
|
|
87
86
|
* Thrown by {@link AgentClient} on a non-2xx response. Carries the HTTP `status` so callers can
|
|
88
87
|
* branch (e.g. 403 → "not your thread", 429 → quota) instead of string-matching a generic Error.
|
|
@@ -93,12 +92,14 @@ declare class AgentHttpError extends Error {
|
|
|
93
92
|
readonly path: string;
|
|
94
93
|
constructor(status: number, method: string, path: string, statusText: string);
|
|
95
94
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
95
|
+
/** The quota-today read-model: usage, the configured limit (null → unlimited), and USD spend. */
|
|
96
|
+
type QuotaToday = QuotaView;
|
|
99
97
|
interface CancelResult {
|
|
100
98
|
aborted: boolean;
|
|
101
99
|
}
|
|
100
|
+
interface OkResult {
|
|
101
|
+
ok: boolean;
|
|
102
|
+
}
|
|
102
103
|
interface AgentClientOptions {
|
|
103
104
|
/** Origin + base path, e.g. `https://api.example.com`. Defaults to `''`. */
|
|
104
105
|
baseUrl?: string;
|
|
@@ -122,7 +123,9 @@ declare class AgentClient {
|
|
|
122
123
|
getThread(id: string): Promise<ThreadDetail>;
|
|
123
124
|
deleteThread(id: string): Promise<void>;
|
|
124
125
|
forkFromMessage(threadId: string, messageId: string): Promise<ThreadSummary>;
|
|
125
|
-
|
|
126
|
+
renameThread(id: string, title: string): Promise<OkResult>;
|
|
127
|
+
promoteThread(id: string): Promise<OkResult>;
|
|
128
|
+
truncateFromMessage(threadId: string, messageId: string): Promise<OkResult>;
|
|
126
129
|
getQuotaToday(): Promise<QuotaToday>;
|
|
127
130
|
cancelStream(runId: string): Promise<CancelResult>;
|
|
128
131
|
approveToolCall(input: {
|
|
@@ -160,8 +163,6 @@ interface UseAgentChatOptions {
|
|
|
160
163
|
* mount (no id) never fires a doomed resume GET. Omitted → no resume.
|
|
161
164
|
*/
|
|
162
165
|
resumeRunId?: string;
|
|
163
|
-
/** Active persona id sent on every turn. */
|
|
164
|
-
persona?: string;
|
|
165
166
|
/** Read at every send to capture a page snapshot for the page-assistant. */
|
|
166
167
|
getPageContext?: () => Record<string, unknown> | null;
|
|
167
168
|
/** Fired after each streamed turn finishes (e.g. to refetch the sidebar). */
|
|
@@ -175,8 +176,8 @@ interface AddToolResultArgs {
|
|
|
175
176
|
/**
|
|
176
177
|
* Generalized `useChat` wiring for the nestjs-agent backend. Wraps the
|
|
177
178
|
* AI SDK v7 hook with `AgentChatTransport`, plus thread list/load/delete/
|
|
178
|
-
* fork,
|
|
179
|
-
*
|
|
179
|
+
* fork, quota, cancel, and HITL approve/reject — all driven through
|
|
180
|
+
* `AgentClient`. Mirrors flip's `useAdminChat`, generalized.
|
|
180
181
|
*/
|
|
181
182
|
declare function useAgentChat(options: UseAgentChatOptions): {
|
|
182
183
|
addToolResult: ({ tool, toolCallId, output }: AddToolResultArgs) => void | PromiseLike<void>;
|
|
@@ -187,9 +188,10 @@ declare function useAgentChat(options: UseAgentChatOptions): {
|
|
|
187
188
|
loadThread: (id: string) => Promise<ThreadDetail>;
|
|
188
189
|
deleteThread: (id: string) => Promise<void>;
|
|
189
190
|
forkThread: (threadId: string, messageId: string) => Promise<ThreadSummary>;
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
renameThread: (id: string, title: string) => Promise<void>;
|
|
192
|
+
promoteThread: (id: string) => Promise<void>;
|
|
193
|
+
truncateFromMessage: (threadId: string, messageId: string) => Promise<void>;
|
|
194
|
+
quota: _dudousxd_nestjs_agent_core.QuotaView | null;
|
|
193
195
|
loadQuota: () => Promise<QuotaToday>;
|
|
194
196
|
cancel: () => Promise<void>;
|
|
195
197
|
approve: ({ toolCallId }: {
|
|
@@ -416,4 +418,4 @@ interface SpeechRecognitionHook {
|
|
|
416
418
|
*/
|
|
417
419
|
declare function useSpeechRecognition({ lang, onFinalTranscript, onInterimTranscript, }: UseSpeechRecognitionOptions): SpeechRecognitionHook;
|
|
418
420
|
|
|
419
|
-
export { AgentChatTransport, type AgentChatTransportOptions, AgentClient, type AgentClientOptions, AgentHttpError, type AgentStreamMeta, type AnyToolUIPart, type CancelResult, ChatInput, type ChatInputProps, type ChatStatus, DEFAULT_SPEECH_LANG, MessageItem, type MessageItemClassNames, type MessageItemProps, MessageList, type MessageListClassNames, type MessageListProps, type MessageUsageInfo, type
|
|
421
|
+
export { AgentChatTransport, type AgentChatTransportOptions, AgentClient, type AgentClientOptions, AgentHttpError, type AgentStreamMeta, type AnyToolUIPart, type CancelResult, ChatInput, type ChatInputProps, type ChatStatus, DEFAULT_SPEECH_LANG, MessageItem, type MessageItemClassNames, type MessageItemProps, MessageList, type MessageListClassNames, type MessageListProps, type MessageUsageInfo, type QuotaToday, type RenderTextFn, type RenderToolGroupFn, type RenderToolPartFn, SPEECH_LANGUAGES, type SpeechLanguage, type SpeechRecognitionHook, type UseAgentChatOptions, type UseSpeechRecognitionOptions, formatRelativeTime, loadStoredSpeechLang, persistSpeechLang, useAgentChat, useSpeechRecognition };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as ai from 'ai';
|
|
2
2
|
import { ChatTransport, UIMessage, UIMessageChunk, ToolUIPart, DynamicToolUIPart } from 'ai';
|
|
3
|
-
import
|
|
3
|
+
import * as _dudousxd_nestjs_agent_core from '@dudousxd/nestjs-agent-core';
|
|
4
|
+
import { ThreadSummary, ThreadDetail, QuotaView } from '@dudousxd/nestjs-agent-core';
|
|
4
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
6
|
import React from 'react';
|
|
6
7
|
|
|
@@ -28,9 +29,9 @@ interface AgentChatTransportOptions {
|
|
|
28
29
|
/** Named agent to run the turn (backend `agent` field). */
|
|
29
30
|
agent?: string;
|
|
30
31
|
/**
|
|
31
|
-
* Extra body fields evaluated per send — the hook injects `threadId
|
|
32
|
-
*
|
|
33
|
-
*
|
|
32
|
+
* Extra body fields evaluated per send — the hook injects `threadId`
|
|
33
|
+
* and `pageContext` through this. Returned object is spread into the
|
|
34
|
+
* request body after the SDK's own `body`.
|
|
34
35
|
*/
|
|
35
36
|
getBody?: () => Record<string, unknown>;
|
|
36
37
|
/**
|
|
@@ -81,8 +82,6 @@ declare class AgentChatTransport implements ChatTransport<UIMessage> {
|
|
|
81
82
|
private toChunkStream;
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
/** The trimmed persona shape returned by `/agent/threads/personas/catalog`. */
|
|
85
|
-
type PersonaCatalogEntry = Pick<Persona, 'id' | 'label'>;
|
|
86
85
|
/**
|
|
87
86
|
* Thrown by {@link AgentClient} on a non-2xx response. Carries the HTTP `status` so callers can
|
|
88
87
|
* branch (e.g. 403 → "not your thread", 429 → quota) instead of string-matching a generic Error.
|
|
@@ -93,12 +92,14 @@ declare class AgentHttpError extends Error {
|
|
|
93
92
|
readonly path: string;
|
|
94
93
|
constructor(status: number, method: string, path: string, statusText: string);
|
|
95
94
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
95
|
+
/** The quota-today read-model: usage, the configured limit (null → unlimited), and USD spend. */
|
|
96
|
+
type QuotaToday = QuotaView;
|
|
99
97
|
interface CancelResult {
|
|
100
98
|
aborted: boolean;
|
|
101
99
|
}
|
|
100
|
+
interface OkResult {
|
|
101
|
+
ok: boolean;
|
|
102
|
+
}
|
|
102
103
|
interface AgentClientOptions {
|
|
103
104
|
/** Origin + base path, e.g. `https://api.example.com`. Defaults to `''`. */
|
|
104
105
|
baseUrl?: string;
|
|
@@ -122,7 +123,9 @@ declare class AgentClient {
|
|
|
122
123
|
getThread(id: string): Promise<ThreadDetail>;
|
|
123
124
|
deleteThread(id: string): Promise<void>;
|
|
124
125
|
forkFromMessage(threadId: string, messageId: string): Promise<ThreadSummary>;
|
|
125
|
-
|
|
126
|
+
renameThread(id: string, title: string): Promise<OkResult>;
|
|
127
|
+
promoteThread(id: string): Promise<OkResult>;
|
|
128
|
+
truncateFromMessage(threadId: string, messageId: string): Promise<OkResult>;
|
|
126
129
|
getQuotaToday(): Promise<QuotaToday>;
|
|
127
130
|
cancelStream(runId: string): Promise<CancelResult>;
|
|
128
131
|
approveToolCall(input: {
|
|
@@ -160,8 +163,6 @@ interface UseAgentChatOptions {
|
|
|
160
163
|
* mount (no id) never fires a doomed resume GET. Omitted → no resume.
|
|
161
164
|
*/
|
|
162
165
|
resumeRunId?: string;
|
|
163
|
-
/** Active persona id sent on every turn. */
|
|
164
|
-
persona?: string;
|
|
165
166
|
/** Read at every send to capture a page snapshot for the page-assistant. */
|
|
166
167
|
getPageContext?: () => Record<string, unknown> | null;
|
|
167
168
|
/** Fired after each streamed turn finishes (e.g. to refetch the sidebar). */
|
|
@@ -175,8 +176,8 @@ interface AddToolResultArgs {
|
|
|
175
176
|
/**
|
|
176
177
|
* Generalized `useChat` wiring for the nestjs-agent backend. Wraps the
|
|
177
178
|
* AI SDK v7 hook with `AgentChatTransport`, plus thread list/load/delete/
|
|
178
|
-
* fork,
|
|
179
|
-
*
|
|
179
|
+
* fork, quota, cancel, and HITL approve/reject — all driven through
|
|
180
|
+
* `AgentClient`. Mirrors flip's `useAdminChat`, generalized.
|
|
180
181
|
*/
|
|
181
182
|
declare function useAgentChat(options: UseAgentChatOptions): {
|
|
182
183
|
addToolResult: ({ tool, toolCallId, output }: AddToolResultArgs) => void | PromiseLike<void>;
|
|
@@ -187,9 +188,10 @@ declare function useAgentChat(options: UseAgentChatOptions): {
|
|
|
187
188
|
loadThread: (id: string) => Promise<ThreadDetail>;
|
|
188
189
|
deleteThread: (id: string) => Promise<void>;
|
|
189
190
|
forkThread: (threadId: string, messageId: string) => Promise<ThreadSummary>;
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
renameThread: (id: string, title: string) => Promise<void>;
|
|
192
|
+
promoteThread: (id: string) => Promise<void>;
|
|
193
|
+
truncateFromMessage: (threadId: string, messageId: string) => Promise<void>;
|
|
194
|
+
quota: _dudousxd_nestjs_agent_core.QuotaView | null;
|
|
193
195
|
loadQuota: () => Promise<QuotaToday>;
|
|
194
196
|
cancel: () => Promise<void>;
|
|
195
197
|
approve: ({ toolCallId }: {
|
|
@@ -416,4 +418,4 @@ interface SpeechRecognitionHook {
|
|
|
416
418
|
*/
|
|
417
419
|
declare function useSpeechRecognition({ lang, onFinalTranscript, onInterimTranscript, }: UseSpeechRecognitionOptions): SpeechRecognitionHook;
|
|
418
420
|
|
|
419
|
-
export { AgentChatTransport, type AgentChatTransportOptions, AgentClient, type AgentClientOptions, AgentHttpError, type AgentStreamMeta, type AnyToolUIPart, type CancelResult, ChatInput, type ChatInputProps, type ChatStatus, DEFAULT_SPEECH_LANG, MessageItem, type MessageItemClassNames, type MessageItemProps, MessageList, type MessageListClassNames, type MessageListProps, type MessageUsageInfo, type
|
|
421
|
+
export { AgentChatTransport, type AgentChatTransportOptions, AgentClient, type AgentClientOptions, AgentHttpError, type AgentStreamMeta, type AnyToolUIPart, type CancelResult, ChatInput, type ChatInputProps, type ChatStatus, DEFAULT_SPEECH_LANG, MessageItem, type MessageItemClassNames, type MessageItemProps, MessageList, type MessageListClassNames, type MessageListProps, type MessageUsageInfo, type QuotaToday, type RenderTextFn, type RenderToolGroupFn, type RenderToolPartFn, SPEECH_LANGUAGES, type SpeechLanguage, type SpeechRecognitionHook, type UseAgentChatOptions, type UseSpeechRecognitionOptions, formatRelativeTime, loadStoredSpeechLang, persistSpeechLang, useAgentChat, useSpeechRecognition };
|
package/dist/index.js
CHANGED
|
@@ -301,8 +301,16 @@ var AgentClient = class {
|
|
|
301
301
|
forkFromMessage(threadId, messageId) {
|
|
302
302
|
return this.request("POST", `/agent/threads/${encodeURIComponent(threadId)}/fork-from/${encodeURIComponent(messageId)}`);
|
|
303
303
|
}
|
|
304
|
-
|
|
305
|
-
return this.request("
|
|
304
|
+
renameThread(id, title) {
|
|
305
|
+
return this.request("PATCH", `/agent/threads/${encodeURIComponent(id)}`, {
|
|
306
|
+
title
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
promoteThread(id) {
|
|
310
|
+
return this.request("POST", `/agent/threads/${encodeURIComponent(id)}/promote`);
|
|
311
|
+
}
|
|
312
|
+
truncateFromMessage(threadId, messageId) {
|
|
313
|
+
return this.request("DELETE", `/agent/threads/${encodeURIComponent(threadId)}/from/${encodeURIComponent(messageId)}`);
|
|
306
314
|
}
|
|
307
315
|
getQuotaToday() {
|
|
308
316
|
return this.request("GET", "/agent/quota/today");
|
|
@@ -400,9 +408,6 @@ function useAgentChat(options) {
|
|
|
400
408
|
...current.threadId !== void 0 ? {
|
|
401
409
|
threadId: current.threadId
|
|
402
410
|
} : {},
|
|
403
|
-
...current.persona !== void 0 ? {
|
|
404
|
-
persona: current.persona
|
|
405
|
-
} : {},
|
|
406
411
|
...pageContext ? {
|
|
407
412
|
pageContext
|
|
408
413
|
} : {},
|
|
@@ -436,7 +441,6 @@ function useAgentChat(options) {
|
|
|
436
441
|
output
|
|
437
442
|
}), []);
|
|
438
443
|
const [threads, setThreads] = useState([]);
|
|
439
|
-
const [personaCatalog, setPersonaCatalog] = useState([]);
|
|
440
444
|
const [quota, setQuota] = useState(null);
|
|
441
445
|
const loadThreads = useCallback(async () => {
|
|
442
446
|
const list = await client.listThreads();
|
|
@@ -457,13 +461,25 @@ function useAgentChat(options) {
|
|
|
457
461
|
const forkThread = useCallback((threadId, messageId) => client.forkFromMessage(threadId, messageId), [
|
|
458
462
|
client
|
|
459
463
|
]);
|
|
460
|
-
const
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
+
const renameThread = useCallback(async (id, title) => {
|
|
465
|
+
await client.renameThread(id, title);
|
|
466
|
+
setThreads((current) => current.map((thread) => thread.id === id ? {
|
|
467
|
+
...thread,
|
|
468
|
+
title
|
|
469
|
+
} : thread));
|
|
464
470
|
}, [
|
|
465
471
|
client
|
|
466
472
|
]);
|
|
473
|
+
const promoteThread = useCallback(async (id) => {
|
|
474
|
+
await client.promoteThread(id);
|
|
475
|
+
await loadThreads();
|
|
476
|
+
}, [
|
|
477
|
+
client,
|
|
478
|
+
loadThreads
|
|
479
|
+
]);
|
|
480
|
+
const truncateFromMessage = useCallback((threadId, messageId) => client.truncateFromMessage(threadId, messageId).then(() => void 0), [
|
|
481
|
+
client
|
|
482
|
+
]);
|
|
467
483
|
const loadQuota = useCallback(async () => {
|
|
468
484
|
const today = await client.getQuotaToday();
|
|
469
485
|
setQuota(today);
|
|
@@ -514,8 +530,9 @@ function useAgentChat(options) {
|
|
|
514
530
|
loadThread,
|
|
515
531
|
deleteThread,
|
|
516
532
|
forkThread,
|
|
517
|
-
|
|
518
|
-
|
|
533
|
+
renameThread,
|
|
534
|
+
promoteThread,
|
|
535
|
+
truncateFromMessage,
|
|
519
536
|
quota,
|
|
520
537
|
loadQuota,
|
|
521
538
|
cancel,
|