@alumbwe/anvil 1.0.20 → 1.0.22
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 +74 -70
- 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,846 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, test } from 'bun:test'
|
|
2
|
+
|
|
3
|
+
import { validateAgents } from '../templates/agent-validation'
|
|
4
|
+
import { DynamicAgentDefinitionSchema } from '../types/dynamic-agent-template'
|
|
5
|
+
import { getStubProjectFileContext } from '../util/file'
|
|
6
|
+
|
|
7
|
+
import type { DynamicAgentTemplate } from '../types/dynamic-agent-template'
|
|
8
|
+
import type { AgentState } from '../types/session-state'
|
|
9
|
+
import type { ProjectFileContext } from '../util/file'
|
|
10
|
+
import type { Logger } from '@anvil/common/types/contracts/logger'
|
|
11
|
+
|
|
12
|
+
describe('Agent Validation', () => {
|
|
13
|
+
let mockFileContext: ProjectFileContext
|
|
14
|
+
let mockAgentTemplate: DynamicAgentTemplate
|
|
15
|
+
const logger: Logger = {
|
|
16
|
+
debug: () => {},
|
|
17
|
+
error: () => {},
|
|
18
|
+
info: () => {},
|
|
19
|
+
warn: () => {},
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
mockFileContext = getStubProjectFileContext()
|
|
24
|
+
|
|
25
|
+
mockAgentTemplate = {
|
|
26
|
+
id: 'test-agent',
|
|
27
|
+
version: '1.0.0',
|
|
28
|
+
displayName: 'Test Agent',
|
|
29
|
+
spawnerPrompt: 'Testing',
|
|
30
|
+
model: 'claude-3-5-sonnet-20241022',
|
|
31
|
+
outputMode: 'structured_output' as const,
|
|
32
|
+
mcpServers: {},
|
|
33
|
+
toolNames: ['set_output'],
|
|
34
|
+
spawnableAgents: [],
|
|
35
|
+
includeMessageHistory: true,
|
|
36
|
+
inheritParentSystemPrompt: false,
|
|
37
|
+
systemPrompt: 'Test system prompt',
|
|
38
|
+
instructionsPrompt: 'Test user prompt',
|
|
39
|
+
stepPrompt: 'Test agent step prompt',
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
describe('Dynamic Agent Loading', () => {
|
|
44
|
+
it('should load valid dynamic agent template', async () => {
|
|
45
|
+
const fileContext: ProjectFileContext = {
|
|
46
|
+
...mockFileContext,
|
|
47
|
+
agentTemplates: {
|
|
48
|
+
'brainstormer.ts': {
|
|
49
|
+
id: 'brainstormer',
|
|
50
|
+
version: '1.0.0',
|
|
51
|
+
displayName: 'Brainy',
|
|
52
|
+
spawnerPrompt: 'Creative thought partner',
|
|
53
|
+
model: 'anthropic/claude-4-sonnet-20250522',
|
|
54
|
+
systemPrompt: 'You are a creative brainstormer.',
|
|
55
|
+
instructionsPrompt: 'Help brainstorm ideas.',
|
|
56
|
+
stepPrompt: 'Continue brainstorming.',
|
|
57
|
+
toolNames: ['end_turn', 'spawn_agents'],
|
|
58
|
+
spawnableAgents: ['thinker', 'researcher'],
|
|
59
|
+
outputMode: 'last_message',
|
|
60
|
+
includeMessageHistory: true,
|
|
61
|
+
inheritParentSystemPrompt: false,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const result = validateAgents({
|
|
67
|
+
agentTemplates: fileContext.agentTemplates || {},
|
|
68
|
+
logger,
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
expect(result.validationErrors).toHaveLength(0)
|
|
72
|
+
expect(result.templates).toHaveProperty('brainstormer')
|
|
73
|
+
expect(result.templates.brainstormer.displayName).toBe('Brainy')
|
|
74
|
+
expect(result.templates.brainstormer.id).toBe('brainstormer')
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('should merge static and dynamic templates', async () => {
|
|
78
|
+
const fileContext: ProjectFileContext = {
|
|
79
|
+
...mockFileContext,
|
|
80
|
+
agentTemplates: {
|
|
81
|
+
'custom.ts': {
|
|
82
|
+
id: 'custom-agent',
|
|
83
|
+
version: '1.0.0',
|
|
84
|
+
displayName: 'Custom',
|
|
85
|
+
spawnerPrompt: 'Custom agent',
|
|
86
|
+
model: 'anthropic/claude-4-sonnet-20250522',
|
|
87
|
+
systemPrompt: 'Custom system prompt',
|
|
88
|
+
instructionsPrompt: 'Custom user prompt',
|
|
89
|
+
stepPrompt: 'Custom step prompt',
|
|
90
|
+
outputMode: 'last_message',
|
|
91
|
+
includeMessageHistory: true,
|
|
92
|
+
inheritParentSystemPrompt: false,
|
|
93
|
+
toolNames: ['end_turn'],
|
|
94
|
+
spawnableAgents: [],
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const result = validateAgents({
|
|
100
|
+
agentTemplates: fileContext.agentTemplates || {},
|
|
101
|
+
logger,
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
// Should have dynamic templates
|
|
105
|
+
expect(result.templates).toHaveProperty('custom-agent') // Dynamic
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('should handle agents with JSON schemas', async () => {
|
|
109
|
+
const fileContext: ProjectFileContext = {
|
|
110
|
+
...mockFileContext,
|
|
111
|
+
agentTemplates: {
|
|
112
|
+
'schema-agent.ts': {
|
|
113
|
+
id: 'schema-agent',
|
|
114
|
+
version: '1.0.0',
|
|
115
|
+
displayName: 'Schema Agent',
|
|
116
|
+
spawnerPrompt: 'Agent with JSON schemas',
|
|
117
|
+
model: 'anthropic/claude-4-sonnet-20250522',
|
|
118
|
+
systemPrompt: 'Test system prompt',
|
|
119
|
+
instructionsPrompt: 'Test user prompt',
|
|
120
|
+
stepPrompt: 'Test step prompt',
|
|
121
|
+
inputSchema: {
|
|
122
|
+
prompt: {
|
|
123
|
+
type: 'string',
|
|
124
|
+
description: 'A test prompt',
|
|
125
|
+
},
|
|
126
|
+
params: {
|
|
127
|
+
type: 'object',
|
|
128
|
+
properties: {
|
|
129
|
+
temperature: { type: 'number', minimum: 0, maximum: 1 },
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
outputMode: 'last_message',
|
|
134
|
+
includeMessageHistory: true,
|
|
135
|
+
inheritParentSystemPrompt: false,
|
|
136
|
+
toolNames: ['end_turn'],
|
|
137
|
+
spawnableAgents: [],
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const result = validateAgents({
|
|
143
|
+
agentTemplates: fileContext.agentTemplates || {},
|
|
144
|
+
logger,
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
expect(result.validationErrors).toHaveLength(0)
|
|
148
|
+
expect(result.templates).toHaveProperty('schema-agent')
|
|
149
|
+
expect(result.templates['schema-agent'].inputSchema.prompt).toBeDefined()
|
|
150
|
+
expect(result.templates['schema-agent'].inputSchema.params).toBeDefined()
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
it('should return validation errors for invalid schemas', async () => {
|
|
154
|
+
const fileContext: ProjectFileContext = {
|
|
155
|
+
...mockFileContext,
|
|
156
|
+
agentTemplates: {
|
|
157
|
+
'invalid-schema-agent.ts': {
|
|
158
|
+
id: 'invalid-schema-agent',
|
|
159
|
+
version: '1.0.0',
|
|
160
|
+
displayName: 'Invalid Schema Agent',
|
|
161
|
+
spawnerPrompt: 'Agent with invalid schemas',
|
|
162
|
+
model: 'anthropic/claude-4-sonnet-20250522',
|
|
163
|
+
systemPrompt: 'Test system prompt',
|
|
164
|
+
instructionsPrompt: 'Test user prompt',
|
|
165
|
+
stepPrompt: 'Test step prompt',
|
|
166
|
+
inputSchema: {
|
|
167
|
+
prompt: {} as Record<string, never>, // invalid prompt schema
|
|
168
|
+
},
|
|
169
|
+
outputMode: 'last_message',
|
|
170
|
+
includeMessageHistory: true,
|
|
171
|
+
inheritParentSystemPrompt: false,
|
|
172
|
+
toolNames: ['end_turn'],
|
|
173
|
+
spawnableAgents: [],
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const result = validateAgents({
|
|
179
|
+
agentTemplates: fileContext.agentTemplates || {},
|
|
180
|
+
logger,
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
expect(result.validationErrors).toHaveLength(1)
|
|
184
|
+
expect(result.validationErrors[0].message).toContain(
|
|
185
|
+
'Schema validation failed',
|
|
186
|
+
)
|
|
187
|
+
expect(result.templates).not.toHaveProperty('invalid-schema-agent')
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
it('should handle missing override field as non-override template', async () => {
|
|
191
|
+
const fileContext: ProjectFileContext = {
|
|
192
|
+
...mockFileContext,
|
|
193
|
+
agentTemplates: {
|
|
194
|
+
'no-override-field.ts': {
|
|
195
|
+
id: 'no-override-agent',
|
|
196
|
+
version: '1.0.0',
|
|
197
|
+
// No override field - should be treated as non-override
|
|
198
|
+
displayName: 'No Override Agent',
|
|
199
|
+
spawnerPrompt: 'Agent without override field',
|
|
200
|
+
model: 'anthropic/claude-4-sonnet-20250522',
|
|
201
|
+
systemPrompt: 'Test system prompt',
|
|
202
|
+
instructionsPrompt: 'Test user prompt',
|
|
203
|
+
stepPrompt: 'Test step prompt',
|
|
204
|
+
outputMode: 'last_message',
|
|
205
|
+
includeMessageHistory: true,
|
|
206
|
+
inheritParentSystemPrompt: false,
|
|
207
|
+
toolNames: ['end_turn'],
|
|
208
|
+
spawnableAgents: [],
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const result = validateAgents({
|
|
214
|
+
agentTemplates: fileContext.agentTemplates || {},
|
|
215
|
+
logger,
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
expect(result.validationErrors).toHaveLength(0)
|
|
219
|
+
expect(result.templates).toHaveProperty('no-override-agent')
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
it('should validate spawnable agents including dynamic agents from first pass', async () => {
|
|
223
|
+
const fileContext: ProjectFileContext = {
|
|
224
|
+
...mockFileContext,
|
|
225
|
+
agentTemplates: {
|
|
226
|
+
'git-committer.ts': {
|
|
227
|
+
id: 'anvilai-git-committer',
|
|
228
|
+
version: '0.0.1',
|
|
229
|
+
displayName: 'Git Committer',
|
|
230
|
+
spawnerPrompt: 'A git committer agent',
|
|
231
|
+
model: 'google/gemini-2.5-pro',
|
|
232
|
+
systemPrompt: 'You are an expert software developer.',
|
|
233
|
+
instructionsPrompt: 'Create a commit message.',
|
|
234
|
+
stepPrompt: 'Make sure to end your response.',
|
|
235
|
+
spawnableAgents: [], // No spawnable agents
|
|
236
|
+
outputMode: 'last_message',
|
|
237
|
+
includeMessageHistory: true,
|
|
238
|
+
inheritParentSystemPrompt: false,
|
|
239
|
+
toolNames: ['end_turn'],
|
|
240
|
+
},
|
|
241
|
+
'spawner.ts': {
|
|
242
|
+
id: 'spawner-agent',
|
|
243
|
+
version: '1.0.0',
|
|
244
|
+
displayName: 'Spawner Agent',
|
|
245
|
+
spawnerPrompt: 'Agent that can spawn git-committer',
|
|
246
|
+
model: 'anthropic/claude-4-sonnet-20250522',
|
|
247
|
+
systemPrompt: 'Test system prompt',
|
|
248
|
+
instructionsPrompt: 'Test user prompt',
|
|
249
|
+
stepPrompt: 'Test step prompt',
|
|
250
|
+
spawnableAgents: ['anvilai-git-committer'], // Should be valid after first pass
|
|
251
|
+
outputMode: 'last_message',
|
|
252
|
+
includeMessageHistory: true,
|
|
253
|
+
inheritParentSystemPrompt: false,
|
|
254
|
+
toolNames: ['end_turn', 'spawn_agents'],
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const result = validateAgents({
|
|
260
|
+
agentTemplates: fileContext.agentTemplates || {},
|
|
261
|
+
logger,
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
expect(result.validationErrors).toHaveLength(0)
|
|
265
|
+
expect(result.templates).toHaveProperty('anvilai-git-committer')
|
|
266
|
+
expect(result.templates).toHaveProperty('spawner-agent')
|
|
267
|
+
expect(result.templates['spawner-agent'].spawnableAgents).toContain(
|
|
268
|
+
'anvilai-git-committer', // Full agent ID with prefix
|
|
269
|
+
)
|
|
270
|
+
})
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
describe('Schema Validation', () => {
|
|
274
|
+
describe('Default Schema Behavior', () => {
|
|
275
|
+
it('should have no prompt schema when no inputSchema provided', async () => {
|
|
276
|
+
const fileContext: ProjectFileContext = {
|
|
277
|
+
...mockFileContext,
|
|
278
|
+
agentTemplates: {
|
|
279
|
+
'no-prompt-schema.ts': {
|
|
280
|
+
id: 'no-prompt-schema-agent',
|
|
281
|
+
version: '1.0.0',
|
|
282
|
+
displayName: 'No Prompt Schema Agent',
|
|
283
|
+
spawnerPrompt: 'Test agent without prompt schema',
|
|
284
|
+
model: 'anthropic/claude-4-sonnet-20250522',
|
|
285
|
+
systemPrompt: 'Test system prompt',
|
|
286
|
+
instructionsPrompt: 'Test user prompt',
|
|
287
|
+
stepPrompt: 'Test step prompt',
|
|
288
|
+
outputMode: 'last_message',
|
|
289
|
+
includeMessageHistory: true,
|
|
290
|
+
inheritParentSystemPrompt: false,
|
|
291
|
+
toolNames: ['end_turn'],
|
|
292
|
+
spawnableAgents: [],
|
|
293
|
+
// No inputSchema
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const result = validateAgents({
|
|
299
|
+
agentTemplates: fileContext.agentTemplates || {},
|
|
300
|
+
logger,
|
|
301
|
+
})
|
|
302
|
+
|
|
303
|
+
expect(result.validationErrors).toHaveLength(0)
|
|
304
|
+
expect(result.templates).toHaveProperty('no-prompt-schema-agent')
|
|
305
|
+
expect(
|
|
306
|
+
result.templates['no-prompt-schema-agent'].inputSchema.prompt,
|
|
307
|
+
).toBeUndefined()
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
it('should not have params schema when no paramsSchema provided', async () => {
|
|
311
|
+
const fileContext: ProjectFileContext = {
|
|
312
|
+
...mockFileContext,
|
|
313
|
+
agentTemplates: {
|
|
314
|
+
'no-params-schema.ts': {
|
|
315
|
+
id: 'no-params-schema-agent',
|
|
316
|
+
version: '1.0.0',
|
|
317
|
+
displayName: 'No Params Schema Agent',
|
|
318
|
+
spawnerPrompt: 'Test agent without params schema',
|
|
319
|
+
model: 'anthropic/claude-4-sonnet-20250522',
|
|
320
|
+
systemPrompt: 'Test system prompt',
|
|
321
|
+
instructionsPrompt: 'Test user prompt',
|
|
322
|
+
stepPrompt: 'Test step prompt',
|
|
323
|
+
outputMode: 'last_message',
|
|
324
|
+
includeMessageHistory: true,
|
|
325
|
+
inheritParentSystemPrompt: false,
|
|
326
|
+
toolNames: ['end_turn'],
|
|
327
|
+
spawnableAgents: [],
|
|
328
|
+
// No paramsSchema
|
|
329
|
+
},
|
|
330
|
+
},
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const result = validateAgents({
|
|
334
|
+
agentTemplates: fileContext.agentTemplates || {},
|
|
335
|
+
logger,
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
expect(result.validationErrors).toHaveLength(0)
|
|
339
|
+
expect(result.templates).toHaveProperty('no-params-schema-agent')
|
|
340
|
+
expect(
|
|
341
|
+
result.templates['no-params-schema-agent'].inputSchema.params,
|
|
342
|
+
).toBeUndefined()
|
|
343
|
+
})
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
describe('Complex Schema Scenarios', () => {
|
|
347
|
+
it('should handle both inputSchema prompt and params together', async () => {
|
|
348
|
+
const fileContext: ProjectFileContext = {
|
|
349
|
+
...mockFileContext,
|
|
350
|
+
agentTemplates: {
|
|
351
|
+
'both-schemas.ts': {
|
|
352
|
+
id: 'both-schemas-agent',
|
|
353
|
+
version: '1.0.0',
|
|
354
|
+
displayName: 'Both Schemas Agent',
|
|
355
|
+
spawnerPrompt: 'Test agent with both schemas',
|
|
356
|
+
model: 'anthropic/claude-4-sonnet-20250522',
|
|
357
|
+
systemPrompt: 'Test system prompt',
|
|
358
|
+
instructionsPrompt: 'Test user prompt',
|
|
359
|
+
stepPrompt: 'Test step prompt',
|
|
360
|
+
inputSchema: {
|
|
361
|
+
prompt: {
|
|
362
|
+
type: 'string',
|
|
363
|
+
minLength: 1,
|
|
364
|
+
description: 'A required prompt',
|
|
365
|
+
},
|
|
366
|
+
params: {
|
|
367
|
+
type: 'object',
|
|
368
|
+
properties: {
|
|
369
|
+
mode: {
|
|
370
|
+
type: 'string',
|
|
371
|
+
enum: ['fast', 'thorough'],
|
|
372
|
+
},
|
|
373
|
+
iterations: {
|
|
374
|
+
type: 'integer',
|
|
375
|
+
minimum: 1,
|
|
376
|
+
maximum: 10,
|
|
377
|
+
default: 3,
|
|
378
|
+
},
|
|
379
|
+
},
|
|
380
|
+
required: ['mode'],
|
|
381
|
+
},
|
|
382
|
+
},
|
|
383
|
+
spawnableAgents: [],
|
|
384
|
+
outputMode: 'last_message',
|
|
385
|
+
includeMessageHistory: true,
|
|
386
|
+
inheritParentSystemPrompt: false,
|
|
387
|
+
toolNames: ['end_turn'],
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const result = validateAgents({
|
|
393
|
+
agentTemplates: fileContext.agentTemplates || {},
|
|
394
|
+
logger,
|
|
395
|
+
})
|
|
396
|
+
|
|
397
|
+
expect(result.validationErrors).toHaveLength(0)
|
|
398
|
+
expect(result.templates).toHaveProperty('both-schemas-agent')
|
|
399
|
+
|
|
400
|
+
const template = result.templates['both-schemas-agent']
|
|
401
|
+
expect(template.inputSchema.prompt).toBeDefined()
|
|
402
|
+
expect(template.inputSchema.params).toBeDefined()
|
|
403
|
+
|
|
404
|
+
const inputPromptSchema = template.inputSchema.prompt!
|
|
405
|
+
const paramsSchema = template.inputSchema.params!
|
|
406
|
+
|
|
407
|
+
// Test prompt schema
|
|
408
|
+
expect(inputPromptSchema.safeParse('valid prompt').success).toBe(true)
|
|
409
|
+
expect(inputPromptSchema.safeParse('').success).toBe(false) // Too short
|
|
410
|
+
|
|
411
|
+
// Test params schema
|
|
412
|
+
expect(
|
|
413
|
+
paramsSchema.safeParse({ mode: 'fast', iterations: 5 }).success,
|
|
414
|
+
).toBe(true)
|
|
415
|
+
expect(paramsSchema.safeParse({ mode: 'invalid' }).success).toBe(false) // Invalid enum
|
|
416
|
+
expect(paramsSchema.safeParse({ iterations: 5 }).success).toBe(false) // Missing required field
|
|
417
|
+
})
|
|
418
|
+
|
|
419
|
+
it('should handle schema with nested objects and arrays', async () => {
|
|
420
|
+
const fileContext: ProjectFileContext = {
|
|
421
|
+
...mockFileContext,
|
|
422
|
+
agentTemplates: {
|
|
423
|
+
'complex-schema.ts': {
|
|
424
|
+
id: 'complex-schema-agent',
|
|
425
|
+
version: '1.0.0',
|
|
426
|
+
displayName: 'Complex Schema Agent',
|
|
427
|
+
spawnerPrompt: 'Test agent with complex nested schema',
|
|
428
|
+
model: 'anthropic/claude-4-sonnet-20250522',
|
|
429
|
+
systemPrompt: 'Test system prompt',
|
|
430
|
+
instructionsPrompt: 'Test user prompt',
|
|
431
|
+
stepPrompt: 'Test step prompt',
|
|
432
|
+
inputSchema: {
|
|
433
|
+
params: {
|
|
434
|
+
type: 'object',
|
|
435
|
+
properties: {
|
|
436
|
+
config: {
|
|
437
|
+
type: 'object',
|
|
438
|
+
properties: {
|
|
439
|
+
name: { type: 'string' },
|
|
440
|
+
settings: {
|
|
441
|
+
type: 'array',
|
|
442
|
+
items: {
|
|
443
|
+
type: 'object',
|
|
444
|
+
properties: {
|
|
445
|
+
key: { type: 'string' },
|
|
446
|
+
value: { type: 'string' },
|
|
447
|
+
},
|
|
448
|
+
required: ['key', 'value'],
|
|
449
|
+
},
|
|
450
|
+
},
|
|
451
|
+
},
|
|
452
|
+
required: ['name'],
|
|
453
|
+
},
|
|
454
|
+
},
|
|
455
|
+
required: ['config'],
|
|
456
|
+
},
|
|
457
|
+
},
|
|
458
|
+
outputMode: 'last_message',
|
|
459
|
+
includeMessageHistory: true,
|
|
460
|
+
inheritParentSystemPrompt: false,
|
|
461
|
+
toolNames: ['end_turn'],
|
|
462
|
+
spawnableAgents: [],
|
|
463
|
+
},
|
|
464
|
+
},
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const result = validateAgents({
|
|
468
|
+
agentTemplates: fileContext.agentTemplates || {},
|
|
469
|
+
logger,
|
|
470
|
+
})
|
|
471
|
+
|
|
472
|
+
expect(result.validationErrors).toHaveLength(0)
|
|
473
|
+
expect(result.templates).toHaveProperty('complex-schema-agent')
|
|
474
|
+
|
|
475
|
+
const paramsSchema =
|
|
476
|
+
result.templates['complex-schema-agent'].inputSchema.params!
|
|
477
|
+
|
|
478
|
+
// Test valid complex object
|
|
479
|
+
const validParams = {
|
|
480
|
+
config: {
|
|
481
|
+
name: 'test config',
|
|
482
|
+
settings: [
|
|
483
|
+
{ key: 'setting1', value: 'value1' },
|
|
484
|
+
{ key: 'setting2', value: 'value2' },
|
|
485
|
+
],
|
|
486
|
+
},
|
|
487
|
+
}
|
|
488
|
+
expect(paramsSchema.safeParse(validParams).success).toBe(true)
|
|
489
|
+
|
|
490
|
+
// Test invalid nested structure
|
|
491
|
+
const invalidParams = {
|
|
492
|
+
config: {
|
|
493
|
+
name: 'test config',
|
|
494
|
+
settings: [
|
|
495
|
+
{ key: 'setting1' }, // Missing required 'value' field
|
|
496
|
+
],
|
|
497
|
+
},
|
|
498
|
+
}
|
|
499
|
+
expect(paramsSchema.safeParse(invalidParams).success).toBe(false)
|
|
500
|
+
})
|
|
501
|
+
})
|
|
502
|
+
|
|
503
|
+
describe('Error Message Quality', () => {
|
|
504
|
+
it('should include file path in error messages', async () => {
|
|
505
|
+
const fileContext: ProjectFileContext = {
|
|
506
|
+
...mockFileContext,
|
|
507
|
+
agentTemplates: {
|
|
508
|
+
'error-context.ts': {
|
|
509
|
+
id: 'error-context-agent',
|
|
510
|
+
version: '1.0.0',
|
|
511
|
+
displayName: 'Error Context Agent',
|
|
512
|
+
spawnerPrompt: 'Test agent for error context',
|
|
513
|
+
model: 'anthropic/claude-4-sonnet-20250522',
|
|
514
|
+
systemPrompt: 'Test system prompt',
|
|
515
|
+
instructionsPrompt: 'Test user prompt',
|
|
516
|
+
stepPrompt: 'Test step prompt',
|
|
517
|
+
inputSchema: {
|
|
518
|
+
prompt: 10 as unknown as Record<string, never>, // Invalid - number schema
|
|
519
|
+
},
|
|
520
|
+
outputMode: 'last_message',
|
|
521
|
+
includeMessageHistory: true,
|
|
522
|
+
inheritParentSystemPrompt: false,
|
|
523
|
+
toolNames: ['end_turn'],
|
|
524
|
+
spawnableAgents: [],
|
|
525
|
+
},
|
|
526
|
+
},
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
const result = validateAgents({
|
|
530
|
+
agentTemplates: fileContext.agentTemplates || {},
|
|
531
|
+
logger,
|
|
532
|
+
})
|
|
533
|
+
|
|
534
|
+
expect(result.validationErrors).toHaveLength(1)
|
|
535
|
+
expect(result.validationErrors[0].message).toContain(
|
|
536
|
+
'Schema validation failed',
|
|
537
|
+
)
|
|
538
|
+
expect(result.validationErrors[0].filePath).toBe('error-context.ts')
|
|
539
|
+
})
|
|
540
|
+
})
|
|
541
|
+
|
|
542
|
+
describe('Edge Cases', () => {
|
|
543
|
+
it('should handle git-committer agent schema correctly', async () => {
|
|
544
|
+
const fileContext: ProjectFileContext = {
|
|
545
|
+
...mockFileContext,
|
|
546
|
+
agentTemplates: {
|
|
547
|
+
'git-committer.ts': {
|
|
548
|
+
id: 'anvilai-git-committer',
|
|
549
|
+
version: '0.0.1',
|
|
550
|
+
displayName: 'Git Committer',
|
|
551
|
+
spawnerPrompt:
|
|
552
|
+
'A git committer agent specialized to commit current changes with an appropriate commit message.',
|
|
553
|
+
model: 'google/gemini-2.5-pro',
|
|
554
|
+
systemPrompt: 'Test system prompt',
|
|
555
|
+
instructionsPrompt: 'Test user prompt',
|
|
556
|
+
stepPrompt: 'Test step prompt',
|
|
557
|
+
inputSchema: {
|
|
558
|
+
prompt: {
|
|
559
|
+
type: 'string',
|
|
560
|
+
description: 'What changes to commit',
|
|
561
|
+
},
|
|
562
|
+
params: {
|
|
563
|
+
type: 'object',
|
|
564
|
+
properties: {
|
|
565
|
+
message: {
|
|
566
|
+
type: 'string',
|
|
567
|
+
},
|
|
568
|
+
},
|
|
569
|
+
required: ['message'],
|
|
570
|
+
},
|
|
571
|
+
},
|
|
572
|
+
outputMode: 'last_message',
|
|
573
|
+
includeMessageHistory: true,
|
|
574
|
+
inheritParentSystemPrompt: false,
|
|
575
|
+
toolNames: ['end_turn'],
|
|
576
|
+
spawnableAgents: [],
|
|
577
|
+
},
|
|
578
|
+
},
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
const result = validateAgents({
|
|
582
|
+
agentTemplates: fileContext.agentTemplates || {},
|
|
583
|
+
logger,
|
|
584
|
+
})
|
|
585
|
+
|
|
586
|
+
expect(result.validationErrors).toHaveLength(0)
|
|
587
|
+
expect(result.templates).toHaveProperty('anvilai-git-committer')
|
|
588
|
+
|
|
589
|
+
const template = result.templates['anvilai-git-committer']
|
|
590
|
+
const paramsSchema = template.inputSchema.params!
|
|
591
|
+
|
|
592
|
+
expect(paramsSchema.safeParse('').success).toBe(false) // Too short
|
|
593
|
+
expect(template.inputSchema.params).toBeDefined()
|
|
594
|
+
// Test that the params schema properly validates the message property
|
|
595
|
+
// This should succeed with a message property
|
|
596
|
+
const validResult = paramsSchema.safeParse({
|
|
597
|
+
message: 'test commit message',
|
|
598
|
+
})
|
|
599
|
+
expect(validResult.success).toBe(true)
|
|
600
|
+
|
|
601
|
+
// This should fail without the required message property
|
|
602
|
+
const invalidResult = paramsSchema.safeParse({})
|
|
603
|
+
expect(invalidResult.success).toBe(false)
|
|
604
|
+
})
|
|
605
|
+
|
|
606
|
+
it('should handle empty inputSchema object', async () => {
|
|
607
|
+
const fileContext: ProjectFileContext = {
|
|
608
|
+
...mockFileContext,
|
|
609
|
+
agentTemplates: {
|
|
610
|
+
'empty-schema.ts': {
|
|
611
|
+
id: 'empty-schema-agent',
|
|
612
|
+
version: '1.0.0',
|
|
613
|
+
displayName: 'Empty Schema Agent',
|
|
614
|
+
model: 'anthropic/claude-4-sonnet-20250522',
|
|
615
|
+
systemPrompt: 'Test system prompt',
|
|
616
|
+
instructionsPrompt: 'Test user prompt',
|
|
617
|
+
stepPrompt: 'Test step prompt',
|
|
618
|
+
spawnerPrompt: 'Test agent with empty schema',
|
|
619
|
+
inputSchema: {},
|
|
620
|
+
outputMode: 'last_message',
|
|
621
|
+
includeMessageHistory: true,
|
|
622
|
+
inheritParentSystemPrompt: false,
|
|
623
|
+
toolNames: ['end_turn'],
|
|
624
|
+
spawnableAgents: [],
|
|
625
|
+
},
|
|
626
|
+
},
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
const result = validateAgents({
|
|
630
|
+
agentTemplates: fileContext.agentTemplates || {},
|
|
631
|
+
logger,
|
|
632
|
+
})
|
|
633
|
+
|
|
634
|
+
expect(result.validationErrors).toHaveLength(0)
|
|
635
|
+
expect(result.templates).toHaveProperty('empty-schema-agent')
|
|
636
|
+
|
|
637
|
+
// Empty schemas should have no prompt schema
|
|
638
|
+
expect(
|
|
639
|
+
result.templates['empty-schema-agent'].inputSchema.prompt,
|
|
640
|
+
).toBeUndefined()
|
|
641
|
+
})
|
|
642
|
+
})
|
|
643
|
+
})
|
|
644
|
+
|
|
645
|
+
describe('HandleSteps Parsing', () => {
|
|
646
|
+
test('should validate agent config with handleSteps function', () => {
|
|
647
|
+
const agentConfig = {
|
|
648
|
+
id: 'test-agent',
|
|
649
|
+
version: '1.0.0',
|
|
650
|
+
displayName: 'Test Agent',
|
|
651
|
+
spawnerPrompt: 'Testing handleSteps',
|
|
652
|
+
model: 'claude-3-5-sonnet-20241022',
|
|
653
|
+
outputMode: 'structured_output' as const,
|
|
654
|
+
toolNames: ['set_output'],
|
|
655
|
+
systemPrompt: 'You are a test agent',
|
|
656
|
+
instructionsPrompt: 'Process: {prompt}',
|
|
657
|
+
stepPrompt: 'Continue processing',
|
|
658
|
+
handleSteps: function* ({
|
|
659
|
+
agentState,
|
|
660
|
+
prompt,
|
|
661
|
+
params,
|
|
662
|
+
}: {
|
|
663
|
+
agentState: AgentState
|
|
664
|
+
prompt?: string
|
|
665
|
+
params?: any
|
|
666
|
+
}) {
|
|
667
|
+
yield {
|
|
668
|
+
toolName: 'set_output',
|
|
669
|
+
input: { message: 'Test completed' },
|
|
670
|
+
}
|
|
671
|
+
},
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
const result = DynamicAgentDefinitionSchema.safeParse(agentConfig)
|
|
675
|
+
expect(result.success).toBe(true)
|
|
676
|
+
|
|
677
|
+
if (result.success) {
|
|
678
|
+
expect(typeof result.data.handleSteps).toBe('function')
|
|
679
|
+
}
|
|
680
|
+
})
|
|
681
|
+
|
|
682
|
+
test('should convert handleSteps function to string', async () => {
|
|
683
|
+
const handleStepsFunction = function* ({
|
|
684
|
+
agentState,
|
|
685
|
+
prompt,
|
|
686
|
+
params,
|
|
687
|
+
}: {
|
|
688
|
+
agentState: AgentState
|
|
689
|
+
prompt?: string
|
|
690
|
+
params?: any
|
|
691
|
+
}) {
|
|
692
|
+
yield {
|
|
693
|
+
toolName: 'set_output',
|
|
694
|
+
input: { message: 'Hello from generator' },
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
const agentTemplates = {
|
|
699
|
+
'test-agent.ts': {
|
|
700
|
+
...mockAgentTemplate,
|
|
701
|
+
handleSteps: handleStepsFunction.toString(),
|
|
702
|
+
},
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
const fileContext: ProjectFileContext = {
|
|
706
|
+
...mockFileContext,
|
|
707
|
+
agentTemplates,
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
const result = validateAgents({
|
|
711
|
+
agentTemplates: fileContext.agentTemplates || {},
|
|
712
|
+
logger,
|
|
713
|
+
})
|
|
714
|
+
|
|
715
|
+
expect(result.validationErrors).toHaveLength(0)
|
|
716
|
+
expect(result.templates['test-agent']).toBeDefined()
|
|
717
|
+
expect(typeof result.templates['test-agent'].handleSteps).toBe('string')
|
|
718
|
+
})
|
|
719
|
+
|
|
720
|
+
// Note: The validation that required set_output tool for structured_output mode was
|
|
721
|
+
// intentionally disabled to allow handleSteps to use set_output while the LLM does not
|
|
722
|
+
// have access to the set_output tool.
|
|
723
|
+
test('should allow structured_output mode without set_output tool in toolNames', () => {
|
|
724
|
+
const {
|
|
725
|
+
DynamicAgentTemplateSchema,
|
|
726
|
+
} = require('../types/dynamic-agent-template')
|
|
727
|
+
|
|
728
|
+
const agentConfig = {
|
|
729
|
+
id: 'test-agent',
|
|
730
|
+
version: '1.0.0',
|
|
731
|
+
displayName: 'Test Agent',
|
|
732
|
+
spawnerPrompt: 'Testing',
|
|
733
|
+
model: 'claude-3-5-sonnet-20241022',
|
|
734
|
+
outputMode: 'structured_output' as const,
|
|
735
|
+
systemPrompt: 'Test',
|
|
736
|
+
instructionsPrompt: 'Test',
|
|
737
|
+
stepPrompt: 'Test',
|
|
738
|
+
toolNames: ['end_turn'], // Missing set_output - now allowed
|
|
739
|
+
spawnableAgents: [],
|
|
740
|
+
handleSteps:
|
|
741
|
+
'function* () { yield { toolName: "set_output", input: {} } }',
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
const result = DynamicAgentTemplateSchema.safeParse(agentConfig)
|
|
745
|
+
expect(result.success).toBe(true)
|
|
746
|
+
})
|
|
747
|
+
|
|
748
|
+
// Note: The validation that rejected set_output without structured_output mode was
|
|
749
|
+
// intentionally disabled to allow parent agents to have set_output tool with 'last_message'
|
|
750
|
+
// outputMode while their subagents use 'structured_output' (preserves prompt caching).
|
|
751
|
+
test('should allow set_output tool without structured_output mode', () => {
|
|
752
|
+
const {
|
|
753
|
+
DynamicAgentTemplateSchema,
|
|
754
|
+
} = require('../types/dynamic-agent-template')
|
|
755
|
+
|
|
756
|
+
const agentConfig = {
|
|
757
|
+
id: 'test-agent',
|
|
758
|
+
version: '1.0.0',
|
|
759
|
+
displayName: 'Test Agent',
|
|
760
|
+
spawnerPrompt: 'Testing',
|
|
761
|
+
model: 'claude-3-5-sonnet-20241022',
|
|
762
|
+
outputMode: 'last_message' as const, // Not structured_output
|
|
763
|
+
toolNames: ['end_turn', 'set_output'], // Has set_output - now allowed
|
|
764
|
+
spawnableAgents: [],
|
|
765
|
+
systemPrompt: 'Test',
|
|
766
|
+
instructionsPrompt: 'Test',
|
|
767
|
+
stepPrompt: 'Test',
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
const result = DynamicAgentTemplateSchema.safeParse(agentConfig)
|
|
771
|
+
expect(result.success).toBe(true)
|
|
772
|
+
})
|
|
773
|
+
|
|
774
|
+
test('should validate that handleSteps is a generator function', async () => {
|
|
775
|
+
const agentTemplates = {
|
|
776
|
+
'test-agent.ts': {
|
|
777
|
+
...mockAgentTemplate,
|
|
778
|
+
handleSteps: 'function () { return "not a generator" }', // Missing *
|
|
779
|
+
},
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
const fileContext: ProjectFileContext = {
|
|
783
|
+
...mockFileContext,
|
|
784
|
+
agentTemplates,
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
const result = validateAgents({
|
|
788
|
+
agentTemplates: fileContext.agentTemplates || {},
|
|
789
|
+
logger,
|
|
790
|
+
})
|
|
791
|
+
|
|
792
|
+
expect(result.validationErrors.length).toBeGreaterThan(0)
|
|
793
|
+
expect(result.validationErrors[0].message).toContain('generator function')
|
|
794
|
+
expect(result.validationErrors[0].message).toContain('function*')
|
|
795
|
+
})
|
|
796
|
+
test('should verify loaded template handleSteps matches original function toString', async () => {
|
|
797
|
+
// Create a generator function
|
|
798
|
+
const originalFunction = function* ({
|
|
799
|
+
agentState,
|
|
800
|
+
prompt,
|
|
801
|
+
params,
|
|
802
|
+
}: {
|
|
803
|
+
agentState: AgentState
|
|
804
|
+
prompt?: string
|
|
805
|
+
params?: any
|
|
806
|
+
}) {
|
|
807
|
+
yield {
|
|
808
|
+
toolName: 'set_output',
|
|
809
|
+
input: { message: 'Test output', data: params },
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
// Get the string representation
|
|
814
|
+
const expectedStringified = originalFunction.toString()
|
|
815
|
+
|
|
816
|
+
// Create agent templates with the function
|
|
817
|
+
const agentTemplates = {
|
|
818
|
+
'test-agent.ts': {
|
|
819
|
+
...mockAgentTemplate,
|
|
820
|
+
handleSteps: expectedStringified,
|
|
821
|
+
},
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
const fileContext: ProjectFileContext = {
|
|
825
|
+
...mockFileContext,
|
|
826
|
+
agentTemplates,
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
// Load agents through the service
|
|
830
|
+
const result = validateAgents({
|
|
831
|
+
agentTemplates: fileContext.agentTemplates || {},
|
|
832
|
+
logger,
|
|
833
|
+
})
|
|
834
|
+
|
|
835
|
+
// Verify no validation errors
|
|
836
|
+
expect(result.validationErrors).toHaveLength(0)
|
|
837
|
+
expect(result.templates['test-agent']).toBeDefined()
|
|
838
|
+
|
|
839
|
+
// Verify the loaded template's handleSteps field matches the original toString
|
|
840
|
+
expect(result.templates['test-agent'].handleSteps).toBe(
|
|
841
|
+
expectedStringified,
|
|
842
|
+
)
|
|
843
|
+
expect(typeof result.templates['test-agent'].handleSteps).toBe('string')
|
|
844
|
+
})
|
|
845
|
+
})
|
|
846
|
+
})
|