kernl 0.2.1 → 0.6.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 (267) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-check-types.log +4 -0
  3. package/CHANGELOG.md +138 -0
  4. package/LICENSE +1 -1
  5. package/dist/agent/__tests__/concurrency.test.d.ts +2 -0
  6. package/dist/agent/__tests__/concurrency.test.d.ts.map +1 -0
  7. package/dist/agent/__tests__/concurrency.test.js +152 -0
  8. package/dist/agent/__tests__/run.test.d.ts +2 -0
  9. package/dist/agent/__tests__/run.test.d.ts.map +1 -0
  10. package/dist/agent/__tests__/run.test.js +357 -0
  11. package/dist/agent/index.d.ts +1 -0
  12. package/dist/agent/index.d.ts.map +1 -0
  13. package/dist/agent.d.ts +32 -9
  14. package/dist/agent.d.ts.map +1 -1
  15. package/dist/agent.js +101 -14
  16. package/dist/api/__tests__/cursor-page.test.d.ts +2 -0
  17. package/dist/api/__tests__/cursor-page.test.d.ts.map +1 -0
  18. package/dist/api/__tests__/cursor-page.test.js +414 -0
  19. package/dist/api/__tests__/offset-page.test.d.ts +2 -0
  20. package/dist/api/__tests__/offset-page.test.d.ts.map +1 -0
  21. package/dist/api/__tests__/offset-page.test.js +510 -0
  22. package/dist/api/__tests__/threads.test.d.ts +2 -0
  23. package/dist/api/__tests__/threads.test.d.ts.map +1 -0
  24. package/dist/api/__tests__/threads.test.js +338 -0
  25. package/dist/api/models/index.d.ts +2 -0
  26. package/dist/api/models/index.d.ts.map +1 -0
  27. package/dist/api/models/thread.d.ts +120 -0
  28. package/dist/api/models/thread.d.ts.map +1 -0
  29. package/dist/api/pagination/base.d.ts +48 -0
  30. package/dist/api/pagination/base.d.ts.map +1 -0
  31. package/dist/api/pagination/base.js +45 -0
  32. package/dist/api/pagination/cursor.d.ts +44 -0
  33. package/dist/api/pagination/cursor.d.ts.map +1 -0
  34. package/dist/api/pagination/cursor.js +52 -0
  35. package/dist/api/pagination/offset.d.ts +42 -0
  36. package/dist/api/pagination/offset.d.ts.map +1 -0
  37. package/dist/api/pagination/offset.js +55 -0
  38. package/dist/api/resources/threads/events.d.ts +21 -0
  39. package/dist/api/resources/threads/events.d.ts.map +1 -0
  40. package/dist/api/resources/threads/events.js +24 -0
  41. package/dist/api/resources/threads/index.d.ts +4 -0
  42. package/dist/api/resources/threads/index.d.ts.map +1 -0
  43. package/dist/api/resources/threads/index.js +2 -0
  44. package/dist/api/resources/threads/threads.d.ts +57 -0
  45. package/dist/api/resources/threads/threads.d.ts.map +1 -0
  46. package/dist/api/resources/threads/threads.js +199 -0
  47. package/dist/api/resources/threads/types.d.ts +123 -0
  48. package/dist/api/resources/threads/types.d.ts.map +1 -0
  49. package/dist/api/resources/threads/utils.d.ts +18 -0
  50. package/dist/api/resources/threads/utils.d.ts.map +1 -0
  51. package/dist/api/resources/threads/utils.js +78 -0
  52. package/dist/context.d.ts +5 -1
  53. package/dist/context.d.ts.map +1 -1
  54. package/dist/context.js +6 -1
  55. package/dist/index.d.ts +9 -1
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +7 -0
  58. package/dist/internal.d.ts +4 -0
  59. package/dist/internal.d.ts.map +1 -0
  60. package/dist/internal.js +2 -0
  61. package/dist/kernl/index.d.ts +3 -0
  62. package/dist/kernl/index.d.ts.map +1 -0
  63. package/dist/kernl/index.js +2 -0
  64. package/dist/kernl/kernl.d.ts +64 -0
  65. package/dist/kernl/kernl.d.ts.map +1 -0
  66. package/dist/kernl/kernl.js +116 -0
  67. package/dist/kernl/threads.d.ts +110 -0
  68. package/dist/kernl/threads.d.ts.map +1 -0
  69. package/dist/kernl/threads.js +126 -0
  70. package/dist/kernl.d.ts +22 -6
  71. package/dist/kernl.d.ts.map +1 -1
  72. package/dist/kernl.js +73 -10
  73. package/dist/lib/env.d.ts +3 -3
  74. package/dist/lib/env.js +1 -1
  75. package/dist/mcp/__tests__/integration.test.js +8 -8
  76. package/dist/mcp/__tests__/utils.test.js +6 -6
  77. package/dist/mcp/http.d.ts +1 -1
  78. package/dist/mcp/http.d.ts.map +1 -1
  79. package/dist/mcp/http.js +9 -9
  80. package/dist/mcp/sse.d.ts +1 -1
  81. package/dist/mcp/sse.d.ts.map +1 -1
  82. package/dist/mcp/sse.js +7 -7
  83. package/dist/mcp/utils.d.ts +1 -1
  84. package/dist/mcp/utils.d.ts.map +1 -1
  85. package/dist/mcp/utils.js +4 -5
  86. package/dist/storage/__tests__/in-memory.test.d.ts +2 -0
  87. package/dist/storage/__tests__/in-memory.test.d.ts.map +1 -0
  88. package/dist/storage/__tests__/in-memory.test.js +455 -0
  89. package/dist/storage/base.d.ts +64 -0
  90. package/dist/storage/base.d.ts.map +1 -0
  91. package/dist/storage/base.js +4 -0
  92. package/dist/storage/in-memory.d.ts +62 -0
  93. package/dist/storage/in-memory.d.ts.map +1 -0
  94. package/dist/storage/in-memory.js +283 -0
  95. package/dist/storage/index.d.ts +10 -0
  96. package/dist/storage/index.d.ts.map +1 -0
  97. package/dist/storage/index.js +7 -0
  98. package/dist/storage/thread.d.ts +123 -0
  99. package/dist/storage/thread.d.ts.map +1 -0
  100. package/dist/storage/thread.js +4 -0
  101. package/dist/task.d.ts +5 -3
  102. package/dist/task.d.ts.map +1 -1
  103. package/dist/task.js +10 -8
  104. package/dist/thread/__tests__/fixtures/mock-model.d.ts +1 -2
  105. package/dist/thread/__tests__/fixtures/mock-model.d.ts.map +1 -1
  106. package/dist/thread/__tests__/integration.test.js +6 -6
  107. package/dist/thread/__tests__/namespace.test.d.ts +2 -0
  108. package/dist/thread/__tests__/namespace.test.d.ts.map +1 -0
  109. package/dist/thread/__tests__/namespace.test.js +131 -0
  110. package/dist/thread/__tests__/thread-persistence.test.d.ts +2 -0
  111. package/dist/thread/__tests__/thread-persistence.test.d.ts.map +1 -0
  112. package/dist/thread/__tests__/thread-persistence.test.js +351 -0
  113. package/dist/thread/__tests__/thread.test.js +49 -51
  114. package/dist/thread/thread.d.ts +70 -18
  115. package/dist/thread/thread.d.ts.map +1 -1
  116. package/dist/thread/thread.js +211 -73
  117. package/dist/thread/utils.d.ts +36 -8
  118. package/dist/thread/utils.d.ts.map +1 -1
  119. package/dist/thread/utils.js +52 -8
  120. package/dist/tool/__tests__/fixtures.js +1 -1
  121. package/dist/tool/__tests__/toolkit.test.js +15 -12
  122. package/dist/tool/tool.js +3 -3
  123. package/dist/types/kernl.d.ts +42 -0
  124. package/dist/types/kernl.d.ts.map +1 -0
  125. package/dist/types/thread.d.ts +108 -22
  126. package/dist/types/thread.d.ts.map +1 -1
  127. package/dist/types/thread.js +12 -0
  128. package/package.json +11 -7
  129. package/src/agent/__tests__/concurrency.test.ts +194 -0
  130. package/src/agent/__tests__/run.test.ts +441 -0
  131. package/src/agent/index.ts +0 -0
  132. package/src/agent.ts +139 -24
  133. package/src/api/__tests__/cursor-page.test.ts +512 -0
  134. package/src/api/__tests__/offset-page.test.ts +624 -0
  135. package/src/api/__tests__/threads.test.ts +415 -0
  136. package/src/api/models/index.ts +6 -0
  137. package/src/api/models/thread.ts +138 -0
  138. package/src/api/pagination/base.ts +79 -0
  139. package/src/api/pagination/cursor.ts +86 -0
  140. package/src/api/pagination/offset.ts +89 -0
  141. package/src/api/resources/threads/events.ts +26 -0
  142. package/src/api/resources/threads/index.ts +9 -0
  143. package/src/api/resources/threads/threads.ts +256 -0
  144. package/src/api/resources/threads/types.ts +143 -0
  145. package/src/api/resources/threads/utils.ts +104 -0
  146. package/src/context.ts +10 -1
  147. package/src/index.ts +49 -1
  148. package/src/internal.ts +15 -0
  149. package/src/kernl.ts +86 -17
  150. package/src/mcp/__tests__/integration.test.ts +8 -9
  151. package/src/mcp/__tests__/utils.test.ts +6 -6
  152. package/src/mcp/http.ts +9 -9
  153. package/src/mcp/sse.ts +7 -7
  154. package/src/mcp/utils.ts +6 -5
  155. package/src/storage/__tests__/in-memory.test.ts +534 -0
  156. package/src/storage/base.ts +77 -0
  157. package/src/storage/in-memory.ts +372 -0
  158. package/src/storage/index.ts +21 -0
  159. package/src/storage/thread.ts +141 -0
  160. package/src/task.ts +12 -10
  161. package/src/thread/__tests__/fixtures/mock-model.ts +2 -4
  162. package/src/thread/__tests__/integration.test.ts +13 -12
  163. package/src/thread/__tests__/namespace.test.ts +158 -0
  164. package/src/thread/__tests__/thread-persistence.test.ts +367 -0
  165. package/src/thread/__tests__/thread.test.ts +52 -54
  166. package/src/thread/thread.ts +247 -96
  167. package/src/thread/utils.ts +76 -13
  168. package/src/tool/__tests__/fixtures.ts +1 -1
  169. package/src/tool/__tests__/toolkit.test.ts +15 -12
  170. package/src/tool/tool.ts +3 -3
  171. package/src/types/kernl.ts +51 -0
  172. package/src/types/thread.ts +139 -25
  173. package/vitest.config.ts +1 -0
  174. package/dist/env.d.ts +0 -45
  175. package/dist/env.d.ts.map +0 -1
  176. package/dist/env.js +0 -31
  177. package/dist/error.d.ts +0 -1
  178. package/dist/error.d.ts.map +0 -1
  179. package/dist/kernel.d.ts +0 -7
  180. package/dist/kernel.d.ts.map +0 -1
  181. package/dist/kernel.js +0 -7
  182. package/dist/lib/serde/__tests__/codec.test.d.ts +0 -2
  183. package/dist/lib/serde/__tests__/codec.test.d.ts.map +0 -1
  184. package/dist/lib/serde/__tests__/codec.test.js +0 -75
  185. package/dist/lib/serde/codec.d.ts +0 -12
  186. package/dist/lib/serde/codec.d.ts.map +0 -1
  187. package/dist/lib/serde/codec.js +0 -54
  188. package/dist/lib/serde/thread.d.ts +0 -1
  189. package/dist/lib/serde/thread.d.ts.map +0 -1
  190. package/dist/lib/serde/thread.js +0 -172
  191. package/dist/lib/serde/tool.d.ts +0 -36
  192. package/dist/lib/serde/tool.d.ts.map +0 -1
  193. package/dist/lib/utils.d.ts +0 -19
  194. package/dist/lib/utils.d.ts.map +0 -1
  195. package/dist/lib/utils.js +0 -41
  196. package/dist/logger.d.ts +0 -36
  197. package/dist/logger.d.ts.map +0 -1
  198. package/dist/logger.js +0 -43
  199. package/dist/mcp/__tests__/fixtures/echo-server.d.ts +0 -3
  200. package/dist/mcp/__tests__/fixtures/echo-server.d.ts.map +0 -1
  201. package/dist/mcp/__tests__/fixtures/echo-server.js +0 -92
  202. package/dist/mcp/__tests__/fixtures/math-server.d.ts +0 -3
  203. package/dist/mcp/__tests__/fixtures/math-server.d.ts.map +0 -1
  204. package/dist/mcp/__tests__/fixtures/math-server.js +0 -98
  205. package/dist/mcp/__tests__/fixtures/test-server.d.ts +0 -3
  206. package/dist/mcp/__tests__/fixtures/test-server.d.ts.map +0 -1
  207. package/dist/mcp/__tests__/fixtures/test-server.js +0 -163
  208. package/dist/mcp/__tests__/test-utils.d.ts +0 -17
  209. package/dist/mcp/__tests__/test-utils.d.ts.map +0 -1
  210. package/dist/mcp/__tests__/test-utils.js +0 -42
  211. package/dist/mcp/node.d.ts +0 -60
  212. package/dist/mcp/node.d.ts.map +0 -1
  213. package/dist/mcp/node.js +0 -297
  214. package/dist/model.d.ts +0 -175
  215. package/dist/model.d.ts.map +0 -1
  216. package/dist/providers/ai.d.ts +0 -1
  217. package/dist/providers/ai.d.ts.map +0 -1
  218. package/dist/providers/ai.js +0 -1
  219. package/dist/providers/default.d.ts +0 -16
  220. package/dist/providers/default.d.ts.map +0 -1
  221. package/dist/providers/default.js +0 -17
  222. package/dist/providers/registry.d.ts +0 -1
  223. package/dist/providers/registry.d.ts.map +0 -1
  224. package/dist/providers/registry.js +0 -1
  225. package/dist/sched/scheduler.d.ts +0 -20
  226. package/dist/sched/scheduler.d.ts.map +0 -1
  227. package/dist/sched/task.d.ts +0 -92
  228. package/dist/sched/task.d.ts.map +0 -1
  229. package/dist/sched/task.js +0 -102
  230. package/dist/serde/__tests__/codec.test.d.ts +0 -2
  231. package/dist/serde/__tests__/codec.test.d.ts.map +0 -1
  232. package/dist/serde/__tests__/codec.test.js +0 -75
  233. package/dist/serde/codec.d.ts +0 -12
  234. package/dist/serde/codec.d.ts.map +0 -1
  235. package/dist/serde/codec.js +0 -54
  236. package/dist/serde/json.d.ts +0 -8
  237. package/dist/serde/json.d.ts.map +0 -1
  238. package/dist/serde/json.js +0 -13
  239. package/dist/serde/thread.d.ts +0 -687
  240. package/dist/serde/thread.d.ts.map +0 -1
  241. package/dist/serde/thread.js +0 -158
  242. package/dist/serde/tool.d.ts +0 -36
  243. package/dist/serde/tool.d.ts.map +0 -1
  244. package/dist/session.d.ts +0 -1
  245. package/dist/session.d.ts.map +0 -1
  246. package/dist/session.js +0 -1
  247. package/dist/thread/__tests__/stream.test.d.ts +0 -2
  248. package/dist/thread/__tests__/stream.test.d.ts.map +0 -1
  249. package/dist/thread/__tests__/stream.test.js +0 -244
  250. package/dist/tool/mcp.d.ts +0 -75
  251. package/dist/tool/mcp.d.ts.map +0 -1
  252. package/dist/tool/mcp.js +0 -111
  253. package/dist/tools.d.ts +0 -362
  254. package/dist/tools.d.ts.map +0 -1
  255. package/dist/tools.js +0 -220
  256. package/dist/types/proto.d.ts +0 -1551
  257. package/dist/types/proto.d.ts.map +0 -1
  258. package/dist/types/proto.js +0 -531
  259. package/dist/usage.d.ts +0 -43
  260. package/dist/usage.d.ts.map +0 -1
  261. package/dist/usage.js +0 -61
  262. package/src/lib/serde/thread.ts +0 -188
  263. /package/dist/{error.js → agent/index.js} +0 -0
  264. /package/dist/{lib/serde/tool.js → api/models/index.js} +0 -0
  265. /package/dist/{model.js → api/models/thread.js} +0 -0
  266. /package/dist/{sched/scheduler.js → api/resources/threads/types.js} +0 -0
  267. /package/dist/{serde/tool.js → types/kernl.js} +0 -0
