openloops 0.1.39 → 0.2.2

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 (133) hide show
  1. package/README.md +40 -4
  2. package/dist/clients/index.d.ts +2 -2
  3. package/dist/clients/index.js +4 -4
  4. package/dist/clients/index.mjs +2 -2
  5. package/dist/clients/llm/index.d.ts +1 -0
  6. package/dist/{loops/plan-execute → clients/llm}/index.js +4 -4
  7. package/dist/clients/llm/index.mjs +1 -0
  8. package/dist/clients/{llm-client.d.ts → llm/llm-client.d.ts} +3 -14
  9. package/dist/clients/{llm-client.js → llm/llm-client.js} +14 -37
  10. package/dist/clients/{llm-client.mjs → llm/llm-client.mjs} +15 -38
  11. package/dist/clients/{llm-error.mjs → llm/llm-error.mjs} +1 -1
  12. package/dist/clients/{llm-types.d.ts → llm/llm-types.d.ts} +1 -1
  13. package/dist/clients/llm/model-resolution.d.ts +20 -0
  14. package/dist/clients/llm/model-resolution.js +83 -0
  15. package/dist/clients/llm/model-resolution.mjs +46 -0
  16. package/dist/clients/{pi-ai-adapter.mjs → llm/pi-ai-adapter.mjs} +1 -1
  17. package/dist/clients/serper/index.d.ts +1 -0
  18. package/dist/clients/serper/index.js +22 -0
  19. package/dist/clients/serper/index.mjs +1 -0
  20. package/dist/clients/{serper-client.js → serper/serper-client.js} +2 -2
  21. package/dist/clients/{serper-client.mjs → serper/serper-client.mjs} +3 -3
  22. package/dist/harness/agent-loop.d.ts +0 -1
  23. package/dist/harness/agent.d.ts +6 -1
  24. package/dist/harness/agent.js +21 -13
  25. package/dist/harness/agent.mjs +21 -13
  26. package/dist/harness/native-tools.d.ts +1 -1
  27. package/dist/{loops/shared → harness}/skills/approval-request.d.ts +1 -1
  28. package/dist/{loops/shared → harness}/skills/approval-request.js +1 -1
  29. package/dist/{loops/shared → harness}/skills/approval-request.mjs +2 -2
  30. package/dist/{loops/shared → harness}/skills/autonomous-answer.d.ts +1 -1
  31. package/dist/{loops/shared → harness}/skills/autonomous-answer.js +1 -1
  32. package/dist/{loops/shared → harness}/skills/autonomous-answer.mjs +2 -2
  33. package/dist/{loops/shared → harness}/skills/confirmation-gate.d.ts +1 -1
  34. package/dist/{loops/shared → harness}/skills/confirmation-gate.js +1 -1
  35. package/dist/{loops/shared → harness}/skills/confirmation-gate.mjs +2 -2
  36. package/dist/harness/skills/index.d.ts +4 -0
  37. package/dist/{loops/plan-execute → harness}/skills/index.js +8 -8
  38. package/dist/harness/skills/index.mjs +4 -0
  39. package/dist/{loops/shared → harness}/skills/mcp-change-review.d.ts +1 -1
  40. package/dist/{loops/shared → harness}/skills/mcp-change-review.js +1 -1
  41. package/dist/{loops/shared → harness}/skills/mcp-change-review.mjs +2 -2
  42. package/dist/harness/tool-catalog.d.ts +1 -1
  43. package/dist/loops/index.d.ts +0 -1
  44. package/dist/loops/index.js +0 -2
  45. package/dist/loops/index.mjs +0 -1
  46. package/dist/loops/shared/skills/index.d.ts +0 -4
  47. package/dist/loops/shared/skills/index.js +1 -9
  48. package/dist/loops/shared/skills/index.mjs +0 -4
  49. package/dist/services/chats/entities/chat.entity.d.ts +0 -5
  50. package/dist/services/chats/entities/chat.entity.js +0 -10
  51. package/dist/services/chats/entities/chat.entity.mjs +0 -10
  52. package/dist/services/llmcalls/module.d.ts +4 -2
  53. package/dist/services/llmcalls/module.js +13 -6
  54. package/dist/services/llmcalls/module.mjs +11 -5
  55. package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.d.ts +14 -0
  56. package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.js +62 -0
  57. package/dist/services/llmcalls/use-cases/get-llm-usage-by-chat.use-case.mjs +33 -0
  58. package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.d.ts +14 -0
  59. package/dist/services/llmcalls/use-cases/{get-llm-usage.use-case.js → get-llm-usage-by-message.use-case.js} +18 -37
  60. package/dist/services/llmcalls/use-cases/get-llm-usage-by-message.use-case.mjs +33 -0
  61. package/dist/services/llmcalls/utils/usage-totals.d.ts +20 -0
  62. package/dist/services/llmcalls/utils/usage-totals.js +31 -0
  63. package/dist/services/llmcalls/utils/usage-totals.mjs +29 -0
  64. package/dist/services/tasks/entities/agent-task.entity.d.ts +2 -24
  65. package/dist/services/tasks/entities/agent-task.entity.js +2 -75
  66. package/dist/services/tasks/entities/agent-task.entity.mjs +2 -75
  67. package/dist/services/users/entities/user-default-model.d.ts +11 -0
  68. package/dist/services/users/entities/user-default-model.js +42 -0
  69. package/dist/services/users/entities/user-default-model.mjs +19 -0
  70. package/dist/services/users/entities/user-preferences.d.ts +4 -1
  71. package/dist/services/users/entities/user-preferences.js +8 -3
  72. package/dist/services/users/entities/user-preferences.mjs +8 -3
  73. package/dist/services/users/use-cases/create-user.use-case.js +3 -1
  74. package/dist/services/users/use-cases/create-user.use-case.mjs +3 -1
  75. package/dist/services/users/use-cases/update-user.use-case.js +4 -1
  76. package/dist/services/users/use-cases/update-user.use-case.mjs +4 -1
  77. package/dist/services/users/utils/default-model.d.ts +6 -0
  78. package/dist/services/users/utils/default-model.js +38 -0
  79. package/dist/services/users/utils/default-model.mjs +15 -0
  80. package/dist/skills/call-modes.d.ts +1 -1
  81. package/dist/skills/skill.d.ts +1 -1
  82. package/dist/skills/skill.js +1 -1
  83. package/dist/skills/skill.mjs +1 -1
  84. package/dist/tools/core/web-search/web-search.tool.js +1 -1
  85. package/dist/tools/core/web-search/web-search.tool.mjs +1 -1
  86. package/docs/README.md +1 -1
  87. package/docs/agent.md +4 -3
  88. package/docs/agentic-jobs.md +1 -1
  89. package/docs/assets/harness-car.svg +79 -0
  90. package/docs/chats.md +1 -1
  91. package/docs/configuration.md +18 -4
  92. package/docs/harness.md +12 -1
  93. package/docs/integration-guide.md +2 -2
  94. package/docs/llms.txt +1 -1
  95. package/docs/loops.md +4 -15
  96. package/docs/usage.md +19 -14
  97. package/docs/users.md +23 -0
  98. package/examples/run-agent/run-agent-with-fallback-model.ts +25 -0
  99. package/examples/usage/get-chat-usage.ts +8 -10
  100. package/examples/usage/get-message-usage.ts +5 -7
  101. package/examples/users/set-default-model.ts +36 -0
  102. package/package.json +1 -16
  103. package/dist/loops/plan-execute/index.d.ts +0 -1
  104. package/dist/loops/plan-execute/index.mjs +0 -1
  105. package/dist/loops/plan-execute/loop.d.ts +0 -26
  106. package/dist/loops/plan-execute/loop.js +0 -267
  107. package/dist/loops/plan-execute/loop.mjs +0 -249
  108. package/dist/loops/plan-execute/skills/action-planner.d.ts +0 -35
  109. package/dist/loops/plan-execute/skills/action-planner.js +0 -71
  110. package/dist/loops/plan-execute/skills/action-planner.mjs +0 -48
  111. package/dist/loops/plan-execute/skills/final-responder.d.ts +0 -7
  112. package/dist/loops/plan-execute/skills/final-responder.js +0 -58
  113. package/dist/loops/plan-execute/skills/final-responder.mjs +0 -35
  114. package/dist/loops/plan-execute/skills/index.d.ts +0 -4
  115. package/dist/loops/plan-execute/skills/index.mjs +0 -4
  116. package/dist/loops/plan-execute/skills/state-observer.d.ts +0 -10
  117. package/dist/loops/plan-execute/skills/state-observer.js +0 -61
  118. package/dist/loops/plan-execute/skills/state-observer.mjs +0 -38
  119. package/dist/loops/plan-execute/skills/strategy-engine.d.ts +0 -11
  120. package/dist/loops/plan-execute/skills/strategy-engine.js +0 -61
  121. package/dist/loops/plan-execute/skills/strategy-engine.mjs +0 -38
  122. package/dist/services/llmcalls/use-cases/get-llm-usage.use-case.d.ts +0 -24
  123. package/dist/services/llmcalls/use-cases/get-llm-usage.use-case.mjs +0 -51
  124. package/dist/skills/skill-runner.d.ts +0 -30
  125. package/dist/skills/skill-runner.js +0 -121
  126. package/dist/skills/skill-runner.mjs +0 -92
  127. /package/dist/clients/{llm-error.d.ts → llm/llm-error.d.ts} +0 -0
  128. /package/dist/clients/{llm-error.js → llm/llm-error.js} +0 -0
  129. /package/dist/clients/{llm-types.js → llm/llm-types.js} +0 -0
  130. /package/dist/clients/{llm-types.mjs → llm/llm-types.mjs} +0 -0
  131. /package/dist/clients/{pi-ai-adapter.d.ts → llm/pi-ai-adapter.d.ts} +0 -0
  132. /package/dist/clients/{pi-ai-adapter.js → llm/pi-ai-adapter.js} +0 -0
  133. /package/dist/clients/{serper-client.d.ts → serper/serper-client.d.ts} +0 -0
