@sequenceholdings/managed-functions 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +374 -2
  2. package/dist/abrigo-contract.d.ts +92 -0
  3. package/dist/abrigo-contract.js +55 -0
  4. package/dist/abrigo-response.d.ts +6 -0
  5. package/dist/abrigo-response.js +27 -0
  6. package/dist/abrigo.d.ts +14 -0
  7. package/dist/abrigo.js +150 -0
  8. package/dist/agent-evidence.d.ts +9 -0
  9. package/dist/agent-evidence.js +84 -0
  10. package/dist/agent-source-evidence-contract.d.ts +1197 -0
  11. package/dist/agent-source-evidence-contract.js +96 -0
  12. package/dist/agents-contract.d.ts +99 -0
  13. package/dist/agents-contract.js +69 -0
  14. package/dist/agents.d.ts +15 -0
  15. package/dist/agents.js +121 -0
  16. package/dist/capabilities.d.ts +150 -0
  17. package/dist/capabilities.js +58 -5
  18. package/dist/config.d.ts +17 -2
  19. package/dist/config.js +55 -1
  20. package/dist/deployed-policy.js +90 -2
  21. package/dist/directory-config.js +1 -1
  22. package/dist/directory-contract.d.ts +68 -0
  23. package/dist/directory-contract.js +57 -0
  24. package/dist/directory-manifest.d.ts +5 -0
  25. package/dist/directory-manifest.js +10 -0
  26. package/dist/http-tracing.js +3 -0
  27. package/dist/immutable-release-contract.d.ts +3 -0
  28. package/dist/immutable-release-contract.js +12 -0
  29. package/dist/index.d.ts +37 -1
  30. package/dist/index.js +72 -1
  31. package/dist/invocation-client.d.ts +8 -1
  32. package/dist/invocation-client.js +8 -3
  33. package/dist/invocation-contract.d.ts +36 -0
  34. package/dist/invocation-contract.js +48 -0
  35. package/dist/invocation.d.ts +8 -0
  36. package/dist/invocation.js +134 -0
  37. package/dist/lattice-capability.d.ts +5 -0
  38. package/dist/lattice-capability.js +16 -0
  39. package/dist/lattice-provenance-contract.d.ts +519 -0
  40. package/dist/lattice-provenance-contract.js +148 -0
  41. package/dist/lattice-provenance.d.ts +16 -0
  42. package/dist/lattice-provenance.js +167 -0
  43. package/dist/monitoring-annotations.d.ts +53 -0
  44. package/dist/monitoring-annotations.js +54 -0
  45. package/dist/monitoring-contract.d.ts +463 -0
  46. package/dist/monitoring-contract.js +89 -0
  47. package/dist/monitoring-events.d.ts +257 -0
  48. package/dist/monitoring-events.js +136 -0
  49. package/dist/monitoring.d.ts +14 -0
  50. package/dist/monitoring.js +78 -0
  51. package/dist/orm-contract.d.ts +1 -0
  52. package/dist/orm-contract.js +4 -0
  53. package/dist/orm.d.ts +19 -3
  54. package/dist/orm.js +93 -13
  55. package/dist/preflight-abrigo.d.ts +10 -0
  56. package/dist/preflight-abrigo.js +26 -0
  57. package/dist/preflight-agents.d.ts +10 -0
  58. package/dist/preflight-agents.js +51 -0
  59. package/dist/preflight-immutable-release.d.ts +10 -0
  60. package/dist/preflight-immutable-release.js +34 -0
  61. package/dist/preflight-invocation.d.ts +10 -0
  62. package/dist/preflight-invocation.js +40 -0
  63. package/dist/preflight-lattice.d.ts +10 -0
  64. package/dist/preflight-lattice.js +40 -0
  65. package/dist/preflight-monitoring.d.ts +10 -0
  66. package/dist/preflight-monitoring.js +46 -0
  67. package/dist/preflight-service-directory.d.ts +10 -0
  68. package/dist/preflight-service-directory.js +26 -0
  69. package/dist/preflight-workflows.d.ts +10 -0
  70. package/dist/preflight-workflows.js +38 -0
  71. package/dist/preflight.js +49 -5
  72. package/dist/processes-contract.d.ts +20 -0
  73. package/dist/processes-contract.js +8 -1
  74. package/dist/processes.d.ts +2 -1
  75. package/dist/processes.js +34 -0
  76. package/dist/runtime.cjs +3111 -214
  77. package/dist/sdk-range.d.ts +1 -0
  78. package/dist/sdk-range.js +25 -0
  79. package/dist/service-directory.d.ts +12 -0
  80. package/dist/service-directory.js +72 -0
  81. package/dist/workflow-scopes-contract.d.ts +8 -0
  82. package/dist/workflow-scopes-contract.js +29 -0
  83. package/dist/workflow-source-contract.d.ts +524 -0
  84. package/dist/workflow-source-contract.js +59 -0
  85. package/dist/workflow-source.d.ts +12 -0
  86. package/dist/workflow-source.js +93 -0
  87. package/package.json +2 -2
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.functionAgentSourceEvidenceVerificationSchema = exports.functionAgentSourceEvidenceRequestSchema = exports.functionAgentSourceEvidenceClaimsSchema = exports.functionAgentHumanConversationEvidenceClaimsSchema = exports.functionAgentRunSourceEvidenceClaimsSchema = exports.functionAgentManagedFunctionSourceEvidenceClaimsSchema = exports.functionAgentHumanSourceEvidenceClaimsSchema = exports.functionAgentConversationEvidenceRequestSchema = exports.functionAgentConversationEvidenceQuerySchema = exports.functionAgentConversationEvidenceCaptureSchema = exports.functionAgentConversationEvidenceResponseSchema = exports.functionAgentSourceEvidenceCaptureSchema = exports.functionAgentSourceResponseSchema = exports.functionAgentConversationResponseSchema = exports.functionAgentSourceExecutionSchema = exports.functionSourceJobAdmissionSchema = exports.AGENT_SOURCE_VERIFY_MAX_BYTES = exports.AGENT_SOURCE_RESPONSE_MAX_BYTES = exports.FUNCTION_AGENT_EVIDENCE_PATH = exports.FUNCTION_AGENT_EVIDENCE_TOKEN_HEADER = exports.functionAgentEvidenceScopesSchema = void 0;
4
+ exports.readFunctionAgentEvidenceScopes = readFunctionAgentEvidenceScopes;
5
+ const zod_1 = require("zod");
6
+ const agents_contract_1 = require("./agents-contract");
7
+ var agents_contract_2 = require("./agents-contract");
8
+ Object.defineProperty(exports, "functionAgentEvidenceScopesSchema", { enumerable: true, get: function () { return agents_contract_2.functionAgentEvidenceScopesSchema; } });
9
+ exports.FUNCTION_AGENT_EVIDENCE_TOKEN_HEADER = 'x-sequence-agent-evidence-token';
10
+ exports.FUNCTION_AGENT_EVIDENCE_PATH = '/api/managed-functions/agents/evidence';
11
+ exports.AGENT_SOURCE_RESPONSE_MAX_BYTES = 512 * 1024;
12
+ exports.AGENT_SOURCE_VERIFY_MAX_BYTES = 768 * 1024;
13
+ const identifier = zod_1.z.string().min(1).max(255);
14
+ const hash = zod_1.z.string().regex(/^[a-f0-9]{64}$/);
15
+ exports.functionSourceJobAdmissionSchema = zod_1.z.strictObject({
16
+ idempotencyKey: zod_1.z.string().min(1).max(128).regex(/^[\x21-\x7e]+$/), requestHash: hash,
17
+ kind: zod_1.z.enum(['agent', 'workflow']), resourceId: identifier, actorSub: zod_1.z.string().min(1).max(512),
18
+ runId: identifier, executionSnapshotId: zod_1.z.uuid(),
19
+ });
20
+ exports.functionAgentSourceExecutionSchema = zod_1.z.strictObject({
21
+ run: zod_1.z.strictObject({ id: identifier, processId: identifier, processVersion: identifier, bundleHash: identifier, entity: zod_1.z.strictObject({ type: identifier, id: identifier }).nullable() }),
22
+ step: zod_1.z.strictObject({ id: identifier, nodeId: identifier, attempt: zod_1.z.number().int().positive() }),
23
+ agent: zod_1.z.strictObject({ id: identifier, runId: identifier, threadId: identifier, identity: zod_1.z.strictObject({ id: identifier, version: identifier, definitionSha256: hash }) }),
24
+ }).refine((source) => source.agent.id === source.agent.identity.id, 'The source agent must match its private execution identity');
25
+ function readFunctionAgentEvidenceScopes(manifest) {
26
+ if (typeof manifest !== 'object' || manifest === null)
27
+ return [];
28
+ const capabilities = Reflect.get(manifest, 'capabilities');
29
+ if (typeof capabilities !== 'object' || capabilities === null)
30
+ return [];
31
+ const agents = Reflect.get(capabilities, 'agents');
32
+ if (typeof agents !== 'object' || agents === null)
33
+ return [];
34
+ const evidence = Reflect.get(agents, 'evidence');
35
+ return evidence === undefined ? [] : agents_contract_1.functionAgentEvidenceScopesSchema.parse(evidence);
36
+ }
37
+ const textPart = zod_1.z.strictObject({ type: zod_1.z.literal('text'), text: zod_1.z.string() });
38
+ const toolPart = zod_1.z.strictObject({
39
+ type: zod_1.z.string().min(1).max(255).refine((type) => type !== 'tool-result' && (type === 'dynamic-tool' || type === 'tool-invocation' || type.startsWith('tool-')), 'Only tool parts are permitted'),
40
+ toolName: zod_1.z.string().max(255).optional(), name: zod_1.z.string().max(255).optional(), toolCallId: identifier.optional(), state: zod_1.z.string().max(255).optional(),
41
+ input: zod_1.z.json().optional(), output: zod_1.z.json().optional(),
42
+ });
43
+ exports.functionAgentConversationResponseSchema = agents_contract_1.functionAgentCompletedRunSchema.extend({
44
+ context: zod_1.z.strictObject({
45
+ messages: zod_1.z.array(zod_1.z.strictObject({ id: identifier, role: zod_1.z.enum(['user', 'assistant']), parts: zod_1.z.array(zod_1.z.union([textPart, toolPart])).max(1000), metadata: zod_1.z.strictObject({ citations: zod_1.z.array(zod_1.z.json()).max(1000) }).optional() })).max(1000),
46
+ compactionSummary: zod_1.z.string().nullable(),
47
+ }),
48
+ });
49
+ exports.functionAgentSourceResponseSchema = zod_1.z.union([agents_contract_1.functionAgentCompletedRunSchema, exports.functionAgentConversationResponseSchema]);
50
+ exports.functionAgentSourceEvidenceCaptureSchema = zod_1.z.strictObject({ response: exports.functionAgentSourceResponseSchema, responseHash: hash, sourceReceipt: zod_1.z.string().min(1).max(16_384) });
51
+ const conversationRevision = zod_1.z.number().int().min(1).max(Number.MAX_SAFE_INTEGER);
52
+ exports.functionAgentConversationEvidenceResponseSchema = zod_1.z.strictObject({
53
+ agent: identifier, threadId: identifier, revision: conversationRevision, cutoffAt: zod_1.z.iso.datetime({ offset: true }),
54
+ context: exports.functionAgentConversationResponseSchema.shape.context.extend({ compactionSummary: zod_1.z.null() }),
55
+ conversation: agents_contract_1.functionAgentCompletedRunSchema.shape.conversation.unwrap(),
56
+ });
57
+ exports.functionAgentConversationEvidenceCaptureSchema = zod_1.z.strictObject({ response: exports.functionAgentConversationEvidenceResponseSchema, responseHash: hash, sourceReceipt: zod_1.z.string().min(1).max(16_384) });
58
+ exports.functionAgentConversationEvidenceQuerySchema = zod_1.z.strictObject({ agent: identifier, threadId: identifier });
59
+ exports.functionAgentConversationEvidenceRequestSchema = exports.functionAgentConversationEvidenceQuerySchema.extend({ operation: zod_1.z.literal('verifyConversationEvidence'), response: exports.functionAgentConversationEvidenceResponseSchema, responseHash: hash, sourceReceipt: zod_1.z.string().min(1).max(16_384) });
60
+ const sourceEvidenceFields = {
61
+ environment: zod_1.z.string(), org: identifier, agentId: identifier, runId: identifier, threadId: identifier,
62
+ familyRunIds: zod_1.z.array(identifier).min(1).max(16), cutoffAt: zod_1.z.iso.datetime({ offset: true }),
63
+ responseHash: hash, sourceExecution: exports.functionAgentSourceExecutionSchema.nullable(), jobAdmission: exports.functionSourceJobAdmissionSchema.nullable(),
64
+ };
65
+ exports.functionAgentHumanSourceEvidenceClaimsSchema = zod_1.z.strictObject({
66
+ ...sourceEvidenceFields, sourceKind: zod_1.z.literal('human'), audience: zod_1.z.literal('atlas-agent-source-evidence'),
67
+ actualUserSub: zod_1.z.string().min(1).max(512).refine((sub) => !sub.startsWith('service-account|'), 'Human source evidence requires a user principal'),
68
+ projection: zod_1.z.enum(['completed-v1', 'conversation-v1']),
69
+ });
70
+ exports.functionAgentManagedFunctionSourceEvidenceClaimsSchema = zod_1.z.strictObject({
71
+ ...sourceEvidenceFields, sourceKind: zod_1.z.literal('managed_function'), audience: zod_1.z.literal('atlas-managed-function-source-evidence'),
72
+ actualServiceAccountSub: zod_1.z.string().min(1).max(512), projection: zod_1.z.literal('completed-v1'),
73
+ sourceReceiver: zod_1.z.strictObject({ functionId: zod_1.z.uuid(), versionId: zod_1.z.uuid(), invocationId: zod_1.z.uuid(), serviceAccountId: zod_1.z.uuid(), org: identifier }),
74
+ }).refine((source) => source.actualServiceAccountSub === `service-account|${source.sourceReceiver.serviceAccountId}` && source.org === source.sourceReceiver.org, 'The service source must match its actual invocation identity');
75
+ exports.functionAgentRunSourceEvidenceClaimsSchema = zod_1.z.discriminatedUnion('sourceKind', [exports.functionAgentHumanSourceEvidenceClaimsSchema, exports.functionAgentManagedFunctionSourceEvidenceClaimsSchema])
76
+ .refine((source) => source.familyRunIds.includes(source.runId) && new Set(source.familyRunIds).size === source.familyRunIds.length, 'The source family must contain its run and be distinct')
77
+ .refine((source) => source.sourceExecution === null || (source.sourceExecution.agent.id === source.agentId && source.sourceExecution.agent.runId === source.runId && source.sourceExecution.agent.threadId === source.threadId), 'The execution origin must match the captured source')
78
+ .refine((source) => source.jobAdmission === null || (source.jobAdmission.kind === 'agent' && source.jobAdmission.runId === source.runId && source.jobAdmission.resourceId === source.agentId && (source.sourceKind === 'human' || source.jobAdmission.actorSub === source.actualServiceAccountSub)), 'The job admission must match the captured source');
79
+ exports.functionAgentHumanConversationEvidenceClaimsSchema = zod_1.z.strictObject({
80
+ sourceKind: zod_1.z.literal('human'), projection: zod_1.z.literal('thread-conversation-v1'), audience: zod_1.z.literal('atlas-agent-source-evidence'),
81
+ actualUserSub: zod_1.z.string().min(1).max(512).refine((sub) => !sub.startsWith('service-account|'), 'Human conversation evidence requires a user principal'),
82
+ environment: zod_1.z.string(), org: identifier, agentId: identifier, threadId: identifier,
83
+ revision: conversationRevision, cutoffAt: zod_1.z.iso.datetime({ offset: true }), responseHash: hash,
84
+ });
85
+ exports.functionAgentSourceEvidenceClaimsSchema = zod_1.z.union([exports.functionAgentRunSourceEvidenceClaimsSchema, exports.functionAgentHumanConversationEvidenceClaimsSchema]);
86
+ exports.functionAgentSourceEvidenceRequestSchema = zod_1.z.strictObject({ operation: zod_1.z.literal('verifySourceEvidence'), agent: identifier, runId: identifier, response: exports.functionAgentSourceResponseSchema, responseHash: hash, sourceReceipt: zod_1.z.string().min(1).max(16_384) });
87
+ exports.functionAgentSourceEvidenceVerificationSchema = zod_1.z.strictObject({
88
+ source: exports.functionAgentSourceEvidenceClaimsSchema,
89
+ receiver: zod_1.z.strictObject({ functionId: identifier, versionId: identifier, invocationId: identifier, serviceAccountId: identifier, org: identifier }),
90
+ lattice: zod_1.z.strictObject({
91
+ receiverFunctionOrgId: identifier,
92
+ run: zod_1.z.strictObject({ id: identifier, processId: identifier, processVersion: identifier, bundleHash: identifier, entity: zod_1.z.strictObject({ type: identifier, id: identifier }).nullable() }),
93
+ step: zod_1.z.strictObject({ id: identifier, nodeId: identifier, attempt: zod_1.z.number().int().positive(), runAsServiceAccount: zod_1.z.string().nullable() }),
94
+ receiver: zod_1.z.strictObject({ functionId: identifier, versionId: identifier, invocationId: identifier }),
95
+ }).nullable(),
96
+ });
@@ -0,0 +1,99 @@
1
+ import { z } from 'zod';
2
+ export declare const FUNCTION_AGENT_TOKEN_HEADER = "x-sequence-agent-service-token";
3
+ export declare const FUNCTION_AGENT_READ_PATH = "/api/managed-functions/agents/read";
4
+ export declare const FUNCTION_AGENT_CAPTURE_PATH = "/api/managed-functions/agents/capture";
5
+ export declare const functionAgentEvidenceScopesSchema: z.ZodArray<z.ZodString>;
6
+ export declare const functionAgentReadScopesSchema: z.ZodObject<{
7
+ read: z.ZodOptional<z.ZodArray<z.ZodString>>;
8
+ evidence: z.ZodOptional<z.ZodArray<z.ZodString>>;
9
+ }, z.core.$strict>;
10
+ export declare function readFunctionAgentScopes(manifest: unknown): string[];
11
+ export declare const functionAgentCompletedRunQuerySchema: z.ZodObject<{
12
+ agent: z.ZodString;
13
+ runId: z.ZodString;
14
+ recoveryProof: z.ZodOptional<z.ZodString>;
15
+ }, z.core.$strict>;
16
+ export type FunctionAgentCompletedRunQuery = z.infer<typeof functionAgentCompletedRunQuerySchema>;
17
+ export declare const functionAgentReadRequestSchema: z.ZodObject<{
18
+ agent: z.ZodString;
19
+ runId: z.ZodString;
20
+ recoveryProof: z.ZodOptional<z.ZodString>;
21
+ operation: z.ZodLiteral<"getCompletedRun">;
22
+ }, z.core.$strict>;
23
+ export declare const functionAgentMessageSchema: z.ZodObject<{
24
+ id: z.ZodString;
25
+ role: z.ZodLiteral<"assistant">;
26
+ parts: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
27
+ type: z.ZodLiteral<"text">;
28
+ text: z.ZodString;
29
+ }, z.core.$strict>, z.ZodObject<{
30
+ type: z.ZodLiteral<"dynamic-tool">;
31
+ output: z.ZodObject<{
32
+ content: z.ZodArray<z.ZodObject<{
33
+ type: z.ZodLiteral<"resource">;
34
+ resource: z.ZodObject<{
35
+ uri: z.ZodString;
36
+ text: z.ZodString;
37
+ }, z.core.$strict>;
38
+ }, z.core.$strict>>;
39
+ }, z.core.$strict>;
40
+ }, z.core.$strict>]>>;
41
+ metadata: z.ZodOptional<z.ZodObject<{
42
+ citations: z.ZodArray<z.ZodJSONSchema>;
43
+ }, z.core.$strict>>;
44
+ }, z.core.$strict>;
45
+ export declare const functionAgentCompletedRunSchema: z.ZodObject<{
46
+ runId: z.ZodString;
47
+ agent: z.ZodString;
48
+ threadId: z.ZodString;
49
+ status: z.ZodLiteral<"completed">;
50
+ output: z.ZodJSONSchema;
51
+ messages: z.ZodArray<z.ZodObject<{
52
+ id: z.ZodString;
53
+ role: z.ZodLiteral<"assistant">;
54
+ parts: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
55
+ type: z.ZodLiteral<"text">;
56
+ text: z.ZodString;
57
+ }, z.core.$strict>, z.ZodObject<{
58
+ type: z.ZodLiteral<"dynamic-tool">;
59
+ output: z.ZodObject<{
60
+ content: z.ZodArray<z.ZodObject<{
61
+ type: z.ZodLiteral<"resource">;
62
+ resource: z.ZodObject<{
63
+ uri: z.ZodString;
64
+ text: z.ZodString;
65
+ }, z.core.$strict>;
66
+ }, z.core.$strict>>;
67
+ }, z.core.$strict>;
68
+ }, z.core.$strict>]>>;
69
+ metadata: z.ZodOptional<z.ZodObject<{
70
+ citations: z.ZodArray<z.ZodJSONSchema>;
71
+ }, z.core.$strict>>;
72
+ }, z.core.$strict>>;
73
+ conversation: z.ZodOptional<z.ZodObject<{
74
+ messageCount: z.ZodNumber;
75
+ userMessageCount: z.ZodNumber;
76
+ assistantMessageCount: z.ZodNumber;
77
+ messages: z.ZodArray<z.ZodObject<{
78
+ id: z.ZodString;
79
+ role: z.ZodEnum<{
80
+ assistant: "assistant";
81
+ user: "user";
82
+ }>;
83
+ textParts: z.ZodArray<z.ZodString>;
84
+ tools: z.ZodArray<z.ZodObject<{
85
+ partType: z.ZodString;
86
+ toolName: z.ZodNullable<z.ZodString>;
87
+ state: z.ZodNullable<z.ZodString>;
88
+ outputTruthy: z.ZodBoolean;
89
+ }, z.core.$strict>>;
90
+ }, z.core.$strict>>;
91
+ }, z.core.$strict>>;
92
+ }, z.core.$strict>;
93
+ export type FunctionAgentCompletedRun = z.infer<typeof functionAgentCompletedRunSchema>;
94
+ export declare class FunctionAgentReadError extends Error {
95
+ readonly status: number;
96
+ readonly code: string;
97
+ readonly name = "FunctionAgentReadError";
98
+ constructor(status: number, code: string, message: string);
99
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FunctionAgentReadError = exports.functionAgentCompletedRunSchema = exports.functionAgentMessageSchema = exports.functionAgentReadRequestSchema = exports.functionAgentCompletedRunQuerySchema = exports.functionAgentReadScopesSchema = exports.functionAgentEvidenceScopesSchema = exports.FUNCTION_AGENT_CAPTURE_PATH = exports.FUNCTION_AGENT_READ_PATH = exports.FUNCTION_AGENT_TOKEN_HEADER = void 0;
4
+ exports.readFunctionAgentScopes = readFunctionAgentScopes;
5
+ const zod_1 = require("zod");
6
+ exports.FUNCTION_AGENT_TOKEN_HEADER = 'x-sequence-agent-service-token';
7
+ exports.FUNCTION_AGENT_READ_PATH = '/api/managed-functions/agents/read';
8
+ exports.FUNCTION_AGENT_CAPTURE_PATH = '/api/managed-functions/agents/capture';
9
+ const resourceId = zod_1.z.string().min(1).max(255).regex(/^[A-Za-z0-9._-]+$/);
10
+ exports.functionAgentEvidenceScopesSchema = zod_1.z.array(resourceId).min(1).max(64)
11
+ .refine((ids) => new Set(ids).size === ids.length, 'Agent evidence ids must be distinct')
12
+ .refine((ids) => ids.reduce((bytes, id) => bytes + id.length, 0) <= 8192, 'Agent evidence ids must fit within 8192 bytes');
13
+ exports.functionAgentReadScopesSchema = zod_1.z.strictObject({
14
+ read: zod_1.z.array(resourceId).min(1).max(64)
15
+ .refine((ids) => new Set(ids).size === ids.length, 'Agent ids must be distinct')
16
+ .refine((ids) => ids.reduce((bytes, id) => bytes + id.length, 0) <= 8192, 'Agent ids must fit within 8192 bytes').optional(),
17
+ evidence: exports.functionAgentEvidenceScopesSchema.optional(),
18
+ }).refine((value) => value.read !== undefined || value.evidence !== undefined, 'Declare agent reads or evidence verification');
19
+ function readFunctionAgentScopes(manifest) {
20
+ if (typeof manifest !== 'object' || manifest === null)
21
+ return [];
22
+ const capabilities = Reflect.get(manifest, 'capabilities');
23
+ if (typeof capabilities !== 'object' || capabilities === null)
24
+ return [];
25
+ const agents = Reflect.get(capabilities, 'agents');
26
+ if (agents === undefined)
27
+ return [];
28
+ return exports.functionAgentReadScopesSchema.parse(agents).read ?? [];
29
+ }
30
+ exports.functionAgentCompletedRunQuerySchema = zod_1.z.strictObject({ agent: resourceId, runId: resourceId, recoveryProof: zod_1.z.string().min(1).max(16_384).optional() });
31
+ exports.functionAgentReadRequestSchema = exports.functionAgentCompletedRunQuerySchema.extend({ operation: zod_1.z.literal('getCompletedRun') });
32
+ exports.functionAgentMessageSchema = zod_1.z.strictObject({
33
+ id: zod_1.z.string().min(1).max(255),
34
+ role: zod_1.z.literal('assistant'),
35
+ parts: zod_1.z.array(zod_1.z.union([
36
+ zod_1.z.strictObject({ type: zod_1.z.literal('text'), text: zod_1.z.string() }),
37
+ zod_1.z.strictObject({ type: zod_1.z.literal('dynamic-tool'), output: zod_1.z.strictObject({ content: zod_1.z.array(zod_1.z.strictObject({ type: zod_1.z.literal('resource'), resource: zod_1.z.strictObject({ uri: zod_1.z.string().startsWith('citation://'), text: zod_1.z.string() }) })).max(1000) }) }),
38
+ ])).max(1000),
39
+ metadata: zod_1.z.strictObject({ citations: zod_1.z.array(zod_1.z.json()).max(1000) }).optional(),
40
+ });
41
+ exports.functionAgentCompletedRunSchema = zod_1.z.strictObject({
42
+ runId: resourceId,
43
+ agent: resourceId,
44
+ threadId: resourceId,
45
+ status: zod_1.z.literal('completed'),
46
+ output: zod_1.z.json(),
47
+ messages: zod_1.z.array(exports.functionAgentMessageSchema).max(1000),
48
+ conversation: zod_1.z.strictObject({
49
+ messageCount: zod_1.z.number().int().min(0).max(1000),
50
+ userMessageCount: zod_1.z.number().int().min(0).max(1000),
51
+ assistantMessageCount: zod_1.z.number().int().min(0).max(1000),
52
+ messages: zod_1.z.array(zod_1.z.strictObject({
53
+ id: zod_1.z.string().min(1).max(255), role: zod_1.z.enum(['user', 'assistant']),
54
+ textParts: zod_1.z.array(zod_1.z.string()).max(1000),
55
+ tools: zod_1.z.array(zod_1.z.strictObject({ partType: zod_1.z.string().min(1).max(255), toolName: zod_1.z.string().max(255).nullable(), state: zod_1.z.string().max(255).nullable(), outputTruthy: zod_1.z.boolean() })).max(1000),
56
+ })).max(1000),
57
+ }).optional(),
58
+ });
59
+ class FunctionAgentReadError extends Error {
60
+ status;
61
+ code;
62
+ name = 'FunctionAgentReadError';
63
+ constructor(status, code, message) {
64
+ super(message);
65
+ this.status = status;
66
+ this.code = code;
67
+ }
68
+ }
69
+ exports.FunctionAgentReadError = FunctionAgentReadError;
@@ -0,0 +1,15 @@
1
+ import { type FunctionAgentCompletedRun, type FunctionAgentCompletedRunQuery } from './agents-contract';
2
+ import { type FunctionAgentSourceEvidenceCapture } from './agent-source-evidence-contract';
3
+ export * from './agents-contract';
4
+ export interface FunctionServiceAgentsOptions {
5
+ request: {
6
+ headers: Pick<Headers, 'get'> | Readonly<Record<string, string | readonly string[] | undefined>>;
7
+ };
8
+ baseUrl: string;
9
+ fetchImpl?: typeof globalThis.fetch;
10
+ }
11
+ export interface FunctionServiceAgentsClient {
12
+ getCompletedRun(query: FunctionAgentCompletedRunQuery): Promise<FunctionAgentCompletedRun>;
13
+ captureCompletedRun(query: FunctionAgentCompletedRunQuery): Promise<FunctionAgentSourceEvidenceCapture>;
14
+ }
15
+ export declare function createFunctionServiceAgentsClient({ request, baseUrl, fetchImpl }: FunctionServiceAgentsOptions): FunctionServiceAgentsClient;
package/dist/agents.js ADDED
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.createFunctionServiceAgentsClient = createFunctionServiceAgentsClient;
18
+ const zod_1 = require("zod");
19
+ const agents_contract_1 = require("./agents-contract");
20
+ const agent_source_evidence_contract_1 = require("./agent-source-evidence-contract");
21
+ const processes_contract_1 = require("./processes-contract");
22
+ __exportStar(require("./agents-contract"), exports);
23
+ function header({ request, name }) {
24
+ const { headers } = request;
25
+ const values = typeof headers.get === 'function' ? [headers.get(name)] : Object.entries(headers).filter(([key]) => key.toLowerCase() === name).map(([, value]) => value);
26
+ return values.length === 1 && typeof values[0] === 'string' ? values[0] : null;
27
+ }
28
+ function credential(request) {
29
+ const denied = () => new agents_contract_1.FunctionAgentReadError(401, 'invalid_context', 'This invocation has no valid agent-read credential');
30
+ const token = header({ request, name: agents_contract_1.FUNCTION_AGENT_TOKEN_HEADER });
31
+ if (!token || token.length > 16_384)
32
+ throw denied();
33
+ const body = /^([A-Za-z0-9_-]+)\.[A-Za-z0-9_-]{43}$/.exec(token)?.[1];
34
+ if (!body)
35
+ throw denied();
36
+ let value;
37
+ try {
38
+ value = JSON.parse(Buffer.from(body, 'base64url').toString('utf8'));
39
+ }
40
+ catch {
41
+ throw denied();
42
+ }
43
+ 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);
44
+ if (!claims.success)
45
+ throw denied();
46
+ return { token, expiresAt: claims.data.exp };
47
+ }
48
+ function origin(baseUrl) {
49
+ let url;
50
+ try {
51
+ url = new URL(baseUrl);
52
+ }
53
+ catch {
54
+ throw new agents_contract_1.FunctionAgentReadError(400, 'invalid_configuration', 'Configure a trusted Atlas origin');
55
+ }
56
+ const loopback = url.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);
57
+ if ((!loopback && url.protocol !== 'https:') || url.username || url.password || url.pathname !== '/' || url.search || url.hash)
58
+ throw new agents_contract_1.FunctionAgentReadError(400, 'invalid_configuration', 'Configure an HTTPS Atlas origin without credentials, path, query or fragment');
59
+ return url.origin;
60
+ }
61
+ function recoveryProcessCredential(request) {
62
+ const denied = () => new agents_contract_1.FunctionAgentReadError(401, 'invalid_context', 'Recovery requires this invocation’s process-read credential');
63
+ const token = header({ request, name: processes_contract_1.FUNCTION_PROCESS_TOKEN_HEADER });
64
+ if (!token || token.length > 16_384)
65
+ throw denied();
66
+ const body = /^([A-Za-z0-9_-]+)\.[A-Za-z0-9_-]{43}$/.exec(token)?.[1];
67
+ if (!body)
68
+ throw denied();
69
+ let value;
70
+ try {
71
+ value = JSON.parse(Buffer.from(body, 'base64url').toString('utf8'));
72
+ }
73
+ catch {
74
+ throw denied();
75
+ }
76
+ const claims = zod_1.z.object({ audience: zod_1.z.literal('atlas-managed-function-process-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);
77
+ if (!claims.success)
78
+ throw denied();
79
+ if (claims.data.exp <= Date.now() / 1000)
80
+ throw new agents_contract_1.FunctionAgentReadError(401, 'expired_context', 'The process-read credential expired; start a new invocation');
81
+ return token;
82
+ }
83
+ function createFunctionServiceAgentsClient({ request, baseUrl, fetchImpl = globalThis.fetch }) {
84
+ const base = origin(baseUrl);
85
+ const { token, expiresAt } = credential(request);
86
+ const lattice = header({ request, name: 'x-sequence-lattice-execution-token' });
87
+ async function read(query, capture) {
88
+ if (expiresAt <= Date.now() / 1000)
89
+ throw new agents_contract_1.FunctionAgentReadError(401, 'expired_context', 'The agent-read credential expired; start a new invocation');
90
+ const body = agents_contract_1.functionAgentCompletedRunQuerySchema.parse(query);
91
+ const process = body.recoveryProof ? recoveryProcessCredential(request) : null;
92
+ const evidence = capture ? header({ request, name: agent_source_evidence_contract_1.FUNCTION_AGENT_EVIDENCE_TOKEN_HEADER }) : null;
93
+ if (capture && !evidence)
94
+ throw new agents_contract_1.FunctionAgentReadError(401, 'invalid_context', 'Source capture requires this invocation’s separate agent-evidence credential');
95
+ const response = await fetchImpl(`${base}${capture ? agents_contract_1.FUNCTION_AGENT_CAPTURE_PATH : agents_contract_1.FUNCTION_AGENT_READ_PATH}`, {
96
+ method: 'POST', headers: { 'content-type': 'application/json', [agents_contract_1.FUNCTION_AGENT_TOKEN_HEADER]: token, ...(process ? { [processes_contract_1.FUNCTION_PROCESS_TOKEN_HEADER]: process } : {}), ...(evidence ? { [agent_source_evidence_contract_1.FUNCTION_AGENT_EVIDENCE_TOKEN_HEADER]: evidence } : {}), ...(lattice ? { 'x-sequence-lattice-execution-token': lattice } : {}) },
97
+ body: JSON.stringify({ ...body, operation: capture ? 'captureCompletedRun' : 'getCompletedRun' }), redirect: 'error', signal: AbortSignal.timeout(30_000),
98
+ });
99
+ const result = await response.json().catch(() => null);
100
+ if (!response.ok) {
101
+ const error = zod_1.z.object({ code: zod_1.z.string().max(128).optional(), detail: zod_1.z.string().max(2000).optional() }).safeParse(result);
102
+ throw new agents_contract_1.FunctionAgentReadError(response.status, error.success ? (error.data.code ?? 'agent_read_failed') : 'agent_read_failed', error.success ? (error.data.detail ?? 'Agent read failed') : 'Agent read failed');
103
+ }
104
+ return result;
105
+ }
106
+ return {
107
+ async getCompletedRun(query) {
108
+ const result = await read(query, false);
109
+ const parsed = agents_contract_1.functionAgentCompletedRunSchema.safeParse(result);
110
+ if (!parsed.success || parsed.data.runId !== query.runId || parsed.data.agent !== query.agent)
111
+ throw new agents_contract_1.FunctionAgentReadError(502, 'malformed_response', 'Atlas returned an invalid completed agent response');
112
+ return parsed.data;
113
+ },
114
+ async captureCompletedRun(query) {
115
+ const parsed = agent_source_evidence_contract_1.functionAgentSourceEvidenceCaptureSchema.safeParse(await read(query, true));
116
+ if (!parsed.success || parsed.data.response.runId !== query.runId || parsed.data.response.agent !== query.agent || 'context' in parsed.data.response)
117
+ throw new agents_contract_1.FunctionAgentReadError(502, 'malformed_response', 'Atlas returned an invalid neutral source capture');
118
+ return parsed.data;
119
+ },
120
+ };
121
+ }
@@ -20,6 +20,76 @@ export declare const MANAGED_FUNCTION_CAPABILITIES: {
20
20
  readonly min_cli: "0.5.2";
21
21
  readonly min_sdk: "0.4.1";
22
22
  };
23
+ readonly abrigo_read: {
24
+ readonly field: "capabilities.abrigo.read";
25
+ readonly supported: true;
26
+ readonly limit: "eleven fixed human reads: eight integration reads and three workflow-scoped document-review reads; pages 1 to 100 with 1 to 500 rows; 1 MiB JSON responses";
27
+ readonly min_cli: "0.5.5";
28
+ readonly min_sdk: "0.4.2";
29
+ };
30
+ readonly immutable_release: {
31
+ readonly field: "function.immutable_release";
32
+ readonly supported: true;
33
+ readonly limit: "a fresh function identity whose runtime cannot be redeployed after first activation";
34
+ readonly min_cli: "0.5.5";
35
+ readonly min_sdk: "0.4.2";
36
+ };
37
+ readonly invocation_identity: {
38
+ readonly field: "capabilities.invocation.identity";
39
+ readonly supported: true;
40
+ readonly limit: "verified receiver and actual caller for this exact active invocation only";
41
+ readonly min_cli: "0.5.5";
42
+ readonly min_sdk: "0.4.2";
43
+ };
44
+ readonly directory_resolve: {
45
+ readonly field: "capabilities.directory.resolve";
46
+ readonly supported: true;
47
+ readonly limit: "1 to 16 exact tenant scopes; at most 50 exact active human principal lookups";
48
+ readonly min_cli: "0.5.5";
49
+ readonly min_sdk: "0.4.2";
50
+ };
51
+ readonly lattice_context: {
52
+ readonly field: "capabilities.lattice.context";
53
+ readonly supported: true;
54
+ readonly limit: "verified context and causal human completion for the receiving Lattice step only";
55
+ readonly min_cli: "0.5.5";
56
+ readonly min_sdk: "0.4.2";
57
+ };
58
+ readonly agents_read: {
59
+ readonly field: "capabilities.agents.read";
60
+ readonly supported: true;
61
+ readonly limit: "1 to 64 exact agent ids; completed owned or verified upstream responses only";
62
+ readonly min_cli: "0.5.5";
63
+ readonly min_sdk: "0.4.2";
64
+ };
65
+ readonly agents_evidence_verify: {
66
+ readonly field: "capabilities.agents.evidence";
67
+ readonly supported: true;
68
+ readonly limit: "1 to 64 exact agent ids; verify bounded supplied historical source evidence only";
69
+ readonly min_cli: "0.5.5";
70
+ readonly min_sdk: "0.4.2";
71
+ };
72
+ readonly workflows_read: {
73
+ readonly field: "capabilities.workflows.read";
74
+ readonly supported: true;
75
+ readonly limit: "1 to 64 exact workflow ids; completed owned root outputs only";
76
+ readonly min_cli: "0.5.5";
77
+ readonly min_sdk: "0.4.2";
78
+ };
79
+ readonly workflows_evidence_verify: {
80
+ readonly field: "capabilities.workflows.evidence";
81
+ readonly supported: true;
82
+ readonly limit: "1 to 64 exact workflow ids; verify bounded supplied historical root-output evidence only";
83
+ readonly min_cli: "0.5.5";
84
+ readonly min_sdk: "0.4.2";
85
+ };
86
+ readonly monitoring_deliveries: {
87
+ readonly field: "capabilities.monitoring.producers";
88
+ readonly supported: true;
89
+ readonly limit: "1 to 16 producer namespaces; immutable publish and receipt lookup";
90
+ readonly min_cli: "0.5.5";
91
+ readonly min_sdk: "0.4.2";
92
+ };
23
93
  readonly processes_read: {
24
94
  readonly field: "capabilities.processes.read";
25
95
  readonly supported: true;
@@ -71,6 +141,76 @@ export interface ManagedFunctionCapabilities {
71
141
  min_cli: string;
72
142
  min_sdk: string;
73
143
  };
144
+ abrigo_read?: {
145
+ field: string;
146
+ supported: boolean;
147
+ limit: string;
148
+ min_cli: string;
149
+ min_sdk: string;
150
+ };
151
+ immutable_release?: {
152
+ field: string;
153
+ supported: boolean;
154
+ limit: string;
155
+ min_cli: string;
156
+ min_sdk: string;
157
+ };
158
+ invocation_identity?: {
159
+ field: string;
160
+ supported: boolean;
161
+ limit: string;
162
+ min_cli: string;
163
+ min_sdk: string;
164
+ };
165
+ directory_resolve?: {
166
+ field: string;
167
+ supported: boolean;
168
+ limit: string;
169
+ min_cli: string;
170
+ min_sdk: string;
171
+ };
172
+ lattice_context?: {
173
+ field: string;
174
+ supported: boolean;
175
+ limit: string;
176
+ min_cli: string;
177
+ min_sdk: string;
178
+ };
179
+ agents_read?: {
180
+ field: string;
181
+ supported: boolean;
182
+ limit: string;
183
+ min_cli: string;
184
+ min_sdk: string;
185
+ };
186
+ agents_evidence_verify?: {
187
+ field: string;
188
+ supported: boolean;
189
+ limit: string;
190
+ min_cli: string;
191
+ min_sdk: string;
192
+ };
193
+ workflows_read?: {
194
+ field: string;
195
+ supported: boolean;
196
+ limit: string;
197
+ min_cli: string;
198
+ min_sdk: string;
199
+ };
200
+ workflows_evidence_verify?: {
201
+ field: string;
202
+ supported: boolean;
203
+ limit: string;
204
+ min_cli: string;
205
+ min_sdk: string;
206
+ };
207
+ monitoring_deliveries?: {
208
+ field: string;
209
+ supported: boolean;
210
+ limit: string;
211
+ min_cli: string;
212
+ min_sdk: string;
213
+ };
74
214
  processes_read?: {
75
215
  field: string;
76
216
  supported: boolean;
@@ -107,6 +247,9 @@ export interface DeployedPolicy {
107
247
  capabilities: ManagedFunctionCapabilities | null;
108
248
  }
109
249
  export interface PreflightManifest {
250
+ function?: {
251
+ immutable_release?: unknown;
252
+ };
110
253
  limits?: {
111
254
  memory_mb?: number;
112
255
  cpu?: number | 'auto';
@@ -122,7 +265,13 @@ export interface PreflightManifest {
122
265
  data?: Readonly<Record<string, unknown>>;
123
266
  storage?: unknown;
124
267
  processes?: unknown;
268
+ agents?: unknown;
269
+ workflows?: unknown;
270
+ monitoring?: unknown;
125
271
  directory?: unknown;
272
+ abrigo?: unknown;
273
+ lattice?: unknown;
274
+ invocation?: unknown;
126
275
  };
127
276
  }
128
277
  export interface PreflightIssue {
@@ -135,6 +284,7 @@ export interface PreflightIssue {
135
284
  export declare function versionIsOlder(installed: string, required: string): boolean;
136
285
  export declare function sdkVersionLowerBound(spec: string | undefined): string | null;
137
286
  export declare function sdkVersionFromPackageJson(raw: string): string | null;
287
+ export declare function sdkSpecFromPackageJson(raw: string): string | null;
138
288
  export declare function isPostgresEgress(entry: string): boolean;
139
289
  export declare function formatValidationDetail(issues: readonly {
140
290
  path?: readonly PropertyKey[];