@illalabs/sdk 0.3.3-canary.b7f69a88 → 0.4.0-canary.1a04c18e
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 +68 -9
- package/dist/src/chat/Chat.d.ts +36 -4
- package/dist/src/chat/Chat.d.ts.map +1 -1
- package/dist/src/chat/Chat.js +134 -24
- package/dist/src/chat/Chat.js.map +1 -1
- package/dist/src/chat/errors/ChatInvalidMultiplePromptsKind.d.ts +22 -0
- package/dist/src/chat/errors/ChatInvalidMultiplePromptsKind.d.ts.map +1 -0
- package/dist/src/chat/errors/ChatInvalidMultiplePromptsKind.js +31 -0
- package/dist/src/chat/errors/ChatInvalidMultiplePromptsKind.js.map +1 -0
- package/dist/src/chat/errors/ChatInvalidPromptSnapshot.d.ts +19 -0
- package/dist/src/chat/errors/ChatInvalidPromptSnapshot.d.ts.map +1 -0
- package/dist/src/chat/errors/ChatInvalidPromptSnapshot.js +28 -0
- package/dist/src/chat/errors/ChatInvalidPromptSnapshot.js.map +1 -0
- package/dist/src/chat/errors/ChatInvalidSinglePromptKind.d.ts +22 -0
- package/dist/src/chat/errors/ChatInvalidSinglePromptKind.d.ts.map +1 -0
- package/dist/src/chat/errors/ChatInvalidSinglePromptKind.js +31 -0
- package/dist/src/chat/errors/ChatInvalidSinglePromptKind.js.map +1 -0
- package/dist/src/chat/errors/index.d.ts +3 -0
- package/dist/src/chat/errors/index.d.ts.map +1 -1
- package/dist/src/chat/errors/index.js +3 -0
- package/dist/src/chat/errors/index.js.map +1 -1
- package/dist/src/chat/utils/prompt.d.ts +3 -0
- package/dist/src/chat/utils/prompt.d.ts.map +1 -0
- package/dist/src/chat/utils/prompt.js +5 -0
- package/dist/src/chat/utils/prompt.js.map +1 -0
- package/dist/src/context/ContextManager.d.ts +2 -0
- package/dist/src/context/ContextManager.d.ts.map +1 -1
- package/dist/src/context/ContextManager.js +8 -1
- package/dist/src/context/ContextManager.js.map +1 -1
- package/dist/src/errors/SdkEmptyToolsResultsError.d.ts +19 -0
- package/dist/src/errors/SdkEmptyToolsResultsError.d.ts.map +1 -0
- package/dist/src/errors/SdkEmptyToolsResultsError.js +28 -0
- package/dist/src/errors/SdkEmptyToolsResultsError.js.map +1 -0
- package/dist/src/interfaces/chat.interface.d.ts +55 -3
- package/dist/src/interfaces/chat.interface.d.ts.map +1 -1
- package/dist/src/interfaces/contextManager.interface.d.ts +7 -1
- package/dist/src/interfaces/contextManager.interface.d.ts.map +1 -1
- package/dist/src/interfaces/coreApiProvider.interface.d.ts +13 -1
- package/dist/src/interfaces/coreApiProvider.interface.d.ts.map +1 -1
- package/dist/src/interfaces/index.d.ts +1 -1
- package/dist/src/interfaces/index.d.ts.map +1 -1
- package/dist/src/internal.d.ts +1 -0
- package/dist/src/internal.d.ts.map +1 -1
- package/dist/src/internal.js +1 -0
- package/dist/src/internal.js.map +1 -1
- package/dist/src/prompt/Prompt.d.ts +2 -10
- package/dist/src/prompt/Prompt.d.ts.map +1 -1
- package/dist/src/prompt/Prompt.js +9 -22
- package/dist/src/prompt/Prompt.js.map +1 -1
- package/dist/src/prompt/index.d.ts +1 -1
- package/dist/src/prompt/index.d.ts.map +1 -1
- package/dist/src/prompt/types.d.ts +7 -9
- package/dist/src/prompt/types.d.ts.map +1 -1
- package/dist/src/prompt/utils/cloneToolResult.d.ts +6 -6
- package/dist/src/prompt/utils/cloneToolResult.d.ts.map +1 -1
- package/dist/src/prompt/utils/cloneToolResult.js +11 -16
- package/dist/src/prompt/utils/cloneToolResult.js.map +1 -1
- package/dist/src/prompt/utils/index.d.ts +1 -3
- package/dist/src/prompt/utils/index.d.ts.map +1 -1
- package/dist/src/prompt/utils/index.js +1 -3
- package/dist/src/prompt/utils/index.js.map +1 -1
- package/dist/src/providers/coreApiProvider/CoreApiProvider.d.ts +40 -1
- package/dist/src/providers/coreApiProvider/CoreApiProvider.d.ts.map +1 -1
- package/dist/src/providers/coreApiProvider/CoreApiProvider.js +124 -2
- package/dist/src/providers/coreApiProvider/CoreApiProvider.js.map +1 -1
- package/dist/src/providers/coreApiProvider/index.d.ts +1 -1
- package/dist/src/providers/coreApiProvider/index.d.ts.map +1 -1
- package/dist/src/providers/coreApiProvider/types.d.ts +44 -0
- package/dist/src/providers/coreApiProvider/types.d.ts.map +1 -1
- package/dist/src/sdk.d.ts +312 -25
- package/dist/src/sdk.d.ts.map +1 -1
- package/dist/src/sdk.js +366 -26
- package/dist/src/sdk.js.map +1 -1
- package/dist/src/streaming/errors/SSEParse.d.ts +15 -0
- package/dist/src/streaming/errors/SSEParse.d.ts.map +1 -0
- package/dist/src/streaming/errors/SSEParse.js +23 -0
- package/dist/src/streaming/errors/SSEParse.js.map +1 -0
- package/dist/src/streaming/errors/StreamingHttpError.d.ts +18 -0
- package/dist/src/streaming/errors/StreamingHttpError.d.ts.map +1 -0
- package/dist/src/streaming/errors/StreamingHttpError.js +27 -0
- package/dist/src/streaming/errors/StreamingHttpError.js.map +1 -0
- package/dist/src/streaming/errors/StreamingResponseBodyNull.d.ts +13 -0
- package/dist/src/streaming/errors/StreamingResponseBodyNull.d.ts.map +1 -0
- package/dist/src/streaming/errors/StreamingResponseBodyNull.js +21 -0
- package/dist/src/streaming/errors/StreamingResponseBodyNull.js.map +1 -0
- package/dist/src/streaming/errors/StreamingServerError.d.ts +23 -0
- package/dist/src/streaming/errors/StreamingServerError.d.ts.map +1 -0
- package/dist/src/streaming/errors/StreamingServerError.js +33 -0
- package/dist/src/streaming/errors/StreamingServerError.js.map +1 -0
- package/dist/src/streaming/errors/index.d.ts +5 -0
- package/dist/src/streaming/errors/index.d.ts.map +1 -0
- package/dist/src/streaming/errors/index.js +5 -0
- package/dist/src/streaming/errors/index.js.map +1 -0
- package/dist/src/streaming/index.d.ts +4 -0
- package/dist/src/streaming/index.d.ts.map +1 -0
- package/dist/src/streaming/index.js +3 -0
- package/dist/src/streaming/index.js.map +1 -0
- package/dist/src/streaming/parseSSE.d.ts +23 -0
- package/dist/src/streaming/parseSSE.d.ts.map +1 -0
- package/dist/src/streaming/parseSSE.js +152 -0
- package/dist/src/streaming/parseSSE.js.map +1 -0
- package/dist/src/streaming/types.d.ts +6 -0
- package/dist/src/streaming/types.d.ts.map +1 -0
- package/dist/src/streaming/types.js +6 -0
- package/dist/src/streaming/types.js.map +1 -0
- package/dist/src/telemetry/TelemetryClient.d.ts +140 -0
- package/dist/src/telemetry/TelemetryClient.d.ts.map +1 -0
- package/dist/src/telemetry/TelemetryClient.js +225 -0
- package/dist/src/telemetry/TelemetryClient.js.map +1 -0
- package/dist/src/telemetry/index.d.ts +2 -0
- package/dist/src/telemetry/index.d.ts.map +1 -0
- package/dist/src/telemetry/index.js +2 -0
- package/dist/src/telemetry/index.js.map +1 -0
- package/package.json +3 -5
- package/dist/src/chat/errors/ChatInvalidModelContext.d.ts +0 -15
- package/dist/src/chat/errors/ChatInvalidModelContext.d.ts.map +0 -1
- package/dist/src/chat/errors/ChatInvalidModelContext.js +0 -24
- package/dist/src/chat/errors/ChatInvalidModelContext.js.map +0 -1
- package/dist/src/prompt/utils/normalizeTextPrompt.d.ts +0 -14
- package/dist/src/prompt/utils/normalizeTextPrompt.d.ts.map +0 -1
- package/dist/src/prompt/utils/normalizeTextPrompt.js +0 -22
- package/dist/src/prompt/utils/normalizeTextPrompt.js.map +0 -1
- package/dist/src/prompt/utils/normalizeToolResult.d.ts +0 -14
- package/dist/src/prompt/utils/normalizeToolResult.d.ts.map +0 -1
- package/dist/src/prompt/utils/normalizeToolResult.js +0 -27
- package/dist/src/prompt/utils/normalizeToolResult.js.map +0 -1
package/README.md
CHANGED
|
@@ -52,6 +52,8 @@ const result2 = await sdk.sendMessage("I want to swap 1 ETH for USDC on Base", {
|
|
|
52
52
|
When the AI needs to execute blockchain operations, it will return pending tools:
|
|
53
53
|
|
|
54
54
|
```typescript
|
|
55
|
+
import { IllaToolError, IllaToolOutcome } from "@illalabs/interfaces";
|
|
56
|
+
|
|
55
57
|
const result = await sdk.sendMessage("Swap 1 ETH for USDC on Base", {
|
|
56
58
|
userContext: { address: "0x..." },
|
|
57
59
|
});
|
|
@@ -60,17 +62,21 @@ const result = await sdk.sendMessage("Swap 1 ETH for USDC on Base", {
|
|
|
60
62
|
if (result.response.pendingTools && result.response.pendingTools.length > 0) {
|
|
61
63
|
const tool = result.response.pendingTools[0];
|
|
62
64
|
|
|
63
|
-
// Execute the tool
|
|
64
|
-
|
|
65
|
+
// Execute the tool and create the outcome
|
|
66
|
+
let toolResult: IllaToolOutcome;
|
|
67
|
+
try {
|
|
68
|
+
const executionResult = await executeTool(tool);
|
|
69
|
+
toolResult = IllaToolOutcome.success(tool.toolCallId, tool.toolName, executionResult);
|
|
70
|
+
} catch (error) {
|
|
71
|
+
toolResult = IllaToolOutcome.error(
|
|
72
|
+
tool.toolCallId,
|
|
73
|
+
tool.toolName,
|
|
74
|
+
IllaToolError.execution(tool.toolCallId, tool.toolName, error.message),
|
|
75
|
+
);
|
|
76
|
+
}
|
|
65
77
|
|
|
66
78
|
// Send the result back to the AI
|
|
67
|
-
const
|
|
68
|
-
toolCallId: tool.toolCallId,
|
|
69
|
-
toolName: tool.toolName,
|
|
70
|
-
result: executionResult,
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const followUp = await sdk.sendToolResult(result.chatId, toolResult);
|
|
79
|
+
const followUp = await sdk.sendToolResult(result.chatId, toolResult.toJSON());
|
|
74
80
|
console.log(followUp.response.text);
|
|
75
81
|
}
|
|
76
82
|
```
|
|
@@ -225,9 +231,62 @@ E2E_API_KEY=your-api-key E2E_FORK_BASE_RPC_URL="https://mainnet.base.org" pnpm t
|
|
|
225
231
|
- **Multi-turn Conversations**: Seamless context preservation across messages
|
|
226
232
|
- **Session Persistence**: Resume conversations across different instances
|
|
227
233
|
- **Async Tool Monitoring**: Built-in support for long-running blockchain operations
|
|
234
|
+
- **Streaming Responses**: Real-time telemetry and text streaming via SSE
|
|
228
235
|
- **TypeScript-first**: Full type safety with comprehensive type definitions
|
|
229
236
|
- **Flexible Caching**: Pluggable cache implementations (in-memory, Redis, etc.)
|
|
230
237
|
|
|
238
|
+
## Streaming
|
|
239
|
+
|
|
240
|
+
The SDK supports streaming responses via Server-Sent Events (SSE). This allows you to receive telemetry events and text in real-time as the AI processes your request.
|
|
241
|
+
|
|
242
|
+
### Required Header
|
|
243
|
+
|
|
244
|
+
To enable streaming, the request must include the `Accept: text/event-stream` header. The SDK handles this automatically when using the streaming methods.
|
|
245
|
+
|
|
246
|
+
### Usage
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
import { IllaSDK, Prompt } from "@illalabs/sdk";
|
|
250
|
+
|
|
251
|
+
const sdk = new IllaSDK({ apiKey: "your-api-key" });
|
|
252
|
+
const chat = sdk.createChat({ userContext: { address: "0x..." } });
|
|
253
|
+
|
|
254
|
+
await chat.sendMessageStreaming(new Prompt({ text: "What is my balance?" }), {
|
|
255
|
+
// Called for each telemetry event (including text_delta for streaming text)
|
|
256
|
+
onEvent: (event) => {
|
|
257
|
+
console.log("Event:", event.type);
|
|
258
|
+
},
|
|
259
|
+
// Called specifically for text chunks as they arrive
|
|
260
|
+
onTextDelta: (delta) => {
|
|
261
|
+
process.stdout.write(delta);
|
|
262
|
+
},
|
|
263
|
+
// Called when the complete response is ready
|
|
264
|
+
onComplete: (result) => {
|
|
265
|
+
console.log("\nComplete:", result.text);
|
|
266
|
+
},
|
|
267
|
+
// Called if an error occurs during streaming
|
|
268
|
+
onError: (error) => {
|
|
269
|
+
console.error("Error:", error.message);
|
|
270
|
+
},
|
|
271
|
+
});
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### Direct Provider Usage
|
|
275
|
+
|
|
276
|
+
When using `CoreApiProvider` directly with fetch, include the header manually:
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
const response = await fetch(url, {
|
|
280
|
+
method: "POST",
|
|
281
|
+
headers: {
|
|
282
|
+
"Content-Type": "application/json",
|
|
283
|
+
Accept: "text/event-stream", // Required for streaming
|
|
284
|
+
"x-api-key": "your-api-key",
|
|
285
|
+
},
|
|
286
|
+
body: stringify(requestBody),
|
|
287
|
+
});
|
|
288
|
+
```
|
|
289
|
+
|
|
231
290
|
## 📦 Project Structure
|
|
232
291
|
|
|
233
292
|
```plaintext
|
package/dist/src/chat/Chat.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MessageHistoryType } from "@illalabs/interfaces";
|
|
2
2
|
import type { AwaitableActionDescriptor, AwaitActionResult } from "../asyncToolChecker/index.js";
|
|
3
|
-
import type { ChatContextSnapshot, ChatOptions, SendMessageResult } from "../interfaces/index.js";
|
|
3
|
+
import type { ChatContextSnapshot, ChatOptions, SendMessageOptions, SendMessageResult, SendMessageStreamingOptions } from "../interfaces/index.js";
|
|
4
4
|
import type { Prompt } from "../prompt/index.js";
|
|
5
5
|
/**
|
|
6
6
|
* Represents a conversational session with the Illa Core API.
|
|
@@ -30,13 +30,45 @@ export declare class Chat {
|
|
|
30
30
|
getId(): string;
|
|
31
31
|
get messages(): Promise<MessageHistoryType>;
|
|
32
32
|
/**
|
|
33
|
-
* Sends a prompt to the Core API and returns the processed result.
|
|
33
|
+
* Sends a prompt or array of prompts to the Core API and returns the processed result.
|
|
34
34
|
*
|
|
35
|
-
* @param prompt Prompt instance
|
|
35
|
+
* @param prompt Either a single Prompt instance (must be kind "text") or an array of Prompts (all must be kind "tool-result").
|
|
36
|
+
* @param options Optional request options including abort signal and telemetry callback.
|
|
37
|
+
*
|
|
38
|
+
* @throws {ChatInvalidSinglePromptKind} When a single prompt is provided but is not of kind "text".
|
|
39
|
+
* @throws {ChatInvalidMultiplePromptsKind} When an array of prompts is provided but not all are of kind "tool-result".
|
|
36
40
|
*
|
|
37
41
|
* @returns Structured chat result containing the processed response.
|
|
38
42
|
*/
|
|
39
|
-
sendMessage(prompt: Prompt): Promise<SendMessageResult>;
|
|
43
|
+
sendMessage(prompt: Prompt | Prompt[], options?: SendMessageOptions): Promise<SendMessageResult>;
|
|
44
|
+
/**
|
|
45
|
+
* Sends a message with streaming response via SSE.
|
|
46
|
+
*
|
|
47
|
+
* Instead of waiting for the full response, this method streams telemetry events
|
|
48
|
+
* in real-time as they occur during orchestration. The final result is delivered
|
|
49
|
+
* through the `onComplete` callback.
|
|
50
|
+
*
|
|
51
|
+
* This eliminates the need for a separate telemetry subscription - events and
|
|
52
|
+
* the result are delivered through a single HTTP connection.
|
|
53
|
+
*
|
|
54
|
+
* @param prompt A single Prompt instance of kind "text".
|
|
55
|
+
* @param options Streaming options with event callbacks.
|
|
56
|
+
*
|
|
57
|
+
* @throws {ChatInvalidSinglePromptKind} When the prompt is not of kind "text".
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* await chat.sendMessageStreaming(
|
|
62
|
+
* new Prompt({ text: "Show me my balance" }),
|
|
63
|
+
* {
|
|
64
|
+
* onEvent: (event) => console.log('Event:', event.type),
|
|
65
|
+
* onComplete: (result) => console.log('Done:', result.text),
|
|
66
|
+
* onError: (error) => console.error('Error:', error),
|
|
67
|
+
* }
|
|
68
|
+
* );
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
sendMessageStreaming(prompt: Prompt, options?: SendMessageStreamingOptions): Promise<void>;
|
|
40
72
|
private buildRequest;
|
|
41
73
|
private static isSuccessResponse;
|
|
42
74
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/chat/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIR,kBAAkB,EAKrB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/chat/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIR,kBAAkB,EAKrB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAER,yBAAyB,EACzB,iBAAiB,EACpB,MAAM,8BAA8B,CAAC;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G;IACU,UAAU,CAAC,QAAQ,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;CAIxE"}
|
package/dist/src/chat/Chat.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ModelContextSchema } from "@illalabs/interfaces";
|
|
2
1
|
import { ChatAsyncToolCheckerUnavailable } from "./errors/ChatAsyncToolCheckerUnavailable.js";
|
|
3
|
-
import {
|
|
2
|
+
import { ChatInvalidMultiplePromptsKind } from "./errors/ChatInvalidMultiplePromptsKind.js";
|
|
3
|
+
import { ChatInvalidPromptSnapshot } from "./errors/ChatInvalidPromptSnapshot.js";
|
|
4
|
+
import { ChatInvalidSinglePromptKind } from "./errors/ChatInvalidSinglePromptKind.js";
|
|
4
5
|
import { generateUUID } from "./utils/index.js";
|
|
5
6
|
/**
|
|
6
7
|
* Represents a conversational session with the Illa Core API.
|
|
@@ -29,16 +30,10 @@ export class Chat {
|
|
|
29
30
|
this.defaultRole = options.defaultRole ?? "user";
|
|
30
31
|
this.userContext = options.userContext;
|
|
31
32
|
this.personalityContext = options.personalityContext ?? { channel: "text" };
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
this.modelContext = modelContext.data;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
this.modelContext = { provider: "openai", model: "gpt-5-mini-2025-08-07" };
|
|
41
|
-
}
|
|
33
|
+
this.modelContext = options.modelContext ?? {
|
|
34
|
+
provider: "openai",
|
|
35
|
+
model: "gpt-5-mini-2025-08-07",
|
|
36
|
+
};
|
|
42
37
|
}
|
|
43
38
|
/**
|
|
44
39
|
* Retrieves the identifier associated with this chat instance.
|
|
@@ -52,21 +47,64 @@ export class Chat {
|
|
|
52
47
|
return this.contextManager.getContext(this.id).then((context) => context.messages);
|
|
53
48
|
}
|
|
54
49
|
/**
|
|
55
|
-
* Sends a prompt to the Core API and returns the processed result.
|
|
50
|
+
* Sends a prompt or array of prompts to the Core API and returns the processed result.
|
|
56
51
|
*
|
|
57
|
-
* @param prompt Prompt instance
|
|
52
|
+
* @param prompt Either a single Prompt instance (must be kind "text") or an array of Prompts (all must be kind "tool-result").
|
|
53
|
+
* @param options Optional request options including abort signal and telemetry callback.
|
|
54
|
+
*
|
|
55
|
+
* @throws {ChatInvalidSinglePromptKind} When a single prompt is provided but is not of kind "text".
|
|
56
|
+
* @throws {ChatInvalidMultiplePromptsKind} When an array of prompts is provided but not all are of kind "tool-result".
|
|
58
57
|
*
|
|
59
58
|
* @returns Structured chat result containing the processed response.
|
|
60
59
|
*/
|
|
61
|
-
async sendMessage(prompt) {
|
|
62
|
-
|
|
63
|
-
const
|
|
60
|
+
async sendMessage(prompt, options) {
|
|
61
|
+
// Validate prompt kinds based on single vs array
|
|
62
|
+
const isMulti = Array.isArray(prompt);
|
|
63
|
+
const prompts = isMulti ? prompt : [prompt];
|
|
64
|
+
const snapshots = prompts.map((p) => p.getSnapshot());
|
|
65
|
+
if (isMulti) {
|
|
66
|
+
const hasInvalid = snapshots.some((snapshot) => snapshot.kind !== "tool-result");
|
|
67
|
+
if (hasInvalid) {
|
|
68
|
+
throw new ChatInvalidMultiplePromptsKind({
|
|
69
|
+
chatId: this.id,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
const snapshot = snapshots[0];
|
|
75
|
+
if (!snapshot || snapshot.kind !== "text") {
|
|
76
|
+
throw new ChatInvalidSinglePromptKind({
|
|
77
|
+
chatId: this.id,
|
|
78
|
+
kind: snapshot?.kind,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const normalizedPromptsArray = prompts.map((p) => p.getNormalizedSnapshot());
|
|
83
|
+
const promptSnapshot = isMulti ? snapshots : snapshots[0];
|
|
84
|
+
if (!promptSnapshot || normalizedPromptsArray.length === 0) {
|
|
85
|
+
throw new ChatInvalidPromptSnapshot({
|
|
86
|
+
chatId: this.id,
|
|
87
|
+
snapshot: promptSnapshot ?? [],
|
|
88
|
+
});
|
|
89
|
+
}
|
|
64
90
|
const originalContext = await this.contextManager.getContext(this.id);
|
|
65
|
-
const { body, messages: stagedMessages } = this.buildRequest(originalContext,
|
|
66
|
-
|
|
91
|
+
const { body, messages: stagedMessages } = this.buildRequest(originalContext, normalizedPromptsArray);
|
|
92
|
+
// Track requestId for the result
|
|
93
|
+
let capturedRequestId;
|
|
94
|
+
const requestOptions = options
|
|
95
|
+
? {
|
|
96
|
+
signal: options.signal,
|
|
97
|
+
onRequestId: (id) => {
|
|
98
|
+
capturedRequestId = id;
|
|
99
|
+
options.onRequestId?.(id);
|
|
100
|
+
},
|
|
101
|
+
}
|
|
102
|
+
: undefined;
|
|
103
|
+
const response = await this.coreApiProvider.sendMessage(body, requestOptions);
|
|
67
104
|
if (!Chat.isSuccessResponse(response)) {
|
|
68
105
|
return {
|
|
69
106
|
chatId: this.id,
|
|
107
|
+
requestId: capturedRequestId,
|
|
70
108
|
prompt: body.prompt,
|
|
71
109
|
promptSnapshot,
|
|
72
110
|
messages: stagedMessages,
|
|
@@ -81,6 +119,7 @@ export class Chat {
|
|
|
81
119
|
await this.contextManager.setToolsConfig(this.id, originalContext.toolsConfig);
|
|
82
120
|
return {
|
|
83
121
|
chatId: this.id,
|
|
122
|
+
requestId: response.requestId ?? capturedRequestId,
|
|
84
123
|
prompt: body.prompt,
|
|
85
124
|
promptSnapshot,
|
|
86
125
|
messages: response.messages,
|
|
@@ -91,21 +130,92 @@ export class Chat {
|
|
|
91
130
|
},
|
|
92
131
|
};
|
|
93
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Sends a message with streaming response via SSE.
|
|
135
|
+
*
|
|
136
|
+
* Instead of waiting for the full response, this method streams telemetry events
|
|
137
|
+
* in real-time as they occur during orchestration. The final result is delivered
|
|
138
|
+
* through the `onComplete` callback.
|
|
139
|
+
*
|
|
140
|
+
* This eliminates the need for a separate telemetry subscription - events and
|
|
141
|
+
* the result are delivered through a single HTTP connection.
|
|
142
|
+
*
|
|
143
|
+
* @param prompt A single Prompt instance of kind "text".
|
|
144
|
+
* @param options Streaming options with event callbacks.
|
|
145
|
+
*
|
|
146
|
+
* @throws {ChatInvalidSinglePromptKind} When the prompt is not of kind "text".
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```typescript
|
|
150
|
+
* await chat.sendMessageStreaming(
|
|
151
|
+
* new Prompt({ text: "Show me my balance" }),
|
|
152
|
+
* {
|
|
153
|
+
* onEvent: (event) => console.log('Event:', event.type),
|
|
154
|
+
* onComplete: (result) => console.log('Done:', result.text),
|
|
155
|
+
* onError: (error) => console.error('Error:', error),
|
|
156
|
+
* }
|
|
157
|
+
* );
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
async sendMessageStreaming(prompt, options = {}) {
|
|
161
|
+
const snapshot = prompt.getSnapshot();
|
|
162
|
+
if (snapshot.kind !== "text") {
|
|
163
|
+
throw new ChatInvalidSinglePromptKind({
|
|
164
|
+
chatId: this.id,
|
|
165
|
+
kind: snapshot.kind,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
const normalizedPrompt = [prompt.getNormalizedSnapshot()];
|
|
169
|
+
const context = await this.contextManager.getContext(this.id);
|
|
170
|
+
const { body } = this.buildRequest(context, normalizedPrompt);
|
|
171
|
+
await this.coreApiProvider.sendMessageStreaming(body, {
|
|
172
|
+
signal: options.signal,
|
|
173
|
+
onEvent: options.onEvent,
|
|
174
|
+
onTextDelta: options.onTextDelta,
|
|
175
|
+
onComplete: (result) => {
|
|
176
|
+
void (async () => {
|
|
177
|
+
try {
|
|
178
|
+
await this.contextManager.setMessages(this.id, result.messages);
|
|
179
|
+
await this.contextManager.setToolsConfig(this.id, context.toolsConfig);
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
options.onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
options.onComplete?.(result);
|
|
186
|
+
})();
|
|
187
|
+
},
|
|
188
|
+
onError: options.onError,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
94
191
|
buildRequest(context, normalizedPrompt) {
|
|
95
|
-
|
|
192
|
+
const baseBodyRequest = {
|
|
96
193
|
body: {
|
|
97
194
|
toolsConfig: context.toolsConfig,
|
|
98
195
|
messages: context.messages,
|
|
99
196
|
userContext: this.userContext,
|
|
100
|
-
prompt: normalizedPrompt.kind === "text" ? normalizedPrompt.message : undefined,
|
|
101
|
-
// At the moment we only send one tool result at a time, so we wrap it in an array.
|
|
102
|
-
toolResults: normalizedPrompt.kind === "tool-result" ? [normalizedPrompt.prompt] : undefined,
|
|
103
197
|
personalityContext: this.personalityContext,
|
|
104
|
-
languageModel: this.modelContext.model
|
|
198
|
+
languageModel: `${this.modelContext.provider}:${this.modelContext.model}`,
|
|
105
199
|
},
|
|
106
200
|
messages: context.messages,
|
|
107
201
|
toolsConfig: context.toolsConfig,
|
|
108
202
|
};
|
|
203
|
+
const textPrompt = normalizedPrompt.find((p) => p.type === "text");
|
|
204
|
+
const toolResultPrompts = normalizedPrompt.filter((p) => p.type === "tool-result");
|
|
205
|
+
const promptValue = textPrompt
|
|
206
|
+
? {
|
|
207
|
+
role: "user",
|
|
208
|
+
content: [{ type: "text", text: textPrompt.text }],
|
|
209
|
+
}
|
|
210
|
+
: undefined;
|
|
211
|
+
return {
|
|
212
|
+
...baseBodyRequest,
|
|
213
|
+
body: {
|
|
214
|
+
...baseBodyRequest.body,
|
|
215
|
+
toolResults: toolResultPrompts.flatMap((p) => p.toolResults),
|
|
216
|
+
prompt: promptValue,
|
|
217
|
+
},
|
|
218
|
+
};
|
|
109
219
|
}
|
|
110
220
|
static isSuccessResponse(response) {
|
|
111
221
|
return "status" in response && response.status === 200;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Chat.js","sourceRoot":"","sources":["../../../src/chat/Chat.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version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;YAC7B,UAAU,EAAE,UAAU,CAAC,IAAI;SAC9B,CAAC,CAAC;IACP,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,UAAU;QACnB,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACnD,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,UAAU,CAAC,QAA6B;QACjD,MAAM,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAClE,MAAM,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC5E,CAAC;CACJ"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error emitted when an array of prompts contains prompts that are not all of kind "tool-result".
|
|
3
|
+
*
|
|
4
|
+
* When sending multiple prompts as an array, all prompts must be of kind "tool-result".
|
|
5
|
+
* If you need to send a text prompt, send it as a single prompt instead.
|
|
6
|
+
*
|
|
7
|
+
* The error may include a `context` property with additional debugging information
|
|
8
|
+
* such as the `chatId` and the indices of invalid prompts.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ChatInvalidMultiplePromptsKind extends Error {
|
|
11
|
+
/**
|
|
12
|
+
* Optional context describing the invalid prompts and chat details.
|
|
13
|
+
*/
|
|
14
|
+
readonly context?: unknown;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new {@link ChatInvalidMultiplePromptsKind} instance.
|
|
17
|
+
*
|
|
18
|
+
* @param context Additional context useful for debugging, e.g. `{ chatId: string, invalidIndices: number[] }`.
|
|
19
|
+
*/
|
|
20
|
+
constructor(context?: unknown);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=ChatInvalidMultiplePromptsKind.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatInvalidMultiplePromptsKind.d.ts","sourceRoot":"","sources":["../../../../src/chat/errors/ChatInvalidMultiplePromptsKind.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,qBAAa,8BAA+B,SAAQ,KAAK;IACrD;;OAEG;IACH,SAAgB,OAAO,CAAC,EAAE,OAAO,CAAC;IAElC;;;;OAIG;gBACgB,OAAO,CAAC,EAAE,OAAO;CAYvC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error emitted when an array of prompts contains prompts that are not all of kind "tool-result".
|
|
3
|
+
*
|
|
4
|
+
* When sending multiple prompts as an array, all prompts must be of kind "tool-result".
|
|
5
|
+
* If you need to send a text prompt, send it as a single prompt instead.
|
|
6
|
+
*
|
|
7
|
+
* The error may include a `context` property with additional debugging information
|
|
8
|
+
* such as the `chatId` and the indices of invalid prompts.
|
|
9
|
+
*/
|
|
10
|
+
export class ChatInvalidMultiplePromptsKind extends Error {
|
|
11
|
+
/**
|
|
12
|
+
* Optional context describing the invalid prompts and chat details.
|
|
13
|
+
*/
|
|
14
|
+
context;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new {@link ChatInvalidMultiplePromptsKind} instance.
|
|
17
|
+
*
|
|
18
|
+
* @param context Additional context useful for debugging, e.g. `{ chatId: string, invalidIndices: number[] }`.
|
|
19
|
+
*/
|
|
20
|
+
constructor(context) {
|
|
21
|
+
super("When sending multiple prompts, all prompts must be of kind 'tool-result'. Found prompts with other kinds.");
|
|
22
|
+
this.name = "ChatInvalidMultiplePromptsKind";
|
|
23
|
+
if (context !== undefined) {
|
|
24
|
+
Object.defineProperty(this, "context", {
|
|
25
|
+
value: context,
|
|
26
|
+
enumerable: true,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=ChatInvalidMultiplePromptsKind.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatInvalidMultiplePromptsKind.js","sourceRoot":"","sources":["../../../../src/chat/errors/ChatInvalidMultiplePromptsKind.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IACrD;;OAEG;IACa,OAAO,CAAW;IAElC;;;;OAIG;IACH,YAAmB,OAAiB;QAChC,KAAK,CACD,2GAA2G,CAC9G,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;QAC7C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,EAAE;gBACnC,KAAK,EAAE,OAAO;gBACd,UAAU,EAAE,IAAI;aACnB,CAAC,CAAC;QACP,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error emitted when a prompt snapshot is invalid.
|
|
3
|
+
*
|
|
4
|
+
* The error may include a `context` property with additional debugging information
|
|
5
|
+
* such as the `chatId` and the invalid snapshot.
|
|
6
|
+
*/
|
|
7
|
+
export declare class ChatInvalidPromptSnapshot extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* Optional context describing the invalid prompts and chat details.
|
|
10
|
+
*/
|
|
11
|
+
readonly context?: unknown;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new {@link ChatInvalidPromptSnapshot} instance.
|
|
14
|
+
*
|
|
15
|
+
* @param context Additional context useful for debugging, e.g. `{ chatId: string, invalidIndices: number[] }`.
|
|
16
|
+
*/
|
|
17
|
+
constructor(context?: unknown);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=ChatInvalidPromptSnapshot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatInvalidPromptSnapshot.d.ts","sourceRoot":"","sources":["../../../../src/chat/errors/ChatInvalidPromptSnapshot.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qBAAa,yBAA0B,SAAQ,KAAK;IAChD;;OAEG;IACH,SAAgB,OAAO,CAAC,EAAE,OAAO,CAAC;IAElC;;;;OAIG;gBACgB,OAAO,CAAC,EAAE,OAAO;CAYvC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error emitted when a prompt snapshot is invalid.
|
|
3
|
+
*
|
|
4
|
+
* The error may include a `context` property with additional debugging information
|
|
5
|
+
* such as the `chatId` and the invalid snapshot.
|
|
6
|
+
*/
|
|
7
|
+
export class ChatInvalidPromptSnapshot extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* Optional context describing the invalid prompts and chat details.
|
|
10
|
+
*/
|
|
11
|
+
context;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new {@link ChatInvalidPromptSnapshot} instance.
|
|
14
|
+
*
|
|
15
|
+
* @param context Additional context useful for debugging, e.g. `{ chatId: string, invalidIndices: number[] }`.
|
|
16
|
+
*/
|
|
17
|
+
constructor(context) {
|
|
18
|
+
super("Invalid prompt snapshot. Expected kind 'tool-result' or 'text', but got something else.");
|
|
19
|
+
this.name = "ChatInvalidPromptSnapshot";
|
|
20
|
+
if (context !== undefined) {
|
|
21
|
+
Object.defineProperty(this, "context", {
|
|
22
|
+
value: context,
|
|
23
|
+
enumerable: true,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=ChatInvalidPromptSnapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatInvalidPromptSnapshot.js","sourceRoot":"","sources":["../../../../src/chat/errors/ChatInvalidPromptSnapshot.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAChD;;OAEG;IACa,OAAO,CAAW;IAElC;;;;OAIG;IACH,YAAmB,OAAiB;QAChC,KAAK,CACD,yFAAyF,CAC5F,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;QACxC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,EAAE;gBACnC,KAAK,EAAE,OAAO;gBACd,UAAU,EAAE,IAAI;aACnB,CAAC,CAAC;QACP,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error emitted when a single prompt is sent with an invalid kind.
|
|
3
|
+
*
|
|
4
|
+
* Single prompts must be of kind "text" only. If you need to send tool results,
|
|
5
|
+
* use an array of prompts instead.
|
|
6
|
+
*
|
|
7
|
+
* The error may include a `context` property with additional debugging information
|
|
8
|
+
* such as the `chatId` and the actual `kind` that was provided.
|
|
9
|
+
*/
|
|
10
|
+
export declare class ChatInvalidSinglePromptKind extends Error {
|
|
11
|
+
/**
|
|
12
|
+
* Optional context describing the invalid prompt kind and chat details.
|
|
13
|
+
*/
|
|
14
|
+
readonly context?: unknown;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new {@link ChatInvalidSinglePromptKind} instance.
|
|
17
|
+
*
|
|
18
|
+
* @param context Additional context useful for debugging, e.g. `{ chatId: string, kind: string }`.
|
|
19
|
+
*/
|
|
20
|
+
constructor(context?: unknown);
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=ChatInvalidSinglePromptKind.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatInvalidSinglePromptKind.d.ts","sourceRoot":"","sources":["../../../../src/chat/errors/ChatInvalidSinglePromptKind.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,qBAAa,2BAA4B,SAAQ,KAAK;IAClD;;OAEG;IACH,SAAgB,OAAO,CAAC,EAAE,OAAO,CAAC;IAElC;;;;OAIG;gBACgB,OAAO,CAAC,EAAE,OAAO;CAUvC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error emitted when a single prompt is sent with an invalid kind.
|
|
3
|
+
*
|
|
4
|
+
* Single prompts must be of kind "text" only. If you need to send tool results,
|
|
5
|
+
* use an array of prompts instead.
|
|
6
|
+
*
|
|
7
|
+
* The error may include a `context` property with additional debugging information
|
|
8
|
+
* such as the `chatId` and the actual `kind` that was provided.
|
|
9
|
+
*/
|
|
10
|
+
export class ChatInvalidSinglePromptKind extends Error {
|
|
11
|
+
/**
|
|
12
|
+
* Optional context describing the invalid prompt kind and chat details.
|
|
13
|
+
*/
|
|
14
|
+
context;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new {@link ChatInvalidSinglePromptKind} instance.
|
|
17
|
+
*
|
|
18
|
+
* @param context Additional context useful for debugging, e.g. `{ chatId: string, kind: string }`.
|
|
19
|
+
*/
|
|
20
|
+
constructor(context) {
|
|
21
|
+
super("Single prompts must be of kind 'text'. Use an array of prompts for tool results.");
|
|
22
|
+
this.name = "ChatInvalidSinglePromptKind";
|
|
23
|
+
if (context !== undefined) {
|
|
24
|
+
Object.defineProperty(this, "context", {
|
|
25
|
+
value: context,
|
|
26
|
+
enumerable: true,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=ChatInvalidSinglePromptKind.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatInvalidSinglePromptKind.js","sourceRoot":"","sources":["../../../../src/chat/errors/ChatInvalidSinglePromptKind.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IAClD;;OAEG;IACa,OAAO,CAAW;IAElC;;;;OAIG;IACH,YAAmB,OAAiB;QAChC,KAAK,CAAC,kFAAkF,CAAC,CAAC;QAC1F,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;QAC1C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,SAAS,EAAE;gBACnC,KAAK,EAAE,OAAO;gBACd,UAAU,EAAE,IAAI;aACnB,CAAC,CAAC;QACP,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export { ChatAsyncToolCheckerUnavailable } from "./ChatAsyncToolCheckerUnavailable.js";
|
|
2
|
+
export { ChatInvalidMultiplePromptsKind } from "./ChatInvalidMultiplePromptsKind.js";
|
|
3
|
+
export { ChatInvalidSinglePromptKind } from "./ChatInvalidSinglePromptKind.js";
|
|
2
4
|
export { UserContextMissing } from "./UserContextMissing.js";
|
|
5
|
+
export { ChatInvalidPromptSnapshot } from "./ChatInvalidPromptSnapshot.js";
|
|
3
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/chat/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AACvF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/chat/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AACvF,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AACrF,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export { ChatAsyncToolCheckerUnavailable } from "./ChatAsyncToolCheckerUnavailable.js";
|
|
2
|
+
export { ChatInvalidMultiplePromptsKind } from "./ChatInvalidMultiplePromptsKind.js";
|
|
3
|
+
export { ChatInvalidSinglePromptKind } from "./ChatInvalidSinglePromptKind.js";
|
|
2
4
|
export { UserContextMissing } from "./UserContextMissing.js";
|
|
5
|
+
export { ChatInvalidPromptSnapshot } from "./ChatInvalidPromptSnapshot.js";
|
|
3
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/chat/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AACvF,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/chat/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AACvF,OAAO,EAAE,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AACrF,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../../src/chat/utils/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,eAAO,MAAM,eAAe,QAAS,MAAM,GAAG,MAAM,KAAG,MAEtD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../../../src/chat/utils/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,GAAoB,EAAU,EAAE;IAC5D,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AACrE,CAAC,CAAC"}
|