@jterrazz/intelligence 1.6.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +199 -83
  2. package/dist/adapters/agents/{basic-agent.adapter.d.ts → chat-agent.adapter.d.ts} +6 -6
  3. package/dist/adapters/agents/{basic-agent.adapter.js → chat-agent.adapter.js} +37 -20
  4. package/dist/adapters/agents/chat-agent.adapter.js.map +1 -0
  5. package/dist/adapters/agents/{retryable-agent.adapter.d.ts → resilient-agent.adapter.d.ts} +4 -4
  6. package/dist/adapters/agents/{retryable-agent.adapter.js → resilient-agent.adapter.js} +8 -8
  7. package/dist/adapters/agents/resilient-agent.adapter.js.map +1 -0
  8. package/dist/adapters/agents/{autonomous-agent.adapter.d.ts → tool-agent.adapter.d.ts} +6 -6
  9. package/dist/adapters/agents/{autonomous-agent.adapter.js → tool-agent.adapter.js} +10 -10
  10. package/dist/adapters/agents/tool-agent.adapter.js.map +1 -0
  11. package/dist/adapters/models/openrouter-model.adapter.d.ts +17 -32
  12. package/dist/adapters/models/openrouter-model.adapter.js +84 -25
  13. package/dist/adapters/models/openrouter-model.adapter.js.map +1 -1
  14. package/dist/adapters/prompts/__tests__/presets.test.js +4 -4
  15. package/dist/adapters/prompts/__tests__/presets.test.js.map +1 -1
  16. package/dist/adapters/prompts/system-prompt.adapter.d.ts +2 -2
  17. package/dist/adapters/prompts/system-prompt.adapter.js +6 -6
  18. package/dist/adapters/prompts/system-prompt.adapter.js.map +1 -1
  19. package/dist/adapters/prompts/user-prompt.adapter.d.ts +2 -2
  20. package/dist/adapters/prompts/user-prompt.adapter.js +6 -6
  21. package/dist/adapters/prompts/user-prompt.adapter.js.map +1 -1
  22. package/dist/adapters/providers/openrouter-provider.adapter.d.ts +34 -0
  23. package/dist/adapters/providers/openrouter-provider.adapter.js +57 -0
  24. package/dist/adapters/providers/openrouter-provider.adapter.js.map +1 -0
  25. package/dist/adapters/tools/safe-tool.adapter.d.ts +2 -2
  26. package/dist/adapters/tools/safe-tool.adapter.js +6 -6
  27. package/dist/adapters/tools/safe-tool.adapter.js.map +1 -1
  28. package/dist/adapters/utils/__tests__/{ai-response-parser.test.js → structured-response-parser.test.js} +30 -30
  29. package/dist/adapters/utils/__tests__/structured-response-parser.test.js.map +1 -0
  30. package/dist/adapters/utils/{ai-response-parser-error.d.ts → structured-response-parser-error.d.ts} +2 -2
  31. package/dist/adapters/utils/{ai-response-parser-error.js → structured-response-parser-error.js} +9 -9
  32. package/dist/adapters/utils/structured-response-parser-error.js.map +1 -0
  33. package/dist/adapters/utils/{ai-response-parser.d.ts → structured-response-parser.d.ts} +1 -1
  34. package/dist/adapters/utils/{ai-response-parser.js → structured-response-parser.js} +13 -13
  35. package/dist/adapters/utils/structured-response-parser.js.map +1 -0
  36. package/dist/index.cjs +727 -342
  37. package/dist/index.d.ts +11 -8
  38. package/dist/index.js +29 -8
  39. package/dist/index.js.map +1 -1
  40. package/dist/ports/model.port.d.ts +30 -3
  41. package/dist/ports/model.port.js +1 -1
  42. package/dist/ports/model.port.js.map +1 -1
  43. package/dist/ports/provider.port.d.ts +13 -0
  44. package/dist/ports/provider.port.js +5 -0
  45. package/dist/ports/provider.port.js.map +1 -0
  46. package/package.json +11 -9
  47. package/dist/adapters/agents/autonomous-agent.adapter.js.map +0 -1
  48. package/dist/adapters/agents/basic-agent.adapter.js.map +0 -1
  49. package/dist/adapters/agents/retryable-agent.adapter.js.map +0 -1
  50. package/dist/adapters/utils/__tests__/ai-response-parser.test.js.map +0 -1
  51. package/dist/adapters/utils/ai-response-parser-error.js.map +0 -1
  52. package/dist/adapters/utils/ai-response-parser.js.map +0 -1
  53. /package/dist/adapters/utils/__tests__/{ai-response-parser.test.d.ts → structured-response-parser.test.d.ts} +0 -0
package/dist/index.cjs CHANGED
@@ -1,14 +1,16 @@
1
1
  'use strict';
2
2
 
3
- var prompts = require('@langchain/core/prompts');
4
- var agents = require('langchain/agents');
3
+ var ai = require('ai');
5
4
  var v4 = require('zod/v4');
6
5
  var jsonrepair = require('jsonrepair');
6
+ var prompts = require('@langchain/core/prompts');
7
+ var agents = require('langchain/agents');
7
8
  var openai = require('@langchain/openai');
9
+ var aiSdkProvider = require('@openrouter/ai-sdk-provider');
8
10
  var tools = require('langchain/tools');
9
11
 
