@w6w/embed 0.2.11 → 0.2.20

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 (133) hide show
  1. package/README.md +22 -5
  2. package/dist/ConfirmModal-Pv2-A_3U.js +186 -0
  3. package/dist/ConfirmModal-Pv2-A_3U.js.map +1 -0
  4. package/dist/{CreateFunctionModal-D6CQLpa_.js → CreateFunctionModal-DScxp_LN.js} +2 -2
  5. package/dist/{CreateFunctionModal-D6CQLpa_.js.map → CreateFunctionModal-DScxp_LN.js.map} +1 -1
  6. package/dist/{DocumentFormModal-YauVdolr.js → DocumentFormModal-Br4s8wmi.js} +3 -3
  7. package/dist/{DocumentFormModal-YauVdolr.js.map → DocumentFormModal-Br4s8wmi.js.map} +1 -1
  8. package/dist/ImportSpecModal-Cpzp8ndt.js +251 -0
  9. package/dist/ImportSpecModal-Cpzp8ndt.js.map +1 -0
  10. package/dist/{ModelRoutesManager-BGESQahw.js → ModelRoutesManager-1Ac5wcas.js} +3 -3
  11. package/dist/{ModelRoutesManager-BGESQahw.js.map → ModelRoutesManager-1Ac5wcas.js.map} +1 -1
  12. package/dist/WorkflowEditor-CmhXHRxi.js +1109 -0
  13. package/dist/WorkflowEditor-CmhXHRxi.js.map +1 -0
  14. package/dist/apps-ItBvnWX3.js +92 -0
  15. package/dist/apps-ItBvnWX3.js.map +1 -0
  16. package/dist/chrome/DangerZone.d.ts +4 -3
  17. package/dist/chrome/ExecutionProfileHeader.d.ts +3 -3
  18. package/dist/chrome/JsonToggle.d.ts +29 -20
  19. package/dist/chrome/Modal.d.ts +3 -1
  20. package/dist/chrome/RightRail.d.ts +6 -1
  21. package/dist/chrome/VersionHistoryModal.d.ts +2 -0
  22. package/dist/chrome/index.d.ts +1 -0
  23. package/dist/chrome/workspace.d.ts +32 -1
  24. package/dist/{coerce-input-DttlcSdO.js → coerce-input-DFJ4n_wc.js} +68 -69
  25. package/dist/coerce-input-DFJ4n_wc.js.map +1 -0
  26. package/dist/{connections-D7cgXhDS.js → connections-CzsCyIxY.js} +10 -10
  27. package/dist/{connections-D7cgXhDS.js.map → connections-CzsCyIxY.js.map} +1 -1
  28. package/dist/{credentials-DaQU3Ca_.js → credentials-Cn92LGhJ.js} +4 -4
  29. package/dist/{credentials-DaQU3Ca_.js.map → credentials-Cn92LGhJ.js.map} +1 -1
  30. package/dist/data-stores-UeQvwVCa.js +170 -0
  31. package/dist/data-stores-UeQvwVCa.js.map +1 -0
  32. package/dist/document-sources-DNmBojx6.js +169 -0
  33. package/dist/document-sources-DNmBojx6.js.map +1 -0
  34. package/dist/draft/use-workflow-draft.d.ts +2 -0
  35. package/dist/draft.mjs +2 -2
  36. package/dist/editor/PublishTooltip.d.ts +7 -0
  37. package/dist/editor/SetupIncompleteBanner.d.ts +12 -0
  38. package/dist/editor/StartingStateModal.d.ts +14 -0
  39. package/dist/editor/WorkflowSettingsModal.d.ts +6 -1
  40. package/dist/editor/WorkflowVariablesEditor.d.ts +6 -0
  41. package/dist/editor/definition.d.ts +4 -0
  42. package/dist/editor/json-apply.d.ts +29 -0
  43. package/dist/editor/step-problems-feed.d.ts +5 -0
  44. package/dist/editor/types.d.ts +2 -2
  45. package/dist/editor-apps-DkkC7wOQ.js +152 -0
  46. package/dist/editor-apps-DkkC7wOQ.js.map +1 -0
  47. package/dist/editor-tools-BR27RGto.js +1683 -0
  48. package/dist/editor-tools-BR27RGto.js.map +1 -0
  49. package/dist/editor.mjs +1 -1
  50. package/dist/editors.mjs +536 -478
  51. package/dist/editors.mjs.map +1 -1
  52. package/dist/forms.mjs +3 -3
  53. package/dist/{rail-settings-XYGToh00.js → import-bindings-EUtxZ9Ti.js} +90 -24
  54. package/dist/import-bindings-EUtxZ9Ti.js.map +1 -0
  55. package/dist/index.mjs +138 -108
  56. package/dist/index.mjs.map +1 -1
  57. package/dist/lib/binding-problems.d.ts +5 -1
  58. package/dist/lib/history-query.d.ts +45 -0
  59. package/dist/lib/import-bindings.d.ts +89 -0
  60. package/dist/lib/index.d.ts +3 -0
  61. package/dist/lib/rail-settings.d.ts +1 -1
  62. package/dist/lib/setup-incomplete.d.ts +22 -0
  63. package/dist/lib/starting-data.d.ts +31 -0
  64. package/dist/lib/state-panel.d.ts +29 -0
  65. package/dist/lib/target-fields.d.ts +3 -15
  66. package/dist/lib/workflow-live-run.d.ts +84 -6
  67. package/dist/lib/workflow-validity.d.ts +64 -16
  68. package/dist/lib/workflow-variables.d.ts +1 -1
  69. package/dist/lib/workflow-version.d.ts +2 -0
  70. package/dist/lib.mjs +87 -72
  71. package/dist/lists/DataStoreList.d.ts +17 -0
  72. package/dist/lists/DataStoreView.d.ts +19 -0
  73. package/dist/lists/Logs.d.ts +19 -0
  74. package/dist/lists.d.ts +6 -0
  75. package/dist/lists.mjs +1255 -816
  76. package/dist/lists.mjs.map +1 -1
  77. package/dist/rail/ConnectionsTool.d.ts +2 -0
  78. package/dist/rail/HistoryTool.d.ts +2 -0
  79. package/dist/rail/StartingStateTool.d.ts +2 -0
  80. package/dist/rail/settings-sections.d.ts +4 -1
  81. package/dist/rail.mjs +1 -1
  82. package/dist/repos/connections.d.ts +1 -0
  83. package/dist/repos/constants.d.ts +12 -0
  84. package/dist/repos/data-stores.d.ts +84 -0
  85. package/dist/repos/history.d.ts +9 -0
  86. package/dist/repos/index.d.ts +2 -0
  87. package/dist/repos/spec-export.d.ts +3 -3
  88. package/dist/repos/spec-import.d.ts +30 -1
  89. package/dist/repos/step-tests.d.ts +2 -0
  90. package/dist/repos/webhook-listen.d.ts +35 -0
  91. package/dist/repos/workflows.d.ts +105 -2
  92. package/dist/repos.mjs +370 -328
  93. package/dist/repos.mjs.map +1 -1
  94. package/dist/setup-incomplete-BHs3Lpfy.js +199 -0
  95. package/dist/setup-incomplete-BHs3Lpfy.js.map +1 -0
  96. package/dist/{spec-export-CBbloO_n.js → spec-export-DGy5ijps.js} +72 -59
  97. package/dist/spec-export-DGy5ijps.js.map +1 -0
  98. package/dist/spec-import-SWOonsNr.js +116 -0
  99. package/dist/spec-import-SWOonsNr.js.map +1 -0
  100. package/dist/{step-tests-CivICmTq.js → step-tests-B4E4W3ly.js} +8 -7
  101. package/dist/step-tests-B4E4W3ly.js.map +1 -0
  102. package/dist/{use-callable-draft-DsALnSfF.js → use-callable-draft-DCauHt5o.js} +2 -2
  103. package/dist/{use-callable-draft-DsALnSfF.js.map → use-callable-draft-DCauHt5o.js.map} +1 -1
  104. package/dist/use-workflow-draft-l3P5KZzw.js +338 -0
  105. package/dist/use-workflow-draft-l3P5KZzw.js.map +1 -0
  106. package/dist/workflows-BZN4Hyz1.js +623 -0
  107. package/dist/workflows-BZN4Hyz1.js.map +1 -0
  108. package/package.json +4 -3
  109. package/src/styles.css +153 -1
  110. package/dist/ConfirmModal-BE-SdX-O.js +0 -185
  111. package/dist/ConfirmModal-BE-SdX-O.js.map +0 -1
  112. package/dist/ImportSpecModal-B7qd1Km2.js +0 -136
  113. package/dist/ImportSpecModal-B7qd1Km2.js.map +0 -1
  114. package/dist/WorkflowEditor-CwvmAGp2.js +0 -925
  115. package/dist/WorkflowEditor-CwvmAGp2.js.map +0 -1
  116. package/dist/apps-CboASBKr.js +0 -77
  117. package/dist/apps-CboASBKr.js.map +0 -1
  118. package/dist/coerce-input-DttlcSdO.js.map +0 -1
  119. package/dist/document-sources-UCwe8x77.js +0 -91
  120. package/dist/document-sources-UCwe8x77.js.map +0 -1
  121. package/dist/editor-apps-BUZWld-m.js +0 -95
  122. package/dist/editor-apps-BUZWld-m.js.map +0 -1
  123. package/dist/editor-tools-B_Lfx3kw.js +0 -1279
  124. package/dist/editor-tools-B_Lfx3kw.js.map +0 -1
  125. package/dist/rail-settings-XYGToh00.js.map +0 -1
  126. package/dist/spec-export-CBbloO_n.js.map +0 -1
  127. package/dist/spec-import-CW6R_Wk1.js +0 -469
  128. package/dist/spec-import-CW6R_Wk1.js.map +0 -1
  129. package/dist/step-tests-CivICmTq.js.map +0 -1
  130. package/dist/trigger-preview-DKxfjzUY.js +0 -145
  131. package/dist/trigger-preview-DKxfjzUY.js.map +0 -1
  132. package/dist/use-workflow-draft-DzAyUeA6.js +0 -316
  133. package/dist/use-workflow-draft-DzAyUeA6.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-workflow-draft-l3P5KZzw.js","sources":["../src/draft/autosave.ts","../src/draft/autosave-flush.ts","../src/draft/workflow-save.ts","../src/draft/use-workflow-draft.ts"],"sourcesContent":["/**\n * The debouncing, coalescing, payload-deduplicated saver behind auto-save.\n *\n * ## Why this exists at all\n *\n * Every edit on the canvas replaces the whole definition: a single keystroke in a\n * step's param form travels `ParamsForm onChange → commit → StepEditModal onChange\n * → updateStep → emitChange → onChange(flowToWorkflow(…))` and lands in\n * `WorkflowsPage` as `setJson(JSON.stringify(next, null, 2))`. So a naive\n * `useEffect(() => save(), [json])` is **one `POST /workflows` per character\n * typed**. This module is the thing that stands between those two facts.\n *\n * ## The rule\n *\n * **Trailing debounce, single pending entry, decided at fire time.**\n *\n * - `push` never writes. It replaces the one pending entry and restarts a\n * `delayMs` window. N pushes inside one window therefore produce exactly ONE\n * `save`, carrying the LAST payload.\n * - The decision to save is taken when the timer fires, not when the payload was\n * pushed. That is what makes a transiently-invalid edit harmless: while the JSON\n * modal round-trips text through `JsonEditor`, `canSave` flickers false\n * mid-typing, and a push-time decision would discard the save the author is\n * waiting for. An invalid push still re-arms the window; the next valid one wins.\n * - A payload equal to the last saved one is dropped without a request. The\n * comparison is on the serialised JSON **text**, the same structural-equality\n * dirty signal the house already uses (`packages/ui/src/ActionTestForm.tsx`,\n * *\"Compared by structural JSON so a load→edit→revert cycle clears it\"*), which\n * is why an in-place mutation of some nested object can never fool it: nothing\n * here holds a reference to a live object across ticks.\n *\n * Deliberately absent: retry/backoff. On a failed save the host stops and shows\n * the existing error surface; a background retry against a server that just\n * refused is worse than a visible failure (and, with a stale-write conflict on\n * screen, it would retry into the dialog the author is reading).\n *\n * It lives here rather than in `@w6w/ui` because `@w6w/ui` owns no workflow write\n * at all — the canvas emits `onChange`, the host decides when to persist — and in\n * a plain `.ts` module rather than in `WorkflowsPage.tsx` so it is executable:\n * that file is JSX, which Node 24's type-stripping cannot parse, so nothing in it\n * can be loaded by `node --test`. Same shape as `workflow-save.ts`.\n */\n\n/** The debounce window. One quiet beat after the last keystroke, not per keystroke. */\nexport const AUTOSAVE_DEBOUNCE_MS = 1200;\n\nexport interface AutoSaverOpts {\n /** May return a promise (awaited by `flush`); any other return value is ignored. */\n save: (payload: string, ctx?: unknown) => unknown;\n delayMs?: number;\n /** Injectable for tests; defaults to the globals. */\n setTimer?: (fn: () => void, ms: number) => number;\n clearTimer?: (handle: number) => void;\n}\n\nexport interface AutoSaver {\n /** Consider a payload. (Re)starts the debounce window. */\n push(payload: string, enabled: boolean, canSave: boolean, ctx?: unknown): void;\n /**\n * Fire the pending save now (the Save button). Resolves after the fired save settles\n * (`Promise.resolve()` when nothing fired); rejects if the fired save rejects.\n */\n flush(): Promise<void>;\n /** Drop any pending save without firing (unmount / workflow switch / stale conflict). */\n cancel(): void;\n /** This payload is now on the server. */\n markSaved(payload: string): void;\n /** Does `payload` diverge from the last-saved one? */\n isDirty(payload: string): boolean;\n}\n\n/** The single pending entry — a later `push` overwrites it rather than queueing. */\ninterface Pending {\n payload: string;\n enabled: boolean;\n canSave: boolean;\n /** Caller context captured at push time and handed to `save` at fire time. */\n ctx?: unknown;\n}\n\nexport function createAutoSaver(opts: AutoSaverOpts): AutoSaver {\n const delayMs = opts.delayMs ?? AUTOSAVE_DEBOUNCE_MS;\n const setTimer =\n opts.setTimer ?? ((fn: () => void, ms: number) => setTimeout(fn, ms) as unknown as number);\n const clearTimer = opts.clearTimer ?? ((handle: number) => clearTimeout(handle));\n\n let pending: Pending | null = null;\n let handle: number | null = null;\n let lastSaved: string | null = null;\n\n /** Disarm the window without touching the pending entry. */\n function disarm(): void {\n if (handle !== null) {\n clearTimer(handle);\n handle = null;\n }\n }\n\n /**\n * The window elapsed (or was flushed). Re-read the pending entry and decide\n * NOW — see the fire-time rule above. Either way the entry is consumed, so a\n * dropped save never lingers to fire later on its own.\n */\n function fire(): Promise<void> {\n handle = null;\n const entry = pending;\n pending = null;\n if (!entry) return Promise.resolve();\n if (!entry.enabled) return Promise.resolve();\n if (!entry.canSave) return Promise.resolve();\n if (entry.payload === lastSaved) return Promise.resolve();\n // A synchronous throw from `save` stays synchronous, as before; a returned promise is\n // awaited by `flush` only. The timer path ignores it (the host owns its own error surface).\n const result = opts.save(entry.payload, entry.ctx) as void | Promise<void>;\n return Promise.resolve(result);\n }\n\n return {\n push(payload: string, enabled: boolean, canSave: boolean, ctx?: unknown): void {\n pending = { payload, enabled, canSave, ctx };\n disarm();\n handle = setTimer(() => {\n // The timer path has no caller to receive a rejection; `save` owns its error surface.\n void fire().catch(() => {});\n }, delayMs);\n },\n flush(): Promise<void> {\n disarm();\n return fire();\n },\n cancel(): void {\n disarm();\n pending = null;\n },\n markSaved(payload: string): void {\n lastSaved = payload;\n },\n isDirty(payload: string): boolean {\n return payload !== lastSaved;\n },\n };\n}\n","/**\n * Flush a pending debounced write before the page actually goes away.\n *\n * ## Why this exists at all\n *\n * `autosave.ts`'s `createAutoSaver` coalesces edits behind an `AUTOSAVE_DEBOUNCE_MS`\n * (1200ms) window timer (`autosave.ts:45`) — a `push()` inside that window never writes,\n * it only re-arms the timer. Nothing in `autosave.ts` itself ever\n * flushes on navigation, so a canvas pan (or any other edit) that lands less than the\n * window's width before a refresh is lost: the tab is gone before the timer fires (I-3).\n * A zoom gesture \"works\" only by accident — it takes longer than the window to finish.\n *\n * This module does not touch the debounce, the `AutoSaver` interface, or its save\n * decision (`fire()`'s `enabled`/`canSave`/dedup checks in `autosave.ts:98-107` already\n * apply to a flush exactly as they do to a natural fire) — it only decides WHEN to call\n * the `flush()` the caller already owns.\n *\n * ## The rule\n *\n * Two signals, both wired here, neither replacing the other:\n *\n * - `visibilitychange` with `document.visibilityState === \"hidden\"` is the PRIMARY path.\n * It fires on tab close, tab switch, and navigation alike, and — unlike `beforeunload`\n * — a listener registered on it is not itself a signal to the browser that the page is\n * unusual, so it carries no risk of suppressing the back/forward cache.\n * - `beforeunload` is the BELT, wired unconditionally (it does not check\n * `visibilityState`): some navigations do not reliably fire `visibilitychange` first in\n * every browser, so this is a second chance at the same flush.\n *\n * **Known, accepted limit — do not claim this race is provably closed.** A `fetch`\n * kicked off from either handler is not guaranteed to complete before the browser\n * actually tears the page down (`beforeunload` in particular has no such guarantee in\n * every browser). `visibilitychange`+`hidden` fires earlier in the common\n * switch-tab/navigate-away cases, which is why it is the primary path and `beforeunload`\n * only the belt — this module narrows the loss window, it does not eliminate it.\n *\n * ## Why the parameters are typed the way they are\n *\n * `WindowLike`/`DocumentLike` below name only the handful of members this module\n * actually calls. That is what lets `node --test` — which cannot load `.tsx`, the same\n * reason `autosave.ts` itself lives in a plain `.ts` module (`autosave.ts:37-41`) — pass\n * a plain fake object in tests, while `tsc -b --noEmit` still proves the real\n * `window`/`document` satisfy the same shape at the call site in `WorkflowsPage.tsx`.\n */\n\n/** The subset of `Window` this module needs: register/unregister `beforeunload`. */\nexport interface WindowLike {\n addEventListener(type: \"beforeunload\", listener: () => void): void;\n removeEventListener(type: \"beforeunload\", listener: () => void): void;\n}\n\n/**\n * The subset of `Document` this module needs: register/unregister `visibilitychange`,\n * and read the visibility state the moment the event fires.\n */\nexport interface DocumentLike {\n readonly visibilityState: string;\n addEventListener(type: \"visibilitychange\", listener: () => void): void;\n removeEventListener(type: \"visibilitychange\", listener: () => void): void;\n}\n\n/**\n * Register both listeners; call `flush` when the page is going away. Returns a cleanup\n * that removes both — callers wire this straight into a `useEffect`'s return.\n */\nexport function registerFlushOnHide(\n windowTarget: WindowLike,\n documentTarget: DocumentLike,\n flush: () => void,\n): () => void {\n const onBeforeUnload = () => {\n flush();\n };\n const onVisibilityChange = () => {\n if (documentTarget.visibilityState === \"hidden\") {\n flush();\n }\n };\n\n windowTarget.addEventListener(\"beforeunload\", onBeforeUnload);\n documentTarget.addEventListener(\"visibilitychange\", onVisibilityChange);\n\n return () => {\n windowTarget.removeEventListener(\"beforeunload\", onBeforeUnload);\n documentTarget.removeEventListener(\"visibilitychange\", onVisibilityChange);\n };\n}\n","/**\n * The two decisions behind the workflow save precondition (optimistic\n * concurrency; server half in `packages/server` `packages/api/workflows.ts`).\n *\n * `POST /workflows` accepts an optional `x-w6w-if-unmodified-since` header\n * carrying the exact ISO-8601 `updatedAt` the client last saw. If the stored row\n * has moved on, the save is refused with **409 `workflow_stale`** instead of\n * silently overwriting whoever saved in between.\n *\n * Both functions here are pure functions of their inputs, and they live in a\n * `.ts` module rather than in `WorkflowsPage.tsx` so they are executable:\n * `WorkflowsPage.tsx` is JSX, which Node 24's type-stripping cannot parse, so\n * nothing in it can be loaded by `node --test`. Same shape as\n * `src/lib/sdk-snippets.ts` + its `.test.ts`.\n */\n/**\n * Is this the one save failure an author can fix by reloading?\n *\n * Keyed on the error **code**, never on the HTTP status. The server answers 409\n * for two completely different situations and only one of them is recoverable:\n *\n * - `workflow_stale` — your copy is out of date. Reload and re-save. ← this one\n * - `workflow_conflict` — another `(tenant, subject)` owns that workflow id.\n * Reloading changes nothing; offering a reload here would be a dead end.\n *\n * The same precondition guards Function and Endpoint saves, answered with `function_stale` /\n * `endpoint_stale`; all three are the recoverable \"your copy is out of date\" verdict.\n *\n * Anything that carries no `code` (a thrown `TypeError`, a string, `null`) is\n * not a server verdict at all, so it is not a stale write either.\n *\n * Duck-typed on the `code` property rather than `instanceof ApiError`: this module is\n * headless and must not value-import the SDK, and two SDK copies would defeat `instanceof`.\n */\nexport function isStaleWrite(e: unknown): boolean {\n if (typeof e !== \"object\" || e === null) return false;\n const code = (e as { code?: unknown }).code;\n return code === \"workflow_stale\" || code === \"function_stale\" || code === \"endpoint_stale\";\n}\n\n/**\n * The precondition token to send with the NEXT save, given the token we sent\n * with this one and the response that came back.\n *\n * The server rides `updatedAt` on both the `GET /workflows/:id` body and the\n * `POST /workflows` 201, precisely so a client can advance without a re-GET.\n *\n * When the response carries no usable `updatedAt`, the answer is **`null`** (no\n * precondition on the next save), never `prev`: `prev` is by then a value the\n * server may already have moved past, so resending it would 409 forever with no\n * way out. Dropping the guard for one save is the weaker failure — it is exactly\n * the pre-existing last-write-wins behaviour, which the header is optional for.\n */\nexport function nextSaveToken(prev: string | null, res: { updatedAt?: unknown }): string | null {\n if (typeof res.updatedAt === \"string\") return res.updatedAt;\n // `prev` is deliberately dropped here — see above.\n void prev;\n return null;\n}\n","/**\n * `useWorkflowDraft` — the headless draft lifecycle behind the workflow editor: load, a JSON text\n * buffer, syntax validity plus injected guards, SERIALIZED conditional saves behind a debounced\n * auto-save, flush on hide / unmount / workflow switch, an awaited flush before an action, and a\n * 409 that is surfaced and never retried. Lifted from Studio's `WorkflowsPage` (load effect,\n * `saveCallbacks`, `reloadFromServer`, `onSave`, `autoSaveNow` + push effect), minus the UI.\n *\n * ## The trust boundary (why the state is per ROW, not per hook)\n *\n * A pending save must write into the account / project / workflow that PRODUCED the edit, even if\n * the host has since swapped its client (token rotation, account switch) or moved to another\n * workflow. Two mechanisms hold that:\n *\n * - The AUTHORING context belongs to the buffer. Each row holds `{client, project}` — set when the\n * buffer is loaded — and EVERY save path (debounce, re-push after a guard flip, `flush`,\n * `flushThen`, unmount, registry, hide) sends with it, never with the current render's values.\n * When the render's client or project stops matching it, the row hands over: one save of a dirty\n * buffer with the authoring context, then (saved or not) the buffer is discarded and reloaded\n * under the new context. `canSave` is false and pushes are ignored meanwhile, so no save is ever\n * issued with the new context for text authored under the old one.\n * - One `Row` (its own saver, buffer, token, in-flight promise) per `workflowId`. Switching rows\n * flushes the old row's pending entry into the old row, and a late completion of that save\n * updates the OLD row object — it can never move the new row's token or clean marker.\n *\n * `project` is required to save: with none, the save is refused (`saveBlockedReason`), the buffer\n * is kept and no request is sent. It is always passed explicitly to the SDK — never the client's\n * `config.project` fallback, and never the account default (a projectless update would silently\n * MOVE the row).\n *\n * Deliberately absent: retry, a save queue. A save in flight disables the next one; the edit made\n * meanwhile is pushed again when the first settles, carrying the token that save returned. The one\n * exception is the context handover above: it sends a dirty buffer once more into the OLD account\n * (even if the save that just failed carried the same bytes), and never into the new one.\n */\nimport { useQueryClient } from \"@tanstack/react-query\";\nimport type { W6WClient, WorkflowDefinition } from \"@w6w/sdk\";\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { registerFlushOnHide } from \"./autosave-flush.ts\";\nimport { type AutoSaver, createAutoSaver } from \"./autosave.ts\";\nimport { useEmbedClient } from \"./client-context.ts\";\nimport { useDraftRegistry } from \"./draft-registry.ts\";\nimport { isStaleWrite, nextSaveToken } from \"./workflow-save.ts\";\n\nexport type FlushOutcome =\n | { status: \"clean\" }\n | { status: \"saved\" }\n | { status: \"blocked\"; reason: string }\n | { status: \"failed\"; error: unknown };\n\nexport interface UseWorkflowDraftOptions {\n /** `null` ⇒ idle (the hook stays mounted above an early return). */\n workflowId: string | null;\n /** REQUIRED to save; empty/absent ⇒ the save is refused and no request is sent. */\n project: string | null | undefined;\n /** Default true; a debounced save follows the last edit. */\n autoSave?: boolean;\n /** Injected busy probe (Studio: expression modal open). Gates AUTOMATIC saves only. */\n canAutoSave?: () => boolean;\n /** Injected key-edit guard: a reason blocks saving. */\n saveGuard?: (parsed: unknown) => string | null;\n /** Injected (B/D-3): reported as `publishBlockedReason`, not enforced by save. */\n publishBlockedReason?: (parsed: unknown) => string | null;\n /**\n * Called exactly once when a handover (client/project change) or an identity switch\n * (`flushAll`) drops a dirty buffer it could not save. `blocked`: the save was refused before a\n * request (invalid text, no project, a guard, busy); `failed`: the request was sent or the row\n * was stale and the save did not succeed. No UI here: the host decides what to show.\n */\n onDiscard?: (info: { workflowId: string; text: string; reason: \"blocked\" | \"failed\" }) => void;\n}\n\nexport interface WorkflowDraft {\n json: string;\n setJson(next: string): void;\n parsed: unknown | null;\n syntaxError: string | null;\n loading: boolean;\n loadError: unknown | null;\n dirty: boolean;\n saving: boolean;\n canSave: boolean;\n saveBlockedReason: string | null;\n stale: boolean;\n error: unknown | null;\n publishBlockedReason: string | null;\n /** Push + fire now (Ctrl/Cmd+S, the Save button). */\n saveNow(): void;\n flush(): Promise<FlushOutcome>;\n /** Flush, then run `action` only when the buffer is clean or just saved. */\n flushThen<T>(\n action: () => Promise<T>,\n ): Promise<{ ok: true; value: T } | { ok: false; outcome: FlushOutcome }>;\n /** `setJson(next)` + an immediate save (the saveMeta / onPolicyChange paths). */\n commit(next: string): Promise<FlushOutcome>;\n /** 409 recovery: GET, replace the buffer and token, clear `stale`. */\n reload(): Promise<void>;\n /** Stop pending saves, drain an in-flight save, replace the server draft, then reload. */\n discardThen(action: () => Promise<unknown>): Promise<void>;\n}\n\n/** What a pending entry carries from push time to fire time. */\ninterface SaveCtx {\n client: W6WClient;\n project: string | null | undefined;\n id: string;\n token: string | null;\n /** Explicit (button / flushThen) saves ignore the busy probe; automatic ones honour it. */\n explicit: boolean;\n}\n\n/** Everything that belongs to ONE workflow id's draft. */\ninterface Row {\n id: string;\n /** The buffer text; the row keeps its final text after the hook has moved on. */\n text: string;\n token: string | null;\n loaded: boolean;\n stale: boolean;\n /** Bytes the server refused — auto-save must not re-push them. */\n refused: string | null;\n lastError: unknown;\n inflight: Promise<void> | null;\n saver: AutoSaver;\n /** Who this buffer was loaded as (the context every save of it is sent with). */\n auth: AuthCtx | null;\n /** A context change is being settled (save with `auth`, then reload); pushes are ignored. */\n handover: boolean;\n replacing: boolean;\n /**\n * Bumped whenever the buffer is replaced by a fresh read (the handover, `reload()`). A save\n * remembers the generation it started in; a completion from an older one describes a buffer that\n * is gone and must not touch the new one's token, clean marker or error.\n */\n gen: number;\n /** The `gen` whose dirty buffer was already reported through `onDiscard` (at most once each). */\n discardReported: number;\n}\n\ninterface AuthCtx {\n client: W6WClient;\n project: string | null | undefined;\n}\n\n/**\n * Does the render context differ from the one the buffer was authored in? A buffer loaded before\n * any project existed (so it could never be saved) is not in conflict with the same client gaining\n * one: nothing was authored under a project, and no account changes.\n */\nfunction ctxDiffers(a: AuthCtx | null, client: W6WClient, project: string | null | undefined) {\n if (!a) return false;\n if (a.client !== client) return true;\n return (a.project || null) !== (project || null) && !!a.project;\n}\n\ninterface Evaluation {\n parsed: unknown | null;\n syntaxError: string | null;\n /** Why this text cannot be saved right now, or `null`. */\n blocked: string | null;\n}\n\nconst NO_PROJECT = \"No project selected: a workflow can only be saved into a project.\";\n\nfunction evaluate(\n text: string,\n id: string,\n project: string | null | undefined,\n saveGuard: UseWorkflowDraftOptions[\"saveGuard\"],\n): Evaluation {\n let parsed: unknown | null = null;\n let syntaxError: string | null = null;\n try {\n parsed = JSON.parse(text);\n } catch (e) {\n syntaxError = e instanceof Error ? e.message : String(e);\n }\n let blocked: string | null = null;\n if (!project) blocked = NO_PROJECT;\n else if (syntaxError !== null) blocked = `Invalid JSON: ${syntaxError}`;\n else if (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n blocked = \"A workflow definition must be a JSON object.\";\n } else if (\n typeof (parsed as { id?: unknown }).id === \"string\" &&\n (parsed as { id: string }).id !== id\n ) {\n // `update(id, def)` writes `def` under `id`; a different id in the text would be saved under\n // the original id yet read as saved. Refuse rather than write somewhere the author did not mean.\n blocked = \"The workflow id cannot be changed here.\";\n } else if (saveGuard) blocked = saveGuard(parsed) ?? null;\n return { parsed, syntaxError, blocked };\n}\n\nexport function useWorkflowDraft(o: UseWorkflowDraftOptions): WorkflowDraft {\n const client = useEmbedClient();\n const registry = useDraftRegistry();\n const qc = useQueryClient();\n const { workflowId } = o;\n const { project, saveGuard } = o;\n const autoSave = o.autoSave ?? true;\n\n const [json, setJsonState] = useState(\"\");\n const [loadedId, setLoadedId] = useState<string | null>(null);\n const [loadError, setLoadError] = useState<unknown | null>(null);\n const [saving, setSaving] = useState(false);\n const [stale, setStale] = useState(false);\n const [error, setError] = useState<unknown | null>(null);\n const [handingOver, setHandingOver] = useState(false);\n\n // Latest-value refs: stable callbacks read these, never a captured render.\n const optsRef = useRef(o);\n optsRef.current = o;\n const clientRef = useRef(client);\n clientRef.current = client;\n const qcRef = useRef(qc);\n qcRef.current = qc;\n const rowRef = useRef<Row | null>(null);\n // The key-edit guard of the context that authored the buffer: a handover save is judged by the\n // guard in force when the text was written, not by one that arrived with the new context.\n const guardRef = useRef(saveGuard);\n\n // One row per workflow id, created during render so `dirty` is answerable on the first paint.\n // Nothing in a fresh row starts a timer or a request, so a discarded render leaks nothing.\n if (workflowId === null) rowRef.current = null;\n else if (rowRef.current?.id !== workflowId) {\n const row: Row = {\n id: workflowId,\n text: \"\",\n token: null, // a token from another row would 409 against this one\n loaded: false,\n stale: false,\n refused: null,\n lastError: null,\n inflight: null,\n saver: undefined as unknown as AutoSaver,\n auth: null,\n handover: false,\n replacing: false,\n gen: 0,\n discardReported: -1,\n };\n row.saver = createAutoSaver({\n save: (payload, ctx) => saveRow(row, payload, ctx as SaveCtx),\n });\n rowRef.current = row;\n }\n\n /** The coalescer's sink: ONE request, written into the ctx captured at push time. */\n const saveRowRef = useRef(saveRow);\n saveRowRef.current = saveRow;\n function saveRow(row: Row, payload: string, ctx: SaveCtx): Promise<void> {\n // Serialization: no queue. The edit made meanwhile is re-pushed when this one settles.\n if (row.inflight) return Promise.resolve();\n const cur = optsRef.current;\n if (!ctx.explicit && cur.canAutoSave && !cur.canAutoSave()) return Promise.resolve();\n const isCurrent = () => rowRef.current === row;\n const gen = row.gen;\n const run = async (): Promise<void> => {\n if (!ctx.project) throw new Error(NO_PROJECT);\n const definition = JSON.parse(payload) as WorkflowDefinition;\n if (isCurrent()) {\n setSaving(true);\n setError(null);\n }\n try {\n const res = await ctx.client.workflows.update(ctx.id, definition, {\n project: ctx.project,\n ifUnmodifiedSince: ctx.token,\n });\n void qcRef.current.invalidateQueries({ queryKey: [\"workflows\"] });\n // The buffer was replaced while this save was in flight: its token and clean marker belong\n // to the old buffer.\n if (gen !== row.gen) return;\n row.token = nextSaveToken(ctx.token, res as { updatedAt?: unknown });\n row.saver.markSaved(payload);\n row.refused = null;\n } catch (e) {\n if (gen === row.gen) {\n row.refused = payload;\n row.lastError = e;\n row.saver.cancel();\n if (isStaleWrite(e)) row.stale = true;\n if (isCurrent()) {\n if (row.stale) setStale(true);\n setError(e);\n }\n }\n throw e;\n }\n };\n const p = run();\n row.inflight = p;\n const clear = () => {\n if (row.inflight === p) row.inflight = null;\n if (isCurrent()) setSaving(false);\n };\n p.then(clear, clear);\n return p;\n }\n\n /** A dirty buffer that could not be saved is about to be dropped: tell the host, once. */\n const reportDiscard = useCallback((row: Row, outcome: FlushOutcome) => {\n if (outcome.status !== \"blocked\" && outcome.status !== \"failed\") return;\n if (row.discardReported === row.gen) return;\n row.discardReported = row.gen;\n try {\n optsRef.current.onDiscard?.({\n workflowId: row.id,\n text: row.text,\n reason: outcome.status,\n });\n } catch {\n // A host callback must not break the switch.\n }\n }, []);\n\n /**\n * Settle a row's buffer. `explicit` (Save button, `flushThen`) saves any dirty saveable text;\n * the automatic callers (hide, unmount, the registry) additionally honour `autoSave` and the busy\n * probe, and re-use the ctx of the entry they are flushing. Never rejects.\n */\n const flushRow = useCallback(\n async (\n row: Row,\n explicit: boolean,\n /**\n * Identity switch / logout / client-project handover: the buffer is about to be dropped, so\n * save a dirty saveable one even when `autoSave` is off AND the busy probe reports busy.\n * Validity (syntax, project, guard) still blocks.\n */\n ignoreGates = false,\n ): Promise<FlushOutcome> => {\n try {\n if (row.replacing) return { status: \"blocked\", reason: \"A version is being restored.\" };\n let drained: { error: unknown } | null = null;\n while (row.inflight) {\n try {\n await row.inflight;\n } catch (e) {\n drained = { error: e };\n }\n }\n if (row.replacing) return { status: \"blocked\", reason: \"A version is being restored.\" };\n if (!row.loaded) return { status: \"blocked\", reason: \"The workflow has not loaded.\" };\n const text = row.text;\n if (!row.saver.isDirty(text)) return { status: \"clean\" };\n // The save we just waited for refused these very bytes: report it, do not hammer the server.\n if (drained && row.refused === text) return { status: \"failed\", error: drained.error };\n if (row.stale) return { status: \"failed\", error: row.lastError };\n const cur = optsRef.current;\n const auth = row.auth as AuthCtx;\n if (!auth.project && auth.client === clientRef.current) auth.project = cur.project;\n const { blocked } = evaluate(text, row.id, auth.project, guardRef.current);\n if (blocked !== null) return { status: \"blocked\", reason: blocked };\n if (!explicit) {\n if (!ignoreGates && !(cur.autoSave ?? true)) {\n return { status: \"blocked\", reason: \"Auto-save is off.\" };\n }\n if (!ignoreGates && cur.canAutoSave && !cur.canAutoSave()) {\n return { status: \"blocked\", reason: \"The editor is busy.\" };\n }\n }\n const ctx: SaveCtx = {\n client: auth.client,\n project: auth.project,\n id: row.id,\n token: row.token,\n // `saveRow` re-checks the busy probe for automatic saves; a gate-ignoring flush is explicit.\n explicit: explicit || ignoreGates,\n };\n row.saver.push(text, true, true, ctx);\n await row.saver.flush();\n return { status: \"saved\" };\n } catch (error) {\n return { status: \"failed\", error };\n }\n },\n [],\n );\n\n // ── load ──────────────────────────────────────────────────────────────────\n // Keyed on `workflowId` ONLY: a rebuilt client (token rotation) neither reloads nor cancels the\n // pending entry.\n // biome-ignore lint/correctness/useExhaustiveDependencies: `workflowId` is the trigger; the row is read from a ref\n useEffect(() => {\n const row = rowRef.current;\n if (!row) return;\n let canceled = false;\n setJsonState(\"\");\n setLoadedId(null);\n setLoadError(null);\n setError(null);\n setStale(false);\n setSaving(false);\n const authored: AuthCtx = { client: clientRef.current, project: optsRef.current.project };\n authored.client.workflows.get(row.id).then(\n (r) => {\n if (canceled) return;\n row.auth = authored;\n const text = JSON.stringify(r.workflow, null, 2);\n row.text = text;\n row.token = nextSaveToken(null, r);\n // What we just loaded IS the server's copy: the editor opens clean.\n row.saver.markSaved(text);\n row.loaded = true;\n setJsonState(text);\n setLoadedId(row.id);\n },\n (e) => {\n if (!canceled) setLoadError(e);\n },\n );\n return () => {\n canceled = true;\n // The pending entry belongs to the row that produced it: flush it there, never drop it.\n void flushRow(row, false);\n // Disarm the window; a flush still waiting on an in-flight save pushes afresh.\n row.saver.cancel();\n };\n }, [workflowId, flushRow]);\n\n // ── derived ───────────────────────────────────────────────────────────────\n const row = rowRef.current;\n // `row.loaded` too: A→B→A leaves `loadedId === A` for one render while the NEW A row loads.\n const loaded = row?.loaded === true && loadedId === workflowId;\n const text = loaded ? json : \"\";\n const ev = useMemo(\n () => (loaded && workflowId !== null ? evaluate(text, workflowId, project, saveGuard) : null),\n [loaded, text, workflowId, project, saveGuard],\n );\n const saveBlockedReason = ev ? ev.blocked : !project && workflowId !== null ? NO_PROJECT : null;\n if (!(loaded && ctxDiffers(row?.auth ?? null, client, project))) guardRef.current = saveGuard;\n const switching = handingOver || (loaded && ctxDiffers(row?.auth ?? null, client, project));\n const canSave = loaded && saveBlockedReason === null && !saving && !switching;\n const dirty = loaded && row?.saver.isDirty(text) === true;\n const publishBlocked =\n ev && ev.parsed !== null && o.publishBlockedReason ? o.publishBlockedReason(ev.parsed) : null;\n\n // ── auto-save push ──────────────────────────────────────────────────────────\n // Never writes: hands the payload to the coalescer. `project`/`client` are read here (push time)\n // and ride the entry as its ctx.\n useEffect(() => {\n const r = rowRef.current;\n if (!r || !loaded || r.id !== workflowId) return;\n // While a 409 is on screen every save is refused the same way; pushing would retry into it.\n if (stale) return;\n if (json === r.refused) return;\n // A context change is being handed over: nothing is pushed under the new context.\n if (r.handover || !r.auth || ctxDiffers(r.auth, clientRef.current, optsRef.current.project)) {\n return;\n }\n if (!r.auth.project) r.auth.project = optsRef.current.project;\n const ctx: SaveCtx = {\n client: r.auth.client,\n project: r.auth.project,\n id: r.id,\n token: r.token,\n explicit: false,\n };\n r.saver.push(json, autoSave, canSave, ctx);\n }, [loaded, workflowId, json, stale, autoSave, canSave]);\n\n // ── context handover ──────────────────────────────────────────────────────\n // The host swapped client or project under a loaded buffer: settle the buffer into the context\n // that authored it (once), then discard it and read the row afresh under the new one.\n // biome-ignore lint/correctness/useExhaustiveDependencies: the row is read from a ref\n useEffect(() => {\n const r = rowRef.current;\n if (!r || !loaded || r.id !== workflowId || r.handover) return;\n if (!ctxDiffers(r.auth, client, project)) {\n if (r.auth && !r.auth.project) r.auth.project = project;\n return;\n }\n r.handover = true;\n setHandingOver(true);\n void (async () => {\n try {\n // Same path as the registry's flushAll (so also regardless of `autoSave`); saved or\n // refused, the buffer is then dropped.\n reportDiscard(r, await flushRow(r, false, true));\n if (rowRef.current !== r) return;\n r.saver.cancel();\n const authored: AuthCtx = { client: clientRef.current, project: optsRef.current.project };\n const res = await authored.client.workflows.get(r.id);\n if (rowRef.current !== r) return;\n const next = JSON.stringify(res.workflow, null, 2);\n r.gen++;\n r.auth = authored;\n r.text = next;\n r.token = nextSaveToken(null, res);\n r.saver.markSaved(next);\n r.refused = null;\n r.stale = false;\n r.lastError = null;\n setJsonState(next);\n setStale(false);\n setError(null);\n } catch (e) {\n if (rowRef.current === r) {\n r.loaded = false;\n setLoadedId(null);\n setLoadError(e);\n }\n } finally {\n r.handover = false;\n if (rowRef.current === r) setHandingOver(false);\n }\n })();\n }, [loaded, workflowId, client, project, handingOver, flushRow, reportDiscard]);\n\n // ── flush on hide / registry ──────────────────────────────────────────────\n // biome-ignore lint/correctness/useExhaustiveDependencies: `workflowId` is the trigger; the row is read from a ref\n useEffect(() => {\n const r = rowRef.current;\n if (!r) return;\n const w = (globalThis as { window?: Window }).window;\n const d = (globalThis as { document?: Document }).document;\n const offHide =\n w && d\n ? registerFlushOnHide(w, d, () => {\n void flushRow(r, false);\n })\n : undefined;\n // `flushAll` exists for identity switches and logout, so it saves regardless of `autoSave`\n // and of the busy probe, and reports what it had to drop. Hide / unmount keep their `autoSave` gate.\n const unregister = registry?.register(async () => {\n const outcome = await flushRow(r, false, true);\n reportDiscard(r, outcome);\n return outcome;\n });\n return () => {\n offHide?.();\n unregister?.();\n };\n }, [workflowId, registry, flushRow, reportDiscard]);\n\n // ── stable actions ────────────────────────────────────────────────────────\n const setJson = useCallback((next: string) => {\n const r = rowRef.current;\n if (!r || !r.loaded || r.replacing) return;\n r.text = next;\n setJsonState(next);\n }, []);\n const flush = useCallback((): Promise<FlushOutcome> => {\n const r = rowRef.current;\n return r ? flushRow(r, true) : Promise.resolve({ status: \"clean\" });\n }, [flushRow]);\n const saveNow = useCallback(() => {\n void flush();\n }, [flush]);\n const flushThen = useCallback(\n async <T>(action: () => Promise<T>) => {\n const outcome = await flush();\n if (outcome.status === \"clean\" || outcome.status === \"saved\") {\n return { ok: true as const, value: await action() };\n }\n return { ok: false as const, outcome };\n },\n [flush],\n );\n const commit = useCallback(\n (next: string): Promise<FlushOutcome> => {\n setJson(next);\n return flush();\n },\n [setJson, flush],\n );\n const reload = useCallback(async () => {\n const r = rowRef.current;\n if (!r) return;\n try {\n const authored: AuthCtx = { client: clientRef.current, project: optsRef.current.project };\n const res = await authored.client.workflows.get(r.id);\n if (rowRef.current !== r) return;\n r.auth = authored;\n const next = JSON.stringify(res.workflow, null, 2);\n // The canvas we are replacing is gone, and so is anything it had pending.\n r.saver.cancel();\n r.gen++;\n r.text = next;\n r.token = nextSaveToken(null, res);\n r.saver.markSaved(next);\n r.refused = null;\n r.stale = false;\n r.lastError = null;\n r.loaded = true;\n setJsonState(next);\n setLoadedId(r.id);\n setStale(false);\n setError(null);\n } catch (e) {\n if (rowRef.current === r) setError(e);\n }\n }, []);\n\n const discardThen = useCallback(\n async (action: () => Promise<unknown>) => {\n const r = rowRef.current;\n if (!r || r.replacing) return;\n r.replacing = true;\n r.handover = true;\n r.saver.cancel();\n setHandingOver(true);\n try {\n while (r.inflight) {\n try {\n await r.inflight;\n } catch {\n /* The replacement supersedes this save. */\n }\n }\n await action();\n if (rowRef.current === r) {\n // If the read fails after the server changed, refuse saves of the old buffer.\n r.stale = true;\n setStale(true);\n await reload();\n }\n } finally {\n r.replacing = false;\n r.handover = false;\n if (rowRef.current === r) setHandingOver(false);\n }\n },\n [reload],\n );\n\n return {\n json: text,\n setJson,\n parsed: ev ? ev.parsed : null,\n syntaxError: ev ? ev.syntaxError : null,\n loading: workflowId !== null && !loaded && loadError === null,\n loadError,\n dirty,\n saving,\n canSave,\n saveBlockedReason,\n stale,\n error,\n publishBlockedReason: publishBlocked,\n saveNow,\n flush,\n flushThen,\n commit,\n reload,\n discardThen,\n };\n}\n"],"names":["AUTOSAVE_DEBOUNCE_MS","createAutoSaver","opts","delayMs","setTimer","fn","ms","clearTimer","handle","pending","lastSaved","disarm","fire","entry","result","payload","enabled","canSave","ctx","registerFlushOnHide","windowTarget","documentTarget","flush","onBeforeUnload","onVisibilityChange","isStaleWrite","e","code","nextSaveToken","prev","res","ctxDiffers","a","client","project","NO_PROJECT","evaluate","text","id","saveGuard","parsed","syntaxError","blocked","useWorkflowDraft","o","useEmbedClient","registry","useDraftRegistry","qc","useQueryClient","workflowId","autoSave","json","setJsonState","useState","loadedId","setLoadedId","loadError","setLoadError","saving","setSaving","stale","setStale","error","setError","handingOver","setHandingOver","optsRef","useRef","clientRef","qcRef","rowRef","guardRef","_a","row","saveRow","saveRowRef","cur","isCurrent","gen","p","definition","clear","reportDiscard","useCallback","outcome","_b","flushRow","explicit","ignoreGates","drained","auth","useEffect","canceled","authored","r","loaded","ev","useMemo","saveBlockedReason","switching","dirty","publishBlocked","next","w","d","offHide","unregister","setJson","saveNow","flushThen","action","commit","reload","discardThen"],"mappings":";;;;AA4CO,MAAMA,KAAuB;AAoC7B,SAASC,GAAgBC,GAAgC;AAC9D,QAAMC,IAAUD,EAAK,WAAWF,IAC1BI,IACJF,EAAK,aAAa,CAACG,GAAgBC,MAAe,WAAWD,GAAIC,CAAE,IAC/DC,IAAaL,EAAK,eAAe,CAACM,MAAmB,aAAaA,CAAM;AAE9E,MAAIC,IAA0B,MAC1BD,IAAwB,MACxBE,IAA2B;AAG/B,WAASC,IAAe;AACtB,IAAIH,MAAW,SACbD,EAAWC,CAAM,GACjBA,IAAS;AAAA,EAEb;AAOA,WAASI,IAAsB;AAC7B,IAAAJ,IAAS;AACT,UAAMK,IAAQJ;AAKd,QAJAA,IAAU,MACN,CAACI,KACD,CAACA,EAAM,WACP,CAACA,EAAM,WACPA,EAAM,YAAYH,EAAW,QAA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