typeclaw 0.42.0 → 0.42.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.
Files changed (59) hide show
  1. package/package.json +3 -3
  2. package/src/agent/adaptive-thinking-compat.ts +79 -0
  3. package/src/agent/index.ts +79 -101
  4. package/src/agent/plugin-tools.ts +77 -130
  5. package/src/agent/provider-error.ts +37 -0
  6. package/src/agent/reload-tool.ts +1 -1
  7. package/src/agent/subagents.ts +2 -2
  8. package/src/agent/system-prompt.ts +19 -5
  9. package/src/agent/tool-result-budget.ts +1 -1
  10. package/src/agent/tools/stream-snapshot.ts +8 -3
  11. package/src/bundled-plugins/agent-browser/index.ts +18 -8
  12. package/src/bundled-plugins/memory/README.md +4 -1
  13. package/src/bundled-plugins/memory/belief-sentence.ts +50 -0
  14. package/src/bundled-plugins/memory/dreaming.ts +13 -6
  15. package/src/bundled-plugins/memory/load-memory.ts +22 -2
  16. package/src/bundled-plugins/memory/memory-logger.ts +1 -1
  17. package/src/capabilities/control-plane.ts +24 -0
  18. package/src/capabilities/index.ts +2 -0
  19. package/src/capabilities/runtime.ts +30 -0
  20. package/src/channels/manager.ts +41 -47
  21. package/src/channels/router.ts +11 -2
  22. package/src/cli/channel.ts +49 -12
  23. package/src/cli/hostd.ts +4 -3
  24. package/src/cli/logs.ts +2 -2
  25. package/src/cli/restart.ts +5 -3
  26. package/src/cli/shell.ts +2 -2
  27. package/src/cli/start.ts +2 -2
  28. package/src/cli/status.ts +2 -2
  29. package/src/cli/stop.ts +2 -2
  30. package/src/compose/restart.ts +4 -3
  31. package/src/compose/start.ts +2 -2
  32. package/src/compose/stop.ts +2 -2
  33. package/src/config/config.ts +10 -1
  34. package/src/config/providers.ts +61 -9
  35. package/src/container/controller.ts +104 -0
  36. package/src/container/index.ts +9 -0
  37. package/src/init/index.ts +1 -1
  38. package/src/init/instagram-auth.ts +189 -34
  39. package/src/inspect/logs-item.ts +2 -2
  40. package/src/mcp/client.ts +1 -1
  41. package/src/run/index.ts +21 -9
  42. package/src/run/{codex-fetch-observer.ts → llm-fetch-observer.ts} +182 -82
  43. package/src/sandbox/availability.ts +2 -2
  44. package/src/sandbox/build.ts +1 -1
  45. package/src/sandbox/policy.ts +2 -2
  46. package/src/secrets/discord-store.ts +4 -13
  47. package/src/secrets/instagram-store.ts +4 -13
  48. package/src/secrets/kakao-store.ts +4 -13
  49. package/src/secrets/line-store.ts +4 -13
  50. package/src/secrets/secrets-provider.ts +86 -0
  51. package/src/secrets/slack-store.ts +4 -13
  52. package/src/secrets/webex-store.ts +4 -13
  53. package/src/server/index.ts +2 -2
  54. package/src/skills/typeclaw-channel-instagram/SKILL.md +1 -1
  55. package/src/skills/typeclaw-config/SKILL.md +5 -3
  56. package/src/skills/typeclaw-plugins/SKILL.md +1 -1
  57. package/src/stream/broker.ts +4 -3
  58. package/src/stream/types.ts +1 -0
  59. package/typeclaw.schema.json +14 -0
