@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,47 @@
1
+ /**
2
+ * Client-side warm-envelope cache — the pure helpers of
3
+ * `amalgm-ui/lib/chat/launchEnvelopeClientCache.ts`. The React hook, the
4
+ * module-level Maps, the debounce timer, and the warm POST are host; this
5
+ * module owns the key law, the usability check, the debounce constant, and
6
+ * the payload-key law.
7
+ *
8
+ * DEAD-LAYER WOUND (docs/warm-payloads.md, "Layer B ... currently dead"):
9
+ * in ChatView today `chatPayloadId` is always present on the request, so
10
+ * the guard `request && !request.chatPayloadId`
11
+ * (`launchEnvelopeClientCache.ts:48-50`) makes `payloadKey` ALWAYS null —
12
+ * no warm POST is ever issued and every send logs `launchEnvelope: "miss"`.
13
+ * Whether that is deliberate (machine payload made authoritative in
14
+ * `0f778ba`) or a regression is an open product question. The guard is
15
+ * ported faithfully anyway (engineParity with the UI source).
16
+ */
17
+ import type { LaunchEnvelopeRequest } from './payload.js';
18
+ /** Client cache-entry shape — `launchEnvelopeClientCache.ts:7-16`. */
19
+ export type LaunchEnvelopeCacheEntry = {
20
+ id: string;
21
+ fingerprint: string;
22
+ key: string;
23
+ cacheKey: string;
24
+ machineId: string | null;
25
+ expiresAt: number;
26
+ prepareMs: number;
27
+ fetchedMs: number;
28
+ };
29
+ /** `launchEnvelopeClientCache.ts:18` — warm 100 ms after any selection change. */
30
+ export declare const CACHE_WARM_DELAY_MS = 100;
31
+ /** Machine half of the cache key — `launchEnvelopeClientCache.ts:23-25`. */
32
+ export declare function machineKey(machineId: string | null | undefined): string;
33
+ /** Cache-key law — `launchEnvelopeClientCache.ts:27-32`: `machineKey\0payloadKey`. */
34
+ export declare function launchEnvelopeCacheKey(machineId: string | null | undefined, payloadKey: string): string;
35
+ /**
36
+ * Payload-key law — `launchEnvelopeClientCache.ts:48-51`: the warm body is
37
+ * the stable JSON of the request, but only when the request exists AND has
38
+ * no `chatPayloadId` (see the dead-layer wound above — in practice this is
39
+ * always null today).
40
+ */
41
+ export declare function launchEnvelopePayloadKey(request: LaunchEnvelopeRequest | null): string | null;
42
+ /**
43
+ * Usability check — `launchEnvelopeClientCache.ts:34-38`: an entry is
44
+ * usable while `expiresAt > now`; the UI reads `Date.now()`, injected here.
45
+ */
46
+ export declare function usableEntry(entry: LaunchEnvelopeCacheEntry | undefined, nowMs: number): LaunchEnvelopeCacheEntry | null;
47
+ //# sourceMappingURL=client-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-cache.d.ts","sourceRoot":"","sources":["../../src/warm/client-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAG1D,sEAAsE;AACtE,MAAM,MAAM,wBAAwB,GAAG;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,kFAAkF;AAClF,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC,4EAA4E;AAC5E,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAEvE;AAED,sFAAsF;AACtF,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACpC,UAAU,EAAE,MAAM,GACjB,MAAM,CAER;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,qBAAqB,GAAG,IAAI,GACpC,MAAM,GAAG,IAAI,CAEf;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,wBAAwB,GAAG,SAAS,EAC3C,KAAK,EAAE,MAAM,GACZ,wBAAwB,GAAG,IAAI,CAIjC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Client-side warm-envelope cache — the pure helpers of
3
+ * `amalgm-ui/lib/chat/launchEnvelopeClientCache.ts`. The React hook, the
4
+ * module-level Maps, the debounce timer, and the warm POST are host; this
5
+ * module owns the key law, the usability check, the debounce constant, and
6
+ * the payload-key law.
7
+ *
8
+ * DEAD-LAYER WOUND (docs/warm-payloads.md, "Layer B ... currently dead"):
9
+ * in ChatView today `chatPayloadId` is always present on the request, so
10
+ * the guard `request && !request.chatPayloadId`
11
+ * (`launchEnvelopeClientCache.ts:48-50`) makes `payloadKey` ALWAYS null —
12
+ * no warm POST is ever issued and every send logs `launchEnvelope: "miss"`.
13
+ * Whether that is deliberate (machine payload made authoritative in
14
+ * `0f778ba`) or a regression is an open product question. The guard is
15
+ * ported faithfully anyway (engineParity with the UI source).
16
+ */
17
+ import { stableJson } from './payload.js';
18
+ /** `launchEnvelopeClientCache.ts:18` — warm 100 ms after any selection change. */
19
+ export const CACHE_WARM_DELAY_MS = 100;
20
+ /** Machine half of the cache key — `launchEnvelopeClientCache.ts:23-25`. */
21
+ export function machineKey(machineId) {
22
+ return machineId?.trim() || 'local';
23
+ }
24
+ /** Cache-key law — `launchEnvelopeClientCache.ts:27-32`: `machineKey\0payloadKey`. */
25
+ export function launchEnvelopeCacheKey(machineId, payloadKey) {
26
+ return `${machineKey(machineId)}\0${payloadKey}`;
27
+ }
28
+ /**
29
+ * Payload-key law — `launchEnvelopeClientCache.ts:48-51`: the warm body is
30
+ * the stable JSON of the request, but only when the request exists AND has
31
+ * no `chatPayloadId` (see the dead-layer wound above — in practice this is
32
+ * always null today).
33
+ */
34
+ export function launchEnvelopePayloadKey(request) {
35
+ return request && !request.chatPayloadId ? stableJson(request) : null;
36
+ }
37
+ /**
38
+ * Usability check — `launchEnvelopeClientCache.ts:34-38`: an entry is
39
+ * usable while `expiresAt > now`; the UI reads `Date.now()`, injected here.
40
+ */
41
+ export function usableEntry(entry, nowMs) {
42
+ if (!entry)
43
+ return null;
44
+ if (entry.expiresAt <= nowMs)
45
+ return null;
46
+ return entry;
47
+ }
48
+ //# sourceMappingURL=client-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-cache.js","sourceRoot":"","sources":["../../src/warm/client-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAc1C,kFAAkF;AAClF,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEvC,4EAA4E;AAC5E,MAAM,UAAU,UAAU,CAAC,SAAoC;IAC7D,OAAO,SAAS,EAAE,IAAI,EAAE,IAAI,OAAO,CAAC;AACtC,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,sBAAsB,CACpC,SAAoC,EACpC,UAAkB;IAElB,OAAO,GAAG,UAAU,CAAC,SAAS,CAAC,KAAK,UAAU,EAAE,CAAC;AACnD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CACtC,OAAqC;IAErC,OAAO,OAAO,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACxE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CACzB,KAA2C,EAC3C,KAAa;IAEb,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,IAAI,KAAK,CAAC,SAAS,IAAI,KAAK;QAAE,OAAO,IAAI,CAAC;IAC1C,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Server-side launch-envelope cache policy — the pure laws of
3
+ * `amalgm-ui/lib/server/agentLaunchEnvelopeCache.ts` (Layer B in
4
+ * docs/warm-payloads.md).
5
+ *
6
+ * The `globalThis` Map itself, `crypto.randomUUID` id minting, and the
7
+ * store/get functions are host effects — this module exports the
8
+ * fingerprint law (sha256 injected via Sha256HexPort), the stable-sort
9
+ * law, the TTL/cap constants, and the prune decision as a pure function
10
+ * over an entries array + a clock reading.
11
+ */
12
+ import type { Sha256HexPort } from '../ports.js';
13
+ /** `agentLaunchEnvelopeCache.ts:4` — a warmed envelope lives 10 minutes. */
14
+ export declare const ENVELOPE_TTL_MS: number;
15
+ /** `agentLaunchEnvelopeCache.ts:5` — at most 200 envelopes; overflow evicts oldest-prepared. */
16
+ export declare const MAX_ENVELOPES = 200;
17
+ /**
18
+ * Cached-entry shape — `agentLaunchEnvelopeCache.ts:7-15`. The UI types
19
+ * `envelope` as `PreparedLaunchEnvelope` (a Next-server type); the SDK
20
+ * carries it opaquely.
21
+ */
22
+ export type CachedAgentLaunchEnvelope = {
23
+ id: string;
24
+ userId: string;
25
+ fingerprint: string;
26
+ preparedAt: number;
27
+ expiresAt: number;
28
+ prepareMs: number;
29
+ envelope: unknown;
30
+ };
31
+ /**
32
+ * The subset of the raw `/api/agent-stream` body the fingerprint reads —
33
+ * field types as in `prepareAgentStreamPayload.ts:81-114`
34
+ * (`RawAgentStreamBody`); only the fingerprinted fields are mirrored.
35
+ */
36
+ export type LaunchEnvelopeFingerprintInput = {
37
+ chatInput?: unknown;
38
+ modelId?: string;
39
+ harness?: string;
40
+ authMethod?: string;
41
+ mcpAppIds?: string[];
42
+ systemPrompt?: string;
43
+ modelSettings?: unknown;
44
+ chatPayloadId?: string;
45
+ chatPayloadRevision?: string;
46
+ chatPayloadComputerId?: string;
47
+ cloudWorkspaceRef?: unknown;
48
+ };
49
+ /**
50
+ * Stable-sort law — `agentLaunchEnvelopeCache.ts:28-37`. Recursively
51
+ * rebuilds objects with sorted keys so `JSON.stringify` is deterministic.
52
+ * (Unlike `stableJson` in payload.ts this keeps `undefined` values as
53
+ * object entries — the fingerprint input `?? null`s every field first, so
54
+ * the difference never surfaces there.)
55
+ */
56
+ export declare function stableValue(value: unknown): unknown;
57
+ /**
58
+ * Fingerprint law — `agentLaunchEnvelopeCache.ts:52-72`: sha256 hex over
59
+ * the JSON of the stable-sorted `(userId, chatInput, modelId, harness,
60
+ * authMethod, mcpAppIds, systemPrompt, modelSettings, chatPayloadId,
61
+ * chatPayloadRevision, chatPayloadComputerId, cloudWorkspaceRef)` tuple,
62
+ * every absent field coerced to null. The UI calls
63
+ * `crypto.createHash('sha256')...digest('hex')`; the host injects the
64
+ * equivalent as `sha256Hex`.
65
+ */
66
+ export declare function fingerprintLaunchEnvelopeInput(userId: string, body: LaunchEnvelopeFingerprintInput, sha256Hex: Sha256HexPort): string;
67
+ /** Expiry law — `agentLaunchEnvelopeCache.ts:88`: expiresAt = preparedAt + TTL. */
68
+ export declare function envelopeExpiresAt(preparedAtMs: number): number;
69
+ /**
70
+ * Prune law — `agentLaunchEnvelopeCache.ts:39-50`, as a pure function:
71
+ * drop every entry with `expiresAt <= now`; then, if still over the cap,
72
+ * evict the oldest by `preparedAt` until exactly `MAX_ENVELOPES` remain.
73
+ * Returns the ids to delete; the host applies them to its Map.
74
+ */
75
+ export declare function pruneAgentLaunchEnvelopes(entries: readonly CachedAgentLaunchEnvelope[], nowMs: number): {
76
+ expiredIds: string[];
77
+ overflowIds: string[];
78
+ };
79
+ //# sourceMappingURL=envelope-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope-cache.d.ts","sourceRoot":"","sources":["../../src/warm/envelope-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,4EAA4E;AAC5E,eAAO,MAAM,eAAe,QAAiB,CAAC;AAC9C,gGAAgG;AAChG,eAAO,MAAM,aAAa,MAAM,CAAC;AAEjC;;;;GAIG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CASnD;AAED;;;;;;;;GAQG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,8BAA8B,EACpC,SAAS,EAAE,aAAa,GACvB,MAAM,CAiBR;AAED,mFAAmF;AACnF,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAE9D;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,SAAS,yBAAyB,EAAE,EAC7C,KAAK,EAAE,MAAM,GACZ;IAAE,UAAU,EAAE,MAAM,EAAE,CAAC;IAAC,WAAW,EAAE,MAAM,EAAE,CAAA;CAAE,CAajD"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Server-side launch-envelope cache policy — the pure laws of
3
+ * `amalgm-ui/lib/server/agentLaunchEnvelopeCache.ts` (Layer B in
4
+ * docs/warm-payloads.md).
5
+ *
6
+ * The `globalThis` Map itself, `crypto.randomUUID` id minting, and the
7
+ * store/get functions are host effects — this module exports the
8
+ * fingerprint law (sha256 injected via Sha256HexPort), the stable-sort
9
+ * law, the TTL/cap constants, and the prune decision as a pure function
10
+ * over an entries array + a clock reading.
11
+ */
12
+ /** `agentLaunchEnvelopeCache.ts:4` — a warmed envelope lives 10 minutes. */
13
+ export const ENVELOPE_TTL_MS = 10 * 60 * 1000;
14
+ /** `agentLaunchEnvelopeCache.ts:5` — at most 200 envelopes; overflow evicts oldest-prepared. */
15
+ export const MAX_ENVELOPES = 200;
16
+ /**
17
+ * Stable-sort law — `agentLaunchEnvelopeCache.ts:28-37`. Recursively
18
+ * rebuilds objects with sorted keys so `JSON.stringify` is deterministic.
19
+ * (Unlike `stableJson` in payload.ts this keeps `undefined` values as
20
+ * object entries — the fingerprint input `?? null`s every field first, so
21
+ * the difference never surfaces there.)
22
+ */
23
+ export function stableValue(value) {
24
+ if (Array.isArray(value))
25
+ return value.map(stableValue);
26
+ if (!value || typeof value !== 'object')
27
+ return value;
28
+ const input = value;
29
+ return Object.fromEntries(Object.keys(input)
30
+ .sort()
31
+ .map((key) => [key, stableValue(input[key])]));
32
+ }
33
+ /**
34
+ * Fingerprint law — `agentLaunchEnvelopeCache.ts:52-72`: sha256 hex over
35
+ * the JSON of the stable-sorted `(userId, chatInput, modelId, harness,
36
+ * authMethod, mcpAppIds, systemPrompt, modelSettings, chatPayloadId,
37
+ * chatPayloadRevision, chatPayloadComputerId, cloudWorkspaceRef)` tuple,
38
+ * every absent field coerced to null. The UI calls
39
+ * `crypto.createHash('sha256')...digest('hex')`; the host injects the
40
+ * equivalent as `sha256Hex`.
41
+ */
42
+ export function fingerprintLaunchEnvelopeInput(userId, body, sha256Hex) {
43
+ const stableInput = stableValue({
44
+ userId,
45
+ chatInput: body.chatInput ?? null,
46
+ modelId: body.modelId ?? null,
47
+ harness: body.harness ?? null,
48
+ authMethod: body.authMethod ?? null,
49
+ mcpAppIds: body.mcpAppIds ?? null,
50
+ systemPrompt: body.systemPrompt ?? null,
51
+ modelSettings: body.modelSettings ?? null,
52
+ chatPayloadId: body.chatPayloadId ?? null,
53
+ chatPayloadRevision: body.chatPayloadRevision ?? null,
54
+ chatPayloadComputerId: body.chatPayloadComputerId ?? null,
55
+ cloudWorkspaceRef: body.cloudWorkspaceRef ?? null,
56
+ });
57
+ return sha256Hex(JSON.stringify(stableInput));
58
+ }
59
+ /** Expiry law — `agentLaunchEnvelopeCache.ts:88`: expiresAt = preparedAt + TTL. */
60
+ export function envelopeExpiresAt(preparedAtMs) {
61
+ return preparedAtMs + ENVELOPE_TTL_MS;
62
+ }
63
+ /**
64
+ * Prune law — `agentLaunchEnvelopeCache.ts:39-50`, as a pure function:
65
+ * drop every entry with `expiresAt <= now`; then, if still over the cap,
66
+ * evict the oldest by `preparedAt` until exactly `MAX_ENVELOPES` remain.
67
+ * Returns the ids to delete; the host applies them to its Map.
68
+ */
69
+ export function pruneAgentLaunchEnvelopes(entries, nowMs) {
70
+ const expiredIds = [];
71
+ const live = [];
72
+ for (const entry of entries) {
73
+ if (entry.expiresAt <= nowMs)
74
+ expiredIds.push(entry.id);
75
+ else
76
+ live.push(entry);
77
+ }
78
+ if (live.length <= MAX_ENVELOPES)
79
+ return { expiredIds, overflowIds: [] };
80
+ const oldest = live
81
+ .sort((a, b) => a.preparedAt - b.preparedAt)
82
+ .slice(0, live.length - MAX_ENVELOPES);
83
+ return { expiredIds, overflowIds: oldest.map((entry) => entry.id) };
84
+ }
85
+ //# sourceMappingURL=envelope-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelope-cache.js","sourceRoot":"","sources":["../../src/warm/envelope-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,4EAA4E;AAC5E,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAC9C,gGAAgG;AAChG,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAC;AAoCjC;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACxD,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACtD,MAAM,KAAK,GAAG,KAAgC,CAAC;IAC/C,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;SACf,IAAI,EAAE;SACN,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAChD,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,8BAA8B,CAC5C,MAAc,EACd,IAAoC,EACpC,SAAwB;IAExB,MAAM,WAAW,GAAG,WAAW,CAAC;QAC9B,MAAM;QACN,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,IAAI;QACjC,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,IAAI;QAC7B,OAAO,EAAE,IAAI,CAAC,OAAO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AAC,EAAE,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC,CAAC;IACzC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;AACtE,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @amalgm/chat — warm-payload laws (how "enter" costs nothing).
3
+ * Design doc: docs/warm-payloads.md. Pure laws only: publishing,
4
+ * SQLite, state events, and HTTP are host effects behind ports.
5
+ */
6
+ export type { HarnessId, AuthMethod, CliEffort, ModelCliSettings, CustomAgentLoadout, InstalledSkillSource, AgentConfigLoadout, AgentConfigSkill, AgentConfigHook, AgentConfigSubagent, AgentConfig, ChatPayloadAgentConfigSnapshot, ChatViewPayload, SessionStableChatViewPayload, LaunchEnvelopeRequest, } from './payload.js';
7
+ export { stableJson, getSessionStableChatViewPayload, mergeSessionStableChatViewPayload, buildLaunchEnvelopeRequest, } from './payload.js';
8
+ export type { MachineChatPayloadRecord, PendingMachinePayloadWrite, ConfirmedMachinePayloadWrite, MachinePayloadPublishDecision, } from './revision.js';
9
+ export { CONFIRMED_WRITE_TTL_MS, machinePayloadWriteKey, chatPayloadRevision, isConfirmedWriteFresh, machinePayloadPublishDecision, } from './revision.js';
10
+ export type { CachedAgentLaunchEnvelope, LaunchEnvelopeFingerprintInput, } from './envelope-cache.js';
11
+ export { ENVELOPE_TTL_MS, MAX_ENVELOPES, stableValue, fingerprintLaunchEnvelopeInput, envelopeExpiresAt, pruneAgentLaunchEnvelopes, } from './envelope-cache.js';
12
+ export type { LaunchEnvelopeCacheEntry } from './client-cache.js';
13
+ export { CACHE_WARM_DELAY_MS, machineKey, launchEnvelopeCacheKey, launchEnvelopePayloadKey, usableEntry, } from './client-cache.js';
14
+ export type { ChatPayloadStoreRecord } from './store-policy.js';
15
+ export { CHAT_PAYLOADS_META_KEY, CHAT_PAYLOADS_RESOURCE, CHAT_PAYLOAD_TTL_MS, CHAT_PAYLOAD_MAX_RECORDS, isPlainObject, cleanString, normalizeChatPayloadRecord, recordTimestamp, sweepChatPayloads, } from './store-policy.js';
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/warm/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EACV,SAAS,EACT,UAAU,EACV,SAAS,EACT,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,WAAW,EACX,8BAA8B,EAC9B,eAAe,EACf,4BAA4B,EAC5B,qBAAqB,GACtB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,UAAU,EACV,+BAA+B,EAC/B,iCAAiC,EACjC,0BAA0B,GAC3B,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,4BAA4B,EAC5B,6BAA6B,GAC9B,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,EACnB,qBAAqB,EACrB,6BAA6B,GAC9B,MAAM,eAAe,CAAC;AAEvB,YAAY,EACV,yBAAyB,EACzB,8BAA8B,GAC/B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,eAAe,EACf,aAAa,EACb,WAAW,EACX,8BAA8B,EAC9B,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAC;AAE7B,YAAY,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,sBAAsB,EACtB,wBAAwB,EACxB,WAAW,GACZ,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,EACnB,wBAAwB,EACxB,aAAa,EACb,WAAW,EACX,0BAA0B,EAC1B,eAAe,EACf,iBAAiB,GAClB,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @amalgm/chat — warm-payload laws (how "enter" costs nothing).
3
+ * Design doc: docs/warm-payloads.md. Pure laws only: publishing,
4
+ * SQLite, state events, and HTTP are host effects behind ports.
5
+ */
6
+ export { stableJson, getSessionStableChatViewPayload, mergeSessionStableChatViewPayload, buildLaunchEnvelopeRequest, } from './payload.js';
7
+ export { CONFIRMED_WRITE_TTL_MS, machinePayloadWriteKey, chatPayloadRevision, isConfirmedWriteFresh, machinePayloadPublishDecision, } from './revision.js';
8
+ export { ENVELOPE_TTL_MS, MAX_ENVELOPES, stableValue, fingerprintLaunchEnvelopeInput, envelopeExpiresAt, pruneAgentLaunchEnvelopes, } from './envelope-cache.js';
9
+ export { CACHE_WARM_DELAY_MS, machineKey, launchEnvelopeCacheKey, launchEnvelopePayloadKey, usableEntry, } from './client-cache.js';
10
+ export { CHAT_PAYLOADS_META_KEY, CHAT_PAYLOADS_RESOURCE, CHAT_PAYLOAD_TTL_MS, CHAT_PAYLOAD_MAX_RECORDS, isPlainObject, cleanString, normalizeChatPayloadRecord, recordTimestamp, sweepChatPayloads, } from './store-policy.js';
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/warm/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAmBH,OAAO,EACL,UAAU,EACV,+BAA+B,EAC/B,iCAAiC,EACjC,0BAA0B,GAC3B,MAAM,cAAc,CAAC;AAQtB,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,EACnB,qBAAqB,EACrB,6BAA6B,GAC9B,MAAM,eAAe,CAAC;AAMvB,OAAO,EACL,eAAe,EACf,aAAa,EACb,WAAW,EACX,8BAA8B,EAC9B,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,mBAAmB,EACnB,UAAU,EACV,sBAAsB,EACtB,wBAAwB,EACxB,WAAW,GACZ,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,EACnB,wBAAwB,EACxB,aAAa,EACb,WAAW,EACX,0BAA0B,EAC1B,eAAe,EACf,iBAAiB,GAClB,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Warm-payload shapes and the stable-JSON / session-freeze / envelope-request
3
+ * laws — `amalgm-ui/lib/chat/payload.ts`, ported byte-exact.
4
+ *
5
+ * Design doc: docs/warm-payloads.md (Layer A shape + freeze interaction).
6
+ *
7
+ * The UI file imports its field types from elsewhere in amalgm-ui; those
8
+ * types are mirrored here verbatim so the SDK stands alone:
9
+ * - `HarnessId`, `AuthMethod` — amalgm-ui/lib/harnesses.ts:26,30
10
+ * - `CliEffort`, `ModelCliSettings` — amalgm-ui/lib/modelSettings.ts:4-11
11
+ * - `CustomAgentLoadout` — amalgm-ui/lib/customAgents.ts:31-34
12
+ * - `InstalledSkillSource` — amalgm-ui/lib/skills/types.ts:1-12
13
+ * - `AgentConfig*` — amalgm-ui/lib/agent-config/types.ts:3-48
14
+ */
15
+ export type HarnessId = "claude_code" | "opencode" | "codex" | "pi" | "amp" | "cursor";
16
+ export type AuthMethod = "amalgm" | "byok" | "provider_auth";
17
+ export type CliEffort = 'low' | 'medium' | 'high' | 'xhigh' | 'max' | 'ultra';
18
+ export type ModelCliSettings = {
19
+ /** Canonical CLI/SDK effort value. Claude supports max; Codex stops at xhigh. */
20
+ effort?: CliEffort;
21
+ /** Harness-level faster inference toggle. Claude maps this to settings; Codex maps it to service tier. */
22
+ fastMode?: boolean;
23
+ };
24
+ export interface CustomAgentLoadout {
25
+ /** Toolbox tool IDs connected to this agent. */
26
+ toolIds: string[];
27
+ }
28
+ export type InstalledSkillSource = {
29
+ kind?: string;
30
+ provider?: string;
31
+ scope?: string;
32
+ rootLabel?: string;
33
+ path?: string;
34
+ directoryPath?: string;
35
+ resolvedPath?: string;
36
+ resolvedDirectoryPath?: string;
37
+ rootPath?: string;
38
+ viaSymlink?: boolean;
39
+ };
40
+ export type AgentConfigLoadout = {
41
+ toolIds: string[];
42
+ };
43
+ export type AgentConfigSkill = {
44
+ id: string;
45
+ name: string;
46
+ description?: string;
47
+ content?: string;
48
+ enabled?: boolean;
49
+ source?: InstalledSkillSource;
50
+ };
51
+ export type AgentConfigHook = {
52
+ id: string;
53
+ name: string;
54
+ enabled?: boolean;
55
+ event: string;
56
+ phase: string;
57
+ matcher?: string;
58
+ type: 'command' | string;
59
+ command?: string;
60
+ timeout?: number;
61
+ statusMessage?: string;
62
+ source?: Record<string, unknown>;
63
+ };
64
+ export type AgentConfigSubagent = {
65
+ id: string;
66
+ agentId: string;
67
+ name?: string;
68
+ description?: string;
69
+ enabled?: boolean;
70
+ source?: Record<string, unknown>;
71
+ };
72
+ export type AgentConfig = {
73
+ version: 1;
74
+ agentId?: string;
75
+ runtimeHomeLayout?: 'legacy' | 'per-agent';
76
+ instructions: string;
77
+ skills: AgentConfigSkill[];
78
+ loadout: AgentConfigLoadout;
79
+ hooks: AgentConfigHook[];
80
+ subagents: AgentConfigSubagent[];
81
+ };
82
+ export type ChatPayloadAgentConfigSnapshot = {
83
+ agentId: string;
84
+ revision: string;
85
+ config: AgentConfig;
86
+ compiledInstructions: string;
87
+ };
88
+ export type ChatViewPayload = {
89
+ machineId: string | null;
90
+ harness: string;
91
+ resolvedHarnessId: HarnessId;
92
+ modelId: string;
93
+ modelSettings: ModelCliSettings;
94
+ authMethod: AuthMethod;
95
+ cwd: string | null;
96
+ customAgentId: string | null;
97
+ systemPrompt: string | null;
98
+ agentConfigSnapshot?: ChatPayloadAgentConfigSnapshot | null;
99
+ mcpAppIds: string[];
100
+ loadout?: CustomAgentLoadout;
101
+ pendingWorktree: boolean;
102
+ };
103
+ export type SessionStableChatViewPayload = Pick<ChatViewPayload, 'machineId' | 'harness' | 'resolvedHarnessId' | 'authMethod' | 'cwd' | 'customAgentId' | 'systemPrompt' | 'agentConfigSnapshot'>;
104
+ export type LaunchEnvelopeRequest = {
105
+ chatPayloadId?: string | null;
106
+ chatPayloadRevision?: string | null;
107
+ chatInput: {
108
+ parts: [];
109
+ agent: {
110
+ harness: string;
111
+ model: string;
112
+ authMethod: AuthMethod;
113
+ customAgentId: string | null;
114
+ systemPrompt: string | null;
115
+ };
116
+ tools: {
117
+ mcpAppIds: string[];
118
+ toolIds: string[];
119
+ };
120
+ execution: {
121
+ cwd: string | null;
122
+ computerId: string | null;
123
+ };
124
+ };
125
+ modelSettings?: ModelCliSettings;
126
+ agentConfigId?: string;
127
+ agentConfig?: AgentConfig;
128
+ compiledAgentInstructions?: string;
129
+ };
130
+ export declare function stableJson(value: unknown): string;
131
+ export declare function getSessionStableChatViewPayload(payload: ChatViewPayload): SessionStableChatViewPayload;
132
+ export declare function mergeSessionStableChatViewPayload(payload: ChatViewPayload, sessionStablePayload?: SessionStableChatViewPayload | null): ChatViewPayload;
133
+ export declare function buildLaunchEnvelopeRequest(payload: ChatViewPayload, machinePayload?: {
134
+ payloadId?: string | null;
135
+ revision?: string | null;
136
+ }): LaunchEnvelopeRequest | null;
137
+ //# sourceMappingURL=payload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payload.d.ts","sourceRoot":"","sources":["../../src/warm/payload.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,MAAM,SAAS,GAAG,aAAa,GAAG,UAAU,GAAG,OAAO,GAAG,IAAI,GAAG,KAAK,GAAG,QAAQ,CAAC;AAEvF,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,MAAM,GAAG,eAAe,CAAC;AAE7D,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,OAAO,CAAC;AAE9E,MAAM,MAAM,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MAAM,CAEjD;AAED,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,eAAe,GACvB,4BAA4B,CAW9B;AAED,wBAAgB,iCAAiC,CAC/C,OAAO,EAAE,eAAe,EACxB,oBAAoB,CAAC,EAAE,4BAA4B,GAAG,IAAI,GACzD,eAAe,CAMjB;AAED,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,eAAe,EACxB,cAAc,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GACvE,qBAAqB,GAAG,IAAI,CAwD9B"}
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Warm-payload shapes and the stable-JSON / session-freeze / envelope-request
3
+ * laws — `amalgm-ui/lib/chat/payload.ts`, ported byte-exact.
4
+ *
5
+ * Design doc: docs/warm-payloads.md (Layer A shape + freeze interaction).
6
+ *
7
+ * The UI file imports its field types from elsewhere in amalgm-ui; those
8
+ * types are mirrored here verbatim so the SDK stands alone:
9
+ * - `HarnessId`, `AuthMethod` — amalgm-ui/lib/harnesses.ts:26,30
10
+ * - `CliEffort`, `ModelCliSettings` — amalgm-ui/lib/modelSettings.ts:4-11
11
+ * - `CustomAgentLoadout` — amalgm-ui/lib/customAgents.ts:31-34
12
+ * - `InstalledSkillSource` — amalgm-ui/lib/skills/types.ts:1-12
13
+ * - `AgentConfig*` — amalgm-ui/lib/agent-config/types.ts:3-48
14
+ */
15
+ function stableJsonValue(value, arrayItem = false) {
16
+ if (value === undefined || typeof value === 'function' || typeof value === 'symbol') {
17
+ return arrayItem ? 'null' : undefined;
18
+ }
19
+ if (Array.isArray(value)) {
20
+ return `[${value.map((item) => stableJsonValue(item, true) ?? 'null').join(',')}]`;
21
+ }
22
+ if (!value || typeof value !== 'object') {
23
+ return JSON.stringify(value);
24
+ }
25
+ const input = value;
26
+ return `{${Object.keys(input)
27
+ .sort()
28
+ .flatMap((key) => {
29
+ const serialized = stableJsonValue(input[key]);
30
+ return serialized === undefined ? [] : `${JSON.stringify(key)}:${serialized}`;
31
+ })
32
+ .join(',')}}`;
33
+ }
34
+ export function stableJson(value) {
35
+ return stableJsonValue(value) ?? 'null';
36
+ }
37
+ export function getSessionStableChatViewPayload(payload) {
38
+ return {
39
+ machineId: payload.machineId,
40
+ harness: payload.harness,
41
+ resolvedHarnessId: payload.resolvedHarnessId,
42
+ authMethod: payload.authMethod,
43
+ cwd: payload.cwd,
44
+ customAgentId: payload.customAgentId,
45
+ systemPrompt: payload.systemPrompt,
46
+ agentConfigSnapshot: payload.agentConfigSnapshot ?? null,
47
+ };
48
+ }
49
+ export function mergeSessionStableChatViewPayload(payload, sessionStablePayload) {
50
+ if (!sessionStablePayload)
51
+ return payload;
52
+ return {
53
+ ...payload,
54
+ ...sessionStablePayload,
55
+ };
56
+ }
57
+ export function buildLaunchEnvelopeRequest(payload, machinePayload) {
58
+ if (payload.pendingWorktree)
59
+ return null;
60
+ if (machinePayload?.payloadId) {
61
+ return {
62
+ chatPayloadId: machinePayload.payloadId,
63
+ chatPayloadRevision: machinePayload.revision ?? null,
64
+ chatInput: {
65
+ parts: [],
66
+ agent: {
67
+ harness: payload.harness,
68
+ model: payload.modelId,
69
+ authMethod: payload.authMethod,
70
+ customAgentId: payload.customAgentId,
71
+ systemPrompt: null,
72
+ },
73
+ tools: {
74
+ mcpAppIds: [],
75
+ toolIds: payload.loadout?.toolIds ?? [],
76
+ },
77
+ execution: {
78
+ cwd: null,
79
+ computerId: payload.machineId,
80
+ },
81
+ },
82
+ };
83
+ }
84
+ const agentConfigSnapshot = payload.agentConfigSnapshot ?? null;
85
+ return {
86
+ chatInput: {
87
+ parts: [],
88
+ agent: {
89
+ harness: payload.harness,
90
+ model: payload.modelId,
91
+ authMethod: payload.authMethod,
92
+ customAgentId: payload.customAgentId,
93
+ systemPrompt: payload.systemPrompt,
94
+ },
95
+ tools: {
96
+ mcpAppIds: payload.mcpAppIds,
97
+ toolIds: payload.loadout?.toolIds ?? [],
98
+ },
99
+ execution: {
100
+ cwd: payload.cwd,
101
+ computerId: payload.machineId,
102
+ },
103
+ },
104
+ modelSettings: payload.modelSettings,
105
+ ...(agentConfigSnapshot ? {
106
+ agentConfigId: agentConfigSnapshot.agentId,
107
+ agentConfig: agentConfigSnapshot.config,
108
+ compiledAgentInstructions: agentConfigSnapshot.compiledInstructions,
109
+ } : {}),
110
+ };
111
+ }
112
+ //# sourceMappingURL=payload.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payload.js","sourceRoot":"","sources":["../../src/warm/payload.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAgJH,SAAS,eAAe,CAAC,KAAc,EAAE,SAAS,GAAG,KAAK;IACxD,IAAI,KAAK,KAAK,SAAS,IAAI,OAAO,KAAK,KAAK,UAAU,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACpF,OAAO,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IACxC,CAAC;IAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IACrF,CAAC;IAED,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM,KAAK,GAAG,KAAgC,CAAC;IAC/C,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;SAC1B,IAAI,EAAE;SACN,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACf,MAAM,UAAU,GAAG,eAAe,CAAC,KAAK,CAAC,GAAG,CAAC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