@sequenceholdings/managed-functions 0.4.5 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +147 -12
  2. package/dist/abrigo-contract.d.ts +2 -92
  3. package/dist/abrigo-contract.js +12 -53
  4. package/dist/abrigo-response.d.ts +1 -6
  5. package/dist/abrigo-response.js +3 -25
  6. package/dist/abrigo.d.ts +5 -5
  7. package/dist/abrigo.js +66 -92
  8. package/dist/agent-evidence.d.ts +5 -5
  9. package/dist/agent-evidence.js +58 -48
  10. package/dist/agent-source-evidence-contract.d.ts +2 -1197
  11. package/dist/agent-source-evidence-contract.js +24 -94
  12. package/dist/agents-contract.d.ts +2 -99
  13. package/dist/agents-contract.js +13 -67
  14. package/dist/agents.d.ts +5 -5
  15. package/dist/agents.js +79 -44
  16. package/dist/capabilities.d.ts +1 -1
  17. package/dist/capabilities.js +1 -1
  18. package/dist/config.d.ts +1 -0
  19. package/dist/config.js +4 -1
  20. package/dist/directory-config.d.ts +1 -23
  21. package/dist/directory-config.js +8 -20
  22. package/dist/directory-contract.d.ts +2 -68
  23. package/dist/directory-contract.js +13 -55
  24. package/dist/directory-roster-contract.d.ts +2 -22
  25. package/dist/directory-roster-contract.js +7 -22
  26. package/dist/directory.d.ts +4 -8
  27. package/dist/directory.js +15 -33
  28. package/dist/group-roster-access.d.ts +7 -0
  29. package/dist/group-roster-access.js +8 -0
  30. package/dist/index.d.ts +49 -46
  31. package/dist/index.js +8 -1
  32. package/dist/invocation-client.d.ts +4 -4
  33. package/dist/invocation-client.js +32 -60
  34. package/dist/invocation-contract.d.ts +2 -59
  35. package/dist/invocation-contract.js +10 -61
  36. package/dist/invocation.d.ts +4 -4
  37. package/dist/invocation.js +42 -63
  38. package/dist/lattice-provenance-contract.d.ts +2 -607
  39. package/dist/lattice-provenance-contract.js +14 -154
  40. package/dist/lattice-provenance.d.ts +3 -3
  41. package/dist/lattice-provenance.js +46 -97
  42. package/dist/monitoring-annotations.d.ts +2 -53
  43. package/dist/monitoring-annotations.js +2 -51
  44. package/dist/monitoring-contract.d.ts +5 -460
  45. package/dist/monitoring-contract.js +37 -77
  46. package/dist/monitoring-events.d.ts +2 -252
  47. package/dist/monitoring-events.js +15 -125
  48. package/dist/monitoring.d.ts +3 -3
  49. package/dist/monitoring.js +41 -41
  50. package/dist/orm.d.ts +10 -1
  51. package/dist/orm.js +27 -7
  52. package/dist/platform-client.d.ts +27 -0
  53. package/dist/platform-client.js +79 -0
  54. package/dist/platform-domains.d.ts +1671 -0
  55. package/dist/platform-domains.js +77 -0
  56. package/dist/processes-contract.d.ts +2 -149
  57. package/dist/processes-contract.js +17 -100
  58. package/dist/processes.d.ts +3 -3
  59. package/dist/processes.js +64 -49
  60. package/dist/runtime.cjs +4251 -1666
  61. package/dist/service-directory-roster.d.ts +12 -3
  62. package/dist/service-directory-roster.js +11 -17
  63. package/dist/service-directory.d.ts +4 -8
  64. package/dist/service-directory.js +16 -67
  65. package/dist/storage.d.ts +36 -35
  66. package/dist/storage.js +12 -5
  67. package/dist/workflow-source-contract.d.ts +2 -524
  68. package/dist/workflow-source-contract.js +16 -56
  69. package/dist/workflow-source.d.ts +3 -3
  70. package/dist/workflow-source.js +106 -43
  71. package/package.json +4 -3
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FUNCTION_PLATFORM_DOMAIN_HEADERS = void 0;
4
+ exports.createFunctionPlatformDomains = createFunctionPlatformDomains;
5
+ const directory_1 = require("./directory");
6
+ const agents_1 = require("./agents");
7
+ const agent_evidence_1 = require("./agent-evidence");
8
+ const workflow_source_1 = require("./workflow-source");
9
+ const monitoring_1 = require("./monitoring");
10
+ const abrigo_1 = require("./abrigo");
11
+ const storage_1 = require("./storage");
12
+ exports.FUNCTION_PLATFORM_DOMAIN_HEADERS = [
13
+ "x-sequence-directory-token",
14
+ "x-sequence-storage-token",
15
+ "x-sequence-storage-token-service",
16
+ "x-sequence-agent-evidence-token",
17
+ "x-sequence-workflow-service-token",
18
+ "x-sequence-workflow-evidence-token",
19
+ "x-sequence-monitoring-service-token",
20
+ "x-sequence-abrigo-read-token",
21
+ ];
22
+ function lazy(create) {
23
+ let value;
24
+ return () => (value ??= create());
25
+ }
26
+ function createFunctionPlatformDomains(context) {
27
+ const callerDirectory = lazy(() => (0, directory_1.createFunctionDirectoryClient)(context));
28
+ const agents = lazy(() => (0, agents_1.createFunctionServiceAgentsClient)(context));
29
+ const agentEvidence = lazy(() => (0, agent_evidence_1.createFunctionAgentEvidenceClient)(context));
30
+ const workflows = lazy(() => (0, workflow_source_1.createFunctionServiceWorkflowsClient)(context));
31
+ const workflowEvidence = lazy(() => (0, workflow_source_1.createFunctionWorkflowEvidenceClient)(context));
32
+ const monitoring = lazy(() => (0, monitoring_1.createFunctionServiceMonitoringClient)(context));
33
+ const abrigo = lazy(() => (0, abrigo_1.createFunctionCallerAbrigoClient)(context));
34
+ function storage(mode) {
35
+ const client = lazy(() => (0, storage_1.createFunctionStorageClient)({
36
+ baseUrl: context.baseUrl,
37
+ headers: context.request.headers,
38
+ mode,
39
+ fetchImpl: context.fetchImpl,
40
+ }));
41
+ return {
42
+ capabilities: async () => client().capabilities(),
43
+ list: async (options) => client().list(options),
44
+ shared: async (options) => client().shared(options),
45
+ apply: async (manifest) => client().apply(manifest),
46
+ workspace: (id) => client().workspace(id),
47
+ };
48
+ }
49
+ return {
50
+ callerDirectory: {
51
+ resolveMembers: async (query) => callerDirectory().resolveMembers(query),
52
+ },
53
+ agents: {
54
+ getCompletedRun: async (query) => agents().getCompletedRun(query),
55
+ captureCompletedRun: async (query) => agents().captureCompletedRun(query),
56
+ evidence: {
57
+ verifySourceEvidence: async (input) => agentEvidence().verifySourceEvidence(input),
58
+ verifyConversationEvidence: async (input) => agentEvidence().verifyConversationEvidence(input),
59
+ },
60
+ },
61
+ workflows: {
62
+ captureCompletedRun: async (query) => workflows().captureCompletedRun(query),
63
+ evidence: {
64
+ verifySourceEvidence: async (input) => workflowEvidence().verifySourceEvidence(input),
65
+ },
66
+ },
67
+ monitoring: {
68
+ publish: async (input) => monitoring().publish(input),
69
+ get: async (input) => monitoring().get(input),
70
+ getBucketCatalog: async (input) => monitoring().getBucketCatalog(input),
71
+ },
72
+ abrigo: {
73
+ read: async (input) => abrigo().read(input),
74
+ },
75
+ storage: { caller: storage("user"), service: storage("service") },
76
+ };
77
+ }
@@ -1,149 +1,2 @@
1
- import { z } from 'zod';
2
- export declare const FUNCTION_PROCESS_TOKEN_HEADER = "x-sequence-process-service-token";
3
- export declare const FUNCTION_PROCESS_READ_PATH = "/api/managed-functions/processes/read";
4
- export declare const functionProcessReadScopesSchema: z.ZodObject<{
5
- read: z.ZodArray<z.ZodString>;
6
- }, z.core.$strict>;
7
- export declare function readFunctionProcessScopes(manifest: unknown): string[];
8
- export declare const functionProcessRunStatusSchema: z.ZodEnum<{
9
- pending: "pending";
10
- running: "running";
11
- completed: "completed";
12
- failed: "failed";
13
- cancelled: "cancelled";
14
- timed_out: "timed_out";
15
- }>;
16
- export type FunctionProcessRunStatus = z.infer<typeof functionProcessRunStatusSchema>;
17
- export declare const functionProcessRunSummarySchema: z.ZodObject<{
18
- id: z.ZodString;
19
- processId: z.ZodString;
20
- status: z.ZodEnum<{
21
- pending: "pending";
22
- running: "running";
23
- completed: "completed";
24
- failed: "failed";
25
- cancelled: "cancelled";
26
- timed_out: "timed_out";
27
- }>;
28
- entityType: z.ZodNullable<z.ZodString>;
29
- entityId: z.ZodNullable<z.ZodString>;
30
- startedAt: z.ZodISODateTime;
31
- completedAt: z.ZodNullable<z.ZodISODateTime>;
32
- }, z.core.$strip>;
33
- export type FunctionProcessRunSummary = z.infer<typeof functionProcessRunSummarySchema>;
34
- export declare const functionProcessRunQuerySchema: z.ZodObject<{
35
- process: z.ZodString;
36
- runId: z.ZodString;
37
- }, z.core.$strict>;
38
- export declare const functionProcessRunsPageQuerySchema: z.ZodObject<{
39
- process: z.ZodString;
40
- statuses: z.ZodOptional<z.ZodArray<z.ZodEnum<{
41
- pending: "pending";
42
- running: "running";
43
- completed: "completed";
44
- failed: "failed";
45
- cancelled: "cancelled";
46
- timed_out: "timed_out";
47
- }>>>;
48
- entity: z.ZodOptional<z.ZodObject<{
49
- type: z.ZodString;
50
- id: z.ZodOptional<z.ZodString>;
51
- ids: z.ZodOptional<z.ZodArray<z.ZodString>>;
52
- }, z.core.$strict>>;
53
- limit: z.ZodOptional<z.ZodNumber>;
54
- cursor: z.ZodOptional<z.ZodString>;
55
- archived: z.ZodOptional<z.ZodBoolean>;
56
- }, z.core.$strict>;
57
- export type FunctionProcessRunQuery = z.infer<typeof functionProcessRunQuerySchema>;
58
- export declare const functionProcessCompletedNodeQuerySchema: z.ZodObject<{
59
- process: z.ZodString;
60
- runId: z.ZodString;
61
- nodeId: z.ZodString;
62
- }, z.core.$strict>;
63
- export type FunctionProcessCompletedNodeQuery = z.infer<typeof functionProcessCompletedNodeQuerySchema>;
64
- export declare const functionProcessCompletedNodeSchema: z.ZodObject<{
65
- runId: z.ZodString;
66
- processId: z.ZodString;
67
- processVersion: z.ZodString;
68
- nodeId: z.ZodString;
69
- stepId: z.ZodString;
70
- completedAt: z.ZodISODateTime;
71
- }, z.core.$strict>;
72
- export type FunctionProcessCompletedNode = z.infer<typeof functionProcessCompletedNodeSchema>;
73
- export declare const functionProcessCompletedAgentReferenceQuerySchema: z.ZodObject<{
74
- process: z.ZodString;
75
- runId: z.ZodString;
76
- nodeId: z.ZodString;
77
- }, z.core.$strict>;
78
- export type FunctionProcessCompletedAgentReferenceQuery = z.infer<typeof functionProcessCompletedAgentReferenceQuerySchema>;
79
- export declare const functionProcessCompletedAgentReferenceSchema: z.ZodObject<{
80
- stepId: z.ZodString;
81
- attempt: z.ZodNumber;
82
- agentId: z.ZodString;
83
- agentRunId: z.ZodString;
84
- threadId: z.ZodString;
85
- recoveryProof: z.ZodString;
86
- }, z.core.$strict>;
87
- export type FunctionProcessCompletedAgentReference = z.infer<typeof functionProcessCompletedAgentReferenceSchema>;
88
- export type FunctionProcessRunsPageQuery = z.infer<typeof functionProcessRunsPageQuerySchema>;
89
- export declare const functionProcessRunsPageSchema: z.ZodObject<{
90
- runs: z.ZodArray<z.ZodObject<{
91
- id: z.ZodString;
92
- processId: z.ZodString;
93
- status: z.ZodEnum<{
94
- pending: "pending";
95
- running: "running";
96
- completed: "completed";
97
- failed: "failed";
98
- cancelled: "cancelled";
99
- timed_out: "timed_out";
100
- }>;
101
- entityType: z.ZodNullable<z.ZodString>;
102
- entityId: z.ZodNullable<z.ZodString>;
103
- startedAt: z.ZodISODateTime;
104
- completedAt: z.ZodNullable<z.ZodISODateTime>;
105
- }, z.core.$strip>>;
106
- nextCursor: z.ZodNullable<z.ZodString>;
107
- }, z.core.$strip>;
108
- export type FunctionProcessRunsPage = z.infer<typeof functionProcessRunsPageSchema>;
109
- export declare const functionProcessReadRequestSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
110
- process: z.ZodString;
111
- runId: z.ZodString;
112
- operation: z.ZodLiteral<"getRun">;
113
- }, z.core.$strict>, z.ZodObject<{
114
- process: z.ZodString;
115
- runId: z.ZodString;
116
- nodeId: z.ZodString;
117
- operation: z.ZodLiteral<"getCompletedNode">;
118
- }, z.core.$strict>, z.ZodObject<{
119
- process: z.ZodString;
120
- runId: z.ZodString;
121
- nodeId: z.ZodString;
122
- operation: z.ZodLiteral<"getCompletedAgentReference">;
123
- }, z.core.$strict>, z.ZodObject<{
124
- process: z.ZodString;
125
- statuses: z.ZodOptional<z.ZodArray<z.ZodEnum<{
126
- pending: "pending";
127
- running: "running";
128
- completed: "completed";
129
- failed: "failed";
130
- cancelled: "cancelled";
131
- timed_out: "timed_out";
132
- }>>>;
133
- entity: z.ZodOptional<z.ZodObject<{
134
- type: z.ZodString;
135
- id: z.ZodOptional<z.ZodString>;
136
- ids: z.ZodOptional<z.ZodArray<z.ZodString>>;
137
- }, z.core.$strict>>;
138
- limit: z.ZodOptional<z.ZodNumber>;
139
- cursor: z.ZodOptional<z.ZodString>;
140
- archived: z.ZodOptional<z.ZodBoolean>;
141
- operation: z.ZodLiteral<"listRunsPage">;
142
- }, z.core.$strict>], "operation">;
143
- export type FunctionProcessReadRequest = z.infer<typeof functionProcessReadRequestSchema>;
144
- export declare class FunctionProcessReadError extends Error {
145
- readonly status: number;
146
- readonly code: string;
147
- readonly name = "FunctionProcessReadError";
148
- constructor(status: number, code: string, message: string);
149
- }
1
+ export { FUNCTION_PROCESS_TOKEN_HEADER, FUNCTION_PROCESS_READ_PATH, functionProcessReadScopesSchema, readFunctionProcessScopes, functionProcessRunStatusSchema, functionProcessRunSummarySchema, functionProcessRunQuerySchema, functionProcessRunsPageQuerySchema, functionProcessCompletedNodeQuerySchema, functionProcessCompletedNodeSchema, functionProcessCompletedAgentReferenceQuerySchema, functionProcessCompletedAgentReferenceSchema, functionProcessRunsPageSchema, functionProcessReadRequestSchema, FunctionProcessReadError, } from "@sequenceholdings/platform/contracts";
2
+ export type { FunctionProcessRunStatus, FunctionProcessRunSummary, FunctionProcessRunQuery, FunctionProcessCompletedNodeQuery, FunctionProcessCompletedNode, FunctionProcessCompletedAgentReferenceQuery, FunctionProcessCompletedAgentReference, FunctionProcessRunsPageQuery, FunctionProcessRunsPage, FunctionProcessReadRequest, } from "@sequenceholdings/platform/contracts";
@@ -1,102 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FunctionProcessReadError = exports.functionProcessReadRequestSchema = exports.functionProcessRunsPageSchema = exports.functionProcessCompletedAgentReferenceSchema = exports.functionProcessCompletedAgentReferenceQuerySchema = exports.functionProcessCompletedNodeSchema = exports.functionProcessCompletedNodeQuerySchema = exports.functionProcessRunsPageQuerySchema = exports.functionProcessRunQuerySchema = exports.functionProcessRunSummarySchema = exports.functionProcessRunStatusSchema = exports.functionProcessReadScopesSchema = exports.FUNCTION_PROCESS_READ_PATH = exports.FUNCTION_PROCESS_TOKEN_HEADER = void 0;
4
- exports.readFunctionProcessScopes = readFunctionProcessScopes;
5
- const zod_1 = require("zod");
6
- exports.FUNCTION_PROCESS_TOKEN_HEADER = 'x-sequence-process-service-token';
7
- exports.FUNCTION_PROCESS_READ_PATH = '/api/managed-functions/processes/read';
8
- const processId = zod_1.z
9
- .string()
10
- .min(1)
11
- .max(255)
12
- .regex(/^[A-Za-z0-9._-]+$/);
13
- const entityId = zod_1.z.string().min(1).max(255);
14
- exports.functionProcessReadScopesSchema = zod_1.z.strictObject({
15
- read: zod_1.z
16
- .array(processId)
17
- .min(1)
18
- .max(64)
19
- .refine((ids) => new Set(ids).size === ids.length, 'Process ids must be distinct')
20
- .refine((ids) => ids.reduce((bytes, id) => bytes + id.length, 0) <= 8192, 'Process ids must fit within 8192 bytes'),
21
- });
22
- function readFunctionProcessScopes(manifest) {
23
- if (typeof manifest !== 'object' || manifest === null)
24
- return [];
25
- const capabilities = Reflect.get(manifest, 'capabilities');
26
- if (typeof capabilities !== 'object' || capabilities === null)
27
- return [];
28
- const processes = Reflect.get(capabilities, 'processes');
29
- if (processes === undefined)
30
- return [];
31
- return exports.functionProcessReadScopesSchema.parse(processes).read;
32
- }
33
- exports.functionProcessRunStatusSchema = zod_1.z.enum([
34
- 'pending',
35
- 'running',
36
- 'completed',
37
- 'failed',
38
- 'cancelled',
39
- 'timed_out',
40
- ]);
41
- exports.functionProcessRunSummarySchema = zod_1.z.object({
42
- id: zod_1.z.string().min(1).max(255),
43
- processId,
44
- status: exports.functionProcessRunStatusSchema,
45
- entityType: zod_1.z.string().max(255).nullable(),
46
- entityId: zod_1.z.string().max(255).nullable(),
47
- startedAt: zod_1.z.iso.datetime({ offset: true }),
48
- completedAt: zod_1.z.iso.datetime({ offset: true }).nullable(),
49
- });
50
- exports.functionProcessRunQuerySchema = zod_1.z.strictObject({
51
- process: processId,
52
- runId: zod_1.z.string().min(1).max(255),
53
- });
54
- exports.functionProcessRunsPageQuerySchema = zod_1.z.strictObject({
55
- process: processId,
56
- statuses: zod_1.z.array(exports.functionProcessRunStatusSchema).min(1).max(6).optional(),
57
- entity: zod_1.z
58
- .strictObject({
59
- type: entityId,
60
- id: entityId.optional(),
61
- ids: zod_1.z.array(entityId).min(1).max(500).optional(),
62
- })
63
- .refine((value) => value.id === undefined || value.ids === undefined, 'Name one entity id or a set, not both')
64
- .optional(),
65
- limit: zod_1.z.number().int().min(1).max(500).optional(),
66
- cursor: zod_1.z.string().min(1).max(8192).optional(),
67
- archived: zod_1.z.boolean().optional(),
68
- });
69
- exports.functionProcessCompletedNodeQuerySchema = exports.functionProcessRunQuerySchema.extend({ nodeId: entityId });
70
- exports.functionProcessCompletedNodeSchema = zod_1.z.strictObject({
71
- runId: entityId, processId, processVersion: entityId, nodeId: entityId, stepId: entityId,
72
- completedAt: zod_1.z.iso.datetime({ offset: true }),
73
- });
74
- exports.functionProcessCompletedAgentReferenceQuerySchema = exports.functionProcessRunQuerySchema.extend({ nodeId: entityId });
75
- exports.functionProcessCompletedAgentReferenceSchema = zod_1.z.strictObject({
76
- stepId: entityId, attempt: zod_1.z.number().int().positive().max(Number.MAX_SAFE_INTEGER),
77
- agentId: entityId, agentRunId: entityId, threadId: entityId,
78
- recoveryProof: zod_1.z.string().min(1).max(16_384),
79
- });
80
- exports.functionProcessRunsPageSchema = zod_1.z.object({
81
- runs: zod_1.z.array(exports.functionProcessRunSummarySchema).max(500),
82
- nextCursor: zod_1.z.string().nullable(),
83
- });
84
- exports.functionProcessReadRequestSchema = zod_1.z.discriminatedUnion('operation', [
85
- exports.functionProcessRunQuerySchema.extend({ operation: zod_1.z.literal('getRun') }),
86
- exports.functionProcessCompletedNodeQuerySchema.extend({ operation: zod_1.z.literal('getCompletedNode') }),
87
- exports.functionProcessCompletedAgentReferenceQuerySchema.extend({ operation: zod_1.z.literal('getCompletedAgentReference') }),
88
- exports.functionProcessRunsPageQuerySchema.extend({
89
- operation: zod_1.z.literal('listRunsPage'),
90
- }),
91
- ]);
92
- class FunctionProcessReadError extends Error {
93
- status;
94
- code;
95
- name = 'FunctionProcessReadError';
96
- constructor(status, code, message) {
97
- super(message);
98
- this.status = status;
99
- this.code = code;
100
- }
101
- }
102
- exports.FunctionProcessReadError = FunctionProcessReadError;
3
+ exports.FunctionProcessReadError = exports.functionProcessReadRequestSchema = exports.functionProcessRunsPageSchema = exports.functionProcessCompletedAgentReferenceSchema = exports.functionProcessCompletedAgentReferenceQuerySchema = exports.functionProcessCompletedNodeSchema = exports.functionProcessCompletedNodeQuerySchema = exports.functionProcessRunsPageQuerySchema = exports.functionProcessRunQuerySchema = exports.functionProcessRunSummarySchema = exports.functionProcessRunStatusSchema = exports.readFunctionProcessScopes = exports.functionProcessReadScopesSchema = exports.FUNCTION_PROCESS_READ_PATH = exports.FUNCTION_PROCESS_TOKEN_HEADER = void 0;
4
+ var contracts_1 = require("@sequenceholdings/platform/contracts");
5
+ Object.defineProperty(exports, "FUNCTION_PROCESS_TOKEN_HEADER", { enumerable: true, get: function () { return contracts_1.FUNCTION_PROCESS_TOKEN_HEADER; } });
6
+ Object.defineProperty(exports, "FUNCTION_PROCESS_READ_PATH", { enumerable: true, get: function () { return contracts_1.FUNCTION_PROCESS_READ_PATH; } });
7
+ Object.defineProperty(exports, "functionProcessReadScopesSchema", { enumerable: true, get: function () { return contracts_1.functionProcessReadScopesSchema; } });
8
+ Object.defineProperty(exports, "readFunctionProcessScopes", { enumerable: true, get: function () { return contracts_1.readFunctionProcessScopes; } });
9
+ Object.defineProperty(exports, "functionProcessRunStatusSchema", { enumerable: true, get: function () { return contracts_1.functionProcessRunStatusSchema; } });
10
+ Object.defineProperty(exports, "functionProcessRunSummarySchema", { enumerable: true, get: function () { return contracts_1.functionProcessRunSummarySchema; } });
11
+ Object.defineProperty(exports, "functionProcessRunQuerySchema", { enumerable: true, get: function () { return contracts_1.functionProcessRunQuerySchema; } });
12
+ Object.defineProperty(exports, "functionProcessRunsPageQuerySchema", { enumerable: true, get: function () { return contracts_1.functionProcessRunsPageQuerySchema; } });
13
+ Object.defineProperty(exports, "functionProcessCompletedNodeQuerySchema", { enumerable: true, get: function () { return contracts_1.functionProcessCompletedNodeQuerySchema; } });
14
+ Object.defineProperty(exports, "functionProcessCompletedNodeSchema", { enumerable: true, get: function () { return contracts_1.functionProcessCompletedNodeSchema; } });
15
+ Object.defineProperty(exports, "functionProcessCompletedAgentReferenceQuerySchema", { enumerable: true, get: function () { return contracts_1.functionProcessCompletedAgentReferenceQuerySchema; } });
16
+ Object.defineProperty(exports, "functionProcessCompletedAgentReferenceSchema", { enumerable: true, get: function () { return contracts_1.functionProcessCompletedAgentReferenceSchema; } });
17
+ Object.defineProperty(exports, "functionProcessRunsPageSchema", { enumerable: true, get: function () { return contracts_1.functionProcessRunsPageSchema; } });
18
+ Object.defineProperty(exports, "functionProcessReadRequestSchema", { enumerable: true, get: function () { return contracts_1.functionProcessReadRequestSchema; } });
19
+ Object.defineProperty(exports, "FunctionProcessReadError", { enumerable: true, get: function () { return contracts_1.FunctionProcessReadError; } });
@@ -1,6 +1,6 @@
1
- import { type FunctionProcessCompletedNode, type FunctionProcessCompletedNodeQuery, type FunctionProcessCompletedAgentReference, type FunctionProcessCompletedAgentReferenceQuery, type FunctionProcessRunQuery, type FunctionProcessRunSummary, type FunctionProcessRunsPage, type FunctionProcessRunsPageQuery } from './processes-contract';
2
- import { type FunctionInvocationClientOptions } from './invocation-client';
3
- export * from './processes-contract';
1
+ import { type FunctionProcessCompletedNode, type FunctionProcessCompletedNodeQuery, type FunctionProcessCompletedAgentReference, type FunctionProcessCompletedAgentReferenceQuery, type FunctionProcessRunQuery, type FunctionProcessRunSummary, type FunctionProcessRunsPage, type FunctionProcessRunsPageQuery } from "./processes-contract";
2
+ import { type FunctionInvocationClientOptions } from "./invocation-client";
3
+ export * from "./processes-contract";
4
4
  export type FunctionServiceProcessesOptions = FunctionInvocationClientOptions;
