kernl 0.6.1 → 0.6.3
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 +4 -5
- package/.turbo/turbo-check-types.log +1 -1
- package/CHANGELOG.md +36 -0
- package/dist/agent/__tests__/concurrency.test.js +1 -1
- package/dist/agent/__tests__/run.test.js +1 -1
- package/dist/{types/agent.d.ts → agent/types.d.ts} +2 -2
- package/dist/agent/types.d.ts.map +1 -0
- package/dist/agent.d.ts +36 -4
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +58 -0
- package/dist/api/models/thread.d.ts +1 -1
- package/dist/api/resources/threads/threads.d.ts +1 -1
- package/dist/api/resources/threads/threads.d.ts.map +1 -1
- package/dist/api/resources/threads/threads.js +1 -1
- package/dist/api/resources/threads/types.d.ts +2 -2
- package/dist/api/resources/threads/types.d.ts.map +1 -1
- package/dist/context.d.ts +4 -4
- package/dist/context.d.ts.map +1 -1
- package/dist/guardrail.d.ts +2 -2
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/internal.d.ts +2 -2
- package/dist/internal.js +1 -1
- package/dist/kernl/index.d.ts +1 -1
- package/dist/kernl/index.d.ts.map +1 -1
- package/dist/kernl/index.js +0 -1
- package/dist/kernl/kernl.d.ts +7 -18
- package/dist/kernl/kernl.d.ts.map +1 -1
- package/dist/kernl/kernl.js +29 -29
- package/dist/kernl/types.d.ts +91 -0
- package/dist/kernl/types.d.ts.map +1 -0
- package/dist/lib/error.d.ts +2 -2
- package/dist/lifecycle.d.ts +2 -2
- package/dist/memory/codec.d.ts +32 -0
- package/dist/memory/codec.d.ts.map +1 -0
- package/dist/memory/codec.js +97 -0
- package/dist/memory/codecs/domain.d.ts +34 -0
- package/dist/memory/codecs/domain.d.ts.map +1 -0
- package/dist/memory/codecs/domain.js +99 -0
- package/dist/memory/codecs/identity.d.ts +12 -0
- package/dist/memory/codecs/identity.d.ts.map +1 -0
- package/dist/memory/codecs/identity.js +17 -0
- package/dist/memory/codecs/index.d.ts +31 -0
- package/dist/memory/codecs/index.d.ts.map +1 -0
- package/dist/memory/codecs/index.js +39 -0
- package/dist/memory/codecs/tpuf.d.ts +38 -0
- package/dist/memory/codecs/tpuf.d.ts.map +1 -0
- package/dist/memory/codecs/tpuf.js +90 -0
- package/dist/memory/encoder.d.ts +29 -0
- package/dist/memory/encoder.d.ts.map +1 -0
- package/dist/memory/encoder.js +45 -0
- package/dist/memory/handle.d.ts +89 -0
- package/dist/memory/handle.d.ts.map +1 -0
- package/dist/memory/handle.js +128 -0
- package/dist/memory/index.d.ts +12 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +7 -0
- package/dist/memory/indexes.d.ts +91 -0
- package/dist/memory/indexes.d.ts.map +1 -0
- package/dist/memory/indexes.js +7 -0
- package/dist/memory/memory.d.ts +51 -0
- package/dist/memory/memory.d.ts.map +1 -0
- package/dist/memory/memory.js +107 -0
- package/dist/memory/schema.d.ts +41 -0
- package/dist/memory/schema.d.ts.map +1 -0
- package/dist/memory/schema.js +112 -0
- package/dist/memory/store.d.ts +36 -0
- package/dist/memory/store.d.ts.map +1 -0
- package/dist/memory/store.js +4 -0
- package/dist/memory/types.d.ts +250 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +4 -0
- package/dist/storage/base.d.ts +6 -1
- package/dist/storage/base.d.ts.map +1 -1
- package/dist/storage/in-memory.d.ts +24 -2
- package/dist/storage/in-memory.d.ts.map +1 -1
- package/dist/storage/in-memory.js +131 -0
- package/dist/storage/thread.d.ts +1 -1
- package/dist/thread/__tests__/integration.test.js +1 -1
- package/dist/thread/__tests__/mock.d.ts +1 -1
- package/dist/thread/__tests__/namespace.test.js +1 -1
- package/dist/thread/__tests__/thread.test.js +1 -1
- package/dist/thread/thread.d.ts +2 -2
- package/dist/thread/thread.d.ts.map +1 -1
- package/dist/{types/thread.d.ts → thread/types.d.ts} +2 -2
- package/dist/thread/types.d.ts.map +1 -0
- package/dist/thread/utils.d.ts +2 -2
- package/dist/thread/utils.d.ts.map +1 -1
- package/package.json +4 -2
- package/src/{types/agent.ts → agent/types.ts} +1 -1
- package/src/agent.ts +78 -2
- package/src/api/__tests__/threads.test.ts +2 -2
- package/src/api/models/thread.ts +1 -1
- package/src/api/resources/threads/events.ts +1 -1
- package/src/api/resources/threads/threads.ts +2 -2
- package/src/api/resources/threads/types.ts +2 -2
- package/src/context.ts +6 -136
- package/src/guardrail.ts +2 -2
- package/src/index.ts +35 -6
- package/src/internal.ts +2 -2
- package/src/kernl/index.ts +8 -0
- package/src/{kernl.ts → kernl/kernl.ts} +40 -28
- package/src/kernl/types.ts +106 -0
- package/src/lib/error.ts +2 -2
- package/src/lifecycle.ts +2 -2
- package/src/memory/codecs/domain.ts +115 -0
- package/src/memory/codecs/identity.ts +28 -0
- package/src/memory/codecs/index.ts +61 -0
- package/src/memory/codecs/tpuf.ts +115 -0
- package/src/memory/encoder.ts +56 -0
- package/src/memory/handle.ts +189 -0
- package/src/memory/index.ts +49 -0
- package/src/memory/indexes.ts +108 -0
- package/src/memory/memory.ts +143 -0
- package/src/memory/schema.ts +142 -0
- package/src/memory/store.ts +47 -0
- package/src/memory/types.ts +282 -0
- package/src/storage/__tests__/in-memory.test.ts +1 -1
- package/src/storage/base.ts +7 -1
- package/src/storage/in-memory.ts +170 -2
- package/src/storage/thread.ts +1 -1
- package/src/thread/__tests__/integration.test.ts +1 -1
- package/src/thread/__tests__/mock.ts +1 -1
- package/src/thread/__tests__/thread.test.ts +1 -1
- package/src/thread/thread.ts +2 -2
- package/src/{types/thread.ts → thread/types.ts} +1 -1
- package/src/thread/utils.ts +2 -2
- package/tsconfig.tsbuildinfo +1 -0
- package/dist/api/__tests__/cursor-page.test.d.ts +0 -2
- package/dist/api/__tests__/cursor-page.test.d.ts.map +0 -1
- package/dist/api/__tests__/cursor-page.test.js +0 -414
- package/dist/api/__tests__/offset-page.test.d.ts +0 -2
- package/dist/api/__tests__/offset-page.test.d.ts.map +0 -1
- package/dist/api/__tests__/offset-page.test.js +0 -510
- package/dist/api/pagination/base.d.ts +0 -48
- package/dist/api/pagination/base.d.ts.map +0 -1
- package/dist/api/pagination/base.js +0 -45
- package/dist/api/pagination/cursor.d.ts +0 -44
- package/dist/api/pagination/cursor.d.ts.map +0 -1
- package/dist/api/pagination/cursor.js +0 -52
- package/dist/api/pagination/offset.d.ts +0 -42
- package/dist/api/pagination/offset.d.ts.map +0 -1
- package/dist/api/pagination/offset.js +0 -55
- package/dist/kernl/threads.d.ts +0 -110
- package/dist/kernl/threads.d.ts.map +0 -1
- package/dist/kernl/threads.js +0 -126
- package/dist/kernl.d.ts +0 -60
- package/dist/kernl.d.ts.map +0 -1
- package/dist/kernl.js +0 -113
- package/dist/types/agent.d.ts.map +0 -1
- package/dist/types/kernl.d.ts +0 -42
- package/dist/types/kernl.d.ts.map +0 -1
- package/dist/types/thread.d.ts.map +0 -1
- package/src/api/__tests__/cursor-page.test.ts +0 -512
- package/src/api/__tests__/offset-page.test.ts +0 -624
- package/src/api/pagination/base.ts +0 -79
- package/src/api/pagination/cursor.ts +0 -86
- package/src/api/pagination/offset.ts +0 -89
- package/src/types/kernl.ts +0 -51
- /package/dist/{types/agent.js → agent/types.js} +0 -0
- /package/dist/{types/kernl.js → kernl/types.js} +0 -0
- /package/dist/{types/thread.js → thread/types.js} +0 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory index schema builder.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Build a canonical memory index schema for vector search.
|
|
6
|
+
*
|
|
7
|
+
* Returns a schema Record that can be used with SearchIndex.createIndex().
|
|
8
|
+
*
|
|
9
|
+
* Schema includes all fields from IndexMemoryRecord:
|
|
10
|
+
* - id: primary key
|
|
11
|
+
* - namespace, entityId, agentId: scope fields (filterable, nullable)
|
|
12
|
+
* - kind, collection: memory attributes (filterable)
|
|
13
|
+
* - timestamp, createdAt, updatedAt: timestamps (filterable + sortable)
|
|
14
|
+
* - text: content text (full-text search)
|
|
15
|
+
* - tvec, ivec, avec, vvec: vector embeddings for text/image/audio/video
|
|
16
|
+
* - metadata: structured metadata (object)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const schema = buildMemoryIndexSchema({ dimensions: 1536 });
|
|
21
|
+
* const handle = new MemoryIndexHandle({ index: vector, indexId: "kernl_memories", schema });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function buildMemoryIndexSchema(options = {}) {
|
|
25
|
+
const dimensions = options.dimensions ?? 1536;
|
|
26
|
+
const similarity = options.similarity ?? "cosine";
|
|
27
|
+
const schema = {
|
|
28
|
+
id: {
|
|
29
|
+
type: "string",
|
|
30
|
+
pk: true,
|
|
31
|
+
sortable: true,
|
|
32
|
+
},
|
|
33
|
+
// scope fields (filterable, nullable)
|
|
34
|
+
namespace: {
|
|
35
|
+
type: "string",
|
|
36
|
+
filterable: true,
|
|
37
|
+
optional: true,
|
|
38
|
+
},
|
|
39
|
+
entityId: {
|
|
40
|
+
type: "string",
|
|
41
|
+
filterable: true,
|
|
42
|
+
optional: true,
|
|
43
|
+
},
|
|
44
|
+
agentId: {
|
|
45
|
+
type: "string",
|
|
46
|
+
filterable: true,
|
|
47
|
+
optional: true,
|
|
48
|
+
},
|
|
49
|
+
// memory attributes (filterable)
|
|
50
|
+
kind: {
|
|
51
|
+
type: "string",
|
|
52
|
+
filterable: true,
|
|
53
|
+
},
|
|
54
|
+
collection: {
|
|
55
|
+
type: "string",
|
|
56
|
+
filterable: true,
|
|
57
|
+
},
|
|
58
|
+
// timestamps (filterable + sortable) - store as bigint to safely handle
|
|
59
|
+
// millisecond Unix epoch values without overflow in SQL backends.
|
|
60
|
+
timestamp: {
|
|
61
|
+
type: "bigint",
|
|
62
|
+
filterable: true,
|
|
63
|
+
sortable: true,
|
|
64
|
+
},
|
|
65
|
+
createdAt: {
|
|
66
|
+
type: "bigint",
|
|
67
|
+
filterable: true,
|
|
68
|
+
sortable: true,
|
|
69
|
+
},
|
|
70
|
+
updatedAt: {
|
|
71
|
+
type: "bigint",
|
|
72
|
+
filterable: true,
|
|
73
|
+
sortable: true,
|
|
74
|
+
},
|
|
75
|
+
// content fields
|
|
76
|
+
text: {
|
|
77
|
+
type: "string",
|
|
78
|
+
fts: true,
|
|
79
|
+
optional: true,
|
|
80
|
+
},
|
|
81
|
+
// vector fields for different modalities
|
|
82
|
+
tvec: {
|
|
83
|
+
type: "vector",
|
|
84
|
+
dimensions,
|
|
85
|
+
similarity,
|
|
86
|
+
optional: true,
|
|
87
|
+
},
|
|
88
|
+
ivec: {
|
|
89
|
+
type: "vector",
|
|
90
|
+
dimensions,
|
|
91
|
+
similarity,
|
|
92
|
+
optional: true,
|
|
93
|
+
},
|
|
94
|
+
avec: {
|
|
95
|
+
type: "vector",
|
|
96
|
+
dimensions,
|
|
97
|
+
similarity,
|
|
98
|
+
optional: true,
|
|
99
|
+
},
|
|
100
|
+
vvec: {
|
|
101
|
+
type: "vector",
|
|
102
|
+
dimensions,
|
|
103
|
+
similarity,
|
|
104
|
+
optional: true,
|
|
105
|
+
},
|
|
106
|
+
metadata: {
|
|
107
|
+
type: "object",
|
|
108
|
+
optional: true,
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
return schema;
|
|
112
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory store interface.
|
|
3
|
+
*/
|
|
4
|
+
import type { MemoryRecord, NewMemory, MemoryRecordUpdate, MemoryListOptions } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Memory persistence store.
|
|
7
|
+
*
|
|
8
|
+
* Follows the same pattern as ThreadStore - simple CRUD operations.
|
|
9
|
+
*/
|
|
10
|
+
export interface MemoryStore {
|
|
11
|
+
/**
|
|
12
|
+
* Get a memory by ID.
|
|
13
|
+
*/
|
|
14
|
+
get(id: string): Promise<MemoryRecord | null>;
|
|
15
|
+
/**
|
|
16
|
+
* List memories matching the filter.
|
|
17
|
+
*/
|
|
18
|
+
list(options?: MemoryListOptions): Promise<MemoryRecord[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Create a new memory.
|
|
21
|
+
*/
|
|
22
|
+
create(memory: NewMemory): Promise<MemoryRecord>;
|
|
23
|
+
/**
|
|
24
|
+
* Update an existing memory.
|
|
25
|
+
*/
|
|
26
|
+
update(id: string, patch: MemoryRecordUpdate): Promise<MemoryRecord>;
|
|
27
|
+
/**
|
|
28
|
+
* Delete a memory.
|
|
29
|
+
*/
|
|
30
|
+
delete(id: string): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Delete multiple memories.
|
|
33
|
+
*/
|
|
34
|
+
mdelete(ids: string[]): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/memory/store.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACT,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAEjB;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAE9C;;OAEG;IACH,IAAI,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC;IAE3D;;OAEG;IACH,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAEjD;;OAEG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAErE;;OAEG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAElC;;OAEG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC"}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory types.
|
|
3
|
+
*/
|
|
4
|
+
import type { JSONObject } from "@kernl-sdk/protocol";
|
|
5
|
+
import type { AsyncCodec } from "@kernl-sdk/shared/lib";
|
|
6
|
+
import type { IndexHandle } from "@kernl-sdk/retrieval";
|
|
7
|
+
import type { MemoryStore } from "./store.js";
|
|
8
|
+
export type TextByte = string;
|
|
9
|
+
/**
|
|
10
|
+
* Image content.
|
|
11
|
+
*
|
|
12
|
+
* NOTE: Parallels @kernl-sdk/protocol's FilePart type.
|
|
13
|
+
* @see packages/protocol/src/language-model/item.ts
|
|
14
|
+
*/
|
|
15
|
+
export interface ImageByte {
|
|
16
|
+
data: Uint8Array | string;
|
|
17
|
+
mime: string;
|
|
18
|
+
alt?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Audio content.
|
|
22
|
+
*/
|
|
23
|
+
export interface AudioByte {
|
|
24
|
+
data: Uint8Array | string;
|
|
25
|
+
mime: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Video content.
|
|
29
|
+
*/
|
|
30
|
+
export interface VideoByte {
|
|
31
|
+
data: Uint8Array | string;
|
|
32
|
+
mime: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Memory content - the smallest coherent unit of memory.
|
|
36
|
+
*
|
|
37
|
+
* May contain multiple modalities (e.g., captioned image, video with transcript).
|
|
38
|
+
* At most one of each modality type.
|
|
39
|
+
*/
|
|
40
|
+
export interface MemoryByte {
|
|
41
|
+
text?: TextByte;
|
|
42
|
+
image?: ImageByte;
|
|
43
|
+
audio?: AudioByte;
|
|
44
|
+
video?: VideoByte;
|
|
45
|
+
object?: JSONObject;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Search-ready projection of a MemoryByte.
|
|
49
|
+
*
|
|
50
|
+
* Contains canonical text plus embeddings for each modality.
|
|
51
|
+
*/
|
|
52
|
+
export interface IndexableByte {
|
|
53
|
+
text?: string;
|
|
54
|
+
tvec?: number[];
|
|
55
|
+
ivec?: number[];
|
|
56
|
+
avec?: number[];
|
|
57
|
+
vvec?: number[];
|
|
58
|
+
metadata?: JSONObject | null;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Encoder that converts MemoryByte to IndexableByte with embeddings.
|
|
62
|
+
*/
|
|
63
|
+
export interface MemoryByteCodec extends AsyncCodec<MemoryByte, IndexableByte> {
|
|
64
|
+
embed(text: string): Promise<number[]>;
|
|
65
|
+
}
|
|
66
|
+
export interface MemoryConfig {
|
|
67
|
+
store: MemoryStore;
|
|
68
|
+
search?: IndexHandle<IndexMemoryRecord>;
|
|
69
|
+
/** Encoder for converting MemoryByte to IndexableByte with embeddings. */
|
|
70
|
+
encoder: MemoryByteCodec;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Working memory snapshot (L1).
|
|
74
|
+
*/
|
|
75
|
+
export interface WorkingMemorySnapshot {
|
|
76
|
+
scope: MemoryScope;
|
|
77
|
+
records: MemoryRecord[];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Short-term memory snapshot (L2).
|
|
81
|
+
*/
|
|
82
|
+
export interface ShortTermMemorySnapshot {
|
|
83
|
+
scope: MemoryScope;
|
|
84
|
+
records: MemoryRecord[];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Memory scope - identifies who/what this memory belongs to.
|
|
88
|
+
*/
|
|
89
|
+
export interface MemoryScope {
|
|
90
|
+
namespace?: string;
|
|
91
|
+
entityId?: string;
|
|
92
|
+
agentId?: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Memory kind - episodic (events/experiences) or semantic (facts/knowledge).
|
|
96
|
+
*/
|
|
97
|
+
export type MemoryKind = "episodic" | "semantic";
|
|
98
|
+
/**
|
|
99
|
+
* Input for creating a new memory.
|
|
100
|
+
*/
|
|
101
|
+
export interface NewMemory {
|
|
102
|
+
id: string;
|
|
103
|
+
scope: MemoryScope;
|
|
104
|
+
kind: MemoryKind;
|
|
105
|
+
collection: string;
|
|
106
|
+
content: MemoryByte;
|
|
107
|
+
wmem?: boolean;
|
|
108
|
+
smem?: {
|
|
109
|
+
expiresAt: number | null;
|
|
110
|
+
};
|
|
111
|
+
timestamp?: number;
|
|
112
|
+
metadata?: JSONObject | null;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Simplified input for agent-scoped memory creation.
|
|
116
|
+
*
|
|
117
|
+
* Sugar over NewMemory with:
|
|
118
|
+
* - id auto-generated if not provided
|
|
119
|
+
* - scope fields flattened (namespace, entityId) - agentId is implicit
|
|
120
|
+
* - kind defaults to "semantic"
|
|
121
|
+
*/
|
|
122
|
+
export interface AgentMemoryCreate {
|
|
123
|
+
id?: string;
|
|
124
|
+
namespace?: string;
|
|
125
|
+
entityId?: string;
|
|
126
|
+
collection: string;
|
|
127
|
+
content: MemoryByte;
|
|
128
|
+
wmem?: boolean;
|
|
129
|
+
smem?: {
|
|
130
|
+
expiresAt: number | null;
|
|
131
|
+
};
|
|
132
|
+
timestamp?: number;
|
|
133
|
+
metadata?: JSONObject | null;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Base memory record fields.
|
|
137
|
+
*/
|
|
138
|
+
interface BaseMemoryRecord {
|
|
139
|
+
id: string;
|
|
140
|
+
scope: MemoryScope;
|
|
141
|
+
kind: MemoryKind;
|
|
142
|
+
collection: string;
|
|
143
|
+
content: MemoryByte;
|
|
144
|
+
wmem: boolean;
|
|
145
|
+
smem: {
|
|
146
|
+
expiresAt: number | null;
|
|
147
|
+
};
|
|
148
|
+
timestamp: number;
|
|
149
|
+
createdAt: number;
|
|
150
|
+
updatedAt: number;
|
|
151
|
+
metadata: JSONObject | null;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Episodic memory - events, experiences, conversations.
|
|
155
|
+
*/
|
|
156
|
+
export interface EpisodicMemoryRecord extends BaseMemoryRecord {
|
|
157
|
+
kind: "episodic";
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Semantic memory - facts, knowledge, learned information.
|
|
161
|
+
*/
|
|
162
|
+
export interface SemanticMemoryRecord extends BaseMemoryRecord {
|
|
163
|
+
kind: "semantic";
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* A persisted memory record.
|
|
167
|
+
*/
|
|
168
|
+
export type MemoryRecord = EpisodicMemoryRecord | SemanticMemoryRecord;
|
|
169
|
+
/**
|
|
170
|
+
* Update payload for a memory record.
|
|
171
|
+
*/
|
|
172
|
+
export interface MemoryRecordUpdate {
|
|
173
|
+
id: string;
|
|
174
|
+
scope?: MemoryScope;
|
|
175
|
+
collection?: string;
|
|
176
|
+
content?: MemoryByte;
|
|
177
|
+
wmem?: boolean;
|
|
178
|
+
smem?: {
|
|
179
|
+
expiresAt: number | null;
|
|
180
|
+
};
|
|
181
|
+
timestamp?: number;
|
|
182
|
+
updatedAt?: number;
|
|
183
|
+
metadata?: JSONObject | null;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Filter for listing memories.
|
|
187
|
+
*/
|
|
188
|
+
export interface MemoryFilter {
|
|
189
|
+
scope?: Partial<MemoryScope>;
|
|
190
|
+
collections?: string[];
|
|
191
|
+
wmem?: boolean;
|
|
192
|
+
smem?: boolean;
|
|
193
|
+
after?: number;
|
|
194
|
+
before?: number;
|
|
195
|
+
metadata?: JSONObject;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Options for listing memories.
|
|
199
|
+
*/
|
|
200
|
+
export interface MemoryListOptions {
|
|
201
|
+
filter?: MemoryFilter;
|
|
202
|
+
limit?: number;
|
|
203
|
+
offset?: number;
|
|
204
|
+
order?: "asc" | "desc";
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Query for semantic memory search.
|
|
208
|
+
*/
|
|
209
|
+
export interface MemorySearchQuery {
|
|
210
|
+
query: string;
|
|
211
|
+
filter?: MemoryFilter;
|
|
212
|
+
limit?: number;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Params for triggering reindexing of a memory record.
|
|
216
|
+
*/
|
|
217
|
+
export interface MemoryReindexParams {
|
|
218
|
+
id: string;
|
|
219
|
+
indexes?: ("search" | "graph" | "archive")[];
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Flat document for search indexes.
|
|
223
|
+
*/
|
|
224
|
+
export interface IndexMemoryRecord extends IndexableByte {
|
|
225
|
+
id: string;
|
|
226
|
+
namespace: string | null;
|
|
227
|
+
entityId: string | null;
|
|
228
|
+
agentId: string | null;
|
|
229
|
+
kind: MemoryKind;
|
|
230
|
+
collection: string;
|
|
231
|
+
timestamp: number;
|
|
232
|
+
createdAt: number;
|
|
233
|
+
updatedAt: number;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Patch payload for updating an IndexMemoryRecord.
|
|
237
|
+
* Content changes require full re-index, not a patch.
|
|
238
|
+
*/
|
|
239
|
+
export interface IndexMemoryRecordPatch {
|
|
240
|
+
id: string;
|
|
241
|
+
namespace?: string | null;
|
|
242
|
+
entityId?: string | null;
|
|
243
|
+
agentId?: string | null;
|
|
244
|
+
collection?: string;
|
|
245
|
+
timestamp?: number;
|
|
246
|
+
updatedAt?: number;
|
|
247
|
+
metadata?: JSONObject | null;
|
|
248
|
+
}
|
|
249
|
+
export {};
|
|
250
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/memory/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE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C;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,UAAU,GAAG,IAAI,CAAC;CAC9B"}
|
package/dist/storage/base.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Core storage contracts.
|
|
3
3
|
*/
|
|
4
|
-
import type { AgentRegistry, ModelRegistry } from "../types
|
|
4
|
+
import type { AgentRegistry, ModelRegistry } from "../kernl/types.js";
|
|
5
5
|
import type { ThreadStore } from "./thread.js";
|
|
6
|
+
import type { MemoryStore } from "../memory/store.js";
|
|
6
7
|
/**
|
|
7
8
|
* The main storage interface for Kernl.
|
|
8
9
|
*
|
|
@@ -13,6 +14,10 @@ export interface KernlStorage {
|
|
|
13
14
|
* Thread store - manages thread execution records and event history.
|
|
14
15
|
*/
|
|
15
16
|
threads: ThreadStore;
|
|
17
|
+
/**
|
|
18
|
+
* Memory store - manages memory records for agents.
|
|
19
|
+
*/
|
|
20
|
+
memories: MemoryStore;
|
|
16
21
|
/**
|
|
17
22
|
* Bind runtime registries to storage.
|
|
18
23
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/storage/base.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/storage/base.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,OAAO,EAAE,WAAW,CAAC;IAErB;;OAEG;IACH,QAAQ,EAAE,WAAW,CAAC;IAKtB;;;;OAIG;IACH,IAAI,CAAC,UAAU,EAAE;QAAE,MAAM,EAAE,aAAa,CAAC;QAAC,MAAM,EAAE,aAAa,CAAA;KAAE,GAAG,IAAI,CAAC;IAEzE;;;;;OAKG;IACH,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAEhE;;;;OAIG;IACH,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtB;;OAEG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB;;OAEG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,OAAO,EAAE,WAAW,CAAC;IAMrB;;OAEG;IACH,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAExB;;OAEG;IACH,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B"}
|
|
@@ -7,13 +7,15 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { Thread } from "../thread/index.js";
|
|
9
9
|
import type { KernlStorage, Transaction, ThreadStore, NewThread, ThreadUpdate, ThreadInclude, ThreadListOptions, ThreadHistoryOptions } from "../storage/index.js";
|
|
10
|
-
import type { ThreadEvent } from "../types
|
|
11
|
-
import type { AgentRegistry, ModelRegistry } from "../types
|
|
10
|
+
import type { ThreadEvent } from "../thread/types.js";
|
|
11
|
+
import type { AgentRegistry, ModelRegistry } from "../kernl/types.js";
|
|
12
|
+
import type { MemoryStore, MemoryRecord, NewMemory, MemoryRecordUpdate, MemoryListOptions } from "../memory/index.js";
|
|
12
13
|
/**
|
|
13
14
|
* In-memory storage implementation.
|
|
14
15
|
*/
|
|
15
16
|
export declare class InMemoryStorage implements KernlStorage {
|
|
16
17
|
threads: InMemoryThreadStore;
|
|
18
|
+
memories: InMemoryMemoryStore;
|
|
17
19
|
constructor();
|
|
18
20
|
bind(registries: {
|
|
19
21
|
agents: AgentRegistry;
|
|
@@ -59,4 +61,24 @@ export declare class InMemoryThreadStore implements ThreadStore {
|
|
|
59
61
|
*/
|
|
60
62
|
private applySorting;
|
|
61
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* In-memory memory store implementation.
|
|
66
|
+
*/
|
|
67
|
+
export declare class InMemoryMemoryStore implements MemoryStore {
|
|
68
|
+
private memories;
|
|
69
|
+
get(id: string): Promise<MemoryRecord | null>;
|
|
70
|
+
list(options?: MemoryListOptions): Promise<MemoryRecord[]>;
|
|
71
|
+
create(memory: NewMemory): Promise<MemoryRecord>;
|
|
72
|
+
update(id: string, patch: MemoryRecordUpdate): Promise<MemoryRecord>;
|
|
73
|
+
delete(id: string): Promise<void>;
|
|
74
|
+
mdelete(ids: string[]): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Apply filters to memory list.
|
|
77
|
+
*/
|
|
78
|
+
private applyFilters;
|
|
79
|
+
/**
|
|
80
|
+
* Apply sorting to memory list.
|
|
81
|
+
*/
|
|
82
|
+
private applySorting;
|
|
83
|
+
}
|
|
62
84
|
//# sourceMappingURL=in-memory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"in-memory.d.ts","sourceRoot":"","sources":["../../src/storage/in-memory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,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;
|
|
1
|
+
{"version":3,"file":"in-memory.d.ts","sourceRoot":"","sources":["../../src/storage/in-memory.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,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;;IAO9B,IAAI,CAAC,UAAU,EAAE;QAAE,MAAM,EAAE,aAAa,CAAC;QAAC,MAAM,EAAE,aAAa,CAAA;KAAE,GAAG,IAAI;IAIlE,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,WAAW,KAAK,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,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;IA+DpB;;OAEG;IACH,OAAO,CAAC,YAAY;CASrB"}
|
|
@@ -14,8 +14,10 @@ import { UnimplementedError } from "@kernl-sdk/shared/lib";
|
|
|
14
14
|
*/
|
|
15
15
|
export class InMemoryStorage {
|
|
16
16
|
threads;
|
|
17
|
+
memories;
|
|
17
18
|
constructor() {
|
|
18
19
|
this.threads = new InMemoryThreadStore();
|
|
20
|
+
this.memories = new InMemoryMemoryStore();
|
|
19
21
|
}
|
|
20
22
|
bind(registries) {
|
|
21
23
|
this.threads.bind(registries);
|
|
@@ -281,3 +283,132 @@ export class InMemoryThreadStore {
|
|
|
281
283
|
});
|
|
282
284
|
}
|
|
283
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* In-memory memory store implementation.
|
|
288
|
+
*/
|
|
289
|
+
export class InMemoryMemoryStore {
|
|
290
|
+
memories = new Map();
|
|
291
|
+
async get(id) {
|
|
292
|
+
return this.memories.get(id) ?? null;
|
|
293
|
+
}
|
|
294
|
+
async list(options) {
|
|
295
|
+
let records = Array.from(this.memories.values());
|
|
296
|
+
// Apply filters
|
|
297
|
+
if (options?.filter) {
|
|
298
|
+
records = this.applyFilters(records, options.filter);
|
|
299
|
+
}
|
|
300
|
+
// Apply sorting
|
|
301
|
+
records = this.applySorting(records, options?.order);
|
|
302
|
+
// Apply pagination
|
|
303
|
+
if (options?.offset)
|
|
304
|
+
records = records.slice(options.offset);
|
|
305
|
+
if (options?.limit)
|
|
306
|
+
records = records.slice(0, options.limit);
|
|
307
|
+
return records;
|
|
308
|
+
}
|
|
309
|
+
async create(memory) {
|
|
310
|
+
const now = Date.now();
|
|
311
|
+
const record = {
|
|
312
|
+
id: memory.id,
|
|
313
|
+
scope: memory.scope,
|
|
314
|
+
kind: memory.kind,
|
|
315
|
+
collection: memory.collection,
|
|
316
|
+
content: memory.content,
|
|
317
|
+
wmem: memory.wmem ?? false,
|
|
318
|
+
smem: memory.smem ?? { expiresAt: null },
|
|
319
|
+
timestamp: memory.timestamp ?? now,
|
|
320
|
+
createdAt: now,
|
|
321
|
+
updatedAt: now,
|
|
322
|
+
metadata: memory.metadata ?? null,
|
|
323
|
+
};
|
|
324
|
+
this.memories.set(memory.id, record);
|
|
325
|
+
return record;
|
|
326
|
+
}
|
|
327
|
+
async update(id, patch) {
|
|
328
|
+
const record = this.memories.get(id);
|
|
329
|
+
if (!record)
|
|
330
|
+
throw new Error(`Memory ${id} not found`);
|
|
331
|
+
const updated = {
|
|
332
|
+
...record,
|
|
333
|
+
...(patch.scope && { scope: patch.scope }),
|
|
334
|
+
...(patch.collection && { collection: patch.collection }),
|
|
335
|
+
...(patch.content && { content: patch.content }),
|
|
336
|
+
...(patch.wmem !== undefined && { wmem: patch.wmem }),
|
|
337
|
+
...(patch.smem && { smem: patch.smem }),
|
|
338
|
+
...(patch.timestamp && { timestamp: patch.timestamp }),
|
|
339
|
+
...(patch.metadata !== undefined && { metadata: patch.metadata }),
|
|
340
|
+
updatedAt: patch.updatedAt ?? Date.now(),
|
|
341
|
+
};
|
|
342
|
+
this.memories.set(id, updated);
|
|
343
|
+
return updated;
|
|
344
|
+
}
|
|
345
|
+
async delete(id) {
|
|
346
|
+
this.memories.delete(id);
|
|
347
|
+
}
|
|
348
|
+
async mdelete(ids) {
|
|
349
|
+
for (const id of ids) {
|
|
350
|
+
this.memories.delete(id);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Apply filters to memory list.
|
|
355
|
+
*/
|
|
356
|
+
applyFilters(records, filter) {
|
|
357
|
+
return records.filter((record) => {
|
|
358
|
+
// Filter by scope
|
|
359
|
+
if (filter.scope) {
|
|
360
|
+
if (filter.scope.namespace !== undefined &&
|
|
361
|
+
record.scope.namespace !== filter.scope.namespace) {
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
if (filter.scope.entityId !== undefined &&
|
|
365
|
+
record.scope.entityId !== filter.scope.entityId) {
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
if (filter.scope.agentId !== undefined &&
|
|
369
|
+
record.scope.agentId !== filter.scope.agentId) {
|
|
370
|
+
return false;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
// Filter by collections
|
|
374
|
+
if (filter.collections && !filter.collections.includes(record.collection)) {
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
// Filter by wmem
|
|
378
|
+
if (filter.wmem !== undefined && record.wmem !== filter.wmem) {
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
381
|
+
// Filter by smem
|
|
382
|
+
if (filter.smem !== undefined) {
|
|
383
|
+
const hasSmem = record.smem.expiresAt !== null;
|
|
384
|
+
if (filter.smem !== hasSmem)
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
// Filter by timestamp range
|
|
388
|
+
if (filter.after !== undefined && record.timestamp <= filter.after) {
|
|
389
|
+
return false;
|
|
390
|
+
}
|
|
391
|
+
if (filter.before !== undefined && record.timestamp >= filter.before) {
|
|
392
|
+
return false;
|
|
393
|
+
}
|
|
394
|
+
// Filter by metadata (simple equality check for now)
|
|
395
|
+
if (filter.metadata) {
|
|
396
|
+
const recordMeta = record.metadata ?? {};
|
|
397
|
+
for (const [key, value] of Object.entries(filter.metadata)) {
|
|
398
|
+
if (recordMeta[key] !== value)
|
|
399
|
+
return false;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return true;
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Apply sorting to memory list.
|
|
407
|
+
*/
|
|
408
|
+
applySorting(records, order) {
|
|
409
|
+
return records.sort((a, b) => {
|
|
410
|
+
const diff = a.timestamp - b.timestamp;
|
|
411
|
+
return order === "desc" ? -diff : diff;
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
}
|
package/dist/storage/thread.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import type { Thread } from "../thread/index.js";
|
|
5
5
|
import type { Context } from "../context.js";
|
|
6
|
-
import type { ThreadEvent, ThreadState } from "../types
|
|
6
|
+
import type { ThreadEvent, ThreadState } from "../thread/types.js";
|
|
7
7
|
/**
|
|
8
8
|
* Thread persistence store.
|
|
9
9
|
*/
|
|
@@ -3,7 +3,7 @@ import { z } from "zod";
|
|
|
3
3
|
import { openai } from "@ai-sdk/openai";
|
|
4
4
|
import { AISDKLanguageModel } from "@kernl-sdk/ai";
|
|
5
5
|
import { Agent } from "../../agent.js";
|
|
6
|
-
import { Kernl } from "../../kernl.js";
|
|
6
|
+
import { Kernl } from "../../kernl/index.js";
|
|
7
7
|
import { tool, Toolkit } from "../../tool/index.js";
|
|
8
8
|
import { Thread } from "../thread.js";
|
|
9
9
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LanguageModel, LanguageModelRequest, LanguageModelResponse } from "@kernl-sdk/protocol";
|
|
2
|
-
import type { ThreadStreamEvent } from "../../types
|
|
2
|
+
import type { ThreadStreamEvent } from "../../thread/types.js";
|
|
3
3
|
/**
|
|
4
4
|
* A mock language model that echoes the user input back as an assistant message.
|
|
5
5
|
* Useful for testing the execution flow without calling a real LLM.
|