@ellyco/agentic 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +560 -0
  3. package/dist/graphs/graph.d.ts +218 -0
  4. package/dist/graphs/graph.d.ts.map +1 -0
  5. package/dist/graphs/graph.js +334 -0
  6. package/dist/graphs/graph.js.map +1 -0
  7. package/dist/graphs/index.d.ts +7 -0
  8. package/dist/graphs/index.d.ts.map +1 -0
  9. package/dist/graphs/index.js +15 -0
  10. package/dist/graphs/index.js.map +1 -0
  11. package/dist/graphs/iterator.d.ts +138 -0
  12. package/dist/graphs/iterator.d.ts.map +1 -0
  13. package/dist/graphs/iterator.js +184 -0
  14. package/dist/graphs/iterator.js.map +1 -0
  15. package/dist/graphs/merge-state.d.ts +22 -0
  16. package/dist/graphs/merge-state.d.ts.map +1 -0
  17. package/dist/graphs/merge-state.js +56 -0
  18. package/dist/graphs/merge-state.js.map +1 -0
  19. package/dist/graphs/node-sequence.d.ts +63 -0
  20. package/dist/graphs/node-sequence.d.ts.map +1 -0
  21. package/dist/graphs/node-sequence.js +84 -0
  22. package/dist/graphs/node-sequence.js.map +1 -0
  23. package/dist/graphs/registry.d.ts +5 -0
  24. package/dist/graphs/registry.d.ts.map +1 -0
  25. package/dist/graphs/registry.js +6 -0
  26. package/dist/graphs/registry.js.map +1 -0
  27. package/dist/graphs/runtime-context.d.ts +189 -0
  28. package/dist/graphs/runtime-context.d.ts.map +1 -0
  29. package/dist/graphs/runtime-context.js +254 -0
  30. package/dist/graphs/runtime-context.js.map +1 -0
  31. package/dist/graphs/state-machine.d.ts +105 -0
  32. package/dist/graphs/state-machine.d.ts.map +1 -0
  33. package/dist/graphs/state-machine.js +130 -0
  34. package/dist/graphs/state-machine.js.map +1 -0
  35. package/dist/graphs/store/base-store.d.ts +90 -0
  36. package/dist/graphs/store/base-store.d.ts.map +1 -0
  37. package/dist/graphs/store/base-store.js +50 -0
  38. package/dist/graphs/store/base-store.js.map +1 -0
  39. package/dist/graphs/store/sqlite-store.d.ts +88 -0
  40. package/dist/graphs/store/sqlite-store.d.ts.map +1 -0
  41. package/dist/graphs/store/sqlite-store.js +109 -0
  42. package/dist/graphs/store/sqlite-store.js.map +1 -0
  43. package/dist/graphs/store/stored-run.d.ts +77 -0
  44. package/dist/graphs/store/stored-run.d.ts.map +1 -0
  45. package/dist/graphs/store/stored-run.js +88 -0
  46. package/dist/graphs/store/stored-run.js.map +1 -0
  47. package/dist/graphs/types.d.ts +15 -0
  48. package/dist/graphs/types.d.ts.map +1 -0
  49. package/dist/graphs/types.js +3 -0
  50. package/dist/graphs/types.js.map +1 -0
  51. package/dist/messages/index.d.ts +6 -0
  52. package/dist/messages/index.d.ts.map +1 -0
  53. package/dist/messages/index.js +19 -0
  54. package/dist/messages/index.js.map +1 -0
  55. package/dist/messages/message.d.ts +143 -0
  56. package/dist/messages/message.d.ts.map +1 -0
  57. package/dist/messages/message.js +172 -0
  58. package/dist/messages/message.js.map +1 -0
  59. package/dist/messages/tool.d.ts +160 -0
  60. package/dist/messages/tool.d.ts.map +1 -0
  61. package/dist/messages/tool.js +173 -0
  62. package/dist/messages/tool.js.map +1 -0
  63. package/dist/models/BaseModel.d.ts +232 -0
  64. package/dist/models/BaseModel.d.ts.map +1 -0
  65. package/dist/models/BaseModel.js +247 -0
  66. package/dist/models/BaseModel.js.map +1 -0
  67. package/dist/models/BedrockModel.d.ts +112 -0
  68. package/dist/models/BedrockModel.d.ts.map +1 -0
  69. package/dist/models/BedrockModel.js +315 -0
  70. package/dist/models/BedrockModel.js.map +1 -0
  71. package/dist/models/TestModel.d.ts +135 -0
  72. package/dist/models/TestModel.d.ts.map +1 -0
  73. package/dist/models/TestModel.js +191 -0
  74. package/dist/models/TestModel.js.map +1 -0
  75. package/dist/nodes/function-node.d.ts +59 -0
  76. package/dist/nodes/function-node.d.ts.map +1 -0
  77. package/dist/nodes/function-node.js +72 -0
  78. package/dist/nodes/function-node.js.map +1 -0
  79. package/dist/nodes/index.d.ts +4 -0
  80. package/dist/nodes/index.d.ts.map +1 -0
  81. package/dist/nodes/index.js +9 -0
  82. package/dist/nodes/index.js.map +1 -0
  83. package/dist/nodes/interrupt-node.d.ts +51 -0
  84. package/dist/nodes/interrupt-node.d.ts.map +1 -0
  85. package/dist/nodes/interrupt-node.js +65 -0
  86. package/dist/nodes/interrupt-node.js.map +1 -0
  87. package/dist/nodes/model-node.d.ts +72 -0
  88. package/dist/nodes/model-node.d.ts.map +1 -0
  89. package/dist/nodes/model-node.js +80 -0
  90. package/dist/nodes/model-node.js.map +1 -0
  91. package/dist/nodes/types.d.ts +5 -0
  92. package/dist/nodes/types.d.ts.map +1 -0
  93. package/dist/nodes/types.js +3 -0
  94. package/dist/nodes/types.js.map +1 -0
  95. package/dist/tools.d.ts +65 -0
  96. package/dist/tools.d.ts.map +1 -0
  97. package/dist/tools.js +56 -0
  98. package/dist/tools.js.map +1 -0
  99. package/dist/types.d.ts +17 -0
  100. package/dist/types.d.ts.map +1 -0
  101. package/dist/types.js +3 -0
  102. package/dist/types.js.map +1 -0
  103. package/package.json +32 -0
