@heddleagent/execution-host-client 6.1.0 → 6.3.0

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 (60) hide show
  1. package/README.md +42 -3
  2. package/dist/agentcore/agentcore-execution-host.d.ts +4 -3
  3. package/dist/agentcore/agentcore-execution-host.d.ts.map +1 -1
  4. package/dist/agentcore/agentcore-execution-host.js +4 -0
  5. package/dist/agentcore/agentcore-execution-host.js.map +1 -1
  6. package/dist/authority/index.d.ts +1 -1
  7. package/dist/authority/index.d.ts.map +1 -1
  8. package/dist/authority/index.js.map +1 -1
  9. package/dist/authority/jose-execution-authority.js +2 -2
  10. package/dist/authority/jose-execution-authority.js.map +1 -1
  11. package/dist/authority/types.d.ts +3 -1
  12. package/dist/authority/types.d.ts.map +1 -1
  13. package/dist/authority/types.js.map +1 -1
  14. package/dist/contracts/index.d.ts +106 -3
  15. package/dist/contracts/index.d.ts.map +1 -1
  16. package/dist/contracts/index.js +67 -2
  17. package/dist/contracts/index.js.map +1 -1
  18. package/dist/conversation/index.d.ts +1 -1
  19. package/dist/conversation/index.d.ts.map +1 -1
  20. package/dist/conversation/index.js.map +1 -1
  21. package/dist/conversation/types.d.ts +6 -4
  22. package/dist/conversation/types.d.ts.map +1 -1
  23. package/dist/conversation/types.js.map +1 -1
  24. package/dist/heartbeat/hosted-heartbeat-agent-execution-transport.d.ts +14 -0
  25. package/dist/heartbeat/hosted-heartbeat-agent-execution-transport.d.ts.map +1 -0
  26. package/dist/heartbeat/hosted-heartbeat-agent-execution-transport.js +38 -0
  27. package/dist/heartbeat/hosted-heartbeat-agent-execution-transport.js.map +1 -0
  28. package/dist/heartbeat/hosted-heartbeat-task-service.d.ts +22 -0
  29. package/dist/heartbeat/hosted-heartbeat-task-service.d.ts.map +1 -0
  30. package/dist/heartbeat/hosted-heartbeat-task-service.js +96 -0
  31. package/dist/heartbeat/hosted-heartbeat-task-service.js.map +1 -0
  32. package/dist/heartbeat/index.d.ts +5 -0
  33. package/dist/heartbeat/index.d.ts.map +1 -0
  34. package/dist/heartbeat/index.js +4 -0
  35. package/dist/heartbeat/index.js.map +1 -0
  36. package/dist/heartbeat/types.d.ts +83 -0
  37. package/dist/heartbeat/types.d.ts.map +1 -0
  38. package/dist/heartbeat/types.js +17 -0
  39. package/dist/heartbeat/types.js.map +1 -0
  40. package/dist/http-sse/direct-http-execution-host.d.ts +4 -3
  41. package/dist/http-sse/direct-http-execution-host.d.ts.map +1 -1
  42. package/dist/http-sse/direct-http-execution-host.js +56 -21
  43. package/dist/http-sse/direct-http-execution-host.js.map +1 -1
  44. package/dist/http-sse/index.d.ts +1 -1
  45. package/dist/http-sse/index.d.ts.map +1 -1
  46. package/dist/http-sse/index.js.map +1 -1
  47. package/dist/http-sse/types.d.ts +11 -1
  48. package/dist/http-sse/types.d.ts.map +1 -1
  49. package/dist/http-sse/types.js.map +1 -1
  50. package/dist/index.d.ts +1 -0
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +1 -0
  53. package/dist/index.js.map +1 -1
  54. package/package.json +5 -1
  55. package/spec/v1/README.md +14 -4
  56. package/spec/v1/fixtures/manifest.json +12 -0
  57. package/spec/v1/fixtures/valid-heartbeat-request.json +23 -0
  58. package/spec/v1/fixtures/valid-heartbeat-result.sse +13 -0
  59. package/spec/v1/openapi.json +513 -6
  60. package/spec/v1/schema-bundle.json +499 -2
package/README.md CHANGED
@@ -5,7 +5,7 @@ products that invoke a separately deployed Heddle Execution Host. It lets an
5
5
  adopter keep its own language stack, authentication, database, product policy,
6
6
  MCP tools, and UI while reusing the security-sensitive v1 contract machinery.
7
7
 
8
- > **Current availability:** stable version `6.1.0`. The former
8
+ > **Current availability:** stable version `6.2.0`. The former
9
9
  > `@roackb2/heddle-adopter@5.13.0` coordinate is deprecated and remains
10
10
  > installable only for existing consumers. Heddle does not currently distribute
11
11
  > the compatible Execution Host implementation or offer a hosted service. The
@@ -30,10 +30,11 @@ modular AWS SDK for its AgentCore transport and the official MCP SDK, plus
30
30
  | `@heddleagent/execution-host-client/contracts` | Runtime-validated v1 request, stream, identity, capability, and header contracts |
31
31
  | `@heddleagent/execution-host-client/authority` | ES256 execution assertion and optional MCP capability issuance plus public JWKS projection |
32
32
  | `@heddleagent/execution-host-client/conversation` | Turn orchestration across authority, model credentials, optional MCP policy, an `ExecutionHost`, and an optional adopter-implemented durable lifecycle store |
33
+ | `@heddleagent/execution-host-client/heartbeat` | Remote heartbeat orchestration that keeps durable task authority in a coordinator while a compatible Execution Host runs the agent cycle |
33
34
  | `@heddleagent/execution-host-client/mcp` | Independent capability verification at the adopter's MCP edge |
34
35
  | `@heddleagent/execution-host-client/mcp/node` | Stateless official-SDK Streamable HTTP lifecycle around adopter-defined toolsets |
35
- | `@heddleagent/execution-host-client/http-sse` | Transport-neutral `ExecutionHost` port and strict direct-development HTTP/SSE client |
36
- | `@heddleagent/execution-host-client/agentcore` | Official AWS AgentCore/SigV4 implementation of the same `ExecutionHost` port |
36
+ | `@heddleagent/execution-host-client/http-sse` | Transport-neutral conversation and heartbeat ports plus the strict direct-development HTTP/SSE client |
37
+ | `@heddleagent/execution-host-client/agentcore` | Official AWS AgentCore/SigV4 implementation of the same conversation and heartbeat ports |
37
38
  | `@heddleagent/execution-host-client/testing` | Node-only loopback v1 fixture plus durable-turn store conformance for real adapters |
38
39
  | `@heddleagent/execution-host-client/node` | Optional Node JWKS/conversation HTTP edge plus safe local signing-key helpers |
39
40
 
@@ -278,6 +279,44 @@ The client refuses redirects, bounds parser and error bodies, validates ordered
278
279
  SSE identity, streams accepted/activity events incrementally, and withholds the
279
280
  terminal event until clean EOF. It never retries an ambiguous invocation.
280
281
 
282
+ ## Delegate heartbeat agent cycles
283
+
284
+ For autonomous work, keep the durable task store and scheduler in one
285
+ long-running coordinator. Inject the hosted transport only at the point where
286
+ the scheduler would otherwise run the local heartbeat agent:
287
+
288
+ ```ts
289
+ import { HeartbeatSchedulerService } from '@heddleagent/runtime/advanced'
290
+ import {
291
+ HostedHeartbeatAgentExecutionTransport,
292
+ HostedHeartbeatTaskService,
293
+ } from '@heddleagent/execution-host-client/heartbeat'
294
+
295
+ const hostedHeartbeat = new HostedHeartbeatTaskService({
296
+ authority,
297
+ executionHost: agentCoreExecutionHost,
298
+ modelCredentials,
299
+ mcp: { allowedTools: ['read_workspace_snapshot'] },
300
+ })
301
+ const agentExecutionTransport = new HostedHeartbeatAgentExecutionTransport({
302
+ runner: hostedHeartbeat,
303
+ resolveInvocationContext: ({ taskId, executionId, signal }) => (
304
+ resolveAuthorizedHeartbeatInvocation({ taskId, executionId, signal })
305
+ ),
306
+ })
307
+
308
+ const scheduler = HeartbeatSchedulerService.start({
309
+ store: heddleHeartbeatStore,
310
+ agentExecutionTransport,
311
+ })
312
+ ```
313
+
314
+ The coordinator still owns task lookup, claims, checkpoint loading, cancellation,
315
+ claim-fenced settlement, history, and recovery. The Runtime receives a bounded
316
+ task/checkpoint request plus invocation-scoped authority and model credentials;
317
+ it receives no Heddle database credential. Omitting `agentExecutionTransport`
318
+ preserves the existing in-process runner.
319
+
281
320
  ## Verify an adopter integration locally
282
321
 
283
322
  The explicit `testing` subpath provides a real loopback implementation of the
@@ -1,14 +1,15 @@
1
- import { type ExecutionHostStreamEvent } from '../contracts/index.js';
2
- import { type ExecutionHost, type ExecutionHostConversationTurn } from '../http-sse/index.js';
1
+ import { type ExecutionHostHeartbeatStreamEvent, type ExecutionHostStreamEvent } from '../contracts/index.js';
2
+ import { type ExecutionHost, type ExecutionHostConversationTurn, type ExecutionHostHeartbeatTask, type HeartbeatExecutionHost } from '../http-sse/index.js';
3
3
  import type { AgentCoreExecutionHostConfig } from './types.js';
4
4
  /**
5
5
  * Invokes one compatible Heddle Execution Host through AWS AgentCore while
6
6
  * reusing the package's strict request and SSE protocol validation.
7
7
  */
