@jterrazz/intelligence 1.0.0 → 1.1.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 (71) hide show
  1. package/README.md +111 -14
  2. package/dist/adapters/agents/chat-agent.adapter.d.ts +20 -26
  3. package/dist/adapters/agents/chat-agent.adapter.js +99 -129
  4. package/dist/adapters/agents/chat-agent.adapter.js.map +1 -1
  5. package/dist/adapters/agents/query-agent.adapter.d.ts +26 -0
  6. package/dist/adapters/agents/query-agent.adapter.js +303 -0
  7. package/dist/adapters/agents/query-agent.adapter.js.map +1 -0
  8. package/dist/adapters/models/openrouter-model.adapter.d.ts +16 -6
  9. package/dist/adapters/models/openrouter-model.adapter.js +7 -4
  10. package/dist/adapters/models/openrouter-model.adapter.js.map +1 -1
  11. package/dist/adapters/prompts/__tests__/__snapshots__/presets.test.ts.snap +73 -103
  12. package/dist/adapters/prompts/__tests__/presets.test.js +1 -1
  13. package/dist/adapters/prompts/__tests__/presets.test.js.map +1 -1
  14. package/dist/adapters/prompts/library/categories/domain.d.ts +8 -8
  15. package/dist/adapters/prompts/library/categories/domain.js +8 -8
  16. package/dist/adapters/prompts/library/categories/domain.js.map +1 -1
  17. package/dist/adapters/prompts/library/categories/format.d.ts +7 -6
  18. package/dist/adapters/prompts/library/categories/format.js +7 -6
  19. package/dist/adapters/prompts/library/categories/format.js.map +1 -1
  20. package/dist/adapters/prompts/library/categories/foundations.d.ts +9 -0
  21. package/dist/adapters/prompts/library/categories/foundations.js +10 -0
  22. package/dist/adapters/prompts/library/categories/foundations.js.map +1 -0
  23. package/dist/adapters/prompts/library/categories/language.d.ts +8 -8
  24. package/dist/adapters/prompts/library/categories/language.js +8 -8
  25. package/dist/adapters/prompts/library/categories/language.js.map +1 -1
  26. package/dist/adapters/prompts/library/categories/persona.d.ts +8 -8
  27. package/dist/adapters/prompts/library/categories/persona.js +8 -8
  28. package/dist/adapters/prompts/library/categories/persona.js.map +1 -1
  29. package/dist/adapters/prompts/library/categories/response.d.ts +9 -0
  30. package/dist/adapters/prompts/library/categories/response.js +10 -0
  31. package/dist/adapters/prompts/library/categories/response.js.map +1 -0
  32. package/dist/adapters/prompts/library/categories/tone.d.ts +5 -5
  33. package/dist/adapters/prompts/library/categories/tone.js +5 -5
  34. package/dist/adapters/prompts/library/categories/tone.js.map +1 -1
  35. package/dist/adapters/prompts/library/categories/verbosity.d.ts +3 -3
  36. package/dist/adapters/prompts/library/categories/verbosity.js +3 -3
  37. package/dist/adapters/prompts/library/categories/verbosity.js.map +1 -1
  38. package/dist/adapters/prompts/library/index.d.ts +53 -56
  39. package/dist/adapters/prompts/library/index.js +15 -17
  40. package/dist/adapters/prompts/library/index.js.map +1 -1
  41. package/dist/adapters/prompts/library/presets.d.ts +5 -5
  42. package/dist/adapters/prompts/library/presets.js +27 -33
  43. package/dist/adapters/prompts/library/presets.js.map +1 -1
  44. package/dist/adapters/prompts/system-prompt.adapter.d.ts +2 -2
  45. package/dist/adapters/prompts/system-prompt.adapter.js.map +1 -1
  46. package/dist/adapters/prompts/user-prompt.adapter.d.ts +2 -2
  47. package/dist/adapters/prompts/user-prompt.adapter.js.map +1 -1
  48. package/dist/adapters/tools/safe-tool.adapter.d.ts +2 -2
  49. package/dist/adapters/tools/safe-tool.adapter.js.map +1 -1
  50. package/dist/index.cjs +514 -258
  51. package/dist/index.d.ts +1 -0
  52. package/dist/index.js +1 -0
  53. package/dist/index.js.map +1 -1
  54. package/dist/ports/agent.port.d.ts +3 -3
  55. package/dist/ports/agent.port.js.map +1 -1
  56. package/dist/ports/model.port.d.ts +1 -1
  57. package/dist/ports/model.port.js.map +1 -1
  58. package/dist/ports/prompt.port.d.ts +1 -1
  59. package/dist/ports/prompt.port.js.map +1 -1
  60. package/dist/ports/tool.port.d.ts +1 -1
  61. package/dist/ports/tool.port.js.map +1 -1
  62. package/package.json +1 -1
  63. package/dist/adapters/prompts/library/categories/agent-logic.d.ts +0 -8
  64. package/dist/adapters/prompts/library/categories/agent-logic.js +0 -9
  65. package/dist/adapters/prompts/library/categories/agent-logic.js.map +0 -1
  66. package/dist/adapters/prompts/library/categories/agent-skills.d.ts +0 -8
  67. package/dist/adapters/prompts/library/categories/agent-skills.js +0 -9
  68. package/dist/adapters/prompts/library/categories/agent-skills.js.map +0 -1
  69. package/dist/adapters/prompts/library/categories/directives.d.ts +0 -9
  70. package/dist/adapters/prompts/library/categories/directives.js +0 -10
  71. package/dist/adapters/prompts/library/categories/directives.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -18,7 +18,7 @@ function _call_super(_this, derived, args) {
18
18
  derived = _get_prototype_of(derived);
19
19
  return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
20
20
  }
