@evalops/maestro 0.10.21 → 0.10.22
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/dist/agent/agent.d.ts +1 -0
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/agent.js +15 -4
- package/dist/agent/agent.js.map +1 -1
- package/dist/agent/swarm/executor.d.ts.map +1 -1
- package/dist/agent/swarm/executor.js +68 -3
- package/dist/agent/swarm/executor.js.map +1 -1
- package/dist/agent/swarm/types.d.ts +3 -0
- package/dist/agent/swarm/types.d.ts.map +1 -1
- package/dist/agent/swarm/types.js.map +1 -1
- package/dist/agent/transport.d.ts.map +1 -1
- package/dist/agent/transport.js +7 -1
- package/dist/agent/transport.js.map +1 -1
- package/dist/audit/logger.d.ts +1 -1
- package/dist/bootstrap/tools-setup.d.ts.map +1 -1
- package/dist/bootstrap/tools-setup.js +3 -2
- package/dist/bootstrap/tools-setup.js.map +1 -1
- package/dist/cli/commands/a2a.d.ts.map +1 -1
- package/dist/cli/commands/a2a.js +141 -8
- package/dist/cli/commands/a2a.js.map +1 -1
- package/dist/cli/commands/codex.d.ts.map +1 -1
- package/dist/cli/commands/codex.js +4 -3
- package/dist/cli/commands/codex.js.map +1 -1
- package/dist/cli/commands/hosted-runner.d.ts +1 -0
- package/dist/cli/commands/hosted-runner.d.ts.map +1 -1
- package/dist/cli/commands/hosted-runner.js +31 -2
- package/dist/cli/commands/hosted-runner.js.map +1 -1
- package/dist/cli/commands/run.d.ts.map +1 -1
- package/dist/cli/commands/run.js +2 -9
- package/dist/cli/commands/run.js.map +1 -1
- package/dist/cli-tui/commands/a2a-handlers.d.ts.map +1 -1
- package/dist/cli-tui/commands/a2a-handlers.js +55 -0
- package/dist/cli-tui/commands/a2a-handlers.js.map +1 -1
- package/dist/cli.js +3924 -1972
- package/dist/codex/compatibility.d.ts +17 -1
- package/dist/codex/compatibility.d.ts.map +1 -1
- package/dist/codex/compatibility.js +57 -1
- package/dist/codex/compatibility.js.map +1 -1
- package/dist/guardian/config.d.ts +8 -6
- package/dist/guardian/config.d.ts.map +1 -1
- package/dist/guardian/config.js +33 -7
- package/dist/guardian/config.js.map +1 -1
- package/dist/guardian/runner.d.ts.map +1 -1
- package/dist/guardian/runner.js +54 -9
- package/dist/guardian/runner.js.map +1 -1
- package/dist/mcp/config.d.ts.map +1 -1
- package/dist/mcp/config.js +2 -0
- package/dist/mcp/config.js.map +1 -1
- package/dist/mcp/fathom-cua.d.ts +3 -0
- package/dist/mcp/fathom-cua.d.ts.map +1 -0
- package/dist/mcp/fathom-cua.js +158 -0
- package/dist/mcp/fathom-cua.js.map +1 -0
- package/dist/mcp/index.d.ts +1 -0
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +1 -0
- package/dist/mcp/index.js.map +1 -1
- package/dist/node_modules/@evalops/contracts/package.json +1 -1
- package/dist/node_modules/@evalops/tui/package.json +1 -1
- package/dist/platform/a2a-cockpit.d.ts +90 -0
- package/dist/platform/a2a-cockpit.d.ts.map +1 -0
- package/dist/platform/a2a-cockpit.js +302 -0
- package/dist/platform/a2a-cockpit.js.map +1 -0
- package/dist/platform/a2a-fleet.d.ts +14 -0
- package/dist/platform/a2a-fleet.d.ts.map +1 -1
- package/dist/platform/a2a-fleet.js +66 -1
- package/dist/platform/a2a-fleet.js.map +1 -1
- package/dist/platform/a2a-ownership.d.ts +27 -0
- package/dist/platform/a2a-ownership.d.ts.map +1 -0
- package/dist/platform/a2a-ownership.js +149 -0
- package/dist/platform/a2a-ownership.js.map +1 -0
- package/dist/platform/a2a-task-ledger.d.ts.map +1 -1
- package/dist/platform/a2a-task-ledger.js +29 -5
- package/dist/platform/a2a-task-ledger.js.map +1 -1
- package/dist/server/agent-trajectory-replay-lab.d.ts +36 -0
- package/dist/server/agent-trajectory-replay-lab.d.ts.map +1 -0
- package/dist/server/agent-trajectory-replay-lab.js +48 -0
- package/dist/server/agent-trajectory-replay-lab.js.map +1 -0
- package/dist/server/any-agent-control-plane-proof.d.ts +42 -0
- package/dist/server/any-agent-control-plane-proof.d.ts.map +1 -0
- package/dist/server/any-agent-control-plane-proof.js +175 -0
- package/dist/server/any-agent-control-plane-proof.js.map +1 -0
- package/dist/server/app-context.d.ts +1 -0
- package/dist/server/app-context.d.ts.map +1 -1
- package/dist/server/app-context.js.map +1 -1
- package/dist/server/handlers/a2a-cockpit.d.ts +3 -0
- package/dist/server/handlers/a2a-cockpit.d.ts.map +1 -0
- package/dist/server/handlers/a2a-cockpit.js +71 -0
- package/dist/server/handlers/a2a-cockpit.js.map +1 -0
- package/dist/server/handlers/headless-sessions.d.ts.map +1 -1
- package/dist/server/handlers/headless-sessions.js +17 -2
- package/dist/server/handlers/headless-sessions.js.map +1 -1
- package/dist/server/handlers/session-artifacts.d.ts.map +1 -1
- package/dist/server/handlers/session-artifacts.js +20 -3
- package/dist/server/handlers/session-artifacts.js.map +1 -1
- package/dist/server/handlers/session-replay-lab.d.ts +13 -0
- package/dist/server/handlers/session-replay-lab.d.ts.map +1 -0
- package/dist/server/handlers/session-replay-lab.js +80 -0
- package/dist/server/handlers/session-replay-lab.js.map +1 -0
- package/dist/server/handlers/stats.js +1 -1
- package/dist/server/handlers/stats.js.map +1 -1
- package/dist/server/handlers/status.d.ts +44 -3
- package/dist/server/handlers/status.d.ts.map +1 -1
- package/dist/server/handlers/status.js +227 -17
- package/dist/server/handlers/status.js.map +1 -1
- package/dist/server/headless-runtime-service.d.ts +17 -0
- package/dist/server/headless-runtime-service.d.ts.map +1 -1
- package/dist/server/headless-runtime-service.js +143 -3
- package/dist/server/headless-runtime-service.js.map +1 -1
- package/dist/server/hosted-agent-runtime-progress.d.ts +17 -0
- package/dist/server/hosted-agent-runtime-progress.d.ts.map +1 -1
- package/dist/server/hosted-agent-runtime-progress.js +352 -15
- package/dist/server/hosted-agent-runtime-progress.js.map +1 -1
- package/dist/server/routes.d.ts.map +1 -1
- package/dist/server/routes.js +14 -0
- package/dist/server/routes.js.map +1 -1
- package/dist/services/intelligent-router/index.d.ts +1 -1
- package/dist/services/intelligent-router/index.d.ts.map +1 -1
- package/dist/services/intelligent-router/index.js +1 -1
- package/dist/services/intelligent-router/index.js.map +1 -1
- package/dist/services/intelligent-router/normalize.d.ts +10 -2
- package/dist/services/intelligent-router/normalize.d.ts.map +1 -1
- package/dist/services/intelligent-router/normalize.js +20 -1
- package/dist/services/intelligent-router/normalize.js.map +1 -1
- package/dist/services/intelligent-router/service.d.ts.map +1 -1
- package/dist/services/intelligent-router/service.js +35 -0
- package/dist/services/intelligent-router/service.js.map +1 -1
- package/dist/services/intelligent-router/types.d.ts +13 -0
- package/dist/services/intelligent-router/types.d.ts.map +1 -1
- package/dist/services/intelligent-router/types.js +1 -0
- package/dist/services/intelligent-router/types.js.map +1 -1
- package/dist/telemetry/cli-command-aggregator.d.ts +1 -0
- package/dist/telemetry/cli-command-aggregator.d.ts.map +1 -1
- package/dist/telemetry/cli-command-aggregator.js +23 -0
- package/dist/telemetry/cli-command-aggregator.js.map +1 -1
- package/dist/telemetry/maestro-event-bus.d.ts.map +1 -1
- package/dist/telemetry/maestro-event-bus.js +11 -5
- package/dist/telemetry/maestro-event-bus.js.map +1 -1
- package/dist/telemetry/maestro-event-catalog.d.ts +15 -1
- package/dist/telemetry/maestro-event-catalog.d.ts.map +1 -1
- package/dist/telemetry/maestro-event-catalog.js +30 -0
- package/dist/telemetry/maestro-event-catalog.js.map +1 -1
- package/dist/version.json +2 -2
- package/package.json +289 -283
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-context.js","sourceRoot":"","sources":["../../src/server/app-context.ts"],"names":[],"mappings":"","sourcesContent":["import type { IncomingMessage, ServerResponse } from \"node:http\";\nimport type {\n\tActionApprovalService,\n\tApprovalMode,\n} from \"../agent/action-approval.js\";\nimport type { Agent } from \"../agent/index.js\";\nimport type { ToolRetryService } from \"../agent/tool-retry.js\";\nimport type { ClientToolExecutionService } from \"../agent/transport.js\";\nimport type { ThinkingLevel } from \"../agent/types.js\";\nimport type { RegisteredModel } from \"../models/registry.js\";\nimport type { AuthCredential } from \"../providers/auth.js\";\nimport type { HeadlessRuntimeService } from \"./headless-runtime-service.js\";\nimport type { HostedRunnerLeaseSnapshot } from \"./hosted-runner-lease.js\";\n\nexport interface WebServerConfig {\n\tcorsHeaders: Record<string, string>;\n\tstaticMaxAge: number;\n\tdefaultApprovalMode: ApprovalMode;\n\tdefaultProvider: string;\n\tdefaultModelId: string;\n\thostedRunner?: HostedRunnerContext;\n}\n\nexport interface HostedRunnerContext {\n\tenabled: true;\n\trunnerSessionId: string;\n\townerInstanceId?: string;\n\tworkspaceRoot: string;\n\tsnapshotRoot?: string;\n\tlistenHost?: string;\n\tlistenPort?: number;\n\tworkspaceId?: string;\n\tagentId?: string;\n\tagentRunId?: string;\n\tagentRuntimeLeaseToken?: string;\n\ta2aMessageId?: string;\n\ta2aTaskId?: string;\n\tlastPlatformA2APush?: {\n\t\tkind: \"statusUpdate\" | \"artifactUpdate\" | \"task\" | \"message\";\n\t\ttaskId?: string;\n\t\tcontextId?: string;\n\t\tstate?: string;\n\t\tfinal?: boolean;\n\t\treceivedAt: string;\n\t\truntimeEventId?: string;\n\t\truntimeEventType?: string;\n\t};\n\tagentRuntimeWorkerQueue?: string;\n\tagentRuntimeCorrelationPath?: string;\n\tattachAudience?: string;\n\tconfiguredMaestroSessionId?: string;\n\tactiveMaestroSessionId?: string;\n\truntimeLease?: HostedRunnerLeaseSnapshot;\n\tdraining?: boolean;\n\tlastDrain?: {\n\t\tstatus: string;\n\t\tmanifestPath: string;\n\t\tdrainedAt: string;\n\t\treason?: string;\n\t\trequestedBy?: string;\n\t};\n}\n\nexport interface WebServerServices {\n\tcreateAgent: (\n\t\tmodel: RegisteredModel,\n\t\tthinking: ThinkingLevel,\n\t\tapproval: ApprovalMode,\n\t\toptions?: {\n\t\t\tcwd?: string;\n\t\t\tenableClientTools?: boolean;\n\t\t\tuseClientAskUser?: boolean;\n\t\t\tincludeVscodeTools?: boolean;\n\t\t\tincludeJetBrainsTools?: boolean;\n\t\t\tincludeConductorTools?: boolean;\n\t\t\tapprovalService?: ActionApprovalService;\n\t\t\tclientToolService?: ClientToolExecutionService;\n\t\t\ttoolRetryService?: ToolRetryService;\n\t\t},\n\t) => Promise<Agent>;\n\tcreateBackgroundAgent: (\n\t\tmodel: RegisteredModel,\n\t\toptions?: {\n\t\t\tcwd?: string;\n\t\t\tsystemPrompt?: string;\n\t\t},\n\t) => Promise<Agent>;\n\tgetRegisteredModel: (\n\t\tinput: string | null | undefined,\n\t) => Promise<RegisteredModel>;\n\tgetCurrentSelection: () => { provider: string; modelId: string };\n\tensureCredential: (provider: string) => Promise<AuthCredential>;\n\tsetModelSelection: (model: RegisteredModel) => void;\n\tacquireSse: () => symbol | null;\n\treleaseSse: (token: symbol | null) => void;\n\theadlessRuntimeService: HeadlessRuntimeService;\n}\n\nexport type WebServerContext = WebServerConfig & WebServerServices;\n"]}
|
|
1
|
+
{"version":3,"file":"app-context.js","sourceRoot":"","sources":["../../src/server/app-context.ts"],"names":[],"mappings":"","sourcesContent":["import type { IncomingMessage, ServerResponse } from \"node:http\";\nimport type {\n\tActionApprovalService,\n\tApprovalMode,\n} from \"../agent/action-approval.js\";\nimport type { Agent } from \"../agent/index.js\";\nimport type { ToolRetryService } from \"../agent/tool-retry.js\";\nimport type { ClientToolExecutionService } from \"../agent/transport.js\";\nimport type { ThinkingLevel } from \"../agent/types.js\";\nimport type { RegisteredModel } from \"../models/registry.js\";\nimport type { AuthCredential } from \"../providers/auth.js\";\nimport type { HeadlessRuntimeService } from \"./headless-runtime-service.js\";\nimport type { HostedRunnerLeaseSnapshot } from \"./hosted-runner-lease.js\";\n\nexport interface WebServerConfig {\n\tcorsHeaders: Record<string, string>;\n\tstaticMaxAge: number;\n\tdefaultApprovalMode: ApprovalMode;\n\tdefaultProvider: string;\n\tdefaultModelId: string;\n\thostedRunner?: HostedRunnerContext;\n}\n\nexport interface HostedRunnerContext {\n\tenabled: true;\n\trunnerSessionId: string;\n\townerInstanceId?: string;\n\tworkspaceRoot: string;\n\tsnapshotRoot?: string;\n\trestoreManifestPath?: string;\n\tlistenHost?: string;\n\tlistenPort?: number;\n\tworkspaceId?: string;\n\tagentId?: string;\n\tagentRunId?: string;\n\tagentRuntimeLeaseToken?: string;\n\ta2aMessageId?: string;\n\ta2aTaskId?: string;\n\tlastPlatformA2APush?: {\n\t\tkind: \"statusUpdate\" | \"artifactUpdate\" | \"task\" | \"message\";\n\t\ttaskId?: string;\n\t\tcontextId?: string;\n\t\tstate?: string;\n\t\tfinal?: boolean;\n\t\treceivedAt: string;\n\t\truntimeEventId?: string;\n\t\truntimeEventType?: string;\n\t};\n\tagentRuntimeWorkerQueue?: string;\n\tagentRuntimeCorrelationPath?: string;\n\tattachAudience?: string;\n\tconfiguredMaestroSessionId?: string;\n\tactiveMaestroSessionId?: string;\n\truntimeLease?: HostedRunnerLeaseSnapshot;\n\tdraining?: boolean;\n\tlastDrain?: {\n\t\tstatus: string;\n\t\tmanifestPath: string;\n\t\tdrainedAt: string;\n\t\treason?: string;\n\t\trequestedBy?: string;\n\t};\n}\n\nexport interface WebServerServices {\n\tcreateAgent: (\n\t\tmodel: RegisteredModel,\n\t\tthinking: ThinkingLevel,\n\t\tapproval: ApprovalMode,\n\t\toptions?: {\n\t\t\tcwd?: string;\n\t\t\tenableClientTools?: boolean;\n\t\t\tuseClientAskUser?: boolean;\n\t\t\tincludeVscodeTools?: boolean;\n\t\t\tincludeJetBrainsTools?: boolean;\n\t\t\tincludeConductorTools?: boolean;\n\t\t\tapprovalService?: ActionApprovalService;\n\t\t\tclientToolService?: ClientToolExecutionService;\n\t\t\ttoolRetryService?: ToolRetryService;\n\t\t},\n\t) => Promise<Agent>;\n\tcreateBackgroundAgent: (\n\t\tmodel: RegisteredModel,\n\t\toptions?: {\n\t\t\tcwd?: string;\n\t\t\tsystemPrompt?: string;\n\t\t},\n\t) => Promise<Agent>;\n\tgetRegisteredModel: (\n\t\tinput: string | null | undefined,\n\t) => Promise<RegisteredModel>;\n\tgetCurrentSelection: () => { provider: string; modelId: string };\n\tensureCredential: (provider: string) => Promise<AuthCredential>;\n\tsetModelSelection: (model: RegisteredModel) => void;\n\tacquireSse: () => symbol | null;\n\treleaseSse: (token: symbol | null) => void;\n\theadlessRuntimeService: HeadlessRuntimeService;\n}\n\nexport type WebServerContext = WebServerConfig & WebServerServices;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a2a-cockpit.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/a2a-cockpit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAUjE,wBAAsB,gBAAgB,CACrC,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACjC,OAAO,CAAC,IAAI,CAAC,CAsBf"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { buildA2ACockpit } from "../../platform/a2a-cockpit.js";
|
|
2
|
+
import { getVerifiedRequestPrincipal } from "../authz.js";
|
|
3
|
+
import { ApiError, respondWithApiError, sendJson } from "../server-utils.js";
|
|
4
|
+
import { resolveSessionScope } from "../session-scope.js";
|
|
5
|
+
const DEFAULT_WEB_A2A_COCKPIT_TIMEOUT_MS = 2_500;
|
|
6
|
+
const MAX_WEB_A2A_COCKPIT_TIMEOUT_MS = 10_000;
|
|
7
|
+
export async function handleA2ACockpit(req, res, corsHeaders) {
|
|
8
|
+
try {
|
|
9
|
+
if (req.method !== "GET") {
|
|
10
|
+
throw new ApiError(405, "Method not allowed");
|
|
11
|
+
}
|
|
12
|
+
const url = new URL(req.url ?? "/api/a2a/cockpit", "http://localhost");
|
|
13
|
+
rejectHostedPathOverrides(url);
|
|
14
|
+
const cockpit = await buildA2ACockpit({
|
|
15
|
+
registryPath: undefined,
|
|
16
|
+
tasksPath: undefined,
|
|
17
|
+
timeoutMs: positiveIntegerQuery(url, "timeoutMs", {
|
|
18
|
+
max: MAX_WEB_A2A_COCKPIT_TIMEOUT_MS,
|
|
19
|
+
}) ?? DEFAULT_WEB_A2A_COCKPIT_TIMEOUT_MS,
|
|
20
|
+
peer: optionalQueryString(url, "peer"),
|
|
21
|
+
limit: positiveIntegerQuery(url, "limit"),
|
|
22
|
+
ownershipScope: ownershipScopeForRequest(req),
|
|
23
|
+
});
|
|
24
|
+
sendJson(res, 200, cockpit, corsHeaders, req);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
respondWithApiError(res, error, 500, corsHeaders, req);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function ownershipScopeForRequest(req) {
|
|
31
|
+
const principal = getVerifiedRequestPrincipal(req);
|
|
32
|
+
const scopeKey = resolveSessionScope(req) ??
|
|
33
|
+
(principal?.authMethod !== "anon" ? principal?.scopeKey : undefined);
|
|
34
|
+
if (!scopeKey) {
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
scopeKey,
|
|
39
|
+
...(principal?.subject ? { subject: principal.subject } : {}),
|
|
40
|
+
...(principal?.userId ? { userId: principal.userId } : {}),
|
|
41
|
+
...(principal?.keyId ? { keyId: principal.keyId } : {}),
|
|
42
|
+
...(principal?.workspaceId ? { workspaceId: principal.workspaceId } : {}),
|
|
43
|
+
...(principal?.orgId ? { orgId: principal.orgId } : {}),
|
|
44
|
+
...(principal?.teamId ? { teamId: principal.teamId } : {}),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function rejectHostedPathOverrides(url) {
|
|
48
|
+
const blockedParams = ["registry", "tasks"].filter((key) => url.searchParams.has(key));
|
|
49
|
+
if (blockedParams.length > 0) {
|
|
50
|
+
throw new ApiError(400, `${blockedParams.join(", ")} query parameter${blockedParams.length === 1 ? " is" : "s are"} not supported by the hosted A2A cockpit`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function optionalQueryString(url, key) {
|
|
54
|
+
const value = url.searchParams.get(key)?.trim();
|
|
55
|
+
return value ? value : undefined;
|
|
56
|
+
}
|
|
57
|
+
function positiveIntegerQuery(url, key, options = {}) {
|
|
58
|
+
const value = optionalQueryString(url, key);
|
|
59
|
+
if (!value) {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
const parsed = Number(value);
|
|
63
|
+
if (!Number.isInteger(parsed) || parsed <= 0) {
|
|
64
|
+
throw new ApiError(400, `${key} must be a positive integer`);
|
|
65
|
+
}
|
|
66
|
+
if (options.max !== undefined && parsed > options.max) {
|
|
67
|
+
throw new ApiError(400, `${key} must be at most ${options.max}`);
|
|
68
|
+
}
|
|
69
|
+
return parsed;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=a2a-cockpit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"a2a-cockpit.js","sourceRoot":"","sources":["../../../src/server/handlers/a2a-cockpit.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,MAAM,kCAAkC,GAAG,KAAK,CAAC;AACjD,MAAM,8BAA8B,GAAG,MAAM,CAAC;AAE9C,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACrC,GAAoB,EACpB,GAAmB,EACnB,WAAmC;IAEnC,IAAI,CAAC;QACJ,IAAI,GAAG,CAAC,MAAM,KAAK,KAAK,EAAE,CAAC;YAC1B,MAAM,IAAI,QAAQ,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAC;QAC/C,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,GAA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ChD,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAClC,CAAC;AAED,SAAS,oBAAoB,CAC5B,GAAQ,EACR,GAAW,EACX,UAA4B,EAAE;IAE9B,MAAM,KAAK,GAAG,mBAAmB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC5C,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,6BAA6B,CAAC,CAAC;IAC9D,CAAC;IACD,IAAI,OAAO,CAAC,GAAG,KAAK,SAAS,IAAI,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;QACvD,MAAM,IAAI,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,oBAAoB,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import type { IncomingMessage, ServerResponse } from \"node:http\";\nimport { buildA2ACockpit } from \"../../platform/a2a-cockpit.js\";\nimport type { A2AOwnershipScope } from \"../../platform/a2a-ownership.js\";\nimport { getVerifiedRequestPrincipal } from \"../authz.js\";\nimport { ApiError, respondWithApiError, sendJson } from \"../server-utils.js\";\nimport { resolveSessionScope } from \"../session-scope.js\";\n\nconst DEFAULT_WEB_A2A_COCKPIT_TIMEOUT_MS = 2_500;\nconst MAX_WEB_A2A_COCKPIT_TIMEOUT_MS = 10_000;\n\nexport async function handleA2ACockpit(\n\treq: IncomingMessage,\n\tres: ServerResponse,\n\tcorsHeaders: Record<string, string>,\n): Promise<void> {\n\ttry {\n\t\tif (req.method !== \"GET\") {\n\t\t\tthrow new ApiError(405, \"Method not allowed\");\n\t\t}\n\t\tconst url = new URL(req.url ?? \"/api/a2a/cockpit\", \"http://localhost\");\n\t\trejectHostedPathOverrides(url);\n\t\tconst cockpit = await buildA2ACockpit({\n\t\t\tregistryPath: undefined,\n\t\t\ttasksPath: undefined,\n\t\t\ttimeoutMs:\n\t\t\t\tpositiveIntegerQuery(url, \"timeoutMs\", {\n\t\t\t\t\tmax: MAX_WEB_A2A_COCKPIT_TIMEOUT_MS,\n\t\t\t\t}) ?? DEFAULT_WEB_A2A_COCKPIT_TIMEOUT_MS,\n\t\t\tpeer: optionalQueryString(url, \"peer\"),\n\t\t\tlimit: positiveIntegerQuery(url, \"limit\"),\n\t\t\townershipScope: ownershipScopeForRequest(req),\n\t\t});\n\t\tsendJson(res, 200, cockpit, corsHeaders, req);\n\t} catch (error) {\n\t\trespondWithApiError(res, error, 500, corsHeaders, req);\n\t}\n}\n\nfunction ownershipScopeForRequest(\n\treq: IncomingMessage,\n): A2AOwnershipScope | undefined {\n\tconst principal = getVerifiedRequestPrincipal(req);\n\tconst scopeKey =\n\t\tresolveSessionScope(req) ??\n\t\t(principal?.authMethod !== \"anon\" ? principal?.scopeKey : undefined);\n\tif (!scopeKey) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\tscopeKey,\n\t\t...(principal?.subject ? { subject: principal.subject } : {}),\n\t\t...(principal?.userId ? { userId: principal.userId } : {}),\n\t\t...(principal?.keyId ? { keyId: principal.keyId } : {}),\n\t\t...(principal?.workspaceId ? { workspaceId: principal.workspaceId } : {}),\n\t\t...(principal?.orgId ? { orgId: principal.orgId } : {}),\n\t\t...(principal?.teamId ? { teamId: principal.teamId } : {}),\n\t};\n}\n\nfunction rejectHostedPathOverrides(url: URL): void {\n\tconst blockedParams = [\"registry\", \"tasks\"].filter((key) =>\n\t\turl.searchParams.has(key),\n\t);\n\tif (blockedParams.length > 0) {\n\t\tthrow new ApiError(\n\t\t\t400,\n\t\t\t`${blockedParams.join(\", \")} query parameter${\n\t\t\t\tblockedParams.length === 1 ? \" is\" : \"s are\"\n\t\t\t} not supported by the hosted A2A cockpit`,\n\t\t);\n\t}\n}\n\nfunction optionalQueryString(url: URL, key: string): string | undefined {\n\tconst value = url.searchParams.get(key)?.trim();\n\treturn value ? value : undefined;\n}\n\nfunction positiveIntegerQuery(\n\turl: URL,\n\tkey: string,\n\toptions: { max?: number } = {},\n): number | undefined {\n\tconst value = optionalQueryString(url, key);\n\tif (!value) {\n\t\treturn undefined;\n\t}\n\tconst parsed = Number(value);\n\tif (!Number.isInteger(parsed) || parsed <= 0) {\n\t\tthrow new ApiError(400, `${key} must be a positive integer`);\n\t}\n\tif (options.max !== undefined && parsed > options.max) {\n\t\tthrow new ApiError(400, `${key} must be at most ${options.max}`);\n\t}\n\treturn parsed;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headless-sessions.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/headless-sessions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"headless-sessions.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/headless-sessions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAmBjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AA4B1D,oBAAY,qBAAqB;IAChC,eAAe,sBAAsB;IACrC,qBAAqB,4BAA4B;CACjD;AA+rBD,wBAAsB,2BAA2B,CAChD,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,OAAO,EAAE,gBAAgB,iBAQzB;AAED,wBAAsB,8BAA8B,CACnD,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,OAAO,EAAE,gBAAgB,iBAazB;AAED,wBAAgB,0BAA0B,CACzC,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,OAAO,EAAE,gBAAgB,EACzB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,QAI/B;AAED,wBAAsB,8BAA8B,CACnD,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,OAAO,EAAE,gBAAgB,EACzB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,iBAyD/B;AAED,wBAAsB,gCAAgC,CACrD,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,OAAO,EAAE,gBAAgB,EACzB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,iBAW/B;AAED,wBAAsB,8BAA8B,CACnD,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,OAAO,EAAE,gBAAgB,EACzB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,iBAiB/B;AAED,wBAAsB,+BAA+B,CACpD,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,OAAO,EAAE,gBAAgB,EACzB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,iBAqB/B;AAED,wBAAgB,2BAA2B,CAC1C,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,OAAO,EAAE,gBAAgB,EACzB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,QAsE/B;AAED,wBAAsB,4BAA4B,CACjD,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,cAAc,EACnB,OAAO,EAAE,gBAAgB,EACzB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,iBAsB/B"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
1
2
|
import { headlessApprovalModes, headlessConnectionRoles, headlessNotificationTypes, headlessServerRequestTypes, headlessThinkingLevels, headlessToAgentMessageSchemasByType, headlessToAgentMessageTypes, headlessUtilityOperations, } from "@evalops/contracts";
|
|
2
3
|
import { Type } from "@sinclair/typebox";
|
|
3
4
|
import { resolveExistingWorkspaceRoot } from "../../headless/workspace-root.js";
|
|
4
5
|
import { recordMaestroSessionRuntimeTrigger } from "../../platform/agent-runtime-client.js";
|
|
5
6
|
import { normalizeApprovalMode, resolveApprovalModeForRequest, } from "../approval-mode-store.js";
|
|
6
7
|
import { getAuthScopeKey, getAuthSubject } from "../authz.js";
|
|
8
|
+
import { loadHostedRunnerRestoreManifest } from "../headless-runtime-service.js";
|
|
7
9
|
import { bindHostedRunnerPlatformLease, claimHostedRunnerLease, evaluateHostedRunnerLeaseUse, } from "../hosted-runner-lease.js";
|
|
8
10
|
import { getTraceParentHeader } from "../request-context.js";
|
|
9
11
|
import { ApiError, getRequestHeader, readRequestBody, sendJson, } from "../server-utils.js";
|
|
@@ -293,11 +295,24 @@ function rethrowHeadlessConnectionLifecycleError(error) {
|
|
|
293
295
|
async function ensureRuntime(req, context, input) {
|
|
294
296
|
const sessionManager = createSessionManagerForRequest(req, false);
|
|
295
297
|
const role = getHeadlessRole(req, input.role);
|
|
296
|
-
const
|
|
298
|
+
const hostedRestoreSessionId = context.hostedRunner?.restoreManifestPath
|
|
299
|
+
? (context.hostedRunner.activeMaestroSessionId ??
|
|
300
|
+
context.hostedRunner.configuredMaestroSessionId)
|
|
301
|
+
: undefined;
|
|
302
|
+
const requestedSessionId = input.sessionId?.trim() || hostedRestoreSessionId || undefined;
|
|
297
303
|
const workspaceRoot = resolveRuntimeWorkspaceRoot(context, input.workspaceRoot);
|
|
298
304
|
ensureHostedRunnerCanUseSession(context, requestedSessionId);
|
|
299
305
|
if (requestedSessionId) {
|
|
300
|
-
|
|
306
|
+
let sessionFile = sessionManager.getSessionFileById(requestedSessionId);
|
|
307
|
+
if (!sessionFile && context.hostedRunner?.restoreManifestPath) {
|
|
308
|
+
const restoreManifest = await loadHostedRunnerRestoreManifest(context.hostedRunner.restoreManifestPath);
|
|
309
|
+
const restoreSessionFile = restoreManifest?.maestro_session_id === requestedSessionId
|
|
310
|
+
? restoreManifest.runtime.session_file
|
|
311
|
+
: undefined;
|
|
312
|
+
if (restoreSessionFile && existsSync(restoreSessionFile)) {
|
|
313
|
+
sessionFile = restoreSessionFile;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
301
316
|
if (!sessionFile) {
|
|
302
317
|
throw new ApiError(404, "Session not found");
|
|
303
318
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"headless-sessions.js","sourceRoot":"","sources":["../../../src/server/handlers/headless-sessions.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,qBAAqB,EACrB,uBAAuB,EACvB,yBAAyB,EACzB,0BAA0B,EAC1B,sBAAsB,EACtB,mCAAmC,EACnC,2BAA2B,EAC3B,yBAAyB,GACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAA6B,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAIpE,OAAO,EAAE,4BAA4B,EAAE,MAAM,kCAAkC,CAAC;AAEhF,OAAO,EAAE,kCAAkC,EAAE,MAAM,wCAAwC,CAAC;AAE5F,OAAO,EACN,qBAAqB,EACrB,6BAA6B,GAC7B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAO9D,OAAO,EACN,6BAA6B,EAC7B,sBAAsB,EACtB,4BAA4B,GAC5B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EACN,QAAQ,EACR,gBAAgB,EAChB,eAAe,EACf,QAAQ,GACR,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEzE,MAAM,CAAN,IAAY,qBAGX;AAHD,WAAY,qBAAqB;IAChC,8DAAqC,CAA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B,CACjD,GAAoB,EACpB,GAAmB,EACnB,OAAyB,EACzB,MAA+B;IAE/B,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;IACrD,MAAM,KAAK,GAAG,MAAM,oBAAoB,CAAC,GAAG,CAAC,CAAC;IAC9C,IAAI,CAAC;QACJ,OAAO,CAAC,aAAa,CACpB,eAAe,CAAC,GAAG,CAAC,EACpB,uBAAuB,CAAC,GAAG,CAAC,EAC5B,uBAAuB,CAAC,GAAG,CAAC,CAC5B,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,2BAA2B,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IACD,IAAI,CAAC;QACJ,MAAM,OAAO,CAAC,IAAI,CAAC,KAA+B,EAAE;YACnD,YAAY,EAAE,uBAAuB,CAAC,GAAG,CAAC;YAC1C,cAAc,EAAE,uBAAuB,CAAC,GAAG,CAAC;SAC5C,CAAC,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,2BAA2B,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IACD,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import type { IncomingMessage, ServerResponse } from \"node:http\";\nimport {\n\ttype HeadlessConnectionRole,\n\theadlessApprovalModes,\n\theadlessConnectionRoles,\n\theadlessNotificationTypes,\n\theadlessServerRequestTypes,\n\theadlessThinkingLevels,\n\theadlessToAgentMessageSchemasByType,\n\theadlessToAgentMessageTypes,\n\theadlessUtilityOperations,\n} from \"@evalops/contracts\";\nimport { type Static, type TSchema, Type } from \"@sinclair/typebox\";\nimport type { ApprovalMode } from \"../../agent/action-approval.js\";\nimport type { ThinkingLevel } from \"../../agent/types.js\";\nimport type { HeadlessToAgentMessage } from \"../../cli/headless-protocol.js\";\nimport { resolveExistingWorkspaceRoot } from \"../../headless/workspace-root.js\";\nimport type { RegisteredModel } from \"../../models/registry.js\";\nimport { recordMaestroSessionRuntimeTrigger } from \"../../platform/agent-runtime-client.js\";\nimport type { WebServerContext } from \"../app-context.js\";\nimport {\n\tnormalizeApprovalMode,\n\tresolveApprovalModeForRequest,\n} from \"../approval-mode-store.js\";\nimport { getAuthScopeKey, getAuthSubject } from \"../authz.js\";\nimport type {\n\tHeadlessRuntimeConnectionSnapshot,\n\tHeadlessRuntimeHeartbeatSnapshot,\n\tHeadlessRuntimeStreamEnvelope,\n\tHeadlessSessionRuntime,\n} from \"../headless-runtime-service.js\";\nimport {\n\tbindHostedRunnerPlatformLease,\n\tclaimHostedRunnerLease,\n\tevaluateHostedRunnerLeaseUse,\n} from \"../hosted-runner-lease.js\";\nimport { getTraceParentHeader } from \"../request-context.js\";\nimport {\n\tApiError,\n\tgetRequestHeader,\n\treadRequestBody,\n\tsendJson,\n} from \"../server-utils.js\";\nimport { createSessionManagerForRequest } from \"../session-scope.js\";\nimport { parseAndValidateJson, validatePayload } from \"../validation.js\";\n\nexport enum HostedRunnerErrorType {\n\tRuntimeNotReady = \"runtime_not_ready\",\n\tRuntimeOwnedElsewhere = \"runtime_owned_elsewhere\",\n}\n\nconst HOSTED_RUNNER_ERROR_DOMAIN = \"maestro.hosted_runner\";\n\nfunction stringLiteralUnion<const T extends readonly string[]>(values: T) {\n\treturn Type.Unsafe<T[number]>(\n\t\tType.Union(\n\t\t\tvalues.map((value) => Type.Literal(value)) as unknown as [\n\t\t\t\tTSchema,\n\t\t\t\t...TSchema[],\n\t\t\t],\n\t\t),\n\t);\n}\n\nconst HeadlessOptOutNotificationsSchema = Type.Array(\n\tstringLiteralUnion(headlessNotificationTypes),\n\t{\n\t\tuniqueItems: true,\n\t},\n);\n\nconst HeadlessCreateBaseProperties = {\n\tsessionId: Type.Optional(Type.String()),\n\tprotocolVersion: Type.Optional(Type.String()),\n\tclientInfo: Type.Optional(\n\t\tType.Object({\n\t\t\tname: Type.String(),\n\t\t\tversion: Type.Optional(Type.String()),\n\t\t}),\n\t),\n\tworkspaceRoot: Type.Optional(Type.String()),\n\tmodel: Type.Optional(Type.String()),\n\tenableClientTools: Type.Optional(Type.Boolean()),\n\tcapabilities: Type.Optional(\n\t\tType.Object({\n\t\t\tserverRequests: Type.Optional(\n\t\t\t\tType.Array(stringLiteralUnion(headlessServerRequestTypes), {\n\t\t\t\t\tuniqueItems: true,\n\t\t\t\t}),\n\t\t\t),\n\t\t\tutilityOperations: Type.Optional(\n\t\t\t\tType.Array(stringLiteralUnion(headlessUtilityOperations), {\n\t\t\t\t\tuniqueItems: true,\n\t\t\t\t}),\n\t\t\t),\n\t\t\trawAgentEvents: Type.Optional(Type.Boolean()),\n\t\t}),\n\t),\n\toptOutNotifications: Type.Optional(HeadlessOptOutNotificationsSchema),\n\trole: Type.Optional(stringLiteralUnion(headlessConnectionRoles)),\n\tclient: Type.Optional(\n\t\tType.Union([\n\t\t\tType.Literal(\"generic\"),\n\t\t\tType.Literal(\"vscode\"),\n\t\t\tType.Literal(\"jetbrains\"),\n\t\t\tType.Literal(\"conductor\"),\n\t\t]),\n\t),\n\tthinkingLevel: Type.Optional(stringLiteralUnion(headlessThinkingLevels)),\n\tapprovalMode: Type.Optional(stringLiteralUnion(headlessApprovalModes)),\n} as const;\n\nconst HeadlessSessionCreateSchema = Type.Object(HeadlessCreateBaseProperties);\n\nconst HeadlessConnectionCreateSchema = Type.Object({\n\t...HeadlessCreateBaseProperties,\n\tconnectionId: Type.Optional(Type.String()),\n\ttakeControl: Type.Optional(Type.Boolean()),\n});\n\nconst HeadlessMessageTypeSchema = Type.Object(\n\t{\n\t\ttype: stringLiteralUnion(headlessToAgentMessageTypes),\n\t},\n\t{ additionalProperties: true },\n);\n\nconst HeadlessSessionSubscribeSchema = Type.Object({\n\tconnectionId: Type.Optional(Type.String()),\n\tprotocolVersion: Type.Optional(Type.String()),\n\tclientInfo: Type.Optional(\n\t\tType.Object({\n\t\t\tname: Type.String(),\n\t\t\tversion: Type.Optional(Type.String()),\n\t\t}),\n\t),\n\tcapabilities: Type.Optional(\n\t\tType.Object({\n\t\t\tserverRequests: Type.Optional(\n\t\t\t\tType.Array(stringLiteralUnion(headlessServerRequestTypes), {\n\t\t\t\t\tuniqueItems: true,\n\t\t\t\t}),\n\t\t\t),\n\t\t\tutilityOperations: Type.Optional(\n\t\t\t\tType.Array(stringLiteralUnion(headlessUtilityOperations), {\n\t\t\t\t\tuniqueItems: true,\n\t\t\t\t}),\n\t\t\t),\n\t\t\trawAgentEvents: Type.Optional(Type.Boolean()),\n\t\t}),\n\t),\n\toptOutNotifications: Type.Optional(HeadlessOptOutNotificationsSchema),\n\trole: Type.Optional(stringLiteralUnion(headlessConnectionRoles)),\n\ttakeControl: Type.Optional(Type.Boolean()),\n});\n\nconst HeadlessSessionUnsubscribeSchema = Type.Object({\n\tsubscriptionId: Type.String(),\n});\n\nconst HeadlessSessionHeartbeatSchema = Type.Object({\n\tconnectionId: Type.Optional(Type.String()),\n\tsubscriptionId: Type.Optional(Type.String()),\n});\n\nconst HeadlessSessionDisconnectSchema = Type.Object({\n\tconnectionId: Type.Optional(Type.String()),\n\tsubscriptionId: Type.Optional(Type.String()),\n});\n\ntype HeadlessSessionCreateInput = Static<typeof HeadlessSessionCreateSchema>;\ntype HeadlessConnectionCreateInput = Static<\n\ttypeof HeadlessConnectionCreateSchema\n>;\ntype HeadlessSessionSubscribeInput = Static<\n\ttypeof HeadlessSessionSubscribeSchema\n>;\ntype HeadlessSessionUnsubscribeInput = Static<\n\ttypeof HeadlessSessionUnsubscribeSchema\n>;\ntype HeadlessSessionHeartbeatInput = Static<\n\ttypeof HeadlessSessionHeartbeatSchema\n>;\ntype HeadlessSessionDisconnectInput = Static<\n\ttypeof HeadlessSessionDisconnectSchema\n>;\ntype HeadlessMessageTypeInput = Static<typeof HeadlessMessageTypeSchema>;\n\nasync function parseHeadlessMessage(\n\treq: IncomingMessage,\n): Promise<HeadlessToAgentMessage> {\n\tconst raw = await readRequestBody(req);\n\tif (!raw.length) {\n\t\tthrow new ApiError(400, \"Request body required\");\n\t}\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(raw.toString());\n\t} catch {\n\t\tthrow new ApiError(400, \"Invalid JSON payload\");\n\t}\n\tconst envelope = validatePayload<HeadlessMessageTypeInput>(\n\t\tparsed,\n\t\tHeadlessMessageTypeSchema,\n\t\t\"body\",\n\t);\n\treturn validatePayload<HeadlessToAgentMessage>(\n\t\tparsed,\n\t\theadlessToAgentMessageSchemasByType[envelope.type],\n\t\t\"body\",\n\t);\n}\n\nfunction getHeadlessRole(\n\treq: IncomingMessage,\n\texplicitRole?: HeadlessConnectionRole,\n): HeadlessConnectionRole {\n\tif (explicitRole) {\n\t\treturn explicitRole;\n\t}\n\tconst headerRole = getRequestHeader(\n\t\treq,\n\t\t\"x-composer-headless-role\",\n\t\t\"x-maestro-headless-role\",\n\t);\n\treturn headerRole === \"viewer\" ? \"viewer\" : \"controller\";\n}\n\nfunction getViewerDisallowedServerRequest(\n\tserverRequests?: Static<\n\t\ttypeof HeadlessCreateBaseProperties.capabilities\n\t>[\"serverRequests\"],\n): \"mcp_elicitation\" | \"user_input\" | undefined {\n\tif (serverRequests?.includes(\"mcp_elicitation\")) {\n\t\treturn \"mcp_elicitation\";\n\t}\n\tif (serverRequests?.includes(\"user_input\")) {\n\t\treturn \"user_input\";\n\t}\n\treturn undefined;\n}\n\nfunction writeSse(res: ServerResponse, payload: unknown): boolean {\n\treturn res.write(`data: ${JSON.stringify(payload)}\\n\\n`);\n}\n\nfunction getHeadlessSubscriberId(req: IncomingMessage): string | undefined {\n\treturn (\n\t\tgetRequestHeader(\n\t\t\treq,\n\t\t\t\"x-composer-headless-subscriber-id\",\n\t\t\t\"x-maestro-headless-subscriber-id\",\n\t\t) ?? undefined\n\t);\n}\n\nfunction getHeadlessConnectionId(req: IncomingMessage): string | undefined {\n\treturn (\n\t\tgetRequestHeader(\n\t\t\treq,\n\t\t\t\"x-composer-headless-connection-id\",\n\t\t\t\"x-maestro-headless-connection-id\",\n\t\t) ?? undefined\n\t);\n}\n\nfunction parseOptOutNotifications(\n\treq: IncomingMessage,\n): HeadlessSessionSubscribeInput[\"optOutNotifications\"] {\n\tconst url = new URL(\n\t\treq.url || \"/\",\n\t\t`http://${req.headers.host || \"localhost\"}`,\n\t);\n\tconst raw = url.searchParams.get(\"optOutNotifications\");\n\tif (!raw) {\n\t\treturn undefined;\n\t}\n\tconst notifications = raw\n\t\t.split(\",\")\n\t\t.map((value) => value.trim())\n\t\t.filter(Boolean);\n\tif (notifications.length === 0) {\n\t\treturn undefined;\n\t}\n\treturn validatePayload<\n\t\tNonNullable<HeadlessSessionSubscribeInput[\"optOutNotifications\"]>\n\t>(\n\t\tnotifications,\n\t\tHeadlessOptOutNotificationsSchema,\n\t\t\"query.optOutNotifications\",\n\t);\n}\n\nfunction getScopeKey(req: IncomingMessage): string {\n\treturn getAuthScopeKey(req);\n}\n\nfunction hostedRunnerErrorMetadata(\n\tcontext: WebServerContext,\n\tmetadata: Record<string, string | undefined>,\n): Record<string, string> {\n\tconst hostedRunner = context.hostedRunner;\n\tconst detailMetadata: Record<string, string> = {};\n\tfor (const [key, value] of Object.entries({\n\t\trunner_session_id: hostedRunner?.runnerSessionId,\n\t\towner_instance_id: hostedRunner?.ownerInstanceId,\n\t\tworkspace_id: hostedRunner?.workspaceId,\n\t\tagent_run_id: hostedRunner?.agentRunId,\n\t\t...metadata,\n\t})) {\n\t\tif (value) {\n\t\t\tdetailMetadata[key] = value;\n\t\t}\n\t}\n\treturn detailMetadata;\n}\n\nfunction hostedRunnerOwnershipError(\n\tcontext: WebServerContext,\n\tmessage: string,\n\tmetadata: Record<string, string | undefined>,\n): ApiError {\n\treturn new ApiError(\n\t\t409,\n\t\tmessage,\n\t\t[\n\t\t\t{\n\t\t\t\treason: HostedRunnerErrorType.RuntimeOwnedElsewhere,\n\t\t\t\tdomain: HOSTED_RUNNER_ERROR_DOMAIN,\n\t\t\t\tmetadata: hostedRunnerErrorMetadata(context, metadata),\n\t\t\t},\n\t\t],\n\t\tHostedRunnerErrorType.RuntimeOwnedElsewhere,\n\t);\n}\n\nfunction hostedRunnerNotReadyError(\n\tcontext: WebServerContext,\n\tmessage: string,\n\tmetadata: Record<string, string | undefined>,\n): ApiError {\n\treturn new ApiError(\n\t\t503,\n\t\tmessage,\n\t\t[\n\t\t\t{\n\t\t\t\treason: HostedRunnerErrorType.RuntimeNotReady,\n\t\t\t\tdomain: HOSTED_RUNNER_ERROR_DOMAIN,\n\t\t\t\tmetadata: hostedRunnerErrorMetadata(context, metadata),\n\t\t\t},\n\t\t],\n\t\tHostedRunnerErrorType.RuntimeNotReady,\n\t);\n}\n\nfunction ensureHostedRunnerCanUseSession(\n\tcontext: WebServerContext,\n\trequestedSessionId: string | undefined,\n): void {\n\tconst hostedRunner = context.hostedRunner;\n\tif (!hostedRunner) {\n\t\treturn;\n\t}\n\tconst decision = evaluateHostedRunnerLeaseUse(\n\t\thostedRunner,\n\t\trequestedSessionId,\n\t);\n\tif (decision.ok) {\n\t\treturn;\n\t}\n\tif (decision.reason === \"runtime_draining\") {\n\t\tthrow hostedRunnerNotReadyError(context, decision.message, {\n\t\t\tdraining: \"true\",\n\t\t\tmaestro_session_id: decision.activeSessionId,\n\t\t\trequested_maestro_session_id: requestedSessionId,\n\t\t\tlease_generation: String(decision.snapshot.generation),\n\t\t});\n\t}\n\tthrow hostedRunnerOwnershipError(context, decision.message, {\n\t\tmaestro_session_id: decision.activeSessionId,\n\t\trequested_maestro_session_id: decision.requestedSessionId,\n\t\tlease_generation: String(decision.snapshot.generation),\n\t});\n}\n\nfunction claimHostedRunnerSession(\n\tcontext: WebServerContext,\n\tsessionId: string,\n): void {\n\tconst hostedRunner = context.hostedRunner;\n\tif (!hostedRunner) {\n\t\treturn;\n\t}\n\tconst decision = claimHostedRunnerLease(hostedRunner, sessionId);\n\tif (!decision.ok) {\n\t\tif (decision.reason === \"runtime_draining\") {\n\t\t\tthrow hostedRunnerNotReadyError(context, decision.message, {\n\t\t\t\tdraining: \"true\",\n\t\t\t\tmaestro_session_id: decision.activeSessionId,\n\t\t\t\trequested_maestro_session_id: decision.requestedSessionId ?? sessionId,\n\t\t\t\tlease_generation: String(decision.snapshot.generation),\n\t\t\t});\n\t\t}\n\t\tthrow hostedRunnerOwnershipError(context, decision.message, {\n\t\t\tmaestro_session_id: decision.activeSessionId,\n\t\t\trequested_maestro_session_id: decision.requestedSessionId ?? sessionId,\n\t\t\tlease_generation: String(decision.snapshot.generation),\n\t\t});\n\t}\n}\n\nfunction resolveRuntimeWorkspaceRoot(\n\tcontext: WebServerContext,\n\tworkspaceRoot: string | undefined,\n): string | undefined {\n\tconst requestedRoot = workspaceRoot?.trim() || undefined;\n\tconst hostedRoot = context.hostedRunner?.workspaceRoot?.trim() || undefined;\n\n\tlet resolvedRequestedRoot: string | undefined;\n\tif (requestedRoot) {\n\t\ttry {\n\t\t\tresolvedRequestedRoot = resolveExistingWorkspaceRoot(requestedRoot);\n\t\t} catch {\n\t\t\tthrow new ApiError(400, `workspaceRoot not found: ${requestedRoot}`);\n\t\t}\n\t}\n\n\tlet resolvedHostedRoot: string | undefined;\n\tif (hostedRoot) {\n\t\ttry {\n\t\t\tresolvedHostedRoot = resolveExistingWorkspaceRoot(hostedRoot);\n\t\t} catch {\n\t\t\tthrow new ApiError(\n\t\t\t\t500,\n\t\t\t\t`Hosted runner workspace root is unavailable: ${hostedRoot}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (\n\t\tresolvedRequestedRoot &&\n\t\tresolvedHostedRoot &&\n\t\tresolvedRequestedRoot !== resolvedHostedRoot\n\t) {\n\t\tthrow new ApiError(\n\t\t\t409,\n\t\t\t`workspaceRoot must match hosted runner workspace root: ${resolvedHostedRoot}`,\n\t\t);\n\t}\n\n\treturn resolvedHostedRoot ?? resolvedRequestedRoot;\n}\n\nfunction rethrowHeadlessMessageError(error: unknown): never {\n\tif (!(error instanceof Error)) {\n\t\tthrow error;\n\t}\n\tif (error.message === \"Viewer headless connections cannot send messages\") {\n\t\tthrow new ApiError(403, error.message);\n\t}\n\tif (error.message === \"Headless subscriber not found\") {\n\t\tthrow new ApiError(404, error.message);\n\t}\n\tif (\n\t\terror.message === \"Headless connection not found\" ||\n\t\terror.message === \"Headless connection does not have controller access\" ||\n\t\terror.message.includes(\"is owned by another connection\")\n\t) {\n\t\tthrow new ApiError(403, error.message);\n\t}\n\tif (error.message.includes(\"Controller lease\")) {\n\t\tthrow new ApiError(409, error.message);\n\t}\n\tthrow new ApiError(403, error.message);\n}\n\nfunction rethrowHeadlessConnectionLifecycleError(error: unknown): never {\n\tif (!(error instanceof Error)) {\n\t\tthrow error;\n\t}\n\tif (error.message === \"Headless connection not found\") {\n\t\tthrow new ApiError(404, error.message);\n\t}\n\tif (\n\t\terror.message.includes(\"Controller lease\") ||\n\t\terror.message ===\n\t\t\t\"Headless connection role does not match subscription role\"\n\t) {\n\t\tthrow new ApiError(409, error.message);\n\t}\n\tthrow error;\n}\n\nasync function ensureRuntime(\n\treq: IncomingMessage,\n\tcontext: WebServerContext,\n\tinput: HeadlessSessionCreateInput & {\n\t\tregisterConnection?: boolean;\n\t\trecordAgentRuntimeTrigger?: boolean;\n\t},\n) {\n\tconst sessionManager = createSessionManagerForRequest(req, false);\n\tconst role = getHeadlessRole(req, input.role);\n\tconst requestedSessionId = input.sessionId?.trim() || undefined;\n\tconst workspaceRoot = resolveRuntimeWorkspaceRoot(\n\t\tcontext,\n\t\tinput.workspaceRoot,\n\t);\n\tensureHostedRunnerCanUseSession(context, requestedSessionId);\n\tif (requestedSessionId) {\n\t\tconst sessionFile = sessionManager.getSessionFileById(requestedSessionId);\n\t\tif (!sessionFile) {\n\t\t\tthrow new ApiError(404, \"Session not found\");\n\t\t}\n\t\tsessionManager.setSessionFile(sessionFile);\n\t}\n\n\tconst registeredModel = await context.getRegisteredModel(input.model);\n\tconst subject = getAuthSubject(req);\n\tif (\n\t\tinput.enableClientTools &&\n\t\t!input.capabilities?.serverRequests?.includes(\"client_tool\")\n\t) {\n\t\tthrow new ApiError(\n\t\t\t400,\n\t\t\t\"client_tool capability is required when enableClientTools is true\",\n\t\t);\n\t}\n\tif (role === \"viewer\" && input.enableClientTools) {\n\t\tthrow new ApiError(\n\t\t\t400,\n\t\t\t\"viewer headless connections cannot enable client-side tools\",\n\t\t);\n\t}\n\tconst disallowedViewerRequest = getViewerDisallowedServerRequest(\n\t\tinput.capabilities?.serverRequests,\n\t);\n\tif (role === \"viewer\" && disallowedViewerRequest) {\n\t\tthrow new ApiError(\n\t\t\t400,\n\t\t\t`viewer headless connections cannot negotiate ${disallowedViewerRequest} requests`,\n\t\t);\n\t}\n\tconst headerApproval = normalizeApprovalMode(\n\t\tgetRequestHeader(\n\t\t\treq,\n\t\t\t\"x-composer-approval-mode\",\n\t\t\t\"x-maestro-approval-mode\",\n\t\t) ?? undefined,\n\t);\n\tconst effectiveApproval = resolveApprovalModeForRequest({\n\t\tsessionId: requestedSessionId ?? sessionManager.getSessionId(),\n\t\tsubject,\n\t\theaderApprovalMode: input.approvalMode ?? headerApproval,\n\t\tdefaultApprovalMode: context.defaultApprovalMode,\n\t});\n\n\tconst runtime = await context.headlessRuntimeService.ensureRuntime({\n\t\tscope_key: getScopeKey(req),\n\t\tsessionId: requestedSessionId,\n\t\tsubject,\n\t\tworkspaceRoot,\n\t\tclientProtocolVersion: input.protocolVersion,\n\t\tclientInfo: input.clientInfo,\n\t\tcapabilities: input.capabilities\n\t\t\t? {\n\t\t\t\t\tserver_requests: input.capabilities.serverRequests,\n\t\t\t\t\tutility_operations: input.capabilities.utilityOperations,\n\t\t\t\t\traw_agent_events: input.capabilities.rawAgentEvents,\n\t\t\t\t}\n\t\t\t: undefined,\n\t\toptOutNotifications: input.optOutNotifications,\n\t\trole,\n\t\tregisteredModel,\n\t\tthinkingLevel: (input.thinkingLevel ?? \"off\") as ThinkingLevel,\n\t\tapprovalMode: effectiveApproval,\n\t\tenableClientTools: input.enableClientTools,\n\t\tclient: input.client,\n\t\tregisterConnection: input.registerConnection ?? true,\n\t\tcontext,\n\t\tsessionManager,\n\t});\n\tif (context.hostedRunner) {\n\t\tclaimHostedRunnerSession(context, runtime.getSnapshot().session_id);\n\t}\n\tif (input.recordAgentRuntimeTrigger !== false) {\n\t\tawait recordPlatformAgentRuntimeSessionStart({\n\t\t\tcontext,\n\t\t\truntime,\n\t\t\tsubject,\n\t\t\tregisteredModel,\n\t\t\trole,\n\t\t\tthinkingLevel: (input.thinkingLevel ?? \"off\") as ThinkingLevel,\n\t\t\tapprovalMode: effectiveApproval,\n\t\t\tworkspaceRoot,\n\t\t\tinput,\n\t\t});\n\t}\n\treturn runtime;\n}\n\nasync function recordPlatformAgentRuntimeSessionStart(options: {\n\tcontext: WebServerContext;\n\truntime: HeadlessSessionRuntime;\n\tsubject?: string;\n\tregisteredModel: RegisteredModel;\n\trole: HeadlessConnectionRole;\n\tthinkingLevel: ThinkingLevel;\n\tapprovalMode: ApprovalMode;\n\tworkspaceRoot: string | undefined;\n\tinput: HeadlessSessionCreateInput;\n}): Promise<void> {\n\tconst snapshot = options.runtime.getSnapshot();\n\tconst hostedRunner = options.context.hostedRunner;\n\t// This is a projection, not ownership transfer. The local headless runtime\n\t// remains authoritative; Platform receives session-start metadata and trace\n\t// context so AgentRuntime, A2A, deploy smoke tests, and support endpoints can\n\t// all join on the same Maestro session.\n\tconst result = await recordMaestroSessionRuntimeTrigger({\n\t\tworkspaceId: hostedRunner?.workspaceId,\n\t\tagentId: hostedRunner?.agentId,\n\t\tsessionId: snapshot.session_id,\n\t\tactorId: options.subject,\n\t\tcorrelationId: `maestro-session:${snapshot.session_id}`,\n\t\ttraceparent: getTraceParentHeader(),\n\t\tmetadata: {\n\t\t\tmodel: options.registeredModel.id,\n\t\t\tprovider: options.registeredModel.provider,\n\t\t\trole: options.role,\n\t\t\tthinking_level: options.thinkingLevel,\n\t\t\tapproval_mode: options.approvalMode,\n\t\t\tclient: options.input.client ?? \"generic\",\n\t\t\tprotocol_version: options.input.protocolVersion,\n\t\t\tworkspace_root: options.workspaceRoot,\n\t\t\trunner_session_id: hostedRunner?.runnerSessionId,\n\t\t\towner_instance_id: hostedRunner?.ownerInstanceId,\n\t\t\tagent_id: hostedRunner?.agentId,\n\t\t},\n\t});\n\tif (!hostedRunner || !result) {\n\t\treturn;\n\t}\n\tconst a2aCorrelation = result.events.find(\n\t\t(event) => event.type === \"maestro.platform_runtime.a2a_correlated\",\n\t)?.attributes;\n\tbindHostedRunnerPlatformLease(hostedRunner, {\n\t\tagentRunId: result.run.id,\n\t\tagentId: result.run.linkage?.agentId,\n\t\tleaseToken: result.run.lease?.token,\n\t});\n\t// Store only support-grade handles on the hosted runner. The full run/task\n\t// state stays in Platform; health and identity endpoints expose these ids\n\t// for operators without making Platform a session-state dependency.\n\thostedRunner.a2aMessageId = a2aCorrelation\n\t\t? stringAttribute(a2aCorrelation, \"a2a_message_id\")\n\t\t: undefined;\n\thostedRunner.a2aTaskId = a2aCorrelation\n\t\t? stringAttribute(a2aCorrelation, \"a2a_task_id\")\n\t\t: undefined;\n\thostedRunner.agentRuntimeWorkerQueue = a2aCorrelation\n\t\t? stringAttribute(a2aCorrelation, \"worker_queue\")\n\t\t: undefined;\n\thostedRunner.agentRuntimeCorrelationPath = a2aCorrelation\n\t\t? stringAttribute(a2aCorrelation, \"correlation_path\")\n\t\t: undefined;\n}\n\nfunction stringAttribute(\n\tattributes: Record<string, unknown>,\n\tkey: string,\n): string | undefined {\n\tconst value = attributes[key];\n\treturn typeof value === \"string\" && value.trim().length > 0\n\t\t? value\n\t\t: undefined;\n}\n\nasync function ensureConnection(\n\treq: IncomingMessage,\n\tcontext: WebServerContext,\n\tinput: HeadlessConnectionCreateInput,\n): Promise<HeadlessRuntimeConnectionSnapshot> {\n\tconst runtime = await ensureRuntime(req, context, {\n\t\t...input,\n\t\tregisterConnection: false,\n\t\trecordAgentRuntimeTrigger: false,\n\t});\n\tconst role = getHeadlessRole(req, input.role);\n\tconst heartbeat = runtime.registerConnection({\n\t\tconnectionId: input.connectionId,\n\t\tclientProtocolVersion: input.protocolVersion,\n\t\tclientInfo: input.clientInfo,\n\t\tcapabilities: input.capabilities\n\t\t\t? {\n\t\t\t\t\tserver_requests: input.capabilities.serverRequests,\n\t\t\t\t\tutility_operations: input.capabilities.utilityOperations,\n\t\t\t\t\traw_agent_events: input.capabilities.rawAgentEvents,\n\t\t\t\t}\n\t\t\t: undefined,\n\t\toptOutNotifications: input.optOutNotifications,\n\t\trole,\n\t\ttakeControl: input.takeControl,\n\t});\n\tconst snapshot = runtime.getSnapshot();\n\treturn {\n\t\t...heartbeat,\n\t\tsession_id: snapshot.session_id,\n\t\trole,\n\t\topt_out_notifications: input.optOutNotifications,\n\t\tsnapshot,\n\t};\n}\n\nfunction getRuntime(\n\treq: IncomingMessage,\n\tcontext: WebServerContext,\n\tsessionId: string | undefined,\n) {\n\tif (!sessionId) {\n\t\tthrow new ApiError(400, \"Missing headless session id\");\n\t}\n\tensureHostedRunnerCanUseSession(context, sessionId);\n\tconst runtime = context.headlessRuntimeService.getRuntime(\n\t\tgetScopeKey(req),\n\t\tsessionId,\n\t);\n\tif (!runtime) {\n\t\tthrow new ApiError(404, \"Headless session not found\");\n\t}\n\tif (context.hostedRunner) {\n\t\tclaimHostedRunnerSession(context, runtime.getSnapshot().session_id);\n\t}\n\treturn runtime;\n}\n\nexport async function handleHeadlessSessionCreate(\n\treq: IncomingMessage,\n\tres: ServerResponse,\n\tcontext: WebServerContext,\n) {\n\tconst input = await parseAndValidateJson<HeadlessSessionCreateInput>(\n\t\treq,\n\t\tHeadlessSessionCreateSchema,\n\t);\n\tconst runtime = await ensureRuntime(req, context, input);\n\tsendJson(res, 200, runtime.getSnapshot(), context.corsHeaders, req);\n}\n\nexport async function handleHeadlessConnectionCreate(\n\treq: IncomingMessage,\n\tres: ServerResponse,\n\tcontext: WebServerContext,\n) {\n\tconst input = await parseAndValidateJson<HeadlessConnectionCreateInput>(\n\t\treq,\n\t\tHeadlessConnectionCreateSchema,\n\t);\n\tlet connection: HeadlessRuntimeConnectionSnapshot;\n\ttry {\n\t\tconnection = await ensureConnection(req, context, input);\n\t} catch (error) {\n\t\trethrowHeadlessConnectionLifecycleError(error);\n\t}\n\tsendJson(res, 200, connection, context.corsHeaders, req);\n}\n\nexport function handleHeadlessSessionState(\n\treq: IncomingMessage,\n\tres: ServerResponse,\n\tcontext: WebServerContext,\n\tparams?: Record<string, string>,\n) {\n\tconst runtime = getRuntime(req, context, params?.id);\n\tsendJson(res, 200, runtime.getSnapshot(), context.corsHeaders, req);\n}\n\nexport async function handleHeadlessSessionSubscribe(\n\treq: IncomingMessage,\n\tres: ServerResponse,\n\tcontext: WebServerContext,\n\tparams?: Record<string, string>,\n) {\n\tconst runtime = getRuntime(req, context, params?.id);\n\tconst input = await parseAndValidateJson<HeadlessSessionSubscribeInput>(\n\t\treq,\n\t\tHeadlessSessionSubscribeSchema,\n\t);\n\tconst role = getHeadlessRole(req, input.role);\n\tconst disallowedViewerRequest = getViewerDisallowedServerRequest(\n\t\tinput.capabilities?.serverRequests,\n\t);\n\tif (role === \"viewer\" && disallowedViewerRequest) {\n\t\tthrow new ApiError(\n\t\t\t400,\n\t\t\t`viewer headless connections cannot negotiate ${disallowedViewerRequest} requests`,\n\t\t);\n\t}\n\ttry {\n\t\tsendJson(\n\t\t\tres,\n\t\t\t200,\n\t\t\truntime.createSubscription({\n\t\t\t\tconnectionId: input.connectionId,\n\t\t\t\trole,\n\t\t\t\texplicit: true,\n\t\t\t\ttakeControl: input.takeControl,\n\t\t\t\tclientProtocolVersion: input.protocolVersion,\n\t\t\t\tclientInfo: input.clientInfo,\n\t\t\t\tcapabilities: input.capabilities\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tserver_requests: input.capabilities.serverRequests,\n\t\t\t\t\t\t\tutility_operations: input.capabilities.utilityOperations,\n\t\t\t\t\t\t\traw_agent_events: input.capabilities.rawAgentEvents,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined,\n\t\t\t\toptOutNotifications: input.optOutNotifications,\n\t\t\t}),\n\t\t\tcontext.corsHeaders,\n\t\t\treq,\n\t\t);\n\t} catch (error) {\n\t\tif (\n\t\t\terror instanceof Error &&\n\t\t\terror.message === \"Controller lease is already held by another connection\"\n\t\t) {\n\t\t\tthrow new ApiError(409, error.message);\n\t\t}\n\t\tif (\n\t\t\terror instanceof Error &&\n\t\t\t(error.message === \"Headless connection not found\" ||\n\t\t\t\terror.message ===\n\t\t\t\t\t\"Headless connection role does not match subscription role\")\n\t\t) {\n\t\t\tthrow new ApiError(400, error.message);\n\t\t}\n\t\tthrow error;\n\t}\n}\n\nexport async function handleHeadlessSessionUnsubscribe(\n\treq: IncomingMessage,\n\tres: ServerResponse,\n\tcontext: WebServerContext,\n\tparams?: Record<string, string>,\n) {\n\tconst runtime = getRuntime(req, context, params?.id);\n\tconst input = await parseAndValidateJson<HeadlessSessionUnsubscribeInput>(\n\t\treq,\n\t\tHeadlessSessionUnsubscribeSchema,\n\t);\n\tif (!(await runtime.unsubscribe(input.subscriptionId))) {\n\t\tthrow new ApiError(404, \"Headless subscriber not found\");\n\t}\n\tsendJson(res, 200, { success: true }, context.corsHeaders, req);\n}\n\nexport async function handleHeadlessSessionHeartbeat(\n\treq: IncomingMessage,\n\tres: ServerResponse,\n\tcontext: WebServerContext,\n\tparams?: Record<string, string>,\n) {\n\tconst runtime = getRuntime(req, context, params?.id);\n\tconst input = await parseAndValidateJson<HeadlessSessionHeartbeatInput>(\n\t\treq,\n\t\tHeadlessSessionHeartbeatSchema,\n\t);\n\tlet heartbeat: HeadlessRuntimeHeartbeatSnapshot;\n\ttry {\n\t\theartbeat = runtime.heartbeatConnection({\n\t\t\tconnectionId: input.connectionId ?? getHeadlessConnectionId(req),\n\t\t\tsubscriptionId: input.subscriptionId ?? getHeadlessSubscriberId(req),\n\t\t});\n\t} catch (error) {\n\t\trethrowHeadlessConnectionLifecycleError(error);\n\t}\n\tsendJson(res, 200, heartbeat, context.corsHeaders, req);\n}\n\nexport async function handleHeadlessSessionDisconnect(\n\treq: IncomingMessage,\n\tres: ServerResponse,\n\tcontext: WebServerContext,\n\tparams?: Record<string, string>,\n) {\n\tconst runtime = getRuntime(req, context, params?.id);\n\tconst input = await parseAndValidateJson<HeadlessSessionDisconnectInput>(\n\t\treq,\n\t\tHeadlessSessionDisconnectSchema,\n\t);\n\ttry {\n\t\tsendJson(\n\t\t\tres,\n\t\t\t200,\n\t\t\tawait runtime.disconnectConnection({\n\t\t\t\tconnectionId: input.connectionId ?? getHeadlessConnectionId(req),\n\t\t\t\tsubscriptionId: input.subscriptionId ?? getHeadlessSubscriberId(req),\n\t\t\t}),\n\t\t\tcontext.corsHeaders,\n\t\t\treq,\n\t\t);\n\t} catch (error) {\n\t\trethrowHeadlessConnectionLifecycleError(error);\n\t}\n}\n\nexport function handleHeadlessSessionEvents(\n\treq: IncomingMessage,\n\tres: ServerResponse,\n\tcontext: WebServerContext,\n\tparams?: Record<string, string>,\n) {\n\tconst runtime = getRuntime(req, context, params?.id);\n\tconst url = new URL(\n\t\treq.url || `/api/headless/sessions/${params?.id}/events`,\n\t\t`http://${req.headers.host || \"localhost\"}`,\n\t);\n\tconst cursorParam = url.searchParams.get(\"cursor\");\n\tconst cursor = cursorParam ? Number.parseInt(cursorParam, 10) : null;\n\tconst subscriptionId =\n\t\turl.searchParams.get(\"subscriptionId\") || getHeadlessSubscriberId(req);\n\n\tconst stream = subscriptionId\n\t\t? runtime.attachSubscription(subscriptionId)\n\t\t: runtime.createImplicitStream({\n\t\t\t\tcursor,\n\t\t\t\trole: getHeadlessRole(req),\n\t\t\t\toptOutNotifications: parseOptOutNotifications(req),\n\t\t\t});\n\tif (!stream) {\n\t\tthrow new ApiError(404, \"Headless subscriber not found\");\n\t}\n\n\tres.writeHead(200, {\n\t\t\"Content-Type\": \"text/event-stream\",\n\t\t\"Cache-Control\": \"no-cache\",\n\t\tConnection: \"keep-alive\",\n\t\t...context.corsHeaders,\n\t});\n\tlet flushing = false;\n\n\tconst flush = () => {\n\t\tif (flushing || res.writableEnded) {\n\t\t\treturn;\n\t\t}\n\t\tflushing = true;\n\t\twhile (!res.writableEnded) {\n\t\t\tconst next = stream.next();\n\t\t\tif (!next) {\n\t\t\t\tflushing = false;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst wrote = writeSse(res, next);\n\t\t\tif (!wrote) {\n\t\t\t\tres.once(\"drain\", () => {\n\t\t\t\t\tflushing = false;\n\t\t\t\t\tflush();\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tflushing = false;\n\t};\n\tconst stopListening = stream.onAvailable(flush);\n\tconst heartbeat = setInterval(() => {\n\t\tif (!res.writableEnded) {\n\t\t\tstream.enqueue(runtime.heartbeat());\n\t\t\tflush();\n\t\t}\n\t}, 15000);\n\theartbeat.unref();\n\n\tconst cleanup = () => {\n\t\tclearInterval(heartbeat);\n\t\tstopListening();\n\t\tstream.close();\n\t};\n\treq.on(\"close\", cleanup);\n\tres.on(\"close\", cleanup);\n\tflush();\n}\n\nexport async function handleHeadlessSessionMessage(\n\treq: IncomingMessage,\n\tres: ServerResponse,\n\tcontext: WebServerContext,\n\tparams?: Record<string, string>,\n) {\n\tconst runtime = getRuntime(req, context, params?.id);\n\tconst input = await parseHeadlessMessage(req);\n\ttry {\n\t\truntime.assertCanSend(\n\t\t\tgetHeadlessRole(req),\n\t\t\tgetHeadlessSubscriberId(req),\n\t\t\tgetHeadlessConnectionId(req),\n\t\t);\n\t} catch (error) {\n\t\trethrowHeadlessMessageError(error);\n\t}\n\ttry {\n\t\tawait runtime.send(input as HeadlessToAgentMessage, {\n\t\t\tconnectionId: getHeadlessConnectionId(req),\n\t\t\tsubscriptionId: getHeadlessSubscriberId(req),\n\t\t});\n\t} catch (error) {\n\t\trethrowHeadlessMessageError(error);\n\t}\n\tsendJson(res, 200, { success: true }, context.corsHeaders, req);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"headless-sessions.js","sourceRoot":"","sources":["../../../src/server/handlers/headless-sessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,EAEN,qBAAqB,EACrB,uBAAuB,EACvB,yBAAyB,EACzB,0BAA0B,EAC1B,sBAAsB,EACtB,mCAAmC,EACnC,2BAA2B,EAC3B,yBAAyB,GACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAA6B,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAIpE,OAAO,EAAE,4BAA4B,EAAE,MAAM,kCAAkC,CAAC;AAEhF,OAAO,EAAE,kCAAkC,EAAE,MAAM,wCAAwC,CAAC;AAE5F,OAAO,EACN,qBAAqB,EACrB,6BAA6B,GAC7B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAO9D,OAAO,EAAE,+BAA+B,EAAE,MAAM,gCAAgC,CAAC;AACjF,OAAO,EACN,6BAA6B,EAC7B,sBAAsB,EACtB,4BAA4B,GAC5B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EACN,QAAQ,EACR,gBAAgB,EAChB,eAAe,EACf,QAAQ,GACR,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEzE,MAAM,CAAN,IAAY,qBAGX;AAHD,WAAY,qBAAqB;IAChC,8DAAqC,CAAA;IACrC,0EAAiD,CAAA;AAClD,CAAC,EAHW,qBAAqB,KAArB,qBAAqB,QAGhC;AAED,MAAM,0BAA0B,GAAG,uBAAuB,CAAC;AAE3D,SAAS,kBAAkB,CAAoC,MAAS;IACv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,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { existsSync } from \"node:fs\";\nimport type { IncomingMessage, ServerResponse } from \"node:http\";\nimport {\n\ttype HeadlessConnectionRole,\n\theadlessApprovalModes,\n\theadlessConnectionRoles,\n\theadlessNotificationTypes,\n\theadlessServerRequestTypes,\n\theadlessThinkingLevels,\n\theadlessToAgentMessageSchemasByType,\n\theadlessToAgentMessageTypes,\n\theadlessUtilityOperations,\n} from \"@evalops/contracts\";\nimport { type Static, type TSchema, Type } from \"@sinclair/typebox\";\nimport type { ApprovalMode } from \"../../agent/action-approval.js\";\nimport type { ThinkingLevel } from \"../../agent/types.js\";\nimport type { HeadlessToAgentMessage } from \"../../cli/headless-protocol.js\";\nimport { resolveExistingWorkspaceRoot } from \"../../headless/workspace-root.js\";\nimport type { RegisteredModel } from \"../../models/registry.js\";\nimport { recordMaestroSessionRuntimeTrigger } from \"../../platform/agent-runtime-client.js\";\nimport type { WebServerContext } from \"../app-context.js\";\nimport {\n\tnormalizeApprovalMode,\n\tresolveApprovalModeForRequest,\n} from \"../approval-mode-store.js\";\nimport { getAuthScopeKey, getAuthSubject } from \"../authz.js\";\nimport type {\n\tHeadlessRuntimeConnectionSnapshot,\n\tHeadlessRuntimeHeartbeatSnapshot,\n\tHeadlessRuntimeStreamEnvelope,\n\tHeadlessSessionRuntime,\n} from \"../headless-runtime-service.js\";\nimport { loadHostedRunnerRestoreManifest } from \"../headless-runtime-service.js\";\nimport {\n\tbindHostedRunnerPlatformLease,\n\tclaimHostedRunnerLease,\n\tevaluateHostedRunnerLeaseUse,\n} from \"../hosted-runner-lease.js\";\nimport { getTraceParentHeader } from \"../request-context.js\";\nimport {\n\tApiError,\n\tgetRequestHeader,\n\treadRequestBody,\n\tsendJson,\n} from \"../server-utils.js\";\nimport { createSessionManagerForRequest } from \"../session-scope.js\";\nimport { parseAndValidateJson, validatePayload } from \"../validation.js\";\n\nexport enum HostedRunnerErrorType {\n\tRuntimeNotReady = \"runtime_not_ready\",\n\tRuntimeOwnedElsewhere = \"runtime_owned_elsewhere\",\n}\n\nconst HOSTED_RUNNER_ERROR_DOMAIN = \"maestro.hosted_runner\";\n\nfunction stringLiteralUnion<const T extends readonly string[]>(values: T) {\n\treturn Type.Unsafe<T[number]>(\n\t\tType.Union(\n\t\t\tvalues.map((value) => Type.Literal(value)) as unknown as [\n\t\t\t\tTSchema,\n\t\t\t\t...TSchema[],\n\t\t\t],\n\t\t),\n\t);\n}\n\nconst HeadlessOptOutNotificationsSchema = Type.Array(\n\tstringLiteralUnion(headlessNotificationTypes),\n\t{\n\t\tuniqueItems: true,\n\t},\n);\n\nconst HeadlessCreateBaseProperties = {\n\tsessionId: Type.Optional(Type.String()),\n\tprotocolVersion: Type.Optional(Type.String()),\n\tclientInfo: Type.Optional(\n\t\tType.Object({\n\t\t\tname: Type.String(),\n\t\t\tversion: Type.Optional(Type.String()),\n\t\t}),\n\t),\n\tworkspaceRoot: Type.Optional(Type.String()),\n\tmodel: Type.Optional(Type.String()),\n\tenableClientTools: Type.Optional(Type.Boolean()),\n\tcapabilities: Type.Optional(\n\t\tType.Object({\n\t\t\tserverRequests: Type.Optional(\n\t\t\t\tType.Array(stringLiteralUnion(headlessServerRequestTypes), {\n\t\t\t\t\tuniqueItems: true,\n\t\t\t\t}),\n\t\t\t),\n\t\t\tutilityOperations: Type.Optional(\n\t\t\t\tType.Array(stringLiteralUnion(headlessUtilityOperations), {\n\t\t\t\t\tuniqueItems: true,\n\t\t\t\t}),\n\t\t\t),\n\t\t\trawAgentEvents: Type.Optional(Type.Boolean()),\n\t\t}),\n\t),\n\toptOutNotifications: Type.Optional(HeadlessOptOutNotificationsSchema),\n\trole: Type.Optional(stringLiteralUnion(headlessConnectionRoles)),\n\tclient: Type.Optional(\n\t\tType.Union([\n\t\t\tType.Literal(\"generic\"),\n\t\t\tType.Literal(\"vscode\"),\n\t\t\tType.Literal(\"jetbrains\"),\n\t\t\tType.Literal(\"conductor\"),\n\t\t]),\n\t),\n\tthinkingLevel: Type.Optional(stringLiteralUnion(headlessThinkingLevels)),\n\tapprovalMode: Type.Optional(stringLiteralUnion(headlessApprovalModes)),\n} as const;\n\nconst HeadlessSessionCreateSchema = Type.Object(HeadlessCreateBaseProperties);\n\nconst HeadlessConnectionCreateSchema = Type.Object({\n\t...HeadlessCreateBaseProperties,\n\tconnectionId: Type.Optional(Type.String()),\n\ttakeControl: Type.Optional(Type.Boolean()),\n});\n\nconst HeadlessMessageTypeSchema = Type.Object(\n\t{\n\t\ttype: stringLiteralUnion(headlessToAgentMessageTypes),\n\t},\n\t{ additionalProperties: true },\n);\n\nconst HeadlessSessionSubscribeSchema = Type.Object({\n\tconnectionId: Type.Optional(Type.String()),\n\tprotocolVersion: Type.Optional(Type.String()),\n\tclientInfo: Type.Optional(\n\t\tType.Object({\n\t\t\tname: Type.String(),\n\t\t\tversion: Type.Optional(Type.String()),\n\t\t}),\n\t),\n\tcapabilities: Type.Optional(\n\t\tType.Object({\n\t\t\tserverRequests: Type.Optional(\n\t\t\t\tType.Array(stringLiteralUnion(headlessServerRequestTypes), {\n\t\t\t\t\tuniqueItems: true,\n\t\t\t\t}),\n\t\t\t),\n\t\t\tutilityOperations: Type.Optional(\n\t\t\t\tType.Array(stringLiteralUnion(headlessUtilityOperations), {\n\t\t\t\t\tuniqueItems: true,\n\t\t\t\t}),\n\t\t\t),\n\t\t\trawAgentEvents: Type.Optional(Type.Boolean()),\n\t\t}),\n\t),\n\toptOutNotifications: Type.Optional(HeadlessOptOutNotificationsSchema),\n\trole: Type.Optional(stringLiteralUnion(headlessConnectionRoles)),\n\ttakeControl: Type.Optional(Type.Boolean()),\n});\n\nconst HeadlessSessionUnsubscribeSchema = Type.Object({\n\tsubscriptionId: Type.String(),\n});\n\nconst HeadlessSessionHeartbeatSchema = Type.Object({\n\tconnectionId: Type.Optional(Type.String()),\n\tsubscriptionId: Type.Optional(Type.String()),\n});\n\nconst HeadlessSessionDisconnectSchema = Type.Object({\n\tconnectionId: Type.Optional(Type.String()),\n\tsubscriptionId: Type.Optional(Type.String()),\n});\n\ntype HeadlessSessionCreateInput = Static<typeof HeadlessSessionCreateSchema>;\ntype HeadlessConnectionCreateInput = Static<\n\ttypeof HeadlessConnectionCreateSchema\n>;\ntype HeadlessSessionSubscribeInput = Static<\n\ttypeof HeadlessSessionSubscribeSchema\n>;\ntype HeadlessSessionUnsubscribeInput = Static<\n\ttypeof HeadlessSessionUnsubscribeSchema\n>;\ntype HeadlessSessionHeartbeatInput = Static<\n\ttypeof HeadlessSessionHeartbeatSchema\n>;\ntype HeadlessSessionDisconnectInput = Static<\n\ttypeof HeadlessSessionDisconnectSchema\n>;\ntype HeadlessMessageTypeInput = Static<typeof HeadlessMessageTypeSchema>;\n\nasync function parseHeadlessMessage(\n\treq: IncomingMessage,\n): Promise<HeadlessToAgentMessage> {\n\tconst raw = await readRequestBody(req);\n\tif (!raw.length) {\n\t\tthrow new ApiError(400, \"Request body required\");\n\t}\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(raw.toString());\n\t} catch {\n\t\tthrow new ApiError(400, \"Invalid JSON payload\");\n\t}\n\tconst envelope = validatePayload<HeadlessMessageTypeInput>(\n\t\tparsed,\n\t\tHeadlessMessageTypeSchema,\n\t\t\"body\",\n\t);\n\treturn validatePayload<HeadlessToAgentMessage>(\n\t\tparsed,\n\t\theadlessToAgentMessageSchemasByType[envelope.type],\n\t\t\"body\",\n\t);\n}\n\nfunction getHeadlessRole(\n\treq: IncomingMessage,\n\texplicitRole?: HeadlessConnectionRole,\n): HeadlessConnectionRole {\n\tif (explicitRole) {\n\t\treturn explicitRole;\n\t}\n\tconst headerRole = getRequestHeader(\n\t\treq,\n\t\t\"x-composer-headless-role\",\n\t\t\"x-maestro-headless-role\",\n\t);\n\treturn headerRole === \"viewer\" ? \"viewer\" : \"controller\";\n}\n\nfunction getViewerDisallowedServerRequest(\n\tserverRequests?: Static<\n\t\ttypeof HeadlessCreateBaseProperties.capabilities\n\t>[\"serverRequests\"],\n): \"mcp_elicitation\" | \"user_input\" | undefined {\n\tif (serverRequests?.includes(\"mcp_elicitation\")) {\n\t\treturn \"mcp_elicitation\";\n\t}\n\tif (serverRequests?.includes(\"user_input\")) {\n\t\treturn \"user_input\";\n\t}\n\treturn undefined;\n}\n\nfunction writeSse(res: ServerResponse, payload: unknown): boolean {\n\treturn res.write(`data: ${JSON.stringify(payload)}\\n\\n`);\n}\n\nfunction getHeadlessSubscriberId(req: IncomingMessage): string | undefined {\n\treturn (\n\t\tgetRequestHeader(\n\t\t\treq,\n\t\t\t\"x-composer-headless-subscriber-id\",\n\t\t\t\"x-maestro-headless-subscriber-id\",\n\t\t) ?? undefined\n\t);\n}\n\nfunction getHeadlessConnectionId(req: IncomingMessage): string | undefined {\n\treturn (\n\t\tgetRequestHeader(\n\t\t\treq,\n\t\t\t\"x-composer-headless-connection-id\",\n\t\t\t\"x-maestro-headless-connection-id\",\n\t\t) ?? undefined\n\t);\n}\n\nfunction parseOptOutNotifications(\n\treq: IncomingMessage,\n): HeadlessSessionSubscribeInput[\"optOutNotifications\"] {\n\tconst url = new URL(\n\t\treq.url || \"/\",\n\t\t`http://${req.headers.host || \"localhost\"}`,\n\t);\n\tconst raw = url.searchParams.get(\"optOutNotifications\");\n\tif (!raw) {\n\t\treturn undefined;\n\t}\n\tconst notifications = raw\n\t\t.split(\",\")\n\t\t.map((value) => value.trim())\n\t\t.filter(Boolean);\n\tif (notifications.length === 0) {\n\t\treturn undefined;\n\t}\n\treturn validatePayload<\n\t\tNonNullable<HeadlessSessionSubscribeInput[\"optOutNotifications\"]>\n\t>(\n\t\tnotifications,\n\t\tHeadlessOptOutNotificationsSchema,\n\t\t\"query.optOutNotifications\",\n\t);\n}\n\nfunction getScopeKey(req: IncomingMessage): string {\n\treturn getAuthScopeKey(req);\n}\n\nfunction hostedRunnerErrorMetadata(\n\tcontext: WebServerContext,\n\tmetadata: Record<string, string | undefined>,\n): Record<string, string> {\n\tconst hostedRunner = context.hostedRunner;\n\tconst detailMetadata: Record<string, string> = {};\n\tfor (const [key, value] of Object.entries({\n\t\trunner_session_id: hostedRunner?.runnerSessionId,\n\t\towner_instance_id: hostedRunner?.ownerInstanceId,\n\t\tworkspace_id: hostedRunner?.workspaceId,\n\t\tagent_run_id: hostedRunner?.agentRunId,\n\t\t...metadata,\n\t})) {\n\t\tif (value) {\n\t\t\tdetailMetadata[key] = value;\n\t\t}\n\t}\n\treturn detailMetadata;\n}\n\nfunction hostedRunnerOwnershipError(\n\tcontext: WebServerContext,\n\tmessage: string,\n\tmetadata: Record<string, string | undefined>,\n): ApiError {\n\treturn new ApiError(\n\t\t409,\n\t\tmessage,\n\t\t[\n\t\t\t{\n\t\t\t\treason: HostedRunnerErrorType.RuntimeOwnedElsewhere,\n\t\t\t\tdomain: HOSTED_RUNNER_ERROR_DOMAIN,\n\t\t\t\tmetadata: hostedRunnerErrorMetadata(context, metadata),\n\t\t\t},\n\t\t],\n\t\tHostedRunnerErrorType.RuntimeOwnedElsewhere,\n\t);\n}\n\nfunction hostedRunnerNotReadyError(\n\tcontext: WebServerContext,\n\tmessage: string,\n\tmetadata: Record<string, string | undefined>,\n): ApiError {\n\treturn new ApiError(\n\t\t503,\n\t\tmessage,\n\t\t[\n\t\t\t{\n\t\t\t\treason: HostedRunnerErrorType.RuntimeNotReady,\n\t\t\t\tdomain: HOSTED_RUNNER_ERROR_DOMAIN,\n\t\t\t\tmetadata: hostedRunnerErrorMetadata(context, metadata),\n\t\t\t},\n\t\t],\n\t\tHostedRunnerErrorType.RuntimeNotReady,\n\t);\n}\n\nfunction ensureHostedRunnerCanUseSession(\n\tcontext: WebServerContext,\n\trequestedSessionId: string | undefined,\n): void {\n\tconst hostedRunner = context.hostedRunner;\n\tif (!hostedRunner) {\n\t\treturn;\n\t}\n\tconst decision = evaluateHostedRunnerLeaseUse(\n\t\thostedRunner,\n\t\trequestedSessionId,\n\t);\n\tif (decision.ok) {\n\t\treturn;\n\t}\n\tif (decision.reason === \"runtime_draining\") {\n\t\tthrow hostedRunnerNotReadyError(context, decision.message, {\n\t\t\tdraining: \"true\",\n\t\t\tmaestro_session_id: decision.activeSessionId,\n\t\t\trequested_maestro_session_id: requestedSessionId,\n\t\t\tlease_generation: String(decision.snapshot.generation),\n\t\t});\n\t}\n\tthrow hostedRunnerOwnershipError(context, decision.message, {\n\t\tmaestro_session_id: decision.activeSessionId,\n\t\trequested_maestro_session_id: decision.requestedSessionId,\n\t\tlease_generation: String(decision.snapshot.generation),\n\t});\n}\n\nfunction claimHostedRunnerSession(\n\tcontext: WebServerContext,\n\tsessionId: string,\n): void {\n\tconst hostedRunner = context.hostedRunner;\n\tif (!hostedRunner) {\n\t\treturn;\n\t}\n\tconst decision = claimHostedRunnerLease(hostedRunner, sessionId);\n\tif (!decision.ok) {\n\t\tif (decision.reason === \"runtime_draining\") {\n\t\t\tthrow hostedRunnerNotReadyError(context, decision.message, {\n\t\t\t\tdraining: \"true\",\n\t\t\t\tmaestro_session_id: decision.activeSessionId,\n\t\t\t\trequested_maestro_session_id: decision.requestedSessionId ?? sessionId,\n\t\t\t\tlease_generation: String(decision.snapshot.generation),\n\t\t\t});\n\t\t}\n\t\tthrow hostedRunnerOwnershipError(context, decision.message, {\n\t\t\tmaestro_session_id: decision.activeSessionId,\n\t\t\trequested_maestro_session_id: decision.requestedSessionId ?? sessionId,\n\t\t\tlease_generation: String(decision.snapshot.generation),\n\t\t});\n\t}\n}\n\nfunction resolveRuntimeWorkspaceRoot(\n\tcontext: WebServerContext,\n\tworkspaceRoot: string | undefined,\n): string | undefined {\n\tconst requestedRoot = workspaceRoot?.trim() || undefined;\n\tconst hostedRoot = context.hostedRunner?.workspaceRoot?.trim() || undefined;\n\n\tlet resolvedRequestedRoot: string | undefined;\n\tif (requestedRoot) {\n\t\ttry {\n\t\t\tresolvedRequestedRoot = resolveExistingWorkspaceRoot(requestedRoot);\n\t\t} catch {\n\t\t\tthrow new ApiError(400, `workspaceRoot not found: ${requestedRoot}`);\n\t\t}\n\t}\n\n\tlet resolvedHostedRoot: string | undefined;\n\tif (hostedRoot) {\n\t\ttry {\n\t\t\tresolvedHostedRoot = resolveExistingWorkspaceRoot(hostedRoot);\n\t\t} catch {\n\t\t\tthrow new ApiError(\n\t\t\t\t500,\n\t\t\t\t`Hosted runner workspace root is unavailable: ${hostedRoot}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (\n\t\tresolvedRequestedRoot &&\n\t\tresolvedHostedRoot &&\n\t\tresolvedRequestedRoot !== resolvedHostedRoot\n\t) {\n\t\tthrow new ApiError(\n\t\t\t409,\n\t\t\t`workspaceRoot must match hosted runner workspace root: ${resolvedHostedRoot}`,\n\t\t);\n\t}\n\n\treturn resolvedHostedRoot ?? resolvedRequestedRoot;\n}\n\nfunction rethrowHeadlessMessageError(error: unknown): never {\n\tif (!(error instanceof Error)) {\n\t\tthrow error;\n\t}\n\tif (error.message === \"Viewer headless connections cannot send messages\") {\n\t\tthrow new ApiError(403, error.message);\n\t}\n\tif (error.message === \"Headless subscriber not found\") {\n\t\tthrow new ApiError(404, error.message);\n\t}\n\tif (\n\t\terror.message === \"Headless connection not found\" ||\n\t\terror.message === \"Headless connection does not have controller access\" ||\n\t\terror.message.includes(\"is owned by another connection\")\n\t) {\n\t\tthrow new ApiError(403, error.message);\n\t}\n\tif (error.message.includes(\"Controller lease\")) {\n\t\tthrow new ApiError(409, error.message);\n\t}\n\tthrow new ApiError(403, error.message);\n}\n\nfunction rethrowHeadlessConnectionLifecycleError(error: unknown): never {\n\tif (!(error instanceof Error)) {\n\t\tthrow error;\n\t}\n\tif (error.message === \"Headless connection not found\") {\n\t\tthrow new ApiError(404, error.message);\n\t}\n\tif (\n\t\terror.message.includes(\"Controller lease\") ||\n\t\terror.message ===\n\t\t\t\"Headless connection role does not match subscription role\"\n\t) {\n\t\tthrow new ApiError(409, error.message);\n\t}\n\tthrow error;\n}\n\nasync function ensureRuntime(\n\treq: IncomingMessage,\n\tcontext: WebServerContext,\n\tinput: HeadlessSessionCreateInput & {\n\t\tregisterConnection?: boolean;\n\t\trecordAgentRuntimeTrigger?: boolean;\n\t},\n) {\n\tconst sessionManager = createSessionManagerForRequest(req, false);\n\tconst role = getHeadlessRole(req, input.role);\n\tconst hostedRestoreSessionId = context.hostedRunner?.restoreManifestPath\n\t\t? (context.hostedRunner.activeMaestroSessionId ??\n\t\t\tcontext.hostedRunner.configuredMaestroSessionId)\n\t\t: undefined;\n\tconst requestedSessionId =\n\t\tinput.sessionId?.trim() || hostedRestoreSessionId || undefined;\n\tconst workspaceRoot = resolveRuntimeWorkspaceRoot(\n\t\tcontext,\n\t\tinput.workspaceRoot,\n\t);\n\tensureHostedRunnerCanUseSession(context, requestedSessionId);\n\tif (requestedSessionId) {\n\t\tlet sessionFile = sessionManager.getSessionFileById(requestedSessionId);\n\t\tif (!sessionFile && context.hostedRunner?.restoreManifestPath) {\n\t\t\tconst restoreManifest = await loadHostedRunnerRestoreManifest(\n\t\t\t\tcontext.hostedRunner.restoreManifestPath,\n\t\t\t);\n\t\t\tconst restoreSessionFile =\n\t\t\t\trestoreManifest?.maestro_session_id === requestedSessionId\n\t\t\t\t\t? restoreManifest.runtime.session_file\n\t\t\t\t\t: undefined;\n\t\t\tif (restoreSessionFile && existsSync(restoreSessionFile)) {\n\t\t\t\tsessionFile = restoreSessionFile;\n\t\t\t}\n\t\t}\n\t\tif (!sessionFile) {\n\t\t\tthrow new ApiError(404, \"Session not found\");\n\t\t}\n\t\tsessionManager.setSessionFile(sessionFile);\n\t}\n\n\tconst registeredModel = await context.getRegisteredModel(input.model);\n\tconst subject = getAuthSubject(req);\n\tif (\n\t\tinput.enableClientTools &&\n\t\t!input.capabilities?.serverRequests?.includes(\"client_tool\")\n\t) {\n\t\tthrow new ApiError(\n\t\t\t400,\n\t\t\t\"client_tool capability is required when enableClientTools is true\",\n\t\t);\n\t}\n\tif (role === \"viewer\" && input.enableClientTools) {\n\t\tthrow new ApiError(\n\t\t\t400,\n\t\t\t\"viewer headless connections cannot enable client-side tools\",\n\t\t);\n\t}\n\tconst disallowedViewerRequest = getViewerDisallowedServerRequest(\n\t\tinput.capabilities?.serverRequests,\n\t);\n\tif (role === \"viewer\" && disallowedViewerRequest) {\n\t\tthrow new ApiError(\n\t\t\t400,\n\t\t\t`viewer headless connections cannot negotiate ${disallowedViewerRequest} requests`,\n\t\t);\n\t}\n\tconst headerApproval = normalizeApprovalMode(\n\t\tgetRequestHeader(\n\t\t\treq,\n\t\t\t\"x-composer-approval-mode\",\n\t\t\t\"x-maestro-approval-mode\",\n\t\t) ?? undefined,\n\t);\n\tconst effectiveApproval = resolveApprovalModeForRequest({\n\t\tsessionId: requestedSessionId ?? sessionManager.getSessionId(),\n\t\tsubject,\n\t\theaderApprovalMode: input.approvalMode ?? headerApproval,\n\t\tdefaultApprovalMode: context.defaultApprovalMode,\n\t});\n\n\tconst runtime = await context.headlessRuntimeService.ensureRuntime({\n\t\tscope_key: getScopeKey(req),\n\t\tsessionId: requestedSessionId,\n\t\tsubject,\n\t\tworkspaceRoot,\n\t\tclientProtocolVersion: input.protocolVersion,\n\t\tclientInfo: input.clientInfo,\n\t\tcapabilities: input.capabilities\n\t\t\t? {\n\t\t\t\t\tserver_requests: input.capabilities.serverRequests,\n\t\t\t\t\tutility_operations: input.capabilities.utilityOperations,\n\t\t\t\t\traw_agent_events: input.capabilities.rawAgentEvents,\n\t\t\t\t}\n\t\t\t: undefined,\n\t\toptOutNotifications: input.optOutNotifications,\n\t\trole,\n\t\tregisteredModel,\n\t\tthinkingLevel: (input.thinkingLevel ?? \"off\") as ThinkingLevel,\n\t\tapprovalMode: effectiveApproval,\n\t\tenableClientTools: input.enableClientTools,\n\t\tclient: input.client,\n\t\tregisterConnection: input.registerConnection ?? true,\n\t\tcontext,\n\t\tsessionManager,\n\t});\n\tif (context.hostedRunner) {\n\t\tclaimHostedRunnerSession(context, runtime.getSnapshot().session_id);\n\t}\n\tif (input.recordAgentRuntimeTrigger !== false) {\n\t\tawait recordPlatformAgentRuntimeSessionStart({\n\t\t\tcontext,\n\t\t\truntime,\n\t\t\tsubject,\n\t\t\tregisteredModel,\n\t\t\trole,\n\t\t\tthinkingLevel: (input.thinkingLevel ?? \"off\") as ThinkingLevel,\n\t\t\tapprovalMode: effectiveApproval,\n\t\t\tworkspaceRoot,\n\t\t\tinput,\n\t\t});\n\t}\n\treturn runtime;\n}\n\nasync function recordPlatformAgentRuntimeSessionStart(options: {\n\tcontext: WebServerContext;\n\truntime: HeadlessSessionRuntime;\n\tsubject?: string;\n\tregisteredModel: RegisteredModel;\n\trole: HeadlessConnectionRole;\n\tthinkingLevel: ThinkingLevel;\n\tapprovalMode: ApprovalMode;\n\tworkspaceRoot: string | undefined;\n\tinput: HeadlessSessionCreateInput;\n}): Promise<void> {\n\tconst snapshot = options.runtime.getSnapshot();\n\tconst hostedRunner = options.context.hostedRunner;\n\t// This is a projection, not ownership transfer. The local headless runtime\n\t// remains authoritative; Platform receives session-start metadata and trace\n\t// context so AgentRuntime, A2A, deploy smoke tests, and support endpoints can\n\t// all join on the same Maestro session.\n\tconst result = await recordMaestroSessionRuntimeTrigger({\n\t\tworkspaceId: hostedRunner?.workspaceId,\n\t\tagentId: hostedRunner?.agentId,\n\t\tsessionId: snapshot.session_id,\n\t\tactorId: options.subject,\n\t\tcorrelationId: `maestro-session:${snapshot.session_id}`,\n\t\ttraceparent: getTraceParentHeader(),\n\t\tmetadata: {\n\t\t\tmodel: options.registeredModel.id,\n\t\t\tprovider: options.registeredModel.provider,\n\t\t\trole: options.role,\n\t\t\tthinking_level: options.thinkingLevel,\n\t\t\tapproval_mode: options.approvalMode,\n\t\t\tclient: options.input.client ?? \"generic\",\n\t\t\tprotocol_version: options.input.protocolVersion,\n\t\t\tworkspace_root: options.workspaceRoot,\n\t\t\trunner_session_id: hostedRunner?.runnerSessionId,\n\t\t\towner_instance_id: hostedRunner?.ownerInstanceId,\n\t\t\tagent_id: hostedRunner?.agentId,\n\t\t},\n\t});\n\tif (!hostedRunner || !result) {\n\t\treturn;\n\t}\n\tconst a2aCorrelation = result.events.find(\n\t\t(event) => event.type === \"maestro.platform_runtime.a2a_correlated\",\n\t)?.attributes;\n\tbindHostedRunnerPlatformLease(hostedRunner, {\n\t\tagentRunId: result.run.id,\n\t\tagentId: result.run.linkage?.agentId,\n\t\tleaseToken: result.run.lease?.token,\n\t});\n\t// Store only support-grade handles on the hosted runner. The full run/task\n\t// state stays in Platform; health and identity endpoints expose these ids\n\t// for operators without making Platform a session-state dependency.\n\thostedRunner.a2aMessageId = a2aCorrelation\n\t\t? stringAttribute(a2aCorrelation, \"a2a_message_id\")\n\t\t: undefined;\n\thostedRunner.a2aTaskId = a2aCorrelation\n\t\t? stringAttribute(a2aCorrelation, \"a2a_task_id\")\n\t\t: undefined;\n\thostedRunner.agentRuntimeWorkerQueue = a2aCorrelation\n\t\t? stringAttribute(a2aCorrelation, \"worker_queue\")\n\t\t: undefined;\n\thostedRunner.agentRuntimeCorrelationPath = a2aCorrelation\n\t\t? stringAttribute(a2aCorrelation, \"correlation_path\")\n\t\t: undefined;\n}\n\nfunction stringAttribute(\n\tattributes: Record<string, unknown>,\n\tkey: string,\n): string | undefined {\n\tconst value = attributes[key];\n\treturn typeof value === \"string\" && value.trim().length > 0\n\t\t? value\n\t\t: undefined;\n}\n\nasync function ensureConnection(\n\treq: IncomingMessage,\n\tcontext: WebServerContext,\n\tinput: HeadlessConnectionCreateInput,\n): Promise<HeadlessRuntimeConnectionSnapshot> {\n\tconst runtime = await ensureRuntime(req, context, {\n\t\t...input,\n\t\tregisterConnection: false,\n\t\trecordAgentRuntimeTrigger: false,\n\t});\n\tconst role = getHeadlessRole(req, input.role);\n\tconst heartbeat = runtime.registerConnection({\n\t\tconnectionId: input.connectionId,\n\t\tclientProtocolVersion: input.protocolVersion,\n\t\tclientInfo: input.clientInfo,\n\t\tcapabilities: input.capabilities\n\t\t\t? {\n\t\t\t\t\tserver_requests: input.capabilities.serverRequests,\n\t\t\t\t\tutility_operations: input.capabilities.utilityOperations,\n\t\t\t\t\traw_agent_events: input.capabilities.rawAgentEvents,\n\t\t\t\t}\n\t\t\t: undefined,\n\t\toptOutNotifications: input.optOutNotifications,\n\t\trole,\n\t\ttakeControl: input.takeControl,\n\t});\n\tconst snapshot = runtime.getSnapshot();\n\treturn {\n\t\t...heartbeat,\n\t\tsession_id: snapshot.session_id,\n\t\trole,\n\t\topt_out_notifications: input.optOutNotifications,\n\t\tsnapshot,\n\t};\n}\n\nfunction getRuntime(\n\treq: IncomingMessage,\n\tcontext: WebServerContext,\n\tsessionId: string | undefined,\n) {\n\tif (!sessionId) {\n\t\tthrow new ApiError(400, \"Missing headless session id\");\n\t}\n\tensureHostedRunnerCanUseSession(context, sessionId);\n\tconst runtime = context.headlessRuntimeService.getRuntime(\n\t\tgetScopeKey(req),\n\t\tsessionId,\n\t);\n\tif (!runtime) {\n\t\tthrow new ApiError(404, \"Headless session not found\");\n\t}\n\tif (context.hostedRunner) {\n\t\tclaimHostedRunnerSession(context, runtime.getSnapshot().session_id);\n\t}\n\treturn runtime;\n}\n\nexport async function handleHeadlessSessionCreate(\n\treq: IncomingMessage,\n\tres: ServerResponse,\n\tcontext: WebServerContext,\n) {\n\tconst input = await parseAndValidateJson<HeadlessSessionCreateInput>(\n\t\treq,\n\t\tHeadlessSessionCreateSchema,\n\t);\n\tconst runtime = await ensureRuntime(req, context, input);\n\tsendJson(res, 200, runtime.getSnapshot(), context.corsHeaders, req);\n}\n\nexport async function handleHeadlessConnectionCreate(\n\treq: IncomingMessage,\n\tres: ServerResponse,\n\tcontext: WebServerContext,\n) {\n\tconst input = await parseAndValidateJson<HeadlessConnectionCreateInput>(\n\t\treq,\n\t\tHeadlessConnectionCreateSchema,\n\t);\n\tlet connection: HeadlessRuntimeConnectionSnapshot;\n\ttry {\n\t\tconnection = await ensureConnection(req, context, input);\n\t} catch (error) {\n\t\trethrowHeadlessConnectionLifecycleError(error);\n\t}\n\tsendJson(res, 200, connection, context.corsHeaders, req);\n}\n\nexport function handleHeadlessSessionState(\n\treq: IncomingMessage,\n\tres: ServerResponse,\n\tcontext: WebServerContext,\n\tparams?: Record<string, string>,\n) {\n\tconst runtime = getRuntime(req, context, params?.id);\n\tsendJson(res, 200, runtime.getSnapshot(), context.corsHeaders, req);\n}\n\nexport async function handleHeadlessSessionSubscribe(\n\treq: IncomingMessage,\n\tres: ServerResponse,\n\tcontext: WebServerContext,\n\tparams?: Record<string, string>,\n) {\n\tconst runtime = getRuntime(req, context, params?.id);\n\tconst input = await parseAndValidateJson<HeadlessSessionSubscribeInput>(\n\t\treq,\n\t\tHeadlessSessionSubscribeSchema,\n\t);\n\tconst role = getHeadlessRole(req, input.role);\n\tconst disallowedViewerRequest = getViewerDisallowedServerRequest(\n\t\tinput.capabilities?.serverRequests,\n\t);\n\tif (role === \"viewer\" && disallowedViewerRequest) {\n\t\tthrow new ApiError(\n\t\t\t400,\n\t\t\t`viewer headless connections cannot negotiate ${disallowedViewerRequest} requests`,\n\t\t);\n\t}\n\ttry {\n\t\tsendJson(\n\t\t\tres,\n\t\t\t200,\n\t\t\truntime.createSubscription({\n\t\t\t\tconnectionId: input.connectionId,\n\t\t\t\trole,\n\t\t\t\texplicit: true,\n\t\t\t\ttakeControl: input.takeControl,\n\t\t\t\tclientProtocolVersion: input.protocolVersion,\n\t\t\t\tclientInfo: input.clientInfo,\n\t\t\t\tcapabilities: input.capabilities\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tserver_requests: input.capabilities.serverRequests,\n\t\t\t\t\t\t\tutility_operations: input.capabilities.utilityOperations,\n\t\t\t\t\t\t\traw_agent_events: input.capabilities.rawAgentEvents,\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined,\n\t\t\t\toptOutNotifications: input.optOutNotifications,\n\t\t\t}),\n\t\t\tcontext.corsHeaders,\n\t\t\treq,\n\t\t);\n\t} catch (error) {\n\t\tif (\n\t\t\terror instanceof Error &&\n\t\t\terror.message === \"Controller lease is already held by another connection\"\n\t\t) {\n\t\t\tthrow new ApiError(409, error.message);\n\t\t}\n\t\tif (\n\t\t\terror instanceof Error &&\n\t\t\t(error.message === \"Headless connection not found\" ||\n\t\t\t\terror.message ===\n\t\t\t\t\t\"Headless connection role does not match subscription role\")\n\t\t) {\n\t\t\tthrow new ApiError(400, error.message);\n\t\t}\n\t\tthrow error;\n\t}\n}\n\nexport async function handleHeadlessSessionUnsubscribe(\n\treq: IncomingMessage,\n\tres: ServerResponse,\n\tcontext: WebServerContext,\n\tparams?: Record<string, string>,\n) {\n\tconst runtime = getRuntime(req, context, params?.id);\n\tconst input = await parseAndValidateJson<HeadlessSessionUnsubscribeInput>(\n\t\treq,\n\t\tHeadlessSessionUnsubscribeSchema,\n\t);\n\tif (!(await runtime.unsubscribe(input.subscriptionId))) {\n\t\tthrow new ApiError(404, \"Headless subscriber not found\");\n\t}\n\tsendJson(res, 200, { success: true }, context.corsHeaders, req);\n}\n\nexport async function handleHeadlessSessionHeartbeat(\n\treq: IncomingMessage,\n\tres: ServerResponse,\n\tcontext: WebServerContext,\n\tparams?: Record<string, string>,\n) {\n\tconst runtime = getRuntime(req, context, params?.id);\n\tconst input = await parseAndValidateJson<HeadlessSessionHeartbeatInput>(\n\t\treq,\n\t\tHeadlessSessionHeartbeatSchema,\n\t);\n\tlet heartbeat: HeadlessRuntimeHeartbeatSnapshot;\n\ttry {\n\t\theartbeat = runtime.heartbeatConnection({\n\t\t\tconnectionId: input.connectionId ?? getHeadlessConnectionId(req),\n\t\t\tsubscriptionId: input.subscriptionId ?? getHeadlessSubscriberId(req),\n\t\t});\n\t} catch (error) {\n\t\trethrowHeadlessConnectionLifecycleError(error);\n\t}\n\tsendJson(res, 200, heartbeat, context.corsHeaders, req);\n}\n\nexport async function handleHeadlessSessionDisconnect(\n\treq: IncomingMessage,\n\tres: ServerResponse,\n\tcontext: WebServerContext,\n\tparams?: Record<string, string>,\n) {\n\tconst runtime = getRuntime(req, context, params?.id);\n\tconst input = await parseAndValidateJson<HeadlessSessionDisconnectInput>(\n\t\treq,\n\t\tHeadlessSessionDisconnectSchema,\n\t);\n\ttry {\n\t\tsendJson(\n\t\t\tres,\n\t\t\t200,\n\t\t\tawait runtime.disconnectConnection({\n\t\t\t\tconnectionId: input.connectionId ?? getHeadlessConnectionId(req),\n\t\t\t\tsubscriptionId: input.subscriptionId ?? getHeadlessSubscriberId(req),\n\t\t\t}),\n\t\t\tcontext.corsHeaders,\n\t\t\treq,\n\t\t);\n\t} catch (error) {\n\t\trethrowHeadlessConnectionLifecycleError(error);\n\t}\n}\n\nexport function handleHeadlessSessionEvents(\n\treq: IncomingMessage,\n\tres: ServerResponse,\n\tcontext: WebServerContext,\n\tparams?: Record<string, string>,\n) {\n\tconst runtime = getRuntime(req, context, params?.id);\n\tconst url = new URL(\n\t\treq.url || `/api/headless/sessions/${params?.id}/events`,\n\t\t`http://${req.headers.host || \"localhost\"}`,\n\t);\n\tconst cursorParam = url.searchParams.get(\"cursor\");\n\tconst cursor = cursorParam ? Number.parseInt(cursorParam, 10) : null;\n\tconst subscriptionId =\n\t\turl.searchParams.get(\"subscriptionId\") || getHeadlessSubscriberId(req);\n\n\tconst stream = subscriptionId\n\t\t? runtime.attachSubscription(subscriptionId)\n\t\t: runtime.createImplicitStream({\n\t\t\t\tcursor,\n\t\t\t\trole: getHeadlessRole(req),\n\t\t\t\toptOutNotifications: parseOptOutNotifications(req),\n\t\t\t});\n\tif (!stream) {\n\t\tthrow new ApiError(404, \"Headless subscriber not found\");\n\t}\n\n\tres.writeHead(200, {\n\t\t\"Content-Type\": \"text/event-stream\",\n\t\t\"Cache-Control\": \"no-cache\",\n\t\tConnection: \"keep-alive\",\n\t\t...context.corsHeaders,\n\t});\n\tlet flushing = false;\n\n\tconst flush = () => {\n\t\tif (flushing || res.writableEnded) {\n\t\t\treturn;\n\t\t}\n\t\tflushing = true;\n\t\twhile (!res.writableEnded) {\n\t\t\tconst next = stream.next();\n\t\t\tif (!next) {\n\t\t\t\tflushing = false;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst wrote = writeSse(res, next);\n\t\t\tif (!wrote) {\n\t\t\t\tres.once(\"drain\", () => {\n\t\t\t\t\tflushing = false;\n\t\t\t\t\tflush();\n\t\t\t\t});\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tflushing = false;\n\t};\n\tconst stopListening = stream.onAvailable(flush);\n\tconst heartbeat = setInterval(() => {\n\t\tif (!res.writableEnded) {\n\t\t\tstream.enqueue(runtime.heartbeat());\n\t\t\tflush();\n\t\t}\n\t}, 15000);\n\theartbeat.unref();\n\n\tconst cleanup = () => {\n\t\tclearInterval(heartbeat);\n\t\tstopListening();\n\t\tstream.close();\n\t};\n\treq.on(\"close\", cleanup);\n\tres.on(\"close\", cleanup);\n\tflush();\n}\n\nexport async function handleHeadlessSessionMessage(\n\treq: IncomingMessage,\n\tres: ServerResponse,\n\tcontext: WebServerContext,\n\tparams?: Record<string, string>,\n) {\n\tconst runtime = getRuntime(req, context, params?.id);\n\tconst input = await parseHeadlessMessage(req);\n\ttry {\n\t\truntime.assertCanSend(\n\t\t\tgetHeadlessRole(req),\n\t\t\tgetHeadlessSubscriberId(req),\n\t\t\tgetHeadlessConnectionId(req),\n\t\t);\n\t} catch (error) {\n\t\trethrowHeadlessMessageError(error);\n\t}\n\ttry {\n\t\tawait runtime.send(input as HeadlessToAgentMessage, {\n\t\t\tconnectionId: getHeadlessConnectionId(req),\n\t\t\tsubscriptionId: getHeadlessSubscriberId(req),\n\t\t});\n\t} catch (error) {\n\t\trethrowHeadlessMessageError(error);\n\t}\n\tsendJson(res, 200, { success: true }, context.corsHeaders, req);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-artifacts.d.ts","sourceRoot":"","sources":["../../../src/server/handlers/session-artifacts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE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,EACpB,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EACtB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,iBA6C5B"}
|
|
@@ -129,6 +129,21 @@ function injectArtifactsSnapshotRuntime(htmlContent, artifacts) {
|
|
|
129
129
|
function asString(value) {
|
|
130
130
|
return typeof value === "string" ? value : undefined;
|
|
131
131
|
}
|
|
132
|
+
function hasControlCharacter(value) {
|
|
133
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
134
|
+
const code = value.charCodeAt(index);
|
|
135
|
+
if (code < 32 || code === 127)
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
function isValidArtifactFilename(filename) {
|
|
141
|
+
return (filename.length > 0 &&
|
|
142
|
+
!filename.includes("..") &&
|
|
143
|
+
!filename.includes("/") &&
|
|
144
|
+
!filename.includes("\\") &&
|
|
145
|
+
!hasControlCharacter(filename));
|
|
146
|
+
}
|
|
132
147
|
function reconstructArtifactsFromMessages(messages) {
|
|
133
148
|
const byFilename = new Map();
|
|
134
149
|
for (const msg of messages) {
|
|
@@ -150,6 +165,8 @@ function reconstructArtifactsFromMessages(messages) {
|
|
|
150
165
|
const filename = asString(args.filename)?.trim();
|
|
151
166
|
if (!command || !filename)
|
|
152
167
|
continue;
|
|
168
|
+
if (!isValidArtifactFilename(filename))
|
|
169
|
+
continue;
|
|
153
170
|
if (command === "get" || command === "logs")
|
|
154
171
|
continue;
|
|
155
172
|
if (command === "create") {
|
|
@@ -172,6 +189,8 @@ function reconstructArtifactsFromMessages(messages) {
|
|
|
172
189
|
const newStr = asString(args.new_str);
|
|
173
190
|
if (oldStr === undefined || newStr === undefined)
|
|
174
191
|
continue;
|
|
192
|
+
if (oldStr.length === 0)
|
|
193
|
+
continue;
|
|
175
194
|
if (!current.includes(oldStr))
|
|
176
195
|
continue;
|
|
177
196
|
byFilename.set(filename, current.replace(oldStr, newStr));
|
|
@@ -194,9 +213,7 @@ async function loadComposerMessages(req, sessionId) {
|
|
|
194
213
|
}
|
|
195
214
|
function validateFilename(filename) {
|
|
196
215
|
// Keep this strict: no path traversal, no folder hierarchies.
|
|
197
|
-
if (filename.
|
|
198
|
-
filename.includes("/") ||
|
|
199
|
-
filename.includes("\\")) {
|
|
216
|
+
if (!isValidArtifactFilename(filename.trim())) {
|
|
200
217
|
throw new ApiError(400, "Invalid filename");
|
|
201
218
|
}
|
|
202
219
|
}
|