10
12
  /**
11
- * Custom error for AI response parsing failures
13
+ * Custom error for structured response parsing failures
12
14
  */ function _assert_this_initialized(self) {
13
15
  if (self === void 0) {
14
16
  throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
@@ -19,7 +21,7 @@ function _call_super(_this, derived, args) {
19
21
  derived = _get_prototype_of(derived);
20
22
  return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
21
23
  }
22
- function _class_call_check$7(instance, Constructor) {
24
+ function _class_call_check$9(instance, Constructor) {
23
25
  if (!(instance instanceof Constructor)) {
24
26
  throw new TypeError("Cannot call a class as a function");
25
27
  }
@@ -41,7 +43,7 @@ function _construct(Parent, args, Class) {
41
43
  }
42
44
  return _construct.apply(null, arguments);
43
45
  }
44
- function _define_property$7(obj, key, value) {
46
+ function _define_property$9(obj, key, value) {
45
47
  if (key in obj) {
46
48
  Object.defineProperty(obj, key, {
47
49
  value: value,
@@ -127,18 +129,18 @@ function _is_native_reflect_construct() {
127
129
  return !!result;
128
130
  })();
129
131
  }
130
- var AIResponseParserError = /*#__PURE__*/ function(Error1) {
131
- _inherits(AIResponseParserError, Error1);
132
- function AIResponseParserError(message, cause, text) {
133
- _class_call_check$7(this, AIResponseParserError);
132
+ var StructuredResponseParserError = /*#__PURE__*/ function(Error1) {
133
+ _inherits(StructuredResponseParserError, Error1);
134
+ function StructuredResponseParserError(message, cause, text) {
135
+ _class_call_check$9(this, StructuredResponseParserError);
134
136
  var _this;
135
- _this = _call_super(this, AIResponseParserError, [
137
+ _this = _call_super(this, StructuredResponseParserError, [
136
138
  message
137
- ]), _define_property$7(_this, "cause", void 0), _define_property$7(_this, "text", void 0), _this.cause = cause, _this.text = text;
138
- _this.name = 'AIResponseParserError';
139
+ ]), _define_property$9(_this, "cause", void 0), _define_property$9(_this, "text", void 0), _this.cause = cause, _this.text = text;
140
+ _this.name = 'StructuredResponseParserError';
139
141
  return _this;
140
142
  }
141
- return AIResponseParserError;
143
+ return StructuredResponseParserError;
142
144
  }(_wrap_native_super(Error));
143
145
 
144
146
  function _array_like_to_array(arr, len) {
@@ -149,12 +151,12 @@ function _array_like_to_array(arr, len) {
149
151
  function _array_with_holes(arr) {
150
152
  if (Array.isArray(arr)) return arr;
151
153
  }
152
- function _class_call_check$6(instance, Constructor) {
154
+ function _class_call_check$8(instance, Constructor) {
153
155
  if (!(instance instanceof Constructor)) {
154
156
  throw new TypeError("Cannot call a class as a function");
155
157
  }
156
158
  }
157
- function _defineProperties$6(target, props) {
159
+ function _defineProperties$8(target, props) {
158
160
  for(var i = 0; i < props.length; i++){
159
161
  var descriptor = props[i];
160
162
  descriptor.enumerable = descriptor.enumerable || false;
@@ -163,11 +165,11 @@ function _defineProperties$6(target, props) {
163
165
  Object.defineProperty(target, descriptor.key, descriptor);
164
166
  }
165
167
  }
166
- function _create_class$6(Constructor, protoProps, staticProps) {
167
- if (protoProps) _defineProperties$6(Constructor.prototype, protoProps);
168
+ function _create_class$8(Constructor, protoProps, staticProps) {
169
+ if (protoProps) _defineProperties$8(Constructor.prototype, protoProps);
168
170
  return Constructor;
169
171
  }
170
- function _define_property$6(obj, key, value) {
172
+ function _define_property$8(obj, key, value) {
171
173
  if (key in obj) {
172
174
  Object.defineProperty(obj, key, {
173
175
  value: value,
@@ -180,7 +182,7 @@ function _define_property$6(obj, key, value) {
180
182
  }
181
183
  return obj;
182
184
  }
183
- function _instanceof$3(left, right) {
185
+ function _instanceof$4(left, right) {
184
186
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
185
187
  return !!right[Symbol.hasInstance](left);
186
188
  } else {
@@ -231,13 +233,13 @@ function _unsupported_iterable_to_array(o, minLen) {
231
233
  }
232
234
  /**
233
235
  * Parses AI response text into structured data based on Zod schema
234
- */ var AIResponseParser = /*#__PURE__*/ function() {
235
- function AIResponseParser(schema) {
236
- _class_call_check$6(this, AIResponseParser);
237
- _define_property$6(this, "schema", void 0);
236
+ */ var StructuredResponseParser = /*#__PURE__*/ function() {
237
+ function StructuredResponseParser(schema) {
238
+ _class_call_check$8(this, StructuredResponseParser);
239
+ _define_property$8(this, "schema", void 0);
238
240
  this.schema = schema;
239
241
  }
240
- _create_class$6(AIResponseParser, [
242
+ _create_class$8(StructuredResponseParser, [
241
243
  {
242
244
  key: "parse",
243
245
  value: /**
@@ -249,8 +251,8 @@ function _unsupported_iterable_to_array(o, minLen) {
249
251
  var unescapedJson = this.unescapeJsonValues(json);
250
252
  return this.schema.parse(unescapedJson);
251
253
  } catch (error) {
252
- if (_instanceof$3(error, v4.z.ZodError)) {
253
- throw new AIResponseParserError('Failed to validate response against schema', error, text);
254
+ if (_instanceof$4(error, v4.z.ZodError)) {
255
+ throw new StructuredResponseParserError('Failed to validate response against schema', error, text);
254
256
  }
255
257
  throw error;
256
258
  }
@@ -289,16 +291,16 @@ function _unsupported_iterable_to_array(o, minLen) {
289
291
  value: /**
290
292
  * Converts value to appropriate primitive type based on schema
291
293
  */ function convertToPrimitive(value, schema) {
292
- if (_instanceof$3(schema, v4.z.ZodString)) {
294
+ if (_instanceof$4(schema, v4.z.ZodString)) {
293
295
  return String(value);
294
296
  }
295
- if (_instanceof$3(schema, v4.z.ZodNumber)) {
297
+ if (_instanceof$4(schema, v4.z.ZodNumber)) {
296
298
  return Number(value);
297
299
  }
298
- if (_instanceof$3(schema, v4.z.ZodBoolean)) {
300
+ if (_instanceof$4(schema, v4.z.ZodBoolean)) {
299
301
  return Boolean(value);
300
302
  }
301
- if (_instanceof$3(schema, v4.z.ZodNull)) {
303
+ if (_instanceof$4(schema, v4.z.ZodNull)) {
302
304
  return null;
303
305
  }
304
306
  return value;
@@ -312,14 +314,14 @@ function _unsupported_iterable_to_array(o, minLen) {
312
314
  var arrayStart = text.indexOf('[');
313
315
  var arrayEnd = text.lastIndexOf(']');
314
316
  if (arrayStart === -1 || arrayEnd === -1) {
315
- throw new AIResponseParserError('No array found in response', undefined, text);
317
+ throw new StructuredResponseParserError('No array found in response', undefined, text);
316
318
  }
317
319
  try {
318
320
  var raw = text.slice(arrayStart, arrayEnd + 1);
319
321
  var repaired = this.repairJson(raw);
320
322
  return JSON.parse(repaired);
321
323
  } catch (error) {
322
- throw new AIResponseParserError('Failed to parse array JSON', error, text);
324
+ throw new StructuredResponseParserError('Failed to parse array JSON', error, text);
323
325
  }
324
326
  }
325
327
  },
@@ -343,16 +345,16 @@ function _unsupported_iterable_to_array(o, minLen) {
343
345
  value: /**
344
346
  * Extracts and parses JSON from text based on schema type
345
347
  */ function extractJsonFromText(text) {
346
- if (_instanceof$3(this.schema, v4.z.ZodArray)) {
348
+ if (_instanceof$4(this.schema, v4.z.ZodArray)) {
347
349
  return this.extractArray(text);
348
350
  }
349
- if (_instanceof$3(this.schema, v4.z.ZodObject)) {
351
+ if (_instanceof$4(this.schema, v4.z.ZodObject)) {
350
352
  return this.extractObject(text);
351
353
  }
352
- if (_instanceof$3(this.schema, v4.z.ZodString) || _instanceof$3(this.schema, v4.z.ZodNumber) || _instanceof$3(this.schema, v4.z.ZodBoolean) || _instanceof$3(this.schema, v4.z.ZodNull)) {
354
+ if (_instanceof$4(this.schema, v4.z.ZodString) || _instanceof$4(this.schema, v4.z.ZodNumber) || _instanceof$4(this.schema, v4.z.ZodBoolean) || _instanceof$4(this.schema, v4.z.ZodNull)) {
353
355
  return this.extractPrimitive(text, this.schema);
354
356
  }
355
- throw new AIResponseParserError('Unsupported schema type', undefined, text);
357
+ throw new StructuredResponseParserError('Unsupported schema type', undefined, text);
356
358
  }
357
359
  },
358
360
  {
@@ -363,14 +365,14 @@ function _unsupported_iterable_to_array(o, minLen) {
363
365
  var objectStart = text.indexOf('{');
364
366
  var objectEnd = text.lastIndexOf('}');
365
367
  if (objectStart === -1 || objectEnd === -1) {
366
- throw new AIResponseParserError('No object found in response', undefined, text);
368
+ throw new StructuredResponseParserError('No object found in response', undefined, text);
367
369
  }
368
370
  try {
369
371
  var raw = text.slice(objectStart, objectEnd + 1);
370
372
  var repaired = this.repairJson(raw);
371
373
  return JSON.parse(repaired);
372
374
  } catch (error) {
373
- throw new AIResponseParserError('Failed to parse object JSON', error, text);
375
+ throw new StructuredResponseParserError('Failed to parse object JSON', error, text);
374
376
  }
375
377
  }
376
378
  },
@@ -479,10 +481,10 @@ function _unsupported_iterable_to_array(o, minLen) {
479
481
  }
480
482
  }
481
483
  ]);
482
- return AIResponseParser;
484
+ return StructuredResponseParser;
483
485
  }();
484
486
 
485
- function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
487
+ function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
486
488
  try {
487
489
  var info = gen[key](arg);
488
490
  var value = info.value;
@@ -496,27 +498,27 @@ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
496
498
  Promise.resolve(value).then(_next, _throw);
497
499
  }
498
500
  }
499
- function _async_to_generator$2(fn) {
501
+ function _async_to_generator$3(fn) {
500
502
  return function() {
501
503
  var self = this, args = arguments;
502
504
  return new Promise(function(resolve, reject) {
503
505
  var gen = fn.apply(self, args);
504
506
  function _next(value) {
505
- asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
507
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
506
508
  }
507
509
  function _throw(err) {
508
- asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
510
+ asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
509
511
  }
510
512
  _next(undefined);
511
513
  });
512
514
  };
513
515
  }
514
- function _class_call_check$5(instance, Constructor) {
516
+ function _class_call_check$7(instance, Constructor) {
515
517
  if (!(instance instanceof Constructor)) {
516
518
  throw new TypeError("Cannot call a class as a function");
517
519
  }
518
520
  }
519
- function _defineProperties$5(target, props) {
521
+ function _defineProperties$7(target, props) {
520
522
  for(var i = 0; i < props.length; i++){
521
523
  var descriptor = props[i];
522
524
  descriptor.enumerable = descriptor.enumerable || false;
@@ -525,11 +527,11 @@ function _defineProperties$5(target, props) {
525
527
  Object.defineProperty(target, descriptor.key, descriptor);
526
528
  }
527
529
  }
528
- function _create_class$5(Constructor, protoProps, staticProps) {
529
- if (protoProps) _defineProperties$5(Constructor.prototype, protoProps);
530
+ function _create_class$7(Constructor, protoProps, staticProps) {
531
+ if (protoProps) _defineProperties$7(Constructor.prototype, protoProps);
530
532
  return Constructor;
531
533
  }
532
- function _define_property$5(obj, key, value) {
534
+ function _define_property$7(obj, key, value) {
533
535
  if (key in obj) {
534
536
  Object.defineProperty(obj, key, {
535
537
  value: value,
@@ -542,14 +544,14 @@ function _define_property$5(obj, key, value) {
542
544
  }
543
545
  return obj;
544
546
  }
545
- function _instanceof$2(left, right) {
547
+ function _instanceof$3(left, right) {
546
548
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
547
549
  return !!right[Symbol.hasInstance](left);
548
550
  } else {
549
551
  return left instanceof right;
550
552
  }
551
553
  }
552
- function _ts_generator$2(thisArg, body) {
554
+ function _ts_generator$3(thisArg, body) {
553
555
  var f, y, t, _ = {
554
556
  label: 0,
555
557
  sent: function() {
@@ -640,109 +642,74 @@ function _ts_generator$2(thisArg, body) {
640
642
  };
641
643
  }
642
644
  }
643
- var SYSTEM_PROMPT_TEMPLATE = '\n<OBJECTIVE>\n{mission_prompt}\n</OBJECTIVE>\n\n<GLOBAL_WRAPPER_OUTPUT_FORMAT>\nCRITICAL: The format instructions in this section are the ONLY valid way to structure your response. Your entire response MUST be a single JSON markdown code block. Any formatting guidelines within the <OBJECTIVE> section apply ONLY to the content inside the "RESPOND:" part of your final "action_input".\n\nREQUIRED: You have two ways to respond:\n\n1. **Call a tool** to gather information. For this, you MUST output a JSON blob with the tool\'s name and its input.\n *Valid tool names are: {tool_names}*\n ```json\n {{\n "action": "tool_name_to_use",\n "action_input": "the input for the tool, or an empty object {{}} if no input is needed"\n }}\n ```\n\n2. **Provide the Final Answer** once you have enough information. For this, you MUST output a JSON blob with the "Final Answer" action.\n The "action_input" for a "Final Answer" MUST be a string that begins with either "RESPOND: " for a message or "SILENT: " for no message. This prefix is a literal part of the output string and MUST NOT be omitted.\n - To send a message:\n ```json\n {{\n "action": "Final Answer",\n "action_input": "RESPOND: <your response message>"\n }}\n ```\n - To stay silent:\n ```json\n {{\n "action": "Final Answer",\n "action_input": "SILENT: <your reason for staying silent>"\n }}\n ```\n\n YOU MUST ALWAYS INCLUDE "RESPOND:" OR "SILENT:" IN YOUR FINAL ANSWER\'S "action_input". FAILURE TO DO SO WILL CAUSE AN ERROR.\n\n{schema_format}\n</OUTPUT_FORMAT>\n\n<EXECUTION_CONTEXT>\nThis is internal data for your reference.\n\n<TOOLS>\n{tools}\n</TOOLS>\n\n<WORKING_MEMORY>\nThis is your internal thought process and previous tool usage.\n{agent_scratchpad}\n</WORKING_MEMORY>\n</EXECUTION_CONTEXT>\n';
644
645
  /**
645
- * An autonomous agent that uses tools and a structured prompt to accomplish tasks.
646
- * It can decide whether to respond or remain silent and supports schema-validated responses.
646
+ * A conversational agent for direct, one-shot interactions with a model.
647
+ * It supports optional response parsing against a Zod schema but does not use tools.
647
648
  * @template TOutput - The TypeScript type of the output
648
- */ var AutonomousAgentAdapter = /*#__PURE__*/ function() {
649
- function AutonomousAgentAdapter(name, options) {
650
- _class_call_check$5(this, AutonomousAgentAdapter);
651
- _define_property$5(this, "name", void 0);
652
- _define_property$5(this, "options", void 0);
649
+ */ var ChatAgent = /*#__PURE__*/ function() {
650
+ function ChatAgent(name, options) {
651
+ _class_call_check$7(this, ChatAgent);
652
+ _define_property$7(this, "name", void 0);
653
+ _define_property$7(this, "options", void 0);
653
654
  this.name = name;
654
655
  this.options = options;
655
656
  }
656
- _create_class$5(AutonomousAgentAdapter, [
657
+ _create_class$7(ChatAgent, [
657
658
  {
658
659
  key: "run",
659
660
  value: function run(input) {
660
- return _async_to_generator$2(function() {
661
- var _this_options_logger, _this_options_logger1, executor, userInput, result, agentResponse, _this_options_logger2, _agentResponse_message, message, _this_options_logger3, validatedResponse, _this_options_logger4, error, _this_options_logger5;
662
- return _ts_generator$2(this, function(_state) {
661
+ return _async_to_generator$3(function() {
662
+ var _this_options_logger, content, _this_options_logger1, parsedResponse, _this_options_logger2, error, _this_options_logger3;
663
+ return _ts_generator$3(this, function(_state) {
663
664
  switch(_state.label){
664
665
  case 0:
665
- (_this_options_logger = this.options.logger) === null || _this_options_logger === void 0 ? void 0 : _this_options_logger.debug('Starting chat execution', {
666
+ (_this_options_logger = this.options.logger) === null || _this_options_logger === void 0 ? void 0 : _this_options_logger.debug('Starting query execution', {
666
667
  agent: this.name
667
668
  });
668
669
  _state.label = 1;
669
670
  case 1:
670
671
  _state.trys.push([
671
672
  1,
672
- 4,
673
+ 3,
673
674
  ,
674
- 5
675
+ 4
675
676
  ]);
676
677
  return [
677
678
  4,
678
- this.createExecutor()
679
+ this.invokeModel(input)
679
680
  ];
680
681
  case 2:
681
- executor = _state.sent();
682
- userInput = this.resolveUserInput(input);
683
- return [
684
- 4,
685
- executor.invoke({
686
- input: userInput
687
- })
688
- ];
689
- case 3:
690
- result = _state.sent();
691
- (_this_options_logger1 = this.options.logger) === null || _this_options_logger1 === void 0 ? void 0 : _this_options_logger1.debug('Agent execution completed', {
692
- agent: this.name,
693
- hasOutput: 'output' in result
694
- });
695
- if (!result || typeof result.output !== 'string') {
696
- throw new Error('Agent returned an invalid result structure.');
697
- }
698
- agentResponse = this.parseAgentOutput(result.output);
699
- if (!agentResponse) {
700
- return [
701
- 2,
702
- null
703
- ];
704
- }
705
- if (!agentResponse.shouldRespond) {
706
- (_this_options_logger2 = this.options.logger) === null || _this_options_logger2 === void 0 ? void 0 : _this_options_logger2.debug('Agent chose to remain silent', {
707
- agent: this.name,
708
- reason: agentResponse.reason
709
- });
710
- return [
711
- 2,
712
- null
713
- ];
714
- }
715
- message = (_agentResponse_message = agentResponse.message) !== null && _agentResponse_message !== void 0 ? _agentResponse_message : '';
682
+ content = _state.sent();
716
683
  if (this.options.schema) {
717
- validatedResponse = this.validateResponseContent(message, this.options.schema);
718
- (_this_options_logger3 = this.options.logger) === null || _this_options_logger3 === void 0 ? void 0 : _this_options_logger3.debug('Execution finished; response content validated.', {
684
+ parsedResponse = this.parseResponse(content, this.options.schema);
685
+ (_this_options_logger1 = this.options.logger) === null || _this_options_logger1 === void 0 ? void 0 : _this_options_logger1.debug('Execution finished and response parsed', {
719
686
  agent: this.name
720
687
  });
721
688
  return [
722
689
  2,
723
- validatedResponse
690
+ parsedResponse
724
691
  ];
725
692
  } else {
726
- (_this_options_logger4 = this.options.logger) === null || _this_options_logger4 === void 0 ? void 0 : _this_options_logger4.debug('Execution finished', {
693
+ (_this_options_logger2 = this.options.logger) === null || _this_options_logger2 === void 0 ? void 0 : _this_options_logger2.debug('Execution finished', {
727
694
  agent: this.name
728
695
  });
729
- // When no schema is provided, we assume TOutput is string (default), so message is the result
730
696
  return [
731
697
  2,
732
- message
698
+ content
733
699
  ];
734
700
  }
735
- case 4:
701
+ case 3:
736
702
  error = _state.sent();
737
- (_this_options_logger5 = this.options.logger) === null || _this_options_logger5 === void 0 ? void 0 : _this_options_logger5.error('Chat execution failed', {
703
+ (_this_options_logger3 = this.options.logger) === null || _this_options_logger3 === void 0 ? void 0 : _this_options_logger3.error('Execution failed', {
738
704
  agent: this.name,
739
- error: _instanceof$2(error, Error) ? error.message : 'Unknown error'
705
+ error: _instanceof$3(error, Error) ? error.message : 'Unknown error',
706
+ errorStack: _instanceof$3(error, Error) ? error.stack : undefined
740
707
  });
741
708
  return [
742
709
  2,
743
710
  null
744
711
  ];
745
- case 5:
712
+ case 4:
746
713
  return [
747
714
  2
748
715
  ];
@@ -752,19 +719,15 @@ var SYSTEM_PROMPT_TEMPLATE = '\n<OBJECTIVE>\n{mission_prompt}\n</OBJECTIVE>\n\n<
752
719
  }
753
720
  },
754
721
  {
755
- key: "createExecutor",
756
- value: function createExecutor() {
757
- return _async_to_generator$2(function() {
758
- var model, tools, schemaFormatInstructions, jsonSchema, isPrimitiveType, jsonSchemaString, prompt, agent;
759
- return _ts_generator$2(this, function(_state) {
722
+ key: "invokeModel",
723
+ value: function invokeModel(input) {
724
+ return _async_to_generator$3(function() {
725
+ var _this_options_logger, userInput, systemMessage, jsonSchema, isPrimitiveType, messages, _this_options_logger1, generateConfig, jsonSchema1, text;
726
+ return _ts_generator$3(this, function(_state) {
760
727
  switch(_state.label){
761
728
  case 0:
762
- model = this.options.model.getModel();
763
- tools = this.options.tools.map(function(tool) {
764
- return tool.getDynamicTool();
765
- });
766
- // Add schema format instructions if schema is provided
767
- schemaFormatInstructions = '';
729
+ userInput = this.resolveUserInput(input);
730
+ systemMessage = this.options.systemPrompt.generate();
768
731
  if (this.options.schema) {
769
732
  jsonSchema = v4.z.toJSONSchema(this.options.schema);
770
733
  isPrimitiveType = [
@@ -773,40 +736,62 @@ var SYSTEM_PROMPT_TEMPLATE = '\n<OBJECTIVE>\n{mission_prompt}\n</OBJECTIVE>\n\n<
773
736
  'number',
774
737
  'string'
775
738
  ].includes(jsonSchema.type);
776
- jsonSchemaString = JSON.stringify(jsonSchema, null, 2).replace(/{/g, '{{').replace(/}/g, '}}');
777
739
  if (isPrimitiveType) {
778
- schemaFormatInstructions = '\n\nSCHEMA VALIDATION: When providing a "RESPOND:" answer, the content after "RESPOND: " must be a '.concat(jsonSchema.type, " value that matches this schema description:\n\n```json\n").concat(jsonSchemaString, '\n```\n\nExample format:\n```json\n{{\n "action": "Final Answer",\n "action_input": "RESPOND: your ').concat(jsonSchema.type, ' value here"\n}}\n```\n\nDo not wrap the ').concat(jsonSchema.type, ' value in JSON - just provide the raw value after "RESPOND: ".');
740
+ systemMessage += "\n\n<OUTPUT_FORMAT>\nYou must respond with a ".concat(jsonSchema.type, " value that matches this schema:\n\n```json\n").concat(JSON.stringify(jsonSchema, null, 2), "\n```\n\nYour response should be only the ").concat(jsonSchema.type, " value, without any JSON wrapping or additional text.\n</OUTPUT_FORMAT>");
779
741
  } else {
780
- schemaFormatInstructions = '\n\nSCHEMA VALIDATION: When providing a "RESPOND:" answer, the content after "RESPOND: " must be valid JSON that matches this JSON schema description:\n\n```json\n'.concat(jsonSchemaString, '\n```\n\nExample format:\n```json\n{{\n "action": "Final Answer",\n "action_input": "RESPOND: {{\\"field1\\": \\"value1\\", \\"field2\\": \\"value2\\"}}"\n}}\n```\n');
742
+ systemMessage += "\n\n<OUTPUT_FORMAT>\nYou must respond with valid JSON that matches this JSON schema description:\n\n```json\n".concat(JSON.stringify(jsonSchema, null, 2), "\n```\n\nYour response must be parseable JSON that validates against this schema. Do not include any text outside the JSON.\n</OUTPUT_FORMAT>");
781
743
  }
782
744
  }
783
- prompt = prompts.ChatPromptTemplate.fromMessages([
784
- [
785
- 'system',
786
- SYSTEM_PROMPT_TEMPLATE.replace('{mission_prompt}', this.options.systemPrompt.generate()).replace('{schema_format}', schemaFormatInstructions)
787
- ],
788
- [
789
- 'human',
790
- '{input}'
791
- ]
792
- ]);
745
+ messages = [
746
+ {
747
+ content: systemMessage,
748
+ role: 'system'
749
+ },
750
+ {
751
+ content: userInput,
752
+ role: 'user'
753
+ }
754
+ ];
755
+ (_this_options_logger = this.options.logger) === null || _this_options_logger === void 0 ? void 0 : _this_options_logger.debug('Invoking model...', {
756
+ agent: this.name,
757
+ hasSchema: !!this.options.schema
758
+ });
759
+ if (this.options.verbose) {
760
+ (_this_options_logger1 = this.options.logger) === null || _this_options_logger1 === void 0 ? void 0 : _this_options_logger1.debug('Sending messages to model...', {
761
+ agent: this.name,
762
+ messages: messages
763
+ });
764
+ }
765
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
766
+ generateConfig = {
767
+ messages: messages,
768
+ model: this.options.model.getVercelModel()
769
+ };
770
+ // Prepare structured outputs configuration for better schema validation when schema is provided
771
+ // NOTE: OpenRouter supports structured outputs, but @openrouter/ai-sdk-provider (v0.7.3)
772
+ // doesn't pass through responseFormat parameter yet. Currently relies on prompt-based instructions.
773
+ // Once provider support is added, this will provide stronger guarantees than prompts alone.
774
+ // See: https://openrouter.ai/docs/features/structured-outputs
775
+ if (this.options.schema) {
776
+ jsonSchema1 = v4.z.toJSONSchema(this.options.schema);
777
+ generateConfig.responseFormat = {
778
+ json_schema: {
779
+ name: 'response',
780
+ schema: jsonSchema1,
781
+ strict: true
782
+ },
783
+ type: 'json_schema'
784
+ };
785
+ }
793
786
  return [
794
787
  4,
795
- agents.createStructuredChatAgent({
796
- llm: model,
797
- prompt: prompt,
798
- tools: tools
799
- })
788
+ ai.generateText(generateConfig)
800
789
  ];
801
790
  case 1:
802
- agent = _state.sent();
791
+ text = _state.sent().text;
803
792
  return [
804
793
  2,
805
- agents.AgentExecutor.fromAgentAndTools({
806
- agent: agent,
807
- tools: tools,
808
- verbose: this.options.verbose
809
- })
794
+ text
810
795
  ];
811
796
  }
812
797
  });
@@ -814,29 +799,19 @@ var SYSTEM_PROMPT_TEMPLATE = '\n<OBJECTIVE>\n{mission_prompt}\n</OBJECTIVE>\n\n<
814
799
  }
815
800
  },
816
801
  {
817
- key: "parseAgentOutput",
818
- value: function parseAgentOutput(output) {
819
- var _this_options_logger;
820
- var text = output.trim();
821
- var respondMatch = text.match(/^RESPOND:\s*([\s\S]+)$/i);
822
- if (respondMatch) {
823
- return {
824
- message: respondMatch[1].trim(),
825
- shouldRespond: true
826
- };
827
- }
828
- var silentMatch = text.match(/^SILENT:\s*([\s\S]+)$/i);
829
- if (silentMatch) {
830
- return {
831
- reason: silentMatch[1].trim(),
832
- shouldRespond: false
833
- };
802
+ key: "parseResponse",
803
+ value: function parseResponse(content, schema) {
804
+ try {
805
+ return new StructuredResponseParser(schema).parse(content);
806
+ } catch (error) {
807
+ var _this_options_logger;
808
+ (_this_options_logger = this.options.logger) === null || _this_options_logger === void 0 ? void 0 : _this_options_logger.error('Failed to parse model response.', {
809
+ agent: this.name,
810
+ error: _instanceof$3(error, Error) ? error.message : 'Unknown error',
811
+ rawContent: content
812
+ });
813
+ throw new Error('Invalid response format from model.');
834
814
  }
835
- (_this_options_logger = this.options.logger) === null || _this_options_logger === void 0 ? void 0 : _this_options_logger.error("Agent output was missing 'RESPOND:' or 'SILENT:' prefix.", {
836
- agent: this.name,
837
- rawOutput: output
838
- });
839
- return null;
840
815
  }
841
816
  },
842
817
  {
@@ -847,28 +822,12 @@ var SYSTEM_PROMPT_TEMPLATE = '\n<OBJECTIVE>\n{mission_prompt}\n</OBJECTIVE>\n\n<
847
822
  }
848
823
  return 'Proceed with your instructions.';
849
824
  }
850
- },
851
- {
852
- key: "validateResponseContent",
853
- value: function validateResponseContent(content, schema) {
854
- try {
855
- return new AIResponseParser(schema).parse(content);
856
- } catch (error) {
857
- var _this_options_logger;
858
- (_this_options_logger = this.options.logger) === null || _this_options_logger === void 0 ? void 0 : _this_options_logger.error('Failed to validate response content against schema.', {
859
- agent: this.name,
860
- error: _instanceof$2(error, Error) ? error.message : 'Unknown error',
861
- rawContent: content
862
- });
863
- throw new Error('Invalid response content from model.');
864
- }
865
- }
866
825
  }
867
826
  ]);
868
- return AutonomousAgentAdapter;
827
+ return ChatAgent;
869
828
  }();
870
829
 
871
- function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
830
+ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
872
831
  try {
873
832
  var info = gen[key](arg);
874
833
  var value = info.value;
@@ -882,27 +841,27 @@ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
882
841
  Promise.resolve(value).then(_next, _throw);
883
842
  }
884
843
  }
885
- function _async_to_generator$1(fn) {
844
+ function _async_to_generator$2(fn) {
886
845
  return function() {
887
846
  var self = this, args = arguments;
888
847
  return new Promise(function(resolve, reject) {
889
848
  var gen = fn.apply(self, args);
890
849
  function _next(value) {
891
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
850
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
892
851
  }
893
852
  function _throw(err) {
894
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
853
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
895
854
  }
896
855
  _next(undefined);
897
856
  });
898
857
  };
899
858
  }
900
- function _class_call_check$4(instance, Constructor) {
859
+ function _class_call_check$6(instance, Constructor) {
901
860
  if (!(instance instanceof Constructor)) {
902
861
  throw new TypeError("Cannot call a class as a function");
903
862
  }
904
863
  }
905
- function _defineProperties$4(target, props) {
864
+ function _defineProperties$6(target, props) {
906
865
  for(var i = 0; i < props.length; i++){
907
866
  var descriptor = props[i];
908
867
  descriptor.enumerable = descriptor.enumerable || false;
@@ -911,11 +870,11 @@ function _defineProperties$4(target, props) {
911
870
  Object.defineProperty(target, descriptor.key, descriptor);
912
871
  }
913
872
  }
914
- function _create_class$4(Constructor, protoProps, staticProps) {
915
- if (protoProps) _defineProperties$4(Constructor.prototype, protoProps);
873
+ function _create_class$6(Constructor, protoProps, staticProps) {
874
+ if (protoProps) _defineProperties$6(Constructor.prototype, protoProps);
916
875
  return Constructor;
917
876
  }
918
- function _define_property$4(obj, key, value) {
877
+ function _define_property$6(obj, key, value) {
919
878
  if (key in obj) {
920
879
  Object.defineProperty(obj, key, {
921
880
  value: value,
@@ -928,14 +887,14 @@ function _define_property$4(obj, key, value) {
928
887
  }
929
888
  return obj;
930
889
  }
931
- function _instanceof$1(left, right) {
890
+ function _instanceof$2(left, right) {
932
891
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
933
892
  return !!right[Symbol.hasInstance](left);
934
893
  } else {
935
894
  return left instanceof right;
936
895
  }
937
896
  }
938
- function _ts_generator$1(thisArg, body) {
897
+ function _ts_generator$2(thisArg, body) {
939
898
  var f, y, t, _ = {
940
899
  label: 0,
941
900
  sent: function() {
@@ -1027,65 +986,359 @@ function _ts_generator$1(thisArg, body) {
1027
986
  }
1028
987
  }
1029
988
  /**
1030
- * A basic agent for direct, one-shot interactions with a model.
1031
- * It supports optional response parsing against a Zod schema but does not use tools.
989
+ * A decorator agent that adds retry logic to an existing agent for resilient execution.
990
+ * @template TInput - The TypeScript type of the input
1032
991
  * @template TOutput - The TypeScript type of the output
1033
- */ var BasicAgentAdapter = /*#__PURE__*/ function() {
1034
- function BasicAgentAdapter(name, options) {
1035
- _class_call_check$4(this, BasicAgentAdapter);
1036
- _define_property$4(this, "name", void 0);
1037
- _define_property$4(this, "options", void 0);
1038
- this.name = name;
1039
- this.options = options;
992
+ */ var ResilientAgent = /*#__PURE__*/ function() {
993
+ function ResilientAgent(agent) {
994
+ var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
995
+ _class_call_check$6(this, ResilientAgent);
996
+ _define_property$6(this, "agent", void 0);
997
+ _define_property$6(this, "name", void 0);
998
+ _define_property$6(this, "logger", void 0);
999
+ _define_property$6(this, "retries", void 0);
1000
+ this.agent = agent;
1001
+ var logger = options.logger, _options_retries = options.retries, retries = _options_retries === void 0 ? 1 : _options_retries;
1002
+ this.name = "Resilient(".concat(agent.name, ")");
1003
+ this.logger = logger;
1004
+ this.retries = retries;
1040
1005
  }
1041
- _create_class$4(BasicAgentAdapter, [
1006
+ _create_class$6(ResilientAgent, [
1042
1007
  {
1043
1008
  key: "run",
1044
1009
  value: function run(input) {
1045
- return _async_to_generator$1(function() {
1046
- var _this_options_logger, content, _this_options_logger1, parsedResponse, _this_options_logger2, error, _this_options_logger3;
1047
- return _ts_generator$1(this, function(_state) {
1010
+ return _async_to_generator$2(function() {
1011
+ var _this_logger, maxAttempts, attempt, _this_logger1, _this_logger2, result, _this_logger3, error, _this_logger4;
1012
+ return _ts_generator$2(this, function(_state) {
1048
1013
  switch(_state.label){
1049
1014
  case 0:
1050
- (_this_options_logger = this.options.logger) === null || _this_options_logger === void 0 ? void 0 : _this_options_logger.debug('Starting query execution', {
1051
- agent: this.name
1052
- });
1015
+ maxAttempts = this.retries + 1;
1016
+ attempt = 1;
1053
1017
  _state.label = 1;
1054
1018
  case 1:
1055
- _state.trys.push([
1056
- 1,
1019
+ if (!(attempt <= maxAttempts)) return [
1057
1020
  3,
1021
+ 6
1022
+ ];
1023
+ _state.label = 2;
1024
+ case 2:
1025
+ _state.trys.push([
1026
+ 2,
1027
+ 4,
1058
1028
  ,
1059
- 4
1029
+ 5
1060
1030
  ]);
1031
+ (_this_logger1 = this.logger) === null || _this_logger1 === void 0 ? void 0 : _this_logger1.debug("Attempt ".concat(attempt, " of ").concat(maxAttempts), {
1032
+ agent: this.name
1033
+ });
1061
1034
  return [
1062
1035
  4,
1063
- this.invokeModel(input)
1036
+ this.agent.run(input)
1064
1037
  ];
1065
- case 2:
1066
- content = _state.sent();
1067
- if (this.options.schema) {
1068
- parsedResponse = this.parseResponse(content, this.options.schema);
1069
- (_this_options_logger1 = this.options.logger) === null || _this_options_logger1 === void 0 ? void 0 : _this_options_logger1.debug('Execution finished and response parsed', {
1038
+ case 3:
1039
+ result = _state.sent();
1040
+ if (result !== null) {
1041
+ (_this_logger3 = this.logger) === null || _this_logger3 === void 0 ? void 0 : _this_logger3.debug("Attempt ".concat(attempt, " of ").concat(maxAttempts, " succeeded"), {
1070
1042
  agent: this.name
1071
1043
  });
1072
1044
  return [
1073
1045
  2,
1074
- parsedResponse
1046
+ result
1047
+ ];
1048
+ }
1049
+ (_this_logger2 = this.logger) === null || _this_logger2 === void 0 ? void 0 : _this_logger2.debug("Attempt ".concat(attempt, " of ").concat(maxAttempts, " failed: agent returned null"), {
1050
+ agent: this.name
1051
+ });
1052
+ return [
1053
+ 3,
1054
+ 5
1055
+ ];
1056
+ case 4:
1057
+ error = _state.sent();
1058
+ (_this_logger4 = this.logger) === null || _this_logger4 === void 0 ? void 0 : _this_logger4.debug("Attempt ".concat(attempt, " of ").concat(maxAttempts, " failed with an error"), {
1059
+ agent: this.name,
1060
+ error: _instanceof$2(error, Error) ? error.message : 'Unknown error'
1061
+ });
1062
+ return [
1063
+ 3,
1064
+ 5
1065
+ ];
1066
+ case 5:
1067
+ attempt++;
1068
+ return [
1069
+ 3,
1070
+ 1
1071
+ ];
1072
+ case 6:
1073
+ (_this_logger = this.logger) === null || _this_logger === void 0 ? void 0 : _this_logger.error("All ".concat(maxAttempts, " attempts failed"), {
1074
+ agent: this.name
1075
+ });
1076
+ return [
1077
+ 2,
1078
+ null
1079
+ ];
1080
+ }
1081
+ });
1082
+ }).call(this);
1083
+ }
1084
+ }
1085
+ ]);
1086
+ return ResilientAgent;
1087
+ }();
1088
+
1089
+ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
1090
+ try {
1091
+ var info = gen[key](arg);
1092
+ var value = info.value;
1093
+ } catch (error) {
1094
+ reject(error);
1095
+ return;
1096
+ }
1097
+ if (info.done) {
1098
+ resolve(value);
1099
+ } else {
1100
+ Promise.resolve(value).then(_next, _throw);
1101
+ }
1102
+ }
1103
+ function _async_to_generator$1(fn) {
1104
+ return function() {
1105
+ var self = this, args = arguments;
1106
+ return new Promise(function(resolve, reject) {
1107
+ var gen = fn.apply(self, args);
1108
+ function _next(value) {
1109
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
1110
+ }
1111
+ function _throw(err) {
1112
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
1113
+ }
1114
+ _next(undefined);
1115
+ });
1116
+ };
1117
+ }
1118
+ function _class_call_check$5(instance, Constructor) {
1119
+ if (!(instance instanceof Constructor)) {
1120
+ throw new TypeError("Cannot call a class as a function");
1121
+ }
1122
+ }
1123
+ function _defineProperties$5(target, props) {
1124
+ for(var i = 0; i < props.length; i++){
1125
+ var descriptor = props[i];
1126
+ descriptor.enumerable = descriptor.enumerable || false;
1127
+ descriptor.configurable = true;
1128
+ if ("value" in descriptor) descriptor.writable = true;
1129
+ Object.defineProperty(target, descriptor.key, descriptor);
1130
+ }
1131
+ }
1132
+ function _create_class$5(Constructor, protoProps, staticProps) {
1133
+ if (protoProps) _defineProperties$5(Constructor.prototype, protoProps);
1134
+ return Constructor;
1135
+ }
1136
+ function _define_property$5(obj, key, value) {
1137
+ if (key in obj) {
1138
+ Object.defineProperty(obj, key, {
1139
+ value: value,
1140
+ enumerable: true,
1141
+ configurable: true,
1142
+ writable: true
1143
+ });
1144
+ } else {
1145
+ obj[key] = value;
1146
+ }
1147
+ return obj;
1148
+ }
1149
+ function _instanceof$1(left, right) {
1150
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
1151
+ return !!right[Symbol.hasInstance](left);
1152
+ } else {
1153
+ return left instanceof right;
1154
+ }
1155
+ }
1156
+ function _ts_generator$1(thisArg, body) {
1157
+ var f, y, t, _ = {
1158
+ label: 0,
1159
+ sent: function() {
1160
+ if (t[0] & 1) throw t[1];
1161
+ return t[1];
1162
+ },
1163
+ trys: [],
1164
+ ops: []
1165
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
1166
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
1167
+ return this;
1168
+ }), g;
1169
+ function verb(n) {
1170
+ return function(v) {
1171
+ return step([
1172
+ n,
1173
+ v
1174
+ ]);
1175
+ };
1176
+ }
1177
+ function step(op) {
1178
+ if (f) throw new TypeError("Generator is already executing.");
1179
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
1180
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1181
+ if (y = 0, t) op = [
1182
+ op[0] & 2,
1183
+ t.value
1184
+ ];
1185
+ switch(op[0]){
1186
+ case 0:
1187
+ case 1:
1188
+ t = op;
1189
+ break;
1190
+ case 4:
1191
+ _.label++;
1192
+ return {
1193
+ value: op[1],
1194
+ done: false
1195
+ };
1196
+ case 5:
1197
+ _.label++;
1198
+ y = op[1];
1199
+ op = [
1200
+ 0
1201
+ ];
1202
+ continue;
1203
+ case 7:
1204
+ op = _.ops.pop();
1205
+ _.trys.pop();
1206
+ continue;
1207
+ default:
1208
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1209
+ _ = 0;
1210
+ continue;
1211
+ }
1212
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1213
+ _.label = op[1];
1214
+ break;
1215
+ }
1216
+ if (op[0] === 6 && _.label < t[1]) {
1217
+ _.label = t[1];
1218
+ t = op;
1219
+ break;
1220
+ }
1221
+ if (t && _.label < t[2]) {
1222
+ _.label = t[2];
1223
+ _.ops.push(op);
1224
+ break;
1225
+ }
1226
+ if (t[2]) _.ops.pop();
1227
+ _.trys.pop();
1228
+ continue;
1229
+ }
1230
+ op = body.call(thisArg, _);
1231
+ } catch (e) {
1232
+ op = [
1233
+ 6,
1234
+ e
1235
+ ];
1236
+ y = 0;
1237
+ } finally{
1238
+ f = t = 0;
1239
+ }
1240
+ if (op[0] & 5) throw op[1];
1241
+ return {
1242
+ value: op[0] ? op[1] : void 0,
1243
+ done: true
1244
+ };
1245
+ }
1246
+ }
1247
+ var SYSTEM_PROMPT_TEMPLATE = '\n<OBJECTIVE>\n{mission_prompt}\n</OBJECTIVE>\n\n<GLOBAL_WRAPPER_OUTPUT_FORMAT>\nCRITICAL: The format instructions in this section are the ONLY valid way to structure your response. Your entire response MUST be a single JSON markdown code block. Any formatting guidelines within the <OBJECTIVE> section apply ONLY to the content inside the "RESPOND:" part of your final "action_input".\n\nREQUIRED: You have two ways to respond:\n\n1. **Call a tool** to gather information. For this, you MUST output a JSON blob with the tool\'s name and its input.\n *Valid tool names are: {tool_names}*\n ```json\n {{\n "action": "tool_name_to_use",\n "action_input": "the input for the tool, or an empty object {{}} if no input is needed"\n }}\n ```\n\n2. **Provide the Final Answer** once you have enough information. For this, you MUST output a JSON blob with the "Final Answer" action.\n The "action_input" for a "Final Answer" MUST be a string that begins with either "RESPOND: " for a message or "SILENT: " for no message. This prefix is a literal part of the output string and MUST NOT be omitted.\n - To send a message:\n ```json\n {{\n "action": "Final Answer",\n "action_input": "RESPOND: <your response message>"\n }}\n ```\n - To stay silent:\n ```json\n {{\n "action": "Final Answer",\n "action_input": "SILENT: <your reason for staying silent>"\n }}\n ```\n\n YOU MUST ALWAYS INCLUDE "RESPOND:" OR "SILENT:" IN YOUR FINAL ANSWER\'S "action_input". FAILURE TO DO SO WILL CAUSE AN ERROR.\n\n{schema_format}\n</OUTPUT_FORMAT>\n\n<EXECUTION_CONTEXT>\nThis is internal data for your reference.\n\n<TOOLS>\n{tools}\n</TOOLS>\n\n<WORKING_MEMORY>\nThis is your internal thought process and previous tool usage.\n{agent_scratchpad}\n</WORKING_MEMORY>\n</EXECUTION_CONTEXT>\n';
1248
+ /**
1249
+ * A tool-enabled agent that uses tools and a structured prompt to accomplish tasks.
1250
+ * It can decide whether to respond or remain silent and supports schema-validated responses.
1251
+ * @template TOutput - The TypeScript type of the output
1252
+ */ var ToolAgent = /*#__PURE__*/ function() {
1253
+ function ToolAgent(name, options) {
1254
+ _class_call_check$5(this, ToolAgent);
1255
+ _define_property$5(this, "name", void 0);
1256
+ _define_property$5(this, "options", void 0);
1257
+ this.name = name;
1258
+ this.options = options;
1259
+ }
1260
+ _create_class$5(ToolAgent, [
1261
+ {
1262
+ key: "run",
1263
+ value: function run(input) {
1264
+ return _async_to_generator$1(function() {
1265
+ var _this_options_logger, _this_options_logger1, executor, userInput, result, agentResponse, _this_options_logger2, _agentResponse_message, message, _this_options_logger3, validatedResponse, _this_options_logger4, error, _this_options_logger5;
1266
+ return _ts_generator$1(this, function(_state) {
1267
+ switch(_state.label){
1268
+ case 0:
1269
+ (_this_options_logger = this.options.logger) === null || _this_options_logger === void 0 ? void 0 : _this_options_logger.debug('Starting chat execution', {
1270
+ agent: this.name
1271
+ });
1272
+ _state.label = 1;
1273
+ case 1:
1274
+ _state.trys.push([
1275
+ 1,
1276
+ 4,
1277
+ ,
1278
+ 5
1279
+ ]);
1280
+ return [
1281
+ 4,
1282
+ this.createExecutor()
1283
+ ];
1284
+ case 2:
1285
+ executor = _state.sent();
1286
+ userInput = this.resolveUserInput(input);
1287
+ return [
1288
+ 4,
1289
+ executor.invoke({
1290
+ input: userInput
1291
+ })
1292
+ ];
1293
+ case 3:
1294
+ result = _state.sent();
1295
+ (_this_options_logger1 = this.options.logger) === null || _this_options_logger1 === void 0 ? void 0 : _this_options_logger1.debug('Agent execution completed', {
1296
+ agent: this.name,
1297
+ hasOutput: 'output' in result
1298
+ });
1299
+ if (!result || typeof result.output !== 'string') {
1300
+ throw new Error('Agent returned an invalid result structure.');
1301
+ }
1302
+ agentResponse = this.parseAgentOutput(result.output);
1303
+ if (!agentResponse) {
1304
+ return [
1305
+ 2,
1306
+ null
1307
+ ];
1308
+ }
1309
+ if (!agentResponse.shouldRespond) {
1310
+ (_this_options_logger2 = this.options.logger) === null || _this_options_logger2 === void 0 ? void 0 : _this_options_logger2.debug('Agent chose to remain silent', {
1311
+ agent: this.name,
1312
+ reason: agentResponse.reason
1313
+ });
1314
+ return [
1315
+ 2,
1316
+ null
1317
+ ];
1318
+ }
1319
+ message = (_agentResponse_message = agentResponse.message) !== null && _agentResponse_message !== void 0 ? _agentResponse_message : '';
1320
+ if (this.options.schema) {
1321
+ validatedResponse = this.validateResponseContent(message, this.options.schema);
1322
+ (_this_options_logger3 = this.options.logger) === null || _this_options_logger3 === void 0 ? void 0 : _this_options_logger3.debug('Execution finished; response content validated.', {
1323
+ agent: this.name
1324
+ });
1325
+ return [
1326
+ 2,
1327
+ validatedResponse
1075
1328
  ];
1076
1329
  } else {
1077
- (_this_options_logger2 = this.options.logger) === null || _this_options_logger2 === void 0 ? void 0 : _this_options_logger2.debug('Execution finished', {
1330
+ (_this_options_logger4 = this.options.logger) === null || _this_options_logger4 === void 0 ? void 0 : _this_options_logger4.debug('Execution finished', {
1078
1331
  agent: this.name
1079
1332
  });
1080
- // When no schema is provided, we assume TOutput is string (default), so content is the result
1333
+ // When no schema is provided, we assume TOutput is string (default), so message is the result
1081
1334
  return [
1082
1335
  2,
1083
- content
1336
+ message
1084
1337
  ];
1085
1338
  }
1086
- case 3:
1339
+ case 4:
1087
1340
  error = _state.sent();
1088
- (_this_options_logger3 = this.options.logger) === null || _this_options_logger3 === void 0 ? void 0 : _this_options_logger3.error('Execution failed', {
1341
+ (_this_options_logger5 = this.options.logger) === null || _this_options_logger5 === void 0 ? void 0 : _this_options_logger5.error('Chat execution failed', {
1089
1342
  agent: this.name,
1090
1343
  error: _instanceof$1(error, Error) ? error.message : 'Unknown error'
1091
1344
  });
@@ -1093,7 +1346,7 @@ function _ts_generator$1(thisArg, body) {
1093
1346
  2,
1094
1347
  null
1095
1348
  ];
1096
- case 4:
1349
+ case 5:
1097
1350
  return [
1098
1351
  2
1099
1352
  ];
@@ -1103,16 +1356,19 @@ function _ts_generator$1(thisArg, body) {
1103
1356
  }
1104
1357
  },
1105
1358
  {
1106
- key: "invokeModel",
1107
- value: function invokeModel(input) {
1359
+ key: "createExecutor",
1360
+ value: function createExecutor() {
1108
1361
  return _async_to_generator$1(function() {
1109
- var _this_options_logger, userInput, systemMessage, jsonSchema, isPrimitiveType, messages, _this_options_logger1, response, content;
1362
+ var model, tools, schemaFormatInstructions, jsonSchema, isPrimitiveType, jsonSchemaString, prompt, agent;
1110
1363
  return _ts_generator$1(this, function(_state) {
1111
1364
  switch(_state.label){
1112
1365
  case 0:
1113
- userInput = this.resolveUserInput(input);
1114
- systemMessage = this.options.systemPrompt.generate();
1115
- // Add schema definition to system prompt if schema is provided
1366
+ model = this.options.model.getLangchainModel();
1367
+ tools = this.options.tools.map(function(tool) {
1368
+ return tool.getDynamicTool();
1369
+ });
1370
+ // Add schema format instructions if schema is provided
1371
+ schemaFormatInstructions = '';
1116
1372
  if (this.options.schema) {
1117
1373
  jsonSchema = v4.z.toJSONSchema(this.options.schema);
1118
1374
  isPrimitiveType = [
@@ -1121,45 +1377,40 @@ function _ts_generator$1(thisArg, body) {
1121
1377
  'number',
1122
1378
  'string'
1123
1379
  ].includes(jsonSchema.type);
1380
+ jsonSchemaString = JSON.stringify(jsonSchema, null, 2).replace(/{/g, '{{').replace(/}/g, '}}');
1124
1381
  if (isPrimitiveType) {
1125
- systemMessage += "\n\n<OUTPUT_FORMAT>\nYou must respond with a ".concat(jsonSchema.type, " value that matches this schema:\n\n```json\n").concat(JSON.stringify(jsonSchema, null, 2), "\n```\n\nYour response should be only the ").concat(jsonSchema.type, " value, without any JSON wrapping or additional text.\n</OUTPUT_FORMAT>");
1382
+ schemaFormatInstructions = '\n\nSCHEMA VALIDATION: When providing a "RESPOND:" answer, the content after "RESPOND: " must be a '.concat(jsonSchema.type, " value that matches this schema description:\n\n```json\n").concat(jsonSchemaString, '\n```\n\nExample format:\n```json\n{{\n "action": "Final Answer",\n "action_input": "RESPOND: your ').concat(jsonSchema.type, ' value here"\n}}\n```\n\nDo not wrap the ').concat(jsonSchema.type, ' value in JSON - just provide the raw value after "RESPOND: ".');
1126
1383
  } else {
1127
- systemMessage += "\n\n<OUTPUT_FORMAT>\nYou must respond with valid JSON that matches this JSON schema description:\n\n```json\n".concat(JSON.stringify(jsonSchema, null, 2), "\n```\n\nYour response must be parseable JSON that validates against this schema. Do not include any text outside the JSON.\n</OUTPUT_FORMAT>");
1128
- }
1129
- }
1130
- messages = [
1131
- {
1132
- content: systemMessage,
1133
- role: 'system'
1134
- },
1135
- {
1136
- content: userInput,
1137
- role: 'user'
1384
+ schemaFormatInstructions = '\n\nSCHEMA VALIDATION: When providing a "RESPOND:" answer, the content after "RESPOND: " must be valid JSON that matches this JSON schema description:\n\n```json\n'.concat(jsonSchemaString, '\n```\n\nExample format:\n```json\n{{\n "action": "Final Answer",\n "action_input": "RESPOND: {{\\"field1\\": \\"value1\\", \\"field2\\": \\"value2\\"}}"\n}}\n```\n');
1138
1385
  }
1139
- ];
1140
- (_this_options_logger = this.options.logger) === null || _this_options_logger === void 0 ? void 0 : _this_options_logger.debug('Invoking model...', {
1141
- agent: this.name,
1142
- hasSchema: !!this.options.schema
1143
- });
1144
- if (this.options.verbose) {
1145
- (_this_options_logger1 = this.options.logger) === null || _this_options_logger1 === void 0 ? void 0 : _this_options_logger1.debug('Sending messages to model...', {
1146
- agent: this.name,
1147
- messages: messages
1148
- });
1149
1386
  }
1387
+ prompt = prompts.ChatPromptTemplate.fromMessages([
1388
+ [
1389
+ 'system',
1390
+ SYSTEM_PROMPT_TEMPLATE.replace('{mission_prompt}', this.options.systemPrompt.generate()).replace('{schema_format}', schemaFormatInstructions)
1391
+ ],
1392
+ [
1393
+ 'human',
1394
+ '{input}'
1395
+ ]
1396
+ ]);
1150
1397
  return [
1151
1398
  4,
1152
- this.options.model.getModel().invoke(messages)
1399
+ agents.createStructuredChatAgent({
1400
+ llm: model,
1401
+ prompt: prompt,
1402
+ tools: tools
1403
+ })
1153
1404
  ];
1154
1405
  case 1:
1155
- response = _state.sent();
1156
- content = response.content;
1157
- if (typeof content !== 'string') {
1158
- throw new Error('Model returned a non-string content type.');
1159
- }
1406
+ agent = _state.sent();
1160
1407
  return [
1161
1408
  2,
1162
- content
1409
+ agents.AgentExecutor.fromAgentAndTools({
1410
+ agent: agent,
1411
+ tools: tools,
1412
+ verbose: this.options.verbose
1413
+ })
1163
1414
  ];
1164
1415
  }
1165
1416
  });
@@ -1167,19 +1418,29 @@ function _ts_generator$1(thisArg, body) {
1167
1418
  }
1168
1419
  },
1169
1420
  {
1170
- key: "parseResponse",
1171
- value: function parseResponse(content, schema) {
1172
- try {
1173
- return new AIResponseParser(schema).parse(content);
1174
- } catch (error) {
1175
- var _this_options_logger;
1176
- (_this_options_logger = this.options.logger) === null || _this_options_logger === void 0 ? void 0 : _this_options_logger.error('Failed to parse model response.', {
1177
- agent: this.name,
1178
- error: _instanceof$1(error, Error) ? error.message : 'Unknown error',
1179
- rawContent: content
1180
- });
1181
- throw new Error('Invalid response format from model.');
1421
+ key: "parseAgentOutput",
1422
+ value: function parseAgentOutput(output) {
1423
+ var _this_options_logger;
1424
+ var text = output.trim();
1425
+ var respondMatch = text.match(/^RESPOND:\s*([\s\S]+)$/i);
1426
+ if (respondMatch) {
1427
+ return {
1428
+ message: respondMatch[1].trim(),
1429
+ shouldRespond: true
1430
+ };
1182
1431
  }
1432
+ var silentMatch = text.match(/^SILENT:\s*([\s\S]+)$/i);
1433
+ if (silentMatch) {
1434
+ return {
1435
+ reason: silentMatch[1].trim(),
1436
+ shouldRespond: false
1437
+ };
1438
+ }
1439
+ (_this_options_logger = this.options.logger) === null || _this_options_logger === void 0 ? void 0 : _this_options_logger.error("Agent output was missing 'RESPOND:' or 'SILENT:' prefix.", {
1440
+ agent: this.name,
1441
+ rawOutput: output
1442
+ });
1443
+ return null;
1183
1444
  }
1184
1445
  },
1185
1446
  {
@@ -1190,17 +1451,33 @@ function _ts_generator$1(thisArg, body) {
1190
1451
  }
1191
1452
  return 'Proceed with your instructions.';
1192
1453
  }
1454
+ },
1455
+ {
1456
+ key: "validateResponseContent",
1457
+ value: function validateResponseContent(content, schema) {
1458
+ try {
1459
+ return new StructuredResponseParser(schema).parse(content);
1460
+ } catch (error) {
1461
+ var _this_options_logger;
1462
+ (_this_options_logger = this.options.logger) === null || _this_options_logger === void 0 ? void 0 : _this_options_logger.error('Failed to validate response content against schema.', {
1463
+ agent: this.name,
1464
+ error: _instanceof$1(error, Error) ? error.message : 'Unknown error',
1465
+ rawContent: content
1466
+ });
1467
+ throw new Error('Invalid response content from model.');
1468
+ }
1469
+ }
1193
1470
  }
1194
1471
  ]);
1195
- return BasicAgentAdapter;
1472
+ return ToolAgent;
1196
1473
  }();
1197
1474
 
1198
- function _class_call_check$3(instance, Constructor) {
1475
+ function _class_call_check$4(instance, Constructor) {
1199
1476
  if (!(instance instanceof Constructor)) {
1200
1477
  throw new TypeError("Cannot call a class as a function");
1201
1478
  }
1202
1479
  }
1203
- function _defineProperties$3(target, props) {
1480
+ function _defineProperties$4(target, props) {
1204
1481
  for(var i = 0; i < props.length; i++){
1205
1482
  var descriptor = props[i];
1206
1483
  descriptor.enumerable = descriptor.enumerable || false;
@@ -1209,11 +1486,11 @@ function _defineProperties$3(target, props) {
1209
1486
  Object.defineProperty(target, descriptor.key, descriptor);
1210
1487
  }
1211
1488
  }
1212
- function _create_class$3(Constructor, protoProps, staticProps) {
1213
- if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
1489
+ function _create_class$4(Constructor, protoProps, staticProps) {
1490
+ if (protoProps) _defineProperties$4(Constructor.prototype, protoProps);
1214
1491
  return Constructor;
1215
1492
  }
1216
- function _define_property$3(obj, key, value) {
1493
+ function _define_property$4(obj, key, value) {
1217
1494
  if (key in obj) {
1218
1495
  Object.defineProperty(obj, key, {
1219
1496
  value: value,
@@ -1236,48 +1513,101 @@ function _object_spread(target) {
1236
1513
  }));
1237
1514
  }
1238
1515
  ownKeys.forEach(function(key) {
1239
- _define_property$3(target, key, source[key]);
1516
+ _define_property$4(target, key, source[key]);
1517
+ });
1518
+ }
1519
+ return target;
1520
+ }
1521
+ function ownKeys(object, enumerableOnly) {
1522
+ var keys = Object.keys(object);
1523
+ if (Object.getOwnPropertySymbols) {
1524
+ var symbols = Object.getOwnPropertySymbols(object);
1525
+ keys.push.apply(keys, symbols);
1526
+ }
1527
+ return keys;
1528
+ }
1529
+ function _object_spread_props(target, source) {
1530
+ source = source != null ? source : {};
1531
+ if (Object.getOwnPropertyDescriptors) {
1532
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
1533
+ } else {
1534
+ ownKeys(Object(source)).forEach(function(key) {
1535
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
1240
1536
  });
1241
1537
  }
1242
1538
  return target;
1243
1539
  }
1244
1540
  /**
1245
- * OpenRouter adapter that provides access to various models through OpenRouter's API
1246
- */ var OpenRouterModelAdapter = /*#__PURE__*/ function() {
1247
- function OpenRouterModelAdapter(config) {
1248
- _class_call_check$3(this, OpenRouterModelAdapter);
1249
- var _config_metadata, _config_metadata1;
1250
- _define_property$3(this, "model", void 0);
1251
- var _config_maxTokens;
1252
- this.model = new openai.ChatOpenAI({
1541
+ * OpenRouter model wrapper supporting both LangChain and Vercel AI SDK
1542
+ */ var OpenRouterModel = /*#__PURE__*/ function() {
1543
+ function OpenRouterModel(providerConfig, modelName) {
1544
+ var modelConfig = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
1545
+ _class_call_check$4(this, OpenRouterModel);
1546
+ var _this_providerConfig_metadata, _this_providerConfig_metadata1;
1547
+ _define_property$4(this, "providerConfig", void 0);
1548
+ _define_property$4(this, "modelName", void 0);
1549
+ _define_property$4(this, "langchainModel", void 0);
1550
+ _define_property$4(this, "modelConfig", void 0);
1551
+ _define_property$4(this, "vercelModel", void 0);
1552
+ this.providerConfig = providerConfig;
1553
+ this.modelName = modelName;
1554
+ this.modelConfig = _object_spread({
1555
+ maxTokens: 256000,
1556
+ reasoning: {
1557
+ effort: 'high',
1558
+ exclude: true
1559
+ }
1560
+ }, modelConfig);
1561
+ // LangChain model setup
1562
+ this.langchainModel = new openai.ChatOpenAI(_object_spread_props(_object_spread({
1253
1563
  configuration: {
1254
1564
  baseURL: 'https://openrouter.ai/api/v1',
1255
- defaultHeaders: _object_spread({}, ((_config_metadata = config.metadata) === null || _config_metadata === void 0 ? void 0 : _config_metadata.website) && {
1256
- 'HTTP-Referer': config.metadata.website
1257
- }, ((_config_metadata1 = config.metadata) === null || _config_metadata1 === void 0 ? void 0 : _config_metadata1.application) && {
1258
- 'X-Title': config.metadata.application
1565
+ defaultHeaders: _object_spread({}, ((_this_providerConfig_metadata = this.providerConfig.metadata) === null || _this_providerConfig_metadata === void 0 ? void 0 : _this_providerConfig_metadata.website) && {
1566
+ 'HTTP-Referer': this.providerConfig.metadata.website
1567
+ }, ((_this_providerConfig_metadata1 = this.providerConfig.metadata) === null || _this_providerConfig_metadata1 === void 0 ? void 0 : _this_providerConfig_metadata1.application) && {
1568
+ 'X-Title': this.providerConfig.metadata.application
1259
1569
  })
1260
1570
  },
1261
- maxTokens: (_config_maxTokens = config.maxTokens) !== null && _config_maxTokens !== void 0 ? _config_maxTokens : 256000,
1571
+ maxTokens: this.modelConfig.maxTokens
1572
+ }, this.modelConfig.reasoning && {
1262
1573
  modelKwargs: {
1263
- reasoning: {
1264
- effort: 'high',
1265
- exclude: true
1266
- }
1267
- },
1268
- modelName: config.modelName,
1269
- openAIApiKey: config.apiKey
1574
+ reasoning: this.modelConfig.reasoning
1575
+ }
1576
+ }), {
1577
+ modelName: this.modelName,
1578
+ openAIApiKey: this.providerConfig.apiKey
1579
+ }));
1580
+ // Vercel AI SDK model setup
1581
+ var openrouter = aiSdkProvider.createOpenRouter({
1582
+ apiKey: this.providerConfig.apiKey
1270
1583
  });
1584
+ this.vercelModel = openrouter(this.modelName, _object_spread({}, this.modelConfig.maxTokens && {
1585
+ maxTokens: this.modelConfig.maxTokens
1586
+ }, this.modelConfig.reasoning && {
1587
+ extraBody: {
1588
+ reasoning: this.modelConfig.reasoning
1589
+ }
1590
+ }));
1271
1591
  }
1272
- _create_class$3(OpenRouterModelAdapter, [
1592
+ _create_class$4(OpenRouterModel, [
1593
+ {
1594
+ /**
1595
+ * Get the configured LangChain language model instance
1596
+ */ key: "getLangchainModel",
1597
+ value: function getLangchainModel() {
1598
+ return this.langchainModel;
1599
+ }
1600
+ },
1273
1601
  {
1274
- key: "getModel",
1275
- value: function getModel() {
1276
- return this.model;
1602
+ /**
1603
+ * Get the configured Vercel AI SDK language model instance
1604
+ */ key: "getVercelModel",
1605
+ value: function getVercelModel() {
1606
+ return this.vercelModel;
1277
1607
  }
1278
1608
  }
1279
1609
  ]);
1280
- return OpenRouterModelAdapter;
1610
+ return OpenRouterModel;
1281
1611
  }();
1282
1612
 
1283
1613
  /**
@@ -1412,6 +1742,60 @@ var PROMPT_LIBRARY = {
1412
1742
  VERBOSITY: VERBOSITY
1413
1743
  };
1414
1744
 
1745
+ function _class_call_check$3(instance, Constructor) {
1746
+ if (!(instance instanceof Constructor)) {
1747
+ throw new TypeError("Cannot call a class as a function");
1748
+ }
1749
+ }
1750
+ function _defineProperties$3(target, props) {
1751
+ for(var i = 0; i < props.length; i++){
1752
+ var descriptor = props[i];
1753
+ descriptor.enumerable = descriptor.enumerable || false;
1754
+ descriptor.configurable = true;
1755
+ if ("value" in descriptor) descriptor.writable = true;
1756
+ Object.defineProperty(target, descriptor.key, descriptor);
1757
+ }
1758
+ }
1759
+ function _create_class$3(Constructor, protoProps, staticProps) {
1760
+ if (protoProps) _defineProperties$3(Constructor.prototype, protoProps);
1761
+ return Constructor;
1762
+ }
1763
+ function _define_property$3(obj, key, value) {
1764
+ if (key in obj) {
1765
+ Object.defineProperty(obj, key, {
1766
+ value: value,
1767
+ enumerable: true,
1768
+ configurable: true,
1769
+ writable: true
1770
+ });
1771
+ } else {
1772
+ obj[key] = value;
1773
+ }
1774
+ return obj;
1775
+ }
1776
+ /**
1777
+ * System prompt that generates a system prompt from a list of strings
1778
+ */ var SystemPrompt = /*#__PURE__*/ function() {
1779
+ function SystemPrompt() {
1780
+ for(var _len = arguments.length, prompts = new Array(_len), _key = 0; _key < _len; _key++){
1781
+ prompts[_key] = arguments[_key];
1782
+ }
1783
+ _class_call_check$3(this, SystemPrompt);
1784
+ _define_property$3(this, "finalPrompt", void 0);
1785
+ var flattenedPrompts = prompts.flat();
1786
+ this.finalPrompt = flattenedPrompts.join('\n\n');
1787
+ }
1788
+ _create_class$3(SystemPrompt, [
1789
+ {
1790
+ key: "generate",
1791
+ value: function generate() {
1792
+ return this.finalPrompt;
1793
+ }
1794
+ }
1795
+ ]);
1796
+ return SystemPrompt;
1797
+ }();
1798
+
1415
1799
  function _class_call_check$2(instance, Constructor) {
1416
1800
  if (!(instance instanceof Constructor)) {
1417
1801
  throw new TypeError("Cannot call a class as a function");
@@ -1444,18 +1828,18 @@ function _define_property$2(obj, key, value) {
1444
1828
  return obj;
1445
1829
  }
1446
1830
  /**
1447
- * System prompt adapter that generates a system prompt from a list of strings
1448
- */ var SystemPromptAdapter = /*#__PURE__*/ function() {
1449
- function SystemPromptAdapter() {
1831
+ * User prompt that generates a user prompt from a list of strings
1832
+ */ var UserPrompt = /*#__PURE__*/ function() {
1833
+ function UserPrompt() {
1450
1834
  for(var _len = arguments.length, prompts = new Array(_len), _key = 0; _key < _len; _key++){
1451
1835
  prompts[_key] = arguments[_key];
1452
1836
  }
1453
- _class_call_check$2(this, SystemPromptAdapter);
1837
+ _class_call_check$2(this, UserPrompt);
1454
1838
  _define_property$2(this, "finalPrompt", void 0);
1455
1839
  var flattenedPrompts = prompts.flat();
1456
1840
  this.finalPrompt = flattenedPrompts.join('\n\n');
1457
1841
  }
1458
- _create_class$2(SystemPromptAdapter, [
1842
+ _create_class$2(UserPrompt, [
1459
1843
  {
1460
1844
  key: "generate",
1461
1845
  value: function generate() {
@@ -1463,7 +1847,7 @@ function _define_property$2(obj, key, value) {
1463
1847
  }
1464
1848
  }
1465
1849
  ]);
1466
- return SystemPromptAdapter;
1850
+ return UserPrompt;
1467
1851
  }();
1468
1852
 
1469
1853
  function _class_call_check$1(instance, Constructor) {
@@ -1498,26 +1882,25 @@ function _define_property$1(obj, key, value) {
1498
1882
  return obj;
1499
1883
  }
1500
1884
  /**
1501
- * User prompt adapter that generates a user prompt from a list of strings
1502
- */ var UserPromptAdapter = /*#__PURE__*/ function() {
1503
- function UserPromptAdapter() {
1504
- for(var _len = arguments.length, prompts = new Array(_len), _key = 0; _key < _len; _key++){
1505
- prompts[_key] = arguments[_key];
1506
- }
1507
- _class_call_check$1(this, UserPromptAdapter);
1508
- _define_property$1(this, "finalPrompt", void 0);
1509
- var flattenedPrompts = prompts.flat();
1510
- this.finalPrompt = flattenedPrompts.join('\n\n');
1885
+ * OpenRouter provider that manages connection configuration
1886
+ */ var OpenRouterProvider = /*#__PURE__*/ function() {
1887
+ function OpenRouterProvider(config) {
1888
+ _class_call_check$1(this, OpenRouterProvider);
1889
+ _define_property$1(this, "config", void 0);
1890
+ this.config = config;
1511
1891
  }
1512
- _create_class$1(UserPromptAdapter, [
1892
+ _create_class$1(OpenRouterProvider, [
1513
1893
  {
1514
- key: "generate",
1515
- value: function generate() {
1516
- return this.finalPrompt;
1894
+ /**
1895
+ * Get a model instance for the specified model name
1896
+ */ key: "getModel",
1897
+ value: function getModel(modelName) {
1898
+ var modelConfig = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1899
+ return new OpenRouterModel(this.config, modelName, modelConfig);
1517
1900
  }
1518
1901
  }
1519
1902
  ]);
1520
- return UserPromptAdapter;
1903
+ return OpenRouterProvider;
1521
1904
  }();
1522
1905
 
1523
1906
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
@@ -1679,11 +2062,11 @@ function _ts_generator(thisArg, body) {
1679
2062
  }
1680
2063
  }
1681
2064
  /**
1682
- * Safe tool adapter that provides error handling and logging for LangChain tools
1683
- */ var SafeToolAdapter = /*#__PURE__*/ function() {
1684
- function SafeToolAdapter(config) {
2065
+ * Safe tool that provides error handling and logging for LangChain tools
2066
+ */ var SafeTool = /*#__PURE__*/ function() {
2067
+ function SafeTool(config) {
1685
2068
  var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1686
- _class_call_check(this, SafeToolAdapter);
2069
+ _class_call_check(this, SafeTool);
1687
2070
  _define_property(this, "config", void 0);
1688
2071
  _define_property(this, "options", void 0);
1689
2072
  _define_property(this, "dynamicTool", void 0);
@@ -1786,7 +2169,7 @@ function _ts_generator(thisArg, body) {
1786
2169
  });
1787
2170
  }
1788
2171
  }
1789
- _create_class(SafeToolAdapter, [
2172
+ _create_class(SafeTool, [
1790
2173
  {
1791
2174
  /**
1792
2175
  * Get the underlying LangChain DynamicTool instance
@@ -1796,14 +2179,16 @@ function _ts_generator(thisArg, body) {
1796
2179
  }
1797
2180
  }
1798
2181
  ]);
1799
- return SafeToolAdapter;
2182
+ return SafeTool;
1800
2183
  }();
1801
2184
 
1802
- exports.AIResponseParser = AIResponseParser;
1803
- exports.AutonomousAgentAdapter = AutonomousAgentAdapter;
1804
- exports.BasicAgentAdapter = BasicAgentAdapter;
1805
- exports.OpenRouterAdapter = OpenRouterModelAdapter;
1806
- exports.PROMPT_LIBRARY = PROMPT_LIBRARY;
1807
- exports.SafeToolAdapter = SafeToolAdapter;
1808
- exports.SystemPromptAdapter = SystemPromptAdapter;
1809
- exports.UserPromptAdapter = UserPromptAdapter;
2185
+ exports.ChatAgent = ChatAgent;
2186
+ exports.OpenRouterModel = OpenRouterModel;
2187
+ exports.OpenRouterProvider = OpenRouterProvider;
2188
+ exports.PROMPTS = PROMPT_LIBRARY;
2189
+ exports.ResilientAgent = ResilientAgent;
2190
+ exports.SafeTool = SafeTool;
2191
+ exports.StructuredResponseParser = StructuredResponseParser;
2192
+ exports.SystemPrompt = SystemPrompt;
2193
+ exports.ToolAgent = ToolAgent;
2194
+ exports.UserPrompt = UserPrompt;