kernl 0.6.2 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-check-types.log +1 -1
  3. package/CHANGELOG.md +44 -0
  4. package/dist/agent/__tests__/concurrency.test.js +1 -1
  5. package/dist/agent/__tests__/run.test.js +1 -1
  6. package/dist/agent/__tests__/systools.test.d.ts +2 -0
  7. package/dist/agent/__tests__/systools.test.d.ts.map +1 -0
  8. package/dist/agent/__tests__/systools.test.js +121 -0
  9. package/dist/{types/agent.d.ts → agent/types.d.ts} +19 -2
  10. package/dist/agent/types.d.ts.map +1 -0
  11. package/dist/agent.d.ts +48 -6
  12. package/dist/agent.d.ts.map +1 -1
  13. package/dist/agent.js +100 -13
  14. package/dist/api/models/thread.d.ts +1 -1
  15. package/dist/api/resources/agents/agents.d.ts +38 -0
  16. package/dist/api/resources/agents/agents.d.ts.map +1 -0
  17. package/dist/api/resources/agents/agents.js +44 -0
  18. package/dist/api/resources/agents/index.d.ts +2 -0
  19. package/dist/api/resources/agents/index.d.ts.map +1 -0
  20. package/dist/api/resources/agents/index.js +1 -0
  21. package/dist/api/resources/threads/threads.d.ts +1 -1
  22. package/dist/api/resources/threads/threads.d.ts.map +1 -1
  23. package/dist/api/resources/threads/threads.js +1 -1
  24. package/dist/api/resources/threads/types.d.ts +2 -2
  25. package/dist/api/resources/threads/types.d.ts.map +1 -1
  26. package/dist/context.d.ts +10 -4
  27. package/dist/context.d.ts.map +1 -1
  28. package/dist/context.js +5 -0
  29. package/dist/guardrail.d.ts +2 -2
  30. package/dist/index.d.ts +5 -3
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +4 -3
  33. package/dist/internal.d.ts +2 -2
  34. package/dist/internal.js +1 -1
  35. package/dist/kernl/index.d.ts +1 -1
  36. package/dist/kernl/index.d.ts.map +1 -1
  37. package/dist/kernl/index.js +0 -1
  38. package/dist/kernl/kernl.d.ts +11 -20
  39. package/dist/kernl/kernl.d.ts.map +1 -1
  40. package/dist/kernl/kernl.js +37 -34
  41. package/dist/kernl/types.d.ts +91 -0
  42. package/dist/kernl/types.d.ts.map +1 -0
  43. package/dist/lib/error.d.ts +2 -2
  44. package/dist/lifecycle.d.ts +2 -2
  45. package/dist/memory/codec.d.ts +32 -0
  46. package/dist/memory/codec.d.ts.map +1 -0
  47. package/dist/memory/codec.js +97 -0
  48. package/dist/memory/codecs/domain.d.ts +34 -0
  49. package/dist/memory/codecs/domain.d.ts.map +1 -0
  50. package/dist/memory/codecs/domain.js +99 -0
  51. package/dist/memory/codecs/identity.d.ts +12 -0
  52. package/dist/memory/codecs/identity.d.ts.map +1 -0
  53. package/dist/memory/codecs/identity.js +17 -0
  54. package/dist/memory/codecs/index.d.ts +31 -0
  55. package/dist/memory/codecs/index.d.ts.map +1 -0
  56. package/dist/memory/codecs/index.js +39 -0
  57. package/dist/memory/codecs/tpuf.d.ts +38 -0
  58. package/dist/memory/codecs/tpuf.d.ts.map +1 -0
  59. package/dist/memory/codecs/tpuf.js +90 -0
  60. package/dist/memory/encoder.d.ts +29 -0
  61. package/dist/memory/encoder.d.ts.map +1 -0
  62. package/dist/memory/encoder.js +45 -0
  63. package/dist/memory/handle.d.ts +89 -0
  64. package/dist/memory/handle.d.ts.map +1 -0
  65. package/dist/memory/handle.js +128 -0
  66. package/dist/memory/index.d.ts +12 -0
  67. package/dist/memory/index.d.ts.map +1 -0
  68. package/dist/memory/index.js +7 -0
  69. package/dist/memory/indexes.d.ts +91 -0
  70. package/dist/memory/indexes.d.ts.map +1 -0
  71. package/dist/memory/indexes.js +7 -0
  72. package/dist/memory/memory.d.ts +55 -0
  73. package/dist/memory/memory.d.ts.map +1 -0
  74. package/dist/memory/memory.js +113 -0
  75. package/dist/memory/schema.d.ts +41 -0
  76. package/dist/memory/schema.d.ts.map +1 -0
  77. package/dist/memory/schema.js +112 -0
  78. package/dist/memory/store.d.ts +36 -0
  79. package/dist/memory/store.d.ts.map +1 -0
  80. package/dist/memory/store.js +4 -0
  81. package/dist/memory/types.d.ts +250 -0
  82. package/dist/memory/types.d.ts.map +1 -0
  83. package/dist/memory/types.js +4 -0
  84. package/dist/storage/base.d.ts +6 -1
  85. package/dist/storage/base.d.ts.map +1 -1
  86. package/dist/storage/in-memory.d.ts +24 -2
  87. package/dist/storage/in-memory.d.ts.map +1 -1
  88. package/dist/storage/in-memory.js +131 -0
  89. package/dist/storage/thread.d.ts +1 -1
  90. package/dist/thread/__tests__/integration.test.js +1 -1
  91. package/dist/thread/__tests__/mock.d.ts +1 -1
  92. package/dist/thread/__tests__/namespace.test.js +1 -1
  93. package/dist/thread/__tests__/thread.test.js +1 -1
  94. package/dist/thread/thread.d.ts +2 -2
  95. package/dist/thread/thread.d.ts.map +1 -1
  96. package/dist/thread/thread.js +3 -1
  97. package/dist/{types/thread.d.ts → thread/types.d.ts} +2 -2
  98. package/dist/thread/types.d.ts.map +1 -0
  99. package/dist/thread/utils.d.ts +2 -2
  100. package/dist/thread/utils.d.ts.map +1 -1
  101. package/dist/tool/index.d.ts +1 -0
  102. package/dist/tool/index.d.ts.map +1 -1
  103. package/dist/tool/index.js +2 -0
  104. package/dist/tool/sys/index.d.ts +7 -0
  105. package/dist/tool/sys/index.d.ts.map +1 -0
  106. package/dist/tool/sys/index.js +6 -0
  107. package/dist/tool/sys/memory.d.ts +14 -0
  108. package/dist/tool/sys/memory.d.ts.map +1 -0
  109. package/dist/tool/sys/memory.js +103 -0
  110. package/dist/tool/tool.d.ts +1 -1
  111. package/dist/tool/tool.d.ts.map +1 -1
  112. package/dist/tool/tool.js +2 -2
  113. package/package.json +4 -2
  114. package/src/agent/__tests__/systools.test.ts +146 -0
  115. package/src/{types/agent.ts → agent/types.ts} +22 -1
  116. package/src/agent.ts +144 -36
  117. package/src/api/__tests__/threads.test.ts +2 -2
  118. package/src/api/models/thread.ts +1 -1
  119. package/src/api/resources/agents/agents.ts +56 -0
  120. package/src/api/resources/agents/index.ts +1 -0
  121. package/src/api/resources/threads/events.ts +1 -1
  122. package/src/api/resources/threads/threads.ts +2 -2
  123. package/src/api/resources/threads/types.ts +2 -2
  124. package/src/context.ts +14 -136
  125. package/src/guardrail.ts +2 -2
  126. package/src/index.ts +35 -6
  127. package/src/internal.ts +2 -2
  128. package/src/kernl/index.ts +8 -0
  129. package/src/{kernl.ts → kernl/kernl.ts} +50 -10
  130. package/src/kernl/types.ts +106 -0
  131. package/src/lib/error.ts +2 -2
  132. package/src/lifecycle.ts +2 -2
  133. package/src/memory/codecs/domain.ts +115 -0
  134. package/src/memory/codecs/identity.ts +28 -0
  135. package/src/memory/codecs/index.ts +61 -0
  136. package/src/memory/codecs/tpuf.ts +115 -0
  137. package/src/memory/encoder.ts +56 -0
  138. package/src/memory/handle.ts +189 -0
  139. package/src/memory/index.ts +49 -0
  140. package/src/memory/indexes.ts +108 -0
  141. package/src/memory/memory.ts +151 -0
  142. package/src/memory/schema.ts +142 -0
  143. package/src/memory/store.ts +47 -0
  144. package/src/memory/types.ts +282 -0
  145. package/src/storage/__tests__/in-memory.test.ts +1 -1
  146. package/src/storage/base.ts +7 -1
  147. package/src/storage/in-memory.ts +170 -2
  148. package/src/storage/thread.ts +1 -1
  149. package/src/thread/__tests__/integration.test.ts +1 -1
  150. package/src/thread/__tests__/mock.ts +1 -1
  151. package/src/thread/__tests__/thread.test.ts +1 -1
  152. package/src/thread/thread.ts +5 -3
  153. package/src/{types/thread.ts → thread/types.ts} +1 -1
  154. package/src/thread/utils.ts +2 -2
  155. package/src/tool/index.ts +3 -0
  156. package/src/tool/sys/index.ts +7 -0
  157. package/src/tool/sys/memory.ts +120 -0
  158. package/src/tool/tool.ts +8 -4
  159. package/tsconfig.tsbuildinfo +1 -0
  160. package/dist/api/__tests__/cursor-page.test.d.ts +0 -2
  161. package/dist/api/__tests__/cursor-page.test.d.ts.map +0 -1
  162. package/dist/api/__tests__/cursor-page.test.js +0 -414
  163. package/dist/api/__tests__/offset-page.test.d.ts +0 -2
  164. package/dist/api/__tests__/offset-page.test.d.ts.map +0 -1
  165. package/dist/api/__tests__/offset-page.test.js +0 -510
  166. package/dist/api/pagination/base.d.ts +0 -48
  167. package/dist/api/pagination/base.d.ts.map +0 -1
  168. package/dist/api/pagination/base.js +0 -45
  169. package/dist/api/pagination/cursor.d.ts +0 -44
  170. package/dist/api/pagination/cursor.d.ts.map +0 -1
  171. package/dist/api/pagination/cursor.js +0 -52
  172. package/dist/api/pagination/offset.d.ts +0 -42
  173. package/dist/api/pagination/offset.d.ts.map +0 -1
  174. package/dist/api/pagination/offset.js +0 -55
  175. package/dist/kernl/threads.d.ts +0 -110
  176. package/dist/kernl/threads.d.ts.map +0 -1
  177. package/dist/kernl/threads.js +0 -126
  178. package/dist/kernl.d.ts +0 -51
  179. package/dist/kernl.d.ts.map +0 -1
  180. package/dist/kernl.js +0 -91
  181. package/dist/types/agent.d.ts.map +0 -1
  182. package/dist/types/kernl.d.ts +0 -42
  183. package/dist/types/kernl.d.ts.map +0 -1
  184. package/dist/types/thread.d.ts.map +0 -1
  185. package/src/api/__tests__/cursor-page.test.ts +0 -512
  186. package/src/api/__tests__/offset-page.test.ts +0 -624
  187. package/src/api/pagination/base.ts +0 -79
  188. package/src/api/pagination/cursor.ts +0 -86
  189. package/src/api/pagination/offset.ts +0 -89
  190. package/src/types/kernl.ts +0 -51
  191. /package/dist/{types/agent.js → agent/types.js} +0 -0
  192. /package/dist/{types/kernl.js → kernl/types.js} +0 -0
  193. /package/dist/{types/thread.js → thread/types.js} +0 -0
