@llumiverse/core 1.3.0 → 1.4.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/lib/CompletionStream.d.ts +48 -0
- package/lib/CompletionStream.d.ts.map +1 -0
- package/lib/{esm/CompletionStream.js → CompletionStream.js} +142 -67
- package/lib/CompletionStream.js.map +1 -0
- package/lib/{types/Driver.d.ts → Driver.d.ts} +38 -5
- package/lib/Driver.d.ts.map +1 -0
- package/lib/{esm/Driver.js → Driver.js} +151 -106
- package/lib/Driver.js.map +1 -0
- package/lib/{types/async.d.ts → async.d.ts} +3 -3
- package/lib/async.d.ts.map +1 -0
- package/lib/{esm/async.js → async.js} +4 -4
- package/lib/async.js.map +1 -0
- package/lib/{types/conversation-utils.d.ts → conversation-utils.d.ts} +9 -0
- package/lib/conversation-utils.d.ts.map +1 -0
- package/lib/{esm/conversation-utils.js → conversation-utils.js} +78 -15
- package/lib/conversation-utils.js.map +1 -0
- package/lib/embeddings.d.ts +58 -0
- package/lib/embeddings.d.ts.map +1 -0
- package/lib/embeddings.js +131 -0
- package/lib/embeddings.js.map +1 -0
- package/lib/formatters/commons.d.ts +3 -0
- package/lib/formatters/commons.d.ts.map +1 -0
- package/lib/formatters/commons.js +4 -0
- package/lib/formatters/commons.js.map +1 -0
- package/lib/{types/formatters → formatters}/generic.d.ts +2 -2
- package/lib/formatters/generic.d.ts.map +1 -0
- package/lib/{esm/formatters → formatters}/generic.js +8 -8
- package/lib/formatters/generic.js.map +1 -0
- package/lib/formatters/index.d.ts +4 -0
- package/lib/formatters/index.d.ts.map +1 -0
- package/lib/formatters/index.js +4 -0
- package/lib/formatters/index.js.map +1 -0
- package/lib/{types/formatters → formatters}/nova.d.ts +4 -4
- package/lib/formatters/nova.d.ts.map +1 -0
- package/lib/{esm/formatters → formatters}/nova.js +19 -17
- package/lib/formatters/nova.js.map +1 -0
- package/lib/http-agent.d.ts +53 -0
- package/lib/http-agent.d.ts.map +1 -0
- package/lib/http-agent.js +141 -0
- package/lib/http-agent.js.map +1 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +7 -0
- package/lib/index.js.map +1 -0
- package/lib/{types/json.d.ts → json.d.ts} +1 -1
- package/lib/json.d.ts.map +1 -0
- package/lib/{esm/json.js → json.js} +4 -3
- package/lib/json.js.map +1 -0
- package/lib/logger.d.ts +3 -0
- package/lib/logger.d.ts.map +1 -0
- package/lib/logger.js +42 -0
- package/lib/logger.js.map +1 -0
- package/lib/resolver.d.ts +2 -0
- package/lib/resolver.d.ts.map +1 -0
- package/lib/{esm/resolver.js → resolver.js} +7 -4
- package/lib/resolver.js.map +1 -0
- package/lib/stream.d.ts.map +1 -0
- package/lib/stream.js.map +1 -0
- package/lib/{types/validation.d.ts → validation.d.ts} +1 -1
- package/lib/validation.d.ts.map +1 -0
- package/lib/validation.js +100 -0
- package/lib/validation.js.map +1 -0
- package/package.json +28 -38
- package/src/CompletionStream.ts +208 -115
- package/src/Driver.error.test.ts +101 -72
- package/src/Driver.ts +208 -152
- package/src/async.ts +30 -30
- package/src/conversation-utils.ts +92 -16
- package/src/embeddings.ts +157 -0
- package/src/formatters/commons.ts +2 -2
- package/src/formatters/generic.ts +20 -17
- package/src/formatters/index.ts +3 -3
- package/src/formatters/nova.ts +53 -51
- package/src/http-agent.test.ts +281 -0
- package/src/http-agent.ts +177 -0
- package/src/index.ts +7 -5
- package/src/json.ts +6 -5
- package/src/logger.ts +42 -0
- package/src/resolver.ts +12 -9
- package/src/stream.ts +4 -5
- package/src/validation.ts +42 -29
- package/lib/cjs/CompletionStream.js +0 -293
- package/lib/cjs/CompletionStream.js.map +0 -1
- package/lib/cjs/Driver.js +0 -300
- package/lib/cjs/Driver.js.map +0 -1
- package/lib/cjs/async.js +0 -131
- package/lib/cjs/async.js.map +0 -1
- package/lib/cjs/conversation-utils.js +0 -579
- package/lib/cjs/conversation-utils.js.map +0 -1
- package/lib/cjs/formatters/commons.js +0 -7
- package/lib/cjs/formatters/commons.js.map +0 -1
- package/lib/cjs/formatters/generic.js +0 -59
- package/lib/cjs/formatters/generic.js.map +0 -1
- package/lib/cjs/formatters/index.js +0 -20
- package/lib/cjs/formatters/index.js.map +0 -1
- package/lib/cjs/formatters/nova.js +0 -99
- package/lib/cjs/formatters/nova.js.map +0 -1
- package/lib/cjs/index.js +0 -22
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/json.js +0 -29
- package/lib/cjs/json.js.map +0 -1
- package/lib/cjs/package.json +0 -3
- package/lib/cjs/resolver.js +0 -45
- package/lib/cjs/resolver.js.map +0 -1
- package/lib/cjs/stream.js +0 -30
- package/lib/cjs/stream.js.map +0 -1
- package/lib/cjs/validation.js +0 -96
- package/lib/cjs/validation.js.map +0 -1
- package/lib/esm/CompletionStream.js.map +0 -1
- package/lib/esm/Driver.js.map +0 -1
- package/lib/esm/async.js.map +0 -1
- package/lib/esm/conversation-utils.js.map +0 -1
- package/lib/esm/formatters/commons.js +0 -4
- package/lib/esm/formatters/commons.js.map +0 -1
- package/lib/esm/formatters/generic.js.map +0 -1
- package/lib/esm/formatters/index.js +0 -4
- package/lib/esm/formatters/index.js.map +0 -1
- package/lib/esm/formatters/nova.js.map +0 -1
- package/lib/esm/index.js +0 -6
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/json.js.map +0 -1
- package/lib/esm/resolver.js.map +0 -1
- package/lib/esm/stream.js.map +0 -1
- package/lib/esm/validation.js +0 -88
- package/lib/esm/validation.js.map +0 -1
- package/lib/types/CompletionStream.d.ts +0 -20
- package/lib/types/CompletionStream.d.ts.map +0 -1
- package/lib/types/Driver.d.ts.map +0 -1
- package/lib/types/async.d.ts.map +0 -1
- package/lib/types/conversation-utils.d.ts.map +0 -1
- package/lib/types/formatters/commons.d.ts +0 -3
- package/lib/types/formatters/commons.d.ts.map +0 -1
- package/lib/types/formatters/generic.d.ts.map +0 -1
- package/lib/types/formatters/index.d.ts +0 -4
- package/lib/types/formatters/index.d.ts.map +0 -1
- package/lib/types/formatters/nova.d.ts.map +0 -1
- package/lib/types/index.d.ts +0 -6
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/json.d.ts.map +0 -1
- package/lib/types/resolver.d.ts +0 -2
- package/lib/types/resolver.d.ts.map +0 -1
- package/lib/types/stream.d.ts.map +0 -1
- package/lib/types/validation.d.ts.map +0 -1
- /package/lib/{types/stream.d.ts → stream.d.ts} +0 -0
- /package/lib/{esm/stream.js → stream.js} +0 -0
package/src/validation.ts
CHANGED
|
@@ -1,67 +1,76 @@
|
|
|
1
|
-
import { CompletionResult, ResultValidationError } from
|
|
1
|
+
import type { CompletionResult, JSONValue, ResultValidationError } from '@llumiverse/common';
|
|
2
2
|
import { Ajv } from 'ajv';
|
|
3
3
|
import addFormats from 'ajv-formats';
|
|
4
|
-
import { extractAndParseJSON } from
|
|
4
|
+
import { extractAndParseJSON } from './json.js';
|
|
5
5
|
import { resolveField } from './resolver.js';
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
const ajv = new Ajv({
|
|
9
8
|
coerceTypes: 'array',
|
|
10
9
|
allowDate: true,
|
|
11
10
|
strict: false,
|
|
12
11
|
useDefaults: true,
|
|
13
|
-
removeAdditional:
|
|
12
|
+
removeAdditional: 'failing',
|
|
14
13
|
});
|
|
15
14
|
|
|
16
|
-
//
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
addFormats(ajv)
|
|
15
|
+
// biome-ignore lint/suspicious/noTsIgnore: ajv-formats default export inconsistently callable under ESM/CJS interop
|
|
16
|
+
// @ts-ignore - ajv-formats default export is not callable under one of the TS configs in this monorepo
|
|
17
|
+
addFormats(ajv);
|
|
18
|
+
|
|
19
|
+
function errorMessage(error: unknown): string {
|
|
20
|
+
return error instanceof Error ? error.message : String(error);
|
|
21
|
+
}
|
|
19
22
|
|
|
23
|
+
function getRequiredFields(schemaField: unknown): string[] {
|
|
24
|
+
if (!schemaField || typeof schemaField !== 'object') {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
const required = (schemaField as Record<string, unknown>).required;
|
|
28
|
+
return Array.isArray(required) ? required.filter((field): field is string => typeof field === 'string') : [];
|
|
29
|
+
}
|
|
20
30
|
|
|
21
31
|
export class ValidationError extends Error implements ResultValidationError {
|
|
22
32
|
constructor(
|
|
23
33
|
public code: 'validation_error' | 'json_error',
|
|
24
|
-
message: string
|
|
34
|
+
message: string,
|
|
25
35
|
) {
|
|
26
|
-
super(message)
|
|
27
|
-
this.name = 'ValidationError'
|
|
36
|
+
super(message);
|
|
37
|
+
this.name = 'ValidationError';
|
|
28
38
|
}
|
|
29
39
|
}
|
|
30
40
|
|
|
31
41
|
function parseCompletionAsJson(data: CompletionResult[]) {
|
|
32
42
|
let lastError: ValidationError | undefined;
|
|
33
43
|
for (const part of data) {
|
|
34
|
-
if (part.type ===
|
|
44
|
+
if (part.type === 'text') {
|
|
35
45
|
const text = part.value.trim();
|
|
36
46
|
try {
|
|
37
47
|
return extractAndParseJSON(text);
|
|
38
|
-
} catch (error:
|
|
39
|
-
lastError = new ValidationError(
|
|
48
|
+
} catch (error: unknown) {
|
|
49
|
+
lastError = new ValidationError('json_error', errorMessage(error));
|
|
40
50
|
}
|
|
41
51
|
}
|
|
42
52
|
}
|
|
43
53
|
if (!lastError) {
|
|
44
|
-
lastError = new ValidationError(
|
|
54
|
+
lastError = new ValidationError('json_error', 'No JSON compatible response found in completion result');
|
|
45
55
|
}
|
|
46
56
|
throw lastError;
|
|
47
57
|
}
|
|
48
58
|
|
|
49
|
-
|
|
50
59
|
export function validateResult(data: CompletionResult[], schema: object): CompletionResult[] {
|
|
51
|
-
let json;
|
|
60
|
+
let json: JSONValue;
|
|
52
61
|
if (Array.isArray(data)) {
|
|
53
|
-
const jsonResults = data.filter(r => r.type ===
|
|
62
|
+
const jsonResults = data.filter((r) => r.type === 'json');
|
|
54
63
|
if (jsonResults.length > 0) {
|
|
55
64
|
json = jsonResults[0].value;
|
|
56
65
|
} else {
|
|
57
66
|
try {
|
|
58
67
|
json = parseCompletionAsJson(data);
|
|
59
|
-
} catch (error:
|
|
60
|
-
throw new ValidationError(
|
|
68
|
+
} catch (error: unknown) {
|
|
69
|
+
throw new ValidationError('json_error', errorMessage(error));
|
|
61
70
|
}
|
|
62
71
|
}
|
|
63
72
|
} else {
|
|
64
|
-
throw new Error(
|
|
73
|
+
throw new Error('Data to validate must be an array');
|
|
65
74
|
}
|
|
66
75
|
|
|
67
76
|
const validate = ajv.compile(schema);
|
|
@@ -71,17 +80,19 @@ export function validateResult(data: CompletionResult[], schema: object): Comple
|
|
|
71
80
|
const errors = [];
|
|
72
81
|
|
|
73
82
|
for (const e of validate.errors) {
|
|
74
|
-
const path = e.instancePath.split(
|
|
83
|
+
const path = e.instancePath.split('/').slice(1);
|
|
75
84
|
const value = resolveField(json, path);
|
|
76
|
-
const schemaPath = e.schemaPath.split(
|
|
85
|
+
const schemaPath = e.schemaPath.split('/').slice(1);
|
|
77
86
|
const schemaFieldFormat = resolveField(schema, schemaPath);
|
|
78
87
|
const schemaField = resolveField(schema, schemaPath.slice(0, -3));
|
|
79
88
|
|
|
80
89
|
//ignore date if empty or null
|
|
81
|
-
if (
|
|
82
|
-
&&
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
if (
|
|
91
|
+
!value &&
|
|
92
|
+
typeof schemaFieldFormat === 'string' &&
|
|
93
|
+
['date', 'date-time'].includes(schemaFieldFormat) &&
|
|
94
|
+
!getRequiredFields(schemaField).includes(path[path.length - 1])
|
|
95
|
+
) {
|
|
85
96
|
} else {
|
|
86
97
|
errors.push(e);
|
|
87
98
|
}
|
|
@@ -89,10 +100,12 @@ export function validateResult(data: CompletionResult[], schema: object): Comple
|
|
|
89
100
|
|
|
90
101
|
//console.log("Errors", errors)
|
|
91
102
|
if (errors.length > 0) {
|
|
92
|
-
const errorsMessage = errors
|
|
93
|
-
|
|
103
|
+
const errorsMessage = errors
|
|
104
|
+
.map((e) => `${e.instancePath}: ${e.message}\n${JSON.stringify(e.params)}`)
|
|
105
|
+
.join(',\n\n');
|
|
106
|
+
throw new ValidationError('validation_error', errorsMessage);
|
|
94
107
|
}
|
|
95
108
|
}
|
|
96
109
|
|
|
97
|
-
return [{ type:
|
|
110
|
+
return [{ type: 'json', value: json }];
|
|
98
111
|
}
|
|
@@ -1,293 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FallbackCompletionStream = exports.DefaultCompletionStream = void 0;
|
|
4
|
-
const common_1 = require("@llumiverse/common");
|
|
5
|
-
class DefaultCompletionStream {
|
|
6
|
-
driver;
|
|
7
|
-
prompt;
|
|
8
|
-
options;
|
|
9
|
-
chunks; // Counter for number of chunks instead of storing strings
|
|
10
|
-
completion;
|
|
11
|
-
constructor(driver, prompt, options) {
|
|
12
|
-
this.driver = driver;
|
|
13
|
-
this.prompt = prompt;
|
|
14
|
-
this.options = options;
|
|
15
|
-
this.chunks = 0;
|
|
16
|
-
}
|
|
17
|
-
async *[Symbol.asyncIterator]() {
|
|
18
|
-
// reset state
|
|
19
|
-
this.completion = undefined;
|
|
20
|
-
this.chunks = 0;
|
|
21
|
-
const accumulatedResults = []; // Accumulate CompletionResult[] from chunks
|
|
22
|
-
const accumulatedToolUse = new Map(); // Accumulate tool_use by id
|
|
23
|
-
this.driver.logger.debug(`[${this.driver.provider}] Streaming Execution of ${this.options.model} with prompt`);
|
|
24
|
-
const start = Date.now();
|
|
25
|
-
let finish_reason = undefined;
|
|
26
|
-
let promptTokens = 0;
|
|
27
|
-
let resultTokens = undefined;
|
|
28
|
-
let promptCachedTokens = undefined;
|
|
29
|
-
let promptCacheWriteTokens = undefined;
|
|
30
|
-
let promptNewTokens = undefined;
|
|
31
|
-
try {
|
|
32
|
-
const stream = await this.driver.requestTextCompletionStream(this.prompt, this.options);
|
|
33
|
-
for await (const chunk of stream) {
|
|
34
|
-
if (chunk) {
|
|
35
|
-
if (typeof chunk === 'string') {
|
|
36
|
-
this.chunks++;
|
|
37
|
-
yield chunk;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
if (chunk.finish_reason) { //Do not replace non-null values with null values
|
|
41
|
-
finish_reason = chunk.finish_reason; //Used to skip empty finish_reason chunks coming after "stop" or "length"
|
|
42
|
-
}
|
|
43
|
-
if (chunk.token_usage) {
|
|
44
|
-
//Tokens returned include prior parts of stream,
|
|
45
|
-
//so overwrite rather than accumulate
|
|
46
|
-
//Math.max used as some models report final token count at beginning of stream
|
|
47
|
-
promptTokens = Math.max(promptTokens, chunk.token_usage.prompt ?? 0);
|
|
48
|
-
resultTokens = Math.max(resultTokens ?? 0, chunk.token_usage.result ?? 0);
|
|
49
|
-
if (chunk.token_usage.prompt_cached != null)
|
|
50
|
-
promptCachedTokens = chunk.token_usage.prompt_cached;
|
|
51
|
-
if (chunk.token_usage.prompt_cache_write != null)
|
|
52
|
-
promptCacheWriteTokens = chunk.token_usage.prompt_cache_write;
|
|
53
|
-
if (chunk.token_usage.prompt_new != null)
|
|
54
|
-
promptNewTokens = chunk.token_usage.prompt_new;
|
|
55
|
-
}
|
|
56
|
-
// Accumulate tool_use from chunks
|
|
57
|
-
// Note: During streaming, tool_input comes as string chunks that need concatenation
|
|
58
|
-
if (chunk.tool_use && chunk.tool_use.length > 0) {
|
|
59
|
-
for (const tool of chunk.tool_use) {
|
|
60
|
-
const existing = accumulatedToolUse.get(tool.id);
|
|
61
|
-
if (existing) {
|
|
62
|
-
// Merge tool input (for streaming where arguments come as string pieces)
|
|
63
|
-
if (tool.tool_input !== null && tool.tool_input !== undefined) {
|
|
64
|
-
const existingInput = existing.tool_input;
|
|
65
|
-
const newInput = tool.tool_input;
|
|
66
|
-
if (typeof existingInput === 'string' && typeof newInput === 'string') {
|
|
67
|
-
// Concatenate string arguments
|
|
68
|
-
existing.tool_input = existingInput + newInput;
|
|
69
|
-
}
|
|
70
|
-
else if (existingInput && typeof existingInput === 'object' && newInput && typeof newInput === 'object') {
|
|
71
|
-
// Merge objects
|
|
72
|
-
existing.tool_input = { ...existingInput, ...newInput };
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
existing.tool_input = tool.tool_input;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
// Update tool name if provided (might come in later chunk)
|
|
79
|
-
if (tool.tool_name) {
|
|
80
|
-
existing.tool_name = tool.tool_name;
|
|
81
|
-
}
|
|
82
|
-
// Update actual ID if provided (OpenAI sends id only in first chunk)
|
|
83
|
-
if (tool._actual_id) {
|
|
84
|
-
existing._actual_id = tool._actual_id;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
// New tool call
|
|
89
|
-
accumulatedToolUse.set(tool.id, { ...tool });
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (Array.isArray(chunk.result) && chunk.result.length > 0) {
|
|
94
|
-
// Process each result in the chunk, combining consecutive text/JSON
|
|
95
|
-
for (const result of chunk.result) {
|
|
96
|
-
// Check if we can combine with the last accumulated result
|
|
97
|
-
const lastResult = accumulatedResults[accumulatedResults.length - 1];
|
|
98
|
-
if (lastResult &&
|
|
99
|
-
((lastResult.type === 'text' && result.type === 'text') ||
|
|
100
|
-
(lastResult.type === 'json' && result.type === 'json'))) {
|
|
101
|
-
// Combine consecutive text or JSON results
|
|
102
|
-
if (result.type === 'text') {
|
|
103
|
-
lastResult.value += result.value;
|
|
104
|
-
}
|
|
105
|
-
else if (result.type === 'json') {
|
|
106
|
-
// For JSON, combine the parsed objects directly
|
|
107
|
-
try {
|
|
108
|
-
const lastParsed = lastResult.value;
|
|
109
|
-
const currentParsed = result.value;
|
|
110
|
-
if (lastParsed !== null && typeof lastParsed === 'object' &&
|
|
111
|
-
currentParsed !== null && typeof currentParsed === 'object') {
|
|
112
|
-
const combined = { ...lastParsed, ...currentParsed };
|
|
113
|
-
lastResult.value = combined;
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
// If not objects, convert to string and concatenate
|
|
117
|
-
const lastStr = typeof lastParsed === 'string' ? lastParsed : JSON.stringify(lastParsed);
|
|
118
|
-
const currentStr = typeof currentParsed === 'string' ? currentParsed : JSON.stringify(currentParsed);
|
|
119
|
-
lastResult.value = lastStr + currentStr;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
catch {
|
|
123
|
-
// If anything fails, just concatenate string representations
|
|
124
|
-
lastResult.value = String(lastResult.value) + String(result.value);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
// Add as new result
|
|
130
|
-
accumulatedResults.push(result);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
// Convert CompletionResult[] to string for streaming
|
|
134
|
-
// Only yield if we have results to show
|
|
135
|
-
const resultText = chunk.result.map(r => {
|
|
136
|
-
switch (r.type) {
|
|
137
|
-
case 'text':
|
|
138
|
-
return r.value;
|
|
139
|
-
case 'json':
|
|
140
|
-
return JSON.stringify(r.value);
|
|
141
|
-
case 'image':
|
|
142
|
-
// Show truncated image placeholder for streaming
|
|
143
|
-
const truncatedValue = typeof r.value === 'string' ? r.value.slice(0, 10) : String(r.value).slice(0, 10);
|
|
144
|
-
return `\n[Image: ${truncatedValue}...]\n`;
|
|
145
|
-
default:
|
|
146
|
-
return String(r.value || '');
|
|
147
|
-
}
|
|
148
|
-
}).join('');
|
|
149
|
-
if (resultText) {
|
|
150
|
-
this.chunks++;
|
|
151
|
-
yield resultText;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
catch (error) {
|
|
159
|
-
// Don't wrap if already a LlumiverseError
|
|
160
|
-
if (common_1.LlumiverseError.isLlumiverseError(error)) {
|
|
161
|
-
throw error;
|
|
162
|
-
}
|
|
163
|
-
throw this.driver.formatLlumiverseError(error, {
|
|
164
|
-
provider: this.driver.provider,
|
|
165
|
-
model: this.options.model,
|
|
166
|
-
operation: 'stream',
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
// Return undefined only if we never received any token data from the provider.
|
|
170
|
-
// Use !== undefined (not truthiness) because resultTokens === 0 is valid (e.g. empty output with stop).
|
|
171
|
-
const tokens = resultTokens !== undefined ? {
|
|
172
|
-
prompt: promptTokens,
|
|
173
|
-
result: resultTokens,
|
|
174
|
-
total: resultTokens + promptTokens,
|
|
175
|
-
...(promptCachedTokens != null && { prompt_cached: promptCachedTokens }),
|
|
176
|
-
...(promptCacheWriteTokens != null && { prompt_cache_write: promptCacheWriteTokens }),
|
|
177
|
-
...(promptNewTokens != null && { prompt_new: promptNewTokens }),
|
|
178
|
-
} : undefined;
|
|
179
|
-
// Convert accumulated tool_use Map to array
|
|
180
|
-
let toolUseArray = accumulatedToolUse.size > 0 ? Array.from(accumulatedToolUse.values()) : undefined;
|
|
181
|
-
// Finalize tool calls: restore actual IDs and parse JSON arguments
|
|
182
|
-
if (toolUseArray) {
|
|
183
|
-
const truncatedToolIds = new Set();
|
|
184
|
-
for (const tool of toolUseArray) {
|
|
185
|
-
// Restore actual ID from OpenAI (was stored in _actual_id during streaming)
|
|
186
|
-
if (tool._actual_id) {
|
|
187
|
-
tool.id = tool._actual_id;
|
|
188
|
-
delete tool._actual_id;
|
|
189
|
-
}
|
|
190
|
-
// Parse tool_input strings as JSON if needed (streaming sends arguments as string chunks)
|
|
191
|
-
if (typeof tool.tool_input === 'string') {
|
|
192
|
-
try {
|
|
193
|
-
tool.tool_input = JSON.parse(tool.tool_input);
|
|
194
|
-
}
|
|
195
|
-
catch {
|
|
196
|
-
// JSON parse failed — tool_input was likely truncated by max_tokens.
|
|
197
|
-
// Set to empty object to prevent string tool_input from corrupting the conversation.
|
|
198
|
-
tool.tool_input = {};
|
|
199
|
-
truncatedToolIds.add(tool.id);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
// If finish_reason is "length" (max_tokens hit), drop truncated tool calls entirely —
|
|
204
|
-
// they were cut off mid-generation and would produce invalid results.
|
|
205
|
-
if (finish_reason === 'length' && truncatedToolIds.size > 0) {
|
|
206
|
-
toolUseArray = toolUseArray.filter(t => !truncatedToolIds.has(t.id));
|
|
207
|
-
if (toolUseArray.length === 0) {
|
|
208
|
-
toolUseArray = undefined;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
this.completion = {
|
|
213
|
-
result: accumulatedResults, // Return the accumulated CompletionResult[] instead of text
|
|
214
|
-
prompt: this.prompt,
|
|
215
|
-
execution_time: Date.now() - start,
|
|
216
|
-
token_usage: tokens,
|
|
217
|
-
finish_reason: finish_reason,
|
|
218
|
-
chunks: this.chunks,
|
|
219
|
-
tool_use: toolUseArray,
|
|
220
|
-
};
|
|
221
|
-
// Build conversation context for multi-turn support
|
|
222
|
-
const conversation = this.driver.buildStreamingConversation(this.prompt, accumulatedResults, toolUseArray, this.options);
|
|
223
|
-
if (conversation !== undefined) {
|
|
224
|
-
this.completion.conversation = conversation;
|
|
225
|
-
}
|
|
226
|
-
try {
|
|
227
|
-
if (this.completion) {
|
|
228
|
-
this.driver.validateResult(this.completion, this.options);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
catch (error) {
|
|
232
|
-
// Don't wrap if already a LlumiverseError
|
|
233
|
-
if (common_1.LlumiverseError.isLlumiverseError(error)) {
|
|
234
|
-
throw error;
|
|
235
|
-
}
|
|
236
|
-
throw this.driver.formatLlumiverseError(error, {
|
|
237
|
-
provider: this.driver.provider,
|
|
238
|
-
model: this.options.model,
|
|
239
|
-
operation: 'stream',
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
exports.DefaultCompletionStream = DefaultCompletionStream;
|
|
245
|
-
class FallbackCompletionStream {
|
|
246
|
-
driver;
|
|
247
|
-
prompt;
|
|
248
|
-
options;
|
|
249
|
-
completion;
|
|
250
|
-
constructor(driver, prompt, options) {
|
|
251
|
-
this.driver = driver;
|
|
252
|
-
this.prompt = prompt;
|
|
253
|
-
this.options = options;
|
|
254
|
-
}
|
|
255
|
-
async *[Symbol.asyncIterator]() {
|
|
256
|
-
// reset state
|
|
257
|
-
this.completion = undefined;
|
|
258
|
-
this.driver.logger.debug(`[${this.driver.provider}] Streaming is not supported, falling back to blocking execution`);
|
|
259
|
-
try {
|
|
260
|
-
const completion = await this.driver._execute(this.prompt, this.options);
|
|
261
|
-
// For fallback streaming, yield the text content but keep the original completion
|
|
262
|
-
const content = completion.result.map(r => {
|
|
263
|
-
switch (r.type) {
|
|
264
|
-
case 'text':
|
|
265
|
-
return r.value;
|
|
266
|
-
case 'json':
|
|
267
|
-
return JSON.stringify(r.value);
|
|
268
|
-
case 'image':
|
|
269
|
-
// Show truncated image placeholder for streaming
|
|
270
|
-
const truncatedValue = typeof r.value === 'string' ? r.value.slice(0, 10) : String(r.value).slice(0, 10);
|
|
271
|
-
return `[Image: ${truncatedValue}...]`;
|
|
272
|
-
default:
|
|
273
|
-
return String(r.value || '');
|
|
274
|
-
}
|
|
275
|
-
}).join('');
|
|
276
|
-
yield content;
|
|
277
|
-
this.completion = completion; // Return the original completion with untouched CompletionResult[]
|
|
278
|
-
}
|
|
279
|
-
catch (error) {
|
|
280
|
-
// Don't wrap if already a LlumiverseError
|
|
281
|
-
if (common_1.LlumiverseError.isLlumiverseError(error)) {
|
|
282
|
-
throw error;
|
|
283
|
-
}
|
|
284
|
-
throw this.driver.formatLlumiverseError(error, {
|
|
285
|
-
provider: this.driver.provider,
|
|
286
|
-
model: this.options.model,
|
|
287
|
-
operation: 'stream',
|
|
288
|
-
});
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
exports.FallbackCompletionStream = FallbackCompletionStream;
|
|
293
|
-
//# sourceMappingURL=CompletionStream.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CompletionStream.js","sourceRoot":"","sources":["../../src/CompletionStream.ts"],"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