castle-web-cli 0.4.221 → 0.4.222
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/castle-host/host.js
CHANGED
|
@@ -1457,7 +1457,7 @@ const DECKS_PLAYLISTS_QUERY = `
|
|
|
1457
1457
|
// seconds, and `[DONE]`. The executor reads the stream as it arrives, passes
|
|
1458
1458
|
// text, reasoning and finished tool calls on to the deck, and resolves with
|
|
1459
1459
|
// the whole message.
|
|
1460
|
-
const DECK_AGENT_CHAT_URL = "https://deck-agent.castle.xyz/chat/completions";
|
|
1460
|
+
export const DECK_AGENT_CHAT_URL = "https://deck-agent.castle.xyz/chat/completions";
|
|
1461
1461
|
// Three missed heartbeats; the service sends one every 15 seconds.
|
|
1462
1462
|
const ORACLE_SILENCE_MS = 45_000;
|
|
1463
1463
|
// Text and reasoning pieces are sent to the deck in batches this far apart. A
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { fetchOracleStream, type OracleStream } from './castle-host/host.js';
|
|
2
|
+
export declare const SANDBOX_DECK_AGENT_PATH = "/castle/deck-agent/chat/completions";
|
|
3
|
+
export declare function serveOracleStream(getLoginToken: () => string | null | undefined, env?: NodeJS.ProcessEnv, streamFor?: typeof fetchOracleStream): OracleStream;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Where `castle-web serve` sends Agent.chat. On a developer's machine the host
|
|
2
|
+
// calls deck-agent.castle.xyz with the CLI's login token. Inside a cloud sandbox
|
|
3
|
+
// the CLI holds only the sandbox's own token, which deck-agent cannot read, so the
|
|
4
|
+
// call goes to the sandbox host's llm-proxy instead: the proxy checks that token and
|
|
5
|
+
// asserts the sandbox owner to deck-agent (castle-sandboxes llm-proxy, the
|
|
6
|
+
// CASTLE_DECK_AGENT_PATH route). Every other stream URL is left alone.
|
|
7
|
+
import { DECK_AGENT_CHAT_URL, fetchOracleStream } from './castle-host/host.js';
|
|
8
|
+
// Mirrors castle-sandboxes shared/src/index.ts CASTLE_DECK_AGENT_PATH.
|
|
9
|
+
export const SANDBOX_DECK_AGENT_PATH = '/castle/deck-agent/chat/completions';
|
|
10
|
+
export function serveOracleStream(getLoginToken, env = process.env, streamFor = fetchOracleStream) {
|
|
11
|
+
const direct = streamFor(getLoginToken);
|
|
12
|
+
const proxyBase = env.CASTLE_LLM_PROXY_URL?.trim();
|
|
13
|
+
const proxyToken = env.CASTLE_LLM_PROXY_TOKEN?.trim();
|
|
14
|
+
if (!proxyBase || !proxyToken)
|
|
15
|
+
return direct;
|
|
16
|
+
const viaProxy = streamFor(() => proxyToken);
|
|
17
|
+
const proxyUrl = `${proxyBase.replace(/\/+$/, '')}${SANDBOX_DECK_AGENT_PATH}`;
|
|
18
|
+
return (url, body, sink) => url === DECK_AGENT_CHAT_URL ? viaProxy(proxyUrl, body, sink) : direct(url, body, sink);
|
|
19
|
+
}
|
package/dist/serve.js
CHANGED
|
@@ -25,7 +25,8 @@ import { migrateClaudeMd, PLATFORM_DOC_REL, writePlatformDocs } from './platform
|
|
|
25
25
|
import { FORKS_DIR, ownForkFile, splitImportRel } from './forks.js';
|
|
26
26
|
import * as config from './config.js';
|
|
27
27
|
import { graphql as castleGraphql } from './api.js';
|
|
28
|
-
import { executeCommand
|
|
28
|
+
import { executeCommand } from './castle-host/host.js';
|
|
29
|
+
import { serveOracleStream } from './deckAgentRoute.js';
|
|
29
30
|
import { ServeSecurity } from './serveSecurity.js';
|
|
30
31
|
import { atomicWriteFileSync } from './atomicFile.js';
|
|
31
32
|
import { isSameOriginUpgrade } from './wsOrigin.js';
|
|
@@ -772,8 +773,9 @@ async function devHostContext(projectDir) {
|
|
|
772
773
|
username: me.username,
|
|
773
774
|
};
|
|
774
775
|
}
|
|
775
|
-
// Agent.chat's route to
|
|
776
|
-
|
|
776
|
+
// Agent.chat's route to deck-agent: the CLI's login token locally, the sandbox
|
|
777
|
+
// host's llm-proxy inside a cloud sandbox (deckAgentRoute.ts).
|
|
778
|
+
const oracleStream = serveOracleStream(() => config.getToken());
|
|
777
779
|
// Commands in flight on each socket, so a deck's cancel or a closed socket can
|
|
778
780
|
// abort a streaming one.
|
|
779
781
|
const commandAborts = new WeakMap();
|