@undefineds.co/models 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 (254) hide show
  1. package/README.md +578 -0
  2. package/dist/_drizzle-solid/columns.d.ts +37 -0
  3. package/dist/_drizzle-solid/columns.js +1 -0
  4. package/dist/_drizzle-solid/pod-table.d.ts +3 -0
  5. package/dist/_drizzle-solid/pod-table.js +1 -0
  6. package/dist/_drizzle-solid/types.d.ts +40 -0
  7. package/dist/_drizzle-solid/types.js +1 -0
  8. package/dist/agent.providers.d.ts +13 -0
  9. package/dist/agent.providers.js +69 -0
  10. package/dist/agent.repository.d.ts +85 -0
  11. package/dist/agent.repository.js +7 -0
  12. package/dist/agent.schema.d.ts +1 -0
  13. package/dist/agent.schema.js +1 -0
  14. package/dist/ai-config/index.d.ts +61 -0
  15. package/dist/ai-config/index.js +294 -0
  16. package/dist/ai-config.d.ts +1 -0
  17. package/dist/ai-config.js +1 -0
  18. package/dist/ai-model.schema.d.ts +1 -0
  19. package/dist/ai-model.schema.js +1 -0
  20. package/dist/ai-provider.schema.d.ts +1 -0
  21. package/dist/ai-provider.schema.js +1 -0
  22. package/dist/approval.schema.d.ts +1 -0
  23. package/dist/approval.schema.js +1 -0
  24. package/dist/audit.schema.d.ts +1 -0
  25. package/dist/audit.schema.js +1 -0
  26. package/dist/chat.repository.d.ts +61 -0
  27. package/dist/chat.repository.js +8 -0
  28. package/dist/chat.schema.d.ts +1 -0
  29. package/dist/chat.schema.js +1 -0
  30. package/dist/chat.utils.d.ts +3 -0
  31. package/dist/chat.utils.js +30 -0
  32. package/dist/contact.repository.d.ts +85 -0
  33. package/dist/contact.repository.js +8 -0
  34. package/dist/contact.schema.d.ts +1 -0
  35. package/dist/contact.schema.js +1 -0
  36. package/dist/core/agent-provider.schema.d.ts +1 -0
  37. package/dist/core/agent-provider.schema.js +1 -0
  38. package/dist/core/agent-status.schema.d.ts +12 -0
  39. package/dist/core/agent-status.schema.js +18 -0
  40. package/dist/core/agent.schema.d.ts +72 -0
  41. package/dist/core/agent.schema.js +38 -0
  42. package/dist/core/ai-config.schema.d.ts +11 -0
  43. package/dist/core/ai-config.schema.js +18 -0
  44. package/dist/core/ai-model.schema.d.ts +15 -0
  45. package/dist/core/ai-model.schema.js +21 -0
  46. package/dist/core/ai-provider.schema.d.ts +16 -0
  47. package/dist/core/ai-provider.schema.js +28 -0
  48. package/dist/core/approval.schema.d.ts +21 -0
  49. package/dist/core/approval.schema.js +33 -0
  50. package/dist/core/audit.schema.d.ts +17 -0
  51. package/dist/core/audit.schema.js +29 -0
  52. package/dist/core/chat.schema.d.ts +36 -0
  53. package/dist/core/chat.schema.js +45 -0
  54. package/dist/core/contact.schema.d.ts +47 -0
  55. package/dist/core/contact.schema.js +59 -0
  56. package/dist/core/credential.schema.d.ts +56 -0
  57. package/dist/core/credential.schema.js +40 -0
  58. package/dist/core/extension/extension.schema.d.ts +4 -0
  59. package/dist/core/extension/extension.schema.js +11 -0
  60. package/dist/core/extension/index.d.ts +1 -0
  61. package/dist/core/extension/index.js +1 -0
  62. package/dist/core/extension.d.ts +1 -0
  63. package/dist/core/extension.js +1 -0
  64. package/dist/core/favorite/favorite.schema.d.ts +24 -0
  65. package/dist/core/favorite/favorite.schema.js +34 -0
  66. package/dist/core/favorite/index.d.ts +1 -0
  67. package/dist/core/favorite/index.js +1 -0
  68. package/dist/core/file/file.schema.d.ts +39 -0
  69. package/dist/core/file/file.schema.js +51 -0
  70. package/dist/core/file/index.d.ts +1 -0
  71. package/dist/core/file/index.js +1 -0
  72. package/dist/core/file.d.ts +1 -0
  73. package/dist/core/file.js +1 -0
  74. package/dist/core/grant.schema.d.ts +16 -0
  75. package/dist/core/grant.schema.js +29 -0
  76. package/dist/core/import/import-job.schema.d.ts +5 -0
  77. package/dist/core/import/import-job.schema.js +5 -0
  78. package/dist/core/import/index.d.ts +1 -0
  79. package/dist/core/import/index.js +1 -0
  80. package/dist/core/import.d.ts +1 -0
  81. package/dist/core/import.js +1 -0
  82. package/dist/core/inbox-notification.schema.d.ts +9 -0
  83. package/dist/core/inbox-notification.schema.js +16 -0
  84. package/dist/core/index.d.ts +31 -0
  85. package/dist/core/index.js +32 -0
  86. package/dist/core/knowledge/index.d.ts +1 -0
  87. package/dist/core/knowledge/index.js +1 -0
  88. package/dist/core/knowledge/knowledge-folder.schema.d.ts +7 -0
  89. package/dist/core/knowledge/knowledge-folder.schema.js +6 -0
  90. package/dist/core/knowledge.d.ts +1 -0
  91. package/dist/core/knowledge.js +1 -0
  92. package/dist/core/message.schema.d.ts +33 -0
  93. package/dist/core/message.schema.js +49 -0
  94. package/dist/core/namespaces.d.ts +176 -0
  95. package/dist/core/namespaces.js +289 -0
  96. package/dist/core/profile.d.ts +16 -0
  97. package/dist/core/profile.js +19 -0
  98. package/dist/core/schema.d.ts +304 -0
  99. package/dist/core/schema.js +46 -0
  100. package/dist/core/session/index.d.ts +1 -0
  101. package/dist/core/session/index.js +1 -0
  102. package/dist/core/session/session.schema.d.ts +6 -0
  103. package/dist/core/session/session.schema.js +6 -0
  104. package/dist/core/session.d.ts +1 -0
  105. package/dist/core/session.js +1 -0
  106. package/dist/core/settings/index.d.ts +1 -0
  107. package/dist/core/settings/index.js +1 -0
  108. package/dist/core/settings/settings.schema.d.ts +49 -0
  109. package/dist/core/settings/settings.schema.js +63 -0
  110. package/dist/core/settings.d.ts +1 -0
  111. package/dist/core/settings.js +1 -0
  112. package/dist/core/thread.schema.d.ts +28 -0
  113. package/dist/core/thread.schema.js +36 -0
  114. package/dist/core/types/collaboration-blocks.d.ts +52 -0
  115. package/dist/core/types/collaboration-blocks.js +7 -0
  116. package/dist/core/types/message-block.d.ts +270 -0
  117. package/dist/core/types/message-block.js +125 -0
  118. package/dist/core/vector-store.schema.d.ts +25 -0
  119. package/dist/core/vector-store.schema.js +35 -0
  120. package/dist/core/vocab/_namespaces.d.ts +1 -0
  121. package/dist/core/vocab/_namespaces.js +3 -0
  122. package/dist/core/vocab/chat.vocab.d.ts +16 -0
  123. package/dist/core/vocab/chat.vocab.js +22 -0
  124. package/dist/core/vocab/contact.vocab.d.ts +21 -0
  125. package/dist/core/vocab/contact.vocab.js +22 -0
  126. package/dist/core/vocab/index.d.ts +6 -0
  127. package/dist/core/vocab/index.js +6 -0
  128. package/dist/core/vocab/message.vocab.d.ts +20 -0
  129. package/dist/core/vocab/message.vocab.js +24 -0
  130. package/dist/core/vocab/sidecar.vocab.d.ts +46 -0
  131. package/dist/core/vocab/sidecar.vocab.js +47 -0
  132. package/dist/core/vocab/thread.vocab.d.ts +11 -0
  133. package/dist/core/vocab/thread.vocab.js +14 -0
  134. package/dist/core/vocab/workspace.vocab.d.ts +12 -0
  135. package/dist/core/vocab/workspace.vocab.js +13 -0
  136. package/dist/core/vocab.d.ts +1 -0
  137. package/dist/core/vocab.js +1 -0
  138. package/dist/core/workspace.schema.d.ts +35 -0
  139. package/dist/core/workspace.schema.js +106 -0
  140. package/dist/core.d.ts +1 -0
  141. package/dist/core.js +1 -0
  142. package/dist/credential.schema.d.ts +1 -0
  143. package/dist/credential.schema.js +1 -0
  144. package/dist/discovery/index.d.ts +31 -0
  145. package/dist/discovery/index.js +147 -0
  146. package/dist/discovery/models.json +2623 -0
  147. package/dist/discovery/providers.json +156 -0
  148. package/dist/discovery/types.d.ts +103 -0
  149. package/dist/discovery/types.js +12 -0
  150. package/dist/discovery/vercel.d.ts +25 -0
  151. package/dist/discovery/vercel.js +95 -0
  152. package/dist/discovery.d.ts +1 -0
  153. package/dist/discovery.js +1 -0
  154. package/dist/extension/extension.schema.d.ts +1 -0
  155. package/dist/extension/extension.schema.js +1 -0
  156. package/dist/extension/index.d.ts +1 -0
  157. package/dist/extension/index.js +1 -0
  158. package/dist/extension.d.ts +1 -0
  159. package/dist/extension.js +1 -0
  160. package/dist/favorite/favorite.schema.d.ts +1 -0
  161. package/dist/favorite/favorite.schema.js +1 -0
  162. package/dist/favorite/index.d.ts +2 -0
  163. package/dist/favorite/index.js +7 -0
  164. package/dist/favorite/starred-sync.d.ts +66 -0
  165. package/dist/favorite/starred-sync.js +156 -0
  166. package/dist/favorite.d.ts +1 -0
  167. package/dist/favorite.js +1 -0
  168. package/dist/file/file.schema.d.ts +1 -0
  169. package/dist/file/file.schema.js +1 -0
  170. package/dist/file/index.d.ts +1 -0
  171. package/dist/file/index.js +1 -0
  172. package/dist/file.d.ts +1 -0
  173. package/dist/file.js +1 -0
  174. package/dist/fixtures/contracts-chat-contact.d.ts +13 -0
  175. package/dist/fixtures/contracts-chat-contact.js +76 -0
  176. package/dist/grant.schema.d.ts +1 -0
  177. package/dist/grant.schema.js +1 -0
  178. package/dist/import/import-job.schema.d.ts +5 -0
  179. package/dist/import/import-job.schema.js +5 -0
  180. package/dist/import/index.d.ts +1 -0
  181. package/dist/import/index.js +1 -0
  182. package/dist/import.d.ts +1 -0
  183. package/dist/import.js +1 -0
  184. package/dist/inbox-notification.schema.d.ts +1 -0
  185. package/dist/inbox-notification.schema.js +1 -0
  186. package/dist/index.d.ts +41 -0
  187. package/dist/index.js +83 -0
  188. package/dist/knowledge/index.d.ts +1 -0
  189. package/dist/knowledge/index.js +1 -0
  190. package/dist/knowledge/knowledge-folder.schema.d.ts +1 -0
  191. package/dist/knowledge/knowledge-folder.schema.js +1 -0
  192. package/dist/knowledge.d.ts +1 -0
  193. package/dist/knowledge.js +1 -0
  194. package/dist/message.repository.d.ts +81 -0
  195. package/dist/message.repository.js +8 -0
  196. package/dist/message.schema.d.ts +1 -0
  197. package/dist/message.schema.js +1 -0
  198. package/dist/namespaces.d.ts +1 -0
  199. package/dist/namespaces.js +1 -0
  200. package/dist/profile.d.ts +1 -0
  201. package/dist/profile.js +1 -0
  202. package/dist/repository.d.ts +59 -0
  203. package/dist/repository.js +186 -0
  204. package/dist/schema.d.ts +1 -0
  205. package/dist/schema.js +1 -0
  206. package/dist/session/index.d.ts +1 -0
  207. package/dist/session/index.js +1 -0
  208. package/dist/session/session.schema.d.ts +1 -0
  209. package/dist/session/session.schema.js +1 -0
  210. package/dist/session.d.ts +1 -0
  211. package/dist/session.js +1 -0
  212. package/dist/settings/index.d.ts +1 -0
  213. package/dist/settings/index.js +1 -0
  214. package/dist/settings/settings.schema.d.ts +1 -0
  215. package/dist/settings/settings.schema.js +1 -0
  216. package/dist/settings.d.ts +1 -0
  217. package/dist/settings.js +1 -0
  218. package/dist/sidecar/index.d.ts +2 -0
  219. package/dist/sidecar/index.js +2 -0
  220. package/dist/sidecar/persistence-mapping.d.ts +51 -0
  221. package/dist/sidecar/persistence-mapping.js +44 -0
  222. package/dist/sidecar/sidecar-events.d.ts +632 -0
  223. package/dist/sidecar/sidecar-events.js +133 -0
  224. package/dist/thread.repository.d.ts +41 -0
  225. package/dist/thread.repository.js +8 -0
  226. package/dist/thread.schema.d.ts +1 -0
  227. package/dist/thread.schema.js +1 -0
  228. package/dist/types/collaboration-blocks.d.ts +52 -0
  229. package/dist/types/collaboration-blocks.js +7 -0
  230. package/dist/types/message-block.d.ts +270 -0
  231. package/dist/types/message-block.js +125 -0
  232. package/dist/vocab/_namespaces.d.ts +1 -0
  233. package/dist/vocab/_namespaces.js +3 -0
  234. package/dist/vocab/chat.vocab.d.ts +16 -0
  235. package/dist/vocab/chat.vocab.js +22 -0
  236. package/dist/vocab/contact.vocab.d.ts +21 -0
  237. package/dist/vocab/contact.vocab.js +22 -0
  238. package/dist/vocab/index.d.ts +6 -0
  239. package/dist/vocab/index.js +6 -0
  240. package/dist/vocab/message.vocab.d.ts +20 -0
  241. package/dist/vocab/message.vocab.js +24 -0
  242. package/dist/vocab/sidecar.vocab.d.ts +46 -0
  243. package/dist/vocab/sidecar.vocab.js +47 -0
  244. package/dist/vocab/thread.vocab.d.ts +11 -0
  245. package/dist/vocab/thread.vocab.js +14 -0
  246. package/dist/vocab/workspace.vocab.d.ts +12 -0
  247. package/dist/vocab/workspace.vocab.js +13 -0
  248. package/dist/vocab.d.ts +1 -0
  249. package/dist/vocab.js +1 -0
  250. package/dist/workspace.repository.d.ts +45 -0
  251. package/dist/workspace.repository.js +8 -0
  252. package/dist/workspace.schema.d.ts +1 -0
  253. package/dist/workspace.schema.js +1 -0
  254. package/package.json +68 -0
