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.
- package/.turbo/turbo-build.log +5 -4
- package/.turbo/turbo-check-types.log +4 -0
- package/CHANGELOG.md +147 -0
- package/LICENSE +1 -1
- package/dist/agent/__tests__/concurrency.test.d.ts +2 -0
- package/dist/agent/__tests__/concurrency.test.d.ts.map +1 -0
- package/dist/agent/__tests__/concurrency.test.js +152 -0
- package/dist/agent/__tests__/run.test.d.ts +2 -0
- package/dist/agent/__tests__/run.test.d.ts.map +1 -0
- package/dist/agent/__tests__/run.test.js +357 -0
- package/dist/agent/index.d.ts +1 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent.d.ts +35 -12
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +102 -15
- package/dist/api/__tests__/cursor-page.test.d.ts +2 -0
- package/dist/api/__tests__/cursor-page.test.d.ts.map +1 -0
- package/dist/api/__tests__/cursor-page.test.js +414 -0
- package/dist/api/__tests__/offset-page.test.d.ts +2 -0
- package/dist/api/__tests__/offset-page.test.d.ts.map +1 -0
- package/dist/api/__tests__/offset-page.test.js +510 -0
- package/dist/api/__tests__/threads.test.d.ts +2 -0
- package/dist/api/__tests__/threads.test.d.ts.map +1 -0
- package/dist/api/__tests__/threads.test.js +338 -0
- package/dist/api/models/index.d.ts +2 -0
- package/dist/api/models/index.d.ts.map +1 -0
- package/dist/api/models/thread.d.ts +120 -0
- package/dist/api/models/thread.d.ts.map +1 -0
- package/dist/api/pagination/base.d.ts +48 -0
- package/dist/api/pagination/base.d.ts.map +1 -0
- package/dist/api/pagination/base.js +45 -0
- package/dist/api/pagination/cursor.d.ts +44 -0
- package/dist/api/pagination/cursor.d.ts.map +1 -0
- package/dist/api/pagination/cursor.js +52 -0
- package/dist/api/pagination/offset.d.ts +42 -0
- package/dist/api/pagination/offset.d.ts.map +1 -0
- package/dist/api/pagination/offset.js +55 -0
- package/dist/api/resources/threads/events.d.ts +21 -0
- package/dist/api/resources/threads/events.d.ts.map +1 -0
- package/dist/api/resources/threads/events.js +24 -0
- package/dist/api/resources/threads/index.d.ts +4 -0
- package/dist/api/resources/threads/index.d.ts.map +1 -0
- package/dist/api/resources/threads/index.js +2 -0
- package/dist/api/resources/threads/threads.d.ts +57 -0
- package/dist/api/resources/threads/threads.d.ts.map +1 -0
- package/dist/api/resources/threads/threads.js +199 -0
- package/dist/api/resources/threads/types.d.ts +123 -0
- package/dist/api/resources/threads/types.d.ts.map +1 -0
- package/dist/api/resources/threads/utils.d.ts +18 -0
- package/dist/api/resources/threads/utils.d.ts.map +1 -0
- package/dist/api/resources/threads/utils.js +78 -0
- package/dist/context.d.ts +5 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +6 -1
- package/dist/guardrail.d.ts +4 -4
- package/dist/index.d.ts +12 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -3
- package/dist/internal.d.ts +4 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +2 -0
- package/dist/kernl/index.d.ts +3 -0
- package/dist/kernl/index.d.ts.map +1 -0
- package/dist/kernl/index.js +2 -0
- package/dist/kernl/kernl.d.ts +64 -0
- package/dist/kernl/kernl.d.ts.map +1 -0
- package/dist/kernl/kernl.js +116 -0
- package/dist/kernl/threads.d.ts +110 -0
- package/dist/kernl/threads.d.ts.map +1 -0
- package/dist/kernl/threads.js +126 -0
- package/dist/kernl.d.ts +27 -11
- package/dist/kernl.d.ts.map +1 -1
- package/dist/kernl.js +74 -11
- package/dist/lib/env.d.ts +3 -3
- package/dist/lib/env.js +1 -1
- package/dist/lib/error.d.ts +3 -3
- package/dist/lib/logger.js +1 -1
- package/dist/lifecycle.d.ts +5 -5
- package/dist/mcp/__tests__/base.test.js +2 -2
- package/dist/mcp/__tests__/fixtures/utils.d.ts +1 -1
- package/dist/mcp/__tests__/fixtures/utils.js +1 -1
- package/dist/mcp/__tests__/integration.test.js +16 -16
- package/dist/mcp/__tests__/stdio.test.js +2 -2
- package/dist/mcp/__tests__/utils.test.js +8 -8
- package/dist/mcp/base.d.ts +2 -2
- package/dist/mcp/http.d.ts +3 -3
- package/dist/mcp/http.d.ts.map +1 -1
- package/dist/mcp/http.js +11 -11
- package/dist/mcp/sse.d.ts +3 -3
- package/dist/mcp/sse.d.ts.map +1 -1
- package/dist/mcp/sse.js +9 -9
- package/dist/mcp/stdio.d.ts +2 -2
- package/dist/mcp/stdio.js +2 -2
- package/dist/mcp/types.d.ts +3 -3
- package/dist/mcp/utils.d.ts +4 -4
- package/dist/mcp/utils.d.ts.map +1 -1
- package/dist/mcp/utils.js +5 -6
- package/dist/storage/__tests__/in-memory.test.d.ts +2 -0
- package/dist/storage/__tests__/in-memory.test.d.ts.map +1 -0
- package/dist/storage/__tests__/in-memory.test.js +455 -0
- package/dist/storage/base.d.ts +64 -0
- package/dist/storage/base.d.ts.map +1 -0
- package/dist/storage/base.js +4 -0
- package/dist/storage/in-memory.d.ts +62 -0
- package/dist/storage/in-memory.d.ts.map +1 -0
- package/dist/storage/in-memory.js +283 -0
- package/dist/storage/index.d.ts +10 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +7 -0
- package/dist/storage/thread.d.ts +123 -0
- package/dist/storage/thread.d.ts.map +1 -0
- package/dist/storage/thread.js +4 -0
- package/dist/task.d.ts +8 -6
- package/dist/task.d.ts.map +1 -1
- package/dist/task.js +10 -8
- package/dist/thread/__tests__/fixtures/mock-model.d.ts +1 -2
- package/dist/thread/__tests__/fixtures/mock-model.d.ts.map +1 -1
- package/dist/thread/__tests__/integration.test.js +10 -10
- package/dist/thread/__tests__/mock.d.ts +1 -1
- package/dist/thread/__tests__/namespace.test.d.ts +2 -0
- package/dist/thread/__tests__/namespace.test.d.ts.map +1 -0
- package/dist/thread/__tests__/namespace.test.js +131 -0
- package/dist/thread/__tests__/thread-persistence.test.d.ts +2 -0
- package/dist/thread/__tests__/thread-persistence.test.d.ts.map +1 -0
- package/dist/thread/__tests__/thread-persistence.test.js +351 -0
- package/dist/thread/__tests__/thread.test.js +55 -57
- package/dist/thread/index.d.ts +1 -1
- package/dist/thread/index.js +1 -1
- package/dist/thread/thread.d.ts +74 -22
- package/dist/thread/thread.d.ts.map +1 -1
- package/dist/thread/thread.js +212 -74
- package/dist/thread/utils.d.ts +38 -10
- package/dist/thread/utils.d.ts.map +1 -1
- package/dist/thread/utils.js +53 -9
- package/dist/tool/__tests__/fixtures.d.ts +8 -8
- package/dist/tool/__tests__/fixtures.js +3 -3
- package/dist/tool/__tests__/tool.test.js +2 -2
- package/dist/tool/__tests__/toolkit.test.js +17 -14
- package/dist/tool/index.d.ts +3 -3
- package/dist/tool/index.js +2 -2
- package/dist/tool/tool.d.ts +2 -2
- package/dist/tool/tool.js +5 -5
- package/dist/tool/toolkit.d.ts +4 -4
- package/dist/tool/toolkit.js +1 -1
- package/dist/tool/types.d.ts +4 -4
- package/dist/trace/traces.js +2 -2
- package/dist/types/agent.d.ts +4 -4
- package/dist/types/kernl.d.ts +42 -0
- package/dist/types/kernl.d.ts.map +1 -0
- package/dist/types/thread.d.ts +110 -24
- package/dist/types/thread.d.ts.map +1 -1
- package/dist/types/thread.js +12 -0
- package/package.json +12 -8
- package/src/agent/__tests__/concurrency.test.ts +194 -0
- package/src/agent/__tests__/run.test.ts +441 -0
- package/src/agent/index.ts +0 -0
- package/src/agent.ts +139 -24
- package/src/api/__tests__/cursor-page.test.ts +512 -0
- package/src/api/__tests__/offset-page.test.ts +624 -0
- package/src/api/__tests__/threads.test.ts +415 -0
- package/src/api/models/index.ts +6 -0
- package/src/api/models/thread.ts +138 -0
- package/src/api/pagination/base.ts +79 -0
- package/src/api/pagination/cursor.ts +86 -0
- package/src/api/pagination/offset.ts +89 -0
- package/src/api/resources/threads/events.ts +26 -0
- package/src/api/resources/threads/index.ts +9 -0
- package/src/api/resources/threads/threads.ts +256 -0
- package/src/api/resources/threads/types.ts +143 -0
- package/src/api/resources/threads/utils.ts +104 -0
- package/src/context.ts +10 -1
- package/src/index.ts +49 -1
- package/src/internal.ts +15 -0
- package/src/kernl.ts +86 -17
- package/src/mcp/__tests__/integration.test.ts +8 -9
- package/src/mcp/__tests__/utils.test.ts +6 -6
- package/src/mcp/http.ts +9 -9
- package/src/mcp/sse.ts +7 -7
- package/src/mcp/utils.ts +6 -5
- package/src/storage/__tests__/in-memory.test.ts +534 -0
- package/src/storage/base.ts +77 -0
- package/src/storage/in-memory.ts +372 -0
- package/src/storage/index.ts +21 -0
- package/src/storage/thread.ts +141 -0
- package/src/task.ts +12 -10
- package/src/thread/__tests__/fixtures/mock-model.ts +2 -4
- package/src/thread/__tests__/integration.test.ts +13 -12
- package/src/thread/__tests__/namespace.test.ts +158 -0
- package/src/thread/__tests__/thread-persistence.test.ts +367 -0
- package/src/thread/__tests__/thread.test.ts +52 -54
- package/src/thread/thread.ts +247 -96
- package/src/thread/utils.ts +76 -13
- package/src/tool/__tests__/fixtures.ts +1 -1
- package/src/tool/__tests__/toolkit.test.ts +15 -12
- package/src/tool/tool.ts +3 -3
- package/src/types/kernl.ts +51 -0
- package/src/types/thread.ts +139 -25
- package/vitest.config.ts +1 -0
- package/dist/env.d.ts +0 -45
- package/dist/env.d.ts.map +0 -1
- package/dist/env.js +0 -31
- package/dist/error.d.ts +0 -1
- package/dist/error.d.ts.map +0 -1
- package/dist/kernel.d.ts +0 -7
- package/dist/kernel.d.ts.map +0 -1
- package/dist/kernel.js +0 -7
- package/dist/lib/serde/__tests__/codec.test.d.ts +0 -2
- package/dist/lib/serde/__tests__/codec.test.d.ts.map +0 -1
- package/dist/lib/serde/__tests__/codec.test.js +0 -75
- package/dist/lib/serde/codec.d.ts +0 -12
- package/dist/lib/serde/codec.d.ts.map +0 -1
- package/dist/lib/serde/codec.js +0 -54
- package/dist/lib/serde/thread.d.ts +0 -1
- package/dist/lib/serde/thread.d.ts.map +0 -1
- package/dist/lib/serde/thread.js +0 -172
- package/dist/lib/serde/tool.d.ts +0 -36
- package/dist/lib/serde/tool.d.ts.map +0 -1
- package/dist/lib/utils.d.ts +0 -19
- package/dist/lib/utils.d.ts.map +0 -1
- package/dist/lib/utils.js +0 -41
- package/dist/logger.d.ts +0 -36
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -43
- package/dist/mcp/__tests__/fixtures/echo-server.d.ts +0 -3
- package/dist/mcp/__tests__/fixtures/echo-server.d.ts.map +0 -1
- package/dist/mcp/__tests__/fixtures/echo-server.js +0 -92
- package/dist/mcp/__tests__/fixtures/math-server.d.ts +0 -3
- package/dist/mcp/__tests__/fixtures/math-server.d.ts.map +0 -1
- package/dist/mcp/__tests__/fixtures/math-server.js +0 -98
- package/dist/mcp/__tests__/fixtures/test-server.d.ts +0 -3
- package/dist/mcp/__tests__/fixtures/test-server.d.ts.map +0 -1
- package/dist/mcp/__tests__/fixtures/test-server.js +0 -163
- package/dist/mcp/__tests__/test-utils.d.ts +0 -17
- package/dist/mcp/__tests__/test-utils.d.ts.map +0 -1
- package/dist/mcp/__tests__/test-utils.js +0 -42
- package/dist/mcp/node.d.ts +0 -60
- package/dist/mcp/node.d.ts.map +0 -1
- package/dist/mcp/node.js +0 -297
- package/dist/model.d.ts +0 -175
- package/dist/model.d.ts.map +0 -1
- package/dist/providers/ai.d.ts +0 -1
- package/dist/providers/ai.d.ts.map +0 -1
- package/dist/providers/ai.js +0 -1
- package/dist/providers/default.d.ts +0 -16
- package/dist/providers/default.d.ts.map +0 -1
- package/dist/providers/default.js +0 -17
- package/dist/providers/registry.d.ts +0 -1
- package/dist/providers/registry.d.ts.map +0 -1
- package/dist/providers/registry.js +0 -1
- package/dist/sched/scheduler.d.ts +0 -20
- package/dist/sched/scheduler.d.ts.map +0 -1
- package/dist/sched/task.d.ts +0 -92
- package/dist/sched/task.d.ts.map +0 -1
- package/dist/sched/task.js +0 -102
- package/dist/serde/__tests__/codec.test.d.ts +0 -2
- package/dist/serde/__tests__/codec.test.d.ts.map +0 -1
- package/dist/serde/__tests__/codec.test.js +0 -75
- package/dist/serde/codec.d.ts +0 -12
- package/dist/serde/codec.d.ts.map +0 -1
- package/dist/serde/codec.js +0 -54
- package/dist/serde/json.d.ts +0 -8
- package/dist/serde/json.d.ts.map +0 -1
- package/dist/serde/json.js +0 -13
- package/dist/serde/thread.d.ts +0 -687
- package/dist/serde/thread.d.ts.map +0 -1
- package/dist/serde/thread.js +0 -158
- package/dist/serde/tool.d.ts +0 -36
- package/dist/serde/tool.d.ts.map +0 -1
- package/dist/session.d.ts +0 -1
- package/dist/session.d.ts.map +0 -1
- package/dist/session.js +0 -1
- package/dist/thread/__tests__/stream.test.d.ts +0 -2
- package/dist/thread/__tests__/stream.test.d.ts.map +0 -1
- package/dist/thread/__tests__/stream.test.js +0 -244
- package/dist/tool/mcp.d.ts +0 -75
- package/dist/tool/mcp.d.ts.map +0 -1
- package/dist/tool/mcp.js +0 -111
- package/dist/tools.d.ts +0 -362
- package/dist/tools.d.ts.map +0 -1
- package/dist/tools.js +0 -220
- package/dist/types/proto.d.ts +0 -1551
- package/dist/types/proto.d.ts.map +0 -1
- package/dist/types/proto.js +0 -531
- package/dist/usage.d.ts +0 -43
- package/dist/usage.d.ts.map +0 -1
- package/dist/usage.js +0 -61
- package/src/lib/serde/thread.ts +0 -188
- /package/dist/{error.js → agent/index.js} +0 -0
- /package/dist/{lib/serde/tool.js → api/models/index.js} +0 -0
- /package/dist/{model.js → api/models/thread.js} +0 -0
- /package/dist/{sched/scheduler.js → api/resources/threads/types.js} +0 -0
- /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
|
-
|
|
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.
|
|
23
|
-
|
|
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
|
-
|
|
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) -
|
|
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.
|
|
40
|
-
|
|
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) -
|
|
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
|
-
|
|
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 '
|
|
30
|
+
* import { env } from '@/env';
|
|
31
31
|
* console.log(env.LOG_LEVEL);
|
|
32
32
|
*/
|
|
33
33
|
export declare const env: {
|
|
34
|
-
LOG_LEVEL: "
|
|
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
package/dist/lib/error.d.ts
CHANGED
|
@@ -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
|
package/dist/lib/logger.js
CHANGED
package/dist/lifecycle.d.ts
CHANGED
|
@@ -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,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
|
});
|
package/dist/mcp/base.d.ts
CHANGED
|
@@ -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";
|
package/dist/mcp/http.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, 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
|
-
|
|
12
|
+
options: MCPServerStreamableHttpOptions;
|
|
13
13
|
private transport;
|
|
14
14
|
constructor(options: MCPServerStreamableHttpOptions);
|
|
15
15
|
/**
|
package/dist/mcp/http.d.ts.map
CHANGED
|
@@ -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,
|
|
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
|
-
|
|
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.
|
|
25
|
-
this.id = options.id || `streamable-http: ${this.
|
|
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.
|
|
34
|
-
authProvider: this.
|
|
35
|
-
requestInit: this.
|
|
36
|
-
fetch: this.
|
|
37
|
-
reconnectionOptions: this.
|
|
38
|
-
sessionId: this.
|
|
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
|
-
|
|
12
|
+
options: MCPServerSSEOptions;
|
|
13
13
|
private transport;
|
|
14
14
|
constructor(options: MCPServerSSEOptions);
|
|
15
15
|
/**
|
package/dist/mcp/sse.d.ts.map
CHANGED
|
@@ -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,
|
|
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
|
-
|
|
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.
|
|
24
|
-
this.id = options.id || `sse: ${this.
|
|
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.
|
|
33
|
-
authProvider: this.
|
|
34
|
-
requestInit: this.
|
|
35
|
-
eventSourceInit: this.
|
|
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,
|
package/dist/mcp/stdio.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, 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
|
*/
|
package/dist/mcp/types.d.ts
CHANGED
|
@@ -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.
|
package/dist/mcp/utils.d.ts
CHANGED
|
@@ -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.
|
|
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
|
} | {
|
package/dist/mcp/utils.d.ts.map
CHANGED
|
@@ -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;;;;;;
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"in-memory.test.d.ts","sourceRoot":"","sources":["../../../src/storage/__tests__/in-memory.test.ts"],"names":[],"mappings":""}
|