@@ -1,52 +0,0 @@
1
- import { AbstractPage } from "./base.js";
2
- export class CursorPage extends AbstractPage {
3
- data;
4
- _next;
5
- _last;
6
- constructor(args) {
7
- super(args);
8
- this.data = args.response.data ?? [];
9
- this._next = args.response.next;
10
- this._last = args.response.last;
11
- }
12
- /**
13
- * All items contained in this page.
14
- */
15
- get items() {
16
- return this.data;
17
- }
18
- /**
19
- * True if this is the last page in the sequence.
20
- *
21
- * When `last` is true, `next()` will return null.
22
- */
23
- get last() {
24
- if (this._last)
25
- return true;
26
- if (!this._next)
27
- return true;
28
- return this.data.length === 0;
29
- }
30
- /**
31
- * Fetch the next page, or null if there is no next page.
32
- */
33
- async next() {
34
- if (this.last) {
35
- return null;
36
- }
37
- if (!this._next) {
38
- return null;
39
- }
40
- const nextParams = {
41
- ...this.params,
42
- cursor: this._next,
43
- };
44
- const res = await this.loader(nextParams);
45
- const page = new CursorPage({
46
- params: nextParams,
47
- response: res,
48
- loader: this.loader,
49
- });
50
- return page;
51
- }
52
- }
@@ -1,42 +0,0 @@
1
- import { AbstractPage, type PageParamsBase } from "./base.js";
2
- export interface OffsetPageParams extends PageParamsBase {
3
- /**
4
- * Number of items to skip from the beginning of the collection.
5
- */
6
- offset?: number;
7
- }
8
- export interface OffsetPageResponse<T> {
9
- data: T[];
10
- offset: number;
11
- limit: number;
12
- /**
13
- * Optional total count when the underlying store can provide it.
14
- */
15
- total?: number;
16
- }
17
- export declare class OffsetPage<T, TParams extends OffsetPageParams = OffsetPageParams> extends AbstractPage<T, TParams, OffsetPageResponse<T>> {
18
- data: T[];
19
- offset: number;
20
- limit: number;
21
- total?: number;
22
- constructor(args: {
23
- params: TParams;
24
- response: OffsetPageResponse<T>;
25
- loader: (params: TParams) => Promise<OffsetPageResponse<T>>;
26
- });
27
- /**
28
- * All items contained in this page.
29
- */
30
- get items(): T[];
31
- /**
32
- * True if this is the last page in the sequence.
33
- *
34
- * When `last` is true, `next()` will return null.
35
- */
36
- get last(): boolean;
37
- /**
38
- * Fetch the next page, or null if there is no next page.
39
- */
40
- next(): Promise<this | null>;
41
- }
42
- //# sourceMappingURL=offset.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"offset.d.ts","sourceRoot":"","sources":["../../../src/api/pagination/offset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,QAAQ,CAAC;AAE3D,MAAM,WAAW,gBAAiB,SAAQ,cAAc;IACtD;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,kBAAkB,CAAC,CAAC;IACnC,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qBAAa,UAAU,CACrB,CAAC,EACD,OAAO,SAAS,gBAAgB,GAAG,gBAAgB,CACnD,SAAQ,YAAY,CAAC,CAAC,EAAE,OAAO,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC;IACvD,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;gBAEH,IAAI,EAAE;QAChB,MAAM,EAAE,OAAO,CAAC;QAChB,QAAQ,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC;QAChC,MAAM,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;KAC7D;IAQD;;OAEG;IACH,IAAI,KAAK,IAAI,CAAC,EAAE,CAEf;IAED;;;;OAIG;IACH,IAAI,IAAI,IAAI,OAAO,CAWlB;IAED;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;CAoBnC"}
@@ -1,55 +0,0 @@
1
- import { AbstractPage } from "./base.js";
2
- export class OffsetPage extends AbstractPage {
3
- data;
4
- offset;
5
- limit;
6
- total;
7
- constructor(args) {
8
- super(args);
9
- this.data = args.response.data ?? [];
10
- this.offset = args.response.offset;
11
- this.limit = args.response.limit;
12
- this.total = args.response.total;
13
- }
14
- /**
15
- * All items contained in this page.
16
- */
17
- get items() {
18
- return this.data;
19
- }
20
- /**
21
- * True if this is the last page in the sequence.
22
- *
23
- * When `last` is true, `next()` will return null.
24
- */
25
- get last() {
26
- if (this.data.length === 0) {
27
- return true;
28
- }
29
- const next = (this.offset ?? 0) + (this.limit ?? 0);
30
- if (this.total != null && next >= this.total) {
31
- return true;
32
- }
33
- return false;
34
- }
35
- /**
36
- * Fetch the next page, or null if there is no next page.
37
- */
38
- async next() {
39
- if (this.last) {
40
- return null;
41
- }
42
- const next = (this.offset ?? 0) + (this.limit ?? 0);
43
- const nextParams = {
44
- ...this.params,
45
- offset: next,
46
- };
47
- const res = await this.loader(nextParams);
48
- const page = new OffsetPage({
49
- params: nextParams,
50
- response: res,
51
- loader: this.loader,
52
- });
53
- return page;
54
- }
55
- }
@@ -1,110 +0,0 @@
1
- import type { ThreadStore } from "../storage/index.js";
2
- import type { ThreadResource, PublicThreadEvent } from "../types/thread.js";
3
- /**
4
- * Threads resource - provides a clean API for managing threads.
5
- *
6
- * Returns public ThreadResource types, not internal Thread class instances.
7
- */
8
- export declare class ThreadsResource {
9
- private store;
10
- constructor(store: ThreadStore);
11
- /**
12
- * Get a thread by ID.
13
- *
14
- * @param id - Thread ID
15
- * @param options - Include options (history included by default)
16
- * @returns Thread resource, or null if not found
17
- *
18
- * @example
19
- * ```ts
20
- * // With history (default)
21
- * const thread = await kernl.threads.get("thread_123");
22
- * console.log(thread?.history); // Array of ThreadEvents
23
- *
24
- * // Without history
25
- * const thread = await kernl.threads.get("thread_123", { includeHistory: false });
26
- * ```
27
- */
28
- get(id: string, options?: ThreadGetOptions): Promise<ThreadResource | null>;
29
- /**
30
- * List threads with optional filtering and pagination.
31
- *
32
- * Returns thread metadata only (no event history).
33
- * Use get() with includeHistory to retrieve full thread details.
34
- *
35
- * @param params - List parameters
36
- * @returns Array of thread resources (metadata only)
37
- *
38
- * @example
39
- * ```ts
40
- * // List recent threads for a specific agent
41
- * const threads = await kernl.threads.list({
42
- * agentId: "jarvis",
43
- * limit: 20
44
- * });
45
- * ```
46
- */
47
- list(params?: ThreadsListParams): Promise<ThreadResource[]>;
48
- /**
49
- * Delete a thread and all its events.
50
- *
51
- * @param id - Thread ID
52
- *
53
- * @example
54
- * ```ts
55
- * await kernl.threads.delete("thread_123");
56
- * ```
57
- */
58
- delete(id: string): Promise<void>;
59
- /**
60
- * Get the event history for a thread.
61
- *
62
- * Returns only public/client-facing events (excludes internal system events).
63
- *
64
- * @param id - Thread ID
65
- * @returns Array of public thread events
66
- *
67
- * @example
68
- * ```ts
69
- * const events = await kernl.threads.history("thread_123");
70
- * console.log(events.length); // Number of events in thread
71
- * ```
72
- */
73
- history(id: string): Promise<PublicThreadEvent[]>;
74
- }
75
- /**
76
- * Parameters for listing threads.
77
- */
78
- export interface ThreadsListParams {
79
- /**
80
- * Maximum number of threads to return.
81
- */
82
- limit?: number;
83
- /**
84
- * Return threads created before this cursor.
85
- */
86
- before?: string;
87
- /**
88
- * Return threads created after this cursor.
89
- */
90
- after?: string;
91
- /**
92
- * Filter by namespace.
93
- */
94
- namespace?: string;
95
- /**
96
- * Filter by agent ID.
97
- */
98
- agentId?: string;
99
- }
100
- /**
101
- * Options for getting a thread.
102
- */
103
- export interface ThreadGetOptions {
104
- /**
105
- * Include full event history in the response.
106
- * @default true
107
- */
108
- includeHistory?: boolean;
109
- }
110
- //# sourceMappingURL=threads.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"threads.d.ts","sourceRoot":"","sources":["../../src/kernl/threads.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAqB,MAAM,WAAW,CAAC;AAChE,OAAO,KAAK,EAEV,cAAc,EACd,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AAGxB;;;;GAIG;AACH,qBAAa,eAAe;IACd,OAAO,CAAC,KAAK;gBAAL,KAAK,EAAE,WAAW;IAEtC;;;;;;;;;;;;;;;;OAgBG;IACG,GAAG,CACP,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAYjC;;;;;;;;;;;;;;;;;OAiBG;IACG,IAAI,CAAC,MAAM,GAAE,iBAAsB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAerE;;;;;;;;;OASG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvC;;;;;;;;;;;;;OAaG;IACG,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;CAIxD;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B"}
@@ -1,126 +0,0 @@
1
- import { isPublicEvent } from "../thread/utils.js";
2
- /**
3
- * Threads resource - provides a clean API for managing threads.
4
- *
5
- * Returns public ThreadResource types, not internal Thread class instances.
6
- */
7
- export class ThreadsResource {
8
- store;
9
- constructor(store) {
10
- this.store = store;
11
- }
12
- /**
13
- * Get a thread by ID.
14
- *
15
- * @param id - Thread ID
16
- * @param options - Include options (history included by default)
17
- * @returns Thread resource, or null if not found
18
- *
19
- * @example
20
- * ```ts
21
- * // With history (default)
22
- * const thread = await kernl.threads.get("thread_123");
23
- * console.log(thread?.history); // Array of ThreadEvents
24
- *
25
- * // Without history
26
- * const thread = await kernl.threads.get("thread_123", { includeHistory: false });
27
- * ```
28
- */
29
- async get(id, options) {
30
- const includeHistory = options?.includeHistory ?? true; // include history by default
31
- const thread = await this.store.get(id, { history: includeHistory });
32
- if (!thread) {
33
- return null;
34
- }
35
- const history = includeHistory ? await this.store.history(id) : undefined;
36
- return ThreadResourceCodec.decode(thread, history);
37
- }
38
- /**
39
- * List threads with optional filtering and pagination.
40
- *
41
- * Returns thread metadata only (no event history).
42
- * Use get() with includeHistory to retrieve full thread details.
43
- *
44
- * @param params - List parameters
45
- * @returns Array of thread resources (metadata only)
46
- *
47
- * @example
48
- * ```ts
49
- * // List recent threads for a specific agent
50
- * const threads = await kernl.threads.list({
51
- * agentId: "jarvis",
52
- * limit: 20
53
- * });
54
- * ```
55
- */
56
- async list(params = {}) {
57
- const options = {
58
- limit: params.limit,
59
- filter: {
60
- agentId: params.agentId,
61
- namespace: params.namespace,
62
- },
63
- order: { createdAt: "desc" },
64
- };
65
- // TODO: Implement cursor-based pagination with before/after
66
- const threads = await this.store.list(options);
67
- return threads.map((t) => ThreadResourceCodec.decode(t));
68
- }
69
- /**
70
- * Delete a thread and all its events.
71
- *
72
- * @param id - Thread ID
73
- *
74
- * @example
75
- * ```ts
76
- * await kernl.threads.delete("thread_123");
77
- * ```
78
- */
79
- async delete(id) {
80
- return this.store.delete(id);
81
- }
82
- /**
83
- * Get the event history for a thread.
84
- *
85
- * Returns only public/client-facing events (excludes internal system events).
86
- *
87
- * @param id - Thread ID
88
- * @returns Array of public thread events
89
- *
90
- * @example
91
- * ```ts
92
- * const events = await kernl.threads.history("thread_123");
93
- * console.log(events.length); // Number of events in thread
94
- * ```
95
- */
96
- async history(id) {
97
- const events = await this.store.history(id);
98
- return events.filter(isPublicEvent);
99
- }
100
- }
101
- /**
102
- * Codec: Convert internal Thread instance to public ThreadResource.
103
- */
104
- const ThreadResourceCodec = {
105
- decode(thread, history) {
106
- const resource = {
107
- tid: thread.tid,
108
- namespace: thread.namespace,
109
- agentId: thread.agent.id,
110
- model: {
111
- provider: thread.model.provider,
112
- modelId: thread.model.modelId,
113
- },
114
- context: thread.context.context,
115
- parentTaskId: thread.parent?.id ?? null,
116
- state: thread.state,
117
- createdAt: thread.createdAt,
118
- updatedAt: thread.updatedAt,
119
- };
120
- if (history !== undefined) {
121
- // Filter to only public events (exclude internal system events)
122
- resource.history = history.filter(isPublicEvent);
123
- }
124
- return resource;
125
- },
126
- };
package/dist/kernl.d.ts DELETED
@@ -1,51 +0,0 @@
1
- import { Agent } from "./agent.js";
2
- import { UnknownContext } from "./context.js";
3
- import { KernlHooks } from "./lifecycle.js";
4
- import type { Thread } from "./thread/index.js";
5
- import type { ResolvedAgentResponse } from "./guardrail.js";
6
- import { type KernlStorage } from "./storage/index.js";
7
- import { RThreads } from "./api/resources/threads/index.js";
8
- import type { KernlOptions } from "./types/kernl.js";
9
- import type { ThreadExecuteResult, ThreadStreamEvent } from "./types/thread.js";
10
- import type { AgentResponseType } from "./types/agent.js";
11
- /**
12
- * The kernl - manages agent processes, scheduling, and task lifecycle.
13
- *
14
- * Orchestrates agent execution, including guardrails, tool calls, session persistence, and
15
- * tracing.
16
- */
17
- export declare class Kernl extends KernlHooks<UnknownContext, AgentResponseType> {
18
- private agents;
19
- private models;
20
- readonly storage: KernlStorage;
21
- athreads: Map<string, Thread<any, any>>;
22
- readonly threads: RThreads;
23
- constructor(options?: KernlOptions);
24
- /**
25
- * Registers a new agent with the kernl instance.
26
- */
27
- register(agent: Agent): void;
28
- /**
29
- * Spawn a new thread - blocking execution
30
- */
31
- spawn<TContext, TResponse extends AgentResponseType>(thread: Thread<TContext, TResponse>): Promise<ThreadExecuteResult<ResolvedAgentResponse<TResponse>>>;
32
- /**
33
- * Schedule an existing thread - blocking execution
34
- *
35
- * NOTE: just blocks for now
36
- */
37
- schedule<TContext, TResponse extends AgentResponseType>(thread: Thread<TContext, TResponse>): Promise<ThreadExecuteResult<ResolvedAgentResponse<TResponse>>>;
38
- /**
39
- * (TMP) - won't make sense in async scheduling contexts
40
- *
41
- * Spawn a new thread - streaming execution
42
- */
43
- spawnStream<TContext, TResponse extends AgentResponseType>(thread: Thread<TContext, TResponse>): AsyncIterable<ThreadStreamEvent>;
44
- /**
45
- * (TMP) - won't make sense with async scheduling contexts
46
- *
47
- * Schedule an existing thread - streaming execution
48
- */
49
- scheduleStream<TContext, TResponse extends AgentResponseType>(thread: Thread<TContext, TResponse>): AsyncIterable<ThreadStreamEvent>;
50
- }
51
- //# sourceMappingURL=kernl.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"kernl.d.ts","sourceRoot":"","sources":["../src/kernl.ts"],"names":[],"mappings":"AAEA,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;AAEnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD;;;;;GAKG;AACH,qBAAa,KAAM,SAAQ,UAAU,CAAC,cAAc,EAAE,iBAAiB,CAAC;IACtE,OAAO,CAAC,MAAM,CAAiC;IAC/C,OAAO,CAAC,MAAM,CAAyC;IAEvD,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAa;IAGpD,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;gBAEf,OAAO,GAAE,YAAiB;IAOtC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAa5B;;OAEG;IACG,KAAK,CAAC,QAAQ,EAAE,SAAS,SAAS,iBAAiB,EACvD,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,GAClC,OAAO,CAAC,mBAAmB,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC,CAAC;IASjE;;;;OAIG;IACG,QAAQ,CAAC,QAAQ,EAAE,SAAS,SAAS,iBAAiB,EAC1D,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,GAClC,OAAO,CAAC,mBAAmB,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC,CAAC;IASjE;;;;OAIG;IACI,WAAW,CAAC,QAAQ,EAAE,SAAS,SAAS,iBAAiB,EAC9D,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,GAClC,aAAa,CAAC,iBAAiB,CAAC;IASnC;;;;OAIG;IACI,cAAc,CAAC,QAAQ,EAAE,SAAS,SAAS,iBAAiB,EACjE,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,GAClC,aAAa,CAAC,iBAAiB,CAAC;CAQpC"}
package/dist/kernl.js DELETED
@@ -1,91 +0,0 @@
1
- import { KernlHooks } from "./lifecycle.js";
2
- import { InMemoryStorage } from "./storage/index.js";
3
- import { RThreads } from "./api/resources/threads/index.js";
4
- /**
5
- * The kernl - manages agent processes, scheduling, and task lifecycle.
6
- *
7
- * Orchestrates agent execution, including guardrails, tool calls, session persistence, and
8
- * tracing.
9
- */
10
- export class Kernl extends KernlHooks {
11
- agents = new Map();
12
- models = new Map();
13
- storage;
14
- athreads = new Map(); /* active threads */
15
- // --- public API ---
16
- threads; /* Threads resource */
17
- constructor(options = {}) {
18
- super();
19
- this.storage = options.storage?.db ?? new InMemoryStorage();
20
- this.storage.bind({ agents: this.agents, models: this.models });
21
- this.threads = new RThreads(this.storage.threads);
22
- }
23
- /**
24
- * Registers a new agent with the kernl instance.
25
- */
26
- register(agent) {
27
- this.agents.set(agent.id, agent);
28
- agent.bind(this);
29
- // (TODO): implement exhaustive model registry in protocol/ package
30
- //
31
- // auto-populate model registry for storage hydration
32
- const key = `${agent.model.provider}/${agent.model.modelId}`;
33
- if (!this.models.has(key)) {
34
- this.models.set(key, agent.model);
35
- }
36
- }
37
- /**
38
- * Spawn a new thread - blocking execution
39
- */
40
- async spawn(thread) {
41
- this.athreads.set(thread.tid, thread);
42
- try {
43
- return await thread.execute();
44
- }
45
- finally {
46
- this.athreads.delete(thread.tid);
47
- }
48
- }
49
- /**
50
- * Schedule an existing thread - blocking execution
51
- *
52
- * NOTE: just blocks for now
53
- */
54
- async schedule(thread) {
55
- this.athreads.set(thread.tid, thread);
56
- try {
57
- return await thread.execute();
58
- }
59
- finally {
60
- this.athreads.delete(thread.tid);
61
- }
62
- }
63
- /**
64
- * (TMP) - won't make sense in async scheduling contexts
65
- *
66
- * Spawn a new thread - streaming execution
67
- */
68
- async *spawnStream(thread) {
69
- this.athreads.set(thread.tid, thread);
70
- try {
71
- yield* thread.stream();
72
- }
73
- finally {
74
- this.athreads.delete(thread.tid);
75
- }
76
- }
77
- /**
78
- * (TMP) - won't make sense with async scheduling contexts
79
- *
80
- * Schedule an existing thread - streaming execution
81
- */
82
- async *scheduleStream(thread) {
83
- this.athreads.set(thread.tid, thread);
84
- try {
85
- yield* thread.stream();
86
- }
87
- finally {
88
- this.athreads.delete(thread.tid);
89
- }
90
- }
91
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/types/agent.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,UAAU,CAAC;AAExC;;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"}
@@ -1,42 +0,0 @@
1
- import { LanguageModel } from "@kernl-sdk/protocol";
2
- import { Agent } from "../agent.js";
3
- import { KernlStorage } from "../storage/index.js";
4
- /**
5
- * Storage configuration for Kernl.
6
- */
7
- export interface StorageOptions {
8
- /**
9
- * Relational database storage (threads, tasks, traces).
10
- */
11
- db?: KernlStorage;
12
- }
13
- /**
14
- * Configuration options for creating a Kernl instance.
15
- */
16
- export interface KernlOptions {
17
- /**
18
- * Storage configuration for persisting threads, tasks, and traces.
19
- */
20
- storage?: StorageOptions;
21
- }
22
- /**
23
- * Agent registry interface.
24
- *
25
- * Satisfied by Map<string, Agent>.
26
- */
27
- export interface AgentRegistry {
28
- get(id: string): Agent<any> | undefined;
29
- }
30
- /**
31
- * Model registry interface.
32
- *
33
- * Satisfied by Map<string, LanguageModel>.
34
- * Key format: "provider/modelId"
35
- *
36
- * TODO: Create an exhaustive model registry in the protocol package
37
- * with all supported models and their metadata.
38
- */
39
- export interface ModelRegistry {
40
- get(key: string): LanguageModel | undefined;
41
- }
42
- //# sourceMappingURL=kernl.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"kernl.d.ts","sourceRoot":"","sources":["../../src/types/kernl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,EAAE,CAAC,EAAE,YAAY,CAAC;CAMnB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;CACzC;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAAC;CAC7C"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"thread.d.ts","sourceRoot":"","sources":["../../src/types/thread.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,Q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