kernl 0.1.1

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 (257) hide show
  1. package/.turbo/turbo-build.log +5 -0
  2. package/CHANGELOG.md +53 -0
  3. package/LICENSE +201 -0
  4. package/dist/agent.d.ts +43 -0
  5. package/dist/agent.d.ts.map +1 -0
  6. package/dist/agent.js +130 -0
  7. package/dist/context.d.ts +70 -0
  8. package/dist/context.d.ts.map +1 -0
  9. package/dist/context.js +111 -0
  10. package/dist/env.d.ts +45 -0
  11. package/dist/env.d.ts.map +1 -0
  12. package/dist/env.js +31 -0
  13. package/dist/error.d.ts +1 -0
  14. package/dist/error.d.ts.map +1 -0
  15. package/dist/error.js +1 -0
  16. package/dist/guardrail.d.ts +178 -0
  17. package/dist/guardrail.d.ts.map +1 -0
  18. package/dist/guardrail.js +34 -0
  19. package/dist/index.d.ts +4 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +2 -0
  22. package/dist/kernel.d.ts +7 -0
  23. package/dist/kernel.d.ts.map +1 -0
  24. package/dist/kernel.js +7 -0
  25. package/dist/kernl.d.ts +18 -0
  26. package/dist/kernl.d.ts.map +1 -0
  27. package/dist/kernl.js +16 -0
  28. package/dist/lib/env.d.ts +43 -0
  29. package/dist/lib/env.d.ts.map +1 -0
  30. package/dist/lib/env.js +29 -0
  31. package/dist/lib/error.d.ts +88 -0
  32. package/dist/lib/error.d.ts.map +1 -0
  33. package/dist/lib/error.js +117 -0
  34. package/dist/lib/logger.d.ts +36 -0
  35. package/dist/lib/logger.d.ts.map +1 -0
  36. package/dist/lib/logger.js +43 -0
  37. package/dist/lib/serde/__tests__/codec.test.d.ts +2 -0
  38. package/dist/lib/serde/__tests__/codec.test.d.ts.map +1 -0
  39. package/dist/lib/serde/__tests__/codec.test.js +75 -0
  40. package/dist/lib/serde/codec.d.ts +12 -0
  41. package/dist/lib/serde/codec.d.ts.map +1 -0
  42. package/dist/lib/serde/codec.js +54 -0
  43. package/dist/lib/serde/json.d.ts +8 -0
  44. package/dist/lib/serde/json.d.ts.map +1 -0
  45. package/dist/lib/serde/json.js +13 -0
  46. package/dist/lib/serde/thread.d.ts +1 -0
  47. package/dist/lib/serde/thread.d.ts.map +1 -0
  48. package/dist/lib/serde/thread.js +172 -0
  49. package/dist/lib/serde/tool.d.ts +36 -0
  50. package/dist/lib/serde/tool.d.ts.map +1 -0
  51. package/dist/lib/serde/tool.js +1 -0
  52. package/dist/lib/utils.d.ts +19 -0
  53. package/dist/lib/utils.d.ts.map +1 -0
  54. package/dist/lib/utils.js +41 -0
  55. package/dist/lifecycle.d.ts +133 -0
  56. package/dist/lifecycle.d.ts.map +1 -0
  57. package/dist/lifecycle.js +29 -0
  58. package/dist/logger.d.ts +36 -0
  59. package/dist/logger.d.ts.map +1 -0
  60. package/dist/logger.js +43 -0
  61. package/dist/mcp/__tests__/base.test.d.ts +2 -0
  62. package/dist/mcp/__tests__/base.test.d.ts.map +1 -0
  63. package/dist/mcp/__tests__/base.test.js +268 -0
  64. package/dist/mcp/__tests__/fixtures/echo-server.d.ts +3 -0
  65. package/dist/mcp/__tests__/fixtures/echo-server.d.ts.map +1 -0
  66. package/dist/mcp/__tests__/fixtures/echo-server.js +92 -0
  67. package/dist/mcp/__tests__/fixtures/math-server.d.ts +3 -0
  68. package/dist/mcp/__tests__/fixtures/math-server.d.ts.map +1 -0
  69. package/dist/mcp/__tests__/fixtures/math-server.js +98 -0
  70. package/dist/mcp/__tests__/fixtures/server.d.ts +3 -0
  71. package/dist/mcp/__tests__/fixtures/server.d.ts.map +1 -0
  72. package/dist/mcp/__tests__/fixtures/server.js +162 -0
  73. package/dist/mcp/__tests__/fixtures/test-server.d.ts +3 -0
  74. package/dist/mcp/__tests__/fixtures/test-server.d.ts.map +1 -0
  75. package/dist/mcp/__tests__/fixtures/test-server.js +163 -0
  76. package/dist/mcp/__tests__/fixtures/utils.d.ts +17 -0
  77. package/dist/mcp/__tests__/fixtures/utils.d.ts.map +1 -0
  78. package/dist/mcp/__tests__/fixtures/utils.js +42 -0
  79. package/dist/mcp/__tests__/integration.test.d.ts +2 -0
  80. package/dist/mcp/__tests__/integration.test.d.ts.map +1 -0
  81. package/dist/mcp/__tests__/integration.test.js +360 -0
  82. package/dist/mcp/__tests__/stdio.test.d.ts +2 -0
  83. package/dist/mcp/__tests__/stdio.test.d.ts.map +1 -0
  84. package/dist/mcp/__tests__/stdio.test.js +180 -0
  85. package/dist/mcp/__tests__/test-utils.d.ts +17 -0
  86. package/dist/mcp/__tests__/test-utils.d.ts.map +1 -0
  87. package/dist/mcp/__tests__/test-utils.js +42 -0
  88. package/dist/mcp/__tests__/utils.test.d.ts +2 -0
  89. package/dist/mcp/__tests__/utils.test.d.ts.map +1 -0
  90. package/dist/mcp/__tests__/utils.test.js +300 -0
  91. package/dist/mcp/base.d.ts +88 -0
  92. package/dist/mcp/base.d.ts.map +1 -0
  93. package/dist/mcp/base.js +68 -0
  94. package/dist/mcp/http.d.ts +34 -0
  95. package/dist/mcp/http.d.ts.map +1 -0
  96. package/dist/mcp/http.js +100 -0
  97. package/dist/mcp/node.d.ts +60 -0
  98. package/dist/mcp/node.d.ts.map +1 -0
  99. package/dist/mcp/node.js +297 -0
  100. package/dist/mcp/sse.d.ts +34 -0
  101. package/dist/mcp/sse.d.ts.map +1 -0
  102. package/dist/mcp/sse.js +97 -0
  103. package/dist/mcp/stdio.d.ts +32 -0
  104. package/dist/mcp/stdio.d.ts.map +1 -0
  105. package/dist/mcp/stdio.js +96 -0
  106. package/dist/mcp/types.d.ts +172 -0
  107. package/dist/mcp/types.d.ts.map +1 -0
  108. package/dist/mcp/types.js +16 -0
  109. package/dist/mcp/utils.d.ts +23 -0
  110. package/dist/mcp/utils.d.ts.map +1 -0
  111. package/dist/mcp/utils.js +44 -0
  112. package/dist/model.d.ts +175 -0
  113. package/dist/model.d.ts.map +1 -0
  114. package/dist/model.js +1 -0
  115. package/dist/providers/ai.d.ts +1 -0
  116. package/dist/providers/ai.d.ts.map +1 -0
  117. package/dist/providers/ai.js +1 -0
  118. package/dist/providers/default.d.ts +16 -0
  119. package/dist/providers/default.d.ts.map +1 -0
  120. package/dist/providers/default.js +17 -0
  121. package/dist/providers/registry.d.ts +1 -0
  122. package/dist/providers/registry.d.ts.map +1 -0
  123. package/dist/providers/registry.js +1 -0
  124. package/dist/sched/scheduler.d.ts +20 -0
  125. package/dist/sched/scheduler.d.ts.map +1 -0
  126. package/dist/sched/scheduler.js +1 -0
  127. package/dist/sched/task.d.ts +92 -0
  128. package/dist/sched/task.d.ts.map +1 -0
  129. package/dist/sched/task.js +102 -0
  130. package/dist/serde/__tests__/codec.test.d.ts +2 -0
  131. package/dist/serde/__tests__/codec.test.d.ts.map +1 -0
  132. package/dist/serde/__tests__/codec.test.js +75 -0
  133. package/dist/serde/codec.d.ts +12 -0
  134. package/dist/serde/codec.d.ts.map +1 -0
  135. package/dist/serde/codec.js +54 -0
  136. package/dist/serde/json.d.ts +8 -0
  137. package/dist/serde/json.d.ts.map +1 -0
  138. package/dist/serde/json.js +13 -0
  139. package/dist/serde/thread.d.ts +687 -0
  140. package/dist/serde/thread.d.ts.map +1 -0
  141. package/dist/serde/thread.js +158 -0
  142. package/dist/serde/tool.d.ts +36 -0
  143. package/dist/serde/tool.d.ts.map +1 -0
  144. package/dist/serde/tool.js +1 -0
  145. package/dist/session.d.ts +1 -0
  146. package/dist/session.d.ts.map +1 -0
  147. package/dist/session.js +1 -0
  148. package/dist/task.d.ts +87 -0
  149. package/dist/task.d.ts.map +1 -0
  150. package/dist/task.js +97 -0
  151. package/dist/thread/__tests__/mock.d.ts +28 -0
  152. package/dist/thread/__tests__/mock.d.ts.map +1 -0
  153. package/dist/thread/__tests__/mock.js +74 -0
  154. package/dist/thread/__tests__/thread.test.d.ts +2 -0
  155. package/dist/thread/__tests__/thread.test.d.ts.map +1 -0
  156. package/dist/thread/__tests__/thread.test.js +1412 -0
  157. package/dist/thread/index.d.ts +2 -0
  158. package/dist/thread/index.d.ts.map +1 -0
  159. package/dist/thread/index.js +1 -0
  160. package/dist/thread/thread.d.ts +66 -0
  161. package/dist/thread/thread.d.ts.map +1 -0
  162. package/dist/thread/thread.js +472 -0
  163. package/dist/thread/utils.d.ts +19 -0
  164. package/dist/thread/utils.d.ts.map +1 -0
  165. package/dist/thread/utils.js +50 -0
  166. package/dist/tool/__tests__/fixtures.d.ts +45 -0
  167. package/dist/tool/__tests__/fixtures.d.ts.map +1 -0
  168. package/dist/tool/__tests__/fixtures.js +97 -0
  169. package/dist/tool/__tests__/tool.test.d.ts +2 -0
  170. package/dist/tool/__tests__/tool.test.d.ts.map +1 -0
  171. package/dist/tool/__tests__/tool.test.js +172 -0
  172. package/dist/tool/__tests__/toolkit.test.d.ts +2 -0
  173. package/dist/tool/__tests__/toolkit.test.d.ts.map +1 -0
  174. package/dist/tool/__tests__/toolkit.test.js +134 -0
  175. package/dist/tool/index.d.ts +4 -0
  176. package/dist/tool/index.d.ts.map +1 -0
  177. package/dist/tool/index.js +2 -0
  178. package/dist/tool/mcp.d.ts +75 -0
  179. package/dist/tool/mcp.d.ts.map +1 -0
  180. package/dist/tool/mcp.js +111 -0
  181. package/dist/tool/tool.d.ts +95 -0
  182. package/dist/tool/tool.d.ts.map +1 -0
  183. package/dist/tool/tool.js +176 -0
  184. package/dist/tool/toolkit.d.ts +121 -0
  185. package/dist/tool/toolkit.d.ts.map +1 -0
  186. package/dist/tool/toolkit.js +180 -0
  187. package/dist/tool/types.d.ts +187 -0
  188. package/dist/tool/types.d.ts.map +1 -0
  189. package/dist/tool/types.js +1 -0
  190. package/dist/tools.d.ts +362 -0
  191. package/dist/tools.d.ts.map +1 -0
  192. package/dist/tools.js +220 -0
  193. package/dist/trace/processor.d.ts +1 -0
  194. package/dist/trace/processor.d.ts.map +1 -0
  195. package/dist/trace/processor.js +1 -0
  196. package/dist/trace/traces.d.ts +1 -0
  197. package/dist/trace/traces.d.ts.map +1 -0
  198. package/dist/trace/traces.js +73 -0
  199. package/dist/trace/utils.d.ts +22 -0
  200. package/dist/trace/utils.d.ts.map +1 -0
  201. package/dist/trace/utils.js +30 -0
  202. package/dist/types/agent.d.ts +91 -0
  203. package/dist/types/agent.d.ts.map +1 -0
  204. package/dist/types/agent.js +1 -0
  205. package/dist/types/proto.d.ts +1551 -0
  206. package/dist/types/proto.d.ts.map +1 -0
  207. package/dist/types/proto.js +531 -0
  208. package/dist/types/thread.d.ts +71 -0
  209. package/dist/types/thread.d.ts.map +1 -0
  210. package/dist/types/thread.js +5 -0
  211. package/dist/usage.d.ts +43 -0
  212. package/dist/usage.d.ts.map +1 -0
  213. package/dist/usage.js +61 -0
  214. package/package.json +52 -0
  215. package/src/agent.ts +203 -0
  216. package/src/context.ts +265 -0
  217. package/src/guardrail.ts +277 -0
  218. package/src/index.ts +3 -0
  219. package/src/kernl.ts +22 -0
  220. package/src/lib/env.ts +36 -0
  221. package/src/lib/error.ts +158 -0
  222. package/src/lib/logger.ts +78 -0
  223. package/src/lib/serde/json.ts +18 -0
  224. package/src/lib/serde/thread.ts +188 -0
  225. package/src/lifecycle.ts +181 -0
  226. package/src/mcp/__tests__/base.test.ts +344 -0
  227. package/src/mcp/__tests__/fixtures/server.ts +179 -0
  228. package/src/mcp/__tests__/fixtures/utils.ts +58 -0
  229. package/src/mcp/__tests__/integration.test.ts +447 -0
  230. package/src/mcp/__tests__/stdio.test.ts +236 -0
  231. package/src/mcp/__tests__/utils.test.ts +360 -0
  232. package/src/mcp/base.ts +162 -0
  233. package/src/mcp/http.ts +147 -0
  234. package/src/mcp/sse.ts +137 -0
  235. package/src/mcp/stdio.ts +136 -0
  236. package/src/mcp/types.ts +202 -0
  237. package/src/mcp/utils.ts +62 -0
  238. package/src/task.ts +119 -0
  239. package/src/thread/__tests__/mock.ts +95 -0
  240. package/src/thread/__tests__/thread.test.ts +1574 -0
  241. package/src/thread/index.ts +1 -0
  242. package/src/thread/thread.ts +611 -0
  243. package/src/thread/utils.ts +67 -0
  244. package/src/tool/__tests__/fixtures.ts +106 -0
  245. package/src/tool/__tests__/tool.test.ts +235 -0
  246. package/src/tool/__tests__/toolkit.test.ts +174 -0
  247. package/src/tool/index.ts +10 -0
  248. package/src/tool/tool.ts +264 -0
  249. package/src/tool/toolkit.ts +234 -0
  250. package/src/tool/types.ts +243 -0
  251. package/src/trace/processor.ts +0 -0
  252. package/src/trace/traces.ts +86 -0
  253. package/src/trace/utils.ts +38 -0
  254. package/src/types/agent.ts +145 -0
  255. package/src/types/thread.ts +86 -0
  256. package/tsconfig.json +13 -0
  257. package/vitest.config.ts +14 -0
