@stacklink/sdk 0.2.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 (60) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +50 -0
  3. package/compatibility.json +30 -0
  4. package/dist/src/domain/knowledge-meta-tools.d.ts +12 -0
  5. package/dist/src/domain/knowledge-meta-tools.d.ts.map +1 -0
  6. package/dist/src/domain/knowledge-meta-tools.js +38 -0
  7. package/dist/src/domain/knowledge-meta-tools.js.map +1 -0
  8. package/dist/src/domain/memory-contract.d.ts +3399 -0
  9. package/dist/src/domain/memory-contract.d.ts.map +1 -0
  10. package/dist/src/domain/memory-contract.js +931 -0
  11. package/dist/src/domain/memory-contract.js.map +1 -0
  12. package/dist/src/domain/memory-meta-tools.d.ts +5 -0
  13. package/dist/src/domain/memory-meta-tools.d.ts.map +1 -0
  14. package/dist/src/domain/memory-meta-tools.js +18 -0
  15. package/dist/src/domain/memory-meta-tools.js.map +1 -0
  16. package/dist/src/domain/platform-mcp-tools.d.ts +3 -0
  17. package/dist/src/domain/platform-mcp-tools.d.ts.map +1 -0
  18. package/dist/src/domain/platform-mcp-tools.js +30 -0
  19. package/dist/src/domain/platform-mcp-tools.js.map +1 -0
  20. package/dist/src/domain/provider-branding.d.ts +27 -0
  21. package/dist/src/domain/provider-branding.d.ts.map +1 -0
  22. package/dist/src/domain/provider-branding.js +256 -0
  23. package/dist/src/domain/provider-branding.js.map +1 -0
  24. package/dist/src/domain/stacklink-meta-tools.d.ts +80 -0
  25. package/dist/src/domain/stacklink-meta-tools.d.ts.map +1 -0
  26. package/dist/src/domain/stacklink-meta-tools.js +456 -0
  27. package/dist/src/domain/stacklink-meta-tools.js.map +1 -0
  28. package/dist/src/sdk/claude-agent.d.ts +14 -0
  29. package/dist/src/sdk/claude-agent.d.ts.map +1 -0
  30. package/dist/src/sdk/claude-agent.js +15 -0
  31. package/dist/src/sdk/claude-agent.js.map +1 -0
  32. package/dist/src/sdk/framework-tools.d.ts +19 -0
  33. package/dist/src/sdk/framework-tools.d.ts.map +1 -0
  34. package/dist/src/sdk/framework-tools.js +26 -0
  35. package/dist/src/sdk/framework-tools.js.map +1 -0
  36. package/dist/src/sdk/index.d.ts +3443 -0
  37. package/dist/src/sdk/index.d.ts.map +1 -0
  38. package/dist/src/sdk/index.js +2782 -0
  39. package/dist/src/sdk/index.js.map +1 -0
  40. package/dist/src/sdk/langchain.d.ts +9 -0
  41. package/dist/src/sdk/langchain.d.ts.map +1 -0
  42. package/dist/src/sdk/langchain.js +11 -0
  43. package/dist/src/sdk/langchain.js.map +1 -0
  44. package/dist/src/sdk/memory-lifecycle.d.ts +75 -0
  45. package/dist/src/sdk/memory-lifecycle.d.ts.map +1 -0
  46. package/dist/src/sdk/memory-lifecycle.js +128 -0
  47. package/dist/src/sdk/memory-lifecycle.js.map +1 -0
  48. package/dist/src/sdk/openai-agents.d.ts +45 -0
  49. package/dist/src/sdk/openai-agents.d.ts.map +1 -0
  50. package/dist/src/sdk/openai-agents.js +182 -0
  51. package/dist/src/sdk/openai-agents.js.map +1 -0
  52. package/dist/src/sdk/openai.d.ts +12 -0
  53. package/dist/src/sdk/openai.d.ts.map +1 -0
  54. package/dist/src/sdk/openai.js +271 -0
  55. package/dist/src/sdk/openai.js.map +1 -0
  56. package/dist/src/sdk/vercel-ai.d.ts +11 -0
  57. package/dist/src/sdk/vercel-ai.d.ts.map +1 -0
  58. package/dist/src/sdk/vercel-ai.js +226 -0
  59. package/dist/src/sdk/vercel-ai.js.map +1 -0
  60. package/package.json +81 -0