5
5
  export interface FunctionServiceProcessesClient {
6
6
  getCompletedNode(query: FunctionProcessCompletedNodeQuery): Promise<FunctionProcessCompletedNode>;
package/dist/processes.js CHANGED
@@ -15,35 +15,49 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.createFunctionServiceProcessesClient = createFunctionServiceProcessesClient;
18
+ const browser_1 = require("@sequenceholdings/platform/browser");
18
19
  const zod_1 = require("zod");
19
20
  const processes_contract_1 = require("./processes-contract");
20
21
  const invocation_client_1 = require("./invocation-client");
21
22
  const agents_contract_1 = require("./agents-contract");
22
23
  __exportStar(require("./processes-contract"), exports);
23
- function readAgentCredential({ request }) {
24
+ function readAgentCredential({ request, }) {
24
25
  const { headers } = request;
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);
26
+ const matches = typeof headers.get === "function"
27
+ ? [headers.get(agents_contract_1.FUNCTION_AGENT_TOKEN_HEADER)]
28
+ : Object.entries(headers)
29
+ .filter(([name]) => name.toLowerCase() === agents_contract_1.FUNCTION_AGENT_TOKEN_HEADER)
30
+ .map(([, value]) => value);
27
31
  const token = matches[0];
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)
32
+ const denied = () => new processes_contract_1.FunctionProcessReadError(401, "invalid_context", "Completed-agent reference lookup requires an agent-read credential");
33
+ if (matches.length !== 1 ||
34
+ typeof token !== "string" ||
35
+ token.length > 16_384)
30
36
  throw denied();
31
37
  const body = /^([A-Za-z0-9_-]+)\.[A-Za-z0-9_-]{43}$/.exec(token)?.[1];
32
38
  if (!body)
33
39
  throw denied();
34
40
  let value;
35
41
  try {
36
- value = JSON.parse(Buffer.from(body, 'base64url').toString('utf8'));
42
+ value = JSON.parse(Buffer.from(body, "base64url").toString("utf8"));
37
43
  }
38
44
  catch {
39
45
  throw denied();
40
46
  }
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);
47
+ const claims = zod_1.z
48
+ .object({
49
+ audience: zod_1.z.literal("atlas-managed-function-agent-read"),
50
+ sub: zod_1.z.string().startsWith("service-account|"),
51
+ functionId: zod_1.z.string().min(1),
52
+ invocationId: zod_1.z.string().min(1),
53
+ exp: zod_1.z.number().int(),
54
+ })
55
+ .safeParse(value);
42
56
  if (!claims.success)
