@alumbwe/anvil 1.0.20 → 1.0.21
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/package.json +6 -2
- package/src/agents/bundled-agents.generated.ts +4 -4
- package/src/chat.tsx +1703 -1698
- package/src/cli-args.ts +134 -134
- package/src/components/status-bar.tsx +331 -313
- package/src/hooks/helpers/send-message.ts +663 -654
- package/src/hooks/use-send-message.ts +806 -773
- package/src/index.tsx +473 -473
- package/src/state/chat-store.ts +553 -544
- package/src/utils/create-run-config.ts +121 -121
- package/src/utils/format-compact-number.ts +37 -0
- package/vendor/@anvil/common/package.json +27 -0
- package/vendor/@anvil/common/src/__tests__/agent-validation.test.ts +846 -0
- package/vendor/@anvil/common/src/__tests__/anvil-model-availability.test.ts +101 -0
- package/vendor/@anvil/common/src/__tests__/anvil-models.test.ts +1408 -0
- package/vendor/@anvil/common/src/__tests__/anvil-public-data-use-copy.test.ts +258 -0
- package/vendor/@anvil/common/src/__tests__/anvil-referral-tiers.test.ts +48 -0
- package/vendor/@anvil/common/src/__tests__/anvil-spend-ceilings.test.ts +282 -0
- package/vendor/@anvil/common/src/__tests__/anvil-trust.test.ts +526 -0
- package/vendor/@anvil/common/src/__tests__/deepseek-direct.test.ts +68 -0
- package/vendor/@anvil/common/src/__tests__/disposable-email.test.ts +132 -0
- package/vendor/@anvil/common/src/__tests__/dynamic-agent-template-schema.test.ts +422 -0
- package/vendor/@anvil/common/src/__tests__/env-ci.test.ts +167 -0
- package/vendor/@anvil/common/src/__tests__/env-process.test.ts +145 -0
- package/vendor/@anvil/common/src/__tests__/foreign-client-shipped-agents.test.ts +234 -0
- package/vendor/@anvil/common/src/__tests__/foreign-client-signals.test.ts +379 -0
- package/vendor/@anvil/common/src/__tests__/free-agents.test.ts +807 -0
- package/vendor/@anvil/common/src/__tests__/gravity-capi.test.ts +154 -0
- package/vendor/@anvil/common/src/__tests__/handlesteps-parsing.test.ts +246 -0
- package/vendor/@anvil/common/src/__tests__/kimi-k3-god-only.test.ts +77 -0
- package/vendor/@anvil/common/src/__tests__/model-config.test.ts +89 -0
- package/vendor/@anvil/common/src/__tests__/project-file-tree.test.ts +298 -0
- package/vendor/@anvil/common/src/__tests__/provisioned-model-tiers.test.ts +116 -0
- package/vendor/@anvil/common/src/__tests__/reasoning-effort.test.ts +167 -0
- package/vendor/@anvil/common/src/__tests__/reddit-capi.test.ts +132 -0
- package/vendor/@anvil/common/src/__tests__/response-ad-positions.test.ts +72 -0
- package/vendor/@anvil/common/src/__tests__/user-state.test.ts +30 -0
- package/vendor/@anvil/common/src/actions.ts +215 -0
- package/vendor/@anvil/common/src/analytics-core.ts +69 -0
- package/vendor/@anvil/common/src/analytics.ts +93 -0
- package/vendor/@anvil/common/src/api-keys/constants.ts +26 -0
- package/vendor/@anvil/common/src/browser-actions.ts +413 -0
- package/vendor/@anvil/common/src/constants/__tests__/anvil-onboarding-gate.test.ts +63 -0
- package/vendor/@anvil/common/src/constants/__tests__/anvil-onboarding.test.ts +246 -0
- package/vendor/@anvil/common/src/constants/__tests__/cf-worker-signals.test.ts +106 -0
- package/vendor/@anvil/common/src/constants/agents.ts +99 -0
- package/vendor/@anvil/common/src/constants/analytics-events.ts +435 -0
- package/vendor/@anvil/common/src/constants/anthropic.ts +73 -0
- package/vendor/@anvil/common/src/constants/anvil-data-use.ts +81 -0
- package/vendor/@anvil/common/src/constants/anvil-errors.ts +7 -0
- package/vendor/@anvil/common/src/constants/anvil-gemini-thinker.ts +21 -0
- package/vendor/@anvil/common/src/constants/anvil-model-ids.ts +11 -0
- package/vendor/@anvil/common/src/constants/anvil-models.ts +2130 -0
- package/vendor/@anvil/common/src/constants/anvil-onboarding-gate.ts +55 -0
- package/vendor/@anvil/common/src/constants/anvil-onboarding.ts +307 -0
- package/vendor/@anvil/common/src/constants/anvil-referral-tiers.ts +87 -0
- package/vendor/@anvil/common/src/constants/anvil-signup-block.ts +68 -0
- package/vendor/@anvil/common/src/constants/anvil-spend-ceilings.ts +450 -0
- package/vendor/@anvil/common/src/constants/anvil-trust.ts +976 -0
- package/vendor/@anvil/common/src/constants/auth.ts +18 -0
- package/vendor/@anvil/common/src/constants/byok.ts +2 -0
- package/vendor/@anvil/common/src/constants/cf-worker-signals.ts +132 -0
- package/vendor/@anvil/common/src/constants/composio.ts +34 -0
- package/vendor/@anvil/common/src/constants/deepseek-direct.ts +55 -0
- package/vendor/@anvil/common/src/constants/feedback.ts +13 -0
- package/vendor/@anvil/common/src/constants/foreign-client-signals.ts +272 -0
- package/vendor/@anvil/common/src/constants/free-agents.ts +777 -0
- package/vendor/@anvil/common/src/constants/gemini.ts +15 -0
- package/vendor/@anvil/common/src/constants/grant-priorities.ts +13 -0
- package/vendor/@anvil/common/src/constants/hosts.ts +6 -0
- package/vendor/@anvil/common/src/constants/images.ts +51 -0
- package/vendor/@anvil/common/src/constants/index.ts +7 -0
- package/vendor/@anvil/common/src/constants/knowledge.ts +35 -0
- package/vendor/@anvil/common/src/constants/limits.ts +23 -0
- package/vendor/@anvil/common/src/constants/model-config.ts +277 -0
- package/vendor/@anvil/common/src/constants/openrouter-attribution.ts +8 -0
- package/vendor/@anvil/common/src/constants/paths.ts +69 -0
- package/vendor/@anvil/common/src/constants/provider-routes.ts +317 -0
- package/vendor/@anvil/common/src/constants/reasoning-effort.ts +79 -0
- package/vendor/@anvil/common/src/constants/skills.ts +60 -0
- package/vendor/@anvil/common/src/constants/subscription-plans.ts +49 -0
- package/vendor/@anvil/common/src/constants/ui.ts +25 -0
- package/vendor/@anvil/common/src/env-ci.ts +36 -0
- package/vendor/@anvil/common/src/env-process.ts +95 -0
- package/vendor/@anvil/common/src/env-schema.ts +95 -0
- package/vendor/@anvil/common/src/env.ts +24 -0
- package/vendor/@anvil/common/src/gravity-capi.ts +207 -0
- package/vendor/@anvil/common/src/mcp/client.ts +233 -0
- package/vendor/@anvil/common/src/old-constants.ts +10 -0
- package/vendor/@anvil/common/src/project-file-tree.ts +355 -0
- package/vendor/@anvil/common/src/reddit-capi.ts +254 -0
- package/vendor/@anvil/common/src/schemas/feedback.ts +52 -0
- package/vendor/@anvil/common/src/schemas/logs.ts +66 -0
- package/vendor/@anvil/common/src/templates/agent-validation.ts +392 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/LICENSE +202 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/README.md +294 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/examples/01-basic-diff-reviewer.ts +17 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/examples/02-intermediate-git-committer.ts +78 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/examples/03-advanced-file-explorer.ts +73 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/my-custom-agent.ts +40 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/package.json +6 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/skills/README.md +65 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/skills/example-skill/SKILL.md +29 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/types/agent-definition.ts +497 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/types/tools.ts +444 -0
- package/vendor/@anvil/common/src/templates/initial-agents-dir/types/util-types.ts +178 -0
- package/vendor/@anvil/common/src/testing/TESTING_PATTERNS.md +351 -0
- package/vendor/@anvil/common/src/testing/anvil-offer-invariants.ts +169 -0
- package/vendor/@anvil/common/src/testing/errors.ts +33 -0
- package/vendor/@anvil/common/src/testing/fixtures/agent-runtime.ts +334 -0
- package/vendor/@anvil/common/src/testing/impl/agent-runtime.ts +6 -0
- package/vendor/@anvil/common/src/testing/index.ts +84 -0
- package/vendor/@anvil/common/src/testing/mock-modules.ts +53 -0
- package/vendor/@anvil/common/src/testing/mock-types.ts +123 -0
- package/vendor/@anvil/common/src/testing/mocks/analytics.ts +261 -0
- package/vendor/@anvil/common/src/testing/mocks/child-process.ts +93 -0
- package/vendor/@anvil/common/src/testing/mocks/crypto.ts +218 -0
- package/vendor/@anvil/common/src/testing/mocks/database.ts +337 -0
- package/vendor/@anvil/common/src/testing/mocks/fetch.ts +219 -0
- package/vendor/@anvil/common/src/testing/mocks/filesystem.ts +166 -0
- package/vendor/@anvil/common/src/testing/mocks/index.ts +101 -0
- package/vendor/@anvil/common/src/testing/mocks/logger.ts +135 -0
- package/vendor/@anvil/common/src/testing/mocks/stream.ts +313 -0
- package/vendor/@anvil/common/src/testing/mocks/timers.ts +132 -0
- package/vendor/@anvil/common/src/testing/mocks/tree-sitter.ts +127 -0
- package/vendor/@anvil/common/src/testing/setup.ts +282 -0
- package/vendor/@anvil/common/src/testing-env-ci.ts +15 -0
- package/vendor/@anvil/common/src/testing-env-process.ts +78 -0
- package/vendor/@anvil/common/src/tools/__tests__/compile-tool-definitions.test.ts +34 -0
- package/vendor/@anvil/common/src/tools/compile-tool-definitions.ts +157 -0
- package/vendor/@anvil/common/src/tools/constants.ts +117 -0
- package/vendor/@anvil/common/src/tools/list.ts +190 -0
- package/vendor/@anvil/common/src/tools/params/__tests__/coerce-to-array.test.ts +213 -0
- package/vendor/@anvil/common/src/tools/params/__tests__/read-docs.test.ts +47 -0
- package/vendor/@anvil/common/src/tools/params/__tests__/render-ui.test.ts +65 -0
- package/vendor/@anvil/common/src/tools/params/tool/__tests__/run-terminal-command-timeout.test.ts +49 -0
- package/vendor/@anvil/common/src/tools/params/tool/add-message.ts +39 -0
- package/vendor/@anvil/common/src/tools/params/tool/add-subgoal.ts +57 -0
- package/vendor/@anvil/common/src/tools/params/tool/apply-patch.ts +110 -0
- package/vendor/@anvil/common/src/tools/params/tool/ask-user.ts +181 -0
- package/vendor/@anvil/common/src/tools/params/tool/browser-logs.ts +85 -0
- package/vendor/@anvil/common/src/tools/params/tool/cloud-plan-ready.ts +94 -0
- package/vendor/@anvil/common/src/tools/params/tool/code-search.ts +159 -0
- package/vendor/@anvil/common/src/tools/params/tool/composio.ts +131 -0
- package/vendor/@anvil/common/src/tools/params/tool/create-plan.ts +80 -0
- package/vendor/@anvil/common/src/tools/params/tool/end-turn.ts +57 -0
- package/vendor/@anvil/common/src/tools/params/tool/find-files.ts +60 -0
- package/vendor/@anvil/common/src/tools/params/tool/glob.ts +80 -0
- package/vendor/@anvil/common/src/tools/params/tool/gravity-index.ts +93 -0
- package/vendor/@anvil/common/src/tools/params/tool/list-directory.ts +58 -0
- package/vendor/@anvil/common/src/tools/params/tool/lookup-agent-info.ts +37 -0
- package/vendor/@anvil/common/src/tools/params/tool/propose-str-replace.ts +103 -0
- package/vendor/@anvil/common/src/tools/params/tool/propose-write-file.ts +71 -0
- package/vendor/@anvil/common/src/tools/params/tool/read-docs.ts +90 -0
- package/vendor/@anvil/common/src/tools/params/tool/read-files.ts +109 -0
- package/vendor/@anvil/common/src/tools/params/tool/read-subtree.ts +79 -0
- package/vendor/@anvil/common/src/tools/params/tool/read-url.ts +81 -0
- package/vendor/@anvil/common/src/tools/params/tool/render-ui.ts +168 -0
- package/vendor/@anvil/common/src/tools/params/tool/run-file-change-hooks.ts +57 -0
- package/vendor/@anvil/common/src/tools/params/tool/run-terminal-command.ts +211 -0
- package/vendor/@anvil/common/src/tools/params/tool/screenshot.ts +97 -0
- package/vendor/@anvil/common/src/tools/params/tool/set-messages.ts +44 -0
- package/vendor/@anvil/common/src/tools/params/tool/set-output.ts +61 -0
- package/vendor/@anvil/common/src/tools/params/tool/skill.ts +59 -0
- package/vendor/@anvil/common/src/tools/params/tool/spawn-agent-inline.ts +56 -0
- package/vendor/@anvil/common/src/tools/params/tool/spawn-agents.ts +154 -0
- package/vendor/@anvil/common/src/tools/params/tool/str-replace.ts +107 -0
- package/vendor/@anvil/common/src/tools/params/tool/suggest-followups.ts +97 -0
- package/vendor/@anvil/common/src/tools/params/tool/task-completed.ts +61 -0
- package/vendor/@anvil/common/src/tools/params/tool/think-deeply.ts +56 -0
- package/vendor/@anvil/common/src/tools/params/tool/update-subgoal.ts +89 -0
- package/vendor/@anvil/common/src/tools/params/tool/vision-analyze.ts +82 -0
- package/vendor/@anvil/common/src/tools/params/tool/web-search.ts +73 -0
- package/vendor/@anvil/common/src/tools/params/tool/write-file.ts +71 -0
- package/vendor/@anvil/common/src/tools/params/tool/write-todos.ts +67 -0
- package/vendor/@anvil/common/src/tools/params/utils.ts +150 -0
- package/vendor/@anvil/common/src/tools/utils.ts +24 -0
- package/vendor/@anvil/common/src/types/__tests__/dynamic-agent-template.test.ts +20 -0
- package/vendor/@anvil/common/src/types/agent-template.ts +215 -0
- package/vendor/@anvil/common/src/types/anvil-session.ts +535 -0
- package/vendor/@anvil/common/src/types/anvil-streak.ts +6 -0
- package/vendor/@anvil/common/src/types/anvil-usage.ts +64 -0
- package/vendor/@anvil/common/src/types/api/agents/publish.ts +61 -0
- package/vendor/@anvil/common/src/types/bun-test.d.ts +5 -0
- package/vendor/@anvil/common/src/types/contracts/agent-runtime.ts +75 -0
- package/vendor/@anvil/common/src/types/contracts/analytics.ts +9 -0
- package/vendor/@anvil/common/src/types/contracts/bigquery.ts +55 -0
- package/vendor/@anvil/common/src/types/contracts/billing.ts +46 -0
- package/vendor/@anvil/common/src/types/contracts/client.ts +53 -0
- package/vendor/@anvil/common/src/types/contracts/database.ts +112 -0
- package/vendor/@anvil/common/src/types/contracts/env.ts +203 -0
- package/vendor/@anvil/common/src/types/contracts/llm.ts +191 -0
- package/vendor/@anvil/common/src/types/contracts/logger.ts +14 -0
- package/vendor/@anvil/common/src/types/contracts/logs.ts +34 -0
- package/vendor/@anvil/common/src/types/contracts/trace.ts +21 -0
- package/vendor/@anvil/common/src/types/dynamic-agent-template.ts +328 -0
- package/vendor/@anvil/common/src/types/filesystem.ts +10 -0
- package/vendor/@anvil/common/src/types/function-params.ts +33 -0
- package/vendor/@anvil/common/src/types/grant.ts +20 -0
- package/vendor/@anvil/common/src/types/gravity-index.ts +170 -0
- package/vendor/@anvil/common/src/types/json.ts +29 -0
- package/vendor/@anvil/common/src/types/mcp.ts +24 -0
- package/vendor/@anvil/common/src/types/messages/anvil-message.ts +58 -0
- package/vendor/@anvil/common/src/types/messages/content-part.ts +59 -0
- package/vendor/@anvil/common/src/types/messages/data-content.ts +14 -0
- package/vendor/@anvil/common/src/types/messages/provider-metadata.ts +13 -0
- package/vendor/@anvil/common/src/types/organization.ts +118 -0
- package/vendor/@anvil/common/src/types/print-mode.ts +121 -0
- package/vendor/@anvil/common/src/types/publisher.ts +67 -0
- package/vendor/@anvil/common/src/types/session-state.ts +149 -0
- package/vendor/@anvil/common/src/types/skill.ts +86 -0
- package/vendor/@anvil/common/src/types/source.ts +11 -0
- package/vendor/@anvil/common/src/types/spawn.ts +13 -0
- package/vendor/@anvil/common/src/types/subscription.ts +67 -0
- package/vendor/@anvil/common/src/types/usage.ts +16 -0
- package/vendor/@anvil/common/src/types/util.ts +3 -0
- package/vendor/@anvil/common/src/util/__tests__/ad-user-agent.test.ts +26 -0
- package/vendor/@anvil/common/src/util/__tests__/analytics-dispatcher.test.ts +122 -0
- package/vendor/@anvil/common/src/util/__tests__/analytics-log.test.ts +102 -0
- package/vendor/@anvil/common/src/util/__tests__/analytics-sampling.test.ts +143 -0
- package/vendor/@anvil/common/src/util/__tests__/anvil-streak.test.ts +202 -0
- package/vendor/@anvil/common/src/util/__tests__/anvil-usage-summary.test.ts +193 -0
- package/vendor/@anvil/common/src/util/__tests__/axiom-only-log.test.ts +140 -0
- package/vendor/@anvil/common/src/util/__tests__/client-user-agent.test.ts +148 -0
- package/vendor/@anvil/common/src/util/__tests__/engagement-tracker.test.ts +115 -0
- package/vendor/@anvil/common/src/util/__tests__/env-file-path.test.ts +57 -0
- package/vendor/@anvil/common/src/util/__tests__/error-abort.test.ts +774 -0
- package/vendor/@anvil/common/src/util/__tests__/error-api-details.test.ts +206 -0
- package/vendor/@anvil/common/src/util/__tests__/file-read-limits.test.ts +173 -0
- package/vendor/@anvil/common/src/util/__tests__/format-code-search.test.ts +60 -0
- package/vendor/@anvil/common/src/util/__tests__/log-mirror.test.ts +31 -0
- package/vendor/@anvil/common/src/util/__tests__/messages.test.ts +1252 -0
- package/vendor/@anvil/common/src/util/__tests__/partial-json-delta.test.ts +505 -0
- package/vendor/@anvil/common/src/util/__tests__/path.test.ts +22 -0
- package/vendor/@anvil/common/src/util/__tests__/project-ignore.test.ts +90 -0
- package/vendor/@anvil/common/src/util/__tests__/promise.test.ts +325 -0
- package/vendor/@anvil/common/src/util/__tests__/rate-limit.test.ts +28 -0
- package/vendor/@anvil/common/src/util/__tests__/reddit-anvil-retention.test.ts +130 -0
- package/vendor/@anvil/common/src/util/__tests__/saxy.test.ts +1008 -0
- package/vendor/@anvil/common/src/util/__tests__/split-data.test.ts +289 -0
- package/vendor/@anvil/common/src/util/__tests__/string.test.ts +239 -0
- package/vendor/@anvil/common/src/util/__tests__/thread-title.test.ts +70 -0
- package/vendor/@anvil/common/src/util/__tests__/tool-result-media-order.test.ts +108 -0
- package/vendor/@anvil/common/src/util/__tests__/ttft-histogram.test.ts +180 -0
- package/vendor/@anvil/common/src/util/__tests__/with-timeout.test.ts +24 -0
- package/vendor/@anvil/common/src/util/__tests__/zoned-time.test.ts +88 -0
- package/vendor/@anvil/common/src/util/ad-user-agent.ts +25 -0
- package/vendor/@anvil/common/src/util/agent-file-utils.ts +110 -0
- package/vendor/@anvil/common/src/util/agent-id-parsing.ts +136 -0
- package/vendor/@anvil/common/src/util/agent-name-normalization.ts +38 -0
- package/vendor/@anvil/common/src/util/agent-name-resolver.ts +86 -0
- package/vendor/@anvil/common/src/util/analytics-dispatcher.ts +82 -0
- package/vendor/@anvil/common/src/util/analytics-log.ts +78 -0
- package/vendor/@anvil/common/src/util/analytics-sampling.ts +255 -0
- package/vendor/@anvil/common/src/util/anvil-model-availability.ts +102 -0
- package/vendor/@anvil/common/src/util/anvil-privacy.ts +82 -0
- package/vendor/@anvil/common/src/util/anvil-streak-line.ts +103 -0
- package/vendor/@anvil/common/src/util/anvil-streak.ts +156 -0
- package/vendor/@anvil/common/src/util/anvil-usage-summary.ts +125 -0
- package/vendor/@anvil/common/src/util/array.ts +31 -0
- package/vendor/@anvil/common/src/util/axiom-only-log.ts +124 -0
- package/vendor/@anvil/common/src/util/cache-debug.ts +171 -0
- package/vendor/@anvil/common/src/util/client-user-agent.ts +114 -0
- package/vendor/@anvil/common/src/util/credentials.ts +26 -0
- package/vendor/@anvil/common/src/util/currency.ts +25 -0
- package/vendor/@anvil/common/src/util/dates.ts +81 -0
- package/vendor/@anvil/common/src/util/disposable-email.ts +277 -0
- package/vendor/@anvil/common/src/util/engagement-tracker.ts +129 -0
- package/vendor/@anvil/common/src/util/env-file-path.ts +40 -0
- package/vendor/@anvil/common/src/util/error.ts +562 -0
- package/vendor/@anvil/common/src/util/file-read-limits.ts +236 -0
- package/vendor/@anvil/common/src/util/file.ts +339 -0
- package/vendor/@anvil/common/src/util/format-code-search.ts +115 -0
- package/vendor/@anvil/common/src/util/lazy-response-ads.ts +92 -0
- package/vendor/@anvil/common/src/util/log-data.ts +57 -0
- package/vendor/@anvil/common/src/util/log-ingest.ts +58 -0
- package/vendor/@anvil/common/src/util/log-mirror.ts +34 -0
- package/vendor/@anvil/common/src/util/lru-cache.ts +67 -0
- package/vendor/@anvil/common/src/util/messages.ts +685 -0
- package/vendor/@anvil/common/src/util/min-heap.ts +87 -0
- package/vendor/@anvil/common/src/util/model-utils.ts +4 -0
- package/vendor/@anvil/common/src/util/object.ts +128 -0
- package/vendor/@anvil/common/src/util/partial-json-delta.ts +89 -0
- package/vendor/@anvil/common/src/util/path.ts +15 -0
- package/vendor/@anvil/common/src/util/project-ignore.ts +119 -0
- package/vendor/@anvil/common/src/util/promise.ts +73 -0
- package/vendor/@anvil/common/src/util/random.ts +15 -0
- package/vendor/@anvil/common/src/util/rate-limit.ts +56 -0
- package/vendor/@anvil/common/src/util/reddit-anvil-retention.ts +60 -0
- package/vendor/@anvil/common/src/util/reddit-capi-events.ts +36 -0
- package/vendor/@anvil/common/src/util/response-ad-positions.ts +54 -0
- package/vendor/@anvil/common/src/util/saxy.ts +741 -0
- package/vendor/@anvil/common/src/util/skills.test.ts +44 -0
- package/vendor/@anvil/common/src/util/skills.ts +36 -0
- package/vendor/@anvil/common/src/util/split-data.ts +259 -0
- package/vendor/@anvil/common/src/util/stop-sequence.ts +61 -0
- package/vendor/@anvil/common/src/util/string.ts +426 -0
- package/vendor/@anvil/common/src/util/system-info.ts +53 -0
- package/vendor/@anvil/common/src/util/thread-title.ts +46 -0
- package/vendor/@anvil/common/src/util/ttft-histogram.ts +73 -0
- package/vendor/@anvil/common/src/util/xml-parser.ts +27 -0
- package/vendor/@anvil/common/src/util/xml.ts +17 -0
- package/vendor/@anvil/common/src/util/zod-schema.ts +25 -0
- package/vendor/@anvil/common/src/util/zoned-time.ts +136 -0
- package/vendor/@anvil/common/src/utils/ask-user-bridge.ts +44 -0
- package/vendor/@anvil/sdk/dist/index.cjs +52297 -0
- package/vendor/@anvil/sdk/dist/index.cjs.map +440 -0
- package/vendor/@anvil/sdk/dist/index.d.ts +4277 -0
- package/vendor/@anvil/sdk/dist/index.mjs +52290 -0
- package/vendor/@anvil/sdk/dist/index.mjs.map +440 -0
- package/vendor/@anvil/sdk/dist/vendor/ai.cjs +30886 -0
- package/vendor/@anvil/sdk/dist/vendor/ripgrep/arm64-darwin/rg +0 -0
- package/vendor/@anvil/sdk/dist/vendor/ripgrep/arm64-linux/rg +0 -0
- package/vendor/@anvil/sdk/dist/vendor/ripgrep/x64-darwin/rg +0 -0
- package/vendor/@anvil/sdk/dist/vendor/ripgrep/x64-linux/rg +0 -0
- package/vendor/@anvil/sdk/dist/vendor/ripgrep/x64-win32/rg.exe +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-c-sharp.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-cpp.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-go.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-java.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-javascript.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-python.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-ruby.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-rust.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-tsx.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter-typescript.wasm +0 -0
- package/vendor/@anvil/sdk/dist/wasm/tree-sitter.wasm +0 -0
- package/vendor/@anvil/sdk/package.json +21 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import type { TrackEventFn } from './analytics'
|
|
2
|
+
import type { SendActionFn } from './client'
|
|
3
|
+
import type {
|
|
4
|
+
OpenRouterProviderRoutingOptions,
|
|
5
|
+
AgentTemplate,
|
|
6
|
+
} from '../agent-template'
|
|
7
|
+
import type { ParamsExcluding } from '../function-params'
|
|
8
|
+
import type { Logger } from './logger'
|
|
9
|
+
import type { Model } from '../../old-constants'
|
|
10
|
+
import type { Message } from '../messages/anvil-message'
|
|
11
|
+
import type { ProviderMetadata } from '../messages/provider-metadata'
|
|
12
|
+
import type { PromptResult } from '../../util/error'
|
|
13
|
+
import type { generateText, streamText, ToolCallPart } from 'ai'
|
|
14
|
+
import type z from 'zod/v4'
|
|
15
|
+
|
|
16
|
+
/** Auto-recovered stream endings (see sdk/src/impl/stream-interruption.ts):
|
|
17
|
+
* - 'stream-interrupted': the stream ended without a finish marker
|
|
18
|
+
* (connection cut mid-response — a server deploy or network drop).
|
|
19
|
+
* - 'output-limit': the stream produced only reasoning and no usable answer,
|
|
20
|
+
* either by reaching its output limit or by reporting a normal stop. */
|
|
21
|
+
export type StreamRecoverySource = 'stream-interrupted' | 'output-limit'
|
|
22
|
+
|
|
23
|
+
export type StreamChunk =
|
|
24
|
+
| {
|
|
25
|
+
type: 'text'
|
|
26
|
+
text: string
|
|
27
|
+
agentId?: string
|
|
28
|
+
}
|
|
29
|
+
| {
|
|
30
|
+
type: 'reasoning'
|
|
31
|
+
text: string
|
|
32
|
+
/** Provider metadata for the whole reasoning segment (e.g. OpenRouter
|
|
33
|
+
* reasoning_details with thinking signatures), delivered on a final
|
|
34
|
+
* empty-text chunk once the segment ends. Stored on the history's
|
|
35
|
+
* reasoning part so the next request can replay it. */
|
|
36
|
+
providerOptions?: ProviderMetadata
|
|
37
|
+
}
|
|
38
|
+
| Pick<
|
|
39
|
+
ToolCallPart,
|
|
40
|
+
'type' | 'toolCallId' | 'toolName' | 'input' | 'providerOptions'
|
|
41
|
+
>
|
|
42
|
+
| {
|
|
43
|
+
type: 'error'
|
|
44
|
+
message: string
|
|
45
|
+
/** When set, this is an auto-recovered stream ending rather than a
|
|
46
|
+
* failure: consumers force another agent step so the model can
|
|
47
|
+
* continue, instead of wrapping the message as a tool-call failure and
|
|
48
|
+
* instead of the turn silently ending. */
|
|
49
|
+
source?: StreamRecoverySource
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type CacheDebugUsageData = {
|
|
53
|
+
inputTokens: number
|
|
54
|
+
outputTokens: number
|
|
55
|
+
reasoningOutputTokens?: number
|
|
56
|
+
cachedInputTokens: number
|
|
57
|
+
totalTokens: number
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Provider-reported usage for one model request. */
|
|
61
|
+
export type ModelUsageData = CacheDebugUsageData
|
|
62
|
+
|
|
63
|
+
/** Provider usage attributed by the runtime to the agent that made the request. */
|
|
64
|
+
export type AgentUsageData = ModelUsageData & {
|
|
65
|
+
isRoot: boolean
|
|
66
|
+
agentId?: string
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export type ContextCompactionData = {
|
|
70
|
+
trigger: 'context_limit' | 'cache_expiry' | 'context_limit_and_cache_expiry'
|
|
71
|
+
thresholdTokens: number
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export type PromptAiSdkStreamFn = (
|
|
75
|
+
params: {
|
|
76
|
+
apiKey: string
|
|
77
|
+
runId: string
|
|
78
|
+
messages: Message[]
|
|
79
|
+
clientSessionId: string
|
|
80
|
+
fingerprintId: string
|
|
81
|
+
model: Model
|
|
82
|
+
userId: string | undefined
|
|
83
|
+
chargeUser?: boolean
|
|
84
|
+
thinkingBudget?: number
|
|
85
|
+
userInputId: string
|
|
86
|
+
agentId?: string
|
|
87
|
+
maxRetries?: number
|
|
88
|
+
onCostCalculated?: (credits: number) => Promise<void>
|
|
89
|
+
onCacheDebugProviderRequestBuilt?: (params: {
|
|
90
|
+
provider: string
|
|
91
|
+
rawBody: unknown
|
|
92
|
+
normalizedBody?: unknown
|
|
93
|
+
}) => void
|
|
94
|
+
onCacheDebugUsageReceived?: (usage: CacheDebugUsageData) => void
|
|
95
|
+
onUsageReceived?: (usage: ModelUsageData) => void
|
|
96
|
+
/** The request ended without an exact final provider usage receipt. */
|
|
97
|
+
onUsageIncomplete?: () => void
|
|
98
|
+
includeCacheControl?: boolean
|
|
99
|
+
cacheDebugCorrelation?: string
|
|
100
|
+
agentProviderOptions?: OpenRouterProviderRoutingOptions
|
|
101
|
+
/** List of agents that can be spawned - used to transform agent tool calls */
|
|
102
|
+
spawnableAgents?: string[]
|
|
103
|
+
/** Map of locally available agent templates - used to transform agent tool calls */
|
|
104
|
+
localAgentTemplates?: Record<string, AgentTemplate>
|
|
105
|
+
/** Cost mode - 'free' mode means 0 credits charged for all agents */
|
|
106
|
+
costMode?: string
|
|
107
|
+
/** Extra key/values merged into the request's `anvil_metadata` field.
|
|
108
|
+
* Used to forward client-scoped identifiers (e.g. `anvil_instance_id`)
|
|
109
|
+
* that server-side gates read from the chat-completions body. */
|
|
110
|
+
extraAnvilMetadata?: Record<string, string>
|
|
111
|
+
sendAction: SendActionFn
|
|
112
|
+
logger: Logger
|
|
113
|
+
trackEvent: TrackEventFn
|
|
114
|
+
signal: AbortSignal
|
|
115
|
+
} & ParamsExcluding<typeof streamText, 'model' | 'messages'>,
|
|
116
|
+
) => AsyncGenerator<StreamChunk, PromptResult<string | null>>
|
|
117
|
+
|
|
118
|
+
export type PromptAiSdkFn = (
|
|
119
|
+
params: {
|
|
120
|
+
apiKey: string
|
|
121
|
+
runId: string
|
|
122
|
+
messages: Message[]
|
|
123
|
+
clientSessionId: string
|
|
124
|
+
fingerprintId: string
|
|
125
|
+
userInputId: string
|
|
126
|
+
model: Model
|
|
127
|
+
userId: string | undefined
|
|
128
|
+
chargeUser?: boolean
|
|
129
|
+
agentId?: string
|
|
130
|
+
onCostCalculated?: (credits: number) => Promise<void>
|
|
131
|
+
onCacheDebugProviderRequestBuilt?: (params: {
|
|
132
|
+
provider: string
|
|
133
|
+
rawBody: unknown
|
|
134
|
+
normalizedBody?: unknown
|
|
135
|
+
}) => void
|
|
136
|
+
onCacheDebugUsageReceived?: (usage: CacheDebugUsageData) => void
|
|
137
|
+
includeCacheControl?: boolean
|
|
138
|
+
cacheDebugCorrelation?: string
|
|
139
|
+
agentProviderOptions?: OpenRouterProviderRoutingOptions
|
|
140
|
+
maxRetries?: number
|
|
141
|
+
/** Cost mode - 'free' mode means 0 credits charged for all agents */
|
|
142
|
+
costMode?: string
|
|
143
|
+
sendAction: SendActionFn
|
|
144
|
+
logger: Logger
|
|
145
|
+
trackEvent: TrackEventFn
|
|
146
|
+
n?: number
|
|
147
|
+
signal: AbortSignal
|
|
148
|
+
} & ParamsExcluding<typeof generateText, 'model' | 'messages'>,
|
|
149
|
+
) => Promise<PromptResult<string>>
|
|
150
|
+
|
|
151
|
+
export type PromptAiSdkStructuredInput<T> = {
|
|
152
|
+
apiKey: string
|
|
153
|
+
runId: string
|
|
154
|
+
messages: Message[]
|
|
155
|
+
schema: z.ZodType<T>
|
|
156
|
+
clientSessionId: string
|
|
157
|
+
fingerprintId: string
|
|
158
|
+
userInputId: string
|
|
159
|
+
model: Model
|
|
160
|
+
userId: string | undefined
|
|
161
|
+
maxTokens?: number
|
|
162
|
+
temperature?: number
|
|
163
|
+
timeout?: number
|
|
164
|
+
chargeUser?: boolean
|
|
165
|
+
agentId?: string
|
|
166
|
+
onCostCalculated?: (credits: number) => Promise<void>
|
|
167
|
+
onCacheDebugProviderRequestBuilt?: (params: {
|
|
168
|
+
provider: string
|
|
169
|
+
rawBody: unknown
|
|
170
|
+
normalizedBody?: unknown
|
|
171
|
+
}) => void
|
|
172
|
+
onCacheDebugUsageReceived?: (usage: CacheDebugUsageData) => void
|
|
173
|
+
includeCacheControl?: boolean
|
|
174
|
+
cacheDebugCorrelation?: string
|
|
175
|
+
agentProviderOptions?: OpenRouterProviderRoutingOptions
|
|
176
|
+
maxRetries?: number
|
|
177
|
+
sendAction: SendActionFn
|
|
178
|
+
logger: Logger
|
|
179
|
+
trackEvent: TrackEventFn
|
|
180
|
+
signal: AbortSignal
|
|
181
|
+
}
|
|
182
|
+
export type PromptAiSdkStructuredOutput<T> = Promise<PromptResult<T>>
|
|
183
|
+
export type PromptAiSdkStructuredFn = <T>(
|
|
184
|
+
params: PromptAiSdkStructuredInput<T>,
|
|
185
|
+
) => PromptAiSdkStructuredOutput<T>
|
|
186
|
+
|
|
187
|
+
export type HandleOpenRouterStreamFn = (params: {
|
|
188
|
+
body: any
|
|
189
|
+
userId: string
|
|
190
|
+
agentId: string
|
|
191
|
+
}) => Promise<ReadableStream>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type LoggerFn = (
|
|
2
|
+
data: unknown,
|
|
3
|
+
msg?: string,
|
|
4
|
+
...args: unknown[]
|
|
5
|
+
) => unknown
|
|
6
|
+
|
|
7
|
+
export type Logger = {
|
|
8
|
+
debug: LoggerFn
|
|
9
|
+
info: LoggerFn
|
|
10
|
+
warn: LoggerFn
|
|
11
|
+
error: LoggerFn
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type LoggerWithContextFn = (context: Record<string, any>) => Logger
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** Severity levels for the unified logs stream. */
|
|
2
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'fatal'
|
|
3
|
+
|
|
4
|
+
/** Origin of a log row. */
|
|
5
|
+
export type LogSource = 'server' | 'cli' | 'browser'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* One normalized log/event record. This is the provider-agnostic shape the
|
|
9
|
+
* sink ingests (currently into Axiom — see `@anvil/logging`). An "event" is
|
|
10
|
+
* just a log row with `event` populated, so all logs and analytics events live
|
|
11
|
+
* in one stream. See docs/logging.md.
|
|
12
|
+
*/
|
|
13
|
+
export type LogRow = {
|
|
14
|
+
/** UUID for this row. */
|
|
15
|
+
id: string
|
|
16
|
+
/** Event time (becomes Axiom's `_time`). */
|
|
17
|
+
timestamp: Date
|
|
18
|
+
level: LogLevel
|
|
19
|
+
source: LogSource
|
|
20
|
+
/** Emitting service, e.g. 'web', 'agent-runtime', 'anvil-web', 'cli'. */
|
|
21
|
+
service?: string | null
|
|
22
|
+
/** Deploy environment: 'dev' | 'test' | 'prod'. */
|
|
23
|
+
env: string
|
|
24
|
+
/** Analytics or operational event name when applicable, else null. */
|
|
25
|
+
event?: string | null
|
|
26
|
+
/** Human-readable message (the formatted pino msg). */
|
|
27
|
+
message?: string | null
|
|
28
|
+
user_id?: string | null
|
|
29
|
+
client_session_id?: string | null
|
|
30
|
+
client_request_id?: string | null
|
|
31
|
+
fingerprint_id?: string | null
|
|
32
|
+
/** Structured payload. Serialized to a single string field on ingest. */
|
|
33
|
+
data?: unknown
|
|
34
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Message } from '../messages/anvil-message'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Records agent message histories for debugging (e.g. to a trace.jsonl file).
|
|
5
|
+
*
|
|
6
|
+
* Callers pass the agent's full message history at each step boundary;
|
|
7
|
+
* implementations are expected to persist each message only once (appending
|
|
8
|
+
* the delta since the previous call for the same agentId), so calling this
|
|
9
|
+
* every step does not grow storage quadratically.
|
|
10
|
+
*/
|
|
11
|
+
export type TraceWriter = {
|
|
12
|
+
recordStep: (params: {
|
|
13
|
+
agentId: string
|
|
14
|
+
agentType: string
|
|
15
|
+
runId: string | undefined
|
|
16
|
+
userInputId: string
|
|
17
|
+
step: number
|
|
18
|
+
system: string | undefined
|
|
19
|
+
messages: Message[]
|
|
20
|
+
}) => void
|
|
21
|
+
}
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { z } from 'zod/v4'
|
|
2
|
+
|
|
3
|
+
import { ALLOWED_MODEL_PREFIXES, models } from '../old-constants'
|
|
4
|
+
import { mcpConfigSchema } from './mcp'
|
|
5
|
+
|
|
6
|
+
import type { JSONSchema } from 'zod/v4/core'
|
|
7
|
+
|
|
8
|
+
// Filter models to only include those that begin with allowed prefixes
|
|
9
|
+
const filteredModels = Object.values(models).filter((model) =>
|
|
10
|
+
ALLOWED_MODEL_PREFIXES.some((prefix) => model.startsWith(prefix)),
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
if (filteredModels.length === 0) {
|
|
14
|
+
throw new Error('No valid models found with allowed prefixes')
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Simplified JSON Schema definition - supports object schemas with nested properties
|
|
18
|
+
export const JsonSchemaSchema: z.ZodType<
|
|
19
|
+
JSONSchema.BaseSchema,
|
|
20
|
+
JSONSchema.BaseSchema
|
|
21
|
+
> = z.lazy(() =>
|
|
22
|
+
z.looseObject({
|
|
23
|
+
type: z
|
|
24
|
+
.enum([
|
|
25
|
+
'object',
|
|
26
|
+
'array',
|
|
27
|
+
'string',
|
|
28
|
+
'number',
|
|
29
|
+
'boolean',
|
|
30
|
+
'null',
|
|
31
|
+
'integer',
|
|
32
|
+
])
|
|
33
|
+
.optional(),
|
|
34
|
+
description: z.string().optional(),
|
|
35
|
+
properties: z
|
|
36
|
+
.record(z.string(), JsonSchemaSchema.or(z.boolean()))
|
|
37
|
+
.optional(),
|
|
38
|
+
required: z.string().array().optional(),
|
|
39
|
+
enum: z
|
|
40
|
+
.union([z.string(), z.number(), z.boolean(), z.null()])
|
|
41
|
+
.array()
|
|
42
|
+
.optional(),
|
|
43
|
+
}),
|
|
44
|
+
)
|
|
45
|
+
const JsonObjectSchemaSchema = z.intersection(
|
|
46
|
+
JsonSchemaSchema,
|
|
47
|
+
z.object({ type: z.literal('object') }),
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
// Schema for the combined inputSchema object
|
|
51
|
+
const InputSchemaObjectSchema = z
|
|
52
|
+
.looseObject({
|
|
53
|
+
prompt: z
|
|
54
|
+
.looseObject({
|
|
55
|
+
type: z.literal('string'),
|
|
56
|
+
description: z.string().optional(),
|
|
57
|
+
})
|
|
58
|
+
.optional(), // Optional JSON schema for prompt validation
|
|
59
|
+
params: JsonObjectSchemaSchema.optional(), // Optional JSON schema for params validation
|
|
60
|
+
})
|
|
61
|
+
.optional()
|
|
62
|
+
|
|
63
|
+
// Schema for prompt fields that can be either a string or a path reference
|
|
64
|
+
const PromptFieldSchema = z.union([
|
|
65
|
+
z.string(), // Direct string content
|
|
66
|
+
z.object({ path: z.string() }), // Path reference to external file
|
|
67
|
+
])
|
|
68
|
+
export type PromptField = z.infer<typeof PromptFieldSchema>
|
|
69
|
+
|
|
70
|
+
const functionSchema = <T extends z.core.$ZodFunction>(schema: T) =>
|
|
71
|
+
z.custom<Parameters<T['implement']>[0]>((fn: any) => schema.implement(fn))
|
|
72
|
+
// Schema for the Logger interface
|
|
73
|
+
const LoggerSchema = z.object({
|
|
74
|
+
debug: z.function({
|
|
75
|
+
input: [z.any(), z.string().optional()],
|
|
76
|
+
output: z.void(),
|
|
77
|
+
}),
|
|
78
|
+
info: z.function({
|
|
79
|
+
input: [z.any(), z.string().optional()],
|
|
80
|
+
output: z.void(),
|
|
81
|
+
}),
|
|
82
|
+
warn: z.function({
|
|
83
|
+
input: [z.any(), z.string().optional()],
|
|
84
|
+
output: z.void(),
|
|
85
|
+
}),
|
|
86
|
+
error: z.function({
|
|
87
|
+
input: [z.any(), z.string().optional()],
|
|
88
|
+
output: z.void(),
|
|
89
|
+
}),
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
// Schema for validating handleSteps function signature
|
|
93
|
+
const HandleStepsSchema = functionSchema(
|
|
94
|
+
z.function({
|
|
95
|
+
input: [
|
|
96
|
+
z.object({
|
|
97
|
+
agentState: z.object({
|
|
98
|
+
agentId: z.string(),
|
|
99
|
+
parentId: z.string(),
|
|
100
|
+
messageHistory: z.array(z.any()),
|
|
101
|
+
}),
|
|
102
|
+
prompt: z.string().optional(),
|
|
103
|
+
params: z.any().optional(),
|
|
104
|
+
}),
|
|
105
|
+
LoggerSchema.optional(),
|
|
106
|
+
],
|
|
107
|
+
output: z.any(),
|
|
108
|
+
}),
|
|
109
|
+
).optional()
|
|
110
|
+
|
|
111
|
+
// Validates the Typescript template file.
|
|
112
|
+
export const DynamicAgentDefinitionSchema = z.object({
|
|
113
|
+
id: z
|
|
114
|
+
.string()
|
|
115
|
+
.regex(
|
|
116
|
+
/^[a-z0-9-]+$/,
|
|
117
|
+
'Agent ID must contain only lowercase letters, numbers, and hyphens',
|
|
118
|
+
), // The unique identifier for this agent
|
|
119
|
+
version: z.string().optional(),
|
|
120
|
+
publisher: z.string().optional(),
|
|
121
|
+
|
|
122
|
+
// Required fields for new agents
|
|
123
|
+
displayName: z.string(),
|
|
124
|
+
model: z.string(),
|
|
125
|
+
reasoningOptions: z
|
|
126
|
+
.object({
|
|
127
|
+
enabled: z.boolean().optional(),
|
|
128
|
+
exclude: z.boolean().optional(),
|
|
129
|
+
})
|
|
130
|
+
.and(
|
|
131
|
+
z.union([
|
|
132
|
+
z.object({ max_tokens: z.number() }),
|
|
133
|
+
z.object({
|
|
134
|
+
effort: z.enum(['high', 'medium', 'low', 'minimal', 'none']),
|
|
135
|
+
}),
|
|
136
|
+
]),
|
|
137
|
+
)
|
|
138
|
+
.optional(),
|
|
139
|
+
providerOptions: z
|
|
140
|
+
.object({
|
|
141
|
+
order: z.array(z.string()).optional(),
|
|
142
|
+
allow_fallbacks: z.boolean().optional(),
|
|
143
|
+
require_parameters: z.boolean().optional(),
|
|
144
|
+
data_collection: z.enum(['allow', 'deny']).optional(),
|
|
145
|
+
only: z.array(z.string()).optional(),
|
|
146
|
+
ignore: z.array(z.string()).optional(),
|
|
147
|
+
quantizations: z
|
|
148
|
+
.array(
|
|
149
|
+
z.enum([
|
|
150
|
+
'int4',
|
|
151
|
+
'int8',
|
|
152
|
+
'fp4',
|
|
153
|
+
'fp6',
|
|
154
|
+
'fp8',
|
|
155
|
+
'fp16',
|
|
156
|
+
'bf16',
|
|
157
|
+
'fp32',
|
|
158
|
+
'unknown',
|
|
159
|
+
]),
|
|
160
|
+
)
|
|
161
|
+
.optional(),
|
|
162
|
+
sort: z.enum(['price', 'throughput', 'latency']).optional(),
|
|
163
|
+
max_price: z
|
|
164
|
+
.object({
|
|
165
|
+
prompt: z.union([z.number(), z.string()]).optional(),
|
|
166
|
+
completion: z.union([z.number(), z.string()]).optional(),
|
|
167
|
+
image: z.union([z.number(), z.string()]).optional(),
|
|
168
|
+
audio: z.union([z.number(), z.string()]).optional(),
|
|
169
|
+
request: z.union([z.number(), z.string()]).optional(),
|
|
170
|
+
})
|
|
171
|
+
.optional(),
|
|
172
|
+
})
|
|
173
|
+
.optional(),
|
|
174
|
+
|
|
175
|
+
// Tools and spawnable agents
|
|
176
|
+
mcpServers: z.record(z.string(), mcpConfigSchema).default(() => ({})),
|
|
177
|
+
toolNames: z
|
|
178
|
+
.string()
|
|
179
|
+
.array()
|
|
180
|
+
.optional()
|
|
181
|
+
.default(() => []),
|
|
182
|
+
spawnableAgents: z
|
|
183
|
+
.array(z.string())
|
|
184
|
+
.optional()
|
|
185
|
+
.default(() => []),
|
|
186
|
+
|
|
187
|
+
// Input and output
|
|
188
|
+
inputSchema: InputSchemaObjectSchema,
|
|
189
|
+
includeMessageHistory: z.boolean().default(false),
|
|
190
|
+
inheritParentSystemPrompt: z.boolean().default(false),
|
|
191
|
+
windowedFileReads: z.boolean().optional(),
|
|
192
|
+
compactContext: z
|
|
193
|
+
.union([
|
|
194
|
+
z.boolean(),
|
|
195
|
+
z
|
|
196
|
+
.object({
|
|
197
|
+
cacheExpiryMs: z.number().nullish(),
|
|
198
|
+
cacheExpiryMinTokens: z.number().nullish(),
|
|
199
|
+
})
|
|
200
|
+
.strict(),
|
|
201
|
+
])
|
|
202
|
+
.optional(),
|
|
203
|
+
outputMode: z
|
|
204
|
+
.enum(['last_message', 'all_messages', 'structured_output'])
|
|
205
|
+
.default('last_message'),
|
|
206
|
+
outputSchema: JsonObjectSchemaSchema.optional(), // Optional JSON schema for output validation
|
|
207
|
+
|
|
208
|
+
// Prompts
|
|
209
|
+
spawnerPrompt: z.string().optional(),
|
|
210
|
+
systemPrompt: z.string().optional(),
|
|
211
|
+
instructionsPrompt: z.string().optional(),
|
|
212
|
+
stepPrompt: z.string().optional(),
|
|
213
|
+
|
|
214
|
+
// Optional generator function for programmatic agents
|
|
215
|
+
handleSteps: z.union([z.string(), HandleStepsSchema]).optional(),
|
|
216
|
+
})
|
|
217
|
+
export type DynamicAgentDefinition = z.input<
|
|
218
|
+
typeof DynamicAgentDefinitionSchema
|
|
219
|
+
>
|
|
220
|
+
export type DynamicAgentDefinitionParsed = z.infer<
|
|
221
|
+
typeof DynamicAgentDefinitionSchema
|
|
222
|
+
>
|
|
223
|
+
|
|
224
|
+
export const DynamicAgentTemplateSchema = DynamicAgentDefinitionSchema.extend({
|
|
225
|
+
systemPrompt: z.string(),
|
|
226
|
+
instructionsPrompt: z.string(),
|
|
227
|
+
stepPrompt: z.string(),
|
|
228
|
+
handleSteps: z.string().optional(), // Converted to string after processing
|
|
229
|
+
// Live copy of handleSteps preserved for in-process execution (the string
|
|
230
|
+
// form of a bundled/minified function may not survive an eval round-trip).
|
|
231
|
+
// Never serialized: JSON.stringify drops function values. Typed loosely so
|
|
232
|
+
// the zod-inferred signature doesn't fight the StepHandler type.
|
|
233
|
+
handleStepsFn: z
|
|
234
|
+
.custom<(...args: any[]) => any>((v) => typeof v === 'function')
|
|
235
|
+
.optional(),
|
|
236
|
+
})
|
|
237
|
+
.refine(
|
|
238
|
+
(data) => {
|
|
239
|
+
// If outputSchema is provided, outputMode must be explicitly set to 'structured_output'
|
|
240
|
+
if (data.outputSchema && data.outputMode !== 'structured_output') {
|
|
241
|
+
return false
|
|
242
|
+
}
|
|
243
|
+
return true
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
message:
|
|
247
|
+
"outputSchema requires outputMode to be explicitly set to 'structured_output'.",
|
|
248
|
+
path: ['outputMode'],
|
|
249
|
+
},
|
|
250
|
+
)
|
|
251
|
+
// Note(James): Disabled so that handleSteps could use set_output while the llm does not see or have access to the set_output tool.
|
|
252
|
+
// .refine(
|
|
253
|
+
// (data) => {
|
|
254
|
+
// // If outputMode is 'structured_output', 'set_output' tool must be included
|
|
255
|
+
// if (
|
|
256
|
+
// data.outputMode === 'structured_output' &&
|
|
257
|
+
// !data.toolNames.includes('set_output')
|
|
258
|
+
// ) {
|
|
259
|
+
// return false
|
|
260
|
+
// }
|
|
261
|
+
// return true
|
|
262
|
+
// },
|
|
263
|
+
// {
|
|
264
|
+
// message:
|
|
265
|
+
// "outputMode 'structured_output' requires the 'set_output' tool. Add 'set_output' to toolNames.",
|
|
266
|
+
// path: ['toolNames'],
|
|
267
|
+
// },
|
|
268
|
+
// )
|
|
269
|
+
// Note(James): Disabled so that a parent agent can have set_output tool and 'last_message' outputMode while its subagents use 'structured_output'. (The set_output tool must be included in parent to preserver prompt caching.)
|
|
270
|
+
// .refine(
|
|
271
|
+
// (data) => {
|
|
272
|
+
// // If 'set_output' tool is included, outputMode must be 'structured_output'
|
|
273
|
+
// if (
|
|
274
|
+
// data.toolNames.includes('set_output') &&
|
|
275
|
+
// data.outputMode !== 'structured_output'
|
|
276
|
+
// ) {
|
|
277
|
+
// return false
|
|
278
|
+
// }
|
|
279
|
+
// return true
|
|
280
|
+
// },
|
|
281
|
+
// {
|
|
282
|
+
// message:
|
|
283
|
+
// "'set_output' tool requires outputMode to be 'structured_output'. Change outputMode to 'structured_output' or remove 'set_output' from toolNames.",
|
|
284
|
+
// path: ['outputMode'],
|
|
285
|
+
// },
|
|
286
|
+
// )
|
|
287
|
+
.refine(
|
|
288
|
+
(data) => {
|
|
289
|
+
// A non-empty spawnableAgents array requires some way to spawn them:
|
|
290
|
+
// the 'spawn_agents' or 'spawn_agent_inline' tool, or a programmatic
|
|
291
|
+
// handleSteps generator (which can yield spawn tool calls without the
|
|
292
|
+
// LLM having access to the tools).
|
|
293
|
+
if (
|
|
294
|
+
data.spawnableAgents.length > 0 &&
|
|
295
|
+
!data.toolNames.includes('spawn_agents') &&
|
|
296
|
+
!data.toolNames.includes('spawn_agent_inline') &&
|
|
297
|
+
!data.handleSteps &&
|
|
298
|
+
!data.handleStepsFn
|
|
299
|
+
) {
|
|
300
|
+
return false
|
|
301
|
+
}
|
|
302
|
+
return true
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
message:
|
|
306
|
+
"Non-empty spawnableAgents array requires the 'spawn_agents' tool. Add 'spawn_agents' to toolNames (or spawn programmatically via handleSteps) or remove spawnableAgents.",
|
|
307
|
+
path: ['toolNames'],
|
|
308
|
+
},
|
|
309
|
+
)
|
|
310
|
+
.refine(
|
|
311
|
+
(data) => {
|
|
312
|
+
// If inheritParentSystemPrompt is true, systemPrompt must be empty or undefined
|
|
313
|
+
if (
|
|
314
|
+
data.inheritParentSystemPrompt &&
|
|
315
|
+
data.systemPrompt &&
|
|
316
|
+
data.systemPrompt.trim() !== ''
|
|
317
|
+
) {
|
|
318
|
+
return false
|
|
319
|
+
}
|
|
320
|
+
return true
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
message:
|
|
324
|
+
'Cannot specify both systemPrompt and inheritParentSystemPrompt. When inheritParentSystemPrompt is true, systemPrompt must be empty.',
|
|
325
|
+
path: ['systemPrompt'],
|
|
326
|
+
},
|
|
327
|
+
)
|
|
328
|
+
export type DynamicAgentTemplate = z.infer<typeof DynamicAgentTemplateSchema>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type fs from 'fs'
|
|
2
|
+
|
|
3
|
+
/** File system used for Anvil SDK.
|
|
4
|
+
*
|
|
5
|
+
* Compatible with `fs.promises` from the `'fs'` module.
|
|
6
|
+
*/
|
|
7
|
+
export type AnvilFileSystem = Pick<
|
|
8
|
+
typeof fs.promises,
|
|
9
|
+
'mkdir' | 'readdir' | 'readFile' | 'stat' | 'unlink' | 'writeFile'
|
|
10
|
+
>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { UnionToIntersection } from 'bun-types/vendor/expect-type'
|
|
2
|
+
|
|
3
|
+
type Prettify<T> = {
|
|
4
|
+
[K in keyof T]: T[K]
|
|
5
|
+
} & {}
|
|
6
|
+
|
|
7
|
+
type StripExact<T> = T extends infer U & { [x: string]: never } ? U : T
|
|
8
|
+
|
|
9
|
+
type ParamsOfFunction<T> = T extends (params: infer C) => any
|
|
10
|
+
? StripExact<C>
|
|
11
|
+
: never
|
|
12
|
+
|
|
13
|
+
type IsUnion<T, U = T> = T extends any ? ([U] extends [T] ? false : true) : false
|
|
14
|
+
type ParamsOfArray<T> = UnionToIntersection<
|
|
15
|
+
T extends [infer fn, ...infer rest]
|
|
16
|
+
? ParamsOfFunction<fn> | ParamsOfArray<rest>
|
|
17
|
+
: {}
|
|
18
|
+
>
|
|
19
|
+
type ParamsOfUnion<T> = IsUnion<T> extends true
|
|
20
|
+
? UnionToIntersection<ParamsOfFunction<T>>
|
|
21
|
+
: ParamsOfFunction<T>
|
|
22
|
+
|
|
23
|
+
export type ParamsOf<T> = Prettify<
|
|
24
|
+
T extends any[] ? ParamsOfArray<T> : ParamsOfUnion<T>
|
|
25
|
+
>
|
|
26
|
+
|
|
27
|
+
export type OptionalFields<T, K extends keyof T> = Prettify<
|
|
28
|
+
Omit<T, K> & Partial<Pick<T, K>>
|
|
29
|
+
>
|
|
30
|
+
|
|
31
|
+
export type ParamsExcluding<T, K extends keyof ParamsOf<T>> = Prettify<
|
|
32
|
+
Omit<ParamsOf<T>, K>
|
|
33
|
+
>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type GrantType =
|
|
2
|
+
| 'free'
|
|
3
|
+
| 'referral'
|
|
4
|
+
| 'referral_legacy'
|
|
5
|
+
| 'subscription'
|
|
6
|
+
| 'purchase'
|
|
7
|
+
| 'admin'
|
|
8
|
+
| 'organization'
|
|
9
|
+
| 'ad' // Credits earned from ads (impressions, clicks, acquisitions, etc.)
|
|
10
|
+
|
|
11
|
+
export const GrantTypeValues = [
|
|
12
|
+
'free',
|
|
13
|
+
'referral',
|
|
14
|
+
'referral_legacy',
|
|
15
|
+
'subscription',
|
|
16
|
+
'purchase',
|
|
17
|
+
'admin',
|
|
18
|
+
'organization',
|
|
19
|
+
'ad',
|
|
20
|
+
] as const
|