kernl 0.2.1 → 0.6.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 (292) hide show
  1. package/.turbo/turbo-build.log +5 -4
  2. package/.turbo/turbo-check-types.log +4 -0
  3. package/CHANGELOG.md +147 -0
  4. package/LICENSE +1 -1
  5. package/dist/agent/__tests__/concurrency.test.d.ts +2 -0
  6. package/dist/agent/__tests__/concurrency.test.d.ts.map +1 -0
  7. package/dist/agent/__tests__/concurrency.test.js +152 -0
  8. package/dist/agent/__tests__/run.test.d.ts +2 -0
  9. package/dist/agent/__tests__/run.test.d.ts.map +1 -0
  10. package/dist/agent/__tests__/run.test.js +357 -0
  11. package/dist/agent/index.d.ts +1 -0
  12. package/dist/agent/index.d.ts.map +1 -0
  13. package/dist/agent.d.ts +35 -12
  14. package/dist/agent.d.ts.map +1 -1
  15. package/dist/agent.js +102 -15
  16. package/dist/api/__tests__/cursor-page.test.d.ts +2 -0
  17. package/dist/api/__tests__/cursor-page.test.d.ts.map +1 -0
  18. package/dist/api/__tests__/cursor-page.test.js +414 -0
  19. package/dist/api/__tests__/offset-page.test.d.ts +2 -0
  20. package/dist/api/__tests__/offset-page.test.d.ts.map +1 -0
  21. package/dist/api/__tests__/offset-page.test.js +510 -0
  22. package/dist/api/__tests__/threads.test.d.ts +2 -0
  23. package/dist/api/__tests__/threads.test.d.ts.map +1 -0
  24. package/dist/api/__tests__/threads.test.js +338 -0
  25. package/dist/api/models/index.d.ts +2 -0
  26. package/dist/api/models/index.d.ts.map +1 -0
  27. package/dist/api/models/thread.d.ts +120 -0
  28. package/dist/api/models/thread.d.ts.map +1 -0
  29. package/dist/api/pagination/base.d.ts +48 -0
  30. package/dist/api/pagination/base.d.ts.map +1 -0
  31. package/dist/api/pagination/base.js +45 -0
  32. package/dist/api/pagination/cursor.d.ts +44 -0
  33. package/dist/api/pagination/cursor.d.ts.map +1 -0
  34. package/dist/api/pagination/cursor.js +52 -0
  35. package/dist/api/pagination/offset.d.ts +42 -0
  36. package/dist/api/pagination/offset.d.ts.map +1 -0
  37. package/dist/api/pagination/offset.js +55 -0
  38. package/dist/api/resources/threads/events.d.ts +21 -0
  39. package/dist/api/resources/threads/events.d.ts.map +1 -0
  40. package/dist/api/resources/threads/events.js +24 -0
  41. package/dist/api/resources/threads/index.d.ts +4 -0
  42. package/dist/api/resources/threads/index.d.ts.map +1 -0
  43. package/dist/api/resources/threads/index.js +2 -0
  44. package/dist/api/resources/threads/threads.d.ts +57 -0
  45. package/dist/api/resources/threads/threads.d.ts.map +1 -0
  46. package/dist/api/resources/threads/threads.js +199 -0
  47. package/dist/api/resources/threads/types.d.ts +123 -0
  48. package/dist/api/resources/threads/types.d.ts.map +1 -0
  49. package/dist/api/resources/threads/utils.d.ts +18 -0
  50. package/dist/api/resources/threads/utils.d.ts.map +1 -0
  51. package/dist/api/resources/threads/utils.js +78 -0
  52. package/dist/context.d.ts +5 -1
  53. package/dist/context.d.ts.map +1 -1
  54. package/dist/context.js +6 -1
  55. package/dist/guardrail.d.ts +4 -4
  56. package/dist/index.d.ts +12 -4
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +10 -3
  59. package/dist/internal.d.ts +4 -0
  60. package/dist/internal.d.ts.map +1 -0
  61. package/dist/internal.js +2 -0
  62. package/dist/kernl/index.d.ts +3 -0
  63. package/dist/kernl/index.d.ts.map +1 -0
  64. package/dist/kernl/index.js +2 -0
  65. package/dist/kernl/kernl.d.ts +64 -0
  66. package/dist/kernl/kernl.d.ts.map +1 -0
  67. package/dist/kernl/kernl.js +116 -0
  68. package/dist/kernl/threads.d.ts +110 -0
  69. package/dist/kernl/threads.d.ts.map +1 -0
  70. package/dist/kernl/threads.js +126 -0
  71. package/dist/kernl.d.ts +27 -11
  72. package/dist/kernl.d.ts.map +1 -1
  73. package/dist/kernl.js +74 -11
  74. package/dist/lib/env.d.ts +3 -3
  75. package/dist/lib/env.js +1 -1
  76. package/dist/lib/error.d.ts +3 -3
  77. package/dist/lib/logger.js +1 -1
  78. package/dist/lifecycle.d.ts +5 -5
  79. package/dist/mcp/__tests__/base.test.js +2 -2
  80. package/dist/mcp/__tests__/fixtures/utils.d.ts +1 -1
  81. package/dist/mcp/__tests__/fixtures/utils.js +1 -1
  82. package/dist/mcp/__tests__/integration.test.js +16 -16
  83. package/dist/mcp/__tests__/stdio.test.js +2 -2
  84. package/dist/mcp/__tests__/utils.test.js +8 -8
  85. package/dist/mcp/base.d.ts +2 -2
  86. package/dist/mcp/http.d.ts +3 -3
  87. package/dist/mcp/http.d.ts.map +1 -1
  88. package/dist/mcp/http.js +11 -11
  89. package/dist/mcp/sse.d.ts +3 -3
  90. package/dist/mcp/sse.d.ts.map +1 -1
  91. package/dist/mcp/sse.js +9 -9
  92. package/dist/mcp/stdio.d.ts +2 -2
  93. package/dist/mcp/stdio.js +2 -2
  94. package/dist/mcp/types.d.ts +3 -3
  95. package/dist/mcp/utils.d.ts +4 -4
  96. package/dist/mcp/utils.d.ts.map +1 -1
  97. package/dist/mcp/utils.js +5 -6
  98. package/dist/storage/__tests__/in-memory.test.d.ts +2 -0
  99. package/dist/storage/__tests__/in-memory.test.d.ts.map +1 -0
  100. package/dist/storage/__tests__/in-memory.test.js +455 -0
  101. package/dist/storage/base.d.ts +64 -0
  102. package/dist/storage/base.d.ts.map +1 -0
  103. package/dist/storage/base.js +4 -0
  104. package/dist/storage/in-memory.d.ts +62 -0
  105. package/dist/storage/in-memory.d.ts.map +1 -0
  106. package/dist/storage/in-memory.js +283 -0
  107. package/dist/storage/index.d.ts +10 -0
  108. package/dist/storage/index.d.ts.map +1 -0
  109. package/dist/storage/index.js +7 -0
  110. package/dist/storage/thread.d.ts +123 -0
  111. package/dist/storage/thread.d.ts.map +1 -0
  112. package/dist/storage/thread.js +4 -0
  113. package/dist/task.d.ts +8 -6
  114. package/dist/task.d.ts.map +1 -1
  115. package/dist/task.js +10 -8
  116. package/dist/thread/__tests__/fixtures/mock-model.d.ts +1 -2
  117. package/dist/thread/__tests__/fixtures/mock-model.d.ts.map +1 -1
  118. package/dist/thread/__tests__/integration.test.js +10 -10
  119. package/dist/thread/__tests__/mock.d.ts +1 -1
  120. package/dist/thread/__tests__/namespace.test.d.ts +2 -0
  121. package/dist/thread/__tests__/namespace.test.d.ts.map +1 -0
  122. package/dist/thread/__tests__/namespace.test.js +131 -0
  123. package/dist/thread/__tests__/thread-persistence.test.d.ts +2 -0
  124. package/dist/thread/__tests__/thread-persistence.test.d.ts.map +1 -0
  125. package/dist/thread/__tests__/thread-persistence.test.js +351 -0
  126. package/dist/thread/__tests__/thread.test.js +55 -57
  127. package/dist/thread/index.d.ts +1 -1
  128. package/dist/thread/index.js +1 -1
  129. package/dist/thread/thread.d.ts +74 -22
  130. package/dist/thread/thread.d.ts.map +1 -1
  131. package/dist/thread/thread.js +212 -74
  132. package/dist/thread/utils.d.ts +38 -10
  133. package/dist/thread/utils.d.ts.map +1 -1
  134. package/dist/thread/utils.js +53 -9
  135. package/dist/tool/__tests__/fixtures.d.ts +8 -8
  136. package/dist/tool/__tests__/fixtures.js +3 -3
  137. package/dist/tool/__tests__/tool.test.js +2 -2
  138. package/dist/tool/__tests__/toolkit.test.js +17 -14
  139. package/dist/tool/index.d.ts +3 -3
  140. package/dist/tool/index.js +2 -2
  141. package/dist/tool/tool.d.ts +2 -2
  142. package/dist/tool/tool.js +5 -5
  143. package/dist/tool/toolkit.d.ts +4 -4
  144. package/dist/tool/toolkit.js +1 -1
  145. package/dist/tool/types.d.ts +4 -4
  146. package/dist/trace/traces.js +2 -2
  147. package/dist/types/agent.d.ts +4 -4
  148. package/dist/types/kernl.d.ts +42 -0
  149. package/dist/types/kernl.d.ts.map +1 -0
  150. package/dist/types/thread.d.ts +110 -24
  151. package/dist/types/thread.d.ts.map +1 -1
  152. package/dist/types/thread.js +12 -0
  153. package/package.json +12 -8
  154. package/src/agent/__tests__/concurrency.test.ts +194 -0
  155. package/src/agent/__tests__/run.test.ts +441 -0
  156. package/src/agent/index.ts +0 -0
  157. package/src/agent.ts +139 -24
  158. package/src/api/__tests__/cursor-page.test.ts +512 -0
  159. package/src/api/__tests__/offset-page.test.ts +624 -0
  160. package/src/api/__tests__/threads.test.ts +415 -0
  161. package/src/api/models/index.ts +6 -0
  162. package/src/api/models/thread.ts +138 -0
  163. package/src/api/pagination/base.ts +79 -0
  164. package/src/api/pagination/cursor.ts +86 -0
  165. package/src/api/pagination/offset.ts +89 -0
  166. package/src/api/resources/threads/events.ts +26 -0
  167. package/src/api/resources/threads/index.ts +9 -0
  168. package/src/api/resources/threads/threads.ts +256 -0
  169. package/src/api/resources/threads/types.ts +143 -0
  170. package/src/api/resources/threads/utils.ts +104 -0
  171. package/src/context.ts +10 -1
  172. package/src/index.ts +49 -1
  173. package/src/internal.ts +15 -0
  174. package/src/kernl.ts +86 -17
  175. package/src/mcp/__tests__/integration.test.ts +8 -9
  176. package/src/mcp/__tests__/utils.test.ts +6 -6
  177. package/src/mcp/http.ts +9 -9
  178. package/src/mcp/sse.ts +7 -7
  179. package/src/mcp/utils.ts +6 -5
  180. package/src/storage/__tests__/in-memory.test.ts +534 -0
  181. package/src/storage/base.ts +77 -0
  182. package/src/storage/in-memory.ts +372 -0
  183. package/src/storage/index.ts +21 -0
  184. package/src/storage/thread.ts +141 -0
  185. package/src/task.ts +12 -10
  186. package/src/thread/__tests__/fixtures/mock-model.ts +2 -4
  187. package/src/thread/__tests__/integration.test.ts +13 -12
  188. package/src/thread/__tests__/namespace.test.ts +158 -0
  189. package/src/thread/__tests__/thread-persistence.test.ts +367 -0
  190. package/src/thread/__tests__/thread.test.ts +52 -54
  191. package/src/thread/thread.ts +247 -96
  192. package/src/thread/utils.ts +76 -13
  193. package/src/tool/__tests__/fixtures.ts +1 -1
  194. package/src/tool/__tests__/toolkit.test.ts +15 -12
  195. package/src/tool/tool.ts +3 -3
  196. package/src/types/kernl.ts +51 -0
  197. package/src/types/thread.ts +139 -25
  198. package/vitest.config.ts +1 -0
  199. package/dist/env.d.ts +0 -45
  200. package/dist/env.d.ts.map +0 -1
  201. package/dist/env.js +0 -31
  202. package/dist/error.d.ts +0 -1
  203. package/dist/error.d.ts.map +0 -1
  204. package/dist/kernel.d.ts +0 -7
  205. package/dist/kernel.d.ts.map +0 -1
  206. package/dist/kernel.js +0 -7
  207. package/dist/lib/serde/__tests__/codec.test.d.ts +0 -2
  208. package/dist/lib/serde/__tests__/codec.test.d.ts.map +0 -1
  209. package/dist/lib/serde/__tests__/codec.test.js +0 -75
  210. package/dist/lib/serde/codec.d.ts +0 -12
  211. package/dist/lib/serde/codec.d.ts.map +0 -1
  212. package/dist/lib/serde/codec.js +0 -54
  213. package/dist/lib/serde/thread.d.ts +0 -1
  214. package/dist/lib/serde/thread.d.ts.map +0 -1
  215. package/dist/lib/serde/thread.js +0 -172
  216. package/dist/lib/serde/tool.d.ts +0 -36
  217. package/dist/lib/serde/tool.d.ts.map +0 -1
  218. package/dist/lib/utils.d.ts +0 -19
  219. package/dist/lib/utils.d.ts.map +0 -1
  220. package/dist/lib/utils.js +0 -41
  221. package/dist/logger.d.ts +0 -36
  222. package/dist/logger.d.ts.map +0 -1
  223. package/dist/logger.js +0 -43
  224. package/dist/mcp/__tests__/fixtures/echo-server.d.ts +0 -3
  225. package/dist/mcp/__tests__/fixtures/echo-server.d.ts.map +0 -1
  226. package/dist/mcp/__tests__/fixtures/echo-server.js +0 -92
  227. package/dist/mcp/__tests__/fixtures/math-server.d.ts +0 -3
  228. package/dist/mcp/__tests__/fixtures/math-server.d.ts.map +0 -1
  229. package/dist/mcp/__tests__/fixtures/math-server.js +0 -98
  230. package/dist/mcp/__tests__/fixtures/test-server.d.ts +0 -3
  231. package/dist/mcp/__tests__/fixtures/test-server.d.ts.map +0 -1
  232. package/dist/mcp/__tests__/fixtures/test-server.js +0 -163
  233. package/dist/mcp/__tests__/test-utils.d.ts +0 -17
  234. package/dist/mcp/__tests__/test-utils.d.ts.map +0 -1
  235. package/dist/mcp/__tests__/test-utils.js +0 -42
  236. package/dist/mcp/node.d.ts +0 -60
  237. package/dist/mcp/node.d.ts.map +0 -1
  238. package/dist/mcp/node.js +0 -297
  239. package/dist/model.d.ts +0 -175
  240. package/dist/model.d.ts.map +0 -1
  241. package/dist/providers/ai.d.ts +0 -1
  242. package/dist/providers/ai.d.ts.map +0 -1
  243. package/dist/providers/ai.js +0 -1
  244. package/dist/providers/default.d.ts +0 -16
  245. package/dist/providers/default.d.ts.map +0 -1
  246. package/dist/providers/default.js +0 -17
  247. package/dist/providers/registry.d.ts +0 -1
  248. package/dist/providers/registry.d.ts.map +0 -1
  249. package/dist/providers/registry.js +0 -1
  250. package/dist/sched/scheduler.d.ts +0 -20
  251. package/dist/sched/scheduler.d.ts.map +0 -1
  252. package/dist/sched/task.d.ts +0 -92
  253. package/dist/sched/task.d.ts.map +0 -1
  254. package/dist/sched/task.js +0 -102
  255. package/dist/serde/__tests__/codec.test.d.ts +0 -2
  256. package/dist/serde/__tests__/codec.test.d.ts.map +0 -1
  257. package/dist/serde/__tests__/codec.test.js +0 -75
  258. package/dist/serde/codec.d.ts +0 -12
  259. package/dist/serde/codec.d.ts.map +0 -1
  260. package/dist/serde/codec.js +0 -54
  261. package/dist/serde/json.d.ts +0 -8
  262. package/dist/serde/json.d.ts.map +0 -1
  263. package/dist/serde/json.js +0 -13
  264. package/dist/serde/thread.d.ts +0 -687
  265. package/dist/serde/thread.d.ts.map +0 -1
  266. package/dist/serde/thread.js +0 -158
  267. package/dist/serde/tool.d.ts +0 -36
  268. package/dist/serde/tool.d.ts.map +0 -1
  269. package/dist/session.d.ts +0 -1
  270. package/dist/session.d.ts.map +0 -1
  271. package/dist/session.js +0 -1
  272. package/dist/thread/__tests__/stream.test.d.ts +0 -2
  273. package/dist/thread/__tests__/stream.test.d.ts.map +0 -1
  274. package/dist/thread/__tests__/stream.test.js +0 -244
  275. package/dist/tool/mcp.d.ts +0 -75
  276. package/dist/tool/mcp.d.ts.map +0 -1
  277. package/dist/tool/mcp.js +0 -111
  278. package/dist/tools.d.ts +0 -362
  279. package/dist/tools.d.ts.map +0 -1
  280. package/dist/tools.js +0 -220
  281. package/dist/types/proto.d.ts +0 -1551
  282. package/dist/types/proto.d.ts.map +0 -1
  283. package/dist/types/proto.js +0 -531
  284. package/dist/usage.d.ts +0 -43
  285. package/dist/usage.d.ts.map +0 -1
  286. package/dist/usage.js +0 -61
  287. package/src/lib/serde/thread.ts +0 -188
  288. /package/dist/{error.js → agent/index.js} +0 -0
  289. /package/dist/{lib/serde/tool.js → api/models/index.js} +0 -0
  290. /package/dist/{model.js → api/models/thread.js} +0 -0
  291. /package/dist/{sched/scheduler.js → api/resources/threads/types.js} +0 -0
  292. /package/dist/{serde/tool.js → types/kernl.js} +0 -0
