@celljs/ai-core 3.2.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -0
- package/lib/common/chat/message/assistant-message.d.ts +3 -2
- package/lib/common/chat/message/assistant-message.d.ts.map +1 -1
- package/lib/common/chat/message/assistant-message.js +2 -1
- package/lib/common/chat/message/assistant-message.js.map +1 -1
- package/lib/common/chat/message/index.d.ts +1 -0
- package/lib/common/chat/message/index.d.ts.map +1 -1
- package/lib/common/chat/message/index.js +1 -0
- package/lib/common/chat/message/index.js.map +1 -1
- package/lib/common/chat/message/message-protocol.d.ts +23 -1
- package/lib/common/chat/message/message-protocol.d.ts.map +1 -1
- package/lib/common/chat/message/message-protocol.js +1 -0
- package/lib/common/chat/message/message-protocol.js.map +1 -1
- package/lib/common/chat/message/tool-response-message.d.ts +32 -0
- package/lib/common/chat/message/tool-response-message.d.ts.map +1 -0
- package/lib/common/chat/message/tool-response-message.js +23 -0
- package/lib/common/chat/message/tool-response-message.js.map +1 -0
- package/lib/common/chat/metadata/chat-generation-metadata.d.ts +28 -0
- package/lib/common/chat/metadata/chat-generation-metadata.d.ts.map +1 -0
- package/lib/common/chat/metadata/chat-generation-metadata.js +21 -0
- package/lib/common/chat/metadata/chat-generation-metadata.js.map +1 -0
- package/lib/common/chat/metadata/index.d.ts +1 -0
- package/lib/common/chat/metadata/index.d.ts.map +1 -1
- package/lib/common/chat/metadata/index.js +1 -0
- package/lib/common/chat/metadata/index.js.map +1 -1
- package/lib/common/chat/metadata/metadata-protocol.d.ts +2 -0
- package/lib/common/chat/metadata/metadata-protocol.d.ts.map +1 -1
- package/lib/common/chat/metadata/metadata-protocol.js.map +1 -1
- package/lib/common/chat/prompt/index.d.ts +1 -0
- package/lib/common/chat/prompt/index.d.ts.map +1 -1
- package/lib/common/chat/prompt/index.js +1 -0
- package/lib/common/chat/prompt/index.js.map +1 -1
- package/lib/common/chat/prompt/prompt-protocol.d.ts +17 -16
- package/lib/common/chat/prompt/prompt-protocol.d.ts.map +1 -1
- package/lib/common/chat/prompt/prompt-protocol.js +2 -0
- package/lib/common/chat/prompt/prompt-protocol.js.map +1 -1
- package/lib/common/chat/prompt/prompt-template.d.ts +8 -0
- package/lib/common/chat/prompt/prompt-template.d.ts.map +1 -0
- package/lib/common/chat/prompt/prompt-template.js +34 -0
- package/lib/common/chat/prompt/prompt-template.js.map +1 -0
- package/lib/common/embedding/embedding-protocol.d.ts +11 -8
- package/lib/common/embedding/embedding-protocol.d.ts.map +1 -1
- package/lib/common/embedding/embedding-protocol.js +10 -1
- package/lib/common/embedding/embedding-protocol.js.map +1 -1
- package/lib/common/error/error.d.ts +5 -0
- package/lib/common/error/error.d.ts.map +1 -0
- package/lib/common/error/error.js +11 -0
- package/lib/common/error/error.js.map +1 -0
- package/lib/common/error/index.d.ts +2 -0
- package/lib/common/error/index.d.ts.map +1 -0
- package/lib/common/error/index.js +5 -0
- package/lib/common/error/index.js.map +1 -0
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +2 -0
- package/lib/common/index.js.map +1 -1
- package/lib/common/model/function/function-protocol.d.ts +2 -2
- package/lib/common/model/function/function-protocol.d.ts.map +1 -1
- package/lib/common/model/model-protocol.d.ts +2 -1
- package/lib/common/model/model-protocol.d.ts.map +1 -1
- package/lib/common/sse/index.d.ts +4 -0
- package/lib/common/sse/index.d.ts.map +1 -0
- package/lib/common/sse/index.js +7 -0
- package/lib/common/sse/index.js.map +1 -0
- package/lib/common/sse/line-decoder.d.ts +15 -0
- package/lib/common/sse/line-decoder.d.ts.map +1 -0
- package/lib/common/sse/line-decoder.js +54 -0
- package/lib/common/sse/line-decoder.js.map +1 -0
- package/lib/common/sse/sse-decoder.d.ts +27 -0
- package/lib/common/sse/sse-decoder.d.ts.map +1 -0
- package/lib/common/sse/sse-decoder.js +74 -0
- package/lib/common/sse/sse-decoder.js.map +1 -0
- package/lib/common/sse/sse-protocol.d.ts +23 -0
- package/lib/common/sse/sse-protocol.d.ts.map +1 -0
- package/lib/common/sse/sse-protocol.js +4 -0
- package/lib/common/sse/sse-protocol.js.map +1 -0
- package/lib/common/utils/index.d.ts +1 -0
- package/lib/common/utils/index.d.ts.map +1 -1
- package/lib/common/utils/index.js +1 -0
- package/lib/common/utils/index.js.map +1 -1
- package/lib/common/utils/sse-util.d.ts +10 -0
- package/lib/common/utils/sse-util.d.ts.map +1 -0
- package/lib/common/utils/sse-util.js +109 -0
- package/lib/common/utils/sse-util.js.map +1 -0
- package/package.json +5 -5
- package/src/common/chat/message/assistant-message.ts +5 -3
- package/src/common/chat/message/index.ts +1 -0
- package/src/common/chat/message/message-protocol.ts +27 -1
- package/src/common/chat/message/tool-response-message.ts +40 -0
- package/src/common/chat/metadata/chat-generation-metadata.ts +38 -0
- package/src/common/chat/metadata/index.ts +1 -0
- package/src/common/chat/metadata/metadata-protocol.ts +2 -0
- package/src/common/chat/prompt/index.ts +1 -0
- package/src/common/chat/prompt/prompt-protocol.ts +18 -28
- package/src/common/chat/prompt/prompt-template.ts +26 -0
- package/src/common/embedding/embedding-protocol.ts +17 -8
- package/src/common/error/error.ts +7 -0
- package/src/common/error/index.ts +1 -0
- package/src/common/index.ts +2 -0
- package/src/common/model/function/function-protocol.ts +2 -2
- package/src/common/model/model-protocol.ts +4 -2
- package/src/common/sse/index.ts +3 -0
- package/src/common/sse/line-decoder.ts +65 -0
- package/src/common/sse/sse-decoder.ts +88 -0
- package/src/common/sse/sse-protocol.ts +25 -0
- package/src/common/utils/index.ts +1 -0
- package/src/common/utils/sse-util.ts +111 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"embedding-protocol.js","sourceRoot":"","sources":["../../../src/common/embedding/embedding-protocol.ts"],"names":[],"mappings":";;;AAAA,uCAAuD;AAI1C,QAAA,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"embedding-protocol.js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wB,GAAG,QAAQ,CAAC,CAAC;IACzD,CAAC;;AA7BL,sCA8BC;AA7BkB,4BAAc,GAAG,oBAAa,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;AACvD,6BAAe,GAAG,oBAAa,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;AACzD,6BAAe,GAAG,oBAAa,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;AACzD,6BAAe,GAAG,oBAAa,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../src/common/error/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,qBAAa,OAAQ,SAAQ,WAAW;gBACxB,OAAO,EAAE,MAAM;CAG9B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AIError = void 0;
|
|
4
|
+
const core_1 = require("@celljs/core");
|
|
5
|
+
class AIError extends core_1.CustomError {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.AIError = AIError;
|
|
11
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/common/error/error.ts"],"names":[],"mappings":";;;AAAA,uCAA2C;AAE3C,MAAa,OAAQ,SAAQ,kBAAW;IACpC,YAAY,OAAe;QACvB,KAAK,CAAC,OAAO,CAAC,CAAC;IACnB,CAAC;CACJ;AAJD,0BAIC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/error/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/error/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB"}
|
package/lib/common/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
package/lib/common/index.js
CHANGED
|
@@ -4,5 +4,7 @@ const tslib_1 = require("tslib");
|
|
|
4
4
|
tslib_1.__exportStar(require("./chat"), exports);
|
|
5
5
|
tslib_1.__exportStar(require("./model"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./embedding"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./sse"), exports);
|
|
7
8
|
tslib_1.__exportStar(require("./utils"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./error"), exports);
|
|
8
10
|
//# sourceMappingURL=index.js.map
|
package/lib/common/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":";;;AAAA,iDAAuB;AACvB,kDAAwB;AACxB,sDAA4B;AAC5B,kDAAwB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":";;;AAAA,iDAAuB;AACvB,kDAAwB;AACxB,sDAA4B;AAC5B,gDAAsB;AACtB,kDAAwB;AACxB,kDAAwB"}
|
|
@@ -20,12 +20,12 @@ export interface FunctionCallback {
|
|
|
20
20
|
/**
|
|
21
21
|
* Called when a model detects and triggers a function call. The model is responsible
|
|
22
22
|
* to pass the function arguments in the pre-configured JSON schema format.
|
|
23
|
-
* @param
|
|
23
|
+
* @param functionArguments JSON string with the function arguments to be passed to the
|
|
24
24
|
* function. The arguments are defined as JSON schema usually registered with the the
|
|
25
25
|
* model.
|
|
26
26
|
* @return String containing the function call response.
|
|
27
27
|
*/
|
|
28
|
-
call(
|
|
28
|
+
call(functionArguments: string): Promise<string>;
|
|
29
29
|
}
|
|
30
30
|
export interface FunctionCallingOptions {
|
|
31
31
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function-protocol.d.ts","sourceRoot":"","sources":["../../../../src/common/model/function/function-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAE7B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IAEjC;;;;;;;OAOG;IACH,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"function-protocol.d.ts","sourceRoot":"","sources":["../../../../src/common/model/function/function-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAE7B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAE7B;;OAEG;IACH,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IAEjC;;;;;;;OAOG;IACH,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAEpD;AAED,MAAM,WAAW,sBAAsB;IAEnC;;;;;;OAMG;IACH,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;IAEtC;;;OAGG;IACH,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC1B;AAED,MAAM,WAAW,8BAA+B,SAAQ,sBAAsB,EAAE,WAAW;CAE1F"}
|
|
@@ -37,6 +37,7 @@ export interface ResultMetadata {
|
|
|
37
37
|
* responses in various applications.
|
|
38
38
|
*/
|
|
39
39
|
export interface ResponseMetadata {
|
|
40
|
+
readonly extra: Record<string, any>;
|
|
40
41
|
}
|
|
41
42
|
/**
|
|
42
43
|
* This interface provides methods to access the main output of the AI model and the
|
|
@@ -157,6 +158,6 @@ export interface StreamingModel<TReq extends ModelRequest<any>, TResChunk extend
|
|
|
157
158
|
* @param request the request object to be sent to the AI model
|
|
158
159
|
* @return the streaming response from the AI model
|
|
159
160
|
*/
|
|
160
|
-
stream(request: TReq): Observable<TResChunk
|
|
161
|
+
stream(request: TReq): Promise<Observable<TResChunk>>;
|
|
161
162
|
}
|
|
162
163
|
//# sourceMappingURL=model-protocol.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-protocol.d.ts","sourceRoot":"","sources":["../../../src/common/model/model-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,eAAO,MAAM,KAAK,eAAkB,CAAC;AACrC,eAAO,MAAM,cAAc,eAA2B,CAAC;AAEvD;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;CAAG;AAEhC;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;CAAG;AAElC;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;
|
|
1
|
+
{"version":3,"file":"model-protocol.d.ts","sourceRoot":"","sources":["../../../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,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAEtC;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IAEpB;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC;IAExB;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAE1C;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,cAAc,CAAC,IAAI,SAAS,YAAY,CAAC,GAAG,CAAC,EAAE,SAAS,SAAS,aAAa,CAAC,GAAG,CAAC;IAEhG;;;;OAIG;IACH,MAAM,CAAC,OAAO,EAAE,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC;CAEzD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/sse/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./line-decoder"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./sse-protocol"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./sse-decoder"), exports);
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/sse/index.ts"],"names":[],"mappings":";;;AAAA,yDAA+B;AAC/B,yDAA+B;AAC/B,wDAA8B"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Bytes } from '@celljs/core';
|
|
2
|
+
import { LineDecoder } from './sse-protocol';
|
|
3
|
+
/**
|
|
4
|
+
* Line decoder.
|
|
5
|
+
*/
|
|
6
|
+
export declare class LineDecoderImpl implements LineDecoder {
|
|
7
|
+
private buffer;
|
|
8
|
+
private trailingCR;
|
|
9
|
+
static readonly NEWLINE_CHARS: Set<string>;
|
|
10
|
+
static readonly NEWLINE_REGEXP: RegExp;
|
|
11
|
+
constructor();
|
|
12
|
+
decode(chunk: Bytes): string[];
|
|
13
|
+
flush(): string[];
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=line-decoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"line-decoder.d.ts","sourceRoot":"","sources":["../../../src/common/sse/line-decoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAY,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;GAEG;AACH,qBAAa,eAAgB,YAAW,WAAW;IAC/C,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,UAAU,CAAU;IAE5B,MAAM,CAAC,QAAQ,CAAC,aAAa,cAA6F;IAC1H,MAAM,CAAC,QAAQ,CAAC,cAAc,SAAsD;;IAOpF,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE;IAsC9B,KAAK,IAAI,MAAM,EAAE;CAUpB"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LineDecoderImpl = void 0;
|
|
4
|
+
const core_1 = require("@celljs/core");
|
|
5
|
+
/**
|
|
6
|
+
* Line decoder.
|
|
7
|
+
*/
|
|
8
|
+
class LineDecoderImpl {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.buffer = [];
|
|
11
|
+
this.trailingCR = false;
|
|
12
|
+
}
|
|
13
|
+
decode(chunk) {
|
|
14
|
+
let text = core_1.ByteUtil.decode(chunk);
|
|
15
|
+
if (this.trailingCR) {
|
|
16
|
+
text = '\r' + text;
|
|
17
|
+
this.trailingCR = false;
|
|
18
|
+
}
|
|
19
|
+
if (text.endsWith('\r')) {
|
|
20
|
+
this.trailingCR = true;
|
|
21
|
+
text = text.slice(0, -1);
|
|
22
|
+
}
|
|
23
|
+
if (!text) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
const trailingNewline = LineDecoderImpl.NEWLINE_CHARS.has(text[text.length - 1] || '');
|
|
27
|
+
let lines = text.split(LineDecoderImpl.NEWLINE_REGEXP);
|
|
28
|
+
if (lines.length === 1 && !trailingNewline) {
|
|
29
|
+
this.buffer.push(lines[0]);
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
if (this.buffer.length > 0) {
|
|
33
|
+
lines = [this.buffer.join('') + lines[0], ...lines.slice(1)];
|
|
34
|
+
this.buffer = [];
|
|
35
|
+
}
|
|
36
|
+
if (!trailingNewline) {
|
|
37
|
+
this.buffer = [lines.pop() || ''];
|
|
38
|
+
}
|
|
39
|
+
return lines;
|
|
40
|
+
}
|
|
41
|
+
flush() {
|
|
42
|
+
if (this.buffer.length === 0 && !this.trailingCR) {
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
const lines = [this.buffer.join('')];
|
|
46
|
+
this.buffer = [];
|
|
47
|
+
this.trailingCR = false;
|
|
48
|
+
return lines;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.LineDecoderImpl = LineDecoderImpl;
|
|
52
|
+
LineDecoderImpl.NEWLINE_CHARS = new Set(['\n', '\r', '\x0b', '\x0c', '\x1c', '\x1d', '\x1e', '\x85', '\u2028', '\u2029']);
|
|
53
|
+
LineDecoderImpl.NEWLINE_REGEXP = /\r\n|[\n\r\x0b\x0c\x1c\x1d\x1e\x85\u2028\u2029]/g;
|
|
54
|
+
//# sourceMappingURL=line-decoder.js.map
|
|
@@ -0,0 +1 @@
|
|
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AAC,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7D,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;SACpB;QAED,IAAI,CAAC,eAAe,EAAE;YAClB,IAAI,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;SACrC;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IAID,KAAK;QACD,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;YAC9C,OAAO,EAAE,CAAC;SACb;QAED,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QACxB,OAAO,KAAK,CAAC;IACjB,CAAC;;AA3DL,0CA4DC;AAxDmB,6BAAa,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC1G,8BAAc,GAAG,kDAAkD,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EventDecoder, ServerSentEvent } from './sse-protocol';
|
|
2
|
+
/**
|
|
3
|
+
* Server-sent event.
|
|
4
|
+
*/
|
|
5
|
+
export declare class SSEDecoder implements EventDecoder {
|
|
6
|
+
private event?;
|
|
7
|
+
private data;
|
|
8
|
+
private chunks;
|
|
9
|
+
constructor();
|
|
10
|
+
protected buildServerSentEvent(): ServerSentEvent;
|
|
11
|
+
decode(line: string): ServerSentEvent | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Partitions a string into three parts based on a delimiter.
|
|
14
|
+
* @param str The string to partition.
|
|
15
|
+
* @param delimiter The delimiter to partition the string by.
|
|
16
|
+
* @returns A tuple containing the three parts of the partitioned string.
|
|
17
|
+
* The first part is the string before the delimiter, the second part is the delimiter itself,
|
|
18
|
+
* and the third part is the string after the delimiter.
|
|
19
|
+
* If the delimiter is not found in the string, the first part is the entire string, the second part is an empty string, and the third part is an empty string.
|
|
20
|
+
* @example
|
|
21
|
+
* partition('hello,world', ',') // ['hello', ',', 'world']
|
|
22
|
+
* partition('hello,world', '.') // ['hello,world', '', '']
|
|
23
|
+
* partition('hello,world', 'l') // ['he', 'l', 'lo,world']
|
|
24
|
+
*/
|
|
25
|
+
protected partition(str: string, delimiter: string): [string, string, string];
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=sse-decoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse-decoder.d.ts","sourceRoot":"","sources":["../../../src/common/sse/sse-decoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE/D;;GAEG;AACH,qBAAa,UAAW,YAAW,YAAY;IAC3C,OAAO,CAAC,KAAK,CAAC,CAAS;IACvB,OAAO,CAAC,IAAI,CAAW;IACvB,OAAO,CAAC,MAAM,CAAW;;IAQzB,SAAS,CAAC,oBAAoB,IAAI,eAAe;IAcjD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAqCjD;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;CAOhF"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SSEDecoder = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Server-sent event.
|
|
6
|
+
*/
|
|
7
|
+
class SSEDecoder {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.event = undefined;
|
|
10
|
+
this.data = [];
|
|
11
|
+
this.chunks = [];
|
|
12
|
+
}
|
|
13
|
+
buildServerSentEvent() {
|
|
14
|
+
const sse = {
|
|
15
|
+
event: this.event,
|
|
16
|
+
data: this.data.join('\n'),
|
|
17
|
+
raw: this.chunks,
|
|
18
|
+
};
|
|
19
|
+
this.event = undefined;
|
|
20
|
+
this.data = [];
|
|
21
|
+
this.chunks = [];
|
|
22
|
+
return sse;
|
|
23
|
+
}
|
|
24
|
+
decode(line) {
|
|
25
|
+
if (line.endsWith('\r')) {
|
|
26
|
+
line = line.substring(0, line.length - 1);
|
|
27
|
+
}
|
|
28
|
+
if (!line) {
|
|
29
|
+
if (!this.event && this.data.length === 0) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
return this.buildServerSentEvent();
|
|
33
|
+
}
|
|
34
|
+
this.chunks.push(line);
|
|
35
|
+
if (line.startsWith(':')) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (line.startsWith('{') && line.endsWith('}')) {
|
|
39
|
+
this.data.push(line);
|
|
40
|
+
return this.buildServerSentEvent();
|
|
41
|
+
}
|
|
42
|
+
const [fieldName, , value] = this.partition(line, ':');
|
|
43
|
+
const trimmedValue = value.startsWith(' ') ? value.substring(1) : value;
|
|
44
|
+
if (fieldName === 'event') {
|
|
45
|
+
this.event = trimmedValue;
|
|
46
|
+
}
|
|
47
|
+
else if (fieldName === 'data') {
|
|
48
|
+
this.data.push(trimmedValue);
|
|
49
|
+
}
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Partitions a string into three parts based on a delimiter.
|
|
54
|
+
* @param str The string to partition.
|
|
55
|
+
* @param delimiter The delimiter to partition the string by.
|
|
56
|
+
* @returns A tuple containing the three parts of the partitioned string.
|
|
57
|
+
* The first part is the string before the delimiter, the second part is the delimiter itself,
|
|
58
|
+
* and the third part is the string after the delimiter.
|
|
59
|
+
* If the delimiter is not found in the string, the first part is the entire string, the second part is an empty string, and the third part is an empty string.
|
|
60
|
+
* @example
|
|
61
|
+
* partition('hello,world', ',') // ['hello', ',', 'world']
|
|
62
|
+
* partition('hello,world', '.') // ['hello,world', '', '']
|
|
63
|
+
* partition('hello,world', 'l') // ['he', 'l', 'lo,world']
|
|
64
|
+
*/
|
|
65
|
+
partition(str, delimiter) {
|
|
66
|
+
const index = str.indexOf(delimiter);
|
|
67
|
+
if (index !== -1) {
|
|
68
|
+
return [str.substring(0, index), delimiter, str.substring(index + delimiter.length)];
|
|
69
|
+
}
|
|
70
|
+
return [str, '', ''];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.SSEDecoder = SSEDecoder;
|
|
74
|
+
//# sourceMappingURL=sse-decoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse-decoder.js","sourceRoot":"","sources":["../../../src/common/sse/sse-decoder.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAa,UAAU;IAKnB;QACI,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACrB,CAAC;IAES,oBAAoB;QAC1B,MAAM,GAAG,GAAoB;YACzB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YAC1B,GAAG,EAAE,IAAI,CAAC,MAAM;SACnB,CAAC;QAEF,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QAEjB,OAAO,GAAG,CAAC;IACf,CAAC;IAED,MAAM,CAAC,IAAY;QACf,IAAI,IAAI,CAAC,QAAQ,CAAC,IA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C,CAAC;QACrC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;YACd,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;SACxF;QACD,OAAO,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IACzB,CAAC;CACJ;AAlFD,gCAkFC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Bytes } from '@celljs/core';
|
|
2
|
+
/**
|
|
3
|
+
* Server-sent event.
|
|
4
|
+
*/
|
|
5
|
+
export interface ServerSentEvent {
|
|
6
|
+
event?: string;
|
|
7
|
+
data: string;
|
|
8
|
+
raw: string[];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Decoder for server-sent events.
|
|
12
|
+
*/
|
|
13
|
+
export interface EventDecoder {
|
|
14
|
+
decode(line: string): ServerSentEvent | undefined;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Decoder for line-based protocols.
|
|
18
|
+
*/
|
|
19
|
+
export interface LineDecoder {
|
|
20
|
+
decode(chunk: Bytes): string[];
|
|
21
|
+
flush(): string[];
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=sse-protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse-protocol.d.ts","sourceRoot":"","sources":["../../../src/common/sse/sse-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,eAAe;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAAC;CACrD;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,MAAM,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE,CAAC;IAC/B,KAAK,IAAI,MAAM,EAAE,CAAC;CACrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse-protocol.js","sourceRoot":"","sources":["../../../src/common/sse/sse-protocol.ts"],"names":[],"mappings":";;AASC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/common/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/utils/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/utils/index.ts"],"names":[],"mappings":";;;AAAA,wDAA8B;AAC9B,qDAA2B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
/**
|
|
3
|
+
* SSE utility class.
|
|
4
|
+
*/
|
|
5
|
+
export declare class SSEUtil {
|
|
6
|
+
static toObservable<Item>(readableStream: ReadableStream, controller?: AbortController): Observable<Item>;
|
|
7
|
+
private static handleSSE;
|
|
8
|
+
private static readableStreamAsyncIterable;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=sse-util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse-util.d.ts","sourceRoot":"","sources":["../../../src/common/utils/sse-util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAc,MAAM,MAAM,CAAC;AAI9C;;GAEG;AACH,qBAAa,OAAO;IAEhB,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,cAAc,EAAE,cAAc,EAAE,UAAU,CAAC,EAAE,eAAe,GAAG,UAAU,CAAC,IAAI,CAAC;IAyCzG,OAAO,CAAC,MAAM,CAAC,SAAS;IAkCxB,OAAO,CAAC,MAAM,CAAC,2BAA2B;CA0B7C"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SSEUtil = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const sse_1 = require("../sse");
|
|
6
|
+
/**
|
|
7
|
+
* SSE utility class.
|
|
8
|
+
*/
|
|
9
|
+
class SSEUtil {
|
|
10
|
+
static toObservable(readableStream, controller) {
|
|
11
|
+
return new rxjs_1.Observable(subscriber => {
|
|
12
|
+
(async () => {
|
|
13
|
+
const decoder = new sse_1.SSEDecoder();
|
|
14
|
+
const lineDecoder = new sse_1.LineDecoderImpl();
|
|
15
|
+
try {
|
|
16
|
+
const iterable = this.readableStreamAsyncIterable(readableStream);
|
|
17
|
+
for await (const chunk of iterable) {
|
|
18
|
+
const lines = lineDecoder.decode(chunk);
|
|
19
|
+
for (const line of lines) {
|
|
20
|
+
const sse = decoder.decode(line);
|
|
21
|
+
this.handleSSE(sse, subscriber, controller);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const remainingLines = lineDecoder.flush();
|
|
25
|
+
for (const line of remainingLines) {
|
|
26
|
+
const sse = decoder.decode(line);
|
|
27
|
+
if (sse) {
|
|
28
|
+
this.handleSSE(sse, subscriber, controller);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
subscriber.complete();
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
if (e instanceof Error && e.name === 'AbortError') {
|
|
35
|
+
subscriber.complete();
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
subscriber.error(e);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
controller === null || controller === void 0 ? void 0 : controller.abort();
|
|
43
|
+
}
|
|
44
|
+
})();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
static handleSSE(sse, subscriber, controller) {
|
|
48
|
+
if (sse) {
|
|
49
|
+
if (sse.data.startsWith('[DONE]')) {
|
|
50
|
+
subscriber.complete();
|
|
51
|
+
controller === null || controller === void 0 ? void 0 : controller.abort();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (!sse.event || sse.event === 'error') {
|
|
55
|
+
let data;
|
|
56
|
+
try {
|
|
57
|
+
data = JSON.parse(sse.data);
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
console.error('Could not parse message into JSON:', sse.data);
|
|
61
|
+
console.error('From chunk:', sse.raw);
|
|
62
|
+
subscriber.error(e);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (data && data.error) {
|
|
66
|
+
subscriber.error(data.error);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
subscriber.next(data);
|
|
70
|
+
if (data.done === true) {
|
|
71
|
+
subscriber.complete();
|
|
72
|
+
controller === null || controller === void 0 ? void 0 : controller.abort();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
static readableStreamAsyncIterable(stream) {
|
|
78
|
+
if (stream[Symbol.asyncIterator]) {
|
|
79
|
+
return stream;
|
|
80
|
+
}
|
|
81
|
+
const reader = stream.getReader();
|
|
82
|
+
return {
|
|
83
|
+
async next() {
|
|
84
|
+
try {
|
|
85
|
+
const result = await reader.read();
|
|
86
|
+
if (result === null || result === void 0 ? void 0 : result.done) {
|
|
87
|
+
reader.releaseLock();
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
catch (e) {
|
|
92
|
+
reader.releaseLock();
|
|
93
|
+
throw e;
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
async return() {
|
|
97
|
+
const cancelPromise = reader.cancel();
|
|
98
|
+
reader.releaseLock();
|
|
99
|
+
await cancelPromise;
|
|
100
|
+
return { done: true, value: undefined };
|
|
101
|
+
},
|
|
102
|
+
[Symbol.asyncIterator]() {
|
|
103
|
+
return this;
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.SSEUtil = SSEUtil;
|
|
109
|
+
//# sourceMappingURL=sse-util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse-util.js","sourceRoot":"","sources":["../../../src/common/utils/sse-util.ts"],"names":[],"mappings":";;;AAAA,+BAA8C;AAC9C,gCAAsE;AAGtE;;GAEG;AACH,MAAa,OAAO;IAEhB,MAAM,CAAC,YAAY,CAAO,cAA8B,EAAE,UAA4B;QAClF,OAAO,IAAI,iBAAU,CAAO,UAAU,CAAC,EAAE;YACrC,CAAC,KAAK,IAAI,EAAE;gBACR,MAAM,OAAO,GAAG,IAAI,gBAAU,EAAE,CAAC;gBACjC,MAAM,WAAW,GAAG,IAAI,qBAAe,EAAE,CAAC;gBAE1C,IAAI;oBACA,MAAM,QAAQ,GAAG,IAAI,CAAC,2BAA2B,CAAQ,cAAc,CAAC,CAAC;oBACzE,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,QAAQ,EAAE;wBAChC,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;wBACxC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;4BACtB,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;4BACjC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;yBAC/C;qBACJ;oBAED,MAAM,cAAc,GAAG,WAAW,CAA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5C,CAAC;YACD,CAAC,MAAM,CAAC,aAAa,CAAC;gBAClB,OAAO,IAAI,CAAC;YAChB,CAAC;SACJ,CAAC;IACN,CAAC;CACJ;AAvGD,0BAuGC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ai-core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Core domain for AI programming",
|
|
5
5
|
"main": "lib/common/index.js",
|
|
6
6
|
"typings": "lib/common/index.d.ts",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@celljs/core": "3.
|
|
9
|
-
"@celljs/http": "3.
|
|
8
|
+
"@celljs/core": "3.3.0",
|
|
9
|
+
"@celljs/http": "3.3.0",
|
|
10
10
|
"rxjs": "^6.6.0",
|
|
11
11
|
"tslib": "^2.8.0"
|
|
12
12
|
},
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"test": "cell-component test:js"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@celljs/component": "3.
|
|
41
|
+
"@celljs/component": "3.3.0"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "6046657df0c1674e13e2e3911559643160f9d94c"
|
|
44
44
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { AbstractMessage } from './abstract-message';
|
|
2
|
-
import { Media, MessageType } from './message-protocol';
|
|
2
|
+
import { Media, MessageType, ToolCall } from './message-protocol';
|
|
3
3
|
|
|
4
4
|
export class AssistantMessage extends AbstractMessage {
|
|
5
5
|
|
|
6
6
|
constructor(
|
|
7
|
-
override readonly content: string,
|
|
7
|
+
override readonly content: string = '',
|
|
8
8
|
override readonly media: Media[] = [],
|
|
9
|
-
override readonly metadata: Record<string, any> = {}
|
|
9
|
+
override readonly metadata: Record<string, any> = {},
|
|
10
|
+
readonly toolCalls: ToolCall[] = []
|
|
11
|
+
) {
|
|
10
12
|
super(MessageType.ASSISTANT, content, media, metadata);
|
|
11
13
|
}
|
|
12
14
|
}
|
|
@@ -27,7 +27,8 @@ export enum MessageType {
|
|
|
27
27
|
USER = 'user',
|
|
28
28
|
ASSISTANT = 'assistant',
|
|
29
29
|
SYSTEM = 'system',
|
|
30
|
-
FUNCTION = 'function'
|
|
30
|
+
FUNCTION = 'function',
|
|
31
|
+
TOOL = 'tool'
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
/**
|
|
@@ -47,3 +48,28 @@ export namespace Message {
|
|
|
47
48
|
return obj && obj.messageType !== undefined;
|
|
48
49
|
}
|
|
49
50
|
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Represents a tool call.
|
|
54
|
+
*/
|
|
55
|
+
export interface ToolCall {
|
|
56
|
+
/**
|
|
57
|
+
* The unique identifier for the tool call.
|
|
58
|
+
*/
|
|
59
|
+
id: string;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The type of the tool.
|
|
63
|
+
*/
|
|
64
|
+
type: string;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The name of the tool.
|
|
68
|
+
*/
|
|
69
|
+
name: string;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The arguments passed to the tool.
|
|
73
|
+
*/
|
|
74
|
+
arguments: string;
|
|
75
|
+
}
|