@helpra/design 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +106 -2
- package/README.ru.md +23 -0
- package/bin/helpra-design.mjs +12 -0
- package/design-system/helpra/tokens.json +1593 -0
- package/dist/embed/index.d.ts +9 -0
- package/dist/embed/index.js +94 -0
- package/dist/embed/types.d.ts +113 -0
- package/dist/embed/types.js +1 -0
- package/dist/ui/assets/browserHost-DO0VE7SS.js +1 -0
- package/dist/ui/assets/index-B0caw0Dc.js +82 -0
- package/dist/ui/assets/index-BpwlDiXE.css +1 -0
- package/dist/ui/assets/inter-cyrillic-wght-normal-BmJJXa8e.woff2 +0 -0
- package/dist/ui/assets/inter-latin-wght-normal-BgVq2Tq4.woff2 +0 -0
- package/dist/ui/assets/session.schemas-o3W88yfn.js +352 -0
- package/dist/ui/fonts/OFL.txt +93 -0
- package/dist/ui/index.html +14 -0
- package/docs/agent-workflow.md +28 -0
- package/docs/orca-integration.md +66 -0
- package/package.json +88 -4
- package/skills/README.md +25 -0
- package/skills/helpra-design/SKILL.md +23 -0
- package/skills/helpra-design/agents/openai.yaml +4 -0
- package/skills/helpra-design/references/button-change.md +14 -0
- package/skills/helpra-design/references/canvases-and-artboards.md +15 -0
- package/skills/helpra-design/references/capture-and-export.md +20 -0
- package/skills/helpra-design/references/comments-and-anchors.md +31 -0
- package/skills/helpra-design/references/designing-screens.md +79 -0
- package/skills/helpra-design/references/mcp-workflow.md +121 -0
- package/skills/helpra-design/references/project-format.md +17 -0
- package/skills/helpra-design/scripts/find_elements.py +77 -0
- package/skills/helpra-design/templates/artboard.json +23 -0
- package/skills/helpra-design/templates/canvas.json +9 -0
- package/skills/helpra-design/templates/page.json +11 -0
- package/skills/helpra-design-system/SKILL.md +35 -0
- package/skills/helpra-design-system/agents/openai.yaml +4 -0
- package/skills/helpra-design-system/references/component-contract.md +11 -0
- package/skills/helpra-design-system/references/coverage.md +19 -0
- package/skills/helpra-design-system/references/tokens-and-rules.md +13 -0
- package/skills/helpra-design-system/references/validation.md +11 -0
- package/skills/helpra-design-system/templates/component.json +38 -0
- package/skills/helpra-design-system/templates/system.json +70 -0
- package/skills/helpra-screen-composition/SKILL.md +69 -0
- package/src/brief/authoring-brief.ts +97 -0
- package/src/brief/bound.ts +80 -0
- package/src/brief/component-props.ts +53 -0
- package/src/brief/project-brief.ts +80 -0
- package/src/brief/reference-excerpt.ts +61 -0
- package/src/brief/references.ts +66 -0
- package/src/brief/screen-composition.ts +68 -0
- package/src/brief/shell.ts +84 -0
- package/src/brief/system.ts +74 -0
- package/src/brief/theme-css.ts +57 -0
- package/src/brief/tokens.ts +74 -0
- package/src/brief/trajectory.ts +64 -0
- package/src/contracts/agent-targets.ts +42 -0
- package/src/contracts/annotations.ts +44 -0
- package/src/contracts/artboard-appearance.ts +67 -0
- package/src/contracts/artboard-approval.ts +109 -0
- package/src/contracts/artboard-topology.ts +45 -0
- package/src/contracts/assets.ts +20 -0
- package/src/contracts/canvas-name.ts +19 -0
- package/src/contracts/common.schemas.ts +32 -0
- package/src/contracts/common.ts +3 -0
- package/src/contracts/common.types.ts +10 -0
- package/src/contracts/context-navigation.types.ts +6 -0
- package/src/contracts/context-read.schemas.ts +34 -0
- package/src/contracts/context-read.types.ts +20 -0
- package/src/contracts/design-error.ts +3 -0
- package/src/contracts/design-system-lifecycle.ts +107 -0
- package/src/contracts/design-system-themes.ts +36 -0
- package/src/contracts/design-system-tokens.ts +167 -0
- package/src/contracts/find-elements.ts +63 -0
- package/src/contracts/git-commit.ts +17 -0
- package/src/contracts/graph.schemas.ts +18 -0
- package/src/contracts/graph.types.ts +11 -0
- package/src/contracts/guide.types.ts +4 -0
- package/src/contracts/helpra-mark.ts +2 -0
- package/src/contracts/index.ts +13 -0
- package/src/contracts/input-errors.ts +48 -0
- package/src/contracts/legacy-component.ts +23 -0
- package/src/contracts/local-directory-picker.ts +9 -0
- package/src/contracts/managed-project.ts +22 -0
- package/src/contracts/operations.ts +315 -0
- package/src/contracts/origins.ts +25 -0
- package/src/contracts/portable.ts +72 -0
- package/src/contracts/project-brief-screen-pool.ts +78 -0
- package/src/contracts/project-brief.ts +99 -0
- package/src/contracts/project-component-dirs.ts +18 -0
- package/src/contracts/project-files.ts +17 -0
- package/src/contracts/project-read.types.ts +41 -0
- package/src/contracts/project.schemas.ts +72 -0
- package/src/contracts/project.ts +2 -0
- package/src/contracts/project.types.ts +70 -0
- package/src/contracts/publication-publish.schemas.ts +33 -0
- package/src/contracts/publication-publish.types.ts +6 -0
- package/src/contracts/publication-status.schemas.ts +17 -0
- package/src/contracts/publication-status.types.ts +5 -0
- package/src/contracts/publication.schemas.ts +9 -0
- package/src/contracts/publication.types.ts +25 -0
- package/src/contracts/recents.ts +59 -0
- package/src/contracts/render-inspection.schemas.ts +75 -0
- package/src/contracts/render-tree.schemas.ts +58 -0
- package/src/contracts/render.ts +182 -0
- package/src/contracts/review-geometry.ts +55 -0
- package/src/contracts/review-image.ts +26 -0
- package/src/contracts/review.ts +227 -0
- package/src/contracts/screen-constants.ts +93 -0
- package/src/contracts/screen-layout.ts +31 -0
- package/src/contracts/screen-palette-constants.ts +99 -0
- package/src/contracts/screen-palette-domain.styles.ts +160 -0
- package/src/contracts/screen-palette-domain.ts +134 -0
- package/src/contracts/screen-palette-fallbacks.ts +57 -0
- package/src/contracts/screen-palette-seed.ts +6 -0
- package/src/contracts/screen-palette-styles.ts +96 -0
- package/src/contracts/screen-palette.ts +88 -0
- package/src/contracts/screen-recipe.ts +118 -0
- package/src/contracts/screen-transition.ts +166 -0
- package/src/contracts/screen-workspace-palette.ts +62 -0
- package/src/contracts/screen-workspace-styles.ts +143 -0
- package/src/contracts/screen-workspace-template.ts +65 -0
- package/src/contracts/service.types.ts +16 -0
- package/src/contracts/source-export.schemas.ts +19 -0
- package/src/contracts/source-export.types.ts +6 -0
- package/src/contracts/source-mime.ts +5 -0
- package/src/contracts/system-browser.schemas.ts +15 -0
- package/src/contracts/system-browser.types.ts +7 -0
- package/src/contracts/system.constants.ts +2 -0
- package/src/contracts/system.schemas.ts +36 -0
- package/src/contracts/system.ts +3 -0
- package/src/contracts/system.types.ts +42 -0
- package/src/contracts/ui-session.ts +11 -0
- package/src/contracts/visual-replay.ts +21 -0
- package/src/embed/index.ts +94 -0
- package/src/embed/types.ts +61 -0
- package/src/graph/evidence.ts +47 -0
- package/src/graph/projection.ts +52 -0
- package/src/graph/query-snapshot.ts +42 -0
- package/src/graph/query.ts +60 -0
- package/src/graph/relations.ts +40 -0
- package/src/graph/validate.ts +20 -0
- package/src/guide/bundle.ts +26 -0
- package/src/guide/guide.constants.ts +3 -0
- package/src/guide/views.ts +22 -0
- package/src/project/annotations.ts +55 -0
- package/src/project/appearance-transaction.ts +240 -0
- package/src/project/approval-state.ts +125 -0
- package/src/project/artboard-approvals.ts +152 -0
- package/src/project/artboard-operations.ts +66 -0
- package/src/project/artboard-placement.ts +58 -0
- package/src/project/artboard-properties.ts +31 -0
- package/src/project/artboard-source.ts +124 -0
- package/src/project/artboard-topology-transaction.ts +249 -0
- package/src/project/assets.ts +217 -0
- package/src/project/catalog-summary.ts +169 -0
- package/src/project/change-impact.ts +96 -0
- package/src/project/component-aliases.ts +16 -0
- package/src/project/component-library.ts +54 -0
- package/src/project/css-impact.ts +151 -0
- package/src/project/demo-assets/fonts/LICENSE +93 -0
- package/src/project/demo-assets/fonts/README.md +5 -0
- package/src/project/demo-assets/fonts/inter-cyrillic-wght-normal.woff2 +0 -0
- package/src/project/demo-assets/fonts/inter-latin-wght-normal.woff2 +0 -0
- package/src/project/demo-assets/fonts/provenance.json +22 -0
- package/src/project/demo-design.ts +35 -0
- package/src/project/demo-fonts.ts +8 -0
- package/src/project/demo-sources.ts +19 -0
- package/src/project/demo.ts +64 -0
- package/src/project/dependencies.ts +124 -0
- package/src/project/derived-snapshot.ts +78 -0
- package/src/project/design-system-components.ts +178 -0
- package/src/project/design-system-documents.ts +128 -0
- package/src/project/design-system-journal.ts +52 -0
- package/src/project/design-system-lifecycle.ts +161 -0
- package/src/project/design-system-seed.ts +165 -0
- package/src/project/design-system-theme-edits.ts +124 -0
- package/src/project/design-system-token-patches.ts +278 -0
- package/src/project/design-system-tokens.ts +157 -0
- package/src/project/design-system-transaction.ts +164 -0
- package/src/project/design-systems.ts +266 -0
- package/src/project/design-workspace.ts +50 -0
- package/src/project/export-files.ts +34 -0
- package/src/project/extract-html-component.ts +83 -0
- package/src/project/file-cache.ts +61 -0
- package/src/project/file-lease.ts +44 -0
- package/src/project/format.ts +104 -0
- package/src/project/git-commit.ts +80 -0
- package/src/project/git.ts +140 -0
- package/src/project/html-fragments.ts +60 -0
- package/src/project/import-screen-mapper.ts +150 -0
- package/src/project/imports.ts +354 -0
- package/src/project/index.ts +12 -0
- package/src/project/initial-canvas.ts +31 -0
- package/src/project/live-topology.ts +17 -0
- package/src/project/locks.ts +36 -0
- package/src/project/managed-projects.ts +265 -0
- package/src/project/module-resolution.ts +21 -0
- package/src/project/parse-script.ts +53 -0
- package/src/project/paths.ts +230 -0
- package/src/project/project-component-dirs.ts +125 -0
- package/src/project/project-files.ts +117 -0
- package/src/project/project-metadata.ts +142 -0
- package/src/project/public-git.ts +39 -0
- package/src/project/recents.ts +111 -0
- package/src/project/registered-snapshot.ts +18 -0
- package/src/project/registry.ts +141 -0
- package/src/project/revisions.ts +200 -0
- package/src/project/screen-authoring.ts +153 -0
- package/src/project/screen-definitions.ts +47 -0
- package/src/project/screen-fonts.ts +18 -0
- package/src/project/screen-policy.ts +76 -0
- package/src/project/screen-pool.ts +91 -0
- package/src/project/screen-project-seed.ts +40 -0
- package/src/project/screen-styles.ts +33 -0
- package/src/project/screen-transitions.ts +317 -0
- package/src/project/snapshot-reader.ts +63 -0
- package/src/project/snapshot-selection.ts +41 -0
- package/src/project/snapshot-topology.ts +99 -0
- package/src/project/source-view.ts +42 -0
- package/src/project/stage-component-dirs.ts +37 -0
- package/src/project/topology-source-inventory.ts +92 -0
- package/src/project/topology.ts +394 -0
- package/src/project/transactions.ts +213 -0
- package/src/project/transition-transaction.ts +377 -0
- package/src/project/ui-sessions.ts +66 -0
- package/src/project/watch.ts +217 -0
- package/src/project/workspace.ts +746 -0
- package/src/project/workspace.types.ts +4 -0
- package/src/publication/cli.ts +51 -0
- package/src/publication/cutover.schemas.ts +25 -0
- package/src/publication/cutover.ts +82 -0
- package/src/publication/cutover.types.ts +5 -0
- package/src/publication/digests.ts +44 -0
- package/src/publication/durable.ts +21 -0
- package/src/publication/live-reader.ts +16 -0
- package/src/publication/navigation.ts +26 -0
- package/src/publication/navigation.types.ts +3 -0
- package/src/publication/publish-files.ts +39 -0
- package/src/publication/publish-gateway.ts +48 -0
- package/src/publication/publish-identity.ts +107 -0
- package/src/publication/publish-identity.types.ts +5 -0
- package/src/publication/publish-status.ts +88 -0
- package/src/publication/publish-status.types.ts +14 -0
- package/src/publication/publish.ts +132 -0
- package/src/publication/schemas.ts +10 -0
- package/src/publication/store.constants.ts +8 -0
- package/src/publication/store.ts +131 -0
- package/src/publication/validate-store.ts +23 -0
- package/src/publication/validate.ts +99 -0
- package/src/render/annotations.ts +149 -0
- package/src/render/archive-workspace.ts +31 -0
- package/src/render/asset-safety.ts +19 -0
- package/src/render/bridge-client.ts +41 -0
- package/src/render/budgets.ts +8 -0
- package/src/render/build.schemas.ts +13 -0
- package/src/render/build.ts +125 -0
- package/src/render/build.types.ts +6 -0
- package/src/render/capture.ts +105 -0
- package/src/render/comment-cursor.constants.ts +23 -0
- package/src/render/design-system-screenshot.ts +148 -0
- package/src/render/export.ts +144 -0
- package/src/render/html-head.ts +33 -0
- package/src/render/index.ts +324 -0
- package/src/render/input-references.ts +116 -0
- package/src/render/input-references.types.ts +1 -0
- package/src/render/inputs.ts +161 -0
- package/src/render/inputs.types.ts +4 -0
- package/src/render/interactive-capture.ts +49 -0
- package/src/render/module-policy.constants.ts +5 -0
- package/src/render/offline.ts +87 -0
- package/src/render/preview-headers.ts +8 -0
- package/src/render/preview.ts +64 -0
- package/src/render/provenance.ts +28 -0
- package/src/render/renderer.types.ts +17 -0
- package/src/render/replay.ts +131 -0
- package/src/render/resources.ts +97 -0
- package/src/render/runtime-archive-workspace.ts +116 -0
- package/src/render/runtime-cascade.ts +255 -0
- package/src/render/runtime-css-values.ts +20 -0
- package/src/render/runtime-cssom.ts +238 -0
- package/src/render/runtime-dom.ts +74 -0
- package/src/render/runtime-lazy.ts +108 -0
- package/src/render/runtime-lengths.ts +58 -0
- package/src/render/runtime-spacing.ts +40 -0
- package/src/render/runtime-styles.ts +187 -0
- package/src/render/runtime-transitions.ts +378 -0
- package/src/render/runtime.ts +490 -0
- package/src/render/source-map.ts +39 -0
- package/src/render/static-build.ts +115 -0
- package/src/render/static-public-screen.ts +27 -0
- package/src/render/static-svg.ts +71 -0
- package/src/render/system-artifacts.ts +108 -0
- package/src/render/system-chromium.ts +31 -0
- package/src/render/system-preview.ts +46 -0
- package/src/render/vite-build.ts +113 -0
- package/src/render/vite-pool.ts +125 -0
- package/src/render/vite-worker.ts +31 -0
- package/src/review/anchors.ts +85 -0
- package/src/review/attachments.ts +119 -0
- package/src/review/comparison.ts +57 -0
- package/src/review/creation-topology.ts +71 -0
- package/src/review/drawing-observation.ts +93 -0
- package/src/review/evidence.ts +77 -0
- package/src/review/image-bytes.ts +9 -0
- package/src/review/index.ts +1 -0
- package/src/review/original-captures.ts +60 -0
- package/src/review/placement.ts +49 -0
- package/src/review/project.ts +18 -0
- package/src/review/removed-target.ts +39 -0
- package/src/review/review-images.ts +79 -0
- package/src/review/service.ts +477 -0
- package/src/review/storage.ts +257 -0
- package/src/sandbox/HomeIdePreview.tsx +27 -0
- package/src/sandbox/SandboxClient.ts +106 -0
- package/src/sandbox/SandboxState.ts +56 -0
- package/src/sandbox/SketchPreview.tsx +54 -0
- package/src/sandbox/artboardBackground.ts +8 -0
- package/src/sandbox/canvasOperations.ts +148 -0
- package/src/sandbox/commentOperations.ts +85 -0
- package/src/sandbox/main.tsx +56 -0
- package/src/sandbox/overview.en.md +27 -0
- package/src/sandbox/overview.ru.md +27 -0
- package/src/sandbox/pngExports.ts +79 -0
- package/src/sandbox/previewLocation.ts +40 -0
- package/src/sandbox/project.ts +69 -0
- package/src/sandbox/sandbox.css +100 -0
- package/src/sandbox/system.ts +69 -0
- package/src/search/budget.ts +80 -0
- package/src/search/find-elements.ts +128 -0
- package/src/search/html.ts +56 -0
- package/src/search/jsx.ts +124 -0
- package/src/search/query.ts +74 -0
- package/src/search/source.ts +57 -0
- package/src/service/agent/dispatch.ts +326 -0
- package/src/service/agent/http.ts +76 -0
- package/src/service/agent/orca-bridge.ts +126 -0
- package/src/service/agent/orca.ts +261 -0
- package/src/service/agent/payload.ts +125 -0
- package/src/service/agent/receipts.ts +44 -0
- package/src/service/cli.ts +196 -0
- package/src/service/client.ts +77 -0
- package/src/service/comment-evidence.ts +91 -0
- package/src/service/comment-inspection.ts +33 -0
- package/src/service/comment-scenes.ts +22 -0
- package/src/service/context-cursor.ts +59 -0
- package/src/service/context-pinned.ts +82 -0
- package/src/service/context-selection.ts +62 -0
- package/src/service/context-source.ts +56 -0
- package/src/service/context.ts +119 -0
- package/src/service/daemon-entry.ts +16 -0
- package/src/service/daemon.ts +121 -0
- package/src/service/export-config.ts +21 -0
- package/src/service/http.ts +491 -0
- package/src/service/index.ts +190 -0
- package/src/service/inspect-page.ts +49 -0
- package/src/service/inspect.ts +38 -0
- package/src/service/lifecycle.ts +29 -0
- package/src/service/local-cli.ts +65 -0
- package/src/service/local-directory-picker.ts +29 -0
- package/src/service/loopback-http.ts +35 -0
- package/src/service/mcp-artboard-review.ts +91 -0
- package/src/service/mcp-auth.ts +24 -0
- package/src/service/mcp-content.ts +47 -0
- package/src/service/mcp-http.ts +26 -0
- package/src/service/mcp.ts +124 -0
- package/src/service/mutation-gate.ts +107 -0
- package/src/service/native-directory-picker.ts +70 -0
- package/src/service/operation-policy.ts +45 -0
- package/src/service/operations.ts +447 -0
- package/src/service/publication-gateway-server.ts +34 -0
- package/src/service/publication-gateway.ts +139 -0
- package/src/service/publication-gateway.types.ts +9 -0
- package/src/service/remote-agent-tokens.ts +49 -0
- package/src/service/remote-config.ts +43 -0
- package/src/service/remote-mcp.ts +76 -0
- package/src/service/remote-results.ts +39 -0
- package/src/service/remote-session.ts +65 -0
- package/src/service/remote.ts +33 -0
- package/src/service/results.ts +33 -0
- package/src/service/review-payloads.ts +72 -0
- package/src/service/review-resource-links.ts +41 -0
- package/src/service/security.ts +117 -0
- package/src/service/server-config.ts +44 -0
- package/src/service/server-config.types.ts +13 -0
- package/src/service/server.ts +16 -0
- package/src/service/status-capacity.ts +59 -0
- package/src/service/status-current.ts +30 -0
- package/src/service/stdio.ts +34 -0
- package/src/service/ui-asset-cache.ts +51 -0
- package/src/service/usecases.ts +155 -0
- package/src/service/work-budget.ts +37 -0
- package/src/service/workspace-http.ts +57 -0
- package/src/source-export/archive.ts +78 -0
- package/src/source-export/capacity.ts +44 -0
- package/src/source-export/checkpoint.ts +58 -0
- package/src/source-export/cleanup.ts +46 -0
- package/src/source-export/download.ts +74 -0
- package/src/source-export/downloads.ts +29 -0
- package/src/source-export/history.ts +50 -0
- package/src/source-export/inventory.types.ts +12 -0
- package/src/source-export/job-store.ts +125 -0
- package/src/source-export/kernel-lease.ts +13 -0
- package/src/source-export/lease.ts +72 -0
- package/src/source-export/legacy.ts +46 -0
- package/src/source-export/manager.ts +189 -0
- package/src/source-export/manifest.ts +23 -0
- package/src/source-export/member-reader.ts +24 -0
- package/src/source-export/result.ts +12 -0
- package/src/source-export/review-checkpoint.ts +169 -0
- package/src/source-export/snapshot-space.ts +35 -0
- package/src/source-export/space.ts +79 -0
- package/src/source-export/tickets.ts +24 -0
- package/src/system/browser-source.ts +87 -0
- package/src/system/browser.ts +39 -0
- package/src/system/change-policy.ts +82 -0
- package/src/system/component-metadata.ts +36 -0
- package/src/system/components.ts +58 -0
- package/src/system/css-token-blocks.ts +346 -0
- package/src/system/index.ts +9 -0
- package/src/system/inspection.ts +20 -0
- package/src/system/library-namespace.ts +108 -0
- package/src/system/published-metadata.ts +38 -0
- package/src/system/report-store.ts +41 -0
- package/src/system/rules.ts +47 -0
- package/src/system/scope-policy.ts +61 -0
- package/src/system/service.ts +129 -0
- package/src/system/service.types.ts +6 -0
- package/src/system/snapshot.ts +101 -0
- package/src/system/source-analysis.ts +273 -0
- package/src/system/source-exports.ts +38 -0
- package/src/system/theme-layers.ts +17 -0
- package/src/system/token-parser.ts +63 -0
- package/src/system/token-values.constants.ts +1 -0
- package/src/system/token-values.ts +62 -0
- package/src/system/token-values.types.ts +4 -0
- package/src/system/tokens.ts +111 -0
- package/src/system/usage-index.ts +148 -0
- package/src/system/validation.ts +101 -0
- package/src/system/validation.types.ts +2 -0
- package/src/ui/AgentDeliveryControl.tsx +106 -0
- package/src/ui/AnnotationDetails.tsx +23 -0
- package/src/ui/AnnotationProperties.tsx +218 -0
- package/src/ui/ApiError.ts +31 -0
- package/src/ui/App.tsx +340 -0
- package/src/ui/ArtboardBackgroundField.tsx +122 -0
- package/src/ui/ArtboardDragGuides.tsx +25 -0
- package/src/ui/ArtboardFrame.tsx +230 -0
- package/src/ui/ArtboardPropertiesSection.tsx +286 -0
- package/src/ui/Brand.tsx +42 -0
- package/src/ui/CanvasAnnotationObject.tsx +358 -0
- package/src/ui/CanvasAnnotations.tsx +168 -0
- package/src/ui/CanvasNavPanel.tsx +421 -0
- package/src/ui/CanvasNavSwitcher.tsx +148 -0
- package/src/ui/CommentComposer.tsx +202 -0
- package/src/ui/CommentDeliveryStatus.tsx +80 -0
- package/src/ui/CommentEvidence.tsx +280 -0
- package/src/ui/CommentLayer.tsx +279 -0
- package/src/ui/CommentTextarea.tsx +47 -0
- package/src/ui/ContextMenu.tsx +373 -0
- package/src/ui/CustomSelect.tsx +364 -0
- package/src/ui/DesignSystemsCatalog.tsx +275 -0
- package/src/ui/DiscussionsPanel.tsx +240 -0
- package/src/ui/ElementProperties.tsx +117 -0
- package/src/ui/Entry.tsx +392 -0
- package/src/ui/ExportMenu.tsx +218 -0
- package/src/ui/FolderPathField.tsx +62 -0
- package/src/ui/FrameExportPopover.tsx +187 -0
- package/src/ui/FullscreenPlayOverlay.tsx +177 -0
- package/src/ui/GhostPlacementOverlay.tsx +48 -0
- package/src/ui/HomeModals.tsx +294 -0
- package/src/ui/HomeProjectDetails.tsx +295 -0
- package/src/ui/HomeProjectList.tsx +327 -0
- package/src/ui/HomeRecents.tsx +249 -0
- package/src/ui/IdeStatusControl.tsx +49 -0
- package/src/ui/InlineNameInput.tsx +51 -0
- package/src/ui/InspectionViews.tsx +133 -0
- package/src/ui/LanguageDropdown.tsx +62 -0
- package/src/ui/McpSettingsDialog.tsx +169 -0
- package/src/ui/MinimalInspector.tsx +112 -0
- package/src/ui/Preview.tsx +68 -0
- package/src/ui/ProjectDialog.tsx +237 -0
- package/src/ui/ProjectHeader.tsx +213 -0
- package/src/ui/RegionSelector.tsx +106 -0
- package/src/ui/ReviewAttachments.tsx +331 -0
- package/src/ui/SandboxHeaderControls.tsx +30 -0
- package/src/ui/ScopeEditor.tsx +109 -0
- package/src/ui/Session.tsx +499 -0
- package/src/ui/SmartGuidesOverlay.tsx +86 -0
- package/src/ui/SpacingOverlay.tsx +33 -0
- package/src/ui/StandaloneSystemReader.tsx +322 -0
- package/src/ui/SystemView.tsx +56 -0
- package/src/ui/ThreadDetail.tsx +426 -0
- package/src/ui/Toolbar.tsx +195 -0
- package/src/ui/TooltipLayer.tsx +132 -0
- package/src/ui/Workbench.tsx +1081 -0
- package/src/ui/Workspace.tsx +497 -0
- package/src/ui/ZoomControls.tsx +131 -0
- package/src/ui/agent-delivery.css +88 -0
- package/src/ui/agentDelivery.ts +138 -0
- package/src/ui/annotations.css +146 -0
- package/src/ui/api.ts +340 -0
- package/src/ui/approvals/ApprovalActions.tsx +121 -0
- package/src/ui/approvals/ApprovalNoteComposer.tsx +69 -0
- package/src/ui/approvals/ApprovalStatusGlyph.tsx +39 -0
- package/src/ui/approvals/ApprovalsPanel.tsx +295 -0
- package/src/ui/approvals/ArtboardApprovalChip.tsx +61 -0
- package/src/ui/approvals/InlineApprovalPopover.tsx +180 -0
- package/src/ui/approvals/QuickReworkPopover.tsx +67 -0
- package/src/ui/approvals/approvalOrder.ts +36 -0
- package/src/ui/approvals/approvalUtils.ts +249 -0
- package/src/ui/approvals/approvals.css +476 -0
- package/src/ui/approvals/inline-approvals.css +125 -0
- package/src/ui/approvals/useApprovalsPanel.ts +257 -0
- package/src/ui/approvals/useInlineApproval.ts +22 -0
- package/src/ui/artboardBackground.ts +29 -0
- package/src/ui/artboardClipboard.ts +54 -0
- package/src/ui/artboardId.ts +5 -0
- package/src/ui/artboardPropertyEdits.ts +58 -0
- package/src/ui/assets/helpra-mark.svg +3 -0
- package/src/ui/authStorage.ts +184 -0
- package/src/ui/browserHost.ts +87 -0
- package/src/ui/browserUiSession.ts +30 -0
- package/src/ui/camera.ts +22 -0
- package/src/ui/cameraAnimation.ts +82 -0
- package/src/ui/canvas-placement.css +160 -0
- package/src/ui/canvas-render-priority.ts +26 -0
- package/src/ui/canvas-render-state.ts +60 -0
- package/src/ui/canvas.css +463 -0
- package/src/ui/canvasFit.ts +96 -0
- package/src/ui/canvasNavigation.ts +52 -0
- package/src/ui/canvasPlacementOps.ts +146 -0
- package/src/ui/catalog.css +119 -0
- package/src/ui/comment-layer.css +108 -0
- package/src/ui/comment-textarea.css +30 -0
- package/src/ui/commentDeliveryFailures.ts +40 -0
- package/src/ui/commentGeometry.ts +339 -0
- package/src/ui/commentLabels.ts +12 -0
- package/src/ui/commentPresentation.ts +32 -0
- package/src/ui/commentState.ts +90 -0
- package/src/ui/comments.css +419 -0
- package/src/ui/componentLibrary.ts +18 -0
- package/src/ui/context-menu.css +93 -0
- package/src/ui/contextMenuEditable.ts +215 -0
- package/src/ui/controls.css +186 -0
- package/src/ui/custom-select.css +131 -0
- package/src/ui/dialogs.css +137 -0
- package/src/ui/drawing/DrawingSnapshot.tsx +46 -0
- package/src/ui/drawing/PencilLayer.tsx +401 -0
- package/src/ui/drawing/drawingUtils.ts +294 -0
- package/src/ui/editorStyles.ts +28 -0
- package/src/ui/entry.css +210 -0
- package/src/ui/entry.types.ts +1 -0
- package/src/ui/fonts/README.md +5 -0
- package/src/ui/fonts/inter-cyrillic-wght-normal.woff2 +0 -0
- package/src/ui/fonts/inter-latin-wght-normal.woff2 +0 -0
- package/src/ui/fonts.css +21 -0
- package/src/ui/frameMounting.ts +88 -0
- package/src/ui/helpra-tokens.css +361 -0
- package/src/ui/home-oss.css +191 -0
- package/src/ui/home-project-list.css +457 -0
- package/src/ui/home.css +374 -0
- package/src/ui/identifyBrowserClient.ts +28 -0
- package/src/ui/index.html +13 -0
- package/src/ui/inspector.css +556 -0
- package/src/ui/keyboardTarget.ts +5 -0
- package/src/ui/language-dropdown.css +30 -0
- package/src/ui/lazyTreeSession.ts +139 -0
- package/src/ui/library.css +212 -0
- package/src/ui/loadTopology.ts +74 -0
- package/src/ui/localizedCopy.ts +10 -0
- package/src/ui/localizedCopyEditor.ts +293 -0
- package/src/ui/localizedCopySystem.ts +177 -0
- package/src/ui/main.tsx +10 -0
- package/src/ui/markupExport.ts +166 -0
- package/src/ui/mobile.css +191 -0
- package/src/ui/models.ts +336 -0
- package/src/ui/navigation.css +373 -0
- package/src/ui/pointerCanvasPoint.ts +6 -0
- package/src/ui/previewInspection.ts +124 -0
- package/src/ui/previewProps.ts +76 -0
- package/src/ui/previewRecord.ts +61 -0
- package/src/ui/previewTreeDemand.ts +14 -0
- package/src/ui/primitives.tsx +207 -0
- package/src/ui/projectArtboardEdits.ts +21 -0
- package/src/ui/projectNames.ts +24 -0
- package/src/ui/projectRefresh.ts +48 -0
- package/src/ui/projectSelection.ts +41 -0
- package/src/ui/projectSourceEvents.ts +39 -0
- package/src/ui/public/fonts/OFL.txt +93 -0
- package/src/ui/publicSandbox.ts +2 -0
- package/src/ui/publicationPresentation.ts +35 -0
- package/src/ui/review-attachments.css +151 -0
- package/src/ui/scene.ts +133 -0
- package/src/ui/session.schemas.ts +35 -0
- package/src/ui/shell.css +294 -0
- package/src/ui/smartGuides.ts +239 -0
- package/src/ui/spacingGeometry.ts +84 -0
- package/src/ui/structuralRepeats.ts +226 -0
- package/src/ui/styles.css +146 -0
- package/src/ui/submitCommentOnEnter.ts +10 -0
- package/src/ui/system/ScreenConstantSample.tsx +84 -0
- package/src/ui/system/ScreenConstantsSection.tsx +184 -0
- package/src/ui/system/SystemAssets.tsx +95 -0
- package/src/ui/system/SystemComponents.tsx +94 -0
- package/src/ui/system/SystemDocument.tsx +74 -0
- package/src/ui/system/SystemFiles.tsx +136 -0
- package/src/ui/system/SystemMarkdown.tsx +236 -0
- package/src/ui/system/SystemNativeLibrary.tsx +37 -0
- package/src/ui/system/SystemNavigation.tsx +107 -0
- package/src/ui/system/SystemOverview.tsx +52 -0
- package/src/ui/system/SystemPreviewFrame.tsx +96 -0
- package/src/ui/system/SystemTokenSection.tsx +190 -0
- package/src/ui/system/SystemTypography.tsx +146 -0
- package/src/ui/system/SystemValue.tsx +52 -0
- package/src/ui/system/open-ds/OpenDsComponentsShowcase.tsx +224 -0
- package/src/ui/system/open-ds/OpenDsIcons.tsx +161 -0
- package/src/ui/system/open-ds/OpenDsSections.tsx +362 -0
- package/src/ui/system/open-ds/OpenDsTokenEditors.tsx +246 -0
- package/src/ui/system/open-ds/OverviewDocuments.tsx +146 -0
- package/src/ui/system/open-ds/SlidingNavigation.tsx +44 -0
- package/src/ui/system/open-ds/open-ds-components.css +109 -0
- package/src/ui/system/open-ds/open-ds-sections.css +356 -0
- package/src/ui/system/open-ds/openDsCatalogData.ts +294 -0
- package/src/ui/system/open-ds/openDsTokenSpecs.ts +192 -0
- package/src/ui/system/open-ds/useOpenDsPersistence.ts +213 -0
- package/src/ui/system/screen-constants.css +143 -0
- package/src/ui/system/screenConstants.ts +193 -0
- package/src/ui/system/standalone-reader.css +404 -0
- package/src/ui/system/system-browser.css +383 -0
- package/src/ui/system/system-content.css +220 -0
- package/src/ui/system/system-library.css +272 -0
- package/src/ui/system/system-markdown.css +99 -0
- package/src/ui/system/system-typography.css +83 -0
- package/src/ui/system/systemBrowser.types.ts +76 -0
- package/src/ui/system/systemBrowserSource.ts +203 -0
- package/src/ui/system/systemCatalog.ts +198 -0
- package/src/ui/system/systemPreviewUrl.ts +38 -0
- package/src/ui/system/systemReadQueue.ts +41 -0
- package/src/ui/system/systemTokens.ts +169 -0
- package/src/ui/system/systemValueStyle.ts +13 -0
- package/src/ui/system/useScreenConstants.ts +32 -0
- package/src/ui/system/useSystemAnchors.ts +85 -0
- package/src/ui/system/useSystemBrowser.ts +167 -0
- package/src/ui/system/useSystemFonts.ts +67 -0
- package/src/ui/system/useSystemVisibility.ts +23 -0
- package/src/ui/tooltip.css +36 -0
- package/src/ui/transfers.css +93 -0
- package/src/ui/transitions/TransitionBackPill.tsx +54 -0
- package/src/ui/transitions/TransitionControl.tsx +257 -0
- package/src/ui/transitions/TransitionPickerPopover.tsx +176 -0
- package/src/ui/transitions/transitionUtils.ts +223 -0
- package/src/ui/transitions/transitions.css +406 -0
- package/src/ui/transitions/useScreenTransitions.ts +308 -0
- package/src/ui/uiTheme.ts +51 -0
- package/src/ui/useArtboardCommands.ts +162 -0
- package/src/ui/useArtboardDrag.ts +83 -0
- package/src/ui/useArtboardPropertyEdits.ts +72 -0
- package/src/ui/useCamera.ts +291 -0
- package/src/ui/useCameraFlight.ts +84 -0
- package/src/ui/useCanvasAnnotations.ts +452 -0
- package/src/ui/useCanvasPlacement.ts +374 -0
- package/src/ui/useCanvasRenders.ts +314 -0
- package/src/ui/useCommentSubmissions.ts +47 -0
- package/src/ui/useInspection.ts +62 -0
- package/src/ui/useLiveInspection.ts +69 -0
- package/src/ui/useMountedFrames.ts +90 -0
- package/src/ui/usePopover.ts +58 -0
- package/src/ui/usePreviewChannel.ts +389 -0
- package/src/ui/usePreviewPanOwner.ts +41 -0
- package/src/ui/useProject.ts +498 -0
- package/src/ui/useProjectComments.ts +152 -0
- package/src/ui/useProjectSourceWatch.ts +89 -0
- package/src/ui/useProjectTopology.ts +16 -0
- package/src/ui/useUsages.ts +102 -0
- package/src/ui/useVisibleCanvasFrames.ts +37 -0
- package/src/ui/useWorkbench.ts +440 -0
- package/src/ui/useWorkbenchContextMenus.ts +456 -0
- package/src/ui/validation.constants.ts +12 -0
- package/src/ui/validationModel.ts +22 -0
- package/src/ui/workbenchI18n.ts +377 -0
- package/src/ui/workingCopyMutations.ts +43 -0
- package/templates/native-components/README.md +62 -0
- package/templates/native-components/components/app-shell/AppShell.tsx +392 -0
- package/templates/native-components/components/app-shell/README.md +5 -0
- package/templates/native-components/components/app-shell/StageScrollbar.tsx +185 -0
- package/templates/native-components/components/app-shell/component.json +34 -0
- package/templates/native-components/components/app-shell/examples/default.tsx +14 -0
- package/templates/native-components/components/app-state/AppState.tsx +151 -0
- package/templates/native-components/components/app-state/README.md +5 -0
- package/templates/native-components/components/app-state/component.json +73 -0
- package/templates/native-components/components/app-state/examples/form.tsx +7 -0
- package/templates/native-components/components/app-state/examples/list.tsx +7 -0
- package/templates/native-components/components/app-state/examples/panel.tsx +7 -0
- package/templates/native-components/components/app-state/examples/screen.tsx +7 -0
- package/templates/native-components/components/badge/Badge.tsx +18 -0
- package/templates/native-components/components/badge/README.md +5 -0
- package/templates/native-components/components/badge/component.json +87 -0
- package/templates/native-components/components/badge/examples/accent.tsx +7 -0
- package/templates/native-components/components/badge/examples/danger.tsx +7 -0
- package/templates/native-components/components/badge/examples/neutral.tsx +7 -0
- package/templates/native-components/components/badge/examples/success.tsx +7 -0
- package/templates/native-components/components/badge/examples/warning.tsx +7 -0
- package/templates/native-components/components/button/Button.tsx +15 -0
- package/templates/native-components/components/button/README.md +5 -0
- package/templates/native-components/components/button/component.json +73 -0
- package/templates/native-components/components/button/examples/add.tsx +7 -0
- package/templates/native-components/components/button/examples/ghost.tsx +7 -0
- package/templates/native-components/components/button/examples/primary.tsx +7 -0
- package/templates/native-components/components/button/examples/secondary.tsx +7 -0
- package/templates/native-components/components/card/Card.tsx +19 -0
- package/templates/native-components/components/card/README.md +5 -0
- package/templates/native-components/components/card/component.json +45 -0
- package/templates/native-components/components/card/examples/md.tsx +7 -0
- package/templates/native-components/components/card/examples/sm.tsx +7 -0
- package/templates/native-components/components/class-names.ts +9 -0
- package/templates/native-components/components/composer/Composer.tsx +61 -0
- package/templates/native-components/components/composer/README.md +5 -0
- package/templates/native-components/components/composer/component.json +43 -0
- package/templates/native-components/components/composer/examples/compact.tsx +12 -0
- package/templates/native-components/components/composer/examples/default.tsx +12 -0
- package/templates/native-components/components/field-message.tsx +16 -0
- package/templates/native-components/components/focus-layer.ts +146 -0
- package/templates/native-components/components/form-field.ts +27 -0
- package/templates/native-components/components/helpra-logo/HelpraLogo.tsx +27 -0
- package/templates/native-components/components/helpra-logo/README.md +5 -0
- package/templates/native-components/components/helpra-logo/component.json +43 -0
- package/templates/native-components/components/helpra-logo/examples/compact.tsx +7 -0
- package/templates/native-components/components/helpra-logo/examples/default.tsx +7 -0
- package/templates/native-components/components/helpra-mark-path.ts +2 -0
- package/templates/native-components/components/helpra-mascot/HelpraMascot.tsx +45 -0
- package/templates/native-components/components/helpra-mascot/README.md +5 -0
- package/templates/native-components/components/helpra-mascot/component.json +57 -0
- package/templates/native-components/components/helpra-mascot/examples/default.tsx +7 -0
- package/templates/native-components/components/helpra-mascot/examples/loading.tsx +7 -0
- package/templates/native-components/components/helpra-mascot/examples/thinking.tsx +7 -0
- package/templates/native-components/components/index.ts +47 -0
- package/templates/native-components/components/input/Input.tsx +59 -0
- package/templates/native-components/components/input/README.md +5 -0
- package/templates/native-components/components/input/component.json +43 -0
- package/templates/native-components/components/input/examples/default.tsx +7 -0
- package/templates/native-components/components/input/examples/invalid.tsx +7 -0
- package/templates/native-components/components/metric-grid/MetricGrid.tsx +40 -0
- package/templates/native-components/components/metric-grid/README.md +5 -0
- package/templates/native-components/components/metric-grid/component.json +29 -0
- package/templates/native-components/components/metric-grid/examples/default.tsx +7 -0
- package/templates/native-components/components/modal/Modal.tsx +75 -0
- package/templates/native-components/components/modal/README.md +5 -0
- package/templates/native-components/components/modal/component.json +31 -0
- package/templates/native-components/components/modal/examples/default.tsx +13 -0
- package/templates/native-components/components/panel-resize-handle/PanelResizeHandle.tsx +52 -0
- package/templates/native-components/components/panel-resize-handle/README.md +5 -0
- package/templates/native-components/components/panel-resize-handle/component.json +29 -0
- package/templates/native-components/components/panel-resize-handle/examples/default.tsx +13 -0
- package/templates/native-components/components/profile-avatar/ProfileAvatar.tsx +37 -0
- package/templates/native-components/components/profile-avatar/README.md +5 -0
- package/templates/native-components/components/profile-avatar/component.json +45 -0
- package/templates/native-components/components/profile-avatar/examples/md.tsx +7 -0
- package/templates/native-components/components/profile-avatar/examples/sm.tsx +7 -0
- package/templates/native-components/components/row-card/README.md +5 -0
- package/templates/native-components/components/row-card/RowCard.tsx +33 -0
- package/templates/native-components/components/row-card/component.json +43 -0
- package/templates/native-components/components/row-card/examples/current.tsx +7 -0
- package/templates/native-components/components/row-card/examples/default.tsx +7 -0
- package/templates/native-components/components/select/README.md +5 -0
- package/templates/native-components/components/select/Select.tsx +66 -0
- package/templates/native-components/components/select/component.json +29 -0
- package/templates/native-components/components/select/examples/default.tsx +7 -0
- package/templates/native-components/components/shell-nav-icon-graphic/README.md +5 -0
- package/templates/native-components/components/shell-nav-icon-graphic/ShellNavIconGraphic.tsx +148 -0
- package/templates/native-components/components/shell-nav-icon-graphic/component.json +45 -0
- package/templates/native-components/components/shell-nav-icon-graphic/examples/home.tsx +7 -0
- package/templates/native-components/components/shell-nav-icon-graphic/examples/settings.tsx +7 -0
- package/templates/native-components/components/shell-resizer.ts +304 -0
- package/templates/native-components/components/skeleton/README.md +5 -0
- package/templates/native-components/components/skeleton/Skeleton.tsx +20 -0
- package/templates/native-components/components/skeleton/component.json +87 -0
- package/templates/native-components/components/skeleton/examples/block.tsx +7 -0
- package/templates/native-components/components/skeleton/examples/card.tsx +7 -0
- package/templates/native-components/components/skeleton/examples/circle.tsx +7 -0
- package/templates/native-components/components/skeleton/examples/text.tsx +7 -0
- package/templates/native-components/components/skeleton/examples/title.tsx +7 -0
- package/templates/native-components/components/status-badge/README.md +5 -0
- package/templates/native-components/components/status-badge/StatusBadge.tsx +18 -0
- package/templates/native-components/components/status-badge/component.json +75 -0
- package/templates/native-components/components/status-badge/examples/danger.tsx +7 -0
- package/templates/native-components/components/status-badge/examples/neutral.tsx +7 -0
- package/templates/native-components/components/status-badge/examples/success.tsx +7 -0
- package/templates/native-components/components/status-badge/examples/warning.tsx +7 -0
- package/templates/native-components/components/step-indicator/README.md +5 -0
- package/templates/native-components/components/step-indicator/StepIndicator.tsx +30 -0
- package/templates/native-components/components/step-indicator/component.json +29 -0
- package/templates/native-components/components/step-indicator/examples/default.tsx +7 -0
- package/templates/native-components/components/styles.css +2 -0
- package/templates/native-components/components/table/README.md +5 -0
- package/templates/native-components/components/table/Table.tsx +95 -0
- package/templates/native-components/components/table/component.json +45 -0
- package/templates/native-components/components/table/examples/scroll.tsx +10 -0
- package/templates/native-components/components/table/examples/stack.tsx +10 -0
- package/templates/native-components/components/tabs/README.md +5 -0
- package/templates/native-components/components/tabs/Tabs.tsx +217 -0
- package/templates/native-components/components/tabs/component.json +29 -0
- package/templates/native-components/components/tabs/examples/default.tsx +10 -0
- package/templates/native-components/components/textarea/README.md +5 -0
- package/templates/native-components/components/textarea/Textarea.tsx +60 -0
- package/templates/native-components/components/textarea/component.json +29 -0
- package/templates/native-components/components/textarea/examples/default.tsx +7 -0
- package/templates/native-components/components/window/README.md +5 -0
- package/templates/native-components/components/window/Window.tsx +25 -0
- package/templates/native-components/components/window/component.json +43 -0
- package/templates/native-components/components/window/examples/default.tsx +8 -0
- package/templates/native-components/components/window/examples/detached.tsx +8 -0
- package/templates/native-components/tsconfig.json +7 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import type { ServerResponse } from 'node:http';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { agentDispatchSchema, type ActiveAgentTarget, type AgentDispatch, type DispatchDestination } from '../../contracts/agent-targets.js';
|
|
5
|
+
import { DesignError } from '../../contracts/common.js';
|
|
6
|
+
import type { RendererService } from '../../contracts/render.js';
|
|
7
|
+
import type { ReviewService } from '../../contracts/review.js';
|
|
8
|
+
import type { AgentCommentDispatchPayload } from '../../embed/types.js';
|
|
9
|
+
import { LocalUiSessions } from '../../project/ui-sessions.js';
|
|
10
|
+
import type { ProjectWorkspace } from '../../project/workspace.js';
|
|
11
|
+
import { ReviewStore } from '../../review/storage.js';
|
|
12
|
+
import { discoverOrca, orcaCommand, resolveOrcaCli, sendToOrca, type OrcaCommand } from './orca.js';
|
|
13
|
+
import { commentDispatchId, commentPayload, deliverWebhook } from './payload.js';
|
|
14
|
+
import { DispatchReceipts, type DispatchReceipt } from './receipts.js';
|
|
15
|
+
import type { requestDispatchSchema } from '../../contracts/agent-targets.js';
|
|
16
|
+
|
|
17
|
+
export const bridgeRegistrationSchema = z.strictObject({
|
|
18
|
+
bridgeId: z.uuid({ version: 'v4' }),
|
|
19
|
+
agentName: z.string().min(1).max(120),
|
|
20
|
+
targetRef: z.string().min(1).max(200),
|
|
21
|
+
});
|
|
22
|
+
export const dispatchResultSchema = z.strictObject({
|
|
23
|
+
attempt: z.number().int().positive(),
|
|
24
|
+
delivered: z.boolean(),
|
|
25
|
+
messageId: z.string().max(200).optional(),
|
|
26
|
+
uncertain: z.boolean().optional(),
|
|
27
|
+
});
|
|
28
|
+
type Outcome = z.infer<typeof dispatchResultSchema>;
|
|
29
|
+
type Bridge = z.infer<typeof bridgeRegistrationSchema> & { response: ServerResponse };
|
|
30
|
+
type Channel = { url: string; secret: string };
|
|
31
|
+
type Browser = { session: string; origin: string; userAgent: string; hostEnabled: boolean };
|
|
32
|
+
type Recipient = Pick<DispatchReceipt, 'targetId' | 'targetName' | 'recipient'>;
|
|
33
|
+
|
|
34
|
+
function hostName(kind: DispatchDestination['hostKind']): string {
|
|
35
|
+
return kind === 'orca' ? 'Orca' : 'Desktop';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class AgentDispatchService {
|
|
39
|
+
private readonly receipts: DispatchReceipts;
|
|
40
|
+
private readonly sessions: LocalUiSessions;
|
|
41
|
+
private readonly reviews: ReviewStore;
|
|
42
|
+
private readonly bridges = new Map<string, Bridge>();
|
|
43
|
+
private readonly pending = new Set<Promise<unknown>>();
|
|
44
|
+
private readonly instance = randomUUID();
|
|
45
|
+
private discovery?: { origin: string; expires: number; result: Promise<ActiveAgentTarget[]> };
|
|
46
|
+
|
|
47
|
+
constructor(private readonly options: {
|
|
48
|
+
workspace: ProjectWorkspace; review: ReviewService; renderer: RendererService;
|
|
49
|
+
sessionsDir: string; origin: () => string; remote: boolean; webhook?: Channel; orca?: OrcaCommand;
|
|
50
|
+
}) {
|
|
51
|
+
this.receipts = new DispatchReceipts(options.workspace.stateDir);
|
|
52
|
+
this.sessions = new LocalUiSessions(options.sessionsDir);
|
|
53
|
+
this.reviews = new ReviewStore(options.workspace);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private async command(): Promise<OrcaCommand | undefined> {
|
|
57
|
+
if (this.options.orca) return this.options.orca;
|
|
58
|
+
const executable = await resolveOrcaCli();
|
|
59
|
+
return executable ? orcaCommand(executable) : undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private get webhookTargetRef(): string | undefined {
|
|
63
|
+
if (this.options.remote && this.options.webhook) {
|
|
64
|
+
return 'wh_' + createHash('sha256').update(new URL(this.options.webhook.url).href).digest('hex');
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private async available(origin: string, userAgent: string, fresh: boolean): Promise<ActiveAgentTarget[]> {
|
|
70
|
+
if (this.options.remote) {
|
|
71
|
+
return [...this.bridges.values()].map(bridge => ({
|
|
72
|
+
ideId: 'orca-' + bridge.bridgeId, ideLabel: 'Orca', hasOpenAgent: true, isSelectedForSession: false,
|
|
73
|
+
currentAgent: { targetRef: bridge.targetRef, agentName: bridge.agentName },
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
if (!/\bElectron\/[\d.]+\b/i.test(userAgent)) return [];
|
|
77
|
+
if (fresh || this.discovery?.origin !== origin || this.discovery.expires <= Date.now()) {
|
|
78
|
+
const result = this.command().then(run => run ? discoverOrca(run, origin, userAgent) : []).catch(() => []);
|
|
79
|
+
this.discovery = { origin, expires: Date.now() + 3000, result };
|
|
80
|
+
}
|
|
81
|
+
return this.discovery.result;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async targets(session: string | undefined, origin: string, agent: string) {
|
|
85
|
+
const available = await this.available(origin, agent, false);
|
|
86
|
+
const choice = session ? await this.sessions.selectedIde(session) : undefined;
|
|
87
|
+
const selectedIdeId = available.find(item => item.ideId === choice)?.ideId ?? available[0]?.ideId ?? null;
|
|
88
|
+
const webhook = this.webhookTargetRef;
|
|
89
|
+
return {
|
|
90
|
+
status: available.length ? 'detected' : 'none', selectedIdeId,
|
|
91
|
+
activeIdeTargets: available.map(item => ({ ...item, isSelectedForSession: item.ideId === selectedIdeId })),
|
|
92
|
+
...(webhook ? { webhook: { targetRef: webhook } } : {}),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async select(session: string | undefined, ideId: string, origin: string, agent: string) {
|
|
97
|
+
if (!session) throw new DesignError('invalid_input', 'A browser session is required');
|
|
98
|
+
if (!(await this.available(origin, agent, true)).some(item => item.ideId === ideId)) {
|
|
99
|
+
throw new DesignError('missing_reference', 'The IDE has no active agent');
|
|
100
|
+
}
|
|
101
|
+
await this.sessions.selectIde(session, ideId);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private async saveReview(receipt: DispatchReceipt): Promise<AgentDispatch> {
|
|
105
|
+
const data = agentDispatchSchema.parse({
|
|
106
|
+
dispatchId: receipt.dispatchId, targetId: receipt.targetId, targetName: receipt.targetName,
|
|
107
|
+
status: receipt.status, updatedAt: receipt.updatedAt, externalMessageId: receipt.externalMessageId, errorCode: receipt.errorCode,
|
|
108
|
+
});
|
|
109
|
+
try {
|
|
110
|
+
await this.reviews.write(receipt.workingCopyId, 'dispatch', `${receipt.threadId}.${receipt.messageId}.json`, JSON.stringify(data));
|
|
111
|
+
} catch {
|
|
112
|
+
// The workspace receipt remains authoritative when a project was moved or removed.
|
|
113
|
+
}
|
|
114
|
+
return data;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async statuses(workingCopyId: string, threadId: string) {
|
|
118
|
+
const thread = await this.options.review.getThread(workingCopyId, threadId);
|
|
119
|
+
const records = await this.receipts.read();
|
|
120
|
+
return thread.messages.flatMap(message => {
|
|
121
|
+
const receipt = records[commentDispatchId(workingCopyId, threadId, message.id)];
|
|
122
|
+
if (!receipt) return [];
|
|
123
|
+
const stalled = receipt.status === 'queued' && this.stalled(receipt);
|
|
124
|
+
return [{ messageId: message.id, dispatch: agentDispatchSchema.strip().parse(stalled
|
|
125
|
+
? { ...receipt, status: 'failed', errorCode: receipt.started ? 'delivery_unknown' : 'delivery_failed' } : receipt) }];
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private stalled(receipt: DispatchReceipt): boolean {
|
|
130
|
+
if (receipt.targetId === 'host-bridge') return Date.now() - Date.parse(receipt.updatedAt) > 30_000;
|
|
131
|
+
if (receipt.targetId.startsWith('orca-')) return this.bridges.get(receipt.targetId.slice(5))?.targetRef !== receipt.recipient;
|
|
132
|
+
return receipt.owner !== this.instance;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private async initialRecipient(input: DispatchDestination, browser: Browser): Promise<Recipient & { available: boolean }> {
|
|
136
|
+
if (input.hostTarget) {
|
|
137
|
+
return { targetId: 'host-bridge', targetName: hostName(input.hostKind), recipient: input.hostTarget, available: true };
|
|
138
|
+
}
|
|
139
|
+
const selected = input.ideId ?? await this.sessions.selectedIde(browser.session);
|
|
140
|
+
const targets = await this.available(browser.origin, browser.userAgent, true);
|
|
141
|
+
const ide = selected ? targets.find(item => item.ideId === selected) : targets[0];
|
|
142
|
+
const webhook = this.webhookTargetRef;
|
|
143
|
+
if (selected === 'webhook' || (!selected && !ide && webhook)) {
|
|
144
|
+
return { targetId: 'webhook', targetName: 'Webhook', recipient: input.targetRef ?? webhook ?? '',
|
|
145
|
+
available: Boolean(webhook && (!input.targetRef || input.targetRef === webhook)) };
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
targetId: ide?.ideId ?? selected ?? 'orca', targetName: ide?.ideLabel ?? 'Orca',
|
|
149
|
+
recipient: input.targetRef ?? ide?.currentAgent.targetRef ?? '',
|
|
150
|
+
available: Boolean(ide && (!input.targetRef || input.targetRef === ide.currentAgent.targetRef)),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async dispatch(threadId: string, input: z.infer<typeof requestDispatchSchema>, browser: Browser) {
|
|
155
|
+
const { workingCopyId, messageId } = input;
|
|
156
|
+
const thread = await this.options.review.getThread(workingCopyId, threadId);
|
|
157
|
+
if (!thread.messages.some(message => message.id === messageId && message.author === 'human')) {
|
|
158
|
+
throw new DesignError('missing_reference', 'Human comment message was not found');
|
|
159
|
+
}
|
|
160
|
+
const dispatchId = commentDispatchId(workingCopyId, threadId, messageId);
|
|
161
|
+
const existing = (await this.receipts.read())[dispatchId];
|
|
162
|
+
const retryable = (receipt: DispatchReceipt) => receipt.errorCode !== 'delivery_unknown'
|
|
163
|
+
&& (receipt.status === 'failed' || receipt.status === 'queued' && !receipt.started && this.stalled(receipt));
|
|
164
|
+
if (existing && (!input.retry || !retryable(existing))) return { dispatch: agentDispatchSchema.strip().parse(existing) };
|
|
165
|
+
const next = existing
|
|
166
|
+
? {
|
|
167
|
+
targetId: existing.targetId, targetName: existing.targetName, available: true,
|
|
168
|
+
// Older receipts identified the configured webhook without an endpoint fingerprint.
|
|
169
|
+
recipient: existing.targetId === 'webhook' && existing.recipient === 'webhook'
|
|
170
|
+
? this.webhookTargetRef ?? existing.recipient
|
|
171
|
+
: existing.recipient,
|
|
172
|
+
}
|
|
173
|
+
: await this.initialRecipient(input, browser);
|
|
174
|
+
const native = next.targetId === 'host-bridge';
|
|
175
|
+
if (native && (!browser.hostEnabled || (existing && existing.owner !== browser.session))) {
|
|
176
|
+
throw new DesignError('agent_unavailable', 'The original agent is unavailable');
|
|
177
|
+
}
|
|
178
|
+
const candidate: DispatchReceipt = {
|
|
179
|
+
dispatchId, workingCopyId, threadId, messageId,
|
|
180
|
+
targetId: next.targetId, targetName: next.targetName, recipient: next.recipient,
|
|
181
|
+
attempt: (existing?.attempt ?? 0) + 1, owner: native ? browser.session : this.instance,
|
|
182
|
+
started: false, status: next.available ? 'queued' : 'failed', updatedAt: new Date().toISOString(),
|
|
183
|
+
...(!next.available ? { errorCode: 'agent_unavailable' } : {}),
|
|
184
|
+
};
|
|
185
|
+
const saved = await this.receipts.change(dispatchId, previous => {
|
|
186
|
+
if (previous && (!input.retry || !retryable(previous) || previous.attempt !== existing?.attempt)) return previous;
|
|
187
|
+
return candidate;
|
|
188
|
+
});
|
|
189
|
+
const dispatch = agentDispatchSchema.strip().parse(saved);
|
|
190
|
+
if (saved !== candidate) return { dispatch };
|
|
191
|
+
await this.saveReview(saved);
|
|
192
|
+
if (!next.available) return { dispatch };
|
|
193
|
+
|
|
194
|
+
if (native) {
|
|
195
|
+
try {
|
|
196
|
+
const payload = await this.payload(saved, saved.targetName === hostName('orca') ? 'orca' : 'desktop');
|
|
197
|
+
const started = await this.claim(saved);
|
|
198
|
+
return started ? { dispatch, payload, attempt: saved.attempt } : { dispatch };
|
|
199
|
+
} catch {
|
|
200
|
+
return { dispatch: await this.complete(saved, { attempt: saved.attempt, delivered: false }) };
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
this.track(this.deliver(saved, browser));
|
|
205
|
+
return { dispatch };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private async claim(receipt: DispatchReceipt) {
|
|
209
|
+
const next = { ...receipt, started: true, updatedAt: new Date().toISOString() };
|
|
210
|
+
return await this.receipts.change(receipt.dispatchId, current => {
|
|
211
|
+
if (!current) throw new DesignError('missing_reference', 'Dispatch receipt was not found');
|
|
212
|
+
return current.status === 'queued' && !current.started && current.attempt === receipt.attempt ? next : current;
|
|
213
|
+
}) === next;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private async payload(receipt: DispatchReceipt, host: AgentCommentDispatchPayload['host']) {
|
|
217
|
+
const { workspace, review, renderer, origin } = this.options;
|
|
218
|
+
const thread = await review.getThread(receipt.workingCopyId, receipt.threadId);
|
|
219
|
+
return commentPayload(workspace, review, renderer, origin(), receipt, thread, host);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private track(task: Promise<unknown>): void {
|
|
223
|
+
this.pending.add(task);
|
|
224
|
+
void task.catch(() => undefined).finally(() => this.pending.delete(task));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private async deliver(receipt: DispatchReceipt, browser: { origin: string; userAgent: string }): Promise<void> {
|
|
228
|
+
const attempt = receipt.attempt;
|
|
229
|
+
let sending = false;
|
|
230
|
+
try {
|
|
231
|
+
const webhook = receipt.targetId === 'webhook' ? this.options.webhook : undefined;
|
|
232
|
+
if (receipt.targetId === 'webhook' && (!webhook || this.webhookTargetRef !== receipt.recipient)) {
|
|
233
|
+
throw new DesignError('agent_unavailable', 'The original webhook is unavailable');
|
|
234
|
+
}
|
|
235
|
+
const payload = await this.payload(receipt, webhook ? 'remote-webhook' : 'local-cli');
|
|
236
|
+
if (receipt.targetId.startsWith('orca-')) {
|
|
237
|
+
await this.offerToBridge(receipt, payload);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const run = !webhook && !this.options.remote ? await this.command() : undefined;
|
|
241
|
+
if (!webhook && !run) throw new DesignError('service_unavailable', 'Orca CLI is unavailable');
|
|
242
|
+
if (run) {
|
|
243
|
+
const current = await discoverOrca(run, browser.origin, browser.userAgent);
|
|
244
|
+
if (!current.some(item => item.currentAgent.targetRef === receipt.recipient)) {
|
|
245
|
+
throw new DesignError('missing_reference', 'The selected Orca agent is no longer active');
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
if (!await this.claim(receipt)) return;
|
|
249
|
+
sending = true;
|
|
250
|
+
const messageId = webhook
|
|
251
|
+
? await deliverWebhook(webhook, payload)
|
|
252
|
+
: run && await sendToOrca(run, this.options.workspace.stateDir, receipt.recipient, payload);
|
|
253
|
+
await this.complete(receipt, { attempt, delivered: true, ...(messageId ? { messageId } : {}) });
|
|
254
|
+
} catch (error) {
|
|
255
|
+
const uncertain = sending && receipt.targetId !== 'webhook' && !(error instanceof DesignError);
|
|
256
|
+
await this.complete(receipt, { attempt, delivered: false, uncertain });
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
private async complete(receipt: DispatchReceipt, result: Outcome) {
|
|
261
|
+
const updated = await this.receipts.change(receipt.dispatchId, current => {
|
|
262
|
+
if (!current) throw new DesignError('missing_reference', 'Dispatch receipt was not found');
|
|
263
|
+
if (current.status !== 'queued' || current.attempt !== result.attempt) return current;
|
|
264
|
+
return {
|
|
265
|
+
...current, status: result.delivered ? 'delivered' : 'failed', updatedAt: new Date().toISOString(),
|
|
266
|
+
...(result.messageId ? { externalMessageId: result.messageId } : {}),
|
|
267
|
+
...(!result.delivered ? { errorCode: result.uncertain ? 'delivery_unknown' : 'delivery_failed' } : {}),
|
|
268
|
+
};
|
|
269
|
+
});
|
|
270
|
+
return this.saveReview(updated);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
async acknowledge(id: string, result: Outcome, browserSession: string | undefined, bridgeId?: string) {
|
|
274
|
+
const receipt = (await this.receipts.read())[id];
|
|
275
|
+
const matches = bridgeId ? receipt?.targetId === 'orca-' + bridgeId
|
|
276
|
+
: receipt?.targetId === 'host-bridge' && receipt.owner === browserSession;
|
|
277
|
+
if (!receipt?.started || !matches) throw new DesignError('missing_reference', 'Dispatch was not assigned to this channel');
|
|
278
|
+
return this.complete(receipt, result);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
private async offerToBridge(receipt: DispatchReceipt, payload: AgentCommentDispatchPayload) {
|
|
282
|
+
const bridge = this.bridges.get(receipt.targetId.slice(5));
|
|
283
|
+
if (!bridge || bridge.targetRef !== receipt.recipient) {
|
|
284
|
+
if (!receipt.started) await this.complete(receipt, { attempt: receipt.attempt, delivered: false });
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
if (!receipt.started && !await this.claim(receipt)) return;
|
|
288
|
+
if (!bridge.response.writableEnded && !bridge.response.writableNeedDrain) {
|
|
289
|
+
bridge.response.write(`event: comment\ndata: ${JSON.stringify({ attempt: receipt.attempt, payload })}\n\n`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
registerBridge(registration: z.infer<typeof bridgeRegistrationSchema>, response: ServerResponse): void {
|
|
294
|
+
if (!this.bridges.has(registration.bridgeId) && this.bridges.size >= 16) {
|
|
295
|
+
throw new DesignError('resource_limit', 'Bridge connection capacity is full');
|
|
296
|
+
}
|
|
297
|
+
this.bridges.get(registration.bridgeId)?.response.end();
|
|
298
|
+
const bridge: Bridge = { ...registration, response };
|
|
299
|
+
this.bridges.set(registration.bridgeId, bridge);
|
|
300
|
+
response.writeHead(200, { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-store', 'X-Accel-Buffering': 'no' });
|
|
301
|
+
response.write(': connected\n\n');
|
|
302
|
+
const interval = setInterval(() => {
|
|
303
|
+
if (response.writableNeedDrain) response.end();
|
|
304
|
+
else response.write(': heartbeat\n\n');
|
|
305
|
+
}, 10_000);
|
|
306
|
+
response.on('close', () => {
|
|
307
|
+
clearInterval(interval);
|
|
308
|
+
if (this.bridges.get(bridge.bridgeId) === bridge) this.bridges.delete(bridge.bridgeId);
|
|
309
|
+
});
|
|
310
|
+
this.track((async () => {
|
|
311
|
+
const records = Object.values(await this.receipts.read()).filter(item =>
|
|
312
|
+
item.targetId === 'orca-' + bridge.bridgeId && item.status === 'queued' && item.recipient === bridge.targetRef);
|
|
313
|
+
for (const receipt of records) {
|
|
314
|
+
if (response.writableEnded) return;
|
|
315
|
+
await this.offerToBridge(receipt, await this.payload(receipt, 'local-cli'));
|
|
316
|
+
}
|
|
317
|
+
})());
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
close() {
|
|
321
|
+
for (const bridge of this.bridges.values()) bridge.response.end();
|
|
322
|
+
this.bridges.clear();
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
async drain() { await Promise.allSettled(this.pending); }
|
|
326
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { dispatchIdSchema, ideSelectionSchema, requestDispatchSchema } from '../../contracts/agent-targets.js';
|
|
4
|
+
import { DesignError, idSchema } from '../../contracts/common.js';
|
|
5
|
+
import type { OperationActor } from '../../contracts/operations.js';
|
|
6
|
+
import { bridgeRegistrationSchema, dispatchResultSchema, type AgentDispatchService } from './dispatch.js';
|
|
7
|
+
|
|
8
|
+
function parse<T>(schema: z.ZodType<T>, input: unknown): T {
|
|
9
|
+
const result = schema.safeParse(input);
|
|
10
|
+
if (!result.success) throw new DesignError('invalid_input', 'Invalid agent delivery request');
|
|
11
|
+
return result.data;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function agentRoute(options: {
|
|
15
|
+
request: IncomingMessage; response: ServerResponse; url: URL; origin: string; actor: OperationActor;
|
|
16
|
+
agentDispatch: AgentDispatchService; remote: boolean; hostEnabled: boolean; body: () => Promise<unknown>;
|
|
17
|
+
send: (value: unknown) => void;
|
|
18
|
+
}): Promise<boolean> {
|
|
19
|
+
const { request, response, url, origin, actor, agentDispatch, remote, hostEnabled, body, send } = options;
|
|
20
|
+
const { method } = request, pathname = url.pathname;
|
|
21
|
+
const userAgent = request.headers['user-agent'] ?? '';
|
|
22
|
+
const user = () => {
|
|
23
|
+
if (actor.kind !== 'human') throw new DesignError('forbidden', 'Human identity required');
|
|
24
|
+
return actor.uiSession;
|
|
25
|
+
};
|
|
26
|
+
const session = () => {
|
|
27
|
+
const id = user();
|
|
28
|
+
if (!id) throw new DesignError('invalid_input', 'A browser session is required');
|
|
29
|
+
return id;
|
|
30
|
+
};
|
|
31
|
+
if (pathname === '/api/agent-targets' && method === 'GET') {
|
|
32
|
+
send(await agentDispatch.targets(user(), origin, userAgent)); return true;
|
|
33
|
+
}
|
|
34
|
+
if (['/api/agent-targets', '/api/agent-targets/select', '/api/ui-session/ide-target'].includes(pathname) && method === 'POST') {
|
|
35
|
+
const id = session();
|
|
36
|
+
const { ideId } = parse(ideSelectionSchema, await body());
|
|
37
|
+
await agentDispatch.select(id, ideId, origin, userAgent);
|
|
38
|
+
send({ ok: true }); return true;
|
|
39
|
+
}
|
|
40
|
+
const dispatch = /^\/api\/comments\/([^/]+)\/dispatch-agent$/.exec(pathname);
|
|
41
|
+
if (dispatch && method === 'POST') {
|
|
42
|
+
const id = session();
|
|
43
|
+
const input = parse(requestDispatchSchema, await body());
|
|
44
|
+
if (input.hostTarget && (!hostEnabled || remote)) throw new DesignError('forbidden', 'Native host is unavailable');
|
|
45
|
+
send(await agentDispatch.dispatch(parse(idSchema, dispatch[1]), input, {
|
|
46
|
+
session: id, origin, userAgent, hostEnabled: hostEnabled && !remote,
|
|
47
|
+
}));
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
const statuses = /^\/api\/working-copies\/([^/]+)\/comments\/([^/]+)\/dispatches$/.exec(pathname);
|
|
51
|
+
if (statuses && method === 'GET') {
|
|
52
|
+
user();
|
|
53
|
+
send(await agentDispatch.statuses(parse(idSchema, statuses[1]), parse(idSchema, statuses[2])));
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
if (pathname === '/api/orca-bridge/events' && method === 'POST' && remote) {
|
|
57
|
+
if (actor.kind !== 'agent') throw new DesignError('forbidden', 'Bridge agent credential required');
|
|
58
|
+
agentDispatch.registerBridge(parse(bridgeRegistrationSchema, await body()), response);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
const outcome = /^\/api\/(agent-dispatch|orca-bridge)\/([^/]+)\/result$/.exec(pathname);
|
|
62
|
+
if (outcome && method === 'POST') {
|
|
63
|
+
const dispatchId = parse(dispatchIdSchema, outcome[2]);
|
|
64
|
+
if (outcome[1] === 'orca-bridge') {
|
|
65
|
+
if (!remote || actor.kind !== 'agent') throw new DesignError('forbidden', 'Bridge agent credential required');
|
|
66
|
+
const { bridgeId, ...result } = parse(dispatchResultSchema.extend({ bridgeId: bridgeRegistrationSchema.shape.bridgeId }), await body());
|
|
67
|
+
send(await agentDispatch.acknowledge(dispatchId, result, undefined, bridgeId));
|
|
68
|
+
} else {
|
|
69
|
+
const id = session();
|
|
70
|
+
if (!hostEnabled || remote) throw new DesignError('forbidden', 'Native host is unavailable');
|
|
71
|
+
send(await agentDispatch.acknowledge(dispatchId, parse(dispatchResultSchema, await body()), id));
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { DesignError } from '../../contracts/common.js';
|
|
5
|
+
import { validateOrigin } from '../../contracts/origins.js';
|
|
6
|
+
import { acquireSourceLock } from '../../project/locks.js';
|
|
7
|
+
import { atomicProjectWrite, isMissing, readProjectBytes } from '../../project/paths.js';
|
|
8
|
+
import { discoverOrca, orcaCommand, resolveOrcaCli, sendToOrca, type OrcaCommand } from './orca.js';
|
|
9
|
+
import { dispatchPayloadSchema } from './payload.js';
|
|
10
|
+
|
|
11
|
+
const eventSchema = z.strictObject({ attempt: z.number().int().positive(), payload: dispatchPayloadSchema });
|
|
12
|
+
const outcomeSchema = z.strictObject({
|
|
13
|
+
delivered: z.boolean(), messageId: z.string().optional(), uncertain: z.boolean().optional(),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export async function* commentEvents(body: ReadableStream<Uint8Array>) {
|
|
17
|
+
const reader = body.getReader();
|
|
18
|
+
const decoder = new TextDecoder();
|
|
19
|
+
let buffer = '';
|
|
20
|
+
try {
|
|
21
|
+
for (;;) {
|
|
22
|
+
const chunk = await reader.read();
|
|
23
|
+
if (chunk.done) return;
|
|
24
|
+
buffer += decoder.decode(chunk.value, { stream: true });
|
|
25
|
+
if (buffer.length > 12 * 1024 * 1024) throw new DesignError('resource_limit', 'Bridge event is too large');
|
|
26
|
+
let end: number;
|
|
27
|
+
while ((end = buffer.indexOf('\n\n')) >= 0) {
|
|
28
|
+
const block = buffer.slice(0, end);
|
|
29
|
+
buffer = buffer.slice(end + 2);
|
|
30
|
+
const lines = block.split('\n');
|
|
31
|
+
if (!lines.includes('event: comment')) continue;
|
|
32
|
+
const data = lines.filter(line => line.startsWith('data: ')).map(line => line.slice(6)).join('\n');
|
|
33
|
+
const event = eventSchema.safeParse(JSON.parse(data));
|
|
34
|
+
if (!event.success) throw new DesignError('invalid_input', 'Invalid bridge event');
|
|
35
|
+
yield event.data;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
} finally { await reader.cancel().catch(() => undefined); reader.releaseLock(); }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function saved<T>(directory: string, file: string, schema: z.ZodType<T>) {
|
|
42
|
+
try { return schema.parse(JSON.parse((await readProjectBytes(directory, file, true)).toString())); }
|
|
43
|
+
catch (error) { if (isMissing(error)) return undefined; throw error; }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function forwardBridgeEvent(event: z.infer<typeof eventSchema>, options: {
|
|
47
|
+
origin: string; targetRef: string; directory: string; run: OrcaCommand;
|
|
48
|
+
}): Promise<z.infer<typeof outcomeSchema>> {
|
|
49
|
+
const { payload, attempt } = event;
|
|
50
|
+
if (new URL(payload.deepLink).origin !== options.origin || payload.targetAgentId !== options.targetRef) {
|
|
51
|
+
return { delivered: false };
|
|
52
|
+
}
|
|
53
|
+
const filename = `orca-bridge/outcomes/${payload.dispatchId}.${attempt}.json`;
|
|
54
|
+
const previous = await saved(options.directory, filename, outcomeSchema);
|
|
55
|
+
if (previous) return previous;
|
|
56
|
+
const target = (await discoverOrca(options.run, options.origin, 'Electron/1.0').catch(() => []))[0];
|
|
57
|
+
if (target?.currentAgent.targetRef !== options.targetRef) return { delivered: false };
|
|
58
|
+
const unknown = { delivered: false, uncertain: true };
|
|
59
|
+
await atomicProjectWrite(options.directory, filename, JSON.stringify(unknown), true);
|
|
60
|
+
let outcome: z.infer<typeof outcomeSchema>;
|
|
61
|
+
try {
|
|
62
|
+
const messageId = await sendToOrca(options.run, options.directory, options.targetRef, payload);
|
|
63
|
+
outcome = { delivered: true, ...(messageId ? { messageId } : {}) };
|
|
64
|
+
} catch (error) {
|
|
65
|
+
outcome = error instanceof DesignError ? { delivered: false } : unknown;
|
|
66
|
+
}
|
|
67
|
+
await atomicProjectWrite(options.directory, filename, JSON.stringify(outcome), true);
|
|
68
|
+
return outcome;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function runOrcaBridge(options: {
|
|
72
|
+
directory: string; origin: string; token: string; signal: AbortSignal; allowPrivateHttp?: boolean;
|
|
73
|
+
command?: OrcaCommand; request?: typeof fetch;
|
|
74
|
+
}): Promise<void> {
|
|
75
|
+
validateOrigin(options.origin, 'remote', options.allowPrivateHttp);
|
|
76
|
+
if (!options.token) throw new DesignError('unauthorized', 'Set DESIGN_AGENT_TOKEN for the bridge');
|
|
77
|
+
const { directory, origin, signal } = options;
|
|
78
|
+
const request = options.request ?? fetch;
|
|
79
|
+
const executable = options.command ? undefined : await resolveOrcaCli();
|
|
80
|
+
const run = options.command ?? (executable && orcaCommand(executable));
|
|
81
|
+
if (!run) throw new DesignError('service_unavailable', 'Orca CLI was not found');
|
|
82
|
+
const originKey = createHash('sha256').update(origin).digest('hex');
|
|
83
|
+
const key = `orca-bridge/${originKey}.json`;
|
|
84
|
+
const release = await acquireSourceLock(directory, `orca-bridge/${originKey}.lock`);
|
|
85
|
+
const headers = { Authorization: 'Bearer ' + options.token, 'Content-Type': 'application/json' };
|
|
86
|
+
try {
|
|
87
|
+
const bridgeId = await saved(directory, key, z.uuid({ version: 'v4' })) ?? randomUUID();
|
|
88
|
+
await atomicProjectWrite(directory, key, JSON.stringify(bridgeId), true);
|
|
89
|
+
while (!signal.aborted) {
|
|
90
|
+
const target = (await discoverOrca(run, origin, 'Electron/1.0').catch(() => []))[0]?.currentAgent;
|
|
91
|
+
if (target) {
|
|
92
|
+
const renew = new AbortController();
|
|
93
|
+
const watch = setInterval(() => {
|
|
94
|
+
void discoverOrca(run, origin, 'Electron/1.0').then(targets => {
|
|
95
|
+
if (targets[0]?.currentAgent.targetRef !== target.targetRef) renew.abort();
|
|
96
|
+
}, () => renew.abort());
|
|
97
|
+
}, 4000);
|
|
98
|
+
try {
|
|
99
|
+
const response = await request(origin + '/api/orca-bridge/events', {
|
|
100
|
+
method: 'POST', redirect: 'error', headers,
|
|
101
|
+
body: JSON.stringify({ bridgeId, agentName: target.agentName, targetRef: target.targetRef }),
|
|
102
|
+
signal: AbortSignal.any([signal, renew.signal]),
|
|
103
|
+
});
|
|
104
|
+
if (response.status === 401 || response.status === 403) throw new DesignError('unauthorized', 'Remote server rejected the bridge credential');
|
|
105
|
+
if (!response.ok || !response.body || !response.headers.get('Content-Type')?.startsWith('text/event-stream')) {
|
|
106
|
+
await response.body?.cancel();
|
|
107
|
+
throw new DesignError('service_unavailable', 'Remote server did not open the bridge stream');
|
|
108
|
+
}
|
|
109
|
+
for await (const event of commentEvents(response.body)) {
|
|
110
|
+
const result = await forwardBridgeEvent(event, { origin, directory, run, targetRef: target.targetRef });
|
|
111
|
+
const ack = await request(`${origin}/api/orca-bridge/${event.payload.dispatchId}/result`, {
|
|
112
|
+
method: 'POST', redirect: 'error', headers, signal: AbortSignal.any([signal, AbortSignal.timeout(8000)]),
|
|
113
|
+
body: JSON.stringify({ bridgeId, attempt: event.attempt, ...result }),
|
|
114
|
+
});
|
|
115
|
+
await ack.body?.cancel();
|
|
116
|
+
if (ack.status === 401 || ack.status === 403) throw new DesignError('unauthorized', 'Remote server rejected the bridge credential');
|
|
117
|
+
if (!ack.ok) throw new DesignError('service_unavailable', 'Remote server did not acknowledge the receipt');
|
|
118
|
+
}
|
|
119
|
+
} catch (error) {
|
|
120
|
+
if (error instanceof DesignError && error.code === 'unauthorized') throw error;
|
|
121
|
+
} finally { clearInterval(watch); renew.abort(); }
|
|
122
|
+
}
|
|
123
|
+
await delay(2000, undefined, { signal }).catch(() => undefined);
|
|
124
|
+
}
|
|
125
|
+
} finally { await release(); }
|
|
126
|
+
}
|