@frost1994/agentic-core 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/LICENSE +201 -0
- package/README.md +32 -0
- package/dist/client.cjs +6 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.ts +149 -0
- package/dist/client.js +6 -0
- package/dist/client.js.map +1 -0
- package/dist/index-CesPelb5.js +619 -0
- package/dist/index-CesPelb5.js.map +1 -0
- package/dist/index-DHqclwK8.cjs +618 -0
- package/dist/index-DHqclwK8.cjs.map +1 -0
- package/dist/index.cjs +605 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +904 -0
- package/dist/index.js +606 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.cjs +2 -0
- package/dist/protocol.cjs.map +1 -0
- package/dist/protocol.d.ts +298 -0
- package/dist/protocol.js +2 -0
- package/dist/protocol.js.map +1 -0
- package/package.json +64 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,904 @@
|
|
|
1
|
+
export declare interface ActionDescriptor {
|
|
2
|
+
actionId: string;
|
|
3
|
+
actionCode: string;
|
|
4
|
+
actionName: string;
|
|
5
|
+
description: string;
|
|
6
|
+
params: Record<string, unknown>;
|
|
7
|
+
needConfirm: boolean;
|
|
8
|
+
riskLevel: 'safe' | 'caution' | 'danger';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export declare interface AiAssistantError extends Error {
|
|
12
|
+
code: ErrorCode;
|
|
13
|
+
retriable: boolean;
|
|
14
|
+
details?: unknown;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export declare class AiHttpClient {
|
|
18
|
+
private readonly baseUrl;
|
|
19
|
+
private readonly headersProvider;
|
|
20
|
+
constructor(baseUrl: string, headersProvider: () => Record<string, string>);
|
|
21
|
+
getPluginConfig(systemCode: string): Promise<PluginConfig | null>;
|
|
22
|
+
listModels(): Promise<ModelOption[]>;
|
|
23
|
+
createConversation(systemCode: string, title?: string, modelCode?: string): Promise<Conversation>;
|
|
24
|
+
listConversations(systemCode: string, page?: number, size?: number): Promise<Conversation[]>;
|
|
25
|
+
getMessages(conversationId: string): Promise<AssistantMessage[]>;
|
|
26
|
+
deleteConversation(conversationId: string): Promise<void>;
|
|
27
|
+
getSuggestions(systemCode: string, sceneCode?: string): Promise<string[]>;
|
|
28
|
+
confirmAction(actionId: string, confirm: boolean): Promise<void>;
|
|
29
|
+
listDataSources(): Promise<DataSourceItem[]>;
|
|
30
|
+
listTables(dataSourceCode: string): Promise<TableInfo[]>;
|
|
31
|
+
submitFeedback(messageId: string, rating: number, comment?: string): Promise<void>;
|
|
32
|
+
health(): Promise<{
|
|
33
|
+
status: string;
|
|
34
|
+
service: string;
|
|
35
|
+
}>;
|
|
36
|
+
private request;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export declare class AiHttpError extends Error {
|
|
40
|
+
readonly code: number;
|
|
41
|
+
readonly traceId?: string;
|
|
42
|
+
constructor(code: number, message: string, traceId?: string);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Core protocol types for AI Assistant
|
|
47
|
+
*/
|
|
48
|
+
export declare type AiOpenMode = 'launcher' | 'floating' | 'drawer' | 'fullscreen' | 'focus-modal';
|
|
49
|
+
|
|
50
|
+
export declare type AiThemeMode = 'system' | 'light' | 'dark' | 'custom';
|
|
51
|
+
|
|
52
|
+
export declare interface AssistantMessage {
|
|
53
|
+
id: string;
|
|
54
|
+
conversationId: string;
|
|
55
|
+
role: MessageRole;
|
|
56
|
+
type: MessageType;
|
|
57
|
+
content: string;
|
|
58
|
+
status: MessageStatus;
|
|
59
|
+
createdAt: string;
|
|
60
|
+
finishedAt?: string;
|
|
61
|
+
metadata?: {
|
|
62
|
+
chart?: ChartConfig;
|
|
63
|
+
table?: TableResult;
|
|
64
|
+
tools?: ToolCall[];
|
|
65
|
+
sources?: SourceRef[];
|
|
66
|
+
suggestions?: string[];
|
|
67
|
+
actions?: ActionDescriptor[];
|
|
68
|
+
metrics?: {
|
|
69
|
+
label: string;
|
|
70
|
+
value: string | number;
|
|
71
|
+
unit?: string;
|
|
72
|
+
trend?: {
|
|
73
|
+
value: number;
|
|
74
|
+
direction: 'up' | 'down' | 'flat';
|
|
75
|
+
label?: string;
|
|
76
|
+
};
|
|
77
|
+
color?: 'primary' | 'success' | 'warning' | 'danger';
|
|
78
|
+
icon?: string;
|
|
79
|
+
};
|
|
80
|
+
sql?: {
|
|
81
|
+
sql: string;
|
|
82
|
+
dialect: 'mysql' | 'postgresql';
|
|
83
|
+
tables: string[];
|
|
84
|
+
estimatedRows: number;
|
|
85
|
+
isReadonly: boolean;
|
|
86
|
+
isSensitive: boolean;
|
|
87
|
+
data: TableResult;
|
|
88
|
+
explanation?: string;
|
|
89
|
+
};
|
|
90
|
+
errorCode?: string;
|
|
91
|
+
[key: string]: unknown;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export declare interface AssistantState {
|
|
96
|
+
/** UI visibility */
|
|
97
|
+
visible: boolean;
|
|
98
|
+
/** Current display mode */
|
|
99
|
+
mode: AiOpenMode;
|
|
100
|
+
/** Previous mode before switch (for back-navigation) */
|
|
101
|
+
previousMode: AiOpenMode | null;
|
|
102
|
+
/** Floating window position (px) */
|
|
103
|
+
position: {
|
|
104
|
+
x: number;
|
|
105
|
+
y: number;
|
|
106
|
+
};
|
|
107
|
+
/** Floating window size (px) */
|
|
108
|
+
size: {
|
|
109
|
+
width: number;
|
|
110
|
+
height: number;
|
|
111
|
+
};
|
|
112
|
+
/** Business system code */
|
|
113
|
+
systemCode: string;
|
|
114
|
+
/** Selected model code */
|
|
115
|
+
modelCode: string;
|
|
116
|
+
/** Current conversation id */
|
|
117
|
+
currentConversationId: string | null;
|
|
118
|
+
/** All loaded conversations */
|
|
119
|
+
conversations: Conversation[];
|
|
120
|
+
/** Messages keyed by conversation id */
|
|
121
|
+
messagesByConversation: Record<string, AssistantMessage[]>;
|
|
122
|
+
/** Tool steps keyed by message id */
|
|
123
|
+
toolStepsByMessage: Record<string, ToolStep[]>;
|
|
124
|
+
/** Stream connection status */
|
|
125
|
+
streamStatus: 'idle' | 'connecting' | 'streaming' | 'reconnecting' | 'closed' | 'error';
|
|
126
|
+
/** Last received sequence number (for ack / resume) */
|
|
127
|
+
lastSeq: number;
|
|
128
|
+
/** Last heartbeat timestamp */
|
|
129
|
+
lastHeartbeatAt: number;
|
|
130
|
+
/** Reconnect attempt counter */
|
|
131
|
+
reconnectAttempt: number;
|
|
132
|
+
/** Theme mode */
|
|
133
|
+
themeMode: AiThemeMode;
|
|
134
|
+
/** Primary color */
|
|
135
|
+
primaryColor: string;
|
|
136
|
+
/** Whether an error toast is currently shown */
|
|
137
|
+
hasError: boolean;
|
|
138
|
+
/** Last error message (transient) */
|
|
139
|
+
lastError: string | null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export declare interface ChartConfig {
|
|
143
|
+
type: 'bar' | 'line' | 'pie' | 'heatmap' | 'gantt' | 'scatter';
|
|
144
|
+
title: string;
|
|
145
|
+
data: unknown;
|
|
146
|
+
options?: Record<string, unknown>;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export declare class ChunkMatcher {
|
|
150
|
+
/**
|
|
151
|
+
* Match parsed citations to a list of knowledge chunks.
|
|
152
|
+
*
|
|
153
|
+
* @param citations — output from `CitationParser.parse()`
|
|
154
|
+
* @param chunks — chunks returned by backend (should be 1-based indexed)
|
|
155
|
+
* @returns chunks that were cited, with `citedBy` populated
|
|
156
|
+
*/
|
|
157
|
+
match(citations: Citation[], chunks: KnowledgeChunk[]): MatchedChunk[];
|
|
158
|
+
/**
|
|
159
|
+
* Build a flat map: citation index → chunk.
|
|
160
|
+
*
|
|
161
|
+
* @returns Map where key is citation number and value is the matching chunk
|
|
162
|
+
*/
|
|
163
|
+
buildIndexMap(chunks: KnowledgeChunk[]): Map<number, KnowledgeChunk>;
|
|
164
|
+
/**
|
|
165
|
+
* Find chunks that are NOT cited in the text (orphans).
|
|
166
|
+
*/
|
|
167
|
+
findOrphans(citations: Citation[], chunks: KnowledgeChunk[]): KnowledgeChunk[];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Knowledge-base citation parser for AI Assistant Core
|
|
172
|
+
*
|
|
173
|
+
* Parses [1] [2] citation markers in assistant text and
|
|
174
|
+
* matches them against content chunks returned by the backend.
|
|
175
|
+
*/
|
|
176
|
+
export declare interface Citation {
|
|
177
|
+
/** Raw marker text, e.g. "[1]" */
|
|
178
|
+
marker: string;
|
|
179
|
+
/** Numeric index, e.g. 1 */
|
|
180
|
+
index: number;
|
|
181
|
+
/** Start position in the source text */
|
|
182
|
+
start: number;
|
|
183
|
+
/** End position in the source text */
|
|
184
|
+
end: number;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export declare class CitationParser {
|
|
188
|
+
/** Regex for citation markers: [1], [12], etc. */
|
|
189
|
+
private static readonly MARKER_RE;
|
|
190
|
+
/**
|
|
191
|
+
* Extract all citation markers from a text block.
|
|
192
|
+
*
|
|
193
|
+
* @param text — source text containing [1], [2], … markers
|
|
194
|
+
* @returns ordered list of citations with positions
|
|
195
|
+
*/
|
|
196
|
+
parse(text: string): Citation[];
|
|
197
|
+
/**
|
|
198
|
+
* Strip citation markers from text, returning clean text and a mapping.
|
|
199
|
+
*
|
|
200
|
+
* @returns `{ text: string, citations: Citation[] }`
|
|
201
|
+
*/
|
|
202
|
+
strip(text: string): {
|
|
203
|
+
text: string;
|
|
204
|
+
citations: Citation[];
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Replace citation markers with custom formatter output.
|
|
208
|
+
*
|
|
209
|
+
* @param text — source text
|
|
210
|
+
* @param format — callback receiving citation index, returns replacement string
|
|
211
|
+
*/
|
|
212
|
+
replace(text: string, format: (index: number) => string): string;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Clamp a number between min and max (inclusive). */
|
|
216
|
+
export declare function clamp(value: number, min: number, max: number): number;
|
|
217
|
+
|
|
218
|
+
export declare interface Conversation {
|
|
219
|
+
id: string;
|
|
220
|
+
title: string;
|
|
221
|
+
systemCode: string;
|
|
222
|
+
sceneCode?: string;
|
|
223
|
+
modelCode?: string;
|
|
224
|
+
status: string;
|
|
225
|
+
createdAt: string;
|
|
226
|
+
updatedAt: string;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export declare interface CreateAiAssistantOptions {
|
|
230
|
+
systemCode: string;
|
|
231
|
+
scene?: string;
|
|
232
|
+
defaultMode?: AiOpenMode;
|
|
233
|
+
theme?: {
|
|
234
|
+
mode?: AiThemeMode;
|
|
235
|
+
primaryColor?: string;
|
|
236
|
+
brandColors?: {
|
|
237
|
+
primary: string;
|
|
238
|
+
accent: string;
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
apiBaseUrl: string;
|
|
242
|
+
apiBaseUrlMock?: string;
|
|
243
|
+
modelCode?: string;
|
|
244
|
+
modelOptions?: ModelOption[];
|
|
245
|
+
userProvider?: () => UserInfo;
|
|
246
|
+
contextProvider?: () => PageContext;
|
|
247
|
+
requestHeaders?: () => Record<string, string>;
|
|
248
|
+
transport?: TransportConfig;
|
|
249
|
+
features?: FeaturesConfig;
|
|
250
|
+
i18n?: I18nConfig;
|
|
251
|
+
onError?: (err: Error) => void;
|
|
252
|
+
onEvent?: (event: unknown) => void;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Create a typed AI Assistant error.
|
|
257
|
+
*
|
|
258
|
+
* @param code — error code from ErrorCodes
|
|
259
|
+
* @param message — human-readable message
|
|
260
|
+
* @param retriable — override default retriability (optional)
|
|
261
|
+
* @param details — extra context for debugging
|
|
262
|
+
*/
|
|
263
|
+
export declare function createError(code: ErrorCode, message: string, retriable?: boolean, details?: unknown): AiAssistantError;
|
|
264
|
+
|
|
265
|
+
export declare function createInitialState(overrides?: Partial<AssistantState>): AssistantState;
|
|
266
|
+
|
|
267
|
+
export declare interface DataSourceItem {
|
|
268
|
+
code: string;
|
|
269
|
+
name: string;
|
|
270
|
+
type: string;
|
|
271
|
+
description?: string;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
export declare function debounce<T extends (...args: unknown[]) => unknown>(fn: T, waitMs: number, immediate?: boolean): DebouncedFunction<T>;
|
|
275
|
+
|
|
276
|
+
export declare interface DebouncedFunction<T extends (...args: unknown[]) => unknown> {
|
|
277
|
+
(...args: Parameters<T>): ReturnType<T> | undefined;
|
|
278
|
+
cancel: () => void;
|
|
279
|
+
flush: () => ReturnType<T> | undefined;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export declare function deepClone<T>(value: T): T;
|
|
283
|
+
|
|
284
|
+
/** Promise-based sleep. */
|
|
285
|
+
export declare function delay(ms: number): Promise<void>;
|
|
286
|
+
|
|
287
|
+
/** Deserialize and merge with fresh initial state defaults. */
|
|
288
|
+
export declare function deserialize(data: unknown): AssistantState | null;
|
|
289
|
+
|
|
290
|
+
/** Convenience: deserialize from JSON string. */
|
|
291
|
+
export declare function deserializeFromString(json: string): AssistantState | null;
|
|
292
|
+
|
|
293
|
+
export declare type ErrorCode = keyof typeof ErrorCodes;
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Error system for AI Assistant Core
|
|
297
|
+
*
|
|
298
|
+
* All error codes with retriability classification.
|
|
299
|
+
*/
|
|
300
|
+
export declare const ErrorCodes: {
|
|
301
|
+
readonly NETWORK: "NETWORK";
|
|
302
|
+
readonly TIMEOUT: "TIMEOUT";
|
|
303
|
+
readonly AUTH: "AUTH";
|
|
304
|
+
readonly FORBIDDEN: "FORBIDDEN";
|
|
305
|
+
readonly RATE_LIMIT: "RATE_LIMIT";
|
|
306
|
+
readonly MODEL_UNAVAILABLE: "MODEL_UNAVAILABLE";
|
|
307
|
+
readonly TOOL_FAILED: "TOOL_FAILED";
|
|
308
|
+
readonly SQL_FORBIDDEN: "SQL_FORBIDDEN";
|
|
309
|
+
readonly SQL_SENSITIVE: "SQL_SENSITIVE";
|
|
310
|
+
readonly PARSE: "PARSE";
|
|
311
|
+
readonly ABORTED: "ABORTED";
|
|
312
|
+
readonly UNKNOWN: "UNKNOWN";
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
export declare type ExecutionMode = 'parallel' | 'serial';
|
|
316
|
+
|
|
317
|
+
export declare interface ExecutionPlan {
|
|
318
|
+
mode: ExecutionMode;
|
|
319
|
+
steps: Array<{
|
|
320
|
+
toolName: string;
|
|
321
|
+
args: Record<string, unknown>;
|
|
322
|
+
title?: string;
|
|
323
|
+
}>;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export declare interface FeaturesConfig {
|
|
327
|
+
enableVoice?: boolean;
|
|
328
|
+
enableFileUpload?: boolean;
|
|
329
|
+
enableFullscreen?: boolean;
|
|
330
|
+
enableDrawer?: boolean;
|
|
331
|
+
enableKnowledge?: boolean;
|
|
332
|
+
enableText2Sql?: boolean;
|
|
333
|
+
enableActionConfirm?: boolean;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** Format a Date or timestamp to locale string. */
|
|
337
|
+
export declare function formatDate(input: Date | number | string, options?: Intl.DateTimeFormatOptions): string;
|
|
338
|
+
|
|
339
|
+
/** Format a duration in milliseconds to human-readable string. */
|
|
340
|
+
export declare function formatDuration(ms: number): string;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Utility functions for AI Assistant Core
|
|
344
|
+
*
|
|
345
|
+
* Pure TypeScript — no framework dependencies.
|
|
346
|
+
*/
|
|
347
|
+
/** Generate a short unique id with an optional prefix. */
|
|
348
|
+
export declare function generateId(prefix?: string): string;
|
|
349
|
+
|
|
350
|
+
export declare interface I18nConfig {
|
|
351
|
+
locale?: string;
|
|
352
|
+
messages?: Record<string, string>;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Check whether an error represents a user abort.
|
|
357
|
+
*/
|
|
358
|
+
export declare function isAborted(error: unknown): boolean;
|
|
359
|
+
|
|
360
|
+
export declare function isArray<T = unknown>(value: unknown): value is T[];
|
|
361
|
+
|
|
362
|
+
export declare function isFunction(value: unknown): value is (...args: unknown[]) => unknown;
|
|
363
|
+
|
|
364
|
+
export declare function isNumber(value: unknown): value is number;
|
|
365
|
+
|
|
366
|
+
export declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Check whether an error is retriable.
|
|
370
|
+
*/
|
|
371
|
+
export declare function isRetriable(error: unknown): boolean;
|
|
372
|
+
|
|
373
|
+
export declare function isString(value: unknown): value is string;
|
|
374
|
+
|
|
375
|
+
export declare interface KnowledgeChunk {
|
|
376
|
+
/** Chunk index (1-based, matching citation numbers) */
|
|
377
|
+
index: number;
|
|
378
|
+
/** Source title or document name */
|
|
379
|
+
title: string;
|
|
380
|
+
/** Chunk text content */
|
|
381
|
+
content: string;
|
|
382
|
+
/** Optional source URL or identifier */
|
|
383
|
+
source?: string;
|
|
384
|
+
/** Relevance score (0–1) */
|
|
385
|
+
score?: number;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
export declare interface MatchedChunk extends KnowledgeChunk {
|
|
389
|
+
/** Citation markers that reference this chunk */
|
|
390
|
+
citedBy: number[];
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
export declare type MessageRole = 'user' | 'assistant' | 'system' | 'tool';
|
|
394
|
+
|
|
395
|
+
export declare type MessageStatus = 'pending' | 'streaming' | 'success' | 'failed';
|
|
396
|
+
|
|
397
|
+
export declare type MessageType = 'text' | 'markdown' | 'chart' | 'table' | 'tool' | 'error' | 'sql' | 'metric' | 'action' | 'source';
|
|
398
|
+
|
|
399
|
+
export declare interface ModelOption {
|
|
400
|
+
code: string;
|
|
401
|
+
name: string;
|
|
402
|
+
supportStream: boolean;
|
|
403
|
+
supportToolCall: boolean;
|
|
404
|
+
bestFor?: Array<'text2sql' | 'analysis' | 'knowledge' | 'general'>;
|
|
405
|
+
maxTokens?: number;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export declare interface OrchestratorOptions {
|
|
409
|
+
registry: ToolRegistry;
|
|
410
|
+
onStepStart?: (step: ToolStep) => void;
|
|
411
|
+
onStepProgress?: (stepId: string, percent: number, message?: string) => void;
|
|
412
|
+
onStepComplete?: (step: ToolStep) => void;
|
|
413
|
+
onStepError?: (step: ToolStep, error: Error) => void;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
export declare interface PageContext {
|
|
417
|
+
systemCode: string;
|
|
418
|
+
pageCode: string;
|
|
419
|
+
pageName?: string;
|
|
420
|
+
routePath: string;
|
|
421
|
+
selectedDeviceIds?: string[];
|
|
422
|
+
selectedWorkOrderIds?: string[];
|
|
423
|
+
selectedScheduleDate?: string;
|
|
424
|
+
filters?: Record<string, unknown>;
|
|
425
|
+
extras?: Record<string, unknown>;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
export declare interface PluginConfig {
|
|
429
|
+
systemCode: string;
|
|
430
|
+
defaultMode: string;
|
|
431
|
+
themeStrategy: string;
|
|
432
|
+
themePreset: string;
|
|
433
|
+
primaryColor: string;
|
|
434
|
+
defaultModelCode: string;
|
|
435
|
+
enableFullscreen: boolean;
|
|
436
|
+
enableDrawer: boolean;
|
|
437
|
+
enableKnowledge: boolean;
|
|
438
|
+
enableText2Sql: boolean;
|
|
439
|
+
rateLimitPerHour: number;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
export declare function reducer(state: AssistantState, action: StateAction): AssistantState;
|
|
443
|
+
|
|
444
|
+
export declare interface RegisteredTool {
|
|
445
|
+
definition: ToolDefinition;
|
|
446
|
+
executor: ToolExecutor;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/** Serialize state to JSON-safe object (excludes transient stream fields). */
|
|
450
|
+
export declare function serialize(state: AssistantState): SerializedState;
|
|
451
|
+
|
|
452
|
+
export declare interface SerializedState {
|
|
453
|
+
version: number;
|
|
454
|
+
state: Omit<AssistantState, 'streamStatus' | 'lastSeq' | 'lastHeartbeatAt' | 'reconnectAttempt' | 'hasError' | 'lastError'>;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/** Convenience: serialize to JSON string. */
|
|
458
|
+
export declare function serializeToString(state: AssistantState): string;
|
|
459
|
+
|
|
460
|
+
export declare interface SourceRef {
|
|
461
|
+
table: string;
|
|
462
|
+
query: string;
|
|
463
|
+
rowCount: number;
|
|
464
|
+
durationMs: number;
|
|
465
|
+
timestamp: string;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
export declare class SqlGuard {
|
|
469
|
+
private readonly sensitiveTables;
|
|
470
|
+
private readonly allowedOperations;
|
|
471
|
+
private readonly rejectComments;
|
|
472
|
+
private readonly rejectUnion;
|
|
473
|
+
private readonly readOnlyAccount;
|
|
474
|
+
constructor(options?: SqlGuardOptions);
|
|
475
|
+
/**
|
|
476
|
+
* Validate a SQL string against all guard rules.
|
|
477
|
+
*
|
|
478
|
+
* Checks (in order):
|
|
479
|
+
* 1. Read-only account enforcement
|
|
480
|
+
* 2. Comment detection (SQL injection vector)
|
|
481
|
+
* 3. UNION / stacked query detection
|
|
482
|
+
* 4. Operation type whitelist
|
|
483
|
+
* 5. Sensitive table access
|
|
484
|
+
*/
|
|
485
|
+
validate(sql: string): SqlGuardResult;
|
|
486
|
+
/** Quick check: does the SQL contain any forbidden pattern? */
|
|
487
|
+
isSafe(sql: string): boolean;
|
|
488
|
+
/** Check if a whole word exists in the text. */
|
|
489
|
+
private _hasWord;
|
|
490
|
+
/** Detect the primary SQL operation (first keyword). */
|
|
491
|
+
private _detectOperation;
|
|
492
|
+
/** Count semicolons that are outside quoted string literals. */
|
|
493
|
+
private _countSemicolonsOutsideStrings;
|
|
494
|
+
private _escapeRegex;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
export declare interface SqlGuardOptions {
|
|
498
|
+
/** Table names that are off-limits */
|
|
499
|
+
sensitiveTables?: string[];
|
|
500
|
+
/** Allowed SQL operations (default: ['SELECT']) */
|
|
501
|
+
allowedOperations?: string[];
|
|
502
|
+
/** Whether to reject SQL containing comments */
|
|
503
|
+
rejectComments?: boolean;
|
|
504
|
+
/** Whether to reject UNION / stacked queries */
|
|
505
|
+
rejectUnion?: boolean;
|
|
506
|
+
/** Whether this guard represents a read-only DB account */
|
|
507
|
+
readOnlyAccount?: boolean;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* SQL Guard — client-side SQL validation for AI Assistant Core
|
|
512
|
+
*
|
|
513
|
+
* Detects dangerous patterns before sending SQL to the backend.
|
|
514
|
+
* This is a **defence-in-depth** layer; the backend must also enforce
|
|
515
|
+
* read-only constraints and parameterised queries.
|
|
516
|
+
*/
|
|
517
|
+
export declare interface SqlGuardResult {
|
|
518
|
+
/** Whether the SQL passes all checks */
|
|
519
|
+
allowed: boolean;
|
|
520
|
+
/** Human-readable reason when blocked */
|
|
521
|
+
reason?: string;
|
|
522
|
+
/** Sanitised SQL (if applicable) */
|
|
523
|
+
sanitizedSql?: string;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
export declare class SseClient {
|
|
527
|
+
private reader;
|
|
528
|
+
private abortCtrl;
|
|
529
|
+
private heartbeatTimer;
|
|
530
|
+
private timeoutTimer;
|
|
531
|
+
private reconnect;
|
|
532
|
+
private lastSeq;
|
|
533
|
+
private buffer;
|
|
534
|
+
private status;
|
|
535
|
+
private options;
|
|
536
|
+
private destroyed;
|
|
537
|
+
/** Current connection status */
|
|
538
|
+
get connectionStatus(): SseConnectionStatus;
|
|
539
|
+
/** Current reconnect attempt count */
|
|
540
|
+
get reconnectAttempt(): number;
|
|
541
|
+
/** Last acknowledged sequence number */
|
|
542
|
+
get currentSeq(): number;
|
|
543
|
+
start(options: SseClientOptions): Promise<void>;
|
|
544
|
+
/** Abort the current connection (does not destroy). */
|
|
545
|
+
abort(): void;
|
|
546
|
+
/** Permanently destroy — no further connections allowed. */
|
|
547
|
+
destroy(): void;
|
|
548
|
+
private _connect;
|
|
549
|
+
private _processChunk;
|
|
550
|
+
private _processLine;
|
|
551
|
+
private _parseEvent;
|
|
552
|
+
private _startHeartbeat;
|
|
553
|
+
private _handleHeartbeat;
|
|
554
|
+
private _handleError;
|
|
555
|
+
private _scheduleReconnect;
|
|
556
|
+
private _resetReconnect;
|
|
557
|
+
private _setStatus;
|
|
558
|
+
private _cancelReader;
|
|
559
|
+
private _clearTimers;
|
|
560
|
+
private _clearHeartbeat;
|
|
561
|
+
private _clearReconnectTimer;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
export declare interface SseClientOptions {
|
|
565
|
+
/** Target URL */
|
|
566
|
+
url: string;
|
|
567
|
+
/** POST body */
|
|
568
|
+
body: unknown;
|
|
569
|
+
/** Request headers */
|
|
570
|
+
headers: Record<string, string>;
|
|
571
|
+
/** Abort signal for cancellation */
|
|
572
|
+
signal?: AbortSignal;
|
|
573
|
+
/** Called for every parsed stream event */
|
|
574
|
+
onEvent?: (event: unknown) => void;
|
|
575
|
+
/** Called on unrecoverable errors */
|
|
576
|
+
onError?: (error: Error) => void;
|
|
577
|
+
/** Called when connection status changes */
|
|
578
|
+
onStatusChange?: (status: SseConnectionStatus) => void;
|
|
579
|
+
/** Heartbeat timeout in ms (default 15000) */
|
|
580
|
+
heartbeatMs?: number;
|
|
581
|
+
/** Request timeout in ms (default 90000) */
|
|
582
|
+
timeoutMs?: number;
|
|
583
|
+
/** Reconnect config */
|
|
584
|
+
reconnect?: {
|
|
585
|
+
max: number;
|
|
586
|
+
baseMs: number;
|
|
587
|
+
maxMs?: number;
|
|
588
|
+
resetOnSuccessMs?: number;
|
|
589
|
+
};
|
|
590
|
+
/** Last acknowledged sequence number (for resume) */
|
|
591
|
+
lastSeq?: number;
|
|
592
|
+
/**
|
|
593
|
+
* Resume hook, consulted ONLY when re-establishing a dropped stream (i.e. on a
|
|
594
|
+
* reconnect attempt, never the initial connect). Returns the additive body
|
|
595
|
+
* fields that let the backend replay from where the client left off —
|
|
596
|
+
* typically `{ conversationId, messageId, lastSeq }`. These are merged over the
|
|
597
|
+
* base body so the same `/chat/stream` endpoint serves both fresh sends and
|
|
598
|
+
* resumes (the 14-endpoint contract stays frozen). Any `lastSeq` returned here
|
|
599
|
+
* takes precedence over the client's internally tracked seq.
|
|
600
|
+
*/
|
|
601
|
+
resume?: () => Record<string, unknown> | undefined;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* SSE Client for AI Assistant Core
|
|
606
|
+
*
|
|
607
|
+
* Uses fetch + ReadableStream (not EventSource) to support:
|
|
608
|
+
* - POST requests with custom headers
|
|
609
|
+
* - AbortController cancellation
|
|
610
|
+
* - Custom event parsing and heartbeat handling
|
|
611
|
+
* - Sequence-based ack / resume protocol
|
|
612
|
+
* - Exponential backoff reconnection
|
|
613
|
+
*/
|
|
614
|
+
export declare type SseConnectionStatus = 'idle' | 'connecting' | 'streaming' | 'reconnecting' | 'closed' | 'error';
|
|
615
|
+
|
|
616
|
+
export declare type StateAction = {
|
|
617
|
+
type: 'OPEN';
|
|
618
|
+
mode?: AiOpenMode;
|
|
619
|
+
} | {
|
|
620
|
+
type: 'CLOSE';
|
|
621
|
+
} | {
|
|
622
|
+
type: 'TOGGLE';
|
|
623
|
+
} | {
|
|
624
|
+
type: 'SWITCH_MODE';
|
|
625
|
+
mode: AiOpenMode;
|
|
626
|
+
} | {
|
|
627
|
+
type: 'SET_POSITION';
|
|
628
|
+
x: number;
|
|
629
|
+
y: number;
|
|
630
|
+
} | {
|
|
631
|
+
type: 'SET_SIZE';
|
|
632
|
+
width: number;
|
|
633
|
+
height: number;
|
|
634
|
+
} | {
|
|
635
|
+
type: 'SET_SYSTEM_CODE';
|
|
636
|
+
systemCode: string;
|
|
637
|
+
} | {
|
|
638
|
+
type: 'SET_MODEL_CODE';
|
|
639
|
+
modelCode: string;
|
|
640
|
+
} | {
|
|
641
|
+
type: 'SET_CONVERSATION';
|
|
642
|
+
id: string | null;
|
|
643
|
+
} | {
|
|
644
|
+
type: 'ADD_CONVERSATION';
|
|
645
|
+
conversation: Conversation;
|
|
646
|
+
} | {
|
|
647
|
+
type: 'SET_CONVERSATIONS';
|
|
648
|
+
conversations: Conversation[];
|
|
649
|
+
} | {
|
|
650
|
+
type: 'APPEND_MESSAGE';
|
|
651
|
+
conversationId: string;
|
|
652
|
+
message: AssistantMessage;
|
|
653
|
+
} | {
|
|
654
|
+
type: 'APPEND_DELTA';
|
|
655
|
+
conversationId: string;
|
|
656
|
+
messageId: string;
|
|
657
|
+
delta: string;
|
|
658
|
+
} | {
|
|
659
|
+
type: 'UPDATE_MESSAGE_STATUS';
|
|
660
|
+
conversationId: string;
|
|
661
|
+
messageId: string;
|
|
662
|
+
status: MessageStatus;
|
|
663
|
+
} | {
|
|
664
|
+
type: 'SET_MESSAGES';
|
|
665
|
+
conversationId: string;
|
|
666
|
+
messages: AssistantMessage[];
|
|
667
|
+
} | {
|
|
668
|
+
type: 'APPEND_TOOL_STEP';
|
|
669
|
+
messageId: string;
|
|
670
|
+
step: ToolStep;
|
|
671
|
+
} | {
|
|
672
|
+
type: 'UPDATE_TOOL_STEP';
|
|
673
|
+
messageId: string;
|
|
674
|
+
stepId: string;
|
|
675
|
+
patch: Partial<ToolStep>;
|
|
676
|
+
} | {
|
|
677
|
+
type: 'SET_STREAM_STATUS';
|
|
678
|
+
status: AssistantState['streamStatus'];
|
|
679
|
+
} | {
|
|
680
|
+
type: 'SET_LAST_SEQ';
|
|
681
|
+
seq: number;
|
|
682
|
+
} | {
|
|
683
|
+
type: 'SET_HEARTBEAT';
|
|
684
|
+
ts: number;
|
|
685
|
+
} | {
|
|
686
|
+
type: 'INCREMENT_RECONNECT';
|
|
687
|
+
} | {
|
|
688
|
+
type: 'RESET_RECONNECT';
|
|
689
|
+
} | {
|
|
690
|
+
type: 'SET_THEME';
|
|
691
|
+
mode: AiThemeMode;
|
|
692
|
+
} | {
|
|
693
|
+
type: 'SET_PRIMARY_COLOR';
|
|
694
|
+
color: string;
|
|
695
|
+
} | {
|
|
696
|
+
type: 'SET_ERROR';
|
|
697
|
+
error: string | null;
|
|
698
|
+
} | {
|
|
699
|
+
type: 'HYDRATE';
|
|
700
|
+
state: Partial<AssistantState>;
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* StreamEvent union type — SSE protocol between frontend and backend
|
|
705
|
+
*/
|
|
706
|
+
export declare type StreamEvent = {
|
|
707
|
+
type: 'open';
|
|
708
|
+
conversationId: string;
|
|
709
|
+
messageId: string;
|
|
710
|
+
} | {
|
|
711
|
+
type: 'text.delta';
|
|
712
|
+
messageId: string;
|
|
713
|
+
seq: number;
|
|
714
|
+
content: string;
|
|
715
|
+
} | {
|
|
716
|
+
type: 'text.done';
|
|
717
|
+
messageId: string;
|
|
718
|
+
seq: number;
|
|
719
|
+
} | {
|
|
720
|
+
type: 'tool.start';
|
|
721
|
+
messageId: string;
|
|
722
|
+
step: {
|
|
723
|
+
stepId: string;
|
|
724
|
+
toolName: string;
|
|
725
|
+
title: string;
|
|
726
|
+
};
|
|
727
|
+
} | {
|
|
728
|
+
type: 'tool.progress';
|
|
729
|
+
messageId: string;
|
|
730
|
+
stepId: string;
|
|
731
|
+
percent?: number;
|
|
732
|
+
message?: string;
|
|
733
|
+
} | {
|
|
734
|
+
type: 'tool.result';
|
|
735
|
+
messageId: string;
|
|
736
|
+
stepId: string;
|
|
737
|
+
result: unknown;
|
|
738
|
+
} | {
|
|
739
|
+
type: 'chart';
|
|
740
|
+
messageId: string;
|
|
741
|
+
chart: unknown;
|
|
742
|
+
} | {
|
|
743
|
+
type: 'table';
|
|
744
|
+
messageId: string;
|
|
745
|
+
table: unknown;
|
|
746
|
+
} | {
|
|
747
|
+
type: 'sql';
|
|
748
|
+
messageId: string;
|
|
749
|
+
sql: unknown;
|
|
750
|
+
} | {
|
|
751
|
+
type: 'metric';
|
|
752
|
+
messageId: string;
|
|
753
|
+
metrics: unknown[];
|
|
754
|
+
} | {
|
|
755
|
+
type: 'action';
|
|
756
|
+
messageId: string;
|
|
757
|
+
actions: unknown[];
|
|
758
|
+
} | {
|
|
759
|
+
type: 'source';
|
|
760
|
+
messageId: string;
|
|
761
|
+
sources: unknown[];
|
|
762
|
+
} | {
|
|
763
|
+
type: 'suggestion';
|
|
764
|
+
messageId: string;
|
|
765
|
+
suggestions: string[];
|
|
766
|
+
} | {
|
|
767
|
+
type: 'risk';
|
|
768
|
+
messageId: string;
|
|
769
|
+
warnings: string[];
|
|
770
|
+
} | {
|
|
771
|
+
type: 'error';
|
|
772
|
+
messageId: string;
|
|
773
|
+
code: string;
|
|
774
|
+
message: string;
|
|
775
|
+
retriable: boolean;
|
|
776
|
+
} | {
|
|
777
|
+
type: 'done';
|
|
778
|
+
conversationId: string;
|
|
779
|
+
messageId: string;
|
|
780
|
+
totalTokens?: number;
|
|
781
|
+
} | {
|
|
782
|
+
type: 'heartbeat';
|
|
783
|
+
ts: number;
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
export declare interface TableInfo {
|
|
787
|
+
tableName: string;
|
|
788
|
+
tableComment?: string;
|
|
789
|
+
columns?: Array<{
|
|
790
|
+
columnName: string;
|
|
791
|
+
columnType: string;
|
|
792
|
+
columnComment?: string;
|
|
793
|
+
sensitive?: boolean;
|
|
794
|
+
}>;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
export declare interface TableResult {
|
|
798
|
+
columns: {
|
|
799
|
+
key: string;
|
|
800
|
+
title: string;
|
|
801
|
+
type?: string;
|
|
802
|
+
}[];
|
|
803
|
+
rows: Record<string, unknown>[];
|
|
804
|
+
total?: number;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
export declare function throttle<T extends (...args: unknown[]) => unknown>(fn: T, waitMs: number, options?: {
|
|
808
|
+
leading?: boolean;
|
|
809
|
+
trailing?: boolean;
|
|
810
|
+
}): ThrottledFunction<T>;
|
|
811
|
+
|
|
812
|
+
export declare interface ThrottledFunction<T extends (...args: unknown[]) => unknown> {
|
|
813
|
+
(...args: Parameters<T>): ReturnType<T> | undefined;
|
|
814
|
+
cancel: () => void;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
export declare interface ToolCall {
|
|
818
|
+
name: string;
|
|
819
|
+
args: Record<string, unknown>;
|
|
820
|
+
result?: unknown;
|
|
821
|
+
status: 'pending' | 'running' | 'success' | 'error';
|
|
822
|
+
durationMs?: number;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
export declare interface ToolDefinition {
|
|
826
|
+
name: string;
|
|
827
|
+
description: string;
|
|
828
|
+
parameters: Record<string, unknown>;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
export declare type ToolExecutor = (args: Record<string, unknown>) => Promise<unknown>;
|
|
832
|
+
|
|
833
|
+
export declare class ToolOrchestrator {
|
|
834
|
+
private readonly registry;
|
|
835
|
+
private readonly onStepStart?;
|
|
836
|
+
private readonly onStepComplete?;
|
|
837
|
+
private readonly onStepError?;
|
|
838
|
+
constructor(options: OrchestratorOptions);
|
|
839
|
+
/**
|
|
840
|
+
* Execute a plan of tool steps.
|
|
841
|
+
*
|
|
842
|
+
* - `serial`: steps run one after another; if one fails, abort the rest.
|
|
843
|
+
* - `parallel`: steps run concurrently; all results collected regardless of individual failures.
|
|
844
|
+
*/
|
|
845
|
+
execute(plan: ExecutionPlan): Promise<ToolStep[]>;
|
|
846
|
+
/** Execute a single tool step. */
|
|
847
|
+
executeSingle(toolName: string, args: Record<string, unknown>, title?: string): Promise<ToolStep>;
|
|
848
|
+
private executeSerial;
|
|
849
|
+
private executeParallel;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
export declare class ToolRegistry {
|
|
853
|
+
private readonly tools;
|
|
854
|
+
/** Register a tool with its definition and executor. */
|
|
855
|
+
register(definition: ToolDefinition, executor: ToolExecutor): void;
|
|
856
|
+
/** Unregister a tool by name. */
|
|
857
|
+
unregister(name: string): boolean;
|
|
858
|
+
/** Look up a registered tool. */
|
|
859
|
+
get(name: string): RegisteredTool | undefined;
|
|
860
|
+
/** Check whether a tool is registered. */
|
|
861
|
+
has(name: string): boolean;
|
|
862
|
+
/** List all registered tool names. */
|
|
863
|
+
list(): string[];
|
|
864
|
+
/** Get all definitions (for sending to LLM). */
|
|
865
|
+
getDefinitions(): ToolDefinition[];
|
|
866
|
+
/** Clear all registrations. */
|
|
867
|
+
clear(): void;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
export declare interface ToolStep {
|
|
871
|
+
stepId: string;
|
|
872
|
+
toolName: string;
|
|
873
|
+
title: string;
|
|
874
|
+
status: 'pending' | 'running' | 'success' | 'error';
|
|
875
|
+
args?: Record<string, unknown>;
|
|
876
|
+
result?: unknown;
|
|
877
|
+
durationMs?: number;
|
|
878
|
+
message?: string;
|
|
879
|
+
percent?: number;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
export declare interface TransportConfig {
|
|
883
|
+
type: 'sse' | 'ws';
|
|
884
|
+
heartbeatMs?: number;
|
|
885
|
+
timeoutMs?: number;
|
|
886
|
+
reconnect?: {
|
|
887
|
+
max: number;
|
|
888
|
+
baseMs: number;
|
|
889
|
+
maxMs?: number;
|
|
890
|
+
resetOnSuccessMs?: number;
|
|
891
|
+
};
|
|
892
|
+
fetchFallback?: boolean;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
export declare interface UserInfo {
|
|
896
|
+
userId: string;
|
|
897
|
+
username: string;
|
|
898
|
+
roles: string[];
|
|
899
|
+
orgId?: string;
|
|
900
|
+
areaPermissions?: string[];
|
|
901
|
+
dataScope?: 'all' | 'org' | 'area' | 'self';
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
export { }
|