@tagit/ai-client-core 0.1.0-beta.1
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/client.d.ts +98 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +876 -0
- package/dist/client.js.map +1 -0
- package/dist/client.test.d.ts +2 -0
- package/dist/client.test.d.ts.map +1 -0
- package/dist/client.test.js +545 -0
- package/dist/client.test.js.map +1 -0
- package/dist/config.d.ts +222 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +71 -0
- package/dist/config.js.map +1 -0
- package/dist/config.test.d.ts +2 -0
- package/dist/config.test.d.ts.map +1 -0
- package/dist/config.test.js +29 -0
- package/dist/config.test.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/transport.d.ts +13 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +11 -0
- package/dist/transport.js.map +1 -0
- package/dist/types.d.ts +257 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +44 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { ClientConfig, ClientEventListener, ConversationState } from './types.js';
|
|
2
|
+
import { type OrchestratorTransport } from './transport.js';
|
|
3
|
+
/**
|
|
4
|
+
* Headless AI client core
|
|
5
|
+
* Handles orchestrator communication, streaming, and conversation state
|
|
6
|
+
*/
|
|
7
|
+
export declare class AIClient {
|
|
8
|
+
private config;
|
|
9
|
+
private conversationState;
|
|
10
|
+
private eventListeners;
|
|
11
|
+
private abortController;
|
|
12
|
+
private abortReason;
|
|
13
|
+
private transport;
|
|
14
|
+
constructor(config: ClientConfig, options?: {
|
|
15
|
+
transport?: OrchestratorTransport;
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* Get current conversation state
|
|
19
|
+
*/
|
|
20
|
+
getState(): ConversationState;
|
|
21
|
+
/**
|
|
22
|
+
* Subscribe to client events
|
|
23
|
+
*/
|
|
24
|
+
on(listener: ClientEventListener): () => void;
|
|
25
|
+
/**
|
|
26
|
+
* Emit an event to all listeners
|
|
27
|
+
*/
|
|
28
|
+
private emit;
|
|
29
|
+
/**
|
|
30
|
+
* Truncate message content based on configured limits
|
|
31
|
+
*/
|
|
32
|
+
private truncateMessage;
|
|
33
|
+
/**
|
|
34
|
+
* Check if history exceeds max messages and emit warning event
|
|
35
|
+
*/
|
|
36
|
+
private checkAndTrimHistory;
|
|
37
|
+
/**
|
|
38
|
+
* Truncate error details to prevent massive error payloads
|
|
39
|
+
*/
|
|
40
|
+
private truncateErrorDetails;
|
|
41
|
+
/**
|
|
42
|
+
* Send a message and stream the response
|
|
43
|
+
*/
|
|
44
|
+
sendMessage(userMessage: string, options?: {
|
|
45
|
+
tools?: 'none' | 'all' | string[];
|
|
46
|
+
useCaseMessage?: string;
|
|
47
|
+
}): Promise<void>;
|
|
48
|
+
private streamResponseWithRetry;
|
|
49
|
+
/**
|
|
50
|
+
* Stream response from orchestrator
|
|
51
|
+
*/
|
|
52
|
+
private streamResponse;
|
|
53
|
+
/**
|
|
54
|
+
* Handle a single chunk from the orchestrator
|
|
55
|
+
*/
|
|
56
|
+
private handleChunk;
|
|
57
|
+
/**
|
|
58
|
+
* Drip-feed text word-by-word to simulate streaming when the server batched
|
|
59
|
+
* the entire response in one chunk. Targets ~1.5 s total regardless of length.
|
|
60
|
+
*/
|
|
61
|
+
private simulateDeltaStream;
|
|
62
|
+
private shouldRetry;
|
|
63
|
+
private tryParseJson;
|
|
64
|
+
private isCanonicalChunk;
|
|
65
|
+
private appendAssistantDelta;
|
|
66
|
+
private applyTerminalContent;
|
|
67
|
+
private handleNonStreamingResponse;
|
|
68
|
+
private extractAssistantText;
|
|
69
|
+
private shouldAcceptDegradedCompletion;
|
|
70
|
+
private hasAssistantContent;
|
|
71
|
+
private normalizeError;
|
|
72
|
+
private isClientErrorInfo;
|
|
73
|
+
private createError;
|
|
74
|
+
private findLatestAssistantMessage;
|
|
75
|
+
private buildCollectorEvent;
|
|
76
|
+
/**
|
|
77
|
+
* Emit a conversation event to the TagIt collector
|
|
78
|
+
*/
|
|
79
|
+
private emitCollectorEvent;
|
|
80
|
+
/**
|
|
81
|
+
* Cancel the current request
|
|
82
|
+
*/
|
|
83
|
+
cancel(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Clear conversation history
|
|
86
|
+
* Throws error if a request is currently in-flight
|
|
87
|
+
*/
|
|
88
|
+
clearHistory(): void;
|
|
89
|
+
/**
|
|
90
|
+
* Remove the message with the given id and all messages that follow it.
|
|
91
|
+
* Returns the content of the removed message so the caller can repopulate
|
|
92
|
+
* an input field (re-edit flow). Returns null if the client is in-flight
|
|
93
|
+
* or the messageId is not found.
|
|
94
|
+
*/
|
|
95
|
+
trimHistoryBefore(messageId: string): string | null;
|
|
96
|
+
}
|
|
97
|
+
export default AIClient;
|
|
98
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,YAAY,EAEZ,mBAAmB,EACnB,iBAAiB,EAMlB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,gBAAgB,CAAC;AASxB;;;GAGG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,cAAc,CAAuC;IAC7D,OAAO,CAAC,eAAe,CAAgC;IACvD,OAAO,CAAC,WAAW,CAAmC;IACtD,OAAO,CAAC,SAAS,CAAwB;gBAGvC,MAAM,EAAE,YAAY,EACpB,OAAO,CAAC,EAAE;QACR,SAAS,CAAC,EAAE,qBAAqB,CAAC;KACnC;IAaH;;O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