@vellumai/assistant 0.12.5 → 0.12.6-dev.202609292019.a6f6d85
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/.env.example +2 -0
- package/ARCHITECTURE.md +23 -0
- package/docs/automatic-done.md +32 -0
- package/docs/desktop-browser-cli.md +3 -2
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/package.json +2 -1
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/mcp-oauth.test.ts +53 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/index.ts +1 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/mcp-oauth.ts +60 -0
- package/node_modules/@vellumai/environments/src/shell.test.ts +13 -1
- package/node_modules/@vellumai/environments/src/shell.ts +22 -1
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/package.json +2 -1
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/mcp-oauth.test.ts +53 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/index.ts +1 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/mcp-oauth.ts +60 -0
- package/node_modules/@vellumai/gateway-client/src/__tests__/status-contracts.test.ts +39 -0
- package/node_modules/@vellumai/gateway-client/src/gateway-ipc-contracts.ts +25 -0
- package/node_modules/@vellumai/service-contracts/package.json +2 -1
- package/node_modules/@vellumai/service-contracts/src/__tests__/mcp-oauth.test.ts +53 -0
- package/node_modules/@vellumai/service-contracts/src/index.ts +1 -0
- package/node_modules/@vellumai/service-contracts/src/mcp-oauth.ts +60 -0
- package/openapi.yaml +270 -10
- package/package.json +1 -1
- package/src/__tests__/agent-loop.test.ts +76 -0
- package/src/__tests__/anthropic-provider.test.ts +2 -0
- package/src/__tests__/byok-default-profile-ensure.test.ts +7 -0
- package/src/__tests__/config-get-vision-flag.test.ts +1 -1
- package/src/__tests__/config-loader-validation-reset-notice.test.ts +2 -2
- package/src/__tests__/conversation-agent-loop-overflow.test.ts +160 -154
- package/src/__tests__/conversation-evictor.test.ts +54 -0
- package/src/__tests__/conversation-pairing.test.ts +112 -0
- package/src/__tests__/document-append-idempotency.test.ts +13 -0
- package/src/__tests__/document-create-dedupe.test.ts +13 -0
- package/src/__tests__/document-find-replace.test.ts +13 -0
- package/src/__tests__/document-revision-history.test.ts +390 -0
- package/src/__tests__/document-revision.test.ts +425 -0
- package/src/__tests__/document-tool-security.test.ts +13 -0
- package/src/__tests__/document-update-default-surface.test.ts +13 -0
- package/src/__tests__/emit-signal-routing-intent.test.ts +270 -0
- package/src/__tests__/gateway-flag-listener.test.ts +59 -6
- package/src/__tests__/headless-browser-navigate.test.ts +20 -30
- package/src/__tests__/host-cu-proxy.test.ts +79 -0
- package/src/__tests__/host-cu-routes-targeted.test.ts +14 -5
- package/src/__tests__/host-shell-tool.test.ts +6 -2
- package/src/__tests__/identity-routes.test.ts +4 -3
- package/src/__tests__/llm-catalog-parity.test.ts +4 -4
- package/src/__tests__/llm-schema.test.ts +1 -1
- package/src/__tests__/notification-platform-adapter.test.ts +83 -1
- package/src/__tests__/oauth2-gateway-transport.test.ts +2 -0
- package/src/__tests__/openai-provider.test.ts +11 -11
- package/src/__tests__/pricing.test.ts +11 -0
- package/src/__tests__/public-ingress-urls.test.ts +26 -0
- package/src/__tests__/retry-thinking-tool-choice.test.ts +47 -0
- package/src/__tests__/usage-attribution.test.ts +31 -0
- package/src/__tests__/workspace-migration-133-collapse-provider-connections.test.ts +3 -3
- package/src/__tests__/workspace-migration-160-repair-retired-fireworks-model-ids.test.ts +262 -0
- package/src/__tests__/workspace-migration-161-repair-retired-fireworks-glm-5p2-model-id.test.ts +233 -0
- package/src/acp/agent-process.ts +6 -1
- package/src/acp/client-handler.ts +6 -1
- package/src/agent/loop.ts +29 -6
- package/src/api/events/document-editor-show.ts +5 -0
- package/src/api/events/document-editor-update.ts +10 -0
- package/src/api/events/tool-result.ts +1 -0
- package/src/calls/__tests__/voice-session-bridge.test.ts +54 -0
- package/src/calls/channel-admission-reader.ts +15 -9
- package/src/calls/twilio-provider.ts +14 -31
- package/src/calls/voice-session-bridge.ts +18 -1
- package/src/cli/commands/browser.ts +1 -2
- package/src/cli/lib/__tests__/plugin-artifact.test.ts +23 -0
- package/src/cli/lib/__tests__/plugin-catalog-visibility.test.ts +2 -0
- package/src/cli/lib/__tests__/plugin-details.test.ts +16 -0
- package/src/cli/lib/bundled-marketplace.json +41 -2
- package/src/cli/lib/inspect-plugin.ts +15 -15
- package/src/cli/lib/list-installed-plugins.ts +29 -28
- package/src/cli/lib/plugin-artifact.ts +74 -63
- package/src/cli/lib/plugin-catalog-visibility.ts +1 -0
- package/src/cli/lib/plugin-details.ts +27 -42
- package/src/cli/lib/plugin-marketplace.ts +6 -8
- package/src/cli/lib/plugin-surfaces.ts +8 -7
- package/src/cli.ts +1 -3
- package/src/config/__tests__/chat-settings.test.ts +121 -0
- package/src/config/assistant-feature-flags.ts +28 -23
- package/src/config/bundled-skills/computer-use/SKILL.md +20 -0
- package/src/config/bundled-skills/computer-use/TOOLS.json +11 -11
- package/src/config/chat-settings.ts +100 -0
- package/src/config/default-profile-catalog.ts +1 -1
- package/src/config/feature-flag-cache.ts +7 -25
- package/src/config/feature-flag-registry.json +1 -9
- package/src/config/loader.ts +5 -1
- package/src/config/profile-text-generation.ts +25 -21
- package/src/config/schemas/conversations.ts +14 -0
- package/src/config/schemas/llm.ts +1 -0
- package/src/config/schemas/notifications.ts +8 -1
- package/src/contacts/gateway-channel-read.ts +1 -1
- package/src/conversations/__tests__/auto-archive-activity.test.ts +136 -0
- package/src/conversations/__tests__/auto-archive.test.ts +304 -0
- package/src/conversations/auto-archive-activity.ts +61 -0
- package/src/conversations/auto-archive.ts +201 -0
- package/src/daemon/computer-use-observation.test.ts +81 -0
- package/src/daemon/computer-use-observation.ts +23 -0
- package/src/daemon/conversation-agent-loop.ts +11 -6
- package/src/daemon/conversation-evictor.ts +50 -16
- package/src/daemon/doordash-steps.ts +1 -3
- package/src/daemon/handlers/__tests__/config-a2a-accept.test.ts +43 -1
- package/src/daemon/handlers/__tests__/config-channels.test.ts +1 -1
- package/src/daemon/handlers/config-a2a.ts +75 -2
- package/src/daemon/host-cu-proxy.ts +34 -3
- package/src/daemon/lifecycle.ts +15 -2
- package/src/daemon/shutdown-handlers.ts +3 -0
- package/src/daemon/turn-finalization.ts +4 -0
- package/src/desktop/desktop-browser-endpoint.ts +11 -2
- package/src/desktop/desktop-chrome-policy.test.ts +1 -0
- package/src/desktop/desktop-chrome-policy.ts +7 -1
- package/src/desktop/desktop-computer-use.test.ts +14 -4
- package/src/desktop/desktop-session-manager.ts +5 -3
- package/src/documents/document-revisions-store.ts +153 -0
- package/src/documents/document-store.ts +471 -133
- package/src/followups/followup-store.ts +0 -4
- package/src/inbound/__tests__/oauth-callback-url.test.ts +25 -2
- package/src/inbound/oauth-callback-url.ts +30 -1
- package/src/inbound/public-ingress-urls.ts +12 -2
- package/src/ipc/gateway-client.test.ts +40 -0
- package/src/ipc/gateway-client.ts +12 -29
- package/src/ipc/gateway-flag-listener.ts +7 -10
- package/src/live-voice/__tests__/live-voice-agent-turn.test.ts +71 -0
- package/src/live-voice/__tests__/live-voice-flux-turn-end.test.ts +83 -0
- package/src/live-voice/__tests__/protocol.test.ts +77 -0
- package/src/live-voice/__tests__/share-targets.test.ts +163 -0
- package/src/live-voice/live-voice-session.ts +23 -6
- package/src/live-voice/protocol.ts +22 -0
- package/src/live-voice/share-targets.ts +225 -0
- package/src/mcp/__tests__/mcp-oauth-client-registration.test.ts +144 -3
- package/src/mcp/__tests__/mcp-oauth-provider.test.ts +2 -0
- package/src/mcp/client.ts +1 -19
- package/src/mcp/mcp-oauth-provider.ts +66 -49
- package/src/media/openrouter-image-service.ts +39 -22
- package/src/monitoring/__tests__/oom-inheritance-sweep.test.ts +86 -0
- package/src/monitoring/__tests__/oom-kill-reporter.test.ts +374 -0
- package/src/monitoring/control.ts +2 -1
- package/src/monitoring/oom-inheritance-sweep.ts +96 -0
- package/src/monitoring/oom-kill-reporter.ts +469 -0
- package/src/monitoring/resource-sampler.ts +30 -0
- package/src/notifications/README.md +53 -4
- package/src/notifications/__tests__/assistant-initiated-thread.test.ts +254 -0
- package/src/notifications/__tests__/broadcaster.test.ts +558 -6
- package/src/notifications/__tests__/completion-policy.test.ts +37 -0
- package/src/notifications/__tests__/from-me-alert-integration.test.ts +192 -0
- package/src/notifications/adapters/platform.ts +14 -0
- package/src/notifications/assistant-initiated-thread.ts +101 -0
- package/src/notifications/broadcaster.ts +94 -16
- package/src/notifications/chat-reply-policy.ts +11 -0
- package/src/notifications/completion-policy.ts +12 -2
- package/src/notifications/conversation-pairing.ts +15 -70
- package/src/notifications/emit-signal.ts +34 -3
- package/src/notifications/types.ts +2 -0
- package/src/oauth/connect-orchestrator.ts +1 -2
- package/src/persistence/__tests__/conversation-auto-archive.test.ts +330 -0
- package/src/persistence/conversation-auto-archive.ts +170 -0
- package/src/persistence/conversation-crud.ts +2 -1
- package/src/persistence/conversation-queries.ts +15 -8
- package/src/persistence/embeddings/embed.test.ts +96 -0
- package/src/persistence/embeddings/embed.ts +20 -2
- package/src/persistence/embeddings/embedding-gemini.test.ts +39 -3
- package/src/persistence/embeddings/embedding-gemini.ts +39 -1
- package/src/persistence/embeddings/embedding-local.ts +6 -0
- package/src/persistence/embeddings/qdrant-manager.ts +5 -0
- package/src/persistence/job-utils.ts +10 -0
- package/src/persistence/migrations/384-add-document-revision.test.ts +83 -0
- package/src/persistence/migrations/384-add-document-revision.ts +21 -0
- package/src/persistence/migrations/385-create-document-revisions.test.ts +67 -0
- package/src/persistence/migrations/385-create-document-revisions.ts +28 -0
- package/src/persistence/migrations/386-conversations-last-reopened-at.ts +10 -0
- package/src/persistence/migrations/__tests__/386-conversations-last-reopened-at.test.ts +32 -0
- package/src/persistence/schema/conversations.ts +1 -0
- package/src/persistence/schema/documents.ts +20 -0
- package/src/persistence/steps.ts +6 -0
- package/src/platform/managed-speech.ts +42 -46
- package/src/plugin-api/vision-support.test.ts +21 -21
- package/src/plugins/defaults/empty-response/hooks/post-model-call.ts +11 -6
- package/src/providers/__tests__/dispatch-connection-routing.test.ts +1 -1
- package/src/providers/__tests__/search-provider-catalog.test.ts +8 -0
- package/src/providers/anthropic/client.ts +1 -1
- package/src/providers/fireworks/client.test.ts +168 -0
- package/src/providers/fireworks/client.ts +24 -0
- package/src/providers/inference/adapter-factory.ts +6 -0
- package/src/providers/ionet/client.test.ts +143 -0
- package/src/providers/ionet/client.ts +37 -0
- package/src/providers/model-catalog.ts +141 -84
- package/src/providers/model-intents.ts +4 -4
- package/src/providers/openai/chat-completions-provider.ts +23 -1
- package/src/providers/retry.ts +56 -4
- package/src/providers/search-provider-catalog.ts +10 -0
- package/src/providers/types.ts +10 -2
- package/src/providers/usage-tracking.ts +5 -3
- package/src/runtime/assistant-event-hub.ts +23 -0
- package/src/runtime/auth/__tests__/guard-tests.test.ts +0 -7
- package/src/runtime/auth/__tests__/route-policy.test.ts +1 -1
- package/src/runtime/channel-retry-sweep.ts +1 -2
- package/src/runtime/migrations/__tests__/vbundle-streaming-validator.test.ts +35 -10
- package/src/runtime/migrations/__tests__/vbundle-validator-v1-schema.test.ts +48 -0
- package/src/runtime/migrations/vbundle-builder.ts +19 -3
- package/src/runtime/migrations/vbundle-streaming-importer.ts +14 -19
- package/src/runtime/migrations/vbundle-streaming-validator.ts +14 -7
- package/src/runtime/migrations/vbundle-validator.ts +54 -1
- package/src/runtime/pending-interactions.ts +20 -2
- package/src/runtime/routes/__tests__/contact-routes.test.ts +5 -3
- package/src/runtime/routes/__tests__/conversation-list-routes.test.ts +36 -0
- package/src/runtime/routes/__tests__/conversation-query-routes.test.ts +375 -2
- package/src/runtime/routes/__tests__/inference-send-routes.test.ts +1 -1
- package/src/runtime/routes/__tests__/user-route-dispatcher.test.ts +12 -0
- package/src/runtime/routes/contact-routes.ts +2 -2
- package/src/runtime/routes/conversation-list-routes.ts +10 -2
- package/src/runtime/routes/conversation-query-routes.ts +48 -10
- package/src/runtime/routes/documents-routes.ts +185 -47
- package/src/runtime/routes/events-routes.ts +1 -3
- package/src/runtime/routes/host-app-control-routes.ts +1 -0
- package/src/runtime/routes/host-bash-routes.ts +1 -0
- package/src/runtime/routes/host-browser-routes.ts +15 -0
- package/src/runtime/routes/host-cu-routes.ts +4 -1
- package/src/runtime/routes/host-file-routes.ts +1 -0
- package/src/runtime/routes/host-proxy-result-binding.test.ts +83 -0
- package/src/runtime/routes/host-proxy-result-binding.ts +25 -0
- package/src/runtime/routes/host-transfer-routes.ts +1 -0
- package/src/runtime/routes/identity-routes.ts +3 -3
- package/src/runtime/routes/integrations/a2a.ts +4 -1
- package/src/runtime/routes/migration-routes.ts +3 -1
- package/src/runtime/routes/notification-routes.ts +1 -2
- package/src/runtime/routes/ui-snapshot-routes.test.ts +1 -0
- package/src/runtime/routes/user-route-dispatcher.ts +5 -1
- package/src/runtime/verification-templates.ts +1 -2
- package/src/sequence/analytics.ts +0 -4
- package/src/sequence/engine.ts +1 -11
- package/src/sequence/guardrails.ts +1 -6
- package/src/sequence/importer.ts +0 -8
- package/src/sequence/store.ts +0 -10
- package/src/signals/user-message.ts +0 -6
- package/src/skills/catalog-install.ts +52 -23
- package/src/tools/browser/browser-execution.ts +20 -23
- package/src/tools/browser/cdp-client/cdp-inspect/ws-transport.ts +1 -3
- package/src/tools/document/document-tool.ts +13 -11
- package/src/tools/executor.ts +1 -2
- package/src/tools/host-terminal/host-shell.ts +4 -2
- package/src/tools/network/__tests__/web-search.test.ts +105 -0
- package/src/tools/network/web-fetch.ts +2 -4
- package/src/tools/network/web-search.ts +239 -12
- package/src/tools/shared/filesystem/format-diff.ts +1 -2
- package/src/tools/shared/shell-output.test.ts +42 -0
- package/src/tools/shared/shell-output.ts +27 -4
- package/src/tools/terminal/shell.ts +3 -3
- package/src/tools/ui-surface/visual-validation.ts +1 -2
- package/src/usage/attribution.ts +18 -1
- package/src/util/__tests__/oom-priority.test.ts +55 -0
- package/src/util/__tests__/worker-memory.test.ts +16 -0
- package/src/util/debounce.ts +0 -4
- package/src/util/oom-priority.ts +79 -0
- package/src/util/platform.ts +0 -2
- package/src/util/plugin-manifest.ts +5 -7
- package/src/util/pricing.ts +25 -0
- package/src/util/worker-memory.ts +9 -3
- package/src/util/worker-process.ts +8 -0
- package/src/workspace/byok-default-profile-ensure.ts +11 -0
- package/src/workspace/hatched-date.ts +11 -4
- package/src/workspace/migrations/160-repair-retired-fireworks-model-ids.ts +209 -0
- package/src/workspace/migrations/161-repair-retired-fireworks-glm-5p2-model-id.ts +197 -0
- package/src/workspace/migrations/registry.ts +4 -0
|
@@ -51,10 +51,10 @@ const PROVIDER_MODEL_INTENTS: Record<string, Record<ModelIntent, string>> = {
|
|
|
51
51
|
},
|
|
52
52
|
fireworks: {
|
|
53
53
|
balanced: "accounts/fireworks/models/minimax-m3",
|
|
54
|
-
"cost-optimized": "accounts/fireworks/models/deepseek-
|
|
55
|
-
"latency-optimized": "accounts/fireworks/models/deepseek-
|
|
56
|
-
"quality-optimized": "accounts/fireworks/models/kimi-
|
|
57
|
-
"vision-optimized": "accounts/fireworks/models/kimi-
|
|
54
|
+
"cost-optimized": "accounts/fireworks/models/deepseek-v4p1-flash",
|
|
55
|
+
"latency-optimized": "accounts/fireworks/models/deepseek-v4p1-flash",
|
|
56
|
+
"quality-optimized": "accounts/fireworks/models/kimi-k3",
|
|
57
|
+
"vision-optimized": "accounts/fireworks/models/kimi-k3",
|
|
58
58
|
},
|
|
59
59
|
openrouter: {
|
|
60
60
|
balanced: "anthropic/claude-sonnet-4.6",
|
|
@@ -212,6 +212,12 @@ export interface OpenAIChatCompletionsProviderOptions {
|
|
|
212
212
|
* (Fireworks, Together) keep sending `none` / forced choices. Enabled for
|
|
213
213
|
* the generic `openai-compatible` adapter, whose upstream is unknown. */
|
|
214
214
|
omitToolChoiceWhenReasoning?: boolean;
|
|
215
|
+
/** Send `tool_choice: "auto"` whenever tools are offered and the caller
|
|
216
|
+
* left the choice unspecified. Strict OpenAI-compatible upstreams default
|
|
217
|
+
* an unspecified `tool_choice` to "none" (io.net documents exactly that),
|
|
218
|
+
* which would leave the model unable to call any tool; OpenAI's own
|
|
219
|
+
* default is "auto", so this option only exists for upstreams that differ. */
|
|
220
|
+
defaultToolChoiceAuto?: boolean;
|
|
215
221
|
/** Wire field for the output-token limit. OpenAI and OpenAI-compatible
|
|
216
222
|
* backends use `max_completion_tokens`. OpenRouter defaults to
|
|
217
223
|
* `max_tokens` because its parameter router matches that key on
|
|
@@ -864,6 +870,7 @@ export class OpenAIChatCompletionsProvider implements Provider {
|
|
|
864
870
|
private coerceObjectArgsToJsonString: boolean;
|
|
865
871
|
private salvageXmlToolCalls: boolean;
|
|
866
872
|
private omitToolChoiceWhenReasoning: boolean;
|
|
873
|
+
private defaultToolChoiceAuto: boolean;
|
|
867
874
|
private outputTokenLimitField: "max_completion_tokens" | "max_tokens";
|
|
868
875
|
|
|
869
876
|
constructor(
|
|
@@ -896,6 +903,7 @@ export class OpenAIChatCompletionsProvider implements Provider {
|
|
|
896
903
|
options.salvageXmlToolCalls ?? shouldSalvageXmlToolCalls(model);
|
|
897
904
|
this.omitToolChoiceWhenReasoning =
|
|
898
905
|
options.omitToolChoiceWhenReasoning ?? false;
|
|
906
|
+
this.defaultToolChoiceAuto = options.defaultToolChoiceAuto ?? false;
|
|
899
907
|
this.outputTokenLimitField =
|
|
900
908
|
options.outputTokenLimitField ?? "max_completion_tokens";
|
|
901
909
|
}
|
|
@@ -958,6 +966,15 @@ export class OpenAIChatCompletionsProvider implements Provider {
|
|
|
958
966
|
maxTokens;
|
|
959
967
|
}
|
|
960
968
|
|
|
969
|
+
// Per-conversation prompt-cache key (OpenAI Chat Completions
|
|
970
|
+
// `prompt_cache_key`). `RetryProvider` stamps it from the durable
|
|
971
|
+
// conversation id for providers in PROMPT_CACHE_KEY_PROVIDERS; omitted
|
|
972
|
+
// from the wire when absent.
|
|
973
|
+
const promptCacheKey = configObj?.promptCacheKey;
|
|
974
|
+
if (typeof promptCacheKey === "string" && promptCacheKey.length > 0) {
|
|
975
|
+
params.prompt_cache_key = promptCacheKey;
|
|
976
|
+
}
|
|
977
|
+
|
|
961
978
|
// Profile-scoped token biasing (e.g. the `suppress-cjk` preset). Resolved
|
|
962
979
|
// and gated to this provider family upstream in `RetryProvider`.
|
|
963
980
|
if (logitBias) {
|
|
@@ -1028,7 +1045,12 @@ export class OpenAIChatCompletionsProvider implements Provider {
|
|
|
1028
1045
|
// wire. Catalog providers that honor `none` / forced choices still
|
|
1029
1046
|
// receive them; the generic openai-compatible adapter drops every
|
|
1030
1047
|
// explicit value in thinking mode via `omitToolChoiceWhenReasoning`.
|
|
1031
|
-
const
|
|
1048
|
+
const callerToolChoice = mapNeutralToolChoice(configObj?.tool_choice);
|
|
1049
|
+
const toolChoice =
|
|
1050
|
+
callerToolChoice ??
|
|
1051
|
+
(this.defaultToolChoiceAuto
|
|
1052
|
+
? ("auto" as OpenAI.Chat.Completions.ChatCompletionToolChoiceOption)
|
|
1053
|
+
: undefined);
|
|
1032
1054
|
xmlToolCallSalvageEnabled =
|
|
1033
1055
|
this.salvageXmlToolCalls && toolChoice !== "none";
|
|
1034
1056
|
if (toolChoice !== undefined) {
|
package/src/providers/retry.ts
CHANGED
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
shouldSkipPrimary,
|
|
36
36
|
tryAcquireRecoveryProbe,
|
|
37
37
|
} from "./fallback-breaker.js";
|
|
38
|
+
import { resolveFireworksRequestHeaders } from "./fireworks/client.js";
|
|
38
39
|
import { resolveLogitBiasPreset } from "./inference/logit-bias.js";
|
|
39
40
|
import { MALFORMED_TOOL_CALL_MESSAGE } from "./malformed-tool-call.js";
|
|
40
41
|
import {
|
|
@@ -77,10 +78,16 @@ const USAGE_ATTRIBUTION_HEADER_NAMES = {
|
|
|
77
78
|
subagentSpawnMode: "X-Vellum-Subagent-Spawn-Mode",
|
|
78
79
|
} as const;
|
|
79
80
|
|
|
80
|
-
/** Providers whose transports consume `promptCacheKey` (OpenAI Responses
|
|
81
|
-
* `prompt_cache_key`); `RetryProvider` derives it from
|
|
82
|
-
* these only.
|
|
83
|
-
|
|
81
|
+
/** Providers whose transports consume `promptCacheKey` (OpenAI Responses /
|
|
82
|
+
* Chat Completions `prompt_cache_key`); `RetryProvider` derives it from
|
|
83
|
+
* `selectionSeed` for these only. `openai-compatible` is included so
|
|
84
|
+
* self-hosted bridges (e.g. a Claude Code shim) receive a stable
|
|
85
|
+
* per-conversation key and can pin server-side sessions / prompt caches to it. */
|
|
86
|
+
const PROMPT_CACHE_KEY_PROVIDERS = new Set([
|
|
87
|
+
"openai",
|
|
88
|
+
"openrouter",
|
|
89
|
+
"openai-compatible",
|
|
90
|
+
]);
|
|
84
91
|
|
|
85
92
|
/** Providers that support the `effort` config (extended thinking / reasoning). */
|
|
86
93
|
const EFFORT_SUPPORTED_PROVIDERS = new Set([
|
|
@@ -681,6 +688,19 @@ function normalizeSendMessageOptions(
|
|
|
681
688
|
nextConfig.requestHeaders = resolveOpenCodeRequestHeaders(conversationId);
|
|
682
689
|
}
|
|
683
690
|
|
|
691
|
+
if (providerName === "fireworks") {
|
|
692
|
+
// Covers BYOK Fireworks and the Vellum-managed Fireworks upstream, which
|
|
693
|
+
// both dispatch through `FireworksProvider`. Keyless calls send no header.
|
|
694
|
+
const sessionKey = [config.selectionSeed, config.conversationId].find(
|
|
695
|
+
(value): value is string =>
|
|
696
|
+
typeof value === "string" && value.trim().length > 0,
|
|
697
|
+
);
|
|
698
|
+
const headers = resolveFireworksRequestHeaders(sessionKey);
|
|
699
|
+
if (Object.keys(headers).length > 0) {
|
|
700
|
+
nextConfig.requestHeaders = headers;
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
684
704
|
// `overrideProfile`, `forceOverrideProfile`, `selectionSeed`,
|
|
685
705
|
// `conversationId`, and `nativeWebSearchSentinel` are routing/resolution-time
|
|
686
706
|
// concerns (consumed by the resolver below, `CallSiteRoutingProvider`'s
|
|
@@ -689,6 +709,7 @@ function normalizeSendMessageOptions(
|
|
|
689
709
|
// (after the `openai` promptCacheKey copy above) so they never leak into
|
|
690
710
|
// provider request bodies even when callers set them without a `callSite`.
|
|
691
711
|
delete nextConfig.overrideProfile;
|
|
712
|
+
delete nextConfig.overrideProfileOrigin;
|
|
692
713
|
delete nextConfig.forceOverrideProfile;
|
|
693
714
|
delete nextConfig.selectionSeed;
|
|
694
715
|
delete nextConfig.conversationId;
|
|
@@ -703,6 +724,7 @@ function normalizeSendMessageOptions(
|
|
|
703
724
|
const attribution = resolveUsageAttribution({
|
|
704
725
|
callSite: config.callSite,
|
|
705
726
|
overrideProfile: config.overrideProfile,
|
|
727
|
+
overrideProfileOrigin: config.overrideProfileOrigin,
|
|
706
728
|
forceOverrideProfile: config.forceOverrideProfile,
|
|
707
729
|
selectionSeed: config.selectionSeed,
|
|
708
730
|
});
|
|
@@ -912,6 +934,36 @@ function normalizeSendMessageOptions(
|
|
|
912
934
|
}
|
|
913
935
|
}
|
|
914
936
|
|
|
937
|
+
// Adaptive-thinking-only Claude models (Fable, Opus 5.5, Sonnet 5.5) cannot
|
|
938
|
+
// turn reasoning off, so stripping `thinking` below does not clear the
|
|
939
|
+
// forced-tool conflict and Anthropic 400s the request. Downgrade the forced
|
|
940
|
+
// choice to `auto` so the call goes out. The tool is no longer guaranteed:
|
|
941
|
+
// forced-tool call sites already treat a missing tool call as a failed
|
|
942
|
+
// result, which is what the 400 gave them on every request.
|
|
943
|
+
const forcedToolModel =
|
|
944
|
+
typeof nextConfig.model === "string" ? nextConfig.model : "";
|
|
945
|
+
const forcedToolChoice = nextConfig.tool_choice as
|
|
946
|
+
| Record<string, unknown>
|
|
947
|
+
| undefined;
|
|
948
|
+
if (
|
|
949
|
+
forcedToolChoice != null &&
|
|
950
|
+
(forcedToolChoice.type === "tool" || forcedToolChoice.type === "any") &&
|
|
951
|
+
isAdaptiveThinkingOnlyModel(forcedToolModel) &&
|
|
952
|
+
targetsAnthropicWire(providerName, forcedToolModel)
|
|
953
|
+
) {
|
|
954
|
+
log.warn(
|
|
955
|
+
{
|
|
956
|
+
providerName,
|
|
957
|
+
callSite: config.callSite,
|
|
958
|
+
model: forcedToolModel,
|
|
959
|
+
droppedToolChoice: forcedToolChoice,
|
|
960
|
+
},
|
|
961
|
+
"Downgrading forced `tool_choice` to `auto` because this model always " +
|
|
962
|
+
"reasons and rejects forced tool use.",
|
|
963
|
+
);
|
|
964
|
+
nextConfig.tool_choice = { type: "auto" };
|
|
965
|
+
}
|
|
966
|
+
|
|
915
967
|
// Anthropic (and the gateways fronting Anthropic) rejects requests that
|
|
916
968
|
// combine extended thinking with forced tool use (`tool_choice.type` of
|
|
917
969
|
// `"tool"` or `"any"`). Strip thinking when both are present so the
|
|
@@ -197,6 +197,16 @@ export const SEARCH_PROVIDER_CATALOG: readonly SearchProviderCatalogEntry[] = [
|
|
|
197
197
|
fallbackOrder: 9,
|
|
198
198
|
privacyPolicyUrl: "https://exa.ai/privacy-policy",
|
|
199
199
|
},
|
|
200
|
+
{
|
|
201
|
+
id: "serply",
|
|
202
|
+
displayName: "Serply",
|
|
203
|
+
kind: "byok",
|
|
204
|
+
apiKeyPrefix: "Serply API key...",
|
|
205
|
+
envVar: "SERPLY_API_KEY",
|
|
206
|
+
secretKey: "serply",
|
|
207
|
+
fallbackOrder: 10,
|
|
208
|
+
privacyPolicyUrl: "https://serply.io/privacy",
|
|
209
|
+
},
|
|
200
210
|
];
|
|
201
211
|
|
|
202
212
|
/** Provider ids accepted by the web-search config schema. */
|
package/src/providers/types.ts
CHANGED
|
@@ -346,6 +346,13 @@ export interface SendMessageConfig {
|
|
|
346
346
|
* silently fall through.
|
|
347
347
|
*/
|
|
348
348
|
overrideProfile?: string;
|
|
349
|
+
/**
|
|
350
|
+
* Who chose `overrideProfile`: `"auto"` when the Auto profile's router
|
|
351
|
+
* picked it for the turn. Usage attribution reports it as the profile
|
|
352
|
+
* source so a routed turn is not counted as a user pin. A routing-time
|
|
353
|
+
* concern only; stripped before any provider wire request.
|
|
354
|
+
*/
|
|
355
|
+
overrideProfileOrigin?: "auto";
|
|
349
356
|
/**
|
|
350
357
|
* When true, the resolver floats `overrideProfile` above the call-site
|
|
351
358
|
* layers (named site profile + call-site override) for non-main-agent call
|
|
@@ -405,8 +412,9 @@ export interface SendMessageConfig {
|
|
|
405
412
|
usageAttributionHeaders?: Record<string, string>;
|
|
406
413
|
/**
|
|
407
414
|
* Per-request HTTP headers merged onto the transport. `RetryProvider`
|
|
408
|
-
* stamps these for providers that need
|
|
409
|
-
* `x-opencode-session` / `x-opencode-request
|
|
415
|
+
* stamps these for providers that need per-conversation routing headers
|
|
416
|
+
* (OpenCode `x-opencode-session` / `x-opencode-request`, Fireworks
|
|
417
|
+
* `x-session-affinity`). Provider clients pass
|
|
410
418
|
* them through SDK request options only and must never include this
|
|
411
419
|
* object in provider JSON request bodies.
|
|
412
420
|
*/
|
|
@@ -77,9 +77,11 @@ export class UsageTrackingProvider implements Provider {
|
|
|
77
77
|
const attribution = resolveUsageAttribution({
|
|
78
78
|
callSite: config.callSite,
|
|
79
79
|
overrideProfile: appliedOverride,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
// A rerouted serve ran on the backup the wrapper chose, not on the
|
|
81
|
+
// router's pick, so the origin applies only to the original route.
|
|
82
|
+
...(response.actualInferenceProfile === undefined
|
|
83
|
+
? { overrideProfileOrigin: config.overrideProfileOrigin }
|
|
84
|
+
: { forceOverrideProfile: true }),
|
|
83
85
|
});
|
|
84
86
|
const providerName = response.actualProvider ?? this.inner.name;
|
|
85
87
|
const pricingUsage = buildPricingUsageFromResponse(
|
|
@@ -438,6 +438,29 @@ export class AssistantEventHub {
|
|
|
438
438
|
return undefined;
|
|
439
439
|
}
|
|
440
440
|
|
|
441
|
+
/**
|
|
442
|
+
* Whether `connectionId` is still an active client subscription, optionally
|
|
443
|
+
* required to belong to `clientId`.
|
|
444
|
+
*/
|
|
445
|
+
hasActiveClientConnection(
|
|
446
|
+
connectionId: string,
|
|
447
|
+
clientId?: string,
|
|
448
|
+
): boolean {
|
|
449
|
+
for (const entry of this.subscribers) {
|
|
450
|
+
if (entry.connectionId !== connectionId) {
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
if (!entry.active || entry.type !== "client") {
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
if (clientId != null && entry.clientId !== clientId) {
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
return true;
|
|
460
|
+
}
|
|
461
|
+
return false;
|
|
462
|
+
}
|
|
463
|
+
|
|
441
464
|
/**
|
|
442
465
|
* Return the verified actor principal id captured at SSE subscription time
|
|
443
466
|
* for the given client, or `undefined` if the client is unknown or
|
|
@@ -68,11 +68,6 @@ describe("route policy coverage", () => {
|
|
|
68
68
|
// handler calls `assertPlaygroundEnabled()`, so the surface
|
|
69
69
|
// is invisible in prod regardless of policy.
|
|
70
70
|
//
|
|
71
|
-
// GROUP C — pre-existing latent unprotected on main (the prior
|
|
72
|
-
// registry had no entry for these endpoints, so `enforcePolicy`
|
|
73
|
-
// returned allowed). Migration preserves behavior. Triage these
|
|
74
|
-
// and assign real policies in a follow-up PR:
|
|
75
|
-
// - integrations/a2a/invite/accept
|
|
76
71
|
const INTENTIONALLY_UNPROTECTED = new Set([
|
|
77
72
|
// A — design-intentional
|
|
78
73
|
"health",
|
|
@@ -87,8 +82,6 @@ describe("route policy coverage", () => {
|
|
|
87
82
|
"playground/seed-conversation",
|
|
88
83
|
"playground/seeded-conversations",
|
|
89
84
|
"playground/seeded-conversations/:id",
|
|
90
|
-
// C — pre-existing latent unprotected (follow-up audit owed)
|
|
91
|
-
"integrations/a2a/invite/accept",
|
|
92
85
|
]);
|
|
93
86
|
|
|
94
87
|
const unprotectedFound: string[] = [];
|
|
@@ -223,7 +223,7 @@ describe("enforcePolicy", () => {
|
|
|
223
223
|
// An oauth_proxy_v1 grant is printed for a user to export into a stock
|
|
224
224
|
// third-party CLI's environment, so it sits outside this install's trust
|
|
225
225
|
// boundary. `policy: null` admits any valid token, which for this grant means
|
|
226
|
-
// mutating routes it was never minted for
|
|
226
|
+
// mutating routes it was never minted for.
|
|
227
227
|
// ---------------------------------------------------------------------------
|
|
228
228
|
|
|
229
229
|
/** The context an exported OAuth proxy grant produces. */
|
|
@@ -75,9 +75,8 @@ function parseTrustRuntimeContext(value: unknown): TrustContext | undefined {
|
|
|
75
75
|
if (!rawSourceChannel || !isChannelId(rawSourceChannel)) {
|
|
76
76
|
return undefined;
|
|
77
77
|
}
|
|
78
|
-
const sourceChannel = rawSourceChannel;
|
|
79
78
|
return {
|
|
80
|
-
sourceChannel,
|
|
79
|
+
sourceChannel: rawSourceChannel,
|
|
81
80
|
trustClass,
|
|
82
81
|
guardianChatId:
|
|
83
82
|
typeof raw.guardianChatId === "string" ? raw.guardianChatId : undefined,
|
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
import {
|
|
31
31
|
computeLegacyManifestSha256,
|
|
32
32
|
computeManifestChecksum,
|
|
33
|
+
MANIFEST_MAX_BYTES,
|
|
33
34
|
} from "../vbundle-validator.js";
|
|
34
35
|
import { defaultV1Options } from "./v1-test-helpers.js";
|
|
35
36
|
|
|
@@ -202,15 +203,16 @@ describe("readAndValidateManifest — negative paths", () => {
|
|
|
202
203
|
});
|
|
203
204
|
|
|
204
205
|
test("throws manifest_too_large and fails fast before draining the whole body", async () => {
|
|
205
|
-
// Fake a tar entry whose body would emit
|
|
206
|
-
// validator must destroy() the stream and throw the moment the
|
|
207
|
-
// byte count crosses
|
|
206
|
+
// Fake a tar entry whose body would emit 10x the cap if fully drained.
|
|
207
|
+
// The validator must destroy() the stream and throw the moment the
|
|
208
|
+
// running byte count crosses MANIFEST_MAX_BYTES; it must NOT keep
|
|
209
|
+
// pulling chunks.
|
|
208
210
|
//
|
|
209
211
|
// We count bytes emitted via a _read implementation, and after the
|
|
210
|
-
// throw assert both that destroy() fired and that far
|
|
211
|
-
//
|
|
212
|
-
const CHUNK =
|
|
213
|
-
const TOTAL_CHUNKS =
|
|
212
|
+
// throw assert both that destroy() fired and that far less than the
|
|
213
|
+
// full body was ever pulled out of the stream.
|
|
214
|
+
const CHUNK = MANIFEST_MAX_BYTES / 2;
|
|
215
|
+
const TOTAL_CHUNKS = 20;
|
|
214
216
|
let chunksEmitted = 0;
|
|
215
217
|
let bytesEmitted = 0;
|
|
216
218
|
const body = new Readable({
|
|
@@ -245,11 +247,34 @@ describe("readAndValidateManifest — negative paths", () => {
|
|
|
245
247
|
expect(err).toBeInstanceOf(StreamingValidationError);
|
|
246
248
|
expect(err?.code).toBe("manifest_too_large");
|
|
247
249
|
// Fail-fast assertions: destroy() was called, and we didn't drain past
|
|
248
|
-
//
|
|
249
|
-
//
|
|
250
|
+
// the cap + one chunk. If the validator had drained to EOF we'd see all
|
|
251
|
+
// 20 chunks here.
|
|
250
252
|
expect(body.destroyed).toBe(true);
|
|
251
253
|
expect(chunksEmitted).toBeLessThanOrEqual(3);
|
|
252
|
-
expect(bytesEmitted).toBeLessThan(2 *
|
|
254
|
+
expect(bytesEmitted).toBeLessThan(2 * MANIFEST_MAX_BYTES);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
test("throws bundle_too_many_entries when manifest.contents exceeds maxEntries", async () => {
|
|
258
|
+
const { archive } = buildVBundle({
|
|
259
|
+
files: [
|
|
260
|
+
{ path: "data/db/assistant.db", data: new Uint8Array() },
|
|
261
|
+
{ path: "workspace/a.txt", data: new TextEncoder().encode("a") },
|
|
262
|
+
{ path: "workspace/b.txt", data: new TextEncoder().encode("b") },
|
|
263
|
+
],
|
|
264
|
+
...defaultV1Options(),
|
|
265
|
+
});
|
|
266
|
+
const { entry, drainRest } = await firstEntryOf(archive);
|
|
267
|
+
|
|
268
|
+
let err: StreamingValidationError | null = null;
|
|
269
|
+
try {
|
|
270
|
+
await readAndValidateManifest(entry, { maxEntries: 2 });
|
|
271
|
+
} catch (e) {
|
|
272
|
+
err = e as StreamingValidationError;
|
|
273
|
+
}
|
|
274
|
+
await drainRest();
|
|
275
|
+
|
|
276
|
+
expect(err).toBeInstanceOf(StreamingValidationError);
|
|
277
|
+
expect(err?.code).toBe("bundle_too_many_entries");
|
|
253
278
|
});
|
|
254
279
|
|
|
255
280
|
test("throws manifest_malformed when manifest body is not valid JSON", async () => {
|
|
@@ -19,6 +19,8 @@ import {
|
|
|
19
19
|
canonicalizeJson,
|
|
20
20
|
computeLegacyManifestSha256,
|
|
21
21
|
computeManifestChecksum,
|
|
22
|
+
MANIFEST_MAX_BYTES,
|
|
23
|
+
MANIFEST_MAX_ENTRIES,
|
|
22
24
|
ManifestSchema,
|
|
23
25
|
validateVBundle,
|
|
24
26
|
} from "../vbundle-validator.js";
|
|
@@ -174,6 +176,52 @@ describe("ManifestSchema — v1 acceptance", () => {
|
|
|
174
176
|
});
|
|
175
177
|
});
|
|
176
178
|
|
|
179
|
+
describe("validateVBundle: streaming manifest limits", () => {
|
|
180
|
+
test("rejects a manifest over MANIFEST_MAX_BYTES with MANIFEST_TOO_LARGE", () => {
|
|
181
|
+
const oversized = new Uint8Array(MANIFEST_MAX_BYTES + 1).fill(0x20);
|
|
182
|
+
const archive = gzipSync(
|
|
183
|
+
tarArchive([{ name: "manifest.json", data: oversized }]),
|
|
184
|
+
);
|
|
185
|
+
const result = validateVBundle(archive, { enforceStreamingLimits: true });
|
|
186
|
+
expect(result.is_valid).toBe(false);
|
|
187
|
+
expect(result.errors.map((e) => e.code)).toEqual(["MANIFEST_TOO_LARGE"]);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test("rejects a manifest declaring more than MANIFEST_MAX_ENTRIES with MANIFEST_TOO_MANY_ENTRIES", () => {
|
|
191
|
+
const skeleton = v1Skeleton();
|
|
192
|
+
const dbEntry = (skeleton.contents as Array<Record<string, unknown>>)[0]!;
|
|
193
|
+
const extra = Array.from({ length: MANIFEST_MAX_ENTRIES }, (_, i) => ({
|
|
194
|
+
...dbEntry,
|
|
195
|
+
path: `workspace/${i}`,
|
|
196
|
+
}));
|
|
197
|
+
const archive = gzipTarOf(
|
|
198
|
+
withChecksum({ ...skeleton, contents: [dbEntry, ...extra] }),
|
|
199
|
+
);
|
|
200
|
+
const result = validateVBundle(archive, { enforceStreamingLimits: true });
|
|
201
|
+
expect(result.is_valid).toBe(false);
|
|
202
|
+
expect(result.errors.map((e) => e.code)).toEqual([
|
|
203
|
+
"MANIFEST_TOO_MANY_ENTRIES",
|
|
204
|
+
]);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test("does not apply the limits unless enforceStreamingLimits is set", () => {
|
|
208
|
+
const skeleton = v1Skeleton();
|
|
209
|
+
const dbEntry = (skeleton.contents as Array<Record<string, unknown>>)[0]!;
|
|
210
|
+
const extra = Array.from({ length: MANIFEST_MAX_ENTRIES }, (_, i) => ({
|
|
211
|
+
...dbEntry,
|
|
212
|
+
path: `workspace/${i}`,
|
|
213
|
+
}));
|
|
214
|
+
const archive = gzipTarOf(
|
|
215
|
+
withChecksum({ ...skeleton, contents: [dbEntry, ...extra] }),
|
|
216
|
+
[{ name: "data/db/assistant.db", data: DB_BYTES }],
|
|
217
|
+
);
|
|
218
|
+
const result = validateVBundle(archive);
|
|
219
|
+
expect(result.errors.map((e) => e.code)).not.toContain(
|
|
220
|
+
"MANIFEST_TOO_MANY_ENTRIES",
|
|
221
|
+
);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
177
225
|
describe("ManifestSchema — v1 rejection", () => {
|
|
178
226
|
test("rejects schema_version !== 1", () => {
|
|
179
227
|
const manifest = withChecksum({ ...v1Skeleton(), schema_version: 2 });
|
|
@@ -31,9 +31,11 @@ import { sanitizeConfigForTransfer } from "../../config/sanitize-for-transfer.js
|
|
|
31
31
|
import { trackDaemonActivity } from "../../daemon/activity-trail.js";
|
|
32
32
|
import { getLogger } from "../../util/logger.js";
|
|
33
33
|
import type { VBundleOriginMode } from "./origin-mode.js";
|
|
34
|
-
import
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
import {
|
|
35
|
+
MANIFEST_MAX_BYTES,
|
|
36
|
+
MANIFEST_MAX_ENTRIES,
|
|
37
|
+
type ManifestFileEntryType,
|
|
38
|
+
type ManifestType,
|
|
37
39
|
} from "./vbundle-validator.js";
|
|
38
40
|
|
|
39
41
|
// ---------------------------------------------------------------------------
|
|
@@ -400,6 +402,20 @@ function buildManifestObject(input: {
|
|
|
400
402
|
const checksum = sha256Hex(canonicalizeJson(manifestWithEmptyChecksum));
|
|
401
403
|
const manifest: ManifestType = { ...manifestWithEmptyChecksum, checksum };
|
|
402
404
|
const manifestData = new TextEncoder().encode(JSON.stringify(manifest));
|
|
405
|
+
if (
|
|
406
|
+
manifest.contents.length > MANIFEST_MAX_ENTRIES ||
|
|
407
|
+
manifestData.length > MANIFEST_MAX_BYTES
|
|
408
|
+
) {
|
|
409
|
+
getLogger("vbundle-builder").warn(
|
|
410
|
+
{
|
|
411
|
+
entries: manifest.contents.length,
|
|
412
|
+
manifestBytes: manifestData.length,
|
|
413
|
+
maxEntries: MANIFEST_MAX_ENTRIES,
|
|
414
|
+
maxBytes: MANIFEST_MAX_BYTES,
|
|
415
|
+
},
|
|
416
|
+
"Bundle manifest exceeds the streaming import limits; teleport and staged-path imports will reject this bundle",
|
|
417
|
+
);
|
|
418
|
+
}
|
|
403
419
|
return { manifest, manifestData };
|
|
404
420
|
}
|
|
405
421
|
|
|
@@ -69,7 +69,10 @@ import {
|
|
|
69
69
|
verifySymlinkEntry,
|
|
70
70
|
} from "./vbundle-streaming-validator.js";
|
|
71
71
|
import { parseVBundleStream } from "./vbundle-tar-stream.js";
|
|
72
|
-
import
|
|
72
|
+
import {
|
|
73
|
+
MANIFEST_MAX_ENTRIES,
|
|
74
|
+
type ManifestType,
|
|
75
|
+
} from "./vbundle-validator.js";
|
|
73
76
|
|
|
74
77
|
const log = getLogger("vbundle-streaming-importer");
|
|
75
78
|
|
|
@@ -91,11 +94,11 @@ const log = getLogger("vbundle-streaming-importer");
|
|
|
91
94
|
const DEFAULT_MAX_BUNDLE_BYTES = 16 * 1024 * 1024 * 1024;
|
|
92
95
|
|
|
93
96
|
/**
|
|
94
|
-
* Entry-count ceiling for the bundle
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
+
* Entry-count ceiling for the bundle, shared with manifest validation so
|
|
98
|
+
* preflight and import agree. Also applied to tar-level entries so padding
|
|
99
|
+
* extras cannot exceed what the manifest declared.
|
|
97
100
|
*/
|
|
98
|
-
const DEFAULT_MAX_BUNDLE_ENTRIES =
|
|
101
|
+
const DEFAULT_MAX_BUNDLE_ENTRIES = MANIFEST_MAX_ENTRIES;
|
|
99
102
|
|
|
100
103
|
/**
|
|
101
104
|
* Prefixes used for scratch dirs the streaming importer creates INSIDE the
|
|
@@ -153,7 +156,7 @@ export interface StreamCommitArgs {
|
|
|
153
156
|
maxBundleBytes?: number;
|
|
154
157
|
/**
|
|
155
158
|
* Test-only override for the entry-count ceiling. Production callers
|
|
156
|
-
* should omit this and rely on the
|
|
159
|
+
* should omit this and rely on the `MANIFEST_MAX_ENTRIES` default.
|
|
157
160
|
*/
|
|
158
161
|
maxBundleEntries?: number;
|
|
159
162
|
}
|
|
@@ -313,7 +316,9 @@ export async function streamCommitImport(
|
|
|
313
316
|
if (entryIndex === 0) {
|
|
314
317
|
// First entry MUST be manifest.json — readAndValidateManifest
|
|
315
318
|
// enforces that and throws StreamingValidationError otherwise.
|
|
316
|
-
const manifestResult = await readAndValidateManifest(entry
|
|
319
|
+
const manifestResult = await readAndValidateManifest(entry, {
|
|
320
|
+
maxEntries: bundleEntryCap,
|
|
321
|
+
});
|
|
317
322
|
manifest = manifestResult.manifest;
|
|
318
323
|
expected = manifestResult.expected;
|
|
319
324
|
|
|
@@ -340,18 +345,8 @@ export async function streamCommitImport(
|
|
|
340
345
|
);
|
|
341
346
|
}
|
|
342
347
|
|
|
343
|
-
//
|
|
344
|
-
//
|
|
345
|
-
// importer is willing to do for this bundle.
|
|
346
|
-
if (manifest.contents.length > bundleEntryCap) {
|
|
347
|
-
throw new StreamingValidationError(
|
|
348
|
-
"bundle_too_many_entries",
|
|
349
|
-
`bundle contains more than ${bundleEntryCap} entries (declared: ${manifest.contents.length})`,
|
|
350
|
-
);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
// Only NOW — after the manifest is parsed, the version gate passes,
|
|
354
|
-
// and the entry-count ceiling is enforced — do we materialize the
|
|
348
|
+
// Only NOW, after the manifest is parsed (including its entry-count
|
|
349
|
+
// ceiling) and the version gate passes, do we materialize the
|
|
355
350
|
// temp staging dir on disk. Doing this lazily preserves the plan
|
|
356
351
|
// invariant that importers gate on runtime-version compat BEFORE
|
|
357
352
|
// any state mutation. If this throws, the outer catch runs
|
|
@@ -28,6 +28,8 @@ import {
|
|
|
28
28
|
computeLegacyManifestSha256,
|
|
29
29
|
computeManifestChecksum,
|
|
30
30
|
LegacyManifestSchema,
|
|
31
|
+
MANIFEST_MAX_BYTES,
|
|
32
|
+
MANIFEST_MAX_ENTRIES,
|
|
31
33
|
ManifestSchema,
|
|
32
34
|
type ManifestType,
|
|
33
35
|
translateLegacyManifest,
|
|
@@ -74,21 +76,17 @@ export class StreamingValidationError extends Error {
|
|
|
74
76
|
// Manifest validation
|
|
75
77
|
// ---------------------------------------------------------------------------
|
|
76
78
|
|
|
77
|
-
// Manifests are metadata only — typically tens to hundreds of KB even for
|
|
78
|
-
// huge bundles. A 1 MiB cap is comfortably above realistic sizes and
|
|
79
|
-
// protects against a malicious archive whose "manifest" is actually a
|
|
80
|
-
// multi-GB stream intended to OOM the validator.
|
|
81
|
-
const MANIFEST_MAX_BYTES = 1 * 1024 * 1024;
|
|
82
|
-
|
|
83
79
|
/**
|
|
84
80
|
* Drain the first tar entry — which MUST be `manifest.json` — and run the
|
|
85
81
|
* full manifest-level validation pipeline:
|
|
86
82
|
* 1. Entry name check.
|
|
87
|
-
* 2. Size cap (
|
|
83
|
+
* 2. Size cap (`MANIFEST_MAX_BYTES`).
|
|
88
84
|
* 3. JSON parse.
|
|
89
85
|
* 4. Zod schema validation.
|
|
90
86
|
* 5. Self-referencing `checksum` verification against the
|
|
91
87
|
* canonicalized JSON (minus that field).
|
|
88
|
+
* 6. Entry-count ceiling on `contents` (`maxEntries`, default
|
|
89
|
+
* `MANIFEST_MAX_ENTRIES`).
|
|
92
90
|
*
|
|
93
91
|
* On success, returns the parsed manifest plus a `Map` keyed by archive
|
|
94
92
|
* path that callers consult as each subsequent entry streams past.
|
|
@@ -98,7 +96,9 @@ const MANIFEST_MAX_BYTES = 1 * 1024 * 1024;
|
|
|
98
96
|
*/
|
|
99
97
|
export async function readAndValidateManifest(
|
|
100
98
|
first: StreamedTarEntry,
|
|
99
|
+
options: { maxEntries?: number } = {},
|
|
101
100
|
): Promise<ManifestReadResult> {
|
|
101
|
+
const maxEntries = options.maxEntries ?? MANIFEST_MAX_ENTRIES;
|
|
102
102
|
if (first.header.name !== "manifest.json") {
|
|
103
103
|
// Drain the body so the underlying tar extractor isn't left dangling
|
|
104
104
|
// on backpressure before the caller reports the error.
|
|
@@ -186,6 +186,13 @@ export async function readAndValidateManifest(
|
|
|
186
186
|
manifest = translateLegacyManifest(legacy);
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
+
if (manifest.contents.length > maxEntries) {
|
|
190
|
+
throw new StreamingValidationError(
|
|
191
|
+
"bundle_too_many_entries",
|
|
192
|
+
`bundle contains more than ${maxEntries} entries (declared: ${manifest.contents.length})`,
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
189
196
|
const expected = new Map<
|
|
190
197
|
string,
|
|
191
198
|
{ sha256: string; size: number; linkTarget: string | null }
|