@sequenceholdings/managed-functions 0.4.5 → 0.5.1

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 (71) hide show
  1. package/README.md +147 -12
  2. package/dist/abrigo-contract.d.ts +2 -92
  3. package/dist/abrigo-contract.js +12 -53
  4. package/dist/abrigo-response.d.ts +1 -6
  5. package/dist/abrigo-response.js +3 -25
  6. package/dist/abrigo.d.ts +5 -5
  7. package/dist/abrigo.js +66 -92
  8. package/dist/agent-evidence.d.ts +5 -5
  9. package/dist/agent-evidence.js +58 -48
  10. package/dist/agent-source-evidence-contract.d.ts +2 -1197
  11. package/dist/agent-source-evidence-contract.js +24 -94
  12. package/dist/agents-contract.d.ts +2 -99
  13. package/dist/agents-contract.js +13 -67
  14. package/dist/agents.d.ts +5 -5
  15. package/dist/agents.js +79 -44
  16. package/dist/capabilities.d.ts +1 -1
  17. package/dist/capabilities.js +1 -1
  18. package/dist/config.d.ts +1 -0
  19. package/dist/config.js +4 -1
  20. package/dist/directory-config.d.ts +1 -23
  21. package/dist/directory-config.js +8 -20
  22. package/dist/directory-contract.d.ts +2 -68
  23. package/dist/directory-contract.js +13 -55
  24. package/dist/directory-roster-contract.d.ts +2 -22
  25. package/dist/directory-roster-contract.js +7 -22
  26. package/dist/directory.d.ts +4 -8
  27. package/dist/directory.js +15 -33
  28. package/dist/group-roster-access.d.ts +7 -0
  29. package/dist/group-roster-access.js +8 -0
  30. package/dist/index.d.ts +49 -46
  31. package/dist/index.js +8 -1
  32. package/dist/invocation-client.d.ts +4 -4
  33. package/dist/invocation-client.js +32 -60
  34. package/dist/invocation-contract.d.ts +2 -59
  35. package/dist/invocation-contract.js +10 -61
  36. package/dist/invocation.d.ts +4 -4
  37. package/dist/invocation.js +42 -63
  38. package/dist/lattice-provenance-contract.d.ts +2 -607
  39. package/dist/lattice-provenance-contract.js +14 -154
  40. package/dist/lattice-provenance.d.ts +3 -3
  41. package/dist/lattice-provenance.js +46 -97
  42. package/dist/monitoring-annotations.d.ts +2 -53
  43. package/dist/monitoring-annotations.js +2 -51
  44. package/dist/monitoring-contract.d.ts +5 -460
  45. package/dist/monitoring-contract.js +37 -77
  46. package/dist/monitoring-events.d.ts +2 -252
  47. package/dist/monitoring-events.js +15 -125
  48. package/dist/monitoring.d.ts +3 -3
  49. package/dist/monitoring.js +41 -41
  50. package/dist/orm.d.ts +10 -1
  51. package/dist/orm.js +27 -7
  52. package/dist/platform-client.d.ts +27 -0
  53. package/dist/platform-client.js +79 -0
  54. package/dist/platform-domains.d.ts +1671 -0
  55. package/dist/platform-domains.js +77 -0
  56. package/dist/processes-contract.d.ts +2 -149
  57. package/dist/processes-contract.js +17 -100
  58. package/dist/processes.d.ts +3 -3
  59. package/dist/processes.js +64 -49
  60. package/dist/runtime.cjs +4251 -1666
  61. package/dist/service-directory-roster.d.ts +12 -3
  62. package/dist/service-directory-roster.js +11 -17
  63. package/dist/service-directory.d.ts +4 -8
  64. package/dist/service-directory.js +16 -67
  65. package/dist/storage.d.ts +36 -35
  66. package/dist/storage.js +12 -5
  67. package/dist/workflow-source-contract.d.ts +2 -524
  68. package/dist/workflow-source-contract.js +16 -56
  69. package/dist/workflow-source.d.ts +3 -3
  70. package/dist/workflow-source.js +106 -43
  71. package/package.json +4 -3
