@jini-ai/sqlite 0.1.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 (102) hide show
  1. package/LICENSE +201 -0
  2. package/dist/backend-config.d.ts +42 -0
  3. package/dist/backend-config.d.ts.map +1 -0
  4. package/dist/backend-config.js +57 -0
  5. package/dist/backend-config.js.map +1 -0
  6. package/dist/db/agent-sessions/agent-sessions.d.ts +79 -0
  7. package/dist/db/agent-sessions/agent-sessions.d.ts.map +1 -0
  8. package/dist/db/agent-sessions/agent-sessions.js +121 -0
  9. package/dist/db/agent-sessions/agent-sessions.js.map +1 -0
  10. package/dist/db/agent-sessions/index.d.ts +6 -0
  11. package/dist/db/agent-sessions/index.d.ts.map +1 -0
  12. package/dist/db/agent-sessions/index.js +6 -0
  13. package/dist/db/agent-sessions/index.js.map +1 -0
  14. package/dist/db/capabilities/capabilities.d.ts +39 -0
  15. package/dist/db/capabilities/capabilities.d.ts.map +1 -0
  16. package/dist/db/capabilities/capabilities.js +54 -0
  17. package/dist/db/capabilities/capabilities.js.map +1 -0
  18. package/dist/db/capabilities/index.d.ts +4 -0
  19. package/dist/db/capabilities/index.d.ts.map +1 -0
  20. package/dist/db/capabilities/index.js +4 -0
  21. package/dist/db/capabilities/index.js.map +1 -0
  22. package/dist/db/connection/connection.d.ts +18 -0
  23. package/dist/db/connection/connection.d.ts.map +1 -0
  24. package/dist/db/connection/connection.js +48 -0
  25. package/dist/db/connection/connection.js.map +1 -0
  26. package/dist/db/connection/index.d.ts +3 -0
  27. package/dist/db/connection/index.d.ts.map +1 -0
  28. package/dist/db/connection/index.js +3 -0
  29. package/dist/db/connection/index.js.map +1 -0
  30. package/dist/db/conversations/conversations.d.ts +109 -0
  31. package/dist/db/conversations/conversations.d.ts.map +1 -0
  32. package/dist/db/conversations/conversations.js +274 -0
  33. package/dist/db/conversations/conversations.js.map +1 -0
  34. package/dist/db/conversations/index.d.ts +3 -0
  35. package/dist/db/conversations/index.d.ts.map +1 -0
  36. package/dist/db/conversations/index.js +3 -0
  37. package/dist/db/conversations/index.js.map +1 -0
  38. package/dist/db/core/index.d.ts +6 -0
  39. package/dist/db/core/index.d.ts.map +1 -0
  40. package/dist/db/core/index.js +6 -0
  41. package/dist/db/core/index.js.map +1 -0
  42. package/dist/db/core/json.d.ts +13 -0
  43. package/dist/db/core/json.d.ts.map +1 -0
  44. package/dist/db/core/json.js +22 -0
  45. package/dist/db/core/json.js.map +1 -0
  46. package/dist/db/core/rows.d.ts +18 -0
  47. package/dist/db/core/rows.d.ts.map +1 -0
  48. package/dist/db/core/rows.js +17 -0
  49. package/dist/db/core/rows.js.map +1 -0
  50. package/dist/db/core/types.d.ts +14 -0
  51. package/dist/db/core/types.d.ts.map +1 -0
  52. package/dist/db/core/types.js +2 -0
  53. package/dist/db/core/types.js.map +1 -0
  54. package/dist/db/index.d.ts +18 -0
  55. package/dist/db/index.d.ts.map +1 -0
  56. package/dist/db/index.js +16 -0
  57. package/dist/db/index.js.map +1 -0
  58. package/dist/db/messages/index.d.ts +4 -0
  59. package/dist/db/messages/index.d.ts.map +1 -0
  60. package/dist/db/messages/index.js +4 -0
  61. package/dist/db/messages/index.js.map +1 -0
  62. package/dist/db/messages/messages.d.ts +129 -0
  63. package/dist/db/messages/messages.d.ts.map +1 -0
  64. package/dist/db/messages/messages.js +246 -0
  65. package/dist/db/messages/messages.js.map +1 -0
  66. package/dist/db/projects/index.d.ts +4 -0
  67. package/dist/db/projects/index.d.ts.map +1 -0
  68. package/dist/db/projects/index.js +4 -0
  69. package/dist/db/projects/index.js.map +1 -0
  70. package/dist/db/projects/projects.d.ts +122 -0
  71. package/dist/db/projects/projects.d.ts.map +1 -0
  72. package/dist/db/projects/projects.js +311 -0
  73. package/dist/db/projects/projects.js.map +1 -0
  74. package/dist/db/schema/index.d.ts +3 -0
  75. package/dist/db/schema/index.d.ts.map +1 -0
  76. package/dist/db/schema/index.js +3 -0
  77. package/dist/db/schema/index.js.map +1 -0
  78. package/dist/db/schema/migrate.d.ts +29 -0
  79. package/dist/db/schema/migrate.d.ts.map +1 -0
  80. package/dist/db/schema/migrate.js +78 -0
  81. package/dist/db/schema/migrate.js.map +1 -0
  82. package/dist/db/tool-catalog/index.d.ts +6 -0
  83. package/dist/db/tool-catalog/index.d.ts.map +1 -0
  84. package/dist/db/tool-catalog/index.js +6 -0
  85. package/dist/db/tool-catalog/index.js.map +1 -0
  86. package/dist/db/tool-catalog/tool-catalog.d.ts +70 -0
  87. package/dist/db/tool-catalog/tool-catalog.d.ts.map +1 -0
  88. package/dist/db/tool-catalog/tool-catalog.js +87 -0
  89. package/dist/db/tool-catalog/tool-catalog.js.map +1 -0
  90. package/dist/db-inspect.d.ts +62 -0
  91. package/dist/db-inspect.d.ts.map +1 -0
  92. package/dist/db-inspect.js +153 -0
  93. package/dist/db-inspect.js.map +1 -0
  94. package/dist/event-log.d.ts +33 -0
  95. package/dist/event-log.d.ts.map +1 -0
  96. package/dist/event-log.js +191 -0
  97. package/dist/event-log.js.map +1 -0
  98. package/dist/index.d.ts +12 -0
  99. package/dist/index.d.ts.map +1 -0
  100. package/dist/index.js +12 -0
  101. package/dist/index.js.map +1 -0
  102. package/package.json +49 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Support. While redistributing the Work or