@@ -0,0 +1,143 @@
1
+ /**
2
+ * Object representation of message content with optional text field.
3
+ *
4
+ * @property {string} [text] - The text content of the message
5
+ */
6
+ export interface MessageContentObject {
7
+ text?: string;
8
+ }
9
+ /**
10
+ * Message content can be either a plain string or a structured content object.
11
+ */
12
+ export type MessageContent = string | MessageContentObject;
13
+ /**
14
+ * Enum representing the role of a message in the conversation.
15
+ *
16
+ * @enum {string}
17
+ * @property {string} SYSTEM - System message for setting context/behavior
18
+ * @property {string} USER - User message requesting something
19
+ * @property {string} AGENT - Agent/AI message responding or taking action
20
+ */
21
+ export declare enum MessageRole {
22
+ SYSTEM = "system",
23
+ USER = "user",
24
+ AGENT = "agent"
25
+ }
26
+ /**
27
+ * Base class for all message types in a conversation.
28
+ * Handles message content parsing, interpolation, and serialization.
29
+ *
30
+ * @abstract
31
+ * @property {MessageRole} role - The role of this message
32
+ * @property {string | undefined} text - The text content of the message
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const message = new UserMessage("Hello, can you help me?");
37
+ * const systemMsg = new SystemMessage("You are a helpful assistant.");
38
+ * ```
39
+ */
40
+ export declare abstract class BaseMessage {
41
+ readonly role: MessageRole;
42
+ private _textContent?;
43
+ /**
44
+ * Gets the text content of the message.
45
+ *
46
+ * @returns {string | undefined} The message text, or undefined if not set
47
+ */
48
+ get text(): string | undefined;
49
+ /**
50
+ * Creates a new message instance.
51
+ *
52
+ * @param {MessageRole} role - The role of this message
53
+ * @param {MessageContent} content - The message content (string or object)
54
+ */
55
+ constructor(role: MessageRole, content: MessageContent);
56
+ /**
57
+ * Interpolates template variables in the message text.
58
+ * Replaces {variableName} patterns with values from the properties object.
59
+ *
60
+ * @param {Record<string, any>} properties - Key-value pairs for template substitution
61
+ * @returns {this} The same message instance for chaining
62
+ * @throws {Error} If a referenced property is not found in the properties object
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const msg = new UserMessage("Hello {name}, your score is {score}");
67
+ * msg.interpolate({ name: "Alice", score: 100 });
68
+ * // Result: "Hello Alice, your score is 100"
69
+ * ```
70
+ */
71
+ interpolate(properties: Record<string, any>): this;
72
+ /**
73
+ * Converts the message to JSON representation.
74
+ *
75
+ * @returns {{role: MessageRole; content: MessageContentObject}} JSON representation of the message
76
+ */
77
+ toJSON(): {
78
+ role: MessageRole;
79
+ content: MessageContentObject;
80
+ };
81
+ /**
82
+ * Checks if the message contains text content.
83
+ *
84
+ * @returns {boolean} True if the message has text content, false otherwise
85
+ */
86
+ hasText(): boolean;
87
+ }
88
+ /**
89
+ * A system message used to set the behavior and context for the AI model.
90
+ * System messages typically appear at the beginning of a conversation.
91
+ *
92
+ * @extends {BaseMessage}
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * const systemMsg = new SystemMessage("You are a helpful customer service assistant.");
97
+ * ```
98
+ */
99
+ export declare class SystemMessage extends BaseMessage {
100
+ /**
101
+ * Creates a new system message.
102
+ *
103
+ * @param {MessageContent} content - The system message content
104
+ */
105
+ constructor(content: MessageContent);
106
+ }
107
+ /**
108
+ * A user message representing input or requests from the user.
109
+ *
110
+ * @extends {BaseMessage}
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * const userMsg = new UserMessage("What is the weather today?");
115
+ * ```
116
+ */
117
+ export declare class UserMessage extends BaseMessage {
118
+ /**
119
+ * Creates a new user message.
120
+ *
121
+ * @param {MessageContent} content - The user message content
122
+ */
123
+ constructor(content: MessageContent);
124
+ }
125
+ /**
126
+ * An agent message representing responses or actions from the AI agent.
127
+ *
128
+ * @extends {BaseMessage}
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * const agentMsg = new AgentMessage("The weather is sunny with a high of 75°F.");
133
+ * ```
134
+ */
135
+ export declare class AgentMessage extends BaseMessage {
136
+ /**
137
+ * Creates a new agent message.
138
+ *
139
+ * @param {MessageContent} content - The agent message content
140
+ */
141
+ constructor(content: MessageContent);
142
+ }
143
+ //# sourceMappingURL=message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/messages/message.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,oBAAoB,CAAC;AAE3D;;;;;;;GAOG;AACH,oBAAY,WAAW;IACnB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,KAAK,UAAU;CAClB;AAED;;;;;;;;;;;;;GAaG;AACH,8BAAsB,WAAW;aAmBT,IAAI,EAAE,WAAW;IAlBrC,OAAO,CAAC,YAAY,CAAC,CAAS;IAE9B;;;;OAIG;IACH,IAAW,IAAI,IAAI,MAAM,GAAG,SAAS,CAEpC;IAED;;;;;OAKG;gBAEiB,IAAI,EAAE,WAAW,EACjC,OAAO,EAAE,cAAc;IAS3B;;;;;;;;;;;;;;OAcG;IACI,WAAW,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAgBzD;;;;OAIG;IACI,MAAM,IAAI;QAAE,IAAI,EAAE,WAAW,CAAC;QAAC,OAAO,EAAE,oBAAoB,CAAA;KAAE;IASrE;;;;OAIG;IACI,OAAO,IAAI,OAAO;CAG5B;AAED;;;;;;;;;;GAUG;AACH,qBAAa,aAAc,SAAQ,WAAW;IAC1C;;;;OAIG;gBACS,OAAO,EAAE,cAAc;CAGtC;AAED;;;;;;;;;GASG;AACH,qBAAa,WAAY,SAAQ,WAAW;IACxC;;;;OAIG;gBACS,OAAO,EAAE,cAAc;CAGtC;AAED;;;;;;;;;GASG;AACH,qBAAa,YAAa,SAAQ,WAAW;IACzC;;;;OAIG;gBACS,OAAO,EAAE,cAAc;CAGtC"}
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AgentMessage = exports.UserMessage = exports.SystemMessage = exports.BaseMessage = exports.MessageRole = void 0;
4
+ /**
5
+ * Enum representing the role of a message in the conversation.
6
+ *
7
+ * @enum {string}
8
+ * @property {string} SYSTEM - System message for setting context/behavior
9
+ * @property {string} USER - User message requesting something
10
+ * @property {string} AGENT - Agent/AI message responding or taking action
11
+ */
12
+ var MessageRole;
13
+ (function (MessageRole) {
14
+ MessageRole["SYSTEM"] = "system";
15
+ MessageRole["USER"] = "user";
16
+ MessageRole["AGENT"] = "agent";
17
+ })(MessageRole || (exports.MessageRole = MessageRole = {}));
18
+ /**
19
+ * Base class for all message types in a conversation.
20
+ * Handles message content parsing, interpolation, and serialization.
21
+ *
22
+ * @abstract
23
+ * @property {MessageRole} role - The role of this message
24
+ * @property {string | undefined} text - The text content of the message
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const message = new UserMessage("Hello, can you help me?");
29
+ * const systemMsg = new SystemMessage("You are a helpful assistant.");
30
+ * ```
31
+ */
32
+ class BaseMessage {
33
+ role;
34
+ _textContent;
35
+ /**
36
+ * Gets the text content of the message.
37
+ *
38
+ * @returns {string | undefined} The message text, or undefined if not set
39
+ */
40
+ get text() {
41
+ return this._textContent;
42
+ }
43
+ /**
44
+ * Creates a new message instance.
45
+ *
46
+ * @param {MessageRole} role - The role of this message
47
+ * @param {MessageContent} content - The message content (string or object)
48
+ */
49
+ constructor(role, content) {
50
+ this.role = role;
51
+ if (typeof content === "string") {
52
+ this._textContent = content;
53
+ }
54
+ else {
55
+ this._textContent = content.text;
56
+ }
57
+ }
58
+ /**
59
+ * Interpolates template variables in the message text.
60
+ * Replaces {variableName} patterns with values from the properties object.
61
+ *
62
+ * @param {Record<string, any>} properties - Key-value pairs for template substitution
63
+ * @returns {this} The same message instance for chaining
64
+ * @throws {Error} If a referenced property is not found in the properties object
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * const msg = new UserMessage("Hello {name}, your score is {score}");
69
+ * msg.interpolate({ name: "Alice", score: 100 });
70
+ * // Result: "Hello Alice, your score is 100"
71
+ * ```
72
+ */
73
+ interpolate(properties) {
74
+ if (this._textContent) {
75
+ this._textContent = this._textContent.replace(/\{\s*(\w+)\s*\}/g, (match, p1) => {
76
+ const value = properties[p1];
77
+ if (value === undefined) {
78
+ throw new Error(`Property ${p1} is not defined`);
79
+ }
80
+ return value;
81
+ });
82
+ }
83
+ return this;
84
+ }
85
+ /**
86
+ * Converts the message to JSON representation.
87
+ *
88
+ * @returns {{role: MessageRole; content: MessageContentObject}} JSON representation of the message
89
+ */
90
+ toJSON() {
91
+ return {
92
+ role: this.role,
93
+ content: {
94
+ text: this._textContent,
95
+ },
96
+ };
97
+ }
98
+ /**
99
+ * Checks if the message contains text content.
100
+ *
101
+ * @returns {boolean} True if the message has text content, false otherwise
102
+ */
103
+ hasText() {
104
+ return this._textContent !== undefined;
105
+ }
106
+ }
107
+ exports.BaseMessage = BaseMessage;
108
+ /**
109
+ * A system message used to set the behavior and context for the AI model.
110
+ * System messages typically appear at the beginning of a conversation.
111
+ *
112
+ * @extends {BaseMessage}
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * const systemMsg = new SystemMessage("You are a helpful customer service assistant.");
117
+ * ```
118
+ */
119
+ class SystemMessage extends BaseMessage {
120
+ /**
121
+ * Creates a new system message.
122
+ *
123
+ * @param {MessageContent} content - The system message content
124
+ */
125
+ constructor(content) {
126
+ super(MessageRole.SYSTEM, content);
127
+ }
128
+ }
129
+ exports.SystemMessage = SystemMessage;
130
+ /**
131
+ * A user message representing input or requests from the user.
132
+ *
133
+ * @extends {BaseMessage}
134
+ *
135
+ * @example
136
+ * ```typescript
137
+ * const userMsg = new UserMessage("What is the weather today?");
138
+ * ```
139
+ */
140
+ class UserMessage extends BaseMessage {
141
+ /**
142
+ * Creates a new user message.
143
+ *
144
+ * @param {MessageContent} content - The user message content
145
+ */
146
+ constructor(content) {
147
+ super(MessageRole.USER, content);
148
+ }
149
+ }
150
+ exports.UserMessage = UserMessage;
151
+ /**
152
+ * An agent message representing responses or actions from the AI agent.
153
+ *
154
+ * @extends {BaseMessage}
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * const agentMsg = new AgentMessage("The weather is sunny with a high of 75°F.");
159
+ * ```
160
+ */
161
+ class AgentMessage extends BaseMessage {
162
+ /**
163
+ * Creates a new agent message.
164
+ *
165
+ * @param {MessageContent} content - The agent message content
166
+ */
167
+ constructor(content) {
168
+ super(MessageRole.AGENT, content);
169
+ }
170
+ }
171
+ exports.AgentMessage = AgentMessage;
172
+ //# sourceMappingURL=message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message.js","sourceRoot":"","sources":["../../src/messages/message.ts"],"names":[],"mappings":";;;AAcA;;;;;;;GAOG;AACH,IAAY,WAIX;AAJD,WAAY,WAAW;IACnB,gCAAiB,CAAA;IACjB,4BAAa,CAAA;IACb,8BAAe,CAAA;AACnB,CAAC,EAJW,WAAW,2BAAX,WAAW,QAItB;AAED;;;;;;;;;;;;;GAaG;AACH,MAAsB,WAAW;IAmBT;IAlBZ,YAAY,CAAU;IAE9B;;;;OAIG;IACH,IAAW,IAAI;QACX,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IAED;;;;;OAKG;IACH,YACoB,IAAiB,EACjC,OAAuB;QADP,SAAI,GAAJ,IAAI,CAAa;QAGjC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAC9B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC;QAChC,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;QACrC,CAAC;IACL,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACI,WAAW,CAAC,UAA+B;QAC9C,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACpB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CACzC,kBAAkB,EAClB,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;gBACV,MAAM,KAAK,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC;gBAC7B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;oBACtB,MAAM,IAAI,KAAK,CAAC,YAAY,EAAE,iBAAiB,CAAC,CAAC;gBACrD,CAAC;gBACD,OAAO,KAAK,CAAC;YACjB,CAAC,CACJ,CAAC;QACN,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACI,MAAM;QACT,OAAO;YACH,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE;gBACL,IAAI,EAAE,IAAI,CAAC,YAAY;aAC1B;SACJ,CAAC;IACN,CAAC;IAED;;;;OAIG;IACI,OAAO;QACV,OAAO,IAAI,CAAC,YAAY,KAAK,SAAS,CAAC;IAC3C,CAAC;CACJ;AAlFD,kCAkFC;AAED;;;;;;;;;;GAUG;AACH,MAAa,aAAc,SAAQ,WAAW;IAC1C;;;;OAIG;IACH,YAAY,OAAuB;QAC/B,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;CACJ;AATD,sCASC;AAED;;;;;;;;;GASG;AACH,MAAa,WAAY,SAAQ,WAAW;IACxC;;;;OAIG;IACH,YAAY,OAAuB;QAC/B,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACrC,CAAC;CACJ;AATD,kCASC;AAED;;;;;;;;;GASG;AACH,MAAa,YAAa,SAAQ,WAAW;IACzC;;;;OAIG;IACH,YAAY,OAAuB;QAC/B,KAAK,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;CACJ;AATD,oCASC"}
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Internal interface for serializing tool-related messages to JSON.
3
+ *
4
+ * @interface ToolUseJSON
5
+ * @property {string} type - The type of tool message: "tool_request", "tool_response", or "tool_error"
6
+ * @property {string} toolUseId - Unique identifier linking request to response/error
7
+ * @property {string} toolName - Name of the tool being used
8
+ * @property {string} [input] - JSON-stringified input parameters for the tool
9
+ * @property {string} [output] - JSON-stringified output/result from the tool
10
+ * @property {string} [error] - Error message if the tool execution failed
11
+ */
12
+ interface ToolUseJSON {
13
+ type: "tool_request" | "tool_response" | "tool_error";
14
+ toolUseId: string;
15
+ toolName: string;
16
+ input?: string;
17
+ output?: string;
18
+ error?: string;
19
+ }
20
+ /**
21
+ * Base class for tool-related messages representing tool usage in agent-model interactions.
22
+ * Covers tool requests, responses, and errors.
23
+ *
24
+ * @abstract
25
+ * @property {string} toolUseId - Unique identifier for this tool usage instance
26
+ * @property {string} toolName - Name of the tool
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * // ToolRequest: Agent requests to use a tool
31
+ * const request = new ToolRequest("call_123", "search", { query: "weather" });
32
+ *
33
+ * // ToolResponse: Tool returns a result
34
+ * const response = new ToolResponse("call_123", "search", { result: "Sunny" });
35
+ *
36
+ * // ToolError: Tool execution failed
37
+ * const error = new ToolError("call_123", "search", "API connection failed");
38
+ * ```
39
+ */
40
+ export declare abstract class ToolUse {
41
+ readonly toolUseId: string;
42
+ readonly toolName: string;
43
+ /**
44
+ * Creates a new tool usage instance.
45
+ *
46
+ * @param {string} toolUseId - Unique identifier for this tool usage
47
+ * @param {string} toolName - Name of the tool being used
48
+ */
49
+ constructor(toolUseId: string, toolName: string);
50
+ /**
51
+ * Converts the tool usage to JSON representation.
52
+ *
53
+ * @abstract
54
+ * @returns {ToolUseJSON} JSON representation of the tool usage
55
+ */
56
+ abstract toJSON(): ToolUseJSON;
57
+ }
58
+ /**
59
+ * Represents a request from the agent to execute a tool.
60
+ * Contains the tool name and input parameters for execution.
61
+ *
62
+ * @extends {ToolUse}
63
+ * @template T - The type of the input parameters object
64
+ * @property {T} input - The input parameters for the tool
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * const request = new ToolRequest(
69
+ * "call_123",
70
+ * "search",
71
+ * { query: "Paris weather" }
72
+ * );
73
+ * ```
74
+ */
75
+ export declare class ToolRequest<T = object> extends ToolUse {
76
+ readonly input: T;
77
+ /**
78
+ * Creates a new tool request.
79
+ *
80
+ * @param {string} toolUseId - Unique identifier for this request
81
+ * @param {string} toolName - Name of the tool to invoke
82
+ * @param {T} input - Parameters to pass to the tool
83
+ */
84
+ constructor(toolUseId: string, toolName: string, input: T);
85
+ /**
86
+ * Converts the tool request to JSON representation.
87
+ *
88
+ * @returns {ToolUseJSON} JSON representation with type "tool_request"
89
+ */
90
+ toJSON(): ToolUseJSON;
91
+ }
92
+ /**
93
+ * Represents the successful result of a tool execution.
94
+ * Contains the output/result returned by the tool.
95
+ *
96
+ * @extends {ToolUse}
97
+ * @template T - The type of the output/result object
98
+ * @property {T} output - The result returned by the tool
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * const response = new ToolResponse(
103
+ * "call_123",
104
+ * "search",
105
+ * { results: ["result1", "result2"], totalCount: 2 }
106
+ * );
107
+ * ```
108
+ */
109
+ export declare class ToolResponse<T = object> extends ToolUse {
110
+ readonly output: T;
111
+ /**
112
+ * Creates a new tool response.
113
+ *
114
+ * @param {string} toolUseId - Unique identifier matching the original request
115
+ * @param {string} toolName - Name of the tool that was executed
116
+ * @param {T} output - The result returned by the tool
117
+ */
118
+ constructor(toolUseId: string, toolName: string, output: T);
119
+ /**
120
+ * Converts the tool response to JSON representation.
121
+ *
122
+ * @returns {ToolUseJSON} JSON representation with type "tool_response"
123
+ */
124
+ toJSON(): ToolUseJSON;
125
+ }
126
+ /**
127
+ * Represents an error that occurred during tool execution.
128
+ * Contains the error message describing what went wrong.
129
+ *
130
+ * @extends {ToolUse}
131
+ * @property {string} error - The error message
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * const error = new ToolError(
136
+ * "call_123",
137
+ * "search",
138
+ * "Network timeout: Request took longer than 30 seconds"
139
+ * );
140
+ * ```
141
+ */
142
+ export declare class ToolError extends ToolUse {
143
+ readonly error: string;
144
+ /**
145
+ * Creates a new tool error.
146
+ *
147
+ * @param {string} toolUseId - Unique identifier matching the original request
148
+ * @param {string} toolName - Name of the tool that failed
149
+ * @param {string} error - Description of the error that occurred
150
+ */
151
+ constructor(toolUseId: string, toolName: string, error: string);
152
+ /**
153
+ * Converts the tool error to JSON representation.
154
+ *
155
+ * @returns {ToolUseJSON} JSON representation with type "tool_error"
156
+ */
157
+ toJSON(): ToolUseJSON;
158
+ }
159
+ export {};
160
+ //# sourceMappingURL=tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/messages/tool.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,UAAU,WAAW;IACjB,IAAI,EAAE,cAAc,GAAG,eAAe,GAAG,YAAY,CAAC;IACtD,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,8BAAsB,OAAO;aAQL,SAAS,EAAE,MAAM;aACjB,QAAQ,EAAE,MAAM;IARpC;;;;;OAKG;gBAEiB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM;IAGpC;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,IAAI,WAAW;CACjC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,WAAW,CAAC,CAAC,GAAG,MAAM,CAAE,SAAQ,OAAO;aAW5B,KAAK,EAAE,CAAC;IAV5B;;;;;;OAMG;gBAEC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EACA,KAAK,EAAE,CAAC;IAK5B;;;;OAIG;IACH,MAAM,IAAI,WAAW;CAQxB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,YAAY,CAAC,CAAC,GAAG,MAAM,CAAE,SAAQ,OAAO;aAW7B,MAAM,EAAE,CAAC;IAV7B;;;;;;OAMG;gBAEC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EACA,MAAM,EAAE,CAAC;IAK7B;;;;OAIG;IACH,MAAM,IAAI,WAAW;CAQxB;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,SAAU,SAAQ,OAAO;aAWd,KAAK,EAAE,MAAM;IAVjC;;;;;;OAMG;gBAEC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EACA,KAAK,EAAE,MAAM;IAKjC;;;;OAIG;IACH,MAAM,IAAI,WAAW;CAQxB"}
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ToolError = exports.ToolResponse = exports.ToolRequest = exports.ToolUse = void 0;
4
+ /**
5
+ * Base class for tool-related messages representing tool usage in agent-model interactions.
6
+ * Covers tool requests, responses, and errors.
7
+ *
8
+ * @abstract
9
+ * @property {string} toolUseId - Unique identifier for this tool usage instance
10
+ * @property {string} toolName - Name of the tool
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * // ToolRequest: Agent requests to use a tool
15
+ * const request = new ToolRequest("call_123", "search", { query: "weather" });
16
+ *
17
+ * // ToolResponse: Tool returns a result
18
+ * const response = new ToolResponse("call_123", "search", { result: "Sunny" });
19
+ *
20
+ * // ToolError: Tool execution failed
21
+ * const error = new ToolError("call_123", "search", "API connection failed");
22
+ * ```
23
+ */
24
+ class ToolUse {
25
+ toolUseId;
26
+ toolName;
27
+ /**
28
+ * Creates a new tool usage instance.
29
+ *
30
+ * @param {string} toolUseId - Unique identifier for this tool usage
31
+ * @param {string} toolName - Name of the tool being used
32
+ */
33
+ constructor(toolUseId, toolName) {
34
+ this.toolUseId = toolUseId;
35
+ this.toolName = toolName;
36
+ }
37
+ }
38
+ exports.ToolUse = ToolUse;
39
+ /**
40
+ * Represents a request from the agent to execute a tool.
41
+ * Contains the tool name and input parameters for execution.
42
+ *
43
+ * @extends {ToolUse}
44
+ * @template T - The type of the input parameters object
45
+ * @property {T} input - The input parameters for the tool
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const request = new ToolRequest(
50
+ * "call_123",
51
+ * "search",
52
+ * { query: "Paris weather" }
53
+ * );
54
+ * ```
55
+ */
56
+ class ToolRequest extends ToolUse {
57
+ input;
58
+ /**
59
+ * Creates a new tool request.
60
+ *
61
+ * @param {string} toolUseId - Unique identifier for this request
62
+ * @param {string} toolName - Name of the tool to invoke
63
+ * @param {T} input - Parameters to pass to the tool
64
+ */
65
+ constructor(toolUseId, toolName, input) {
66
+ super(toolUseId, toolName);
67
+ this.input = input;
68
+ }
69
+ /**
70
+ * Converts the tool request to JSON representation.
71
+ *
72
+ * @returns {ToolUseJSON} JSON representation with type "tool_request"
73
+ */
74
+ toJSON() {
75
+ return {
76
+ type: "tool_request",
77
+ toolUseId: this.toolUseId,
78
+ toolName: this.toolName,
79
+ input: JSON.stringify(this.input),
80
+ };
81
+ }
82
+ }
83
+ exports.ToolRequest = ToolRequest;
84
+ /**
85
+ * Represents the successful result of a tool execution.
86
+ * Contains the output/result returned by the tool.
87
+ *
88
+ * @extends {ToolUse}
89
+ * @template T - The type of the output/result object
90
+ * @property {T} output - The result returned by the tool
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * const response = new ToolResponse(
95
+ * "call_123",
96
+ * "search",
97
+ * { results: ["result1", "result2"], totalCount: 2 }
98
+ * );
99
+ * ```
100
+ */
101
+ class ToolResponse extends ToolUse {
102
+ output;
103
+ /**
104
+ * Creates a new tool response.
105
+ *
106
+ * @param {string} toolUseId - Unique identifier matching the original request
107
+ * @param {string} toolName - Name of the tool that was executed
108
+ * @param {T} output - The result returned by the tool
109
+ */
110
+ constructor(toolUseId, toolName, output) {
111
+ super(toolUseId, toolName);
112
+ this.output = output;
113
+ }
114
+ /**
115
+ * Converts the tool response to JSON representation.
116
+ *
117
+ * @returns {ToolUseJSON} JSON representation with type "tool_response"
118
+ */
119
+ toJSON() {
120
+ return {
121
+ type: "tool_response",
122
+ toolUseId: this.toolUseId,
123
+ toolName: this.toolName,
124
+ output: JSON.stringify(this.output),
125
+ };
126
+ }
127
+ }
128
+ exports.ToolResponse = ToolResponse;
129
+ /**
130
+ * Represents an error that occurred during tool execution.
131
+ * Contains the error message describing what went wrong.
132
+ *
133
+ * @extends {ToolUse}
134
+ * @property {string} error - The error message
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * const error = new ToolError(
139
+ * "call_123",
140
+ * "search",
141
+ * "Network timeout: Request took longer than 30 seconds"
142
+ * );
143
+ * ```
144
+ */
145
+ class ToolError extends ToolUse {
146
+ error;
147
+ /**
148
+ * Creates a new tool error.
149
+ *
150
+ * @param {string} toolUseId - Unique identifier matching the original request
151
+ * @param {string} toolName - Name of the tool that failed
152
+ * @param {string} error - Description of the error that occurred
153
+ */
154
+ constructor(toolUseId, toolName, error) {
155
+ super(toolUseId, toolName);
156
+ this.error = error;
157
+ }
158
+ /**
159
+ * Converts the tool error to JSON representation.
160
+ *
161
+ * @returns {ToolUseJSON} JSON representation with type "tool_error"
162
+ */
163
+ toJSON() {
164
+ return {
165
+ type: "tool_error",
166
+ toolUseId: this.toolUseId,
167
+ toolName: this.toolName,
168
+ error: this.error,
169
+ };
170
+ }
171
+ }
172
+ exports.ToolError = ToolError;
173
+ //# sourceMappingURL=tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.js","sourceRoot":"","sources":["../../src/messages/tool.ts"],"names":[],"mappings":";;;AAoBA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAsB,OAAO;IAQL;IACA;IARpB;;;;;OAKG;IACH,YACoB,SAAiB,EACjB,QAAgB;QADhB,cAAS,GAAT,SAAS,CAAQ;QACjB,aAAQ,GAAR,QAAQ,CAAQ;IAChC,CAAC;CASR;AAnBD,0BAmBC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,WAAwB,SAAQ,OAAO;IAW5B;IAVpB;;;;;;OAMG;IACH,YACI,SAAiB,EACjB,QAAgB,EACA,KAAQ;QAExB,KAAK,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAFX,UAAK,GAAL,KAAK,CAAG;IAG5B,CAAC;IAED;;;;OAIG;IACH,MAAM;QACF,OAAO;YACH,IAAI,EAAE,cAAc;YACpB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC;SACpC,CAAC;IACN,CAAC;CACJ;AA7BD,kCA6BC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,YAAyB,SAAQ,OAAO;IAW7B;IAVpB;;;;;;OAMG;IACH,YACI,SAAiB,EACjB,QAAgB,EACA,MAAS;QAEzB,KAAK,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAFX,WAAM,GAAN,MAAM,CAAG;IAG7B,CAAC;IAED;;;;OAIG;IACH,MAAM;QACF,OAAO;YACH,IAAI,EAAE,eAAe;YACrB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC;SACtC,CAAC;IACN,CAAC;CACJ;AA7BD,oCA6BC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAa,SAAU,SAAQ,OAAO;IAWd;IAVpB;;;;;;OAMG;IACH,YACI,SAAiB,EACjB,QAAgB,EACA,KAAa;QAE7B,KAAK,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAFX,UAAK,GAAL,KAAK,CAAQ;IAGjC,CAAC;IAED;;;;OAIG;IACH,MAAM;QACF,OAAO;YACH,IAAI,EAAE,YAAY;YAClB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,KAAK,EAAE,IAAI,CAAC,KAAK;SACpB,CAAC;IACN,CAAC;CACJ;AA7BD,8BA6BC"}