@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.
- package/README.md +147 -12
- package/dist/abrigo-contract.d.ts +2 -92
- package/dist/abrigo-contract.js +12 -53
- package/dist/abrigo-response.d.ts +1 -6
- package/dist/abrigo-response.js +3 -25
- package/dist/abrigo.d.ts +5 -5
- package/dist/abrigo.js +66 -92
- package/dist/agent-evidence.d.ts +5 -5
- package/dist/agent-evidence.js +58 -48
- package/dist/agent-source-evidence-contract.d.ts +2 -1197
- package/dist/agent-source-evidence-contract.js +24 -94
- package/dist/agents-contract.d.ts +2 -99
- package/dist/agents-contract.js +13 -67
- package/dist/agents.d.ts +5 -5
- package/dist/agents.js +79 -44
- package/dist/capabilities.d.ts +1 -1
- package/dist/capabilities.js +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.js +4 -1
- package/dist/directory-config.d.ts +1 -23
- package/dist/directory-config.js +8 -20
- package/dist/directory-contract.d.ts +2 -68
- package/dist/directory-contract.js +13 -55
- package/dist/directory-roster-contract.d.ts +2 -22
- package/dist/directory-roster-contract.js +7 -22
- package/dist/directory.d.ts +4 -8
- package/dist/directory.js +15 -33
- package/dist/group-roster-access.d.ts +7 -0
- package/dist/group-roster-access.js +8 -0
- package/dist/index.d.ts +49 -46
- package/dist/index.js +8 -1
- package/dist/invocation-client.d.ts +4 -4
- package/dist/invocation-client.js +32 -60
- package/dist/invocation-contract.d.ts +2 -59
- package/dist/invocation-contract.js +10 -61
- package/dist/invocation.d.ts +4 -4
- package/dist/invocation.js +42 -63
- package/dist/lattice-provenance-contract.d.ts +2 -607
- package/dist/lattice-provenance-contract.js +14 -154
- package/dist/lattice-provenance.d.ts +3 -3
- package/dist/lattice-provenance.js +46 -97
- package/dist/monitoring-annotations.d.ts +2 -53
- package/dist/monitoring-annotations.js +2 -51
- package/dist/monitoring-contract.d.ts +5 -460
- package/dist/monitoring-contract.js +37 -77
- package/dist/monitoring-events.d.ts +2 -252
- package/dist/monitoring-events.js +15 -125
- package/dist/monitoring.d.ts +3 -3
- package/dist/monitoring.js +41 -41
- package/dist/orm.d.ts +10 -1
- package/dist/orm.js +27 -7
- package/dist/platform-client.d.ts +27 -0
- package/dist/platform-client.js +79 -0
- package/dist/platform-domains.d.ts +1671 -0
- package/dist/platform-domains.js +77 -0
- package/dist/processes-contract.d.ts +2 -149
- package/dist/processes-contract.js +17 -100
- package/dist/processes.d.ts +3 -3
- package/dist/processes.js +64 -49
- package/dist/runtime.cjs +4251 -1666
- package/dist/service-directory-roster.d.ts +12 -3
- package/dist/service-directory-roster.js +11 -17
- package/dist/service-directory.d.ts +4 -8
- package/dist/service-directory.js +16 -67
- package/dist/storage.d.ts +36 -35
- package/dist/storage.js +12 -5
- package/dist/workflow-source-contract.d.ts +2 -524
- package/dist/workflow-source-contract.js +16 -56
- package/dist/workflow-source.d.ts +3 -3
- package/dist/workflow-source.js +106 -43
- package/package.json +4 -3
|
@@ -1,157 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FunctionLatticeContextError = exports.functionLatticeParallelSnapshotSchema = exports.functionLatticeHumanCompletionsPageSchema = exports.functionLatticeHumanCompletionSchema = exports.functionLatticeExecutionContextSchema = exports.functionLatticeRunCreatorAccessSchema = exports.functionLatticeContextRequestSchema = exports.functionLatticeParallelSnapshotQuerySchema = exports.functionLatticeHumanCompletionsQuerySchema = exports.functionLatticeHumanCompletionQuerySchema = exports.functionLatticeStartProvenanceSchema = exports.FUNCTION_LATTICE_CONTEXT_PATH = exports.FUNCTION_LATTICE_EXECUTION_TOKEN_HEADER = void 0;
|
|
4
|
-
|
|
5
|
-
exports.FUNCTION_LATTICE_EXECUTION_TOKEN_HEADER
|
|
6
|
-
exports.FUNCTION_LATTICE_CONTEXT_PATH
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
exports
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
actorSub: principal, startedBy: principal.nullable(),
|
|
19
|
-
mode: zod_1.z.enum(['manual', 'trigger', 'schedule', 'system', 'subprocess', 'intervention']),
|
|
20
|
-
basis: zod_1.z.enum(['fga_invoker', 'schedule_author', 'schedule_no_author', 'trusted_service', 'trusted_trigger', 'subprocess_spawn_gate', 'subprocess_parent_starter', 'subprocess_existing_child', 'intervention_actor']),
|
|
21
|
-
authorizedAt: zod_1.z.iso.datetime(), schedule: zod_1.z.strictObject({ scheduleId: identifier, scheduledAt: zod_1.z.iso.datetime() }).nullable(),
|
|
22
|
-
}).refine((value) => startBasisByMode[value.mode].includes(value.basis) && (value.mode === 'schedule') === (value.schedule !== null), 'Start basis and schedule must match the verified authorization mode');
|
|
23
|
-
exports.functionLatticeHumanCompletionQuerySchema = zod_1.z.strictObject({
|
|
24
|
-
nodeId: identifier,
|
|
25
|
-
stepId: identifier.optional(),
|
|
26
|
-
ancestorNodeId: identifier.optional(),
|
|
27
|
-
});
|
|
28
|
-
exports.functionLatticeHumanCompletionsQuerySchema = exports.functionLatticeHumanCompletionQuerySchema.omit({ stepId: true });
|
|
29
|
-
exports.functionLatticeParallelSnapshotQuerySchema = zod_1.z.strictObject({ nodeId: identifier, ancestorNodeId: identifier });
|
|
30
|
-
exports.functionLatticeContextRequestSchema = zod_1.z.discriminatedUnion('operation', [
|
|
31
|
-
zod_1.z.strictObject({ operation: zod_1.z.literal('getExecutionContext') }),
|
|
32
|
-
zod_1.z.strictObject({ operation: zod_1.z.literal('getRunCreatorAccess') }),
|
|
33
|
-
exports.functionLatticeHumanCompletionQuerySchema.extend({
|
|
34
|
-
operation: zod_1.z.literal('getHumanCompletion'),
|
|
35
|
-
}),
|
|
36
|
-
exports.functionLatticeHumanCompletionsQuerySchema.extend({
|
|
37
|
-
operation: zod_1.z.literal('getHumanCompletions'),
|
|
38
|
-
}),
|
|
39
|
-
exports.functionLatticeParallelSnapshotQuerySchema.extend({ operation: zod_1.z.literal('getParallelSnapshot') }),
|
|
40
|
-
]);
|
|
41
|
-
const executionIdentity = zod_1.z.object({
|
|
42
|
-
receiverFunctionOrgId: identifier,
|
|
43
|
-
parent: zod_1.z.object({ runId: identifier, processId: identifier, processVersion: identifier, bundleHash: identifier, stepId: identifier, nodeId: identifier, attempt, input: zod_1.z.unknown(), branch: zod_1.z.object({ id: identifier, index: zod_1.z.number().int().nonnegative(), item: zod_1.z.unknown() }).nullable() }).nullable().optional(),
|
|
44
|
-
run: zod_1.z.object({
|
|
45
|
-
id: identifier,
|
|
46
|
-
processId: identifier,
|
|
47
|
-
processVersion: identifier,
|
|
48
|
-
bundleHash: identifier,
|
|
49
|
-
entity: zod_1.z.object({ type: identifier, id: identifier }).nullable(),
|
|
50
|
-
startProvenance: exports.functionLatticeStartProvenanceSchema.nullable().optional(),
|
|
51
|
-
}).refine((run) => !run.startProvenance || (run.startProvenance.runId === run.id && run.startProvenance.processId === run.processId && run.startProvenance.processVersion === run.processVersion && run.startProvenance.bundleHash === run.bundleHash), 'Start provenance must identify the exact executing run'),
|
|
52
|
-
step: zod_1.z.object({
|
|
53
|
-
id: identifier,
|
|
54
|
-
nodeId: identifier,
|
|
55
|
-
attempt,
|
|
56
|
-
runAsServiceAccount: principal.nullable(),
|
|
57
|
-
}),
|
|
58
|
-
receiver: zod_1.z.object({
|
|
59
|
-
functionId: identifier,
|
|
60
|
-
versionId: identifier,
|
|
61
|
-
invocationId: identifier,
|
|
62
|
-
invoker: zod_1.z.object({ sub: principal, kind: identifier, authenticationMethod: identifier }),
|
|
63
|
-
attachedServiceAccountSub: principal,
|
|
64
|
-
}),
|
|
65
|
-
});
|
|
66
|
-
exports.functionLatticeRunCreatorAccessSchema = executionIdentity.extend({
|
|
67
|
-
creator: zod_1.z.strictObject({
|
|
68
|
-
sub: principal,
|
|
69
|
-
tenant: zod_1.z.string().min(1).max(64).nullable(),
|
|
70
|
-
platformOperator: zod_1.z.boolean(),
|
|
71
|
-
}).nullable(),
|
|
72
|
-
observedAt: zod_1.z.iso.datetime({ offset: true }),
|
|
73
|
-
});
|
|
74
|
-
exports.functionLatticeExecutionContextSchema = executionIdentity.extend({
|
|
75
|
-
input: zod_1.z.unknown(),
|
|
76
|
-
ctxSnapshot: zod_1.z.object({
|
|
77
|
-
entity: zod_1.z.unknown(),
|
|
78
|
-
upstream: record,
|
|
79
|
-
state: record,
|
|
80
|
-
run: zod_1.z.object({
|
|
81
|
-
id: identifier,
|
|
82
|
-
process_id: identifier,
|
|
83
|
-
version: identifier,
|
|
84
|
-
started_at: zod_1.z.iso.datetime({ offset: true }),
|
|
85
|
-
started_by: principal.nullable(),
|
|
86
|
-
metadata: record,
|
|
87
|
-
trigger_reason: record.nullable().optional(),
|
|
88
|
-
}),
|
|
89
|
-
branch: zod_1.z.object({ id: identifier, index: zod_1.z.number().int().nonnegative(), item: zod_1.z.unknown() }).optional(),
|
|
90
|
-
}),
|
|
91
|
-
}).refine((value) => value.ctxSnapshot.run.id === value.run.id &&
|
|
92
|
-
value.ctxSnapshot.run.process_id === value.run.processId &&
|
|
93
|
-
value.ctxSnapshot.run.version === value.run.processVersion, 'The context snapshot must identify the executing run');
|
|
94
|
-
exports.functionLatticeHumanCompletionSchema = executionIdentity.extend({
|
|
95
|
-
human: zod_1.z.object({
|
|
96
|
-
receipt: zod_1.z.string().min(1).max(16_384),
|
|
97
|
-
runId: identifier,
|
|
98
|
-
processId: identifier,
|
|
99
|
-
bundleHash: identifier,
|
|
100
|
-
actorSub: principal,
|
|
101
|
-
receiptId: identifier,
|
|
102
|
-
stepId: identifier,
|
|
103
|
-
nodeId: identifier,
|
|
104
|
-
attempt,
|
|
105
|
-
edgeId: identifier.nullable(),
|
|
106
|
-
payload: record,
|
|
107
|
-
completedAt: zod_1.z.iso.datetime({ offset: true }),
|
|
108
|
-
ancestor: zod_1.z.object({
|
|
109
|
-
runId: identifier,
|
|
110
|
-
processId: identifier,
|
|
111
|
-
bundleHash: identifier,
|
|
112
|
-
stepId: identifier,
|
|
113
|
-
nodeId: identifier,
|
|
114
|
-
attempt,
|
|
115
|
-
}).optional(),
|
|
116
|
-
}),
|
|
117
|
-
}).refine((value) => value.human.receiptId === value.human.stepId, 'The receipt identifier must be the actual human step identifier');
|
|
118
|
-
exports.functionLatticeHumanCompletionsPageSchema = zod_1.z.object({
|
|
119
|
-
completions: zod_1.z.array(exports.functionLatticeHumanCompletionSchema).max(64),
|
|
120
|
-
});
|
|
121
|
-
const parallelHumanStep = zod_1.z.object({ runId: identifier, stepId: identifier, nodeId: identifier, attempt, receiptId: identifier });
|
|
122
|
-
exports.functionLatticeParallelSnapshotSchema = executionIdentity.extend({
|
|
123
|
-
parallel: zod_1.z.object({
|
|
124
|
-
runId: identifier, processId: identifier, processVersion: identifier, bundleHash: identifier,
|
|
125
|
-
entity: zod_1.z.object({ type: identifier, id: identifier }).nullable(),
|
|
126
|
-
stepId: identifier, nodeId: identifier, attempt, status: zod_1.z.literal('completed'),
|
|
127
|
-
observedAt: zod_1.z.iso.datetime({ offset: true }), proof: zod_1.z.string().min(1).max(131_072),
|
|
128
|
-
ancestor: zod_1.z.object({ runId: identifier, processId: identifier, bundleHash: identifier, stepId: identifier, nodeId: identifier, attempt, receipt: zod_1.z.string().min(1).max(16_384), receiptId: identifier }),
|
|
129
|
-
branches: zod_1.z.array(zod_1.z.object({
|
|
130
|
-
branchId: identifier, branchIndex: zod_1.z.number().int().nonnegative(), item: zod_1.z.unknown(),
|
|
131
|
-
stepId: identifier, nodeId: identifier, attempt,
|
|
132
|
-
status: zod_1.z.enum(['pending', 'running', 'completed', 'failed', 'cancelled', 'timed_out']),
|
|
133
|
-
joinStatus: zod_1.z.enum(['pending', 'completed', 'failed', 'cancelled', 'timed_out']), humanStep: parallelHumanStep.nullable(),
|
|
134
|
-
})).max(64),
|
|
135
|
-
}),
|
|
136
|
-
}).refine((value) => {
|
|
137
|
-
const branches = value.parallel.branches;
|
|
138
|
-
return value.parallel.runId === value.run.id && value.parallel.bundleHash === value.run.bundleHash &&
|
|
139
|
-
value.parallel.processId === value.run.processId && value.parallel.processVersion === value.run.processVersion &&
|
|
140
|
-
value.parallel.entity?.id === value.run.entity?.id && value.parallel.entity?.type === value.run.entity?.type &&
|
|
141
|
-
value.parallel.ancestor.runId === value.run.id && value.parallel.ancestor.processId === value.run.processId &&
|
|
142
|
-
value.parallel.ancestor.bundleHash === value.run.bundleHash && value.parallel.ancestor.receiptId === value.parallel.ancestor.stepId &&
|
|
143
|
-
new Set(branches.map((branch) => branch.branchId)).size === branches.length &&
|
|
144
|
-
new Set(branches.map((branch) => branch.branchIndex)).size === branches.length &&
|
|
145
|
-
branches.every((branch) => !branch.humanStep || (!['pending', 'timed_out'].includes(branch.joinStatus) && branch.humanStep.runId === value.run.id && branch.humanStep.nodeId === branch.nodeId && branch.humanStep.stepId === branch.stepId && branch.humanStep.attempt === branch.attempt && branch.humanStep.receiptId === branch.stepId));
|
|
146
|
-
}, 'Parallel snapshots must identify one complete causal execution with unique actual branches');
|
|
147
|
-
class FunctionLatticeContextError extends Error {
|
|
148
|
-
status;
|
|
149
|
-
code;
|
|
150
|
-
name = 'FunctionLatticeContextError';
|
|
151
|
-
constructor(status, code, message) {
|
|
152
|
-
super(message);
|
|
153
|
-
this.status = status;
|
|
154
|
-
this.code = code;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
exports.FunctionLatticeContextError = FunctionLatticeContextError;
|
|
4
|
+
var contracts_1 = require("@sequenceholdings/platform/contracts");
|
|
5
|
+
Object.defineProperty(exports, "FUNCTION_LATTICE_EXECUTION_TOKEN_HEADER", { enumerable: true, get: function () { return contracts_1.FUNCTION_LATTICE_EXECUTION_TOKEN_HEADER; } });
|
|
6
|
+
Object.defineProperty(exports, "FUNCTION_LATTICE_CONTEXT_PATH", { enumerable: true, get: function () { return contracts_1.FUNCTION_LATTICE_CONTEXT_PATH; } });
|
|
7
|
+
Object.defineProperty(exports, "functionLatticeStartProvenanceSchema", { enumerable: true, get: function () { return contracts_1.functionLatticeStartProvenanceSchema; } });
|
|
8
|
+
Object.defineProperty(exports, "functionLatticeHumanCompletionQuerySchema", { enumerable: true, get: function () { return contracts_1.functionLatticeHumanCompletionQuerySchema; } });
|
|
9
|
+
Object.defineProperty(exports, "functionLatticeHumanCompletionsQuerySchema", { enumerable: true, get: function () { return contracts_1.functionLatticeHumanCompletionsQuerySchema; } });
|
|
10
|
+
Object.defineProperty(exports, "functionLatticeParallelSnapshotQuerySchema", { enumerable: true, get: function () { return contracts_1.functionLatticeParallelSnapshotQuerySchema; } });
|
|
11
|
+
Object.defineProperty(exports, "functionLatticeContextRequestSchema", { enumerable: true, get: function () { return contracts_1.functionLatticeContextRequestSchema; } });
|
|
12
|
+
Object.defineProperty(exports, "functionLatticeRunCreatorAccessSchema", { enumerable: true, get: function () { return contracts_1.functionLatticeRunCreatorAccessSchema; } });
|
|
13
|
+
Object.defineProperty(exports, "functionLatticeExecutionContextSchema", { enumerable: true, get: function () { return contracts_1.functionLatticeExecutionContextSchema; } });
|
|
14
|
+
Object.defineProperty(exports, "functionLatticeHumanCompletionSchema", { enumerable: true, get: function () { return contracts_1.functionLatticeHumanCompletionSchema; } });
|
|
15
|
+
Object.defineProperty(exports, "functionLatticeHumanCompletionsPageSchema", { enumerable: true, get: function () { return contracts_1.functionLatticeHumanCompletionsPageSchema; } });
|
|
16
|
+
Object.defineProperty(exports, "functionLatticeParallelSnapshotSchema", { enumerable: true, get: function () { return contracts_1.functionLatticeParallelSnapshotSchema; } });
|
|
17
|
+
Object.defineProperty(exports, "FunctionLatticeContextError", { enumerable: true, get: function () { return contracts_1.FunctionLatticeContextError; } });
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type FunctionLatticeRunCreatorAccess, type FunctionLatticeExecutionContext, type FunctionLatticeHumanCompletion, type FunctionLatticeHumanCompletionQuery, type FunctionLatticeHumanCompletionsQuery, type FunctionLatticeHumanCompletionsPage, type FunctionLatticeParallelSnapshot, type FunctionLatticeParallelSnapshotQuery } from
|
|
2
|
-
export * from
|
|
1
|
+
import { type FunctionLatticeRunCreatorAccess, type FunctionLatticeExecutionContext, type FunctionLatticeHumanCompletion, type FunctionLatticeHumanCompletionQuery, type FunctionLatticeHumanCompletionsQuery, type FunctionLatticeHumanCompletionsPage, type FunctionLatticeParallelSnapshot, type FunctionLatticeParallelSnapshotQuery } from "./lattice-provenance-contract";
|
|
2
|
+
export * from "./lattice-provenance-contract";
|
|
3
3
|
export interface FunctionLatticeClientOptions {
|
|
4
4
|
request: {
|
|
5
|
-
headers: Pick<Headers,
|
|
5
|
+
headers: Pick<Headers, "get"> | Readonly<Record<string, string | readonly string[] | undefined>>;
|
|
6
6
|
};
|
|
7
7
|
baseUrl: string;
|
|
8
8
|
fetchImpl?: typeof globalThis.fetch;
|
|
@@ -15,11 +15,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.createFunctionLatticeClient = createFunctionLatticeClient;
|
|
18
|
+
const adapters_1 = require("@sequenceholdings/platform/adapters");
|
|
18
19
|
const zod_1 = require("zod");
|
|
19
20
|
const lattice_provenance_contract_1 = require("./lattice-provenance-contract");
|
|
20
21
|
__exportStar(require("./lattice-provenance-contract"), exports);
|
|
21
22
|
const tokenClaimsSchema = zod_1.z.object({
|
|
22
|
-
audience: zod_1.z.literal(
|
|
23
|
+
audience: zod_1.z.literal("atlas-managed-function-lattice-execution"),
|
|
23
24
|
functionId: zod_1.z.string().min(1).max(255),
|
|
24
25
|
versionId: zod_1.z.string().min(1).max(255),
|
|
25
26
|
invocationId: zod_1.z.string().min(1).max(255),
|
|
@@ -32,29 +33,33 @@ const tokenClaimsSchema = zod_1.z.object({
|
|
|
32
33
|
nodeId: zod_1.z.string().min(1).max(255),
|
|
33
34
|
stepAttempt: zod_1.z.number().int().positive(),
|
|
34
35
|
serviceAccountId: zod_1.z.string().min(1).max(255),
|
|
35
|
-
callerSub: zod_1.z.string().min(1).max(512),
|
|
36
|
+
callerSub: zod_1.z.string().min(1).max(512),
|
|
37
|
+
callerKind: zod_1.z.string().min(1).max(64),
|
|
38
|
+
callerAuthenticationMethod: zod_1.z.string().min(1).max(64),
|
|
36
39
|
exp: zod_1.z.number().int().positive().max(Number.MAX_SAFE_INTEGER),
|
|
37
40
|
});
|
|
38
|
-
const invalidContext = () => new lattice_provenance_contract_1.FunctionLatticeContextError(401,
|
|
41
|
+
const invalidContext = () => new lattice_provenance_contract_1.FunctionLatticeContextError(401, "invalid_context", "This invocation has no valid Lattice execution credential");
|
|
39
42
|
function readCredential({ request, }) {
|
|
40
43
|
const { headers } = request;
|
|
41
|
-
const matches = typeof headers.get ===
|
|
44
|
+
const matches = typeof headers.get === "function"
|
|
42
45
|
? [headers.get(lattice_provenance_contract_1.FUNCTION_LATTICE_EXECUTION_TOKEN_HEADER)]
|
|
43
46
|
: Object.entries(headers)
|
|
44
47
|
.filter(([name]) => name.toLowerCase() === lattice_provenance_contract_1.FUNCTION_LATTICE_EXECUTION_TOKEN_HEADER)
|
|
45
48
|
.map(([, value]) => value);
|
|
46
49
|
const token = matches[0];
|
|
47
|
-
if (matches.length !== 1 ||
|
|
50
|
+
if (matches.length !== 1 ||
|
|
51
|
+
typeof token !== "string" ||
|
|
52
|
+
token.length > 16_384)
|
|
48
53
|
throw invalidContext();
|
|
49
54
|
const envelope = /^([A-Za-z0-9_-]+)\.([A-Za-z0-9_-]{43})$/.exec(token);
|
|
50
55
|
if (!envelope?.[1])
|
|
51
56
|
throw invalidContext();
|
|
52
57
|
let value;
|
|
53
58
|
try {
|
|
54
|
-
const decoded = Buffer.from(envelope[1],
|
|
55
|
-
if (decoded.toString(
|
|
59
|
+
const decoded = Buffer.from(envelope[1], "base64url");
|
|
60
|
+
if (decoded.toString("base64url") !== envelope[1])
|
|
56
61
|
throw invalidContext();
|
|
57
|
-
value = JSON.parse(new TextDecoder(
|
|
62
|
+
value = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(decoded));
|
|
58
63
|
}
|
|
59
64
|
catch {
|
|
60
65
|
throw invalidContext();
|
|
@@ -65,7 +70,7 @@ function readCredential({ request, }) {
|
|
|
65
70
|
return { token, claims: parsed.data };
|
|
66
71
|
}
|
|
67
72
|
function trustedOrigin(baseUrl) {
|
|
68
|
-
const invalid = () => new lattice_provenance_contract_1.FunctionLatticeContextError(400,
|
|
73
|
+
const invalid = () => new lattice_provenance_contract_1.FunctionLatticeContextError(400, "invalid_configuration", "Configure a trusted HTTPS Atlas origin without credentials, path, query or fragment");
|
|
69
74
|
let url;
|
|
70
75
|
try {
|
|
71
76
|
url = new URL(baseUrl);
|
|
@@ -73,98 +78,42 @@ function trustedOrigin(baseUrl) {
|
|
|
73
78
|
catch {
|
|
74
79
|
throw invalid();
|
|
75
80
|
}
|
|
76
|
-
const loopback = url.protocol ===
|
|
77
|
-
[
|
|
78
|
-
if ((!loopback && url.protocol !==
|
|
79
|
-
url.
|
|
81
|
+
const loopback = url.protocol === "http:" &&
|
|
82
|
+
["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
|
|
83
|
+
if ((!loopback && url.protocol !== "https:") ||
|
|
84
|
+
url.username ||
|
|
85
|
+
url.password ||
|
|
86
|
+
url.pathname !== "/" ||
|
|
87
|
+
url.search ||
|
|
88
|
+
url.hash)
|
|
80
89
|
throw invalid();
|
|
81
90
|
return url.origin;
|
|
82
91
|
}
|
|
83
|
-
function matchesExecution({ execution, claims, }) {
|
|
84
|
-
return execution.receiver.functionId === claims.functionId &&
|
|
85
|
-
execution.receiver.versionId === claims.versionId &&
|
|
86
|
-
execution.receiver.invocationId === claims.invocationId &&
|
|
87
|
-
execution.receiverFunctionOrgId === claims.org &&
|
|
88
|
-
execution.run.id === claims.runId && execution.run.processId === claims.processId &&
|
|
89
|
-
execution.run.processVersion === claims.processVersion && execution.run.bundleHash === claims.bundleHash &&
|
|
90
|
-
execution.step.id === claims.stepId && execution.step.nodeId === claims.nodeId &&
|
|
91
|
-
execution.step.attempt === claims.stepAttempt && execution.receiver.invoker.sub === claims.callerSub &&
|
|
92
|
-
execution.receiver.invoker.kind === claims.callerKind && execution.receiver.invoker.authenticationMethod === claims.callerAuthenticationMethod &&
|
|
93
|
-
execution.receiver.attachedServiceAccountSub === `service-account|${claims.serviceAccountId}`;
|
|
94
|
-
}
|
|
95
|
-
function validateHumanSelection({ completion, query, }) {
|
|
96
|
-
if (completion.human.nodeId !== query.nodeId ||
|
|
97
|
-
(query.stepId !== undefined && completion.human.stepId !== query.stepId) ||
|
|
98
|
-
(query.ancestorNodeId !== undefined && completion.human.ancestor?.nodeId !== query.ancestorNodeId))
|
|
99
|
-
throw new lattice_provenance_contract_1.FunctionLatticeContextError(502, 'malformed_response', 'Atlas returned a different completed human step');
|
|
100
|
-
}
|
|
101
92
|
function createFunctionLatticeClient({ request, baseUrl, fetchImpl = globalThis.fetch, }) {
|
|
102
|
-
|
|
93
|
+
trustedOrigin(baseUrl);
|
|
103
94
|
const { token, claims } = readCredential({ request });
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
if (response.redirected || (response.status >= 300 && response.status < 400))
|
|
127
|
-
throw new lattice_provenance_contract_1.FunctionLatticeContextError(502, 'redirect_refused', 'The Lattice context request must not redirect');
|
|
128
|
-
const result = await response.json().catch(() => null);
|
|
129
|
-
if (!response.ok) {
|
|
130
|
-
const error = zod_1.z.object({ code: zod_1.z.string().min(1).max(128), detail: zod_1.z.string().min(1).max(2000) }).safeParse(result);
|
|
131
|
-
throw new lattice_provenance_contract_1.FunctionLatticeContextError(response.status, error.success ? error.data.code : 'context_read_failed', error.success ? error.data.detail : 'Lattice context read failed');
|
|
132
|
-
}
|
|
133
|
-
const validated = schema.safeParse(result);
|
|
134
|
-
if (!validated.success || executions(validated.data).some((execution) => !matchesExecution({ execution, claims })))
|
|
135
|
-
throw new lattice_provenance_contract_1.FunctionLatticeContextError(502, 'malformed_response', 'Atlas returned an invalid Lattice context response');
|
|
136
|
-
return validated.data;
|
|
137
|
-
}
|
|
138
|
-
return {
|
|
139
|
-
getExecutionContext() {
|
|
140
|
-
return read({ body: { operation: 'getExecutionContext' }, schema: lattice_provenance_contract_1.functionLatticeExecutionContextSchema, executions: (value) => [value] });
|
|
141
|
-
},
|
|
142
|
-
getRunCreatorAccess() {
|
|
143
|
-
return read({ body: { operation: 'getRunCreatorAccess' }, schema: lattice_provenance_contract_1.functionLatticeRunCreatorAccessSchema, executions: value => [value] });
|
|
144
|
-
},
|
|
145
|
-
async getHumanCompletion(query) {
|
|
146
|
-
const completion = await read({
|
|
147
|
-
body: { ...query, operation: 'getHumanCompletion' },
|
|
148
|
-
schema: lattice_provenance_contract_1.functionLatticeHumanCompletionSchema,
|
|
149
|
-
executions: (value) => [value],
|
|
150
|
-
});
|
|
151
|
-
validateHumanSelection({ completion, query });
|
|
152
|
-
return completion;
|
|
153
|
-
},
|
|
154
|
-
async getHumanCompletions(query) {
|
|
155
|
-
const page = await read({
|
|
156
|
-
body: { ...query, operation: 'getHumanCompletions' },
|
|
157
|
-
schema: lattice_provenance_contract_1.functionLatticeHumanCompletionsPageSchema,
|
|
158
|
-
executions: (value) => value.completions,
|
|
159
|
-
});
|
|
160
|
-
page.completions.forEach((completion) => validateHumanSelection({ completion, query }));
|
|
161
|
-
return page;
|
|
162
|
-
},
|
|
163
|
-
async getParallelSnapshot(query) {
|
|
164
|
-
const snapshot = await read({ body: { ...query, operation: 'getParallelSnapshot' }, schema: lattice_provenance_contract_1.functionLatticeParallelSnapshotSchema, executions: (value) => [value] });
|
|
165
|
-
if (snapshot.parallel.nodeId !== query.nodeId || snapshot.parallel.ancestor.nodeId !== query.ancestorNodeId)
|
|
166
|
-
throw new lattice_provenance_contract_1.FunctionLatticeContextError(502, 'malformed_response', 'Atlas returned a different causal parallel execution');
|
|
167
|
-
return snapshot;
|
|
95
|
+
const send = (0, adapters_1.createInvocationDomainTransport)({
|
|
96
|
+
baseUrl,
|
|
97
|
+
fetchImpl,
|
|
98
|
+
domain: "lattice-execution",
|
|
99
|
+
credentials: [
|
|
100
|
+
{
|
|
101
|
+
header: lattice_provenance_contract_1.FUNCTION_LATTICE_EXECUTION_TOKEN_HEADER,
|
|
102
|
+
token,
|
|
103
|
+
expiresAt: claims.exp,
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
error: (status, code, message) => new lattice_provenance_contract_1.FunctionLatticeContextError(["transport_failed", "timeout", "redirect_refused"].includes(code)
|
|
107
|
+
? 502
|
|
108
|
+
: status, ["transport_failed", "timeout"].includes(code)
|
|
109
|
+
? "context_request_failed"
|
|
110
|
+
: code, ["transport_failed", "timeout"].includes(code)
|
|
111
|
+
? "The Lattice context request failed"
|
|
112
|
+
: message),
|
|
113
|
+
failure: {
|
|
114
|
+
code: "context_read_failed",
|
|
115
|
+
message: "Lattice context read failed",
|
|
168
116
|
},
|
|
169
|
-
};
|
|
117
|
+
});
|
|
118
|
+
return (0, adapters_1.createLatticeExecutionClient)({ claims, send });
|
|
170
119
|
}
|
|
@@ -1,53 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export type MonitoringJson
|
|
3
|
-
[key: string]: MonitoringJson;
|
|
4
|
-
};
|
|
5
|
-
export declare const functionMonitoringAnnotationSchema: z.ZodObject<{
|
|
6
|
-
sourceType: z.ZodString;
|
|
7
|
-
sourceRef: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
8
|
-
generatingSubject: z.ZodObject<{
|
|
9
|
-
subjectId: z.ZodString;
|
|
10
|
-
subjectKind: z.ZodEnum<{
|
|
11
|
-
workflow: "workflow";
|
|
12
|
-
agent: "agent";
|
|
13
|
-
}>;
|
|
14
|
-
}, z.core.$strict>;
|
|
15
|
-
occurredAt: z.ZodISODateTime;
|
|
16
|
-
summary: z.ZodNullable<z.ZodString>;
|
|
17
|
-
metrics: z.ZodCustom<MonitoringJson, MonitoringJson>;
|
|
18
|
-
conversationFindings: z.ZodArray<z.ZodObject<{
|
|
19
|
-
type: z.ZodString;
|
|
20
|
-
description: z.ZodString;
|
|
21
|
-
excerpt: z.ZodString;
|
|
22
|
-
severity: z.ZodEnum<{
|
|
23
|
-
high: "high";
|
|
24
|
-
medium: "medium";
|
|
25
|
-
low: "low";
|
|
26
|
-
}>;
|
|
27
|
-
}, z.core.$strict>>;
|
|
28
|
-
classifications: z.ZodArray<z.ZodObject<{
|
|
29
|
-
matchedBucketSlug: z.ZodNullable<z.ZodString>;
|
|
30
|
-
newBucketProposal: z.ZodNullable<z.ZodObject<{
|
|
31
|
-
name: z.ZodString;
|
|
32
|
-
description: z.ZodString;
|
|
33
|
-
severity: z.ZodEnum<{
|
|
34
|
-
critical: "critical";
|
|
35
|
-
high: "high";
|
|
36
|
-
medium: "medium";
|
|
37
|
-
low: "low";
|
|
38
|
-
}>;
|
|
39
|
-
category: z.ZodString;
|
|
40
|
-
}, z.core.$strict>>;
|
|
41
|
-
excerpt: z.ZodString;
|
|
42
|
-
inputTags: z.ZodArray<z.ZodObject<{
|
|
43
|
-
type: z.ZodString;
|
|
44
|
-
value: z.ZodString;
|
|
45
|
-
}, z.core.$strict>>;
|
|
46
|
-
}, z.core.$strict>>;
|
|
47
|
-
coarseFallbacks: z.ZodArray<z.ZodObject<{
|
|
48
|
-
bucketSlug: z.ZodString;
|
|
49
|
-
excerpt: z.ZodString;
|
|
50
|
-
coarseCategory: z.ZodString;
|
|
51
|
-
}, z.core.$strict>>;
|
|
52
|
-
}, z.core.$strict>;
|
|
53
|
-
export type FunctionMonitoringAnnotation = z.infer<typeof functionMonitoringAnnotationSchema>;
|
|
1
|
+
export { functionMonitoringAnnotationSchema } from "@sequenceholdings/platform/contracts";
|
|
2
|
+
export type { MonitoringJson, FunctionMonitoringAnnotation, } from "@sequenceholdings/platform/contracts";
|
|
@@ -1,54 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.functionMonitoringAnnotationSchema = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (depth > 6)
|
|
7
|
-
return false;
|
|
8
|
-
if (value === null || typeof value === 'boolean')
|
|
9
|
-
return true;
|
|
10
|
-
if (typeof value === 'number')
|
|
11
|
-
return Number.isFinite(value);
|
|
12
|
-
if (typeof value === 'string')
|
|
13
|
-
return value.length <= 50_000;
|
|
14
|
-
if (Array.isArray(value)) {
|
|
15
|
-
if (Object.getPrototypeOf(value) !== Array.prototype || value.length > 100 || Object.getOwnPropertyNames(value).length !== value.length + 1 || Object.getOwnPropertySymbols(value).length > 0)
|
|
16
|
-
return false;
|
|
17
|
-
for (let index = 0; index < value.length; index++) {
|
|
18
|
-
const entry = Object.getOwnPropertyDescriptor(value, String(index));
|
|
19
|
-
if (!entry?.enumerable || !('value' in entry) || !boundedJson(entry.value, depth + 1))
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
if (typeof value !== 'object')
|
|
25
|
-
return false;
|
|
26
|
-
const prototype = Object.getPrototypeOf(value);
|
|
27
|
-
if ((prototype !== Object.prototype && prototype !== null) || Object.getOwnPropertySymbols(value).length > 0)
|
|
28
|
-
return false;
|
|
29
|
-
const entries = Object.entries(Object.getOwnPropertyDescriptors(value));
|
|
30
|
-
return entries.length <= 64 && entries.every(([key, entry]) => key.length <= 128 && entry.enumerable && 'value' in entry && boundedJson(entry.value, depth + 1));
|
|
31
|
-
}
|
|
32
|
-
const json = zod_1.z.custom(value => boundedJson(value) && Buffer.byteLength(JSON.stringify(value), 'utf8') <= 100_000, 'Expected bounded JSON metrics');
|
|
33
|
-
const text = zod_1.z.string().max(50_000);
|
|
34
|
-
const id = zod_1.z.string().min(1).max(512);
|
|
35
|
-
const severity = zod_1.z.enum(['critical', 'high', 'medium', 'low']);
|
|
36
|
-
const inputTag = zod_1.z.strictObject({ type: zod_1.z.string().min(1).max(128), value: zod_1.z.string().max(8_000) });
|
|
37
|
-
exports.functionMonitoringAnnotationSchema = zod_1.z.strictObject({
|
|
38
|
-
sourceType: id,
|
|
39
|
-
sourceRef: zod_1.z.record(zod_1.z.string().min(1).max(128), zod_1.z.union([zod_1.z.string().max(8_000), zod_1.z.number().finite()])).refine(ref => Object.keys(ref).length > 0 && Object.keys(ref).length <= 64, 'Source references must be bounded and nonempty'),
|
|
40
|
-
generatingSubject: zod_1.z.strictObject({ subjectId: id, subjectKind: zod_1.z.enum(['agent', 'workflow']) }),
|
|
41
|
-
occurredAt: zod_1.z.iso.datetime({ offset: true }),
|
|
42
|
-
summary: text.nullable(),
|
|
43
|
-
metrics: json,
|
|
44
|
-
conversationFindings: zod_1.z.array(zod_1.z.strictObject({ type: id, description: text, excerpt: text, severity: zod_1.z.enum(['high', 'medium', 'low']) })).max(100),
|
|
45
|
-
classifications: zod_1.z.array(zod_1.z.strictObject({
|
|
46
|
-
matchedBucketSlug: id.nullable(),
|
|
47
|
-
newBucketProposal: zod_1.z.strictObject({ name: id, description: text, severity, category: id }).nullable(),
|
|
48
|
-
excerpt: text, inputTags: zod_1.z.array(inputTag).max(64),
|
|
49
|
-
}).refine(classification => (classification.matchedBucketSlug === null) !== (classification.newBucketProposal === null), 'Name exactly one matched bucket or proposal')).max(100),
|
|
50
|
-
coarseFallbacks: zod_1.z.array(zod_1.z.strictObject({ bucketSlug: id, excerpt: text, coarseCategory: id })).max(100),
|
|
51
|
-
}).superRefine((annotation, context) => {
|
|
52
|
-
if (Buffer.byteLength(JSON.stringify(annotation), 'utf8') > 256 * 1024)
|
|
53
|
-
context.addIssue({ code: 'custom', message: 'Monitoring annotations exceed the size limit' });
|
|
54
|
-
});
|
|
4
|
+
var contracts_1 = require("@sequenceholdings/platform/contracts");
|
|
5
|
+
Object.defineProperty(exports, "functionMonitoringAnnotationSchema", { enumerable: true, get: function () { return contracts_1.functionMonitoringAnnotationSchema; } });
|