kernl 0.1.3 → 0.2.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 +5 -4
- package/CHANGELOG.md +18 -0
- package/dist/agent.d.ts +20 -3
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +60 -41
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/kernl.d.ts +27 -1
- package/dist/kernl.d.ts.map +1 -1
- package/dist/kernl.js +36 -2
- package/dist/mcp/__tests__/integration.test.js +16 -0
- package/dist/thread/__tests__/fixtures/mock-model.d.ts +7 -0
- package/dist/thread/__tests__/fixtures/mock-model.d.ts.map +1 -0
- package/dist/thread/__tests__/fixtures/mock-model.js +59 -0
- package/dist/thread/__tests__/integration.test.d.ts +2 -0
- package/dist/thread/__tests__/integration.test.d.ts.map +1 -0
- package/dist/thread/__tests__/integration.test.js +247 -0
- package/dist/thread/__tests__/stream.test.d.ts +2 -0
- package/dist/thread/__tests__/stream.test.d.ts.map +1 -0
- package/dist/thread/__tests__/stream.test.js +244 -0
- package/dist/thread/__tests__/thread.test.js +612 -763
- package/dist/thread/thread.d.ts +30 -25
- package/dist/thread/thread.d.ts.map +1 -1
- package/dist/thread/thread.js +114 -314
- package/dist/thread/utils.d.ts +16 -1
- package/dist/thread/utils.d.ts.map +1 -1
- package/dist/thread/utils.js +30 -0
- package/dist/tool/index.d.ts +1 -1
- package/dist/tool/index.d.ts.map +1 -1
- package/dist/tool/index.js +1 -1
- package/dist/tool/tool.d.ts.map +1 -1
- package/dist/tool/tool.js +6 -2
- package/dist/tool/toolkit.d.ts +13 -3
- package/dist/tool/toolkit.d.ts.map +1 -1
- package/dist/tool/toolkit.js +11 -3
- package/dist/tool/types.d.ts +8 -0
- package/dist/tool/types.d.ts.map +1 -1
- package/dist/types/agent.d.ts +5 -5
- package/dist/types/agent.d.ts.map +1 -1
- package/dist/types/thread.d.ts +10 -16
- package/dist/types/thread.d.ts.map +1 -1
- package/package.json +6 -4
- package/src/agent.ts +97 -86
- package/src/index.ts +1 -1
- package/src/kernl.ts +51 -2
- package/src/mcp/__tests__/integration.test.ts +17 -0
- package/src/thread/__tests__/fixtures/mock-model.ts +71 -0
- package/src/thread/__tests__/integration.test.ts +349 -0
- package/src/thread/__tests__/thread.test.ts +625 -775
- package/src/thread/thread.ts +134 -381
- package/src/thread/utils.ts +36 -1
- package/src/tool/index.ts +1 -1
- package/src/tool/tool.ts +6 -2
- package/src/tool/toolkit.ts +19 -3
- package/src/tool/types.ts +10 -0
- package/src/types/agent.ts +9 -6
- package/src/types/thread.ts +25 -17
package/src/tool/toolkit.ts
CHANGED
|
@@ -18,12 +18,17 @@ import type {
|
|
|
18
18
|
* Toolkits can be static (FunctionToolkit) or dynamic (MCPToolkit), and provide
|
|
19
19
|
* a unified interface for tool discovery and management.
|
|
20
20
|
*/
|
|
21
|
-
export abstract class
|
|
21
|
+
export abstract class BaseToolkit<TContext = UnknownContext> {
|
|
22
22
|
/**
|
|
23
23
|
* Unique identifier for this toolkit
|
|
24
24
|
*/
|
|
25
25
|
abstract readonly id: string;
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Description of what this toolkit provides
|
|
29
|
+
*/
|
|
30
|
+
abstract readonly description: string;
|
|
31
|
+
|
|
27
32
|
/**
|
|
28
33
|
* The agent this toolkit is bound to (if any)
|
|
29
34
|
*/
|
|
@@ -77,8 +82,9 @@ export abstract class Toolkit<TContext = UnknownContext> {
|
|
|
77
82
|
*/
|
|
78
83
|
export class FunctionToolkit<
|
|
79
84
|
TContext = UnknownContext,
|
|
80
|
-
> extends
|
|
85
|
+
> extends BaseToolkit<TContext> {
|
|
81
86
|
readonly id: string;
|
|
87
|
+
readonly description: string;
|
|
82
88
|
private tools: Map<string, Tool<TContext>>;
|
|
83
89
|
|
|
84
90
|
/**
|
|
@@ -89,6 +95,7 @@ export class FunctionToolkit<
|
|
|
89
95
|
constructor(config: FunctionToolkitConfig<TContext>) {
|
|
90
96
|
super();
|
|
91
97
|
this.id = config.id;
|
|
98
|
+
this.description = config.description ?? "";
|
|
92
99
|
this.tools = new Map(config.tools.map((t) => [t.id, t]));
|
|
93
100
|
}
|
|
94
101
|
|
|
@@ -113,6 +120,11 @@ export class FunctionToolkit<
|
|
|
113
120
|
}
|
|
114
121
|
}
|
|
115
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Convenience alias for FunctionToolkit - the default toolkit implementation.
|
|
125
|
+
*/
|
|
126
|
+
export { FunctionToolkit as Toolkit };
|
|
127
|
+
|
|
116
128
|
/*
|
|
117
129
|
* A toolkit that wraps an MCP server and provides tools from it.
|
|
118
130
|
*
|
|
@@ -144,8 +156,11 @@ export class FunctionToolkit<
|
|
|
144
156
|
* });
|
|
145
157
|
* ```
|
|
146
158
|
*/
|
|
147
|
-
export class MCPToolkit<
|
|
159
|
+
export class MCPToolkit<
|
|
160
|
+
TContext = UnknownContext,
|
|
161
|
+
> extends BaseToolkit<TContext> {
|
|
148
162
|
readonly id: string;
|
|
163
|
+
readonly description: string;
|
|
149
164
|
private server: MCPServer;
|
|
150
165
|
private cache: Map<string, Tool<TContext>>;
|
|
151
166
|
private filter: ToolkitFilter<TContext>;
|
|
@@ -161,6 +176,7 @@ export class MCPToolkit<TContext = UnknownContext> extends Toolkit<TContext> {
|
|
|
161
176
|
constructor(config: MCPToolkitConfig<TContext>) {
|
|
162
177
|
super();
|
|
163
178
|
this.id = config.id;
|
|
179
|
+
this.description = config.description ?? "";
|
|
164
180
|
this.server = config.server;
|
|
165
181
|
this.filter = config.filter ?? (() => true);
|
|
166
182
|
this.cache = new Map();
|
package/src/tool/types.ts
CHANGED
|
@@ -121,6 +121,11 @@ export interface FunctionToolkitConfig<TContext = UnknownContext> {
|
|
|
121
121
|
*/
|
|
122
122
|
id: string;
|
|
123
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Optional description of what this toolkit provides.
|
|
126
|
+
*/
|
|
127
|
+
description?: string;
|
|
128
|
+
|
|
124
129
|
/**
|
|
125
130
|
* Array of tools to include in this toolkit.
|
|
126
131
|
*/
|
|
@@ -136,6 +141,11 @@ export interface MCPToolkitConfig<TContext = UnknownContext> {
|
|
|
136
141
|
*/
|
|
137
142
|
id: string;
|
|
138
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Optional description of what this toolkit provides.
|
|
146
|
+
*/
|
|
147
|
+
description?: string;
|
|
148
|
+
|
|
139
149
|
/**
|
|
140
150
|
* The MCP server instance to wrap.
|
|
141
151
|
*/
|
package/src/types/agent.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { type ZodType } from "zod";
|
|
2
2
|
|
|
3
3
|
import { Context, UnknownContext } from "@/context";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
LanguageModel,
|
|
6
|
+
LanguageModelRequestSettings,
|
|
7
|
+
} from "@kernl-sdk/protocol";
|
|
5
8
|
import { InputGuardrail, OutputGuardrail } from "@/guardrail";
|
|
6
|
-
import {
|
|
9
|
+
import { BaseToolkit } from "@/tool";
|
|
7
10
|
|
|
8
11
|
import { TextResponse } from "./thread";
|
|
9
12
|
|
|
@@ -50,7 +53,7 @@ export interface AgentConfig<
|
|
|
50
53
|
*
|
|
51
54
|
* By default, if not set, the agent will use a default model that throws an error when called.
|
|
52
55
|
*/
|
|
53
|
-
model
|
|
56
|
+
model: LanguageModel;
|
|
54
57
|
|
|
55
58
|
/**
|
|
56
59
|
* Configures model-specific tuning parameters (e.g. temperature, top_p, etc.)
|
|
@@ -59,11 +62,11 @@ export interface AgentConfig<
|
|
|
59
62
|
|
|
60
63
|
/**
|
|
61
64
|
* A list of toolkits the agent can use. Toolkits are collections of related tools
|
|
62
|
-
* that can be static (
|
|
65
|
+
* that can be static (Toolkit) or dynamic (MCPToolkit).
|
|
63
66
|
*
|
|
64
67
|
* @example
|
|
65
68
|
* ```typescript
|
|
66
|
-
* const myTools = new
|
|
69
|
+
* const myTools = new Toolkit({
|
|
67
70
|
* id: "custom",
|
|
68
71
|
* tools: [tool1, tool2]
|
|
69
72
|
* });
|
|
@@ -80,7 +83,7 @@ export interface AgentConfig<
|
|
|
80
83
|
* });
|
|
81
84
|
* ```
|
|
82
85
|
*/
|
|
83
|
-
toolkits?:
|
|
86
|
+
toolkits?: BaseToolkit<TContext>[];
|
|
84
87
|
|
|
85
88
|
/**
|
|
86
89
|
* A list of checks that run in parallel to the agent's execution on the input + output for the agent,
|
package/src/types/thread.ts
CHANGED
|
@@ -3,11 +3,30 @@ import {
|
|
|
3
3
|
LanguageModel,
|
|
4
4
|
LanguageModelItem,
|
|
5
5
|
LanguageModelStreamEvent,
|
|
6
|
+
RUNNING,
|
|
7
|
+
STOPPED,
|
|
8
|
+
INTERRUPTIBLE,
|
|
9
|
+
UNINTERRUPTIBLE,
|
|
10
|
+
ZOMBIE,
|
|
11
|
+
DEAD,
|
|
6
12
|
} from "@kernl-sdk/protocol";
|
|
7
13
|
|
|
8
14
|
import { Task } from "@/task";
|
|
9
15
|
import { Context } from "@/context";
|
|
10
16
|
|
|
17
|
+
export type TextResponse = "text";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Thread state discriminated union
|
|
21
|
+
*/
|
|
22
|
+
export type ThreadState =
|
|
23
|
+
| typeof RUNNING
|
|
24
|
+
| typeof STOPPED
|
|
25
|
+
| typeof INTERRUPTIBLE
|
|
26
|
+
| typeof UNINTERRUPTIBLE
|
|
27
|
+
| typeof ZOMBIE
|
|
28
|
+
| typeof DEAD;
|
|
29
|
+
|
|
11
30
|
/**
|
|
12
31
|
* Thread-specific tool call state for approval workflow.
|
|
13
32
|
* This extends the protocol states for internal thread use.
|
|
@@ -35,20 +54,6 @@ export interface ActionSet {
|
|
|
35
54
|
// Future: other actions, mcpRequests, etc.
|
|
36
55
|
}
|
|
37
56
|
|
|
38
|
-
/**
|
|
39
|
-
* Result of a single tick of execution
|
|
40
|
-
*/
|
|
41
|
-
export interface TickResult {
|
|
42
|
-
/**
|
|
43
|
-
* Events to add to thread history
|
|
44
|
-
*/
|
|
45
|
-
events: ThreadEvent[];
|
|
46
|
-
/**
|
|
47
|
-
* Action intentions that need to be performed as a result of this tick
|
|
48
|
-
*/
|
|
49
|
-
intentions: ActionSet | null;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
57
|
/**
|
|
53
58
|
* Result of performing actions, including both executed results and pending approvals
|
|
54
59
|
*/
|
|
@@ -79,8 +84,11 @@ export interface ThreadExecuteResult<TResponse = any> {
|
|
|
79
84
|
|
|
80
85
|
export interface ThreadOptions<TContext> {
|
|
81
86
|
context: Context<TContext>;
|
|
82
|
-
task?: Task<TContext>;
|
|
83
87
|
model?: LanguageModel;
|
|
84
|
-
|
|
88
|
+
task?: Task<TContext>;
|
|
89
|
+
threadId?: string;
|
|
90
|
+
maxTicks?: number;
|
|
91
|
+
abort?: AbortSignal;
|
|
85
92
|
|
|
86
|
-
|
|
93
|
+
// conversationId?: string;
|
|
94
|
+
}
|