@alumbwe/anvil 1.0.41 → 1.0.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/bin/anvil.js +18 -0
  2. package/package.json +13 -6
  3. package/src/agents/bundled-agents.generated.ts +1 -1
  4. package/src/entry.ts +5 -0
  5. package/src/index.tsx +27 -4
  6. package/src/login/plain-login.ts +60 -0
  7. package/src/login/supabase-auth.ts +346 -0
  8. package/src/pre-init/client-env.ts +17 -0
  9. package/src/utils/anvil-client.ts +4 -0
  10. package/src/utils/auth.ts +16 -4
  11. package/src/utils/client-env-defaults.ts +28 -0
  12. package/src/utils/config-dir.ts +1 -1
  13. package/vendor/@anvil/common/src/constants/deepseek-direct.ts +30 -1
  14. package/vendor/@anvil/common/src/util/project-ignore.ts +4 -3
  15. package/vendor/@anvil/sdk/dist/index.cjs +46 -10
  16. package/vendor/@anvil/sdk/dist/index.mjs +46 -10
  17. package/src/commands/__tests__/anvil-command-aliases.test.ts +0 -56
  18. package/src/commands/__tests__/bash-command.test.ts +0 -445
  19. package/src/commands/__tests__/command-args.test.ts +0 -349
  20. package/src/commands/__tests__/copy-conversation-clipboard.test.ts +0 -108
  21. package/src/commands/__tests__/copy-conversation.test.ts +0 -226
  22. package/src/commands/__tests__/diagnostics-command.test.ts +0 -35
  23. package/src/commands/__tests__/image.test.ts +0 -99
  24. package/src/commands/__tests__/init.test.ts +0 -456
  25. package/src/commands/__tests__/new-command-rotates-chat.test.ts +0 -91
  26. package/src/commands/__tests__/process-diagnostics.test.ts +0 -54
  27. package/src/commands/__tests__/prompt-builders.test.ts +0 -28
  28. package/src/commands/__tests__/router-input.test.ts +0 -298
  29. package/src/components/__tests__/ad-banner.test.tsx +0 -83
  30. package/src/components/__tests__/anvil-landing-heading-row.test.tsx +0 -91
  31. package/src/components/__tests__/anvil-model-selector.test.tsx +0 -519
  32. package/src/components/__tests__/anvil-offer-invariants.test.ts +0 -54
  33. package/src/components/__tests__/anvil-takeover-prompt.test.tsx +0 -212
  34. package/src/components/__tests__/chat-input-bar.test.tsx +0 -130
  35. package/src/components/__tests__/grid-layout.integration.test.tsx +0 -304
  36. package/src/components/__tests__/grid-layout.test.tsx +0 -1051
  37. package/src/components/__tests__/message-block.completion.test.tsx +0 -104
  38. package/src/components/__tests__/message-block.streaming.test.tsx +0 -78
  39. package/src/components/__tests__/message-with-agents.test.tsx +0 -579
  40. package/src/components/__tests__/multiline-input.test.tsx +0 -1132
  41. package/src/components/__tests__/queue-panel.test.tsx +0 -398
  42. package/src/components/__tests__/selectable-list.test.ts +0 -232
  43. package/src/components/__tests__/status-bar.test.tsx +0 -44
  44. package/src/components/__tests__/status-indicator.test.tsx +0 -204
  45. package/src/components/__tests__/terminal-thinking-orb.test.tsx +0 -111
  46. package/src/components/__tests__/user-error-banner.test.tsx +0 -102
  47. package/src/components/ask-user/__tests__/multiple-choice-form.test.ts +0 -432
  48. package/src/components/ask-user/__tests__/validation.test.ts +0 -213
  49. package/src/components/tools/__tests__/apply-patch.test.tsx +0 -84
  50. package/src/components/tools/__tests__/code-search.test.tsx +0 -45
  51. package/src/components/tools/__tests__/gravity-index.test.ts +0 -76
  52. package/src/components/tools/__tests__/render-ui.test.tsx +0 -92
  53. package/src/components/tools/__tests__/run-terminal-command.test.ts +0 -233
  54. package/src/contexts/__tests__/chat-runtime-context.test.tsx +0 -149
  55. package/src/data/slash-commands.test.ts +0 -24
  56. package/src/hooks/__tests__/holds-live-anvil-slot.test.ts +0 -49
  57. package/src/hooks/__tests__/session-fetch-signal.test.ts +0 -63
  58. package/src/hooks/__tests__/use-activity-query.test.ts +0 -1000
  59. package/src/hooks/__tests__/use-ask-user-bridge.test.ts +0 -176
  60. package/src/hooks/__tests__/use-auth-query.test.ts +0 -21
  61. package/src/hooks/__tests__/use-chat-input-remount.test.tsx +0 -66
  62. package/src/hooks/__tests__/use-clipboard.test.tsx +0 -73
  63. package/src/hooks/__tests__/use-connection-status.test.ts +0 -112
  64. package/src/hooks/__tests__/use-directory-browser.test.ts +0 -203
  65. package/src/hooks/__tests__/use-gravity-ad.test.ts +0 -73
  66. package/src/hooks/__tests__/use-grid-layout.test.ts +0 -349
  67. package/src/hooks/__tests__/use-input-history.test.ts +0 -699
  68. package/src/hooks/__tests__/use-message-queue-editing.test.tsx +0 -209
  69. package/src/hooks/__tests__/use-message-queue.test.tsx +0 -71
  70. package/src/hooks/__tests__/use-path-tab-completion.test.ts +0 -315
  71. package/src/hooks/__tests__/use-queue-controls.test.ts +0 -68
  72. package/src/hooks/__tests__/use-queue-ui.test.tsx +0 -83
  73. package/src/hooks/__tests__/use-searchable-list.test.ts +0 -359
  74. package/src/hooks/__tests__/use-send-message-timer.test.ts +0 -146
  75. package/src/hooks/__tests__/use-suggestion-engine-mention.test.ts +0 -361
  76. package/src/hooks/__tests__/use-suggestion-engine.test.ts +0 -485
  77. package/src/hooks/__tests__/use-terminal-focus.test.ts +0 -66
  78. package/src/hooks/__tests__/use-terminal-layout.test.ts +0 -675
  79. package/src/hooks/__tests__/use-timeout.test.ts +0 -330
  80. package/src/hooks/__tests__/use-usage-query.test.ts +0 -502
  81. package/src/hooks/__tests__/use-user-details-query.test.ts +0 -195
  82. package/src/hooks/helpers/__tests__/send-message.test.ts +0 -1918
  83. package/src/init/__tests__/init-direnv.test.ts +0 -526
  84. package/src/state/__tests__/chat-store-focus.test.ts +0 -22
  85. package/src/state/__tests__/feedback-store.test.ts +0 -257
  86. package/src/utils/__tests__/active-run.test.ts +0 -140
  87. package/src/utils/__tests__/activity-tracker.test.ts +0 -440
  88. package/src/utils/__tests__/agent-display.test.ts +0 -139
  89. package/src/utils/__tests__/analytics-client.test.ts +0 -262
  90. package/src/utils/__tests__/anonymous-id.test.ts +0 -74
  91. package/src/utils/__tests__/anvil-api.test.ts +0 -578
  92. package/src/utils/__tests__/anvil-instance-owner.test.ts +0 -69
  93. package/src/utils/__tests__/anvil-model-navigation.test.ts +0 -102
  94. package/src/utils/__tests__/anvil-premium-reset.test.ts +0 -79
  95. package/src/utils/__tests__/anvil-referral-cache.test.ts +0 -116
  96. package/src/utils/__tests__/anvil-session-api.test.ts +0 -215
  97. package/src/utils/__tests__/anvil-session-display.test.ts +0 -23
  98. package/src/utils/__tests__/anvil-streak-line.test.ts +0 -217
  99. package/src/utils/__tests__/arrays.test.ts +0 -264
  100. package/src/utils/__tests__/bash-context-processor.test.ts +0 -38
  101. package/src/utils/__tests__/block-processor.test.ts +0 -810
  102. package/src/utils/__tests__/chat-history.test.ts +0 -203
  103. package/src/utils/__tests__/chat-input-key-intercept.test.ts +0 -40
  104. package/src/utils/__tests__/chat-meta.test.ts +0 -130
  105. package/src/utils/__tests__/clipboard-linux.test.ts +0 -359
  106. package/src/utils/__tests__/clipboard.test.ts +0 -910
  107. package/src/utils/__tests__/code-search-summary.test.ts +0 -84
  108. package/src/utils/__tests__/collapse-helpers.test.ts +0 -1109
  109. package/src/utils/__tests__/error-handling.test.ts +0 -658
  110. package/src/utils/__tests__/exit-cleanly.test.ts +0 -110
  111. package/src/utils/__tests__/feedback-helpers.test.ts +0 -444
  112. package/src/utils/__tests__/feedback-submission.test.ts +0 -26
  113. package/src/utils/__tests__/fetch-usage.test.ts +0 -355
  114. package/src/utils/__tests__/fingerprint.test.ts +0 -144
  115. package/src/utils/__tests__/fixtures/terminal-command-broker-child.ts +0 -7
  116. package/src/utils/__tests__/fixtures/terminal-command-broker-entry.ts +0 -3
  117. package/src/utils/__tests__/fixtures/terminal-command-broker-owner.ts +0 -33
  118. package/src/utils/__tests__/format-elapsed-time.test.ts +0 -103
  119. package/src/utils/__tests__/format-timeout.test.ts +0 -87
  120. package/src/utils/__tests__/image-dimensions.test.ts +0 -249
  121. package/src/utils/__tests__/image-processor.test.ts +0 -209
  122. package/src/utils/__tests__/implementor-helpers.test.ts +0 -1458
  123. package/src/utils/__tests__/keyboard-actions.test.ts +0 -660
  124. package/src/utils/__tests__/layout-helpers.test.ts +0 -36
  125. package/src/utils/__tests__/lazy-response-ads.test.ts +0 -167
  126. package/src/utils/__tests__/log-shipper.test.ts +0 -53
  127. package/src/utils/__tests__/markdown-renderer.test.tsx +0 -421
  128. package/src/utils/__tests__/message-block-helpers.test.ts +0 -1263
  129. package/src/utils/__tests__/message-updater.test.ts +0 -645
  130. package/src/utils/__tests__/osc-timeout-scenarios.test.ts +0 -172
  131. package/src/utils/__tests__/pending-attachments.test.ts +0 -277
  132. package/src/utils/__tests__/polling-backoff.test.ts +0 -51
  133. package/src/utils/__tests__/queue-panel-actions.test.ts +0 -148
  134. package/src/utils/__tests__/run-state-storage.test.ts +0 -919
  135. package/src/utils/__tests__/safe-json.test.ts +0 -77
  136. package/src/utils/__tests__/sdk-event-handlers.test.ts +0 -685
  137. package/src/utils/__tests__/send-message-helpers.test.ts +0 -1898
  138. package/src/utils/__tests__/send-message-timer.test.ts +0 -64
  139. package/src/utils/__tests__/settings.test.ts +0 -99
  140. package/src/utils/__tests__/strings.test.ts +0 -192
  141. package/src/utils/__tests__/terminal-color-detection.test.ts +0 -425
  142. package/src/utils/__tests__/terminal-command-broker.test.ts +0 -528
  143. package/src/utils/__tests__/terminal-enter-detection.test.ts +0 -77
  144. package/src/utils/__tests__/terminal-io.test.ts +0 -137
  145. package/src/utils/__tests__/terminal-protocol-controller.test.ts +0 -119
  146. package/src/utils/__tests__/text-layout.test.ts +0 -82
  147. package/src/utils/__tests__/theme-platform-detection.test.ts +0 -125
  148. package/src/utils/__tests__/think-tag-parser.test.ts +0 -159
  149. package/src/utils/__tests__/trace-writer.test.ts +0 -223
  150. package/src/utils/__tests__/trim-chat-logs.test.ts +0 -78
  151. package/src/utils/__tests__/usage-banner-state.test.ts +0 -298
  152. package/src/utils/__tests__/validation-error-formatting.test.ts +0 -126
  153. package/src/utils/__tests__/windows-terminal-health.test.ts +0 -101
  154. package/src/utils/__tests__/write-file-atomic.test.ts +0 -127
  155. package/vendor/@anvil/common/src/__tests__/agent-validation.test.ts +0 -846
  156. package/vendor/@anvil/common/src/__tests__/anvil-model-availability.test.ts +0 -101
  157. package/vendor/@anvil/common/src/__tests__/anvil-models.test.ts +0 -1408
  158. package/vendor/@anvil/common/src/__tests__/anvil-public-data-use-copy.test.ts +0 -258
  159. package/vendor/@anvil/common/src/__tests__/anvil-referral-tiers.test.ts +0 -48
  160. package/vendor/@anvil/common/src/__tests__/anvil-spend-ceilings.test.ts +0 -282
  161. package/vendor/@anvil/common/src/__tests__/anvil-trust.test.ts +0 -526
  162. package/vendor/@anvil/common/src/__tests__/deepseek-direct.test.ts +0 -68
  163. package/vendor/@anvil/common/src/__tests__/disposable-email.test.ts +0 -132
  164. package/vendor/@anvil/common/src/__tests__/dynamic-agent-template-schema.test.ts +0 -422
  165. package/vendor/@anvil/common/src/__tests__/env-ci.test.ts +0 -167
  166. package/vendor/@anvil/common/src/__tests__/env-process.test.ts +0 -145
  167. package/vendor/@anvil/common/src/__tests__/foreign-client-shipped-agents.test.ts +0 -234
  168. package/vendor/@anvil/common/src/__tests__/foreign-client-signals.test.ts +0 -379
  169. package/vendor/@anvil/common/src/__tests__/free-agents.test.ts +0 -807
  170. package/vendor/@anvil/common/src/__tests__/gravity-capi.test.ts +0 -154
  171. package/vendor/@anvil/common/src/__tests__/handlesteps-parsing.test.ts +0 -246
  172. package/vendor/@anvil/common/src/__tests__/kimi-k3-god-only.test.ts +0 -77
  173. package/vendor/@anvil/common/src/__tests__/model-config.test.ts +0 -89
  174. package/vendor/@anvil/common/src/__tests__/project-file-tree.test.ts +0 -298
  175. package/vendor/@anvil/common/src/__tests__/provisioned-model-tiers.test.ts +0 -116
  176. package/vendor/@anvil/common/src/__tests__/reasoning-effort.test.ts +0 -167
  177. package/vendor/@anvil/common/src/__tests__/reddit-capi.test.ts +0 -132
  178. package/vendor/@anvil/common/src/__tests__/response-ad-positions.test.ts +0 -72
  179. package/vendor/@anvil/common/src/__tests__/user-state.test.ts +0 -30
  180. package/vendor/@anvil/common/src/constants/__tests__/anvil-onboarding-gate.test.ts +0 -63
  181. package/vendor/@anvil/common/src/constants/__tests__/anvil-onboarding.test.ts +0 -246
  182. package/vendor/@anvil/common/src/constants/__tests__/cf-worker-signals.test.ts +0 -106
  183. package/vendor/@anvil/common/src/testing/TESTING_PATTERNS.md +0 -351
  184. package/vendor/@anvil/common/src/testing/anvil-offer-invariants.ts +0 -169
  185. package/vendor/@anvil/common/src/testing/errors.ts +0 -33
  186. package/vendor/@anvil/common/src/testing/fixtures/agent-runtime.ts +0 -334
  187. package/vendor/@anvil/common/src/testing/impl/agent-runtime.ts +0 -6
  188. package/vendor/@anvil/common/src/testing/index.ts +0 -84
  189. package/vendor/@anvil/common/src/testing/mock-modules.ts +0 -53
  190. package/vendor/@anvil/common/src/testing/mock-types.ts +0 -123
  191. package/vendor/@anvil/common/src/testing/mocks/analytics.ts +0 -261
  192. package/vendor/@anvil/common/src/testing/mocks/child-process.ts +0 -93
  193. package/vendor/@anvil/common/src/testing/mocks/crypto.ts +0 -218
  194. package/vendor/@anvil/common/src/testing/mocks/database.ts +0 -337
  195. package/vendor/@anvil/common/src/testing/mocks/fetch.ts +0 -219
  196. package/vendor/@anvil/common/src/testing/mocks/filesystem.ts +0 -166
  197. package/vendor/@anvil/common/src/testing/mocks/index.ts +0 -101
  198. package/vendor/@anvil/common/src/testing/mocks/logger.ts +0 -135
  199. package/vendor/@anvil/common/src/testing/mocks/stream.ts +0 -313
  200. package/vendor/@anvil/common/src/testing/mocks/timers.ts +0 -132
  201. package/vendor/@anvil/common/src/testing/mocks/tree-sitter.ts +0 -127
  202. package/vendor/@anvil/common/src/testing/setup.ts +0 -282
  203. package/vendor/@anvil/common/src/tools/__tests__/compile-tool-definitions.test.ts +0 -34
  204. package/vendor/@anvil/common/src/tools/params/__tests__/coerce-to-array.test.ts +0 -213
  205. package/vendor/@anvil/common/src/tools/params/__tests__/read-docs.test.ts +0 -47
  206. package/vendor/@anvil/common/src/tools/params/__tests__/render-ui.test.ts +0 -65
  207. package/vendor/@anvil/common/src/tools/params/tool/__tests__/run-terminal-command-timeout.test.ts +0 -49
  208. package/vendor/@anvil/common/src/types/__tests__/dynamic-agent-template.test.ts +0 -20
  209. package/vendor/@anvil/common/src/util/__tests__/ad-user-agent.test.ts +0 -26
  210. package/vendor/@anvil/common/src/util/__tests__/analytics-dispatcher.test.ts +0 -122
  211. package/vendor/@anvil/common/src/util/__tests__/analytics-log.test.ts +0 -102
  212. package/vendor/@anvil/common/src/util/__tests__/analytics-sampling.test.ts +0 -143
  213. package/vendor/@anvil/common/src/util/__tests__/anvil-streak.test.ts +0 -202
  214. package/vendor/@anvil/common/src/util/__tests__/anvil-usage-summary.test.ts +0 -193
  215. package/vendor/@anvil/common/src/util/__tests__/axiom-only-log.test.ts +0 -140
  216. package/vendor/@anvil/common/src/util/__tests__/client-user-agent.test.ts +0 -148
  217. package/vendor/@anvil/common/src/util/__tests__/engagement-tracker.test.ts +0 -115
  218. package/vendor/@anvil/common/src/util/__tests__/env-file-path.test.ts +0 -57
  219. package/vendor/@anvil/common/src/util/__tests__/error-abort.test.ts +0 -774
  220. package/vendor/@anvil/common/src/util/__tests__/error-api-details.test.ts +0 -206
  221. package/vendor/@anvil/common/src/util/__tests__/file-read-limits.test.ts +0 -173
  222. package/vendor/@anvil/common/src/util/__tests__/format-code-search.test.ts +0 -60
  223. package/vendor/@anvil/common/src/util/__tests__/log-mirror.test.ts +0 -31
  224. package/vendor/@anvil/common/src/util/__tests__/messages.test.ts +0 -1252
  225. package/vendor/@anvil/common/src/util/__tests__/partial-json-delta.test.ts +0 -505
  226. package/vendor/@anvil/common/src/util/__tests__/path.test.ts +0 -22
  227. package/vendor/@anvil/common/src/util/__tests__/project-ignore.test.ts +0 -90
  228. package/vendor/@anvil/common/src/util/__tests__/promise.test.ts +0 -325
  229. package/vendor/@anvil/common/src/util/__tests__/rate-limit.test.ts +0 -28
  230. package/vendor/@anvil/common/src/util/__tests__/reddit-anvil-retention.test.ts +0 -130
  231. package/vendor/@anvil/common/src/util/__tests__/saxy.test.ts +0 -1008
  232. package/vendor/@anvil/common/src/util/__tests__/split-data.test.ts +0 -289
  233. package/vendor/@anvil/common/src/util/__tests__/string.test.ts +0 -239
  234. package/vendor/@anvil/common/src/util/__tests__/thread-title.test.ts +0 -70
  235. package/vendor/@anvil/common/src/util/__tests__/tool-result-media-order.test.ts +0 -108
  236. package/vendor/@anvil/common/src/util/__tests__/ttft-histogram.test.ts +0 -180
  237. package/vendor/@anvil/common/src/util/__tests__/with-timeout.test.ts +0 -24
  238. package/vendor/@anvil/common/src/util/__tests__/zoned-time.test.ts +0 -88
  239. package/vendor/@anvil/common/src/util/skills.test.ts +0 -44
  240. package/vendor/@anvil/sdk/dist/index.cjs.map +0 -440
  241. package/vendor/@anvil/sdk/dist/index.mjs.map +0 -440