@@ -0,0 +1,186 @@
1
+ import { and, like, or } from '@undefineds.co/drizzle-solid';
2
+ export function resolveRowId(row) {
3
+ if (!row)
4
+ return null;
5
+ // Try @id first (standard RDF format)
6
+ const subject = row['@id'] ?? row.subject;
7
+ if (typeof subject === 'string' && subject.length > 0)
8
+ return subject;
9
+ // Try id field
10
+ const id = row.id;
11
+ if (typeof id === 'string' && id.length > 0)
12
+ return id;
13
+ // Handle drizzle-solid insert result format: {success: true, source: 'http://...'}
14
+ const source = row.source;
15
+ if (typeof source === 'string' && source.length > 0)
16
+ return source;
17
+ return null;
18
+ }
19
+ export function isIriLikeIdentifier(value) {
20
+ return /^(?:[a-z][a-z0-9+.-]*:|\/)/i.test(value) || value.startsWith('#');
21
+ }
22
+ export function stripEntityIdentifiers(data) {
23
+ if (!data)
24
+ return {};
25
+ const next = {};
26
+ for (const [key, value] of Object.entries(data)) {
27
+ if (key === 'id' || key === '@id' || key === 'subject' || key === 'source')
28
+ continue;
29
+ next[key] = value;
30
+ }
31
+ return next;
32
+ }
33
+ function resolveExactTarget(input) {
34
+ if (typeof input === 'string') {
35
+ return isIriLikeIdentifier(input) ? { iri: input } : { locator: { id: input } };
36
+ }
37
+ const iri = input['@id'] ?? input.subject;
38
+ if (typeof iri === 'string' && iri.length > 0) {
39
+ return { iri };
40
+ }
41
+ return { locator: input };
42
+ }
43
+ export async function findExactRecord(db, table, target) {
44
+ const exact = resolveExactTarget(target);
45
+ return 'iri' in exact
46
+ ? await db.findByIri(table, exact.iri)
47
+ : await db.findByLocator(table, exact.locator);
48
+ }
49
+ export async function updateExactRecord(db, table, target, data) {
50
+ const exact = resolveExactTarget(target);
51
+ const payload = stripEntityIdentifiers(data);
52
+ return 'iri' in exact
53
+ ? await db.updateByIri(table, exact.iri, payload)
54
+ : await db.updateByLocator(table, exact.locator, payload);
55
+ }
56
+ export async function deleteExactRecord(db, table, target) {
57
+ const exact = resolveExactTarget(target);
58
+ return 'iri' in exact
59
+ ? await db.deleteByIri(table, exact.iri)
60
+ : await db.deleteByLocator(table, exact.locator);
61
+ }
62
+ export function createRepositoryDescriptor(options) {
63
+ const { namespace, table, searchableFields, defaultSort, cache, } = options;
64
+ const searchAccessor = options.searchAccessor ?? ((filters) => {
65
+ const value = filters ? filters.search : undefined;
66
+ return typeof value === 'string' ? value : undefined;
67
+ });
68
+ const transformRow = options.transform ?? ((row) => row);
69
+ const invalidations = {
70
+ create: options.invalidations?.create ?? ['list'],
71
+ update: options.invalidations?.update ?? ['list', 'detail'],
72
+ remove: options.invalidations?.remove ?? ['list', 'detail'],
73
+ };
74
+ const resolveColumn = (field) => {
75
+ const column = table[field];
76
+ if (column)
77
+ return column;
78
+ const tableName = table.config?.name;
79
+ return tableName ? `${tableName}.${field}` : field;
80
+ };
81
+ const buildWhereClause = (filters) => {
82
+ const clauses = [];
83
+ const term = searchAccessor(filters)?.trim();
84
+ if (term && searchableFields?.length) {
85
+ const pattern = `%${term}%`;
86
+ const searchClauses = searchableFields
87
+ .map((field) => like(resolveColumn(field), pattern));
88
+ if (searchClauses.length === 1) {
89
+ clauses.push(searchClauses[0]);
90
+ }
91
+ else if (searchClauses.length > 1) {
92
+ clauses.push(or(...searchClauses));
93
+ }
94
+ }
95
+ const customFilter = options.filter?.({ table, filters });
96
+ if (customFilter) {
97
+ clauses.push(customFilter);
98
+ }
99
+ if (clauses.length === 0)
100
+ return undefined;
101
+ return clauses.length === 1 ? clauses[0] : and(...clauses);
102
+ };
103
+ const list = async (db, filters) => {
104
+ let query = db.select().from(table);
105
+ const whereClause = buildWhereClause(filters);
106
+ if (whereClause) {
107
+ query = query.where(whereClause);
108
+ }
109
+ if (defaultSort) {
110
+ query = query.orderBy(resolveColumn(defaultSort.field), defaultSort.direction);
111
+ }
112
+ const rows = await query.execute();
113
+ return rows.map((row) => transformRow(row));
114
+ };
115
+ const detail = async (db, id) => {
116
+ const record = await findExactRecord(db, table, id);
117
+ return record ? transformRow(record) : null;
118
+ };
119
+ const create = options.disableMutations?.create
120
+ ? undefined
121
+ : async (db, input) => {
122
+ // Generate an ID if not provided
123
+ const inputId = input.id;
124
+ const generatedId = typeof inputId === 'string' && inputId.length > 0
125
+ ? inputId
126
+ : crypto.randomUUID();
127
+ const inputWithId = { ...input, id: generatedId };
128
+ const result = await db.insert(table).values(inputWithId).execute();
129
+ // drizzle-solid returns [{success, source}] or the created row
130
+ const firstResult = Array.isArray(result) ? result?.[0] : result;
131
+ // If result is actual row data (not drizzle-solid success format), return it
132
+ if (firstResult && typeof firstResult === 'object' && !('success' in firstResult)) {
133
+ return transformRow(firstResult);
134
+ }
135
+ // Handle drizzle-solid format: {success: true, source: "http://..."}
136
+ const sourceUrl = firstResult && typeof firstResult === 'object' && 'source' in firstResult
137
+ ? firstResult.source
138
+ : null;
139
+ // Return synthetic row immediately for optimistic update
140
+ // The real data will be fetched via invalidateQueries
141
+ const baseUrl = sourceUrl ? sourceUrl.replace(/\/[^/]+\.ttl$/, '') : '';
142
+ const syntheticId = sourceUrl
143
+ ? `${baseUrl}/${generatedId}.ttl`
144
+ : generatedId;
145
+ return {
146
+ ...inputWithId,
147
+ id: generatedId,
148
+ '@id': syntheticId,
149
+ subject: syntheticId,
150
+ source: sourceUrl,
151
+ };
152
+ };
153
+ const update = options.disableMutations?.update
154
+ ? undefined
155
+ : async (db, id, input) => {
156
+ await updateExactRecord(db, table, id, input);
157
+ const next = await detail(db, id);
158
+ if (!next) {
159
+ throw new Error(`Failed to load ${namespace} record after update`);
160
+ }
161
+ return next;
162
+ };
163
+ const remove = options.disableMutations?.remove
164
+ ? undefined
165
+ : async (db, id) => {
166
+ await deleteExactRecord(db, table, id);
167
+ return { id };
168
+ };
169
+ const resourcePath = typeof table.getResourcePath === 'function'
170
+ ? table.getResourcePath()
171
+ : (table.config?.base ?? '');
172
+ return {
173
+ namespace,
174
+ resourcePath,
175
+ searchableFields,
176
+ defaultSort,
177
+ cache,
178
+ invalidations,
179
+ list,
180
+ detail,
181
+ create,
182
+ update,
183
+ remove,
184
+ };
185
+ }
186
+ export const definePodRepository = createRepositoryDescriptor;
@@ -0,0 +1 @@
1
+ export { linxSchema } from './core.js';
package/dist/schema.js ADDED
@@ -0,0 +1 @@
1
+ export { linxSchema } from './core.js';
@@ -0,0 +1 @@
1
+ export { sessionSchema } from "./session.schema.js";
@@ -0,0 +1 @@
1
+ export { sessionSchema } from "./session.schema.js";
@@ -0,0 +1 @@
1
+ export { sessionSchema } from '../core.js';
@@ -0,0 +1 @@
1
+ export { sessionSchema } from '../core.js';
@@ -0,0 +1 @@
1
+ export * from './session/index.js';
@@ -0,0 +1 @@
1
+ export * from './session/index.js';
@@ -0,0 +1 @@
1
+ export { settingsTable, SETTING_KEYS, type SettingKey, type SettingsRow, type SettingsInsert, type SettingsUpdate } from "./settings.schema.js";
@@ -0,0 +1 @@
1
+ export { settingsTable, SETTING_KEYS } from "./settings.schema.js";
@@ -0,0 +1 @@
1
+ export { settingsTable, SETTING_KEYS, type SettingKey, type SettingsRow, type SettingsInsert, type SettingsUpdate, } from '../core.js';
@@ -0,0 +1 @@
1
+ export { settingsTable, SETTING_KEYS, } from '../core.js';
@@ -0,0 +1 @@
1
+ export * from './settings/index.js';
@@ -0,0 +1 @@
1
+ export * from './settings/index.js';
@@ -0,0 +1,2 @@
1
+ export * from './sidecar-events.js';
2
+ export * from './persistence-mapping.js';
@@ -0,0 +1,2 @@
1
+ export * from './sidecar-events.js';
2
+ export * from './persistence-mapping.js';
@@ -0,0 +1,51 @@
1
+ import type { ApprovalInsert, ApprovalUpdate } from '../approval.schema.js';
2
+ import type { AuditInsert } from '../audit.schema.js';
3
+ import type { GrantInsert } from '../grant.schema.js';
4
+ import type { InboxNotificationInsert } from '../inbox-notification.schema.js';
5
+ import type { ToolCallEvent, InboxApprovalEvent, SessionStateEvent } from './sidecar-events.js';
6
+ export type ChatSessionProjection = {
7
+ chatId: string;
8
+ sessionStatus: 'active' | 'paused' | 'completed' | 'error';
9
+ policy?: string;
10
+ policyVersion?: string;
11
+ };
12
+ export type ApprovalProjectionInsert = Pick<ApprovalInsert, 'session' | 'toolCallId' | 'toolName' | 'target' | 'action' | 'risk' | 'status' | 'policyVersion'>;
13
+ export type ApprovalProjectionUpdate = Partial<Pick<ApprovalUpdate, 'status' | 'assignedTo' | 'decisionBy' | 'decisionRole' | 'onBehalfOf' | 'reason' | 'policyVersion' | 'resolvedAt'>>;
14
+ export type AuditProjectionInsert = Pick<AuditInsert, 'action' | 'actor' | 'actorRole' | 'onBehalfOf' | 'session' | 'toolCallId' | 'approval' | 'context' | 'policy' | 'policyVersion'>;
15
+ export type GrantProjectionInsert = Pick<GrantInsert, 'target' | 'action' | 'effect' | 'riskCeiling' | 'decisionBy' | 'decisionRole' | 'onBehalfOf'>;
16
+ export type InboxNotificationProjectionInsert = Pick<InboxNotificationInsert, 'actor' | 'object'>;
17
+ export declare const SidecarEventToPodMapping: {
18
+ readonly tool_call_waiting_approval: {
19
+ readonly approval: "insert";
20
+ readonly inboxNotification: "insert";
21
+ readonly audit: null;
22
+ readonly grant: null;
23
+ };
24
+ readonly tool_call_approved_or_rejected: {
25
+ readonly approval: "update";
26
+ readonly inboxNotification: "insert";
27
+ readonly audit: "insert";
28
+ readonly grant: null;
29
+ };
30
+ readonly inbox_approval_resolved: {
31
+ readonly approval: "update";
32
+ readonly inboxNotification: "insert";
33
+ readonly audit: null;
34
+ readonly grant: null;
35
+ };
36
+ readonly session_state_terminal: {
37
+ readonly chat: "update";
38
+ };
39
+ };
40
+ export declare function hasPodScope(scope: {
41
+ target?: string;
42
+ action?: string;
43
+ }): scope is {
44
+ target: string;
45
+ action: string;
46
+ };
47
+ export type SidecarPersistenceRuleKey = keyof typeof SidecarEventToPodMapping;
48
+ export declare function isToolWaitingApproval(event: ToolCallEvent): boolean;
49
+ export declare function isToolDecisionEvent(event: ToolCallEvent): boolean;
50
+ export declare function isInboxResolved(event: InboxApprovalEvent): boolean;
51
+ export declare function isSessionTerminal(event: SessionStateEvent): boolean;
@@ -0,0 +1,44 @@
1
+ export const SidecarEventToPodMapping = {
2
+ // tool.call
3
+ tool_call_waiting_approval: {
4
+ approval: 'insert',
5
+ inboxNotification: 'insert',
6
+ audit: null,
7
+ grant: null,
8
+ },
9
+ tool_call_approved_or_rejected: {
10
+ approval: 'update',
11
+ inboxNotification: 'insert',
12
+ audit: 'insert',
13
+ grant: null,
14
+ },
15
+ // inbox.approval
16
+ inbox_approval_resolved: {
17
+ approval: 'update',
18
+ inboxNotification: 'insert',
19
+ audit: null,
20
+ grant: null,
21
+ },
22
+ // session.state
23
+ session_state_terminal: {
24
+ chat: 'update',
25
+ },
26
+ };
27
+ // Projection helpers (pure, no DB calls)
28
+ // NOTE: CP0 scope is Pod-only. Only project events that provide a concrete ODRL target/action.
29
+ export function hasPodScope(scope) {
30
+ return typeof scope.target === 'string' && scope.target.length > 0 && typeof scope.action === 'string' && scope.action.length > 0;
31
+ }
32
+ // Optional helpers for downstream implementers (pure, no DB calls)
33
+ export function isToolWaitingApproval(event) {
34
+ return event.type === 'tool.call' && event.status === 'waiting_approval';
35
+ }
36
+ export function isToolDecisionEvent(event) {
37
+ return event.type === 'tool.call' && (event.status === 'approved' || event.status === 'rejected');
38
+ }
39
+ export function isInboxResolved(event) {
40
+ return event.type === 'inbox.approval' && event.status !== 'pending';
41
+ }
42
+ export function isSessionTerminal(event) {
43
+ return event.type === 'session.state' && (event.status === 'completed' || event.status === 'error');
44
+ }