kernl 0.8.3 → 0.9.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 +21 -0
- package/dist/agent/base.d.ts +73 -0
- package/dist/agent/base.d.ts.map +1 -0
- package/dist/agent/base.js +137 -0
- package/dist/agent/index.d.ts +2 -0
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +2 -1
- package/dist/agent/types.d.ts +4 -0
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent.d.ts +10 -90
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +5 -171
- package/dist/api/resources/agents/agents.d.ts +11 -7
- package/dist/api/resources/agents/agents.d.ts.map +1 -1
- package/dist/api/resources/agents/agents.js +14 -8
- package/dist/kernl/__tests__/memory-config.test.d.ts +2 -0
- package/dist/kernl/__tests__/memory-config.test.d.ts.map +1 -0
- package/dist/kernl/__tests__/memory-config.test.js +157 -0
- package/dist/kernl/kernl.d.ts +11 -2
- package/dist/kernl/kernl.d.ts.map +1 -1
- package/dist/kernl/kernl.js +62 -28
- package/dist/kernl/types.d.ts +6 -5
- package/dist/kernl/types.d.ts.map +1 -1
- package/dist/lib/env.d.ts +2 -2
- package/dist/mcp/__tests__/utils.test.js +4 -2
- package/dist/mcp/utils.d.ts +1 -1
- package/dist/mcp/utils.js +1 -1
- package/dist/memory/__tests__/encoder.test.js +46 -0
- package/dist/memory/codecs/domain.js +1 -2
- package/dist/memory/encoder.d.ts +7 -7
- package/dist/memory/encoder.d.ts.map +1 -1
- package/dist/memory/encoder.js +15 -7
- package/dist/memory/memory.js +1 -1
- package/dist/memory/types.d.ts +6 -2
- package/dist/memory/types.d.ts.map +1 -1
- package/dist/realtime/agent.d.ts +17 -0
- package/dist/realtime/agent.d.ts.map +1 -0
- package/dist/realtime/agent.js +17 -0
- package/dist/realtime/channel.d.ts +30 -0
- package/dist/realtime/channel.d.ts.map +1 -0
- package/dist/realtime/channel.js +1 -0
- package/dist/realtime/index.d.ts +5 -0
- package/dist/realtime/index.d.ts.map +1 -0
- package/dist/realtime/index.js +4 -0
- package/dist/realtime/session.d.ts +98 -0
- package/dist/realtime/session.d.ts.map +1 -0
- package/dist/realtime/session.js +203 -0
- package/dist/realtime/types.d.ts +58 -0
- package/dist/realtime/types.d.ts.map +1 -0
- package/dist/realtime/types.js +1 -0
- package/dist/storage/in-memory.d.ts.map +1 -1
- package/dist/storage/in-memory.js +5 -1
- package/dist/tool/__tests__/toolkit.test.js +2 -2
- package/dist/tool/tool.d.ts +2 -1
- package/dist/tool/tool.d.ts.map +1 -1
- package/dist/tool/toolkit.d.ts +4 -4
- package/dist/tool/toolkit.d.ts.map +1 -1
- package/dist/tool/toolkit.js +2 -1
- package/dist/tool/types.d.ts +4 -4
- package/dist/tool/types.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/agent/base.ts +220 -0
- package/src/agent/index.ts +2 -0
- package/src/agent/types.ts +5 -0
- package/src/agent.ts +12 -231
- package/src/api/resources/agents/agents.ts +19 -13
- package/src/kernl/__tests__/memory-config.test.ts +203 -0
- package/src/kernl/kernl.ts +81 -39
- package/src/kernl/types.ts +6 -5
- package/src/mcp/__tests__/utils.test.ts +4 -2
- package/src/mcp/utils.ts +1 -1
- package/src/memory/__tests__/encoder.test.ts +63 -0
- package/src/memory/codecs/domain.ts +1 -1
- package/src/memory/encoder.ts +18 -10
- package/src/memory/memory.ts +1 -1
- package/src/memory/types.ts +6 -2
- package/src/realtime/agent.ts +24 -0
- package/src/realtime/channel.ts +32 -0
- package/src/realtime/index.ts +4 -0
- package/src/realtime/session.ts +259 -0
- package/src/realtime/types.ts +73 -0
- package/src/storage/in-memory.ts +9 -1
- package/src/tool/__tests__/toolkit.test.ts +2 -2
- package/src/tool/tool.ts +2 -1
- package/src/tool/toolkit.ts +6 -5
- package/src/tool/types.ts +4 -4
package/dist/memory/encoder.js
CHANGED
|
@@ -33,6 +33,7 @@ export const ObjectTextCodec = {
|
|
|
33
33
|
* Encoder that converts MemoryByte to IndexableByte.
|
|
34
34
|
*
|
|
35
35
|
* Extracts canonical text from content and computes embeddings.
|
|
36
|
+
* If no embedder is provided, skips embedding and tvec will be undefined.
|
|
36
37
|
*/
|
|
37
38
|
export class MemoryByteEncoder {
|
|
38
39
|
embedder;
|
|
@@ -45,9 +46,6 @@ export class MemoryByteEncoder {
|
|
|
45
46
|
* - Produces `objtext` string projection for FTS indexing
|
|
46
47
|
* - Combines text + objtext for embedding input
|
|
47
48
|
* - Returns text (fallback to objtext if no text provided)
|
|
48
|
-
*
|
|
49
|
-
* Note: metadata is NOT set here - it comes from record.metadata
|
|
50
|
-
* via the domain codec, not from MemoryByte.object.
|
|
51
49
|
*/
|
|
52
50
|
async encode(byte) {
|
|
53
51
|
const objtext = byte.object
|
|
@@ -56,8 +54,9 @@ export class MemoryByteEncoder {
|
|
|
56
54
|
// (TODO): this behavior deserves consideration - do we always want to merge text + object?
|
|
57
55
|
//
|
|
58
56
|
// combine text + object for richer embedding
|
|
57
|
+
// skip embedding if no embedder configured (embed returns null)
|
|
59
58
|
const combined = [byte.text, objtext].filter(Boolean).join("\n");
|
|
60
|
-
const tvec = combined ? await this.embed(combined) :
|
|
59
|
+
const tvec = combined ? await this.embed(combined) : null;
|
|
61
60
|
// TODO: embed other modalities (image, audio, video)
|
|
62
61
|
//
|
|
63
62
|
// const ivec = byte.image ? await this.embedImage(byte.image) : undefined;
|
|
@@ -66,7 +65,7 @@ export class MemoryByteEncoder {
|
|
|
66
65
|
return {
|
|
67
66
|
text: byte.text ?? objtext, // fallback to projection if no text
|
|
68
67
|
objtext,
|
|
69
|
-
tvec,
|
|
68
|
+
tvec: tvec ?? undefined,
|
|
70
69
|
};
|
|
71
70
|
}
|
|
72
71
|
/**
|
|
@@ -77,10 +76,19 @@ export class MemoryByteEncoder {
|
|
|
77
76
|
}
|
|
78
77
|
/**
|
|
79
78
|
* Embed a text string.
|
|
80
|
-
*
|
|
79
|
+
*
|
|
80
|
+
* @returns Embedding vector, or null if no embedder configured.
|
|
81
|
+
* @throws If embedder returns empty embedding.
|
|
81
82
|
*/
|
|
82
83
|
async embed(text) {
|
|
84
|
+
if (!this.embedder) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
83
87
|
const result = await this.embedder.embed({ values: [text] });
|
|
84
|
-
|
|
88
|
+
const embedding = result.embeddings[0];
|
|
89
|
+
if (!embedding || embedding.length === 0) {
|
|
90
|
+
throw new Error("Embedder returned empty embedding");
|
|
91
|
+
}
|
|
92
|
+
return embedding;
|
|
85
93
|
}
|
|
86
94
|
}
|
package/dist/memory/memory.js
CHANGED
|
@@ -66,7 +66,7 @@ export class Memory {
|
|
|
66
66
|
}
|
|
67
67
|
const tvec = await this.encoder.embed(q.query);
|
|
68
68
|
return this._search.query({
|
|
69
|
-
query: [{ text: q.query, tvec }],
|
|
69
|
+
query: [{ text: q.query, tvec: tvec ?? undefined }],
|
|
70
70
|
filter: q.filter ? MEMORY_FILTER.encode(q.filter) : undefined,
|
|
71
71
|
topK: q.limit ?? 20,
|
|
72
72
|
});
|
package/dist/memory/types.d.ts
CHANGED
|
@@ -62,7 +62,12 @@ export interface IndexableByte {
|
|
|
62
62
|
* Encoder that converts MemoryByte to IndexableByte with embeddings.
|
|
63
63
|
*/
|
|
64
64
|
export interface MemoryByteCodec extends AsyncCodec<MemoryByte, IndexableByte> {
|
|
65
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Embed a text string.
|
|
67
|
+
*
|
|
68
|
+
* @returns Embedding vector, or null if no embedder configured.
|
|
69
|
+
*/
|
|
70
|
+
embed(text: string): Promise<number[] | null>;
|
|
66
71
|
}
|
|
67
72
|
export interface MemoryConfig {
|
|
68
73
|
store: MemoryStore;
|
|
@@ -261,7 +266,6 @@ export interface IndexMemoryRecordPatch {
|
|
|
261
266
|
collection?: string;
|
|
262
267
|
timestamp?: number;
|
|
263
268
|
updatedAt?: number;
|
|
264
|
-
metadata?: JSONObject | null;
|
|
265
269
|
}
|
|
266
270
|
export {};
|
|
267
271
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/memory/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAM3C,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAE9B;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,UAAU,GAAG,MAAM,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,UAAU,GAAG,MAAM,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,UAAU,GAAG,MAAM,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB;AAED;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,IAAI,CA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
|
+
import type { UnknownContext } from "../context.js";
|
|
3
|
+
import { BaseAgent } from "../agent/base.js";
|
|
4
|
+
import type { RealtimeAgentConfig, RealtimeAgentVoiceConfig } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* A realtime agent definition.
|
|
7
|
+
*
|
|
8
|
+
* Stateless configuration that describes what a realtime voice agent does.
|
|
9
|
+
* Create sessions with `new RealtimeSession(agent, options)`.
|
|
10
|
+
*/
|
|
11
|
+
export declare class RealtimeAgent<TContext = UnknownContext> extends BaseAgent<TContext> {
|
|
12
|
+
readonly kind = "realtime";
|
|
13
|
+
readonly model: RealtimeModel;
|
|
14
|
+
readonly voice?: RealtimeAgentVoiceConfig;
|
|
15
|
+
constructor(config: RealtimeAgentConfig<TContext>);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/realtime/agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,KAAK,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAE7E;;;;;GAKG;AACH,qBAAa,aAAa,CAAC,QAAQ,GAAG,cAAc,CAAE,SAAQ,SAAS,CAAC,QAAQ,CAAC;IAC/E,QAAQ,CAAC,IAAI,cAAc;IAC3B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,KAAK,CAAC,EAAE,wBAAwB,CAAC;gBAE9B,MAAM,EAAE,mBAAmB,CAAC,QAAQ,CAAC;CAKlD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseAgent } from "../agent/base.js";
|
|
2
|
+
/**
|
|
3
|
+
* A realtime agent definition.
|
|
4
|
+
*
|
|
5
|
+
* Stateless configuration that describes what a realtime voice agent does.
|
|
6
|
+
* Create sessions with `new RealtimeSession(agent, options)`.
|
|
7
|
+
*/
|
|
8
|
+
export class RealtimeAgent extends BaseAgent {
|
|
9
|
+
kind = "realtime";
|
|
10
|
+
model;
|
|
11
|
+
voice;
|
|
12
|
+
constructor(config) {
|
|
13
|
+
super(config);
|
|
14
|
+
this.model = config.model;
|
|
15
|
+
this.voice = config.voice;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
/**
|
|
3
|
+
* Base interface for audio I/O channels.
|
|
4
|
+
*
|
|
5
|
+
* Channels bridge between audio sources (browser mic, Twilio, Discord)
|
|
6
|
+
* and the realtime session. They handle audio capture/playback and emit
|
|
7
|
+
* events that the session listens to.
|
|
8
|
+
*
|
|
9
|
+
* Events emitted:
|
|
10
|
+
* - 'audio' (audio: string) - Raw audio chunk (base64)
|
|
11
|
+
* - 'commit' () - User finished speaking (VAD or manual)
|
|
12
|
+
* - 'interrupt' () - User started speaking mid-response
|
|
13
|
+
*/
|
|
14
|
+
export interface RealtimeChannel extends EventEmitter {
|
|
15
|
+
/**
|
|
16
|
+
* Send audio to be played/transmitted by the channel.
|
|
17
|
+
* Called by session when audio is received from the model.
|
|
18
|
+
*/
|
|
19
|
+
sendAudio(audio: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Interrupt current audio playback.
|
|
22
|
+
* Called by session when response is cancelled.
|
|
23
|
+
*/
|
|
24
|
+
interrupt(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Clean up resources and close the channel.
|
|
27
|
+
*/
|
|
28
|
+
close(): void;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=channel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel.d.ts","sourceRoot":"","sources":["../../src/realtime/channel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,eAAgB,SAAQ,YAAY;IACnD;;;OAGG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAE/B;;;OAGG;IACH,SAAS,IAAI,IAAI,CAAC;IAElB;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;CACf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/realtime/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import { RealtimeModel } from "@kernl-sdk/protocol";
|
|
3
|
+
import { Context, UnknownContext } from "../context.js";
|
|
4
|
+
import { RealtimeAgent } from "./agent.js";
|
|
5
|
+
import type { RealtimeChannel } from "./channel.js";
|
|
6
|
+
import type { RealtimeSessionOptions } from "./types.js";
|
|
7
|
+
/**
|
|
8
|
+
* A realtime session manages the connection to a realtime model.
|
|
9
|
+
*
|
|
10
|
+
* Handles the bidirectional communication between an agent and a model,
|
|
11
|
+
* including audio I/O (via channels), tool execution, and event routing.
|
|
12
|
+
*/
|
|
13
|
+
export declare class RealtimeSession<TContext = UnknownContext> extends EventEmitter {
|
|
14
|
+
/**
|
|
15
|
+
* Session ID. Null until connected.
|
|
16
|
+
*/
|
|
17
|
+
id: string | null;
|
|
18
|
+
/**
|
|
19
|
+
* The agent definition.
|
|
20
|
+
*/
|
|
21
|
+
readonly agent: RealtimeAgent<TContext>;
|
|
22
|
+
/**
|
|
23
|
+
* The realtime model.
|
|
24
|
+
*/
|
|
25
|
+
readonly model: RealtimeModel;
|
|
26
|
+
/**
|
|
27
|
+
* The audio I/O channel (if any).
|
|
28
|
+
*/
|
|
29
|
+
readonly channel: RealtimeChannel | null;
|
|
30
|
+
/**
|
|
31
|
+
* The session context.
|
|
32
|
+
*/
|
|
33
|
+
readonly context: Context<TContext>;
|
|
34
|
+
/**
|
|
35
|
+
* The active connection. Null until connected.
|
|
36
|
+
*/
|
|
37
|
+
private connection;
|
|
38
|
+
/**
|
|
39
|
+
* Session options.
|
|
40
|
+
*/
|
|
41
|
+
private options;
|
|
42
|
+
constructor(agent: RealtimeAgent<TContext>, options?: RealtimeSessionOptions<TContext>);
|
|
43
|
+
/**
|
|
44
|
+
* Connect to the realtime model.
|
|
45
|
+
*/
|
|
46
|
+
connect(): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Initialize event listeners and send session configuration.
|
|
49
|
+
*/
|
|
50
|
+
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
|
+
/**
|
|
70
|
+
* Send audio to the model.
|
|
71
|
+
*/
|
|
72
|
+
sendAudio(audio: string): void;
|
|
73
|
+
/**
|
|
74
|
+
* Commit the audio buffer (signal end of speech).
|
|
75
|
+
*/
|
|
76
|
+
commit(): void;
|
|
77
|
+
/**
|
|
78
|
+
* Send a text message to the model.
|
|
79
|
+
*/
|
|
80
|
+
sendMessage(text: string): void;
|
|
81
|
+
/**
|
|
82
|
+
* Interrupt the current response.
|
|
83
|
+
*/
|
|
84
|
+
interrupt(): void;
|
|
85
|
+
/**
|
|
86
|
+
* Mute audio input.
|
|
87
|
+
*/
|
|
88
|
+
mute(): void;
|
|
89
|
+
/**
|
|
90
|
+
* Unmute audio input.
|
|
91
|
+
*/
|
|
92
|
+
unmute(): void;
|
|
93
|
+
/**
|
|
94
|
+
* Close the session and release resources.
|
|
95
|
+
*/
|
|
96
|
+
close(): void;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/realtime/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EACL,aAAa,EAMd,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,eAAe,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEtD;;;;;GAKG;AACH,qBAAa,eAAe,CAAC,QAAQ,GAAG,cAAc,CAAE,SAAQ,YAAY;IAC1E;;OAEG;IACH,EAAE,EAAE,MAAM,GAAG,IAAI,CAAQ;IAEzB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IAExC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,CAAC;IAEzC;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEpC;;OAEG;IACH,OAAO,CAAC,UAAU,CAAmC;IAErD;;OAEG;IACH,OAAO,CAAC,OAAO,CAAmC;gBAGhD,KAAK,EAAE,aAAa,CAAC,QAAQ,CAAC,EAC9B,OAAO,GAAE,sBAAsB,CAAC,QAAQ,CAAM;IAiBhD;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAkB9B;;OAEG;YACW,IAAI;IAalB;;OAEG;YACW,kBAAkB;IAUhC;;;;;;;;OAQG;IACH,OAAO,CAAC,OAAO;IAuCf;;OAEG;YACW,cAAc;IAyB5B;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI9B;;OAEG;IACH,MAAM,IAAI,IAAI;IAId;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAO/B;;OAEG;IACH,SAAS,IAAI,IAAI;IAKjB;;OAEG;IACH,IAAI,IAAI,IAAI;IAIZ;;OAEG;IACH,MAAM,IAAI,IAAI;IAId;;OAEG;IACH,KAAK,IAAI,IAAI;CAId"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
|
+
import { message, } from "@kernl-sdk/protocol";
|
|
3
|
+
import { Context } from "../context.js";
|
|
4
|
+
import { MisconfiguredError } from "../lib/error.js";
|
|
5
|
+
/**
|
|
6
|
+
* A realtime session manages the connection to a realtime model.
|
|
7
|
+
*
|
|
8
|
+
* Handles the bidirectional communication between an agent and a model,
|
|
9
|
+
* including audio I/O (via channels), tool execution, and event routing.
|
|
10
|
+
*/
|
|
11
|
+
export class RealtimeSession extends EventEmitter {
|
|
12
|
+
/**
|
|
13
|
+
* Session ID. Null until connected.
|
|
14
|
+
*/
|
|
15
|
+
id = null;
|
|
16
|
+
/**
|
|
17
|
+
* The agent definition.
|
|
18
|
+
*/
|
|
19
|
+
agent;
|
|
20
|
+
/**
|
|
21
|
+
* The realtime model.
|
|
22
|
+
*/
|
|
23
|
+
model;
|
|
24
|
+
/**
|
|
25
|
+
* The audio I/O channel (if any).
|
|
26
|
+
*/
|
|
27
|
+
channel;
|
|
28
|
+
/**
|
|
29
|
+
* The session context.
|
|
30
|
+
*/
|
|
31
|
+
context;
|
|
32
|
+
/**
|
|
33
|
+
* The active connection. Null until connected.
|
|
34
|
+
*/
|
|
35
|
+
connection = null;
|
|
36
|
+
/**
|
|
37
|
+
* Session options.
|
|
38
|
+
*/
|
|
39
|
+
options;
|
|
40
|
+
constructor(agent, options = {}) {
|
|
41
|
+
super();
|
|
42
|
+
if (options.transport?.handlesAudio && options.channel) {
|
|
43
|
+
throw new MisconfiguredError("Cannot use channel with WebRTC transport - audio is handled by transport");
|
|
44
|
+
}
|
|
45
|
+
this.agent = agent;
|
|
46
|
+
this.model = options.model ?? agent.model;
|
|
47
|
+
this.channel = options.channel ?? null;
|
|
48
|
+
this.context = options.context ?? new Context("kernl", {});
|
|
49
|
+
this.options = options;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Connect to the realtime model.
|
|
53
|
+
*/
|
|
54
|
+
async connect() {
|
|
55
|
+
const sessionConfig = await this.buildSessionConfig();
|
|
56
|
+
const options = {
|
|
57
|
+
...this.options.connectOptions,
|
|
58
|
+
sessionConfig,
|
|
59
|
+
};
|
|
60
|
+
this.connection = this.options.transport
|
|
61
|
+
? await this.options.transport.connect(this.model, options)
|
|
62
|
+
: await this.model.connect(options);
|
|
63
|
+
this.connection.on("event", this.onEvent.bind(this));
|
|
64
|
+
this.connection.on("error", (e) => this.emit("error", e));
|
|
65
|
+
this.connection.on("status", (s) => this.emit("status", s));
|
|
66
|
+
this.init();
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Initialize event listeners and send session configuration.
|
|
70
|
+
*/
|
|
71
|
+
async init() {
|
|
72
|
+
if (this.channel) {
|
|
73
|
+
this.channel.on("audio", (audio) => this.sendAudio(audio));
|
|
74
|
+
this.channel.on("commit", () => this.commit());
|
|
75
|
+
this.channel.on("interrupt", () => this.interrupt());
|
|
76
|
+
}
|
|
77
|
+
this.connection?.send({
|
|
78
|
+
kind: "session.update",
|
|
79
|
+
config: await this.buildSessionConfig(),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Build session configuration from agent.
|
|
84
|
+
*/
|
|
85
|
+
async buildSessionConfig() {
|
|
86
|
+
const tools = await this.agent.tools(this.context);
|
|
87
|
+
return {
|
|
88
|
+
instructions: await this.agent.instructions(this.context),
|
|
89
|
+
tools: tools.map((t) => t.serialize()),
|
|
90
|
+
voice: this.agent.voice,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Handle incoming events from the connection.
|
|
95
|
+
*
|
|
96
|
+
* Maps protocol events to simplified user-facing events:
|
|
97
|
+
* - 'audio' - audio output from assistant
|
|
98
|
+
* - 'transcript' - speech transcriptions (user or assistant)
|
|
99
|
+
* - 'text' - text output from assistant
|
|
100
|
+
* - 'error' - errors
|
|
101
|
+
*/
|
|
102
|
+
onEvent(event) {
|
|
103
|
+
switch (event.kind) {
|
|
104
|
+
// Audio output → 'audio'
|
|
105
|
+
case "audio.output.delta":
|
|
106
|
+
this.channel?.sendAudio(event.audio);
|
|
107
|
+
this.emit("audio", event);
|
|
108
|
+
break;
|
|
109
|
+
case "audio.output.done":
|
|
110
|
+
this.emit("audio", event);
|
|
111
|
+
break;
|
|
112
|
+
// Speech transcriptions → 'transcript'
|
|
113
|
+
case "transcript.input":
|
|
114
|
+
case "transcript.output":
|
|
115
|
+
this.emit("transcript", event);
|
|
116
|
+
break;
|
|
117
|
+
// Text output → 'text'
|
|
118
|
+
case "text.output":
|
|
119
|
+
this.emit("text", event);
|
|
120
|
+
break;
|
|
121
|
+
// Errors → 'error'
|
|
122
|
+
case "session.error":
|
|
123
|
+
this.emit("error", event.error);
|
|
124
|
+
break;
|
|
125
|
+
// Tool calls - handled internally
|
|
126
|
+
case "tool.call":
|
|
127
|
+
this.performActions(event);
|
|
128
|
+
break;
|
|
129
|
+
// Session lifecycle - internal state
|
|
130
|
+
case "session.created":
|
|
131
|
+
this.id = event.session.id;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Execute tool calls from the model.
|
|
137
|
+
*/
|
|
138
|
+
async performActions(event) {
|
|
139
|
+
const tool = this.agent.tool(event.toolId);
|
|
140
|
+
if (!tool || tool.type !== "function") {
|
|
141
|
+
this.connection?.send({
|
|
142
|
+
kind: "tool.result",
|
|
143
|
+
callId: event.callId,
|
|
144
|
+
error: `Unknown tool: ${event.toolId}`,
|
|
145
|
+
});
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const result = await tool.invoke(this.context, event.arguments, event.callId);
|
|
149
|
+
this.connection?.send({
|
|
150
|
+
kind: "tool.result",
|
|
151
|
+
callId: event.callId,
|
|
152
|
+
result: result.state === "completed" ? String(result.result) : undefined,
|
|
153
|
+
error: result.error ?? undefined,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Send audio to the model.
|
|
158
|
+
*/
|
|
159
|
+
sendAudio(audio) {
|
|
160
|
+
this.connection?.send({ kind: "audio.input.append", audio });
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Commit the audio buffer (signal end of speech).
|
|
164
|
+
*/
|
|
165
|
+
commit() {
|
|
166
|
+
this.connection?.send({ kind: "audio.input.commit" });
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Send a text message to the model.
|
|
170
|
+
*/
|
|
171
|
+
sendMessage(text) {
|
|
172
|
+
this.connection?.send({
|
|
173
|
+
kind: "item.create",
|
|
174
|
+
item: message({ role: "user", text }),
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Interrupt the current response.
|
|
179
|
+
*/
|
|
180
|
+
interrupt() {
|
|
181
|
+
this.connection?.send({ kind: "response.cancel" });
|
|
182
|
+
this.channel?.interrupt();
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Mute audio input.
|
|
186
|
+
*/
|
|
187
|
+
mute() {
|
|
188
|
+
this.connection?.mute();
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Unmute audio input.
|
|
192
|
+
*/
|
|
193
|
+
unmute() {
|
|
194
|
+
this.connection?.unmute();
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Close the session and release resources.
|
|
198
|
+
*/
|
|
199
|
+
close() {
|
|
200
|
+
this.channel?.close();
|
|
201
|
+
this.connection?.close();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { RealtimeModel, RealtimeTransport, RealtimeConnectOptions } from "@kernl-sdk/protocol";
|
|
2
|
+
import { Context, UnknownContext } from "../context.js";
|
|
3
|
+
import type { BaseAgentConfig } from "../agent/base.js";
|
|
4
|
+
import type { RealtimeChannel } from "./channel.js";
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for a realtime agent.
|
|
7
|
+
*/
|
|
8
|
+
export interface RealtimeAgentConfig<TContext = UnknownContext> extends BaseAgentConfig<TContext> {
|
|
9
|
+
/**
|
|
10
|
+
* The realtime model to use for this agent.
|
|
11
|
+
*/
|
|
12
|
+
model: RealtimeModel;
|
|
13
|
+
/**
|
|
14
|
+
* Voice configuration for the agent.
|
|
15
|
+
*/
|
|
16
|
+
voice?: RealtimeAgentVoiceConfig;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Voice configuration for a realtime agent.
|
|
20
|
+
*/
|
|
21
|
+
export interface RealtimeAgentVoiceConfig {
|
|
22
|
+
/**
|
|
23
|
+
* Voice ID to use for audio output.
|
|
24
|
+
*/
|
|
25
|
+
voiceId: string;
|
|
26
|
+
/**
|
|
27
|
+
* Playback speed multiplier.
|
|
28
|
+
*/
|
|
29
|
+
speed?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Options for creating a realtime session.
|
|
33
|
+
*/
|
|
34
|
+
export interface RealtimeSessionOptions<TContext = UnknownContext> {
|
|
35
|
+
/**
|
|
36
|
+
* Override the agent's default model for this session.
|
|
37
|
+
*/
|
|
38
|
+
model?: RealtimeModel;
|
|
39
|
+
/**
|
|
40
|
+
* Audio I/O channel (e.g., BrowserChannel, TwilioChannel).
|
|
41
|
+
* Not used with WebRTC transport.
|
|
42
|
+
*/
|
|
43
|
+
channel?: RealtimeChannel;
|
|
44
|
+
/**
|
|
45
|
+
* Custom transport (e.g., WebRTCTransport).
|
|
46
|
+
* If not provided, model.connect() creates the default transport.
|
|
47
|
+
*/
|
|
48
|
+
transport?: RealtimeTransport;
|
|
49
|
+
/**
|
|
50
|
+
* Context for this session.
|
|
51
|
+
*/
|
|
52
|
+
context?: Context<TContext>;
|
|
53
|
+
/**
|
|
54
|
+
* Options passed to model.connect() or transport.connect().
|
|
55
|
+
*/
|
|
56
|
+
connectOptions?: RealtimeConnectOptions;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/realtime/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,mBAAmB,CAAC,QAAQ,GAAG,cAAc,CAC5D,SAAQ,eAAe,CAAC,QAAQ,CAAC;IACjC;;OAEG;IACH,KAAK,EAAE,aAAa,CAAC;IAErB;;OAEG;IACH,KAAK,CAAC,EAAE,wBAAwB,CAAC;CAClC;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB,CAAC,QAAQ,GAAG,cAAc;IAC/D;;OAEG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC;IAEtB;;;OAGG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC;IAE1B;;;OAGG;IACH,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAE9B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE5B;;OAEG;IACH,cAAc,CAAC,EAAE,sBAAsB,CAAC;CACzC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory.d.ts","sourceRoot":"","sources":["../../src/storage/in-memory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"in-memory.d.ts","sourceRoot":"","sources":["../../src/storage/in-memory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAKlC,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,WAAW,EACX,SAAS,EACT,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EAGrB,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,WAAW,EAAe,MAAM,gBAAgB,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,iBAAiB,EAElB,MAAM,UAAU,CAAC;AAElB;;GAEG;AACH,qBAAa,eAAgB,YAAW,YAAY;IAClD,OAAO,EAAE,mBAAmB,CAAC;IAC7B,QAAQ,EAAE,mBAAmB,CAAC;;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IACH,OAAO,CAAC,OAAO;IAuCf;;OAEG;IACH,OAAO,CAAC,aAAa;IAyCrB;;OAEG;IACH,OAAO,CAAC,YAAY;IA2CpB;;OAEG;IACH,OAAO,CAAC,YAAY;CA6BrB;AAED;;GAEG;AACH,qBAAa,mBAAoB,YAAW,WAAW;IACrD,OAAO,CAAC,QAAQ,CAAmC;IAE7C,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAI7C,IAAI,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAkB1D,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC;IAoBhD,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;IAoBpE,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAM3C;;OAEG;IACH,OAAO,CAAC,YAAY;IAmEpB;;OAEG;IACH,OAAO,CAAC,YAAY;CASrB"}
|
|
@@ -166,8 +166,12 @@ export class InMemoryThreadStore {
|
|
|
166
166
|
if (!agent || !model) {
|
|
167
167
|
throw new Error(`Thread ${data.tid} references non-existent agent/model (agent: ${data.agentId}, model: ${data.model})`);
|
|
168
168
|
}
|
|
169
|
+
// safety: threads only exist for llm agents
|
|
170
|
+
if (agent.kind !== "llm") {
|
|
171
|
+
throw new Error(`Thread ${data.tid} references non-llm agent ${data.agentId} (kind: ${agent.kind})`);
|
|
172
|
+
}
|
|
169
173
|
return new Thread({
|
|
170
|
-
agent,
|
|
174
|
+
agent: agent,
|
|
171
175
|
tid: data.tid,
|
|
172
176
|
context: new Context(data.namespace, data.context),
|
|
173
177
|
model,
|
|
@@ -127,10 +127,10 @@ describe("FunctionToolkit", () => {
|
|
|
127
127
|
const serialized = (await toolkit.list()).map((tool) => tool.serialize());
|
|
128
128
|
expect(serialized).toHaveLength(1);
|
|
129
129
|
expect(serialized[0]).toEqual({
|
|
130
|
-
|
|
130
|
+
kind: "provider-defined",
|
|
131
131
|
id: anotherHostedTool.id,
|
|
132
132
|
name: anotherHostedTool.name,
|
|
133
|
-
|
|
133
|
+
args: {},
|
|
134
134
|
});
|
|
135
135
|
});
|
|
136
136
|
});
|
package/dist/tool/tool.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Context, UnknownContext } from "../context.js";
|
|
2
|
+
import type { BaseAgent } from "../agent/base.js";
|
|
2
3
|
import { type LanguageModelTool } from "@kernl-sdk/protocol";
|
|
3
4
|
import type { ToolConfig, ToolApprovalFunction, ToolEnabledFunction, ToolErrorFunction, ToolInputParameters, ToolResult } from "./types.js";
|
|
4
5
|
/**
|
|
@@ -26,7 +27,7 @@ export declare abstract class BaseTool<TContext = UnknownContext> {
|
|
|
26
27
|
/**
|
|
27
28
|
* Determines whether the tool should be exposed to the model for the current run.
|
|
28
29
|
*/
|
|
29
|
-
abstract isEnabled(context: Context<TContext>, agent:
|
|
30
|
+
abstract isEnabled(context: Context<TContext>, agent: BaseAgent<TContext>): Promise<boolean>;
|
|
30
31
|
/**
|
|
31
32
|
* Serialize this tool for sending to the model
|
|
32
33
|
*/
|
package/dist/tool/tool.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/tool/tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/tool/tool.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,M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