@sequenceholdings/managed-functions 0.4.4 → 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 +4257 -1667
  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 +70 -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
package/dist/abrigo.js CHANGED
@@ -15,36 +15,54 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.createFunctionCallerAbrigoClient = createFunctionCallerAbrigoClient;
18
+ const adapters_1 = require("@sequenceholdings/platform/adapters");
18
19
  const zod_1 = require("zod");
19
- const abrigo_response_1 = require("./abrigo-response");
20
20
  const abrigo_contract_1 = require("./abrigo-contract");
21
21
  __exportStar(require("./abrigo-contract"), exports);
22
22
  const claimsSchema = zod_1.z.object({
23
- audience: zod_1.z.literal(abrigo_contract_1.FUNCTION_ABRIGO_READ_AUDIENCE), environment: zod_1.z.string().min(1).max(4096),
24
- functionId: zod_1.z.uuid(), versionId: zod_1.z.uuid(), invocationId: zod_1.z.uuid(), serviceAccountId: zod_1.z.uuid(),
25
- org: zod_1.z.string().min(1).max(255), callerKind: zod_1.z.literal('human'),
26
- callerSub: zod_1.z.string().min(1).max(512).regex(/^[^\s:#|]+\|[^\s:#]+$/).refine((sub) => !sub.startsWith('service-account|') && !sub.startsWith('managed-function|') &&
27
- !sub.startsWith('system|') && !sub.endsWith('@clients') && sub !== 'google-apps|sequence.agent@seqholdings.com', 'Only actual human callers may read Abrigo'),
23
+ audience: zod_1.z.literal(abrigo_contract_1.FUNCTION_ABRIGO_READ_AUDIENCE),
24
+ environment: zod_1.z.string().min(1).max(4096),
25
+ functionId: zod_1.z.uuid(),
26
+ versionId: zod_1.z.uuid(),
27
+ invocationId: zod_1.z.uuid(),
28
+ serviceAccountId: zod_1.z.uuid(),
29
+ org: zod_1.z.string().min(1).max(255),
30
+ callerKind: zod_1.z.literal("human"),
31
+ callerSub: zod_1.z
32
+ .string()
33
+ .min(1)
34
+ .max(512)
35
+ .regex(/^[^\s:#|]+\|[^\s:#]+$/)
36
+ .refine((sub) => !sub.startsWith("service-account|") &&
37
+ !sub.startsWith("managed-function|") &&
38
+ !sub.startsWith("system|") &&
39
+ !sub.endsWith("@clients") &&
40
+ sub !== "google-apps|sequence.agent@seqholdings.com", "Only actual human callers may read Abrigo"),
28
41
  callerAuthenticationMethod: zod_1.z.string().min(1).max(64),
29
42
  exp: zod_1.z.number().int().positive().max(Number.MAX_SAFE_INTEGER),
30
43
  });
31
44
  function credential({ request }) {
32
- const invalid = () => new abrigo_contract_1.FunctionAbrigoReadError(401, 'invalid_context', 'This invocation has no valid caller Abrigo read credential');
45
+ const invalid = () => new abrigo_contract_1.FunctionAbrigoReadError(401, "invalid_context", "This invocation has no valid caller Abrigo read credential");
33
46
  const headers = request.headers;
34
- const matches = typeof headers.get === 'function' ? [headers.get(abrigo_contract_1.FUNCTION_ABRIGO_READ_TOKEN_HEADER)]
35
- : Object.entries(headers).filter(([name]) => name.toLowerCase() === abrigo_contract_1.FUNCTION_ABRIGO_READ_TOKEN_HEADER).map(([, value]) => value);
47
+ const matches = typeof headers.get === "function"
48
+ ? [headers.get(abrigo_contract_1.FUNCTION_ABRIGO_READ_TOKEN_HEADER)]
49
+ : Object.entries(headers)
50
+ .filter(([name]) => name.toLowerCase() === abrigo_contract_1.FUNCTION_ABRIGO_READ_TOKEN_HEADER)
51
+ .map(([, value]) => value);
36
52
  const token = matches[0];
37
- if (matches.length !== 1 || typeof token !== 'string' || token.length > 16_384)
53
+ if (matches.length !== 1 ||
54
+ typeof token !== "string" ||
55
+ token.length > 16_384)
38
56
  throw invalid();
39
57
  const envelope = /^([A-Za-z0-9_-]+)\.([A-Za-z0-9_-]{43})$/.exec(token);
40
58
  if (!envelope?.[1])
41
59
  throw invalid();
42
60
  let value;
43
61
  try {
44
- const decoded = Buffer.from(envelope[1], 'base64url');
45
- if (decoded.toString('base64url') !== envelope[1])
62
+ const decoded = Buffer.from(envelope[1], "base64url");
63
+ if (decoded.toString("base64url") !== envelope[1])
46
64
  throw invalid();
47
- value = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(decoded));
65
+ value = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(decoded));
48
66
  }
49
67
  catch {
50
68
  throw invalid();
@@ -55,7 +73,7 @@ function credential({ request }) {
55
73
  return { token, expiresAt: parsed.data.exp };
56
74
  }
57
75
  function origin(baseUrl) {
58
- const invalid = () => new abrigo_contract_1.FunctionAbrigoReadError(400, 'invalid_configuration', 'Configure a trusted HTTPS Atlas origin without credentials, path, query or fragment');
76
+ const invalid = () => new abrigo_contract_1.FunctionAbrigoReadError(400, "invalid_configuration", "Configure a trusted HTTPS Atlas origin without credentials, path, query or fragment");
59
77
  let url;
60
78
  try {
61
79
  url = new URL(baseUrl);
@@ -63,88 +81,44 @@ function origin(baseUrl) {
63
81
  catch {
64
82
  throw invalid();
65
83
  }
66
- const loopback = url.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);
67
- if ((!loopback && url.protocol !== 'https:') || url.username || url.password || url.pathname !== '/' || url.search || url.hash)
84
+ const loopback = url.protocol === "http:" &&
85
+ ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
86
+ if ((!loopback && url.protocol !== "https:") ||
87
+ url.username ||
88
+ url.password ||
89
+ url.pathname !== "/" ||
90
+ url.search ||
91
+ url.hash)
68
92
  throw invalid();
69
93
  return url.origin;
70
94
  }
71
- function validJson(value, depth = 0) {
72
- if (depth > 64)
73
- return false;
74
- if (value === null || typeof value === 'string' || typeof value === 'boolean')
75
- return true;
76
- if (typeof value === 'number')
77
- return Number.isFinite(value) && (!Number.isInteger(value) || Number.isSafeInteger(value));
78
- if (Array.isArray(value))
79
- return value.every((item) => validJson(item, depth + 1));
80
- return typeof value === 'object' && Object.values(value).every((item) => validJson(item, depth + 1));
81
- }
82
- async function boundedBody(response) {
83
- const oversized = () => new abrigo_contract_1.FunctionAbrigoReadError(502, 'response_too_large', 'Abrigo read exceeded the bounded response size; reduce perPage');
84
- const length = response.headers.get('content-length');
85
- if (length && /^\d+$/.test(length) && Number(length) > abrigo_contract_1.ABRIGO_READ_MAX_RESPONSE_BYTES) {
86
- await response.body?.cancel().catch(() => { });
87
- throw oversized();
88
- }
89
- if (!response.body)
90
- throw new abrigo_contract_1.FunctionAbrigoReadError(502, 'malformed_response', 'Atlas returned invalid Abrigo JSON');
91
- const reader = response.body.getReader();
92
- const chunks = [];
93
- let bytes = 0;
94
- try {
95
- for (;;) {
96
- const chunk = await reader.read();
97
- if (chunk.done)
98
- break;
99
- bytes += chunk.value.byteLength;
100
- if (bytes > abrigo_contract_1.ABRIGO_READ_MAX_RESPONSE_BYTES) {
101
- await reader.cancel().catch(() => { });
102
- throw oversized();
103
- }
104
- chunks.push(chunk.value);
105
- }
106
- }
107
- finally {
108
- reader.releaseLock();
109
- }
110
- try {
111
- return JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(Buffer.concat(chunks, bytes)));
112
- }
113
- catch {
114
- throw new abrigo_contract_1.FunctionAbrigoReadError(502, 'malformed_response', 'Atlas returned invalid Abrigo JSON');
115
- }
116
- }
117
- function createFunctionCallerAbrigoClient({ request, baseUrl, fetchImpl = globalThis.fetch }) {
95
+ function createFunctionCallerAbrigoClient({ request, baseUrl, fetchImpl = globalThis.fetch, }) {
118
96
  const url = `${origin(baseUrl)}${abrigo_contract_1.FUNCTION_ABRIGO_READ_PATH}`;
119
97
  const { token, expiresAt } = credential({ request });
120
- return {
121
- async read(input) {
122
- if (expiresAt <= Date.now() / 1000)
123
- throw new abrigo_contract_1.FunctionAbrigoReadError(401, 'expired_context', 'The Abrigo read credential expired; start a new invocation');
124
- const query = abrigo_contract_1.functionAbrigoReadRequestSchema.safeParse(input);
125
- if (!query.success)
126
- throw new abrigo_contract_1.FunctionAbrigoReadError(400, 'invalid_request', 'Invalid bounded Abrigo read request');
127
- try {
128
- const response = await fetchImpl(url, { method: 'POST', headers: { 'content-type': 'application/json', [abrigo_contract_1.FUNCTION_ABRIGO_READ_TOKEN_HEADER]: token }, body: JSON.stringify(query.data), redirect: 'error', signal: AbortSignal.timeout(abrigo_contract_1.ABRIGO_READ_TIMEOUT_MS) });
129
- const body = await boundedBody(response).catch((error) => {
130
- if (!response.ok && error instanceof abrigo_contract_1.FunctionAbrigoReadError && error.code === 'malformed_response')
131
- return null;
132
- throw error;
133
- });
134
- if (!response.ok) {
135
- const error = zod_1.z.object({ code: zod_1.z.string().max(128).regex(/^[a-z][a-z0-9_]*$/).optional() }).safeParse(body);
136
- throw new abrigo_contract_1.FunctionAbrigoReadError(response.status, error.success ? error.data.code ?? 'abrigo_read_failed' : 'abrigo_read_failed', 'The authorized Abrigo read failed');
137
- }
138
- if (!validJson(body))
139
- throw new abrigo_contract_1.FunctionAbrigoReadError(502, 'malformed_response', 'Atlas returned invalid Abrigo JSON');
140
- (0, abrigo_response_1.validateAbrigoReviewResponse)({ query: query.data, body });
141
- return body;
142
- }
143
- catch (error) {
144
- if (error instanceof abrigo_contract_1.FunctionAbrigoReadError)
145
- throw error;
146
- throw new abrigo_contract_1.FunctionAbrigoReadError(503, 'abrigo_read_unavailable', 'The authorized Abrigo read could not be completed');
147
- }
98
+ const send = (0, adapters_1.createInvocationDomainTransport)({
99
+ baseUrl,
100
+ fetchImpl,
101
+ domain: "abrigo",
102
+ credentials: [
103
+ { header: abrigo_contract_1.FUNCTION_ABRIGO_READ_TOKEN_HEADER, token, expiresAt },
104
+ ],
105
+ maxResponseBytes: abrigo_contract_1.ABRIGO_READ_MAX_RESPONSE_BYTES,
106
+ timeoutMs: abrigo_contract_1.ABRIGO_READ_TIMEOUT_MS,
107
+ error: (status, code, message) => ["timeout", "transport_failed"].includes(code)
108
+ ? new abrigo_contract_1.FunctionAbrigoReadError(503, "abrigo_read_unavailable", "The authorized Abrigo read could not be completed")
109
+ : new abrigo_contract_1.FunctionAbrigoReadError(status, /^[a-z][a-z0-9_]*$/.test(code) ? code : "abrigo_read_failed", [
110
+ "invalid_context",
111
+ "expired_context",
112
+ "invalid_configuration",
113
+ "response_too_large",
114
+ "malformed_response",
115
+ ].includes(code)
116
+ ? message
117
+ : "The authorized Abrigo read failed"),
118
+ failure: {
119
+ code: "abrigo_read_failed",
120
+ message: "The authorized Abrigo read failed",
148
121
  },
149
- };
122
+ });
123
+ return (0, adapters_1.createAbrigoReadClient)({ send });
150
124
  }
@@ -1,9 +1,9 @@
1
- import { type FunctionServiceAgentsOptions } from './agents';
2
- import { type FunctionAgentSourceEvidenceRequest, type FunctionAgentConversationEvidenceRequest, type FunctionAgentSourceEvidenceVerification } from './agent-source-evidence-contract';
3
- export type FunctionAgentSourceEvidenceInput = Omit<FunctionAgentSourceEvidenceRequest, 'operation'>;
4
- export type FunctionAgentConversationEvidenceInput = Omit<FunctionAgentConversationEvidenceRequest, 'operation'>;
1
+ import { type FunctionServiceAgentsOptions } from "./agents";
2
+ import { type FunctionAgentSourceEvidenceRequest, type FunctionAgentConversationEvidenceRequest, type FunctionAgentSourceEvidenceVerification } from "./agent-source-evidence-contract";
3
+ export type FunctionAgentSourceEvidenceInput = Omit<FunctionAgentSourceEvidenceRequest, "operation">;
4
+ export type FunctionAgentConversationEvidenceInput = Omit<FunctionAgentConversationEvidenceRequest, "operation">;
5
5
  export interface FunctionAgentEvidenceClient {
6
6
  verifySourceEvidence(input: FunctionAgentSourceEvidenceInput): Promise<FunctionAgentSourceEvidenceVerification>;
7
7
  verifyConversationEvidence(input: FunctionAgentConversationEvidenceInput): Promise<FunctionAgentSourceEvidenceVerification>;
8
8
  }
9
- export declare function createFunctionAgentEvidenceClient({ request, baseUrl, fetchImpl }: FunctionServiceAgentsOptions): FunctionAgentEvidenceClient;
9
+ export declare function createFunctionAgentEvidenceClient({ request, baseUrl, fetchImpl, }: FunctionServiceAgentsOptions): FunctionAgentEvidenceClient;
@@ -1,30 +1,49 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createFunctionAgentEvidenceClient = createFunctionAgentEvidenceClient;
4
+ const adapters_1 = require("@sequenceholdings/platform/adapters");
4
5
  const zod_1 = require("zod");
5
6
  const agents_1 = require("./agents");
6
7
  const agent_source_evidence_contract_1 = require("./agent-source-evidence-contract");
7
8
  function header(request, name) {
8
9
  const { headers } = request;
9
- const values = typeof headers.get === 'function' ? [headers.get(name)] : Object.entries(headers).filter(([key]) => key.toLowerCase() === name).map(([, value]) => value);
10
- return values.length === 1 && typeof values[0] === 'string' ? values[0] : null;
10
+ const values = typeof headers.get === "function"
11
+ ? [headers.get(name)]
12
+ : Object.entries(headers)
13
+ .filter(([key]) => key.toLowerCase() === name)
14
+ .map(([, value]) => value);
15
+ return values.length === 1 && typeof values[0] === "string"
16
+ ? values[0]
17
+ : null;
11
18
  }
12
- const bindingSchema = zod_1.z.object({ audience: zod_1.z.literal('atlas-managed-function-agent-evidence'), sub: zod_1.z.string().startsWith('service-account|'), functionId: zod_1.z.uuid(), versionId: zod_1.z.uuid(), invocationId: zod_1.z.uuid(), serviceAccountId: zod_1.z.uuid(), org: zod_1.z.string().min(1), exp: zod_1.z.number().int() });
19
+ const bindingSchema = zod_1.z.object({
20
+ audience: zod_1.z.literal("atlas-managed-function-agent-evidence"),
21
+ sub: zod_1.z.string().startsWith("service-account|"),
22
+ functionId: zod_1.z.uuid(),
23
+ versionId: zod_1.z.uuid(),
24
+ invocationId: zod_1.z.uuid(),
25
+ serviceAccountId: zod_1.z.uuid(),
26
+ org: zod_1.z.string().min(1),
27
+ exp: zod_1.z.number().int(),
28
+ });
13
29
  function invocation(request) {
14
- const denied = () => new agents_1.FunctionAgentReadError(401, 'invalid_context', 'This invocation has no valid agent-evidence credential');
30
+ const denied = () => new agents_1.FunctionAgentReadError(401, "invalid_context", "This invocation has no valid agent-evidence credential");
15
31
  const token = header(request, agent_source_evidence_contract_1.FUNCTION_AGENT_EVIDENCE_TOKEN_HEADER);
16
- const body = token && token.length <= 16_384 ? /^([A-Za-z0-9_-]+)\.[A-Za-z0-9_-]{43}$/.exec(token)?.[1] : null;
32
+ const body = token && token.length <= 16_384
33
+ ? /^([A-Za-z0-9_-]+)\.[A-Za-z0-9_-]{43}$/.exec(token)?.[1]
34
+ : null;
17
35
  if (!body || !token)
18
36
  throw denied();
19
37
  let value;
20
38
  try {
21
- value = JSON.parse(Buffer.from(body, 'base64url').toString('utf8'));
39
+ value = JSON.parse(Buffer.from(body, "base64url").toString("utf8"));
22
40
  }
23
41
  catch {
24
42
  throw denied();
25
43
  }
26
44
  const binding = bindingSchema.safeParse(value);
27
- if (!binding.success || binding.data.sub !== `service-account|${binding.data.serviceAccountId}`)
45
+ if (!binding.success ||
46
+ binding.data.sub !== `service-account|${binding.data.serviceAccountId}`)
28
47
  throw denied();
29
48
  return { token, binding: binding.data };
30
49
  }
@@ -34,51 +53,42 @@ function origin(baseUrl) {
34
53
  url = new URL(baseUrl);
35
54
  }
36
55
  catch {
37
- throw new agents_1.FunctionAgentReadError(400, 'invalid_configuration', 'Configure a trusted Atlas origin');
56
+ throw new agents_1.FunctionAgentReadError(400, "invalid_configuration", "Configure a trusted Atlas origin");
38
57
  }
39
- const loopback = url.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);
40
- if ((!loopback && url.protocol !== 'https:') || url.username || url.password || url.pathname !== '/' || url.search || url.hash)
41
- throw new agents_1.FunctionAgentReadError(400, 'invalid_configuration', 'Configure an HTTPS Atlas origin without credentials, path, query or fragment');
58
+ const loopback = url.protocol === "http:" &&
59
+ ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
60
+ if ((!loopback && url.protocol !== "https:") ||
61
+ url.username ||
62
+ url.password ||
63
+ url.pathname !== "/" ||
64
+ url.search ||
65
+ url.hash)
66
+ throw new agents_1.FunctionAgentReadError(400, "invalid_configuration", "Configure an HTTPS Atlas origin without credentials, path, query or fragment");
42
67
  return url.origin;
43
68
  }
44
- function createFunctionAgentEvidenceClient({ request, baseUrl, fetchImpl = globalThis.fetch }) {
69
+ function createFunctionAgentEvidenceClient({ request, baseUrl, fetchImpl = globalThis.fetch, }) {
45
70
  const url = `${origin(baseUrl)}${agent_source_evidence_contract_1.FUNCTION_AGENT_EVIDENCE_PATH}`;
46
71
  const { token, binding } = invocation(request);
47
- const lattice = header(request, 'x-sequence-lattice-execution-token');
48
- async function verify(input) {
49
- if (binding.exp <= Date.now() / 1000)
50
- throw new agents_1.FunctionAgentReadError(401, 'expired_context', 'The agent-evidence credential expired; start a new invocation');
51
- const body = JSON.stringify(input);
52
- if (Buffer.byteLength(body, 'utf8') > agent_source_evidence_contract_1.AGENT_SOURCE_VERIFY_MAX_BYTES)
53
- throw new agents_1.FunctionAgentReadError(413, 'source_evidence_too_large', 'Source verification exceeds 768 KiB; capture a smaller source before writing');
54
- const response = await fetchImpl(url, { method: 'POST', headers: { 'content-type': 'application/json', [agent_source_evidence_contract_1.FUNCTION_AGENT_EVIDENCE_TOKEN_HEADER]: token, ...(lattice ? { 'x-sequence-lattice-execution-token': lattice } : {}) }, body, redirect: 'error', signal: AbortSignal.timeout(30_000) });
55
- const result = await response.json().catch(() => null);
56
- if (!response.ok) {
57
- const error = zod_1.z.object({ detail: zod_1.z.string().max(2000).optional(), code: zod_1.z.string().max(128).optional() }).safeParse(result);
58
- throw new agents_1.FunctionAgentReadError(response.status, error.success ? (error.data.code ?? 'agent_evidence_failed') : 'agent_evidence_failed', error.success ? (error.data.detail ?? 'Source verification failed') : 'Source verification failed');
59
- }
60
- const verified = agent_source_evidence_contract_1.functionAgentSourceEvidenceVerificationSchema.safeParse(result);
61
- if (!verified.success)
62
- throw new agents_1.FunctionAgentReadError(502, 'malformed_response', 'Atlas returned invalid source verification');
63
- const { source, receiver } = verified.data;
64
- const execution = verified.data.lattice;
65
- if (source.agentId !== input.agent || source.threadId !== input.response.threadId || source.responseHash !== input.responseHash || receiver.functionId !== binding.functionId || receiver.versionId !== binding.versionId || receiver.invocationId !== binding.invocationId || receiver.serviceAccountId !== binding.serviceAccountId || receiver.org !== binding.org ||
66
- (execution !== null && (execution.receiverFunctionOrgId !== receiver.org || execution.receiver.functionId !== receiver.functionId || execution.receiver.versionId !== receiver.versionId || execution.receiver.invocationId !== receiver.invocationId)))
67
- throw new agents_1.FunctionAgentReadError(502, 'malformed_response', 'Atlas returned source verification for another request or invocation');
68
- return verified.data;
69
- }
70
- return {
71
- async verifySourceEvidence(input) {
72
- const result = await verify(agent_source_evidence_contract_1.functionAgentSourceEvidenceRequestSchema.parse({ ...input, operation: 'verifySourceEvidence' }));
73
- if (result.source.projection === 'thread-conversation-v1' || result.source.runId !== input.runId)
74
- throw new agents_1.FunctionAgentReadError(502, 'malformed_response', 'Atlas returned evidence for a different completed source');
75
- return result;
76
- },
77
- async verifyConversationEvidence(input) {
78
- const result = await verify(agent_source_evidence_contract_1.functionAgentConversationEvidenceRequestSchema.parse({ ...input, operation: 'verifyConversationEvidence' }));
79
- if (result.source.projection !== 'thread-conversation-v1' || result.source.threadId !== input.threadId || result.source.revision !== input.response.revision || result.source.cutoffAt !== input.response.cutoffAt)
80
- throw new agents_1.FunctionAgentReadError(502, 'malformed_response', 'Atlas returned evidence for a different settled conversation');
81
- return result;
72
+ const lattice = header(request, "x-sequence-lattice-execution-token");
73
+ const send = (0, adapters_1.createInvocationDomainTransport)({
74
+ baseUrl,
75
+ fetchImpl,
76
+ domain: "agents-evidence",
77
+ credentials: [
78
+ {
79
+ header: agent_source_evidence_contract_1.FUNCTION_AGENT_EVIDENCE_TOKEN_HEADER,
80
+ token,
81
+ expiresAt: binding.exp,
82
+ },
83
+ ...(lattice
84
+ ? [{ header: "x-sequence-lattice-execution-token", token: lattice }]
85
+ : []),
86
+ ],
87
+ error: (status, code, message) => new agents_1.FunctionAgentReadError(status, code, message),
88
+ failure: {
89
+ code: "agent_evidence_failed",
90
+ message: "Source verification failed",
82
91
  },
83
- };
92
+ });
93
+ return (0, adapters_1.createAgentEvidenceClient)({ binding, send });
84
94
  }