@@ -1,48 +0,0 @@
1
- import "../../../chunk-CF3WOMB3.mjs";
2
- import { Skill } from "../../../skills/skill.js";
3
- const actionPlanner = new Skill({
4
- name: "action_planner",
5
- version: "1.7.0",
6
- description: "Generates an ordered step-by-step tool execution plan based on IntentContext and candidate tools schema. Flags missing tools, missing required execution parameters, or steps requiring user confirmation for destructive actions.",
7
- temperature: 0.1,
8
- systemInstructions: {
9
- instruction_set: {
10
- goal: "Evaluate userIntent, extracted_entities, and candidate tools to output a structured execution plan. Detect missing capabilities, missing tool arguments, or destructive tool executions and ask for clarification or confirmation when necessary.",
11
- role: "Action planning, tool mapping, argument mapping, and execution strategy agent",
12
- logic_rules: [
13
- "TOOL_EVALUATION: Analyze available tool schemas against userIntent and extracted_entities in IntentContext. Select only the necessary tools required to achieve the goal.",
14
- "MISSING_TOOLS_CHECK: If no candidate tools fit the intent, or if essential actions cannot be mapped to any available tool: 1) Set 'plan_status' to 'MISSING_TOOLS', 2) Set 'current_step_index' to 0, 3) Provide a technical explanation in 'missing_tools_explanation' in English, 4) Generate a polite message in 'user_response' written in 'detected_language' explaining that no connected tools/integrations were found to complete the request and suggest checking their active integrations, 5) Set 'steps' to [], 6) Set 'needs_clarification' to false, 'missing_entities' to [], 'clarification_prompt' to '', and 'confirmation_details' to null.",
15
- "STEP_PLANNING: If tools are available, sequence them logically in 'steps'. Assign incremental 'step_id' starting at 1; ids are local to this plan, even when replanning. Set 'current_step_index' to 0 by default. Explicitly list any prerequisite step IDs in 'depends_on_steps' if a step requires output from a prior step. Define a clear 'expected_outcome' describing the precise expected result or data state after this step runs.",
16
- "ARGUMENT_MAPPING: Map extracted_entities and execution context (e.g., CONTEXT metadata like 'now_utc', 'now_local', 'timezone', user_details, and session_details) to tool parameters in 'arguments'. For relative time/date expressions (e.g., 'today', 'afternoon', 'yesterday at 4:30pm'), calculate and resolve the precise value (such as ISO 8601 strings) using the provided reference timestamp and timezone. If a parameter value comes from the output of another step, represent it as a reference string: '{{step_N.output.path}}' where N is the 'step_id' of an earlier step in THIS plan, or '{{step_REF.output.path}}' where REF is the 'ref' of an entry in CONTEXT.execution_history. The path uses dot and bracket notation into that step's output (e.g., '{{step_1.output.results[0].name}}'), or is omitted to use the whole output.",
17
- "REFERENCE_SAFETY: Only reference a path you are certain exists in that step's output, based on the tool description or on an output already visible in CONTEXT.execution_history. If the arguments of a step depend on the content of an output you cannot see yet (for example the results of a search or discovery tool), do NOT plan that dependent step: plan only up to the step that produces the data. After it runs, the plan will be revised with the real output in CONTEXT.execution_history. Never invent fields, and never pass empty arguments to a tool that has required parameters.",
18
- "ARGUMENT_LANGUAGE: Values inside 'arguments' follow the description of each tool parameter, not 'detected_language'. If a parameter description asks for a specific language (for example English keywords), write that value in that language, translating or extracting the relevant domain terms and entity names from the user request when needed. Only values that must be stored or displayed verbatim (names, titles, free text written by the user) keep the user's original language.",
19
- "REPLANNING: When CONTEXT.execution_history is present, you are revising a plan. Read each entry's 'status', 'output' and 'error', and CONTEXT.replan_feedback when present. Do not propose a step with the same tool and the same arguments as an entry already in the history; use the real outputs to build a different approach (different arguments, another candidate tool, or the data already discovered). If the history shows the goal is already achieved or no different approach is possible with the candidate tools, set 'plan_status' to 'NEEDS_CLARIFICATION' and ask the user for the specific information needed.",
20
- "PARAMETER_AND_SAFETY_VALIDATION: For each step, inspect the candidate tool schema properties and flags:",
21
- "1) Set 'is_destructive' to match the candidate tool's 'destructive' boolean flag.",
22
- "2) If any required parameter is MISSING and CANNOT be derived from CONTEXT: Set step 'status' to 'MISSING_PARAMS' and list the missing keys in 'missing_fields'.",
23
- "3) If ALL required parameters are present BUT 'is_destructive' is true: Set step 'status' to 'REQUIRES_CONFIRMATION' and 'missing_fields' to [].",
24
- "4) If ALL required parameters are present and 'is_destructive' is false: Set step 'status' to 'READY' and 'missing_fields' to [].",
25
- "CLARIFICATION_CHECK: If ANY step has status 'MISSING_PARAMS': 1) Set 'plan_status' to 'NEEDS_CLARIFICATION', 2) Set 'needs_clarification' to true, 3) Collect all unresolvable parameters in 'missing_entities' in English, 4) Provide a short, direct, and polite question in 'clarification_prompt' written in 'detected_language', 5) Set 'user_response' to '', and 'confirmation_details' to null.",
26
- "CONFIRMATION_CHECK: If NO step has 'MISSING_PARAMS' BUT at least one step has status 'REQUIRES_CONFIRMATION': 1) Set 'plan_status' to 'NEEDS_CONFIRMATION', 2) Set 'needs_clarification' to false, 3) Set 'missing_entities' to [], 4) Populate 'confirmation_details' with: 'actions' (one entry per step with status 'REQUIRES_CONFIRMATION', each with that step's 'step_id' and a short natural-language 'description' of exactly what it will do, naming the action and its target \u2014 never the raw tool name or parameter keys), 'impact_summary' summarizing the overall permanent changes in plain terms, and 'confirm_label' \u2014 a short call-to-action asking the user to approve or decline; this will always be shown as the LAST line of the message, so it must stand on its own as the actual yes/no ask, 5) Provide context in 'clarification_prompt' introducing why confirmation is needed \u2014 this field must NOT itself ask a yes/no question, since 'confirm_label' is the only field that does that, 6) Set 'user_response' to ''. CRITICAL: every piece of text produced in this rule ('actions[].description', 'impact_summary', 'confirm_label', 'clarification_prompt') MUST be written in 'detected_language' \u2014 never default to English here regardless of the language used anywhere else in this instruction set.",
27
- "SUCCESS_STATE: If all steps are 'READY' and no tools are missing or requiring confirmation: 1) Set 'plan_status' to 'SUCCESS', 2) Set 'missing_tools_explanation' to '', 3) Set 'user_response' to '', 4) Set 'needs_clarification' to false, 'missing_entities' to [], 'clarification_prompt' to '', and 'confirmation_details' to null.",
28
- "LANGUAGE_ENFORCEMENT: ONLY 'clarification_prompt', 'user_response', and every field inside 'confirmation_details' (including each entry's 'description') MUST be written in the user's actual conversation language \u2014 use CONTEXT.detected_language when present; only fall back to CONTEXT.user_details.preferred_language if 'detected_language' is absent. 'preferred_language' is the app's configured display language and does NOT necessarily match the language the user is typing in right now \u2014 never prefer it over 'detected_language' when both exist. These are the only fields the end user actually reads before approving or declining. ALL OTHER fields ('missing_tools_explanation', step 'rationale', step 'expected_outcome', 'missing_entities', and 'reasoning') MUST strictly be written in English, even when the user wrote in another language. The values inside step 'arguments' are governed by ARGUMENT_LANGUAGE.",
29
- "STRICT_OUTPUT: Return ONLY the JSON object matching response_schema."
30
- ],
31
- response_schema: {
32
- plan_status: "string (SUCCESS | MISSING_TOOLS | NEEDS_CLARIFICATION | NEEDS_CONFIRMATION)",
33
- // current_step_index: "number",
34
- missing_tools_explanation: "string",
35
- user_response: "string",
36
- steps: "array of objects with fields 'step_id' (number), 'tool_name' (string), 'arguments' (object), 'expected_outcome' (string), 'status' ('READY' | 'MISSING_PARAMS' | 'REQUIRES_CONFIRMATION'), 'is_destructive' (boolean), 'missing_fields' (array of strings), 'rationale' (string), 'depends_on_steps' (array of numbers)",
37
- needs_clarification: "boolean",
38
- missing_entities: "array of strings",
39
- clarification_prompt: "string",
40
- confirmation_details: "object containing 'actions' (array of objects with 'step_id' (number) and 'description' (string, natural language, in the user's detected_language)), 'impact_summary' (string, in the user's detected_language), and 'confirm_label' (short string, in the user's detected_language) \u2014 or null",
41
- reasoning: "string"
42
- }
43
- }
44
- }
45
- });
46
- export {
47
- actionPlanner
48
- };
@@ -1,7 +0,0 @@
1
- import { Skill } from '../../../skills/skill.js';
2
- type ResponseSchema = {
3
- final_response: string;
4
- reasoning: string;
5
- };
6
- export declare const finalResponder: Skill<ResponseSchema>;
7
- export {};
@@ -1,58 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var final_responder_exports = {};
20
- __export(final_responder_exports, {
21
- finalResponder: () => finalResponder
22
- });
23
- module.exports = __toCommonJS(final_responder_exports);
24
- var import_skill = require("../../../skills/skill.js");
25
- var import_shared_rules = require("../../../skills/shared/shared-rules.js");
26
- const finalResponder = new import_skill.Skill({
27
- name: "final_responder",
28
- version: "1.1.0",
29
- description: "Synthesizes tool execution results, scratchpad, and context state into a clear, natural, user-facing final response.",
30
- temperature: 0.3,
31
- systemInstructions: {
32
- instruction_set: {
33
- goal: "Synthesize the user's initial goal, extracted entities, and technical tool execution results into a comprehensive, helpful, and naturally formatted final response for the user.",
34
- role: "Final synthesis and communication engine",
35
- logic_rules: [
36
- "RESULT_SYNTHESIS: Review all tool execution results, outputs, and scratchpad context to build a clear, coherent answer addressing the user's original goal.",
37
- "USER_LANGUAGE_MATCHING: Always draft 'final_response' in the user's actual conversation language: use CONTEXT.detected_language when present, otherwise the language used by the user in their original input or conversation history.",
38
- "STOPPED_TASK: If CONTEXT.stop_reason is present, the task did NOT complete. Never claim success. Explain briefly what was attempted and what blocked progress, without internal tool names or stack traces, and ask the user how to proceed or what specific information would help. Do not add a fun fact in this case.",
39
- import_shared_rules.FORMATTING,
40
- import_shared_rules.LATEX_FORMATTING,
41
- import_shared_rules.CITATION_FORMATTING,
42
- "PROACTIVE_ENGAGEMENT: When the task completed successfully, always end your response with a relevant, proactive follow-up question related to the topic. If no compelling question comes to mind, share a fascinating, relevant fun fact or engaging tidbit ('bait') to spark curiosity and keep the conversation going.",
43
- "ERROR_HANDLING: If tool executions failed or yielded partial results, communicate what was accomplished and what failed gracefully without exposing internal raw stack traces unless relevant.",
44
- "REASONING_LOG: Provide a concise logical summary of how the final answer was constructed from the tool outputs in 'reasoning' strictly in English.",
45
- "STRICT_ENGLISH_REASONING: The 'reasoning' field MUST strictly be written in English, while 'final_response' MUST match the user's language.",
46
- "STRICT_OUTPUT: Return ONLY the JSON object matching response_schema."
47
- ],
48
- response_schema: {
49
- final_response: "string",
50
- reasoning: "string"
51
- }
52
- }
53
- }
54
- });
55
- // Annotate the CommonJS export names for ESM import in node:
56
- 0 && (module.exports = {
57
- finalResponder
58
- });
@@ -1,35 +0,0 @@
1
- import "../../../chunk-CF3WOMB3.mjs";
2
- import { Skill } from "../../../skills/skill.js";
3
- import { FORMATTING, LATEX_FORMATTING, CITATION_FORMATTING } from "../../../skills/shared/shared-rules.js";
4
- const finalResponder = new Skill({
5
- name: "final_responder",
6
- version: "1.1.0",
7
- description: "Synthesizes tool execution results, scratchpad, and context state into a clear, natural, user-facing final response.",
8
- temperature: 0.3,
9
- systemInstructions: {
10
- instruction_set: {
11
- goal: "Synthesize the user's initial goal, extracted entities, and technical tool execution results into a comprehensive, helpful, and naturally formatted final response for the user.",
12
- role: "Final synthesis and communication engine",
13
- logic_rules: [
14
- "RESULT_SYNTHESIS: Review all tool execution results, outputs, and scratchpad context to build a clear, coherent answer addressing the user's original goal.",
15
- "USER_LANGUAGE_MATCHING: Always draft 'final_response' in the user's actual conversation language: use CONTEXT.detected_language when present, otherwise the language used by the user in their original input or conversation history.",
16
- "STOPPED_TASK: If CONTEXT.stop_reason is present, the task did NOT complete. Never claim success. Explain briefly what was attempted and what blocked progress, without internal tool names or stack traces, and ask the user how to proceed or what specific information would help. Do not add a fun fact in this case.",
17
- FORMATTING,
18
- LATEX_FORMATTING,
19
- CITATION_FORMATTING,
20
- "PROACTIVE_ENGAGEMENT: When the task completed successfully, always end your response with a relevant, proactive follow-up question related to the topic. If no compelling question comes to mind, share a fascinating, relevant fun fact or engaging tidbit ('bait') to spark curiosity and keep the conversation going.",
21
- "ERROR_HANDLING: If tool executions failed or yielded partial results, communicate what was accomplished and what failed gracefully without exposing internal raw stack traces unless relevant.",
22
- "REASONING_LOG: Provide a concise logical summary of how the final answer was constructed from the tool outputs in 'reasoning' strictly in English.",
23
- "STRICT_ENGLISH_REASONING: The 'reasoning' field MUST strictly be written in English, while 'final_response' MUST match the user's language.",
24
- "STRICT_OUTPUT: Return ONLY the JSON object matching response_schema."
25
- ],
26
- response_schema: {
27
- final_response: "string",
28
- reasoning: "string"
29
- }
30
- }
31
- }
32
- });
33
- export {
34
- finalResponder
35
- };
@@ -1,4 +0,0 @@
1
- export * from './action-planner';
2
- export * from './final-responder';
3
- export * from './state-observer';
4
- export * from './strategy-engine';
@@ -1,4 +0,0 @@
1
- export * from "./action-planner";
2
- export * from "./final-responder";
3
- export * from "./state-observer";
4
- export * from "./strategy-engine";
@@ -1,10 +0,0 @@
1
- import { Skill } from '../../../skills/skill.js';
2
- type StateObserverResponseSchema = {
3
- action: 'CONTINUE' | 'REPLAN' | 'ASK_USER' | 'FINISH';
4
- feedback_for_planner: string;
5
- user_prompt: string;
6
- detected_language: string;
7
- reasoning: string;
8
- };
9
- export declare const stateObserver: Skill<StateObserverResponseSchema>;
10
- export {};
@@ -1,61 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var state_observer_exports = {};
20
- __export(state_observer_exports, {
21
- stateObserver: () => stateObserver
22
- });
23
- module.exports = __toCommonJS(state_observer_exports);
24
- var import_skill = require("../../../skills/skill.js");
25
- const stateObserver = new import_skill.Skill({
26
- name: "state_observer",
27
- version: "1.2.0",
28
- description: "Evaluates the execution output of a tool step against the overall user intent. Determines whether to proceed, replan, ask the user, or finish.",
29
- temperature: 0.1,
30
- systemInstructions: {
31
- instruction_set: {
32
- goal: "Analyze the execution result of the latest executed tool step alongside the original user intent, remaining plan steps, and extracted entities. Decide whether the execution succeeded semantically and determine the next action in the orchestration flow.",
33
- role: "Execution state observer, semantic error evaluator, and dynamic replanning controller agent",
34
- logic_rules: [
35
- "STEP_OUTPUT_ANALYSIS: Inspect 'executed_step'. Check both technical status (COMPLETED vs FAILED) and semantic content of 'output'. Identify if the tool returned empty data, permission errors, business logic failures, or unrecoverable exceptions.",
36
- "EVALUATE_CONTINUE: If the step status is 'COMPLETED' and the 'output' contains valid, expected data required for subsequent steps: 1) Set 'action' to 'CONTINUE', 2) Set 'feedback_for_planner' to '', 3) Set 'user_prompt' to ''.",
37
- "EVALUATE_FINISH: If the step status is 'COMPLETED' and the output fully answers the user's intent, rendering remaining planned steps unnecessary: 1) Set 'action' to 'FINISH', 2) Set 'feedback_for_planner' to '', 3) Set 'user_prompt' to ''.",
38
- "EVALUATE_REPLAN: If the step status is 'FAILED', OR if the tool output is empty/invalid, OR if the data returned drastically alters the context/assumptions required for remaining steps, AND a concretely different approach is realistic (different arguments, another available tool, or new information found in the output): 1) Set 'action' to 'REPLAN', 2) Provide detailed, actionable diagnostic feedback in 'feedback_for_planner' in English explaining why the step failed or what new constraints were discovered, and naming the specific different approach to try (for example, different English keywords, or a tool found in the output), 3) Set 'user_prompt' to ''. If the step failed with 'Invalid arguments' or 'Unresolved references', explain exactly what was wrong so the planner can correct it.",
39
- "REPLAN_BUDGET: CONTEXT.replans_remaining is the number of replans still allowed. If it is 0, NEVER choose 'REPLAN'; choose 'ASK_USER' instead and ask the user for the specific information needed to proceed.",
40
- "NO_PROGRESS: If the output is empty or reports no matches and you cannot name a concretely different approach, do not choose 'REPLAN' (it would repeat the same step); choose 'ASK_USER' and ask the user for the specific details that would help.",
41
- "TRUNCATED_OUTPUT: If 'executed_step.output.truncated' is true, only a preview of the output is shown. Judge from the preview and do not choose 'REPLAN' only because of truncation.",
42
- "EVALUATE_ASK_USER: If the tool output explicitly indicates that user intervention, a missing secret, an auth confirmation, or a decision choice is required to proceed: 1) Set 'action' to 'ASK_USER', 2) Set 'feedback_for_planner' to '', 3) Generate a clear, direct prompt in 'user_prompt' written in 'detected_language' asking the user for the necessary input.",
43
- "LANGUAGE_DETECTION: Detect the primary language of the user input/context and output its ISO 639-1 code in 'detected_language' (e.g., 'es', 'en', 'pt').",
44
- "FIELD_DISCIPLINE: 'user_prompt' MUST be non-empty only when 'action' is 'ASK_USER' and MUST be '' for every other action. 'feedback_for_planner' MUST be non-empty only when 'action' is 'REPLAN' and MUST be '' for every other action.",
45
- "LANGUAGE_ENFORCEMENT: ONLY 'user_prompt' MUST be written in the language specified in 'detected_language'. ALL OTHER fields ('feedback_for_planner', 'detected_language', and 'reasoning') MUST strictly be written in English.",
46
- "STRICT_OUTPUT: Return ONLY the JSON object matching response_schema."
47
- ],
48
- response_schema: {
49
- action: "string (CONTINUE | REPLAN | ASK_USER | FINISH)",
50
- feedback_for_planner: "string",
51
- user_prompt: "string",
52
- detected_language: "string",
53
- reasoning: "string"
54
- }
55
- }
56
- }
57
- });
58
- // Annotate the CommonJS export names for ESM import in node:
59
- 0 && (module.exports = {
60
- stateObserver
61
- });
@@ -1,38 +0,0 @@
1
- import "../../../chunk-CF3WOMB3.mjs";
2
- import { Skill } from "../../../skills/skill.js";
3
- const stateObserver = new Skill({
4
- name: "state_observer",
5
- version: "1.2.0",
6
- description: "Evaluates the execution output of a tool step against the overall user intent. Determines whether to proceed, replan, ask the user, or finish.",
7
- temperature: 0.1,
8
- systemInstructions: {
9
- instruction_set: {
10
- goal: "Analyze the execution result of the latest executed tool step alongside the original user intent, remaining plan steps, and extracted entities. Decide whether the execution succeeded semantically and determine the next action in the orchestration flow.",
11
- role: "Execution state observer, semantic error evaluator, and dynamic replanning controller agent",
12
- logic_rules: [
13
- "STEP_OUTPUT_ANALYSIS: Inspect 'executed_step'. Check both technical status (COMPLETED vs FAILED) and semantic content of 'output'. Identify if the tool returned empty data, permission errors, business logic failures, or unrecoverable exceptions.",
14
- "EVALUATE_CONTINUE: If the step status is 'COMPLETED' and the 'output' contains valid, expected data required for subsequent steps: 1) Set 'action' to 'CONTINUE', 2) Set 'feedback_for_planner' to '', 3) Set 'user_prompt' to ''.",
15
- "EVALUATE_FINISH: If the step status is 'COMPLETED' and the output fully answers the user's intent, rendering remaining planned steps unnecessary: 1) Set 'action' to 'FINISH', 2) Set 'feedback_for_planner' to '', 3) Set 'user_prompt' to ''.",
16
- "EVALUATE_REPLAN: If the step status is 'FAILED', OR if the tool output is empty/invalid, OR if the data returned drastically alters the context/assumptions required for remaining steps, AND a concretely different approach is realistic (different arguments, another available tool, or new information found in the output): 1) Set 'action' to 'REPLAN', 2) Provide detailed, actionable diagnostic feedback in 'feedback_for_planner' in English explaining why the step failed or what new constraints were discovered, and naming the specific different approach to try (for example, different English keywords, or a tool found in the output), 3) Set 'user_prompt' to ''. If the step failed with 'Invalid arguments' or 'Unresolved references', explain exactly what was wrong so the planner can correct it.",
17
- "REPLAN_BUDGET: CONTEXT.replans_remaining is the number of replans still allowed. If it is 0, NEVER choose 'REPLAN'; choose 'ASK_USER' instead and ask the user for the specific information needed to proceed.",
18
- "NO_PROGRESS: If the output is empty or reports no matches and you cannot name a concretely different approach, do not choose 'REPLAN' (it would repeat the same step); choose 'ASK_USER' and ask the user for the specific details that would help.",
19
- "TRUNCATED_OUTPUT: If 'executed_step.output.truncated' is true, only a preview of the output is shown. Judge from the preview and do not choose 'REPLAN' only because of truncation.",
20
- "EVALUATE_ASK_USER: If the tool output explicitly indicates that user intervention, a missing secret, an auth confirmation, or a decision choice is required to proceed: 1) Set 'action' to 'ASK_USER', 2) Set 'feedback_for_planner' to '', 3) Generate a clear, direct prompt in 'user_prompt' written in 'detected_language' asking the user for the necessary input.",
21
- "LANGUAGE_DETECTION: Detect the primary language of the user input/context and output its ISO 639-1 code in 'detected_language' (e.g., 'es', 'en', 'pt').",
22
- "FIELD_DISCIPLINE: 'user_prompt' MUST be non-empty only when 'action' is 'ASK_USER' and MUST be '' for every other action. 'feedback_for_planner' MUST be non-empty only when 'action' is 'REPLAN' and MUST be '' for every other action.",
23
- "LANGUAGE_ENFORCEMENT: ONLY 'user_prompt' MUST be written in the language specified in 'detected_language'. ALL OTHER fields ('feedback_for_planner', 'detected_language', and 'reasoning') MUST strictly be written in English.",
24
- "STRICT_OUTPUT: Return ONLY the JSON object matching response_schema."
25
- ],
26
- response_schema: {
27
- action: "string (CONTINUE | REPLAN | ASK_USER | FINISH)",
28
- feedback_for_planner: "string",
29
- user_prompt: "string",
30
- detected_language: "string",
31
- reasoning: "string"
32
- }
33
- }
34
- }
35
- });
36
- export {
37
- stateObserver
38
- };
@@ -1,11 +0,0 @@
1
- import { Skill } from '../../../skills/skill.js';
2
- export type ResponseSchema = {
3
- goal: string;
4
- hypothesis: string;
5
- required_capabilities: string[];
6
- tool_names: string[];
7
- detected_language: string;
8
- reasoning: string;
9
- is_continuation: boolean;
10
- };
11
- export declare const strategyEngine: Skill<ResponseSchema>;
@@ -1,61 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var strategy_engine_exports = {};
20
- __export(strategy_engine_exports, {
21
- strategyEngine: () => strategyEngine
22
- });
23
- module.exports = __toCommonJS(strategy_engine_exports);
24
- var import_skill = require("../../../skills/skill.js");
25
- const strategyEngine = new import_skill.Skill({
26
- name: "strategy_engine",
27
- version: "2.0.0",
28
- description: "Analyzes user goals, chat history, past tasks and the available tools metadata to formulate a grounded high-level strategy, required capabilities, the exact tools needed to execute it, and Task continuity detection.",
29
- temperature: 0.2,
30
- systemInstructions: {
31
- instruction_set: {
32
- goal: "Analyze the user's intent, conversation context, last completed task and the metadata of the available tools to establish a high-level execution goal, a realistic hypothesis grounded in the real tools, required system capabilities, the exact names of the tools needed, and determine whether the message continues a previous task.",
33
- role: "Strategic reasoning, capability mapping, tool selection, and task continuity engine",
34
- logic_rules: [
35
- "TASK_CONTINUATION_DETECTION: Set 'is_continuation' to true ONLY if 'last_completed_task' is provided in context AND the user's current message directly references, follows up on, or modifies that specific previous task. Set to false if the user introduces a completely new goal or independent topic.",
36
- "GOAL_REFINEMENT: Refine and summarize the ultimate goal of the user into 'goal' strictly in English, resolving references from chat history if present.",
37
- "TOOLS_AWARENESS: 'toolsMeta' lists every tool currently available, each with 'name', 'description' and 'annotations'. Read the descriptions and annotations (for example destructive or read-only hints) to understand what each tool really does and its side effects. Base the strategy ONLY on what these tools can actually do.",
38
- "HYPOTHESIS_FORMULATION: Formulate a clear, step-by-step strategic hypothesis in 'hypothesis' in English explaining how the goal can be achieved using the available tools, mentioning the tools by name and the order in which they would be used. If no available tool can achieve part of the goal, state that explicitly instead of assuming a capability exists.",
39
- "CAPABILITY_MAPPING: Identify and list all functional system capabilities or domain requirements needed in 'required_capabilities' in English (e.g., ['calendar_access', 'data_parsing', 'web_search']).",
40
- "TOOL_SELECTION: Fill 'tool_names' with the exact 'name' values from 'toolsMeta' of every tool needed to execute the strategy, including tools that only provide prerequisite data for other tools. Copy names character by character. NEVER invent, translate, rename or abbreviate a tool name. Select the minimum necessary set and do not include tools that are not part of the strategy. If 'toolsMeta' is missing or no tool fits the goal, return an empty array.",
41
- "LANGUAGE_DETECTION: Detect the primary language of the user input and output its ISO 639-1 code in 'detected_language' (e.g., 'es', 'en', 'pt').",
42
- "REASONING_LOG: Provide a concise, step-by-step logical justification of the proposed strategy and of each selected tool in 'reasoning' strictly in English.",
43
- "STRICT_ENGLISH_OUTPUT: ALL output fields ('goal', 'hypothesis', 'required_capabilities' and 'reasoning') MUST strictly be written in English, regardless of the user input language. 'tool_names' must keep the exact original tool names.",
44
- "STRICT_OUTPUT: Return ONLY the JSON object matching response_schema."
45
- ],
46
- response_schema: {
47
- goal: "string",
48
- hypothesis: "string",
49
- required_capabilities: "array of strings",
50
- tool_names: "array of strings, each one an exact 'name' from toolsMeta",
51
- detected_language: "string",
52
- reasoning: "string",
53
- is_continuation: "boolean"
54
- }
55
- }
56
- }
57
- });
58
- // Annotate the CommonJS export names for ESM import in node:
59
- 0 && (module.exports = {
60
- strategyEngine
61
- });
@@ -1,38 +0,0 @@
1
- import "../../../chunk-CF3WOMB3.mjs";
2
- import { Skill } from "../../../skills/skill.js";
3
- const strategyEngine = new Skill({
4
- name: "strategy_engine",
5
- version: "2.0.0",
6
- description: "Analyzes user goals, chat history, past tasks and the available tools metadata to formulate a grounded high-level strategy, required capabilities, the exact tools needed to execute it, and Task continuity detection.",
7
- temperature: 0.2,
8
- systemInstructions: {
9
- instruction_set: {
10
- goal: "Analyze the user's intent, conversation context, last completed task and the metadata of the available tools to establish a high-level execution goal, a realistic hypothesis grounded in the real tools, required system capabilities, the exact names of the tools needed, and determine whether the message continues a previous task.",
11
- role: "Strategic reasoning, capability mapping, tool selection, and task continuity engine",
12
- logic_rules: [
13
- "TASK_CONTINUATION_DETECTION: Set 'is_continuation' to true ONLY if 'last_completed_task' is provided in context AND the user's current message directly references, follows up on, or modifies that specific previous task. Set to false if the user introduces a completely new goal or independent topic.",
14
- "GOAL_REFINEMENT: Refine and summarize the ultimate goal of the user into 'goal' strictly in English, resolving references from chat history if present.",
15
- "TOOLS_AWARENESS: 'toolsMeta' lists every tool currently available, each with 'name', 'description' and 'annotations'. Read the descriptions and annotations (for example destructive or read-only hints) to understand what each tool really does and its side effects. Base the strategy ONLY on what these tools can actually do.",
16
- "HYPOTHESIS_FORMULATION: Formulate a clear, step-by-step strategic hypothesis in 'hypothesis' in English explaining how the goal can be achieved using the available tools, mentioning the tools by name and the order in which they would be used. If no available tool can achieve part of the goal, state that explicitly instead of assuming a capability exists.",
17
- "CAPABILITY_MAPPING: Identify and list all functional system capabilities or domain requirements needed in 'required_capabilities' in English (e.g., ['calendar_access', 'data_parsing', 'web_search']).",
18
- "TOOL_SELECTION: Fill 'tool_names' with the exact 'name' values from 'toolsMeta' of every tool needed to execute the strategy, including tools that only provide prerequisite data for other tools. Copy names character by character. NEVER invent, translate, rename or abbreviate a tool name. Select the minimum necessary set and do not include tools that are not part of the strategy. If 'toolsMeta' is missing or no tool fits the goal, return an empty array.",
19
- "LANGUAGE_DETECTION: Detect the primary language of the user input and output its ISO 639-1 code in 'detected_language' (e.g., 'es', 'en', 'pt').",
20
- "REASONING_LOG: Provide a concise, step-by-step logical justification of the proposed strategy and of each selected tool in 'reasoning' strictly in English.",
21
- "STRICT_ENGLISH_OUTPUT: ALL output fields ('goal', 'hypothesis', 'required_capabilities' and 'reasoning') MUST strictly be written in English, regardless of the user input language. 'tool_names' must keep the exact original tool names.",
22
- "STRICT_OUTPUT: Return ONLY the JSON object matching response_schema."
23
- ],
24
- response_schema: {
25
- goal: "string",
26
- hypothesis: "string",
27
- required_capabilities: "array of strings",
28
- tool_names: "array of strings, each one an exact 'name' from toolsMeta",
29
- detected_language: "string",
30
- reasoning: "string",
31
- is_continuation: "boolean"
32
- }
33
- }
34
- }
35
- });
36
- export {
37
- strategyEngine
38
- };
@@ -1,24 +0,0 @@
1
- import { ObjectId } from 'mongodb';
2
- import { PipelineStage } from '../../../common/repositories/index.js';
3
- import { BaseUseCase, BaseUseCaseParams, BaseUseCaseOutput } from '../../../common/base/base.use-case.js';
4
- import { LLMCallRepository } from '../repositories';
5
- import { UsageTotals } from '../utils/usage-totals';
6
- export interface Params extends BaseUseCaseParams {
7
- filters: {
8
- sessionId?: string;
9
- messageId?: string;
10
- };
11
- }
12
- export interface Output extends BaseUseCaseOutput {
13
- data: UsageTotals;
14
- }
15
- export declare const buildUsagePipeline: (params: {
16
- ownerId: ObjectId;
17
- sessionId?: ObjectId;
18
- answerId?: ObjectId;
19
- }) => PipelineStage[];
20
- export declare class GetLLMUsageUseCase extends BaseUseCase<Params, Output> {
21
- private readonly llmCallRepository?;
22
- constructor(llmCallRepository?: LLMCallRepository | undefined);
23
- execute(params: Params): Promise<Output>;
24
- }
@@ -1,51 +0,0 @@
1
- import {
2
- __decorateClass,
3
- __decorateParam
4
- } from "../../../chunk-CF3WOMB3.mjs";
5
- import { autoInjectable, inject } from "tsyringe";
6
- import { ObjectId } from "mongodb";
7
- import { BaseUseCase } from "../../../common/base/base.use-case.js";
8
- import { LLMCallRepository } from "../repositories";
9
- import { usageSums, toUsageTotals } from "../utils/usage-totals";
10
- const buildUsagePipeline = (params) => {
11
- const { ownerId, sessionId, answerId } = params;
12
- return [
13
- {
14
- $match: {
15
- ownerId,
16
- deletedAt: null,
17
- ...sessionId ? { sessionId } : {},
18
- ...answerId ? { answerId } : {}
19
- }
20
- },
21
- { $group: { _id: null, ...usageSums() } }
22
- ];
23
- };
24
- let GetLLMUsageUseCase = class extends BaseUseCase {
25
- constructor(llmCallRepository) {
26
- super();
27
- this.llmCallRepository = llmCallRepository;
28
- }
29
- llmCallRepository;
30
- async execute(params) {
31
- const { filters, currentUser } = params;
32
- const { sessionId, messageId } = filters ?? {};
33
- const ownerId = currentUser?.userId;
34
- if (!ownerId || !sessionId && !messageId) return { data: toUsageTotals() };
35
- const pipeline = buildUsagePipeline({
36
- ownerId: new ObjectId(ownerId),
37
- sessionId: sessionId ? new ObjectId(sessionId) : void 0,
38
- answerId: messageId ? new ObjectId(messageId) : void 0
39
- });
40
- const [result] = await this.llmCallRepository?._.aggregate(pipeline);
41
- return { data: toUsageTotals(result) };
42
- }
43
- };
44
- GetLLMUsageUseCase = __decorateClass([
45
- autoInjectable(),
46
- __decorateParam(0, inject(LLMCallRepository))
47
- ], GetLLMUsageUseCase);
48
- export {
49
- GetLLMUsageUseCase,
50
- buildUsagePipeline
51
- };
@@ -1,30 +0,0 @@
1
- import { LLMClient } from '../clients/llm-client.js';
2
- import { CurrentUser, CurrentSession } from '../common/base/index.js';
3
- interface SkillDefinition<TResponse = Record<string, any>> {
4
- name: string;
5
- version?: string;
6
- description?: string;
7
- temperature?: number;
8
- systemInstructions: Record<string, any>;
9
- readonly _responseType?: TResponse;
10
- }
11
- export interface SkillExecuteOptions<TResponse = any, TInput = Record<string, any>> {
12
- skill: SkillDefinition<TResponse>;
13
- sessionId: string;
14
- answerId: string;
15
- userMessage?: string;
16
- currentUser?: CurrentUser;
17
- currentSession?: CurrentSession;
18
- contextInjection?: Record<string, any>;
19
- input?: TInput;
20
- }
21
- export declare class SkillRunner {
22
- private readonly llmClient;
23
- constructor(llmClient: LLMClient);
24
- execute<TResponse>(options: SkillExecuteOptions<TResponse>): Promise<TResponse & {
25
- responseId: string;
26
- costInUsd: number;
27
- }>;
28
- private parseJsonResponse;
29
- }
30
- export {};