hyperbrane 0.1.2 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +105 -23
- package/dist/agent/agentClient.d.ts +5 -0
- package/dist/agent/agentClient.js +4 -0
- package/dist/agent/agentService.d.ts +9 -37
- package/dist/agent/agentService.js +64 -323
- package/dist/agent/agentStorage.d.ts +1 -20
- package/dist/agent/agentStorage.js +0 -30
- package/dist/agent/api.d.ts +105 -152
- package/dist/agent/api.js +1 -8
- package/dist/agent/client.d.ts +3 -1
- package/dist/agent/client.js +2 -3
- package/dist/agent/control.d.ts +23 -0
- package/dist/agent/control.js +479 -0
- package/dist/agent/dimensionAgentClient.d.ts +8 -0
- package/dist/agent/dimensionAgentClient.js +99 -0
- package/dist/agent/hostTranscript.d.ts +0 -6
- package/dist/agent/hostTranscript.js +3 -14
- package/dist/agent/session/backend.d.ts +18 -32
- package/dist/agent/session/claude/home.d.ts +0 -1
- package/dist/agent/session/claude/home.js +0 -1
- package/dist/agent/session/claude/provision.d.ts +10 -0
- package/dist/agent/session/claude/provision.js +17 -0
- package/dist/agent/session/claude/transcript.d.ts +3 -7
- package/dist/agent/session/claude/transcript.js +68 -14
- package/dist/agent/session/client.d.ts +1 -10
- package/dist/agent/session/client.js +0 -3
- package/dist/agent/session/codex/provision.d.ts +14 -0
- package/dist/agent/session/codex/provision.js +25 -0
- package/dist/agent/session/fileTranscript.d.ts +6 -49
- package/dist/agent/session/fileTranscript.js +26 -82
- package/dist/agent/session/install.d.ts +5 -0
- package/dist/agent/session/install.js +35 -0
- package/dist/agent/session/sessionStorage.d.ts +4 -35
- package/dist/agent/session/sessionStorage.js +10 -16
- package/dist/agent/session/sharedConnection.d.ts +0 -8
- package/dist/agent/session/sharedConnection.js +0 -7
- package/dist/agent/session/storedTranscripts.d.ts +1 -6
- package/dist/agent/session/storedTranscripts.js +0 -3
- package/dist/agent/session/worker/jsonRpc.d.ts +2 -13
- package/dist/agent/session/worker/jsonRpc.js +2 -11
- package/dist/agent/session/worker/protocol.d.ts +30 -21
- package/dist/agent/session/worker/protocol.js +29 -18
- package/dist/agent/session/worker/workerParams.d.ts +0 -5
- package/dist/agent/session/worker/workerParams.js +24 -17
- package/dist/agent/session/workerConnection.d.ts +2 -13
- package/dist/agent/session/workerConnection.js +7 -12
- package/dist/agent/session/workerGatewayConnection.d.ts +18 -0
- package/dist/agent/session/workerGatewayConnection.js +86 -0
- package/dist/agent/vendor-types/manifest.json +32 -0
- package/dist/agent/workerBundle.d.ts +4 -19
- package/dist/agent/workerBundle.generated.js +1 -1
- package/dist/agent/workerBundle.js +3 -30
- package/dist/agent/workerReplacement.d.ts +3 -0
- package/dist/agent/workerReplacement.js +49 -0
- package/dist/cli/agent.js +31 -16
- package/dist/cli/command.d.ts +10 -11
- package/dist/cli/command.js +0 -4
- package/dist/cli/dimension.js +6 -6
- package/dist/cli/gateway.js +3 -6
- package/dist/cli/main.js +14 -31
- package/dist/cli/streamPrinter.d.ts +2 -10
- package/dist/cli/streamPrinter.js +16 -46
- package/dist/cli/table.d.ts +0 -3
- package/dist/cli/table.js +0 -4
- package/dist/dimension/api.d.ts +42 -27
- package/dist/dimension/api.js +28 -47
- package/dist/dimension/client.d.ts +5 -0
- package/dist/dimension/client.js +4 -0
- package/dist/dimension/control.d.ts +22 -0
- package/dist/dimension/control.js +346 -0
- package/dist/dimension/image.d.ts +0 -5
- package/dist/dimension/image.js +0 -8
- package/dist/dimension/imageFiles.generated.js +1 -1
- package/dist/dimension/paths.d.ts +5 -4
- package/dist/dimension/paths.js +15 -6
- package/dist/dimension/service.d.ts +8 -24
- package/dist/dimension/service.js +85 -227
- package/dist/dimension/transport-worker.d.ts +1 -0
- package/dist/dimension/transport-worker.js +151 -0
- package/dist/dimension/transportBundle.d.ts +2 -0
- package/dist/dimension/transportBundle.generated.d.ts +1 -0
- package/dist/dimension/transportBundle.generated.js +2 -0
- package/dist/dimension/transportBundle.js +4 -0
- package/dist/dimension/transportClient.d.ts +10 -0
- package/dist/dimension/transportClient.js +115 -0
- package/dist/dimension/transportProtocol.d.ts +53 -0
- package/dist/dimension/transportProtocol.js +8 -0
- package/dist/index.d.ts +7 -9
- package/dist/index.js +7 -19
- package/dist/lib/control.d.ts +11 -0
- package/dist/lib/control.js +62 -0
- package/dist/lib/docker.d.ts +0 -22
- package/dist/lib/docker.js +0 -10
- package/dist/lib/image.d.ts +0 -3
- package/dist/lib/image.js +0 -2
- package/dist/lib/jsonDirectory.d.ts +0 -13
- package/dist/lib/jsonDirectory.js +34 -18
- package/dist/lib/scriptBundle.d.ts +6 -0
- package/dist/lib/scriptBundle.js +28 -0
- package/dist/lib/sh.d.ts +2 -0
- package/dist/lib/sh.js +8 -0
- package/dist/lib/sleep.d.ts +0 -1
- package/dist/lib/sleep.js +0 -1
- package/dist/lib/streamFetch.d.ts +15 -0
- package/dist/lib/streamFetch.js +150 -0
- package/dist/lib/tar.d.ts +0 -1
- package/dist/lib/tar.js +5 -11
- package/dist/lib/unixSocket.d.ts +2 -0
- package/dist/lib/unixSocket.js +28 -0
- package/dist/portal-gateway/api.d.ts +14 -44
- package/dist/portal-gateway/api.js +1 -3
- package/dist/portal-gateway/control.d.ts +42 -0
- package/dist/portal-gateway/control.js +657 -0
- package/dist/portal-gateway/gatewayClient.d.ts +5 -0
- package/dist/portal-gateway/gatewayClient.js +4 -0
- package/dist/portal-gateway/gatewayService.d.ts +8 -38
- package/dist/portal-gateway/gatewayService.js +82 -254
- package/dist/portal-gateway/image.d.ts +0 -1
- package/dist/portal-gateway/image.js +0 -2
- package/dist/portal-gateway/imageFiles.generated.js +2 -2
- package/dist/portal-gateway/portalClient.d.ts +5 -0
- package/dist/portal-gateway/portalClient.js +4 -0
- package/dist/portal-gateway/portalService.d.ts +5 -47
- package/dist/portal-gateway/portalService.js +19 -349
- package/dist/portal-gateway/transport-worker.d.ts +1 -0
- package/dist/portal-gateway/transport-worker.js +205 -0
- package/dist/portal-gateway/transportBundle.d.ts +2 -0
- package/dist/portal-gateway/transportBundle.generated.d.ts +1 -0
- package/dist/portal-gateway/transportBundle.generated.js +2 -0
- package/dist/portal-gateway/transportBundle.js +4 -0
- package/dist/portal-gateway/upstream.d.ts +0 -81
- package/dist/portal-gateway/upstream.js +0 -1
- package/dist/restore.d.ts +9 -0
- package/dist/restore.js +10 -0
- package/dist/sandbox/api.d.ts +126 -187
- package/dist/sandbox/api.js +5 -7
- package/dist/sandbox/client.d.ts +3 -0
- package/dist/sandbox/client.js +7 -0
- package/dist/sandbox/data-endpoints/dataEndpoints.d.ts +13 -0
- package/dist/sandbox/data-endpoints/dataEndpoints.js +100 -0
- package/dist/sandbox/data-endpoints/firewalledPorts.d.ts +4 -0
- package/dist/sandbox/data-endpoints/firewalledPorts.js +28 -0
- package/dist/sandbox/lib/httpOverStream.d.ts +3 -0
- package/dist/sandbox/lib/httpOverStream.js +21 -0
- package/dist/sandbox/lib/remoteFileOperations.d.ts +10 -0
- package/dist/sandbox/lib/remoteFileOperations.js +70 -0
- package/dist/sandbox/lib/shellCommand.d.ts +3 -0
- package/dist/sandbox/lib/shellCommand.js +7 -0
- package/dist/sandbox/lib/sshKey.d.ts +6 -0
- package/dist/sandbox/lib/sshKey.js +75 -0
- package/dist/sandbox/providers/boat/boatService.d.ts +3 -0
- package/dist/sandbox/providers/boat/boatService.js +373 -0
- package/dist/sandbox/providers/exedev/exeDevService.d.ts +2 -0
- package/dist/sandbox/providers/exedev/exeDevService.js +129 -0
- package/dist/sandbox/providers/exedev/exeDevToken.d.ts +1 -0
- package/dist/sandbox/providers/exedev/exeDevToken.js +50 -0
- package/dist/sandbox/providers/local/localService.d.ts +2 -0
- package/dist/sandbox/providers/local/localService.js +197 -0
- package/dist/sandbox/providers/ssh/sshService.d.ts +2 -0
- package/dist/sandbox/providers/ssh/sshService.js +83 -0
- package/dist/sandbox/providers/ssh/sshTransport.d.ts +12 -0
- package/dist/sandbox/providers/ssh/sshTransport.js +216 -0
- package/dist/sandbox/service.d.ts +3 -0
- package/dist/sandbox/service.js +26 -0
- package/dist/sandbox/storage/descriptors.d.ts +6 -0
- package/dist/sandbox/storage/descriptors.js +25 -0
- package/dist/sandbox/storage/sandboxStorage.d.ts +11 -0
- package/dist/sandbox/storage/sandboxStorage.js +42 -0
- package/dist/upstreams/anthropic.d.ts +0 -5
- package/dist/upstreams/anthropic.js +1 -8
- package/dist/upstreams/index.d.ts +2 -6
- package/dist/upstreams/index.js +0 -4
- package/dist/upstreams/openai.d.ts +0 -5
- package/dist/upstreams/openai.js +1 -13
- package/dist/vendor-types/claude/agent-sdk/bridge.d.ts +20 -4
- package/dist/vendor-types/claude/agent-sdk/browser-sdk.d.ts +24 -0
- package/dist/vendor-types/claude/agent-sdk/core.d.ts +2 -0
- package/dist/vendor-types/claude/agent-sdk/sdk-tools.d.ts +75 -6
- package/dist/vendor-types/claude/agent-sdk/sdk.d.ts +569 -100
- package/package.json +13 -4
- package/dist/agent/gatewaySignIns.d.ts +0 -5
- package/dist/agent/gatewaySignIns.js +0 -11
- package/dist/agent/session/codex/home.d.ts +0 -2
- package/dist/agent/session/codex/home.js +0 -4
- package/dist/agent/session/codex/messages.d.ts +0 -30
- package/dist/agent/session/codex/messages.js +0 -135
- package/dist/agent/session/codex/transcript.d.ts +0 -12
- package/dist/agent/session/codex/transcript.js +0 -22
- package/dist/agent/session/sdkMessages.d.ts +0 -15
- package/dist/agent/session/sdkMessages.js +0 -28
- package/dist/agent/session/workerSseConnection.d.ts +0 -31
- package/dist/agent/session/workerSseConnection.js +0 -76
- package/dist/agent/vendor-types/codex/app-server/AbsolutePathBuf.d.ts +0 -10
- package/dist/agent/vendor-types/codex/app-server/AbsolutePathBuf.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/FunctionCallOutputBody.d.ts +0 -2
- package/dist/agent/vendor-types/codex/app-server/FunctionCallOutputBody.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/FunctionCallOutputContentItem.d.ts +0 -22
- package/dist/agent/vendor-types/codex/app-server/FunctionCallOutputContentItem.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/ImageDetail.d.ts +0 -1
- package/dist/agent/vendor-types/codex/app-server/ImageDetail.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/ImageGenerationFailure.d.ts +0 -5
- package/dist/agent/vendor-types/codex/app-server/ImageGenerationFailure.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/ImageGenerationItem.d.ts +0 -11
- package/dist/agent/vendor-types/codex/app-server/ImageGenerationItem.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/LegacyAppPathString.d.ts +0 -23
- package/dist/agent/vendor-types/codex/app-server/LegacyAppPathString.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/MessagePhase.d.ts +0 -7
- package/dist/agent/vendor-types/codex/app-server/MessagePhase.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/ReasoningEffort.d.ts +0 -4
- package/dist/agent/vendor-types/codex/app-server/ReasoningEffort.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/SleepItem.d.ts +0 -7
- package/dist/agent/vendor-types/codex/app-server/SleepItem.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/WebSearchItem.d.ts +0 -14
- package/dist/agent/vendor-types/codex/app-server/WebSearchItem.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/serde_json/JsonValue.d.ts +0 -3
- package/dist/agent/vendor-types/codex/app-server/serde_json/JsonValue.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/AgentMessageDelivery.d.ts +0 -1
- package/dist/agent/vendor-types/codex/app-server/v2/AgentMessageDelivery.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/AsyncUserInputQuestion.d.ts +0 -4
- package/dist/agent/vendor-types/codex/app-server/v2/AsyncUserInputQuestion.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/ByteRange.d.ts +0 -4
- package/dist/agent/vendor-types/codex/app-server/v2/ByteRange.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/CollabAgentState.d.ts +0 -5
- package/dist/agent/vendor-types/codex/app-server/v2/CollabAgentState.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/CollabAgentStatus.d.ts +0 -1
- package/dist/agent/vendor-types/codex/app-server/v2/CollabAgentStatus.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/CollabAgentTool.d.ts +0 -1
- package/dist/agent/vendor-types/codex/app-server/v2/CollabAgentTool.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/CollabAgentToolCallStatus.d.ts +0 -1
- package/dist/agent/vendor-types/codex/app-server/v2/CollabAgentToolCallStatus.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/CommandAction.d.ts +0 -19
- package/dist/agent/vendor-types/codex/app-server/v2/CommandAction.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/CommandExecutionSource.d.ts +0 -1
- package/dist/agent/vendor-types/codex/app-server/v2/CommandExecutionSource.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/CommandExecutionStatus.d.ts +0 -1
- package/dist/agent/vendor-types/codex/app-server/v2/CommandExecutionStatus.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/DynamicToolCallOutputContentItem.d.ts +0 -10
- package/dist/agent/vendor-types/codex/app-server/v2/DynamicToolCallOutputContentItem.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/DynamicToolCallStatus.d.ts +0 -1
- package/dist/agent/vendor-types/codex/app-server/v2/DynamicToolCallStatus.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/FileUpdateChange.d.ts +0 -6
- package/dist/agent/vendor-types/codex/app-server/v2/FileUpdateChange.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/HookPromptFragment.d.ts +0 -4
- package/dist/agent/vendor-types/codex/app-server/v2/HookPromptFragment.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/McpAppDisplayMode.d.ts +0 -1
- package/dist/agent/vendor-types/codex/app-server/v2/McpAppDisplayMode.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/McpAppUi.d.ts +0 -8
- package/dist/agent/vendor-types/codex/app-server/v2/McpAppUi.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/McpToolCallAppContext.d.ts +0 -7
- package/dist/agent/vendor-types/codex/app-server/v2/McpToolCallAppContext.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/McpToolCallError.d.ts +0 -3
- package/dist/agent/vendor-types/codex/app-server/v2/McpToolCallError.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/McpToolCallResult.d.ts +0 -6
- package/dist/agent/vendor-types/codex/app-server/v2/McpToolCallResult.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/McpToolCallStatus.d.ts +0 -1
- package/dist/agent/vendor-types/codex/app-server/v2/McpToolCallStatus.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/MemoryCitation.d.ts +0 -5
- package/dist/agent/vendor-types/codex/app-server/v2/MemoryCitation.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/MemoryCitationEntry.d.ts +0 -6
- package/dist/agent/vendor-types/codex/app-server/v2/MemoryCitationEntry.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/PatchApplyStatus.d.ts +0 -1
- package/dist/agent/vendor-types/codex/app-server/v2/PatchApplyStatus.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/PatchChangeKind.d.ts +0 -8
- package/dist/agent/vendor-types/codex/app-server/v2/PatchChangeKind.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/SubAgentActivityKind.d.ts +0 -1
- package/dist/agent/vendor-types/codex/app-server/v2/SubAgentActivityKind.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/TextElement.d.ts +0 -11
- package/dist/agent/vendor-types/codex/app-server/v2/TextElement.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/ThreadItem.d.ts +0 -215
- package/dist/agent/vendor-types/codex/app-server/v2/ThreadItem.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/UserInput.d.ts +0 -35
- package/dist/agent/vendor-types/codex/app-server/v2/UserInput.js +0 -2
- package/dist/agent/vendor-types/codex/app-server/v2/WebSearchAction.d.ts +0 -14
- package/dist/agent/vendor-types/codex/app-server/v2/WebSearchAction.js +0 -2
- package/dist/cli/services.d.ts +0 -19
- package/dist/cli/services.js +0 -34
- package/dist/dimension/http.d.ts +0 -7
- package/dist/dimension/http.js +0 -77
- package/dist/dimension/storage.d.ts +0 -39
- package/dist/dimension/storage.js +0 -79
- package/dist/portal-gateway/fakes.d.ts +0 -3
- package/dist/portal-gateway/fakes.js +0 -11
- package/dist/portal-gateway/gatewayStorage.d.ts +0 -66
- package/dist/portal-gateway/gatewayStorage.js +0 -125
- package/dist/portal-gateway/portalStorage.d.ts +0 -34
- package/dist/portal-gateway/portalStorage.js +0 -44
- package/dist/sandbox/boatService.d.ts +0 -52
- package/dist/sandbox/boatService.js +0 -343
- package/dist/sandbox/containerService.d.ts +0 -15
- package/dist/sandbox/containerService.js +0 -184
- package/dist/sandbox/endpointProxy.d.ts +0 -90
- package/dist/sandbox/endpointProxy.js +0 -716
- package/dist/sandbox/exeDevAuth.d.ts +0 -16
- package/dist/sandbox/exeDevAuth.js +0 -49
- package/dist/sandbox/localService.d.ts +0 -19
- package/dist/sandbox/localService.js +0 -200
- package/dist/sandbox/sseConnection.d.ts +0 -41
- package/dist/sandbox/sseConnection.js +0 -166
- package/dist/sandbox/sshService.d.ts +0 -30
- package/dist/sandbox/sshService.js +0 -680
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
import { type AgentAuthStatus, type AgentBackend, type AgentBackendInfo, type AgentBackgroundTask, type AgentLastUserMessage, type AgentModelInfo, type AgentPermissionRequest, type AgentPermissionResult, type AgentQuestionRequest, type AgentQuestionResponse, type AgentSession, type AgentSessionInfo, type
|
|
1
|
+
import { type AgentAuthStatus, type AgentBackend, type AgentBackendInfo, type AgentBackgroundTask, type AgentLastUserMessage, type AgentModelInfo, type AgentPermissionRequest, type AgentPermissionResult, type AgentQuestionRequest, type AgentQuestionResponse, type AgentSession, type AgentSessionInfo, type AgentSessionUpdate, type AgentSessionState, type AgentPermissionMode, type AgentStreamingMessage, type AgentTranscriptPage, type AgentTurnUsage, type UserMessage } from "../../api.ts";
|
|
2
2
|
import type { JsonRpcErrorObject } from "./jsonRpc.ts";
|
|
3
|
-
/**
|
|
4
|
-
* The worker's JSON-RPC protocol, spoken over its unix socket (see createWorkerServer): method ->
|
|
5
|
-
* [params, result]. Sessions are named by `session`; everything answers `null` unless it says.
|
|
6
|
-
* worker/health and worker/shutdown are how the host tells a worker's build and replaces it: they
|
|
7
|
-
* never change.
|
|
8
|
-
*
|
|
9
|
-
* @sealed
|
|
10
|
-
*/
|
|
3
|
+
/** @sealed */
|
|
11
4
|
export type WorkerRequests = {
|
|
12
5
|
"worker/health": [Record<string, never>, WorkerHealth];
|
|
13
|
-
/** Answers, then stops the sessions' CLIs and exits. */
|
|
14
6
|
"worker/shutdown": [Record<string, never>, null];
|
|
15
7
|
"backend/install": [{
|
|
16
8
|
backend: AgentBackend;
|
|
@@ -22,7 +14,7 @@ export type WorkerRequests = {
|
|
|
22
14
|
"session/list": [Record<string, never>, AgentSessionInfo[]];
|
|
23
15
|
"session/update": [{
|
|
24
16
|
session: string;
|
|
25
|
-
|
|
17
|
+
update: AgentSessionUpdate;
|
|
26
18
|
}, AgentSessionInfo];
|
|
27
19
|
"session/stop": [{
|
|
28
20
|
session: string;
|
|
@@ -40,12 +32,6 @@ export type WorkerRequests = {
|
|
|
40
32
|
"session/lastUserMessages": [{
|
|
41
33
|
session: string;
|
|
42
34
|
}, AgentLastUserMessage[]];
|
|
43
|
-
/**
|
|
44
|
-
* Streams the session's messages as `session/message` notifications carrying `subscription` (the
|
|
45
|
-
* client's own id for the stream): first the complete messages after `after_id` (all of them when
|
|
46
|
-
* omitted) from the backend's transcript, then each message as it comes, until session/unsubscribe
|
|
47
|
-
* or the connection closes.
|
|
48
|
-
*/
|
|
49
35
|
"session/subscribe": [{
|
|
50
36
|
session: string;
|
|
51
37
|
subscription: string;
|
|
@@ -60,6 +46,15 @@ export type WorkerRequests = {
|
|
|
60
46
|
before?: string;
|
|
61
47
|
cursor?: string;
|
|
62
48
|
}, AgentTranscriptPage];
|
|
49
|
+
"session/subagentTranscript": [{
|
|
50
|
+
session: string;
|
|
51
|
+
toolUseId: string;
|
|
52
|
+
limit?: number;
|
|
53
|
+
before?: string;
|
|
54
|
+
}, AgentTranscriptPage];
|
|
55
|
+
"session/usage": [{
|
|
56
|
+
session: string;
|
|
57
|
+
}, AgentTurnUsage[]];
|
|
63
58
|
"permission/list": [{
|
|
64
59
|
session: string;
|
|
65
60
|
}, AgentPermissionRequest[]];
|
|
@@ -76,7 +71,6 @@ export type WorkerRequests = {
|
|
|
76
71
|
request: string;
|
|
77
72
|
response: AgentQuestionResponse;
|
|
78
73
|
}, null];
|
|
79
|
-
/** Starts the session's CLI if it isn't running. */
|
|
80
74
|
"model/list": [{
|
|
81
75
|
session: string;
|
|
82
76
|
}, AgentModelInfo[]];
|
|
@@ -84,7 +78,10 @@ export type WorkerRequests = {
|
|
|
84
78
|
session: string;
|
|
85
79
|
model: string | null;
|
|
86
80
|
}, null];
|
|
87
|
-
|
|
81
|
+
"permission/mode": [{
|
|
82
|
+
session: string;
|
|
83
|
+
mode: AgentPermissionMode;
|
|
84
|
+
}, null];
|
|
88
85
|
"task/list": [{
|
|
89
86
|
session: string;
|
|
90
87
|
}, AgentBackgroundTask[]];
|
|
@@ -95,7 +92,6 @@ export type WorkerRequests = {
|
|
|
95
92
|
"auth/status": [{
|
|
96
93
|
session: string;
|
|
97
94
|
}, AgentAuthStatus];
|
|
98
|
-
/** `gatewaySignedIn`: the dimension's gateway holds the backend's upstream credential (the host knows; the worker can't). */
|
|
99
95
|
"auth/login": [{
|
|
100
96
|
session: string;
|
|
101
97
|
gatewaySignedIn: boolean;
|
|
@@ -112,13 +108,26 @@ export type WorkerNotifications = {
|
|
|
112
108
|
message: AgentStreamingMessage;
|
|
113
109
|
};
|
|
114
110
|
};
|
|
111
|
+
export declare const WORKER_PROTOCOL = 6;
|
|
115
112
|
export type WorkerHealth = {
|
|
116
113
|
agentName: string;
|
|
117
114
|
build: string;
|
|
115
|
+
protocol: number;
|
|
116
|
+
};
|
|
117
|
+
export declare const WorkerErrorCode: {
|
|
118
|
+
readonly methodNotFound: -32601;
|
|
119
|
+
readonly invalidParams: -32602;
|
|
120
|
+
readonly internalError: -32603;
|
|
121
|
+
readonly notFound: -32004;
|
|
122
|
+
readonly conflict: -32009;
|
|
123
|
+
readonly backendNotInstalled: -32010;
|
|
124
|
+
readonly protocolMismatch: -32011;
|
|
118
125
|
};
|
|
119
126
|
export declare class WorkerMethodNotFoundError extends Error {
|
|
120
127
|
name: string;
|
|
121
128
|
}
|
|
122
|
-
|
|
129
|
+
export declare class WorkerProtocolMismatchError extends Error {
|
|
130
|
+
name: string;
|
|
131
|
+
}
|
|
123
132
|
export declare function encodeWorkerError(error: unknown): JsonRpcErrorObject;
|
|
124
133
|
export declare function decodeWorkerError({ code, message }: JsonRpcErrorObject): Error;
|
|
@@ -1,37 +1,48 @@
|
|
|
1
1
|
import { AgentBackendNotInstalledError, AgentConflictError, AgentInvalidError, AgentNotFoundError, } from "../../api.js";
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
export const WORKER_PROTOCOL = 6;
|
|
3
|
+
export const WorkerErrorCode = {
|
|
4
|
+
methodNotFound: -32601,
|
|
5
|
+
invalidParams: -32602,
|
|
6
|
+
internalError: -32603,
|
|
7
|
+
notFound: -32004,
|
|
8
|
+
conflict: -32009,
|
|
9
|
+
backendNotInstalled: -32010,
|
|
10
|
+
protocolMismatch: -32011,
|
|
11
|
+
};
|
|
9
12
|
export class WorkerMethodNotFoundError extends Error {
|
|
10
13
|
name = "WorkerMethodNotFoundError";
|
|
11
14
|
}
|
|
12
|
-
|
|
15
|
+
export class WorkerProtocolMismatchError extends Error {
|
|
16
|
+
name = "WorkerProtocolMismatchError";
|
|
17
|
+
}
|
|
13
18
|
export function encodeWorkerError(error) {
|
|
14
19
|
const message = error instanceof Error ? error.message : String(error);
|
|
15
20
|
if (error instanceof AgentInvalidError)
|
|
16
|
-
return { code:
|
|
21
|
+
return { code: WorkerErrorCode.invalidParams, message };
|
|
17
22
|
if (error instanceof AgentNotFoundError)
|
|
18
|
-
return { code:
|
|
23
|
+
return { code: WorkerErrorCode.notFound, message };
|
|
19
24
|
if (error instanceof AgentBackendNotInstalledError)
|
|
20
|
-
return { code:
|
|
25
|
+
return { code: WorkerErrorCode.backendNotInstalled, message };
|
|
21
26
|
if (error instanceof AgentConflictError)
|
|
22
|
-
return { code:
|
|
27
|
+
return { code: WorkerErrorCode.conflict, message };
|
|
23
28
|
if (error instanceof WorkerMethodNotFoundError)
|
|
24
|
-
return { code:
|
|
25
|
-
|
|
29
|
+
return { code: WorkerErrorCode.methodNotFound, message };
|
|
30
|
+
if (error instanceof WorkerProtocolMismatchError)
|
|
31
|
+
return { code: WorkerErrorCode.protocolMismatch, message };
|
|
32
|
+
return { code: WorkerErrorCode.internalError, message };
|
|
26
33
|
}
|
|
27
34
|
export function decodeWorkerError({ code, message }) {
|
|
28
|
-
if (code ===
|
|
35
|
+
if (code === WorkerErrorCode.invalidParams)
|
|
29
36
|
return new AgentInvalidError(message);
|
|
30
|
-
if (code ===
|
|
37
|
+
if (code === WorkerErrorCode.notFound)
|
|
31
38
|
return new AgentNotFoundError(message);
|
|
32
|
-
if (code ===
|
|
39
|
+
if (code === WorkerErrorCode.conflict)
|
|
33
40
|
return new AgentConflictError(message);
|
|
34
|
-
if (code ===
|
|
41
|
+
if (code === WorkerErrorCode.backendNotInstalled)
|
|
35
42
|
return new AgentBackendNotInstalledError(message);
|
|
43
|
+
if (code === WorkerErrorCode.methodNotFound)
|
|
44
|
+
return new WorkerMethodNotFoundError(`worker: ${message}`);
|
|
45
|
+
if (code === WorkerErrorCode.protocolMismatch)
|
|
46
|
+
return new WorkerProtocolMismatchError(`worker: ${message}`);
|
|
36
47
|
return new Error(`worker: ${message}`);
|
|
37
48
|
}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import type { WorkerMethod, WorkerRequests } from "./protocol.ts";
|
|
2
2
|
type Fields = Record<string, unknown>;
|
|
3
|
-
/**
|
|
4
|
-
* Turns each method's params, as they arrived (JSON), into the protocol's types, or throws an
|
|
5
|
-
* AgentInvalidError saying what's wrong. Keeps only the fields the types have, so nothing unknown
|
|
6
|
-
* reaches the service (or its storage).
|
|
7
|
-
*/
|
|
8
3
|
export declare const WORKER_PARAMS: {
|
|
9
4
|
[M in WorkerMethod]: (params: Fields) => WorkerRequests[M][0];
|
|
10
5
|
};
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import { AGENT_BACKENDS, AgentInvalidError, } from "../../api.js";
|
|
2
|
-
/**
|
|
3
|
-
* Turns each method's params, as they arrived (JSON), into the protocol's types, or throws an
|
|
4
|
-
* AgentInvalidError saying what's wrong. Keeps only the fields the types have, so nothing unknown
|
|
5
|
-
* reaches the service (or its storage).
|
|
6
|
-
*/
|
|
1
|
+
import { AGENT_BACKENDS, AGENT_PERMISSION_MODES, AgentInvalidError, } from "../../api.js";
|
|
7
2
|
export const WORKER_PARAMS = {
|
|
8
3
|
"worker/health": () => ({}),
|
|
9
4
|
"worker/shutdown": () => ({}),
|
|
@@ -11,7 +6,7 @@ export const WORKER_PARAMS = {
|
|
|
11
6
|
"backend/list": () => ({}),
|
|
12
7
|
"session/create": (params) => ({ session: session(object(params.session, "session")) }),
|
|
13
8
|
"session/list": () => ({}),
|
|
14
|
-
"session/update": (params) => ({ session: name(params),
|
|
9
|
+
"session/update": (params) => ({ session: name(params), update: sessionUpdate(object(params.update, "update")) }),
|
|
15
10
|
"session/stop": (params) => ({ session: name(params) }),
|
|
16
11
|
"session/send": (params) => ({ session: name(params), message: userMessage(params.message) }),
|
|
17
12
|
"session/interrupt": (params) => ({ session: name(params) }),
|
|
@@ -26,9 +21,15 @@ export const WORKER_PARAMS = {
|
|
|
26
21
|
"session/transcript": (params) => ({
|
|
27
22
|
session: name(params),
|
|
28
23
|
limit: optional(params.limit, (value) => number(value, "limit")),
|
|
29
|
-
// `cursor`: `before`'s old name.
|
|
30
24
|
before: params.before === undefined ? optional(params.cursor, (value) => text(value, "cursor")) : text(params.before, "before"),
|
|
31
25
|
}),
|
|
26
|
+
"session/subagentTranscript": (params) => ({
|
|
27
|
+
session: name(params),
|
|
28
|
+
toolUseId: text(params.toolUseId, "toolUseId"),
|
|
29
|
+
limit: optional(params.limit, (value) => number(value, "limit")),
|
|
30
|
+
before: optional(params.before, (value) => text(value, "before")),
|
|
31
|
+
}),
|
|
32
|
+
"session/usage": (params) => ({ session: name(params) }),
|
|
32
33
|
"permission/list": (params) => ({ session: name(params) }),
|
|
33
34
|
"permission/respond": (params) => ({
|
|
34
35
|
session: name(params),
|
|
@@ -46,6 +47,7 @@ export const WORKER_PARAMS = {
|
|
|
46
47
|
session: name(params),
|
|
47
48
|
model: params.model === null ? null : text(params.model, "the model (a model name, or null for the backend's default)"),
|
|
48
49
|
}),
|
|
50
|
+
"permission/mode": (params) => ({ session: name(params), mode: permissionMode(params.mode) }),
|
|
49
51
|
"task/list": (params) => ({ session: name(params) }),
|
|
50
52
|
"task/stop": (params) => ({ session: name(params), task: text(params.task, "task") }),
|
|
51
53
|
"auth/status": (params) => ({ session: name(params) }),
|
|
@@ -64,10 +66,8 @@ function name(params) {
|
|
|
64
66
|
function object(value, what) {
|
|
65
67
|
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
66
68
|
invalid(`${what} must be an object`);
|
|
67
|
-
// type-bypass: a non-null, non-array object is a record of its fields.
|
|
68
69
|
return value;
|
|
69
70
|
}
|
|
70
|
-
/** A non-empty string. */
|
|
71
71
|
function text(value, what) {
|
|
72
72
|
if (typeof value !== "string" || value.trim() === "")
|
|
73
73
|
invalid(`${what} must be a non-empty string`);
|
|
@@ -86,6 +86,12 @@ function boolean(value, what) {
|
|
|
86
86
|
function optional(value, parse) {
|
|
87
87
|
return value === undefined ? undefined : parse(value);
|
|
88
88
|
}
|
|
89
|
+
function permissionMode(value) {
|
|
90
|
+
const known = AGENT_PERMISSION_MODES.find((mode) => mode === value);
|
|
91
|
+
if (!known)
|
|
92
|
+
invalid(`unknown permission mode "${String(value)}"; known: ${AGENT_PERMISSION_MODES.join(", ")}`);
|
|
93
|
+
return known;
|
|
94
|
+
}
|
|
89
95
|
function backend(value) {
|
|
90
96
|
const known = AGENT_BACKENDS.find((name) => name === value);
|
|
91
97
|
if (!known)
|
|
@@ -96,14 +102,12 @@ function memoryLimit(value) {
|
|
|
96
102
|
const bytes = number(value, "memoryLimit");
|
|
97
103
|
if (!(bytes > 0))
|
|
98
104
|
invalid("memoryLimit must be positive");
|
|
99
|
-
// type-bypass: a positive byte count is what a MemoryLimit is (MemoryLimit() parses the CLI's strings).
|
|
100
105
|
return bytes;
|
|
101
106
|
}
|
|
102
107
|
function cpuLimit(value) {
|
|
103
108
|
const cores = number(value, "cpuLimit");
|
|
104
109
|
if (!(cores > 0))
|
|
105
110
|
invalid("cpuLimit must be positive");
|
|
106
|
-
// type-bypass: a positive core count is what a CPULimit is (CPULimit() parses the CLI's strings).
|
|
107
111
|
return cores;
|
|
108
112
|
}
|
|
109
113
|
function environment(value) {
|
|
@@ -111,7 +115,6 @@ function environment(value) {
|
|
|
111
115
|
for (const [key, entry] of Object.entries(fields))
|
|
112
116
|
if (typeof entry !== "string")
|
|
113
117
|
invalid(`env.${key} must be a string`);
|
|
114
|
-
// type-bypass: every value was just checked to be a string.
|
|
115
118
|
return fields;
|
|
116
119
|
}
|
|
117
120
|
function session(fields) {
|
|
@@ -124,8 +127,14 @@ function session(fields) {
|
|
|
124
127
|
env: optional(fields.env, environment),
|
|
125
128
|
};
|
|
126
129
|
}
|
|
127
|
-
function
|
|
128
|
-
return {
|
|
130
|
+
function sessionUpdate(fields) {
|
|
131
|
+
return {
|
|
132
|
+
backend: optional(fields.backend, backend),
|
|
133
|
+
memoryLimit: optional(fields.memoryLimit, memoryLimit),
|
|
134
|
+
cpuLimit: optional(fields.cpuLimit, cpuLimit),
|
|
135
|
+
cwd: optional(fields.cwd, (value) => text(value, "cwd")),
|
|
136
|
+
env: optional(fields.env, environment),
|
|
137
|
+
};
|
|
129
138
|
}
|
|
130
139
|
function userMessage(value) {
|
|
131
140
|
const fields = object(value, "a message (an SDK user message: {type: \"user\", message})");
|
|
@@ -136,7 +145,6 @@ function userMessage(value) {
|
|
|
136
145
|
invalid('message.message.role must be "user"');
|
|
137
146
|
if (typeof message.content !== "string" && !Array.isArray(message.content))
|
|
138
147
|
invalid("message.message.content must be a string or an array of content blocks");
|
|
139
|
-
// type-bypass: the envelope is checked; the content blocks are the CLI's to judge.
|
|
140
148
|
return value;
|
|
141
149
|
}
|
|
142
150
|
function permissionResult(value) {
|
|
@@ -158,6 +166,5 @@ function questionResponse(value) {
|
|
|
158
166
|
for (const [question, answer] of Object.entries(answers))
|
|
159
167
|
if (typeof answer !== "string")
|
|
160
168
|
invalid(`the answer to "${question}" must be a string`);
|
|
161
|
-
// type-bypass: every answer was just checked to be a string.
|
|
162
169
|
return { answers: answers };
|
|
163
170
|
}
|
|
@@ -1,29 +1,18 @@
|
|
|
1
|
-
import type { Sandbox } from "../../sandbox/api.ts";
|
|
1
|
+
import type { Sandbox, SandboxConnection } from "../../sandbox/api.ts";
|
|
2
2
|
import { type WorkerMethod, type WorkerNotifications, type WorkerRequests } from "./worker/protocol.ts";
|
|
3
|
-
/** One connection to a worker: typed requests, and the notifications it pushes. */
|
|
4
3
|
export type WorkerConnection = {
|
|
5
4
|
request<M extends WorkerMethod>(method: M, params: WorkerRequests[M][0]): Promise<WorkerRequests[M][1]>;
|
|
6
|
-
/** Resolves when the worker closes the connection (or it fails). */
|
|
7
5
|
closed: Promise<void>;
|
|
8
6
|
close(): void;
|
|
9
7
|
};
|
|
10
8
|
export type WorkerNotificationHandler = <N extends keyof WorkerNotifications>(method: N, params: WorkerNotifications[N]) => void;
|
|
11
|
-
/** Opens a connection; notifications go to `onNotification`. */
|
|
12
9
|
export type ConnectWorker = (onNotification?: WorkerNotificationHandler) => Promise<WorkerConnection>;
|
|
13
|
-
/** A text stream to a worker that its JSON-RPC lines go out and come in on. */
|
|
14
10
|
export type WorkerTransport = {
|
|
15
11
|
write(text: string): void;
|
|
16
|
-
/** Receives the text read from the worker, in order. Registered before anything arrives. */
|
|
17
12
|
onText(listener: (text: string) => void): void;
|
|
18
|
-
/** Resolves once the transport is closed, by either side or by an error. */
|
|
19
13
|
closed: Promise<void>;
|
|
20
14
|
close(): void;
|
|
21
15
|
};
|
|
22
|
-
/** A connection speaking JSON-RPC over `transport` (`label` says where to, in errors). */
|
|
23
16
|
export declare function workerConnectionOver(transport: WorkerTransport, label: string, onNotification?: WorkerNotificationHandler): WorkerConnection;
|
|
24
|
-
/**
|
|
25
|
-
* Connects over the worker's unix socket at `socketPath` in `host` (the dimension's run directory is
|
|
26
|
-
* mounted on the host, wherever that is: this machine, or a server reached over SSH), speaking
|
|
27
|
-
* JSON-RPC.
|
|
28
|
-
*/
|
|
29
17
|
export declare function workerSocketConnector(host: Sandbox, socketPath: string): ConnectWorker;
|
|
18
|
+
export declare function workerStreamConnector(open: () => Promise<SandboxConnection>, label: string): ConnectWorker;
|
|
@@ -1,44 +1,39 @@
|
|
|
1
1
|
import { createJsonRpcPeer } from "./worker/jsonRpc.js";
|
|
2
|
-
import { WorkerMethodNotFoundError, decodeWorkerError, encodeWorkerError, } from "./worker/protocol.js";
|
|
3
|
-
/** A connection speaking JSON-RPC over `transport` (`label` says where to, in errors). */
|
|
2
|
+
import { WORKER_PROTOCOL, WorkerMethodNotFoundError, decodeWorkerError, encodeWorkerError, } from "./worker/protocol.js";
|
|
4
3
|
export function workerConnectionOver(transport, label, onNotification) {
|
|
5
4
|
let peer;
|
|
6
5
|
transport.onText((text) => peer?.receive(text));
|
|
7
6
|
const closed = transport.closed.then(() => peer?.close(new Error(`the worker at ${label} closed the connection`)));
|
|
8
7
|
peer = createJsonRpcPeer((text) => transport.write(text), {
|
|
9
|
-
// The worker makes no requests of its clients.
|
|
10
8
|
onRequest: async (method) => {
|
|
11
9
|
throw new WorkerMethodNotFoundError(`no method ${method}`);
|
|
12
10
|
},
|
|
13
|
-
// type-bypass: notifications arrive as JSON; the worker only sends those in WorkerNotifications.
|
|
14
11
|
onNotification: (method, params) => onNotification?.(method, params),
|
|
12
|
+
protocol: WORKER_PROTOCOL,
|
|
15
13
|
encodeError: encodeWorkerError,
|
|
16
14
|
decodeError: decodeWorkerError,
|
|
17
15
|
});
|
|
18
16
|
const connected = peer;
|
|
19
17
|
return {
|
|
20
|
-
// type-bypass: the result is the one WorkerRequests pairs with this method.
|
|
21
18
|
request: (method, params) => connected.request(method, params),
|
|
22
19
|
closed,
|
|
23
20
|
close: () => transport.close(),
|
|
24
21
|
};
|
|
25
22
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Connects over the worker's unix socket at `socketPath` in `host` (the dimension's run directory is
|
|
28
|
-
* mounted on the host, wherever that is: this machine, or a server reached over SSH), speaking
|
|
29
|
-
* JSON-RPC.
|
|
30
|
-
*/
|
|
31
23
|
export function workerSocketConnector(host, socketPath) {
|
|
24
|
+
return workerStreamConnector(() => host.connect(socketPath), socketPath);
|
|
25
|
+
}
|
|
26
|
+
export function workerStreamConnector(open, label) {
|
|
32
27
|
return async (onNotification) => {
|
|
33
28
|
const decoder = new TextDecoder();
|
|
34
29
|
const encoder = new TextEncoder();
|
|
35
|
-
const socket = await
|
|
30
|
+
const socket = await open();
|
|
36
31
|
const transport = {
|
|
37
32
|
write: (text) => socket.write(encoder.encode(text)),
|
|
38
33
|
onText: (listener) => socket.onData((data) => listener(decoder.decode(data, { stream: true }))),
|
|
39
34
|
closed: socket.closed,
|
|
40
35
|
close: () => socket.close(),
|
|
41
36
|
};
|
|
42
|
-
return workerConnectionOver(transport,
|
|
37
|
+
return workerConnectionOver(transport, label, onNotification);
|
|
43
38
|
};
|
|
44
39
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { SandboxAccess } from "../../sandbox/api.ts";
|
|
2
|
+
import { type ConnectWorker } from "./workerConnection.ts";
|
|
3
|
+
export declare class EndpointUnreachableError extends Error {
|
|
4
|
+
readonly url: string;
|
|
5
|
+
name: string;
|
|
6
|
+
constructor(url: string, cause?: unknown);
|
|
7
|
+
}
|
|
8
|
+
export declare class EndpointCredentialsError extends Error {
|
|
9
|
+
readonly url: string;
|
|
10
|
+
name: string;
|
|
11
|
+
constructor(url: string);
|
|
12
|
+
}
|
|
13
|
+
export declare function workerGatewayConnector(endpoint: SandboxAccess, { dimensionName, agentName, }: {
|
|
14
|
+
dimensionName: string;
|
|
15
|
+
agentName: string;
|
|
16
|
+
}, { signal, }?: {
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
}): ConnectWorker;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { EventSourceParserStream } from "eventsource-parser/stream";
|
|
2
|
+
import { AgentNotFoundError } from "../api.js";
|
|
3
|
+
import { workerConnectionOver } from "./workerConnection.js";
|
|
4
|
+
const TOKEN_PARAM = "hyb_token";
|
|
5
|
+
export class EndpointUnreachableError extends Error {
|
|
6
|
+
url;
|
|
7
|
+
name = "EndpointUnreachableError";
|
|
8
|
+
constructor(url, cause) {
|
|
9
|
+
super(`the gateway ${url} didn't answer (a browser reports this as a CORS error): the machine is unreachable, or the gateway isn't running`, { cause });
|
|
10
|
+
this.url = url;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export class EndpointCredentialsError extends Error {
|
|
14
|
+
url;
|
|
15
|
+
name = "EndpointCredentialsError";
|
|
16
|
+
constructor(url) {
|
|
17
|
+
super(`the gateway ${url} refused the credentials: they expired, or aren't its own; get new ones`);
|
|
18
|
+
this.url = url;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function workerGatewayConnector(endpoint, { dimensionName, agentName, }, { signal, } = {}) {
|
|
22
|
+
const { exeDev, token } = endpoint.credentials;
|
|
23
|
+
const headers = exeDev ? { "x-exedev-authorization": `Bearer ${exeDev.token}` } : {};
|
|
24
|
+
const url = (path, params = {}) => `${endpoint.url}${path}?${new URLSearchParams({ ...params, [TOKEN_PARAM]: token })}`;
|
|
25
|
+
const label = `agent ${agentName}'s worker through ${endpoint.url}`;
|
|
26
|
+
return async (onNotification) => {
|
|
27
|
+
signal?.throwIfAborted();
|
|
28
|
+
const aborting = new AbortController();
|
|
29
|
+
signal?.addEventListener("abort", () => aborting.abort(), { once: true });
|
|
30
|
+
let response;
|
|
31
|
+
try {
|
|
32
|
+
response = await fetch(url("/connect", { dimension: dimensionName, agent: agentName }), { headers, signal: aborting.signal });
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
if (signal?.aborted)
|
|
36
|
+
throw error;
|
|
37
|
+
throw new EndpointUnreachableError(endpoint.url, error);
|
|
38
|
+
}
|
|
39
|
+
if (response.status === 401)
|
|
40
|
+
throw new EndpointCredentialsError(endpoint.url);
|
|
41
|
+
if (response.status === 502)
|
|
42
|
+
throw new AgentNotFoundError(`${label} can't be reached: ${(await response.text()).trim()}`);
|
|
43
|
+
if (!response.ok || !response.body)
|
|
44
|
+
throw new Error(`${label}: the gateway answered ${response.status}: ${(await response.text()).trim()}`);
|
|
45
|
+
const events = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream()).getReader();
|
|
46
|
+
const opened = await events.read();
|
|
47
|
+
if (opened.done || opened.value.event !== "open")
|
|
48
|
+
throw new Error(`${label}: the gateway's stream didn't open`);
|
|
49
|
+
const { connection } = JSON.parse(opened.value.data);
|
|
50
|
+
const listeners = [];
|
|
51
|
+
let markClosed;
|
|
52
|
+
const closed = new Promise((done) => (markClosed = done));
|
|
53
|
+
void (async () => {
|
|
54
|
+
try {
|
|
55
|
+
for (;;) {
|
|
56
|
+
const { value, done } = await events.read();
|
|
57
|
+
if (done || value.event === "close")
|
|
58
|
+
break;
|
|
59
|
+
for (const listener of listeners)
|
|
60
|
+
listener(`${value.data}\n`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
markClosed();
|
|
68
|
+
}
|
|
69
|
+
})();
|
|
70
|
+
let writes = Promise.resolve();
|
|
71
|
+
const transport = {
|
|
72
|
+
write(text) {
|
|
73
|
+
if (aborting.signal.aborted)
|
|
74
|
+
return;
|
|
75
|
+
writes = writes.then(() => fetch(url(`/connect/${connection}`), { method: "POST", headers, body: text, signal: aborting.signal }).then((response) => {
|
|
76
|
+
if (!response.ok)
|
|
77
|
+
aborting.abort();
|
|
78
|
+
}, () => aborting.abort()));
|
|
79
|
+
},
|
|
80
|
+
onText: (listener) => void listeners.push(listener),
|
|
81
|
+
closed,
|
|
82
|
+
close: () => aborting.abort(),
|
|
83
|
+
};
|
|
84
|
+
return workerConnectionOver(transport, label, onNotification);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"claude": {
|
|
3
|
+
"docs": "https://code.claude.com/docs/en/agent-sdk/typescript",
|
|
4
|
+
"sources": [
|
|
5
|
+
{
|
|
6
|
+
"source": "npm:@anthropic-ai/claude-agent-sdk@0.3.310",
|
|
7
|
+
"into": "agent-sdk",
|
|
8
|
+
"files": 7
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
},
|
|
12
|
+
"codex": {
|
|
13
|
+
"docs": "https://developers.openai.com/codex/app-server",
|
|
14
|
+
"sources": [
|
|
15
|
+
{
|
|
16
|
+
"source": "npm:@openai/codex-sdk@0.164.0",
|
|
17
|
+
"into": "sdk",
|
|
18
|
+
"files": 1
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"source": "github:openai/codex@rust-v0.164.0/codex-rs/app-server-protocol/schema/typescript",
|
|
22
|
+
"into": "app-server",
|
|
23
|
+
"files": 751
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"source": "github:openai/codex@rust-v0.164.0/codex-rs/app-server-protocol/schema/json",
|
|
27
|
+
"into": "app-server-json",
|
|
28
|
+
"files": 2
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*/
|
|
6
|
-
export type WorkerBundle = {
|
|
7
|
-
/** The worker as one script for bun. */
|
|
8
|
-
source: string;
|
|
9
|
-
/** Identifies the source: a running worker with another build is replaced. */
|
|
10
|
-
build: string;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* The worker, once per process. Under Bun with the sources at hand (a checkout) it is bundled from
|
|
14
|
-
* them; otherwise (Node, or the built package, which ships no sources) it comes from
|
|
15
|
-
* agent/workerBundle.generated.ts (scripts/bundle-worker.ts).
|
|
16
|
-
*/
|
|
17
|
-
export declare function workerBundle(): Promise<WorkerBundle>;
|
|
18
|
-
/** Bundles the worker with Bun.build. */
|
|
19
|
-
export declare function buildWorkerSource(): Promise<string>;
|
|
1
|
+
import { type ScriptBundle } from "../lib/scriptBundle.ts";
|
|
2
|
+
export type WorkerBundle = ScriptBundle;
|
|
3
|
+
export declare const workerEntry: () => string;
|
|
4
|
+
export declare const workerBundle: () => Promise<ScriptBundle>;
|