kernl 0.1.4 → 0.2.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 +1 -1
- package/CHANGELOG.md +21 -0
- package/dist/agent.d.ts +20 -3
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +61 -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 +315 -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 +7 -3
- package/dist/tool/toolkit.d.ts.map +1 -1
- package/dist/tool/toolkit.js +7 -3
- 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 +7 -5
- package/src/agent.ts +99 -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 +449 -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 +10 -3
- package/src/types/agent.ts +9 -6
- package/src/types/thread.ts +25 -17
package/src/tool/toolkit.ts
CHANGED
|
@@ -18,7 +18,7 @@ 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
|
*/
|
|
@@ -82,7 +82,7 @@ export abstract class Toolkit<TContext = UnknownContext> {
|
|
|
82
82
|
*/
|
|
83
83
|
export class FunctionToolkit<
|
|
84
84
|
TContext = UnknownContext,
|
|
85
|
-
> extends
|
|
85
|
+
> extends BaseToolkit<TContext> {
|
|
86
86
|
readonly id: string;
|
|
87
87
|
readonly description: string;
|
|
88
88
|
private tools: Map<string, Tool<TContext>>;
|
|
@@ -120,6 +120,11 @@ export class FunctionToolkit<
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Convenience alias for FunctionToolkit - the default toolkit implementation.
|
|
125
|
+
*/
|
|
126
|
+
export { FunctionToolkit as Toolkit };
|
|
127
|
+
|
|
123
128
|
/*
|
|
124
129
|
* A toolkit that wraps an MCP server and provides tools from it.
|
|
125
130
|
*
|
|
@@ -151,7 +156,9 @@ export class FunctionToolkit<
|
|
|
151
156
|
* });
|
|
152
157
|
* ```
|
|
153
158
|
*/
|
|
154
|
-
export class MCPToolkit<
|
|
159
|
+
export class MCPToolkit<
|
|
160
|
+
TContext = UnknownContext,
|
|
161
|
+
> extends BaseToolkit<TContext> {
|
|
155
162
|
readonly id: string;
|
|
156
163
|
readonly description: string;
|
|
157
164
|
private server: MCPServer;
|
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
|
+
}
|