@sequenceholdings/managed-functions 0.4.0 → 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 +444 -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 +165 -0
- package/dist/capabilities.js +61 -1
- package/dist/config.d.ts +18 -2
- package/dist/config.js +62 -1
- package/dist/deployed-policy.js +102 -0
- package/dist/directory-config.d.ts +23 -0
- package/dist/directory-config.js +22 -0
- 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/directory.d.ts +15 -0
- package/dist/directory.js +65 -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 +40 -1
- package/dist/index.js +75 -1
- package/dist/invocation-client.d.ts +45 -0
- package/dist/invocation-client.js +90 -0
- 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-directory.d.ts +10 -0
- package/dist/preflight-directory.js +36 -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 +50 -2
- package/dist/processes-contract.d.ts +20 -0
- package/dist/processes-contract.js +8 -1
- package/dist/processes.d.ts +4 -8
- package/dist/processes.js +52 -83
- package/dist/runtime.cjs +3387 -259
- 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,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkWorkflows = checkWorkflows;
|
|
4
|
+
const capabilities_1 = require("./capabilities");
|
|
5
|
+
const preflight_issue_1 = require("./preflight-issue");
|
|
6
|
+
const sdk_range_1 = require("./sdk-range");
|
|
7
|
+
const workflow_scopes_contract_1 = require("./workflow-scopes-contract");
|
|
8
|
+
function checkWorkflows({ manifest, capabilities, tooling, cliVersion, sdkVersion, checkDeployment, issues, }) {
|
|
9
|
+
const workflows = manifest.capabilities?.workflows;
|
|
10
|
+
if (workflows === undefined)
|
|
11
|
+
return;
|
|
12
|
+
const parsed = workflow_scopes_contract_1.functionWorkflowScopesSchema.safeParse(workflows);
|
|
13
|
+
if (!parsed.success) {
|
|
14
|
+
const feature = capabilities_1.MANAGED_FUNCTION_CAPABILITIES.features.workflows_read;
|
|
15
|
+
issues.push((0, preflight_issue_1.createPreflightIssue)({
|
|
16
|
+
limit: feature.limit, tooling, requiredCli: feature.min_cli, requiredSdk: feature.min_sdk, cliVersion, sdkVersion,
|
|
17
|
+
field: 'capabilities.workflows', problem: (0, capabilities_1.formatValidationDetail)(parsed.error.issues),
|
|
18
|
+
}));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const keys = [];
|
|
22
|
+
if (parsed.data.read !== undefined)
|
|
23
|
+
keys.push('workflows_read');
|
|
24
|
+
if (parsed.data.evidence !== undefined)
|
|
25
|
+
keys.push('workflows_evidence_verify');
|
|
26
|
+
for (const key of keys) {
|
|
27
|
+
const deployed = capabilities?.features[key];
|
|
28
|
+
const feature = deployed ?? capabilities_1.MANAGED_FUNCTION_CAPABILITIES.features[key];
|
|
29
|
+
const details = { limit: feature.limit, tooling, requiredCli: feature.min_cli, requiredSdk: feature.min_sdk, cliVersion, sdkVersion };
|
|
30
|
+
if (checkDeployment && deployed?.supported !== true) {
|
|
31
|
+
issues.push((0, preflight_issue_1.createPreflightIssue)({ ...details, field: feature.field, problem: 'the declared workflow capability is not supported by this deployment' }));
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if ((0, capabilities_1.versionIsOlder)(cliVersion, feature.min_cli) || (sdkVersion && (0, sdk_range_1.sdkConstraintIsOlder)(sdkVersion, feature.min_sdk))) {
|
|
35
|
+
issues.push((0, preflight_issue_1.createPreflightIssue)({ ...details, field: feature.field, problem: 'the installed tooling does not support the declared workflow capability' }));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
package/dist/preflight.js
CHANGED
|
@@ -5,6 +5,22 @@ const capabilities_1 = require("./capabilities");
|
|
|
5
5
|
const sdk_range_1 = require("./sdk-range");
|
|
6
6
|
const preflight_issue_1 = require("./preflight-issue");
|
|
7
7
|
const preflight_processes_1 = require("./preflight-processes");
|
|
8
|
+
const preflight_lattice_1 = require("./preflight-lattice");
|
|
9
|
+
const lattice_capability_1 = require("./lattice-capability");
|
|
10
|
+
const preflight_invocation_1 = require("./preflight-invocation");
|
|
11
|
+
const preflight_immutable_release_1 = require("./preflight-immutable-release");
|
|
12
|
+
const invocation_contract_1 = require("./invocation-contract");
|
|
13
|
+
const preflight_agents_1 = require("./preflight-agents");
|
|
14
|
+
const agents_contract_1 = require("./agents-contract");
|
|
15
|
+
const preflight_workflows_1 = require("./preflight-workflows");
|
|
16
|
+
const workflow_scopes_contract_1 = require("./workflow-scopes-contract");
|
|
17
|
+
const preflight_monitoring_1 = require("./preflight-monitoring");
|
|
18
|
+
const preflight_service_directory_1 = require("./preflight-service-directory");
|
|
19
|
+
const preflight_directory_1 = require("./preflight-directory");
|
|
20
|
+
const directory_manifest_1 = require("./directory-manifest");
|
|
21
|
+
const preflight_abrigo_1 = require("./preflight-abrigo");
|
|
22
|
+
const abrigo_contract_1 = require("./abrigo-contract");
|
|
23
|
+
const monitoring_contract_1 = require("./monitoring-contract");
|
|
8
24
|
const processes_contract_1 = require("./processes-contract");
|
|
9
25
|
const WORKLOAD_FIELDS = [
|
|
10
26
|
'memory_mb',
|
|
@@ -19,8 +35,16 @@ function preflightManagedFunction({ manifest, limits, capabilities, cliVersion,
|
|
|
19
35
|
const tooling = capabilities?.tooling ?? capabilities_1.MANAGED_FUNCTION_CAPABILITIES.tooling;
|
|
20
36
|
const issues = [];
|
|
21
37
|
checkWorkload({ manifest, limits, tooling, cliVersion, sdkVersion, issues });
|
|
38
|
+
(0, preflight_immutable_release_1.checkImmutableRelease)({ manifest, capabilities, tooling, cliVersion, sdkVersion, checkDeployment, issues });
|
|
22
39
|
checkPostgres({ manifest, capabilities, tooling, cliVersion, sdkVersion, issues });
|
|
23
40
|
(0, preflight_processes_1.checkProcesses)({ manifest, capabilities, tooling, cliVersion, sdkVersion, checkDeployment, issues });
|
|
41
|
+
(0, preflight_lattice_1.checkLatticeContext)({ manifest, capabilities, tooling, cliVersion, sdkVersion, checkDeployment, issues });
|
|
42
|
+
(0, preflight_invocation_1.checkInvocationIdentity)({ manifest, capabilities, tooling, cliVersion, sdkVersion, checkDeployment, issues });
|
|
43
|
+
(0, preflight_agents_1.checkAgents)({ manifest, capabilities, tooling, cliVersion, sdkVersion, checkDeployment, issues });
|
|
44
|
+
(0, preflight_workflows_1.checkWorkflows)({ manifest, capabilities, tooling, cliVersion, sdkVersion, checkDeployment, issues });
|
|
45
|
+
(0, preflight_monitoring_1.checkMonitoring)({ manifest, capabilities, tooling, cliVersion, sdkVersion, checkDeployment, issues });
|
|
46
|
+
checkDirectoryDeclarations({ manifest, capabilities, tooling, cliVersion, sdkVersion, checkDeployment, issues });
|
|
47
|
+
(0, preflight_abrigo_1.checkAbrigo)({ manifest, capabilities, tooling, cliVersion, sdkVersion, checkDeployment, issues });
|
|
24
48
|
checkHeaders({ manifest, capabilities, tooling, cliVersion, sdkVersion, issues });
|
|
25
49
|
checkSdkTimeout({ manifest, limits, capabilities, tooling, cliVersion, sdkVersion, issues });
|
|
26
50
|
return issues;
|
|
@@ -122,7 +146,14 @@ function needsWideHeaders(manifest) {
|
|
|
122
146
|
const hasData = !!data && Object.keys(data).length > 0;
|
|
123
147
|
const hasStorage = !!storage && typeof storage === 'object' && Object.keys(storage).length > 0;
|
|
124
148
|
const hasProcesses = processes_contract_1.functionProcessReadScopesSchema.safeParse(manifest.capabilities?.processes).success;
|
|
125
|
-
|
|
149
|
+
const hasAgents = agents_contract_1.functionAgentReadScopesSchema.safeParse(manifest.capabilities?.agents).success;
|
|
150
|
+
const hasWorkflows = workflow_scopes_contract_1.functionWorkflowScopesSchema.safeParse(manifest.capabilities?.workflows).success;
|
|
151
|
+
const hasMonitoring = monitoring_contract_1.functionMonitoringScopesSchema.safeParse(manifest.capabilities?.monitoring).success;
|
|
152
|
+
const hasLattice = (0, lattice_capability_1.readFunctionLatticeContextCapability)(manifest);
|
|
153
|
+
const hasInvocation = (0, invocation_contract_1.readFunctionInvocationIdentityCapability)(manifest);
|
|
154
|
+
const hasDirectory = directory_manifest_1.functionDirectoryManifestSchema.safeParse(manifest.capabilities?.directory).success;
|
|
155
|
+
const hasAbrigo = abrigo_contract_1.functionAbrigoReadScopesSchema.safeParse(manifest.capabilities?.abrigo).success;
|
|
156
|
+
return hasData || hasStorage || hasProcesses || hasMonitoring || hasAgents || hasWorkflows || hasLattice || hasInvocation || hasDirectory || hasAbrigo;
|
|
126
157
|
}
|
|
127
158
|
function checkHeaders({ manifest, capabilities, tooling, cliVersion, sdkVersion, issues, }) {
|
|
128
159
|
const feature = capabilities?.features.http_headers;
|
|
@@ -133,7 +164,7 @@ function checkHeaders({ manifest, capabilities, tooling, cliVersion, sdkVersion,
|
|
|
133
164
|
return;
|
|
134
165
|
issues.push((0, preflight_issue_1.createPreflightIssue)({
|
|
135
166
|
field: feature.field,
|
|
136
|
-
problem: `invocation headers for capabilities.data, capabilities.storage,
|
|
167
|
+
problem: `invocation headers for capability credentials, including capabilities.data, capabilities.storage, capabilities.processes, capabilities.lattice, capabilities.invocation and capabilities.directory, exceed ${feature.max_bytes} bytes and will fail with HTTP 431`,
|
|
137
168
|
limit: feature.limit,
|
|
138
169
|
tooling,
|
|
139
170
|
requiredCli: feature.min_cli,
|
|
@@ -163,3 +194,20 @@ function checkSdkTimeout({ manifest, limits, capabilities, tooling, cliVersion,
|
|
|
163
194
|
sdkVersion,
|
|
164
195
|
}));
|
|
165
196
|
}
|
|
197
|
+
function checkDirectoryDeclarations(args) {
|
|
198
|
+
const directory = args.manifest.capabilities?.directory;
|
|
199
|
+
if (directory === undefined)
|
|
200
|
+
return;
|
|
201
|
+
const parsed = directory_manifest_1.functionDirectoryManifestSchema.safeParse(directory);
|
|
202
|
+
if (!parsed.success) {
|
|
203
|
+
args.issues.push((0, preflight_issue_1.createPreflightIssue)({ field: 'capabilities.directory', problem: (0, capabilities_1.formatValidationDetail)(parsed.error.issues),
|
|
204
|
+
limit: 'concrete groups and/or exact tenant resolution scopes', tooling: args.tooling,
|
|
205
|
+
requiredCli: args.tooling.cli.min, requiredSdk: args.tooling.sdk.min, cliVersion: args.cliVersion, sdkVersion: args.sdkVersion }));
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const scoped = (directory) => ({ ...args, manifest: { ...args.manifest, capabilities: { ...args.manifest.capabilities, directory } } });
|
|
209
|
+
if (parsed.data.groups)
|
|
210
|
+
(0, preflight_directory_1.checkDirectory)(scoped({ groups: parsed.data.groups }));
|
|
211
|
+
if (parsed.data.resolve)
|
|
212
|
+
(0, preflight_service_directory_1.checkDirectory)(scoped({ resolve: parsed.data.resolve }));
|
|
213
|
+
}
|
|
@@ -55,6 +55,21 @@ export declare const functionProcessRunsPageQuerySchema: z.ZodObject<{
|
|
|
55
55
|
archived: z.ZodOptional<z.ZodBoolean>;
|
|
56
56
|
}, z.core.$strict>;
|
|
57
57
|
export type FunctionProcessRunQuery = z.infer<typeof functionProcessRunQuerySchema>;
|
|
58
|
+
export declare const functionProcessCompletedAgentReferenceQuerySchema: z.ZodObject<{
|
|
59
|
+
process: z.ZodString;
|
|
60
|
+
runId: z.ZodString;
|
|
61
|
+
nodeId: z.ZodString;
|
|
62
|
+
}, z.core.$strict>;
|
|
63
|
+
export type FunctionProcessCompletedAgentReferenceQuery = z.infer<typeof functionProcessCompletedAgentReferenceQuerySchema>;
|
|
64
|
+
export declare const functionProcessCompletedAgentReferenceSchema: z.ZodObject<{
|
|
65
|
+
stepId: z.ZodString;
|
|
66
|
+
attempt: z.ZodNumber;
|
|
67
|
+
agentId: z.ZodString;
|
|
68
|
+
agentRunId: z.ZodString;
|
|
69
|
+
threadId: z.ZodString;
|
|
70
|
+
recoveryProof: z.ZodString;
|
|
71
|
+
}, z.core.$strict>;
|
|
72
|
+
export type FunctionProcessCompletedAgentReference = z.infer<typeof functionProcessCompletedAgentReferenceSchema>;
|
|
58
73
|
export type FunctionProcessRunsPageQuery = z.infer<typeof functionProcessRunsPageQuerySchema>;
|
|
59
74
|
export declare const functionProcessRunsPageSchema: z.ZodObject<{
|
|
60
75
|
runs: z.ZodArray<z.ZodObject<{
|
|
@@ -80,6 +95,11 @@ export declare const functionProcessReadRequestSchema: z.ZodDiscriminatedUnion<[
|
|
|
80
95
|
process: z.ZodString;
|
|
81
96
|
runId: z.ZodString;
|
|
82
97
|
operation: z.ZodLiteral<"getRun">;
|
|
98
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
99
|
+
process: z.ZodString;
|
|
100
|
+
runId: z.ZodString;
|
|
101
|
+
nodeId: z.ZodString;
|
|
102
|
+
operation: z.ZodLiteral<"getCompletedAgentReference">;
|
|
83
103
|
}, z.core.$strict>, z.ZodObject<{
|
|
84
104
|
process: z.ZodString;
|
|
85
105
|
statuses: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FunctionProcessReadError = exports.functionProcessReadRequestSchema = exports.functionProcessRunsPageSchema = exports.functionProcessRunsPageQuerySchema = exports.functionProcessRunQuerySchema = exports.functionProcessRunSummarySchema = exports.functionProcessRunStatusSchema = exports.functionProcessReadScopesSchema = exports.FUNCTION_PROCESS_READ_PATH = exports.FUNCTION_PROCESS_TOKEN_HEADER = void 0;
|
|
3
|
+
exports.FunctionProcessReadError = exports.functionProcessReadRequestSchema = exports.functionProcessRunsPageSchema = exports.functionProcessCompletedAgentReferenceSchema = exports.functionProcessCompletedAgentReferenceQuerySchema = exports.functionProcessRunsPageQuerySchema = exports.functionProcessRunQuerySchema = exports.functionProcessRunSummarySchema = exports.functionProcessRunStatusSchema = exports.functionProcessReadScopesSchema = exports.FUNCTION_PROCESS_READ_PATH = exports.FUNCTION_PROCESS_TOKEN_HEADER = void 0;
|
|
4
4
|
exports.readFunctionProcessScopes = readFunctionProcessScopes;
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
6
|
exports.FUNCTION_PROCESS_TOKEN_HEADER = 'x-sequence-process-service-token';
|
|
@@ -66,12 +66,19 @@ exports.functionProcessRunsPageQuerySchema = zod_1.z.strictObject({
|
|
|
66
66
|
cursor: zod_1.z.string().min(1).max(8192).optional(),
|
|
67
67
|
archived: zod_1.z.boolean().optional(),
|
|
68
68
|
});
|
|
69
|
+
exports.functionProcessCompletedAgentReferenceQuerySchema = exports.functionProcessRunQuerySchema.extend({ nodeId: entityId });
|
|
70
|
+
exports.functionProcessCompletedAgentReferenceSchema = zod_1.z.strictObject({
|
|
71
|
+
stepId: entityId, attempt: zod_1.z.number().int().positive().max(Number.MAX_SAFE_INTEGER),
|
|
72
|
+
agentId: entityId, agentRunId: entityId, threadId: entityId,
|
|
73
|
+
recoveryProof: zod_1.z.string().min(1).max(16_384),
|
|
74
|
+
});
|
|
69
75
|
exports.functionProcessRunsPageSchema = zod_1.z.object({
|
|
70
76
|
runs: zod_1.z.array(exports.functionProcessRunSummarySchema).max(500),
|
|
71
77
|
nextCursor: zod_1.z.string().nullable(),
|
|
72
78
|
});
|
|
73
79
|
exports.functionProcessReadRequestSchema = zod_1.z.discriminatedUnion('operation', [
|
|
74
80
|
exports.functionProcessRunQuerySchema.extend({ operation: zod_1.z.literal('getRun') }),
|
|
81
|
+
exports.functionProcessCompletedAgentReferenceQuerySchema.extend({ operation: zod_1.z.literal('getCompletedAgentReference') }),
|
|
75
82
|
exports.functionProcessRunsPageQuerySchema.extend({
|
|
76
83
|
operation: zod_1.z.literal('listRunsPage'),
|
|
77
84
|
}),
|
package/dist/processes.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import { type FunctionProcessRunQuery, type FunctionProcessRunSummary, type FunctionProcessRunsPage, type FunctionProcessRunsPageQuery } from './processes-contract';
|
|
1
|
+
import { type FunctionProcessCompletedAgentReference, type FunctionProcessCompletedAgentReferenceQuery, type FunctionProcessRunQuery, type FunctionProcessRunSummary, type FunctionProcessRunsPage, type FunctionProcessRunsPageQuery } from './processes-contract';
|
|
2
|
+
import { type FunctionInvocationClientOptions } from './invocation-client';
|
|
2
3
|
export * from './processes-contract';
|
|
3
|
-
export
|
|
4
|
-
request: {
|
|
5
|
-
headers: Pick<Headers, 'get'> | Readonly<Record<string, string | readonly string[] | undefined>>;
|
|
6
|
-
};
|
|
7
|
-
baseUrl: string;
|
|
8
|
-
fetchImpl?: typeof globalThis.fetch;
|
|
9
|
-
}
|
|
4
|
+
export type FunctionServiceProcessesOptions = FunctionInvocationClientOptions;
|
|
10
5
|
export interface FunctionServiceProcessesClient {
|
|
6
|
+
getCompletedAgentReference(query: FunctionProcessCompletedAgentReferenceQuery): Promise<FunctionProcessCompletedAgentReference>;
|
|
11
7
|
getRun(query: FunctionProcessRunQuery): Promise<FunctionProcessRunSummary>;
|
|
12
8
|
listRunsPage(query: FunctionProcessRunsPageQuery): Promise<FunctionProcessRunsPage>;
|
|
13
9
|
}
|
package/dist/processes.js
CHANGED
|
@@ -17,100 +17,69 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.createFunctionServiceProcessesClient = createFunctionServiceProcessesClient;
|
|
18
18
|
const zod_1 = require("zod");
|
|
19
19
|
const processes_contract_1 = require("./processes-contract");
|
|
20
|
+
const invocation_client_1 = require("./invocation-client");
|
|
21
|
+
const agents_contract_1 = require("./agents-contract");
|
|
20
22
|
__exportStar(require("./processes-contract"), exports);
|
|
21
|
-
|
|
22
|
-
function readCredential({ request, }) {
|
|
23
|
+
function readAgentCredential({ request }) {
|
|
23
24
|
const { headers } = request;
|
|
24
|
-
const matches = typeof headers.get === 'function'
|
|
25
|
-
|
|
26
|
-
: Object.entries(headers)
|
|
27
|
-
.filter(([name]) => name.toLowerCase() === processes_contract_1.FUNCTION_PROCESS_TOKEN_HEADER)
|
|
28
|
-
.map(([, value]) => value);
|
|
25
|
+
const matches = typeof headers.get === 'function' ? [headers.get(agents_contract_1.FUNCTION_AGENT_TOKEN_HEADER)]
|
|
26
|
+
: Object.entries(headers).filter(([name]) => name.toLowerCase() === agents_contract_1.FUNCTION_AGENT_TOKEN_HEADER).map(([, value]) => value);
|
|
29
27
|
const token = matches[0];
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
throw invalidContext();
|
|
28
|
+
const denied = () => new processes_contract_1.FunctionProcessReadError(401, 'invalid_context', 'Completed-agent reference lookup requires an agent-read credential');
|
|
29
|
+
if (matches.length !== 1 || typeof token !== 'string' || token.length > 16_384)
|
|
30
|
+
throw denied();
|
|
31
|
+
const body = /^([A-Za-z0-9_-]+)\.[A-Za-z0-9_-]{43}$/.exec(token)?.[1];
|
|
32
|
+
if (!body)
|
|
33
|
+
throw denied();
|
|
37
34
|
let value;
|
|
38
35
|
try {
|
|
39
|
-
value = JSON.parse(Buffer.from(
|
|
36
|
+
value = JSON.parse(Buffer.from(body, 'base64url').toString('utf8'));
|
|
40
37
|
}
|
|
41
38
|
catch {
|
|
42
|
-
throw
|
|
39
|
+
throw denied();
|
|
43
40
|
}
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
functionId: zod_1.z.string().min(1),
|
|
49
|
-
invocationId: zod_1.z.string().min(1),
|
|
50
|
-
exp: zod_1.z.number().int(),
|
|
51
|
-
})
|
|
52
|
-
.safeParse(value);
|
|
53
|
-
if (!parsed.success)
|
|
54
|
-
throw invalidContext();
|
|
55
|
-
return { token, expiresAt: parsed.data.exp };
|
|
56
|
-
}
|
|
57
|
-
function origin(baseUrl) {
|
|
58
|
-
let url;
|
|
59
|
-
try {
|
|
60
|
-
url = new URL(baseUrl);
|
|
61
|
-
}
|
|
62
|
-
catch {
|
|
63
|
-
throw new processes_contract_1.FunctionProcessReadError(400, 'invalid_configuration', 'Configure a trusted Atlas origin');
|
|
64
|
-
}
|
|
65
|
-
const loopback = url.protocol === 'http:' &&
|
|
66
|
-
['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);
|
|
67
|
-
if ((!loopback && url.protocol !== 'https:') ||
|
|
68
|
-
url.username ||
|
|
69
|
-
url.password ||
|
|
70
|
-
url.pathname !== '/' ||
|
|
71
|
-
url.search ||
|
|
72
|
-
url.hash) {
|
|
73
|
-
throw new processes_contract_1.FunctionProcessReadError(400, 'invalid_configuration', 'Configure an HTTPS Atlas origin without credentials, path, query or fragment');
|
|
74
|
-
}
|
|
75
|
-
return url.origin;
|
|
41
|
+
const claims = zod_1.z.object({ audience: zod_1.z.literal('atlas-managed-function-agent-read'), sub: zod_1.z.string().startsWith('service-account|'), functionId: zod_1.z.string().min(1), invocationId: zod_1.z.string().min(1), exp: zod_1.z.number().int() }).safeParse(value);
|
|
42
|
+
if (!claims.success)
|
|
43
|
+
throw denied();
|
|
44
|
+
return { token, expiresAt: claims.data.exp };
|
|
76
45
|
}
|
|
46
|
+
const invalidContext = () => new processes_contract_1.FunctionProcessReadError(401, 'invalid_context', 'This invocation has no valid process-read credential');
|
|
77
47
|
function createFunctionServiceProcessesClient({ request, baseUrl, fetchImpl = globalThis.fetch, }) {
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
throw new processes_contract_1.FunctionProcessReadError(response.status, error.success
|
|
103
|
-
? (error.data.code ?? 'process_read_failed')
|
|
104
|
-
: 'process_read_failed', error.success
|
|
105
|
-
? (error.data.detail ?? 'Process read failed')
|
|
106
|
-
: 'Process read failed');
|
|
107
|
-
}
|
|
108
|
-
const validated = schema.safeParse(result);
|
|
109
|
-
if (!validated.success)
|
|
110
|
-
throw new processes_contract_1.FunctionProcessReadError(502, 'malformed_response', 'Atlas returned an invalid process-read response');
|
|
111
|
-
return validated.data;
|
|
112
|
-
}
|
|
48
|
+
const credential = (0, invocation_client_1.readInvocationCredential)({
|
|
49
|
+
request,
|
|
50
|
+
header: processes_contract_1.FUNCTION_PROCESS_TOKEN_HEADER,
|
|
51
|
+
maxBytes: 16_384,
|
|
52
|
+
invalidContext,
|
|
53
|
+
claimsSchema: zod_1.z.object({
|
|
54
|
+
audience: zod_1.z.literal('atlas-managed-function-process-read'),
|
|
55
|
+
sub: zod_1.z.string().startsWith('service-account|'),
|
|
56
|
+
functionId: zod_1.z.string().min(1),
|
|
57
|
+
invocationId: zod_1.z.string().min(1),
|
|
58
|
+
exp: zod_1.z.number().int(),
|
|
59
|
+
}),
|
|
60
|
+
});
|
|
61
|
+
const transport = (0, invocation_client_1.createInvocationReadTransport)({
|
|
62
|
+
baseUrl,
|
|
63
|
+
fetchImpl,
|
|
64
|
+
path: processes_contract_1.FUNCTION_PROCESS_READ_PATH,
|
|
65
|
+
header: processes_contract_1.FUNCTION_PROCESS_TOKEN_HEADER,
|
|
66
|
+
credential,
|
|
67
|
+
timeoutMs: 30_000,
|
|
68
|
+
error: (status, code, message) => new processes_contract_1.FunctionProcessReadError(status, code, message),
|
|
69
|
+
failure: { code: 'process_read_failed', message: 'Process read failed' },
|
|
70
|
+
});
|
|
71
|
+
const read = ({ body, schema }) => transport({ body: processes_contract_1.functionProcessReadRequestSchema.parse(body), schema });
|
|
113
72
|
return {
|
|
73
|
+
async getCompletedAgentReference(query) {
|
|
74
|
+
const agent = readAgentCredential({ request });
|
|
75
|
+
const readReference = (0, invocation_client_1.createInvocationReadTransport)({
|
|
76
|
+
baseUrl, fetchImpl, path: processes_contract_1.FUNCTION_PROCESS_READ_PATH, header: processes_contract_1.FUNCTION_PROCESS_TOKEN_HEADER,
|
|
77
|
+
credential, additionalCredentials: [{ header: agents_contract_1.FUNCTION_AGENT_TOKEN_HEADER, credential: agent }],
|
|
78
|
+
timeoutMs: 30_000, error: (status, code, message) => new processes_contract_1.FunctionProcessReadError(status, code, message),
|
|
79
|
+
failure: { code: 'process_read_failed', message: 'Process read failed' },
|
|
80
|
+
});
|
|
81
|
+
return readReference({ body: processes_contract_1.functionProcessReadRequestSchema.parse({ ...query, operation: 'getCompletedAgentReference' }), schema: processes_contract_1.functionProcessCompletedAgentReferenceSchema });
|
|
82
|
+
},
|
|
114
83
|
async getRun(query) {
|
|
115
84
|
const run = await read({
|
|
116
85
|
body: { ...query, operation: 'getRun' },
|