llm-exe 2.1.8 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +47 -36
- package/dist/index.d.ts +47 -36
- package/dist/index.js +1005 -1225
- package/dist/index.mjs +995 -1227
- package/package.json +34 -30
- package/readme.md +122 -52
package/dist/index.js
CHANGED
|
@@ -9,7 +9,6 @@ var __typeError = (msg) => {
|
|
|
9
9
|
throw TypeError(msg);
|
|
10
10
|
};
|
|
11
11
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
13
12
|
var __export = (target, all) => {
|
|
14
13
|
for (var name in all)
|
|
15
14
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -37,8 +36,8 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
|
|
|
37
36
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
38
37
|
|
|
39
38
|
// src/index.ts
|
|
40
|
-
var
|
|
41
|
-
__export(
|
|
39
|
+
var index_exports = {};
|
|
40
|
+
__export(index_exports, {
|
|
42
41
|
BaseExecutor: () => BaseExecutor,
|
|
43
42
|
BaseParser: () => BaseParser,
|
|
44
43
|
BasePrompt: () => BasePrompt,
|
|
@@ -48,6 +47,8 @@ __export(src_exports, {
|
|
|
48
47
|
DefaultState: () => DefaultState,
|
|
49
48
|
DefaultStateItem: () => DefaultStateItem,
|
|
50
49
|
LlmExecutorOpenAiFunctions: () => LlmExecutorOpenAiFunctions,
|
|
50
|
+
LlmExecutorWithFunctions: () => LlmExecutorWithFunctions,
|
|
51
|
+
LlmNativeFunctionParser: () => LlmNativeFunctionParser,
|
|
51
52
|
OpenAiFunctionParser: () => OpenAiFunctionParser,
|
|
52
53
|
TextPrompt: () => TextPrompt,
|
|
53
54
|
createCallableExecutor: () => createCallableExecutor,
|
|
@@ -57,15 +58,19 @@ __export(src_exports, {
|
|
|
57
58
|
createDialogue: () => createDialogue,
|
|
58
59
|
createEmbedding: () => createEmbedding,
|
|
59
60
|
createLlmExecutor: () => createLlmExecutor,
|
|
61
|
+
createLlmFunctionExecutor: () => createLlmFunctionExecutor,
|
|
60
62
|
createParser: () => createParser,
|
|
61
63
|
createPrompt: () => createPrompt,
|
|
62
64
|
createState: () => createState,
|
|
63
65
|
createStateItem: () => createStateItem,
|
|
66
|
+
defineSchema: () => defineSchema,
|
|
67
|
+
registerHelpers: () => registerHelpers,
|
|
68
|
+
registerPartials: () => registerPartials,
|
|
64
69
|
useExecutors: () => useExecutors,
|
|
65
70
|
useLlm: () => useLlm,
|
|
66
71
|
utils: () => utils_exports
|
|
67
72
|
});
|
|
68
|
-
module.exports = __toCommonJS(
|
|
73
|
+
module.exports = __toCommonJS(index_exports);
|
|
69
74
|
|
|
70
75
|
// src/utils/modules/pick.ts
|
|
71
76
|
function pick(object, keys) {
|
|
@@ -76,38 +81,30 @@ function pick(object, keys) {
|
|
|
76
81
|
return obj;
|
|
77
82
|
}, {});
|
|
78
83
|
}
|
|
79
|
-
__name(pick, "pick");
|
|
80
84
|
|
|
81
85
|
// src/utils/modules/ensureInputIsObject.ts
|
|
82
86
|
function ensureInputIsObject(input) {
|
|
83
87
|
if (input === null || typeof input === "undefined") {
|
|
84
|
-
return {
|
|
85
|
-
input
|
|
86
|
-
};
|
|
88
|
+
return { input };
|
|
87
89
|
}
|
|
88
90
|
switch (typeof input) {
|
|
89
91
|
case "object": {
|
|
90
92
|
if (Array.isArray(input)) {
|
|
91
|
-
return {
|
|
92
|
-
input
|
|
93
|
-
};
|
|
93
|
+
return { input };
|
|
94
94
|
}
|
|
95
95
|
return input;
|
|
96
96
|
}
|
|
97
97
|
default:
|
|
98
|
-
return {
|
|
99
|
-
input
|
|
100
|
-
};
|
|
98
|
+
return { input };
|
|
101
99
|
}
|
|
102
100
|
}
|
|
103
|
-
__name(ensureInputIsObject, "ensureInputIsObject");
|
|
104
101
|
|
|
105
102
|
// src/utils/modules/uuid.ts
|
|
106
103
|
var import_uuid = require("uuid");
|
|
107
104
|
|
|
108
105
|
// src/executor/_metadata.ts
|
|
109
106
|
var _state;
|
|
110
|
-
var
|
|
107
|
+
var ExecutorExecutionMetadataState = class {
|
|
111
108
|
constructor(items) {
|
|
112
109
|
__privateAdd(this, _state, {
|
|
113
110
|
start: null,
|
|
@@ -150,12 +147,9 @@ var _ExecutorExecutionMetadataState = class _ExecutorExecutionMetadataState {
|
|
|
150
147
|
}
|
|
151
148
|
};
|
|
152
149
|
_state = new WeakMap();
|
|
153
|
-
__name(_ExecutorExecutionMetadataState, "ExecutorExecutionMetadataState");
|
|
154
|
-
var ExecutorExecutionMetadataState = _ExecutorExecutionMetadataState;
|
|
155
150
|
function createMetadataState(items) {
|
|
156
151
|
return new ExecutorExecutionMetadataState(items);
|
|
157
152
|
}
|
|
158
|
-
__name(createMetadataState, "createMetadataState");
|
|
159
153
|
|
|
160
154
|
// src/utils/const.ts
|
|
161
155
|
var hookOnComplete = `onComplete`;
|
|
@@ -163,38 +157,34 @@ var hookOnError = `onError`;
|
|
|
163
157
|
var hookOnSuccess = `onSuccess`;
|
|
164
158
|
|
|
165
159
|
// src/executor/_base.ts
|
|
166
|
-
var
|
|
160
|
+
var BaseExecutor = class {
|
|
167
161
|
constructor(name, type, options) {
|
|
168
162
|
/**
|
|
169
|
-
|
|
170
|
-
|
|
163
|
+
* @property id - internal id of the executor
|
|
164
|
+
*/
|
|
171
165
|
__publicField(this, "id");
|
|
172
166
|
/**
|
|
173
|
-
|
|
174
|
-
|
|
167
|
+
* @property type - type of executor
|
|
168
|
+
*/
|
|
175
169
|
__publicField(this, "type");
|
|
176
170
|
/**
|
|
177
|
-
|
|
178
|
-
|
|
171
|
+
* @property created - timestamp date created
|
|
172
|
+
*/
|
|
179
173
|
__publicField(this, "created");
|
|
180
174
|
/**
|
|
181
|
-
|
|
182
|
-
|
|
175
|
+
* @property name - name of executor
|
|
176
|
+
*/
|
|
183
177
|
__publicField(this, "name");
|
|
184
178
|
/**
|
|
185
|
-
|
|
186
|
-
|
|
179
|
+
* @property executions -
|
|
180
|
+
*/
|
|
187
181
|
__publicField(this, "executions");
|
|
188
182
|
__publicField(this, "traceId", null);
|
|
189
183
|
/**
|
|
190
|
-
|
|
191
|
-
|
|
184
|
+
* @property hooks - hooks to be ran during execution
|
|
185
|
+
*/
|
|
192
186
|
__publicField(this, "hooks");
|
|
193
|
-
__publicField(this, "allowedHooks", [
|
|
194
|
-
hookOnComplete,
|
|
195
|
-
hookOnError,
|
|
196
|
-
hookOnSuccess
|
|
197
|
-
]);
|
|
187
|
+
__publicField(this, "allowedHooks", [hookOnComplete, hookOnError, hookOnSuccess]);
|
|
198
188
|
this.id = (0, import_uuid.v4)();
|
|
199
189
|
this.type = type;
|
|
200
190
|
this.name = name;
|
|
@@ -210,29 +200,29 @@ var _BaseExecutor = class _BaseExecutor {
|
|
|
210
200
|
}
|
|
211
201
|
}
|
|
212
202
|
/**
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
203
|
+
*
|
|
204
|
+
* Used to filter the input of the handler
|
|
205
|
+
* @param _input
|
|
206
|
+
* @returns original input formatted for handler
|
|
207
|
+
*/
|
|
218
208
|
async getHandlerInput(_input, _metadata, _options) {
|
|
219
209
|
return ensureInputIsObject(_input);
|
|
220
210
|
}
|
|
221
211
|
/**
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
212
|
+
*
|
|
213
|
+
* Used to filter the output of the handler
|
|
214
|
+
* @param _input
|
|
215
|
+
* @returns output O
|
|
216
|
+
*/
|
|
227
217
|
getHandlerOutput(out, _metadata, _options) {
|
|
228
218
|
return out;
|
|
229
219
|
}
|
|
230
220
|
/**
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
221
|
+
*
|
|
222
|
+
* execute - Runs the executor
|
|
223
|
+
* @param _input
|
|
224
|
+
* @returns handler output
|
|
225
|
+
*/
|
|
236
226
|
async execute(_input, _options) {
|
|
237
227
|
this.executions++;
|
|
238
228
|
const _metadata = createMetadataState({
|
|
@@ -240,31 +230,28 @@ var _BaseExecutor = class _BaseExecutor {
|
|
|
240
230
|
input: _input
|
|
241
231
|
});
|
|
242
232
|
try {
|
|
243
|
-
const input = await this.getHandlerInput(
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
233
|
+
const input = await this.getHandlerInput(
|
|
234
|
+
_input,
|
|
235
|
+
_metadata.asPlainObject(),
|
|
236
|
+
_options
|
|
237
|
+
);
|
|
238
|
+
_metadata.setItem({ handlerInput: input });
|
|
247
239
|
let result = await this.handler(input, _options);
|
|
248
|
-
_metadata.setItem({
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
});
|
|
240
|
+
_metadata.setItem({ handlerOutput: result });
|
|
241
|
+
const output = this.getHandlerOutput(
|
|
242
|
+
result,
|
|
243
|
+
_metadata.asPlainObject(),
|
|
244
|
+
_options
|
|
245
|
+
);
|
|
246
|
+
_metadata.setItem({ output });
|
|
255
247
|
this.runHook("onSuccess", _metadata.asPlainObject());
|
|
256
248
|
return output;
|
|
257
249
|
} catch (error) {
|
|
258
|
-
_metadata.setItem({
|
|
259
|
-
error,
|
|
260
|
-
errorMessage: error.message
|
|
261
|
-
});
|
|
250
|
+
_metadata.setItem({ error, errorMessage: error.message });
|
|
262
251
|
this.runHook("onError", _metadata.asPlainObject());
|
|
263
252
|
throw error;
|
|
264
253
|
} finally {
|
|
265
|
-
_metadata.setItem({
|
|
266
|
-
end: (/* @__PURE__ */ new Date()).getTime()
|
|
267
|
-
});
|
|
254
|
+
_metadata.setItem({ end: (/* @__PURE__ */ new Date()).getTime() });
|
|
268
255
|
this.runHook("onComplete", _metadata.asPlainObject());
|
|
269
256
|
}
|
|
270
257
|
}
|
|
@@ -284,9 +271,7 @@ var _BaseExecutor = class _BaseExecutor {
|
|
|
284
271
|
}
|
|
285
272
|
runHook(hook, _metadata) {
|
|
286
273
|
const { [hook]: hooks = [] } = pick(this.hooks, this.allowedHooks);
|
|
287
|
-
for (const hookFn of [
|
|
288
|
-
...hooks
|
|
289
|
-
]) {
|
|
274
|
+
for (const hookFn of [...hooks]) {
|
|
290
275
|
if (typeof hookFn === "function") {
|
|
291
276
|
try {
|
|
292
277
|
hookFn(_metadata, this.getMetadata());
|
|
@@ -297,12 +282,12 @@ var _BaseExecutor = class _BaseExecutor {
|
|
|
297
282
|
}
|
|
298
283
|
setHooks(hooks = {}) {
|
|
299
284
|
const hookKeys = Object.keys(hooks);
|
|
300
|
-
for (const hookKey of hookKeys.filter(
|
|
285
|
+
for (const hookKey of hookKeys.filter(
|
|
286
|
+
(k) => this.allowedHooks.includes(k)
|
|
287
|
+
)) {
|
|
301
288
|
const hookInput = hooks[hookKey];
|
|
302
289
|
if (hookInput) {
|
|
303
|
-
const _hooks = Array.isArray(hookInput) ? hookInput : [
|
|
304
|
-
hookInput
|
|
305
|
-
];
|
|
290
|
+
const _hooks = Array.isArray(hookInput) ? hookInput : [hookInput];
|
|
306
291
|
for (const hook of _hooks) {
|
|
307
292
|
if (hook && typeof hook === "function" && !this.hooks[hookKey].find((h) => h === hook)) {
|
|
308
293
|
this.hooks[hookKey].push(hook);
|
|
@@ -325,19 +310,17 @@ var _BaseExecutor = class _BaseExecutor {
|
|
|
325
310
|
return this;
|
|
326
311
|
}
|
|
327
312
|
on(eventName, fn) {
|
|
328
|
-
return this.setHooks({
|
|
329
|
-
[eventName]: fn
|
|
330
|
-
});
|
|
313
|
+
return this.setHooks({ [eventName]: fn });
|
|
331
314
|
}
|
|
332
315
|
off(eventName, fn) {
|
|
333
316
|
return this.removeHook(eventName, fn);
|
|
334
317
|
}
|
|
335
318
|
once(eventName, fn) {
|
|
336
319
|
if (typeof fn !== "function") return this;
|
|
337
|
-
const onceWrapper =
|
|
320
|
+
const onceWrapper = (...args) => {
|
|
338
321
|
fn(...args);
|
|
339
322
|
this.off(eventName, onceWrapper);
|
|
340
|
-
}
|
|
323
|
+
};
|
|
341
324
|
this.hooks[eventName].push(onceWrapper);
|
|
342
325
|
return this;
|
|
343
326
|
}
|
|
@@ -349,26 +332,20 @@ var _BaseExecutor = class _BaseExecutor {
|
|
|
349
332
|
return this.traceId;
|
|
350
333
|
}
|
|
351
334
|
};
|
|
352
|
-
__name(_BaseExecutor, "BaseExecutor");
|
|
353
|
-
var BaseExecutor = _BaseExecutor;
|
|
354
335
|
|
|
355
336
|
// src/utils/modules/inferFunctionName.ts
|
|
356
337
|
function inferFunctionName(func, defaultName) {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
} else {
|
|
362
|
-
return name;
|
|
363
|
-
}
|
|
338
|
+
if (typeof func !== "function") return defaultName;
|
|
339
|
+
const name = func.name;
|
|
340
|
+
if (typeof name === "string" && name.length > 0) {
|
|
341
|
+
return name.startsWith("bound ") ? name.slice(6) : name;
|
|
364
342
|
}
|
|
365
|
-
|
|
366
|
-
return
|
|
343
|
+
const match = /^function\s+([\w$]+)\s*\(/.exec(func.toString());
|
|
344
|
+
return match?.[1] ?? defaultName;
|
|
367
345
|
}
|
|
368
|
-
__name(inferFunctionName, "inferFunctionName");
|
|
369
346
|
|
|
370
347
|
// src/executor/core.ts
|
|
371
|
-
var
|
|
348
|
+
var CoreExecutor = class extends BaseExecutor {
|
|
372
349
|
constructor(fn, options) {
|
|
373
350
|
const name = fn?.name ? fn.name : inferFunctionName(fn.handler, "anonymous-core-executor");
|
|
374
351
|
super(name, "function-executor", options);
|
|
@@ -379,16 +356,14 @@ var _CoreExecutor = class _CoreExecutor extends BaseExecutor {
|
|
|
379
356
|
return this._handler.call(null, _input);
|
|
380
357
|
}
|
|
381
358
|
};
|
|
382
|
-
__name(_CoreExecutor, "CoreExecutor");
|
|
383
|
-
var CoreExecutor = _CoreExecutor;
|
|
384
359
|
|
|
385
360
|
// src/parser/_base.ts
|
|
386
|
-
var
|
|
361
|
+
var BaseParser = class {
|
|
387
362
|
/**
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
363
|
+
* Create a new BaseParser.
|
|
364
|
+
* @param name - The name of the parser.
|
|
365
|
+
* @param options - options
|
|
366
|
+
*/
|
|
392
367
|
constructor(name, options = {}, target = "text") {
|
|
393
368
|
__publicField(this, "name");
|
|
394
369
|
__publicField(this, "options");
|
|
@@ -400,14 +375,12 @@ var _BaseParser = class _BaseParser {
|
|
|
400
375
|
}
|
|
401
376
|
}
|
|
402
377
|
};
|
|
403
|
-
|
|
404
|
-
var BaseParser = _BaseParser;
|
|
405
|
-
var _BaseParserWithJson = class _BaseParserWithJson extends BaseParser {
|
|
378
|
+
var BaseParserWithJson = class extends BaseParser {
|
|
406
379
|
/**
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
380
|
+
* Create a new BaseParser.
|
|
381
|
+
* @param name - The name of the parser.
|
|
382
|
+
* @param options - options
|
|
383
|
+
*/
|
|
411
384
|
constructor(name, options) {
|
|
412
385
|
super(name);
|
|
413
386
|
__publicField(this, "schema");
|
|
@@ -419,8 +392,79 @@ var _BaseParserWithJson = class _BaseParserWithJson extends BaseParser {
|
|
|
419
392
|
}
|
|
420
393
|
}
|
|
421
394
|
};
|
|
422
|
-
|
|
423
|
-
|
|
395
|
+
|
|
396
|
+
// src/utils/modules/assert.ts
|
|
397
|
+
function assert(condition, message) {
|
|
398
|
+
if (condition === void 0 || condition === null || condition === false) {
|
|
399
|
+
if (typeof message === "string") {
|
|
400
|
+
throw new Error(message);
|
|
401
|
+
} else if (message instanceof Error) {
|
|
402
|
+
throw message;
|
|
403
|
+
} else {
|
|
404
|
+
throw new Error(`Assertion error`);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// src/parser/parsers/StringParser.ts
|
|
410
|
+
var StringParser = class extends BaseParser {
|
|
411
|
+
constructor(options) {
|
|
412
|
+
super("string", options);
|
|
413
|
+
}
|
|
414
|
+
parse(text, _options) {
|
|
415
|
+
assert(
|
|
416
|
+
typeof text === "string",
|
|
417
|
+
`Invalid input. Expected string. Received ${typeof text}.`
|
|
418
|
+
);
|
|
419
|
+
const parsed = text.toString();
|
|
420
|
+
return parsed;
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
|
|
424
|
+
// src/parser/parsers/BooleanParser.ts
|
|
425
|
+
var BooleanParser = class extends BaseParser {
|
|
426
|
+
constructor(options) {
|
|
427
|
+
super("boolean", options);
|
|
428
|
+
}
|
|
429
|
+
parse(text) {
|
|
430
|
+
assert(
|
|
431
|
+
typeof text === "string",
|
|
432
|
+
`Invalid input. Expected string. Received ${typeof text}.`
|
|
433
|
+
);
|
|
434
|
+
const clean = text.toLowerCase().trim();
|
|
435
|
+
if (clean === "true") {
|
|
436
|
+
return true;
|
|
437
|
+
}
|
|
438
|
+
return false;
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
// src/utils/modules/isFinite.ts
|
|
443
|
+
function isFinite(value) {
|
|
444
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// src/utils/modules/toNumber.ts
|
|
448
|
+
function toNumber(value) {
|
|
449
|
+
if (typeof value === "number") {
|
|
450
|
+
return value;
|
|
451
|
+
}
|
|
452
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
453
|
+
return Number(value);
|
|
454
|
+
}
|
|
455
|
+
return NaN;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// src/parser/parsers/NumberParser.ts
|
|
459
|
+
var NumberParser = class extends BaseParser {
|
|
460
|
+
constructor(options) {
|
|
461
|
+
super("number", options);
|
|
462
|
+
}
|
|
463
|
+
parse(text) {
|
|
464
|
+
const match = text.match(/\d/g);
|
|
465
|
+
return match && isFinite(toNumber(match[0])) ? toNumber(match[0]) : -1;
|
|
466
|
+
}
|
|
467
|
+
};
|
|
424
468
|
|
|
425
469
|
// src/utils/index.ts
|
|
426
470
|
var utils_exports = {};
|
|
@@ -441,33 +485,20 @@ __export(utils_exports, {
|
|
|
441
485
|
replaceTemplateStringAsync: () => replaceTemplateStringAsync
|
|
442
486
|
});
|
|
443
487
|
|
|
444
|
-
// src/utils/modules/assert.ts
|
|
445
|
-
function assert(condition, message) {
|
|
446
|
-
if (condition === void 0 || condition === null || condition === false) {
|
|
447
|
-
if (typeof message === "string") {
|
|
448
|
-
throw new Error(message);
|
|
449
|
-
} else if (message instanceof Error) {
|
|
450
|
-
throw message;
|
|
451
|
-
} else {
|
|
452
|
-
throw new Error(`Assertion error`);
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
__name(assert, "assert");
|
|
457
|
-
|
|
458
488
|
// src/utils/modules/defineSchema.ts
|
|
459
489
|
var import_json_schema_to_ts = require("json-schema-to-ts");
|
|
460
490
|
function defineSchema(obj) {
|
|
461
491
|
obj.additionalProperties = false;
|
|
462
492
|
return (0, import_json_schema_to_ts.asConst)(obj);
|
|
463
493
|
}
|
|
464
|
-
__name(defineSchema, "defineSchema");
|
|
465
494
|
|
|
466
495
|
// src/utils/modules/handlebars/utils/importPartials.ts
|
|
467
496
|
function importPartials(_partials) {
|
|
468
497
|
let partials2 = [];
|
|
469
498
|
if (_partials) {
|
|
470
|
-
const externalPartialKeys = Object.keys(
|
|
499
|
+
const externalPartialKeys = Object.keys(
|
|
500
|
+
_partials
|
|
501
|
+
);
|
|
471
502
|
for (const externalPartialKey of externalPartialKeys) {
|
|
472
503
|
if (typeof externalPartialKey === "string") {
|
|
473
504
|
partials2.push({
|
|
@@ -479,13 +510,14 @@ function importPartials(_partials) {
|
|
|
479
510
|
}
|
|
480
511
|
return partials2;
|
|
481
512
|
}
|
|
482
|
-
__name(importPartials, "importPartials");
|
|
483
513
|
|
|
484
514
|
// src/utils/modules/handlebars/utils/importHelpers.ts
|
|
485
515
|
function importHelpers(_helpers) {
|
|
486
516
|
let helpers = [];
|
|
487
517
|
if (_helpers) {
|
|
488
|
-
const externalHelperKeys = Object.keys(
|
|
518
|
+
const externalHelperKeys = Object.keys(
|
|
519
|
+
_helpers
|
|
520
|
+
);
|
|
489
521
|
for (const externalHelperKey of externalHelperKeys) {
|
|
490
522
|
if (typeof externalHelperKey === "string") {
|
|
491
523
|
helpers.push({
|
|
@@ -497,19 +529,6 @@ function importHelpers(_helpers) {
|
|
|
497
529
|
}
|
|
498
530
|
return helpers;
|
|
499
531
|
}
|
|
500
|
-
__name(importHelpers, "importHelpers");
|
|
501
|
-
|
|
502
|
-
// src/utils/modules/toNumber.ts
|
|
503
|
-
function toNumber(value) {
|
|
504
|
-
if (typeof value === "number") {
|
|
505
|
-
return value;
|
|
506
|
-
}
|
|
507
|
-
if (typeof value === "string" && value.trim() !== "") {
|
|
508
|
-
return Number(value);
|
|
509
|
-
}
|
|
510
|
-
return NaN;
|
|
511
|
-
}
|
|
512
|
-
__name(toNumber, "toNumber");
|
|
513
532
|
|
|
514
533
|
// src/utils/modules/get.ts
|
|
515
534
|
function get(obj, path, defaultValue) {
|
|
@@ -517,17 +536,18 @@ function get(obj, path, defaultValue) {
|
|
|
517
536
|
return defaultValue;
|
|
518
537
|
}
|
|
519
538
|
const pathString = Array.isArray(path) ? path.join(".") : path;
|
|
520
|
-
const travel =
|
|
539
|
+
const travel = (regexp) => pathString.split(regexp).filter(Boolean).reduce(
|
|
540
|
+
(res, key) => res !== null && res !== void 0 ? res[key] : res,
|
|
541
|
+
obj
|
|
542
|
+
);
|
|
521
543
|
const result = travel(/[,[\]]+?/) || travel(/[,[\].]+?/);
|
|
522
544
|
return result === void 0 || result === obj ? defaultValue : result === null ? defaultValue : result;
|
|
523
545
|
}
|
|
524
|
-
__name(get, "get");
|
|
525
546
|
|
|
526
547
|
// src/utils/modules/filterObjectOnSchema.ts
|
|
527
548
|
function isObject(obj) {
|
|
528
549
|
return obj === Object(obj);
|
|
529
550
|
}
|
|
530
|
-
__name(isObject, "isObject");
|
|
531
551
|
function getType(schemaType) {
|
|
532
552
|
if (!Array.isArray(schemaType)) {
|
|
533
553
|
return schemaType;
|
|
@@ -540,7 +560,6 @@ function getType(schemaType) {
|
|
|
540
560
|
}
|
|
541
561
|
}
|
|
542
562
|
}
|
|
543
|
-
__name(getType, "getType");
|
|
544
563
|
function filterObjectOnSchema(schema, doc, detach, property) {
|
|
545
564
|
let result;
|
|
546
565
|
if (doc === null || doc === void 0) {
|
|
@@ -585,25 +604,10 @@ function filterObjectOnSchema(schema, doc, detach, property) {
|
|
|
585
604
|
}
|
|
586
605
|
return result;
|
|
587
606
|
}
|
|
588
|
-
__name(filterObjectOnSchema, "filterObjectOnSchema");
|
|
589
607
|
|
|
590
608
|
// src/utils/modules/handlebars/hbs.ts
|
|
591
609
|
var import_handlebars = __toESM(require("handlebars"));
|
|
592
610
|
|
|
593
|
-
// src/utils/modules/handlebars/utils/registerPartials.ts
|
|
594
|
-
function _registerPartials(partials2, instance) {
|
|
595
|
-
if (partials2 && Array.isArray(partials2)) {
|
|
596
|
-
for (const partial of partials2) {
|
|
597
|
-
if (partial.name && typeof partial.name === "string" && typeof partial.template === "string") {
|
|
598
|
-
if (instance) {
|
|
599
|
-
instance.registerPartial(partial.name, partial.template);
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
__name(_registerPartials, "_registerPartials");
|
|
606
|
-
|
|
607
611
|
// src/utils/modules/handlebars/utils/registerHelpers.ts
|
|
608
612
|
function _registerHelpers(helpers, instance) {
|
|
609
613
|
if (helpers && Array.isArray(helpers)) {
|
|
@@ -616,17 +620,6 @@ function _registerHelpers(helpers, instance) {
|
|
|
616
620
|
}
|
|
617
621
|
}
|
|
618
622
|
}
|
|
619
|
-
__name(_registerHelpers, "_registerHelpers");
|
|
620
|
-
|
|
621
|
-
// src/utils/modules/getEnvironmentVariable.ts
|
|
622
|
-
function getEnvironmentVariable(name) {
|
|
623
|
-
if (typeof process === "object" && process?.env) {
|
|
624
|
-
return process.env[name];
|
|
625
|
-
} else {
|
|
626
|
-
return void 0;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
__name(getEnvironmentVariable, "getEnvironmentVariable");
|
|
630
623
|
|
|
631
624
|
// src/utils/modules/handlebars/templates/index.ts
|
|
632
625
|
var MarkdownCode = `{{#if code}}\`\`\`{{#if language}}{{language}}{{/if}}
|
|
@@ -700,7 +693,7 @@ __export(helpers_exports, {
|
|
|
700
693
|
});
|
|
701
694
|
|
|
702
695
|
// src/utils/modules/json.ts
|
|
703
|
-
var maybeStringifyJSON =
|
|
696
|
+
var maybeStringifyJSON = (objOrMaybeString) => {
|
|
704
697
|
if (!objOrMaybeString || typeof objOrMaybeString !== "object") {
|
|
705
698
|
return objOrMaybeString;
|
|
706
699
|
}
|
|
@@ -710,8 +703,8 @@ var maybeStringifyJSON = /* @__PURE__ */ __name((objOrMaybeString) => {
|
|
|
710
703
|
} catch (error) {
|
|
711
704
|
}
|
|
712
705
|
return "";
|
|
713
|
-
}
|
|
714
|
-
var maybeParseJSON =
|
|
706
|
+
};
|
|
707
|
+
var maybeParseJSON = (objOrMaybeJSON) => {
|
|
715
708
|
if (!objOrMaybeJSON) return {};
|
|
716
709
|
if (typeof objOrMaybeJSON === "string") {
|
|
717
710
|
try {
|
|
@@ -727,24 +720,19 @@ var maybeParseJSON = /* @__PURE__ */ __name((objOrMaybeJSON) => {
|
|
|
727
720
|
return objOrMaybeJSON;
|
|
728
721
|
}
|
|
729
722
|
return {};
|
|
730
|
-
}
|
|
723
|
+
};
|
|
731
724
|
function isObjectStringified(maybeObject) {
|
|
732
725
|
if (typeof maybeObject !== "string") return false;
|
|
733
|
-
const
|
|
734
|
-
const
|
|
735
|
-
if (!
|
|
736
|
-
return false;
|
|
737
|
-
}
|
|
738
|
-
let canDecode = false;
|
|
726
|
+
const trimmed = maybeObject.trim();
|
|
727
|
+
const isWrapped = trimmed.startsWith("{") && trimmed.endsWith("}") || trimmed.startsWith("[") && trimmed.endsWith("]");
|
|
728
|
+
if (!isWrapped) return false;
|
|
739
729
|
try {
|
|
740
|
-
JSON.parse(
|
|
741
|
-
|
|
742
|
-
} catch
|
|
743
|
-
|
|
730
|
+
const parsed = JSON.parse(trimmed);
|
|
731
|
+
return typeof parsed === "object" && parsed !== null;
|
|
732
|
+
} catch {
|
|
733
|
+
return false;
|
|
744
734
|
}
|
|
745
|
-
return canDecode;
|
|
746
735
|
}
|
|
747
|
-
__name(isObjectStringified, "isObjectStringified");
|
|
748
736
|
function helpJsonMarkup(str) {
|
|
749
737
|
if (typeof str !== "string") {
|
|
750
738
|
return str;
|
|
@@ -752,12 +740,17 @@ function helpJsonMarkup(str) {
|
|
|
752
740
|
const input = str.trim();
|
|
753
741
|
const markdownJsonStartsWith = "```json";
|
|
754
742
|
const markdownJsonEndsWith = "```";
|
|
755
|
-
if (input.substring(0, markdownJsonStartsWith.length) === markdownJsonStartsWith && input.substring(
|
|
756
|
-
|
|
743
|
+
if (input.substring(0, markdownJsonStartsWith.length) === markdownJsonStartsWith && input.substring(
|
|
744
|
+
input.length - markdownJsonEndsWith.length,
|
|
745
|
+
input.length
|
|
746
|
+
) === markdownJsonEndsWith) {
|
|
747
|
+
return str.substring(
|
|
748
|
+
markdownJsonStartsWith.length,
|
|
749
|
+
input.length - markdownJsonEndsWith.length
|
|
750
|
+
)?.trim();
|
|
757
751
|
}
|
|
758
752
|
return str;
|
|
759
753
|
}
|
|
760
|
-
__name(helpJsonMarkup, "helpJsonMarkup");
|
|
761
754
|
|
|
762
755
|
// src/utils/modules/replaceTemplateStringSimple.ts
|
|
763
756
|
function replaceTemplateStringSimple(template, context) {
|
|
@@ -774,31 +767,28 @@ function replaceTemplateStringSimple(template, context) {
|
|
|
774
767
|
return typeof value === "string" ? value : String(value);
|
|
775
768
|
});
|
|
776
769
|
}
|
|
777
|
-
__name(replaceTemplateStringSimple, "replaceTemplateStringSimple");
|
|
778
770
|
|
|
779
771
|
// src/utils/modules/handlebars/helpers/indentJson.ts
|
|
780
772
|
function indentJson(arg1, collapse = "false") {
|
|
781
773
|
if (typeof arg1 !== "object") {
|
|
782
774
|
return replaceTemplateStringSimple(arg1 || "", this);
|
|
783
775
|
}
|
|
784
|
-
const replaced = maybeParseJSON(
|
|
776
|
+
const replaced = maybeParseJSON(
|
|
777
|
+
replaceTemplateStringSimple(maybeStringifyJSON(arg1), this)
|
|
778
|
+
);
|
|
785
779
|
if (collapse == "true") {
|
|
786
780
|
return JSON.stringify(replaced);
|
|
787
781
|
}
|
|
788
782
|
return JSON.stringify(replaced, null, 2);
|
|
789
783
|
}
|
|
790
|
-
__name(indentJson, "indentJson");
|
|
791
784
|
|
|
792
785
|
// src/utils/modules/schemaExampleWith.ts
|
|
793
786
|
function schemaExampleWith(schema, property) {
|
|
794
787
|
if (schema.type === "array") {
|
|
795
|
-
return filterObjectOnSchema(schema, [
|
|
796
|
-
{}
|
|
797
|
-
], void 0, property);
|
|
788
|
+
return filterObjectOnSchema(schema, [{}], void 0, property);
|
|
798
789
|
}
|
|
799
790
|
return filterObjectOnSchema(schema, {}, void 0, property);
|
|
800
791
|
}
|
|
801
|
-
__name(schemaExampleWith, "schemaExampleWith");
|
|
802
792
|
|
|
803
793
|
// src/utils/modules/handlebars/helpers/jsonSchemaExample.ts
|
|
804
794
|
function jsonSchemaExample(key, prop, collapse) {
|
|
@@ -808,7 +798,9 @@ function jsonSchemaExample(key, prop, collapse) {
|
|
|
808
798
|
if (typeof result !== "object") {
|
|
809
799
|
return "";
|
|
810
800
|
}
|
|
811
|
-
const replaced = maybeParseJSON(
|
|
801
|
+
const replaced = maybeParseJSON(
|
|
802
|
+
replaceTemplateStringSimple(maybeStringifyJSON(result), this)
|
|
803
|
+
);
|
|
812
804
|
if (collapse == "true") {
|
|
813
805
|
return JSON.stringify(replaced);
|
|
814
806
|
}
|
|
@@ -816,41 +808,35 @@ function jsonSchemaExample(key, prop, collapse) {
|
|
|
816
808
|
}
|
|
817
809
|
return "";
|
|
818
810
|
}
|
|
819
|
-
__name(jsonSchemaExample, "jsonSchemaExample");
|
|
820
811
|
|
|
821
812
|
// src/utils/modules/handlebars/helpers/getKeyOr.ts
|
|
822
813
|
function getKeyOr(key, arg2) {
|
|
823
814
|
const res = get(this, key);
|
|
824
815
|
return typeof res !== "undefined" && res !== "" ? res : arg2;
|
|
825
816
|
}
|
|
826
|
-
__name(getKeyOr, "getKeyOr");
|
|
827
817
|
|
|
828
818
|
// src/utils/modules/handlebars/helpers/getOr.ts
|
|
829
819
|
function getOr(arg1, arg2) {
|
|
830
820
|
return typeof arg1 !== "undefined" && arg1 !== "" ? arg1 : arg2;
|
|
831
821
|
}
|
|
832
|
-
__name(getOr, "getOr");
|
|
833
822
|
|
|
834
823
|
// src/utils/modules/handlebars/helpers/pluralize.ts
|
|
835
824
|
function pluralize(arg1, arg2) {
|
|
836
825
|
const [singular, plural] = arg1.split("|");
|
|
837
826
|
return arg2 > 1 ? plural : singular;
|
|
838
827
|
}
|
|
839
|
-
__name(pluralize, "pluralize");
|
|
840
828
|
|
|
841
829
|
// src/utils/modules/handlebars/helpers/eq.ts
|
|
842
830
|
function eq(arg1 = "", arg2 = "", options) {
|
|
843
831
|
const isArr = arg2.toString().split(",").map((a) => a.trim());
|
|
844
832
|
return isArr.includes(arg1) ? options.fn(this) : options.inverse(this);
|
|
845
833
|
}
|
|
846
|
-
__name(eq, "eq");
|
|
847
834
|
|
|
848
835
|
// src/utils/modules/handlebars/helpers/neq.ts
|
|
849
836
|
function neq(arg1 = "", arg2 = "", options) {
|
|
850
837
|
const isArr = arg2.toString().split(",").map((a) => a.trim());
|
|
851
838
|
return !isArr.includes(arg1) ? options.fn(this) : options.inverse(this);
|
|
852
839
|
}
|
|
853
|
-
__name(neq, "neq");
|
|
854
840
|
|
|
855
841
|
// src/utils/modules/handlebars/helpers/ifCond.ts
|
|
856
842
|
function ifCond(v1, operator, v2, options) {
|
|
@@ -879,13 +865,11 @@ function ifCond(v1, operator, v2, options) {
|
|
|
879
865
|
return options.inverse(this);
|
|
880
866
|
}
|
|
881
867
|
}
|
|
882
|
-
__name(ifCond, "ifCond");
|
|
883
868
|
|
|
884
869
|
// src/utils/modules/handlebars/helpers/objectToList.ts
|
|
885
870
|
function objectToList(arg = {}) {
|
|
886
871
|
return Object.keys(arg).map((key) => `- ${key}: ${arg[key]}`).join("\n");
|
|
887
872
|
}
|
|
888
|
-
__name(objectToList, "objectToList");
|
|
889
873
|
|
|
890
874
|
// src/utils/modules/handlebars/helpers/join.ts
|
|
891
875
|
function join(array) {
|
|
@@ -893,13 +877,11 @@ function join(array) {
|
|
|
893
877
|
if (!Array.isArray(array)) return "";
|
|
894
878
|
return array.join(", ");
|
|
895
879
|
}
|
|
896
|
-
__name(join, "join");
|
|
897
880
|
|
|
898
881
|
// src/utils/modules/handlebars/helpers/cut.ts
|
|
899
882
|
function cutFn(str, arg) {
|
|
900
883
|
return str.toString().replace(new RegExp(arg, "g"), "");
|
|
901
884
|
}
|
|
902
|
-
__name(cutFn, "cutFn");
|
|
903
885
|
|
|
904
886
|
// src/utils/modules/handlebars/helpers/substring.ts
|
|
905
887
|
function substringFn(str, start, end) {
|
|
@@ -912,47 +894,42 @@ function substringFn(str, start, end) {
|
|
|
912
894
|
return str;
|
|
913
895
|
}
|
|
914
896
|
}
|
|
915
|
-
__name(substringFn, "substringFn");
|
|
916
897
|
|
|
917
898
|
// src/utils/modules/handlebars/helpers/with.ts
|
|
918
899
|
function withFn(options, context) {
|
|
919
900
|
return options.fn(context);
|
|
920
901
|
}
|
|
921
|
-
__name(withFn, "withFn");
|
|
922
902
|
|
|
923
903
|
// src/utils/modules/handlebars/utils/makeHandlebarsInstance.ts
|
|
924
904
|
function makeHandlebarsInstance(hbs2) {
|
|
925
905
|
const handlebars = hbs2.create();
|
|
926
906
|
const helperKeys = Object.keys(helpers_exports);
|
|
927
|
-
_registerHelpers(
|
|
928
|
-
handler: helpers_exports[a],
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
handlebars.registerHelper(
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
907
|
+
_registerHelpers(
|
|
908
|
+
helperKeys.map((a) => ({ handler: helpers_exports[a], name: a })),
|
|
909
|
+
handlebars
|
|
910
|
+
);
|
|
911
|
+
handlebars.registerHelper(
|
|
912
|
+
"hbsInTemplate",
|
|
913
|
+
function(str, substitutions) {
|
|
914
|
+
const template = handlebars.compile(str);
|
|
915
|
+
return template(substitutions, {
|
|
916
|
+
allowedProtoMethods: {
|
|
917
|
+
substring: true
|
|
918
|
+
}
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
);
|
|
922
|
+
const contextPartialKeys = Object.keys(
|
|
923
|
+
partials
|
|
924
|
+
);
|
|
945
925
|
for (const contextPartialKey of contextPartialKeys) {
|
|
946
|
-
handlebars.registerPartial(
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
const externalPartials = require(partialsPath);
|
|
951
|
-
_registerPartials(importPartials(externalPartials), handlebars);
|
|
926
|
+
handlebars.registerPartial(
|
|
927
|
+
contextPartialKey,
|
|
928
|
+
partials[contextPartialKey]
|
|
929
|
+
);
|
|
952
930
|
}
|
|
953
931
|
return handlebars;
|
|
954
932
|
}
|
|
955
|
-
__name(makeHandlebarsInstance, "makeHandlebarsInstance");
|
|
956
933
|
|
|
957
934
|
// src/utils/modules/isPromise.ts
|
|
958
935
|
function isPromise(value) {
|
|
@@ -961,24 +938,16 @@ function isPromise(value) {
|
|
|
961
938
|
}
|
|
962
939
|
return Object.prototype.toString.call(value) === "[object AsyncFunction]";
|
|
963
940
|
}
|
|
964
|
-
__name(isPromise, "isPromise");
|
|
965
941
|
|
|
966
942
|
// src/utils/modules/handlebars/utils/appendContextPath.ts
|
|
967
943
|
function appendContextPath(contextPath, id) {
|
|
968
944
|
return (contextPath ? `${contextPath}.` : "") + id;
|
|
969
945
|
}
|
|
970
|
-
__name(appendContextPath, "appendContextPath");
|
|
971
946
|
|
|
972
947
|
// src/utils/modules/handlebars/utils/blockParams.ts
|
|
973
948
|
function blockParams(params, ids) {
|
|
974
|
-
return {
|
|
975
|
-
...params,
|
|
976
|
-
...{
|
|
977
|
-
path: ids
|
|
978
|
-
}
|
|
979
|
-
};
|
|
949
|
+
return { ...params, ...{ path: ids } };
|
|
980
950
|
}
|
|
981
|
-
__name(blockParams, "blockParams");
|
|
982
951
|
|
|
983
952
|
// src/utils/modules/extend.ts
|
|
984
953
|
function extend(obj, _source) {
|
|
@@ -991,7 +960,6 @@ function extend(obj, _source) {
|
|
|
991
960
|
}
|
|
992
961
|
return obj;
|
|
993
962
|
}
|
|
994
|
-
__name(extend, "extend");
|
|
995
963
|
|
|
996
964
|
// src/utils/modules/handlebars/utils/createFrame.ts
|
|
997
965
|
function createFrame(object) {
|
|
@@ -999,7 +967,6 @@ function createFrame(object) {
|
|
|
999
967
|
frame._parent = object;
|
|
1000
968
|
return frame;
|
|
1001
969
|
}
|
|
1002
|
-
__name(createFrame, "createFrame");
|
|
1003
970
|
|
|
1004
971
|
// src/utils/modules/isEmpty.ts
|
|
1005
972
|
function isEmpty(value) {
|
|
@@ -1011,7 +978,6 @@ function isEmpty(value) {
|
|
|
1011
978
|
}
|
|
1012
979
|
return false;
|
|
1013
980
|
}
|
|
1014
|
-
__name(isEmpty, "isEmpty");
|
|
1015
981
|
|
|
1016
982
|
// src/utils/modules/handlebars/helpers/async/with.ts
|
|
1017
983
|
async function withFnAsync(context, options) {
|
|
@@ -1028,20 +994,18 @@ async function withFnAsync(context, options) {
|
|
|
1028
994
|
let { data } = options;
|
|
1029
995
|
if (options.data && options.ids) {
|
|
1030
996
|
data = createFrame(options.data);
|
|
1031
|
-
data.contextPath = appendContextPath(
|
|
997
|
+
data.contextPath = appendContextPath(
|
|
998
|
+
options.data.contextPath,
|
|
999
|
+
options.ids[0]
|
|
1000
|
+
);
|
|
1032
1001
|
}
|
|
1033
1002
|
return fn(context, {
|
|
1034
1003
|
data,
|
|
1035
|
-
blockParams: blockParams([
|
|
1036
|
-
context
|
|
1037
|
-
], [
|
|
1038
|
-
data && data.contextPath
|
|
1039
|
-
])
|
|
1004
|
+
blockParams: blockParams([context], [data && data.contextPath])
|
|
1040
1005
|
});
|
|
1041
1006
|
}
|
|
1042
1007
|
return options.inverse(this);
|
|
1043
1008
|
}
|
|
1044
|
-
__name(withFnAsync, "withFnAsync");
|
|
1045
1009
|
|
|
1046
1010
|
// src/utils/modules/handlebars/helpers/async/if.ts
|
|
1047
1011
|
async function ifFnAsync(conditional, options) {
|
|
@@ -1059,13 +1023,11 @@ async function ifFnAsync(conditional, options) {
|
|
|
1059
1023
|
return options.fn(this);
|
|
1060
1024
|
}
|
|
1061
1025
|
}
|
|
1062
|
-
__name(ifFnAsync, "ifFnAsync");
|
|
1063
1026
|
|
|
1064
1027
|
// src/utils/modules/isReadableStream.ts
|
|
1065
1028
|
function isReadableStream(obj) {
|
|
1066
1029
|
return obj && typeof obj === "object" && typeof obj.pipe === "function" && typeof obj._read === "function";
|
|
1067
1030
|
}
|
|
1068
|
-
__name(isReadableStream, "isReadableStream");
|
|
1069
1031
|
|
|
1070
1032
|
// src/utils/modules/handlebars/helpers/async/each.ts
|
|
1071
1033
|
async function eachFnAsync(arg1, options) {
|
|
@@ -1079,7 +1041,10 @@ async function eachFnAsync(arg1, options) {
|
|
|
1079
1041
|
let ret = [];
|
|
1080
1042
|
let contextPath = "";
|
|
1081
1043
|
if (options.data && options.ids) {
|
|
1082
|
-
contextPath = `${appendContextPath(
|
|
1044
|
+
contextPath = `${appendContextPath(
|
|
1045
|
+
options.data.contextPath,
|
|
1046
|
+
options.ids[0]
|
|
1047
|
+
)}.`;
|
|
1083
1048
|
}
|
|
1084
1049
|
if (typeof arg1 === "function") {
|
|
1085
1050
|
arg1 = arg1.call(this);
|
|
@@ -1097,18 +1062,16 @@ async function eachFnAsync(arg1, options) {
|
|
|
1097
1062
|
data.contextPath = contextPath + field;
|
|
1098
1063
|
}
|
|
1099
1064
|
}
|
|
1100
|
-
ret.push(
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
}));
|
|
1065
|
+
ret.push(
|
|
1066
|
+
await fn(arg1[field], {
|
|
1067
|
+
data,
|
|
1068
|
+
blockParams: blockParams(
|
|
1069
|
+
[arg1[field], field],
|
|
1070
|
+
[contextPath + field, null]
|
|
1071
|
+
)
|
|
1072
|
+
})
|
|
1073
|
+
);
|
|
1110
1074
|
}
|
|
1111
|
-
__name(execIteration, "execIteration");
|
|
1112
1075
|
if (isPromise(arg1)) {
|
|
1113
1076
|
arg1 = await arg1;
|
|
1114
1077
|
}
|
|
@@ -1157,13 +1120,10 @@ async function eachFnAsync(arg1, options) {
|
|
|
1157
1120
|
}
|
|
1158
1121
|
if (i === 0) {
|
|
1159
1122
|
ret = inverse(this);
|
|
1160
|
-
ret = [
|
|
1161
|
-
inverse(this)
|
|
1162
|
-
];
|
|
1123
|
+
ret = [inverse(this)];
|
|
1163
1124
|
}
|
|
1164
1125
|
return ret.join("");
|
|
1165
1126
|
}
|
|
1166
|
-
__name(eachFnAsync, "eachFnAsync");
|
|
1167
1127
|
|
|
1168
1128
|
// src/utils/modules/handlebars/helpers/async/unless.ts
|
|
1169
1129
|
async function unlessFnAsync(conditional, options) {
|
|
@@ -1176,7 +1136,6 @@ async function unlessFnAsync(conditional, options) {
|
|
|
1176
1136
|
hash: options.hash
|
|
1177
1137
|
});
|
|
1178
1138
|
}
|
|
1179
|
-
__name(unlessFnAsync, "unlessFnAsync");
|
|
1180
1139
|
|
|
1181
1140
|
// src/utils/modules/handlebars/helpers/async/async-helpers.ts
|
|
1182
1141
|
var asyncCoreOverrideHelpers = {
|
|
@@ -1188,9 +1147,8 @@ var asyncCoreOverrideHelpers = {
|
|
|
1188
1147
|
|
|
1189
1148
|
// src/utils/modules/handlebars/utils/makeHandlebarsInstanceAsync.ts
|
|
1190
1149
|
function makeHandlebarsInstanceAsync(hbs2) {
|
|
1191
|
-
var _a;
|
|
1192
1150
|
const handlebars = hbs2.create();
|
|
1193
|
-
const asyncCompiler =
|
|
1151
|
+
const asyncCompiler = class extends hbs2.JavaScriptCompiler {
|
|
1194
1152
|
constructor() {
|
|
1195
1153
|
super();
|
|
1196
1154
|
this.compiler = asyncCompiler;
|
|
@@ -1203,30 +1161,20 @@ function makeHandlebarsInstanceAsync(hbs2) {
|
|
|
1203
1161
|
}
|
|
1204
1162
|
appendToBuffer(source, location, explicit) {
|
|
1205
1163
|
if (!Array.isArray(source)) {
|
|
1206
|
-
source = [
|
|
1207
|
-
source
|
|
1208
|
-
];
|
|
1164
|
+
source = [source];
|
|
1209
1165
|
}
|
|
1210
1166
|
source = this.source.wrap(source, location);
|
|
1211
1167
|
if (this.environment.isSimple) {
|
|
1212
|
-
return [
|
|
1213
|
-
"return await ",
|
|
1214
|
-
source,
|
|
1215
|
-
";"
|
|
1216
|
-
];
|
|
1168
|
+
return ["return await ", source, ";"];
|
|
1217
1169
|
}
|
|
1218
1170
|
if (explicit) {
|
|
1219
|
-
return [
|
|
1220
|
-
"buffer += await ",
|
|
1221
|
-
source,
|
|
1222
|
-
";"
|
|
1223
|
-
];
|
|
1171
|
+
return ["buffer += await ", source, ";"];
|
|
1224
1172
|
}
|
|
1225
1173
|
source.appendToBuffer = true;
|
|
1226
1174
|
source.prepend("await ");
|
|
1227
1175
|
return source;
|
|
1228
1176
|
}
|
|
1229
|
-
}
|
|
1177
|
+
};
|
|
1230
1178
|
handlebars.JavaScriptCompiler = asyncCompiler;
|
|
1231
1179
|
const _compile = handlebars.compile;
|
|
1232
1180
|
const _template = handlebars.VM.template;
|
|
@@ -1237,90 +1185,110 @@ function makeHandlebarsInstanceAsync(hbs2) {
|
|
|
1237
1185
|
}
|
|
1238
1186
|
return _escapeExpression(value);
|
|
1239
1187
|
}
|
|
1240
|
-
__name(escapeExpression, "escapeExpression");
|
|
1241
1188
|
function lookupProperty(containerLookupProperty) {
|
|
1242
1189
|
return function(parent, propertyName) {
|
|
1243
1190
|
if (isPromise(parent)) {
|
|
1244
1191
|
if (typeof parent?.then === "function") {
|
|
1245
|
-
return parent.then(
|
|
1192
|
+
return parent.then(
|
|
1193
|
+
(p) => containerLookupProperty(p, propertyName)
|
|
1194
|
+
);
|
|
1246
1195
|
}
|
|
1247
|
-
return parent().then(
|
|
1196
|
+
return parent().then(
|
|
1197
|
+
(p) => containerLookupProperty(p, propertyName)
|
|
1198
|
+
);
|
|
1248
1199
|
}
|
|
1249
1200
|
return containerLookupProperty(parent, propertyName);
|
|
1250
1201
|
};
|
|
1251
1202
|
}
|
|
1252
|
-
__name(lookupProperty, "lookupProperty");
|
|
1253
1203
|
handlebars.template = function(spec) {
|
|
1254
1204
|
spec.main_d = (_prog, _props, container, _depth, data, blockParams2, depths) => async (context) => {
|
|
1255
1205
|
container.escapeExpression = escapeExpression;
|
|
1256
1206
|
container.lookupProperty = lookupProperty(container.lookupProperty);
|
|
1257
1207
|
if (depths.length == 0) {
|
|
1258
|
-
depths = [
|
|
1259
|
-
data.root
|
|
1260
|
-
];
|
|
1208
|
+
depths = [data.root];
|
|
1261
1209
|
}
|
|
1262
|
-
const v = spec.main(
|
|
1210
|
+
const v = spec.main(
|
|
1211
|
+
container,
|
|
1212
|
+
context,
|
|
1213
|
+
container.helpers,
|
|
1214
|
+
container.partials,
|
|
1215
|
+
data,
|
|
1216
|
+
blockParams2,
|
|
1217
|
+
depths
|
|
1218
|
+
);
|
|
1263
1219
|
return v;
|
|
1264
1220
|
};
|
|
1265
1221
|
return _template(spec, handlebars);
|
|
1266
1222
|
};
|
|
1267
1223
|
handlebars.compile = function(template, options) {
|
|
1268
|
-
const compiled = _compile.apply(handlebars, [
|
|
1269
|
-
template,
|
|
1270
|
-
{
|
|
1271
|
-
...options
|
|
1272
|
-
}
|
|
1273
|
-
]);
|
|
1224
|
+
const compiled = _compile.apply(handlebars, [template, { ...options }]);
|
|
1274
1225
|
return function(context, execOptions) {
|
|
1275
1226
|
context = context || {};
|
|
1276
1227
|
return compiled.call(handlebars, context, execOptions);
|
|
1277
1228
|
};
|
|
1278
1229
|
};
|
|
1279
1230
|
const helperKeys = Object.keys(helpers_exports);
|
|
1280
|
-
_registerHelpers(
|
|
1281
|
-
handler: helpers_exports[a],
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
const asyncHelperKeys = Object.keys(
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1231
|
+
_registerHelpers(
|
|
1232
|
+
helperKeys.map((a) => ({ handler: helpers_exports[a], name: a })),
|
|
1233
|
+
handlebars
|
|
1234
|
+
);
|
|
1235
|
+
const asyncHelperKeys = Object.keys(
|
|
1236
|
+
asyncCoreOverrideHelpers
|
|
1237
|
+
);
|
|
1238
|
+
_registerHelpers(
|
|
1239
|
+
asyncHelperKeys.map((a) => ({
|
|
1240
|
+
handler: asyncCoreOverrideHelpers[a],
|
|
1241
|
+
name: a
|
|
1242
|
+
})),
|
|
1243
|
+
handlebars
|
|
1244
|
+
);
|
|
1245
|
+
const contextPartialKeys = Object.keys(
|
|
1246
|
+
partials
|
|
1247
|
+
);
|
|
1290
1248
|
for (const contextPartialKey of contextPartialKeys) {
|
|
1291
|
-
handlebars.registerPartial(
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
const externalPartials = require(partialsPath);
|
|
1296
|
-
_registerPartials(importPartials(externalPartials), handlebars);
|
|
1249
|
+
handlebars.registerPartial(
|
|
1250
|
+
contextPartialKey,
|
|
1251
|
+
partials[contextPartialKey]
|
|
1252
|
+
);
|
|
1297
1253
|
}
|
|
1298
1254
|
return handlebars;
|
|
1299
1255
|
}
|
|
1300
|
-
__name(makeHandlebarsInstanceAsync, "makeHandlebarsInstanceAsync");
|
|
1301
1256
|
|
|
1302
1257
|
// src/utils/modules/handlebars/hbs.ts
|
|
1303
1258
|
var _hbsAsync = makeHandlebarsInstanceAsync(import_handlebars.default);
|
|
1304
1259
|
var _hbs = makeHandlebarsInstance(import_handlebars.default);
|
|
1305
1260
|
|
|
1261
|
+
// src/utils/modules/handlebars/utils/registerPartials.ts
|
|
1262
|
+
function _registerPartials(partials2, instance) {
|
|
1263
|
+
if (partials2 && Array.isArray(partials2)) {
|
|
1264
|
+
for (const partial of partials2) {
|
|
1265
|
+
if (partial.name && typeof partial.name === "string" && typeof partial.template === "string") {
|
|
1266
|
+
if (instance) {
|
|
1267
|
+
instance.registerPartial(partial.name, partial.template);
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1306
1274
|
// src/utils/modules/handlebars/index.ts
|
|
1307
1275
|
var hbs = {
|
|
1308
1276
|
handlebars: _hbs,
|
|
1309
|
-
registerHelpers:
|
|
1277
|
+
registerHelpers: (helpers) => {
|
|
1310
1278
|
_registerHelpers(helpers, _hbs);
|
|
1311
|
-
},
|
|
1312
|
-
registerPartials:
|
|
1279
|
+
},
|
|
1280
|
+
registerPartials: (partials2) => {
|
|
1313
1281
|
_registerPartials(partials2, _hbs);
|
|
1314
|
-
}
|
|
1282
|
+
}
|
|
1315
1283
|
};
|
|
1316
1284
|
var hbsAsync = {
|
|
1317
1285
|
handlebars: _hbsAsync,
|
|
1318
|
-
registerHelpers:
|
|
1286
|
+
registerHelpers: (helpers) => {
|
|
1319
1287
|
_registerHelpers(helpers, _hbsAsync);
|
|
1320
|
-
},
|
|
1321
|
-
registerPartials:
|
|
1288
|
+
},
|
|
1289
|
+
registerPartials: (partials2) => {
|
|
1322
1290
|
_registerPartials(partials2, _hbsAsync);
|
|
1323
|
-
}
|
|
1291
|
+
}
|
|
1324
1292
|
};
|
|
1325
1293
|
|
|
1326
1294
|
// src/utils/modules/replaceTemplateString.ts
|
|
@@ -1353,7 +1321,6 @@ function replaceTemplateString(templateString, substitutions = {}, configuration
|
|
|
1353
1321
|
});
|
|
1354
1322
|
return res;
|
|
1355
1323
|
}
|
|
1356
|
-
__name(replaceTemplateString, "replaceTemplateString");
|
|
1357
1324
|
|
|
1358
1325
|
// src/utils/modules/replaceTemplateStringAsync.ts
|
|
1359
1326
|
async function replaceTemplateStringAsync(templateString, substitutions = {}, configuration = {
|
|
@@ -1385,24 +1352,22 @@ async function replaceTemplateStringAsync(templateString, substitutions = {}, co
|
|
|
1385
1352
|
});
|
|
1386
1353
|
return res;
|
|
1387
1354
|
}
|
|
1388
|
-
__name(replaceTemplateStringAsync, "replaceTemplateStringAsync");
|
|
1389
1355
|
|
|
1390
1356
|
// src/utils/modules/asyncCallWithTimeout.ts
|
|
1391
|
-
var asyncCallWithTimeout =
|
|
1357
|
+
var asyncCallWithTimeout = async (asyncPromise, timeLimit = 1e4) => {
|
|
1392
1358
|
let timeoutHandle;
|
|
1393
1359
|
const timeoutPromise = new Promise((_resolve, reject) => {
|
|
1394
1360
|
timeoutHandle = setTimeout(() => {
|
|
1395
|
-
return reject(
|
|
1361
|
+
return reject(
|
|
1362
|
+
new Error("Unable to perform action. Try again, or use another action.")
|
|
1363
|
+
);
|
|
1396
1364
|
}, timeLimit);
|
|
1397
1365
|
});
|
|
1398
|
-
return Promise.race([
|
|
1399
|
-
asyncPromise,
|
|
1400
|
-
timeoutPromise
|
|
1401
|
-
]).then((result) => {
|
|
1366
|
+
return Promise.race([asyncPromise, timeoutPromise]).then((result) => {
|
|
1402
1367
|
clearTimeout(timeoutHandle);
|
|
1403
1368
|
return result;
|
|
1404
1369
|
});
|
|
1405
|
-
}
|
|
1370
|
+
};
|
|
1406
1371
|
|
|
1407
1372
|
// src/utils/modules/guessProviderFromModel.ts
|
|
1408
1373
|
function isModelKnownOpenAi(payload) {
|
|
@@ -1418,7 +1383,6 @@ function isModelKnownOpenAi(payload) {
|
|
|
1418
1383
|
}
|
|
1419
1384
|
return false;
|
|
1420
1385
|
}
|
|
1421
|
-
__name(isModelKnownOpenAi, "isModelKnownOpenAi");
|
|
1422
1386
|
function isModelKnownAnthropic(payload) {
|
|
1423
1387
|
const model = payload.model.toLowerCase();
|
|
1424
1388
|
if (model.startsWith("claude-")) {
|
|
@@ -1426,7 +1390,6 @@ function isModelKnownAnthropic(payload) {
|
|
|
1426
1390
|
}
|
|
1427
1391
|
return false;
|
|
1428
1392
|
}
|
|
1429
|
-
__name(isModelKnownAnthropic, "isModelKnownAnthropic");
|
|
1430
1393
|
function isModelKnownXai(payload) {
|
|
1431
1394
|
const model = payload.model.toLowerCase();
|
|
1432
1395
|
if (model.startsWith("grok-")) {
|
|
@@ -1434,7 +1397,6 @@ function isModelKnownXai(payload) {
|
|
|
1434
1397
|
}
|
|
1435
1398
|
return false;
|
|
1436
1399
|
}
|
|
1437
|
-
__name(isModelKnownXai, "isModelKnownXai");
|
|
1438
1400
|
function isModelKnownBedrockAnthropic(payload) {
|
|
1439
1401
|
const model = payload.model.toLowerCase();
|
|
1440
1402
|
if (model.startsWith("anthropic.claude-")) {
|
|
@@ -1442,7 +1404,6 @@ function isModelKnownBedrockAnthropic(payload) {
|
|
|
1442
1404
|
}
|
|
1443
1405
|
return false;
|
|
1444
1406
|
}
|
|
1445
|
-
__name(isModelKnownBedrockAnthropic, "isModelKnownBedrockAnthropic");
|
|
1446
1407
|
function guessProviderFromModel(payload) {
|
|
1447
1408
|
switch (true) {
|
|
1448
1409
|
case isModelKnownOpenAi(payload):
|
|
@@ -1457,99 +1418,16 @@ function guessProviderFromModel(payload) {
|
|
|
1457
1418
|
throw new Error("Unsupported model");
|
|
1458
1419
|
}
|
|
1459
1420
|
}
|
|
1460
|
-
__name(guessProviderFromModel, "guessProviderFromModel");
|
|
1461
1421
|
|
|
1462
1422
|
// src/utils/modules/index.ts
|
|
1463
1423
|
function registerHelpers(helpers) {
|
|
1464
1424
|
hbs.registerHelpers(helpers);
|
|
1465
1425
|
hbsAsync.registerHelpers(helpers);
|
|
1466
1426
|
}
|
|
1467
|
-
__name(registerHelpers, "registerHelpers");
|
|
1468
1427
|
function registerPartials(partials2) {
|
|
1469
1428
|
hbs.registerPartials(partials2);
|
|
1470
1429
|
hbsAsync.registerPartials(partials2);
|
|
1471
1430
|
}
|
|
1472
|
-
__name(registerPartials, "registerPartials");
|
|
1473
|
-
|
|
1474
|
-
// src/llm/output/_utils/getResultText.ts
|
|
1475
|
-
function getResultText(content) {
|
|
1476
|
-
if (content.length === 1 && content.every((a) => a.type === "text")) {
|
|
1477
|
-
return content[0]?.text || "";
|
|
1478
|
-
}
|
|
1479
|
-
return "";
|
|
1480
|
-
}
|
|
1481
|
-
__name(getResultText, "getResultText");
|
|
1482
|
-
|
|
1483
|
-
// src/parser/parsers/OpenAiFunctionParser.ts
|
|
1484
|
-
var _OpenAiFunctionParser = class _OpenAiFunctionParser extends BaseParser {
|
|
1485
|
-
constructor(options) {
|
|
1486
|
-
super("openAiFunction", options, "function_call");
|
|
1487
|
-
__publicField(this, "parser");
|
|
1488
|
-
this.parser = options.parser;
|
|
1489
|
-
}
|
|
1490
|
-
parse(text, _options) {
|
|
1491
|
-
const functionUse = text?.find((a) => a.type === "function_use");
|
|
1492
|
-
if (functionUse && "name" in functionUse && "input" in functionUse) {
|
|
1493
|
-
return {
|
|
1494
|
-
name: functionUse.name,
|
|
1495
|
-
arguments: maybeParseJSON(functionUse.input)
|
|
1496
|
-
};
|
|
1497
|
-
}
|
|
1498
|
-
return this.parser.parse(getResultText(text));
|
|
1499
|
-
}
|
|
1500
|
-
};
|
|
1501
|
-
__name(_OpenAiFunctionParser, "OpenAiFunctionParser");
|
|
1502
|
-
var OpenAiFunctionParser = _OpenAiFunctionParser;
|
|
1503
|
-
|
|
1504
|
-
// src/parser/parsers/StringParser.ts
|
|
1505
|
-
var _StringParser = class _StringParser extends BaseParser {
|
|
1506
|
-
constructor(options) {
|
|
1507
|
-
super("string", options);
|
|
1508
|
-
}
|
|
1509
|
-
parse(text, _options) {
|
|
1510
|
-
assert(typeof text === "string", `Invalid input. Expected string. Received ${typeof text}.`);
|
|
1511
|
-
const parsed = text.toString();
|
|
1512
|
-
return parsed;
|
|
1513
|
-
}
|
|
1514
|
-
};
|
|
1515
|
-
__name(_StringParser, "StringParser");
|
|
1516
|
-
var StringParser = _StringParser;
|
|
1517
|
-
|
|
1518
|
-
// src/parser/parsers/BooleanParser.ts
|
|
1519
|
-
var _BooleanParser = class _BooleanParser extends BaseParser {
|
|
1520
|
-
constructor(options) {
|
|
1521
|
-
super("boolean", options);
|
|
1522
|
-
}
|
|
1523
|
-
parse(text) {
|
|
1524
|
-
assert(typeof text === "string", `Invalid input. Expected string. Received ${typeof text}.`);
|
|
1525
|
-
const clean = text.toLowerCase().trim();
|
|
1526
|
-
if (clean === "true") {
|
|
1527
|
-
return true;
|
|
1528
|
-
}
|
|
1529
|
-
return false;
|
|
1530
|
-
}
|
|
1531
|
-
};
|
|
1532
|
-
__name(_BooleanParser, "BooleanParser");
|
|
1533
|
-
var BooleanParser = _BooleanParser;
|
|
1534
|
-
|
|
1535
|
-
// src/utils/modules/isFinite.ts
|
|
1536
|
-
function isFinite(value) {
|
|
1537
|
-
return typeof value === "number" && Number.isFinite(value);
|
|
1538
|
-
}
|
|
1539
|
-
__name(isFinite, "isFinite");
|
|
1540
|
-
|
|
1541
|
-
// src/parser/parsers/NumberParser.ts
|
|
1542
|
-
var _NumberParser = class _NumberParser extends BaseParser {
|
|
1543
|
-
constructor(options) {
|
|
1544
|
-
super("number", options);
|
|
1545
|
-
}
|
|
1546
|
-
parse(text) {
|
|
1547
|
-
const match = text.match(/\d/g);
|
|
1548
|
-
return match && isFinite(toNumber(match[0])) ? toNumber(match[0]) : -1;
|
|
1549
|
-
}
|
|
1550
|
-
};
|
|
1551
|
-
__name(_NumberParser, "NumberParser");
|
|
1552
|
-
var NumberParser = _NumberParser;
|
|
1553
1431
|
|
|
1554
1432
|
// src/parser/_utils.ts
|
|
1555
1433
|
var import_jsonschema = require("jsonschema");
|
|
@@ -1559,7 +1437,6 @@ function enforceParserSchema(schema, parsed) {
|
|
|
1559
1437
|
}
|
|
1560
1438
|
return filterObjectOnSchema(schema, parsed);
|
|
1561
1439
|
}
|
|
1562
|
-
__name(enforceParserSchema, "enforceParserSchema");
|
|
1563
1440
|
function validateParserSchema(schema, parsed) {
|
|
1564
1441
|
if (!schema || !parsed || typeof parsed !== "object") {
|
|
1565
1442
|
return null;
|
|
@@ -1570,10 +1447,9 @@ function validateParserSchema(schema, parsed) {
|
|
|
1570
1447
|
}
|
|
1571
1448
|
return null;
|
|
1572
1449
|
}
|
|
1573
|
-
__name(validateParserSchema, "validateParserSchema");
|
|
1574
1450
|
|
|
1575
1451
|
// src/utils/modules/errors.ts
|
|
1576
|
-
var
|
|
1452
|
+
var LlmExeError = class extends Error {
|
|
1577
1453
|
constructor(message, code, context) {
|
|
1578
1454
|
super(message ?? "");
|
|
1579
1455
|
__publicField(this, "code");
|
|
@@ -1586,11 +1462,9 @@ var _LlmExeError = class _LlmExeError extends Error {
|
|
|
1586
1462
|
}
|
|
1587
1463
|
}
|
|
1588
1464
|
};
|
|
1589
|
-
__name(_LlmExeError, "LlmExeError");
|
|
1590
|
-
var LlmExeError = _LlmExeError;
|
|
1591
1465
|
|
|
1592
1466
|
// src/parser/parsers/JsonParser.ts
|
|
1593
|
-
var
|
|
1467
|
+
var JsonParser = class extends BaseParserWithJson {
|
|
1594
1468
|
constructor(options = {}) {
|
|
1595
1469
|
super("json", options);
|
|
1596
1470
|
}
|
|
@@ -1613,8 +1487,6 @@ var _JsonParser = class _JsonParser extends BaseParserWithJson {
|
|
|
1613
1487
|
return parsed;
|
|
1614
1488
|
}
|
|
1615
1489
|
};
|
|
1616
|
-
__name(_JsonParser, "JsonParser");
|
|
1617
|
-
var JsonParser = _JsonParser;
|
|
1618
1490
|
|
|
1619
1491
|
// src/utils/modules/camelCase.ts
|
|
1620
1492
|
function camelCase(input) {
|
|
@@ -1629,10 +1501,9 @@ function camelCase(input) {
|
|
|
1629
1501
|
}
|
|
1630
1502
|
}).join("");
|
|
1631
1503
|
}
|
|
1632
|
-
__name(camelCase, "camelCase");
|
|
1633
1504
|
|
|
1634
1505
|
// src/parser/parsers/ListToJsonParser.ts
|
|
1635
|
-
var
|
|
1506
|
+
var ListToJsonParser = class extends BaseParserWithJson {
|
|
1636
1507
|
constructor(options = {}) {
|
|
1637
1508
|
super("listToJson", options);
|
|
1638
1509
|
}
|
|
@@ -1662,76 +1533,65 @@ var _ListToJsonParser = class _ListToJsonParser extends BaseParserWithJson {
|
|
|
1662
1533
|
return output;
|
|
1663
1534
|
}
|
|
1664
1535
|
};
|
|
1665
|
-
__name(_ListToJsonParser, "ListToJsonParser");
|
|
1666
|
-
var ListToJsonParser = _ListToJsonParser;
|
|
1667
1536
|
|
|
1668
1537
|
// src/parser/parsers/ListToKeyValueParser.ts
|
|
1669
|
-
var
|
|
1538
|
+
var ListToKeyValueParser = class extends BaseParser {
|
|
1670
1539
|
constructor(options) {
|
|
1671
1540
|
super("listToKeyValue", options);
|
|
1672
1541
|
}
|
|
1673
1542
|
parse(text) {
|
|
1674
|
-
const lines = text.split("\n").map((s) => s.replace("- ", "").replace(
|
|
1543
|
+
const lines = text.split("\n").map((s) => s.replace("- ", "").replace(/'/g, "'"));
|
|
1675
1544
|
let res = [];
|
|
1676
1545
|
for (const line of lines) {
|
|
1677
1546
|
const [key, value] = line.split(":");
|
|
1678
1547
|
if (key && value) {
|
|
1679
|
-
res.push({
|
|
1680
|
-
key: key?.trim(),
|
|
1681
|
-
value: value?.trim()
|
|
1682
|
-
});
|
|
1548
|
+
res.push({ key: key?.trim(), value: value?.trim() });
|
|
1683
1549
|
}
|
|
1684
1550
|
}
|
|
1685
1551
|
return res;
|
|
1686
1552
|
}
|
|
1687
1553
|
};
|
|
1688
|
-
__name(_ListToKeyValueParser, "ListToKeyValueParser");
|
|
1689
|
-
var ListToKeyValueParser = _ListToKeyValueParser;
|
|
1690
1554
|
|
|
1691
1555
|
// src/parser/parsers/CustomParser.ts
|
|
1692
|
-
var
|
|
1556
|
+
var CustomParser = class extends BaseParser {
|
|
1693
1557
|
/**
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1558
|
+
* Creates a new CustomParser instance.
|
|
1559
|
+
* @param {string} name The name of the parser.
|
|
1560
|
+
* @param {any} parserFn The custom parsing function.
|
|
1561
|
+
*/
|
|
1698
1562
|
constructor(name, parserFn) {
|
|
1699
1563
|
super(name);
|
|
1700
1564
|
/**
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1565
|
+
* Custom parsing function.
|
|
1566
|
+
* @type {any}
|
|
1567
|
+
*/
|
|
1704
1568
|
__publicField(this, "parserFn");
|
|
1705
1569
|
this.parserFn = parserFn;
|
|
1706
1570
|
}
|
|
1707
1571
|
/**
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1572
|
+
* Parses the text using the custom parsing function.
|
|
1573
|
+
* @param {string} text The text to be parsed.
|
|
1574
|
+
* @param {any} inputValues Additional input values for the parser function.
|
|
1575
|
+
* @returns {O} The parsed value.
|
|
1576
|
+
*/
|
|
1713
1577
|
parse(text, inputValues) {
|
|
1714
1578
|
return this.parserFn.call(this, text, inputValues);
|
|
1715
1579
|
}
|
|
1716
1580
|
};
|
|
1717
|
-
__name(_CustomParser, "CustomParser");
|
|
1718
|
-
var CustomParser = _CustomParser;
|
|
1719
1581
|
|
|
1720
1582
|
// src/parser/parsers/ListToArrayParser.ts
|
|
1721
|
-
var
|
|
1583
|
+
var ListToArrayParser = class extends BaseParser {
|
|
1722
1584
|
constructor() {
|
|
1723
1585
|
super("listToArray");
|
|
1724
1586
|
}
|
|
1725
1587
|
parse(text) {
|
|
1726
|
-
const lines = text.split("\n").map((s) => s.replace(/^- /, "").replace(
|
|
1588
|
+
const lines = text.split("\n").map((s) => s.replace(/^- /, "").replace(/'/g, "'").trim());
|
|
1727
1589
|
return lines;
|
|
1728
1590
|
}
|
|
1729
1591
|
};
|
|
1730
|
-
__name(_ListToArrayParser, "ListToArrayParser");
|
|
1731
|
-
var ListToArrayParser = _ListToArrayParser;
|
|
1732
1592
|
|
|
1733
1593
|
// src/parser/parsers/ReplaceStringTemplateParser.ts
|
|
1734
|
-
var
|
|
1594
|
+
var ReplaceStringTemplateParser = class extends BaseParser {
|
|
1735
1595
|
constructor(options) {
|
|
1736
1596
|
super("replaceStringTemplate", options);
|
|
1737
1597
|
}
|
|
@@ -1739,17 +1599,38 @@ var _ReplaceStringTemplateParser = class _ReplaceStringTemplateParser extends Ba
|
|
|
1739
1599
|
return replaceTemplateString(text, attributes);
|
|
1740
1600
|
}
|
|
1741
1601
|
};
|
|
1742
|
-
|
|
1743
|
-
|
|
1602
|
+
|
|
1603
|
+
// src/parser/singleKeyObjectToString.ts
|
|
1604
|
+
function singleKeyObjectToString(input) {
|
|
1605
|
+
try {
|
|
1606
|
+
const parsed = JSON.parse(input);
|
|
1607
|
+
if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
|
|
1608
|
+
const keys = Object.keys(parsed);
|
|
1609
|
+
if (keys.length === 1) {
|
|
1610
|
+
const value = parsed[keys[0]];
|
|
1611
|
+
if (typeof value === "string") {
|
|
1612
|
+
return value;
|
|
1613
|
+
} else {
|
|
1614
|
+
return input;
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
} catch {
|
|
1619
|
+
}
|
|
1620
|
+
return input;
|
|
1621
|
+
}
|
|
1744
1622
|
|
|
1745
1623
|
// src/parser/parsers/MarkdownCodeBlocks.ts
|
|
1746
|
-
var
|
|
1624
|
+
var MarkdownCodeBlocksParser = class extends BaseParser {
|
|
1747
1625
|
constructor(options) {
|
|
1748
1626
|
super("markdownCodeBlocks", options);
|
|
1749
1627
|
}
|
|
1750
1628
|
parse(input) {
|
|
1751
1629
|
const out = [];
|
|
1752
|
-
|
|
1630
|
+
if (isObjectStringified(input)) {
|
|
1631
|
+
input = singleKeyObjectToString(input);
|
|
1632
|
+
}
|
|
1633
|
+
const regex = input.matchAll(new RegExp(/```(\w*)\n([\s\S]*?)```/, "g"));
|
|
1753
1634
|
for (const iterator of regex) {
|
|
1754
1635
|
if (iterator) {
|
|
1755
1636
|
const [_input, language, code] = iterator;
|
|
@@ -1762,24 +1643,26 @@ var _MarkdownCodeBlocksParser = class _MarkdownCodeBlocksParser extends BasePars
|
|
|
1762
1643
|
return out;
|
|
1763
1644
|
}
|
|
1764
1645
|
};
|
|
1765
|
-
__name(_MarkdownCodeBlocksParser, "MarkdownCodeBlocksParser");
|
|
1766
|
-
var MarkdownCodeBlocksParser = _MarkdownCodeBlocksParser;
|
|
1767
1646
|
|
|
1768
1647
|
// src/parser/parsers/MarkdownCodeBlock.ts
|
|
1769
|
-
var
|
|
1648
|
+
var MarkdownCodeBlockParser = class extends BaseParser {
|
|
1770
1649
|
constructor(options) {
|
|
1771
1650
|
super("markdownCodeBlock", options);
|
|
1772
1651
|
}
|
|
1773
1652
|
parse(input) {
|
|
1774
1653
|
const [block] = new MarkdownCodeBlocksParser().parse(input);
|
|
1654
|
+
if (!block) {
|
|
1655
|
+
return {
|
|
1656
|
+
code: "",
|
|
1657
|
+
language: ""
|
|
1658
|
+
};
|
|
1659
|
+
}
|
|
1775
1660
|
return block;
|
|
1776
1661
|
}
|
|
1777
1662
|
};
|
|
1778
|
-
__name(_MarkdownCodeBlockParser, "MarkdownCodeBlockParser");
|
|
1779
|
-
var MarkdownCodeBlockParser = _MarkdownCodeBlockParser;
|
|
1780
1663
|
|
|
1781
1664
|
// src/parser/parsers/StringExtractParser.ts
|
|
1782
|
-
var
|
|
1665
|
+
var StringExtractParser = class extends BaseParser {
|
|
1783
1666
|
constructor(options) {
|
|
1784
1667
|
super("stringExtract", options);
|
|
1785
1668
|
__publicField(this, "enum", []);
|
|
@@ -1792,7 +1675,10 @@ var _StringExtractParser = class _StringExtractParser extends BaseParser {
|
|
|
1792
1675
|
}
|
|
1793
1676
|
}
|
|
1794
1677
|
parse(text) {
|
|
1795
|
-
assert(
|
|
1678
|
+
assert(
|
|
1679
|
+
typeof text === "string",
|
|
1680
|
+
`Invalid input. Expected string. Received ${typeof text}.`
|
|
1681
|
+
);
|
|
1796
1682
|
for (const option of this.enum) {
|
|
1797
1683
|
const regex = this.ignoreCase ? new RegExp(option.toLowerCase(), "i") : new RegExp(option);
|
|
1798
1684
|
if (regex.test(text)) {
|
|
@@ -1802,8 +1688,6 @@ var _StringExtractParser = class _StringExtractParser extends BaseParser {
|
|
|
1802
1688
|
return "";
|
|
1803
1689
|
}
|
|
1804
1690
|
};
|
|
1805
|
-
__name(_StringExtractParser, "StringExtractParser");
|
|
1806
|
-
var StringExtractParser = _StringExtractParser;
|
|
1807
1691
|
|
|
1808
1692
|
// src/parser/_functions.ts
|
|
1809
1693
|
function createParser(type, options = {}) {
|
|
@@ -1833,16 +1717,46 @@ function createParser(type, options = {}) {
|
|
|
1833
1717
|
return new StringParser();
|
|
1834
1718
|
}
|
|
1835
1719
|
}
|
|
1836
|
-
__name(createParser, "createParser");
|
|
1837
1720
|
function createCustomParser(name, parserFn) {
|
|
1838
1721
|
return new CustomParser(name, parserFn);
|
|
1839
1722
|
}
|
|
1840
|
-
|
|
1723
|
+
|
|
1724
|
+
// src/llm/output/_utils/getResultText.ts
|
|
1725
|
+
function getResultText(content) {
|
|
1726
|
+
if (content.length === 1 && content.every((a) => a.type === "text")) {
|
|
1727
|
+
return content[0]?.text || "";
|
|
1728
|
+
}
|
|
1729
|
+
return "";
|
|
1730
|
+
}
|
|
1731
|
+
|
|
1732
|
+
// src/parser/parsers/LlmNativeFunctionParser.ts
|
|
1733
|
+
var LlmNativeFunctionParser = class extends BaseParser {
|
|
1734
|
+
constructor(options) {
|
|
1735
|
+
super("openAiFunction", options, "function_call");
|
|
1736
|
+
__publicField(this, "parser");
|
|
1737
|
+
this.parser = options.parser;
|
|
1738
|
+
}
|
|
1739
|
+
parse(text, _options) {
|
|
1740
|
+
const functionUse = text?.find((a) => a.type === "function_use");
|
|
1741
|
+
if (functionUse && "name" in functionUse && "input" in functionUse) {
|
|
1742
|
+
return {
|
|
1743
|
+
name: functionUse.name,
|
|
1744
|
+
arguments: maybeParseJSON(functionUse.input)
|
|
1745
|
+
};
|
|
1746
|
+
}
|
|
1747
|
+
return this.parser.parse(getResultText(text));
|
|
1748
|
+
}
|
|
1749
|
+
};
|
|
1750
|
+
var OpenAiFunctionParser = LlmNativeFunctionParser;
|
|
1841
1751
|
|
|
1842
1752
|
// src/executor/llm.ts
|
|
1843
|
-
var
|
|
1753
|
+
var LlmExecutor = class extends BaseExecutor {
|
|
1844
1754
|
constructor(llmConfiguration, options) {
|
|
1845
|
-
super(
|
|
1755
|
+
super(
|
|
1756
|
+
llmConfiguration.name || "anonymous-llm-executor",
|
|
1757
|
+
"llm-executor",
|
|
1758
|
+
options
|
|
1759
|
+
);
|
|
1846
1760
|
__publicField(this, "llm");
|
|
1847
1761
|
__publicField(this, "prompt");
|
|
1848
1762
|
__publicField(this, "promptFn");
|
|
@@ -1858,12 +1772,13 @@ var _LlmExecutor = class _LlmExecutor extends BaseExecutor {
|
|
|
1858
1772
|
}
|
|
1859
1773
|
}
|
|
1860
1774
|
async execute(_input, _options) {
|
|
1775
|
+
const input = _input ?? {};
|
|
1861
1776
|
if (this?.parser instanceof JsonParser && this.parser.schema) {
|
|
1862
1777
|
_options = Object.assign(_options || {}, {
|
|
1863
1778
|
jsonSchema: this.parser.schema
|
|
1864
1779
|
});
|
|
1865
1780
|
}
|
|
1866
|
-
return super.execute(
|
|
1781
|
+
return super.execute(input, _options);
|
|
1867
1782
|
}
|
|
1868
1783
|
async handler(_input, ..._args) {
|
|
1869
1784
|
const call = await this.llm.call(_input, ..._args);
|
|
@@ -1908,57 +1823,53 @@ var _LlmExecutor = class _LlmExecutor extends BaseExecutor {
|
|
|
1908
1823
|
return this.llm.getTraceId();
|
|
1909
1824
|
}
|
|
1910
1825
|
};
|
|
1911
|
-
__name(_LlmExecutor, "LlmExecutor");
|
|
1912
|
-
var LlmExecutor = _LlmExecutor;
|
|
1913
|
-
|
|
1914
|
-
// src/executor/_functions.ts
|
|
1915
|
-
function createCoreExecutor(handler, options) {
|
|
1916
|
-
return new CoreExecutor({
|
|
1917
|
-
handler
|
|
1918
|
-
}, options);
|
|
1919
|
-
}
|
|
1920
|
-
__name(createCoreExecutor, "createCoreExecutor");
|
|
1921
|
-
function createLlmExecutor(llmConfiguration, options) {
|
|
1922
|
-
return new LlmExecutor(llmConfiguration, options);
|
|
1923
|
-
}
|
|
1924
|
-
__name(createLlmExecutor, "createLlmExecutor");
|
|
1925
1826
|
|
|
1926
1827
|
// src/executor/llm-openai-function.ts
|
|
1927
|
-
var
|
|
1828
|
+
var LlmExecutorWithFunctions = class extends LlmExecutor {
|
|
1928
1829
|
constructor(llmConfiguration, options) {
|
|
1929
|
-
super(
|
|
1930
|
-
|
|
1931
|
-
parser:
|
|
1932
|
-
|
|
1933
|
-
|
|
1830
|
+
super(
|
|
1831
|
+
Object.assign({}, llmConfiguration, {
|
|
1832
|
+
parser: new LlmNativeFunctionParser({
|
|
1833
|
+
parser: llmConfiguration.parser || new StringParser()
|
|
1834
|
+
})
|
|
1835
|
+
}),
|
|
1836
|
+
options
|
|
1837
|
+
);
|
|
1934
1838
|
}
|
|
1935
1839
|
async execute(_input, _options) {
|
|
1936
1840
|
return super.execute(_input, _options);
|
|
1937
1841
|
}
|
|
1938
1842
|
};
|
|
1939
|
-
|
|
1940
|
-
|
|
1843
|
+
var LlmExecutorOpenAiFunctions = class extends LlmExecutorWithFunctions {
|
|
1844
|
+
};
|
|
1845
|
+
|
|
1846
|
+
// src/executor/_functions.ts
|
|
1847
|
+
function createCoreExecutor(handler, options) {
|
|
1848
|
+
return new CoreExecutor({ handler }, options);
|
|
1849
|
+
}
|
|
1850
|
+
function createLlmExecutor(llmConfiguration, options) {
|
|
1851
|
+
return new LlmExecutor(llmConfiguration, options);
|
|
1852
|
+
}
|
|
1853
|
+
function createLlmFunctionExecutor(llmConfiguration, options) {
|
|
1854
|
+
return new LlmExecutorWithFunctions(
|
|
1855
|
+
llmConfiguration,
|
|
1856
|
+
options
|
|
1857
|
+
);
|
|
1858
|
+
}
|
|
1941
1859
|
|
|
1942
1860
|
// src/utils/modules/enforceResultAttributes.ts
|
|
1943
1861
|
function enforceResultAttributes(input) {
|
|
1944
1862
|
if (!input) {
|
|
1945
|
-
return {
|
|
1946
|
-
result: input,
|
|
1947
|
-
attributes: {}
|
|
1948
|
-
};
|
|
1863
|
+
return { result: input, attributes: {} };
|
|
1949
1864
|
}
|
|
1950
1865
|
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))) {
|
|
1951
1866
|
return input;
|
|
1952
1867
|
}
|
|
1953
|
-
return {
|
|
1954
|
-
result: input,
|
|
1955
|
-
attributes: {}
|
|
1956
|
-
};
|
|
1868
|
+
return { result: input, attributes: {} };
|
|
1957
1869
|
}
|
|
1958
|
-
__name(enforceResultAttributes, "enforceResultAttributes");
|
|
1959
1870
|
|
|
1960
1871
|
// src/plugins/callable/callable.ts
|
|
1961
|
-
var
|
|
1872
|
+
var CallableExecutor = class {
|
|
1962
1873
|
constructor(options) {
|
|
1963
1874
|
__publicField(this, "name");
|
|
1964
1875
|
__publicField(this, "key");
|
|
@@ -1993,32 +1904,29 @@ var _CallableExecutor = class _CallableExecutor {
|
|
|
1993
1904
|
async validateInput(input) {
|
|
1994
1905
|
try {
|
|
1995
1906
|
if (typeof this._validateInput === "function") {
|
|
1996
|
-
const response = await this._validateInput(
|
|
1907
|
+
const response = await this._validateInput(
|
|
1908
|
+
ensureInputIsObject(input),
|
|
1909
|
+
this._handler.getMetadata()
|
|
1910
|
+
);
|
|
1997
1911
|
return enforceResultAttributes(response);
|
|
1998
1912
|
}
|
|
1999
|
-
return {
|
|
2000
|
-
result: true,
|
|
2001
|
-
attributes: {}
|
|
2002
|
-
};
|
|
1913
|
+
return { result: true, attributes: {} };
|
|
2003
1914
|
} catch (error) {
|
|
2004
|
-
return {
|
|
2005
|
-
result: false,
|
|
2006
|
-
attributes: {
|
|
2007
|
-
error: error.message
|
|
2008
|
-
}
|
|
2009
|
-
};
|
|
1915
|
+
return { result: false, attributes: { error: error.message } };
|
|
2010
1916
|
}
|
|
2011
1917
|
}
|
|
2012
1918
|
visibilityHandler(input, attributes) {
|
|
2013
1919
|
if (typeof this._visibilityHandler === "function") {
|
|
2014
|
-
return this._visibilityHandler(
|
|
1920
|
+
return this._visibilityHandler(
|
|
1921
|
+
input,
|
|
1922
|
+
this._handler.getMetadata(),
|
|
1923
|
+
attributes
|
|
1924
|
+
);
|
|
2015
1925
|
}
|
|
2016
1926
|
return true;
|
|
2017
1927
|
}
|
|
2018
1928
|
};
|
|
2019
|
-
|
|
2020
|
-
var CallableExecutor = _CallableExecutor;
|
|
2021
|
-
var _UseExecutorsBase = class _UseExecutorsBase {
|
|
1929
|
+
var UseExecutorsBase = class {
|
|
2022
1930
|
constructor(handlers) {
|
|
2023
1931
|
__publicField(this, "handlers", []);
|
|
2024
1932
|
this.handlers = handlers;
|
|
@@ -2030,18 +1938,21 @@ var _UseExecutorsBase = class _UseExecutorsBase {
|
|
|
2030
1938
|
return this.handlers.find((a) => a.name === name);
|
|
2031
1939
|
}
|
|
2032
1940
|
getFunctions() {
|
|
2033
|
-
return [
|
|
2034
|
-
...this.handlers
|
|
2035
|
-
];
|
|
1941
|
+
return [...this.handlers];
|
|
2036
1942
|
}
|
|
2037
1943
|
getVisibleFunctions(_input, _attributes = {}) {
|
|
2038
1944
|
const handlers = this.getFunctions();
|
|
2039
|
-
return handlers.filter(
|
|
1945
|
+
return handlers.filter(
|
|
1946
|
+
(a) => typeof a.visibilityHandler === "undefined" || typeof a.visibilityHandler === "function" && a.visibilityHandler(_input, _attributes)
|
|
1947
|
+
);
|
|
2040
1948
|
}
|
|
2041
1949
|
async callFunction(name, input) {
|
|
2042
1950
|
try {
|
|
2043
1951
|
const handler = this.getFunction(name);
|
|
2044
|
-
assert(
|
|
1952
|
+
assert(
|
|
1953
|
+
handler,
|
|
1954
|
+
`[invalid handler] The handler (${name}) does not exist.`
|
|
1955
|
+
);
|
|
2045
1956
|
const result = await handler.execute(ensureInputIsObject(input));
|
|
2046
1957
|
return result;
|
|
2047
1958
|
} catch (error) {
|
|
@@ -2051,41 +1962,37 @@ var _UseExecutorsBase = class _UseExecutorsBase {
|
|
|
2051
1962
|
async validateFunctionInput(name, input) {
|
|
2052
1963
|
try {
|
|
2053
1964
|
const handler = this.getFunction(name);
|
|
2054
|
-
assert(
|
|
2055
|
-
|
|
1965
|
+
assert(
|
|
1966
|
+
handler,
|
|
1967
|
+
`[invalid handler] The handler (${name}) does not exist.`
|
|
1968
|
+
);
|
|
1969
|
+
const result = await handler.validateInput(
|
|
1970
|
+
ensureInputIsObject(input)
|
|
1971
|
+
);
|
|
2056
1972
|
return result;
|
|
2057
1973
|
} catch (error) {
|
|
2058
|
-
return {
|
|
2059
|
-
result: false,
|
|
2060
|
-
attributes: {
|
|
2061
|
-
error: error.message
|
|
2062
|
-
}
|
|
2063
|
-
};
|
|
1974
|
+
return { result: false, attributes: { error: error.message } };
|
|
2064
1975
|
}
|
|
2065
1976
|
}
|
|
2066
1977
|
};
|
|
2067
|
-
__name(_UseExecutorsBase, "UseExecutorsBase");
|
|
2068
|
-
var UseExecutorsBase = _UseExecutorsBase;
|
|
2069
1978
|
|
|
2070
1979
|
// src/plugins/callable/index.ts
|
|
2071
1980
|
function createCallableExecutor(options) {
|
|
2072
1981
|
return new CallableExecutor(options);
|
|
2073
1982
|
}
|
|
2074
|
-
|
|
2075
|
-
var _UseExecutors = class _UseExecutors extends UseExecutorsBase {
|
|
1983
|
+
var UseExecutors = class extends UseExecutorsBase {
|
|
2076
1984
|
constructor(handlers) {
|
|
2077
1985
|
super(handlers);
|
|
2078
1986
|
}
|
|
2079
1987
|
};
|
|
2080
|
-
__name(_UseExecutors, "UseExecutors");
|
|
2081
|
-
var UseExecutors = _UseExecutors;
|
|
2082
1988
|
function useExecutors(executors) {
|
|
2083
|
-
return new UseExecutors(
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
1989
|
+
return new UseExecutors(
|
|
1990
|
+
executors.map((e) => {
|
|
1991
|
+
if (e instanceof CallableExecutor) return e;
|
|
1992
|
+
return createCallableExecutor(e);
|
|
1993
|
+
})
|
|
1994
|
+
);
|
|
2087
1995
|
}
|
|
2088
|
-
__name(useExecutors, "useExecutors");
|
|
2089
1996
|
|
|
2090
1997
|
// src/utils/modules/deepClone.ts
|
|
2091
1998
|
function deepClone(obj) {
|
|
@@ -2107,7 +2014,6 @@ function deepClone(obj) {
|
|
|
2107
2014
|
}
|
|
2108
2015
|
return obj;
|
|
2109
2016
|
}
|
|
2110
|
-
__name(deepClone, "deepClone");
|
|
2111
2017
|
|
|
2112
2018
|
// src/llm/_utils.withDefaultModel.ts
|
|
2113
2019
|
function withDefaultModel(obj1, model) {
|
|
@@ -2129,7 +2035,15 @@ function withDefaultModel(obj1, model) {
|
|
|
2129
2035
|
}
|
|
2130
2036
|
return copy;
|
|
2131
2037
|
}
|
|
2132
|
-
|
|
2038
|
+
|
|
2039
|
+
// src/utils/modules/getEnvironmentVariable.ts
|
|
2040
|
+
function getEnvironmentVariable(name) {
|
|
2041
|
+
if (typeof process === "object" && process?.env) {
|
|
2042
|
+
return process.env[name];
|
|
2043
|
+
} else {
|
|
2044
|
+
return void 0;
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2133
2047
|
|
|
2134
2048
|
// src/llm/config/openai/index.ts
|
|
2135
2049
|
var openAiChatV1 = {
|
|
@@ -2149,17 +2063,12 @@ var openAiChatV1 = {
|
|
|
2149
2063
|
mapBody: {
|
|
2150
2064
|
prompt: {
|
|
2151
2065
|
key: "messages",
|
|
2152
|
-
sanitize:
|
|
2066
|
+
sanitize: (v) => {
|
|
2153
2067
|
if (typeof v === "string") {
|
|
2154
|
-
return [
|
|
2155
|
-
{
|
|
2156
|
-
role: "user",
|
|
2157
|
-
content: v
|
|
2158
|
-
}
|
|
2159
|
-
];
|
|
2068
|
+
return [{ role: "user", content: v }];
|
|
2160
2069
|
}
|
|
2161
2070
|
return v;
|
|
2162
|
-
}
|
|
2071
|
+
}
|
|
2163
2072
|
},
|
|
2164
2073
|
model: {
|
|
2165
2074
|
key: "model"
|
|
@@ -2169,7 +2078,7 @@ var openAiChatV1 = {
|
|
|
2169
2078
|
},
|
|
2170
2079
|
useJson: {
|
|
2171
2080
|
key: "response_format.type",
|
|
2172
|
-
sanitize:
|
|
2081
|
+
sanitize: (v) => v ? "json_object" : "text"
|
|
2173
2082
|
}
|
|
2174
2083
|
}
|
|
2175
2084
|
};
|
|
@@ -2199,7 +2108,7 @@ var openAiChatMockV1 = {
|
|
|
2199
2108
|
},
|
|
2200
2109
|
useJson: {
|
|
2201
2110
|
key: "response_format.type",
|
|
2202
|
-
sanitize:
|
|
2111
|
+
sanitize: (v) => v ? "json_object" : "text"
|
|
2203
2112
|
}
|
|
2204
2113
|
}
|
|
2205
2114
|
};
|
|
@@ -2213,35 +2122,17 @@ var openai = {
|
|
|
2213
2122
|
// src/llm/config/anthropic/promptSanitize.ts
|
|
2214
2123
|
function anthropicPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
2215
2124
|
if (typeof _messages === "string") {
|
|
2216
|
-
return [
|
|
2217
|
-
{
|
|
2218
|
-
role: "user",
|
|
2219
|
-
content: _messages
|
|
2220
|
-
}
|
|
2221
|
-
];
|
|
2125
|
+
return [{ role: "user", content: _messages }];
|
|
2222
2126
|
}
|
|
2223
|
-
const [first, ...messages] = [
|
|
2224
|
-
..._messages.map((a) => ({
|
|
2225
|
-
...a
|
|
2226
|
-
}))
|
|
2227
|
-
];
|
|
2127
|
+
const [first, ...messages] = [..._messages.map((a) => ({ ...a }))];
|
|
2228
2128
|
if (first.role === "system" && messages.length === 0) {
|
|
2229
|
-
return [
|
|
2230
|
-
{
|
|
2231
|
-
role: "user",
|
|
2232
|
-
content: first.content
|
|
2233
|
-
},
|
|
2234
|
-
...messages
|
|
2235
|
-
];
|
|
2129
|
+
return [{ role: "user", content: first.content }, ...messages];
|
|
2236
2130
|
}
|
|
2237
2131
|
if (first.role === "system" && messages.length > 0) {
|
|
2238
2132
|
_outputObj.system = first.content;
|
|
2239
2133
|
return messages.map((m) => {
|
|
2240
2134
|
if (m.role === "system") {
|
|
2241
|
-
return {
|
|
2242
|
-
...m,
|
|
2243
|
-
role: "user"
|
|
2244
|
-
};
|
|
2135
|
+
return { ...m, role: "user" };
|
|
2245
2136
|
}
|
|
2246
2137
|
return m;
|
|
2247
2138
|
});
|
|
@@ -2250,16 +2141,12 @@ function anthropicPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
|
2250
2141
|
first,
|
|
2251
2142
|
...messages.map((m) => {
|
|
2252
2143
|
if (m.role === "system") {
|
|
2253
|
-
return {
|
|
2254
|
-
...m,
|
|
2255
|
-
role: "user"
|
|
2256
|
-
};
|
|
2144
|
+
return { ...m, role: "user" };
|
|
2257
2145
|
}
|
|
2258
2146
|
return m;
|
|
2259
2147
|
})
|
|
2260
2148
|
];
|
|
2261
2149
|
}
|
|
2262
|
-
__name(anthropicPromptSanitize, "anthropicPromptSanitize");
|
|
2263
2150
|
|
|
2264
2151
|
// src/llm/config/bedrock/index.ts
|
|
2265
2152
|
var ANTORPIC_BEDROCK_VERSION = "bedrock-2023-05-31";
|
|
@@ -2275,10 +2162,7 @@ var amazonAnthropicChatV1 = {
|
|
|
2275
2162
|
maxTokens: {},
|
|
2276
2163
|
awsRegion: {
|
|
2277
2164
|
default: getEnvironmentVariable("AWS_REGION"),
|
|
2278
|
-
required: [
|
|
2279
|
-
true,
|
|
2280
|
-
"aws region is required"
|
|
2281
|
-
]
|
|
2165
|
+
required: [true, "aws region is required"]
|
|
2282
2166
|
},
|
|
2283
2167
|
awsSecretKey: {},
|
|
2284
2168
|
awsAccessKey: {}
|
|
@@ -2321,7 +2205,7 @@ var amazonMetaChatV1 = {
|
|
|
2321
2205
|
mapBody: {
|
|
2322
2206
|
prompt: {
|
|
2323
2207
|
key: "prompt",
|
|
2324
|
-
sanitize:
|
|
2208
|
+
sanitize: (messages) => {
|
|
2325
2209
|
if (typeof messages === "string") {
|
|
2326
2210
|
return messages;
|
|
2327
2211
|
} else {
|
|
@@ -2329,7 +2213,7 @@ var amazonMetaChatV1 = {
|
|
|
2329
2213
|
messages
|
|
2330
2214
|
});
|
|
2331
2215
|
}
|
|
2332
|
-
}
|
|
2216
|
+
}
|
|
2333
2217
|
},
|
|
2334
2218
|
topP: {
|
|
2335
2219
|
key: "top_p"
|
|
@@ -2346,6 +2230,7 @@ var amazonMetaChatV1 = {
|
|
|
2346
2230
|
var bedrock = {
|
|
2347
2231
|
"amazon:anthropic.chat.v1": amazonAnthropicChatV1,
|
|
2348
2232
|
"amazon:meta.chat.v1": amazonMetaChatV1
|
|
2233
|
+
// "amazon:nova.chat.v1": amazonAmazonNovaChatV1,
|
|
2349
2234
|
};
|
|
2350
2235
|
|
|
2351
2236
|
// src/llm/config/anthropic/index.ts
|
|
@@ -2360,10 +2245,7 @@ var anthropicChatV1 = {
|
|
|
2360
2245
|
prompt: {},
|
|
2361
2246
|
system: {},
|
|
2362
2247
|
maxTokens: {
|
|
2363
|
-
required: [
|
|
2364
|
-
true,
|
|
2365
|
-
"maxTokens required"
|
|
2366
|
-
],
|
|
2248
|
+
required: [true, "maxTokens required"],
|
|
2367
2249
|
default: 4096
|
|
2368
2250
|
},
|
|
2369
2251
|
anthropicApiKey: {
|
|
@@ -2388,10 +2270,22 @@ var anthropicChatV1 = {
|
|
|
2388
2270
|
};
|
|
2389
2271
|
var anthropic = {
|
|
2390
2272
|
"anthropic.chat.v1": anthropicChatV1,
|
|
2391
|
-
"anthropic.claude-3-7-sonnet": withDefaultModel(
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2273
|
+
"anthropic.claude-3-7-sonnet": withDefaultModel(
|
|
2274
|
+
anthropicChatV1,
|
|
2275
|
+
"claude-3-7-sonnet-latest"
|
|
2276
|
+
),
|
|
2277
|
+
"anthropic.claude-3-5-sonnet": withDefaultModel(
|
|
2278
|
+
anthropicChatV1,
|
|
2279
|
+
"claude-3-5-sonnet-latest"
|
|
2280
|
+
),
|
|
2281
|
+
"anthropic.claude-3-5-haiku": withDefaultModel(
|
|
2282
|
+
anthropicChatV1,
|
|
2283
|
+
"claude-3-5-haiku-latest"
|
|
2284
|
+
),
|
|
2285
|
+
"anthropic.claude-3-opus": withDefaultModel(
|
|
2286
|
+
anthropicChatV1,
|
|
2287
|
+
"claude-3-opus-latest"
|
|
2288
|
+
)
|
|
2395
2289
|
};
|
|
2396
2290
|
|
|
2397
2291
|
// src/llm/config/x/index.ts
|
|
@@ -2412,17 +2306,12 @@ var xaiChatV1 = {
|
|
|
2412
2306
|
mapBody: {
|
|
2413
2307
|
prompt: {
|
|
2414
2308
|
key: "messages",
|
|
2415
|
-
sanitize:
|
|
2309
|
+
sanitize: (v) => {
|
|
2416
2310
|
if (typeof v === "string") {
|
|
2417
|
-
return [
|
|
2418
|
-
{
|
|
2419
|
-
role: "user",
|
|
2420
|
-
content: v
|
|
2421
|
-
}
|
|
2422
|
-
];
|
|
2311
|
+
return [{ role: "user", content: v }];
|
|
2423
2312
|
}
|
|
2424
2313
|
return v;
|
|
2425
|
-
}
|
|
2314
|
+
}
|
|
2426
2315
|
},
|
|
2427
2316
|
model: {
|
|
2428
2317
|
key: "model"
|
|
@@ -2432,7 +2321,7 @@ var xaiChatV1 = {
|
|
|
2432
2321
|
},
|
|
2433
2322
|
useJson: {
|
|
2434
2323
|
key: "response_format.type",
|
|
2435
|
-
sanitize:
|
|
2324
|
+
sanitize: (v) => v ? "json_object" : "text"
|
|
2436
2325
|
}
|
|
2437
2326
|
}
|
|
2438
2327
|
};
|
|
@@ -2454,17 +2343,12 @@ var ollamaChatV1 = {
|
|
|
2454
2343
|
mapBody: {
|
|
2455
2344
|
prompt: {
|
|
2456
2345
|
key: "messages",
|
|
2457
|
-
sanitize:
|
|
2346
|
+
sanitize: (v) => {
|
|
2458
2347
|
if (typeof v === "string") {
|
|
2459
|
-
return [
|
|
2460
|
-
{
|
|
2461
|
-
role: "user",
|
|
2462
|
-
content: v
|
|
2463
|
-
}
|
|
2464
|
-
];
|
|
2348
|
+
return [{ role: "user", content: v }];
|
|
2465
2349
|
}
|
|
2466
2350
|
return v;
|
|
2467
|
-
}
|
|
2351
|
+
}
|
|
2468
2352
|
},
|
|
2469
2353
|
model: {
|
|
2470
2354
|
key: "model"
|
|
@@ -2482,90 +2366,58 @@ var ollama = {
|
|
|
2482
2366
|
|
|
2483
2367
|
// src/utils/modules/modifyPromptRoleChange.ts
|
|
2484
2368
|
function modifyPromptRoleChange(messages, roleChanges) {
|
|
2485
|
-
const roleChangeMap = new Map(roleChanges.map(({ from, to }) => [
|
|
2486
|
-
from,
|
|
2487
|
-
to
|
|
2488
|
-
]));
|
|
2369
|
+
const roleChangeMap = new Map(roleChanges.map(({ from, to }) => [from, to]));
|
|
2489
2370
|
if (Array.isArray(messages)) {
|
|
2490
2371
|
return messages.map((message) => {
|
|
2491
2372
|
const newRole2 = roleChangeMap.get(message.role);
|
|
2492
|
-
return newRole2 ? {
|
|
2493
|
-
...message,
|
|
2494
|
-
role: newRole2
|
|
2495
|
-
} : message;
|
|
2373
|
+
return newRole2 ? { ...message, role: newRole2 } : message;
|
|
2496
2374
|
});
|
|
2497
2375
|
}
|
|
2498
2376
|
const newRole = roleChangeMap.get(messages.role);
|
|
2499
|
-
return newRole ? {
|
|
2500
|
-
...messages,
|
|
2501
|
-
role: newRole
|
|
2502
|
-
} : messages;
|
|
2377
|
+
return newRole ? { ...messages, role: newRole } : messages;
|
|
2503
2378
|
}
|
|
2504
|
-
__name(modifyPromptRoleChange, "modifyPromptRoleChange");
|
|
2505
2379
|
|
|
2506
2380
|
// src/llm/config/google/promptSanitizeMessageCallback.ts
|
|
2507
2381
|
function googleGeminiPromptMessageCallback(_message) {
|
|
2508
|
-
let message = {
|
|
2509
|
-
..._message
|
|
2510
|
-
};
|
|
2382
|
+
let message = { ..._message };
|
|
2511
2383
|
message = modifyPromptRoleChange(_message, [
|
|
2512
|
-
{
|
|
2513
|
-
from: "assistant",
|
|
2514
|
-
to: "model"
|
|
2515
|
-
}
|
|
2384
|
+
{ from: "assistant", to: "model" }
|
|
2516
2385
|
]);
|
|
2517
2386
|
const { role, ...payload } = message;
|
|
2518
2387
|
const parts = [];
|
|
2519
2388
|
if (typeof payload.content === "string") {
|
|
2520
|
-
parts.push({
|
|
2521
|
-
text: message.content
|
|
2522
|
-
});
|
|
2389
|
+
parts.push({ text: message.content });
|
|
2523
2390
|
}
|
|
2524
2391
|
return {
|
|
2525
2392
|
role,
|
|
2526
2393
|
parts
|
|
2527
2394
|
};
|
|
2528
2395
|
}
|
|
2529
|
-
__name(googleGeminiPromptMessageCallback, "googleGeminiPromptMessageCallback");
|
|
2530
2396
|
|
|
2531
2397
|
// src/llm/config/google/promptSanitize.ts
|
|
2532
2398
|
function googleGeminiPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
2533
2399
|
if (typeof _messages === "string") {
|
|
2534
|
-
return [
|
|
2535
|
-
{
|
|
2536
|
-
role: "user",
|
|
2537
|
-
parts: [
|
|
2538
|
-
{
|
|
2539
|
-
text: _messages
|
|
2540
|
-
}
|
|
2541
|
-
]
|
|
2542
|
-
}
|
|
2543
|
-
];
|
|
2400
|
+
return [{ role: "user", parts: [{ text: _messages }] }];
|
|
2544
2401
|
}
|
|
2545
2402
|
if (Array.isArray(_messages)) {
|
|
2546
2403
|
if (_messages.length === 0) {
|
|
2547
2404
|
throw new Error("Empty messages array");
|
|
2548
2405
|
}
|
|
2549
2406
|
if (_messages.length === 1 && _messages[0].role === "system") {
|
|
2550
|
-
return [
|
|
2551
|
-
{
|
|
2552
|
-
role: "user",
|
|
2553
|
-
parts: [
|
|
2554
|
-
{
|
|
2555
|
-
text: _messages[0].content
|
|
2556
|
-
}
|
|
2557
|
-
]
|
|
2558
|
-
}
|
|
2559
|
-
];
|
|
2407
|
+
return [{ role: "user", parts: [{ text: _messages[0].content }] }];
|
|
2560
2408
|
}
|
|
2561
|
-
const hasSystemInstruction = _messages.some(
|
|
2409
|
+
const hasSystemInstruction = _messages.some(
|
|
2410
|
+
(message) => message.role === "system"
|
|
2411
|
+
);
|
|
2562
2412
|
if (hasSystemInstruction) {
|
|
2563
|
-
const theSystemInstructions = _messages.filter(
|
|
2564
|
-
|
|
2413
|
+
const theSystemInstructions = _messages.filter(
|
|
2414
|
+
(message) => message.role === "system"
|
|
2415
|
+
);
|
|
2416
|
+
const withoutSystemInstructions = _messages.filter(
|
|
2417
|
+
(message) => message.role !== "system"
|
|
2418
|
+
);
|
|
2565
2419
|
_outputObj.system_instruction = {
|
|
2566
|
-
parts: theSystemInstructions.map((message) => ({
|
|
2567
|
-
text: message.content
|
|
2568
|
-
}))
|
|
2420
|
+
parts: theSystemInstructions.map((message) => ({ text: message.content }))
|
|
2569
2421
|
};
|
|
2570
2422
|
return withoutSystemInstructions.map(googleGeminiPromptMessageCallback);
|
|
2571
2423
|
}
|
|
@@ -2573,7 +2425,6 @@ function googleGeminiPromptSanitize(_messages, _inputBodyObj, _outputObj) {
|
|
|
2573
2425
|
}
|
|
2574
2426
|
throw new Error("Invalid messages format");
|
|
2575
2427
|
}
|
|
2576
|
-
__name(googleGeminiPromptSanitize, "googleGeminiPromptSanitize");
|
|
2577
2428
|
|
|
2578
2429
|
// src/llm/config/google/index.ts
|
|
2579
2430
|
var googleGeminiChatV1 = {
|
|
@@ -2594,13 +2445,25 @@ var googleGeminiChatV1 = {
|
|
|
2594
2445
|
key: "contents",
|
|
2595
2446
|
sanitize: googleGeminiPromptSanitize
|
|
2596
2447
|
}
|
|
2448
|
+
// topP: {
|
|
2449
|
+
// key: "top_p",
|
|
2450
|
+
// }
|
|
2597
2451
|
}
|
|
2598
2452
|
};
|
|
2599
2453
|
var google = {
|
|
2600
2454
|
"google.chat.v1": googleGeminiChatV1,
|
|
2601
|
-
"google.gemini-2.0-flash": withDefaultModel(
|
|
2602
|
-
|
|
2603
|
-
|
|
2455
|
+
"google.gemini-2.0-flash": withDefaultModel(
|
|
2456
|
+
googleGeminiChatV1,
|
|
2457
|
+
"gemini-2.0-flash"
|
|
2458
|
+
),
|
|
2459
|
+
"google.gemini-2.0-flash-lite": withDefaultModel(
|
|
2460
|
+
googleGeminiChatV1,
|
|
2461
|
+
"gemini-2.0-flash-lite"
|
|
2462
|
+
),
|
|
2463
|
+
"google.gemini-1.5-pro": withDefaultModel(
|
|
2464
|
+
googleGeminiChatV1,
|
|
2465
|
+
"gemini-1.5-pro"
|
|
2466
|
+
)
|
|
2604
2467
|
};
|
|
2605
2468
|
|
|
2606
2469
|
// src/llm/config/deepseek/index.ts
|
|
@@ -2621,17 +2484,12 @@ var deepseekChatV1 = {
|
|
|
2621
2484
|
mapBody: {
|
|
2622
2485
|
prompt: {
|
|
2623
2486
|
key: "messages",
|
|
2624
|
-
sanitize:
|
|
2487
|
+
sanitize: (v) => {
|
|
2625
2488
|
if (typeof v === "string") {
|
|
2626
|
-
return [
|
|
2627
|
-
{
|
|
2628
|
-
role: "user",
|
|
2629
|
-
content: v
|
|
2630
|
-
}
|
|
2631
|
-
];
|
|
2489
|
+
return [{ role: "user", content: v }];
|
|
2632
2490
|
}
|
|
2633
2491
|
return v;
|
|
2634
|
-
}
|
|
2492
|
+
}
|
|
2635
2493
|
},
|
|
2636
2494
|
model: {
|
|
2637
2495
|
key: "model"
|
|
@@ -2641,7 +2499,7 @@ var deepseekChatV1 = {
|
|
|
2641
2499
|
},
|
|
2642
2500
|
useJson: {
|
|
2643
2501
|
key: "response_format.type",
|
|
2644
|
-
sanitize:
|
|
2502
|
+
sanitize: (v) => v ? "json_object" : "text"
|
|
2645
2503
|
}
|
|
2646
2504
|
}
|
|
2647
2505
|
};
|
|
@@ -2677,7 +2535,6 @@ function getLlmConfig(provider) {
|
|
|
2677
2535
|
resolution: "Provide a valid provider"
|
|
2678
2536
|
});
|
|
2679
2537
|
}
|
|
2680
|
-
__name(getLlmConfig, "getLlmConfig");
|
|
2681
2538
|
|
|
2682
2539
|
// src/llm/output/_utils/getResultContent.ts
|
|
2683
2540
|
function getResultContent(result, index) {
|
|
@@ -2686,11 +2543,8 @@ function getResultContent(result, index) {
|
|
|
2686
2543
|
const val = arr[index];
|
|
2687
2544
|
return val ? val : [];
|
|
2688
2545
|
}
|
|
2689
|
-
return [
|
|
2690
|
-
...result.content
|
|
2691
|
-
];
|
|
2546
|
+
return [...result.content];
|
|
2692
2547
|
}
|
|
2693
|
-
__name(getResultContent, "getResultContent");
|
|
2694
2548
|
|
|
2695
2549
|
// src/llm/output/base.ts
|
|
2696
2550
|
function BaseLlmOutput2(result) {
|
|
@@ -2699,12 +2553,8 @@ function BaseLlmOutput2(result) {
|
|
|
2699
2553
|
name: result.name,
|
|
2700
2554
|
usage: result.usage,
|
|
2701
2555
|
stopReason: result.stopReason,
|
|
2702
|
-
options: [
|
|
2703
|
-
|
|
2704
|
-
],
|
|
2705
|
-
content: [
|
|
2706
|
-
...result.content
|
|
2707
|
-
],
|
|
2556
|
+
options: [...result?.options || []],
|
|
2557
|
+
content: [...result.content],
|
|
2708
2558
|
created: result?.created || (/* @__PURE__ */ new Date()).getTime()
|
|
2709
2559
|
});
|
|
2710
2560
|
function getResult() {
|
|
@@ -2718,14 +2568,12 @@ function BaseLlmOutput2(result) {
|
|
|
2718
2568
|
stopReason: __result.stopReason
|
|
2719
2569
|
};
|
|
2720
2570
|
}
|
|
2721
|
-
__name(getResult, "getResult");
|
|
2722
2571
|
return {
|
|
2723
|
-
getResultContent:
|
|
2724
|
-
getResultText:
|
|
2572
|
+
getResultContent: (index) => getResultContent(__result, index),
|
|
2573
|
+
getResultText: () => getResultText(__result.content),
|
|
2725
2574
|
getResult
|
|
2726
2575
|
};
|
|
2727
2576
|
}
|
|
2728
|
-
__name(BaseLlmOutput2, "BaseLlmOutput2");
|
|
2729
2577
|
|
|
2730
2578
|
// src/llm/output/_util.ts
|
|
2731
2579
|
function normalizeFunctionCall(input, provider) {
|
|
@@ -2736,20 +2584,16 @@ function normalizeFunctionCall(input, provider) {
|
|
|
2736
2584
|
}
|
|
2737
2585
|
return input;
|
|
2738
2586
|
}
|
|
2739
|
-
__name(normalizeFunctionCall, "normalizeFunctionCall");
|
|
2740
2587
|
function formatOptions(response, handler) {
|
|
2741
2588
|
const out = [];
|
|
2742
2589
|
for (const item of response) {
|
|
2743
2590
|
const result = handler(item);
|
|
2744
2591
|
if (result) {
|
|
2745
|
-
out.push([
|
|
2746
|
-
result
|
|
2747
|
-
]);
|
|
2592
|
+
out.push([result]);
|
|
2748
2593
|
}
|
|
2749
2594
|
}
|
|
2750
2595
|
return out;
|
|
2751
2596
|
}
|
|
2752
|
-
__name(formatOptions, "formatOptions");
|
|
2753
2597
|
function formatContent(response, handler) {
|
|
2754
2598
|
const out = [];
|
|
2755
2599
|
const result = handler(response);
|
|
@@ -2758,7 +2602,6 @@ function formatContent(response, handler) {
|
|
|
2758
2602
|
}
|
|
2759
2603
|
return out;
|
|
2760
2604
|
}
|
|
2761
|
-
__name(formatContent, "formatContent");
|
|
2762
2605
|
|
|
2763
2606
|
// src/llm/output/openai.ts
|
|
2764
2607
|
function formatResult(result) {
|
|
@@ -2782,7 +2625,6 @@ function formatResult(result) {
|
|
|
2782
2625
|
text: ""
|
|
2783
2626
|
};
|
|
2784
2627
|
}
|
|
2785
|
-
__name(formatResult, "formatResult");
|
|
2786
2628
|
function OutputOpenAIChat(result, _config) {
|
|
2787
2629
|
const id = result.id;
|
|
2788
2630
|
const name = result.model || _config?.model || "openai.unknown";
|
|
@@ -2806,7 +2648,6 @@ function OutputOpenAIChat(result, _config) {
|
|
|
2806
2648
|
options
|
|
2807
2649
|
});
|
|
2808
2650
|
}
|
|
2809
|
-
__name(OutputOpenAIChat, "OutputOpenAIChat");
|
|
2810
2651
|
|
|
2811
2652
|
// src/llm/output/claude.ts
|
|
2812
2653
|
function formatResult2(response) {
|
|
@@ -2829,7 +2670,6 @@ function formatResult2(response) {
|
|
|
2829
2670
|
}
|
|
2830
2671
|
return out;
|
|
2831
2672
|
}
|
|
2832
|
-
__name(formatResult2, "formatResult");
|
|
2833
2673
|
function OutputAnthropicClaude3Chat(result, _config) {
|
|
2834
2674
|
const id = result.id;
|
|
2835
2675
|
const name = result.model || _config?.model || "anthropic.unknown";
|
|
@@ -2848,17 +2688,13 @@ function OutputAnthropicClaude3Chat(result, _config) {
|
|
|
2848
2688
|
content
|
|
2849
2689
|
});
|
|
2850
2690
|
}
|
|
2851
|
-
__name(OutputAnthropicClaude3Chat, "OutputAnthropicClaude3Chat");
|
|
2852
2691
|
|
|
2853
2692
|
// src/llm/output/llama.ts
|
|
2854
2693
|
function OutputMetaLlama3Chat(result, _config) {
|
|
2855
2694
|
const name = _config?.model || "meta";
|
|
2856
2695
|
const stopReason = result.stop_reason;
|
|
2857
2696
|
const content = [
|
|
2858
|
-
{
|
|
2859
|
-
type: "text",
|
|
2860
|
-
text: result.generation
|
|
2861
|
-
}
|
|
2697
|
+
{ type: "text", text: result.generation }
|
|
2862
2698
|
];
|
|
2863
2699
|
const usage = {
|
|
2864
2700
|
output_tokens: result?.generation_token_count,
|
|
@@ -2872,7 +2708,6 @@ function OutputMetaLlama3Chat(result, _config) {
|
|
|
2872
2708
|
content
|
|
2873
2709
|
});
|
|
2874
2710
|
}
|
|
2875
|
-
__name(OutputMetaLlama3Chat, "OutputMetaLlama3Chat");
|
|
2876
2711
|
|
|
2877
2712
|
// src/llm/output/default.ts
|
|
2878
2713
|
function OutputDefault(result, _config) {
|
|
@@ -2880,10 +2715,7 @@ function OutputDefault(result, _config) {
|
|
|
2880
2715
|
const stopReason = result?.stopReason || "stop";
|
|
2881
2716
|
const content = [];
|
|
2882
2717
|
if (result?.text) {
|
|
2883
|
-
content.push({
|
|
2884
|
-
type: "text",
|
|
2885
|
-
text: result.text
|
|
2886
|
-
});
|
|
2718
|
+
content.push({ type: "text", text: result.text });
|
|
2887
2719
|
}
|
|
2888
2720
|
const usage = {
|
|
2889
2721
|
output_tokens: result?.output_tokens || 0,
|
|
@@ -2897,7 +2729,6 @@ function OutputDefault(result, _config) {
|
|
|
2897
2729
|
content
|
|
2898
2730
|
});
|
|
2899
2731
|
}
|
|
2900
|
-
__name(OutputDefault, "OutputDefault");
|
|
2901
2732
|
|
|
2902
2733
|
// src/llm/output/xai.ts
|
|
2903
2734
|
function formatResult3(result) {
|
|
@@ -2921,7 +2752,6 @@ function formatResult3(result) {
|
|
|
2921
2752
|
text: ""
|
|
2922
2753
|
};
|
|
2923
2754
|
}
|
|
2924
|
-
__name(formatResult3, "formatResult");
|
|
2925
2755
|
function OutputXAIChat(result, _config) {
|
|
2926
2756
|
const id = result.id;
|
|
2927
2757
|
const name = result?.model;
|
|
@@ -2945,7 +2775,6 @@ function OutputXAIChat(result, _config) {
|
|
|
2945
2775
|
options
|
|
2946
2776
|
});
|
|
2947
2777
|
}
|
|
2948
|
-
__name(OutputXAIChat, "OutputXAIChat");
|
|
2949
2778
|
|
|
2950
2779
|
// src/llm/output/_utils/combineJsonl.ts
|
|
2951
2780
|
function combineJsonl(jsonl) {
|
|
@@ -2959,7 +2788,9 @@ function combineJsonl(jsonl) {
|
|
|
2959
2788
|
if (lines.length === 0) {
|
|
2960
2789
|
throw new Error("No JSON lines provided.");
|
|
2961
2790
|
}
|
|
2962
|
-
lines.sort(
|
|
2791
|
+
lines.sort(
|
|
2792
|
+
(a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime()
|
|
2793
|
+
);
|
|
2963
2794
|
let combinedContent = lines.map((line) => line?.message?.content ?? "").join("");
|
|
2964
2795
|
combinedContent = combinedContent.replace(/\\u003c/g, "<").replace(/\\u003e/g, ">");
|
|
2965
2796
|
const finalLine = lines.find((line) => line.done === true);
|
|
@@ -2992,7 +2823,6 @@ function combineJsonl(jsonl) {
|
|
|
2992
2823
|
content
|
|
2993
2824
|
};
|
|
2994
2825
|
}
|
|
2995
|
-
__name(combineJsonl, "combineJsonl");
|
|
2996
2826
|
|
|
2997
2827
|
// src/llm/output/ollama.ts
|
|
2998
2828
|
function OutputOllamaChat(result, _config) {
|
|
@@ -3001,9 +2831,7 @@ function OutputOllamaChat(result, _config) {
|
|
|
3001
2831
|
const name = combined.result.model || _config?.model || "ollama.unknown";
|
|
3002
2832
|
const created = (/* @__PURE__ */ new Date(`${combined.result.created_at}`)).getTime();
|
|
3003
2833
|
const stopReason = `${combined?.result?.done_reason || "stop"}`;
|
|
3004
|
-
const content = [
|
|
3005
|
-
combined.content
|
|
3006
|
-
];
|
|
2834
|
+
const content = [combined.content];
|
|
3007
2835
|
const usage = {
|
|
3008
2836
|
output_tokens: 0,
|
|
3009
2837
|
input_tokens: 0,
|
|
@@ -3019,7 +2847,6 @@ function OutputOllamaChat(result, _config) {
|
|
|
3019
2847
|
options: []
|
|
3020
2848
|
});
|
|
3021
2849
|
}
|
|
3022
|
-
__name(OutputOllamaChat, "OutputOllamaChat");
|
|
3023
2850
|
|
|
3024
2851
|
// src/llm/output/google.gemini/formatResult.ts
|
|
3025
2852
|
function formatResult4(result) {
|
|
@@ -3044,7 +2871,6 @@ function formatResult4(result) {
|
|
|
3044
2871
|
text: ""
|
|
3045
2872
|
};
|
|
3046
2873
|
}
|
|
3047
|
-
__name(formatResult4, "formatResult");
|
|
3048
2874
|
|
|
3049
2875
|
// src/llm/output/google.gemini/index.ts
|
|
3050
2876
|
function OutputGoogleGeminiChat(result, _config) {
|
|
@@ -3070,7 +2896,6 @@ function OutputGoogleGeminiChat(result, _config) {
|
|
|
3070
2896
|
options
|
|
3071
2897
|
});
|
|
3072
2898
|
}
|
|
3073
|
-
__name(OutputGoogleGeminiChat, "OutputGoogleGeminiChat");
|
|
3074
2899
|
|
|
3075
2900
|
// src/llm/output/index.ts
|
|
3076
2901
|
function getOutputParser(config, response) {
|
|
@@ -3102,7 +2927,6 @@ function getOutputParser(config, response) {
|
|
|
3102
2927
|
}
|
|
3103
2928
|
}
|
|
3104
2929
|
}
|
|
3105
|
-
__name(getOutputParser, "getOutputParser");
|
|
3106
2930
|
|
|
3107
2931
|
// src/utils/modules/debug.ts
|
|
3108
2932
|
function debug(...args) {
|
|
@@ -3114,7 +2938,11 @@ function debug(...args) {
|
|
|
3114
2938
|
} else if (arg instanceof Array) {
|
|
3115
2939
|
logs.push(arg.map((item) => JSON.stringify(item, null, 2)));
|
|
3116
2940
|
} else if (arg instanceof Map) {
|
|
3117
|
-
logs.push(
|
|
2941
|
+
logs.push(
|
|
2942
|
+
Array.from(arg.entries()).map(
|
|
2943
|
+
([key, value]) => `${key}: ${JSON.stringify(value, null, 2)}`
|
|
2944
|
+
)
|
|
2945
|
+
);
|
|
3118
2946
|
} else if (arg instanceof Set) {
|
|
3119
2947
|
logs.push(Array.from(arg).map((item) => JSON.stringify(item, null, 2)));
|
|
3120
2948
|
} else if (arg instanceof Date) {
|
|
@@ -3138,7 +2966,6 @@ function debug(...args) {
|
|
|
3138
2966
|
console.debug(...logs);
|
|
3139
2967
|
}
|
|
3140
2968
|
}
|
|
3141
|
-
__name(debug, "debug");
|
|
3142
2969
|
|
|
3143
2970
|
// src/utils/modules/isValidUrl.ts
|
|
3144
2971
|
function isValidUrl(input) {
|
|
@@ -3149,7 +2976,6 @@ function isValidUrl(input) {
|
|
|
3149
2976
|
return false;
|
|
3150
2977
|
}
|
|
3151
2978
|
}
|
|
3152
|
-
__name(isValidUrl, "isValidUrl");
|
|
3153
2979
|
|
|
3154
2980
|
// src/utils/modules/request.ts
|
|
3155
2981
|
async function apiRequest(url, options) {
|
|
@@ -3185,7 +3011,6 @@ async function apiRequest(url, options) {
|
|
|
3185
3011
|
throw new Error(`Request to ${url} failed: ${message}`);
|
|
3186
3012
|
}
|
|
3187
3013
|
}
|
|
3188
|
-
__name(apiRequest, "apiRequest");
|
|
3189
3014
|
|
|
3190
3015
|
// src/utils/modules/convertDotNotation.ts
|
|
3191
3016
|
function convertDotNotation(obj) {
|
|
@@ -3210,7 +3035,6 @@ function convertDotNotation(obj) {
|
|
|
3210
3035
|
}
|
|
3211
3036
|
return result;
|
|
3212
3037
|
}
|
|
3213
|
-
__name(convertDotNotation, "convertDotNotation");
|
|
3214
3038
|
|
|
3215
3039
|
// src/llm/_utils.mapBody.ts
|
|
3216
3040
|
function mapBody(template, body) {
|
|
@@ -3223,9 +3047,11 @@ function mapBody(template, body) {
|
|
|
3223
3047
|
if (providerSpecificKey) {
|
|
3224
3048
|
let valueForThisKey = body[genericInputKey];
|
|
3225
3049
|
if (providerSpecificSettings.sanitize && typeof providerSpecificSettings.sanitize === "function") {
|
|
3226
|
-
valueForThisKey = providerSpecificSettings.sanitize(
|
|
3227
|
-
|
|
3228
|
-
|
|
3050
|
+
valueForThisKey = providerSpecificSettings.sanitize(
|
|
3051
|
+
valueForThisKey,
|
|
3052
|
+
Object.freeze({ ...body }),
|
|
3053
|
+
output
|
|
3054
|
+
);
|
|
3229
3055
|
}
|
|
3230
3056
|
if (typeof valueForThisKey !== "undefined") {
|
|
3231
3057
|
output[providerSpecificKey] = valueForThisKey;
|
|
@@ -3236,127 +3062,16 @@ function mapBody(template, body) {
|
|
|
3236
3062
|
}
|
|
3237
3063
|
return convertDotNotation(output);
|
|
3238
3064
|
}
|
|
3239
|
-
__name(mapBody, "mapBody");
|
|
3240
3065
|
|
|
3241
3066
|
// src/utils/modules/getAwsAuthorizationHeaders.ts
|
|
3242
3067
|
var import_credential_providers = require("@aws-sdk/credential-providers");
|
|
3243
3068
|
var import_signature_v4 = require("@smithy/signature-v4");
|
|
3244
|
-
|
|
3245
|
-
// node_modules/@smithy/types/dist-es/auth/auth.js
|
|
3246
|
-
var HttpAuthLocation;
|
|
3247
|
-
(function(HttpAuthLocation2) {
|
|
3248
|
-
HttpAuthLocation2["HEADER"] = "header";
|
|
3249
|
-
HttpAuthLocation2["QUERY"] = "query";
|
|
3250
|
-
})(HttpAuthLocation || (HttpAuthLocation = {}));
|
|
3251
|
-
|
|
3252
|
-
// node_modules/@smithy/types/dist-es/auth/HttpApiKeyAuth.js
|
|
3253
|
-
var HttpApiKeyAuthLocation;
|
|
3254
|
-
(function(HttpApiKeyAuthLocation2) {
|
|
3255
|
-
HttpApiKeyAuthLocation2["HEADER"] = "header";
|
|
3256
|
-
HttpApiKeyAuthLocation2["QUERY"] = "query";
|
|
3257
|
-
})(HttpApiKeyAuthLocation || (HttpApiKeyAuthLocation = {}));
|
|
3258
|
-
|
|
3259
|
-
// node_modules/@smithy/types/dist-es/endpoint.js
|
|
3260
|
-
var EndpointURLScheme;
|
|
3261
|
-
(function(EndpointURLScheme2) {
|
|
3262
|
-
EndpointURLScheme2["HTTP"] = "http";
|
|
3263
|
-
EndpointURLScheme2["HTTPS"] = "https";
|
|
3264
|
-
})(EndpointURLScheme || (EndpointURLScheme = {}));
|
|
3265
|
-
|
|
3266
|
-
// node_modules/@smithy/types/dist-es/extensions/checksum.js
|
|
3267
|
-
var AlgorithmId;
|
|
3268
|
-
(function(AlgorithmId2) {
|
|
3269
|
-
AlgorithmId2["MD5"] = "md5";
|
|
3270
|
-
AlgorithmId2["CRC32"] = "crc32";
|
|
3271
|
-
AlgorithmId2["CRC32C"] = "crc32c";
|
|
3272
|
-
AlgorithmId2["SHA1"] = "sha1";
|
|
3273
|
-
AlgorithmId2["SHA256"] = "sha256";
|
|
3274
|
-
})(AlgorithmId || (AlgorithmId = {}));
|
|
3275
|
-
|
|
3276
|
-
// node_modules/@smithy/types/dist-es/http.js
|
|
3277
|
-
var FieldPosition;
|
|
3278
|
-
(function(FieldPosition2) {
|
|
3279
|
-
FieldPosition2[FieldPosition2["HEADER"] = 0] = "HEADER";
|
|
3280
|
-
FieldPosition2[FieldPosition2["TRAILER"] = 1] = "TRAILER";
|
|
3281
|
-
})(FieldPosition || (FieldPosition = {}));
|
|
3282
|
-
|
|
3283
|
-
// node_modules/@smithy/types/dist-es/profile.js
|
|
3284
|
-
var IniSectionType;
|
|
3285
|
-
(function(IniSectionType2) {
|
|
3286
|
-
IniSectionType2["PROFILE"] = "profile";
|
|
3287
|
-
IniSectionType2["SSO_SESSION"] = "sso-session";
|
|
3288
|
-
IniSectionType2["SERVICES"] = "services";
|
|
3289
|
-
})(IniSectionType || (IniSectionType = {}));
|
|
3290
|
-
|
|
3291
|
-
// node_modules/@smithy/types/dist-es/transfer.js
|
|
3292
|
-
var RequestHandlerProtocol;
|
|
3293
|
-
(function(RequestHandlerProtocol2) {
|
|
3294
|
-
RequestHandlerProtocol2["HTTP_0_9"] = "http/0.9";
|
|
3295
|
-
RequestHandlerProtocol2["HTTP_1_0"] = "http/1.0";
|
|
3296
|
-
RequestHandlerProtocol2["TDS_8_0"] = "tds/8.0";
|
|
3297
|
-
})(RequestHandlerProtocol || (RequestHandlerProtocol = {}));
|
|
3298
|
-
|
|
3299
|
-
// node_modules/@smithy/protocol-http/dist-es/httpRequest.js
|
|
3300
|
-
var _HttpRequest = class _HttpRequest {
|
|
3301
|
-
constructor(options) {
|
|
3302
|
-
this.method = options.method || "GET";
|
|
3303
|
-
this.hostname = options.hostname || "localhost";
|
|
3304
|
-
this.port = options.port;
|
|
3305
|
-
this.query = options.query || {};
|
|
3306
|
-
this.headers = options.headers || {};
|
|
3307
|
-
this.body = options.body;
|
|
3308
|
-
this.protocol = options.protocol ? options.protocol.slice(-1) !== ":" ? `${options.protocol}:` : options.protocol : "https:";
|
|
3309
|
-
this.path = options.path ? options.path.charAt(0) !== "/" ? `/${options.path}` : options.path : "/";
|
|
3310
|
-
this.username = options.username;
|
|
3311
|
-
this.password = options.password;
|
|
3312
|
-
this.fragment = options.fragment;
|
|
3313
|
-
}
|
|
3314
|
-
static clone(request) {
|
|
3315
|
-
const cloned = new _HttpRequest({
|
|
3316
|
-
...request,
|
|
3317
|
-
headers: {
|
|
3318
|
-
...request.headers
|
|
3319
|
-
}
|
|
3320
|
-
});
|
|
3321
|
-
if (cloned.query) {
|
|
3322
|
-
cloned.query = cloneQuery(cloned.query);
|
|
3323
|
-
}
|
|
3324
|
-
return cloned;
|
|
3325
|
-
}
|
|
3326
|
-
static isInstance(request) {
|
|
3327
|
-
if (!request) {
|
|
3328
|
-
return false;
|
|
3329
|
-
}
|
|
3330
|
-
const req = request;
|
|
3331
|
-
return "method" in req && "protocol" in req && "hostname" in req && "path" in req && typeof req["query"] === "object" && typeof req["headers"] === "object";
|
|
3332
|
-
}
|
|
3333
|
-
clone() {
|
|
3334
|
-
return _HttpRequest.clone(this);
|
|
3335
|
-
}
|
|
3336
|
-
};
|
|
3337
|
-
__name(_HttpRequest, "HttpRequest");
|
|
3338
|
-
var HttpRequest = _HttpRequest;
|
|
3339
|
-
function cloneQuery(query) {
|
|
3340
|
-
return Object.keys(query).reduce((carry, paramName) => {
|
|
3341
|
-
const param = query[paramName];
|
|
3342
|
-
return {
|
|
3343
|
-
...carry,
|
|
3344
|
-
[paramName]: Array.isArray(param) ? [
|
|
3345
|
-
...param
|
|
3346
|
-
] : param
|
|
3347
|
-
};
|
|
3348
|
-
}, {});
|
|
3349
|
-
}
|
|
3350
|
-
__name(cloneQuery, "cloneQuery");
|
|
3351
|
-
|
|
3352
|
-
// src/utils/modules/getAwsAuthorizationHeaders.ts
|
|
3069
|
+
var import_protocol_http = require("@smithy/protocol-http");
|
|
3353
3070
|
var import_sha256_js = require("@aws-crypto/sha256-js");
|
|
3354
3071
|
|
|
3355
3072
|
// src/utils/modules/runWithTemporaryEnv.ts
|
|
3356
3073
|
async function runWithTemporaryEnv(env, handler) {
|
|
3357
|
-
const previousEnv = {
|
|
3358
|
-
...process.env
|
|
3359
|
-
};
|
|
3074
|
+
const previousEnv = { ...process.env };
|
|
3360
3075
|
try {
|
|
3361
3076
|
env();
|
|
3362
3077
|
const value = await handler();
|
|
@@ -3365,22 +3080,24 @@ async function runWithTemporaryEnv(env, handler) {
|
|
|
3365
3080
|
process.env = previousEnv;
|
|
3366
3081
|
}
|
|
3367
3082
|
}
|
|
3368
|
-
__name(runWithTemporaryEnv, "runWithTemporaryEnv");
|
|
3369
3083
|
|
|
3370
3084
|
// src/utils/modules/getAwsAuthorizationHeaders.ts
|
|
3371
3085
|
async function getAwsAuthorizationHeaders(req, props) {
|
|
3372
3086
|
const providerChain = (0, import_credential_providers.fromNodeProviderChain)();
|
|
3373
|
-
const credentials = await runWithTemporaryEnv(
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3087
|
+
const credentials = await runWithTemporaryEnv(
|
|
3088
|
+
() => {
|
|
3089
|
+
if (props.awsAccessKey) {
|
|
3090
|
+
process.env["AWS_ACCESS_KEY_ID"] = props.awsAccessKey;
|
|
3091
|
+
}
|
|
3092
|
+
if (props.awsSecretKey) {
|
|
3093
|
+
process.env["AWS_SECRET_ACCESS_KEY"] = props.awsSecretKey;
|
|
3094
|
+
}
|
|
3095
|
+
if (props.awsSessionToken) {
|
|
3096
|
+
process.env["AWS_SESSION_TOKEN"] = props.awsSessionToken;
|
|
3097
|
+
}
|
|
3098
|
+
},
|
|
3099
|
+
() => providerChain()
|
|
3100
|
+
);
|
|
3384
3101
|
const signer = new import_signature_v4.SignatureV4({
|
|
3385
3102
|
service: "bedrock",
|
|
3386
3103
|
region: props.regionName,
|
|
@@ -3388,14 +3105,10 @@ async function getAwsAuthorizationHeaders(req, props) {
|
|
|
3388
3105
|
sha256: import_sha256_js.Sha256
|
|
3389
3106
|
});
|
|
3390
3107
|
const url = new URL(props.url);
|
|
3391
|
-
const headers = !req.headers ? {} : Symbol.iterator in req.headers ? Object.fromEntries(Array.from(req.headers).map((header) => [
|
|
3392
|
-
...header
|
|
3393
|
-
])) : {
|
|
3394
|
-
...req.headers
|
|
3395
|
-
};
|
|
3108
|
+
const headers = !req.headers ? {} : Symbol.iterator in req.headers ? Object.fromEntries(Array.from(req.headers).map((header) => [...header])) : { ...req.headers };
|
|
3396
3109
|
delete headers["connection"];
|
|
3397
3110
|
headers["host"] = url.hostname;
|
|
3398
|
-
const request = new HttpRequest({
|
|
3111
|
+
const request = new import_protocol_http.HttpRequest({
|
|
3399
3112
|
method: req?.method?.toUpperCase(),
|
|
3400
3113
|
protocol: url.protocol,
|
|
3401
3114
|
path: url.pathname,
|
|
@@ -3405,7 +3118,6 @@ async function getAwsAuthorizationHeaders(req, props) {
|
|
|
3405
3118
|
const signed = await signer.sign(request);
|
|
3406
3119
|
return signed.headers;
|
|
3407
3120
|
}
|
|
3408
|
-
__name(getAwsAuthorizationHeaders, "getAwsAuthorizationHeaders");
|
|
3409
3121
|
|
|
3410
3122
|
// src/llm/_utils.parseHeaders.ts
|
|
3411
3123
|
async function parseHeaders(config, replacements, payload) {
|
|
@@ -3414,30 +3126,40 @@ async function parseHeaders(config, replacements, payload) {
|
|
|
3414
3126
|
const headers = Object.assign({}, payload.headers, parse);
|
|
3415
3127
|
if (config.provider.startsWith("amazon:") || config.provider.startsWith("amazon.")) {
|
|
3416
3128
|
const url = payload.url;
|
|
3417
|
-
return getAwsAuthorizationHeaders(
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3129
|
+
return getAwsAuthorizationHeaders(
|
|
3130
|
+
{
|
|
3131
|
+
method: config.method,
|
|
3132
|
+
headers,
|
|
3133
|
+
body: payload.body
|
|
3134
|
+
},
|
|
3135
|
+
{
|
|
3136
|
+
url,
|
|
3137
|
+
regionName: replacements?.awsRegion || getEnvironmentVariable("AWS_REGION"),
|
|
3138
|
+
awsSecretKey: replacements.awsSecretKey,
|
|
3139
|
+
awsAccessKey: replacements.awsAccessKey
|
|
3140
|
+
}
|
|
3141
|
+
);
|
|
3427
3142
|
} else {
|
|
3428
3143
|
return headers;
|
|
3429
3144
|
}
|
|
3430
3145
|
}
|
|
3431
|
-
__name(parseHeaders, "parseHeaders");
|
|
3432
3146
|
|
|
3433
3147
|
// src/llm/output/_utils/cleanJsonSchemaFor.ts
|
|
3434
3148
|
var providerFieldExclusions = {
|
|
3435
|
-
"openai.chat": [
|
|
3436
|
-
|
|
3437
|
-
]
|
|
3149
|
+
"openai.chat": ["default"],
|
|
3150
|
+
// fields to exclude for openai.chat
|
|
3151
|
+
"anthropic.chat": []
|
|
3152
|
+
// fields to exclude for openai.chat
|
|
3438
3153
|
};
|
|
3439
3154
|
function cleanJsonSchemaFor(schema = {}, provider) {
|
|
3440
3155
|
const clone = deepClone(schema);
|
|
3156
|
+
if (Object.keys(clone).length === 0) {
|
|
3157
|
+
return {
|
|
3158
|
+
type: "object",
|
|
3159
|
+
properties: {},
|
|
3160
|
+
required: []
|
|
3161
|
+
};
|
|
3162
|
+
}
|
|
3441
3163
|
const exclusions = providerFieldExclusions[provider] || [];
|
|
3442
3164
|
function removeDisallowedFields(obj) {
|
|
3443
3165
|
if (Array.isArray(obj)) {
|
|
@@ -3452,20 +3174,21 @@ function cleanJsonSchemaFor(schema = {}, provider) {
|
|
|
3452
3174
|
}
|
|
3453
3175
|
return obj;
|
|
3454
3176
|
}
|
|
3455
|
-
__name(removeDisallowedFields, "removeDisallowedFields");
|
|
3456
3177
|
return removeDisallowedFields(clone);
|
|
3457
3178
|
}
|
|
3458
|
-
__name(cleanJsonSchemaFor, "cleanJsonSchemaFor");
|
|
3459
3179
|
|
|
3460
3180
|
// src/llm/llm.call.ts
|
|
3461
3181
|
async function useLlm_call(state, messages, _options) {
|
|
3462
3182
|
const config = getLlmConfig(state.key);
|
|
3463
3183
|
const { functionCallStrictInput = false } = _options || {};
|
|
3464
|
-
const input = mapBody(
|
|
3465
|
-
|
|
3466
|
-
|
|
3184
|
+
const input = mapBody(
|
|
3185
|
+
config.mapBody,
|
|
3186
|
+
Object.assign({}, state, {
|
|
3187
|
+
prompt: messages
|
|
3188
|
+
})
|
|
3189
|
+
);
|
|
3467
3190
|
if (_options && _options?.jsonSchema) {
|
|
3468
|
-
if (state.provider
|
|
3191
|
+
if (state.provider.startsWith("openai")) {
|
|
3469
3192
|
const curr = input["response_format"] || {};
|
|
3470
3193
|
input["response_format"] = Object.assign(curr, {
|
|
3471
3194
|
type: "json_schema",
|
|
@@ -3478,28 +3201,29 @@ async function useLlm_call(state, messages, _options) {
|
|
|
3478
3201
|
}
|
|
3479
3202
|
}
|
|
3480
3203
|
if (_options && _options?.functionCall) {
|
|
3481
|
-
if (state.provider
|
|
3204
|
+
if (state.provider.startsWith("anthropic")) {
|
|
3482
3205
|
if (_options?.functionCall === "none") {
|
|
3483
3206
|
_options.functions = [];
|
|
3484
3207
|
} else if (_options?.functionCall === "auto" || _options?.functionCall === "any") {
|
|
3485
|
-
input["tool_choice"] = {
|
|
3486
|
-
type: _options?.functionCall
|
|
3487
|
-
};
|
|
3208
|
+
input["tool_choice"] = { type: _options?.functionCall };
|
|
3488
3209
|
} else {
|
|
3489
3210
|
input["tool_choice"] = _options?.functionCall;
|
|
3490
3211
|
}
|
|
3491
|
-
} else if (state.provider
|
|
3492
|
-
input["tool_choice"] = normalizeFunctionCall(
|
|
3212
|
+
} else if (state.provider.startsWith("openai")) {
|
|
3213
|
+
input["tool_choice"] = normalizeFunctionCall(
|
|
3214
|
+
_options?.functionCall,
|
|
3215
|
+
"openai"
|
|
3216
|
+
);
|
|
3493
3217
|
}
|
|
3494
3218
|
}
|
|
3495
3219
|
if (_options && _options?.functions?.length) {
|
|
3496
|
-
if (state.provider
|
|
3220
|
+
if (state.provider.startsWith("anthropic")) {
|
|
3497
3221
|
input["tools"] = _options.functions.map((f) => ({
|
|
3498
3222
|
name: f.name,
|
|
3499
3223
|
description: f.description,
|
|
3500
|
-
input_schema: f.parameters
|
|
3224
|
+
input_schema: cleanJsonSchemaFor(f.parameters, "anthropic.chat")
|
|
3501
3225
|
}));
|
|
3502
|
-
} else if (state.provider
|
|
3226
|
+
} else if (state.provider.startsWith("openai")) {
|
|
3503
3227
|
input["tools"] = _options.functions.map((f) => {
|
|
3504
3228
|
const props = {
|
|
3505
3229
|
name: f?.name,
|
|
@@ -3508,11 +3232,13 @@ async function useLlm_call(state, messages, _options) {
|
|
|
3508
3232
|
};
|
|
3509
3233
|
return {
|
|
3510
3234
|
type: "function",
|
|
3511
|
-
function: Object.assign(
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3235
|
+
function: Object.assign(
|
|
3236
|
+
props,
|
|
3237
|
+
{
|
|
3238
|
+
parameters: cleanJsonSchemaFor(props.parameters, "openai.chat")
|
|
3239
|
+
},
|
|
3240
|
+
{ strict: functionCallStrictInput }
|
|
3241
|
+
)
|
|
3516
3242
|
};
|
|
3517
3243
|
});
|
|
3518
3244
|
}
|
|
@@ -3528,16 +3254,14 @@ async function useLlm_call(state, messages, _options) {
|
|
|
3528
3254
|
id: "0123-45-6789",
|
|
3529
3255
|
model: "model",
|
|
3530
3256
|
created: (/* @__PURE__ */ new Date()).getTime(),
|
|
3531
|
-
usage: {
|
|
3532
|
-
completion_tokens: 0,
|
|
3533
|
-
prompt_tokens: 0,
|
|
3534
|
-
total_tokens: 0
|
|
3535
|
-
},
|
|
3257
|
+
usage: { completion_tokens: 0, prompt_tokens: 0, total_tokens: 0 },
|
|
3536
3258
|
choices: [
|
|
3537
3259
|
{
|
|
3538
3260
|
message: {
|
|
3539
3261
|
role: "assistant",
|
|
3540
|
-
content: `Hello world from LLM! The input was ${JSON.stringify(
|
|
3262
|
+
content: `Hello world from LLM! The input was ${JSON.stringify(
|
|
3263
|
+
messages
|
|
3264
|
+
)}`
|
|
3541
3265
|
}
|
|
3542
3266
|
}
|
|
3543
3267
|
]
|
|
@@ -3548,7 +3272,6 @@ async function useLlm_call(state, messages, _options) {
|
|
|
3548
3272
|
});
|
|
3549
3273
|
return getOutputParser(state, response);
|
|
3550
3274
|
}
|
|
3551
|
-
__name(useLlm_call, "useLlm_call");
|
|
3552
3275
|
|
|
3553
3276
|
// src/llm/_utils.stateFromOptions.ts
|
|
3554
3277
|
function stateFromOptions(options, config) {
|
|
@@ -3567,16 +3290,16 @@ function stateFromOptions(options, config) {
|
|
|
3567
3290
|
state[key] = thisConfig.default;
|
|
3568
3291
|
}
|
|
3569
3292
|
}
|
|
3570
|
-
|
|
3571
|
-
|
|
3572
|
-
|
|
3293
|
+
const value = get(state, key);
|
|
3294
|
+
if (Array.isArray(thisConfig?.required)) {
|
|
3295
|
+
const [required, message = `Error: [${key}] is required`] = thisConfig.required;
|
|
3296
|
+
if (required && typeof value === "undefined") {
|
|
3573
3297
|
throw new Error(message);
|
|
3574
3298
|
}
|
|
3575
3299
|
}
|
|
3576
3300
|
}
|
|
3577
3301
|
return state;
|
|
3578
3302
|
}
|
|
3579
|
-
__name(stateFromOptions, "stateFromOptions");
|
|
3580
3303
|
|
|
3581
3304
|
// src/utils/modules/deepFreeze.ts
|
|
3582
3305
|
function deepFreeze(obj) {
|
|
@@ -3593,13 +3316,14 @@ function deepFreeze(obj) {
|
|
|
3593
3316
|
}
|
|
3594
3317
|
if (typeof obj === "object" && obj !== null) {
|
|
3595
3318
|
for (const key of Object.keys(obj)) {
|
|
3596
|
-
obj[key] = deepFreeze(
|
|
3319
|
+
obj[key] = deepFreeze(
|
|
3320
|
+
obj[key]
|
|
3321
|
+
);
|
|
3597
3322
|
}
|
|
3598
3323
|
return Object.freeze(obj);
|
|
3599
3324
|
}
|
|
3600
3325
|
return obj;
|
|
3601
3326
|
}
|
|
3602
|
-
__name(deepFreeze, "deepFreeze");
|
|
3603
3327
|
|
|
3604
3328
|
// src/utils/modules/requestWrapper.ts
|
|
3605
3329
|
var import_exponential_backoff = require("exponential-backoff");
|
|
@@ -3620,19 +3344,29 @@ function apiRequestWrapper(config, options, handler, doNotRetryErrorMessages = [
|
|
|
3620
3344
|
async function call(messages, options2) {
|
|
3621
3345
|
try {
|
|
3622
3346
|
metrics.total_calls++;
|
|
3623
|
-
const result = await (0, import_exponential_backoff.backOff)(
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3347
|
+
const result = await (0, import_exponential_backoff.backOff)(
|
|
3348
|
+
() => asyncCallWithTimeout(
|
|
3349
|
+
handler(
|
|
3350
|
+
deepFreeze(state),
|
|
3351
|
+
deepFreeze(messages),
|
|
3352
|
+
deepFreeze(options2)
|
|
3353
|
+
),
|
|
3354
|
+
timeout
|
|
3355
|
+
),
|
|
3356
|
+
{
|
|
3357
|
+
startingDelay: 0,
|
|
3358
|
+
maxDelay,
|
|
3359
|
+
numOfAttempts,
|
|
3360
|
+
jitter,
|
|
3361
|
+
retry: (_error, _stepNumber) => {
|
|
3362
|
+
if (doNotRetryErrorMessages.includes(_error.message)) {
|
|
3363
|
+
return false;
|
|
3364
|
+
}
|
|
3365
|
+
metrics.total_call_retry++;
|
|
3366
|
+
return true;
|
|
3631
3367
|
}
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
}, "retry")
|
|
3635
|
-
});
|
|
3368
|
+
}
|
|
3369
|
+
);
|
|
3636
3370
|
metrics.total_call_success++;
|
|
3637
3371
|
return result;
|
|
3638
3372
|
} catch (error) {
|
|
@@ -3640,29 +3374,32 @@ function apiRequestWrapper(config, options, handler, doNotRetryErrorMessages = [
|
|
|
3640
3374
|
throw error;
|
|
3641
3375
|
}
|
|
3642
3376
|
}
|
|
3643
|
-
__name(call, "call");
|
|
3644
3377
|
function getMetadata() {
|
|
3645
|
-
const {
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3378
|
+
const {
|
|
3379
|
+
awsSecretKey,
|
|
3380
|
+
awsAccessKey,
|
|
3381
|
+
openAiApiKey,
|
|
3382
|
+
anthropicApiKey,
|
|
3383
|
+
...rest
|
|
3384
|
+
} = options;
|
|
3385
|
+
return Object.assign(
|
|
3386
|
+
{
|
|
3387
|
+
traceId: getTraceId(),
|
|
3388
|
+
timeout,
|
|
3389
|
+
jitter,
|
|
3390
|
+
maxDelay,
|
|
3391
|
+
numOfAttempts,
|
|
3392
|
+
metrics: { ...metrics }
|
|
3393
|
+
},
|
|
3394
|
+
rest
|
|
3395
|
+
);
|
|
3656
3396
|
}
|
|
3657
|
-
__name(getMetadata, "getMetadata");
|
|
3658
3397
|
function getTraceId() {
|
|
3659
3398
|
return traceId;
|
|
3660
3399
|
}
|
|
3661
|
-
__name(getTraceId, "getTraceId");
|
|
3662
3400
|
function withTraceId(id) {
|
|
3663
3401
|
traceId = id;
|
|
3664
3402
|
}
|
|
3665
|
-
__name(withTraceId, "withTraceId");
|
|
3666
3403
|
return {
|
|
3667
3404
|
call,
|
|
3668
3405
|
getTraceId,
|
|
@@ -3670,14 +3407,12 @@ function apiRequestWrapper(config, options, handler, doNotRetryErrorMessages = [
|
|
|
3670
3407
|
getMetadata
|
|
3671
3408
|
};
|
|
3672
3409
|
}
|
|
3673
|
-
__name(apiRequestWrapper, "apiRequestWrapper");
|
|
3674
3410
|
|
|
3675
3411
|
// src/llm/llm.ts
|
|
3676
3412
|
function useLlm(provider, options = {}) {
|
|
3677
3413
|
const config = getLlmConfig(provider);
|
|
3678
3414
|
return apiRequestWrapper(config, options, useLlm_call);
|
|
3679
3415
|
}
|
|
3680
|
-
__name(useLlm, "useLlm");
|
|
3681
3416
|
|
|
3682
3417
|
// src/embedding/config.ts
|
|
3683
3418
|
var embeddingConfigs = {
|
|
@@ -3725,10 +3460,7 @@ var embeddingConfigs = {
|
|
|
3725
3460
|
},
|
|
3726
3461
|
awsRegion: {
|
|
3727
3462
|
default: getEnvironmentVariable("AWS_REGION"),
|
|
3728
|
-
required: [
|
|
3729
|
-
true,
|
|
3730
|
-
"aws region is required"
|
|
3731
|
-
]
|
|
3463
|
+
required: [true, "aws region is required"]
|
|
3732
3464
|
},
|
|
3733
3465
|
awsSecretKey: {},
|
|
3734
3466
|
awsAccessKey: {}
|
|
@@ -3753,7 +3485,6 @@ function getEmbeddingConfig(provider) {
|
|
|
3753
3485
|
}
|
|
3754
3486
|
throw new Error(`Invalid provider: ${provider}`);
|
|
3755
3487
|
}
|
|
3756
|
-
__name(getEmbeddingConfig, "getEmbeddingConfig");
|
|
3757
3488
|
|
|
3758
3489
|
// src/embedding/output/BaseEmbeddingOutput.ts
|
|
3759
3490
|
function BaseEmbeddingOutput(result) {
|
|
@@ -3761,9 +3492,7 @@ function BaseEmbeddingOutput(result) {
|
|
|
3761
3492
|
id: result.id || (0, import_uuid.v4)(),
|
|
3762
3493
|
model: result.model,
|
|
3763
3494
|
usage: result.usage,
|
|
3764
|
-
embedding: [
|
|
3765
|
-
...result?.embedding || []
|
|
3766
|
-
],
|
|
3495
|
+
embedding: [...result?.embedding || []],
|
|
3767
3496
|
created: result?.created || (/* @__PURE__ */ new Date()).getTime()
|
|
3768
3497
|
});
|
|
3769
3498
|
function getResult() {
|
|
@@ -3775,7 +3504,6 @@ function BaseEmbeddingOutput(result) {
|
|
|
3775
3504
|
embedding: __result.embedding
|
|
3776
3505
|
};
|
|
3777
3506
|
}
|
|
3778
|
-
__name(getResult, "getResult");
|
|
3779
3507
|
function getEmbedding(index) {
|
|
3780
3508
|
if (index && index > 0) {
|
|
3781
3509
|
const arr = __result?.embedding;
|
|
@@ -3784,22 +3512,18 @@ function BaseEmbeddingOutput(result) {
|
|
|
3784
3512
|
}
|
|
3785
3513
|
return __result.embedding[0];
|
|
3786
3514
|
}
|
|
3787
|
-
__name(getEmbedding, "getEmbedding");
|
|
3788
3515
|
return {
|
|
3789
3516
|
getEmbedding,
|
|
3790
3517
|
getResult
|
|
3791
3518
|
};
|
|
3792
3519
|
}
|
|
3793
|
-
__name(BaseEmbeddingOutput, "BaseEmbeddingOutput");
|
|
3794
3520
|
|
|
3795
3521
|
// src/embedding/output/AmazonTitan.ts
|
|
3796
3522
|
function AmazonTitanEmbedding(result, config) {
|
|
3797
3523
|
const __result = deepClone(result);
|
|
3798
3524
|
const model = config.model || "amazon.unknown";
|
|
3799
3525
|
const created = (/* @__PURE__ */ new Date()).getTime();
|
|
3800
|
-
const embedding = [
|
|
3801
|
-
__result.embedding
|
|
3802
|
-
];
|
|
3526
|
+
const embedding = [__result.embedding];
|
|
3803
3527
|
const usage = {
|
|
3804
3528
|
output_tokens: 0,
|
|
3805
3529
|
input_tokens: __result.inputTextTokenCount,
|
|
@@ -3812,7 +3536,6 @@ function AmazonTitanEmbedding(result, config) {
|
|
|
3812
3536
|
embedding
|
|
3813
3537
|
});
|
|
3814
3538
|
}
|
|
3815
|
-
__name(AmazonTitanEmbedding, "AmazonTitanEmbedding");
|
|
3816
3539
|
|
|
3817
3540
|
// src/embedding/output/OpenAiEmbedding.ts
|
|
3818
3541
|
function OpenAiEmbedding(result, config) {
|
|
@@ -3833,7 +3556,6 @@ function OpenAiEmbedding(result, config) {
|
|
|
3833
3556
|
embedding
|
|
3834
3557
|
});
|
|
3835
3558
|
}
|
|
3836
|
-
__name(OpenAiEmbedding, "OpenAiEmbedding");
|
|
3837
3559
|
|
|
3838
3560
|
// src/embedding/output/getEmbeddingOutputParser.ts
|
|
3839
3561
|
function getEmbeddingOutputParser(config, response) {
|
|
@@ -3846,14 +3568,16 @@ function getEmbeddingOutputParser(config, response) {
|
|
|
3846
3568
|
throw new Error("Unsupported provider");
|
|
3847
3569
|
}
|
|
3848
3570
|
}
|
|
3849
|
-
__name(getEmbeddingOutputParser, "getEmbeddingOutputParser");
|
|
3850
3571
|
|
|
3851
3572
|
// src/embedding/embedding.call.ts
|
|
3852
3573
|
async function createEmbedding_call(state, _input, _options) {
|
|
3853
3574
|
const config = getEmbeddingConfig(state.key);
|
|
3854
|
-
const input = mapBody(
|
|
3855
|
-
|
|
3856
|
-
|
|
3575
|
+
const input = mapBody(
|
|
3576
|
+
config.mapBody,
|
|
3577
|
+
Object.assign({}, state, {
|
|
3578
|
+
input: _input
|
|
3579
|
+
})
|
|
3580
|
+
);
|
|
3857
3581
|
const body = JSON.stringify(input);
|
|
3858
3582
|
const url = replaceTemplateStringSimple(config.endpoint, state);
|
|
3859
3583
|
const headers = await parseHeaders(config, state, {
|
|
@@ -3868,21 +3592,19 @@ async function createEmbedding_call(state, _input, _options) {
|
|
|
3868
3592
|
});
|
|
3869
3593
|
return getEmbeddingOutputParser(state, request);
|
|
3870
3594
|
}
|
|
3871
|
-
__name(createEmbedding_call, "createEmbedding_call");
|
|
3872
3595
|
|
|
3873
3596
|
// src/embedding/embedding.ts
|
|
3874
3597
|
function createEmbedding(provider, options) {
|
|
3875
3598
|
const config = getEmbeddingConfig(provider);
|
|
3876
3599
|
return apiRequestWrapper(config, options, createEmbedding_call);
|
|
3877
3600
|
}
|
|
3878
|
-
__name(createEmbedding, "createEmbedding");
|
|
3879
3601
|
|
|
3880
3602
|
// src/prompt/_base.ts
|
|
3881
|
-
var
|
|
3603
|
+
var BasePrompt = class {
|
|
3882
3604
|
/**
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3605
|
+
* constructor description
|
|
3606
|
+
* @param initialPromptMessage An initial message to add to the prompt.
|
|
3607
|
+
*/
|
|
3886
3608
|
constructor(initialPromptMessage, options) {
|
|
3887
3609
|
__publicField(this, "type", "text");
|
|
3888
3610
|
__publicField(this, "messages", []);
|
|
@@ -3916,11 +3638,11 @@ var _BasePrompt = class _BasePrompt {
|
|
|
3916
3638
|
}
|
|
3917
3639
|
}
|
|
3918
3640
|
/**
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3641
|
+
* addToPrompt description
|
|
3642
|
+
* @param content The message content
|
|
3643
|
+
* @param role The role of the user. Defaults to system for base text prompt.
|
|
3644
|
+
* @return instance of BasePrompt.
|
|
3645
|
+
*/
|
|
3924
3646
|
addToPrompt(content, role = "system") {
|
|
3925
3647
|
if (content) {
|
|
3926
3648
|
switch (role) {
|
|
@@ -3933,10 +3655,10 @@ var _BasePrompt = class _BasePrompt {
|
|
|
3933
3655
|
return this;
|
|
3934
3656
|
}
|
|
3935
3657
|
/**
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3658
|
+
* addSystemMessage description
|
|
3659
|
+
* @param content The message content
|
|
3660
|
+
* @return returns BasePrompt so it can be chained.
|
|
3661
|
+
*/
|
|
3940
3662
|
addSystemMessage(content) {
|
|
3941
3663
|
this.messages.push({
|
|
3942
3664
|
role: "system",
|
|
@@ -3945,58 +3667,62 @@ var _BasePrompt = class _BasePrompt {
|
|
|
3945
3667
|
return this;
|
|
3946
3668
|
}
|
|
3947
3669
|
/**
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3670
|
+
* registerPartial description
|
|
3671
|
+
* @param partialOrPartials Additional partials that can be made available to the template parser.
|
|
3672
|
+
* @return BasePrompt so it can be chained.
|
|
3673
|
+
*/
|
|
3952
3674
|
registerPartial(partialOrPartials) {
|
|
3953
|
-
const partials2 = Array.isArray(partialOrPartials) ? partialOrPartials : [
|
|
3954
|
-
partialOrPartials
|
|
3955
|
-
];
|
|
3675
|
+
const partials2 = Array.isArray(partialOrPartials) ? partialOrPartials : [partialOrPartials];
|
|
3956
3676
|
this.partials.push(...partials2);
|
|
3957
3677
|
return this;
|
|
3958
3678
|
}
|
|
3959
3679
|
/**
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3680
|
+
* registerHelpers description
|
|
3681
|
+
* @param helperOrHelpers Additional helper functions that can be made available to the template parser.
|
|
3682
|
+
* @return BasePrompt so it can be chained.
|
|
3683
|
+
*/
|
|
3964
3684
|
registerHelpers(helperOrHelpers) {
|
|
3965
|
-
const helpers = Array.isArray(helperOrHelpers) ? helperOrHelpers : [
|
|
3966
|
-
helperOrHelpers
|
|
3967
|
-
];
|
|
3685
|
+
const helpers = Array.isArray(helperOrHelpers) ? helperOrHelpers : [helperOrHelpers];
|
|
3968
3686
|
this.helpers.push(...helpers);
|
|
3969
3687
|
return this;
|
|
3970
3688
|
}
|
|
3971
3689
|
/**
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3690
|
+
* format description
|
|
3691
|
+
* @param values The message content
|
|
3692
|
+
* @param separator The separator between messages. defaults to "\n\n"
|
|
3693
|
+
* @return returns messages formatted with template replacement
|
|
3694
|
+
*/
|
|
3977
3695
|
format(values, separator = "\n\n") {
|
|
3978
3696
|
const replacements = this.getReplacements(values);
|
|
3979
3697
|
const messages = this.messages.map((message) => {
|
|
3980
|
-
return message.content && !Array.isArray(message.content) ? this.replaceTemplateString(
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3698
|
+
return message.content && !Array.isArray(message.content) ? this.replaceTemplateString(
|
|
3699
|
+
this.runPromptFilter(message.content, this.filters.pre, values),
|
|
3700
|
+
replacements,
|
|
3701
|
+
{
|
|
3702
|
+
partials: this.partials,
|
|
3703
|
+
helpers: this.helpers
|
|
3704
|
+
}
|
|
3705
|
+
) : "";
|
|
3984
3706
|
}).join(separator);
|
|
3985
3707
|
return this.runPromptFilter(messages, this.filters.post, values);
|
|
3986
3708
|
}
|
|
3987
3709
|
/**
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3710
|
+
* format description
|
|
3711
|
+
* @param values The message content
|
|
3712
|
+
* @param separator The separator between messages. defaults to "\n\n"
|
|
3713
|
+
* @return returns messages formatted with template replacement
|
|
3714
|
+
*/
|
|
3993
3715
|
async formatAsync(values, separator = "\n\n") {
|
|
3994
3716
|
const replacements = this.getReplacements(values);
|
|
3995
3717
|
const _messages = await Promise.all(this.messages.map((message) => {
|
|
3996
|
-
return message.content && !Array.isArray(message.content) ? this.replaceTemplateStringAsync(
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
3718
|
+
return message.content && !Array.isArray(message.content) ? this.replaceTemplateStringAsync(
|
|
3719
|
+
this.runPromptFilter(message.content, this.filters.pre, values),
|
|
3720
|
+
replacements,
|
|
3721
|
+
{
|
|
3722
|
+
partials: this.partials,
|
|
3723
|
+
helpers: this.helpers
|
|
3724
|
+
}
|
|
3725
|
+
) : "";
|
|
4000
3726
|
}));
|
|
4001
3727
|
const messages = _messages.join(separator);
|
|
4002
3728
|
return this.runPromptFilter(messages, this.filters.post, values);
|
|
@@ -4010,33 +3736,31 @@ var _BasePrompt = class _BasePrompt {
|
|
|
4010
3736
|
}
|
|
4011
3737
|
getReplacements(values) {
|
|
4012
3738
|
const { input = "", ...restOfValues } = values;
|
|
4013
|
-
const replacements = Object.assign(
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4018
|
-
|
|
3739
|
+
const replacements = Object.assign(
|
|
3740
|
+
{},
|
|
3741
|
+
{ ...restOfValues },
|
|
3742
|
+
{
|
|
3743
|
+
input,
|
|
3744
|
+
_input: input
|
|
3745
|
+
}
|
|
3746
|
+
);
|
|
4019
3747
|
return replacements;
|
|
4020
3748
|
}
|
|
4021
3749
|
/**
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
3750
|
+
* validate description
|
|
3751
|
+
* @return {boolean} Returns false if the template is not valid.
|
|
3752
|
+
*/
|
|
4025
3753
|
validate() {
|
|
4026
3754
|
return true;
|
|
4027
3755
|
}
|
|
4028
3756
|
};
|
|
4029
|
-
__name(_BasePrompt, "BasePrompt");
|
|
4030
|
-
var BasePrompt = _BasePrompt;
|
|
4031
3757
|
|
|
4032
3758
|
// src/prompt/text.ts
|
|
4033
|
-
var
|
|
3759
|
+
var TextPrompt = class extends BasePrompt {
|
|
4034
3760
|
constructor(base, options) {
|
|
4035
3761
|
super(base, options);
|
|
4036
3762
|
}
|
|
4037
3763
|
};
|
|
4038
|
-
__name(_TextPrompt, "TextPrompt");
|
|
4039
|
-
var TextPrompt = _TextPrompt;
|
|
4040
3764
|
|
|
4041
3765
|
// src/utils/modules/unescape.ts
|
|
4042
3766
|
function unescape(str) {
|
|
@@ -4050,13 +3774,10 @@ function unescape(str) {
|
|
|
4050
3774
|
const entityRegex = /&|<|>|"|'/g;
|
|
4051
3775
|
return str.replace(entityRegex, (m) => map[m]);
|
|
4052
3776
|
}
|
|
4053
|
-
__name(unescape, "unescape");
|
|
4054
3777
|
|
|
4055
3778
|
// src/utils/modules/extractPromptPlaceholderToken.ts
|
|
4056
3779
|
function extractPromptPlaceholderToken(tok) {
|
|
4057
|
-
if (!tok) return {
|
|
4058
|
-
token: ""
|
|
4059
|
-
};
|
|
3780
|
+
if (!tok) return { token: "" };
|
|
4060
3781
|
const token = tok.replace(/ /g, "");
|
|
4061
3782
|
if (token.substring(2, 18) === ">DialogueHistory") {
|
|
4062
3783
|
const matchKey = tok.match(/key=(['"`])((?:(?!\1).)*)\1/);
|
|
@@ -4083,11 +3804,8 @@ function extractPromptPlaceholderToken(tok) {
|
|
|
4083
3804
|
};
|
|
4084
3805
|
}
|
|
4085
3806
|
}
|
|
4086
|
-
return {
|
|
4087
|
-
token: ""
|
|
4088
|
-
};
|
|
3807
|
+
return { token: "" };
|
|
4089
3808
|
}
|
|
4090
|
-
__name(extractPromptPlaceholderToken, "extractPromptPlaceholderToken");
|
|
4091
3809
|
|
|
4092
3810
|
// src/utils/modules/escape.ts
|
|
4093
3811
|
function escape(str) {
|
|
@@ -4100,29 +3818,28 @@ function escape(str) {
|
|
|
4100
3818
|
};
|
|
4101
3819
|
return str.replace(/[&<>"']/g, (m) => map[m]);
|
|
4102
3820
|
}
|
|
4103
|
-
__name(escape, "escape");
|
|
4104
3821
|
|
|
4105
3822
|
// src/prompt/chat.ts
|
|
4106
|
-
var
|
|
3823
|
+
var ChatPrompt = class extends BasePrompt {
|
|
4107
3824
|
/**
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
3825
|
+
* new `ChatPrompt`
|
|
3826
|
+
* @param initialSystemPromptMessage (optional) An initial system message to add to the new prompt.
|
|
3827
|
+
* @param options (optional) Options to pass in when creating the prompt.
|
|
3828
|
+
*/
|
|
4112
3829
|
constructor(initialSystemPromptMessage, options) {
|
|
4113
3830
|
super(initialSystemPromptMessage, options);
|
|
4114
3831
|
/**
|
|
4115
|
-
|
|
4116
|
-
|
|
3832
|
+
* @property type - Prompt type (chat)
|
|
3833
|
+
*/
|
|
4117
3834
|
__publicField(this, "type", "chat");
|
|
4118
3835
|
/**
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
__publicField(this, "parseUserTemplates",
|
|
4124
|
-
if (options?.allowUnsafeUserTemplate) {
|
|
4125
|
-
this.parseUserTemplates =
|
|
3836
|
+
* @property parseUserTemplates - Whether or not to allow parsing
|
|
3837
|
+
* user messages with the template engine. This could be a risk,
|
|
3838
|
+
* so we only parse user messages if explicitly set.
|
|
3839
|
+
*/
|
|
3840
|
+
__publicField(this, "parseUserTemplates", true);
|
|
3841
|
+
if (typeof options?.allowUnsafeUserTemplate === "boolean") {
|
|
3842
|
+
this.parseUserTemplates = options?.allowUnsafeUserTemplate;
|
|
4126
3843
|
}
|
|
4127
3844
|
}
|
|
4128
3845
|
addToPrompt(content, role, name) {
|
|
@@ -4143,21 +3860,18 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4143
3860
|
break;
|
|
4144
3861
|
case "function_call":
|
|
4145
3862
|
assert(name, "Function message requires name");
|
|
4146
|
-
this.addFunctionCallMessage({
|
|
4147
|
-
name,
|
|
4148
|
-
arguments: content
|
|
4149
|
-
});
|
|
3863
|
+
this.addFunctionCallMessage({ name, arguments: content });
|
|
4150
3864
|
break;
|
|
4151
3865
|
}
|
|
4152
3866
|
}
|
|
4153
3867
|
return this;
|
|
4154
3868
|
}
|
|
4155
3869
|
/**
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
3870
|
+
* addUserMessage Helper to add a user message to the prompt.
|
|
3871
|
+
* @param content The message content.
|
|
3872
|
+
* @param name (optional) The name of the user.
|
|
3873
|
+
* @return instance of ChatPrompt.
|
|
3874
|
+
*/
|
|
4161
3875
|
addUserMessage(content, name) {
|
|
4162
3876
|
const message = {
|
|
4163
3877
|
role: "user",
|
|
@@ -4170,10 +3884,10 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4170
3884
|
return this;
|
|
4171
3885
|
}
|
|
4172
3886
|
/**
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
3887
|
+
* addAssistantMessage Helper to add an assistant message to the prompt.
|
|
3888
|
+
* @param content The message content.
|
|
3889
|
+
* @return ChatPrompt so it can be chained.
|
|
3890
|
+
*/
|
|
4177
3891
|
addAssistantMessage(content) {
|
|
4178
3892
|
this.messages.push({
|
|
4179
3893
|
role: "assistant",
|
|
@@ -4182,10 +3896,10 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4182
3896
|
return this;
|
|
4183
3897
|
}
|
|
4184
3898
|
/**
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
3899
|
+
* addFunctionMessage Helper to add an assistant message to the prompt.
|
|
3900
|
+
* @param content The message content.
|
|
3901
|
+
* @return ChatPrompt so it can be chained.
|
|
3902
|
+
*/
|
|
4189
3903
|
addFunctionMessage(content, name) {
|
|
4190
3904
|
this.messages.push({
|
|
4191
3905
|
role: "function",
|
|
@@ -4195,10 +3909,10 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4195
3909
|
return this;
|
|
4196
3910
|
}
|
|
4197
3911
|
/**
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
3912
|
+
* addFunctionCallMessage Helper to add an assistant message to the prompt.
|
|
3913
|
+
* @param content The message content.
|
|
3914
|
+
* @return ChatPrompt so it can be chained.
|
|
3915
|
+
*/
|
|
4202
3916
|
addFunctionCallMessage(function_call) {
|
|
4203
3917
|
if (function_call) {
|
|
4204
3918
|
this.messages.push({
|
|
@@ -4213,10 +3927,10 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4213
3927
|
return this;
|
|
4214
3928
|
}
|
|
4215
3929
|
/**
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
3930
|
+
* addFromHistory Adds multiple messages at one time.
|
|
3931
|
+
* @param history History of chat messages.
|
|
3932
|
+
* @return ChatPrompt so it can be chained.
|
|
3933
|
+
*/
|
|
4220
3934
|
addFromHistory(history) {
|
|
4221
3935
|
if (history && Array.isArray(history)) {
|
|
4222
3936
|
for (const message of history) {
|
|
@@ -4243,15 +3957,13 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4243
3957
|
return this;
|
|
4244
3958
|
}
|
|
4245
3959
|
/**
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
3960
|
+
* addPlaceholder description
|
|
3961
|
+
* @param content The message content
|
|
3962
|
+
* @return returns ChatPrompt so it can be chained.
|
|
3963
|
+
*/
|
|
4250
3964
|
addChatHistoryPlaceholder(key, options) {
|
|
4251
3965
|
const start = `{{> DialogueHistory `;
|
|
4252
|
-
const params = [
|
|
4253
|
-
`key='${String(key)}'`
|
|
4254
|
-
];
|
|
3966
|
+
const params = [`key='${String(key)}'`];
|
|
4255
3967
|
const end = `}}`;
|
|
4256
3968
|
if (options?.assistant) {
|
|
4257
3969
|
params.push(`assistant='${options.assistant}'`);
|
|
@@ -4266,17 +3978,14 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4266
3978
|
return this;
|
|
4267
3979
|
}
|
|
4268
3980
|
/**
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
|
|
3981
|
+
* addTokenPlaceholder description
|
|
3982
|
+
* @param content The message content
|
|
3983
|
+
* @return returns ChatPrompt so it can be chained.
|
|
3984
|
+
*/
|
|
4273
3985
|
addMessagePlaceholder(content, role = "user", name) {
|
|
4274
3986
|
if (content) {
|
|
4275
3987
|
const start = `{{> SingleChatMessage `;
|
|
4276
|
-
const params = [
|
|
4277
|
-
`role='${role}'`,
|
|
4278
|
-
`content='${escape(content)}'`
|
|
4279
|
-
];
|
|
3988
|
+
const params = [`role='${role}'`, `content='${escape(content)}'`];
|
|
4280
3989
|
const end = `}}`;
|
|
4281
3990
|
if (name) {
|
|
4282
3991
|
params.push(`name='${name}'`);
|
|
@@ -4296,11 +4005,7 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4296
4005
|
for (const message of history) {
|
|
4297
4006
|
switch (message.role) {
|
|
4298
4007
|
case "user": {
|
|
4299
|
-
const m = pick(message, [
|
|
4300
|
-
"role",
|
|
4301
|
-
"content",
|
|
4302
|
-
"name"
|
|
4303
|
-
]);
|
|
4008
|
+
const m = pick(message, ["role", "content", "name"]);
|
|
4304
4009
|
if (user) {
|
|
4305
4010
|
m["name"] = user;
|
|
4306
4011
|
}
|
|
@@ -4341,19 +4046,16 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4341
4046
|
return messagesOut;
|
|
4342
4047
|
}
|
|
4343
4048
|
/**
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4049
|
+
* format formats the stored prompt based on input values.
|
|
4050
|
+
* Uses template engine.
|
|
4051
|
+
* Output is intended for LLM.
|
|
4052
|
+
* @param values input values.
|
|
4053
|
+
* @return formatted prompt.
|
|
4054
|
+
*/
|
|
4350
4055
|
format(values) {
|
|
4351
4056
|
const messagesOut = [];
|
|
4352
4057
|
const replacements = this.getReplacements(values);
|
|
4353
|
-
const safeToParseTemplate = [
|
|
4354
|
-
"assistant",
|
|
4355
|
-
"system"
|
|
4356
|
-
];
|
|
4058
|
+
const safeToParseTemplate = ["assistant", "system"];
|
|
4357
4059
|
if (this.parseUserTemplates) {
|
|
4358
4060
|
safeToParseTemplate.push("user");
|
|
4359
4061
|
}
|
|
@@ -4362,7 +4064,12 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4362
4064
|
const tokenData = extractPromptPlaceholderToken(message.content);
|
|
4363
4065
|
switch (tokenData.token) {
|
|
4364
4066
|
case ">DialogueHistory": {
|
|
4365
|
-
messagesOut.push(
|
|
4067
|
+
messagesOut.push(
|
|
4068
|
+
...this._format_placeholderDialogueHistory(
|
|
4069
|
+
tokenData,
|
|
4070
|
+
replacements
|
|
4071
|
+
)
|
|
4072
|
+
);
|
|
4366
4073
|
break;
|
|
4367
4074
|
}
|
|
4368
4075
|
case ">SingleChatMessage": {
|
|
@@ -4385,70 +4092,103 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4385
4092
|
}
|
|
4386
4093
|
}
|
|
4387
4094
|
} else if (message.role === "function") {
|
|
4388
|
-
messagesOut.push(
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4095
|
+
messagesOut.push(
|
|
4096
|
+
Object.assign({}, message, {
|
|
4097
|
+
content: this.replaceTemplateString(message.content, replacements, {
|
|
4098
|
+
partials: this.partials,
|
|
4099
|
+
helpers: this.helpers
|
|
4100
|
+
})
|
|
4392
4101
|
})
|
|
4393
|
-
|
|
4102
|
+
);
|
|
4394
4103
|
} else {
|
|
4395
4104
|
if (safeToParseTemplate.includes(message.role)) {
|
|
4396
4105
|
if (Array.isArray(message.content)) {
|
|
4397
|
-
const content = message.content.map(
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4106
|
+
const content = message.content.map(
|
|
4107
|
+
(m) => m.text ? {
|
|
4108
|
+
type: "text",
|
|
4109
|
+
text: this.runPromptFilter(
|
|
4110
|
+
this.replaceTemplateString(
|
|
4111
|
+
this.runPromptFilter(m.text, this.filters.pre, values),
|
|
4112
|
+
replacements,
|
|
4113
|
+
{
|
|
4114
|
+
partials: this.partials,
|
|
4115
|
+
helpers: this.helpers
|
|
4116
|
+
}
|
|
4117
|
+
),
|
|
4118
|
+
this.filters.post,
|
|
4119
|
+
values
|
|
4120
|
+
)
|
|
4121
|
+
} : m
|
|
4122
|
+
);
|
|
4123
|
+
messagesOut.push(Object.assign({}, message, { content }));
|
|
4407
4124
|
} else if (message.content) {
|
|
4408
|
-
const content = this.runPromptFilter(
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4125
|
+
const content = this.runPromptFilter(
|
|
4126
|
+
this.replaceTemplateString(
|
|
4127
|
+
this.runPromptFilter(message.content, this.filters.pre, values),
|
|
4128
|
+
replacements,
|
|
4129
|
+
{
|
|
4130
|
+
partials: this.partials,
|
|
4131
|
+
helpers: this.helpers
|
|
4132
|
+
}
|
|
4133
|
+
),
|
|
4134
|
+
this.filters.post,
|
|
4135
|
+
values
|
|
4136
|
+
);
|
|
4137
|
+
messagesOut.push(Object.assign({}, message, { content }));
|
|
4415
4138
|
} else {
|
|
4416
|
-
messagesOut.push(Object.assign({}, message, {
|
|
4417
|
-
content: null
|
|
4418
|
-
}));
|
|
4139
|
+
messagesOut.push(Object.assign({}, message, { content: null }));
|
|
4419
4140
|
}
|
|
4420
4141
|
} else {
|
|
4421
|
-
messagesOut.push(
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4142
|
+
messagesOut.push(
|
|
4143
|
+
Object.assign({}, message, {
|
|
4144
|
+
content: Array.isArray(message.content) ? message.content.map(
|
|
4145
|
+
(m) => m.text ? {
|
|
4146
|
+
type: "text",
|
|
4147
|
+
text: this.runPromptFilter(
|
|
4148
|
+
this.runPromptFilter(
|
|
4149
|
+
m.text,
|
|
4150
|
+
this.filters.pre,
|
|
4151
|
+
values
|
|
4152
|
+
),
|
|
4153
|
+
this.filters.post,
|
|
4154
|
+
values
|
|
4155
|
+
)
|
|
4156
|
+
} : m
|
|
4157
|
+
) : message.content && !Array.isArray(message.content) ? this.runPromptFilter(
|
|
4158
|
+
this.runPromptFilter(
|
|
4159
|
+
message.content,
|
|
4160
|
+
this.filters.pre,
|
|
4161
|
+
values
|
|
4162
|
+
),
|
|
4163
|
+
this.filters.post,
|
|
4164
|
+
values
|
|
4165
|
+
) : null
|
|
4166
|
+
})
|
|
4167
|
+
);
|
|
4427
4168
|
}
|
|
4428
4169
|
}
|
|
4429
4170
|
}
|
|
4430
4171
|
return messagesOut;
|
|
4431
4172
|
}
|
|
4432
4173
|
/**
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4174
|
+
* format formats the stored prompt based on input values.
|
|
4175
|
+
* Uses template engine.
|
|
4176
|
+
* Output is intended for LLM.
|
|
4177
|
+
* @param values input values.
|
|
4178
|
+
* @return formatted prompt.
|
|
4179
|
+
*/
|
|
4439
4180
|
async formatAsync(values) {
|
|
4440
4181
|
const messagesOut = [];
|
|
4441
4182
|
const replacements = this.getReplacements(values);
|
|
4442
|
-
const safeToParseTemplate = [
|
|
4443
|
-
"assistant",
|
|
4444
|
-
"system"
|
|
4445
|
-
];
|
|
4183
|
+
const safeToParseTemplate = ["assistant", "system"];
|
|
4446
4184
|
if (this.parseUserTemplates) {
|
|
4447
4185
|
safeToParseTemplate.push("user");
|
|
4448
4186
|
}
|
|
4449
4187
|
for (const message of this.messages) {
|
|
4450
4188
|
if (message.role === "placeholder") {
|
|
4451
|
-
const { token, ...data } = extractPromptPlaceholderToken(
|
|
4189
|
+
const { token, ...data } = extractPromptPlaceholderToken(
|
|
4190
|
+
message.content
|
|
4191
|
+
);
|
|
4452
4192
|
switch (token) {
|
|
4453
4193
|
case ">DialogueHistory": {
|
|
4454
4194
|
const { key = "", user } = data;
|
|
@@ -4457,11 +4197,7 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4457
4197
|
for (const message2 of history) {
|
|
4458
4198
|
switch (message2.role) {
|
|
4459
4199
|
case "user": {
|
|
4460
|
-
const m = pick(message2, [
|
|
4461
|
-
"role",
|
|
4462
|
-
"content",
|
|
4463
|
-
"name"
|
|
4464
|
-
]);
|
|
4200
|
+
const m = pick(message2, ["role", "content", "name"]);
|
|
4465
4201
|
if (user) {
|
|
4466
4202
|
m["name"] = user;
|
|
4467
4203
|
}
|
|
@@ -4507,10 +4243,14 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4507
4243
|
const message2 = {
|
|
4508
4244
|
role,
|
|
4509
4245
|
name,
|
|
4510
|
-
content: await this.replaceTemplateStringAsync(
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4246
|
+
content: await this.replaceTemplateStringAsync(
|
|
4247
|
+
content,
|
|
4248
|
+
replacements,
|
|
4249
|
+
{
|
|
4250
|
+
partials: this.partials,
|
|
4251
|
+
helpers: this.helpers
|
|
4252
|
+
}
|
|
4253
|
+
)
|
|
4514
4254
|
};
|
|
4515
4255
|
if (!name || role !== "user") {
|
|
4516
4256
|
delete message2.name;
|
|
@@ -4521,12 +4261,18 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4521
4261
|
}
|
|
4522
4262
|
}
|
|
4523
4263
|
} else if (message.role === "function") {
|
|
4524
|
-
messagesOut.push(
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4264
|
+
messagesOut.push(
|
|
4265
|
+
Object.assign({}, message, {
|
|
4266
|
+
content: await this.replaceTemplateStringAsync(
|
|
4267
|
+
message.content,
|
|
4268
|
+
replacements,
|
|
4269
|
+
{
|
|
4270
|
+
partials: this.partials,
|
|
4271
|
+
helpers: this.helpers
|
|
4272
|
+
}
|
|
4273
|
+
)
|
|
4528
4274
|
})
|
|
4529
|
-
|
|
4275
|
+
);
|
|
4530
4276
|
} else {
|
|
4531
4277
|
if (safeToParseTemplate.includes(message.role)) {
|
|
4532
4278
|
if (Array.isArray(message.content)) {
|
|
@@ -4537,10 +4283,14 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4537
4283
|
type: "text",
|
|
4538
4284
|
text: this.runPromptFilter(
|
|
4539
4285
|
// HERE
|
|
4540
|
-
await this.replaceTemplateStringAsync(
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4286
|
+
await this.replaceTemplateStringAsync(
|
|
4287
|
+
this.runPromptFilter(m.text, this.filters.pre, values),
|
|
4288
|
+
replacements,
|
|
4289
|
+
{
|
|
4290
|
+
partials: this.partials,
|
|
4291
|
+
helpers: this.helpers
|
|
4292
|
+
}
|
|
4293
|
+
),
|
|
4544
4294
|
this.filters.post,
|
|
4545
4295
|
values
|
|
4546
4296
|
)
|
|
@@ -4549,45 +4299,65 @@ var _ChatPrompt = class _ChatPrompt extends BasePrompt {
|
|
|
4549
4299
|
content.push(m);
|
|
4550
4300
|
}
|
|
4551
4301
|
}
|
|
4552
|
-
messagesOut.push(Object.assign({}, message, {
|
|
4553
|
-
content
|
|
4554
|
-
}));
|
|
4302
|
+
messagesOut.push(Object.assign({}, message, { content }));
|
|
4555
4303
|
} else if (message.content) {
|
|
4556
|
-
const content = this.runPromptFilter(
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4304
|
+
const content = this.runPromptFilter(
|
|
4305
|
+
await this.replaceTemplateStringAsync(
|
|
4306
|
+
this.runPromptFilter(message.content, this.filters.pre, values),
|
|
4307
|
+
replacements,
|
|
4308
|
+
{
|
|
4309
|
+
partials: this.partials,
|
|
4310
|
+
helpers: this.helpers
|
|
4311
|
+
}
|
|
4312
|
+
),
|
|
4313
|
+
this.filters.post,
|
|
4314
|
+
values
|
|
4315
|
+
);
|
|
4316
|
+
messagesOut.push(Object.assign({}, message, { content }));
|
|
4563
4317
|
} else {
|
|
4564
|
-
messagesOut.push(Object.assign({}, message, {
|
|
4565
|
-
content: null
|
|
4566
|
-
}));
|
|
4318
|
+
messagesOut.push(Object.assign({}, message, { content: null }));
|
|
4567
4319
|
}
|
|
4568
4320
|
} else {
|
|
4569
|
-
messagesOut.push(
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
|
|
4321
|
+
messagesOut.push(
|
|
4322
|
+
Object.assign({}, message, {
|
|
4323
|
+
content: Array.isArray(message.content) ? message.content.map(
|
|
4324
|
+
(m) => m.text ? {
|
|
4325
|
+
type: "text",
|
|
4326
|
+
text: this.runPromptFilter(
|
|
4327
|
+
this.runPromptFilter(
|
|
4328
|
+
m.text,
|
|
4329
|
+
this.filters.pre,
|
|
4330
|
+
values
|
|
4331
|
+
),
|
|
4332
|
+
this.filters.post,
|
|
4333
|
+
values
|
|
4334
|
+
)
|
|
4335
|
+
} : m
|
|
4336
|
+
) : message.content && !Array.isArray(message.content) ? this.runPromptFilter(
|
|
4337
|
+
this.runPromptFilter(
|
|
4338
|
+
message.content,
|
|
4339
|
+
this.filters.pre,
|
|
4340
|
+
values
|
|
4341
|
+
),
|
|
4342
|
+
this.filters.post,
|
|
4343
|
+
values
|
|
4344
|
+
) : null
|
|
4345
|
+
})
|
|
4346
|
+
);
|
|
4575
4347
|
}
|
|
4576
4348
|
}
|
|
4577
4349
|
}
|
|
4578
4350
|
return messagesOut;
|
|
4579
4351
|
}
|
|
4580
4352
|
/**
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4353
|
+
* validate Ensures there are not unresolved tokens in prompt.
|
|
4354
|
+
* @TODO Make this work!
|
|
4355
|
+
* @return Returns false if the template is not valid.
|
|
4356
|
+
*/
|
|
4585
4357
|
validate() {
|
|
4586
4358
|
return true;
|
|
4587
4359
|
}
|
|
4588
4360
|
};
|
|
4589
|
-
__name(_ChatPrompt, "ChatPrompt");
|
|
4590
|
-
var ChatPrompt = _ChatPrompt;
|
|
4591
4361
|
|
|
4592
4362
|
// src/prompt/_functions.ts
|
|
4593
4363
|
function createPrompt(type, initialPromptMessage, options) {
|
|
@@ -4598,14 +4368,12 @@ function createPrompt(type, initialPromptMessage, options) {
|
|
|
4598
4368
|
return new TextPrompt(initialPromptMessage);
|
|
4599
4369
|
}
|
|
4600
4370
|
}
|
|
4601
|
-
__name(createPrompt, "createPrompt");
|
|
4602
4371
|
function createChatPrompt(initialSystemPromptMessage, options) {
|
|
4603
4372
|
return new ChatPrompt(initialSystemPromptMessage, options);
|
|
4604
4373
|
}
|
|
4605
|
-
__name(createChatPrompt, "createChatPrompt");
|
|
4606
4374
|
|
|
4607
4375
|
// src/state/item.ts
|
|
4608
|
-
var
|
|
4376
|
+
var BaseStateItem = class {
|
|
4609
4377
|
constructor(key, initialValue) {
|
|
4610
4378
|
__publicField(this, "key");
|
|
4611
4379
|
__publicField(this, "value");
|
|
@@ -4615,7 +4383,10 @@ var _BaseStateItem = class _BaseStateItem {
|
|
|
4615
4383
|
this.initialValue = initialValue;
|
|
4616
4384
|
}
|
|
4617
4385
|
setValue(value) {
|
|
4618
|
-
assert(
|
|
4386
|
+
assert(
|
|
4387
|
+
typeof value === typeof this.value,
|
|
4388
|
+
`Invalid value type. Expected ${typeof this.value}, received ${typeof value}`
|
|
4389
|
+
);
|
|
4619
4390
|
this.value = value;
|
|
4620
4391
|
}
|
|
4621
4392
|
getKey() {
|
|
@@ -4639,19 +4410,18 @@ var _BaseStateItem = class _BaseStateItem {
|
|
|
4639
4410
|
value: this.serializeValue()
|
|
4640
4411
|
};
|
|
4641
4412
|
}
|
|
4413
|
+
// deserialize() {}
|
|
4642
4414
|
};
|
|
4643
|
-
|
|
4644
|
-
var BaseStateItem = _BaseStateItem;
|
|
4645
|
-
var _DefaultStateItem = class _DefaultStateItem extends BaseStateItem {
|
|
4415
|
+
var DefaultStateItem = class extends BaseStateItem {
|
|
4646
4416
|
constructor(name, defaultValue) {
|
|
4647
4417
|
super(name, defaultValue);
|
|
4648
4418
|
}
|
|
4419
|
+
// serialize() { return {}; }
|
|
4420
|
+
// deserialize() {}
|
|
4649
4421
|
};
|
|
4650
|
-
__name(_DefaultStateItem, "DefaultStateItem");
|
|
4651
|
-
var DefaultStateItem = _DefaultStateItem;
|
|
4652
4422
|
|
|
4653
4423
|
// src/state/dialogue.ts
|
|
4654
|
-
var
|
|
4424
|
+
var Dialogue = class extends BaseStateItem {
|
|
4655
4425
|
constructor(name) {
|
|
4656
4426
|
super(name, []);
|
|
4657
4427
|
__publicField(this, "name");
|
|
@@ -4699,6 +4469,12 @@ var _Dialogue = class _Dialogue extends BaseStateItem {
|
|
|
4699
4469
|
return this;
|
|
4700
4470
|
}
|
|
4701
4471
|
setFunctionCallMessage(input) {
|
|
4472
|
+
if (!input?.function_call) {
|
|
4473
|
+
throw new LlmExeError(`Invalid arguments`, "state", {
|
|
4474
|
+
error: `Invalid arguments: missing required function_call`,
|
|
4475
|
+
module: "dialogue"
|
|
4476
|
+
});
|
|
4477
|
+
}
|
|
4702
4478
|
this.value.push({
|
|
4703
4479
|
role: "assistant",
|
|
4704
4480
|
function_call: {
|
|
@@ -4747,17 +4523,14 @@ var _Dialogue = class _Dialogue extends BaseStateItem {
|
|
|
4747
4523
|
return {
|
|
4748
4524
|
class: "Dialogue",
|
|
4749
4525
|
name: this.name,
|
|
4750
|
-
value: [
|
|
4751
|
-
...this.value
|
|
4752
|
-
]
|
|
4526
|
+
value: [...this.value]
|
|
4753
4527
|
};
|
|
4754
4528
|
}
|
|
4529
|
+
// deserialize() {}
|
|
4755
4530
|
};
|
|
4756
|
-
__name(_Dialogue, "Dialogue");
|
|
4757
|
-
var Dialogue = _Dialogue;
|
|
4758
4531
|
|
|
4759
4532
|
// src/state/_base.ts
|
|
4760
|
-
var
|
|
4533
|
+
var BaseState = class {
|
|
4761
4534
|
constructor() {
|
|
4762
4535
|
__publicField(this, "dialogues", {});
|
|
4763
4536
|
__publicField(this, "attributes", {});
|
|
@@ -4782,8 +4555,14 @@ var _BaseState = class _BaseState {
|
|
|
4782
4555
|
return dialogue;
|
|
4783
4556
|
}
|
|
4784
4557
|
createContextItem(item) {
|
|
4785
|
-
assert(
|
|
4786
|
-
|
|
4558
|
+
assert(
|
|
4559
|
+
item instanceof BaseStateItem,
|
|
4560
|
+
"Invalid context item. Must be instance of BaseStateItem"
|
|
4561
|
+
);
|
|
4562
|
+
assert(
|
|
4563
|
+
!this.context[item?.getKey()],
|
|
4564
|
+
`key (${item?.getKey()}) already exists`
|
|
4565
|
+
);
|
|
4787
4566
|
this.context[item.getKey()] = item;
|
|
4788
4567
|
return this.context[item.getKey()];
|
|
4789
4568
|
}
|
|
@@ -4805,14 +4584,16 @@ var _BaseState = class _BaseState {
|
|
|
4805
4584
|
serialize() {
|
|
4806
4585
|
const dialogues = {};
|
|
4807
4586
|
const context = {};
|
|
4808
|
-
const attributes = {
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4587
|
+
const attributes = { ...this.attributes };
|
|
4588
|
+
const dialogueKeys = Object.keys(
|
|
4589
|
+
this.dialogues
|
|
4590
|
+
);
|
|
4812
4591
|
for (const dialogueKey of dialogueKeys) {
|
|
4813
4592
|
dialogues[dialogueKey] = this.dialogues[dialogueKey].serialize();
|
|
4814
4593
|
}
|
|
4815
|
-
const contextKeys = Object.keys(
|
|
4594
|
+
const contextKeys = Object.keys(
|
|
4595
|
+
this.context
|
|
4596
|
+
);
|
|
4816
4597
|
for (const contextKey of contextKeys) {
|
|
4817
4598
|
context[contextKey] = this.context[contextKey].serialize();
|
|
4818
4599
|
}
|
|
@@ -4823,9 +4604,7 @@ var _BaseState = class _BaseState {
|
|
|
4823
4604
|
};
|
|
4824
4605
|
}
|
|
4825
4606
|
};
|
|
4826
|
-
|
|
4827
|
-
var BaseState = _BaseState;
|
|
4828
|
-
var _DefaultState = class _DefaultState extends BaseState {
|
|
4607
|
+
var DefaultState = class extends BaseState {
|
|
4829
4608
|
constructor() {
|
|
4830
4609
|
super();
|
|
4831
4610
|
}
|
|
@@ -4833,22 +4612,17 @@ var _DefaultState = class _DefaultState extends BaseState {
|
|
|
4833
4612
|
console.log("Save not implemented in default state.");
|
|
4834
4613
|
}
|
|
4835
4614
|
};
|
|
4836
|
-
__name(_DefaultState, "DefaultState");
|
|
4837
|
-
var DefaultState = _DefaultState;
|
|
4838
4615
|
|
|
4839
4616
|
// src/state/_functions.ts
|
|
4840
4617
|
function createState() {
|
|
4841
4618
|
return new DefaultState();
|
|
4842
4619
|
}
|
|
4843
|
-
__name(createState, "createState");
|
|
4844
4620
|
function createDialogue(name) {
|
|
4845
4621
|
return new Dialogue(name);
|
|
4846
4622
|
}
|
|
4847
|
-
__name(createDialogue, "createDialogue");
|
|
4848
4623
|
function createStateItem(name, defaultValue) {
|
|
4849
4624
|
return new DefaultStateItem(name, defaultValue);
|
|
4850
4625
|
}
|
|
4851
|
-
__name(createStateItem, "createStateItem");
|
|
4852
4626
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4853
4627
|
0 && (module.exports = {
|
|
4854
4628
|
BaseExecutor,
|
|
@@ -4860,6 +4634,8 @@ __name(createStateItem, "createStateItem");
|
|
|
4860
4634
|
DefaultState,
|
|
4861
4635
|
DefaultStateItem,
|
|
4862
4636
|
LlmExecutorOpenAiFunctions,
|
|
4637
|
+
LlmExecutorWithFunctions,
|
|
4638
|
+
LlmNativeFunctionParser,
|
|
4863
4639
|
OpenAiFunctionParser,
|
|
4864
4640
|
TextPrompt,
|
|
4865
4641
|
createCallableExecutor,
|
|
@@ -4869,10 +4645,14 @@ __name(createStateItem, "createStateItem");
|
|
|
4869
4645
|
createDialogue,
|
|
4870
4646
|
createEmbedding,
|
|
4871
4647
|
createLlmExecutor,
|
|
4648
|
+
createLlmFunctionExecutor,
|
|
4872
4649
|
createParser,
|
|
4873
4650
|
createPrompt,
|
|
4874
4651
|
createState,
|
|
4875
4652
|
createStateItem,
|
|
4653
|
+
defineSchema,
|
|
4654
|
+
registerHelpers,
|
|
4655
|
+
registerPartials,
|
|
4876
4656
|
useExecutors,
|
|
4877
4657
|
useLlm,
|
|
4878
4658
|
utils
|