modelfusion 0.134.0 → 0.135.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/index.js CHANGED
@@ -1,25 +1,27 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
+ }) : x)(function(x) {
5
+ if (typeof require !== "undefined")
6
+ return require.apply(this, arguments);
7
+ throw Error('Dynamic require of "' + x + '" is not supported');
8
+ });
3
9
  var __export = (target, all) => {
4
10
  for (var name in all)
5
11
  __defProp(target, name, { get: all[name], enumerable: true });
6
12
  };
7
- var __publicField = (obj, key, value) => {
8
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
9
- return value;
10
- };
11
13
 
12
14
  // src/core/DefaultRun.ts
13
15
  import { nanoid as createId } from "nanoid";
14
16
 
15
17
  // src/core/FunctionEventSource.ts
16
18
  var FunctionEventSource = class {
19
+ observers;
20
+ errorHandler;
17
21
  constructor({
18
22
  observers,
19
23
  errorHandler
20
24
  }) {
21
- __publicField(this, "observers");
22
- __publicField(this, "errorHandler");
23
25
  this.observers = observers;
24
26
  this.errorHandler = errorHandler ?? ((error) => console.error(error));
25
27
  }
@@ -36,6 +38,13 @@ var FunctionEventSource = class {
36
38
 
37
39
  // src/core/DefaultRun.ts
38
40
  var DefaultRun = class {
41
+ runId;
42
+ sessionId;
43
+ userId;
44
+ abortSignal;
45
+ errorHandler;
46
+ events = [];
47
+ functionEventSource;
39
48
  constructor({
40
49
  runId = `run-${createId()}`,
41
50
  sessionId,
@@ -44,19 +53,6 @@ var DefaultRun = class {
44
53
  observers,
45
54
  errorHandler
46
55
  } = {}) {
47
- __publicField(this, "runId");
48
- __publicField(this, "sessionId");
49
- __publicField(this, "userId");
50
- __publicField(this, "abortSignal");
51
- __publicField(this, "errorHandler");
52
- __publicField(this, "events", []);
53
- __publicField(this, "functionEventSource");
54
- __publicField(this, "functionObserver", {
55
- onFunctionEvent: (event) => {
56
- this.events.push(event);
57
- this.functionEventSource.notify(event);
58
- }
59
- });
60
56
  this.runId = runId;
61
57
  this.sessionId = sessionId;
62
58
  this.userId = userId;
@@ -67,6 +63,12 @@ var DefaultRun = class {
67
63
  errorHandler: this.errorHandler.bind(this)
68
64
  });
69
65
  }
66
+ functionObserver = {
67
+ onFunctionEvent: (event) => {
68
+ this.events.push(event);
69
+ this.functionEventSource.notify(event);
70
+ }
71
+ };
70
72
  };
71
73
 
72
74
  // src/core/ModelFusionConfiguration.ts
@@ -116,6 +118,13 @@ var AbortError = class extends Error {
116
118
 
117
119
  // src/core/api/ApiCallError.ts
118
120
  var ApiCallError = class extends Error {
121
+ url;
122
+ requestBodyValues;
123
+ statusCode;
124
+ responseBody;
125
+ cause;
126
+ isRetryable;
127
+ data;
119
128
  constructor({
120
129
  message,
121
130
  url,
@@ -127,13 +136,6 @@ var ApiCallError = class extends Error {
127
136
  data
128
137
  }) {
129
138
  super(message);
130
- __publicField(this, "url");
131
- __publicField(this, "requestBodyValues");
132
- __publicField(this, "statusCode");
133
- __publicField(this, "responseBody");
134
- __publicField(this, "cause");
135
- __publicField(this, "isRetryable");
136
- __publicField(this, "data");
137
139
  this.name = "ApiCallError";
138
140
  this.url = url;
139
141
  this.requestBodyValues = requestBodyValues;
@@ -191,16 +193,16 @@ function getErrorMessage(error) {
191
193
 
192
194
  // src/core/api/RetryError.ts
193
195
  var RetryError = class extends Error {
196
+ // note: property order determines debugging output
197
+ reason;
198
+ lastError;
199
+ errors;
194
200
  constructor({
195
201
  message,
196
202
  reason,
197
203
  errors
198
204
  }) {
199
205
  super(message);
200
- // note: property order determines debugging output
201
- __publicField(this, "reason");
202
- __publicField(this, "lastError");
203
- __publicField(this, "errors");
204
206
  this.name = "RetryError";
205
207
  this.reason = reason;
206
208
  this.errors = errors;
@@ -268,10 +270,10 @@ async function _retryWithExponentialBackoff(f, {
268
270
 
269
271
  // src/core/api/throttleMaxConcurrency.ts
270
272
  var MaxConcurrencyThrottler = class {
273
+ maxConcurrentCalls;
274
+ activeCallCount;
275
+ callQueue;
271
276
  constructor({ maxConcurrentCalls }) {
272
- __publicField(this, "maxConcurrentCalls");
273
- __publicField(this, "activeCallCount");
274
- __publicField(this, "callQueue");
275
277
  this.maxConcurrentCalls = maxConcurrentCalls;
276
278
  this.activeCallCount = 0;
277
279
  this.callQueue = [];
@@ -315,14 +317,14 @@ var throttleOff = () => (fn) => fn();
315
317
 
316
318
  // src/core/api/AbstractApiConfiguration.ts
317
319
  var AbstractApiConfiguration = class {
320
+ retry;
321
+ throttle;
322
+ customCallHeaders;
318
323
  constructor({
319
324
  retry,
320
325
  throttle,
321
326
  customCallHeaders = () => ({})
322
327
  }) {
323
- __publicField(this, "retry");
324
- __publicField(this, "throttle");
325
- __publicField(this, "customCallHeaders");
326
328
  this.retry = retry;
327
329
  this.throttle = throttle;
328
330
  this.customCallHeaders = customCallHeaders;
@@ -342,6 +344,8 @@ var AbstractApiConfiguration = class {
342
344
 
343
345
  // src/core/api/BaseUrlApiConfiguration.ts
344
346
  var BaseUrlApiConfiguration = class extends AbstractApiConfiguration {
347
+ baseUrl;
348
+ fixedHeadersValue;
345
349
  constructor({
346
350
  baseUrl,
347
351
  headers,
@@ -350,8 +354,6 @@ var BaseUrlApiConfiguration = class extends AbstractApiConfiguration {
350
354
  customCallHeaders
351
355
  }) {
352
356
  super({ retry, throttle, customCallHeaders });
353
- __publicField(this, "baseUrl");
354
- __publicField(this, "fixedHeadersValue");
355
357
  this.baseUrl = typeof baseUrl == "string" ? parseBaseUrl(baseUrl) : baseUrl;
356
358
  this.fixedHeadersValue = headers ?? {};
357
359
  }
@@ -412,9 +414,7 @@ function resolveBaseUrl(baseUrl = {}, baseUrlDefaults) {
412
414
 
413
415
  // src/core/cache/MemoryCache.ts
414
416
  var MemoryCache = class {
415
- constructor() {
416
- __publicField(this, "cache", /* @__PURE__ */ new Map());
417
- }
417
+ cache = /* @__PURE__ */ new Map();
418
418
  hashKey(key) {
419
419
  return JSON.stringify(key);
420
420
  }
@@ -538,7 +538,16 @@ function detectRuntime() {
538
538
  var runStorage;
539
539
  async function ensureLoaded() {
540
540
  if (detectRuntime() === "node" && !runStorage) {
541
- const { AsyncLocalStorage } = await import("async_hooks");
541
+ let AsyncLocalStorage;
542
+ try {
543
+ AsyncLocalStorage = (await import("async_hooks")).AsyncLocalStorage;
544
+ } catch (error) {
545
+ try {
546
+ AsyncLocalStorage = __require("async_hooks").AsyncLocalStorage;
547
+ } catch (error2) {
548
+ throw new Error(`Failed to load 'async_hooks' module dynamically.`);
549
+ }
550
+ }
542
551
  runStorage = new AsyncLocalStorage();
543
552
  }
544
553
  return Promise.resolve();
@@ -561,9 +570,7 @@ function startDurationMeasurement() {
561
570
  return globalThis.performance != null ? new PerformanceNowDurationMeasurement() : new DateDurationMeasurement();
562
571
  }
563
572
  var PerformanceNowDurationMeasurement = class {
564
- constructor() {
565
- __publicField(this, "startTime", globalThis.performance.now());
566
- }
573
+ startTime = globalThis.performance.now();
567
574
  get startEpochSeconds() {
568
575
  return Math.floor(
569
576
  (globalThis.performance.timeOrigin + this.startTime) / 1e3
@@ -577,9 +584,7 @@ var PerformanceNowDurationMeasurement = class {
577
584
  }
578
585
  };
579
586
  var DateDurationMeasurement = class {
580
- constructor() {
581
- __publicField(this, "startTime", Date.now());
582
- }
587
+ startTime = Date.now();
583
588
  get startEpochSeconds() {
584
589
  return Math.floor(this.startTime / 1e3);
585
590
  }
@@ -699,14 +704,14 @@ async function executeFunction(fn, input, options) {
699
704
 
700
705
  // src/core/schema/JSONParseError.ts
701
706
  var JSONParseError = class extends Error {
707
+ // note: property order determines debugging output
708
+ text;
709
+ cause;
702
710
  constructor({ text: text13, cause }) {
703
711
  super(
704
712
  `JSON parsing failed: Text: ${text13}.
705
713
  Error message: ${getErrorMessage(cause)}`
706
714
  );
707
- // note: property order determines debugging output
708
- __publicField(this, "text");
709
- __publicField(this, "cause");
710
715
  this.name = "JSONParseError";
711
716
  this.cause = cause;
712
717
  this.text = text13;
@@ -724,13 +729,13 @@ Error message: ${getErrorMessage(cause)}`
724
729
 
725
730
  // src/core/schema/TypeValidationError.ts
726
731
  var TypeValidationError = class extends Error {
732
+ value;
733
+ cause;
727
734
  constructor({ value, cause }) {
728
735
  super(
729
736
  `Type validation failed: Value: ${JSON.stringify(value)}.
730
737
  Error message: ${getErrorMessage(cause)}`
731
738
  );
732
- __publicField(this, "value");
733
- __publicField(this, "cause");
734
739
  this.name = "TypeValidationError";
735
740
  this.cause = cause;
736
741
  this.value = value;
@@ -753,7 +758,6 @@ function uncheckedSchema(jsonSchema) {
753
758
  var UncheckedSchema = class {
754
759
  constructor(jsonSchema) {
755
760
  this.jsonSchema = jsonSchema;
756
- __publicField(this, "_type");
757
761
  }
758
762
  validate(value) {
759
763
  return { success: true, value };
@@ -761,6 +765,7 @@ var UncheckedSchema = class {
761
765
  getJsonSchema() {
762
766
  return this.jsonSchema;
763
767
  }
768
+ _type;
764
769
  };
765
770
 
766
771
  // src/core/schema/ZodSchema.ts
@@ -769,16 +774,8 @@ function zodSchema(zodSchema2) {
769
774
  return new ZodSchema(zodSchema2);
770
775
  }
771
776
  var ZodSchema = class {
777
+ zodSchema;
772
778
  constructor(zodSchema2) {
773
- __publicField(this, "zodSchema");
774
- /**
775
- * Use only for typing purposes. The value is always `undefined`.
776
- */
777
- __publicField(this, "_type");
778
- /**
779
- * Use only for typing purposes. The value is always `undefined`.
780
- */
781
- __publicField(this, "_partialType");
782
779
  this.zodSchema = zodSchema2;
783
780
  }
784
781
  validate(value) {
@@ -788,6 +785,14 @@ var ZodSchema = class {
788
785
  getJsonSchema() {
789
786
  return zodToJsonSchema(this.zodSchema);
790
787
  }
788
+ /**
789
+ * Use only for typing purposes. The value is always `undefined`.
790
+ */
791
+ _type;
792
+ /**
793
+ * Use only for typing purposes. The value is always `undefined`.
794
+ */
795
+ _partialType;
791
796
  };
792
797
 
793
798
  // src/core/schema/parseJSON.ts
@@ -1086,13 +1091,13 @@ async function embed({
1086
1091
 
1087
1092
  // src/model-function/classify/EmbeddingSimilarityClassifier.ts
1088
1093
  var EmbeddingSimilarityClassifier = class _EmbeddingSimilarityClassifier {
1094
+ settings;
1095
+ modelInformation = {
1096
+ provider: "modelfusion",
1097
+ modelName: "EmbeddingSimilarityClassifier"
1098
+ };
1099
+ embeddings;
1089
1100
  constructor(settings) {
1090
- __publicField(this, "settings");
1091
- __publicField(this, "modelInformation", {
1092
- provider: "modelfusion",
1093
- modelName: "EmbeddingSimilarityClassifier"
1094
- });
1095
- __publicField(this, "embeddings");
1096
1101
  this.settings = settings;
1097
1102
  }
1098
1103
  async getEmbeddings(options) {
@@ -1189,12 +1194,12 @@ async function classify({
1189
1194
 
1190
1195
  // src/model-function/generate-image/PromptTemplateImageGenerationModel.ts
1191
1196
  var PromptTemplateImageGenerationModel = class _PromptTemplateImageGenerationModel {
1197
+ model;
1198
+ promptTemplate;
1192
1199
  constructor({
1193
1200
  model,
1194
1201
  promptTemplate
1195
1202
  }) {
1196
- __publicField(this, "model");
1197
- __publicField(this, "promptTemplate");
1198
1203
  this.model = model;
1199
1204
  this.promptTemplate = promptTemplate;
1200
1205
  }
@@ -1308,11 +1313,9 @@ async function generateSpeech({
1308
1313
 
1309
1314
  // src/util/AsyncQueue.ts
1310
1315
  var AsyncQueue = class {
1311
- constructor() {
1312
- __publicField(this, "values", Array());
1313
- __publicField(this, "pendingResolvers", []);
1314
- __publicField(this, "closed", false);
1315
- }
1316
+ values = Array();
1317
+ pendingResolvers = [];
1318
+ closed = false;
1316
1319
  processPendingResolvers() {
1317
1320
  while (this.pendingResolvers.length > 0) {
1318
1321
  this.pendingResolvers.shift()?.();
@@ -1678,13 +1681,13 @@ async function generateText({
1678
1681
 
1679
1682
  // src/model-function/generate-object/ObjectParseError.ts
1680
1683
  var ObjectParseError = class extends Error {
1684
+ cause;
1685
+ valueText;
1681
1686
  constructor({ valueText, cause }) {
1682
1687
  super(
1683
1688
  `Object parsing failed. Value: ${valueText}.
1684
1689
  Error message: ${getErrorMessage(cause)}`
1685
1690
  );
1686
- __publicField(this, "cause");
1687
- __publicField(this, "valueText");
1688
1691
  this.name = "ObjectParseError";
1689
1692
  this.cause = cause;
1690
1693
  this.valueText = valueText;
@@ -1702,12 +1705,12 @@ Error message: ${getErrorMessage(cause)}`
1702
1705
 
1703
1706
  // src/model-function/generate-object/ObjectFromTextGenerationModel.ts
1704
1707
  var ObjectFromTextGenerationModel = class _ObjectFromTextGenerationModel {
1708
+ model;
1709
+ template;
1705
1710
  constructor({
1706
1711
  model,
1707
1712
  template
1708
1713
  }) {
1709
- __publicField(this, "model");
1710
- __publicField(this, "template");
1711
1714
  this.model = model;
1712
1715
  this.template = template;
1713
1716
  }
@@ -2228,6 +2231,9 @@ function ObjectStreamToTextStream(stream) {
2228
2231
 
2229
2232
  // src/model-function/generate-object/ObjectValidationError.ts
2230
2233
  var ObjectValidationError = class extends Error {
2234
+ cause;
2235
+ valueText;
2236
+ value;
2231
2237
  constructor({
2232
2238
  value,
2233
2239
  valueText,
@@ -2237,9 +2243,6 @@ var ObjectValidationError = class extends Error {
2237
2243
  `Object validation failed. Value: ${valueText}.
2238
2244
  Error message: ${getErrorMessage(cause)}`
2239
2245
  );
2240
- __publicField(this, "cause");
2241
- __publicField(this, "valueText");
2242
- __publicField(this, "value");
2243
2246
  this.name = "ObjectValidationError";
2244
2247
  this.cause = cause;
2245
2248
  this.value = value;
@@ -2306,7 +2309,7 @@ async function generateObject({
2306
2309
 
2307
2310
  // src/model-function/generate-object/jsonObjectPrompt.ts
2308
2311
  var DEFAULT_SCHEMA_PREFIX = "JSON schema:";
2309
- var DEFAULT_SCHEMA_SUFFIX = "\nYou MUST answer with a JSON object matches the above schema.";
2312
+ var DEFAULT_SCHEMA_SUFFIX = "\nYou MUST answer with a JSON object that matches the JSON schema above.";
2310
2313
  var jsonObjectPrompt = {
2311
2314
  custom(createPrompt) {
2312
2315
  return { createPrompt, extractObject };
@@ -2353,6 +2356,7 @@ function createSystemPrompt({
2353
2356
  }) {
2354
2357
  return [
2355
2358
  originalSystemPrompt,
2359
+ originalSystemPrompt != null ? "" : null,
2356
2360
  schemaPrefix,
2357
2361
  JSON.stringify(schema.getJsonSchema()),
2358
2362
  schemaSuffix
@@ -2472,6 +2476,9 @@ async function streamObject({
2472
2476
 
2473
2477
  // src/tool/generate-tool-call/ToolCallParseError.ts
2474
2478
  var ToolCallParseError = class extends Error {
2479
+ toolName;
2480
+ valueText;
2481
+ cause;
2475
2482
  constructor({
2476
2483
  toolName,
2477
2484
  valueText,
@@ -2481,9 +2488,6 @@ var ToolCallParseError = class extends Error {
2481
2488
  `Tool call parsing failed for '${toolName}'. Value: ${valueText}.
2482
2489
  Error message: ${getErrorMessage(cause)}`
2483
2490
  );
2484
- __publicField(this, "toolName");
2485
- __publicField(this, "valueText");
2486
- __publicField(this, "cause");
2487
2491
  this.name = "ToolCallParseError";
2488
2492
  this.toolName = toolName;
2489
2493
  this.cause = cause;
@@ -2503,14 +2507,14 @@ Error message: ${getErrorMessage(cause)}`
2503
2507
 
2504
2508
  // src/tool/generate-tool-call/TextGenerationToolCallModel.ts
2505
2509
  var TextGenerationToolCallModel = class _TextGenerationToolCallModel {
2510
+ model;
2511
+ template;
2506
2512
  constructor({
2507
2513
  model,
2508
- format
2514
+ template
2509
2515
  }) {
2510
- __publicField(this, "model");
2511
- __publicField(this, "format");
2512
2516
  this.model = model;
2513
- this.format = format;
2517
+ this.template = template;
2514
2518
  }
2515
2519
  get modelInformation() {
2516
2520
  return this.model.modelInformation;
@@ -2521,17 +2525,26 @@ var TextGenerationToolCallModel = class _TextGenerationToolCallModel {
2521
2525
  get settingsForEvent() {
2522
2526
  return this.model.settingsForEvent;
2523
2527
  }
2528
+ getModelWithJsonOutput(schema) {
2529
+ if (this.template.withJsonOutput != null) {
2530
+ return this.template.withJsonOutput({
2531
+ model: this.model,
2532
+ schema
2533
+ });
2534
+ }
2535
+ return this.model;
2536
+ }
2524
2537
  async doGenerateToolCall(tool, prompt, options) {
2525
2538
  const { rawResponse, text: text13, metadata } = await generateText({
2526
- model: this.model,
2527
- prompt: this.format.createPrompt(prompt, tool),
2539
+ model: this.getModelWithJsonOutput(tool.parameters),
2540
+ prompt: this.template.createPrompt(prompt, tool),
2528
2541
  fullResponse: true,
2529
2542
  ...options
2530
2543
  });
2531
2544
  try {
2532
2545
  return {
2533
2546
  rawResponse,
2534
- toolCall: this.format.extractToolCall(text13, tool),
2547
+ toolCall: this.template.extractToolCall(text13, tool),
2535
2548
  usage: metadata?.usage
2536
2549
  };
2537
2550
  } catch (error) {
@@ -2545,20 +2558,20 @@ var TextGenerationToolCallModel = class _TextGenerationToolCallModel {
2545
2558
  withSettings(additionalSettings) {
2546
2559
  return new _TextGenerationToolCallModel({
2547
2560
  model: this.model.withSettings(additionalSettings),
2548
- format: this.format
2561
+ template: this.template
2549
2562
  });
2550
2563
  }
2551
2564
  };
2552
2565
 
2553
2566
  // src/tool/generate-tool-calls/ToolCallsParseError.ts
2554
2567
  var ToolCallsParseError = class extends Error {
2568
+ valueText;
2569
+ cause;
2555
2570
  constructor({ valueText, cause }) {
2556
2571
  super(
2557
2572
  `Tool calls parsing failed. Value: ${valueText}.
2558
2573
  Error message: ${getErrorMessage(cause)}`
2559
2574
  );
2560
- __publicField(this, "valueText");
2561
- __publicField(this, "cause");
2562
2575
  this.name = "ToolCallsParseError";
2563
2576
  this.cause = cause;
2564
2577
  this.valueText = valueText;
@@ -2576,12 +2589,12 @@ Error message: ${getErrorMessage(cause)}`
2576
2589
 
2577
2590
  // src/tool/generate-tool-calls/TextGenerationToolCallsModel.ts
2578
2591
  var TextGenerationToolCallsModel = class _TextGenerationToolCallsModel {
2592
+ model;
2593
+ template;
2579
2594
  constructor({
2580
2595
  model,
2581
2596
  template
2582
2597
  }) {
2583
- __publicField(this, "model");
2584
- __publicField(this, "template");
2585
2598
  this.model = model;
2586
2599
  this.template = template;
2587
2600
  }
@@ -2630,12 +2643,12 @@ var TextGenerationToolCallsModel = class _TextGenerationToolCallsModel {
2630
2643
 
2631
2644
  // src/model-function/generate-text/PromptTemplateTextGenerationModel.ts
2632
2645
  var PromptTemplateTextGenerationModel = class _PromptTemplateTextGenerationModel {
2646
+ model;
2647
+ promptTemplate;
2633
2648
  constructor({
2634
2649
  model,
2635
2650
  promptTemplate
2636
2651
  }) {
2637
- __publicField(this, "model");
2638
- __publicField(this, "promptTemplate");
2639
2652
  this.model = model;
2640
2653
  this.promptTemplate = promptTemplate;
2641
2654
  }
@@ -2675,7 +2688,7 @@ var PromptTemplateTextGenerationModel = class _PromptTemplateTextGenerationModel
2675
2688
  asToolCallGenerationModel(promptTemplate) {
2676
2689
  return new TextGenerationToolCallModel({
2677
2690
  model: this,
2678
- format: promptTemplate
2691
+ template: promptTemplate
2679
2692
  });
2680
2693
  }
2681
2694
  asToolCallsOrTextGenerationModel(promptTemplate) {
@@ -2775,9 +2788,9 @@ __export(AlpacaPromptTemplate_exports, {
2775
2788
 
2776
2789
  // src/model-function/generate-text/prompt-template/InvalidPromptError.ts
2777
2790
  var InvalidPromptError = class extends Error {
2791
+ prompt;
2778
2792
  constructor(message, prompt) {
2779
2793
  super(message);
2780
- __publicField(this, "prompt");
2781
2794
  this.name = "InvalidPromptError";
2782
2795
  this.prompt = prompt;
2783
2796
  }
@@ -3792,8 +3805,8 @@ var callWithRetryAndThrottle = async ({
3792
3805
 
3793
3806
  // src/model-function/AbstractModel.ts
3794
3807
  var AbstractModel = class {
3808
+ settings;
3795
3809
  constructor({ settings }) {
3796
- __publicField(this, "settings");
3797
3810
  this.settings = settings;
3798
3811
  }
3799
3812
  // implemented as a separate accessor to remove all other properties from the model
@@ -3816,8 +3829,8 @@ function mapBasicPromptToAutomatic1111Format() {
3816
3829
  var Automatic1111ImageGenerationModel = class _Automatic1111ImageGenerationModel extends AbstractModel {
3817
3830
  constructor(settings) {
3818
3831
  super({ settings });
3819
- __publicField(this, "provider", "Automatic1111");
3820
3832
  }
3833
+ provider = "Automatic1111";
3821
3834
  get modelName() {
3822
3835
  return this.settings.model;
3823
3836
  }
@@ -3993,8 +4006,8 @@ import { z as z5 } from "zod";
3993
4006
  // src/model-provider/cohere/CohereTokenizer.ts
3994
4007
  import { z as z4 } from "zod";
3995
4008
  var CohereTokenizer = class {
4009
+ settings;
3996
4010
  constructor(settings) {
3997
- __publicField(this, "settings");
3998
4011
  this.settings = settings;
3999
4012
  }
4000
4013
  async callTokenizeAPI(text13, callOptions) {
@@ -4116,12 +4129,6 @@ var COHERE_TEXT_EMBEDDING_MODELS = {
4116
4129
  var CohereTextEmbeddingModel = class _CohereTextEmbeddingModel extends AbstractModel {
4117
4130
  constructor(settings) {
4118
4131
  super({ settings });
4119
- __publicField(this, "provider", "cohere");
4120
- __publicField(this, "maxValuesPerCall", 96);
4121
- __publicField(this, "isParallelizable", true);
4122
- __publicField(this, "dimensions");
4123
- __publicField(this, "contextWindowSize");
4124
- __publicField(this, "tokenizer");
4125
4132
  this.contextWindowSize = COHERE_TEXT_EMBEDDING_MODELS[this.modelName].contextWindowSize;
4126
4133
  this.tokenizer = new CohereTokenizer({
4127
4134
  api: this.settings.api,
@@ -4129,9 +4136,15 @@ var CohereTextEmbeddingModel = class _CohereTextEmbeddingModel extends AbstractM
4129
4136
  });
4130
4137
  this.dimensions = COHERE_TEXT_EMBEDDING_MODELS[this.modelName].dimensions;
4131
4138
  }
4139
+ provider = "cohere";
4132
4140
  get modelName() {
4133
4141
  return this.settings.model;
4134
4142
  }
4143
+ maxValuesPerCall = 96;
4144
+ isParallelizable = true;
4145
+ dimensions;
4146
+ contextWindowSize;
4147
+ tokenizer;
4135
4148
  async tokenize(text13) {
4136
4149
  return this.tokenizer.tokenize(text13);
4137
4150
  }
@@ -4277,18 +4290,18 @@ var COHERE_TEXT_GENERATION_MODELS = {
4277
4290
  var CohereTextGenerationModel = class _CohereTextGenerationModel extends AbstractModel {
4278
4291
  constructor(settings) {
4279
4292
  super({ settings });
4280
- __publicField(this, "provider", "cohere");
4281
- __publicField(this, "contextWindowSize");
4282
- __publicField(this, "tokenizer");
4283
4293
  this.contextWindowSize = COHERE_TEXT_GENERATION_MODELS[this.settings.model].contextWindowSize;
4284
4294
  this.tokenizer = new CohereTokenizer({
4285
4295
  api: this.settings.api,
4286
4296
  model: this.settings.model
4287
4297
  });
4288
4298
  }
4299
+ provider = "cohere";
4289
4300
  get modelName() {
4290
4301
  return this.settings.model;
4291
4302
  }
4303
+ contextWindowSize;
4304
+ tokenizer;
4292
4305
  async countPromptTokens(input) {
4293
4306
  return countTokens(this.tokenizer, input);
4294
4307
  }
@@ -4532,7 +4545,16 @@ async function createSimpleWebSocket(url) {
4532
4545
  return new WebSocket(url);
4533
4546
  }
4534
4547
  case "node": {
4535
- const { default: WebSocket2 } = await import("ws");
4548
+ let WebSocket2;
4549
+ try {
4550
+ WebSocket2 = (await import("ws")).default;
4551
+ } catch (error) {
4552
+ try {
4553
+ WebSocket2 = __require("ws");
4554
+ } catch (error2) {
4555
+ throw new Error(`Failed to load 'ws' module dynamically.`);
4556
+ }
4557
+ }
4536
4558
  return new WebSocket2(url);
4537
4559
  }
4538
4560
  default: {
@@ -4546,8 +4568,8 @@ var defaultModel = "eleven_monolingual_v1";
4546
4568
  var ElevenLabsSpeechModel = class _ElevenLabsSpeechModel extends AbstractModel {
4547
4569
  constructor(settings) {
4548
4570
  super({ settings });
4549
- __publicField(this, "provider", "elevenlabs");
4550
4571
  }
4572
+ provider = "elevenlabs";
4551
4573
  get modelName() {
4552
4574
  return this.settings.voice;
4553
4575
  }
@@ -4778,19 +4800,18 @@ import { z as z9 } from "zod";
4778
4800
  var HuggingFaceTextEmbeddingModel = class _HuggingFaceTextEmbeddingModel extends AbstractModel {
4779
4801
  constructor(settings) {
4780
4802
  super({ settings });
4781
- __publicField(this, "provider", "huggingface");
4782
- __publicField(this, "maxValuesPerCall");
4783
- __publicField(this, "isParallelizable", true);
4784
- __publicField(this, "contextWindowSize");
4785
- __publicField(this, "dimensions");
4786
- __publicField(this, "tokenizer");
4787
- __publicField(this, "countPromptTokens");
4788
4803
  this.maxValuesPerCall = settings.maxValuesPerCall ?? 1024;
4789
4804
  this.dimensions = settings.dimensions;
4790
4805
  }
4806
+ provider = "huggingface";
4791
4807
  get modelName() {
4792
4808
  return this.settings.model;
4793
4809
  }
4810
+ maxValuesPerCall;
4811
+ isParallelizable = true;
4812
+ contextWindowSize = void 0;
4813
+ dimensions;
4814
+ tokenizer = void 0;
4794
4815
  async callAPI(texts, callOptions) {
4795
4816
  if (texts.length > this.maxValuesPerCall) {
4796
4817
  throw new Error(
@@ -4831,6 +4852,7 @@ var HuggingFaceTextEmbeddingModel = class _HuggingFaceTextEmbeddingModel extends
4831
4852
  options: this.settings.options
4832
4853
  };
4833
4854
  }
4855
+ countPromptTokens = void 0;
4834
4856
  async doEmbedValues(texts, options) {
4835
4857
  const rawResponse = await this.callAPI(texts, options);
4836
4858
  return {
@@ -4851,14 +4873,14 @@ import { z as z10 } from "zod";
4851
4873
  var HuggingFaceTextGenerationModel = class _HuggingFaceTextGenerationModel extends AbstractModel {
4852
4874
  constructor(settings) {
4853
4875
  super({ settings });
4854
- __publicField(this, "provider", "huggingface");
4855
- __publicField(this, "contextWindowSize");
4856
- __publicField(this, "tokenizer");
4857
- __publicField(this, "countPromptTokens");
4858
4876
  }
4877
+ provider = "huggingface";
4859
4878
  get modelName() {
4860
4879
  return this.settings.model;
4861
4880
  }
4881
+ contextWindowSize = void 0;
4882
+ tokenizer = void 0;
4883
+ countPromptTokens = void 0;
4862
4884
  async callAPI(prompt, callOptions) {
4863
4885
  const api = this.settings.api ?? new HuggingFaceApiConfiguration();
4864
4886
  const abortSignal = callOptions?.run?.abortSignal;
@@ -5204,8 +5226,8 @@ var BakLLaVA1 = LlamaCppBakLLaVA1PromptTemplate_exports;
5204
5226
  // src/model-provider/llamacpp/LlamaCppTokenizer.ts
5205
5227
  import { z as z12 } from "zod";
5206
5228
  var LlamaCppTokenizer = class {
5229
+ api;
5207
5230
  constructor(api = new LlamaCppApiConfiguration()) {
5208
- __publicField(this, "api");
5209
5231
  this.api = api;
5210
5232
  }
5211
5233
  async callTokenizeAPI(text13, callOptions) {
@@ -5258,9 +5280,7 @@ var PRIMITIVE_RULES = {
5258
5280
  null: '"null" space'
5259
5281
  };
5260
5282
  var RuleMap = class {
5261
- constructor() {
5262
- __publicField(this, "rules", /* @__PURE__ */ new Map());
5263
- }
5283
+ rules = /* @__PURE__ */ new Map();
5264
5284
  add(name, rule) {
5265
5285
  const escapedName = this.escapeRuleName(name, rule);
5266
5286
  this.rules.set(escapedName, rule);
@@ -5352,16 +5372,16 @@ function visit(schema, name, rules) {
5352
5372
  var LlamaCppCompletionModel = class _LlamaCppCompletionModel extends AbstractModel {
5353
5373
  constructor(settings = {}) {
5354
5374
  super({ settings });
5355
- __publicField(this, "provider", "llamacpp");
5356
- __publicField(this, "tokenizer");
5357
5375
  this.tokenizer = new LlamaCppTokenizer(this.settings.api);
5358
5376
  }
5377
+ provider = "llamacpp";
5359
5378
  get modelName() {
5360
5379
  return null;
5361
5380
  }
5362
5381
  get contextWindowSize() {
5363
5382
  return this.settings.contextWindowSize;
5364
5383
  }
5384
+ tokenizer;
5365
5385
  async callAPI(prompt, callOptions, options) {
5366
5386
  const api = this.settings.api ?? new LlamaCppApiConfiguration();
5367
5387
  const responseFormat = options.responseFormat;
@@ -5661,21 +5681,21 @@ import { z as z14 } from "zod";
5661
5681
  var LlamaCppTextEmbeddingModel = class _LlamaCppTextEmbeddingModel extends AbstractModel {
5662
5682
  constructor(settings = {}) {
5663
5683
  super({ settings });
5664
- __publicField(this, "provider", "llamacpp");
5665
- __publicField(this, "maxValuesPerCall", 1);
5666
- __publicField(this, "contextWindowSize");
5667
- __publicField(this, "tokenizer");
5668
5684
  this.tokenizer = new LlamaCppTokenizer(this.settings.api);
5669
5685
  }
5686
+ provider = "llamacpp";
5670
5687
  get modelName() {
5671
5688
  return null;
5672
5689
  }
5690
+ maxValuesPerCall = 1;
5673
5691
  get isParallelizable() {
5674
5692
  return this.settings.isParallelizable ?? false;
5675
5693
  }
5694
+ contextWindowSize = void 0;
5676
5695
  get dimensions() {
5677
5696
  return this.settings.dimensions;
5678
5697
  }
5698
+ tokenizer;
5679
5699
  async tokenize(text13) {
5680
5700
  return this.tokenizer.tokenize(text13);
5681
5701
  }
@@ -5858,8 +5878,8 @@ import { z as z15 } from "zod";
5858
5878
  var LmntSpeechModel = class _LmntSpeechModel extends AbstractModel {
5859
5879
  constructor(settings) {
5860
5880
  super({ settings });
5861
- __publicField(this, "provider", "lmnt");
5862
5881
  }
5882
+ provider = "lmnt";
5863
5883
  get modelName() {
5864
5884
  return this.settings.voice;
5865
5885
  }
@@ -6103,14 +6123,14 @@ var failedMistralCallResponseHandler = createJsonErrorResponseHandler({
6103
6123
  var MistralChatModel = class _MistralChatModel extends AbstractModel {
6104
6124
  constructor(settings) {
6105
6125
  super({ settings });
6106
- __publicField(this, "provider", "mistral");
6107
- __publicField(this, "contextWindowSize");
6108
- __publicField(this, "tokenizer");
6109
- __publicField(this, "countPromptTokens");
6110
6126
  }
6127
+ provider = "mistral";
6111
6128
  get modelName() {
6112
6129
  return this.settings.model;
6113
6130
  }
6131
+ contextWindowSize = void 0;
6132
+ tokenizer = void 0;
6133
+ countPromptTokens = void 0;
6114
6134
  async callAPI(prompt, callOptions, options) {
6115
6135
  const api = this.settings.api ?? new MistralApiConfiguration();
6116
6136
  const abortSignal = callOptions.run?.abortSignal;
@@ -6295,18 +6315,18 @@ import { z as z18 } from "zod";
6295
6315
  var MistralTextEmbeddingModel = class _MistralTextEmbeddingModel extends AbstractModel {
6296
6316
  constructor(settings) {
6297
6317
  super({ settings });
6298
- __publicField(this, "provider", "mistral");
6299
- __publicField(this, "maxValuesPerCall", 32);
6300
- /**
6301
- * Parallel calls are technically possible, but I have been hitting rate limits and disabled
6302
- * them for now.
6303
- */
6304
- __publicField(this, "isParallelizable", false);
6305
- __publicField(this, "dimensions", 1024);
6306
6318
  }
6319
+ provider = "mistral";
6307
6320
  get modelName() {
6308
6321
  return this.settings.model;
6309
6322
  }
6323
+ maxValuesPerCall = 32;
6324
+ /**
6325
+ * Parallel calls are technically possible, but I have been hitting rate limits and disabled
6326
+ * them for now.
6327
+ */
6328
+ isParallelizable = false;
6329
+ dimensions = 1024;
6310
6330
  async callAPI(texts, callOptions) {
6311
6331
  if (texts.length > this.maxValuesPerCall) {
6312
6332
  throw new Error(
@@ -6501,14 +6521,14 @@ var failedOllamaCallResponseHandler = createJsonErrorResponseHandler({
6501
6521
  var OllamaChatModel = class _OllamaChatModel extends AbstractModel {
6502
6522
  constructor(settings) {
6503
6523
  super({ settings });
6504
- __publicField(this, "provider", "ollama");
6505
- __publicField(this, "tokenizer");
6506
- __publicField(this, "countPromptTokens");
6507
- __publicField(this, "contextWindowSize");
6508
6524
  }
6525
+ provider = "ollama";
6509
6526
  get modelName() {
6510
6527
  return this.settings.model;
6511
6528
  }
6529
+ tokenizer = void 0;
6530
+ countPromptTokens = void 0;
6531
+ contextWindowSize = void 0;
6512
6532
  async callAPI(prompt, callOptions, options) {
6513
6533
  const { responseFormat } = options;
6514
6534
  const api = this.settings.api ?? new OllamaApiConfiguration();
@@ -6617,7 +6637,7 @@ var OllamaChatModel = class _OllamaChatModel extends AbstractModel {
6617
6637
  asToolCallGenerationModel(promptTemplate) {
6618
6638
  return new TextGenerationToolCallModel({
6619
6639
  model: this,
6620
- format: promptTemplate
6640
+ template: promptTemplate
6621
6641
  });
6622
6642
  }
6623
6643
  asToolCallsOrTextGenerationModel(promptTemplate) {
@@ -6802,13 +6822,13 @@ var Vicuna2 = asOllamaCompletionTextPromptTemplateProvider(VicunaPromptTemplate_
6802
6822
  var OllamaCompletionModel = class _OllamaCompletionModel extends AbstractModel {
6803
6823
  constructor(settings) {
6804
6824
  super({ settings });
6805
- __publicField(this, "provider", "ollama");
6806
- __publicField(this, "tokenizer");
6807
- __publicField(this, "countPromptTokens");
6808
6825
  }
6826
+ provider = "ollama";
6809
6827
  get modelName() {
6810
6828
  return this.settings.model;
6811
6829
  }
6830
+ tokenizer = void 0;
6831
+ countPromptTokens = void 0;
6812
6832
  get contextWindowSize() {
6813
6833
  return this.settings.contextWindowSize;
6814
6834
  }
@@ -6939,7 +6959,7 @@ var OllamaCompletionModel = class _OllamaCompletionModel extends AbstractModel {
6939
6959
  asToolCallGenerationModel(promptTemplate) {
6940
6960
  return new TextGenerationToolCallModel({
6941
6961
  model: this,
6942
- format: promptTemplate
6962
+ template: promptTemplate
6943
6963
  });
6944
6964
  }
6945
6965
  asToolCallsOrTextGenerationModel(promptTemplate) {
@@ -7087,12 +7107,12 @@ import { z as z22 } from "zod";
7087
7107
  var OllamaTextEmbeddingModel = class _OllamaTextEmbeddingModel extends AbstractModel {
7088
7108
  constructor(settings) {
7089
7109
  super({ settings });
7090
- __publicField(this, "provider", "ollama");
7091
- __publicField(this, "maxValuesPerCall", 1);
7092
7110
  }
7111
+ provider = "ollama";
7093
7112
  get modelName() {
7094
7113
  return null;
7095
7114
  }
7115
+ maxValuesPerCall = 1;
7096
7116
  get isParallelizable() {
7097
7117
  return this.settings.isParallelizable ?? false;
7098
7118
  }
@@ -7653,11 +7673,11 @@ import { z as z26 } from "zod";
7653
7673
  var AbstractOpenAITextEmbeddingModel = class extends AbstractModel {
7654
7674
  constructor(settings) {
7655
7675
  super({ settings });
7656
- __publicField(this, "isParallelizable", true);
7657
7676
  }
7658
7677
  get maxValuesPerCall() {
7659
7678
  return this.settings.maxValuesPerCall ?? 2048;
7660
7679
  }
7680
+ isParallelizable = true;
7661
7681
  async callAPI(texts, callOptions) {
7662
7682
  const api = this.settings.api ?? new OpenAIApiConfiguration();
7663
7683
  const abortSignal = callOptions.run?.abortSignal;
@@ -7718,6 +7738,10 @@ var openAITextEmbeddingResponseSchema = z26.object({
7718
7738
 
7719
7739
  // src/model-provider/openai/AzureOpenAIApiConfiguration.ts
7720
7740
  var AzureOpenAIApiConfiguration = class extends AbstractApiConfiguration {
7741
+ resourceName;
7742
+ deploymentId;
7743
+ apiVersion;
7744
+ fixedHeaderValue;
7721
7745
  constructor({
7722
7746
  resourceName,
7723
7747
  deploymentId,
@@ -7727,10 +7751,6 @@ var AzureOpenAIApiConfiguration = class extends AbstractApiConfiguration {
7727
7751
  throttle
7728
7752
  }) {
7729
7753
  super({ retry, throttle });
7730
- __publicField(this, "resourceName");
7731
- __publicField(this, "deploymentId");
7732
- __publicField(this, "apiVersion");
7733
- __publicField(this, "fixedHeaderValue");
7734
7754
  this.resourceName = resourceName;
7735
7755
  this.deploymentId = deploymentId;
7736
7756
  this.apiVersion = apiVersion;
@@ -7929,16 +7949,16 @@ function chat12() {
7929
7949
 
7930
7950
  // src/model-provider/openai/OpenAIChatFunctionCallObjectGenerationModel.ts
7931
7951
  var OpenAIChatFunctionCallObjectGenerationModel = class _OpenAIChatFunctionCallObjectGenerationModel {
7952
+ model;
7953
+ fnName;
7954
+ fnDescription;
7955
+ promptTemplate;
7932
7956
  constructor({
7933
7957
  model,
7934
7958
  fnName,
7935
7959
  fnDescription,
7936
7960
  promptTemplate
7937
7961
  }) {
7938
- __publicField(this, "model");
7939
- __publicField(this, "fnName");
7940
- __publicField(this, "fnDescription");
7941
- __publicField(this, "promptTemplate");
7942
7962
  this.model = model;
7943
7963
  this.fnName = fnName;
7944
7964
  this.fnDescription = fnDescription;
@@ -8080,9 +8100,9 @@ var TikTokenTokenizer = class {
8080
8100
  * Get a TikToken tokenizer for a specific model or encoding.
8081
8101
  */
8082
8102
  constructor(settings) {
8083
- __publicField(this, "tiktoken");
8084
8103
  this.tiktoken = new Tiktoken(getTiktokenBPE(settings.model));
8085
8104
  }
8105
+ tiktoken;
8086
8106
  async tokenize(text13) {
8087
8107
  return this.tiktoken.encode(text13);
8088
8108
  }
@@ -8296,18 +8316,18 @@ var calculateOpenAIChatCostInMillicents = ({
8296
8316
  var OpenAIChatModel = class _OpenAIChatModel extends AbstractOpenAIChatModel {
8297
8317
  constructor(settings) {
8298
8318
  super(settings);
8299
- __publicField(this, "provider", "openai");
8300
- __publicField(this, "contextWindowSize");
8301
- __publicField(this, "tokenizer");
8302
8319
  const modelInformation = getOpenAIChatModelInformation(this.settings.model);
8303
8320
  this.tokenizer = new TikTokenTokenizer({
8304
8321
  model: modelInformation.baseModel
8305
8322
  });
8306
8323
  this.contextWindowSize = modelInformation.contextWindowSize;
8307
8324
  }
8325
+ provider = "openai";
8308
8326
  get modelName() {
8309
8327
  return this.settings.model;
8310
8328
  }
8329
+ contextWindowSize;
8330
+ tokenizer;
8311
8331
  /**
8312
8332
  * Counts the prompt tokens required for the messages. This includes the message base tokens
8313
8333
  * and the prompt base tokens.
@@ -8409,9 +8429,6 @@ var calculateOpenAICompletionCostInMillicents = ({
8409
8429
  var OpenAICompletionModel = class _OpenAICompletionModel extends AbstractOpenAICompletionModel {
8410
8430
  constructor(settings) {
8411
8431
  super(settings);
8412
- __publicField(this, "provider", "openai");
8413
- __publicField(this, "contextWindowSize");
8414
- __publicField(this, "tokenizer");
8415
8432
  const modelInformation = getOpenAICompletionModelInformation(
8416
8433
  this.settings.model
8417
8434
  );
@@ -8420,9 +8437,12 @@ var OpenAICompletionModel = class _OpenAICompletionModel extends AbstractOpenAIC
8420
8437
  });
8421
8438
  this.contextWindowSize = modelInformation.contextWindowSize;
8422
8439
  }
8440
+ provider = "openai";
8423
8441
  get modelName() {
8424
8442
  return this.settings.model;
8425
8443
  }
8444
+ contextWindowSize;
8445
+ tokenizer;
8426
8446
  async countPromptTokens(input) {
8427
8447
  return countTokens(this.tokenizer, input);
8428
8448
  }
@@ -8547,8 +8567,8 @@ var calculateOpenAIImageGenerationCostInMillicents = ({
8547
8567
  var OpenAIImageGenerationModel = class _OpenAIImageGenerationModel extends AbstractModel {
8548
8568
  constructor(settings) {
8549
8569
  super({ settings });
8550
- __publicField(this, "provider", "openai");
8551
8570
  }
8571
+ provider = "openai";
8552
8572
  get modelName() {
8553
8573
  return this.settings.model;
8554
8574
  }
@@ -8669,8 +8689,8 @@ var calculateOpenAISpeechCostInMillicents = ({
8669
8689
  var OpenAISpeechModel = class _OpenAISpeechModel extends AbstractModel {
8670
8690
  constructor(settings) {
8671
8691
  super({ settings });
8672
- __publicField(this, "provider", "openai");
8673
8692
  }
8693
+ provider = "openai";
8674
8694
  get voice() {
8675
8695
  return this.settings.voice;
8676
8696
  }
@@ -8755,17 +8775,17 @@ var calculateOpenAIEmbeddingCostInMillicents = ({
8755
8775
  var OpenAITextEmbeddingModel = class _OpenAITextEmbeddingModel extends AbstractOpenAITextEmbeddingModel {
8756
8776
  constructor(settings) {
8757
8777
  super(settings);
8758
- __publicField(this, "provider", "openai");
8759
- __publicField(this, "dimensions");
8760
- __publicField(this, "tokenizer");
8761
- __publicField(this, "contextWindowSize");
8762
8778
  this.tokenizer = new TikTokenTokenizer({ model: this.modelName });
8763
8779
  this.contextWindowSize = OPENAI_TEXT_EMBEDDING_MODELS[this.modelName].contextWindowSize;
8764
8780
  this.dimensions = this.settings.dimensions ?? OPENAI_TEXT_EMBEDDING_MODELS[this.modelName].dimensions;
8765
8781
  }
8782
+ provider = "openai";
8766
8783
  get modelName() {
8767
8784
  return this.settings.model;
8768
8785
  }
8786
+ dimensions;
8787
+ tokenizer;
8788
+ contextWindowSize;
8769
8789
  async countTokens(input) {
8770
8790
  return countTokens(this.tokenizer, input);
8771
8791
  }
@@ -8829,8 +8849,8 @@ var calculateOpenAITranscriptionCostInMillicents = ({
8829
8849
  var OpenAITranscriptionModel = class _OpenAITranscriptionModel extends AbstractModel {
8830
8850
  constructor(settings) {
8831
8851
  super({ settings });
8832
- __publicField(this, "provider", "openai");
8833
8852
  }
8853
+ provider = "openai";
8834
8854
  get modelName() {
8835
8855
  return this.settings.model;
8836
8856
  }
@@ -9010,17 +9030,14 @@ var FireworksAIApiConfiguration = class extends BaseUrlApiConfigurationWithDefau
9010
9030
  path: "/inference/v1"
9011
9031
  }
9012
9032
  });
9013
- __publicField(this, "provider", "openaicompatible-fireworksai");
9014
9033
  }
9034
+ provider = "openaicompatible-fireworksai";
9015
9035
  };
9016
9036
 
9017
9037
  // src/model-provider/openai-compatible/OpenAICompatibleChatModel.ts
9018
9038
  var OpenAICompatibleChatModel = class _OpenAICompatibleChatModel extends AbstractOpenAIChatModel {
9019
9039
  constructor(settings) {
9020
9040
  super(settings);
9021
- __publicField(this, "contextWindowSize");
9022
- __publicField(this, "tokenizer");
9023
- __publicField(this, "countPromptTokens");
9024
9041
  }
9025
9042
  get provider() {
9026
9043
  return this.settings.provider ?? this.settings.api.provider ?? "openaicompatible";
@@ -9028,6 +9045,9 @@ var OpenAICompatibleChatModel = class _OpenAICompatibleChatModel extends Abstrac
9028
9045
  get modelName() {
9029
9046
  return this.settings.model;
9030
9047
  }
9048
+ contextWindowSize = void 0;
9049
+ tokenizer = void 0;
9050
+ countPromptTokens = void 0;
9031
9051
  get settingsForEvent() {
9032
9052
  const eventSettingProperties = [
9033
9053
  ...textGenerationModelProperties,
@@ -9090,9 +9110,6 @@ var OpenAICompatibleChatModel = class _OpenAICompatibleChatModel extends Abstrac
9090
9110
  var OpenAICompatibleCompletionModel = class _OpenAICompatibleCompletionModel extends AbstractOpenAICompletionModel {
9091
9111
  constructor(settings) {
9092
9112
  super(settings);
9093
- __publicField(this, "contextWindowSize");
9094
- __publicField(this, "tokenizer");
9095
- __publicField(this, "countPromptTokens");
9096
9113
  }
9097
9114
  get provider() {
9098
9115
  return this.settings.provider ?? this.settings.api.provider ?? "openaicompatible";
@@ -9100,6 +9117,9 @@ var OpenAICompatibleCompletionModel = class _OpenAICompatibleCompletionModel ext
9100
9117
  get modelName() {
9101
9118
  return this.settings.model;
9102
9119
  }
9120
+ contextWindowSize = void 0;
9121
+ tokenizer = void 0;
9122
+ countPromptTokens = void 0;
9103
9123
  get settingsForEvent() {
9104
9124
  const eventSettingProperties = [
9105
9125
  ...textGenerationModelProperties,
@@ -9203,8 +9223,8 @@ var PerplexityApiConfiguration = class extends BaseUrlApiConfigurationWithDefaul
9203
9223
  path: ""
9204
9224
  }
9205
9225
  });
9206
- __publicField(this, "provider", "openaicompatible-perplexity");
9207
9226
  }
9227
+ provider = "openaicompatible-perplexity";
9208
9228
  };
9209
9229
 
9210
9230
  // src/model-provider/openai-compatible/TogetherAIApiConfiguration.ts
@@ -9226,8 +9246,8 @@ var TogetherAIApiConfiguration = class extends BaseUrlApiConfigurationWithDefaul
9226
9246
  path: "/v1"
9227
9247
  }
9228
9248
  });
9229
- __publicField(this, "provider", "openaicompatible-togetherai");
9230
9249
  }
9250
+ provider = "openaicompatible-togetherai";
9231
9251
  };
9232
9252
 
9233
9253
  // src/model-provider/openai-compatible/OpenAICompatibleFacade.ts
@@ -9303,8 +9323,8 @@ function mapBasicPromptToStabilityFormat() {
9303
9323
  var StabilityImageGenerationModel = class _StabilityImageGenerationModel extends AbstractModel {
9304
9324
  constructor(settings) {
9305
9325
  super({ settings });
9306
- __publicField(this, "provider", "stability");
9307
9326
  }
9327
+ provider = "stability";
9308
9328
  get modelName() {
9309
9329
  return this.settings.model;
9310
9330
  }
@@ -9424,9 +9444,9 @@ import { z as z31 } from "zod";
9424
9444
  var WhisperCppTranscriptionModel = class _WhisperCppTranscriptionModel extends AbstractModel {
9425
9445
  constructor(settings) {
9426
9446
  super({ settings });
9427
- __publicField(this, "provider", "whispercpp");
9428
- __publicField(this, "modelName", null);
9429
9447
  }
9448
+ provider = "whispercpp";
9449
+ modelName = null;
9430
9450
  async doTranscribe({
9431
9451
  audioData,
9432
9452
  mimeType
@@ -9652,6 +9672,9 @@ async function splitTextChunk(splitFunction, input) {
9652
9672
 
9653
9673
  // src/tool/NoSuchToolDefinitionError.ts
9654
9674
  var NoSuchToolDefinitionError = class extends Error {
9675
+ toolName;
9676
+ cause;
9677
+ parameters;
9655
9678
  constructor({
9656
9679
  toolName,
9657
9680
  parameters
@@ -9659,9 +9682,6 @@ var NoSuchToolDefinitionError = class extends Error {
9659
9682
  super(
9660
9683
  `Tool definition '${toolName}' not found. Parameters: ${JSON.stringify(parameters)}.`
9661
9684
  );
9662
- __publicField(this, "toolName");
9663
- __publicField(this, "cause");
9664
- __publicField(this, "parameters");
9665
9685
  this.name = "NoSuchToolDefinitionError";
9666
9686
  this.toolName = toolName;
9667
9687
  this.parameters = parameters;
@@ -9680,6 +9700,28 @@ var NoSuchToolDefinitionError = class extends Error {
9680
9700
 
9681
9701
  // src/tool/Tool.ts
9682
9702
  var Tool = class {
9703
+ /**
9704
+ * The name of the tool.
9705
+ * Should be understandable for language models and unique among the tools that they know.
9706
+ */
9707
+ name;
9708
+ /**
9709
+ * A optional description of what the tool does. Will be used by the language model to decide whether to use the tool.
9710
+ */
9711
+ description;
9712
+ /**
9713
+ * The schema of the input that the tool expects. The language model will use this to generate the input.
9714
+ * Use descriptions to make the input understandable for the language model.
9715
+ */
9716
+ parameters;
9717
+ /**
9718
+ * An optional schema of the output that the tool produces. This will be used to validate the output.
9719
+ */
9720
+ returnType;
9721
+ /**
9722
+ * The actual execution function of the tool.
9723
+ */
9724
+ execute;
9683
9725
  constructor({
9684
9726
  name,
9685
9727
  description,
@@ -9687,28 +9729,6 @@ var Tool = class {
9687
9729
  returnType,
9688
9730
  execute
9689
9731
  }) {
9690
- /**
9691
- * The name of the tool.
9692
- * Should be understandable for language models and unique among the tools that they know.
9693
- */
9694
- __publicField(this, "name");
9695
- /**
9696
- * A description of what the tool does. Will be used by the language model to decide whether to use the tool.
9697
- */
9698
- __publicField(this, "description");
9699
- /**
9700
- * The schema of the input that the tool expects. The language model will use this to generate the input.
9701
- * Use descriptions to make the input understandable for the language model.
9702
- */
9703
- __publicField(this, "parameters");
9704
- /**
9705
- * An optional schema of the output that the tool produces. This will be used to validate the output.
9706
- */
9707
- __publicField(this, "returnType");
9708
- /**
9709
- * The actual execution function of the tool.
9710
- */
9711
- __publicField(this, "execute");
9712
9732
  this.name = name;
9713
9733
  this.description = description;
9714
9734
  this.parameters = parameters;
@@ -9717,8 +9737,36 @@ var Tool = class {
9717
9737
  }
9718
9738
  };
9719
9739
 
9740
+ // src/tool/ObjectGeneratorTool.ts
9741
+ var ObjectGeneratorTool = class extends Tool {
9742
+ constructor({
9743
+ name = "object-generator",
9744
+ // eslint-disable-line @typescript-eslint/no-explicit-any
9745
+ description,
9746
+ model,
9747
+ parameters,
9748
+ objectSchema,
9749
+ prompt
9750
+ }) {
9751
+ super({
9752
+ name,
9753
+ description,
9754
+ parameters,
9755
+ execute: async (input, options) => generateObject({
9756
+ model,
9757
+ schema: objectSchema,
9758
+ prompt: prompt(input),
9759
+ ...options
9760
+ })
9761
+ });
9762
+ }
9763
+ };
9764
+
9720
9765
  // src/tool/ToolCallArgumentsValidationError.ts
9721
9766
  var ToolCallArgumentsValidationError = class extends Error {
9767
+ toolName;
9768
+ cause;
9769
+ args;
9722
9770
  constructor({
9723
9771
  toolName,
9724
9772
  args,
@@ -9729,9 +9777,6 @@ var ToolCallArgumentsValidationError = class extends Error {
9729
9777
  Arguments: ${JSON.stringify(args)}.
9730
9778
  Error message: ${getErrorMessage(cause)}`
9731
9779
  );
9732
- __publicField(this, "toolName");
9733
- __publicField(this, "cause");
9734
- __publicField(this, "args");
9735
9780
  this.name = "ToolCallArgumentsValidationError";
9736
9781
  this.toolName = toolName;
9737
9782
  this.cause = cause;
@@ -9751,14 +9796,14 @@ Error message: ${getErrorMessage(cause)}`
9751
9796
 
9752
9797
  // src/tool/ToolCallError.ts
9753
9798
  var ToolCallError = class extends Error {
9799
+ toolCall;
9800
+ cause;
9754
9801
  constructor({
9755
9802
  cause,
9756
9803
  toolCall,
9757
9804
  message = getErrorMessage(cause)
9758
9805
  }) {
9759
9806
  super(`Tool call for tool '${toolCall.name}' failed: ${message}`);
9760
- __publicField(this, "toolCall");
9761
- __publicField(this, "cause");
9762
9807
  this.name = "ToolCallError";
9763
9808
  this.toolCall = toolCall;
9764
9809
  this.cause = cause;
@@ -9776,12 +9821,12 @@ var ToolCallError = class extends Error {
9776
9821
 
9777
9822
  // src/tool/ToolCallGenerationError.ts
9778
9823
  var ToolCallGenerationError = class extends Error {
9824
+ toolName;
9825
+ cause;
9779
9826
  constructor({ toolName, cause }) {
9780
9827
  super(
9781
9828
  `Tool call generation failed for tool '${toolName}'. Error message: ${getErrorMessage(cause)}`
9782
9829
  );
9783
- __publicField(this, "toolName");
9784
- __publicField(this, "cause");
9785
9830
  this.name = "ToolCallsGenerationError";
9786
9831
  this.toolName = toolName;
9787
9832
  this.cause = cause;
@@ -9799,6 +9844,9 @@ var ToolCallGenerationError = class extends Error {
9799
9844
 
9800
9845
  // src/tool/ToolExecutionError.ts
9801
9846
  var ToolExecutionError = class extends Error {
9847
+ toolName;
9848
+ input;
9849
+ cause;
9802
9850
  constructor({
9803
9851
  toolName,
9804
9852
  input,
@@ -9806,9 +9854,6 @@ var ToolExecutionError = class extends Error {
9806
9854
  message = getErrorMessage(cause)
9807
9855
  }) {
9808
9856
  super(`Error executing tool '${toolName}': ${message}`);
9809
- __publicField(this, "toolName");
9810
- __publicField(this, "input");
9811
- __publicField(this, "cause");
9812
9857
  this.name = "ToolExecutionError";
9813
9858
  this.toolName = toolName;
9814
9859
  this.input = input;
@@ -10030,29 +10075,63 @@ async function generateToolCall({
10030
10075
 
10031
10076
  // src/tool/generate-tool-call/jsonToolCallPrompt.ts
10032
10077
  import { nanoid } from "nanoid";
10078
+ var DEFAULT_TOOL_PROMPT = (tool) => [
10079
+ `You are calling the function "${tool.name}".`,
10080
+ tool.description != null ? `Function description: ${tool.description}` : null,
10081
+ `Function parameters JSON schema: ${JSON.stringify(
10082
+ tool.parameters.getJsonSchema()
10083
+ )}`,
10084
+ ``,
10085
+ `You MUST answer with a JSON object that matches the JSON schema above.`
10086
+ ].filter(Boolean).join("\n");
10033
10087
  var jsonToolCallPrompt = {
10034
- text() {
10088
+ text({
10089
+ toolPrompt
10090
+ } = {}) {
10035
10091
  return {
10036
- createPrompt(instruction13, tool) {
10092
+ createPrompt(prompt, tool) {
10037
10093
  return {
10038
- system: [
10039
- `You are calling a function "${tool.name}".`,
10040
- tool.description != null ? ` Function description: ${tool.description}` : null,
10041
- ` Function parameters JSON schema: ${JSON.stringify(
10042
- tool.parameters.getJsonSchema()
10043
- )}`,
10044
- ``,
10045
- `You MUST answer with a JSON object matches the above schema for the arguments.`
10046
- ].filter(Boolean).join("\n"),
10047
- instruction: instruction13
10094
+ system: createSystemPrompt2({ tool, toolPrompt }),
10095
+ instruction: prompt
10048
10096
  };
10049
10097
  },
10050
- extractToolCall(response) {
10051
- return { id: nanoid(), args: parseJSON({ text: response }) };
10052
- }
10098
+ extractToolCall,
10099
+ withJsonOutput: ({ model, schema }) => model.withJsonOutput(schema)
10100
+ };
10101
+ },
10102
+ instruction({
10103
+ toolPrompt
10104
+ } = {}) {
10105
+ return {
10106
+ createPrompt(prompt, tool) {
10107
+ return {
10108
+ system: createSystemPrompt2({
10109
+ originalSystemPrompt: prompt.system,
10110
+ tool,
10111
+ toolPrompt
10112
+ }),
10113
+ instruction: prompt.instruction
10114
+ };
10115
+ },
10116
+ extractToolCall,
10117
+ withJsonOutput: ({ model, schema }) => model.withJsonOutput(schema)
10053
10118
  };
10054
10119
  }
10055
10120
  };
10121
+ function createSystemPrompt2({
10122
+ originalSystemPrompt,
10123
+ toolPrompt = DEFAULT_TOOL_PROMPT,
10124
+ tool
10125
+ }) {
10126
+ return [
10127
+ originalSystemPrompt,
10128
+ originalSystemPrompt != null ? "" : null,
10129
+ toolPrompt(tool)
10130
+ ].filter(Boolean).join("\n");
10131
+ }
10132
+ function extractToolCall(response) {
10133
+ return { id: nanoid(), args: parseJSON({ text: response }) };
10134
+ }
10056
10135
 
10057
10136
  // src/tool/generate-tool-calls/generateToolCalls.ts
10058
10137
  async function generateToolCalls({
@@ -10240,6 +10319,9 @@ function createEventSourceStream(events) {
10240
10319
 
10241
10320
  // src/vector-index/VectorIndexRetriever.ts
10242
10321
  var VectorIndexRetriever = class _VectorIndexRetriever {
10322
+ vectorIndex;
10323
+ embeddingModel;
10324
+ settings;
10243
10325
  constructor({
10244
10326
  vectorIndex,
10245
10327
  embeddingModel,
@@ -10247,9 +10329,6 @@ var VectorIndexRetriever = class _VectorIndexRetriever {
10247
10329
  similarityThreshold,
10248
10330
  filter
10249
10331
  }) {
10250
- __publicField(this, "vectorIndex");
10251
- __publicField(this, "embeddingModel");
10252
- __publicField(this, "settings");
10253
10332
  this.vectorIndex = vectorIndex;
10254
10333
  this.embeddingModel = embeddingModel;
10255
10334
  this.settings = {
@@ -10294,9 +10373,6 @@ var jsonDataSchema = zodSchema(
10294
10373
  )
10295
10374
  );
10296
10375
  var MemoryVectorIndex = class _MemoryVectorIndex {
10297
- constructor() {
10298
- __publicField(this, "entries", /* @__PURE__ */ new Map());
10299
- }
10300
10376
  static async deserialize({
10301
10377
  serializedData,
10302
10378
  schema
@@ -10316,6 +10392,7 @@ var MemoryVectorIndex = class _MemoryVectorIndex {
10316
10392
  );
10317
10393
  return vectorIndex;
10318
10394
  }
10395
+ entries = /* @__PURE__ */ new Map();
10319
10396
  async upsertMany(data) {
10320
10397
  for (const entry of data) {
10321
10398
  this.entries.set(entry.id, entry);
@@ -10437,6 +10514,7 @@ export {
10437
10514
  OPENAI_TRANSCRIPTION_MODELS,
10438
10515
  ObjectFromTextGenerationModel,
10439
10516
  ObjectFromTextStreamingModel,
10517
+ ObjectGeneratorTool,
10440
10518
  ObjectParseError,
10441
10519
  ObjectStreamFromResponse,
10442
10520
  ObjectStreamResponse,