castle-web-sdk 0.4.40 → 0.4.42
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 +15 -8
- package/dist/agent.js +10 -7
- package/dist/commands.d.ts +1 -1
- package/dist/commands.js +1 -1
- package/dist/runtime.js +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -731,9 +731,11 @@ be coalesced, so it's safe to call on frequent events.
|
|
|
731
731
|
## Agent
|
|
732
732
|
|
|
733
733
|
`Agent` asks a language model for one chat completion. The host sends it
|
|
734
|
-
through Castle's
|
|
735
|
-
|
|
736
|
-
player
|
|
734
|
+
through Castle's deck-agent service, so the deck holds no key. Castle pays
|
|
735
|
+
for each player's calls out of a daily play allowance, which Castle
|
|
736
|
+
characters draw from too; once a player has used it up, calls resolve
|
|
737
|
+
`'allowance_exhausted'` until it resets at midnight UTC. Agent.chat is
|
|
738
|
+
limited to Castle admins for now; every other player gets `'refused'`.
|
|
737
739
|
|
|
738
740
|
### `Agent.chat(params): Promise<AgentChatResult>`
|
|
739
741
|
|
|
@@ -745,9 +747,11 @@ player gets `'refused'`.
|
|
|
745
747
|
- `tools` — optional function tools, in the OpenAI function-tool schema.
|
|
746
748
|
- `toolChoice` — optional: `'auto'` (the default), `'none'`, `'required'`,
|
|
747
749
|
or `{ type: 'function', function: { name } }` to force one tool.
|
|
748
|
-
- `model` — optional OpenRouter model id.
|
|
749
|
-
`'meta/muse-spark-1.3'`.
|
|
750
|
-
|
|
750
|
+
- `model` — optional OpenRouter model id: `'meta/muse-spark-1.3-contributor'`
|
|
751
|
+
(the default), `'meta/muse-spark-1.3'` or `'openai/gpt-4.1-mini'`. Any
|
|
752
|
+
other model resolves `'error'`.
|
|
753
|
+
- `maxTokens` — optional cap on the reply's length. Defaults to 4096; the
|
|
754
|
+
service caps it at 16384.
|
|
751
755
|
- `reasoning` — optional `{ effort: 'minimal' | 'low' | 'medium' | 'high' }`,
|
|
752
756
|
how hard the model thinks before it answers. Lower effort answers sooner.
|
|
753
757
|
Left out, the model uses its own default. Muse can't turn reasoning off;
|
|
@@ -819,9 +823,12 @@ for (let round = 0; round < 8; round++) {
|
|
|
819
823
|
`'tool_calls'` or `'length'`. `usage` carries `prompt_tokens`,
|
|
820
824
|
`completion_tokens` and `total_tokens`.
|
|
821
825
|
- `'refused'` — the player is not a Castle admin. The model was not called.
|
|
822
|
-
- `'
|
|
826
|
+
- `'allowance_exhausted'` — the player's play allowance for the day is used
|
|
827
|
+
up. The model was not called. It resets at midnight UTC.
|
|
828
|
+
- `'unavailable'` — this host has no route to the deck-agent service, or
|
|
829
|
+
the service is down.
|
|
823
830
|
- `'cancelled'` — the call's `signal` was aborted.
|
|
824
|
-
- `'error'` — the
|
|
831
|
+
- `'error'` — the service or the model failed; `reason` says how.
|
|
825
832
|
|
|
826
833
|
Every status but `'ok'` carries a `reason`.
|
|
827
834
|
|
package/dist/agent.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
// Agent — one chat completion from a language model, run
|
|
2
|
-
// Castle
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
1
|
+
// Agent — one chat completion from a language model, run through Castle's
|
|
2
|
+
// deck-agent service. Castle funds each player's calls from a daily play
|
|
3
|
+
// allowance that characters share. Messages and tools follow the OpenAI chat
|
|
4
|
+
// completions format. The reply streams: `onDelta` gets text and reasoning as
|
|
5
|
+
// they arrive and each tool call once its arguments are complete, and the
|
|
6
|
+
// promise resolves with the whole message. A deck runs any tool calls itself
|
|
7
|
+
// and calls Agent.chat again with the results.
|
|
7
8
|
//
|
|
8
9
|
// Agent.chat is limited to Castle admins for now: every other player gets
|
|
9
|
-
// `refused`. A
|
|
10
|
+
// `refused`. A player whose allowance for the day is spent gets
|
|
11
|
+
// `allowance_exhausted`. A host with no route to the service answers
|
|
12
|
+
// `unavailable`.
|
|
10
13
|
import { CastleError } from "./errors";
|
|
11
14
|
import { hostRequest } from "./transport";
|
|
12
15
|
async function chat(params) {
|
package/dist/commands.d.ts
CHANGED
|
@@ -255,7 +255,7 @@ export type AgentChatResult = {
|
|
|
255
255
|
finishReason: string | null;
|
|
256
256
|
usage?: AgentUsage;
|
|
257
257
|
} | {
|
|
258
|
-
status: "unavailable" | "refused" | "error" | "cancelled";
|
|
258
|
+
status: "unavailable" | "refused" | "allowance_exhausted" | "error" | "cancelled";
|
|
259
259
|
reason: string;
|
|
260
260
|
};
|
|
261
261
|
export interface DeckSummary {
|
package/dist/commands.js
CHANGED
|
@@ -15,7 +15,7 @@ export const COMMAND_TIMEOUTS_MS = {
|
|
|
15
15
|
"decks.saved": 30_000,
|
|
16
16
|
};
|
|
17
17
|
// Once a host streams a command, each stream envelope restarts the wait at this
|
|
18
|
-
// length instead. The
|
|
18
|
+
// length instead. The deck-agent service sends a heartbeat every 15 seconds, and the host
|
|
19
19
|
// passes each one on.
|
|
20
20
|
export const STREAM_IDLE_TIMEOUT_MS = 60_000;
|
|
21
21
|
export function isResponseEnvelope(value) {
|
package/dist/runtime.js
CHANGED
|
@@ -8,6 +8,8 @@ const HOST_CAPTURE_REQUEST = "castle-capture-cover";
|
|
|
8
8
|
const HOST_CAPTURE_RESULT = "castle-capture-cover-result";
|
|
9
9
|
let ws = null;
|
|
10
10
|
let logBuffer = [];
|
|
11
|
+
// The shell's play log keeps the same number of lines.
|
|
12
|
+
const MAX_BUFFERED_MESSAGES = 500;
|
|
11
13
|
let nextRequestId = 1;
|
|
12
14
|
const pendingRequests = new Map();
|
|
13
15
|
// Local-dev command channel: the `castle-web serve` dev server is the host, so
|
|
@@ -306,6 +308,11 @@ function sendMsg(msg) {
|
|
|
306
308
|
}
|
|
307
309
|
else {
|
|
308
310
|
logBuffer.push(msg);
|
|
311
|
+
// A deck logging every frame fills this while no socket is open, so the
|
|
312
|
+
// oldest messages are dropped.
|
|
313
|
+
if (logBuffer.length > MAX_BUFFERED_MESSAGES) {
|
|
314
|
+
logBuffer.splice(0, logBuffer.length - MAX_BUFFERED_MESSAGES);
|
|
315
|
+
}
|
|
309
316
|
}
|
|
310
317
|
}
|
|
311
318
|
function sendLocalRequest(msg) {
|