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
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
>
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
|
|
2
|
+
> kernl@0.6.2 build /Users/andjones/Documents/projects/kernl/packages/kernl
|
|
3
|
+
> tsc && tsc-alias --resolve-full-paths
|
|
4
|
+
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,41 @@
|
|
|
1
1
|
# @kernl/core
|
|
2
2
|
|
|
3
|
+
## 0.6.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a7d6138: Add agent.memories API and memory integration with vector backends
|
|
8
|
+
|
|
9
|
+
**@kernl-sdk/retrieval**
|
|
10
|
+
- Add `planQuery()` for adapting queries based on backend capabilities
|
|
11
|
+
- Add `SearchCapabilities` interface to describe backend features
|
|
12
|
+
- Gracefully degrade hybrid queries when not supported
|
|
13
|
+
|
|
14
|
+
**@kernl-sdk/pg**
|
|
15
|
+
- Add `capabilities()` method to PGVectorSearchIndex
|
|
16
|
+
- Fix hit decoding to include id in document
|
|
17
|
+
|
|
18
|
+
**@kernl-sdk/turbopuffer**
|
|
19
|
+
- Add `capabilities()` method describing supported search modes
|
|
20
|
+
- Add bigint type mapping for timestamps
|
|
21
|
+
- Fix hit decoding to include id in document
|
|
22
|
+
- Add memory integration tests
|
|
23
|
+
|
|
24
|
+
**kernl**
|
|
25
|
+
- Add `agent.memories.create()` with simplified syntax (auto-generated IDs, flattened scope)
|
|
26
|
+
- Add `agent.memories.search()` scoped to agent
|
|
27
|
+
- Add backend-aware codecs for Turbopuffer field mapping (tvec → vector)
|
|
28
|
+
- Default `include: true` for Turbopuffer queries to return all attributes
|
|
29
|
+
|
|
30
|
+
- Updated dependencies [a7d6138]
|
|
31
|
+
- @kernl-sdk/retrieval@0.1.0
|
|
32
|
+
|
|
33
|
+
## 0.6.2
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- c5a5fcf: Storage now auto-initializes on first operation - no need to call init() manually
|
|
38
|
+
|
|
3
39
|
## 0.6.1
|
|
4
40
|
|
|
5
41
|
### Patch Changes
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
2
|
import { Agent } from "../../agent.js";
|
|
3
|
-
import { Kernl } from "../../kernl.js";
|
|
3
|
+
import { Kernl } from "../../kernl/index.js";
|
|
4
4
|
import { createMockModel } from "../../thread/__tests__/fixtures/mock-model.js";
|
|
5
5
|
import { RuntimeError } from "../../lib/error.js";
|
|
6
6
|
import { message } from "@kernl-sdk/protocol";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
2
|
import { Agent } from "../../agent.js";
|
|
3
|
-
import { Kernl } from "../../kernl.js";
|
|
3
|
+
import { Kernl } from "../../kernl/index.js";
|
|
4
4
|
import { createMockModel } from "../../thread/__tests__/fixtures/mock-model.js";
|
|
5
5
|
import { MisconfiguredError } from "../../lib/error.js";
|
|
6
6
|
import { message } from "@kernl-sdk/protocol";
|
|
@@ -3,7 +3,7 @@ import { Context, UnknownContext } from "../context.js";
|
|
|
3
3
|
import { LanguageModel, LanguageModelRequestSettings } from "@kernl-sdk/protocol";
|
|
4
4
|
import { InputGuardrail, OutputGuardrail } from "../guardrail.js";
|
|
5
5
|
import { BaseToolkit } from "../tool/index.js";
|
|
6
|
-
import { TextResponse } from "
|
|
6
|
+
import { TextResponse } from "../thread/types.js";
|
|
7
7
|
/**
|
|
8
8
|
* Configuration for an agent.
|
|
9
9
|
*/
|
|
@@ -88,4 +88,4 @@ export interface AgentGuardrails<TResponse extends AgentResponseType = TextRespo
|
|
|
88
88
|
* 'text' is a special type that indicates the output will be a string.
|
|
89
89
|
*/
|
|
90
90
|
export type AgentResponseType = TextResponse | ZodType;
|
|
91
|
-
//# sourceMappingURL=
|
|
91
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/agent/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,KAAK,CAAC;AAEnC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EACL,aAAa,EACb,4BAA4B,EAC7B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,WAAW,CAC1B,QAAQ,GAAG,cAAc,EACzB,SAAS,SAAS,iBAAiB,GAAG,YAAY;IAGlD,EAAE,EAAE,MAAM,CAAC;IAGX,IAAI,EAAE,MAAM,CAAC;IAEb;;;;;;;OAOG;IACH,YAAY,EACR,MAAM,GACN,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC;IAe/D;;;;OAIG;IACH,KAAK,EAAE,aAAa,CAAC;IAErB;;OAEG;IACH,aAAa,CAAC,EAAE,4BAA4B,CAAC;IAE7C;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,QAAQ,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC;IAEnC;;;OAGG;IACH,UAAU,CAAC,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IAExC;;OAEG;IACH,YAAY,CAAC,EAAE,SAAS,CAAC;IAsBzB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe,CAC9B,SAAS,SAAS,iBAAiB,GAAG,YAAY;IAElD;;;OAGG;IACH,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB;;;OAGG;IACH,MAAM,EAAE,eAAe,CAAC,SAAS,CAAC,EAAE,CAAC;CACtC;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,YAAY,GAAG,OAAO,CAAC"}
|
package/dist/agent.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { LanguageModel, LanguageModelItem, LanguageModelRequestSettings } from "@kernl-sdk/protocol";
|
|
2
|
-
import type { Kernl } from "./kernl.js";
|
|
2
|
+
import type { Kernl } from "./kernl/index.js";
|
|
3
3
|
import type { RThreadsListParams, RThreadCreateParams, RThreadGetOptions, RThreadHistoryParams, RThreadUpdateParams } from "./api/resources/threads/types.js";
|
|
4
4
|
import type { Context, UnknownContext } from "./context.js";
|
|
5
5
|
import { Tool } from "./tool/index.js";
|
|
6
6
|
import { BaseToolkit } from "./tool/toolkit.js";
|
|
7
7
|
import { InputGuardrail, OutputGuardrail, type ResolvedAgentResponse } from "./guardrail.js";
|
|
8
8
|
import { AgentHooks } from "./lifecycle.js";
|
|
9
|
-
import type { AgentConfig, AgentResponseType } from "./types
|
|
10
|
-
import type { TextResponse, ThreadExecuteOptions, ThreadExecuteResult, ThreadStreamEvent } from "./types
|
|
9
|
+
import type { AgentConfig, AgentResponseType } from "./agent/types.js";
|
|
10
|
+
import type { TextResponse, ThreadExecuteOptions, ThreadExecuteResult, ThreadStreamEvent } from "./thread/types.js";
|
|
11
|
+
import type { AgentMemoryCreate, MemorySearchQuery } from "./memory/index.js";
|
|
11
12
|
export declare class Agent<TContext = UnknownContext, TResponse extends AgentResponseType = TextResponse> extends AgentHooks<TContext, TResponse> implements AgentConfig<TContext, TResponse> {
|
|
12
13
|
private kernl?;
|
|
13
14
|
id: string;
|
|
@@ -73,11 +74,42 @@ export declare class Agent<TContext = UnknownContext, TResponse extends AgentRes
|
|
|
73
74
|
*/
|
|
74
75
|
get threads(): {
|
|
75
76
|
get: (tid: string, options?: RThreadGetOptions) => Promise<import("./index.js").Thread | null>;
|
|
76
|
-
list: (params?: Omit<RThreadsListParams, "agentId">) => Promise<import("
|
|
77
|
+
list: (params?: Omit<RThreadsListParams, "agentId">) => Promise<import("@kernl-sdk/shared").CursorPage<import("./index.js").Thread, RThreadsListParams>>;
|
|
77
78
|
delete: (tid: string) => Promise<void>;
|
|
78
79
|
history: (tid: string, params?: RThreadHistoryParams) => Promise<import("./index.js").ThreadEvent[]>;
|
|
79
80
|
create: (params: Omit<RThreadCreateParams, "agentId" | "model">) => Promise<import("./index.js").Thread>;
|
|
80
81
|
update: (tid: string, patch: RThreadUpdateParams) => Promise<import("./index.js").Thread | null>;
|
|
81
82
|
};
|
|
83
|
+
/**
|
|
84
|
+
* Memory management scoped to this agent.
|
|
85
|
+
*
|
|
86
|
+
* Provides a simplified API for creating memories with:
|
|
87
|
+
* - Auto-generated IDs
|
|
88
|
+
* - Flattened scope fields (namespace, entityId) - agentId is implicit
|
|
89
|
+
* - Default kind of "semantic"
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* await agent.memories.create({
|
|
94
|
+
* namespace: "user-123",
|
|
95
|
+
* collection: "preferences",
|
|
96
|
+
* content: { text: "User prefers TypeScript" },
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
get memories(): {
|
|
101
|
+
/**
|
|
102
|
+
* Create a new memory scoped to this agent.
|
|
103
|
+
*/
|
|
104
|
+
create: (params: AgentMemoryCreate) => Promise<import("./memory/index.js").MemoryRecord>;
|
|
105
|
+
/**
|
|
106
|
+
* Search memories scoped to this agent.
|
|
107
|
+
*/
|
|
108
|
+
search: (params: Omit<MemorySearchQuery, "filter"> & {
|
|
109
|
+
filter?: Omit<NonNullable<MemorySearchQuery["filter"]>, "scope"> & {
|
|
110
|
+
scope?: Omit<NonNullable<NonNullable<MemorySearchQuery["filter"]>["scope"]>, "agentId">;
|
|
111
|
+
};
|
|
112
|
+
}) => Promise<import("@kernl-sdk/retrieval").SearchHit<import("./memory/index.js").IndexMemoryRecord>[]>;
|
|
113
|
+
};
|
|
82
114
|
}
|
|
83
115
|
//# sourceMappingURL=agent.d.ts.map
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,aAAa,EACb,iBAAiB,EACjB,4BAA4B,EAC7B,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EAAE,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CAAC,CAAC;IAkDjE;;;;;;;OAOG;IACI,MAAM,CACX,KAAK,EAAE,MAAM,GAAG,iBAAiB,EAAE,EACnC,OAAO,CAAC,EAAE,oBAAoB,CAAC,QAAQ,CAAC,GACvC,aAAa,CAAC,iBAAiB,CAAC;IAmDnC;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,SAAS;IAQ5C;;;;;;;;;;;;OAYG;IACG,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;IAqBlE;;;;OAIG;IACH,IAAI,OAAO;mBAWI,MAAM,YAAY,iBAAiB;wBAE/B,IAAI,CAAC,kBAAkB,EAAE,SAAS,CAAC;sBAEpC,MAAM;uBACL,MAAM,WAAW,oBAAoB;yBAEnC,IAAI,CAAC,mBAAmB,EAAE,SAAS,GAAG,OAAO,CAAC;sBASjD,MAAM,SAAS,mBAAmB;MAGnD;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,IAAI,QAAQ;QAWR;;WAEG;yBACc,iBAAiB;QAiBlC;;WAEG;yBAEO,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,GAAG;YAC1C,MAAM,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG;gBACjE,KAAK,CAAC,EAAE,IAAI,CACV,WAAW,CAAC,WAAW,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAC9D,SAAS,CACV,CAAC;aACH,CAAC;SACH;MAaN;CACF"}
|
package/dist/agent.js
CHANGED
|
@@ -2,6 +2,7 @@ import { message, } from "@kernl-sdk/protocol";
|
|
|
2
2
|
import { Thread } from "./thread/index.js";
|
|
3
3
|
import { AgentHooks } from "./lifecycle.js";
|
|
4
4
|
import { MisconfiguredError, RuntimeError } from "./lib/error.js";
|
|
5
|
+
import { randomID } from "@kernl-sdk/shared/lib";
|
|
5
6
|
export class Agent extends AgentHooks {
|
|
6
7
|
kernl;
|
|
7
8
|
id;
|
|
@@ -234,4 +235,61 @@ export class Agent extends AgentHooks {
|
|
|
234
235
|
update: (tid, patch) => kthreads.update(tid, patch),
|
|
235
236
|
};
|
|
236
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* Memory management scoped to this agent.
|
|
240
|
+
*
|
|
241
|
+
* Provides a simplified API for creating memories with:
|
|
242
|
+
* - Auto-generated IDs
|
|
243
|
+
* - Flattened scope fields (namespace, entityId) - agentId is implicit
|
|
244
|
+
* - Default kind of "semantic"
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```ts
|
|
248
|
+
* await agent.memories.create({
|
|
249
|
+
* namespace: "user-123",
|
|
250
|
+
* collection: "preferences",
|
|
251
|
+
* content: { text: "User prefers TypeScript" },
|
|
252
|
+
* });
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
get memories() {
|
|
256
|
+
if (!this.kernl) {
|
|
257
|
+
throw new MisconfiguredError(`Agent ${this.id} not bound to kernl. Call kernl.register(agent) first.`);
|
|
258
|
+
}
|
|
259
|
+
const agentId = this.id;
|
|
260
|
+
const kmem = this.kernl.memories;
|
|
261
|
+
return {
|
|
262
|
+
/**
|
|
263
|
+
* Create a new memory scoped to this agent.
|
|
264
|
+
*/
|
|
265
|
+
create: (params) => kmem.create({
|
|
266
|
+
id: params.id ?? `mem_${randomID()}`,
|
|
267
|
+
scope: {
|
|
268
|
+
namespace: params.namespace,
|
|
269
|
+
entityId: params.entityId,
|
|
270
|
+
agentId,
|
|
271
|
+
},
|
|
272
|
+
kind: "semantic",
|
|
273
|
+
collection: params.collection,
|
|
274
|
+
content: params.content,
|
|
275
|
+
wmem: params.wmem,
|
|
276
|
+
smem: params.smem,
|
|
277
|
+
timestamp: params.timestamp,
|
|
278
|
+
metadata: params.metadata,
|
|
279
|
+
}),
|
|
280
|
+
/**
|
|
281
|
+
* Search memories scoped to this agent.
|
|
282
|
+
*/
|
|
283
|
+
search: (params) => kmem.search({
|
|
284
|
+
...params,
|
|
285
|
+
filter: {
|
|
286
|
+
...params.filter,
|
|
287
|
+
scope: {
|
|
288
|
+
...params.filter?.scope,
|
|
289
|
+
agentId,
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
}),
|
|
293
|
+
};
|
|
294
|
+
}
|
|
237
295
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ThreadStore } from "../../../storage/index.js";
|
|
2
2
|
import type { MThread, MThreadEvent } from "../../../api/models/index.js";
|
|
3
|
-
import { CursorPage } from "
|
|
3
|
+
import { CursorPage } from "@kernl-sdk/shared";
|
|
4
4
|
import { RThreadEvents } from "./events.js";
|
|
5
5
|
import type { RThreadCreateParams, RThreadGetOptions, RThreadHistoryParams, RThreadsListParams, RThreadUpdateParams } from "./types.js";
|
|
6
6
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"threads.d.ts","sourceRoot":"","sources":["../../../../src/api/resources/threads/threads.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EAGZ,MAAM,WAAW,CAAC;AAOnB,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,UAAU,EAA2B,MAAM,
|
|
1
|
+
{"version":3,"file":"threads.d.ts","sourceRoot":"","sources":["../../../../src/api/resources/threads/threads.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EAGZ,MAAM,WAAW,CAAC;AAOnB,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,UAAU,EAA2B,MAAM,mBAAmB,CAAC;AAExE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EACV,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAGjB;;;;GAIG;AACH,qBAAa,QAAQ;IAGP,OAAO,CAAC,QAAQ,CAAC,KAAK;IAFlC,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;gBAEF,KAAK,EAAE,WAAW;IAI/C;;;;;OAKG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAgB5E;;OAEG;IACG,MAAM,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC;IAqC3D;;;;;;;;;;;OAWG;IACG,IAAI,CACR,MAAM,GAAE,kBAAuB,GAC9B,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,kBAAkB,CAAC,CAAC;IAkDnD;;OAEG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxC;;;;OAIG;IACG,OAAO,CACX,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,oBAAoB,GAC5B,OAAO,CAAC,YAAY,EAAE,CAAC;IAY1B;;;;;OAKG;IACG,MAAM,CACV,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,mBAAmB,GACzB,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;CAyD3B"}
|
|
@@ -2,7 +2,7 @@ import { isPublicEvent } from "../../../thread/utils.js";
|
|
|
2
2
|
import { Context } from "../../../context.js";
|
|
3
3
|
import { randomID } from "@kernl-sdk/shared/lib";
|
|
4
4
|
import { RUNNING } from "@kernl-sdk/protocol";
|
|
5
|
-
import { CursorPage } from "
|
|
5
|
+
import { CursorPage } from "@kernl-sdk/shared";
|
|
6
6
|
import { RThreadEvents } from "./events.js";
|
|
7
7
|
import { MThreadCodec, ThreadsFilterCodec, ThreadsOrderCodec } from "./utils.js";
|
|
8
8
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ThreadState } from "../../../types
|
|
1
|
+
import type { ThreadState } from "../../../thread/types.js";
|
|
2
2
|
import type { SortOrder } from "../../../storage/index.js";
|
|
3
|
-
import type { CursorPageParams } from "
|
|
3
|
+
import type { CursorPageParams } from "@kernl-sdk/shared";
|
|
4
4
|
export interface RThreadHistoryParams {
|
|
5
5
|
/**
|
|
6
6
|
* Only return events with seq greater than this value.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/api/resources/threads/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/api/resources/threads/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;;;OAIG;IACH,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAEvB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,MAAM,WAAW,kBAAmB,SAAQ,gBAAgB;IAC1D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,WAAW,GAAG,WAAW,EAAE,C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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Context that is being passed around as part of the session is unknown
|
|
3
3
|
*/
|
|
4
|
-
export type
|
|
4
|
+
export type UnknownContext = unknown;
|
|
5
5
|
/**
|
|
6
6
|
* A propagation mechanism which carries execution-scoped values across API boundaries and between logically associated
|
|
7
7
|
* execution units.
|
|
@@ -68,7 +68,7 @@ export declare class Context<TContext = UnknownContext> {
|
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
71
|
+
* Status of a tool call approval.
|
|
72
72
|
*/
|
|
73
|
-
export type
|
|
73
|
+
export type ApprovalStatus = "approved" | "rejected" | "pending";
|
|
74
74
|
//# sourceMappingURL=context.d.ts.map
|
package/dist/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC;AAErC;;;GAGG;AACH,qBAAa,OAAO,CAAC,QAAQ,GAAG,cAAc;IAC5C;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,OAAO,EAAE,QAAQ,CAAC;IAMlB;;;OAGG;IACH,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAEvC;;;OAGG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI7B;;;OAGG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;gBAwBhB,SAAS,GAAE,MAAgB,EAAE,OAAO,GAAE,QAAyB;IAS3E;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,MAAM;IAevC;;;;;;;;;;;;;;OAcG;IACH,EAAE,IAAI,MAAM;IAIZ;;;;;;;;;;OAUG;IACH,IAAI,IAAI,MAAM;IAId,MAAM,IAAI;QACR,OAAO,EAAE,GAAG,CAAC;KAGd;CAOF;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,CAAC"}
|
package/dist/guardrail.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { z, type ZodType } from "zod";
|
|
|
2
2
|
import { LanguageModelResponse } from "@kernl-sdk/protocol";
|
|
3
3
|
import { Agent } from "./agent.js";
|
|
4
4
|
import { Context, UnknownContext } from "./context.js";
|
|
5
|
-
import type { AgentResponseType } from "./types
|
|
6
|
-
import type { TextResponse, ThreadEvent } from "./types
|
|
5
|
+
import type { AgentResponseType } from "./agent/types.js";
|
|
6
|
+
import type { TextResponse, ThreadEvent } from "./thread/types.js";
|
|
7
7
|
/**
|
|
8
8
|
* Resolves the agent output type based on the response type.
|
|
9
9
|
* - If TResponse is "text" → output is string
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { Kernl } from "./kernl.js";
|
|
2
|
-
export type { KernlOptions, StorageOptions, AgentRegistry, ModelRegistry, } from "./
|
|
1
|
+
export { Kernl } from "./kernl/index.js";
|
|
2
|
+
export type { KernlOptions, StorageOptions, AgentRegistry, ModelRegistry, } from "./kernl/index.js";
|
|
3
3
|
export { Agent } from "./agent.js";
|
|
4
4
|
export { Context } from "./context.js";
|
|
5
5
|
export { tool, Toolkit, FunctionToolkit, MCPToolkit } from "./tool/index.js";
|
|
@@ -8,6 +8,8 @@ export { MCPServerStdio } from "./mcp/stdio.js";
|
|
|
8
8
|
export { MCPServerStreamableHttp } from "./mcp/http.js";
|
|
9
9
|
export type { MThread as Thread, MThreadEvent as ThreadEvent, MThreadEventBase as ThreadEventBase, } from "./api/models/index.js";
|
|
10
10
|
export type { RThreadsListParams as ThreadsListParams, RThreadGetOptions as ThreadGetOptions, RThreadHistoryParams as ThreadHistoryParams, RThreadCreateParams as ThreadCreateParams, RThreadUpdateParams as ThreadUpdateParams, } from "./api/resources/threads/index.js";
|
|
11
|
-
export { THREAD_STATES, type ThreadState, type PublicThreadEvent, } from "./types
|
|
11
|
+
export { THREAD_STATES, type ThreadState, type PublicThreadEvent, } from "./thread/types.js";
|
|
12
12
|
export type { ThreadStore, NewThread, ThreadUpdate, ThreadFilter, ThreadHistoryOptions, ThreadInclude, ThreadListOptions, SortOrder, KernlStorage, Transaction, } from "./storage/index.js";
|
|
13
|
+
export { Memory, MemoryByteEncoder } from "./memory/index.js";
|
|
14
|
+
export type { MemoryStore, MemoryScope, NewMemory, MemoryConfig, MemoryReindexParams, MemoryRecord, MemoryKind, MemoryRecordUpdate, MemoryFilter, MemoryListOptions, MemorySearchQuery, WorkingMemorySnapshot, ShortTermMemorySnapshot, MemoryIndexBase, MemorySearchIndex, MemoryGraphIndex, MemoryArchiveIndex, GraphTraversalQuery, GraphTraversalResult, ArchiveQuery, ArchiveResult, MemoryByte, MemoryByteCodec, } from "./memory/index.js";
|
|
13
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,YAAY,EACV,YAAY,EACZ,cAAc,EACd,aAAa,EACb,aAAa,GACd,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,YAAY,EACV,YAAY,EACZ,cAAc,EACd,aAAa,EACb,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACh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ANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { Kernl } from "./kernl.js";
|
|
1
|
+
export { Kernl } from "./kernl/index.js";
|
|
2
2
|
export { Agent } from "./agent.js";
|
|
3
3
|
export { Context } from "./context.js";
|
|
4
4
|
// --- tools --
|
|
@@ -6,5 +6,6 @@ export { tool, Toolkit, FunctionToolkit, MCPToolkit } from "./tool/index.js";
|
|
|
6
6
|
export { MCPServerSSE } from "./mcp/sse.js";
|
|
7
7
|
export { MCPServerStdio } from "./mcp/stdio.js";
|
|
8
8
|
export { MCPServerStreamableHttp } from "./mcp/http.js";
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
export { THREAD_STATES, } from "./thread/types.js";
|
|
10
|
+
// --- memory ---
|
|
11
|
+
export { Memory, MemoryByteEncoder } from "./memory/index.js";
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Thread } from "./thread/thread.js";
|
|
2
|
-
export type { IThread, ThreadEvent, ThreadEventBase, ThreadEventInner, ThreadSystemEvent, ThreadState, PublicThreadEvent, } from "./types
|
|
3
|
-
export { THREAD_STATES } from "./types
|
|
2
|
+
export type { IThread, ThreadEvent, ThreadEventBase, ThreadEventInner, ThreadSystemEvent, ThreadState, PublicThreadEvent, } from "./thread/types.js";
|
|
3
|
+
export { THREAD_STATES } from "./thread/types.js";
|
|
4
4
|
//# sourceMappingURL=internal.d.ts.map
|
package/dist/internal.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Thread } from "./thread/thread.js";
|
|
2
|
-
export { THREAD_STATES } from "./types
|
|
2
|
+
export { THREAD_STATES } from "./thread/types.js";
|
package/dist/kernl/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { Kernl } from "./kernl.js";
|
|
2
|
-
export {
|
|
2
|
+
export type { KernlOptions, StorageOptions, MemoryOptions, AgentRegistry, ModelRegistry, } from "./types.js";
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/kernl/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/kernl/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,YAAY,EACV,YAAY,EACZ,cAAc,EACd,aAAa,EACb,aAAa,EACb,aAAa,GACd,MAAM,SAAS,CAAC"}
|
package/dist/kernl/index.js
CHANGED
package/dist/kernl/kernl.d.ts
CHANGED
|
@@ -4,10 +4,11 @@ import { KernlHooks } from "../lifecycle.js";
|
|
|
4
4
|
import type { Thread } from "../thread/index.js";
|
|
5
5
|
import type { ResolvedAgentResponse } from "../guardrail.js";
|
|
6
6
|
import { type KernlStorage } from "../storage/index.js";
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import type {
|
|
10
|
-
import {
|
|
7
|
+
import { RThreads } from "../api/resources/threads/index.js";
|
|
8
|
+
import { Memory } from "../memory/index.js";
|
|
9
|
+
import type { ThreadExecuteResult, ThreadStreamEvent } from "../thread/types.js";
|
|
10
|
+
import type { AgentResponseType } from "../agent/types.js";
|
|
11
|
+
import type { KernlOptions } from "./types.js";
|
|
11
12
|
/**
|
|
12
13
|
* The kernl - manages agent processes, scheduling, and task lifecycle.
|
|
13
14
|
*
|
|
@@ -19,12 +20,8 @@ export declare class Kernl extends KernlHooks<UnknownContext, AgentResponseType>
|
|
|
19
20
|
private models;
|
|
20
21
|
readonly storage: KernlStorage;
|
|
21
22
|
athreads: Map<string, Thread<any, any>>;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* Thread management API.
|
|
25
|
-
* Provides methods to get, list, and delete threads.
|
|
26
|
-
*/
|
|
27
|
-
readonly threads: ThreadsResource;
|
|
23
|
+
readonly threads: RThreads;
|
|
24
|
+
readonly memories: Memory;
|
|
28
25
|
constructor(options?: KernlOptions);
|
|
29
26
|
/**
|
|
30
27
|
* Registers a new agent with the kernl instance.
|
|
@@ -52,13 +49,5 @@ export declare class Kernl extends KernlHooks<UnknownContext, AgentResponseType>
|
|
|
52
49
|
* Schedule an existing thread - streaming execution
|
|
53
50
|
*/
|
|
54
51
|
scheduleStream<TContext, TResponse extends AgentResponseType>(thread: Thread<TContext, TResponse>): AsyncIterable<ThreadStreamEvent>;
|
|
55
|
-
/**
|
|
56
|
-
* Ensure the underlying storage backend has been initialized.
|
|
57
|
-
*
|
|
58
|
-
* This is called lazily on first use so that callers do not need to worry
|
|
59
|
-
* about calling storage.init() themselves. Safe and idempotent to call
|
|
60
|
-
* multiple times; concurrent calls share the same initialization promise.
|
|
61
|
-
*/
|
|
62
|
-
private ensureInitialized;
|
|
63
52
|
}
|
|
64
53
|
//# sourceMappingURL=kernl.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kernl.d.ts","sourceRoot":"","sources":["../../src/kernl/kernl.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"kernl.d.ts","sourceRoot":"","sources":["../../src/kernl/kernl.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACnD,OAAO,EACL,MAAM,EAIP,MAAM,UAAU,CAAC;AAElB,OAAO,KAAK,EAAE,mBAAmB,EAAE,iB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AE,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,GAClC,aAAa,CAAC,iBAAiB,CAAC;CAQpC"}
|
package/dist/kernl/kernl.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { resolveEmbeddingModel } from "@kernl-sdk/retrieval";
|
|
1
2
|
import { KernlHooks } from "../lifecycle.js";
|
|
2
3
|
import { InMemoryStorage } from "../storage/index.js";
|
|
3
|
-
import {
|
|
4
|
+
import { RThreads } from "../api/resources/threads/index.js";
|
|
5
|
+
import { Memory, MemoryByteEncoder, MemoryIndexHandle, buildMemoryIndexSchema, } from "../memory/index.js";
|
|
4
6
|
/**
|
|
5
7
|
* The kernl - manages agent processes, scheduling, and task lifecycle.
|
|
6
8
|
*
|
|
@@ -12,17 +14,36 @@ export class Kernl extends KernlHooks {
|
|
|
12
14
|
models = new Map();
|
|
13
15
|
storage;
|
|
14
16
|
athreads = new Map(); /* active threads */
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
* Provides methods to get, list, and delete threads.
|
|
19
|
-
*/
|
|
20
|
-
threads;
|
|
17
|
+
// --- public API ---
|
|
18
|
+
threads; /* Threads resource */
|
|
19
|
+
memories; /* Memory system */
|
|
21
20
|
constructor(options = {}) {
|
|
22
21
|
super();
|
|
23
22
|
this.storage = options.storage?.db ?? new InMemoryStorage();
|
|
24
23
|
this.storage.bind({ agents: this.agents, models: this.models });
|
|
25
|
-
this.threads = new
|
|
24
|
+
this.threads = new RThreads(this.storage.threads);
|
|
25
|
+
// initialize memory
|
|
26
|
+
const embeddingModel = options.memory?.embeddingModel ?? "openai/text-embedding-3-small";
|
|
27
|
+
const embedder = typeof embeddingModel === "string"
|
|
28
|
+
? resolveEmbeddingModel(embeddingModel)
|
|
29
|
+
: embeddingModel;
|
|
30
|
+
const encoder = new MemoryByteEncoder(embedder);
|
|
31
|
+
const vector = options.storage?.vector;
|
|
32
|
+
const indexId = options.memory?.indexId ?? "memories_sindex";
|
|
33
|
+
const dimensions = options.memory?.dimensions ?? 1536;
|
|
34
|
+
const providerOptions = options.memory?.indexProviderOptions ?? { schema: "kernl" };
|
|
35
|
+
this.memories = new Memory({
|
|
36
|
+
store: this.storage.memories,
|
|
37
|
+
search: vector !== undefined
|
|
38
|
+
? new MemoryIndexHandle({
|
|
39
|
+
index: vector,
|
|
40
|
+
indexId,
|
|
41
|
+
schema: buildMemoryIndexSchema({ dimensions }),
|
|
42
|
+
providerOptions,
|
|
43
|
+
})
|
|
44
|
+
: undefined,
|
|
45
|
+
encoder,
|
|
46
|
+
});
|
|
26
47
|
}
|
|
27
48
|
/**
|
|
28
49
|
* Registers a new agent with the kernl instance.
|
|
@@ -42,7 +63,6 @@ export class Kernl extends KernlHooks {
|
|
|
42
63
|
* Spawn a new thread - blocking execution
|
|
43
64
|
*/
|
|
44
65
|
async spawn(thread) {
|
|
45
|
-
await this.ensureInitialized();
|
|
46
66
|
this.athreads.set(thread.tid, thread);
|
|
47
67
|
try {
|
|
48
68
|
return await thread.execute();
|
|
@@ -57,7 +77,6 @@ export class Kernl extends KernlHooks {
|
|
|
57
77
|
* NOTE: just blocks for now
|
|
58
78
|
*/
|
|
59
79
|
async schedule(thread) {
|
|
60
|
-
await this.ensureInitialized();
|
|
61
80
|
this.athreads.set(thread.tid, thread);
|
|
62
81
|
try {
|
|
63
82
|
return await thread.execute();
|
|
@@ -72,7 +91,6 @@ export class Kernl extends KernlHooks {
|
|
|
72
91
|
* Spawn a new thread - streaming execution
|
|
73
92
|
*/
|
|
74
93
|
async *spawnStream(thread) {
|
|
75
|
-
await this.ensureInitialized();
|
|
76
94
|
this.athreads.set(thread.tid, thread);
|
|
77
95
|
try {
|
|
78
96
|
yield* thread.stream();
|
|
@@ -87,7 +105,6 @@ export class Kernl extends KernlHooks {
|
|
|
87
105
|
* Schedule an existing thread - streaming execution
|
|
88
106
|
*/
|
|
89
107
|
async *scheduleStream(thread) {
|
|
90
|
-
await this.ensureInitialized();
|
|
91
108
|
this.athreads.set(thread.tid, thread);
|
|
92
109
|
try {
|
|
93
110
|
yield* thread.stream();
|
|
@@ -96,21 +113,4 @@ export class Kernl extends KernlHooks {
|
|
|
96
113
|
this.athreads.delete(thread.tid);
|
|
97
114
|
}
|
|
98
115
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Ensure the underlying storage backend has been initialized.
|
|
101
|
-
*
|
|
102
|
-
* This is called lazily on first use so that callers do not need to worry
|
|
103
|
-
* about calling storage.init() themselves. Safe and idempotent to call
|
|
104
|
-
* multiple times; concurrent calls share the same initialization promise.
|
|
105
|
-
*/
|
|
106
|
-
async ensureInitialized() {
|
|
107
|
-
if (!this.initPromise) {
|
|
108
|
-
this.initPromise = this.storage.init().catch((error) => {
|
|
109
|
-
// Allow a retry if initialization fails.
|
|
110
|
-
this.initPromise = null;
|
|
111
|
-
throw error;
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
await this.initPromise;
|
|
115
|
-
}
|
|
116
116
|
}
|