@sequenceholdings/managed-functions 0.4.1 → 0.4.2
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.
- package/README.md +374 -2
- package/dist/abrigo-contract.d.ts +92 -0
- package/dist/abrigo-contract.js +55 -0
- package/dist/abrigo-response.d.ts +6 -0
- package/dist/abrigo-response.js +27 -0
- package/dist/abrigo.d.ts +14 -0
- package/dist/abrigo.js +150 -0
- package/dist/agent-evidence.d.ts +9 -0
- package/dist/agent-evidence.js +84 -0
- package/dist/agent-source-evidence-contract.d.ts +1197 -0
- package/dist/agent-source-evidence-contract.js +96 -0
- package/dist/agents-contract.d.ts +99 -0
- package/dist/agents-contract.js +69 -0
- package/dist/agents.d.ts +15 -0
- package/dist/agents.js +121 -0
- package/dist/capabilities.d.ts +150 -0
- package/dist/capabilities.js +58 -5
- package/dist/config.d.ts +17 -2
- package/dist/config.js +55 -1
- package/dist/deployed-policy.js +90 -2
- package/dist/directory-config.js +1 -1
- package/dist/directory-contract.d.ts +68 -0
- package/dist/directory-contract.js +57 -0
- package/dist/directory-manifest.d.ts +5 -0
- package/dist/directory-manifest.js +10 -0
- package/dist/http-tracing.js +3 -0
- package/dist/immutable-release-contract.d.ts +3 -0
- package/dist/immutable-release-contract.js +12 -0
- package/dist/index.d.ts +37 -1
- package/dist/index.js +72 -1
- package/dist/invocation-client.d.ts +8 -1
- package/dist/invocation-client.js +8 -3
- package/dist/invocation-contract.d.ts +36 -0
- package/dist/invocation-contract.js +48 -0
- package/dist/invocation.d.ts +8 -0
- package/dist/invocation.js +134 -0
- package/dist/lattice-capability.d.ts +5 -0
- package/dist/lattice-capability.js +16 -0
- package/dist/lattice-provenance-contract.d.ts +519 -0
- package/dist/lattice-provenance-contract.js +148 -0
- package/dist/lattice-provenance.d.ts +16 -0
- package/dist/lattice-provenance.js +167 -0
- package/dist/monitoring-annotations.d.ts +53 -0
- package/dist/monitoring-annotations.js +54 -0
- package/dist/monitoring-contract.d.ts +463 -0
- package/dist/monitoring-contract.js +89 -0
- package/dist/monitoring-events.d.ts +257 -0
- package/dist/monitoring-events.js +136 -0
- package/dist/monitoring.d.ts +14 -0
- package/dist/monitoring.js +78 -0
- package/dist/orm-contract.d.ts +1 -0
- package/dist/orm-contract.js +4 -0
- package/dist/orm.d.ts +19 -3
- package/dist/orm.js +93 -13
- package/dist/preflight-abrigo.d.ts +10 -0
- package/dist/preflight-abrigo.js +26 -0
- package/dist/preflight-agents.d.ts +10 -0
- package/dist/preflight-agents.js +51 -0
- package/dist/preflight-immutable-release.d.ts +10 -0
- package/dist/preflight-immutable-release.js +34 -0
- package/dist/preflight-invocation.d.ts +10 -0
- package/dist/preflight-invocation.js +40 -0
- package/dist/preflight-lattice.d.ts +10 -0
- package/dist/preflight-lattice.js +40 -0
- package/dist/preflight-monitoring.d.ts +10 -0
- package/dist/preflight-monitoring.js +46 -0
- package/dist/preflight-service-directory.d.ts +10 -0
- package/dist/preflight-service-directory.js +26 -0
- package/dist/preflight-workflows.d.ts +10 -0
- package/dist/preflight-workflows.js +38 -0
- package/dist/preflight.js +49 -5
- package/dist/processes-contract.d.ts +20 -0
- package/dist/processes-contract.js +8 -1
- package/dist/processes.d.ts +2 -1
- package/dist/processes.js +34 -0
- package/dist/runtime.cjs +3111 -214
- package/dist/sdk-range.d.ts +1 -0
- package/dist/sdk-range.js +25 -0
- package/dist/service-directory.d.ts +12 -0
- package/dist/service-directory.js +72 -0
- package/dist/workflow-scopes-contract.d.ts +8 -0
- package/dist/workflow-scopes-contract.js +29 -0
- package/dist/workflow-source-contract.d.ts +524 -0
- package/dist/workflow-source-contract.js +59 -0
- package/dist/workflow-source.d.ts +12 -0
- package/dist/workflow-source.js +93 -0
- package/package.json +2 -2
|
@@ -0,0 +1,257 @@
|
|
|
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>;
|
|
253
|
+
export declare function contentHashKey(parts: ReadonlyArray<string | number>): string;
|
|
254
|
+
export declare function scopedIdempotencyKey(args: {
|
|
255
|
+
scope: string;
|
|
256
|
+
parts: ReadonlyArray<string | number>;
|
|
257
|
+
}): string;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.emitDeltaEventsBodySchema = exports.MAX_DELTA_EVENTS_PER_REQUEST = exports.deltaEventSchema = exports.docExtractEditContextSchema = exports.dtiDeltaContextSchema = exports.artifactDeltaContextSchema = exports.PRODUCER_EVENT_KEY_PREFIX = exports.MAX_CONTEXT_JSON_CHARS = exports.MAX_SCALAR_STRING_CHARS = exports.MAX_CONTEXT_TEXT_CHARS = void 0;
|
|
4
|
+
exports.contentHashKey = contentHashKey;
|
|
5
|
+
exports.scopedIdempotencyKey = scopedIdempotencyKey;
|
|
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
|
+
});
|
|
131
|
+
function contentHashKey(parts) {
|
|
132
|
+
return (0, node_crypto_1.createHash)('sha256').update(parts.join('|')).digest('hex').slice(0, 16);
|
|
133
|
+
}
|
|
134
|
+
function scopedIdempotencyKey(args) {
|
|
135
|
+
return `${args.scope}:${contentHashKey(args.parts)}`;
|
|
136
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type MonitoringCatalogQuery, type MonitoringBucketCatalog, type MonitoringDeliveryKey, type MonitoringDeliveryReceipt, type MonitoringPublish } from './monitoring-contract';
|
|
2
|
+
export interface FunctionServiceMonitoringOptions {
|
|
3
|
+
request: {
|
|
4
|
+
headers: Pick<Headers, 'get'> | Readonly<Record<string, string | readonly string[] | undefined>>;
|
|
5
|
+
};
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
fetchImpl?: typeof globalThis.fetch;
|
|
8
|
+
}
|
|
9
|
+
export interface FunctionServiceMonitoringClient {
|
|
10
|
+
publish(input: MonitoringPublish): Promise<MonitoringDeliveryReceipt>;
|
|
11
|
+
get(input: MonitoringDeliveryKey): Promise<MonitoringDeliveryReceipt>;
|
|
12
|
+
getBucketCatalog(input: MonitoringCatalogQuery): Promise<MonitoringBucketCatalog>;
|
|
13
|
+
}
|
|
14
|
+
export declare function createFunctionServiceMonitoringClient({ request, baseUrl, fetchImpl }: FunctionServiceMonitoringOptions): FunctionServiceMonitoringClient;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFunctionServiceMonitoringClient = createFunctionServiceMonitoringClient;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const monitoring_contract_1 = require("./monitoring-contract");
|
|
6
|
+
function credential(request) {
|
|
7
|
+
const headers = request.headers;
|
|
8
|
+
const matches = typeof headers.get === 'function'
|
|
9
|
+
? [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
|
+
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)
|
|
14
|
+
throw invalid();
|
|
15
|
+
const envelope = /^([A-Za-z0-9_-]+)\.([A-Za-z0-9_-]{43})$/.exec(token);
|
|
16
|
+
if (!envelope?.[1])
|
|
17
|
+
throw invalid();
|
|
18
|
+
let value;
|
|
19
|
+
try {
|
|
20
|
+
value = JSON.parse(Buffer.from(envelope[1], 'base64url').toString('utf8'));
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
throw invalid();
|
|
24
|
+
}
|
|
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);
|
|
26
|
+
if (!parsed.success)
|
|
27
|
+
throw invalid();
|
|
28
|
+
return { token, expiresAt: parsed.data.exp };
|
|
29
|
+
}
|
|
30
|
+
function origin(baseUrl) {
|
|
31
|
+
let url;
|
|
32
|
+
try {
|
|
33
|
+
url = new URL(baseUrl);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
throw new monitoring_contract_1.FunctionMonitoringError(400, 'invalid_configuration', 'Configure a trusted Atlas origin');
|
|
37
|
+
}
|
|
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');
|
|
41
|
+
}
|
|
42
|
+
return url.origin;
|
|
43
|
+
}
|
|
44
|
+
function createFunctionServiceMonitoringClient({ request, baseUrl, fetchImpl = globalThis.fetch }) {
|
|
45
|
+
const url = `${origin(baseUrl)}${monitoring_contract_1.FUNCTION_MONITORING_DELIVERIES_PATH}`;
|
|
46
|
+
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;
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const FUNCTION_CALLER_DATA_TOKEN_HEADER = "x-sequence-caller-data-token";
|
package/dist/orm.d.ts
CHANGED
|
@@ -56,6 +56,8 @@ interface OperationsManifest {
|
|
|
56
56
|
interface OperationExecutionOptions {
|
|
57
57
|
/** Reuse only when retrying the same logical mutation. */
|
|
58
58
|
idempotencyKey?: string;
|
|
59
|
+
/** Require the same source publication as an earlier read receipt. */
|
|
60
|
+
expectedSourceGeneration?: string;
|
|
59
61
|
}
|
|
60
62
|
interface OperationExecutor {
|
|
61
63
|
/** Execute a manifest operation by name (or a raw `sha256:` hash). */
|
|
@@ -66,6 +68,19 @@ interface SqlOperationExecutor extends OperationExecutor {
|
|
|
66
68
|
/** Default read-only ontology SQL; no authored operation or manifest needed. */
|
|
67
69
|
sql(variables: SqlQueryVariables): Promise<SqlQueryResult>;
|
|
68
70
|
}
|
|
71
|
+
interface OperationReadReceipt<TData> {
|
|
72
|
+
readonly data: TData;
|
|
73
|
+
/** Opaque source-publication identity; never an authorization credential. */
|
|
74
|
+
readonly sourceGeneration: string;
|
|
75
|
+
}
|
|
76
|
+
interface ReadReceiptOperationExecutor extends OperationExecutor {
|
|
77
|
+
/** Execute a registered query or built-in SQL read; fail closed without a receipt. */
|
|
78
|
+
executeWithReadReceipt<TData = Record<string, unknown>>(op: string, variables?: Record<string, unknown>, options?: OperationExecutionOptions): Promise<OperationReadReceipt<TData>>;
|
|
79
|
+
}
|
|
80
|
+
/** Additive factories preserve existing host wrappers without receipt support. */
|
|
81
|
+
type ReadReceiptSqlOperationExecutor = SqlOperationExecutor & ReadReceiptOperationExecutor;
|
|
82
|
+
|
|
83
|
+
declare const FUNCTION_CALLER_DATA_TOKEN_HEADER = "x-sequence-caller-data-token";
|
|
69
84
|
|
|
70
85
|
type FunctionOrmErrorCode = 'INVALID_CONFIGURATION' | 'MISSING_CALLER_CONTEXT' | 'INVALID_CALLER_CONTEXT' | 'UNSUPPORTED_CALLER' | 'EXPIRED_CALLER_CONTEXT';
|
|
71
86
|
declare class FunctionOrmError extends Error {
|
|
@@ -87,7 +102,8 @@ interface FunctionOrmExecutorOptions {
|
|
|
87
102
|
fetchImpl?: typeof globalThis.fetch;
|
|
88
103
|
jsonScalars?: FunctionOrmJsonScalars;
|
|
89
104
|
}
|
|
90
|
-
declare function createFunctionOrmExecutor({ request, fetchImpl, ...options }: FunctionOrmExecutorOptions):
|
|
91
|
-
declare function
|
|
105
|
+
declare function createFunctionOrmExecutor({ request, fetchImpl, ...options }: FunctionOrmExecutorOptions): ReadReceiptSqlOperationExecutor;
|
|
106
|
+
declare function createFunctionCallerOrmExecutor({ request, fetchImpl, ...options }: FunctionOrmExecutorOptions): ReadReceiptSqlOperationExecutor;
|
|
107
|
+
declare function createFunctionServiceOrmExecutor({ request, fetchImpl, ...options }: FunctionOrmExecutorOptions): ReadReceiptSqlOperationExecutor;
|
|
92
108
|
|
|
93
|
-
export { FunctionOrmError, type FunctionOrmErrorCode, type FunctionOrmExecutorOptions, type FunctionOrmJsonScalars, type FunctionOrmRequest, ORM_JSON_SCALARS_HEADER, ORM_LOSSLESS_JSON_SCALARS, type OperationExecutor, type OperationsManifest, OrmClientError, OrmOperationError, type SqlOperationExecutor, createFunctionOrmExecutor, createFunctionServiceOrmExecutor };
|
|
109
|
+
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 };
|