kernl 0.6.2 → 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 +1 -1
- package/.turbo/turbo-check-types.log +1 -1
- package/CHANGELOG.md +30 -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 -3
- 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 -51
- package/dist/kernl.d.ts.map +0 -1
- package/dist/kernl.js +0 -91
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
2
|
import { Thread } from "../thread.js";
|
|
3
3
|
import { Agent } from "../../agent.js";
|
|
4
|
-
import { Kernl } from "../../kernl.js";
|
|
4
|
+
import { Kernl } from "../../kernl/index.js";
|
|
5
5
|
import { InMemoryStorage } from "../../storage/in-memory.js";
|
|
6
6
|
import { createMockModel } from "./fixtures/mock-model.js";
|
|
7
7
|
// Helper to create user message input
|
|
@@ -3,7 +3,7 @@ import { z } from "zod";
|
|
|
3
3
|
import { IN_PROGRESS, COMPLETED, FAILED } from "@kernl-sdk/protocol";
|
|
4
4
|
import { Thread } from "../thread.js";
|
|
5
5
|
import { Agent } from "../../agent.js";
|
|
6
|
-
import { Kernl } from "../../kernl.js";
|
|
6
|
+
import { Kernl } from "../../kernl/index.js";
|
|
7
7
|
import { tool, FunctionToolkit } from "../../tool/index.js";
|
|
8
8
|
import { ModelBehaviorError } from "../../lib/error.js";
|
|
9
9
|
import { createMockModel } from "./fixtures/mock-model.js";
|
package/dist/thread/thread.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { Context } from "../context.js";
|
|
|
3
3
|
import type { Task } from "../task.js";
|
|
4
4
|
import type { ResolvedAgentResponse } from "../guardrail.js";
|
|
5
5
|
import { LanguageModel } from "@kernl-sdk/protocol";
|
|
6
|
-
import type { ThreadEvent, ThreadState, ThreadOptions, ThreadEventInner, ThreadStreamEvent, ThreadExecuteResult } from "
|
|
7
|
-
import type { AgentResponseType } from "../types
|
|
6
|
+
import type { ThreadEvent, ThreadState, ThreadOptions, ThreadEventInner, ThreadStreamEvent, ThreadExecuteResult } from "./types.js";
|
|
7
|
+
import type { AgentResponseType } from "../agent/types.js";
|
|
8
8
|
/**
|
|
9
9
|
* A thread drives the execution loop for an agent.
|
|
10
10
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread.d.ts","sourceRoot":"","sources":["../../src/thread/thread.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAKzD,OAAO,EAML,aAAa,EAGd,MAAM,qBAAqB,CAAC;AAG7B,OAAO,KAAK,EAEV,WAAW,EACX,WAAW,EACX,aAAa,EACb,gBAAgB,EAChB,iBAAi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,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,WAAW,CAAC;IACnB,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,SAAS,CAAU;IAC3B,OAAO,CAAC,OAAO,CAAwE;IAEvF,OAAO,CAAC,KAAK,CAAC,CAAkB;IAChC,OAAO,CAAC,OAAO,CAAC,CAAc;gBAElB,OAAO,EAAE,aAAa,CAAC,QAAQ,EAAE,SAAS,CAAC;IA+BvD;;OAEG;IACG,OAAO,IAAI,OAAO,CACtB,mBAAmB,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC,CACtD;IAoBD;;OAEG;IACI,MAAM,IAAI,aAAa,CAAC,iBAAiB,CAAC;IAuBjD;;;;;OAKG;YACY,QAAQ;IAgEvB;;;;;OAKG;YACY,IAAI;IA8BnB;;;;;OAKG;YACW,UAAU;IAuCxB;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,KAAK,EAAE,gBAAgB,EAAE,GAAG,WAAW,EAAE;IAiBnD;;OAEG;IACH,MAAM;IAQN;;OAEG;YACW,cAAc;IAyC5B;;;;OAIG;YACW,YAAY;IA2C1B;;OAEG;YACW,mBAAmB;CA2ClC"}
|
|
@@ -2,7 +2,7 @@ import { ToolCall, LanguageModel, LanguageModelItem, LanguageModelStreamEvent, R
|
|
|
2
2
|
import { Task } from "../task.js";
|
|
3
3
|
import { Context } from "../context.js";
|
|
4
4
|
import { Agent } from "../agent.js";
|
|
5
|
-
import type { AgentResponseType } from "
|
|
5
|
+
import type { AgentResponseType } from "../agent/types.js";
|
|
6
6
|
import type { ThreadStore } from "../storage/index.js";
|
|
7
7
|
/**
|
|
8
8
|
* Public/client-facing thread events (excludes internal system events).
|
|
@@ -148,4 +148,4 @@ export interface PerformActionsResult {
|
|
|
148
148
|
*/
|
|
149
149
|
pendingApprovals: ToolCall[];
|
|
150
150
|
}
|
|
151
|
-
//# sourceMappingURL=
|
|
151
|
+
//# sourceMappingURL=types.d.ts.map
|
|
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AAE,gBAAgB,EAAE,CAAC;IAC5B;;OAEG;IACH,gBAAgB,EAAE,QAAQ,EAAE,CAAC;CAC9B"}
|
package/dist/thread/utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ResolvedAgentResponse } from "../guardrail.js";
|
|
2
2
|
import { ToolCall, LanguageModelItem } from "@kernl-sdk/protocol";
|
|
3
|
-
import type { AgentResponseType } from "../types
|
|
4
|
-
import type { ThreadEvent, ThreadStreamEvent, ActionSet, PublicThreadEvent } from "
|
|
3
|
+
import type { AgentResponseType } from "../agent/types.js";
|
|
4
|
+
import type { ThreadEvent, ThreadStreamEvent, ActionSet, PublicThreadEvent } from "./types.js";
|
|
5
5
|
/**
|
|
6
6
|
* Create a ThreadEvent from a LanguageModelItem with thread metadata.
|
|
7
7
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/thread/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAIzD,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAIlE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EACV,WAAW,EAEX,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EAClB,MAAM,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/thread/utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAIzD,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAIlE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EACV,WAAW,EAEX,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EAClB,MAAM,SAAS,CAAC;AA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|
|
|
36
36
|
"pino": "^9.6.0",
|
|
37
37
|
"zod": "^4.1.12",
|
|
38
38
|
"@kernl-sdk/protocol": "0.2.5",
|
|
39
|
+
"@kernl-sdk/retrieval": "0.1.0",
|
|
39
40
|
"@kernl-sdk/shared": "^0.1.6"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
@@ -44,9 +45,10 @@
|
|
|
44
45
|
"tsc-alias": "^1.8.10",
|
|
45
46
|
"typescript": "5.9.2",
|
|
46
47
|
"vitest": "^4.0.8",
|
|
47
|
-
"@kernl-sdk/ai": "0.2.
|
|
48
|
+
"@kernl-sdk/ai": "0.2.7"
|
|
48
49
|
},
|
|
49
50
|
"scripts": {
|
|
51
|
+
"clean": "rm -rf dist",
|
|
50
52
|
"build": "tsc && tsc-alias --resolve-full-paths",
|
|
51
53
|
"dev": "tsc --watch",
|
|
52
54
|
"lint": "eslint src/",
|
package/src/agent.ts
CHANGED
|
@@ -25,13 +25,15 @@ import {
|
|
|
25
25
|
import { AgentHooks } from "./lifecycle";
|
|
26
26
|
|
|
27
27
|
import { MisconfiguredError, RuntimeError } from "./lib/error";
|
|
28
|
-
import type { AgentConfig, AgentResponseType } from "
|
|
28
|
+
import type { AgentConfig, AgentResponseType } from "@/agent/types";
|
|
29
29
|
import type {
|
|
30
30
|
TextResponse,
|
|
31
31
|
ThreadExecuteOptions,
|
|
32
32
|
ThreadExecuteResult,
|
|
33
33
|
ThreadStreamEvent,
|
|
34
|
-
} from "
|
|
34
|
+
} from "@/thread/types";
|
|
35
|
+
import type { AgentMemoryCreate, MemorySearchQuery } from "./memory";
|
|
36
|
+
import { randomID } from "@kernl-sdk/shared/lib";
|
|
35
37
|
|
|
36
38
|
export class Agent<
|
|
37
39
|
TContext = UnknownContext,
|
|
@@ -328,4 +330,78 @@ export class Agent<
|
|
|
328
330
|
kthreads.update(tid, patch),
|
|
329
331
|
};
|
|
330
332
|
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Memory management scoped to this agent.
|
|
336
|
+
*
|
|
337
|
+
* Provides a simplified API for creating memories with:
|
|
338
|
+
* - Auto-generated IDs
|
|
339
|
+
* - Flattened scope fields (namespace, entityId) - agentId is implicit
|
|
340
|
+
* - Default kind of "semantic"
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* ```ts
|
|
344
|
+
* await agent.memories.create({
|
|
345
|
+
* namespace: "user-123",
|
|
346
|
+
* collection: "preferences",
|
|
347
|
+
* content: { text: "User prefers TypeScript" },
|
|
348
|
+
* });
|
|
349
|
+
* ```
|
|
350
|
+
*/
|
|
351
|
+
get memories() {
|
|
352
|
+
if (!this.kernl) {
|
|
353
|
+
throw new MisconfiguredError(
|
|
354
|
+
`Agent ${this.id} not bound to kernl. Call kernl.register(agent) first.`,
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const agentId = this.id;
|
|
359
|
+
const kmem = this.kernl.memories;
|
|
360
|
+
|
|
361
|
+
return {
|
|
362
|
+
/**
|
|
363
|
+
* Create a new memory scoped to this agent.
|
|
364
|
+
*/
|
|
365
|
+
create: (params: AgentMemoryCreate) =>
|
|
366
|
+
kmem.create({
|
|
367
|
+
id: params.id ?? `mem_${randomID()}`,
|
|
368
|
+
scope: {
|
|
369
|
+
namespace: params.namespace,
|
|
370
|
+
entityId: params.entityId,
|
|
371
|
+
agentId,
|
|
372
|
+
},
|
|
373
|
+
kind: "semantic",
|
|
374
|
+
collection: params.collection,
|
|
375
|
+
content: params.content,
|
|
376
|
+
wmem: params.wmem,
|
|
377
|
+
smem: params.smem,
|
|
378
|
+
timestamp: params.timestamp,
|
|
379
|
+
metadata: params.metadata,
|
|
380
|
+
}),
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Search memories scoped to this agent.
|
|
384
|
+
*/
|
|
385
|
+
search: (
|
|
386
|
+
params: Omit<MemorySearchQuery, "filter"> & {
|
|
387
|
+
filter?: Omit<NonNullable<MemorySearchQuery["filter"]>, "scope"> & {
|
|
388
|
+
scope?: Omit<
|
|
389
|
+
NonNullable<NonNullable<MemorySearchQuery["filter"]>["scope"]>,
|
|
390
|
+
"agentId"
|
|
391
|
+
>;
|
|
392
|
+
};
|
|
393
|
+
},
|
|
394
|
+
) =>
|
|
395
|
+
kmem.search({
|
|
396
|
+
...params,
|
|
397
|
+
filter: {
|
|
398
|
+
...params.filter,
|
|
399
|
+
scope: {
|
|
400
|
+
...params.filter?.scope,
|
|
401
|
+
agentId,
|
|
402
|
+
},
|
|
403
|
+
},
|
|
404
|
+
}),
|
|
405
|
+
};
|
|
406
|
+
}
|
|
331
407
|
}
|
|
@@ -4,10 +4,10 @@ import { message, RUNNING } from "@kernl-sdk/protocol";
|
|
|
4
4
|
|
|
5
5
|
import { Agent } from "@/agent";
|
|
6
6
|
import { InMemoryThreadStore } from "@/storage/in-memory";
|
|
7
|
-
import type { AgentRegistry, ModelRegistry } from "@/types
|
|
7
|
+
import type { AgentRegistry, ModelRegistry } from "@/kernl/types";
|
|
8
8
|
import type { NewThread } from "@/storage";
|
|
9
9
|
import { tevent } from "@/thread/utils";
|
|
10
|
-
import type { ThreadEvent } from "@/types
|
|
10
|
+
import type { ThreadEvent } from "@/thread/types";
|
|
11
11
|
import { RThreads } from "@/api/resources/threads";
|
|
12
12
|
import type { MThread } from "@/api/models";
|
|
13
13
|
|
package/src/api/models/thread.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ThreadStore } from "@/storage";
|
|
2
2
|
import { isPublicEvent } from "@/thread/utils";
|
|
3
3
|
import type { MThreadEvent } from "@/api/models";
|
|
4
|
-
import type { ThreadEvent } from "@/types
|
|
4
|
+
import type { ThreadEvent } from "@/thread/types";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Events subresource for threads.
|
|
@@ -3,14 +3,14 @@ import type {
|
|
|
3
3
|
ThreadListOptions,
|
|
4
4
|
ThreadHistoryOptions,
|
|
5
5
|
} from "@/storage";
|
|
6
|
-
import type { ThreadEvent } from "@/types
|
|
6
|
+
import type { ThreadEvent } from "@/thread/types";
|
|
7
7
|
import { isPublicEvent } from "@/thread/utils";
|
|
8
8
|
import { Context } from "@/context";
|
|
9
9
|
import { randomID } from "@kernl-sdk/shared/lib";
|
|
10
10
|
import { RUNNING } from "@kernl-sdk/protocol";
|
|
11
11
|
|
|
12
12
|
import type { MThread, MThreadEvent } from "@/api/models";
|
|
13
|
-
import { CursorPage, type CursorPageResponse } from "
|
|
13
|
+
import { CursorPage, type CursorPageResponse } from "@kernl-sdk/shared";
|
|
14
14
|
|
|
15
15
|
import { RThreadEvents } from "./events";
|
|
16
16
|
import type {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ThreadState } from "@/types
|
|
1
|
+
import type { ThreadState } from "@/thread/types";
|
|
2
2
|
import type { SortOrder } from "@/storage";
|
|
3
|
-
import type { CursorPageParams } from "
|
|
3
|
+
import type { CursorPageParams } from "@kernl-sdk/shared";
|
|
4
4
|
|
|
5
5
|
export interface RThreadHistoryParams {
|
|
6
6
|
/**
|
package/src/context.ts
CHANGED
|
@@ -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
|
/**
|
|
7
7
|
* A propagation mechanism which carries execution-scoped values across API boundaries and between logically associated
|
|
@@ -12,7 +12,7 @@ export class Context<TContext = UnknownContext> {
|
|
|
12
12
|
* The namespace that this context belongs to.
|
|
13
13
|
*/
|
|
14
14
|
namespace: string;
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
/**
|
|
17
17
|
* The inner context object.
|
|
18
18
|
*/
|
|
@@ -64,10 +64,7 @@ export class Context<TContext = UnknownContext> {
|
|
|
64
64
|
// */
|
|
65
65
|
// #approvals: Map<string, ApprovalRecord>;
|
|
66
66
|
|
|
67
|
-
constructor(
|
|
68
|
-
namespace: string = "kernl",
|
|
69
|
-
context: TContext = {} as TContext,
|
|
70
|
-
) {
|
|
67
|
+
constructor(namespace: string = "kernl", context: TContext = {} as TContext) {
|
|
71
68
|
this.namespace = namespace;
|
|
72
69
|
this.context = context;
|
|
73
70
|
this.approvals = new Map();
|
|
@@ -139,136 +136,9 @@ export class Context<TContext = UnknownContext> {
|
|
|
139
136
|
// approvals: Object.fromEntries(this.#approvals.entries()),
|
|
140
137
|
};
|
|
141
138
|
}
|
|
142
|
-
|
|
143
|
-
// /**
|
|
144
|
-
// * Rebuild the approvals map from a serialized state.
|
|
145
|
-
// * @internal
|
|
146
|
-
// *
|
|
147
|
-
// * @param approvals - The approvals map to rebuild.
|
|
148
|
-
// */
|
|
149
|
-
// _rebuildApprovals(approvals: Record<string, ApprovalRecord>) {
|
|
150
|
-
// this.#approvals = new Map(Object.entries(approvals));
|
|
151
|
-
// }
|
|
152
|
-
|
|
153
|
-
// /**
|
|
154
|
-
// * Check if a tool call has been approved.
|
|
155
|
-
// *
|
|
156
|
-
// * @param approval - Details about the tool call being evaluated.
|
|
157
|
-
// * @returns `true` if the tool call has been approved, `false` if blocked and `undefined` if not yet approved or rejected.
|
|
158
|
-
// */
|
|
159
|
-
// isToolApproved(approval: { toolName: string; callId: string }) {
|
|
160
|
-
// const { toolName, callId } = approval;
|
|
161
|
-
// const approvalEntry = this.#approvals.get(toolName);
|
|
162
|
-
// if (approvalEntry?.approved === true && approvalEntry.rejected === true) {
|
|
163
|
-
// logger.warn(
|
|
164
|
-
// "Tool is permanently approved and rejected at the same time. Approval takes precedence",
|
|
165
|
-
// );
|
|
166
|
-
// return true;
|
|
167
|
-
// }
|
|
168
|
-
|
|
169
|
-
// if (approvalEntry?.approved === true) {
|
|
170
|
-
// return true;
|
|
171
|
-
// }
|
|
172
|
-
|
|
173
|
-
// if (approvalEntry?.rejected === true) {
|
|
174
|
-
// return false;
|
|
175
|
-
// }
|
|
176
|
-
|
|
177
|
-
// const individualCallApproval = Array.isArray(approvalEntry?.approved)
|
|
178
|
-
// ? approvalEntry.approved.includes(callId)
|
|
179
|
-
// : false;
|
|
180
|
-
// const individualCallRejection = Array.isArray(approvalEntry?.rejected)
|
|
181
|
-
// ? approvalEntry.rejected.includes(callId)
|
|
182
|
-
// : false;
|
|
183
|
-
|
|
184
|
-
// if (individualCallApproval && individualCallRejection) {
|
|
185
|
-
// logger.warn(
|
|
186
|
-
// `Tool call ${callId} is both approved and rejected at the same time. Approval takes precedence`,
|
|
187
|
-
// );
|
|
188
|
-
// return true;
|
|
189
|
-
// }
|
|
190
|
-
|
|
191
|
-
// if (individualCallApproval) {
|
|
192
|
-
// return true;
|
|
193
|
-
// }
|
|
194
|
-
|
|
195
|
-
// if (individualCallRejection) {
|
|
196
|
-
// return false;
|
|
197
|
-
// }
|
|
198
|
-
|
|
199
|
-
// return undefined;
|
|
200
|
-
// }
|
|
201
|
-
|
|
202
|
-
// /**
|
|
203
|
-
// * Approve a tool call.
|
|
204
|
-
// *
|
|
205
|
-
// * @param approvalItem - The tool approval item to approve.
|
|
206
|
-
// * @param options - Additional approval behavior options.
|
|
207
|
-
// */
|
|
208
|
-
// approveTool(
|
|
209
|
-
// approvalItem: RunToolApprovalItem,
|
|
210
|
-
// { alwaysApprove = false }: { alwaysApprove?: boolean } = {},
|
|
211
|
-
// ) {
|
|
212
|
-
// const toolName = approvalItem.rawItem.name;
|
|
213
|
-
// if (alwaysApprove) {
|
|
214
|
-
// this.#approvals.set(toolName, {
|
|
215
|
-
// approved: true,
|
|
216
|
-
// rejected: [],
|
|
217
|
-
// });
|
|
218
|
-
// return;
|
|
219
|
-
// }
|
|
220
|
-
|
|
221
|
-
// const approvalEntry = this.#approvals.get(toolName) ?? {
|
|
222
|
-
// approved: [],
|
|
223
|
-
// rejected: [],
|
|
224
|
-
// };
|
|
225
|
-
// if (Array.isArray(approvalEntry.approved)) {
|
|
226
|
-
// // function tool has call_id, hosted tool call has id
|
|
227
|
-
// const callId =
|
|
228
|
-
// "callId" in approvalItem.rawItem
|
|
229
|
-
// ? approvalItem.rawItem.callId // function tools
|
|
230
|
-
// : approvalItem.rawItem.id!; // hosted tools
|
|
231
|
-
// approvalEntry.approved.push(callId);
|
|
232
|
-
// }
|
|
233
|
-
// this.#approvals.set(toolName, approvalEntry);
|
|
234
|
-
// }
|
|
235
|
-
|
|
236
|
-
// /**
|
|
237
|
-
// * Reject a tool call.
|
|
238
|
-
// *
|
|
239
|
-
// * @param approvalItem - The tool approval item to reject.
|
|
240
|
-
// */
|
|
241
|
-
// rejectTool(
|
|
242
|
-
// approvalItem: RunToolApprovalItem,
|
|
243
|
-
// { alwaysReject = false }: { alwaysReject?: boolean } = {},
|
|
244
|
-
// ) {
|
|
245
|
-
// const toolName = approvalItem.rawItem.name;
|
|
246
|
-
// if (alwaysReject) {
|
|
247
|
-
// this.#approvals.set(toolName, {
|
|
248
|
-
// approved: false,
|
|
249
|
-
// rejected: true,
|
|
250
|
-
// });
|
|
251
|
-
// return;
|
|
252
|
-
// }
|
|
253
|
-
|
|
254
|
-
// const approvalEntry = this.#approvals.get(toolName) ?? {
|
|
255
|
-
// approved: [] as string[],
|
|
256
|
-
// rejected: [] as string[],
|
|
257
|
-
// };
|
|
258
|
-
|
|
259
|
-
// if (Array.isArray(approvalEntry.rejected)) {
|
|
260
|
-
// // function tool has call_id, hosted tool call has id
|
|
261
|
-
// const callId =
|
|
262
|
-
// "callId" in approvalItem.rawItem
|
|
263
|
-
// ? approvalItem.rawItem.callId // function tools
|
|
264
|
-
// : approvalItem.rawItem.id!; // hosted tools
|
|
265
|
-
// approvalEntry.rejected.push(callId);
|
|
266
|
-
// }
|
|
267
|
-
// this.#approvals.set(toolName, approvalEntry);
|
|
268
|
-
// }
|
|
269
139
|
}
|
|
270
140
|
|
|
271
141
|
/**
|
|
272
|
-
*
|
|
142
|
+
* Status of a tool call approval.
|
|
273
143
|
*/
|
|
274
|
-
export type
|
|
144
|
+
export type ApprovalStatus = "approved" | "rejected" | "pending";
|
package/src/guardrail.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { LanguageModelResponse } from "@kernl-sdk/protocol";
|
|
|
4
4
|
|
|
5
5
|
import { Agent } from "./agent";
|
|
6
6
|
import { Context, UnknownContext } from "./context";
|
|
7
|
-
import type { AgentResponseType } from "
|
|
8
|
-
import type { TextResponse, ThreadEvent } from "
|
|
7
|
+
import type { AgentResponseType } from "@/agent/types";
|
|
8
|
+
import type { TextResponse, ThreadEvent } from "@/thread/types";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Resolves the agent output type based on the response type.
|
package/src/index.ts
CHANGED
|
@@ -4,24 +4,25 @@ export type {
|
|
|
4
4
|
StorageOptions,
|
|
5
5
|
AgentRegistry,
|
|
6
6
|
ModelRegistry,
|
|
7
|
-
} from "./
|
|
7
|
+
} from "./kernl";
|
|
8
8
|
export { Agent } from "./agent";
|
|
9
9
|
export { Context } from "./context";
|
|
10
10
|
|
|
11
11
|
// --- tools --
|
|
12
|
+
|
|
12
13
|
export { tool, Toolkit, FunctionToolkit, MCPToolkit } from "./tool";
|
|
13
14
|
export { MCPServerSSE } from "./mcp/sse";
|
|
14
15
|
export { MCPServerStdio } from "./mcp/stdio";
|
|
15
16
|
export { MCPServerStreamableHttp } from "./mcp/http";
|
|
16
17
|
|
|
17
|
-
// ---
|
|
18
|
+
// --- threads ---
|
|
19
|
+
|
|
18
20
|
export type {
|
|
19
21
|
MThread as Thread,
|
|
20
22
|
MThreadEvent as ThreadEvent,
|
|
21
23
|
MThreadEventBase as ThreadEventBase,
|
|
22
24
|
} from "./api/models";
|
|
23
25
|
|
|
24
|
-
// --- thread resource types ---
|
|
25
26
|
export type {
|
|
26
27
|
RThreadsListParams as ThreadsListParams,
|
|
27
28
|
RThreadGetOptions as ThreadGetOptions,
|
|
@@ -30,14 +31,14 @@ export type {
|
|
|
30
31
|
RThreadUpdateParams as ThreadUpdateParams,
|
|
31
32
|
} from "./api/resources/threads";
|
|
32
33
|
|
|
33
|
-
// --- thread state enums ---
|
|
34
34
|
export {
|
|
35
35
|
THREAD_STATES,
|
|
36
36
|
type ThreadState,
|
|
37
37
|
type PublicThreadEvent,
|
|
38
|
-
} from "./types
|
|
38
|
+
} from "./thread/types";
|
|
39
|
+
|
|
40
|
+
// --- storage ---
|
|
39
41
|
|
|
40
|
-
// --- storage types ---
|
|
41
42
|
export type {
|
|
42
43
|
ThreadStore,
|
|
43
44
|
NewThread,
|
|
@@ -50,3 +51,31 @@ export type {
|
|
|
50
51
|
KernlStorage,
|
|
51
52
|
Transaction,
|
|
52
53
|
} from "./storage";
|
|
54
|
+
|
|
55
|
+
// --- memory ---
|
|
56
|
+
export { Memory, MemoryByteEncoder } from "./memory";
|
|
57
|
+
export type {
|
|
58
|
+
MemoryStore,
|
|
59
|
+
MemoryScope,
|
|
60
|
+
NewMemory,
|
|
61
|
+
MemoryConfig,
|
|
62
|
+
MemoryReindexParams,
|
|
63
|
+
MemoryRecord,
|
|
64
|
+
MemoryKind,
|
|
65
|
+
MemoryRecordUpdate,
|
|
66
|
+
MemoryFilter,
|
|
67
|
+
MemoryListOptions,
|
|
68
|
+
MemorySearchQuery,
|
|
69
|
+
WorkingMemorySnapshot,
|
|
70
|
+
ShortTermMemorySnapshot,
|
|
71
|
+
MemoryIndexBase,
|
|
72
|
+
MemorySearchIndex,
|
|
73
|
+
MemoryGraphIndex,
|
|
74
|
+
MemoryArchiveIndex,
|
|
75
|
+
GraphTraversalQuery,
|
|
76
|
+
GraphTraversalResult,
|
|
77
|
+
ArchiveQuery,
|
|
78
|
+
ArchiveResult,
|
|
79
|
+
MemoryByte,
|
|
80
|
+
MemoryByteCodec,
|
|
81
|
+
} from "./memory";
|
package/src/internal.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { LanguageModel } from "@kernl-sdk/protocol";
|
|
2
|
+
import { resolveEmbeddingModel } from "@kernl-sdk/retrieval";
|
|
2
3
|
|
|
3
4
|
import { Agent } from "@/agent";
|
|
4
5
|
import { UnknownContext } from "@/context";
|
|
@@ -7,10 +8,17 @@ import type { Thread } from "@/thread";
|
|
|
7
8
|
import type { ResolvedAgentResponse } from "@/guardrail";
|
|
8
9
|
import { InMemoryStorage, type KernlStorage } from "@/storage";
|
|
9
10
|
import { RThreads } from "@/api/resources/threads";
|
|
11
|
+
import {
|
|
12
|
+
Memory,
|
|
13
|
+
MemoryByteEncoder,
|
|
14
|
+
MemoryIndexHandle,
|
|
15
|
+
buildMemoryIndexSchema,
|
|
16
|
+
} from "@/memory";
|
|
10
17
|
|
|
11
|
-
import type {
|
|
12
|
-
import type {
|
|
13
|
-
|
|
18
|
+
import type { ThreadExecuteResult, ThreadStreamEvent } from "@/thread/types";
|
|
19
|
+
import type { AgentResponseType } from "@/agent/types";
|
|
20
|
+
|
|
21
|
+
import type { KernlOptions } from "./types";
|
|
14
22
|
|
|
15
23
|
/**
|
|
16
24
|
* The kernl - manages agent processes, scheduling, and task lifecycle.
|
|
@@ -27,12 +35,41 @@ export class Kernl extends KernlHooks<UnknownContext, AgentResponseType> {
|
|
|
27
35
|
|
|
28
36
|
// --- public API ---
|
|
29
37
|
readonly threads: RThreads; /* Threads resource */
|
|
38
|
+
readonly memories: Memory; /* Memory system */
|
|
30
39
|
|
|
31
40
|
constructor(options: KernlOptions = {}) {
|
|
32
41
|
super();
|
|
33
42
|
this.storage = options.storage?.db ?? new InMemoryStorage();
|
|
34
43
|
this.storage.bind({ agents: this.agents, models: this.models });
|
|
35
44
|
this.threads = new RThreads(this.storage.threads);
|
|
45
|
+
|
|
46
|
+
// initialize memory
|
|
47
|
+
const embeddingModel =
|
|
48
|
+
options.memory?.embeddingModel ?? "openai/text-embedding-3-small";
|
|
49
|
+
const embedder =
|
|
50
|
+
typeof embeddingModel === "string"
|
|
51
|
+
? resolveEmbeddingModel<string>(embeddingModel)
|
|
52
|
+
: embeddingModel;
|
|
53
|
+
const encoder = new MemoryByteEncoder(embedder);
|
|
54
|
+
|
|
55
|
+
const vector = options.storage?.vector;
|
|
56
|
+
const indexId = options.memory?.indexId ?? "memories_sindex";
|
|
57
|
+
const dimensions = options.memory?.dimensions ?? 1536;
|
|
58
|
+
const providerOptions = options.memory?.indexProviderOptions ?? { schema: "kernl" };
|
|
59
|
+
|
|
60
|
+
this.memories = new Memory({
|
|
61
|
+
store: this.storage.memories,
|
|
62
|
+
search:
|
|
63
|
+
vector !== undefined
|
|
64
|
+
? new MemoryIndexHandle({
|
|
65
|
+
index: vector,
|
|
66
|
+
indexId,
|
|
67
|
+
schema: buildMemoryIndexSchema({ dimensions }),
|
|
68
|
+
providerOptions,
|
|
69
|
+
})
|
|
70
|
+
: undefined,
|
|
71
|
+
encoder,
|
|
72
|
+
});
|
|
36
73
|
}
|
|
37
74
|
|
|
38
75
|
/**
|