@@ -0,0 +1,42 @@
1
+ import { AbstractPage, type PageParamsBase } from "./base";
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,55 @@
1
+ import { AbstractPage } from "./base";
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
+ }
@@ -0,0 +1,21 @@
1
+ import type { ThreadStore } from "../../../storage";
2
+ import type { MThreadEvent } from "../../../api/models";
3
+ /**
4
+ * Events subresource for threads.
5
+ *
6
+ * Provides access to the event log for an individual thread, filtered down to
7
+ * events that make sense to surface to callers (messages, tool calls/results, etc.).
8
+ */
9
+ export declare class RThreadEvents {
10
+ private readonly store;
11
+ constructor(store: ThreadStore);
12
+ /**
13
+ * List events for a thread.
14
+ *
15
+ * Returns only public events – internal system events are filtered out.
16
+ *
17
+ * @param tid - Thread ID
18
+ */
19
+ list(tid: string): Promise<MThreadEvent[]>;
20
+ }
21
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../../../src/api/resources/threads/events.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAGjD;;;;;GAKG;AACH,qBAAa,aAAa;IACZ,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,WAAW;IAE/C;;;;;;OAMG;IACG,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;CAIjD"}
@@ -0,0 +1,24 @@
1
+ import { isPublicEvent } from "../../../thread/utils";
2
+ /**
3
+ * Events subresource for threads.
4
+ *
5
+ * Provides access to the event log for an individual thread, filtered down to
6
+ * events that make sense to surface to callers (messages, tool calls/results, etc.).
7
+ */
8
+ export class RThreadEvents {
9
+ store;
10
+ constructor(store) {
11
+ this.store = store;
12
+ }
13
+ /**
14
+ * List events for a thread.
15
+ *
16
+ * Returns only public events – internal system events are filtered out.
17
+ *
18
+ * @param tid - Thread ID
19
+ */
20
+ async list(tid) {
21
+ const events = await this.store.history(tid);
22
+ return events.filter(isPublicEvent).map((e) => e);
23
+ }
24
+ }
@@ -0,0 +1,4 @@
1
+ export { RThreads } from "./threads";
2
+ export { RThreadEvents } from "./events";
3
+ export type { RThreadsListParams, RThreadGetOptions, RThreadHistoryParams, RThreadCreateParams, RThreadUpdateParams, } from "./types";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/api/resources/threads/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,SAAS,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { RThreads } from "./threads";
2
+ export { RThreadEvents } from "./events";
@@ -0,0 +1,57 @@
1
+ import type { ThreadStore } from "../../../storage";
2
+ import type { MThread, MThreadEvent } from "../../../api/models";
3
+ import { CursorPage } from "../../../api/pagination/cursor";
4
+ import { RThreadEvents } from "./events";
5
+ import type { RThreadCreateParams, RThreadGetOptions, RThreadHistoryParams, RThreadsListParams, RThreadUpdateParams } from "./types";
6
+ /**
7
+ * Threads resource.
8
+ *
9
+ * Provides a structured API for listing, inspecting, and deleting threads.
10
+ */
11
+ export declare class RThreads {
12
+ private readonly store;
13
+ readonly events: RThreadEvents;
14
+ constructor(store: ThreadStore);
15
+ /**
16
+ * Get a single thread by ID.
17
+ *
18
+ * When `options.history` is set, the returned thread will include a
19
+ * `history` field containing public events for that thread.
20
+ */
21
+ get(tid: string, options?: RThreadGetOptions): Promise<MThread | null>;
22
+ /**
23
+ * Create a new thread.
24
+ */
25
+ create(params: RThreadCreateParams): Promise<MThread>;
26
+ /**
27
+ * List threads with optional filtering and cursor-based pagination.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const threads = await kernl.threads.list({ limit: 20 });
32
+ *
33
+ * for await (const thread of threads) {
34
+ * console.log(thread.tid);
35
+ * }
36
+ * ```
37
+ */
38
+ list(params?: RThreadsListParams): Promise<CursorPage<MThread, RThreadsListParams>>;
39
+ /**
40
+ * Delete a thread and all associated events.
41
+ */
42
+ delete(tid: string): Promise<void>;
43
+ /**
44
+ * Convenience wrapper around `events.list()` for fetching a thread's history.
45
+ *
46
+ * History is returned in descending sequence order by default (latest first).
47
+ */
48
+ history(tid: string, params?: RThreadHistoryParams): Promise<MThreadEvent[]>;
49
+ /**
50
+ * Update mutable thread fields.
51
+ *
52
+ * Currently only supports updating the human-readable `title`, which is
53
+ * stored in thread metadata as `metadata.title`.
54
+ */
55
+ update(tid: string, patch: RThreadUpdateParams): Promise<MThread | null>;
56
+ }
57
+ //# sourceMappingURL=threads.d.ts.map
@@ -0,0 +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,yBAAyB,CAAC;AAE9E,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"}
@@ -0,0 +1,199 @@
1
+ import { isPublicEvent } from "../../../thread/utils";
2
+ import { Context } from "../../../context";
3
+ import { randomID } from "@kernl-sdk/shared/lib";
4
+ import { RUNNING } from "@kernl-sdk/protocol";
5
+ import { CursorPage } from "../../../api/pagination/cursor";
6
+ import { RThreadEvents } from "./events";
7
+ import { MThreadCodec, ThreadsFilterCodec, ThreadsOrderCodec } from "./utils";
8
+ /**
9
+ * Threads resource.
10
+ *
11
+ * Provides a structured API for listing, inspecting, and deleting threads.
12
+ */
13
+ export class RThreads {
14
+ store;
15
+ events;
16
+ constructor(store) {
17
+ this.store = store;
18
+ this.events = new RThreadEvents(store);
19
+ }
20
+ /**
21
+ * Get a single thread by ID.
22
+ *
23
+ * When `options.history` is set, the returned thread will include a
24
+ * `history` field containing public events for that thread.
25
+ */
26
+ async get(tid, options) {
27
+ const thread = await this.store.get(tid);
28
+ if (!thread)
29
+ return null;
30
+ const model = MThreadCodec.encode(thread);
31
+ if (options?.history) {
32
+ const historyParams = options.history === true ? undefined : options.history;
33
+ const history = await this.history(tid, historyParams);
34
+ model.history = history; // attach history lazily so callers can opt-in.
35
+ }
36
+ return model;
37
+ }
38
+ /**
39
+ * Create a new thread.
40
+ */
41
+ async create(params) {
42
+ const now = new Date();
43
+ const tid = params.tid ?? `tid_${randomID()}`;
44
+ const namespace = params.namespace ?? "kernl";
45
+ // merge caller-supplied metadata with optional title
46
+ const baseMetadata = {
47
+ ...(params.metadata ?? {}),
48
+ };
49
+ if (params.title !== undefined) {
50
+ const trimmed = params.title.trim();
51
+ if (trimmed) {
52
+ baseMetadata.title = trimmed;
53
+ }
54
+ else {
55
+ delete baseMetadata.title;
56
+ }
57
+ }
58
+ const metadata = Object.keys(baseMetadata).length > 0 ? baseMetadata : null;
59
+ const thread = await this.store.insert({
60
+ id: tid,
61
+ namespace,
62
+ agentId: params.agentId,
63
+ model: `${params.model.provider}/${params.model.modelId}`,
64
+ context: params.context,
65
+ parentTaskId: params.parentTaskId ?? null,
66
+ metadata,
67
+ createdAt: now,
68
+ updatedAt: now,
69
+ });
70
+ return MThreadCodec.encode(thread);
71
+ }
72
+ /**
73
+ * List threads with optional filtering and cursor-based pagination.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * const threads = await kernl.threads.list({ limit: 20 });
78
+ *
79
+ * for await (const thread of threads) {
80
+ * console.log(thread.tid);
81
+ * }
82
+ * ```
83
+ */
84
+ async list(params = {}) {
85
+ const loader = async (p) => {
86
+ const offset = p.cursor ? Number(p.cursor) : 0;
87
+ const limit = p.limit;
88
+ const effectiveLimit = limit !== undefined ? limit + 1 : undefined;
89
+ const filter = ThreadsFilterCodec.encode(p);
90
+ const order = ThreadsOrderCodec.encode(p.order);
91
+ const options = {
92
+ filter,
93
+ order,
94
+ limit: effectiveLimit,
95
+ offset,
96
+ };
97
+ const threads = await this.store.list(options);
98
+ if (limit === undefined) {
99
+ // No limit requested → treat as a single, non-paginated page.
100
+ const data = threads.map((t) => MThreadCodec.encode(t));
101
+ return {
102
+ data,
103
+ next: null,
104
+ last: true,
105
+ };
106
+ }
107
+ const hasExtra = threads.length > limit;
108
+ const pageThreads = hasExtra ? threads.slice(0, limit) : threads;
109
+ const data = pageThreads.map((t) => MThreadCodec.encode(t));
110
+ const nextOffset = offset + data.length;
111
+ const last = !hasExtra || data.length === 0;
112
+ const next = last ? null : String(nextOffset);
113
+ return { data, next, last };
114
+ };
115
+ const response = await loader(params);
116
+ return new CursorPage({
117
+ params,
118
+ response,
119
+ loader,
120
+ });
121
+ }
122
+ /**
123
+ * Delete a thread and all associated events.
124
+ */
125
+ async delete(tid) {
126
+ await this.store.delete(tid);
127
+ }
128
+ /**
129
+ * Convenience wrapper around `events.list()` for fetching a thread's history.
130
+ *
131
+ * History is returned in descending sequence order by default (latest first).
132
+ */
133
+ async history(tid, params) {
134
+ const opts = {
135
+ after: params?.after,
136
+ limit: params?.limit,
137
+ order: params?.order ?? "desc",
138
+ kinds: params?.kinds,
139
+ };
140
+ const events = await this.store.history(tid, opts);
141
+ return events.filter(isPublicEvent).map((e) => e);
142
+ }
143
+ /**
144
+ * Update mutable thread fields.
145
+ *
146
+ * Currently only supports updating the human-readable `title`, which is
147
+ * stored in thread metadata as `metadata.title`.
148
+ */
149
+ async update(tid, patch) {
150
+ const current = await this.store.get(tid);
151
+ if (!current)
152
+ return null;
153
+ // Prevent context mutation while the thread is running.
154
+ if (patch.context !== undefined && current.state === RUNNING) {
155
+ throw new Error("Cannot update thread context while thread is running");
156
+ }
157
+ // build context patch
158
+ let contextPatch;
159
+ if ("context" in patch) {
160
+ const nextContextValue = patch.context === null
161
+ ? {}
162
+ : (patch.context ?? current.context.context);
163
+ contextPatch = new Context(current.namespace, nextContextValue);
164
+ }
165
+ // build metadata base according to caller intent
166
+ let metadata;
167
+ if ("metadata" in patch) {
168
+ if (patch.metadata === null) {
169
+ metadata = {};
170
+ }
171
+ else if (patch.metadata === undefined) {
172
+ metadata = current.metadata ? { ...current.metadata } : {};
173
+ }
174
+ else {
175
+ metadata = { ...patch.metadata };
176
+ }
177
+ }
178
+ else {
179
+ metadata = current.metadata ? { ...current.metadata } : {};
180
+ }
181
+ // apply title overlay on top of metadata
182
+ if ("title" in patch) {
183
+ const value = patch.title;
184
+ const trimmed = typeof value === "string" ? value.trim() : (value ?? undefined);
185
+ if (!trimmed) {
186
+ delete metadata.title; // clear title
187
+ }
188
+ else {
189
+ metadata.title = trimmed;
190
+ }
191
+ }
192
+ const nextMetadata = Object.keys(metadata).length > 0 ? metadata : null;
193
+ const updated = await this.store.update(tid, {
194
+ ...(contextPatch ? { context: contextPatch } : {}),
195
+ metadata: nextMetadata,
196
+ });
197
+ return MThreadCodec.encode(updated);
198
+ }
199
+ }
@@ -0,0 +1,123 @@
1
+ import type { ThreadState } from "../../../types/thread";
2
+ import type { SortOrder } from "../../../storage";
3
+ import type { CursorPageParams } from "../../../api/pagination/cursor";
4
+ export interface RThreadHistoryParams {
5
+ /**
6
+ * Only return events with seq greater than this value.
7
+ */
8
+ after?: number;
9
+ /**
10
+ * Maximum number of events to return.
11
+ */
12
+ limit?: number;
13
+ /**
14
+ * Sort order by sequence number.
15
+ *
16
+ * Defaults to `"desc"` so callers see the latest events first.
17
+ */
18
+ order?: "asc" | "desc";
19
+ /**
20
+ * Restrict history to specific event kinds, e.g. `["message", "tool-result"]`.
21
+ */
22
+ kinds?: string[];
23
+ }
24
+ export interface RThreadsListParams extends CursorPageParams {
25
+ namespace?: string;
26
+ agentId?: string;
27
+ state?: ThreadState | ThreadState[];
28
+ parentTaskId?: string;
29
+ /**
30
+ * Only include threads created after this timestamp.
31
+ */
32
+ after?: Date;
33
+ /**
34
+ * Only include threads created before this timestamp.
35
+ */
36
+ before?: Date;
37
+ order?: {
38
+ createdAt?: SortOrder;
39
+ updatedAt?: SortOrder;
40
+ };
41
+ }
42
+ export interface RThreadGetOptions {
43
+ /**
44
+ * Include the thread's event history on the returned model.
45
+ *
46
+ * - `true` will fetch history with default options (latest-first).
47
+ * - An object lets you override history options (limit, kinds, order, etc.).
48
+ *
49
+ * This is equivalent to calling `kernl.threads.history(tid, opts)` and
50
+ * attaching the result to `thread.history`.
51
+ */
52
+ history?: true | RThreadHistoryParams;
53
+ }
54
+ /**
55
+ * Parameters for creating a new thread via the public Threads resource.
56
+ *
57
+ * Note: low-level API requires explicit agent + model. For most callers,
58
+ * prefer the agent-scoped helpers (agent.threads.create) which infer these.
59
+ */
60
+ export interface RThreadCreateParams {
61
+ /**
62
+ * Owning agent id for the new thread.
63
+ */
64
+ agentId: string;
65
+ /**
66
+ * Optional explicit thread id.
67
+ *
68
+ * If omitted, a new id will be generated.
69
+ */
70
+ tid?: string;
71
+ /**
72
+ * Logical namespace to create the thread in.
73
+ *
74
+ * Defaults to `"kernl"` when not provided.
75
+ */
76
+ namespace?: string;
77
+ /**
78
+ * Optional human-readable title for the thread.
79
+ */
80
+ title?: string;
81
+ /**
82
+ * Initial context object for the thread.
83
+ */
84
+ context?: Record<string, unknown>;
85
+ /**
86
+ * Optional parent task id that spawned this thread, if any.
87
+ */
88
+ parentTaskId?: string | null;
89
+ /**
90
+ * Language model backing this thread.
91
+ */
92
+ model: {
93
+ provider: string;
94
+ modelId: string;
95
+ };
96
+ /**
97
+ * Arbitrary JSON-serializable metadata to attach to the thread.
98
+ */
99
+ metadata?: Record<string, unknown>;
100
+ }
101
+ /**
102
+ * Patch for updating caller-owned thread fields.
103
+ *
104
+ * Semantics for all fields:
105
+ * - `undefined` → leave the field unchanged
106
+ * - value (`object` / `string` / etc.) → replace the field
107
+ * - `null` → clear the field (for `title`, clears `metadata.title`)
108
+ */
109
+ export interface RThreadUpdateParams {
110
+ /**
111
+ * Thread context object.
112
+ */
113
+ context?: Record<string, unknown> | null;
114
+ /**
115
+ * Arbitrary metadata bag attached to the thread.
116
+ */
117
+ metadata?: Record<string, unknown> | null;
118
+ /**
119
+ * Human-readable title (stored in `metadata.title`).
120
+ */
121
+ title?: string | null;
122
+ }
123
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +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,yBAAyB,CAAC;AAEhE,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,CAAC;IACpC,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,KAAK,CAAC,EAAE,IAAI,CAAC;IAEb;;OAEG;IACH,MAAM,CAAC,EAAE,IAAI,CAAC;IAEd,KAAK,CAAC,EAAE;QACN,SAAS,CAAC,EAAE,SAAS,CAAC;QACtB,SAAS,CAAC,EAAE,SAAS,CAAC;KACvB,CAAC;CACH;AAED,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,IAAI,GAAG,oBAAoB,CAAC;CACvC;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAElC;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B;;OAEG;IACH,KAAK,EAAE;QACL,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IAEF;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAEzC;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAE1C;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB"}
@@ -0,0 +1,18 @@
1
+ import { type Codec } from "@kernl-sdk/shared/lib";
2
+ import type { Thread } from "../../../thread";
3
+ import type { ThreadFilter, ThreadListOptions } from "../../../storage";
4
+ import type { MThread } from "../../../api/models";
5
+ import type { RThreadsListParams } from "./types";
6
+ /**
7
+ * Converts an internal `Thread` runtime instance into an `MThread` model.
8
+ */
9
+ export declare const MThreadCodec: Codec<Thread, MThread>;
10
+ /**
11
+ * Converts `RThreadsListParams` into a `ThreadFilter` for the store.
12
+ */
13
+ export declare const ThreadsFilterCodec: Codec<RThreadsListParams, ThreadFilter | undefined>;
14
+ /**
15
+ * Converts list `order` params into `ThreadListOptions["order"]` for the store.
16
+ */
17
+ export declare const ThreadsOrderCodec: Codec<RThreadsListParams["order"], ThreadListOptions["order"] | undefined>;
18
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/api/resources/threads/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEvE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,CAyB/C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,KAAK,CACpC,kBAAkB,EAClB,YAAY,GAAG,SAAS,CA8BzB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,EAAE,KAAK,CACnC,kBAAkB,CAAC,OAAO,CAAC,EAC3B,iBAAiB,CAAC,OAAO,CAAC,GAAG,SAAS,CAwBvC,CAAC"}
@@ -0,0 +1,78 @@
1
+ import { UnimplementedError } from "@kernl-sdk/shared/lib";
2
+ /**
3
+ * Converts an internal `Thread` runtime instance into an `MThread` model.
4
+ */
5
+ export const MThreadCodec = {
6
+ encode(thread) {
7
+ const rawTitle = thread.metadata?.title;
8
+ const title = typeof rawTitle === "string" ? rawTitle : null;
9
+ return {
10
+ tid: thread.tid,
11
+ namespace: thread.namespace,
12
+ agentId: thread.agent.id,
13
+ title,
14
+ model: {
15
+ provider: thread.model.provider,
16
+ modelId: thread.model.modelId,
17
+ },
18
+ context: thread.context.context,
19
+ parentTaskId: thread.parent?.id ?? null,
20
+ state: thread.state,
21
+ createdAt: thread.createdAt,
22
+ updatedAt: thread.updatedAt,
23
+ };
24
+ },
25
+ decode(_model) {
26
+ throw new UnimplementedError();
27
+ },
28
+ };
29
+ /**
30
+ * Converts `RThreadsListParams` into a `ThreadFilter` for the store.
31
+ */
32
+ export const ThreadsFilterCodec = {
33
+ encode(params) {
34
+ const filter = {};
35
+ if (params.namespace !== undefined) {
36
+ filter.namespace = params.namespace;
37
+ }
38
+ if (params.state !== undefined) {
39
+ filter.state = params.state;
40
+ }
41
+ if (params.agentId !== undefined) {
42
+ filter.agentId = params.agentId;
43
+ }
44
+ if (params.parentTaskId !== undefined) {
45
+ filter.parentTaskId = params.parentTaskId;
46
+ }
47
+ if (params.after !== undefined) {
48
+ filter.createdAfter = params.after;
49
+ }
50
+ if (params.before !== undefined) {
51
+ filter.createdBefore = params.before;
52
+ }
53
+ return Object.keys(filter).length > 0 ? filter : undefined;
54
+ },
55
+ decode(_filter) {
56
+ throw new UnimplementedError();
57
+ },
58
+ };
59
+ /**
60
+ * Converts list `order` params into `ThreadListOptions["order"]` for the store.
61
+ */
62
+ export const ThreadsOrderCodec = {
63
+ encode(order) {
64
+ if (!order)
65
+ return undefined;
66
+ const result = {};
67
+ if (order.createdAt !== undefined) {
68
+ result.createdAt = order.createdAt;
69
+ }
70
+ if (order.updatedAt !== undefined) {
71
+ result.updatedAt = order.updatedAt;
72
+ }
73
+ return Object.keys(result).length > 0 ? result : undefined;
74
+ },
75
+ decode(_order) {
76
+ throw new UnimplementedError();
77
+ },
78
+ };
package/dist/context.d.ts CHANGED
@@ -7,6 +7,10 @@ export type ApprovalStatus = "approved" | "rejected" | "pending";
7
7
  * execution units.
8
8
  */
9
9
  export declare class Context<TContext = UnknownContext> {
10
+ /**
11
+ * The namespace that this context belongs to.
12
+ */
13
+ namespace: string;
10
14
  /**
11
15
  * The inner context object.
12
16
  */
@@ -26,7 +30,7 @@ export declare class Context<TContext = UnknownContext> {
26
30
  * (TEMPORARY) Used until the actions system is refined.
27
31
  */
28
32
  reject(callId: string): void;
29
- constructor(context?: TContext);
33
+ constructor(namespace?: string, context?: TContext);
30
34
  /**
31
35
  * Renders the context as a prompt using the default format selected. Kernel would inject this info automatically, but exposed in case of control
32
36
  */