@@ -1,255 +1,5 @@
1
- import { z } from 'zod';
2
- export declare const MAX_CONTEXT_TEXT_CHARS = 50000;
3
- export declare const MAX_SCALAR_STRING_CHARS = 8000;
4
- export declare const MAX_CONTEXT_JSON_CHARS = 100000;
5
- export declare const PRODUCER_EVENT_KEY_PREFIX = "producer:";
6
- export declare const artifactDeltaContextSchema: z.ZodObject<{
7
- artifactKind: z.ZodString;
8
- sectionPath: z.ZodString;
9
- before: z.ZodString;
10
- after: z.ZodString;
11
- changeKind: z.ZodEnum<{
12
- added: "added";
13
- removed: "removed";
14
- modified: "modified";
15
- }>;
16
- category: z.ZodOptional<z.ZodString>;
17
- sourceRefs: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
18
- workflowId: z.ZodOptional<z.ZodString>;
19
- }, z.core.$strict>;
20
- export declare const dtiDeltaContextSchema: z.ZodObject<{
21
- stageId: z.ZodString;
22
- loanId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
23
- fieldPath: z.ZodString;
24
- before: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
25
- after: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
26
- section: z.ZodOptional<z.ZodEnum<{
27
- debt: "debt";
28
- income: "income";
29
- other: "other";
30
- }>>;
31
- itemLabel: z.ZodOptional<z.ZodString>;
32
- calculatorType: z.ZodOptional<z.ZodEnum<{
33
- basic: "basic";
34
- advanced: "advanced";
35
- }>>;
36
- workflowId: z.ZodOptional<z.ZodString>;
37
- sourceDocRefs: z.ZodOptional<z.ZodArray<z.ZodString>>;
38
- }, z.core.$strict>;
39
- export declare const docExtractEditContextSchema: z.ZodObject<{
40
- documentId: z.ZodString;
41
- docType: z.ZodString;
42
- fieldPath: z.ZodString;
43
- oldValue: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
44
- newValue: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
45
- rowKey: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
46
- stageId: z.ZodOptional<z.ZodString>;
47
- workflowId: z.ZodOptional<z.ZodString>;
48
- citation: z.ZodOptional<z.ZodObject<{
49
- page: z.ZodNumber;
50
- region: z.ZodOptional<z.ZodString>;
51
- }, z.core.$strict>>;
52
- }, z.core.$strict>;
53
- export declare const deltaEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
54
- contextType: z.ZodLiteral<"artifact_delta">;
55
- context: z.ZodObject<{
56
- artifactKind: z.ZodString;
57
- sectionPath: z.ZodString;
58
- before: z.ZodString;
59
- after: z.ZodString;
60
- changeKind: z.ZodEnum<{
61
- added: "added";
62
- removed: "removed";
63
- modified: "modified";
64
- }>;
65
- category: z.ZodOptional<z.ZodString>;
66
- sourceRefs: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
67
- workflowId: z.ZodOptional<z.ZodString>;
68
- }, z.core.$strict>;
69
- idempotencyKey: z.ZodString;
70
- subjectId: z.ZodString;
71
- subjectKind: z.ZodEnum<{
72
- workflow: "workflow";
73
- agent: "agent";
74
- }>;
75
- occurredAt: z.ZodString;
76
- deltaReason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
77
- deltaSource: z.ZodDefault<z.ZodEnum<{
78
- unknown: "unknown";
79
- human: "human";
80
- llm: "llm";
81
- }>>;
82
- actionability: z.ZodDefault<z.ZodLiteral<"unknown">>;
83
- }, z.core.$strict>, z.ZodObject<{
84
- contextType: z.ZodLiteral<"dti_delta">;
85
- context: z.ZodObject<{
86
- stageId: z.ZodString;
87
- loanId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
88
- fieldPath: z.ZodString;
89
- before: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
90
- after: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
91
- section: z.ZodOptional<z.ZodEnum<{
92
- debt: "debt";
93
- income: "income";
94
- other: "other";
95
- }>>;
96
- itemLabel: z.ZodOptional<z.ZodString>;
97
- calculatorType: z.ZodOptional<z.ZodEnum<{
98
- basic: "basic";
99
- advanced: "advanced";
100
- }>>;
101
- workflowId: z.ZodOptional<z.ZodString>;
102
- sourceDocRefs: z.ZodOptional<z.ZodArray<z.ZodString>>;
103
- }, z.core.$strict>;
104
- idempotencyKey: z.ZodString;
105
- subjectId: z.ZodString;
106
- subjectKind: z.ZodEnum<{
107
- workflow: "workflow";
108
- agent: "agent";
109
- }>;
110
- occurredAt: z.ZodString;
111
- deltaReason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
112
- deltaSource: z.ZodDefault<z.ZodEnum<{
113
- unknown: "unknown";
114
- human: "human";
115
- llm: "llm";
116
- }>>;
117
- actionability: z.ZodDefault<z.ZodLiteral<"unknown">>;
118
- }, z.core.$strict>, z.ZodObject<{
119
- contextType: z.ZodLiteral<"doc_extract_edit">;
120
- context: z.ZodObject<{
121
- documentId: z.ZodString;
122
- docType: z.ZodString;
123
- fieldPath: z.ZodString;
124
- oldValue: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
125
- newValue: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
126
- rowKey: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
127
- stageId: z.ZodOptional<z.ZodString>;
128
- workflowId: z.ZodOptional<z.ZodString>;
129
- citation: z.ZodOptional<z.ZodObject<{
130
- page: z.ZodNumber;
131
- region: z.ZodOptional<z.ZodString>;
132
- }, z.core.$strict>>;
133
- }, z.core.$strict>;
134
- idempotencyKey: z.ZodString;
135
- subjectId: z.ZodString;
136
- subjectKind: z.ZodEnum<{
137
- workflow: "workflow";
138
- agent: "agent";
139
- }>;
140
- occurredAt: z.ZodString;
141
- deltaReason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
142
- deltaSource: z.ZodDefault<z.ZodEnum<{
143
- unknown: "unknown";
144
- human: "human";
145
- llm: "llm";
146
- }>>;
147
- actionability: z.ZodDefault<z.ZodLiteral<"unknown">>;
148
- }, z.core.$strict>], "contextType">;
149
- export type DeltaEventInput = z.infer<typeof deltaEventSchema>;
150
- export type ArtifactDeltaContext = z.infer<typeof artifactDeltaContextSchema>;
151
- export type DtiDeltaContext = z.infer<typeof dtiDeltaContextSchema>;
152
- export type DocExtractEditContext = z.infer<typeof docExtractEditContextSchema>;
153
- export declare const MAX_DELTA_EVENTS_PER_REQUEST = 100;
154
- export declare const emitDeltaEventsBodySchema: z.ZodObject<{
155
- events: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
156
- contextType: z.ZodLiteral<"artifact_delta">;
157
- context: z.ZodObject<{
158
- artifactKind: z.ZodString;
159
- sectionPath: z.ZodString;
160
- before: z.ZodString;
161
- after: z.ZodString;
162
- changeKind: z.ZodEnum<{
163
- added: "added";
164
- removed: "removed";
165
- modified: "modified";
166
- }>;
167
- category: z.ZodOptional<z.ZodString>;
168
- sourceRefs: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
169
- workflowId: z.ZodOptional<z.ZodString>;
170
- }, z.core.$strict>;
171
- idempotencyKey: z.ZodString;
172
- subjectId: z.ZodString;
173
- subjectKind: z.ZodEnum<{
174
- workflow: "workflow";
175
- agent: "agent";
176
- }>;
177
- occurredAt: z.ZodString;
178
- deltaReason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
179
- deltaSource: z.ZodDefault<z.ZodEnum<{
180
- unknown: "unknown";
181
- human: "human";
182
- llm: "llm";
183
- }>>;
184
- actionability: z.ZodDefault<z.ZodLiteral<"unknown">>;
185
- }, z.core.$strict>, z.ZodObject<{
186
- contextType: z.ZodLiteral<"dti_delta">;
187
- context: z.ZodObject<{
188
- stageId: z.ZodString;
189
- loanId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
190
- fieldPath: z.ZodString;
191
- before: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
192
- after: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
193
- section: z.ZodOptional<z.ZodEnum<{
194
- debt: "debt";
195
- income: "income";
196
- other: "other";
197
- }>>;
198
- itemLabel: z.ZodOptional<z.ZodString>;
199
- calculatorType: z.ZodOptional<z.ZodEnum<{
200
- basic: "basic";
201
- advanced: "advanced";
202
- }>>;
203
- workflowId: z.ZodOptional<z.ZodString>;
204
- sourceDocRefs: z.ZodOptional<z.ZodArray<z.ZodString>>;
205
- }, z.core.$strict>;
206
- idempotencyKey: z.ZodString;
207
- subjectId: z.ZodString;
208
- subjectKind: z.ZodEnum<{
209
- workflow: "workflow";
210
- agent: "agent";
211
- }>;
212
- occurredAt: z.ZodString;
213
- deltaReason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
214
- deltaSource: z.ZodDefault<z.ZodEnum<{
215
- unknown: "unknown";
216
- human: "human";
217
- llm: "llm";
218
- }>>;
219
- actionability: z.ZodDefault<z.ZodLiteral<"unknown">>;
220
- }, z.core.$strict>, z.ZodObject<{
221
- contextType: z.ZodLiteral<"doc_extract_edit">;
222
- context: z.ZodObject<{
223
- documentId: z.ZodString;
224
- docType: z.ZodString;
225
- fieldPath: z.ZodString;
226
- oldValue: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
227
- newValue: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>;
228
- rowKey: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodNull]>>>;
229
- stageId: z.ZodOptional<z.ZodString>;
230
- workflowId: z.ZodOptional<z.ZodString>;
231
- citation: z.ZodOptional<z.ZodObject<{
232
- page: z.ZodNumber;
233
- region: z.ZodOptional<z.ZodString>;
234
- }, z.core.$strict>>;
235
- }, z.core.$strict>;
236
- idempotencyKey: z.ZodString;
237
- subjectId: z.ZodString;
238
- subjectKind: z.ZodEnum<{
239
- workflow: "workflow";
240
- agent: "agent";
241
- }>;
242
- occurredAt: z.ZodString;
243
- deltaReason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
244
- deltaSource: z.ZodDefault<z.ZodEnum<{
245
- unknown: "unknown";
246
- human: "human";
247
- llm: "llm";
248
- }>>;
249
- actionability: z.ZodDefault<z.ZodLiteral<"unknown">>;
250
- }, z.core.$strict>], "contextType">>;
251
- }, z.core.$strict>;
252
- export type EmitDeltaEventsBody = z.infer<typeof emitDeltaEventsBodySchema>;
1
+ export { MAX_CONTEXT_TEXT_CHARS, MAX_SCALAR_STRING_CHARS, MAX_CONTEXT_JSON_CHARS, PRODUCER_EVENT_KEY_PREFIX, artifactDeltaContextSchema, dtiDeltaContextSchema, docExtractEditContextSchema, deltaEventSchema, MAX_DELTA_EVENTS_PER_REQUEST, emitDeltaEventsBodySchema, } from "@sequenceholdings/platform/contracts";
2
+ export type { DeltaEventInput, ArtifactDeltaContext, DtiDeltaContext, DocExtractEditContext, EmitDeltaEventsBody, } from "@sequenceholdings/platform/contracts";
253
3
  export declare function contentHashKey(parts: ReadonlyArray<string | number>): string;