@@ -0,0 +1,86 @@
1
+ import { sendHttp } from '@/hostd/client'
2
+ import type { Request } from '@/hostd/protocol'
3
+
4
+ import type { Channels } from './schema'
5
+ import { SecretsBackend } from './storage'
6
+
7
+ // The channel-block payload a container-mode store hands off to be persisted.
8
+ // Identical to the `secrets-patch` RPC's `patch.channels` union so the hostd
9
+ // implementation forwards it verbatim — the on-the-wire contract is unchanged
10
+ // by this abstraction.
11
+ export type ChannelBlockPatch = Extract<Request, { kind: 'secrets-patch' }>['patch']['channels']
12
+
13
+ // The container-stage secrets seam. Named for what the runtime NEEDS, not the
14
+ // transport that serves it. Two halves:
15
+ // read — the whole channels slice (callers extract their own adapter block).
16
+ // Returns null when secrets.json is absent, so callers degrade rather
17
+ // than crash. File-based today (a mounted secrets.json); a managed
18
+ // impl (volume / secret store) slots in behind the same method.
19
+ // write — persist one adapter's block. The container cannot write the
20
+ // host-owned file directly under hostd, so this may cross a transport
21
+ // (secrets-patch RPC); under a volume it's a direct file write.
22
+ export interface RuntimeSecretsProvider {
23
+ readChannels(): Channels | null
24
+ writeBackChannelBlock(channels: ChannelBlockPatch): Promise<void>
25
+ }
26
+
27
+ export type HostdSecretsProviderOptions = {
28
+ hostdUrl: string
29
+ restartToken: string
30
+ containerName: string
31
+ // The mounted secrets.json the container READS from. Writes go through hostd
32
+ // (secrets-patch RPC) to avoid concurrent-writer corruption; reads are the
33
+ // live bind-mounted file, so this path is needed here.
34
+ secretsPath: string
35
+ }
36
+
37
+ // The container-under-hostd provider: reads the mounted secrets.json directly,
38
+ // writes back via a `secrets-patch` RPC over HTTP to hostd (host.docker.internal),
39
+ // Bearer-authed by the per-container restart token.
40
+ export function createHostdSecretsProvider(options: HostdSecretsProviderOptions): RuntimeSecretsProvider {
41
+ const backend = new SecretsBackend(options.secretsPath)
42
+ return {
43
+ readChannels(): Channels | null {
44
+ return backend.tryReadChannelsSync()
45
+ },
46
+ async writeBackChannelBlock(channels: ChannelBlockPatch): Promise<void> {
47
+ const response = await sendHttp(
48
+ { kind: 'secrets-patch', containerName: options.containerName, patch: { channels } },
49
+ { url: options.hostdUrl, token: options.restartToken },
50
+ )
51
+ if (!response.ok) throw new Error(`secrets-patch failed: ${response.reason}`)
52
+ },
53
+ }
54
+ }
55
+
56
+ // The file-backed provider: both halves hit the secrets.json on disk directly.
57
+ // Used where the runtime owns the file (a mounted volume in a future managed
58
+ // profile, or host-stage). No transport — writes merge the block into the file
59
+ // under the same lock the reads use.
60
+ export function createFileSecretsProvider(secretsPath: string): RuntimeSecretsProvider {
61
+ const backend = new SecretsBackend(secretsPath)
62
+ return {
63
+ readChannels(): Channels | null {
64
+ return backend.tryReadChannelsSync()
65
+ },
66
+ async writeBackChannelBlock(patch: ChannelBlockPatch): Promise<void> {
67
+ await backend.updateChannelsAsync(async (channels) => ({ result: undefined, next: { ...channels, ...patch } }))
68
+ },
69
+ }
70
+ }
71
+
72
+ // Resolves the container-stage secrets provider from the environment. Returns
73
+ // null when the hostd triple is absent (daemon unreachable at launch, or a
74
+ // managed profile with no write-back wired yet) — callers degrade gracefully
75
+ // rather than crash. Today only the hostd-backed provider exists; a managed
76
+ // impl (volume / secret store) is selected here when it lands.
77
+ export function resolveRuntimeSecretsProvider(
78
+ env: NodeJS.ProcessEnv,
79
+ secretsPath: string,
80
+ ): RuntimeSecretsProvider | null {
81
+ const hostdUrl = env.TYPECLAW_HOSTD_URL
82
+ const restartToken = env.TYPECLAW_HOSTD_TOKEN
83
+ const containerName = env.TYPECLAW_CONTAINER_NAME
84
+ if (!hostdUrl || !restartToken || !containerName) return null
85
+ return createHostdSecretsProvider({ hostdUrl, restartToken, containerName, secretsPath })
86
+ }
@@ -1,13 +1,12 @@
1
- import { sendHttp } from '@/hostd/client'
2
-
3
1
  import { type SlackAccountRecord, type SlackChannelBlock, slackChannelBlockSchema } from './schema'
