@llumiverse/core 0.25.0 → 0.25.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/lib/cjs/CompletionStream.js +244 -0
- package/lib/cjs/CompletionStream.js.map +1 -0
- package/lib/cjs/Driver.js +194 -0
- package/lib/cjs/Driver.js.map +1 -0
- package/lib/cjs/async.js +131 -0
- package/lib/cjs/async.js.map +1 -0
- package/lib/cjs/conversation-utils.js +457 -0
- package/lib/cjs/conversation-utils.js.map +1 -0
- package/lib/cjs/formatters/commons.js +7 -0
- package/lib/cjs/formatters/commons.js.map +1 -0
- package/lib/cjs/formatters/generic.js +59 -0
- package/lib/cjs/formatters/generic.js.map +1 -0
- package/lib/cjs/formatters/index.js +20 -0
- package/lib/cjs/formatters/index.js.map +1 -0
- package/lib/cjs/formatters/nova.js +99 -0
- package/lib/cjs/formatters/nova.js.map +1 -0
- package/lib/cjs/index.js +22 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/json.js +29 -0
- package/lib/cjs/json.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/resolver.js +45 -0
- package/lib/cjs/resolver.js.map +1 -0
- package/lib/cjs/stream.js +30 -0
- package/lib/cjs/stream.js.map +1 -0
- package/lib/cjs/validation.js +96 -0
- package/lib/cjs/validation.js.map +1 -0
- package/lib/esm/CompletionStream.js +239 -0
- package/lib/esm/CompletionStream.js.map +1 -0
- package/lib/esm/Driver.js +189 -0
- package/lib/esm/Driver.js.map +1 -0
- package/lib/esm/async.js +123 -0
- package/lib/esm/async.js.map +1 -0
- package/lib/esm/conversation-utils.js +447 -0
- package/lib/esm/conversation-utils.js.map +1 -0
- package/lib/esm/formatters/commons.js +4 -0
- package/lib/esm/formatters/commons.js.map +1 -0
- package/lib/esm/formatters/generic.js +55 -0
- package/lib/esm/formatters/generic.js.map +1 -0
- package/lib/esm/formatters/index.js +4 -0
- package/lib/esm/formatters/index.js.map +1 -0
- package/lib/esm/formatters/nova.js +96 -0
- package/lib/esm/formatters/nova.js.map +1 -0
- package/lib/esm/index.js +6 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/json.js +25 -0
- package/lib/esm/json.js.map +1 -0
- package/lib/esm/resolver.js +42 -0
- package/lib/esm/resolver.js.map +1 -0
- package/lib/esm/stream.js +25 -0
- package/lib/esm/stream.js.map +1 -0
- package/lib/esm/validation.js +88 -0
- package/lib/esm/validation.js.map +1 -0
- package/lib/types/CompletionStream.d.ts +20 -0
- package/lib/types/CompletionStream.d.ts.map +1 -0
- package/lib/types/Driver.d.ts +86 -0
- package/lib/types/Driver.d.ts.map +1 -0
- package/lib/types/async.d.ts +27 -0
- package/lib/types/async.d.ts.map +1 -0
- package/lib/types/conversation-utils.d.ts +112 -0
- package/lib/types/conversation-utils.d.ts.map +1 -0
- package/lib/types/formatters/commons.d.ts +3 -0
- package/lib/types/formatters/commons.d.ts.map +1 -0
- package/lib/types/formatters/generic.d.ts +13 -0
- package/lib/types/formatters/generic.d.ts.map +1 -0
- package/lib/types/formatters/index.d.ts +4 -0
- package/lib/types/formatters/index.d.ts.map +1 -0
- package/lib/types/formatters/nova.d.ts +40 -0
- package/lib/types/formatters/nova.d.ts.map +1 -0
- package/lib/types/index.d.ts +6 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/json.d.ts +4 -0
- package/lib/types/json.d.ts.map +1 -0
- package/lib/types/resolver.d.ts +2 -0
- package/lib/types/resolver.d.ts.map +1 -0
- package/lib/types/stream.d.ts +4 -0
- package/lib/types/stream.d.ts.map +1 -0
- package/lib/types/validation.d.ts +7 -0
- package/lib/types/validation.d.ts.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatNovaPrompt = formatNovaPrompt;
|
|
4
|
+
const common_1 = require("@llumiverse/common");
|
|
5
|
+
const stream_js_1 = require("../stream.js");
|
|
6
|
+
const commons_js_1 = require("./commons.js");
|
|
7
|
+
/**
|
|
8
|
+
* A formatter used by Bedrock to format prompts for nova related models
|
|
9
|
+
*/
|
|
10
|
+
async function formatNovaPrompt(segments, schema) {
|
|
11
|
+
const system = [];
|
|
12
|
+
const safety = [];
|
|
13
|
+
const messages = [];
|
|
14
|
+
let negative = "";
|
|
15
|
+
let mask = "";
|
|
16
|
+
for (const segment of segments) {
|
|
17
|
+
const parts = [];
|
|
18
|
+
if (segment.files)
|
|
19
|
+
for (const f of segment.files) {
|
|
20
|
+
//TODO add video support
|
|
21
|
+
if (!f.mime_type?.startsWith('image')) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const source = await f.getStream();
|
|
25
|
+
const data = await (0, stream_js_1.readStreamAsBase64)(source);
|
|
26
|
+
const format = f.mime_type?.split('/')[1] || 'png';
|
|
27
|
+
parts.push({
|
|
28
|
+
image: {
|
|
29
|
+
format: format,
|
|
30
|
+
source: {
|
|
31
|
+
bytes: data
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (segment.content) {
|
|
37
|
+
parts.push({
|
|
38
|
+
text: segment.content
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (segment.role === common_1.PromptRole.system) {
|
|
42
|
+
system.push(segment.content);
|
|
43
|
+
}
|
|
44
|
+
else if (segment.role === common_1.PromptRole.safety) {
|
|
45
|
+
safety.push(segment.content);
|
|
46
|
+
}
|
|
47
|
+
else if (messages.length > 0 && messages[messages.length - 1].role === segment.role) {
|
|
48
|
+
//Maybe can remove for nova?
|
|
49
|
+
//concatenate messages of the same role (Claude requires alternative user and assistant roles)
|
|
50
|
+
messages[messages.length - 1].content.push(...parts);
|
|
51
|
+
}
|
|
52
|
+
else if (segment.role === common_1.PromptRole.negative) {
|
|
53
|
+
negative = negative.concat(segment.content, ', ');
|
|
54
|
+
}
|
|
55
|
+
else if (segment.role === common_1.PromptRole.mask) {
|
|
56
|
+
mask = mask.concat(segment.content, ' ');
|
|
57
|
+
}
|
|
58
|
+
else if (segment.role !== common_1.PromptRole.tool) {
|
|
59
|
+
messages.push({
|
|
60
|
+
role: segment.role,
|
|
61
|
+
content: parts
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (schema) {
|
|
66
|
+
safety.push("IMPORTANT: " + (0, commons_js_1.getJSONSafetyNotice)(schema));
|
|
67
|
+
}
|
|
68
|
+
// messages must contains at least 1 item. If the prompt does not contains a user message (but only system messages)
|
|
69
|
+
// we need to put the system messages in the messages array
|
|
70
|
+
let systemMessage = system.join('\n').trim();
|
|
71
|
+
if (messages.length === 0) {
|
|
72
|
+
if (!systemMessage) {
|
|
73
|
+
throw new Error('Prompt must contain at least one message');
|
|
74
|
+
}
|
|
75
|
+
messages.push({ content: [{ text: systemMessage }], role: 'user' });
|
|
76
|
+
systemMessage = safety.join('\n');
|
|
77
|
+
}
|
|
78
|
+
else if (safety.length > 0) {
|
|
79
|
+
systemMessage = systemMessage + '\n\nIMPORTANT: ' + safety.join('\n');
|
|
80
|
+
}
|
|
81
|
+
/*start Nova's message to make sure it answers properly in JSON
|
|
82
|
+
if enabled, this requires to add the { to Nova's response*/
|
|
83
|
+
if (schema) {
|
|
84
|
+
messages.push({
|
|
85
|
+
role: "assistant",
|
|
86
|
+
content: [{
|
|
87
|
+
text: "{"
|
|
88
|
+
}]
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
// put system messages first and safety last
|
|
92
|
+
return {
|
|
93
|
+
system: systemMessage ? [{ text: systemMessage }] : [{ text: "" }],
|
|
94
|
+
messages: messages,
|
|
95
|
+
negative: negative || undefined,
|
|
96
|
+
mask: mask || undefined,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=nova.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nova.js","sourceRoot":"","sources":["../../../src/formatters/n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,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7C,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,IAAI,CAAC,aAAa,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAChE,CAAC;QACD,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QACpE,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;SAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,aAAa,GAAG,aAAa,GAAG,iBAAiB,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1E,CAAC;IAED;8DAC0D;IAE1D,IAAI,MAAM,EAAE,CAAC;QACT,QAAQ,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,CAAC;oBACN,IAAI,EAAE,GAAG;iBACZ,CAAC;SACL,CAAC,CAAC;IACP,CAAC;IAED,4CAA4C;IAC5C,OAAO;QACH,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;QAClE,QAAQ,EAAE,QAAQ;QAClB,QAAQ,EAAE,QAAQ,IAAI,SAAS;QAC/B,IAAI,EAAE,IAAI,IAAI,SAAS;KAC1B,CAAA;AACL,CAAC"}
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Driver.js"), exports);
|
|
18
|
+
__exportStar(require("./json.js"), exports);
|
|
19
|
+
__exportStar(require("./stream.js"), exports);
|
|
20
|
+
__exportStar(require("./conversation-utils.js"), exports);
|
|
21
|
+
__exportStar(require("@llumiverse/common"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,4CAA0B;AAC1B,8CAA4B;AAC5B,0DAAwC;AACxC,qDAAmC"}
|
package/lib/cjs/json.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractAndParseJSON = extractAndParseJSON;
|
|
4
|
+
exports.parseJSON = parseJSON;
|
|
5
|
+
const jsonrepair_1 = require("jsonrepair");
|
|
6
|
+
function extractJsonFromText(text) {
|
|
7
|
+
const start = text.indexOf("{");
|
|
8
|
+
const end = text.lastIndexOf("}");
|
|
9
|
+
return text.substring(start, end + 1);
|
|
10
|
+
}
|
|
11
|
+
function extractAndParseJSON(text) {
|
|
12
|
+
return parseJSON(extractJsonFromText(text));
|
|
13
|
+
}
|
|
14
|
+
function parseJSON(text) {
|
|
15
|
+
text = text.trim();
|
|
16
|
+
try {
|
|
17
|
+
return JSON.parse(text);
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
// use a relaxed parser
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse((0, jsonrepair_1.jsonrepair)(text));
|
|
23
|
+
}
|
|
24
|
+
catch (err2) { // throw the original error
|
|
25
|
+
throw err;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../src/json.ts"],"names":[],"mappings":";;AASA,kDAEC;AAED,8BAYC;AAxBD,2CAAwC;AAExC,SAAS,mBAAmB,CAAC,IAAY;IACrC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAChC,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAClC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC;AAC1C,CAAC;AAED,SAAgB,mBAAmB,CAAC,IAAY;IAC5C,OAAO,SAAS,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC;AAChD,CAAC;AAED,SAAgB,SAAS,CAAC,IAAY;IAClC,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IACnB,IAAI,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAChB,uBAAuB;QACvB,IAAI,CAAC;YACD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAA,uBAAU,EAAC,IAAI,CAAC,CAAC,CAAC;QACxC,CAAC;QAAC,OAAO,IAAS,EAAE,CAAC,CAAC,2BAA2B;YAC7C,MAAM,GAAG,CAAC;QACd,CAAC;IACL,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveField = resolveField;
|
|
4
|
+
/**
|
|
5
|
+
* Get the property named by "name" of the given object
|
|
6
|
+
* If an array is indexed using a string key then a map is done and an array with the content of the properties with that name are returned
|
|
7
|
+
* Ex: docs.text => will return an array of text properties of the docs array
|
|
8
|
+
* @param object the object
|
|
9
|
+
* @param name the name of the property.
|
|
10
|
+
* @returns the property value
|
|
11
|
+
*/
|
|
12
|
+
function _prop(object, name) {
|
|
13
|
+
if (object === undefined) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
if (Array.isArray(object)) {
|
|
17
|
+
const index = +name;
|
|
18
|
+
if (isNaN(index)) {
|
|
19
|
+
// map array to property
|
|
20
|
+
return object.map(item => item[name]);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return object[index];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return object[name];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function resolveField(object, path) {
|
|
31
|
+
let p = object;
|
|
32
|
+
if (!p)
|
|
33
|
+
return p;
|
|
34
|
+
if (!path.length)
|
|
35
|
+
return p;
|
|
36
|
+
const last = path.length - 1;
|
|
37
|
+
for (let i = 0; i < last; i++) {
|
|
38
|
+
p = _prop(p, path[i]);
|
|
39
|
+
if (!p) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return _prop(p, path[last]);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolver.js","sourceRoot":"","sources":["../../src/res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ict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readStreamAsBase64 = readStreamAsBase64;
|
|
4
|
+
exports.readStreamAsString = readStreamAsString;
|
|
5
|
+
exports.readStreamAsUint8Array = readStreamAsUint8Array;
|
|
6
|
+
async function readStreamAsBase64(stream) {
|
|
7
|
+
const uint8Array = await readStreamAsUint8Array(stream);
|
|
8
|
+
return Buffer.from(uint8Array).toString('base64');
|
|
9
|
+
}
|
|
10
|
+
async function readStreamAsString(stream) {
|
|
11
|
+
const uint8Array = await readStreamAsUint8Array(stream);
|
|
12
|
+
return Buffer.from(uint8Array).toString();
|
|
13
|
+
}
|
|
14
|
+
async function readStreamAsUint8Array(stream) {
|
|
15
|
+
const chunks = [];
|
|
16
|
+
let totalLength = 0;
|
|
17
|
+
for await (const chunk of stream) {
|
|
18
|
+
const uint8Chunk = chunk instanceof Uint8Array ? chunk : new Uint8Array(chunk);
|
|
19
|
+
chunks.push(uint8Chunk);
|
|
20
|
+
totalLength += uint8Chunk.length;
|
|
21
|
+
}
|
|
22
|
+
const combined = new Uint8Array(totalLength);
|
|
23
|
+
let offset = 0;
|
|
24
|
+
for (const chunk of chunks) {
|
|
25
|
+
combined.set(chunk, offset);
|
|
26
|
+
offset += chunk.length;
|
|
27
|
+
}
|
|
28
|
+
return combined;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/stream.ts"],"names":[],"mappings":";;AACA,gDAGC;AAED,gDAGC;AAED,wDAmBC;AA7BM,KAAK,UAAU,kBAAkB,CAAC,MAAsB;IAC3D,MAAM,UAAU,GAAG,MAAM,sBAAsB,CAAC,MAAM,CAAC,CAAC;IACxD,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACtD,CAAC;AAEM,KAAK,UAAU,kBAAkB,CAAC,MAAsB;IAC3D,MAAM,UAAU,GAAG,MAAM,sBAAsB,CAAC,MAAM,CAAC,CAAC;IACxD,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC;AAC9C,CAAC;AAEM,KAAK,UAAU,sBAAsB,CAAC,MAAsB;IAC/D,MAAM,MAAM,GAAiB,EAAE,CAAC;IAChC,IAAI,WAAW,GAAG,CAAC,CAAC;IAEpB,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC/B,MAAM,UAAU,GAAG,KAAK,YAAY,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;QAE/E,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACxB,WAAW,IAAI,UAAU,CAAC,MAAM,CAAC;IACrC,CAAC;IAED,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;IAC7C,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QACzB,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC;IAC3B,CAAC;IAED,OAAO,QAAQ,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ValidationError = void 0;
|
|
7
|
+
exports.validateResult = validateResult;
|
|
8
|
+
const ajv_1 = require("ajv");
|
|
9
|
+
const ajv_formats_1 = __importDefault(require("ajv-formats"));
|
|
10
|
+
const json_js_1 = require("./json.js");
|
|
11
|
+
const resolver_js_1 = require("./resolver.js");
|
|
12
|
+
const ajv = new ajv_1.Ajv({
|
|
13
|
+
coerceTypes: 'array',
|
|
14
|
+
allowDate: true,
|
|
15
|
+
strict: false,
|
|
16
|
+
useDefaults: true,
|
|
17
|
+
removeAdditional: "failing"
|
|
18
|
+
});
|
|
19
|
+
//use ts ignore to avoid error with ESM and ajv-formats
|
|
20
|
+
// @ts-ignore This expression is not callable
|
|
21
|
+
(0, ajv_formats_1.default)(ajv);
|
|
22
|
+
class ValidationError extends Error {
|
|
23
|
+
code;
|
|
24
|
+
constructor(code, message) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.code = code;
|
|
27
|
+
this.name = 'ValidationError';
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.ValidationError = ValidationError;
|
|
31
|
+
function parseCompletionAsJson(data) {
|
|
32
|
+
let lastError;
|
|
33
|
+
for (const part of data) {
|
|
34
|
+
if (part.type === "text") {
|
|
35
|
+
const text = part.value.trim();
|
|
36
|
+
try {
|
|
37
|
+
return (0, json_js_1.extractAndParseJSON)(text);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
lastError = new ValidationError("json_error", error.message);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (!lastError) {
|
|
45
|
+
lastError = new ValidationError("json_error", "No JSON compatible response found in completion result");
|
|
46
|
+
}
|
|
47
|
+
throw lastError;
|
|
48
|
+
}
|
|
49
|
+
function validateResult(data, schema) {
|
|
50
|
+
let json;
|
|
51
|
+
if (Array.isArray(data)) {
|
|
52
|
+
const jsonResults = data.filter(r => r.type === "json");
|
|
53
|
+
if (jsonResults.length > 0) {
|
|
54
|
+
json = jsonResults[0].value;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
try {
|
|
58
|
+
json = parseCompletionAsJson(data);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
throw new ValidationError("json_error", error.message);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
throw new Error("Data to validate must be an array");
|
|
67
|
+
}
|
|
68
|
+
const validate = ajv.compile(schema);
|
|
69
|
+
const valid = validate(json);
|
|
70
|
+
if (!valid && validate.errors) {
|
|
71
|
+
let errors = [];
|
|
72
|
+
for (const e of validate.errors) {
|
|
73
|
+
const path = e.instancePath.split("/").slice(1);
|
|
74
|
+
const value = (0, resolver_js_1.resolveField)(json, path);
|
|
75
|
+
const schemaPath = e.schemaPath.split("/").slice(1);
|
|
76
|
+
const schemaFieldFormat = (0, resolver_js_1.resolveField)(schema, schemaPath);
|
|
77
|
+
const schemaField = (0, resolver_js_1.resolveField)(schema, schemaPath.slice(0, -3));
|
|
78
|
+
//ignore date if empty or null
|
|
79
|
+
if (!value
|
|
80
|
+
&& ["date", "date-time"].includes(schemaFieldFormat)
|
|
81
|
+
&& !schemaField?.required?.includes(path[path.length - 1])) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
errors.push(e);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//console.log("Errors", errors)
|
|
89
|
+
if (errors.length > 0) {
|
|
90
|
+
const errorsMessage = errors.map(e => `${e.instancePath}: ${e.message}\n${JSON.stringify(e.params)}`).join(",\n\n");
|
|
91
|
+
throw new ValidationError("validation_error", errorsMessage);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return [{ type: "json", value: json }];
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/validation.ts"],"names":[],"mappings":";;;;;;AAiDA,wCAgDC;AAhGD,6BAA0B;AAC1B,8DAAqC;AACrC,uCAAgD;AAChD,+CAA6C;AAG7C,MAAM,GAAG,GAAG,IAAI,SAAG,CAAC;IAChB,WAAW,EAAE,OAAO;IACpB,S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9B,IAAI,CAAC,KAAK;mBACH,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,iBAAiB,CAAC;mBACjD,CAAC,WAAW,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC7D,SAAS;YACb,CAAC;iBAAM,CAAC;gBACJ,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACnB,CAAC;QACL,CAAC;QAED,+BAA+B;QAC/B,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpB,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC,OAAO,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACpH,MAAM,IAAI,eAAe,CAAC,kBAAkB,EAAE,aAAa,CAAC,CAAA;QAChE,CAAC;IACL,CAAC;IAED,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
export class DefaultCompletionStream {
|
|
2
|
+
driver;
|
|
3
|
+
prompt;
|
|
4
|
+
options;
|
|
5
|
+
chunks; // Counter for number of chunks instead of storing strings
|
|
6
|
+
completion;
|
|
7
|
+
constructor(driver, prompt, options) {
|
|
8
|
+
this.driver = driver;
|
|
9
|
+
this.prompt = prompt;
|
|
10
|
+
this.options = options;
|
|
11
|
+
this.chunks = 0;
|
|
12
|
+
}
|
|
13
|
+
async *[Symbol.asyncIterator]() {
|
|
14
|
+
// reset state
|
|
15
|
+
this.completion = undefined;
|
|
16
|
+
this.chunks = 0;
|
|
17
|
+
const accumulatedResults = []; // Accumulate CompletionResult[] from chunks
|
|
18
|
+
const accumulatedToolUse = new Map(); // Accumulate tool_use by id
|
|
19
|
+
this.driver.logger.debug(`[${this.driver.provider}] Streaming Execution of ${this.options.model} with prompt`);
|
|
20
|
+
const start = Date.now();
|
|
21
|
+
let finish_reason = undefined;
|
|
22
|
+
let promptTokens = 0;
|
|
23
|
+
let resultTokens = undefined;
|
|
24
|
+
try {
|
|
25
|
+
const stream = await this.driver.requestTextCompletionStream(this.prompt, this.options);
|
|
26
|
+
for await (const chunk of stream) {
|
|
27
|
+
if (chunk) {
|
|
28
|
+
if (typeof chunk === 'string') {
|
|
29
|
+
this.chunks++;
|
|
30
|
+
yield chunk;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
if (chunk.finish_reason) { //Do not replace non-null values with null values
|
|
34
|
+
finish_reason = chunk.finish_reason; //Used to skip empty finish_reason chunks coming after "stop" or "length"
|
|
35
|
+
}
|
|
36
|
+
if (chunk.token_usage) {
|
|
37
|
+
//Tokens returned include prior parts of stream,
|
|
38
|
+
//so overwrite rather than accumulate
|
|
39
|
+
//Math.max used as some models report final token count at beginning of stream
|
|
40
|
+
promptTokens = Math.max(promptTokens, chunk.token_usage.prompt ?? 0);
|
|
41
|
+
resultTokens = Math.max(resultTokens ?? 0, chunk.token_usage.result ?? 0);
|
|
42
|
+
}
|
|
43
|
+
// Accumulate tool_use from chunks
|
|
44
|
+
// Note: During streaming, tool_input comes as string chunks that need concatenation
|
|
45
|
+
if (chunk.tool_use && chunk.tool_use.length > 0) {
|
|
46
|
+
for (const tool of chunk.tool_use) {
|
|
47
|
+
const existing = accumulatedToolUse.get(tool.id);
|
|
48
|
+
if (existing) {
|
|
49
|
+
// Merge tool input (for streaming where arguments come as string pieces)
|
|
50
|
+
if (tool.tool_input !== null && tool.tool_input !== undefined) {
|
|
51
|
+
const existingInput = existing.tool_input;
|
|
52
|
+
const newInput = tool.tool_input;
|
|
53
|
+
if (typeof existingInput === 'string' && typeof newInput === 'string') {
|
|
54
|
+
// Concatenate string arguments
|
|
55
|
+
existing.tool_input = existingInput + newInput;
|
|
56
|
+
}
|
|
57
|
+
else if (existingInput && typeof existingInput === 'object' && newInput && typeof newInput === 'object') {
|
|
58
|
+
// Merge objects
|
|
59
|
+
existing.tool_input = { ...existingInput, ...newInput };
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
existing.tool_input = tool.tool_input;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Update tool name if provided (might come in later chunk)
|
|
66
|
+
if (tool.tool_name) {
|
|
67
|
+
existing.tool_name = tool.tool_name;
|
|
68
|
+
}
|
|
69
|
+
// Update actual ID if provided (OpenAI sends id only in first chunk)
|
|
70
|
+
if (tool._actual_id) {
|
|
71
|
+
existing._actual_id = tool._actual_id;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
// New tool call
|
|
76
|
+
accumulatedToolUse.set(tool.id, { ...tool });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (Array.isArray(chunk.result) && chunk.result.length > 0) {
|
|
81
|
+
// Process each result in the chunk, combining consecutive text/JSON
|
|
82
|
+
for (const result of chunk.result) {
|
|
83
|
+
// Check if we can combine with the last accumulated result
|
|
84
|
+
const lastResult = accumulatedResults[accumulatedResults.length - 1];
|
|
85
|
+
if (lastResult &&
|
|
86
|
+
((lastResult.type === 'text' && result.type === 'text') ||
|
|
87
|
+
(lastResult.type === 'json' && result.type === 'json'))) {
|
|
88
|
+
// Combine consecutive text or JSON results
|
|
89
|
+
if (result.type === 'text') {
|
|
90
|
+
lastResult.value += result.value;
|
|
91
|
+
}
|
|
92
|
+
else if (result.type === 'json') {
|
|
93
|
+
// For JSON, combine the parsed objects directly
|
|
94
|
+
try {
|
|
95
|
+
const lastParsed = lastResult.value;
|
|
96
|
+
const currentParsed = result.value;
|
|
97
|
+
if (lastParsed !== null && typeof lastParsed === 'object' &&
|
|
98
|
+
currentParsed !== null && typeof currentParsed === 'object') {
|
|
99
|
+
const combined = { ...lastParsed, ...currentParsed };
|
|
100
|
+
lastResult.value = combined;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
// If not objects, convert to string and concatenate
|
|
104
|
+
const lastStr = typeof lastParsed === 'string' ? lastParsed : JSON.stringify(lastParsed);
|
|
105
|
+
const currentStr = typeof currentParsed === 'string' ? currentParsed : JSON.stringify(currentParsed);
|
|
106
|
+
lastResult.value = lastStr + currentStr;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
// If anything fails, just concatenate string representations
|
|
111
|
+
lastResult.value = String(lastResult.value) + String(result.value);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
// Add as new result
|
|
117
|
+
accumulatedResults.push(result);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// Convert CompletionResult[] to string for streaming
|
|
121
|
+
// Only yield if we have results to show
|
|
122
|
+
const resultText = chunk.result.map(r => {
|
|
123
|
+
switch (r.type) {
|
|
124
|
+
case 'text':
|
|
125
|
+
return r.value;
|
|
126
|
+
case 'json':
|
|
127
|
+
return JSON.stringify(r.value);
|
|
128
|
+
case 'image':
|
|
129
|
+
// Show truncated image placeholder for streaming
|
|
130
|
+
const truncatedValue = typeof r.value === 'string' ? r.value.slice(0, 10) : String(r.value).slice(0, 10);
|
|
131
|
+
return `\n[Image: ${truncatedValue}...]\n`;
|
|
132
|
+
default:
|
|
133
|
+
return String(r.value || '');
|
|
134
|
+
}
|
|
135
|
+
}).join('');
|
|
136
|
+
if (resultText) {
|
|
137
|
+
this.chunks++;
|
|
138
|
+
yield resultText;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
error.prompt = this.prompt;
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
// Return undefined for the ExecutionTokenUsage object if there is nothing to fill it with.
|
|
150
|
+
// Allows for checking for truthy-ness on token_usage, rather than it's internals. For testing and downstream usage.
|
|
151
|
+
const tokens = resultTokens ?
|
|
152
|
+
{ prompt: promptTokens, result: resultTokens, total: resultTokens + promptTokens, } : undefined;
|
|
153
|
+
// Convert accumulated tool_use Map to array
|
|
154
|
+
const toolUseArray = accumulatedToolUse.size > 0 ? Array.from(accumulatedToolUse.values()) : undefined;
|
|
155
|
+
// Finalize tool calls: restore actual IDs and parse JSON arguments
|
|
156
|
+
if (toolUseArray) {
|
|
157
|
+
for (const tool of toolUseArray) {
|
|
158
|
+
// Restore actual ID from OpenAI (was stored in _actual_id during streaming)
|
|
159
|
+
if (tool._actual_id) {
|
|
160
|
+
tool.id = tool._actual_id;
|
|
161
|
+
delete tool._actual_id;
|
|
162
|
+
}
|
|
163
|
+
// Parse tool_input strings as JSON if needed (streaming sends arguments as string chunks)
|
|
164
|
+
if (typeof tool.tool_input === 'string') {
|
|
165
|
+
try {
|
|
166
|
+
tool.tool_input = JSON.parse(tool.tool_input);
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
// Keep as string if not valid JSON
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
this.completion = {
|
|
175
|
+
result: accumulatedResults, // Return the accumulated CompletionResult[] instead of text
|
|
176
|
+
prompt: this.prompt,
|
|
177
|
+
execution_time: Date.now() - start,
|
|
178
|
+
token_usage: tokens,
|
|
179
|
+
finish_reason: finish_reason,
|
|
180
|
+
chunks: this.chunks,
|
|
181
|
+
tool_use: toolUseArray,
|
|
182
|
+
};
|
|
183
|
+
// Build conversation context for multi-turn support
|
|
184
|
+
const conversation = this.driver.buildStreamingConversation(this.prompt, accumulatedResults, toolUseArray, this.options);
|
|
185
|
+
if (conversation !== undefined) {
|
|
186
|
+
this.completion.conversation = conversation;
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
if (this.completion) {
|
|
190
|
+
this.driver.validateResult(this.completion, this.options);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
error.prompt = this.prompt;
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
export class FallbackCompletionStream {
|
|
200
|
+
driver;
|
|
201
|
+
prompt;
|
|
202
|
+
options;
|
|
203
|
+
completion;
|
|
204
|
+
constructor(driver, prompt, options) {
|
|
205
|
+
this.driver = driver;
|
|
206
|
+
this.prompt = prompt;
|
|
207
|
+
this.options = options;
|
|
208
|
+
}
|
|
209
|
+
async *[Symbol.asyncIterator]() {
|
|
210
|
+
// reset state
|
|
211
|
+
this.completion = undefined;
|
|
212
|
+
this.driver.logger.debug(`[${this.driver.provider}] Streaming is not supported, falling back to blocking execution`);
|
|
213
|
+
try {
|
|
214
|
+
const completion = await this.driver._execute(this.prompt, this.options);
|
|
215
|
+
// For fallback streaming, yield the text content but keep the original completion
|
|
216
|
+
const content = completion.result.map(r => {
|
|
217
|
+
switch (r.type) {
|
|
218
|
+
case 'text':
|
|
219
|
+
return r.value;
|
|
220
|
+
case 'json':
|
|
221
|
+
return JSON.stringify(r.value);
|
|
222
|
+
case 'image':
|
|
223
|
+
// Show truncated image placeholder for streaming
|
|
224
|
+
const truncatedValue = typeof r.value === 'string' ? r.value.slice(0, 10) : String(r.value).slice(0, 10);
|
|
225
|
+
return `[Image: ${truncatedValue}...]`;
|
|
226
|
+
default:
|
|
227
|
+
return String(r.value || '');
|
|
228
|
+
}
|
|
229
|
+
}).join('');
|
|
230
|
+
yield content;
|
|
231
|
+
this.completion = completion; // Return the original completion with untouched CompletionResult[]
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
error.prompt = this.prompt;
|
|
235
|
+
throw error;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
//# sourceMappingURL=CompletionStream.js.map
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