@amalgm/chat 0.1.0

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 (183) hide show
  1. package/PURPOSE.md +107 -0
  2. package/README.md +41 -0
  3. package/dist/contract/chat-input.d.ts +144 -0
  4. package/dist/contract/chat-input.d.ts.map +1 -0
  5. package/dist/contract/chat-input.js +261 -0
  6. package/dist/contract/chat-input.js.map +1 -0
  7. package/dist/contract/create.d.ts +191 -0
  8. package/dist/contract/create.d.ts.map +1 -0
  9. package/dist/contract/create.js +249 -0
  10. package/dist/contract/create.js.map +1 -0
  11. package/dist/contract/freeze.d.ts +85 -0
  12. package/dist/contract/freeze.d.ts.map +1 -0
  13. package/dist/contract/freeze.js +151 -0
  14. package/dist/contract/freeze.js.map +1 -0
  15. package/dist/contract/harnesses.d.ts +21 -0
  16. package/dist/contract/harnesses.d.ts.map +1 -0
  17. package/dist/contract/harnesses.js +39 -0
  18. package/dist/contract/harnesses.js.map +1 -0
  19. package/dist/contract/index.d.ts +17 -0
  20. package/dist/contract/index.d.ts.map +1 -0
  21. package/dist/contract/index.js +17 -0
  22. package/dist/contract/index.js.map +1 -0
  23. package/dist/contract/input.d.ts +45 -0
  24. package/dist/contract/input.d.ts.map +1 -0
  25. package/dist/contract/input.js +78 -0
  26. package/dist/contract/input.js.map +1 -0
  27. package/dist/contract/models.d.ts +57 -0
  28. package/dist/contract/models.d.ts.map +1 -0
  29. package/dist/contract/models.js +380 -0
  30. package/dist/contract/models.js.map +1 -0
  31. package/dist/contract/payload-merge.d.ts +76 -0
  32. package/dist/contract/payload-merge.d.ts.map +1 -0
  33. package/dist/contract/payload-merge.js +215 -0
  34. package/dist/contract/payload-merge.js.map +1 -0
  35. package/dist/events/constructors.d.ts +53 -0
  36. package/dist/events/constructors.d.ts.map +1 -0
  37. package/dist/events/constructors.js +217 -0
  38. package/dist/events/constructors.js.map +1 -0
  39. package/dist/events/index.d.ts +12 -0
  40. package/dist/events/index.d.ts.map +1 -0
  41. package/dist/events/index.js +12 -0
  42. package/dist/events/index.js.map +1 -0
  43. package/dist/events/schema.d.ts +455 -0
  44. package/dist/events/schema.d.ts.map +1 -0
  45. package/dist/events/schema.js +228 -0
  46. package/dist/events/schema.js.map +1 -0
  47. package/dist/events/tool-display.d.ts +22 -0
  48. package/dist/events/tool-display.d.ts.map +1 -0
  49. package/dist/events/tool-display.js +60 -0
  50. package/dist/events/tool-display.js.map +1 -0
  51. package/dist/events/tool-shape.d.ts +48 -0
  52. package/dist/events/tool-shape.d.ts.map +1 -0
  53. package/dist/events/tool-shape.js +225 -0
  54. package/dist/events/tool-shape.js.map +1 -0
  55. package/dist/index.d.ts +27 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +26 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/normalizers/claude.d.ts +628 -0
  60. package/dist/normalizers/claude.d.ts.map +1 -0
  61. package/dist/normalizers/claude.js +603 -0
  62. package/dist/normalizers/claude.js.map +1 -0
  63. package/dist/normalizers/codex.d.ts +352 -0
  64. package/dist/normalizers/codex.d.ts.map +1 -0
  65. package/dist/normalizers/codex.js +485 -0
  66. package/dist/normalizers/codex.js.map +1 -0
  67. package/dist/normalizers/cursor.d.ts +34 -0
  68. package/dist/normalizers/cursor.d.ts.map +1 -0
  69. package/dist/normalizers/cursor.js +197 -0
  70. package/dist/normalizers/cursor.js.map +1 -0
  71. package/dist/normalizers/index.d.ts +13 -0
  72. package/dist/normalizers/index.d.ts.map +1 -0
  73. package/dist/normalizers/index.js +13 -0
  74. package/dist/normalizers/index.js.map +1 -0
  75. package/dist/normalizers/opencode.d.ts +81 -0
  76. package/dist/normalizers/opencode.d.ts.map +1 -0
  77. package/dist/normalizers/opencode.js +640 -0
  78. package/dist/normalizers/opencode.js.map +1 -0
  79. package/dist/normalizers/pi.d.ts +28 -0
  80. package/dist/normalizers/pi.d.ts.map +1 -0
  81. package/dist/normalizers/pi.js +160 -0
  82. package/dist/normalizers/pi.js.map +1 -0
  83. package/dist/ports.d.ts +14 -0
  84. package/dist/ports.d.ts.map +1 -0
  85. package/dist/ports.js +7 -0
  86. package/dist/ports.js.map +1 -0
  87. package/dist/transcript/index.d.ts +14 -0
  88. package/dist/transcript/index.d.ts.map +1 -0
  89. package/dist/transcript/index.js +12 -0
  90. package/dist/transcript/index.js.map +1 -0
  91. package/dist/transcript/message-reducer.d.ts +167 -0
  92. package/dist/transcript/message-reducer.d.ts.map +1 -0
  93. package/dist/transcript/message-reducer.js +400 -0
  94. package/dist/transcript/message-reducer.js.map +1 -0
  95. package/dist/transcript/part-accumulator.d.ts +24 -0
  96. package/dist/transcript/part-accumulator.d.ts.map +1 -0
  97. package/dist/transcript/part-accumulator.js +30 -0
  98. package/dist/transcript/part-accumulator.js.map +1 -0
  99. package/dist/transcript/tool-display.d.ts +14 -0
  100. package/dist/transcript/tool-display.d.ts.map +1 -0
  101. package/dist/transcript/tool-display.js +125 -0
  102. package/dist/transcript/tool-display.js.map +1 -0
  103. package/dist/transcript/tool-shape.d.ts +34 -0
  104. package/dist/transcript/tool-shape.d.ts.map +1 -0
  105. package/dist/transcript/tool-shape.js +216 -0
  106. package/dist/transcript/tool-shape.js.map +1 -0
  107. package/dist/turns/index.d.ts +11 -0
  108. package/dist/turns/index.d.ts.map +1 -0
  109. package/dist/turns/index.js +11 -0
  110. package/dist/turns/index.js.map +1 -0
  111. package/dist/turns/queries.d.ts +36 -0
  112. package/dist/turns/queries.d.ts.map +1 -0
  113. package/dist/turns/queries.js +37 -0
  114. package/dist/turns/queries.js.map +1 -0
  115. package/dist/turns/replay.d.ts +105 -0
  116. package/dist/turns/replay.d.ts.map +1 -0
  117. package/dist/turns/replay.js +163 -0
  118. package/dist/turns/replay.js.map +1 -0
  119. package/dist/turns/status.d.ts +49 -0
  120. package/dist/turns/status.d.ts.map +1 -0
  121. package/dist/turns/status.js +56 -0
  122. package/dist/turns/status.js.map +1 -0
  123. package/dist/turns/turn-store.d.ts +109 -0
  124. package/dist/turns/turn-store.d.ts.map +1 -0
  125. package/dist/turns/turn-store.js +169 -0
  126. package/dist/turns/turn-store.js.map +1 -0
  127. package/dist/usage/finalize.d.ts +57 -0
  128. package/dist/usage/finalize.d.ts.map +1 -0
  129. package/dist/usage/finalize.js +139 -0
  130. package/dist/usage/finalize.js.map +1 -0
  131. package/dist/usage/index.d.ts +11 -0
  132. package/dist/usage/index.d.ts.map +1 -0
  133. package/dist/usage/index.js +11 -0
  134. package/dist/usage/index.js.map +1 -0
  135. package/dist/usage/model-catalog.d.ts +50 -0
  136. package/dist/usage/model-catalog.d.ts.map +1 -0
  137. package/dist/usage/model-catalog.js +344 -0
  138. package/dist/usage/model-catalog.js.map +1 -0
  139. package/dist/usage/normalize.d.ts +103 -0
  140. package/dist/usage/normalize.d.ts.map +1 -0
  141. package/dist/usage/normalize.js +71 -0
  142. package/dist/usage/normalize.js.map +1 -0
  143. package/dist/usage/ports.d.ts +141 -0
  144. package/dist/usage/ports.d.ts.map +1 -0
  145. package/dist/usage/ports.js +113 -0
  146. package/dist/usage/ports.js.map +1 -0
  147. package/dist/usage/tokens.d.ts +79 -0
  148. package/dist/usage/tokens.d.ts.map +1 -0
  149. package/dist/usage/tokens.js +98 -0
  150. package/dist/usage/tokens.js.map +1 -0
  151. package/dist/warm/client-cache.d.ts +47 -0
  152. package/dist/warm/client-cache.d.ts.map +1 -0
  153. package/dist/warm/client-cache.js +48 -0
  154. package/dist/warm/client-cache.js.map +1 -0
  155. package/dist/warm/envelope-cache.d.ts +79 -0
  156. package/dist/warm/envelope-cache.d.ts.map +1 -0
  157. package/dist/warm/envelope-cache.js +85 -0
  158. package/dist/warm/envelope-cache.js.map +1 -0
  159. package/dist/warm/index.d.ts +16 -0
  160. package/dist/warm/index.d.ts.map +1 -0
  161. package/dist/warm/index.js +11 -0
  162. package/dist/warm/index.js.map +1 -0
  163. package/dist/warm/payload.d.ts +137 -0
  164. package/dist/warm/payload.d.ts.map +1 -0
  165. package/dist/warm/payload.js +112 -0
  166. package/dist/warm/payload.js.map +1 -0
  167. package/dist/warm/revision.d.ts +70 -0
  168. package/dist/warm/revision.d.ts.map +1 -0
  169. package/dist/warm/revision.js +63 -0
  170. package/dist/warm/revision.js.map +1 -0
  171. package/dist/warm/store-policy.d.ts +57 -0
  172. package/dist/warm/store-policy.d.ts.map +1 -0
  173. package/dist/warm/store-policy.js +89 -0
  174. package/dist/warm/store-policy.js.map +1 -0
  175. package/dist/wire/frames.d.ts +208 -0
  176. package/dist/wire/frames.d.ts.map +1 -0
  177. package/dist/wire/frames.js +245 -0
  178. package/dist/wire/frames.js.map +1 -0
  179. package/dist/wire/index.d.ts +7 -0
  180. package/dist/wire/index.d.ts.map +1 -0
  181. package/dist/wire/index.js +7 -0
  182. package/dist/wire/index.js.map +1 -0
  183. package/package.json +72 -0
