kernl 0.9.1 → 0.11.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 +1 -1
- package/CHANGELOG.md +34 -0
- package/dist/agent/base.d.ts +5 -1
- package/dist/agent/base.d.ts.map +1 -1
- package/dist/agent/base.js +8 -0
- package/dist/agent.d.ts +1 -1
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +15 -2
- package/dist/context.d.ts +2 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +2 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/kernl/kernl.d.ts +1 -2
- package/dist/kernl/kernl.d.ts.map +1 -1
- package/dist/kernl/kernl.js +61 -1
- package/dist/lib/env.d.ts.map +1 -1
- package/dist/lib/env.js +1 -1
- package/dist/lifecycle/__tests__/hooks.test.d.ts +2 -0
- package/dist/lifecycle/__tests__/hooks.test.d.ts.map +1 -0
- package/dist/lifecycle/__tests__/hooks.test.js +553 -0
- package/dist/lifecycle.d.ts +222 -120
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +5 -23
- package/dist/memory/memory.js +1 -1
- package/dist/realtime/index.d.ts +1 -1
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js +1 -1
- package/dist/realtime/session.d.ts +31 -22
- package/dist/realtime/session.d.ts.map +1 -1
- package/dist/realtime/session.js +64 -55
- package/dist/realtime/transport.d.ts +45 -0
- package/dist/realtime/transport.d.ts.map +1 -0
- package/dist/realtime/transport.js +32 -0
- package/dist/realtime/types.d.ts +8 -2
- package/dist/realtime/types.d.ts.map +1 -1
- package/dist/thread/__tests__/thread.test.js +2 -2
- package/dist/thread/thread.d.ts +2 -2
- package/dist/thread/thread.d.ts.map +1 -1
- package/dist/thread/thread.js +75 -8
- package/dist/thread/types.d.ts +1 -1
- package/dist/thread/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/agent/base.ts +13 -1
- package/src/agent.ts +17 -3
- package/src/context.ts +2 -0
- package/src/index.ts +10 -1
- package/src/kernl/kernl.ts +67 -3
- package/src/lib/env.ts +3 -1
- package/src/lifecycle/__tests__/hooks.test.ts +668 -0
- package/src/lifecycle.ts +289 -163
- package/src/memory/memory.ts +1 -1
- package/src/realtime/index.ts +1 -1
- package/src/realtime/session.ts +88 -64
- package/src/realtime/transport.ts +64 -0
- package/src/realtime/types.ts +10 -2
- package/src/thread/__tests__/thread.test.ts +2 -2
- package/src/thread/thread.ts +88 -10
- package/src/thread/types.ts +1 -1
- package/dist/realtime/channel.d.ts +0 -30
- package/dist/realtime/channel.d.ts.map +0 -1
- package/dist/realtime/channel.js +0 -1
- package/src/realtime/channel.ts +0 -32
package/src/kernl/kernl.ts
CHANGED
|
@@ -2,7 +2,6 @@ import type { LanguageModel } from "@kernl-sdk/protocol";
|
|
|
2
2
|
import { resolveEmbeddingModel } from "@kernl-sdk/retrieval";
|
|
3
3
|
|
|
4
4
|
import { BaseAgent } from "@/agent/base";
|
|
5
|
-
import { UnknownContext } from "@/context";
|
|
6
5
|
import { KernlHooks } from "@/lifecycle";
|
|
7
6
|
import type { Thread } from "@/thread";
|
|
8
7
|
import type { ResolvedAgentResponse } from "@/guardrail";
|
|
@@ -28,7 +27,7 @@ import type { KernlOptions, MemoryOptions, StorageOptions } from "./types";
|
|
|
28
27
|
* Orchestrates agent execution, including guardrails, tool calls, session persistence, and
|
|
29
28
|
* tracing.
|
|
30
29
|
*/
|
|
31
|
-
export class Kernl extends KernlHooks
|
|
30
|
+
export class Kernl extends KernlHooks {
|
|
32
31
|
private readonly _agents: Map<string, BaseAgent> = new Map();
|
|
33
32
|
private readonly _models: Map<string, LanguageModel> = new Map();
|
|
34
33
|
|
|
@@ -103,8 +102,42 @@ export class Kernl extends KernlHooks<UnknownContext, AgentOutputType> {
|
|
|
103
102
|
thread: Thread<TContext, TOutput>,
|
|
104
103
|
): Promise<ThreadExecuteResult<ResolvedAgentResponse<TOutput>>> {
|
|
105
104
|
this.athreads.set(thread.tid, thread);
|
|
105
|
+
|
|
106
|
+
this.emit("thread.start", {
|
|
107
|
+
kind: "thread.start",
|
|
108
|
+
threadId: thread.tid,
|
|
109
|
+
agentId: thread.agent.id,
|
|
110
|
+
namespace: thread.namespace,
|
|
111
|
+
context: thread.context,
|
|
112
|
+
});
|
|
113
|
+
|
|
106
114
|
try {
|
|
107
|
-
|
|
115
|
+
const result = await thread.execute();
|
|
116
|
+
|
|
117
|
+
this.emit("thread.stop", {
|
|
118
|
+
kind: "thread.stop",
|
|
119
|
+
threadId: thread.tid,
|
|
120
|
+
agentId: thread.agent.id,
|
|
121
|
+
namespace: thread.namespace,
|
|
122
|
+
context: thread.context,
|
|
123
|
+
state: thread.state,
|
|
124
|
+
outcome: "success",
|
|
125
|
+
result: result.response,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
return result;
|
|
129
|
+
} catch (err) {
|
|
130
|
+
this.emit("thread.stop", {
|
|
131
|
+
kind: "thread.stop",
|
|
132
|
+
threadId: thread.tid,
|
|
133
|
+
agentId: thread.agent.id,
|
|
134
|
+
namespace: thread.namespace,
|
|
135
|
+
context: thread.context,
|
|
136
|
+
state: thread.state,
|
|
137
|
+
outcome: "error",
|
|
138
|
+
error: err instanceof Error ? err.message : String(err),
|
|
139
|
+
});
|
|
140
|
+
throw err;
|
|
108
141
|
} finally {
|
|
109
142
|
this.athreads.delete(thread.tid);
|
|
110
143
|
}
|
|
@@ -135,8 +168,39 @@ export class Kernl extends KernlHooks<UnknownContext, AgentOutputType> {
|
|
|
135
168
|
thread: Thread<TContext, TOutput>,
|
|
136
169
|
): AsyncIterable<ThreadStreamEvent> {
|
|
137
170
|
this.athreads.set(thread.tid, thread);
|
|
171
|
+
|
|
172
|
+
this.emit("thread.start", {
|
|
173
|
+
kind: "thread.start",
|
|
174
|
+
threadId: thread.tid,
|
|
175
|
+
agentId: thread.agent.id,
|
|
176
|
+
namespace: thread.namespace,
|
|
177
|
+
context: thread.context,
|
|
178
|
+
});
|
|
179
|
+
|
|
138
180
|
try {
|
|
139
181
|
yield* thread.stream();
|
|
182
|
+
|
|
183
|
+
this.emit("thread.stop", {
|
|
184
|
+
kind: "thread.stop",
|
|
185
|
+
threadId: thread.tid,
|
|
186
|
+
agentId: thread.agent.id,
|
|
187
|
+
namespace: thread.namespace,
|
|
188
|
+
context: thread.context,
|
|
189
|
+
state: thread.state,
|
|
190
|
+
outcome: "success",
|
|
191
|
+
});
|
|
192
|
+
} catch (err) {
|
|
193
|
+
this.emit("thread.stop", {
|
|
194
|
+
kind: "thread.stop",
|
|
195
|
+
threadId: thread.tid,
|
|
196
|
+
agentId: thread.agent.id,
|
|
197
|
+
namespace: thread.namespace,
|
|
198
|
+
context: thread.context,
|
|
199
|
+
state: thread.state,
|
|
200
|
+
outcome: "error",
|
|
201
|
+
error: err instanceof Error ? err.message : String(err),
|
|
202
|
+
});
|
|
203
|
+
throw err;
|
|
140
204
|
} finally {
|
|
141
205
|
this.athreads.delete(thread.tid);
|
|
142
206
|
}
|
package/src/lib/env.ts
CHANGED
|
@@ -28,7 +28,9 @@ const envSchema = z.object({
|
|
|
28
28
|
* import { env } from '@/env';
|
|
29
29
|
* console.log(env.LOG_LEVEL);
|
|
30
30
|
*/
|
|
31
|
-
export const env = envSchema.parse(
|
|
31
|
+
export const env = envSchema.parse(
|
|
32
|
+
typeof process !== "undefined" ? process.env : {},
|
|
33
|
+
);
|
|
32
34
|
|
|
33
35
|
/**
|
|
34
36
|
* Type of the validated environment variables
|