@couplet/agent-ui 1.0.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/chunk-LQB4Y7J4.js +135 -0
- package/dist/chunk-MJFUPOSB.js +432 -0
- package/dist/chunk-PVUMYYWU.js +194 -0
- package/dist/client.d.ts +11 -0
- package/dist/client.js +15 -0
- package/dist/core.d.ts +51 -0
- package/dist/core.js +58 -0
- package/dist/index.d.ts +162 -0
- package/dist/index.js +1659 -0
- package/dist/types-rklAgjcr.d.ts +219 -0
- package/package.json +52 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import {
|
|
2
|
+
appendMessageChainNode,
|
|
3
|
+
appendSessionMessages,
|
|
4
|
+
appendUserReplyChainNode,
|
|
5
|
+
createAgentMessage,
|
|
6
|
+
removeSessionMessage,
|
|
7
|
+
streamEventToChainNode,
|
|
8
|
+
updateClarifyMessage,
|
|
9
|
+
updateMessageContent,
|
|
10
|
+
updateMessageReasoning
|
|
11
|
+
} from "./chunk-MJFUPOSB.js";
|
|
12
|
+
|
|
13
|
+
// src/core/session-runtime.ts
|
|
14
|
+
function replaceSession(sessions, nextSession) {
|
|
15
|
+
return sessions.map((session) => session.id === nextSession.id ? nextSession : session);
|
|
16
|
+
}
|
|
17
|
+
function upsertSession(sessions, nextSession) {
|
|
18
|
+
const exists = sessions.some((session) => session.id === nextSession.id);
|
|
19
|
+
return sortSessions(exists ? replaceSession(sessions, nextSession) : [nextSession, ...sessions]);
|
|
20
|
+
}
|
|
21
|
+
function sortSessions(sessions) {
|
|
22
|
+
return [...sessions].sort((first, second) => second.updatedAt - first.updatedAt);
|
|
23
|
+
}
|
|
24
|
+
async function loadInitialChatSession(client, mode) {
|
|
25
|
+
if (mode === "new") {
|
|
26
|
+
return { sessionId: await client.createSession(), messages: [] };
|
|
27
|
+
}
|
|
28
|
+
return client.loadLatestSession();
|
|
29
|
+
}
|
|
30
|
+
function updateSessionInState(sessions, sessionId, updater) {
|
|
31
|
+
const current = sessions.find((s) => s.id === sessionId);
|
|
32
|
+
if (!current) return sessions;
|
|
33
|
+
return sortSessions(replaceSession(sessions, updater(current)));
|
|
34
|
+
}
|
|
35
|
+
function handleStreamEvent(event, ctx) {
|
|
36
|
+
const { sessionId, assistantMessageId, setSessions, setStatus, setContextUsage, onNavigate } = ctx;
|
|
37
|
+
switch (event.kind) {
|
|
38
|
+
case "MessageChunk":
|
|
39
|
+
setSessions(
|
|
40
|
+
(prev) => updateSessionInState(prev, sessionId, (current) => {
|
|
41
|
+
const message = current.messages.find((item) => item.id === assistantMessageId);
|
|
42
|
+
if (!message) return current;
|
|
43
|
+
return updateMessageContent(current, assistantMessageId, message.content + event.text);
|
|
44
|
+
})
|
|
45
|
+
);
|
|
46
|
+
setStatus((prev) => prev === "retrying" ? "streaming" : prev);
|
|
47
|
+
break;
|
|
48
|
+
case "ThinkingChunk":
|
|
49
|
+
handleThinkingChunk(event, ctx);
|
|
50
|
+
break;
|
|
51
|
+
case "ClarifyEvent":
|
|
52
|
+
setSessions(
|
|
53
|
+
(prev) => updateSessionInState(
|
|
54
|
+
prev,
|
|
55
|
+
sessionId,
|
|
56
|
+
(current) => updateClarifyMessage(current, assistantMessageId, {
|
|
57
|
+
question: event.question,
|
|
58
|
+
options: event.options.length ? event.options : void 0
|
|
59
|
+
})
|
|
60
|
+
)
|
|
61
|
+
);
|
|
62
|
+
break;
|
|
63
|
+
case "FinalEvent":
|
|
64
|
+
if (event.content) {
|
|
65
|
+
setSessions(
|
|
66
|
+
(prev) => updateSessionInState(
|
|
67
|
+
prev,
|
|
68
|
+
sessionId,
|
|
69
|
+
(current) => updateMessageContent(current, assistantMessageId, event.content)
|
|
70
|
+
)
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
break;
|
|
74
|
+
case "Retrying":
|
|
75
|
+
setStatus("retrying");
|
|
76
|
+
break;
|
|
77
|
+
case "FatalError":
|
|
78
|
+
throw new Error(event.message || "Agent stream failed");
|
|
79
|
+
case "OpenPageEvent":
|
|
80
|
+
case "OpenExternalLinkEvent":
|
|
81
|
+
if (!onNavigate) throw new Error("Agent navigation handler is not configured");
|
|
82
|
+
onNavigate(event);
|
|
83
|
+
break;
|
|
84
|
+
case "ContextUsageEvent":
|
|
85
|
+
setContextUsage?.({
|
|
86
|
+
budget_tokens: event.budget_tokens,
|
|
87
|
+
used_tokens: event.used_tokens,
|
|
88
|
+
used_percent: event.used_percent,
|
|
89
|
+
categories: event.categories,
|
|
90
|
+
source: event.source,
|
|
91
|
+
estimated_tokens: event.estimated_tokens,
|
|
92
|
+
prompt_tokens: event.prompt_tokens
|
|
93
|
+
});
|
|
94
|
+
break;
|
|
95
|
+
case "MessageStop":
|
|
96
|
+
case "ToolCallFinished":
|
|
97
|
+
case "ContextCompressed":
|
|
98
|
+
case "LongToolHint":
|
|
99
|
+
break;
|
|
100
|
+
default:
|
|
101
|
+
handleChainNodeEvent(event, ctx);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function handleThinkingChunk(event, ctx) {
|
|
105
|
+
const { sessionId, assistantMessageId, setSessions } = ctx;
|
|
106
|
+
if (event.node_id) {
|
|
107
|
+
setSessions(
|
|
108
|
+
(prev) => updateSessionInState(
|
|
109
|
+
prev,
|
|
110
|
+
sessionId,
|
|
111
|
+
(current) => appendMessageChainNode(current, assistantMessageId, {
|
|
112
|
+
id: event.node_id,
|
|
113
|
+
type: "thinking",
|
|
114
|
+
content: event.content
|
|
115
|
+
})
|
|
116
|
+
)
|
|
117
|
+
);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
setSessions(
|
|
121
|
+
(prev) => updateSessionInState(prev, sessionId, (current) => {
|
|
122
|
+
const message = current.messages.find((item) => item.id === assistantMessageId);
|
|
123
|
+
const nextReasoning = (message?.reasoning ?? "") + event.content;
|
|
124
|
+
return updateMessageReasoning(current, assistantMessageId, nextReasoning);
|
|
125
|
+
})
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
function handleChainNodeEvent(event, ctx) {
|
|
129
|
+
const chainNode = streamEventToChainNode(event);
|
|
130
|
+
if (!chainNode) return;
|
|
131
|
+
const { sessionId, assistantMessageId, setSessions } = ctx;
|
|
132
|
+
setSessions(
|
|
133
|
+
(prev) => updateSessionInState(
|
|
134
|
+
prev,
|
|
135
|
+
sessionId,
|
|
136
|
+
(current) => appendMessageChainNode(current, assistantMessageId, chainNode)
|
|
137
|
+
)
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
function createPendingSession(session, content, assistantMessage, chainReplyTo) {
|
|
141
|
+
const userMessages = chainReplyTo ? [] : [createAgentMessage("user", content)];
|
|
142
|
+
const appended = appendSessionMessages(session, [...userMessages, assistantMessage]);
|
|
143
|
+
return chainReplyTo ? appendUserReplyChainNode(appended, chainReplyTo, content) : appended;
|
|
144
|
+
}
|
|
145
|
+
async function runAgentStream(options) {
|
|
146
|
+
const { client, session, content, chainReplyTo, setSessions, setStatus, abortControllerRef } = options;
|
|
147
|
+
const assistantMessage = createAgentMessage("assistant", "");
|
|
148
|
+
const nextSession = createPendingSession(session, content, assistantMessage, chainReplyTo);
|
|
149
|
+
const abortController = new AbortController();
|
|
150
|
+
abortControllerRef.current = abortController;
|
|
151
|
+
setStatus("streaming");
|
|
152
|
+
setSessions((prev) => sortSessions(replaceSession(prev, nextSession)));
|
|
153
|
+
try {
|
|
154
|
+
await client.sendMessageStream({
|
|
155
|
+
request: {
|
|
156
|
+
session_id: session.id,
|
|
157
|
+
message: { role: "user", content },
|
|
158
|
+
stream: true,
|
|
159
|
+
chain_reply_to: chainReplyTo
|
|
160
|
+
},
|
|
161
|
+
signal: abortController.signal,
|
|
162
|
+
onEvent: (event) => handleStreamEvent(event, {
|
|
163
|
+
sessionId: session.id,
|
|
164
|
+
assistantMessageId: assistantMessage.id,
|
|
165
|
+
setSessions,
|
|
166
|
+
setStatus,
|
|
167
|
+
setContextUsage: options.setContextUsage,
|
|
168
|
+
onNavigate: options.onNavigate
|
|
169
|
+
})
|
|
170
|
+
});
|
|
171
|
+
setStatus("idle");
|
|
172
|
+
} catch (error) {
|
|
173
|
+
if (abortController.signal.aborted) {
|
|
174
|
+
setSessions((prev) => replaceSession(prev, removeSessionMessage(nextSession, assistantMessage.id)));
|
|
175
|
+
setStatus("idle");
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const message = error instanceof Error ? error.message : options.getStreamErrorMessage();
|
|
179
|
+
setSessions(
|
|
180
|
+
(prev) => replaceSession(prev, updateMessageContent(nextSession, assistantMessage.id, message, true))
|
|
181
|
+
);
|
|
182
|
+
setStatus("error");
|
|
183
|
+
} finally {
|
|
184
|
+
abortControllerRef.current = null;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export {
|
|
189
|
+
replaceSession,
|
|
190
|
+
upsertSession,
|
|
191
|
+
sortSessions,
|
|
192
|
+
loadInitialChatSession,
|
|
193
|
+
runAgentStream
|
|
194
|
+
};
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { u as CreateAgentClientOptions, b as AgentClient, f as AgentEndpoints } from './types-rklAgjcr.js';
|
|
2
|
+
export { l as AgentTransport, o as ChatSessionListItem, p as ChatSessionListResponse } from './types-rklAgjcr.js';
|
|
3
|
+
|
|
4
|
+
declare function createAgentClient(options: CreateAgentClientOptions): AgentClient;
|
|
5
|
+
|
|
6
|
+
declare const DEFAULT_AGENT_ENDPOINTS: AgentEndpoints;
|
|
7
|
+
declare function resolveAgentEndpoints(overrides?: Partial<AgentEndpoints>): AgentEndpoints;
|
|
8
|
+
declare function getSessionDetailEndpoint(endpoints: AgentEndpoints, sessionId: string): string;
|
|
9
|
+
declare function getContextUsageEndpoint(endpoints: AgentEndpoints, sessionId: string): string;
|
|
10
|
+
|
|
11
|
+
export { AgentClient, AgentEndpoints, CreateAgentClientOptions, DEFAULT_AGENT_ENDPOINTS, createAgentClient, getContextUsageEndpoint, getSessionDetailEndpoint, resolveAgentEndpoints };
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_AGENT_ENDPOINTS,
|
|
3
|
+
createAgentClient,
|
|
4
|
+
getContextUsageEndpoint,
|
|
5
|
+
getSessionDetailEndpoint,
|
|
6
|
+
resolveAgentEndpoints
|
|
7
|
+
} from "./chunk-LQB4Y7J4.js";
|
|
8
|
+
import "./chunk-MJFUPOSB.js";
|
|
9
|
+
export {
|
|
10
|
+
DEFAULT_AGENT_ENDPOINTS,
|
|
11
|
+
createAgentClient,
|
|
12
|
+
getContextUsageEndpoint,
|
|
13
|
+
getSessionDetailEndpoint,
|
|
14
|
+
resolveAgentEndpoints
|
|
15
|
+
};
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { A as AgentSession, m as ChainNode, j as AgentToolCall, g as AgentMessage, e as AgentClarify, d as AgentPendingClarify, b as AgentClient, a as AgentStatus, c as AgentNavigationEvent, C as ContextUsage, S as StreamEvent } from './types-rklAgjcr.js';
|
|
2
|
+
export { h as AgentMessageRole, i as AgentStreamRequest, k as AgentToolCallFunction, n as ChainNodeType, q as ClarifyEvent, r as ContextCompressedEvent, s as ContextUsageCategory, t as ContextUsageEvent, F as FatalErrorEvent, v as FinalEvent, L as LongToolHintEvent, M as MessageChunkEvent, w as MessageStopEvent, O as OpenExternalLinkEvent, x as OpenPageEvent, R as RetryingEvent, y as StreamEventBase, T as ThinkingChunkEvent, z as ToolCallEvent, B as ToolCallFinishedEvent, D as ToolResultEvent, U as UserReplyEvent } from './types-rklAgjcr.js';
|
|
3
|
+
import { Dispatch, SetStateAction, MutableRefObject } from 'react';
|
|
4
|
+
|
|
5
|
+
declare function createAgentSession(id?: string, now?: number): AgentSession;
|
|
6
|
+
declare function createAgentMessage(role: AgentMessage['role'], content: string, extras?: Partial<AgentMessage>): AgentMessage;
|
|
7
|
+
declare function createClarifyMessage(question: string, options?: readonly string[]): AgentMessage;
|
|
8
|
+
declare function findLastClarifyCall(chain: readonly ChainNode[]): ChainNode | undefined;
|
|
9
|
+
declare function isClarifyCallAnswered(chain: readonly ChainNode[], clarifyCall: ChainNode): boolean;
|
|
10
|
+
declare function extractClarifyFromChain(chain: readonly ChainNode[]): AgentClarify | undefined;
|
|
11
|
+
declare function getPendingClarify(messages: readonly AgentMessage[]): AgentPendingClarify | undefined;
|
|
12
|
+
declare function updateMessageType(session: AgentSession, messageId: string, type: AgentMessage['type']): AgentSession;
|
|
13
|
+
declare function updateClarifyMessage(session: AgentSession, messageId: string, clarify: AgentClarify): AgentSession;
|
|
14
|
+
declare function getSessionTitle(input: string): string;
|
|
15
|
+
declare function appendSessionMessages(session: AgentSession, messages: readonly AgentMessage[]): AgentSession;
|
|
16
|
+
declare function updateMessageContent(session: AgentSession, messageId: string, content: string, error?: boolean): AgentSession;
|
|
17
|
+
declare function updateMessageReasoning(session: AgentSession, messageId: string, reasoning: string): AgentSession;
|
|
18
|
+
declare function appendUserReplyChainNode(session: AgentSession, parentNodeId: string, content: string): AgentSession;
|
|
19
|
+
declare function appendMessageChainNode(session: AgentSession, messageId: string, node: ChainNode): AgentSession;
|
|
20
|
+
declare function appendMessageToolCalls(session: AgentSession, messageId: string, deltas: readonly AgentToolCall[]): AgentSession;
|
|
21
|
+
declare function removeSessionMessage(session: AgentSession, messageId: string): AgentSession;
|
|
22
|
+
|
|
23
|
+
type InitialAgentSessionMode = 'latest' | 'new';
|
|
24
|
+
interface AgentStreamRunnerOptions {
|
|
25
|
+
readonly client: AgentClient;
|
|
26
|
+
readonly session: AgentSession;
|
|
27
|
+
readonly content: string;
|
|
28
|
+
readonly chainReplyTo?: string;
|
|
29
|
+
readonly setSessions: Dispatch<SetStateAction<readonly AgentSession[]>>;
|
|
30
|
+
readonly setStatus: Dispatch<SetStateAction<AgentStatus>>;
|
|
31
|
+
readonly abortControllerRef: MutableRefObject<AbortController | null>;
|
|
32
|
+
readonly onNavigate?: (event: AgentNavigationEvent) => void;
|
|
33
|
+
readonly setContextUsage?: Dispatch<SetStateAction<ContextUsage | null>>;
|
|
34
|
+
readonly getStreamErrorMessage: () => string;
|
|
35
|
+
}
|
|
36
|
+
declare function replaceSession(sessions: readonly AgentSession[], nextSession: AgentSession): readonly AgentSession[];
|
|
37
|
+
declare function upsertSession(sessions: readonly AgentSession[], nextSession: AgentSession): readonly AgentSession[];
|
|
38
|
+
declare function sortSessions(sessions: readonly AgentSession[]): readonly AgentSession[];
|
|
39
|
+
declare function loadInitialChatSession(client: AgentClient, mode: InitialAgentSessionMode): Promise<{
|
|
40
|
+
sessionId: string;
|
|
41
|
+
messages: AgentMessage[];
|
|
42
|
+
}>;
|
|
43
|
+
declare function runAgentStream(options: AgentStreamRunnerOptions): Promise<void>;
|
|
44
|
+
|
|
45
|
+
type JsonObject = Record<string, unknown>;
|
|
46
|
+
declare function parseStreamEvent(eventPayload: JsonObject): StreamEvent | null;
|
|
47
|
+
declare function streamEventToChainNode(event: StreamEvent): ChainNode | null;
|
|
48
|
+
declare function parseSseEnvelope(rawEvent: string): StreamEvent | null;
|
|
49
|
+
declare function consumeAgentSseStream(body: ReadableStream<Uint8Array>, onEvent: (event: StreamEvent) => void): Promise<void>;
|
|
50
|
+
|
|
51
|
+
export { AgentClarify, AgentMessage, AgentNavigationEvent, AgentPendingClarify, AgentSession, AgentStatus, type AgentStreamRunnerOptions, AgentToolCall, ChainNode, ContextUsage, type InitialAgentSessionMode, StreamEvent, appendMessageChainNode, appendMessageToolCalls, appendSessionMessages, appendUserReplyChainNode, consumeAgentSseStream, createAgentMessage, createAgentSession, createClarifyMessage, extractClarifyFromChain, findLastClarifyCall, getPendingClarify, getSessionTitle, isClarifyCallAnswered, loadInitialChatSession, parseSseEnvelope, parseStreamEvent, removeSessionMessage, replaceSession, runAgentStream, sortSessions, streamEventToChainNode, updateClarifyMessage, updateMessageContent, updateMessageReasoning, updateMessageType, upsertSession };
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
loadInitialChatSession,
|
|
3
|
+
replaceSession,
|
|
4
|
+
runAgentStream,
|
|
5
|
+
sortSessions,
|
|
6
|
+
upsertSession
|
|
7
|
+
} from "./chunk-PVUMYYWU.js";
|
|
8
|
+
import {
|
|
9
|
+
appendMessageChainNode,
|
|
10
|
+
appendMessageToolCalls,
|
|
11
|
+
appendSessionMessages,
|
|
12
|
+
appendUserReplyChainNode,
|
|
13
|
+
consumeAgentSseStream,
|
|
14
|
+
createAgentMessage,
|
|
15
|
+
createAgentSession,
|
|
16
|
+
createClarifyMessage,
|
|
17
|
+
extractClarifyFromChain,
|
|
18
|
+
findLastClarifyCall,
|
|
19
|
+
getPendingClarify,
|
|
20
|
+
getSessionTitle,
|
|
21
|
+
isClarifyCallAnswered,
|
|
22
|
+
parseSseEnvelope,
|
|
23
|
+
parseStreamEvent,
|
|
24
|
+
removeSessionMessage,
|
|
25
|
+
streamEventToChainNode,
|
|
26
|
+
updateClarifyMessage,
|
|
27
|
+
updateMessageContent,
|
|
28
|
+
updateMessageReasoning,
|
|
29
|
+
updateMessageType
|
|
30
|
+
} from "./chunk-MJFUPOSB.js";
|
|
31
|
+
export {
|
|
32
|
+
appendMessageChainNode,
|
|
33
|
+
appendMessageToolCalls,
|
|
34
|
+
appendSessionMessages,
|
|
35
|
+
appendUserReplyChainNode,
|
|
36
|
+
consumeAgentSseStream,
|
|
37
|
+
createAgentMessage,
|
|
38
|
+
createAgentSession,
|
|
39
|
+
createClarifyMessage,
|
|
40
|
+
extractClarifyFromChain,
|
|
41
|
+
findLastClarifyCall,
|
|
42
|
+
getPendingClarify,
|
|
43
|
+
getSessionTitle,
|
|
44
|
+
isClarifyCallAnswered,
|
|
45
|
+
loadInitialChatSession,
|
|
46
|
+
parseSseEnvelope,
|
|
47
|
+
parseStreamEvent,
|
|
48
|
+
removeSessionMessage,
|
|
49
|
+
replaceSession,
|
|
50
|
+
runAgentStream,
|
|
51
|
+
sortSessions,
|
|
52
|
+
streamEventToChainNode,
|
|
53
|
+
updateClarifyMessage,
|
|
54
|
+
updateMessageContent,
|
|
55
|
+
updateMessageReasoning,
|
|
56
|
+
updateMessageType,
|
|
57
|
+
upsertSession
|
|
58
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { A as AgentSession, a as AgentStatus, C as ContextUsage, b as AgentClient, c as AgentNavigationEvent, d as AgentPendingClarify } from './types-rklAgjcr.js';
|
|
2
|
+
export { e as AgentClarify, f as AgentEndpoints, g as AgentMessage, h as AgentMessageRole, i as AgentStreamRequest, j as AgentToolCall, k as AgentToolCallFunction, l as AgentTransport, m as ChainNode, n as ChainNodeType, o as ChatSessionListItem, p as ChatSessionListResponse, q as ClarifyEvent, r as ContextCompressedEvent, s as ContextUsageCategory, t as ContextUsageEvent, u as CreateAgentClientOptions, F as FatalErrorEvent, v as FinalEvent, L as LongToolHintEvent, M as MessageChunkEvent, w as MessageStopEvent, O as OpenExternalLinkEvent, x as OpenPageEvent, R as RetryingEvent, S as StreamEvent, y as StreamEventBase, T as ThinkingChunkEvent, z as ToolCallEvent, B as ToolCallFinishedEvent, D as ToolResultEvent, U as UserReplyEvent } from './types-rklAgjcr.js';
|
|
3
|
+
export { AgentStreamRunnerOptions, InitialAgentSessionMode, appendMessageChainNode, appendMessageToolCalls, appendSessionMessages, appendUserReplyChainNode, consumeAgentSseStream, createAgentMessage, createAgentSession, createClarifyMessage, extractClarifyFromChain, findLastClarifyCall, getPendingClarify, getSessionTitle, isClarifyCallAnswered, loadInitialChatSession, parseSseEnvelope, parseStreamEvent, removeSessionMessage, replaceSession, runAgentStream, sortSessions, streamEventToChainNode, updateClarifyMessage, updateMessageContent, updateMessageReasoning, updateMessageType, upsertSession } from './core.js';
|
|
4
|
+
export { DEFAULT_AGENT_ENDPOINTS, createAgentClient, getContextUsageEndpoint, getSessionDetailEndpoint, resolveAgentEndpoints } from './client.js';
|
|
5
|
+
import * as react from 'react';
|
|
6
|
+
|
|
7
|
+
interface AgentContextUsageLabels {
|
|
8
|
+
readonly title: string;
|
|
9
|
+
readonly tokens: string;
|
|
10
|
+
readonly percent: string;
|
|
11
|
+
readonly categoryLabels: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
interface AgentComposerLabels {
|
|
14
|
+
readonly placeholder: string;
|
|
15
|
+
readonly send: string;
|
|
16
|
+
readonly stop: string;
|
|
17
|
+
readonly clarifyTitle: string;
|
|
18
|
+
readonly contextUsage: AgentContextUsageLabels;
|
|
19
|
+
}
|
|
20
|
+
interface AgentConversationViewLabels {
|
|
21
|
+
readonly copy: string;
|
|
22
|
+
readonly copied: string;
|
|
23
|
+
readonly thinking: string;
|
|
24
|
+
readonly thoughtProcess: string;
|
|
25
|
+
readonly toolInput: string;
|
|
26
|
+
readonly toolOutput: string;
|
|
27
|
+
readonly userSelected: string;
|
|
28
|
+
readonly clarifyQuestion: string;
|
|
29
|
+
}
|
|
30
|
+
interface AgentHistoryLabels {
|
|
31
|
+
readonly title: string;
|
|
32
|
+
readonly description: string;
|
|
33
|
+
readonly search: string;
|
|
34
|
+
readonly recent: string;
|
|
35
|
+
readonly empty: string;
|
|
36
|
+
readonly loading: string;
|
|
37
|
+
readonly loadError: string;
|
|
38
|
+
readonly selectError: string;
|
|
39
|
+
readonly untitled: string;
|
|
40
|
+
readonly messageCount: (count: number) => string;
|
|
41
|
+
}
|
|
42
|
+
interface AgentSessionLabels {
|
|
43
|
+
readonly streamError: string;
|
|
44
|
+
}
|
|
45
|
+
interface AgentConversationLabels {
|
|
46
|
+
readonly conversation: AgentConversationViewLabels;
|
|
47
|
+
readonly composer: AgentComposerLabels;
|
|
48
|
+
}
|
|
49
|
+
interface AgentPanelHeaderLabels {
|
|
50
|
+
readonly title: string;
|
|
51
|
+
readonly newConversation: string;
|
|
52
|
+
readonly history: string;
|
|
53
|
+
readonly close: string;
|
|
54
|
+
readonly expandToFullPage: string;
|
|
55
|
+
readonly collapseToPanel: string;
|
|
56
|
+
readonly resizeHandle: string;
|
|
57
|
+
}
|
|
58
|
+
interface AgentSurfaceLabels extends AgentConversationLabels {
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface UseAgentSessionOptions {
|
|
62
|
+
readonly client: AgentClient;
|
|
63
|
+
readonly labels: Pick<AgentSessionLabels, 'streamError'>;
|
|
64
|
+
readonly autoInit?: boolean;
|
|
65
|
+
readonly initialSessionMode?: 'latest' | 'new';
|
|
66
|
+
readonly onNavigate?: (event: AgentNavigationEvent) => void;
|
|
67
|
+
}
|
|
68
|
+
interface UseAgentSessionState {
|
|
69
|
+
readonly currentSession: AgentSession;
|
|
70
|
+
readonly status: AgentStatus;
|
|
71
|
+
readonly contextUsage: ContextUsage | null;
|
|
72
|
+
readonly createSession: () => Promise<void>;
|
|
73
|
+
readonly selectSession: (sessionId: string) => Promise<void>;
|
|
74
|
+
readonly sendMessage: (content: string) => Promise<void>;
|
|
75
|
+
readonly sendClarifyOption: (option: string, chainReplyTo: string) => Promise<void>;
|
|
76
|
+
readonly stopStreaming: () => void;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
declare function useAgentSession(options: UseAgentSessionOptions): UseAgentSessionState;
|
|
80
|
+
|
|
81
|
+
interface AgentComposerProps {
|
|
82
|
+
readonly status: AgentStatus;
|
|
83
|
+
readonly contextUsage?: ContextUsage | null;
|
|
84
|
+
readonly pendingClarify?: AgentPendingClarify;
|
|
85
|
+
readonly labels: {
|
|
86
|
+
readonly placeholder: string;
|
|
87
|
+
readonly send: string;
|
|
88
|
+
readonly stop: string;
|
|
89
|
+
readonly clarifyTitle: string;
|
|
90
|
+
readonly contextUsage: {
|
|
91
|
+
readonly title: string;
|
|
92
|
+
readonly tokens: string;
|
|
93
|
+
readonly percent: string;
|
|
94
|
+
readonly categoryLabels: Record<string, string>;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
readonly isNew: boolean;
|
|
98
|
+
readonly initialQuestions?: readonly string[];
|
|
99
|
+
readonly className?: string;
|
|
100
|
+
readonly onSubmit: (content: string) => Promise<void>;
|
|
101
|
+
readonly onClarifyOption: (option: string, chainReplyTo: string) => Promise<void>;
|
|
102
|
+
readonly onStop: () => void;
|
|
103
|
+
}
|
|
104
|
+
declare function AgentComposer({ status, contextUsage, pendingClarify, labels, isNew, initialQuestions, className, onSubmit, onClarifyOption, onStop, }: AgentComposerProps): react.JSX.Element;
|
|
105
|
+
|
|
106
|
+
interface AIConversationRef {
|
|
107
|
+
scrollToBottom: () => void;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
interface ConversationViewLabels {
|
|
111
|
+
readonly copy: string;
|
|
112
|
+
readonly copied: string;
|
|
113
|
+
readonly toolInput: string;
|
|
114
|
+
readonly toolOutput: string;
|
|
115
|
+
readonly userSelected: string;
|
|
116
|
+
readonly clarifyQuestion: string;
|
|
117
|
+
readonly thinking: string;
|
|
118
|
+
readonly thoughtProcess: string;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
interface ConversationViewProps {
|
|
122
|
+
readonly session: AgentSession;
|
|
123
|
+
readonly status: AgentStatus;
|
|
124
|
+
readonly awaitingUserReply?: boolean;
|
|
125
|
+
readonly labels: ConversationViewLabels;
|
|
126
|
+
readonly conversationRef?: React.RefObject<AIConversationRef | null>;
|
|
127
|
+
}
|
|
128
|
+
declare function ConversationView({ session, status, awaitingUserReply, labels, conversationRef, }: ConversationViewProps): react.JSX.Element;
|
|
129
|
+
|
|
130
|
+
interface AgentConversationSurfaceProps {
|
|
131
|
+
readonly agent: UseAgentSessionState;
|
|
132
|
+
readonly labels: AgentSurfaceLabels;
|
|
133
|
+
readonly initialQuestions?: readonly string[];
|
|
134
|
+
readonly className?: string;
|
|
135
|
+
}
|
|
136
|
+
declare function AgentConversationSurface({ agent, labels, initialQuestions, className, }: AgentConversationSurfaceProps): react.JSX.Element;
|
|
137
|
+
|
|
138
|
+
interface AgentHistoryDialogProps {
|
|
139
|
+
readonly client: AgentClient;
|
|
140
|
+
readonly open: boolean;
|
|
141
|
+
readonly busy: boolean;
|
|
142
|
+
readonly onOpenChange: (open: boolean) => void;
|
|
143
|
+
readonly onSelectSession: (sessionId: string) => Promise<void>;
|
|
144
|
+
readonly labels: AgentHistoryLabels;
|
|
145
|
+
}
|
|
146
|
+
declare function AgentHistoryDialog({ client, open, busy, onOpenChange, onSelectSession, labels, }: AgentHistoryDialogProps): react.JSX.Element;
|
|
147
|
+
|
|
148
|
+
interface ContextUsageIndicatorProps {
|
|
149
|
+
readonly usage: ContextUsage | null;
|
|
150
|
+
readonly hasMessages: boolean;
|
|
151
|
+
readonly isStreaming: boolean;
|
|
152
|
+
readonly labels: {
|
|
153
|
+
readonly title: string;
|
|
154
|
+
readonly tokens: string;
|
|
155
|
+
readonly percent: string;
|
|
156
|
+
readonly categoryLabels: Record<string, string>;
|
|
157
|
+
};
|
|
158
|
+
readonly className?: string;
|
|
159
|
+
}
|
|
160
|
+
declare function ContextUsageIndicator({ usage, hasMessages, isStreaming, labels, className, }: ContextUsageIndicatorProps): react.JSX.Element | null;
|
|
161
|
+
|
|
162
|
+
export { AgentClient, AgentComposer, type AgentComposerLabels, type AgentContextUsageLabels, type AgentConversationLabels, AgentConversationSurface, type AgentConversationSurfaceProps, type AgentConversationViewLabels, AgentHistoryDialog, type AgentHistoryDialogProps, type AgentHistoryLabels, AgentNavigationEvent, type AgentPanelHeaderLabels, AgentPendingClarify, AgentSession, type AgentSessionLabels, AgentStatus, type AgentSurfaceLabels, ContextUsage, ContextUsageIndicator, ConversationView, type ConversationViewLabels, type UseAgentSessionOptions, type UseAgentSessionState, useAgentSession };
|