@@ -0,0 +1,380 @@
1
+ /**
2
+ * Model identity tables — engine `chat-core/contract.js:23-345`, ported
3
+ * byte-exact. A model has four identities:
4
+ *
5
+ * - display id — what the UI sent (`payload.modelId`)
6
+ * - canonical id — `canonicalModel()`: the billing identity
7
+ * (`contract.modelId` / `usageModelId`)
8
+ * - runtime-CLI id — `cliModelFor()`: what the harness CLI is launched with
9
+ * (`contract.cliModel`)
10
+ * - context profile — derived downstream from the canonical id
11
+ *
12
+ * The alias tables below are the frozen law: every row's spelling, order, and
13
+ * precedence must match the engine exactly, because `runtimeKey` fingerprints
14
+ * their outputs.
15
+ */
16
+ // First-party providers on the Vercel AI Gateway (multi-word first so the
17
+ // dash-separated legacy ids match longest-prefix).
18
+ export const GATEWAY_PROVIDERS = [
19
+ 'prime-intellect',
20
+ 'arcee-ai',
21
+ 'alibaba',
22
+ 'amazon',
23
+ 'anthropic',
24
+ 'bytedance',
25
+ 'cohere',
26
+ 'cursor',
27
+ 'deepseek',
28
+ 'google',
29
+ 'inception',
30
+ 'kwaipilot',
31
+ 'meituan',
32
+ 'meta',
33
+ 'minimax',
34
+ 'mistral',
35
+ 'moonshotai',
36
+ 'morph',
37
+ 'nvidia',
38
+ 'openai',
39
+ 'perplexity',
40
+ 'xiaomi',
41
+ 'xai',
42
+ 'zai',
43
+ ];
44
+ // 'pi-anthropic-claude-sonnet-4.6' / 'vercel/anthropic/x' -> 'anthropic/claude-sonnet-4.6'
45
+ export function gatewayModelId(raw) {
46
+ const bare = String(raw || '').replace(/^pi-/, '').replace(/^vercel\//, '');
47
+ if (bare.includes('/'))
48
+ return bare;
49
+ for (const provider of GATEWAY_PROVIDERS) {
50
+ const prefix = `${provider}-`;
51
+ if (bare.startsWith(prefix))
52
+ return `${provider}/${bare.slice(prefix.length)}`;
53
+ }
54
+ return bare;
55
+ }
56
+ export const CURSOR_CLI_ALIASES = {
57
+ 'composer-2': 'composer-2.5',
58
+ 'composer-2-fast': 'composer-2.5-fast',
59
+ 'claude-fable-5': 'claude-fable-5-high',
60
+ 'claude-fable-5-thinking': 'claude-fable-5-thinking-high',
61
+ 'claude-opus-4-8': 'claude-opus-4-8-high',
62
+ 'claude-opus-4-8-thinking': 'claude-opus-4-8-thinking-high',
63
+ 'claude-opus-4-7': 'claude-opus-4-7-xhigh',
64
+ 'claude-opus-4-7-thinking': 'claude-opus-4-7-thinking-xhigh',
65
+ 'claude-opus-4-6': 'claude-4.6-opus-high',
66
+ 'claude-opus-4-6-thinking': 'claude-4.6-opus-high-thinking',
67
+ 'claude-opus-4-5': 'claude-4.5-opus-high',
68
+ 'claude-opus-4-5-thinking': 'claude-4.5-opus-high-thinking',
69
+ 'claude-sonnet-5': 'claude-sonnet-5-high',
70
+ 'claude-sonnet-5-thinking': 'claude-sonnet-5-thinking-high',
71
+ 'claude-sonnet-4-6': 'claude-4.6-sonnet-medium',
72
+ 'claude-sonnet-4-6-thinking': 'claude-4.6-sonnet-medium-thinking',
73
+ 'gpt-5.5': 'gpt-5.5-medium',
74
+ 'gpt-5.4': 'gpt-5.4-medium',
75
+ 'gpt-5.4-mini': 'gpt-5.4-mini-medium',
76
+ 'gpt-5.4-nano': 'gpt-5.4-nano-medium',
77
+ 'grok-4.5': 'grok-4.5-xhigh',
78
+ 'glm-5.2': 'glm-5.2-high',
79
+ };
80
+ export const CURSOR_CANONICAL_MODEL_ALIASES = {
81
+ 'cursor/composer-2': 'cursor/composer-2.5',
82
+ 'cursor/composer-2-fast': 'cursor/composer-2.5-fast',
83
+ 'anthropic/claude-fable-5': 'anthropic/claude-fable-5-high',
84
+ 'anthropic/claude-fable-5-thinking': 'anthropic/claude-fable-5-thinking-high',
85
+ 'anthropic/claude-opus-4.8': 'anthropic/claude-opus-4.8-high',
86
+ 'anthropic/claude-opus-4.8-thinking': 'anthropic/claude-opus-4.8-thinking-high',
87
+ 'anthropic/claude-opus-4.7': 'anthropic/claude-opus-4.7-xhigh',
88
+ 'anthropic/claude-opus-4.7-thinking': 'anthropic/claude-opus-4.7-thinking-xhigh',
89
+ 'anthropic/claude-opus-4.6': 'anthropic/claude-opus-4.6-high',
90
+ 'anthropic/claude-opus-4.6-thinking': 'anthropic/claude-opus-4.6-high-thinking',
91
+ 'anthropic/claude-opus-4.5': 'anthropic/claude-opus-4.5-high',
92
+ 'anthropic/claude-opus-4.5-thinking': 'anthropic/claude-opus-4.5-high-thinking',
93
+ 'anthropic/claude-sonnet-5': 'anthropic/claude-sonnet-5-high',
94
+ 'anthropic/claude-sonnet-5-thinking': 'anthropic/claude-sonnet-5-thinking-high',
95
+ 'anthropic/claude-sonnet-4.6': 'anthropic/claude-sonnet-4.6-medium',
96
+ 'anthropic/claude-sonnet-4.6-thinking': 'anthropic/claude-sonnet-4.6-medium-thinking',
97
+ 'openai/gpt-5.5': 'openai/gpt-5.5-medium',
98
+ 'openai/gpt-5.4': 'openai/gpt-5.4-medium',
99
+ 'openai/gpt-5.4-mini': 'openai/gpt-5.4-mini-medium',
100
+ 'openai/gpt-5.4-nano': 'openai/gpt-5.4-nano-medium',
101
+ 'google/gemini-3.1-pro-preview': 'google/gemini-3.1-pro',
102
+ 'xai/grok-4.5': 'xai/grok-4.5-xhigh',
103
+ 'zai/glm-5.2': 'zai/glm-5.2-high',
104
+ };
105
+ export function cursorCliAlias(cliModel) {
106
+ return CURSOR_CLI_ALIASES[cliModel] || cliModel;
107
+ }
108
+ export function cursorAnthropicCliModel(model) {
109
+ const versioned = model.match(/^claude-(opus|sonnet)-(4(?:\.\d+)?)(?:-(.+))?$/);
110
+ if (!versioned) {
111
+ return model.replace(/-(\d+)\.(\d+)(?=$|-)/, '-$1-$2');
112
+ }
113
+ const [, family, version, rawSuffix] = versioned;
114
+ const suffix = rawSuffix || '';
115
+ if (family === 'sonnet' && version === '4.6') {
116
+ if (!suffix)
117
+ return 'claude-4.6-sonnet-medium';
118
+ if (suffix === 'thinking')
119
+ return 'claude-4.6-sonnet-medium-thinking';
120
+ return `claude-4.6-sonnet-${suffix}`;
121
+ }
122
+ if (family === 'sonnet' && (version === '4.5' || version === '4')) {
123
+ return `claude-${version}-sonnet${suffix ? `-${suffix}` : ''}`;
124
+ }
125
+ if (family === 'opus' && version === '4.6') {
126
+ if (!suffix)
127
+ return 'claude-4.6-opus-high';
128
+ if (suffix === 'thinking')
129
+ return 'claude-4.6-opus-high-thinking';
130
+ return `claude-4.6-opus-${suffix}`;
131
+ }
132
+ if (family === 'opus' && version === '4.5') {
133
+ if (!suffix)
134
+ return 'claude-4.5-opus-high';
135
+ if (suffix === 'thinking')
136
+ return 'claude-4.5-opus-high-thinking';
137
+ return `claude-4.5-opus-${suffix}`;
138
+ }
139
+ return model.replace(/-(\d+)\.(\d+)(?=$|-)/, '-$1-$2');
140
+ }
141
+ export function cursorCliModelFor(raw) {
142
+ const clean = String(raw || '').trim().replace(/^vercel\//i, '').toLowerCase();
143
+ const canonical = CURSOR_CANONICAL_MODEL_ALIASES[clean] || clean;
144
+ if (canonical.startsWith('cursor/'))
145
+ return cursorCliAlias(canonical.slice('cursor/'.length));
146
+ if (canonical.startsWith('cursor-'))
147
+ return cursorCliAlias(canonical.slice('cursor-'.length));
148
+ if (canonical.startsWith('openai/'))
149
+ return canonical.slice('openai/'.length);
150
+ if (canonical.startsWith('google/'))
151
+ return canonical.slice('google/'.length);
152
+ if (canonical.startsWith('moonshotai/'))
153
+ return canonical.slice('moonshotai/'.length);
154
+ if (canonical.startsWith('zai/'))
155
+ return canonical.slice('zai/'.length);
156
+ if (canonical.startsWith('xai/')) {
157
+ return canonical.slice('xai/'.length).replace(/^grok-4\.20/, 'grok-4-20');
158
+ }
159
+ if (canonical.startsWith('anthropic/')) {
160
+ return cursorAnthropicCliModel(canonical.slice('anthropic/'.length));
161
+ }
162
+ return cursorCliAlias(canonical);
163
+ }
164
+ /**
165
+ * Claude Code display-id -> canonical billing-id alias table
166
+ * (`contract.js:171-240`). Keys are matched after `vercel/` strip +
167
+ * lowercase.
168
+ */
169
+ export const CLAUDE_CODE_MODEL_ALIASES = {
170
+ 'haiku': 'anthropic/claude-haiku-4.5',
171
+ 'sonnet': 'anthropic/claude-sonnet-4.6',
172
+ 'sonnet[1m]': 'anthropic/claude-sonnet-4.6',
173
+ 'opus': 'anthropic/claude-opus-4.8',
174
+ 'opus1m': 'anthropic/claude-opus-4.8-1m',
175
+ 'opus[1m]': 'anthropic/claude-opus-4.8-1m',
176
+ 'fable': 'anthropic/claude-fable-5',
177
+ 'claude-code-haiku': 'anthropic/claude-haiku-4.5',
178
+ 'claude-code-sonnet': 'anthropic/claude-sonnet-4.6',
179
+ 'claude-code-sonnet-45': 'anthropic/claude-sonnet-4.6',
180
+ 'claude-code-fable': 'anthropic/claude-fable-5',
181
+ 'claude-code-fable-5': 'anthropic/claude-fable-5',
182
+ 'claude-code-opus': 'anthropic/claude-opus-4.8',
183
+ 'claude-code-opus-45': 'anthropic/claude-opus-4.8',
184
+ 'claude-code-opus-46': 'anthropic/claude-opus-4.8',
185
+ 'claude-code-opus-47': 'anthropic/claude-opus-4.8',
186
+ 'claude-code-opus-48': 'anthropic/claude-opus-4.8',
187
+ 'claude-code-opus-4.5': 'anthropic/claude-opus-4.8',
188
+ 'claude-code-opus-4-5': 'anthropic/claude-opus-4.8',
189
+ 'claude-code-opus-4.6': 'anthropic/claude-opus-4.8',
190
+ 'claude-code-opus-4-6': 'anthropic/claude-opus-4.8',
191
+ 'claude-code-opus-4.7': 'anthropic/claude-opus-4.8',
192
+ 'claude-code-opus-4-7': 'anthropic/claude-opus-4.8',
193
+ 'claude-code-opus-4.8': 'anthropic/claude-opus-4.8',
194
+ 'claude-code-opus-4-8': 'anthropic/claude-opus-4.8',
195
+ 'claude-code-opus1m': 'anthropic/claude-opus-4.8-1m',
196
+ 'claude-code-opus-1m': 'anthropic/claude-opus-4.8-1m',
197
+ 'claude-code-opus-4.8-1m': 'anthropic/claude-opus-4.8-1m',
198
+ 'claude-code-opus-4-8-1m': 'anthropic/claude-opus-4.8-1m',
199
+ 'claude-code-opus-4.7-1m': 'anthropic/claude-opus-4.8-1m',
200
+ 'claude-code-opus-4-7-1m': 'anthropic/claude-opus-4.8-1m',
201
+ 'claude-code-sonnet-4.5': 'anthropic/claude-sonnet-4.6',
202
+ 'claude-code-sonnet-4-5': 'anthropic/claude-sonnet-4.6',
203
+ 'claude-code-sonnet-4.6': 'anthropic/claude-sonnet-4.6',
204
+ 'claude-code-sonnet-4-6': 'anthropic/claude-sonnet-4.6',
205
+ 'claude-code-haiku-4.5': 'anthropic/claude-haiku-4.5',
206
+ 'claude-code-haiku-4-5': 'anthropic/claude-haiku-4.5',
207
+ 'claude-haiku-4-5': 'anthropic/claude-haiku-4.5',
208
+ 'claude-fable-5': 'anthropic/claude-fable-5',
209
+ 'claude-sonnet-4-5': 'anthropic/claude-sonnet-4.6',
210
+ 'claude-sonnet-4-6': 'anthropic/claude-sonnet-4.6',
211
+ 'claude-opus-4-5': 'anthropic/claude-opus-4.8',
212
+ 'claude-opus-4-6': 'anthropic/claude-opus-4.8',
213
+ 'claude-opus-4-7': 'anthropic/claude-opus-4.8',
214
+ 'claude-opus-4-8': 'anthropic/claude-opus-4.8',
215
+ 'claude-opus-4-8-1m': 'anthropic/claude-opus-4.8-1m',
216
+ 'claude-opus-4.8-1m': 'anthropic/claude-opus-4.8-1m',
217
+ 'claude-opus-4-7-1m': 'anthropic/claude-opus-4.8-1m',
218
+ 'claude-opus-4.7-1m': 'anthropic/claude-opus-4.8-1m',
219
+ 'anthropic/claude-haiku-4-5': 'anthropic/claude-haiku-4.5',
220
+ 'anthropic/claude-haiku-4.5': 'anthropic/claude-haiku-4.5',
221
+ 'anthropic/claude-fable-5': 'anthropic/claude-fable-5',
222
+ 'anthropic/claude-sonnet-4-5': 'anthropic/claude-sonnet-4.6',
223
+ 'anthropic/claude-sonnet-4-6': 'anthropic/claude-sonnet-4.6',
224
+ 'anthropic/claude-sonnet-4.5': 'anthropic/claude-sonnet-4.6',
225
+ 'anthropic/claude-sonnet-4.6': 'anthropic/claude-sonnet-4.6',
226
+ 'anthropic/claude-opus-4-5': 'anthropic/claude-opus-4.8',
227
+ 'anthropic/claude-opus-4-6': 'anthropic/claude-opus-4.8',
228
+ 'anthropic/claude-opus-4-7': 'anthropic/claude-opus-4.8',
229
+ 'anthropic/claude-opus-4-8': 'anthropic/claude-opus-4.8',
230
+ 'anthropic/claude-opus-4-8-1m': 'anthropic/claude-opus-4.8-1m',
231
+ 'anthropic/claude-opus-4-7-1m': 'anthropic/claude-opus-4.8-1m',
232
+ 'anthropic/claude-opus-4.5': 'anthropic/claude-opus-4.8',
233
+ 'anthropic/claude-opus-4.6': 'anthropic/claude-opus-4.8',
234
+ 'anthropic/claude-opus-4.7': 'anthropic/claude-opus-4.8',
235
+ 'anthropic/claude-opus-4.8': 'anthropic/claude-opus-4.8',
236
+ 'anthropic/claude-opus-4.8-1m': 'anthropic/claude-opus-4.8-1m',
237
+ 'anthropic/claude-opus-4.7-1m': 'anthropic/claude-opus-4.8-1m',
238
+ };
239
+ /**
240
+ * `canonicalModel(modelId, harness)` — engine `contract.js:164-258`.
241
+ * Throw message ("modelId is required for <harness>") is byte-exact.
242
+ */
243
+ export function canonicalModel(modelId, harness) {
244
+ const raw = String(modelId || '').trim();
245
+ if (!raw) {
246
+ throw new Error(`modelId is required for ${harness}`);
247
+ }
248
+ if (harness === 'claude_code') {
249
+ const cleaned = raw.replace(/^vercel\//i, '').toLowerCase();
250
+ const aliased = CLAUDE_CODE_MODEL_ALIASES[cleaned];
251
+ if (aliased)
252
+ return aliased;
253
+ if (cleaned.startsWith('anthropic/'))
254
+ return cleaned.replace(/-(\d+)-(\d+)(?=$|-)/, '-$1.$2');
255
+ if (cleaned.startsWith('claude-')) {
256
+ return `anthropic/${cleaned.replace(/-(\d+)-(\d+)(?=$|-)/, '-$1.$2')}`;
257
+ }
258
+ return raw;
259
+ }
260
+ // Cursor is provider_auth-only and reports no usage, so the model id is a
261
+ // display/runtime identity, not a billing identity; keep it as sent.
262
+ if (harness === 'cursor')
263
+ return raw;
264
+ // Pi bills against the gateway model identity ('anthropic/claude-sonnet-4.6').
265
+ if (harness === 'pi')
266
+ return gatewayModelId(raw);
267
+ if (raw.startsWith('opencode-openai-'))
268
+ return `openai/${raw.slice('opencode-openai-'.length)}`;
269
+ if (raw.startsWith('codex-openai-'))
270
+ return `openai/${raw.slice('codex-openai-'.length)}`;
271
+ if (raw.startsWith('claude-'))
272
+ return `anthropic/${raw}`;
273
+ if (/^gpt-|^o\d|^o-/i.test(raw))
274
+ return `openai/${raw}`;
275
+ return raw;
276
+ }
277
+ /**
278
+ * Claude Code canonical/display -> CLI launch alias table
279
+ * (`contract.js:264-284`). Looked up first by canonical id, then by the
280
+ * lowercased raw input, else the raw input passes through.
281
+ */
282
+ export const CLAUDE_CODE_CLI_ALIASES = {
283
+ 'anthropic/claude-haiku-4.5': 'haiku',
284
+ 'anthropic/claude-sonnet-5': 'sonnet',
285
+ 'anthropic/claude-sonnet-4.6': 'sonnet',
286
+ 'anthropic/claude-opus-4.8': 'opus',
287
+ 'anthropic/claude-opus-4.8-1m': 'opus[1m]',
288
+ 'anthropic/claude-opus-4.7': 'opus',
289
+ 'anthropic/claude-opus-4.7-1m': 'opus[1m]',
290
+ 'anthropic/claude-fable-5': 'claude-fable-5',
291
+ 'haiku': 'haiku',
292
+ 'sonnet': 'sonnet',
293
+ 'sonnet-5': 'sonnet',
294
+ 'claude-sonnet-5': 'sonnet',
295
+ 'opus': 'opus',
296
+ 'opus1m': 'opus[1m]',
297
+ 'opus[1m]': 'opus[1m]',
298
+ 'fable': 'claude-fable-5',
299
+ 'claude-code-fable': 'claude-fable-5',
300
+ 'claude-code-fable-5': 'claude-fable-5',
301
+ 'claude-fable-5': 'claude-fable-5',
302
+ };
303
+ /**
304
+ * OpenCode gateway providers (`contract.js:312-334`). NOTE: intentionally a
305
+ * different list from `GATEWAY_PROVIDERS` — the engine's opencode branch omits
306
+ * 'moonshotai', 'morph', and 'nvidia'. Byte-parity requires keeping both.
307
+ */
308
+ export const OPENCODE_GATEWAY_PROVIDERS = [
309
+ 'prime-intellect',
310
+ 'arcee-ai',
311
+ 'alibaba',
312
+ 'amazon',
313
+ 'anthropic',
314
+ 'bytedance',
315
+ 'cohere',
316
+ 'cursor',
317
+ 'deepseek',
318
+ 'google',
319
+ 'inception',
320
+ 'kwaipilot',
321
+ 'meituan',
322
+ 'meta',
323
+ 'minimax',
324
+ 'mistral',
325
+ 'openai',
326
+ 'perplexity',
327
+ 'xiaomi',
328
+ 'xai',
329
+ 'zai',
330
+ ];
331
+ /**
332
+ * `cliModelFor({ harness, modelId, cliModel, reasoningEffort })` — engine
333
+ * `contract.js:260-345`: the runtime-CLI identity for a model.
334
+ */
335
+ export function cliModelFor({ harness, modelId, cliModel, reasoningEffort }) {
336
+ const clean = String(cliModel || modelId || '').trim();
337
+ if (harness === 'claude_code') {
338
+ const canonical = canonicalModel(clean, harness);
339
+ return CLAUDE_CODE_CLI_ALIASES[canonical] || CLAUDE_CODE_CLI_ALIASES[clean.toLowerCase()] || clean;
340
+ }
341
+ if (harness === 'codex') {
342
+ let base = clean.replace(/^openai\//, '');
343
+ let effort = reasoningEffort;
344
+ const slashEffort = base.match(/\/(low|medium|high|xhigh|max|ultra)$/i);
345
+ if (slashEffort) {
346
+ effort ||= slashEffort[1].toLowerCase();
347
+ base = base.slice(0, -slashEffort[0].length);
348
+ }
349
+ const thinkingEffort = base.match(/-thinking-(low|medium|high|xhigh|max|ultra)$/i);
350
+ if (!cliModel && thinkingEffort) {
351
+ effort ||= thinkingEffort[1].toLowerCase();
352
+ base = base.slice(0, -thinkingEffort[0].length);
353
+ }
354
+ return effort ? `${base}/${effort}` : base;
355
+ }
356
+ if (harness === 'cursor') {
357
+ // The adapter matches this against cursor-agent's ACP availableModels.
358
+ return cursorCliModelFor(clean);
359
+ }
360
+ if (harness === 'pi') {
361
+ // Pi's vercel-ai-gateway provider takes bare '<provider>/<model>' ids.
362
+ return gatewayModelId(clean);
363
+ }
364
+ if (harness === 'opencode') {
365
+ const bare = clean.replace(/^opencode-/, '');
366
+ if (bare.startsWith('vercel/'))
367
+ return bare;
368
+ const slashProvider = bare.split('/')[0];
369
+ if (OPENCODE_GATEWAY_PROVIDERS.includes(slashProvider))
370
+ return `vercel/${bare}`;
371
+ for (const provider of OPENCODE_GATEWAY_PROVIDERS) {
372
+ const prefix = `${provider}-`;
373
+ if (bare.startsWith(prefix))
374
+ return `vercel/${provider}/${bare.slice(prefix.length)}`;
375
+ }
376
+ return bare;
377
+ }
378
+ return clean;
379
+ }
380
+ //# sourceMappingURL=models.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/contract/models.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,0EAA0E;AAC1E,mDAAmD;AACnD,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,iBAAiB;IACjB,UAAU;IACV,SAAS;IACT,QAAQ;IACR,WAAW;IACX,WAAW;IACX,QAAQ;IACR,QAAQ;IACR,UAAU;IACV,QAAQ;IACR,WAAW;IACX,WAAW;IACX,SAAS;IACT,MAAM;IACN,SAAS;IACT,SAAS;IACT,YAAY;IACZ,OAAO;IACP,QA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vG,KAAK,MAAM,QAAQ,IAAI,0BAA0B,EAAE,CAAC;YAClD,MAAM,MAAM,GAAG,GAAG,QAAQ,GAAG,CAAC;YAC9B,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;gBAAE,OAAO,UAAU,QAAQ,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;QACxF,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * The merge law — engine `chat-core/chat-payload.js:33-160`
3
+ * (`applyPayloadRecord`), ported byte-exact, plus the error shapes of
4
+ * `resolveMachineChatPayload` (`chat-payload.js:162-185`) as exported
5
+ * builders. The sqlite payload fetch and MCP server resolution stay host.
6
+ *
7
+ * Precedence: machine payload record > structured chatInput > raw body.
8
+ * Client-supplied `cliModel` / `internalModelId` / `contextWindow` /
9
+ * `maxTokens` are always deleted — those identities are derived server-side.
10
+ */
11
+ import type { ChatInput } from './chat-input.js';
12
+ /** Engine `chat-payload.js harnessToAgent` — harness id back to UI agent id. */
13
+ export declare function harnessToAgent(harness: unknown): string;
14
+ /**
15
+ * Engine `agent-config/loadout.js normalizeLoadout` — pure, ported fully
16
+ * (applyPayloadRecord calls it on `payload.loadout || payload.tools`).
17
+ */
18
+ export declare function normalizeLoadout(value: unknown, fallback?: unknown, options?: {
19
+ defaultToolIds?: readonly string[] | undefined;
20
+ }): {
21
+ toolIds: string[];
22
+ };
23
+ /** A machine chat-payload record (`chat-payloads` store row). */
24
+ export interface ChatPayloadRecord {
25
+ payload?: unknown;
26
+ revision?: unknown;
27
+ [key: string]: unknown;
28
+ }
29
+ /**
30
+ * Host collaborators of `applyPayloadRecord`. Engine defaults:
31
+ * - `getAgentConfig` — `amalgm-mcp/agent-config/store.js getAgentConfig`
32
+ * (sqlite); SDK default returns null (no hydration).
33
+ * - `env` — `process.env.AMALGM_COMPUTER_ID` / `AMALGM_CONTAINER_ID`;
34
+ * pass both raw values so the engine's per-value trim/precedence holds.
35
+ */
36
+ export interface ApplyPayloadRecordPorts {
37
+ getAgentConfig?(agentConfigId: string): unknown | null;
38
+ env?: {
39
+ AMALGM_COMPUTER_ID?: string | undefined;
40
+ AMALGM_CONTAINER_ID?: string | undefined;
41
+ } | undefined;
42
+ }
43
+ export interface MergedChatBody {
44
+ [key: string]: unknown;
45
+ chatInput: ChatInput;
46
+ harness: string;
47
+ mcpAppIds: string[];
48
+ modelSettings: Record<string, unknown>;
49
+ agentId: string;
50
+ }
51
+ /**
52
+ * Engine `applyPayloadRecord(body, record)` (`chat-payload.js:33-160`):
53
+ * overlay a machine payload record onto a raw request body. Field precedence
54
+ * and the final deletions are byte-exact.
55
+ */
56
+ export declare function applyPayloadRecord(body: Record<string, any>, record: ChatPayloadRecord | null | undefined, ports?: ApplyPayloadRecordPorts): MergedChatBody;
57
+ export interface ChatPayloadNotFoundError extends Error {
58
+ status: 404;
59
+ }
60
+ /**
61
+ * The 404 from `resolveMachineChatPayload` when the payload record is missing
62
+ * (`chat-payload.js:167-169`). Message and status are byte-exact.
63
+ */
64
+ export declare function chatPayloadNotFoundError(payloadId: string): ChatPayloadNotFoundError;
65
+ export interface ChatPayloadRevisionMismatchError extends Error {
66
+ status: 409;
67
+ }
68
+ /**
69
+ * The 409 from `resolveMachineChatPayload` when the launch payload's revision
70
+ * moved before launch (`chat-payload.js:173-178`). Message and status are
71
+ * byte-exact. The revision comparison itself stays host (it needs the sqlite
72
+ * record); the engine only throws when BOTH revisions are non-empty strings
73
+ * and differ.
74
+ */
75
+ export declare function chatPayloadRevisionMismatchError(): ChatPayloadRevisionMismatchError;
76
+ //# sourceMappingURL=payload-merge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payload-merge.d.ts","sourceRoot":"","sources":["../../src/contract/payload-merge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,SAAS,E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