mojentic 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +459 -0
- package/dist/agents/async-aggregator-agent.d.ts +101 -0
- package/dist/agents/async-aggregator-agent.d.ts.map +1 -0
- package/dist/agents/async-aggregator-agent.js +160 -0
- package/dist/agents/async-aggregator-agent.js.map +1 -0
- package/dist/agents/async-dispatcher.d.ts +98 -0
- package/dist/agents/async-dispatcher.d.ts.map +1 -0
- package/dist/agents/async-dispatcher.js +173 -0
- package/dist/agents/async-dispatcher.js.map +1 -0
- package/dist/agents/async-llm-agent-with-memory.d.ts +95 -0
- package/dist/agents/async-llm-agent-with-memory.d.ts.map +1 -0
- package/dist/agents/async-llm-agent-with-memory.js +136 -0
- package/dist/agents/async-llm-agent-with-memory.js.map +1 -0
- package/dist/agents/async-llm-agent.d.ts +85 -0
- package/dist/agents/async-llm-agent.d.ts.map +1 -0
- package/dist/agents/async-llm-agent.js +87 -0
- package/dist/agents/async-llm-agent.js.map +1 -0
- package/dist/agents/base-agent.d.ts +59 -0
- package/dist/agents/base-agent.d.ts.map +1 -0
- package/dist/agents/base-agent.js +24 -0
- package/dist/agents/base-agent.js.map +1 -0
- package/dist/agents/base-async-agent.d.ts +42 -0
- package/dist/agents/base-async-agent.d.ts.map +1 -0
- package/dist/agents/base-async-agent.js +6 -0
- package/dist/agents/base-async-agent.js.map +1 -0
- package/dist/agents/event.d.ts +26 -0
- package/dist/agents/event.d.ts.map +1 -0
- package/dist/agents/event.js +13 -0
- package/dist/agents/event.js.map +1 -0
- package/dist/agents/index.d.ts +14 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +30 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/iterative-problem-solver.d.ts +83 -0
- package/dist/agents/iterative-problem-solver.d.ts.map +1 -0
- package/dist/agents/iterative-problem-solver.js +120 -0
- package/dist/agents/iterative-problem-solver.js.map +1 -0
- package/dist/agents/router.d.ts +44 -0
- package/dist/agents/router.d.ts.map +1 -0
- package/dist/agents/router.js +53 -0
- package/dist/agents/router.js.map +1 -0
- package/dist/agents/simple-recursive-agent.d.ts +182 -0
- package/dist/agents/simple-recursive-agent.d.ts.map +1 -0
- package/dist/agents/simple-recursive-agent.js +272 -0
- package/dist/agents/simple-recursive-agent.js.map +1 -0
- package/dist/context/index.d.ts +5 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +21 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/shared-working-memory.d.ts +76 -0
- package/dist/context/shared-working-memory.d.ts.map +1 -0
- package/dist/context/shared-working-memory.js +121 -0
- package/dist/context/shared-working-memory.js.map +1 -0
- package/dist/error.d.ts +93 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +149 -0
- package/dist/error.js.map +1 -0
- package/dist/examples/react/decisioning-agent.d.ts +48 -0
- package/dist/examples/react/decisioning-agent.d.ts.map +1 -0
- package/dist/examples/react/decisioning-agent.js +204 -0
- package/dist/examples/react/decisioning-agent.js.map +1 -0
- package/dist/examples/react/events.d.ts +77 -0
- package/dist/examples/react/events.d.ts.map +1 -0
- package/dist/examples/react/events.js +9 -0
- package/dist/examples/react/events.js.map +1 -0
- package/dist/examples/react/formatters.d.ts +23 -0
- package/dist/examples/react/formatters.d.ts.map +1 -0
- package/dist/examples/react/formatters.js +68 -0
- package/dist/examples/react/formatters.js.map +1 -0
- package/dist/examples/react/index.d.ts +12 -0
- package/dist/examples/react/index.d.ts.map +1 -0
- package/dist/examples/react/index.js +28 -0
- package/dist/examples/react/index.js.map +1 -0
- package/dist/examples/react/models.d.ts +57 -0
- package/dist/examples/react/models.d.ts.map +1 -0
- package/dist/examples/react/models.js +19 -0
- package/dist/examples/react/models.js.map +1 -0
- package/dist/examples/react/output-agent.d.ts +23 -0
- package/dist/examples/react/output-agent.d.ts.map +1 -0
- package/dist/examples/react/output-agent.js +28 -0
- package/dist/examples/react/output-agent.js.map +1 -0
- package/dist/examples/react/summarization-agent.d.ts +46 -0
- package/dist/examples/react/summarization-agent.d.ts.map +1 -0
- package/dist/examples/react/summarization-agent.js +102 -0
- package/dist/examples/react/summarization-agent.js.map +1 -0
- package/dist/examples/react/thinking-agent.d.ts +47 -0
- package/dist/examples/react/thinking-agent.d.ts.map +1 -0
- package/dist/examples/react/thinking-agent.js +127 -0
- package/dist/examples/react/thinking-agent.js.map +1 -0
- package/dist/examples/react/tool-call-agent.d.ts +25 -0
- package/dist/examples/react/tool-call-agent.d.ts.map +1 -0
- package/dist/examples/react/tool-call-agent.js +83 -0
- package/dist/examples/react/tool-call-agent.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/llm/agent.d.ts +68 -0
- package/dist/llm/agent.d.ts.map +1 -0
- package/dist/llm/agent.js +85 -0
- package/dist/llm/agent.js.map +1 -0
- package/dist/llm/broker.d.ts +150 -0
- package/dist/llm/broker.d.ts.map +1 -0
- package/dist/llm/broker.js +355 -0
- package/dist/llm/broker.js.map +1 -0
- package/dist/llm/chat-session.d.ts +98 -0
- package/dist/llm/chat-session.d.ts.map +1 -0
- package/dist/llm/chat-session.js +156 -0
- package/dist/llm/chat-session.js.map +1 -0
- package/dist/llm/gateway.d.ts +28 -0
- package/dist/llm/gateway.d.ts.map +1 -0
- package/dist/llm/gateway.js +6 -0
- package/dist/llm/gateway.js.map +1 -0
- package/dist/llm/gateways/index.d.ts +9 -0
- package/dist/llm/gateways/index.d.ts.map +1 -0
- package/dist/llm/gateways/index.js +25 -0
- package/dist/llm/gateways/index.js.map +1 -0
- package/dist/llm/gateways/ollama.d.ts +30 -0
- package/dist/llm/gateways/ollama.d.ts.map +1 -0
- package/dist/llm/gateways/ollama.js +322 -0
- package/dist/llm/gateways/ollama.js.map +1 -0
- package/dist/llm/gateways/openai-messages-adapter.d.ts +29 -0
- package/dist/llm/gateways/openai-messages-adapter.d.ts.map +1 -0
- package/dist/llm/gateways/openai-messages-adapter.js +188 -0
- package/dist/llm/gateways/openai-messages-adapter.js.map +1 -0
- package/dist/llm/gateways/openai-model-registry.d.ts +82 -0
- package/dist/llm/gateways/openai-model-registry.d.ts.map +1 -0
- package/dist/llm/gateways/openai-model-registry.js +352 -0
- package/dist/llm/gateways/openai-model-registry.js.map +1 -0
- package/dist/llm/gateways/openai.d.ts +40 -0
- package/dist/llm/gateways/openai.d.ts.map +1 -0
- package/dist/llm/gateways/openai.js +469 -0
- package/dist/llm/gateways/openai.js.map +1 -0
- package/dist/llm/gateways/tokenizerGateway.d.ts +61 -0
- package/dist/llm/gateways/tokenizerGateway.d.ts.map +1 -0
- package/dist/llm/gateways/tokenizerGateway.js +75 -0
- package/dist/llm/gateways/tokenizerGateway.js.map +1 -0
- package/dist/llm/index.d.ts +11 -0
- package/dist/llm/index.d.ts.map +1 -0
- package/dist/llm/index.js +27 -0
- package/dist/llm/index.js.map +1 -0
- package/dist/llm/models.d.ts +95 -0
- package/dist/llm/models.d.ts.map +1 -0
- package/dist/llm/models.js +50 -0
- package/dist/llm/models.js.map +1 -0
- package/dist/llm/tools/ask-user.d.ts +39 -0
- package/dist/llm/tools/ask-user.d.ts.map +1 -0
- package/dist/llm/tools/ask-user.js +111 -0
- package/dist/llm/tools/ask-user.js.map +1 -0
- package/dist/llm/tools/current-datetime.d.ts +17 -0
- package/dist/llm/tools/current-datetime.d.ts.map +1 -0
- package/dist/llm/tools/current-datetime.js +76 -0
- package/dist/llm/tools/current-datetime.js.map +1 -0
- package/dist/llm/tools/date-resolver.d.ts +17 -0
- package/dist/llm/tools/date-resolver.d.ts.map +1 -0
- package/dist/llm/tools/date-resolver.js +135 -0
- package/dist/llm/tools/date-resolver.js.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/append-task.d.ts +13 -0
- package/dist/llm/tools/ephemeral-task-manager/append-task.d.ts.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/append-task.js +54 -0
- package/dist/llm/tools/ephemeral-task-manager/append-task.js.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/clear-tasks.d.ts +13 -0
- package/dist/llm/tools/ephemeral-task-manager/clear-tasks.d.ts.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/clear-tasks.js +37 -0
- package/dist/llm/tools/ephemeral-task-manager/clear-tasks.js.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/complete-task.d.ts +15 -0
- package/dist/llm/tools/ephemeral-task-manager/complete-task.d.ts.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/complete-task.js +56 -0
- package/dist/llm/tools/ephemeral-task-manager/complete-task.js.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/index.d.ts +44 -0
- package/dist/llm/tools/ephemeral-task-manager/index.d.ts.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/index.js +73 -0
- package/dist/llm/tools/ephemeral-task-manager/index.js.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/insert-task-after.d.ts +13 -0
- package/dist/llm/tools/ephemeral-task-manager/insert-task-after.d.ts.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/insert-task-after.js +59 -0
- package/dist/llm/tools/ephemeral-task-manager/insert-task-after.js.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/list-tasks.d.ts +14 -0
- package/dist/llm/tools/ephemeral-task-manager/list-tasks.d.ts.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/list-tasks.js +45 -0
- package/dist/llm/tools/ephemeral-task-manager/list-tasks.js.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/prepend-task.d.ts +13 -0
- package/dist/llm/tools/ephemeral-task-manager/prepend-task.d.ts.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/prepend-task.js +54 -0
- package/dist/llm/tools/ephemeral-task-manager/prepend-task.js.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/start-task.d.ts +15 -0
- package/dist/llm/tools/ephemeral-task-manager/start-task.d.ts.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/start-task.js +56 -0
- package/dist/llm/tools/ephemeral-task-manager/start-task.js.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/task-list.d.ts +68 -0
- package/dist/llm/tools/ephemeral-task-manager/task-list.d.ts.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/task-list.js +120 -0
- package/dist/llm/tools/ephemeral-task-manager/task-list.js.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/task.d.ts +21 -0
- package/dist/llm/tools/ephemeral-task-manager/task.d.ts.map +1 -0
- package/dist/llm/tools/ephemeral-task-manager/task.js +24 -0
- package/dist/llm/tools/ephemeral-task-manager/task.js.map +1 -0
- package/dist/llm/tools/file-manager.d.ts +127 -0
- package/dist/llm/tools/file-manager.d.ts.map +1 -0
- package/dist/llm/tools/file-manager.js +598 -0
- package/dist/llm/tools/file-manager.js.map +1 -0
- package/dist/llm/tools/index.d.ts +11 -0
- package/dist/llm/tools/index.d.ts.map +1 -0
- package/dist/llm/tools/index.js +27 -0
- package/dist/llm/tools/index.js.map +1 -0
- package/dist/llm/tools/tell-user.d.ts +31 -0
- package/dist/llm/tools/tell-user.d.ts.map +1 -0
- package/dist/llm/tools/tell-user.js +57 -0
- package/dist/llm/tools/tell-user.js.map +1 -0
- package/dist/llm/tools/tool-wrapper.d.ts +54 -0
- package/dist/llm/tools/tool-wrapper.d.ts.map +1 -0
- package/dist/llm/tools/tool-wrapper.js +91 -0
- package/dist/llm/tools/tool-wrapper.js.map +1 -0
- package/dist/llm/tools/tool.d.ts +70 -0
- package/dist/llm/tools/tool.d.ts.map +1 -0
- package/dist/llm/tools/tool.js +19 -0
- package/dist/llm/tools/tool.js.map +1 -0
- package/dist/llm/tools/web-search-tool.d.ts +35 -0
- package/dist/llm/tools/web-search-tool.d.ts.map +1 -0
- package/dist/llm/tools/web-search-tool.js +105 -0
- package/dist/llm/tools/web-search-tool.js.map +1 -0
- package/dist/llm/utils/image.d.ts +30 -0
- package/dist/llm/utils/image.d.ts.map +1 -0
- package/dist/llm/utils/image.js +65 -0
- package/dist/llm/utils/image.js.map +1 -0
- package/dist/tracer/eventStore.d.ts +101 -0
- package/dist/tracer/eventStore.d.ts.map +1 -0
- package/dist/tracer/eventStore.js +120 -0
- package/dist/tracer/eventStore.js.map +1 -0
- package/dist/tracer/index.d.ts +8 -0
- package/dist/tracer/index.d.ts.map +1 -0
- package/dist/tracer/index.js +24 -0
- package/dist/tracer/index.js.map +1 -0
- package/dist/tracer/nullTracer.d.ts +127 -0
- package/dist/tracer/nullTracer.d.ts.map +1 -0
- package/dist/tracer/nullTracer.js +148 -0
- package/dist/tracer/nullTracer.js.map +1 -0
- package/dist/tracer/tracerEvents.d.ts +209 -0
- package/dist/tracer/tracerEvents.d.ts.map +1 -0
- package/dist/tracer/tracerEvents.js +312 -0
- package/dist/tracer/tracerEvents.js.map +1 -0
- package/dist/tracer/tracerSystem.d.ts +149 -0
- package/dist/tracer/tracerSystem.d.ts.map +1 -0
- package/dist/tracer/tracerSystem.js +196 -0
- package/dist/tracer/tracerSystem.js.map +1 -0
- package/package.json +87 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tell user tool - displays messages to the user without expecting a response
|
|
3
|
+
*/
|
|
4
|
+
import { BaseTool, ToolArgs, ToolDescriptor, ToolResult } from './tool';
|
|
5
|
+
import { Result } from '../../error';
|
|
6
|
+
/**
|
|
7
|
+
* Tool that displays messages to the user without expecting a response
|
|
8
|
+
*
|
|
9
|
+
* This tool allows the LLM to send important intermediate information to the user
|
|
10
|
+
* as it works on completing their request. It's useful for providing status updates,
|
|
11
|
+
* progress information, or other important messages during long-running operations.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const tool = new TellUserTool();
|
|
16
|
+
* const result = await tool.run({ message: "Processing your request..." });
|
|
17
|
+
* // Prints to stdout:
|
|
18
|
+
* //
|
|
19
|
+
* //
|
|
20
|
+
* //
|
|
21
|
+
* // MESSAGE FROM ASSISTANT:
|
|
22
|
+
* // Processing your request...
|
|
23
|
+
* //
|
|
24
|
+
* // Returns: Ok("Message delivered to user.")
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare class TellUserTool extends BaseTool {
|
|
28
|
+
run(args: ToolArgs): Promise<Result<ToolResult, Error>>;
|
|
29
|
+
descriptor(): ToolDescriptor;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=tell-user.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tell-user.d.ts","sourceRoot":"","sources":["../../../src/llm/tools/tell-user.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACxE,OAAO,EAAM,MAAM,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,YAAa,SAAQ,QAAQ;IAClC,GAAG,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAQ7D,UAAU,IAAI,cAAc;CAoB7B"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tell user tool - displays messages to the user without expecting a response
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TellUserTool = void 0;
|
|
7
|
+
const tool_1 = require("./tool");
|
|
8
|
+
const error_1 = require("../../error");
|
|
9
|
+
/**
|
|
10
|
+
* Tool that displays messages to the user without expecting a response
|
|
11
|
+
*
|
|
12
|
+
* This tool allows the LLM to send important intermediate information to the user
|
|
13
|
+
* as it works on completing their request. It's useful for providing status updates,
|
|
14
|
+
* progress information, or other important messages during long-running operations.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const tool = new TellUserTool();
|
|
19
|
+
* const result = await tool.run({ message: "Processing your request..." });
|
|
20
|
+
* // Prints to stdout:
|
|
21
|
+
* //
|
|
22
|
+
* //
|
|
23
|
+
* //
|
|
24
|
+
* // MESSAGE FROM ASSISTANT:
|
|
25
|
+
* // Processing your request...
|
|
26
|
+
* //
|
|
27
|
+
* // Returns: Ok("Message delivered to user.")
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
class TellUserTool extends tool_1.BaseTool {
|
|
31
|
+
async run(args) {
|
|
32
|
+
const message = args.message || '';
|
|
33
|
+
console.log(`\n\n\nMESSAGE FROM ASSISTANT:\n${message}`);
|
|
34
|
+
return (0, error_1.Ok)('Message delivered to user.');
|
|
35
|
+
}
|
|
36
|
+
descriptor() {
|
|
37
|
+
return {
|
|
38
|
+
type: 'function',
|
|
39
|
+
function: {
|
|
40
|
+
name: 'tell_user',
|
|
41
|
+
description: 'Display a message to the user without expecting a response. Use this to send important intermediate information to the user as you work on completing their request.',
|
|
42
|
+
parameters: {
|
|
43
|
+
type: 'object',
|
|
44
|
+
properties: {
|
|
45
|
+
message: {
|
|
46
|
+
type: 'string',
|
|
47
|
+
description: 'The important message you want to display to the user.',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
required: ['message'],
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.TellUserTool = TellUserTool;
|
|
57
|
+
//# sourceMappingURL=tell-user.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tell-user.js","sourceRoot":"","sources":["../../../src/llm/tools/tell-user.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iCAAwE;AACxE,uCAAyC;AAEzC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,YAAa,SAAQ,eAAQ;IACxC,KAAK,CAAC,GAAG,CAAC,IAAc;QACtB,MAAM,OAAO,GAAI,IAAI,CAAC,OAAkB,IAAI,EAAE,CAAC;QAE/C,OAAO,CAAC,GAAG,CAAC,kCAAkC,OAAO,EAAE,CAAC,CAAC;QAEzD,OAAO,IAAA,UAAE,EAAC,4BAA4B,CAAC,CAAC;IAC1C,CAAC;IAED,UAAU;QACR,OAAO;YACL,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE;gBACR,IAAI,EAAE,WAAW;gBACjB,WAAW,EACT,sKAAsK;gBACxK,UAAU,EAAE;oBACV,IAAI,EAAE,QAAQ;oBACd,UAAU,EAAE;wBACV,OAAO,EAAE;4BACP,IAAI,EAAE,QAAQ;4BACd,WAAW,EAAE,wDAAwD;yBACtE;qBACF;oBACD,QAAQ,EAAE,CAAC,SAAS,CAAC;iBACtB;aACF;SACF,CAAC;IACJ,CAAC;CACF;AA7BD,oCA6BC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Wrapper - Wraps agents as tools for agent delegation
|
|
3
|
+
*/
|
|
4
|
+
import { BaseTool, ToolArgs, ToolDescriptor, ToolResult } from './tool';
|
|
5
|
+
import { Result } from '../../error';
|
|
6
|
+
import { Agent } from '../agent';
|
|
7
|
+
/**
|
|
8
|
+
* Wraps an agent as a tool, enabling agent delegation patterns.
|
|
9
|
+
*
|
|
10
|
+
* This allows one agent (coordinator) to use other agents (specialists)
|
|
11
|
+
* as tools, delegating specific tasks to domain experts.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const specialist = new Agent(
|
|
16
|
+
* new LlmBroker('qwen3:7b', gateway),
|
|
17
|
+
* [new DateResolverTool()],
|
|
18
|
+
* 'You are a temporal specialist...'
|
|
19
|
+
* );
|
|
20
|
+
*
|
|
21
|
+
* const coordinator = new Agent(
|
|
22
|
+
* new LlmBroker('qwen3:32b', gateway),
|
|
23
|
+
* [new ToolWrapper(specialist, 'temporal_specialist', 'A historian...')],
|
|
24
|
+
* 'You are a coordinator...'
|
|
25
|
+
* );
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare class ToolWrapper extends BaseTool {
|
|
29
|
+
private readonly agent;
|
|
30
|
+
private readonly toolName;
|
|
31
|
+
private readonly toolDescription;
|
|
32
|
+
/**
|
|
33
|
+
* Creates a new tool wrapper.
|
|
34
|
+
*
|
|
35
|
+
* @param agent - The agent to wrap as a tool
|
|
36
|
+
* @param toolName - Name for the tool (used in function calls)
|
|
37
|
+
* @param toolDescription - Description of what this agent does
|
|
38
|
+
*/
|
|
39
|
+
constructor(agent: Agent, toolName: string, toolDescription: string);
|
|
40
|
+
/**
|
|
41
|
+
* Execute the wrapped agent with the given input.
|
|
42
|
+
*
|
|
43
|
+
* @param args - Tool arguments (must contain 'input' field)
|
|
44
|
+
* @returns Result containing the agent's response
|
|
45
|
+
*/
|
|
46
|
+
run(args: ToolArgs): Promise<Result<ToolResult, Error>>;
|
|
47
|
+
/**
|
|
48
|
+
* Get the tool descriptor for LLM.
|
|
49
|
+
*
|
|
50
|
+
* @returns Tool descriptor with single 'input' parameter
|
|
51
|
+
*/
|
|
52
|
+
descriptor(): ToolDescriptor;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=tool-wrapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-wrapper.d.ts","sourceRoot":"","sources":["../../../src/llm/tools/tool-wrapper.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAGjC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,WAAY,SAAQ,QAAQ;IASrC,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAVlC;;;;;;OAMG;gBAEgB,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,MAAM,EAChB,eAAe,EAAE,MAAM;IAK1C;;;;;OAKG;IACG,GAAG,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAgB7D;;;;OAIG;IACH,UAAU,IAAI,cAAc;CAmB7B"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tool Wrapper - Wraps agents as tools for agent delegation
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ToolWrapper = void 0;
|
|
7
|
+
const tool_1 = require("./tool");
|
|
8
|
+
const models_1 = require("../models");
|
|
9
|
+
/**
|
|
10
|
+
* Wraps an agent as a tool, enabling agent delegation patterns.
|
|
11
|
+
*
|
|
12
|
+
* This allows one agent (coordinator) to use other agents (specialists)
|
|
13
|
+
* as tools, delegating specific tasks to domain experts.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const specialist = new Agent(
|
|
18
|
+
* new LlmBroker('qwen3:7b', gateway),
|
|
19
|
+
* [new DateResolverTool()],
|
|
20
|
+
* 'You are a temporal specialist...'
|
|
21
|
+
* );
|
|
22
|
+
*
|
|
23
|
+
* const coordinator = new Agent(
|
|
24
|
+
* new LlmBroker('qwen3:32b', gateway),
|
|
25
|
+
* [new ToolWrapper(specialist, 'temporal_specialist', 'A historian...')],
|
|
26
|
+
* 'You are a coordinator...'
|
|
27
|
+
* );
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
class ToolWrapper extends tool_1.BaseTool {
|
|
31
|
+
agent;
|
|
32
|
+
toolName;
|
|
33
|
+
toolDescription;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new tool wrapper.
|
|
36
|
+
*
|
|
37
|
+
* @param agent - The agent to wrap as a tool
|
|
38
|
+
* @param toolName - Name for the tool (used in function calls)
|
|
39
|
+
* @param toolDescription - Description of what this agent does
|
|
40
|
+
*/
|
|
41
|
+
constructor(agent, toolName, toolDescription) {
|
|
42
|
+
super();
|
|
43
|
+
this.agent = agent;
|
|
44
|
+
this.toolName = toolName;
|
|
45
|
+
this.toolDescription = toolDescription;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Execute the wrapped agent with the given input.
|
|
49
|
+
*
|
|
50
|
+
* @param args - Tool arguments (must contain 'input' field)
|
|
51
|
+
* @returns Result containing the agent's response
|
|
52
|
+
*/
|
|
53
|
+
async run(args) {
|
|
54
|
+
const input = args.input;
|
|
55
|
+
if (!input) {
|
|
56
|
+
return { ok: true, value: { error: 'input is required' } };
|
|
57
|
+
}
|
|
58
|
+
// Create initial messages from agent's behavior
|
|
59
|
+
const messages = this.agent.createInitialMessages();
|
|
60
|
+
// Append the input as a user message
|
|
61
|
+
messages.push(models_1.Message.user(input));
|
|
62
|
+
// Call the agent's broker with the agent's tools
|
|
63
|
+
return this.agent.getBroker().generate(messages, this.agent.getTools());
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get the tool descriptor for LLM.
|
|
67
|
+
*
|
|
68
|
+
* @returns Tool descriptor with single 'input' parameter
|
|
69
|
+
*/
|
|
70
|
+
descriptor() {
|
|
71
|
+
return {
|
|
72
|
+
type: 'function',
|
|
73
|
+
function: {
|
|
74
|
+
name: this.toolName,
|
|
75
|
+
description: this.toolDescription,
|
|
76
|
+
parameters: {
|
|
77
|
+
type: 'object',
|
|
78
|
+
properties: {
|
|
79
|
+
input: {
|
|
80
|
+
type: 'string',
|
|
81
|
+
description: 'Instructions for this agent.',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
required: ['input'],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.ToolWrapper = ToolWrapper;
|
|
91
|
+
//# sourceMappingURL=tool-wrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-wrapper.js","sourceRoot":"","sources":["../../../src/llm/tools/tool-wrapper.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iCAAwE;AAGxE,sCAAoC;AAEpC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,WAAY,SAAQ,eAAQ;IASpB;IACA;IACA;IAVnB;;;;;;OAMG;IACH,YACmB,KAAY,EACZ,QAAgB,EAChB,eAAuB;QAExC,KAAK,EAAE,CAAC;QAJS,UAAK,GAAL,KAAK,CAAO;QACZ,aAAQ,GAAR,QAAQ,CAAQ;QAChB,oBAAe,GAAf,eAAe,CAAQ;IAG1C,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAG,CAAC,IAAc;QACtB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAe,CAAC;QACnC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,mBAAmB,EAAE,EAAE,CAAC;QAC7D,CAAC;QAED,gDAAgD;QAChD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,qBAAqB,EAAE,CAAC;QAEpD,qCAAqC;QACrC,QAAQ,CAAC,IAAI,CAAC,gBAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAEnC,iDAAiD;QACjD,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC1E,CAAC;IAED;;;;OAIG;IACH,UAAU;QACR,OAAO;YACL,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE;gBACR,IAAI,EAAE,IAAI,CAAC,QAAQ;gBACnB,WAAW,EAAE,IAAI,CAAC,eAAe;gBACjC,UAAU,EAAE;oBACV,IAAI,EAAE,QAAQ;oBACd,UAAU,EAAE;wBACV,KAAK,EAAE;4BACL,IAAI,EAAE,QAAQ;4BACd,WAAW,EAAE,8BAA8B;yBAC5C;qBACF;oBACD,QAAQ,EAAE,CAAC,OAAO,CAAC;iBACpB;aACF;SACF,CAAC;IACJ,CAAC;CACF;AA9DD,kCA8DC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool system for LLM function calling
|
|
3
|
+
*/
|
|
4
|
+
import { Result } from '../../error';
|
|
5
|
+
/**
|
|
6
|
+
* JSON Schema definition for tool parameters
|
|
7
|
+
*/
|
|
8
|
+
export interface JsonSchema {
|
|
9
|
+
type: string;
|
|
10
|
+
properties?: Record<string, JsonSchema>;
|
|
11
|
+
items?: JsonSchema;
|
|
12
|
+
required?: string[];
|
|
13
|
+
description?: string;
|
|
14
|
+
enum?: unknown[];
|
|
15
|
+
[key: string]: unknown;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Function descriptor for tool calling
|
|
19
|
+
*/
|
|
20
|
+
export interface FunctionDescriptor {
|
|
21
|
+
name: string;
|
|
22
|
+
description: string;
|
|
23
|
+
parameters: JsonSchema;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Tool descriptor for LLM
|
|
27
|
+
*/
|
|
28
|
+
export interface ToolDescriptor {
|
|
29
|
+
type: 'function';
|
|
30
|
+
function: FunctionDescriptor;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Arguments passed to a tool
|
|
34
|
+
*/
|
|
35
|
+
export type ToolArgs = Record<string, unknown>;
|
|
36
|
+
/**
|
|
37
|
+
* Result of a tool execution
|
|
38
|
+
*/
|
|
39
|
+
export type ToolResult = Record<string, unknown> | string | number | boolean | null;
|
|
40
|
+
/**
|
|
41
|
+
* Interface for LLM tools
|
|
42
|
+
*/
|
|
43
|
+
export interface LlmTool {
|
|
44
|
+
/**
|
|
45
|
+
* Execute the tool with the given arguments
|
|
46
|
+
*/
|
|
47
|
+
run(args: ToolArgs): Promise<Result<ToolResult, Error>>;
|
|
48
|
+
/**
|
|
49
|
+
* Get the tool descriptor for LLM
|
|
50
|
+
*/
|
|
51
|
+
descriptor(): ToolDescriptor;
|
|
52
|
+
/**
|
|
53
|
+
* Get the tool name
|
|
54
|
+
*/
|
|
55
|
+
name(): string;
|
|
56
|
+
/**
|
|
57
|
+
* Check if tool name matches given name
|
|
58
|
+
*/
|
|
59
|
+
matches(name: string): boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Abstract base class for tools
|
|
63
|
+
*/
|
|
64
|
+
export declare abstract class BaseTool implements LlmTool {
|
|
65
|
+
abstract run(args: ToolArgs): Promise<Result<ToolResult, Error>>;
|
|
66
|
+
abstract descriptor(): ToolDescriptor;
|
|
67
|
+
name(): string;
|
|
68
|
+
matches(name: string): boolean;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../../src/llm/tools/tool.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACxC,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,UAAU,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,kBAAkB,CAAC;CAC9B;AAED;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC;AAEpF;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC;IAExD;;OAEG;IACH,UAAU,IAAI,cAAc,CAAC;IAE7B;;OAEG;IACH,IAAI,IAAI,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAChC;AAED;;GAEG;AACH,8BAAsB,QAAS,YAAW,OAAO;IAC/C,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IAChE,QAAQ,CAAC,UAAU,IAAI,cAAc;IAErC,IAAI,IAAI,MAAM;IAId,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAG/B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tool system for LLM function calling
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BaseTool = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Abstract base class for tools
|
|
9
|
+
*/
|
|
10
|
+
class BaseTool {
|
|
11
|
+
name() {
|
|
12
|
+
return this.descriptor().function.name;
|
|
13
|
+
}
|
|
14
|
+
matches(name) {
|
|
15
|
+
return this.name() === name;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.BaseTool = BaseTool;
|
|
19
|
+
//# sourceMappingURL=tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../../../src/llm/tools/tool.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAqEH;;GAEG;AACH,MAAsB,QAAQ;IAI5B,IAAI;QACF,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC;IACzC,CAAC;IAED,OAAO,CAAC,IAAY;QAClB,OAAO,IAAI,CAAC,IAAI,EAAE,KAAK,IAAI,CAAC;IAC9B,CAAC;CACF;AAXD,4BAWC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web search tool - searches the web using DuckDuckGo
|
|
3
|
+
*/
|
|
4
|
+
import { BaseTool, ToolArgs, ToolDescriptor, ToolResult } from './tool';
|
|
5
|
+
import { Result } from '../../error';
|
|
6
|
+
/**
|
|
7
|
+
* Search result interface
|
|
8
|
+
*/
|
|
9
|
+
export interface SearchResult {
|
|
10
|
+
title: string;
|
|
11
|
+
url: string;
|
|
12
|
+
snippet: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Tool that searches the web using DuckDuckGo Lite
|
|
16
|
+
*/
|
|
17
|
+
export declare class WebSearchTool extends BaseTool {
|
|
18
|
+
private readonly baseUrl;
|
|
19
|
+
private readonly maxResults;
|
|
20
|
+
run(args: ToolArgs): Promise<Result<ToolResult, Error>>;
|
|
21
|
+
descriptor(): ToolDescriptor;
|
|
22
|
+
/**
|
|
23
|
+
* Parse search results from DuckDuckGo Lite HTML
|
|
24
|
+
*/
|
|
25
|
+
private parseResults;
|
|
26
|
+
/**
|
|
27
|
+
* Strip HTML tags from a string
|
|
28
|
+
*/
|
|
29
|
+
private stripHtmlTags;
|
|
30
|
+
/**
|
|
31
|
+
* Decode HTML entities
|
|
32
|
+
*/
|
|
33
|
+
private decodeHtmlEntities;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=web-search-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-search-tool.d.ts","sourceRoot":"","sources":["../../../src/llm/tools/web-search-tool.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACxE,OAAO,EAAW,MAAM,EAAE,MAAM,aAAa,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,QAAQ;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuC;IAC/D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAM;IAE3B,GAAG,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IA0B7D,UAAU,IAAI,cAAc;IAqB5B;;OAEG;IACH,OAAO,CAAC,YAAY;IA4BpB;;OAEG;IACH,OAAO,CAAC,aAAa;IAIrB;;OAEG;IACH,OAAO,CAAC,kBAAkB;CAkB3B"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Web search tool - searches the web using DuckDuckGo
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.WebSearchTool = void 0;
|
|
7
|
+
const tool_1 = require("./tool");
|
|
8
|
+
const error_1 = require("../../error");
|
|
9
|
+
/**
|
|
10
|
+
* Tool that searches the web using DuckDuckGo Lite
|
|
11
|
+
*/
|
|
12
|
+
class WebSearchTool extends tool_1.BaseTool {
|
|
13
|
+
baseUrl = 'https://lite.duckduckgo.com/lite/';
|
|
14
|
+
maxResults = 10;
|
|
15
|
+
async run(args) {
|
|
16
|
+
const query = args.query;
|
|
17
|
+
if (!query || typeof query !== 'string' || query.trim().length === 0) {
|
|
18
|
+
return (0, error_1.Err)(new Error('Query parameter is required and must be a non-empty string'));
|
|
19
|
+
}
|
|
20
|
+
try {
|
|
21
|
+
const encodedQuery = encodeURIComponent(query.trim());
|
|
22
|
+
const url = `${this.baseUrl}?q=${encodedQuery}`;
|
|
23
|
+
const response = await fetch(url);
|
|
24
|
+
if (!response.ok) {
|
|
25
|
+
return (0, error_1.Err)(new Error(`Search request failed with status ${response.status}`));
|
|
26
|
+
}
|
|
27
|
+
const html = await response.text();
|
|
28
|
+
const results = this.parseResults(html);
|
|
29
|
+
return (0, error_1.Ok)(JSON.stringify(results, null, 2));
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
return (0, error_1.Err)(error instanceof Error ? error : new Error('Unknown error during web search'));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
descriptor() {
|
|
36
|
+
return {
|
|
37
|
+
type: 'function',
|
|
38
|
+
function: {
|
|
39
|
+
name: 'web_search',
|
|
40
|
+
description: 'Search the web for information using DuckDuckGo. Returns organic search results.',
|
|
41
|
+
parameters: {
|
|
42
|
+
type: 'object',
|
|
43
|
+
properties: {
|
|
44
|
+
query: {
|
|
45
|
+
type: 'string',
|
|
46
|
+
description: 'The search query',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
required: ['query'],
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Parse search results from DuckDuckGo Lite HTML
|
|
56
|
+
*/
|
|
57
|
+
parseResults(html) {
|
|
58
|
+
const results = [];
|
|
59
|
+
// DuckDuckGo Lite uses table rows for results
|
|
60
|
+
// Each result has a structure like:
|
|
61
|
+
// <tr><td>...</td></tr> (ad/info rows)
|
|
62
|
+
// <tr><td valign="top">N.</td><td><a rel="nofollow" href="URL">Title</a><br>Snippet</td></tr>
|
|
63
|
+
// Match result rows with numbered entries
|
|
64
|
+
// Using [\s\S] instead of . with 's' flag for better compatibility
|
|
65
|
+
const resultPattern = /<tr>\s*<td[^>]*valign="top"[^>]*>\d+\.<\/td>\s*<td[^>]*>[\s\S]*?<a[^>]*href="([^"]+)"[^>]*>(.*?)<\/a>(?:<br\s*\/?>|\s*)([\s\S]*?)<\/td>\s*<\/tr>/gi;
|
|
66
|
+
let match;
|
|
67
|
+
while ((match = resultPattern.exec(html)) !== null && results.length < this.maxResults) {
|
|
68
|
+
const url = this.decodeHtmlEntities(match[1].trim());
|
|
69
|
+
const title = this.stripHtmlTags(this.decodeHtmlEntities(match[2].trim()));
|
|
70
|
+
const snippet = this.stripHtmlTags(this.decodeHtmlEntities(match[3].trim()));
|
|
71
|
+
// Only include results with meaningful content
|
|
72
|
+
if (url && title && snippet) {
|
|
73
|
+
results.push({ title, url, snippet });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return results;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Strip HTML tags from a string
|
|
80
|
+
*/
|
|
81
|
+
stripHtmlTags(text) {
|
|
82
|
+
return text.replace(/<[^>]*>/g, '').trim();
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Decode HTML entities
|
|
86
|
+
*/
|
|
87
|
+
decodeHtmlEntities(text) {
|
|
88
|
+
const entities = {
|
|
89
|
+
'&': '&',
|
|
90
|
+
'<': '<',
|
|
91
|
+
'>': '>',
|
|
92
|
+
'"': '"',
|
|
93
|
+
''': "'",
|
|
94
|
+
' ': ' ',
|
|
95
|
+
};
|
|
96
|
+
let result = text;
|
|
97
|
+
for (const [entity, char] of Object.entries(entities)) {
|
|
98
|
+
// eslint-disable-next-line security/detect-non-literal-regexp -- Entity patterns are from controlled set
|
|
99
|
+
result = result.replace(new RegExp(entity, 'g'), char);
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.WebSearchTool = WebSearchTool;
|
|
105
|
+
//# sourceMappingURL=web-search-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-search-tool.js","sourceRoot":"","sources":["../../../src/llm/tools/web-search-tool.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iCAAwE;AACxE,uCAA8C;AAW9C;;GAEG;AACH,MAAa,aAAc,SAAQ,eAAQ;IACxB,OAAO,GAAG,mCAAmC,CAAC;IAC9C,UAAU,GAAG,EAAE,CAAC;IAEjC,KAAK,CAAC,GAAG,CAAC,IAAc;QACtB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAe,CAAC;QAEnC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACrE,OAAO,IAAA,WAAG,EAAC,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC,CAAC;QACtF,CAAC;QAED,IAAI,CAAC;YACH,MAAM,YAAY,GAAG,kBAAkB,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;YACtD,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,MAAM,YAAY,EAAE,CAAC;YAEhD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;YAElC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACjB,OAAO,IAAA,WAAG,EAAC,IAAI,KAAK,CAAC,qCAAqC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;YAChF,CAAC;YAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnC,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YAExC,OAAO,IAAA,UAAE,EAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAC9C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,IAAA,WAAG,EAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC,CAAC;QAC5F,CAAC;IACH,CAAC;IAED,UAAU;QACR,OAAO;YACL,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE;gBACR,IAAI,EAAE,YAAY;gBAClB,WAAW,EACT,kFAAkF;gBACpF,UAAU,EAAE;oBACV,IAAI,EAAE,QAAQ;oBACd,UAAU,EAAE;wBACV,KAAK,EAAE;4BACL,IAAI,EAAE,QAAQ;4BACd,WAAW,EAAE,kBAAkB;yBAChC;qBACF;oBACD,QAAQ,EAAE,CAAC,OAAO,CAAC;iBACpB;aACF;SACF,CAAC;IACJ,CAAC;IAED;;OAEG;IACK,YAAY,CAAC,IAAY;QAC/B,MAAM,OAAO,GAAmB,EAAE,CAAC;QAEnC,8CAA8C;QAC9C,oCAAoC;QACpC,uCAAuC;QACvC,8FAA8F;QAE9F,0CAA0C;QAC1C,mEAAmE;QACnE,MAAM,aAAa,GACjB,oJAAoJ,CAAC;QAEvJ,IAAI,KAAK,CAAC;QACV,OAAO,CAAC,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;YACvF,MAAM,GAAG,GAAG,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;YACrD,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;YAC3E,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;YAE7E,+CAA+C;YAC/C,IAAI,GAAG,IAAI,KAAK,IAAI,OAAO,EAAE,CAAC;gBAC5B,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;YACxC,CAAC;QACH,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;OAEG;IACK,aAAa,CAAC,IAAY;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7C,CAAC;IAED;;OAEG;IACK,kBAAkB,CAAC,IAAY;QACrC,MAAM,QAAQ,GAA2B;YACvC,OAAO,EAAE,GAAG;YACZ,MAAM,EAAE,GAAG;YACX,MAAM,EAAE,GAAG;YACX,QAAQ,EAAE,GAAG;YACb,OAAO,EAAE,GAAG;YACZ,QAAQ,EAAE,GAAG;SACd,CAAC;QAEF,IAAI,MAAM,GAAG,IAAI,CAAC;QAClB,KAAK,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtD,yGAAyG;YACzG,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;QACzD,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA9GD,sCA8GC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image utilities for converting file paths to base64 data URIs
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Read an image file and convert it to a base64 data URI
|
|
6
|
+
*
|
|
7
|
+
* @param filePath - Path to the image file
|
|
8
|
+
* @returns Base64 data URI string (e.g., "data:image/jpeg;base64,...")
|
|
9
|
+
*/
|
|
10
|
+
export declare function imageToDataUri(filePath: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Create a message content item for an image
|
|
13
|
+
*
|
|
14
|
+
* @param filePath - Path to the image file
|
|
15
|
+
* @returns ContentItem for the image
|
|
16
|
+
*/
|
|
17
|
+
export declare function imageContent(filePath: string): {
|
|
18
|
+
type: "image_url";
|
|
19
|
+
image_url: {
|
|
20
|
+
url: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Create a message content item for text
|
|
25
|
+
*/
|
|
26
|
+
export declare function textContent(text: string): {
|
|
27
|
+
type: "text";
|
|
28
|
+
text: string;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../../src/llm/utils/image.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAUvD;AAoBD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM;;;;;EAO5C;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM;;;EAKvC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Image utilities for converting file paths to base64 data URIs
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.imageToDataUri = imageToDataUri;
|
|
7
|
+
exports.imageContent = imageContent;
|
|
8
|
+
exports.textContent = textContent;
|
|
9
|
+
const node_fs_1 = require("node:fs");
|
|
10
|
+
const node_path_1 = require("node:path");
|
|
11
|
+
/**
|
|
12
|
+
* Read an image file and convert it to a base64 data URI
|
|
13
|
+
*
|
|
14
|
+
* @param filePath - Path to the image file
|
|
15
|
+
* @returns Base64 data URI string (e.g., "data:image/jpeg;base64,...")
|
|
16
|
+
*/
|
|
17
|
+
function imageToDataUri(filePath) {
|
|
18
|
+
// eslint-disable-next-line security/detect-non-literal-fs-filename -- User-provided image paths required for multimodal LLM input
|
|
19
|
+
const imageBuffer = (0, node_fs_1.readFileSync)(filePath);
|
|
20
|
+
const base64 = imageBuffer.toString('base64');
|
|
21
|
+
// Determine MIME type from file extension
|
|
22
|
+
const ext = (0, node_path_1.extname)(filePath).toLowerCase();
|
|
23
|
+
const mimeType = getMimeType(ext);
|
|
24
|
+
return `data:${mimeType};base64,${base64}`;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get MIME type from file extension
|
|
28
|
+
*/
|
|
29
|
+
function getMimeType(ext) {
|
|
30
|
+
const mimeTypes = {
|
|
31
|
+
'.jpg': 'image/jpeg',
|
|
32
|
+
'.jpeg': 'image/jpeg',
|
|
33
|
+
'.png': 'image/png',
|
|
34
|
+
'.gif': 'image/gif',
|
|
35
|
+
'.webp': 'image/webp',
|
|
36
|
+
'.bmp': 'image/bmp',
|
|
37
|
+
'.svg': 'image/svg+xml',
|
|
38
|
+
};
|
|
39
|
+
// eslint-disable-next-line security/detect-object-injection -- Safe dictionary lookup with known keys and fallback
|
|
40
|
+
return mimeTypes[ext] || 'image/jpeg';
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Create a message content item for an image
|
|
44
|
+
*
|
|
45
|
+
* @param filePath - Path to the image file
|
|
46
|
+
* @returns ContentItem for the image
|
|
47
|
+
*/
|
|
48
|
+
function imageContent(filePath) {
|
|
49
|
+
return {
|
|
50
|
+
type: 'image_url',
|
|
51
|
+
image_url: {
|
|
52
|
+
url: imageToDataUri(filePath),
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Create a message content item for text
|
|
58
|
+
*/
|
|
59
|
+
function textContent(text) {
|
|
60
|
+
return {
|
|
61
|
+
type: 'text',
|
|
62
|
+
text,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.js","sourceRoot":"","sources":["../../../src/llm/utils/image.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAWH,wCAUC;AA0BD,oCAOC;AAKD,kCAKC;AA9DD,qCAAuC;AACvC,yCAAoC;AAEpC;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,QAAgB;IAC7C,kIAAkI;IAClI,MAAM,WAAW,GAAG,IAAA,sBAAY,EAAC,QAAQ,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAG,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAE9C,0CAA0C;IAC1C,MAAM,GAAG,GAAG,IAAA,mBAAO,EAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;IAC5C,MAAM,QAAQ,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;IAElC,OAAO,QAAQ,QAAQ,WAAW,MAAM,EAAE,CAAC;AAC7C,CAAC;AAED;;GAEG;AACH,SAAS,WAAW,CAAC,GAAW;IAC9B,MAAM,SAAS,GAA2B;QACxC,MAAM,EAAE,YAAY;QACpB,OAAO,EAAE,YAAY;QACrB,MAAM,EAAE,WAAW;QACnB,MAAM,EAAE,WAAW;QACnB,OAAO,EAAE,YAAY;QACrB,MAAM,EAAE,WAAW;QACnB,MAAM,EAAE,eAAe;KACxB,CAAC;IAEF,mHAAmH;IACnH,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC;AACxC,CAAC;AAED;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,QAAgB;IAC3C,OAAO;QACL,IAAI,EAAE,WAAoB;QAC1B,SAAS,EAAE;YACT,GAAG,EAAE,cAAc,CAAC,QAAQ,CAAC;SAC9B;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,WAAW,CAAC,IAAY;IACtC,OAAO;QACL,IAAI,EAAE,MAAe;QACrB,IAAI;KACL,CAAC;AACJ,CAAC"}
|