llm-exe 2.1.7 → 2.2.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/dist/index.d.mts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +919 -1116
- package/dist/index.mjs +912 -1118
- package/package.json +29 -26
- package/readme.md +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3,13 +3,6 @@ var __typeError = (msg) => {
|
|
|
3
3
|
throw TypeError(msg);
|
|
4
4
|
};
|
|
5
5
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
-
}) : x)(function(x) {
|
|
10
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
11
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
|
-
});
|
|
13
6
|
var __export = (target, all) => {
|
|
14
7
|
for (var name in all)
|
|
15
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -28,38 +21,30 @@ function pick(object, keys) {
|
|
|
28
21
|
return obj;
|
|
29
22
|
}, {});
|
|
30
23
|
}
|
|
31
|
-
__name(pick, "pick");
|
|
32
24
|
|
|
33
25
|
// src/utils/modules/ensureInputIsObject.ts
|
|
34
26
|
function ensureInputIsObject(input) {
|
|
35
27
|
if (input === null || typeof input === "undefined") {
|
|
36
|
-
return {
|
|
37
|
-
input
|
|
38
|
-
};
|
|
28
|
+
return { input };
|
|
39
29
|
}
|
|
40
30
|
switch (typeof input) {
|
|
41
31
|
case "object": {
|
|
42
32
|
if (Array.isArray(input)) {
|
|
43
|
-
return {
|
|
44
|
-
input
|
|
45
|
-
};
|
|
33
|
+
return { input };
|
|
46
34
|
}
|
|
47
35
|
return input;
|
|
48
36
|
}
|
|
49
37
|
default:
|
|
50
|
-
return {
|
|
51
|
-
input
|
|
52
|
-
};
|
|
38
|
+
return { input };
|
|
53
39
|
}
|
|
54
40
|
}
|
|
55
|
-
__name(ensureInputIsObject, "ensureInputIsObject");
|
|
56
41
|
|
|
57
42
|
// src/utils/modules/uuid.ts
|
|
58
43
|
import { v4 as uuidv4 } from "uuid";
|
|
59
44
|
|
|
60
45
|
// src/executor/_metadata.ts
|
|
61
46
|
var _state;
|
|
62
|
-
var
|
|
47
|
+
var ExecutorExecutionMetadataState = class {
|
|
63
48
|
constructor(items) {
|
|
64
49
|
__privateAdd(this, _state, {
|
|
65
50
|
start: null,
|
|
@@ -102,12 +87,9 @@ var _ExecutorExecutionMetadataState = class _ExecutorExecutionMetadataState {
|
|
|
102
87
|
}
|
|
103
88
|
};
|
|
104
89
|
_state = new WeakMap();
|
|
105
|
-
__name(_ExecutorExecutionMetadataState, "ExecutorExecutionMetadataState");
|
|
106
|
-
var ExecutorExecutionMetadataState = _ExecutorExecutionMetadataState;
|
|
107
90
|
function createMetadataState(items) {
|
|
108
91
|
return new ExecutorExecutionMetadataState(items);
|
|
109
92
|
}
|
|
110
|
-
__name(createMetadataState, "createMetadataState");
|
|
111
93
|
|
|
112
94
|
// src/utils/const.ts
|
|
113
95
|
var hookOnComplete = `onComplete`;
|
|
@@ -115,38 +97,34 @@ var hookOnError = `onError`;
|
|
|
115
97
|
var hookOnSuccess = `onSuccess`;
|
|
116
98
|
|
|
117
99
|
// src/executor/_base.ts
|
|
118
|
-
var
|
|
100
|
+
var BaseExecutor = class {
|
|
119
101
|
constructor(name, type, options) {
|
|
120
102
|
/**
|
|
121
|
-
|
|
122
|
-
|
|
103
|
+
* @property id - internal id of the executor
|
|
104
|
+
*/
|
|
123
105
|
__publicField(this, "id");
|
|
124
106
|
/**
|
|
125
|
-
|
|
126
|
-
|
|
107
|
+
* @property type - type of executor
|
|
108
|
+
*/
|
|
127
109
|
__publicField(this, "type");
|
|
128
110
|
/**
|
|
129
|
-
|
|
130
|
-
|
|
111
|
+
* @property created - timestamp date created
|
|
112
|
+
*/
|
|
131
113
|
__publicField(this, "created");
|
|
132
114
|
/**
|
|
133
|
-
|
|
134
|
-
|
|
115
|
+
* @property name - name of executor
|
|
116
|
+
*/
|
|
135
117
|
__publicField(this, "name");
|
|
136
118
|
/**
|
|
137
|
-
|
|
138
|
-
|
|
119
|
+
* @property executions -
|
|
120
|
+
*/
|
|
139
121
|
__publicField(this, "executions");
|
|
140
122
|
__publicField(this, "traceId", null);
|
|
141
123
|
/**
|
|
142
|
-
|
|
143
|
-
|
|
124
|
+
* @property hooks - hooks to be ran during execution
|
|
125
|
+
*/
|
|
144
126
|
__publicField(this, "hooks");
|
|
145
|
-
__publicField(this, "allowedHooks", [
|
|
146
|
-
hookOnComplete,
|
|
147
|
-
hookOnError,
|
|
148
|
-
hookOnSuccess
|
|
149
|
-
]);
|
|
127
|
+
__publicField(this, "allowedHooks", [hookOnComplete, hookOnError, hookOnSuccess]);
|
|
150
128
|
this.id = uuidv4();
|
|
151
129
|
this.type = type;
|
|
152
130
|
this.name = name;
|
|
@@ -162,29 +140,29 @@ var _BaseExecutor = class _BaseExecutor {
|
|
|
162
140
|
}
|
|
163
141
|
}
|
|
164
142
|
/**
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
143
|
+
*
|
|
144
|
+
* Used to filter the input of the handler
|
|
145
|
+
* @param _input
|
|
146
|
+
* @returns original input formatted for handler
|
|
147
|
+
*/
|
|
170
148
|
async getHandlerInput(_input, _metadata, _options) {
|
|
171
149
|
return ensureInputIsObject(_input);
|
|
172
150
|
}
|
|
173
151
|
/**
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
152
|
+
*
|
|
153
|
+
* Used to filter the output of the handler
|
|
154
|
+
* @param _input
|
|
155
|
+
* @returns output O
|
|
156
|
+
*/
|
|
179
157
|
getHandlerOutput(out, _metadata, _options) {
|
|
180
158
|
return out;
|
|
181
159
|
}
|
|
182
160
|
/**
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
161
|
+
*
|
|
162
|
+
* execute - Runs the executor
|
|
163
|
+
* @param _input
|
|
164
|
+
* @returns handler output
|
|
165
|
+
*/
|
|
188
166
|
async execute(_input, _options) {
|
|
189
167
|
this.executions++;
|
|
190
168
|
const _metadata = createMetadataState({
|
|
@@ -192,31 +170,28 @@ var _BaseExecutor = class _BaseExecutor {
|
|
|
192
170
|
input: _input
|
|
193
171
|
});
|
|
194
172
|
try {
|
|
195
|
-
const input = await this.getHandlerInput(
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
173
|
+
const input = await this.getHandlerInput(
|
|
174
|
+
_input,
|
|
175
|
+
_metadata.asPlainObject(),
|
|
176
|
+
_options
|
|
177
|
+
);
|
|
178
|
+
_metadata.setItem({ handlerInput: input });
|
|
199
179
|
let result = await this.handler(input, _options);
|
|
200
|
-
_metadata.setItem({
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
});
|
|
180
|
+
_metadata.setItem({ handlerOutput: result });
|
|
181
|
+
const output = this.getHandlerOutput(
|
|
182
|
+
result,
|
|
183
|
+
_metadata.asPlainObject(),
|
|
184
|
+
_options
|
|
185
|
+
);
|
|
186
|
+
_metadata.setItem({ output });
|
|
207
187
|
this.runHook("onSuccess", _metadata.asPlainObject());
|
|
208
188
|
return output;
|
|
209
189
|
} catch (error) {
|
|
210
|
-
_metadata.setItem({
|
|
211
|
-
error,
|
|
212
|
-
errorMessage: error.message
|
|
213
|
-
});
|
|
190
|
+
_metadata.setItem({ error, errorMessage: error.message });
|
|
214
191
|
this.runHook("onError", _metadata.asPlainObject());
|
|
215
192
|
throw error;
|
|
216
193
|
} finally {
|
|
217
|
-
_metadata.setItem({
|
|
218
|
-
end: (/* @__PURE__ */ new Date()).getTime()
|
|
219
|
-
});
|
|
194
|
+
_metadata.setItem({ end: (/* @__PURE__ */ new Date()).getTime() });
|
|
220
195
|
this.runHook("onComplete", _metadata.asPlainObject());
|
|
221
196
|
}
|
|
222
197
|
}
|
|
@@ -236,9 +211,7 @@ var _BaseExecutor = class _BaseExecutor {
|
|
|
236
211
|
}
|
|
237
212
|
runHook(hook, _metadata) {
|
|
238
213
|
const { [hook]: hooks = [] } = pick(this.hooks, this.allowedHooks);
|
|
239
|
-
for (const hookFn of [
|
|
240
|
-
...hooks
|
|
241
|
-
]) {
|
|
214
|
+
for (const hookFn of [...hooks]) {
|
|
242
215
|
if (typeof hookFn === "function") {
|
|
243
216
|
try {
|
|
244
217
|
hookFn(_metadata, this.getMetadata());
|
|
@@ -249,12 +222,12 @@ var _BaseExecutor = class _BaseExecutor {
|
|
|
249
222
|
}
|
|
250
223
|
setHooks(hooks = {}) {
|
|
251
224
|
const hookKeys = Object.keys(hooks);
|
|
252
|
-
for (const hookKey of hookKeys.filter(
|
|
225
|
+
for (const hookKey of hookKeys.filter(
|
|
226
|
+
(k) => this.allowedHooks.includes(k)
|
|
227
|
+
)) {
|
|
253
228
|
const hookInput = hooks[hookKey];
|
|
254
229
|
if (hookInput) {
|
|
255
|
-
const _hooks = Array.isArray(hookInput) ? hookInput : [
|
|
256
|
-
hookInput
|
|
257
|
-
];
|
|
230
|
+
const _hooks = Array.isArray(hookInput) ? hookInput : [hookInput];
|
|
258
231
|
for (const hook of _hooks) {
|
|
259
232
|
if (hook && typeof hook === "function" && !this.hooks[hookKey].find((h) => h === hook)) {
|
|
260
233
|
this.hooks[hookKey].push(hook);
|
|
@@ -277,19 +250,17 @@ var _BaseExecutor = class _BaseExecutor {
|
|
|
277
250
|
return this;
|
|
278
251
|
}
|
|
279
252
|
on(eventName, fn) {
|
|
280
|
-
return this.setHooks({
|
|
281
|
-
[eventName]: fn
|
|
282
|
-
});
|
|
253
|
+
return this.setHooks({ [eventName]: fn });
|
|
283
254
|
}
|
|
284
255
|
off(eventName, fn) {
|
|
285
256
|
return this.removeHook(eventName, fn);
|
|
286
257
|
}
|
|
287
258
|
once(eventName, fn) {
|
|
288
259
|
if (typeof fn !== "function") return this;
|
|
289
|
-
const onceWrapper =
|
|
260
|
+
const onceWrapper = (...args) => {
|
|
290
261
|
fn(...args);
|
|
291
262
|
this.off(eventName, onceWrapper);
|
|
292
|
-
}
|
|
263
|
+
};
|
|
293
264
|
this.hooks[eventName].push(onceWrapper);
|
|
294
265
|
return this;
|
|
295
266
|
}
|
|
@@ -301,26 +272,20 @@ var _BaseExecutor = class _BaseExecutor {
|
|
|
301
272
|
return this.traceId;
|
|
302
273
|
}
|
|
303
274
|
};
|
|
304
|
-
__name(_BaseExecutor, "BaseExecutor");
|
|
305
|
-
var BaseExecutor = _BaseExecutor;
|
|
306
275
|
|
|
307
276
|
// src/utils/modules/inferFunctionName.ts
|
|
308
277
|
function inferFunctionName(func, defaultName) {
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
} else {
|
|
314
|
-
return name;
|
|
315
|
-
}
|
|
278
|
+
if (typeof func !== "function") return defaultName;
|
|
279
|
+
const name = func.name;
|
|
280
|
+
if (typeof name === "string" && name.length > 0) {
|
|
281
|
+
return name.startsWith("bound ") ? name.slice(6) : name;
|
|
316
282
|
}
|
|
317
|
-
|
|
318
|
-
return
|
|
283
|
+
const match = /^function\s+([\w$]+)\s*\(/.exec(func.toString());
|
|
284
|
+
return match?.[1] ?? defaultName;
|
|
319
285
|
}
|
|
320
|
-
__name(inferFunctionName, "inferFunctionName");
|
|
321
286
|
|
|
322
287
|
// src/executor/core.ts
|
|
323
|
-
var
|
|
288
|
+
var CoreExecutor = class extends BaseExecutor {
|
|
324
289
|
constructor(fn, options) {
|
|
325
290
|
const name = fn?.name ? fn.name : inferFunctionName(fn.handler, "anonymous-core-executor");
|
|
326
291
|
super(name, "function-executor", options);
|
|
@@ -331,16 +296,14 @@ var _CoreExecutor = class _CoreExecutor extends BaseExecutor {
|
|
|
331
296
|
return this._handler.call(null, _input);
|
|
332
297
|
}
|
|
333
298
|
};
|
|
334
|
-
__name(_CoreExecutor, "CoreExecutor");
|
|
335
|
-
var CoreExecutor = _CoreExecutor;
|
|
336
299
|
|
|
337
300
|
// src/parser/_base.ts
|
|
338
|
-
var
|
|
301
|
+
var BaseParser = class {
|
|
339
302
|
/**
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
303
|
+
* Create a new BaseParser.
|
|
304
|
+
* @param name - The name of the parser.
|
|
305
|
+
* @param options - options
|
|
306
|
+
*/
|
|
344
307
|
constructor(name, options = {}, target = "text") {
|
|
345
308
|
__publicField(this, "name");
|
|
346
309
|
__publicField(this, "options");
|
|
@@ -352,14 +315,12 @@ var _BaseParser = class _BaseParser {
|
|
|
352
315
|
}
|
|
353
316
|
}
|
|
354
317
|
};
|
|
355
|
-
|
|
356
|
-
var BaseParser = _BaseParser;
|
|
357
|
-
var _BaseParserWithJson = class _BaseParserWithJson extends BaseParser {
|
|
318
|
+
var BaseParserWithJson = class extends BaseParser {
|
|
358
319
|
/**
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
320
|
+
* Create a new BaseParser.
|
|
321
|
+
* @param name - The name of the parser.
|
|
322
|
+
* @param options - options
|
|
323
|
+
*/
|
|
363
324
|
constructor(name, options) {
|
|
364
325
|
super(name);
|
|
365
326
|
__publicField(this, "schema");
|
|
@@ -371,8 +332,6 @@ var _BaseParserWithJson = class _BaseParserWithJson extends BaseParser {
|
|
|
371
332
|
}
|
|
372
333
|
}
|
|
373
334
|
};
|
|
374
|
-
__name(_BaseParserWithJson, "BaseParserWithJson");
|
|
375
|
-
var BaseParserWithJson = _BaseParserWithJson;
|
|
376
335
|
|
|
377
336
|
// src/utils/index.ts
|
|
378
337
|
var utils_exports = {};
|
|
@@ -405,7 +364,6 @@ function assert(condition, message) {
|
|
|
405
364
|
}
|
|
406
365
|
}
|
|
407
366
|
}
|
|
408
|
-
__name(assert, "assert");
|
|
409
367
|
|
|
410
368
|
// src/utils/modules/defineSchema.ts
|
|
411
369
|
import { asConst } from "json-schema-to-ts";
|
|
@@ -413,13 +371,14 @@ function defineSchema(obj) {
|
|
|
413
371
|
obj.additionalProperties = false;
|
|
414
372
|
return asConst(obj);
|
|
415
373
|
}
|
|
416
|
-
__name(defineSchema, "defineSchema");
|
|
417
374
|
|
|
418
375
|
// src/utils/modules/handlebars/utils/importPartials.ts
|
|
419
376
|
function importPartials(_partials) {
|
|
420
377
|
let partials2 = [];
|
|
421
378
|
if (_partials) {
|
|
422
|
-
const externalPartialKeys = Object.keys(
|
|
379
|
+
const externalPartialKeys = Object.keys(
|
|
380
|
+
_partials
|
|
381
|
+
);
|
|
423
382
|
for (const externalPartialKey of externalPartialKeys) {
|
|
424
383
|
if (typeof externalPartialKey === "string") {
|
|
425
384
|
partials2.push({
|
|
@@ -431,13 +390,14 @@ function importPartials(_partials) {
|
|
|
431
390
|
}
|
|
432
391
|
return partials2;
|
|
433
392
|
}
|
|
434
|
-
__name(importPartials, "importPartials");
|
|
435
393
|
|
|
436
394
|
// src/utils/modules/handlebars/utils/importHelpers.ts
|
|
437
395
|
function importHelpers(_helpers) {
|
|
438
396
|
let helpers = [];
|
|
439
397
|
if (_helpers) {
|
|
440
|
-
const externalHelperKeys = Object.keys(
|
|
398
|
+
const externalHelperKeys = Object.keys(
|
|
399
|
+
_helpers
|
|
400
|
+
);
|
|
441
401
|
for (const externalHelperKey of externalHelperKeys) {
|
|
442
402
|
if (typeof externalHelperKey === "string") {
|
|
443
403
|
helpers.push({
|
|
@@ -449,7 +409,6 @@ function importHelpers(_helpers) {
|
|
|
449
409
|
}
|
|
450
410
|
return helpers;
|
|
451
411
|
}
|
|
452
|
-
__name(importHelpers, "importHelpers");
|
|
453
412
|
|
|
454
413
|
// src/utils/modules/toNumber.ts
|
|
455
414
|
function toNumber(value) {
|
|
@@ -461,7 +420,6 @@ function toNumber(value) {
|
|
|
461
420
|
}
|
|
462
421
|
return NaN;
|
|
463
422
|
}
|
|
464
|
-
__name(toNumber, "toNumber");
|
|
465
423
|
|
|
466
424
|
// src/utils/modules/get.ts
|
|
467
425
|
function get(obj, path, defaultValue) {
|
|
@@ -469,17 +427,18 @@ function get(obj, path, defaultValue) {
|
|
|
469
427
|
return defaultValue;
|
|
470
428
|
}
|
|
471
429
|
const pathString = Array.isArray(path) ? path.join(".") : path;
|
|
472
|
-
const travel =
|
|
430
|
+
const travel = (regexp) => pathString.split(regexp).filter(Boolean).reduce(
|
|
431
|
+
(res, key) => res !== null && res !== void 0 ? res[key] : res,
|
|
432
|
+
obj
|
|
433
|
+
);
|
|
473
434
|
const result = travel(/[,[\]]+?/) || travel(/[,[\].]+?/);
|
|
474
435
|
return result === void 0 || result === obj ? defaultValue : result === null ? defaultValue : result;
|
|
475
436
|
}
|
|
476
|
-
__name(get, "get");
|
|
477
437
|
|
|
478
438
|
// src/utils/modules/filterObjectOnSchema.ts
|
|
479
439
|
function isObject(obj) {
|
|
480
440
|
return obj === Object(obj);
|
|
481
441
|
}
|
|
482
|
-
__name(isObject, "isObject");
|
|
483
442
|
function getType(schemaType) {
|
|
484
443
|
if (!Array.isArray(schemaType)) {
|
|
485
444
|
return schemaType;
|
|
@@ -492,7 +451,6 @@ function getType(schemaType) {
|
|
|
492
451
|
}
|
|
493
452
|
}
|
|
494
453
|
}
|
|
495
|
-
__name(getType, "getType");
|
|
496
454
|
function filterObjectOnSchema(schema, doc, detach, property) {
|
|
497
455
|
let result;
|
|
498
456
|
if (doc === null || doc === void 0) {
|
|
@@ -537,25 +495,10 @@ function filterObjectOnSchema(schema, doc, detach, property) {
|
|
|
537
495
|
}
|
|
538
496
|
return result;
|
|
539
497
|
}
|
|
540
|
-
__name(filterObjectOnSchema, "filterObjectOnSchema");
|
|
541
498
|
|
|
542
499
|
// src/utils/modules/handlebars/hbs.ts
|
|
543
500
|
import Handlebars from "handlebars";
|
|
544
501
|
|
|
545
|
-
// src/utils/modules/handlebars/utils/registerPartials.ts
|
|
546
|
-
function _registerPartials(partials2, instance) {
|
|
547
|
-
if (partials2 && Array.isArray(partials2)) {
|
|
548
|
-
for (const partial of partials2) {
|
|
549
|
-
if (partial.name && typeof partial.name === "string" && typeof partial.template === "string") {
|
|
550
|
-
if (instance) {
|
|
551
|
-
instance.registerPartial(partial.name, partial.template);
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
__name(_registerPartials, "_registerPartials");
|
|
558
|
-
|
|
559
502
|
// src/utils/modules/handlebars/utils/registerHelpers.ts
|
|
560
503
|
function _registerHelpers(helpers, instance) {
|
|
561
504
|
if (helpers && Array.isArray(helpers)) {
|
|
@@ -568,17 +511,6 @@ function _registerHelpers(helpers, instance) {
|
|
|
568
511
|
}
|
|
569
512
|
}
|
|
570
513
|
}
|
|
571
|
-
__name(_registerHelpers, "_registerHelpers");
|
|
572
|
-
|
|
573
|
-
// src/utils/modules/getEnvironmentVariable.ts
|
|
574
|
-
function getEnvironmentVariable(name) {
|
|
575
|
-
if (typeof process === "object" && process?.env) {
|
|
576
|
-
return process.env[name];
|
|
577
|
-
} else {
|
|
578
|
-
return void 0;
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
__name(getEnvironmentVariable, "getEnvironmentVariable");
|
|
582
514
|
|
|
583
515
|
// src/utils/modules/handlebars/templates/index.ts
|
|
584
516
|
var MarkdownCode = `{{#if code}}\`\`\`{{#if language}}{{language}}{{/if}}
|
|
@@ -652,7 +584,7 @@ __export(helpers_exports, {
|
|
|
652
584
|
});
|
|
653
585
|
|
|
654
586
|
// src/utils/modules/json.ts
|
|
655
|
-
var maybeStringifyJSON =
|
|
587
|
+
var maybeStringifyJSON = (objOrMaybeString) => {
|
|
656
588
|
if (!objOrMaybeString || typeof objOrMaybeString !== "object") {
|
|
657
589
|
return objOrMaybeString;
|
|
658
590
|
}
|
|
@@ -662,8 +594,8 @@ var maybeStringifyJSON = /* @__PURE__ */ __name((objOrMaybeString) => {
|
|
|
662
594
|
} catch (error) {
|
|
663
595
|
}
|
|
664
596
|
return "";
|
|
665
|
-
}
|
|
666
|
-
var maybeParseJSON =
|
|
597
|
+
};
|
|
598
|
+
var maybeParseJSON = (objOrMaybeJSON) => {
|
|
667
599
|
if (!objOrMaybeJSON) return {};
|
|
668
600
|
if (typeof objOrMaybeJSON === "string") {
|
|
669
601
|
try {
|
|
@@ -679,24 +611,19 @@ var maybeParseJSON = /* @__PURE__ */ __name((objOrMaybeJSON) => {
|
|
|
679
611
|
return objOrMaybeJSON;
|
|
680
612
|
}
|
|
681
613
|
return {};
|
|
682
|
-
}
|
|
614
|
+
};
|
|
683
615
|
function isObjectStringified(maybeObject) {
|
|
684
616
|
if (typeof maybeObject !== "string") return false;
|
|
685
|
-
const
|
|
686
|
-
const
|
|
687
|
-
if (!
|
|
688
|
-
return false;
|
|
689
|
-
}
|
|
690
|
-
let canDecode = false;
|
|
617
|
+
const trimmed = maybeObject.trim();
|
|
618
|
+
const isWrapped = trimmed.startsWith("{") && trimmed.endsWith("}") || trimmed.startsWith("[") && trimmed.endsWith("]");
|
|
619
|
+
if (!isWrapped) return false;
|
|
691
620
|
try {
|
|
692
|
-
JSON.parse(
|
|
693
|
-
|
|
694
|
-
} catch
|
|
695
|
-
|
|
621
|
+
const parsed = JSON.parse(trimmed);
|
|
622
|
+
return typeof parsed === "object" && parsed !== null;
|
|
623
|
+
} catch {
|
|
624
|
+
return false;
|
|
696
625
|
}
|
|
697
|
-
return canDecode;
|
|
698
626
|
}
|
|
699
|
-
__name(isObjectStringified, "isObjectStringified");
|
|
700
627
|
function helpJsonMarkup(str) {
|
|
701
628
|
if (typeof str !== "string") {
|
|
702
629
|
return str;
|
|
@@ -704,12 +631,17 @@ function helpJsonMarkup(str) {
|
|
|
704
631
|
const input = str.trim();
|
|
705
632
|
const markdownJsonStartsWith = "```json";
|
|
706
633
|
const markdownJsonEndsWith = "```";
|
|
707
|
-
if (input.substring(0, markdownJsonStartsWith.length) === markdownJsonStartsWith && input.substring(
|
|
708
|
-
|
|
634
|
+
if (input.substring(0, markdownJsonStartsWith.length) === markdownJsonStartsWith && input.substring(
|
|
635
|
+
input.length - markdownJsonEndsWith.length,
|
|
636
|
+
input.length
|
|
637
|
+
) === markdownJsonEndsWith) {
|
|
638
|
+
return str.substring(
|
|
639
|
+
markdownJsonStartsWith.length,
|
|
640
|
+
input.length - markdownJsonEndsWith.length
|
|
641
|
+
)?.trim();
|
|
709
642
|
}
|
|
710
643
|
return str;
|
|
711
644
|
}
|
|
712
|
-
__name(helpJsonMarkup, "helpJsonMarkup");
|
|
713
645
|
|
|
714
646
|
// src/utils/modules/replaceTemplateStringSimple.ts
|
|
715
647
|
function replaceTemplateStringSimple(template, context) {
|
|
@@ -726,31 +658,28 @@ function replaceTemplateStringSimple(template, context) {
|
|
|
726
658
|
return typeof value === "string" ? value : String(value);
|
|
727
659
|
});
|
|
728
660
|
}
|
|
729
|
-
__name(replaceTemplateStringSimple, "replaceTemplateStringSimple");
|
|
730
661
|
|
|
731
662
|
// src/utils/modules/handlebars/helpers/indentJson.ts
|
|
732
663
|
function indentJson(arg1, collapse = "false") {
|
|
733
664
|
if (typeof arg1 !== "object") {
|
|
734
665
|
return replaceTemplateStringSimple(arg1 || "", this);
|
|
735
666
|
}
|
|
736
|
-
const replaced = maybeParseJSON(
|
|
667
|
+
const replaced = maybeParseJSON(
|
|
668
|
+
replaceTemplateStringSimple(maybeStringifyJSON(arg1), this)
|
|
669
|
+
);
|
|
737
670
|
if (collapse == "true") {
|
|
738
671
|
return JSON.stringify(replaced);
|
|
739
672
|
}
|
|
740
673
|
return JSON.stringify(replaced, null, 2);
|
|
741
674
|
}
|
|
742
|
-
__name(indentJson, "indentJson");
|
|
743
675
|
|
|
744
676
|
// src/utils/modules/schemaExampleWith.ts
|
|
745
677
|
function schemaExampleWith(schema, property) {
|
|
746
678
|
if (schema.type === "array") {
|
|
747
|
-
return filterObjectOnSchema(schema, [
|
|
748
|
-
{}
|
|
749
|
-
], void 0, property);
|
|
679
|
+
return filterObjectOnSchema(schema, [{}], void 0, property);
|
|
750
680
|
}
|
|
751
681
|
return filterObjectOnSchema(schema, {}, void 0, property);
|
|
752
682
|
}
|
|
753
|
-
__name(schemaExampleWith, "schemaExampleWith");
|
|
754
683
|
|
|
755
684
|
// src/utils/modules/handlebars/helpers/jsonSchemaExample.ts
|
|
756
685
|
function jsonSchemaExample(key, prop, collapse) {
|
|
@@ -760,7 +689,9 @@ function jsonSchemaExample(key, prop, collapse) {
|
|
|
760
689
|
if (typeof result !== "object") {
|
|
761
690
|
return "";
|
|
762
691
|
}
|
|
763
|
-
const replaced = maybeParseJSON(
|
|
692
|
+
const replaced = maybeParseJSON(
|
|
693
|
+
replaceTemplateStringSimple(maybeStringifyJSON(result), this)
|
|
694
|
+
);
|
|
764
695
|
if (collapse == "true") {
|
|
765
696
|
return JSON.stringify(replaced);
|
|
766
697
|
}
|
|
@@ -768,41 +699,35 @@ function jsonSchemaExample(key, prop, collapse) {
|
|
|
768
699
|
}
|
|
769
700
|
return "";
|
|
770
701
|
}
|
|
771
|
-
__name(jsonSchemaExample, "jsonSchemaExample");
|
|
772
702
|
|
|
773
703
|
// src/utils/modules/handlebars/helpers/getKeyOr.ts
|
|
774
704
|
function getKeyOr(key, arg2) {
|
|
775
705
|
const res = get(this, key);
|
|
776
706
|
return typeof res !== "undefined" && res !== "" ? res : arg2;
|
|
777
707
|
}
|
|
778
|
-
__name(getKeyOr, "getKeyOr");
|
|
779
708
|
|
|
780
709
|
// src/utils/modules/handlebars/helpers/getOr.ts
|
|
781
710
|
function getOr(arg1, arg2) {
|
|
782
711
|
return typeof arg1 !== "undefined" && arg1 !== "" ? arg1 : arg2;
|
|
783
712
|
}
|
|
784
|
-
__name(getOr, "getOr");
|
|
785
713
|
|
|
786
714
|
// src/utils/modules/handlebars/helpers/pluralize.ts
|
|
787
715
|
function pluralize(arg1, arg2) {
|
|
788
716
|
const [singular, plural] = arg1.split("|");
|
|
789
717
|
return arg2 > 1 ? plural : singular;
|
|
790
718
|
}
|
|
791
|
-
__name(pluralize, "pluralize");
|
|
792
719
|
|
|
793
720
|
// src/utils/modules/handlebars/helpers/eq.ts
|
|
794
721
|
function eq(arg1 = "", arg2 = "", options) {
|
|
795
722
|
const isArr = arg2.toString().split(",").map((a) => a.trim());
|
|
796
723
|
return isArr.includes(arg1) ? options.fn(this) : options.inverse(this);
|
|
797
724
|
}
|
|
798
|
-
__name(eq, "eq");
|
|
799
725
|
|
|
800
726
|
// src/utils/modules/handlebars/helpers/neq.ts
|
|
801
727
|
function neq(arg1 = "", arg2 = "", options) {
|
|
802
728
|
const isArr = arg2.toString().split(",").map((a) => a.trim());
|
|
803
729
|
return !isArr.includes(arg1) ? options.fn(this) : options.inverse(this);
|
|
804
730
|
}
|
|
805
|
-
__name(neq, "neq");
|
|
806
731
|
|
|
807
732
|
// src/utils/modules/handlebars/helpers/ifCond.ts
|
|
808
733
|
function ifCond(v1, operator, v2, options) {
|
|
@@ -831,13 +756,11 @@ function ifCond(v1, operator, v2, options) {
|
|
|
831
756
|
return options.inverse(this);
|
|
832
757
|
}
|
|
833
758
|
}
|
|
834
|
-
__name(ifCond, "ifCond");
|
|
835
759
|
|
|
836
760
|
// src/utils/modules/handlebars/helpers/objectToList.ts
|
|
837
761
|
function objectToList(arg = {}) {
|
|
838
762
|
return Object.keys(arg).map((key) => `- ${key}: ${arg[key]}`).join("\n");
|
|
839
763
|
}
|
|
840
|
-
__name(objectToList, "objectToList");
|
|
841
764
|
|
|
842
765
|
// src/utils/modules/handlebars/helpers/join.ts
|
|
843
766
|
function join(array) {
|
|
@@ -845,13 +768,11 @@ function join(array) {
|
|
|
845
768
|
if (!Array.isArray(array)) return "";
|
|
846
769
|
return array.join(", ");
|
|
847
770
|
}
|
|
848
|
-
__name(join, "join");
|
|
849
771
|
|
|
850
772
|
// src/utils/modules/handlebars/helpers/cut.ts
|
|
851
773
|
function cutFn(str, arg) {
|
|
852
774
|
return str.toString().replace(new RegExp(arg, "g"), "");
|
|
853
775
|
}
|
|
854
|
-
__name(cutFn, "cutFn");
|
|
855
776
|
|
|
856
777
|
// src/utils/modules/handlebars/helpers/substring.ts
|
|
857
778
|
function substringFn(str, start, end) {
|
|
@@ -864,47 +785,42 @@ function substringFn(str, start, end) {
|
|
|
864
785
|
return str;
|
|
865
786
|
}
|
|
866
787
|
}
|
|
867
|
-
__name(substringFn, "substringFn");
|
|
868
788
|
|
|
869
789
|
// src/utils/modules/handlebars/helpers/with.ts
|
|
870
790
|
function withFn(options, context) {
|
|
871
791
|
return options.fn(context);
|
|
872
792
|
}
|
|
873
|
-
__name(withFn, "withFn");
|
|
874
793
|
|
|
875
794
|
// src/utils/modules/handlebars/utils/makeHandlebarsInstance.ts
|
|
876
795
|
function makeHandlebarsInstance(hbs2) {
|
|
877
796
|
const handlebars = hbs2.create();
|
|
878
797
|
const helperKeys = Object.keys(helpers_exports);
|
|
879
|
-
_registerHelpers(
|
|
880
|
-
handler: helpers_exports[a],
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
handlebars.registerHelper(
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
798
|
+
_registerHelpers(
|
|
799
|
+
helperKeys.map((a) => ({ handler: helpers_exports[a], name: a })),
|
|
800
|
+
handlebars
|
|
801
|
+
);
|
|
802
|
+
handlebars.registerHelper(
|
|
803
|
+
"hbsInTemplate",
|
|
804
|
+
function(str, substitutions) {
|
|
805
|
+
const template = handlebars.compile(str);
|
|
806
|
+
return template(substitutions, {
|
|
807
|
+
allowedProtoMethods: {
|
|
808
|
+
substring: true
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
}
|
|
812
|
+
);
|
|
813
|
+
const contextPartialKeys = Object.keys(
|
|
814
|
+
partials
|
|
815
|
+
);
|
|
897
816
|
for (const contextPartialKey of contextPartialKeys) {
|
|
898
|
-
handlebars.registerPartial(
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
const externalPartials = __require(partialsPath);
|
|
903
|
-
_registerPartials(importPartials(externalPartials), handlebars);
|
|
817
|
+
handlebars.registerPartial(
|
|
818
|
+
contextPartialKey,
|
|
819
|
+
partials[contextPartialKey]
|
|
820
|
+
);
|
|
904
821
|
}
|
|
905
822
|
return handlebars;
|
|
906
823
|
}
|
|
907
|
-
__name(makeHandlebarsInstance, "makeHandlebarsInstance");
|
|
908
824
|
|
|
909
825
|
// src/utils/modules/isPromise.ts
|
|
910
826
|
function isPromise(value) {
|
|
@@ -913,24 +829,16 @@ function isPromise(value) {
|
|
|
913
829
|
}
|
|
914
830
|
return Object.prototype.toString.call(value) === "[object AsyncFunction]";
|
|
915
831
|
}
|
|
916
|
-
__name(isPromise, "isPromise");
|
|
917
832
|
|
|
918
833
|
// src/utils/modules/handlebars/utils/appendContextPath.ts
|
|
919
834
|
function appendContextPath(contextPath, id) {
|
|
920
835
|
return (contextPath ? `${contextPath}.` : "") + id;
|
|
921
836
|
}
|
|
922
|
-
__name(appendContextPath, "appendContextPath");
|
|
923
837
|
|
|
924
838
|
// src/utils/modules/handlebars/utils/blockParams.ts
|
|
925
839
|
function blockParams(params, ids) {
|
|
926
|
-
return {
|
|
927
|
-
...params,
|
|
928
|
-
...{
|
|
929
|
-
path: ids
|
|
930
|
-
}
|
|
931
|
-
};
|
|
840
|
+
return { ...params, ...{ path: ids } };
|
|
932
841
|
}
|
|
933
|
-
__name(blockParams, "blockParams");
|
|
934
842
|
|
|
935
843
|
// src/utils/modules/extend.ts
|
|
936
844
|
function extend(obj, _source) {
|
|
@@ -943,7 +851,6 @@ function extend(obj, _source) {
|
|
|
943
851
|
}
|
|
944
852
|
return obj;
|
|
945
853
|
}
|
|
946
|
-
__name(extend, "extend");
|
|
947
854
|
|
|
948
855
|
// src/utils/modules/handlebars/utils/createFrame.ts
|
|
949
856
|
function createFrame(object) {
|
|
@@ -951,7 +858,6 @@ function createFrame(object) {
|
|
|
951
858
|
frame._parent = object;
|
|
952
859
|
return frame;
|
|
953
860
|
}
|
|
954
|
-
__name(createFrame, "createFrame");
|
|
955
861
|
|
|
956
862
|
// src/utils/modules/isEmpty.ts
|
|
957
863
|
function isEmpty(value) {
|
|
@@ -963,7 +869,6 @@ function isEmpty(value) {
|
|
|
963
869
|
}
|
|
964
870
|
return false;
|
|
965
871
|
}
|
|
966
|
-
__name(isEmpty, "isEmpty");
|
|
967
872
|
|
|
968
873
|
// src/utils/modules/handlebars/helpers/async/with.ts
|
|
969
874
|
async function withFnAsync(context, options) {
|
|
@@ -980,20 +885,18 @@ async function withFnAsync(context, options) {
|
|
|
980
885
|
let { data } = options;
|
|
981
886
|
if (options.data && options.ids) {
|
|
982
887
|
data = createFrame(options.data);
|
|
983
|
-
data.contextPath = appendContextPath(
|
|
888
|
+
data.contextPath = appendContextPath(
|
|
889
|
+
options.data.contextPath,
|
|
890
|
+
options.ids[0]
|
|
891
|
+
);
|
|
984
892
|
}
|
|
985
893
|
return fn(context, {
|
|
986
894
|
data,
|
|
987
|
-
blockParams: blockParams([
|
|
988
|
-
context
|
|
989
|
-
], [
|
|
990
|
-
data && data.contextPath
|
|
991
|
-
])
|
|
895
|
+
blockParams: blockParams([context], [data && data.contextPath])
|
|
992
896
|
});
|
|
993
897
|
}
|
|
994
898
|
return options.inverse(this);
|
|
995
899
|
}
|
|
996
|
-
__name(withFnAsync, "withFnAsync");
|
|
997
900
|
|
|
998
901
|
// src/utils/modules/handlebars/helpers/async/if.ts
|
|
999
902
|
async function ifFnAsync(conditional, options) {
|
|
@@ -1011,13 +914,11 @@ async function ifFnAsync(conditional, options) {
|
|
|
1011
914
|
return options.fn(this);
|
|
1012
915
|
}
|
|
1013
916
|
}
|
|
1014
|
-
__name(ifFnAsync, "ifFnAsync");
|
|
1015
917
|
|
|
1016
918
|
// src/utils/modules/isReadableStream.ts
|
|
1017
919
|
function isReadableStream(obj) {
|
|
1018
920
|
return obj && typeof obj === "object" && typeof obj.pipe === "function" && typeof obj._read === "function";
|
|
1019
921
|
}
|
|
1020
|
-
__name(isReadableStream, "isReadableStream");
|
|
1021
922
|
|
|
1022
923
|
// src/utils/modules/handlebars/helpers/async/each.ts
|
|
1023
924
|
async function eachFnAsync(arg1, options) {
|
|
@@ -1031,7 +932,10 @@ async function eachFnAsync(arg1, options) {
|
|
|
1031
932
|
let ret = [];
|
|
1032
933
|
let contextPath = "";
|
|
1033
934
|
if (options.data && options.ids) {
|
|
1034
|
-
contextPath = `${appendContextPath(
|
|
935
|
+
contextPath = `${appendContextPath(
|
|
936
|
+
options.data.contextPath,
|
|
937
|
+
options.ids[0]
|
|
938
|
+
)}.`;
|
|
1035
939
|
}
|
|
1036
940
|
if (typeof arg1 === "function") {
|
|
1037
941
|
arg1 = arg1.call(this);
|
|
@@ -1049,18 +953,16 @@ async function eachFnAsync(arg1, options) {
|
|
|
1049
953
|
data.contextPath = contextPath + field;
|
|
1050
954
|
}
|
|
1051
955
|
}
|
|
1052
|
-
ret.push(
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
}));
|
|
956
|
+
ret.push(
|
|
957
|
+
await fn(arg1[field], {
|
|
958
|
+
data,
|
|
959
|
+
blockParams: blockParams(
|
|
960
|
+
[arg1[field], field],
|
|
961
|
+
[contextPath + field, null]
|
|
962
|
+
)
|
|
963
|
+
})
|
|
964
|
+
);
|
|
1062
965
|
}
|
|
1063
|
-
__name(execIteration, "execIteration");
|
|
1064
966
|
if (isPromise(arg1)) {
|
|
1065
967
|
arg1 = await arg1;
|
|
1066
968
|
}
|
|
@@ -1109,13 +1011,10 @@ async function eachFnAsync(arg1, options) {
|
|
|
1109
1011
|
}
|
|
1110
1012
|
if (i === 0) {
|
|
1111
1013
|
ret = inverse(this);
|
|
1112
|
-
ret = [
|
|
1113
|
-
inverse(this)
|
|
1114
|
-
];
|
|
1014
|
+
ret = [inverse(this)];
|
|
1115
1015
|
}
|
|
1116
1016
|
return ret.join("");
|
|
1117
1017
|
}
|
|
1118
|
-
__name(eachFnAsync, "eachFnAsync");
|
|
1119
1018
|
|
|
1120
1019
|
// src/utils/modules/handlebars/helpers/async/unless.ts
|
|
1121
1020
|
async function unlessFnAsync(conditional, options) {
|
|
@@ -1128,7 +1027,6 @@ async function unlessFnAsync(conditional, options) {
|
|
|
1128
1027
|
hash: options.hash
|
|
1129
1028
|
});
|
|
1130
1029
|
}
|
|
1131
|
-
__name(unlessFnAsync, "unlessFnAsync");
|
|
1132
1030
|
|
|
1133
1031
|
// src/utils/modules/handlebars/helpers/async/async-helpers.ts
|
|
1134
1032
|
var asyncCoreOverrideHelpers = {
|
|
@@ -1140,9 +1038,8 @@ var asyncCoreOverrideHelpers = {
|
|
|
1140
1038
|
|
|
1141
1039
|
// src/utils/modules/handlebars/utils/makeHandlebarsInstanceAsync.ts
|
|
1142
1040
|
function makeHandlebarsInstanceAsync(hbs2) {
|
|
1143
|
-
var _a;
|
|
1144
1041
|
const handlebars = hbs2.create();
|
|
1145
|
-
const asyncCompiler =
|
|
1042
|
+
const asyncCompiler = class extends hbs2.JavaScriptCompiler {
|
|
1146
1043
|
constructor() {
|
|
1147
1044
|
super();
|
|
1148
1045
|
this.compiler = asyncCompiler;
|
|
@@ -1155,30 +1052,20 @@ function makeHandlebarsInstanceAsync(hbs2) {
|
|
|
1155
1052
|
}
|
|
1156
1053
|
appendToBuffer(source, location, explicit) {
|
|
1157
1054
|
if (!Array.isArray(source)) {
|
|
1158
|
-
source = [
|
|
1159
|
-
source
|
|
1160
|
-
];
|
|
1055
|
+
source = [source];
|
|
1161
1056
|
}
|
|
1162
1057
|
source = this.source.wrap(source, location);
|
|
1163
1058
|
if (this.environment.isSimple) {
|
|
1164
|
-
return [
|
|
1165
|
-
"return await ",
|
|
1166
|
-
source,
|
|
1167
|
-
";"
|
|
1168
|
-
];
|
|
1059
|
+
return ["return await ", source, ";"];
|
|
1169
1060
|
}
|
|
1170
1061
|
if (explicit) {
|
|
1171
|
-
return [
|
|
1172
|
-
"buffer += await ",
|
|
1173
|
-
source,
|
|
1174
|
-
";"
|
|
1175
|
-
];
|
|
1062
|
+
return ["buffer += await ", source, ";"];
|
|
1176
1063
|
}
|
|
1177
1064
|
source.appendToBuffer = true;
|
|
1178
1065
|
source.prepend("await ");
|
|
1179
1066
|
return source;
|
|
1180
1067
|
}
|
|
1181
|
-
}
|
|
1068
|
+
};
|
|
1182
1069
|
handlebars.JavaScriptCompiler = asyncCompiler;
|
|
1183
1070
|
const _compile = handlebars.compile;
|
|
1184
1071
|
const _template = handlebars.VM.template;
|
|
@@ -1189,90 +1076,110 @@ function makeHandlebarsInstanceAsync(hbs2) {
|
|
|
1189
1076
|
}
|
|
1190
1077
|
return _escapeExpression(value);
|
|
1191
1078
|
}
|
|
1192
|
-
__name(escapeExpression, "escapeExpression");
|
|
1193
1079
|
function lookupProperty(containerLookupProperty) {
|
|
1194
1080
|
return function(parent, propertyName) {
|
|
1195
1081
|
if (isPromise(parent)) {
|
|
1196
1082
|
if (typeof parent?.then === "function") {
|
|
1197
|
-
return parent.then(
|
|
1083
|
+
return parent.then(
|
|
1084
|
+
(p) => containerLookupProperty(p, propertyName)
|
|
1085
|
+
);
|
|
1198
1086
|
}
|
|
1199
|
-
return parent().then(
|
|
1087
|
+
return parent().then(
|
|
1088
|
+
(p) => containerLookupProperty(p, propertyName)
|
|
1089
|
+
);
|
|
1200
1090
|
}
|
|
1201
1091
|
return containerLookupProperty(parent, propertyName);
|
|
1202
1092
|
};
|
|
1203
1093
|
}
|
|
1204
|
-
__name(lookupProperty, "lookupProperty");
|
|
1205
1094
|
handlebars.template = function(spec) {
|
|
1206
1095
|
spec.main_d = (_prog, _props, container, _depth, data, blockParams2, depths) => async (context) => {
|
|
1207
1096
|
container.escapeExpression = escapeExpression;
|
|
1208
1097
|
container.lookupProperty = lookupProperty(container.lookupProperty);
|
|
1209
1098
|
if (depths.length == 0) {
|
|
1210
|
-
depths = [
|
|
1211
|
-
data.root
|
|
1212
|
-
];
|
|
1099
|
+
depths = [data.root];
|
|
1213
1100
|
}
|
|
1214
|
-
const v = spec.main(
|
|
1101
|
+
const v = spec.main(
|
|
1102
|
+
container,
|
|
1103
|
+
context,
|
|
1104
|
+
container.helpers,
|
|
1105
|
+
container.partials,
|
|
1106
|
+
data,
|
|
1107
|
+
blockParams2,
|
|
1108
|
+
depths
|
|
1109
|
+
);
|
|
1215
1110
|
return v;
|
|
1216
1111
|
};
|
|
1217
1112
|
return _template(spec, handlebars);
|
|
1218
1113
|
};
|
|
1219
1114
|
handlebars.compile = function(template, options) {
|
|
1220
|
-
const compiled = _compile.apply(handlebars, [
|
|
1221
|
-
template,
|
|
1222
|
-
{
|
|
1223
|
-
...options
|
|
1224
|
-
}
|
|
1225
|
-
]);
|
|
1115
|
+
const compiled = _compile.apply(handlebars, [template, { ...options }]);
|
|
1226
1116
|
return function(context, execOptions) {
|
|
1227
1117
|
context = context || {};
|
|
1228
1118
|
return compiled.call(handlebars, context, execOptions);
|
|
1229
1119
|
};
|
|
1230
1120
|
};
|
|
1231
1121
|
const helperKeys = Object.keys(helpers_exports);
|
|
1232
|
-
_registerHelpers(
|
|
1233
|
-
handler: helpers_exports[a],
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
const asyncHelperKeys = Object.keys(
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1122
|
+
_registerHelpers(
|
|
1123
|
+
helperKeys.map((a) => ({ handler: helpers_exports[a], name: a })),
|
|
1124
|
+
handlebars
|
|
1125
|
+
);
|
|
1126
|
+
const asyncHelperKeys = Object.keys(
|
|
1127
|
+
asyncCoreOverrideHelpers
|
|
1128
|
+
);
|
|
1129
|
+
_registerHelpers(
|
|
1130
|
+
asyncHelperKeys.map((a) => ({
|
|
1131
|
+
handler: asyncCoreOverrideHelpers[a],
|
|
1132
|
+
name: a
|
|
1133
|
+
})),
|
|
1134
|
+
handlebars
|
|
1135
|
+
);
|
|
1136
|
+
const contextPartialKeys = Object.keys(
|
|
1137
|
+
partials
|
|
1138
|
+
);
|
|
1242
1139
|
for (const contextPartialKey of contextPartialKeys) {
|
|
1243
|
-
handlebars.registerPartial(
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
const externalPartials = __require(partialsPath);
|
|
1248
|
-
_registerPartials(importPartials(externalPartials), handlebars);
|
|
1140
|
+
handlebars.registerPartial(
|
|
1141
|
+
contextPartialKey,
|
|
1142
|
+
partials[contextPartialKey]
|
|
1143
|
+
);
|
|
1249
1144
|
}
|
|
1250
1145
|
return handlebars;
|
|
1251
1146
|
}
|
|
1252
|
-
__name(makeHandlebarsInstanceAsync, "makeHandlebarsInstanceAsync");
|
|
1253
1147
|
|
|
1254
1148
|
// src/utils/modules/handlebars/hbs.ts
|
|
1255
1149
|
var _hbsAsync = makeHandlebarsInstanceAsync(Handlebars);
|
|
1256
1150
|
var _hbs = makeHandlebarsInstance(Handlebars);
|
|
1257
1151
|
|
|
1152
|
+
// src/utils/modules/handlebars/utils/registerPartials.ts
|
|
1153
|
+
function _registerPartials(partials2, instance) {
|
|
1154
|
+
if (partials2 && Array.isArray(partials2)) {
|
|
1155
|
+
for (const partial of partials2) {
|
|
1156
|
+
if (partial.name && typeof partial.name === "string" && typeof partial.template === "string") {
|
|
1157
|
+
if (instance) {
|
|
1158
|
+
instance.registerPartial(partial.name, partial.template);
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1258
1165
|
// src/utils/modules/handlebars/index.ts
|
|
1259
1166
|
var hbs = {
|
|
1260
1167
|
handlebars: _hbs,
|
|
1261
|
-
registerHelpers:
|
|
1168
|
+
registerHelpers: (helpers) => {
|
|
1262
1169
|
_registerHelpers(helpers, _hbs);
|
|
1263
|
-
},
|
|
1264
|
-
registerPartials:
|
|
1170
|
+
},
|
|
1171
|
+
registerPartials: (partials2) => {
|
|
1265
1172
|
_registerPartials(partials2, _hbs);
|
|
1266
|
-
}
|
|
1173
|
+
}
|
|
1267
1174
|
};
|
|
1268
1175
|
var hbsAsync = {
|
|
1269
1176
|
handlebars: _hbsAsync,
|
|
1270
|
-
registerHelpers:
|
|
1177
|
+
registerHelpers: (helpers) => {
|
|
1271
1178
|
_registerHelpers(helpers, _hbsAsync);
|
|
1272
|
-
},
|
|
1273
|
-
registerPartials:
|
|
1179
|
+
},
|
|
1180
|
+
registerPartials: (partials2) => {
|
|
1274
1181
|
_registerPartials(partials2, _hbsAsync);
|
|
1275
|
-
}
|
|
1182
|
+
}
|
|
1276
1183
|
};
|
|
1277
1184
|
|
|
1278
1185
|
// src/utils/modules/replaceTemplateString.ts
|
|
@@ -1305,7 +1212,6 @@ function replaceTemplateString(templateString, substitutions = {}, configuration
|
|
|
1305
1212
|
});
|
|
1306
1213
|
return res;
|
|
1307
1214
|
}
|
|
1308
|
-
__name(replaceTemplateString, "replaceTemplateString");
|
|
1309
1215
|
|
|
1310
1216
|
// src/utils/modules/replaceTemplateStringAsync.ts
|
|
1311
1217
|
async function replaceTemplateStringAsync(templateString, substitutions = {}, configuration = {
|
|
@@ -1337,24 +1243,22 @@ async function replaceTemplateStringAsync(templateString, substitutions = {}, co
|
|
|
1337
1243
|
});
|
|
1338
1244
|
return res;
|
|
1339
1245
|
}
|
|
1340
|
-
__name(replaceTemplateStringAsync, "replaceTemplateStringAsync");
|
|
1341
1246
|
|
|
1342
1247
|
// src/utils/modules/asyncCallWithTimeout.ts
|
|
1343
|
-
var asyncCallWithTimeout =
|
|
1248
|
+
var asyncCallWithTimeout = async (asyncPromise, timeLimit = 1e4) => {
|
|
1344
1249
|
let timeoutHandle;
|
|
1345
1250
|
const timeoutPromise = new Promise((_resolve, reject) => {
|
|
1346
1251
|
timeoutHandle = setTimeout(() => {
|
|
1347
|
-
return reject(
|
|
1252
|
+
return reject(
|
|
1253
|
+
new Error("Unable to perform action. Try again, or use another action.")
|
|
1254
|
+
);
|
|
1348
1255
|
}, timeLimit);
|
|
1349
1256
|
});
|
|
1350
|
-
return Promise.race([
|
|
1351
|
-
asyncPromise,
|
|
1352
|
-
timeoutPromise
|
|
1353
|
-
]).then((result) => {
|
|
1257
|
+
return Promise.race([asyncPromise, timeoutPromise]).then((result) => {
|
|
1354
1258
|
clearTimeout(timeoutHandle);
|
|
1355
1259
|
return result;
|
|
1356
1260
|
});
|
|
1357
|
-
}
|
|
1261
|
+
};
|
|
1358
1262
|
|
|
1359
1263
|
// src/utils/modules/guessProviderFromModel.ts
|
|
1360
1264
|
function isModelKnownOpenAi(payload) {
|
|
@@ -1370,7 +1274,6 @@ function isModelKnownOpenAi(payload) {
|
|
|
1370
1274
|
}
|
|
1371
1275
|
return false;
|
|
1372
1276
|
}
|
|
1373
|
-
__name(isModelKnownOpenAi, "isModelKnownOpenAi");
|
|
1374
1277
|
function isModelKnownAnthropic(payload) {
|
|
1375
1278
|
const model = payload.model.toLowerCase();
|
|
1376
1279
|
if (model.startsWith("claude-")) {
|
|
@@ -1378,7 +1281,6 @@ function isModelKnownAnthropic(payload) {
|
|
|
1378
1281
|
}
|
|
1379
1282
|
return false;
|
|
1380
1283
|
}
|
|
1381
|
-
__name(isModelKnownAnthropic, "isModelKnownAnthropic");
|
|
1382
1284
|
function isModelKnownXai(payload) {
|
|
1383
1285
|
const model = payload.model.toLowerCase();
|
|
1384
1286
|
if (model.startsWith("grok-")) {
|
|
@@ -1386,7 +1288,6 @@ function isModelKnownXai(payload) {
|
|
|
1386
1288
|
}
|
|
1387
1289
|
return false;
|
|
1388
1290
|
}
|
|
1389
|
-
__name(isModelKnownXai, "isModelKnownXai");
|
|
1390
1291
|
function isModelKnownBedrockAnthropic(payload) {
|
|
1391
1292
|
const model = payload.model.toLowerCase();
|
|
1392
1293
|
if (model.startsWith("anthropic.claude-")) {
|
|
@@ -1394,7 +1295,6 @@ function isModelKnownBedrockAnthropic(payload) {
|
|
|
1394
1295
|
}
|
|
1395
1296
|
return false;
|
|
1396
1297
|
}
|
|
1397
|
-
__name(isModelKnownBedrockAnthropic, "isModelKnownBedrockAnthropic");
|
|
1398
1298
|
function guessProviderFromModel(payload) {
|
|
1399
1299
|
switch (true) {
|
|
1400
1300
|
case isModelKnownOpenAi(payload):
|
|
@@ -1409,19 +1309,16 @@ function guessProviderFromModel(payload) {
|
|
|
1409
1309
|
throw new Error("Unsupported model");
|
|
1410
1310
|
}
|
|
1411
1311
|
}
|
|
1412
|
-
__name(guessProviderFromModel, "guessProviderFromModel");
|
|
1413
1312
|
|
|
1414
1313
|
// src/utils/modules/index.ts
|
|
1415
1314
|
function registerHelpers(helpers) {
|
|
1416
1315
|
hbs.registerHelpers(helpers);
|
|
1417
1316
|
hbsAsync.registerHelpers(helpers);
|
|
1418
1317
|
}
|
|
1419
|
-
__name(registerHelpers, "registerHelpers");
|
|
1420
1318
|
function registerPartials(partials2) {
|
|
1421
1319
|
hbs.registerPartials(partials2);
|
|
1422
1320
|
hbsAsync.registerPartials(partials2);
|
|
1423
1321
|
}
|
|
1424
|
-
__name(registerPartials, "registerPartials");
|
|
1425
1322
|
|
|
1426
1323
|
// src/llm/output/_utils/getResultText.ts
|
|
1427
1324
|
function getResultText(content) {
|
|
@@ -1430,10 +1327,9 @@ function getResultText(content) {
|
|
|
1430
1327
|
}
|
|
1431
1328
|
return "";
|
|
1432
1329
|
}
|
|
1433
|
-
__name(getResultText, "getResultText");
|
|
1434
1330
|
|
|
1435
1331
|
// src/parser/parsers/OpenAiFunctionParser.ts
|
|
1436
|
-
var
|
|
1332
|
+
var OpenAiFunctionParser = class extends BaseParser {
|
|
1437
1333
|
constructor(options) {
|
|
1438
1334
|
super("openAiFunction", options, "function_call");
|
|
1439
1335
|
__publicField(this, "parser");
|
|
@@ -1450,30 +1346,32 @@ var _OpenAiFunctionParser = class _OpenAiFunctionParser extends BaseParser {
|
|
|
1450
1346
|
return this.parser.parse(getResultText(text));
|
|
1451
1347
|
}
|
|
1452
1348
|
};
|
|
1453
|
-
__name(_OpenAiFunctionParser, "OpenAiFunctionParser");
|
|
1454
|
-
var OpenAiFunctionParser = _OpenAiFunctionParser;
|
|
1455
1349
|
|
|
1456
1350
|
// src/parser/parsers/StringParser.ts
|
|
1457
|
-
var
|
|
1351
|
+
var StringParser = class extends BaseParser {
|
|
1458
1352
|
constructor(options) {
|
|
1459
1353
|
super("string", options);
|
|
1460
1354
|
}
|
|
1461
1355
|
parse(text, _options) {
|
|
1462
|
-
assert(
|
|
1356
|
+
assert(
|
|
1357
|
+
typeof text === "string",
|
|
1358
|
+
`Invalid input. Expected string. Received ${typeof text}.`
|
|
1359
|
+
);
|
|
1463
1360
|
const parsed = text.toString();
|
|
1464
1361
|
return parsed;
|
|
1465
1362
|
}
|
|
1466
1363
|
};
|
|
1467
|
-
__name(_StringParser, "StringParser");
|
|
1468
|
-
var StringParser = _StringParser;
|
|
1469
1364
|
|
|
1470
1365
|
// src/parser/parsers/BooleanParser.ts
|
|
1471
|
-
var
|
|
1366
|
+
var BooleanParser = class extends BaseParser {
|
|
1472
1367
|
constructor(options) {
|
|
1473
1368
|
super("boolean", options);
|
|
1474
1369
|
}
|
|
1475
1370
|
parse(text) {
|
|
1476
|
-
assert(
|
|
1371
|
+
assert(
|
|
1372
|
+
typeof text === "string",
|
|
1373
|
+
`Invalid input. Expected string. Received ${typeof text}.`
|
|
1374
|
+
);
|
|
1477
1375
|
const clean = text.toLowerCase().trim();
|
|
1478
1376
|
if (clean === "true") {
|
|
1479
1377
|
return true;
|
|
@@ -1481,17 +1379,14 @@ var _BooleanParser = class _BooleanParser extends BaseParser {
|
|
|
1481
1379
|
return false;
|
|
1482
1380
|
}
|
|
1483
1381
|
};
|
|
1484
|
-
__name(_BooleanParser, "BooleanParser");
|
|
1485
|
-
var BooleanParser = _BooleanParser;
|
|
1486
1382
|
|
|
1487
1383
|
// src/utils/modules/isFinite.ts
|
|
1488
1384
|
function isFinite(value) {
|
|
1489
1385
|
return typeof value === "number" && Number.isFinite(value);
|
|
1490
1386
|
}
|
|
1491
|
-
__name(isFinite, "isFinite");
|
|
1492
1387
|
|
|
1493
1388
|
// src/parser/parsers/NumberParser.ts
|
|
1494
|
-
var
|
|
1389
|
+
var NumberParser = class extends BaseParser {
|
|
1495
1390
|
constructor(options) {
|
|
1496
1391
|
super("number", options);
|
|
1497
1392
|
}
|
|
@@ -1500,8 +1395,6 @@ var _NumberParser = class _NumberParser extends BaseParser {
|
|
|
1500
1395
|
return match && isFinite(toNumber(match[0])) ? toNumber(match[0]) : -1;
|
|
1501
1396
|
}
|
|
1502
1397
|
};
|
|
1503
|
-
__name(_NumberParser, "NumberParser");
|
|
1504
|
-
var NumberParser = _NumberParser;
|
|
1505
1398
|
|
|
1506
1399
|
// src/parser/_utils.ts
|
|
1507
1400
|
import { validate as validateSchema } from "jsonschema";
|
|
@@ -1511,7 +1404,6 @@ function enforceParserSchema(schema, parsed) {
|
|
|
1511
1404
|
}
|
|
1512
1405
|
return filterObjectOnSchema(schema, parsed);
|
|
1513
1406
|
}
|
|
1514
|
-
__name(enforceParserSchema, "enforceParserSchema");
|
|
1515
1407
|
function validateParserSchema(schema, parsed) {
|
|
1516
1408
|
if (!schema || !parsed || typeof parsed !== "object") {
|
|
1517
1409
|
return null;
|
|
@@ -1522,10 +1414,9 @@ function validateParserSchema(schema, parsed) {
|
|
|
1522
1414
|
}
|
|
1523
1415
|
return null;
|
|
1524
1416
|
}
|
|
1525
|
-
__name(validateParserSchema, "validateParserSchema");
|
|
1526
1417
|
|
|
1527
1418
|
// src/utils/modules/errors.ts
|
|
1528
|
-
var
|
|
1419
|
+
var LlmExeError = class extends Error {
|
|
1529
1420
|
constructor(message, code, context) {
|
|
1530
1421
|
super(message ?? "");
|
|
1531
1422
|
__publicField(this, "code");
|
|
@@ -1538,11 +1429,9 @@ var _LlmExeError = class _LlmExeError extends Error {
|
|
|
1538
1429
|
}
|
|
1539
1430
|
}
|
|
1540
1431
|
};
|
|
1541
|
-
__name(_LlmExeError, "LlmExeError");
|
|
1542
|
-
var LlmExeError = _LlmExeError;
|
|
1543
1432
|
|
|
1544
1433
|
// src/parser/parsers/JsonParser.ts
|
|
1545
|
-
var
|
|
1434
|
+
var JsonParser = class extends BaseParserWithJson {
|
|
1546
1435
|
constructor(options = {}) {
|
|
1547
1436
|
super("json", options);
|
|
1548
1437
|
}
|
|
@@ -1565,8 +1454,6 @@ var _JsonParser = class _JsonParser extends BaseParserWithJson {
|
|
|
1565
1454
|
return parsed;
|
|
1566
1455
|
}
|
|
1567
1456
|
};
|
|
1568
|
-
__name(_JsonParser, "JsonParser");
|
|
1569
|
-
var JsonParser = _JsonParser;
|
|
1570
1457
|
|
|
1571
1458
|
// src/utils/modules/camelCase.ts
|
|
1572
1459
|
function camelCase(input) {
|
|
@@ -1581,10 +1468,9 @@ function camelCase(input) {
|
|
|
1581
1468
|
}
|
|
1582
1469
|
}).join("");
|
|
1583
1470
|
}
|
|
1584
|
-
__name(camelCase, "camelCase");
|
|
1585
1471
|
|
|
1586
1472
|
// src/parser/parsers/ListToJsonParser.ts
|
|
1587
|
-
var
|
|
1473
|
+
var ListToJsonParser = class extends BaseParserWithJson {
|
|
1588
1474
|
constructor(options = {}) {
|
|
1589
1475
|
super("listToJson", options);
|
|
1590
1476
|
}
|
|
@@ -1614,76 +1500,65 @@ var _ListToJsonParser = class _ListToJsonParser extends BaseParserWithJson {
|
|
|
1614
1500
|
return output;
|
|
1615
1501
|
}
|
|
1616
1502
|
};
|
|
1617
|
-
__name(_ListToJsonParser, "ListToJsonParser");
|
|
1618
|
-
var ListToJsonParser = _ListToJsonParser;
|
|
1619
1503
|
|
|
1620
1504
|
// src/parser/parsers/ListToKeyValueParser.ts
|
|
1621
|
-
var
|
|
1505
|
+
var ListToKeyValueParser = class extends BaseParser {
|
|
1622
1506
|
constructor(options) {
|
|
1623
1507
|
super("listToKeyValue", options);
|
|
1624
1508
|
}
|
|
1625
1509
|
parse(text) {
|
|
1626
|
-
const lines = text.split("\n").map((s) => s.replace("- ", "").replace(
|
|
1510
|
+
const lines = text.split("\n").map((s) => s.replace("- ", "").replace(/'/g, "'"));
|
|
1627
1511
|
let res = [];
|
|
1628
1512
|
for (const line of lines) {
|
|
1629
1513
|
const [key, value] = line.split(":");
|
|
1630
1514
|
if (key && value) {
|
|
1631
|
-
res.push({
|
|
1632
|
-
key: key?.trim(),
|
|
1633
|
-
value: value?.trim()
|
|
1634
|
-
});
|
|
1515
|
+
res.push({ key: key?.trim(), value: value?.trim() });
|
|
1635
1516
|
}
|
|
1636
1517
|
}
|
|
1637
1518
|
return res;
|
|
1638
1519
|
}
|
|
1639
1520
|
};
|
|
1640
|
-
__name(_ListToKeyValueParser, "ListToKeyValueParser");
|
|
1641
|
-
var ListToKeyValueParser = _ListToKeyValueParser;
|
|
1642
1521
|
|
|
1643
1522
|
// src/parser/parsers/CustomParser.ts
|
|
1644
|
-
var
|
|
1523
|
+
var CustomParser = class extends BaseParser {
|
|
1645
1524
|
/**
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1525
|
+
* Creates a new CustomParser instance.
|
|
1526
|
+
* @param {string} name The name of the parser.
|
|
1527
|
+
* @param {any} parserFn The custom parsing function.
|
|
1528
|
+
*/
|
|
1650
1529
|
constructor(name, parserFn) {
|
|
1651
1530
|
super(name);
|
|
1652
1531
|
/**
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1532
|
+
* Custom parsing function.
|
|
1533
|
+
* @type {any}
|
|
1534
|
+
*/
|
|
1656
1535
|
__publicField(this, "parserFn");
|
|
1657
1536
|
this.parserFn = parserFn;
|
|
1658
1537
|
}
|
|
1659
1538
|
/**
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1539
|
+
* Parses the text using the custom parsing function.
|
|
1540
|
+
* @param {string} text The text to be parsed.
|
|
1541
|
+
* @param {any} inputValues Additional input values for the parser function.
|
|
1542
|
+
* @returns {O} The parsed value.
|
|
1543
|
+
*/
|
|
1665
1544
|
parse(text, inputValues) {
|
|
1666
1545
|
return this.parserFn.call(this, text, inputValues);
|
|
1667
1546
|
}
|
|
1668
1547
|
};
|
|
1669
|
-
__name(_CustomParser, "CustomParser");
|
|
1670
|
-
var CustomParser = _CustomParser;
|
|
1671
1548
|
|
|
1672
1549
|
// src/parser/parsers/ListToArrayParser.ts
|
|
1673
|
-
var
|
|
1550
|
+
var ListToArrayParser = class extends BaseParser {
|
|
1674
1551
|
constructor() {
|
|
1675
1552
|
super("listToArray");
|
|
1676
1553
|
}
|
|
1677
1554
|
parse(text) {
|
|
1678
|
-
const lines = text.split("\n").map((s) => s.replace(
|
|
1555
|
+
const lines = text.split("\n").map((s) => s.replace(/^- /, "").replace(/'/g, "'").trim());
|
|
1679
1556
|
return lines;
|
|
1680
1557
|
}
|
|
1681
1558
|
};
|
|
1682
|
-
__name(_ListToArrayParser, "ListToArrayParser");
|
|
1683
|
-
var ListToArrayParser = _ListToArrayParser;
|
|
1684
1559
|
|
|
1685
1560
|
// src/parser/parsers/ReplaceStringTemplateParser.ts
|
|
1686
|
-
var
|
|
1561
|
+
var ReplaceStringTemplateParser = class extends BaseParser {
|
|
1687
1562
|
constructor(options) {
|
|
1688
1563
|
super("replaceStringTemplate", options);
|
|
1689
1564
|
}
|
|
@@ -1691,17 +1566,38 @@ var _ReplaceStringTemplateParser = class _ReplaceStringTemplateParser extends Ba
|
|
|
1691
1566
|
return replaceTemplateString(text, attributes);
|
|
1692
1567
|
}
|
|
1693
1568
|
};
|
|
1694
|
-
|
|
1695
|
-
|
|
1569
|
+
|
|
1570
|
+
// src/parser/singleKeyObjectToString.ts
|
|
1571
|
+
function singleKeyObjectToString(input) {
|
|
1572
|
+
try {
|
|
1573
|
+
const parsed = JSON.parse(input);
|
|
1574
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
1575
|
+
const keys = Object.keys(parsed);
|
|
1576
|
+
if (keys.length === 1) {
|
|
1577
|
+
const value = parsed[keys[0]];
|
|
1578
|
+
if (typeof value === "string") {
|
|
1579
|
+
return value;
|
|
1580
|
+
} else {
|
|
1581
|
+
return input;
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
}
|
|
1585
|
+
} catch {
|
|
1586
|
+
}
|
|
1587
|
+
return input;
|
|
1588
|
+
}
|
|
1696
1589
|
|
|
1697
1590
|
// src/parser/parsers/MarkdownCodeBlocks.ts
|
|
1698
|
-
var
|
|
1591
|
+
var MarkdownCodeBlocksParser = class extends BaseParser {
|
|
1699
1592
|
constructor(options) {
|
|
1700
1593
|
super("markdownCodeBlocks", options);
|
|
1701
1594
|
}
|
|
1702
1595
|
parse(input) {
|
|
1703
1596
|
const out = [];
|
|
1704
|
-
|
|
1597
|
+
if (isObjectStringified(input)) {
|
|
1598
|
+
input = singleKeyObjectToString(input);
|
|
1599
|
+
}
|
|
1600
|
+
const regex = input.matchAll(new RegExp(/```(\w*)\n([\s\S]*?)```/, "g"));
|
|
1705
1601
|
for (const iterator of regex) {
|
|
1706
1602
|
if (iterator) {
|
|
1707
1603
|
const [_input, language, code] = iterator;
|
|
@@ -1714,24 +1610,26 @@ var _MarkdownCodeBlocksParser = class _MarkdownCodeBlocksParser extends BasePars
|
|
|
1714
1610
|
return out;
|
|
1715
1611
|
}
|
|
1716
1612
|
};
|
|
1717
|
-
__name(_MarkdownCodeBlocksParser, "MarkdownCodeBlocksParser");
|
|
1718
|
-
var MarkdownCodeBlocksParser = _MarkdownCodeBlocksParser;
|
|
1719
1613
|
|
|
1720
1614
|
// src/parser/parsers/MarkdownCodeBlock.ts
|
|
1721
|
-
var
|
|
1615
|
+
var MarkdownCodeBlockParser = class extends BaseParser {
|
|
1722
1616
|
constructor(options) {
|
|
1723
1617
|
super("markdownCodeBlock", options);
|
|
1724
1618
|
}
|
|
1725
1619
|
parse(input) {
|
|
1726
1620
|
const [block] = new MarkdownCodeBlocksParser().parse(input);
|
|
1621
|
+
if (!block) {
|
|
1622
|
+
return {
|
|
1623
|
+
code: "",
|
|
1624
|
+
language: ""
|
|
1625
|
+
};
|
|
1626
|
+
}
|
|
1727
1627
|
return block;
|
|
1728
1628
|
}
|
|
1729
1629
|
};
|
|
1730
|
-
__name(_MarkdownCodeBlockParser, "MarkdownCodeBlockParser");
|
|
1731
|
-
var MarkdownCodeBlockParser = _MarkdownCodeBlockParser;
|
|
1732
1630
|
|
|
1733
1631
|
// src/parser/parsers/StringExtractParser.ts
|
|
1734
|
-
var
|
|
1632
|
+
var StringExtractParser = class extends BaseParser {
|
|
1735
1633
|
constructor(options) {
|
|
1736
1634
|
super("stringExtract", options);
|
|
1737
1635
|
__publicField(this, "enum", []);
|
|
@@ -1744,7 +1642,10 @@ var _StringExtractParser = class _StringExtractParser extends BaseParser {
|
|
|
1744
1642
|
}
|
|
1745
1643
|
}
|
|
1746
1644
|
parse(text) {
|
|
1747
|
-
assert(
|
|
1645
|
+
assert(
|
|
1646
|
+
typeof text === "string",
|
|
1647
|
+
`Invalid input. Expected string. Received ${typeof text}.`
|
|
1648
|
+
);
|
|
1748
1649
|
for (const option of this.enum) {
|
|
1749
1650
|
const regex = this.ignoreCase ? new RegExp(option.toLowerCase(), "i") : new RegExp(option);
|
|
1750
1651
|
if (regex.test(text)) {
|
|
@@ -1754,8 +1655,6 @@ var _StringExtractParser = class _StringExtractParser extends BaseParser {
|
|
|
1754
1655
|
return "";
|
|
1755
1656
|
}
|
|
1756
1657
|
};
|
|
1757
|
-
__name(_StringExtractParser, "StringExtractParser");
|
|
1758
|
-
var StringExtractParser = _StringExtractParser;
|
|
1759
1658
|
|
|
1760
1659
|
// src/parser/_functions.ts
|
|
1761
1660
|
function createParser(type, options = {}) {
|
|
@@ -1785,16 +1684,18 @@ function createParser(type, options = {}) {
|
|
|
1785
1684
|
return new StringParser();
|
|
1786
1685
|
}
|
|
1787
1686
|
}
|
|
1788
|
-
__name(createParser, "createParser");
|
|
1789
1687
|
function createCustomParser(name, parserFn) {
|
|
1790
1688
|
return new CustomParser(name, parserFn);
|
|
1791
1689
|
}
|
|
1792
|
-
__name(createCustomParser, "createCustomParser");
|
|
1793
1690
|
|
|
1794
1691
|
// src/executor/llm.ts
|
|
1795
|
-
var
|
|
1692
|
+
var LlmExecutor = class extends BaseExecutor {
|
|
1796
1693
|
constructor(llmConfiguration, options) {
|
|
1797
|
-
super(
|
|
1694
|
+
super(
|
|
1695
|
+
llmConfiguration.name || "anonymous-llm-executor",
|
|
1696
|
+
"llm-executor",
|
|
1697
|
+
options
|
|
1698
|
+
);
|
|
1798
1699
|
__publicField(this, "llm");
|
|
1799
1700
|
__publicField(this, "prompt");
|
|
1800
1701
|
__publicField(this, "promptFn");
|
|
@@ -1810,12 +1711,13 @@ var _LlmExecutor = class _LlmExecutor extends BaseExecutor {
|
|
|
1810
1711
|
}
|
|
1811
1712
|
}
|
|
1812
1713
|
async execute(_input, _options) {
|
|
1714
|
+
const input = _input ?? {};
|
|
1813
1715
|
if (this?.parser instanceof JsonParser && this.parser.schema) {
|
|
1814
1716
|
_options = Object.assign(_options || {}, {
|
|
1815
1717
|
jsonSchema: this.parser.schema
|
|
1816
1718
|
});
|
|
1817
1719
|
}
|
|
1818
|
-
return super.execute(
|
|
1720
|
+
return super.execute(input, _options);
|
|
1819
1721
|
}
|
|
1820
1722
|
async handler(_input, ..._args) {
|
|
1821
1723
|
const call = await this.llm.call(_input, ..._args);
|
|
@@ -1860,57 +1762,45 @@ var _LlmExecutor = class _LlmExecutor extends BaseExecutor {
|
|
|
1860
1762
|
return this.llm.getTraceId();
|
|
1861
1763
|
}
|
|
1862
1764
|
};
|
|
1863
|
-
__name(_LlmExecutor, "LlmExecutor");
|
|
1864
|
-
var LlmExecutor = _LlmExecutor;
|
|
1865
1765
|
|
|
1866
1766
|
// src/executor/_functions.ts
|
|
1867
1767
|
function createCoreExecutor(handler, options) {
|
|
1868
|
-
return new CoreExecutor({
|
|
1869
|
-
handler
|
|
1870
|
-
}, options);
|
|
1768
|
+
return new CoreExecutor({ handler }, options);
|
|
1871
1769
|
}
|
|
1872
|
-
__name(createCoreExecutor, "createCoreExecutor");
|
|
1873
1770
|
function createLlmExecutor(llmConfiguration, options) {
|
|
1874
1771
|
return new LlmExecutor(llmConfiguration, options);
|
|
1875
1772
|
}
|
|
1876
|
-
__name(createLlmExecutor, "createLlmExecutor");
|
|
1877
1773
|
|
|
1878
1774
|
// src/executor/llm-openai-function.ts
|
|
1879
|
-
var
|
|
1775
|
+
var LlmExecutorOpenAiFunctions = class extends LlmExecutor {
|
|
1880
1776
|
constructor(llmConfiguration, options) {
|
|
1881
|
-
super(
|
|
1882
|
-
|
|
1883
|
-
parser:
|
|
1884
|
-
|
|
1885
|
-
|
|
1777
|
+
super(
|
|
1778
|
+
Object.assign({}, llmConfiguration, {
|
|
1779
|
+
parser: new OpenAiFunctionParser({
|
|
1780
|
+
parser: llmConfiguration.parser || new StringParser()
|
|
1781
|
+
})
|
|
1782
|
+
}),
|
|
1783
|
+
options
|
|
1784
|
+
);
|
|
1886
1785
|
}
|
|
1887
1786
|
async execute(_input, _options) {
|
|
1888
1787
|
return super.execute(_input, _options);
|
|
1889
1788
|
}
|
|
1890
1789
|
};
|
|
1891
|
-
__name(_LlmExecutorOpenAiFunctions, "LlmExecutorOpenAiFunctions");
|
|
1892
|
-
var LlmExecutorOpenAiFunctions = _LlmExecutorOpenAiFunctions;
|
|
1893
1790
|
|
|
1894
1791
|
// src/utils/modules/enforceResultAttributes.ts
|
|
1895
1792
|
function enforceResultAttributes(input) {
|
|
1896
1793
|
if (!input) {
|
|
1897
|
-
return {
|
|
1898
|
-
result: input,
|
|
1899
|
-
attributes: {}
|
|
1900
|
-
};
|
|
1794
|
+
return { result: input, attributes: {} };
|
|
1901
1795
|
}
|
|
1902
1796
|
if (typeof input === "object" && (Object.keys(input).length === 2 && "result" in input && "attributes" in input || Object.keys(input).length === 1 && ("result" in input || "attributes" in input))) {
|
|
1903
1797
|
return input;
|
|
1904
1798
|
}
|
|
1905
|
-
return {
|
|
1906
|
-
result: input,
|
|
1907
|
-
attributes: {}
|
|
1908
|
-
};
|
|
1799
|
+
return { result: input, attributes: {} };
|
|
1909
1800
|
}
|
|
1910
|
-
__name(enforceResultAttributes, "enforceResultAttributes");
|
|
1911
1801
|
|
|
1912
1802
|
// src/plugins/callable/callable.ts
|
|
1913
|
-
var
|
|
1803
|
+
var CallableExecutor = class {
|
|
1914
1804
|
constructor(options) {
|
|
1915
1805
|
__publicField(this, "name");
|
|
1916
1806
|
__publicField(this, "key");
|
|
@@ -1945,32 +1835,29 @@ var _CallableExecutor = class _CallableExecutor {
|
|
|
1945
1835
|
async validateInput(input) {
|
|
1946
1836
|
try {
|
|
1947
1837
|
if (typeof this._validateInput === "function") {
|
|
1948
|
-
const response = await this._validateInput(
|
|
1838
|
+
const response = await this._validateInput(
|
|
1839
|
+
ensureInputIsObject(input),
|
|
1840
|
+
this._handler.getMetadata()
|
|
1841
|
+
);
|
|
1949
1842
|
return enforceResultAttributes(response);
|
|
1950
1843
|
}
|
|
1951
|
-
return {
|
|
1952
|
-
result: true,
|
|
1953
|
-
attributes: {}
|
|
1954
|
-
};
|
|
1844
|
+
return { result: true, attributes: {} };
|
|
1955
1845
|
} catch (error) {
|
|
1956
|
-
return {
|
|
1957
|
-
result: false,
|
|
1958
|
-
attributes: {
|
|
1959
|
-
error: error.message
|
|
1960
|
-
}
|
|
1961
|
-
};
|
|
1846
|
+
return { result: false, attributes: { error: error.message } };
|
|
1962
1847
|
}
|
|
1963
1848
|
}
|
|
1964
1849
|
visibilityHandler(input, attributes) {
|
|
1965
1850
|
if (typeof this._visibilityHandler === "function") {
|
|
1966
|
-
return this._visibilityHandler(
|
|
1851
|
+
return this._visibilityHandler(
|
|
1852
|
+
input,
|
|
1853
|
+
this._handler.getMetadata(),
|
|
1854
|
+
attributes
|
|
1855
|
+
);
|
|
1967
1856
|
}
|
|
1968
1857
|
return true;
|
|
1969
1858
|
}
|
|
1970
1859
|
};
|
|
1971
|
-
|
|
1972
|
-
var CallableExecutor = _CallableExecutor;
|
|
1973
|
-
var _UseExecutorsBase = class _UseExecutorsBase {
|
|
1860
|
+
var UseExecutorsBase = class {
|
|
1974
1861
|
constructor(handlers) {
|
|
1975
1862
|
__publicField(this, "handlers", []);
|
|
1976
1863
|
this.handlers = handlers;
|
|
@@ -1982,18 +1869,21 @@ var _UseExecutorsBase = class _UseExecutorsBase {
|
|
|
1982
1869
|
return this.handlers.find((a) => a.name === name);
|
|
1983
1870
|
}
|
|
1984
1871
|
getFunctions() {
|
|
1985
|
-
return [
|
|
1986
|
-
...this.handlers
|
|
1987
|
-
];
|
|
1872
|
+
return [...this.handlers];
|
|
1988
1873
|
}
|
|
1989
1874
|
getVisibleFunctions(_input, _attributes = {}) {
|
|
1990
1875
|
const handlers = this.getFunctions();
|
|
1991
|
-
return handlers.filter(
|
|
1876
|
+
return handlers.filter(
|
|
1877
|
+
(a) => typeof a.visibilityHandler === "undefined" || typeof a.visibilityHandler === "function" && a.visibilityHandler(_input, _attributes)
|
|
1878
|
+
);
|
|
1992
1879
|
}
|
|
1993
1880
|
async callFunction(name, input) {
|
|
1994
1881
|
try {
|
|
1995
1882
|
const handler = this.getFunction(name);
|
|
1996
|
-
assert(
|
|
1883
|
+
assert(
|
|
1884
|
+
handler,
|
|
1885
|
+
`[invalid handler] The handler (${name}) does not exist.`
|
|
1886
|
+
);
|
|
1997
1887
|
const result = await handler.execute(ensureInputIsObject(input));
|
|
1998
1888
|
return result;
|
|
1999
1889
|
} catch (error) {
|
|
@@ -2003,41 +1893,37 @@ var _UseExecutorsBase = class _UseExecutorsBase {
|
|
|
2003
1893
|
async validateFunctionInput(name, input) {
|
|
2004
1894
|
try {
|
|
2005
1895
|
const handler = this.getFunction(name);
|
|
2006
|
-
assert(
|
|
2007
|
-
|
|
1896
|
+
assert(
|
|
1897
|
+
handler,
|
|
1898
|
+
`[invalid handler] The handler (${name}) does not exist.`
|
|
1899
|
+
);
|
|
1900
|
+
const result = await handler.validateInput(
|
|
1901
|
+
ensureInputIsObject(input)
|
|
1902
|
+
);
|
|
2008
1903
|
return result;
|
|
2009
1904
|
} catch (error) {
|
|
2010
|
-
return {
|
|
2011
|
-
result: false,
|
|
2012
|
-
attributes: {
|
|
2013
|
-
error: error.message
|
|
2014
|
-
}
|
|
2015
|
-
};
|
|
1905
|
+
return { result: false, attributes: { error: error.message } };
|
|
2016
1906
|
}
|
|
2017
1907
|
}
|
|
2018
1908
|
};
|
|
2019
|
-
__name(_UseExecutorsBase, "UseExecutorsBase");
|
|
2020
|
-
var UseExecutorsBase = _UseExecutorsBase;
|
|
2021
1909
|
|
|
2022
1910
|
// src/plugins/callable/index.ts
|
|
2023
1911
|
function createCallableExecutor(options) {
|
|
2024
1912
|
return new CallableExecutor(options);
|
|
2025
1913
|
}
|
|
2026
|
-
|
|
2027
|
-
var _UseExecutors = class _UseExecutors extends UseExecutorsBase {
|
|
1914
|
+
var UseExecutors = class extends UseExecutorsBase {
|
|
2028
1915
|
constructor(handlers) {
|
|
2029
1916
|
super(handlers);
|
|
2030
1917
|
}
|
|
2031
1918
|
};
|
|
2032
|
-
__name(_UseExecutors, "UseExecutors");
|
|
2033
|
-
var UseExecutors = _UseExecutors;
|
|
2034
1919
|
function useExecutors(executors) {
|
|
2035
|
-
return new UseExecutors(
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
1920
|
+
return new UseExecutors(
|
|
1921
|
+
executors.map((e) => {
|
|
1922
|
+
if (e instanceof CallableExecutor) return e;
|
|
1923
|
+
return createCallableExecutor(e);
|
|
1924
|
+
})
|
|
1925
|
+
);
|
|
2039
1926
|
}
|
|
2040
|
-
__name(useExecutors, "useExecutors");
|
|
2041
1927
|
|
|
2042
1928
|
// src/utils/modules/deepClone.ts
|
|
2043
1929
|
function deepClone(obj) {
|
|
@@ -2059,7 +1945,6 @@ function deepClone(obj) {
|
|
|
2059
1945
|
}
|
|
2060
1946
|
return obj;
|
|
2061
1947
|
}
|
|
2062
|
-
__name(deepClone, "deepClone");
|
|
2063
1948
|
|
|
2064
1949
|
// src/llm/_utils.withDefaultModel.ts
|
|
2065
1950
|
function withDefaultModel(obj1, model) {
|
|
@@ -2081,7 +1966,15 @@ function withDefaultModel(obj1, model) {
|
|
|
2081
1966
|
}
|
|
2082
1967
|
return copy;
|
|
2083
1968
|
}
|
|
2084
|
-
|
|
1969
|
+
|
|
1970
|
+
// src/utils/modules/getEnvironmentVariable.ts
|
|
1971
|
+
function getEnvironmentVariable(name) {
|
|
1972
|
+
if (typeof process === "object" && process?.env) {
|
|
1973
|
+
return process.env[name];
|
|
1974
|
+
} else {
|
|
1975
|
+
return void 0;
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
2085
1978
|
|
|
2086
1979
|
// src/llm/config/openai/index.ts
|
|
2087
1980
|
var openAiChatV1 = {
|
|
@@ -2101,17 +1994,12 @@ var openAiChatV1 = {
|
|
|
2101
1994
|
mapBody: {
|
|
2102
1995
|
prompt: {
|
|
2103
1996
|
key: "messages",
|
|
2104
|
-
sanitize:
|
|
1997
|
+
sanitize: (v) => {
|
|
2105
1998
|
if (typeof v === "string") {
|
|
2106
|
-
return [
|
|
2107
|
-
{
|
|
2108
|
-
role: "user",
|
|
2109
|
-
content: v
|
|
2110
|
-
}
|
|
2111
|
-
];
|
|
1999
|
+
return [{ role: "user", content: v }];
|
|
2112
2000
|
}
|
|
2113
2001
|
return v;
|
|
2114
|
-
}
|
|
2002
|
+
}
|
|
2115
2003
|
},
|
|
2116
2004
|
model: {
|
|
2117
2005
|
key: "model"
|
|
@@ -2121,7 +2009,7 @@ var openAiChatV1 = {
|
|
|
2121
2009
|
},
|
|
2122
2010
|
useJson: {
|
|
2123
2011
|
key: "response_format.type",
|
|
2124
|
-
sanitize:
|
|
2012
|
+
sanitize: (v) => v ? "json_object" : "text"
|
|
2125
2013
|
}
|
|
2126
2014
|
}
|
|
2127
2015
|
};
|
|
@@ -2151,7 +2039,7 @@ var openAiChatMockV1 = {
|
|
|
2151
2039
|
},
|
|
2152
2040
|
useJson: {
|
|
2153
2041
|
key: "response_format.type",
|
|
2154
|
-
sanitize:
|
|
2042
|
+
sanitize: (v) => v ? "json_object" : "text"
|
|
2155
2043
|
}
|
|
2156
2044
|
}
|
|
2157
2045
|
};
|
|
@@ -2165,37 +2053,31 @@ var openai = {
|
|
|
2165
2053
|
// src/llm/config/anthropic/promptSanitize.ts
|
|
2166
2054
|
function anthropicPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
2167
2055
|
if (typeof _messages === "string") {
|
|
2168
|
-
return [
|
|
2169
|
-
{
|
|
2170
|
-
role: "user",
|
|
2171
|
-
content: _messages
|
|
2172
|
-
}
|
|
2173
|
-
];
|
|
2056
|
+
return [{ role: "user", content: _messages }];
|
|
2174
2057
|
}
|
|
2175
|
-
const [first, ...messages] = [
|
|
2176
|
-
..._messages.map((a) => ({
|
|
2177
|
-
...a
|
|
2178
|
-
}))
|
|
2179
|
-
];
|
|
2058
|
+
const [first, ...messages] = [..._messages.map((a) => ({ ...a }))];
|
|
2180
2059
|
if (first.role === "system" && messages.length === 0) {
|
|
2181
|
-
return [
|
|
2182
|
-
{
|
|
2183
|
-
role: "user",
|
|
2184
|
-
content: first.content
|
|
2185
|
-
},
|
|
2186
|
-
...messages
|
|
2187
|
-
];
|
|
2060
|
+
return [{ role: "user", content: first.content }, ...messages];
|
|
2188
2061
|
}
|
|
2189
2062
|
if (first.role === "system" && messages.length > 0) {
|
|
2190
2063
|
_outputObj.system = first.content;
|
|
2191
|
-
return messages
|
|
2064
|
+
return messages.map((m) => {
|
|
2065
|
+
if (m.role === "system") {
|
|
2066
|
+
return { ...m, role: "user" };
|
|
2067
|
+
}
|
|
2068
|
+
return m;
|
|
2069
|
+
});
|
|
2192
2070
|
}
|
|
2193
2071
|
return [
|
|
2194
2072
|
first,
|
|
2195
|
-
...messages
|
|
2073
|
+
...messages.map((m) => {
|
|
2074
|
+
if (m.role === "system") {
|
|
2075
|
+
return { ...m, role: "user" };
|
|
2076
|
+
}
|
|
2077
|
+
return m;
|
|
2078
|
+
})
|
|
2196
2079
|
];
|
|
2197
2080
|
}
|
|
2198
|
-
__name(anthropicPromptSanitize, "anthropicPromptSanitize");
|
|
2199
2081
|
|
|
2200
2082
|
// src/llm/config/bedrock/index.ts
|
|
2201
2083
|
var ANTORPIC_BEDROCK_VERSION = "bedrock-2023-05-31";
|
|
@@ -2211,10 +2093,7 @@ var amazonAnthropicChatV1 = {
|
|
|
2211
2093
|
maxTokens: {},
|
|
2212
2094
|
awsRegion: {
|
|
2213
2095
|
default: getEnvironmentVariable("AWS_REGION"),
|
|
2214
|
-
required: [
|
|
2215
|
-
true,
|
|
2216
|
-
"aws region is required"
|
|
2217
|
-
]
|
|
2096
|
+
required: [true, "aws region is required"]
|
|
2218
2097
|
},
|
|
2219
2098
|
awsSecretKey: {},
|
|
2220
2099
|
awsAccessKey: {}
|
|
@@ -2257,7 +2136,7 @@ var amazonMetaChatV1 = {
|
|
|
2257
2136
|
mapBody: {
|
|
2258
2137
|
prompt: {
|
|
2259
2138
|
key: "prompt",
|
|
2260
|
-
sanitize:
|
|
2139
|
+
sanitize: (messages) => {
|
|
2261
2140
|
if (typeof messages === "string") {
|
|
2262
2141
|
return messages;
|
|
2263
2142
|
} else {
|
|
@@ -2265,7 +2144,7 @@ var amazonMetaChatV1 = {
|
|
|
2265
2144
|
messages
|
|
2266
2145
|
});
|
|
2267
2146
|
}
|
|
2268
|
-
}
|
|
2147
|
+
}
|
|
2269
2148
|
},
|
|
2270
2149
|
topP: {
|
|
2271
2150
|
key: "top_p"
|
|
@@ -2282,6 +2161,7 @@ var amazonMetaChatV1 = {
|
|
|
2282
2161
|
var bedrock = {
|
|
2283
2162
|
"amazon:anthropic.chat.v1": amazonAnthropicChatV1,
|
|
2284
2163
|
"amazon:meta.chat.v1": amazonMetaChatV1
|
|
2164
|
+
// "amazon:nova.chat.v1": amazonAmazonNovaChatV1,
|
|
2285
2165
|
};
|
|
2286
2166
|
|
|
2287
2167
|
// src/llm/config/anthropic/index.ts
|
|
@@ -2296,10 +2176,7 @@ var anthropicChatV1 = {
|
|
|
2296
2176
|
prompt: {},
|
|
2297
2177
|
system: {},
|
|
2298
2178
|
maxTokens: {
|
|
2299
|
-
required: [
|
|
2300
|
-
true,
|
|
2301
|
-
"maxTokens required"
|
|
2302
|
-
],
|
|
2179
|
+
required: [true, "maxTokens required"],
|
|
2303
2180
|
default: 4096
|
|
2304
2181
|
},
|
|
2305
2182
|
anthropicApiKey: {
|
|
@@ -2324,10 +2201,22 @@ var anthropicChatV1 = {
|
|
|
2324
2201
|
};
|
|
2325
2202
|
var anthropic = {
|
|
2326
2203
|
"anthropic.chat.v1": anthropicChatV1,
|
|
2327
|
-
"anthropic.claude-3-7-sonnet": withDefaultModel(
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2204
|
+
"anthropic.claude-3-7-sonnet": withDefaultModel(
|
|
2205
|
+
anthropicChatV1,
|
|
2206
|
+
"claude-3-7-sonnet-latest"
|
|
2207
|
+
),
|
|
2208
|
+
"anthropic.claude-3-5-sonnet": withDefaultModel(
|
|
2209
|
+
anthropicChatV1,
|
|
2210
|
+
"claude-3-5-sonnet-latest"
|
|
2211
|
+
),
|
|
2212
|
+
"anthropic.claude-3-5-haiku": withDefaultModel(
|
|
2213
|
+
anthropicChatV1,
|
|
2214
|
+
"claude-3-5-haiku-latest"
|
|
2215
|
+
),
|
|
2216
|
+
"anthropic.claude-3-opus": withDefaultModel(
|
|
2217
|
+
anthropicChatV1,
|
|
2218
|
+
"claude-3-opus-latest"
|
|
2219
|
+
)
|
|
2331
2220
|
};
|
|
2332
2221
|
|
|
2333
2222
|
// src/llm/config/x/index.ts
|
|
@@ -2348,17 +2237,12 @@ var xaiChatV1 = {
|
|
|
2348
2237
|
mapBody: {
|
|
2349
2238
|
prompt: {
|
|
2350
2239
|
key: "messages",
|
|
2351
|
-
sanitize:
|
|
2240
|
+
sanitize: (v) => {
|
|
2352
2241
|
if (typeof v === "string") {
|
|
2353
|
-
return [
|
|
2354
|
-
{
|
|
2355
|
-
role: "user",
|
|
2356
|
-
content: v
|
|
2357
|
-
}
|
|
2358
|
-
];
|
|
2242
|
+
return [{ role: "user", content: v }];
|
|
2359
2243
|
}
|
|
2360
2244
|
return v;
|
|
2361
|
-
}
|
|
2245
|
+
}
|
|
2362
2246
|
},
|
|
2363
2247
|
model: {
|
|
2364
2248
|
key: "model"
|
|
@@ -2368,7 +2252,7 @@ var xaiChatV1 = {
|
|
|
2368
2252
|
},
|
|
2369
2253
|
useJson: {
|
|
2370
2254
|
key: "response_format.type",
|
|
2371
|
-
sanitize:
|
|
2255
|
+
sanitize: (v) => v ? "json_object" : "text"
|
|
2372
2256
|
}
|
|
2373
2257
|
}
|
|
2374
2258
|
};
|
|
@@ -2390,17 +2274,12 @@ var ollamaChatV1 = {
|
|
|
2390
2274
|
mapBody: {
|
|
2391
2275
|
prompt: {
|
|
2392
2276
|
key: "messages",
|
|
2393
|
-
sanitize:
|
|
2277
|
+
sanitize: (v) => {
|
|
2394
2278
|
if (typeof v === "string") {
|
|
2395
|
-
return [
|
|
2396
|
-
{
|
|
2397
|
-
role: "user",
|
|
2398
|
-
content: v
|
|
2399
|
-
}
|
|
2400
|
-
];
|
|
2279
|
+
return [{ role: "user", content: v }];
|
|
2401
2280
|
}
|
|
2402
2281
|
return v;
|
|
2403
|
-
}
|
|
2282
|
+
}
|
|
2404
2283
|
},
|
|
2405
2284
|
model: {
|
|
2406
2285
|
key: "model"
|
|
@@ -2418,90 +2297,58 @@ var ollama = {
|
|
|
2418
2297
|
|
|
2419
2298
|
// src/utils/modules/modifyPromptRoleChange.ts
|
|
2420
2299
|
function modifyPromptRoleChange(messages, roleChanges) {
|
|
2421
|
-
const roleChangeMap = new Map(roleChanges.map(({ from, to }) => [
|
|
2422
|
-
from,
|
|
2423
|
-
to
|
|
2424
|
-
]));
|
|
2300
|
+
const roleChangeMap = new Map(roleChanges.map(({ from, to }) => [from, to]));
|
|
2425
2301
|
if (Array.isArray(messages)) {
|
|
2426
2302
|
return messages.map((message) => {
|
|
2427
2303
|
const newRole2 = roleChangeMap.get(message.role);
|
|
2428
|
-
return newRole2 ? {
|
|
2429
|
-
...message,
|
|
2430
|
-
role: newRole2
|
|
2431
|
-
} : message;
|
|
2304
|
+
return newRole2 ? { ...message, role: newRole2 } : message;
|
|
2432
2305
|
});
|
|
2433
2306
|
}
|
|
2434
2307
|
const newRole = roleChangeMap.get(messages.role);
|
|
2435
|
-
return newRole ? {
|
|
2436
|
-
...messages,
|
|
2437
|
-
role: newRole
|
|
2438
|
-
} : messages;
|
|
2308
|
+
return newRole ? { ...messages, role: newRole } : messages;
|
|
2439
2309
|
}
|
|
2440
|
-
__name(modifyPromptRoleChange, "modifyPromptRoleChange");
|
|
2441
2310
|
|
|
2442
2311
|
// src/llm/config/google/promptSanitizeMessageCallback.ts
|
|
2443
2312
|
function googleGeminiPromptMessageCallback(_message) {
|
|
2444
|
-
let message = {
|
|
2445
|
-
..._message
|
|
2446
|
-
};
|
|
2313
|
+
let message = { ..._message };
|
|
2447
2314
|
message = modifyPromptRoleChange(_message, [
|
|
2448
|
-
{
|
|
2449
|
-
from: "assistant",
|
|
2450
|
-
to: "model"
|
|
2451
|
-
}
|
|
2315
|
+
{ from: "assistant", to: "model" }
|
|
2452
2316
|
]);
|
|
2453
2317
|
const { role, ...payload } = message;
|
|
2454
2318
|
const parts = [];
|
|
2455
2319
|
if (typeof payload.content === "string") {
|
|
2456
|
-
parts.push({
|
|
2457
|
-
text: message.content
|
|
2458
|
-
});
|
|
2320
|
+
parts.push({ text: message.content });
|
|
2459
2321
|
}
|
|
2460
2322
|
return {
|
|
2461
2323
|
role,
|
|
2462
2324
|
parts
|
|
2463
2325
|
};
|
|
2464
2326
|
}
|
|
2465
|
-
__name(googleGeminiPromptMessageCallback, "googleGeminiPromptMessageCallback");
|
|
2466
2327
|
|
|
2467
2328
|
// src/llm/config/google/promptSanitize.ts
|
|
2468
2329
|
function googleGeminiPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
2469
2330
|
if (typeof _messages === "string") {
|
|
2470
|
-
return [
|
|
2471
|
-
{
|
|
2472
|
-
role: "user",
|
|
2473
|
-
parts: [
|
|
2474
|
-
{
|
|
2475
|
-
text: _messages
|
|
2476
|
-
}
|
|
2477
|
-
]
|
|
2478
|
-
}
|
|
2479
|
-
];
|
|
2331
|
+
return [{ role: "user", parts: [{ text: _messages }] }];
|
|
2480
2332
|
}
|
|
2481
2333
|
if (Array.isArray(_messages)) {
|
|
2482
2334
|
if (_messages.length === 0) {
|
|
2483
2335
|
throw new Error("Empty messages array");
|
|
2484
2336
|
}
|
|
2485
2337
|
if (_messages.length === 1 && _messages[0].role === "system") {
|
|
2486
|
-
return [
|
|
2487
|
-
{
|
|
2488
|
-
role: "user",
|
|
2489
|
-
parts: [
|
|
2490
|
-
{
|
|
2491
|
-
text: _messages[0].content
|
|
2492
|
-
}
|
|
2493
|
-
]
|
|
2494
|
-
}
|
|
2495
|
-
];
|
|
2338
|
+
return [{ role: "user", parts: [{ text: _messages[0].content }] }];
|
|
2496
2339
|
}
|
|
2497
|
-
const hasSystemInstruction = _messages.some(
|
|
2340
|
+
const hasSystemInstruction = _messages.some(
|
|
2341
|
+
(message) => message.role === "system"
|
|
2342
|
+
);
|
|
2498
2343
|
if (hasSystemInstruction) {
|
|
2499
|
-
const theSystemInstructions = _messages.filter(
|
|
2500
|
-
|
|
2344
|
+
const theSystemInstructions = _messages.filter(
|
|
2345
|
+
(message) => message.role === "system"
|
|
2346
|
+
);
|
|
2347
|
+
const withoutSystemInstructions = _messages.filter(
|
|
2348
|
+
(message) => message.role !== "system"
|
|
2349
|
+
);
|
|
2501
2350
|
_outputObj.system_instruction = {
|
|
2502
|
-
parts: theSystemInstructions.map((message) => ({
|
|
2503
|
-
text: message.content
|
|
2504
|
-
}))
|
|
2351
|
+
parts: theSystemInstructions.map((message) => ({ text: message.content }))
|
|
2505
2352
|
};
|
|
2506
2353
|
return withoutSystemInstructions.map(googleGeminiPromptMessageCallback);
|
|
2507
2354
|
}
|
|
@@ -2509,7 +2356,6 @@ function googleGeminiPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
|
2509
2356
|
}
|
|
2510
2357
|
throw new Error("Invalid messages format");
|
|
2511
2358
|
}
|
|
2512
|
-
__name(googleGeminiPromptSanitize, "googleGeminiPromptSanitize");
|
|
2513
2359
|
|
|
2514
2360
|
// src/llm/config/google/index.ts
|
|
2515
2361
|
var googleGeminiChatV1 = {
|
|
@@ -2530,13 +2376,25 @@ var googleGeminiChatV1 = {
|
|
|
2530
2376
|
key: "contents",
|
|
2531
2377
|
sanitize: googleGeminiPromptSanitize
|
|
2532
2378
|
}
|
|
2379
|
+
// topP: {
|
|
2380
|
+
// key: "top_p",
|
|
2381
|
+
// }
|
|
2533
2382
|
}
|
|
2534
2383
|
};
|
|
2535
2384
|
var google = {
|
|
2536
2385
|
"google.chat.v1": googleGeminiChatV1,
|
|
2537
|
-
"google.gemini-2.0-flash": withDefaultModel(
|
|
2538
|
-
|
|
2539
|
-
|
|
2386
|
+
"google.gemini-2.0-flash": withDefaultModel(
|
|
2387
|
+
googleGeminiChatV1,
|
|
2388
|
+
"gemini-2.0-flash"
|
|
2389
|
+
),
|
|
2390
|
+
"google.gemini-2.0-flash-lite": withDefaultModel(
|
|
2391
|
+
googleGeminiChatV1,
|
|
2392
|
+
"gemini-2.0-flash-lite"
|
|
2393
|
+
),
|
|
2394
|
+
"google.gemini-1.5-pro": withDefaultModel(
|
|
2395
|
+
googleGeminiChatV1,
|
|
2396
|
+
"gemini-1.5-pro"
|
|
2397
|
+
)
|
|
2540
2398
|
};
|
|
2541
2399
|
|
|
2542
2400
|
// src/llm/config/deepseek/index.ts
|
|
@@ -2557,17 +2415,12 @@ var deepseekChatV1 = {
|
|
|
2557
2415
|
mapBody: {
|
|
2558
2416
|
prompt: {
|
|
2559
2417
|
key: "messages",
|
|
2560
|
-
sanitize:
|
|
2418
|
+
sanitize: (v) => {
|
|
2561
2419
|
if (typeof v === "string") {
|
|
2562
|
-
return [
|
|
2563
|
-
{
|
|
2564
|
-
role: "user",
|
|
2565
|
-
content: v
|
|
2566
|
-
}
|
|
2567
|
-
];
|
|
2420
|
+
return [{ role: "user", content: v }];
|
|
2568
2421
|
}
|
|
2569
2422
|
return v;
|
|
2570
|
-
}
|
|
2423
|
+
}
|
|
2571
2424
|
},
|
|
2572
2425
|
model: {
|
|
2573
2426
|
key: "model"
|
|
@@ -2577,7 +2430,7 @@ var deepseekChatV1 = {
|
|
|
2577
2430
|
},
|
|
2578
2431
|
useJson: {
|
|
2579
2432
|
key: "response_format.type",
|
|
2580
|
-
sanitize:
|
|
2433
|
+
sanitize: (v) => v ? "json_object" : "text"
|
|
2581
2434
|
}
|
|
2582
2435
|
}
|
|
2583
2436
|
};
|
|
@@ -2613,7 +2466,6 @@ function getLlmConfig(provider) {
|
|
|
2613
2466
|
resolution: "Provide a valid provider"
|
|
2614
2467
|
});
|
|
2615
2468
|
}
|
|
2616
|
-
__name(getLlmConfig, "getLlmConfig");
|
|
2617
2469
|
|
|
2618
2470
|
// src/llm/output/_utils/getResultContent.ts
|
|
2619
2471
|
function getResultContent(result, index) {
|
|
@@ -2622,11 +2474,8 @@ function getResultContent(result, index) {
|
|
|
2622
2474
|
const val = arr[index];
|
|
2623
2475
|
return val ? val : [];
|
|
2624
2476
|
}
|
|
2625
|
-
return [
|
|
2626
|
-
...result.content
|
|
2627
|
-
];
|
|
2477
|
+
return [...result.content];
|
|
2628
2478
|
}
|
|
2629
|
-
__name(getResultContent, "getResultContent");
|
|
2630
2479
|
|
|
2631
2480
|
// src/llm/output/base.ts
|
|
2632
2481
|
function BaseLlmOutput2(result) {
|
|
@@ -2635,12 +2484,8 @@ function BaseLlmOutput2(result) {
|
|
|
2635
2484
|
name: result.name,
|
|
2636
2485
|
usage: result.usage,
|
|
2637
2486
|
stopReason: result.stopReason,
|
|
2638
|
-
options: [
|
|
2639
|
-
|
|
2640
|
-
],
|
|
2641
|
-
content: [
|
|
2642
|
-
...result.content
|
|
2643
|
-
],
|
|
2487
|
+
options: [...result?.options || []],
|
|
2488
|
+
content: [...result.content],
|
|
2644
2489
|
created: result?.created || (/* @__PURE__ */ new Date()).getTime()
|
|
2645
2490
|
});
|
|
2646
2491
|
function getResult() {
|
|
@@ -2654,14 +2499,12 @@ function BaseLlmOutput2(result) {
|
|
|
2654
2499
|
stopReason: __result.stopReason
|
|
2655
2500
|
};
|
|
2656
2501
|
}
|
|
2657
|
-
__name(getResult, "getResult");
|
|
2658
2502
|
return {
|
|
2659
|
-
getResultContent:
|
|
2660
|
-
getResultText:
|
|
2503
|
+
getResultContent: (index) => getResultContent(__result, index),
|
|
2504
|
+
getResultText: () => getResultText(__result.content),
|
|
2661
2505
|
getResult
|
|
2662
2506
|
};
|
|
2663
2507
|
}
|
|
2664
|
-
__name(BaseLlmOutput2, "BaseLlmOutput2");
|
|
2665
2508
|
|
|
2666
2509
|
// src/llm/output/_util.ts
|
|
2667
2510
|
function normalizeFunctionCall(input, provider) {
|
|
@@ -2672,20 +2515,16 @@ function normalizeFunctionCall(input, provider) {
|
|
|
2672
2515
|
}
|
|
2673
2516
|
return input;
|
|
2674
2517
|
}
|
|
2675
|
-
__name(normalizeFunctionCall, "normalizeFunctionCall");
|
|
2676
2518
|
function formatOptions(response, handler) {
|
|
2677
2519
|
const out = [];
|
|
2678
2520
|
for (const item of response) {
|
|
2679
2521
|
const result = handler(item);
|
|
2680
2522
|
if (result) {
|
|
2681
|
-
out.push([
|
|
2682
|
-
result
|
|
2683
|
-
]);
|
|
2523
|
+
out.push([result]);
|
|
2684
2524
|
}
|
|
2685
2525
|
}
|
|
2686
2526
|
return out;
|
|
2687
2527
|
}
|
|
2688
|
-
__name(formatOptions, "formatOptions");
|
|
2689
2528
|
function formatContent(response, handler) {
|
|
2690
2529
|
const out = [];
|
|
2691
2530
|
const result = handler(response);
|
|
@@ -2694,7 +2533,6 @@ function formatContent(response, handler) {
|
|
|
2694
2533
|
}
|
|
2695
2534
|
return out;
|
|
2696
2535
|
}
|
|
2697
|
-
__name(formatContent, "formatContent");
|
|
2698
2536
|
|
|
2699
2537
|
// src/llm/output/openai.ts
|
|
2700
2538
|
function formatResult(result) {
|
|
@@ -2718,7 +2556,6 @@ function formatResult(result) {
|
|
|
2718
2556
|
text: ""
|
|
2719
2557
|
};
|
|
2720
2558
|
}
|
|
2721
|
-
__name(formatResult, "formatResult");
|
|
2722
2559
|
function OutputOpenAIChat(result, _config) {
|
|
2723
2560
|
const id = result.id;
|
|
2724
2561
|
const name = result.model || _config?.model || "openai.unknown";
|
|
@@ -2742,7 +2579,6 @@ function OutputOpenAIChat(result, _config) {
|
|
|
2742
2579
|
options
|
|
2743
2580
|
});
|
|
2744
2581
|
}
|
|
2745
|
-
__name(OutputOpenAIChat, "OutputOpenAIChat");
|
|
2746
2582
|
|
|
2747
2583
|
// src/llm/output/claude.ts
|
|
2748
2584
|
function formatResult2(response) {
|
|
@@ -2765,7 +2601,6 @@ function formatResult2(response) {
|
|
|
2765
2601
|
}
|
|
2766
2602
|
return out;
|
|
2767
2603
|
}
|
|
2768
|
-
__name(formatResult2, "formatResult");
|
|
2769
2604
|
function OutputAnthropicClaude3Chat(result, _config) {
|
|
2770
2605
|
const id = result.id;
|
|
2771
2606
|
const name = result.model || _config?.model || "anthropic.unknown";
|
|
@@ -2784,17 +2619,13 @@ function OutputAnthropicClaude3Chat(result, _config) {
|
|
|
2784
2619
|
content
|
|
2785
2620
|
});
|
|
2786
2621
|
}
|
|
2787
|
-
__name(OutputAnthropicClaude3Chat, "OutputAnthropicClaude3Chat");
|
|
2788
2622
|
|
|
2789
2623
|
// src/llm/output/llama.ts
|
|
2790
2624
|
function OutputMetaLlama3Chat(result, _config) {
|
|
2791
2625
|
const name = _config?.model || "meta";
|
|
2792
2626
|
const stopReason = result.stop_reason;
|
|
2793
2627
|
const content = [
|
|
2794
|
-
{
|
|
2795
|
-
type: "text",
|
|
2796
|
-
text: result.generation
|
|
2797
|
-
}
|
|
2628
|
+
{ type: "text", text: result.generation }
|
|
2798
2629
|
];
|
|
2799
2630
|
const usage = {
|
|
2800
2631
|
output_tokens: result?.generation_token_count,
|
|
@@ -2808,7 +2639,6 @@ function OutputMetaLlama3Chat(result, _config) {
|
|
|
2808
2639
|
content
|
|
2809
2640
|
});
|
|
2810
2641
|
}
|
|
2811
|
-
__name(OutputMetaLlama3Chat, "OutputMetaLlama3Chat");
|
|
2812
2642
|
|
|
2813
2643
|
// src/llm/output/default.ts
|
|
2814
2644
|
function OutputDefault(result, _config) {
|
|
@@ -2816,10 +2646,7 @@ function OutputDefault(result, _config) {
|
|
|
2816
2646
|
const stopReason = result?.stopReason || "stop";
|
|
2817
2647
|
const content = [];
|
|
2818
2648
|
if (result?.text) {
|
|
2819
|
-
content.push({
|
|
2820
|
-
type: "text",
|
|
2821
|
-
text: result.text
|
|
2822
|
-
});
|
|
2649
|
+
content.push({ type: "text", text: result.text });
|
|
2823
2650
|
}
|
|
2824
2651
|
const usage = {
|
|
2825
2652
|
output_tokens: result?.output_tokens || 0,
|
|
@@ -2833,7 +2660,6 @@ function OutputDefault(result, _config) {
|
|
|
2833
2660
|
content
|
|
2834
2661
|
});
|
|
2835
2662
|
}
|
|
2836
|
-
__name(OutputDefault, "OutputDefault");
|
|
2837
2663
|
|
|
2838
2664
|
// src/llm/output/xai.ts
|
|
2839
2665
|
function formatResult3(result) {
|
|
@@ -2857,7 +2683,6 @@ function formatResult3(result) {
|
|
|
2857
2683
|
text: ""
|
|
2858
2684
|
};
|
|
2859
2685
|
}
|
|
2860
|
-
__name(formatResult3, "formatResult");
|
|
2861
2686
|
function OutputXAIChat(result, _config) {
|
|
2862
2687
|
const id = result.id;
|
|
2863
2688
|
const name = result?.model;
|
|
@@ -2881,7 +2706,6 @@ function OutputXAIChat(result, _config) {
|
|
|
2881
2706
|
options
|
|
2882
2707
|
});
|
|
2883
2708
|
}
|
|
2884
|
-
__name(OutputXAIChat, "OutputXAIChat");
|
|
2885
2709
|
|
|
2886
2710
|
// src/llm/output/_utils/combineJsonl.ts
|
|
2887
2711
|
function combineJsonl(jsonl) {
|
|
@@ -2895,7 +2719,9 @@ function combineJsonl(jsonl) {
|
|
|
2895
2719
|
if (lines.length === 0) {
|
|
2896
2720
|
throw new Error("No JSON lines provided.");
|
|
2897
2721
|
}
|
|
2898
|
-
lines.sort(
|
|
2722
|
+
lines.sort(
|
|
2723
|
+
(a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime()
|
|
2724
|
+
);
|
|
2899
2725
|
let combinedContent = lines.map((line) => line?.message?.content ?? "").join("");
|
|
2900
2726
|
combinedContent = combinedContent.replace(/\\u003c/g, "<").replace(/\\u003e/g, ">");
|
|
2901
2727
|
const finalLine = lines.find((line) => line.done === true);
|
|
@@ -2928,7 +2754,6 @@ function combineJsonl(jsonl) {
|
|
|
2928
2754
|
content
|
|
2929
2755
|
};
|
|
2930
2756
|
}
|
|
2931
|
-
__name(combineJsonl, "combineJsonl");
|
|
2932
2757
|
|
|
2933
2758
|
// src/llm/output/ollama.ts
|
|
2934
2759
|
function OutputOllamaChat(result, _config) {
|
|
@@ -2937,9 +2762,7 @@ function OutputOllamaChat(result, _config) {
|
|
|
2937
2762
|
const name = combined.result.model || _config?.model || "ollama.unknown";
|
|
2938
2763
|
const created = (/* @__PURE__ */ new Date(`${combined.result.created_at}`)).getTime();
|
|
2939
2764
|
const stopReason = `${combined?.result?.done_reason || "stop"}`;
|
|
2940
|
-
const content = [
|
|
2941
|
-
combined.content
|
|
2942
|
-
];
|
|
2765
|
+
const content = [combined.content];
|
|
2943
2766
|
const usage = {
|
|
2944
2767
|
output_tokens: 0,
|
|
2945
2768
|
input_tokens: 0,
|
|
@@ -2955,7 +2778,6 @@ function OutputOllamaChat(result, _config) {
|
|
|
2955
2778
|
options: []
|
|
2956
2779
|
});
|
|
2957
2780
|
}
|
|
2958
|
-
__name(OutputOllamaChat, "OutputOllamaChat");
|
|
2959
2781
|
|
|
2960
2782
|
// src/llm/output/google.gemini/formatResult.ts
|
|
2961
2783
|
function formatResult4(result) {
|
|
@@ -2980,7 +2802,6 @@ function formatResult4(result) {
|
|
|
2980
2802
|
text: ""
|
|
2981
2803
|
};
|
|
2982
2804
|
}
|
|
2983
|
-
__name(formatResult4, "formatResult");
|
|
2984
2805
|
|
|
2985
2806
|
// src/llm/output/google.gemini/index.ts
|
|
2986
2807
|
function OutputGoogleGeminiChat(result, _config) {
|
|
@@ -3006,7 +2827,6 @@ function OutputGoogleGeminiChat(result, _config) {
|
|
|
3006
2827
|
options
|
|
3007
2828
|
});
|
|
3008
2829
|
}
|
|
3009
|
-
__name(OutputGoogleGeminiChat, "OutputGoogleGeminiChat");
|
|
3010
2830
|
|
|
3011
2831
|
// src/llm/output/index.ts
|
|
3012
2832
|
function getOutputParser(config, response) {
|
|
@@ -3038,7 +2858,45 @@ function getOutputParser(config, response) {
|
|
|
3038
2858
|
}
|
|
3039
2859
|
}
|
|
3040
2860
|
}
|
|
3041
|
-
|
|
2861
|
+
|
|
2862
|
+
// src/utils/modules/debug.ts
|
|
2863
|
+
function debug(...args) {
|
|
2864
|
+
const debugValue = getEnvironmentVariable("LLM_EXE_DEBUG");
|
|
2865
|
+
const logs = [];
|
|
2866
|
+
for (const arg of args) {
|
|
2867
|
+
if (arg && typeof arg === "object") {
|
|
2868
|
+
if (arg instanceof Error) {
|
|
2869
|
+
} else if (arg instanceof Array) {
|
|
2870
|
+
logs.push(arg.map((item) => JSON.stringify(item, null, 2)));
|
|
2871
|
+
} else if (arg instanceof Map) {
|
|
2872
|
+
logs.push(
|
|
2873
|
+
Array.from(arg.entries()).map(
|
|
2874
|
+
([key, value]) => `${key}: ${JSON.stringify(value, null, 2)}`
|
|
2875
|
+
)
|
|
2876
|
+
);
|
|
2877
|
+
} else if (arg instanceof Set) {
|
|
2878
|
+
logs.push(Array.from(arg).map((item) => JSON.stringify(item, null, 2)));
|
|
2879
|
+
} else if (arg instanceof Date) {
|
|
2880
|
+
logs.push(arg.toISOString());
|
|
2881
|
+
} else if (arg instanceof RegExp) {
|
|
2882
|
+
logs.push(arg.toString());
|
|
2883
|
+
} else {
|
|
2884
|
+
try {
|
|
2885
|
+
logs.push(JSON.stringify(arg, null, 2));
|
|
2886
|
+
} catch (error) {
|
|
2887
|
+
console.error("Error parsing object:", error);
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
} else if (typeof arg === "string") {
|
|
2891
|
+
logs.push(arg);
|
|
2892
|
+
} else {
|
|
2893
|
+
logs.push(arg);
|
|
2894
|
+
}
|
|
2895
|
+
}
|
|
2896
|
+
if (typeof debugValue === "string" && debugValue !== "" && debugValue.toLowerCase() !== "undefined" && debugValue.toLowerCase() !== "null") {
|
|
2897
|
+
console.debug(...logs);
|
|
2898
|
+
}
|
|
2899
|
+
}
|
|
3042
2900
|
|
|
3043
2901
|
// src/utils/modules/isValidUrl.ts
|
|
3044
2902
|
function isValidUrl(input) {
|
|
@@ -3049,7 +2907,6 @@ function isValidUrl(input) {
|
|
|
3049
2907
|
return false;
|
|
3050
2908
|
}
|
|
3051
2909
|
}
|
|
3052
|
-
__name(isValidUrl, "isValidUrl");
|
|
3053
2910
|
|
|
3054
2911
|
// src/utils/modules/request.ts
|
|
3055
2912
|
async function apiRequest(url, options) {
|
|
@@ -3057,6 +2914,7 @@ async function apiRequest(url, options) {
|
|
|
3057
2914
|
...options
|
|
3058
2915
|
};
|
|
3059
2916
|
try {
|
|
2917
|
+
debug(url, finalOptions);
|
|
3060
2918
|
if (!url || !isValidUrl(url)) {
|
|
3061
2919
|
throw new Error("Invalid URL");
|
|
3062
2920
|
}
|
|
@@ -3084,7 +2942,6 @@ async function apiRequest(url, options) {
|
|
|
3084
2942
|
throw new Error(`Request to ${url} failed: ${message}`);
|
|
3085
2943
|
}
|
|
3086
2944
|
}
|
|
3087
|
-
__name(apiRequest, "apiRequest");
|
|
3088
2945
|
|
|
3089
2946
|
// src/utils/modules/convertDotNotation.ts
|
|
3090
2947
|
function convertDotNotation(obj) {
|
|
@@ -3109,7 +2966,6 @@ function convertDotNotation(obj) {
|
|
|
3109
2966
|
}
|
|
3110
2967
|
return result;
|
|
3111
2968
|
}
|
|
3112
|
-
__name(convertDotNotation, "convertDotNotation");
|
|
3113
2969
|
|
|
3114
2970
|
// src/llm/_utils.mapBody.ts
|
|
3115
2971
|
function mapBody(template, body) {
|
|
@@ -3122,9 +2978,11 @@ function mapBody(template, body) {
|
|
|
3122
2978
|
if (providerSpecificKey) {
|
|
3123
2979
|
let valueForThisKey = body[genericInputKey];
|
|
3124
2980
|
if (providerSpecificSettings.sanitize && typeof providerSpecificSettings.sanitize === "function") {
|
|
3125
|
-
valueForThisKey = providerSpecificSettings.sanitize(
|
|
3126
|
-
|
|
3127
|
-
|
|
2981
|
+
valueForThisKey = providerSpecificSettings.sanitize(
|
|
2982
|
+
valueForThisKey,
|
|
2983
|
+
Object.freeze({ ...body }),
|
|
2984
|
+
output
|
|
2985
|
+
);
|
|
3128
2986
|
}
|
|
3129
2987
|
if (typeof valueForThisKey !== "undefined") {
|
|
3130
2988
|
output[providerSpecificKey] = valueForThisKey;
|
|
@@ -3135,127 +2993,16 @@ function mapBody(template, body) {
|
|
|
3135
2993
|
}
|
|
3136
2994
|
return convertDotNotation(output);
|
|
3137
2995
|
}
|
|
3138
|
-
__name(mapBody, "mapBody");
|
|
3139
2996
|
|
|
3140
2997
|
// src/utils/modules/getAwsAuthorizationHeaders.ts
|
|
3141
2998
|
import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
|
|
3142
2999
|
import { SignatureV4 } from "@smithy/signature-v4";
|
|
3143
|
-
|
|
3144
|
-
// node_modules/@smithy/types/dist-es/auth/auth.js
|
|
3145
|
-
var HttpAuthLocation;
|
|
3146
|
-
(function(HttpAuthLocation2) {
|
|
3147
|
-
HttpAuthLocation2["HEADER"] = "header";
|
|
3148
|
-
HttpAuthLocation2["QUERY"] = "query";
|
|
3149
|
-
})(HttpAuthLocation || (HttpAuthLocation = {}));
|
|
3150
|
-
|
|
3151
|
-
// node_modules/@smithy/types/dist-es/auth/HttpApiKeyAuth.js
|
|
3152
|
-
var HttpApiKeyAuthLocation;
|
|
3153
|
-
(function(HttpApiKeyAuthLocation2) {
|
|
3154
|
-
HttpApiKeyAuthLocation2["HEADER"] = "header";
|
|
3155
|
-
HttpApiKeyAuthLocation2["QUERY"] = "query";
|
|
3156
|
-
})(HttpApiKeyAuthLocation || (HttpApiKeyAuthLocation = {}));
|
|
3157
|
-
|
|
3158
|
-
// node_modules/@smithy/types/dist-es/endpoint.js
|
|
3159
|
-
var EndpointURLScheme;
|
|
3160
|
-
(function(EndpointURLScheme2) {
|
|
3161
|
-
EndpointURLScheme2["HTTP"] = "http";
|
|
3162
|
-
EndpointURLScheme2["HTTPS"] = "https";
|
|
3163
|
-
})(EndpointURLScheme || (EndpointURLScheme = {}));
|
|
3164
|
-
|
|
3165
|
-
// node_modules/@smithy/types/dist-es/extensions/checksum.js
|
|
3166
|
-
var AlgorithmId;
|
|
3167
|
-
(function(AlgorithmId2) {
|
|
3168
|
-
AlgorithmId2["MD5"] = "md5";
|
|
3169
|
-
AlgorithmId2["CRC32"] = "crc32";
|
|
3170
|
-
AlgorithmId2["CRC32C"] = "crc32c";
|
|
3171
|
-
AlgorithmId2["SHA1"] = "sha1";
|
|
3172
|
-
AlgorithmId2["SHA256"] = "sha256";
|
|
3173
|
-
})(AlgorithmId || (AlgorithmId = {}));
|
|
3174
|
-
|
|
3175
|
-
// node_modules/@smithy/types/dist-es/http.js
|
|
3176
|
-
var FieldPosition;
|
|
3177
|
-
(function(FieldPosition2) {
|
|
3178
|
-
FieldPosition2[FieldPosition2["HEADER"] = 0] = "HEADER";
|
|
3179
|
-
FieldPosition2[FieldPosition2["TRAILER"] = 1] = "TRAILER";
|
|
3180
|
-
})(FieldPosition || (FieldPosition = {}));
|
|
3181
|
-
|
|
3182
|
-
// node_modules/@smithy/types/dist-es/profile.js
|
|
3183
|
-
var IniSectionType;
|
|
3184
|
-
(function(IniSectionType2) {
|
|
3185
|
-
IniSectionType2["PROFILE"] = "profile";
|
|
3186
|
-
IniSectionType2["SSO_SESSION"] = "sso-session";
|
|
3187
|
-
IniSectionType2["SERVICES"] = "services";
|
|
3188
|
-
})(IniSectionType || (IniSectionType = {}));
|
|
3189
|
-
|
|
3190
|
-
// node_modules/@smithy/types/dist-es/transfer.js
|
|
3191
|
-
var RequestHandlerProtocol;
|
|
3192
|
-
(function(RequestHandlerProtocol2) {
|
|
3193
|
-
RequestHandlerProtocol2["HTTP_0_9"] = "http/0.9";
|
|
3194
|
-
RequestHandlerProtocol2["HTTP_1_0"] = "http/1.0";
|
|
3195
|
-
RequestHandlerProtocol2["TDS_8_0"] = "tds/8.0";
|
|
3196
|
-
})(RequestHandlerProtocol || (RequestHandlerProtocol = {}));
|
|
3197
|
-
|
|
3198
|
-
// node_modules/@smithy/protocol-http/dist-es/httpRequest.js
|
|
3199
|
-
var _HttpRequest = class _HttpRequest {
|
|
3200
|
-
constructor(options) {
|
|
3201
|
-
this.method = options.method || "GET";
|
|
3202
|
-
this.hostname = options.hostname || "localhost";
|
|
3203
|
-
this.port = options.port;
|
|
3204
|
-
this.query = options.query || {};
|
|
3205
|
-
this.headers = options.headers || {};
|
|
3206
|
-
this.body = options.body;
|
|
3207
|
-
this.protocol = options.protocol ? options.protocol.slice(-1) !== ":" ? `${options.protocol}:` : options.protocol : "https:";
|
|
3208
|
-
this.path = options.path ? options.path.charAt(0) !== "/" ? `/${options.path}` : options.path : "/";
|
|
3209
|
-
this.username = options.username;
|
|
3210
|
-
this.password = options.password;
|
|
3211
|
-
this.fragment = options.fragment;
|
|
3212
|
-
}
|
|
3213
|
-
static clone(request) {
|
|
3214
|
-
const cloned = new _HttpRequest({
|
|
3215
|
-
...request,
|
|
3216
|
-
headers: {
|
|
3217
|
-
...request.headers
|
|
3218
|
-
}
|
|
3219
|
-
});
|
|
3220
|
-
if (cloned.query) {
|
|
3221
|
-
cloned.query = cloneQuery(cloned.query);
|
|
3222
|
-
}
|
|
3223
|
-
return cloned;
|
|
3224
|
-
}
|
|
3225
|
-
static isInstance(request) {
|
|
3226
|
-
if (!request) {
|
|
3227
|
-
return false;
|
|
3228
|
-
}
|
|
3229
|
-
const req = request;
|
|
3230
|
-
return "method" in req && "protocol" in req && "hostname" in req && "path" in req && typeof req["query"] === "object" && typeof req["headers"] === "object";
|
|
3231
|
-
}
|
|
3232
|
-
clone() {
|
|
3233
|
-
return _HttpRequest.clone(this);
|
|
3234
|
-
}
|
|
3235
|
-
};
|
|
3236
|
-
__name(_HttpRequest, "HttpRequest");
|
|
3237
|
-
var HttpRequest = _HttpRequest;
|
|
3238
|
-
function cloneQuery(query) {
|
|
3239
|
-
return Object.keys(query).reduce((carry, paramName) => {
|
|
3240
|
-
const param = query[paramName];
|
|
3241
|
-
return {
|
|
3242
|
-
...carry,
|
|
3243
|
-
[paramName]: Array.isArray(param) ? [
|
|
3244
|
-
...param
|
|
3245
|
-
] : param
|
|
3246
|
-
};
|
|
3247
|
-
}, {});
|
|
3248
|
-
}
|
|
3249
|
-
__name(cloneQuery, "cloneQuery");
|
|
3250
|
-
|
|
3251
|
-
// src/utils/modules/getAwsAuthorizationHeaders.ts
|
|
3000
|
+
import { HttpRequest } from "@smithy/protocol-http";
|
|
3252
3001
|
import { Sha256 } from "@aws-crypto/sha256-js";
|
|
3253
3002
|
|
|
3254
3003
|
// src/utils/modules/runWithTemporaryEnv.ts
|
|
3255
3004
|
async function runWithTemporaryEnv(env, handler) {
|
|
3256
|
-
const previousEnv = {
|
|
3257
|
-
...process.env
|
|
3258
|
-
};
|
|
3005
|
+
const previousEnv = { ...process.env };
|
|
3259
3006
|
try {
|
|
3260
3007
|
env();
|
|
3261
3008
|
const value = await handler();
|
|
@@ -3264,22 +3011,24 @@ async function runWithTemporaryEnv(env, handler) {
|
|
|
3264
3011
|
process.env = previousEnv;
|
|
3265
3012
|
}
|
|
3266
3013
|
}
|
|
3267
|
-
__name(runWithTemporaryEnv, "runWithTemporaryEnv");
|
|
3268
3014
|
|
|
3269
3015
|
// src/utils/modules/getAwsAuthorizationHeaders.ts
|
|
3270
3016
|
async function getAwsAuthorizationHeaders(req, props) {
|
|
3271
3017
|
const providerChain = fromNodeProviderChain();
|
|
3272
|
-
const credentials = await runWithTemporaryEnv(
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3018
|
+
const credentials = await runWithTemporaryEnv(
|
|
3019
|
+
() => {
|
|
3020
|
+
if (props.awsAccessKey) {
|
|
3021
|
+
process.env["AWS_ACCESS_KEY_ID"] = props.awsAccessKey;
|
|
3022
|
+
}
|
|
3023
|
+
if (props.awsSecretKey) {
|
|
3024
|
+
process.env["AWS_SECRET_ACCESS_KEY"] = props.awsSecretKey;
|
|
3025
|
+
}
|
|
3026
|
+
if (props.awsSessionToken) {
|
|
3027
|
+
process.env["AWS_SESSION_TOKEN"] = props.awsSessionToken;
|
|
3028
|
+
}
|
|
3029
|
+
},
|
|
3030
|
+
() => providerChain()
|
|
3031
|
+
);
|
|
3283
3032
|
const signer = new SignatureV4({
|
|
3284
3033
|
service: "bedrock",
|
|
3285
3034
|
region: props.regionName,
|
|
@@ -3287,11 +3036,7 @@ async function getAwsAuthorizationHeaders(req, props) {
|
|
|
3287
3036
|
sha256: Sha256
|
|
3288
3037
|
});
|
|
3289
3038
|
const url = new URL(props.url);
|
|
3290
|
-
const headers = !req.headers ? {} : Symbol.iterator in req.headers ? Object.fromEntries(Array.from(req.headers).map((header) => [
|
|
3291
|
-
...header
|
|
3292
|
-
])) : {
|
|
3293
|
-
...req.headers
|
|
3294
|
-
};
|
|
3039
|
+
const headers = !req.headers ? {} : Symbol.iterator in req.headers ? Object.fromEntries(Array.from(req.headers).map((header) => [...header])) : { ...req.headers };
|
|
3295
3040
|
delete headers["connection"];
|
|
3296
3041
|
headers["host"] = url.hostname;
|
|
3297
3042
|
const request = new HttpRequest({
|
|
@@ -3304,7 +3049,6 @@ async function getAwsAuthorizationHeaders(req, props) {
|
|
|
3304
3049
|
const signed = await signer.sign(request);
|
|
3305
3050
|
return signed.headers;
|
|
3306
3051
|
}
|
|
3307
|
-
__name(getAwsAuthorizationHeaders, "getAwsAuthorizationHeaders");
|
|
3308
3052
|
|
|
3309
3053
|
// src/llm/_utils.parseHeaders.ts
|
|
3310
3054
|
async function parseHeaders(config, replacements, payload) {
|
|
@@ -3313,27 +3057,28 @@ async function parseHeaders(config, replacements, payload) {
|
|
|
3313
3057
|
const headers = Object.assign({}, payload.headers, parse);
|
|
3314
3058
|
if (config.provider.startsWith("amazon:") || config.provider.startsWith("amazon.")) {
|
|
3315
3059
|
const url = payload.url;
|
|
3316
|
-
return getAwsAuthorizationHeaders(
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3060
|
+
return getAwsAuthorizationHeaders(
|
|
3061
|
+
{
|
|
3062
|
+
method: config.method,
|
|
3063
|
+
headers,
|
|
3064
|
+
body: payload.body
|
|
3065
|
+
},
|
|
3066
|
+
{
|
|
3067
|
+
url,
|
|
3068
|
+
regionName: replacements?.awsRegion || getEnvironmentVariable("AWS_REGION"),
|
|
3069
|
+
awsSecretKey: replacements.awsSecretKey,
|
|
3070
|
+
awsAccessKey: replacements.awsAccessKey
|
|
3071
|
+
}
|
|
3072
|
+
);
|
|
3326
3073
|
} else {
|
|
3327
3074
|
return headers;
|
|
3328
3075
|
}
|
|
3329
3076
|
}
|
|
3330
|
-
__name(parseHeaders, "parseHeaders");
|
|
3331
3077
|
|
|
3332
3078
|
// src/llm/output/_utils/cleanJsonSchemaFor.ts
|
|
3333
3079
|
var providerFieldExclusions = {
|
|
3334
|
-
"openai.chat": [
|
|
3335
|
-
|
|
3336
|
-
]
|
|
3080
|
+
"openai.chat": ["default"]
|
|
3081
|
+
// fields to exclude for openai.chat
|
|
3337
3082
|
};
|
|
3338
3083
|
function cleanJsonSchemaFor(schema = {}, provider) {
|
|
3339
3084
|
const clone = deepClone(schema);
|
|
@@ -3351,18 +3096,19 @@ function cleanJsonSchemaFor(schema = {}, provider) {
|
|
|
3351
3096
|
}
|
|
3352
3097
|
return obj;
|
|
3353
3098
|
}
|
|
3354
|
-
__name(removeDisallowedFields, "removeDisallowedFields");
|
|
3355
3099
|
return removeDisallowedFields(clone);
|
|
3356
3100
|
}
|
|
3357
|
-
__name(cleanJsonSchemaFor, "cleanJsonSchemaFor");
|
|
3358
3101
|
|
|
3359
3102
|
// src/llm/llm.call.ts
|
|
3360
3103
|
async function useLlm_call(state, messages, _options) {
|
|
3361
3104
|
const config = getLlmConfig(state.key);
|
|
3362
3105
|
const { functionCallStrictInput = false } = _options || {};
|
|
3363
|
-
const input = mapBody(
|
|
3364
|
-
|
|
3365
|
-
|
|
3106
|
+
const input = mapBody(
|
|
3107
|
+
config.mapBody,
|
|
3108
|
+
Object.assign({}, state, {
|
|
3109
|
+
prompt: messages
|
|
3110
|
+
})
|
|
3111
|
+
);
|
|
3366
3112
|
if (_options && _options?.jsonSchema) {
|
|
3367
3113
|
if (state.provider === "openai.chat") {
|
|
3368
3114
|
const curr = input["response_format"] || {};
|
|
@@ -3381,14 +3127,15 @@ async function useLlm_call(state, messages, _options) {
|
|
|
3381
3127
|
if (_options?.functionCall === "none") {
|
|
3382
3128
|
_options.functions = [];
|
|
3383
3129
|
} else if (_options?.functionCall === "auto" || _options?.functionCall === "any") {
|
|
3384
|
-
input["tool_choice"] = {
|
|
3385
|
-
type: _options?.functionCall
|
|
3386
|
-
};
|
|
3130
|
+
input["tool_choice"] = { type: _options?.functionCall };
|
|
3387
3131
|
} else {
|
|
3388
3132
|
input["tool_choice"] = _options?.functionCall;
|
|
3389
3133
|
}
|
|
3390
3134
|
} else if (state.provider === "openai.chat") {
|
|
3391
|
-
input["tool_choice"] = normalizeFunctionCall(
|
|
3135
|
+
input["tool_choice"] = normalizeFunctionCall(
|
|
3136
|
+
_options?.functionCall,
|
|
3137
|
+
"openai"
|
|
3138
|
+
);
|
|
3392
3139
|
}
|
|
3393
3140
|
}
|
|
3394
3141
|
if (_options && _options?.functions?.length) {
|
|
@@ -3407,11 +3154,13 @@ async function useLlm_call(state, messages, _options) {
|
|
|
3407
3154
|
};
|
|
3408
3155
|
return {
|
|
3409
3156
|
type: "function",
|
|
3410
|
-
function: Object.assign(
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3157
|
+
function: Object.assign(
|
|
3158
|
+
props,
|
|
3159
|
+
{
|
|
3160
|
+
parameters: cleanJsonSchemaFor(props.parameters, "openai.chat")
|
|
3161
|
+
},
|
|
3162
|
+
{ strict: functionCallStrictInput }
|
|
3163
|
+
)
|
|
3415
3164
|
};
|
|
3416
3165
|
});
|
|
3417
3166
|
}
|
|
@@ -3427,16 +3176,14 @@ async function useLlm_call(state, messages, _options) {
|
|
|
3427
3176
|
id: "0123-45-6789",
|
|
3428
3177
|
model: "model",
|
|
3429
3178
|
created: (/* @__PURE__ */ new Date()).getTime(),
|
|
3430
|
-
usage: {
|
|
3431
|
-
completion_tokens: 0,
|
|
3432
|
-
prompt_tokens: 0,
|
|
3433
|
-
total_tokens: 0
|
|
3434
|
-
},
|
|
3179
|
+
usage: { completion_tokens: 0, prompt_tokens: 0, total_tokens: 0 },
|
|
3435
3180
|
choices: [
|
|
3436
3181
|
{
|
|
3437
3182
|
message: {
|
|
3438
3183
|
role: "assistant",
|
|
3439
|
-
content: `Hello world from LLM! The input was ${JSON.stringify(
|
|
3184
|
+
content: `Hello world from LLM! The input was ${JSON.stringify(
|
|
3185
|
+
messages
|
|
3186
|
+
)}`
|
|
3440
3187
|
}
|
|
3441
3188
|
}
|
|
3442
3189
|
]
|
|
@@ -3447,7 +3194,6 @@ async function useLlm_call(state, messages, _options) {
|
|
|
3447
3194
|
});
|
|
3448
3195
|
return getOutputParser(state, response);
|
|
3449
3196
|
}
|
|
3450
|
-
__name(useLlm_call, "useLlm_call");
|
|
3451
3197
|
|
|
3452
3198
|
// src/llm/_utils.stateFromOptions.ts
|
|
3453
3199
|
function stateFromOptions(options, config) {
|
|
@@ -3466,16 +3212,16 @@ function stateFromOptions(options, config) {
|
|
|
3466
3212
|
state[key] = thisConfig.default;
|
|
3467
3213
|
}
|
|
3468
3214
|
}
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3215
|
+
const value = get(state, key);
|
|
3216
|
+
if (Array.isArray(thisConfig?.required)) {
|
|
3217
|
+
const [required, message = `Error: [${key}] is required`] = thisConfig.required;
|
|
3218
|
+
if (required && typeof value === "undefined") {
|
|
3472
3219
|
throw new Error(message);
|
|
3473
3220
|
}
|
|
3474
3221
|
}
|
|
3475
3222
|
}
|
|
3476
3223
|
return state;
|
|
3477
3224
|
}
|
|
3478
|
-
__name(stateFromOptions, "stateFromOptions");
|
|
3479
3225
|
|
|
3480
3226
|
// src/utils/modules/deepFreeze.ts
|
|
3481
3227
|
function deepFreeze(obj) {
|
|
@@ -3492,13 +3238,14 @@ function deepFreeze(obj) {
|
|
|
3492
3238
|
}
|
|
3493
3239
|
if (typeof obj === "object" && obj !== null) {
|
|
3494
3240
|
for (const key of Object.keys(obj)) {
|
|
3495
|
-
obj[key] = deepFreeze(
|
|
3241
|
+
obj[key] = deepFreeze(
|
|
3242
|
+
obj[key]
|
|
3243
|
+
);
|
|
3496
3244
|
}
|
|
3497
3245
|
return Object.freeze(obj);
|
|
3498
3246
|
}
|
|
3499
3247
|
return obj;
|
|
3500
3248
|
}
|
|
3501
|
-
__name(deepFreeze, "deepFreeze");
|
|
3502
3249
|
|
|
3503
3250
|
// src/utils/modules/requestWrapper.ts
|
|
3504
3251
|
import { backOff } from "exponential-backoff";
|
|
@@ -3519,19 +3266,29 @@ function apiRequestWrapper(config, options, handler, doNotRetryErrorMessages = [
|
|
|
3519
3266
|
async function call(messages, options2) {
|
|
3520
3267
|
try {
|
|
3521
3268
|
metrics.total_calls++;
|
|
3522
|
-
const result = await backOff(
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3269
|
+
const result = await backOff(
|
|
3270
|
+
() => asyncCallWithTimeout(
|
|
3271
|
+
handler(
|
|
3272
|
+
deepFreeze(state),
|
|
3273
|
+
deepFreeze(messages),
|
|
3274
|
+
deepFreeze(options2)
|
|
3275
|
+
),
|
|
3276
|
+
timeout
|
|
3277
|
+
),
|
|
3278
|
+
{
|
|
3279
|
+
startingDelay: 0,
|
|
3280
|
+
maxDelay,
|
|
3281
|
+
numOfAttempts,
|
|
3282
|
+
jitter,
|
|
3283
|
+
retry: (_error, _stepNumber) => {
|
|
3284
|
+
if (doNotRetryErrorMessages.includes(_error.message)) {
|
|
3285
|
+
return false;
|
|
3286
|
+
}
|
|
3287
|
+
metrics.total_call_retry++;
|
|
3288
|
+
return true;
|
|
3530
3289
|
}
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
}, "retry")
|
|
3534
|
-
});
|
|
3290
|
+
}
|
|
3291
|
+
);
|
|
3535
3292
|
metrics.total_call_success++;
|
|
3536
3293
|
return result;
|
|
3537
3294
|
} catch (error) {
|
|
@@ -3539,29 +3296,32 @@ function apiRequestWrapper(config, options, handler, doNotRetryErrorMessages = [
|
|
|
3539
3296
|
throw error;
|
|
3540
3297
|
}
|
|
3541
3298
|
}
|
|
3542
|
-
__name(call, "call");
|
|
3543
3299
|
function getMetadata() {
|
|
3544
|
-
const {
|
|
3545
|
-
|
|
3546
|
-
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
3300
|
+
const {
|
|
3301
|
+
awsSecretKey,
|
|
3302
|
+
awsAccessKey,
|
|
3303
|
+
openAiApiKey,
|
|
3304
|
+
anthropicApiKey,
|
|
3305
|
+
...rest
|
|
3306
|
+
} = options;
|
|
3307
|
+
return Object.assign(
|
|
3308
|
+
{
|
|
3309
|
+
traceId: getTraceId(),
|
|
3310
|
+
timeout,
|
|
3311
|
+
jitter,
|
|
3312
|
+
maxDelay,
|
|
3313
|
+
numOfAttempts,
|
|
3314
|
+
metrics: { ...metrics }
|
|
3315
|
+
},
|
|
3316
|
+
rest
|
|
3317
|
+
);
|
|
3555
3318
|
}
|
|
3556
|
-
__name(getMetadata, "getMetadata");
|
|
3557
3319
|
function getTraceId() {
|
|
3558
3320
|
return traceId;
|
|
3559
3321
|
}
|
|
3560
|
-
__name(getTraceId, "getTraceId");
|
|
3561
3322
|
function withTraceId(id) {
|
|
3562
3323
|
traceId = id;
|
|
3563
3324
|
}
|
|
3564
|
-
__name(withTraceId, "withTraceId");
|
|
3565
3325
|
return {
|
|
3566
3326
|
call,
|
|
3567
3327
|
getTraceId,
|
|
@@ -3569,14 +3329,12 @@ function apiRequestWrapper(config, options, handler, doNotRetryErrorMessages = [
|
|
|
3569
3329
|
getMetadata
|
|
3570
3330
|
};
|
|
3571
3331
|
}
|
|
3572
|
-
__name(apiRequestWrapper, "apiRequestWrapper");
|
|
3573
3332
|
|
|
3574
3333
|
// src/llm/llm.ts
|
|
3575
3334
|
function useLlm(provider, options = {}) {
|
|
3576
3335
|
const config = getLlmConfig(provider);
|
|
3577
3336
|
return apiRequestWrapper(config, options, useLlm_call);
|
|
3578
3337
|
}
|
|
3579
|
-
__name(useLlm, "useLlm");
|
|
3580
3338
|
|
|
3581
3339
|
// src/embedding/config.ts
|
|
3582
3340
|
var embeddingConfigs = {
|
|
@@ -3624,10 +3382,7 @@ var embeddingConfigs = {
|
|
|
3624
3382
|
},
|
|
3625
3383
|
awsRegion: {
|
|
3626
3384
|
default: getEnvironmentVariable("AWS_REGION"),
|
|
3627
|
-
required: [
|
|
3628
|
-
true,
|
|
3629
|
-
"aws region is required"
|
|
3630
|
-
]
|
|
3385
|
+
required: [true, "aws region is required"]
|
|
3631
3386
|
},
|
|
3632
3387
|
awsSecretKey: {},
|
|
3633
3388
|
awsAccessKey: {}
|
|
@@ -3652,7 +3407,6 @@ function getEmbeddingConfig(provider) {
|
|
|
3652
3407
|
}
|
|
3653
3408
|
throw new Error(`Invalid provider: ${provider}`);
|
|
3654
3409
|
}
|
|
3655
|
-
__name(getEmbeddingConfig, "getEmbeddingConfig");
|
|
3656
3410
|
|
|
3657
3411
|
// src/embedding/output/BaseEmbeddingOutput.ts
|
|
3658
3412
|
function BaseEmbeddingOutput(result) {
|
|
@@ -3660,9 +3414,7 @@ function BaseEmbeddingOutput(result) {
|
|
|
3660
3414
|
id: result.id || uuidv4(),
|
|
3661
3415
|
model: result.model,
|
|
3662
3416
|
usage: result.usage,
|
|
3663
|
-
embedding: [
|
|
3664
|
-
...result?.embedding || []
|
|
3665
|
-
],
|
|
3417
|
+
embedding: [...result?.embedding || []],
|
|
3666
3418
|
created: result?.created || (/* @__PURE__ */ new Date()).getTime()
|
|
3667
3419
|
});
|
|
3668
3420
|
function getResult() {
|
|
@@ -3674,7 +3426,6 @@ function BaseEmbeddingOutput(result) {
|
|
|
3674
3426
|
embedding: __result.embedding
|
|
3675
3427
|
};
|
|
3676
3428
|
}
|
|
3677
|
-
__name(getResult, "getResult");
|
|
3678
3429
|
function getEmbedding(index) {
|
|
3679
3430
|
if (index && index > 0) {
|
|
3680
3431
|
const arr = __result?.embedding;
|
|
@@ -3683,22 +3434,18 @@ function BaseEmbeddingOutput(result) {
|
|
|
3683
3434
|
}
|
|
3684
3435
|
return __result.embedding[0];
|
|
3685
3436
|
}
|
|
3686
|
-
__name(getEmbedding, "getEmbedding");
|
|
3687
3437
|
return {
|
|
3688
3438
|
getEmbedding,
|
|
3689
3439
|
getResult
|
|
3690
3440
|
};
|
|
3691
3441
|
}
|
|
3692
|
-
__name(BaseEmbeddingOutput, "BaseEmbeddingOutput");
|
|
3693
3442
|
|
|
3694
3443
|
// src/embedding/output/AmazonTitan.ts
|
|
3695
3444
|
function AmazonTitanEmbedding(result, config) {
|
|
3696
3445
|
const __result = deepClone(result);
|
|
3697
3446
|
const model = config.model || "amazon.unknown";
|
|
3698
3447
|
const created = (/* @__PURE__ */ new Date()).getTime();
|
|
3699
|
-
const embedding = [
|
|
3700
|
-
__result.embedding
|
|
3701
|
-
];
|
|
3448
|
+
const embedding = [__result.embedding];
|
|
3702
3449
|
const usage = {
|
|
3703
3450
|
output_tokens: 0,
|
|
3704
3451
|
input_tokens: __result.inputTextTokenCount,
|
|
@@ -3711,7 +3458,6 @@ function AmazonTitanEmbedding(result, config) {
|
|
|
3711
3458
|
embedding
|
|
3712
3459
|
});
|
|
3713
3460
|
}
|
|
3714
|
-
__name(AmazonTitanEmbedding, "AmazonTitanEmbedding");
|
|
3715
3461
|
|
|
3716
3462
|
// src/embedding/output/OpenAiEmbedding.ts
|
|
3717
3463
|
function OpenAiEmbedding(result, config) {
|
|
@@ -3732,7 +3478,6 @@ function OpenAiEmbedding(result, config) {
|
|
|
3732
3478
|
embedding
|
|
3733
3479
|
});
|
|
3734
3480
|
}
|
|
3735
|
-
__name(OpenAiEmbedding, "OpenAiEmbedding");
|
|
3736
3481
|
|
|
3737
3482
|
// src/embedding/output/getEmbeddingOutputParser.ts
|
|
3738
3483
|
function getEmbeddingOutputParser(config, response) {
|
|
@@ -3745,14 +3490,16 @@ function getEmbeddingOutputParser(config, response) {
|
|
|
3745
3490
|
throw new Error("Unsupported provider");
|
|
3746
3491
|
}
|
|
3747
3492
|
}
|
|
3748
|
-
__name(getEmbeddingOutputParser, "getEmbeddingOutputParser");
|
|
3749
3493
|
|
|
3750
3494
|
// src/embedding/embedding.call.ts
|
|
3751
3495
|
async function createEmbedding_call(state, _input, _options) {
|
|
3752
3496
|
const config = getEmbeddingConfig(state.key);
|
|
3753
|
-
const input = mapBody(
|
|
3754
|
-
|
|
3755
|
-
|
|
3497
|
+
const input = mapBody(
|
|
3498
|
+
config.mapBody,
|
|
3499
|
+
Object.assign({}, state, {
|
|
3500
|
+
input: _input
|
|
3501
|
+
})
|
|
3502
|
+
);
|
|
3756
3503
|
const body = JSON.stringify(input);
|
|
3757
3504
|
const url = replaceTemplateStringSimple(config.endpoint, state);
|
|
3758
3505
|
const headers = await parseHeaders(config, state, {
|
|
@@ -3767,21 +3514,19 @@ async function createEmbedding_call(state, _input, _options) {
|
|
|
3767
3514
|
});
|
|
3768
3515
|
return getEmbeddingOutputParser(state, request);
|
|
3769
3516
|
}
|
|
3770
|
-
__name(createEmbedding_call, "createEmbedding_call");
|
|
3771
3517
|
|
|
3772
3518
|
// src/embedding/embedding.ts
|
|
3773
3519
|
function createEmbedding(provider, options) {
|
|
3774
3520
|
const config = getEmbeddingConfig(provider);
|
|
3775
3521
|
return apiRequestWrapper(config, options, createEmbedding_call);
|
|
3776
3522
|
}
|
|
3777
|
-
__name(createEmbedding, "createEmbedding");
|
|
3778
3523
|
|
|
3779
3524
|
// src/prompt/_base.ts
|
|
3780
|
-
var
|
|
3525
|
+
var BasePrompt = class {
|
|
3781
3526
|
/**
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3527
|
+
* constructor description
|
|
3528
|
+
* @param initialPromptMessage An initial message to add to the prompt.
|
|
3529
|
+
*/
|
|
3785
3530
|
constructor(initialPromptMessage, options) {
|
|
3786
3531
|
__publicField(this, "type", "text");
|
|
3787
3532
|
__publicField(this, "messages", []);
|
|
@@ -3815,11 +3560,11 @@ var _BasePrompt = class _BasePrompt {
|
|
|
3815
3560
|
}
|
|
3816
3561
|
}
|
|
3817
3562
|
/**
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3563
|
+
* addToPrompt description
|
|
3564
|
+
* @param content The message content
|
|
3565
|
+
* @param role The role of the user. Defaults to system for base text prompt.
|
|
3566
|
+
* @return instance of BasePrompt.
|
|
3567
|
+
*/
|
|
3823
3568
|
addToPrompt(content, role = "system") {
|
|
3824
3569
|
if (content) {
|
|
3825
3570
|
switch (role) {
|
|
@@ -3832,10 +3577,10 @@ var _BasePrompt = class _BasePrompt {
|
|
|
3832
3577
|
return this;
|
|
3833
3578
|
}
|
|
3834
3579
|
/**
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3580
|
+
* addSystemMessage description
|
|
3581
|
+
* @param content The message content
|
|
3582
|
+
* @return returns BasePrompt so it can be chained.
|
|
3583
|
+
*/
|
|
3839
3584
|
addSystemMessage(content) {
|
|
3840
3585
|
this.messages.push({
|
|
3841
3586
|
role: "system",
|
|
@@ -3844,58 +3589,62 @@ var _BasePrompt = class _BasePrompt {
|
|
|
3844
3589
|
return this;
|
|
3845
3590
|
}
|
|
3846
3591
|
/**
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3592
|
+
* registerPartial description
|
|
3593
|
+
* @param partialOrPartials Additional partials that can be made available to the template parser.
|
|
3594
|
+
* @return BasePrompt so it can be chained.
|
|
3595
|
+
*/
|
|
3851
3596
|
registerPartial(partialOrPartials) {
|
|
3852
|
-
const partials2 = Array.isArray(partialOrPartials) ? partialOrPartials : [
|
|
3853
|
-
partialOrPartials
|
|
3854
|
-
];
|
|
3597
|
+
const partials2 = Array.isArray(partialOrPartials) ? partialOrPartials : [partialOrPartials];
|
|
3855
3598
|
this.partials.push(...partials2);
|
|
3856
3599
|
return this;
|
|
3857
3600
|
}
|
|
3858
3601
|
/**
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3602
|
+
* registerHelpers description
|
|
3603
|
+
* @param helperOrHelpers Additional helper functions that can be made available to the template parser.
|
|
3604
|
+
* @return BasePrompt so it can be chained.
|
|
3605
|
+
*/
|
|
3863
3606
|
registerHelpers(helperOrHelpers) {
|
|
3864
|
-
const helpers = Array.isArray(helperOrHelpers) ? helperOrHelpers : [
|
|
3865
|
-
helperOrHelpers
|
|
3866
|
-
];
|
|
3607
|
+
const helpers = Array.isArray(helperOrHelpers) ? helperOrHelpers : [helperOrHelpers];
|
|
3867
3608
|
this.helpers.push(...helpers);
|
|
3868
3609
|
return this;
|
|
3869
3610
|
}
|
|
3870
3611
|
/**
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
3612
|
+
* format description
|
|
3613
|
+
* @param values The message content
|
|
3614
|
+
* @param separator The separator between messages. defaults to "\n\n"
|
|
3615
|
+
* @return returns messages formatted with template replacement
|
|
3616
|
+
*/
|
|
3876
3617
|
format(values, separator = "\n\n") {
|
|
3877
3618
|
const replacements = this.getReplacements(values);
|
|
3878
3619
|
const messages = this.messages.map((message) => {
|
|
3879
|
-
return message.content && !Array.isArray(message.content) ? this.replaceTemplateString(
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3620
|
+
return message.content && !Array.isArray(message.content) ? this.replaceTemplateString(
|
|
3621
|
+
this.runPromptFilter(message.content, this.filters.pre, values),
|
|
3622
|
+
replacements,
|
|
3623
|
+
{
|
|
3624
|
+
partials: this.partials,
|
|
3625
|
+
helpers: this.helpers
|
|
3626
|
+
}
|
|
3627
|
+
) : "";
|
|
3883
3628
|
}).join(separator);
|
|
3884
3629
|
return this.runPromptFilter(messages, this.filters.post, values);
|
|
3885
3630
|
}
|
|
3886
3631
|
/**
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3632
|
+
* format description
|
|
3633
|
+
* @param values The message content
|
|
3634
|
+
* @param separator The separator between messages. defaults to "\n\n"
|
|
3635
|
+
* @return returns messages formatted with template replacement
|
|
3636
|
+
*/
|
|
3892
3637
|
async formatAsync(values, separator = "\n\n") {
|
|
3893
3638
|
const replacements = this.getReplacements(values);
|
|
3894
3639
|
const _messages = await Promise.all(this.messages.map((message) => {
|
|
3895
|
-
return message.content && !Array.isArray(message.content) ? this.replaceTemplateStringAsync(
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3640
|
+
return message.content && !Array.isArray(message.content) ? this.replaceTemplateStringAsync(
|
|
3641
|
+
this.runPromptFilter(message.content, this.filters.pre, values),
|
|
3642
|
+
replacements,
|
|
3643
|
+
{
|
|
3644
|
+
partials: this.partials,
|
|
3645
|
+
helpers: this.helpers
|
|
3646
|
+
}
|
|
3647
|
+
) : "";
|
|
3899
3648
|
}));
|
|
3900
3649
|
const messages = _messages.join(separator);
|
|
3901
3650
|
return this.runPromptFilter(messages, this.filters.post, values);
|
|
@@ -3909,33 +3658,31 @@ var _BasePrompt = class _BasePrompt {
|
|
|
3909
3658
|
}
|
|
3910
3659
|
getReplacements(values) {
|
|
3911
3660
|
const { input = "", ...restOfValues } = values;
|
|
3912
|
-
const replacements = Object.assign(
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3661
|
+
const replacements = Object.assign(
|
|
3662
|
+
{},
|
|
3663
|
+
{ ...restOfValues },
|
|
3664
|
+
{
|
|
3665
|
+
input,
|
|
3666
|
+
_input: input
|
|
3667
|
+
}
|
|
3668
|
+
);
|
|
3918
3669
|
return replacements;
|
|
3919
3670
|
}
|
|
3920
3671
|
/**
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3672
|
+
* validate description
|
|
3673
|
+
* @return {boolean} Returns false if the template is not valid.
|
|
3674
|
+
*/
|
|
3924
3675
|
validate() {
|
|
3925
3676
|
return true;
|
|
3926
3677
|
}
|
|
3927
3678
|
};
|
|
3928
|
-
__name(_BasePrompt, "BasePrompt");
|
|
3929
|
-
var BasePrompt = _BasePrompt;
|
|
3930
3679
|
|
|
3931
3680
|
// src/prompt/text.ts
|
|
3932
|
-
var
|
|
3681
|
+
var TextPrompt = class extends BasePrompt {
|
|
3933
3682
|
constructor(base, options) {
|
|
3934
3683
|
super(base, options);
|
|
3935
3684
|
}
|
|
3936
3685
|
};
|
|
3937
|
-
__name(_TextPrompt, "TextPrompt");
|
|
3938
|
-
var TextPrompt = _TextPrompt;
|
|
3939
3686
|
|
|
3940
3687
|
// src/utils/modules/unescape.ts
|
|
3941
3688
|
function unescape(str) {
|
|
@@ -3949,13 +3696,10 @@ function unescape(str) {
|
|
|
3949
3696
|
const entityRegex = /&|<|>|"|'/g;
|
|
3950
3697
|
return str.replace(entityRegex, (m) => map[m]);
|
|
3951
3698
|
}
|
|
3952
|
-
__name(unescape, "unescape");
|
|
3953
3699
|
|
|
3954
3700
|
// src/utils/modules/extractPromptPlaceholderToken.ts
|
|
3955
3701
|
function extractPromptPlaceholderToken(tok) {
|
|
3956
|
-
if (!tok) return {
|
|
3957
|
-
token: ""
|
|
3958
|
-
};
|
|
3702
|
+
if (!tok) return { token: "" };
|
|
3959
3703
|
const token = tok.replace(/ /g, "");
|
|
3960
3704
|
if (token.substring(2, 18) === ">DialogueHistory") {
|
|
3961
3705
|
const matchKey = tok.match(/key=(['"`])((?:(?!\1).)*)\1/);
|
|
@@ -3982,11 +3726,8 @@ function extractPromptPlaceholderToken(tok) {
|
|
|
3982
3726
|
};
|
|
3983
3727
|
}
|
|
3984
3728
|
}
|
|
3985
|
-
return {
|
|
3986
|
-
token: ""
|
|
3987
|
-
};
|
|
3729
|
+
return { token: "" };
|
|
3988
3730
|
}
|
|
3989
|
-
__name(extractPromptPlaceholderToken, "extractPromptPlaceholderToken");
|
|
3990
3731
|
|
|
3991
3732
|
// src/utils/modules/escape.ts
|
|
3992
3733
|
function escape(str) {
|
|
@@ -3999,29 +3740,28 @@ function escape(str) {
|
|
|
3999
3740
|
};
|
|
4000
3741
|
return str.replace(/[&<>"']/g, (m) => map[m]);
|
|
4001
3742
|
}
|
|
4002
|
-
__name(escape, "escape");
|
|
4003
3743
|
|
|
4004
3744
|
// src/prompt/chat.ts
|
|
4005
|
-
var
|
|
3745
|
+
var ChatPrompt = class extends BasePrompt {
|
|
4006
3746
|
/**
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
3747
|
+
* new `ChatPrompt`
|
|
3748
|
+
* @param initialSystemPromptMessage (optional) An initial system message to add to the new prompt.
|
|
3749
|
+
* @param options (optional) Options to pass in when creating the prompt.
|
|
3750
|
+
*/
|
|
4011
3751
|
constructor(initialSystemPromptMessage, options) {
|
|
4012
3752
|
super(initialSystemPromptMessage, options);
|
|
4013
3753
|
/**
|
|
4014
|
-
|
|
4015
|
-
|
|
3754
|
+
* @property type - Prompt type (chat)
|
|
3755
|
+
*/
|
|
4016
3756
|
__publicField(this, "type", "chat");
|
|
4017
3757
|
/**
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
__publicField(this, "parseUserTemplates",
|
|
4023
|
-
if (options?.allowUnsafeUserTemplate) {
|
|
4024
|
-
this.parseUserTemplates =
|
|
3758
|
+
* @property parseUserTemplates - Whether or not to allow parsing
|
|
3759
|
+
* user messages with the template engine. This could be a risk,
|
|
3760
|
+
* so we only parse user messages if explicitly set.
|
|
3761
|
+
*/
|
|
3762
|
+
__publicField(this, "parseUserTemplates", true);
|
|
3763
|
+
if (typeof options?.allowUnsafeUserTemplate === "boolean") {
|
|
3764
|
+
this.parseUserTemplates = options?.allowUnsafeUserTemplate;
|
|
4025
3765
|
}
|
|
4026
3766
|
}
|
|
4027
3767
|
addToPrompt(content, role, name) {
|
|
@@ -4042,21 +3782,18 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4042
3782
|
break;
|
|
4043
3783
|
case "function_call":
|
|
4044
3784
|
assert(name, "Function message requires name");
|
|
4045
|
-
this.addFunctionCallMessage({
|
|
4046
|
-
name,
|
|
4047
|
-
arguments: content
|
|
4048
|
-
});
|
|
3785
|
+
this.addFunctionCallMessage({ name, arguments: content });
|
|
4049
3786
|
break;
|
|
4050
3787
|
}
|
|
4051
3788
|
}
|
|
4052
3789
|
return this;
|
|
4053
3790
|
}
|
|
4054
3791
|
/**
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
3792
|
+
* addUserMessage Helper to add a user message to the prompt.
|
|
3793
|
+
* @param content The message content.
|
|
3794
|
+
* @param name (optional) The name of the user.
|
|
3795
|
+
* @return instance of ChatPrompt.
|
|
3796
|
+
*/
|
|
4060
3797
|
addUserMessage(content, name) {
|
|
4061
3798
|
const message = {
|
|
4062
3799
|
role: "user",
|
|
@@ -4069,10 +3806,10 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4069
3806
|
return this;
|
|
4070
3807
|
}
|
|
4071
3808
|
/**
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
3809
|
+
* addAssistantMessage Helper to add an assistant message to the prompt.
|
|
3810
|
+
* @param content The message content.
|
|
3811
|
+
* @return ChatPrompt so it can be chained.
|
|
3812
|
+
*/
|
|
4076
3813
|
addAssistantMessage(content) {
|
|
4077
3814
|
this.messages.push({
|
|
4078
3815
|
role: "assistant",
|
|
@@ -4081,10 +3818,10 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4081
3818
|
return this;
|
|
4082
3819
|
}
|
|
4083
3820
|
/**
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
3821
|
+
* addFunctionMessage Helper to add an assistant message to the prompt.
|
|
3822
|
+
* @param content The message content.
|
|
3823
|
+
* @return ChatPrompt so it can be chained.
|
|
3824
|
+
*/
|
|
4088
3825
|
addFunctionMessage(content, name) {
|
|
4089
3826
|
this.messages.push({
|
|
4090
3827
|
role: "function",
|
|
@@ -4094,10 +3831,10 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4094
3831
|
return this;
|
|
4095
3832
|
}
|
|
4096
3833
|
/**
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
3834
|
+
* addFunctionCallMessage Helper to add an assistant message to the prompt.
|
|
3835
|
+
* @param content The message content.
|
|
3836
|
+
* @return ChatPrompt so it can be chained.
|
|
3837
|
+
*/
|
|
4101
3838
|
addFunctionCallMessage(function_call) {
|
|
4102
3839
|
if (function_call) {
|
|
4103
3840
|
this.messages.push({
|
|
@@ -4112,10 +3849,10 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4112
3849
|
return this;
|
|
4113
3850
|
}
|
|
4114
3851
|
/**
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
3852
|
+
* addFromHistory Adds multiple messages at one time.
|
|
3853
|
+
* @param history History of chat messages.
|
|
3854
|
+
* @return ChatPrompt so it can be chained.
|
|
3855
|
+
*/
|
|
4119
3856
|
addFromHistory(history) {
|
|
4120
3857
|
if (history && Array.isArray(history)) {
|
|
4121
3858
|
for (const message of history) {
|
|
@@ -4142,15 +3879,13 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4142
3879
|
return this;
|
|
4143
3880
|
}
|
|
4144
3881
|
/**
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
3882
|
+
* addPlaceholder description
|
|
3883
|
+
* @param content The message content
|
|
3884
|
+
* @return returns ChatPrompt so it can be chained.
|
|
3885
|
+
*/
|
|
4149
3886
|
addChatHistoryPlaceholder(key, options) {
|
|
4150
3887
|
const start = `{{> DialogueHistory `;
|
|
4151
|
-
const params = [
|
|
4152
|
-
`key='${String(key)}'`
|
|
4153
|
-
];
|
|
3888
|
+
const params = [`key='${String(key)}'`];
|
|
4154
3889
|
const end = `}}`;
|
|
4155
3890
|
if (options?.assistant) {
|
|
4156
3891
|
params.push(`assistant='${options.assistant}'`);
|
|
@@ -4165,17 +3900,14 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4165
3900
|
return this;
|
|
4166
3901
|
}
|
|
4167
3902
|
/**
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
3903
|
+
* addTokenPlaceholder description
|
|
3904
|
+
* @param content The message content
|
|
3905
|
+
* @return returns ChatPrompt so it can be chained.
|
|
3906
|
+
*/
|
|
4172
3907
|
addMessagePlaceholder(content, role = "user", name) {
|
|
4173
3908
|
if (content) {
|
|
4174
3909
|
const start = `{{> SingleChatMessage `;
|
|
4175
|
-
const params = [
|
|
4176
|
-
`role='${role}'`,
|
|
4177
|
-
`content='${escape(content)}'`
|
|
4178
|
-
];
|
|
3910
|
+
const params = [`role='${role}'`, `content='${escape(content)}'`];
|
|
4179
3911
|
const end = `}}`;
|
|
4180
3912
|
if (name) {
|
|
4181
3913
|
params.push(`name='${name}'`);
|
|
@@ -4195,11 +3927,7 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4195
3927
|
for (const message of history) {
|
|
4196
3928
|
switch (message.role) {
|
|
4197
3929
|
case "user": {
|
|
4198
|
-
const m = pick(message, [
|
|
4199
|
-
"role",
|
|
4200
|
-
"content",
|
|
4201
|
-
"name"
|
|
4202
|
-
]);
|
|
3930
|
+
const m = pick(message, ["role", "content", "name"]);
|
|
4203
3931
|
if (user) {
|
|
4204
3932
|
m["name"] = user;
|
|
4205
3933
|
}
|
|
@@ -4240,19 +3968,16 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4240
3968
|
return messagesOut;
|
|
4241
3969
|
}
|
|
4242
3970
|
/**
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
3971
|
+
* format formats the stored prompt based on input values.
|
|
3972
|
+
* Uses template engine.
|
|
3973
|
+
* Output is intended for LLM.
|
|
3974
|
+
* @param values input values.
|
|
3975
|
+
* @return formatted prompt.
|
|
3976
|
+
*/
|
|
4249
3977
|
format(values) {
|
|
4250
3978
|
const messagesOut = [];
|
|
4251
3979
|
const replacements = this.getReplacements(values);
|
|
4252
|
-
const safeToParseTemplate = [
|
|
4253
|
-
"assistant",
|
|
4254
|
-
"system"
|
|
4255
|
-
];
|
|
3980
|
+
const safeToParseTemplate = ["assistant", "system"];
|
|
4256
3981
|
if (this.parseUserTemplates) {
|
|
4257
3982
|
safeToParseTemplate.push("user");
|
|
4258
3983
|
}
|
|
@@ -4261,7 +3986,12 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4261
3986
|
const tokenData = extractPromptPlaceholderToken(message.content);
|
|
4262
3987
|
switch (tokenData.token) {
|
|
4263
3988
|
case ">DialogueHistory": {
|
|
4264
|
-
messagesOut.push(
|
|
3989
|
+
messagesOut.push(
|
|
3990
|
+
...this._format_placeholderDialogueHistory(
|
|
3991
|
+
tokenData,
|
|
3992
|
+
replacements
|
|
3993
|
+
)
|
|
3994
|
+
);
|
|
4265
3995
|
break;
|
|
4266
3996
|
}
|
|
4267
3997
|
case ">SingleChatMessage": {
|
|
@@ -4284,70 +4014,103 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4284
4014
|
}
|
|
4285
4015
|
}
|
|
4286
4016
|
} else if (message.role === "function") {
|
|
4287
|
-
messagesOut.push(
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4017
|
+
messagesOut.push(
|
|
4018
|
+
Object.assign({}, message, {
|
|
4019
|
+
content: this.replaceTemplateString(message.content, replacements, {
|
|
4020
|
+
partials: this.partials,
|
|
4021
|
+
helpers: this.helpers
|
|
4022
|
+
})
|
|
4291
4023
|
})
|
|
4292
|
-
|
|
4024
|
+
);
|
|
4293
4025
|
} else {
|
|
4294
4026
|
if (safeToParseTemplate.includes(message.role)) {
|
|
4295
4027
|
if (Array.isArray(message.content)) {
|
|
4296
|
-
const content = message.content.map(
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
|
|
4028
|
+
const content = message.content.map(
|
|
4029
|
+
(m) => m.text ? {
|
|
4030
|
+
type: "text",
|
|
4031
|
+
text: this.runPromptFilter(
|
|
4032
|
+
this.replaceTemplateString(
|
|
4033
|
+
this.runPromptFilter(m.text, this.filters.pre, values),
|
|
4034
|
+
replacements,
|
|
4035
|
+
{
|
|
4036
|
+
partials: this.partials,
|
|
4037
|
+
helpers: this.helpers
|
|
4038
|
+
}
|
|
4039
|
+
),
|
|
4040
|
+
this.filters.post,
|
|
4041
|
+
values
|
|
4042
|
+
)
|
|
4043
|
+
} : m
|
|
4044
|
+
);
|
|
4045
|
+
messagesOut.push(Object.assign({}, message, { content }));
|
|
4306
4046
|
} else if (message.content) {
|
|
4307
|
-
const content = this.runPromptFilter(
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4047
|
+
const content = this.runPromptFilter(
|
|
4048
|
+
this.replaceTemplateString(
|
|
4049
|
+
this.runPromptFilter(message.content, this.filters.pre, values),
|
|
4050
|
+
replacements,
|
|
4051
|
+
{
|
|
4052
|
+
partials: this.partials,
|
|
4053
|
+
helpers: this.helpers
|
|
4054
|
+
}
|
|
4055
|
+
),
|
|
4056
|
+
this.filters.post,
|
|
4057
|
+
values
|
|
4058
|
+
);
|
|
4059
|
+
messagesOut.push(Object.assign({}, message, { content }));
|
|
4314
4060
|
} else {
|
|
4315
|
-
messagesOut.push(Object.assign({}, message, {
|
|
4316
|
-
content: null
|
|
4317
|
-
}));
|
|
4061
|
+
messagesOut.push(Object.assign({}, message, { content: null }));
|
|
4318
4062
|
}
|
|
4319
4063
|
} else {
|
|
4320
|
-
messagesOut.push(
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4064
|
+
messagesOut.push(
|
|
4065
|
+
Object.assign({}, message, {
|
|
4066
|
+
content: Array.isArray(message.content) ? message.content.map(
|
|
4067
|
+
(m) => m.text ? {
|
|
4068
|
+
type: "text",
|
|
4069
|
+
text: this.runPromptFilter(
|
|
4070
|
+
this.runPromptFilter(
|
|
4071
|
+
m.text,
|
|
4072
|
+
this.filters.pre,
|
|
4073
|
+
values
|
|
4074
|
+
),
|
|
4075
|
+
this.filters.post,
|
|
4076
|
+
values
|
|
4077
|
+
)
|
|
4078
|
+
} : m
|
|
4079
|
+
) : message.content && !Array.isArray(message.content) ? this.runPromptFilter(
|
|
4080
|
+
this.runPromptFilter(
|
|
4081
|
+
message.content,
|
|
4082
|
+
this.filters.pre,
|
|
4083
|
+
values
|
|
4084
|
+
),
|
|
4085
|
+
this.filters.post,
|
|
4086
|
+
values
|
|
4087
|
+
) : null
|
|
4088
|
+
})
|
|
4089
|
+
);
|
|
4326
4090
|
}
|
|
4327
4091
|
}
|
|
4328
4092
|
}
|
|
4329
4093
|
return messagesOut;
|
|
4330
4094
|
}
|
|
4331
4095
|
/**
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4096
|
+
* format formats the stored prompt based on input values.
|
|
4097
|
+
* Uses template engine.
|
|
4098
|
+
* Output is intended for LLM.
|
|
4099
|
+
* @param values input values.
|
|
4100
|
+
* @return formatted prompt.
|
|
4101
|
+
*/
|
|
4338
4102
|
async formatAsync(values) {
|
|
4339
4103
|
const messagesOut = [];
|
|
4340
4104
|
const replacements = this.getReplacements(values);
|
|
4341
|
-
const safeToParseTemplate = [
|
|
4342
|
-
"assistant",
|
|
4343
|
-
"system"
|
|
4344
|
-
];
|
|
4105
|
+
const safeToParseTemplate = ["assistant", "system"];
|
|
4345
4106
|
if (this.parseUserTemplates) {
|
|
4346
4107
|
safeToParseTemplate.push("user");
|
|
4347
4108
|
}
|
|
4348
4109
|
for (const message of this.messages) {
|
|
4349
4110
|
if (message.role === "placeholder") {
|
|
4350
|
-
const { token, ...data } = extractPromptPlaceholderToken(
|
|
4111
|
+
const { token, ...data } = extractPromptPlaceholderToken(
|
|
4112
|
+
message.content
|
|
4113
|
+
);
|
|
4351
4114
|
switch (token) {
|
|
4352
4115
|
case ">DialogueHistory": {
|
|
4353
4116
|
const { key = "", user } = data;
|
|
@@ -4356,11 +4119,7 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4356
4119
|
for (const message2 of history) {
|
|
4357
4120
|
switch (message2.role) {
|
|
4358
4121
|
case "user": {
|
|
4359
|
-
const m = pick(message2, [
|
|
4360
|
-
"role",
|
|
4361
|
-
"content",
|
|
4362
|
-
"name"
|
|
4363
|
-
]);
|
|
4122
|
+
const m = pick(message2, ["role", "content", "name"]);
|
|
4364
4123
|
if (user) {
|
|
4365
4124
|
m["name"] = user;
|
|
4366
4125
|
}
|
|
@@ -4406,10 +4165,14 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4406
4165
|
const message2 = {
|
|
4407
4166
|
role,
|
|
4408
4167
|
name,
|
|
4409
|
-
content: await this.replaceTemplateStringAsync(
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4168
|
+
content: await this.replaceTemplateStringAsync(
|
|
4169
|
+
content,
|
|
4170
|
+
replacements,
|
|
4171
|
+
{
|
|
4172
|
+
partials: this.partials,
|
|
4173
|
+
helpers: this.helpers
|
|
4174
|
+
}
|
|
4175
|
+
)
|
|
4413
4176
|
};
|
|
4414
4177
|
if (!name || role !== "user") {
|
|
4415
4178
|
delete message2.name;
|
|
@@ -4420,12 +4183,18 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4420
4183
|
}
|
|
4421
4184
|
}
|
|
4422
4185
|
} else if (message.role === "function") {
|
|
4423
|
-
messagesOut.push(
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4186
|
+
messagesOut.push(
|
|
4187
|
+
Object.assign({}, message, {
|
|
4188
|
+
content: await this.replaceTemplateStringAsync(
|
|
4189
|
+
message.content,
|
|
4190
|
+
replacements,
|
|
4191
|
+
{
|
|
4192
|
+
partials: this.partials,
|
|
4193
|
+
helpers: this.helpers
|
|
4194
|
+
}
|
|
4195
|
+
)
|
|
4427
4196
|
})
|
|
4428
|
-
|
|
4197
|
+
);
|
|
4429
4198
|
} else {
|
|
4430
4199
|
if (safeToParseTemplate.includes(message.role)) {
|
|
4431
4200
|
if (Array.isArray(message.content)) {
|
|
@@ -4436,10 +4205,14 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4436
4205
|
type: "text",
|
|
4437
4206
|
text: this.runPromptFilter(
|
|
4438
4207
|
// HERE
|
|
4439
|
-
await this.replaceTemplateStringAsync(
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4208
|
+
await this.replaceTemplateStringAsync(
|
|
4209
|
+
this.runPromptFilter(m.text, this.filters.pre, values),
|
|
4210
|
+
replacements,
|
|
4211
|
+
{
|
|
4212
|
+
partials: this.partials,
|
|
4213
|
+
helpers: this.helpers
|
|
4214
|
+
}
|
|
4215
|
+
),
|
|
4443
4216
|
this.filters.post,
|
|
4444
4217
|
values
|
|
4445
4218
|
)
|
|
@@ -4448,45 +4221,65 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4448
4221
|
content.push(m);
|
|
4449
4222
|
}
|
|
4450
4223
|
}
|
|
4451
|
-
messagesOut.push(Object.assign({}, message, {
|
|
4452
|
-
content
|
|
4453
|
-
}));
|
|
4224
|
+
messagesOut.push(Object.assign({}, message, { content }));
|
|
4454
4225
|
} else if (message.content) {
|
|
4455
|
-
const content = this.runPromptFilter(
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4226
|
+
const content = this.runPromptFilter(
|
|
4227
|
+
await this.replaceTemplateStringAsync(
|
|
4228
|
+
this.runPromptFilter(message.content, this.filters.pre, values),
|
|
4229
|
+
replacements,
|
|
4230
|
+
{
|
|
4231
|
+
partials: this.partials,
|
|
4232
|
+
helpers: this.helpers
|
|
4233
|
+
}
|
|
4234
|
+
),
|
|
4235
|
+
this.filters.post,
|
|
4236
|
+
values
|
|
4237
|
+
);
|
|
4238
|
+
messagesOut.push(Object.assign({}, message, { content }));
|
|
4462
4239
|
} else {
|
|
4463
|
-
messagesOut.push(Object.assign({}, message, {
|
|
4464
|
-
content: null
|
|
4465
|
-
}));
|
|
4240
|
+
messagesOut.push(Object.assign({}, message, { content: null }));
|
|
4466
4241
|
}
|
|
4467
4242
|
} else {
|
|
4468
|
-
messagesOut.push(
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4243
|
+
messagesOut.push(
|
|
4244
|
+
Object.assign({}, message, {
|
|
4245
|
+
content: Array.isArray(message.content) ? message.content.map(
|
|
4246
|
+
(m) => m.text ? {
|
|
4247
|
+
type: "text",
|
|
4248
|
+
text: this.runPromptFilter(
|
|
4249
|
+
this.runPromptFilter(
|
|
4250
|
+
m.text,
|
|
4251
|
+
this.filters.pre,
|
|
4252
|
+
values
|
|
4253
|
+
),
|
|
4254
|
+
this.filters.post,
|
|
4255
|
+
values
|
|
4256
|
+
)
|
|
4257
|
+
} : m
|
|
4258
|
+
) : message.content && !Array.isArray(message.content) ? this.runPromptFilter(
|
|
4259
|
+
this.runPromptFilter(
|
|
4260
|
+
message.content,
|
|
4261
|
+
this.filters.pre,
|
|
4262
|
+
values
|
|
4263
|
+
),
|
|
4264
|
+
this.filters.post,
|
|
4265
|
+
values
|
|
4266
|
+
) : null
|
|
4267
|
+
})
|
|
4268
|
+
);
|
|
4474
4269
|
}
|
|
4475
4270
|
}
|
|
4476
4271
|
}
|
|
4477
4272
|
return messagesOut;
|
|
4478
4273
|
}
|
|
4479
4274
|
/**
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
|
|
4483
|
-
|
|
4275
|
+
* validate Ensures there are not unresolved tokens in prompt.
|
|
4276
|
+
* @TODO Make this work!
|
|
4277
|
+
* @return Returns false if the template is not valid.
|
|
4278
|
+
*/
|
|
4484
4279
|
validate() {
|
|
4485
4280
|
return true;
|
|
4486
4281
|
}
|
|
4487
4282
|
};
|
|
4488
|
-
__name(_ChatPrompt, "ChatPrompt");
|
|
4489
|
-
var ChatPrompt = _ChatPrompt;
|
|
4490
4283
|
|
|
4491
4284
|
// src/prompt/_functions.ts
|
|
4492
4285
|
function createPrompt(type, initialPromptMessage, options) {
|
|
@@ -4497,14 +4290,12 @@ function createPrompt(type, initialPromptMessage, options) {
|
|
|
4497
4290
|
return new TextPrompt(initialPromptMessage);
|
|
4498
4291
|
}
|
|
4499
4292
|
}
|
|
4500
|
-
__name(createPrompt, "createPrompt");
|
|
4501
4293
|
function createChatPrompt(initialSystemPromptMessage, options) {
|
|
4502
4294
|
return new ChatPrompt(initialSystemPromptMessage, options);
|
|
4503
4295
|
}
|
|
4504
|
-
__name(createChatPrompt, "createChatPrompt");
|
|
4505
4296
|
|
|
4506
4297
|
// src/state/item.ts
|
|
4507
|
-
var
|
|
4298
|
+
var BaseStateItem = class {
|
|
4508
4299
|
constructor(key, initialValue) {
|
|
4509
4300
|
__publicField(this, "key");
|
|
4510
4301
|
__publicField(this, "value");
|
|
@@ -4514,7 +4305,10 @@ var _BaseStateItem = class _BaseStateItem {
|
|
|
4514
4305
|
this.initialValue = initialValue;
|
|
4515
4306
|
}
|
|
4516
4307
|
setValue(value) {
|
|
4517
|
-
assert(
|
|
4308
|
+
assert(
|
|
4309
|
+
typeof value === typeof this.value,
|
|
4310
|
+
`Invalid value type. Expected ${typeof this.value}, received ${typeof value}`
|
|
4311
|
+
);
|
|
4518
4312
|
this.value = value;
|
|
4519
4313
|
}
|
|
4520
4314
|
getKey() {
|
|
@@ -4538,19 +4332,18 @@ var _BaseStateItem = class _BaseStateItem {
|
|
|
4538
4332
|
value: this.serializeValue()
|
|
4539
4333
|
};
|
|
4540
4334
|
}
|
|
4335
|
+
// deserialize() {}
|
|
4541
4336
|
};
|
|
4542
|
-
|
|
4543
|
-
var BaseStateItem = _BaseStateItem;
|
|
4544
|
-
var _DefaultStateItem = class _DefaultStateItem extends BaseStateItem {
|
|
4337
|
+
var DefaultStateItem = class extends BaseStateItem {
|
|
4545
4338
|
constructor(name, defaultValue) {
|
|
4546
4339
|
super(name, defaultValue);
|
|
4547
4340
|
}
|
|
4341
|
+
// serialize() { return {}; }
|
|
4342
|
+
// deserialize() {}
|
|
4548
4343
|
};
|
|
4549
|
-
__name(_DefaultStateItem, "DefaultStateItem");
|
|
4550
|
-
var DefaultStateItem = _DefaultStateItem;
|
|
4551
4344
|
|
|
4552
4345
|
// src/state/dialogue.ts
|
|
4553
|
-
var
|
|
4346
|
+
var Dialogue = class extends BaseStateItem {
|
|
4554
4347
|
constructor(name) {
|
|
4555
4348
|
super(name, []);
|
|
4556
4349
|
__publicField(this, "name");
|
|
@@ -4646,17 +4439,14 @@ var _Dialogue = class _Dialogue extends BaseStateItem {
|
|
|
4646
4439
|
return {
|
|
4647
4440
|
class: "Dialogue",
|
|
4648
4441
|
name: this.name,
|
|
4649
|
-
value: [
|
|
4650
|
-
...this.value
|
|
4651
|
-
]
|
|
4442
|
+
value: [...this.value]
|
|
4652
4443
|
};
|
|
4653
4444
|
}
|
|
4445
|
+
// deserialize() {}
|
|
4654
4446
|
};
|
|
4655
|
-
__name(_Dialogue, "Dialogue");
|
|
4656
|
-
var Dialogue = _Dialogue;
|
|
4657
4447
|
|
|
4658
4448
|
// src/state/_base.ts
|
|
4659
|
-
var
|
|
4449
|
+
var BaseState = class {
|
|
4660
4450
|
constructor() {
|
|
4661
4451
|
__publicField(this, "dialogues", {});
|
|
4662
4452
|
__publicField(this, "attributes", {});
|
|
@@ -4681,8 +4471,14 @@ var _BaseState = class _BaseState {
|
|
|
4681
4471
|
return dialogue;
|
|
4682
4472
|
}
|
|
4683
4473
|
createContextItem(item) {
|
|
4684
|
-
assert(
|
|
4685
|
-
|
|
4474
|
+
assert(
|
|
4475
|
+
item instanceof BaseStateItem,
|
|
4476
|
+
"Invalid context item. Must be instance of BaseStateItem"
|
|
4477
|
+
);
|
|
4478
|
+
assert(
|
|
4479
|
+
!this.context[item?.getKey()],
|
|
4480
|
+
`key (${item?.getKey()}) already exists`
|
|
4481
|
+
);
|
|
4686
4482
|
this.context[item.getKey()] = item;
|
|
4687
4483
|
return this.context[item.getKey()];
|
|
4688
4484
|
}
|
|
@@ -4704,14 +4500,16 @@ var _BaseState = class _BaseState {
|
|
|
4704
4500
|
serialize() {
|
|
4705
4501
|
const dialogues = {};
|
|
4706
4502
|
const context = {};
|
|
4707
|
-
const attributes = {
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4503
|
+
const attributes = { ...this.attributes };
|
|
4504
|
+
const dialogueKeys = Object.keys(
|
|
4505
|
+
this.dialogues
|
|
4506
|
+
);
|
|
4711
4507
|
for (const dialogueKey of dialogueKeys) {
|
|
4712
4508
|
dialogues[dialogueKey] = this.dialogues[dialogueKey].serialize();
|
|
4713
4509
|
}
|
|
4714
|
-
const contextKeys = Object.keys(
|
|
4510
|
+
const contextKeys = Object.keys(
|
|
4511
|
+
this.context
|
|
4512
|
+
);
|
|
4715
4513
|
for (const contextKey of contextKeys) {
|
|
4716
4514
|
context[contextKey] = this.context[contextKey].serialize();
|
|
4717
4515
|
}
|
|
@@ -4722,9 +4520,7 @@ var _BaseState = class _BaseState {
|
|
|
4722
4520
|
};
|
|
4723
4521
|
}
|
|
4724
4522
|
};
|
|
4725
|
-
|
|
4726
|
-
var BaseState = _BaseState;
|
|
4727
|
-
var _DefaultState = class _DefaultState extends BaseState {
|
|
4523
|
+
var DefaultState = class extends BaseState {
|
|
4728
4524
|
constructor() {
|
|
4729
4525
|
super();
|
|
4730
4526
|
}
|
|
@@ -4732,22 +4528,17 @@ var _DefaultState = class _DefaultState extends BaseState {
|
|
|
4732
4528
|
console.log("Save not implemented in default state.");
|
|
4733
4529
|
}
|
|
4734
4530
|
};
|
|
4735
|
-
__name(_DefaultState, "DefaultState");
|
|
4736
|
-
var DefaultState = _DefaultState;
|
|
4737
4531
|
|
|
4738
4532
|
// src/state/_functions.ts
|
|
4739
4533
|
function createState() {
|
|
4740
4534
|
return new DefaultState();
|
|
4741
4535
|
}
|
|
4742
|
-
__name(createState, "createState");
|
|
4743
4536
|
function createDialogue(name) {
|
|
4744
4537
|
return new Dialogue(name);
|
|
4745
4538
|
}
|
|
4746
|
-
__name(createDialogue, "createDialogue");
|
|
4747
4539
|
function createStateItem(name, defaultValue) {
|
|
4748
4540
|
return new DefaultStateItem(name, defaultValue);
|
|
4749
4541
|
}
|
|
4750
|
-
__name(createStateItem, "createStateItem");
|
|
4751
4542
|
export {
|
|
4752
4543
|
BaseExecutor,
|
|
4753
4544
|
BaseParser,
|
|
@@ -4771,6 +4562,9 @@ export {
|
|
|
4771
4562
|
createPrompt,
|
|
4772
4563
|
createState,
|
|
4773
4564
|
createStateItem,
|
|
4565
|
+
defineSchema,
|
|
4566
|
+
registerHelpers,
|
|
4567
|
+
registerPartials,
|
|
4774
4568
|
useExecutors,
|
|
4775
4569
|
useLlm,
|
|
4776
4570
|
utils_exports as utils
|