21
- function _class_call_check$6(instance, Constructor) {
21
+ function _class_call_check$7(instance, Constructor) {
22
22
  if (!(instance instanceof Constructor)) {
23
23
  throw new TypeError("Cannot call a class as a function");
24
24
  }
@@ -40,7 +40,7 @@ function _construct(Parent, args, Class) {
40
40
  }
41
41
  return _construct.apply(null, arguments);
42
42
  }
43
- function _define_property$6(obj, key, value) {
43
+ function _define_property$7(obj, key, value) {
44
44
  if (key in obj) {
45
45
  Object.defineProperty(obj, key, {
46
46
  value: value,
@@ -76,7 +76,7 @@ function _is_native_function(fn) {
76
76
  return Function.toString.call(fn).indexOf("[native code]") !== -1;
77
77
  }
78
78
  function _possible_constructor_return(self, call) {
79
- if (call && (_type_of$2(call) === "object" || typeof call === "function")) {
79
+ if (call && (_type_of$1(call) === "object" || typeof call === "function")) {
80
80
  return call;
81
81
  }
82
82
  return _assert_this_initialized(self);
@@ -88,7 +88,7 @@ function _set_prototype_of(o, p) {
88
88
  };
89
89
  return _set_prototype_of(o, p);
90
90
  }
91
- function _type_of$2(obj) {
91
+ function _type_of$1(obj) {
92
92
  "@swc/helpers - typeof";
93
93
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
94
94
  }
@@ -129,11 +129,11 @@ function _is_native_reflect_construct() {
129
129
  var AIResponseParserError = /*#__PURE__*/ function(Error1) {
130
130
  _inherits(AIResponseParserError, Error1);
131
131
  function AIResponseParserError(message, cause, text) {
132
- _class_call_check$6(this, AIResponseParserError);
132
+ _class_call_check$7(this, AIResponseParserError);
133
133
  var _this;
134
134
  _this = _call_super(this, AIResponseParserError, [
135
135
  message
136
- ]), _define_property$6(_this, "cause", void 0), _define_property$6(_this, "text", void 0), _this.cause = cause, _this.text = text;
136
+ ]), _define_property$7(_this, "cause", void 0), _define_property$7(_this, "text", void 0), _this.cause = cause, _this.text = text;
137
137
  _this.name = 'AIResponseParserError';
138
138
  return _this;
139
139
  }
@@ -148,12 +148,12 @@ function _array_like_to_array(arr, len) {
148
148
  function _array_with_holes(arr) {
149
149
  if (Array.isArray(arr)) return arr;
150
150
  }
151
- function _class_call_check$5(instance, Constructor) {
151
+ function _class_call_check$6(instance, Constructor) {
152
152
  if (!(instance instanceof Constructor)) {
153
153
  throw new TypeError("Cannot call a class as a function");
154
154
  }
155
155
  }
156
- function _defineProperties$5(target, props) {
156
+ function _defineProperties$6(target, props) {
157
157
  for(var i = 0; i < props.length; i++){
158
158
  var descriptor = props[i];
159
159
  descriptor.enumerable = descriptor.enumerable || false;
@@ -162,11 +162,11 @@ function _defineProperties$5(target, props) {
162
162
  Object.defineProperty(target, descriptor.key, descriptor);
163
163
  }
164
164
  }
165
- function _create_class$5(Constructor, protoProps, staticProps) {
166
- if (protoProps) _defineProperties$5(Constructor.prototype, protoProps);
165
+ function _create_class$6(Constructor, protoProps, staticProps) {
166
+ if (protoProps) _defineProperties$6(Constructor.prototype, protoProps);
167
167
  return Constructor;
168
168
  }
169
- function _define_property$5(obj, key, value) {
169
+ function _define_property$6(obj, key, value) {
170
170
  if (key in obj) {
171
171
  Object.defineProperty(obj, key, {
172
172
  value: value,
@@ -179,7 +179,7 @@ function _define_property$5(obj, key, value) {
179
179
  }
180
180
  return obj;
181
181
  }
182
- function _instanceof$2(left, right) {
182
+ function _instanceof$3(left, right) {
183
183
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
184
184
  return !!right[Symbol.hasInstance](left);
185
185
  } else {
@@ -216,7 +216,7 @@ function _non_iterable_rest() {
216
216
  function _sliced_to_array(arr, i) {
217
217
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
218
218
  }
219
- function _type_of$1(obj) {
219
+ function _type_of(obj) {
220
220
  "@swc/helpers - typeof";
221
221
  return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
222
222
  }
@@ -232,11 +232,11 @@ function _unsupported_iterable_to_array(o, minLen) {
232
232
  * Parses AI response text into structured data based on Zod schema
233
233
  */ var AIResponseParser = /*#__PURE__*/ function() {
234
234
  function AIResponseParser(schema) {
235
- _class_call_check$5(this, AIResponseParser);
236
- _define_property$5(this, "schema", void 0);
235
+ _class_call_check$6(this, AIResponseParser);
236
+ _define_property$6(this, "schema", void 0);
237
237
  this.schema = schema;
238
238
  }
239
- _create_class$5(AIResponseParser, [
239
+ _create_class$6(AIResponseParser, [
240
240
  {
241
241
  key: "parse",
242
242
  value: /**
@@ -248,7 +248,7 @@ function _unsupported_iterable_to_array(o, minLen) {
248
248
  var unescapedJson = this.unescapeJsonValues(json);
249
249
  return this.schema.parse(unescapedJson);
250
250
  } catch (error) {
251
- if (_instanceof$2(error, v4.z.ZodError)) {
251
+ if (_instanceof$3(error, v4.z.ZodError)) {
252
252
  throw new AIResponseParserError('Failed to validate response against schema', error, text);
253
253
  }
254
254
  throw error;
@@ -288,16 +288,16 @@ function _unsupported_iterable_to_array(o, minLen) {
288
288
  value: /**
289
289
  * Converts value to appropriate primitive type based on schema
290
290
  */ function convertToPrimitive(value, schema) {
291
- if (_instanceof$2(schema, v4.z.ZodString)) {
291
+ if (_instanceof$3(schema, v4.z.ZodString)) {
292
292
  return String(value);
293
293
  }
294
- if (_instanceof$2(schema, v4.z.ZodNumber)) {
294
+ if (_instanceof$3(schema, v4.z.ZodNumber)) {
295
295
  return Number(value);
296
296
  }
297
- if (_instanceof$2(schema, v4.z.ZodBoolean)) {
297
+ if (_instanceof$3(schema, v4.z.ZodBoolean)) {
298
298
  return Boolean(value);
299
299
  }
300
- if (_instanceof$2(schema, v4.z.ZodNull)) {
300
+ if (_instanceof$3(schema, v4.z.ZodNull)) {
301
301
  return null;
302
302
  }
303
303
  return value;
@@ -340,13 +340,13 @@ function _unsupported_iterable_to_array(o, minLen) {
340
340
  value: /**
341
341
  * Extracts and parses JSON from text based on schema type
342
342
  */ function extractJsonFromText(text) {
343
- if (_instanceof$2(this.schema, v4.z.ZodArray)) {
343
+ if (_instanceof$3(this.schema, v4.z.ZodArray)) {
344
344
  return this.extractArray(text);
345
345
  }
346
- if (_instanceof$2(this.schema, v4.z.ZodObject)) {
346
+ if (_instanceof$3(this.schema, v4.z.ZodObject)) {
347
347
  return this.extractObject(text);
348
348
  }
349
- if (_instanceof$2(this.schema, v4.z.ZodString) || _instanceof$2(this.schema, v4.z.ZodNumber) || _instanceof$2(this.schema, v4.z.ZodBoolean) || _instanceof$2(this.schema, v4.z.ZodNull)) {
349
+ 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)) {
350
350
  return this.extractPrimitive(text, this.schema);
351
351
  }
352
352
  throw new AIResponseParserError('Unsupported schema type', undefined, text);
@@ -438,7 +438,7 @@ function _unsupported_iterable_to_array(o, minLen) {
438
438
  return _this.unescapeJsonValues(item);
439
439
  });
440
440
  }
441
- if ((typeof json === "undefined" ? "undefined" : _type_of$1(json)) === 'object' && json !== null) {
441
+ if ((typeof json === "undefined" ? "undefined" : _type_of(json)) === 'object' && json !== null) {
442
442
  return Object.fromEntries(Object.entries(json).map(function(param) {
443
443
  var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
444
444
  return [
@@ -469,7 +469,7 @@ function _unsupported_iterable_to_array(o, minLen) {
469
469
  return AIResponseParser;
470
470
  }();
471
471
 
472
- function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
472
+ function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
473
473
  try {
474
474
  var info = gen[key](arg);
475
475
  var value = info.value;
@@ -483,27 +483,27 @@ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
483
483
  Promise.resolve(value).then(_next, _throw);
484
484
  }
485
485
  }
486
- function _async_to_generator$1(fn) {
486
+ function _async_to_generator$2(fn) {
487
487
  return function() {
488
488
  var self = this, args = arguments;
489
489
  return new Promise(function(resolve, reject) {
490
490
  var gen = fn.apply(self, args);
491
491
  function _next(value) {
492
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
492
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
493
493
  }
494
494
  function _throw(err) {
495
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
495
+ asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
496
496
  }
497
497
  _next(undefined);
498
498
  });
499
499
  };
500
500
  }
501
- function _class_call_check$4(instance, Constructor) {
501
+ function _class_call_check$5(instance, Constructor) {
502
502
  if (!(instance instanceof Constructor)) {
503
503
  throw new TypeError("Cannot call a class as a function");
504
504
  }
505
505
  }
506
- function _defineProperties$4(target, props) {
506
+ function _defineProperties$5(target, props) {
507
507
  for(var i = 0; i < props.length; i++){
508
508
  var descriptor = props[i];
509
509
  descriptor.enumerable = descriptor.enumerable || false;
@@ -512,11 +512,11 @@ function _defineProperties$4(target, props) {
512
512
  Object.defineProperty(target, descriptor.key, descriptor);
513
513
  }
514
514
  }
515
- function _create_class$4(Constructor, protoProps, staticProps) {
516
- if (protoProps) _defineProperties$4(Constructor.prototype, protoProps);
515
+ function _create_class$5(Constructor, protoProps, staticProps) {
516
+ if (protoProps) _defineProperties$5(Constructor.prototype, protoProps);
517
517
  return Constructor;
518
518
  }
519
- function _define_property$4(obj, key, value) {
519
+ function _define_property$5(obj, key, value) {
520
520
  if (key in obj) {
521
521
  Object.defineProperty(obj, key, {
522
522
  value: value,
@@ -529,18 +529,14 @@ function _define_property$4(obj, key, value) {
529
529
  }
530
530
  return obj;
531
531
  }
532
- function _instanceof$1(left, right) {
532
+ function _instanceof$2(left, right) {
533
533
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
534
534
  return !!right[Symbol.hasInstance](left);
535
535
  } else {
536
536
  return left instanceof right;
537
537
  }
538
538
  }
539
- function _type_of(obj) {
540
- "@swc/helpers - typeof";
541
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
542
- }
543
- function _ts_generator$1(thisArg, body) {
539
+ function _ts_generator$2(thisArg, body) {
544
540
  var f, y, t, _ = {
545
541
  label: 0,
546
542
  sent: function() {
@@ -631,84 +627,88 @@ function _ts_generator$1(thisArg, body) {
631
627
  };
632
628
  }
633
629
  }
634
- // Schema for agent responses
635
- var AgentResponseSchema = v4.z.object({
636
- message: v4.z.string().optional(),
637
- reason: v4.z.string().optional(),
638
- shouldRespond: v4.z["boolean"]()
639
- });
640
- // LangChain-specific framework rules (internal to this adapter)
641
- var LANGCHAIN_FRAMEWORK_RULES = '\n<AGENT_FRAMEWORK>\nYou are a chat agent piloted by the LangChain framework.\n\nYou have access to the following tools: {tools}\nTool names: {tool_names}\nAgent scratchpad: {agent_scratchpad}\n\nWhen you want to provide your final response, you MUST format it exactly like this:\n\n```json\n{{"action": "Final Answer", "action_input": {{"shouldRespond": false, "reason": "<your reason>"}}}}\n```\n\nOR \n\n```json\n{{"action": "Final Answer", "action_input": {{"shouldRespond": true, "message": "<your response message>"}}}}\n```\n\n"shouldRespond" set to true means the message will be sent to the user.\n"shouldRespond" set to false means the message will not be sent to the user.\n\nALWAYS use this exact format with markdown code blocks and the action/action_input structure.\n</AGENT_FRAMEWORK>';
630
+ var SYSTEM_PROMPT_TEMPLATE = '\n<OBJECTIVE>\n{mission_prompt}\n</OBJECTIVE>\n\n<OUTPUT_FORMAT>\nCRITICAL: The format instructions in this section are the ONLY valid way to structure your response. Any formatting guidelines within the <OBJECTIVE> section (like message templates) apply ONLY to the content that goes inside the "RESPOND: " part of your final answer.\n\nYou 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. The input must start with "RESPOND: " or "SILENT: ".\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</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';
642
631
  /**
643
- * Chat agent adapter that provides structured chat capabilities with optional responses
632
+ * An advanced agent that uses tools and a structured prompt to engage in conversational chat.
633
+ * It can decide whether to respond or remain silent and supports schema-validated responses.
644
634
  */ var ChatAgentAdapter = /*#__PURE__*/ function() {
645
- function ChatAgentAdapter(name, systemPrompt, options) {
646
- _class_call_check$4(this, ChatAgentAdapter);
647
- _define_property$4(this, "executorPromise", void 0);
648
- _define_property$4(this, "logger", void 0);
649
- _define_property$4(this, "name", void 0);
650
- _define_property$4(this, "responseParser", void 0);
635
+ function ChatAgentAdapter(name, options) {
636
+ _class_call_check$5(this, ChatAgentAdapter);
637
+ _define_property$5(this, "name", void 0);
638
+ _define_property$5(this, "options", void 0);
651
639
  this.name = name;
652
- this.logger = options.logger;
653
- this.responseParser = new AIResponseParser(AgentResponseSchema);
654
- this.executorPromise = this.createExecutor(systemPrompt, options);
640
+ this.options = options;
655
641
  }
656
- _create_class$4(ChatAgentAdapter, [
642
+ _create_class$5(ChatAgentAdapter, [
657
643
  {
658
644
  key: "run",
659
645
  value: function run(userPrompt) {
660
- return _async_to_generator$1(function() {
661
- var _this_logger, executor, input, result, response, error, _this_logger1;
662
- return _ts_generator$1(this, function(_state) {
646
+ return _async_to_generator$2(function() {
647
+ var _this_options_logger, _this_options_logger1, executor, userInput, result, agentResponse, _this_options_logger2, _agentResponse_message, message, _this_options_logger3, _this_options_logger4, error, _this_options_logger5;
648
+ return _ts_generator$2(this, function(_state) {
663
649
  switch(_state.label){
664
650
  case 0:
651
+ (_this_options_logger = this.options.logger) === null || _this_options_logger === void 0 ? void 0 : _this_options_logger.debug("[".concat(this.name, "] Starting chat execution."));
652
+ _state.label = 1;
653
+ case 1:
665
654
  _state.trys.push([
666
- 0,
667
- 3,
655
+ 1,
656
+ 4,
668
657
  ,
669
- 4
658
+ 5
670
659
  ]);
671
660
  return [
672
661
  4,
673
- this.executorPromise
662
+ this.createExecutor()
674
663
  ];
675
- case 1:
664
+ case 2:
676
665
  executor = _state.sent();
677
- input = this.resolveUserInput(userPrompt);
666
+ userInput = this.resolveUserInput(userPrompt);
678
667
  return [
679
668
  4,
680
669
  executor.invoke({
681
- input: input
670
+ input: userInput
682
671
  })
683
672
  ];
684
- case 2:
673
+ case 3:
685
674
  result = _state.sent();
686
- (_this_logger = this.logger) === null || _this_logger === void 0 ? void 0 : _this_logger.debug('Agent execution result', {
687
- agentName: this.name,
688
- hasOutput: 'output' in result,
689
- hasUserPrompt: !!userPrompt,
690
- outputType: _type_of(result.output)
675
+ (_this_options_logger1 = this.options.logger) === null || _this_options_logger1 === void 0 ? void 0 : _this_options_logger1.debug("[".concat(this.name, "] Agent execution completed."), {
676
+ hasOutput: 'output' in result
691
677
  });
692
- if (!result || typeof result.output === 'undefined') {
693
- throw new Error('Agent returned invalid result structure');
678
+ if (!result || typeof result.output !== 'string') {
679
+ throw new Error('Agent returned an invalid result structure.');
680
+ }
681
+ agentResponse = this.parseAgentOutput(result.output);
682
+ if (!agentResponse.shouldRespond) {
683
+ (_this_options_logger2 = this.options.logger) === null || _this_options_logger2 === void 0 ? void 0 : _this_options_logger2.info("[".concat(this.name, "] Agent chose to remain silent."), {
684
+ reason: agentResponse.reason
685
+ });
686
+ return [
687
+ 2,
688
+ null
689
+ ];
690
+ }
691
+ message = (_agentResponse_message = agentResponse.message) !== null && _agentResponse_message !== void 0 ? _agentResponse_message : '';
692
+ if (this.options.schema) {
693
+ this.validateResponseContent(message, this.options.schema);
694
+ (_this_options_logger3 = this.options.logger) === null || _this_options_logger3 === void 0 ? void 0 : _this_options_logger3.info("[".concat(this.name, "] Execution finished; response content validated."));
695
+ } else {
696
+ (_this_options_logger4 = this.options.logger) === null || _this_options_logger4 === void 0 ? void 0 : _this_options_logger4.info("[".concat(this.name, "] Execution finished."));
694
697
  }
695
- response = this.parseAgentResponse(result.output);
696
698
  return [
697
699
  2,
698
- this.handleResponse(response)
700
+ message
699
701
  ];
700
- case 3:
702
+ case 4:
701
703
  error = _state.sent();
702
- (_this_logger1 = this.logger) === null || _this_logger1 === void 0 ? void 0 : _this_logger1.error('Error running chat agent', {
703
- agentName: this.name,
704
- error: _instanceof$1(error, Error) ? error.message : 'Unknown error',
705
- userPrompt: userPrompt ? 'Prompt object' : 'none'
704
+ (_this_options_logger5 = this.options.logger) === null || _this_options_logger5 === void 0 ? void 0 : _this_options_logger5.error("[".concat(this.name, "] Chat execution failed."), {
705
+ error: _instanceof$2(error, Error) ? error.message : 'Unknown error'
706
706
  });
707
707
  return [
708
708
  2,
709
709
  null
710
710
  ];
711
- case 4:
711
+ case 5:
712
712
  return [
713
713
  2
714
714
  ];
@@ -719,31 +719,32 @@ var LANGCHAIN_FRAMEWORK_RULES = '\n<AGENT_FRAMEWORK>\nYou are a chat agent pilot
719
719
  },
720
720
  {
721
721
  key: "createExecutor",
722
- value: function createExecutor(systemPrompt, options) {
723
- return _async_to_generator$1(function() {
724
- var model, dynamicTools, systemPromptText, systemTemplate, humanTemplate, prompt, agent;
725
- return _ts_generator$1(this, function(_state) {
722
+ value: function createExecutor() {
723
+ return _async_to_generator$2(function() {
724
+ var model, tools, prompt, agent;
725
+ return _ts_generator$2(this, function(_state) {
726
726
  switch(_state.label){
727
727
  case 0:
728
- model = options.model.getModel();
729
- // Convert Tool instances to DynamicTool instances
730
- dynamicTools = options.tools.map(function(tool) {
728
+ model = this.options.model.getModel();
729
+ tools = this.options.tools.map(function(tool) {
731
730
  return tool.getDynamicTool();
732
731
  });
733
- // Combine LangChain framework rules with user-provided system prompts
734
- systemPromptText = "".concat(LANGCHAIN_FRAMEWORK_RULES, "\n\n").concat(systemPrompt.generate());
735
- systemTemplate = prompts.SystemMessagePromptTemplate.fromTemplate(systemPromptText);
736
- humanTemplate = prompts.HumanMessagePromptTemplate.fromTemplate('{input}');
737
732
  prompt = prompts.ChatPromptTemplate.fromMessages([
738
- systemTemplate,
739
- humanTemplate
733
+ [
734
+ 'system',
735
+ SYSTEM_PROMPT_TEMPLATE.replace('{mission_prompt}', this.options.systemPrompt.generate())
736
+ ],
737
+ [
738
+ 'human',
739
+ '{input}'
740
+ ]
740
741
  ]);
741
742
  return [
742
743
  4,
743
744
  agents.createStructuredChatAgent({
744
745
  llm: model,
745
746
  prompt: prompt,
746
- tools: dynamicTools
747
+ tools: tools
747
748
  })
748
749
  ];
749
750
  case 1:
@@ -752,102 +753,365 @@ var LANGCHAIN_FRAMEWORK_RULES = '\n<AGENT_FRAMEWORK>\nYou are a chat agent pilot
752
753
  2,
753
754
  agents.AgentExecutor.fromAgentAndTools({
754
755
  agent: agent,
755
- tools: dynamicTools
756
+ tools: tools,
757
+ verbose: this.options.verbose
756
758
  })
757
759
  ];
758
760
  }
759
761
  });
760
- })();
762
+ }).call(this);
761
763
  }
762
764
  },
763
765
  {
764
- key: "extractActionInput",
765
- value: function extractActionInput(output) {
766
- if ((typeof output === "undefined" ? "undefined" : _type_of(output)) === 'object' && output !== null) {
767
- return JSON.stringify(output);
768
- }
769
- if (typeof output !== 'string') {
770
- return String(output);
766
+ key: "parseAgentOutput",
767
+ value: function parseAgentOutput(output) {
768
+ var _this_options_logger;
769
+ var text = output.trim();
770
+ var respondMatch = text.match(/^RESPOND:\s*([\s\S]+)$/i);
771
+ if (respondMatch) {
772
+ return {
773
+ message: respondMatch[1].trim(),
774
+ shouldRespond: true
775
+ };
771
776
  }
772
- // Check for LangChain's action/action_input format first
773
- var codeBlockMatch = output.match(/```(?:json)?\s*([\s\S]*?)```/i);
774
- if (codeBlockMatch) {
775
- var content = codeBlockMatch[1].trim();
776
- try {
777
- var parsed = JSON.parse(content);
778
- if (parsed.action === 'Final Answer' && parsed.action_input) {
779
- return JSON.stringify(parsed.action_input);
780
- }
781
- } catch (e) {
782
- // Fall through to return original content
783
- }
784
- return content;
777
+ var silentMatch = text.match(/^SILENT:\s*([\s\S]+)$/i);
778
+ if (silentMatch) {
779
+ return {
780
+ reason: silentMatch[1].trim(),
781
+ shouldRespond: false
782
+ };
785
783
  }
786
- // Fallback: Look for "Final Answer:" pattern
787
- if (output.includes('Final Answer:')) {
788
- var actionInputMatch = output.match(/Final Answer:\s*([\s\S]*?)$/i);
789
- if (actionInputMatch) {
790
- return actionInputMatch[1].trim();
791
- }
784
+ (_this_options_logger = this.options.logger) === null || _this_options_logger === void 0 ? void 0 : _this_options_logger.warn("[".concat(this.name, "] Agent output was missing 'RESPOND:' or 'SILENT:' prefix. Treating as a direct response."), {
785
+ rawOutput: output
786
+ });
787
+ return {
788
+ message: text,
789
+ shouldRespond: true
790
+ };
791
+ }
792
+ },
793
+ {
794
+ key: "resolveUserInput",
795
+ value: function resolveUserInput(userPrompt) {
796
+ if (userPrompt) {
797
+ return userPrompt.generate();
792
798
  }
793
- return output;
799
+ return 'Proceed with your instructions.';
794
800
  }
795
801
  },
796
802
  {
797
- key: "handleResponse",
798
- value: function handleResponse(response) {
799
- var _this_logger;
800
- if (response.shouldRespond && response.message) {
801
- var _this_logger1;
802
- (_this_logger1 = this.logger) === null || _this_logger1 === void 0 ? void 0 : _this_logger1.info('Agent responding with message', {
803
- agentName: this.name
803
+ key: "validateResponseContent",
804
+ value: function validateResponseContent(content, schema) {
805
+ try {
806
+ new AIResponseParser(schema).parse(content);
807
+ } catch (error) {
808
+ var _this_options_logger;
809
+ (_this_options_logger = this.options.logger) === null || _this_options_logger === void 0 ? void 0 : _this_options_logger.error("[".concat(this.name, "] Failed to validate response content against schema."), {
810
+ error: _instanceof$2(error, Error) ? error.message : 'Unknown error',
811
+ rawContent: content
804
812
  });
805
- return response.message;
813
+ throw new Error('Invalid response content from model.');
806
814
  }
807
- if (!response.shouldRespond) {
808
- var _this_logger2;
809
- (_this_logger2 = this.logger) === null || _this_logger2 === void 0 ? void 0 : _this_logger2.info('Agent chose not to respond', {
810
- agentName: this.name,
811
- reason: response.reason
815
+ }
816
+ }
817
+ ]);
818
+ return ChatAgentAdapter;
819
+ }();
820
+
821
+ function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
822
+ try {
823
+ var info = gen[key](arg);
824
+ var value = info.value;
825
+ } catch (error) {
826
+ reject(error);
827
+ return;
828
+ }
829
+ if (info.done) {
830
+ resolve(value);
831
+ } else {
832
+ Promise.resolve(value).then(_next, _throw);
833
+ }
834
+ }
835
+ function _async_to_generator$1(fn) {
836
+ return function() {
837
+ var self = this, args = arguments;
838
+ return new Promise(function(resolve, reject) {
839
+ var gen = fn.apply(self, args);
840
+ function _next(value) {
841
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
842
+ }
843
+ function _throw(err) {
844
+ asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
845
+ }
846
+ _next(undefined);
847
+ });
848
+ };
849
+ }
850
+ function _class_call_check$4(instance, Constructor) {
851
+ if (!(instance instanceof Constructor)) {
852
+ throw new TypeError("Cannot call a class as a function");
853
+ }
854
+ }
855
+ function _defineProperties$4(target, props) {
856
+ for(var i = 0; i < props.length; i++){
857
+ var descriptor = props[i];
858
+ descriptor.enumerable = descriptor.enumerable || false;
859
+ descriptor.configurable = true;
860
+ if ("value" in descriptor) descriptor.writable = true;
861
+ Object.defineProperty(target, descriptor.key, descriptor);
862
+ }
863
+ }
864
+ function _create_class$4(Constructor, protoProps, staticProps) {
865
+ if (protoProps) _defineProperties$4(Constructor.prototype, protoProps);
866
+ return Constructor;
867
+ }
868
+ function _define_property$4(obj, key, value) {
869
+ if (key in obj) {
870
+ Object.defineProperty(obj, key, {
871
+ value: value,
872
+ enumerable: true,
873
+ configurable: true,
874
+ writable: true
875
+ });
876
+ } else {
877
+ obj[key] = value;
878
+ }
879
+ return obj;
880
+ }
881
+ function _instanceof$1(left, right) {
882
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
883
+ return !!right[Symbol.hasInstance](left);
884
+ } else {
885
+ return left instanceof right;
886
+ }
887
+ }
888
+ function _ts_generator$1(thisArg, body) {
889
+ var f, y, t, _ = {
890
+ label: 0,
891
+ sent: function() {
892
+ if (t[0] & 1) throw t[1];
893
+ return t[1];
894
+ },
895
+ trys: [],
896
+ ops: []
897
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
898
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
899
+ return this;
900
+ }), g;
901
+ function verb(n) {
902
+ return function(v) {
903
+ return step([
904
+ n,
905
+ v
906
+ ]);
907
+ };
908
+ }
909
+ function step(op) {
910
+ if (f) throw new TypeError("Generator is already executing.");
911
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
912
+ 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;
913
+ if (y = 0, t) op = [
914
+ op[0] & 2,
915
+ t.value
916
+ ];
917
+ switch(op[0]){
918
+ case 0:
919
+ case 1:
920
+ t = op;
921
+ break;
922
+ case 4:
923
+ _.label++;
924
+ return {
925
+ value: op[1],
926
+ done: false
927
+ };
928
+ case 5:
929
+ _.label++;
930
+ y = op[1];
931
+ op = [
932
+ 0
933
+ ];
934
+ continue;
935
+ case 7:
936
+ op = _.ops.pop();
937
+ _.trys.pop();
938
+ continue;
939
+ default:
940
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
941
+ _ = 0;
942
+ continue;
943
+ }
944
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
945
+ _.label = op[1];
946
+ break;
947
+ }
948
+ if (op[0] === 6 && _.label < t[1]) {
949
+ _.label = t[1];
950
+ t = op;
951
+ break;
952
+ }
953
+ if (t && _.label < t[2]) {
954
+ _.label = t[2];
955
+ _.ops.push(op);
956
+ break;
957
+ }
958
+ if (t[2]) _.ops.pop();
959
+ _.trys.pop();
960
+ continue;
961
+ }
962
+ op = body.call(thisArg, _);
963
+ } catch (e) {
964
+ op = [
965
+ 6,
966
+ e
967
+ ];
968
+ y = 0;
969
+ } finally{
970
+ f = t = 0;
971
+ }
972
+ if (op[0] & 5) throw op[1];
973
+ return {
974
+ value: op[0] ? op[1] : void 0,
975
+ done: true
976
+ };
977
+ }
978
+ }
979
+ /**
980
+ * A simple agent for direct, one-shot interactions with a model.
981
+ * It supports optional response parsing against a Zod schema but does not use tools.
982
+ */ var QueryAgentAdapter = /*#__PURE__*/ function() {
983
+ function QueryAgentAdapter(name, options) {
984
+ _class_call_check$4(this, QueryAgentAdapter);
985
+ _define_property$4(this, "name", void 0);
986
+ _define_property$4(this, "options", void 0);
987
+ this.name = name;
988
+ this.options = options;
989
+ }
990
+ _create_class$4(QueryAgentAdapter, [
991
+ {
992
+ key: "run",
993
+ value: function run(userPrompt) {
994
+ return _async_to_generator$1(function() {
995
+ var _this_options_logger, content, _this_options_logger1, _this_options_logger2, error, _this_options_logger3;
996
+ return _ts_generator$1(this, function(_state) {
997
+ switch(_state.label){
998
+ case 0:
999
+ (_this_options_logger = this.options.logger) === null || _this_options_logger === void 0 ? void 0 : _this_options_logger.debug("[".concat(this.name, "] Starting query execution."));
1000
+ _state.label = 1;
1001
+ case 1:
1002
+ _state.trys.push([
1003
+ 1,
1004
+ 3,
1005
+ ,
1006
+ 4
1007
+ ]);
1008
+ return [
1009
+ 4,
1010
+ this.invokeModel(userPrompt)
1011
+ ];
1012
+ case 2:
1013
+ content = _state.sent();
1014
+ if (this.options.schema) {
1015
+ this.parseResponse(content, this.options.schema);
1016
+ (_this_options_logger1 = this.options.logger) === null || _this_options_logger1 === void 0 ? void 0 : _this_options_logger1.info("[".concat(this.name, "] Execution finished and response parsed."));
1017
+ } else {
1018
+ (_this_options_logger2 = this.options.logger) === null || _this_options_logger2 === void 0 ? void 0 : _this_options_logger2.info("[".concat(this.name, "] Execution finished."));
1019
+ }
1020
+ return [
1021
+ 2,
1022
+ content
1023
+ ];
1024
+ case 3:
1025
+ error = _state.sent();
1026
+ (_this_options_logger3 = this.options.logger) === null || _this_options_logger3 === void 0 ? void 0 : _this_options_logger3.error("[".concat(this.name, "] Execution failed."), {
1027
+ error: _instanceof$1(error, Error) ? error.message : 'Unknown error'
1028
+ });
1029
+ return [
1030
+ 2,
1031
+ null
1032
+ ];
1033
+ case 4:
1034
+ return [
1035
+ 2
1036
+ ];
1037
+ }
812
1038
  });
813
- return null;
814
- }
815
- (_this_logger = this.logger) === null || _this_logger === void 0 ? void 0 : _this_logger.error('Invalid agent response state', {
816
- agentName: this.name,
817
- response: response
818
- });
819
- return null;
1039
+ }).call(this);
820
1040
  }
821
1041
  },
822
1042
  {
823
- key: "parseAgentResponse",
824
- value: function parseAgentResponse(output) {
1043
+ key: "invokeModel",
1044
+ value: function invokeModel(userPrompt) {
1045
+ return _async_to_generator$1(function() {
1046
+ var _this_options_logger, userInput, systemMessage, messages, _this_options_logger1, response, content;
1047
+ return _ts_generator$1(this, function(_state) {
1048
+ switch(_state.label){
1049
+ case 0:
1050
+ userInput = this.resolveUserInput(userPrompt);
1051
+ systemMessage = this.options.systemPrompt.generate();
1052
+ messages = [
1053
+ {
1054
+ content: systemMessage,
1055
+ role: 'system'
1056
+ },
1057
+ {
1058
+ content: userInput,
1059
+ role: 'user'
1060
+ }
1061
+ ];
1062
+ (_this_options_logger = this.options.logger) === null || _this_options_logger === void 0 ? void 0 : _this_options_logger.debug("[".concat(this.name, "] Invoking model..."), {
1063
+ hasSchema: !!this.options.schema
1064
+ });
1065
+ if (this.options.verbose) {
1066
+ (_this_options_logger1 = this.options.logger) === null || _this_options_logger1 === void 0 ? void 0 : _this_options_logger1.info("[".concat(this.name, "] Sending messages to model..."), {
1067
+ messages: messages
1068
+ });
1069
+ }
1070
+ return [
1071
+ 4,
1072
+ this.options.model.getModel().invoke(messages)
1073
+ ];
1074
+ case 1:
1075
+ response = _state.sent();
1076
+ content = response.content;
1077
+ if (typeof content !== 'string') {
1078
+ throw new Error('Model returned a non-string content type.');
1079
+ }
1080
+ return [
1081
+ 2,
1082
+ content
1083
+ ];
1084
+ }
1085
+ });
1086
+ }).call(this);
1087
+ }
1088
+ },
1089
+ {
1090
+ key: "parseResponse",
1091
+ value: function parseResponse(content, schema) {
825
1092
  try {
826
- // Handle LangChain's action/action_input format
827
- var processedOutput = this.extractActionInput(output);
828
- return this.responseParser.parse(processedOutput);
1093
+ new AIResponseParser(schema).parse(content);
829
1094
  } catch (error) {
830
- var _this_logger;
831
- (_this_logger = this.logger) === null || _this_logger === void 0 ? void 0 : _this_logger.error('Failed to parse agent response', {
832
- agentName: this.name,
1095
+ var _this_options_logger;
1096
+ (_this_options_logger = this.options.logger) === null || _this_options_logger === void 0 ? void 0 : _this_options_logger.error("[".concat(this.name, "] Failed to parse model response."), {
833
1097
  error: _instanceof$1(error, Error) ? error.message : 'Unknown error',
834
- rawOutput: output
1098
+ rawContent: content
835
1099
  });
836
- throw new Error('Invalid agent response format');
1100
+ throw new Error('Invalid response format from model.');
837
1101
  }
838
1102
  }
839
1103
  },
840
1104
  {
841
1105
  key: "resolveUserInput",
842
1106
  value: function resolveUserInput(userPrompt) {
843
- if (!userPrompt) {
844
- return 'Please analyze the current situation and respond if appropriate.';
1107
+ if (userPrompt) {
1108
+ return userPrompt.generate();
845
1109
  }
846
- return userPrompt.generate();
1110
+ return 'Proceed with your instructions.';
847
1111
  }
848
1112
  }
849
1113
  ]);
850
- return ChatAgentAdapter;
1114
+ return QueryAgentAdapter;
851
1115
  }();
852
1116
 
853
1117
  function _class_call_check$3(instance, Constructor) {
@@ -901,16 +1165,19 @@ function _object_spread(target) {
901
1165
  */ var OpenRouterModelAdapter = /*#__PURE__*/ function() {
902
1166
  function OpenRouterModelAdapter(config) {
903
1167
  _class_call_check$3(this, OpenRouterModelAdapter);
1168
+ var _config_metadata, _config_metadata1;
904
1169
  _define_property$3(this, "model", void 0);
1170
+ var _config_maxTokens;
905
1171
  this.model = new openai.ChatOpenAI({
906
1172
  configuration: {
907
1173
  baseURL: 'https://openrouter.ai/api/v1',
908
- defaultHeaders: _object_spread({}, config.websiteUrl && {
909
- 'HTTP-Referer': config.websiteUrl
910
- }, config.title && {
911
- 'X-Title': config.title
1174
+ defaultHeaders: _object_spread({}, ((_config_metadata = config.metadata) === null || _config_metadata === void 0 ? void 0 : _config_metadata.website) && {
1175
+ 'HTTP-Referer': config.metadata.website
1176
+ }, ((_config_metadata1 = config.metadata) === null || _config_metadata1 === void 0 ? void 0 : _config_metadata1.application) && {
1177
+ 'X-Title': config.metadata.application
912
1178
  })
913
1179
  },
1180
+ maxTokens: (_config_maxTokens = config.maxTokens) !== null && _config_maxTokens !== void 0 ? _config_maxTokens : 64000,
914
1181
  modelName: config.modelName,
915
1182
  openAIApiKey: config.apiKey
916
1183
  });
@@ -927,142 +1194,130 @@ function _object_spread(target) {
927
1194
  }();
928
1195
 
929
1196
  /**
930
- * Specifies the agent's area of expertise.
931
- * This helps focus the agent's knowledge and the context of its responses.
932
- */ var DOMAIN = {
933
- ACADEMIC_RESEARCH: "\n<DOMAIN>\nYour expertise is in academic research. You are familiar with scholarly writing, peer-review processes, and formal citation methods.\n</DOMAIN>",
934
- BUSINESS_STRATEGY: "\n<DOMAIN>\nYour expertise is in business strategy, including market analysis, competitive positioning, and operational planning.\n</DOMAIN>",
935
- DATA_SCIENCE: "\n<DOMAIN>\nYour expertise is in data science, including statistical analysis, machine learning, and data visualization.\n</DOMAIN>",
936
- GENERAL: "\n<DOMAIN>\nYou are a generalist with broad knowledge across many subjects.\n</DOMAIN>",
937
- SOFTWARE_ENGINEERING: "\n<DOMAIN>\nYour expertise is in software engineering, including programming languages, system architecture, design patterns, and development best practices.\n</DOMAIN>"
1197
+ * Specifies the agent's area of knowledge and expertise.
1198
+ * This focuses the agent's responses within a specific context.
1199
+ */ var DOMAINS = {
1200
+ ACADEMIC_RESEARCH: "\n<Domain>\nYour knowledge is specialized in academic research. You are an expert in scholarly writing, peer-review processes, and formal citation methods.\n</Domain>",
1201
+ BUSINESS_STRATEGY: "\n<Domain>\nYour knowledge is specialized in business strategy, including market analysis, competitive positioning, and operational planning.\n</Domain>",
1202
+ DATA_SCIENCE: "\n<Domain>\nYour knowledge is specialized in data science, including statistical analysis, machine learning, and data visualization.\n</Domain>",
1203
+ GENERAL: "\n<Domain>\nYou possess broad, generalist knowledge across a wide variety of subjects.\n</Domain>",
1204
+ SOFTWARE_ENGINEERING: "\n<Domain>\nYour knowledge is specialized in software engineering. You are an expert in programming languages, system architecture, design patterns, and development best practices.\n</Domain>"
938
1205
  };
939
1206
 
940
1207
  /**
941
- * Governs the agent's internal logic for responding and using tools.
942
- */ var AGENT_LOGIC = {
943
- ALWAYS_RESPOND: "\n<AGENT_LOGIC>\nAlways provide a response to the user's input, even if it's just to state that you cannot fulfill the request.\n</AGENT_LOGIC>",
944
- SELECTIVE_RESPONSE: "\n<AGENT_LOGIC>\nOnly respond when you can provide a valuable, relevant, and substantive contribution.\nIf a response is not necessary, state that you have nothing to add.\n</AGENT_LOGIC>",
945
- TOOL_FIRST: "\n<AGENT_LOGIC>\nBefore formulating a response, always prioritize using your available tools to gather the most current and accurate information.\n</AGENT_LOGIC>"
1208
+ * Defines the required structural format for the agent's output.
1209
+ */ var FORMATS = {
1210
+ DISCORD_MARKDOWN: "\n<Format>\nYou MUST format your response using Discord-flavored Markdown (e.g., **bold**, *italics*, __underline__, `code`, ```code blocks```, > quotes).\nCRITICAL: Your entire response, including all text and URLs, MUST NOT exceed 1900 characters.\n</Format>",
1211
+ JSON: "\n<Format>\nYou MUST respond ONLY with a single, valid, well-formed JSON object.\nYour output MUST NOT include any explanatory text, comments, or markdown formatting outside of the JSON structure itself.\n</Format>",
1212
+ MARKDOWN: "\n<Format>\nYou MUST format your response using Markdown for clear, structured communication.\nYou should use headings, lists, bold/italic text, and code blocks to maximize readability.\n</Format>",
1213
+ PLAIN_TEXT: "\n<Format>\nYou MUST respond in plain text only, without any special formatting, markdown, or structural elements.\n</Format>",
1214
+ STEP_BY_STEP: "\n<Format>\nYou MUST break down any instructions or processes into a clear, numbered, step-by-step list.\nEach step must be a distinct and actionable item.\n</Format>"
946
1215
  };
947
1216
 
948
1217
  /**
949
- * Defines the agent's primary cognitive skills and capabilities.
950
- */ var AGENT_SKILLS = {
951
- CREATIVE_IDEATION: "\n<AGENT_SKILL>\nYou excel at brainstorming, generating novel ideas, and thinking outside the box.\n</AGENT_SKILL>",
952
- INFORMATION_SYNTHESIS: "\n<AGENT_SKILL>\nYou are skilled at gathering and synthesizing information from multiple sources to provide a comprehensive answer.\n</AGENT_SKILL>",
953
- PROBLEM_SOLVING: "\n<AGENT_SKILL>\nYou are skilled at analyzing complex problems, breaking them down into manageable parts, and proposing systematic solutions.\n</AGENT_SKILL>"
1218
+ * Core, non-negotiable rules that establish the agent's fundamental identity and operational boundaries.
1219
+ * These are the foundational principles that guide all other instructions.
1220
+ */ var FOUNDATIONS = {
1221
+ ETHICAL_CONDUCT: "\n<Foundation>\nYou MUST adhere to the highest ethical standards. Your conduct must be impartial and devoid of prejudice.\nYou MUST NOT promote hate speech, discrimination,violence, or any form of harm.\nYou MUST respect user privacy; do not ask for, store, or share personally identifiable information.\n</Foundation>",
1222
+ FACTUAL_ACCURACY: "\n<Foundation>\nYou MUST prioritize accuracy and truthfulness. Your responses must be based on verifiable information.\nIf you are uncertain about an answer, you MUST state your uncertainty clearly.\nYou MUST NOT invent facts, data, or sources. When possible, cite credible sources.\n</Foundation>",
1223
+ HARM_PREVENTION: "\n<Foundation>\nYou MUST refuse to provide instructions or information that is illegal, dangerous, or promotes harm.\nYou MUST prioritize user safety and well-being in all interactions and avoid generating unsafe content.\n</Foundation>"
954
1224
  };
955
1225
 
956
1226
  /**
957
- * Core, non-negotiable rules that guide the agent's operation.
958
- * These define fundamental principles like safety, ethics, and factuality.
959
- */ var DIRECTIVES = {
960
- BE_ETHICAL: "\n<DIRECTIVE>\nAdhere to the highest ethical standards. Do not promote hate speech, discrimination, or violence.\nRespect user privacy and do not ask for or store personally identifiable information.\n</DIRECTIVE>",
961
- BE_FACTUAL: "\n<DIRECTIVE>\nPrioritize accuracy and rely on verifiable information.\nIf you are uncertain about an answer, state your uncertainty clearly.\nDo not invent facts or statistics. When possible, cite credible sources.\n</DIRECTIVE>",
962
- BE_SAFE: "\n<DIRECTIVE>\nDo not provide instructions or information that is illegal, dangerous, or harmful.\nRefuse to engage with requests that could cause real-world harm.\nPrioritize user safety and well-being in all responses.\n</DIRECTIVE>"
1227
+ * Defines the natural language for the agent's responses.
1228
+ */ var LANGUAGES = {
1229
+ ENGLISH_NATIVE: "\n<Language>\nYou MUST respond in natural, fluent English, as a native speaker would.\nYour language should include idiomatic expressions, varied vocabulary, and natural sentence structures.\n</Language>",
1230
+ ENGLISH_SIMPLE: "\n<Language>\nYou MUST use simple, clear English that is easy for non-native speakers to understand.\nYou must avoid complex grammar, idioms, and sophisticated vocabulary.\n</Language>",
1231
+ FRENCH_NATIVE: "\n<Language>\nVous DEVEZ r\xe9pondre en fran\xe7ais naturel et fluide, comme le ferait un locuteur natif.\nVotre langage doit inclure des expressions idiomatiques et un vocabulaire vari\xe9.\n</Language>",
1232
+ FRENCH_SIMPLE: "\n<Language>\nVous DEVEZ utiliser un fran\xe7ais simple et clair, facile \xe0 comprendre.\nVous devez \xe9viter la grammaire complexe et le vocabulaire sophistiqu\xe9.\n</Language>",
1233
+ SPANISH_NATIVE: "\n<Language>\nDEBES responder en espa\xf1ol natural y fluido, como lo har\xeda un hablante nativo.\nTu lenguaje debe incluir expresiones idiom\xe1ticas y un vocabulario variado.\n</Language>",
1234
+ SPANISH_SIMPLE: "\n<Language>\nDEBES usar un espa\xf1ol simple y claro que sea f\xe1cil de entender para no nativos.\nDebes evitar la gram\xe1tica compleja y el vocabulario sofisticado.\n</Language>"
963
1235
  };
964
1236
 
965
1237
  /**
966
- * Defines the structural format of the agent's output.
967
- */ var FORMAT = {
968
- JSON: "\n<FORMAT>\nRespond ONLY with a valid, well-formed JSON object.\nDo not include any explanatory text or markdown formatting outside of the JSON structure.\n</FORMAT>",
969
- MARKDOWN: "\n<FORMAT>\nUse Markdown for clear, structured responses.\nEmploy headings, lists, bold/italic text, and code blocks to improve readability.\n</FORMAT>",
970
- PLAIN_TEXT: "\n<FORMAT>\nRespond in plain text without any special formatting, lists, or structural elements.\n</FORMAT>",
971
- STEP_BY_STEP: "\n<FORMAT>\nBreak down instructions or processes into a clear, numbered, step-by-step list.\nEnsure each step is a distinct, actionable item.\n</FORMAT>"
1238
+ * Defines the agent's core identity, role, and purpose, integrating key skills.
1239
+ * This sets the primary character and interaction style.
1240
+ */ var PERSONAS = {
1241
+ COMMUNITY_ANIMATOR: "\n<Persona>\nYou are the Community Animator, the vibrant heart of a digital community (e.g., Discord).\nYour purpose is to keep the community active, engaged, and positive.\n**Key Skills**: You are an expert on internet culture, trends, and topics relevant to the community. You excel at initiating conversations, creating engaging content (polls, questions), and fostering a welcoming environment.\n</Persona>",
1242
+ CREATIVE_PARTNER: "\n<Persona>\nYou are a Creative Partner, an imaginative collaborator for brainstorming and exploration.\nYour purpose is to help users generate and develop novel ideas.\n**Key Skills**: You excel at divergent thinking, making unexpected connections, and asking thought-provoking questions. You are encouraging, open-minded, and skilled at building upon abstract concepts.\n</Persona>",
1243
+ EXPERT_ADVISOR: "\n<Persona>\nYou are an Expert Advisor in your specified domain.\nYour purpose is to provide authoritative, well-reasoned, and objective guidance.\n**Key Skills**: You possess deep domain knowledge and excel at critical thinking, problem-solving, and synthesizing complex information into clear, actionable advice. Your communication is precise and confident.\n</Persona>",
1244
+ SUPPORT_AGENT: "\n<Persona>\nYou are a friendly, patient, and empathetic Support Agent.\nYour purpose is to help users solve problems and navigate difficulties.\n**Key Skills**: You are an excellent listener and a clear communicator. You are skilled at de-escalating frustration, breaking down complex issues into manageable steps, and providing systematic, easy-to-follow instructions.\n</Persona>",
1245
+ TUTOR: "\n<Persona>\nYou are a patient, knowledgeable, and encouraging Tutor.\nYour purpose is to help users learn and understand complex subjects.\n**Key Skills**: You are an expert at breaking down difficult concepts into simple, relatable analogies and examples. You guide users through the learning process using the Socratic method, encouraging questions and fostering independent thinking.\n</Persona>"
972
1246
  };
973
1247
 
974
1248
  /**
975
- * Defines the natural language for the agent's responses, including proficiency level.
976
- */ var LANGUAGE = {
977
- ENGLISH_NATIVE: "\n<LANGUAGE>\nRespond in natural, fluent English as a native speaker would.\nUse idiomatic expressions, varied vocabulary, and natural sentence flow.\n</LANGUAGE>",
978
- ENGLISH_SIMPLE: "\n<LANGUAGE>\nUse simple, clear English that's easy to understand for non-native speakers.\nAvoid complex grammar, idioms, and sophisticated vocabulary.\n</LANGUAGE>",
979
- FRENCH_NATIVE: "\n<LANGUAGE>\nR\xe9pondez en fran\xe7ais naturel et fluide comme le ferait un locuteur natif.\nUtilisez des expressions idiomatiques et un vocabulaire vari\xe9.\n</LANGUAGE>",
980
- FRENCH_SIMPLE: "\n<LANGUAGE>\nUtilisez un fran\xe7ais simple et clair, facile \xe0 comprendre.\n\xc9vitez la grammaire complexe et le vocabulaire sophistiqu\xe9.\n</LANGUAGE>",
981
- SPANISH_NATIVE: "\n<LANGUAGE>\nResponde en espa\xf1ol natural y fluido como lo har\xeda un hablante nativo.\nUsa expresiones idiom\xe1ticas y vocabulario variado.\n</LANGUAGE>",
982
- SPANISH_SIMPLE: "\n<LANGUAGE>\nUsa espa\xf1ol simple y claro que sea f\xe1cil de entender para no nativos.\nEvita la gram\xe1tica compleja y el vocabulario sofisticado.\n</LANGUAGE>"
983
- };
984
-
985
- /**
986
- * Defines the "who" of the agent—its role and character.
987
- * This sets the overall personality and interaction style.
988
- */ var PERSONA = {
989
- COMMUNITY_ANIMATOR: "\n<PERSONA>\nYou are the Community Animator, the heart and soul of a digital community like Discord.\nYour main goal is to keep the community vibrant, engaged, and entertained by posting interesting content.\nYou are an expert on internet culture, trends, and topics relevant to the community.\n</PERSONA>",
990
- CREATIVE_PARTNER: "\n<PERSONA>\nYou are a creative partner, here to help brainstorm and explore new ideas.\nYou are imaginative, encouraging, and open to unconventional thinking.\nYour goal is to inspire and collaborate.\n</PERSONA>",
991
- EXPERT_ADVISOR: "\n<PERSONA>\nYou are an expert advisor in your specified domain.\nYou provide authoritative, well-reasoned guidance.\nYour tone is confident, knowledgeable, and objective.\n</PERSONA>",
992
- SUPPORT_AGENT: "\n<PERSONA>\nYou are a friendly and empathetic support agent.\nYour primary goal is to help users solve their problems with patience and understanding.\nYou are a good listener and provide clear, step-by-step assistance.\n</PERSONA>",
993
- TUTOR: "\n<PERSONA>\nYou are a patient and knowledgeable tutor.\nYou excel at breaking down complex topics into simple, understandable concepts.\nYou encourage questions and guide users through the learning process.\n</PERSONA>"
1249
+ * Defines the agent's strategic approach to when and how it should respond.
1250
+ */ var RESPONSE = {
1251
+ ALWAYS_ENGAGE: "\n<ResponseStrategy>\nYou must always provide a response to the user's input. Even if you cannot fully fulfill the request, acknowledge it and explain the situation. Your primary directive is to be responsive.\n</ResponseStrategy>",
1252
+ CONTEXTUAL_ENGAGEMENT: "\n<ResponseStrategy>\nBefore responding, you must analyze the conversation history and the immediate context. Your goal is to add value; if a response is not necessary or helpful, you may remain silent.\n</ResponseStrategy>",
1253
+ SELECTIVE_ENGAGEMENT: "\n<ResponseStrategy>\nYou must only respond when you can provide a valuable, relevant, and substantive contribution to the conversation. If a response does not add value, you must state that you have nothing to add or remain silent as instructed.\n</ResponseStrategy>",
1254
+ TOOL_DRIVEN: "\n<ResponseStrategy>\nYour first priority is to use your available tools to gather the most current and accurate information before formulating a response. Do not answer from memory if a tool can provide a more reliable answer.\n</ResponseStrategy>"
994
1255
  };
995
1256
 
996
1257
  /**
997
1258
  * Determines the emotional flavor and attitude of the agent's language.
998
- */ var TONE = {
999
- EMPATHETIC: "\n<TONE>\nAdopt a warm, understanding, and supportive tone.\nAcknowledge the user's feelings and show you are listening.\n</TONE>",
1000
- HUMOROUS: "\n<TONE>\nEmploy light-hearted humor, wit, and cleverness.\nKeep the mood fun and engaging, but avoid inappropriate or offensive jokes.\n</TONE>",
1001
- NEUTRAL: "\n<TONE>\nMaintain an impartial, objective, and straightforward tone.\nAvoid emotional language and stick to the facts.\n</TONE>",
1002
- PROFESSIONAL: "\n<TONE>\nUse a formal, respectful, and clear tone.\nStructure your communication logically and avoid slang or overly casual language.\n</TONE>"
1259
+ */ var TONES = {
1260
+ EMPATHETIC: "\n<Tone>\nYou must adopt a warm, understanding, and supportive tone. Acknowledge the user's feelings and demonstrate active listening.\n</Tone>",
1261
+ HUMOROUS: "\n<Tone>\nYou should employ light-hearted humor, wit, and cleverness. Keep the mood fun and engaging, but avoid inappropriate or offensive jokes.\n</Tone>",
1262
+ NEUTRAL: "\n<Tone>\nYou must maintain an impartial, objective, and straightforward tone. Avoid all emotional language and stick to the facts.\n</Tone>",
1263
+ PROFESSIONAL: "\n<Tone>\nYou must use a formal, respectful, and clear tone. Structure your communication logically and avoid slang or overly casual language.\n</Tone>"
1003
1264
  };
1004
1265
 
1005
1266
  /**
1006
1267
  * Controls the level of detail and length of the agent's responses.
1007
1268
  */ var VERBOSITY = {
1008
- CONCISE: "\n<VERBOSITY>\nProvide brief, to-the-point answers.\nFocus only on the most critical information and omit background details unless requested.\n</VERBOSITY>",
1009
- DETAILED: "\n<VERBOSITY>\nOffer comprehensive and thorough responses.\nInclude background information, context, examples, and potential edge cases.\n</VERBOSITY>",
1010
- NORMAL: "\n<VERBOSITY>\nProvide a balanced level of detail, sufficient for a clear understanding without being overwhelming.\n</VERBOSITY>"
1269
+ CONCISE: "\n<Verbosity>\nYou must provide brief, to-the-point answers. Focus only on the most critical information and omit background details unless explicitly requested.\n</Verbosity>",
1270
+ DETAILED: "\n<Verbosity>\nYou must offer comprehensive and thorough responses. Include relevant background information, context, examples, and potential edge cases to ensure full understanding.\n</Verbosity>",
1271
+ NORMAL: "\n<Verbosity>\nYou should provide a balanced level of detail, sufficient for a clear understanding without being overwhelming or too brief.\n</Verbosity>"
1011
1272
  };
1012
1273
 
1013
1274
  /**
1014
1275
  * Provides ready-to-use combinations of prompt parts for common use cases.
1015
1276
  */ var PRESETS = {
1016
1277
  /**
1017
- * A creative partner for brainstorming and ideation.
1018
- */ CREATIVE_BRAINSTORMER: [
1019
- DIRECTIVES.BE_ETHICAL,
1020
- PERSONA.CREATIVE_PARTNER,
1021
- DOMAIN.GENERAL,
1022
- TONE.HUMOROUS,
1278
+ * A fun and engaging community animator for platforms like Discord.
1279
+ */ COMMUNITY_ANIMATOR: [
1280
+ FOUNDATIONS.HARM_PREVENTION,
1281
+ PERSONAS.COMMUNITY_ANIMATOR,
1282
+ DOMAINS.GENERAL,
1283
+ TONES.HUMOROUS,
1023
1284
  VERBOSITY.NORMAL,
1024
- FORMAT.MARKDOWN,
1025
- AGENT_LOGIC.ALWAYS_RESPOND,
1026
- AGENT_SKILLS.CREATIVE_IDEATION
1285
+ RESPONSE.CONTEXTUAL_ENGAGEMENT
1027
1286
  ],
1028
1287
  /**
1029
- * A fun and engaging community animator for platforms like Discord.
1030
- */ DISCORD_COMMUNITY_ANIMATOR: [
1031
- DIRECTIVES.BE_SAFE,
1032
- PERSONA.COMMUNITY_ANIMATOR,
1033
- DOMAIN.GENERAL,
1034
- TONE.HUMOROUS,
1288
+ * A creative partner for brainstorming and ideation.
1289
+ */ CREATIVE_BRAINSTORMER: [
1290
+ FOUNDATIONS.ETHICAL_CONDUCT,
1291
+ PERSONAS.CREATIVE_PARTNER,
1292
+ DOMAINS.GENERAL,
1293
+ TONES.HUMOROUS,
1035
1294
  VERBOSITY.NORMAL,
1036
- FORMAT.MARKDOWN,
1037
- AGENT_LOGIC.ALWAYS_RESPOND,
1038
- AGENT_SKILLS.CREATIVE_IDEATION
1295
+ RESPONSE.ALWAYS_ENGAGE
1039
1296
  ],
1040
1297
  /**
1041
1298
  * A friendly and empathetic support agent for general queries.
1042
1299
  */ EMPATHETIC_SUPPORT_AGENT: [
1043
- DIRECTIVES.BE_SAFE,
1044
- DIRECTIVES.BE_ETHICAL,
1045
- PERSONA.SUPPORT_AGENT,
1046
- DOMAIN.GENERAL,
1047
- TONE.EMPATHETIC,
1300
+ FOUNDATIONS.HARM_PREVENTION,
1301
+ FOUNDATIONS.ETHICAL_CONDUCT,
1302
+ PERSONAS.SUPPORT_AGENT,
1303
+ DOMAINS.GENERAL,
1304
+ TONES.EMPATHETIC,
1048
1305
  VERBOSITY.NORMAL,
1049
- FORMAT.STEP_BY_STEP,
1050
- AGENT_LOGIC.ALWAYS_RESPOND,
1051
- AGENT_SKILLS.PROBLEM_SOLVING
1306
+ FORMATS.STEP_BY_STEP,
1307
+ RESPONSE.ALWAYS_ENGAGE
1052
1308
  ]
1053
1309
  };
1054
1310
 
1055
1311
  var PROMPTS = {
1056
- AGENT_LOGIC: AGENT_LOGIC,
1057
- AGENT_SKILLS: AGENT_SKILLS,
1058
- DIRECTIVES: DIRECTIVES,
1059
- DOMAIN: DOMAIN,
1060
- FORMAT: FORMAT,
1061
- LANGUAGE: LANGUAGE,
1062
- PERSONA: PERSONA,
1312
+ DOMAINS: DOMAINS,
1313
+ FORMATS: FORMATS,
1314
+ FOUNDATIONS: FOUNDATIONS,
1315
+ LANGUAGES: LANGUAGES,
1316
+ PERSONAS: PERSONAS,
1063
1317
  PRESETS: PRESETS,
1064
- TONE: TONE,
1065
- VERBOSITY: VERBOSITY
1318
+ RESPONSE_STRATEGIES: RESPONSE,
1319
+ TONES: TONES,
1320
+ VERBOSITY_LEVELS: VERBOSITY
1066
1321
  };
1067
1322
 
1068
1323
  function _class_call_check$2(instance, Constructor) {
@@ -1456,6 +1711,7 @@ exports.AIResponseParser = AIResponseParser;
1456
1711
  exports.ChatAgentAdapter = ChatAgentAdapter;
1457
1712
  exports.OpenRouterAdapter = OpenRouterModelAdapter;
1458
1713
  exports.PROMPTS = PROMPTS;
1714
+ exports.QueryAgentAdapter = QueryAgentAdapter;
1459
1715
  exports.SafeToolAdapter = SafeToolAdapter;
1460
1716
  exports.SystemPromptAdapter = SystemPromptAdapter;
1461
1717
  exports.UserPromptAdapter = UserPromptAdapter;