@heddleagent/execution-host-client 6.6.1 → 6.7.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.
package/README.md CHANGED
@@ -5,8 +5,8 @@ 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:** `6.6.1` is the current package version as of
9
- > 2026-08-26. The former
8
+ > **Current availability:** `6.7.0` is the current package version as of
9
+ > 2026-08-27. The former
10
10
  > `@roackb2/heddle-adopter@5.13.0` coordinate is deprecated and remains
11
11
  > installable only for existing consumers. The compatible Execution Host source
12
12
  > is maintained in this private-first repository; Heddle does not yet offer a
@@ -283,6 +283,12 @@ This surface owns credential verification and exact scope binding. It does not
283
283
  own HTTP ingress, Runtime-session isolation, model credentials, streaming,
284
284
  provider bootstrap, or deployment.
285
285
 
286
+ After verification, `RuntimeSessionService` forwards that same canonical
287
+ `ExecutionScope` to the selected host executor. A compatible host can therefore
288
+ derive host-owned scoped resources such as memory without reparsing claims or
289
+ inventing a second identity vocabulary. The executor must not accept an
290
+ independently supplied scope.
291
+
286
292
  ## Invoke an Execution Host
287
293
 
288
294
  Use the official AgentCore client for a Runtime deployed in the adopter's AWS
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/host/runtime-session/service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kCAAkC,EAClC,yBAAyB,EAC1B,MAAM,aAAa,CAAC;AAMrB,OAAO,EACL,0BAA0B,EAC1B,KAAK,iBAAiB,EACvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,2BAA2B,EAC3B,KAAK,4BAA4B,EAClC,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAGV,uBAAuB,EACvB,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,YAAY,CAAC;AAiB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,iBAAiB,GAAG,SAAS;IAI3C,OAAO,CAAC,eAAe;IAgBvB,OAAO,CAAC,MAAM;IAWd,OAAO,CAAC,2BAA2B;IAYnC,OAAO,CAAC,cAAc;CAcvB"}
@@ -49,6 +49,7 @@ export class RuntimeSessionService {
49
49
  deadlineTimer.unref();
50
50
  this.status.markExecuting();
51
51
  const executionInput = {
52
+ scope: input.identity.scope,
52
53
  scopeKey: binding.scopeKey,
53
54
  executionSessionId: binding.executionSessionId,
54
55
  request: input.invocation,
@@ -1 +1 @@
1
- {"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/host/runtime-session/service.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,+BAA+B,GAChC,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,0BAA0B,GAE3B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,2BAA2B,GAE5B,MAAM,aAAa,CAAC;AAUrB,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAepC,iFAAiF;AACjF,MAAM,OAAO,qBAAqB;IACxB,MAAM,CAAoB;IAC1B,QAAQ,CAAsB;IACrB,4BAA4B,GAAG,IAAI,GAAG,EAAU,CAAC;IACjD,8BAA8B,GAAa,EAAE,CAAC;IAC9C,MAAM,CAAuB;IAC7B,SAAS,CAA2B;IACpC,OAAO,CAA6B;IACpC,MAAM,CAA8B;IACpC,GAAG,CAAa;IAEjC,YAAY,OAMX;QACC,IACE,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC;eAClD,OAAO,CAAC,MAAM,CAAC,eAAe,IAAI,CAAC,EACtC,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACtE,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;QACnC,IAAI,CAAC,OAAO,GAA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EAAE,KAAK,CAAC,OAAO;aACvB,CAAC,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC;YACxC,GAAG,KAAK;YACR,OAAO,EAAE,KAAK,CAAC,OAAO;SACvB,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type {\n VerifiedExecutionHostMcpCapability,\n VerifiedExecutionIdentity,\n} from '../types.js';\nimport {\n RuntimeBusyError,\n RuntimeDeadlineError,\n RuntimeDuplicateInvocationError,\n} from './errors.js';\nimport {\n RuntimeScopeBindingService,\n type BoundRuntimeScope,\n} from './scope-binding.js';\nimport {\n RuntimeSessionStatusService,\n type RuntimeSessionStatusSnapshot,\n} from './status.js';\nimport type {\n RuntimeExecutionHandle,\n RuntimeExecutionInput,\n RuntimeInvocationHandle,\n RuntimeInvocationRequest,\n RuntimeSessionConfig,\n RuntimeWorkflowExecutors,\n} from './types.js';\n\nconst RECENT_INVOCATION_LIMIT = 128;\n\ntype ActiveInvocation = {\n invocationId: string;\n run: RuntimeExecutionHandle;\n controller: AbortController;\n deadlineTimer: ReturnType<typeof setTimeout>;\n removeCallerAbortListener: () => void;\n};\n\ntype StartingInvocation = {\n controller: AbortController;\n promise: Promise<RuntimeExecutionHandle>;\n};\n\n/** Coordinates one process-bound Runtime session without owning product data. */\nexport class RuntimeSessionService {\n private active?: ActiveInvocation;\n private starting?: StartingInvocation;\n private readonly recentCompletedInvocationIds = new Set<string>();\n private readonly recentCompletedInvocationOrder: string[] = [];\n private readonly config: RuntimeSessionConfig;\n private readonly executors: RuntimeWorkflowExecutors;\n private readonly binding: RuntimeScopeBindingService;\n private readonly status: RuntimeSessionStatusService;\n private readonly now: () => Date;\n\n constructor(options: {\n config: RuntimeSessionConfig;\n executors: RuntimeWorkflowExecutors;\n binding?: RuntimeScopeBindingService;\n status?: RuntimeSessionStatusService;\n now?: () => Date;\n }) {\n if (\n !Number.isSafeInteger(options.config.maxInvocationMs)\n || options.config.maxInvocationMs <= 0\n ) {\n throw new Error('maxInvocationMs must be a positive safe integer.');\n }\n this.config = options.config;\n this.executors = options.executors;\n this.binding = options.binding ?? new RuntimeScopeBindingService();\n this.now = options.now ?? (() => new Date());\n this.status = options.status ?? new RuntimeSessionStatusService(this.now);\n }\n\n readStatus(): RuntimeSessionStatusSnapshot {\n return this.status.read();\n }\n\n async start(input: {\n identity: VerifiedExecutionIdentity;\n invocation: RuntimeInvocationRequest;\n modelApiKey: string;\n mcpCapability?: VerifiedExecutionHostMcpCapability;\n callerSignal: AbortSignal;\n }): Promise<RuntimeInvocationHandle> {\n const deadline = this.resolveDeadline(input.invocation.deadlineAt);\n const binding = this.binding.bind({\n runtimeSessionId: input.identity.runtimeSessionId,\n ...input.identity.scope,\n });\n\n if (this.active || this.starting) {\n throw new RuntimeBusyError(\n 'This runtime session already has an active invocation.',\n );\n }\n if (this.recentCompletedInvocationIds.has(input.identity.invocationId)) {\n throw new RuntimeDuplicateInvocationError(\n 'This recent invocation identifier already completed in the current runtime process.',\n );\n }\n\n const controller = new AbortController();\n const abortFromCaller = () => controller.abort(input.callerSignal.reason);\n input.callerSignal.addEventListener('abort', abortFromCaller, { once: true });\n if (input.callerSignal.aborted) {\n abortFromCaller();\n }\n\n const deadlineTimer = setTimeout(\n () => controller.abort(\n new RuntimeDeadlineError('The runtime invocation deadline elapsed.'),\n ),\n deadline.getTime() - this.now().getTime(),\n );\n deadlineTimer.unref();\n\n this.status.markExecuting();\n const executionInput = {\n scopeKey: binding.scopeKey,\n executionSessionId: binding.executionSessionId,\n request: input.invocation,\n modelApiKey: input.modelApiKey,\n mcpCapability: input.mcpCapability,\n abortSignal: controller.signal,\n } satisfies RuntimeExecutionInput;\n const startPromise = Promise.resolve().then(\n () => this.startExecution(executionInput),\n );\n const starting: StartingInvocation = {\n controller,\n promise: startPromise,\n };\n this.starting = starting;\n\n let run: RuntimeExecutionHandle;\n try {\n run = await startPromise;\n } catch (error) {\n clearTimeout(deadlineTimer);\n input.callerSignal.removeEventListener('abort', abortFromCaller);\n this.status.markIdle();\n throw error;\n } finally {\n if (this.starting === starting) {\n this.starting = undefined;\n }\n }\n\n const active: ActiveInvocation = {\n invocationId: input.identity.invocationId,\n run,\n controller,\n deadlineTimer,\n removeCallerAbortListener: () =>\n input.callerSignal.removeEventListener('abort', abortFromCaller),\n };\n this.active = active;\n controller.signal.addEventListener('abort', () => run.cancel(), {\n once: true,\n });\n if (controller.signal.aborted) {\n run.cancel();\n }\n\n const result = run.result.finally(() => this.settle(active));\n result.catch(() => undefined);\n\n return {\n runId: run.runId,\n acceptedAt: this.now().toISOString(),\n // The execution signal cancels the agent, but the event subscription\n // remains open for the executor's truthful cancelled terminal.\n events: () => run.events(),\n cancel: () => {\n const wasActive = !controller.signal.aborted;\n controller.abort();\n return wasActive;\n },\n result,\n };\n }\n\n async shutdown(): Promise<void> {\n const starting = this.starting;\n if (starting) {\n starting.controller.abort(new Error('Runtime is shutting down.'));\n const run = await starting.promise.catch(() => undefined);\n if (run) {\n run.cancel();\n await run.result.catch(() => undefined);\n }\n }\n\n const active = this.active;\n if (!active) {\n return;\n }\n active.controller.abort(new Error('Runtime is shutting down.'));\n active.run.cancel();\n await active.run.result.catch(() => undefined);\n }\n\n boundScope(): BoundRuntimeScope | undefined {\n return this.binding.current();\n }\n\n private resolveDeadline(deadlineAt?: string): Date {\n const now = this.now();\n const maximum = new Date(now.getTime() + this.config.maxInvocationMs);\n if (!deadlineAt) {\n return maximum;\n }\n\n const requested = new Date(deadlineAt);\n if (requested.getTime() <= now.getTime()) {\n throw new RuntimeDeadlineError(\n 'The runtime invocation deadline has already elapsed.',\n );\n }\n return requested.getTime() < maximum.getTime() ? requested : maximum;\n }\n\n private settle(active: ActiveInvocation): void {\n if (this.active !== active) {\n return;\n }\n clearTimeout(active.deadlineTimer);\n active.removeCallerAbortListener();\n this.active = undefined;\n this.rememberCompletedInvocation(active.invocationId);\n this.status.markIdle();\n }\n\n private rememberCompletedInvocation(invocationId: string): void {\n this.recentCompletedInvocationIds.add(invocationId);\n this.recentCompletedInvocationOrder.push(invocationId);\n if (this.recentCompletedInvocationOrder.length <= RECENT_INVOCATION_LIMIT) {\n return;\n }\n const oldest = this.recentCompletedInvocationOrder.shift();\n if (oldest) {\n this.recentCompletedInvocationIds.delete(oldest);\n }\n }\n\n private startExecution(\n input: RuntimeExecutionInput,\n ): Promise<RuntimeExecutionHandle> {\n if (input.request.kind === 'conversation-turn') {\n return this.executors.conversationTurn.start({\n ...input,\n request: input.request,\n });\n }\n return this.executors.heartbeatTask.start({\n ...input,\n request: input.request,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/host/runtime-session/service.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,+BAA+B,GAChC,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,0BAA0B,GAE3B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,2BAA2B,GAE5B,MAAM,aAAa,CAAC;AAUrB,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAepC,iFAAiF;AACjF,MAAM,OAAO,qBAAqB;IACxB,MAAM,CAAoB;IAC1B,QAAQ,CAAsB;IACrB,4BAA4B,GAAG,IAAI,GAAG,EAAU,CAAC;IACjD,8BAA8B,GAAa,EAAE,CAAC;IAC9C,MAAM,CAAuB;IAC7B,SAAS,CAA2B;IACpC,OAAO,CAA6B;IACpC,MAAM,CAA8B;IACpC,GAAG,CAAa;IAEjC,YAAY,OAMX;QACC,IACE,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC;eAClD,OAAO,CAAC,MAAM,CAAC,eAAe,IAAI,CAAC,EACtC,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACtE,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,OA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AC;YAC/C,OAAO,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,KAAK,CAAC;gBAC3C,GAAG,KAAK;gBACR,OAAO,EAAE,KAAK,CAAC,OAAO;aACvB,CAAC,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,CAAC;YACxC,GAAG,KAAK;YACR,OAAO,EAAE,KAAK,CAAC,OAAO;SACvB,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type {\n VerifiedExecutionHostMcpCapability,\n VerifiedExecutionIdentity,\n} from '../types.js';\nimport {\n RuntimeBusyError,\n RuntimeDeadlineError,\n RuntimeDuplicateInvocationError,\n} from './errors.js';\nimport {\n RuntimeScopeBindingService,\n type BoundRuntimeScope,\n} from './scope-binding.js';\nimport {\n RuntimeSessionStatusService,\n type RuntimeSessionStatusSnapshot,\n} from './status.js';\nimport type {\n RuntimeExecutionHandle,\n RuntimeExecutionInput,\n RuntimeInvocationHandle,\n RuntimeInvocationRequest,\n RuntimeSessionConfig,\n RuntimeWorkflowExecutors,\n} from './types.js';\n\nconst RECENT_INVOCATION_LIMIT = 128;\n\ntype ActiveInvocation = {\n invocationId: string;\n run: RuntimeExecutionHandle;\n controller: AbortController;\n deadlineTimer: ReturnType<typeof setTimeout>;\n removeCallerAbortListener: () => void;\n};\n\ntype StartingInvocation = {\n controller: AbortController;\n promise: Promise<RuntimeExecutionHandle>;\n};\n\n/** Coordinates one process-bound Runtime session without owning product data. */\nexport class RuntimeSessionService {\n private active?: ActiveInvocation;\n private starting?: StartingInvocation;\n private readonly recentCompletedInvocationIds = new Set<string>();\n private readonly recentCompletedInvocationOrder: string[] = [];\n private readonly config: RuntimeSessionConfig;\n private readonly executors: RuntimeWorkflowExecutors;\n private readonly binding: RuntimeScopeBindingService;\n private readonly status: RuntimeSessionStatusService;\n private readonly now: () => Date;\n\n constructor(options: {\n config: RuntimeSessionConfig;\n executors: RuntimeWorkflowExecutors;\n binding?: RuntimeScopeBindingService;\n status?: RuntimeSessionStatusService;\n now?: () => Date;\n }) {\n if (\n !Number.isSafeInteger(options.config.maxInvocationMs)\n || options.config.maxInvocationMs <= 0\n ) {\n throw new Error('maxInvocationMs must be a positive safe integer.');\n }\n this.config = options.config;\n this.executors = options.executors;\n this.binding = options.binding ?? new RuntimeScopeBindingService();\n this.now = options.now ?? (() => new Date());\n this.status = options.status ?? new RuntimeSessionStatusService(this.now);\n }\n\n readStatus(): RuntimeSessionStatusSnapshot {\n return this.status.read();\n }\n\n async start(input: {\n identity: VerifiedExecutionIdentity;\n invocation: RuntimeInvocationRequest;\n modelApiKey: string;\n mcpCapability?: VerifiedExecutionHostMcpCapability;\n callerSignal: AbortSignal;\n }): Promise<RuntimeInvocationHandle> {\n const deadline = this.resolveDeadline(input.invocation.deadlineAt);\n const binding = this.binding.bind({\n runtimeSessionId: input.identity.runtimeSessionId,\n ...input.identity.scope,\n });\n\n if (this.active || this.starting) {\n throw new RuntimeBusyError(\n 'This runtime session already has an active invocation.',\n );\n }\n if (this.recentCompletedInvocationIds.has(input.identity.invocationId)) {\n throw new RuntimeDuplicateInvocationError(\n 'This recent invocation identifier already completed in the current runtime process.',\n );\n }\n\n const controller = new AbortController();\n const abortFromCaller = () => controller.abort(input.callerSignal.reason);\n input.callerSignal.addEventListener('abort', abortFromCaller, { once: true });\n if (input.callerSignal.aborted) {\n abortFromCaller();\n }\n\n const deadlineTimer = setTimeout(\n () => controller.abort(\n new RuntimeDeadlineError('The runtime invocation deadline elapsed.'),\n ),\n deadline.getTime() - this.now().getTime(),\n );\n deadlineTimer.unref();\n\n this.status.markExecuting();\n const executionInput = {\n scope: input.identity.scope,\n scopeKey: binding.scopeKey,\n executionSessionId: binding.executionSessionId,\n request: input.invocation,\n modelApiKey: input.modelApiKey,\n mcpCapability: input.mcpCapability,\n abortSignal: controller.signal,\n } satisfies RuntimeExecutionInput;\n const startPromise = Promise.resolve().then(\n () => this.startExecution(executionInput),\n );\n const starting: StartingInvocation = {\n controller,\n promise: startPromise,\n };\n this.starting = starting;\n\n let run: RuntimeExecutionHandle;\n try {\n run = await startPromise;\n } catch (error) {\n clearTimeout(deadlineTimer);\n input.callerSignal.removeEventListener('abort', abortFromCaller);\n this.status.markIdle();\n throw error;\n } finally {\n if (this.starting === starting) {\n this.starting = undefined;\n }\n }\n\n const active: ActiveInvocation = {\n invocationId: input.identity.invocationId,\n run,\n controller,\n deadlineTimer,\n removeCallerAbortListener: () =>\n input.callerSignal.removeEventListener('abort', abortFromCaller),\n };\n this.active = active;\n controller.signal.addEventListener('abort', () => run.cancel(), {\n once: true,\n });\n if (controller.signal.aborted) {\n run.cancel();\n }\n\n const result = run.result.finally(() => this.settle(active));\n result.catch(() => undefined);\n\n return {\n runId: run.runId,\n acceptedAt: this.now().toISOString(),\n // The execution signal cancels the agent, but the event subscription\n // remains open for the executor's truthful cancelled terminal.\n events: () => run.events(),\n cancel: () => {\n const wasActive = !controller.signal.aborted;\n controller.abort();\n return wasActive;\n },\n result,\n };\n }\n\n async shutdown(): Promise<void> {\n const starting = this.starting;\n if (starting) {\n starting.controller.abort(new Error('Runtime is shutting down.'));\n const run = await starting.promise.catch(() => undefined);\n if (run) {\n run.cancel();\n await run.result.catch(() => undefined);\n }\n }\n\n const active = this.active;\n if (!active) {\n return;\n }\n active.controller.abort(new Error('Runtime is shutting down.'));\n active.run.cancel();\n await active.run.result.catch(() => undefined);\n }\n\n boundScope(): BoundRuntimeScope | undefined {\n return this.binding.current();\n }\n\n private resolveDeadline(deadlineAt?: string): Date {\n const now = this.now();\n const maximum = new Date(now.getTime() + this.config.maxInvocationMs);\n if (!deadlineAt) {\n return maximum;\n }\n\n const requested = new Date(deadlineAt);\n if (requested.getTime() <= now.getTime()) {\n throw new RuntimeDeadlineError(\n 'The runtime invocation deadline has already elapsed.',\n );\n }\n return requested.getTime() < maximum.getTime() ? requested : maximum;\n }\n\n private settle(active: ActiveInvocation): void {\n if (this.active !== active) {\n return;\n }\n clearTimeout(active.deadlineTimer);\n active.removeCallerAbortListener();\n this.active = undefined;\n this.rememberCompletedInvocation(active.invocationId);\n this.status.markIdle();\n }\n\n private rememberCompletedInvocation(invocationId: string): void {\n this.recentCompletedInvocationIds.add(invocationId);\n this.recentCompletedInvocationOrder.push(invocationId);\n if (this.recentCompletedInvocationOrder.length <= RECENT_INVOCATION_LIMIT) {\n return;\n }\n const oldest = this.recentCompletedInvocationOrder.shift();\n if (oldest) {\n this.recentCompletedInvocationIds.delete(oldest);\n }\n }\n\n private startExecution(\n input: RuntimeExecutionInput,\n ): Promise<RuntimeExecutionHandle> {\n if (input.request.kind === 'conversation-turn') {\n return this.executors.conversationTurn.start({\n ...input,\n request: input.request,\n });\n }\n return this.executors.heartbeatTask.start({\n ...input,\n request: input.request,\n });\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { ExecutionHostConversationTurnRequest, ExecutionHostHeartbeatTaskRequest, RuntimePublicResult } from '../../contracts/index.js';
1
+ import type { ExecutionHostConversationTurnRequest, ExecutionHostHeartbeatTaskRequest, ExecutionScope, RuntimePublicResult } from '../../contracts/index.js';
2
2
  import type { VerifiedExecutionHostMcpCapability } from '../types.js';
3
3
  type RuntimeExecutionStreamEnvelope = {
4
4
  runId: string;
@@ -24,6 +24,8 @@ export type RuntimeExecutionStreamItem<Result = unknown> = (RuntimeExecutionStre
24
24
  });
25
25
  export type RuntimeInvocationRequest = ExecutionHostConversationTurnRequest | ExecutionHostHeartbeatTaskRequest;
26
26
  export type RuntimeExecutionInput<Request extends RuntimeInvocationRequest = RuntimeInvocationRequest> = {
27
+ /** Verified product identity forwarded unchanged from host admission. */
28
+ scope: Readonly<ExecutionScope>;
27
29
  scopeKey: string;
28
30
  executionSessionId: string;
29
31
  request: Request;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/host/runtime-session/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oCAAoC,EACpC,iCAAiC,EACjC,mBAAmB,EAC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AAC,CAAC;IACtD,MAAM,IAAI,OAAO,CAAC;CACnB,CAAC;AAEF,iEAAiE;AACjE,MAAM,MAAM,uBAAuB,CACjC,OAAO,SAAS,wBAAwB,EACxC,MAAM,IACJ;IACF,KAAK,CACH,KAAK,EAAE,qBAAqB,CAAC,OAAO,CAAC,GACpC,OAAO,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,wBAAwB,CAAC,eAAe,GAAG,OAAO,IAAI;IAChE,gBAAgB,EAAE,uBAAuB,CACvC,oCAAoC,EACpC,mBAAmB,CACpB,CAAC;IACF,aAAa,EAAE,uBAAuB,CACpC,iCAAiC,EACjC,eAAe,CAChB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,uBAAuB,CAAC,MAAM,GAAG,OAAO,IAAI;IACtD,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,IAAI,aAAa,CAAC,0BAA0B,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5D,MAAM,IAAI,OAAO,CAAC;IAClB,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/host/runtime-session/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n ExecutionHostConversationTurnRequest,\n ExecutionHostHeartbeatTaskRequest,\n RuntimePublicResult,\n} from '../../contracts/index.js';\nimport type { VerifiedExecutionHostMcpCapability } from '../types.js';\n\ntype RuntimeExecutionStreamEnvelope = {\n runId: string;\n sequence: number;\n timestamp: string;\n};\n\n/** Ordered execution events exposed by any workflow executor. */\nexport type RuntimeExecutionStreamItem<Result = unknown> =\n | (RuntimeExecutionStreamEnvelope & {\n kind: 'activity';\n activity: unknown;\n })\n | (RuntimeExecutionStreamEnvelope & {\n kind: 'result';\n result: Result;\n })\n | (RuntimeExecutionStreamEnvelope & {\n kind: 'cancelled';\n reason: string;\n })\n | (RuntimeExecutionStreamEnvelope & {\n kind: 'error';\n error: { code: string; message: string };\n });\n\nexport type RuntimeInvocationRequest =\n | ExecutionHostConversationTurnRequest\n | ExecutionHostHeartbeatTaskRequest;\n\nexport type RuntimeExecutionInput<\n Request extends RuntimeInvocationRequest = RuntimeInvocationRequest,\n> = {\n scopeKey: string;\n executionSessionId: string;\n request: Request;\n modelApiKey: string;\n mcpCapability?: VerifiedExecutionHostMcpCapability;\n abortSignal: AbortSignal;\n};\n\nexport type RuntimeExecutionHandle<Result = unknown> = {\n runId: string;\n result: Promise<Result>;\n events(options?: {\n signal?: AbortSignal;\n }): AsyncIterable<RuntimeExecutionStreamItem<Result>>;\n cancel(): boolean;\n};\n\n/** Outbound execution port for one provider-neutral workflow. */\nexport type RuntimeWorkflowExecutor<\n Request extends RuntimeInvocationRequest,\n Result,\n> = {\n start(\n input: RuntimeExecutionInput<Request>,\n ): Promise<RuntimeExecutionHandle<Result>>;\n};\n\nexport type RuntimeWorkflowExecutors<HeartbeatResult = unknown> = {\n conversationTurn: RuntimeWorkflowExecutor<\n ExecutionHostConversationTurnRequest,\n RuntimePublicResult\n >;\n heartbeatTask: RuntimeWorkflowExecutor<\n ExecutionHostHeartbeatTaskRequest,\n HeartbeatResult\n >;\n};\n\nexport type RuntimeInvocationHandle<Result = unknown> = {\n runId: string;\n acceptedAt: string;\n events(): AsyncIterable<RuntimeExecutionStreamItem<Result>>;\n cancel(): boolean;\n result: Promise<Result>;\n};\n\nexport type RuntimeSessionConfig = {\n maxInvocationMs: number;\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/host/runtime-session/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n ExecutionHostConversationTurnRequest,\n ExecutionHostHeartbeatTaskRequest,\n ExecutionScope,\n RuntimePublicResult,\n} from '../../contracts/index.js';\nimport type { VerifiedExecutionHostMcpCapability } from '../types.js';\n\ntype RuntimeExecutionStreamEnvelope = {\n runId: string;\n sequence: number;\n timestamp: string;\n};\n\n/** Ordered execution events exposed by any workflow executor. */\nexport type RuntimeExecutionStreamItem<Result = unknown> =\n | (RuntimeExecutionStreamEnvelope & {\n kind: 'activity';\n activity: unknown;\n })\n | (RuntimeExecutionStreamEnvelope & {\n kind: 'result';\n result: Result;\n })\n | (RuntimeExecutionStreamEnvelope & {\n kind: 'cancelled';\n reason: string;\n })\n | (RuntimeExecutionStreamEnvelope & {\n kind: 'error';\n error: { code: string; message: string };\n });\n\nexport type RuntimeInvocationRequest =\n | ExecutionHostConversationTurnRequest\n | ExecutionHostHeartbeatTaskRequest;\n\nexport type RuntimeExecutionInput<\n Request extends RuntimeInvocationRequest = RuntimeInvocationRequest,\n> = {\n /** Verified product identity forwarded unchanged from host admission. */\n scope: Readonly<ExecutionScope>;\n scopeKey: string;\n executionSessionId: string;\n request: Request;\n modelApiKey: string;\n mcpCapability?: VerifiedExecutionHostMcpCapability;\n abortSignal: AbortSignal;\n};\n\nexport type RuntimeExecutionHandle<Result = unknown> = {\n runId: string;\n result: Promise<Result>;\n events(options?: {\n signal?: AbortSignal;\n }): AsyncIterable<RuntimeExecutionStreamItem<Result>>;\n cancel(): boolean;\n};\n\n/** Outbound execution port for one provider-neutral workflow. */\nexport type RuntimeWorkflowExecutor<\n Request extends RuntimeInvocationRequest,\n Result,\n> = {\n start(\n input: RuntimeExecutionInput<Request>,\n ): Promise<RuntimeExecutionHandle<Result>>;\n};\n\nexport type RuntimeWorkflowExecutors<HeartbeatResult = unknown> = {\n conversationTurn: RuntimeWorkflowExecutor<\n ExecutionHostConversationTurnRequest,\n RuntimePublicResult\n >;\n heartbeatTask: RuntimeWorkflowExecutor<\n ExecutionHostHeartbeatTaskRequest,\n HeartbeatResult\n >;\n};\n\nexport type RuntimeInvocationHandle<Result = unknown> = {\n runId: string;\n acceptedAt: string;\n events(): AsyncIterable<RuntimeExecutionStreamItem<Result>>;\n cancel(): boolean;\n result: Promise<Result>;\n};\n\nexport type RuntimeSessionConfig = {\n maxInvocationMs: number;\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heddleagent/execution-host-client",
3
- "version": "6.6.1",
3
+ "version": "6.7.0",
4
4
  "description": "Contracts, execution authority, lifecycle services, and adopter clients for compatible Heddle Execution Hosts",
5
5
  "author": "Jay / Fienna Liang <roackb2@gmail.com>",
6
6
  "license": "MIT",