@@ -0,0 +1,172 @@
1
+ import { z } from "zod";
2
+ import type { Tool } from "@modelcontextprotocol/sdk/types.js";
3
+ import { Agent } from "../agent";
4
+ import { Context, UnknownContext } from "../context";
5
+ import { Logger } from "../lib/logger";
6
+ /**
7
+ * MCP tool type from the SDK.
8
+ * We use the SDK's type directly to avoid compatibility issues.
9
+ */
10
+ export type MCPTool = Tool;
11
+ /**
12
+ * Custom MCP tool schema definition with stricter contracts.
13
+ * NOTE: Currently not used, but kept for potential future runtime validation.
14
+ * If needed, we could parse SDK tools through this schema to enforce stricter requirements.
15
+ */
16
+ export declare const MCPToolSchema: z.ZodObject<{
17
+ name: z.ZodString;
18
+ description: z.ZodOptional<z.ZodString>;
19
+ inputSchema: z.ZodObject<{
20
+ type: z.ZodLiteral<"object">;
21
+ properties: z.ZodRecord<z.ZodString, z.ZodAny>;
22
+ required: z.ZodArray<z.ZodString>;
23
+ additionalProperties: z.ZodBoolean;
24
+ }, z.core.$strip>;
25
+ }, z.core.$strip>;
26
+ /**
27
+ * Context provided to server-level tool filters during tool resolution.
28
+ */
29
+ export interface MCPToolFilterContext<TContext = UnknownContext> {
30
+ context: Context<TContext>;
31
+ agent: Agent<TContext, any>;
32
+ serverId: string;
33
+ }
34
+ /**
35
+ * Server-level filter for MCP tools.
36
+ *
37
+ * Operates at the protocol layer on raw MCPTool objects before conversion.
38
+ * Use this for static, security-focused filtering (e.g., "never expose tool X").
39
+ *
40
+ * This is the first filter in the pipeline. For dynamic, context-aware filtering,
41
+ * use ToolkitFilter on MCPToolkit instead.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const server = new MCPServerStdio({
46
+ * command: "npx",
47
+ * args: ["-y", "some-server"],
48
+ * toolFilter: async (ctx, tool) => {
49
+ * // Never expose dangerous tools
50
+ * return !tool.name.startsWith("dangerous_");
51
+ * }
52
+ * });
53
+ * ```
54
+ */
55
+ export type MCPToolFilter<TContext = UnknownContext> = (context: MCPToolFilterContext<TContext>, tool: MCPTool) => Promise<boolean>;
56
+ /**
57
+ * Static tool filter using allowlist and blocklist of tool names.
58
+ */
59
+ export interface MCPToolFilterStatic {
60
+ allowedToolNames?: string[];
61
+ blockedToolNames?: string[];
62
+ }
63
+ /**
64
+ * JSON-RPC 2.0 request message.
65
+ */
66
+ export interface JsonRpcRequest {
67
+ jsonrpc: "2.0";
68
+ id: number;
69
+ method: string;
70
+ params?: Record<string, unknown>;
71
+ }
72
+ /**
73
+ * JSON-RPC 2.0 notification message (no response expected).
74
+ */
75
+ export interface JsonRpcNotification {
76
+ jsonrpc: "2.0";
77
+ method: string;
78
+ params?: Record<string, unknown>;
79
+ }
80
+ /**
81
+ * JSON-RPC 2.0 response message.
82
+ */
83
+ export interface JsonRpcResponse {
84
+ jsonrpc: "2.0";
85
+ id: number;
86
+ result?: any;
87
+ error?: any;
88
+ }
89
+ /**
90
+ * Response from calling an MCP tool.
91
+ */
92
+ export interface CallToolResponse extends JsonRpcResponse {
93
+ result: {
94
+ content: {
95
+ type: string;
96
+ text: string;
97
+ }[];
98
+ };
99
+ }
100
+ export type CallToolResult = CallToolResponse["result"];
101
+ export type CallToolResultContent = CallToolResult["content"];
102
+ /**
103
+ * Response from MCP server initialization.
104
+ */
105
+ export interface InitializeResponse extends JsonRpcResponse {
106
+ result: {
107
+ protocolVersion: string;
108
+ capabilities: {
109
+ tools: Record<string, unknown>;
110
+ };
111
+ serverInfo: {
112
+ name: string;
113
+ version: string;
114
+ };
115
+ };
116
+ }
117
+ export type InitializeResult = InitializeResponse["result"];
118
+ /**
119
+ * Base configuration options for stdio-based MCP servers.
120
+ */
121
+ export interface BaseMCPServerStdioOptions {
122
+ env?: Record<string, string>;
123
+ cwd?: string;
124
+ cacheToolsList?: boolean;
125
+ clientSessionTimeoutSeconds?: number;
126
+ id?: string;
127
+ encoding?: string;
128
+ encodingErrorHandler?: "strict" | "ignore" | "replace";
129
+ logger?: Logger;
130
+ toolFilter?: MCPToolFilter;
131
+ timeout?: number;
132
+ }
133
+ /**
134
+ * Stdio MCP server options with command and args.
135
+ */
136
+ export interface MCPServerStdioOptions extends BaseMCPServerStdioOptions {
137
+ command: string;
138
+ args?: string[];
139
+ }
140
+ /**
141
+ * Configuration options for streamable HTTP MCP servers.
142
+ */
143
+ export interface MCPServerStreamableHttpOptions {
144
+ url: string;
145
+ cacheToolsList?: boolean;
146
+ clientSessionTimeoutSeconds?: number;
147
+ id?: string;
148
+ logger?: Logger;
149
+ toolFilter?: MCPToolFilter;
150
+ timeout?: number;
151
+ authProvider?: any;
152
+ requestInit?: any;
153
+ fetch?: any;
154
+ reconnectionOptions?: any;
155
+ sessionId?: string;
156
+ }
157
+ /**
158
+ * Configuration options for Server-Sent Events (SSE) MCP servers.
159
+ */
160
+ export interface MCPServerSSEOptions {
161
+ url: string;
162
+ cacheToolsList?: boolean;
163
+ clientSessionTimeoutSeconds?: number;
164
+ id?: string;
165
+ logger?: Logger;
166
+ toolFilter?: MCPToolFilter;
167
+ timeout?: number;
168
+ authProvider?: any;
169
+ requestInit?: any;
170
+ eventSourceInit?: any;
171
+ }
172
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/mcp/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oCA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OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,yBAAyB;IACtE,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C,GAAG,EAAE,MAAM,CAAC;IACZ,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,aAAa,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IAKjB,YAAY,CAAC,EAAE,GAAG,CAAC;IAEnB,WAAW,CAAC,EAAE,GAAG,CAAC;IAGlB,KAAK,CAAC,EAAE,GAAG,CAAC;IAEZ,mBAAmB,CAAC,EAAE,GAAG,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;CAEpB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,2BAA2B,CAAC,EAAE,MAAM,CAAC;IACrC,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,aAAa,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IAKjB,YAAY,CAAC,EAAE,GAAG,CAAC;IAEnB,WAAW,CAAC,EAAE,GAAG,CAAC;IAElB,eAAe,CAAC,EAAE,GAAG,CAAC;CAEvB"}
@@ -0,0 +1,16 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Custom MCP tool schema definition with stricter contracts.
4
+ * NOTE: Currently not used, but kept for potential future runtime validation.
5
+ * If needed, we could parse SDK tools through this schema to enforce stricter requirements.
6
+ */
7
+ export const MCPToolSchema = z.object({
8
+ name: z.string(),
9
+ description: z.string().optional(),
10
+ inputSchema: z.object({
11
+ type: z.literal("object"),
12
+ properties: z.record(z.string(), z.any()),
13
+ required: z.array(z.string()),
14
+ additionalProperties: z.boolean(),
15
+ }),
16
+ });
@@ -0,0 +1,23 @@
1
+ import { z } from "zod";
2
+ import { UnknownContext } from "../context";
3
+ import { MCPServer } from "./base";
4
+ import type { MCPTool, MCPToolFilter } from "./types";
5
+ /**
6
+ * Converts an MCP tool definition into a function tool usable by the SDK.
7
+ */
8
+ export declare function mcpToFunctionTool(server: MCPServer, mcpTool: MCPTool): import("../tool").FunctionTool<unknown, z.ZodRecord<z.ZodString, z.ZodAny> | undefined, {
9
+ type: string;
10
+ text: string;
11
+ } | {
12
+ type: string;
13
+ text: string;
14
+ }[]>;
15
+ /**
16
+ * Creates a static tool filter from allowed and blocked tool name lists.
17
+ * Returns a filter function that can be used with MCP servers.
18
+ */
19
+ export declare function createMCPToolStaticFilter<TContext = UnknownContext>(options?: {
20
+ allowed?: string[];
21
+ blocked?: string[];
22
+ }): MCPToolFilter<TContext> | undefined;
23
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/mcp/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3C,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEtD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO;;;;;;KAmBpE;AAMD;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,GAAG,cAAc,EAAE,OAAO,CAAC,EAAE;IAC7E,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,GAAG,aAAa,CAAC,QAAQ,CAAC,GAAG,SAAS,CAkBtC"}
@@ -0,0 +1,44 @@
1
+ import { z } from "zod";
2
+ import { tool } from "../tool";
3
+ /**
4
+ * Converts an MCP tool definition into a function tool usable by the SDK.
5
+ */
6
+ export function mcpToFunctionTool(server, mcpTool) {
7
+ async function invoke(_ctx, input) {
8
+ const content = await server.callTool(mcpTool.name, input);
9
+ return content.length === 1 ? content[0] : content;
10
+ }
11
+ // MCP tools accept an object with any properties based on their inputSchema
12
+ // We use z.record(z.any()) to represent this flexible schema
13
+ const parameters = mcpTool.inputSchema
14
+ ? z.record(z.string(), z.any())
15
+ : undefined;
16
+ return tool({
17
+ id: mcpTool.name,
18
+ name: mcpTool.name,
19
+ description: mcpTool.description ?? "",
20
+ parameters,
21
+ execute: invoke,
22
+ });
23
+ }
24
+ // ----------------------------
25
+ // Tool filters
26
+ // ----------------------------
27
+ /**
28
+ * Creates a static tool filter from allowed and blocked tool name lists.
29
+ * Returns a filter function that can be used with MCP servers.
30
+ */
31
+ export function createMCPToolStaticFilter(options) {
32
+ if (!options?.allowed && !options?.blocked) {
33
+ return undefined;
34
+ }
35
+ const allowedToolNames = options.allowed ?? [];
36
+ const blockedToolNames = options.blocked ?? [];
37
+ return async (_ctx, tool) => {
38
+ const allowed = allowedToolNames.length > 0 ? allowedToolNames.includes(tool.name) : true;
39
+ const blocked = blockedToolNames.length > 0
40
+ ? blockedToolNames.includes(tool.name)
41
+ : false;
42
+ return allowed && !blocked;
43
+ };
44
+ }
@@ -0,0 +1,175 @@
1
+ import { Usage } from "./usage";
2
+ import { SerializedTool } from "./lib/serde/tool";
3
+ import { ThreadEvent, ThreadStreamEvent } from "./types/thread";
4
+ export type ModelTracing = boolean | "enabled_without_data";
5
+ /**
6
+ * The base interface for calling an LLM.
7
+ */
8
+ export interface LanguageModel {
9
+ /**
10
+ * Get a response from the model.
11
+ *
12
+ * @param request - The request to get a response for.
13
+ */
14
+ generate(request: LanguageModelRequest): Promise<LanguageModelResponse>;
15
+ /**
16
+ * Get a streamed response from the model.
17
+ *
18
+ * @param request - The request to get a response for.
19
+ */
20
+ stream(request: LanguageModelRequest): AsyncIterable<ThreadStreamEvent>;
21
+ }
22
+ /**
23
+ * A request to a large language model.
24
+ */
25
+ export type LanguageModelRequest = {
26
+ /**
27
+ * The system instructions to use for the model.
28
+ */
29
+ system?: string;
30
+ /**
31
+ * The input to the model.
32
+ */
33
+ input: ThreadEvent[] | string;
34
+ /**
35
+ * The ID of stored conversation to use for the model.
36
+ */
37
+ conversationId?: string;
38
+ /**
39
+ * The model settings to use for the model.
40
+ */
41
+ modelSettings: LanguageModelSettings;
42
+ /**
43
+ * The tools to use for the model.
44
+ */
45
+ tools: SerializedTool[];
46
+ /**
47
+ * Whether to enable tracing for the model.
48
+ */
49
+ tracing: ModelTracing;
50
+ /**
51
+ * An optional signal to abort the model request.
52
+ */
53
+ abort?: AbortSignal;
54
+ };
55
+ /**
56
+ * The base response type
57
+ */
58
+ export type LanguageModelResponse = {
59
+ /**
60
+ * The usage information for response.
61
+ */
62
+ usage: Usage;
63
+ /**
64
+ * A list of events (messages, tool calls, etc.) generated by the model.
65
+ */
66
+ events: ThreadEvent[];
67
+ /**
68
+ * An ID for the response which can be used to refer to the response in subsequent calls to the
69
+ * model. Not supported by all model providers.
70
+ */
71
+ responseId?: string;
72
+ /**
73
+ * Raw response data from the underlying model provider.
74
+ */
75
+ providerData?: Record<string, any>;
76
+ };
77
+ /**
78
+ * Settings to use when calling an LLM.
79
+ *
80
+ * This class holds optional model configuration parameters (e.g. temperature,
81
+ * topP, penalties, truncation, etc.).
82
+ *
83
+ * Not all models/providers support all of these parameters, so please check the API documentation
84
+ * for the specific model and provider you are using.
85
+ */
86
+ export type LanguageModelSettings = {
87
+ /**
88
+ * The temperature to use when calling the model.
89
+ */
90
+ temperature?: number;
91
+ /**
92
+ * The topP to use when calling the model.
93
+ */
94
+ topP?: number;
95
+ /**
96
+ * The frequency penalty to use when calling the model.
97
+ */
98
+ frequencyPenalty?: number;
99
+ /**
100
+ * The presence penalty to use when calling the model.
101
+ */
102
+ presencePenalty?: number;
103
+ /**
104
+ * The tool choice to use when calling the model.
105
+ */
106
+ toolChoice?: ModelSettingsToolChoice;
107
+ /**
108
+ * Whether to use parallel tool calls when calling the model.
109
+ * Defaults to false if not provided.
110
+ */
111
+ parallelToolCalls?: boolean;
112
+ /**
113
+ * The truncation strategy to use when calling the model.
114
+ */
115
+ truncation?: "auto" | "disabled";
116
+ /**
117
+ * The maximum number of output tokens to generate.
118
+ */
119
+ maxTokens?: number;
120
+ /**
121
+ * Whether to store the generated model response for later retrieval.
122
+ * Defaults to true if not provided.
123
+ */
124
+ store?: boolean;
125
+ /**
126
+ * The reasoning settings to use when calling the model.
127
+ */
128
+ reasoning?: ModelSettingsReasoning;
129
+ /**
130
+ * The text settings to use when calling the model.
131
+ */
132
+ text?: ModelSettingsText;
133
+ /**
134
+ * Additional provider specific settings to be passed directly to the model
135
+ * request.
136
+ */
137
+ providerData?: Record<string, any>;
138
+ };
139
+ export type ModelSettingsToolChoice = "auto" | "required" | "none";
140
+ /**
141
+ * Constrains effort on reasoning for [reasoning models](https://platform.openai.com/docs/guides/reasoning).
142
+ *
143
+ * Supported for providers:
144
+ *
145
+ * - OpenAI
146
+ * - ... ?
147
+ */
148
+ export type ModelSettingsReasoningEffort = "minimal" | "low" | "medium" | "high" | null;
149
+ /**
150
+ * Configuration options for [reasoning models](https://platform.openai.com/docs/guides/reasoning).
151
+ */
152
+ export type ModelSettingsReasoning = {
153
+ /**
154
+ * Constrains effort on reasoning for [reasoning models](https://platform.openai.com/docs/guides/reasoning).
155
+ */
156
+ effort?: ModelSettingsReasoningEffort | null;
157
+ /**
158
+ * A summary of the reasoning performed by the model.
159
+ * This can be useful for debugging and understanding the model's reasoning process.
160
+ * One of `auto`, `concise`, or `detailed`.
161
+ */
162
+ summary?: "auto" | "concise" | "detailed" | null;
163
+ };
164
+ export interface ModelSettingsText {
165
+ /**
166
+ * Constrains the verbosity of the model's response.
167
+ *
168
+ * Supported for providers:
169
+ *
170
+ * - OpenAI
171
+ * - ... ?
172
+ */
173
+ verbosity?: "low" | "medium" | "high" | null;
174
+ }
175
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEhE,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,sBAAsB,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,QAAQ,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAExE;;;;OAIG;IACH,MAAM,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAAC,iBAAiB,CAAC,CAAC;CACzE;AAED;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,KAAK,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IAO9B;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,aAAa,EAAE,qBAAqB,CAAC;IAErC;;OAEG;IACH,KAAK,EAAE,cAAc,EAAE,CAAC;IAYxB;;OAEG;IACH,OAAO,EAAE,YAAY,CAAC;IAEtB;;OAEG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC;;OAEG;IACH,KAAK,EAAE,KAAK,CAA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AG,SAAS,GAAG,UAAU,GAAG,IAAI,CAAC;CAClD,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,IAAI,CAAC;CAC9C"}
package/dist/model.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=ai.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai.d.ts","sourceRoot":"","sources":["../../src/providers/ai.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,16 @@
1
+ import type { LanguageModel, LanguageModelRequest, LanguageModelResponse } from "../model";
2
+ import type { ThreadStreamEvent } from "../types/thread";
3
+ /**
4
+ * Default language model that throws an error when used.
5
+ * This is used as a fallback when no model is provided to an Agent.
6
+ */
7
+ declare class DefaultLanguageModel implements LanguageModel {
8
+ generate(request: LanguageModelRequest): Promise<LanguageModelResponse>;
9
+ stream(request: LanguageModelRequest): AsyncIterable<ThreadStreamEvent>;
10
+ }
11
+ /**
12
+ * Singleton instance of the default language model
13
+ */
14
+ export declare const DEFAULT_LANGUAGE_MODEL: DefaultLanguageModel;
15
+ export {};
16
+ //# sourceMappingURL=default.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../src/providers/default.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAIxD;;;GAGG;AACH,cAAM,oBAAqB,YAAW,aAAa;IAC3C,QAAQ,CACZ,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IAM1B,MAAM,CACX,OAAO,EAAE,oBAAoB,GAC5B,aAAa,CAAC,iBAAiB,CAAC;CAKpC;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,sBAA6B,CAAC"}
@@ -0,0 +1,17 @@
1
+ // (TEMPORARY)
2
+ /**
3
+ * Default language model that throws an error when used.
4
+ * This is used as a fallback when no model is provided to an Agent.
5
+ */
6
+ class DefaultLanguageModel {
7
+ async generate(request) {
8
+ throw new Error("No language model configured. Please provide a model to the Agent.");
9
+ }
10
+ async *stream(request) {
11
+ throw new Error("No language model configured. Please provide a model to the Agent.");
12
+ }
13
+ }
14
+ /**
15
+ * Singleton instance of the default language model
16
+ */
17
+ export const DEFAULT_LANGUAGE_MODEL = new DefaultLanguageModel();
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/providers/registry.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,20 @@
1
+ import type { Task } from "./task";
2
+ /**
3
+ * Per-agent run queue.
4
+ * Each agent has one run queue tracking its tasks.
5
+ *
6
+ * Simplified for hello world - defers clock, load, stats, and CFS priority logic.
7
+ */
8
+ export interface RunQueue {
9
+ agentId: string;
10
+ curr: Task[];
11
+ nrunning: number;
12
+ tasks: Task[];
13
+ }
14
+ /**
15
+ * Configuration for the Scheduler.
16
+ */
17
+ export interface SchedulerConfig {
18
+ defaultMaxConcurrent?: number;
19
+ }
20
+ //# sourceMappingURL=scheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../src/sched/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEnC;;;;;GAKG;AACH,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAmC;IAClD,IAAI,EAAE,IAAI,EAAE,CAAiC;IAC7C,QAAQ,EAAE,MAAM,CAAgC;IAChD,KAAK,EAAE,IAAI,EAAE,CAA0C;CAOxD;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,oBAAoB,CAAC,EAAE,MAAM,CAAkD;CAChF"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,92 @@
1
+ import type { Agent } from "../agent";
2
+ import type { Context, UnknownContext } from "../context";
3
+ import type { Thread } from "../thread";
4
+ /**
5
+ * A Task represents a unit of work scheduled by the kernl.
6
+ * Analogous to task_struct in the Linux kernel.
7
+ */
8
+ export declare class Task<TContext = UnknownContext, TResult = unknown> {
9
+ pid: string;
10
+ instructions: string | ((context: Context<TContext>) => string);
11
+ state: TaskState;
12
+ owner: Agent<TContext>;
13
+ context: Context<TContext>;
14
+ /**
15
+ * Might want the ability to pick up a new thread of execution from a compressed task checkpoint instead of including
16
+ * all of the events from the old threads (which may no longer be useful if they completed with good artifacts + reasoning / action summaries).
17
+ * At that point its really more about tracing.
18
+ */
19
+ threads: Thread<TContext>[];
20
+ current: Thread<TContext> | null;
21
+ result: TResult | null;
22
+ constructor(init: {
23
+ pid: string;
24
+ instructions: string | ((context: Context<TContext>) => string);
25
+ state: TaskState;
26
+ owner: Agent<TContext>;
27
+ context: Context<TContext>;
28
+ });
29
+ }
30
+ /**
31
+ * The various states that a task may be in.
32
+ */
33
+ export declare enum TaskState {
34
+ /**
35
+ * Task is either:
36
+ * - Currently executing
37
+ * - In run queue waiting to be scheduled (might want to differentiate between running + queued here)
38
+ */
39
+ RUNNING = "running",
40
+ /**
41
+ * Task is sleeping/blocked, waiting for a condition.
42
+ * Can be woken up by:
43
+ * - The condition being met (e.g., approval granted)
44
+ * - A signal (e.g., user cancellation)
45
+ *
46
+ * Examples:
47
+ * - Waiting for tool approval
48
+ * - Waiting for user input
49
+ * - Sleeping on a timer
50
+ */
51
+ INTERRUPTIBLE = "interruptible",
52
+ /**
53
+ * Task is sleeping/blocked and CANNOT be interrupted by signals.
54
+ * Only wakes when the condition is met.
55
+ *
56
+ * Examples:
57
+ * - Waiting for critical I/O (model API call)
58
+ * - Waiting for resource that MUST complete
59
+ *
60
+ * Use sparingly - these tasks can't be cancelled!
61
+ */
62
+ UNINTERRUPTIBLE = "uninterruptible",
63
+ /**
64
+ * Task has been stopped by a signal (SIGSTOP).
65
+ * Will remain stopped until explicitly continued (SIGCONT).
66
+ *
67
+ * Examples:
68
+ * - User explicitly paused the agent
69
+ * - Debugger attached
70
+ */
71
+ STOPPED = "stopped",
72
+ /**
73
+ * Task is being traced by a debugger.
74
+ * Similar to STOPPED but for debugging.
75
+ */
76
+ TRACED = "traced",
77
+ /**
78
+ * Task has finished execution but hasn't been cleaned up yet.
79
+ * Waiting for parent to read exit status (wait/waitpid).
80
+ *
81
+ * Examples:
82
+ * - Agent completed but result not yet retrieved
83
+ * - Child agent finished, parent needs to collect result
84
+ */
85
+ ZOMBIE = "zombie",
86
+ /**
87
+ * Task is being removed from the system.
88
+ * Final cleanup in progress, about to be fully deleted.
89
+ */
90
+ DEAD = "dead"
91
+ }
92
+ //# sourceMappingURL=task.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"task.d.ts","sourceRoot":"","sources":["../../src/sched/task.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC;;;GAGG;AACH,qBAAa,IAAI,CAAC,QAAQ,GAAG,cAAc,EAAE,OAAO,GAAG,OAAO;IAC5D,GAAG,EAAE,MAAM,CAAoD;IAG/D,YAAY,EACR,MAAM,GACN,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,KAAK,MAAM,CAAC,CAA4B;IAExE,KAAK,EAAE,SAAS,CAAiC;IACjD,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,CAA2C;IAEjE,OAAO,EAAE,OAAO,CAAC,QAAQ,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