package/dist/kernl.js CHANGED
@@ -1,26 +1,52 @@
1
- import { KernlHooks } from "./lifecycle";
1
+ import { KernlHooks } from "./lifecycle.js";
2
+ import { InMemoryStorage } from "./storage/index.js";
3
+ import { RThreads } from "./api/resources/threads/index.js";
2
4
  /**
3
- * The kernl - manages agent processes, scheduling, and task lifecycle
5
+ * The kernl - manages agent processes, scheduling, and task lifecycle.
4
6
  *
5
7
  * Orchestrates agent execution, including guardrails, tool calls, session persistence, and
6
8
  * tracing.
7
9
  */
8
10
  export class Kernl extends KernlHooks {
9
11
  agents = new Map();
10
- threads = new Map();
12
+ models = new Map();
13
+ storage;
14
+ athreads = new Map(); /* active threads */
15
+ initPromise = null;
16
+ // --- public API ---
17
+ threads; /* Threads resource */
18
+ constructor(options = {}) {
19
+ super();
20
+ this.storage = options.storage?.db ?? new InMemoryStorage();
21
+ this.storage.bind({ agents: this.agents, models: this.models });
22
+ this.threads = new RThreads(this.storage.threads);
23
+ }
11
24
  /**
12
25
  * Registers a new agent with the kernl instance.
13
26
  */
14
27
  register(agent) {
15
28
  this.agents.set(agent.id, agent);
16
29
  agent.bind(this);
30
+ // (TODO): implement exhaustive model registry in protocol/ package
31
+ //
32
+ // auto-populate model registry for storage hydration
33
+ const key = `${agent.model.provider}/${agent.model.modelId}`;
34
+ if (!this.models.has(key)) {
35
+ this.models.set(key, agent.model);
36
+ }
17
37
  }
18
38
  /**
19
39
  * Spawn a new thread - blocking execution
20
40
  */
21
41
  async spawn(thread) {
22
- this.threads.set(thread.id, thread);
23
- return await thread.execute();
42
+ await this.ensureInitialized();
43
+ this.athreads.set(thread.tid, thread);
44
+ try {
45
+ return await thread.execute();
46
+ }
47
+ finally {
48
+ this.athreads.delete(thread.tid);
49
+ }
24
50
  }
25
51
  /**
26
52
  * Schedule an existing thread - blocking execution
@@ -28,23 +54,60 @@ export class Kernl extends KernlHooks {
28
54
  * NOTE: just blocks for now
29
55
  */
30
56
  async schedule(thread) {
31
- return await thread.execute();
57
+ await this.ensureInitialized();
58
+ this.athreads.set(thread.tid, thread);
59
+ try {
60
+ return await thread.execute();
61
+ }
62
+ finally {
63
+ this.athreads.delete(thread.tid);
64
+ }
32
65
  }
33
66
  /**
34
- * (TMP) - probably won't make sense with assync scheduling contexts
67
+ * (TMP) - won't make sense in async scheduling contexts
35
68
  *
36
69
  * Spawn a new thread - streaming execution
37
70
  */
38
71
  async *spawnStream(thread) {
39
- this.threads.set(thread.id, thread);
40
- yield* thread.stream();
72
+ await this.ensureInitialized();
73
+ this.athreads.set(thread.tid, thread);
74
+ try {
75
+ yield* thread.stream();
76
+ }
77
+ finally {
78
+ this.athreads.delete(thread.tid);
79
+ }
41
80
  }
42
81
  /**
43
- * (TMP) - probably won't make sense with assync scheduling contexts
82
+ * (TMP) - won't make sense with async scheduling contexts
44
83
  *
45
84
  * Schedule an existing thread - streaming execution
46
85
  */
47
86
  async *scheduleStream(thread) {
48
- yield* thread.stream();
87
+ await this.ensureInitialized();
88
+ this.athreads.set(thread.tid, thread);
89
+ try {
90
+ yield* thread.stream();
91
+ }
92
+ finally {
93
+ this.athreads.delete(thread.tid);
94
+ }
95
+ }
96
+ /**
97
+ * Ensure the underlying storage backend has been initialized.
98
+ *
99
+ * This is called lazily on first use so that callers do not need to worry
100
+ * about calling storage.init() themselves. Safe and idempotent to call
101
+ * multiple times; concurrent calls share the same initialization promise.
102
+ */
103
+ async ensureInitialized() {
104
+ if (!this.initPromise) {
105
+ this.initPromise = this.storage.init().catch((error) => {
106
+ // allow a retry if initialization fails.
107
+ this.initPromise = null;
108
+ throw error;
109
+ });
110
+ }
111
+ await this.initPromise;
49
112
  }
50
113
  }
