llm-exe 2.1.8 → 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 +874 -1124
- package/dist/index.mjs +867 -1126
- package/package.json +29 -26
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(/^- /, "").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,35 +2053,17 @@ 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
2064
|
return messages.map((m) => {
|
|
2192
2065
|
if (m.role === "system") {
|
|
2193
|
-
return {
|
|
2194
|
-
...m,
|
|
2195
|
-
role: "user"
|
|
2196
|
-
};
|
|
2066
|
+
return { ...m, role: "user" };
|
|
2197
2067
|
}
|
|
2198
2068
|
return m;
|
|
2199
2069
|
});
|
|
@@ -2202,16 +2072,12 @@ function anthropicPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
|
2202
2072
|
first,
|
|
2203
2073
|
...messages.map((m) => {
|
|
2204
2074
|
if (m.role === "system") {
|
|
2205
|
-
return {
|
|
2206
|
-
...m,
|
|
2207
|
-
role: "user"
|
|
2208
|
-
};
|
|
2075
|
+
return { ...m, role: "user" };
|
|
2209
2076
|
}
|
|
2210
2077
|
return m;
|
|
2211
2078
|
})
|
|
2212
2079
|
];
|
|
2213
2080
|
}
|
|
2214
|
-
__name(anthropicPromptSanitize, "anthropicPromptSanitize");
|
|
2215
2081
|
|
|
2216
2082
|
// src/llm/config/bedrock/index.ts
|
|
2217
2083
|
var ANTORPIC_BEDROCK_VERSION = "bedrock-2023-05-31";
|
|
@@ -2227,10 +2093,7 @@ var amazonAnthropicChatV1 = {
|
|
|
2227
2093
|
maxTokens: {},
|
|
2228
2094
|
awsRegion: {
|
|
2229
2095
|
default: getEnvironmentVariable("AWS_REGION"),
|
|
2230
|
-
required: [
|
|
2231
|
-
true,
|
|
2232
|
-
"aws region is required"
|
|
2233
|
-
]
|
|
2096
|
+
required: [true, "aws region is required"]
|
|
2234
2097
|
},
|
|
2235
2098
|
awsSecretKey: {},
|
|
2236
2099
|
awsAccessKey: {}
|
|
@@ -2273,7 +2136,7 @@ var amazonMetaChatV1 = {
|
|
|
2273
2136
|
mapBody: {
|
|
2274
2137
|
prompt: {
|
|
2275
2138
|
key: "prompt",
|
|
2276
|
-
sanitize:
|
|
2139
|
+
sanitize: (messages) => {
|
|
2277
2140
|
if (typeof messages === "string") {
|
|
2278
2141
|
return messages;
|
|
2279
2142
|
} else {
|
|
@@ -2281,7 +2144,7 @@ var amazonMetaChatV1 = {
|
|
|
2281
2144
|
messages
|
|
2282
2145
|
});
|
|
2283
2146
|
}
|
|
2284
|
-
}
|
|
2147
|
+
}
|
|
2285
2148
|
},
|
|
2286
2149
|
topP: {
|
|
2287
2150
|
key: "top_p"
|
|
@@ -2298,6 +2161,7 @@ var amazonMetaChatV1 = {
|
|
|
2298
2161
|
var bedrock = {
|
|
2299
2162
|
"amazon:anthropic.chat.v1": amazonAnthropicChatV1,
|
|
2300
2163
|
"amazon:meta.chat.v1": amazonMetaChatV1
|
|
2164
|
+
// "amazon:nova.chat.v1": amazonAmazonNovaChatV1,
|
|
2301
2165
|
};
|
|
2302
2166
|
|
|
2303
2167
|
// src/llm/config/anthropic/index.ts
|
|
@@ -2312,10 +2176,7 @@ var anthropicChatV1 = {
|
|
|
2312
2176
|
prompt: {},
|
|
2313
2177
|
system: {},
|
|
2314
2178
|
maxTokens: {
|
|
2315
|
-
required: [
|
|
2316
|
-
true,
|
|
2317
|
-
"maxTokens required"
|
|
2318
|
-
],
|
|
2179
|
+
required: [true, "maxTokens required"],
|
|
2319
2180
|
default: 4096
|
|
2320
2181
|
},
|
|
2321
2182
|
anthropicApiKey: {
|
|
@@ -2340,10 +2201,22 @@ var anthropicChatV1 = {
|
|
|
2340
2201
|
};
|
|
2341
2202
|
var anthropic = {
|
|
2342
2203
|
"anthropic.chat.v1": anthropicChatV1,
|
|
2343
|
-
"anthropic.claude-3-7-sonnet": withDefaultModel(
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
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
|
+
)
|
|
2347
2220
|
};
|
|
2348
2221
|
|
|
2349
2222
|
// src/llm/config/x/index.ts
|
|
@@ -2364,17 +2237,12 @@ var xaiChatV1 = {
|
|
|
2364
2237
|
mapBody: {
|
|
2365
2238
|
prompt: {
|
|
2366
2239
|
key: "messages",
|
|
2367
|
-
sanitize:
|
|
2240
|
+
sanitize: (v) => {
|
|
2368
2241
|
if (typeof v === "string") {
|
|
2369
|
-
return [
|
|
2370
|
-
{
|
|
2371
|
-
role: "user",
|
|
2372
|
-
content: v
|
|
2373
|
-
}
|
|
2374
|
-
];
|
|
2242
|
+
return [{ role: "user", content: v }];
|
|
2375
2243
|
}
|
|
2376
2244
|
return v;
|
|
2377
|
-
}
|
|
2245
|
+
}
|
|
2378
2246
|
},
|
|
2379
2247
|
model: {
|
|
2380
2248
|
key: "model"
|
|
@@ -2384,7 +2252,7 @@ var xaiChatV1 = {
|
|
|
2384
2252
|
},
|
|
2385
2253
|
useJson: {
|
|
2386
2254
|
key: "response_format.type",
|
|
2387
|
-
sanitize:
|
|
2255
|
+
sanitize: (v) => v ? "json_object" : "text"
|
|
2388
2256
|
}
|
|
2389
2257
|
}
|
|
2390
2258
|
};
|
|
@@ -2406,17 +2274,12 @@ var ollamaChatV1 = {
|
|
|
2406
2274
|
mapBody: {
|
|
2407
2275
|
prompt: {
|
|
2408
2276
|
key: "messages",
|
|
2409
|
-
sanitize:
|
|
2277
|
+
sanitize: (v) => {
|
|
2410
2278
|
if (typeof v === "string") {
|
|
2411
|
-
return [
|
|
2412
|
-
{
|
|
2413
|
-
role: "user",
|
|
2414
|
-
content: v
|
|
2415
|
-
}
|
|
2416
|
-
];
|
|
2279
|
+
return [{ role: "user", content: v }];
|
|
2417
2280
|
}
|
|
2418
2281
|
return v;
|
|
2419
|
-
}
|
|
2282
|
+
}
|
|
2420
2283
|
},
|
|
2421
2284
|
model: {
|
|
2422
2285
|
key: "model"
|
|
@@ -2434,90 +2297,58 @@ var ollama = {
|
|
|
2434
2297
|
|
|
2435
2298
|
// src/utils/modules/modifyPromptRoleChange.ts
|
|
2436
2299
|
function modifyPromptRoleChange(messages, roleChanges) {
|
|
2437
|
-
const roleChangeMap = new Map(roleChanges.map(({ from, to }) => [
|
|
2438
|
-
from,
|
|
2439
|
-
to
|
|
2440
|
-
]));
|
|
2300
|
+
const roleChangeMap = new Map(roleChanges.map(({ from, to }) => [from, to]));
|
|
2441
2301
|
if (Array.isArray(messages)) {
|
|
2442
2302
|
return messages.map((message) => {
|
|
2443
2303
|
const newRole2 = roleChangeMap.get(message.role);
|
|
2444
|
-
return newRole2 ? {
|
|
2445
|
-
...message,
|
|
2446
|
-
role: newRole2
|
|
2447
|
-
} : message;
|
|
2304
|
+
return newRole2 ? { ...message, role: newRole2 } : message;
|
|
2448
2305
|
});
|
|
2449
2306
|
}
|
|
2450
2307
|
const newRole = roleChangeMap.get(messages.role);
|
|
2451
|
-
return newRole ? {
|
|
2452
|
-
...messages,
|
|
2453
|
-
role: newRole
|
|
2454
|
-
} : messages;
|
|
2308
|
+
return newRole ? { ...messages, role: newRole } : messages;
|
|
2455
2309
|
}
|
|
2456
|
-
__name(modifyPromptRoleChange, "modifyPromptRoleChange");
|
|
2457
2310
|
|
|
2458
2311
|
// src/llm/config/google/promptSanitizeMessageCallback.ts
|
|
2459
2312
|
function googleGeminiPromptMessageCallback(_message) {
|
|
2460
|
-
let message = {
|
|
2461
|
-
..._message
|
|
2462
|
-
};
|
|
2313
|
+
let message = { ..._message };
|
|
2463
2314
|
message = modifyPromptRoleChange(_message, [
|
|
2464
|
-
{
|
|
2465
|
-
from: "assistant",
|
|
2466
|
-
to: "model"
|
|
2467
|
-
}
|
|
2315
|
+
{ from: "assistant", to: "model" }
|
|
2468
2316
|
]);
|
|
2469
2317
|
const { role, ...payload } = message;
|
|
2470
2318
|
const parts = [];
|
|
2471
2319
|
if (typeof payload.content === "string") {
|
|
2472
|
-
parts.push({
|
|
2473
|
-
text: message.content
|
|
2474
|
-
});
|
|
2320
|
+
parts.push({ text: message.content });
|
|
2475
2321
|
}
|
|
2476
2322
|
return {
|
|
2477
2323
|
role,
|
|
2478
2324
|
parts
|
|
2479
2325
|
};
|
|
2480
2326
|
}
|
|
2481
|
-
__name(googleGeminiPromptMessageCallback, "googleGeminiPromptMessageCallback");
|
|
2482
2327
|
|
|
2483
2328
|
// src/llm/config/google/promptSanitize.ts
|
|
2484
2329
|
function googleGeminiPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
2485
2330
|
if (typeof _messages === "string") {
|
|
2486
|
-
return [
|
|
2487
|
-
{
|
|
2488
|
-
role: "user",
|
|
2489
|
-
parts: [
|
|
2490
|
-
{
|
|
2491
|
-
text: _messages
|
|
2492
|
-
}
|
|
2493
|
-
]
|
|
2494
|
-
}
|
|
2495
|
-
];
|
|
2331
|
+
return [{ role: "user", parts: [{ text: _messages }] }];
|
|
2496
2332
|
}
|
|
2497
2333
|
if (Array.isArray(_messages)) {
|
|
2498
2334
|
if (_messages.length === 0) {
|
|
2499
2335
|
throw new Error("Empty messages array");
|
|
2500
2336
|
}
|
|
2501
2337
|
if (_messages.length === 1 && _messages[0].role === "system") {
|
|
2502
|
-
return [
|
|
2503
|
-
{
|
|
2504
|
-
role: "user",
|
|
2505
|
-
parts: [
|
|
2506
|
-
{
|
|
2507
|
-
text: _messages[0].content
|
|
2508
|
-
}
|
|
2509
|
-
]
|
|
2510
|
-
}
|
|
2511
|
-
];
|
|
2338
|
+
return [{ role: "user", parts: [{ text: _messages[0].content }] }];
|
|
2512
2339
|
}
|
|
2513
|
-
const hasSystemInstruction = _messages.some(
|
|
2340
|
+
const hasSystemInstruction = _messages.some(
|
|
2341
|
+
(message) => message.role === "system"
|
|
2342
|
+
);
|
|
2514
2343
|
if (hasSystemInstruction) {
|
|
2515
|
-
const theSystemInstructions = _messages.filter(
|
|
2516
|
-
|
|
2344
|
+
const theSystemInstructions = _messages.filter(
|
|
2345
|
+
(message) => message.role === "system"
|
|
2346
|
+
);
|
|
2347
|
+
const withoutSystemInstructions = _messages.filter(
|
|
2348
|
+
(message) => message.role !== "system"
|
|
2349
|
+
);
|
|
2517
2350
|
_outputObj.system_instruction = {
|
|
2518
|
-
parts: theSystemInstructions.map((message) => ({
|
|
2519
|
-
text: message.content
|
|
2520
|
-
}))
|
|
2351
|
+
parts: theSystemInstructions.map((message) => ({ text: message.content }))
|
|
2521
2352
|
};
|
|
2522
2353
|
return withoutSystemInstructions.map(googleGeminiPromptMessageCallback);
|
|
2523
2354
|
}
|
|
@@ -2525,7 +2356,6 @@ function googleGeminiPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
|
2525
2356
|
}
|
|
2526
2357
|
throw new Error("Invalid messages format");
|
|
2527
2358
|
}
|
|
2528
|
-
__name(googleGeminiPromptSanitize, "googleGeminiPromptSanitize");
|
|
2529
2359
|
|
|
2530
2360
|
// src/llm/config/google/index.ts
|
|
2531
2361
|
var googleGeminiChatV1 = {
|
|
@@ -2546,13 +2376,25 @@ var googleGeminiChatV1 = {
|
|
|
2546
2376
|
key: "contents",
|
|
2547
2377
|
sanitize: googleGeminiPromptSanitize
|
|
2548
2378
|
}
|
|
2379
|
+
// topP: {
|
|
2380
|
+
// key: "top_p",
|
|
2381
|
+
// }
|
|
2549
2382
|
}
|
|
2550
2383
|
};
|
|
2551
2384
|
var google = {
|
|
2552
2385
|
"google.chat.v1": googleGeminiChatV1,
|
|
2553
|
-
"google.gemini-2.0-flash": withDefaultModel(
|
|
2554
|
-
|
|
2555
|
-
|
|
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
|
+
)
|
|
2556
2398
|
};
|
|
2557
2399
|
|
|
2558
2400
|
// src/llm/config/deepseek/index.ts
|
|
@@ -2573,17 +2415,12 @@ var deepseekChatV1 = {
|
|
|
2573
2415
|
mapBody: {
|
|
2574
2416
|
prompt: {
|
|
2575
2417
|
key: "messages",
|
|
2576
|
-
sanitize:
|
|
2418
|
+
sanitize: (v) => {
|
|
2577
2419
|
if (typeof v === "string") {
|
|
2578
|
-
return [
|
|
2579
|
-
{
|
|
2580
|
-
role: "user",
|
|
2581
|
-
content: v
|
|
2582
|
-
}
|
|
2583
|
-
];
|
|
2420
|
+
return [{ role: "user", content: v }];
|
|
2584
2421
|
}
|
|
2585
2422
|
return v;
|
|
2586
|
-
}
|
|
2423
|
+
}
|
|
2587
2424
|
},
|
|
2588
2425
|
model: {
|
|
2589
2426
|
key: "model"
|
|
@@ -2593,7 +2430,7 @@ var deepseekChatV1 = {
|
|
|
2593
2430
|
},
|
|
2594
2431
|
useJson: {
|
|
2595
2432
|
key: "response_format.type",
|
|
2596
|
-
sanitize:
|
|
2433
|
+
sanitize: (v) => v ? "json_object" : "text"
|
|
2597
2434
|
}
|
|
2598
2435
|
}
|
|
2599
2436
|
};
|
|
@@ -2629,7 +2466,6 @@ function getLlmConfig(provider) {
|
|
|
2629
2466
|
resolution: "Provide a valid provider"
|
|
2630
2467
|
});
|
|
2631
2468
|
}
|
|
2632
|
-
__name(getLlmConfig, "getLlmConfig");
|
|
2633
2469
|
|
|
2634
2470
|
// src/llm/output/_utils/getResultContent.ts
|
|
2635
2471
|
function getResultContent(result, index) {
|
|
@@ -2638,11 +2474,8 @@ function getResultContent(result, index) {
|
|
|
2638
2474
|
const val = arr[index];
|
|
2639
2475
|
return val ? val : [];
|
|
2640
2476
|
}
|
|
2641
|
-
return [
|
|
2642
|
-
...result.content
|
|
2643
|
-
];
|
|
2477
|
+
return [...result.content];
|
|
2644
2478
|
}
|
|
2645
|
-
__name(getResultContent, "getResultContent");
|
|
2646
2479
|
|
|
2647
2480
|
// src/llm/output/base.ts
|
|
2648
2481
|
function BaseLlmOutput2(result) {
|
|
@@ -2651,12 +2484,8 @@ function BaseLlmOutput2(result) {
|
|
|
2651
2484
|
name: result.name,
|
|
2652
2485
|
usage: result.usage,
|
|
2653
2486
|
stopReason: result.stopReason,
|
|
2654
|
-
options: [
|
|
2655
|
-
|
|
2656
|
-
],
|
|
2657
|
-
content: [
|
|
2658
|
-
...result.content
|
|
2659
|
-
],
|
|
2487
|
+
options: [...result?.options || []],
|
|
2488
|
+
content: [...result.content],
|
|
2660
2489
|
created: result?.created || (/* @__PURE__ */ new Date()).getTime()
|
|
2661
2490
|
});
|
|
2662
2491
|
function getResult() {
|
|
@@ -2670,14 +2499,12 @@ function BaseLlmOutput2(result) {
|
|
|
2670
2499
|
stopReason: __result.stopReason
|
|
2671
2500
|
};
|
|
2672
2501
|
}
|
|
2673
|
-
__name(getResult, "getResult");
|
|
2674
2502
|
return {
|
|
2675
|
-
getResultContent:
|
|
2676
|
-
getResultText:
|
|
2503
|
+
getResultContent: (index) => getResultContent(__result, index),
|
|
2504
|
+
getResultText: () => getResultText(__result.content),
|
|
2677
2505
|
getResult
|
|
2678
2506
|
};
|
|
2679
2507
|
}
|
|
2680
|
-
__name(BaseLlmOutput2, "BaseLlmOutput2");
|
|
2681
2508
|
|
|
2682
2509
|
// src/llm/output/_util.ts
|
|
2683
2510
|
function normalizeFunctionCall(input, provider) {
|
|
@@ -2688,20 +2515,16 @@ function normalizeFunctionCall(input, provider) {
|
|
|
2688
2515
|
}
|
|
2689
2516
|
return input;
|
|
2690
2517
|
}
|
|
2691
|
-
__name(normalizeFunctionCall, "normalizeFunctionCall");
|
|
2692
2518
|
function formatOptions(response, handler) {
|
|
2693
2519
|
const out = [];
|
|
2694
2520
|
for (const item of response) {
|
|
2695
2521
|
const result = handler(item);
|
|
2696
2522
|
if (result) {
|
|
2697
|
-
out.push([
|
|
2698
|
-
result
|
|
2699
|
-
]);
|
|
2523
|
+
out.push([result]);
|
|
2700
2524
|
}
|
|
2701
2525
|
}
|
|
2702
2526
|
return out;
|
|
2703
2527
|
}
|
|
2704
|
-
__name(formatOptions, "formatOptions");
|
|
2705
2528
|
function formatContent(response, handler) {
|
|
2706
2529
|
const out = [];
|
|
2707
2530
|
const result = handler(response);
|
|
@@ -2710,7 +2533,6 @@ function formatContent(response, handler) {
|
|
|
2710
2533
|
}
|
|
2711
2534
|
return out;
|
|
2712
2535
|
}
|
|
2713
|
-
__name(formatContent, "formatContent");
|
|
2714
2536
|
|
|
2715
2537
|
// src/llm/output/openai.ts
|
|
2716
2538
|
function formatResult(result) {
|
|
@@ -2734,7 +2556,6 @@ function formatResult(result) {
|
|
|
2734
2556
|
text: ""
|
|
2735
2557
|
};
|
|
2736
2558
|
}
|
|
2737
|
-
__name(formatResult, "formatResult");
|
|
2738
2559
|
function OutputOpenAIChat(result, _config) {
|
|
2739
2560
|
const id = result.id;
|
|
2740
2561
|
const name = result.model || _config?.model || "openai.unknown";
|
|
@@ -2758,7 +2579,6 @@ function OutputOpenAIChat(result, _config) {
|
|
|
2758
2579
|
options
|
|
2759
2580
|
});
|
|
2760
2581
|
}
|
|
2761
|
-
__name(OutputOpenAIChat, "OutputOpenAIChat");
|
|
2762
2582
|
|
|
2763
2583
|
// src/llm/output/claude.ts
|
|
2764
2584
|
function formatResult2(response) {
|
|
@@ -2781,7 +2601,6 @@ function formatResult2(response) {
|
|
|
2781
2601
|
}
|
|
2782
2602
|
return out;
|
|
2783
2603
|
}
|
|
2784
|
-
__name(formatResult2, "formatResult");
|
|
2785
2604
|
function OutputAnthropicClaude3Chat(result, _config) {
|
|
2786
2605
|
const id = result.id;
|
|
2787
2606
|
const name = result.model || _config?.model || "anthropic.unknown";
|
|
@@ -2800,17 +2619,13 @@ function OutputAnthropicClaude3Chat(result, _config) {
|
|
|
2800
2619
|
content
|
|
2801
2620
|
});
|
|
2802
2621
|
}
|
|
2803
|
-
__name(OutputAnthropicClaude3Chat, "OutputAnthropicClaude3Chat");
|
|
2804
2622
|
|
|
2805
2623
|
// src/llm/output/llama.ts
|
|
2806
2624
|
function OutputMetaLlama3Chat(result, _config) {
|
|
2807
2625
|
const name = _config?.model || "meta";
|
|
2808
2626
|
const stopReason = result.stop_reason;
|
|
2809
2627
|
const content = [
|
|
2810
|
-
{
|
|
2811
|
-
type: "text",
|
|
2812
|
-
text: result.generation
|
|
2813
|
-
}
|
|
2628
|
+
{ type: "text", text: result.generation }
|
|
2814
2629
|
];
|
|
2815
2630
|
const usage = {
|
|
2816
2631
|
output_tokens: result?.generation_token_count,
|
|
@@ -2824,7 +2639,6 @@ function OutputMetaLlama3Chat(result, _config) {
|
|
|
2824
2639
|
content
|
|
2825
2640
|
});
|
|
2826
2641
|
}
|
|
2827
|
-
__name(OutputMetaLlama3Chat, "OutputMetaLlama3Chat");
|
|
2828
2642
|
|
|
2829
2643
|
// src/llm/output/default.ts
|
|
2830
2644
|
function OutputDefault(result, _config) {
|
|
@@ -2832,10 +2646,7 @@ function OutputDefault(result, _config) {
|
|
|
2832
2646
|
const stopReason = result?.stopReason || "stop";
|
|
2833
2647
|
const content = [];
|
|
2834
2648
|
if (result?.text) {
|
|
2835
|
-
content.push({
|
|
2836
|
-
type: "text",
|
|
2837
|
-
text: result.text
|
|
2838
|
-
});
|
|
2649
|
+
content.push({ type: "text", text: result.text });
|
|
2839
2650
|
}
|
|
2840
2651
|
const usage = {
|
|
2841
2652
|
output_tokens: result?.output_tokens || 0,
|
|
@@ -2849,7 +2660,6 @@ function OutputDefault(result, _config) {
|
|
|
2849
2660
|
content
|
|
2850
2661
|
});
|
|
2851
2662
|
}
|
|
2852
|
-
__name(OutputDefault, "OutputDefault");
|
|
2853
2663
|
|
|
2854
2664
|
// src/llm/output/xai.ts
|
|
2855
2665
|
function formatResult3(result) {
|
|
@@ -2873,7 +2683,6 @@ function formatResult3(result) {
|
|
|
2873
2683
|
text: ""
|
|
2874
2684
|
};
|
|
2875
2685
|
}
|
|
2876
|
-
__name(formatResult3, "formatResult");
|
|
2877
2686
|
function OutputXAIChat(result, _config) {
|
|
2878
2687
|
const id = result.id;
|
|
2879
2688
|
const name = result?.model;
|
|
@@ -2897,7 +2706,6 @@ function OutputXAIChat(result, _config) {
|
|
|
2897
2706
|
options
|
|
2898
2707
|
});
|
|
2899
2708
|
}
|
|
2900
|
-
__name(OutputXAIChat, "OutputXAIChat");
|
|
2901
2709
|
|
|
2902
2710
|
// src/llm/output/_utils/combineJsonl.ts
|
|
2903
2711
|
function combineJsonl(jsonl) {
|
|
@@ -2911,7 +2719,9 @@ function combineJsonl(jsonl) {
|
|
|
2911
2719
|
if (lines.length === 0) {
|
|
2912
2720
|
throw new Error("No JSON lines provided.");
|
|
2913
2721
|
}
|
|
2914
|
-
lines.sort(
|
|
2722
|
+
lines.sort(
|
|
2723
|
+
(a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime()
|
|
2724
|
+
);
|
|
2915
2725
|
let combinedContent = lines.map((line) => line?.message?.content ?? "").join("");
|
|
2916
2726
|
combinedContent = combinedContent.replace(/\\u003c/g, "<").replace(/\\u003e/g, ">");
|
|
2917
2727
|
const finalLine = lines.find((line) => line.done === true);
|
|
@@ -2944,7 +2754,6 @@ function combineJsonl(jsonl) {
|
|
|
2944
2754
|
content
|
|
2945
2755
|
};
|
|
2946
2756
|
}
|
|
2947
|
-
__name(combineJsonl, "combineJsonl");
|
|
2948
2757
|
|
|
2949
2758
|
// src/llm/output/ollama.ts
|
|
2950
2759
|
function OutputOllamaChat(result, _config) {
|
|
@@ -2953,9 +2762,7 @@ function OutputOllamaChat(result, _config) {
|
|
|
2953
2762
|
const name = combined.result.model || _config?.model || "ollama.unknown";
|
|
2954
2763
|
const created = (/* @__PURE__ */ new Date(`${combined.result.created_at}`)).getTime();
|
|
2955
2764
|
const stopReason = `${combined?.result?.done_reason || "stop"}`;
|
|
2956
|
-
const content = [
|
|
2957
|
-
combined.content
|
|
2958
|
-
];
|
|
2765
|
+
const content = [combined.content];
|
|
2959
2766
|
const usage = {
|
|
2960
2767
|
output_tokens: 0,
|
|
2961
2768
|
input_tokens: 0,
|
|
@@ -2971,7 +2778,6 @@ function OutputOllamaChat(result, _config) {
|
|
|
2971
2778
|
options: []
|
|
2972
2779
|
});
|
|
2973
2780
|
}
|
|
2974
|
-
__name(OutputOllamaChat, "OutputOllamaChat");
|
|
2975
2781
|
|
|
2976
2782
|
// src/llm/output/google.gemini/formatResult.ts
|
|
2977
2783
|
function formatResult4(result) {
|
|
@@ -2996,7 +2802,6 @@ function formatResult4(result) {
|
|
|
2996
2802
|
text: ""
|
|
2997
2803
|
};
|
|
2998
2804
|
}
|
|
2999
|
-
__name(formatResult4, "formatResult");
|
|
3000
2805
|
|
|
3001
2806
|
// src/llm/output/google.gemini/index.ts
|
|
3002
2807
|
function OutputGoogleGeminiChat(result, _config) {
|
|
@@ -3022,7 +2827,6 @@ function OutputGoogleGeminiChat(result, _config) {
|
|
|
3022
2827
|
options
|
|
3023
2828
|
});
|
|
3024
2829
|
}
|
|
3025
|
-
__name(OutputGoogleGeminiChat, "OutputGoogleGeminiChat");
|
|
3026
2830
|
|
|
3027
2831
|
// src/llm/output/index.ts
|
|
3028
2832
|
function getOutputParser(config, response) {
|
|
@@ -3054,7 +2858,6 @@ function getOutputParser(config, response) {
|
|
|
3054
2858
|
}
|
|
3055
2859
|
}
|
|
3056
2860
|
}
|
|
3057
|
-
__name(getOutputParser, "getOutputParser");
|
|
3058
2861
|
|
|
3059
2862
|
// src/utils/modules/debug.ts
|
|
3060
2863
|
function debug(...args) {
|
|
@@ -3066,7 +2869,11 @@ function debug(...args) {
|
|
|
3066
2869
|
} else if (arg instanceof Array) {
|
|
3067
2870
|
logs.push(arg.map((item) => JSON.stringify(item, null, 2)));
|
|
3068
2871
|
} else if (arg instanceof Map) {
|
|
3069
|
-
logs.push(
|
|
2872
|
+
logs.push(
|
|
2873
|
+
Array.from(arg.entries()).map(
|
|
2874
|
+
([key, value]) => `${key}: ${JSON.stringify(value, null, 2)}`
|
|
2875
|
+
)
|
|
2876
|
+
);
|
|
3070
2877
|
} else if (arg instanceof Set) {
|
|
3071
2878
|
logs.push(Array.from(arg).map((item) => JSON.stringify(item, null, 2)));
|
|
3072
2879
|
} else if (arg instanceof Date) {
|
|
@@ -3090,7 +2897,6 @@ function debug(...args) {
|
|
|
3090
2897
|
console.debug(...logs);
|
|
3091
2898
|
}
|
|
3092
2899
|
}
|
|
3093
|
-
__name(debug, "debug");
|
|
3094
2900
|
|
|
3095
2901
|
// src/utils/modules/isValidUrl.ts
|
|
3096
2902
|
function isValidUrl(input) {
|
|
@@ -3101,7 +2907,6 @@ function isValidUrl(input) {
|
|
|
3101
2907
|
return false;
|
|
3102
2908
|
}
|
|
3103
2909
|
}
|
|
3104
|
-
__name(isValidUrl, "isValidUrl");
|
|
3105
2910
|
|
|
3106
2911
|
// src/utils/modules/request.ts
|
|
3107
2912
|
async function apiRequest(url, options) {
|
|
@@ -3137,7 +2942,6 @@ async function apiRequest(url, options) {
|
|
|
3137
2942
|
throw new Error(`Request to ${url} failed: ${message}`);
|
|
3138
2943
|
}
|
|
3139
2944
|
}
|
|
3140
|
-
__name(apiRequest, "apiRequest");
|
|
3141
2945
|
|
|
3142
2946
|
// src/utils/modules/convertDotNotation.ts
|
|
3143
2947
|
function convertDotNotation(obj) {
|
|
@@ -3162,7 +2966,6 @@ function convertDotNotation(obj) {
|
|
|
3162
2966
|
}
|
|
3163
2967
|
return result;
|
|
3164
2968
|
}
|
|
3165
|
-
__name(convertDotNotation, "convertDotNotation");
|
|
3166
2969
|
|
|
3167
2970
|
// src/llm/_utils.mapBody.ts
|
|
3168
2971
|
function mapBody(template, body) {
|
|
@@ -3175,9 +2978,11 @@ function mapBody(template, body) {
|
|
|
3175
2978
|
if (providerSpecificKey) {
|
|
3176
2979
|
let valueForThisKey = body[genericInputKey];
|
|
3177
2980
|
if (providerSpecificSettings.sanitize && typeof providerSpecificSettings.sanitize === "function") {
|
|
3178
|
-
valueForThisKey = providerSpecificSettings.sanitize(
|
|
3179
|
-
|
|
3180
|
-
|
|
2981
|
+
valueForThisKey = providerSpecificSettings.sanitize(
|
|
2982
|
+
valueForThisKey,
|
|
2983
|
+
Object.freeze({ ...body }),
|
|
2984
|
+
output
|
|
2985
|
+
);
|
|
3181
2986
|
}
|
|
3182
2987
|
if (typeof valueForThisKey !== "undefined") {
|
|
3183
2988
|
output[providerSpecificKey] = valueForThisKey;
|
|
@@ -3188,127 +2993,16 @@ function mapBody(template, body) {
|
|
|
3188
2993
|
}
|
|
3189
2994
|
return convertDotNotation(output);
|
|
3190
2995
|
}
|
|
3191
|
-
__name(mapBody, "mapBody");
|
|
3192
2996
|
|
|
3193
2997
|
// src/utils/modules/getAwsAuthorizationHeaders.ts
|
|
3194
2998
|
import { fromNodeProviderChain } from "@aws-sdk/credential-providers";
|
|
3195
2999
|
import { SignatureV4 } from "@smithy/signature-v4";
|
|
3196
|
-
|
|
3197
|
-
// node_modules/@smithy/types/dist-es/auth/auth.js
|
|
3198
|
-
var HttpAuthLocation;
|
|
3199
|
-
(function(HttpAuthLocation2) {
|
|
3200
|
-
HttpAuthLocation2["HEADER"] = "header";
|
|
3201
|
-
HttpAuthLocation2["QUERY"] = "query";
|
|
3202
|
-
})(HttpAuthLocation || (HttpAuthLocation = {}));
|
|
3203
|
-
|
|
3204
|
-
// node_modules/@smithy/types/dist-es/auth/HttpApiKeyAuth.js
|
|
3205
|
-
var HttpApiKeyAuthLocation;
|
|
3206
|
-
(function(HttpApiKeyAuthLocation2) {
|
|
3207
|
-
HttpApiKeyAuthLocation2["HEADER"] = "header";
|
|
3208
|
-
HttpApiKeyAuthLocation2["QUERY"] = "query";
|
|
3209
|
-
})(HttpApiKeyAuthLocation || (HttpApiKeyAuthLocation = {}));
|
|
3210
|
-
|
|
3211
|
-
// node_modules/@smithy/types/dist-es/endpoint.js
|
|
3212
|
-
var EndpointURLScheme;
|
|
3213
|
-
(function(EndpointURLScheme2) {
|
|
3214
|
-
EndpointURLScheme2["HTTP"] = "http";
|
|
3215
|
-
EndpointURLScheme2["HTTPS"] = "https";
|
|
3216
|
-
})(EndpointURLScheme || (EndpointURLScheme = {}));
|
|
3217
|
-
|
|
3218
|
-
// node_modules/@smithy/types/dist-es/extensions/checksum.js
|
|
3219
|
-
var AlgorithmId;
|
|
3220
|
-
(function(AlgorithmId2) {
|
|
3221
|
-
AlgorithmId2["MD5"] = "md5";
|
|
3222
|
-
AlgorithmId2["CRC32"] = "crc32";
|
|
3223
|
-
AlgorithmId2["CRC32C"] = "crc32c";
|
|
3224
|
-
AlgorithmId2["SHA1"] = "sha1";
|
|
3225
|
-
AlgorithmId2["SHA256"] = "sha256";
|
|
3226
|
-
})(AlgorithmId || (AlgorithmId = {}));
|
|
3227
|
-
|
|
3228
|
-
// node_modules/@smithy/types/dist-es/http.js
|
|
3229
|
-
var FieldPosition;
|
|
3230
|
-
(function(FieldPosition2) {
|
|
3231
|
-
FieldPosition2[FieldPosition2["HEADER"] = 0] = "HEADER";
|
|
3232
|
-
FieldPosition2[FieldPosition2["TRAILER"] = 1] = "TRAILER";
|
|
3233
|
-
})(FieldPosition || (FieldPosition = {}));
|
|
3234
|
-
|
|
3235
|
-
// node_modules/@smithy/types/dist-es/profile.js
|
|
3236
|
-
var IniSectionType;
|
|
3237
|
-
(function(IniSectionType2) {
|
|
3238
|
-
IniSectionType2["PROFILE"] = "profile";
|
|
3239
|
-
IniSectionType2["SSO_SESSION"] = "sso-session";
|
|
3240
|
-
IniSectionType2["SERVICES"] = "services";
|
|
3241
|
-
})(IniSectionType || (IniSectionType = {}));
|
|
3242
|
-
|
|
3243
|
-
// node_modules/@smithy/types/dist-es/transfer.js
|
|
3244
|
-
var RequestHandlerProtocol;
|
|
3245
|
-
(function(RequestHandlerProtocol2) {
|
|
3246
|
-
RequestHandlerProtocol2["HTTP_0_9"] = "http/0.9";
|
|
3247
|
-
RequestHandlerProtocol2["HTTP_1_0"] = "http/1.0";
|
|
3248
|
-
RequestHandlerProtocol2["TDS_8_0"] = "tds/8.0";
|
|
3249
|
-
})(RequestHandlerProtocol || (RequestHandlerProtocol = {}));
|
|
3250
|
-
|
|
3251
|
-
// node_modules/@smithy/protocol-http/dist-es/httpRequest.js
|
|
3252
|
-
var _HttpRequest = class _HttpRequest {
|
|
3253
|
-
constructor(options) {
|
|
3254
|
-
this.method = options.method || "GET";
|
|
3255
|
-
this.hostname = options.hostname || "localhost";
|
|
3256
|
-
this.port = options.port;
|
|
3257
|
-
this.query = options.query || {};
|
|
3258
|
-
this.headers = options.headers || {};
|
|
3259
|
-
this.body = options.body;
|
|
3260
|
-
this.protocol = options.protocol ? options.protocol.slice(-1) !== ":" ? `${options.protocol}:` : options.protocol : "https:";
|
|
3261
|
-
this.path = options.path ? options.path.charAt(0) !== "/" ? `/${options.path}` : options.path : "/";
|
|
3262
|
-
this.username = options.username;
|
|
3263
|
-
this.password = options.password;
|
|
3264
|
-
this.fragment = options.fragment;
|
|
3265
|
-
}
|
|
3266
|
-
static clone(request) {
|
|
3267
|
-
const cloned = new _HttpRequest({
|
|
3268
|
-
...request,
|
|
3269
|
-
headers: {
|
|
3270
|
-
...request.headers
|
|
3271
|
-
}
|
|
3272
|
-
});
|
|
3273
|
-
if (cloned.query) {
|
|
3274
|
-
cloned.query = cloneQuery(cloned.query);
|
|
3275
|
-
}
|
|
3276
|
-
return cloned;
|
|
3277
|
-
}
|
|
3278
|
-
static isInstance(request) {
|
|
3279
|
-
if (!request) {
|
|
3280
|
-
return false;
|
|
3281
|
-
}
|
|
3282
|
-
const req = request;
|
|
3283
|
-
return "method" in req && "protocol" in req && "hostname" in req && "path" in req && typeof req["query"] === "object" && typeof req["headers"] === "object";
|
|
3284
|
-
}
|
|
3285
|
-
clone() {
|
|
3286
|
-
return _HttpRequest.clone(this);
|
|
3287
|
-
}
|
|
3288
|
-
};
|
|
3289
|
-
__name(_HttpRequest, "HttpRequest");
|
|
3290
|
-
var HttpRequest = _HttpRequest;
|
|
3291
|
-
function cloneQuery(query) {
|
|
3292
|
-
return Object.keys(query).reduce((carry, paramName) => {
|
|
3293
|
-
const param = query[paramName];
|
|
3294
|
-
return {
|
|
3295
|
-
...carry,
|
|
3296
|
-
[paramName]: Array.isArray(param) ? [
|
|
3297
|
-
...param
|
|
3298
|
-
] : param
|
|
3299
|
-
};
|
|
3300
|
-
}, {});
|
|
3301
|
-
}
|
|
3302
|
-
__name(cloneQuery, "cloneQuery");
|
|
3303
|
-
|
|
3304
|
-
// src/utils/modules/getAwsAuthorizationHeaders.ts
|
|
3000
|
+
import { HttpRequest } from "@smithy/protocol-http";
|
|
3305
3001
|
import { Sha256 } from "@aws-crypto/sha256-js";
|
|
3306
3002
|
|
|
3307
3003
|
// src/utils/modules/runWithTemporaryEnv.ts
|
|
3308
3004
|
async function runWithTemporaryEnv(env, handler) {
|
|
3309
|
-
const previousEnv = {
|
|
3310
|
-
...process.env
|
|
3311
|
-
};
|
|
3005
|
+
const previousEnv = { ...process.env };
|
|
3312
3006
|
try {
|
|
3313
3007
|
env();
|
|
3314
3008
|
const value = await handler();
|
|
@@ -3317,22 +3011,24 @@ async function runWithTemporaryEnv(env, handler) {
|
|
|
3317
3011
|
process.env = previousEnv;
|
|
3318
3012
|
}
|
|
3319
3013
|
}
|
|
3320
|
-
__name(runWithTemporaryEnv, "runWithTemporaryEnv");
|
|
3321
3014
|
|
|
3322
3015
|
// src/utils/modules/getAwsAuthorizationHeaders.ts
|
|
3323
3016
|
async function getAwsAuthorizationHeaders(req, props) {
|
|
3324
3017
|
const providerChain = fromNodeProviderChain();
|
|
3325
|
-
const credentials = await runWithTemporaryEnv(
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
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
|
+
);
|
|
3336
3032
|
const signer = new SignatureV4({
|
|
3337
3033
|
service: "bedrock",
|
|
3338
3034
|
region: props.regionName,
|
|
@@ -3340,11 +3036,7 @@ async function getAwsAuthorizationHeaders(req, props) {
|
|
|
3340
3036
|
sha256: Sha256
|
|
3341
3037
|
});
|
|
3342
3038
|
const url = new URL(props.url);
|
|
3343
|
-
const headers = !req.headers ? {} : Symbol.iterator in req.headers ? Object.fromEntries(Array.from(req.headers).map((header) => [
|
|
3344
|
-
...header
|
|
3345
|
-
])) : {
|
|
3346
|
-
...req.headers
|
|
3347
|
-
};
|
|
3039
|
+
const headers = !req.headers ? {} : Symbol.iterator in req.headers ? Object.fromEntries(Array.from(req.headers).map((header) => [...header])) : { ...req.headers };
|
|
3348
3040
|
delete headers["connection"];
|
|
3349
3041
|
headers["host"] = url.hostname;
|
|
3350
3042
|
const request = new HttpRequest({
|
|
@@ -3357,7 +3049,6 @@ async function getAwsAuthorizationHeaders(req, props) {
|
|
|
3357
3049
|
const signed = await signer.sign(request);
|
|
3358
3050
|
return signed.headers;
|
|
3359
3051
|
}
|
|
3360
|
-
__name(getAwsAuthorizationHeaders, "getAwsAuthorizationHeaders");
|
|
3361
3052
|
|
|
3362
3053
|
// src/llm/_utils.parseHeaders.ts
|
|
3363
3054
|
async function parseHeaders(config, replacements, payload) {
|
|
@@ -3366,27 +3057,28 @@ async function parseHeaders(config, replacements, payload) {
|
|
|
3366
3057
|
const headers = Object.assign({}, payload.headers, parse);
|
|
3367
3058
|
if (config.provider.startsWith("amazon:") || config.provider.startsWith("amazon.")) {
|
|
3368
3059
|
const url = payload.url;
|
|
3369
|
-
return getAwsAuthorizationHeaders(
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
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
|
+
);
|
|
3379
3073
|
} else {
|
|
3380
3074
|
return headers;
|
|
3381
3075
|
}
|
|
3382
3076
|
}
|
|
3383
|
-
__name(parseHeaders, "parseHeaders");
|
|
3384
3077
|
|
|
3385
3078
|
// src/llm/output/_utils/cleanJsonSchemaFor.ts
|
|
3386
3079
|
var providerFieldExclusions = {
|
|
3387
|
-
"openai.chat": [
|
|
3388
|
-
|
|
3389
|
-
]
|
|
3080
|
+
"openai.chat": ["default"]
|
|
3081
|
+
// fields to exclude for openai.chat
|
|
3390
3082
|
};
|
|
3391
3083
|
function cleanJsonSchemaFor(schema = {}, provider) {
|
|
3392
3084
|
const clone = deepClone(schema);
|
|
@@ -3404,18 +3096,19 @@ function cleanJsonSchemaFor(schema = {}, provider) {
|
|
|
3404
3096
|
}
|
|
3405
3097
|
return obj;
|
|
3406
3098
|
}
|
|
3407
|
-
__name(removeDisallowedFields, "removeDisallowedFields");
|
|
3408
3099
|
return removeDisallowedFields(clone);
|
|
3409
3100
|
}
|
|
3410
|
-
__name(cleanJsonSchemaFor, "cleanJsonSchemaFor");
|
|
3411
3101
|
|
|
3412
3102
|
// src/llm/llm.call.ts
|
|
3413
3103
|
async function useLlm_call(state, messages, _options) {
|
|
3414
3104
|
const config = getLlmConfig(state.key);
|
|
3415
3105
|
const { functionCallStrictInput = false } = _options || {};
|
|
3416
|
-
const input = mapBody(
|
|
3417
|
-
|
|
3418
|
-
|
|
3106
|
+
const input = mapBody(
|
|
3107
|
+
config.mapBody,
|
|
3108
|
+
Object.assign({}, state, {
|
|
3109
|
+
prompt: messages
|
|
3110
|
+
})
|
|
3111
|
+
);
|
|
3419
3112
|
if (_options && _options?.jsonSchema) {
|
|
3420
3113
|
if (state.provider === "openai.chat") {
|
|
3421
3114
|
const curr = input["response_format"] || {};
|
|
@@ -3434,14 +3127,15 @@ async function useLlm_call(state, messages, _options) {
|
|
|
3434
3127
|
if (_options?.functionCall === "none") {
|
|
3435
3128
|
_options.functions = [];
|
|
3436
3129
|
} else if (_options?.functionCall === "auto" || _options?.functionCall === "any") {
|
|
3437
|
-
input["tool_choice"] = {
|
|
3438
|
-
type: _options?.functionCall
|
|
3439
|
-
};
|
|
3130
|
+
input["tool_choice"] = { type: _options?.functionCall };
|
|
3440
3131
|
} else {
|
|
3441
3132
|
input["tool_choice"] = _options?.functionCall;
|
|
3442
3133
|
}
|
|
3443
3134
|
} else if (state.provider === "openai.chat") {
|
|
3444
|
-
input["tool_choice"] = normalizeFunctionCall(
|
|
3135
|
+
input["tool_choice"] = normalizeFunctionCall(
|
|
3136
|
+
_options?.functionCall,
|
|
3137
|
+
"openai"
|
|
3138
|
+
);
|
|
3445
3139
|
}
|
|
3446
3140
|
}
|
|
3447
3141
|
if (_options && _options?.functions?.length) {
|
|
@@ -3460,11 +3154,13 @@ async function useLlm_call(state, messages, _options) {
|
|
|
3460
3154
|
};
|
|
3461
3155
|
return {
|
|
3462
3156
|
type: "function",
|
|
3463
|
-
function: Object.assign(
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3157
|
+
function: Object.assign(
|
|
3158
|
+
props,
|
|
3159
|
+
{
|
|
3160
|
+
parameters: cleanJsonSchemaFor(props.parameters, "openai.chat")
|
|
3161
|
+
},
|
|
3162
|
+
{ strict: functionCallStrictInput }
|
|
3163
|
+
)
|
|
3468
3164
|
};
|
|
3469
3165
|
});
|
|
3470
3166
|
}
|
|
@@ -3480,16 +3176,14 @@ async function useLlm_call(state, messages, _options) {
|
|
|
3480
3176
|
id: "0123-45-6789",
|
|
3481
3177
|
model: "model",
|
|
3482
3178
|
created: (/* @__PURE__ */ new Date()).getTime(),
|
|
3483
|
-
usage: {
|
|
3484
|
-
completion_tokens: 0,
|
|
3485
|
-
prompt_tokens: 0,
|
|
3486
|
-
total_tokens: 0
|
|
3487
|
-
},
|
|
3179
|
+
usage: { completion_tokens: 0, prompt_tokens: 0, total_tokens: 0 },
|
|
3488
3180
|
choices: [
|
|
3489
3181
|
{
|
|
3490
3182
|
message: {
|
|
3491
3183
|
role: "assistant",
|
|
3492
|
-
content: `Hello world from LLM! The input was ${JSON.stringify(
|
|
3184
|
+
content: `Hello world from LLM! The input was ${JSON.stringify(
|
|
3185
|
+
messages
|
|
3186
|
+
)}`
|
|
3493
3187
|
}
|
|
3494
3188
|
}
|
|
3495
3189
|
]
|
|
@@ -3500,7 +3194,6 @@ async function useLlm_call(state, messages, _options) {
|
|
|
3500
3194
|
});
|
|
3501
3195
|
return getOutputParser(state, response);
|
|
3502
3196
|
}
|
|
3503
|
-
__name(useLlm_call, "useLlm_call");
|
|
3504
3197
|
|
|
3505
3198
|
// src/llm/_utils.stateFromOptions.ts
|
|
3506
3199
|
function stateFromOptions(options, config) {
|
|
@@ -3519,16 +3212,16 @@ function stateFromOptions(options, config) {
|
|
|
3519
3212
|
state[key] = thisConfig.default;
|
|
3520
3213
|
}
|
|
3521
3214
|
}
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
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") {
|
|
3525
3219
|
throw new Error(message);
|
|
3526
3220
|
}
|
|
3527
3221
|
}
|
|
3528
3222
|
}
|
|
3529
3223
|
return state;
|
|
3530
3224
|
}
|
|
3531
|
-
__name(stateFromOptions, "stateFromOptions");
|
|
3532
3225
|
|
|
3533
3226
|
// src/utils/modules/deepFreeze.ts
|
|
3534
3227
|
function deepFreeze(obj) {
|
|
@@ -3545,13 +3238,14 @@ function deepFreeze(obj) {
|
|
|
3545
3238
|
}
|
|
3546
3239
|
if (typeof obj === "object" && obj !== null) {
|
|
3547
3240
|
for (const key of Object.keys(obj)) {
|
|
3548
|
-
obj[key] = deepFreeze(
|
|
3241
|
+
obj[key] = deepFreeze(
|
|
3242
|
+
obj[key]
|
|
3243
|
+
);
|
|
3549
3244
|
}
|
|
3550
3245
|
return Object.freeze(obj);
|
|
3551
3246
|
}
|
|
3552
3247
|
return obj;
|
|
3553
3248
|
}
|
|
3554
|
-
__name(deepFreeze, "deepFreeze");
|
|
3555
3249
|
|
|
3556
3250
|
// src/utils/modules/requestWrapper.ts
|
|
3557
3251
|
import { backOff } from "exponential-backoff";
|
|
@@ -3572,19 +3266,29 @@ function apiRequestWrapper(config, options, handler, doNotRetryErrorMessages = [
|
|
|
3572
3266
|
async function call(messages, options2) {
|
|
3573
3267
|
try {
|
|
3574
3268
|
metrics.total_calls++;
|
|
3575
|
-
const result = await backOff(
|
|
3576
|
-
|
|
3577
|
-
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
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;
|
|
3583
3289
|
}
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
}, "retry")
|
|
3587
|
-
});
|
|
3290
|
+
}
|
|
3291
|
+
);
|
|
3588
3292
|
metrics.total_call_success++;
|
|
3589
3293
|
return result;
|
|
3590
3294
|
} catch (error) {
|
|
@@ -3592,29 +3296,32 @@ function apiRequestWrapper(config, options, handler, doNotRetryErrorMessages = [
|
|
|
3592
3296
|
throw error;
|
|
3593
3297
|
}
|
|
3594
3298
|
}
|
|
3595
|
-
__name(call, "call");
|
|
3596
3299
|
function getMetadata() {
|
|
3597
|
-
const {
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
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
|
+
);
|
|
3608
3318
|
}
|
|
3609
|
-
__name(getMetadata, "getMetadata");
|
|
3610
3319
|
function getTraceId() {
|
|
3611
3320
|
return traceId;
|
|
3612
3321
|
}
|
|
3613
|
-
__name(getTraceId, "getTraceId");
|
|
3614
3322
|
function withTraceId(id) {
|
|
3615
3323
|
traceId = id;
|
|
3616
3324
|
}
|
|
3617
|
-
__name(withTraceId, "withTraceId");
|
|
3618
3325
|
return {
|
|
3619
3326
|
call,
|
|
3620
3327
|
getTraceId,
|
|
@@ -3622,14 +3329,12 @@ function apiRequestWrapper(config, options, handler, doNotRetryErrorMessages = [
|
|
|
3622
3329
|
getMetadata
|
|
3623
3330
|
};
|
|
3624
3331
|
}
|
|
3625
|
-
__name(apiRequestWrapper, "apiRequestWrapper");
|
|
3626
3332
|
|
|
3627
3333
|
// src/llm/llm.ts
|
|
3628
3334
|
function useLlm(provider, options = {}) {
|
|
3629
3335
|
const config = getLlmConfig(provider);
|
|
3630
3336
|
return apiRequestWrapper(config, options, useLlm_call);
|
|
3631
3337
|
}
|
|
3632
|
-
__name(useLlm, "useLlm");
|
|
3633
3338
|
|
|
3634
3339
|
// src/embedding/config.ts
|
|
3635
3340
|
var embeddingConfigs = {
|
|
@@ -3677,10 +3382,7 @@ var embeddingConfigs = {
|
|
|
3677
3382
|
},
|
|
3678
3383
|
awsRegion: {
|
|
3679
3384
|
default: getEnvironmentVariable("AWS_REGION"),
|
|
3680
|
-
required: [
|
|
3681
|
-
true,
|
|
3682
|
-
"aws region is required"
|
|
3683
|
-
]
|
|
3385
|
+
required: [true, "aws region is required"]
|
|
3684
3386
|
},
|
|
3685
3387
|
awsSecretKey: {},
|
|
3686
3388
|
awsAccessKey: {}
|
|
@@ -3705,7 +3407,6 @@ function getEmbeddingConfig(provider) {
|
|
|
3705
3407
|
}
|
|
3706
3408
|
throw new Error(`Invalid provider: ${provider}`);
|
|
3707
3409
|
}
|
|
3708
|
-
__name(getEmbeddingConfig, "getEmbeddingConfig");
|
|
3709
3410
|
|
|
3710
3411
|
// src/embedding/output/BaseEmbeddingOutput.ts
|
|
3711
3412
|
function BaseEmbeddingOutput(result) {
|
|
@@ -3713,9 +3414,7 @@ function BaseEmbeddingOutput(result) {
|
|
|
3713
3414
|
id: result.id || uuidv4(),
|
|
3714
3415
|
model: result.model,
|
|
3715
3416
|
usage: result.usage,
|
|
3716
|
-
embedding: [
|
|
3717
|
-
...result?.embedding || []
|
|
3718
|
-
],
|
|
3417
|
+
embedding: [...result?.embedding || []],
|
|
3719
3418
|
created: result?.created || (/* @__PURE__ */ new Date()).getTime()
|
|
3720
3419
|
});
|
|
3721
3420
|
function getResult() {
|
|
@@ -3727,7 +3426,6 @@ function BaseEmbeddingOutput(result) {
|
|
|
3727
3426
|
embedding: __result.embedding
|
|
3728
3427
|
};
|
|
3729
3428
|
}
|
|
3730
|
-
__name(getResult, "getResult");
|
|
3731
3429
|
function getEmbedding(index) {
|
|
3732
3430
|
if (index && index > 0) {
|
|
3733
3431
|
const arr = __result?.embedding;
|
|
@@ -3736,22 +3434,18 @@ function BaseEmbeddingOutput(result) {
|
|
|
3736
3434
|
}
|
|
3737
3435
|
return __result.embedding[0];
|
|
3738
3436
|
}
|
|
3739
|
-
__name(getEmbedding, "getEmbedding");
|
|
3740
3437
|
return {
|
|
3741
3438
|
getEmbedding,
|
|
3742
3439
|
getResult
|
|
3743
3440
|
};
|
|
3744
3441
|
}
|
|
3745
|
-
__name(BaseEmbeddingOutput, "BaseEmbeddingOutput");
|
|
3746
3442
|
|
|
3747
3443
|
// src/embedding/output/AmazonTitan.ts
|
|
3748
3444
|
function AmazonTitanEmbedding(result, config) {
|
|
3749
3445
|
const __result = deepClone(result);
|
|
3750
3446
|
const model = config.model || "amazon.unknown";
|
|
3751
3447
|
const created = (/* @__PURE__ */ new Date()).getTime();
|
|
3752
|
-
const embedding = [
|
|
3753
|
-
__result.embedding
|
|
3754
|
-
];
|
|
3448
|
+
const embedding = [__result.embedding];
|
|
3755
3449
|
const usage = {
|
|
3756
3450
|
output_tokens: 0,
|
|
3757
3451
|
input_tokens: __result.inputTextTokenCount,
|
|
@@ -3764,7 +3458,6 @@ function AmazonTitanEmbedding(result, config) {
|
|
|
3764
3458
|
embedding
|
|
3765
3459
|
});
|
|
3766
3460
|
}
|
|
3767
|
-
__name(AmazonTitanEmbedding, "AmazonTitanEmbedding");
|
|
3768
3461
|
|
|
3769
3462
|
// src/embedding/output/OpenAiEmbedding.ts
|
|
3770
3463
|
function OpenAiEmbedding(result, config) {
|
|
@@ -3785,7 +3478,6 @@ function OpenAiEmbedding(result, config) {
|
|
|
3785
3478
|
embedding
|
|
3786
3479
|
});
|
|
3787
3480
|
}
|
|
3788
|
-
__name(OpenAiEmbedding, "OpenAiEmbedding");
|
|
3789
3481
|
|
|
3790
3482
|
// src/embedding/output/getEmbeddingOutputParser.ts
|
|
3791
3483
|
function getEmbeddingOutputParser(config, response) {
|
|
@@ -3798,14 +3490,16 @@ function getEmbeddingOutputParser(config, response) {
|
|
|
3798
3490
|
throw new Error("Unsupported provider");
|
|
3799
3491
|
}
|
|
3800
3492
|
}
|
|
3801
|
-
__name(getEmbeddingOutputParser, "getEmbeddingOutputParser");
|
|
3802
3493
|
|
|
3803
3494
|
// src/embedding/embedding.call.ts
|
|
3804
3495
|
async function createEmbedding_call(state, _input, _options) {
|
|
3805
3496
|
const config = getEmbeddingConfig(state.key);
|
|
3806
|
-
const input = mapBody(
|
|
3807
|
-
|
|
3808
|
-
|
|
3497
|
+
const input = mapBody(
|
|
3498
|
+
config.mapBody,
|
|
3499
|
+
Object.assign({}, state, {
|
|
3500
|
+
input: _input
|
|
3501
|
+
})
|
|
3502
|
+
);
|
|
3809
3503
|
const body = JSON.stringify(input);
|
|
3810
3504
|
const url = replaceTemplateStringSimple(config.endpoint, state);
|
|
3811
3505
|
const headers = await parseHeaders(config, state, {
|
|
@@ -3820,21 +3514,19 @@ async function createEmbedding_call(state, _input, _options) {
|
|
|
3820
3514
|
});
|
|
3821
3515
|
return getEmbeddingOutputParser(state, request);
|
|
3822
3516
|
}
|
|
3823
|
-
__name(createEmbedding_call, "createEmbedding_call");
|
|
3824
3517
|
|
|
3825
3518
|
// src/embedding/embedding.ts
|
|
3826
3519
|
function createEmbedding(provider, options) {
|
|
3827
3520
|
const config = getEmbeddingConfig(provider);
|
|
3828
3521
|
return apiRequestWrapper(config, options, createEmbedding_call);
|
|
3829
3522
|
}
|
|
3830
|
-
__name(createEmbedding, "createEmbedding");
|
|
3831
3523
|
|
|
3832
3524
|
// src/prompt/_base.ts
|
|
3833
|
-
var
|
|
3525
|
+
var BasePrompt = class {
|
|
3834
3526
|
/**
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3527
|
+
* constructor description
|
|
3528
|
+
* @param initialPromptMessage An initial message to add to the prompt.
|
|
3529
|
+
*/
|
|
3838
3530
|
constructor(initialPromptMessage, options) {
|
|
3839
3531
|
__publicField(this, "type", "text");
|
|
3840
3532
|
__publicField(this, "messages", []);
|
|
@@ -3868,11 +3560,11 @@ var _BasePrompt = class _BasePrompt {
|
|
|
3868
3560
|
}
|
|
3869
3561
|
}
|
|
3870
3562
|
/**
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
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
|
+
*/
|
|
3876
3568
|
addToPrompt(content, role = "system") {
|
|
3877
3569
|
if (content) {
|
|
3878
3570
|
switch (role) {
|
|
@@ -3885,10 +3577,10 @@ var _BasePrompt = class _BasePrompt {
|
|
|
3885
3577
|
return this;
|
|
3886
3578
|
}
|
|
3887
3579
|
/**
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3580
|
+
* addSystemMessage description
|
|
3581
|
+
* @param content The message content
|
|
3582
|
+
* @return returns BasePrompt so it can be chained.
|
|
3583
|
+
*/
|
|
3892
3584
|
addSystemMessage(content) {
|
|
3893
3585
|
this.messages.push({
|
|
3894
3586
|
role: "system",
|
|
@@ -3897,58 +3589,62 @@ var _BasePrompt = class _BasePrompt {
|
|
|
3897
3589
|
return this;
|
|
3898
3590
|
}
|
|
3899
3591
|
/**
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
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
|
+
*/
|
|
3904
3596
|
registerPartial(partialOrPartials) {
|
|
3905
|
-
const partials2 = Array.isArray(partialOrPartials) ? partialOrPartials : [
|
|
3906
|
-
partialOrPartials
|
|
3907
|
-
];
|
|
3597
|
+
const partials2 = Array.isArray(partialOrPartials) ? partialOrPartials : [partialOrPartials];
|
|
3908
3598
|
this.partials.push(...partials2);
|
|
3909
3599
|
return this;
|
|
3910
3600
|
}
|
|
3911
3601
|
/**
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
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
|
+
*/
|
|
3916
3606
|
registerHelpers(helperOrHelpers) {
|
|
3917
|
-
const helpers = Array.isArray(helperOrHelpers) ? helperOrHelpers : [
|
|
3918
|
-
helperOrHelpers
|
|
3919
|
-
];
|
|
3607
|
+
const helpers = Array.isArray(helperOrHelpers) ? helperOrHelpers : [helperOrHelpers];
|
|
3920
3608
|
this.helpers.push(...helpers);
|
|
3921
3609
|
return this;
|
|
3922
3610
|
}
|
|
3923
3611
|
/**
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
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
|
+
*/
|
|
3929
3617
|
format(values, separator = "\n\n") {
|
|
3930
3618
|
const replacements = this.getReplacements(values);
|
|
3931
3619
|
const messages = this.messages.map((message) => {
|
|
3932
|
-
return message.content && !Array.isArray(message.content) ? this.replaceTemplateString(
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
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
|
+
) : "";
|
|
3936
3628
|
}).join(separator);
|
|
3937
3629
|
return this.runPromptFilter(messages, this.filters.post, values);
|
|
3938
3630
|
}
|
|
3939
3631
|
/**
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
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
|
+
*/
|
|
3945
3637
|
async formatAsync(values, separator = "\n\n") {
|
|
3946
3638
|
const replacements = this.getReplacements(values);
|
|
3947
3639
|
const _messages = await Promise.all(this.messages.map((message) => {
|
|
3948
|
-
return message.content && !Array.isArray(message.content) ? this.replaceTemplateStringAsync(
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
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
|
+
) : "";
|
|
3952
3648
|
}));
|
|
3953
3649
|
const messages = _messages.join(separator);
|
|
3954
3650
|
return this.runPromptFilter(messages, this.filters.post, values);
|
|
@@ -3962,33 +3658,31 @@ var _BasePrompt = class _BasePrompt {
|
|
|
3962
3658
|
}
|
|
3963
3659
|
getReplacements(values) {
|
|
3964
3660
|
const { input = "", ...restOfValues } = values;
|
|
3965
|
-
const replacements = Object.assign(
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3661
|
+
const replacements = Object.assign(
|
|
3662
|
+
{},
|
|
3663
|
+
{ ...restOfValues },
|
|
3664
|
+
{
|
|
3665
|
+
input,
|
|
3666
|
+
_input: input
|
|
3667
|
+
}
|
|
3668
|
+
);
|
|
3971
3669
|
return replacements;
|
|
3972
3670
|
}
|
|
3973
3671
|
/**
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3672
|
+
* validate description
|
|
3673
|
+
* @return {boolean} Returns false if the template is not valid.
|
|
3674
|
+
*/
|
|
3977
3675
|
validate() {
|
|
3978
3676
|
return true;
|
|
3979
3677
|
}
|
|
3980
3678
|
};
|
|
3981
|
-
__name(_BasePrompt, "BasePrompt");
|
|
3982
|
-
var BasePrompt = _BasePrompt;
|
|
3983
3679
|
|
|
3984
3680
|
// src/prompt/text.ts
|
|
3985
|
-
var
|
|
3681
|
+
var TextPrompt = class extends BasePrompt {
|
|
3986
3682
|
constructor(base, options) {
|
|
3987
3683
|
super(base, options);
|
|
3988
3684
|
}
|
|
3989
3685
|
};
|
|
3990
|
-
__name(_TextPrompt, "TextPrompt");
|
|
3991
|
-
var TextPrompt = _TextPrompt;
|
|
3992
3686
|
|
|
3993
3687
|
// src/utils/modules/unescape.ts
|
|
3994
3688
|
function unescape(str) {
|
|
@@ -4002,13 +3696,10 @@ function unescape(str) {
|
|
|
4002
3696
|
const entityRegex = /&|<|>|"|'/g;
|
|
4003
3697
|
return str.replace(entityRegex, (m) => map[m]);
|
|
4004
3698
|
}
|
|
4005
|
-
__name(unescape, "unescape");
|
|
4006
3699
|
|
|
4007
3700
|
// src/utils/modules/extractPromptPlaceholderToken.ts
|
|
4008
3701
|
function extractPromptPlaceholderToken(tok) {
|
|
4009
|
-
if (!tok) return {
|
|
4010
|
-
token: ""
|
|
4011
|
-
};
|
|
3702
|
+
if (!tok) return { token: "" };
|
|
4012
3703
|
const token = tok.replace(/ /g, "");
|
|
4013
3704
|
if (token.substring(2, 18) === ">DialogueHistory") {
|
|
4014
3705
|
const matchKey = tok.match(/key=(['"`])((?:(?!\1).)*)\1/);
|
|
@@ -4035,11 +3726,8 @@ function extractPromptPlaceholderToken(tok) {
|
|
|
4035
3726
|
};
|
|
4036
3727
|
}
|
|
4037
3728
|
}
|
|
4038
|
-
return {
|
|
4039
|
-
token: ""
|
|
4040
|
-
};
|
|
3729
|
+
return { token: "" };
|
|
4041
3730
|
}
|
|
4042
|
-
__name(extractPromptPlaceholderToken, "extractPromptPlaceholderToken");
|
|
4043
3731
|
|
|
4044
3732
|
// src/utils/modules/escape.ts
|
|
4045
3733
|
function escape(str) {
|
|
@@ -4052,29 +3740,28 @@ function escape(str) {
|
|
|
4052
3740
|
};
|
|
4053
3741
|
return str.replace(/[&<>"']/g, (m) => map[m]);
|
|
4054
3742
|
}
|
|
4055
|
-
__name(escape, "escape");
|
|
4056
3743
|
|
|
4057
3744
|
// src/prompt/chat.ts
|
|
4058
|
-
var
|
|
3745
|
+
var ChatPrompt = class extends BasePrompt {
|
|
4059
3746
|
/**
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
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
|
+
*/
|
|
4064
3751
|
constructor(initialSystemPromptMessage, options) {
|
|
4065
3752
|
super(initialSystemPromptMessage, options);
|
|
4066
3753
|
/**
|
|
4067
|
-
|
|
4068
|
-
|
|
3754
|
+
* @property type - Prompt type (chat)
|
|
3755
|
+
*/
|
|
4069
3756
|
__publicField(this, "type", "chat");
|
|
4070
3757
|
/**
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
__publicField(this, "parseUserTemplates",
|
|
4076
|
-
if (options?.allowUnsafeUserTemplate) {
|
|
4077
|
-
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;
|
|
4078
3765
|
}
|
|
4079
3766
|
}
|
|
4080
3767
|
addToPrompt(content, role, name) {
|
|
@@ -4095,21 +3782,18 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4095
3782
|
break;
|
|
4096
3783
|
case "function_call":
|
|
4097
3784
|
assert(name, "Function message requires name");
|
|
4098
|
-
this.addFunctionCallMessage({
|
|
4099
|
-
name,
|
|
4100
|
-
arguments: content
|
|
4101
|
-
});
|
|
3785
|
+
this.addFunctionCallMessage({ name, arguments: content });
|
|
4102
3786
|
break;
|
|
4103
3787
|
}
|
|
4104
3788
|
}
|
|
4105
3789
|
return this;
|
|
4106
3790
|
}
|
|
4107
3791
|
/**
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
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
|
+
*/
|
|
4113
3797
|
addUserMessage(content, name) {
|
|
4114
3798
|
const message = {
|
|
4115
3799
|
role: "user",
|
|
@@ -4122,10 +3806,10 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4122
3806
|
return this;
|
|
4123
3807
|
}
|
|
4124
3808
|
/**
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
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
|
+
*/
|
|
4129
3813
|
addAssistantMessage(content) {
|
|
4130
3814
|
this.messages.push({
|
|
4131
3815
|
role: "assistant",
|
|
@@ -4134,10 +3818,10 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4134
3818
|
return this;
|
|
4135
3819
|
}
|
|
4136
3820
|
/**
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
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
|
+
*/
|
|
4141
3825
|
addFunctionMessage(content, name) {
|
|
4142
3826
|
this.messages.push({
|
|
4143
3827
|
role: "function",
|
|
@@ -4147,10 +3831,10 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4147
3831
|
return this;
|
|
4148
3832
|
}
|
|
4149
3833
|
/**
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
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
|
+
*/
|
|
4154
3838
|
addFunctionCallMessage(function_call) {
|
|
4155
3839
|
if (function_call) {
|
|
4156
3840
|
this.messages.push({
|
|
@@ -4165,10 +3849,10 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4165
3849
|
return this;
|
|
4166
3850
|
}
|
|
4167
3851
|
/**
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
3852
|
+
* addFromHistory Adds multiple messages at one time.
|
|
3853
|
+
* @param history History of chat messages.
|
|
3854
|
+
* @return ChatPrompt so it can be chained.
|
|
3855
|
+
*/
|
|
4172
3856
|
addFromHistory(history) {
|
|
4173
3857
|
if (history && Array.isArray(history)) {
|
|
4174
3858
|
for (const message of history) {
|
|
@@ -4195,15 +3879,13 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4195
3879
|
return this;
|
|
4196
3880
|
}
|
|
4197
3881
|
/**
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
3882
|
+
* addPlaceholder description
|
|
3883
|
+
* @param content The message content
|
|
3884
|
+
* @return returns ChatPrompt so it can be chained.
|
|
3885
|
+
*/
|
|
4202
3886
|
addChatHistoryPlaceholder(key, options) {
|
|
4203
3887
|
const start = `{{> DialogueHistory `;
|
|
4204
|
-
const params = [
|
|
4205
|
-
`key='${String(key)}'`
|
|
4206
|
-
];
|
|
3888
|
+
const params = [`key='${String(key)}'`];
|
|
4207
3889
|
const end = `}}`;
|
|
4208
3890
|
if (options?.assistant) {
|
|
4209
3891
|
params.push(`assistant='${options.assistant}'`);
|
|
@@ -4218,17 +3900,14 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4218
3900
|
return this;
|
|
4219
3901
|
}
|
|
4220
3902
|
/**
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
3903
|
+
* addTokenPlaceholder description
|
|
3904
|
+
* @param content The message content
|
|
3905
|
+
* @return returns ChatPrompt so it can be chained.
|
|
3906
|
+
*/
|
|
4225
3907
|
addMessagePlaceholder(content, role = "user", name) {
|
|
4226
3908
|
if (content) {
|
|
4227
3909
|
const start = `{{> SingleChatMessage `;
|
|
4228
|
-
const params = [
|
|
4229
|
-
`role='${role}'`,
|
|
4230
|
-
`content='${escape(content)}'`
|
|
4231
|
-
];
|
|
3910
|
+
const params = [`role='${role}'`, `content='${escape(content)}'`];
|
|
4232
3911
|
const end = `}}`;
|
|
4233
3912
|
if (name) {
|
|
4234
3913
|
params.push(`name='${name}'`);
|
|
@@ -4248,11 +3927,7 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4248
3927
|
for (const message of history) {
|
|
4249
3928
|
switch (message.role) {
|
|
4250
3929
|
case "user": {
|
|
4251
|
-
const m = pick(message, [
|
|
4252
|
-
"role",
|
|
4253
|
-
"content",
|
|
4254
|
-
"name"
|
|
4255
|
-
]);
|
|
3930
|
+
const m = pick(message, ["role", "content", "name"]);
|
|
4256
3931
|
if (user) {
|
|
4257
3932
|
m["name"] = user;
|
|
4258
3933
|
}
|
|
@@ -4293,19 +3968,16 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4293
3968
|
return messagesOut;
|
|
4294
3969
|
}
|
|
4295
3970
|
/**
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
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
|
+
*/
|
|
4302
3977
|
format(values) {
|
|
4303
3978
|
const messagesOut = [];
|
|
4304
3979
|
const replacements = this.getReplacements(values);
|
|
4305
|
-
const safeToParseTemplate = [
|
|
4306
|
-
"assistant",
|
|
4307
|
-
"system"
|
|
4308
|
-
];
|
|
3980
|
+
const safeToParseTemplate = ["assistant", "system"];
|
|
4309
3981
|
if (this.parseUserTemplates) {
|
|
4310
3982
|
safeToParseTemplate.push("user");
|
|
4311
3983
|
}
|
|
@@ -4314,7 +3986,12 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4314
3986
|
const tokenData = extractPromptPlaceholderToken(message.content);
|
|
4315
3987
|
switch (tokenData.token) {
|
|
4316
3988
|
case ">DialogueHistory": {
|
|
4317
|
-
messagesOut.push(
|
|
3989
|
+
messagesOut.push(
|
|
3990
|
+
...this._format_placeholderDialogueHistory(
|
|
3991
|
+
tokenData,
|
|
3992
|
+
replacements
|
|
3993
|
+
)
|
|
3994
|
+
);
|
|
4318
3995
|
break;
|
|
4319
3996
|
}
|
|
4320
3997
|
case ">SingleChatMessage": {
|
|
@@ -4337,70 +4014,103 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4337
4014
|
}
|
|
4338
4015
|
}
|
|
4339
4016
|
} else if (message.role === "function") {
|
|
4340
|
-
messagesOut.push(
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4017
|
+
messagesOut.push(
|
|
4018
|
+
Object.assign({}, message, {
|
|
4019
|
+
content: this.replaceTemplateString(message.content, replacements, {
|
|
4020
|
+
partials: this.partials,
|
|
4021
|
+
helpers: this.helpers
|
|
4022
|
+
})
|
|
4344
4023
|
})
|
|
4345
|
-
|
|
4024
|
+
);
|
|
4346
4025
|
} else {
|
|
4347
4026
|
if (safeToParseTemplate.includes(message.role)) {
|
|
4348
4027
|
if (Array.isArray(message.content)) {
|
|
4349
|
-
const content = message.content.map(
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
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 }));
|
|
4359
4046
|
} else if (message.content) {
|
|
4360
|
-
const content = this.runPromptFilter(
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
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 }));
|
|
4367
4060
|
} else {
|
|
4368
|
-
messagesOut.push(Object.assign({}, message, {
|
|
4369
|
-
content: null
|
|
4370
|
-
}));
|
|
4061
|
+
messagesOut.push(Object.assign({}, message, { content: null }));
|
|
4371
4062
|
}
|
|
4372
4063
|
} else {
|
|
4373
|
-
messagesOut.push(
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
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
|
+
);
|
|
4379
4090
|
}
|
|
4380
4091
|
}
|
|
4381
4092
|
}
|
|
4382
4093
|
return messagesOut;
|
|
4383
4094
|
}
|
|
4384
4095
|
/**
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
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
|
+
*/
|
|
4391
4102
|
async formatAsync(values) {
|
|
4392
4103
|
const messagesOut = [];
|
|
4393
4104
|
const replacements = this.getReplacements(values);
|
|
4394
|
-
const safeToParseTemplate = [
|
|
4395
|
-
"assistant",
|
|
4396
|
-
"system"
|
|
4397
|
-
];
|
|
4105
|
+
const safeToParseTemplate = ["assistant", "system"];
|
|
4398
4106
|
if (this.parseUserTemplates) {
|
|
4399
4107
|
safeToParseTemplate.push("user");
|
|
4400
4108
|
}
|
|
4401
4109
|
for (const message of this.messages) {
|
|
4402
4110
|
if (message.role === "placeholder") {
|
|
4403
|
-
const { token, ...data } = extractPromptPlaceholderToken(
|
|
4111
|
+
const { token, ...data } = extractPromptPlaceholderToken(
|
|
4112
|
+
message.content
|
|
4113
|
+
);
|
|
4404
4114
|
switch (token) {
|
|
4405
4115
|
case ">DialogueHistory": {
|
|
4406
4116
|
const { key = "", user } = data;
|
|
@@ -4409,11 +4119,7 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4409
4119
|
for (const message2 of history) {
|
|
4410
4120
|
switch (message2.role) {
|
|
4411
4121
|
case "user": {
|
|
4412
|
-
const m = pick(message2, [
|
|
4413
|
-
"role",
|
|
4414
|
-
"content",
|
|
4415
|
-
"name"
|
|
4416
|
-
]);
|
|
4122
|
+
const m = pick(message2, ["role", "content", "name"]);
|
|
4417
4123
|
if (user) {
|
|
4418
4124
|
m["name"] = user;
|
|
4419
4125
|
}
|
|
@@ -4459,10 +4165,14 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4459
4165
|
const message2 = {
|
|
4460
4166
|
role,
|
|
4461
4167
|
name,
|
|
4462
|
-
content: await this.replaceTemplateStringAsync(
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4168
|
+
content: await this.replaceTemplateStringAsync(
|
|
4169
|
+
content,
|
|
4170
|
+
replacements,
|
|
4171
|
+
{
|
|
4172
|
+
partials: this.partials,
|
|
4173
|
+
helpers: this.helpers
|
|
4174
|
+
}
|
|
4175
|
+
)
|
|
4466
4176
|
};
|
|
4467
4177
|
if (!name || role !== "user") {
|
|
4468
4178
|
delete message2.name;
|
|
@@ -4473,12 +4183,18 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4473
4183
|
}
|
|
4474
4184
|
}
|
|
4475
4185
|
} else if (message.role === "function") {
|
|
4476
|
-
messagesOut.push(
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
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
|
+
)
|
|
4480
4196
|
})
|
|
4481
|
-
|
|
4197
|
+
);
|
|
4482
4198
|
} else {
|
|
4483
4199
|
if (safeToParseTemplate.includes(message.role)) {
|
|
4484
4200
|
if (Array.isArray(message.content)) {
|
|
@@ -4489,10 +4205,14 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4489
4205
|
type: "text",
|
|
4490
4206
|
text: this.runPromptFilter(
|
|
4491
4207
|
// HERE
|
|
4492
|
-
await this.replaceTemplateStringAsync(
|
|
4493
|
-
|
|
4494
|
-
|
|
4495
|
-
|
|
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
|
+
),
|
|
4496
4216
|
this.filters.post,
|
|
4497
4217
|
values
|
|
4498
4218
|
)
|
|
@@ -4501,45 +4221,65 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4501
4221
|
content.push(m);
|
|
4502
4222
|
}
|
|
4503
4223
|
}
|
|
4504
|
-
messagesOut.push(Object.assign({}, message, {
|
|
4505
|
-
content
|
|
4506
|
-
}));
|
|
4224
|
+
messagesOut.push(Object.assign({}, message, { content }));
|
|
4507
4225
|
} else if (message.content) {
|
|
4508
|
-
const content = this.runPromptFilter(
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
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 }));
|
|
4515
4239
|
} else {
|
|
4516
|
-
messagesOut.push(Object.assign({}, message, {
|
|
4517
|
-
content: null
|
|
4518
|
-
}));
|
|
4240
|
+
messagesOut.push(Object.assign({}, message, { content: null }));
|
|
4519
4241
|
}
|
|
4520
4242
|
} else {
|
|
4521
|
-
messagesOut.push(
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
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
|
+
);
|
|
4527
4269
|
}
|
|
4528
4270
|
}
|
|
4529
4271
|
}
|
|
4530
4272
|
return messagesOut;
|
|
4531
4273
|
}
|
|
4532
4274
|
/**
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
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
|
+
*/
|
|
4537
4279
|
validate() {
|
|
4538
4280
|
return true;
|
|
4539
4281
|
}
|
|
4540
4282
|
};
|
|
4541
|
-
__name(_ChatPrompt, "ChatPrompt");
|
|
4542
|
-
var ChatPrompt = _ChatPrompt;
|
|
4543
4283
|
|
|
4544
4284
|
// src/prompt/_functions.ts
|
|
4545
4285
|
function createPrompt(type, initialPromptMessage, options) {
|
|
@@ -4550,14 +4290,12 @@ function createPrompt(type, initialPromptMessage, options) {
|
|
|
4550
4290
|
return new TextPrompt(initialPromptMessage);
|
|
4551
4291
|
}
|
|
4552
4292
|
}
|
|
4553
|
-
__name(createPrompt, "createPrompt");
|
|
4554
4293
|
function createChatPrompt(initialSystemPromptMessage, options) {
|
|
4555
4294
|
return new ChatPrompt(initialSystemPromptMessage, options);
|
|
4556
4295
|
}
|
|
4557
|
-
__name(createChatPrompt, "createChatPrompt");
|
|
4558
4296
|
|
|
4559
4297
|
// src/state/item.ts
|
|
4560
|
-
var
|
|
4298
|
+
var BaseStateItem = class {
|
|
4561
4299
|
constructor(key, initialValue) {
|
|
4562
4300
|
__publicField(this, "key");
|
|
4563
4301
|
__publicField(this, "value");
|
|
@@ -4567,7 +4305,10 @@ var _BaseStateItem = class _BaseStateItem {
|
|
|
4567
4305
|
this.initialValue = initialValue;
|
|
4568
4306
|
}
|
|
4569
4307
|
setValue(value) {
|
|
4570
|
-
assert(
|
|
4308
|
+
assert(
|
|
4309
|
+
typeof value === typeof this.value,
|
|
4310
|
+
`Invalid value type. Expected ${typeof this.value}, received ${typeof value}`
|
|
4311
|
+
);
|
|
4571
4312
|
this.value = value;
|
|
4572
4313
|
}
|
|
4573
4314
|
getKey() {
|
|
@@ -4591,19 +4332,18 @@ var _BaseStateItem = class _BaseStateItem {
|
|
|
4591
4332
|
value: this.serializeValue()
|
|
4592
4333
|
};
|
|
4593
4334
|
}
|
|
4335
|
+
// deserialize() {}
|
|
4594
4336
|
};
|
|
4595
|
-
|
|
4596
|
-
var BaseStateItem = _BaseStateItem;
|
|
4597
|
-
var _DefaultStateItem = class _DefaultStateItem extends BaseStateItem {
|
|
4337
|
+
var DefaultStateItem = class extends BaseStateItem {
|
|
4598
4338
|
constructor(name, defaultValue) {
|
|
4599
4339
|
super(name, defaultValue);
|
|
4600
4340
|
}
|
|
4341
|
+
// serialize() { return {}; }
|
|
4342
|
+
// deserialize() {}
|
|
4601
4343
|
};
|
|
4602
|
-
__name(_DefaultStateItem, "DefaultStateItem");
|
|
4603
|
-
var DefaultStateItem = _DefaultStateItem;
|
|
4604
4344
|
|
|
4605
4345
|
// src/state/dialogue.ts
|
|
4606
|
-
var
|
|
4346
|
+
var Dialogue = class extends BaseStateItem {
|
|
4607
4347
|
constructor(name) {
|
|
4608
4348
|
super(name, []);
|
|
4609
4349
|
__publicField(this, "name");
|
|
@@ -4699,17 +4439,14 @@ var _Dialogue = class _Dialogue extends BaseStateItem {
|
|
|
4699
4439
|
return {
|
|
4700
4440
|
class: "Dialogue",
|
|
4701
4441
|
name: this.name,
|
|
4702
|
-
value: [
|
|
4703
|
-
...this.value
|
|
4704
|
-
]
|
|
4442
|
+
value: [...this.value]
|
|
4705
4443
|
};
|
|
4706
4444
|
}
|
|
4445
|
+
// deserialize() {}
|
|
4707
4446
|
};
|
|
4708
|
-
__name(_Dialogue, "Dialogue");
|
|
4709
|
-
var Dialogue = _Dialogue;
|
|
4710
4447
|
|
|
4711
4448
|
// src/state/_base.ts
|
|
4712
|
-
var
|
|
4449
|
+
var BaseState = class {
|
|
4713
4450
|
constructor() {
|
|
4714
4451
|
__publicField(this, "dialogues", {});
|
|
4715
4452
|
__publicField(this, "attributes", {});
|
|
@@ -4734,8 +4471,14 @@ var _BaseState = class _BaseState {
|
|
|
4734
4471
|
return dialogue;
|
|
4735
4472
|
}
|
|
4736
4473
|
createContextItem(item) {
|
|
4737
|
-
assert(
|
|
4738
|
-
|
|
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
|
+
);
|
|
4739
4482
|
this.context[item.getKey()] = item;
|
|
4740
4483
|
return this.context[item.getKey()];
|
|
4741
4484
|
}
|
|
@@ -4757,14 +4500,16 @@ var _BaseState = class _BaseState {
|
|
|
4757
4500
|
serialize() {
|
|
4758
4501
|
const dialogues = {};
|
|
4759
4502
|
const context = {};
|
|
4760
|
-
const attributes = {
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4503
|
+
const attributes = { ...this.attributes };
|
|
4504
|
+
const dialogueKeys = Object.keys(
|
|
4505
|
+
this.dialogues
|
|
4506
|
+
);
|
|
4764
4507
|
for (const dialogueKey of dialogueKeys) {
|
|
4765
4508
|
dialogues[dialogueKey] = this.dialogues[dialogueKey].serialize();
|
|
4766
4509
|
}
|
|
4767
|
-
const contextKeys = Object.keys(
|
|
4510
|
+
const contextKeys = Object.keys(
|
|
4511
|
+
this.context
|
|
4512
|
+
);
|
|
4768
4513
|
for (const contextKey of contextKeys) {
|
|
4769
4514
|
context[contextKey] = this.context[contextKey].serialize();
|
|
4770
4515
|
}
|
|
@@ -4775,9 +4520,7 @@ var _BaseState = class _BaseState {
|
|
|
4775
4520
|
};
|
|
4776
4521
|
}
|
|
4777
4522
|
};
|
|
4778
|
-
|
|
4779
|
-
var BaseState = _BaseState;
|
|
4780
|
-
var _DefaultState = class _DefaultState extends BaseState {
|
|
4523
|
+
var DefaultState = class extends BaseState {
|
|
4781
4524
|
constructor() {
|
|
4782
4525
|
super();
|
|
4783
4526
|
}
|
|
@@ -4785,22 +4528,17 @@ var _DefaultState = class _DefaultState extends BaseState {
|
|
|
4785
4528
|
console.log("Save not implemented in default state.");
|
|
4786
4529
|
}
|
|
4787
4530
|
};
|
|
4788
|
-
__name(_DefaultState, "DefaultState");
|
|
4789
|
-
var DefaultState = _DefaultState;
|
|
4790
4531
|
|
|
4791
4532
|
// src/state/_functions.ts
|
|
4792
4533
|
function createState() {
|
|
4793
4534
|
return new DefaultState();
|
|
4794
4535
|
}
|
|
4795
|
-
__name(createState, "createState");
|
|
4796
4536
|
function createDialogue(name) {
|
|
4797
4537
|
return new Dialogue(name);
|
|
4798
4538
|
}
|
|
4799
|
-
__name(createDialogue, "createDialogue");
|
|
4800
4539
|
function createStateItem(name, defaultValue) {
|
|
4801
4540
|
return new DefaultStateItem(name, defaultValue);
|
|
4802
4541
|
}
|
|
4803
|
-
__name(createStateItem, "createStateItem");
|
|
4804
4542
|
export {
|
|
4805
4543
|
BaseExecutor,
|
|
4806
4544
|
BaseParser,
|
|
@@ -4824,6 +4562,9 @@ export {
|
|
|
4824
4562
|
createPrompt,
|
|
4825
4563
|
createState,
|
|
4826
4564
|
createStateItem,
|
|
4565
|
+
defineSchema,
|
|
4566
|
+
registerHelpers,
|
|
4567
|
+
registerPartials,
|
|
4827
4568
|
useExecutors,
|
|
4828
4569
|
useLlm,
|
|
4829
4570
|
utils_exports as utils
|