@uniqbit/mate-core 0.18.5 → 1.0.0-canary.2
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/claude-capability-plugins/companion-mentions/.claude-plugin/marketplace.json +14 -0
- package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +8 -0
- package/claude-capability-plugins/companion-mentions/hooks/companion.ts +457 -0
- package/claude-capability-plugins/companion-mentions/hooks/hooks.json +1 -0
- package/claude-capability-plugins/companion-mentions/hooks/register.ts +403 -0
- package/claude-plugin/hooks/companion-instructions.mjs +9 -0
- package/claude-plugin/hooks/hooks.json +21 -2
- package/claude-plugin/hooks/tokensave-route.mjs +52 -0
- package/opencode-plugin/src/server.ts +4 -0
- package/opencode-plugin/src/tui.tsx +2 -0
- package/opencode-plugin/tui.tsx +2 -0
- package/package.json +52 -15
- package/src/brand/art.generated.ts +69 -0
- package/src/brand/index.ts +12 -0
- package/src/brand/palette.ts +19 -0
- package/src/brand/svg.generated.ts +8 -0
- package/src/brand/terminal.ts +88 -0
- package/src/brand/types.ts +33 -0
- package/src/cli/commands/artifact/apply-context.ts +275 -0
- package/src/cli/commands/artifact/artifact.ts +12 -0
- package/src/cli/commands/artifact/delivery/archive.ts +125 -0
- package/src/cli/commands/artifact/delivery/branch-flags.ts +55 -0
- package/src/cli/commands/artifact/delivery/environment.ts +127 -0
- package/src/cli/commands/artifact/delivery/link.ts +174 -0
- package/src/cli/commands/artifact/delivery/output.ts +89 -0
- package/src/cli/commands/artifact/finish/command.ts +83 -8
- package/src/cli/commands/artifact/finish/engine.ts +91 -14
- package/src/cli/commands/artifact/finish/finisher.ts +10 -0
- package/src/cli/commands/artifact/finish/git.ts +132 -19
- package/src/cli/commands/artifact/finish/openspec.ts +182 -138
- package/src/cli/commands/artifact/finish/secret-scan.ts +43 -0
- package/src/cli/commands/artifact/finish/worktree-cleanup.ts +92 -0
- package/src/cli/commands/artifact/pending/command.ts +31 -3
- package/src/cli/commands/artifact/pending/discovery.ts +21 -57
- package/src/cli/commands/cap/graphify.ts +52 -3
- package/src/cli/commands/cap/index-cmd.ts +71 -15
- package/src/cli/commands/cap/openspec.ts +13 -25
- package/src/cli/commands/cap/tokensave.ts +7 -5
- package/src/cli/commands/companion/link.ts +14 -1
- package/src/cli/commands/companion/open.ts +68 -46
- package/src/cli/commands/companion/sync.ts +10 -0
- package/src/cli/commands/companion/tui.ts +17 -7
- package/src/cli/commands/companion/update.ts +143 -48
- package/src/cli/commands/doctor.ts +195 -7
- package/src/cli/commands/factory/factory.ts +301 -0
- package/src/cli/commands/install.ts +133 -9
- package/src/cli/commands/launch/shared.ts +16 -11
- package/src/cli/commands/plugin/install.ts +9 -4
- package/src/cli/commands/plugin/plugin.ts +3 -2
- package/src/cli/commands/report/adapter.ts +11 -2
- package/src/cli/commands/report/contract.ts +21 -0
- package/src/cli/commands/report/highlight.ts +34 -4
- package/src/cli/commands/report/index.ts +20 -1
- package/src/cli/commands/report/markdown.ts +110 -0
- package/src/cli/commands/report/palette.ts +118 -0
- package/src/cli/commands/report/renderer.ts +456 -153
- package/src/cli/commands/report/types.ts +16 -0
- package/src/cli/commands/session/context.ts +102 -0
- package/src/cli/commands/setup.ts +50 -24
- package/src/cli/commands/studio/factory-credential.ts +49 -0
- package/src/cli/commands/studio/index.ts +29 -2
- package/src/cli/commands/studio/openspec-cli.ts +10 -58
- package/src/cli/commands/studio/payload.ts +249 -15
- package/src/cli/commands/studio/routes.ts +41 -6
- package/src/cli/commands/studio/selection.ts +161 -17
- package/src/cli/commands/studio/server.ts +404 -324
- package/src/cli/commands/studio/services.ts +60 -0
- package/src/cli/commands/studio/studio-app.ts +67 -0
- package/src/cli/commands/studio/terminal-assets.ts +21 -33
- package/src/cli/commands/studio/terminal.ts +85 -15
- package/src/cli/commands/studio/views/model.ts +18 -0
- package/src/cli/commands/studio/views/vault/markdown-tree.ts +267 -0
- package/src/cli/commands/studio/views/vault/view.ts +185 -0
- package/src/cli/commands/studio/workset-session.ts +131 -0
- package/src/cli/commands/unwrap.ts +8 -0
- package/src/cli/commands/update.ts +27 -1
- package/src/cli/commands/working/cleanup.ts +10 -1
- package/src/cli/commands/working/link.ts +76 -0
- package/src/cli/commands/working/working.ts +10 -0
- package/src/cli/commands/working/worktree.ts +356 -0
- package/src/cli/commands/wrap.ts +5 -13
- package/src/cli/companion-link-wizard.tsx +2 -0
- package/src/cli/companion-selector.tsx +2 -0
- package/src/cli/confirm.ts +2 -0
- package/src/cli/install-plan.tsx +127 -160
- package/src/cli/launch-selector.tsx +2 -0
- package/src/cli/main.ts +22 -1
- package/src/cli/parse-flags.ts +32 -6
- package/src/cli/repo-list-table.tsx +2 -0
- package/src/cli/setup-selector.tsx +86 -151
- package/src/cli/usage.ts +14 -0
- package/src/create-mate.ts +5 -4
- package/src/hooks/companion-instructions.ts +190 -0
- package/src/hooks/hook-io.ts +63 -0
- package/src/hooks/session-banner.ts +21 -29
- package/src/hooks/session-guidance.ts +9 -17
- package/src/hooks/session-prepare.ts +115 -28
- package/src/hooks/tokensave-route.ts +26 -0
- package/src/hooks/validate-artifact-path.ts +82 -24
- package/src/index.ts +4 -0
- package/src/lib/apply-context/fingerprint.ts +174 -0
- package/src/lib/apply-context/protocol.ts +193 -0
- package/src/lib/change-layout.ts +154 -0
- package/src/lib/components/confirm-prompt.tsx +21 -9
- package/src/lib/components/select-menu.tsx +10 -3
- package/src/lib/components/spinner.tsx +4 -2
- package/src/lib/components/startup-progress.tsx +227 -41
- package/src/lib/components/text-input-display.tsx +2 -0
- package/src/lib/components/wizard-footer.tsx +2 -0
- package/src/lib/components/wizard-header.tsx +16 -12
- package/src/lib/context-mode-package.ts +24 -11
- package/src/lib/delivery/archive-change.ts +166 -0
- package/src/lib/delivery/branches.ts +132 -0
- package/src/lib/delivery/environment.ts +35 -0
- package/src/lib/delivery/forge.ts +279 -0
- package/src/lib/delivery/merge-git.ts +261 -0
- package/src/lib/delivery/overlap.ts +209 -0
- package/src/lib/delivery/record-delivery.ts +283 -0
- package/src/lib/delivery/record.ts +403 -0
- package/src/lib/delivery/refresh.ts +268 -0
- package/src/lib/delivery/repository-access.ts +141 -0
- package/src/lib/delivery/resolve-branch.ts +162 -0
- package/src/lib/delivery/stages.ts +111 -0
- package/src/lib/delivery/token.ts +24 -0
- package/src/lib/factory/attach-client.ts +113 -0
- package/src/lib/factory/attach.ts +178 -0
- package/src/lib/factory/broker.ts +190 -0
- package/src/lib/factory/bun-commands.ts +39 -0
- package/src/lib/factory/client.ts +92 -0
- package/src/lib/factory/command.ts +61 -0
- package/src/lib/factory/credential-store.ts +153 -0
- package/src/lib/factory/frames.ts +77 -0
- package/src/lib/factory/ids.ts +58 -0
- package/src/lib/factory/keyed-serial.ts +27 -0
- package/src/lib/factory/outcomes/actions.ts +114 -0
- package/src/lib/factory/outcomes/index.ts +381 -0
- package/src/lib/factory/outcomes/lifecycle.ts +205 -0
- package/src/lib/factory/outcomes/runs.ts +81 -0
- package/src/lib/factory/outcomes/sessions.ts +38 -0
- package/src/lib/factory/prepare.ts +49 -0
- package/src/lib/factory/pty.ts +103 -0
- package/src/lib/factory/runner/companion-context.ts +178 -0
- package/src/lib/factory/runner/control.ts +92 -0
- package/src/lib/factory/runner/harness-agent.ts +250 -0
- package/src/lib/factory/runner/live.ts +159 -0
- package/src/lib/factory/runner/questions.ts +22 -0
- package/src/lib/factory/runner/rank.ts +26 -0
- package/src/lib/factory/runner/run-policy.ts +12 -0
- package/src/lib/factory/runner/run.ts +199 -0
- package/src/lib/factory/runner/scheduler.ts +416 -0
- package/src/lib/factory/runner/state.ts +233 -0
- package/src/lib/factory/runner/workflow.ts +542 -0
- package/src/lib/factory/runtime.ts +972 -0
- package/src/lib/factory/sandbox.ts +292 -0
- package/src/lib/factory/worktree-branch.ts +17 -0
- package/src/lib/frontmatter.ts +18 -0
- package/src/lib/install.ts +66 -14
- package/src/lib/live-progress.ts +36 -0
- package/src/lib/member-choices.ts +67 -0
- package/src/lib/opencode-plugin-package.ts +5 -5
- package/src/lib/openspec-cli.ts +116 -0
- package/src/lib/openspec-scopes.ts +86 -0
- package/src/lib/orchestrator/adapters/base.ts +55 -22
- package/src/lib/orchestrator/adapters/claude-args.ts +50 -0
- package/src/lib/orchestrator/adapters/claude.ts +54 -41
- package/src/lib/orchestrator/adapters/opencode.ts +2 -0
- package/src/lib/orchestrator/config-store.ts +3 -2
- package/src/lib/orchestrator/editor.ts +31 -25
- package/src/lib/orchestrator/openspec-store.ts +14 -54
- package/src/lib/orchestrator/projection-claude-commands.ts +36 -0
- package/src/lib/orchestrator/projection-claude-links.ts +159 -0
- package/src/lib/orchestrator/projection-claude-skills.ts +19 -137
- package/src/lib/orchestrator/projection-entries.ts +100 -34
- package/src/lib/orchestrator/projection-opencode-copies.ts +32 -15
- package/src/lib/orchestrator/projection-openspec-store.ts +54 -9
- package/src/lib/orchestrator/projection-runtime-documents.ts +15 -6
- package/src/lib/orchestrator/projection-types.ts +36 -1
- package/src/lib/orchestrator/refresh-working-claude-links.ts +87 -0
- package/src/lib/orchestrator/session-context-link.ts +67 -0
- package/src/lib/orchestrator/session-prepare.ts +45 -5
- package/src/lib/orchestrator/setup-compatibilities.ts +56 -70
- package/src/lib/orchestrator/types.ts +7 -2
- package/src/lib/orchestrator/working-repo-projection.ts +50 -7
- package/src/lib/orchestrator/workspace-document.ts +105 -0
- package/src/lib/orchestrator/wrap-pass.ts +22 -1
- package/src/lib/package-paths.ts +37 -0
- package/src/lib/runtime-directory-refresh.ts +17 -1
- package/src/lib/workset/record.ts +513 -0
- package/src/lib/workset/repositories.ts +55 -0
- package/src/lib/workset/stage.ts +148 -0
- package/src/lib/workset/stages.ts +113 -0
- package/src/lib/workset/worktree-index.ts +116 -0
- package/src/lib/workset/worktree.ts +830 -0
- package/src/opencode/companion-hooks.ts +109 -7
- package/src/opencode/companion-policy.ts +37 -18
- package/src/opencode/enter-worktree.ts +72 -0
- package/src/opencode/projected-guidance.ts +4 -1
- package/src/opencode/session-prepare.ts +2 -1
- package/src/opencode/tui.tsx +13 -6
- package/src/plugins.ts +1 -0
- package/src/runtime/artifact-refusal.ts +63 -0
- package/src/runtime/claude-delivery-plan.ts +107 -8
- package/src/runtime/commit-attribution-guard.ts +181 -0
- package/src/runtime/companion-git.ts +52 -10
- package/src/runtime/companion-guidance.ts +20 -8
- package/src/runtime/companion-instructions.ts +340 -0
- package/src/runtime/companion-lock.ts +30 -7
- package/src/runtime/env.ts +48 -3
- package/src/runtime/error-message.ts +4 -0
- package/src/runtime/git-layout.ts +219 -0
- package/src/runtime/index.ts +29 -0
- package/src/runtime/managed-block.ts +117 -0
- package/src/runtime/markdown-scan.ts +266 -0
- package/src/runtime/physical-path.ts +111 -0
- package/src/runtime/policy.ts +50 -2
- package/src/runtime/projected-flag.ts +7 -0
- package/src/runtime/projected-guidance.ts +1 -0
- package/src/runtime/runtime-directory.ts +5 -0
- package/src/runtime/runtime-document-manifest.ts +62 -11
- package/src/runtime/secret-guard.ts +162 -0
- package/src/runtime/secret-patterns.ts +397 -0
- package/src/runtime/secret-scan.ts +90 -0
- package/src/runtime/session-context.ts +98 -0
- package/src/runtime/session-kind.ts +13 -0
- package/src/runtime/shell-heredoc.ts +81 -0
- package/src/runtime/tokensave-route.ts +152 -0
- package/src/runtime/wrap-state.ts +44 -2
- package/src/runtime/write-atomic.ts +64 -0
- package/src/studio.ts +124 -0
- package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +14 -10
- package/src/templates/capabilities/openspec-cap/mate-minimal/templates/spec.md +3 -5
- package/src/templates/capabilities/openspec-cap/mate-v1/schema.yaml +18 -102
- package/src/templates/capabilities/openspec-cap/mate-v1/templates/spec.md +3 -5
- package/src/templates/capabilities/openspec-cap/openspec-conventions.yaml +20 -14
- package/src/templates/mate-skills/THIRD-PARTY-NOTICES.md +40 -0
- package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +134 -0
- package/src/templates/mate-skills/agents/mate-apply-change/references/mate-compact-apply.md +47 -0
- package/src/templates/mate-skills/agents/mate-apply-change/references/openspec-apply-change.md +200 -0
- package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +86 -0
- package/src/templates/mate-skills/{claude/mate-openspec-backfill → agents/mate-backfill-spec}/SKILL.md +11 -4
- package/src/templates/mate-skills/agents/mate-clarify-intent/SKILL.md +110 -0
- package/src/templates/mate-skills/agents/mate-explore-change/SKILL.md +66 -0
- package/src/templates/mate-skills/agents/mate-explore-change/references/openspec-explore.md +350 -0
- package/src/templates/mate-skills/agents/mate-grill-me/SKILL.md +11 -4
- package/src/templates/mate-skills/agents/mate-grill-with-docs/SKILL.md +2 -2
- package/src/templates/mate-skills/agents/mate-interview-me/SKILL.md +12 -5
- package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +108 -0
- package/src/templates/mate-skills/agents/mate-propose-change/references/mate-revise.md +47 -0
- package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-propose.md +169 -0
- package/src/templates/mate-skills/agents/mate-propose-change/references/openspec-update-change.md +103 -0
- package/src/templates/mate-skills/agents/{mate-artifact-publish → mate-publish-artifact}/SKILL.md +111 -24
- package/src/templates/mate-skills/{claude/mate-artifact-publish → agents/mate-publish-artifact}/references/openspec.md +8 -5
- package/src/templates/mate-skills/agents/mate-show-me/SKILL.md +95 -16
- package/src/templates/mate-skills/agents/mate-simplify-code/SKILL.md +87 -68
- package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +134 -0
- package/src/templates/mate-skills/claude/mate-apply-change/references/mate-compact-apply.md +47 -0
- package/src/templates/mate-skills/claude/mate-apply-change/references/openspec-apply-change.md +200 -0
- package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +86 -0
- package/src/templates/mate-skills/{agents/mate-openspec-backfill → claude/mate-backfill-spec}/SKILL.md +11 -4
- package/src/templates/mate-skills/claude/mate-clarify-intent/SKILL.md +110 -0
- package/src/templates/mate-skills/claude/mate-explore-change/SKILL.md +66 -0
- package/src/templates/mate-skills/claude/mate-explore-change/references/openspec-explore.md +350 -0
- package/src/templates/mate-skills/claude/mate-grill-me/SKILL.md +11 -4
- package/src/templates/mate-skills/claude/mate-grill-with-docs/SKILL.md +2 -2
- package/src/templates/mate-skills/claude/mate-interview-me/SKILL.md +12 -5
- package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +108 -0
- package/src/templates/mate-skills/claude/mate-propose-change/references/mate-revise.md +47 -0
- package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-propose.md +169 -0
- package/src/templates/mate-skills/claude/mate-propose-change/references/openspec-update-change.md +103 -0
- package/src/templates/mate-skills/claude/{mate-artifact-publish → mate-publish-artifact}/SKILL.md +111 -24
- package/src/templates/mate-skills/{agents/mate-artifact-publish → claude/mate-publish-artifact}/references/openspec.md +8 -5
- package/src/templates/mate-skills/claude/mate-show-me/SKILL.md +95 -16
- package/src/templates/mate-skills/claude/mate-simplify-code/SKILL.md +87 -68
- package/src/templates/mate-skills/openspec-references.ts +142 -0
- package/src/templates/root/TEMPLATE_AGENTS.md +2 -2
- package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +3938 -391
- package/src/tools/setup/capabilities/companion-mentions.ts +27 -0
- package/src/tools/setup/capabilities/context-mode.ts +56 -7
- package/src/tools/setup/capabilities/graphify-gate.ts +31 -0
- package/src/tools/setup/capabilities/graphify-secrets.ts +243 -0
- package/src/tools/setup/capabilities/graphify.ts +46 -7
- package/src/tools/setup/capabilities/openspec.ts +163 -272
- package/src/tools/setup/capabilities/react-doctor.ts +8 -1
- package/src/tools/setup/capabilities/rtk.ts +4 -0
- package/src/tools/setup/capabilities/tokensave.ts +113 -71
- package/src/tools/setup/context-services.ts +9 -17
- package/src/tools/setup/dynamic-plugins/install.ts +24 -28
- package/src/tools/setup/engine.ts +100 -23
- package/src/tools/setup/install-contract.ts +8 -0
- package/src/tools/setup/managed-output.ts +51 -0
- package/src/tools/setup/mate-skill-copies.ts +51 -0
- package/src/tools/setup/mate.ts +86 -11
- package/src/tools/setup/package-managers/uv.ts +73 -11
- package/src/tools/setup/plugin.ts +40 -0
- package/src/tools/setup/plugins/guidance.ts +7 -4
- package/src/tools/setup/providers/agent-file-sections.ts +4 -2
- package/src/tools/setup/providers/claude-attribution.ts +65 -0
- package/src/tools/setup/providers/claude-plugin-folders.ts +625 -0
- package/src/tools/setup/providers/claude-plugin-hooks.ts +51 -19
- package/src/tools/setup/providers/claude-worktree-plugins.ts +122 -0
- package/src/tools/setup/providers/claude.ts +290 -8
- package/src/tools/setup/providers/opencode.ts +180 -1
- package/src/tools/setup/utils.ts +18 -4
- package/src/tools/setup/working-repo-cleanup.ts +29 -1
- package/src/tools/setup/working-repo-local-state.ts +252 -75
- package/src/tools/setup.ts +183 -26
- package/studio-dist/client/assets/companion-view-Csva26Ir.js +1 -0
- package/studio-dist/client/assets/delivery-path-DJMpRmiY.js +1 -0
- package/studio-dist/client/assets/dist-Dm7MtyHc.js +5 -0
- package/studio-dist/client/assets/factory-B7l9ZQyx.js +4 -0
- package/studio-dist/client/assets/index-n6uo_92S.js +40 -0
- package/studio-dist/client/assets/preload-helper-BLdHbfdN.js +1 -0
- package/studio-dist/client/assets/prepaint-CD5OpmTM.js +24 -0
- package/studio-dist/client/assets/queries-CN3JwMBX.js +1 -0
- package/studio-dist/client/assets/react-CabXf2Ds.js +1 -0
- package/studio-dist/client/assets/report-time-Dc-KOqQu.js +1 -0
- package/studio-dist/client/assets/reports-C01RsnMA.js +1 -0
- package/studio-dist/client/assets/rolldown-runtime-WkwZ5CU-.js +1 -0
- package/studio-dist/client/assets/routes-4pbC-2Hj.js +1 -0
- package/studio-dist/client/assets/skills-CihQganl.js +1 -0
- package/studio-dist/client/assets/spec-areas-C2L48N4C.js +1 -0
- package/studio-dist/client/assets/specs-D24_35_K.js +1 -0
- package/studio-dist/client/assets/studio-DKxfi691.css +1 -0
- package/studio-dist/client/assets/studio-queries-rvbJupCy.js +3 -0
- package/studio-dist/client/assets/terminal-eU5fzQzv.css +1 -0
- package/studio-dist/client/assets/vault-Bd4CQiTK.js +1 -0
- package/studio-dist/client/assets/warnings-V_Ys51wJ.js +1 -0
- package/studio-dist/client/assets/wasm-inline-C2en61B5.js +1 -0
- package/studio-dist/client/assets/workflow-BJejeVwQ.js +1 -0
- package/studio-dist/server/assets/__23tanstack-start-server-fn-resolver-BQKuMdJW.js +3881 -0
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +85 -0
- package/studio-dist/server/assets/actions-Bvgj9eb8.js +54 -0
- package/studio-dist/server/assets/actions-D8erOphH.js +44 -0
- package/studio-dist/server/assets/companion-view-aBady57v.js +33 -0
- package/studio-dist/server/assets/createServerFn-F5sAOF8V.js +459 -0
- package/studio-dist/server/assets/createServerRpc-tK2lE9R2.js +11 -0
- package/studio-dist/server/assets/delivery-path-BkKNjgkf.js +778 -0
- package/studio-dist/server/assets/dist-DpJWKyCm.js +5582 -0
- package/studio-dist/server/assets/empty-plugin-adapters-Cipd4ZH4.js +4 -0
- package/studio-dist/server/assets/factory-D6xnjedJ.js +2385 -0
- package/studio-dist/server/assets/factory-DT3UzHlh.js +68 -0
- package/studio-dist/server/assets/model-PyPALjii.js +18 -0
- package/studio-dist/server/assets/prepaint-BMke0fo1.js +41 -0
- package/studio-dist/server/assets/queries-Ag2iL8q2.js +107 -0
- package/studio-dist/server/assets/react-COs0LHn-.js +51 -0
- package/studio-dist/server/assets/report-time-DAfzln-N.js +8 -0
- package/studio-dist/server/assets/reports-BnUNJVtx.js +126 -0
- package/studio-dist/server/assets/rolldown-runtime-DYf_mQCB.js +34 -0
- package/studio-dist/server/assets/router-BH--drIx.js +4298 -0
- package/studio-dist/server/assets/routes-khSDK1bV.js +361 -0
- package/studio-dist/server/assets/search-JAKurDNh.js +36 -0
- package/studio-dist/server/assets/shell-CboT2f66.js +51 -0
- package/studio-dist/server/assets/skills-MWYnWoKs.js +106 -0
- package/studio-dist/server/assets/spec-areas-DcnO6vW-.js +16 -0
- package/studio-dist/server/assets/specs-DE3w8hZP.js +155 -0
- package/studio-dist/server/assets/start-BW5ovN0k.js +33 -0
- package/studio-dist/server/assets/studio-BeltxxKt.js +216 -0
- package/studio-dist/server/assets/studio-queries-CLnP9kGu.js +3365 -0
- package/studio-dist/server/assets/utils-C9CX1kcy.js +221 -0
- package/studio-dist/server/assets/vault-BGulVoNh.js +70 -0
- package/studio-dist/server/assets/vault-CuyyhLyB.js +832 -0
- package/studio-dist/server/assets/views-Bd7cRr27.js +82 -0
- package/studio-dist/server/assets/warnings-BH05rOuG.js +15 -0
- package/studio-dist/server/assets/wasm-inline-CNeBKGwC.js +3 -0
- package/studio-dist/server/assets/workflow-BSuIKWqH.js +42 -0
- package/studio-dist/server/server.js +16220 -0
- package/wrappers/bin/graphify +52 -4
- package/wrappers/bin/openspec +33 -9
- package/wrappers/lib/graphify-gate.mjs +8 -0
- package/src/cli/commands/studio/views/client.ts +0 -654
- package/src/cli/commands/studio/views/companion-picker.tsx +0 -95
- package/src/cli/commands/studio/views/companion-selector.tsx +0 -94
- package/src/cli/commands/studio/views/dashboard/changes.tsx +0 -107
- package/src/cli/commands/studio/views/dashboard/index.tsx +0 -19
- package/src/cli/commands/studio/views/document.tsx +0 -842
- package/src/cli/commands/studio/views/error.tsx +0 -20
- package/src/cli/commands/studio/views/reports/index.tsx +0 -49
- package/src/cli/commands/studio/views/selection-fields.tsx +0 -14
- package/src/cli/commands/studio/views/skills/index.tsx +0 -87
- package/src/cli/commands/studio/views/specs/index.tsx +0 -157
- package/src/cli/commands/studio/views/styles.ts +0 -519
- package/src/cli/commands/studio/views/terminal.tsx +0 -484
- package/src/cli/commands/studio/views/vault/state.ts +0 -43
- package/src/cli/commands/studio/views/warnings.tsx +0 -21
- package/src/cli/commands/studio/views/workflow/index.tsx +0 -21
- package/src/cli/commands/studio/views/workflow/steps.ts +0 -337
- package/src/cli/commands/studio/views/workflow/transcript.tsx +0 -190
- package/src/lib/components/theme.ts +0 -2
- package/src/tools/setup/git-utils.ts +0 -30
- package/src/tools/setup/runtime-documents.ts +0 -291
|
@@ -0,0 +1,4298 @@
|
|
|
1
|
+
import { i as __toESM, n as __exportAll } from "./rolldown-runtime-DYf_mQCB.js";
|
|
2
|
+
import { $ as createFileRoute, B as hashKey, C as TERMINAL_SESSIONS_END_ROUTE, E as TERMINAL_WASM, F as onlineManager, G as partialMatchKey, H as matchMutation, I as notifyManager, J as shouldThrowError, K as resolveQueryValue, L as focusManager, M as Query, N as Removable, P as createRetryer, Q as lazyRouteComponent, R as Subscribable, S as STUDIO_EVENTS_ROUTE, T as TERMINAL_SOCKET_ROUTE, U as matchQuery, V as hashQueryKeyByOptions, W as noop, X as QueryClientProvider, Y as skipToken, Z as useQueryClient, et as createRootRouteWithContext, f as vaultQuery, h as getShell, l as shellQuery, nt as useNavigate, o as companionViewQuery, q as shallowEqualObjects, r as afterRefresh, s as factoryQuery, t as afterEvent, tt as Link, w as TERMINAL_SESSIONS_ROUTE, z as functionalUpdate } from "./studio-queries-CLnP9kGu.js";
|
|
3
|
+
import { A as require_react, h as RouterCore, l as require_jsx_runtime, p as _getAssetMatches, s as useRouter, v as createNonReactiveMutableStore, y as createNonReactiveReadonlyStore } from "./__23tanstack-start-server-fn-resolver-BQKuMdJW.js";
|
|
4
|
+
import { y as redirect } from "./createServerFn-F5sAOF8V.js";
|
|
5
|
+
import { a as appendUniqueUserTags, c as resolveManifestCssLink, i as useHydrated, n as useMatches, o as getAssetCrossOrigin, r as Outlet, s as getScriptPreloadAttrs } from "../server.js";
|
|
6
|
+
import { s as escapeHtml } from "./utils-C9CX1kcy.js";
|
|
7
|
+
import { b as viewsFor, h as STUDIO_MODES, m as SHARED_VIEWS, n as LIGHT_PALETTE, p as MODE_VIEWS, t as DARK_PALETTE } from "./studio-BeltxxKt.js";
|
|
8
|
+
import { i as VAULT_TREE_STORAGE_KEY, n as STUDIO_PREPAINT_SCRIPT, r as THEME_STORAGE_KEY, t as COMPANION_STORAGE_KEY } from "./prepaint-BMke0fo1.js";
|
|
9
|
+
import { t as formatCollectedAt } from "./model-PyPALjii.js";
|
|
10
|
+
import { i as useSuspenseQuery, n as loadView, r as registeredCompanion, t as loadHeld } from "./queries-Ag2iL8q2.js";
|
|
11
|
+
import { n as validateStudioSearch, t as canonicalHref } from "./search-JAKurDNh.js";
|
|
12
|
+
import { n as useQuery, t as create } from "./react-COs0LHn-.js";
|
|
13
|
+
// ../../node_modules/.bun/@tanstack+router-core@1.171.39/node_modules/@tanstack/router-core/dist/esm/ssr/bodyScripts.js
|
|
14
|
+
function getSsrBodyScriptParts(matches, manifest, nonce, routeScriptAttrs) {
|
|
15
|
+
const assetMatches = _getAssetMatches(matches);
|
|
16
|
+
const routeScripts = [];
|
|
17
|
+
const manifestScripts = [];
|
|
18
|
+
for (const match of assetMatches) for (const script of Array.isArray(match.scripts) ? match.scripts : []) {
|
|
19
|
+
if (!script) continue;
|
|
20
|
+
const { children, ...attrs } = script;
|
|
21
|
+
routeScripts.push({
|
|
22
|
+
tag: "script",
|
|
23
|
+
attrs: {
|
|
24
|
+
...attrs,
|
|
25
|
+
...routeScriptAttrs,
|
|
26
|
+
nonce
|
|
27
|
+
},
|
|
28
|
+
children
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
if (manifest) for (const match of assetMatches) for (const asset of manifest.routes[match.routeId]?.scripts ?? []) manifestScripts.push({
|
|
32
|
+
tag: "script",
|
|
33
|
+
attrs: {
|
|
34
|
+
...asset.attrs,
|
|
35
|
+
nonce
|
|
36
|
+
},
|
|
37
|
+
children: asset.children
|
|
38
|
+
});
|
|
39
|
+
return [routeScripts, manifestScripts];
|
|
40
|
+
}
|
|
41
|
+
function composeSsrBodyScripts([routeScripts, manifestScripts], initialHydrationScripts) {
|
|
42
|
+
if (!initialHydrationScripts) return [...routeScripts, ...manifestScripts];
|
|
43
|
+
return [
|
|
44
|
+
...initialHydrationScripts.before,
|
|
45
|
+
...routeScripts,
|
|
46
|
+
...manifestScripts,
|
|
47
|
+
initialHydrationScripts.boundary
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
// ../../node_modules/.bun/@tanstack+store@0.11.2/node_modules/@tanstack/store/dist/alien.js
|
|
51
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
52
|
+
function createReactiveSystem({ update, notify, unwatched }) {
|
|
53
|
+
return {
|
|
54
|
+
link,
|
|
55
|
+
unlink,
|
|
56
|
+
propagate,
|
|
57
|
+
checkDirty,
|
|
58
|
+
shallowPropagate
|
|
59
|
+
};
|
|
60
|
+
function link(dep, sub, version) {
|
|
61
|
+
const prevDep = sub.depsTail;
|
|
62
|
+
if (prevDep !== void 0 && prevDep.dep === dep) return;
|
|
63
|
+
const nextDep = prevDep !== void 0 ? prevDep.nextDep : sub.deps;
|
|
64
|
+
if (nextDep !== void 0 && nextDep.dep === dep) {
|
|
65
|
+
nextDep.version = version;
|
|
66
|
+
sub.depsTail = nextDep;
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const prevSub = dep.subsTail;
|
|
70
|
+
if (prevSub !== void 0 && prevSub.version === version && prevSub.sub === sub) return;
|
|
71
|
+
const newLink = sub.depsTail = dep.subsTail = {
|
|
72
|
+
version,
|
|
73
|
+
dep,
|
|
74
|
+
sub,
|
|
75
|
+
prevDep,
|
|
76
|
+
nextDep,
|
|
77
|
+
prevSub,
|
|
78
|
+
nextSub: void 0
|
|
79
|
+
};
|
|
80
|
+
if (nextDep !== void 0) nextDep.prevDep = newLink;
|
|
81
|
+
if (prevDep !== void 0) prevDep.nextDep = newLink;
|
|
82
|
+
else sub.deps = newLink;
|
|
83
|
+
if (prevSub !== void 0) prevSub.nextSub = newLink;
|
|
84
|
+
else dep.subs = newLink;
|
|
85
|
+
}
|
|
86
|
+
function unlink(link, sub = link.sub) {
|
|
87
|
+
const dep = link.dep;
|
|
88
|
+
const prevDep = link.prevDep;
|
|
89
|
+
const nextDep = link.nextDep;
|
|
90
|
+
const nextSub = link.nextSub;
|
|
91
|
+
const prevSub = link.prevSub;
|
|
92
|
+
if (nextDep !== void 0) nextDep.prevDep = prevDep;
|
|
93
|
+
else sub.depsTail = prevDep;
|
|
94
|
+
if (prevDep !== void 0) prevDep.nextDep = nextDep;
|
|
95
|
+
else sub.deps = nextDep;
|
|
96
|
+
if (nextSub !== void 0) nextSub.prevSub = prevSub;
|
|
97
|
+
else dep.subsTail = prevSub;
|
|
98
|
+
if (prevSub !== void 0) prevSub.nextSub = nextSub;
|
|
99
|
+
else if ((dep.subs = nextSub) === void 0) unwatched(dep);
|
|
100
|
+
return nextDep;
|
|
101
|
+
}
|
|
102
|
+
function propagate(link) {
|
|
103
|
+
let next = link.nextSub;
|
|
104
|
+
let stack;
|
|
105
|
+
top: do {
|
|
106
|
+
const sub = link.sub;
|
|
107
|
+
let flags = sub.flags;
|
|
108
|
+
if (!(flags & 60)) sub.flags = flags | 32;
|
|
109
|
+
else if (!(flags & 12)) flags = 0;
|
|
110
|
+
else if (!(flags & 4)) sub.flags = flags & -9 | 32;
|
|
111
|
+
else if (!(flags & 48) && isValidLink(link, sub)) {
|
|
112
|
+
sub.flags = flags | 40;
|
|
113
|
+
flags &= 1;
|
|
114
|
+
} else flags = 0;
|
|
115
|
+
if (flags & 2) notify(sub);
|
|
116
|
+
if (flags & 1) {
|
|
117
|
+
const subSubs = sub.subs;
|
|
118
|
+
if (subSubs !== void 0) {
|
|
119
|
+
const nextSub = (link = subSubs).nextSub;
|
|
120
|
+
if (nextSub !== void 0) {
|
|
121
|
+
stack = {
|
|
122
|
+
value: next,
|
|
123
|
+
prev: stack
|
|
124
|
+
};
|
|
125
|
+
next = nextSub;
|
|
126
|
+
}
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if ((link = next) !== void 0) {
|
|
131
|
+
next = link.nextSub;
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
while (stack !== void 0) {
|
|
135
|
+
link = stack.value;
|
|
136
|
+
stack = stack.prev;
|
|
137
|
+
if (link !== void 0) {
|
|
138
|
+
next = link.nextSub;
|
|
139
|
+
continue top;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
break;
|
|
143
|
+
} while (true);
|
|
144
|
+
}
|
|
145
|
+
function checkDirty(link, sub) {
|
|
146
|
+
let stack;
|
|
147
|
+
let checkDepth = 0;
|
|
148
|
+
let dirty = false;
|
|
149
|
+
top: do {
|
|
150
|
+
const dep = link.dep;
|
|
151
|
+
const flags = dep.flags;
|
|
152
|
+
if (sub.flags & 16) dirty = true;
|
|
153
|
+
else if ((flags & 17) === 17) {
|
|
154
|
+
if (update(dep)) {
|
|
155
|
+
const subs = dep.subs;
|
|
156
|
+
if (subs.nextSub !== void 0) shallowPropagate(subs);
|
|
157
|
+
dirty = true;
|
|
158
|
+
}
|
|
159
|
+
} else if ((flags & 33) === 33) {
|
|
160
|
+
if (link.nextSub !== void 0 || link.prevSub !== void 0) stack = {
|
|
161
|
+
value: link,
|
|
162
|
+
prev: stack
|
|
163
|
+
};
|
|
164
|
+
link = dep.deps;
|
|
165
|
+
sub = dep;
|
|
166
|
+
++checkDepth;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (!dirty) {
|
|
170
|
+
const nextDep = link.nextDep;
|
|
171
|
+
if (nextDep !== void 0) {
|
|
172
|
+
link = nextDep;
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
while (checkDepth--) {
|
|
177
|
+
const firstSub = sub.subs;
|
|
178
|
+
const hasMultipleSubs = firstSub.nextSub !== void 0;
|
|
179
|
+
if (hasMultipleSubs) {
|
|
180
|
+
link = stack.value;
|
|
181
|
+
stack = stack.prev;
|
|
182
|
+
} else link = firstSub;
|
|
183
|
+
if (dirty) {
|
|
184
|
+
if (update(sub)) {
|
|
185
|
+
if (hasMultipleSubs) shallowPropagate(firstSub);
|
|
186
|
+
sub = link.sub;
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
dirty = false;
|
|
190
|
+
} else sub.flags &= -33;
|
|
191
|
+
sub = link.sub;
|
|
192
|
+
const nextDep = link.nextDep;
|
|
193
|
+
if (nextDep !== void 0) {
|
|
194
|
+
link = nextDep;
|
|
195
|
+
continue top;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return dirty;
|
|
199
|
+
} while (true);
|
|
200
|
+
}
|
|
201
|
+
function shallowPropagate(link) {
|
|
202
|
+
do {
|
|
203
|
+
const sub = link.sub;
|
|
204
|
+
const flags = sub.flags;
|
|
205
|
+
if ((flags & 48) === 32) {
|
|
206
|
+
sub.flags = flags | 16;
|
|
207
|
+
if ((flags & 6) === 2) notify(sub);
|
|
208
|
+
}
|
|
209
|
+
} while ((link = link.nextSub) !== void 0);
|
|
210
|
+
}
|
|
211
|
+
function isValidLink(checkLink, sub) {
|
|
212
|
+
let link = sub.depsTail;
|
|
213
|
+
while (link !== void 0) {
|
|
214
|
+
if (link === checkLink) return true;
|
|
215
|
+
link = link.prevDep;
|
|
216
|
+
}
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
var queuedEffects = [];
|
|
221
|
+
var { link, unlink, propagate, checkDirty, shallowPropagate } = /* @__PURE__ */ createReactiveSystem({
|
|
222
|
+
update(atom) {
|
|
223
|
+
return atom._update();
|
|
224
|
+
},
|
|
225
|
+
notify(effect) {
|
|
226
|
+
queuedEffects[queuedEffectsLength++] = effect;
|
|
227
|
+
effect.flags &= -3;
|
|
228
|
+
},
|
|
229
|
+
unwatched(atom) {
|
|
230
|
+
if (atom.depsTail !== void 0) {
|
|
231
|
+
atom.depsTail = void 0;
|
|
232
|
+
atom.flags = 17;
|
|
233
|
+
purgeDeps(atom);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
var queuedEffectsLength = 0;
|
|
238
|
+
function purgeDeps(sub) {
|
|
239
|
+
const depsTail = sub.depsTail;
|
|
240
|
+
let dep = depsTail !== void 0 ? depsTail.nextDep : sub.deps;
|
|
241
|
+
while (dep !== void 0) dep = unlink(dep, sub);
|
|
242
|
+
}
|
|
243
|
+
// ../../node_modules/.bun/@tanstack+react-router@1.170.46+7492c01c6988791b/node_modules/@tanstack/react-router/dist/esm/routerStores.js
|
|
244
|
+
var getStoreFactory = (opts) => {
|
|
245
|
+
return {
|
|
246
|
+
createMutableStore: createNonReactiveMutableStore,
|
|
247
|
+
createReadonlyStore: createNonReactiveReadonlyStore,
|
|
248
|
+
batch: (fn) => fn()
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
// ../../node_modules/.bun/@tanstack+react-router@1.170.46+7492c01c6988791b/node_modules/@tanstack/react-router/dist/esm/router.js
|
|
252
|
+
/**
|
|
253
|
+
* Creates a new Router instance for React.
|
|
254
|
+
*
|
|
255
|
+
* Pass the returned router to `RouterProvider` to enable routing.
|
|
256
|
+
* Notable options: `routeTree` (your route definitions) and `context`
|
|
257
|
+
* (required if the root route was created with `createRootRouteWithContext`).
|
|
258
|
+
*
|
|
259
|
+
* @param options Router options used to configure the router.
|
|
260
|
+
* @returns A Router instance to be provided to `RouterProvider`.
|
|
261
|
+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/createRouterFunction
|
|
262
|
+
*/
|
|
263
|
+
var createRouter = (options) => {
|
|
264
|
+
return new Router(options);
|
|
265
|
+
};
|
|
266
|
+
var Router = class extends RouterCore {
|
|
267
|
+
constructor(options) {
|
|
268
|
+
super(options, getStoreFactory);
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
// ../../node_modules/.bun/@tanstack+react-router@1.170.46+7492c01c6988791b/node_modules/@tanstack/react-router/dist/esm/useRouterState.js
|
|
272
|
+
/**
|
|
273
|
+
* Subscribe to the router's state store with optional selection and
|
|
274
|
+
* structural sharing for render optimization.
|
|
275
|
+
*
|
|
276
|
+
* Options:
|
|
277
|
+
* - `select`: Project the full router state to a derived slice
|
|
278
|
+
* - `structuralSharing`: Replace-equal semantics for stable references
|
|
279
|
+
* - `router`: Read state from a specific router instance instead of context
|
|
280
|
+
*
|
|
281
|
+
* @returns The selected router state (or the full state by default).
|
|
282
|
+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useRouterStateHook
|
|
283
|
+
*/
|
|
284
|
+
function useRouterState(opts) {
|
|
285
|
+
const contextRouter = useRouter({ warn: opts?.router === void 0 });
|
|
286
|
+
const router = opts?.router || contextRouter;
|
|
287
|
+
{
|
|
288
|
+
const state = router.stores.__store.get();
|
|
289
|
+
return opts?.select ? opts.select(state) : state;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
// ../../node_modules/.bun/@tanstack+react-router@1.170.46+7492c01c6988791b/node_modules/@tanstack/react-router/dist/esm/Asset.js
|
|
293
|
+
var import_react = /* @__PURE__ */ __toESM(require_react(), 1);
|
|
294
|
+
var import_jsx_runtime = require_jsx_runtime();
|
|
295
|
+
var noopScriptHandler = () => {};
|
|
296
|
+
function setScriptAttrs(script, attrs) {
|
|
297
|
+
if (!attrs) return;
|
|
298
|
+
for (const [key, value] of Object.entries(attrs)) if (key !== "suppressHydrationWarning" && value !== void 0 && value !== false) script.setAttribute(key, typeof value === "boolean" ? "" : String(value));
|
|
299
|
+
}
|
|
300
|
+
function Asset(asset) {
|
|
301
|
+
const { attrs, children, nonce, preventScriptHoist } = asset;
|
|
302
|
+
const innerHTML = import_react.useMemo(() => children === void 0 ? void 0 : { __html: children }, [children]);
|
|
303
|
+
switch (asset.tag) {
|
|
304
|
+
case "title": return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("title", {
|
|
305
|
+
...attrs,
|
|
306
|
+
suppressHydrationWarning: true,
|
|
307
|
+
children
|
|
308
|
+
});
|
|
309
|
+
case "meta": return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("meta", {
|
|
310
|
+
...attrs,
|
|
311
|
+
suppressHydrationWarning: true
|
|
312
|
+
});
|
|
313
|
+
case "link": return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("link", {
|
|
314
|
+
...attrs,
|
|
315
|
+
precedence: attrs?.precedence ?? (attrs?.rel === "stylesheet" ? "default" : void 0),
|
|
316
|
+
nonce,
|
|
317
|
+
suppressHydrationWarning: true
|
|
318
|
+
});
|
|
319
|
+
case "style":
|
|
320
|
+
if (asset.inlineCss && false);
|
|
321
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", {
|
|
322
|
+
...attrs,
|
|
323
|
+
dangerouslySetInnerHTML: innerHTML,
|
|
324
|
+
nonce
|
|
325
|
+
});
|
|
326
|
+
case "script": return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Script, {
|
|
327
|
+
attrs,
|
|
328
|
+
preventScriptHoist,
|
|
329
|
+
children
|
|
330
|
+
});
|
|
331
|
+
default: return null;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
function Script({ attrs, children, preventScriptHoist }) {
|
|
335
|
+
useRouter();
|
|
336
|
+
useHydrated();
|
|
337
|
+
const innerHTML = import_react.useMemo(() => children === void 0 ? void 0 : { __html: children }, [children]);
|
|
338
|
+
const dataScript = typeof attrs?.type === "string" && attrs.type !== "" && attrs.type !== "text/javascript" && attrs.type !== "module";
|
|
339
|
+
import_react.useEffect(() => {
|
|
340
|
+
if (dataScript) return;
|
|
341
|
+
if (attrs?.src) {
|
|
342
|
+
const link = document.createElement("a");
|
|
343
|
+
link.href = attrs.src;
|
|
344
|
+
const normSrc = link.href;
|
|
345
|
+
for (const el of document.scripts) if (el.src === normSrc) return;
|
|
346
|
+
const script = document.createElement("script");
|
|
347
|
+
setScriptAttrs(script, attrs);
|
|
348
|
+
document.head.appendChild(script);
|
|
349
|
+
return () => script.remove();
|
|
350
|
+
}
|
|
351
|
+
if (typeof children === "string") {
|
|
352
|
+
const typeAttr = typeof attrs?.type === "string" ? attrs.type : "text/javascript";
|
|
353
|
+
const nonceAttr = typeof attrs?.nonce === "string" ? attrs.nonce : void 0;
|
|
354
|
+
for (const el of document.scripts) {
|
|
355
|
+
if (el.hasAttribute("src")) continue;
|
|
356
|
+
const sType = el.getAttribute("type") ?? "text/javascript";
|
|
357
|
+
const sNonce = el.getAttribute("nonce") ?? void 0;
|
|
358
|
+
if (el.textContent === children && sType === typeAttr && sNonce === nonceAttr) return;
|
|
359
|
+
}
|
|
360
|
+
const script = document.createElement("script");
|
|
361
|
+
script.textContent = children;
|
|
362
|
+
setScriptAttrs(script, attrs);
|
|
363
|
+
document.head.appendChild(script);
|
|
364
|
+
return () => script.remove();
|
|
365
|
+
}
|
|
366
|
+
}, [
|
|
367
|
+
attrs,
|
|
368
|
+
children,
|
|
369
|
+
dataScript
|
|
370
|
+
]);
|
|
371
|
+
if (attrs?.src) {
|
|
372
|
+
if (!preventScriptHoist) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", {
|
|
373
|
+
...attrs,
|
|
374
|
+
suppressHydrationWarning: true
|
|
375
|
+
});
|
|
376
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", {
|
|
377
|
+
...attrs,
|
|
378
|
+
onLoad: noopScriptHandler,
|
|
379
|
+
suppressHydrationWarning: true
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
if (typeof children === "string") return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", {
|
|
383
|
+
...attrs,
|
|
384
|
+
dangerouslySetInnerHTML: innerHTML,
|
|
385
|
+
suppressHydrationWarning: true
|
|
386
|
+
});
|
|
387
|
+
return null;
|
|
388
|
+
}
|
|
389
|
+
// ../../node_modules/.bun/@tanstack+react-router@1.170.46+7492c01c6988791b/node_modules/@tanstack/react-router/dist/esm/headContentUtils.js
|
|
390
|
+
function buildTagsFromMatches(router, nonce, matches, assetCrossOrigin) {
|
|
391
|
+
matches = _getAssetMatches(matches);
|
|
392
|
+
const routeMeta = matches.map((match) => match.meta).filter((meta) => meta !== void 0);
|
|
393
|
+
const resultMeta = [];
|
|
394
|
+
const metaByAttribute = {};
|
|
395
|
+
let title;
|
|
396
|
+
for (let i = routeMeta.length - 1; i >= 0; i--) {
|
|
397
|
+
const metas = routeMeta[i];
|
|
398
|
+
for (let j = metas.length - 1; j >= 0; j--) {
|
|
399
|
+
const m = metas[j];
|
|
400
|
+
if (!m) continue;
|
|
401
|
+
if (m.title) {
|
|
402
|
+
if (!title) title = {
|
|
403
|
+
tag: "title",
|
|
404
|
+
children: m.title
|
|
405
|
+
};
|
|
406
|
+
} else if ("script:ld+json" in m) try {
|
|
407
|
+
const json = JSON.stringify(m["script:ld+json"]);
|
|
408
|
+
resultMeta.push({
|
|
409
|
+
tag: "script",
|
|
410
|
+
attrs: { type: "application/ld+json" },
|
|
411
|
+
children: escapeHtml(json)
|
|
412
|
+
});
|
|
413
|
+
} catch {}
|
|
414
|
+
else {
|
|
415
|
+
const attribute = m.name ?? m.property;
|
|
416
|
+
if (attribute) {
|
|
417
|
+
if (metaByAttribute[attribute]) continue;
|
|
418
|
+
else metaByAttribute[attribute] = true;
|
|
419
|
+
}
|
|
420
|
+
resultMeta.push({
|
|
421
|
+
tag: "meta",
|
|
422
|
+
attrs: {
|
|
423
|
+
...m,
|
|
424
|
+
nonce
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (title) resultMeta.push(title);
|
|
431
|
+
if (nonce) resultMeta.push({
|
|
432
|
+
tag: "meta",
|
|
433
|
+
attrs: {
|
|
434
|
+
property: "csp-nonce",
|
|
435
|
+
content: nonce
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
resultMeta.reverse();
|
|
439
|
+
const constructedLinks = matches.flatMap((match) => match.links ?? []).filter((link) => link !== void 0).map((link) => ({
|
|
440
|
+
tag: "link",
|
|
441
|
+
attrs: {
|
|
442
|
+
...link,
|
|
443
|
+
nonce
|
|
444
|
+
}
|
|
445
|
+
}));
|
|
446
|
+
const manifest = router.ssr?.manifest;
|
|
447
|
+
const manifestCssTags = [];
|
|
448
|
+
if (manifest) {
|
|
449
|
+
matches.forEach((match) => {
|
|
450
|
+
(manifest.routes[match.routeId]?.css)?.forEach((link) => {
|
|
451
|
+
const resolvedLink = resolveManifestCssLink(link);
|
|
452
|
+
manifestCssTags.push({
|
|
453
|
+
tag: "link",
|
|
454
|
+
attrs: {
|
|
455
|
+
rel: "stylesheet",
|
|
456
|
+
...resolvedLink,
|
|
457
|
+
crossOrigin: getAssetCrossOrigin(assetCrossOrigin, "stylesheet") ?? resolvedLink.crossOrigin,
|
|
458
|
+
suppressHydrationWarning: true,
|
|
459
|
+
nonce
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
});
|
|
463
|
+
});
|
|
464
|
+
if (manifest.inlineStyle) manifestCssTags.push({
|
|
465
|
+
tag: "style",
|
|
466
|
+
attrs: {
|
|
467
|
+
...manifest.inlineStyle.attrs,
|
|
468
|
+
nonce
|
|
469
|
+
},
|
|
470
|
+
children: manifest.inlineStyle.children,
|
|
471
|
+
inlineCss: true
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
const preloadLinks = [];
|
|
475
|
+
if (manifest) matches.forEach((match) => {
|
|
476
|
+
manifest.routes[match.routeId]?.preloads?.forEach((preload) => {
|
|
477
|
+
preloadLinks.push({
|
|
478
|
+
tag: "link",
|
|
479
|
+
attrs: {
|
|
480
|
+
...getScriptPreloadAttrs(manifest, preload, assetCrossOrigin),
|
|
481
|
+
nonce
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
});
|
|
485
|
+
});
|
|
486
|
+
const styles = matches.flatMap((match) => match.styles ?? []).filter((style) => style !== void 0).map(({ children, ...attrs }) => ({
|
|
487
|
+
tag: "style",
|
|
488
|
+
attrs: {
|
|
489
|
+
...attrs,
|
|
490
|
+
nonce
|
|
491
|
+
},
|
|
492
|
+
children
|
|
493
|
+
}));
|
|
494
|
+
const headScripts = matches.flatMap((match) => match.headScripts ?? []).filter((script) => script !== void 0).map(({ children, ...script }) => ({
|
|
495
|
+
tag: "script",
|
|
496
|
+
attrs: {
|
|
497
|
+
...script,
|
|
498
|
+
nonce
|
|
499
|
+
},
|
|
500
|
+
children
|
|
501
|
+
}));
|
|
502
|
+
const tags = [];
|
|
503
|
+
appendUniqueUserTags(tags, resultMeta);
|
|
504
|
+
tags.push(...preloadLinks);
|
|
505
|
+
appendUniqueUserTags(tags, constructedLinks);
|
|
506
|
+
tags.push(...manifestCssTags);
|
|
507
|
+
appendUniqueUserTags(tags, styles);
|
|
508
|
+
appendUniqueUserTags(tags, headScripts);
|
|
509
|
+
return tags;
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Build the head/link/meta/script tags from the renderable presented prefix.
|
|
513
|
+
* Used internally by `HeadContent`.
|
|
514
|
+
*/
|
|
515
|
+
var useTags = (assetCrossOrigin) => {
|
|
516
|
+
const router = useRouter();
|
|
517
|
+
const nonce = router.options.ssr?.nonce;
|
|
518
|
+
return buildTagsFromMatches(router, nonce, router.stores.matches.get(), assetCrossOrigin);
|
|
519
|
+
};
|
|
520
|
+
// ../../node_modules/.bun/@tanstack+react-router@1.170.46+7492c01c6988791b/node_modules/@tanstack/react-router/dist/esm/HeadContent.js
|
|
521
|
+
/**
|
|
522
|
+
* Render route-managed head tags (title, meta, links, styles, head scripts).
|
|
523
|
+
* Place inside the document head of your app shell.
|
|
524
|
+
* @link https://tanstack.com/router/latest/docs/framework/react/guide/document-head-management
|
|
525
|
+
*/
|
|
526
|
+
function HeadContent(props) {
|
|
527
|
+
const tags = useTags(props.assetCrossOrigin);
|
|
528
|
+
const nonce = useRouter().options.ssr?.nonce;
|
|
529
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: tags.map((tag) => /* @__PURE__ */ (0, import_react.createElement)(Asset, {
|
|
530
|
+
...tag,
|
|
531
|
+
key: `tsr-meta-${JSON.stringify(tag)}`,
|
|
532
|
+
nonce
|
|
533
|
+
})) });
|
|
534
|
+
}
|
|
535
|
+
// ../../node_modules/.bun/@tanstack+react-router@1.170.46+7492c01c6988791b/node_modules/@tanstack/react-router/dist/esm/Scripts.js
|
|
536
|
+
var routeScriptAttrs = { suppressHydrationWarning: true };
|
|
537
|
+
/**
|
|
538
|
+
* Render body script tags collected from route matches and SSR manifests.
|
|
539
|
+
* During streaming SSR, `<Scripts>` marks where late hydration scripts may
|
|
540
|
+
* begin to be inserted.
|
|
541
|
+
*/
|
|
542
|
+
var Scripts = () => {
|
|
543
|
+
const router = useRouter();
|
|
544
|
+
const nonce = router.options.ssr?.nonce;
|
|
545
|
+
const getParts = (matches) => {
|
|
546
|
+
const parts = getSsrBodyScriptParts(matches, router.ssr?.manifest, nonce, routeScriptAttrs);
|
|
547
|
+
for (const script of parts[1]) if (typeof script.attrs?.src === "string") {
|
|
548
|
+
const scriptWithHoist = script;
|
|
549
|
+
scriptWithHoist.preventScriptHoist = true;
|
|
550
|
+
}
|
|
551
|
+
return parts;
|
|
552
|
+
};
|
|
553
|
+
return renderScripts(composeSsrBodyScripts(getParts(router.stores.matches.get()), router.serverSsr?.takeInitialHydrationScriptTags()));
|
|
554
|
+
};
|
|
555
|
+
function renderScripts(scripts) {
|
|
556
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: scripts.map((asset, i) => /* @__PURE__ */ (0, import_react.createElement)(Asset, {
|
|
557
|
+
...asset,
|
|
558
|
+
key: `tsr-scripts-${asset.tag}-${i}`
|
|
559
|
+
})) });
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Prepares the in-flight promise of a pending query for dehydration: applies `serializeData` to its
|
|
563
|
+
* result, and redacts its rejection error unless `shouldRedactErrors` returns `false` for it.
|
|
564
|
+
* @param query - The pending query whose promise is dehydrated.
|
|
565
|
+
* @param serializeData - Optional transform applied to the resolved data.
|
|
566
|
+
* @param shouldRedactErrors - Optional predicate; if it returns `false` for the rejection error,
|
|
567
|
+
* that
|
|
568
|
+
* error is kept as-is instead of being redacted.
|
|
569
|
+
* @returns The transformed promise, or `undefined` if the query has no in-flight promise.
|
|
570
|
+
*/
|
|
571
|
+
function dehydratePromise(query, serializeData, shouldRedactErrors) {
|
|
572
|
+
const promise = query.promise?.then(serializeData).catch((error) => {
|
|
573
|
+
if (shouldRedactErrors?.(error) === false) return Promise.reject(error);
|
|
574
|
+
return Promise.reject(/* @__PURE__ */ new Error("redacted"));
|
|
575
|
+
});
|
|
576
|
+
promise?.catch(noop);
|
|
577
|
+
return promise;
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Dehydrates a single `Query` into a serializable `DehydratedQuery` snapshot. Note that most query config (e.g.
|
|
581
|
+
* `queryFn`, `staleTime`) is not dehydrated but instead meant to be configured again when consuming the
|
|
582
|
+
* de/rehydrated data, typically with `useQuery` on the client. If the query is still `pending`, its in-flight
|
|
583
|
+
* promise is dehydrated too so it can be resumed on the other side instead of re-fetched.
|
|
584
|
+
* @param query - The query to dehydrate.
|
|
585
|
+
* @param serializeData - Optional transform applied to `query.state.data` before it is included in the snapshot.
|
|
586
|
+
* @param shouldRedactErrors - Optional predicate; if it returns `false` for the promise's rejection error, that
|
|
587
|
+
* error is kept as-is instead of being redacted.
|
|
588
|
+
* @returns The dehydrated query.
|
|
589
|
+
*/
|
|
590
|
+
function dehydrateQuery(query, serializeData, shouldRedactErrors) {
|
|
591
|
+
return {
|
|
592
|
+
dehydratedAt: Date.now(),
|
|
593
|
+
state: {
|
|
594
|
+
...query.state,
|
|
595
|
+
...query.state.data !== void 0 && { data: serializeData ? serializeData(query.state.data) : query.state.data }
|
|
596
|
+
},
|
|
597
|
+
queryKey: query.queryKey,
|
|
598
|
+
queryHash: query.queryHash,
|
|
599
|
+
...query.state.status === "pending" && { promise: dehydratePromise(query, serializeData, shouldRedactErrors) },
|
|
600
|
+
...query.meta && { meta: query.meta },
|
|
601
|
+
...query.queryType && { queryType: query.queryType }
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
// ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/mutation.js
|
|
605
|
+
/**
|
|
606
|
+
* Represents a single mutation attempt. A `Mutation` holds the mutation's
|
|
607
|
+
* options, state (data/error/status), and the `MutationObserver`s currently
|
|
608
|
+
* subscribed to it.
|
|
609
|
+
*
|
|
610
|
+
* Instances are created and managed internally by `MutationCache`; application
|
|
611
|
+
* code typically interacts with mutations indirectly through `QueryClient` or
|
|
612
|
+
* a framework hook like `useMutation`. Direct access to a `Mutation` instance
|
|
613
|
+
* is possible via `mutationCache.find()`/`getAll()` for inspecting cache state.
|
|
614
|
+
* @example
|
|
615
|
+
* ```ts
|
|
616
|
+
* const mutationCache = queryClient.getMutationCache()
|
|
617
|
+
*
|
|
618
|
+
* const mutation = mutationCache.find({ mutationKey: ['addPost'] })
|
|
619
|
+
* ```
|
|
620
|
+
*/
|
|
621
|
+
var Mutation = class extends Removable {
|
|
622
|
+
#client;
|
|
623
|
+
#observers;
|
|
624
|
+
#mutationCache;
|
|
625
|
+
#retryer;
|
|
626
|
+
constructor(config) {
|
|
627
|
+
super();
|
|
628
|
+
this.#client = config.client;
|
|
629
|
+
this.mutationId = config.mutationId;
|
|
630
|
+
this.#mutationCache = config.mutationCache;
|
|
631
|
+
this.#observers = [];
|
|
632
|
+
this.state = config.state || getDefaultState();
|
|
633
|
+
this.setOptions(config.options);
|
|
634
|
+
this.scheduleGc();
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Replaces the mutation's options and applies their `gcTime`.
|
|
638
|
+
* @internal
|
|
639
|
+
* @param options - The new mutation options.
|
|
640
|
+
*/
|
|
641
|
+
setOptions(options) {
|
|
642
|
+
this.options = options;
|
|
643
|
+
this.updateGcTime(this.options.gcTime);
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* The `meta` object passed in the mutation's options, if any.
|
|
647
|
+
* @returns The mutation's `meta`, or `undefined` if none was set.
|
|
648
|
+
*/
|
|
649
|
+
get meta() {
|
|
650
|
+
return this.options.meta;
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* Subscribes an observer to the mutation and stops its garbage collection.
|
|
654
|
+
* @internal
|
|
655
|
+
* @param observer - The observer to add. Adding an observer that is already subscribed does
|
|
656
|
+
* nothing.
|
|
657
|
+
*/
|
|
658
|
+
addObserver(observer) {
|
|
659
|
+
if (!this.#observers.includes(observer)) {
|
|
660
|
+
this.#observers.push(observer);
|
|
661
|
+
this.clearGcTimeout();
|
|
662
|
+
this.#mutationCache.notify({
|
|
663
|
+
type: "observerAdded",
|
|
664
|
+
mutation: this,
|
|
665
|
+
observer
|
|
666
|
+
});
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Unsubscribes an observer from the mutation.
|
|
671
|
+
* @internal
|
|
672
|
+
* @param observer - The observer to remove. Garbage collection is scheduled afterwards.
|
|
673
|
+
*/
|
|
674
|
+
removeObserver(observer) {
|
|
675
|
+
this.#observers = this.#observers.filter((x) => x !== observer);
|
|
676
|
+
this.scheduleGc();
|
|
677
|
+
this.#mutationCache.notify({
|
|
678
|
+
type: "observerRemoved",
|
|
679
|
+
mutation: this,
|
|
680
|
+
observer
|
|
681
|
+
});
|
|
682
|
+
}
|
|
683
|
+
optionalRemove() {
|
|
684
|
+
if (!this.#observers.length) {
|
|
685
|
+
if (this.state.status === "pending") this.scheduleGc();
|
|
686
|
+
else this.#mutationCache.remove(this);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Resumes a mutation that is currently paused or was restored from a
|
|
691
|
+
* dehydrated, still-`pending` state.
|
|
692
|
+
*
|
|
693
|
+
* - If this mutation has an active retryer (it paused mid-attempt, e.g. due
|
|
694
|
+
* to the network mode or scope-based queuing), its retryer is resumed.
|
|
695
|
+
* - Otherwise, if the mutation's status is still `pending` (e.g. it was
|
|
696
|
+
* dehydrated while an attempt was in flight and never got a retryer in
|
|
697
|
+
* this instance), `execute` is called again with the last known variables.
|
|
698
|
+
* - Otherwise the mutation has already settled and this resolves immediately
|
|
699
|
+
* without running anything again.
|
|
700
|
+
* @returns A promise that settles with the resumed mutation: it rejects if the mutation fails.
|
|
701
|
+
* It resolves immediately if the mutation has already settled.
|
|
702
|
+
* @see {@link Mutation#execute}
|
|
703
|
+
* @example
|
|
704
|
+
* ```ts
|
|
705
|
+
* // typically driven by reconnect handling, e.g. queryClient.resumePausedMutations()
|
|
706
|
+
* const mutation = mutationCache.find({ mutationKey: ['addPost'] })
|
|
707
|
+
* await mutation?.continue()
|
|
708
|
+
* ```
|
|
709
|
+
*/
|
|
710
|
+
continue() {
|
|
711
|
+
return this.#retryer?.continue() ?? (this.state.status === "pending" ? this.execute(this.state.variables) : Promise.resolve());
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Runs the mutation function for the given variables through a retryer, and
|
|
715
|
+
* drives the mutation's state and lifecycle callbacks through to settlement.
|
|
716
|
+
*
|
|
717
|
+
* If this mutation's state is already `pending` when `execute` is called
|
|
718
|
+
* (i.e. it was restored, still in-flight, from a dehydrated state), the
|
|
719
|
+
* `onMutate` step is skipped and a `continue` action is dispatched to
|
|
720
|
+
* unpause it; otherwise a `pending` action is dispatched first, then the
|
|
721
|
+
* mutation cache's `onMutate` and the mutation's own `onMutate` option are
|
|
722
|
+
* awaited in that order, and the resulting context is stored.
|
|
723
|
+
*
|
|
724
|
+
* The mutation function is then run (subject to `retry`/`retryDelay`/
|
|
725
|
+
* `networkMode`, and to the mutation cache's scope-based serialization).
|
|
726
|
+
* On success, the cache's `onSuccess`/`onSettled` callbacks run before the
|
|
727
|
+
* mutation's own `onSuccess`/`onSettled` options, a `success` action is
|
|
728
|
+
* dispatched, and the resolved data is returned. On failure, the same
|
|
729
|
+
* cache-then-option ordering is used for `onError`/`onSettled`, but each of
|
|
730
|
+
* those four callbacks is individually caught so that a throwing callback
|
|
731
|
+
* cannot mask the original error; an `error` action is then dispatched and
|
|
732
|
+
* the original error is re-thrown.
|
|
733
|
+
* @param variables - The variables passed to the `mutationFn`.
|
|
734
|
+
* @returns A promise that resolves with the mutation's data, or rejects with its error.
|
|
735
|
+
* @see {@link Mutation#continue}
|
|
736
|
+
* @example
|
|
737
|
+
* ```ts
|
|
738
|
+
* // Called internally by `MutationObserver.mutate` and `Mutation.continue` —
|
|
739
|
+
* // applications normally trigger mutations through those, not this method.
|
|
740
|
+
* const data = await mutation.execute(variables)
|
|
741
|
+
* ```
|
|
742
|
+
*/
|
|
743
|
+
async execute(variables) {
|
|
744
|
+
const onContinue = () => {
|
|
745
|
+
this.#dispatch({ type: "continue" });
|
|
746
|
+
};
|
|
747
|
+
const mutationFnContext = {
|
|
748
|
+
client: this.#client,
|
|
749
|
+
meta: this.options.meta,
|
|
750
|
+
mutationKey: this.options.mutationKey
|
|
751
|
+
};
|
|
752
|
+
const retryer = this.#retryer = createRetryer({
|
|
753
|
+
fn: () => {
|
|
754
|
+
if (!this.options.mutationFn) return Promise.reject(/* @__PURE__ */ new Error("No mutationFn found"));
|
|
755
|
+
return this.options.mutationFn(variables, mutationFnContext);
|
|
756
|
+
},
|
|
757
|
+
onFail: (failureCount, error) => {
|
|
758
|
+
this.#dispatch({
|
|
759
|
+
type: "failed",
|
|
760
|
+
failureCount,
|
|
761
|
+
error
|
|
762
|
+
});
|
|
763
|
+
},
|
|
764
|
+
onPause: () => {
|
|
765
|
+
this.#dispatch({ type: "pause" });
|
|
766
|
+
},
|
|
767
|
+
onContinue,
|
|
768
|
+
retry: this.options.retry ?? 0,
|
|
769
|
+
retryDelay: this.options.retryDelay,
|
|
770
|
+
networkMode: this.options.networkMode,
|
|
771
|
+
canRun: () => this.#mutationCache.canRun(this)
|
|
772
|
+
});
|
|
773
|
+
const restored = this.state.status === "pending";
|
|
774
|
+
const isPaused = !retryer.canStart();
|
|
775
|
+
try {
|
|
776
|
+
if (restored) onContinue();
|
|
777
|
+
else {
|
|
778
|
+
this.#dispatch({
|
|
779
|
+
type: "pending",
|
|
780
|
+
variables,
|
|
781
|
+
isPaused
|
|
782
|
+
});
|
|
783
|
+
if (this.#mutationCache.config.onMutate) await this.#mutationCache.config.onMutate(variables, this, mutationFnContext);
|
|
784
|
+
const context = await this.options.onMutate?.(variables, mutationFnContext);
|
|
785
|
+
if (context !== this.state.context) this.#dispatch({
|
|
786
|
+
type: "pending",
|
|
787
|
+
context,
|
|
788
|
+
variables,
|
|
789
|
+
isPaused
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
if (this.state.isPaused && retryer.canStart()) onContinue();
|
|
793
|
+
const data = await retryer.start();
|
|
794
|
+
await this.#mutationCache.config.onSuccess?.(data, variables, this.state.context, this, mutationFnContext);
|
|
795
|
+
await this.options.onSuccess?.(data, variables, this.state.context, mutationFnContext);
|
|
796
|
+
await this.#mutationCache.config.onSettled?.(data, null, this.state.variables, this.state.context, this, mutationFnContext);
|
|
797
|
+
await this.options.onSettled?.(data, null, variables, this.state.context, mutationFnContext);
|
|
798
|
+
this.#dispatch({
|
|
799
|
+
type: "success",
|
|
800
|
+
data
|
|
801
|
+
});
|
|
802
|
+
return data;
|
|
803
|
+
} catch (error) {
|
|
804
|
+
try {
|
|
805
|
+
await this.#mutationCache.config.onError?.(error, variables, this.state.context, this, mutationFnContext);
|
|
806
|
+
} catch (e) {
|
|
807
|
+
Promise.reject(e);
|
|
808
|
+
}
|
|
809
|
+
try {
|
|
810
|
+
await this.options.onError?.(error, variables, this.state.context, mutationFnContext);
|
|
811
|
+
} catch (e) {
|
|
812
|
+
Promise.reject(e);
|
|
813
|
+
}
|
|
814
|
+
try {
|
|
815
|
+
await this.#mutationCache.config.onSettled?.(void 0, error, this.state.variables, this.state.context, this, mutationFnContext);
|
|
816
|
+
} catch (e) {
|
|
817
|
+
Promise.reject(e);
|
|
818
|
+
}
|
|
819
|
+
try {
|
|
820
|
+
await this.options.onSettled?.(void 0, error, variables, this.state.context, mutationFnContext);
|
|
821
|
+
} catch (e) {
|
|
822
|
+
Promise.reject(e);
|
|
823
|
+
}
|
|
824
|
+
this.#dispatch({
|
|
825
|
+
type: "error",
|
|
826
|
+
error
|
|
827
|
+
});
|
|
828
|
+
throw error;
|
|
829
|
+
} finally {
|
|
830
|
+
if (this.#retryer === retryer) this.#retryer = void 0;
|
|
831
|
+
this.#mutationCache.runNext(this);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
#dispatch(action) {
|
|
835
|
+
const reducer = (state) => {
|
|
836
|
+
switch (action.type) {
|
|
837
|
+
case "failed": return {
|
|
838
|
+
...state,
|
|
839
|
+
failureCount: action.failureCount,
|
|
840
|
+
failureReason: action.error
|
|
841
|
+
};
|
|
842
|
+
case "pause": return {
|
|
843
|
+
...state,
|
|
844
|
+
isPaused: true
|
|
845
|
+
};
|
|
846
|
+
case "continue": return {
|
|
847
|
+
...state,
|
|
848
|
+
isPaused: false
|
|
849
|
+
};
|
|
850
|
+
case "pending": return {
|
|
851
|
+
...state,
|
|
852
|
+
context: action.context,
|
|
853
|
+
data: void 0,
|
|
854
|
+
failureCount: 0,
|
|
855
|
+
failureReason: null,
|
|
856
|
+
error: null,
|
|
857
|
+
isPaused: action.isPaused,
|
|
858
|
+
status: "pending",
|
|
859
|
+
variables: action.variables,
|
|
860
|
+
submittedAt: Date.now()
|
|
861
|
+
};
|
|
862
|
+
case "success": return {
|
|
863
|
+
...state,
|
|
864
|
+
data: action.data,
|
|
865
|
+
failureCount: 0,
|
|
866
|
+
failureReason: null,
|
|
867
|
+
error: null,
|
|
868
|
+
status: "success",
|
|
869
|
+
isPaused: false
|
|
870
|
+
};
|
|
871
|
+
case "error": return {
|
|
872
|
+
...state,
|
|
873
|
+
data: void 0,
|
|
874
|
+
error: action.error,
|
|
875
|
+
failureCount: state.failureCount + 1,
|
|
876
|
+
failureReason: action.error,
|
|
877
|
+
isPaused: false,
|
|
878
|
+
status: "error"
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
};
|
|
882
|
+
this.state = reducer(this.state);
|
|
883
|
+
notifyManager.batch(() => {
|
|
884
|
+
this.#observers.forEach((observer) => {
|
|
885
|
+
observer.onMutationUpdate(action);
|
|
886
|
+
});
|
|
887
|
+
this.#mutationCache.notify({
|
|
888
|
+
mutation: this,
|
|
889
|
+
type: "updated",
|
|
890
|
+
action
|
|
891
|
+
});
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
};
|
|
895
|
+
/**
|
|
896
|
+
* Returns the initial state of a mutation: `'idle'`, with no data, error, or variables.
|
|
897
|
+
* @returns The initial mutation state.
|
|
898
|
+
*/
|
|
899
|
+
function getDefaultState() {
|
|
900
|
+
return {
|
|
901
|
+
context: void 0,
|
|
902
|
+
data: void 0,
|
|
903
|
+
error: null,
|
|
904
|
+
failureCount: 0,
|
|
905
|
+
failureReason: null,
|
|
906
|
+
isPaused: false,
|
|
907
|
+
status: "idle",
|
|
908
|
+
variables: void 0,
|
|
909
|
+
submittedAt: 0
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
// ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/mutationCache.js
|
|
913
|
+
/**
|
|
914
|
+
* The `MutationCache` is the storage for mutations.
|
|
915
|
+
*
|
|
916
|
+
* Normally, you will not interact with the `MutationCache` directly and instead use a
|
|
917
|
+
* `QueryClient`. You can subscribe to it (inherited from `Subscribable`) to be informed of
|
|
918
|
+
* safe/known updates to the cache, such as mutations being added, removed, or updated.
|
|
919
|
+
* @example
|
|
920
|
+
* ```ts
|
|
921
|
+
* const unsubscribe = mutationCache.subscribe((event) => {
|
|
922
|
+
* console.log(event.type, event.mutation)
|
|
923
|
+
* })
|
|
924
|
+
* ```
|
|
925
|
+
*/
|
|
926
|
+
var MutationCache = class extends Subscribable {
|
|
927
|
+
#mutations;
|
|
928
|
+
#scopes;
|
|
929
|
+
#mutationId;
|
|
930
|
+
constructor(config = {}) {
|
|
931
|
+
super();
|
|
932
|
+
this.config = config;
|
|
933
|
+
this.#mutations = /* @__PURE__ */ new Set();
|
|
934
|
+
this.#scopes = /* @__PURE__ */ new Map();
|
|
935
|
+
this.#mutationId = 0;
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
* Creates a mutation and adds it to the cache.
|
|
939
|
+
* @internal
|
|
940
|
+
* @param client - The client the mutation belongs to, used to default its options.
|
|
941
|
+
* @param options - The mutation options. They are defaulted with {@link
|
|
942
|
+
* QueryClient#defaultMutationOptions}.
|
|
943
|
+
* @param state - The initial state of the mutation, e.g. when restoring a dehydrated mutation.
|
|
944
|
+
* @returns The new mutation, already added to the cache.
|
|
945
|
+
*/
|
|
946
|
+
build(client, options, state) {
|
|
947
|
+
const mutation = new Mutation({
|
|
948
|
+
client,
|
|
949
|
+
mutationCache: this,
|
|
950
|
+
mutationId: ++this.#mutationId,
|
|
951
|
+
options: client.defaultMutationOptions(options),
|
|
952
|
+
state
|
|
953
|
+
});
|
|
954
|
+
this.add(mutation);
|
|
955
|
+
return mutation;
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
* Adds a mutation to the cache.
|
|
959
|
+
* @internal
|
|
960
|
+
* @param mutation - The mutation to add. If it has a `scope`, it is queued in that scope.
|
|
961
|
+
*/
|
|
962
|
+
add(mutation) {
|
|
963
|
+
this.#mutations.add(mutation);
|
|
964
|
+
const scope = scopeFor(mutation);
|
|
965
|
+
if (typeof scope === "string") {
|
|
966
|
+
const scopedMutations = this.#scopes.get(scope);
|
|
967
|
+
if (scopedMutations) scopedMutations.push(mutation);
|
|
968
|
+
else this.#scopes.set(scope, [mutation]);
|
|
969
|
+
}
|
|
970
|
+
this.notify({
|
|
971
|
+
type: "added",
|
|
972
|
+
mutation
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* Removes a mutation from the cache.
|
|
977
|
+
* @internal
|
|
978
|
+
* @param mutation - The mutation to remove, also from its scope's queue.
|
|
979
|
+
*/
|
|
980
|
+
remove(mutation) {
|
|
981
|
+
if (this.#mutations.delete(mutation)) {
|
|
982
|
+
const scope = scopeFor(mutation);
|
|
983
|
+
if (typeof scope === "string") {
|
|
984
|
+
const scopedMutations = this.#scopes.get(scope);
|
|
985
|
+
if (scopedMutations) {
|
|
986
|
+
if (scopedMutations.length > 1) {
|
|
987
|
+
const index = scopedMutations.indexOf(mutation);
|
|
988
|
+
if (index !== -1) scopedMutations.splice(index, 1);
|
|
989
|
+
} else if (scopedMutations[0] === mutation) this.#scopes.delete(scope);
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
this.notify({
|
|
994
|
+
type: "removed",
|
|
995
|
+
mutation
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
/**
|
|
999
|
+
* Checks whether a mutation can run now, given the other mutations in its `scope`.
|
|
1000
|
+
* @internal
|
|
1001
|
+
* @param mutation - The mutation to check.
|
|
1002
|
+
* @returns `true` if the mutation has no `scope`, or no other mutation in its scope is pending
|
|
1003
|
+
* ahead of it.
|
|
1004
|
+
*/
|
|
1005
|
+
canRun(mutation) {
|
|
1006
|
+
const scope = scopeFor(mutation);
|
|
1007
|
+
if (typeof scope === "string") {
|
|
1008
|
+
const firstPendingMutation = this.#scopes.get(scope)?.find((m) => m.state.status === "pending");
|
|
1009
|
+
return !firstPendingMutation || firstPendingMutation === mutation;
|
|
1010
|
+
} else return true;
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* Continues the next paused mutation in the same `scope` after a mutation finishes.
|
|
1014
|
+
* @internal
|
|
1015
|
+
* @param mutation - The mutation that finished.
|
|
1016
|
+
* @returns A promise that resolves once the next paused mutation in the same scope has continued,
|
|
1017
|
+
* or immediately if there is none.
|
|
1018
|
+
*/
|
|
1019
|
+
runNext(mutation) {
|
|
1020
|
+
const scope = scopeFor(mutation);
|
|
1021
|
+
if (typeof scope === "string") return (this.#scopes.get(scope)?.find((m) => m !== mutation && m.state.isPaused))?.continue() ?? Promise.resolve();
|
|
1022
|
+
else return Promise.resolve();
|
|
1023
|
+
}
|
|
1024
|
+
/**
|
|
1025
|
+
* Removes all mutations from the cache.
|
|
1026
|
+
* @example
|
|
1027
|
+
* ```ts
|
|
1028
|
+
* const mutationCache = queryClient.getMutationCache()
|
|
1029
|
+
*
|
|
1030
|
+
* mutationCache.clear()
|
|
1031
|
+
* ```
|
|
1032
|
+
*/
|
|
1033
|
+
clear() {
|
|
1034
|
+
notifyManager.batch(() => {
|
|
1035
|
+
const mutations = this.getAll();
|
|
1036
|
+
this.#mutations.clear();
|
|
1037
|
+
this.#scopes.clear();
|
|
1038
|
+
mutations.forEach((mutation) => {
|
|
1039
|
+
this.notify({
|
|
1040
|
+
type: "removed",
|
|
1041
|
+
mutation
|
|
1042
|
+
});
|
|
1043
|
+
});
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1046
|
+
/**
|
|
1047
|
+
* Returns all mutations within the cache.
|
|
1048
|
+
*
|
|
1049
|
+
* This is not typically needed for most applications, but can come in handy when needing more
|
|
1050
|
+
* information about a mutation in rare scenarios.
|
|
1051
|
+
* @returns Every mutation in the cache.
|
|
1052
|
+
* @example
|
|
1053
|
+
* ```ts
|
|
1054
|
+
* const mutationCache = queryClient.getMutationCache()
|
|
1055
|
+
*
|
|
1056
|
+
* const mutations = mutationCache.getAll()
|
|
1057
|
+
* ```
|
|
1058
|
+
*/
|
|
1059
|
+
getAll() {
|
|
1060
|
+
return Array.from(this.#mutations);
|
|
1061
|
+
}
|
|
1062
|
+
/**
|
|
1063
|
+
* A slightly more advanced method that can be used to get an existing mutation instance from
|
|
1064
|
+
* the cache. If the mutation does not exist, `undefined` is returned.
|
|
1065
|
+
*
|
|
1066
|
+
* This is not typically needed for most applications, but can come in handy when needing more
|
|
1067
|
+
* information about a mutation in rare scenarios.
|
|
1068
|
+
* @param filters - The filters to match. `exact` defaults to `true`.
|
|
1069
|
+
* @returns The first matching mutation, or `undefined`.
|
|
1070
|
+
* @see {@link MutationCache#findAll}
|
|
1071
|
+
* @example
|
|
1072
|
+
* ```ts
|
|
1073
|
+
* const mutationCache = queryClient.getMutationCache()
|
|
1074
|
+
*
|
|
1075
|
+
* const mutation = mutationCache.find({ mutationKey: ['addPost'] })
|
|
1076
|
+
* ```
|
|
1077
|
+
*/
|
|
1078
|
+
find(filters) {
|
|
1079
|
+
const defaultedFilters = {
|
|
1080
|
+
exact: true,
|
|
1081
|
+
...filters
|
|
1082
|
+
};
|
|
1083
|
+
return this.getAll().find((mutation) => matchMutation(defaultedFilters, mutation));
|
|
1084
|
+
}
|
|
1085
|
+
/**
|
|
1086
|
+
* An even more advanced method that can be used to get existing mutation instances from the
|
|
1087
|
+
* cache that match the given filters. If no mutations match, an empty array is returned.
|
|
1088
|
+
*
|
|
1089
|
+
* This is not typically needed for most applications, but can come in handy when needing more
|
|
1090
|
+
* information about mutations in rare scenarios.
|
|
1091
|
+
* @param filters - The filters to match. Without filters, every mutation is returned.
|
|
1092
|
+
* @returns The matching mutations.
|
|
1093
|
+
* @see {@link MutationCache#find}
|
|
1094
|
+
* @example
|
|
1095
|
+
* ```ts
|
|
1096
|
+
* const mutationCache = queryClient.getMutationCache()
|
|
1097
|
+
*
|
|
1098
|
+
* const mutations = mutationCache.findAll({ mutationKey: ['addPost'] })
|
|
1099
|
+
* ```
|
|
1100
|
+
*/
|
|
1101
|
+
findAll(filters = {}) {
|
|
1102
|
+
return this.getAll().filter((mutation) => matchMutation(filters, mutation));
|
|
1103
|
+
}
|
|
1104
|
+
/**
|
|
1105
|
+
* Notifies every cache listener of an event, in one batch.
|
|
1106
|
+
* @internal
|
|
1107
|
+
* @param event - The event passed to every listener.
|
|
1108
|
+
*/
|
|
1109
|
+
notify(event) {
|
|
1110
|
+
notifyManager.batch(() => {
|
|
1111
|
+
this.listeners.forEach((listener) => {
|
|
1112
|
+
listener(event);
|
|
1113
|
+
});
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Continues every paused mutation, e.g. when the app comes back online.
|
|
1118
|
+
* @internal
|
|
1119
|
+
* @returns A promise that resolves once every paused mutation has continued and settled.
|
|
1120
|
+
*/
|
|
1121
|
+
resumePausedMutations() {
|
|
1122
|
+
const pausedMutations = this.getAll().filter((x) => x.state.isPaused);
|
|
1123
|
+
return notifyManager.batch(() => Promise.all(pausedMutations.map((mutation) => mutation.continue().catch(noop))));
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
1126
|
+
/**
|
|
1127
|
+
* Returns the scope id of a mutation, used to run mutations with the same scope one after another.
|
|
1128
|
+
* @param mutation - The mutation to read the scope of.
|
|
1129
|
+
* @returns The mutation's `scope.id`, or `undefined` if it has no scope.
|
|
1130
|
+
*/
|
|
1131
|
+
function scopeFor(mutation) {
|
|
1132
|
+
return mutation.options.scope?.id;
|
|
1133
|
+
}
|
|
1134
|
+
// ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/mutationObserver.js
|
|
1135
|
+
/**
|
|
1136
|
+
* Observes a single mutation and derives a `MutationObserverResult` from it.
|
|
1137
|
+
* A framework hook like `useMutation` creates one `MutationObserver` per hook
|
|
1138
|
+
* call, keeps it stable across re-renders, calls `setOptions` when the options
|
|
1139
|
+
* passed to the hook change, subscribes to it to re-render on updates, and
|
|
1140
|
+
* reads `getCurrentResult()` for the value to return. Calling `mutate()`
|
|
1141
|
+
* builds a new underlying `Mutation` in the `MutationCache` and executes it.
|
|
1142
|
+
* @example
|
|
1143
|
+
* ```ts
|
|
1144
|
+
* const observer = new MutationObserver(queryClient, {
|
|
1145
|
+
* mutationFn: (variables: { title: string }) => addPost(variables),
|
|
1146
|
+
* })
|
|
1147
|
+
* ```
|
|
1148
|
+
*/
|
|
1149
|
+
var MutationObserver = class extends Subscribable {
|
|
1150
|
+
#client;
|
|
1151
|
+
#currentResult = void 0;
|
|
1152
|
+
#currentMutation;
|
|
1153
|
+
#mutateOptions;
|
|
1154
|
+
constructor(client, options) {
|
|
1155
|
+
super();
|
|
1156
|
+
this.#client = client;
|
|
1157
|
+
this.setOptions(options);
|
|
1158
|
+
this.bindMethods();
|
|
1159
|
+
this.#updateResult();
|
|
1160
|
+
}
|
|
1161
|
+
/**
|
|
1162
|
+
* Binds the methods of the result (`mutate` and `reset`) to the observer, so they keep working when
|
|
1163
|
+
* destructured from it.
|
|
1164
|
+
*/
|
|
1165
|
+
bindMethods() {
|
|
1166
|
+
this.mutate = this.mutate.bind(this);
|
|
1167
|
+
this.reset = this.reset.bind(this);
|
|
1168
|
+
}
|
|
1169
|
+
/**
|
|
1170
|
+
* Updates the observer's options.
|
|
1171
|
+
*
|
|
1172
|
+
* If the new `mutationKey` differs from the previous one (and both were
|
|
1173
|
+
* defined), the observer is reset, detaching it from the mutation it was
|
|
1174
|
+
* observing. Otherwise, if the currently observed mutation is still
|
|
1175
|
+
* `pending`, its options are updated in place as well.
|
|
1176
|
+
* @param options - The new mutation observer options. They are defaulted with {@link
|
|
1177
|
+
* QueryClient#defaultMutationOptions} before being applied.
|
|
1178
|
+
* @example
|
|
1179
|
+
* ```ts
|
|
1180
|
+
* observer.setOptions({
|
|
1181
|
+
* mutationFn: (variables: { title: string }) => addPost(variables),
|
|
1182
|
+
* onSuccess: (data) => console.log(data),
|
|
1183
|
+
* })
|
|
1184
|
+
* ```
|
|
1185
|
+
*/
|
|
1186
|
+
setOptions(options) {
|
|
1187
|
+
const prevOptions = this.options;
|
|
1188
|
+
this.options = this.#client.defaultMutationOptions(options);
|
|
1189
|
+
if (!shallowEqualObjects(this.options, prevOptions)) this.#client.getMutationCache().notify({
|
|
1190
|
+
type: "observerOptionsUpdated",
|
|
1191
|
+
mutation: this.#currentMutation,
|
|
1192
|
+
observer: this
|
|
1193
|
+
});
|
|
1194
|
+
if (prevOptions?.mutationKey && this.options.mutationKey && hashKey(prevOptions.mutationKey) !== hashKey(this.options.mutationKey)) this.reset();
|
|
1195
|
+
else if (this.#currentMutation?.state.status === "pending") this.#currentMutation.setOptions(this.options);
|
|
1196
|
+
}
|
|
1197
|
+
onSubscribe() {
|
|
1198
|
+
if (this.listeners.size === 1 && this.#currentMutation) {
|
|
1199
|
+
this.#currentMutation.addObserver(this);
|
|
1200
|
+
this.#updateResult();
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
onUnsubscribe() {
|
|
1204
|
+
if (!this.hasListeners()) this.#currentMutation?.removeObserver(this);
|
|
1205
|
+
}
|
|
1206
|
+
/**
|
|
1207
|
+
* Updates the observer's result when the observed mutation changes, and notifies its listeners.
|
|
1208
|
+
* @internal
|
|
1209
|
+
* @param action - The action that updated the observed mutation, passed on to the observer's
|
|
1210
|
+
* callbacks.
|
|
1211
|
+
*/
|
|
1212
|
+
onMutationUpdate(action) {
|
|
1213
|
+
this.#updateResult();
|
|
1214
|
+
this.#notify(action);
|
|
1215
|
+
}
|
|
1216
|
+
/**
|
|
1217
|
+
* Returns the observer's current result, derived from the observed
|
|
1218
|
+
* mutation's state (or the default, `idle` state if no mutation has been
|
|
1219
|
+
* built yet, e.g. before the first `mutate()` call or after `reset()`).
|
|
1220
|
+
* @returns The observer's latest result.
|
|
1221
|
+
*/
|
|
1222
|
+
getCurrentResult() {
|
|
1223
|
+
return this.#currentResult;
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* Detaches the observer from the mutation it is currently observing (if
|
|
1227
|
+
* any) and resets the observed result back to its default, `idle` state.
|
|
1228
|
+
*
|
|
1229
|
+
* This does not cancel an in-flight mutation; the mutation itself keeps
|
|
1230
|
+
* running to completion and its own callbacks still fire, but this
|
|
1231
|
+
* observer stops reflecting its state and a subsequent `mutate()` call
|
|
1232
|
+
* will build a brand new mutation.
|
|
1233
|
+
* @see {@link MutationObserver#mutate}
|
|
1234
|
+
* @example
|
|
1235
|
+
* ```ts
|
|
1236
|
+
* observer.reset()
|
|
1237
|
+
* ```
|
|
1238
|
+
*/
|
|
1239
|
+
reset() {
|
|
1240
|
+
this.#currentMutation?.removeObserver(this);
|
|
1241
|
+
this.#currentMutation = void 0;
|
|
1242
|
+
this.#updateResult();
|
|
1243
|
+
this.#notify();
|
|
1244
|
+
}
|
|
1245
|
+
/**
|
|
1246
|
+
* Builds a new `Mutation` in the `MutationCache` using the observer's
|
|
1247
|
+
* current options, detaches this observer from any previously observed
|
|
1248
|
+
* mutation, attaches it to the new one, and executes it with the given
|
|
1249
|
+
* variables.
|
|
1250
|
+
*
|
|
1251
|
+
* The optional per-call `options` (`onSuccess`/`onError`/`onSettled`) are
|
|
1252
|
+
* invoked once the mutation settles, in addition to any callbacks defined
|
|
1253
|
+
* on the observer's own options.
|
|
1254
|
+
* @param variables - The variables passed to the `mutationFn`.
|
|
1255
|
+
* @param options - Per-call `onSuccess`, `onError`, and `onSettled` callbacks.
|
|
1256
|
+
* @returns A promise that resolves with the mutation's data, or rejects with its error.
|
|
1257
|
+
* @example
|
|
1258
|
+
* ```ts
|
|
1259
|
+
* await observer.mutate(
|
|
1260
|
+
* { title: 'New post' },
|
|
1261
|
+
* { onSuccess: (data) => console.log(data) },
|
|
1262
|
+
* )
|
|
1263
|
+
* ```
|
|
1264
|
+
*/
|
|
1265
|
+
mutate(variables, options) {
|
|
1266
|
+
this.#mutateOptions = options;
|
|
1267
|
+
this.#currentMutation?.removeObserver(this);
|
|
1268
|
+
this.#currentMutation = this.#client.getMutationCache().build(this.#client, this.options);
|
|
1269
|
+
this.#currentMutation.addObserver(this);
|
|
1270
|
+
return this.#currentMutation.execute(variables);
|
|
1271
|
+
}
|
|
1272
|
+
#updateResult() {
|
|
1273
|
+
const state = this.#currentMutation?.state ?? getDefaultState();
|
|
1274
|
+
this.#currentResult = {
|
|
1275
|
+
...state,
|
|
1276
|
+
isPending: state.status === "pending",
|
|
1277
|
+
isSuccess: state.status === "success",
|
|
1278
|
+
isError: state.status === "error",
|
|
1279
|
+
isIdle: state.status === "idle",
|
|
1280
|
+
mutate: this.mutate,
|
|
1281
|
+
reset: this.reset
|
|
1282
|
+
};
|
|
1283
|
+
}
|
|
1284
|
+
#notify(action) {
|
|
1285
|
+
notifyManager.batch(() => {
|
|
1286
|
+
const mutateOptions = this.#mutateOptions;
|
|
1287
|
+
if (mutateOptions && this.hasListeners()) {
|
|
1288
|
+
const variables = this.#currentResult.variables;
|
|
1289
|
+
const onMutateResult = this.#currentResult.context;
|
|
1290
|
+
const context = {
|
|
1291
|
+
client: this.#client,
|
|
1292
|
+
meta: this.options.meta,
|
|
1293
|
+
mutationKey: this.options.mutationKey
|
|
1294
|
+
};
|
|
1295
|
+
if (action?.type === "success") {
|
|
1296
|
+
try {
|
|
1297
|
+
mutateOptions.onSuccess?.(action.data, variables, onMutateResult, context);
|
|
1298
|
+
} catch (e) {
|
|
1299
|
+
Promise.reject(e);
|
|
1300
|
+
}
|
|
1301
|
+
try {
|
|
1302
|
+
mutateOptions.onSettled?.(action.data, null, variables, onMutateResult, context);
|
|
1303
|
+
} catch (e) {
|
|
1304
|
+
Promise.reject(e);
|
|
1305
|
+
}
|
|
1306
|
+
} else if (action?.type === "error") {
|
|
1307
|
+
try {
|
|
1308
|
+
mutateOptions.onError?.(action.error, variables, onMutateResult, context);
|
|
1309
|
+
} catch (e) {
|
|
1310
|
+
Promise.reject(e);
|
|
1311
|
+
}
|
|
1312
|
+
try {
|
|
1313
|
+
mutateOptions.onSettled?.(void 0, action.error, variables, onMutateResult, context);
|
|
1314
|
+
} catch (e) {
|
|
1315
|
+
Promise.reject(e);
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
this.listeners.forEach((listener) => {
|
|
1320
|
+
listener(this.#currentResult);
|
|
1321
|
+
});
|
|
1322
|
+
});
|
|
1323
|
+
}
|
|
1324
|
+
};
|
|
1325
|
+
// ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/queryCache.js
|
|
1326
|
+
/**
|
|
1327
|
+
* The `QueryCache` is the storage mechanism for TanStack Query. It stores all the data, meta
|
|
1328
|
+
* information, and state of the queries it contains.
|
|
1329
|
+
*
|
|
1330
|
+
* Normally, you will not interact with the `QueryCache` directly and instead use a `QueryClient`
|
|
1331
|
+
* for a specific cache. You can subscribe to it (inherited from `Subscribable`) to be informed of
|
|
1332
|
+
* safe/known updates to the cache, such as queries being added, removed, or updated — updates made
|
|
1333
|
+
* outside of the cache's own tracked mechanisms (e.g. mutating a query's state object directly) do
|
|
1334
|
+
* not notify subscribers.
|
|
1335
|
+
* @example
|
|
1336
|
+
* ```ts
|
|
1337
|
+
* const unsubscribe = queryCache.subscribe((event) => {
|
|
1338
|
+
* console.log(event.type, event.query)
|
|
1339
|
+
* })
|
|
1340
|
+
* ```
|
|
1341
|
+
*/
|
|
1342
|
+
var QueryCache = class extends Subscribable {
|
|
1343
|
+
#queries;
|
|
1344
|
+
constructor(config = {}) {
|
|
1345
|
+
super();
|
|
1346
|
+
this.config = config;
|
|
1347
|
+
this.#queries = /* @__PURE__ */ new Map();
|
|
1348
|
+
}
|
|
1349
|
+
/**
|
|
1350
|
+
* Returns the existing `Query` instance for the given options' `queryKey`/`queryHash`, or
|
|
1351
|
+
* builds and adds a new one to the cache if none exists yet. Used by framework adapters and
|
|
1352
|
+
* plugins (e.g. broadcast/persistence) that need to get-or-create a `Query` directly, bypassing
|
|
1353
|
+
* the reactive `QueryObserver` machinery.
|
|
1354
|
+
* @param client - The client the query belongs to, used to default its options.
|
|
1355
|
+
* @param options - The query options, including the `queryKey`. A new query is created with the
|
|
1356
|
+
* options defaulted by {@link QueryClient#defaultQueryOptions}.
|
|
1357
|
+
* @param state - The initial state of a newly created query, e.g. when hydrating. Ignored if the
|
|
1358
|
+
* query already exists.
|
|
1359
|
+
* @returns The existing or newly created query.
|
|
1360
|
+
* @example
|
|
1361
|
+
* ```ts
|
|
1362
|
+
* const queryCache = queryClient.getQueryCache()
|
|
1363
|
+
*
|
|
1364
|
+
* const query = queryCache.build(queryClient, {
|
|
1365
|
+
* queryKey: ['posts'],
|
|
1366
|
+
* queryFn: fetchPosts,
|
|
1367
|
+
* })
|
|
1368
|
+
* ```
|
|
1369
|
+
*/
|
|
1370
|
+
build(client, options, state) {
|
|
1371
|
+
const queryKey = options.queryKey;
|
|
1372
|
+
const queryHash = options.queryHash ?? hashQueryKeyByOptions(queryKey, options);
|
|
1373
|
+
let query = this.get(queryHash);
|
|
1374
|
+
if (!query) {
|
|
1375
|
+
query = new Query({
|
|
1376
|
+
client,
|
|
1377
|
+
queryKey,
|
|
1378
|
+
queryHash,
|
|
1379
|
+
options: client.defaultQueryOptions(options),
|
|
1380
|
+
state,
|
|
1381
|
+
defaultOptions: client.getQueryDefaults(queryKey)
|
|
1382
|
+
});
|
|
1383
|
+
this.add(query);
|
|
1384
|
+
}
|
|
1385
|
+
return query;
|
|
1386
|
+
}
|
|
1387
|
+
/**
|
|
1388
|
+
* Adds a query to the cache.
|
|
1389
|
+
* @internal
|
|
1390
|
+
* @param query - The query to add. If a query with the same hash is already cached, nothing
|
|
1391
|
+
* happens.
|
|
1392
|
+
*/
|
|
1393
|
+
add(query) {
|
|
1394
|
+
if (!this.#queries.has(query.queryHash)) {
|
|
1395
|
+
this.#queries.set(query.queryHash, query);
|
|
1396
|
+
this.notify({
|
|
1397
|
+
type: "added",
|
|
1398
|
+
query
|
|
1399
|
+
});
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* Destroys the given `Query` and removes it from the cache, notifying subscribers with a
|
|
1404
|
+
* `'removed'` event. A no-op if the query is no longer the one currently stored under its hash
|
|
1405
|
+
* (e.g. it was already replaced). Used by plugins (e.g. the broadcast client) that mirror
|
|
1406
|
+
* removals across `QueryCache` instances.
|
|
1407
|
+
* @param query - The query to remove.
|
|
1408
|
+
* @example
|
|
1409
|
+
* ```ts
|
|
1410
|
+
* const queryCache = queryClient.getQueryCache()
|
|
1411
|
+
* const query = queryCache.find({ queryKey: ['posts'] })
|
|
1412
|
+
*
|
|
1413
|
+
* if (query) {
|
|
1414
|
+
* queryCache.remove(query)
|
|
1415
|
+
* }
|
|
1416
|
+
* ```
|
|
1417
|
+
*/
|
|
1418
|
+
remove(query) {
|
|
1419
|
+
if (this.#queries.get(query.queryHash) === query) {
|
|
1420
|
+
query.destroy();
|
|
1421
|
+
this.#queries.delete(query.queryHash);
|
|
1422
|
+
this.notify({
|
|
1423
|
+
type: "removed",
|
|
1424
|
+
query
|
|
1425
|
+
});
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
/**
|
|
1429
|
+
* Removes all queries from the cache.
|
|
1430
|
+
* @example
|
|
1431
|
+
* ```ts
|
|
1432
|
+
* const queryCache = queryClient.getQueryCache()
|
|
1433
|
+
*
|
|
1434
|
+
* queryCache.clear()
|
|
1435
|
+
* ```
|
|
1436
|
+
*/
|
|
1437
|
+
clear() {
|
|
1438
|
+
notifyManager.batch(() => {
|
|
1439
|
+
this.getAll().forEach((query) => {
|
|
1440
|
+
this.remove(query);
|
|
1441
|
+
});
|
|
1442
|
+
});
|
|
1443
|
+
}
|
|
1444
|
+
/**
|
|
1445
|
+
* Returns the `Query` instance stored under the given `queryHash`, or `undefined` if none
|
|
1446
|
+
* exists. Unlike {@link QueryCache#find}, this looks up by the already-computed hash rather
|
|
1447
|
+
* than by `QueryFilters`. Used by plugins (e.g. broadcast/hydration) that already have a hash
|
|
1448
|
+
* to look up directly.
|
|
1449
|
+
* @param queryHash - The hash of the query to look up.
|
|
1450
|
+
* @returns The query stored under the hash, or `undefined`.
|
|
1451
|
+
* @example
|
|
1452
|
+
* ```ts
|
|
1453
|
+
* const queryCache = queryClient.getQueryCache()
|
|
1454
|
+
* const queryHash = hashKey(['posts'])
|
|
1455
|
+
*
|
|
1456
|
+
* const query = queryCache.get(queryHash)
|
|
1457
|
+
* ```
|
|
1458
|
+
*/
|
|
1459
|
+
get(queryHash) {
|
|
1460
|
+
return this.#queries.get(queryHash);
|
|
1461
|
+
}
|
|
1462
|
+
/**
|
|
1463
|
+
* Returns all queries within the cache.
|
|
1464
|
+
* @returns Every query in the cache.
|
|
1465
|
+
* @example
|
|
1466
|
+
* ```ts
|
|
1467
|
+
* const queryCache = queryClient.getQueryCache()
|
|
1468
|
+
*
|
|
1469
|
+
* const queries = queryCache.getAll()
|
|
1470
|
+
* ```
|
|
1471
|
+
*/
|
|
1472
|
+
getAll() {
|
|
1473
|
+
return [...this.#queries.values()];
|
|
1474
|
+
}
|
|
1475
|
+
/**
|
|
1476
|
+
* A slightly more advanced method that can be used to get an existing query instance from the
|
|
1477
|
+
* cache. This instance not only contains all the state for the query, but all of the instances,
|
|
1478
|
+
* and underlying guts of the query as well. If the query does not exist, `undefined` is
|
|
1479
|
+
* returned.
|
|
1480
|
+
*
|
|
1481
|
+
* This is not typically needed for most applications, but can come in handy when needing more
|
|
1482
|
+
* information about a query in rare scenarios (e.g. looking at `query.state.dataUpdatedAt` to
|
|
1483
|
+
* decide whether a query is fresh enough to be used as an initial value).
|
|
1484
|
+
* @param filters - The filters to match, including the required `queryKey`. `exact` defaults to
|
|
1485
|
+
* `true`.
|
|
1486
|
+
* @returns The first matching query, or `undefined`.
|
|
1487
|
+
* @see {@link QueryCache#findAll}
|
|
1488
|
+
* @example
|
|
1489
|
+
* ```ts
|
|
1490
|
+
* const queryCache = queryClient.getQueryCache()
|
|
1491
|
+
*
|
|
1492
|
+
* const query = queryCache.find({ queryKey: ['posts'] })
|
|
1493
|
+
* ```
|
|
1494
|
+
*/
|
|
1495
|
+
find(filters) {
|
|
1496
|
+
const defaultedFilters = {
|
|
1497
|
+
exact: true,
|
|
1498
|
+
...filters
|
|
1499
|
+
};
|
|
1500
|
+
return this.getAll().find((query) => matchQuery(defaultedFilters, query));
|
|
1501
|
+
}
|
|
1502
|
+
/**
|
|
1503
|
+
* An even more advanced method that can be used to get existing query instances from the cache
|
|
1504
|
+
* that partially match a query key. If no queries match, an empty array is returned.
|
|
1505
|
+
*
|
|
1506
|
+
* This is not typically needed for most applications, but can come in handy when needing more
|
|
1507
|
+
* information about queries in rare scenarios.
|
|
1508
|
+
* @param filters - The filters to match. Without filters, every query is returned.
|
|
1509
|
+
* @returns The matching queries.
|
|
1510
|
+
* @see {@link QueryCache#find}
|
|
1511
|
+
* @example
|
|
1512
|
+
* ```ts
|
|
1513
|
+
* const queryCache = queryClient.getQueryCache()
|
|
1514
|
+
*
|
|
1515
|
+
* const queries = queryCache.findAll({ queryKey: ['posts'] })
|
|
1516
|
+
* ```
|
|
1517
|
+
*/
|
|
1518
|
+
findAll(filters = {}) {
|
|
1519
|
+
const queries = this.getAll();
|
|
1520
|
+
return Object.keys(filters).length > 0 ? queries.filter((query) => matchQuery(filters, query)) : queries;
|
|
1521
|
+
}
|
|
1522
|
+
/**
|
|
1523
|
+
* Notifies every cache listener of an event, in one batch.
|
|
1524
|
+
* @internal
|
|
1525
|
+
* @param event - The event passed to every listener.
|
|
1526
|
+
*/
|
|
1527
|
+
notify(event) {
|
|
1528
|
+
notifyManager.batch(() => {
|
|
1529
|
+
this.listeners.forEach((listener) => {
|
|
1530
|
+
listener(event);
|
|
1531
|
+
});
|
|
1532
|
+
});
|
|
1533
|
+
}
|
|
1534
|
+
/**
|
|
1535
|
+
* Calls {@link Query#onFocus} on every cached query, in one batch.
|
|
1536
|
+
* @internal
|
|
1537
|
+
*/
|
|
1538
|
+
onFocus() {
|
|
1539
|
+
notifyManager.batch(() => {
|
|
1540
|
+
this.getAll().forEach((query) => {
|
|
1541
|
+
query.onFocus();
|
|
1542
|
+
});
|
|
1543
|
+
});
|
|
1544
|
+
}
|
|
1545
|
+
/**
|
|
1546
|
+
* Calls {@link Query#onOnline} on every cached query, in one batch.
|
|
1547
|
+
* @internal
|
|
1548
|
+
*/
|
|
1549
|
+
onOnline() {
|
|
1550
|
+
notifyManager.batch(() => {
|
|
1551
|
+
this.getAll().forEach((query) => {
|
|
1552
|
+
query.onOnline();
|
|
1553
|
+
});
|
|
1554
|
+
});
|
|
1555
|
+
}
|
|
1556
|
+
};
|
|
1557
|
+
// ../../node_modules/.bun/@tanstack+query-core@5.105.3/node_modules/@tanstack/query-core/build/modern/queryClient.js
|
|
1558
|
+
/**
|
|
1559
|
+
* `QueryClient` is used to interact with a cache of queries and mutations. It owns a
|
|
1560
|
+
* `QueryCache` and a `MutationCache` (creating default ones if none are passed in) and holds
|
|
1561
|
+
* the default options that are applied to queries and mutations created through it.
|
|
1562
|
+
* @example
|
|
1563
|
+
* ```ts
|
|
1564
|
+
* const queryClient = new QueryClient({
|
|
1565
|
+
* defaultOptions: {
|
|
1566
|
+
* queries: {
|
|
1567
|
+
* staleTime: Infinity,
|
|
1568
|
+
* },
|
|
1569
|
+
* },
|
|
1570
|
+
* })
|
|
1571
|
+
*
|
|
1572
|
+
* await queryClient.query({ queryKey: ['posts'], queryFn: fetchPosts })
|
|
1573
|
+
* ```
|
|
1574
|
+
*/
|
|
1575
|
+
var QueryClient = class {
|
|
1576
|
+
#queryCache;
|
|
1577
|
+
#mutationCache;
|
|
1578
|
+
#defaultOptions;
|
|
1579
|
+
#queryDefaults;
|
|
1580
|
+
#mutationDefaults;
|
|
1581
|
+
#mountCount;
|
|
1582
|
+
#unsubscribeFocus;
|
|
1583
|
+
#unsubscribeOnline;
|
|
1584
|
+
constructor(config = {}) {
|
|
1585
|
+
this.#queryCache = config.queryCache || new QueryCache();
|
|
1586
|
+
this.#mutationCache = config.mutationCache || new MutationCache();
|
|
1587
|
+
this.#defaultOptions = config.defaultOptions || {};
|
|
1588
|
+
this.#queryDefaults = /* @__PURE__ */ new Map();
|
|
1589
|
+
this.#mutationDefaults = /* @__PURE__ */ new Map();
|
|
1590
|
+
this.#mountCount = 0;
|
|
1591
|
+
}
|
|
1592
|
+
/**
|
|
1593
|
+
* Called by a framework adapter's `QueryClientProvider`-equivalent when it mounts, to start
|
|
1594
|
+
* listening for focus/online events and resume paused mutations. Ref-counted via an internal
|
|
1595
|
+
* mount count, so nested or multiple providers sharing the same `QueryClient` don't tear down
|
|
1596
|
+
* the shared listeners until the last one unmounts.
|
|
1597
|
+
*/
|
|
1598
|
+
mount() {
|
|
1599
|
+
this.#mountCount++;
|
|
1600
|
+
if (this.#mountCount !== 1) return;
|
|
1601
|
+
this.#unsubscribeFocus = focusManager.subscribe(async (focused) => {
|
|
1602
|
+
if (focused) {
|
|
1603
|
+
await this.resumePausedMutations();
|
|
1604
|
+
this.#queryCache.onFocus();
|
|
1605
|
+
}
|
|
1606
|
+
});
|
|
1607
|
+
this.#unsubscribeOnline = onlineManager.subscribe(async (online) => {
|
|
1608
|
+
if (online) {
|
|
1609
|
+
await this.resumePausedMutations();
|
|
1610
|
+
this.#queryCache.onOnline();
|
|
1611
|
+
}
|
|
1612
|
+
});
|
|
1613
|
+
}
|
|
1614
|
+
/**
|
|
1615
|
+
* The inverse of {@link QueryClient#mount} — called by a framework adapter's
|
|
1616
|
+
* `QueryClientProvider`-equivalent when it unmounts. Only tears down the focus/online
|
|
1617
|
+
* listeners once the mount count returns to `0`.
|
|
1618
|
+
*/
|
|
1619
|
+
unmount() {
|
|
1620
|
+
this.#mountCount--;
|
|
1621
|
+
if (this.#mountCount !== 0) return;
|
|
1622
|
+
this.#unsubscribeFocus?.();
|
|
1623
|
+
this.#unsubscribeFocus = void 0;
|
|
1624
|
+
this.#unsubscribeOnline?.();
|
|
1625
|
+
this.#unsubscribeOnline = void 0;
|
|
1626
|
+
}
|
|
1627
|
+
/**
|
|
1628
|
+
* Returns the number of queries in the cache that are currently fetching, optionally
|
|
1629
|
+
* matching a set of filters. This includes background-fetching, loading new pages, and
|
|
1630
|
+
* loading more infinite query results.
|
|
1631
|
+
* @param filters - Narrows down which fetching queries are counted. Without filters, every
|
|
1632
|
+
* fetching query is counted.
|
|
1633
|
+
* @returns The number of matching queries whose `fetchStatus` is `'fetching'`.
|
|
1634
|
+
* @example
|
|
1635
|
+
* ```ts
|
|
1636
|
+
* if (queryClient.isFetching()) {
|
|
1637
|
+
* console.log('At least one query is fetching!')
|
|
1638
|
+
* }
|
|
1639
|
+
* ```
|
|
1640
|
+
*/
|
|
1641
|
+
isFetching(filters) {
|
|
1642
|
+
return this.#queryCache.findAll({
|
|
1643
|
+
...filters,
|
|
1644
|
+
fetchStatus: "fetching"
|
|
1645
|
+
}).length;
|
|
1646
|
+
}
|
|
1647
|
+
/**
|
|
1648
|
+
* Returns the number of mutations in the cache that are currently pending, optionally
|
|
1649
|
+
* matching a set of filters.
|
|
1650
|
+
* @param filters - Narrows down which pending mutations are counted. Without filters, every
|
|
1651
|
+
* pending mutation is counted.
|
|
1652
|
+
* @returns The number of matching mutations whose `status` is `'pending'`.
|
|
1653
|
+
* @example
|
|
1654
|
+
* ```ts
|
|
1655
|
+
* if (queryClient.isMutating()) {
|
|
1656
|
+
* console.log('At least one mutation is pending!')
|
|
1657
|
+
* }
|
|
1658
|
+
* ```
|
|
1659
|
+
*/
|
|
1660
|
+
isMutating(filters) {
|
|
1661
|
+
return this.#mutationCache.findAll({
|
|
1662
|
+
...filters,
|
|
1663
|
+
status: "pending"
|
|
1664
|
+
}).length;
|
|
1665
|
+
}
|
|
1666
|
+
/**
|
|
1667
|
+
* Imperative (non-reactive) way to retrieve data for a QueryKey.
|
|
1668
|
+
* Should only be used in callbacks or functions where reading the latest data is necessary, e.g. for optimistic updates.
|
|
1669
|
+
*
|
|
1670
|
+
* Hint: Do not use this function inside a component, because it won't receive updates.
|
|
1671
|
+
* Use `useQuery` to create a `QueryObserver` that subscribes to changes.
|
|
1672
|
+
* @param queryKey - The query key of the query to read.
|
|
1673
|
+
* @returns The cached data for the query, or `undefined` if no query with this key has been observed yet.
|
|
1674
|
+
* @see {@link QueryClient#getQueriesData}
|
|
1675
|
+
*/
|
|
1676
|
+
getQueryData(queryKey) {
|
|
1677
|
+
const options = this.defaultQueryOptions({ queryKey });
|
|
1678
|
+
return this.#queryCache.get(options.queryHash)?.state.data;
|
|
1679
|
+
}
|
|
1680
|
+
/**
|
|
1681
|
+
* Returns the cached data of a query, or fetches it if there is none. With `revalidateIfStale`,
|
|
1682
|
+
* stale cached data is also refetched in the background.
|
|
1683
|
+
* @param options - The query options. If the query has no cached data yet, it is fetched with
|
|
1684
|
+
* these options.
|
|
1685
|
+
* @returns A promise that resolves to the cached data, or to the fetched data if nothing was
|
|
1686
|
+
* cached yet.
|
|
1687
|
+
* @deprecated Use queryClient.query({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.
|
|
1688
|
+
*/
|
|
1689
|
+
ensureQueryData(options) {
|
|
1690
|
+
const defaultedOptions = this.defaultQueryOptions(options);
|
|
1691
|
+
const query = this.#queryCache.build(this, defaultedOptions);
|
|
1692
|
+
const cachedData = query.state.data;
|
|
1693
|
+
if (cachedData === void 0) return this.fetchQuery(options);
|
|
1694
|
+
if (options.revalidateIfStale && query.isStaleByTime(resolveQueryValue(defaultedOptions.staleTime, query))) this.prefetchQuery(defaultedOptions);
|
|
1695
|
+
return Promise.resolve(cachedData);
|
|
1696
|
+
}
|
|
1697
|
+
/**
|
|
1698
|
+
* Imperative (non-reactive) way to retrieve the cached data of multiple queries at once.
|
|
1699
|
+
* Only queries matching the given filters are returned; if none match, an empty array is
|
|
1700
|
+
* returned.
|
|
1701
|
+
*
|
|
1702
|
+
* Because the matched queries can hold data of different shapes (e.g. a broad filter can match
|
|
1703
|
+
* queries with unrelated data types), the `TQueryFnData` generic defaults to `unknown` rather
|
|
1704
|
+
* than being inferred. Passing a more specific type is a convenience for call sites that know
|
|
1705
|
+
* every matched query holds the same shape — it is not checked against the actual cache
|
|
1706
|
+
* contents.
|
|
1707
|
+
* @param filters - The filters that select which queries to read.
|
|
1708
|
+
* @returns An array of query key and data pairs. The data is `undefined` for a query with no cached data.
|
|
1709
|
+
* @see {@link QueryClient#getQueryData}
|
|
1710
|
+
* @example
|
|
1711
|
+
* ```ts
|
|
1712
|
+
* const data = queryClient.getQueriesData({ queryKey: ['posts'] })
|
|
1713
|
+
* ```
|
|
1714
|
+
*/
|
|
1715
|
+
getQueriesData(filters) {
|
|
1716
|
+
return this.#queryCache.findAll(filters).map(({ queryKey, state }) => {
|
|
1717
|
+
return [queryKey, state.data];
|
|
1718
|
+
});
|
|
1719
|
+
}
|
|
1720
|
+
/**
|
|
1721
|
+
* Synchronous way to immediately update a query's cached data. If the updater (or the value
|
|
1722
|
+
* passed) resolves to `undefined`, the cache is left untouched and no query is created;
|
|
1723
|
+
* otherwise, if the query does not exist yet, it will be created. To update multiple queries
|
|
1724
|
+
* at once by partially matching query keys, use {@link QueryClient#setQueriesData} instead.
|
|
1725
|
+
*
|
|
1726
|
+
* Updates must be performed immutably: do not mutate `oldData`, or data previously retrieved
|
|
1727
|
+
* via {@link QueryClient#getQueryData}, in place.
|
|
1728
|
+
* @param queryKey - The query key to set data for.
|
|
1729
|
+
* @param updater - Either the new data, or a function that receives the current data (which
|
|
1730
|
+
* may be `undefined`) and returns the new data.
|
|
1731
|
+
* @param options - Set `updatedAt` to override the timestamp the written data is recorded with.
|
|
1732
|
+
* @returns The data that was written, or `undefined` if the updater returned `undefined` — in that case
|
|
1733
|
+
* the write is skipped and the cache is left unchanged.
|
|
1734
|
+
* @example
|
|
1735
|
+
* ```ts
|
|
1736
|
+
* queryClient.setQueryData(['posts'], newPosts)
|
|
1737
|
+
*
|
|
1738
|
+
* // Or, using an updater function that receives the current data:
|
|
1739
|
+
* queryClient.setQueryData(['posts'], (oldPosts) => [...oldPosts, newPost])
|
|
1740
|
+
* ```
|
|
1741
|
+
*/
|
|
1742
|
+
setQueryData(queryKey, updater, options) {
|
|
1743
|
+
const defaultedOptions = this.defaultQueryOptions({ queryKey });
|
|
1744
|
+
const prevData = this.#queryCache.get(defaultedOptions.queryHash)?.state.data;
|
|
1745
|
+
const data = functionalUpdate(updater, prevData);
|
|
1746
|
+
if (data === void 0) return;
|
|
1747
|
+
return this.#queryCache.build(this, defaultedOptions).setData(data, {
|
|
1748
|
+
...options,
|
|
1749
|
+
manual: true
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
/**
|
|
1753
|
+
* Synchronous way to immediately update the cached data of multiple queries at once, using
|
|
1754
|
+
* filters or partial query key matching. Only queries that already exist and match the given
|
|
1755
|
+
* filters are updated; no new cache entries are created. Internally this calls
|
|
1756
|
+
* {@link QueryClient#setQueryData} for each matching query.
|
|
1757
|
+
* @param filters - The filters that select which existing queries to update.
|
|
1758
|
+
* @param updater - Either the new data, or a function that receives each matched query's current
|
|
1759
|
+
* data (which may be `undefined`) and returns the new data.
|
|
1760
|
+
* @param options - Set `updatedAt` to override the timestamp the written data is recorded with.
|
|
1761
|
+
* @returns One `[queryKey, data]` tuple per matched query, in the same shape and with the same
|
|
1762
|
+
* `undefined` case as {@link QueryClient#setQueryData}.
|
|
1763
|
+
* @example
|
|
1764
|
+
* ```ts
|
|
1765
|
+
* queryClient.setQueriesData({ queryKey: ['posts'] }, (oldPosts) =>
|
|
1766
|
+
* oldPosts ? oldPosts.filter((post) => post.id !== deletedId) : oldPosts,
|
|
1767
|
+
* )
|
|
1768
|
+
* ```
|
|
1769
|
+
*/
|
|
1770
|
+
setQueriesData(filters, updater, options) {
|
|
1771
|
+
return notifyManager.batch(() => this.#queryCache.findAll(filters).map(({ queryKey }) => [queryKey, this.setQueryData(queryKey, updater, options)]));
|
|
1772
|
+
}
|
|
1773
|
+
/**
|
|
1774
|
+
* Imperative (non-reactive) way to retrieve an existing query's state. If the query does not
|
|
1775
|
+
* exist, `undefined` is returned.
|
|
1776
|
+
* @param queryKey - The query key of the query to read.
|
|
1777
|
+
* @returns The query's state, or `undefined` if no query with this key exists.
|
|
1778
|
+
* @example
|
|
1779
|
+
* ```ts
|
|
1780
|
+
* const state = queryClient.getQueryState(['posts'])
|
|
1781
|
+
* console.log(state?.dataUpdatedAt)
|
|
1782
|
+
* ```
|
|
1783
|
+
*/
|
|
1784
|
+
getQueryState(queryKey) {
|
|
1785
|
+
const options = this.defaultQueryOptions({ queryKey });
|
|
1786
|
+
return this.#queryCache.get(options.queryHash)?.state;
|
|
1787
|
+
}
|
|
1788
|
+
/**
|
|
1789
|
+
* Removes queries from the cache that match the given filters. Unlike
|
|
1790
|
+
* {@link QueryClient#invalidateQueries} or {@link QueryClient#refetchQueries}, this removes
|
|
1791
|
+
* matching queries from the cache instead of refetching them. Without filters, every query in
|
|
1792
|
+
* the cache is removed.
|
|
1793
|
+
* @param filters - The filters that select which queries to remove. Without filters, every query
|
|
1794
|
+
* is removed.
|
|
1795
|
+
* @example
|
|
1796
|
+
* ```ts
|
|
1797
|
+
* queryClient.removeQueries({ queryKey: ['posts'], exact: true })
|
|
1798
|
+
* ```
|
|
1799
|
+
*/
|
|
1800
|
+
removeQueries(filters) {
|
|
1801
|
+
const queryCache = this.#queryCache;
|
|
1802
|
+
notifyManager.batch(() => {
|
|
1803
|
+
queryCache.findAll(filters).forEach((query) => {
|
|
1804
|
+
queryCache.remove(query);
|
|
1805
|
+
});
|
|
1806
|
+
});
|
|
1807
|
+
}
|
|
1808
|
+
/**
|
|
1809
|
+
* Resets queries matching the given filters back to their initial state (e.g. any
|
|
1810
|
+
* `initialData`), notifying subscribers rather than removing them. Active queries among the
|
|
1811
|
+
* matched set are then refetched, and the returned promise resolves once that refetch settles.
|
|
1812
|
+
* @param filters - The filters that select which queries to reset. Without filters, every query
|
|
1813
|
+
* is reset.
|
|
1814
|
+
* @param options - Passed to the refetch of the active matched queries, e.g. `cancelRefetch` and
|
|
1815
|
+
* `throwOnError`.
|
|
1816
|
+
* @returns A promise that resolves once the refetch of the active matched queries settles.
|
|
1817
|
+
* @example
|
|
1818
|
+
* ```ts
|
|
1819
|
+
* await queryClient.resetQueries({ queryKey: ['posts'], exact: true })
|
|
1820
|
+
* ```
|
|
1821
|
+
*/
|
|
1822
|
+
resetQueries(filters, options) {
|
|
1823
|
+
const queryCache = this.#queryCache;
|
|
1824
|
+
return notifyManager.batch(() => {
|
|
1825
|
+
const matched = queryCache.findAll(filters);
|
|
1826
|
+
const queriesToRefetch = new Set(matched);
|
|
1827
|
+
matched.forEach((query) => {
|
|
1828
|
+
query.reset();
|
|
1829
|
+
});
|
|
1830
|
+
return this.refetchQueries({
|
|
1831
|
+
type: "active",
|
|
1832
|
+
predicate: (query) => queriesToRefetch.has(query)
|
|
1833
|
+
}, options);
|
|
1834
|
+
});
|
|
1835
|
+
}
|
|
1836
|
+
/**
|
|
1837
|
+
* Cancels outgoing fetches for queries matching the given filters. Most useful when performing
|
|
1838
|
+
* optimistic updates, since any outgoing refetch that resolves afterwards would otherwise
|
|
1839
|
+
* overwrite the optimistic update. By default (`revert: true`), a cancelled query's data is
|
|
1840
|
+
* reverted to its state before the outgoing fetch started.
|
|
1841
|
+
*
|
|
1842
|
+
* The returned promise never rejects, even if individual cancellations fail.
|
|
1843
|
+
* @param filters - The filters that select which queries to cancel. Without filters, every query
|
|
1844
|
+
* is cancelled.
|
|
1845
|
+
* @param cancelOptions - Passed to each matched query's cancellation. `revert` defaults to
|
|
1846
|
+
* `true`.
|
|
1847
|
+
* @returns A promise that resolves once every cancellation has settled.
|
|
1848
|
+
* @example
|
|
1849
|
+
* ```ts
|
|
1850
|
+
* await queryClient.cancelQueries({ queryKey: ['posts'], exact: true })
|
|
1851
|
+
* ```
|
|
1852
|
+
*/
|
|
1853
|
+
cancelQueries(filters, cancelOptions = {}) {
|
|
1854
|
+
const defaultedCancelOptions = {
|
|
1855
|
+
revert: true,
|
|
1856
|
+
...cancelOptions
|
|
1857
|
+
};
|
|
1858
|
+
const promises = notifyManager.batch(() => this.#queryCache.findAll(filters).map((query) => query.cancel(defaultedCancelOptions)));
|
|
1859
|
+
return Promise.all(promises).then(noop).catch(noop);
|
|
1860
|
+
}
|
|
1861
|
+
/**
|
|
1862
|
+
* Marks queries matching the given filters as invalidated. Unlike
|
|
1863
|
+
* {@link QueryClient#removeQueries}, invalidated queries stay in the cache.
|
|
1864
|
+
*
|
|
1865
|
+
* Unless `filters.refetchType` is `'none'`, matching queries are then refetched via
|
|
1866
|
+
* {@link QueryClient#refetchQueries}, using `filters.refetchType` if set, otherwise
|
|
1867
|
+
* `filters.type`, otherwise `'active'`.
|
|
1868
|
+
* @param filters - The filters that select which queries to invalidate, plus `refetchType` to
|
|
1869
|
+
* control which of them to refetch afterwards. Without filters, every query is invalidated.
|
|
1870
|
+
* @param options - Passed to {@link QueryClient#refetchQueries}, e.g. `cancelRefetch` and
|
|
1871
|
+
* `throwOnError`.
|
|
1872
|
+
* @returns A promise that resolves once the refetch settles, or immediately if `refetchType` is
|
|
1873
|
+
* `'none'`.
|
|
1874
|
+
* @example
|
|
1875
|
+
* ```ts
|
|
1876
|
+
* await queryClient.invalidateQueries({ queryKey: ['posts'], refetchType: 'active' })
|
|
1877
|
+
* ```
|
|
1878
|
+
*/
|
|
1879
|
+
invalidateQueries(filters, options = {}) {
|
|
1880
|
+
return notifyManager.batch(() => {
|
|
1881
|
+
this.#queryCache.findAll(filters).forEach((query) => {
|
|
1882
|
+
query.invalidate();
|
|
1883
|
+
});
|
|
1884
|
+
if (filters?.refetchType === "none") return Promise.resolve();
|
|
1885
|
+
return this.refetchQueries({
|
|
1886
|
+
...filters,
|
|
1887
|
+
type: filters?.refetchType ?? filters?.type ?? "active"
|
|
1888
|
+
}, options);
|
|
1889
|
+
});
|
|
1890
|
+
}
|
|
1891
|
+
/**
|
|
1892
|
+
* Refetches queries matching the given filters, regardless of whether they are stale. Without
|
|
1893
|
+
* filters, every query in the cache is refetched. Queries that are disabled, or static (only
|
|
1894
|
+
* have observers with a static `staleTime`), are never refetched.
|
|
1895
|
+
*
|
|
1896
|
+
* By default (`cancelRefetch: true`), a currently running fetch is cancelled before the new
|
|
1897
|
+
* one starts. The returned promise does not reject on individual query failures unless
|
|
1898
|
+
* `throwOnError` is `true`.
|
|
1899
|
+
*
|
|
1900
|
+
* Initially paused fetches do not delay the returned promise. Their later errors are handled
|
|
1901
|
+
* even when `throwOnError` is `true`.
|
|
1902
|
+
* @param filters - The filters that select which queries to refetch. Without filters, every query
|
|
1903
|
+
* in the cache is included.
|
|
1904
|
+
* @param options - Set `cancelRefetch` to `false` to keep a running fetch instead of cancelling
|
|
1905
|
+
* it, and `throwOnError` to `true` to reject when a refetch that was not initially paused fails.
|
|
1906
|
+
* @returns A promise that resolves once all matching refetches that were not initially paused
|
|
1907
|
+
* have settled.
|
|
1908
|
+
* @example
|
|
1909
|
+
* ```ts
|
|
1910
|
+
* // refetch all active queries partially matching a query key:
|
|
1911
|
+
* await queryClient.refetchQueries({ queryKey: ['posts'], type: 'active' })
|
|
1912
|
+
* ```
|
|
1913
|
+
*/
|
|
1914
|
+
refetchQueries(filters, options = {}) {
|
|
1915
|
+
const fetchOptions = {
|
|
1916
|
+
...options,
|
|
1917
|
+
cancelRefetch: options.cancelRefetch ?? true
|
|
1918
|
+
};
|
|
1919
|
+
const promises = notifyManager.batch(() => this.#queryCache.findAll(filters).filter((query) => !query.isDisabled() && !query.isStatic()).map((query) => {
|
|
1920
|
+
let promise = query.fetch(void 0, fetchOptions);
|
|
1921
|
+
const isPaused = query.state.fetchStatus === "paused";
|
|
1922
|
+
if (!fetchOptions.throwOnError || isPaused) promise = promise.catch(noop);
|
|
1923
|
+
return isPaused ? Promise.resolve() : promise;
|
|
1924
|
+
}));
|
|
1925
|
+
return Promise.all(promises).then(noop);
|
|
1926
|
+
}
|
|
1927
|
+
/**
|
|
1928
|
+
* Asynchronous method to fetch and cache a query, resolving with the data or throwing with
|
|
1929
|
+
* the error.
|
|
1930
|
+
*
|
|
1931
|
+
* If the query already exists in the cache and its data is not stale (per the given
|
|
1932
|
+
* `staleTime`), the cached data is returned without fetching. Otherwise, the query is fetched
|
|
1933
|
+
* and the promise resolves once the fetch settles. If a `select` function is provided, it is
|
|
1934
|
+
* applied to the data in both cases (cached or freshly fetched) before it is returned.
|
|
1935
|
+
*
|
|
1936
|
+
* Unlike a reactive observer, retries are disabled by default here (`retry: false`) unless
|
|
1937
|
+
* explicitly configured, since there is no component to catch a thrown error and retry through
|
|
1938
|
+
* re-render.
|
|
1939
|
+
*
|
|
1940
|
+
* The accepted options are `QueryObserverOptions` minus the fields that only make sense for a
|
|
1941
|
+
* reactive observer — `enabled`, `refetchInterval`, `refetchIntervalInBackground`,
|
|
1942
|
+
* `refetchOnWindowFocus`, `refetchOnReconnect`, `refetchOnMount`, `retryOnMount`,
|
|
1943
|
+
* `notifyOnChangeProps`, `throwOnError`, `suspense`, and `placeholderData` are not part of this
|
|
1944
|
+
* method's options.
|
|
1945
|
+
*
|
|
1946
|
+
* This method replaces the deprecated `fetchQuery`, and — combined with
|
|
1947
|
+
* `{ staleTime: 'static' }` — the deprecated `ensureQueryData`.
|
|
1948
|
+
* @param options - The query options, including the `queryKey` and the `queryFn` used if the
|
|
1949
|
+
* query needs to fetch.
|
|
1950
|
+
* @returns A promise that resolves to the data, or to the result of `select` if provided. It
|
|
1951
|
+
* rejects with the error from the fetch or from `select`.
|
|
1952
|
+
* @example
|
|
1953
|
+
* ```ts
|
|
1954
|
+
* try {
|
|
1955
|
+
* const data = await queryClient.query({ queryKey, queryFn, staleTime: 10000 })
|
|
1956
|
+
* } catch (error) {
|
|
1957
|
+
* console.log(error)
|
|
1958
|
+
* }
|
|
1959
|
+
* ```
|
|
1960
|
+
*/
|
|
1961
|
+
async query(options) {
|
|
1962
|
+
const defaultedOptions = this.defaultQueryOptions(options);
|
|
1963
|
+
if (defaultedOptions.retry === void 0) defaultedOptions.retry = false;
|
|
1964
|
+
const query = this.#queryCache.build(this, defaultedOptions);
|
|
1965
|
+
const queryData = query.isStaleByTime(resolveQueryValue(defaultedOptions.staleTime, query)) ? await query.fetch(defaultedOptions) : query.state.data;
|
|
1966
|
+
const select = defaultedOptions.select;
|
|
1967
|
+
if (select) return select(queryData);
|
|
1968
|
+
return queryData;
|
|
1969
|
+
}
|
|
1970
|
+
/**
|
|
1971
|
+
* Fetches and caches a query, or returns its cached data if it isn't stale. Unlike in observers,
|
|
1972
|
+
* the fetch isn't retried unless `retry` is set.
|
|
1973
|
+
* @param options - The query options, including the `queryKey` and the `queryFn` used if the
|
|
1974
|
+
* query needs to fetch.
|
|
1975
|
+
* @returns A promise that resolves to the cached or fetched data, or rejects with the fetch
|
|
1976
|
+
* error.
|
|
1977
|
+
* @deprecated Use queryClient.query(options) instead. This method will be removed in the next major version.
|
|
1978
|
+
*/
|
|
1979
|
+
fetchQuery(options) {
|
|
1980
|
+
const defaultedOptions = this.defaultQueryOptions(options);
|
|
1981
|
+
if (defaultedOptions.retry === void 0) defaultedOptions.retry = false;
|
|
1982
|
+
const query = this.#queryCache.build(this, defaultedOptions);
|
|
1983
|
+
return query.isStaleByTime(resolveQueryValue(defaultedOptions.staleTime, query)) ? query.fetch(defaultedOptions) : Promise.resolve(query.state.data);
|
|
1984
|
+
}
|
|
1985
|
+
/**
|
|
1986
|
+
* Fetches and caches a query like {@link QueryClient#fetchQuery}, but ignores the result and any
|
|
1987
|
+
* error.
|
|
1988
|
+
* @param options - The query options, including the `queryKey` and the `queryFn` used if the
|
|
1989
|
+
* query needs to fetch.
|
|
1990
|
+
* @returns A promise that resolves once the fetch settles. It never rejects.
|
|
1991
|
+
* @deprecated Use queryClient.query(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.
|
|
1992
|
+
*/
|
|
1993
|
+
prefetchQuery(options) {
|
|
1994
|
+
return this.fetchQuery(options).then(noop).catch(noop);
|
|
1995
|
+
}
|
|
1996
|
+
/**
|
|
1997
|
+
* Asynchronous method to fetch and cache an infinite query, resolving with an
|
|
1998
|
+
* {@link InfiniteData} object or throwing with the error.
|
|
1999
|
+
*
|
|
2000
|
+
* Behaves like {@link QueryClient#query}, accepting the same options (minus
|
|
2001
|
+
* `initialPageParam`), plus the required `initialPageParam`, and an optional `pages` /
|
|
2002
|
+
* `getNextPageParam` pair used to refetch a fixed number of pages from the start.
|
|
2003
|
+
*
|
|
2004
|
+
* This method replaces the deprecated `fetchInfiniteQuery`, and — combined with
|
|
2005
|
+
* `{ staleTime: 'static' }` — the deprecated `ensureInfiniteQueryData`.
|
|
2006
|
+
* @param options - The infinite query options, including the `queryKey`, the `queryFn`, and the
|
|
2007
|
+
* `initialPageParam`.
|
|
2008
|
+
* @returns A promise that resolves to the {@link InfiniteData}, or to the result of `select` if
|
|
2009
|
+
* provided. It rejects with the error from the fetch or from `select`.
|
|
2010
|
+
* @example
|
|
2011
|
+
* ```ts
|
|
2012
|
+
* try {
|
|
2013
|
+
* const data = await queryClient.infiniteQuery({ queryKey, queryFn, initialPageParam: 0 })
|
|
2014
|
+
* console.log(data.pages)
|
|
2015
|
+
* } catch (error) {
|
|
2016
|
+
* console.log(error)
|
|
2017
|
+
* }
|
|
2018
|
+
* ```
|
|
2019
|
+
*/
|
|
2020
|
+
infiniteQuery(options) {
|
|
2021
|
+
options._type = "infinite";
|
|
2022
|
+
return this.query(options);
|
|
2023
|
+
}
|
|
2024
|
+
/**
|
|
2025
|
+
* Fetches and caches an infinite query, or returns its cached data if it isn't stale.
|
|
2026
|
+
* @param options - The infinite query options, including the `queryKey`, the `queryFn`, and the
|
|
2027
|
+
* `initialPageParam`.
|
|
2028
|
+
* @returns A promise that resolves to the cached or fetched {@link InfiniteData}, or rejects with
|
|
2029
|
+
* the fetch error.
|
|
2030
|
+
* @deprecated Use queryClient.infiniteQuery(options) instead. This method will be removed in the next major version.
|
|
2031
|
+
*/
|
|
2032
|
+
fetchInfiniteQuery(options) {
|
|
2033
|
+
options._type = "infinite";
|
|
2034
|
+
return this.fetchQuery(options);
|
|
2035
|
+
}
|
|
2036
|
+
/**
|
|
2037
|
+
* Fetches and caches an infinite query like {@link QueryClient#fetchInfiniteQuery}, but ignores
|
|
2038
|
+
* the result and any error.
|
|
2039
|
+
* @param options - The infinite query options, including the `queryKey`, the `queryFn`, and the
|
|
2040
|
+
* `initialPageParam`.
|
|
2041
|
+
* @returns A promise that resolves once the fetch settles. It never rejects.
|
|
2042
|
+
* @deprecated Use queryClient.infiniteQuery(options) instead. You can swallow errors with `.catch(noop)`. This method will be removed in the next major version.
|
|
2043
|
+
*/
|
|
2044
|
+
prefetchInfiniteQuery(options) {
|
|
2045
|
+
return this.fetchInfiniteQuery(options).then(noop).catch(noop);
|
|
2046
|
+
}
|
|
2047
|
+
/**
|
|
2048
|
+
* Returns the cached data of an infinite query, or fetches it if there is none. With
|
|
2049
|
+
* `revalidateIfStale`, stale cached data is also refetched in the background.
|
|
2050
|
+
* @param options - The infinite query options. If the query has no cached data yet, it is fetched
|
|
2051
|
+
* with these options.
|
|
2052
|
+
* @returns A promise that resolves to the cached {@link InfiniteData}, or to the fetched data if
|
|
2053
|
+
* nothing was cached yet.
|
|
2054
|
+
* @deprecated Use queryClient.infiniteQuery({ ...options, staleTime: 'static' }) instead. This method will be removed in the next major version.
|
|
2055
|
+
*/
|
|
2056
|
+
ensureInfiniteQueryData(options) {
|
|
2057
|
+
options._type = "infinite";
|
|
2058
|
+
return this.ensureQueryData(options);
|
|
2059
|
+
}
|
|
2060
|
+
/**
|
|
2061
|
+
* Resumes mutations that were paused because there was no network connection. Does nothing
|
|
2062
|
+
* (resolving immediately) if the client is currently offline.
|
|
2063
|
+
* @returns A promise that resolves once the resumed mutations have settled.
|
|
2064
|
+
* @example
|
|
2065
|
+
* ```ts
|
|
2066
|
+
* import { QueryClient } from '@tanstack/query-core'
|
|
2067
|
+
*
|
|
2068
|
+
* const queryClient = new QueryClient()
|
|
2069
|
+
* await queryClient.resumePausedMutations()
|
|
2070
|
+
* ```
|
|
2071
|
+
*/
|
|
2072
|
+
resumePausedMutations() {
|
|
2073
|
+
if (onlineManager.isOnline()) return this.#mutationCache.resumePausedMutations();
|
|
2074
|
+
return Promise.resolve();
|
|
2075
|
+
}
|
|
2076
|
+
/**
|
|
2077
|
+
* Returns the query cache this client is connected to.
|
|
2078
|
+
* @returns The {@link QueryCache} instance.
|
|
2079
|
+
* @example
|
|
2080
|
+
* ```ts
|
|
2081
|
+
* import { QueryClient } from '@tanstack/query-core'
|
|
2082
|
+
*
|
|
2083
|
+
* const queryClient = new QueryClient()
|
|
2084
|
+
* const queryCache = queryClient.getQueryCache()
|
|
2085
|
+
* const queries = queryCache.findAll({ queryKey: ['posts'] })
|
|
2086
|
+
* ```
|
|
2087
|
+
*/
|
|
2088
|
+
getQueryCache() {
|
|
2089
|
+
return this.#queryCache;
|
|
2090
|
+
}
|
|
2091
|
+
/**
|
|
2092
|
+
* Returns the mutation cache this client is connected to.
|
|
2093
|
+
* @returns The {@link MutationCache} instance.
|
|
2094
|
+
* @example
|
|
2095
|
+
* ```ts
|
|
2096
|
+
* import { QueryClient } from '@tanstack/query-core'
|
|
2097
|
+
*
|
|
2098
|
+
* const queryClient = new QueryClient()
|
|
2099
|
+
* const mutationCache = queryClient.getMutationCache()
|
|
2100
|
+
* const mutations = mutationCache.findAll({ status: 'pending' })
|
|
2101
|
+
* ```
|
|
2102
|
+
*/
|
|
2103
|
+
getMutationCache() {
|
|
2104
|
+
return this.#mutationCache;
|
|
2105
|
+
}
|
|
2106
|
+
/**
|
|
2107
|
+
* Returns the default options that were set when creating the client, or via
|
|
2108
|
+
* {@link QueryClient#setDefaultOptions}.
|
|
2109
|
+
* @returns The client's current default options.
|
|
2110
|
+
* @example
|
|
2111
|
+
* ```ts
|
|
2112
|
+
* import { QueryClient } from '@tanstack/query-core'
|
|
2113
|
+
*
|
|
2114
|
+
* const queryClient = new QueryClient()
|
|
2115
|
+
* const defaultOptions = queryClient.getDefaultOptions()
|
|
2116
|
+
* ```
|
|
2117
|
+
*/
|
|
2118
|
+
getDefaultOptions() {
|
|
2119
|
+
return this.#defaultOptions;
|
|
2120
|
+
}
|
|
2121
|
+
/**
|
|
2122
|
+
* Dynamically sets the default options for this client, overwriting any previously defined
|
|
2123
|
+
* default options.
|
|
2124
|
+
* @param options - The new default options for queries and mutations.
|
|
2125
|
+
* @see {@link QueryClient#getDefaultOptions}
|
|
2126
|
+
* @example
|
|
2127
|
+
* ```ts
|
|
2128
|
+
* import { QueryClient } from '@tanstack/query-core'
|
|
2129
|
+
*
|
|
2130
|
+
* const queryClient = new QueryClient()
|
|
2131
|
+
* queryClient.setDefaultOptions({
|
|
2132
|
+
* queries: {
|
|
2133
|
+
* staleTime: Infinity,
|
|
2134
|
+
* },
|
|
2135
|
+
* })
|
|
2136
|
+
* ```
|
|
2137
|
+
*/
|
|
2138
|
+
setDefaultOptions(options) {
|
|
2139
|
+
this.#defaultOptions = options;
|
|
2140
|
+
}
|
|
2141
|
+
/**
|
|
2142
|
+
* Sets default options for queries whose query key partially matches the given `queryKey`.
|
|
2143
|
+
*
|
|
2144
|
+
* If several registered query defaults match a given query key, they are merged together in
|
|
2145
|
+
* registration order by {@link QueryClient#getQueryDefaults}, so register defaults from the
|
|
2146
|
+
* most generic key to the least generic one — more specific defaults should be registered
|
|
2147
|
+
* after more generic ones so they take precedence.
|
|
2148
|
+
* @param queryKey - The query key that query keys are partially matched against.
|
|
2149
|
+
* @param options - The default options applied to matching queries.
|
|
2150
|
+
* @example
|
|
2151
|
+
* ```ts
|
|
2152
|
+
* queryClient.setQueryDefaults(['posts'], { queryFn: fetchPosts })
|
|
2153
|
+
*
|
|
2154
|
+
* await queryClient.query({ queryKey: ['posts'] })
|
|
2155
|
+
* ```
|
|
2156
|
+
*/
|
|
2157
|
+
setQueryDefaults(queryKey, options) {
|
|
2158
|
+
this.#queryDefaults.set(hashKey(queryKey), {
|
|
2159
|
+
queryKey,
|
|
2160
|
+
defaultOptions: options
|
|
2161
|
+
});
|
|
2162
|
+
}
|
|
2163
|
+
/**
|
|
2164
|
+
* Returns the default options registered for queries whose query key partially matches the
|
|
2165
|
+
* given `queryKey`, via {@link QueryClient#setQueryDefaults}. If multiple registered defaults
|
|
2166
|
+
* match, they are merged together in registration order.
|
|
2167
|
+
* @param queryKey - The query key to look up registered defaults for.
|
|
2168
|
+
* @returns The merged default options of every registration that matches, or an empty object if
|
|
2169
|
+
* none match.
|
|
2170
|
+
* @example
|
|
2171
|
+
* ```ts
|
|
2172
|
+
* const defaultOptions = queryClient.getQueryDefaults(['posts'])
|
|
2173
|
+
* ```
|
|
2174
|
+
*/
|
|
2175
|
+
getQueryDefaults(queryKey) {
|
|
2176
|
+
const defaults = [...this.#queryDefaults.values()];
|
|
2177
|
+
const result = {};
|
|
2178
|
+
defaults.forEach((queryDefault) => {
|
|
2179
|
+
if (partialMatchKey(queryKey, queryDefault.queryKey)) Object.assign(result, queryDefault.defaultOptions);
|
|
2180
|
+
});
|
|
2181
|
+
return result;
|
|
2182
|
+
}
|
|
2183
|
+
/**
|
|
2184
|
+
* Sets default options for mutations whose mutation key partially matches the given
|
|
2185
|
+
* `mutationKey`. As with {@link QueryClient#setQueryDefaults}, the order of registration
|
|
2186
|
+
* matters when several registered defaults match the same mutation key.
|
|
2187
|
+
* @param mutationKey - The mutation key that mutation keys are partially matched against.
|
|
2188
|
+
* @param options - The default options applied to matching mutations.
|
|
2189
|
+
* @see {@link QueryClient#getMutationDefaults}
|
|
2190
|
+
* @example
|
|
2191
|
+
* ```ts
|
|
2192
|
+
* queryClient.setMutationDefaults(['addPost'], { mutationFn: addPost })
|
|
2193
|
+
* ```
|
|
2194
|
+
*/
|
|
2195
|
+
setMutationDefaults(mutationKey, options) {
|
|
2196
|
+
this.#mutationDefaults.set(hashKey(mutationKey), {
|
|
2197
|
+
mutationKey,
|
|
2198
|
+
defaultOptions: options
|
|
2199
|
+
});
|
|
2200
|
+
}
|
|
2201
|
+
/**
|
|
2202
|
+
* Returns the default options registered for mutations whose mutation key partially matches
|
|
2203
|
+
* the given `mutationKey`, via {@link QueryClient#setMutationDefaults}. If multiple registered
|
|
2204
|
+
* defaults match, they are merged together in registration order.
|
|
2205
|
+
* @param mutationKey - The mutation key to look up registered defaults for.
|
|
2206
|
+
* @returns The merged default options of every registration that matches, or an empty object if
|
|
2207
|
+
* none match.
|
|
2208
|
+
* @example
|
|
2209
|
+
* ```ts
|
|
2210
|
+
* const defaultOptions = queryClient.getMutationDefaults(['addPost'])
|
|
2211
|
+
* ```
|
|
2212
|
+
*/
|
|
2213
|
+
getMutationDefaults(mutationKey) {
|
|
2214
|
+
const defaults = [...this.#mutationDefaults.values()];
|
|
2215
|
+
const result = {};
|
|
2216
|
+
defaults.forEach((queryDefault) => {
|
|
2217
|
+
if (partialMatchKey(mutationKey, queryDefault.mutationKey)) Object.assign(result, queryDefault.defaultOptions);
|
|
2218
|
+
});
|
|
2219
|
+
return result;
|
|
2220
|
+
}
|
|
2221
|
+
/**
|
|
2222
|
+
* Called by framework adapters (e.g. inside `useQuery`) to resolve the options passed by the
|
|
2223
|
+
* caller into their final, defaulted form: merging the client's own `defaultOptions.queries`,
|
|
2224
|
+
* then `queryClient.setQueryDefaults` for the given `queryKey`, then the caller's options on
|
|
2225
|
+
* top. A no-op if the options are already defaulted (`_defaulted: true`).
|
|
2226
|
+
* @param options - The query options passed by the caller.
|
|
2227
|
+
* @returns The defaulted options, with `queryHash` and dependent defaults (e.g.
|
|
2228
|
+
* `refetchOnReconnect`) filled in.
|
|
2229
|
+
*/
|
|
2230
|
+
defaultQueryOptions(options) {
|
|
2231
|
+
if (options._defaulted) return options;
|
|
2232
|
+
const defaultedOptions = {
|
|
2233
|
+
...this.#defaultOptions.queries,
|
|
2234
|
+
...this.getQueryDefaults(options.queryKey),
|
|
2235
|
+
...options,
|
|
2236
|
+
_defaulted: true
|
|
2237
|
+
};
|
|
2238
|
+
if (!defaultedOptions.queryHash) defaultedOptions.queryHash = hashQueryKeyByOptions(defaultedOptions.queryKey, defaultedOptions);
|
|
2239
|
+
if (defaultedOptions.refetchOnReconnect === void 0) defaultedOptions.refetchOnReconnect = defaultedOptions.networkMode !== "always";
|
|
2240
|
+
if (defaultedOptions.throwOnError === void 0) defaultedOptions.throwOnError = !!defaultedOptions.suspense;
|
|
2241
|
+
if (!defaultedOptions.networkMode && defaultedOptions.persister) defaultedOptions.networkMode = "offlineFirst";
|
|
2242
|
+
if (defaultedOptions.queryFn === skipToken) defaultedOptions.enabled = false;
|
|
2243
|
+
return defaultedOptions;
|
|
2244
|
+
}
|
|
2245
|
+
/**
|
|
2246
|
+
* The mutation counterpart of {@link QueryClient#defaultQueryOptions}. Called by framework
|
|
2247
|
+
* adapters (e.g. inside `useMutation`) to merge the client's `defaultOptions.mutations`, then
|
|
2248
|
+
* `queryClient.setMutationDefaults` for the given `mutationKey`, then the caller's options on
|
|
2249
|
+
* top. A no-op if the options are already defaulted (`_defaulted: true`).
|
|
2250
|
+
* @param options - The mutation options passed by the caller.
|
|
2251
|
+
* @returns The defaulted options.
|
|
2252
|
+
*/
|
|
2253
|
+
defaultMutationOptions(options) {
|
|
2254
|
+
if (options?._defaulted) return options;
|
|
2255
|
+
return {
|
|
2256
|
+
...this.#defaultOptions.mutations,
|
|
2257
|
+
...options?.mutationKey && this.getMutationDefaults(options.mutationKey),
|
|
2258
|
+
...options,
|
|
2259
|
+
_defaulted: true
|
|
2260
|
+
};
|
|
2261
|
+
}
|
|
2262
|
+
/**
|
|
2263
|
+
* Clears both the query cache and the mutation cache this client is connected to.
|
|
2264
|
+
* @example
|
|
2265
|
+
* ```ts
|
|
2266
|
+
* import { QueryClient } from '@tanstack/query-core'
|
|
2267
|
+
*
|
|
2268
|
+
* const queryClient = new QueryClient()
|
|
2269
|
+
* queryClient.clear()
|
|
2270
|
+
* ```
|
|
2271
|
+
*/
|
|
2272
|
+
clear() {
|
|
2273
|
+
this.#queryCache.clear();
|
|
2274
|
+
this.#mutationCache.clear();
|
|
2275
|
+
}
|
|
2276
|
+
};
|
|
2277
|
+
// ../../node_modules/.bun/@tanstack+react-query@5.105.3+cef22a3c7e8b4cef/node_modules/@tanstack/react-query/build/modern/useMutation.js
|
|
2278
|
+
/**
|
|
2279
|
+
* Unlike queries, mutations are typically used to create/update/delete data or perform server side-effects.
|
|
2280
|
+
* `useMutation` is the hook for that.
|
|
2281
|
+
* @param options - The {@link UseMutationOptions} to use — everything you can pass to `useMutation`.
|
|
2282
|
+
* @param queryClient - Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
|
|
2283
|
+
* be used.
|
|
2284
|
+
* @returns `mutate`/`mutateAsync` also accept per-call `onSuccess`/`onError`/`onSettled` callbacks as a second
|
|
2285
|
+
* argument, useful for triggering call-site side effects (e.g. navigation) without coupling them to the shared
|
|
2286
|
+
* mutation definition. Hook-level callbacks (passed to `options`) fire for every mutation; per-call callbacks
|
|
2287
|
+
* fire only for the latest call you've made, and only while the component is still mounted — unmounting before
|
|
2288
|
+
* the mutation settles removes the subscription and prevents them from firing.
|
|
2289
|
+
* @throws {Error} The mutation error, when `throwOnError` is `true` or returns `true` for it, so that it is
|
|
2290
|
+
* thrown to the nearest error boundary.
|
|
2291
|
+
* @see {@link mutationOptions} to share these options across multiple `useMutation` call sites, or to look
|
|
2292
|
+
* the mutation up elsewhere via its `mutationKey` (e.g. with `useMutationState`).
|
|
2293
|
+
* @example
|
|
2294
|
+
* ```tsx
|
|
2295
|
+
* import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
2296
|
+
*
|
|
2297
|
+
* function AddTodo() {
|
|
2298
|
+
* const queryClient = useQueryClient()
|
|
2299
|
+
*
|
|
2300
|
+
* const addMutation = useMutation({
|
|
2301
|
+
* mutationFn: addTodo,
|
|
2302
|
+
* onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),
|
|
2303
|
+
* })
|
|
2304
|
+
*
|
|
2305
|
+
* return (
|
|
2306
|
+
* <button
|
|
2307
|
+
* onClick={() =>
|
|
2308
|
+
* addMutation.mutate('Item', {
|
|
2309
|
+
* onError: (error) => console.error('Failed to add item:', error),
|
|
2310
|
+
* })
|
|
2311
|
+
* }
|
|
2312
|
+
* >
|
|
2313
|
+
* Add
|
|
2314
|
+
* </button>
|
|
2315
|
+
* )
|
|
2316
|
+
* }
|
|
2317
|
+
* ```
|
|
2318
|
+
* @example
|
|
2319
|
+
* Rendering the mutation's own state, rather than just firing it off:
|
|
2320
|
+
* ```tsx
|
|
2321
|
+
* import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
2322
|
+
*
|
|
2323
|
+
* function AddTodo() {
|
|
2324
|
+
* const queryClient = useQueryClient()
|
|
2325
|
+
*
|
|
2326
|
+
* const addMutation = useMutation({
|
|
2327
|
+
* mutationFn: addTodo,
|
|
2328
|
+
* onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),
|
|
2329
|
+
* })
|
|
2330
|
+
*
|
|
2331
|
+
* return (
|
|
2332
|
+
* <div>
|
|
2333
|
+
* {addMutation.isPending ? (
|
|
2334
|
+
* 'Adding todo...'
|
|
2335
|
+
* ) : (
|
|
2336
|
+
* <>
|
|
2337
|
+
* {addMutation.isError ? (
|
|
2338
|
+
* <div>An error occurred: {addMutation.error.message}</div>
|
|
2339
|
+
* ) : null}
|
|
2340
|
+
* <button onClick={() => addMutation.mutate('Item')}>Add</button>
|
|
2341
|
+
* </>
|
|
2342
|
+
* )}
|
|
2343
|
+
* </div>
|
|
2344
|
+
* )
|
|
2345
|
+
* }
|
|
2346
|
+
* ```
|
|
2347
|
+
* @example
|
|
2348
|
+
* Optimistic update via `onMutate`, rolling back on `onError`:
|
|
2349
|
+
* ```tsx
|
|
2350
|
+
* import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
2351
|
+
*
|
|
2352
|
+
* function AddTodo() {
|
|
2353
|
+
* const queryClient = useQueryClient()
|
|
2354
|
+
*
|
|
2355
|
+
* const addMutation = useMutation({
|
|
2356
|
+
* mutationFn: addTodo,
|
|
2357
|
+
* onMutate: async (newTodo) => {
|
|
2358
|
+
* await queryClient.cancelQueries({ queryKey: ['todos'] })
|
|
2359
|
+
* const previousTodos = queryClient.getQueryData<Array<string>>(['todos'])
|
|
2360
|
+
*
|
|
2361
|
+
* queryClient.setQueryData<Array<string>>(['todos'], (old) => [
|
|
2362
|
+
* ...(old ?? []),
|
|
2363
|
+
* newTodo,
|
|
2364
|
+
* ])
|
|
2365
|
+
*
|
|
2366
|
+
* // Passed to `onError` as `onMutateResult` if the mutation fails.
|
|
2367
|
+
* return { previousTodos }
|
|
2368
|
+
* },
|
|
2369
|
+
* onError: (_err, _newTodo, onMutateResult) => {
|
|
2370
|
+
* queryClient.setQueryData(['todos'], onMutateResult?.previousTodos)
|
|
2371
|
+
* },
|
|
2372
|
+
* onSettled: () => {
|
|
2373
|
+
* queryClient.invalidateQueries({ queryKey: ['todos'] })
|
|
2374
|
+
* },
|
|
2375
|
+
* })
|
|
2376
|
+
*
|
|
2377
|
+
* return (
|
|
2378
|
+
* <button onClick={() => addMutation.mutate('Item')}>Add</button>
|
|
2379
|
+
* )
|
|
2380
|
+
* }
|
|
2381
|
+
* ```
|
|
2382
|
+
* @example
|
|
2383
|
+
* Callbacks passed per call to `mutate` only fire for the last call — `mutateAsync` gives you a
|
|
2384
|
+
* promise per call instead, so you can wait for all of them when they succeed:
|
|
2385
|
+
* ```tsx
|
|
2386
|
+
* import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
2387
|
+
*
|
|
2388
|
+
* function AddTodos() {
|
|
2389
|
+
* const queryClient = useQueryClient()
|
|
2390
|
+
*
|
|
2391
|
+
* const addMutation = useMutation({
|
|
2392
|
+
* mutationFn: addTodo,
|
|
2393
|
+
* onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),
|
|
2394
|
+
* })
|
|
2395
|
+
*
|
|
2396
|
+
* async function handleAddAll(todos: Array<string>) {
|
|
2397
|
+
* try {
|
|
2398
|
+
* await Promise.all(todos.map((todo) => addMutation.mutateAsync(todo)))
|
|
2399
|
+
* } catch (error) {
|
|
2400
|
+
* console.error('Failed to add todos:', error)
|
|
2401
|
+
* }
|
|
2402
|
+
* }
|
|
2403
|
+
*
|
|
2404
|
+
* return (
|
|
2405
|
+
* <button onClick={() => handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])}>
|
|
2406
|
+
* Add all
|
|
2407
|
+
* </button>
|
|
2408
|
+
* )
|
|
2409
|
+
* }
|
|
2410
|
+
* ```
|
|
2411
|
+
* @example
|
|
2412
|
+
* If some of the mutations above can fail independently of the others, and you want to know which ones
|
|
2413
|
+
* did — rather than losing that information the moment the first one rejects — swap `Promise.all` for
|
|
2414
|
+
* `Promise.allSettled`:
|
|
2415
|
+
* ```tsx
|
|
2416
|
+
* import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
2417
|
+
*
|
|
2418
|
+
* function AddTodos() {
|
|
2419
|
+
* const queryClient = useQueryClient()
|
|
2420
|
+
*
|
|
2421
|
+
* const addMutation = useMutation({
|
|
2422
|
+
* mutationFn: addTodo,
|
|
2423
|
+
* onSuccess: () => queryClient.invalidateQueries({ queryKey: ['todos'] }),
|
|
2424
|
+
* })
|
|
2425
|
+
*
|
|
2426
|
+
* async function handleAddAll(todos: Array<string>) {
|
|
2427
|
+
* const addResults = await Promise.allSettled(
|
|
2428
|
+
* todos.map((todo) => addMutation.mutateAsync(todo)),
|
|
2429
|
+
* )
|
|
2430
|
+
*
|
|
2431
|
+
* addResults.forEach((addResult, index) => {
|
|
2432
|
+
* if (addResult.status === 'rejected') {
|
|
2433
|
+
* console.error(`Failed to add "${todos[index]}":`, addResult.reason)
|
|
2434
|
+
* }
|
|
2435
|
+
* })
|
|
2436
|
+
* }
|
|
2437
|
+
*
|
|
2438
|
+
* return (
|
|
2439
|
+
* <button onClick={() => handleAddAll(['Todo 1', 'Todo 2', 'Todo 3'])}>
|
|
2440
|
+
* Add all
|
|
2441
|
+
* </button>
|
|
2442
|
+
* )
|
|
2443
|
+
* }
|
|
2444
|
+
* ```
|
|
2445
|
+
*/
|
|
2446
|
+
function useMutation(options, queryClient) {
|
|
2447
|
+
const client = useQueryClient(queryClient);
|
|
2448
|
+
const [observer] = import_react.useState(() => new MutationObserver(client, options));
|
|
2449
|
+
import_react.useEffect(() => {
|
|
2450
|
+
observer.setOptions(options);
|
|
2451
|
+
}, [observer, options]);
|
|
2452
|
+
const result = import_react.useSyncExternalStore(import_react.useCallback((onStoreChange) => observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
|
|
2453
|
+
const mutate = import_react.useCallback((...args) => {
|
|
2454
|
+
observer.mutate(args[0], args[1]).catch(noop);
|
|
2455
|
+
}, [observer]);
|
|
2456
|
+
if (result.error && shouldThrowError(observer.options.throwOnError, [result.error])) throw result.error;
|
|
2457
|
+
return {
|
|
2458
|
+
...result,
|
|
2459
|
+
mutate,
|
|
2460
|
+
mutateAsync: result.mutate
|
|
2461
|
+
};
|
|
2462
|
+
}
|
|
2463
|
+
// ../../node_modules/.bun/@tanstack+router-ssr-query-core@1.169.3+3554ab4a3d907bbf/node_modules/@tanstack/router-ssr-query-core/dist/esm/index.js
|
|
2464
|
+
var shouldDehydrateAllQueries = () => true;
|
|
2465
|
+
function setupCoreRouterSsrQueryIntegration({ router, queryClient, dehydrateOptions, hydrateOptions, handleRedirects = true }) {
|
|
2466
|
+
{
|
|
2467
|
+
const originalDehydrate = router.options.dehydrate;
|
|
2468
|
+
let streamState;
|
|
2469
|
+
let cleanedUp = false;
|
|
2470
|
+
const finalizeQueryStream = (failure) => {
|
|
2471
|
+
const state = streamState;
|
|
2472
|
+
streamState = void 0;
|
|
2473
|
+
if (!state) return;
|
|
2474
|
+
state.unsubscribe();
|
|
2475
|
+
try {
|
|
2476
|
+
if (failure) state.controller.error(failure.error);
|
|
2477
|
+
else state.controller.close();
|
|
2478
|
+
} catch {}
|
|
2479
|
+
};
|
|
2480
|
+
const teardown = () => {
|
|
2481
|
+
cleanedUp = true;
|
|
2482
|
+
finalizeQueryStream();
|
|
2483
|
+
queryClient.clear();
|
|
2484
|
+
};
|
|
2485
|
+
router.serverSsrLifecycle = {
|
|
2486
|
+
...router.serverSsrLifecycle,
|
|
2487
|
+
onServerSsrAttach: [...router.serverSsrLifecycle?.onServerSsrAttach ?? [], (serverSsr) => serverSsr.onCleanup(teardown)]
|
|
2488
|
+
};
|
|
2489
|
+
router.options.dehydrate = async () => {
|
|
2490
|
+
let originalDehydrated;
|
|
2491
|
+
try {
|
|
2492
|
+
originalDehydrated = await originalDehydrate?.();
|
|
2493
|
+
} finally {
|
|
2494
|
+
if (cleanedUp) queryClient.clear();
|
|
2495
|
+
}
|
|
2496
|
+
if (cleanedUp) return;
|
|
2497
|
+
const currentDehydrateOptions = queryClient.getDefaultOptions().dehydrate;
|
|
2498
|
+
const shouldDehydrateQuery = dehydrateOptions?.shouldDehydrateQuery ?? currentDehydrateOptions?.shouldDehydrateQuery ?? shouldDehydrateAllQueries;
|
|
2499
|
+
const serializeData = dehydrateOptions?.serializeData ?? currentDehydrateOptions?.serializeData;
|
|
2500
|
+
const shouldRedactErrors = dehydrateOptions?.shouldRedactErrors ?? currentDehydrateOptions?.shouldRedactErrors;
|
|
2501
|
+
const initialQueries = new Array();
|
|
2502
|
+
const sentQueries = /* @__PURE__ */ new Set();
|
|
2503
|
+
for (const query of queryClient.getQueryCache().getAll()) if (shouldDehydrateQuery(query)) {
|
|
2504
|
+
initialQueries.push(dehydrateQuery(query, serializeData, shouldRedactErrors));
|
|
2505
|
+
sentQueries.add(query.queryHash);
|
|
2506
|
+
}
|
|
2507
|
+
let controller;
|
|
2508
|
+
const stream = new ReadableStream({ start(value) {
|
|
2509
|
+
controller = value;
|
|
2510
|
+
} });
|
|
2511
|
+
const flushPendingQueries = () => {
|
|
2512
|
+
const state = streamState;
|
|
2513
|
+
const queries = state?.pendingQueries;
|
|
2514
|
+
if (!state || !queries) return;
|
|
2515
|
+
state.pendingQueries = void 0;
|
|
2516
|
+
const dehydratedQueries = new Array();
|
|
2517
|
+
for (const query of queries.values()) {
|
|
2518
|
+
if (state.sentQueries.has(query.queryHash) || !shouldDehydrateQuery(query)) continue;
|
|
2519
|
+
dehydratedQueries.push(dehydrateQuery(query, serializeData, shouldRedactErrors));
|
|
2520
|
+
state.sentQueries.add(query.queryHash);
|
|
2521
|
+
}
|
|
2522
|
+
if (dehydratedQueries.length > 0) state.controller.enqueue(dehydratedQueries);
|
|
2523
|
+
};
|
|
2524
|
+
const unsubscribe = queryClient.getQueryCache().subscribe((event) => {
|
|
2525
|
+
const state = streamState;
|
|
2526
|
+
if (!state) return;
|
|
2527
|
+
if (state.sentQueries.has(event.query.queryHash) || !event.query.promise) return;
|
|
2528
|
+
if (!state.pendingQueries) {
|
|
2529
|
+
state.pendingQueries = /* @__PURE__ */ new Map();
|
|
2530
|
+
queueMicrotask(() => {
|
|
2531
|
+
try {
|
|
2532
|
+
flushPendingQueries();
|
|
2533
|
+
} catch (error) {
|
|
2534
|
+
finalizeQueryStream({ error });
|
|
2535
|
+
}
|
|
2536
|
+
});
|
|
2537
|
+
}
|
|
2538
|
+
state.pendingQueries.set(event.query.queryHash, event.query);
|
|
2539
|
+
});
|
|
2540
|
+
streamState = {
|
|
2541
|
+
controller,
|
|
2542
|
+
sentQueries,
|
|
2543
|
+
unsubscribe
|
|
2544
|
+
};
|
|
2545
|
+
const finishRendering = () => {
|
|
2546
|
+
try {
|
|
2547
|
+
flushPendingQueries();
|
|
2548
|
+
} catch (error) {
|
|
2549
|
+
finalizeQueryStream({ error });
|
|
2550
|
+
return;
|
|
2551
|
+
}
|
|
2552
|
+
finalizeQueryStream();
|
|
2553
|
+
};
|
|
2554
|
+
router.serverSsr.onRenderFinished(finishRendering);
|
|
2555
|
+
return {
|
|
2556
|
+
...originalDehydrated,
|
|
2557
|
+
query: {
|
|
2558
|
+
...initialQueries.length > 0 && { initial: initialQueries },
|
|
2559
|
+
stream
|
|
2560
|
+
}
|
|
2561
|
+
};
|
|
2562
|
+
};
|
|
2563
|
+
return;
|
|
2564
|
+
}
|
|
2565
|
+
}
|
|
2566
|
+
// ../../node_modules/.bun/@tanstack+react-router-ssr-query@1.167.3+95ede8f94b09b3ae/node_modules/@tanstack/react-router-ssr-query/dist/esm/index.js
|
|
2567
|
+
function setupRouterSsrQueryIntegration(opts) {
|
|
2568
|
+
setupCoreRouterSsrQueryIntegration(opts);
|
|
2569
|
+
if (opts.wrapQueryClient === false) return;
|
|
2570
|
+
const OGWrap = opts.router.options.Wrap || import_react.Fragment;
|
|
2571
|
+
opts.router.options.Wrap = ({ children }) => {
|
|
2572
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(QueryClientProvider, {
|
|
2573
|
+
client: opts.queryClient,
|
|
2574
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OGWrap, { children })
|
|
2575
|
+
});
|
|
2576
|
+
};
|
|
2577
|
+
}
|
|
2578
|
+
// ../mate-core/src/brand/svg.generated.ts
|
|
2579
|
+
var BRAND_SVGS = {
|
|
2580
|
+
symbolColor: "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" width=\"256\" height=\"256\" role=\"img\" aria-labelledby=\"title\"><title id=\"title\">mate logo</title><g id=\"symbol\"><path fill=\"#1F2421\" d=\"M36 16H144V240H36A20 20 0 0 1 16 220V36A20 20 0 0 1 36 16Z\"/><path fill=\"#2E7D5B\" d=\"M160 16H220A20 20 0 0 1 240 36V80H160Z M160 96H240V160H160Z M160 176H240V220A20 20 0 0 1 220 240H160Z\"/></g></svg>",
|
|
2581
|
+
symbolOnDark: "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" width=\"256\" height=\"256\" role=\"img\" aria-labelledby=\"title\"><title id=\"title\">mate logo</title><g id=\"symbol\"><path fill=\"#F4F0E8\" d=\"M36 16H144V240H36A20 20 0 0 1 16 220V36A20 20 0 0 1 36 16Z\"/><path fill=\"#7FD0A6\" d=\"M160 16H220A20 20 0 0 1 240 36V80H160Z M160 96H240V160H160Z M160 176H240V220A20 20 0 0 1 220 240H160Z\"/></g></svg>",
|
|
2582
|
+
favicon: "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 256 256\" width=\"256\" height=\"256\" role=\"img\" aria-labelledby=\"title\"><title id=\"title\">mate logo</title><rect width=\"256\" height=\"256\" rx=\"48\" fill=\"#1F2421\"/><g id=\"symbol\" transform=\"translate(32 32) scale(0.75)\"><path fill=\"#F4F0E8\" d=\"M36 16H144V240H36A20 20 0 0 1 16 220V36A20 20 0 0 1 36 16Z\"/><path fill=\"#7FD0A6\" d=\"M160 16H220A20 20 0 0 1 240 36V80H160Z M160 96H240V160H160Z M160 176H240V220A20 20 0 0 1 220 240H160Z\"/></g></svg>"
|
|
2583
|
+
};
|
|
2584
|
+
// src/styles/palette.ts
|
|
2585
|
+
/** Each of these also gets a `--<name>-soft` tint: this share of the colour over the card surface. */
|
|
2586
|
+
var TINTED_TOKENS = [
|
|
2587
|
+
"accent",
|
|
2588
|
+
"done",
|
|
2589
|
+
"warn",
|
|
2590
|
+
"bad",
|
|
2591
|
+
"info",
|
|
2592
|
+
"what",
|
|
2593
|
+
"why"
|
|
2594
|
+
];
|
|
2595
|
+
function fromReport(report, studio) {
|
|
2596
|
+
return {
|
|
2597
|
+
bg: report.bg,
|
|
2598
|
+
bgRail: report.surface,
|
|
2599
|
+
panel: report.surface,
|
|
2600
|
+
panelSoft: report.bg,
|
|
2601
|
+
border: report.rule,
|
|
2602
|
+
text: report.ink,
|
|
2603
|
+
muted: report.muted,
|
|
2604
|
+
accent: report.accent,
|
|
2605
|
+
done: report.ok,
|
|
2606
|
+
warn: report.warn,
|
|
2607
|
+
bad: report.error,
|
|
2608
|
+
info: report.info,
|
|
2609
|
+
promptBg: report.bg,
|
|
2610
|
+
promptText: report.ink,
|
|
2611
|
+
...studio
|
|
2612
|
+
};
|
|
2613
|
+
}
|
|
2614
|
+
var STUDIO_LIGHT_PALETTE = fromReport(LIGHT_PALETTE, {
|
|
2615
|
+
what: "#176B75",
|
|
2616
|
+
why: "#6346A5",
|
|
2617
|
+
onAccent: "#FFFFFF",
|
|
2618
|
+
drawerShadow: "0 12px 32px rgb(31 36 33 / 12%)"
|
|
2619
|
+
});
|
|
2620
|
+
var STUDIO_DARK_PALETTE = fromReport(DARK_PALETTE, {
|
|
2621
|
+
what: "#74D3D8",
|
|
2622
|
+
why: "#CAA8FF",
|
|
2623
|
+
onAccent: DARK_PALETTE.bg,
|
|
2624
|
+
drawerShadow: "0 14px 36px rgb(0 0 0 / 40%)"
|
|
2625
|
+
});
|
|
2626
|
+
var kebab = (name) => name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
|
|
2627
|
+
function declarations(palette, indent) {
|
|
2628
|
+
const lines = Object.entries(palette).map(([name, value]) => `--${kebab(name)}: ${value};`);
|
|
2629
|
+
lines.push("--border-soft: color-mix(in srgb, var(--border) 55%, var(--panel));");
|
|
2630
|
+
for (const token of TINTED_TOKENS) lines.push(`--${token}-soft: color-mix(in srgb, var(--${token}) 12%, var(--panel));`);
|
|
2631
|
+
return lines.map((line) => `${indent}${line}`).join("\n");
|
|
2632
|
+
}
|
|
2633
|
+
/**
|
|
2634
|
+
* Dark is the default; light applies through the system preference or the in-page
|
|
2635
|
+
* toggle, and an explicit `data-theme` wins over the media query in both directions.
|
|
2636
|
+
*/
|
|
2637
|
+
function studioPaletteCss() {
|
|
2638
|
+
return `:root {
|
|
2639
|
+
color-scheme: dark;
|
|
2640
|
+
${declarations(STUDIO_DARK_PALETTE, " ")}
|
|
2641
|
+
}
|
|
2642
|
+
@media (prefers-color-scheme: light) {
|
|
2643
|
+
:root:not([data-theme="dark"]) {
|
|
2644
|
+
color-scheme: light;
|
|
2645
|
+
${declarations(STUDIO_LIGHT_PALETTE, " ")}
|
|
2646
|
+
}
|
|
2647
|
+
}
|
|
2648
|
+
@media (prefers-color-scheme: dark) {
|
|
2649
|
+
:root:not([data-theme="light"]) { color-scheme: dark; }
|
|
2650
|
+
}
|
|
2651
|
+
:root[data-theme="light"] {
|
|
2652
|
+
color-scheme: light;
|
|
2653
|
+
${declarations(STUDIO_LIGHT_PALETTE, " ")}
|
|
2654
|
+
}
|
|
2655
|
+
:root[data-theme="dark"] {
|
|
2656
|
+
color-scheme: dark;
|
|
2657
|
+
}`;
|
|
2658
|
+
}
|
|
2659
|
+
// src/shell/views.ts
|
|
2660
|
+
/** The path each view is served at. */
|
|
2661
|
+
var VIEW_PATHS = {
|
|
2662
|
+
dashboard: "/",
|
|
2663
|
+
factory: "/factory",
|
|
2664
|
+
workflow: "/workflow",
|
|
2665
|
+
skills: "/skills",
|
|
2666
|
+
vault: "/vault",
|
|
2667
|
+
specs: "/specs",
|
|
2668
|
+
reports: "/reports"
|
|
2669
|
+
};
|
|
2670
|
+
/** A view's page title is its navigation label. */
|
|
2671
|
+
var VIEW_TITLES = {
|
|
2672
|
+
dashboard: "Overview",
|
|
2673
|
+
factory: "Factory",
|
|
2674
|
+
workflow: "Workflow",
|
|
2675
|
+
skills: "Skills",
|
|
2676
|
+
vault: "Vault",
|
|
2677
|
+
specs: "Specs",
|
|
2678
|
+
reports: "Reports"
|
|
2679
|
+
};
|
|
2680
|
+
var MODE_TITLES = {
|
|
2681
|
+
engineering: "Engineering",
|
|
2682
|
+
analysis: "Analysis"
|
|
2683
|
+
};
|
|
2684
|
+
/** The view a path serves, for guards that see only the location. */
|
|
2685
|
+
function viewAt(pathname) {
|
|
2686
|
+
return Object.entries(VIEW_PATHS).find(([, path]) => path === pathname)?.[0];
|
|
2687
|
+
}
|
|
2688
|
+
// src/styles/studio.css?url
|
|
2689
|
+
var studio_default = "/assets/studio-DKxfi691.css";
|
|
2690
|
+
// src/terminal/keys.ts
|
|
2691
|
+
/** Browser storage keys and sizes of the agent terminal, shared by the page and its scripts. */
|
|
2692
|
+
var TERMINAL_TAB_KEY = "mate-studio-terminal-tab";
|
|
2693
|
+
var TERMINAL_SESSION_KEY = "mate-studio-terminal-session";
|
|
2694
|
+
var TERMINAL_WIDTH_KEY = "mate-studio-terminal-width";
|
|
2695
|
+
var TERMINAL_COLLAPSED_KEY = "mate-studio-terminal-collapsed";
|
|
2696
|
+
var TERMINAL_MAX_WIDTH_RATIO = .7;
|
|
2697
|
+
// src/stores/terminal-ui.ts
|
|
2698
|
+
function clampWidth(px) {
|
|
2699
|
+
return Math.round(Math.max(360, Math.min(px, window.innerWidth * TERMINAL_MAX_WIDTH_RATIO)));
|
|
2700
|
+
}
|
|
2701
|
+
function save(key, value) {
|
|
2702
|
+
try {
|
|
2703
|
+
localStorage.setItem(key, value);
|
|
2704
|
+
} catch {}
|
|
2705
|
+
}
|
|
2706
|
+
/**
|
|
2707
|
+
* The terminal sidebar's chrome. The document attributes and the width variable stay what the
|
|
2708
|
+
* stylesheet and the pre-paint script already use, so a reload paints the remembered layout.
|
|
2709
|
+
*/
|
|
2710
|
+
var useTerminalUi = create((set, get) => ({
|
|
2711
|
+
collapsed: false,
|
|
2712
|
+
drawerOpen: false,
|
|
2713
|
+
viewing: null,
|
|
2714
|
+
controller: null,
|
|
2715
|
+
setCollapsed: (collapsed) => {
|
|
2716
|
+
document.documentElement.toggleAttribute("data-terminal-collapsed", collapsed);
|
|
2717
|
+
save(TERMINAL_COLLAPSED_KEY, String(collapsed));
|
|
2718
|
+
set({ collapsed });
|
|
2719
|
+
},
|
|
2720
|
+
setDrawerOpen: (drawerOpen) => set({ drawerOpen }),
|
|
2721
|
+
setWidth: (px, persist) => {
|
|
2722
|
+
const width = clampWidth(px);
|
|
2723
|
+
document.documentElement.style.setProperty("--terminal-width", `${width}px`);
|
|
2724
|
+
if (persist) save(TERMINAL_WIDTH_KEY, String(width));
|
|
2725
|
+
},
|
|
2726
|
+
setViewing: (viewing) => {
|
|
2727
|
+
if (viewing) document.documentElement.setAttribute("data-agent-viewed", viewing);
|
|
2728
|
+
else document.documentElement.removeAttribute("data-agent-viewed");
|
|
2729
|
+
set({ viewing });
|
|
2730
|
+
},
|
|
2731
|
+
register: (controller) => set({ controller }),
|
|
2732
|
+
reveal: () => {
|
|
2733
|
+
if (get().collapsed) get().setCollapsed(false);
|
|
2734
|
+
const opener = document.getElementById("terminal-drawer-open");
|
|
2735
|
+
if (opener && getComputedStyle(opener).display !== "none") set({ drawerOpen: true });
|
|
2736
|
+
}
|
|
2737
|
+
}));
|
|
2738
|
+
/** Applies the remembered layout before paint; authored source only. */
|
|
2739
|
+
var TERMINAL_PREPAINT_SCRIPT = `(function () {
|
|
2740
|
+
try {
|
|
2741
|
+
var width = parseInt(localStorage.getItem(${JSON.stringify(TERMINAL_WIDTH_KEY)}) || "", 10);
|
|
2742
|
+
if (width > 0) document.documentElement.style.setProperty("--terminal-width", Math.round(Math.max(360, Math.min(width, window.innerWidth * ${TERMINAL_MAX_WIDTH_RATIO}))) + "px");
|
|
2743
|
+
if (localStorage.getItem(${JSON.stringify(TERMINAL_COLLAPSED_KEY)}) === "true") {
|
|
2744
|
+
document.documentElement.setAttribute("data-terminal-collapsed", "");
|
|
2745
|
+
}
|
|
2746
|
+
} catch (error) {
|
|
2747
|
+
/* a blocked web store only costs the preference, never the page */
|
|
2748
|
+
}
|
|
2749
|
+
})();`;
|
|
2750
|
+
// src/stores/page-ui.ts
|
|
2751
|
+
var toastTimer;
|
|
2752
|
+
var reportTimer;
|
|
2753
|
+
var usePageUi = create((set) => ({
|
|
2754
|
+
toast: null,
|
|
2755
|
+
report: null,
|
|
2756
|
+
reportsBadge: false,
|
|
2757
|
+
announce: (toast) => {
|
|
2758
|
+
set({ toast });
|
|
2759
|
+
clearTimeout(toastTimer);
|
|
2760
|
+
toastTimer = setTimeout(() => set({ toast: null }), 1400);
|
|
2761
|
+
},
|
|
2762
|
+
announceReport: (report) => {
|
|
2763
|
+
set({
|
|
2764
|
+
report,
|
|
2765
|
+
reportsBadge: true
|
|
2766
|
+
});
|
|
2767
|
+
clearTimeout(reportTimer);
|
|
2768
|
+
reportTimer = setTimeout(() => set({ report: null }), 1e4);
|
|
2769
|
+
},
|
|
2770
|
+
clearReports: () => set({
|
|
2771
|
+
reportsBadge: false,
|
|
2772
|
+
report: null
|
|
2773
|
+
})
|
|
2774
|
+
}));
|
|
2775
|
+
/** Copies text and confirms it in the page; a blocked clipboard costs the copy, never the page. */
|
|
2776
|
+
function copyText(text, label) {
|
|
2777
|
+
const { announce } = usePageUi.getState();
|
|
2778
|
+
if (typeof navigator === "undefined" || typeof navigator.clipboard?.writeText !== "function") {
|
|
2779
|
+
announce("copying is blocked in this browser");
|
|
2780
|
+
return;
|
|
2781
|
+
}
|
|
2782
|
+
navigator.clipboard.writeText(text).then(() => announce(`copied ${label}`), () => announce("copying is blocked in this browser"));
|
|
2783
|
+
}
|
|
2784
|
+
// src/stores/vault-ui.ts
|
|
2785
|
+
var useVaultUi = create((set, get) => ({
|
|
2786
|
+
treeHidden: false,
|
|
2787
|
+
latestGeneration: null,
|
|
2788
|
+
dirty: false,
|
|
2789
|
+
hydrate: () => set({ treeHidden: document.documentElement.getAttribute("data-vault-tree") === "hidden" }),
|
|
2790
|
+
toggleTree: () => {
|
|
2791
|
+
const treeHidden = !get().treeHidden;
|
|
2792
|
+
if (treeHidden) document.documentElement.setAttribute("data-vault-tree", "hidden");
|
|
2793
|
+
else document.documentElement.removeAttribute("data-vault-tree");
|
|
2794
|
+
try {
|
|
2795
|
+
localStorage.setItem(VAULT_TREE_STORAGE_KEY, treeHidden ? "hidden" : "shown");
|
|
2796
|
+
} catch {}
|
|
2797
|
+
set({ treeHidden });
|
|
2798
|
+
},
|
|
2799
|
+
setGeneration: (generation) => set((state) => ({ latestGeneration: Math.max(generation, state.latestGeneration ?? generation) })),
|
|
2800
|
+
setDirty: (dirty) => set({ dirty })
|
|
2801
|
+
}));
|
|
2802
|
+
// src/lib/events.ts
|
|
2803
|
+
/** Follows the companion's event stream for as long as the page shows it. */
|
|
2804
|
+
function useStudioEvents(digest) {
|
|
2805
|
+
const queryClient = useQueryClient();
|
|
2806
|
+
(0, import_react.useEffect)(() => {
|
|
2807
|
+
if (!digest || typeof EventSource === "undefined") return;
|
|
2808
|
+
const source = new EventSource(`${STUDIO_EVENTS_ROUTE}?companion=${encodeURIComponent(digest)}`);
|
|
2809
|
+
source.addEventListener("message", (message) => {
|
|
2810
|
+
let event;
|
|
2811
|
+
try {
|
|
2812
|
+
event = JSON.parse(message.data);
|
|
2813
|
+
} catch {
|
|
2814
|
+
return;
|
|
2815
|
+
}
|
|
2816
|
+
if (event.type === "vault-tree") useVaultUi.getState().setGeneration(event.generation);
|
|
2817
|
+
if (event.type === "reports" && !location.pathname.startsWith("/reports")) usePageUi.getState().announceReport({
|
|
2818
|
+
id: event.id,
|
|
2819
|
+
title: event.title
|
|
2820
|
+
});
|
|
2821
|
+
afterEvent(queryClient, digest, event.type);
|
|
2822
|
+
});
|
|
2823
|
+
return () => source.close();
|
|
2824
|
+
}, [digest, queryClient]);
|
|
2825
|
+
}
|
|
2826
|
+
// src/lib/page-actions.ts
|
|
2827
|
+
var AGENT_ORDER = ["claude", "opencode"];
|
|
2828
|
+
/** The prompt for the agent the terminal shows, else the first agent that has one. */
|
|
2829
|
+
function promptFor(node) {
|
|
2830
|
+
const viewed = useTerminalUi.getState().viewing;
|
|
2831
|
+
const order = viewed && viewed !== "pending" ? [viewed, ...AGENT_ORDER] : AGENT_ORDER;
|
|
2832
|
+
for (const agent of order) {
|
|
2833
|
+
const text = node.getAttribute(`data-prompt-${agent}`);
|
|
2834
|
+
if (text) return text;
|
|
2835
|
+
}
|
|
2836
|
+
return null;
|
|
2837
|
+
}
|
|
2838
|
+
/**
|
|
2839
|
+
* One delegated handler for the views' copy and run controls, so a long list needs no
|
|
2840
|
+
* handler per row: `data-copy` copies its text, `data-studio-copy-prompt` the prompt for the
|
|
2841
|
+
* viewed agent, and `data-studio-action` runs a registered skill action in the terminal.
|
|
2842
|
+
*/
|
|
2843
|
+
function useStudioClicks() {
|
|
2844
|
+
(0, import_react.useEffect)(() => {
|
|
2845
|
+
const click = (event) => {
|
|
2846
|
+
const target = event.target;
|
|
2847
|
+
if (!target?.closest) return;
|
|
2848
|
+
const run = target.closest("[data-studio-action]");
|
|
2849
|
+
if (run) {
|
|
2850
|
+
useTerminalUi.getState().controller?.runAction({
|
|
2851
|
+
action: run.getAttribute("data-studio-action") ?? "",
|
|
2852
|
+
subject: run.getAttribute("data-studio-subject") ?? "",
|
|
2853
|
+
agents: (run.getAttribute("data-studio-agents") ?? "").split(" ").filter(Boolean)
|
|
2854
|
+
});
|
|
2855
|
+
return;
|
|
2856
|
+
}
|
|
2857
|
+
const copy = target.closest("[data-copy]");
|
|
2858
|
+
if (copy) {
|
|
2859
|
+
const text = copy.getAttribute("data-copy");
|
|
2860
|
+
if (text) copyText(text, copy.getAttribute("data-copy-label") || "prompt");
|
|
2861
|
+
return;
|
|
2862
|
+
}
|
|
2863
|
+
const prompt = target.closest("[data-studio-copy-prompt]");
|
|
2864
|
+
if (prompt) {
|
|
2865
|
+
const text = promptFor(prompt);
|
|
2866
|
+
if (text) copyText(text, "prompt");
|
|
2867
|
+
}
|
|
2868
|
+
};
|
|
2869
|
+
document.addEventListener("click", click);
|
|
2870
|
+
return () => document.removeEventListener("click", click);
|
|
2871
|
+
}, []);
|
|
2872
|
+
}
|
|
2873
|
+
// src/lib/prefetch-views.ts
|
|
2874
|
+
/** Views read from the held snapshot; Factory, Vault and Reports load their own way. */
|
|
2875
|
+
var AHEAD = [
|
|
2876
|
+
"dashboard",
|
|
2877
|
+
"workflow",
|
|
2878
|
+
"skills",
|
|
2879
|
+
"specs"
|
|
2880
|
+
];
|
|
2881
|
+
/**
|
|
2882
|
+
* Loads the mode's companion views one after another, skipping those already held, so the
|
|
2883
|
+
* first click on each is instant and the server is asked one view at a time.
|
|
2884
|
+
*/
|
|
2885
|
+
async function prefetchViews(queryClient, search, studioMode, { query = companionViewQuery, preload, cancelled = () => false } = {}) {
|
|
2886
|
+
const offered = viewsFor(studioMode);
|
|
2887
|
+
for (const view of AHEAD) {
|
|
2888
|
+
if (cancelled()) return;
|
|
2889
|
+
if (!offered.includes(view)) continue;
|
|
2890
|
+
const options = query(view, search);
|
|
2891
|
+
if (queryClient.getQueryData(options.queryKey) === void 0) {
|
|
2892
|
+
await queryClient.query(options).catch(() => {});
|
|
2893
|
+
if (cancelled()) return;
|
|
2894
|
+
}
|
|
2895
|
+
await preload?.(view).catch(() => {});
|
|
2896
|
+
}
|
|
2897
|
+
}
|
|
2898
|
+
var whenIdle = (run) => {
|
|
2899
|
+
if (typeof requestIdleCallback === "function") {
|
|
2900
|
+
const handle = requestIdleCallback(run);
|
|
2901
|
+
return () => cancelIdleCallback(handle);
|
|
2902
|
+
}
|
|
2903
|
+
const handle = setTimeout(run, 200);
|
|
2904
|
+
return () => clearTimeout(handle);
|
|
2905
|
+
};
|
|
2906
|
+
/**
|
|
2907
|
+
* Loads the current mode's other companion views while the page is idle. Never runs while the
|
|
2908
|
+
* Vault is shown: every page read on the server deactivates the vault's watchers.
|
|
2909
|
+
*/
|
|
2910
|
+
function usePrefetchViews(search, studioMode, view) {
|
|
2911
|
+
const queryClient = useQueryClient();
|
|
2912
|
+
const router = useRouter();
|
|
2913
|
+
const { companion } = search;
|
|
2914
|
+
const requestedMode = search.studioMode;
|
|
2915
|
+
const onVault = view === "vault";
|
|
2916
|
+
(0, import_react.useEffect)(() => {
|
|
2917
|
+
if (!companion || onVault) return;
|
|
2918
|
+
let stopped = false;
|
|
2919
|
+
const viewSearch = {
|
|
2920
|
+
companion,
|
|
2921
|
+
studioMode: requestedMode
|
|
2922
|
+
};
|
|
2923
|
+
const cancel = whenIdle(() => {
|
|
2924
|
+
prefetchViews(queryClient, viewSearch, studioMode, {
|
|
2925
|
+
preload: (next) => router.preloadRoute({
|
|
2926
|
+
to: VIEW_PATHS[next],
|
|
2927
|
+
search: viewSearch
|
|
2928
|
+
}),
|
|
2929
|
+
cancelled: () => stopped
|
|
2930
|
+
});
|
|
2931
|
+
});
|
|
2932
|
+
return () => {
|
|
2933
|
+
stopped = true;
|
|
2934
|
+
cancel();
|
|
2935
|
+
};
|
|
2936
|
+
}, [
|
|
2937
|
+
companion,
|
|
2938
|
+
requestedMode,
|
|
2939
|
+
studioMode,
|
|
2940
|
+
onVault,
|
|
2941
|
+
queryClient,
|
|
2942
|
+
router
|
|
2943
|
+
]);
|
|
2944
|
+
}
|
|
2945
|
+
// src/shell/companion-picker.tsx
|
|
2946
|
+
/** Kept short so a card leads with what distinguishes it, not the shared prefix. */
|
|
2947
|
+
var PAIRING_CHIP_LIMIT = 3;
|
|
2948
|
+
function companionName(companionPath) {
|
|
2949
|
+
const segments = companionPath.split(/[\\/]+/).filter(Boolean);
|
|
2950
|
+
return segments[segments.length - 1] ?? companionPath;
|
|
2951
|
+
}
|
|
2952
|
+
/**
|
|
2953
|
+
* The main content while no companion is chosen: one card per companion, so the first choice
|
|
2954
|
+
* is a click on the thing being chosen rather than a trip through the sidebar select.
|
|
2955
|
+
*/
|
|
2956
|
+
function CompanionPicker({ companions }) {
|
|
2957
|
+
const navigate = useNavigate();
|
|
2958
|
+
if (companions.length === 0) return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
|
|
2959
|
+
className: "panel",
|
|
2960
|
+
children: [
|
|
2961
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { children: "No Companion Repository" }),
|
|
2962
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
|
|
2963
|
+
className: "empty",
|
|
2964
|
+
children: "No Companion Repository is registered on this machine."
|
|
2965
|
+
}),
|
|
2966
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
|
|
2967
|
+
className: "muted",
|
|
2968
|
+
children: [
|
|
2969
|
+
"Run ",
|
|
2970
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
2971
|
+
className: "mono",
|
|
2972
|
+
children: "mate companion setup"
|
|
2973
|
+
}),
|
|
2974
|
+
" in a Working Repository to register one."
|
|
2975
|
+
]
|
|
2976
|
+
})
|
|
2977
|
+
]
|
|
2978
|
+
});
|
|
2979
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
|
|
2980
|
+
className: "panel",
|
|
2981
|
+
children: [
|
|
2982
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { children: "Choose a Companion Repository" }),
|
|
2983
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
|
|
2984
|
+
className: "note",
|
|
2985
|
+
children: "Studio serves one companion at a time, and remembers the one you choose for your next visit."
|
|
2986
|
+
}),
|
|
2987
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
2988
|
+
className: "picker-grid",
|
|
2989
|
+
children: companions.map((companion) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
|
|
2990
|
+
type: "button",
|
|
2991
|
+
className: "picker-card",
|
|
2992
|
+
"data-unready": companion.unready ? "true" : void 0,
|
|
2993
|
+
onClick: () => void navigate({
|
|
2994
|
+
to: ".",
|
|
2995
|
+
search: (previous) => ({
|
|
2996
|
+
...previous,
|
|
2997
|
+
companion: companion.digest
|
|
2998
|
+
})
|
|
2999
|
+
}),
|
|
3000
|
+
children: [
|
|
3001
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
3002
|
+
className: "picker-card-name",
|
|
3003
|
+
children: companionName(companion.path)
|
|
3004
|
+
}),
|
|
3005
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
3006
|
+
className: "picker-card-path mono",
|
|
3007
|
+
children: companion.path
|
|
3008
|
+
}),
|
|
3009
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
3010
|
+
className: "picker-card-meta",
|
|
3011
|
+
children: [
|
|
3012
|
+
companion.note ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
3013
|
+
className: "chip chip-invalid",
|
|
3014
|
+
children: companion.note
|
|
3015
|
+
}) : null,
|
|
3016
|
+
companion.pairings.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
3017
|
+
className: "chip",
|
|
3018
|
+
children: "no linked working repository"
|
|
3019
|
+
}) : companion.pairings.slice(0, PAIRING_CHIP_LIMIT).map((pairing) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
3020
|
+
className: "chip",
|
|
3021
|
+
children: pairing
|
|
3022
|
+
}, pairing)),
|
|
3023
|
+
companion.pairings.length > PAIRING_CHIP_LIMIT ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
3024
|
+
className: "chip",
|
|
3025
|
+
children: [
|
|
3026
|
+
"+",
|
|
3027
|
+
companion.pairings.length - PAIRING_CHIP_LIMIT,
|
|
3028
|
+
" more"
|
|
3029
|
+
]
|
|
3030
|
+
}) : null
|
|
3031
|
+
]
|
|
3032
|
+
})
|
|
3033
|
+
]
|
|
3034
|
+
}, companion.digest))
|
|
3035
|
+
})
|
|
3036
|
+
]
|
|
3037
|
+
});
|
|
3038
|
+
}
|
|
3039
|
+
// src/shell/navigation-progress.tsx
|
|
3040
|
+
/**
|
|
3041
|
+
* A thin bar along the top while a navigation is pending or a view waits for its first data.
|
|
3042
|
+
* The waiting view is seen through its placeholder in the stylesheet, so background refreshes
|
|
3043
|
+
* of held data, which show no placeholder, stay quiet.
|
|
3044
|
+
*/
|
|
3045
|
+
function NavigationProgress() {
|
|
3046
|
+
const pending = useRouterState({ select: (state) => state.status === "pending" });
|
|
3047
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
3048
|
+
className: "nav-progress",
|
|
3049
|
+
"data-pending": pending ? "true" : "false",
|
|
3050
|
+
"aria-hidden": "true"
|
|
3051
|
+
});
|
|
3052
|
+
}
|
|
3053
|
+
/** Stands in for a view until its data arrives; the sidebar and header stay as they were. */
|
|
3054
|
+
function ViewPlaceholder() {
|
|
3055
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
|
|
3056
|
+
className: "view-placeholder",
|
|
3057
|
+
"aria-busy": "true",
|
|
3058
|
+
children: [
|
|
3059
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
3060
|
+
className: "visually-hidden",
|
|
3061
|
+
role: "status",
|
|
3062
|
+
children: "Loading…"
|
|
3063
|
+
}),
|
|
3064
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "view-placeholder-line" }),
|
|
3065
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "view-placeholder-line" }),
|
|
3066
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "view-placeholder-line" })
|
|
3067
|
+
]
|
|
3068
|
+
});
|
|
3069
|
+
}
|
|
3070
|
+
// src/shell/local-time.tsx
|
|
3071
|
+
var subscribe = () => () => {};
|
|
3072
|
+
/**
|
|
3073
|
+
* A moment in the viewer's own time zone. The shell is rendered on the server, whose zone may
|
|
3074
|
+
* differ (the factory appliance runs in UTC), so the time is filled in after the page hydrates.
|
|
3075
|
+
*/
|
|
3076
|
+
function LocalTime({ at }) {
|
|
3077
|
+
const text = (0, import_react.useSyncExternalStore)(subscribe, () => formatCollectedAt(at), () => "");
|
|
3078
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("time", {
|
|
3079
|
+
dateTime: new Date(at).toISOString(),
|
|
3080
|
+
children: text
|
|
3081
|
+
});
|
|
3082
|
+
}
|
|
3083
|
+
// src/shell/page-header.tsx
|
|
3084
|
+
function PageHeader({ shell, view }) {
|
|
3085
|
+
if (!shell.selected) return null;
|
|
3086
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("header", {
|
|
3087
|
+
className: "page-header",
|
|
3088
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
3089
|
+
className: "page-heading",
|
|
3090
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", { children: VIEW_TITLES[view] })
|
|
3091
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
3092
|
+
className: "page-context",
|
|
3093
|
+
children: [
|
|
3094
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
3095
|
+
className: "page-context-label",
|
|
3096
|
+
children: "Companion Repository"
|
|
3097
|
+
}),
|
|
3098
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { children: shell.selected.path }),
|
|
3099
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
|
|
3100
|
+
className: "snapshot-status",
|
|
3101
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
3102
|
+
className: "snapshot-dot",
|
|
3103
|
+
"aria-hidden": "true"
|
|
3104
|
+
}), shell.collectedAt === null ? "No snapshot" : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: ["Snapshot ", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LocalTime, { at: shell.collectedAt })] })]
|
|
3105
|
+
})
|
|
3106
|
+
]
|
|
3107
|
+
})]
|
|
3108
|
+
});
|
|
3109
|
+
}
|
|
3110
|
+
// src/stores/appearance.ts
|
|
3111
|
+
var THEME_CYCLE = [
|
|
3112
|
+
"system",
|
|
3113
|
+
"dark",
|
|
3114
|
+
"light"
|
|
3115
|
+
];
|
|
3116
|
+
function readTheme() {
|
|
3117
|
+
try {
|
|
3118
|
+
const stored = localStorage.getItem(THEME_STORAGE_KEY);
|
|
3119
|
+
return stored && THEME_CYCLE.includes(stored) ? stored : "system";
|
|
3120
|
+
} catch {
|
|
3121
|
+
return "system";
|
|
3122
|
+
}
|
|
3123
|
+
}
|
|
3124
|
+
function applyTheme(theme) {
|
|
3125
|
+
const root = document.documentElement;
|
|
3126
|
+
if (theme === "system") root.removeAttribute("data-theme");
|
|
3127
|
+
else root.setAttribute("data-theme", theme);
|
|
3128
|
+
}
|
|
3129
|
+
/** The chosen appearance, remembered in local storage like the server-rendered views did. */
|
|
3130
|
+
var useAppearance = create((set, get) => ({
|
|
3131
|
+
theme: "system",
|
|
3132
|
+
hydrate: () => set({ theme: readTheme() }),
|
|
3133
|
+
cycle: () => {
|
|
3134
|
+
const next = THEME_CYCLE[(THEME_CYCLE.indexOf(get().theme) + 1) % THEME_CYCLE.length];
|
|
3135
|
+
applyTheme(next);
|
|
3136
|
+
try {
|
|
3137
|
+
localStorage.setItem(THEME_STORAGE_KEY, next);
|
|
3138
|
+
} catch {}
|
|
3139
|
+
set({ theme: next });
|
|
3140
|
+
}
|
|
3141
|
+
}));
|
|
3142
|
+
// src/shell/sidebar.tsx
|
|
3143
|
+
var svgUri = (svg) => `data:image/svg+xml;base64,${btoa(svg)}`;
|
|
3144
|
+
var SYMBOL_COLOR_URI = svgUri(BRAND_SVGS.symbolColor);
|
|
3145
|
+
var SYMBOL_ON_DARK_URI = svgUri(BRAND_SVGS.symbolOnDark);
|
|
3146
|
+
function Sidebar({ shell, search, view }) {
|
|
3147
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("aside", {
|
|
3148
|
+
className: "rail studio-sidebar",
|
|
3149
|
+
id: "studio-rail",
|
|
3150
|
+
children: [
|
|
3151
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
3152
|
+
className: "sidebar-brand",
|
|
3153
|
+
children: [
|
|
3154
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", {
|
|
3155
|
+
className: "sidebar-brand-mark brand-symbol-color",
|
|
3156
|
+
src: SYMBOL_COLOR_URI,
|
|
3157
|
+
alt: ""
|
|
3158
|
+
}),
|
|
3159
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", {
|
|
3160
|
+
className: "sidebar-brand-mark brand-symbol-on-dark",
|
|
3161
|
+
src: SYMBOL_ON_DARK_URI,
|
|
3162
|
+
alt: ""
|
|
3163
|
+
}),
|
|
3164
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
3165
|
+
className: "sidebar-brand-copy",
|
|
3166
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: "Mate Studio" })
|
|
3167
|
+
})
|
|
3168
|
+
]
|
|
3169
|
+
}),
|
|
3170
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ModeSwitch, {
|
|
3171
|
+
shell,
|
|
3172
|
+
search,
|
|
3173
|
+
view
|
|
3174
|
+
}),
|
|
3175
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(CompanionSelector, { shell }),
|
|
3176
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ViewNav, {
|
|
3177
|
+
studioMode: shell.studioMode,
|
|
3178
|
+
factoryMode: shell.factoryMode,
|
|
3179
|
+
search,
|
|
3180
|
+
view
|
|
3181
|
+
}),
|
|
3182
|
+
shell.studioMode === "engineering" && shell.metrics ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Metrics, { metrics: shell.metrics }) : null,
|
|
3183
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Footer, {
|
|
3184
|
+
shell,
|
|
3185
|
+
search
|
|
3186
|
+
})
|
|
3187
|
+
]
|
|
3188
|
+
});
|
|
3189
|
+
}
|
|
3190
|
+
var MODE_NOTE_ID = "studio-mode-note";
|
|
3191
|
+
/** Why a mode is shown but cannot be chosen; only the appliance disables one. */
|
|
3192
|
+
function unavailableNote(shell) {
|
|
3193
|
+
const disabled = STUDIO_MODES.filter((mode) => !shell.enabledModes.includes(mode));
|
|
3194
|
+
if (disabled.length === 0) return null;
|
|
3195
|
+
const names = disabled.map((mode) => MODE_TITLES[mode]).join(" and ");
|
|
3196
|
+
return shell.profile === "appliance" ? `${names} is unavailable in the appliance.` : `${names} is unavailable here.`;
|
|
3197
|
+
}
|
|
3198
|
+
function ModeSwitch({ shell, search, view }) {
|
|
3199
|
+
const note = unavailableNote(shell);
|
|
3200
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
3201
|
+
className: "mode-switch-block",
|
|
3202
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
3203
|
+
className: "mode-switch",
|
|
3204
|
+
role: "group",
|
|
3205
|
+
"aria-label": "Mode",
|
|
3206
|
+
"aria-describedby": note ? MODE_NOTE_ID : void 0,
|
|
3207
|
+
children: STUDIO_MODES.map((next) => shell.enabledModes.includes(next) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Link, {
|
|
3208
|
+
className: "mode-switch-option",
|
|
3209
|
+
to: viewsFor(next).includes(view) ? VIEW_PATHS[view] : "/",
|
|
3210
|
+
search: {
|
|
3211
|
+
...search,
|
|
3212
|
+
studioMode: next
|
|
3213
|
+
},
|
|
3214
|
+
"aria-pressed": shell.studioMode === next,
|
|
3215
|
+
role: "button",
|
|
3216
|
+
children: MODE_TITLES[next]
|
|
3217
|
+
}, next) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
3218
|
+
type: "button",
|
|
3219
|
+
className: "mode-switch-option",
|
|
3220
|
+
disabled: true,
|
|
3221
|
+
"aria-pressed": false,
|
|
3222
|
+
"aria-describedby": MODE_NOTE_ID,
|
|
3223
|
+
children: MODE_TITLES[next]
|
|
3224
|
+
}, next))
|
|
3225
|
+
}), note ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
|
|
3226
|
+
className: "mode-switch-note",
|
|
3227
|
+
id: MODE_NOTE_ID,
|
|
3228
|
+
children: note
|
|
3229
|
+
}) : null]
|
|
3230
|
+
});
|
|
3231
|
+
}
|
|
3232
|
+
function CompanionSelector({ shell }) {
|
|
3233
|
+
const navigate = useNavigate();
|
|
3234
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
3235
|
+
className: "sidebar-scope",
|
|
3236
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
3237
|
+
className: "sidebar-label",
|
|
3238
|
+
children: "Scope"
|
|
3239
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("select", {
|
|
3240
|
+
"aria-label": "Companion Repository",
|
|
3241
|
+
value: shell.selected?.digest ?? "",
|
|
3242
|
+
onChange: (event) => void navigate({
|
|
3243
|
+
to: ".",
|
|
3244
|
+
search: (previous) => ({
|
|
3245
|
+
...previous,
|
|
3246
|
+
companion: event.target.value
|
|
3247
|
+
})
|
|
3248
|
+
}),
|
|
3249
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(PlaceholderOption, { shell }), shell.companions.map((companion) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", {
|
|
3250
|
+
value: companion.digest,
|
|
3251
|
+
className: companion.unready ? "unready" : void 0,
|
|
3252
|
+
"data-unready": companion.unready ? "true" : void 0,
|
|
3253
|
+
children: companion.note ? `${companion.path} (${companion.note})` : companion.path
|
|
3254
|
+
}, companion.digest))]
|
|
3255
|
+
})]
|
|
3256
|
+
});
|
|
3257
|
+
}
|
|
3258
|
+
/** Stands in for the selection while no companion is registered or none is selected. */
|
|
3259
|
+
function PlaceholderOption({ shell }) {
|
|
3260
|
+
if (shell.companions.length === 0) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", {
|
|
3261
|
+
value: "",
|
|
3262
|
+
className: "placeholder",
|
|
3263
|
+
children: "no companion registered"
|
|
3264
|
+
});
|
|
3265
|
+
if (shell.selected) return null;
|
|
3266
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", {
|
|
3267
|
+
value: "",
|
|
3268
|
+
disabled: true,
|
|
3269
|
+
className: "placeholder",
|
|
3270
|
+
children: "select a companion…"
|
|
3271
|
+
});
|
|
3272
|
+
}
|
|
3273
|
+
function ViewNav({ studioMode, factoryMode, search, view }) {
|
|
3274
|
+
const modeViews = MODE_VIEWS[studioMode].filter((entry) => factoryMode || entry !== "factory");
|
|
3275
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("nav", {
|
|
3276
|
+
className: "sidebar-nav",
|
|
3277
|
+
"aria-label": "Studio views",
|
|
3278
|
+
children: [modeViews.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ViewSection, {
|
|
3279
|
+
label: MODE_TITLES[studioMode],
|
|
3280
|
+
views: modeViews,
|
|
3281
|
+
search,
|
|
3282
|
+
current: view
|
|
3283
|
+
}) : null, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ViewSection, {
|
|
3284
|
+
label: "Shared",
|
|
3285
|
+
views: SHARED_VIEWS,
|
|
3286
|
+
search,
|
|
3287
|
+
current: view
|
|
3288
|
+
})]
|
|
3289
|
+
});
|
|
3290
|
+
}
|
|
3291
|
+
function ViewSection(props) {
|
|
3292
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
3293
|
+
className: "sidebar-nav-section",
|
|
3294
|
+
"data-studio-nav-section": props.label,
|
|
3295
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
3296
|
+
className: "sidebar-label",
|
|
3297
|
+
children: props.label
|
|
3298
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
3299
|
+
className: "sidebar-nav-list",
|
|
3300
|
+
children: props.views.map((view) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Link, {
|
|
3301
|
+
to: VIEW_PATHS[view],
|
|
3302
|
+
search: props.search,
|
|
3303
|
+
className: "sidebar-nav-link",
|
|
3304
|
+
"aria-current": props.current === view ? "page" : void 0,
|
|
3305
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: VIEW_TITLES[view] }), view === "reports" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ReportsBadge, {}) : null]
|
|
3306
|
+
}, view))
|
|
3307
|
+
})]
|
|
3308
|
+
});
|
|
3309
|
+
}
|
|
3310
|
+
function Metrics({ metrics }) {
|
|
3311
|
+
const shown = [
|
|
3312
|
+
["changes", metrics.changes],
|
|
3313
|
+
["done", metrics.done],
|
|
3314
|
+
["specs", metrics.specs]
|
|
3315
|
+
];
|
|
3316
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
3317
|
+
className: "sidebar-metrics",
|
|
3318
|
+
id: "studio-stats",
|
|
3319
|
+
children: shown.map(([label, value]) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
3320
|
+
className: "sidebar-metric",
|
|
3321
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: value }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: label })]
|
|
3322
|
+
}, label))
|
|
3323
|
+
});
|
|
3324
|
+
}
|
|
3325
|
+
/** The refresh control is the only thing that collects again, and only the selected companion. */
|
|
3326
|
+
function Footer({ shell, search }) {
|
|
3327
|
+
const queryClient = useQueryClient();
|
|
3328
|
+
const refresh = useMutation({
|
|
3329
|
+
mutationFn: () => getShell({ data: {
|
|
3330
|
+
...search,
|
|
3331
|
+
refresh: true
|
|
3332
|
+
} }),
|
|
3333
|
+
onSuccess: () => afterRefresh(queryClient, search.companion)
|
|
3334
|
+
});
|
|
3335
|
+
const theme = useAppearance((state) => state.theme);
|
|
3336
|
+
const cycle = useAppearance((state) => state.cycle);
|
|
3337
|
+
const hydrate = useAppearance((state) => state.hydrate);
|
|
3338
|
+
(0, import_react.useEffect)(hydrate, [hydrate]);
|
|
3339
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
3340
|
+
className: "sidebar-footer",
|
|
3341
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
3342
|
+
className: "sidebar-footer-row",
|
|
3343
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
3344
|
+
className: "muted",
|
|
3345
|
+
children: shell.collectedAt === null ? "no state collected" : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: ["state as of ", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LocalTime, { at: shell.collectedAt })] })
|
|
3346
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
3347
|
+
type: "button",
|
|
3348
|
+
onClick: () => refresh.mutate(),
|
|
3349
|
+
disabled: refresh.isPending,
|
|
3350
|
+
children: refresh.isPending ? "Refreshing…" : "Refresh"
|
|
3351
|
+
})]
|
|
3352
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
|
|
3353
|
+
id: "studio-theme",
|
|
3354
|
+
type: "button",
|
|
3355
|
+
"data-theme-state": theme,
|
|
3356
|
+
onClick: cycle,
|
|
3357
|
+
children: ["Theme: ", theme]
|
|
3358
|
+
})]
|
|
3359
|
+
});
|
|
3360
|
+
}
|
|
3361
|
+
/** A report published while another view was shown. */
|
|
3362
|
+
function ReportsBadge() {
|
|
3363
|
+
return usePageUi((state) => state.reportsBadge) ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
3364
|
+
className: "nav-badge",
|
|
3365
|
+
children: "new"
|
|
3366
|
+
}) : null;
|
|
3367
|
+
}
|
|
3368
|
+
// src/terminal/socket.ts
|
|
3369
|
+
/** The terminal WebSocket on Studio's own origin; output arrives as binary frames. */
|
|
3370
|
+
function openTerminalSocket() {
|
|
3371
|
+
const scheme = location.protocol === "https:" ? "wss:" : "ws:";
|
|
3372
|
+
const ws = new WebSocket(`${scheme}//${location.host}${TERMINAL_SOCKET_ROUTE}`);
|
|
3373
|
+
ws.binaryType = "arraybuffer";
|
|
3374
|
+
return ws;
|
|
3375
|
+
}
|
|
3376
|
+
/** Sends `message` as JSON only while the socket is open; reports whether it went out. */
|
|
3377
|
+
function sendMessage(ws, message) {
|
|
3378
|
+
if (ws?.readyState !== WebSocket.OPEN) return false;
|
|
3379
|
+
ws.send(JSON.stringify(message));
|
|
3380
|
+
return true;
|
|
3381
|
+
}
|
|
3382
|
+
/** A text frame's control message, or `null` when it is not JSON. */
|
|
3383
|
+
function parseMessage(data) {
|
|
3384
|
+
try {
|
|
3385
|
+
return JSON.parse(data);
|
|
3386
|
+
} catch {
|
|
3387
|
+
return null;
|
|
3388
|
+
}
|
|
3389
|
+
}
|
|
3390
|
+
// src/terminal/terminal-client.ts
|
|
3391
|
+
var MAX_ATTEMPTS = 8;
|
|
3392
|
+
var FIRST_DELAY = 2e3;
|
|
3393
|
+
function load(key) {
|
|
3394
|
+
try {
|
|
3395
|
+
return sessionStorage.getItem(key);
|
|
3396
|
+
} catch {
|
|
3397
|
+
return null;
|
|
3398
|
+
}
|
|
3399
|
+
}
|
|
3400
|
+
function store(key, value) {
|
|
3401
|
+
try {
|
|
3402
|
+
if (value === null) sessionStorage.removeItem(key);
|
|
3403
|
+
else sessionStorage.setItem(key, value);
|
|
3404
|
+
} catch {}
|
|
3405
|
+
}
|
|
3406
|
+
/** The session this tab views, kept across reloads so it reattaches. */
|
|
3407
|
+
function storedSession() {
|
|
3408
|
+
return load(TERMINAL_SESSION_KEY);
|
|
3409
|
+
}
|
|
3410
|
+
/** The tab id lives in `sessionStorage`, so a reload keeps it and a new tab gets its own. */
|
|
3411
|
+
function tabId() {
|
|
3412
|
+
let id = load(TERMINAL_TAB_KEY);
|
|
3413
|
+
if (!id) {
|
|
3414
|
+
id = globalThis.crypto?.randomUUID?.() ?? String(Math.random()).slice(2);
|
|
3415
|
+
store(TERMINAL_TAB_KEY, id);
|
|
3416
|
+
}
|
|
3417
|
+
return id;
|
|
3418
|
+
}
|
|
3419
|
+
/**
|
|
3420
|
+
* Drives the sidebar's wterm view over the terminal WebSocket: start, attach, take over,
|
|
3421
|
+
* reconnect with backoff, and a full reset before each replay. A taken-over tab never
|
|
3422
|
+
* reconnects on its own. Created once per mount; data updates never touch it.
|
|
3423
|
+
*/
|
|
3424
|
+
var TerminalClient = class {
|
|
3425
|
+
mount;
|
|
3426
|
+
companion;
|
|
3427
|
+
events;
|
|
3428
|
+
term;
|
|
3429
|
+
tab = tabId();
|
|
3430
|
+
ws = null;
|
|
3431
|
+
attempts = 0;
|
|
3432
|
+
takenOver = false;
|
|
3433
|
+
pending = null;
|
|
3434
|
+
opened = false;
|
|
3435
|
+
initialized = false;
|
|
3436
|
+
frame = 0;
|
|
3437
|
+
queued = [];
|
|
3438
|
+
sent;
|
|
3439
|
+
resize;
|
|
3440
|
+
retry = null;
|
|
3441
|
+
destroyed = false;
|
|
3442
|
+
constructor(mount, WTerm, companion, events) {
|
|
3443
|
+
this.mount = mount;
|
|
3444
|
+
this.companion = companion;
|
|
3445
|
+
this.events = events;
|
|
3446
|
+
this.term = new WTerm(mount, {
|
|
3447
|
+
cursorBlink: true,
|
|
3448
|
+
autoResize: false,
|
|
3449
|
+
wasmUrl: TERMINAL_WASM,
|
|
3450
|
+
onClipboardWrite: (text) => void navigator.clipboard?.writeText(text).catch(() => {})
|
|
3451
|
+
});
|
|
3452
|
+
this.sent = {
|
|
3453
|
+
cols: this.term.cols,
|
|
3454
|
+
rows: this.term.rows
|
|
3455
|
+
};
|
|
3456
|
+
this.term.onData = (data) => void this.send({
|
|
3457
|
+
type: "input",
|
|
3458
|
+
data
|
|
3459
|
+
});
|
|
3460
|
+
this.term.onResize = () => this.sendSize();
|
|
3461
|
+
if (storedSession()) events.viewing("pending");
|
|
3462
|
+
this.resize = new ResizeObserver(() => this.scheduleFit());
|
|
3463
|
+
this.resize.observe(mount);
|
|
3464
|
+
this.fitNow();
|
|
3465
|
+
this.connect();
|
|
3466
|
+
}
|
|
3467
|
+
write(data) {
|
|
3468
|
+
if (this.initialized) this.term.write(data);
|
|
3469
|
+
else this.queued.push(data);
|
|
3470
|
+
}
|
|
3471
|
+
/**
|
|
3472
|
+
* wterm measures its cells on init, so a sidebar collapsed at load starts it only once the
|
|
3473
|
+
* area is visible. A zero size never fits: it would send a resize the server rejects.
|
|
3474
|
+
*/
|
|
3475
|
+
fitNow() {
|
|
3476
|
+
this.frame = 0;
|
|
3477
|
+
if (!this.mount.clientWidth || !this.mount.clientHeight) return;
|
|
3478
|
+
if (this.initialized) {
|
|
3479
|
+
this.term.fit();
|
|
3480
|
+
return;
|
|
3481
|
+
}
|
|
3482
|
+
if (this.opened) return;
|
|
3483
|
+
this.opened = true;
|
|
3484
|
+
this.term.init().then(() => {
|
|
3485
|
+
if (this.destroyed) return;
|
|
3486
|
+
this.initialized = true;
|
|
3487
|
+
this.term.fit();
|
|
3488
|
+
for (const data of this.queued) this.term.write(data);
|
|
3489
|
+
this.queued = [];
|
|
3490
|
+
if (this.pending || this.ws) this.sendSize();
|
|
3491
|
+
}).catch(() => {
|
|
3492
|
+
this.opened = false;
|
|
3493
|
+
this.events.state("detached");
|
|
3494
|
+
this.events.status("The terminal could not start in this browser.");
|
|
3495
|
+
this.events.reconnectable(true);
|
|
3496
|
+
});
|
|
3497
|
+
}
|
|
3498
|
+
scheduleFit() {
|
|
3499
|
+
if (!this.frame) this.frame = requestAnimationFrame(() => this.fitNow());
|
|
3500
|
+
}
|
|
3501
|
+
send(message) {
|
|
3502
|
+
return sendMessage(this.ws, message);
|
|
3503
|
+
}
|
|
3504
|
+
sendOrQueue(message) {
|
|
3505
|
+
if (!this.send(message)) {
|
|
3506
|
+
this.pending = message;
|
|
3507
|
+
this.connect();
|
|
3508
|
+
}
|
|
3509
|
+
}
|
|
3510
|
+
sendSize() {
|
|
3511
|
+
const { cols, rows } = this.term;
|
|
3512
|
+
if (cols === this.sent.cols && rows === this.sent.rows) return;
|
|
3513
|
+
this.sent = {
|
|
3514
|
+
cols,
|
|
3515
|
+
rows
|
|
3516
|
+
};
|
|
3517
|
+
this.send({
|
|
3518
|
+
type: "resize",
|
|
3519
|
+
cols,
|
|
3520
|
+
rows
|
|
3521
|
+
});
|
|
3522
|
+
}
|
|
3523
|
+
connect() {
|
|
3524
|
+
if (this.destroyed || this.ws && this.ws.readyState <= WebSocket.OPEN) return;
|
|
3525
|
+
this.takenOver = false;
|
|
3526
|
+
this.events.reconnectable(false);
|
|
3527
|
+
const ws = openTerminalSocket();
|
|
3528
|
+
this.ws = ws;
|
|
3529
|
+
ws.onopen = () => {
|
|
3530
|
+
this.attempts = 0;
|
|
3531
|
+
this.events.state("connected");
|
|
3532
|
+
this.events.status("Connected.");
|
|
3533
|
+
if (this.pending) {
|
|
3534
|
+
ws.send(JSON.stringify(this.pending));
|
|
3535
|
+
this.pending = null;
|
|
3536
|
+
} else {
|
|
3537
|
+
const session = storedSession();
|
|
3538
|
+
if (session) this.attach(session);
|
|
3539
|
+
}
|
|
3540
|
+
};
|
|
3541
|
+
ws.onmessage = (event) => this.receive(event.data);
|
|
3542
|
+
ws.onclose = () => {
|
|
3543
|
+
this.ws = null;
|
|
3544
|
+
if (this.takenOver || this.destroyed) return;
|
|
3545
|
+
if (this.attempts >= MAX_ATTEMPTS) {
|
|
3546
|
+
this.events.state("detached");
|
|
3547
|
+
this.events.status("Disconnected.");
|
|
3548
|
+
this.events.reconnectable(true);
|
|
3549
|
+
return;
|
|
3550
|
+
}
|
|
3551
|
+
const delay = FIRST_DELAY * 2 ** this.attempts;
|
|
3552
|
+
this.attempts += 1;
|
|
3553
|
+
this.events.state("reconnecting");
|
|
3554
|
+
this.events.status(`Reconnecting (attempt ${this.attempts} of ${MAX_ATTEMPTS})…`);
|
|
3555
|
+
this.retry = setTimeout(() => this.connect(), delay);
|
|
3556
|
+
};
|
|
3557
|
+
}
|
|
3558
|
+
receive(data) {
|
|
3559
|
+
if (typeof data !== "string") {
|
|
3560
|
+
this.write(new Uint8Array(data));
|
|
3561
|
+
return;
|
|
3562
|
+
}
|
|
3563
|
+
const message = parseMessage(data);
|
|
3564
|
+
if (!message) return;
|
|
3565
|
+
const { events } = this;
|
|
3566
|
+
const lost = (text) => {
|
|
3567
|
+
store(TERMINAL_SESSION_KEY, null);
|
|
3568
|
+
events.viewing(null);
|
|
3569
|
+
events.state("detached");
|
|
3570
|
+
events.status(text);
|
|
3571
|
+
};
|
|
3572
|
+
if (message.type === "ready") {
|
|
3573
|
+
store(TERMINAL_SESSION_KEY, String(message.sessionId));
|
|
3574
|
+
events.viewing(String(message.agent));
|
|
3575
|
+
this.write("\x1Bc");
|
|
3576
|
+
events.state("connected");
|
|
3577
|
+
events.status(message.workset ? `Connected to Workset ${message.workset.id}.` : `Connected to ${String(message.agent)} in ${String(message.companionPath)}.`);
|
|
3578
|
+
if (this.initialized) this.term.focus();
|
|
3579
|
+
} else if (message.type === "exit") lost(`The agent exited with status ${String(message.status)}.`);
|
|
3580
|
+
else if (message.type === "ended") lost(`The session ended${message.reason ? `: ${String(message.reason)}` : ""}.`);
|
|
3581
|
+
else if (message.type === "detached") {
|
|
3582
|
+
events.viewing(null);
|
|
3583
|
+
events.state("detached");
|
|
3584
|
+
events.status(`Detached (${String(message.reason)}); the agent keeps running.`);
|
|
3585
|
+
} else if (message.type === "takenOver") {
|
|
3586
|
+
events.viewing(null);
|
|
3587
|
+
this.takenOver = true;
|
|
3588
|
+
events.state("detached");
|
|
3589
|
+
events.status("Another tab took over this session.");
|
|
3590
|
+
events.reconnectable(true);
|
|
3591
|
+
} else if (message.type === "gone") lost("That session no longer exists.");
|
|
3592
|
+
else if (message.type === "error") events.status(String(message.reason));
|
|
3593
|
+
events.changed();
|
|
3594
|
+
}
|
|
3595
|
+
size() {
|
|
3596
|
+
return {
|
|
3597
|
+
tabId: this.tab,
|
|
3598
|
+
cols: this.term.cols,
|
|
3599
|
+
rows: this.term.rows
|
|
3600
|
+
};
|
|
3601
|
+
}
|
|
3602
|
+
/** `task` carries a registered action and subject; the server builds the prompt from them. */
|
|
3603
|
+
start(agent, task) {
|
|
3604
|
+
this.sendOrQueue({
|
|
3605
|
+
type: "start",
|
|
3606
|
+
agent,
|
|
3607
|
+
companion: this.companion,
|
|
3608
|
+
...this.size(),
|
|
3609
|
+
...task
|
|
3610
|
+
});
|
|
3611
|
+
}
|
|
3612
|
+
/** A Factory Outcome names only its Workset; the server resolves everything else. */
|
|
3613
|
+
startWorkset(workset) {
|
|
3614
|
+
this.sendOrQueue({
|
|
3615
|
+
type: "start",
|
|
3616
|
+
workset,
|
|
3617
|
+
companion: this.companion,
|
|
3618
|
+
...this.size()
|
|
3619
|
+
});
|
|
3620
|
+
}
|
|
3621
|
+
attach(sessionId) {
|
|
3622
|
+
this.sendOrQueue({
|
|
3623
|
+
type: "attach",
|
|
3624
|
+
sessionId,
|
|
3625
|
+
...this.size()
|
|
3626
|
+
});
|
|
3627
|
+
}
|
|
3628
|
+
reconnect() {
|
|
3629
|
+
this.attempts = 0;
|
|
3630
|
+
if (!this.initialized) this.fitNow();
|
|
3631
|
+
this.connect();
|
|
3632
|
+
}
|
|
3633
|
+
/** Detaches only: the session keeps running for its detach window. */
|
|
3634
|
+
destroy() {
|
|
3635
|
+
this.destroyed = true;
|
|
3636
|
+
if (this.retry) clearTimeout(this.retry);
|
|
3637
|
+
if (this.frame) cancelAnimationFrame(this.frame);
|
|
3638
|
+
this.resize.disconnect();
|
|
3639
|
+
this.ws?.close();
|
|
3640
|
+
this.ws = null;
|
|
3641
|
+
this.term.destroy();
|
|
3642
|
+
}
|
|
3643
|
+
};
|
|
3644
|
+
// src/terminal/wterm.ts
|
|
3645
|
+
var loading = null;
|
|
3646
|
+
/**
|
|
3647
|
+
* Loads the terminal, bundled as its own chunk with its stylesheet, only when a terminal is first
|
|
3648
|
+
* shown. The WASM core is served by Studio itself (`TERMINAL_WASM`), matching the installed version.
|
|
3649
|
+
*/
|
|
3650
|
+
function loadWTerm() {
|
|
3651
|
+
loading ??= Promise.all([import("./dist-DpJWKyCm.js"), Promise.resolve({ })]).then(([module]) => module.WTerm).catch((error) => {
|
|
3652
|
+
loading = null;
|
|
3653
|
+
throw error;
|
|
3654
|
+
});
|
|
3655
|
+
return loading;
|
|
3656
|
+
}
|
|
3657
|
+
// src/terminal/terminal-sidebar.tsx
|
|
3658
|
+
var AGENT_LABELS = {
|
|
3659
|
+
claude: "Claude Code",
|
|
3660
|
+
opencode: "OpenCode"
|
|
3661
|
+
};
|
|
3662
|
+
var sessionsKey = ["terminal-sessions"];
|
|
3663
|
+
function age(seconds) {
|
|
3664
|
+
if (seconds < 60) return `${seconds} s`;
|
|
3665
|
+
if (seconds < 3600) return `${Math.floor(seconds / 60)} min`;
|
|
3666
|
+
return `${Math.floor(seconds / 3600)} h`;
|
|
3667
|
+
}
|
|
3668
|
+
/** Where a listed session is viewed, as seen from this tab. */
|
|
3669
|
+
function viewedFrom(session, mine) {
|
|
3670
|
+
if (session.id === mine) return "this tab";
|
|
3671
|
+
return session.attached ? "attached elsewhere" : "detached";
|
|
3672
|
+
}
|
|
3673
|
+
function closeDrawer(setDrawerOpen) {
|
|
3674
|
+
setDrawerOpen(false);
|
|
3675
|
+
document.getElementById("terminal-drawer-open")?.focus();
|
|
3676
|
+
}
|
|
3677
|
+
/** Every running session, polled, and ending one. */
|
|
3678
|
+
function useTerminalSessions() {
|
|
3679
|
+
const queryClient = useQueryClient();
|
|
3680
|
+
const sessions = useQuery({
|
|
3681
|
+
queryKey: sessionsKey,
|
|
3682
|
+
queryFn: async () => {
|
|
3683
|
+
const response = await fetch(TERMINAL_SESSIONS_ROUTE, { credentials: "same-origin" });
|
|
3684
|
+
return response.ok ? (await response.json()).sessions : [];
|
|
3685
|
+
},
|
|
3686
|
+
refetchInterval: 5e3
|
|
3687
|
+
});
|
|
3688
|
+
const end = useMutation({
|
|
3689
|
+
mutationFn: (id) => fetch(TERMINAL_SESSIONS_END_ROUTE, {
|
|
3690
|
+
method: "POST",
|
|
3691
|
+
headers: { "content-type": "application/json" },
|
|
3692
|
+
body: JSON.stringify({ id })
|
|
3693
|
+
}),
|
|
3694
|
+
onSettled: () => queryClient.invalidateQueries({ queryKey: sessionsKey })
|
|
3695
|
+
});
|
|
3696
|
+
return {
|
|
3697
|
+
sessions: sessions.data,
|
|
3698
|
+
end: (id) => end.mutate(id)
|
|
3699
|
+
};
|
|
3700
|
+
}
|
|
3701
|
+
/**
|
|
3702
|
+
* The sidebar's terminal client for `companion`, and the controller other views reach it
|
|
3703
|
+
* through while the sidebar is mounted.
|
|
3704
|
+
*/
|
|
3705
|
+
function useTerminalClient(mount, companion) {
|
|
3706
|
+
const client = (0, import_react.useRef)(null);
|
|
3707
|
+
const [state, setState] = (0, import_react.useState)("reconnecting");
|
|
3708
|
+
const [status, setStatus] = (0, import_react.useState)("Connecting…");
|
|
3709
|
+
const [reconnectable, setReconnectable] = (0, import_react.useState)(false);
|
|
3710
|
+
const [choice, setChoice] = (0, import_react.useState)(null);
|
|
3711
|
+
const queryClient = useQueryClient();
|
|
3712
|
+
(0, import_react.useEffect)(() => {
|
|
3713
|
+
useTerminalUi.setState({ collapsed: document.documentElement.hasAttribute("data-terminal-collapsed") });
|
|
3714
|
+
}, []);
|
|
3715
|
+
(0, import_react.useEffect)(() => {
|
|
3716
|
+
let cancelled = false;
|
|
3717
|
+
const setViewing = useTerminalUi.getState().setViewing;
|
|
3718
|
+
loadWTerm().then((WTerm) => {
|
|
3719
|
+
if (cancelled || !mount.current) return;
|
|
3720
|
+
client.current = new TerminalClient(mount.current, WTerm, companion, {
|
|
3721
|
+
state: setState,
|
|
3722
|
+
status: setStatus,
|
|
3723
|
+
reconnectable: setReconnectable,
|
|
3724
|
+
viewing: (agent) => {
|
|
3725
|
+
setViewing(agent);
|
|
3726
|
+
if (agent) setChoice(null);
|
|
3727
|
+
},
|
|
3728
|
+
changed: () => void queryClient.invalidateQueries({ queryKey: sessionsKey })
|
|
3729
|
+
});
|
|
3730
|
+
}, () => {
|
|
3731
|
+
setState("detached");
|
|
3732
|
+
setStatus("The terminal could not start in this browser.");
|
|
3733
|
+
setReconnectable(true);
|
|
3734
|
+
});
|
|
3735
|
+
return () => {
|
|
3736
|
+
cancelled = true;
|
|
3737
|
+
client.current?.destroy();
|
|
3738
|
+
client.current = null;
|
|
3739
|
+
setViewing(null);
|
|
3740
|
+
};
|
|
3741
|
+
}, [
|
|
3742
|
+
mount,
|
|
3743
|
+
companion,
|
|
3744
|
+
queryClient
|
|
3745
|
+
]);
|
|
3746
|
+
(0, import_react.useEffect)(() => {
|
|
3747
|
+
const busy = () => {
|
|
3748
|
+
if (!useTerminalUi.getState().viewing) return false;
|
|
3749
|
+
setStatus("End the current session first.");
|
|
3750
|
+
return true;
|
|
3751
|
+
};
|
|
3752
|
+
useTerminalUi.getState().register({
|
|
3753
|
+
startWorkset: (id) => {
|
|
3754
|
+
useTerminalUi.getState().reveal();
|
|
3755
|
+
if (!busy()) client.current?.startWorkset(id);
|
|
3756
|
+
},
|
|
3757
|
+
attach: (sessionId) => {
|
|
3758
|
+
useTerminalUi.getState().reveal();
|
|
3759
|
+
client.current?.attach(sessionId);
|
|
3760
|
+
},
|
|
3761
|
+
runAction: (task) => {
|
|
3762
|
+
const agents = task.agents.filter((agent) => AGENT_LABELS[agent]);
|
|
3763
|
+
if (agents.length === 0) return;
|
|
3764
|
+
useTerminalUi.getState().reveal();
|
|
3765
|
+
if (busy()) return;
|
|
3766
|
+
if (agents.length === 1) client.current?.start(agents[0], task);
|
|
3767
|
+
else setChoice({
|
|
3768
|
+
...task,
|
|
3769
|
+
agents
|
|
3770
|
+
});
|
|
3771
|
+
}
|
|
3772
|
+
});
|
|
3773
|
+
return () => useTerminalUi.getState().register(null);
|
|
3774
|
+
}, []);
|
|
3775
|
+
return {
|
|
3776
|
+
client,
|
|
3777
|
+
state,
|
|
3778
|
+
status,
|
|
3779
|
+
reconnectable,
|
|
3780
|
+
choice,
|
|
3781
|
+
setChoice
|
|
3782
|
+
};
|
|
3783
|
+
}
|
|
3784
|
+
/**
|
|
3785
|
+
* A direct grid child of `.shell`: sticky positioning breaks under an ancestor that sets
|
|
3786
|
+
* `overflow`. Lives in the root layout, so its session survives navigation between views.
|
|
3787
|
+
*/
|
|
3788
|
+
function TerminalSidebar({ terminal }) {
|
|
3789
|
+
const target = terminal.target;
|
|
3790
|
+
const mount = (0, import_react.useRef)(null);
|
|
3791
|
+
const { client, state, status, reconnectable, choice, setChoice } = useTerminalClient(mount, target?.digest ?? "");
|
|
3792
|
+
const { sessions, end } = useTerminalSessions();
|
|
3793
|
+
const ui = useTerminalUi();
|
|
3794
|
+
(0, import_react.useEffect)(() => {
|
|
3795
|
+
if (!ui.drawerOpen) return;
|
|
3796
|
+
const close = (event) => {
|
|
3797
|
+
if (event.key === "Escape") closeDrawer(ui.setDrawerOpen);
|
|
3798
|
+
};
|
|
3799
|
+
document.addEventListener("keydown", close);
|
|
3800
|
+
return () => document.removeEventListener("keydown", close);
|
|
3801
|
+
}, [ui]);
|
|
3802
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("aside", {
|
|
3803
|
+
className: "terminal-sidebar",
|
|
3804
|
+
id: "studio-terminal-panel",
|
|
3805
|
+
"aria-label": "Agent terminal",
|
|
3806
|
+
"data-terminal-companion": target?.digest,
|
|
3807
|
+
"data-terminal-state": state,
|
|
3808
|
+
"data-drawer-open": ui.drawerOpen ? "" : void 0,
|
|
3809
|
+
children: [
|
|
3810
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ResizeHandle, {}),
|
|
3811
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
3812
|
+
className: "terminal-strip",
|
|
3813
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
3814
|
+
type: "button",
|
|
3815
|
+
className: "terminal-icon-button",
|
|
3816
|
+
id: "terminal-expand",
|
|
3817
|
+
"aria-controls": "terminal-body",
|
|
3818
|
+
"aria-expanded": !ui.collapsed,
|
|
3819
|
+
"aria-label": "Expand the terminal",
|
|
3820
|
+
onClick: () => ui.setCollapsed(false),
|
|
3821
|
+
children: "‹"
|
|
3822
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
3823
|
+
className: "terminal-dot",
|
|
3824
|
+
"aria-hidden": "true"
|
|
3825
|
+
})]
|
|
3826
|
+
}),
|
|
3827
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
3828
|
+
className: "terminal-body",
|
|
3829
|
+
id: "terminal-body",
|
|
3830
|
+
children: [
|
|
3831
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("header", {
|
|
3832
|
+
className: "terminal-head",
|
|
3833
|
+
children: [
|
|
3834
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
3835
|
+
className: "terminal-title",
|
|
3836
|
+
children: [
|
|
3837
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
3838
|
+
className: "terminal-dot",
|
|
3839
|
+
"aria-hidden": "true"
|
|
3840
|
+
}),
|
|
3841
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { children: "Agent terminal" }),
|
|
3842
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
3843
|
+
type: "button",
|
|
3844
|
+
className: "terminal-icon-button",
|
|
3845
|
+
id: "terminal-collapse",
|
|
3846
|
+
"aria-controls": "terminal-body",
|
|
3847
|
+
"aria-expanded": !ui.collapsed,
|
|
3848
|
+
"aria-label": "Collapse the terminal",
|
|
3849
|
+
onClick: () => ui.setCollapsed(true),
|
|
3850
|
+
children: "›"
|
|
3851
|
+
}),
|
|
3852
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
3853
|
+
type: "button",
|
|
3854
|
+
className: "terminal-icon-button",
|
|
3855
|
+
id: "terminal-drawer-close",
|
|
3856
|
+
"aria-label": "Close the terminal",
|
|
3857
|
+
onClick: () => closeDrawer(ui.setDrawerOpen),
|
|
3858
|
+
children: "×"
|
|
3859
|
+
})
|
|
3860
|
+
]
|
|
3861
|
+
}),
|
|
3862
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
|
|
3863
|
+
className: "terminal-target",
|
|
3864
|
+
children: target ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
3865
|
+
"Launches against ",
|
|
3866
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { children: target.path }),
|
|
3867
|
+
terminal.pinned ? " (fixed when Studio started)" : null
|
|
3868
|
+
] }) : "Select a registered companion to launch an agent."
|
|
3869
|
+
}),
|
|
3870
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
3871
|
+
className: "terminal-actions",
|
|
3872
|
+
children: [target ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StartButtons, {
|
|
3873
|
+
agents: terminal.agents,
|
|
3874
|
+
onStart: (agent) => client.current?.start(agent)
|
|
3875
|
+
}) : null, /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
3876
|
+
type: "button",
|
|
3877
|
+
className: "button",
|
|
3878
|
+
id: "terminal-reconnect",
|
|
3879
|
+
hidden: !reconnectable,
|
|
3880
|
+
onClick: () => client.current?.reconnect(),
|
|
3881
|
+
children: "Reconnect"
|
|
3882
|
+
})]
|
|
3883
|
+
}),
|
|
3884
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
3885
|
+
className: "terminal-choice",
|
|
3886
|
+
id: "terminal-action-choice",
|
|
3887
|
+
role: "group",
|
|
3888
|
+
"aria-label": "Choose an agent",
|
|
3889
|
+
hidden: !choice,
|
|
3890
|
+
children: choice ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
3891
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
|
|
3892
|
+
"Run ",
|
|
3893
|
+
choice.action,
|
|
3894
|
+
" with:"
|
|
3895
|
+
] }),
|
|
3896
|
+
choice.agents.map((agent) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
3897
|
+
type: "button",
|
|
3898
|
+
className: "button",
|
|
3899
|
+
onClick: () => {
|
|
3900
|
+
setChoice(null);
|
|
3901
|
+
client.current?.start(agent, choice);
|
|
3902
|
+
},
|
|
3903
|
+
children: AGENT_LABELS[agent]
|
|
3904
|
+
}, agent)),
|
|
3905
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
3906
|
+
type: "button",
|
|
3907
|
+
className: "button",
|
|
3908
|
+
onClick: () => setChoice(null),
|
|
3909
|
+
children: "Cancel"
|
|
3910
|
+
})
|
|
3911
|
+
] }) : null
|
|
3912
|
+
}),
|
|
3913
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
|
|
3914
|
+
className: "terminal-status",
|
|
3915
|
+
id: "terminal-status",
|
|
3916
|
+
role: "status",
|
|
3917
|
+
children: status
|
|
3918
|
+
})
|
|
3919
|
+
]
|
|
3920
|
+
}),
|
|
3921
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
3922
|
+
className: "terminal-view",
|
|
3923
|
+
id: "studio-terminal",
|
|
3924
|
+
ref: mount
|
|
3925
|
+
}),
|
|
3926
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("footer", {
|
|
3927
|
+
className: "terminal-sessions-footer",
|
|
3928
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", {
|
|
3929
|
+
className: "terminal-sessions-title",
|
|
3930
|
+
children: "Sessions"
|
|
3931
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SessionList, {
|
|
3932
|
+
sessions,
|
|
3933
|
+
onAttach: (id) => client.current?.attach(id),
|
|
3934
|
+
onEnd: end
|
|
3935
|
+
})]
|
|
3936
|
+
})
|
|
3937
|
+
]
|
|
3938
|
+
})
|
|
3939
|
+
]
|
|
3940
|
+
});
|
|
3941
|
+
}
|
|
3942
|
+
function StartButtons({ agents, onStart }) {
|
|
3943
|
+
if (agents.length === 0) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
3944
|
+
className: "empty",
|
|
3945
|
+
children: "No agent this companion allows is installed."
|
|
3946
|
+
});
|
|
3947
|
+
return agents.map((agent) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
|
|
3948
|
+
type: "button",
|
|
3949
|
+
className: "button",
|
|
3950
|
+
"data-terminal-start": agent,
|
|
3951
|
+
onClick: () => onStart(agent),
|
|
3952
|
+
children: ["Start ", AGENT_LABELS[agent]]
|
|
3953
|
+
}, agent));
|
|
3954
|
+
}
|
|
3955
|
+
/** Running sessions; this tab's own offers no attach. */
|
|
3956
|
+
function SessionList({ sessions, onAttach, onEnd }) {
|
|
3957
|
+
const mine = storedSession();
|
|
3958
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("ul", {
|
|
3959
|
+
className: "terminal-sessions",
|
|
3960
|
+
id: "terminal-sessions",
|
|
3961
|
+
children: [sessions && sessions.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", {
|
|
3962
|
+
className: "empty",
|
|
3963
|
+
children: "No sessions are running."
|
|
3964
|
+
}) : null, sessions?.map((session) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { children: [
|
|
3965
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [session.workset ? `Workset ${session.workset.id} (${session.workset.title})` : `${session.agent} · ${session.companionPath}`, ` · ${viewedFrom(session, mine)} · ${age(session.ageSeconds)}`] }),
|
|
3966
|
+
session.id !== mine ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
3967
|
+
type: "button",
|
|
3968
|
+
className: "button",
|
|
3969
|
+
onClick: () => onAttach(session.id),
|
|
3970
|
+
children: session.attached ? "Take over" : "Attach"
|
|
3971
|
+
}) : null,
|
|
3972
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
3973
|
+
type: "button",
|
|
3974
|
+
className: "button",
|
|
3975
|
+
onClick: () => onEnd(session.id),
|
|
3976
|
+
children: "End"
|
|
3977
|
+
})
|
|
3978
|
+
] }, session.id))]
|
|
3979
|
+
});
|
|
3980
|
+
}
|
|
3981
|
+
/** Drag to resize; the width is remembered once the drag ends. */
|
|
3982
|
+
function ResizeHandle() {
|
|
3983
|
+
const setWidth = useTerminalUi((state) => state.setWidth);
|
|
3984
|
+
const width = (0, import_react.useRef)(0);
|
|
3985
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
3986
|
+
className: "terminal-resize",
|
|
3987
|
+
id: "terminal-resize",
|
|
3988
|
+
role: "separator",
|
|
3989
|
+
"aria-orientation": "vertical",
|
|
3990
|
+
"aria-label": "Resize the terminal",
|
|
3991
|
+
onPointerDown: (event) => {
|
|
3992
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
3993
|
+
event.preventDefault();
|
|
3994
|
+
},
|
|
3995
|
+
onPointerMove: (event) => {
|
|
3996
|
+
if (!event.currentTarget.hasPointerCapture(event.pointerId)) return;
|
|
3997
|
+
width.current = window.innerWidth - event.clientX;
|
|
3998
|
+
setWidth(width.current, false);
|
|
3999
|
+
},
|
|
4000
|
+
onPointerUp: (event) => {
|
|
4001
|
+
if (event.currentTarget.hasPointerCapture(event.pointerId)) event.currentTarget.releasePointerCapture(event.pointerId);
|
|
4002
|
+
if (width.current > 0) setWidth(width.current, true);
|
|
4003
|
+
},
|
|
4004
|
+
onPointerCancel: () => {
|
|
4005
|
+
if (width.current > 0) setWidth(width.current, true);
|
|
4006
|
+
}
|
|
4007
|
+
});
|
|
4008
|
+
}
|
|
4009
|
+
/** Outside `.shell`, so it never takes a grid cell; shown only below the side-by-side breakpoint. */
|
|
4010
|
+
function TerminalDrawerButton() {
|
|
4011
|
+
const drawerOpen = useTerminalUi((state) => state.drawerOpen);
|
|
4012
|
+
const setDrawerOpen = useTerminalUi((state) => state.setDrawerOpen);
|
|
4013
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
|
|
4014
|
+
type: "button",
|
|
4015
|
+
className: "terminal-drawer-open",
|
|
4016
|
+
id: "terminal-drawer-open",
|
|
4017
|
+
"aria-controls": "studio-terminal-panel",
|
|
4018
|
+
"aria-expanded": drawerOpen,
|
|
4019
|
+
onClick: () => {
|
|
4020
|
+
setDrawerOpen(true);
|
|
4021
|
+
requestAnimationFrame(() => document.getElementById("terminal-drawer-close")?.focus());
|
|
4022
|
+
},
|
|
4023
|
+
children: "Terminal"
|
|
4024
|
+
});
|
|
4025
|
+
}
|
|
4026
|
+
// src/shell/layout.tsx
|
|
4027
|
+
/** The sidebar and page header around every view; the view comes from the matched route. */
|
|
4028
|
+
function StudioLayout({ search }) {
|
|
4029
|
+
const { data: shell } = useSuspenseQuery(shellQuery(search));
|
|
4030
|
+
const view = useMatches({ select: (matches) => matches.findLast((match) => match.staticData.view)?.staticData.view }) ?? "dashboard";
|
|
4031
|
+
const digest = shell.selected?.digest;
|
|
4032
|
+
useStudioEvents(digest);
|
|
4033
|
+
useStudioClicks();
|
|
4034
|
+
usePrefetchViews(shell.selected ? search : {}, shell.studioMode, view);
|
|
4035
|
+
(0, import_react.useEffect)(() => {
|
|
4036
|
+
if (!digest) return;
|
|
4037
|
+
try {
|
|
4038
|
+
localStorage.setItem(COMPANION_STORAGE_KEY, digest);
|
|
4039
|
+
} catch {}
|
|
4040
|
+
}, [digest]);
|
|
4041
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
4042
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
4043
|
+
className: "shell",
|
|
4044
|
+
"data-companion": digest,
|
|
4045
|
+
"data-terminal": shell.terminal ? "" : void 0,
|
|
4046
|
+
children: [
|
|
4047
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(NavigationProgress, {}),
|
|
4048
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Sidebar, {
|
|
4049
|
+
shell,
|
|
4050
|
+
search,
|
|
4051
|
+
view
|
|
4052
|
+
}),
|
|
4053
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("main", {
|
|
4054
|
+
className: "main",
|
|
4055
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(PageHeader, {
|
|
4056
|
+
shell,
|
|
4057
|
+
view
|
|
4058
|
+
}), shell.selected ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Outlet, {}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CompanionPicker, { companions: shell.companions })]
|
|
4059
|
+
}),
|
|
4060
|
+
shell.terminal ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TerminalSidebar, { terminal: shell.terminal }) : null
|
|
4061
|
+
]
|
|
4062
|
+
}),
|
|
4063
|
+
shell.terminal ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TerminalDrawerButton, {}) : null,
|
|
4064
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Toasts, { search })
|
|
4065
|
+
] });
|
|
4066
|
+
}
|
|
4067
|
+
/** The copy confirmation, and a report published while another view is shown. */
|
|
4068
|
+
function Toasts({ search }) {
|
|
4069
|
+
const toast = usePageUi((state) => state.toast);
|
|
4070
|
+
const report = usePageUi((state) => state.report);
|
|
4071
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
4072
|
+
className: "toast",
|
|
4073
|
+
id: "studio-toast",
|
|
4074
|
+
"data-shown": toast ? "true" : "false",
|
|
4075
|
+
children: toast
|
|
4076
|
+
}), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
4077
|
+
className: "toast toast-report",
|
|
4078
|
+
id: "reports-toast",
|
|
4079
|
+
"data-shown": report ? "true" : "false",
|
|
4080
|
+
role: "status",
|
|
4081
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
|
|
4082
|
+
id: "reports-toast-title",
|
|
4083
|
+
children: report ? `New report: ${report.title}` : null
|
|
4084
|
+
}), report ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Link, {
|
|
4085
|
+
id: "reports-toast-open",
|
|
4086
|
+
to: "/reports",
|
|
4087
|
+
search,
|
|
4088
|
+
hash: `report=${report.id}`,
|
|
4089
|
+
children: "Open"
|
|
4090
|
+
}) : null]
|
|
4091
|
+
})] });
|
|
4092
|
+
}
|
|
4093
|
+
// src/routes/__root.tsx
|
|
4094
|
+
var FAVICON_URI = `data:image/svg+xml;base64,${btoa(BRAND_SVGS.favicon)}`;
|
|
4095
|
+
var Route$7 = createRootRouteWithContext()({
|
|
4096
|
+
validateSearch: validateStudioSearch,
|
|
4097
|
+
loaderDeps: ({ search }) => search,
|
|
4098
|
+
ssr: true,
|
|
4099
|
+
beforeLoad: async ({ context, search, location }) => {
|
|
4100
|
+
const shell = await loadHeld(context.queryClient, shellQuery(search));
|
|
4101
|
+
const href = canonicalHref(location.pathname, location.searchStr, viewAt(location.pathname), shell.studioMode);
|
|
4102
|
+
if (href) throw redirect({
|
|
4103
|
+
href,
|
|
4104
|
+
replace: true
|
|
4105
|
+
});
|
|
4106
|
+
},
|
|
4107
|
+
loader: ({ context, deps }) => loadHeld(context.queryClient, shellQuery(deps)),
|
|
4108
|
+
head: () => ({
|
|
4109
|
+
meta: [
|
|
4110
|
+
{ charSet: "utf-8" },
|
|
4111
|
+
{
|
|
4112
|
+
name: "viewport",
|
|
4113
|
+
content: "width=device-width, initial-scale=1"
|
|
4114
|
+
},
|
|
4115
|
+
{ title: "Mate Studio" }
|
|
4116
|
+
],
|
|
4117
|
+
links: [{
|
|
4118
|
+
rel: "icon",
|
|
4119
|
+
type: "image/svg+xml",
|
|
4120
|
+
href: FAVICON_URI
|
|
4121
|
+
}, {
|
|
4122
|
+
rel: "stylesheet",
|
|
4123
|
+
href: studio_default
|
|
4124
|
+
}],
|
|
4125
|
+
styles: [{ children: studioPaletteCss() }],
|
|
4126
|
+
scripts: [{ children: STUDIO_PREPAINT_SCRIPT }, { children: TERMINAL_PREPAINT_SCRIPT }]
|
|
4127
|
+
}),
|
|
4128
|
+
shellComponent: RootDocument,
|
|
4129
|
+
component: RootLayout
|
|
4130
|
+
});
|
|
4131
|
+
function RootLayout() {
|
|
4132
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StudioLayout, { search: Route$7.useSearch() });
|
|
4133
|
+
}
|
|
4134
|
+
function RootDocument({ children }) {
|
|
4135
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("html", {
|
|
4136
|
+
lang: "en",
|
|
4137
|
+
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("head", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(HeadContent, {}) }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("body", { children: [children, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Scripts, {})] })]
|
|
4138
|
+
});
|
|
4139
|
+
}
|
|
4140
|
+
// src/routes/index.tsx
|
|
4141
|
+
var $$splitComponentImporter$6 = () => import("./routes-khSDK1bV.js");
|
|
4142
|
+
var Route$6 = createFileRoute("/")({
|
|
4143
|
+
staticData: { view: "dashboard" },
|
|
4144
|
+
loaderDeps: ({ search }) => ({
|
|
4145
|
+
companion: search.companion,
|
|
4146
|
+
studioMode: search.studioMode
|
|
4147
|
+
}),
|
|
4148
|
+
loader: async ({ context, deps }) => await registeredCompanion(context.queryClient, deps) ? loadView(context.queryClient, companionViewQuery("dashboard", deps)) : null,
|
|
4149
|
+
component: lazyRouteComponent($$splitComponentImporter$6, "component")
|
|
4150
|
+
});
|
|
4151
|
+
/** Each mode reads its own Overview; the server's effective mode picks it, not the address. */
|
|
4152
|
+
// src/routes/factory.tsx
|
|
4153
|
+
var $$splitComponentImporter$5 = () => import("./factory-D6xnjedJ.js");
|
|
4154
|
+
var Route$5 = createFileRoute("/factory")({
|
|
4155
|
+
staticData: { view: "factory" },
|
|
4156
|
+
validateSearch: (raw) => typeof raw.outcome === "string" && /^[a-z0-9][a-z0-9-]*$/.test(raw.outcome) ? { outcome: raw.outcome } : {},
|
|
4157
|
+
beforeLoad: async ({ context, search }) => {
|
|
4158
|
+
const studioSearch = {
|
|
4159
|
+
companion: search.companion,
|
|
4160
|
+
studioMode: search.studioMode
|
|
4161
|
+
};
|
|
4162
|
+
if (!(await loadHeld(context.queryClient, shellQuery(studioSearch))).factoryMode) throw redirect({
|
|
4163
|
+
to: "/",
|
|
4164
|
+
search: studioSearch
|
|
4165
|
+
});
|
|
4166
|
+
},
|
|
4167
|
+
loaderDeps: ({ search }) => ({
|
|
4168
|
+
companion: search.companion,
|
|
4169
|
+
studioMode: search.studioMode
|
|
4170
|
+
}),
|
|
4171
|
+
loader: async ({ context, deps }) => {
|
|
4172
|
+
const companion = await registeredCompanion(context.queryClient, deps);
|
|
4173
|
+
return companion ? loadView(context.queryClient, factoryQuery(companion)) : null;
|
|
4174
|
+
},
|
|
4175
|
+
component: lazyRouteComponent($$splitComponentImporter$5, "component")
|
|
4176
|
+
});
|
|
4177
|
+
// src/routes/reports.tsx
|
|
4178
|
+
var $$splitComponentImporter$4 = () => import("./reports-BnUNJVtx.js");
|
|
4179
|
+
var Route$4 = createFileRoute("/reports")({
|
|
4180
|
+
staticData: { view: "reports" },
|
|
4181
|
+
component: lazyRouteComponent($$splitComponentImporter$4, "component")
|
|
4182
|
+
});
|
|
4183
|
+
// src/routes/skills.tsx
|
|
4184
|
+
var $$splitComponentImporter$3 = () => import("./skills-MWYnWoKs.js");
|
|
4185
|
+
var Route$3 = createFileRoute("/skills")({
|
|
4186
|
+
staticData: { view: "skills" },
|
|
4187
|
+
loaderDeps: ({ search }) => ({
|
|
4188
|
+
companion: search.companion,
|
|
4189
|
+
studioMode: search.studioMode
|
|
4190
|
+
}),
|
|
4191
|
+
loader: async ({ context, deps }) => await registeredCompanion(context.queryClient, deps) ? loadView(context.queryClient, companionViewQuery("skills", deps)) : null,
|
|
4192
|
+
component: lazyRouteComponent($$splitComponentImporter$3, "component")
|
|
4193
|
+
});
|
|
4194
|
+
// src/routes/specs.tsx
|
|
4195
|
+
var $$splitComponentImporter$2 = () => import("./specs-DE3w8hZP.js");
|
|
4196
|
+
var Route$2 = createFileRoute("/specs")({
|
|
4197
|
+
staticData: { view: "specs" },
|
|
4198
|
+
loaderDeps: ({ search }) => ({
|
|
4199
|
+
companion: search.companion,
|
|
4200
|
+
studioMode: search.studioMode
|
|
4201
|
+
}),
|
|
4202
|
+
loader: async ({ context, deps }) => await registeredCompanion(context.queryClient, deps) ? loadView(context.queryClient, companionViewQuery("specs", deps)) : null,
|
|
4203
|
+
component: lazyRouteComponent($$splitComponentImporter$2, "component")
|
|
4204
|
+
});
|
|
4205
|
+
// src/routes/vault.tsx
|
|
4206
|
+
var $$splitComponentImporter$1 = () => import("./vault-CuyyhLyB.js");
|
|
4207
|
+
var text = (value) => typeof value === "string" && value ? value : void 0;
|
|
4208
|
+
var Route$1 = createFileRoute("/vault")({
|
|
4209
|
+
staticData: { view: "vault" },
|
|
4210
|
+
validateSearch: (raw) => ({
|
|
4211
|
+
...text(raw.path) ? { path: text(raw.path) } : {},
|
|
4212
|
+
...text(raw.dir) ? { dir: text(raw.dir) } : {},
|
|
4213
|
+
...raw.mode === "edit" ? { mode: "edit" } : {}
|
|
4214
|
+
}),
|
|
4215
|
+
loaderDeps: ({ search }) => ({
|
|
4216
|
+
companion: search.companion,
|
|
4217
|
+
studioMode: search.studioMode,
|
|
4218
|
+
path: search.path,
|
|
4219
|
+
dir: search.dir
|
|
4220
|
+
}),
|
|
4221
|
+
loader: async ({ context, deps }) => {
|
|
4222
|
+
const companion = await registeredCompanion(context.queryClient, deps);
|
|
4223
|
+
return companion ? loadView(context.queryClient, vaultQuery(companion, deps)) : null;
|
|
4224
|
+
},
|
|
4225
|
+
component: lazyRouteComponent($$splitComponentImporter$1, "component")
|
|
4226
|
+
});
|
|
4227
|
+
// src/routes/workflow.tsx
|
|
4228
|
+
var $$splitComponentImporter = () => import("./workflow-BSuIKWqH.js");
|
|
4229
|
+
var Route = createFileRoute("/workflow")({
|
|
4230
|
+
staticData: { view: "workflow" },
|
|
4231
|
+
loaderDeps: ({ search }) => ({
|
|
4232
|
+
companion: search.companion,
|
|
4233
|
+
studioMode: search.studioMode
|
|
4234
|
+
}),
|
|
4235
|
+
loader: async ({ context, deps }) => await registeredCompanion(context.queryClient, deps) ? loadView(context.queryClient, companionViewQuery("workflow", deps)) : null,
|
|
4236
|
+
component: lazyRouteComponent($$splitComponentImporter, "component")
|
|
4237
|
+
});
|
|
4238
|
+
// src/route-tree.gen.ts
|
|
4239
|
+
var rootRouteChildren = {
|
|
4240
|
+
IndexRoute: Route$6.update({
|
|
4241
|
+
id: "/",
|
|
4242
|
+
path: "/",
|
|
4243
|
+
getParentRoute: () => Route$7
|
|
4244
|
+
}),
|
|
4245
|
+
FactoryRoute: Route$5.update({
|
|
4246
|
+
id: "/factory",
|
|
4247
|
+
path: "/factory",
|
|
4248
|
+
getParentRoute: () => Route$7
|
|
4249
|
+
}),
|
|
4250
|
+
ReportsRoute: Route$4.update({
|
|
4251
|
+
id: "/reports",
|
|
4252
|
+
path: "/reports",
|
|
4253
|
+
getParentRoute: () => Route$7
|
|
4254
|
+
}),
|
|
4255
|
+
SkillsRoute: Route$3.update({
|
|
4256
|
+
id: "/skills",
|
|
4257
|
+
path: "/skills",
|
|
4258
|
+
getParentRoute: () => Route$7
|
|
4259
|
+
}),
|
|
4260
|
+
SpecsRoute: Route$2.update({
|
|
4261
|
+
id: "/specs",
|
|
4262
|
+
path: "/specs",
|
|
4263
|
+
getParentRoute: () => Route$7
|
|
4264
|
+
}),
|
|
4265
|
+
VaultRoute: Route$1.update({
|
|
4266
|
+
id: "/vault",
|
|
4267
|
+
path: "/vault",
|
|
4268
|
+
getParentRoute: () => Route$7
|
|
4269
|
+
}),
|
|
4270
|
+
WorkflowRoute: Route.update({
|
|
4271
|
+
id: "/workflow",
|
|
4272
|
+
path: "/workflow",
|
|
4273
|
+
getParentRoute: () => Route$7
|
|
4274
|
+
})
|
|
4275
|
+
};
|
|
4276
|
+
var routeTree = Route$7._addFileChildren(rootRouteChildren)._addFileTypes();
|
|
4277
|
+
// src/router.tsx
|
|
4278
|
+
var router_exports = /* @__PURE__ */ __exportAll({ getRouter: () => getRouter });
|
|
4279
|
+
/** One router and query client per request on the server, one per page in the browser. */
|
|
4280
|
+
function getRouter() {
|
|
4281
|
+
const queryClient = new QueryClient({ defaultOptions: { queries: {
|
|
4282
|
+
staleTime: 5e3,
|
|
4283
|
+
gcTime: Infinity
|
|
4284
|
+
} } });
|
|
4285
|
+
const router = createRouter({
|
|
4286
|
+
routeTree,
|
|
4287
|
+
context: { queryClient },
|
|
4288
|
+
scrollRestoration: true,
|
|
4289
|
+
defaultPreload: "intent",
|
|
4290
|
+
defaultPendingComponent: ViewPlaceholder
|
|
4291
|
+
});
|
|
4292
|
+
setupRouterSsrQueryIntegration({
|
|
4293
|
+
router,
|
|
4294
|
+
queryClient
|
|
4295
|
+
});
|
|
4296
|
+
return router;
|
|
4297
|
+
}
|
|
4298
|
+
export { useMutation as _, Route$3 as a, Route$6 as c, parseMessage as d, sendMessage as f, usePageUi as g, getRouter, useVaultUi as h, Route$2 as i, loadWTerm as l, ViewPlaceholder as m, Route as n, Route$4 as o, useAppearance as p, Route$1 as r, Route$5 as s, router_exports as t, openTerminalSocket as u };
|