2
+ import type { RuntimeSecretsProvider } from './secrets-provider'
4
3
  import { SecretsBackend } from './storage'
5
4
 
6
5
  export type SetSlackAccountInput = SlackAccountRecord
7
6
 
8
7
  export type SecretsSlackCredentialStoreOptions =
9
8
  | { mode: 'host'; secretsPath: string }
10
- | { mode: 'container'; secretsPath: string; hostdUrl: string; restartToken: string; containerName: string }
9
+ | { mode: 'container'; secretsPath: string; hostProvider: RuntimeSecretsProvider }
11
10
 
12
11
  const EMPTY_BLOCK: SlackChannelBlock = { currentAccount: null, accounts: {} }
13
12
 
@@ -56,7 +55,7 @@ export class SecretsSlackCredentialStore {
56
55
 
57
56
  private readBlock(): SlackChannelBlock {
58
57
  const channels =
59
- this.options.mode === 'container' ? this.backend.tryReadChannelsSync() : this.backend.readChannelsSync()
58
+ this.options.mode === 'container' ? this.options.hostProvider.readChannels() : this.backend.readChannelsSync()
60
59
  return parseBlock(channels?.slack)
61
60
  }
62
61
 
@@ -64,15 +63,7 @@ export class SecretsSlackCredentialStore {
64
63
  return this.enqueueWrite(async () => {
65
64
  if (this.options.mode === 'container') {
66
65
  const next = update(this.readBlock())
67
- const response = await sendHttp(
68
- {
69
- kind: 'secrets-patch',
70
- containerName: this.options.containerName,
71
- patch: { channels: { slack: next } },
72
- },
73
- { url: this.options.hostdUrl, token: this.options.restartToken },
74
- )
75
- if (!response.ok) throw new Error(`secrets-patch failed: ${response.reason}`)
66
+ await this.options.hostProvider.writeBackChannelBlock({ slack: next })
76
67
  return
77
68
  }
78
69
 
@@ -1,13 +1,12 @@
1
- import { sendHttp } from '@/hostd/client'
2
-
3
1
  import { type WebexAccountRecord, type WebexChannelBlock, webexChannelBlockSchema } from './schema'
2
+ import type { RuntimeSecretsProvider } from './secrets-provider'
4
3
  import { SecretsBackend } from './storage'
5
4
 
6
5
  export type SetWebexAccountInput = WebexAccountRecord
7
6
 
8
7
  export type SecretsWebexCredentialStoreOptions =
9
8
  | { mode: 'host'; secretsPath: string }
10
- | { mode: 'container'; secretsPath: string; hostdUrl: string; restartToken: string; containerName: string }
9
+ | { mode: 'container'; secretsPath: string; hostProvider: RuntimeSecretsProvider }
11
10
 
12
11
  const EMPTY_BLOCK: WebexChannelBlock = { currentAccount: null, accounts: {} }
13
12
 
@@ -61,7 +60,7 @@ export class SecretsWebexCredentialStore {
61
60
 
62
61
  private readBlock(): WebexChannelBlock {
63
62
  const channels =
64
- this.options.mode === 'container' ? this.backend.tryReadChannelsSync() : this.backend.readChannelsSync()
63
+ this.options.mode === 'container' ? this.options.hostProvider.readChannels() : this.backend.readChannelsSync()
65
64
  return parseBlock(channels?.webex)
66
65
  }
67
66
 
@@ -69,15 +68,7 @@ export class SecretsWebexCredentialStore {
69
68
  return this.enqueueWrite(async () => {
70
69
  if (this.options.mode === 'container') {
71
70
  const next = update(this.readBlock())
72
- const response = await sendHttp(
73
- {
74
- kind: 'secrets-patch',
75
- containerName: this.options.containerName,
76
- patch: { channels: { webex: next } },
77
- },
78
- { url: this.options.hostdUrl, token: this.options.restartToken },
79
- )
80
- if (!response.ok) throw new Error(`secrets-patch failed: ${response.reason}`)
71
+ await this.options.hostProvider.writeBackChannelBlock({ webex: next })
81
72
  return
82
73
  }
83
74
 
@@ -15,7 +15,7 @@ import type { LiveSubagentRegistry } from '@/agent/live-subagents'
15
15
  import { resolveFallbackChain } from '@/agent/model-fallback'
16
16
  import { applyModelRuntimeOverrides } from '@/agent/model-overrides'
17
17
  import { forgetSharedLoopGuardTool } from '@/agent/plugin-tools'
18
- import { detectProviderError, isThrottleOrOverload } from '@/agent/provider-error'
18
+ import { detectProviderError, isFailoverWorthy } from '@/agent/provider-error'
19
19
  import { requestContainerRestart } from '@/agent/restart'
20
20
  import { consumeRestartHandoff, type RestartHandoff } from '@/agent/restart-handoff'
21
21
  import { sessionMetaPayload } from '@/agent/session-meta'
@@ -1130,7 +1130,7 @@ async function drain(
1130
1130
  currentModelRef: state.activeModelRef,
1131
1131
  session: state.session,
1132
1132
  text: turnText,
1133
- shouldFailover: (err) => isThrottleOrOverload(err.message),
1133
+ shouldFailover: (err) => isFailoverWorthy(err.message),
1134
1134
  setModelForRef: async (ref) => {
1135
1135
  await state.session.setModel(applyModelRuntimeOverrides(resolveModel(ref), ref))
1136
1136
  state.activeModelRef = ref
@@ -27,4 +27,4 @@ Engagement: every DM message engages. Groups are alias-only because the SDK summ
27
27
 
28
28
  Realtime vs polling transport is automatic and invisible to you: TypeClaw uses the hybrid listener when available and falls back to polling on older SDKs.
29
29
 
30
- 2FA/checkpointed Instagram accounts are unsupported for this adapter; the operator must use a dedicated account that can authenticate without those challenges.
30
+ 2FA and checkpoint-protected Instagram accounts are supported: the operator completes the verification code interactively at `typeclaw channel add instagram` (or `reauth`) time. Nothing about this is visible to you at runtime.
@@ -21,6 +21,7 @@ The runtime reads `typeclaw.json` at container startup. Some fields are picked u
21
21
  - `plugins` — array of plugin module specifiers loaded at server boot: npm package names for published plugins, or relative paths for local plugins you are authoring. **Restart-required.**
22
22
  - `alias` — additional names the agent answers to when a channel message contains its name in plain text (no `<@id>` mention). The agent folder's directory name (`basename(agentDir)`) is always implicit; `alias` adds further forms (Latin transliteration, nicknames, Korean particles, etc.). Used by the channel engagement layer alongside the structural mention/reply/dm triggers. **Live-reloadable.**
23
23
  - `channels` — per-adapter engagement triggers and history-prefetch knobs for external messengers (Discord, Slack, Telegram, LINE, KakaoTalk), plus the GitHub channel (a webhook-driven adapter that watches repos and reviews PRs — see **GitHub channel** below). Access control lives in `roles`, not here. **Live-reloadable** — edits take effect on the next `reload` without a container restart.
24
+ - `branding` — whether your system prompt discloses that you run on TypeClaw. Default `true`: the prompt says you run "inside TypeClaw" and stamps a `## Runtime` TypeClaw-version block. Set `false` and both are stripped — the prompt opens generically and the runtime-version block is omitted (also on the subagent prompt path). Read fresh per session, so it applies on the next `reload`. The `typeclaw.json` filename and the `typeclaw-render-pdf` / `typeclaw-troubleshooting` skill names stay regardless — they are tokens you need to operate, not disclosure. **Live-reloadable.**
24
25
  - `docker.file` — controls what ships in the autogenerated container image. Two layers: (1) **toggles** for opinionated package installs — `tmux`, `gh`, `python`, `xvfb` default on (`true`); `cjkFonts` defaults to `"auto"` (resolved from host locale at start); `ffmpeg`, `cloudflared`, `claudeCode`, `codexCli` default off (`false`) — set a toggle to `false` to omit, or to a version string like `"2.40.0"` to apt-pin (`python`, `cjkFonts`, `cloudflared`, `xvfb`, `claudeCode`, and `codexCli` are boolean-only). Most toggles install apt packages with BuildKit cache mounts; `cloudflared`, `claudeCode`, and `codexCli` are exceptions — `cloudflared` downloads the pinned GitHub release, `claudeCode` runs Anthropic's official `curl | bash` installer, `codexCli` `bun install`s the `@openai/codex` npm package. (2) **`append`** — extra Dockerfile lines spliced in right before `ENTRYPOINT` for anything the toggles don't cover. The whole Dockerfile is rewritten on every `start` from the typeclaw template. Lives under the `docker` namespace alongside future Docker-related blocks (e.g. `docker.compose`). **Restart-required** (next `typeclaw start` rebuilds the image).
25
26
  - `git.ignore.append` — extra `.gitignore` patterns `typeclaw start` splices into the TypeClaw-owned `.gitignore` before the protected TypeClaw rules. The whole `.gitignore` is rewritten and auto-committed on every `start` when it changes; `append` is the supported escape hatch for local ignore patterns without editing the managed file by hand. Lives under the `git` namespace. **Restart-required** (next `typeclaw start` refreshes and commits `.gitignore`).
26
27
  - `portForward` — allow/deny policy for the auto port-forwarder (the host-stage `_hostd` daemon's portbroker). When the agent runs a server inside the container that LISTENs on a TCP port, the broker proxies it to the same port number on `127.0.0.1` of the host so the user can hit it directly. `portForward` decides which ports are allowed through. **Restart-required** — the broker captures the policy at register time on `typeclaw start`.
@@ -29,7 +30,7 @@ The runtime reads `typeclaw.json` at container startup. Some fields are picked u
29
30
 
30
31
  There is no file watcher, but there is a `reload` mechanism. When `typeclaw.json` changes:
31
32
 
32
- - **Live-reloadable fields** (`models` — including per-profile `thinkingLevel`, `alias`, `channels`) take effect on the next `reload` — no container restart.
33
+ - **Live-reloadable fields** (`models` — including per-profile `thinkingLevel`, `alias`, `channels`, `branding`) take effect on the next `reload` — no container restart.
33
34
  - **Restart-required fields** (`port`, `mounts`, `plugins`, `portForward`, `docker.file`, `git.ignore`) are reported as "reload landed but change won't apply until restart". The diff returns success; the runtime still has the old value in memory. Tell the user explicitly which one they're hitting. `docker.file` additionally requires an image rebuild — that happens automatically on the next `typeclaw start`, no extra flag needed. `git.ignore` refreshes the managed `.gitignore` and auto-commits it on the next `typeclaw start` if content changed.
34
35
  - **`$schema`** changes are ignored.
35
36
 
@@ -54,6 +55,7 @@ You yourself cannot run `typeclaw restart` — that is a host-stage command and
54
55
  | `portForward` | no | object | Allow/deny policy for the host-stage portbroker that auto-forwards container LISTEN ports to `127.0.0.1` on the host. Defaults to `{ "allow": "*" }` (forward everything). Omitted from scaffolded `typeclaw.json`. **Restart-required.** See **portForward** section below. |
55
56
  | `docker` | no | object | Namespace for Docker-related blocks. Today the only child is `docker.file` — toggles (`tmux`, `gh`, `python`, `ffmpeg`, `cjkFonts`, `cloudflared`, `xvfb`, `claudeCode`, `codexCli`) gate opinionated package installs; `append` adds custom Dockerfile lines just before `ENTRYPOINT`. `docker.file` defaults to `{ ffmpeg: false, gh: true, python: true, tmux: true, cjkFonts: 'auto', cloudflared: false, xvfb: true, claudeCode: false, codexCli: false, append: [] }`. Omitted from scaffolded `typeclaw.json`. **Restart-required** (next `typeclaw start` rebuilds the image). See **Dockerfile** section below. |
56
57
  | `git` | no | object | Namespace for git-related blocks. Today the only child is `git.ignore` — extra patterns spliced into the autogenerated `.gitignore` before TypeClaw's protected rules. `git.ignore` defaults to `{ "append": [] }`. Omitted from scaffolded `typeclaw.json`. **Restart-required** (next `typeclaw start` refreshes `.gitignore`). See **Gitignore** section below. |
58
+ | `branding` | no | boolean | Whether the system prompt discloses that you run on TypeClaw. Defaults to `true`. Set `false` to strip every TypeClaw clue from the prompt: the base prompt opens generically (no "inside TypeClaw") and the `## Runtime` version block is omitted, on both the main and subagent prompt paths. Read fresh per session. Functional identifiers (`typeclaw.json`, the `typeclaw-render-pdf` / `typeclaw-troubleshooting` skill names) are unaffected. **Live-reloadable.** |
57
59
 
58
60
  > **Top-level keys not in this table are not "ignored unknowns" anymore** — they are reserved for **plugin config blocks**. The schema's `catchall(z.unknown())` preserves them, and the plugin loader hands each block to its owning plugin's `configSchema` for validation. The bundled memory plugin owns `memory` at the top level — see the `typeclaw-memory` skill for that block's semantics. Do not write a top-level key unless you know which plugin owns it.
59
61
 
@@ -438,7 +440,7 @@ Every secret-bearing field in `secrets.json` is a **`Secret`**: either a plain s
438
440
  {
439
441
  "version": 2,
440
442
  "providers": {
441
- "fireworks": { "type": "api_key", "key": "fw_xxx" },
443
+ "openai": { "type": "api_key", "key": "sk-xxx" },
442
444
  "openai-codex": { "type": "oauth", "access_token": "...", "refresh_token": "...", "expires_at": 99 }
443
445
  },
444
446
  "channels": {
@@ -453,7 +455,7 @@ Every secret-bearing field in `secrets.json` is a **`Secret`**: either a plain s
453
455
  **Resolution at boot, in order:**
454
456
 
455
457
  1. `process.env[secret.env]` — explicit binding wins (the `env` field on the object form).
456
- 2. `process.env[<canonical env name>]` — canonical-env fallback (`SLACK_BOT_TOKEN`, `FIREWORKS_API_KEY`, etc.).
458
+ 2. `process.env[<canonical env name>]` — canonical-env fallback (`SLACK_BOT_TOKEN`, `OPENAI_API_KEY`, etc.).
457
459
  3. `secret.value` — the on-disk value.
458
460
  4. Otherwise the field is treated as missing.
459
461
 
@@ -738,7 +738,7 @@ Plugin `ToolContext` is `{ signal, sessionId, agentDir, logger }`. There is no `
738
738
  - `session.turn.start` / `session.turn.end`: bracket every `session.prompt(text)` call across all four prompt-driver sites — `src/server/index.ts` (TUI drain + fallback), `src/channels/router.ts` (`fireSessionTurnStart`), `src/cron/consumer.ts` (per-attempt), `src/agent/subagents.ts` (subagent runner). `userPrompt` carries the literal text being passed to `session.prompt(text)`.
739
739
  - `session.idle`: `src/server/index.ts` `drain()` — fires immediately after every `session.prompt()` resolves (success or error)
740
740
  - `session.start`/`session.end`: `src/server/index.ts` ws open/close
741
- - `tool.before`/`tool.after`: `src/agent/plugin-tools.ts` `wrapPluginTool`, `wrapSystemTool`, `wrapSystemAgentTool`, and `wrapAgentToolAsCustomToolDefinition`. The last one is the load-bearing path for pi's builtin coding tools (`read`/`bash`/`edit`/`write`/`grep`/`find`/`ls`): pi-coding-agent 0.67.3 treats `createAgentSession({ tools })` as a name filter only, so the wrapping has to ride in `customTools` to actually override the builtin implementations. See the top-of-file contract block in `plugin-tools.ts` for the full reasoning.
741
+ - `tool.before`/`tool.after`: `src/agent/plugin-tools.ts` `wrapPluginTool`, `wrapSystemTool`, and `wrapBuiltinToolDefinition`. The last one is the load-bearing path for pi's builtin coding tools (`read`/`bash`/`edit`/`write`/`grep`/`find`/`ls`): as of pi-coding-agent 0.73, every builtin is a `ToolDefinition` (via pi's `create*ToolDefinition` factories) that TypeClaw wraps and ships through `customTools`, while `createAgentSession({ noTools: 'builtin', tools })` disables pi's unwrapped copies and narrows the active set to an explicit name allowlist. See the top-of-file contract block in `plugin-tools.ts` for the full reasoning.
742
742
  - **Schema additions**: `src/config/config.ts` (`plugins` array, `.catchall(z.unknown())` for per-plugin blocks, `extractPluginConfigs`)
743
743
 
744
744
  ### Audit log on boot
@@ -22,12 +22,13 @@ const DEFAULT_HISTORY_SIZE = 1000
22
22
  export function createStream(opts: CreateStreamOptions = {}): Stream {
23
23
  const subscriptions = new Set<Subscription>()
24
24
  const historySize = Math.max(0, opts.historySize ?? DEFAULT_HISTORY_SIZE)
25
+ const now = opts.now ?? Date.now
25
26
  const history: StreamMessage[] = []
26
27
  let counter = 0
27
28
 
28
29
  function generateId(): StreamMessageId {
29
30
  counter++
30
- return `s_${Date.now().toString(36)}_${counter.toString(36)}_${Math.random().toString(36).slice(2, 8)}`
31
+ return `s_${now().toString(36)}_${counter.toString(36)}_${Math.random().toString(36).slice(2, 8)}`
31
32
  }
32
33
 
33
34
  function record(msg: StreamMessage): void {
@@ -51,7 +52,7 @@ export function createStream(opts: CreateStreamOptions = {}): Stream {
51
52
  function publishMessage(input: StreamMessageInput): StreamMessage {
52
53
  const msg: StreamMessage = {
53
54
  id: generateId(),
54
- ts: Date.now(),
55
+ ts: now(),
55
56
  target: input.target,
56
57
  payload: input.payload,
57
58
  ...(input.replyTo !== undefined ? { replyTo: input.replyTo } : {}),
@@ -73,7 +74,7 @@ export function createStream(opts: CreateStreamOptions = {}): Stream {
73
74
  const requestId = generateId()
74
75
  const requestMessage: StreamMessage = {
75
76
  id: requestId,
76
- ts: Date.now(),
77
+ ts: now(),
77
78
  target: input.target,
78
79
  payload: input.payload,
79
80
  ...(input.replyTo !== undefined ? { replyTo: input.replyTo } : {}),
@@ -62,6 +62,7 @@ export type Stream = {
62
62
 
63
63
  export type CreateStreamOptions = {
64
64
  historySize?: number
65
+ now?: () => number
65
66
  }
66
67
 
67
68
  export class StreamTimeoutError extends Error {
@@ -33,8 +33,10 @@
33
33
  "openai-codex/gpt-5.5",
34
34
  "anthropic/claude-haiku-4-5",
35
35
  "anthropic/claude-sonnet-4-6",
36
+ "anthropic/claude-sonnet-5",
36
37
  "anthropic/claude-opus-4-7",
37
38
  "anthropic/claude-opus-4-8",
39
+ "anthropic/claude-fable-5",
38
40
  "fireworks/accounts/fireworks/routers/kimi-k2p6-turbo",
39
41
  "zai/glm-4.5-air",
40
42
  "zai/glm-4.6",
@@ -83,8 +85,10 @@
83
85
  "openai-codex/gpt-5.5",
84
86
  "anthropic/claude-haiku-4-5",
85
87
  "anthropic/claude-sonnet-4-6",
88
+ "anthropic/claude-sonnet-5",
86
89
  "anthropic/claude-opus-4-7",
87
90
  "anthropic/claude-opus-4-8",
91
+ "anthropic/claude-fable-5",
88
92
  "fireworks/accounts/fireworks/routers/kimi-k2p6-turbo",
89
93
  "zai/glm-4.5-air",
90
94
  "zai/glm-4.6",
@@ -134,8 +138,10 @@
134
138
  "openai-codex/gpt-5.5",
135
139
  "anthropic/claude-haiku-4-5",
136
140
  "anthropic/claude-sonnet-4-6",
141
+ "anthropic/claude-sonnet-5",
137
142
  "anthropic/claude-opus-4-7",
138
143
  "anthropic/claude-opus-4-8",
144
+ "anthropic/claude-fable-5",
139
145
  "fireworks/accounts/fireworks/routers/kimi-k2p6-turbo",
140
146
  "zai/glm-4.5-air",
141
147
  "zai/glm-4.6",
@@ -183,8 +189,10 @@
183
189
  "openai-codex/gpt-5.5",
184
190
  "anthropic/claude-haiku-4-5",
185
191
  "anthropic/claude-sonnet-4-6",
192
+ "anthropic/claude-sonnet-5",
186
193
  "anthropic/claude-opus-4-7",
187
194
  "anthropic/claude-opus-4-8",
195
+ "anthropic/claude-fable-5",
188
196
  "fireworks/accounts/fireworks/routers/kimi-k2p6-turbo",
189
197
  "zai/glm-4.5-air",
190
198
  "zai/glm-4.6",
@@ -233,8 +241,10 @@
233
241
  "openai-codex/gpt-5.5",
234
242
  "anthropic/claude-haiku-4-5",
235
243
  "anthropic/claude-sonnet-4-6",
244
+ "anthropic/claude-sonnet-5",
236
245
  "anthropic/claude-opus-4-7",
237
246
  "anthropic/claude-opus-4-8",
247
+ "anthropic/claude-fable-5",
238
248
  "fireworks/accounts/fireworks/routers/kimi-k2p6-turbo",
239
249
  "zai/glm-4.5-air",
240
250
  "zai/glm-4.6",
@@ -2648,6 +2658,10 @@
2648
2658
  ]
2649
2659
  }
2650
2660
  },
2661
+ "branding": {
2662
+ "default": true,
2663
+ "type": "boolean"
2664
+ },
2651
2665
  "tool-result-cap": {
2652
2666
  "default": {
2653
2667
  "enabled": true,