package/dist/lib/env.d.ts CHANGED
@@ -7,11 +7,11 @@ import { z } from "zod";
7
7
  */
8
8
  declare const envSchema: z.ZodObject<{
9
9
  LOG_LEVEL: z.ZodDefault<z.ZodEnum<{
10
- error: "error";
11
10
  trace: "trace";
12
11
  debug: "debug";
13
12
  info: "info";
14
13
  warn: "warn";
14
+ error: "error";
15
15
  fatal: "fatal";
16
16
  }>>;
17
17
  KERNL_LOG_MODEL_DATA: z.ZodPipe<z.ZodOptional<z.ZodEnum<{
@@ -27,11 +27,11 @@ declare const envSchema: z.ZodObject<{
27
27
  * Validated and type-safe environment variables
28
28
  *
29
29
  * @example
30
- * import { env } from '../env';
30
+ * import { env } from '@/env';
31
31
  * console.log(env.LOG_LEVEL);
32
32
  */
33
33
  export declare const env: {
34
- LOG_LEVEL: "error" | "trace" | "debug" | "info" | "warn" | "fatal";
34
+ LOG_LEVEL: "trace" | "debug" | "info" | "warn" | "error" | "fatal";
35
35
  KERNL_LOG_MODEL_DATA: boolean;
36
36
  KERNL_LOG_TOOL_DATA: boolean;
37
37
  };
package/dist/lib/env.js CHANGED
@@ -23,7 +23,7 @@ const envSchema = z.object({
23
23
  * Validated and type-safe environment variables
24
24
  *
25
25
  * @example
26
- * import { env } from '../env';
26
+ * import { env } from '@/env';
27
27
  * console.log(env.LOG_LEVEL);
28
28
  */
29
29
  export const env = envSchema.parse(process.env);
@@ -1,7 +1,7 @@
1
- import { InputGuardrailResult, OutputGuardrailMetadata, OutputGuardrailResult } from "../guardrail";
1
+ import { InputGuardrailResult, OutputGuardrailMetadata, OutputGuardrailResult } from "../guardrail.js";
2
2
  type SerializedThread = any;
3
- import { AgentResponseType } from "../types/agent";
4
- import { TextResponse } from "../types/thread";
3
+ import { AgentResponseType } from "../types/agent.js";
4
+ import { TextResponse } from "../types/thread.js";
5
5
  /**
6
6
  * Abstract base class for all `kernl` errors
7
7
  * Requires subclasses to implement JSON serialization
@@ -1,5 +1,5 @@
1
1
  import pino from "pino";
2
- import { env } from "./env";
2
+ import { env } from "./env.js";
3
3
  /**
4
4
  * By default we don't log LLM inputs/outputs, to prevent exposing sensitive data.
5
5
  * Set KERNL_LOG_MODEL_DATA=true to enable.
@@ -1,10 +1,10 @@
1
1
  import { EventEmitter } from "node:events";
2
- import { Agent } from "./agent";
3
- import { Context, UnknownContext } from "./context";
4
- import { Tool } from "./tool";
2
+ import { Agent } from "./agent.js";
3
+ import { Context, UnknownContext } from "./context.js";
4
+ import { Tool } from "./tool/index.js";
5
5
  import type { ToolCall } from "@kernl-sdk/protocol";
6
- import { AgentResponseType } from "./types/agent";
7
- import { TextResponse } from "./types/thread";
6
+ import { AgentResponseType } from "./types/agent.js";
7
+ import { TextResponse } from "./types/thread.js";
8
8
  export type EventEmitterEvents = Record<string, any[]>;
9
9
  /**
10
10
  * Generic typed event emitter that wraps Node's EventEmitter with type safety
@@ -1,6 +1,6 @@
1
1
  import { describe, it, expect, vi } from "vitest";
2
- import { BaseMCPServer } from "../base";
3
- import { logger } from "../../lib/logger";
2
+ import { BaseMCPServer } from "../base.js";
3
+ import { logger } from "../../lib/logger.js";
4
4
  // Create a minimal concrete implementation for testing
5
5
  class TestMCPServer extends BaseMCPServer {
6
6
  id;
@@ -1,4 +1,4 @@
1
- import { MCPServerStdio } from "../../stdio";
1
+ import { MCPServerStdio } from "../../stdio.js";
2
2
  /**
3
3
  * Helper to run a test with an MCP server, ensuring cleanup.
4
4
  */
@@ -1,4 +1,4 @@
1
- import { MCPServerStdio } from "../../stdio";
1
+ import { MCPServerStdio } from "../../stdio.js";
2
2
  /**
3
3
  * Helper to run a test with an MCP server, ensuring cleanup.
4
4
  */
@@ -1,14 +1,14 @@
1
1
  import { describe, it, expect, beforeEach, afterEach } from "vitest";
2
2
  import path from "path";
3
- import { MCPServerStdio } from "../stdio";
4
- import { MCPToolkit } from "../../tool/toolkit";
5
- import { FunctionToolkit } from "../../tool/toolkit";
6
- import { Agent } from "../../agent";
7
- import { Context } from "../../context";
8
- import { tool } from "../../tool";
3
+ import { MCPServerStdio } from "../stdio.js";
4
+ import { MCPToolkit } from "../../tool/toolkit.js";
5
+ import { FunctionToolkit } from "../../tool/toolkit.js";
6
+ import { Agent } from "../../agent.js";
7
+ import { Context } from "../../context.js";
8
+ import { tool } from "../../tool/index.js";
9
9
  import { z } from "zod";
10
- import { createMCPToolStaticFilter } from "../utils";
11
- import { createMockModel } from "../../thread/__tests__/fixtures/mock-model";
10
+ import { createMCPToolStaticFilter } from "../utils.js";
11
+ import { createMockModel } from "../../thread/__tests__/fixtures/mock-model.js";
12
12
  const TEST_SERVER = path.join(__dirname, "fixtures", "server.ts");
13
13
  // Mock model for tests that only need toolkit functionality
14
14
  const mockModel = createMockModel(async () => ({
@@ -139,7 +139,7 @@ describe("MCP Integration Tests", () => {
139
139
  model: mockModel,
140
140
  toolkits: [toolkit],
141
141
  });
142
- const context = new Context({});
142
+ const context = new Context("test-namespace", {});
143
143
  const tools = await toolkit.list(context);
144
144
  // Should have 3 math tools only
145
145
  expect(tools.length).toBe(3);
@@ -170,7 +170,7 @@ describe("MCP Integration Tests", () => {
170
170
  model: mockModel,
171
171
  toolkits: [toolkit],
172
172
  });
173
- const context = new Context({});
173
+ const context = new Context("test-namespace", {});
174
174
  const tools = await toolkit.list(context);
175
175
  // Should have only add and divide (multiply blocked by toolkit filter)
176
176
  expect(tools.length).toBe(2);
@@ -202,7 +202,7 @@ describe("MCP Integration Tests", () => {
202
202
  model: mockModel,
203
203
  toolkits: [toolkit],
204
204
  });
205
- const context = new Context({ userId: "test-user" });
205
+ const context = new Context("test-namespace", { userId: "test-user" });
206
206
  await toolkit.list(context);
207
207
  // Verify context was passed correctly
208
208
  expect(receivedContext).toBeDefined();
@@ -230,7 +230,7 @@ describe("MCP Integration Tests", () => {
230
230
  model: mockModel,
231
231
  toolkits: [mcpToolkit],
232
232
  });
233
- const context = new Context({});
233
+ const context = new Context("test-namespace", {});
234
234
  const tools = await agent.tools(context);
235
235
  expect(tools.length).toBe(6);
236
236
  expect(tools.find((t) => t.id === "add")).toBeDefined();
@@ -255,7 +255,7 @@ describe("MCP Integration Tests", () => {
255
255
  toolkits: [mcpToolkit],
256
256
  });
257
257
  // Populate toolkit cache
258
- const context = new Context({});
258
+ const context = new Context("test-namespace", {});
259
259
  await agent.tools(context);
260
260
  // Now get specific tool
261
261
  const addTool = agent.tool("add");
@@ -280,7 +280,7 @@ describe("MCP Integration Tests", () => {
280
280
  model: mockModel,
281
281
  toolkits: [mcpToolkit],
282
282
  });
283
- const context = new Context({});
283
+ const context = new Context("test-namespace", {});
284
284
  await agent.tools(context);
285
285
  const addTool = agent.tool("add");
286
286
  expect(addTool).toBeDefined();
@@ -325,7 +325,7 @@ describe("MCP Integration Tests", () => {
325
325
  model: mockModel,
326
326
  toolkits: [mcpToolkit, functionToolkit],
327
327
  });
328
- const context = new Context({});
328
+ const context = new Context("test-namespace", {});
329
329
  const tools = await agent.tools(context);
330
330
  // Should have 7 tools (6 MCP + 1 local)
331
331
  expect(tools.length).toBe(7);
@@ -367,7 +367,7 @@ describe("MCP Integration Tests", () => {
367
367
  model: mockModel,
368
368
  toolkits: [mcpToolkit, functionToolkit],
369
369
  });
370
- const context = new Context({});
370
+ const context = new Context("test-namespace", {});
371
371
  // Should throw error about duplicate tool IDs
372
372
  await expect(agent.tools(context)).rejects.toThrow(/Duplicate tool IDs found/);
373
373
  await mcpToolkit.destroy();
@@ -1,6 +1,6 @@
1
1
  import { describe, it, expect } from "vitest";
2
- import { MCPServerStdio } from "../stdio";
3
- import { withMCPServer, createMCPServer } from "./fixtures/utils";
2
+ import { MCPServerStdio } from "../stdio.js";
3
+ import { withMCPServer, createMCPServer } from "./fixtures/utils.js";
4
4
  import path from "path";
5
5
  const TEST_SERVER = path.join(__dirname, "fixtures", "server.ts");
6
6
  describe("MCPServerStdio", () => {
@@ -1,6 +1,6 @@
1
1
  import { describe, it, expect, vi } from "vitest";
2
- import { mcpToFunctionTool, createMCPToolStaticFilter } from "../utils";
3
- import { Context } from "../../context";
2
+ import { mcpToFunctionTool, createMCPToolStaticFilter } from "../utils.js";
3
+ import { Context } from "../../context.js";
4
4
  describe("mcpToFunctionTool", () => {
5
5
  // Create a mock MCP server
6
6
  const createMockServer = () => ({
@@ -79,7 +79,7 @@ describe("mcpToFunctionTool", () => {
79
79
  },
80
80
  };
81
81
  const functionTool = mcpToFunctionTool(server, mcpTool);
82
- const ctx = new Context({});
82
+ const ctx = new Context("test-namespace", {});
83
83
  const input = { arg1: "value1" };
84
84
  await functionTool.invoke(ctx, JSON.stringify(input));
85
85
  expect(server.callTool).toHaveBeenCalledWith("test_tool", input);
@@ -98,7 +98,7 @@ describe("mcpToFunctionTool", () => {
98
98
  },
99
99
  };
100
100
  const functionTool = mcpToFunctionTool(server, mcpTool);
101
- const ctx = new Context({});
101
+ const ctx = new Context("test-namespace", {});
102
102
  const toolResult = await functionTool.invoke(ctx, JSON.stringify({}));
103
103
  expect(toolResult.state).toBe("completed");
104
104
  expect(toolResult.result).toEqual({ type: "text", text: "single result" });
@@ -119,7 +119,7 @@ describe("mcpToFunctionTool", () => {
119
119
  },
120
120
  };
121
121
  const functionTool = mcpToFunctionTool(server, mcpTool);
122
- const ctx = new Context({});
122
+ const ctx = new Context("test-namespace", {});
123
123
  const toolResult = await functionTool.invoke(ctx, JSON.stringify({}));
124
124
  expect(toolResult.state).toBe("completed");
125
125
  expect(toolResult.result).toEqual(multipleItems);
@@ -141,7 +141,7 @@ describe("mcpToFunctionTool", () => {
141
141
  };
142
142
  const functionTool1 = mcpToFunctionTool(server, tool1);
143
143
  const functionTool2 = mcpToFunctionTool(server, tool2);
144
- const ctx = new Context({});
144
+ const ctx = new Context("test-namespace", {});
145
145
  await functionTool1.invoke(ctx, JSON.stringify({}));
146
146
  expect(server.callTool).toHaveBeenCalledWith("tool1", {});
147
147
  await functionTool2.invoke(ctx, JSON.stringify({}));
@@ -163,7 +163,7 @@ describe("mcpToFunctionTool", () => {
163
163
  };
164
164
  const functionTool = mcpToFunctionTool(server, mcpTool);
165
165
  // Invoke takes (context, params as JSON string) in that order
166
- const ctx = new Context({});
166
+ const ctx = new Context("test-namespace", {});
167
167
  const params = { foo: "bar" };
168
168
  await functionTool.invoke(ctx, JSON.stringify(params));
169
169
  // Verify the tool was called with the params (not the context)
@@ -173,7 +173,7 @@ describe("mcpToFunctionTool", () => {
173
173
  describe("createMCPToolStaticFilter", () => {
174
174
  // Helper to create mock filter context
175
175
  const createMockFilterContext = () => ({
176
- context: new Context({}),
176
+ context: new Context("test-namespace", {}),
177
177
  agent: {},
178
178
  serverId: "test-server",
179
179
  });
@@ -1,5 +1,5 @@
1
- import { Logger } from "../lib/logger";
2
- import { MCPTool, MCPToolFilter, CallToolResultContent } from "./types";
1
+ import { Logger } from "../lib/logger.js";
2
+ import { MCPTool, MCPToolFilter, CallToolResultContent } from "./types.js";
3
3
  export declare const DEFAULT_STDIO_MCP_CLIENT_LOGGER_NAME = "kernl:stdio-mcp-client";
4
4
  export declare const DEFAULT_SSE_MCP_CLIENT_LOGGER_NAME = "kernl:sse-mcp-client";
5
5
  export declare const DEFAULT_STREAMABLE_HTTP_MCP_CLIENT_LOGGER_NAME = "kernl:streamable-http-mcp-client";
@@ -1,6 +1,6 @@
1
1
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
- import { BaseMCPServer } from "./base";
3
- import type { MCPTool, CallToolResultContent, MCPServerStreamableHttpOptions, InitializeResult } from "./types";
2
+ import { BaseMCPServer } from "./base.js";
3
+ import type { MCPTool, CallToolResultContent, MCPServerStreamableHttpOptions, InitializeResult } from "./types.js";
4
4
  /**
5
5
  * MCP server client that communicates over streamable HTTP protocol.
6
6
  */
@@ -9,7 +9,7 @@ export declare class MCPServerStreamableHttp extends BaseMCPServer {
9
9
  protected session: Client | null;
10
10
  protected timeout: number;
11
11
  protected serverInitializeResult: InitializeResult | null;
12
- params: MCPServerStreamableHttpOptions;
12
+ options: MCPServerStreamableHttpOptions;
13
13
  private transport;
14
14
  constructor(options: MCPServerStreamableHttpOptions);
15
15
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/mcp/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAUnE,OAAO,EACL,aAAa,EAEd,MAAM,QAAQ,CAAC;AAChB,OAAO,KAAK,EACV,OAAO,EACP,qBAAqB,EACrB,8BAA8B,EAC9B,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,aAAa;IACxD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAQ;IACxC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,sBAAsB,EAAE,gBAAgB,GAAG,IAAI,CAAQ;IAEjE,MAAM,EAAE,8BAA8B,CAAC;IACvC,OAAO,CAAC,SAAS,CAAa;gBAElB,OAAO,EAAE,8BAA8B;IAcnD;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAgC9B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAW5B;;;;OAIG;cACa,UAAU,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAYhD;;OAEG;IACG,QAAQ,CACZ,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GACnC,OAAO,CAAC,qBAAqB,CAAC;CA2BlC"}
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/mcp/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAUnE,OAAO,EACL,aAAa,EAEd,MAAM,QAAQ,CAAC;AAChB,OAAO,KAAK,EACV,OAAO,EACP,qBAAqB,EACrB,8BAA8B,EAC9B,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,aAAa;IACxD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAQ;IACxC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,sBAAsB,EAAE,gBAAgB,GAAG,IAAI,CAAQ;IAEjE,OAAO,EAAE,8BAA8B,CAAC;IACxC,OAAO,CAAC,SAAS,CAAa;gBAElB,OAAO,EAAE,8BAA8B;IAcnD;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAgC9B;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAW5B;;;;OAIG;cACa,UAAU,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAYhD;;OAEG;IACG,QAAQ,CACZ,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GACnC,OAAO,CAAC,qBAAqB,CAAC;CA2BlC"}
package/dist/mcp/http.js CHANGED
@@ -2,8 +2,8 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
2
  import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
3
3
  import { DEFAULT_REQUEST_TIMEOUT_MSEC } from "@modelcontextprotocol/sdk/shared/protocol.js";
4
4
  import { ListToolsResultSchema, CallToolResultSchema, } from "@modelcontextprotocol/sdk/types.js";
5
- import { getLogger } from "../lib/logger";
6
- import { BaseMCPServer, DEFAULT_STREAMABLE_HTTP_MCP_CLIENT_LOGGER_NAME, } from "./base";
5
+ import { getLogger } from "../lib/logger.js";
6
+ import { BaseMCPServer, DEFAULT_STREAMABLE_HTTP_MCP_CLIENT_LOGGER_NAME, } from "./base.js";
7
7
  /**
8
8
  * MCP server client that communicates over streamable HTTP protocol.
9
9
  */
@@ -12,7 +12,7 @@ export class MCPServerStreamableHttp extends BaseMCPServer {
12
12
  session = null;
13
13
  timeout;
14
14
  serverInitializeResult = null;
15
- params;
15
+ options;
16
16
  transport = null;
17
17
  constructor(options) {
18
18
  super({
@@ -21,8 +21,8 @@ export class MCPServerStreamableHttp extends BaseMCPServer {
21
21
  logger: options.logger ??
22
22
  getLogger(DEFAULT_STREAMABLE_HTTP_MCP_CLIENT_LOGGER_NAME),
23
23
  });
24
- this.params = options;
25
- this.id = options.id || `streamable-http: ${this.params.url}`;
24
+ this.options = options;
25
+ this.id = options.id || `streamable-http: ${this.options.url}`;
26
26
  this.timeout = options.timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC;
27
27
  }
28
28
  /**
@@ -30,12 +30,12 @@ export class MCPServerStreamableHttp extends BaseMCPServer {
30
30
  */
31
31
  async connect() {
32
32
  try {
33
- this.transport = new StreamableHTTPClientTransport(new URL(this.params.url), {
34
- authProvider: this.params.authProvider,
35
- requestInit: this.params.requestInit,
36
- fetch: this.params.fetch,
37
- reconnectionOptions: this.params.reconnectionOptions,
38
- sessionId: this.params.sessionId,
33
+ this.transport = new StreamableHTTPClientTransport(new URL(this.options.url), {
34
+ authProvider: this.options.authProvider,
35
+ requestInit: this.options.requestInit,
36
+ fetch: this.options.fetch,
37
+ reconnectionOptions: this.options.reconnectionOptions,
38
+ sessionId: this.options.sessionId,
39
39
  });
40
40
  this.session = new Client({
41
41
  name: this.id,
package/dist/mcp/sse.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
- import { BaseMCPServer } from "./base";
3
- import type { MCPTool, CallToolResultContent, MCPServerSSEOptions, InitializeResult } from "./types";
2
+ import { BaseMCPServer } from "./base.js";
3
+ import type { MCPTool, CallToolResultContent, MCPServerSSEOptions, InitializeResult } from "./types.js";
4
4
  /**
5
5
  * MCP server client that communicates over Server-Sent Events (SSE).
6
6
  */
@@ -9,7 +9,7 @@ export declare class MCPServerSSE extends BaseMCPServer {
9
9
  protected session: Client | null;
10
10
  protected timeout: number;
11
11
  protected serverInitializeResult: InitializeResult | null;
12
- params: MCPServerSSEOptions;
12
+ options: MCPServerSSEOptions;
13
13
  private transport;
14
14
  constructor(options: MCPServerSSEOptions);
15
15
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../src/mcp/sse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAUnE,OAAO,EAAE,aAAa,EAAsC,MAAM,QAAQ,CAAC;AAC3E,OAAO,KAAK,EACV,OAAO,EACP,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,qBAAa,YAAa,SAAQ,aAAa;IAC7C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAQ;IACxC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,sBAAsB,EAAE,gBAAgB,GAAG,IAAI,CAAQ;IAEjE,MAAM,EAAE,mBAAmB,CAAC;IAC5B,OAAO,CAAC,SAAS,CAAa;gBAElB,OAAO,EAAE,mBAAmB;IAYxC;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA2B9B;;;;OAIG;cACa,UAAU,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAYhD;;OAEG;IACG,QAAQ,CACZ,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GACnC,OAAO,CAAC,qBAAqB,CAAC;IA4BjC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAU7B"}
1
+ {"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../src/mcp/sse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAUnE,OAAO,EAAE,aAAa,EAAsC,MAAM,QAAQ,CAAC;AAC3E,OAAO,KAAK,EACV,OAAO,EACP,qBAAqB,EACrB,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,qBAAa,YAAa,SAAQ,aAAa;IAC7C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAQ;IACxC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,sBAAsB,EAAE,gBAAgB,GAAG,IAAI,CAAQ;IAEjE,OAAO,EAAE,mBAAmB,CAAC;IAC7B,OAAO,CAAC,SAAS,CAAa;gBAElB,OAAO,EAAE,mBAAmB;IAYxC;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA2B9B;;;;OAIG;cACa,UAAU,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAYhD;;OAEG;IACG,QAAQ,CACZ,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GACnC,OAAO,CAAC,qBAAqB,CAAC;IA4BjC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAU7B"}
package/dist/mcp/sse.js CHANGED
@@ -2,8 +2,8 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
2
  import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
3
3
  import { DEFAULT_REQUEST_TIMEOUT_MSEC } from "@modelcontextprotocol/sdk/shared/protocol.js";
4
4
  import { ListToolsResultSchema, CallToolResultSchema, } from "@modelcontextprotocol/sdk/types.js";
5
- import { getLogger } from "../lib/logger";
6
- import { BaseMCPServer, DEFAULT_SSE_MCP_CLIENT_LOGGER_NAME } from "./base";
5
+ import { getLogger } from "../lib/logger.js";
6
+ import { BaseMCPServer, DEFAULT_SSE_MCP_CLIENT_LOGGER_NAME } from "./base.js";
7
7
  /**
8
8
  * MCP server client that communicates over Server-Sent Events (SSE).
9
9
  */
@@ -12,7 +12,7 @@ export class MCPServerSSE extends BaseMCPServer {
12
12
  session = null;
13
13
  timeout;
14
14
  serverInitializeResult = null;
15
- params;
15
+ options;
16
16
  transport = null;
17
17
  constructor(options) {
18
18
  super({
@@ -20,8 +20,8 @@ export class MCPServerSSE extends BaseMCPServer {
20
20
  toolFilter: options.toolFilter,
21
21
  logger: options.logger ?? getLogger(DEFAULT_SSE_MCP_CLIENT_LOGGER_NAME),
22
22
  });
23
- this.params = options;
24
- this.id = options.id || `sse: ${this.params.url}`;
23
+ this.options = options;
24
+ this.id = options.id || `sse: ${this.options.url}`;
25
25
  this.timeout = options.timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC;
26
26
  }
27
27
  /**
@@ -29,10 +29,10 @@ export class MCPServerSSE extends BaseMCPServer {
29
29
  */
30
30
  async connect() {
31
31
  try {
32
- this.transport = new SSEClientTransport(new URL(this.params.url), {
33
- authProvider: this.params.authProvider,
34
- requestInit: this.params.requestInit,
35
- eventSourceInit: this.params.eventSourceInit,
32
+ this.transport = new SSEClientTransport(new URL(this.options.url), {
33
+ authProvider: this.options.authProvider,
34
+ requestInit: this.options.requestInit,
35
+ eventSourceInit: this.options.eventSourceInit,
36
36
  });
37
37
  this.session = new Client({
38
38
  name: this.id,
@@ -1,6 +1,6 @@
1
1
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
- import { BaseMCPServer } from "./base";
3
- import type { MCPTool, CallToolResultContent, MCPServerStdioOptions, InitializeResult } from "./types";
2
+ import { BaseMCPServer } from "./base.js";
3
+ import type { MCPTool, CallToolResultContent, MCPServerStdioOptions, InitializeResult } from "./types.js";
4
4
  /**
5
5
  * MCP server client that communicates over stdio (standard input/output).
6
6
  */
package/dist/mcp/stdio.js CHANGED
@@ -2,8 +2,8 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2
2
  import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
3
3
  import { DEFAULT_REQUEST_TIMEOUT_MSEC } from "@modelcontextprotocol/sdk/shared/protocol.js";
4
4
  import { ListToolsResultSchema, CallToolResultSchema, } from "@modelcontextprotocol/sdk/types.js";
5
- import { getLogger } from "../lib/logger";
6
- import { BaseMCPServer, DEFAULT_STDIO_MCP_CLIENT_LOGGER_NAME } from "./base";
5
+ import { getLogger } from "../lib/logger.js";
6
+ import { BaseMCPServer, DEFAULT_STDIO_MCP_CLIENT_LOGGER_NAME } from "./base.js";
7
7
  /**
8
8
  * MCP server client that communicates over stdio (standard input/output).
9
9
  */
@@ -1,8 +1,8 @@
1
1
  import { z } from "zod";
2
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";
3
+ import { Agent } from "../agent.js";
4
+ import { Context, UnknownContext } from "../context.js";
5
+ import { Logger } from "../lib/logger.js";
6
6
  /**
7
7
  * MCP tool type from the SDK.
8
8
  * We use the SDK's type directly to avoid compatibility issues.
@@ -1,11 +1,11 @@
1
1
  import { z } from "zod";
2
- import { UnknownContext } from "../context";
3
- import { MCPServer } from "./base";
4
- import type { MCPTool, MCPToolFilter } from "./types";
2
+ import { UnknownContext } from "../context.js";
3
+ import { MCPServer } from "./base.js";
4
+ import type { MCPTool, MCPToolFilter } from "./types.js";
5
5
  /**
6
6
  * Converts an MCP tool definition into a function tool usable by the SDK.
7
7
  */
8
- export declare function mcpToFunctionTool(server: MCPServer, mcpTool: MCPTool): import("../tool").FunctionTool<unknown, z.ZodRecord<z.ZodString, z.ZodAny> | undefined, {
8
+ export declare function mcpToFunctionTool(server: MCPServer, mcpTool: MCPTool): import("../tool/index.js").FunctionTool<unknown, z.ZodObject<{}, z.core.$strip>, {
9
9
  type: string;
10
10
  text: string;
11
11
  } | {
@@ -1 +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"}
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;;;;;;KAoBpE;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"}
package/dist/mcp/utils.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { tool } from "../tool";
2
+ import { tool } from "../tool/index.js";
3
3
  /**
4
4
  * Converts an MCP tool definition into a function tool usable by the SDK.
5
5
  */
@@ -8,11 +8,10 @@ export function mcpToFunctionTool(server, mcpTool) {
8
8
  const content = await server.callTool(mcpTool.name, input);
9
9
  return content.length === 1 ? content[0] : content;
10
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;
11
+ const hasProperties = mcpTool.inputSchema &&
12
+ Object.keys(mcpTool.inputSchema.properties || {}).length > 0;
13
+ // If tool has properties, use passthrough to accept any object, else empty object (matches AI SDK)
14
+ const parameters = hasProperties ? z.object({}).passthrough() : z.object({});
16
15
  return tool({
17
16
  id: mcpTool.name,
18
17
  name: mcpTool.name,
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=in-memory.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory.test.d.ts","sourceRoot":"","sources":["../../../src/storage/__tests__/in-memory.test.ts"],"names":[],"mappings":""}