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/dist/lifecycle.d.ts
CHANGED
|
@@ -1,133 +1,235 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Context
|
|
4
|
-
import {
|
|
5
|
-
import type { ToolCall } from "@kernl-sdk/protocol";
|
|
6
|
-
import { AgentOutputType } from "./agent/types.js";
|
|
7
|
-
import { TextOutput } from "./thread/types.js";
|
|
8
|
-
export type EventEmitterEvents = Record<string, any[]>;
|
|
1
|
+
import { Emitter } from "@kernl-sdk/shared";
|
|
2
|
+
import type { LanguageModelUsage, LanguageModelFinishReason, LanguageModelRequestSettings, ToolCallState } from "@kernl-sdk/protocol";
|
|
3
|
+
import type { Context } from "./context.js";
|
|
4
|
+
import type { ThreadState } from "./thread/types.js";
|
|
9
5
|
/**
|
|
10
|
-
*
|
|
6
|
+
* Emitted when a thread starts execution.
|
|
11
7
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
export interface ThreadStartEvent<TContext = unknown> {
|
|
9
|
+
readonly kind: "thread.start";
|
|
10
|
+
/**
|
|
11
|
+
* The thread ID.
|
|
12
|
+
*/
|
|
13
|
+
threadId: string;
|
|
14
|
+
/**
|
|
15
|
+
* The agent executing this thread.
|
|
16
|
+
*/
|
|
17
|
+
agentId: string;
|
|
18
|
+
/**
|
|
19
|
+
* The namespace of the thread.
|
|
20
|
+
*/
|
|
21
|
+
namespace: string;
|
|
22
|
+
/**
|
|
23
|
+
* The context for this execution.
|
|
24
|
+
*
|
|
25
|
+
* NOTE: Includes `context.agent` reference for tools - may be optimized in future.
|
|
26
|
+
*/
|
|
27
|
+
context: Context<TContext>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Emitted when a thread stops execution.
|
|
31
|
+
*/
|
|
32
|
+
export interface ThreadStopEvent<TContext = unknown, TOutput = unknown> {
|
|
33
|
+
readonly kind: "thread.stop";
|
|
34
|
+
/**
|
|
35
|
+
* The thread ID.
|
|
36
|
+
*/
|
|
37
|
+
threadId: string;
|
|
38
|
+
/**
|
|
39
|
+
* The agent that executed this thread.
|
|
40
|
+
*/
|
|
41
|
+
agentId: string;
|
|
42
|
+
/**
|
|
43
|
+
* The namespace of the thread.
|
|
44
|
+
*/
|
|
45
|
+
namespace: string;
|
|
46
|
+
/**
|
|
47
|
+
* The context for this execution.
|
|
48
|
+
*
|
|
49
|
+
* NOTE: Includes `context.agent` reference for tools - may be optimized in future.
|
|
50
|
+
*/
|
|
51
|
+
context: Context<TContext>;
|
|
52
|
+
/**
|
|
53
|
+
* Final state of the thread.
|
|
54
|
+
*/
|
|
55
|
+
state: ThreadState;
|
|
56
|
+
/**
|
|
57
|
+
* The outcome of the execution.
|
|
58
|
+
*/
|
|
59
|
+
outcome: "success" | "error" | "cancelled";
|
|
60
|
+
/**
|
|
61
|
+
* The result if outcome is "success".
|
|
62
|
+
*/
|
|
63
|
+
result?: TOutput;
|
|
64
|
+
/**
|
|
65
|
+
* Error message if outcome is "error".
|
|
66
|
+
*/
|
|
67
|
+
error?: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Emitted when a model call starts.
|
|
71
|
+
*/
|
|
72
|
+
export interface ModelCallStartEvent<TContext = unknown> {
|
|
73
|
+
readonly kind: "model.call.start";
|
|
74
|
+
/**
|
|
75
|
+
* The model provider.
|
|
76
|
+
*/
|
|
77
|
+
provider: string;
|
|
78
|
+
/**
|
|
79
|
+
* The model ID.
|
|
80
|
+
*/
|
|
81
|
+
modelId: string;
|
|
82
|
+
/**
|
|
83
|
+
* Request settings passed to the model.
|
|
84
|
+
*/
|
|
85
|
+
settings: LanguageModelRequestSettings;
|
|
86
|
+
/**
|
|
87
|
+
* Thread ID if called within a thread context.
|
|
88
|
+
*/
|
|
89
|
+
threadId?: string;
|
|
90
|
+
/**
|
|
91
|
+
* Agent ID if called within an agent context.
|
|
92
|
+
*/
|
|
93
|
+
agentId?: string;
|
|
94
|
+
/**
|
|
95
|
+
* Execution context if available.
|
|
96
|
+
*
|
|
97
|
+
* NOTE: Includes `context.agent` reference for tools - may be optimized in future.
|
|
98
|
+
*/
|
|
99
|
+
context?: Context<TContext>;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Emitted when a model call ends.
|
|
103
|
+
*/
|
|
104
|
+
export interface ModelCallEndEvent<TContext = unknown> {
|
|
105
|
+
readonly kind: "model.call.end";
|
|
106
|
+
/**
|
|
107
|
+
* The model provider.
|
|
108
|
+
*/
|
|
109
|
+
provider: string;
|
|
110
|
+
/**
|
|
111
|
+
* The model ID.
|
|
112
|
+
*/
|
|
113
|
+
modelId: string;
|
|
114
|
+
/**
|
|
115
|
+
* Reason the model stopped generating.
|
|
116
|
+
*/
|
|
117
|
+
finishReason: LanguageModelFinishReason;
|
|
118
|
+
/**
|
|
119
|
+
* Token usage for this call.
|
|
120
|
+
*/
|
|
121
|
+
usage?: LanguageModelUsage;
|
|
122
|
+
/**
|
|
123
|
+
* Thread ID if called within a thread context.
|
|
124
|
+
*/
|
|
125
|
+
threadId?: string;
|
|
126
|
+
/**
|
|
127
|
+
* Agent ID if called within an agent context.
|
|
128
|
+
*/
|
|
129
|
+
agentId?: string;
|
|
130
|
+
/**
|
|
131
|
+
* Execution context if available.
|
|
132
|
+
*
|
|
133
|
+
* NOTE: Includes `context.agent` reference for tools - may be optimized in future.
|
|
134
|
+
*/
|
|
135
|
+
context?: Context<TContext>;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Emitted when a tool call starts.
|
|
139
|
+
*/
|
|
140
|
+
export interface ToolCallStartEvent<TContext = unknown> {
|
|
141
|
+
readonly kind: "tool.call.start";
|
|
142
|
+
/**
|
|
143
|
+
* The thread ID.
|
|
144
|
+
*/
|
|
145
|
+
threadId: string;
|
|
146
|
+
/**
|
|
147
|
+
* The agent executing this tool.
|
|
148
|
+
*/
|
|
149
|
+
agentId: string;
|
|
150
|
+
/**
|
|
151
|
+
* The context for this execution.
|
|
152
|
+
*
|
|
153
|
+
* NOTE: Includes `context.agent` reference for tools - may be optimized in future.
|
|
154
|
+
*/
|
|
155
|
+
context: Context<TContext>;
|
|
156
|
+
/**
|
|
157
|
+
* The tool being called.
|
|
158
|
+
*/
|
|
159
|
+
toolId: string;
|
|
160
|
+
/**
|
|
161
|
+
* Unique identifier for this call.
|
|
162
|
+
*/
|
|
163
|
+
callId: string;
|
|
164
|
+
/**
|
|
165
|
+
* Arguments passed to the tool (parsed JSON).
|
|
166
|
+
*/
|
|
167
|
+
args: Record<string, unknown>;
|
|
21
168
|
}
|
|
22
|
-
export type AgentHookEvents<TContext = UnknownContext, TOutput extends AgentOutputType = TextOutput> = {
|
|
23
|
-
/**
|
|
24
|
-
* @param context - The context of the run
|
|
25
|
-
*/
|
|
26
|
-
agent_start: [context: Context<TContext>, agent: Agent<TContext, TOutput>];
|
|
27
|
-
/**
|
|
28
|
-
* @param context - The context of the run
|
|
29
|
-
* @param output - The output of the agent
|
|
30
|
-
*/
|
|
31
|
-
agent_end: [context: Context<TContext>, output: string];
|
|
32
|
-
/**
|
|
33
|
-
* @param context - The context of the run
|
|
34
|
-
* @param agent - The agent that is starting a tool
|
|
35
|
-
* @param tool - The tool that is starting
|
|
36
|
-
*/
|
|
37
|
-
agent_tool_start: [
|
|
38
|
-
context: Context<TContext>,
|
|
39
|
-
tool: Tool<any>,
|
|
40
|
-
details: {
|
|
41
|
-
toolCall: ToolCall;
|
|
42
|
-
}
|
|
43
|
-
];
|
|
44
|
-
/**
|
|
45
|
-
* @param context - The context of the run
|
|
46
|
-
* @param agent - The agent that is ending a tool
|
|
47
|
-
* @param tool - The tool that is ending
|
|
48
|
-
* @param result - The result of the tool
|
|
49
|
-
*/
|
|
50
|
-
agent_tool_end: [
|
|
51
|
-
context: Context<TContext>,
|
|
52
|
-
tool: Tool<any>,
|
|
53
|
-
result: string,
|
|
54
|
-
details: {
|
|
55
|
-
toolCall: ToolCall;
|
|
56
|
-
}
|
|
57
|
-
];
|
|
58
|
-
};
|
|
59
169
|
/**
|
|
60
|
-
*
|
|
61
|
-
* of the agent.
|
|
170
|
+
* Emitted when a tool call ends.
|
|
62
171
|
*/
|
|
63
|
-
export
|
|
172
|
+
export interface ToolCallEndEvent<TContext = unknown> {
|
|
173
|
+
readonly kind: "tool.call.end";
|
|
174
|
+
/**
|
|
175
|
+
* The thread ID.
|
|
176
|
+
*/
|
|
177
|
+
threadId: string;
|
|
178
|
+
/**
|
|
179
|
+
* The agent that executed this tool.
|
|
180
|
+
*/
|
|
181
|
+
agentId: string;
|
|
182
|
+
/**
|
|
183
|
+
* The context for this execution.
|
|
184
|
+
*
|
|
185
|
+
* NOTE: Includes `context.agent` reference for tools - may be optimized in future.
|
|
186
|
+
*/
|
|
187
|
+
context: Context<TContext>;
|
|
188
|
+
/**
|
|
189
|
+
* The tool that was called.
|
|
190
|
+
*/
|
|
191
|
+
toolId: string;
|
|
192
|
+
/**
|
|
193
|
+
* Unique identifier for this call.
|
|
194
|
+
*/
|
|
195
|
+
callId: string;
|
|
196
|
+
/**
|
|
197
|
+
* Final state of the tool call.
|
|
198
|
+
*/
|
|
199
|
+
state: ToolCallState;
|
|
200
|
+
/**
|
|
201
|
+
* Result if state is "completed".
|
|
202
|
+
*/
|
|
203
|
+
result?: string;
|
|
204
|
+
/**
|
|
205
|
+
* Error message if state is "failed", null if successful.
|
|
206
|
+
*/
|
|
207
|
+
error: string | null;
|
|
64
208
|
}
|
|
209
|
+
export type LifecycleEvent<TContext = unknown, TOutput = unknown> = ThreadStartEvent<TContext> | ThreadStopEvent<TContext, TOutput> | ModelCallStartEvent<TContext> | ModelCallEndEvent<TContext> | ToolCallStartEvent<TContext> | ToolCallEndEvent<TContext>;
|
|
65
210
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* Unlike AgentHookEvents (which are emitted by individual agents with implicit context),
|
|
69
|
-
* KernlHookEvents explicitly include the agent reference in all events since it needs to
|
|
70
|
-
* coordinate multiple agents and listeners need to know which agent triggered each event.
|
|
211
|
+
* Event map for agent-level lifecycle hooks (typed).
|
|
71
212
|
*/
|
|
72
|
-
export type
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
* @param context - The context of the run
|
|
80
|
-
* @param agent - The agent that is ending
|
|
81
|
-
* @param output - The output of the agent
|
|
82
|
-
*/
|
|
83
|
-
agent_end: [
|
|
84
|
-
context: Context<TContext>,
|
|
85
|
-
agent: Agent<TContext, TOutput>,
|
|
86
|
-
output: string
|
|
87
|
-
];
|
|
88
|
-
/**
|
|
89
|
-
* @param context - The context of the run
|
|
90
|
-
* @param fromAgent - The agent that is handing off
|
|
91
|
-
* @param toAgent - The next agent to run
|
|
92
|
-
*/
|
|
93
|
-
agent_handoff: [
|
|
94
|
-
context: Context<TContext>,
|
|
95
|
-
fromAgent: Agent<any, any>,
|
|
96
|
-
toAgent: Agent<any, any>
|
|
97
|
-
];
|
|
98
|
-
/**
|
|
99
|
-
* @param context - The context of the run
|
|
100
|
-
* @param agent - The agent that is starting a tool
|
|
101
|
-
* @param tool - The tool that is starting
|
|
102
|
-
*/
|
|
103
|
-
agent_tool_start: [
|
|
104
|
-
context: Context<TContext>,
|
|
105
|
-
agent: Agent<TContext, TOutput>,
|
|
106
|
-
tool: Tool,
|
|
107
|
-
details: {
|
|
108
|
-
toolCall: ToolCall;
|
|
109
|
-
}
|
|
110
|
-
];
|
|
111
|
-
/**
|
|
112
|
-
* @param context - The context of the run
|
|
113
|
-
* @param agent - The agent that is ending a tool
|
|
114
|
-
* @param tool - The tool that is ending
|
|
115
|
-
* @param result - The result of the tool
|
|
116
|
-
*/
|
|
117
|
-
agent_tool_end: [
|
|
118
|
-
context: Context<TContext>,
|
|
119
|
-
agent: Agent<TContext, TOutput>,
|
|
120
|
-
tool: Tool,
|
|
121
|
-
result: string,
|
|
122
|
-
details: {
|
|
123
|
-
toolCall: ToolCall;
|
|
124
|
-
}
|
|
125
|
-
];
|
|
213
|
+
export type AgentHookEvents<TContext = unknown, TOutput = unknown> = {
|
|
214
|
+
"thread.start": [event: ThreadStartEvent<TContext>];
|
|
215
|
+
"thread.stop": [event: ThreadStopEvent<TContext, TOutput>];
|
|
216
|
+
"model.call.start": [event: ModelCallStartEvent<TContext>];
|
|
217
|
+
"model.call.end": [event: ModelCallEndEvent<TContext>];
|
|
218
|
+
"tool.call.start": [event: ToolCallStartEvent<TContext>];
|
|
219
|
+
"tool.call.end": [event: ToolCallEndEvent<TContext>];
|
|
126
220
|
};
|
|
127
221
|
/**
|
|
128
|
-
* Event
|
|
222
|
+
* Event map for Kernl-level lifecycle hooks (untyped).
|
|
223
|
+
*/
|
|
224
|
+
export type KernlHookEvents = AgentHookEvents<unknown, unknown>;
|
|
225
|
+
/**
|
|
226
|
+
* Event emitter for agent-level lifecycle events.
|
|
227
|
+
*/
|
|
228
|
+
export declare class AgentHooks<TContext = unknown, TOutput = unknown> extends Emitter<AgentHookEvents<TContext, TOutput>> {
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Event emitter for Kernl-level lifecycle events.
|
|
129
232
|
*/
|
|
130
|
-
export declare class KernlHooks
|
|
233
|
+
export declare class KernlHooks extends Emitter<KernlHookEvents> {
|
|
131
234
|
}
|
|
132
|
-
export {};
|
|
133
235
|
//# sourceMappingURL=lifecycle.d.ts.map
|
package/dist/lifecycle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,KAAK,EACV,kBAAkB,EAClB,yBAAyB,EACzB,4BAA4B,EAC5B,aAAa,EACd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAIlD;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,QAAQ,GAAG,OAAO;IAClD,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAE9B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;;OAIG;IACH,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,QAAQ,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO;IACpE,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAE7B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;;OAIG;IACH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cAAc,EAAE,CAAC,KAAK,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC;IACpD,aAAa,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3D,kBAAkB,EAAE,CAAC,KAAK,EAAE,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC3D,gBAAgB,EAAE,CAAC,KAAK,EAAE,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC;IACvD,iBAAiB,EAAE,CAAC,KAAK,EAAE,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC;IACzD,eAAe,EAAE,CAAC,KAAK,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC;CACtD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAEhE;;GAEG;AACH,qBAAa,UAAU,CACrB,QAAQ,GAAG,OAAO,EAClB,OAAO,GAAG,OAAO,CACjB,SAAQ,OAAO,CAAC,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;CAAG;AAExD;;GAEG;AACH,qBAAa,UAAW,SAAQ,OAAO,CAAC,eAAe,CAAC;CAAG"}
|
package/dist/lifecycle.js
CHANGED
|
@@ -1,29 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Emitter } from "@kernl-sdk/shared";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Event emitter for agent-level lifecycle events.
|
|
4
4
|
*/
|
|
5
|
-
class
|
|
6
|
-
on(event, listener) {
|
|
7
|
-
return super.on(event, listener);
|
|
8
|
-
}
|
|
9
|
-
off(event, listener) {
|
|
10
|
-
return super.off(event, listener);
|
|
11
|
-
}
|
|
12
|
-
emit(event, ...args) {
|
|
13
|
-
return super.emit(event, ...args);
|
|
14
|
-
}
|
|
15
|
-
once(event, listener) {
|
|
16
|
-
return super.once(event, listener);
|
|
17
|
-
}
|
|
5
|
+
export class AgentHooks extends Emitter {
|
|
18
6
|
}
|
|
19
7
|
/**
|
|
20
|
-
* Event emitter
|
|
21
|
-
* of the agent.
|
|
8
|
+
* Event emitter for Kernl-level lifecycle events.
|
|
22
9
|
*/
|
|
23
|
-
export class
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Event emitter that the kernl uses to emit events for the lifecycle of every agent run.
|
|
27
|
-
*/
|
|
28
|
-
export class KernlHooks extends TypedEventEmitter {
|
|
10
|
+
export class KernlHooks extends Emitter {
|
|
29
11
|
}
|
package/dist/memory/memory.js
CHANGED
package/dist/realtime/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/realtime/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/realtime/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
|
package/dist/realtime/index.js
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { RealtimeModel } from "@kernl-sdk/protocol";
|
|
1
|
+
import { Emitter } from "@kernl-sdk/shared";
|
|
2
|
+
import { RealtimeModel, RealtimeServerEvent, RealtimeChannel, TransportStatus } from "@kernl-sdk/protocol";
|
|
3
3
|
import { Context, UnknownContext } from "../context.js";
|
|
4
4
|
import { RealtimeAgent } from "./agent.js";
|
|
5
|
-
import type { RealtimeChannel } from "./channel.js";
|
|
6
5
|
import type { RealtimeSessionOptions } from "./types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Events emitted by a realtime session.
|
|
8
|
+
*/
|
|
9
|
+
export type RealtimeSessionEvents = {
|
|
10
|
+
audio: [event: RealtimeServerEvent];
|
|
11
|
+
transcript: [event: RealtimeServerEvent];
|
|
12
|
+
text: [event: RealtimeServerEvent];
|
|
13
|
+
error: [error: Error];
|
|
14
|
+
status: [status: TransportStatus];
|
|
15
|
+
};
|
|
7
16
|
/**
|
|
8
17
|
* A realtime session manages the connection to a realtime model.
|
|
9
18
|
*
|
|
10
19
|
* Handles the bidirectional communication between an agent and a model,
|
|
11
20
|
* including audio I/O (via channels), tool execution, and event routing.
|
|
12
21
|
*/
|
|
13
|
-
export declare class RealtimeSession<TContext = UnknownContext> extends
|
|
22
|
+
export declare class RealtimeSession<TContext = UnknownContext> extends Emitter<RealtimeSessionEvents> {
|
|
14
23
|
/**
|
|
15
24
|
* Session ID. Null until connected.
|
|
16
25
|
*/
|
|
@@ -48,24 +57,6 @@ export declare class RealtimeSession<TContext = UnknownContext> extends EventEmi
|
|
|
48
57
|
* Initialize event listeners and send session configuration.
|
|
49
58
|
*/
|
|
50
59
|
private init;
|
|
51
|
-
/**
|
|
52
|
-
* Build session configuration from agent.
|
|
53
|
-
*/
|
|
54
|
-
private buildSessionConfig;
|
|
55
|
-
/**
|
|
56
|
-
* Handle incoming events from the connection.
|
|
57
|
-
*
|
|
58
|
-
* Maps protocol events to simplified user-facing events:
|
|
59
|
-
* - 'audio' - audio output from assistant
|
|
60
|
-
* - 'transcript' - speech transcriptions (user or assistant)
|
|
61
|
-
* - 'text' - text output from assistant
|
|
62
|
-
* - 'error' - errors
|
|
63
|
-
*/
|
|
64
|
-
private onEvent;
|
|
65
|
-
/**
|
|
66
|
-
* Execute tool calls from the model.
|
|
67
|
-
*/
|
|
68
|
-
private performActions;
|
|
69
60
|
/**
|
|
70
61
|
* Send audio to the model.
|
|
71
62
|
*/
|
|
@@ -94,5 +85,23 @@ export declare class RealtimeSession<TContext = UnknownContext> extends EventEmi
|
|
|
94
85
|
* Close the session and release resources.
|
|
95
86
|
*/
|
|
96
87
|
close(): void;
|
|
88
|
+
/**
|
|
89
|
+
* Build session configuration from agent.
|
|
90
|
+
*/
|
|
91
|
+
private buildSessionConfig;
|
|
92
|
+
/**
|
|
93
|
+
* Handle incoming events from the connection.
|
|
94
|
+
*
|
|
95
|
+
* Maps protocol events to simplified user-facing events:
|
|
96
|
+
* - 'audio' - audio output from assistant
|
|
97
|
+
* - 'transcript' - speech transcriptions (user or assistant)
|
|
98
|
+
* - 'text' - text output from assistant
|
|
99
|
+
* - 'error' - errors
|
|
100
|
+
*/
|
|
101
|
+
private onEvent;
|
|
102
|
+
/**
|
|
103
|
+
* Execute tool calls from the model.
|
|
104
|
+
*/
|
|
105
|
+
private performActions;
|
|
97
106
|
}
|
|
98
107
|
//# sourceMappingURL=session.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/realtime/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/realtime/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EACL,aAAa,EAEb,mBAAmB,EAEnB,eAAe,EAEf,eAAe,EAEhB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAGpD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEtD;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC;IACpC,UAAU,EAAE,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC;IACzC,IAAI,EAAE,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC;IACnC,KAAK,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACtB,MAAM,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,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