43
57
  throw denied();
44
58
  return { token, expiresAt: claims.data.exp };
45
59
  }
46
- const invalidContext = () => new processes_contract_1.FunctionProcessReadError(401, 'invalid_context', 'This invocation has no valid process-read credential');
60
+ const invalidContext = () => new processes_contract_1.FunctionProcessReadError(401, "invalid_context", "This invocation has no valid process-read credential");
47
61
  function createFunctionServiceProcessesClient({ request, baseUrl, fetchImpl = globalThis.fetch, }) {
48
62
  const credential = (0, invocation_client_1.readInvocationCredential)({
49
63
  request,
@@ -51,58 +65,59 @@ function createFunctionServiceProcessesClient({ request, baseUrl, fetchImpl = gl
51
65
  maxBytes: 16_384,
52
66
  invalidContext,
53
67
  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|'),
68
+ audience: zod_1.z.literal("atlas-managed-function-process-read"),
69
+ sub: zod_1.z.string().startsWith("service-account|"),
56
70
  functionId: zod_1.z.string().min(1),
57
71
  invocationId: zod_1.z.string().min(1),
58
72
  exp: zod_1.z.number().int(),
59
73
  }),
60
74
  });
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 });
75
+ let shared;
76
+ try {
77
+ shared = (0, browser_1.createLatticeReadClient)({
78
+ transport: (0, browser_1.createPlatformTransport)({
79
+ baseUrl,
80
+ fetchImpl,
81
+ auth: { kind: "invocation-process", token: credential.token },
82
+ }),
83
+ });
84
+ }
85
+ catch (error) {
86
+ if (error instanceof processes_contract_1.FunctionProcessReadError)
87
+ throw error;
88
+ if (error instanceof browser_1.PlatformError)
89
+ throw new processes_contract_1.FunctionProcessReadError(error.status, error.code, error.message);
90
+ throw error;
91
+ }
72
92
  return {
73
- async getCompletedNode(query) {
74
- const proof = await read({ body: { ...query, operation: 'getCompletedNode' }, schema: processes_contract_1.functionProcessCompletedNodeSchema });
75
- if (proof.runId !== query.runId || proof.processId !== query.process || proof.nodeId !== query.nodeId)
76
- throw new processes_contract_1.FunctionProcessReadError(502, 'malformed_response', 'Atlas returned a different completed node');
77
- return proof;
78
- },
93
+ getCompletedNode: shared.completedNodes.get,
94
+ getRun: shared.runs.get,
95
+ listRunsPage: shared.runs.listPage,
79
96
  async getCompletedAgentReference(query) {
80
97
  const agent = readAgentCredential({ request });
81
98
  const readReference = (0, invocation_client_1.createInvocationReadTransport)({
82
- baseUrl, fetchImpl, path: processes_contract_1.FUNCTION_PROCESS_READ_PATH, header: processes_contract_1.FUNCTION_PROCESS_TOKEN_HEADER,
83
- credential, additionalCredentials: [{ header: agents_contract_1.FUNCTION_AGENT_TOKEN_HEADER, credential: agent }],
84
- timeoutMs: 30_000, error: (status, code, message) => new processes_contract_1.FunctionProcessReadError(status, code, message),
85
- failure: { code: 'process_read_failed', message: 'Process read failed' },
86
- });
87
- return readReference({ body: processes_contract_1.functionProcessReadRequestSchema.parse({ ...query, operation: 'getCompletedAgentReference' }), schema: processes_contract_1.functionProcessCompletedAgentReferenceSchema });
88
- },
89
- async getRun(query) {
90
- const run = await read({
91
- body: { ...query, operation: 'getRun' },
92
- schema: processes_contract_1.functionProcessRunSummarySchema,
99
+ baseUrl,
100
+ fetchImpl,
101
+ path: processes_contract_1.FUNCTION_PROCESS_READ_PATH,
102
+ header: processes_contract_1.FUNCTION_PROCESS_TOKEN_HEADER,
103
+ credential,
104
+ additionalCredentials: [
105
+ { header: agents_contract_1.FUNCTION_AGENT_TOKEN_HEADER, credential: agent },
106
+ ],
107
+ timeoutMs: 30_000,
108
+ error: (status, code, message) => new processes_contract_1.FunctionProcessReadError(status, code, message),
109
+ failure: {
110
+ code: "process_read_failed",
111
+ message: "Process read failed",
112
+ },
93
113
  });
94
- if (run.id !== query.runId || run.processId !== query.process)
95
- throw new processes_contract_1.FunctionProcessReadError(502, 'malformed_response', 'Atlas returned a different process run');
96
- return run;
97
- },
98
- async listRunsPage(query) {
99
- const page = await read({
100
- body: { ...query, operation: 'listRunsPage' },
101
- schema: processes_contract_1.functionProcessRunsPageSchema,
114
+ return readReference({
115
+ body: processes_contract_1.functionProcessReadRequestSchema.parse({
116
+ ...query,
117
+ operation: "getCompletedAgentReference",
118
+ }),
119
+ schema: processes_contract_1.functionProcessCompletedAgentReferenceSchema,
102
120
  });
103
- if (page.runs.some((run) => run.processId !== query.process))
104
- throw new processes_contract_1.FunctionProcessReadError(502, 'malformed_response', 'Atlas returned runs from a different process');
105
- return page;
106
121
  },
107
122
  };
108
123
  }