@@ -1,154 +0,0 @@
1
- import { describe, expect, test } from 'bun:test'
2
-
3
- import {
4
- buildGravityFirstMessagePayload,
5
- gravityFirstMessageEventId,
6
- isAnvilGravitySurface,
7
- sanitizeGravityCapiData,
8
- sendGravityFirstMessageConversion,
9
- } from '../gravity-capi'
10
-
11
- describe('Gravity first-message CAPI', () => {
12
- test('sanitizes browser attribution in one shared boundary', () => {
13
- expect(
14
- sanitizeGravityCapiData(
15
- {
16
- user_data: {
17
- click_id: 'click-1',
18
- visitor_id: 123,
19
- session_id: 'session-1',
20
- },
21
- event_source_url: 'https://stale.example',
22
- client_context: { timezone: 'America/Los_Angeles' },
23
- },
24
- 'https://anvil.com/chat',
25
- ),
26
- ).toEqual({
27
- user_data: {
28
- click_id: 'click-1',
29
- visitor_id: undefined,
30
- session_id: 'session-1',
31
- client_user_agent: undefined,
32
- },
33
- event_source_url: 'https://anvil.com/chat',
34
- client_context: { timezone: 'America/Los_Angeles' },
35
- })
36
- expect(isAnvilGravitySurface('desktop')).toBe(true)
37
- expect(isAnvilGravitySurface('preexisting')).toBe(false)
38
- })
39
-
40
- test('drops oversized client context before forwarding it to Gravity', () => {
41
- expect(
42
- sanitizeGravityCapiData({
43
- user_data: { click_id: 'click-123' },
44
- client_context: { padding: 'x'.repeat(32_768) },
45
- }),
46
- ).toEqual({
47
- user_data: {
48
- click_id: 'click-123',
49
- visitor_id: undefined,
50
- session_id: undefined,
51
- client_user_agent: undefined,
52
- },
53
- event_source_url: undefined,
54
- client_context: undefined,
55
- })
56
- })
57
-
58
- test('builds a stable, attributed payload with authoritative identity', () => {
59
- expect(
60
- buildGravityFirstMessagePayload({
61
- userId: 'user-123',
62
- email: 'person@example.com',
63
- surface: 'cloud',
64
- eventTime: 123,
65
- gravity: {
66
- event_source_url: 'https://anvil.com/cloud/project/example',
67
- user_data: {
68
- click_id: 'click-1',
69
- visitor_id: 'visitor-1',
70
- session_id: 'session-1',
71
- client_user_agent: 'pixel-agent',
72
- },
73
- client_context: { timezone: 'America/Los_Angeles' },
74
- },
75
- }),
76
- ).toEqual({
77
- data: [
78
- {
79
- event_name: 'FirstMessage',
80
- event_time: 123,
81
- event_id: 'anvil-first-message-user-123',
82
- action_source: 'website',
83
- event_source_url: 'https://anvil.com/cloud/project/example',
84
- user_data: {
85
- click_id: 'click-1',
86
- visitor_id: 'visitor-1',
87
- session_id: 'session-1',
88
- client_user_agent: 'pixel-agent',
89
- em: ['person@example.com'],
90
- external_id: ['user-123'],
91
- },
92
- client_context: { timezone: 'America/Los_Angeles' },
93
- custom_data: {
94
- content_name: 'Anvil first message',
95
- content_category: 'cloud',
96
- },
97
- },
98
- ],
99
- })
100
- })
101
-
102
- test('uses the same event id across surfaces for Gravity deduplication', () => {
103
- expect(gravityFirstMessageEventId('user-123')).toBe(
104
- 'anvil-first-message-user-123',
105
- )
106
- })
107
-
108
- test('accepts a duplicate response as delivered', async () => {
109
- let requestBody: unknown
110
- const result = await sendGravityFirstMessageConversion({
111
- apiKey: 'secret',
112
- userId: 'user-123',
113
- surface: 'desktop',
114
- fetchImpl: (async (_input, init) => {
115
- requestBody = JSON.parse(String(init?.body))
116
- return new Response(
117
- JSON.stringify({
118
- results: [
119
- {
120
- event_id: 'anvil-first-message-user-123',
121
- status: 'duplicate',
122
- },
123
- ],
124
- }),
125
- { status: 200 },
126
- )
127
- }) as typeof fetch,
128
- })
129
-
130
- expect(result.status).toBe('duplicate')
131
- expect(requestBody).toMatchObject({
132
- data: [
133
- {
134
- event_name: 'FirstMessage',
135
- custom_data: { content_category: 'desktop' },
136
- },
137
- ],
138
- })
139
- })
140
-
141
- test('throws on an event-level error so the claim remains retryable', async () => {
142
- await expect(
143
- sendGravityFirstMessageConversion({
144
- apiKey: 'secret',
145
- userId: 'user-123',
146
- surface: 'cli',
147
- fetchImpl: (async () =>
148
- new Response(JSON.stringify({ results: [{ status: 'error' }] }), {
149
- status: 200,
150
- })) as unknown as typeof fetch,
151
- }),
152
- ).rejects.toThrow('status error')
153
- })
154
- })
@@ -1,246 +0,0 @@
1
- import { afterEach, beforeEach, describe, expect, test } from 'bun:test'
2
-
3
- import { validateAgents } from '../templates/agent-validation'
4
- import { DynamicAgentDefinitionSchema } from '../types/dynamic-agent-template'
5
-
6
- import type { DynamicAgentTemplate } from '../types/dynamic-agent-template'
7
- import type { AgentState } from '../types/session-state'
8
- import type { ProjectFileContext } from '../util/file'
9
- import type { Logger } from '@anvil/common/types/contracts/logger'
10
-
11
- describe('handleSteps Parsing Tests', () => {
12
- let mockFileContext: ProjectFileContext
13
- let mockAgentTemplate: DynamicAgentTemplate
14
- const logger: Logger = {
15
- debug: () => {},
16
- error: () => {},
17
- info: () => {},
18
- warn: () => {},
19
- }
20
-
21
- beforeEach(() => {
22
- // Setup common mock data
23
- mockFileContext = {
24
- projectRoot: '/test',
25
- cwd: '/test',
26
- fileTree: [],
27
- fileTokenScores: {},
28
- knowledgeFiles: {},
29
- agentTemplates: {},
30
- customToolDefinitions: {},
31
- gitChanges: {
32
- status: '',
33
- diff: '',
34
- diffCached: '',
35
- lastCommitMessages: '',
36
- },
37
- changesSinceLastChat: {},
38
- shellConfigFiles: {},
39
- systemInfo: {
40
- platform: 'test',
41
- shell: 'test',
42
- nodeVersion: 'test',
43
- arch: 'test',
44
- homedir: '/test',
45
- cpus: 1,
46
- chromeAvailable: false,
47
- },
48
- tokenCallers: {},
49
- }
50
-
51
- mockAgentTemplate = {
52
- id: 'test-agent',
53
- version: '1.0.0',
54
- displayName: 'Test Agent',
55
- spawnerPrompt: 'Testing',
56
- model: 'claude-3-5-sonnet-20241022',
57
- outputMode: 'structured_output' as const,
58
- mcpServers: {},
59
- toolNames: ['set_output'],
60
- spawnableAgents: [],
61
- includeMessageHistory: true,
62
- inheritParentSystemPrompt: false,
63
- systemPrompt: 'Test system prompt',
64
- instructionsPrompt: 'Test user prompt',
65
- stepPrompt: 'Test agent step prompt',
66
- }
67
- })
68
-
69
- afterEach(() => {
70
- // No cleanup needed for stateless functions
71
- })
72
-
73
- test('should validate agent config with handleSteps function', () => {
74
- const agentConfig = {
75
- id: 'test-agent',
76
- version: '1.0.0',
77
- displayName: 'Test Agent',
78
- spawnerPrompt: 'Testing handleSteps',
79
- model: 'claude-3-5-sonnet-20241022',
80
- outputMode: 'structured_output' as const,
81
- toolNames: ['set_output'],
82
- systemPrompt: 'You are a test agent',
83
- instructionsPrompt: 'Process: {prompt}',
84
- stepPrompt: 'Continue processing',
85
- handleSteps: function* ({
86
- agentState,
87
- prompt,
88
- params,
89
- }: {
90
- agentState: AgentState
91
- prompt?: string
92
- params?: any
93
- }) {
94
- yield {
95
- toolName: 'set_output',
96
- args: { message: 'Test completed' },
97
- }
98
- },
99
- }
100
-
101
- const result = DynamicAgentDefinitionSchema.safeParse(agentConfig)
102
- expect(result.success).toBe(true)
103
-
104
- if (result.success) {
105
- expect(typeof result.data.handleSteps).toBe('function')
106
- }
107
- })
108
-
109
- test('should convert handleSteps function to string', async () => {
110
- const handleStepsFunction = function* ({
111
- agentState,
112
- prompt,
113
- params,
114
- }: {
115
- agentState: AgentState
116
- prompt?: string
117
- params?: any
118
- }) {
119
- yield {
120
- toolName: 'set_output',
121
- args: { message: 'Hello from generator' },
122
- }
123
- }
124
-
125
- const agentTemplates = {
126
- 'test-agent.ts': {
127
- ...mockAgentTemplate,
128
- handleSteps: handleStepsFunction.toString(),
129
- },
130
- }
131
-
132
- const fileContext: ProjectFileContext = {
133
- ...mockFileContext,
134
- agentTemplates,
135
- }
136
-
137
- const result = validateAgents({
138
- agentTemplates: fileContext.agentTemplates || {},
139
- logger,
140
- })
141
-
142
- expect(result.validationErrors).toHaveLength(0)
143
- expect(result.templates['test-agent']).toBeDefined()
144
- expect(typeof result.templates['test-agent'].handleSteps).toBe('string')
145
- })
146
-
147
- // Note: The validation that required set_output tool for structured_output mode was
148
- // intentionally disabled to allow handleSteps to use set_output while the LLM does not
149
- // have access to the set_output tool.
150
- test('should allow structured_output mode without set_output tool in toolNames', () => {
151
- const {
152
- DynamicAgentTemplateSchema,
153
- } = require('../types/dynamic-agent-template')
154
-
155
- const agentConfig = {
156
- id: 'test-agent',
157
- version: '1.0.0',
158
- displayName: 'Test Agent',
159
- spawnerPrompt: 'Testing handleSteps',
160
- model: 'claude-3-5-sonnet-20241022',
161
- outputMode: 'structured_output' as const,
162
- toolNames: ['end_turn'], // Missing set_output - now allowed
163
- spawnableAgents: [],
164
- systemPrompt: 'Test',
165
- instructionsPrompt: 'Test',
166
- stepPrompt: 'Test',
167
-
168
- handleSteps:
169
- 'function* () { yield { toolName: "set_output", args: {} } }',
170
- }
171
-
172
- const result = DynamicAgentTemplateSchema.safeParse(agentConfig)
173
- expect(result.success).toBe(true)
174
- })
175
-
176
- test('should validate that handleSteps is a generator function', async () => {
177
- const agentTemplates = {
178
- 'test-agent.ts': {
179
- ...mockAgentTemplate,
180
- handleSteps: 'function () { return "not a generator" }', // Missing *
181
- },
182
- }
183
-
184
- const fileContext: ProjectFileContext = {
185
- ...mockFileContext,
186
- agentTemplates,
187
- }
188
-
189
- const result = validateAgents({
190
- agentTemplates: fileContext.agentTemplates || {},
191
- logger,
192
- })
193
-
194
- expect(result.validationErrors.length).toBeGreaterThan(0)
195
- expect(result.validationErrors[0].message).toContain('generator function')
196
- expect(result.validationErrors[0].message).toContain('function*')
197
- })
198
-
199
- test('should verify loaded template handleSteps matches original function toString', async () => {
200
- // Create a generator function
201
- const originalFunction = function* ({
202
- agentState,
203
- prompt,
204
- params,
205
- }: {
206
- agentState: AgentState
207
- prompt?: string
208
- params?: any
209
- }) {
210
- yield {
211
- toolName: 'set_output',
212
- args: { message: 'Test output', data: params },
213
- }
214
- }
215
-
216
- // Get the string representation
217
- const expectedStringified = originalFunction.toString()
218
-
219
- // Create agent templates with the function
220
- const agentTemplates = {
221
- 'test-agent.ts': {
222
- ...mockAgentTemplate,
223
- handleSteps: expectedStringified,
224
- },
225
- }
226
-
227
- const fileContext: ProjectFileContext = {
228
- ...mockFileContext,
229
- agentTemplates,
230
- }
231
-
232
- // Load agents through the service
233
- const result = validateAgents({
234
- agentTemplates: fileContext.agentTemplates || {},
235
- logger,
236
- })
237
-
238
- // Verify no validation errors
239
- expect(result.validationErrors).toHaveLength(0)
240
- expect(result.templates['test-agent']).toBeDefined()
241
-
242
- // Verify the loaded template's handleSteps field matches the original toString
243
- expect(result.templates['test-agent'].handleSteps).toBe(expectedStringified)
244
- expect(typeof result.templates['test-agent'].handleSteps).toBe('string')
245
- })
246
- })
@@ -1,77 +0,0 @@
1
- /**
2
- * Kimi K3 (Eco) is god-only on Anvil Web — a testing row, not a product one.
3
- * Cost backs that up: CrofAI lists it at $1.00/$4.00 per M against DeepSeek V4
4
- * Flash's $0.12/$0.21 on the same provider, ~8x input and ~19x output.
5
- */
6
- import { describe, expect, it } from 'bun:test'
7
-
8
- import {
9
- ANVIL_KIMI_K3_ECO_MODEL_ID,
10
- ANVIL_MODELS,
11
- ANVIL_WEB_ALL_MODELS,
12
- ANVIL_WEB_GOD_ONLY_MODELS,
13
- ANVIL_WEB_MODELS,
14
- ANVIL_WEB_PREMIUM_MODEL_IDS,
15
- ANVIL_WEB_STANDARD_MODEL_IDS,
16
- isAnvilWebGodOnlyModelId,
17
- isAnvilWebModelId,
18
- SUPPORTED_ANVIL_MODELS,
19
- } from '../constants/anvil-models'
20
-
21
- const KIMI_ID = ANVIL_KIMI_K3_ECO_MODEL_ID
22
-
23
- describe('Kimi K3 is god-only on Anvil Web', () => {
24
- it('is offered to god users and nobody else', () => {
25
- expect(isAnvilWebGodOnlyModelId(KIMI_ID)).toBe(true)
26
- expect(isAnvilWebModelId(KIMI_ID, { includeGodOnly: true })).toBe(true)
27
- expect(isAnvilWebModelId(KIMI_ID, { includeGodOnly: false })).toBe(false)
28
- expect(ANVIL_WEB_GOD_ONLY_MODELS.map((m) => m.id)).toContain(KIMI_ID)
29
- // The god-only list is additive to the visible one, so it must NOT also
30
- // appear there or every user would see it.
31
- expect(ANVIL_WEB_MODELS.map((m) => m.id)).not.toContain(KIMI_ID)
32
- })
33
-
34
- it('stays off every non-web surface', () => {
35
- // Web only, as asked. ANVIL_MODELS is the CLI/Desktop catalog and
36
- // SUPPORTED_ANVIL_MODELS the waiting-room set.
37
- expect(ANVIL_MODELS.map((m) => m.id)).not.toContain(KIMI_ID)
38
- expect(SUPPORTED_ANVIL_MODELS.map((m) => m.id)).not.toContain(KIMI_ID)
39
- expect(ANVIL_WEB_ALL_MODELS.map((m) => m.id)).toContain(KIMI_ID)
40
- })
41
-
42
- it('is metered by the premium pool, never the standard one', () => {
43
- // ANVIL_WEB_STANDARD_MODEL_IDS is derived by filtering `!premium`, so a
44
- // premium row missing from the premium list would be metered by NO pool.
45
- expect(ANVIL_WEB_PREMIUM_MODEL_IDS).toContain(KIMI_ID)
46
- expect(ANVIL_WEB_STANDARD_MODEL_IDS).not.toContain(KIMI_ID)
47
- const model = ANVIL_WEB_GOD_ONLY_MODELS.find((m) => m.id === KIMI_ID)
48
- expect(model?.premium).toBe(true)
49
- })
50
-
51
- it('displays as "Kimi K3" while the wire id keeps the -eco build', () => {
52
- // DELIBERATE, by explicit request, and the reason this assertion exists: it
53
- // breaks the convention DeepSeek V4 Flash 07/31 sets (name the exact build),
54
- // so without a test someone would "fix" the label to 'Kimi K3 Eco'.
55
- //
56
- // The wire id must keep `-eco` regardless. CrofAI serves a full `kimi-k3` at
57
- // twice the price ($2.00/$8.00), and routing, billing and CROF_MODEL_MAP all
58
- // key off this id — collapsing it to a bare `kimi-k3` would silently point
59
- // this row at the dearer model.
60
- const model = ANVIL_WEB_GOD_ONLY_MODELS.find((m) => m.id === KIMI_ID)
61
- expect(model?.displayName).toBe('Kimi K3')
62
- expect(model?.displayName).not.toContain('Eco')
63
- expect(KIMI_ID).toBe('crof/kimi-k3-eco')
64
- })
65
-
66
- it('is marked experimental, since it exists to be tested', () => {
67
- const model = ANVIL_WEB_GOD_ONLY_MODELS.find((m) => m.id === KIMI_ID)
68
- expect(model?.experimental).toBe(true)
69
- })
70
-
71
- it('keeps its id distinct from every other catalog row', () => {
72
- // A second id for an already-offered model is how the retired `crof/glm-5.2`
73
- // became a quota-bypass route. This must be the only id that reaches K3 Eco.
74
- const all = ANVIL_WEB_ALL_MODELS.map((m) => m.id)
75
- expect(new Set(all).size).toBe(all.length)
76
- })
77
- })
@@ -1,89 +0,0 @@
1
- import { describe, expect, test } from 'bun:test'
2
-
3
- import {
4
- contextPrunerBudgetForModel,
5
- isExplicitlyDefinedModel,
6
- models,
7
- supportsAssistantPrefill,
8
- } from '../constants/model-config'
9
-
10
- describe('isExplicitlyDefinedModel', () => {
11
- test('distinguishes configured models from unknown model IDs', () => {
12
- expect(isExplicitlyDefinedModel(models.openrouter_gpt5)).toBe(true)
13
- expect(isExplicitlyDefinedModel('custom/unknown-model')).toBe(false)
14
- })
15
- })
16
-
17
- describe('supportsAssistantPrefill', () => {
18
- test('rejects prefill for Claude 4.6+', () => {
19
- expect(supportsAssistantPrefill('anthropic/claude-opus-4.6')).toBe(false)
20
- expect(supportsAssistantPrefill('anthropic/claude-opus-4.7')).toBe(false)
21
- expect(supportsAssistantPrefill('anthropic/claude-sonnet-4.6')).toBe(false)
22
- expect(supportsAssistantPrefill('anthropic/claude-fable-5')).toBe(false)
23
- })
24
-
25
- test('allows prefill for Claude before 4.6', () => {
26
- expect(supportsAssistantPrefill('anthropic/claude-sonnet-4.5')).toBe(true)
27
- expect(supportsAssistantPrefill('anthropic/claude-opus-4')).toBe(true)
28
- expect(supportsAssistantPrefill('anthropic/claude-3-5-sonnet')).toBe(true)
29
- expect(
30
- supportsAssistantPrefill('anthropic/claude-haiku-4-5-20251001'),
31
- ).toBe(true)
32
- })
33
-
34
- test('allows prefill for non-Claude models', () => {
35
- expect(supportsAssistantPrefill('openai/gpt-5.1')).toBe(true)
36
- expect(supportsAssistantPrefill('deepseek/deepseek-v4-pro')).toBe(true)
37
- expect(supportsAssistantPrefill('moonshotai/kimi-k2.6')).toBe(true)
38
- })
39
- })
40
-
41
- describe('contextPrunerBudgetForModel', () => {
42
- test('defaults to 400k, which every ~1M-window model we serve can hold', () => {
43
- for (const model of [
44
- 'anthropic/claude-opus-5',
45
- 'anthropic/claude-sonnet-5',
46
- 'openai/gpt-5.4',
47
- 'openai/gpt-5.6-luna',
48
- 'deepseek/deepseek-v4-flash',
49
- 'deepseek/deepseek-v4-pro',
50
- 'mimo/mimo-v2.5',
51
- 'z-ai/glm-5.2',
52
- // MiniMax M3's real enforced limit is 524_288 (Fireworks rejects with
53
- // "model maximum context length: 524287"), not the 1M OpenRouter lists.
54
- // 400k is still comfortably under it.
55
- 'minimax/minimax-m3',
56
- 'some/model-we-have-never-shipped',
57
- ]) {
58
- expect(contextPrunerBudgetForModel(model)).toBe(400_000)
59
- }
60
- })
61
-
62
- test('drops to 250k for the 262,144-token models', () => {
63
- // Kimi K2.7 Code is the only remaining exception: the HY3 and Ling 3.0
64
- // Flash entries that shared its window went with those models on
65
- // 2026-08-07, so they now take the 400k default like anything unlisted.
66
- expect(contextPrunerBudgetForModel('moonshotai/kimi-k2.7-code')).toBe(
67
- 250_000,
68
- )
69
- for (const removed of [
70
- 'tencent/hy3',
71
- 'tencent/hy3:free',
72
- 'tencent/hy3-preview',
73
- 'inclusionai/ling-3.0-flash:free',
74
- ]) {
75
- expect(contextPrunerBudgetForModel(removed)).toBe(400_000)
76
- }
77
- })
78
-
79
- test('every exception stays under its real window', () => {
80
- // The budget is compared against a GPT-4o-based estimate applied to other
81
- // tokenizers, so it must sit under the provider's limit with room to spare.
82
- expect(
83
- contextPrunerBudgetForModel('moonshotai/kimi-k2.7-code'),
84
- ).toBeLessThan(262_144)
85
- // Kimi K3 Eco is deliberately NOT an exception — CrofAI serves it at a 1M
86
- // context, so the 400k default is correct for it.
87
- expect(contextPrunerBudgetForModel('crof/kimi-k3-eco')).toBe(400_000)
88
- })
89
- })