254
4
  export declare function scopedIdempotencyKey(args: {
255
5
  scope: string;
@@ -4,132 +4,22 @@ exports.emitDeltaEventsBodySchema = exports.MAX_DELTA_EVENTS_PER_REQUEST = expor
4
4
  exports.contentHashKey = contentHashKey;
5
5
  exports.scopedIdempotencyKey = scopedIdempotencyKey;
6
6
  const node_crypto_1 = require("node:crypto");
7
- const zod_1 = require("zod");
8
- exports.MAX_CONTEXT_TEXT_CHARS = 50_000;
9
- exports.MAX_SCALAR_STRING_CHARS = 8_000;
10
- exports.MAX_CONTEXT_JSON_CHARS = 100_000;
11
- exports.PRODUCER_EVENT_KEY_PREFIX = 'producer:';
12
- const scalarSchema = zod_1.z.union([
13
- zod_1.z.string().max(exports.MAX_SCALAR_STRING_CHARS),
14
- zod_1.z.number(),
15
- zod_1.z.boolean(),
16
- zod_1.z.null(),
17
- ]);
18
- const boundedText = zod_1.z.string().max(exports.MAX_CONTEXT_TEXT_CHARS);
19
- const boundedId = zod_1.z.string().min(1).max(512);
20
- function assertBoundedContextJson(context, ctx, path = ['context']) {
21
- if (JSON.stringify(context).length > exports.MAX_CONTEXT_JSON_CHARS) {
22
- ctx.addIssue({
23
- code: zod_1.z.ZodIssueCode.custom,
24
- path: [...path],
25
- message: `context JSON exceeds ${exports.MAX_CONTEXT_JSON_CHARS} characters`,
26
- });
27
- }
28
- }
29
- exports.artifactDeltaContextSchema = zod_1.z
30
- .object({
31
- artifactKind: boundedId,
32
- sectionPath: boundedId,
33
- before: boundedText,
34
- after: boundedText,
35
- changeKind: zod_1.z.enum(['added', 'removed', 'modified']),
36
- category: boundedId.optional(),
37
- sourceRefs: zod_1.z.record(zod_1.z.string().max(128), zod_1.z.union([zod_1.z.string().max(exports.MAX_SCALAR_STRING_CHARS), zod_1.z.number()])),
38
- workflowId: boundedId.optional(),
39
- })
40
- .strict()
41
- .superRefine((context, ctx) => assertBoundedContextJson(context, ctx, []));
42
- exports.dtiDeltaContextSchema = zod_1.z
43
- .object({
44
- stageId: boundedId,
45
- loanId: zod_1.z.string().max(512).nullable().optional(),
46
- fieldPath: boundedId,
47
- before: scalarSchema,
48
- after: scalarSchema,
49
- section: zod_1.z.enum(['debt', 'income', 'other']).optional(),
50
- itemLabel: zod_1.z.string().max(exports.MAX_SCALAR_STRING_CHARS).optional(),
51
- calculatorType: zod_1.z.enum(['basic', 'advanced']).optional(),
52
- workflowId: boundedId.optional(),
53
- sourceDocRefs: zod_1.z.array(zod_1.z.string().max(512)).max(50).optional(),
54
- })
55
- .strict()
56
- .superRefine((context, ctx) => assertBoundedContextJson(context, ctx, []));
57
- exports.docExtractEditContextSchema = zod_1.z
58
- .object({
59
- documentId: boundedId,
60
- docType: boundedId,
61
- fieldPath: boundedId,
62
- oldValue: scalarSchema,
63
- newValue: scalarSchema,
64
- rowKey: zod_1.z.record(zod_1.z.string().max(128), scalarSchema).optional(),
65
- stageId: zod_1.z.string().max(512).optional(),
66
- workflowId: zod_1.z.string().max(512).optional(),
67
- citation: zod_1.z
68
- .object({
69
- page: zod_1.z.number().int(),
70
- region: zod_1.z.string().max(exports.MAX_SCALAR_STRING_CHARS).optional(),
71
- })
72
- .strict()
73
- .optional(),
74
- })
75
- .strict()
76
- .superRefine((context, ctx) => assertBoundedContextJson(context, ctx, []));
77
- const deltaEventBaseFields = {
78
- idempotencyKey: zod_1.z.string().min(1).max(512),
79
- subjectId: zod_1.z.string().min(1).max(512),
80
- subjectKind: zod_1.z.enum(['agent', 'workflow']),
81
- occurredAt: zod_1.z.string().datetime({ offset: true }),
82
- deltaReason: zod_1.z.string().max(exports.MAX_CONTEXT_TEXT_CHARS).nullable().optional(),
83
- deltaSource: zod_1.z.enum(['human', 'llm', 'unknown']).default('unknown'),
84
- actionability: zod_1.z.literal('unknown').default('unknown'),
85
- };
86
- exports.deltaEventSchema = zod_1.z.discriminatedUnion('contextType', [
87
- zod_1.z
88
- .object({
89
- ...deltaEventBaseFields,
90
- contextType: zod_1.z.literal('artifact_delta'),
91
- context: exports.artifactDeltaContextSchema,
92
- })
93
- .strict(),
94
- zod_1.z
95
- .object({
96
- ...deltaEventBaseFields,
97
- contextType: zod_1.z.literal('dti_delta'),
98
- context: exports.dtiDeltaContextSchema,
99
- })
100
- .strict(),
101
- zod_1.z
102
- .object({
103
- ...deltaEventBaseFields,
104
- contextType: zod_1.z.literal('doc_extract_edit'),
105
- context: exports.docExtractEditContextSchema,
106
- })
107
- .strict(),
108
- ]);
109
- exports.MAX_DELTA_EVENTS_PER_REQUEST = 100;
110
- exports.emitDeltaEventsBodySchema = zod_1.z
111
- .object({
112
- events: zod_1.z.array(exports.deltaEventSchema).min(1).max(exports.MAX_DELTA_EVENTS_PER_REQUEST),
113
- })
114
- .strict()
115
- .superRefine((body, ctx) => {
116
- const seen = new Set();
117
- body.events.forEach((event, index) => {
118
- if (event.idempotencyKey.startsWith(exports.PRODUCER_EVENT_KEY_PREFIX)) {
119
- ctx.addIssue({ code: zod_1.z.ZodIssueCode.custom, path: ['events', index, 'idempotencyKey'], message: 'Producer event storage keys are reserved for scoped monitoring delivery' });
120
- }
121
- if (seen.has(event.idempotencyKey)) {
122
- ctx.addIssue({
123
- code: zod_1.z.ZodIssueCode.custom,
124
- path: ['events', index, 'idempotencyKey'],
125
- message: `Duplicate idempotencyKey in batch: ${event.idempotencyKey}`,
126
- });
127
- }
128
- seen.add(event.idempotencyKey);
129
- });
130
- });
7
+ var contracts_1 = require("@sequenceholdings/platform/contracts");
8
+ Object.defineProperty(exports, "MAX_CONTEXT_TEXT_CHARS", { enumerable: true, get: function () { return contracts_1.MAX_CONTEXT_TEXT_CHARS; } });
9
+ Object.defineProperty(exports, "MAX_SCALAR_STRING_CHARS", { enumerable: true, get: function () { return contracts_1.MAX_SCALAR_STRING_CHARS; } });
10
+ Object.defineProperty(exports, "MAX_CONTEXT_JSON_CHARS", { enumerable: true, get: function () { return contracts_1.MAX_CONTEXT_JSON_CHARS; } });
11
+ Object.defineProperty(exports, "PRODUCER_EVENT_KEY_PREFIX", { enumerable: true, get: function () { return contracts_1.PRODUCER_EVENT_KEY_PREFIX; } });
12
+ Object.defineProperty(exports, "artifactDeltaContextSchema", { enumerable: true, get: function () { return contracts_1.artifactDeltaContextSchema; } });
13
+ Object.defineProperty(exports, "dtiDeltaContextSchema", { enumerable: true, get: function () { return contracts_1.dtiDeltaContextSchema; } });
14
+ Object.defineProperty(exports, "docExtractEditContextSchema", { enumerable: true, get: function () { return contracts_1.docExtractEditContextSchema; } });
15
+ Object.defineProperty(exports, "deltaEventSchema", { enumerable: true, get: function () { return contracts_1.deltaEventSchema; } });
16
+ Object.defineProperty(exports, "MAX_DELTA_EVENTS_PER_REQUEST", { enumerable: true, get: function () { return contracts_1.MAX_DELTA_EVENTS_PER_REQUEST; } });
17
+ Object.defineProperty(exports, "emitDeltaEventsBodySchema", { enumerable: true, get: function () { return contracts_1.emitDeltaEventsBodySchema; } });
131
18
  function contentHashKey(parts) {
132
- return (0, node_crypto_1.createHash)('sha256').update(parts.join('|')).digest('hex').slice(0, 16);
19
+ return (0, node_crypto_1.createHash)("sha256")
20
+ .update(parts.join("|"))
21
+ .digest("hex")
22
+ .slice(0, 16);
133
23
  }
134
24
  function scopedIdempotencyKey(args) {
135
25
  return `${args.scope}:${contentHashKey(args.parts)}`;
@@ -1,7 +1,7 @@
1
- import { type MonitoringCatalogQuery, type MonitoringBucketCatalog, type MonitoringDeliveryKey, type MonitoringDeliveryReceipt, type MonitoringPublish } from './monitoring-contract';
1
+ import { type MonitoringCatalogQuery, type MonitoringBucketCatalog, type MonitoringDeliveryKey, type MonitoringDeliveryReceipt, type MonitoringPublish } from "./monitoring-contract";
2
2
  export interface FunctionServiceMonitoringOptions {
3
3
  request: {
4
- headers: Pick<Headers, 'get'> | Readonly<Record<string, string | readonly string[] | undefined>>;
4
+ headers: Pick<Headers, "get"> | Readonly<Record<string, string | readonly string[] | undefined>>;
5
5
  };
6
6
  baseUrl: string;
7
7
  fetchImpl?: typeof globalThis.fetch;
@@ -11,4 +11,4 @@ export interface FunctionServiceMonitoringClient {
11
11
  get(input: MonitoringDeliveryKey): Promise<MonitoringDeliveryReceipt>;
12
12
  getBucketCatalog(input: MonitoringCatalogQuery): Promise<MonitoringBucketCatalog>;
13
13
  }
14
- export declare function createFunctionServiceMonitoringClient({ request, baseUrl, fetchImpl }: FunctionServiceMonitoringOptions): FunctionServiceMonitoringClient;
14
+ export declare function createFunctionServiceMonitoringClient({ request, baseUrl, fetchImpl, }: FunctionServiceMonitoringOptions): FunctionServiceMonitoringClient;
@@ -1,28 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createFunctionServiceMonitoringClient = createFunctionServiceMonitoringClient;
4
+ const adapters_1 = require("@sequenceholdings/platform/adapters");
4
5
  const zod_1 = require("zod");
5
6
  const monitoring_contract_1 = require("./monitoring-contract");
6
7
  function credential(request) {
7
8
  const headers = request.headers;
8
- const matches = typeof headers.get === 'function'
9
+ const matches = typeof headers.get === "function"
9
10
  ? [headers.get(monitoring_contract_1.FUNCTION_MONITORING_TOKEN_HEADER)]
10
- : Object.entries(headers).filter(([name]) => name.toLowerCase() === monitoring_contract_1.FUNCTION_MONITORING_TOKEN_HEADER).map(([, value]) => value);
11
+ : Object.entries(headers)
12
+ .filter(([name]) => name.toLowerCase() === monitoring_contract_1.FUNCTION_MONITORING_TOKEN_HEADER)
13
+ .map(([, value]) => value);
11
14
  const token = matches[0];
12
- const invalid = () => new monitoring_contract_1.FunctionMonitoringError(401, 'invalid_context', 'This invocation has no valid monitoring credential');
13
- if (matches.length !== 1 || typeof token !== 'string' || token.length > 16_384)
15
+ const invalid = () => new monitoring_contract_1.FunctionMonitoringError(401, "invalid_context", "This invocation has no valid monitoring credential");
16
+ if (matches.length !== 1 ||
17
+ typeof token !== "string" ||
18
+ token.length > 16_384)
14
19
  throw invalid();
15
20
  const envelope = /^([A-Za-z0-9_-]+)\.([A-Za-z0-9_-]{43})$/.exec(token);
16
21
  if (!envelope?.[1])
17
22
  throw invalid();
18
23
  let value;
19
24
  try {
20
- value = JSON.parse(Buffer.from(envelope[1], 'base64url').toString('utf8'));
25
+ value = JSON.parse(Buffer.from(envelope[1], "base64url").toString("utf8"));
21
26
  }
22
27
  catch {
23
28
  throw invalid();
24
29
  }
25
- const parsed = zod_1.z.object({ audience: zod_1.z.literal('atlas-managed-function-monitoring'), sub: zod_1.z.string().startsWith('service-account|'), exp: zod_1.z.number().int() }).safeParse(value);
30
+ const parsed = zod_1.z
31
+ .object({
32
+ audience: zod_1.z.literal("atlas-managed-function-monitoring"),
33
+ sub: zod_1.z.string().startsWith("service-account|"),
34
+ exp: zod_1.z.number().int(),
35
+ })
36
+ .safeParse(value);
26
37
  if (!parsed.success)
27
38
  throw invalid();
28
39
  return { token, expiresAt: parsed.data.exp };
@@ -33,46 +44,35 @@ function origin(baseUrl) {
33
44
  url = new URL(baseUrl);
34
45
  }
35
46
  catch {
36
- throw new monitoring_contract_1.FunctionMonitoringError(400, 'invalid_configuration', 'Configure a trusted Atlas origin');
47
+ throw new monitoring_contract_1.FunctionMonitoringError(400, "invalid_configuration", "Configure a trusted Atlas origin");
37
48
  }
38
- const local = url.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);
39
- if ((!local && url.protocol !== 'https:') || url.username || url.password || url.pathname !== '/' || url.search || url.hash) {
40
- throw new monitoring_contract_1.FunctionMonitoringError(400, 'invalid_configuration', 'Configure an HTTPS Atlas origin without credentials, path, query or fragment');
49
+ const local = url.protocol === "http:" &&
50
+ ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
51
+ if ((!local && url.protocol !== "https:") ||
52
+ url.username ||
53
+ url.password ||
54
+ url.pathname !== "/" ||
55
+ url.search ||
56
+ url.hash) {
57
+ throw new monitoring_contract_1.FunctionMonitoringError(400, "invalid_configuration", "Configure an HTTPS Atlas origin without credentials, path, query or fragment");
41
58
  }
42
59
  return url.origin;
43
60
  }
44
- function createFunctionServiceMonitoringClient({ request, baseUrl, fetchImpl = globalThis.fetch }) {
61
+ function createFunctionServiceMonitoringClient({ request, baseUrl, fetchImpl = globalThis.fetch, }) {
45
62
  const url = `${origin(baseUrl)}${monitoring_contract_1.FUNCTION_MONITORING_DELIVERIES_PATH}`;
46
63
  const { token, expiresAt } = credential(request);
47
- async function call(body) {
48
- if (expiresAt <= Date.now() / 1000)
49
- throw new monitoring_contract_1.FunctionMonitoringError(401, 'expired_context', 'The monitoring credential expired; start a new invocation');
50
- const input = monitoring_contract_1.functionMonitoringRequestSchema.parse(body);
51
- const response = await fetchImpl(url, {
52
- method: 'POST', headers: { 'content-type': 'application/json', [monitoring_contract_1.FUNCTION_MONITORING_TOKEN_HEADER]: token },
53
- body: JSON.stringify(input), redirect: 'error', signal: AbortSignal.timeout(30_000),
54
- });
55
- const result = await response.json().catch(() => null);
56
- if (!response.ok) {
57
- const error = zod_1.z.object({ code: zod_1.z.string().max(128).optional(), detail: zod_1.z.string().max(2000).optional() }).safeParse(result);
58
- throw new monitoring_contract_1.FunctionMonitoringError(response.status, error.success ? (error.data.code ?? 'monitoring_failed') : 'monitoring_failed', error.success ? (error.data.detail ?? 'Monitoring delivery failed') : 'Monitoring delivery failed');
59
- }
60
- return result;
61
- }
62
- async function delivery(input, operation) {
63
- const validated = monitoring_contract_1.monitoringDeliveryReceiptSchema.safeParse(await call({ ...input, operation }));
64
- if (!validated.success || validated.data.producer !== input.producer || validated.data.businessKey !== input.businessKey || ('payloadHash' in input && validated.data.payloadHash !== input.payloadHash) || ('events' in input && validated.data.eventCount !== input.events.length)) {
65
- throw new monitoring_contract_1.FunctionMonitoringError(502, 'malformed_response', 'Atlas returned an invalid monitoring receipt');
66
- }
67
- return validated.data;
68
- }
69
- return {
70
- publish: input => delivery(input, 'publish'), get: input => delivery(input, 'get'),
71
- async getBucketCatalog(input) {
72
- const validated = monitoring_contract_1.monitoringBucketCatalogSchema.safeParse(await call({ ...input, operation: 'getBucketCatalog' }));
73
- if (!validated.success || validated.data.producer !== input.producer)
74
- throw new monitoring_contract_1.FunctionMonitoringError(502, 'malformed_response', 'Atlas returned an invalid monitoring catalog');
75
- return validated.data;
64
+ const send = (0, adapters_1.createInvocationDomainTransport)({
65
+ baseUrl,
66
+ fetchImpl,
67
+ domain: "monitoring",
68
+ credentials: [
69
+ { header: monitoring_contract_1.FUNCTION_MONITORING_TOKEN_HEADER, token, expiresAt },
70
+ ],
71
+ error: (status, code, message) => new monitoring_contract_1.FunctionMonitoringError(status, code, message),
72
+ failure: {
73
+ code: "monitoring_failed",
74
+ message: "Monitoring delivery failed",
76
75
  },
77
- };
76
+ });
77
+ return (0, adapters_1.createMonitoringDeliveryClient)({ send });
78
78
  }
package/dist/orm.d.ts CHANGED
@@ -82,6 +82,14 @@ interface ReadReceiptOperationExecutor extends OperationExecutor {
82
82
  }
83
83
  /** Additive factories preserve existing host wrappers without receipt support. */
84
84
  type ReadReceiptSqlOperationExecutor = SqlOperationExecutor & ReadReceiptOperationExecutor;
85
+ /**
86
+ * How a string selector reaches the server. `hash` (the default) resolves the
87
+ * name through the manifest and sends the hash, pinning the exact contract the
88
+ * caller was generated against. `name` sends the name itself, resolved by the
89
+ * server against the namespace's active version when the request runs, so the
90
+ * caller survives the rehash every schema change causes and needs no manifest.
91
+ */
92
+ type OperationSelection = 'hash' | 'name';
85
93
 
86
94
  declare const FUNCTION_CALLER_DATA_TOKEN_HEADER = "x-sequence-caller-data-token";
87
95
 
@@ -101,6 +109,7 @@ interface FunctionOrmExecutorOptions {
101
109
  request: FunctionOrmRequest;
102
110
  baseUrl: string;
103
111
  namespace: string;
112
+ operationSelection?: OperationSelection;
104
113
  manifest?: unknown;
105
114
  fetchImpl?: typeof globalThis.fetch;
106
115
  jsonScalars?: FunctionOrmJsonScalars;
@@ -109,4 +118,4 @@ declare function createFunctionOrmExecutor({ request, fetchImpl, ...options }: F
109
118
  declare function createFunctionCallerOrmExecutor({ request, fetchImpl, ...options }: FunctionOrmExecutorOptions): ReadReceiptSqlOperationExecutor;
110
119
  declare function createFunctionServiceOrmExecutor({ request, fetchImpl, ...options }: FunctionOrmExecutorOptions): ReadReceiptSqlOperationExecutor;
111
120
 
112
- export { FUNCTION_CALLER_DATA_TOKEN_HEADER, FunctionOrmError, type FunctionOrmErrorCode, type FunctionOrmExecutorOptions, type FunctionOrmJsonScalars, type FunctionOrmRequest, ORM_JSON_SCALARS_HEADER, ORM_LOSSLESS_JSON_SCALARS, type OperationExecutor, type OperationReadReceipt, type OperationsManifest, OrmClientError, OrmOperationError, type ReadReceiptSqlOperationExecutor, type SqlOperationExecutor, createFunctionCallerOrmExecutor, createFunctionOrmExecutor, createFunctionServiceOrmExecutor };
121
+ export { FUNCTION_CALLER_DATA_TOKEN_HEADER, FunctionOrmError, type FunctionOrmErrorCode, type FunctionOrmExecutorOptions, type FunctionOrmJsonScalars, type FunctionOrmRequest, ORM_JSON_SCALARS_HEADER, ORM_LOSSLESS_JSON_SCALARS, type OperationExecutor, type OperationReadReceipt, type OperationSelection, type OperationsManifest, OrmClientError, OrmOperationError, type ReadReceiptSqlOperationExecutor, type SqlOperationExecutor, createFunctionCallerOrmExecutor, createFunctionOrmExecutor, createFunctionServiceOrmExecutor };
package/dist/orm.js CHANGED
@@ -127,6 +127,13 @@ function createReadReceiptOperationResolver({ operations }) {
127
127
  };
128
128
  }
129
129
  var operationHash = /^sha256:[a-f0-9]{64}$/;
130
+ var operationName = /^[_A-Za-z][_0-9A-Za-z]{0,254}$/;
131
+ function refusedAsUnknownSelector(response) {
132
+ if (response.status !== 404 || !isRecord(response.body) || !Array.isArray(response.body.errors)) return false;
133
+ const first = response.body.errors[0];
134
+ const extensions = isRecord(first) && isRecord(first.extensions) ? first.extensions : void 0;
135
+ return extensions?.code === "NOT_FOUND" && !(isRecord(extensions.details) && extensions.details.cause === "unknown_operation") && isRecord(first) && typeof first.message === "string" && first.message.startsWith("operation not found");
136
+ }
130
137
  function readManifestHashes(manifest) {
131
138
  if (!isRecord(manifest) || typeof manifest.schemaHash !== "string" || !manifest.schemaHash || !isRecord(manifest.operations)) {
132
139
  throw new OrmClientError("invalid operations manifest \u2014 use operations.manifest.json from seq-studio orm generate");
@@ -140,26 +147,37 @@ function readManifestHashes(manifest) {
140
147
  }
141
148
  return hashes;
142
149
  }
143
- function createOperationExecutorWithTransport({ namespace, manifest, transport }) {
150
+ function createOperationExecutorWithTransport({ namespace, manifest, transport, operationSelection = "hash" }) {
151
+ if (operationSelection !== "hash" && operationSelection !== "name") throw new OrmClientError("operationSelection must be 'hash' or 'name'");
144
152
  if (typeof namespace !== "string" || !NAMESPACE_PATTERN.test(namespace)) throw new OrmClientError("invalid ORM namespace \u2014 expected a lowercase identifier of at most 41 characters");
145
153
  const hashes = manifest === void 0 ? /* @__PURE__ */ new Map() : readManifestHashes(manifest);
146
154
  const knownHashes = new Set([...hashes.values()].map((entry) => entry.hash));
147
155
  const resolveReceiptOperation = createReadReceiptOperationResolver({ operations: hashes });
156
+ function selectTarget({ op, requireReadReceipt }) {
157
+ const selector = typeof op === "string" ? op : op.hash;
158
+ if (operationSelection === "name" && !requireReadReceipt && typeof op === "string" && operationName.test(op)) {
159
+ return { target: op, byName: true };
160
+ }
161
+ const hash = requireReadReceipt ? resolveReceiptOperation({ selector, hashOnly: typeof op !== "string" }) : selector === BUILTIN_SQL_READ_HASH ? selector : hashes.get(selector)?.hash ?? (knownHashes.has(selector) ? selector : void 0);
162
+ if (!hash) throw new OrmClientError(`unknown operation "${String(op)}" \u2014 not in the manifest (${hashes.size} known). Re-run seq-studio orm generate.`);
163
+ return { target: hash, byName: false };
164
+ }
148
165
  async function request({ op, variables, options, requireReadReceipt = false }) {
149
166
  validateIdempotencyKey(options.idempotencyKey);
150
167
  validateExpectedSourceGeneration(options.expectedSourceGeneration);
151
168
  if (typeof op !== "string" && op.namespace !== namespace) throw new OrmClientError("operation belongs to a different namespace");
152
- const selector = typeof op === "string" ? op : op.hash;
153
- const hash = requireReadReceipt ? resolveReceiptOperation({ selector, hashOnly: typeof op !== "string" }) : selector === BUILTIN_SQL_READ_HASH ? selector : hashes.get(selector)?.hash ?? (knownHashes.has(selector) ? selector : void 0);
154
- if (!hash) throw new OrmClientError(`unknown operation "${op}" \u2014 not in the manifest (${hashes.size} known). Re-run seq-studio orm generate.`);
169
+ const { target: hash, byName } = selectTarget({ op, requireReadReceipt });
155
170
  if (!isRecord(variables)) throw new OrmClientError("operation variables must be an object");
156
- const response = await transport({
171
+ const send = (target) => transport({
157
172
  namespace,
158
- op: hash,
173
+ op: target,
159
174
  variables,
160
175
  ...options.idempotencyKey === void 0 ? {} : { idempotencyKey: options.idempotencyKey },
161
176
  ...options.expectedSourceGeneration === void 0 ? {} : { expectedSourceGeneration: options.expectedSourceGeneration }
162
177
  });
178
+ let response = await send(hash);
179
+ const fallback = byName && typeof op === "string" ? hashes.get(op)?.hash : void 0;
180
+ if (fallback && response && refusedAsUnknownSelector(response)) response = await send(fallback);
163
181
  if (!response || typeof response.ok !== "boolean" || !Number.isInteger(response.status) || response.status < 100 || response.status > 599 || response.ok !== (response.status >= 200 && response.status < 300)) {
164
182
  throw new OrmOperationError("malformed transport response", null, null);
165
183
  }
@@ -284,6 +302,7 @@ function createExecutor({
284
302
  baseUrl,
285
303
  namespace,
286
304
  manifest,
305
+ operationSelection = "name",
287
306
  fetchImpl,
288
307
  token,
289
308
  header,
@@ -301,6 +320,7 @@ function createExecutor({
301
320
  return createOperationExecutorWithTransport({
302
321
  namespace,
303
322
  manifest,
323
+ operationSelection,
304
324
  transport: async ({ namespace: targetNamespace, op, variables, idempotencyKey, expectedSourceGeneration }) => {
305
325
  requireUnexpired({ expiresAt });
306
326
  const response = await fetchImpl(`${origin}/_data/v2/${targetNamespace}`, {
@@ -360,7 +380,7 @@ function createFunctionServiceOrmExecutor({
360
380
  const token = readToken({
361
381
  request,
362
382
  header: ORM_SERVICE_DATA_TOKEN_HEADER,
363
- missing: "Service ORM access is unavailable. Declare service_account and the data binding in managed-function.yml and invoke the function through the platform."
383
+ missing: "Service ORM access is unavailable. Set `service: true` on the namespace under capabilities.data, name a service_account in managed-function.yml, and invoke the function through the platform."
364
384
  });
365
385
  return createExecutor({ ...options, fetchImpl, token, header: ORM_SERVICE_DATA_TOKEN_HEADER, expiresAt: serviceExpiry({ token }) });
366
386
  }