@heddleagent/execution-host-client 6.0.0-next.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/LICENSE +21 -0
- package/README.md +305 -0
- package/dist/authority/index.d.ts +3 -0
- package/dist/authority/index.d.ts.map +1 -0
- package/dist/authority/index.js +2 -0
- package/dist/authority/index.js.map +1 -0
- package/dist/authority/jose-execution-authority.d.ts +14 -0
- package/dist/authority/jose-execution-authority.d.ts.map +1 -0
- package/dist/authority/jose-execution-authority.js +266 -0
- package/dist/authority/jose-execution-authority.js.map +1 -0
- package/dist/authority/types.d.ts +63 -0
- package/dist/authority/types.d.ts.map +1 -0
- package/dist/authority/types.js +2 -0
- package/dist/authority/types.js.map +1 -0
- package/dist/contracts/index.d.ts +163 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +149 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/conversation/durable-hosted-conversation-turn-service.d.ts +23 -0
- package/dist/conversation/durable-hosted-conversation-turn-service.d.ts.map +1 -0
- package/dist/conversation/durable-hosted-conversation-turn-service.js +273 -0
- package/dist/conversation/durable-hosted-conversation-turn-service.js.map +1 -0
- package/dist/conversation/hosted-conversation-turn-service.d.ts +17 -0
- package/dist/conversation/hosted-conversation-turn-service.d.ts.map +1 -0
- package/dist/conversation/hosted-conversation-turn-service.js +60 -0
- package/dist/conversation/hosted-conversation-turn-service.js.map +1 -0
- package/dist/conversation/index.d.ts +7 -0
- package/dist/conversation/index.d.ts.map +1 -0
- package/dist/conversation/index.js +5 -0
- package/dist/conversation/index.js.map +1 -0
- package/dist/conversation/lifecycle-types.d.ts +208 -0
- package/dist/conversation/lifecycle-types.d.ts.map +1 -0
- package/dist/conversation/lifecycle-types.js +92 -0
- package/dist/conversation/lifecycle-types.js.map +1 -0
- package/dist/conversation/types.d.ts +35 -0
- package/dist/conversation/types.d.ts.map +1 -0
- package/dist/conversation/types.js +11 -0
- package/dist/conversation/types.js.map +1 -0
- package/dist/http-sse/direct-http-execution-host.d.ts +12 -0
- package/dist/http-sse/direct-http-execution-host.d.ts.map +1 -0
- package/dist/http-sse/direct-http-execution-host.js +279 -0
- package/dist/http-sse/direct-http-execution-host.js.map +1 -0
- package/dist/http-sse/errors.d.ts +19 -0
- package/dist/http-sse/errors.d.ts.map +1 -0
- package/dist/http-sse/errors.js +29 -0
- package/dist/http-sse/errors.js.map +1 -0
- package/dist/http-sse/index.d.ts +4 -0
- package/dist/http-sse/index.d.ts.map +1 -0
- package/dist/http-sse/index.js +3 -0
- package/dist/http-sse/index.js.map +1 -0
- package/dist/http-sse/types.d.ts +20 -0
- package/dist/http-sse/types.d.ts.map +1 -0
- package/dist/http-sse/types.js +2 -0
- package/dist/http-sse/types.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/errors.d.ts +11 -0
- package/dist/mcp/errors.d.ts.map +1 -0
- package/dist/mcp/errors.js +15 -0
- package/dist/mcp/errors.js.map +1 -0
- package/dist/mcp/index.d.ts +5 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/jwt-capability-verifier.d.ts +12 -0
- package/dist/mcp/jwt-capability-verifier.d.ts.map +1 -0
- package/dist/mcp/jwt-capability-verifier.js +136 -0
- package/dist/mcp/jwt-capability-verifier.js.map +1 -0
- package/dist/mcp/node/index.d.ts +4 -0
- package/dist/mcp/node/index.d.ts.map +1 -0
- package/dist/mcp/node/index.js +3 -0
- package/dist/mcp/node/index.js.map +1 -0
- package/dist/mcp/node/json-toolset.d.ts +23 -0
- package/dist/mcp/node/json-toolset.d.ts.map +1 -0
- package/dist/mcp/node/json-toolset.js +94 -0
- package/dist/mcp/node/json-toolset.js.map +1 -0
- package/dist/mcp/node/streamable-http-mcp-service.d.ts +18 -0
- package/dist/mcp/node/streamable-http-mcp-service.d.ts.map +1 -0
- package/dist/mcp/node/streamable-http-mcp-service.js +229 -0
- package/dist/mcp/node/streamable-http-mcp-service.js.map +1 -0
- package/dist/mcp/node/types.d.ts +53 -0
- package/dist/mcp/node/types.d.ts.map +1 -0
- package/dist/mcp/node/types.js +2 -0
- package/dist/mcp/node/types.js.map +1 -0
- package/dist/mcp/types.d.ts +37 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +2 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/node/authority-key.d.ts +14 -0
- package/dist/node/authority-key.d.ts.map +1 -0
- package/dist/node/authority-key.js +89 -0
- package/dist/node/authority-key.js.map +1 -0
- package/dist/node/direct-credentials.d.ts +21 -0
- package/dist/node/direct-credentials.d.ts.map +1 -0
- package/dist/node/direct-credentials.js +47 -0
- package/dist/node/direct-credentials.js.map +1 -0
- package/dist/node/http-service.d.ts +21 -0
- package/dist/node/http-service.d.ts.map +1 -0
- package/dist/node/http-service.js +389 -0
- package/dist/node/http-service.js.map +1 -0
- package/dist/node/index.d.ts +6 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +4 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/types.d.ts +52 -0
- package/dist/node/types.d.ts.map +1 -0
- package/dist/node/types.js +2 -0
- package/dist/node/types.js.map +1 -0
- package/dist/testing/event-stream.d.ts +17 -0
- package/dist/testing/event-stream.d.ts.map +1 -0
- package/dist/testing/event-stream.js +83 -0
- package/dist/testing/event-stream.js.map +1 -0
- package/dist/testing/hosted-conversation-turn-store-conformance.d.ts +17 -0
- package/dist/testing/hosted-conversation-turn-store-conformance.d.ts.map +1 -0
- package/dist/testing/hosted-conversation-turn-store-conformance.js +137 -0
- package/dist/testing/hosted-conversation-turn-store-conformance.js.map +1 -0
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +3 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/invocation.d.ts +20 -0
- package/dist/testing/invocation.d.ts.map +1 -0
- package/dist/testing/invocation.js +39 -0
- package/dist/testing/invocation.js.map +1 -0
- package/dist/testing/local-execution-host-contract-fixture.d.ts +21 -0
- package/dist/testing/local-execution-host-contract-fixture.d.ts.map +1 -0
- package/dist/testing/local-execution-host-contract-fixture.js +197 -0
- package/dist/testing/local-execution-host-contract-fixture.js.map +1 -0
- package/dist/testing/request.d.ts +10 -0
- package/dist/testing/request.d.ts.map +1 -0
- package/dist/testing/request.js +140 -0
- package/dist/testing/request.js.map +1 -0
- package/dist/testing/types.d.ts +42 -0
- package/dist/testing/types.d.ts.map +1 -0
- package/dist/testing/types.js +2 -0
- package/dist/testing/types.js.map +1 -0
- package/package.json +92 -0
- package/spec/v1/README.md +101 -0
- package/spec/v1/durable-hosted-conversation-lifecycle.md +139 -0
- package/spec/v1/fixtures/ambiguous-eof.sse +9 -0
- package/spec/v1/fixtures/authority.json +70 -0
- package/spec/v1/fixtures/cancelled.sse +9 -0
- package/spec/v1/fixtures/durable-conversation-lifecycle.json +890 -0
- package/spec/v1/fixtures/invalid-request-extra-field.json +8 -0
- package/spec/v1/fixtures/invalid-sequence-gap.sse +9 -0
- package/spec/v1/fixtures/manifest.json +53 -0
- package/spec/v1/fixtures/valid-request.json +7 -0
- package/spec/v1/fixtures/valid-result.sse +13 -0
- package/spec/v1/openapi.json +896 -0
- package/spec/v1/schema-bundle.json +1286 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle-types.d.ts","sourceRoot":"","sources":["../../src/conversation/lifecycle-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAKL,KAAK,0BAA0B,EAChC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EACV,4BAA4B,EAC7B,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,iCAAiC,mGAQpC,CAAC;AAEX,eAAO,MAAM,g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S,gCAAgC,GACpE,IAAI,CAAC,CAAC,EAAE,MAAM,8BAA8B,GAAG,WAAW,CAAC,GAC3D,KAAK,CAAC;AAEV,MAAM,MAAM,oCAAoC,GAAG;IACjD,KAAK,EAAE,0BAA0B,CAAC;IAClC,UAAU,EAAE,mBAAmB,CAAC,gCAAgC,CAAC,CAAC;CACnE,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ExecutionHostConversationTurnRequestSchema, ExecutionScopeSchema, OpaqueIdSchema, TimestampSchema, } from '../contracts/index.js';
|
|
3
|
+
export const HOSTED_CONVERSATION_TURN_STATUSES = [
|
|
4
|
+
'requested',
|
|
5
|
+
'running',
|
|
6
|
+
'completed',
|
|
7
|
+
'max_steps',
|
|
8
|
+
'failed',
|
|
9
|
+
'cancelled',
|
|
10
|
+
'interrupted',
|
|
11
|
+
];
|
|
12
|
+
export const HOSTED_CONVERSATION_FAILED_CODES = [
|
|
13
|
+
'execution_error',
|
|
14
|
+
'execution_failed',
|
|
15
|
+
'execution_result_error',
|
|
16
|
+
'host_protocol_error',
|
|
17
|
+
'host_rejected',
|
|
18
|
+
'model_authentication',
|
|
19
|
+
'model_context_window',
|
|
20
|
+
'model_empty_response',
|
|
21
|
+
'model_permission',
|
|
22
|
+
'model_quota',
|
|
23
|
+
'model_rate_limit',
|
|
24
|
+
'model_request',
|
|
25
|
+
'model_transport',
|
|
26
|
+
'model_unknown',
|
|
27
|
+
];
|
|
28
|
+
export const HOSTED_CONVERSATION_INTERRUPTED_CODES = [
|
|
29
|
+
'deadline_elapsed',
|
|
30
|
+
'execution_interrupted',
|
|
31
|
+
'invocation_aborted',
|
|
32
|
+
'stream_ended_without_terminal',
|
|
33
|
+
'stream_interrupted',
|
|
34
|
+
];
|
|
35
|
+
export const HOSTED_CONVERSATION_CANCELLED_CODES = [
|
|
36
|
+
'invocation_cancelled',
|
|
37
|
+
];
|
|
38
|
+
export const HOSTED_CONVERSATION_FAILURE_CODES = [
|
|
39
|
+
...HOSTED_CONVERSATION_FAILED_CODES,
|
|
40
|
+
...HOSTED_CONVERSATION_INTERRUPTED_CODES,
|
|
41
|
+
...HOSTED_CONVERSATION_CANCELLED_CODES,
|
|
42
|
+
];
|
|
43
|
+
export const HostedConversationTurnStatusSchema = z.enum(HOSTED_CONVERSATION_TURN_STATUSES);
|
|
44
|
+
export const HostedConversationFailureCodeSchema = z.enum(HOSTED_CONVERSATION_FAILURE_CODES);
|
|
45
|
+
export const HostedConversationPersistenceScopeSchema = ExecutionScopeSchema.omit({ adopterId: true });
|
|
46
|
+
export const HostedConversationTurnIdentitySchema = z.object({
|
|
47
|
+
invocationId: OpaqueIdSchema,
|
|
48
|
+
scope: HostedConversationPersistenceScopeSchema,
|
|
49
|
+
}).strict();
|
|
50
|
+
export const HostedConversationRequestedTurnSchema = HostedConversationTurnIdentitySchema.extend({
|
|
51
|
+
prompt: ExecutionHostConversationTurnRequestSchema.shape.prompt,
|
|
52
|
+
deadlineAt: ExecutionHostConversationTurnRequestSchema.shape.deadlineAt,
|
|
53
|
+
requestedAt: TimestampSchema,
|
|
54
|
+
}).strict();
|
|
55
|
+
export const HostedConversationAcceptedTurnSchema = HostedConversationTurnIdentitySchema.extend({
|
|
56
|
+
runId: OpaqueIdSchema,
|
|
57
|
+
acceptedAt: TimestampSchema,
|
|
58
|
+
}).strict();
|
|
59
|
+
const SummarySchema = z.string().max(1_000_000);
|
|
60
|
+
const SettlementBaseSchema = HostedConversationTurnIdentitySchema.extend({
|
|
61
|
+
settledAt: TimestampSchema,
|
|
62
|
+
});
|
|
63
|
+
export const HostedConversationTurnSettlementSchema = z.discriminatedUnion('status', [
|
|
64
|
+
SettlementBaseSchema.extend({
|
|
65
|
+
status: z.literal('completed'),
|
|
66
|
+
summary: SummarySchema.optional(),
|
|
67
|
+
}).strict(),
|
|
68
|
+
SettlementBaseSchema.extend({
|
|
69
|
+
status: z.literal('max_steps'),
|
|
70
|
+
summary: SummarySchema.optional(),
|
|
71
|
+
}).strict(),
|
|
72
|
+
SettlementBaseSchema.extend({
|
|
73
|
+
status: z.literal('failed'),
|
|
74
|
+
summary: SummarySchema.optional(),
|
|
75
|
+
failureCode: z.enum(HOSTED_CONVERSATION_FAILED_CODES),
|
|
76
|
+
}).strict(),
|
|
77
|
+
SettlementBaseSchema.extend({
|
|
78
|
+
status: z.literal('cancelled'),
|
|
79
|
+
failureCode: z.literal(HOSTED_CONVERSATION_CANCELLED_CODES[0]),
|
|
80
|
+
}).strict(),
|
|
81
|
+
SettlementBaseSchema.extend({
|
|
82
|
+
status: z.literal('interrupted'),
|
|
83
|
+
summary: SummarySchema.optional(),
|
|
84
|
+
failureCode: z.enum(HOSTED_CONVERSATION_INTERRUPTED_CODES),
|
|
85
|
+
}).strict(),
|
|
86
|
+
]);
|
|
87
|
+
export const HostedConversationExpiredTurnReconciliationSchema = z.object({
|
|
88
|
+
scope: HostedConversationPersistenceScopeSchema,
|
|
89
|
+
expiredBefore: TimestampSchema,
|
|
90
|
+
settledAt: TimestampSchema,
|
|
91
|
+
}).strict();
|
|
92
|
+
//# sourceMappingURL=lifecycle-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle-types.js","sourceRoot":"","sources":["../../src/conversation/lifecycle-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,0CAA0C,EAC1C,oBAAoB,EACpB,cAAc,EACd,eAAe,GAEhB,MAAM,uBAAuB,CAAC;AAK/B,MAAM,CAAC,MAAM,iCAAiC,GAAG;IAC/C,WAAW;IACX,SAAS;IACT,WAAW;IACX,WAAW;IACX,QAAQ;IACR,WAAW;IACX,aAAa;CACL,CAAC;AAEX,MAAM,CAAC,MAAM,gCAAgC,GAAG;IAC9C,iBAAiB;IACjB,kBAAkB;IAClB,wBAAwB;IACxB,qBAAqB;IACrB,eAAe;IACf,sBAAsB;IACtB,sBAAsB;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iD,GAAG,CAAC,CAAC,MAAM,CAAC;IACxE,KAAK,EAAE,wCAAwC;IAC/C,aAAa,EAAE,eAAe;IAC9B,SAAS,EAAE,eAAe;CAC3B,CAAC,CAAC,MAAM,EAAE,CAAC","sourcesContent":["import { z } from 'zod';\nimport {\n ExecutionHostConversationTurnRequestSchema,\n ExecutionScopeSchema,\n OpaqueIdSchema,\n TimestampSchema,\n type ExecutionHostTerminalEvent,\n} from '../contracts/index.js';\nimport type {\n HostedConversationTurnRunner,\n} from './types.js';\n\nexport const HOSTED_CONVERSATION_TURN_STATUSES = [\n 'requested',\n 'running',\n 'completed',\n 'max_steps',\n 'failed',\n 'cancelled',\n 'interrupted',\n] as const;\n\nexport const HOSTED_CONVERSATION_FAILED_CODES = [\n 'execution_error',\n 'execution_failed',\n 'execution_result_error',\n 'host_protocol_error',\n 'host_rejected',\n 'model_authentication',\n 'model_context_window',\n 'model_empty_response',\n 'model_permission',\n 'model_quota',\n 'model_rate_limit',\n 'model_request',\n 'model_transport',\n 'model_unknown',\n] as const;\n\nexport const HOSTED_CONVERSATION_INTERRUPTED_CODES = [\n 'deadline_elapsed',\n 'execution_interrupted',\n 'invocation_aborted',\n 'stream_ended_without_terminal',\n 'stream_interrupted',\n] as const;\n\nexport const HOSTED_CONVERSATION_CANCELLED_CODES = [\n 'invocation_cancelled',\n] as const;\n\nexport const HOSTED_CONVERSATION_FAILURE_CODES = [\n ...HOSTED_CONVERSATION_FAILED_CODES,\n ...HOSTED_CONVERSATION_INTERRUPTED_CODES,\n ...HOSTED_CONVERSATION_CANCELLED_CODES,\n] as const;\n\nexport const HostedConversationTurnStatusSchema = z.enum(\n HOSTED_CONVERSATION_TURN_STATUSES,\n);\nexport const HostedConversationFailureCodeSchema = z.enum(\n HOSTED_CONVERSATION_FAILURE_CODES,\n);\nexport const HostedConversationPersistenceScopeSchema =\n ExecutionScopeSchema.omit({ adopterId: true });\nexport const HostedConversationTurnIdentitySchema = z.object({\n invocationId: OpaqueIdSchema,\n scope: HostedConversationPersistenceScopeSchema,\n}).strict();\nexport const HostedConversationRequestedTurnSchema =\n HostedConversationTurnIdentitySchema.extend({\n prompt: ExecutionHostConversationTurnRequestSchema.shape.prompt,\n deadlineAt:\n ExecutionHostConversationTurnRequestSchema.shape.deadlineAt,\n requestedAt: TimestampSchema,\n }).strict();\nexport const HostedConversationAcceptedTurnSchema =\n HostedConversationTurnIdentitySchema.extend({\n runId: OpaqueIdSchema,\n acceptedAt: TimestampSchema,\n }).strict();\n\nconst SummarySchema = z.string().max(1_000_000);\nconst SettlementBaseSchema = HostedConversationTurnIdentitySchema.extend({\n settledAt: TimestampSchema,\n});\n\nexport const HostedConversationTurnSettlementSchema = z.discriminatedUnion(\n 'status',\n [\n SettlementBaseSchema.extend({\n status: z.literal('completed'),\n summary: SummarySchema.optional(),\n }).strict(),\n SettlementBaseSchema.extend({\n status: z.literal('max_steps'),\n summary: SummarySchema.optional(),\n }).strict(),\n SettlementBaseSchema.extend({\n status: z.literal('failed'),\n summary: SummarySchema.optional(),\n failureCode: z.enum(HOSTED_CONVERSATION_FAILED_CODES),\n }).strict(),\n SettlementBaseSchema.extend({\n status: z.literal('cancelled'),\n failureCode: z.literal(HOSTED_CONVERSATION_CANCELLED_CODES[0]),\n }).strict(),\n SettlementBaseSchema.extend({\n status: z.literal('interrupted'),\n summary: SummarySchema.optional(),\n failureCode: z.enum(HOSTED_CONVERSATION_INTERRUPTED_CODES),\n }).strict(),\n ],\n);\n\nexport const HostedConversationExpiredTurnReconciliationSchema = z.object({\n scope: HostedConversationPersistenceScopeSchema,\n expiredBefore: TimestampSchema,\n settledAt: TimestampSchema,\n}).strict();\n\nexport type HostedConversationTurnStatus = z.infer<\n typeof HostedConversationTurnStatusSchema\n>;\n\nexport type HostedConversationTerminalStatus = Exclude<\n HostedConversationTurnStatus,\n 'requested' | 'running'\n>;\n\nexport type HostedConversationFailureCode = z.infer<\n typeof HostedConversationFailureCodeSchema\n>;\n\nexport type HostedConversationPersistenceScope = z.infer<\n typeof HostedConversationPersistenceScopeSchema\n>;\n\nexport type HostedConversationTurnIdentity = z.infer<\n typeof HostedConversationTurnIdentitySchema\n>;\n\nexport type HostedConversationRequestedTurn = z.infer<\n typeof HostedConversationRequestedTurnSchema\n>;\n\nexport type HostedConversationAcceptedTurn = z.infer<\n typeof HostedConversationAcceptedTurnSchema\n>;\n\nexport type HostedConversationTurnSettlement = z.infer<\n typeof HostedConversationTurnSettlementSchema\n>;\n\nexport type HostedConversationTurnLifecycleRecord =\n HostedConversationRequestedTurn & {\n status: HostedConversationTurnStatus;\n runId?: string;\n summary?: string;\n failureCode?: HostedConversationFailureCode;\n acceptedAt?: string;\n settledAt?: string;\n };\n\nexport type HostedConversationExpiredTurnReconciliation = z.infer<\n typeof HostedConversationExpiredTurnReconciliationSchema\n>;\n\n/**\n * Durable write port for the generic hosted-turn lifecycle.\n *\n * Implementations must fence every mutation by invocation and full scope.\n * Creation rejects every duplicate invocation so a repeated request cannot\n * start execution twice. Accepted and terminal writes allow only an exact\n * repeat; conflicting or late transitions must fail atomically. The port\n * deliberately cannot carry activity, raw errors, credentials, or tool data.\n */\nexport interface HostedConversationTurnLifecycleStore {\n createTurn(input: HostedConversationRequestedTurn): Promise<void>;\n recordAccepted(input: HostedConversationAcceptedTurn): Promise<void>;\n settleTurn(input: HostedConversationTurnSettlement): Promise<void>;\n interruptExpiredTurns(\n input: HostedConversationExpiredTurnReconciliation,\n ): Promise<void>;\n}\n\nexport type DurableHostedConversationTurnServiceConfig = {\n turns: HostedConversationTurnRunner;\n store: HostedConversationTurnLifecycleStore;\n maxSummaryCharacters?: number;\n expiredTurnGraceMs?: number;\n};\n\nexport type DurableHostedConversationTurnServiceOptions = {\n now?: () => Date;\n};\n\nexport type HostedConversationTurnReconciliationOptions = {\n expiredTurnGraceMs?: number;\n now?: () => Date;\n};\n\ntype ProjectedSettlement<T> = T extends HostedConversationTurnSettlement\n ? Omit<T, keyof HostedConversationTurnIdentity | 'settledAt'>\n : never;\n\nexport type HostedConversationTerminalProjection = {\n event: ExecutionHostTerminalEvent;\n settlement: ProjectedSettlement<HostedConversationTurnSettlement>;\n};\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type ExecutionHostStreamEvent } from '../contracts/index.js';
|
|
3
|
+
import type { ExecutionAuthority } from '../authority/index.js';
|
|
4
|
+
import type { ExecutionHost } from '../http-sse/index.js';
|
|
5
|
+
export declare const HostedConversationTurnInputSchema: z.ZodObject<{
|
|
6
|
+
scope: z.ZodObject<{
|
|
7
|
+
tenantId: z.ZodString;
|
|
8
|
+
subjectId: z.ZodString;
|
|
9
|
+
productSessionId: z.ZodString;
|
|
10
|
+
}, z.core.$strict>;
|
|
11
|
+
runtimeSessionId: z.ZodString;
|
|
12
|
+
invocationId: z.ZodString;
|
|
13
|
+
prompt: z.ZodString;
|
|
14
|
+
deadlineAt: z.ZodOptional<z.ZodISODateTime>;
|
|
15
|
+
signal: z.ZodOptional<z.ZodCustom<AbortSignal, AbortSignal>>;
|
|
16
|
+
}, z.core.$strict>;
|
|
17
|
+
export type HostedConversationTurnInput = z.infer<typeof HostedConversationTurnInputSchema>;
|
|
18
|
+
export type HostedConversationCredentialContext = Pick<HostedConversationTurnInput, 'scope' | 'invocationId' | 'signal'>;
|
|
19
|
+
/** Resolves model authority without exposing it to HTTP or product data. */
|
|
20
|
+
export interface HostedConversationModelCredentialProvider {
|
|
21
|
+
resolveModelApiKey(context: HostedConversationCredentialContext): Promise<string>;
|
|
22
|
+
}
|
|
23
|
+
export interface HostedConversationTurnRunner {
|
|
24
|
+
streamTurn(input: HostedConversationTurnInput): AsyncIterable<ExecutionHostStreamEvent>;
|
|
25
|
+
}
|
|
26
|
+
export type HostedConversationTurnServiceConfig = {
|
|
27
|
+
authority: ExecutionAuthority;
|
|
28
|
+
executionHost: ExecutionHost;
|
|
29
|
+
modelCredentials: HostedConversationModelCredentialProvider;
|
|
30
|
+
/** Omit this policy when the hosted workflow needs no product MCP tools. */
|
|
31
|
+
mcp?: {
|
|
32
|
+
allowedTools: readonly string[];
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/conversation/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAIL,KAAK,wBAAwB,EAC9B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,eAAO,MAAM,iCAAiC;;;;;;;;;;;kBAUnC,CAAC;AAEZ,MAAM,MAAM,2BAA2B,GAAG,CAAC,CAAC,KAAK,CAC/C,OAAO,iCAAiC,CACzC,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG,IAAI,CACpD,2BAA2B,EAC3B,OAAO,GAAG,cAAc,GAAG,QAAQ,CACpC,CAAC;AAEF,4EAA4E;AAC5E,MAAM,WAAW,yCAAyC;IACxD,kBAAkB,CAChB,OAAO,EAAE,mCAAmC,GAC3C,OAAO,CAAC,MAAM,CAAC,CAAC;CACpB;AAED,MAAM,WAAW,4BAA4B;IAC3C,UAAU,CACR,KAAK,EAAE,2BAA2B,GACjC,aAAa,CAAC,wBAAwB,CAAC,CAAC;CAC5C;AAED,MAAM,MAAM,mCAAmC,GAAG;IAChD,SAAS,EAAE,kBAAkB,CAAC;IAC9B,aAAa,EAAE,aAAa,CAAC;IAC7B,gBAAgB,EAAE,yCAAyC,CAAC;IAC5D,4EAA4E;IAC5E,GAAG,CAAC,EAAE;QACJ,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;KACjC,CAAC;CACH,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ExecutionHostConversationTurnRequestSchema, ExecutionScopeSchema, RuntimeSessionIdSchema, } from '../contracts/index.js';
|
|
3
|
+
export const HostedConversationTurnInputSchema = z.object({
|
|
4
|
+
scope: ExecutionScopeSchema.omit({ adopterId: true }),
|
|
5
|
+
runtimeSessionId: RuntimeSessionIdSchema,
|
|
6
|
+
invocationId: ExecutionHostConversationTurnRequestSchema.shape.invocationId,
|
|
7
|
+
prompt: ExecutionHostConversationTurnRequestSchema.shape.prompt,
|
|
8
|
+
deadlineAt: ExecutionHostConversationTurnRequestSchema.shape.deadlineAt,
|
|
9
|
+
signal: z.custom((value) => value instanceof AbortSignal, 'signal must be an AbortSignal').optional(),
|
|
10
|
+
}).strict();
|
|
11
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/conversation/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,0CAA0C,EAC1C,oBAAoB,EACpB,sBAAsB,GAEvB,MAAM,uBAAuB,CAAC;AAI/B,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,CAAC,MAAM,CAAC;IACxD,KAAK,EAAE,oBAAoB,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACrD,gBAAgB,EAAE,sBAAsB;IACxC,YAAY,EAAE,0CAA0C,CAAC,KAAK,CAAC,YAAY;IAC3E,MAAM,EAAE,0CAA0C,CAAC,KAAK,CAAC,MAAM;IAC/D,UAAU,EAAE,0CAA0C,CAAC,KAAK,CAAC,UAAU;IACvE,MAAM,EAAE,CAAC,CAAC,MAAM,CACd,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,YAAY,WAAW,EACvC,+BAA+B,CAChC,CAAC,QAAQ,EAAE;CACb,CAAC,CAAC,MAAM,EAAE,CAAC","sourcesContent":["import { z } from 'zod';\nimport {\n ExecutionHostConversationTurnRequestSchema,\n ExecutionScopeSchema,\n RuntimeSessionIdSchema,\n type ExecutionHostStreamEvent,\n} from '../contracts/index.js';\nimport type { ExecutionAuthority } from '../authority/index.js';\nimport type { ExecutionHost } from '../http-sse/index.js';\n\nexport const HostedConversationTurnInputSchema = z.object({\n scope: ExecutionScopeSchema.omit({ adopterId: true }),\n runtimeSessionId: RuntimeSessionIdSchema,\n invocationId: ExecutionHostConversationTurnRequestSchema.shape.invocationId,\n prompt: ExecutionHostConversationTurnRequestSchema.shape.prompt,\n deadlineAt: ExecutionHostConversationTurnRequestSchema.shape.deadlineAt,\n signal: z.custom<AbortSignal>(\n (value) => value instanceof AbortSignal,\n 'signal must be an AbortSignal',\n ).optional(),\n}).strict();\n\nexport type HostedConversationTurnInput = z.infer<\n typeof HostedConversationTurnInputSchema\n>;\n\nexport type HostedConversationCredentialContext = Pick<\n HostedConversationTurnInput,\n 'scope' | 'invocationId' | 'signal'\n>;\n\n/** Resolves model authority without exposing it to HTTP or product data. */\nexport interface HostedConversationModelCredentialProvider {\n resolveModelApiKey(\n context: HostedConversationCredentialContext,\n ): Promise<string>;\n}\n\nexport interface HostedConversationTurnRunner {\n streamTurn(\n input: HostedConversationTurnInput,\n ): AsyncIterable<ExecutionHostStreamEvent>;\n}\n\nexport type HostedConversationTurnServiceConfig = {\n authority: ExecutionAuthority;\n executionHost: ExecutionHost;\n modelCredentials: HostedConversationModelCredentialProvider;\n /** Omit this policy when the hosted workflow needs no product MCP tools. */\n mcp?: {\n allowedTools: readonly string[];\n };\n};\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ExecutionHostStreamEvent } from '../contracts/index.js';
|
|
2
|
+
import type { DirectHttpExecutionHostConfig, ExecutionHost, ExecutionHostConversationTurn } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Strict direct-development HTTP/SSE adapter for the Execution Host v1 wire.
|
|
5
|
+
* It deliberately owns neither AWS SDK nor SigV4 behavior.
|
|
6
|
+
*/
|
|
7
|
+
export declare class DirectHttpExecutionHost implements ExecutionHost {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(config: DirectHttpExecutionHostConfig);
|
|
10
|
+
streamConversationTurn(rawInput: ExecutionHostConversationTurn): AsyncIterable<ExecutionHostStreamEvent>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=direct-http-execution-host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"direct-http-execution-host.d.ts","sourceRoot":"","sources":["../../src/http-sse/direct-http-execution-host.ts"],"names":[],"mappings":"AAEA,OAAO,EAeL,KAAK,wBAAwB,EAC9B,MAAM,uBAAuB,CAAC;AAO/B,OAAO,KAAK,EACV,6BAA6B,EAC7B,aAAa,EACb,6BAA6B,EAC9B,MAAM,YAAY,CAAC;AA0BpB;;;GAGG;AACH,qBAAa,uBAAwB,YAAW,aAAa;;gBAK/C,MAAM,EAAE,6BAA6B;IAO1C,sBAAsB,CAC3B,QAAQ,EAAE,6BAA6B,GACtC,aAAa,CAAC,wBAAwB,CAAC;CAuH3C"}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { createParser } from 'eventsource-parser';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { AGENTCORE_RUNTIME_SESSION_HEADER, CONVERSATION_TURN_WORKFLOW, EXECUTION_ASSERTION_HEADER, EXECUTION_CONTRACT_VERSION, EXECUTION_HOST_LOCAL_TOKEN_HEADER, ExecutionHostConversationTurnRequestSchema, ExecutionHostStreamEventSchema, MCP_CAPABILITY_HEADER, MODEL_API_KEY_HEADER, OpaqueIdSchema, RuntimeSessionIdSchema, TimestampSchema, isExecutionHostTerminalEvent, isSafeWebUrl, } from '../contracts/index.js';
|
|
4
|
+
import { ExecutionHostInvocationCancelledError, ExecutionHostProtocolError, ExecutionHostRejectedError, ExecutionHostStreamInterruptedError, } from './errors.js';
|
|
5
|
+
const MAX_SSE_BUFFER_CHARACTERS = 1_048_576;
|
|
6
|
+
const MAX_PENDING_SSE_FRAMES = 1_024;
|
|
7
|
+
const MAX_ERROR_BODY_BYTES = 16_384;
|
|
8
|
+
const SecretSchema = z.string().min(8).max(4_096);
|
|
9
|
+
const ConversationTurnSchema = z.object({
|
|
10
|
+
invocationId: OpaqueIdSchema,
|
|
11
|
+
runtimeSessionId: RuntimeSessionIdSchema,
|
|
12
|
+
prompt: z.string().trim().min(1).max(200_000),
|
|
13
|
+
deadlineAt: TimestampSchema.optional(),
|
|
14
|
+
executionAssertion: z.string().min(32).max(4_096),
|
|
15
|
+
mcpCapability: z.string().min(32).max(4_096).optional(),
|
|
16
|
+
modelApiKey: SecretSchema,
|
|
17
|
+
signal: z.custom((value) => value instanceof AbortSignal, 'signal must be an AbortSignal').optional(),
|
|
18
|
+
}).strict();
|
|
19
|
+
const ApiErrorSchema = z.object({
|
|
20
|
+
error: z.object({
|
|
21
|
+
code: z.string().min(1).max(128).regex(/^[a-z0-9_]+$/),
|
|
22
|
+
message: z.string(),
|
|
23
|
+
}).strict(),
|
|
24
|
+
}).strict();
|
|
25
|
+
/**
|
|
26
|
+
* Strict direct-development HTTP/SSE adapter for the Execution Host v1 wire.
|
|
27
|
+
* It deliberately owns neither AWS SDK nor SigV4 behavior.
|
|
28
|
+
*/
|
|
29
|
+
export class DirectHttpExecutionHost {
|
|
30
|
+
#endpoint;
|
|
31
|
+
#fetch;
|
|
32
|
+
#localToken;
|
|
33
|
+
constructor(config) {
|
|
34
|
+
assertSafeBaseUrl(config.baseUrl);
|
|
35
|
+
this.#localToken = SecretSchema.parse(config.localToken);
|
|
36
|
+
this.#endpoint = new URL('invocations', withTrailingSlash(config.baseUrl));
|
|
37
|
+
this.#fetch = config.fetch ?? globalThis.fetch;
|
|
38
|
+
}
|
|
39
|
+
async *streamConversationTurn(rawInput) {
|
|
40
|
+
const input = ConversationTurnSchema.parse(rawInput);
|
|
41
|
+
if (input.signal?.aborted) {
|
|
42
|
+
throw new ExecutionHostInvocationCancelledError();
|
|
43
|
+
}
|
|
44
|
+
const response = await this.#invoke(input);
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
throw new ExecutionHostRejectedError(response.status, await readSafeErrorCode(response));
|
|
47
|
+
}
|
|
48
|
+
if (!isEventStream(response.headers.get('content-type'))) {
|
|
49
|
+
await cancelBody(response);
|
|
50
|
+
throw new ExecutionHostProtocolError('Execution Host did not return an SSE stream.');
|
|
51
|
+
}
|
|
52
|
+
if (!response.body) {
|
|
53
|
+
throw new ExecutionHostProtocolError('Execution Host returned an empty SSE response body.');
|
|
54
|
+
}
|
|
55
|
+
const state = {
|
|
56
|
+
invocationId: input.invocationId,
|
|
57
|
+
nextSequence: 0,
|
|
58
|
+
terminal: false,
|
|
59
|
+
};
|
|
60
|
+
const decoder = new TextDecoder();
|
|
61
|
+
const pending = [];
|
|
62
|
+
let terminalEvent;
|
|
63
|
+
let parserError = false;
|
|
64
|
+
const parser = createParser({
|
|
65
|
+
maxBufferSize: MAX_SSE_BUFFER_CHARACTERS,
|
|
66
|
+
onEvent: (event) => {
|
|
67
|
+
if (pending.length >= MAX_PENDING_SSE_FRAMES) {
|
|
68
|
+
parserError = true;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
pending.push(event);
|
|
72
|
+
},
|
|
73
|
+
onError: () => {
|
|
74
|
+
parserError = true;
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
try {
|
|
78
|
+
for await (const chunk of response.body) {
|
|
79
|
+
input.signal?.throwIfAborted();
|
|
80
|
+
parser.feed(decoder.decode(chunk, { stream: true }));
|
|
81
|
+
if (parserError) {
|
|
82
|
+
throw new ExecutionHostProtocolError();
|
|
83
|
+
}
|
|
84
|
+
while (pending.length > 0) {
|
|
85
|
+
const event = validateEvent(pending.shift(), state);
|
|
86
|
+
if (isExecutionHostTerminalEvent(event)) {
|
|
87
|
+
terminalEvent = event;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
yield event;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
parser.feed(decoder.decode());
|
|
95
|
+
parser.reset({ consume: true });
|
|
96
|
+
if (parserError) {
|
|
97
|
+
throw new ExecutionHostProtocolError();
|
|
98
|
+
}
|
|
99
|
+
while (pending.length > 0) {
|
|
100
|
+
const event = validateEvent(pending.shift(), state);
|
|
101
|
+
if (isExecutionHostTerminalEvent(event)) {
|
|
102
|
+
terminalEvent = event;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
yield event;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
if (error instanceof ExecutionHostProtocolError) {
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
throw toTransportError(error, input.signal);
|
|
114
|
+
}
|
|
115
|
+
if (!state.accepted) {
|
|
116
|
+
throw new ExecutionHostProtocolError('Execution Host stream omitted the accepted event.');
|
|
117
|
+
}
|
|
118
|
+
if (!state.terminal || !terminalEvent) {
|
|
119
|
+
throw new ExecutionHostStreamInterruptedError();
|
|
120
|
+
}
|
|
121
|
+
// Terminal is released only after clean EOF, so a trailing malformed or
|
|
122
|
+
// post-terminal frame cannot be projected as success.
|
|
123
|
+
yield terminalEvent;
|
|
124
|
+
}
|
|
125
|
+
async #invoke(input) {
|
|
126
|
+
const body = ExecutionHostConversationTurnRequestSchema.parse({
|
|
127
|
+
schemaVersion: EXECUTION_CONTRACT_VERSION,
|
|
128
|
+
kind: CONVERSATION_TURN_WORKFLOW,
|
|
129
|
+
invocationId: input.invocationId,
|
|
130
|
+
prompt: input.prompt,
|
|
131
|
+
...(input.deadlineAt ? { deadlineAt: input.deadlineAt } : {}),
|
|
132
|
+
});
|
|
133
|
+
try {
|
|
134
|
+
return await this.#fetch(this.#endpoint, {
|
|
135
|
+
method: 'POST',
|
|
136
|
+
redirect: 'error',
|
|
137
|
+
signal: input.signal,
|
|
138
|
+
headers: createSensitiveHeaders(input, this.#localToken),
|
|
139
|
+
body: JSON.stringify(body),
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
throw toTransportError(error, input.signal);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function validateEvent(frame, state) {
|
|
148
|
+
let decoded;
|
|
149
|
+
try {
|
|
150
|
+
decoded = JSON.parse(frame.data);
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
throw new ExecutionHostProtocolError();
|
|
154
|
+
}
|
|
155
|
+
const parsed = ExecutionHostStreamEventSchema.safeParse(decoded);
|
|
156
|
+
if (!parsed.success) {
|
|
157
|
+
throw new ExecutionHostProtocolError();
|
|
158
|
+
}
|
|
159
|
+
const event = parsed.data;
|
|
160
|
+
const correctFrameMetadata = frame.event === event.kind
|
|
161
|
+
&& frame.id === String(event.sequence);
|
|
162
|
+
const correctEnvelope = event.invocationId === state.invocationId
|
|
163
|
+
&& event.sequence === state.nextSequence;
|
|
164
|
+
if (!correctFrameMetadata || !correctEnvelope || state.terminal) {
|
|
165
|
+
throw new ExecutionHostProtocolError();
|
|
166
|
+
}
|
|
167
|
+
if (!state.accepted) {
|
|
168
|
+
if (event.kind !== 'accepted') {
|
|
169
|
+
throw new ExecutionHostProtocolError();
|
|
170
|
+
}
|
|
171
|
+
state.accepted = true;
|
|
172
|
+
state.runId = event.runId;
|
|
173
|
+
}
|
|
174
|
+
else if (event.kind === 'accepted' || event.runId !== state.runId) {
|
|
175
|
+
throw new ExecutionHostProtocolError();
|
|
176
|
+
}
|
|
177
|
+
state.nextSequence += 1;
|
|
178
|
+
state.terminal = isExecutionHostTerminalEvent(event);
|
|
179
|
+
return event;
|
|
180
|
+
}
|
|
181
|
+
function createSensitiveHeaders(input, localToken) {
|
|
182
|
+
const headers = new Headers({
|
|
183
|
+
Accept: 'text/event-stream',
|
|
184
|
+
'Content-Type': 'application/json',
|
|
185
|
+
[AGENTCORE_RUNTIME_SESSION_HEADER]: input.runtimeSessionId,
|
|
186
|
+
[EXECUTION_HOST_LOCAL_TOKEN_HEADER]: localToken,
|
|
187
|
+
[MODEL_API_KEY_HEADER]: input.modelApiKey,
|
|
188
|
+
[EXECUTION_ASSERTION_HEADER]: input.executionAssertion,
|
|
189
|
+
});
|
|
190
|
+
if (input.mcpCapability) {
|
|
191
|
+
headers.set(MCP_CAPABILITY_HEADER, input.mcpCapability);
|
|
192
|
+
}
|
|
193
|
+
return headers;
|
|
194
|
+
}
|
|
195
|
+
function isEventStream(contentType) {
|
|
196
|
+
return contentType?.split(';', 1)[0]?.trim().toLowerCase()
|
|
197
|
+
=== 'text/event-stream';
|
|
198
|
+
}
|
|
199
|
+
async function readSafeErrorCode(response) {
|
|
200
|
+
try {
|
|
201
|
+
const declaredLength = Number(response.headers.get('content-length'));
|
|
202
|
+
if (Number.isFinite(declaredLength)
|
|
203
|
+
&& declaredLength > MAX_ERROR_BODY_BYTES) {
|
|
204
|
+
await cancelBody(response);
|
|
205
|
+
return 'unknown';
|
|
206
|
+
}
|
|
207
|
+
const bytes = await readBoundedBody(response, MAX_ERROR_BODY_BYTES);
|
|
208
|
+
if (!bytes) {
|
|
209
|
+
return 'unknown';
|
|
210
|
+
}
|
|
211
|
+
const parsed = ApiErrorSchema.safeParse(JSON.parse(new TextDecoder().decode(bytes)));
|
|
212
|
+
return parsed.success ? parsed.data.error.code : 'unknown';
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
return 'unknown';
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
async function readBoundedBody(response, maxBytes) {
|
|
219
|
+
if (!response.body) {
|
|
220
|
+
return new Uint8Array();
|
|
221
|
+
}
|
|
222
|
+
const reader = response.body.getReader();
|
|
223
|
+
const chunks = [];
|
|
224
|
+
let totalBytes = 0;
|
|
225
|
+
try {
|
|
226
|
+
while (true) {
|
|
227
|
+
const { done, value } = await reader.read();
|
|
228
|
+
if (done) {
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
totalBytes += value.byteLength;
|
|
232
|
+
if (totalBytes > maxBytes) {
|
|
233
|
+
await reader.cancel();
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
chunks.push(value);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
finally {
|
|
240
|
+
reader.releaseLock();
|
|
241
|
+
}
|
|
242
|
+
const bytes = new Uint8Array(totalBytes);
|
|
243
|
+
let offset = 0;
|
|
244
|
+
for (const chunk of chunks) {
|
|
245
|
+
bytes.set(chunk, offset);
|
|
246
|
+
offset += chunk.byteLength;
|
|
247
|
+
}
|
|
248
|
+
return bytes;
|
|
249
|
+
}
|
|
250
|
+
async function cancelBody(response) {
|
|
251
|
+
try {
|
|
252
|
+
await response.body?.cancel();
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
// Response cleanup is best effort and must not replace the protocol error.
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
function toTransportError(error, signal) {
|
|
259
|
+
if (signal?.aborted || isAbortError(error)) {
|
|
260
|
+
return new ExecutionHostInvocationCancelledError();
|
|
261
|
+
}
|
|
262
|
+
return new ExecutionHostStreamInterruptedError();
|
|
263
|
+
}
|
|
264
|
+
function isAbortError(error) {
|
|
265
|
+
return error instanceof Error && error.name === 'AbortError';
|
|
266
|
+
}
|
|
267
|
+
function assertSafeBaseUrl(url) {
|
|
268
|
+
if (!isSafeWebUrl(url)) {
|
|
269
|
+
throw new Error('Direct Execution Host URL must use HTTPS or loopback HTTP and contain no credentials, query, or fragment.');
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function withTrailingSlash(url) {
|
|
273
|
+
const normalized = new URL(url);
|
|
274
|
+
normalized.pathname = normalized.pathname.endsWith('/')
|
|
275
|
+
? normalized.pathname
|
|
276
|
+
: `${normalized.pathname}/`;
|
|
277
|
+
return normalized;
|
|
278
|
+
}
|
|
279
|
+
//# sourceMappingURL=direct-http-execution-host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"direct-http-execution-host.js","sourceRoot":"","sources":["../../src/http-sse/direct-http-execution-host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA2B,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,gCAAgC,EAChC,0BAA0B,EAC1B,0BAA0B,EAC1B,0BAA0B,EAC1B,iCAAiC,EACjC,0CAA0C,EAC1C,8BAA8B,EAC9B,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,sBAAsB,EACtB,eAAe,EACf,4BAA4B,EAC5B,YAAY,GAEb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,qCAAqC,EACrC,0BAA0B,EAC1B,0BAA0B,EAC1B,mCAAmC,GACpC,MAAM,aAAa,CAAC;AAOrB,MAAM,yBAAyB,GAAG,SAAS,CAAC;AAC5C,MAAM,sBAAsB,GAAG,KAAK,CAAC;AACrC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AACpC,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AAClD,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,YAAY,EAAE,cAAc;IAC5B,gBAAgB,EAAE,sBAAsB;IACxC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC;IAC7C,UAAU,EAAE,eAAe,CAAC,QAAQ,EAAE;IACtC,kBAAkB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC;IACjD,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC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age } from 'eventsource-parser';\nimport { z } from 'zod';\nimport {\n AGENTCORE_RUNTIME_SESSION_HEADER,\n CONVERSATION_TURN_WORKFLOW,\n EXECUTION_ASSERTION_HEADER,\n EXECUTION_CONTRACT_VERSION,\n EXECUTION_HOST_LOCAL_TOKEN_HEADER,\n ExecutionHostConversationTurnRequestSchema,\n ExecutionHostStreamEventSchema,\n MCP_CAPABILITY_HEADER,\n MODEL_API_KEY_HEADER,\n OpaqueIdSchema,\n RuntimeSessionIdSchema,\n TimestampSchema,\n isExecutionHostTerminalEvent,\n isSafeWebUrl,\n type ExecutionHostStreamEvent,\n} from '../contracts/index.js';\nimport {\n ExecutionHostInvocationCancelledError,\n ExecutionHostProtocolError,\n ExecutionHostRejectedError,\n ExecutionHostStreamInterruptedError,\n} from './errors.js';\nimport type {\n DirectHttpExecutionHostConfig,\n ExecutionHost,\n ExecutionHostConversationTurn,\n} from './types.js';\n\nconst MAX_SSE_BUFFER_CHARACTERS = 1_048_576;\nconst MAX_PENDING_SSE_FRAMES = 1_024;\nconst MAX_ERROR_BODY_BYTES = 16_384;\nconst SecretSchema = z.string().min(8).max(4_096);\nconst ConversationTurnSchema = z.object({\n invocationId: OpaqueIdSchema,\n runtimeSessionId: RuntimeSessionIdSchema,\n prompt: z.string().trim().min(1).max(200_000),\n deadlineAt: TimestampSchema.optional(),\n executionAssertion: z.string().min(32).max(4_096),\n mcpCapability: z.string().min(32).max(4_096).optional(),\n modelApiKey: SecretSchema,\n signal: z.custom<AbortSignal>(\n (value) => value instanceof AbortSignal,\n 'signal must be an AbortSignal',\n ).optional(),\n}).strict();\nconst ApiErrorSchema = z.object({\n error: z.object({\n code: z.string().min(1).max(128).regex(/^[a-z0-9_]+$/),\n message: z.string(),\n }).strict(),\n}).strict();\n\n/**\n * Strict direct-development HTTP/SSE adapter for the Execution Host v1 wire.\n * It deliberately owns neither AWS SDK nor SigV4 behavior.\n */\nexport class DirectHttpExecutionHost implements ExecutionHost {\n readonly #endpoint: URL;\n readonly #fetch: typeof fetch;\n readonly #localToken: string;\n\n constructor(config: DirectHttpExecutionHostConfig) {\n assertSafeBaseUrl(config.baseUrl);\n this.#localToken = SecretSchema.parse(config.localToken);\n this.#endpoint = new URL('invocations', withTrailingSlash(config.baseUrl));\n this.#fetch = config.fetch ?? globalThis.fetch;\n }\n\n async *streamConversationTurn(\n rawInput: ExecutionHostConversationTurn,\n ): AsyncIterable<ExecutionHostStreamEvent> {\n const input = ConversationTurnSchema.parse(rawInput);\n if (input.signal?.aborted) {\n throw new ExecutionHostInvocationCancelledError();\n }\n\n const response = await this.#invoke(input);\n if (!response.ok) {\n throw new ExecutionHostRejectedError(\n response.status,\n await readSafeErrorCode(response),\n );\n }\n if (!isEventStream(response.headers.get('content-type'))) {\n await cancelBody(response);\n throw new ExecutionHostProtocolError(\n 'Execution Host did not return an SSE stream.',\n );\n }\n if (!response.body) {\n throw new ExecutionHostProtocolError(\n 'Execution Host returned an empty SSE response body.',\n );\n }\n\n const state: StreamValidationState = {\n invocationId: input.invocationId,\n nextSequence: 0,\n terminal: false,\n };\n const decoder = new TextDecoder();\n const pending: EventSourceMessage[] = [];\n let terminalEvent: ExecutionHostStreamEvent | undefined;\n let parserError = false;\n const parser = createParser({\n maxBufferSize: MAX_SSE_BUFFER_CHARACTERS,\n onEvent: (event) => {\n if (pending.length >= MAX_PENDING_SSE_FRAMES) {\n parserError = true;\n return;\n }\n pending.push(event);\n },\n onError: () => {\n parserError = true;\n },\n });\n\n try {\n for await (const chunk of response.body) {\n input.signal?.throwIfAborted();\n parser.feed(decoder.decode(chunk, { stream: true }));\n if (parserError) {\n throw new ExecutionHostProtocolError();\n }\n while (pending.length > 0) {\n const event = validateEvent(pending.shift()!, state);\n if (isExecutionHostTerminalEvent(event)) {\n terminalEvent = event;\n } else {\n yield event;\n }\n }\n }\n parser.feed(decoder.decode());\n parser.reset({ consume: true });\n if (parserError) {\n throw new ExecutionHostProtocolError();\n }\n while (pending.length > 0) {\n const event = validateEvent(pending.shift()!, state);\n if (isExecutionHostTerminalEvent(event)) {\n terminalEvent = event;\n } else {\n yield event;\n }\n }\n } catch (error) {\n if (error instanceof ExecutionHostProtocolError) {\n throw error;\n }\n throw toTransportError(error, input.signal);\n }\n\n if (!state.accepted) {\n throw new ExecutionHostProtocolError(\n 'Execution Host stream omitted the accepted event.',\n );\n }\n if (!state.terminal || !terminalEvent) {\n throw new ExecutionHostStreamInterruptedError();\n }\n // Terminal is released only after clean EOF, so a trailing malformed or\n // post-terminal frame cannot be projected as success.\n yield terminalEvent;\n }\n\n async #invoke(\n input: z.infer<typeof ConversationTurnSchema>,\n ): Promise<Response> {\n const body = ExecutionHostConversationTurnRequestSchema.parse({\n schemaVersion: EXECUTION_CONTRACT_VERSION,\n kind: CONVERSATION_TURN_WORKFLOW,\n invocationId: input.invocationId,\n prompt: input.prompt,\n ...(input.deadlineAt ? { deadlineAt: input.deadlineAt } : {}),\n });\n try {\n return await this.#fetch(this.#endpoint, {\n method: 'POST',\n redirect: 'error',\n signal: input.signal,\n headers: createSensitiveHeaders(input, this.#localToken),\n body: JSON.stringify(body),\n });\n } catch (error) {\n throw toTransportError(error, input.signal);\n }\n }\n}\n\ntype StreamValidationState = {\n invocationId: string;\n runId?: string;\n nextSequence: number;\n accepted?: true;\n terminal: boolean;\n};\n\nfunction validateEvent(\n frame: EventSourceMessage,\n state: StreamValidationState,\n): ExecutionHostStreamEvent {\n let decoded: unknown;\n try {\n decoded = JSON.parse(frame.data);\n } catch {\n throw new ExecutionHostProtocolError();\n }\n const parsed = ExecutionHostStreamEventSchema.safeParse(decoded);\n if (!parsed.success) {\n throw new ExecutionHostProtocolError();\n }\n const event = parsed.data;\n const correctFrameMetadata = frame.event === event.kind\n && frame.id === String(event.sequence);\n const correctEnvelope = event.invocationId === state.invocationId\n && event.sequence === state.nextSequence;\n if (!correctFrameMetadata || !correctEnvelope || state.terminal) {\n throw new ExecutionHostProtocolError();\n }\n\n if (!state.accepted) {\n if (event.kind !== 'accepted') {\n throw new ExecutionHostProtocolError();\n }\n state.accepted = true;\n state.runId = event.runId;\n } else if (event.kind === 'accepted' || event.runId !== state.runId) {\n throw new ExecutionHostProtocolError();\n }\n\n state.nextSequence += 1;\n state.terminal = isExecutionHostTerminalEvent(event);\n return event;\n}\n\nfunction createSensitiveHeaders(\n input: z.infer<typeof ConversationTurnSchema>,\n localToken: string,\n): Headers {\n const headers = new Headers({\n Accept: 'text/event-stream',\n 'Content-Type': 'application/json',\n [AGENTCORE_RUNTIME_SESSION_HEADER]: input.runtimeSessionId,\n [EXECUTION_HOST_LOCAL_TOKEN_HEADER]: localToken,\n [MODEL_API_KEY_HEADER]: input.modelApiKey,\n [EXECUTION_ASSERTION_HEADER]: input.executionAssertion,\n });\n if (input.mcpCapability) {\n headers.set(MCP_CAPABILITY_HEADER, input.mcpCapability);\n }\n return headers;\n}\n\nfunction isEventStream(contentType: string | null): boolean {\n return contentType?.split(';', 1)[0]?.trim().toLowerCase()\n === 'text/event-stream';\n}\n\nasync function readSafeErrorCode(response: Response): Promise<string> {\n try {\n const declaredLength = Number(response.headers.get('content-length'));\n if (\n Number.isFinite(declaredLength)\n && declaredLength > MAX_ERROR_BODY_BYTES\n ) {\n await cancelBody(response);\n return 'unknown';\n }\n const bytes = await readBoundedBody(response, MAX_ERROR_BODY_BYTES);\n if (!bytes) {\n return 'unknown';\n }\n const parsed = ApiErrorSchema.safeParse(\n JSON.parse(new TextDecoder().decode(bytes)),\n );\n return parsed.success ? parsed.data.error.code : 'unknown';\n } catch {\n return 'unknown';\n }\n}\n\nasync function readBoundedBody(\n response: Response,\n maxBytes: number,\n): Promise<Uint8Array | undefined> {\n if (!response.body) {\n return new Uint8Array();\n }\n const reader = response.body.getReader();\n const chunks: Uint8Array[] = [];\n let totalBytes = 0;\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n break;\n }\n totalBytes += value.byteLength;\n if (totalBytes > maxBytes) {\n await reader.cancel();\n return undefined;\n }\n chunks.push(value);\n }\n } finally {\n reader.releaseLock();\n }\n const bytes = new Uint8Array(totalBytes);\n let offset = 0;\n for (const chunk of chunks) {\n bytes.set(chunk, offset);\n offset += chunk.byteLength;\n }\n return bytes;\n}\n\nasync function cancelBody(response: Response): Promise<void> {\n try {\n await response.body?.cancel();\n } catch {\n // Response cleanup is best effort and must not replace the protocol error.\n }\n}\n\nfunction toTransportError(error: unknown, signal?: AbortSignal): Error {\n if (signal?.aborted || isAbortError(error)) {\n return new ExecutionHostInvocationCancelledError();\n }\n return new ExecutionHostStreamInterruptedError();\n}\n\nfunction isAbortError(error: unknown): boolean {\n return error instanceof Error && error.name === 'AbortError';\n}\n\nfunction assertSafeBaseUrl(url: URL): void {\n if (!isSafeWebUrl(url)) {\n throw new Error(\n 'Direct Execution Host URL must use HTTPS or loopback HTTP and contain no credentials, query, or fragment.',\n );\n }\n}\n\nfunction withTrailingSlash(url: URL): URL {\n const normalized = new URL(url);\n normalized.pathname = normalized.pathname.endsWith('/')\n ? normalized.pathname\n : `${normalized.pathname}/`;\n return normalized;\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare class ExecutionHostProtocolError extends Error {
|
|
2
|
+
readonly name = "ExecutionHostProtocolError";
|
|
3
|
+
constructor(message?: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class ExecutionHostStreamInterruptedError extends Error {
|
|
6
|
+
readonly name = "ExecutionHostStreamInterruptedError";
|
|
7
|
+
constructor();
|
|
8
|
+
}
|
|
9
|
+
export declare class ExecutionHostInvocationCancelledError extends Error {
|
|
10
|
+
readonly name = "ExecutionHostInvocationCancelledError";
|
|
11
|
+
constructor();
|
|
12
|
+
}
|
|
13
|
+
export declare class ExecutionHostRejectedError extends Error {
|
|
14
|
+
readonly status: number;
|
|
15
|
+
readonly code: string;
|
|
16
|
+
readonly name = "ExecutionHostRejectedError";
|
|
17
|
+
constructor(status: number, code: string);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/http-sse/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,0BAA2B,SAAQ,KAAK;IACnD,QAAQ,CAAC,IAAI,gCAAgC;gBAEjC,OAAO,SAAkD;CAGtE;AAED,qBAAa,mCAAoC,SAAQ,KAAK;IAC5D,QAAQ,CAAC,IAAI,yCAAyC;;CAKvD;AAED,qBAAa,qCAAsC,SAAQ,KAAK;IAC9D,QAAQ,CAAC,IAAI,2CAA2C;;CAKzD;AAED,qBAAa,0BAA2B,SAAQ,KAAK;IAIjD,QAAQ,CAAC,MAAM,EAAE,MAAM;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM;IAJvB,QAAQ,CAAC,IAAI,gCAAgC;gBAGlC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM;CAIxB"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export class ExecutionHostProtocolError extends Error {
|
|
2
|
+
name = 'ExecutionHostProtocolError';
|
|
3
|
+
constructor(message = 'Execution Host returned an invalid v1 stream.') {
|
|
4
|
+
super(message);
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export class ExecutionHostStreamInterruptedError extends Error {
|
|
8
|
+
name = 'ExecutionHostStreamInterruptedError';
|
|
9
|
+
constructor() {
|
|
10
|
+
super('Execution Host stream ended without a terminal event.');
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class ExecutionHostInvocationCancelledError extends Error {
|
|
14
|
+
name = 'ExecutionHostInvocationCancelledError';
|
|
15
|
+
constructor() {
|
|
16
|
+
super('Execution Host invocation was cancelled.');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export class ExecutionHostRejectedError extends Error {
|
|
20
|
+
status;
|
|
21
|
+
code;
|
|
22
|
+
name = 'ExecutionHostRejectedError';
|
|
23
|
+
constructor(status, code) {
|
|
24
|
+
super(`Execution Host rejected the invocation (${status}, ${code}).`);
|
|
25
|
+
this.status = status;
|
|
26
|
+
this.code = code;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/http-sse/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IAC1C,IAAI,GAAG,4BAA4B,CAAC;IAE7C,YAAY,OAAO,GAAG,+CAA+C;QACnE,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAED,MAAM,OAAO,mCAAoC,SAAQ,KAAK;IACnD,IAAI,GAAG,qCAAqC,CAAC;IAEtD;QACE,KAAK,CAAC,uDAAuD,CAAC,CAAC;IACjE,CAAC;CACF;AAED,MAAM,OAAO,qCAAsC,SAAQ,KAAK;IACrD,IAAI,GAAG,uCAAuC,CAAC;IAExD;QACE,KAAK,CAAC,0CAA0C,CAAC,CAAC;IACpD,CAAC;CACF;AAED,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IAIxC;IACA;IAJF,IAAI,GAAG,4BAA4B,CAAC;IAE7C,YACW,MAAc,EACd,IAAY;QAErB,KAAK,CAAC,2CAA2C,MAAM,KAAK,IAAI,IAAI,CAAC,CAAC;QAH7D,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAQ;IAGvB,CAAC;CACF","sourcesContent":["export class ExecutionHostProtocolError extends Error {\n readonly name = 'ExecutionHostProtocolError';\n\n constructor(message = 'Execution Host returned an invalid v1 stream.') {\n super(message);\n }\n}\n\nexport class ExecutionHostStreamInterruptedError extends Error {\n readonly name = 'ExecutionHostStreamInterruptedError';\n\n constructor() {\n super('Execution Host stream ended without a terminal event.');\n }\n}\n\nexport class ExecutionHostInvocationCancelledError extends Error {\n readonly name = 'ExecutionHostInvocationCancelledError';\n\n constructor() {\n super('Execution Host invocation was cancelled.');\n }\n}\n\nexport class ExecutionHostRejectedError extends Error {\n readonly name = 'ExecutionHostRejectedError';\n\n constructor(\n readonly status: number,\n readonly code: string,\n ) {\n super(`Execution Host rejected the invocation (${status}, ${code}).`);\n }\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { DirectHttpExecutionHost } from './direct-http-execution-host.js';
|
|
2
|
+
export { ExecutionHostInvocationCancelledError, ExecutionHostProtocolError, ExecutionHostRejectedError, ExecutionHostStreamInterruptedError, } from './errors.js';
|
|
3
|
+
export type { DirectHttpExecutionHostConfig, ExecutionHost, ExecutionHostConversationTurn, } from './types.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/http-sse/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EACL,qCAAqC,EACrC,0BAA0B,EAC1B,0BAA0B,EAC1B,mCAAmC,GACpC,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,6BAA6B,EAC7B,aAAa,EACb,6BAA6B,GAC9B,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/http-sse/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EACL,qCAAqC,EACrC,0BAA0B,EAC1B,0BAA0B,EAC1B,mCAAmC,GACpC,MAAM,aAAa,CAAC","sourcesContent":["export { DirectHttpExecutionHost } from './direct-http-execution-host.js';\nexport {\n ExecutionHostInvocationCancelledError,\n ExecutionHostProtocolError,\n ExecutionHostRejectedError,\n ExecutionHostStreamInterruptedError,\n} from './errors.js';\nexport type {\n DirectHttpExecutionHostConfig,\n ExecutionHost,\n ExecutionHostConversationTurn,\n} from './types.js';\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ExecutionHostStreamEvent } from '../contracts/index.js';
|
|
2
|
+
export type ExecutionHostConversationTurn = {
|
|
3
|
+
invocationId: string;
|
|
4
|
+
runtimeSessionId: string;
|
|
5
|
+
prompt: string;
|
|
6
|
+
deadlineAt?: string;
|
|
7
|
+
executionAssertion: string;
|
|
8
|
+
mcpCapability?: string;
|
|
9
|
+
modelApiKey: string;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
};
|
|
12
|
+
export interface ExecutionHost {
|
|
13
|
+
streamConversationTurn(input: ExecutionHostConversationTurn): AsyncIterable<ExecutionHostStreamEvent>;
|
|
14
|
+
}
|
|
15
|
+
export type DirectHttpExecutionHostConfig = {
|
|
16
|
+
baseUrl: URL;
|
|
17
|
+
localToken: string;
|
|
18
|
+
fetch?: typeof fetch;
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/http-sse/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE,MAAM,MAAM,6BAA6B,GAAG;IAC1C,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF,MAAM,WAAW,aAAa;IAC5B,sBAAsB,CACpB,KAAK,EAAE,6BAA6B,GACnC,aAAa,CAAC,wBAAwB,CAAC,CAAC;CAC5C;AAED,MAAM,MAAM,6BAA6B,GAAG;IAC1C,OAAO,EAAE,GAAG,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;CACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/http-sse/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ExecutionHostStreamEvent } from '../contracts/index.js';\n\nexport type ExecutionHostConversationTurn = {\n invocationId: string;\n runtimeSessionId: string;\n prompt: string;\n deadlineAt?: string;\n executionAssertion: string;\n mcpCapability?: string;\n modelApiKey: string;\n signal?: AbortSignal;\n};\n\nexport interface ExecutionHost {\n streamConversationTurn(\n input: ExecutionHostConversationTurn,\n ): AsyncIterable<ExecutionHostStreamEvent>;\n}\n\nexport type DirectHttpExecutionHostConfig = {\n baseUrl: URL;\n localToken: string;\n fetch?: typeof fetch;\n};\n"]}
|