@w6w/embed 0.2.34 → 0.2.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{CreateFunctionModal-glk2zg1r.js → CreateFunctionModal-CYNHJUGJ.js} +3 -3
- package/dist/{CreateFunctionModal-glk2zg1r.js.map → CreateFunctionModal-CYNHJUGJ.js.map} +1 -1
- package/dist/{DocumentFormModal-B3OkvI5v.js → DocumentFormModal-CLmdGx34.js} +2 -2
- package/dist/{DocumentFormModal-B3OkvI5v.js.map → DocumentFormModal-CLmdGx34.js.map} +1 -1
- package/dist/ImportSpecModal-BzEyiNWD.js +378 -0
- package/dist/ImportSpecModal-BzEyiNWD.js.map +1 -0
- package/dist/WorkflowEditor-CxTuK8_d.js +1272 -0
- package/dist/WorkflowEditor-CxTuK8_d.js.map +1 -0
- package/dist/{apps-CFWdgGst.js → apps-CyEszfIu.js} +33 -33
- package/dist/{apps-CFWdgGst.js.map → apps-CyEszfIu.js.map} +1 -1
- package/dist/callable-row-actions-BPBPflMn.js +56 -0
- package/dist/callable-row-actions-BPBPflMn.js.map +1 -0
- package/dist/callables-dLF2IcwA.js +317 -0
- package/dist/callables-dLF2IcwA.js.map +1 -0
- package/dist/chrome/TagEditor.d.ts +6 -1
- package/dist/chrome/workspace.d.ts +16 -0
- package/dist/documents-hgltn0xe.js +1017 -0
- package/dist/documents-hgltn0xe.js.map +1 -0
- package/dist/draft.mjs +1 -1
- package/dist/editor/WaitingForm.d.ts +19 -0
- package/dist/{editor-apps-ShwCmvLY.js → editor-apps-DsGrGKfe.js} +3 -3
- package/dist/{editor-apps-ShwCmvLY.js.map → editor-apps-DsGrGKfe.js.map} +1 -1
- package/dist/{editor-tools-rY9nddqr.js → editor-tools-Ct7YPPj8.js} +682 -784
- package/dist/editor-tools-Ct7YPPj8.js.map +1 -0
- package/dist/editor.mjs +1 -1
- package/dist/editors.mjs +18 -18
- package/dist/{endpoints-zOuwci2U.js → endpoints-DJxXRh-I.js} +12 -12
- package/dist/{endpoints-zOuwci2U.js.map → endpoints-DJxXRh-I.js.map} +1 -1
- package/dist/forms.mjs +1 -1
- package/dist/index.mjs +140 -115
- package/dist/index.mjs.map +1 -1
- package/dist/lib/callable-row-actions.d.ts +17 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/run-event-stream.d.ts +122 -0
- package/dist/lib/tag-editor.d.ts +6 -0
- package/dist/lib/workflow-live-run.d.ts +7 -0
- package/dist/lib/workflow-validity.d.ts +7 -1
- package/dist/lib.mjs +52 -47
- package/dist/lists/CallableKindList.d.ts +12 -0
- package/dist/lists/CallableRowParts.d.ts +8 -1
- package/dist/lists/EndpointList.d.ts +3 -0
- package/dist/lists/FunctionList.d.ts +3 -0
- package/dist/lists/WorkflowList.d.ts +3 -0
- package/dist/lists.d.ts +1 -0
- package/dist/lists.mjs +1589 -1513
- package/dist/lists.mjs.map +1 -1
- package/dist/rail.mjs +1 -1
- package/dist/repos/callables.d.ts +25 -0
- package/dist/repos/documents.d.ts +9 -1
- package/dist/repos/saved-file-names.d.ts +10 -0
- package/dist/repos/workflows.d.ts +19 -13
- package/dist/repos.mjs +333 -328
- package/dist/{setup-incomplete-BHs3Lpfy.js → setup-incomplete-6PAbN0EW.js} +50 -49
- package/dist/setup-incomplete-6PAbN0EW.js.map +1 -0
- package/dist/spec-import-BKyfhTYG.js +200 -0
- package/dist/spec-import-BKyfhTYG.js.map +1 -0
- package/dist/{use-callable-draft-w4tDTYcb.js → use-callable-draft-7HwfTuYQ.js} +3 -3
- package/dist/{use-callable-draft-w4tDTYcb.js.map → use-callable-draft-7HwfTuYQ.js.map} +1 -1
- package/package.json +3 -3
- package/src/styles.css +43 -0
- package/dist/ImportSpecModal-SQvTwtcX.js +0 -252
- package/dist/ImportSpecModal-SQvTwtcX.js.map +0 -1
- package/dist/WorkflowEditor-D2EfEP-U.js +0 -1201
- package/dist/WorkflowEditor-D2EfEP-U.js.map +0 -1
- package/dist/callable-record-Bhxim8C1.js +0 -14
- package/dist/callable-record-Bhxim8C1.js.map +0 -1
- package/dist/callables-B49tS2vv.js +0 -297
- package/dist/callables-B49tS2vv.js.map +0 -1
- package/dist/editor-tools-rY9nddqr.js.map +0 -1
- package/dist/setup-incomplete-BHs3Lpfy.js.map +0 -1
- package/dist/spec-import-CPbDnnuv.js +0 -272
- package/dist/spec-import-CPbDnnuv.js.map +0 -1
- package/dist/workflows-RhR8kwt7.js +0 -667
- package/dist/workflows-RhR8kwt7.js.map +0 -1
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/embed-status.ts","../src/repos/webhook-listen.ts","../src/W6WEmbedProvider.tsx"],"sourcesContent":["/**\n * The embed's public session status, as a pure total function over the `@w6w/react` session\n * store's status plus whether a terminal partner-token 401 has been seen. No React here, so\n * `node:test` covers it exhaustively.\n */\nimport type { W6WSessionStatus } from \"@w6w/react\";\n\nexport type EmbedStatusValue = \"connecting\" | \"ready\" | \"error\";\n\nexport interface EmbedStatus {\n status: EmbedStatusValue;\n /** `EmbedAuthError` for a terminal 401, else the session store's own error; `null` otherwise. */\n error: unknown;\n}\n\n/**\n * The terminal partner-token 401: the host's `getSession` minted a token the API refused, and a\n * renewal did not fix it. `cause` is the SDK `ApiError`.\n */\nexport class EmbedAuthError extends Error {\n constructor(cause: unknown) {\n super(\"The w6w API rejected the embed session token (401).\", { cause });\n this.name = \"EmbedAuthError\";\n }\n}\n\n/**\n * `loading -> connecting`, `ready|renewing -> ready`, `expired -> connecting` (the provider\n * re-acquires), `error -> error`. A seen 401 wins over everything: it is `error` with the\n * `EmbedAuthError`, whatever the store currently says.\n */\nexport function deriveEmbedStatus(\n sessionStatus: W6WSessionStatus,\n sessionError: unknown,\n authError: EmbedAuthError | null,\n): EmbedStatus {\n if (authError) return { status: \"error\", error: authError };\n switch (sessionStatus) {\n case \"ready\":\n case \"renewing\":\n return { status: \"ready\", error: null };\n case \"error\":\n return { status: \"error\", error: sessionError };\n case \"loading\":\n case \"expired\":\n return { status: \"connecting\", error: null };\n }\n}\n","import type { W6WClient } from \"@w6w/sdk\";\nimport { path } from \"@w6w/sdk\";\n/**\n * \"Listen for test event\" on a `@w6w/webhook` subscription — `/subscriptions/:id/listen` over\n * `client.request()`. Not in the SDK's stable contract (Studio reaches it the same way, its\n * `repos/subscriptions.ts`), and `createW6WUiAdapter` carries none of it, so without these the\n * embedded editor's webhook Test tab fell back to the paste-a-payload form.\n */\n\n/**\n * Structural mirror of ui's `WebhookListenSession` (this barrel may not import `@w6w/ui`); the\n * UiBridge assignment typechecks against W6WApi structurally.\n */\nexport interface WebhookListenSession {\n id: string;\n subscriptionId: string;\n nodeId: string | null;\n expiresAt: string;\n status: \"waiting\" | \"captured\" | \"expired\";\n request?: {\n method: string;\n path: string;\n query: Record<string, string>;\n headers: Record<string, string>;\n body: unknown;\n };\n receivedAt?: string;\n}\n\nexport async function startWebhookListen(\n client: W6WClient,\n subscriptionId: string,\n): Promise<{ session: WebhookListenSession; webhookUrl: string }> {\n const res = await client.request<{ session: WebhookListenSession; webhookUrl: string }>({\n method: \"POST\",\n path: path`/subscriptions/${subscriptionId}/listen`,\n body: {},\n });\n return res.body;\n}\n\nexport async function pollWebhookListen(\n client: W6WClient,\n subscriptionId: string,\n sessionId: string,\n opts?: { waitSeconds?: number; signal?: AbortSignal },\n): Promise<WebhookListenSession> {\n const res = await client.request<{ session: WebhookListenSession }>({\n method: \"GET\",\n path: path`/subscriptions/${subscriptionId}/listen/${sessionId}`,\n query: { wait: String(opts?.waitSeconds ?? 0) },\n signal: opts?.signal,\n });\n return res.body.session;\n}\n\nexport async function stopWebhookListen(\n client: W6WClient,\n subscriptionId: string,\n sessionId: string,\n): Promise<void> {\n await client.request<unknown>({\n method: \"DELETE\",\n path: path`/subscriptions/${subscriptionId}/listen/${sessionId}`,\n });\n}\n","import { QueryClient, QueryClientProvider, useQuery } from \"@tanstack/react-query\";\n/**\n * `<W6WEmbedProvider>` — everything an embedded w6w surface needs from a host, behind one\n * element: an identity-scoped `QueryClient`, a `@w6w/react` `<W6WProvider>` (client, session\n * renewal, per-request token) and `@w6w/ui`'s `<W6WUIProvider>` fed by `createW6WUiAdapter`.\n * It composes the three public pieces exactly as `@w6w/react`'s README bridge does: it never\n * spreads or patches the adapter, never reaches into `client.console`, and keeps no session\n * store of its own (`getSession` goes straight to `<W6WProvider>`).\n *\n * **Identity cache.** The `QueryClient` is owned here, not borrowed from the host, and it is a\n * NEW instance whenever `identityKey` changes — so a query cached while signed in as account A\n * is unreachable once the host switches to B. A new client alone is NOT enough: a mounted\n * `useQuery` keeps the `QueryObserver` it was born with, and that observer is bound to the client\n * it was created against, so a child that survives the swap would keep rendering A's cache. The\n * subtree is therefore also re-mounted (`key`), which drops every observer and every piece of\n * child state from the previous identity. The client, the `key` and the tuple handed to\n * `<W6WProvider>` all change in ONE state update: there is no render in which B's tree reads A's\n * cache. The old client is cleared once it is no longer mounted.\n *\n * **Identity switch (flush first).** A draft with a pending save must be written into the account\n * that produced the edit. When `identityKey` changes this provider therefore HOLDS the applied\n * tuple — `identityKey`, `apiOrigin`, `project`, `getSession`, the client — and keeps handing the\n * OLD one to `<W6WProvider>`, awaits `registry.flushAll()` (bounded, never rejects), and only then\n * applies the new tuple in a single update. `<W6WProvider>` swaps its client synchronously on a\n * new `identityKey` and detaches the old session store, so the flush must finish first; and the\n * new `getSession` is NOT forwarded early: `<W6WProvider>` reaches it through the stable wrapper\n * below, whose target is swapped in the same update as the tuple (forwarded early, the new\n * account's token would be minted on the old client). A flush that fails or times out still lets\n * the switch proceed (Q6) and is never retried with the new identity. A token rotation under an\n * unchanged `identityKey` is not a switch: it is forwarded at once, no hold.\n *\n * **No identity.** `identityKey={null}` mounts nothing but `fallback`: no `<W6WProvider>`, no\n * `QueryClientProvider`, no children — so no `getSession` call and no request. `null -> \"A\"`\n * applies at once (nothing can be pending); `\"A\" -> null` takes the SAME flush-first path as any\n * other switch before the fallback renders.\n *\n * **Default project.** `project={{ use: \"default\" }}` resolves ONCE per applied identity, through\n * one `client.projects.list()` query inside the identity-scoped `QueryClient`, to the row with\n * `isDefault === true` — never `list[0]`, never a fallback. `<W6WProvider>` gets no project until\n * it resolves; the client rebuild that follows reuses the cached answer (the query is keyed\n * without the client and lives in a component that stays mounted, so it is not re-issued).\n *\n * **Status.** `useEmbedStatus()` is `deriveEmbedStatus` over the `@w6w/react` session store plus a\n * terminal 401 seen through the forwarded `onUnauthorized`.\n */\nimport {\n W6WProvider,\n type W6WSession,\n createW6WUiAdapter,\n useW6WClient,\n useW6WSession,\n} from \"@w6w/react\";\nimport type { ApiError, FetchLike } from \"@w6w/sdk\";\nimport { type ThemeMode, type W6WApi, W6WUIProvider } from \"@w6w/ui\";\nimport {\n type ReactNode,\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { DraftRegistryProvider, EmbedClientProvider, createDraftRegistry } from \"./draft/index.ts\";\nimport { EmbedAuthError, type EmbedStatus, deriveEmbedStatus } from \"./embed-status.ts\";\nimport {\n EmbedProjectContext,\n type EmbedProjectState,\n useProvidedProject,\n} from \"./project-context.ts\";\nimport { updateConnection } from \"./repos/connections.ts\";\nimport { withCredentialMethods } from \"./repos/credentials.ts\";\nimport { listDataStoreEntries, listDataStores } from \"./repos/data-stores.ts\";\nimport { resolveActionFields, resolveTriggerFields } from \"./repos/fields.ts\";\nimport { listModelRoutes } from \"./repos/models.ts\";\nimport {\n pollWebhookListen,\n startWebhookListen,\n stopWebhookListen,\n} from \"./repos/webhook-listen.ts\";\nimport { listNodeSamples, listTestInputs, saveTestInput } from \"./repos/workflows.ts\";\nimport { EmbedThemeContext } from \"./theme-context.ts\";\n\nexport interface W6WEmbedProviderProps {\n /** The w6w API origin, e.g. `\"https://api.w6w.io\"`. */\n apiOrigin: string;\n /**\n * Mints a session for the CURRENT host user (`{token, expiresAt, expiresIn?}`). Always the\n * latest callback; the provider caches and renews the result.\n */\n getSession: () => Promise<W6WSession>;\n /**\n * Which signed-in identity this provider speaks for (e.g. `${userId}:${accountId}`). Changing it\n * rebuilds the API client AND replaces the `QueryClient`, so nothing cached for the previous\n * identity is ever shown under the new one.\n */\n identityKey: string | null;\n /**\n * Rendered instead of the embed while `identityKey` is `null` (no signed-in user). Nothing of\n * the embed mounts then: no `getSession` call, no request. Default `null`.\n */\n fallback?: ReactNode;\n /**\n * Start acquiring a session on mount. Without it the session is acquired lazily, by the first\n * request a mounted surface makes, and `useEmbedStatus()` stays `\"connecting\"` until then.\n */\n eager?: boolean;\n /** Force the `@w6w/ui` theme to follow the host's. Omit to resolve it the library's default way. */\n theme?: ThemeMode;\n /** Gates every read hook while `false` (default `true`) — e.g. until the host has a user. */\n ready?: boolean;\n /**\n * Default project for project-scoped operations: a project id, or `{ use: \"default\" }` to use\n * the account's default project (resolved once per identity; see `useEmbedProject()`).\n */\n project?: string | { use: \"default\" };\n /** Transport override (tests, request recording). Defaults to `globalThis.fetch`. */\n fetch?: FetchLike;\n children: ReactNode;\n}\n\nfunction makeQueryClient(): QueryClient {\n // Same defaults as Studio's own client (`studio/src/main.tsx`).\n return new QueryClient({\n defaultOptions: { queries: { retry: false, refetchOnWindowFocus: false } },\n });\n}\n\n/** The part of the tuple that changes only when a switch has been APPLIED (after the flush). */\ninterface Applied {\n identityKey: string | null;\n queryClient: QueryClient;\n}\n\n/** What `<W6WProvider>` is fed while no switch is in progress; frozen at the last such render. */\ninterface Forwarded {\n apiOrigin: string;\n project: string | { use: \"default\" } | undefined;\n getSession: () => Promise<W6WSession>;\n}\n\n/** Hands the SDK client of the nearest `<W6WProvider>` to `useWorkflowDraft`. */\nfunction ClientBridge({ children }: { children: ReactNode }) {\n return <EmbedClientProvider client={useW6WClient()}>{children}</EmbedClientProvider>;\n}\n\n/** The README bridge: `useW6WClient` -> `createW6WUiAdapter` -> `<W6WUIProvider>`. */\nfunction UiBridge({ theme, children }: { theme?: ThemeMode; children: ReactNode }) {\n const client = useW6WClient();\n const provided = useProvidedProject();\n // `createW6WUiAdapter` has no `updateConnection` or `listModelRoutes`; keep them if it ever\n // gains them, else supply the embed repo's own so the ui Edit modal can save and the\n // `@w6w/model` node's Route field offers the project's routes (not free text) in any host.\n const api = useMemo(() => {\n const adapter: W6WApi = createW6WUiAdapter(client);\n if (typeof adapter.updateConnection !== \"function\") {\n adapter.updateConnection = (id, body) => updateConnection(client, id, body);\n }\n withCredentialMethods(adapter, client);\n if (typeof adapter.listModelRoutes !== \"function\") {\n adapter.listModelRoutes = async (editorProject) => {\n const project = editorProject || provided;\n if (!project) return [];\n const routes = await listModelRoutes(client, project);\n return routes.map((r) => ({ name: r.name, model: r.modelId, status: r.status }));\n };\n }\n // Same for the `@w6w/store` node's store picker: the project's store names, not free text.\n if (typeof adapter.listDataStores !== \"function\") {\n adapter.listDataStores = async (editorProject) => {\n const project = editorProject || provided;\n if (!project) return [];\n return listDataStores(client, project);\n };\n }\n // ...and its key picker: one page of the named store's entries, searched by key prefix.\n if (typeof adapter.listDataStoreEntries !== \"function\") {\n adapter.listDataStoreEntries = async (store, opts) => {\n const project = opts.project || provided;\n if (!project) return { items: [] };\n return listDataStoreEntries(client, project, store, opts);\n };\n }\n // Persisted node samples, so the editor's picker keeps upstream keys across a reload.\n if (typeof adapter.loadNodeSamples !== \"function\") {\n adapter.loadNodeSamples = (workflowId) => listNodeSamples(client, workflowId);\n }\n // Remembered test inputs, so every test form reopens prefilled with the last values used.\n if (typeof adapter.loadTestInputs !== \"function\") {\n adapter.loadTestInputs = (workflowId) => listTestInputs(client, workflowId);\n }\n if (typeof adapter.saveTestInput !== \"function\") {\n adapter.saveTestInput = (workflowId, nodeId, input) =>\n saveTestInput(client, workflowId, nodeId, input);\n }\n if (typeof adapter.resolveActionFields !== \"function\") {\n adapter.resolveActionFields = (appId, actionKey, body, opts) =>\n resolveActionFields(client, appId, actionKey, body, opts);\n }\n if (typeof adapter.resolveTriggerFields !== \"function\") {\n adapter.resolveTriggerFields = (appId, triggerKey, body, opts) =>\n resolveTriggerFields(client, appId, triggerKey, body, opts);\n }\n // The webhook node's Test tab listens for a real request only when all three exist; without\n // them it falls back to the paste-a-payload form.\n if (typeof adapter.startWebhookListen !== \"function\") {\n adapter.startWebhookListen = (subscriptionId) => startWebhookListen(client, subscriptionId);\n adapter.pollWebhookListen = (subscriptionId, sessionId, opts) =>\n pollWebhookListen(client, subscriptionId, sessionId, opts);\n adapter.stopWebhookListen = (subscriptionId, sessionId) =>\n stopWebhookListen(client, subscriptionId, sessionId);\n }\n return adapter;\n }, [client, provided]);\n return (\n <W6WUIProvider api={api} theme={theme}>\n <EmbedThemeContext.Provider value={theme}>{children}</EmbedThemeContext.Provider>\n </W6WUIProvider>\n );\n}\n\nconst EmbedStatusContext = createContext<EmbedStatus>({ status: \"connecting\", error: null });\n\n/** The session status of the nearest `<W6WEmbedProvider>`. See `deriveEmbedStatus`. */\nexport function useEmbedStatus(): EmbedStatus {\n return useContext(EmbedStatusContext);\n}\n\n/** Publishes `useEmbedStatus()`, and starts the session on mount when `eager`. */\nfunction StatusBridge({\n eager,\n authError,\n onAcquire,\n children,\n}: {\n eager: boolean;\n authError: EmbedAuthError | null;\n onAcquire: () => void;\n children: ReactNode;\n}) {\n const { status, error, refresh } = useW6WSession();\n // `refresh` is per session store, so a rebuilt client (project resolved) is started again.\n useEffect(() => {\n if (eager) void refresh();\n }, [eager, refresh]);\n useEffect(() => {\n if (status === \"loading\" || status === \"renewing\") onAcquire();\n }, [status, onAcquire]);\n const value = useMemo(\n () => deriveEmbedStatus(status, error, authError),\n [status, error, authError],\n );\n return <EmbedStatusContext.Provider value={value}>{children}</EmbedStatusContext.Provider>;\n}\n\n/**\n * Resolves `{use:\"default\"}`. Lives INSIDE `<W6WProvider>` (it needs the client) but at a fixed\n * slot, so it survives the client rebuild that follows resolution; the query key carries no\n * client, so nothing refetches.\n */\nfunction DefaultProjectResolver({\n identityKey,\n enabled,\n onState,\n}: {\n identityKey: string;\n enabled: boolean;\n onState: (key: string, state: EmbedProjectState) => void;\n}) {\n const client = useW6WClient();\n const q = useQuery({\n queryKey: [\"w6w-embed\", \"default-project\"],\n enabled,\n queryFn: async () => {\n const rows = await client.projects.list();\n const home = rows.find((p) => p.isDefault === true);\n if (!home) throw new Error(\"The account has no default project.\");\n return home.id;\n },\n });\n const { isError, error, data } = q;\n const state = useMemo<EmbedProjectState>(\n () =>\n isError\n ? { project: null, status: \"error\", error }\n : data !== undefined\n ? { project: data, status: \"ready\" }\n : { project: null, status: \"resolving\" },\n [isError, error, data],\n );\n useEffect(() => {\n onState(identityKey, state);\n }, [identityKey, state, onState]);\n return null;\n}\n\nexport function W6WEmbedProvider({\n apiOrigin,\n getSession,\n identityKey,\n fallback = null,\n eager = false,\n theme,\n ready,\n project,\n fetch,\n children,\n}: W6WEmbedProviderProps): ReactNode {\n const [registry] = useState(createDraftRegistry);\n const [applied, setApplied] = useState<Applied>(() => ({\n identityKey,\n queryClient: makeQueryClient(),\n }));\n\n // While `identityKey` differs from the applied one a switch is pending: everything below keeps\n // using the values frozen at the last render that was not pending. Otherwise props flow straight\n // through (project / origin changes, token rotation). Idempotent latest-value writes, the same\n // pattern `<W6WProvider>` uses for its own refs.\n const switching = identityKey !== applied.identityKey;\n const forwardedRef = useRef<Forwarded>({ apiOrigin, project, getSession });\n if (!switching) forwardedRef.current = { apiOrigin, project, getSession };\n const forwarded = forwardedRef.current;\n\n // The stable `getSession` handed to `<W6WProvider>`: reads whatever is applied RIGHT NOW. Its\n // target changes in the same render that applies the new tuple, never before the flush settles.\n const sessionRef = useRef(forwarded.getSession);\n sessionRef.current = forwarded.getSession;\n const [stableGetSession] = useState(() => () => sessionRef.current());\n\n useEffect(() => {\n if (identityKey === applied.identityKey) return;\n let cancelled = false;\n const apply = () => {\n if (cancelled) return;\n setApplied({ identityKey, queryClient: makeQueryClient() });\n };\n // Nothing is mounted under a null identity, so nothing can be pending: apply at once.\n if (applied.identityKey === null) {\n apply();\n return () => {\n cancelled = true;\n };\n }\n // `flushAll` never rejects and is bounded; the switch proceeds either way (Q6).\n registry.flushAll().then(apply, apply);\n return () => {\n cancelled = true;\n };\n }, [identityKey, applied.identityKey, registry]);\n\n // The replaced client is dropped once nothing mounted reads it.\n const queryClient = applied.queryClient;\n useEffect(() => () => queryClient.clear(), [queryClient]);\n\n // Default-project resolution, tagged with the identity it was resolved for: a result for A is\n // never read once B is applied.\n const [resolved, setResolved] = useState<{ key: string; state: EmbedProjectState } | null>(null);\n const onResolved = useCallback((key: string, state: EmbedProjectState) => {\n setResolved((prev) =>\n prev &&\n prev.key === key &&\n prev.state.project === state.project &&\n prev.state.status === state.status &&\n prev.state.error === state.error\n ? prev\n : { key, state },\n );\n }, []);\n\n // The terminal partner-token 401, tagged with its identity; cleared when the next acquisition\n // starts (StatusBridge) or the identity changes (the tag no longer matches).\n const [authFailure, setAuthFailure] = useState<{\n key: QueryClient;\n error: EmbedAuthError;\n } | null>(null);\n // The handler is bound to the per-mount client it was created for: a late 401 from a previous\n // `<W6WProvider>` is tagged with ITS client, never the one applied by the time it fires — even\n // when the identity key came back (A -> B -> A mints a new client for the same key).\n const onUnauthorized = useMemo(() => {\n const key = applied.queryClient;\n return (error: ApiError) => {\n setAuthFailure({ key, error: new EmbedAuthError(error) });\n };\n }, [applied.queryClient]);\n const clearAuthFailure = useCallback(() => setAuthFailure(null), []);\n\n const appliedKey = applied.identityKey;\n const spec = forwarded.project;\n // Only exactly `{ use: \"default\" }` asks for the account default; null, `{}`, `[]` or any other\n // object (JS hosts, casts) is \"no project\" and makes no lookup.\n const wantsDefault =\n typeof spec === \"object\" && spec !== null && !Array.isArray(spec) && spec.use === \"default\";\n const projectState: EmbedProjectState = useMemo(() => {\n if (typeof spec === \"string\") return { project: spec, status: \"ready\" };\n if (!wantsDefault) return { project: null, status: \"ready\" };\n return resolved && resolved.key === appliedKey\n ? resolved.state\n : { project: null, status: \"resolving\" };\n }, [spec, wantsDefault, resolved, appliedKey]);\n\n if (appliedKey === null) return fallback;\n\n return (\n <DraftRegistryProvider registry={registry}>\n <QueryClientProvider key={appliedKey} client={queryClient}>\n <W6WProvider\n baseUrl={forwarded.apiOrigin}\n getSession={stableGetSession}\n identityKey={appliedKey}\n ready={ready}\n project={projectState.project ?? undefined}\n fetch={fetch}\n onUnauthorized={onUnauthorized}\n >\n {wantsDefault ? (\n <DefaultProjectResolver\n identityKey={appliedKey}\n enabled={ready !== false}\n onState={onResolved}\n />\n ) : null}\n <EmbedProjectContext.Provider value={projectState}>\n <StatusBridge\n eager={eager}\n authError={authFailure && authFailure.key === queryClient ? authFailure.error : null}\n onAcquire={clearAuthFailure}\n >\n <ClientBridge>\n <UiBridge theme={theme}>{children}</UiBridge>\n </ClientBridge>\n </StatusBridge>\n </EmbedProjectContext.Provider>\n </W6WProvider>\n </QueryClientProvider>\n </DraftRegistryProvider>\n );\n}\n"],"names":["EmbedAuthError","cause","deriveEmbedStatus","sessionStatus","sessionError","authError","startWebhookListen","client","subscriptionId","path","pollWebhookListen","sessionId","opts","stopWebhookListen","makeQueryClient","QueryClient","ClientBridge","children","jsx","EmbedClientProvider","useW6WClient","UiBridge","theme","provided","useProvidedProject","api","useMemo","adapter","createW6WUiAdapter","id","body","updateConnection","withCredentialMethods","editorProject","project","listModelRoutes","r","listDataStores","store","listDataStoreEntries","workflowId","listNodeSamples","listTestInputs","nodeId","input","saveTestInput","appId","actionKey","resolveActionFields","triggerKey","resolveTriggerFields","W6WUIProvider","EmbedThemeContext","EmbedStatusContext","createContext","useEmbedStatus","useContext","StatusBridge","eager","onAcquire","status","error","refresh","useW6WSession","useEffect","value","DefaultProjectResolver","identityKey","enabled","onState","q","useQuery","home","p","isError","data","state","W6WEmbedProvider","apiOrigin","getSession","fallback","ready","fetch","registry","useState","createDraftRegistry","applied","setApplied","switching","forwardedRef","useRef","forwarded","sessionRef","stableGetSession","cancelled","apply","queryClient","resolved","setResolved","onResolved","useCallback","key","prev","authFailure","setAuthFailure","onUnauthorized","clearAuthFailure","appliedKey","spec","wantsDefault","projectState","DraftRegistryProvider","QueryClientProvider","jsxs","W6WProvider","EmbedProjectContext"],"mappings":";;;;;;;;;;;;;;;;;;AAmBO,MAAMA,WAAuB,MAAM;AAAA,EACxC,YAAYC,GAAgB;AAC1B,UAAM,uDAAuD,EAAE,OAAAA,GAAO,GACtE,KAAK,OAAO;AAAA,EACd;AACF;AAOO,SAASC,GACdC,GACAC,GACAC,GACa;AACb,MAAIA,EAAW,QAAO,EAAE,QAAQ,SAAS,OAAOA,EAAA;AAChD,UAAQF,GAAA;AAAA,IACN,KAAK;AAAA,IACL,KAAK;AACH,aAAO,EAAE,QAAQ,SAAS,OAAO,KAAA;AAAA,IACnC,KAAK;AACH,aAAO,EAAE,QAAQ,SAAS,OAAOC,EAAA;AAAA,IACnC,KAAK;AAAA,IACL,KAAK;AACH,aAAO,EAAE,QAAQ,cAAc,OAAO,KAAA;AAAA,EAAK;AAEjD;AClBA,eAAsBE,GACpBC,GACAC,GACgE;AAMhE,UALY,MAAMD,EAAO,QAA+D;AAAA,IACtF,QAAQ;AAAA,IACR,MAAME,mBAAsBD,CAAc;AAAA,IAC1C,MAAM,CAAA;AAAA,EAAC,CACR,GACU;AACb;AAEA,eAAsBE,GACpBH,GACAC,GACAG,GACAC,GAC+B;AAO/B,UANY,MAAML,EAAO,QAA2C;AAAA,IAClE,QAAQ;AAAA,IACR,MAAME,mBAAsBD,CAAc,WAAWG,CAAS;AAAA,IAC9D,OAAO,EAAE,MAAM,QAAOC,KAAA,gBAAAA,EAAM,gBAAe,CAAC,EAAA;AAAA,IAC5C,QAAQA,KAAA,gBAAAA,EAAM;AAAA,EAAA,CACf,GACU,KAAK;AAClB;AAEA,eAAsBC,GACpBN,GACAC,GACAG,GACe;AACf,QAAMJ,EAAO,QAAiB;AAAA,IAC5B,QAAQ;AAAA,IACR,MAAME,mBAAsBD,CAAc,WAAWG,CAAS;AAAA,EAAA,CAC/D;AACH;ACyDA,SAASG,IAA+B;AAEtC,SAAO,IAAIC,EAAY;AAA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BAAAiB;AAAA,IAACC;AAAA,IAAA;AAAA,MACC,SAASvB,EAAU;AAAA,MACnB,YAAYE;AAAA,MACZ,aAAac;AAAA,MACb,OAAA1B;AAAA,MACA,SAAS6B,EAAa,WAAW;AAAA,MACjC,OAAA5B;AAAA,MACA,gBAAAuB;AAAA,MAEC,UAAA;AAAA,QAAAI,IACC,gBAAA3F;AAAA,UAACgD;AAAA,UAAA;AAAA,YACC,aAAayC;AAAA,YACb,SAAS1B,MAAU;AAAA,YACnB,SAASkB;AAAA,UAAA;AAAA,QAAA,IAET;AAAA,QACJ,gBAAAjF,EAACiG,GAAoB,UAApB,EAA6B,OAAOL,GACnC,UAAA,gBAAA5F;AAAA,UAACuC;AAAA,UAAA;AAAA,YACC,OAAAC;AAAA,YACA,WAAW6C,KAAeA,EAAY,QAAQP,IAAcO,EAAY,QAAQ;AAAA,YAChF,WAAWG;AAAA,YAEX,4BAAC1F,IAAA,EACC,UAAA,gBAAAE,EAACG,IAAA,EAAS,OAAAC,GAAe,UAAAL,GAAS,EAAA,CACpC;AAAA,UAAA;AAAA,QAAA,EACF,CACF;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA,EACF,GA5BwB0F,CA6B1B,GACF;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/embed-status.ts","../src/repos/saved-file-names.ts","../src/repos/webhook-listen.ts","../src/W6WEmbedProvider.tsx"],"sourcesContent":["/**\n * The embed's public session status, as a pure total function over the `@w6w/react` session\n * store's status plus whether a terminal partner-token 401 has been seen. No React here, so\n * `node:test` covers it exhaustively.\n */\nimport type { W6WSessionStatus } from \"@w6w/react\";\n\nexport type EmbedStatusValue = \"connecting\" | \"ready\" | \"error\";\n\nexport interface EmbedStatus {\n status: EmbedStatusValue;\n /** `EmbedAuthError` for a terminal 401, else the session store's own error; `null` otherwise. */\n error: unknown;\n}\n\n/**\n * The terminal partner-token 401: the host's `getSession` minted a token the API refused, and a\n * renewal did not fix it. `cause` is the SDK `ApiError`.\n */\nexport class EmbedAuthError extends Error {\n constructor(cause: unknown) {\n super(\"The w6w API rejected the embed session token (401).\", { cause });\n this.name = \"EmbedAuthError\";\n }\n}\n\n/**\n * `loading -> connecting`, `ready|renewing -> ready`, `expired -> connecting` (the provider\n * re-acquires), `error -> error`. A seen 401 wins over everything: it is `error` with the\n * `EmbedAuthError`, whatever the store currently says.\n */\nexport function deriveEmbedStatus(\n sessionStatus: W6WSessionStatus,\n sessionError: unknown,\n authError: EmbedAuthError | null,\n): EmbedStatus {\n if (authError) return { status: \"error\", error: authError };\n switch (sessionStatus) {\n case \"ready\":\n case \"renewing\":\n return { status: \"ready\", error: null };\n case \"error\":\n return { status: \"error\", error: sessionError };\n case \"loading\":\n case \"expired\":\n return { status: \"connecting\", error: null };\n }\n}\n","import type { W6WClient } from \"@w6w/sdk\";\n\n/** At most this many requests per list: a runaway cursor must not loop the picker forever. */\nconst MAX_PAGES = 10;\n\ninterface SavedFilesPage {\n assets?: { name: string; latestVersion?: { totalBytes?: number } }[];\n nextCursor?: string;\n}\n\n/**\n * The project's saved files as `{ path, size }`, for the ui's `saved-file` step-param picker\n * (`W6WApi.listSavedFiles`, `@w6w/files` save/read): `GET /assets?kind=saved_file`, walked page\n * by page. A saved file's `name` IS its canonical path; `size` is the latest version's bytes.\n */\nexport async function listSavedFiles(\n client: Pick<W6WClient, \"request\">,\n project: string,\n): Promise<{ path: string; size?: number }[]> {\n const out: { path: string; size?: number }[] = [];\n let cursor: string | undefined;\n for (let page = 0; page < MAX_PAGES; page++) {\n const query: Record<string, string> = { project, kind: \"saved_file\" };\n if (cursor !== undefined) query.cursor = cursor;\n const response = await client.request<SavedFilesPage>({\n method: \"GET\",\n path: \"/assets\",\n query,\n });\n for (const a of response.body.assets ?? []) {\n out.push({ path: a.name, size: a.latestVersion?.totalBytes });\n }\n cursor =\n typeof response.body.nextCursor === \"string\" && response.body.nextCursor !== \"\"\n ? response.body.nextCursor\n : undefined;\n if (!cursor) break;\n }\n return out;\n}\n","import type { W6WClient } from \"@w6w/sdk\";\nimport { path } from \"@w6w/sdk\";\n/**\n * \"Listen for test event\" on a `@w6w/webhook` subscription — `/subscriptions/:id/listen` over\n * `client.request()`. Not in the SDK's stable contract (Studio reaches it the same way, its\n * `repos/subscriptions.ts`), and `createW6WUiAdapter` carries none of it, so without these the\n * embedded editor's webhook Test tab fell back to the paste-a-payload form.\n */\n\n/**\n * Structural mirror of ui's `WebhookListenSession` (this barrel may not import `@w6w/ui`); the\n * UiBridge assignment typechecks against W6WApi structurally.\n */\nexport interface WebhookListenSession {\n id: string;\n subscriptionId: string;\n nodeId: string | null;\n expiresAt: string;\n status: \"waiting\" | \"captured\" | \"expired\";\n request?: {\n method: string;\n path: string;\n query: Record<string, string>;\n headers: Record<string, string>;\n body: unknown;\n };\n receivedAt?: string;\n}\n\nexport async function startWebhookListen(\n client: W6WClient,\n subscriptionId: string,\n): Promise<{ session: WebhookListenSession; webhookUrl: string }> {\n const res = await client.request<{ session: WebhookListenSession; webhookUrl: string }>({\n method: \"POST\",\n path: path`/subscriptions/${subscriptionId}/listen`,\n body: {},\n });\n return res.body;\n}\n\nexport async function pollWebhookListen(\n client: W6WClient,\n subscriptionId: string,\n sessionId: string,\n opts?: { waitSeconds?: number; signal?: AbortSignal },\n): Promise<WebhookListenSession> {\n const res = await client.request<{ session: WebhookListenSession }>({\n method: \"GET\",\n path: path`/subscriptions/${subscriptionId}/listen/${sessionId}`,\n query: { wait: String(opts?.waitSeconds ?? 0) },\n signal: opts?.signal,\n });\n return res.body.session;\n}\n\nexport async function stopWebhookListen(\n client: W6WClient,\n subscriptionId: string,\n sessionId: string,\n): Promise<void> {\n await client.request<unknown>({\n method: \"DELETE\",\n path: path`/subscriptions/${subscriptionId}/listen/${sessionId}`,\n });\n}\n","import { QueryClient, QueryClientProvider, useQuery } from \"@tanstack/react-query\";\n/**\n * `<W6WEmbedProvider>` — everything an embedded w6w surface needs from a host, behind one\n * element: an identity-scoped `QueryClient`, a `@w6w/react` `<W6WProvider>` (client, session\n * renewal, per-request token) and `@w6w/ui`'s `<W6WUIProvider>` fed by `createW6WUiAdapter`.\n * It composes the three public pieces exactly as `@w6w/react`'s README bridge does: it never\n * spreads or patches the adapter, never reaches into `client.console`, and keeps no session\n * store of its own (`getSession` goes straight to `<W6WProvider>`).\n *\n * **Identity cache.** The `QueryClient` is owned here, not borrowed from the host, and it is a\n * NEW instance whenever `identityKey` changes — so a query cached while signed in as account A\n * is unreachable once the host switches to B. A new client alone is NOT enough: a mounted\n * `useQuery` keeps the `QueryObserver` it was born with, and that observer is bound to the client\n * it was created against, so a child that survives the swap would keep rendering A's cache. The\n * subtree is therefore also re-mounted (`key`), which drops every observer and every piece of\n * child state from the previous identity. The client, the `key` and the tuple handed to\n * `<W6WProvider>` all change in ONE state update: there is no render in which B's tree reads A's\n * cache. The old client is cleared once it is no longer mounted.\n *\n * **Identity switch (flush first).** A draft with a pending save must be written into the account\n * that produced the edit. When `identityKey` changes this provider therefore HOLDS the applied\n * tuple — `identityKey`, `apiOrigin`, `project`, `getSession`, the client — and keeps handing the\n * OLD one to `<W6WProvider>`, awaits `registry.flushAll()` (bounded, never rejects), and only then\n * applies the new tuple in a single update. `<W6WProvider>` swaps its client synchronously on a\n * new `identityKey` and detaches the old session store, so the flush must finish first; and the\n * new `getSession` is NOT forwarded early: `<W6WProvider>` reaches it through the stable wrapper\n * below, whose target is swapped in the same update as the tuple (forwarded early, the new\n * account's token would be minted on the old client). A flush that fails or times out still lets\n * the switch proceed (Q6) and is never retried with the new identity. A token rotation under an\n * unchanged `identityKey` is not a switch: it is forwarded at once, no hold.\n *\n * **No identity.** `identityKey={null}` mounts nothing but `fallback`: no `<W6WProvider>`, no\n * `QueryClientProvider`, no children — so no `getSession` call and no request. `null -> \"A\"`\n * applies at once (nothing can be pending); `\"A\" -> null` takes the SAME flush-first path as any\n * other switch before the fallback renders.\n *\n * **Default project.** `project={{ use: \"default\" }}` resolves ONCE per applied identity, through\n * one `client.projects.list()` query inside the identity-scoped `QueryClient`, to the row with\n * `isDefault === true` — never `list[0]`, never a fallback. `<W6WProvider>` gets no project until\n * it resolves; the client rebuild that follows reuses the cached answer (the query is keyed\n * without the client and lives in a component that stays mounted, so it is not re-issued).\n *\n * **Status.** `useEmbedStatus()` is `deriveEmbedStatus` over the `@w6w/react` session store plus a\n * terminal 401 seen through the forwarded `onUnauthorized`.\n */\nimport {\n W6WProvider,\n type W6WSession,\n createW6WUiAdapter,\n useW6WClient,\n useW6WSession,\n} from \"@w6w/react\";\nimport type { ApiError, FetchLike } from \"@w6w/sdk\";\nimport { type ThemeMode, type W6WApi, W6WUIProvider } from \"@w6w/ui\";\nimport {\n type ReactNode,\n createContext,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { DraftRegistryProvider, EmbedClientProvider, createDraftRegistry } from \"./draft/index.ts\";\nimport { EmbedAuthError, type EmbedStatus, deriveEmbedStatus } from \"./embed-status.ts\";\nimport {\n EmbedProjectContext,\n type EmbedProjectState,\n useProvidedProject,\n} from \"./project-context.ts\";\nimport { updateConnection } from \"./repos/connections.ts\";\nimport { withCredentialMethods } from \"./repos/credentials.ts\";\nimport { listDataStoreEntries, listDataStores } from \"./repos/data-stores.ts\";\nimport { listDocumentKeys } from \"./repos/documents.ts\";\nimport { resolveActionFields, resolveTriggerFields } from \"./repos/fields.ts\";\nimport { listModelRoutes } from \"./repos/models.ts\";\nimport { listSavedFiles } from \"./repos/saved-file-names.ts\";\nimport {\n pollWebhookListen,\n startWebhookListen,\n stopWebhookListen,\n} from \"./repos/webhook-listen.ts\";\nimport { listNodeSamples, listTestInputs, saveTestInput } from \"./repos/workflows.ts\";\nimport { EmbedThemeContext } from \"./theme-context.ts\";\n\nexport interface W6WEmbedProviderProps {\n /** The w6w API origin, e.g. `\"https://api.w6w.io\"`. */\n apiOrigin: string;\n /**\n * Mints a session for the CURRENT host user (`{token, expiresAt, expiresIn?}`). Always the\n * latest callback; the provider caches and renews the result.\n */\n getSession: () => Promise<W6WSession>;\n /**\n * Which signed-in identity this provider speaks for (e.g. `${userId}:${accountId}`). Changing it\n * rebuilds the API client AND replaces the `QueryClient`, so nothing cached for the previous\n * identity is ever shown under the new one.\n */\n identityKey: string | null;\n /**\n * Rendered instead of the embed while `identityKey` is `null` (no signed-in user). Nothing of\n * the embed mounts then: no `getSession` call, no request. Default `null`.\n */\n fallback?: ReactNode;\n /**\n * Start acquiring a session on mount. Without it the session is acquired lazily, by the first\n * request a mounted surface makes, and `useEmbedStatus()` stays `\"connecting\"` until then.\n */\n eager?: boolean;\n /** Force the `@w6w/ui` theme to follow the host's. Omit to resolve it the library's default way. */\n theme?: ThemeMode;\n /** Gates every read hook while `false` (default `true`) — e.g. until the host has a user. */\n ready?: boolean;\n /**\n * Default project for project-scoped operations: a project id, or `{ use: \"default\" }` to use\n * the account's default project (resolved once per identity; see `useEmbedProject()`).\n */\n project?: string | { use: \"default\" };\n /** Transport override (tests, request recording). Defaults to `globalThis.fetch`. */\n fetch?: FetchLike;\n children: ReactNode;\n}\n\nfunction makeQueryClient(): QueryClient {\n // Same defaults as Studio's own client (`studio/src/main.tsx`).\n return new QueryClient({\n defaultOptions: { queries: { retry: false, refetchOnWindowFocus: false } },\n });\n}\n\n/** The part of the tuple that changes only when a switch has been APPLIED (after the flush). */\ninterface Applied {\n identityKey: string | null;\n queryClient: QueryClient;\n}\n\n/** What `<W6WProvider>` is fed while no switch is in progress; frozen at the last such render. */\ninterface Forwarded {\n apiOrigin: string;\n project: string | { use: \"default\" } | undefined;\n getSession: () => Promise<W6WSession>;\n}\n\n/** Hands the SDK client of the nearest `<W6WProvider>` to `useWorkflowDraft`. */\nfunction ClientBridge({ children }: { children: ReactNode }) {\n return <EmbedClientProvider client={useW6WClient()}>{children}</EmbedClientProvider>;\n}\n\n/** The README bridge: `useW6WClient` -> `createW6WUiAdapter` -> `<W6WUIProvider>`. */\nfunction UiBridge({ theme, children }: { theme?: ThemeMode; children: ReactNode }) {\n const client = useW6WClient();\n const provided = useProvidedProject();\n // `createW6WUiAdapter` has no `updateConnection` or `listModelRoutes`; keep them if it ever\n // gains them, else supply the embed repo's own so the ui Edit modal can save and the\n // `@w6w/model` node's Route field offers the project's routes (not free text) in any host.\n const api = useMemo(() => {\n const adapter: W6WApi = createW6WUiAdapter(client);\n if (typeof adapter.updateConnection !== \"function\") {\n adapter.updateConnection = (id, body) => updateConnection(client, id, body);\n }\n withCredentialMethods(adapter, client);\n if (typeof adapter.listModelRoutes !== \"function\") {\n adapter.listModelRoutes = async (editorProject) => {\n const project = editorProject || provided;\n if (!project) return [];\n const routes = await listModelRoutes(client, project);\n return routes.map((r) => ({ name: r.name, model: r.modelId, status: r.status }));\n };\n }\n // Same for the `@w6w/store` node's store picker: the project's store names, not free text.\n if (typeof adapter.listDataStores !== \"function\") {\n adapter.listDataStores = async (editorProject) => {\n const project = editorProject || provided;\n if (!project) return [];\n return listDataStores(client, project);\n };\n }\n // ...and its key picker: one page of the named store's entries, searched by key prefix.\n if (typeof adapter.listDataStoreEntries !== \"function\") {\n adapter.listDataStoreEntries = async (store, opts) => {\n const project = opts.project || provided;\n if (!project) return { items: [] };\n return listDataStoreEntries(client, project, store, opts);\n };\n }\n // The `@w6w/document` node's key picker: the project's document keys, not free text.\n if (typeof adapter.listDocuments !== \"function\") {\n adapter.listDocuments = async (editorProject) => {\n const project = editorProject || provided;\n if (!project) return [];\n return listDocumentKeys(client, project);\n };\n }\n // The `@w6w/files` path picker: the project's saved files.\n if (typeof adapter.listSavedFiles !== \"function\") {\n adapter.listSavedFiles = async (editorProject) => {\n const project = editorProject || provided;\n if (!project) return [];\n return listSavedFiles(client, project);\n };\n }\n // Persisted node samples, so the editor's picker keeps upstream keys across a reload.\n if (typeof adapter.loadNodeSamples !== \"function\") {\n adapter.loadNodeSamples = (workflowId) => listNodeSamples(client, workflowId);\n }\n // Remembered test inputs, so every test form reopens prefilled with the last values used.\n if (typeof adapter.loadTestInputs !== \"function\") {\n adapter.loadTestInputs = (workflowId) => listTestInputs(client, workflowId);\n }\n if (typeof adapter.saveTestInput !== \"function\") {\n adapter.saveTestInput = (workflowId, nodeId, input) =>\n saveTestInput(client, workflowId, nodeId, input);\n }\n if (typeof adapter.resolveActionFields !== \"function\") {\n adapter.resolveActionFields = (appId, actionKey, body, opts) =>\n resolveActionFields(client, appId, actionKey, body, opts);\n }\n if (typeof adapter.resolveTriggerFields !== \"function\") {\n adapter.resolveTriggerFields = (appId, triggerKey, body, opts) =>\n resolveTriggerFields(client, appId, triggerKey, body, opts);\n }\n // The webhook node's Test tab listens for a real request only when all three exist; without\n // them it falls back to the paste-a-payload form.\n if (typeof adapter.startWebhookListen !== \"function\") {\n adapter.startWebhookListen = (subscriptionId) => startWebhookListen(client, subscriptionId);\n adapter.pollWebhookListen = (subscriptionId, sessionId, opts) =>\n pollWebhookListen(client, subscriptionId, sessionId, opts);\n adapter.stopWebhookListen = (subscriptionId, sessionId) =>\n stopWebhookListen(client, subscriptionId, sessionId);\n }\n return adapter;\n }, [client, provided]);\n return (\n <W6WUIProvider api={api} theme={theme}>\n <EmbedThemeContext.Provider value={theme}>{children}</EmbedThemeContext.Provider>\n </W6WUIProvider>\n );\n}\n\nconst EmbedStatusContext = createContext<EmbedStatus>({ status: \"connecting\", error: null });\n\n/** The session status of the nearest `<W6WEmbedProvider>`. See `deriveEmbedStatus`. */\nexport function useEmbedStatus(): EmbedStatus {\n return useContext(EmbedStatusContext);\n}\n\n/** Publishes `useEmbedStatus()`, and starts the session on mount when `eager`. */\nfunction StatusBridge({\n eager,\n authError,\n onAcquire,\n children,\n}: {\n eager: boolean;\n authError: EmbedAuthError | null;\n onAcquire: () => void;\n children: ReactNode;\n}) {\n const { status, error, refresh } = useW6WSession();\n // `refresh` is per session store, so a rebuilt client (project resolved) is started again.\n useEffect(() => {\n if (eager) void refresh();\n }, [eager, refresh]);\n useEffect(() => {\n if (status === \"loading\" || status === \"renewing\") onAcquire();\n }, [status, onAcquire]);\n const value = useMemo(\n () => deriveEmbedStatus(status, error, authError),\n [status, error, authError],\n );\n return <EmbedStatusContext.Provider value={value}>{children}</EmbedStatusContext.Provider>;\n}\n\n/**\n * Resolves `{use:\"default\"}`. Lives INSIDE `<W6WProvider>` (it needs the client) but at a fixed\n * slot, so it survives the client rebuild that follows resolution; the query key carries no\n * client, so nothing refetches.\n */\nfunction DefaultProjectResolver({\n identityKey,\n enabled,\n onState,\n}: {\n identityKey: string;\n enabled: boolean;\n onState: (key: string, state: EmbedProjectState) => void;\n}) {\n const client = useW6WClient();\n const q = useQuery({\n queryKey: [\"w6w-embed\", \"default-project\"],\n enabled,\n queryFn: async () => {\n const rows = await client.projects.list();\n const home = rows.find((p) => p.isDefault === true);\n if (!home) throw new Error(\"The account has no default project.\");\n return home.id;\n },\n });\n const { isError, error, data } = q;\n const state = useMemo<EmbedProjectState>(\n () =>\n isError\n ? { project: null, status: \"error\", error }\n : data !== undefined\n ? { project: data, status: \"ready\" }\n : { project: null, status: \"resolving\" },\n [isError, error, data],\n );\n useEffect(() => {\n onState(identityKey, state);\n }, [identityKey, state, onState]);\n return null;\n}\n\nexport function W6WEmbedProvider({\n apiOrigin,\n getSession,\n identityKey,\n fallback = null,\n eager = false,\n theme,\n ready,\n project,\n fetch,\n children,\n}: W6WEmbedProviderProps): ReactNode {\n const [registry] = useState(createDraftRegistry);\n const [applied, setApplied] = useState<Applied>(() => ({\n identityKey,\n queryClient: makeQueryClient(),\n }));\n\n // While `identityKey` differs from the applied one a switch is pending: everything below keeps\n // using the values frozen at the last render that was not pending. Otherwise props flow straight\n // through (project / origin changes, token rotation). Idempotent latest-value writes, the same\n // pattern `<W6WProvider>` uses for its own refs.\n const switching = identityKey !== applied.identityKey;\n const forwardedRef = useRef<Forwarded>({ apiOrigin, project, getSession });\n if (!switching) forwardedRef.current = { apiOrigin, project, getSession };\n const forwarded = forwardedRef.current;\n\n // The stable `getSession` handed to `<W6WProvider>`: reads whatever is applied RIGHT NOW. Its\n // target changes in the same render that applies the new tuple, never before the flush settles.\n const sessionRef = useRef(forwarded.getSession);\n sessionRef.current = forwarded.getSession;\n const [stableGetSession] = useState(() => () => sessionRef.current());\n\n useEffect(() => {\n if (identityKey === applied.identityKey) return;\n let cancelled = false;\n const apply = () => {\n if (cancelled) return;\n setApplied({ identityKey, queryClient: makeQueryClient() });\n };\n // Nothing is mounted under a null identity, so nothing can be pending: apply at once.\n if (applied.identityKey === null) {\n apply();\n return () => {\n cancelled = true;\n };\n }\n // `flushAll` never rejects and is bounded; the switch proceeds either way (Q6).\n registry.flushAll().then(apply, apply);\n return () => {\n cancelled = true;\n };\n }, [identityKey, applied.identityKey, registry]);\n\n // The replaced client is dropped once nothing mounted reads it.\n const queryClient = applied.queryClient;\n useEffect(() => () => queryClient.clear(), [queryClient]);\n\n // Default-project resolution, tagged with the identity it was resolved for: a result for A is\n // never read once B is applied.\n const [resolved, setResolved] = useState<{ key: string; state: EmbedProjectState } | null>(null);\n const onResolved = useCallback((key: string, state: EmbedProjectState) => {\n setResolved((prev) =>\n prev &&\n prev.key === key &&\n prev.state.project === state.project &&\n prev.state.status === state.status &&\n prev.state.error === state.error\n ? prev\n : { key, state },\n );\n }, []);\n\n // The terminal partner-token 401, tagged with its identity; cleared when the next acquisition\n // starts (StatusBridge) or the identity changes (the tag no longer matches).\n const [authFailure, setAuthFailure] = useState<{\n key: QueryClient;\n error: EmbedAuthError;\n } | null>(null);\n // The handler is bound to the per-mount client it was created for: a late 401 from a previous\n // `<W6WProvider>` is tagged with ITS client, never the one applied by the time it fires — even\n // when the identity key came back (A -> B -> A mints a new client for the same key).\n const onUnauthorized = useMemo(() => {\n const key = applied.queryClient;\n return (error: ApiError) => {\n setAuthFailure({ key, error: new EmbedAuthError(error) });\n };\n }, [applied.queryClient]);\n const clearAuthFailure = useCallback(() => setAuthFailure(null), []);\n\n const appliedKey = applied.identityKey;\n const spec = forwarded.project;\n // Only exactly `{ use: \"default\" }` asks for the account default; null, `{}`, `[]` or any other\n // object (JS hosts, casts) is \"no project\" and makes no lookup.\n const wantsDefault =\n typeof spec === \"object\" && spec !== null && !Array.isArray(spec) && spec.use === \"default\";\n const projectState: EmbedProjectState = useMemo(() => {\n if (typeof spec === \"string\") return { project: spec, status: \"ready\" };\n if (!wantsDefault) return { project: null, status: \"ready\" };\n return resolved && resolved.key === appliedKey\n ? resolved.state\n : { project: null, status: \"resolving\" };\n }, [spec, wantsDefault, resolved, appliedKey]);\n\n if (appliedKey === null) return fallback;\n\n return (\n <DraftRegistryProvider registry={registry}>\n <QueryClientProvider key={appliedKey} client={queryClient}>\n <W6WProvider\n baseUrl={forwarded.apiOrigin}\n getSession={stableGetSession}\n identityKey={appliedKey}\n ready={ready}\n project={projectState.project ?? undefined}\n fetch={fetch}\n onUnauthorized={onUnauthorized}\n >\n {wantsDefault ? (\n <DefaultProjectResolver\n identityKey={appliedKey}\n enabled={ready !== false}\n onState={onResolved}\n />\n ) : null}\n <EmbedProjectContext.Provider value={projectState}>\n <StatusBridge\n eager={eager}\n authError={authFailure && authFailure.key === queryClient ? authFailure.error : null}\n onAcquire={clearAuthFailure}\n >\n <ClientBridge>\n <UiBridge theme={theme}>{children}</UiBridge>\n </ClientBridge>\n </StatusBridge>\n </EmbedProjectContext.Provider>\n </W6WProvider>\n </QueryClientProvider>\n </DraftRegistryProvider>\n );\n}\n"],"names":["EmbedAuthError","cause","deriveEmbedStatus","sessionStatus","sessionError","authError","MAX_PAGES","listSavedFiles","client","project","out","cursor","page","query","response","a","_a","startWebhookListen","subscriptionId","path","pollWebhookListen","sessionId","opts","stopWebhookListen","makeQueryClient","QueryClient","ClientBridge","children","jsx","EmbedClientProvider","useW6WClient","UiBridge","theme","provided","useProvidedProject","api","useMemo","adapter","createW6WUiAdapter","id","body","updateConnection","withCredentialMethods","editorProject","listModelRoutes","r","listDataStores","store","listDataStoreEntries","listDocumentKeys","workflowId","listNodeSamples","listTestInputs","nodeId","input","saveTestInput","appId","actionKey","resolveActionFields","triggerKey","resolveTriggerFields","W6WUIProvider","EmbedThemeContext","EmbedStatusContext","createContext","useEmbedStatus","useContext","StatusBridge","eager","onAcquire","status","error","refresh","useW6WSession","useEffect","value","DefaultProjectResolver","identityKey","enabled","onState","q","useQuery","home","p","isError","data","state","W6WEmbedProvider","apiOrigin","getSession","fallback","ready","fetch","registry","useState","createDraftRegistry","applied","setApplied","switching","forwardedRef","useRef","forwarded","sessionRef","stableGetSession","cancelled","apply","queryClient","resolved","setResolved","onResolved","useCallback","key","prev","authFailure","setAuthFailure","onUnauthorized","clearAuthFailure","appliedKey","spec","wantsDefault","projectState","DraftRegistryProvider","QueryClientProvider","jsxs","W6WProvider","EmbedProjectContext"],"mappings":";;;;;;;;;;;;;;;;;;AAmBO,MAAMA,WAAuB,MAAM;AAAA,EACxC,YAAYC,GAAgB;AAC1B,UAAM,uDAAuD,EAAE,OAAAA,GAAO,GACtE,KAAK,OAAO;AAAA,EACd;AACF;AAOO,SAASC,GACdC,GACAC,GACAC,GACa;AACb,MAAIA,EAAW,QAAO,EAAE,QAAQ,SAAS,OAAOA,EAAA;AAChD,UAAQF,GAAA;AAAA,IACN,KAAK;AAAA,IACL,KAAK;AACH,aAAO,EAAE,QAAQ,SAAS,OAAO,KAAA;AAAA,IACnC,KAAK;AACH,aAAO,EAAE,QAAQ,SAAS,OAAOC,EAAA;AAAA,IACnC,KAAK;AAAA,IACL,KAAK;AACH,aAAO,EAAE,QAAQ,cAAc,OAAO,KAAA;AAAA,EAAK;AAEjD;AC5CA,MAAME,KAAY;AAYlB,eAAsBC,GACpBC,GACAC,GAC4C;;AAC5C,QAAMC,IAAyC,CAAA;AAC/C,MAAIC;AACJ,WAASC,IAAO,GAAGA,IAAON,IAAWM,KAAQ;AAC3C,UAAMC,IAAgC,EAAE,SAAAJ,GAAS,MAAM,aAAA;AACvD,IAAIE,MAAW,WAAWE,EAAM,SAASF;AACzC,UAAMG,IAAW,MAAMN,EAAO,QAAwB;AAAA,MACpD,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,OA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,OAAa3B,sBAG7B+B,IAAA,EAAsB,UAAA5B,GACrB,UAAA,gBAAAjE,EAAC8F,GAAA,EAAqC,QAAQhB,GAC5C,UAAA,gBAAAiB;AAAA,IAACC;AAAA,IAAA;AAAA,MACC,SAASvB,EAAU;AAAA,MACnB,YAAYE;AAAA,MACZ,aAAac;AAAA,MACb,OAAA1B;AAAA,MACA,SAAS6B,EAAa,WAAW;AAAA,MACjC,OAAA5B;AAAA,MACA,gBAAAuB;AAAA,MAEC,UAAA;AAAA,QAAAI,IACC,gBAAA3F;AAAA,UAACgD;AAAA,UAAA;AAAA,YACC,aAAayC;AAAA,YACb,SAAS1B,MAAU;AAAA,YACnB,SAASkB;AAAA,UAAA;AAAA,QAAA,IAET;AAAA,QACJ,gBAAAjF,EAACiG,GAAoB,UAApB,EAA6B,OAAOL,GACnC,UAAA,gBAAA5F;AAAA,UAACuC;AAAA,UAAA;AAAA,YACC,OAAAC;AAAA,YACA,WAAW6C,KAAeA,EAAY,QAAQP,IAAcO,EAAY,QAAQ;AAAA,YAChF,WAAWG;AAAA,YAEX,4BAAC1F,IAAA,EACC,UAAA,gBAAAE,EAACG,IAAA,EAAS,OAAAC,GAAe,UAAAL,GAAS,EAAA,CACpC;AAAA,UAAA;AAAA,QAAA,EACF,CACF;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA,EACF,GA5BwB0F,CA6B1B,GACF;AAEJ;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CallableKind } from './callable-kind.ts';
|
|
2
|
+
/** What the settings modal hands back. */
|
|
3
|
+
export interface CallableSettingsEdit {
|
|
4
|
+
displayName: string;
|
|
5
|
+
key: string | null;
|
|
6
|
+
tags?: string[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The definition to save after a settings edit: `base` (the record as stored, read just before the
|
|
10
|
+
* save) with the edit's name, its key where the kind lets a key change (Function, Workflow; an
|
|
11
|
+
* Endpoint's key is its URL and stays), and its tags only when they differ from `openedTags` (the
|
|
12
|
+
* tags the modal opened with). The modal always hands back a tag list, so presence is not a signal;
|
|
13
|
+
* an untouched list must not overwrite tags the server holds. `base` is never mutated.
|
|
14
|
+
*/
|
|
15
|
+
export declare function applySettingsEdit(kind: CallableKind, base: Record<string, unknown>, edit: CallableSettingsEdit, openedTags: readonly string[]): Record<string, unknown>;
|
|
16
|
+
/** `send-email.function.json`: the key (or name, or id) cut to a safe file name. */
|
|
17
|
+
export declare function specFileName(kind: CallableKind, label: string): string;
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ export * from './input-seeding.ts';
|
|
|
23
23
|
export * from './input-coverage.ts';
|
|
24
24
|
export * from './coerce-input.ts';
|
|
25
25
|
export * from './callable-record.ts';
|
|
26
|
+
export * from './callable-duplicate.ts';
|
|
27
|
+
export * from './callable-row-actions.ts';
|
|
26
28
|
export * from './binding-problems.ts';
|
|
27
29
|
export * from './setup-incomplete.ts';
|
|
28
30
|
export * from './import-bindings.ts';
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The run-events stream client — PURE and Node-testable in full (no React, no runtime import):
|
|
3
|
+
* the SSE frame parser, the per-run stream loop with its reconnect backoff and fallback decision,
|
|
4
|
+
* and the refcounted registry that shares one stream per run between every component watching it.
|
|
5
|
+
* `../repos/workflows.ts`'s `useLiveRunQuery` is the only React caller.
|
|
6
|
+
*
|
|
7
|
+
* WHY. The editor used to poll `GET /runs/:id` (and `GET /runs/:id/state-writes`) every 500 ms
|
|
8
|
+
* for as long as a run was in flight. The server now pushes the run instead:
|
|
9
|
+
*
|
|
10
|
+
* GET /runs/:id/events
|
|
11
|
+
* event: snapshot data = {"run": <exactly GET /runs/:id's `run`>} (full, replaces the last)
|
|
12
|
+
* event: reconnect data = {} the server is ending the stream early: open a new one now
|
|
13
|
+
* event: gone data = {} the run is no longer readable: stop streaming
|
|
14
|
+
* : keep-alive heartbeat comment, about every 15 s
|
|
15
|
+
*
|
|
16
|
+
* Every `snapshot` is the same `RunState` a poll returned, so it goes straight into the query
|
|
17
|
+
* cache and the canvas and the run log need no change.
|
|
18
|
+
*
|
|
19
|
+
* TRANSPORT. `fetch` + `ReadableStream` with the client's `Authorization: Bearer` HEADER, never
|
|
20
|
+
* `EventSource` (it cannot send headers) and never a token in the URL (it would land in access
|
|
21
|
+
* logs). The token, base URL and default headers are read off the caller's `W6WClient.config`, so
|
|
22
|
+
* the public `@w6w/sdk` surface is unchanged.
|
|
23
|
+
*
|
|
24
|
+
* A RUN NEVER LOOKS FROZEN. The loop reports a {@link RunStreamMode}; the hook polls exactly as it
|
|
25
|
+
* used to whenever the mode is `fallback`:
|
|
26
|
+
* - a refusal (`401`/`403`/`404`, or a `2xx` that is not `text/event-stream`, e.g. an older
|
|
27
|
+
* server without the route) is final: `fallback` for the rest of the run, no retry;
|
|
28
|
+
* - a drop (a network error, any other status, the stream ending before a terminal snapshot, or
|
|
29
|
+
* no byte at all for {@link RunStreamOptions.idleTimeoutMs}) is `fallback` WHILE the loop
|
|
30
|
+
* reconnects with exponential backoff, and `live` again on the next snapshot;
|
|
31
|
+
* - a stream that has not delivered its first snapshot within
|
|
32
|
+
* {@link RunStreamOptions.firstSnapshotMs} (a buffering proxy) is `fallback` until it does;
|
|
33
|
+
* - `reconnect` (the server's lifetime cap, or an instance shutting down) reconnects at once and
|
|
34
|
+
* stays `live`: the new stream opens with a fresh snapshot, so nothing is lost.
|
|
35
|
+
*/
|
|
36
|
+
/** One dispatched SSE event. Comment lines never become events. */
|
|
37
|
+
export interface SseEvent {
|
|
38
|
+
event: string;
|
|
39
|
+
data: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Incremental SSE parser (the WHATWG event-stream rules this wire uses): feed it decoded text in
|
|
43
|
+
* any chunking; it returns the events completed so far. `onActivity` is the caller's business —
|
|
44
|
+
* every chunk, heartbeat comments included, counts as the connection being alive.
|
|
45
|
+
*/
|
|
46
|
+
export declare class SseParser {
|
|
47
|
+
#private;
|
|
48
|
+
push(chunk: string): SseEvent[];
|
|
49
|
+
}
|
|
50
|
+
/** Where the stream lives, relative to the API base. */
|
|
51
|
+
export declare function runEventsPath(runId: string): string;
|
|
52
|
+
/**
|
|
53
|
+
* - `connecting`: the first request is in flight and no snapshot has arrived yet;
|
|
54
|
+
* - `live`: snapshots are arriving — the hook does not poll;
|
|
55
|
+
* - `fallback`: the stream is refused or down — the hook polls `GET /runs/:id` as it used to;
|
|
56
|
+
* - `done`: a terminal snapshot arrived (or the stream was stopped) — nothing more to fetch.
|
|
57
|
+
*/
|
|
58
|
+
export type RunStreamMode = "connecting" | "live" | "fallback" | "done";
|
|
59
|
+
/** The run statuses after which nothing about a run changes again. */
|
|
60
|
+
export declare function isTerminalRunStatusLike(status: unknown): boolean;
|
|
61
|
+
/** The slice of a `@w6w/sdk` `W6WClient.config` the stream reads (structural, no import). */
|
|
62
|
+
export interface StreamClientConfig {
|
|
63
|
+
baseUrl: string;
|
|
64
|
+
token: string | ((ctx?: {
|
|
65
|
+
forceRefresh?: boolean;
|
|
66
|
+
}) => string | null | undefined | Promise<string | null | undefined>) | null;
|
|
67
|
+
headers?: Record<string, string>;
|
|
68
|
+
}
|
|
69
|
+
/** The request headers for one stream attempt, or `null` when there is no token to send. */
|
|
70
|
+
export declare function streamHeaders(config: StreamClientConfig): Promise<Record<string, string> | null>;
|
|
71
|
+
export type FetchLike = (url: string, init: RequestInit) => Promise<Response>;
|
|
72
|
+
export interface RunStreamOptions {
|
|
73
|
+
config: StreamClientConfig;
|
|
74
|
+
runId: string;
|
|
75
|
+
fetchImpl: FetchLike;
|
|
76
|
+
signal: AbortSignal;
|
|
77
|
+
onSnapshot: (run: Record<string, unknown>) => void;
|
|
78
|
+
onMode: (mode: RunStreamMode) => void;
|
|
79
|
+
/** Injected for tests. Must settle early (resolve) when `signal` aborts. */
|
|
80
|
+
sleep?: (ms: number, signal: AbortSignal) => Promise<void>;
|
|
81
|
+
/** Fall back to polling if no snapshot arrived this long after a request started. */
|
|
82
|
+
firstSnapshotMs?: number;
|
|
83
|
+
/** Treat the connection as dead after this long without a byte (heartbeats included). */
|
|
84
|
+
idleTimeoutMs?: number;
|
|
85
|
+
/** Reconnect backoff after a drop: `retryMinMs` doubling up to `retryMaxMs`. */
|
|
86
|
+
retryMinMs?: number;
|
|
87
|
+
retryMaxMs?: number;
|
|
88
|
+
}
|
|
89
|
+
export declare function abortableSleep(ms: number, signal: AbortSignal): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Stream one run until a terminal snapshot, a refusal, `gone`, or `signal` aborts. Never rejects.
|
|
92
|
+
* Resolves with the final mode it reported.
|
|
93
|
+
*/
|
|
94
|
+
export declare function streamRun(opts: RunStreamOptions): Promise<RunStreamMode>;
|
|
95
|
+
/**
|
|
96
|
+
* One shared stream per run. Every component that watches a run (the editor canvas, the run log,
|
|
97
|
+
* the starting-state rail) calls {@link RunStreamRegistry.acquire}; the first starts the stream,
|
|
98
|
+
* the last release stops it. The release is deferred by a tick so React StrictMode's
|
|
99
|
+
* unmount/remount in development reuses the stream instead of opening a second one.
|
|
100
|
+
*/
|
|
101
|
+
export declare class RunStreamRegistry {
|
|
102
|
+
#private;
|
|
103
|
+
/** `start` opens the stream for a run (normally {@link streamRun}) and stops on `signal`. */
|
|
104
|
+
constructor(start: (runId: string, signal: AbortSignal, onMode: (mode: RunStreamMode) => void) => void);
|
|
105
|
+
/** The run's current stream mode, or `null` when nothing streams it. */
|
|
106
|
+
mode(runId: string): RunStreamMode | null;
|
|
107
|
+
/** Subscribe to mode changes of one run (for `useSyncExternalStore`). */
|
|
108
|
+
subscribe(runId: string, listener: () => void): () => void;
|
|
109
|
+
acquire(runId: string): () => void;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Should the hook poll `GET /runs/:id` right now? Only when no stream carries the run (`null`:
|
|
113
|
+
* none started, e.g. a run already known terminal or a host without a streaming client) or the
|
|
114
|
+
* stream is down (`fallback`). While `connecting`, `live` or `done`, the stream owns the cache.
|
|
115
|
+
*/
|
|
116
|
+
export declare function pollWhileStreaming(mode: RunStreamMode | null): boolean;
|
|
117
|
+
/**
|
|
118
|
+
* A signature of what the run's state-write log can depend on: the run status plus each node's
|
|
119
|
+
* status. The hook re-reads `GET /runs/:id/state-writes` when it changes — once per step that
|
|
120
|
+
* finishes — instead of polling that route every 500 ms.
|
|
121
|
+
*/
|
|
122
|
+
export declare function stateWritesSignature(run: Record<string, unknown>): string;
|
package/dist/lib/tag-editor.d.ts
CHANGED
|
@@ -28,6 +28,12 @@ export declare function commitTag(tags: string[], typed: string): {
|
|
|
28
28
|
tags: string[];
|
|
29
29
|
typed: string;
|
|
30
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* The tags the editor ends up with if what is still typed in its input counts too — the typed
|
|
33
|
+
* text is committed exactly as if a `,` followed it. A save uses this, so a tag typed without the
|
|
34
|
+
* comma is saved rather than silently dropped.
|
|
35
|
+
*/
|
|
36
|
+
export declare function withPendingTag(tags: string[], typed: string): string[];
|
|
31
37
|
/**
|
|
32
38
|
* Removes exactly one tag by VALUE, never by position — a list carrying both
|
|
33
39
|
* a tag and a second tag that merely contains it as a prefix (`["ab", "b"]`)
|
|
@@ -38,6 +38,8 @@ export interface StepExecutionLike {
|
|
|
38
38
|
error?: unknown;
|
|
39
39
|
/** Recorded metadata; absent (or null) for steps that recorded none. */
|
|
40
40
|
meta?: StepMetaLike | null;
|
|
41
|
+
/** `NodeExecution.usage` — the step's sandbox figures; read as `unknown` (opaque wire). */
|
|
42
|
+
usage?: unknown;
|
|
41
43
|
/** For each only (I3): per-iteration body records, read as `unknown` (opaque wire). */
|
|
42
44
|
iterations?: unknown;
|
|
43
45
|
iterationsTotal?: unknown;
|
|
@@ -101,6 +103,11 @@ export interface ExecutionLogStepLike {
|
|
|
101
103
|
logs?: string[];
|
|
102
104
|
error?: LogErrorLike;
|
|
103
105
|
meta?: StepMetaLike;
|
|
106
|
+
/** Peak memory and CPU time, the finite non-negative figures only (`@w6w/ui`'s `usage`). */
|
|
107
|
+
usage?: {
|
|
108
|
+
memoryBytes?: number;
|
|
109
|
+
cpuMs?: number;
|
|
110
|
+
};
|
|
104
111
|
/** For each only (I4) — field-for-field `@w6w/ui`'s `ExecutionLogStep`. */
|
|
105
112
|
iterations?: ExecutionLogIterationLike[];
|
|
106
113
|
iterationsTotal?: number;
|
|
@@ -88,11 +88,17 @@ export interface ValidityContext {
|
|
|
88
88
|
testStatus: Record<string, boolean>;
|
|
89
89
|
/** `@w6w/ui`'s `requiredParamsFilled`, injected (see module docstring). */
|
|
90
90
|
requiredParamsFilled: (params: ActionParamLike[], values: Record<string, unknown>) => boolean;
|
|
91
|
+
/**
|
|
92
|
+
* `@w6w/ui`'s `paramsValid`, injected like `requiredParamsFilled`: false when a filled value is
|
|
93
|
+
* invalid (a cron, a regex, a time zone, a declared `validation` rule). Optional — without it
|
|
94
|
+
* only required-ness is checked.
|
|
95
|
+
*/
|
|
96
|
+
paramsValid?: (params: ActionParamLike[], values: Record<string, unknown>) => boolean;
|
|
91
97
|
/** @deprecated Kept for caller compatibility; never consulted for publishing. */
|
|
92
98
|
isTestRequired: (app: unknown) => boolean;
|
|
93
99
|
}
|
|
94
100
|
/** Which of the pinned predicate's checks a step fails, or `null` when it's valid. */
|
|
95
|
-
type StepFailure = "target missing" | "required params";
|
|
101
|
+
type StepFailure = "target missing" | "required params" | "invalid params";
|
|
96
102
|
/** Is this one step valid, per the pinned predicate? */
|
|
97
103
|
export declare function stepValid(step: WorkflowStepLike, ctx: ValidityContext): boolean;
|
|
98
104
|
/**
|
package/dist/lib.mjs
CHANGED
|
@@ -1,100 +1,105 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { d as l, f as d, a as
|
|
3
|
-
import { d as
|
|
4
|
-
import { a as
|
|
5
|
-
import { d as
|
|
6
|
-
import { A as la, b as da, f as
|
|
2
|
+
import { d as l, f as d, a as p, i as c, p as u, b as m, r as f, c as g, s as S, t as b, e as w, w as R, g as v } from "./setup-incomplete-6PAbN0EW.js";
|
|
3
|
+
import { d as F, a as h, e as D, i as x, b as I, p as C, r as E, c as K, f as P, s as U, g as A, t as T, v as N, h as k } from "./document-sources-Khcw2zB5.js";
|
|
4
|
+
import { a as V, b as W, e as _, h as B, c as O, d as j, i as H, m as q, p as G, r as M, f as Y, g as $, s as z, j as J, k as Q, l as X, t as Z, v as aa, w as ea, n as sa } from "./import-bindings-EUtxZ9Ti.js";
|
|
5
|
+
import { d as ia, i as ra, p as oa } from "./settings-rail-gUU2ZbSw.js";
|
|
6
|
+
import { A as la, b as da, f as pa, i as ca, a as ua, c as ma, s as fa, u as ga } from "./slug-BVdgiP_L.js";
|
|
7
7
|
import { i as ba, s as wa } from "./spec-import-invalidation-D3retX4Q.js";
|
|
8
|
-
import { U as va, b as
|
|
9
|
-
import { I as
|
|
10
|
-
import {
|
|
11
|
-
function
|
|
8
|
+
import { U as va, b as ya, n as Fa } from "./workflow-blank-BJFLdGyE.js";
|
|
9
|
+
import { I as Da, c as xa, f as Ia, i as Ca, a as Ea, m as Ka, p as Pa, s as Ua, t as Aa, b as Ta, d as Na, u as ka, e as La, g as Va } from "./coerce-input-DFJ4n_wc.js";
|
|
10
|
+
import { a as _a, c as Ba, b as Oa, d as ja, e as Ha, s as qa } from "./callable-row-actions-BPBPflMn.js";
|
|
11
|
+
function i(s) {
|
|
12
12
|
const e = new URLSearchParams(s), a = e.get("edit");
|
|
13
13
|
if (a === null || a === "") return null;
|
|
14
14
|
e.delete("edit");
|
|
15
15
|
const t = e.toString();
|
|
16
16
|
return { id: a, search: t === "" ? "" : `?${t}` };
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function r(s) {
|
|
19
19
|
const a = new URLSearchParams(s).get("run");
|
|
20
20
|
return a != null && a.startsWith("run_") ? a : null;
|
|
21
21
|
}
|
|
22
22
|
export {
|
|
23
23
|
la as ACCOUNT_SLUG_RE,
|
|
24
|
-
|
|
24
|
+
Da as INPUT_TYPES,
|
|
25
25
|
va as UNTITLED_WORKFLOW,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
V as allowedModes,
|
|
27
|
+
_a as applySettingsEdit,
|
|
28
|
+
ya as blankDefinition,
|
|
29
|
+
W as buildRows,
|
|
29
30
|
da as buildSnippet,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
Ba as callableRecord,
|
|
32
|
+
xa as coerceInput,
|
|
33
|
+
Oa as copyDisplayName,
|
|
34
|
+
ja as copyKey,
|
|
35
|
+
ia as definitionWithPolicy,
|
|
33
36
|
l as disabledBannerState,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
F as documentSampleValues,
|
|
38
|
+
Ha as duplicateDefinition,
|
|
39
|
+
h as duplicateKeyIndexes,
|
|
40
|
+
D as errorHandlerSelfDecision,
|
|
37
41
|
_ as evaluateEdit,
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
Ia as fieldsFromWorkflow,
|
|
43
|
+
pa as filterKeyInput,
|
|
40
44
|
d as findBindingProblems,
|
|
41
|
-
|
|
45
|
+
p as findSetupIncomplete,
|
|
42
46
|
B as hasDefinitionActions,
|
|
43
47
|
O as hasDelete,
|
|
44
48
|
j as hasVersionHistory,
|
|
45
49
|
Ca as implToTarget,
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
Ea as inputsForSave,
|
|
51
|
+
c as invalidReason,
|
|
48
52
|
ba as invalidateImportedCallable,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
x as isCodeRailAvailable,
|
|
54
|
+
ca as isEndpointKey,
|
|
55
|
+
I as isExprDefault,
|
|
52
56
|
H as isRowArchived,
|
|
53
|
-
|
|
57
|
+
ra as isSettingsRailAvailable,
|
|
54
58
|
ua as isUrnAddressable,
|
|
55
59
|
ma as isValidAccountSlug,
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
i as legacyEditRedirect,
|
|
61
|
+
Ka as mergeSeed,
|
|
58
62
|
q as metadataFieldsForKind,
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
Fa as nextUntitledName,
|
|
64
|
+
Pa as paramsToFields,
|
|
61
65
|
G as parseImportPaste,
|
|
62
66
|
oa as policyFromDefinition,
|
|
63
67
|
C as projectDocumentSources,
|
|
64
68
|
u as publishDisabledReason,
|
|
65
69
|
m as publishProblems,
|
|
66
70
|
f as readSettings,
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
E as readStartingData,
|
|
72
|
+
K as readVariables,
|
|
69
73
|
g as readWorkflowStatus,
|
|
70
74
|
M as restoreRailState,
|
|
71
75
|
Y as rowReady,
|
|
72
76
|
$ as rowsReady,
|
|
73
|
-
|
|
74
|
-
|
|
77
|
+
P as runFormFields,
|
|
78
|
+
r as runParamFromSearch,
|
|
75
79
|
z as setBind,
|
|
76
80
|
J as setCreateName,
|
|
77
81
|
Q as setUnconfigured,
|
|
78
|
-
|
|
82
|
+
Ua as shouldSeed,
|
|
79
83
|
fa as slugify,
|
|
80
84
|
X as specCollectionForKind,
|
|
85
|
+
qa as specFileName,
|
|
81
86
|
wa as specImportListKey,
|
|
82
|
-
|
|
83
|
-
|
|
87
|
+
U as startingDataCollisions,
|
|
88
|
+
A as startingDataForSave,
|
|
84
89
|
S as stepValid,
|
|
85
|
-
|
|
90
|
+
Aa as targetIsBound,
|
|
86
91
|
Ta as targetRef,
|
|
87
|
-
|
|
92
|
+
Na as targetToImpl,
|
|
88
93
|
Z as toSelections,
|
|
89
94
|
T as toSnippetCallable,
|
|
90
95
|
b as triggerInputSeed,
|
|
91
96
|
w as triggerPreviews,
|
|
92
97
|
ga as unavailableReason,
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
+
ka as uncoveredForEndpoint,
|
|
99
|
+
La as uncoveredForFunction,
|
|
100
|
+
Va as uncoveredRequiredKeys,
|
|
101
|
+
N as variablesForSave,
|
|
102
|
+
k as varsRailFor,
|
|
98
103
|
aa as visibleRows,
|
|
99
104
|
ea as withCreatedConnection,
|
|
100
105
|
sa as workflowKeyEditAllowed,
|
|
@@ -15,6 +15,17 @@ export interface CallableRowFacts {
|
|
|
15
15
|
metaExtra?: ReactNode;
|
|
16
16
|
/** "Copy …" menu items. */
|
|
17
17
|
copy?: readonly CopyItem[];
|
|
18
|
+
/** The stored key, when `keyText` shows something else (a keyless Workflow shows its name). */
|
|
19
|
+
key?: string | null;
|
|
20
|
+
/** The row's tags, which the menu's Rename… opens with. */
|
|
21
|
+
tags?: readonly string[];
|
|
22
|
+
}
|
|
23
|
+
/** Host routes the row menu offers beyond the row click itself. Each is optional. */
|
|
24
|
+
export interface CallableRowLinks {
|
|
25
|
+
/** A row's own page, for the menu's Open in new tab. Falls back to `getHref`. */
|
|
26
|
+
getNewTabHref?: (id: string) => string;
|
|
27
|
+
/** Set, the menu offers Run history, which calls it. */
|
|
28
|
+
onOpenHistory?: (id: string) => void;
|
|
18
29
|
}
|
|
19
30
|
/**
|
|
20
31
|
* The internal frame the three kind lists (`FunctionList`, `EndpointList`, `WorkflowList`) share:
|
|
@@ -44,6 +55,7 @@ export declare function CallableKindList<Row extends {
|
|
|
44
55
|
project: string | null;
|
|
45
56
|
onOpen?: (id: string, event?: React.MouseEvent<Element>) => void;
|
|
46
57
|
getHref?: (id: string) => string;
|
|
58
|
+
links?: CallableRowLinks;
|
|
47
59
|
onCreate: () => void;
|
|
48
60
|
creating?: boolean;
|
|
49
61
|
error?: string | null;
|
|
@@ -24,7 +24,7 @@ export interface CopyItem {
|
|
|
24
24
|
label: string;
|
|
25
25
|
value: string;
|
|
26
26
|
}
|
|
27
|
-
/** The row's three-dots menu, with its own
|
|
27
|
+
/** The row's three-dots menu, with its own dialogs for Rename, Archive and Delete. */
|
|
28
28
|
export declare function CallableRowMenu(props: {
|
|
29
29
|
kind: CallableKind;
|
|
30
30
|
id: string;
|
|
@@ -35,4 +35,11 @@ export declare function CallableRowMenu(props: {
|
|
|
35
35
|
siblings?: () => DuplicateSiblings;
|
|
36
36
|
/** Where Duplicate creates the copy — a Workflow is project-scoped, the others ignore it. */
|
|
37
37
|
project?: string | null;
|
|
38
|
+
/** The row's key and tags, which Rename… opens with. */
|
|
39
|
+
keyText?: string | null;
|
|
40
|
+
tags?: readonly string[];
|
|
41
|
+
/** The row's own page; set, the menu offers Open in new tab. */
|
|
42
|
+
href?: string;
|
|
43
|
+
/** Set, the menu offers Run history. */
|
|
44
|
+
onHistory?: () => void;
|
|
38
45
|
}): import("react").JSX.Element;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CallableListProps } from '@w6w/ui';
|
|
2
|
+
import { CallableRowLinks } from './CallableKindList.tsx';
|
|
2
3
|
export interface EndpointListProps {
|
|
3
4
|
/** Project for Import only (the Endpoints list itself is account-wide). Omitted: the provider's. */
|
|
4
5
|
project?: string | null;
|
|
@@ -6,6 +7,8 @@ export interface EndpointListProps {
|
|
|
6
7
|
onOpen?: (id: string, event?: React.MouseEvent<Element>) => void;
|
|
7
8
|
/** When set, each row is a real `<a href>`; a click still calls `onOpen`. */
|
|
8
9
|
getHref?: (id: string) => string;
|
|
10
|
+
/** Host routes for the row menu's Open in new tab and Run history. */
|
|
11
|
+
links?: CallableRowLinks;
|
|
9
12
|
/** An Endpoint was created from the list's New button; receives the SERVER's id. */
|
|
10
13
|
onCreated?: (id: string) => void;
|
|
11
14
|
slots?: CallableListProps["slots"];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CallableListProps } from '@w6w/ui';
|
|
2
|
+
import { CallableRowLinks } from './CallableKindList.tsx';
|
|
2
3
|
export interface FunctionListProps {
|
|
3
4
|
/** Project for Import only (the Functions list itself is account-wide). Omitted: the provider's. */
|
|
4
5
|
project?: string | null;
|
|
@@ -6,6 +7,8 @@ export interface FunctionListProps {
|
|
|
6
7
|
onOpen?: (id: string, event?: React.MouseEvent<Element>) => void;
|
|
7
8
|
/** When set, each row is a real `<a href>`; a click still calls `onOpen`. */
|
|
8
9
|
getHref?: (id: string) => string;
|
|
10
|
+
/** Host routes for the row menu's Open in new tab and Run history. */
|
|
11
|
+
links?: CallableRowLinks;
|
|
9
12
|
/** A Function was created from the list's New button; receives the SERVER's id. */
|
|
10
13
|
onCreated?: (id: string) => void;
|
|
11
14
|
slots?: CallableListProps["slots"];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CallableListProps } from '@w6w/ui';
|
|
2
|
+
import { CallableRowLinks } from './CallableKindList.tsx';
|
|
2
3
|
export interface WorkflowListProps {
|
|
3
4
|
/** The project whose Workflows are listed and created. Omitted: the provider's project. */
|
|
4
5
|
project?: string | null;
|
|
@@ -6,6 +7,8 @@ export interface WorkflowListProps {
|
|
|
6
7
|
onOpen?: (id: string, event?: React.MouseEvent<Element>) => void;
|
|
7
8
|
/** When set, each row is a real `<a href>`; a click still calls `onOpen`. */
|
|
8
9
|
getHref?: (id: string) => string;
|
|
10
|
+
/** Host routes for the row menu's Open in new tab and Run history. */
|
|
11
|
+
links?: CallableRowLinks;
|
|
9
12
|
/** A blank Workflow was created from the list's New button; receives the SERVER's id. */
|
|
10
13
|
onCreated?: (id: string) => void;
|
|
11
14
|
slots?: CallableListProps["slots"];
|