166
+ Derivative Works thereof, You may choose to offer, and charge a
167
+ fee for, acceptance of support, warranty, indemnity, or other
168
+ liability obligations and/or rights consistent with this License.
169
+ However, in accepting such obligations, You may act only on Your
170
+ own behalf and on Your sole responsibility, not on behalf of any
171
+ other Contributor, and only if You agree to indemnify, defend,
172
+ and hold each Contributor harmless for any liability incurred by,
173
+ or claims asserted against, such Contributor by reason of your
174
+ accepting any such warranty or support.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Open Design contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,42 @@
1
+ /**
2
+ * @module backend-config
3
+ *
4
+ * Resolves which SQL backend a host daemon should use from environment
5
+ * variables. v1 ships local SQLite via `better-sqlite3` (see `./event-log.js`);
6
+ * a `postgres` selection is recorded so a future adapter can read it, but
7
+ * `resolveSqliteBackendConfig` never opens a connection itself — it only
8
+ * pins the parameter surface (host/port/database/user/sslMode) so a
9
+ * follow-up package can land the adapter without re-litigating the env-var
10
+ * contract.
11
+ */
12
+ export type SqliteBackendKind = 'sqlite' | 'postgres';
13
+ export interface SqliteBackendConfig {
14
+ kind: SqliteBackendKind;
15
+ /** Resolution metadata a future Postgres adapter will read. */
16
+ postgres?: {
17
+ host: string;
18
+ port: number;
19
+ database: string;
20
+ user: string;
21
+ /**
22
+ * Password / connection string are looked up at runtime from the
23
+ * caller's own secret manager; this layer never reads them through env.
24
+ */
25
+ sslMode?: 'disable' | 'require' | 'verify-full';
26
+ };
27
+ }
28
+ export declare class SqliteBackendConfigError extends Error {
29
+ constructor(message: string);
30
+ }
31
+ /**
32
+ * Reads `JINI_SQLITE_BACKEND` (`'sqlite'` default, or `'postgres'`) and, for
33
+ * `postgres`, `JINI_PG_HOST`/`JINI_PG_PORT`/`JINI_PG_DATABASE`/`JINI_PG_USER`/
34
+ * `JINI_PG_SSL_MODE` from the given env map (defaults to `process.env`).
35
+ *
36
+ * @param env - Environment map to read from. Defaults to `process.env`.
37
+ * @returns The resolved backend config.
38
+ * @throws {SqliteBackendConfigError} When `kind` is unrecognized, or `postgres`
39
+ * is selected without the required host/database/user.
40
+ */
41
+ export declare function resolveSqliteBackendConfig(env?: Record<string, string | undefined>): SqliteBackendConfig;
42
+ //# sourceMappingURL=backend-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend-config.d.ts","sourceRoot":"","sources":["../src/backend-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,UAAU,CAAC;AAEtD,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,iBAAiB,CAAC;IACxB,+DAA+D;IAC/D,QAAQ,CAAC,EAAE;QACT,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,MAAM,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;QACb;;;WAGG;QACH,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,aAAa,CAAC;KACjD,CAAC;CACH;AAED,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,mBAAmB,CA+BxG"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @module backend-config
3
+ *
4
+ * Resolves which SQL backend a host daemon should use from environment
5
+ * variables. v1 ships local SQLite via `better-sqlite3` (see `./event-log.js`);
6
+ * a `postgres` selection is recorded so a future adapter can read it, but
7
+ * `resolveSqliteBackendConfig` never opens a connection itself — it only
8
+ * pins the parameter surface (host/port/database/user/sslMode) so a
9
+ * follow-up package can land the adapter without re-litigating the env-var
10
+ * contract.
11
+ */
12
+ export class SqliteBackendConfigError extends Error {
13
+ constructor(message) {
14
+ super(message);
15
+ this.name = 'SqliteBackendConfigError';
16
+ }
17
+ }
18
+ /**
19
+ * Reads `JINI_SQLITE_BACKEND` (`'sqlite'` default, or `'postgres'`) and, for
20
+ * `postgres`, `JINI_PG_HOST`/`JINI_PG_PORT`/`JINI_PG_DATABASE`/`JINI_PG_USER`/
21
+ * `JINI_PG_SSL_MODE` from the given env map (defaults to `process.env`).
22
+ *
23
+ * @param env - Environment map to read from. Defaults to `process.env`.
24
+ * @returns The resolved backend config.
25
+ * @throws {SqliteBackendConfigError} When `kind` is unrecognized, or `postgres`
26
+ * is selected without the required host/database/user.
27
+ */
28
+ export function resolveSqliteBackendConfig(env) {
29
+ const e = env ?? process.env;
30
+ const kind = (e.JINI_SQLITE_BACKEND ?? 'sqlite').trim().toLowerCase();
31
+ if (kind === 'postgres') {
32
+ const host = e.JINI_PG_HOST ?? '';
33
+ const portStr = e.JINI_PG_PORT ?? '5432';
34
+ const database = e.JINI_PG_DATABASE ?? '';
35
+ const user = e.JINI_PG_USER ?? '';
36
+ const sslMode = e.JINI_PG_SSL_MODE === 'disable' || e.JINI_PG_SSL_MODE === 'verify-full' ? e.JINI_PG_SSL_MODE : 'require';
37
+ if (!host || !database || !user) {
38
+ throw new SqliteBackendConfigError('JINI_SQLITE_BACKEND=postgres requires JINI_PG_HOST, JINI_PG_DATABASE, JINI_PG_USER. ' +
39
+ 'JINI_PG_PORT defaults to 5432; JINI_PG_SSL_MODE defaults to "require".');
40
+ }
41
+ return {
42
+ kind: 'postgres',
43
+ postgres: {
44
+ host,
45
+ port: Number.parseInt(portStr, 10) || 5432,
46
+ database,
47
+ user,
48
+ sslMode,
49
+ },
50
+ };
51
+ }
52
+ if (kind !== 'sqlite' && kind !== '') {
53
+ throw new SqliteBackendConfigError(`unknown JINI_SQLITE_BACKEND value '${kind}'. Accepted: 'sqlite' (default), 'postgres'.`);
54
+ }
55
+ return { kind: 'sqlite' };
56
+ }
57
+ //# sourceMappingURL=backend-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backend-config.js","sourceRoot":"","sources":["../src/backend-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAoBH,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACjD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,0BAA0B,CAAC;IACzC,CAAC;CACF;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,0BAA0B,CAAC,GAAwC;IACjF,MAAM,CAAC,GAAG,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IAC7B,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC,mBAAmB,IAAI,QAAQ,CAAC,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACtE,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;QACxB,MAAM,IAAI,GAAG,CAAC,CAAC,YAAY,IAAI,EAAE,CAAC;QAClC,MAAM,OAAO,GAAG,CAAC,CAAC,YAAY,IAAI,MAAM,CAAC;QACzC,MAAM,QAAQ,GAAG,CAAC,CAAC,gBAAgB,IAAI,EAAE,CAAC;QAC1C,MAAM,IAAI,GAAG,CAAC,CAAC,YAAY,IAAI,EAAE,CAAC;QAClC,MAAM,OAAO,GACX,CAAC,CAAC,gBAAgB,KAAK,SAAS,IAAI,CAAC,CAAC,gBAAgB,KAAK,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,SAAS,CAAC;QAC5G,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAChC,MAAM,IAAI,wBAAwB,CAChC,sFAAsF;gBACpF,wEAAwE,CAC3E,CAAC;QACJ,CAAC;QACD,OAAO;YACL,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE;gBACR,IAAI;gBACJ,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,IAAI;gBAC1C,QAAQ;gBACR,IAAI;gBACJ,OAAO;aACR;SACF,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;QACrC,MAAM,IAAI,wBAAwB,CAAC,sCAAsC,IAAI,8CAA8C,CAAC,CAAC;IAC/H,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @module db/agent-sessions
3
+ * Owns the per-(conversation, agent) upstream CLI session cache used by the resume identity guard.
4
+ * Imports only the core/ kernel (types). No other db concern is imported.
5
+ *
6
+ * NOTE (neutral port): no OD-specific columns or logic — every field (session id, prompt hash,
7
+ * model, cwd, last message id) is generic resume-identity bookkeeping already matched 1:1 by the
8
+ * already-ported `schema/migrate.ts` `agent_sessions` table. Ported verbatim aside from
9
+ * de-branding the module doc comment.
10
+ */
11
+ import type { SqliteDb } from '../core/index.js';
12
+ /**
13
+ * Returns the stored upstream CLI session id for a (conversation, agent) pair, or null if none exists.
14
+ * Used as a quick existence check before the full record is needed.
15
+ * @param db - Open SQLite database handle.
16
+ * @param conversationId - Conversation scope for the session.
17
+ * @param agentId - Agent whose session to look up.
18
+ */
19
+ export declare function getAgentSession(db: SqliteDb, conversationId: string, agentId: string): string | null;
20
+ /**
21
+ * Creates or replaces the agent session record for a (conversation, agent) pair.
22
+ * All nullable fields are stored as SQL NULL when omitted, preserving the resume guard's
23
+ * ability to detect staleness via stablePromptHash and lastMessageId.
24
+ * @param db - Open SQLite database handle.
25
+ * @param input - Session fields to persist; conversationId, agentId, and sessionId are required.
26
+ */
27
+ export declare function upsertAgentSession(db: SqliteDb, input: {
28
+ conversationId: string;
29
+ agentId: string;
30
+ sessionId: string;
31
+ stablePromptHash?: string | null;
32
+ model?: string | null;
33
+ cwd?: string | null;
34
+ lastMessageId?: string | null;
35
+ }): void;
36
+ /**
37
+ * Fetches the full agent session record for a (conversation, agent) pair, or null if absent.
38
+ * Callers that need only the session id should use {@link getAgentSession} instead.
39
+ * @param db - Open SQLite database handle.
40
+ * @param conversationId - Conversation scope for the session.
41
+ * @param agentId - Agent whose session to retrieve.
42
+ */
43
+ export declare function getAgentSessionRecord(db: SqliteDb, conversationId: string, agentId: string): {
44
+ sessionId: string;
45
+ stablePromptHash: string | null;
46
+ model: string | null;
47
+ cwd: string | null;
48
+ lastMessageId: string | null;
49
+ } | null;
50
+ /**
51
+ * Returns the conversation cursor used by the resume identity guard: the id of the most recent
52
+ * completed (succeeded) assistant message, excluding the current in-flight placeholder.
53
+ * See the inline comment above for the full invariant and the resumableMessageId exception.
54
+ * @param db - Open SQLite database handle.
55
+ * @param conversationId - Conversation to inspect.
56
+ * @param excludeMessageId - The in-flight run's own placeholder message id to skip.
57
+ * @param resumableMessageId - Optional id of a transiently-failed session's last message, admitted through the succeeded-only filter.
58
+ * @returns The matching message id, or null if no prior completed turn exists.
59
+ */
60
+ export declare function latestCompletedAssistantMessageId(db: SqliteDb, conversationId: string, excludeMessageId: string, resumableMessageId?: string | null): string | null;
61
+ /**
62
+ * Updates the stable prompt hash for an existing agent session without touching other fields.
63
+ * Called after the resume path confirms the prompt context is still stable, recording the
64
+ * current hash so future identity checks can compare against it.
65
+ * @param db - Open SQLite database handle.
66
+ * @param conversationId - Conversation scope for the session.
67
+ * @param agentId - Agent whose session to update.
68
+ * @param stablePromptHash - The new prompt hash to record.
69
+ */
70
+ export declare function updateAgentSessionStableHash(db: SqliteDb, conversationId: string, agentId: string, stablePromptHash: string): void;
71
+ /**
72
+ * Deletes the agent session record for a (conversation, agent) pair.
73
+ * Forces the next run to start a fresh upstream CLI session rather than attempting resume.
74
+ * @param db - Open SQLite database handle.
75
+ * @param conversationId - Conversation scope for the session.
76
+ * @param agentId - Agent whose session to clear.
77
+ */
78
+ export declare function clearAgentSession(db: SqliteDb, conversationId: string, agentId: string): void;
79
+ //# sourceMappingURL=agent-sessions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-sessions.d.ts","sourceRoot":"","sources":["../../../src/db/agent-sessions/agent-sessions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAS,MAAM,kBAAkB,CAAC;AAExD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,EAAE,EAAE,QAAQ,EACZ,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,IAAI,CAQf;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,QAAQ,EACZ,KAAK,EAAE;IACL,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B,GACA,IAAI,CAsBN;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,QAAQ,EACZ,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,MAAM,GACd;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,GAAG,IAAI,CAgBP;AAyBD;;;;;;;;;GASG;AACH,wBAAgB,iCAAiC,CAC/C,EAAE,EAAE,QAAQ,EACZ,cAAc,EAAE,MAAM,EACtB,gBAAgB,EAAE,MAAM,EACxB,kBAAkB,GAAE,MAAM,GAAG,IAAW,GACvC,MAAM,GAAG,IAAI,CAUf;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAC1C,EAAE,EAAE,QAAQ,EACZ,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,MAAM,EACf,gBAAgB,EAAE,MAAM,GACvB,IAAI,CAKN;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,EAAE,EAAE,QAAQ,EACZ,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,MAAM,GACd,IAAI,CAIN"}
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Returns the stored upstream CLI session id for a (conversation, agent) pair, or null if none exists.
3
+ * Used as a quick existence check before the full record is needed.
4
+ * @param db - Open SQLite database handle.
5
+ * @param conversationId - Conversation scope for the session.
6
+ * @param agentId - Agent whose session to look up.
7
+ */
8
+ export function getAgentSession(db, conversationId, agentId) {
9
+ const row = db
10
+ .prepare(`SELECT session_id FROM agent_sessions
11
+ WHERE conversation_id = ? AND agent_id = ?`)
12
+ .get(conversationId, agentId);
13
+ return row && typeof row.session_id === 'string' ? row.session_id : null;
14
+ }
15
+ /**
16
+ * Creates or replaces the agent session record for a (conversation, agent) pair.
17
+ * All nullable fields are stored as SQL NULL when omitted, preserving the resume guard's
18
+ * ability to detect staleness via stablePromptHash and lastMessageId.
19
+ * @param db - Open SQLite database handle.
20
+ * @param input - Session fields to persist; conversationId, agentId, and sessionId are required.
21
+ */
22
+ export function upsertAgentSession(db, input) {
23
+ db.prepare(`INSERT INTO agent_sessions
24
+ (conversation_id, agent_id, session_id, stable_prompt_hash, model, cwd, last_message_id, updated_at)
25
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
26
+ ON CONFLICT(conversation_id, agent_id)
27
+ DO UPDATE SET session_id = excluded.session_id,
28
+ stable_prompt_hash = excluded.stable_prompt_hash,
29
+ model = excluded.model,
30
+ cwd = excluded.cwd,
31
+ last_message_id = excluded.last_message_id,
32
+ updated_at = excluded.updated_at`).run(input.conversationId, input.agentId, input.sessionId, input.stablePromptHash ?? null, input.model ?? null, input.cwd ?? null, input.lastMessageId ?? null, Date.now());
33
+ }
34
+ /**
35
+ * Fetches the full agent session record for a (conversation, agent) pair, or null if absent.
36
+ * Callers that need only the session id should use {@link getAgentSession} instead.
37
+ * @param db - Open SQLite database handle.
38
+ * @param conversationId - Conversation scope for the session.
39
+ * @param agentId - Agent whose session to retrieve.
40
+ */
41
+ export function getAgentSessionRecord(db, conversationId, agentId) {
42
+ const row = db
43
+ .prepare(`SELECT session_id, stable_prompt_hash, model, cwd, last_message_id FROM agent_sessions
44
+ WHERE conversation_id = ? AND agent_id = ?`)
45
+ .get(conversationId, agentId);
46
+ if (!row || typeof row.session_id !== 'string')
47
+ return null;
48
+ return {
49
+ sessionId: row.session_id,
50
+ stablePromptHash: typeof row.stable_prompt_hash === 'string' ? row.stable_prompt_hash : null,
51
+ model: typeof row.model === 'string' ? row.model : null,
52
+ cwd: typeof row.cwd === 'string' ? row.cwd : null,
53
+ lastMessageId: typeof row.last_message_id === 'string' ? row.last_message_id : null,
54
+ };
55
+ }
56
+ // Conversation cursor for the resume identity guard: the id of the latest
57
+ // COMPLETED assistant message in the conversation, EXCLUDING the current run's
58
+ // in-flight placeholder (`excludeMessageId`). At resolve time the session is in
59
+ // sync iff this equals the assistant message the session last produced —
60
+ // otherwise another agent completed a turn in between, or the session's own last
61
+ // message was edited/removed, and the session is behind. Returns null when there
62
+ // is no prior completed assistant turn.
63
+ //
64
+ // "Completed" means run_status = 'succeeded' — a run stamps its assistant
65
+ // message with the terminal status on finish, so an intervening agent run that
66
+ // FAILED or was CANCELED leaves a placeholder that produced no completed turn;
67
+ // counting it as advancement would force a needless cold reseed (silently
68
+ // disabling the resume perf path) even though the stored session is still the
69
+ // latest completed turn. In-flight placeholders have a null run_status and are
70
+ // likewise excluded.
71
+ //
72
+ // `resumableMessageId` is the one allowed exception: a resume-on-failure path
73
+ // may persist a session whose own last assistant turn FAILED transiently (the
74
+ // CLI session already committed a tool/artifact block and is resumable). That
75
+ // stored id is admitted through the filter so the session it owns still matches
76
+ // its cursor — while a DIFFERENT later failed/canceled turn (a different id)
77
+ // stays excluded, so genuine advancement by a later succeeded turn is still
78
+ // detected.
79
+ /**
80
+ * Returns the conversation cursor used by the resume identity guard: the id of the most recent
81
+ * completed (succeeded) assistant message, excluding the current in-flight placeholder.
82
+ * See the inline comment above for the full invariant and the resumableMessageId exception.
83
+ * @param db - Open SQLite database handle.
84
+ * @param conversationId - Conversation to inspect.
85
+ * @param excludeMessageId - The in-flight run's own placeholder message id to skip.
86
+ * @param resumableMessageId - Optional id of a transiently-failed session's last message, admitted through the succeeded-only filter.
87
+ * @returns The matching message id, or null if no prior completed turn exists.
88
+ */
89
+ export function latestCompletedAssistantMessageId(db, conversationId, excludeMessageId, resumableMessageId = null) {
90
+ const row = db
91
+ .prepare(`SELECT id FROM messages
92
+ WHERE conversation_id = ? AND role = 'assistant' AND id != ?
93
+ AND (run_status = 'succeeded' OR id = ?)
94
+ ORDER BY position DESC LIMIT 1`)
95
+ .get(conversationId, excludeMessageId, resumableMessageId);
96
+ return row && typeof row.id === 'string' ? row.id : null;
97
+ }
98
+ /**
99
+ * Updates the stable prompt hash for an existing agent session without touching other fields.
100
+ * Called after the resume path confirms the prompt context is still stable, recording the
101
+ * current hash so future identity checks can compare against it.
102
+ * @param db - Open SQLite database handle.
103
+ * @param conversationId - Conversation scope for the session.
104
+ * @param agentId - Agent whose session to update.
105
+ * @param stablePromptHash - The new prompt hash to record.
106
+ */
107
+ export function updateAgentSessionStableHash(db, conversationId, agentId, stablePromptHash) {
108
+ db.prepare(`UPDATE agent_sessions SET stable_prompt_hash = ?, updated_at = ?
109
+ WHERE conversation_id = ? AND agent_id = ?`).run(stablePromptHash, Date.now(), conversationId, agentId);
110
+ }
111
+ /**
112
+ * Deletes the agent session record for a (conversation, agent) pair.
113
+ * Forces the next run to start a fresh upstream CLI session rather than attempting resume.
114
+ * @param db - Open SQLite database handle.
115
+ * @param conversationId - Conversation scope for the session.
116
+ * @param agentId - Agent whose session to clear.
117
+ */
118
+ export function clearAgentSession(db, conversationId, agentId) {
119
+ db.prepare(`DELETE FROM agent_sessions WHERE conversation_id = ? AND agent_id = ?`).run(conversationId, agentId);
120
+ }
121
+ //# sourceMappingURL=agent-sessions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-sessions.js","sourceRoot":"","sources":["../../../src/db/agent-sessions/agent-sessions.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @module db/agent-sessions/index
3
+ * Public barrel for the agent-sessions concern: re-exports the upstream CLI session cache API.
4
+ */
5
+ export * from './agent-sessions.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/db/agent-sessions/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @module db/agent-sessions/index
3
+ * Public barrel for the agent-sessions concern: re-exports the upstream CLI session cache API.
4
+ */
5
+ export * from './agent-sessions.js';
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/db/agent-sessions/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @module db/capabilities/capabilities
3
+ *
4
+ * The SQLite-backed half of `ai-control-plane.md`'s proposed `CapabilityCatalog` (§9): durable
5
+ * storage for a host's registered capability definitions (name/description/schema/risk) plus an
6
+ * append-only execution audit trail. New, not ported — scoped to what a real caller
7
+ * (`examples/reference-web`'s chat capabilities, first) needs today rather than the full
8
+ * FTS5/tag/scope/provider schema that document sketches; add those when a caller actually needs
9
+ * search-at-scale instead of a small `SELECT *`. Imports only the `core/` kernel.
10
+ */
11
+ import type { SqliteDb } from '../core/index.js';
12
+ export interface CapabilityDefinitionRecord {
13
+ readonly id: string;
14
+ readonly description: string;
15
+ readonly inputSchema: unknown;
16
+ readonly risk: string;
17
+ readonly updatedAt: number;
18
+ }
19
+ export interface CapabilityExecutionRecord {
20
+ readonly executionId: string;
21
+ readonly capabilityId: string;
22
+ readonly input: unknown;
23
+ readonly status: string;
24
+ readonly output?: unknown;
25
+ readonly error?: string;
26
+ readonly requestedAt: number;
27
+ readonly completedAt?: number;
28
+ }
29
+ /** Inserts a capability definition, or overwrites the existing row with the same id (a host re-declaring its manifest at every startup, not a versioned upgrade). */
30
+ export declare function upsertCapabilityDefinition(db: SqliteDb, def: Omit<CapabilityDefinitionRecord, 'updatedAt'> & {
31
+ updatedAt?: number;
32
+ }): void;
33
+ /** Lists every registered capability definition, ordered by id. */
34
+ export declare function listCapabilityDefinitions(db: SqliteDb): CapabilityDefinitionRecord[];
35
+ /** Fetches one capability definition by id, or `null` if it isn't registered. */
36
+ export declare function getCapabilityDefinition(db: SqliteDb, id: string): CapabilityDefinitionRecord | null;
37
+ /** Appends one execution audit row. Insert-only — this is a durable trail, never updated in place. */
38
+ export declare function recordCapabilityExecution(db: SqliteDb, record: CapabilityExecutionRecord): void;
39
+ //# sourceMappingURL=capabilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../../src/db/capabilities/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,EAAS,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAGxD,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAYD,qKAAqK;AACrK,wBAAgB,0BAA0B,CAAC,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,CAAC,0BAA0B,EAAE,WAAW,CAAC,GAAG;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAiB1I;AAED,mEAAmE;AACnE,wBAAgB,yBAAyB,CAAC,EAAE,EAAE,QAAQ,GAAG,0BAA0B,EAAE,CAOpF;AAED,iFAAiF;AACjF,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,GAAG,0BAA0B,GAAG,IAAI,CAQnG;AAED,sGAAsG;AACtG,wBAAgB,yBAAyB,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,yBAAyB,GAAG,IAAI,CAe/F"}
@@ -0,0 +1,54 @@
1
+ import { row, rows } from '../core/index.js';
2
+ function normalizeDefinition(r) {
3
+ return {
4
+ id: r.id,
5
+ description: r.description,
6
+ inputSchema: JSON.parse(r.inputSchemaJson),
7
+ risk: r.risk,
8
+ updatedAt: Number(r.updatedAt),
9
+ };
10
+ }
11
+ /** Inserts a capability definition, or overwrites the existing row with the same id (a host re-declaring its manifest at every startup, not a versioned upgrade). */
12
+ export function upsertCapabilityDefinition(db, def) {
13
+ const updatedAt = def.updatedAt ?? Date.now();
14
+ db.prepare(`INSERT INTO capability_definitions (id, description, input_schema_json, risk, updated_at)
15
+ VALUES (@id, @description, @inputSchemaJson, @risk, @updatedAt)
16
+ ON CONFLICT(id) DO UPDATE SET
17
+ description = excluded.description,
18
+ input_schema_json = excluded.input_schema_json,
19
+ risk = excluded.risk,
20
+ updated_at = excluded.updated_at`).run({
21
+ id: def.id,
22
+ description: def.description,
23
+ inputSchemaJson: JSON.stringify(def.inputSchema),
24
+ risk: def.risk,
25
+ updatedAt,
26
+ });
27
+ }
28
+ /** Lists every registered capability definition, ordered by id. */
29
+ export function listCapabilityDefinitions(db) {
30
+ return rows(db.prepare(`SELECT id, description, input_schema_json AS inputSchemaJson, risk, updated_at AS updatedAt
31
+ FROM capability_definitions ORDER BY id`).all()).map(normalizeDefinition);
32
+ }
33
+ /** Fetches one capability definition by id, or `null` if it isn't registered. */
34
+ export function getCapabilityDefinition(db, id) {
35
+ const r = row(db.prepare(`SELECT id, description, input_schema_json AS inputSchemaJson, risk, updated_at AS updatedAt
36
+ FROM capability_definitions WHERE id = ?`).get(id));
37
+ return r ? normalizeDefinition(r) : null;
38
+ }
39
+ /** Appends one execution audit row. Insert-only — this is a durable trail, never updated in place. */
40
+ export function recordCapabilityExecution(db, record) {
41
+ db.prepare(`INSERT INTO capability_executions
42
+ (execution_id, capability_id, input_json, status, output_json, error, requested_at, completed_at)
43
+ VALUES (@executionId, @capabilityId, @inputJson, @status, @outputJson, @error, @requestedAt, @completedAt)`).run({
44
+ executionId: record.executionId,
45
+ capabilityId: record.capabilityId,
46
+ inputJson: JSON.stringify(record.input ?? null),
47
+ status: record.status,
48
+ outputJson: record.output === undefined ? null : JSON.stringify(record.output),
49
+ error: record.error ?? null,
50
+ requestedAt: record.requestedAt,
51
+ completedAt: record.completedAt ?? null,
52
+ });
53
+ }
54
+ //# sourceMappingURL=capabilities.js.map