8
- export declare class AgentCoreExecutionHost implements ExecutionHost {
8
+ export declare class AgentCoreExecutionHost implements ExecutionHost, HeartbeatExecutionHost {
9
9
  #private;
10
10
  constructor(config: AgentCoreExecutionHostConfig);
11
11
  streamConversationTurn(input: ExecutionHostConversationTurn): AsyncIterable<ExecutionHostStreamEvent>;
12
+ streamHeartbeatTask(input: ExecutionHostHeartbeatTask): AsyncIterable<ExecutionHostHeartbeatStreamEvent>;
12
13
  close(): void;
13
14
  }
14
15
  export declare const AGENTCORE_FORWARDED_HEADER_NAMES: readonly ["x-heddle-execution-host-assertion", "x-heddle-execution-host-mcp-capability", "x-heddle-execution-host-model-api-key"];
@@ -1 +1 @@
1
- {"version":3,"file":"agentcore-execution-host.d.ts","sourceRoot":"","sources":["../../src/agentcore/agentcore-execution-host.ts"],"names":[],"mappings":"AAMA,OAAO,EAML,KAAK,wBAAwB,EAC9B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,6BAA6B,EACnC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EACV,4BAA4B,EAE7B,MAAM,YAAY,CAAC;AAoBpB;;;GAGG;AACH,qBAAa,sBAAuB,YAAW,aAAa;;gBAM9C,MAAM,EAAE,4BAA4B;IAgBhD,sBAAsB,CACpB,KAAK,EAAE,6BAA6B,GACnC,aAAa,CAAC,wBAAwB,CAAC;IAK1C,KAAK,IAAI,IAAI;CAiEd;AAsGD,eAAO,MAAM,gCAAgC,mIAIlC,CAAC;AAEZ,eAAO,MAAM,+BAA+B,kDAEjC,CAAC"}
1
+ {"version":3,"file":"agentcore-execution-host.d.ts","sourceRoot":"","sources":["../../src/agentcore/agentcore-execution-host.ts"],"names":[],"mappings":"AAMA,OAAO,EAML,KAAK,iCAAiC,EACtC,KAAK,wBAAwB,EAC9B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,6BAA6B,EAClC,KAAK,0BAA0B,EAC/B,KAAK,sBAAsB,EAC5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EACV,4BAA4B,EAE7B,MAAM,YAAY,CAAC;AAoBpB;;;GAGG;AACH,qBAAa,sBACb,YAAW,aAAa,EAAE,sBAAsB;;gBAMlC,MAAM,EAAE,4BAA4B;IAgBhD,sBAAsB,CACpB,KAAK,EAAE,6BAA6B,GACnC,aAAa,CAAC,wBAAwB,CAAC;IAK1C,mBAAmB,CACjB,KAAK,EAAE,0BAA0B,GAChC,aAAa,CAAC,iCAAiC,CAAC;IAKnD,KAAK,IAAI,IAAI;CAiEd;AAsGD,eAAO,MAAM,gCAAgC,mIAIlC,CAAC;AAEZ,eAAO,MAAM,+BAA+B,kDAEjC,CAAC"}
@@ -47,6 +47,10 @@ export class AgentCoreExecutionHost {
47
47
  assertAgentCoreRuntimeSessionId(input.runtimeSessionId);
48
48
  return this.#wire.streamConversationTurn(input);
49
49
  }
50
+ streamHeartbeatTask(input) {
51
+ assertAgentCoreRuntimeSessionId(input.runtimeSessionId);
52
+ return this.#wire.streamHeartbeatTask(input);
53
+ }
50
54
  close() {
51
55
  this.#client.destroy?.();
52
56
  }
@@ -1 +1 @@
1
- {"version":3,"file":"agentcore-execution-host.js","sourceRoot":"","sources":["../../src/agentcore/agentcore-execution-host.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,yBAAyB,GAE1B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EACL,gCAAgC,EAChC,0BAA0B,EAC1B,iCAAiC,EACjC,qBAAqB,EACrB,oBAAoB,GAErB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,uBAAuB,GAGxB,MAAM,sBAAsB,CAAC;AAM9B,MAAM,YAAY,GAAG,kBAAkB,CAAC;AACxC,MAAM,MAAM,GAAG,mBAAmB,CAAC;AACnC,MAAM,6BAA6B,GAAG,EAAE,CAAC;AACzC,MAAM,6BAA6B,GAAG,GAAG,CAAC;AAC1C,MAAM,0BAA0B,GAAG,iCAAiC,CAAC;AACrE,MAAM,eAAe,GAAG,IAAI,GAAG,CAA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AAI,MAAM,IAAI,GAAG;QACjE,CAAC,CAAC,MAAM;QACR,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;AAClD,CAAC;AAED,MAAM,CAAC,MAAM,gCAAgC,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5D,0BAA0B;IAC1B,qBAAqB;IACrB,oBAAoB;CACZ,CAAC,CAAC;AAEZ,MAAM,CAAC,MAAM,+BAA+B,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3D,iCAAiC;CACzB,CAAC,CAAC","sourcesContent":["import {\n BedrockAgentCoreClient,\n InvokeAgentRuntimeCommand,\n type InvokeAgentRuntimeCommandOutput,\n} from '@aws-sdk/client-bedrock-agentcore';\nimport { HttpRequest } from '@smithy/protocol-http';\nimport {\n AGENTCORE_RUNTIME_SESSION_HEADER,\n EXECUTION_ASSERTION_HEADER,\n EXECUTION_HOST_LOCAL_TOKEN_HEADER,\n MCP_CAPABILITY_HEADER,\n MODEL_API_KEY_HEADER,\n type ExecutionHostStreamEvent,\n} from '../contracts/index.js';\nimport {\n DirectHttpExecutionHost,\n type ExecutionHost,\n type ExecutionHostConversationTurn,\n} from '../http-sse/index.js';\nimport type {\n AgentCoreExecutionHostConfig,\n AgentCoreRuntimeClient,\n} from './types.js';\n\nconst CONTENT_TYPE = 'application/json';\nconst ACCEPT = 'text/event-stream';\nconst MIN_RUNTIME_SESSION_ID_LENGTH = 33;\nconst MAX_RUNTIME_SESSION_ID_LENGTH = 256;\nconst RUNTIME_SESSION_ID_PATTERN = /^[A-Za-z0-9](?:-*[A-Za-z0-9])+$/;\nconst WIRE_BRIDGE_URL = new URL('http://127.0.0.1/agentcore-bridge');\nconst NON_FORWARDED_LOCAL_TOKEN = 'agentcore-bridge-token-never-forwarded';\nconst SERVICE_ERROR_CODES = new Map<string, string>([\n ['AccessDeniedException', 'access_denied'],\n ['InternalServerException', 'runtime_internal'],\n ['ResourceNotFoundException', 'runtime_not_found'],\n ['RetryableConflictException', 'runtime_conflict'],\n ['RuntimeClientError', 'runtime_client_error'],\n ['ServiceQuotaExceededException', 'quota_exceeded'],\n ['ThrottlingException', 'throttled'],\n ['ValidationException', 'invalid_request'],\n]);\n\n/**\n * Invokes one compatible Heddle Execution Host through AWS AgentCore while\n * reusing the package's strict request and SSE protocol validation.\n */\nexport class AgentCoreExecutionHost implements ExecutionHost {\n readonly #client: AgentCoreRuntimeClient;\n readonly #runtimeArn: string;\n readonly #qualifier?: string;\n readonly #wire: DirectHttpExecutionHost;\n\n constructor(config: AgentCoreExecutionHostConfig) {\n this.#runtimeArn = config.runtimeArn;\n this.#qualifier = config.qualifier;\n this.#client = config.client ?? new BedrockAgentCoreClient({\n region: config.region,\n // Invocation settlement is ambiguous after a transport interruption.\n // Product policy, not the AWS client, decides whether a turn may retry.\n maxAttempts: 1,\n });\n this.#wire = new DirectHttpExecutionHost({\n baseUrl: WIRE_BRIDGE_URL,\n localToken: NON_FORWARDED_LOCAL_TOKEN,\n fetch: (_input, init) => this.#invoke(init),\n });\n }\n\n streamConversationTurn(\n input: ExecutionHostConversationTurn,\n ): AsyncIterable<ExecutionHostStreamEvent> {\n assertAgentCoreRuntimeSessionId(input.runtimeSessionId);\n return this.#wire.streamConversationTurn(input);\n }\n\n close(): void {\n this.#client.destroy?.();\n }\n\n async #invoke(init?: RequestInit): Promise<Response> {\n if (init?.method !== 'POST' || typeof init.body !== 'string') {\n throw new Error('AgentCore wire bridge received an invalid request.');\n }\n const headers = new Headers(init.headers);\n const runtimeSessionId = requireHeader(\n headers,\n AGENTCORE_RUNTIME_SESSION_HEADER,\n );\n const customHeaders = Object.fromEntries([\n [\n EXECUTION_ASSERTION_HEADER,\n requireHeader(headers, EXECUTION_ASSERTION_HEADER),\n ],\n [MODEL_API_KEY_HEADER, requireHeader(headers, MODEL_API_KEY_HEADER)],\n ...(headers.has(MCP_CAPABILITY_HEADER)\n ? [[MCP_CAPABILITY_HEADER, headers.get(MCP_CAPABILITY_HEADER)!]]\n : []),\n ]);\n const command = new InvokeAgentRuntimeCommand({\n agentRuntimeArn: this.#runtimeArn,\n runtimeSessionId,\n qualifier: this.#qualifier,\n contentType: CONTENT_TYPE,\n accept: ACCEPT,\n payload: new TextEncoder().encode(init.body),\n });\n addSignedCustomHeaders(command, customHeaders);\n const signal = init.signal ?? undefined;\n\n try {\n const output = await this.#client.send(command, { abortSignal: signal });\n return new Response(\n output.response ? toReadableStream(output.response) : null,\n {\n status: output.statusCode ?? output.$metadata.httpStatusCode ?? 200,\n headers: {\n 'content-type': output.contentType ?? 'application/octet-stream',\n },\n },\n );\n } catch (error) {\n if (signal?.aborted) {\n throw error;\n }\n const status = readServiceStatus(error);\n if (!status) {\n throw error;\n }\n const code = SERVICE_ERROR_CODES.get(readErrorName(error)) ?? 'unknown';\n return new Response(JSON.stringify({\n error: {\n code,\n message: 'AgentCore rejected the invocation.',\n },\n }), {\n status,\n headers: { 'content-type': CONTENT_TYPE },\n });\n }\n }\n}\n\nfunction assertAgentCoreRuntimeSessionId(value: string): void {\n if (\n value.length < MIN_RUNTIME_SESSION_ID_LENGTH\n || value.length > MAX_RUNTIME_SESSION_ID_LENGTH\n || !RUNTIME_SESSION_ID_PATTERN.test(value)\n ) {\n throw new Error('AgentCore runtime session ID is not provider-compatible.');\n }\n}\n\nfunction addSignedCustomHeaders(\n command: InvokeAgentRuntimeCommand,\n headers: Readonly<Record<string, string>>,\n): void {\n command.middlewareStack.add(\n (next) => async (args) => {\n if (!HttpRequest.isInstance(args.request)) {\n throw new Error('AgentCore invocation did not produce an HTTP request.');\n }\n Object.assign(args.request.headers, headers);\n return await next(args);\n },\n {\n step: 'build',\n priority: 'low',\n name: 'heddleAgentCoreCustomHeaders',\n },\n );\n}\n\nfunction requireHeader(headers: Headers, name: string): string {\n const value = headers.get(name);\n if (!value) {\n throw new Error('AgentCore wire bridge omitted required authority.');\n }\n return value;\n}\n\nfunction toReadableStream(\n source: NonNullable<InvokeAgentRuntimeCommandOutput['response']>,\n): ReadableStream<Uint8Array> {\n if (source instanceof Blob) {\n return source.stream();\n }\n if (source instanceof ReadableStream) {\n return source;\n }\n if (!isAsyncIterable(source)) {\n throw new Error('AgentCore returned an unsupported stream type.');\n }\n const iterator = source[Symbol.asyncIterator]();\n return new ReadableStream<Uint8Array>({\n async pull(controller) {\n try {\n const item = await iterator.next();\n if (item.done) {\n controller.close();\n return;\n }\n if (!(item.value instanceof Uint8Array)) {\n throw new Error('AgentCore returned a non-binary stream chunk.');\n }\n controller.enqueue(item.value);\n } catch (error) {\n controller.error(error);\n }\n },\n async cancel() {\n await iterator.return?.();\n },\n });\n}\n\nfunction isAsyncIterable(\n value: unknown,\n): value is AsyncIterable<Uint8Array> {\n return Boolean(\n value\n && typeof value === 'object'\n && Symbol.asyncIterator in value\n && typeof value[Symbol.asyncIterator] === 'function',\n );\n}\n\nfunction readServiceStatus(error: unknown): number | undefined {\n if (!error || typeof error !== 'object' || !('$metadata' in error)) {\n return undefined;\n }\n const metadata = (error as { $metadata?: { httpStatusCode?: unknown } })\n .$metadata;\n const status = metadata?.httpStatusCode;\n return typeof status === 'number' && status >= 400 && status <= 599\n ? status\n : undefined;\n}\n\nfunction readErrorName(error: unknown): string {\n return error instanceof Error ? error.name : '';\n}\n\nexport const AGENTCORE_FORWARDED_HEADER_NAMES = Object.freeze([\n EXECUTION_ASSERTION_HEADER,\n MCP_CAPABILITY_HEADER,\n MODEL_API_KEY_HEADER,\n] as const);\n\nexport const AGENTCORE_EXCLUDED_HEADER_NAMES = Object.freeze([\n EXECUTION_HOST_LOCAL_TOKEN_HEADER,\n] as const);\n"]}
1
+ {"version":3,"file":"agentcore-execution-host.js","sourceRoot":"","sources":["../../src/agentcore/agentcore-execution-host.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,yBAAyB,GAE1B,MAAM,m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AAM,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;QAC5B,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,SAAS,eAAe,CACtB,KAAc;IAEd,OAAO,OAAO,CACZ,KAAK;WACF,OAAO,KAAK,KAAK,QAAQ;WACzB,MAAM,CAAC,aAAa,IAAI,KAAK;WAC7B,OAAO,KAAK,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,UAAU,CACrD,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAc;IACvC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,CAAC,WAAW,IAAI,KAAK,CAAC,EAAE,CAAC;QACnE,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,QAAQ,GAAI,KAAsD;SACrE,SAAS,CAAC;IACb,MAAM,MAAM,GAAG,QAAQ,EAAE,cAAc,CAAC;IACxC,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,IAAI,GAAG;QACjE,CAAC,CAAC,MAAM;QACR,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;AAClD,CAAC;AAED,MAAM,CAAC,MAAM,gCAAgC,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5D,0BAA0B;IAC1B,qBAAqB;IACrB,oBAAoB;CACZ,CAAC,CAAC;AAEZ,MAAM,CAAC,MAAM,+BAA+B,GAAG,MAAM,CAAC,MAAM,CAAC;IAC3D,iCAAiC;CACzB,CAAC,CAAC","sourcesContent":["import {\n BedrockAgentCoreClient,\n InvokeAgentRuntimeCommand,\n type InvokeAgentRuntimeCommandOutput,\n} from '@aws-sdk/client-bedrock-agentcore';\nimport { HttpRequest } from '@smithy/protocol-http';\nimport {\n AGENTCORE_RUNTIME_SESSION_HEADER,\n EXECUTION_ASSERTION_HEADER,\n EXECUTION_HOST_LOCAL_TOKEN_HEADER,\n MCP_CAPABILITY_HEADER,\n MODEL_API_KEY_HEADER,\n type ExecutionHostHeartbeatStreamEvent,\n type ExecutionHostStreamEvent,\n} from '../contracts/index.js';\nimport {\n DirectHttpExecutionHost,\n type ExecutionHost,\n type ExecutionHostConversationTurn,\n type ExecutionHostHeartbeatTask,\n type HeartbeatExecutionHost,\n} from '../http-sse/index.js';\nimport type {\n AgentCoreExecutionHostConfig,\n AgentCoreRuntimeClient,\n} from './types.js';\n\nconst CONTENT_TYPE = 'application/json';\nconst ACCEPT = 'text/event-stream';\nconst MIN_RUNTIME_SESSION_ID_LENGTH = 33;\nconst MAX_RUNTIME_SESSION_ID_LENGTH = 256;\nconst RUNTIME_SESSION_ID_PATTERN = /^[A-Za-z0-9](?:-*[A-Za-z0-9])+$/;\nconst WIRE_BRIDGE_URL = new URL('http://127.0.0.1/agentcore-bridge');\nconst NON_FORWARDED_LOCAL_TOKEN = 'agentcore-bridge-token-never-forwarded';\nconst SERVICE_ERROR_CODES = new Map<string, string>([\n ['AccessDeniedException', 'access_denied'],\n ['InternalServerException', 'runtime_internal'],\n ['ResourceNotFoundException', 'runtime_not_found'],\n ['RetryableConflictException', 'runtime_conflict'],\n ['RuntimeClientError', 'runtime_client_error'],\n ['ServiceQuotaExceededException', 'quota_exceeded'],\n ['ThrottlingException', 'throttled'],\n ['ValidationException', 'invalid_request'],\n]);\n\n/**\n * Invokes one compatible Heddle Execution Host through AWS AgentCore while\n * reusing the package's strict request and SSE protocol validation.\n */\nexport class AgentCoreExecutionHost\nimplements ExecutionHost, HeartbeatExecutionHost {\n readonly #client: AgentCoreRuntimeClient;\n readonly #runtimeArn: string;\n readonly #qualifier?: string;\n readonly #wire: DirectHttpExecutionHost;\n\n constructor(config: AgentCoreExecutionHostConfig) {\n this.#runtimeArn = config.runtimeArn;\n this.#qualifier = config.qualifier;\n this.#client = config.client ?? new BedrockAgentCoreClient({\n region: config.region,\n // Invocation settlement is ambiguous after a transport interruption.\n // Product policy, not the AWS client, decides whether a turn may retry.\n maxAttempts: 1,\n });\n this.#wire = new DirectHttpExecutionHost({\n baseUrl: WIRE_BRIDGE_URL,\n localToken: NON_FORWARDED_LOCAL_TOKEN,\n fetch: (_input, init) => this.#invoke(init),\n });\n }\n\n streamConversationTurn(\n input: ExecutionHostConversationTurn,\n ): AsyncIterable<ExecutionHostStreamEvent> {\n assertAgentCoreRuntimeSessionId(input.runtimeSessionId);\n return this.#wire.streamConversationTurn(input);\n }\n\n streamHeartbeatTask(\n input: ExecutionHostHeartbeatTask,\n ): AsyncIterable<ExecutionHostHeartbeatStreamEvent> {\n assertAgentCoreRuntimeSessionId(input.runtimeSessionId);\n return this.#wire.streamHeartbeatTask(input);\n }\n\n close(): void {\n this.#client.destroy?.();\n }\n\n async #invoke(init?: RequestInit): Promise<Response> {\n if (init?.method !== 'POST' || typeof init.body !== 'string') {\n throw new Error('AgentCore wire bridge received an invalid request.');\n }\n const headers = new Headers(init.headers);\n const runtimeSessionId = requireHeader(\n headers,\n AGENTCORE_RUNTIME_SESSION_HEADER,\n );\n const customHeaders = Object.fromEntries([\n [\n EXECUTION_ASSERTION_HEADER,\n requireHeader(headers, EXECUTION_ASSERTION_HEADER),\n ],\n [MODEL_API_KEY_HEADER, requireHeader(headers, MODEL_API_KEY_HEADER)],\n ...(headers.has(MCP_CAPABILITY_HEADER)\n ? [[MCP_CAPABILITY_HEADER, headers.get(MCP_CAPABILITY_HEADER)!]]\n : []),\n ]);\n const command = new InvokeAgentRuntimeCommand({\n agentRuntimeArn: this.#runtimeArn,\n runtimeSessionId,\n qualifier: this.#qualifier,\n contentType: CONTENT_TYPE,\n accept: ACCEPT,\n payload: new TextEncoder().encode(init.body),\n });\n addSignedCustomHeaders(command, customHeaders);\n const signal = init.signal ?? undefined;\n\n try {\n const output = await this.#client.send(command, { abortSignal: signal });\n return new Response(\n output.response ? toReadableStream(output.response) : null,\n {\n status: output.statusCode ?? output.$metadata.httpStatusCode ?? 200,\n headers: {\n 'content-type': output.contentType ?? 'application/octet-stream',\n },\n },\n );\n } catch (error) {\n if (signal?.aborted) {\n throw error;\n }\n const status = readServiceStatus(error);\n if (!status) {\n throw error;\n }\n const code = SERVICE_ERROR_CODES.get(readErrorName(error)) ?? 'unknown';\n return new Response(JSON.stringify({\n error: {\n code,\n message: 'AgentCore rejected the invocation.',\n },\n }), {\n status,\n headers: { 'content-type': CONTENT_TYPE },\n });\n }\n }\n}\n\nfunction assertAgentCoreRuntimeSessionId(value: string): void {\n if (\n value.length < MIN_RUNTIME_SESSION_ID_LENGTH\n || value.length > MAX_RUNTIME_SESSION_ID_LENGTH\n || !RUNTIME_SESSION_ID_PATTERN.test(value)\n ) {\n throw new Error('AgentCore runtime session ID is not provider-compatible.');\n }\n}\n\nfunction addSignedCustomHeaders(\n command: InvokeAgentRuntimeCommand,\n headers: Readonly<Record<string, string>>,\n): void {\n command.middlewareStack.add(\n (next) => async (args) => {\n if (!HttpRequest.isInstance(args.request)) {\n throw new Error('AgentCore invocation did not produce an HTTP request.');\n }\n Object.assign(args.request.headers, headers);\n return await next(args);\n },\n {\n step: 'build',\n priority: 'low',\n name: 'heddleAgentCoreCustomHeaders',\n },\n );\n}\n\nfunction requireHeader(headers: Headers, name: string): string {\n const value = headers.get(name);\n if (!value) {\n throw new Error('AgentCore wire bridge omitted required authority.');\n }\n return value;\n}\n\nfunction toReadableStream(\n source: NonNullable<InvokeAgentRuntimeCommandOutput['response']>,\n): ReadableStream<Uint8Array> {\n if (source instanceof Blob) {\n return source.stream();\n }\n if (source instanceof ReadableStream) {\n return source;\n }\n if (!isAsyncIterable(source)) {\n throw new Error('AgentCore returned an unsupported stream type.');\n }\n const iterator = source[Symbol.asyncIterator]();\n return new ReadableStream<Uint8Array>({\n async pull(controller) {\n try {\n const item = await iterator.next();\n if (item.done) {\n controller.close();\n return;\n }\n if (!(item.value instanceof Uint8Array)) {\n throw new Error('AgentCore returned a non-binary stream chunk.');\n }\n controller.enqueue(item.value);\n } catch (error) {\n controller.error(error);\n }\n },\n async cancel() {\n await iterator.return?.();\n },\n });\n}\n\nfunction isAsyncIterable(\n value: unknown,\n): value is AsyncIterable<Uint8Array> {\n return Boolean(\n value\n && typeof value === 'object'\n && Symbol.asyncIterator in value\n && typeof value[Symbol.asyncIterator] === 'function',\n );\n}\n\nfunction readServiceStatus(error: unknown): number | undefined {\n if (!error || typeof error !== 'object' || !('$metadata' in error)) {\n return undefined;\n }\n const metadata = (error as { $metadata?: { httpStatusCode?: unknown } })\n .$metadata;\n const status = metadata?.httpStatusCode;\n return typeof status === 'number' && status >= 400 && status <= 599\n ? status\n : undefined;\n}\n\nfunction readErrorName(error: unknown): string {\n return error instanceof Error ? error.name : '';\n}\n\nexport const AGENTCORE_FORWARDED_HEADER_NAMES = Object.freeze([\n EXECUTION_ASSERTION_HEADER,\n MCP_CAPABILITY_HEADER,\n MODEL_API_KEY_HEADER,\n] as const);\n\nexport const AGENTCORE_EXCLUDED_HEADER_NAMES = Object.freeze([\n EXECUTION_HOST_LOCAL_TOKEN_HEADER,\n] as const);\n"]}
@@ -1,3 +1,3 @@
1
1
  export { JoseExecutionAuthority } from './jose-execution-authority.js';
2
- export type { ExecutionAuthority, ExecutionAuthorityConfig, ExecutionAuthorityIssueInput, ExecutionAuthorityKeyPair, ExecutionAuthorityMcpConfig, IssuedExecutionAuthority, IssuedExecutionAuthorityMetadata, IssuedMcpCapabilityMetadata, JoseExecutionAuthorityOptions, } from './types.js';
2
+ export type { ExecutionAuthority, ExecutionAuthorityConfig, ExecutionAuthorityIssuer, ExecutionAuthorityIssueInput, ExecutionAuthorityKeyPair, ExecutionAuthorityMcpConfig, IssuedExecutionAuthority, IssuedExecutionAuthorityMetadata, IssuedMcpCapabilityMetadata, JoseExecutionAuthorityOptions, } from './types.js';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/authority/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,YAAY,EACV,kBAAkB,EAClB,wBAAwB,EACxB,4BAA4B,EAC5B,yBAAyB,EACzB,2BAA2B,EAC3B,wBAAwB,EACxB,gCAAgC,EAChC,2BAA2B,EAC3B,6BAA6B,GAC9B,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/authority/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,YAAY,EACV,kBAAkB,EAClB,wBAAwB,EACxB,wBAAwB,EACxB,4BAA4B,EAC5B,yBAAyB,EACzB,2BAA2B,EAC3B,wBAAwB,EACxB,gCAAgC,EAChC,2BAA2B,EAC3B,6BAA6B,GAC9B,MAAM,YAAY,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/authority/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC","sourcesContent":["export { JoseExecutionAuthority } from './jose-execution-authority.js';\nexport type {\n ExecutionAuthority,\n ExecutionAuthorityConfig,\n ExecutionAuthorityIssueInput,\n ExecutionAuthorityKeyPair,\n ExecutionAuthorityMcpConfig,\n IssuedExecutionAuthority,\n IssuedExecutionAuthorityMetadata,\n IssuedMcpCapabilityMetadata,\n JoseExecutionAuthorityOptions,\n} from './types.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/authority/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC","sourcesContent":["export { JoseExecutionAuthority } from './jose-execution-authority.js';\nexport type {\n ExecutionAuthority,\n ExecutionAuthorityConfig,\n ExecutionAuthorityIssuer,\n ExecutionAuthorityIssueInput,\n ExecutionAuthorityKeyPair,\n ExecutionAuthorityMcpConfig,\n IssuedExecutionAuthority,\n IssuedExecutionAuthorityMetadata,\n IssuedMcpCapabilityMetadata,\n JoseExecutionAuthorityOptions,\n} from './types.js';\n"]}
@@ -1,7 +1,7 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { CompactSign, SignJWT, compactVerify, exportJWK, } from 'jose';
3
3
  import { z } from 'zod';
4
- import { CONVERSATION_TURN_WORKFLOW, EXECUTION_ASSERTION_TYPE, EXECUTION_CONTRACT_VERSION, ExecutionScopeSchema, JwtAudienceSchema, JwtIssuerSchema, MCP_CAPABILITY_TYPE, McpAllowedToolsSchema, McpServerIdSchema, OpaqueIdSchema, RuntimeSessionIdSchema, } from '../contracts/index.js';
4
+ import { EXECUTION_ASSERTION_TYPE, EXECUTION_CONTRACT_VERSION, ExecutionScopeSchema, HostedExecutionWorkflowSchema, JwtAudienceSchema, JwtIssuerSchema, MCP_CAPABILITY_TYPE, McpAllowedToolsSchema, McpServerIdSchema, OpaqueIdSchema, RuntimeSessionIdSchema, } from '../contracts/index.js';
5
5
  const SIGNING_ALGORITHM = 'ES256';
6
6
  const ExecutionAuthorityMcpConfigSchema = z.object({
7
7
  audience: JwtAudienceSchema,
@@ -39,7 +39,7 @@ const ExecutionAuthorityIssueInputSchema = z.object({
39
39
  scope: ExecutionIssueScopeSchema,
40
40
  runtimeSessionId: RuntimeSessionIdSchema,
41
41
  invocationId: OpaqueIdSchema,
42
- workflow: z.literal(CONVERSATION_TURN_WORKFLOW),
42
+ workflow: HostedExecutionWorkflowSchema,
43
43
  mcp: z.object({
44
44
  allowedTools: McpAllowedToolsSchema,
45
45
  }).strict().optional(),
@@ -1 +1 @@
1
- {"version":3,"file":"jose-execution-authority.js","sourceRoot":"","sources":["../../src/authority/jose-execution-authority.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,WAAW,EACX,OAAO,EACP,aAAa,EACb,SAAS,GA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AAE,CAAC,CAAC;AACxE,CAAC","sourcesContent":["import { randomUUID } from 'node:crypto';\nimport {\n CompactSign,\n SignJWT,\n compactVerify,\n exportJWK,\n type CryptoKey,\n type JWK,\n type JSONWebKeySet,\n} from 'jose';\nimport { z } from 'zod';\nimport {\n CONVERSATION_TURN_WORKFLOW,\n EXECUTION_ASSERTION_TYPE,\n EXECUTION_CONTRACT_VERSION,\n ExecutionScopeSchema,\n JwtAudienceSchema,\n JwtIssuerSchema,\n MCP_CAPABILITY_TYPE,\n McpAllowedToolsSchema,\n McpServerIdSchema,\n OpaqueIdSchema,\n RuntimeSessionIdSchema,\n type ExecutionScope,\n} from '../contracts/index.js';\nimport type {\n ExecutionAuthority,\n ExecutionAuthorityConfig,\n ExecutionAuthorityIssueInput,\n ExecutionAuthorityKeyPair,\n IssuedExecutionAuthority,\n IssuedExecutionAuthorityMetadata,\n JoseExecutionAuthorityOptions,\n} from './types.js';\n\nconst SIGNING_ALGORITHM = 'ES256';\nconst ExecutionAuthorityMcpConfigSchema = z.object({\n audience: JwtAudienceSchema,\n serverId: McpServerIdSchema,\n ttlSeconds: z.number().int().min(1).max(15 * 60),\n}).strict();\nconst ExecutionAuthorityConfigSchema = z.object({\n issuer: JwtIssuerSchema,\n adopterId: OpaqueIdSchema,\n executionAudience: JwtAudienceSchema,\n keyId: OpaqueIdSchema,\n executionTtlSeconds: z.number().int().min(1).max(15 * 60),\n mcp: ExecutionAuthorityMcpConfigSchema.optional(),\n}).strict().superRefine((config, context) => {\n if (!config.mcp) {\n return;\n }\n if (config.executionAudience === config.mcp.audience) {\n context.addIssue({\n code: 'custom',\n path: ['mcp', 'audience'],\n message: 'must be distinct from the execution audience',\n });\n }\n if (config.mcp.ttlSeconds < config.executionTtlSeconds) {\n context.addIssue({\n code: 'custom',\n path: ['mcp', 'ttlSeconds'],\n message: 'must not expire before execution admission authority',\n });\n }\n});\nconst ExecutionIssueScopeSchema = ExecutionScopeSchema.omit({ adopterId: true });\nconst ExecutionAuthorityIssueInputSchema = z.object({\n scope: ExecutionIssueScopeSchema,\n runtimeSessionId: RuntimeSessionIdSchema,\n invocationId: OpaqueIdSchema,\n workflow: z.literal(CONVERSATION_TURN_WORKFLOW),\n mcp: z.object({\n allowedTools: McpAllowedToolsSchema,\n }).strict().optional(),\n}).strict();\nconst PublicP256JwkSchema = z.object({\n kty: z.literal('EC'),\n crv: z.literal('P-256'),\n x: z.string().regex(/^[A-Za-z0-9_-]+$/),\n y: z.string().regex(/^[A-Za-z0-9_-]+$/),\n}).passthrough().superRefine((jwk, context) => {\n const privateFields = ['d', 'p', 'q', 'dp', 'dq', 'qi', 'oth', 'k'];\n if (privateFields.some((field) => field in jwk)) {\n context.addIssue({\n code: 'custom',\n message: 'must not contain private key material',\n });\n }\n});\n\n/**\n * ES256 reference adapter for issuing one invocation's admission assertion and\n * optional product-MCP capability.\n */\nexport class JoseExecutionAuthority implements ExecutionAuthority {\n readonly #config: z.infer<typeof ExecutionAuthorityConfigSchema>;\n readonly #privateKey: CryptoKey;\n readonly #publicJwk: Readonly<JWK>;\n readonly #now: () => Date;\n readonly #createCapabilityId: () => string;\n\n private constructor(\n config: ExecutionAuthorityConfig,\n key: { privateKey: CryptoKey; publicJwk: JWK },\n options: JoseExecutionAuthorityOptions,\n ) {\n this.#config = deepFreezeConfig(ExecutionAuthorityConfigSchema.parse(config));\n assertPrivateSigningKey(key.privateKey);\n this.#privateKey = key.privateKey;\n this.#publicJwk = projectPublicJwk(key.publicJwk, this.#config.keyId);\n this.#now = options.now ?? (() => new Date());\n this.#createCapabilityId = options.createCapabilityId ?? randomUUID;\n }\n\n static async create(\n config: ExecutionAuthorityConfig,\n keyPair: ExecutionAuthorityKeyPair,\n options: JoseExecutionAuthorityOptions = {},\n ): Promise<JoseExecutionAuthority> {\n assertPrivateSigningKey(keyPair.privateKey);\n assertPublicVerificationKey(keyPair.publicKey);\n await assertMatchingKeyPair(keyPair);\n return new JoseExecutionAuthority(\n config,\n {\n privateKey: keyPair.privateKey,\n publicJwk: await exportJWK(keyPair.publicKey),\n },\n options,\n );\n }\n\n async issue(\n input: ExecutionAuthorityIssueInput,\n ): Promise<IssuedExecutionAuthority> {\n const authority = ExecutionAuthorityIssueInputSchema.parse(input);\n if (authority.mcp && !this.#config.mcp) {\n throw new Error(\n 'Execution authority cannot issue an MCP capability without MCP deployment configuration.',\n );\n }\n\n const issuedAt = toEpochSeconds(this.#now());\n const executionExpiresAt = issuedAt + this.#config.executionTtlSeconds;\n const executionAssertion = await this.#signExecutionAssertion(\n authority,\n issuedAt,\n executionExpiresAt,\n );\n\n const mcp = authority.mcp && this.#config.mcp\n ? await this.#issueMcpCapability(\n { ...authority, mcp: authority.mcp },\n issuedAt,\n )\n : undefined;\n\n return new ProtectedIssuedExecutionAuthority(\n executionAssertion,\n mcp?.assertion,\n freezeIssuedMetadata({\n scope: {\n adopterId: this.#config.adopterId,\n ...authority.scope,\n },\n runtimeSessionId: authority.runtimeSessionId,\n invocationId: authority.invocationId,\n workflow: authority.workflow,\n issuedAt: toIsoTimestamp(issuedAt),\n executionExpiresAt: toIsoTimestamp(executionExpiresAt),\n ...(mcp ? { mcp: mcp.metadata } : {}),\n }),\n );\n }\n\n publicJwks(): JSONWebKeySet {\n return { keys: [{ ...this.#publicJwk }] };\n }\n\n #signExecutionAssertion(\n input: z.infer<typeof ExecutionAuthorityIssueInputSchema>,\n issuedAt: number,\n expiresAt: number,\n ): Promise<string> {\n return new SignJWT({\n contractVersion: EXECUTION_CONTRACT_VERSION,\n adopterId: this.#config.adopterId,\n tenantId: input.scope.tenantId,\n productSessionId: input.scope.productSessionId,\n runtimeSessionId: input.runtimeSessionId,\n workflow: input.workflow,\n })\n .setProtectedHeader({\n alg: SIGNING_ALGORITHM,\n kid: this.#config.keyId,\n typ: EXECUTION_ASSERTION_TYPE,\n })\n .setIssuer(this.#config.issuer)\n .setAudience(this.#config.executionAudience)\n .setSubject(input.scope.subjectId)\n .setJti(input.invocationId)\n .setIssuedAt(issuedAt)\n .setExpirationTime(expiresAt)\n .sign(this.#privateKey);\n }\n\n async #issueMcpCapability(\n input: z.infer<typeof ExecutionAuthorityIssueInputSchema> & {\n mcp: { allowedTools: string[] };\n },\n issuedAt: number,\n ): Promise<{\n assertion: string;\n metadata: NonNullable<IssuedExecutionAuthorityMetadata['mcp']>;\n }> {\n const mcpConfig = this.#config.mcp!;\n const capabilityId = OpaqueIdSchema.parse(this.#createCapabilityId());\n if (capabilityId === input.invocationId) {\n throw new Error(\n 'MCP capability identity must be distinct from the invocation identity.',\n );\n }\n const expiresAt = issuedAt + mcpConfig.ttlSeconds;\n const assertion = await new SignJWT({\n contractVersion: EXECUTION_CONTRACT_VERSION,\n adopterId: this.#config.adopterId,\n tenantId: input.scope.tenantId,\n productSessionId: input.scope.productSessionId,\n runtimeSessionId: input.runtimeSessionId,\n invocationId: input.invocationId,\n workflow: input.workflow,\n serverId: mcpConfig.serverId,\n allowedTools: [...input.mcp.allowedTools],\n })\n .setProtectedHeader({\n alg: SIGNING_ALGORITHM,\n kid: this.#config.keyId,\n typ: MCP_CAPABILITY_TYPE,\n })\n .setIssuer(this.#config.issuer)\n .setAudience(mcpConfig.audience)\n .setSubject(input.scope.subjectId)\n .setJti(capabilityId)\n .setIssuedAt(issuedAt)\n .setExpirationTime(expiresAt)\n .sign(this.#privateKey);\n\n return {\n assertion,\n metadata: {\n capabilityId,\n serverId: mcpConfig.serverId,\n allowedTools: Object.freeze([...input.mcp.allowedTools]),\n expiresAt: toIsoTimestamp(expiresAt),\n },\n };\n }\n}\n\nclass ProtectedIssuedExecutionAuthority implements IssuedExecutionAuthority {\n readonly metadata: IssuedExecutionAuthorityMetadata;\n readonly #executionAssertion: string;\n readonly #mcpCapability: string | undefined;\n\n constructor(\n executionAssertion: string,\n mcpCapability: string | undefined,\n metadata: IssuedExecutionAuthorityMetadata,\n ) {\n this.#executionAssertion = executionAssertion;\n this.#mcpCapability = mcpCapability;\n this.metadata = metadata;\n }\n\n executionAssertion(): string {\n return this.#executionAssertion;\n }\n\n mcpCapability(): string | undefined {\n return this.#mcpCapability;\n }\n\n toJSON(): IssuedExecutionAuthorityMetadata {\n return this.metadata;\n }\n}\n\nfunction projectPublicJwk(jwk: JWK, keyId: string): Readonly<JWK> {\n const parsed = PublicP256JwkSchema.parse(jwk);\n return Object.freeze({\n kty: parsed.kty,\n crv: parsed.crv,\n x: parsed.x,\n y: parsed.y,\n alg: SIGNING_ALGORITHM,\n kid: keyId,\n use: 'sig',\n });\n}\n\nfunction assertPrivateSigningKey(key: CryptoKey): void {\n const algorithm = key.algorithm as { name: string; namedCurve?: string };\n const accepted = key.type === 'private'\n && algorithm.name === 'ECDSA'\n && algorithm.namedCurve === 'P-256'\n && key.usages.includes('sign');\n if (!accepted) {\n throw new Error(\n 'Execution authority requires an ES256 private signing key.',\n );\n }\n}\n\nfunction assertPublicVerificationKey(key: CryptoKey): void {\n const algorithm = key.algorithm as { name: string; namedCurve?: string };\n const accepted = key.type === 'public'\n && algorithm.name === 'ECDSA'\n && algorithm.namedCurve === 'P-256'\n && key.usages.includes('verify');\n if (!accepted) {\n throw new Error(\n 'Execution authority requires an ES256 public verification key.',\n );\n }\n}\n\nasync function assertMatchingKeyPair(\n keyPair: ExecutionAuthorityKeyPair,\n): Promise<void> {\n try {\n const probe = await new CompactSign(\n new TextEncoder().encode('heddle-adopter-execution-authority-key-pair'),\n )\n .setProtectedHeader({ alg: SIGNING_ALGORITHM })\n .sign(keyPair.privateKey);\n await compactVerify(probe, keyPair.publicKey, {\n algorithms: [SIGNING_ALGORITHM],\n });\n } catch {\n throw new Error('Execution authority signing keys do not match.');\n }\n}\n\nfunction toEpochSeconds(value: Date): number {\n const seconds = Math.floor(value.getTime() / 1_000);\n if (!Number.isSafeInteger(seconds) || seconds < 0) {\n throw new Error('Execution authority could not resolve a valid issue time.');\n }\n return seconds;\n}\n\nfunction toIsoTimestamp(epochSeconds: number): string {\n return new Date(epochSeconds * 1_000).toISOString();\n}\n\nfunction deepFreezeConfig(\n config: z.infer<typeof ExecutionAuthorityConfigSchema>,\n): z.infer<typeof ExecutionAuthorityConfigSchema> {\n const mcp = config.mcp ? Object.freeze({ ...config.mcp }) : undefined;\n return Object.freeze({ ...config, ...(mcp ? { mcp } : {}) });\n}\n\nfunction freezeIssuedMetadata(\n metadata: IssuedExecutionAuthorityMetadata,\n): IssuedExecutionAuthorityMetadata {\n const scope: ExecutionScope = Object.freeze({ ...metadata.scope });\n const mcp = metadata.mcp\n ? Object.freeze({\n ...metadata.mcp,\n allowedTools: Object.freeze([...metadata.mcp.allowedTools]),\n })\n : undefined;\n return Object.freeze({ ...metadata, scope, ...(mcp ? { mcp } : {}) });\n}\n"]}
1
+ {"version":3,"file":"jose-execution-authority.js","sourceRoot":"","sources":["../../src/authority/jose-execution-authority.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,WAAW,EACX,OAAO,EACP,aAAa,EACb,SAAS,GAIV,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,wBAAwB,EACxB,0BAA0B,EAC1B,oBAAoB,EACpB,6BAA6B,EAC7B,iBAAiB,EACjB,eAAe,EACf,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EACjB,cAAc,EACd,sBAAsB,GAEvB,MAAM,uBAAuB,CAAC;AAW/B,MAAM,iBAAiB,GAAG,OAAO,CAAC;AAClC,MAAM,iCAAiC,GAAG,CAAC,CAAC,MAAM,CAAC;IACjD,QAAQ,EAAE,iBAAiB;IAC3B,QAAQ,EAAE,iBAAiB;IAC3B,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC;CACjD,CAAC,CAAC,MAAM,EAAE,CAAC;AACZ,MAAM,8BAA8B,GAAG,CAAC,CAAC,MAAM,CAA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AAE,CAAC,CAAC;AAC/D,CAAC;AAED,SAAS,oBAAoB,CAC3B,QAA0C;IAE1C,MAAM,KAAK,GAAmB,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IACnE,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG;QACtB,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;YACd,GAAG,QAAQ,CAAC,GAAG;YACf,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;SAC5D,CAAC;QACF,CAAC,CAAC,SAAS,CAAC;IACd,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,QAAQ,EAAE,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AACxE,CAAC","sourcesContent":["import { randomUUID } from 'node:crypto';\nimport {\n CompactSign,\n SignJWT,\n compactVerify,\n exportJWK,\n type CryptoKey,\n type JWK,\n type JSONWebKeySet,\n} from 'jose';\nimport { z } from 'zod';\nimport {\n EXECUTION_ASSERTION_TYPE,\n EXECUTION_CONTRACT_VERSION,\n ExecutionScopeSchema,\n HostedExecutionWorkflowSchema,\n JwtAudienceSchema,\n JwtIssuerSchema,\n MCP_CAPABILITY_TYPE,\n McpAllowedToolsSchema,\n McpServerIdSchema,\n OpaqueIdSchema,\n RuntimeSessionIdSchema,\n type ExecutionScope,\n} from '../contracts/index.js';\nimport type {\n ExecutionAuthority,\n ExecutionAuthorityConfig,\n ExecutionAuthorityIssueInput,\n ExecutionAuthorityKeyPair,\n IssuedExecutionAuthority,\n IssuedExecutionAuthorityMetadata,\n JoseExecutionAuthorityOptions,\n} from './types.js';\n\nconst SIGNING_ALGORITHM = 'ES256';\nconst ExecutionAuthorityMcpConfigSchema = z.object({\n audience: JwtAudienceSchema,\n serverId: McpServerIdSchema,\n ttlSeconds: z.number().int().min(1).max(15 * 60),\n}).strict();\nconst ExecutionAuthorityConfigSchema = z.object({\n issuer: JwtIssuerSchema,\n adopterId: OpaqueIdSchema,\n executionAudience: JwtAudienceSchema,\n keyId: OpaqueIdSchema,\n executionTtlSeconds: z.number().int().min(1).max(15 * 60),\n mcp: ExecutionAuthorityMcpConfigSchema.optional(),\n}).strict().superRefine((config, context) => {\n if (!config.mcp) {\n return;\n }\n if (config.executionAudience === config.mcp.audience) {\n context.addIssue({\n code: 'custom',\n path: ['mcp', 'audience'],\n message: 'must be distinct from the execution audience',\n });\n }\n if (config.mcp.ttlSeconds < config.executionTtlSeconds) {\n context.addIssue({\n code: 'custom',\n path: ['mcp', 'ttlSeconds'],\n message: 'must not expire before execution admission authority',\n });\n }\n});\nconst ExecutionIssueScopeSchema = ExecutionScopeSchema.omit({ adopterId: true });\nconst ExecutionAuthorityIssueInputSchema = z.object({\n scope: ExecutionIssueScopeSchema,\n runtimeSessionId: RuntimeSessionIdSchema,\n invocationId: OpaqueIdSchema,\n workflow: HostedExecutionWorkflowSchema,\n mcp: z.object({\n allowedTools: McpAllowedToolsSchema,\n }).strict().optional(),\n}).strict();\nconst PublicP256JwkSchema = z.object({\n kty: z.literal('EC'),\n crv: z.literal('P-256'),\n x: z.string().regex(/^[A-Za-z0-9_-]+$/),\n y: z.string().regex(/^[A-Za-z0-9_-]+$/),\n}).passthrough().superRefine((jwk, context) => {\n const privateFields = ['d', 'p', 'q', 'dp', 'dq', 'qi', 'oth', 'k'];\n if (privateFields.some((field) => field in jwk)) {\n context.addIssue({\n code: 'custom',\n message: 'must not contain private key material',\n });\n }\n});\n\n/**\n * ES256 reference adapter for issuing one invocation's admission assertion and\n * optional product-MCP capability.\n */\nexport class JoseExecutionAuthority implements ExecutionAuthority {\n readonly #config: z.infer<typeof ExecutionAuthorityConfigSchema>;\n readonly #privateKey: CryptoKey;\n readonly #publicJwk: Readonly<JWK>;\n readonly #now: () => Date;\n readonly #createCapabilityId: () => string;\n\n private constructor(\n config: ExecutionAuthorityConfig,\n key: { privateKey: CryptoKey; publicJwk: JWK },\n options: JoseExecutionAuthorityOptions,\n ) {\n this.#config = deepFreezeConfig(ExecutionAuthorityConfigSchema.parse(config));\n assertPrivateSigningKey(key.privateKey);\n this.#privateKey = key.privateKey;\n this.#publicJwk = projectPublicJwk(key.publicJwk, this.#config.keyId);\n this.#now = options.now ?? (() => new Date());\n this.#createCapabilityId = options.createCapabilityId ?? randomUUID;\n }\n\n static async create(\n config: ExecutionAuthorityConfig,\n keyPair: ExecutionAuthorityKeyPair,\n options: JoseExecutionAuthorityOptions = {},\n ): Promise<JoseExecutionAuthority> {\n assertPrivateSigningKey(keyPair.privateKey);\n assertPublicVerificationKey(keyPair.publicKey);\n await assertMatchingKeyPair(keyPair);\n return new JoseExecutionAuthority(\n config,\n {\n privateKey: keyPair.privateKey,\n publicJwk: await exportJWK(keyPair.publicKey),\n },\n options,\n );\n }\n\n async issue(\n input: ExecutionAuthorityIssueInput,\n ): Promise<IssuedExecutionAuthority> {\n const authority = ExecutionAuthorityIssueInputSchema.parse(input);\n if (authority.mcp && !this.#config.mcp) {\n throw new Error(\n 'Execution authority cannot issue an MCP capability without MCP deployment configuration.',\n );\n }\n\n const issuedAt = toEpochSeconds(this.#now());\n const executionExpiresAt = issuedAt + this.#config.executionTtlSeconds;\n const executionAssertion = await this.#signExecutionAssertion(\n authority,\n issuedAt,\n executionExpiresAt,\n );\n\n const mcp = authority.mcp && this.#config.mcp\n ? await this.#issueMcpCapability(\n { ...authority, mcp: authority.mcp },\n issuedAt,\n )\n : undefined;\n\n return new ProtectedIssuedExecutionAuthority(\n executionAssertion,\n mcp?.assertion,\n freezeIssuedMetadata({\n scope: {\n adopterId: this.#config.adopterId,\n ...authority.scope,\n },\n runtimeSessionId: authority.runtimeSessionId,\n invocationId: authority.invocationId,\n workflow: authority.workflow,\n issuedAt: toIsoTimestamp(issuedAt),\n executionExpiresAt: toIsoTimestamp(executionExpiresAt),\n ...(mcp ? { mcp: mcp.metadata } : {}),\n }),\n );\n }\n\n publicJwks(): JSONWebKeySet {\n return { keys: [{ ...this.#publicJwk }] };\n }\n\n #signExecutionAssertion(\n input: z.infer<typeof ExecutionAuthorityIssueInputSchema>,\n issuedAt: number,\n expiresAt: number,\n ): Promise<string> {\n return new SignJWT({\n contractVersion: EXECUTION_CONTRACT_VERSION,\n adopterId: this.#config.adopterId,\n tenantId: input.scope.tenantId,\n productSessionId: input.scope.productSessionId,\n runtimeSessionId: input.runtimeSessionId,\n workflow: input.workflow,\n })\n .setProtectedHeader({\n alg: SIGNING_ALGORITHM,\n kid: this.#config.keyId,\n typ: EXECUTION_ASSERTION_TYPE,\n })\n .setIssuer(this.#config.issuer)\n .setAudience(this.#config.executionAudience)\n .setSubject(input.scope.subjectId)\n .setJti(input.invocationId)\n .setIssuedAt(issuedAt)\n .setExpirationTime(expiresAt)\n .sign(this.#privateKey);\n }\n\n async #issueMcpCapability(\n input: z.infer<typeof ExecutionAuthorityIssueInputSchema> & {\n mcp: { allowedTools: string[] };\n },\n issuedAt: number,\n ): Promise<{\n assertion: string;\n metadata: NonNullable<IssuedExecutionAuthorityMetadata['mcp']>;\n }> {\n const mcpConfig = this.#config.mcp!;\n const capabilityId = OpaqueIdSchema.parse(this.#createCapabilityId());\n if (capabilityId === input.invocationId) {\n throw new Error(\n 'MCP capability identity must be distinct from the invocation identity.',\n );\n }\n const expiresAt = issuedAt + mcpConfig.ttlSeconds;\n const assertion = await new SignJWT({\n contractVersion: EXECUTION_CONTRACT_VERSION,\n adopterId: this.#config.adopterId,\n tenantId: input.scope.tenantId,\n productSessionId: input.scope.productSessionId,\n runtimeSessionId: input.runtimeSessionId,\n invocationId: input.invocationId,\n workflow: input.workflow,\n serverId: mcpConfig.serverId,\n allowedTools: [...input.mcp.allowedTools],\n })\n .setProtectedHeader({\n alg: SIGNING_ALGORITHM,\n kid: this.#config.keyId,\n typ: MCP_CAPABILITY_TYPE,\n })\n .setIssuer(this.#config.issuer)\n .setAudience(mcpConfig.audience)\n .setSubject(input.scope.subjectId)\n .setJti(capabilityId)\n .setIssuedAt(issuedAt)\n .setExpirationTime(expiresAt)\n .sign(this.#privateKey);\n\n return {\n assertion,\n metadata: {\n capabilityId,\n serverId: mcpConfig.serverId,\n allowedTools: Object.freeze([...input.mcp.allowedTools]),\n expiresAt: toIsoTimestamp(expiresAt),\n },\n };\n }\n}\n\nclass ProtectedIssuedExecutionAuthority implements IssuedExecutionAuthority {\n readonly metadata: IssuedExecutionAuthorityMetadata;\n readonly #executionAssertion: string;\n readonly #mcpCapability: string | undefined;\n\n constructor(\n executionAssertion: string,\n mcpCapability: string | undefined,\n metadata: IssuedExecutionAuthorityMetadata,\n ) {\n this.#executionAssertion = executionAssertion;\n this.#mcpCapability = mcpCapability;\n this.metadata = metadata;\n }\n\n executionAssertion(): string {\n return this.#executionAssertion;\n }\n\n mcpCapability(): string | undefined {\n return this.#mcpCapability;\n }\n\n toJSON(): IssuedExecutionAuthorityMetadata {\n return this.metadata;\n }\n}\n\nfunction projectPublicJwk(jwk: JWK, keyId: string): Readonly<JWK> {\n const parsed = PublicP256JwkSchema.parse(jwk);\n return Object.freeze({\n kty: parsed.kty,\n crv: parsed.crv,\n x: parsed.x,\n y: parsed.y,\n alg: SIGNING_ALGORITHM,\n kid: keyId,\n use: 'sig',\n });\n}\n\nfunction assertPrivateSigningKey(key: CryptoKey): void {\n const algorithm = key.algorithm as { name: string; namedCurve?: string };\n const accepted = key.type === 'private'\n && algorithm.name === 'ECDSA'\n && algorithm.namedCurve === 'P-256'\n && key.usages.includes('sign');\n if (!accepted) {\n throw new Error(\n 'Execution authority requires an ES256 private signing key.',\n );\n }\n}\n\nfunction assertPublicVerificationKey(key: CryptoKey): void {\n const algorithm = key.algorithm as { name: string; namedCurve?: string };\n const accepted = key.type === 'public'\n && algorithm.name === 'ECDSA'\n && algorithm.namedCurve === 'P-256'\n && key.usages.includes('verify');\n if (!accepted) {\n throw new Error(\n 'Execution authority requires an ES256 public verification key.',\n );\n }\n}\n\nasync function assertMatchingKeyPair(\n keyPair: ExecutionAuthorityKeyPair,\n): Promise<void> {\n try {\n const probe = await new CompactSign(\n new TextEncoder().encode('heddle-adopter-execution-authority-key-pair'),\n )\n .setProtectedHeader({ alg: SIGNING_ALGORITHM })\n .sign(keyPair.privateKey);\n await compactVerify(probe, keyPair.publicKey, {\n algorithms: [SIGNING_ALGORITHM],\n });\n } catch {\n throw new Error('Execution authority signing keys do not match.');\n }\n}\n\nfunction toEpochSeconds(value: Date): number {\n const seconds = Math.floor(value.getTime() / 1_000);\n if (!Number.isSafeInteger(seconds) || seconds < 0) {\n throw new Error('Execution authority could not resolve a valid issue time.');\n }\n return seconds;\n}\n\nfunction toIsoTimestamp(epochSeconds: number): string {\n return new Date(epochSeconds * 1_000).toISOString();\n}\n\nfunction deepFreezeConfig(\n config: z.infer<typeof ExecutionAuthorityConfigSchema>,\n): z.infer<typeof ExecutionAuthorityConfigSchema> {\n const mcp = config.mcp ? Object.freeze({ ...config.mcp }) : undefined;\n return Object.freeze({ ...config, ...(mcp ? { mcp } : {}) });\n}\n\nfunction freezeIssuedMetadata(\n metadata: IssuedExecutionAuthorityMetadata,\n): IssuedExecutionAuthorityMetadata {\n const scope: ExecutionScope = Object.freeze({ ...metadata.scope });\n const mcp = metadata.mcp\n ? Object.freeze({\n ...metadata.mcp,\n allowedTools: Object.freeze([...metadata.mcp.allowedTools]),\n })\n : undefined;\n return Object.freeze({ ...metadata, scope, ...(mcp ? { mcp } : {}) });\n}\n"]}
@@ -48,8 +48,10 @@ export interface IssuedExecutionAuthority {
48
48
  mcpCapability(): string | undefined;
49
49
  toJSON(): IssuedExecutionAuthorityMetadata;
50
50
  }
51
- export interface ExecutionAuthority {
51
+ export interface ExecutionAuthorityIssuer {
52
52
  issue(input: ExecutionAuthorityIssueInput): Promise<IssuedExecutionAuthority>;
53
+ }
54
+ export interface ExecutionAuthority extends ExecutionAuthorityIssuer {
53
55
  publicJwks(): JSONWebKeySet;
54
56
  }
55
57
  export type ExecutionAuthorityKeyPair = {
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/authority/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AACrD,OAAO,KAAK,EACV,cAAc,EACd,uBAAuB,EACxB,MAAM,uBAAuB,CAAC;AAE/B,MAAM,MAAM,2BAA2B,GAAG;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,mBAAmB,EAAE,MAAM,CAAC;IAC5B,GAAG,CAAC,EAAE,2BAA2B,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,KAAK,EAAE,IAAI,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;IACzC,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,uBAAuB,CAAC;IAClC,GAAG,CAAC,EAAE;QACJ,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;KACjC,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IACxC,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,gCAAgC,GAAG;IAC7C,KAAK,EAAE,cAAc,CAAC;IACtB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAA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M,yBAAyB,GAAG;IACtC,UAAU,EAAE,SAAS,CAAC;IACtB,SAAS,EAAE,SAAS,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;IACjB,kBAAkB,CAAC,EAAE,MAAM,MAAM,CAAC;CACnC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/authority/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { CryptoKey, JSONWebKeySet } from 'jose';\nimport type {\n ExecutionScope,\n HostedExecutionWorkflow,\n} from '../contracts/index.js';\n\nexport type ExecutionAuthorityMcpConfig = {\n audience: string;\n serverId: string;\n ttlSeconds: number;\n};\n\nexport type ExecutionAuthorityConfig = {\n issuer: string;\n adopterId: string;\n executionAudience: string;\n keyId: string;\n executionTtlSeconds: number;\n mcp?: ExecutionAuthorityMcpConfig;\n};\n\nexport type ExecutionAuthorityIssueInput = {\n scope: Omit<ExecutionScope, 'adopterId'>;\n runtimeSessionId: string;\n invocationId: string;\n workflow: HostedExecutionWorkflow;\n mcp?: {\n allowedTools: readonly string[];\n };\n};\n\nexport type IssuedMcpCapabilityMetadata = {\n capabilityId: string;\n serverId: string;\n allowedTools: readonly string[];\n expiresAt: string;\n};\n\nexport type IssuedExecutionAuthorityMetadata = {\n scope: ExecutionScope;\n runtimeSessionId: string;\n invocationId: string;\n workflow: HostedExecutionWorkflow;\n issuedAt: string;\n executionExpiresAt: string;\n mcp?: IssuedMcpCapabilityMetadata;\n};\n\n/**\n * Short-lived credentials are available only through explicit accessors.\n * JSON serialization contains credential-free metadata. Identifiers can still\n * be product data and remain subject to the adopter's logging policy.\n */\nexport interface IssuedExecutionAuthority {\n readonly metadata: IssuedExecutionAuthorityMetadata;\n executionAssertion(): string;\n mcpCapability(): string | undefined;\n toJSON(): IssuedExecutionAuthorityMetadata;\n}\n\nexport interface ExecutionAuthority {\n issue(input: ExecutionAuthorityIssueInput): Promise<IssuedExecutionAuthority>;\n publicJwks(): JSONWebKeySet;\n}\n\nexport type ExecutionAuthorityKeyPair = {\n privateKey: CryptoKey;\n publicKey: CryptoKey;\n};\n\nexport type JoseExecutionAuthorityOptions = {\n now?: () => Date;\n createCapabilityId?: () => string;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/authority/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { CryptoKey, JSONWebKeySet } from 'jose';\nimport type {\n ExecutionScope,\n HostedExecutionWorkflow,\n} from '../contracts/index.js';\n\nexport type ExecutionAuthorityMcpConfig = {\n audience: string;\n serverId: string;\n ttlSeconds: number;\n};\n\nexport type ExecutionAuthorityConfig = {\n issuer: string;\n adopterId: string;\n executionAudience: string;\n keyId: string;\n executionTtlSeconds: number;\n mcp?: ExecutionAuthorityMcpConfig;\n};\n\nexport type ExecutionAuthorityIssueInput = {\n scope: Omit<ExecutionScope, 'adopterId'>;\n runtimeSessionId: string;\n invocationId: string;\n workflow: HostedExecutionWorkflow;\n mcp?: {\n allowedTools: readonly string[];\n };\n};\n\nexport type IssuedMcpCapabilityMetadata = {\n capabilityId: string;\n serverId: string;\n allowedTools: readonly string[];\n expiresAt: string;\n};\n\nexport type IssuedExecutionAuthorityMetadata = {\n scope: ExecutionScope;\n runtimeSessionId: string;\n invocationId: string;\n workflow: HostedExecutionWorkflow;\n issuedAt: string;\n executionExpiresAt: string;\n mcp?: IssuedMcpCapabilityMetadata;\n};\n\n/**\n * Short-lived credentials are available only through explicit accessors.\n * JSON serialization contains credential-free metadata. Identifiers can still\n * be product data and remain subject to the adopter's logging policy.\n */\nexport interface IssuedExecutionAuthority {\n readonly metadata: IssuedExecutionAuthorityMetadata;\n executionAssertion(): string;\n mcpCapability(): string | undefined;\n toJSON(): IssuedExecutionAuthorityMetadata;\n}\n\nexport interface ExecutionAuthorityIssuer {\n issue(input: ExecutionAuthorityIssueInput): Promise<IssuedExecutionAuthority>;\n}\n\nexport interface ExecutionAuthority extends ExecutionAuthorityIssuer {\n publicJwks(): JSONWebKeySet;\n}\n\nexport type ExecutionAuthorityKeyPair = {\n privateKey: CryptoKey;\n publicKey: CryptoKey;\n};\n\nexport type JoseExecutionAuthorityOptions = {\n now?: () => Date;\n createCapabilityId?: () => string;\n};\n"]}
@@ -1,6 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  export declare const EXECUTION_CONTRACT_VERSION: 1;
3
3
  export declare const CONVERSATION_TURN_WORKFLOW: "conversation-turn";
4
+ export declare const HEARTBEAT_TASK_WORKFLOW: "heartbeat-task";
4
5
  export declare const EXECUTION_ASSERTION_TYPE: "heddle-execution+jwt";
5
6
  export declare const MCP_CAPABILITY_TYPE: "heddle-mcp-capability+jwt";
6
7
  export declare const AGENTCORE_RUNTIME_SESSION_HEADER: "x-amzn-bedrock-agentcore-runtime-session-id";
@@ -29,6 +30,49 @@ export declare const ExecutionHostConversationTurnRequestSchema: z.ZodObject<{
29
30
  prompt: z.ZodString;
30
31
  deadlineAt: z.ZodOptional<z.ZodISODateTime>;
31
32
  }, z.core.$strict>;
33
+ export declare const HeartbeatRunContextSchema: z.ZodObject<{
34
+ currentDateTime: z.ZodISODateTime;
35
+ intervalMs: z.ZodNumber;
36
+ continuationMode: z.ZodOptional<z.ZodEnum<{
37
+ operator: "operator";
38
+ agent: "agent";
39
+ }>>;
40
+ nextRunAt: z.ZodOptional<z.ZodISODateTime>;
41
+ previousRunAt: z.ZodOptional<z.ZodISODateTime>;
42
+ previousRunId: z.ZodOptional<z.ZodString>;
43
+ }, z.core.$strict>;
44
+ export declare const ExecutionHostHeartbeatTaskRequestSchema: z.ZodObject<{
45
+ schemaVersion: z.ZodLiteral<1>;
46
+ kind: z.ZodLiteral<"heartbeat-task">;
47
+ invocationId: z.ZodString;
48
+ taskId: z.ZodString;
49
+ task: z.ZodString;
50
+ checkpoint: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodJSONSchema>>;
51
+ runContext: z.ZodObject<{
52
+ currentDateTime: z.ZodISODateTime;
53
+ intervalMs: z.ZodNumber;
54
+ continuationMode: z.ZodOptional<z.ZodEnum<{
55
+ operator: "operator";
56
+ agent: "agent";
57
+ }>>;
58
+ nextRunAt: z.ZodOptional<z.ZodISODateTime>;
59
+ previousRunAt: z.ZodOptional<z.ZodISODateTime>;
60
+ previousRunId: z.ZodOptional<z.ZodString>;
61
+ }, z.core.$strict>;
62
+ model: z.ZodOptional<z.ZodString>;
63
+ reasoningEffort: z.ZodOptional<z.ZodEnum<{
64
+ none: "none";
65
+ low: "low";
66
+ medium: "medium";
67
+ high: "high";
68
+ ultrahigh: "ultrahigh";
69
+ max: "max";
70
+ }>>;
71
+ maxSteps: z.ZodOptional<z.ZodNumber>;
72
+ searchIgnoreDirs: z.ZodOptional<z.ZodArray<z.ZodString>>;
73
+ systemContext: z.ZodOptional<z.ZodString>;
74
+ deadlineAt: z.ZodOptional<z.ZodISODateTime>;
75
+ }, z.core.$strict>;
32
76
  export declare const RuntimePublicResultSchema: z.ZodObject<{
33
77
  outcome: z.ZodEnum<{
34
78
  error: "error";
@@ -117,6 +161,53 @@ export declare const ExecutionHostStreamEventSchema: z.ZodDiscriminatedUnion<[z.
117
161
  message: z.ZodString;
118
162
  }, z.core.$strict>;
119
163
  }, z.core.$strict>], "kind">;
164
+ export declare const ExecutionHostHeartbeatStreamEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
165
+ schemaVersion: z.ZodLiteral<1>;
166
+ invocationId: z.ZodString;
167
+ runId: z.ZodString;
168
+ timestamp: z.ZodISODateTime;
169
+ sequence: z.ZodLiteral<0>;
170
+ kind: z.ZodLiteral<"accepted">;
171
+ }, z.core.$strict>, z.ZodObject<{
172
+ schemaVersion: z.ZodLiteral<1>;
173
+ invocationId: z.ZodString;
174
+ runId: z.ZodString;
175
+ sequence: z.ZodNumber;
176
+ timestamp: z.ZodISODateTime;
177
+ kind: z.ZodLiteral<"activity">;
178
+ activity: z.ZodJSONSchema;
179
+ }, z.core.$strict>, z.ZodObject<{
180
+ schemaVersion: z.ZodLiteral<1>;
181
+ invocationId: z.ZodString;
182
+ runId: z.ZodString;
183
+ sequence: z.ZodNumber;
184
+ timestamp: z.ZodISODateTime;
185
+ kind: z.ZodLiteral<"result">;
186
+ result: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
187
+ }, z.core.$strict>, z.ZodObject<{
188
+ schemaVersion: z.ZodLiteral<1>;
189
+ invocationId: z.ZodString;
190
+ runId: z.ZodString;
191
+ sequence: z.ZodNumber;
192
+ timestamp: z.ZodISODateTime;
193
+ kind: z.ZodLiteral<"cancelled">;
194
+ reason: z.ZodString;
195
+ }, z.core.$strict>, z.ZodObject<{
196
+ schemaVersion: z.ZodLiteral<1>;
197
+ invocationId: z.ZodString;
198
+ runId: z.ZodString;
199
+ sequence: z.ZodNumber;
200
+ timestamp: z.ZodISODateTime;
201
+ kind: z.ZodLiteral<"error">;
202
+ error: z.ZodObject<{
203
+ code: z.ZodString;
204
+ message: z.ZodString;
205
+ }, z.core.$strict>;
206
+ }, z.core.$strict>], "kind">;
207
+ export declare const HostedExecutionWorkflowSchema: z.ZodEnum<{
208
+ "conversation-turn": "conversation-turn";
209
+ "heartbeat-task": "heartbeat-task";
210
+ }>;
120
211
  export declare const ExecutionAssertionClaimsSchema: z.ZodObject<{
121
212
  iss: z.ZodURL;
122
213
  aud: z.ZodString;
@@ -125,7 +216,10 @@ export declare const ExecutionAssertionClaimsSchema: z.ZodObject<{
125
216
  tenantId: z.ZodString;
126
217
  productSessionId: z.ZodString;
127
218
  runtimeSessionId: z.ZodString;
128
- workflow: z.ZodLiteral<"conversation-turn">;
219
+ workflow: z.ZodEnum<{
220
+ "conversation-turn": "conversation-turn";
221
+ "heartbeat-task": "heartbeat-task";
222
+ }>;
129
223
  sub: z.ZodString;
130
224
  jti: z.ZodString;
131
225
  iat: z.ZodNumber;
@@ -140,7 +234,10 @@ export declare const McpCapabilityClaimsSchema: z.ZodObject<{
140
234
  productSessionId: z.ZodString;
141
235
  runtimeSessionId: z.ZodString;
142
236
  invocationId: z.ZodString;
143
- workflow: z.ZodLiteral<"conversation-turn">;
237
+ workflow: z.ZodEnum<{
238
+ "conversation-turn": "conversation-turn";
239
+ "heartbeat-task": "heartbeat-task";
240
+ }>;
144
241
  serverId: z.ZodString;
145
242
  allowedTools: z.ZodArray<z.ZodString>;
146
243
  sub: z.ZodString;
@@ -150,14 +247,20 @@ export declare const McpCapabilityClaimsSchema: z.ZodObject<{
150
247
  }, z.core.$loose>;
151
248
  export type ExecutionScope = z.infer<typeof ExecutionScopeSchema>;
152
249
  export type ExecutionHostConversationTurnRequest = z.infer<typeof ExecutionHostConversationTurnRequestSchema>;
250
+ export type ExecutionHostHeartbeatTaskRequest = z.infer<typeof ExecutionHostHeartbeatTaskRequestSchema>;
153
251
  export type RuntimePublicResult = z.infer<typeof RuntimePublicResultSchema>;
154
252
  export type ExecutionHostStreamEvent = z.infer<typeof ExecutionHostStreamEventSchema>;
155
253
  export type ExecutionHostTerminalEvent = Extract<ExecutionHostStreamEvent, {
156
254
  kind: 'result' | 'cancelled' | 'error';
157
255
  }>;
256
+ export type ExecutionHostHeartbeatStreamEvent = z.infer<typeof ExecutionHostHeartbeatStreamEventSchema>;
257
+ export type ExecutionHostHeartbeatTerminalEvent = Extract<ExecutionHostHeartbeatStreamEvent, {
258
+ kind: 'result' | 'cancelled' | 'error';
259
+ }>;
158
260
  export type ExecutionAssertionClaims = z.infer<typeof ExecutionAssertionClaimsSchema>;
159
261
  export type McpCapabilityClaims = z.infer<typeof McpCapabilityClaimsSchema>;
160
- export type HostedExecutionWorkflow = typeof CONVERSATION_TURN_WORKFLOW;
262
+ export type HostedExecutionWorkflow = z.infer<typeof HostedExecutionWorkflowSchema>;
161
263
  export declare function isExecutionHostTerminalEvent(event: ExecutionHostStreamEvent): event is ExecutionHostTerminalEvent;
264
+ export declare function isExecutionHostHeartbeatTerminalEvent(event: ExecutionHostHeartbeatStreamEvent): event is ExecutionHostHeartbeatTerminalEvent;
162
265
  export declare function isSafeWebUrl(url: URL): boolean;
163
266
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,0BAA0B,EAAG,CAAU,CAAC;AACrD,eAAO,MAAM,0BAA0B,EAAG,mBAA4B,CAAC;AACvE,eAAO,MAAM,wBAAwB,EAAG,sBAA+B,CAAC;AACxE,eAAO,MAAM,mBAAmB,EAAG,2BAAoC,CAAC;AAExE,eAAO,MAAM,gCAAgC,EAC3C,6CAAsD,CAAC;AACzD,eAAO,MAAM,iCAAiC,EAC5C,qCAA8C,CAAC;AACjD,eAAO,MAAM,0BAA0B,EACrC,mCAA4C,CAAC;AAC/C,eAAO,MAAM,qBAAqB,EAChC,wCAAiD,CAAC;AACpD,eAAO,MAAM,oBAAoB,EAC/B,uCAAgD,CAAC;AAEnD,eAAO,MAAM,cAAc,aAOxB,CAAC;AAEJ,eAAO,MAAM,eAAe,UAG3B,CAAC;AAEF,eAAO,MAAM,iBAAiB,aAA6B,CAAC;AAE5D,eAAO,MAAM,sBAAsB,aAI8C,CAAC;AAElF,eAAO,MAAM,eAAe,kBAAmC,CAAC;AAEhE,eAAO,MAAM,iBAAiB,aAO3B,CAAC;AAEJ,eAAO,MAAM,iBAAiB,aAO3B,CAAC;AAEJ,eAAO,MAAM,qBAAqB,yBAa/B,CAAC;AAEJ,eAAO,MAAM,oBAAoB;;;;;kBAKtB,CAAC;AAEZ,eAAO,MAAM,0CAA0C;;;;;;kBAM5C,CAAC;AAEZ,eAAO,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;kBAiB3B,CAAC;AAUZ,eAAO,MAAM,8BAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAwBzC,CAAC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