@@ -0,0 +1,931 @@
1
+ import { z } from 'zod';
2
+ export const memorySubjectTypes = [
3
+ 'user',
4
+ 'agent',
5
+ 'tenant',
6
+ 'run',
7
+ 'application',
8
+ 'custom',
9
+ ];
10
+ export const memoryRecordKinds = [
11
+ 'fact',
12
+ 'episode',
13
+ 'profile_item',
14
+ 'block',
15
+ ];
16
+ export const memoryAutomaticRecordKinds = [
17
+ 'fact',
18
+ 'episode',
19
+ ];
20
+ export const memoryTypes = [
21
+ 'preference',
22
+ 'decision',
23
+ 'commitment',
24
+ 'goal',
25
+ 'constraint',
26
+ 'relationship',
27
+ 'durable_fact',
28
+ ];
29
+ export const memorySensitivityClasses = [
30
+ 'standard',
31
+ 'personal',
32
+ 'restricted',
33
+ 'secret',
34
+ ];
35
+ export const memoryRestrictedDataClasses = [
36
+ 'health',
37
+ 'biometric',
38
+ 'government_identity',
39
+ 'precise_location',
40
+ 'protected_trait',
41
+ 'minor',
42
+ 'detailed_personal_financial',
43
+ ];
44
+ export const memoryRecordStates = [
45
+ 'current',
46
+ 'conflicted',
47
+ 'forgotten',
48
+ ];
49
+ export const memoryRecallableRecordStates = [
50
+ 'current',
51
+ 'conflicted',
52
+ ];
53
+ export const memoryRelationTypes = [
54
+ 'derived_from',
55
+ 'supersedes',
56
+ 'contradicts',
57
+ 'supports',
58
+ 'related_to',
59
+ ];
60
+ export const memorySourceKinds = [
61
+ 'direct',
62
+ 'conversation',
63
+ 'document',
64
+ 'provider',
65
+ 'tool_execution',
66
+ 'artifact',
67
+ ];
68
+ export const memorySubjectRefSchema = z.object({
69
+ type: z.enum(memorySubjectTypes),
70
+ externalId: z.string().trim().min(1).max(220),
71
+ }).strict();
72
+ export const memoryConsentProofSchema = z.object({
73
+ status: z.literal('granted'),
74
+ basis: z.enum(['user_consent', 'contract', 'legitimate_interest', 'project_policy']),
75
+ recordedAt: z.string().datetime(),
76
+ reference: z.string().trim().min(1).max(500).optional(),
77
+ }).strict();
78
+ export const memoryConsentPolicySchema = z.object({
79
+ mode: z.enum(['project_policy', 'required']).default('project_policy'),
80
+ }).passthrough();
81
+ export const memoryTenantSelectorSchema = z.object({
82
+ tenantId: z.string().uuid().optional(),
83
+ externalTenantId: z.string().trim().min(1).max(160).optional(),
84
+ sessionId: z.string().uuid().optional(),
85
+ }).superRefine((value, ctx) => {
86
+ const supplied = [value.tenantId, value.externalTenantId, value.sessionId].filter(Boolean);
87
+ if (supplied.length !== 1) {
88
+ ctx.addIssue({
89
+ code: z.ZodIssueCode.custom,
90
+ message: 'Provide exactly one of tenantId, externalTenantId, or sessionId.',
91
+ });
92
+ }
93
+ });
94
+ const memoryTemporalFieldsShape = {
95
+ occurredAt: z.string().datetime().optional(),
96
+ validFrom: z.string().datetime().optional(),
97
+ validTo: z.string().datetime().optional(),
98
+ };
99
+ export const memoryIngestInputSchema = z.object({
100
+ tenantId: z.string().uuid().optional(),
101
+ externalTenantId: z.string().trim().min(1).max(160).optional(),
102
+ sessionId: z.string().uuid().optional(),
103
+ subjects: z.array(memorySubjectRefSchema).min(1).max(20).optional(),
104
+ mode: z.enum(['exact', 'extract']).default('exact'),
105
+ kind: z.enum(memoryRecordKinds).default('fact'),
106
+ content: z.string().trim().min(1).max(10_000_000),
107
+ title: z.string().trim().min(1).max(260).optional(),
108
+ memoryType: z.enum(memoryTypes).default('durable_fact'),
109
+ sensitivityClass: z.enum(memorySensitivityClasses).default('standard'),
110
+ restrictedDataClasses: z.array(z.enum(memoryRestrictedDataClasses)).max(memoryRestrictedDataClasses.length).default([]),
111
+ topicTags: z.array(z.string().trim().min(1).max(120)).max(50).default([]),
112
+ language: z.string().trim().min(1).max(80).optional(),
113
+ source: z.object({
114
+ kind: z.enum(memorySourceKinds).default('direct'),
115
+ externalId: z.string().trim().min(1).max(320).optional(),
116
+ providerKey: z.string().trim().min(1).max(120).optional(),
117
+ connectedAccountId: z.string().uuid().optional(),
118
+ resourceType: z.string().trim().min(1).max(120).optional(),
119
+ resourceId: z.string().trim().min(1).max(320).optional(),
120
+ toolExecutionId: z.string().uuid().optional(),
121
+ applicationKey: z.string().trim().min(1).max(160).optional(),
122
+ }).strict().default({ kind: 'direct' }),
123
+ idempotencyKey: z.string().trim().min(1).max(240).optional(),
124
+ policyKey: z.string().trim().min(1).max(120).optional(),
125
+ consent: memoryConsentProofSchema.optional(),
126
+ metadata: z.record(z.unknown()).default({}),
127
+ ...memoryTemporalFieldsShape,
128
+ }).superRefine((value, ctx) => {
129
+ const selectors = [value.tenantId, value.externalTenantId, value.sessionId].filter(Boolean);
130
+ if (selectors.length !== 1) {
131
+ ctx.addIssue({
132
+ code: z.ZodIssueCode.custom,
133
+ message: 'Provide exactly one of tenantId, externalTenantId, or sessionId.',
134
+ });
135
+ }
136
+ if (!value.sessionId && (!value.subjects || value.subjects.length === 0)) {
137
+ ctx.addIssue({
138
+ code: z.ZodIssueCode.custom,
139
+ path: ['subjects'],
140
+ message: 'subjects are required when sessionId is not supplied.',
141
+ });
142
+ }
143
+ validateMemorySensitivity(value, ctx);
144
+ validateTemporalInterval(value, ctx);
145
+ });
146
+ const memoryRichInputSchema = z.discriminatedUnion('type', [
147
+ z.object({
148
+ type: z.literal('file'),
149
+ filename: z.string().trim().min(1).max(260),
150
+ mediaType: z.string().trim().min(1).max(160),
151
+ dataBase64: z.string().min(1).max(35_000_000),
152
+ }).strict(),
153
+ z.object({
154
+ type: z.literal('url'),
155
+ url: z.string().url().max(4_000),
156
+ }).strict(),
157
+ ]);
158
+ export const memoryRichIngestInputSchema = z.object({
159
+ tenantId: z.string().uuid().optional(),
160
+ externalTenantId: z.string().trim().min(1).max(160).optional(),
161
+ sessionId: z.string().uuid().optional(),
162
+ subjects: z.array(memorySubjectRefSchema).min(1).max(20).optional(),
163
+ mode: z.enum(['exact', 'extract']).default('extract'),
164
+ kind: z.enum(memoryRecordKinds).default('episode'),
165
+ input: memoryRichInputSchema,
166
+ title: z.string().trim().min(1).max(260).optional(),
167
+ memoryType: z.enum(memoryTypes).default('durable_fact'),
168
+ sensitivityClass: z.enum(memorySensitivityClasses).default('standard'),
169
+ restrictedDataClasses: z.array(z.enum(memoryRestrictedDataClasses)).max(memoryRestrictedDataClasses.length).default([]),
170
+ topicTags: z.array(z.string().trim().min(1).max(120)).max(50).default([]),
171
+ language: z.string().trim().min(1).max(80).optional(),
172
+ idempotencyKey: z.string().trim().min(1).max(240).optional(),
173
+ policyKey: z.string().trim().min(1).max(120).optional(),
174
+ consent: memoryConsentProofSchema.optional(),
175
+ metadata: z.record(z.unknown()).default({}),
176
+ ...memoryTemporalFieldsShape,
177
+ }).superRefine((value, ctx) => {
178
+ const selectors = [value.tenantId, value.externalTenantId, value.sessionId].filter(Boolean);
179
+ if (selectors.length !== 1) {
180
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Provide exactly one tenant or session selector.' });
181
+ }
182
+ if (!value.sessionId && (!value.subjects || value.subjects.length === 0)) {
183
+ ctx.addIssue({
184
+ code: z.ZodIssueCode.custom,
185
+ path: ['subjects'],
186
+ message: 'subjects are required when sessionId is not supplied.',
187
+ });
188
+ }
189
+ validateMemorySensitivity(value, ctx);
190
+ validateTemporalInterval(value, ctx);
191
+ });
192
+ const memoryReadInputShape = {
193
+ tenantId: z.string().uuid().optional(),
194
+ externalTenantId: z.string().trim().min(1).max(160).optional(),
195
+ sessionId: z.string().uuid().optional(),
196
+ subjects: z.array(memorySubjectRefSchema).min(1).max(20).optional(),
197
+ query: z.string().trim().min(1).max(20_000),
198
+ kinds: z.array(z.enum(memoryRecordKinds)).max(memoryRecordKinds.length).optional(),
199
+ memoryTypes: z.array(z.enum(memoryTypes)).max(memoryTypes.length).optional(),
200
+ providerKeys: z.array(z.string().trim().min(1).max(120)).max(50).optional(),
201
+ sourceFamilyKeys: z.array(z.string().trim().min(1).max(180)).max(50).optional(),
202
+ connectedAccountIds: z.array(z.string().uuid()).max(50).optional(),
203
+ resourceTypes: z.array(z.string().trim().min(1).max(120)).max(50).optional(),
204
+ resourceIds: z.array(z.string().trim().min(1).max(320)).max(1000).optional(),
205
+ states: z.array(z.enum(memoryRecallableRecordStates))
206
+ .max(memoryRecallableRecordStates.length)
207
+ .default(['current', 'conflicted']),
208
+ validAt: z.string().datetime().optional(),
209
+ recordedAt: z.string().datetime().optional(),
210
+ includeGraph: z.boolean().default(true),
211
+ includeSourceRefs: z.boolean().default(true),
212
+ limit: z.number().int().min(1).max(100).default(20),
213
+ semanticCandidateLimit: z.number().int().min(1).max(2000).optional(),
214
+ };
215
+ const memorySearchBaseSchema = z.object(memoryReadInputShape);
216
+ export const memorySearchInputSchema = memorySearchBaseSchema.superRefine(memoryReadSelectorValidation);
217
+ export const memoryContextInputSchema = memorySearchBaseSchema.extend({
218
+ query: z.string().trim().min(1).max(20_000),
219
+ tokenBudget: z.number().int().min(128).max(32_000).optional(),
220
+ includeProfile: z.boolean().optional(),
221
+ includeBlocks: z.boolean().optional(),
222
+ includeRecentEpisodes: z.boolean().default(true),
223
+ promptFormat: z.enum(['text', 'markdown']).default('text'),
224
+ }).superRefine(memoryReadSelectorValidation);
225
+ const memoryRecordListSelectorShape = {
226
+ tenantId: z.string().uuid().optional(),
227
+ externalTenantId: z.string().trim().min(1).max(160).optional(),
228
+ sessionId: z.string().uuid().optional(),
229
+ subjectType: z.enum(memorySubjectTypes).optional(),
230
+ externalSubjectId: z.string().trim().min(1).max(220).optional(),
231
+ kind: z.enum(memoryRecordKinds).optional(),
232
+ sourceKind: z.enum(memorySourceKinds).optional(),
233
+ cursor: z.string().uuid().optional(),
234
+ limit: z.coerce.number().int().min(1).max(100).default(50),
235
+ };
236
+ function validateMemoryRecordListSelector(value, ctx) {
237
+ const selectors = [value.tenantId, value.externalTenantId, value.sessionId].filter(Boolean);
238
+ if (selectors.length !== 1) {
239
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Provide exactly one tenant or session selector.' });
240
+ }
241
+ if (Boolean(value.subjectType) !== Boolean(value.externalSubjectId)) {
242
+ ctx.addIssue({
243
+ code: z.ZodIssueCode.custom,
244
+ message: 'subjectType and externalSubjectId must be supplied together.',
245
+ });
246
+ }
247
+ }
248
+ export const memoryRecordListQuerySchema = z.object({
249
+ ...memoryRecordListSelectorShape,
250
+ state: z.enum(memoryRecallableRecordStates).optional(),
251
+ }).superRefine(validateMemoryRecordListSelector);
252
+ export const memoryForgottenRecordListQuerySchema = z.object(memoryRecordListSelectorShape)
253
+ .superRefine(validateMemoryRecordListSelector);
254
+ export const memoryRecordUpdateInputSchema = z.object({
255
+ content: z.string().trim().min(1).max(1_000_000).optional(),
256
+ title: z.string().trim().min(1).max(260).nullable().optional(),
257
+ memoryType: z.enum(memoryTypes).optional(),
258
+ sensitivityClass: z.enum(memorySensitivityClasses).optional(),
259
+ restrictedDataClasses: z.array(z.enum(memoryRestrictedDataClasses)).max(memoryRestrictedDataClasses.length).optional(),
260
+ topicTags: z.array(z.string().trim().min(1).max(120)).max(50).optional(),
261
+ language: z.string().trim().min(1).max(80).nullable().optional(),
262
+ validFrom: z.string().datetime().nullable().optional(),
263
+ validTo: z.string().datetime().nullable().optional(),
264
+ state: z.enum(['current', 'conflicted']).optional(),
265
+ reason: z.string().trim().min(1).max(500).optional(),
266
+ metadata: z.record(z.unknown()).optional(),
267
+ }).superRefine((value, ctx) => {
268
+ if (Object.keys(value).length === 0) {
269
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'At least one record field must be supplied.' });
270
+ }
271
+ if (value.sensitivityClass !== undefined)
272
+ validateMemorySensitivity(value, ctx);
273
+ });
274
+ export const memoryForgetInputSchema = z.object({
275
+ reason: z.string().trim().min(1).max(500).optional(),
276
+ });
277
+ export const memoryBlockInputSchema = z.object({
278
+ tenantId: z.string().uuid().optional(),
279
+ externalTenantId: z.string().trim().min(1).max(160).optional(),
280
+ sessionId: z.string().uuid().optional(),
281
+ subjects: z.array(memorySubjectRefSchema).min(1).max(20).optional(),
282
+ title: z.string().trim().min(1).max(260),
283
+ content: z.string().trim().min(1).max(200_000),
284
+ access: z.enum(['read_only', 'editable']).default('read_only'),
285
+ priority: z.number().int().min(0).max(100).default(50),
286
+ required: z.boolean().default(false),
287
+ metadata: z.record(z.unknown()).default({}),
288
+ }).superRefine((value, ctx) => {
289
+ const selectors = [value.tenantId, value.externalTenantId, value.sessionId].filter(Boolean);
290
+ if (selectors.length !== 1) {
291
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Provide exactly one tenant or session selector.' });
292
+ }
293
+ if (!value.sessionId && (!value.subjects || value.subjects.length === 0)) {
294
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: ['subjects'], message: 'subjects are required without sessionId.' });
295
+ }
296
+ });
297
+ export const memorySourceBindingInputSchema = z.object({
298
+ tenantId: z.string().uuid().optional(),
299
+ externalTenantId: z.string().trim().min(1).max(160).optional(),
300
+ source: z.discriminatedUnion('kind', [
301
+ z.object({
302
+ kind: z.literal('conversation'),
303
+ applicationKey: z.string().trim().min(1).max(160),
304
+ }).strict(),
305
+ z.object({
306
+ kind: z.literal('artifact'),
307
+ artifactIds: z.array(z.string().uuid()).max(1000).default([]),
308
+ }).strict(),
309
+ ]),
310
+ targets: z.array(memorySubjectRefSchema).min(1).max(20),
311
+ policyKey: z.string().trim().min(1).max(120).default('default'),
312
+ consent: memoryConsentProofSchema.optional(),
313
+ metadata: z.record(z.unknown()).default({}),
314
+ }).superRefine((value, ctx) => {
315
+ if (Boolean(value.tenantId) === Boolean(value.externalTenantId)) {
316
+ ctx.addIssue({
317
+ code: z.ZodIssueCode.custom,
318
+ message: 'Provide exactly one of tenantId or externalTenantId.',
319
+ });
320
+ }
321
+ });
322
+ export const memoryConnectedSourceBackfillRangeSchema = z.enum([
323
+ 'future_only',
324
+ 'last_30_days',
325
+ 'last_90_days',
326
+ 'all',
327
+ ]);
328
+ export const memoryConnectedSourceInputSchema = z.object({
329
+ idempotencyKey: z.string().trim().min(1).max(240),
330
+ tenantId: z.string().uuid().optional(),
331
+ externalTenantId: z.string().trim().min(1).max(160).optional(),
332
+ connectedAccountId: z.string().uuid(),
333
+ sourceFamilyKey: z.string().trim().min(1).max(180),
334
+ resourceIds: z.array(z.string().trim().min(1).max(320)).max(1000).default([]),
335
+ selectionMode: z.enum(['selected_resources', 'recipe_default']).default('selected_resources'),
336
+ targets: z.array(memorySubjectRefSchema).min(1).max(20),
337
+ existingContent: memoryConnectedSourceBackfillRangeSchema.default('future_only'),
338
+ maxBackfillItems: z.number().int().positive().max(10_000).nullable().default(null),
339
+ deliveryMode: z.enum(['auto', 'webhook', 'polling']).default('auto'),
340
+ rememberInstructions: z.string().trim().max(4000).default(''),
341
+ excludeInstructions: z.string().trim().max(4000).default(''),
342
+ allowedMemoryTypes: z.array(z.enum(memoryTypes)).max(memoryTypes.length).default([...memoryTypes]),
343
+ learnedRetentionDays: z.number().int().min(1).max(3650).nullable().default(null),
344
+ sourceRetentionDays: z.number().int().min(1).max(3650).nullable().default(30),
345
+ consent: memoryConsentProofSchema.optional(),
346
+ metadata: z.record(z.unknown()).default({}),
347
+ }).strict().superRefine((value, ctx) => {
348
+ if (Boolean(value.tenantId) === Boolean(value.externalTenantId)) {
349
+ ctx.addIssue({
350
+ code: z.ZodIssueCode.custom,
351
+ message: 'Provide exactly one of tenantId or externalTenantId.',
352
+ });
353
+ }
354
+ });
355
+ export const memoryConnectedSourcePreviewInputSchema = z.object({
356
+ tenantId: z.string().uuid().optional(),
357
+ externalTenantId: z.string().trim().min(1).max(160).optional(),
358
+ connectedAccountId: z.string().uuid(),
359
+ sourceFamilyKey: z.string().trim().min(1).max(180),
360
+ resourceIds: z.array(z.string().trim().min(1).max(320)).max(1000).default([]),
361
+ existingContent: memoryConnectedSourceBackfillRangeSchema.default('future_only'),
362
+ }).strict().superRefine((value, ctx) => {
363
+ if (Boolean(value.tenantId) === Boolean(value.externalTenantId)) {
364
+ ctx.addIssue({
365
+ code: z.ZodIssueCode.custom,
366
+ message: 'Provide exactly one of tenantId or externalTenantId.',
367
+ });
368
+ }
369
+ });
370
+ export const memoryConnectedSourceSettingsInputSchema = z.object({
371
+ resourceIds: z.array(z.string().trim().min(1).max(320)).max(1000),
372
+ targets: z.array(memorySubjectRefSchema).min(1).max(20),
373
+ existingContent: memoryConnectedSourceBackfillRangeSchema,
374
+ rememberInstructions: z.string().trim().max(4000),
375
+ excludeInstructions: z.string().trim().max(4000),
376
+ allowedMemoryTypes: z.array(z.enum(memoryTypes)).max(memoryTypes.length),
377
+ learnedRetentionDays: z.number().int().min(1).max(3650).nullable(),
378
+ sourceRetentionDays: z.number().int().min(1).max(3650).nullable(),
379
+ }).strict();
380
+ export const memorySourceBindingUpdateInputSchema = z.object({
381
+ status: z.enum(['active', 'paused']).optional(),
382
+ connectedSource: memoryConnectedSourceSettingsInputSchema.optional(),
383
+ }).strict().refine((value) => value.status !== undefined || value.connectedSource !== undefined, {
384
+ message: 'Provide a source status or complete connected-source settings.',
385
+ });
386
+ export const memoryProcessSourceJobType = 'memory_process_source';
387
+ export const memoryNormalizeRichSourceJobType = 'memory_normalize_rich_source';
388
+ export const memoryRebuildProfileJobType = 'memory_rebuild_profile';
389
+ export const memoryCellMoveJobType = 'memory_cell_move_execute';
390
+ export const memoryReconcileJobType = 'memory_reconcile';
391
+ export const memoryRetentionJobType = 'memory_retention';
392
+ export const memoryConnectedSourceEventJobType = 'memory_connected_source_event';
393
+ export const memoryConversationTurnInputSchema = z.object({
394
+ sessionId: z.string().uuid(),
395
+ applicationKey: z.string().trim().min(1).max(160),
396
+ turnId: z.string().trim().min(1).max(240),
397
+ content: z.string().trim().min(1).max(1_000_000),
398
+ title: z.string().trim().min(1).max(260).optional(),
399
+ occurredAt: z.string().datetime().optional(),
400
+ consent: memoryConsentProofSchema.optional(),
401
+ metadata: z.record(z.unknown()).default({}),
402
+ }).strict();
403
+ export const memoryGraphQueryInputSchema = memorySearchBaseSchema.extend({
404
+ query: z.string().trim().min(1).max(20_000).optional(),
405
+ seedRecordIds: z.array(z.string().uuid()).max(50).default([]),
406
+ predicates: z.array(z.string().trim().min(1).max(120)).max(50).optional(),
407
+ maxDepth: z.number().int().min(1).max(4).default(2),
408
+ maxClaims: z.number().int().min(1).max(200).default(50),
409
+ }).superRefine(memoryReadSelectorValidation).refine((value) => Boolean(value.query) || value.seedRecordIds.length > 0, {
410
+ message: 'Provide query or seedRecordIds.',
411
+ });
412
+ export const memoryExportInputSchema = z.object({
413
+ tenantId: z.string().uuid().optional(),
414
+ externalTenantId: z.string().trim().min(1).max(160).optional(),
415
+ subject: memorySubjectRefSchema.optional(),
416
+ format: z.enum(['json', 'jsonl']).default('json'),
417
+ }).superRefine((value, ctx) => {
418
+ if (Boolean(value.tenantId) === Boolean(value.externalTenantId)) {
419
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Provide exactly one tenant selector.' });
420
+ }
421
+ });
422
+ export const memoryLegalHoldInputSchema = z.object({
423
+ tenantId: z.string().uuid().optional(),
424
+ externalTenantId: z.string().trim().min(1).max(160).optional(),
425
+ subject: memorySubjectRefSchema.optional(),
426
+ reason: z.string().trim().min(1).max(2000),
427
+ }).strict().superRefine((value, ctx) => {
428
+ if (Boolean(value.tenantId) === Boolean(value.externalTenantId)) {
429
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Provide exactly one tenant selector.' });
430
+ }
431
+ });
432
+ export const memoryProjectPolicyInputSchema = z.object({
433
+ key: z.string().trim().min(1).max(120).default('default'),
434
+ captureMode: z.enum(['explicit', 'bound_sources']).default('explicit'),
435
+ extractionEnabled: z.boolean().default(true),
436
+ profileEnabled: z.boolean().default(true),
437
+ retentionDays: z.number().int().min(1).max(3650).nullable().default(null),
438
+ sourceRetentionDays: z.number().int().min(1).max(3650).nullable().default(30),
439
+ allowedMemoryTypes: z.array(z.enum(memoryTypes)).max(memoryTypes.length).default([...memoryTypes]),
440
+ restrictedDataClasses: z.array(z.enum(memoryRestrictedDataClasses)).max(memoryRestrictedDataClasses.length).default([]),
441
+ languages: z.array(z.string().trim().min(1).max(80)).max(50).default([]),
442
+ consent: z.record(z.unknown()).default({}),
443
+ extraction: z.record(z.unknown()).default({}),
444
+ context: z.record(z.unknown()).default({}),
445
+ metadata: z.record(z.unknown()).default({}),
446
+ });
447
+ export const memoryProjectPolicyUpdateInputSchema = memoryProjectPolicyInputSchema
448
+ .omit({ key: true })
449
+ .extend({
450
+ expectedVersion: z.number().int().positive(),
451
+ })
452
+ .strict();
453
+ export const memoryPolicyPreviewInputSchema = z.object({
454
+ idempotencyKey: z.string().trim().min(1).max(240),
455
+ content: z.string().trim().min(1).max(200_000),
456
+ title: z.string().trim().min(1).max(260).optional(),
457
+ sourceCategory: z.string().trim().min(1).max(120).optional(),
458
+ language: z.string().trim().min(1).max(80).optional(),
459
+ policy: memoryProjectPolicyInputSchema.omit({ key: true }).default({}),
460
+ }).strict();
461
+ export const stacklinkPlatformEventTypes = [
462
+ 'provider.resource.created',
463
+ 'provider.resource.updated',
464
+ 'provider.resource.deleted',
465
+ 'tool.execution.completed',
466
+ 'conversation.turn.completed',
467
+ 'artifact.created',
468
+ ];
469
+ export const stacklinkPlatformEventSchema = z.object({
470
+ id: z.string().uuid(),
471
+ schemaVersion: z.literal('stacklink.event.v1'),
472
+ consumerAppId: z.string().uuid(),
473
+ tenantId: z.string().uuid(),
474
+ sessionId: z.string().uuid().optional(),
475
+ userId: z.string().uuid().optional(),
476
+ type: z.enum(stacklinkPlatformEventTypes),
477
+ source: z.object({
478
+ kind: z.enum(['provider', 'tool_execution', 'conversation', 'artifact']),
479
+ providerKey: z.string().trim().min(1).max(120).optional(),
480
+ connectedAccountId: z.string().uuid().optional(),
481
+ resourceType: z.string().trim().min(1).max(120).optional(),
482
+ resourceId: z.string().trim().min(1).max(320).optional(),
483
+ resourcePreviousScopeIds: z.array(z.string().trim().min(1).max(320)).max(1000).optional(),
484
+ resourceCurrentScopeIds: z.array(z.string().trim().min(1).max(320)).max(1000).optional(),
485
+ resourceAffectedScopeIds: z.array(z.string().trim().min(1).max(320)).max(1000).optional(),
486
+ toolExecutionId: z.string().uuid().optional(),
487
+ applicationKey: z.string().trim().min(1).max(160).optional(),
488
+ }).strict(),
489
+ occurredAt: z.string().datetime(),
490
+ observedAt: z.string().datetime(),
491
+ payloadRef: z.string().trim().min(1).max(2000).optional(),
492
+ data: z.record(z.unknown()),
493
+ metadata: z.record(z.unknown()),
494
+ }).strict();
495
+ export const memorySessionConfigSchema = z.object({
496
+ enabled: z.boolean().default(false),
497
+ agentExternalId: z.string().trim().min(1).max(220).optional(),
498
+ readableSubjects: z.array(z.enum(['session_user', 'session_agent', 'tenant_shared'])).max(3).default(['session_user']),
499
+ writableSubjects: z.array(z.enum(['session_user', 'session_agent', 'tenant_shared'])).max(3).default(['session_user']),
500
+ captureMode: z.enum(['explicit', 'bound_sources']).default('explicit'),
501
+ includeProfile: z.boolean().default(true),
502
+ includeBlocks: z.boolean().default(true),
503
+ contextTokenBudget: z.number().int().min(128).max(32_000).default(1600),
504
+ policyKey: z.string().trim().min(1).max(120).default('default'),
505
+ }).strict().superRefine((value, ctx) => {
506
+ if (value.enabled && value.readableSubjects.length === 0 && value.writableSubjects.length === 0) {
507
+ ctx.addIssue({
508
+ code: z.ZodIssueCode.custom,
509
+ path: ['readableSubjects'],
510
+ message: 'An enabled Memory session must grant at least one readable or writable subject.',
511
+ });
512
+ }
513
+ const usesAgent = value.readableSubjects.includes('session_agent')
514
+ || value.writableSubjects.includes('session_agent');
515
+ if (usesAgent && !value.agentExternalId) {
516
+ ctx.addIssue({
517
+ code: z.ZodIssueCode.custom,
518
+ path: ['agentExternalId'],
519
+ message: 'agentExternalId is required when session_agent is readable or writable.',
520
+ });
521
+ }
522
+ });
523
+ export const memoryExtractedEntitySchema = z.object({
524
+ key: z.string().trim().min(1).max(320),
525
+ type: z.string().trim().min(1).max(80),
526
+ canonicalKey: z.string().trim().min(1).max(320),
527
+ displayName: z.string().trim().min(1).max(320).nullable(),
528
+ attributes: z.record(z.unknown()),
529
+ }).strict();
530
+ const memoryExtractedNullableDateTimeSchema = z.preprocess((value) => {
531
+ if (typeof value !== 'string')
532
+ return value;
533
+ return z.string().datetime().safeParse(value).success ? value : null;
534
+ }, z.string().datetime().nullable());
535
+ export const memoryExtractedClaimSchema = z.object({
536
+ subjectEntityKey: z.string().trim().min(1).max(320),
537
+ predicate: z.string().trim().min(1).max(120),
538
+ objectEntityKey: z.string().trim().min(1).max(320).nullable(),
539
+ literalValue: z.unknown().nullable(),
540
+ validFrom: memoryExtractedNullableDateTimeSchema,
541
+ validTo: memoryExtractedNullableDateTimeSchema,
542
+ }).strict().superRefine((value, ctx) => {
543
+ const objectCount = Number(value.objectEntityKey !== null) + Number(value.literalValue !== null);
544
+ if (objectCount !== 1) {
545
+ ctx.addIssue({
546
+ code: z.ZodIssueCode.custom,
547
+ message: 'Each claim requires exactly one objectEntityKey or literalValue.',
548
+ });
549
+ }
550
+ validateTemporalInterval({
551
+ validFrom: value.validFrom ?? undefined,
552
+ validTo: value.validTo ?? undefined,
553
+ }, ctx);
554
+ });
555
+ export const memoryEvidenceSpanSchema = z.object({
556
+ sourceObjectId: z.string().trim().min(1).max(320),
557
+ segmentId: z.string().trim().min(1).max(80),
558
+ startOffset: z.number().int().min(0),
559
+ endOffset: z.number().int().positive(),
560
+ quotedText: z.string().min(1).max(20_000),
561
+ }).strict().refine((value) => value.endOffset > value.startOffset, {
562
+ message: 'Evidence endOffset must be greater than startOffset.',
563
+ });
564
+ export const memoryExtractedRecordSchema = z.object({
565
+ candidateId: z.string().trim().min(1).max(120),
566
+ recordKind: z.enum(memoryAutomaticRecordKinds),
567
+ memoryType: z.enum(memoryTypes),
568
+ title: z.string().trim().min(1).max(260),
569
+ content: z.string().trim().min(1).max(200_000),
570
+ language: z.string().trim().min(1).max(80),
571
+ sensitivityClass: z.enum(memorySensitivityClasses),
572
+ restrictedDataClasses: z.array(z.enum(memoryRestrictedDataClasses)).max(memoryRestrictedDataClasses.length),
573
+ topicTags: z.array(z.string().trim().min(1).max(120)).max(50),
574
+ validFrom: memoryExtractedNullableDateTimeSchema,
575
+ validTo: memoryExtractedNullableDateTimeSchema,
576
+ evidence: z.array(memoryEvidenceSpanSchema).min(1).max(5),
577
+ entities: z.array(memoryExtractedEntitySchema).max(50),
578
+ claims: z.array(memoryExtractedClaimSchema).max(100),
579
+ attributes: z.record(z.unknown()),
580
+ }).strict().superRefine((value, ctx) => {
581
+ validateTemporalInterval({
582
+ validFrom: value.validFrom ?? undefined,
583
+ validTo: value.validTo ?? undefined,
584
+ }, ctx);
585
+ const entityKeys = new Set(value.entities.map((entity) => entity.key));
586
+ for (const [index, claim] of value.claims.entries()) {
587
+ if (!entityKeys.has(claim.subjectEntityKey)) {
588
+ ctx.addIssue({
589
+ code: z.ZodIssueCode.custom,
590
+ path: ['claims', index, 'subjectEntityKey'],
591
+ message: 'Claim subjectEntityKey must reference an entity in the same candidate.',
592
+ });
593
+ }
594
+ if (claim.objectEntityKey && !entityKeys.has(claim.objectEntityKey)) {
595
+ ctx.addIssue({
596
+ code: z.ZodIssueCode.custom,
597
+ path: ['claims', index, 'objectEntityKey'],
598
+ message: 'Claim objectEntityKey must reference an entity in the same candidate.',
599
+ });
600
+ }
601
+ }
602
+ });
603
+ export const memoryExtractionResultSchema = z.object({
604
+ records: z.array(memoryExtractedRecordSchema).max(100),
605
+ }).strict();
606
+ export const memorySafetyDecisionSchema = z.object({
607
+ candidateId: z.string().trim().min(1).max(120),
608
+ status: z.enum(['classified', 'uncertain']),
609
+ sensitivityClass: z.enum(memorySensitivityClasses),
610
+ restrictedDataClasses: z.array(z.enum(memoryRestrictedDataClasses)).max(memoryRestrictedDataClasses.length),
611
+ reason: z.string().trim().min(1).max(1000),
612
+ }).strict().superRefine((value, ctx) => {
613
+ if (value.sensitivityClass === 'restricted' && value.restrictedDataClasses.length === 0) {
614
+ ctx.addIssue({
615
+ code: z.ZodIssueCode.custom,
616
+ path: ['restrictedDataClasses'],
617
+ message: 'Restricted safety decisions must declare at least one restricted-data class.',
618
+ });
619
+ }
620
+ if (value.sensitivityClass !== 'restricted' && value.restrictedDataClasses.length > 0) {
621
+ ctx.addIssue({
622
+ code: z.ZodIssueCode.custom,
623
+ path: ['restrictedDataClasses'],
624
+ message: 'Only restricted safety decisions may declare restricted-data classes.',
625
+ });
626
+ }
627
+ });
628
+ export const memorySafetyResultSchema = z.object({
629
+ decisions: z.array(memorySafetyDecisionSchema).max(100),
630
+ }).strict();
631
+ const memoryConsolidationDecisionSchema = z.object({
632
+ candidateId: z.string().trim().min(1).max(120),
633
+ action: z.enum(['add', 'supersede', 'contradict', 'support', 'no_change']),
634
+ targetRecordId: z.string().uuid().nullable(),
635
+ reason: z.string().trim().min(1).max(1000),
636
+ }).strict().superRefine((decision, ctx) => {
637
+ const actionRequiresTarget = decision.action === 'supersede'
638
+ || decision.action === 'contradict'
639
+ || decision.action === 'support';
640
+ if (actionRequiresTarget !== (decision.targetRecordId !== null)) {
641
+ ctx.addIssue({
642
+ code: z.ZodIssueCode.custom,
643
+ path: ['targetRecordId'],
644
+ message: actionRequiresTarget
645
+ ? `${decision.action} requires targetRecordId.`
646
+ : `${decision.action} requires targetRecordId to be null.`,
647
+ });
648
+ }
649
+ });
650
+ export const memoryConsolidationResultSchema = z.object({
651
+ decisions: z.array(memoryConsolidationDecisionSchema).max(100),
652
+ }).strict();
653
+ export const memoryProfileResultSchema = z.object({
654
+ buckets: z.array(z.object({
655
+ key: z.string().trim().min(1).max(120),
656
+ content: z.string().trim().min(1).max(100_000),
657
+ includedRecordVersionIds: z.array(z.string().uuid()).min(1).max(500),
658
+ }).strict()).max(100),
659
+ }).strict().superRefine((value, ctx) => {
660
+ const keys = value.buckets.map((bucket) => bucket.key);
661
+ if (new Set(keys).size !== keys.length) {
662
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Profile bucket keys must be unique.' });
663
+ }
664
+ });
665
+ export const memoryProfileDeltaResultSchema = z.object({
666
+ buckets: z.array(z.object({
667
+ key: z.string().trim().min(1).max(120),
668
+ content: z.string().trim().min(1).max(100_000),
669
+ includedRecordVersionIds: z.array(z.string().uuid()).min(1).max(500),
670
+ }).strict()).max(100),
671
+ removeBucketKeys: z.array(z.string().trim().min(1).max(120)).max(100),
672
+ }).strict().superRefine((value, ctx) => {
673
+ const keys = value.buckets.map((bucket) => bucket.key);
674
+ if (new Set(keys).size !== keys.length) {
675
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Profile delta bucket keys must be unique.' });
676
+ }
677
+ if (new Set(value.removeBucketKeys).size !== value.removeBucketKeys.length) {
678
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Profile delta removal keys must be unique.' });
679
+ }
680
+ for (const key of value.removeBucketKeys) {
681
+ if (keys.includes(key)) {
682
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: `Profile delta cannot update and remove bucket ${key}.` });
683
+ }
684
+ }
685
+ });
686
+ export const memoryExtractionJsonSchema = {
687
+ type: 'object',
688
+ additionalProperties: false,
689
+ required: ['records'],
690
+ properties: {
691
+ records: {
692
+ type: 'array',
693
+ maxItems: 100,
694
+ items: {
695
+ type: 'object',
696
+ additionalProperties: false,
697
+ required: [
698
+ 'candidateId', 'recordKind', 'memoryType', 'title', 'content', 'language',
699
+ 'sensitivityClass', 'restrictedDataClasses', 'topicTags', 'validFrom', 'validTo',
700
+ 'evidence', 'entities', 'claims', 'attributes',
701
+ ],
702
+ properties: {
703
+ candidateId: { type: 'string' },
704
+ recordKind: { type: 'string', enum: [...memoryAutomaticRecordKinds] },
705
+ memoryType: { type: 'string', enum: [...memoryTypes] },
706
+ title: { type: 'string' },
707
+ content: { type: 'string' },
708
+ language: { type: 'string' },
709
+ sensitivityClass: { type: 'string', enum: [...memorySensitivityClasses] },
710
+ restrictedDataClasses: {
711
+ type: 'array',
712
+ maxItems: memoryRestrictedDataClasses.length,
713
+ items: { type: 'string', enum: [...memoryRestrictedDataClasses] },
714
+ },
715
+ topicTags: {
716
+ type: 'array',
717
+ maxItems: 50,
718
+ items: { type: 'string' },
719
+ },
720
+ validFrom: { type: ['string', 'null'], format: 'date-time' },
721
+ validTo: { type: ['string', 'null'], format: 'date-time' },
722
+ evidence: {
723
+ type: 'array',
724
+ minItems: 1,
725
+ maxItems: 5,
726
+ items: {
727
+ type: 'object',
728
+ additionalProperties: false,
729
+ required: ['sourceObjectId', 'segmentId', 'startOffset', 'endOffset', 'quotedText'],
730
+ properties: {
731
+ sourceObjectId: { type: 'string' },
732
+ segmentId: { type: 'string' },
733
+ startOffset: { type: 'integer', minimum: 0 },
734
+ endOffset: { type: 'integer', minimum: 1 },
735
+ quotedText: { type: 'string' },
736
+ },
737
+ },
738
+ },
739
+ entities: {
740
+ type: 'array',
741
+ description: 'Entities used by this record. Every entity key referenced by this record claims must be declared in this same array.',
742
+ items: {
743
+ type: 'object',
744
+ additionalProperties: false,
745
+ required: ['key', 'type', 'canonicalKey', 'displayName', 'attributes'],
746
+ properties: {
747
+ key: { type: 'string', description: 'A key unique within this record and used by this record claims.' },
748
+ type: { type: 'string' },
749
+ canonicalKey: { type: 'string' },
750
+ displayName: { type: ['string', 'null'] },
751
+ attributes: { type: 'object', additionalProperties: true },
752
+ },
753
+ },
754
+ },
755
+ claims: {
756
+ type: 'array',
757
+ description: 'Claims for this record. Entity references may only use keys declared in this same record entities array.',
758
+ items: {
759
+ type: 'object',
760
+ additionalProperties: false,
761
+ required: ['subjectEntityKey', 'predicate', 'objectEntityKey', 'literalValue', 'validFrom', 'validTo'],
762
+ properties: {
763
+ subjectEntityKey: { type: 'string', description: 'Must exactly match an entities[].key in this same record.' },
764
+ predicate: { type: 'string' },
765
+ objectEntityKey: { type: ['string', 'null'], description: 'When non-null, must exactly match an entities[].key in this same record.' },
766
+ literalValue: {
767
+ anyOf: [
768
+ { type: 'string' },
769
+ { type: 'number' },
770
+ { type: 'boolean' },
771
+ { type: 'object' },
772
+ { type: 'array' },
773
+ { type: 'null' },
774
+ ],
775
+ },
776
+ validFrom: { type: ['string', 'null'], format: 'date-time' },
777
+ validTo: { type: ['string', 'null'], format: 'date-time' },
778
+ },
779
+ },
780
+ },
781
+ attributes: { type: 'object', additionalProperties: true },
782
+ },
783
+ },
784
+ },
785
+ },
786
+ };
787
+ export const memorySafetyJsonSchema = {
788
+ type: 'object',
789
+ additionalProperties: false,
790
+ required: ['decisions'],
791
+ properties: {
792
+ decisions: {
793
+ type: 'array',
794
+ maxItems: 100,
795
+ items: {
796
+ type: 'object',
797
+ additionalProperties: false,
798
+ required: ['candidateId', 'status', 'sensitivityClass', 'restrictedDataClasses', 'reason'],
799
+ properties: {
800
+ candidateId: { type: 'string' },
801
+ status: { type: 'string', enum: ['classified', 'uncertain'] },
802
+ sensitivityClass: { type: 'string', enum: [...memorySensitivityClasses] },
803
+ restrictedDataClasses: {
804
+ type: 'array',
805
+ maxItems: memoryRestrictedDataClasses.length,
806
+ items: { type: 'string', enum: [...memoryRestrictedDataClasses] },
807
+ },
808
+ reason: { type: 'string' },
809
+ },
810
+ },
811
+ },
812
+ },
813
+ };
814
+ export const memoryConsolidationJsonSchema = {
815
+ type: 'object',
816
+ additionalProperties: false,
817
+ required: ['decisions'],
818
+ properties: {
819
+ decisions: {
820
+ type: 'array',
821
+ maxItems: 100,
822
+ items: {
823
+ type: 'object',
824
+ additionalProperties: false,
825
+ required: ['candidateId', 'action', 'targetRecordId', 'reason'],
826
+ properties: {
827
+ candidateId: { type: 'string' },
828
+ action: { type: 'string', enum: ['add', 'supersede', 'contradict', 'support', 'no_change'] },
829
+ targetRecordId: { type: ['string', 'null'], format: 'uuid' },
830
+ reason: { type: 'string' },
831
+ },
832
+ },
833
+ },
834
+ },
835
+ };
836
+ export function memoryProfileJsonSchema(allowedBucketKeys) {
837
+ return {
838
+ type: 'object',
839
+ additionalProperties: false,
840
+ required: ['buckets'],
841
+ properties: {
842
+ buckets: {
843
+ type: 'array',
844
+ maxItems: allowedBucketKeys.length,
845
+ items: memoryProfileBucketJsonSchema(allowedBucketKeys),
846
+ },
847
+ },
848
+ };
849
+ }
850
+ export function memoryProfileDeltaJsonSchema(allowedBucketKeys) {
851
+ return {
852
+ type: 'object',
853
+ additionalProperties: false,
854
+ required: ['buckets', 'removeBucketKeys'],
855
+ properties: {
856
+ buckets: {
857
+ type: 'array',
858
+ maxItems: allowedBucketKeys.length,
859
+ items: memoryProfileBucketJsonSchema(allowedBucketKeys),
860
+ },
861
+ removeBucketKeys: {
862
+ type: 'array',
863
+ maxItems: allowedBucketKeys.length,
864
+ items: { type: 'string', enum: allowedBucketKeys },
865
+ },
866
+ },
867
+ };
868
+ }
869
+ function memoryProfileBucketJsonSchema(allowedBucketKeys) {
870
+ if (allowedBucketKeys.length === 0) {
871
+ throw new Error('Memory profile schemas require at least one allowed bucket key.');
872
+ }
873
+ return {
874
+ type: 'object',
875
+ additionalProperties: false,
876
+ required: ['key', 'content', 'includedRecordVersionIds'],
877
+ properties: {
878
+ key: { type: 'string', enum: allowedBucketKeys },
879
+ content: { type: 'string', minLength: 1, maxLength: 100_000 },
880
+ includedRecordVersionIds: {
881
+ type: 'array',
882
+ minItems: 1,
883
+ maxItems: 500,
884
+ items: { type: 'string', format: 'uuid' },
885
+ },
886
+ },
887
+ };
888
+ }
889
+ function memoryReadSelectorValidation(value, ctx) {
890
+ const selectors = [value.tenantId, value.externalTenantId, value.sessionId].filter(Boolean);
891
+ if (selectors.length !== 1) {
892
+ ctx.addIssue({ code: z.ZodIssueCode.custom, message: 'Provide exactly one tenant or session selector.' });
893
+ }
894
+ if (!value.sessionId && (!value.subjects || value.subjects.length === 0)) {
895
+ ctx.addIssue({ code: z.ZodIssueCode.custom, path: ['subjects'], message: 'subjects are required without sessionId.' });
896
+ }
897
+ }
898
+ function validateMemorySensitivity(value, ctx) {
899
+ const restrictedDataClasses = value.restrictedDataClasses ?? [];
900
+ if (value.sensitivityClass === 'secret') {
901
+ ctx.addIssue({
902
+ code: z.ZodIssueCode.custom,
903
+ path: ['sensitivityClass'],
904
+ message: 'Secret authentication or credential material cannot be stored in Memory.',
905
+ });
906
+ }
907
+ if (value.sensitivityClass === 'restricted' && restrictedDataClasses.length === 0) {
908
+ ctx.addIssue({
909
+ code: z.ZodIssueCode.custom,
910
+ path: ['restrictedDataClasses'],
911
+ message: 'Restricted Memory must declare at least one typed restricted-data class.',
912
+ });
913
+ }
914
+ if (value.sensitivityClass !== 'restricted' && restrictedDataClasses.length > 0) {
915
+ ctx.addIssue({
916
+ code: z.ZodIssueCode.custom,
917
+ path: ['restrictedDataClasses'],
918
+ message: 'Restricted-data classes are allowed only when sensitivityClass is restricted.',
919
+ });
920
+ }
921
+ }
922
+ function validateTemporalInterval(value, ctx) {
923
+ if (value.validFrom && value.validTo && Date.parse(value.validTo) <= Date.parse(value.validFrom)) {
924
+ ctx.addIssue({
925
+ code: z.ZodIssueCode.custom,
926
+ path: ['validTo'],
927
+ message: 'validTo must be later than validFrom.',
928
+ });
929
+ }
930
+ }
931
+ //# sourceMappingURL=memory-contract.js.map