kernl 0.2.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +4 -5
- 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 +32 -9
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +102 -14
- 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/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- 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 +22 -6
- package/dist/kernl.d.ts.map +1 -1
- package/dist/kernl.js +73 -10
- package/dist/lib/env.d.ts +3 -3
- package/dist/lib/env.js +1 -1
- package/dist/mcp/__tests__/integration.test.js +8 -8
- package/dist/mcp/__tests__/utils.test.js +6 -6
- package/dist/mcp/http.d.ts +1 -1
- package/dist/mcp/http.d.ts.map +1 -1
- package/dist/mcp/http.js +9 -9
- package/dist/mcp/sse.d.ts +1 -1
- package/dist/mcp/sse.d.ts.map +1 -1
- package/dist/mcp/sse.js +7 -7
- package/dist/mcp/utils.d.ts +1 -1
- package/dist/mcp/utils.d.ts.map +1 -1
- package/dist/mcp/utils.js +4 -5
- 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 +5 -3
- 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 +73 -5
- 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 +49 -51
- package/dist/thread/thread.d.ts +70 -18
- package/dist/thread/thread.d.ts.map +1 -1
- package/dist/thread/thread.js +211 -73
- package/dist/thread/utils.d.ts +36 -8
- package/dist/thread/utils.d.ts.map +1 -1
- package/dist/thread/utils.js +52 -8
- package/dist/tool/__tests__/fixtures.js +1 -1
- package/dist/tool/__tests__/toolkit.test.js +15 -12
- package/dist/tool/tool.js +3 -3
- package/dist/types/kernl.d.ts +42 -0
- package/dist/types/kernl.d.ts.map +1 -0
- package/dist/types/thread.d.ts +108 -22
- package/dist/types/thread.d.ts.map +1 -1
- package/dist/types/thread.js +12 -0
- package/package.json +11 -7
- 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 +141 -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 +111 -10
- 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
|
@@ -115,12 +115,12 @@ describe("FunctionToolkit", () => {
|
|
|
115
115
|
|
|
116
116
|
const serialized = (await toolkit.list()).map((tool: any) => tool.serialize());
|
|
117
117
|
expect(serialized).toHaveLength(1);
|
|
118
|
-
expect(serialized[0]).
|
|
119
|
-
|
|
120
|
-
name: simpleStringTool.
|
|
118
|
+
expect(serialized[0]).toMatchObject({
|
|
119
|
+
kind: "function",
|
|
120
|
+
name: simpleStringTool.id,
|
|
121
121
|
description: simpleStringTool.description,
|
|
122
|
-
parameters: simpleStringTool.parameters,
|
|
123
122
|
});
|
|
123
|
+
expect(serialized[0].parameters).toBeDefined();
|
|
124
124
|
});
|
|
125
125
|
|
|
126
126
|
it("should serialize hosted tools correctly", async () => {
|
|
@@ -129,10 +129,10 @@ describe("FunctionToolkit", () => {
|
|
|
129
129
|
const serialized = (await toolkit.list()).map((tool: any) => tool.serialize());
|
|
130
130
|
expect(serialized).toHaveLength(1);
|
|
131
131
|
expect(serialized[0]).toEqual({
|
|
132
|
-
|
|
132
|
+
kind: "provider-defined",
|
|
133
133
|
id: mockHostedTool.id,
|
|
134
134
|
name: mockHostedTool.name,
|
|
135
|
-
|
|
135
|
+
args: mockHostedTool.providerData,
|
|
136
136
|
});
|
|
137
137
|
});
|
|
138
138
|
|
|
@@ -144,18 +144,21 @@ describe("FunctionToolkit", () => {
|
|
|
144
144
|
|
|
145
145
|
// Check both tools are present (order not guaranteed with Map)
|
|
146
146
|
expect(serialized).toContainEqual({
|
|
147
|
-
|
|
147
|
+
kind: "provider-defined",
|
|
148
148
|
id: mockHostedTool.id,
|
|
149
149
|
name: mockHostedTool.name,
|
|
150
|
-
|
|
150
|
+
args: mockHostedTool.providerData,
|
|
151
151
|
});
|
|
152
152
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
// Check that function tool is present with correct structure
|
|
154
|
+
const functionTool = serialized.find((t: any) => t.kind === "function");
|
|
155
|
+
expect(functionTool).toBeDefined();
|
|
156
|
+
expect(functionTool).toMatchObject({
|
|
157
|
+
kind: "function",
|
|
158
|
+
name: simpleStringTool.id,
|
|
156
159
|
description: simpleStringTool.description,
|
|
157
|
-
parameters: simpleStringTool.parameters,
|
|
158
160
|
});
|
|
161
|
+
expect(functionTool.parameters).toBeDefined();
|
|
159
162
|
});
|
|
160
163
|
|
|
161
164
|
it("should handle hosted tools without providerData", async () => {
|
package/src/tool/tool.ts
CHANGED
|
@@ -197,9 +197,9 @@ export class FunctionTool<
|
|
|
197
197
|
kind: "function",
|
|
198
198
|
name: this.id,
|
|
199
199
|
description: this.description,
|
|
200
|
-
parameters: (this.parameters
|
|
201
|
-
|
|
202
|
-
|
|
200
|
+
parameters: z.toJSONSchema(this.parameters ?? z.object({}), {
|
|
201
|
+
target: "draft-7",
|
|
202
|
+
}) as any, // Use empty object if no parameters (matches AI SDK)
|
|
203
203
|
};
|
|
204
204
|
}
|
|
205
205
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { LanguageModel } from "@kernl-sdk/protocol";
|
|
2
|
+
|
|
3
|
+
import { Agent } from "@/agent";
|
|
4
|
+
import { KernlStorage } from "@/storage";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Storage configuration for Kernl.
|
|
8
|
+
*/
|
|
9
|
+
export interface StorageOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Relational database storage (threads, tasks, traces).
|
|
12
|
+
*/
|
|
13
|
+
db?: KernlStorage;
|
|
14
|
+
|
|
15
|
+
// Future storage layers (deferred):
|
|
16
|
+
// vector?: VectorStore;
|
|
17
|
+
// blob?: BlobStore;
|
|
18
|
+
// lake?: DataLake;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Configuration options for creating a Kernl instance.
|
|
23
|
+
*/
|
|
24
|
+
export interface KernlOptions {
|
|
25
|
+
/**
|
|
26
|
+
* Storage configuration for persisting threads, tasks, and traces.
|
|
27
|
+
*/
|
|
28
|
+
storage?: StorageOptions;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Agent registry interface.
|
|
33
|
+
*
|
|
34
|
+
* Satisfied by Map<string, Agent>.
|
|
35
|
+
*/
|
|
36
|
+
export interface AgentRegistry {
|
|
37
|
+
get(id: string): Agent<any> | undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Model registry interface.
|
|
42
|
+
*
|
|
43
|
+
* Satisfied by Map<string, LanguageModel>.
|
|
44
|
+
* Key format: "provider/modelId"
|
|
45
|
+
*
|
|
46
|
+
* TODO: Create an exhaustive model registry in the protocol package
|
|
47
|
+
* with all supported models and their metadata.
|
|
48
|
+
*/
|
|
49
|
+
export interface ModelRegistry {
|
|
50
|
+
get(key: string): LanguageModel | undefined;
|
|
51
|
+
}
|
package/src/types/thread.ts
CHANGED
|
@@ -13,9 +13,30 @@ import {
|
|
|
13
13
|
|
|
14
14
|
import { Task } from "@/task";
|
|
15
15
|
import { Context } from "@/context";
|
|
16
|
+
import { Agent } from "@/agent";
|
|
17
|
+
|
|
18
|
+
import type { AgentResponseType } from "./agent";
|
|
19
|
+
import type { ThreadStore } from "@/storage";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Public/client-facing thread events (excludes internal system events).
|
|
23
|
+
*/
|
|
24
|
+
export type PublicThreadEvent = LanguageModelItem & ThreadEventBase;
|
|
16
25
|
|
|
17
26
|
export type TextResponse = "text";
|
|
18
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Thread state values as a const array (for zod schemas).
|
|
30
|
+
*/
|
|
31
|
+
export const THREAD_STATES = [
|
|
32
|
+
RUNNING,
|
|
33
|
+
STOPPED,
|
|
34
|
+
INTERRUPTIBLE,
|
|
35
|
+
UNINTERRUPTIBLE,
|
|
36
|
+
ZOMBIE,
|
|
37
|
+
DEAD,
|
|
38
|
+
] as const;
|
|
39
|
+
|
|
19
40
|
/**
|
|
20
41
|
* Thread state discriminated union
|
|
21
42
|
*/
|
|
@@ -34,44 +55,84 @@ export type ThreadState =
|
|
|
34
55
|
export const REQUIRES_APPROVAL = "requires_approval";
|
|
35
56
|
|
|
36
57
|
/**
|
|
37
|
-
*
|
|
58
|
+
* Thread domain interface.
|
|
38
59
|
*
|
|
39
|
-
*
|
|
40
|
-
* which don't go to the model.
|
|
60
|
+
* Represents the complete state of a Thread that can be stored and restored.
|
|
41
61
|
*/
|
|
42
|
-
export
|
|
62
|
+
export interface IThread<
|
|
63
|
+
TContext = unknown,
|
|
64
|
+
TResponse extends AgentResponseType = "text",
|
|
65
|
+
> {
|
|
66
|
+
tid: string;
|
|
67
|
+
agent: Agent<TContext, TResponse>;
|
|
68
|
+
model: LanguageModel;
|
|
69
|
+
|
|
70
|
+
context: Context<TContext>;
|
|
71
|
+
input: LanguageModelItem[] /* initial input for the thread */;
|
|
72
|
+
history: ThreadEvent[];
|
|
73
|
+
task: Task<TContext> | null /* parent task which spawned this thread (if any) */;
|
|
74
|
+
|
|
75
|
+
/* state */
|
|
76
|
+
tick: number;
|
|
77
|
+
state: ThreadState /* running | stopped | ... */;
|
|
78
|
+
namespace: string;
|
|
79
|
+
|
|
80
|
+
/* metadata */
|
|
81
|
+
createdAt: Date;
|
|
82
|
+
updatedAt: Date;
|
|
83
|
+
metadata: Record<string, unknown> | null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface CheckpointDelta {
|
|
87
|
+
state?: ThreadState;
|
|
88
|
+
tick?: number;
|
|
89
|
+
seq?: number;
|
|
90
|
+
events?: ThreadEvent[];
|
|
91
|
+
}
|
|
43
92
|
|
|
44
93
|
/**
|
|
45
|
-
*
|
|
94
|
+
* The inner data of a ThreadEvent without the headers
|
|
46
95
|
*/
|
|
47
|
-
export type
|
|
96
|
+
export type ThreadEventInner = LanguageModelItem; // ...
|
|
48
97
|
|
|
49
98
|
/**
|
|
50
|
-
*
|
|
99
|
+
* Base fields for all thread events - added to every LanguageModelItem when stored in thread.
|
|
51
100
|
*/
|
|
52
|
-
export interface
|
|
53
|
-
|
|
54
|
-
|
|
101
|
+
export interface ThreadEventBase {
|
|
102
|
+
id: string;
|
|
103
|
+
tid: string;
|
|
104
|
+
seq: number;
|
|
105
|
+
timestamp: Date;
|
|
106
|
+
metadata: Record<string, unknown>;
|
|
55
107
|
}
|
|
56
108
|
|
|
57
109
|
/**
|
|
58
|
-
*
|
|
110
|
+
* System event - runtime state changes (not sent to model).
|
|
59
111
|
*/
|
|
60
|
-
export interface
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
*/
|
|
64
|
-
actions: ThreadEvent[];
|
|
65
|
-
/**
|
|
66
|
-
* Tool calls that require approval before execution
|
|
67
|
-
*/
|
|
68
|
-
pendingApprovals: ToolCall[];
|
|
112
|
+
export interface ThreadSystemEvent extends ThreadEventBase {
|
|
113
|
+
readonly kind: "system";
|
|
114
|
+
// Future: error?, state-change?, etc.
|
|
69
115
|
}
|
|
70
116
|
|
|
117
|
+
/**
|
|
118
|
+
* Thread events are append-only log entries ordered by seq.
|
|
119
|
+
*
|
|
120
|
+
* Events extend LanguageModelItem types with thread-specific metadata (tid, seq, timestamp).
|
|
121
|
+
* When sent to the model, we extract the LanguageModelItem by omitting the base fields.
|
|
122
|
+
*/
|
|
123
|
+
export type ThreadEvent =
|
|
124
|
+
| (LanguageModelItem & ThreadEventBase)
|
|
125
|
+
| ThreadSystemEvent;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Stream events - use protocol definition directly.
|
|
129
|
+
*/
|
|
130
|
+
export type ThreadStreamEvent = LanguageModelStreamEvent;
|
|
131
|
+
|
|
71
132
|
/**
|
|
72
133
|
* Result of thread execution
|
|
73
134
|
*/
|
|
74
|
-
export interface ThreadExecuteResult<TResponse =
|
|
135
|
+
export interface ThreadExecuteResult<TResponse = unknown> {
|
|
75
136
|
/**
|
|
76
137
|
* The final parsed response from the agent
|
|
77
138
|
*/
|
|
@@ -79,16 +140,69 @@ export interface ThreadExecuteResult<TResponse = any> {
|
|
|
79
140
|
/**
|
|
80
141
|
* The thread state at completion
|
|
81
142
|
*/
|
|
82
|
-
state: any; //
|
|
143
|
+
state: any; // (TODO): Update this
|
|
83
144
|
}
|
|
84
145
|
|
|
85
|
-
|
|
86
|
-
|
|
146
|
+
/**
|
|
147
|
+
* Options for constructing a Thread.
|
|
148
|
+
*/
|
|
149
|
+
export interface ThreadOptions<
|
|
150
|
+
TContext = unknown,
|
|
151
|
+
TResponse extends AgentResponseType = "text",
|
|
152
|
+
> {
|
|
153
|
+
agent: Agent<TContext, TResponse>;
|
|
154
|
+
input?: LanguageModelItem[];
|
|
155
|
+
history?: ThreadEvent[];
|
|
156
|
+
context?: Context<TContext>;
|
|
157
|
+
model?: LanguageModel;
|
|
158
|
+
task?: Task<TContext> | null;
|
|
159
|
+
namespace?: string;
|
|
160
|
+
tid?: string;
|
|
161
|
+
tick?: number;
|
|
162
|
+
state?: ThreadState;
|
|
163
|
+
storage?: ThreadStore;
|
|
164
|
+
createdAt?: Date;
|
|
165
|
+
updatedAt?: Date;
|
|
166
|
+
metadata?: Record<string, unknown> | null;
|
|
167
|
+
/**
|
|
168
|
+
* Internal flag indicating whether this thread already has a persisted
|
|
169
|
+
* row in storage. Storage implementations MUST set this to true when
|
|
170
|
+
* hydrating from a store. Callers creating new threads should omit it.
|
|
171
|
+
*/
|
|
172
|
+
persisted?: boolean;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Options passed to agent.execute() and agent.stream().
|
|
177
|
+
*/
|
|
178
|
+
export interface ThreadExecuteOptions<TContext> {
|
|
179
|
+
context?: Context<TContext>;
|
|
87
180
|
model?: LanguageModel;
|
|
88
181
|
task?: Task<TContext>;
|
|
89
182
|
threadId?: string;
|
|
183
|
+
namespace?: string;
|
|
90
184
|
maxTicks?: number;
|
|
91
185
|
abort?: AbortSignal;
|
|
186
|
+
}
|
|
92
187
|
|
|
93
|
-
|
|
188
|
+
/**
|
|
189
|
+
* Set of actionable items extracted from a model response
|
|
190
|
+
*/
|
|
191
|
+
export interface ActionSet {
|
|
192
|
+
toolCalls: ToolCall[];
|
|
193
|
+
// Future: other actions, mcpRequests, etc.
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Result of performing actions, including both executed results and pending approvals
|
|
198
|
+
*/
|
|
199
|
+
export interface PerformActionsResult {
|
|
200
|
+
/**
|
|
201
|
+
* Action events generated from executing tools (tool results)
|
|
202
|
+
*/
|
|
203
|
+
actions: ThreadEventInner[];
|
|
204
|
+
/**
|
|
205
|
+
* Tool calls that require approval before execution
|
|
206
|
+
*/
|
|
207
|
+
pendingApprovals: ToolCall[];
|
|
94
208
|
}
|
package/vitest.config.ts
CHANGED
package/dist/env.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
/**
|
|
3
|
-
* Environment variable validation schema
|
|
4
|
-
*
|
|
5
|
-
* This ensures all environment variables are valid at startup.
|
|
6
|
-
* All variables are optional with sensible defaults.
|
|
7
|
-
*/
|
|
8
|
-
declare const envSchema: z.ZodObject<{
|
|
9
|
-
LOG_LEVEL: z.ZodDefault<z.ZodEnum<{
|
|
10
|
-
trace: "trace";
|
|
11
|
-
debug: "debug";
|
|
12
|
-
info: "info";
|
|
13
|
-
warn: "warn";
|
|
14
|
-
error: "error";
|
|
15
|
-
fatal: "fatal";
|
|
16
|
-
}>>;
|
|
17
|
-
KERNL_LOG_MODEL_DATA: z.ZodPipe<z.ZodOptional<z.ZodEnum<{
|
|
18
|
-
true: "true";
|
|
19
|
-
false: "false";
|
|
20
|
-
}>>, z.ZodTransform<boolean, "true" | "false" | undefined>>;
|
|
21
|
-
KERNL_LOG_TOOL_DATA: z.ZodPipe<z.ZodOptional<z.ZodEnum<{
|
|
22
|
-
true: "true";
|
|
23
|
-
false: "false";
|
|
24
|
-
}>>, z.ZodTransform<boolean, "true" | "false" | undefined>>;
|
|
25
|
-
}, z.core.$strip>;
|
|
26
|
-
/**
|
|
27
|
-
* Validated and type-safe environment variables
|
|
28
|
-
*
|
|
29
|
-
* Use this throughout the library instead of process.env directly.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* import { env } from './env';
|
|
33
|
-
* console.log(env.LOG_LEVEL);
|
|
34
|
-
*/
|
|
35
|
-
export declare const env: {
|
|
36
|
-
LOG_LEVEL: "trace" | "debug" | "info" | "warn" | "error" | "fatal";
|
|
37
|
-
KERNL_LOG_MODEL_DATA: boolean;
|
|
38
|
-
KERNL_LOG_TOOL_DATA: boolean;
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Type of the validated environment variables
|
|
42
|
-
*/
|
|
43
|
-
export type Env = z.infer<typeof envSchema>;
|
|
44
|
-
export {};
|
|
45
|
-
//# sourceMappingURL=env.d.ts.map
|
package/dist/env.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;GAKG;AACH,QAAA,MAAM,SAAS;;;;;;;;;;;;;;;;;iBAab,CAAC;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,GAAG;;;;CAA+B,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC"}
|
package/dist/env.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
/**
|
|
3
|
-
* Environment variable validation schema
|
|
4
|
-
*
|
|
5
|
-
* This ensures all environment variables are valid at startup.
|
|
6
|
-
* All variables are optional with sensible defaults.
|
|
7
|
-
*/
|
|
8
|
-
const envSchema = z.object({
|
|
9
|
-
// --- Logging ---
|
|
10
|
-
LOG_LEVEL: z
|
|
11
|
-
.enum(["trace", "debug", "info", "warn", "error", "fatal"])
|
|
12
|
-
.default("info"),
|
|
13
|
-
KERNL_LOG_MODEL_DATA: z
|
|
14
|
-
.enum(["true", "false"])
|
|
15
|
-
.optional()
|
|
16
|
-
.transform((val) => val === "true"),
|
|
17
|
-
KERNL_LOG_TOOL_DATA: z
|
|
18
|
-
.enum(["true", "false"])
|
|
19
|
-
.optional()
|
|
20
|
-
.transform((val) => val === "true"),
|
|
21
|
-
});
|
|
22
|
-
/**
|
|
23
|
-
* Validated and type-safe environment variables
|
|
24
|
-
*
|
|
25
|
-
* Use this throughout the library instead of process.env directly.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* import { env } from './env';
|
|
29
|
-
* console.log(env.LOG_LEVEL);
|
|
30
|
-
*/
|
|
31
|
-
export const env = envSchema.parse(process.env);
|
package/dist/error.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=error.d.ts.map
|
package/dist/error.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":""}
|
package/dist/kernel.d.ts
DELETED
package/dist/kernel.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"kernel.d.ts","sourceRoot":"","sources":["../src/kernel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAErC,qBAAa,MAAM;IACjB,OAAO,CAAC,MAAM,CAAiC;;IAI/C,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;CAG7B"}
|
package/dist/kernel.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codec.test.d.ts","sourceRoot":"","sources":["../../../../src/lib/serde/__tests__/codec.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { json } from "../codec";
|
|
4
|
-
describe("json codec", () => {
|
|
5
|
-
it("should parse valid JSON and validate against schema", () => {
|
|
6
|
-
const schema = z.object({
|
|
7
|
-
name: z.string(),
|
|
8
|
-
age: z.number(),
|
|
9
|
-
});
|
|
10
|
-
const codec = json(schema);
|
|
11
|
-
const result = codec.decode('{"name": "Alice", "age": 30}');
|
|
12
|
-
expect(result).toEqual({ name: "Alice", age: 30 });
|
|
13
|
-
});
|
|
14
|
-
it("should reject invalid JSON syntax", () => {
|
|
15
|
-
const schema = z.object({
|
|
16
|
-
name: z.string(),
|
|
17
|
-
});
|
|
18
|
-
const codec = json(schema);
|
|
19
|
-
expect(() => {
|
|
20
|
-
codec.decode('{"name": "Alice"');
|
|
21
|
-
}).toThrow();
|
|
22
|
-
});
|
|
23
|
-
it("should reject valid JSON that doesn't match schema", () => {
|
|
24
|
-
const schema = z.object({
|
|
25
|
-
name: z.string(),
|
|
26
|
-
age: z.number(),
|
|
27
|
-
});
|
|
28
|
-
const codec = json(schema);
|
|
29
|
-
// Valid JSON but age is a string, not a number
|
|
30
|
-
expect(() => {
|
|
31
|
-
codec.decode('{"name": "Alice", "age": "30"}');
|
|
32
|
-
}).toThrow();
|
|
33
|
-
});
|
|
34
|
-
it("should reject JSON missing required fields", () => {
|
|
35
|
-
const schema = z.object({
|
|
36
|
-
name: z.string(),
|
|
37
|
-
age: z.number(),
|
|
38
|
-
});
|
|
39
|
-
const codec = json(schema);
|
|
40
|
-
// Valid JSON but missing age field
|
|
41
|
-
expect(() => {
|
|
42
|
-
codec.decode('{"name": "Alice"}');
|
|
43
|
-
}).toThrow();
|
|
44
|
-
});
|
|
45
|
-
it("should handle nested objects", () => {
|
|
46
|
-
const schema = z.object({
|
|
47
|
-
user: z.object({
|
|
48
|
-
name: z.string(),
|
|
49
|
-
email: z.string().email(),
|
|
50
|
-
}),
|
|
51
|
-
metadata: z.object({
|
|
52
|
-
createdAt: z.string(),
|
|
53
|
-
}),
|
|
54
|
-
});
|
|
55
|
-
const codec = json(schema);
|
|
56
|
-
const result = codec.decode('{"user": {"name": "Bob", "email": "bob@example.com"}, "metadata": {"createdAt": "2024-01-01"}}');
|
|
57
|
-
expect(result).toEqual({
|
|
58
|
-
user: { name: "Bob", email: "bob@example.com" },
|
|
59
|
-
metadata: { createdAt: "2024-01-01" },
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
it("should reject nested objects that don't match schema", () => {
|
|
63
|
-
const schema = z.object({
|
|
64
|
-
user: z.object({
|
|
65
|
-
name: z.string(),
|
|
66
|
-
email: z.string().email(),
|
|
67
|
-
}),
|
|
68
|
-
});
|
|
69
|
-
const codec = json(schema);
|
|
70
|
-
// Invalid email format
|
|
71
|
-
expect(() => {
|
|
72
|
-
codec.decode('{"user": {"name": "Bob", "email": "not-an-email"}}');
|
|
73
|
-
}).toThrow();
|
|
74
|
-
});
|
|
75
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
export declare const stringToNumber: z.ZodCodec<z.ZodString, z.ZodNumber>;
|
|
3
|
-
export declare const stringToInt: z.ZodCodec<z.ZodString, z.ZodInt>;
|
|
4
|
-
export declare const isotime: z.ZodCodec<z.ZodISODateTime, z.ZodDate>;
|
|
5
|
-
export declare const epochsec: z.ZodCodec<z.ZodInt, z.ZodDate>;
|
|
6
|
-
export declare const epochms: z.ZodCodec<z.ZodInt, z.ZodDate>;
|
|
7
|
-
export declare const json: <T extends z.core.$ZodType>(schema: T) => z.ZodCodec<z.ZodString, T>;
|
|
8
|
-
export declare const stringToURL: z.ZodCodec<z.ZodURL, z.ZodCustom<import("url").URL, import("url").URL>>;
|
|
9
|
-
export declare const stringToHttpURL: z.ZodCodec<z.ZodURL, z.ZodCustom<import("url").URL, import("url").URL>>;
|
|
10
|
-
export declare const base64ToBytes: z.ZodCodec<z.ZodBase64, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
|
|
11
|
-
export declare const base64urlToBytes: z.ZodCodec<z.ZodBase64URL, z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
|
|
12
|
-
//# sourceMappingURL=codec.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codec.d.ts","sourceRoot":"","sources":["../../../src/lib/serde/codec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,cAAc,sCAO1B,CAAC;AAEF,eAAO,MAAM,WAAW,mCAOvB,CAAC;AAEF,eAAO,MAAM,OAAO,yCAGlB,CAAC;AAEH,eAAO,MAAM,QAAQ,iCAGnB,CAAC;AAEH,eAAO,MAAM,OAAO,iCAGlB,CAAC;AAEH,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,+BAgBrD,CAAC;AAEL,eAAO,MAAM,WAAW,yEAGtB,CAAC;AAEH,eAAO,MAAM,eAAe,yEAG1B,CAAC;AAEH,eAAO,MAAM,aAAa,wFAGxB,CAAC;AAEH,eAAO,MAAM,gBAAgB,2FAO5B,CAAC"}
|
package/dist/lib/serde/codec.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
export const stringToNumber = z.codec(z.string().regex(z.regexes.number), z.number(), {
|
|
3
|
-
decode: (str) => Number.parseFloat(str),
|
|
4
|
-
encode: (num) => num.toString(),
|
|
5
|
-
});
|
|
6
|
-
export const stringToInt = z.codec(z.string().regex(z.regexes.integer), z.int(), {
|
|
7
|
-
decode: (str) => Number.parseInt(str, 10),
|
|
8
|
-
encode: (num) => num.toString(),
|
|
9
|
-
});
|
|
10
|
-
export const isotime = z.codec(z.iso.datetime(), z.date(), {
|
|
11
|
-
decode: (isoString) => new Date(isoString),
|
|
12
|
-
encode: (date) => date.toISOString(),
|
|
13
|
-
});
|
|
14
|
-
export const epochsec = z.codec(z.int().min(0), z.date(), {
|
|
15
|
-
decode: (seconds) => new Date(seconds * 1000),
|
|
16
|
-
encode: (date) => Math.floor(date.getTime() / 1000),
|
|
17
|
-
});
|
|
18
|
-
export const epochms = z.codec(z.int().min(0), z.date(), {
|
|
19
|
-
decode: (millis) => new Date(millis),
|
|
20
|
-
encode: (date) => date.getTime(),
|
|
21
|
-
});
|
|
22
|
-
export const json = (schema) => z.codec(z.string(), schema, {
|
|
23
|
-
decode: (jsonString, ctx) => {
|
|
24
|
-
try {
|
|
25
|
-
return JSON.parse(jsonString);
|
|
26
|
-
}
|
|
27
|
-
catch (err) {
|
|
28
|
-
ctx.issues.push({
|
|
29
|
-
code: "invalid_format",
|
|
30
|
-
format: "json",
|
|
31
|
-
input: jsonString,
|
|
32
|
-
message: err.message,
|
|
33
|
-
});
|
|
34
|
-
return z.NEVER;
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
encode: (value) => JSON.stringify(value),
|
|
38
|
-
});
|
|
39
|
-
export const stringToURL = z.codec(z.url(), z.instanceof(URL), {
|
|
40
|
-
decode: (urlString) => new URL(urlString),
|
|
41
|
-
encode: (url) => url.href,
|
|
42
|
-
});
|
|
43
|
-
export const stringToHttpURL = z.codec(z.httpUrl(), z.instanceof(URL), {
|
|
44
|
-
decode: (urlString) => new URL(urlString),
|
|
45
|
-
encode: (url) => url.href,
|
|
46
|
-
});
|
|
47
|
-
export const base64ToBytes = z.codec(z.base64(), z.instanceof(Uint8Array), {
|
|
48
|
-
decode: (base64String) => z.util.base64ToUint8Array(base64String),
|
|
49
|
-
encode: (bytes) => z.util.uint8ArrayToBase64(bytes),
|
|
50
|
-
});
|
|
51
|
-
export const base64urlToBytes = z.codec(z.base64url(), z.instanceof(Uint8Array), {
|
|
52
|
-
decode: (base64urlString) => z.util.base64urlToUint8Array(base64urlString),
|
|
53
|
-
encode: (bytes) => z.util.uint8ArrayToBase64url(bytes),
|
|
54
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=thread.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"thread.d.ts","sourceRoot":"","sources":["../../../src/lib/serde/thread.ts"],"names":[],"mappings":""}
|