diff --git a/specs/22_should-add-support-for-cloud-compute/.issue-flow-state.json b/specs/22_should-add-support-for-cloud-compute/.issue-flow-state.json new file mode 100644 index 00000000..1ea30c14 --- /dev/null +++ b/specs/22_should-add-support-for-cloud-compute/.issue-flow-state.json @@ -0,0 +1,423 @@ +{ + "version": 4, + "updated_at": "2026-04-08T14:39:28Z", + "issue": { + "number": "22", + "url": "https://github.com/Flow-Research/Jarvis/issues/22", + "title": "should add support for cloud compute" + }, + "epic": { + "name": "22_should-add-support-for-cloud-compute", + "path": "specs/22_should-add-support-for-cloud-compute", + "spec_root": "specs" + }, + "phase": { + "id": 7, + "name": "Phase 7 \u2014 Tech spec review", + "status": "paused_awaiting_instruction", + "started_at": "2026-04-08T14:36:45Z", + "updated_at": "2026-04-08T14:39:28Z" + }, + "mode": "discovery-recovery", + "git": { + "branch": "22_should-add-support-for-cloud-compute", + "base_branch": "main", + "worktree_strategy": "sibling-project-worktrees-v1", + "worktree_dirname": "22_should-add-support-for-cloud-compute" + }, + "github": { + "issue_state": "open", + "project_status": null, + "project_title": null, + "pr_url": "https://github.com/Flow-Research/Jarvis/pull/28", + "ci_url": null, + "last_sync_at": "2026-04-08T14:39:28Z", + "gh_available": true, + "issue_assignees": ["catchmeifyoucaan", "ojogu"], + "issue_labels": [] + }, + "gates": { + "quality": { + "issue_readiness_check": "passed", + "issue_clarification_recovery_gate": "passed", + "brainstorm_discovery_gate": "passed", + "spec_gate": "passed", + "design_completeness_gate": "passed", + "design_simplicity_gate": "passed", + "regression_coverage_gate": "pending", + "generated_test_gate": "pending", + "test_quality_gate": "pending", + "qa_execution_gate": "pending", + "implementation_simplicity_gate": "pending", + "final_verification_gate": "pending" + }, + "human": { + "brainstorm_approval": "passed", + "issue_append_approval": "passed", + "prd_approval": "passed", + "design_approval": "passed", + "tech_spec_approval": "passed", + "execution_scope_approval": "pending", + "final_acceptance": "pending" + } + }, + "artifacts": { + "issue_intake": "specs/22_should-add-support-for-cloud-compute/issue_intake.md", + "brainstorm": null, + "brainstorm_transcript": "specs/22_should-add-support-for-cloud-compute/brainstorm_transcript.md", + "issue_body_draft": "specs/22_should-add-support-for-cloud-compute/issue_body_draft.md", + "product_spec": "specs/22_should-add-support-for-cloud-compute/product_spec.md", + "prd_review_summary": "specs/22_should-add-support-for-cloud-compute/prd_review_summary.md", + "design_spec": "specs/22_should-add-support-for-cloud-compute/design_spec.md", + "design_review_summary": "specs/22_should-add-support-for-cloud-compute/design_review_summary.md", + "technical_spec": "specs/22_should-add-support-for-cloud-compute/technical_spec.md", + "techspec_review_summary": "specs/22_should-add-support-for-cloud-compute/techspec_review_summary.md", + "regression_spec": null, + "api_tests": [], + "browser_tests": [], + "test_quality_report": null, + "qa_summary": null, + "qa_logs": [], + "verification_report": null + }, + "artifact_commits": { + "product_spec": { + "committed": true, + "commit_sha": "78495f4c63886d65e5c9145a5256eff73af7993f", + "pushed": true, + "github_comment_posted": true, + "github_comment_url": "https://github.com/Flow-Research/Jarvis/issues/22#issuecomment-4171936263", + "pr_created": true, + "pr_url": "https://github.com/Flow-Research/Jarvis/pull/28", + "skipped": false, + "timestamp": "2026-04-01T17:55:12Z" + }, + "design_spec": { + "committed": true, + "commit_sha": "5c66802ee7111341b9417de5c48cc1b5904cbf61", + "pushed": true, + "github_comment_posted": true, + "github_comment_url": "https://github.com/Flow-Research/Jarvis/issues/22#issuecomment-4207018362", + "pr_created": false, + "pr_url": "https://github.com/Flow-Research/Jarvis/pull/28", + "skipped": false, + "timestamp": "2026-04-08T14:30:12Z" + }, + "technical_spec": { + "committed": true, + "commit_sha": "28a759901e6a38e45dd1955ba12e1ff11a59728a", + "pushed": true, + "github_comment_posted": true, + "github_comment_url": "https://github.com/Flow-Research/Jarvis/issues/22#issuecomment-4207082264", + "pr_created": false, + "pr_url": "https://github.com/Flow-Research/Jarvis/pull/28", + "skipped": false, + "timestamp": "2026-04-08T14:39:28Z" + }, + "regression_spec": { + "committed": false, + "skipped": false + } + }, + "reconciliation": { + "last_checked_at": "2026-04-01T17:48:25Z", + "status": "reconciled", + "discrepancies": [], + "resolution_notes": [ + "Reconciled on 2026-04-01: GitHub auth verified and issue metadata refreshed.", + "Reconciled on 2026-04-01: issue clarification appended on GitHub and brainstorm approvals captured." + ] + }, + "blockers": [], + "next_action": "Await explicit user instruction to start implementation planning.", + "history": [ + { + "timestamp": "2026-03-27T14:07:12Z", + "event": "state_initialized", + "phase_id": 0, + "phase_name": "Phase 0 \u2014 Intake, readiness check, and clarification recovery", + "details": "Initialized issue-flow state file.", + "source": "issue-flow" + }, + { + "timestamp": "2026-03-27T14:08:46Z", + "event": "phase0_intake_completed", + "phase_id": 0, + "phase_name": "Phase 0 \u2014 Intake, readiness check, and clarification recovery", + "details": "Completed intake; classified as discovery-recovery with strategy unavailable and testability gaps.", + "source": "issue-flow" + }, + { + "timestamp": "2026-03-27T14:09:15Z", + "event": "phase_transition", + "phase_id": 1, + "phase_name": "Phase 1 \u2014 Brainstorm", + "details": "Transitioned from Phase 0 to Phase 1 after passing issue_readiness_check.", + "source": "issue-flow" + }, + { + "timestamp": "2026-03-27T14:10:55Z", + "event": "brainstorm_question_asked", + "phase_id": 1, + "phase_name": "Phase 1 \u2014 Brainstorm", + "details": "Asked Q1 about minimum shippable slice boundaries.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-01T00:00:00Z", + "event": "reconciliation_update", + "phase_id": 1, + "phase_name": "Phase 1 \u2014 Brainstorm", + "details": "Refreshed issue metadata and recorded Q1 answer (full hosted + local end-to-end).", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-01T00:15:00Z", + "event": "brainstorm_answer_recorded", + "phase_id": 1, + "phase_name": "Phase 1 \u2014 Brainstorm", + "details": "Recorded Q2 answer: use provider wizard with EigenCloud, DigitalOcean, and AWS (not EigenCloud-only).", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-01T00:25:00Z", + "event": "brainstorm_answer_recorded", + "phase_id": 1, + "phase_name": "Phase 1 \u2014 Brainstorm", + "details": "Recorded Q3 answer: local provider fallback behavior must be configurable (auto-fallback or explicit selection).", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-01T00:35:00Z", + "event": "brainstorm_answer_recorded", + "phase_id": 1, + "phase_name": "Phase 1 \u2014 Brainstorm", + "details": "Recorded Q4 answer: MVP must include real provisioning integration for EigenCloud, AWS, and DigitalOcean.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-01T00:45:00Z", + "event": "brainstorm_answer_recorded", + "phase_id": 1, + "phase_name": "Phase 1 \u2014 Brainstorm", + "details": "Recorded Q5 answer: liveness target is sandbox creation under 60 seconds plus provider healthcheck pass for each provider.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-01T01:00:00Z", + "event": "brainstorm_answer_recorded", + "phase_id": 1, + "phase_name": "Phase 1 \u2014 Brainstorm", + "details": "Recorded Q6 answer: local fallback default must be ON.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-01T01:00:00Z", + "event": "issue_clarification_draft_created", + "phase_id": 1, + "phase_name": "Phase 1 \u2014 Brainstorm", + "details": "Created append-only issue clarification draft with testable acceptance criteria.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-01T17:48:25Z", + "event": "issue_clarification_appended", + "phase_id": 1, + "phase_name": "Phase 1 \u2014 Brainstorm", + "details": "Posted clarification comment to issue #22: https://github.com/Flow-Research/Jarvis/issues/22#issuecomment-4171883359", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-01T17:48:25Z", + "event": "brainstorm_approval_recorded", + "phase_id": 1, + "phase_name": "Phase 1 \u2014 Brainstorm", + "details": "User approved brainstorm outputs and issue clarification append; human gates marked passed.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-01T17:48:25Z", + "event": "phase_transition", + "phase_id": 2, + "phase_name": "Phase 2 \u2014 PRD", + "details": "Transitioned from Phase 1 to Phase 2 after passing clarification and brainstorm gates.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-01T17:50:42Z", + "event": "product_spec_created", + "phase_id": 2, + "phase_name": "Phase 2 \u2014 PRD", + "details": "Created product_spec.md with explicit acceptance criteria and provider/fallback requirements.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-01T17:50:42Z", + "event": "phase_transition", + "phase_id": 3, + "phase_name": "Phase 3 \u2014 PRD review", + "details": "Transitioned from Phase 2 to Phase 3 after PRD generation.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-01T17:50:42Z", + "event": "prd_review_completed", + "phase_id": 3, + "phase_name": "Phase 3 \u2014 PRD review", + "details": "Created prd_review_summary.md; review found no blocking issues and spec_gate passed.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-01T17:55:12Z", + "event": "prd_approval_recorded", + "phase_id": 3, + "phase_name": "Phase 3 \u2014 PRD review", + "details": "User approval recorded for PRD.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-01T17:55:12Z", + "event": "artifact_commit_and_link_completed", + "phase_id": 3, + "phase_name": "Phase 3 \u2014 PRD review", + "details": "Committed product_spec.md at 78495f4c63886d65e5c9145a5256eff73af7993f, pushed branch, posted issue link, and opened PR #28.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-01T17:55:12Z", + "event": "phase_paused", + "phase_id": 3, + "phase_name": "Phase 3 \u2014 PRD review", + "details": "Pause protocol applied. Awaiting explicit user instruction: start design spec.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-08T14:28:26Z", + "event": "phase_transition", + "phase_id": 4, + "phase_name": "Phase 4 \u2014 Design specification", + "details": "Transitioned from Phase 3 to Phase 4 after explicit user instruction to continue.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-08T14:28:26Z", + "event": "design_spec_created", + "phase_id": 4, + "phase_name": "Phase 4 \u2014 Design specification", + "details": "Created design_spec.md with user flows, screen inventory, component specs, interaction patterns, accessibility, and responsive behavior.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-08T14:28:26Z", + "event": "phase_transition", + "phase_id": 5, + "phase_name": "Phase 5 \u2014 Design review", + "details": "Transitioned from Phase 4 to Phase 5 after design specification generation.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-08T14:28:26Z", + "event": "design_review_completed", + "phase_id": 5, + "phase_name": "Phase 5 \u2014 Design review", + "details": "Created design_review_summary.md and passed design_completeness_gate with no blocking findings.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-08T14:28:26Z", + "event": "phase_paused", + "phase_id": 5, + "phase_name": "Phase 5 \u2014 Design review", + "details": "Awaiting human gate design_approval before tech spec can start.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-08T14:30:12Z", + "event": "design_approval_recorded", + "phase_id": 5, + "phase_name": "Phase 5 \u2014 Design review", + "details": "User approval recorded for design spec.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-08T14:30:12Z", + "event": "artifact_commit_and_link_completed", + "phase_id": 5, + "phase_name": "Phase 5 \u2014 Design review", + "details": "Committed design_spec.md at 5c66802ee7111341b9417de5c48cc1b5904cbf61, pushed branch, posted issue link, and updated PR #28 checklist.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-08T14:30:12Z", + "event": "phase_paused", + "phase_id": 5, + "phase_name": "Phase 5 \u2014 Design review", + "details": "Pause protocol applied. Awaiting explicit user instruction: start tech spec.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-08T14:36:45Z", + "event": "phase_transition", + "phase_id": 6, + "phase_name": "Phase 6 \u2014 Tech spec", + "details": "Transitioned from Phase 5 to Phase 6 after explicit user instruction to start tech spec.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-08T14:36:45Z", + "event": "technical_spec_created", + "phase_id": 6, + "phase_name": "Phase 6 \u2014 Tech spec", + "details": "Created technical_spec.md with architecture, file-level implementation plan, fallback behavior, and test matrix.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-08T14:36:45Z", + "event": "phase_transition", + "phase_id": 7, + "phase_name": "Phase 7 \u2014 Tech spec review", + "details": "Transitioned from Phase 6 to Phase 7 after technical spec generation.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-08T14:36:45Z", + "event": "techspec_review_completed", + "phase_id": 7, + "phase_name": "Phase 7 \u2014 Tech spec review", + "details": "Created techspec_review_summary.md; design_simplicity_gate passed with no blocking architecture issues.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-08T14:36:45Z", + "event": "phase_paused", + "phase_id": 7, + "phase_name": "Phase 7 \u2014 Tech spec review", + "details": "Awaiting human gate tech_spec_approval before implementation planning can start.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-08T14:39:28Z", + "event": "tech_spec_approval_recorded", + "phase_id": 7, + "phase_name": "Phase 7 \u2014 Tech spec review", + "details": "User approval recorded for technical spec.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-08T14:39:28Z", + "event": "artifact_commit_and_link_completed", + "phase_id": 7, + "phase_name": "Phase 7 \u2014 Tech spec review", + "details": "Technical spec artifact recorded at 28a759901e6a38e45dd1955ba12e1ff11a59728a, issue link posted, and PR #28 checklist updated.", + "source": "issue-flow" + }, + { + "timestamp": "2026-04-08T14:39:28Z", + "event": "phase_paused", + "phase_id": 7, + "phase_name": "Phase 7 \u2014 Tech spec review", + "details": "Pause protocol applied. Awaiting explicit user instruction: start implementation planning.", + "source": "issue-flow" + } + ] +} diff --git a/specs/22_should-add-support-for-cloud-compute/brainstorm_transcript.md b/specs/22_should-add-support-for-cloud-compute/brainstorm_transcript.md new file mode 100644 index 00000000..c09d43fa --- /dev/null +++ b/specs/22_should-add-support-for-cloud-compute/brainstorm_transcript.md @@ -0,0 +1,72 @@ +# Brainstorm Transcript: Issue #22 + +## Session + +- Date: 2026-03-27 +- Mode: discovery-recovery +- Goal: close testability gaps so acceptance criteria become implementation-ready. + +## Q1 + +What is the minimum shippable slice for this issue: + +1. abstraction/interface scaffolding only, +2. abstraction + one hosted provider integration (EigenCompute), or +3. abstraction + hosted + local fully wired end-to-end? + +### A1 + +`3` - abstraction + hosted + local fully wired end-to-end. + +## Q2 + +For hosted provider scope in this issue, should it be: +A) EigenCloud only, or +B) provider wizard with multiple hosted providers? + +### A2 + +Provider wizard with multiple hosted providers, not EigenCloud only. +Initial targets: EigenCloud, DigitalOcean, and AWS. + +## Q3 + +For local provider behavior, what is the required rule for this issue? +A) auto-fallback to local when cloud is unavailable +B) no auto-fallback, explicit local selection only +C) both with a configurable toggle + +### A3 + +`C` - both with a configurable toggle. + +## Q4 + +For this issue's MVP depth: +A) real provisioning integration for EigenCloud, AWS, and DigitalOcean, or +B) provider wizard + provider interface + validated adapter wiring, with real provisioning for one provider and stubs for others. + +### A4 + +`A` - real provisioning integration for EigenCloud, AWS, and DigitalOcean. + +## Q5 + +Pick the minimum liveness acceptance target for this issue: +A) successful sandbox creation in < 120s for each provider + healthcheck pass +B) successful sandbox creation in < 60s for each provider + healthcheck pass +C) custom target + +### A5 + +`B` - successful sandbox creation in < 60s for each provider + healthcheck pass. + +## Q6 + +For the configurable local fallback toggle, what should be the default? +A) default ON (auto-fallback to local when cloud fails) +B) default OFF (explicit local selection required) + +### A6 + +`A` - default ON (auto-fallback to local when cloud fails). diff --git a/specs/22_should-add-support-for-cloud-compute/design_review_summary.md b/specs/22_should-add-support-for-cloud-compute/design_review_summary.md new file mode 100644 index 00000000..9b2d30b0 --- /dev/null +++ b/specs/22_should-add-support-for-cloud-compute/design_review_summary.md @@ -0,0 +1,48 @@ +# Design Review Summary: Issue #22 + +## Metadata + +- Date: 2026-04-08 +- Input: `specs/22_should-add-support-for-cloud-compute/design_spec.md` +- Phase: 5 (Design review) + +## Lens 1: UX Research + +- Primary user goals are represented: selection, configuration, status visibility, and failure recovery. +- Flow accounts for first-time setup and settings-based updates. +- No blocker found. + +## Lens 2: Interaction Design + +- End-to-end flow is deterministic and includes fallback branches. +- Step transitions and disable/enable rules for submission are explicit. +- No blocker found. + +## Lens 3: Accessibility + +- Keyboard navigation, labels, live-region updates, and non-color status indicators are defined. +- Mobile touch target and responsive constraints are included. +- No blocker found. + +## Lens 4: Visual/Brand + +- Component inventory is cohesive and supports clear status storytelling. +- Placeholder references exist for visual design handoff artifacts. +- No blocker found. + +## Lens 5: Frontend Engineering + +- Components are decomposed into implementable units (`ProviderSelector`, `ProviderConfigForm`, `FallbackPolicyToggle`, `ProvisioningTimeline`). +- State and behavior boundaries are clear for implementation and testing. +- No blocker found. + +## Gate Decision + +- `design_completeness_gate`: **passed** +- `design_approval`: **pending human approval** + +## Non-Blocking Follow-Ups + +- Finalize exact field schema names during technical spec phase. +- Define canonical provider ordering constant to avoid UI drift. +- Confirm copy strings with docs/content owner before implementation freeze. diff --git a/specs/22_should-add-support-for-cloud-compute/design_spec.md b/specs/22_should-add-support-for-cloud-compute/design_spec.md new file mode 100644 index 00000000..c02edcfa --- /dev/null +++ b/specs/22_should-add-support-for-cloud-compute/design_spec.md @@ -0,0 +1,347 @@ +# Design Spec: Cloud Compute Provider Wizard and Provisioning UX + +## Metadata + +- Issue: https://github.com/Flow-Research/Jarvis/issues/22 +- PRD source: `specs/22_should-add-support-for-cloud-compute/product_spec.md` +- Date: 2026-04-08 +- Phase: 4 (Design specification) + +## Design Goals + +- Make provider selection explicit, low-friction, and reversible. +- Use one user-facing flow regardless of provider while preserving provider-specific configuration. +- Keep local provider as a first-class option. +- Make fallback behavior understandable and configurable without hidden automation. +- Expose provisioning and healthcheck status with clear outcomes and timings. +- Surface provider class differences honestly so EigenCloud is not presented as just another SSH/VM provider. + +## Primary Users + +- Operator setting up compute for a new workspace. +- Existing user updating compute provider in settings. +- Platform maintainer diagnosing provider provisioning failures. + +## Information Architecture + +- Entry points: + - Onboarding wizard step: `Compute Provider` + - Settings page: `Compute` -> `Provider` tab +- Primary sections: + - Provider Selection + - Provider Configuration + - Fallback Policy + - Provisioning Status and Result + - Provider Healthcheck Status + - Evidence / Attestation Status (when supported) + +## User Flow Diagram + +```mermaid +flowchart TD + A[Open Compute Setup] --> B{Choose Provider} + B -->|Local| C[Show Local Summary] + B -->|EigenCloud| D[Show Hosted Attested App Form] + B -->|AWS| E[Show Hosted VM Form] + B -->|DigitalOcean| F[Show Hosted VM Form] + + D --> G[Set Fallback Toggle] + E --> G + F --> G + C --> H[Submit Create Sandbox] + G --> H + + H --> I{Provisioning Success?} + I -->|Yes| J[Run Healthcheck] + I -->|No + Fallback ON + Hosted| K[Start Local Fallback] + I -->|No + Fallback OFF| L[Show Hosted Failure] + + K --> M{Local Fallback Success?} + M -->|Yes| J + M -->|No| N[Show Fallback Failure] + + J --> O{Healthcheck Pass?} + O -->|Yes + Evidence Supported| P[Show Success + Provider + Duration + Evidence] + O -->|Yes + No Evidence| R[Show Success + Provider + Duration] + O -->|No| Q[Show Healthcheck Failure] +``` + +## Screen Inventory + +1. Compute Provider Selection (wizard step / settings tab root) +2. Provider Configuration Form (dynamic by provider) +3. Fallback Policy Card +4. Provisioning Progress and Logs Panel +5. Provisioning Result Screen (success/failure/fallback outcomes) +6. Evidence Panel (attested providers only) + +## Screen Specifications + +### 1) Compute Provider Selection + +#### Purpose + +Allow explicit selection of `EigenCloud`, `AWS`, `DigitalOcean`, or `Local`. + +#### Components + +- Radio/segmented provider selector (single select) +- Provider cards with short capability summary and provider-class badge +- Continue button (disabled until valid selection) + +#### States + +- Default: no selection +- Selected provider: card highlighted, continue enabled +- Editing existing profile: current provider preselected + +#### Card content rules + +- `Local`: label as `Local Docker` +- `AWS` and `DigitalOcean`: label as `Hosted VM` +- `EigenCloud`: label as `Hosted Attested App` + +### 2) Provider Configuration Form + +#### Purpose + +Capture provider-specific values needed for provisioning. + +#### Shared layout + +- Header: provider name + icon +- Required fields section +- Advanced fields (collapsible) +- Inline validation + error messages + +#### Provider-specific field groups + +- EigenCloud: + - Auth key / credential reference selector + - Environment / network + - Image/version selection or allowlisted runtime image reference + - Secret release policy summary +- AWS: + - Account/profile or role reference + - Region + - VPC/subnet selection (or reference) + - Image/instance size +- DigitalOcean: + - Project ID/tag + - Region + - API token reference selector + - Image/size +- Local: + - Runtime profile selection + - Optional local resource caps + +### 3) Fallback Policy Card + +#### Purpose + +Control auto-fallback to local when hosted creation fails. + +#### Components + +- Toggle: `Auto-fallback to Local on hosted creation failure` +- Description text for ON/OFF behavior +- Default value indicator: ON + +#### Behavior + +- Toggle shown for hosted providers. +- For Local selection, toggle hidden and not applied. +- Changes persist with provider configuration. +- Copy clarifies that fallback is a control-plane policy and does not imply provider equivalence. + +### 4) Provisioning Progress and Logs Panel + +#### Purpose + +Make create + healthcheck lifecycle transparent. + +#### Components + +- Stepper/timeline: + - `Submitting request` + - `Provisioning runtime` + - `Running healthcheck` + - `Completed` +- Timer showing elapsed duration +- Structured event log rows: + - timestamp + - provider + - event + - status +- Optional capability rows: + - transport type + - attestation/evidence available + - secret release mode + +#### Hosted failure behavior + +- If fallback ON: + - Add explicit event `Hosted provisioning failed, attempting local fallback` + - Start local provisioning step +- If fallback OFF: + - Show terminal hosted failure without fallback step + +### 5) Provisioning Result Screen + +#### Success + +- Show final provider used +- Show total duration +- Show healthcheck pass status +- Show fallback badge if fallback occurred +- Show provider class (`Local`, `Hosted VM`, `Hosted Attested App`) +- Show evidence summary only when provider supports it + +#### Failure + +- Show failing provider +- Show failure reason category +- Show retry action and edit settings action +- If fallback occurred and also failed, show both hosted and fallback failure summaries distinctly + +### 6) Evidence Panel + +#### Purpose + +Surface trust evidence only for providers that can produce it. + +#### Components + +- Evidence availability badge +- Attestation identifier / verification link +- Secret release status + +#### Behavior + +- Hidden for Local, AWS, and DigitalOcean in MVP +- Shown for EigenCloud when evidence is returned by the provider adapter + +## Component Specifications + +### `ProviderSelector` + +- Inputs: + - `providers: ProviderOption[]` + - `selectedProvider: ProviderId | null` + - `onSelect(providerId)` +- Requirements: + - Keyboard navigable options + - Consistent ordering: EigenCloud, AWS, DigitalOcean, Local + - Each option shows provider class and transport summary + +### `ProviderConfigForm` + +- Inputs: + - `providerId` + - `initialValues` + - `onChange(values, isValid)` +- Requirements: + - Provider-specific schema validation + - Inline field-level errors + - Supports provider-class-specific helper text instead of generic hosted wording + +### `FallbackPolicyToggle` + +- Inputs: + - `enabled` + - `defaultEnabled = true` + - `onToggle(enabled)` +- Requirements: + - Visible only when provider is hosted + - Must display default ON guidance + +### `ProvisioningTimeline` + +- Inputs: + - `events[]` + - `elapsedMs` + - `fallbackAttempted` +- Requirements: + - Event grouping by phase + - Visual distinction between primary provider and fallback provider + - Visual distinction between attested evidence-bearing providers and plain VM providers + +### `EvidencePanel` + +- Inputs: + - `supported` + - `evidence` + - `verificationUrl` +- Requirements: + - Hidden when unsupported + - Never shown with empty placeholder content + +## Interaction Patterns + +- Switching provider resets provider-specific invalid fields and preserves cross-provider common values where safe. +- Switching between provider classes resets incompatible fields instead of attempting lossy reuse. +- Submit button remains disabled until selected provider config validates. +- During provisioning, prevent duplicate submissions and surface cancel/back behavior clearly. +- Retry action reuses last valid configuration. +- Fallback events are never silent; user sees explicit status transition. + +## Accessibility Requirements + +- All form controls have associated labels and descriptions. +- Provider selector supports keyboard navigation and visible focus state. +- Error text is linked to invalid fields with ARIA attributes. +- Timeline updates announce status changes using polite live regions. +- Color is not the only status indicator; include text labels/icons. +- Minimum touch target size 44x44 CSS px on mobile. + +## Responsive Behavior + +- Desktop/tablet: + - Two-column layout for provider card + form + - Timeline and event logs side-by-side +- Mobile: + - Single-column stack + - Sticky primary actions (`Continue`, `Create Sandbox`) + - Collapsible advanced fields by default + +## Copy and Messaging Rules + +- Hosted failure + fallback ON: + - "Hosted provisioning failed for . Switching to Local fallback." +- Hosted failure + fallback OFF: + - "Hosted provisioning failed for . Local fallback is disabled." +- Healthcheck failure: + - "Runtime created, but healthcheck did not pass. Review provider logs." +- Evidence available: + - "Runtime is healthy and trust evidence is available." + +## Telemetry and Analytics Events + +- `compute_provider_selected` +- `compute_provider_config_validated` +- `sandbox_create_started` +- `sandbox_create_succeeded` +- `sandbox_create_failed` +- `sandbox_fallback_attempted` +- `sandbox_fallback_succeeded` +- `sandbox_fallback_failed` +- `sandbox_healthcheck_passed` +- `sandbox_healthcheck_failed` +- `sandbox_evidence_available` +- `sandbox_evidence_unavailable` + +## Figma / Screenshots Placeholders + +- Figma board link: `TODO` +- Onboarding provider step screenshot: `TODO` +- Settings provider tab screenshot: `TODO` +- Provisioning timeline screenshot: `TODO` + +## PRD Traceability + +- AC-1 (provider list) -> Provider Selection screen + `ProviderSelector`. +- AC-2 (routing) -> ProviderConfig + submit flow mapping. +- AC-3/4/5/6 (create + healthcheck success) -> Provisioning timeline + result states. +- AC-7/8/9 (fallback behavior) -> Fallback policy card + hosted failure branches. +- AC-10 (logging) -> Provisioning logs panel + telemetry events. +- AC-11 (provider evidence only when supported) -> Evidence panel + result state gating. diff --git a/specs/22_should-add-support-for-cloud-compute/issue_body_draft.md b/specs/22_should-add-support-for-cloud-compute/issue_body_draft.md new file mode 100644 index 00000000..d9a6df70 --- /dev/null +++ b/specs/22_should-add-support-for-cloud-compute/issue_body_draft.md @@ -0,0 +1,48 @@ +# Proposed Issue Clarification Update (Append-Only) + +## Clarified Scope (MVP for this issue) + +- Build a provider wizard that supports hosted provider selection across: + - EigenCloud + - AWS + - DigitalOcean +- Keep local sandbox support as a first-class provider path. +- Use one shared control-plane abstraction for sandbox creation regardless of provider. + +## Provider and Fallback Rules + +- Hosted path is multi-provider (not EigenCloud-only). +- Local fallback behavior is configurable. +- Default fallback mode is **ON**: + - If selected hosted provider fails during sandbox creation, system auto-falls back to local provider. + +## Required Implementation Depth + +- Deliver **real provisioning integration** for: + - EigenCloud + - AWS + - DigitalOcean +- No stub-only hosted provider adapters for this issue. + +## Measurable Acceptance Criteria + +- Wizard allows selecting `EigenCloud`, `AWS`, `DigitalOcean`, or `Local`. +- Sandbox creation path uses the same provider interface/contract across all providers. +- For each hosted provider: + - sandbox creation succeeds in **< 60 seconds** + - provider healthcheck passes after creation +- Local provider path remains functional with the same control-plane interface. +- Config toggle exists for local fallback behavior and defaults to ON. +- When fallback is ON and hosted creation fails, system creates local sandbox and logs fallback event with provider + reason. +- Add tests covering: + - provider selection routing + - per-provider creation success path + - fallback enabled behavior + - fallback disabled behavior + - healthcheck + timing assertion path + +## Out of Scope for this issue + +- Advanced provider cost optimization policies. +- Multi-region scheduling policies beyond minimum integration needed for creation flow. +- Wallet/reward/PSH integration. diff --git a/specs/22_should-add-support-for-cloud-compute/issue_intake.md b/specs/22_should-add-support-for-cloud-compute/issue_intake.md new file mode 100644 index 00000000..0afcf1dc --- /dev/null +++ b/specs/22_should-add-support-for-cloud-compute/issue_intake.md @@ -0,0 +1,77 @@ +# Issue Intake: #22 should add support for cloud compute + +## Source + +- Issue URL: https://github.com/Flow-Research/Jarvis/issues/22 +- Captured at: 2026-03-27T14:07:12Z + +## Issue Snapshot + +- State: open +- Author: @Sheys11 +- Assignees: @catchmeifyoucaan, @ojogu +- Labels: none +- Milestone: none +- Body comments: 0 + +## Extracted Problem Statement + +Jarvis needs support for cloud compute so personal operators can get compute resources while preserving task execution and liveness guarantees. + +## Extracted Goal + +Support a hybrid sandbox architecture where sandbox provisioning uses the same control-plane abstraction across: + +- hosted providers (containerized, attested execution) +- local providers (local-first execution on user-owned devices) + +## Stated Scope + +- Introduce/extend provider-class support for `hosted` and `local`. +- Ensure sandbox creation path is unified regardless of provider. + +## Explicit Non-goals + +Not specified in the issue body. + +## Acceptance Criteria Assessment + +Current issue text is directionally clear but not yet testable as delivery criteria. + +Missing details that block execution-ready classification: + +- No explicit API/CLI surface requirements (inputs/outputs/errors). +- No compatibility or migration requirements for existing local-only paths. +- No definition of "liveness guarantees" measurable in tests. +- No concrete hosted provider contract boundaries (minimum interface/attestation assumptions). +- No rollout constraints or out-of-scope boundaries. + +## Strategy Sources Consulted + +Strategy context unavailable: + +- `.jarvis/context/docs/strategy/` not found. +- `docs/strategy/` not found. + +## Strategic Context + +No local strategy documentation was available in-repo, so strategic alignment must be inferred from issue intent and validated during brainstorm. + +## Strategic Alignment Hypothesis + +The request appears aligned with platform reliability and deployment flexibility by introducing a provider abstraction layer that supports both hosted and local compute. + +## Strategy Gaps / Questions + +- Is cloud compute support expected to be production-ready in this issue or scaffold-only? +- Is EigenCompute the only hosted provider target for this slice? +- Which reliability/SLO dimensions are mandatory in this issue vs deferred? + +## Classification + +- Mode: discovery-recovery +- Rationale: acceptance criteria are not yet testable enough to move directly into PRD/implementation. + +## Recommended Next Action + +Run Phase 1 brainstorming with focused clarification to produce testable acceptance criteria and an append-only issue update draft. diff --git a/specs/22_should-add-support-for-cloud-compute/prd_review_summary.md b/specs/22_should-add-support-for-cloud-compute/prd_review_summary.md new file mode 100644 index 00000000..a4debf3b --- /dev/null +++ b/specs/22_should-add-support-for-cloud-compute/prd_review_summary.md @@ -0,0 +1,33 @@ +# PRD Review Summary: Issue #22 + +## Review Metadata + +- Date: 2026-04-01 +- Input: `specs/22_should-add-support-for-cloud-compute/product_spec.md` +- Phase: 3 (PRD review) + +## Review Outcome + +- Blocking issues: **none** +- Spec gate recommendation: **PASS** +- Human approval required to advance: `prd_approval` + +## What Was Verified + +- Scope is explicit and bounded to provider wizard + shared control-plane + real integrations for EigenCloud, AWS, and DigitalOcean. +- Local provider is preserved as a first-class path. +- Fallback behavior is explicitly defined, configurable, and defaulted to ON. +- Acceptance criteria are measurable and testable (AC-1 through AC-10). +- Test requirements cover routing, success paths, liveness, and fallback behavior. +- Non-goals are clearly documented to prevent scope drift. + +## Minor Improvements (Non-Blocking) + +- Add exact config key names once technical spec finalizes naming conventions. +- Add explicit test environment assumptions for cloud provider credentials in CI docs. +- Confirm whether `< 60s` target applies to cold-start only or both cold/warm starts. + +## Gate Decision + +- `spec_gate`: **passed** +- `prd_approval`: **pending user approval** diff --git a/specs/22_should-add-support-for-cloud-compute/product_spec.md b/specs/22_should-add-support-for-cloud-compute/product_spec.md new file mode 100644 index 00000000..8dfab8cf --- /dev/null +++ b/specs/22_should-add-support-for-cloud-compute/product_spec.md @@ -0,0 +1,167 @@ +# Product Spec: Cloud Compute Provider Support + +## Metadata + +- Issue: https://github.com/Flow-Research/Jarvis/issues/22 +- Epic path: `specs/22_should-add-support-for-cloud-compute` +- Phase: 2 (PRD) +- Date: 2026-04-01 + +## Problem Statement + +Jarvis currently needs a production-ready cloud compute path that keeps local execution as a first-class option while preserving one shared sandbox control-plane contract. Without this, teams cannot reliably choose compute providers per environment, and fallback behavior is inconsistent. + +## Product Goal + +Deliver a compute selection and runtime orchestration path that supports: + +- Local compute: Docker-backed local sandbox path +- Hosted VM compute: AWS and DigitalOcean +- Hosted attested app compute: EigenCloud +- One shared control-plane abstraction for runtime lifecycle operations across all providers without forcing all providers into the same transport model + +## Scope + +### In Scope + +- Provider selection wizard supporting `EigenCloud`, `AWS`, `DigitalOcean`, and `Local`. +- Shared provider interface and routing layer used by all provider adapters. +- Provider capability model covering transport, healthcheck, attestation/evidence, and secret release behavior. +- Real provisioning integrations (not stubs) for EigenCloud, AWS, and DigitalOcean. +- Local provider fallback toggle with default `ON`. +- Automatic local fallback when hosted provisioning fails and fallback is enabled. +- Provider healthcheck validation after runtime creation. +- Evidence/attestation surfacing when the selected provider supports it. +- Readiness target enforcement and reporting using provider-class-appropriate timing budgets. +- Tests for provider routing, success paths, and fallback behavior. + +### Out of Scope + +- Cost optimization and dynamic provider pricing decisions. +- Multi-region optimization policies beyond minimum creation support. +- Wallet/reward/PSH integration. +- New business workflows unrelated to provider selection or sandbox provisioning. +- Treating the EigenCloud app wallet as the product treasury. +- Requiring attestation parity across all providers in MVP. + +## Users and Primary Jobs + +- Operator/Developer: choose where sandbox compute runs and get predictable startup behavior. +- Platform/Infra owner: enforce unified control-plane behavior and observe provider reliability. + +## Functional Requirements + +### FR-1 Shared Runtime Contract + +- Define and use a single runtime contract for compute lifecycle operations: + - provision runtime + - run healthcheck + - report status and failures + - expose provider capabilities +- Hosted and local providers must implement this contract. +- The shared contract must not assume every provider is reached via SSH. + +### FR-2 Provider Selection Wizard + +- User can explicitly select one of: `EigenCloud`, `AWS`, `DigitalOcean`, `Local`. +- Wizard captures provider-specific configuration inputs required for provisioning. +- Wizard persists enough context for deterministic routing to the selected adapter. +- Wizard surfaces provider class differences clearly: + - `Local` + - `Hosted VM` + - `Hosted Attested App` + +### FR-3 Hosted VM Integrations + +- AWS adapter performs real VM provisioning and healthcheck. +- DigitalOcean adapter performs real VM provisioning and healthcheck. +- VM-class providers may expose SSH access as the execution transport. + +### FR-4 Hosted Attested App Integration + +- EigenCloud adapter performs real app deployment and healthcheck using the EigenCloud SDK. +- EigenCloud path exposes attestation/evidence metadata and explicit secret release support. +- EigenCloud integration must not be modeled as a raw VM/SSH provider in the final architecture. + +### FR-5 Local Provider Path + +- Local provider remains functional and reachable from the same control-plane API. +- Local path behaves as a first-class compute option, not an emergency-only backdoor. + +### FR-6 Fallback Policy + +- Config toggle controls fallback behavior (`fallback_to_local_on_hosted_failure` or equivalent). +- Default value is `ON`. +- When `ON`, a hosted provider failure in sandbox creation triggers automatic local creation attempt. +- When `OFF`, hosted failure is returned as failure without local auto-attempt. + +### FR-7 Readiness and Health Targets + +- Healthcheck must pass after creation for each provider. +- Readiness timing must be measured and observable for each provider. +- Timing budgets may differ by provider class: + - fast app-deployment providers + - VM boot providers +- The system must not hardcode an EigenCloud-style readiness assumption onto AWS or DigitalOcean. + +### FR-8 Observability + +- Log provider selection, provisioning outcome, duration, and fallback decisions. +- On fallback execution, include: + - original hosted provider + - failure reason/classification + - local fallback attempt result +- When supported, include attestation/evidence identifiers without logging secrets. + +## Non-Functional Requirements + +- Reliability: consistent lifecycle semantics across providers for provision + healthcheck + failure outcomes, while allowing provider-specific transports and capabilities. +- Testability: all acceptance criteria map to deterministic automated tests. +- Backward safety: local-only usage remains operational if no hosted provider is configured. + +## Acceptance Criteria (Testable) + +- AC-1 Wizard lists exactly: `EigenCloud`, `AWS`, `DigitalOcean`, `Local`. +- AC-2 Selected provider routes to the correct adapter path. +- AC-3 EigenCloud create+healthcheck succeeds under an EigenCloud integration harness and exposes provider evidence metadata. +- AC-4 AWS create+healthcheck succeeds under an AWS integration harness. +- AC-5 DigitalOcean create+healthcheck succeeds under a DigitalOcean integration harness. +- AC-6 Local provider create+healthcheck succeeds through the same control-plane contract. +- AC-7 Fallback toggle default is `ON`. +- AC-8 With fallback `ON`, simulated hosted creation failure triggers local fallback and logs provider + reason. +- AC-9 With fallback `OFF`, hosted creation failure does not trigger fallback and returns an explicit error path. +- AC-10 Logs/telemetry include provider, duration, healthcheck result, and fallback decision metadata. +- AC-11 Attested-provider-only fields and evidence states are hidden for non-attested providers. + +## Test Plan Requirements + +- Unit tests: + - provider routing matrix for all 4 providers + - fallback policy gate behavior (`ON` vs `OFF`) + - logging payload structure for success/failure/fallback +- Integration tests: + - per-provider create + healthcheck path + - provider-class-specific readiness assertions + - hosted failure simulation leading to local fallback when enabled + +## Risks and Mitigations + +- Risk: provider API differences cause contract drift. + - Mitigation: enforce adapter conformance tests at the runtime contract boundary and keep provider-specific capability flags explicit. +- Risk: an EigenCloud-specific design leaks into VM providers or vice versa. + - Mitigation: separate provider classes (`hosted-vm` vs `hosted-attested-app`) and validate transport assumptions per class. +- Risk: fallback masks root hosted failures. + - Mitigation: structured fallback logs with explicit reason and original provider ID. + +## Dependencies + +- Provider credentials/config for EigenCloud, AWS, DigitalOcean in test/runtime environments. +- Existing sandbox control-plane module where provider adapter interface is enforced. +- CI lanes capable of running provider integration and fallback behavior tests. +- EigenCloud SDK and deployment image pipeline for attested app runtime. + +## Definition of Done + +- All acceptance criteria AC-1 through AC-10 are validated by tests or deterministic checks. +- Provider wizard, shared runtime contract, hosted adapters, and local fallback behavior are implemented. +- CI checks covering provider selection, provisioning, fallback, and liveness are green. diff --git a/specs/22_should-add-support-for-cloud-compute/provider_architecture_addendum.md b/specs/22_should-add-support-for-cloud-compute/provider_architecture_addendum.md new file mode 100644 index 00000000..97195220 --- /dev/null +++ b/specs/22_should-add-support-for-cloud-compute/provider_architecture_addendum.md @@ -0,0 +1,102 @@ +# Provider Architecture Addendum + +## Purpose + +This note records how the reviewed EigenCloud architecture note was adapted into a multi-provider runtime design for issue #22. + +## Source Inputs + +- Reviewed note: + - `https://any.coop/A7AAFUdmufaBG3HDyzxAqzviXfxtPAUeCstfSCVmb5ZY9AGj/eigencloud` +- Reviewed official docs: + - EigenCompute overview + - Quickstart + - Use ecloud SDK + - Expose ports + - Verify trust guarantees + - EigenCompute KMS + +## What Stayed True + +- EigenCloud is best treated as one long-lived operator core runtime, not a swarm of always-on external worker apps. +- Internal subagents should stay inside the core runtime by default. +- Durable state should remain outside provider memory. +- Explicit secret release remains the right platform-owned control plane. +- SDK-backed integration is preferred over shell-driven CLI automation. + +## What Changed + +- EigenCloud is no longer the top-level architecture. +- The top-level architecture is now provider-neutral. +- AWS and DigitalOcean are VM providers first. +- EigenCloud is an attested app provider. +- Shared control-plane behavior is lifecycle-based, not SSH-based. + +## Final Model + +### Runtime classes + +- `local-container` +- `hosted-vm` +- `hosted-attested-app` + +### Provider mapping + +- `local` -> `local-container` +- `aws` -> `hosted-vm` +- `digitalocean` -> `hosted-vm` +- `eigencloud` -> `hosted-attested-app` + +### Design rule + +Do not force all providers into one transport model. + +Correct transport expectations: + +- `local` -> Docker/local process control +- `aws` and `digitalocean` -> SSH-capable VM access +- `eigencloud` -> provider-managed deployed app endpoint with evidence support + +## Why This Matters + +If EigenCloud is modeled as just another SSH host: + +- attestation becomes invisible +- secret release becomes bolted-on instead of first-class +- the design inherits VM assumptions that do not actually match the provider + +If AWS and DigitalOcean are modeled as EigenCloud-like attested apps: + +- the shared contract becomes dishonest +- provider forms become confusing +- implementation work is blocked on capabilities those providers do not expose in MVP + +## Resulting Engineering Rule + +Share: + +- lifecycle contract +- healthcheck semantics +- fallback policy +- observability schema + +Do not over-share: + +- transport details +- evidence model +- secret delivery mechanics +- provider-specific identity assumptions + +## Status + +The branch currently implements the control-plane scaffolding: + +- provider selection +- fallback policy +- hosted provider registry +- hosted healthcheck routing + +The remaining work is to complete provider-native runtime implementations: + +- VM providers with real provisioning +- EigenCloud with SDK-backed attested app runtime diff --git a/specs/22_should-add-support-for-cloud-compute/technical_spec.md b/specs/22_should-add-support-for-cloud-compute/technical_spec.md new file mode 100644 index 00000000..56cf40af --- /dev/null +++ b/specs/22_should-add-support-for-cloud-compute/technical_spec.md @@ -0,0 +1,533 @@ +# Technical Spec: Multi-Provider Compute Runtime for Sandbox Execution + +## Metadata + +- Issue: https://github.com/Flow-Research/Jarvis/issues/22 +- PRD: `specs/22_should-add-support-for-cloud-compute/product_spec.md` +- Design spec: `specs/22_should-add-support-for-cloud-compute/design_spec.md` +- Date: 2026-04-09 +- Phase: 6 (Tech spec) + +## Implementation Objective + +Implement compute selection across `local`, `eigencloud`, `aws`, and `digitalocean` behind one control-plane path for runtime provisioning, healthcheck, failure handling, and fallback, without forcing all providers into the same transport or trust model. + +## Architectural Correction + +The previous EigenCloud-only direction was useful for understanding EigenCloud, but it is not a correct top-level abstraction now that we support more than one hosted provider. + +The final architecture must distinguish three runtime classes: + +- `local-container` +- `hosted-vm` +- `hosted-attested-app` + +Provider mapping: + +- `local` -> `local-container` +- `aws` -> `hosted-vm` +- `digitalocean` -> `hosted-vm` +- `eigencloud` -> `hosted-attested-app` + +This is the key design rule: + +- The shared control plane is lifecycle-oriented. +- Provider transports are capability-driven. +- EigenCloud is not modeled as a raw SSH VM in the final architecture. + +## External Constraints + +The following constraints come from the reviewed EigenCloud note and official EigenCloud docs: + +- EigenCompute deploys containerized services, not raw VMs. +- Deployments are image-based and exposed over bound ports. +- EigenCloud provides attestation/trust evidence. +- EigenCloud provides a deterministic TEE mnemonic and app wallet inside the TEE. +- Stopping/restarting preserves identity, but in-memory state is not durable. +- Terminating the app destroys access to the app wallet permanently. +- The SDK is the correct programmatic integration surface. + +That means: + +- EigenCloud should be integrated as an attested app runtime. +- AWS and DigitalOcean should be integrated as VM runtimes first. +- Explicit platform-controlled secret release remains valid across all providers. + +## Existing Architecture Baseline + +- Sandbox orchestration today centers on: + - `src/agents/sandbox/context.ts` + - `src/agents/sandbox/backend.ts` + - `src/agents/sandbox/types.ts` + - `src/agents/sandbox/config.ts` +- Existing runtime backends are currently backend-oriented: + - `docker` + - `ssh` +- Onboarding and setup paths are centered on: + - `src/wizard/setup.ts` + - `src/commands/onboard*.ts` + - `src/cli/program/register.onboard.ts` +- Current work already landed: + - provider selection wiring + - hosted provider registry scaffolding + - fallback routing + - setup/onboarding prompts and flags + +## Current Implemented State + +The current branch now includes a valid phase-0 scaffold: + +- provider selection in wizard/CLI/onboarding +- hosted provider registry +- hosted healthcheck execution +- local fallback policy +- sandbox context routing + +Current limitation: + +- hosted providers are still modeled as SSH-oriented targets in code +- that is acceptable for `aws` and `digitalocean` as an interim path +- that is not the correct final model for `eigencloud` + +So the shipped scaffold should be treated as: + +- a correct control-plane/fallback foundation +- not the final provider transport model + +## Final Architecture + +### 1) Shared Runtime Contract + +The shared abstraction must be a provisioned runtime, not a raw SSH target. + +```ts +type ComputeProviderId = "local" | "eigencloud" | "aws" | "digitalocean"; + +type ComputeRuntimeKind = "local-container" | "hosted-vm" | "hosted-attested-app"; + +type ComputeProviderCapabilities = { + access: { + ssh: boolean; + httpApi: boolean; + }; + attestation: boolean; + explicitSecretRelease: boolean; + startStop: boolean; + destroy: boolean; +}; + +type ProvisionedRuntime = { + providerId: ComputeProviderId; + runtimeId: string; + runtimeKind: ComputeRuntimeKind; + displayName: string; + endpoints: { + sshTarget?: string; + apiBaseUrl?: string; + }; + workspaceRoot?: string; + identityFileRef?: unknown; + evidence?: { + attestationId?: string; + verificationUrl?: string; + deploymentRecord?: string; + }; + metadata: Record; +}; + +type RuntimeHealthcheckResult = { + ok: boolean; + detail?: string; + durationMs: number; +}; + +type HostedComputeProvider = { + id: Exclude; + capabilities: ComputeProviderCapabilities; + provision(params: ProvisionParams): Promise; + healthcheck(params: HealthcheckParams): Promise; + stop?(runtime: ProvisionedRuntime): Promise; + start?(runtime: ProvisionedRuntime): Promise; + destroy?(runtime: ProvisionedRuntime): Promise; + getEvidence?(runtime: ProvisionedRuntime): Promise; + releaseSecrets?(params: ReleaseSecretsParams): Promise; +}; +``` + +### 2) Provider Profiles + +#### Local + +- Maps to existing `docker` backend. +- No attestation. +- No explicit secret release endpoint required. + +#### AWS + +- First-class profile: `hosted-vm` +- Primary transport: SSH +- Provisioning target: EC2 or equivalent VM instance +- Execution path can continue to reuse the `ssh` backend +- Attestation is not required for MVP + +#### DigitalOcean + +- First-class profile: `hosted-vm` +- Primary transport: SSH +- Provisioning target: Droplet +- Execution path can continue to reuse the `ssh` backend +- Attestation is not required for MVP + +#### EigenCloud + +- First-class profile: `hosted-attested-app` +- Primary transport: provider-managed HTTP/API endpoint +- Provisioning target: deployed EigenCompute app via SDK +- Must expose evidence/attestation metadata +- Should support explicit secret release +- Must not be permanently forced through the `ssh` backend in the final design + +### 3) Control-Plane Routing + +Routing decisions happen in two stages: + +#### A. Provider stage + +- Read `sandbox.compute.provider` +- Provision with the selected provider adapter +- Receive a `ProvisionedRuntime` + +#### B. Access stage + +- Convert `ProvisionedRuntime` into the concrete execution backend: + - `local-container` -> `docker` + - `hosted-vm` with SSH -> `ssh` + - `hosted-attested-app` with HTTP API -> new `provider-managed` or `remote-api` execution path + +This keeps one control plane while allowing multiple execution transports. + +### 4) Fallback Policy + +Fallback remains control-plane policy, not provider emulation. + +Rules: + +- Hosted provider failure before readiness: + - if fallback `ON` -> try local + - if fallback `OFF` -> return hosted failure +- Healthcheck failure after provisioning: + - treated as hosted failure for fallback purposes +- Fallback logs must preserve: + - selected provider + - runtime kind + - failure class + - local fallback outcome + +### 5) Evidence and Secret Release + +Evidence and secret release must be optional capabilities, not universal assumptions. + +Rules: + +- `eigencloud`: + - supports evidence/attestation + - supports explicit secret release flow +- `aws` and `digitalocean` MVP: + - no attestation requirement + - secrets delivered through VM bootstrap/SSH-safe mechanisms +- `local`: + - no attestation + - no provider-level secret release + +## Config Surface + +Retain the new `sandbox.compute` block, but evolve it to represent provider capabilities cleanly. + +```ts +compute?: { + provider?: "local" | "eigencloud" | "aws" | "digitalocean"; + fallbackToLocalOnHostedFailure?: boolean; + hosted?: { + eigencloud?: { + authKeyRef?: SecretInput; + environment?: string; + imageRef?: string; + apiBaseUrl?: string; + }; + aws?: { + region?: string; + roleArn?: string; + imageId?: string; + instanceType?: string; + subnetId?: string; + target?: string; + identityFile?: string; + }; + digitalocean?: { + region?: string; + image?: string; + size?: string; + projectId?: string; + tokenRef?: SecretInput; + target?: string; + identityFile?: string; + }; + }; +} +``` + +Important rule: + +- `target` remains valid for VM-class providers. +- `target` is not the final source of truth for EigenCloud. + +## Control-Plane Modules + +### A) Provider Registry + +Files: + +- `src/agents/sandbox/compute/types.ts` +- `src/agents/sandbox/compute/registry.ts` + +Responsibilities: + +- register hosted provider adapters +- expose provider capabilities +- dispatch provision/healthcheck/evidence/release-secrets + +### B) Provider Adapters + +Files: + +- `src/agents/sandbox/compute/providers/eigencloud.ts` +- `src/agents/sandbox/compute/providers/aws.ts` +- `src/agents/sandbox/compute/providers/digitalocean.ts` +- `src/agents/sandbox/compute/providers/shared.ts` + +Responsibilities: + +- convert provider config into a `ProvisionedRuntime` +- implement provider-native lifecycle behavior + +### C) Runtime Resolution Layer + +Files: + +- `src/agents/sandbox/context.ts` +- future: `src/agents/sandbox/provider-runtime.ts` + +Responsibilities: + +- resolve provider from config +- provision runtime +- choose correct execution backend based on runtime kind and capabilities +- perform healthcheck and fallback + +### D) EigenCloud-Specific Runtime Access + +New future files: + +- `src/agents/sandbox/provider-managed.ts` +- `src/agents/sandbox/provider-managed.test.ts` + +Responsibilities: + +- handle provider-managed API transport +- invoke `/health`, `/exec`, `/files/*`, `/release-secrets` +- carry attestation/evidence metadata + +This is the missing final leg for EigenCloud. + +## Onboarding and Wizard Surface + +Already implemented: + +- provider selection +- target/workspace/identity/fallback flags + +Needed refinement: + +- keep `aws` and `digitalocean` forms SSH/VM-shaped +- evolve `eigencloud` form away from SSH-target-first UX toward: + - auth key reference + - image/version + - environment/network + - evidence-capable runtime explanation + +Files: + +- `src/wizard/setup.ts` +- `src/wizard/setup.compute-provider.ts` +- `src/commands/onboard.ts` +- `src/commands/onboard-sandbox-compute.ts` +- `src/cli/program/register.onboard.ts` + +## Observability Schema + +Every lifecycle event should carry: + +- `compute_provider` +- `runtime_kind` +- `capabilities` +- `duration_ms` +- `healthcheck_ok` +- `fallback_attempted` +- `fallback_result` + +Attested providers may also carry: + +- `attestation_id` +- `verification_url` +- `deployment_record` + +Never log: + +- raw secrets +- auth keys +- private key material +- identity file contents + +## Failure Model + +### Hosted VM failure + +- instance creation fails +- SSH not reachable +- bootstrapping fails +- healthcheck fails + +### Hosted attested app failure + +- deployment submission fails +- app does not reach ready state +- healthcheck endpoint fails +- evidence retrieval fails +- secret release fails + +### Fallback behavior + +- fallback only applies from hosted to local +- fallback preserves original hosted failure context +- final error may be composite: + - hosted failure + - local fallback failure + +## Security Rules + +- Do not use EigenCloud app wallet as product treasury. +- Use provider capabilities instead of assuming attestation everywhere. +- Keep explicit secret release as the platform-owned policy gate. +- Reuse existing SecretRef and redaction flows for provider credentials. +- Treat provider evidence as trust metadata, not as an excuse to skip platform authorization and budget controls. + +## Testing Plan + +### Already Implemented + +- provider selection routing +- fallback enabled behavior +- fallback disabled behavior +- hosted healthcheck failure routing +- wizard/CLI mapping +- non-interactive setup coverage + +### Remaining Unit Tests + +- provider capability matrix tests +- `ProvisionedRuntime` mapping tests +- EigenCloud evidence mapping tests +- provider-managed API transport tests + +### Remaining Integration Tests + +- real DigitalOcean VM provisioning + SSH-ready healthcheck +- real AWS VM provisioning + SSH-ready healthcheck +- real EigenCloud SDK deployment + app healthcheck + evidence retrieval +- explicit secret release flow on EigenCloud + +### Acceptance Mapping + +- AC-1/2: onboarding and routing tests +- AC-3/4/5: provider-specific integration harnesses +- AC-6: local path parity +- AC-7/8/9: fallback behavior tests +- AC-10: structured logging tests +- AC-11: evidence gating tests + +## Phased Delivery Plan + +### Phase 0: Scaffolding + +Status: done on this branch + +Includes: + +- provider selection +- config plumbing +- hosted provider registry +- hosted healthcheck path +- fallback routing + +### Phase 1: Runtime Contract Upgrade + +Next + +Includes: + +- `ProvisionedRuntime` +- provider capability matrix +- runtime-kind-aware routing + +### Phase 2: VM Providers + +Next after phase 1 + +Includes: + +- real DigitalOcean adapter +- real AWS adapter +- SSH-ready healthcheck and lifecycle behavior + +### Phase 3: EigenCloud Attested Runtime + +After VM providers or in parallel if credentials and image pipeline are ready + +Includes: + +- SDK-backed deploy/start/stop/destroy +- app endpoint readiness +- evidence retrieval +- explicit secret release +- provider-managed API execution path + +### Phase 4: Unified Operator Runtime Polishing + +Final + +Includes: + +- richer observability +- provider-specific docs +- full integration CI strategy + +## Explicit Non-Goals + +- Making every provider attested in MVP +- Using one provider’s lifecycle model as the universal model +- Treating EigenCloud wallet/KMS semantics as the generic hosted compute baseline +- Cost-based scheduling and PSH integration in this issue + +## Reference Notes + +- Internal reference note reviewed: + - `https://any.coop/A7AAFUdmufaBG3HDyzxAqzviXfxtPAUeCstfSCVmb5ZY9AGj/eigencloud` +- Official EigenCloud docs reviewed: + - EigenCompute overview + - Quickstart + - Use ecloud SDK + - Expose ports + - Verify trust guarantees + - Create and use authentication keys + - EigenCompute KMS + - Security and trust model diff --git a/specs/22_should-add-support-for-cloud-compute/techspec_review_summary.md b/specs/22_should-add-support-for-cloud-compute/techspec_review_summary.md new file mode 100644 index 00000000..b2fb66f8 --- /dev/null +++ b/specs/22_should-add-support-for-cloud-compute/techspec_review_summary.md @@ -0,0 +1,51 @@ +# Tech Spec Review Summary: Issue #22 + +## Metadata + +- Date: 2026-04-08 +- Input: `specs/22_should-add-support-for-cloud-compute/technical_spec.md` +- Phase: 7 (Tech spec review) + +## Review Focus + +- Simplicity and architectural fitness +- Alignment with existing sandbox + onboarding architecture +- Testability and acceptance-criteria traceability + +## Findings + +### 1) Architecture Fit + +- The spec extends existing sandbox/onboarding structure instead of introducing a separate orchestration stack. +- It reuses current config and backend primitives (`context.ts`, backend registry, wizard/onboard flow). +- Result: **fit is good**, no redesign blocker. + +### 2) Simplicity Check + +- Minimal approach selected: + - Add a compute provider contract and route through existing control-plane entry. + - Keep local path as current default. + - Add hosted adapters without replacing baseline sandbox backend architecture. +- Avoids unnecessary framework/microservice split. +- Result: **passes simplicity gate**. + +### 3) Testability + +- Acceptance criteria map cleanly to concrete unit/integration tests. +- Fallback-on/fallback-off behaviors are explicitly testable. +- Result: **testability is sufficient**. + +## Non-Blocking Adjustments + +- Keep provider field names consistent between wizard, CLI flags, and config schema (`eigencloud`/`aws`/`digitalocean`). +- Ensure timing assertions (`< 60s`) use stable mocked clocks/harnesses where live provider timing is nondeterministic. +- Confirm final event schema names before implementation to avoid log migration churn. + +## Gate Decision + +- `design_simplicity_gate`: **passed** +- `tech_spec_approval`: **pending human approval** + +## Recommendation + +- Ready to proceed once tech spec approval is recorded. diff --git a/src/agents/pi-embedded-runner.buildembeddedsandboxinfo.test.ts b/src/agents/pi-embedded-runner.buildembeddedsandboxinfo.test.ts index 52289130..a776096b 100644 --- a/src/agents/pi-embedded-runner.buildembeddedsandboxinfo.test.ts +++ b/src/agents/pi-embedded-runner.buildembeddedsandboxinfo.test.ts @@ -14,6 +14,17 @@ function createSandboxContext(overrides?: Partial): SandboxConte runtimeLabel: "openclaw-sbx-test", containerName: "openclaw-sbx-test", containerWorkdir: "/workspace", + compute: { + providerId: "local", + runtimeKind: "local-container", + access: {}, + capabilities: { + sshAccess: false, + httpsAccess: false, + supportsAttestation: false, + supportsSecretRelease: false, + }, + }, docker: { image: "openclaw-sandbox:bookworm-slim", containerPrefix: "openclaw-sbx-", diff --git a/src/agents/pi-tools-agent-config.test.ts b/src/agents/pi-tools-agent-config.test.ts index 353b0333..2a300d2a 100644 --- a/src/agents/pi-tools-agent-config.test.ts +++ b/src/agents/pi-tools-agent-config.test.ts @@ -583,6 +583,17 @@ describe("Agent-specific tool filtering", () => { runtimeLabel: "test-container", containerName: "test-container", containerWorkdir: "/workspace", + compute: { + providerId: "local", + runtimeKind: "local-container", + access: {}, + capabilities: { + sshAccess: false, + httpsAccess: false, + supportsAttestation: false, + supportsSecretRelease: false, + }, + }, docker: { image: "test-image", containerPrefix: "test-", diff --git a/src/agents/sandbox-merge.test.ts b/src/agents/sandbox-merge.test.ts index 74270101..9e71ca3a 100644 --- a/src/agents/sandbox-merge.test.ts +++ b/src/agents/sandbox-merge.test.ts @@ -166,6 +166,89 @@ describe("sandbox config merges", () => { expect(sshShared.target).toBe("global@example.com:22"); }); + it("defaults sandbox compute config to local provider with fallback enabled", () => { + const resolved = resolveSandboxConfigForAgent(); + expect(resolved.compute).toEqual({ + provider: "local", + fallbackToLocalOnHostedFailure: true, + hosted: {}, + }); + }); + + it("routes hosted compute providers to openshell by default", () => { + const resolved = resolveSandboxConfigForAgent({ + agents: { + defaults: { + sandbox: { + mode: "all", + compute: { + provider: "aws", + }, + }, + }, + }, + }); + + expect(resolved.compute?.provider).toBe("aws"); + expect(resolved.backend).toBe("openshell"); + expect(resolved.ssh.target).toBeUndefined(); + }); + + it("applies provider ssh overrides when hosted backend is explicitly ssh", () => { + const resolved = resolveSandboxConfigForAgent({ + agents: { + defaults: { + sandbox: { + mode: "all", + backend: "ssh", + ssh: { target: "global@example.com:22" }, + compute: { + provider: "aws", + hosted: { + aws: { target: "ec2-user@aws-host:2222" }, + }, + }, + }, + }, + }, + }); + + expect(resolved.compute?.provider).toBe("aws"); + expect(resolved.backend).toBe("ssh"); + expect(resolved.ssh.target).toBe("ec2-user@aws-host:2222"); + }); + + it("ignores agent compute overrides under shared scope", () => { + const resolved = resolveSandboxConfigForAgent( + { + agents: { + defaults: { + sandbox: { + mode: "all", + scope: "shared", + compute: { + provider: "local", + }, + }, + }, + list: [ + { + id: "main", + sandbox: { + compute: { + provider: "digitalocean", + }, + }, + }, + ], + }, + }, + "main", + ); + expect(resolved.compute?.provider).toBe("local"); + expect(resolved.backend).toBe("docker"); + }); + it("defaults sandbox backend to docker", () => { expect(resolveSandboxConfigForAgent().backend).toBe("docker"); }); diff --git a/src/agents/sandbox.resolveSandboxContext.test.ts b/src/agents/sandbox.resolveSandboxContext.test.ts index 0fa62a36..e754e0c8 100644 --- a/src/agents/sandbox.resolveSandboxContext.test.ts +++ b/src/agents/sandbox.resolveSandboxContext.test.ts @@ -107,6 +107,7 @@ describe("resolveSandboxContext", () => { const cfg: OpenClawConfig = { agents: { defaults: { + skipBootstrap: true, sandbox: { mode: "all", backend: "test-backend", scope: "session" }, }, }, @@ -122,6 +123,17 @@ describe("resolveSandboxContext", () => { expect(result?.runtimeId).toBe("test-runtime"); expect(result?.containerName).toBe("test-runtime"); expect(result?.backend?.id).toBe("test-backend"); + expect(result?.compute).toEqual({ + providerId: "local", + runtimeKind: "local-container", + access: {}, + capabilities: { + sshAccess: false, + httpsAccess: false, + supportsAttestation: false, + supportsSecretRelease: false, + }, + }); } finally { restore(); } diff --git a/src/agents/sandbox.ts b/src/agents/sandbox.ts index d26dc752..018edada 100644 --- a/src/agents/sandbox.ts +++ b/src/agents/sandbox.ts @@ -67,9 +67,17 @@ export type { } from "./sandbox/ssh.js"; export type { + SandboxComputeAccess, + SandboxComputeCapabilities, SandboxBrowserConfig, SandboxBrowserContext, SandboxConfig, + SandboxComputeConfig, + SandboxComputeEvidence, + SandboxComputeHostedProviderConfig, + SandboxComputeProviderId, + SandboxComputeRuntimeInfo, + SandboxComputeRuntimeKind, SandboxContext, SandboxDockerConfig, SandboxPruneConfig, diff --git a/src/agents/sandbox/compute/providers/aws.ts b/src/agents/sandbox/compute/providers/aws.ts new file mode 100644 index 00000000..f28af180 --- /dev/null +++ b/src/agents/sandbox/compute/providers/aws.ts @@ -0,0 +1,8 @@ +import { createHostedComputeProvider } from "./shared.js"; + +export const awsHostedComputeProvider = createHostedComputeProvider("aws", { + runtimeKind: "hosted-vm", + managedEvidence: { + summary: "Managed via OpenShell provider-backed sandbox provisioning.", + }, +}); diff --git a/src/agents/sandbox/compute/providers/digitalocean.ts b/src/agents/sandbox/compute/providers/digitalocean.ts new file mode 100644 index 00000000..53aa40c5 --- /dev/null +++ b/src/agents/sandbox/compute/providers/digitalocean.ts @@ -0,0 +1,8 @@ +import { createHostedComputeProvider } from "./shared.js"; + +export const digitaloceanHostedComputeProvider = createHostedComputeProvider("digitalocean", { + runtimeKind: "hosted-vm", + managedEvidence: { + summary: "Managed via OpenShell provider-backed sandbox provisioning.", + }, +}); diff --git a/src/agents/sandbox/compute/providers/eigencloud.ts b/src/agents/sandbox/compute/providers/eigencloud.ts new file mode 100644 index 00000000..14f37ef1 --- /dev/null +++ b/src/agents/sandbox/compute/providers/eigencloud.ts @@ -0,0 +1,13 @@ +import { createHostedComputeProvider } from "./shared.js"; + +export const eigencloudHostedComputeProvider = createHostedComputeProvider("eigencloud", { + runtimeKind: "hosted-attested-app", + managedEvidence: { + summary: + "Managed via OpenShell on EigenCloud; attestation verification is not exposed through the current sandbox contract yet.", + }, + sshEvidence: { + summary: + "Phase-0 SSH scaffold; native EigenCloud attestation and secret-release hooks are not wired yet.", + }, +}); diff --git a/src/agents/sandbox/compute/providers/shared.ts b/src/agents/sandbox/compute/providers/shared.ts new file mode 100644 index 00000000..cadc9d8b --- /dev/null +++ b/src/agents/sandbox/compute/providers/shared.ts @@ -0,0 +1,162 @@ +import { performance } from "node:perf_hooks"; +import type { + HostedSandboxComputeProvider, + HostedSandboxComputeProviderId, + HostedSandboxComputeRuntimeInfo, + HostedSandboxHealthcheckParams, + HostedSandboxHealthcheckResult, + HostedSandboxProvisionParams, + HostedSandboxProvisionResult, +} from "../types.js"; + +function resolveHostedTarget(params: HostedSandboxProvisionParams): string { + const providerTarget = params.cfg.compute?.hosted?.[params.providerId]?.target?.trim(); + const sshTarget = params.cfg.ssh.target?.trim(); + const target = providerTarget || sshTarget; + if (!target) { + throw new Error( + [ + `Hosted sandbox provider "${params.providerId}" requires an SSH target.`, + `Set sandbox.compute.hosted.${params.providerId}.target or sandbox.ssh.target.`, + ].join(" "), + ); + } + return target; +} + +function resolveHealthcheckFailureDetail(params: { + code: number; + stderr: Buffer; + stdout: Buffer; +}): string { + const stderrText = params.stderr.toString("utf8").trim(); + const stdoutText = params.stdout.toString("utf8").trim(); + const lines = [`exit code ${params.code}`]; + if (stderrText) { + lines.push(`stderr: ${stderrText}`); + } + if (stdoutText) { + lines.push(`stdout: ${stdoutText}`); + } + return lines.join("; "); +} + +async function runHostedHealthcheck( + params: HostedSandboxHealthcheckParams, +): Promise { + const startedAt = performance.now(); + const backend = params.sandbox.backend; + if (!backend) { + return { + ok: false, + detail: "missing sandbox backend handle", + durationMs: Math.round(performance.now() - startedAt), + }; + } + try { + const result = await backend.runShellCommand({ + script: "printf 'openclaw-sandbox-healthcheck\\n'", + allowFailure: true, + }); + const durationMs = Math.round(performance.now() - startedAt); + if (result.code === 0) { + return { + ok: true, + durationMs, + }; + } + return { + ok: false, + detail: resolveHealthcheckFailureDetail(result), + durationMs, + }; + } catch (error) { + return { + ok: false, + detail: error instanceof Error ? error.message : String(error), + durationMs: Math.round(performance.now() - startedAt), + }; + } +} + +function validateHostedBackend(params: HostedSandboxProvisionParams): void { + if (params.cfg.backend !== "ssh") { + throw new Error( + [ + `Hosted sandbox provider "${params.providerId}" requires the SSH backend.`, + `Resolved backend: "${params.cfg.backend}".`, + ].join(" "), + ); + } +} + +function validateProviderManagedBackend(params: HostedSandboxProvisionParams): void { + if (params.cfg.backend !== "openshell") { + throw new Error( + [ + `Hosted sandbox provider "${params.providerId}" requires the OpenShell or SSH backend.`, + `Resolved backend: "${params.cfg.backend}".`, + ].join(" "), + ); + } +} + +type HostedComputeProviderOptions = { + runtimeKind: HostedSandboxComputeRuntimeInfo["runtimeKind"]; + managedCapabilities?: Partial; + managedEvidence?: HostedSandboxComputeRuntimeInfo["evidence"]; + sshCapabilities?: Partial; + sshEvidence?: HostedSandboxComputeRuntimeInfo["evidence"]; +}; + +function buildHostedCapabilities( + overrides?: Partial, +): HostedSandboxComputeRuntimeInfo["capabilities"] { + return { + sshAccess: true, + httpsAccess: false, + supportsAttestation: false, + supportsSecretRelease: false, + ...overrides, + }; +} + +export function createHostedComputeProvider( + id: HostedSandboxComputeProviderId, + options: HostedComputeProviderOptions, +): HostedSandboxComputeProvider { + return { + id, + async provision(params): Promise { + if (params.cfg.backend === "openshell") { + validateProviderManagedBackend(params); + return { + cfg: params.cfg, + runtime: { + providerId: id, + runtimeKind: options.runtimeKind, + access: {}, + capabilities: buildHostedCapabilities(options.managedCapabilities), + evidence: options.managedEvidence, + }, + }; + } + validateHostedBackend(params); + return { + cfg: params.cfg, + runtime: { + providerId: id, + runtimeKind: options.runtimeKind, + access: { + sshTarget: resolveHostedTarget(params), + }, + capabilities: buildHostedCapabilities(options.sshCapabilities), + evidence: options.sshEvidence, + }, + }; + }, + async healthcheck(params): Promise { + return await runHostedHealthcheck(params); + }, + }; +} diff --git a/src/agents/sandbox/compute/registry.test.ts b/src/agents/sandbox/compute/registry.test.ts new file mode 100644 index 00000000..63d0bff0 --- /dev/null +++ b/src/agents/sandbox/compute/registry.test.ts @@ -0,0 +1,141 @@ +import { describe, expect, it, vi } from "vitest"; +import { resolveSandboxConfigForAgent } from "../config.js"; +import type { SandboxContext } from "../types.js"; +import { + healthcheckHostedSandboxCompute, + isHostedSandboxComputeProviderId, + provisionHostedSandboxCompute, +} from "./registry.js"; + +describe("sandbox compute registry", () => { + it("recognizes hosted provider ids", () => { + expect(isHostedSandboxComputeProviderId("eigencloud")).toBe(true); + expect(isHostedSandboxComputeProviderId("aws")).toBe(true); + expect(isHostedSandboxComputeProviderId("digitalocean")).toBe(true); + expect(isHostedSandboxComputeProviderId("local")).toBe(false); + }); + + it("provisions hosted compute providers through openshell by default", async () => { + const runtime = { + log: vi.fn(), + error: vi.fn(), + exit: vi.fn(), + }; + const cfg = resolveSandboxConfigForAgent({ + agents: { + defaults: { + sandbox: { + mode: "all", + scope: "session", + compute: { + provider: "aws", + }, + }, + }, + }, + }); + + const result = await provisionHostedSandboxCompute({ + providerId: "aws", + cfg, + sessionKey: "agent:worker:task", + runtime, + }); + + expect(result.runtime.providerId).toBe("aws"); + expect(result.runtime.runtimeKind).toBe("hosted-vm"); + expect(result.cfg.backend).toBe("openshell"); + expect(result.runtime.access).toEqual({}); + expect(result.runtime.capabilities).toEqual({ + sshAccess: true, + httpsAccess: false, + supportsAttestation: false, + supportsSecretRelease: false, + }); + expect(result.runtime.evidence).toEqual({ + summary: "Managed via OpenShell provider-backed sandbox provisioning.", + }); + expect(runtime.log).toHaveBeenCalled(); + }); + + it("supports explicit ssh overrides for hosted providers", async () => { + const runtime = { + log: vi.fn(), + error: vi.fn(), + exit: vi.fn(), + }; + const cfg = resolveSandboxConfigForAgent({ + agents: { + defaults: { + sandbox: { + mode: "all", + scope: "session", + backend: "ssh", + compute: { + provider: "aws", + hosted: { + aws: { target: "ec2-user@aws-host:22" }, + }, + }, + }, + }, + }, + }); + + const result = await provisionHostedSandboxCompute({ + providerId: "aws", + cfg, + sessionKey: "agent:worker:task", + runtime, + }); + + expect(result.cfg.backend).toBe("ssh"); + expect(result.runtime.access.sshTarget).toBe("ec2-user@aws-host:22"); + }); + + it("reports healthcheck failures with details", async () => { + const runtime = { + log: vi.fn(), + error: vi.fn(), + exit: vi.fn(), + }; + const cfg = resolveSandboxConfigForAgent({ + agents: { + defaults: { + sandbox: { + mode: "all", + scope: "session", + compute: { + provider: "digitalocean", + hosted: { + digitalocean: { target: "root@do-host:22" }, + }, + }, + }, + }, + }, + }); + + const sandbox = { + backend: { + runShellCommand: async () => ({ + stdout: Buffer.alloc(0), + stderr: Buffer.from("no route"), + code: 1, + }), + }, + } as unknown as SandboxContext; + + const result = await healthcheckHostedSandboxCompute({ + providerId: "digitalocean", + cfg, + sandbox, + runtime, + }); + + expect(result.ok).toBe(false); + expect(result.durationMs).toBeGreaterThanOrEqual(0); + expect(result.detail).toContain("exit code 1"); + expect(runtime.error).toHaveBeenCalled(); + }); +}); diff --git a/src/agents/sandbox/compute/registry.ts b/src/agents/sandbox/compute/registry.ts new file mode 100644 index 00000000..8ff3dc97 --- /dev/null +++ b/src/agents/sandbox/compute/registry.ts @@ -0,0 +1,105 @@ +import { defaultRuntime, type RuntimeEnv } from "../../../runtime.js"; +import { awsHostedComputeProvider } from "./providers/aws.js"; +import { digitaloceanHostedComputeProvider } from "./providers/digitalocean.js"; +import { eigencloudHostedComputeProvider } from "./providers/eigencloud.js"; +import type { + HostedSandboxComputeProvider, + HostedSandboxComputeProviderId, + HostedSandboxHealthcheckParams, + HostedSandboxHealthcheckResult, + HostedSandboxProvisionParams, + HostedSandboxProvisionResult, +} from "./types.js"; + +const HOSTED_SANDBOX_COMPUTE_PROVIDERS = new Map< + HostedSandboxComputeProviderId, + HostedSandboxComputeProvider +>(); + +export function isHostedSandboxComputeProviderId( + value: string, +): value is HostedSandboxComputeProviderId { + return value === "eigencloud" || value === "aws" || value === "digitalocean"; +} + +export function registerHostedSandboxComputeProvider(provider: HostedSandboxComputeProvider) { + HOSTED_SANDBOX_COMPUTE_PROVIDERS.set(provider.id, provider); + return () => { + if (HOSTED_SANDBOX_COMPUTE_PROVIDERS.get(provider.id) === provider) { + HOSTED_SANDBOX_COMPUTE_PROVIDERS.delete(provider.id); + } + }; +} + +function requireHostedSandboxComputeProvider( + providerId: HostedSandboxComputeProviderId, +): HostedSandboxComputeProvider { + const provider = HOSTED_SANDBOX_COMPUTE_PROVIDERS.get(providerId); + if (provider) { + return provider; + } + throw new Error(`Hosted sandbox compute provider "${providerId}" is not registered.`); +} + +function resolveRuntime(runtime: RuntimeEnv | undefined): RuntimeEnv { + return runtime ?? defaultRuntime; +} + +function formatHostedRuntimeAccess( + target: HostedSandboxProvisionResult["runtime"]["access"], +): string { + return target.sshTarget ?? target.httpsBaseUrl ?? "n/a"; +} + +export async function provisionHostedSandboxCompute(params: { + providerId: HostedSandboxComputeProviderId; + cfg: HostedSandboxProvisionParams["cfg"]; + sessionKey: string; + runtime?: RuntimeEnv; +}): Promise { + const runtime = resolveRuntime(params.runtime); + runtime.log( + `sandbox.compute provision start provider=${params.providerId} session=${params.sessionKey}`, + ); + const provider = requireHostedSandboxComputeProvider(params.providerId); + const result = await provider.provision({ + providerId: params.providerId, + cfg: params.cfg, + sessionKey: params.sessionKey, + runtime, + }); + runtime.log( + `sandbox.compute provision ok provider=${params.providerId} runtime_kind=${result.runtime.runtimeKind} access=${formatHostedRuntimeAccess(result.runtime.access)} backend=${result.cfg.backend}`, + ); + return result; +} + +export async function healthcheckHostedSandboxCompute(params: { + providerId: HostedSandboxComputeProviderId; + cfg: HostedSandboxHealthcheckParams["cfg"]; + sandbox: HostedSandboxHealthcheckParams["sandbox"]; + runtime?: RuntimeEnv; +}): Promise { + const runtime = resolveRuntime(params.runtime); + const provider = requireHostedSandboxComputeProvider(params.providerId); + const result = await provider.healthcheck({ + providerId: params.providerId, + cfg: params.cfg, + sandbox: params.sandbox, + runtime, + }); + if (result.ok) { + runtime.log( + `sandbox.compute healthcheck ok provider=${params.providerId} duration_ms=${result.durationMs}`, + ); + } else { + runtime.error( + `sandbox.compute healthcheck failed provider=${params.providerId} duration_ms=${result.durationMs} detail=${result.detail ?? "unknown"}`, + ); + } + return result; +} + +registerHostedSandboxComputeProvider(eigencloudHostedComputeProvider); +registerHostedSandboxComputeProvider(awsHostedComputeProvider); +registerHostedSandboxComputeProvider(digitaloceanHostedComputeProvider); diff --git a/src/agents/sandbox/compute/types.ts b/src/agents/sandbox/compute/types.ts new file mode 100644 index 00000000..3578a7ea --- /dev/null +++ b/src/agents/sandbox/compute/types.ts @@ -0,0 +1,47 @@ +import type { RuntimeEnv } from "../../../runtime.js"; +import type { + SandboxComputeRuntimeInfo, + SandboxComputeRuntimeKind, + SandboxContext, + SandboxConfig, + SandboxComputeProviderId, +} from "../types.js"; + +export type HostedSandboxComputeProviderId = Exclude; +export type HostedSandboxRuntimeKind = Exclude; + +export type HostedSandboxComputeRuntimeInfo = SandboxComputeRuntimeInfo & { + providerId: HostedSandboxComputeProviderId; + runtimeKind: HostedSandboxRuntimeKind; +}; + +export type HostedSandboxProvisionParams = { + providerId: HostedSandboxComputeProviderId; + cfg: SandboxConfig; + sessionKey: string; + runtime: RuntimeEnv; +}; + +export type HostedSandboxProvisionResult = { + cfg: SandboxConfig; + runtime: HostedSandboxComputeRuntimeInfo; +}; + +export type HostedSandboxHealthcheckParams = { + providerId: HostedSandboxComputeProviderId; + cfg: SandboxConfig; + sandbox: SandboxContext; + runtime: RuntimeEnv; +}; + +export type HostedSandboxHealthcheckResult = { + ok: boolean; + detail?: string; + durationMs: number; +}; + +export type HostedSandboxComputeProvider = { + id: HostedSandboxComputeProviderId; + provision(params: HostedSandboxProvisionParams): Promise; + healthcheck(params: HostedSandboxHealthcheckParams): Promise; +}; diff --git a/src/agents/sandbox/config.ts b/src/agents/sandbox/config.ts index c5bd29e9..ebbfb689 100644 --- a/src/agents/sandbox/config.ts +++ b/src/agents/sandbox/config.ts @@ -1,5 +1,9 @@ import type { OpenClawConfig } from "../../config/config.js"; -import type { SandboxSshSettings } from "../../config/types.sandbox.js"; +import type { + SandboxComputeHostedProviderSettings, + SandboxComputeSettings, + SandboxSshSettings, +} from "../../config/types.sandbox.js"; import { normalizeSecretInputString } from "../../config/types.secrets.js"; import { resolveAgentConfig } from "../agent-scope.js"; import { @@ -20,6 +24,9 @@ import { import { resolveSandboxToolPolicyForAgent } from "./tool-policy.js"; import type { SandboxBrowserConfig, + SandboxComputeConfig, + SandboxComputeHostedProviderConfig, + SandboxComputeProviderId, SandboxConfig, SandboxDockerConfig, SandboxPruneConfig, @@ -35,6 +42,8 @@ export const DANGEROUS_SANDBOX_DOCKER_BOOLEAN_KEYS = [ const DEFAULT_SANDBOX_SSH_COMMAND = "ssh"; const DEFAULT_SANDBOX_SSH_WORKSPACE_ROOT = "/tmp/openclaw-sandboxes"; +const DEFAULT_SANDBOX_COMPUTE_PROVIDER: SandboxComputeProviderId = "local"; +const DEFAULT_SANDBOX_COMPUTE_HOSTED_FALLBACK_TO_LOCAL = true; type DangerousSandboxDockerBooleanKey = (typeof DANGEROUS_SANDBOX_DOCKER_BOOLEAN_KEYS)[number]; type DangerousSandboxDockerBooleans = Pick; @@ -187,6 +196,134 @@ function normalizeRemoteRoot(value: string | undefined, fallback: string): strin return posix.replace(/\/+$/g, "") || "/"; } +function resolveSandboxComputeHostedProviderConfig(params: { + globalHosted?: Partial; + agentHosted?: Partial; +}): SandboxComputeHostedProviderConfig | undefined { + const globalHosted = params.globalHosted; + const agentHosted = params.agentHosted; + const target = normalizeOptionalString(agentHosted?.target ?? globalHosted?.target); + const command = normalizeOptionalString(agentHosted?.command ?? globalHosted?.command); + const workspaceRootRaw = agentHosted?.workspaceRoot ?? globalHosted?.workspaceRoot; + const workspaceRoot = + workspaceRootRaw !== undefined + ? normalizeRemoteRoot(workspaceRootRaw, DEFAULT_SANDBOX_SSH_WORKSPACE_ROOT) + : undefined; + const strictHostKeyChecking = + agentHosted?.strictHostKeyChecking ?? globalHosted?.strictHostKeyChecking; + const updateHostKeys = agentHosted?.updateHostKeys ?? globalHosted?.updateHostKeys; + const identityFile = normalizeOptionalString( + agentHosted?.identityFile ?? globalHosted?.identityFile, + ); + const certificateFile = normalizeOptionalString( + agentHosted?.certificateFile ?? globalHosted?.certificateFile, + ); + const knownHostsFile = normalizeOptionalString( + agentHosted?.knownHostsFile ?? globalHosted?.knownHostsFile, + ); + const identityData = normalizeSecretInputString( + agentHosted?.identityData ?? globalHosted?.identityData, + ); + const certificateData = normalizeSecretInputString( + agentHosted?.certificateData ?? globalHosted?.certificateData, + ); + const knownHostsData = normalizeSecretInputString( + agentHosted?.knownHostsData ?? globalHosted?.knownHostsData, + ); + const resolved: SandboxComputeHostedProviderConfig = { + target, + command, + workspaceRoot, + strictHostKeyChecking, + updateHostKeys, + identityFile, + certificateFile, + knownHostsFile, + identityData, + certificateData, + knownHostsData, + }; + return Object.values(resolved).some((value) => value !== undefined) ? resolved : undefined; +} + +export function resolveSandboxComputeConfig(params: { + scope: SandboxScope; + globalCompute?: Partial; + agentCompute?: Partial; +}): SandboxComputeConfig { + const agentCompute = params.scope === "shared" ? undefined : params.agentCompute; + const globalCompute = params.globalCompute; + return { + provider: agentCompute?.provider ?? globalCompute?.provider ?? DEFAULT_SANDBOX_COMPUTE_PROVIDER, + fallbackToLocalOnHostedFailure: + agentCompute?.fallbackToLocalOnHostedFailure ?? + globalCompute?.fallbackToLocalOnHostedFailure ?? + DEFAULT_SANDBOX_COMPUTE_HOSTED_FALLBACK_TO_LOCAL, + hosted: { + eigencloud: resolveSandboxComputeHostedProviderConfig({ + globalHosted: globalCompute?.hosted?.eigencloud, + agentHosted: agentCompute?.hosted?.eigencloud, + }), + aws: resolveSandboxComputeHostedProviderConfig({ + globalHosted: globalCompute?.hosted?.aws, + agentHosted: agentCompute?.hosted?.aws, + }), + digitalocean: resolveSandboxComputeHostedProviderConfig({ + globalHosted: globalCompute?.hosted?.digitalocean, + agentHosted: agentCompute?.hosted?.digitalocean, + }), + }, + }; +} + +function resolveSandboxBackendFromCompute(params: { + provider: SandboxComputeProviderId; + configuredBackend?: string; +}): string { + const configuredBackend = params.configuredBackend?.trim(); + if (configuredBackend) { + return configuredBackend; + } + return params.provider === "local" ? "docker" : "openshell"; +} + +function resolveHostedComputeProviderSshOverride( + compute: SandboxComputeConfig, +): SandboxComputeHostedProviderConfig | undefined { + switch (compute.provider) { + case "eigencloud": + return compute.hosted.eigencloud; + case "aws": + return compute.hosted.aws; + case "digitalocean": + return compute.hosted.digitalocean; + default: + return undefined; + } +} + +function mergeSandboxSshConfigWithHostedOverride( + base: SandboxSshConfig, + override?: SandboxComputeHostedProviderConfig, +): SandboxSshConfig { + if (!override) { + return base; + } + return { + target: override.target ?? base.target, + command: override.command ?? base.command, + workspaceRoot: override.workspaceRoot ?? base.workspaceRoot, + strictHostKeyChecking: override.strictHostKeyChecking ?? base.strictHostKeyChecking, + updateHostKeys: override.updateHostKeys ?? base.updateHostKeys, + identityFile: override.identityFile ?? base.identityFile, + certificateFile: override.certificateFile ?? base.certificateFile, + knownHostsFile: override.knownHostsFile ?? base.knownHostsFile, + identityData: override.identityData ?? base.identityData, + certificateData: override.certificateData ?? base.certificateData, + knownHostsData: override.knownHostsData ?? base.knownHostsData, + }; +} + export function resolveSandboxSshConfig(params: { scope: SandboxScope; globalSsh?: Partial; @@ -240,10 +377,31 @@ export function resolveSandboxConfigForAgent( }); const toolPolicy = resolveSandboxToolPolicyForAgent(cfg, agentId); + const compute = resolveSandboxComputeConfig({ + scope, + globalCompute: agent?.compute, + agentCompute: agentSandbox?.compute, + }); + const backend = resolveSandboxBackendFromCompute({ + provider: compute.provider, + configuredBackend: agentSandbox?.backend ?? agent?.backend, + }); + const sshBase = resolveSandboxSshConfig({ + scope, + globalSsh: agent?.ssh, + agentSsh: agentSandbox?.ssh, + }); + const ssh = + backend === "ssh" + ? mergeSandboxSshConfigWithHostedOverride( + sshBase, + resolveHostedComputeProviderSshOverride(compute), + ) + : sshBase; return { mode: agentSandbox?.mode ?? agent?.mode ?? "off", - backend: agentSandbox?.backend?.trim() || agent?.backend?.trim() || "docker", + backend, scope, workspaceAccess: agentSandbox?.workspaceAccess ?? agent?.workspaceAccess ?? "none", workspaceRoot: @@ -253,11 +411,8 @@ export function resolveSandboxConfigForAgent( globalDocker: agent?.docker, agentDocker: agentSandbox?.docker, }), - ssh: resolveSandboxSshConfig({ - scope, - globalSsh: agent?.ssh, - agentSsh: agentSandbox?.ssh, - }), + ssh, + compute, browser: resolveSandboxBrowserConfig({ scope, globalBrowser: agent?.browser, diff --git a/src/agents/sandbox/context.compute-fallback.test.ts b/src/agents/sandbox/context.compute-fallback.test.ts new file mode 100644 index 00000000..084023fc --- /dev/null +++ b/src/agents/sandbox/context.compute-fallback.test.ts @@ -0,0 +1,241 @@ +import { describe, expect, it } from "vitest"; +import type { OpenClawConfig } from "../../config/config.js"; +import { registerSandboxBackend } from "./backend.js"; +import { resolveSandboxContext } from "./context.js"; + +function createStaticBackend( + id: string, + runtimeId: string, + params?: { + healthcheckCode?: number; + }, +) { + const healthcheckCode = params?.healthcheckCode ?? 0; + return async () => ({ + id, + runtimeId, + runtimeLabel: runtimeId, + workdir: "/workspace", + buildExecSpec: async () => ({ + argv: [id, "exec"], + env: process.env, + stdinMode: "pipe-closed" as const, + }), + runShellCommand: async () => ({ + stdout: Buffer.alloc(0), + stderr: healthcheckCode === 0 ? Buffer.alloc(0) : Buffer.from("healthcheck failed"), + code: healthcheckCode, + }), + }); +} + +describe("sandbox compute fallback routing", () => { + it("falls back to local backend when hosted provider fails and fallback is enabled", async () => { + const restoreHosted = registerSandboxBackend("openshell", async () => { + throw new Error("hosted backend failed"); + }); + const restoreDocker = registerSandboxBackend( + "docker", + createStaticBackend("docker", "local-ok"), + ); + try { + const cfg: OpenClawConfig = { + agents: { + defaults: { + skipBootstrap: true, + sandbox: { + mode: "all", + scope: "session", + compute: { + provider: "eigencloud", + fallbackToLocalOnHostedFailure: true, + }, + }, + }, + }, + }; + + const result = await resolveSandboxContext({ + config: cfg, + sessionKey: "agent:worker:task", + workspaceDir: "/tmp/openclaw-test", + }); + + expect(result?.backendId).toBe("docker"); + expect(result?.runtimeId).toBe("local-ok"); + expect(result?.compute).toEqual({ + providerId: "local", + runtimeKind: "local-container", + access: {}, + capabilities: { + sshAccess: false, + httpsAccess: false, + supportsAttestation: false, + supportsSecretRelease: false, + }, + }); + } finally { + restoreDocker(); + restoreHosted(); + } + }); + + it("returns hosted failure when fallback is disabled", async () => { + const restoreHosted = registerSandboxBackend("openshell", async () => { + throw new Error("hosted backend failed"); + }); + try { + const cfg: OpenClawConfig = { + agents: { + defaults: { + skipBootstrap: true, + sandbox: { + mode: "all", + scope: "session", + compute: { + provider: "aws", + fallbackToLocalOnHostedFailure: false, + }, + }, + }, + }, + }; + + await expect( + resolveSandboxContext({ + config: cfg, + sessionKey: "agent:worker:task", + workspaceDir: "/tmp/openclaw-test", + }), + ).rejects.toThrow("hosted backend failed"); + } finally { + restoreHosted(); + } + }); + + it("falls back to local backend when hosted healthcheck fails and fallback is enabled", async () => { + const restoreHosted = registerSandboxBackend( + "openshell", + createStaticBackend("openshell", "hosted-runtime", { healthcheckCode: 1 }), + ); + const restoreDocker = registerSandboxBackend( + "docker", + createStaticBackend("docker", "local-ok"), + ); + try { + const cfg: OpenClawConfig = { + agents: { + defaults: { + skipBootstrap: true, + sandbox: { + mode: "all", + scope: "session", + compute: { + provider: "digitalocean", + fallbackToLocalOnHostedFailure: true, + }, + }, + }, + }, + }; + + const result = await resolveSandboxContext({ + config: cfg, + sessionKey: "agent:worker:task", + workspaceDir: "/tmp/openclaw-test", + }); + + expect(result?.backendId).toBe("docker"); + expect(result?.runtimeId).toBe("local-ok"); + expect(result?.compute.providerId).toBe("local"); + expect(result?.compute.runtimeKind).toBe("local-container"); + } finally { + restoreDocker(); + restoreHosted(); + } + }); + + it("returns healthcheck failure when fallback is disabled", async () => { + const restoreHosted = registerSandboxBackend( + "openshell", + createStaticBackend("openshell", "hosted-runtime", { healthcheckCode: 1 }), + ); + try { + const cfg: OpenClawConfig = { + agents: { + defaults: { + skipBootstrap: true, + sandbox: { + mode: "all", + scope: "session", + compute: { + provider: "digitalocean", + fallbackToLocalOnHostedFailure: false, + }, + }, + }, + }, + }; + + await expect( + resolveSandboxContext({ + config: cfg, + sessionKey: "agent:worker:task", + workspaceDir: "/tmp/openclaw-test", + }), + ).rejects.toThrow('Sandbox compute provider "digitalocean" healthcheck failed.'); + } finally { + restoreHosted(); + } + }); + + it("preserves hosted runtime metadata when hosted provisioning succeeds", async () => { + const restoreHosted = registerSandboxBackend( + "openshell", + createStaticBackend("openshell", "hosted-ok"), + ); + try { + const cfg: OpenClawConfig = { + agents: { + defaults: { + skipBootstrap: true, + sandbox: { + mode: "all", + scope: "session", + compute: { + provider: "eigencloud", + fallbackToLocalOnHostedFailure: true, + }, + }, + }, + }, + }; + + const result = await resolveSandboxContext({ + config: cfg, + sessionKey: "agent:worker:task", + workspaceDir: "/tmp/openclaw-test", + }); + + expect(result?.backendId).toBe("openshell"); + expect(result?.runtimeId).toBe("hosted-ok"); + expect(result?.compute).toEqual({ + providerId: "eigencloud", + runtimeKind: "hosted-attested-app", + access: {}, + capabilities: { + sshAccess: true, + httpsAccess: false, + supportsAttestation: false, + supportsSecretRelease: false, + }, + evidence: { + summary: + "Managed via OpenShell on EigenCloud; attestation verification is not exposed through the current sandbox contract yet.", + }, + }); + } finally { + restoreHosted(); + } + }); +}); diff --git a/src/agents/sandbox/context.ts b/src/agents/sandbox/context.ts index 031b7c45..bd2e3513 100644 --- a/src/agents/sandbox/context.ts +++ b/src/agents/sandbox/context.ts @@ -9,13 +9,25 @@ import { syncSkillsToWorkspace } from "../skills.js"; import { DEFAULT_AGENT_WORKSPACE_DIR } from "../workspace.js"; import { requireSandboxBackendFactory } from "./backend.js"; import { ensureSandboxBrowser } from "./browser.js"; +import { + healthcheckHostedSandboxCompute, + isHostedSandboxComputeProviderId, + provisionHostedSandboxCompute, +} from "./compute/registry.js"; +import type { HostedSandboxComputeRuntimeInfo } from "./compute/types.js"; import { resolveSandboxConfigForAgent } from "./config.js"; import { createSandboxFsBridge } from "./fs-bridge.js"; import { maybePruneSandboxes } from "./prune.js"; import { updateRegistry } from "./registry.js"; import { resolveSandboxRuntimeStatus } from "./runtime-status.js"; import { resolveSandboxScopeKey, resolveSandboxWorkspaceDir } from "./shared.js"; -import type { SandboxContext, SandboxDockerConfig, SandboxWorkspaceInfo } from "./types.js"; +import type { + SandboxConfig, + SandboxComputeRuntimeInfo, + SandboxContext, + SandboxDockerConfig, + SandboxWorkspaceInfo, +} from "./types.js"; import { ensureSandboxWorkspace } from "./workspace.js"; async function ensureSandboxWorkspaceLayout(params: { @@ -106,16 +118,70 @@ function resolveSandboxSession(params: { config?: OpenClawConfig; sessionKey?: s return { rawSessionKey, runtime, cfg }; } -export async function resolveSandboxContext(params: { +function formatSandboxError(error: unknown): string { + if (error instanceof Error) { + return error.message; + } + try { + return JSON.stringify(error); + } catch { + return String(error); + } +} + +function resolveSandboxComputeRuntimeInfo(params: { + cfg: SandboxConfig; + provisionedRuntime?: HostedSandboxComputeRuntimeInfo; +}): SandboxComputeRuntimeInfo { + if (params.provisionedRuntime) { + return params.provisionedRuntime; + } + + const providerId = params.cfg.compute?.provider ?? "local"; + if (providerId === "local") { + return { + providerId, + runtimeKind: "local-container", + access: {}, + capabilities: { + sshAccess: false, + httpsAccess: false, + supportsAttestation: false, + supportsSecretRelease: false, + }, + }; + } + + return { + providerId, + runtimeKind: providerId === "eigencloud" ? "hosted-attested-app" : "hosted-vm", + access: params.cfg.backend === "ssh" ? { sshTarget: params.cfg.ssh.target } : {}, + capabilities: { + sshAccess: params.cfg.backend === "ssh" || params.cfg.backend === "openshell", + httpsAccess: false, + supportsAttestation: false, + supportsSecretRelease: false, + }, + evidence: + providerId === "eigencloud" + ? { + summary: + params.cfg.backend === "openshell" + ? "Managed via OpenShell on EigenCloud; attestation verification is not exposed through the current sandbox contract yet." + : "Phase-0 SSH scaffold; native EigenCloud attestation and secret-release hooks are not wired yet.", + } + : undefined, + }; +} + +async function resolveSandboxContextWithConfig(params: { config?: OpenClawConfig; - sessionKey?: string; workspaceDir?: string; -}): Promise { - const resolved = resolveSandboxSession(params); - if (!resolved) { - return null; - } - const { rawSessionKey, cfg } = resolved; + rawSessionKey: string; + cfg: SandboxConfig; + provisionedRuntime?: HostedSandboxComputeRuntimeInfo; +}): Promise { + const { rawSessionKey, cfg } = params; await maybePruneSandboxes(cfg); @@ -164,8 +230,9 @@ export async function resolveSandboxContext(params: { const ensured = await ensureBrowserControlAuth({ cfg: cfgForAuth }); browserAuth = ensured.auth; } catch (error) { - const message = error instanceof Error ? error.message : JSON.stringify(error); - defaultRuntime.error?.(`Sandbox browser auth ensure failed: ${message}`); + defaultRuntime.error?.( + `Sandbox browser auth ensure failed: ${formatSandboxError(error)}`, + ); } return browserAuth; })() @@ -199,6 +266,10 @@ export async function resolveSandboxContext(params: { containerName: backend.runtimeId, containerWorkdir: backend.workdir, docker: resolvedCfg.docker, + compute: resolveSandboxComputeRuntimeInfo({ + cfg: resolvedCfg, + provisionedRuntime: params.provisionedRuntime, + }), tools: resolvedCfg.tools, browserAllowHostControl: resolvedCfg.browser.allowHostControl, browser: browser ?? undefined, @@ -212,6 +283,101 @@ export async function resolveSandboxContext(params: { return sandboxContext; } +export async function resolveSandboxContext(params: { + config?: OpenClawConfig; + sessionKey?: string; + workspaceDir?: string; +}): Promise { + const resolved = resolveSandboxSession(params); + if (!resolved) { + return null; + } + const { rawSessionKey, cfg } = resolved; + const computeProvider = cfg.compute?.provider ?? "local"; + if (!isHostedSandboxComputeProviderId(computeProvider)) { + return await resolveSandboxContextWithConfig({ + config: params.config, + workspaceDir: params.workspaceDir, + rawSessionKey, + cfg, + }); + } + + try { + const provisioned = await provisionHostedSandboxCompute({ + providerId: computeProvider, + cfg, + sessionKey: rawSessionKey, + runtime: defaultRuntime, + }); + const hostedSandbox = await resolveSandboxContextWithConfig({ + config: params.config, + workspaceDir: params.workspaceDir, + rawSessionKey, + cfg: provisioned.cfg, + provisionedRuntime: provisioned.runtime, + }); + const healthcheck = await healthcheckHostedSandboxCompute({ + providerId: computeProvider, + cfg: provisioned.cfg, + sandbox: hostedSandbox, + runtime: defaultRuntime, + }); + if (!healthcheck.ok) { + throw new Error( + [ + `Sandbox compute provider "${computeProvider}" healthcheck failed.`, + healthcheck.detail ? `detail: ${healthcheck.detail}` : undefined, + ] + .filter(Boolean) + .join(" "), + ); + } + return hostedSandbox; + } catch (hostedError) { + const fallbackToLocal = cfg.compute?.fallbackToLocalOnHostedFailure ?? true; + if (!fallbackToLocal) { + throw hostedError; + } + defaultRuntime.log?.( + `Sandbox compute provider "${computeProvider}" failed; retrying with local backend. detail=${formatSandboxError(hostedError)}`, + ); + const fallbackCfg: SandboxConfig = { + ...cfg, + backend: "docker", + compute: { + provider: "local", + fallbackToLocalOnHostedFailure: fallbackToLocal, + hosted: cfg.compute?.hosted ?? {}, + }, + }; + try { + const fallbackSandbox = await resolveSandboxContextWithConfig({ + config: params.config, + workspaceDir: params.workspaceDir, + rawSessionKey, + cfg: fallbackCfg, + }); + defaultRuntime.log?.( + `sandbox.compute fallback ok provider=${computeProvider} fallback_provider=local`, + ); + return fallbackSandbox; + } catch (fallbackError) { + defaultRuntime.error?.( + `sandbox.compute fallback failed provider=${computeProvider} fallback_provider=local detail=${formatSandboxError(fallbackError)}`, + ); + throw new Error( + [ + `Sandbox hosted provider "${computeProvider}" failed and local fallback also failed.`, + `Hosted error: ${formatSandboxError(hostedError)}`, + `Local fallback error: ${formatSandboxError(fallbackError)}`, + ].join("\n"), + { cause: fallbackError }, + ); + } + } +} + export async function ensureSandboxWorkspaceForSession(params: { config?: OpenClawConfig; sessionKey?: string; diff --git a/src/agents/sandbox/test-fixtures.ts b/src/agents/sandbox/test-fixtures.ts index b20b5b45..c88752da 100644 --- a/src/agents/sandbox/test-fixtures.ts +++ b/src/agents/sandbox/test-fixtures.ts @@ -38,6 +38,17 @@ export function createSandboxTestContext(params?: { containerName: "openclaw-sbx-test", containerWorkdir: "/workspace", tools: { allow: ["*"], deny: [] }, + compute: { + providerId: "local", + runtimeKind: "local-container", + access: {}, + capabilities: { + sshAccess: false, + httpsAccess: false, + supportsAttestation: false, + supportsSecretRelease: false, + }, + }, browserAllowHostControl: false, ...sandboxOverrides, docker, diff --git a/src/agents/sandbox/types.ts b/src/agents/sandbox/types.ts index 482ce6a9..a9aea6d0 100644 --- a/src/agents/sandbox/types.ts +++ b/src/agents/sandbox/types.ts @@ -65,6 +65,59 @@ export type SandboxSshConfig = { knownHostsData?: string; }; +export type SandboxComputeProviderId = "local" | "eigencloud" | "aws" | "digitalocean"; + +export type SandboxComputeHostedProviderConfig = { + target?: string; + command?: string; + workspaceRoot?: string; + strictHostKeyChecking?: boolean; + updateHostKeys?: boolean; + identityFile?: string; + certificateFile?: string; + knownHostsFile?: string; + identityData?: string; + certificateData?: string; + knownHostsData?: string; +}; + +export type SandboxComputeRuntimeKind = "local-container" | "hosted-vm" | "hosted-attested-app"; + +export type SandboxComputeAccess = { + sshTarget?: string; + httpsBaseUrl?: string; +}; + +export type SandboxComputeCapabilities = { + sshAccess: boolean; + httpsAccess: boolean; + supportsAttestation: boolean; + supportsSecretRelease: boolean; +}; + +export type SandboxComputeEvidence = { + summary?: string; + verifyUrl?: string; +}; + +export type SandboxComputeRuntimeInfo = { + providerId: SandboxComputeProviderId; + runtimeKind: SandboxComputeRuntimeKind; + access: SandboxComputeAccess; + capabilities: SandboxComputeCapabilities; + evidence?: SandboxComputeEvidence; +}; + +export type SandboxComputeConfig = { + provider: SandboxComputeProviderId; + fallbackToLocalOnHostedFailure: boolean; + hosted: { + eigencloud?: SandboxComputeHostedProviderConfig; + aws?: SandboxComputeHostedProviderConfig; + digitalocean?: SandboxComputeHostedProviderConfig; + }; +}; + export type SandboxScope = "session" | "agent" | "shared"; export type SandboxConfig = { @@ -75,6 +128,7 @@ export type SandboxConfig = { workspaceRoot: string; docker: SandboxDockerConfig; ssh: SandboxSshConfig; + compute?: SandboxComputeConfig; browser: SandboxBrowserConfig; tools: SandboxToolPolicy; prune: SandboxPruneConfig; @@ -98,6 +152,7 @@ export type SandboxContext = { containerName: string; containerWorkdir: string; docker: SandboxDockerConfig; + compute: SandboxComputeRuntimeInfo; tools: SandboxToolPolicy; browserAllowHostControl: boolean; browser?: SandboxBrowserContext; diff --git a/src/agents/test-helpers/pi-tools-sandbox-context.ts b/src/agents/test-helpers/pi-tools-sandbox-context.ts index abf712c2..1d64e9cb 100644 --- a/src/agents/test-helpers/pi-tools-sandbox-context.ts +++ b/src/agents/test-helpers/pi-tools-sandbox-context.ts @@ -28,6 +28,17 @@ export function createPiToolsSandboxContext(params: PiToolsSandboxContextParams) containerName: params.containerName ?? "openclaw-sbx-test", containerWorkdir: params.containerWorkdir ?? "/workspace", fsBridge: params.fsBridge, + compute: { + providerId: "local", + runtimeKind: "local-container", + access: {}, + capabilities: { + sshAccess: false, + httpsAccess: false, + supportsAttestation: false, + supportsSecretRelease: false, + }, + }, docker: { image: "openclaw-sandbox:bookworm-slim", containerPrefix: "openclaw-sbx-", diff --git a/src/canvas-host/a2ui/a2ui.bundle.js b/src/canvas-host/a2ui/a2ui.bundle.js index 4193fb64..84abe173 100644 --- a/src/canvas-host/a2ui/a2ui.bundle.js +++ b/src/canvas-host/a2ui/a2ui.bundle.js @@ -1,849 +1,1205 @@ var __defProp$1 = Object.defineProperty; var __exportAll = (all, no_symbols) => { - let target = {}; - for (var name in all) __defProp$1(target, name, { - get: all[name], - enumerable: true - }); - if (!no_symbols) __defProp$1(target, Symbol.toStringTag, { value: "Module" }); - return target; + let target = {}; + for (var name in all) + __defProp$1(target, name, { + get: all[name], + enumerable: true, + }); + if (!no_symbols) __defProp$1(target, Symbol.toStringTag, { value: "Module" }); + return target; }; /** -* @license -* Copyright 2019 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ -const t$6 = globalThis, e$13 = t$6.ShadowRoot && (void 0 === t$6.ShadyCSS || t$6.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype, s$8 = Symbol(), o$14 = /* @__PURE__ */ new WeakMap(); + * @license + * Copyright 2019 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ +const t$6 = globalThis, + e$13 = + t$6.ShadowRoot && + (void 0 === t$6.ShadyCSS || t$6.ShadyCSS.nativeShadow) && + "adoptedStyleSheets" in Document.prototype && + "replace" in CSSStyleSheet.prototype, + s$8 = Symbol(), + o$14 = /* @__PURE__ */ new WeakMap(); var n$12 = class { - constructor(t, e, o) { - if (this._$cssResult$ = !0, o !== s$8) throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead."); - this.cssText = t, this.t = e; - } - get styleSheet() { - let t = this.o; - const s = this.t; - if (e$13 && void 0 === t) { - const e = void 0 !== s && 1 === s.length; - e && (t = o$14.get(s)), void 0 === t && ((this.o = t = new CSSStyleSheet()).replaceSync(this.cssText), e && o$14.set(s, t)); - } - return t; - } - toString() { - return this.cssText; - } -}; -const r$11 = (t) => new n$12("string" == typeof t ? t : t + "", void 0, s$8), i$9 = (t, ...e) => { - return new n$12(1 === t.length ? t[0] : e.reduce((e, s, o) => e + ((t) => { - if (!0 === t._$cssResult$) return t.cssText; - if ("number" == typeof t) return t; - throw Error("Value passed to 'css' function must be a 'css' function result: " + t + ". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security."); - })(s) + t[o + 1], t[0]), t, s$8); -}, S$1 = (s, o) => { - if (e$13) s.adoptedStyleSheets = o.map((t) => t instanceof CSSStyleSheet ? t : t.styleSheet); - else for (const e of o) { - const o = document.createElement("style"), n = t$6.litNonce; - void 0 !== n && o.setAttribute("nonce", n), o.textContent = e.cssText, s.appendChild(o); - } -}, c$6 = e$13 ? (t) => t : (t) => t instanceof CSSStyleSheet ? ((t) => { - let e = ""; - for (const s of t.cssRules) e += s.cssText; - return r$11(e); -})(t) : t; + constructor(t, e, o) { + if (((this._$cssResult$ = !0), o !== s$8)) + throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead."); + ((this.cssText = t), (this.t = e)); + } + get styleSheet() { + let t = this.o; + const s = this.t; + if (e$13 && void 0 === t) { + const e = void 0 !== s && 1 === s.length; + (e && (t = o$14.get(s)), + void 0 === t && + ((this.o = t = new CSSStyleSheet()).replaceSync(this.cssText), e && o$14.set(s, t))); + } + return t; + } + toString() { + return this.cssText; + } +}; +const r$11 = (t) => new n$12("string" == typeof t ? t : t + "", void 0, s$8), + i$9 = (t, ...e) => { + return new n$12( + 1 === t.length + ? t[0] + : e.reduce( + (e, s, o) => + e + + ((t) => { + if (!0 === t._$cssResult$) return t.cssText; + if ("number" == typeof t) return t; + throw Error( + "Value passed to 'css' function must be a 'css' function result: " + + t + + ". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.", + ); + })(s) + + t[o + 1], + t[0], + ), + t, + s$8, + ); + }, + S$1 = (s, o) => { + if (e$13) s.adoptedStyleSheets = o.map((t) => (t instanceof CSSStyleSheet ? t : t.styleSheet)); + else + for (const e of o) { + const o = document.createElement("style"), + n = t$6.litNonce; + (void 0 !== n && o.setAttribute("nonce", n), (o.textContent = e.cssText), s.appendChild(o)); + } + }, + c$6 = e$13 + ? (t) => t + : (t) => + t instanceof CSSStyleSheet + ? ((t) => { + let e = ""; + for (const s of t.cssRules) e += s.cssText; + return r$11(e); + })(t) + : t; /** -* @license -* Copyright 2017 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ const { is: i$8, defineProperty: e$12, getOwnPropertyDescriptor: h$6, getOwnPropertyNames: r$10, getOwnPropertySymbols: o$13, getPrototypeOf: n$11 } = Object, a$1 = globalThis, c$5 = a$1.trustedTypes, l$4 = c$5 ? c$5.emptyScript : "", p$2 = a$1.reactiveElementPolyfillSupport, d$2 = (t, s) => t, u$3 = { - toAttribute(t, s) { - switch (s) { - case Boolean: - t = t ? l$4 : null; - break; - case Object: - case Array: t = null == t ? t : JSON.stringify(t); - } - return t; - }, - fromAttribute(t, s) { - let i = t; - switch (s) { - case Boolean: - i = null !== t; - break; - case Number: - i = null === t ? null : Number(t); - break; - case Object: - case Array: try { - i = JSON.parse(t); - } catch (t) { - i = null; - } - } - return i; - } -}, f$3 = (t, s) => !i$8(t, s), b$1 = { - attribute: !0, - type: String, - converter: u$3, - reflect: !1, - useDefault: !1, - hasChanged: f$3 -}; -Symbol.metadata ??= Symbol("metadata"), a$1.litPropertyMetadata ??= /* @__PURE__ */ new WeakMap(); + * @license + * Copyright 2017 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ const { + is: i$8, + defineProperty: e$12, + getOwnPropertyDescriptor: h$6, + getOwnPropertyNames: r$10, + getOwnPropertySymbols: o$13, + getPrototypeOf: n$11, + } = Object, + a$1 = globalThis, + c$5 = a$1.trustedTypes, + l$4 = c$5 ? c$5.emptyScript : "", + p$2 = a$1.reactiveElementPolyfillSupport, + d$2 = (t, s) => t, + u$3 = { + toAttribute(t, s) { + switch (s) { + case Boolean: + t = t ? l$4 : null; + break; + case Object: + case Array: + t = null == t ? t : JSON.stringify(t); + } + return t; + }, + fromAttribute(t, s) { + let i = t; + switch (s) { + case Boolean: + i = null !== t; + break; + case Number: + i = null === t ? null : Number(t); + break; + case Object: + case Array: + try { + i = JSON.parse(t); + } catch (t) { + i = null; + } + } + return i; + }, + }, + f$3 = (t, s) => !i$8(t, s), + b$1 = { + attribute: !0, + type: String, + converter: u$3, + reflect: !1, + useDefault: !1, + hasChanged: f$3, + }; +((Symbol.metadata ??= Symbol("metadata")), + (a$1.litPropertyMetadata ??= /* @__PURE__ */ new WeakMap())); var y$1 = class extends HTMLElement { - static addInitializer(t) { - this._$Ei(), (this.l ??= []).push(t); - } - static get observedAttributes() { - return this.finalize(), this._$Eh && [...this._$Eh.keys()]; - } - static createProperty(t, s = b$1) { - if (s.state && (s.attribute = !1), this._$Ei(), this.prototype.hasOwnProperty(t) && ((s = Object.create(s)).wrapped = !0), this.elementProperties.set(t, s), !s.noAccessor) { - const i = Symbol(), h = this.getPropertyDescriptor(t, i, s); - void 0 !== h && e$12(this.prototype, t, h); - } - } - static getPropertyDescriptor(t, s, i) { - const { get: e, set: r } = h$6(this.prototype, t) ?? { - get() { - return this[s]; - }, - set(t) { - this[s] = t; - } - }; - return { - get: e, - set(s) { - const h = e?.call(this); - r?.call(this, s), this.requestUpdate(t, h, i); - }, - configurable: !0, - enumerable: !0 - }; - } - static getPropertyOptions(t) { - return this.elementProperties.get(t) ?? b$1; - } - static _$Ei() { - if (this.hasOwnProperty(d$2("elementProperties"))) return; - const t = n$11(this); - t.finalize(), void 0 !== t.l && (this.l = [...t.l]), this.elementProperties = new Map(t.elementProperties); - } - static finalize() { - if (this.hasOwnProperty(d$2("finalized"))) return; - if (this.finalized = !0, this._$Ei(), this.hasOwnProperty(d$2("properties"))) { - const t = this.properties, s = [...r$10(t), ...o$13(t)]; - for (const i of s) this.createProperty(i, t[i]); - } - const t = this[Symbol.metadata]; - if (null !== t) { - const s = litPropertyMetadata.get(t); - if (void 0 !== s) for (const [t, i] of s) this.elementProperties.set(t, i); - } - this._$Eh = /* @__PURE__ */ new Map(); - for (const [t, s] of this.elementProperties) { - const i = this._$Eu(t, s); - void 0 !== i && this._$Eh.set(i, t); - } - this.elementStyles = this.finalizeStyles(this.styles); - } - static finalizeStyles(s) { - const i = []; - if (Array.isArray(s)) { - const e = new Set(s.flat(Infinity).reverse()); - for (const s of e) i.unshift(c$6(s)); - } else void 0 !== s && i.push(c$6(s)); - return i; - } - static _$Eu(t, s) { - const i = s.attribute; - return !1 === i ? void 0 : "string" == typeof i ? i : "string" == typeof t ? t.toLowerCase() : void 0; - } - constructor() { - super(), this._$Ep = void 0, this.isUpdatePending = !1, this.hasUpdated = !1, this._$Em = null, this._$Ev(); - } - _$Ev() { - this._$ES = new Promise((t) => this.enableUpdating = t), this._$AL = /* @__PURE__ */ new Map(), this._$E_(), this.requestUpdate(), this.constructor.l?.forEach((t) => t(this)); - } - addController(t) { - (this._$EO ??= /* @__PURE__ */ new Set()).add(t), void 0 !== this.renderRoot && this.isConnected && t.hostConnected?.(); - } - removeController(t) { - this._$EO?.delete(t); - } - _$E_() { - const t = /* @__PURE__ */ new Map(), s = this.constructor.elementProperties; - for (const i of s.keys()) this.hasOwnProperty(i) && (t.set(i, this[i]), delete this[i]); - t.size > 0 && (this._$Ep = t); - } - createRenderRoot() { - const t = this.shadowRoot ?? this.attachShadow(this.constructor.shadowRootOptions); - return S$1(t, this.constructor.elementStyles), t; - } - connectedCallback() { - this.renderRoot ??= this.createRenderRoot(), this.enableUpdating(!0), this._$EO?.forEach((t) => t.hostConnected?.()); - } - enableUpdating(t) {} - disconnectedCallback() { - this._$EO?.forEach((t) => t.hostDisconnected?.()); - } - attributeChangedCallback(t, s, i) { - this._$AK(t, i); - } - _$ET(t, s) { - const i = this.constructor.elementProperties.get(t), e = this.constructor._$Eu(t, i); - if (void 0 !== e && !0 === i.reflect) { - const h = (void 0 !== i.converter?.toAttribute ? i.converter : u$3).toAttribute(s, i.type); - this._$Em = t, null == h ? this.removeAttribute(e) : this.setAttribute(e, h), this._$Em = null; - } - } - _$AK(t, s) { - const i = this.constructor, e = i._$Eh.get(t); - if (void 0 !== e && this._$Em !== e) { - const t = i.getPropertyOptions(e), h = "function" == typeof t.converter ? { fromAttribute: t.converter } : void 0 !== t.converter?.fromAttribute ? t.converter : u$3; - this._$Em = e; - const r = h.fromAttribute(s, t.type); - this[e] = r ?? this._$Ej?.get(e) ?? r, this._$Em = null; - } - } - requestUpdate(t, s, i, e = !1, h) { - if (void 0 !== t) { - const r = this.constructor; - if (!1 === e && (h = this[t]), i ??= r.getPropertyOptions(t), !((i.hasChanged ?? f$3)(h, s) || i.useDefault && i.reflect && h === this._$Ej?.get(t) && !this.hasAttribute(r._$Eu(t, i)))) return; - this.C(t, s, i); - } - !1 === this.isUpdatePending && (this._$ES = this._$EP()); - } - C(t, s, { useDefault: i, reflect: e, wrapped: h }, r) { - i && !(this._$Ej ??= /* @__PURE__ */ new Map()).has(t) && (this._$Ej.set(t, r ?? s ?? this[t]), !0 !== h || void 0 !== r) || (this._$AL.has(t) || (this.hasUpdated || i || (s = void 0), this._$AL.set(t, s)), !0 === e && this._$Em !== t && (this._$Eq ??= /* @__PURE__ */ new Set()).add(t)); - } - async _$EP() { - this.isUpdatePending = !0; - try { - await this._$ES; - } catch (t) { - Promise.reject(t); - } - const t = this.scheduleUpdate(); - return null != t && await t, !this.isUpdatePending; - } - scheduleUpdate() { - return this.performUpdate(); - } - performUpdate() { - if (!this.isUpdatePending) return; - if (!this.hasUpdated) { - if (this.renderRoot ??= this.createRenderRoot(), this._$Ep) { - for (const [t, s] of this._$Ep) this[t] = s; - this._$Ep = void 0; - } - const t = this.constructor.elementProperties; - if (t.size > 0) for (const [s, i] of t) { - const { wrapped: t } = i, e = this[s]; - !0 !== t || this._$AL.has(s) || void 0 === e || this.C(s, void 0, i, e); - } - } - let t = !1; - const s = this._$AL; - try { - t = this.shouldUpdate(s), t ? (this.willUpdate(s), this._$EO?.forEach((t) => t.hostUpdate?.()), this.update(s)) : this._$EM(); - } catch (s) { - throw t = !1, this._$EM(), s; - } - t && this._$AE(s); - } - willUpdate(t) {} - _$AE(t) { - this._$EO?.forEach((t) => t.hostUpdated?.()), this.hasUpdated || (this.hasUpdated = !0, this.firstUpdated(t)), this.updated(t); - } - _$EM() { - this._$AL = /* @__PURE__ */ new Map(), this.isUpdatePending = !1; - } - get updateComplete() { - return this.getUpdateComplete(); - } - getUpdateComplete() { - return this._$ES; - } - shouldUpdate(t) { - return !0; - } - update(t) { - this._$Eq &&= this._$Eq.forEach((t) => this._$ET(t, this[t])), this._$EM(); - } - updated(t) {} - firstUpdated(t) {} -}; -y$1.elementStyles = [], y$1.shadowRootOptions = { mode: "open" }, y$1[d$2("elementProperties")] = /* @__PURE__ */ new Map(), y$1[d$2("finalized")] = /* @__PURE__ */ new Map(), p$2?.({ ReactiveElement: y$1 }), (a$1.reactiveElementVersions ??= []).push("2.1.2"); + static addInitializer(t) { + (this._$Ei(), (this.l ??= []).push(t)); + } + static get observedAttributes() { + return (this.finalize(), this._$Eh && [...this._$Eh.keys()]); + } + static createProperty(t, s = b$1) { + if ( + (s.state && (s.attribute = !1), + this._$Ei(), + this.prototype.hasOwnProperty(t) && ((s = Object.create(s)).wrapped = !0), + this.elementProperties.set(t, s), + !s.noAccessor) + ) { + const i = Symbol(), + h = this.getPropertyDescriptor(t, i, s); + void 0 !== h && e$12(this.prototype, t, h); + } + } + static getPropertyDescriptor(t, s, i) { + const { get: e, set: r } = h$6(this.prototype, t) ?? { + get() { + return this[s]; + }, + set(t) { + this[s] = t; + }, + }; + return { + get: e, + set(s) { + const h = e?.call(this); + (r?.call(this, s), this.requestUpdate(t, h, i)); + }, + configurable: !0, + enumerable: !0, + }; + } + static getPropertyOptions(t) { + return this.elementProperties.get(t) ?? b$1; + } + static _$Ei() { + if (this.hasOwnProperty(d$2("elementProperties"))) return; + const t = n$11(this); + (t.finalize(), + void 0 !== t.l && (this.l = [...t.l]), + (this.elementProperties = new Map(t.elementProperties))); + } + static finalize() { + if (this.hasOwnProperty(d$2("finalized"))) return; + if (((this.finalized = !0), this._$Ei(), this.hasOwnProperty(d$2("properties")))) { + const t = this.properties, + s = [...r$10(t), ...o$13(t)]; + for (const i of s) this.createProperty(i, t[i]); + } + const t = this[Symbol.metadata]; + if (null !== t) { + const s = litPropertyMetadata.get(t); + if (void 0 !== s) for (const [t, i] of s) this.elementProperties.set(t, i); + } + this._$Eh = /* @__PURE__ */ new Map(); + for (const [t, s] of this.elementProperties) { + const i = this._$Eu(t, s); + void 0 !== i && this._$Eh.set(i, t); + } + this.elementStyles = this.finalizeStyles(this.styles); + } + static finalizeStyles(s) { + const i = []; + if (Array.isArray(s)) { + const e = new Set(s.flat(Infinity).reverse()); + for (const s of e) i.unshift(c$6(s)); + } else void 0 !== s && i.push(c$6(s)); + return i; + } + static _$Eu(t, s) { + const i = s.attribute; + return !1 === i + ? void 0 + : "string" == typeof i + ? i + : "string" == typeof t + ? t.toLowerCase() + : void 0; + } + constructor() { + (super(), + (this._$Ep = void 0), + (this.isUpdatePending = !1), + (this.hasUpdated = !1), + (this._$Em = null), + this._$Ev()); + } + _$Ev() { + ((this._$ES = new Promise((t) => (this.enableUpdating = t))), + (this._$AL = /* @__PURE__ */ new Map()), + this._$E_(), + this.requestUpdate(), + this.constructor.l?.forEach((t) => t(this))); + } + addController(t) { + ((this._$EO ??= /* @__PURE__ */ new Set()).add(t), + void 0 !== this.renderRoot && this.isConnected && t.hostConnected?.()); + } + removeController(t) { + this._$EO?.delete(t); + } + _$E_() { + const t = /* @__PURE__ */ new Map(), + s = this.constructor.elementProperties; + for (const i of s.keys()) this.hasOwnProperty(i) && (t.set(i, this[i]), delete this[i]); + t.size > 0 && (this._$Ep = t); + } + createRenderRoot() { + const t = this.shadowRoot ?? this.attachShadow(this.constructor.shadowRootOptions); + return (S$1(t, this.constructor.elementStyles), t); + } + connectedCallback() { + ((this.renderRoot ??= this.createRenderRoot()), + this.enableUpdating(!0), + this._$EO?.forEach((t) => t.hostConnected?.())); + } + enableUpdating(t) {} + disconnectedCallback() { + this._$EO?.forEach((t) => t.hostDisconnected?.()); + } + attributeChangedCallback(t, s, i) { + this._$AK(t, i); + } + _$ET(t, s) { + const i = this.constructor.elementProperties.get(t), + e = this.constructor._$Eu(t, i); + if (void 0 !== e && !0 === i.reflect) { + const h = (void 0 !== i.converter?.toAttribute ? i.converter : u$3).toAttribute(s, i.type); + ((this._$Em = t), + null == h ? this.removeAttribute(e) : this.setAttribute(e, h), + (this._$Em = null)); + } + } + _$AK(t, s) { + const i = this.constructor, + e = i._$Eh.get(t); + if (void 0 !== e && this._$Em !== e) { + const t = i.getPropertyOptions(e), + h = + "function" == typeof t.converter + ? { fromAttribute: t.converter } + : void 0 !== t.converter?.fromAttribute + ? t.converter + : u$3; + this._$Em = e; + const r = h.fromAttribute(s, t.type); + ((this[e] = r ?? this._$Ej?.get(e) ?? r), (this._$Em = null)); + } + } + requestUpdate(t, s, i, e = !1, h) { + if (void 0 !== t) { + const r = this.constructor; + if ( + (!1 === e && (h = this[t]), + (i ??= r.getPropertyOptions(t)), + !( + (i.hasChanged ?? f$3)(h, s) || + (i.useDefault && i.reflect && h === this._$Ej?.get(t) && !this.hasAttribute(r._$Eu(t, i))) + )) + ) + return; + this.C(t, s, i); + } + !1 === this.isUpdatePending && (this._$ES = this._$EP()); + } + C(t, s, { useDefault: i, reflect: e, wrapped: h }, r) { + (i && + !(this._$Ej ??= /* @__PURE__ */ new Map()).has(t) && + (this._$Ej.set(t, r ?? s ?? this[t]), !0 !== h || void 0 !== r)) || + (this._$AL.has(t) || (this.hasUpdated || i || (s = void 0), this._$AL.set(t, s)), + !0 === e && this._$Em !== t && (this._$Eq ??= /* @__PURE__ */ new Set()).add(t)); + } + async _$EP() { + this.isUpdatePending = !0; + try { + await this._$ES; + } catch (t) { + Promise.reject(t); + } + const t = this.scheduleUpdate(); + return (null != t && (await t), !this.isUpdatePending); + } + scheduleUpdate() { + return this.performUpdate(); + } + performUpdate() { + if (!this.isUpdatePending) return; + if (!this.hasUpdated) { + if (((this.renderRoot ??= this.createRenderRoot()), this._$Ep)) { + for (const [t, s] of this._$Ep) this[t] = s; + this._$Ep = void 0; + } + const t = this.constructor.elementProperties; + if (t.size > 0) + for (const [s, i] of t) { + const { wrapped: t } = i, + e = this[s]; + !0 !== t || this._$AL.has(s) || void 0 === e || this.C(s, void 0, i, e); + } + } + let t = !1; + const s = this._$AL; + try { + ((t = this.shouldUpdate(s)), + t + ? (this.willUpdate(s), this._$EO?.forEach((t) => t.hostUpdate?.()), this.update(s)) + : this._$EM()); + } catch (s) { + throw ((t = !1), this._$EM(), s); + } + t && this._$AE(s); + } + willUpdate(t) {} + _$AE(t) { + (this._$EO?.forEach((t) => t.hostUpdated?.()), + this.hasUpdated || ((this.hasUpdated = !0), this.firstUpdated(t)), + this.updated(t)); + } + _$EM() { + ((this._$AL = /* @__PURE__ */ new Map()), (this.isUpdatePending = !1)); + } + get updateComplete() { + return this.getUpdateComplete(); + } + getUpdateComplete() { + return this._$ES; + } + shouldUpdate(t) { + return !0; + } + update(t) { + ((this._$Eq &&= this._$Eq.forEach((t) => this._$ET(t, this[t]))), this._$EM()); + } + updated(t) {} + firstUpdated(t) {} +}; +((y$1.elementStyles = []), + (y$1.shadowRootOptions = { mode: "open" }), + (y$1[d$2("elementProperties")] = /* @__PURE__ */ new Map()), + (y$1[d$2("finalized")] = /* @__PURE__ */ new Map()), + p$2?.({ ReactiveElement: y$1 }), + (a$1.reactiveElementVersions ??= []).push("2.1.2")); /** -* @license -* Copyright 2017 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ -const t$5 = globalThis, i$7 = (t) => t, s$7 = t$5.trustedTypes, e$11 = s$7 ? s$7.createPolicy("lit-html", { createHTML: (t) => t }) : void 0, h$5 = "$lit$", o$12 = `lit$${Math.random().toFixed(9).slice(2)}$`, n$10 = "?" + o$12, r$9 = `<${n$10}>`, l$3 = document, c$4 = () => l$3.createComment(""), a = (t) => null === t || "object" != typeof t && "function" != typeof t, u$2 = Array.isArray, d$1 = (t) => u$2(t) || "function" == typeof t?.[Symbol.iterator], f$2 = "[ \n\f\r]", v$1 = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g, _ = /-->/g, m$2 = />/g, p$1 = RegExp(`>|${f$2}(?:([^\\s"'>=/]+)(${f$2}*=${f$2}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`, "g"), g = /'/g, $ = /"/g, y = /^(?:script|style|textarea|title)$/i, x = (t) => (i, ...s) => ({ - _$litType$: t, - strings: i, - values: s -}), b = x(1), w = x(2); + * @license + * Copyright 2017 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ +const t$5 = globalThis, + i$7 = (t) => t, + s$7 = t$5.trustedTypes, + e$11 = s$7 ? s$7.createPolicy("lit-html", { createHTML: (t) => t }) : void 0, + h$5 = "$lit$", + o$12 = `lit$${Math.random().toFixed(9).slice(2)}$`, + n$10 = "?" + o$12, + r$9 = `<${n$10}>`, + l$3 = document, + c$4 = () => l$3.createComment(""), + a = (t) => null === t || ("object" != typeof t && "function" != typeof t), + u$2 = Array.isArray, + d$1 = (t) => u$2(t) || "function" == typeof t?.[Symbol.iterator], + f$2 = "[ \n\f\r]", + v$1 = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g, + _ = /-->/g, + m$2 = />/g, + p$1 = RegExp(`>|${f$2}(?:([^\\s"'>=/]+)(${f$2}*=${f$2}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`, "g"), + g = /'/g, + $ = /"/g, + y = /^(?:script|style|textarea|title)$/i, + x = + (t) => + (i, ...s) => ({ + _$litType$: t, + strings: i, + values: s, + }), + b = x(1), + w = x(2); x(3); -const E = Symbol.for("lit-noChange"), A = Symbol.for("lit-nothing"), C = /* @__PURE__ */ new WeakMap(), P = l$3.createTreeWalker(l$3, 129); +const E = Symbol.for("lit-noChange"), + A = Symbol.for("lit-nothing"), + C = /* @__PURE__ */ new WeakMap(), + P = l$3.createTreeWalker(l$3, 129); function V(t, i) { - if (!u$2(t) || !t.hasOwnProperty("raw")) throw Error("invalid template strings array"); - return void 0 !== e$11 ? e$11.createHTML(i) : i; + if (!u$2(t) || !t.hasOwnProperty("raw")) throw Error("invalid template strings array"); + return void 0 !== e$11 ? e$11.createHTML(i) : i; } const N = (t, i) => { - const s = t.length - 1, e = []; - let n, l = 2 === i ? "" : 3 === i ? "" : "", c = v$1; - for (let i = 0; i < s; i++) { - const s = t[i]; - let a, u, d = -1, f = 0; - for (; f < s.length && (c.lastIndex = f, u = c.exec(s), null !== u);) f = c.lastIndex, c === v$1 ? "!--" === u[1] ? c = _ : void 0 !== u[1] ? c = m$2 : void 0 !== u[2] ? (y.test(u[2]) && (n = RegExp("" === u[0] ? (c = n ?? v$1, d = -1) : void 0 === u[1] ? d = -2 : (d = c.lastIndex - u[2].length, a = u[1], c = void 0 === u[3] ? p$1 : "\"" === u[3] ? $ : g) : c === $ || c === g ? c = p$1 : c === _ || c === m$2 ? c = v$1 : (c = p$1, n = void 0); - const x = c === p$1 && t[i + 1].startsWith("/>") ? " " : ""; - l += c === v$1 ? s + r$9 : d >= 0 ? (e.push(a), s.slice(0, d) + h$5 + s.slice(d) + o$12 + x) : s + o$12 + (-2 === d ? i : x); - } - return [V(t, l + (t[s] || "") + (2 === i ? "" : 3 === i ? "" : "")), e]; + const s = t.length - 1, + e = []; + let n, + l = 2 === i ? "" : 3 === i ? "" : "", + c = v$1; + for (let i = 0; i < s; i++) { + const s = t[i]; + let a, + u, + d = -1, + f = 0; + for (; f < s.length && ((c.lastIndex = f), (u = c.exec(s)), null !== u); ) + ((f = c.lastIndex), + c === v$1 + ? "!--" === u[1] + ? (c = _) + : void 0 !== u[1] + ? (c = m$2) + : void 0 !== u[2] + ? (y.test(u[2]) && (n = RegExp("" === u[0] + ? ((c = n ?? v$1), (d = -1)) + : void 0 === u[1] + ? (d = -2) + : ((d = c.lastIndex - u[2].length), + (a = u[1]), + (c = void 0 === u[3] ? p$1 : '"' === u[3] ? $ : g)) + : c === $ || c === g + ? (c = p$1) + : c === _ || c === m$2 + ? (c = v$1) + : ((c = p$1), (n = void 0))); + const x = c === p$1 && t[i + 1].startsWith("/>") ? " " : ""; + l += + c === v$1 + ? s + r$9 + : d >= 0 + ? (e.push(a), s.slice(0, d) + h$5 + s.slice(d) + o$12 + x) + : s + o$12 + (-2 === d ? i : x); + } + return [V(t, l + (t[s] || "") + (2 === i ? "" : 3 === i ? "" : "")), e]; }; var S = class S { - constructor({ strings: t, _$litType$: i }, e) { - let r; - this.parts = []; - let l = 0, a = 0; - const u = t.length - 1, d = this.parts, [f, v] = N(t, i); - if (this.el = S.createElement(f, e), P.currentNode = this.el.content, 2 === i || 3 === i) { - const t = this.el.content.firstChild; - t.replaceWith(...t.childNodes); - } - for (; null !== (r = P.nextNode()) && d.length < u;) { - if (1 === r.nodeType) { - if (r.hasAttributes()) for (const t of r.getAttributeNames()) if (t.endsWith(h$5)) { - const i = v[a++], s = r.getAttribute(t).split(o$12), e = /([.?@])?(.*)/.exec(i); - d.push({ - type: 1, - index: l, - name: e[2], - strings: s, - ctor: "." === e[1] ? I : "?" === e[1] ? L : "@" === e[1] ? z : H - }), r.removeAttribute(t); - } else t.startsWith(o$12) && (d.push({ - type: 6, - index: l - }), r.removeAttribute(t)); - if (y.test(r.tagName)) { - const t = r.textContent.split(o$12), i = t.length - 1; - if (i > 0) { - r.textContent = s$7 ? s$7.emptyScript : ""; - for (let s = 0; s < i; s++) r.append(t[s], c$4()), P.nextNode(), d.push({ - type: 2, - index: ++l - }); - r.append(t[i], c$4()); - } - } - } else if (8 === r.nodeType) if (r.data === n$10) d.push({ - type: 2, - index: l - }); - else { - let t = -1; - for (; -1 !== (t = r.data.indexOf(o$12, t + 1));) d.push({ - type: 7, - index: l - }), t += o$12.length - 1; - } - l++; - } - } - static createElement(t, i) { - const s = l$3.createElement("template"); - return s.innerHTML = t, s; - } + constructor({ strings: t, _$litType$: i }, e) { + let r; + this.parts = []; + let l = 0, + a = 0; + const u = t.length - 1, + d = this.parts, + [f, v] = N(t, i); + if ( + ((this.el = S.createElement(f, e)), (P.currentNode = this.el.content), 2 === i || 3 === i) + ) { + const t = this.el.content.firstChild; + t.replaceWith(...t.childNodes); + } + for (; null !== (r = P.nextNode()) && d.length < u; ) { + if (1 === r.nodeType) { + if (r.hasAttributes()) + for (const t of r.getAttributeNames()) + if (t.endsWith(h$5)) { + const i = v[a++], + s = r.getAttribute(t).split(o$12), + e = /([.?@])?(.*)/.exec(i); + (d.push({ + type: 1, + index: l, + name: e[2], + strings: s, + ctor: "." === e[1] ? I : "?" === e[1] ? L : "@" === e[1] ? z : H, + }), + r.removeAttribute(t)); + } else + t.startsWith(o$12) && + (d.push({ + type: 6, + index: l, + }), + r.removeAttribute(t)); + if (y.test(r.tagName)) { + const t = r.textContent.split(o$12), + i = t.length - 1; + if (i > 0) { + r.textContent = s$7 ? s$7.emptyScript : ""; + for (let s = 0; s < i; s++) + (r.append(t[s], c$4()), + P.nextNode(), + d.push({ + type: 2, + index: ++l, + })); + r.append(t[i], c$4()); + } + } + } else if (8 === r.nodeType) + if (r.data === n$10) + d.push({ + type: 2, + index: l, + }); + else { + let t = -1; + for (; -1 !== (t = r.data.indexOf(o$12, t + 1)); ) + (d.push({ + type: 7, + index: l, + }), + (t += o$12.length - 1)); + } + l++; + } + } + static createElement(t, i) { + const s = l$3.createElement("template"); + return ((s.innerHTML = t), s); + } }; function M$1(t, i, s = t, e) { - if (i === E) return i; - let h = void 0 !== e ? s._$Co?.[e] : s._$Cl; - const o = a(i) ? void 0 : i._$litDirective$; - return h?.constructor !== o && (h?._$AO?.(!1), void 0 === o ? h = void 0 : (h = new o(t), h._$AT(t, s, e)), void 0 !== e ? (s._$Co ??= [])[e] = h : s._$Cl = h), void 0 !== h && (i = M$1(t, h._$AS(t, i.values), h, e)), i; + if (i === E) return i; + let h = void 0 !== e ? s._$Co?.[e] : s._$Cl; + const o = a(i) ? void 0 : i._$litDirective$; + return ( + h?.constructor !== o && + (h?._$AO?.(!1), + void 0 === o ? (h = void 0) : ((h = new o(t)), h._$AT(t, s, e)), + void 0 !== e ? ((s._$Co ??= [])[e] = h) : (s._$Cl = h)), + void 0 !== h && (i = M$1(t, h._$AS(t, i.values), h, e)), + i + ); } var R = class { - constructor(t, i) { - this._$AV = [], this._$AN = void 0, this._$AD = t, this._$AM = i; - } - get parentNode() { - return this._$AM.parentNode; - } - get _$AU() { - return this._$AM._$AU; - } - u(t) { - const { el: { content: i }, parts: s } = this._$AD, e = (t?.creationScope ?? l$3).importNode(i, !0); - P.currentNode = e; - let h = P.nextNode(), o = 0, n = 0, r = s[0]; - for (; void 0 !== r;) { - if (o === r.index) { - let i; - 2 === r.type ? i = new k(h, h.nextSibling, this, t) : 1 === r.type ? i = new r.ctor(h, r.name, r.strings, this, t) : 6 === r.type && (i = new Z(h, this, t)), this._$AV.push(i), r = s[++n]; - } - o !== r?.index && (h = P.nextNode(), o++); - } - return P.currentNode = l$3, e; - } - p(t) { - let i = 0; - for (const s of this._$AV) void 0 !== s && (void 0 !== s.strings ? (s._$AI(t, s, i), i += s.strings.length - 2) : s._$AI(t[i])), i++; - } + constructor(t, i) { + ((this._$AV = []), (this._$AN = void 0), (this._$AD = t), (this._$AM = i)); + } + get parentNode() { + return this._$AM.parentNode; + } + get _$AU() { + return this._$AM._$AU; + } + u(t) { + const { + el: { content: i }, + parts: s, + } = this._$AD, + e = (t?.creationScope ?? l$3).importNode(i, !0); + P.currentNode = e; + let h = P.nextNode(), + o = 0, + n = 0, + r = s[0]; + for (; void 0 !== r; ) { + if (o === r.index) { + let i; + (2 === r.type + ? (i = new k(h, h.nextSibling, this, t)) + : 1 === r.type + ? (i = new r.ctor(h, r.name, r.strings, this, t)) + : 6 === r.type && (i = new Z(h, this, t)), + this._$AV.push(i), + (r = s[++n])); + } + o !== r?.index && ((h = P.nextNode()), o++); + } + return ((P.currentNode = l$3), e); + } + p(t) { + let i = 0; + for (const s of this._$AV) + (void 0 !== s && + (void 0 !== s.strings ? (s._$AI(t, s, i), (i += s.strings.length - 2)) : s._$AI(t[i])), + i++); + } }; var k = class k { - get _$AU() { - return this._$AM?._$AU ?? this._$Cv; - } - constructor(t, i, s, e) { - this.type = 2, this._$AH = A, this._$AN = void 0, this._$AA = t, this._$AB = i, this._$AM = s, this.options = e, this._$Cv = e?.isConnected ?? !0; - } - get parentNode() { - let t = this._$AA.parentNode; - const i = this._$AM; - return void 0 !== i && 11 === t?.nodeType && (t = i.parentNode), t; - } - get startNode() { - return this._$AA; - } - get endNode() { - return this._$AB; - } - _$AI(t, i = this) { - t = M$1(this, t, i), a(t) ? t === A || null == t || "" === t ? (this._$AH !== A && this._$AR(), this._$AH = A) : t !== this._$AH && t !== E && this._(t) : void 0 !== t._$litType$ ? this.$(t) : void 0 !== t.nodeType ? this.T(t) : d$1(t) ? this.k(t) : this._(t); - } - O(t) { - return this._$AA.parentNode.insertBefore(t, this._$AB); - } - T(t) { - this._$AH !== t && (this._$AR(), this._$AH = this.O(t)); - } - _(t) { - this._$AH !== A && a(this._$AH) ? this._$AA.nextSibling.data = t : this.T(l$3.createTextNode(t)), this._$AH = t; - } - $(t) { - const { values: i, _$litType$: s } = t, e = "number" == typeof s ? this._$AC(t) : (void 0 === s.el && (s.el = S.createElement(V(s.h, s.h[0]), this.options)), s); - if (this._$AH?._$AD === e) this._$AH.p(i); - else { - const t = new R(e, this), s = t.u(this.options); - t.p(i), this.T(s), this._$AH = t; - } - } - _$AC(t) { - let i = C.get(t.strings); - return void 0 === i && C.set(t.strings, i = new S(t)), i; - } - k(t) { - u$2(this._$AH) || (this._$AH = [], this._$AR()); - const i = this._$AH; - let s, e = 0; - for (const h of t) e === i.length ? i.push(s = new k(this.O(c$4()), this.O(c$4()), this, this.options)) : s = i[e], s._$AI(h), e++; - e < i.length && (this._$AR(s && s._$AB.nextSibling, e), i.length = e); - } - _$AR(t = this._$AA.nextSibling, s) { - for (this._$AP?.(!1, !0, s); t !== this._$AB;) { - const s = i$7(t).nextSibling; - i$7(t).remove(), t = s; - } - } - setConnected(t) { - void 0 === this._$AM && (this._$Cv = t, this._$AP?.(t)); - } + get _$AU() { + return this._$AM?._$AU ?? this._$Cv; + } + constructor(t, i, s, e) { + ((this.type = 2), + (this._$AH = A), + (this._$AN = void 0), + (this._$AA = t), + (this._$AB = i), + (this._$AM = s), + (this.options = e), + (this._$Cv = e?.isConnected ?? !0)); + } + get parentNode() { + let t = this._$AA.parentNode; + const i = this._$AM; + return (void 0 !== i && 11 === t?.nodeType && (t = i.parentNode), t); + } + get startNode() { + return this._$AA; + } + get endNode() { + return this._$AB; + } + _$AI(t, i = this) { + ((t = M$1(this, t, i)), + a(t) + ? t === A || null == t || "" === t + ? (this._$AH !== A && this._$AR(), (this._$AH = A)) + : t !== this._$AH && t !== E && this._(t) + : void 0 !== t._$litType$ + ? this.$(t) + : void 0 !== t.nodeType + ? this.T(t) + : d$1(t) + ? this.k(t) + : this._(t)); + } + O(t) { + return this._$AA.parentNode.insertBefore(t, this._$AB); + } + T(t) { + this._$AH !== t && (this._$AR(), (this._$AH = this.O(t))); + } + _(t) { + (this._$AH !== A && a(this._$AH) + ? (this._$AA.nextSibling.data = t) + : this.T(l$3.createTextNode(t)), + (this._$AH = t)); + } + $(t) { + const { values: i, _$litType$: s } = t, + e = + "number" == typeof s + ? this._$AC(t) + : (void 0 === s.el && (s.el = S.createElement(V(s.h, s.h[0]), this.options)), s); + if (this._$AH?._$AD === e) this._$AH.p(i); + else { + const t = new R(e, this), + s = t.u(this.options); + (t.p(i), this.T(s), (this._$AH = t)); + } + } + _$AC(t) { + let i = C.get(t.strings); + return (void 0 === i && C.set(t.strings, (i = new S(t))), i); + } + k(t) { + u$2(this._$AH) || ((this._$AH = []), this._$AR()); + const i = this._$AH; + let s, + e = 0; + for (const h of t) + (e === i.length + ? i.push((s = new k(this.O(c$4()), this.O(c$4()), this, this.options))) + : (s = i[e]), + s._$AI(h), + e++); + e < i.length && (this._$AR(s && s._$AB.nextSibling, e), (i.length = e)); + } + _$AR(t = this._$AA.nextSibling, s) { + for (this._$AP?.(!1, !0, s); t !== this._$AB; ) { + const s = i$7(t).nextSibling; + (i$7(t).remove(), (t = s)); + } + } + setConnected(t) { + void 0 === this._$AM && ((this._$Cv = t), this._$AP?.(t)); + } }; var H = class { - get tagName() { - return this.element.tagName; - } - get _$AU() { - return this._$AM._$AU; - } - constructor(t, i, s, e, h) { - this.type = 1, this._$AH = A, this._$AN = void 0, this.element = t, this.name = i, this._$AM = e, this.options = h, s.length > 2 || "" !== s[0] || "" !== s[1] ? (this._$AH = Array(s.length - 1).fill(/* @__PURE__ */ new String()), this.strings = s) : this._$AH = A; - } - _$AI(t, i = this, s, e) { - const h = this.strings; - let o = !1; - if (void 0 === h) t = M$1(this, t, i, 0), o = !a(t) || t !== this._$AH && t !== E, o && (this._$AH = t); - else { - const e = t; - let n, r; - for (t = h[0], n = 0; n < h.length - 1; n++) r = M$1(this, e[s + n], i, n), r === E && (r = this._$AH[n]), o ||= !a(r) || r !== this._$AH[n], r === A ? t = A : t !== A && (t += (r ?? "") + h[n + 1]), this._$AH[n] = r; - } - o && !e && this.j(t); - } - j(t) { - t === A ? this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, t ?? ""); - } + get tagName() { + return this.element.tagName; + } + get _$AU() { + return this._$AM._$AU; + } + constructor(t, i, s, e, h) { + ((this.type = 1), + (this._$AH = A), + (this._$AN = void 0), + (this.element = t), + (this.name = i), + (this._$AM = e), + (this.options = h), + s.length > 2 || "" !== s[0] || "" !== s[1] + ? ((this._$AH = Array(s.length - 1).fill(/* @__PURE__ */ new String())), (this.strings = s)) + : (this._$AH = A)); + } + _$AI(t, i = this, s, e) { + const h = this.strings; + let o = !1; + if (void 0 === h) + ((t = M$1(this, t, i, 0)), (o = !a(t) || (t !== this._$AH && t !== E)), o && (this._$AH = t)); + else { + const e = t; + let n, r; + for (t = h[0], n = 0; n < h.length - 1; n++) + ((r = M$1(this, e[s + n], i, n)), + r === E && (r = this._$AH[n]), + (o ||= !a(r) || r !== this._$AH[n]), + r === A ? (t = A) : t !== A && (t += (r ?? "") + h[n + 1]), + (this._$AH[n] = r)); + } + o && !e && this.j(t); + } + j(t) { + t === A + ? this.element.removeAttribute(this.name) + : this.element.setAttribute(this.name, t ?? ""); + } }; var I = class extends H { - constructor() { - super(...arguments), this.type = 3; - } - j(t) { - this.element[this.name] = t === A ? void 0 : t; - } + constructor() { + (super(...arguments), (this.type = 3)); + } + j(t) { + this.element[this.name] = t === A ? void 0 : t; + } }; var L = class extends H { - constructor() { - super(...arguments), this.type = 4; - } - j(t) { - this.element.toggleAttribute(this.name, !!t && t !== A); - } + constructor() { + (super(...arguments), (this.type = 4)); + } + j(t) { + this.element.toggleAttribute(this.name, !!t && t !== A); + } }; var z = class extends H { - constructor(t, i, s, e, h) { - super(t, i, s, e, h), this.type = 5; - } - _$AI(t, i = this) { - if ((t = M$1(this, t, i, 0) ?? A) === E) return; - const s = this._$AH, e = t === A && s !== A || t.capture !== s.capture || t.once !== s.once || t.passive !== s.passive, h = t !== A && (s === A || e); - e && this.element.removeEventListener(this.name, this, s), h && this.element.addEventListener(this.name, this, t), this._$AH = t; - } - handleEvent(t) { - "function" == typeof this._$AH ? this._$AH.call(this.options?.host ?? this.element, t) : this._$AH.handleEvent(t); - } + constructor(t, i, s, e, h) { + (super(t, i, s, e, h), (this.type = 5)); + } + _$AI(t, i = this) { + if ((t = M$1(this, t, i, 0) ?? A) === E) return; + const s = this._$AH, + e = + (t === A && s !== A) || + t.capture !== s.capture || + t.once !== s.once || + t.passive !== s.passive, + h = t !== A && (s === A || e); + (e && this.element.removeEventListener(this.name, this, s), + h && this.element.addEventListener(this.name, this, t), + (this._$AH = t)); + } + handleEvent(t) { + "function" == typeof this._$AH + ? this._$AH.call(this.options?.host ?? this.element, t) + : this._$AH.handleEvent(t); + } }; var Z = class { - constructor(t, i, s) { - this.element = t, this.type = 6, this._$AN = void 0, this._$AM = i, this.options = s; - } - get _$AU() { - return this._$AM._$AU; - } - _$AI(t) { - M$1(this, t); - } + constructor(t, i, s) { + ((this.element = t), + (this.type = 6), + (this._$AN = void 0), + (this._$AM = i), + (this.options = s)); + } + get _$AU() { + return this._$AM._$AU; + } + _$AI(t) { + M$1(this, t); + } }; const j$1 = { - M: h$5, - P: o$12, - A: n$10, - C: 1, - L: N, - R, - D: d$1, - V: M$1, - I: k, - H, - N: L, - U: z, - B: I, - F: Z -}, B = t$5.litHtmlPolyfillSupport; -B?.(S, k), (t$5.litHtmlVersions ??= []).push("3.3.2"); + M: h$5, + P: o$12, + A: n$10, + C: 1, + L: N, + R, + D: d$1, + V: M$1, + I: k, + H, + N: L, + U: z, + B: I, + F: Z, + }, + B = t$5.litHtmlPolyfillSupport; +(B?.(S, k), (t$5.litHtmlVersions ??= []).push("3.3.2")); const D = (t, i, s) => { - const e = s?.renderBefore ?? i; - let h = e._$litPart$; - if (void 0 === h) { - const t = s?.renderBefore ?? null; - e._$litPart$ = h = new k(i.insertBefore(c$4(), t), t, void 0, s ?? {}); - } - return h._$AI(t), h; + const e = s?.renderBefore ?? i; + let h = e._$litPart$; + if (void 0 === h) { + const t = s?.renderBefore ?? null; + e._$litPart$ = h = new k(i.insertBefore(c$4(), t), t, void 0, s ?? {}); + } + return (h._$AI(t), h); }; /** -* @license -* Copyright 2017 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ const s$6 = globalThis; + * @license + * Copyright 2017 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ const s$6 = globalThis; var i$6 = class extends y$1 { - constructor() { - super(...arguments), this.renderOptions = { host: this }, this._$Do = void 0; - } - createRenderRoot() { - const t = super.createRenderRoot(); - return this.renderOptions.renderBefore ??= t.firstChild, t; - } - update(t) { - const r = this.render(); - this.hasUpdated || (this.renderOptions.isConnected = this.isConnected), super.update(t), this._$Do = D(r, this.renderRoot, this.renderOptions); - } - connectedCallback() { - super.connectedCallback(), this._$Do?.setConnected(!0); - } - disconnectedCallback() { - super.disconnectedCallback(), this._$Do?.setConnected(!1); - } - render() { - return E; - } -}; -i$6._$litElement$ = !0, i$6["finalized"] = !0, s$6.litElementHydrateSupport?.({ LitElement: i$6 }); + constructor() { + (super(...arguments), (this.renderOptions = { host: this }), (this._$Do = void 0)); + } + createRenderRoot() { + const t = super.createRenderRoot(); + return ((this.renderOptions.renderBefore ??= t.firstChild), t); + } + update(t) { + const r = this.render(); + (this.hasUpdated || (this.renderOptions.isConnected = this.isConnected), + super.update(t), + (this._$Do = D(r, this.renderRoot, this.renderOptions))); + } + connectedCallback() { + (super.connectedCallback(), this._$Do?.setConnected(!0)); + } + disconnectedCallback() { + (super.disconnectedCallback(), this._$Do?.setConnected(!1)); + } + render() { + return E; + } +}; +((i$6._$litElement$ = !0), + (i$6["finalized"] = !0), + s$6.litElementHydrateSupport?.({ LitElement: i$6 })); const o$11 = s$6.litElementPolyfillSupport; o$11?.({ LitElement: i$6 }); (s$6.litElementVersions ??= []).push("4.2.2"); /** -* @license -* Copyright 2017 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ + * @license + * Copyright 2017 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ const t$4 = { - ATTRIBUTE: 1, - CHILD: 2, - PROPERTY: 3, - BOOLEAN_ATTRIBUTE: 4, - EVENT: 5, - ELEMENT: 6 -}, e$10 = (t) => (...e) => ({ - _$litDirective$: t, - values: e -}); + ATTRIBUTE: 1, + CHILD: 2, + PROPERTY: 3, + BOOLEAN_ATTRIBUTE: 4, + EVENT: 5, + ELEMENT: 6, + }, + e$10 = + (t) => + (...e) => ({ + _$litDirective$: t, + values: e, + }); var i$5 = class { - constructor(t) {} - get _$AU() { - return this._$AM._$AU; - } - _$AT(t, e, i) { - this._$Ct = t, this._$AM = e, this._$Ci = i; - } - _$AS(t, e) { - return this.update(t, e); - } - update(t, e) { - return this.render(...e); - } + constructor(t) {} + get _$AU() { + return this._$AM._$AU; + } + _$AT(t, e, i) { + ((this._$Ct = t), (this._$AM = e), (this._$Ci = i)); + } + _$AS(t, e) { + return this.update(t, e); + } + update(t, e) { + return this.render(...e); + } }; /** -* @license -* Copyright 2020 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ const { I: t$3 } = j$1, i$4 = (o) => o, r$8 = (o) => void 0 === o.strings, s$5 = () => document.createComment(""), v = (o, n, e) => { - const l = o._$AA.parentNode, d = void 0 === n ? o._$AB : n._$AA; - if (void 0 === e) e = new t$3(l.insertBefore(s$5(), d), l.insertBefore(s$5(), d), o, o.options); - else { - const t = e._$AB.nextSibling, n = e._$AM, c = n !== o; - if (c) { - let t; - e._$AQ?.(o), e._$AM = o, void 0 !== e._$AP && (t = o._$AU) !== n._$AU && e._$AP(t); - } - if (t !== d || c) { - let o = e._$AA; - for (; o !== t;) { - const t = i$4(o).nextSibling; - i$4(l).insertBefore(o, d), o = t; - } - } - } - return e; -}, u$1 = (o, t, i = o) => (o._$AI(t, i), o), m$1 = {}, p = (o, t = m$1) => o._$AH = t, M = (o) => o._$AH, h$4 = (o) => { - o._$AR(), o._$AA.remove(); -}; + * @license + * Copyright 2020 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ const { I: t$3 } = j$1, + i$4 = (o) => o, + r$8 = (o) => void 0 === o.strings, + s$5 = () => document.createComment(""), + v = (o, n, e) => { + const l = o._$AA.parentNode, + d = void 0 === n ? o._$AB : n._$AA; + if (void 0 === e) e = new t$3(l.insertBefore(s$5(), d), l.insertBefore(s$5(), d), o, o.options); + else { + const t = e._$AB.nextSibling, + n = e._$AM, + c = n !== o; + if (c) { + let t; + (e._$AQ?.(o), (e._$AM = o), void 0 !== e._$AP && (t = o._$AU) !== n._$AU && e._$AP(t)); + } + if (t !== d || c) { + let o = e._$AA; + for (; o !== t; ) { + const t = i$4(o).nextSibling; + (i$4(l).insertBefore(o, d), (o = t)); + } + } + } + return e; + }, + u$1 = (o, t, i = o) => (o._$AI(t, i), o), + m$1 = {}, + p = (o, t = m$1) => (o._$AH = t), + M = (o) => o._$AH, + h$4 = (o) => { + (o._$AR(), o._$AA.remove()); + }; /** -* @license -* Copyright 2017 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ + * @license + * Copyright 2017 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ const u = (e, s, t) => { - const r = /* @__PURE__ */ new Map(); - for (let l = s; l <= t; l++) r.set(e[l], l); - return r; -}, c$2 = e$10(class extends i$5 { - constructor(e) { - if (super(e), e.type !== t$4.CHILD) throw Error("repeat() can only be used in text expressions"); - } - dt(e, s, t) { - let r; - void 0 === t ? t = s : void 0 !== s && (r = s); - const l = [], o = []; - let i = 0; - for (const s of e) l[i] = r ? r(s, i) : i, o[i] = t(s, i), i++; - return { - values: o, - keys: l - }; - } - render(e, s, t) { - return this.dt(e, s, t).values; - } - update(s, [t, r, c]) { - const d = M(s), { values: p$3, keys: a } = this.dt(t, r, c); - if (!Array.isArray(d)) return this.ut = a, p$3; - const h = this.ut ??= [], v$2 = []; - let m, y, x = 0, j = d.length - 1, k = 0, w = p$3.length - 1; - for (; x <= j && k <= w;) if (null === d[x]) x++; - else if (null === d[j]) j--; - else if (h[x] === a[k]) v$2[k] = u$1(d[x], p$3[k]), x++, k++; - else if (h[j] === a[w]) v$2[w] = u$1(d[j], p$3[w]), j--, w--; - else if (h[x] === a[w]) v$2[w] = u$1(d[x], p$3[w]), v(s, v$2[w + 1], d[x]), x++, w--; - else if (h[j] === a[k]) v$2[k] = u$1(d[j], p$3[k]), v(s, d[x], d[j]), j--, k++; - else if (void 0 === m && (m = u(a, k, w), y = u(h, x, j)), m.has(h[x])) if (m.has(h[j])) { - const e = y.get(a[k]), t = void 0 !== e ? d[e] : null; - if (null === t) { - const e = v(s, d[x]); - u$1(e, p$3[k]), v$2[k] = e; - } else v$2[k] = u$1(t, p$3[k]), v(s, d[x], t), d[e] = null; - k++; - } else h$4(d[j]), j--; - else h$4(d[x]), x++; - for (; k <= w;) { - const e = v(s, v$2[w + 1]); - u$1(e, p$3[k]), v$2[k++] = e; - } - for (; x <= j;) { - const e = d[x++]; - null !== e && h$4(e); - } - return this.ut = a, p(s, v$2), E; - } -}); + const r = /* @__PURE__ */ new Map(); + for (let l = s; l <= t; l++) r.set(e[l], l); + return r; + }, + c$2 = e$10( + class extends i$5 { + constructor(e) { + if ((super(e), e.type !== t$4.CHILD)) + throw Error("repeat() can only be used in text expressions"); + } + dt(e, s, t) { + let r; + void 0 === t ? (t = s) : void 0 !== s && (r = s); + const l = [], + o = []; + let i = 0; + for (const s of e) ((l[i] = r ? r(s, i) : i), (o[i] = t(s, i)), i++); + return { + values: o, + keys: l, + }; + } + render(e, s, t) { + return this.dt(e, s, t).values; + } + update(s, [t, r, c]) { + const d = M(s), + { values: p$3, keys: a } = this.dt(t, r, c); + if (!Array.isArray(d)) return ((this.ut = a), p$3); + const h = (this.ut ??= []), + v$2 = []; + let m, + y, + x = 0, + j = d.length - 1, + k = 0, + w = p$3.length - 1; + for (; x <= j && k <= w; ) + if (null === d[x]) x++; + else if (null === d[j]) j--; + else if (h[x] === a[k]) ((v$2[k] = u$1(d[x], p$3[k])), x++, k++); + else if (h[j] === a[w]) ((v$2[w] = u$1(d[j], p$3[w])), j--, w--); + else if (h[x] === a[w]) ((v$2[w] = u$1(d[x], p$3[w])), v(s, v$2[w + 1], d[x]), x++, w--); + else if (h[j] === a[k]) ((v$2[k] = u$1(d[j], p$3[k])), v(s, d[x], d[j]), j--, k++); + else if ((void 0 === m && ((m = u(a, k, w)), (y = u(h, x, j))), m.has(h[x]))) + if (m.has(h[j])) { + const e = y.get(a[k]), + t = void 0 !== e ? d[e] : null; + if (null === t) { + const e = v(s, d[x]); + (u$1(e, p$3[k]), (v$2[k] = e)); + } else ((v$2[k] = u$1(t, p$3[k])), v(s, d[x], t), (d[e] = null)); + k++; + } else (h$4(d[j]), j--); + else (h$4(d[x]), x++); + for (; k <= w; ) { + const e = v(s, v$2[w + 1]); + (u$1(e, p$3[k]), (v$2[k++] = e)); + } + for (; x <= j; ) { + const e = d[x++]; + null !== e && h$4(e); + } + return ((this.ut = a), p(s, v$2), E); + } + }, + ); /** -* @license -* Copyright 2021 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ + * @license + * Copyright 2021 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ var s$4 = class extends Event { - constructor(s, t, e, o) { - super("context-request", { - bubbles: !0, - composed: !0 - }), this.context = s, this.contextTarget = t, this.callback = e, this.subscribe = o ?? !1; - } + constructor(s, t, e, o) { + (super("context-request", { + bubbles: !0, + composed: !0, + }), + (this.context = s), + (this.contextTarget = t), + (this.callback = e), + (this.subscribe = o ?? !1)); + } }; /** -* @license -* Copyright 2021 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ + * @license + * Copyright 2021 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ function n$7(n) { - return n; + return n; } /** -* @license -* Copyright 2021 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ var s$3 = class { - constructor(t, s, i, h) { - if (this.subscribe = !1, this.provided = !1, this.value = void 0, this.t = (t, s) => { - this.unsubscribe && (this.unsubscribe !== s && (this.provided = !1, this.unsubscribe()), this.subscribe || this.unsubscribe()), this.value = t, this.host.requestUpdate(), this.provided && !this.subscribe || (this.provided = !0, this.callback && this.callback(t, s)), this.unsubscribe = s; - }, this.host = t, void 0 !== s.context) { - const t = s; - this.context = t.context, this.callback = t.callback, this.subscribe = t.subscribe ?? !1; - } else this.context = s, this.callback = i, this.subscribe = h ?? !1; - this.host.addController(this); - } - hostConnected() { - this.dispatchRequest(); - } - hostDisconnected() { - this.unsubscribe && (this.unsubscribe(), this.unsubscribe = void 0); - } - dispatchRequest() { - this.host.dispatchEvent(new s$4(this.context, this.host, this.t, this.subscribe)); - } + * @license + * Copyright 2021 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ var s$3 = class { + constructor(t, s, i, h) { + if ( + ((this.subscribe = !1), + (this.provided = !1), + (this.value = void 0), + (this.t = (t, s) => { + (this.unsubscribe && + (this.unsubscribe !== s && ((this.provided = !1), this.unsubscribe()), + this.subscribe || this.unsubscribe()), + (this.value = t), + this.host.requestUpdate(), + (this.provided && !this.subscribe) || + ((this.provided = !0), this.callback && this.callback(t, s)), + (this.unsubscribe = s)); + }), + (this.host = t), + void 0 !== s.context) + ) { + const t = s; + ((this.context = t.context), + (this.callback = t.callback), + (this.subscribe = t.subscribe ?? !1)); + } else ((this.context = s), (this.callback = i), (this.subscribe = h ?? !1)); + this.host.addController(this); + } + hostConnected() { + this.dispatchRequest(); + } + hostDisconnected() { + this.unsubscribe && (this.unsubscribe(), (this.unsubscribe = void 0)); + } + dispatchRequest() { + this.host.dispatchEvent(new s$4(this.context, this.host, this.t, this.subscribe)); + } }; /** -* @license -* Copyright 2021 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ + * @license + * Copyright 2021 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ var s$2 = class { - get value() { - return this.o; - } - set value(s) { - this.setValue(s); - } - setValue(s, t = !1) { - const i = t || !Object.is(s, this.o); - this.o = s, i && this.updateObservers(); - } - constructor(s) { - this.subscriptions = /* @__PURE__ */ new Map(), this.updateObservers = () => { - for (const [s, { disposer: t }] of this.subscriptions) s(this.o, t); - }, void 0 !== s && (this.value = s); - } - addCallback(s, t, i) { - if (!i) return void s(this.value); - this.subscriptions.has(s) || this.subscriptions.set(s, { - disposer: () => { - this.subscriptions.delete(s); - }, - consumerHost: t - }); - const { disposer: h } = this.subscriptions.get(s); - s(this.value, h); - } - clearCallbacks() { - this.subscriptions.clear(); - } + get value() { + return this.o; + } + set value(s) { + this.setValue(s); + } + setValue(s, t = !1) { + const i = t || !Object.is(s, this.o); + ((this.o = s), i && this.updateObservers()); + } + constructor(s) { + ((this.subscriptions = /* @__PURE__ */ new Map()), + (this.updateObservers = () => { + for (const [s, { disposer: t }] of this.subscriptions) s(this.o, t); + }), + void 0 !== s && (this.value = s)); + } + addCallback(s, t, i) { + if (!i) return void s(this.value); + this.subscriptions.has(s) || + this.subscriptions.set(s, { + disposer: () => { + this.subscriptions.delete(s); + }, + consumerHost: t, + }); + const { disposer: h } = this.subscriptions.get(s); + s(this.value, h); + } + clearCallbacks() { + this.subscriptions.clear(); + } }; /** -* @license -* Copyright 2021 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ var e$8 = class extends Event { - constructor(t, s) { - super("context-provider", { - bubbles: !0, - composed: !0 - }), this.context = t, this.contextTarget = s; - } + * @license + * Copyright 2021 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ var e$8 = class extends Event { + constructor(t, s) { + (super("context-provider", { + bubbles: !0, + composed: !0, + }), + (this.context = t), + (this.contextTarget = s)); + } }; var i$3 = class extends s$2 { - constructor(s, e, i) { - super(void 0 !== e.context ? e.initialValue : i), this.onContextRequest = (t) => { - if (t.context !== this.context) return; - const s = t.contextTarget ?? t.composedPath()[0]; - s !== this.host && (t.stopPropagation(), this.addCallback(t.callback, s, t.subscribe)); - }, this.onProviderRequest = (s) => { - if (s.context !== this.context) return; - if ((s.contextTarget ?? s.composedPath()[0]) === this.host) return; - const e = /* @__PURE__ */ new Set(); - for (const [s, { consumerHost: i }] of this.subscriptions) e.has(s) || (e.add(s), i.dispatchEvent(new s$4(this.context, i, s, !0))); - s.stopPropagation(); - }, this.host = s, void 0 !== e.context ? this.context = e.context : this.context = e, this.attachListeners(), this.host.addController?.(this); - } - attachListeners() { - this.host.addEventListener("context-request", this.onContextRequest), this.host.addEventListener("context-provider", this.onProviderRequest); - } - hostConnected() { - this.host.dispatchEvent(new e$8(this.context, this.host)); - } + constructor(s, e, i) { + (super(void 0 !== e.context ? e.initialValue : i), + (this.onContextRequest = (t) => { + if (t.context !== this.context) return; + const s = t.contextTarget ?? t.composedPath()[0]; + s !== this.host && (t.stopPropagation(), this.addCallback(t.callback, s, t.subscribe)); + }), + (this.onProviderRequest = (s) => { + if (s.context !== this.context) return; + if ((s.contextTarget ?? s.composedPath()[0]) === this.host) return; + const e = /* @__PURE__ */ new Set(); + for (const [s, { consumerHost: i }] of this.subscriptions) + e.has(s) || (e.add(s), i.dispatchEvent(new s$4(this.context, i, s, !0))); + s.stopPropagation(); + }), + (this.host = s), + void 0 !== e.context ? (this.context = e.context) : (this.context = e), + this.attachListeners(), + this.host.addController?.(this)); + } + attachListeners() { + (this.host.addEventListener("context-request", this.onContextRequest), + this.host.addEventListener("context-provider", this.onProviderRequest)); + } + hostConnected() { + this.host.dispatchEvent(new e$8(this.context, this.host)); + } }; /** -* @license -* Copyright 2022 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ function c$1({ context: c, subscribe: e }) { - return (o, n) => { - "object" == typeof n ? n.addInitializer((function() { - new s$3(this, { - context: c, - callback: (t) => { - o.set.call(this, t); - }, - subscribe: e - }); - })) : o.constructor.addInitializer(((o) => { - new s$3(o, { - context: c, - callback: (t) => { - o[n] = t; - }, - subscribe: e - }); - })); - }; + * @license + * Copyright 2022 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ function c$1({ context: c, subscribe: e }) { + return (o, n) => { + "object" == typeof n + ? n.addInitializer(function () { + new s$3(this, { + context: c, + callback: (t) => { + o.set.call(this, t); + }, + subscribe: e, + }); + }) + : o.constructor.addInitializer((o) => { + new s$3(o, { + context: c, + callback: (t) => { + o[n] = t; + }, + subscribe: e, + }); + }); + }; } const eventInit = { - bubbles: true, - cancelable: true, - composed: true + bubbles: true, + cancelable: true, + composed: true, }; var StateEvent = class StateEvent extends CustomEvent { - static { - this.eventName = "a2uiaction"; - } - constructor(payload) { - super(StateEvent.eventName, { - detail: payload, - ...eventInit - }); - this.payload = payload; - } + static { + this.eventName = "a2uiaction"; + } + constructor(payload) { + super(StateEvent.eventName, { + detail: payload, + ...eventInit, + }); + this.payload = payload; + } }; const opacityBehavior = ` &:not([disabled]) { @@ -857,12 +1213,15 @@ const opacityBehavior = ` } }`; const behavior = ` - ${new Array(21).fill(0).map((_, idx) => { - return `.behavior-ho-${idx * 5} { + ${new Array(21) + .fill(0) + .map((_, idx) => { + return `.behavior-ho-${idx * 5} { --opacity: ${idx / 20}; ${opacityBehavior} }`; -}).join("\n")} + }) + .join("\n")} .behavior-o-s { overflow: scroll; @@ -881,8 +1240,10 @@ const behavior = ` } `; const border = ` - ${new Array(25).fill(0).map((_, idx) => { - return ` + ${new Array(25) + .fill(0) + .map((_, idx) => { + return ` .border-bw-${idx} { border-width: ${idx}px; } .border-btw-${idx} { border-top-width: ${idx}px; } .border-bbw-${idx} { border-bottom-width: ${idx}px; } @@ -891,7 +1252,8 @@ const border = ` .border-ow-${idx} { outline-width: ${idx}px; } .border-br-${idx} { border-radius: ${idx * 4}px; overflow: hidden;}`; -}).join("\n")} + }) + .join("\n")} .border-br-50pc { border-radius: 50%; @@ -901,98 +1263,92 @@ const border = ` border-style: solid; } `; -const shades = [ - 0, - 5, - 10, - 15, - 20, - 25, - 30, - 35, - 40, - 50, - 60, - 70, - 80, - 90, - 95, - 98, - 99, - 100 -]; +const shades = [0, 5, 10, 15, 20, 25, 30, 35, 40, 50, 60, 70, 80, 90, 95, 98, 99, 100]; function merge(...classes) { - const styles = {}; - for (const clazz of classes) for (const [key, val] of Object.entries(clazz)) { - const prefix = key.split("-").with(-1, "").join("-"); - const existingKeys = Object.keys(styles).filter((key) => key.startsWith(prefix)); - for (const existingKey of existingKeys) delete styles[existingKey]; - styles[key] = val; - } - return styles; + const styles = {}; + for (const clazz of classes) + for (const [key, val] of Object.entries(clazz)) { + const prefix = key.split("-").with(-1, "").join("-"); + const existingKeys = Object.keys(styles).filter((key) => key.startsWith(prefix)); + for (const existingKey of existingKeys) delete styles[existingKey]; + styles[key] = val; + } + return styles; } function appendToAll(target, exclusions, ...classes) { - const updatedTarget = structuredClone(target); - for (const clazz of classes) for (const key of Object.keys(clazz)) { - const prefix = key.split("-").with(-1, "").join("-"); - for (const [tagName, classesToAdd] of Object.entries(updatedTarget)) { - if (exclusions.includes(tagName)) continue; - let found = false; - for (let t = 0; t < classesToAdd.length; t++) if (classesToAdd[t].startsWith(prefix)) { - found = true; - classesToAdd[t] = key; - } - if (!found) classesToAdd.push(key); - } - } - return updatedTarget; + const updatedTarget = structuredClone(target); + for (const clazz of classes) + for (const key of Object.keys(clazz)) { + const prefix = key.split("-").with(-1, "").join("-"); + for (const [tagName, classesToAdd] of Object.entries(updatedTarget)) { + if (exclusions.includes(tagName)) continue; + let found = false; + for (let t = 0; t < classesToAdd.length; t++) + if (classesToAdd[t].startsWith(prefix)) { + found = true; + classesToAdd[t] = key; + } + if (!found) classesToAdd.push(key); + } + } + return updatedTarget; } function toProp(key) { - if (key.startsWith("nv")) return `--nv-${key.slice(2)}`; - return `--${key[0]}-${key.slice(1)}`; + if (key.startsWith("nv")) return `--nv-${key.slice(2)}`; + return `--${key[0]}-${key.slice(1)}`; } const color = (src) => ` - ${src.map((key) => { - const inverseKey = getInverseKey(key); - return `.color-bc-${key} { border-color: light-dark(var(${toProp(key)}), var(${toProp(inverseKey)})); }`; -}).join("\n")} - - ${src.map((key) => { - const inverseKey = getInverseKey(key); - const vals = [`.color-bgc-${key} { background-color: light-dark(var(${toProp(key)}), var(${toProp(inverseKey)})); }`, `.color-bbgc-${key}::backdrop { background-color: light-dark(var(${toProp(key)}), var(${toProp(inverseKey)})); }`]; - for (let o = .1; o < 1; o += .1) vals.push(`.color-bbgc-${key}_${(o * 100).toFixed(0)}::backdrop { + ${src + .map((key) => { + const inverseKey = getInverseKey(key); + return `.color-bc-${key} { border-color: light-dark(var(${toProp(key)}), var(${toProp(inverseKey)})); }`; + }) + .join("\n")} + + ${src + .map((key) => { + const inverseKey = getInverseKey(key); + const vals = [ + `.color-bgc-${key} { background-color: light-dark(var(${toProp(key)}), var(${toProp(inverseKey)})); }`, + `.color-bbgc-${key}::backdrop { background-color: light-dark(var(${toProp(key)}), var(${toProp(inverseKey)})); }`, + ]; + for (let o = 0.1; o < 1; o += 0.1) + vals.push(`.color-bbgc-${key}_${(o * 100).toFixed(0)}::backdrop { background-color: light-dark(oklch(from var(${toProp(key)}) l c h / calc(alpha * ${o.toFixed(1)})), oklch(from var(${toProp(inverseKey)}) l c h / calc(alpha * ${o.toFixed(1)})) ); } `); - return vals.join("\n"); -}).join("\n")} + return vals.join("\n"); + }) + .join("\n")} - ${src.map((key) => { - const inverseKey = getInverseKey(key); - return `.color-c-${key} { color: light-dark(var(${toProp(key)}), var(${toProp(inverseKey)})); }`; -}).join("\n")} + ${src + .map((key) => { + const inverseKey = getInverseKey(key); + return `.color-c-${key} { color: light-dark(var(${toProp(key)}), var(${toProp(inverseKey)})); }`; + }) + .join("\n")} `; const getInverseKey = (key) => { - const match = key.match(/^([a-z]+)(\d+)$/); - if (!match) return key; - const [, prefix, shadeStr] = match; - const target = 100 - parseInt(shadeStr, 10); - return `${prefix}${shades.reduce((prev, curr) => Math.abs(curr - target) < Math.abs(prev - target) ? curr : prev)}`; + const match = key.match(/^([a-z]+)(\d+)$/); + if (!match) return key; + const [, prefix, shadeStr] = match; + const target = 100 - parseInt(shadeStr, 10); + return `${prefix}${shades.reduce((prev, curr) => (Math.abs(curr - target) < Math.abs(prev - target) ? curr : prev))}`; }; const keyFactory = (prefix) => { - return shades.map((v) => `${prefix}${v}`); + return shades.map((v) => `${prefix}${v}`); }; const structuralStyles$1 = [ - behavior, - border, - [ - color(keyFactory("p")), - color(keyFactory("s")), - color(keyFactory("t")), - color(keyFactory("n")), - color(keyFactory("nv")), - color(keyFactory("e")), - ` + behavior, + border, + [ + color(keyFactory("p")), + color(keyFactory("s")), + color(keyFactory("t")), + color(keyFactory("n")), + color(keyFactory("nv")), + color(keyFactory("e")), + ` .color-bgc-transparent { background-color: transparent; } @@ -1000,9 +1356,9 @@ const structuralStyles$1 = [ :host { color-scheme: var(--color-scheme); } + `, + ], ` - ], - ` .g-icon { font-family: "Material Symbols Outlined", "Google Symbols"; font-weight: normal; @@ -1037,17 +1393,22 @@ const structuralStyles$1 = [ } } `, - ` + ` :host { - ${new Array(16).fill(0).map((_, idx) => { - return `--g-${idx + 1}: ${(idx + 1) * 4}px;`; - }).join("\n")} + ${new Array(16) + .fill(0) + .map((_, idx) => { + return `--g-${idx + 1}: ${(idx + 1) * 4}px;`; + }) + .join("\n")} } - ${new Array(49).fill(0).map((_, index) => { - const idx = index - 24; - const lbl = idx < 0 ? `n${Math.abs(idx)}` : idx.toString(); - return ` + ${new Array(49) + .fill(0) + .map((_, index) => { + const idx = index - 24; + const lbl = idx < 0 ? `n${Math.abs(idx)}` : idx.toString(); + return ` .layout-p-${lbl} { --padding: ${idx * 4}px; padding: var(--padding); } .layout-pt-${lbl} { padding-top: ${idx * 4}px; } .layout-pr-${lbl} { padding-right: ${idx * 4}px; } @@ -1064,17 +1425,24 @@ const structuralStyles$1 = [ .layout-r-${lbl} { right: ${idx * 4}px; } .layout-b-${lbl} { bottom: ${idx * 4}px; } .layout-l-${lbl} { left: ${idx * 4}px; }`; - }).join("\n")} + }) + .join("\n")} - ${new Array(25).fill(0).map((_, idx) => { - return ` + ${new Array(25) + .fill(0) + .map((_, idx) => { + return ` .layout-g-${idx} { gap: ${idx * 4}px; }`; - }).join("\n")} + }) + .join("\n")} - ${new Array(8).fill(0).map((_, idx) => { - return ` + ${new Array(8) + .fill(0) + .map((_, idx) => { + return ` .layout-grd-col${idx + 1} { grid-template-columns: ${"1fr ".repeat(idx + 1).trim()}; }`; - }).join("\n")} + }) + .join("\n")} .layout-pos-a { position: absolute; @@ -1184,25 +1552,37 @@ const structuralStyles$1 = [ /** Widths **/ - ${new Array(10).fill(0).map((_, idx) => { - const weight = (idx + 1) * 10; - return `.layout-w-${weight} { width: ${weight}%; max-width: ${weight}%; }`; - }).join("\n")} + ${new Array(10) + .fill(0) + .map((_, idx) => { + const weight = (idx + 1) * 10; + return `.layout-w-${weight} { width: ${weight}%; max-width: ${weight}%; }`; + }) + .join("\n")} - ${new Array(16).fill(0).map((_, idx) => { - return `.layout-wp-${idx} { width: ${idx * 4}px; }`; - }).join("\n")} + ${new Array(16) + .fill(0) + .map((_, idx) => { + return `.layout-wp-${idx} { width: ${idx * 4}px; }`; + }) + .join("\n")} /** Heights **/ - ${new Array(10).fill(0).map((_, idx) => { - const height = (idx + 1) * 10; - return `.layout-h-${height} { height: ${height}%; }`; - }).join("\n")} + ${new Array(10) + .fill(0) + .map((_, idx) => { + const height = (idx + 1) * 10; + return `.layout-h-${height} { height: ${height}%; }`; + }) + .join("\n")} - ${new Array(16).fill(0).map((_, idx) => { - return `.layout-hp-${idx} { height: ${idx * 4}px; }`; - }).join("\n")} + ${new Array(16) + .fill(0) + .map((_, idx) => { + return `.layout-hp-${idx} { height: ${idx * 4}px; }`; + }) + .join("\n")} .layout-el-cv { & img, @@ -1224,12 +1604,15 @@ const structuralStyles$1 = [ height: calc(100% + var(--padding) * 2); } `, - ` - ${new Array(21).fill(0).map((_, idx) => { - return `.opacity-el-${idx * 5} { opacity: ${idx / 20}; }`; - }).join("\n")} + ` + ${new Array(21) + .fill(0) + .map((_, idx) => { + return `.opacity-el-${idx * 5} { opacity: ${idx / 20}; }`; + }) + .join("\n")} `, - ` + ` :host { --default-font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; --default-font-family-mono: "Courier New", Courier, monospace; @@ -1361,2029 +1744,2448 @@ const structuralStyles$1 = [ /** Weights **/ - ${new Array(9).fill(0).map((_, idx) => { - const weight = (idx + 1) * 100; - return `.typography-w-${weight} { font-weight: ${weight}; }`; - }).join("\n")} -` -].flat(Infinity).join("\n"); + ${new Array(9) + .fill(0) + .map((_, idx) => { + const weight = (idx + 1) * 100; + return `.typography-w-${weight} { font-weight: ${weight}; }`; + }) + .join("\n")} +`, +] + .flat(Infinity) + .join("\n"); var guards_exports = /* @__PURE__ */ __exportAll({ - isComponentArrayReference: () => isComponentArrayReference, - isObject: () => isObject$1, - isPath: () => isPath, - isResolvedAudioPlayer: () => isResolvedAudioPlayer, - isResolvedButton: () => isResolvedButton, - isResolvedCard: () => isResolvedCard, - isResolvedCheckbox: () => isResolvedCheckbox, - isResolvedColumn: () => isResolvedColumn, - isResolvedDateTimeInput: () => isResolvedDateTimeInput, - isResolvedDivider: () => isResolvedDivider, - isResolvedIcon: () => isResolvedIcon, - isResolvedImage: () => isResolvedImage, - isResolvedList: () => isResolvedList, - isResolvedModal: () => isResolvedModal, - isResolvedMultipleChoice: () => isResolvedMultipleChoice, - isResolvedRow: () => isResolvedRow, - isResolvedSlider: () => isResolvedSlider, - isResolvedTabs: () => isResolvedTabs, - isResolvedText: () => isResolvedText, - isResolvedTextField: () => isResolvedTextField, - isResolvedVideo: () => isResolvedVideo, - isValueMap: () => isValueMap + isComponentArrayReference: () => isComponentArrayReference, + isObject: () => isObject$1, + isPath: () => isPath, + isResolvedAudioPlayer: () => isResolvedAudioPlayer, + isResolvedButton: () => isResolvedButton, + isResolvedCard: () => isResolvedCard, + isResolvedCheckbox: () => isResolvedCheckbox, + isResolvedColumn: () => isResolvedColumn, + isResolvedDateTimeInput: () => isResolvedDateTimeInput, + isResolvedDivider: () => isResolvedDivider, + isResolvedIcon: () => isResolvedIcon, + isResolvedImage: () => isResolvedImage, + isResolvedList: () => isResolvedList, + isResolvedModal: () => isResolvedModal, + isResolvedMultipleChoice: () => isResolvedMultipleChoice, + isResolvedRow: () => isResolvedRow, + isResolvedSlider: () => isResolvedSlider, + isResolvedTabs: () => isResolvedTabs, + isResolvedText: () => isResolvedText, + isResolvedTextField: () => isResolvedTextField, + isResolvedVideo: () => isResolvedVideo, + isValueMap: () => isValueMap, }); function isValueMap(value) { - return isObject$1(value) && "key" in value; + return isObject$1(value) && "key" in value; } function isPath(key, value) { - return key === "path" && typeof value === "string"; + return key === "path" && typeof value === "string"; } function isObject$1(value) { - return typeof value === "object" && value !== null && !Array.isArray(value); + return typeof value === "object" && value !== null && !Array.isArray(value); } function isComponentArrayReference(value) { - if (!isObject$1(value)) return false; - return "explicitList" in value || "template" in value; + if (!isObject$1(value)) return false; + return "explicitList" in value || "template" in value; } function isStringValue(value) { - return isObject$1(value) && ("path" in value || "literal" in value && typeof value.literal === "string" || "literalString" in value); + return ( + isObject$1(value) && + ("path" in value || + ("literal" in value && typeof value.literal === "string") || + "literalString" in value) + ); } function isNumberValue(value) { - return isObject$1(value) && ("path" in value || "literal" in value && typeof value.literal === "number" || "literalNumber" in value); + return ( + isObject$1(value) && + ("path" in value || + ("literal" in value && typeof value.literal === "number") || + "literalNumber" in value) + ); } function isBooleanValue(value) { - return isObject$1(value) && ("path" in value || "literal" in value && typeof value.literal === "boolean" || "literalBoolean" in value); + return ( + isObject$1(value) && + ("path" in value || + ("literal" in value && typeof value.literal === "boolean") || + "literalBoolean" in value) + ); } function isAnyComponentNode(value) { - if (!isObject$1(value)) return false; - if (!("id" in value && "type" in value && "properties" in value)) return false; - return true; + if (!isObject$1(value)) return false; + if (!("id" in value && "type" in value && "properties" in value)) return false; + return true; } function isResolvedAudioPlayer(props) { - return isObject$1(props) && "url" in props && isStringValue(props.url); + return isObject$1(props) && "url" in props && isStringValue(props.url); } function isResolvedButton(props) { - return isObject$1(props) && "child" in props && isAnyComponentNode(props.child) && "action" in props; + return ( + isObject$1(props) && "child" in props && isAnyComponentNode(props.child) && "action" in props + ); } function isResolvedCard(props) { - if (!isObject$1(props)) return false; - if (!("child" in props)) if (!("children" in props)) return false; - else return Array.isArray(props.children) && props.children.every(isAnyComponentNode); - return isAnyComponentNode(props.child); + if (!isObject$1(props)) return false; + if (!("child" in props)) + if (!("children" in props)) return false; + else return Array.isArray(props.children) && props.children.every(isAnyComponentNode); + return isAnyComponentNode(props.child); } function isResolvedCheckbox(props) { - return isObject$1(props) && "label" in props && isStringValue(props.label) && "value" in props && isBooleanValue(props.value); + return ( + isObject$1(props) && + "label" in props && + isStringValue(props.label) && + "value" in props && + isBooleanValue(props.value) + ); } function isResolvedColumn(props) { - return isObject$1(props) && "children" in props && Array.isArray(props.children) && props.children.every(isAnyComponentNode); + return ( + isObject$1(props) && + "children" in props && + Array.isArray(props.children) && + props.children.every(isAnyComponentNode) + ); } function isResolvedDateTimeInput(props) { - return isObject$1(props) && "value" in props && isStringValue(props.value); + return isObject$1(props) && "value" in props && isStringValue(props.value); } function isResolvedDivider(props) { - return isObject$1(props); + return isObject$1(props); } function isResolvedImage(props) { - return isObject$1(props) && "url" in props && isStringValue(props.url); + return isObject$1(props) && "url" in props && isStringValue(props.url); } function isResolvedIcon(props) { - return isObject$1(props) && "name" in props && isStringValue(props.name); + return isObject$1(props) && "name" in props && isStringValue(props.name); } function isResolvedList(props) { - return isObject$1(props) && "children" in props && Array.isArray(props.children) && props.children.every(isAnyComponentNode); + return ( + isObject$1(props) && + "children" in props && + Array.isArray(props.children) && + props.children.every(isAnyComponentNode) + ); } function isResolvedModal(props) { - return isObject$1(props) && "entryPointChild" in props && isAnyComponentNode(props.entryPointChild) && "contentChild" in props && isAnyComponentNode(props.contentChild); + return ( + isObject$1(props) && + "entryPointChild" in props && + isAnyComponentNode(props.entryPointChild) && + "contentChild" in props && + isAnyComponentNode(props.contentChild) + ); } function isResolvedMultipleChoice(props) { - return isObject$1(props) && "selections" in props; + return isObject$1(props) && "selections" in props; } function isResolvedRow(props) { - return isObject$1(props) && "children" in props && Array.isArray(props.children) && props.children.every(isAnyComponentNode); + return ( + isObject$1(props) && + "children" in props && + Array.isArray(props.children) && + props.children.every(isAnyComponentNode) + ); } function isResolvedSlider(props) { - return isObject$1(props) && "value" in props && isNumberValue(props.value); + return isObject$1(props) && "value" in props && isNumberValue(props.value); } function isResolvedTabItem(item) { - return isObject$1(item) && "title" in item && isStringValue(item.title) && "child" in item && isAnyComponentNode(item.child); + return ( + isObject$1(item) && + "title" in item && + isStringValue(item.title) && + "child" in item && + isAnyComponentNode(item.child) + ); } function isResolvedTabs(props) { - return isObject$1(props) && "tabItems" in props && Array.isArray(props.tabItems) && props.tabItems.every(isResolvedTabItem); + return ( + isObject$1(props) && + "tabItems" in props && + Array.isArray(props.tabItems) && + props.tabItems.every(isResolvedTabItem) + ); } function isResolvedText(props) { - return isObject$1(props) && "text" in props && isStringValue(props.text); + return isObject$1(props) && "text" in props && isStringValue(props.text); } function isResolvedTextField(props) { - return isObject$1(props) && "label" in props && isStringValue(props.label); + return isObject$1(props) && "label" in props && isStringValue(props.label); } function isResolvedVideo(props) { - return isObject$1(props) && "url" in props && isStringValue(props.url); + return isObject$1(props) && "url" in props && isStringValue(props.url); } /** -* Processes and consolidates A2UIProtocolMessage objects into a structured, -* hierarchical model of UI surfaces. -*/ + * Processes and consolidates A2UIProtocolMessage objects into a structured, + * hierarchical model of UI surfaces. + */ var A2uiMessageProcessor = class A2uiMessageProcessor { - static { - this.DEFAULT_SURFACE_ID = "@default"; - } - #mapCtor = Map; - #arrayCtor = Array; - #setCtor = Set; - #objCtor = Object; - #surfaces; - constructor(opts = { - mapCtor: Map, - arrayCtor: Array, - setCtor: Set, - objCtor: Object - }) { - this.opts = opts; - this.#arrayCtor = opts.arrayCtor; - this.#mapCtor = opts.mapCtor; - this.#setCtor = opts.setCtor; - this.#objCtor = opts.objCtor; - this.#surfaces = new opts.mapCtor(); - } - getSurfaces() { - return this.#surfaces; - } - clearSurfaces() { - this.#surfaces.clear(); - } - processMessages(messages) { - for (const message of messages) { - if (message.beginRendering) this.#handleBeginRendering(message.beginRendering, message.beginRendering.surfaceId); - if (message.surfaceUpdate) this.#handleSurfaceUpdate(message.surfaceUpdate, message.surfaceUpdate.surfaceId); - if (message.dataModelUpdate) this.#handleDataModelUpdate(message.dataModelUpdate, message.dataModelUpdate.surfaceId); - if (message.deleteSurface) this.#handleDeleteSurface(message.deleteSurface); - } - } - /** - * Retrieves the data for a given component node and a relative path string. - * This correctly handles the special `.` path, which refers to the node's - * own data context. - */ - getData(node, relativePath, surfaceId = A2uiMessageProcessor.DEFAULT_SURFACE_ID) { - const surface = this.#getOrCreateSurface(surfaceId); - if (!surface) return null; - let finalPath; - if (relativePath === "." || relativePath === "") finalPath = node.dataContextPath ?? "/"; - else finalPath = this.resolvePath(relativePath, node.dataContextPath); - return this.#getDataByPath(surface.dataModel, finalPath); - } - setData(node, relativePath, value, surfaceId = A2uiMessageProcessor.DEFAULT_SURFACE_ID) { - if (!node) { - console.warn("No component node set"); - return; - } - const surface = this.#getOrCreateSurface(surfaceId); - if (!surface) return; - let finalPath; - if (relativePath === "." || relativePath === "") finalPath = node.dataContextPath ?? "/"; - else finalPath = this.resolvePath(relativePath, node.dataContextPath); - this.#setDataByPath(surface.dataModel, finalPath, value); - } - resolvePath(path, dataContextPath) { - if (path.startsWith("/")) return path; - if (dataContextPath && dataContextPath !== "/") return dataContextPath.endsWith("/") ? `${dataContextPath}${path}` : `${dataContextPath}/${path}`; - return `/${path}`; - } - #parseIfJsonString(value) { - if (typeof value !== "string") return value; - const trimmedValue = value.trim(); - if (trimmedValue.startsWith("{") && trimmedValue.endsWith("}") || trimmedValue.startsWith("[") && trimmedValue.endsWith("]")) try { - return JSON.parse(value); - } catch (e) { - console.warn(`Failed to parse potential JSON string: "${value.substring(0, 50)}..."`, e); - return value; - } - return value; - } - /** - * Converts a specific array format [{key: "...", value_string: "..."}, ...] - * into a standard Map. It also attempts to parse any string values that - * appear to be stringified JSON. - */ - #convertKeyValueArrayToMap(arr) { - const map = new this.#mapCtor(); - for (const item of arr) { - if (!isObject$1(item) || !("key" in item)) continue; - const key = item.key; - const valueKey = this.#findValueKey(item); - if (!valueKey) continue; - let value = item[valueKey]; - if (valueKey === "valueMap" && Array.isArray(value)) value = this.#convertKeyValueArrayToMap(value); - else if (typeof value === "string") value = this.#parseIfJsonString(value); - this.#setDataByPath(map, key, value); - } - return map; - } - #setDataByPath(root, path, value) { - if (Array.isArray(value) && (value.length === 0 || isObject$1(value[0]) && "key" in value[0])) if (value.length === 1 && isObject$1(value[0]) && value[0].key === ".") { - const item = value[0]; - const valueKey = this.#findValueKey(item); - if (valueKey) { - value = item[valueKey]; - if (valueKey === "valueMap" && Array.isArray(value)) value = this.#convertKeyValueArrayToMap(value); - else if (typeof value === "string") value = this.#parseIfJsonString(value); - } else value = this.#convertKeyValueArrayToMap(value); - } else value = this.#convertKeyValueArrayToMap(value); - const segments = this.#normalizePath(path).split("/").filter((s) => s); - if (segments.length === 0) { - if (value instanceof Map || isObject$1(value)) { - if (!(value instanceof Map) && isObject$1(value)) value = new this.#mapCtor(Object.entries(value)); - root.clear(); - for (const [key, v] of value.entries()) root.set(key, v); - } else console.error("Cannot set root of DataModel to a non-Map value."); - return; - } - let current = root; - for (let i = 0; i < segments.length - 1; i++) { - const segment = segments[i]; - let target; - if (current instanceof Map) target = current.get(segment); - else if (Array.isArray(current) && /^\d+$/.test(segment)) target = current[parseInt(segment, 10)]; - if (target === void 0 || typeof target !== "object" || target === null) { - target = new this.#mapCtor(); - if (current instanceof this.#mapCtor) current.set(segment, target); - else if (Array.isArray(current)) current[parseInt(segment, 10)] = target; - } - current = target; - } - const finalSegment = segments[segments.length - 1]; - const storedValue = value; - if (current instanceof this.#mapCtor) current.set(finalSegment, storedValue); - else if (Array.isArray(current) && /^\d+$/.test(finalSegment)) current[parseInt(finalSegment, 10)] = storedValue; - } - /** - * Normalizes a path string into a consistent, slash-delimited format. - * Converts bracket notation and dot notation in a two-pass. - * e.g., "bookRecommendations[0].title" -> "/bookRecommendations/0/title" - * e.g., "book.0.title" -> "/book/0/title" - */ - #normalizePath(path) { - return "/" + path.replace(/\[(\d+)\]/g, ".$1").split(".").filter((s) => s.length > 0).join("/"); - } - #getDataByPath(root, path) { - const segments = this.#normalizePath(path).split("/").filter((s) => s); - let current = root; - for (const segment of segments) { - if (current === void 0 || current === null) return null; - if (current instanceof Map) current = current.get(segment); - else if (Array.isArray(current) && /^\d+$/.test(segment)) current = current[parseInt(segment, 10)]; - else if (isObject$1(current)) current = current[segment]; - else return null; - } - return current; - } - #getOrCreateSurface(surfaceId) { - let surface = this.#surfaces.get(surfaceId); - if (!surface) { - surface = new this.#objCtor({ - rootComponentId: null, - componentTree: null, - dataModel: new this.#mapCtor(), - components: new this.#mapCtor(), - styles: new this.#objCtor() - }); - this.#surfaces.set(surfaceId, surface); - } - return surface; - } - #handleBeginRendering(message, surfaceId) { - const surface = this.#getOrCreateSurface(surfaceId); - surface.rootComponentId = message.root; - surface.styles = message.styles ?? {}; - this.#rebuildComponentTree(surface); - } - #handleSurfaceUpdate(message, surfaceId) { - const surface = this.#getOrCreateSurface(surfaceId); - for (const component of message.components) surface.components.set(component.id, component); - this.#rebuildComponentTree(surface); - } - #handleDataModelUpdate(message, surfaceId) { - const surface = this.#getOrCreateSurface(surfaceId); - const path = message.path ?? "/"; - this.#setDataByPath(surface.dataModel, path, message.contents); - this.#rebuildComponentTree(surface); - } - #handleDeleteSurface(message) { - this.#surfaces.delete(message.surfaceId); - } - /** - * Starts at the root component of the surface and builds out the tree - * recursively. This process involves resolving all properties of the child - * components, and expanding on any explicit children lists or templates - * found in the structure. - * - * @param surface The surface to be built. - */ - #rebuildComponentTree(surface) { - if (!surface.rootComponentId) { - surface.componentTree = null; - return; - } - const visited = new this.#setCtor(); - surface.componentTree = this.#buildNodeRecursive(surface.rootComponentId, surface, visited, "/", ""); - } - /** Finds a value key in a map. */ - #findValueKey(value) { - return Object.keys(value).find((k) => k.startsWith("value")); - } - /** - * Builds out the nodes recursively. - */ - #buildNodeRecursive(baseComponentId, surface, visited, dataContextPath, idSuffix = "") { - const fullId = `${baseComponentId}${idSuffix}`; - const { components } = surface; - if (!components.has(baseComponentId)) return null; - if (visited.has(fullId)) throw new Error(`Circular dependency for component "${fullId}".`); - visited.add(fullId); - const componentData = components.get(baseComponentId); - const componentProps = componentData.component ?? {}; - const componentType = Object.keys(componentProps)[0]; - const unresolvedProperties = componentProps[componentType]; - const resolvedProperties = new this.#objCtor(); - if (isObject$1(unresolvedProperties)) for (const [key, value] of Object.entries(unresolvedProperties)) resolvedProperties[key] = this.#resolvePropertyValue(value, surface, visited, dataContextPath, idSuffix, key); - visited.delete(fullId); - const baseNode = { - id: fullId, - dataContextPath, - weight: componentData.weight ?? "initial" - }; - switch (componentType) { - case "Text": - if (!isResolvedText(resolvedProperties)) throw new Error(`Invalid data; expected ${componentType}`); - return new this.#objCtor({ - ...baseNode, - type: "Text", - properties: resolvedProperties - }); - case "Image": - if (!isResolvedImage(resolvedProperties)) throw new Error(`Invalid data; expected ${componentType}`); - return new this.#objCtor({ - ...baseNode, - type: "Image", - properties: resolvedProperties - }); - case "Icon": - if (!isResolvedIcon(resolvedProperties)) throw new Error(`Invalid data; expected ${componentType}`); - return new this.#objCtor({ - ...baseNode, - type: "Icon", - properties: resolvedProperties - }); - case "Video": - if (!isResolvedVideo(resolvedProperties)) throw new Error(`Invalid data; expected ${componentType}`); - return new this.#objCtor({ - ...baseNode, - type: "Video", - properties: resolvedProperties - }); - case "AudioPlayer": - if (!isResolvedAudioPlayer(resolvedProperties)) throw new Error(`Invalid data; expected ${componentType}`); - return new this.#objCtor({ - ...baseNode, - type: "AudioPlayer", - properties: resolvedProperties - }); - case "Row": - if (!isResolvedRow(resolvedProperties)) throw new Error(`Invalid data; expected ${componentType}`); - return new this.#objCtor({ - ...baseNode, - type: "Row", - properties: resolvedProperties - }); - case "Column": - if (!isResolvedColumn(resolvedProperties)) throw new Error(`Invalid data; expected ${componentType}`); - return new this.#objCtor({ - ...baseNode, - type: "Column", - properties: resolvedProperties - }); - case "List": - if (!isResolvedList(resolvedProperties)) throw new Error(`Invalid data; expected ${componentType}`); - return new this.#objCtor({ - ...baseNode, - type: "List", - properties: resolvedProperties - }); - case "Card": - if (!isResolvedCard(resolvedProperties)) throw new Error(`Invalid data; expected ${componentType}`); - return new this.#objCtor({ - ...baseNode, - type: "Card", - properties: resolvedProperties - }); - case "Tabs": - if (!isResolvedTabs(resolvedProperties)) throw new Error(`Invalid data; expected ${componentType}`); - return new this.#objCtor({ - ...baseNode, - type: "Tabs", - properties: resolvedProperties - }); - case "Divider": - if (!isResolvedDivider(resolvedProperties)) throw new Error(`Invalid data; expected ${componentType}`); - return new this.#objCtor({ - ...baseNode, - type: "Divider", - properties: resolvedProperties - }); - case "Modal": - if (!isResolvedModal(resolvedProperties)) throw new Error(`Invalid data; expected ${componentType}`); - return new this.#objCtor({ - ...baseNode, - type: "Modal", - properties: resolvedProperties - }); - case "Button": - if (!isResolvedButton(resolvedProperties)) throw new Error(`Invalid data; expected ${componentType}`); - return new this.#objCtor({ - ...baseNode, - type: "Button", - properties: resolvedProperties - }); - case "CheckBox": - if (!isResolvedCheckbox(resolvedProperties)) throw new Error(`Invalid data; expected ${componentType}`); - return new this.#objCtor({ - ...baseNode, - type: "CheckBox", - properties: resolvedProperties - }); - case "TextField": - if (!isResolvedTextField(resolvedProperties)) throw new Error(`Invalid data; expected ${componentType}`); - return new this.#objCtor({ - ...baseNode, - type: "TextField", - properties: resolvedProperties - }); - case "DateTimeInput": - if (!isResolvedDateTimeInput(resolvedProperties)) throw new Error(`Invalid data; expected ${componentType}`); - return new this.#objCtor({ - ...baseNode, - type: "DateTimeInput", - properties: resolvedProperties - }); - case "MultipleChoice": - if (!isResolvedMultipleChoice(resolvedProperties)) throw new Error(`Invalid data; expected ${componentType}`); - return new this.#objCtor({ - ...baseNode, - type: "MultipleChoice", - properties: resolvedProperties - }); - case "Slider": - if (!isResolvedSlider(resolvedProperties)) throw new Error(`Invalid data; expected ${componentType}`); - return new this.#objCtor({ - ...baseNode, - type: "Slider", - properties: resolvedProperties - }); - default: return new this.#objCtor({ - ...baseNode, - type: componentType, - properties: resolvedProperties - }); - } - } - /** - * Recursively resolves an individual property value. If a property indicates - * a child node (a string that matches a component ID), an explicitList of - * children, or a template, these will be built out here. - */ - #resolvePropertyValue(value, surface, visited, dataContextPath, idSuffix = "", propertyKey = null) { - const isComponentIdReferenceKey = (key) => key === "child" || key.endsWith("Child"); - if (typeof value === "string" && propertyKey && isComponentIdReferenceKey(propertyKey) && surface.components.has(value)) return this.#buildNodeRecursive(value, surface, visited, dataContextPath, idSuffix); - if (isComponentArrayReference(value)) { - if (value.explicitList) return value.explicitList.map((id) => this.#buildNodeRecursive(id, surface, visited, dataContextPath, idSuffix)); - if (value.template) { - const fullDataPath = this.resolvePath(value.template.dataBinding, dataContextPath); - const data = this.#getDataByPath(surface.dataModel, fullDataPath); - const template = value.template; - if (Array.isArray(data)) return data.map((_, index) => { - const newSuffix = `:${[...dataContextPath.split("/").filter((segment) => /^\d+$/.test(segment)), index].join(":")}`; - const childDataContextPath = `${fullDataPath}/${index}`; - return this.#buildNodeRecursive(template.componentId, surface, visited, childDataContextPath, newSuffix); - }); - if (data instanceof this.#mapCtor) return Array.from(data.keys(), (key) => { - const newSuffix = `:${key}`; - const childDataContextPath = `${fullDataPath}/${key}`; - return this.#buildNodeRecursive(template.componentId, surface, visited, childDataContextPath, newSuffix); - }); - return new this.#arrayCtor(); - } - } - if (Array.isArray(value)) return value.map((item) => this.#resolvePropertyValue(item, surface, visited, dataContextPath, idSuffix, propertyKey)); - if (isObject$1(value)) { - const newObj = new this.#objCtor(); - for (const [key, propValue] of Object.entries(value)) { - let propertyValue = propValue; - if (isPath(key, propValue) && dataContextPath !== "/") { - propertyValue = propValue.replace(/^\.?\/item/, "").replace(/^\.?\/text/, "").replace(/^\.?\/label/, "").replace(/^\.?\//, ""); - newObj[key] = propertyValue; - continue; - } - newObj[key] = this.#resolvePropertyValue(propertyValue, surface, visited, dataContextPath, idSuffix, key); - } - return newObj; - } - return value; - } + static { + this.DEFAULT_SURFACE_ID = "@default"; + } + #mapCtor = Map; + #arrayCtor = Array; + #setCtor = Set; + #objCtor = Object; + #surfaces; + constructor( + opts = { + mapCtor: Map, + arrayCtor: Array, + setCtor: Set, + objCtor: Object, + }, + ) { + this.opts = opts; + this.#arrayCtor = opts.arrayCtor; + this.#mapCtor = opts.mapCtor; + this.#setCtor = opts.setCtor; + this.#objCtor = opts.objCtor; + this.#surfaces = new opts.mapCtor(); + } + getSurfaces() { + return this.#surfaces; + } + clearSurfaces() { + this.#surfaces.clear(); + } + processMessages(messages) { + for (const message of messages) { + if (message.beginRendering) + this.#handleBeginRendering(message.beginRendering, message.beginRendering.surfaceId); + if (message.surfaceUpdate) + this.#handleSurfaceUpdate(message.surfaceUpdate, message.surfaceUpdate.surfaceId); + if (message.dataModelUpdate) + this.#handleDataModelUpdate(message.dataModelUpdate, message.dataModelUpdate.surfaceId); + if (message.deleteSurface) this.#handleDeleteSurface(message.deleteSurface); + } + } + /** + * Retrieves the data for a given component node and a relative path string. + * This correctly handles the special `.` path, which refers to the node's + * own data context. + */ + getData(node, relativePath, surfaceId = A2uiMessageProcessor.DEFAULT_SURFACE_ID) { + const surface = this.#getOrCreateSurface(surfaceId); + if (!surface) return null; + let finalPath; + if (relativePath === "." || relativePath === "") finalPath = node.dataContextPath ?? "/"; + else finalPath = this.resolvePath(relativePath, node.dataContextPath); + return this.#getDataByPath(surface.dataModel, finalPath); + } + setData(node, relativePath, value, surfaceId = A2uiMessageProcessor.DEFAULT_SURFACE_ID) { + if (!node) { + console.warn("No component node set"); + return; + } + const surface = this.#getOrCreateSurface(surfaceId); + if (!surface) return; + let finalPath; + if (relativePath === "." || relativePath === "") finalPath = node.dataContextPath ?? "/"; + else finalPath = this.resolvePath(relativePath, node.dataContextPath); + this.#setDataByPath(surface.dataModel, finalPath, value); + } + resolvePath(path, dataContextPath) { + if (path.startsWith("/")) return path; + if (dataContextPath && dataContextPath !== "/") + return dataContextPath.endsWith("/") + ? `${dataContextPath}${path}` + : `${dataContextPath}/${path}`; + return `/${path}`; + } + #parseIfJsonString(value) { + if (typeof value !== "string") return value; + const trimmedValue = value.trim(); + if ( + (trimmedValue.startsWith("{") && trimmedValue.endsWith("}")) || + (trimmedValue.startsWith("[") && trimmedValue.endsWith("]")) + ) + try { + return JSON.parse(value); + } catch (e) { + console.warn(`Failed to parse potential JSON string: "${value.substring(0, 50)}..."`, e); + return value; + } + return value; + } + /** + * Converts a specific array format [{key: "...", value_string: "..."}, ...] + * into a standard Map. It also attempts to parse any string values that + * appear to be stringified JSON. + */ + #convertKeyValueArrayToMap(arr) { + const map = new this.#mapCtor(); + for (const item of arr) { + if (!isObject$1(item) || !("key" in item)) continue; + const key = item.key; + const valueKey = this.#findValueKey(item); + if (!valueKey) continue; + let value = item[valueKey]; + if (valueKey === "valueMap" && Array.isArray(value)) + value = this.#convertKeyValueArrayToMap(value); + else if (typeof value === "string") value = this.#parseIfJsonString(value); + this.#setDataByPath(map, key, value); + } + return map; + } + #setDataByPath(root, path, value) { + if (Array.isArray(value) && (value.length === 0 || (isObject$1(value[0]) && "key" in value[0]))) + if (value.length === 1 && isObject$1(value[0]) && value[0].key === ".") { + const item = value[0]; + const valueKey = this.#findValueKey(item); + if (valueKey) { + value = item[valueKey]; + if (valueKey === "valueMap" && Array.isArray(value)) + value = this.#convertKeyValueArrayToMap(value); + else if (typeof value === "string") value = this.#parseIfJsonString(value); + } else value = this.#convertKeyValueArrayToMap(value); + } else value = this.#convertKeyValueArrayToMap(value); + const segments = this.#normalizePath(path) + .split("/") + .filter((s) => s); + if (segments.length === 0) { + if (value instanceof Map || isObject$1(value)) { + if (!(value instanceof Map) && isObject$1(value)) + value = new this.#mapCtor(Object.entries(value)); + root.clear(); + for (const [key, v] of value.entries()) root.set(key, v); + } else console.error("Cannot set root of DataModel to a non-Map value."); + return; + } + let current = root; + for (let i = 0; i < segments.length - 1; i++) { + const segment = segments[i]; + let target; + if (current instanceof Map) target = current.get(segment); + else if (Array.isArray(current) && /^\d+$/.test(segment)) + target = current[parseInt(segment, 10)]; + if (target === void 0 || typeof target !== "object" || target === null) { + target = new this.#mapCtor(); + if (current instanceof this.#mapCtor) current.set(segment, target); + else if (Array.isArray(current)) current[parseInt(segment, 10)] = target; + } + current = target; + } + const finalSegment = segments[segments.length - 1]; + const storedValue = value; + if (current instanceof this.#mapCtor) current.set(finalSegment, storedValue); + else if (Array.isArray(current) && /^\d+$/.test(finalSegment)) + current[parseInt(finalSegment, 10)] = storedValue; + } + /** + * Normalizes a path string into a consistent, slash-delimited format. + * Converts bracket notation and dot notation in a two-pass. + * e.g., "bookRecommendations[0].title" -> "/bookRecommendations/0/title" + * e.g., "book.0.title" -> "/book/0/title" + */ + #normalizePath(path) { + return ( + "/" + + path + .replace(/\[(\d+)\]/g, ".$1") + .split(".") + .filter((s) => s.length > 0) + .join("/") + ); + } + #getDataByPath(root, path) { + const segments = this.#normalizePath(path) + .split("/") + .filter((s) => s); + let current = root; + for (const segment of segments) { + if (current === void 0 || current === null) return null; + if (current instanceof Map) current = current.get(segment); + else if (Array.isArray(current) && /^\d+$/.test(segment)) + current = current[parseInt(segment, 10)]; + else if (isObject$1(current)) current = current[segment]; + else return null; + } + return current; + } + #getOrCreateSurface(surfaceId) { + let surface = this.#surfaces.get(surfaceId); + if (!surface) { + surface = new this.#objCtor({ + rootComponentId: null, + componentTree: null, + dataModel: new this.#mapCtor(), + components: new this.#mapCtor(), + styles: new this.#objCtor(), + }); + this.#surfaces.set(surfaceId, surface); + } + return surface; + } + #handleBeginRendering(message, surfaceId) { + const surface = this.#getOrCreateSurface(surfaceId); + surface.rootComponentId = message.root; + surface.styles = message.styles ?? {}; + this.#rebuildComponentTree(surface); + } + #handleSurfaceUpdate(message, surfaceId) { + const surface = this.#getOrCreateSurface(surfaceId); + for (const component of message.components) surface.components.set(component.id, component); + this.#rebuildComponentTree(surface); + } + #handleDataModelUpdate(message, surfaceId) { + const surface = this.#getOrCreateSurface(surfaceId); + const path = message.path ?? "/"; + this.#setDataByPath(surface.dataModel, path, message.contents); + this.#rebuildComponentTree(surface); + } + #handleDeleteSurface(message) { + this.#surfaces.delete(message.surfaceId); + } + /** + * Starts at the root component of the surface and builds out the tree + * recursively. This process involves resolving all properties of the child + * components, and expanding on any explicit children lists or templates + * found in the structure. + * + * @param surface The surface to be built. + */ + #rebuildComponentTree(surface) { + if (!surface.rootComponentId) { + surface.componentTree = null; + return; + } + const visited = new this.#setCtor(); + surface.componentTree = this.#buildNodeRecursive( + surface.rootComponentId, + surface, + visited, + "/", + "", + ); + } + /** Finds a value key in a map. */ + #findValueKey(value) { + return Object.keys(value).find((k) => k.startsWith("value")); + } + /** + * Builds out the nodes recursively. + */ + #buildNodeRecursive(baseComponentId, surface, visited, dataContextPath, idSuffix = "") { + const fullId = `${baseComponentId}${idSuffix}`; + const { components } = surface; + if (!components.has(baseComponentId)) return null; + if (visited.has(fullId)) throw new Error(`Circular dependency for component "${fullId}".`); + visited.add(fullId); + const componentData = components.get(baseComponentId); + const componentProps = componentData.component ?? {}; + const componentType = Object.keys(componentProps)[0]; + const unresolvedProperties = componentProps[componentType]; + const resolvedProperties = new this.#objCtor(); + if (isObject$1(unresolvedProperties)) + for (const [key, value] of Object.entries(unresolvedProperties)) + resolvedProperties[key] = this.#resolvePropertyValue( + value, + surface, + visited, + dataContextPath, + idSuffix, + key, + ); + visited.delete(fullId); + const baseNode = { + id: fullId, + dataContextPath, + weight: componentData.weight ?? "initial", + }; + switch (componentType) { + case "Text": + if (!isResolvedText(resolvedProperties)) + throw new Error(`Invalid data; expected ${componentType}`); + return new this.#objCtor({ + ...baseNode, + type: "Text", + properties: resolvedProperties, + }); + case "Image": + if (!isResolvedImage(resolvedProperties)) + throw new Error(`Invalid data; expected ${componentType}`); + return new this.#objCtor({ + ...baseNode, + type: "Image", + properties: resolvedProperties, + }); + case "Icon": + if (!isResolvedIcon(resolvedProperties)) + throw new Error(`Invalid data; expected ${componentType}`); + return new this.#objCtor({ + ...baseNode, + type: "Icon", + properties: resolvedProperties, + }); + case "Video": + if (!isResolvedVideo(resolvedProperties)) + throw new Error(`Invalid data; expected ${componentType}`); + return new this.#objCtor({ + ...baseNode, + type: "Video", + properties: resolvedProperties, + }); + case "AudioPlayer": + if (!isResolvedAudioPlayer(resolvedProperties)) + throw new Error(`Invalid data; expected ${componentType}`); + return new this.#objCtor({ + ...baseNode, + type: "AudioPlayer", + properties: resolvedProperties, + }); + case "Row": + if (!isResolvedRow(resolvedProperties)) + throw new Error(`Invalid data; expected ${componentType}`); + return new this.#objCtor({ + ...baseNode, + type: "Row", + properties: resolvedProperties, + }); + case "Column": + if (!isResolvedColumn(resolvedProperties)) + throw new Error(`Invalid data; expected ${componentType}`); + return new this.#objCtor({ + ...baseNode, + type: "Column", + properties: resolvedProperties, + }); + case "List": + if (!isResolvedList(resolvedProperties)) + throw new Error(`Invalid data; expected ${componentType}`); + return new this.#objCtor({ + ...baseNode, + type: "List", + properties: resolvedProperties, + }); + case "Card": + if (!isResolvedCard(resolvedProperties)) + throw new Error(`Invalid data; expected ${componentType}`); + return new this.#objCtor({ + ...baseNode, + type: "Card", + properties: resolvedProperties, + }); + case "Tabs": + if (!isResolvedTabs(resolvedProperties)) + throw new Error(`Invalid data; expected ${componentType}`); + return new this.#objCtor({ + ...baseNode, + type: "Tabs", + properties: resolvedProperties, + }); + case "Divider": + if (!isResolvedDivider(resolvedProperties)) + throw new Error(`Invalid data; expected ${componentType}`); + return new this.#objCtor({ + ...baseNode, + type: "Divider", + properties: resolvedProperties, + }); + case "Modal": + if (!isResolvedModal(resolvedProperties)) + throw new Error(`Invalid data; expected ${componentType}`); + return new this.#objCtor({ + ...baseNode, + type: "Modal", + properties: resolvedProperties, + }); + case "Button": + if (!isResolvedButton(resolvedProperties)) + throw new Error(`Invalid data; expected ${componentType}`); + return new this.#objCtor({ + ...baseNode, + type: "Button", + properties: resolvedProperties, + }); + case "CheckBox": + if (!isResolvedCheckbox(resolvedProperties)) + throw new Error(`Invalid data; expected ${componentType}`); + return new this.#objCtor({ + ...baseNode, + type: "CheckBox", + properties: resolvedProperties, + }); + case "TextField": + if (!isResolvedTextField(resolvedProperties)) + throw new Error(`Invalid data; expected ${componentType}`); + return new this.#objCtor({ + ...baseNode, + type: "TextField", + properties: resolvedProperties, + }); + case "DateTimeInput": + if (!isResolvedDateTimeInput(resolvedProperties)) + throw new Error(`Invalid data; expected ${componentType}`); + return new this.#objCtor({ + ...baseNode, + type: "DateTimeInput", + properties: resolvedProperties, + }); + case "MultipleChoice": + if (!isResolvedMultipleChoice(resolvedProperties)) + throw new Error(`Invalid data; expected ${componentType}`); + return new this.#objCtor({ + ...baseNode, + type: "MultipleChoice", + properties: resolvedProperties, + }); + case "Slider": + if (!isResolvedSlider(resolvedProperties)) + throw new Error(`Invalid data; expected ${componentType}`); + return new this.#objCtor({ + ...baseNode, + type: "Slider", + properties: resolvedProperties, + }); + default: + return new this.#objCtor({ + ...baseNode, + type: componentType, + properties: resolvedProperties, + }); + } + } + /** + * Recursively resolves an individual property value. If a property indicates + * a child node (a string that matches a component ID), an explicitList of + * children, or a template, these will be built out here. + */ + #resolvePropertyValue( + value, + surface, + visited, + dataContextPath, + idSuffix = "", + propertyKey = null, + ) { + const isComponentIdReferenceKey = (key) => key === "child" || key.endsWith("Child"); + if ( + typeof value === "string" && + propertyKey && + isComponentIdReferenceKey(propertyKey) && + surface.components.has(value) + ) + return this.#buildNodeRecursive(value, surface, visited, dataContextPath, idSuffix); + if (isComponentArrayReference(value)) { + if (value.explicitList) + return value.explicitList.map((id) => + this.#buildNodeRecursive(id, surface, visited, dataContextPath, idSuffix), + ); + if (value.template) { + const fullDataPath = this.resolvePath(value.template.dataBinding, dataContextPath); + const data = this.#getDataByPath(surface.dataModel, fullDataPath); + const template = value.template; + if (Array.isArray(data)) + return data.map((_, index) => { + const newSuffix = `:${[...dataContextPath.split("/").filter((segment) => /^\d+$/.test(segment)), index].join(":")}`; + const childDataContextPath = `${fullDataPath}/${index}`; + return this.#buildNodeRecursive( + template.componentId, + surface, + visited, + childDataContextPath, + newSuffix, + ); + }); + if (data instanceof this.#mapCtor) + return Array.from(data.keys(), (key) => { + const newSuffix = `:${key}`; + const childDataContextPath = `${fullDataPath}/${key}`; + return this.#buildNodeRecursive( + template.componentId, + surface, + visited, + childDataContextPath, + newSuffix, + ); + }); + return new this.#arrayCtor(); + } + } + if (Array.isArray(value)) + return value.map((item) => + this.#resolvePropertyValue(item, surface, visited, dataContextPath, idSuffix, propertyKey), + ); + if (isObject$1(value)) { + const newObj = new this.#objCtor(); + for (const [key, propValue] of Object.entries(value)) { + let propertyValue = propValue; + if (isPath(key, propValue) && dataContextPath !== "/") { + propertyValue = propValue + .replace(/^\.?\/item/, "") + .replace(/^\.?\/text/, "") + .replace(/^\.?\/label/, "") + .replace(/^\.?\//, ""); + newObj[key] = propertyValue; + continue; + } + newObj[key] = this.#resolvePropertyValue( + propertyValue, + surface, + visited, + dataContextPath, + idSuffix, + key, + ); + } + return newObj; + } + return value; + } }; var __defProp = Object.defineProperty; -var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { - enumerable: true, - configurable: true, - writable: true, - value -}) : obj[key] = value; +var __defNormalProp = (obj, key, value) => + key in obj + ? __defProp(obj, key, { + enumerable: true, + configurable: true, + writable: true, + value, + }) + : (obj[key] = value); var __publicField = (obj, key, value) => { - __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); - return value; + __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); + return value; }; var __accessCheck = (obj, member, msg) => { - if (!member.has(obj)) throw TypeError("Cannot " + msg); + if (!member.has(obj)) throw TypeError("Cannot " + msg); }; var __privateIn = (member, obj) => { - if (Object(obj) !== obj) throw TypeError("Cannot use the \"in\" operator on this value"); - return member.has(obj); + if (Object(obj) !== obj) throw TypeError('Cannot use the "in" operator on this value'); + return member.has(obj); }; var __privateAdd = (obj, member, value) => { - if (member.has(obj)) throw TypeError("Cannot add the same private member more than once"); - member instanceof WeakSet ? member.add(obj) : member.set(obj, value); + if (member.has(obj)) throw TypeError("Cannot add the same private member more than once"); + member instanceof WeakSet ? member.add(obj) : member.set(obj, value); }; var __privateMethod = (obj, member, method) => { - __accessCheck(obj, member, "access private method"); - return method; + __accessCheck(obj, member, "access private method"); + return method; }; /** -* @license -* Copyright Google LLC All Rights Reserved. -* -* Use of this source code is governed by an MIT-style license that can be -* found in the LICENSE file at https://angular.io/license -*/ + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ function defaultEquals(a, b) { - return Object.is(a, b); + return Object.is(a, b); } /** -* @license -* Copyright Google LLC All Rights Reserved. -* -* Use of this source code is governed by an MIT-style license that can be -* found in the LICENSE file at https://angular.io/license -*/ + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ let activeConsumer = null; let inNotificationPhase = false; let epoch = 1; const SIGNAL = /* @__PURE__ */ Symbol("SIGNAL"); function setActiveConsumer(consumer) { - const prev = activeConsumer; - activeConsumer = consumer; - return prev; + const prev = activeConsumer; + activeConsumer = consumer; + return prev; } function getActiveConsumer() { - return activeConsumer; + return activeConsumer; } function isInNotificationPhase() { - return inNotificationPhase; + return inNotificationPhase; } const REACTIVE_NODE = { - version: 0, - lastCleanEpoch: 0, - dirty: false, - producerNode: void 0, - producerLastReadVersion: void 0, - producerIndexOfThis: void 0, - nextProducerIndex: 0, - liveConsumerNode: void 0, - liveConsumerIndexOfThis: void 0, - consumerAllowSignalWrites: false, - consumerIsAlwaysLive: false, - producerMustRecompute: () => false, - producerRecomputeValue: () => {}, - consumerMarkedDirty: () => {}, - consumerOnSignalRead: () => {} + version: 0, + lastCleanEpoch: 0, + dirty: false, + producerNode: void 0, + producerLastReadVersion: void 0, + producerIndexOfThis: void 0, + nextProducerIndex: 0, + liveConsumerNode: void 0, + liveConsumerIndexOfThis: void 0, + consumerAllowSignalWrites: false, + consumerIsAlwaysLive: false, + producerMustRecompute: () => false, + producerRecomputeValue: () => {}, + consumerMarkedDirty: () => {}, + consumerOnSignalRead: () => {}, }; function producerAccessed(node) { - if (inNotificationPhase) throw new Error(typeof ngDevMode !== "undefined" && ngDevMode ? `Assertion error: signal read during notification phase` : ""); - if (activeConsumer === null) return; - activeConsumer.consumerOnSignalRead(node); - const idx = activeConsumer.nextProducerIndex++; - assertConsumerNode(activeConsumer); - if (idx < activeConsumer.producerNode.length && activeConsumer.producerNode[idx] !== node) { - if (consumerIsLive(activeConsumer)) { - const staleProducer = activeConsumer.producerNode[idx]; - producerRemoveLiveConsumerAtIndex(staleProducer, activeConsumer.producerIndexOfThis[idx]); - } - } - if (activeConsumer.producerNode[idx] !== node) { - activeConsumer.producerNode[idx] = node; - activeConsumer.producerIndexOfThis[idx] = consumerIsLive(activeConsumer) ? producerAddLiveConsumer(node, activeConsumer, idx) : 0; - } - activeConsumer.producerLastReadVersion[idx] = node.version; + if (inNotificationPhase) + throw new Error( + typeof ngDevMode !== "undefined" && ngDevMode + ? `Assertion error: signal read during notification phase` + : "", + ); + if (activeConsumer === null) return; + activeConsumer.consumerOnSignalRead(node); + const idx = activeConsumer.nextProducerIndex++; + assertConsumerNode(activeConsumer); + if (idx < activeConsumer.producerNode.length && activeConsumer.producerNode[idx] !== node) { + if (consumerIsLive(activeConsumer)) { + const staleProducer = activeConsumer.producerNode[idx]; + producerRemoveLiveConsumerAtIndex(staleProducer, activeConsumer.producerIndexOfThis[idx]); + } + } + if (activeConsumer.producerNode[idx] !== node) { + activeConsumer.producerNode[idx] = node; + activeConsumer.producerIndexOfThis[idx] = consumerIsLive(activeConsumer) + ? producerAddLiveConsumer(node, activeConsumer, idx) + : 0; + } + activeConsumer.producerLastReadVersion[idx] = node.version; } function producerIncrementEpoch() { - epoch++; + epoch++; } function producerUpdateValueVersion(node) { - if (!node.dirty && node.lastCleanEpoch === epoch) return; - if (!node.producerMustRecompute(node) && !consumerPollProducersForChange(node)) { - node.dirty = false; - node.lastCleanEpoch = epoch; - return; - } - node.producerRecomputeValue(node); - node.dirty = false; - node.lastCleanEpoch = epoch; + if (!node.dirty && node.lastCleanEpoch === epoch) return; + if (!node.producerMustRecompute(node) && !consumerPollProducersForChange(node)) { + node.dirty = false; + node.lastCleanEpoch = epoch; + return; + } + node.producerRecomputeValue(node); + node.dirty = false; + node.lastCleanEpoch = epoch; } function producerNotifyConsumers(node) { - if (node.liveConsumerNode === void 0) return; - const prev = inNotificationPhase; - inNotificationPhase = true; - try { - for (const consumer of node.liveConsumerNode) if (!consumer.dirty) consumerMarkDirty(consumer); - } finally { - inNotificationPhase = prev; - } + if (node.liveConsumerNode === void 0) return; + const prev = inNotificationPhase; + inNotificationPhase = true; + try { + for (const consumer of node.liveConsumerNode) if (!consumer.dirty) consumerMarkDirty(consumer); + } finally { + inNotificationPhase = prev; + } } function producerUpdatesAllowed() { - return (activeConsumer == null ? void 0 : activeConsumer.consumerAllowSignalWrites) !== false; + return (activeConsumer == null ? void 0 : activeConsumer.consumerAllowSignalWrites) !== false; } function consumerMarkDirty(node) { - var _a; - node.dirty = true; - producerNotifyConsumers(node); - (_a = node.consumerMarkedDirty) == null || _a.call(node.wrapper ?? node); + var _a; + node.dirty = true; + producerNotifyConsumers(node); + (_a = node.consumerMarkedDirty) == null || _a.call(node.wrapper ?? node); } function consumerBeforeComputation(node) { - node && (node.nextProducerIndex = 0); - return setActiveConsumer(node); + node && (node.nextProducerIndex = 0); + return setActiveConsumer(node); } function consumerAfterComputation(node, prevConsumer) { - setActiveConsumer(prevConsumer); - if (!node || node.producerNode === void 0 || node.producerIndexOfThis === void 0 || node.producerLastReadVersion === void 0) return; - if (consumerIsLive(node)) for (let i = node.nextProducerIndex; i < node.producerNode.length; i++) producerRemoveLiveConsumerAtIndex(node.producerNode[i], node.producerIndexOfThis[i]); - while (node.producerNode.length > node.nextProducerIndex) { - node.producerNode.pop(); - node.producerLastReadVersion.pop(); - node.producerIndexOfThis.pop(); - } + setActiveConsumer(prevConsumer); + if ( + !node || + node.producerNode === void 0 || + node.producerIndexOfThis === void 0 || + node.producerLastReadVersion === void 0 + ) + return; + if (consumerIsLive(node)) + for (let i = node.nextProducerIndex; i < node.producerNode.length; i++) + producerRemoveLiveConsumerAtIndex(node.producerNode[i], node.producerIndexOfThis[i]); + while (node.producerNode.length > node.nextProducerIndex) { + node.producerNode.pop(); + node.producerLastReadVersion.pop(); + node.producerIndexOfThis.pop(); + } } function consumerPollProducersForChange(node) { - assertConsumerNode(node); - for (let i = 0; i < node.producerNode.length; i++) { - const producer = node.producerNode[i]; - const seenVersion = node.producerLastReadVersion[i]; - if (seenVersion !== producer.version) return true; - producerUpdateValueVersion(producer); - if (seenVersion !== producer.version) return true; - } - return false; + assertConsumerNode(node); + for (let i = 0; i < node.producerNode.length; i++) { + const producer = node.producerNode[i]; + const seenVersion = node.producerLastReadVersion[i]; + if (seenVersion !== producer.version) return true; + producerUpdateValueVersion(producer); + if (seenVersion !== producer.version) return true; + } + return false; } function producerAddLiveConsumer(node, consumer, indexOfThis) { - var _a; - assertProducerNode(node); - assertConsumerNode(node); - if (node.liveConsumerNode.length === 0) { - (_a = node.watched) == null || _a.call(node.wrapper); - for (let i = 0; i < node.producerNode.length; i++) node.producerIndexOfThis[i] = producerAddLiveConsumer(node.producerNode[i], node, i); - } - node.liveConsumerIndexOfThis.push(indexOfThis); - return node.liveConsumerNode.push(consumer) - 1; + var _a; + assertProducerNode(node); + assertConsumerNode(node); + if (node.liveConsumerNode.length === 0) { + (_a = node.watched) == null || _a.call(node.wrapper); + for (let i = 0; i < node.producerNode.length; i++) + node.producerIndexOfThis[i] = producerAddLiveConsumer(node.producerNode[i], node, i); + } + node.liveConsumerIndexOfThis.push(indexOfThis); + return node.liveConsumerNode.push(consumer) - 1; } function producerRemoveLiveConsumerAtIndex(node, idx) { - var _a; - assertProducerNode(node); - assertConsumerNode(node); - if (typeof ngDevMode !== "undefined" && ngDevMode && idx >= node.liveConsumerNode.length) throw new Error(`Assertion error: active consumer index ${idx} is out of bounds of ${node.liveConsumerNode.length} consumers)`); - if (node.liveConsumerNode.length === 1) { - (_a = node.unwatched) == null || _a.call(node.wrapper); - for (let i = 0; i < node.producerNode.length; i++) producerRemoveLiveConsumerAtIndex(node.producerNode[i], node.producerIndexOfThis[i]); - } - const lastIdx = node.liveConsumerNode.length - 1; - node.liveConsumerNode[idx] = node.liveConsumerNode[lastIdx]; - node.liveConsumerIndexOfThis[idx] = node.liveConsumerIndexOfThis[lastIdx]; - node.liveConsumerNode.length--; - node.liveConsumerIndexOfThis.length--; - if (idx < node.liveConsumerNode.length) { - const idxProducer = node.liveConsumerIndexOfThis[idx]; - const consumer = node.liveConsumerNode[idx]; - assertConsumerNode(consumer); - consumer.producerIndexOfThis[idxProducer] = idx; - } + var _a; + assertProducerNode(node); + assertConsumerNode(node); + if (typeof ngDevMode !== "undefined" && ngDevMode && idx >= node.liveConsumerNode.length) + throw new Error( + `Assertion error: active consumer index ${idx} is out of bounds of ${node.liveConsumerNode.length} consumers)`, + ); + if (node.liveConsumerNode.length === 1) { + (_a = node.unwatched) == null || _a.call(node.wrapper); + for (let i = 0; i < node.producerNode.length; i++) + producerRemoveLiveConsumerAtIndex(node.producerNode[i], node.producerIndexOfThis[i]); + } + const lastIdx = node.liveConsumerNode.length - 1; + node.liveConsumerNode[idx] = node.liveConsumerNode[lastIdx]; + node.liveConsumerIndexOfThis[idx] = node.liveConsumerIndexOfThis[lastIdx]; + node.liveConsumerNode.length--; + node.liveConsumerIndexOfThis.length--; + if (idx < node.liveConsumerNode.length) { + const idxProducer = node.liveConsumerIndexOfThis[idx]; + const consumer = node.liveConsumerNode[idx]; + assertConsumerNode(consumer); + consumer.producerIndexOfThis[idxProducer] = idx; + } } function consumerIsLive(node) { - var _a; - return node.consumerIsAlwaysLive || (((_a = node == null ? void 0 : node.liveConsumerNode) == null ? void 0 : _a.length) ?? 0) > 0; + var _a; + return ( + node.consumerIsAlwaysLive || + (((_a = node == null ? void 0 : node.liveConsumerNode) == null ? void 0 : _a.length) ?? 0) > 0 + ); } function assertConsumerNode(node) { - node.producerNode ?? (node.producerNode = []); - node.producerIndexOfThis ?? (node.producerIndexOfThis = []); - node.producerLastReadVersion ?? (node.producerLastReadVersion = []); + node.producerNode ?? (node.producerNode = []); + node.producerIndexOfThis ?? (node.producerIndexOfThis = []); + node.producerLastReadVersion ?? (node.producerLastReadVersion = []); } function assertProducerNode(node) { - node.liveConsumerNode ?? (node.liveConsumerNode = []); - node.liveConsumerIndexOfThis ?? (node.liveConsumerIndexOfThis = []); + node.liveConsumerNode ?? (node.liveConsumerNode = []); + node.liveConsumerIndexOfThis ?? (node.liveConsumerIndexOfThis = []); } /** -* @license -* Copyright Google LLC All Rights Reserved. -* -* Use of this source code is governed by an MIT-style license that can be -* found in the LICENSE file at https://angular.io/license -*/ + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ function computedGet(node) { - producerUpdateValueVersion(node); - producerAccessed(node); - if (node.value === ERRORED) throw node.error; - return node.value; + producerUpdateValueVersion(node); + producerAccessed(node); + if (node.value === ERRORED) throw node.error; + return node.value; } function createComputed(computation) { - const node = Object.create(COMPUTED_NODE); - node.computation = computation; - const computed = () => computedGet(node); - computed[SIGNAL] = node; - return computed; + const node = Object.create(COMPUTED_NODE); + node.computation = computation; + const computed = () => computedGet(node); + computed[SIGNAL] = node; + return computed; } const UNSET = /* @__PURE__ */ Symbol("UNSET"); const COMPUTING = /* @__PURE__ */ Symbol("COMPUTING"); const ERRORED = /* @__PURE__ */ Symbol("ERRORED"); const COMPUTED_NODE = { - ...REACTIVE_NODE, - value: UNSET, - dirty: true, - error: null, - equal: defaultEquals, - producerMustRecompute(node) { - return node.value === UNSET || node.value === COMPUTING; - }, - producerRecomputeValue(node) { - if (node.value === COMPUTING) throw new Error("Detected cycle in computations."); - const oldValue = node.value; - node.value = COMPUTING; - const prevConsumer = consumerBeforeComputation(node); - let newValue; - let wasEqual = false; - try { - newValue = node.computation.call(node.wrapper); - wasEqual = oldValue !== UNSET && oldValue !== ERRORED && node.equal.call(node.wrapper, oldValue, newValue); - } catch (err) { - newValue = ERRORED; - node.error = err; - } finally { - consumerAfterComputation(node, prevConsumer); - } - if (wasEqual) { - node.value = oldValue; - return; - } - node.value = newValue; - node.version++; - } + ...REACTIVE_NODE, + value: UNSET, + dirty: true, + error: null, + equal: defaultEquals, + producerMustRecompute(node) { + return node.value === UNSET || node.value === COMPUTING; + }, + producerRecomputeValue(node) { + if (node.value === COMPUTING) throw new Error("Detected cycle in computations."); + const oldValue = node.value; + node.value = COMPUTING; + const prevConsumer = consumerBeforeComputation(node); + let newValue; + let wasEqual = false; + try { + newValue = node.computation.call(node.wrapper); + wasEqual = + oldValue !== UNSET && + oldValue !== ERRORED && + node.equal.call(node.wrapper, oldValue, newValue); + } catch (err) { + newValue = ERRORED; + node.error = err; + } finally { + consumerAfterComputation(node, prevConsumer); + } + if (wasEqual) { + node.value = oldValue; + return; + } + node.value = newValue; + node.version++; + }, }; /** -* @license -* Copyright Google LLC All Rights Reserved. -* -* Use of this source code is governed by an MIT-style license that can be -* found in the LICENSE file at https://angular.io/license -*/ + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ function defaultThrowError() { - throw new Error(); + throw new Error(); } let throwInvalidWriteToSignalErrorFn = defaultThrowError; function throwInvalidWriteToSignalError() { - throwInvalidWriteToSignalErrorFn(); + throwInvalidWriteToSignalErrorFn(); } /** -* @license -* Copyright Google LLC All Rights Reserved. -* -* Use of this source code is governed by an MIT-style license that can be -* found in the LICENSE file at https://angular.io/license -*/ + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ function createSignal(initialValue) { - const node = Object.create(SIGNAL_NODE); - node.value = initialValue; - const getter = () => { - producerAccessed(node); - return node.value; - }; - getter[SIGNAL] = node; - return getter; + const node = Object.create(SIGNAL_NODE); + node.value = initialValue; + const getter = () => { + producerAccessed(node); + return node.value; + }; + getter[SIGNAL] = node; + return getter; } function signalGetFn() { - producerAccessed(this); - return this.value; + producerAccessed(this); + return this.value; } function signalSetFn(node, newValue) { - if (!producerUpdatesAllowed()) throwInvalidWriteToSignalError(); - if (!node.equal.call(node.wrapper, node.value, newValue)) { - node.value = newValue; - signalValueChanged(node); - } + if (!producerUpdatesAllowed()) throwInvalidWriteToSignalError(); + if (!node.equal.call(node.wrapper, node.value, newValue)) { + node.value = newValue; + signalValueChanged(node); + } } const SIGNAL_NODE = { - ...REACTIVE_NODE, - equal: defaultEquals, - value: void 0 + ...REACTIVE_NODE, + equal: defaultEquals, + value: void 0, }; function signalValueChanged(node) { - node.version++; - producerIncrementEpoch(); - producerNotifyConsumers(node); + node.version++; + producerIncrementEpoch(); + producerNotifyConsumers(node); } /** -* @license -* Copyright 2024 Bloomberg Finance L.P. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * @license + * Copyright 2024 Bloomberg Finance L.P. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ const NODE = Symbol("node"); var Signal; ((Signal2) => { - var _a, _brand, _b, _brand2; - class State { - constructor(initialValue, options = {}) { - __privateAdd(this, _brand); - __publicField(this, _a); - const node = createSignal(initialValue)[SIGNAL]; - this[NODE] = node; - node.wrapper = this; - if (options) { - const equals = options.equals; - if (equals) node.equal = equals; - node.watched = options[Signal2.subtle.watched]; - node.unwatched = options[Signal2.subtle.unwatched]; - } - } - get() { - if (!(0, Signal2.isState)(this)) throw new TypeError("Wrong receiver type for Signal.State.prototype.get"); - return signalGetFn.call(this[NODE]); - } - set(newValue) { - if (!(0, Signal2.isState)(this)) throw new TypeError("Wrong receiver type for Signal.State.prototype.set"); - if (isInNotificationPhase()) throw new Error("Writes to signals not permitted during Watcher callback"); - const ref = this[NODE]; - signalSetFn(ref, newValue); - } - } - _a = NODE; - _brand = /* @__PURE__ */ new WeakSet(); - Signal2.isState = (s) => typeof s === "object" && __privateIn(_brand, s); - Signal2.State = State; - class Computed { - constructor(computation, options) { - __privateAdd(this, _brand2); - __publicField(this, _b); - const node = createComputed(computation)[SIGNAL]; - node.consumerAllowSignalWrites = true; - this[NODE] = node; - node.wrapper = this; - if (options) { - const equals = options.equals; - if (equals) node.equal = equals; - node.watched = options[Signal2.subtle.watched]; - node.unwatched = options[Signal2.subtle.unwatched]; - } - } - get() { - if (!(0, Signal2.isComputed)(this)) throw new TypeError("Wrong receiver type for Signal.Computed.prototype.get"); - return computedGet(this[NODE]); - } - } - _b = NODE; - _brand2 = /* @__PURE__ */ new WeakSet(); - Signal2.isComputed = (c) => typeof c === "object" && __privateIn(_brand2, c); - Signal2.Computed = Computed; - ((subtle2) => { - var _a2, _brand3, _assertSignals, assertSignals_fn; - function untrack(cb) { - let output; - let prevActiveConsumer = null; - try { - prevActiveConsumer = setActiveConsumer(null); - output = cb(); - } finally { - setActiveConsumer(prevActiveConsumer); - } - return output; - } - subtle2.untrack = untrack; - function introspectSources(sink) { - var _a3; - if (!(0, Signal2.isComputed)(sink) && !(0, Signal2.isWatcher)(sink)) throw new TypeError("Called introspectSources without a Computed or Watcher argument"); - return ((_a3 = sink[NODE].producerNode) == null ? void 0 : _a3.map((n) => n.wrapper)) ?? []; - } - subtle2.introspectSources = introspectSources; - function introspectSinks(signal) { - var _a3; - if (!(0, Signal2.isComputed)(signal) && !(0, Signal2.isState)(signal)) throw new TypeError("Called introspectSinks without a Signal argument"); - return ((_a3 = signal[NODE].liveConsumerNode) == null ? void 0 : _a3.map((n) => n.wrapper)) ?? []; - } - subtle2.introspectSinks = introspectSinks; - function hasSinks(signal) { - if (!(0, Signal2.isComputed)(signal) && !(0, Signal2.isState)(signal)) throw new TypeError("Called hasSinks without a Signal argument"); - const liveConsumerNode = signal[NODE].liveConsumerNode; - if (!liveConsumerNode) return false; - return liveConsumerNode.length > 0; - } - subtle2.hasSinks = hasSinks; - function hasSources(signal) { - if (!(0, Signal2.isComputed)(signal) && !(0, Signal2.isWatcher)(signal)) throw new TypeError("Called hasSources without a Computed or Watcher argument"); - const producerNode = signal[NODE].producerNode; - if (!producerNode) return false; - return producerNode.length > 0; - } - subtle2.hasSources = hasSources; - class Watcher { - constructor(notify) { - __privateAdd(this, _brand3); - __privateAdd(this, _assertSignals); - __publicField(this, _a2); - let node = Object.create(REACTIVE_NODE); - node.wrapper = this; - node.consumerMarkedDirty = notify; - node.consumerIsAlwaysLive = true; - node.consumerAllowSignalWrites = false; - node.producerNode = []; - this[NODE] = node; - } - watch(...signals) { - if (!(0, Signal2.isWatcher)(this)) throw new TypeError("Called unwatch without Watcher receiver"); - __privateMethod(this, _assertSignals, assertSignals_fn).call(this, signals); - const node = this[NODE]; - node.dirty = false; - const prev = setActiveConsumer(node); - for (const signal of signals) producerAccessed(signal[NODE]); - setActiveConsumer(prev); - } - unwatch(...signals) { - if (!(0, Signal2.isWatcher)(this)) throw new TypeError("Called unwatch without Watcher receiver"); - __privateMethod(this, _assertSignals, assertSignals_fn).call(this, signals); - const node = this[NODE]; - assertConsumerNode(node); - for (let i = node.producerNode.length - 1; i >= 0; i--) if (signals.includes(node.producerNode[i].wrapper)) { - producerRemoveLiveConsumerAtIndex(node.producerNode[i], node.producerIndexOfThis[i]); - const lastIdx = node.producerNode.length - 1; - node.producerNode[i] = node.producerNode[lastIdx]; - node.producerIndexOfThis[i] = node.producerIndexOfThis[lastIdx]; - node.producerNode.length--; - node.producerIndexOfThis.length--; - node.nextProducerIndex--; - if (i < node.producerNode.length) { - const idxConsumer = node.producerIndexOfThis[i]; - const producer = node.producerNode[i]; - assertProducerNode(producer); - producer.liveConsumerIndexOfThis[idxConsumer] = i; - } - } - } - getPending() { - if (!(0, Signal2.isWatcher)(this)) throw new TypeError("Called getPending without Watcher receiver"); - return this[NODE].producerNode.filter((n) => n.dirty).map((n) => n.wrapper); - } - } - _a2 = NODE; - _brand3 = /* @__PURE__ */ new WeakSet(); - _assertSignals = /* @__PURE__ */ new WeakSet(); - assertSignals_fn = function(signals) { - for (const signal of signals) if (!(0, Signal2.isComputed)(signal) && !(0, Signal2.isState)(signal)) throw new TypeError("Called watch/unwatch without a Computed or State argument"); - }; - Signal2.isWatcher = (w) => __privateIn(_brand3, w); - subtle2.Watcher = Watcher; - function currentComputed() { - var _a3; - return (_a3 = getActiveConsumer()) == null ? void 0 : _a3.wrapper; - } - subtle2.currentComputed = currentComputed; - subtle2.watched = Symbol("watched"); - subtle2.unwatched = Symbol("unwatched"); - })(Signal2.subtle || (Signal2.subtle = {})); + var _a, _brand, _b, _brand2; + class State { + constructor(initialValue, options = {}) { + __privateAdd(this, _brand); + __publicField(this, _a); + const node = createSignal(initialValue)[SIGNAL]; + this[NODE] = node; + node.wrapper = this; + if (options) { + const equals = options.equals; + if (equals) node.equal = equals; + node.watched = options[Signal2.subtle.watched]; + node.unwatched = options[Signal2.subtle.unwatched]; + } + } + get() { + if (!(0, Signal2.isState)(this)) + throw new TypeError("Wrong receiver type for Signal.State.prototype.get"); + return signalGetFn.call(this[NODE]); + } + set(newValue) { + if (!(0, Signal2.isState)(this)) + throw new TypeError("Wrong receiver type for Signal.State.prototype.set"); + if (isInNotificationPhase()) + throw new Error("Writes to signals not permitted during Watcher callback"); + const ref = this[NODE]; + signalSetFn(ref, newValue); + } + } + _a = NODE; + _brand = /* @__PURE__ */ new WeakSet(); + Signal2.isState = (s) => typeof s === "object" && __privateIn(_brand, s); + Signal2.State = State; + class Computed { + constructor(computation, options) { + __privateAdd(this, _brand2); + __publicField(this, _b); + const node = createComputed(computation)[SIGNAL]; + node.consumerAllowSignalWrites = true; + this[NODE] = node; + node.wrapper = this; + if (options) { + const equals = options.equals; + if (equals) node.equal = equals; + node.watched = options[Signal2.subtle.watched]; + node.unwatched = options[Signal2.subtle.unwatched]; + } + } + get() { + if (!(0, Signal2.isComputed)(this)) + throw new TypeError("Wrong receiver type for Signal.Computed.prototype.get"); + return computedGet(this[NODE]); + } + } + _b = NODE; + _brand2 = /* @__PURE__ */ new WeakSet(); + Signal2.isComputed = (c) => typeof c === "object" && __privateIn(_brand2, c); + Signal2.Computed = Computed; + ((subtle2) => { + var _a2, _brand3, _assertSignals, assertSignals_fn; + function untrack(cb) { + let output; + let prevActiveConsumer = null; + try { + prevActiveConsumer = setActiveConsumer(null); + output = cb(); + } finally { + setActiveConsumer(prevActiveConsumer); + } + return output; + } + subtle2.untrack = untrack; + function introspectSources(sink) { + var _a3; + if (!(0, Signal2.isComputed)(sink) && !(0, Signal2.isWatcher)(sink)) + throw new TypeError("Called introspectSources without a Computed or Watcher argument"); + return ((_a3 = sink[NODE].producerNode) == null ? void 0 : _a3.map((n) => n.wrapper)) ?? []; + } + subtle2.introspectSources = introspectSources; + function introspectSinks(signal) { + var _a3; + if (!(0, Signal2.isComputed)(signal) && !(0, Signal2.isState)(signal)) + throw new TypeError("Called introspectSinks without a Signal argument"); + return ( + ((_a3 = signal[NODE].liveConsumerNode) == null ? void 0 : _a3.map((n) => n.wrapper)) ?? [] + ); + } + subtle2.introspectSinks = introspectSinks; + function hasSinks(signal) { + if (!(0, Signal2.isComputed)(signal) && !(0, Signal2.isState)(signal)) + throw new TypeError("Called hasSinks without a Signal argument"); + const liveConsumerNode = signal[NODE].liveConsumerNode; + if (!liveConsumerNode) return false; + return liveConsumerNode.length > 0; + } + subtle2.hasSinks = hasSinks; + function hasSources(signal) { + if (!(0, Signal2.isComputed)(signal) && !(0, Signal2.isWatcher)(signal)) + throw new TypeError("Called hasSources without a Computed or Watcher argument"); + const producerNode = signal[NODE].producerNode; + if (!producerNode) return false; + return producerNode.length > 0; + } + subtle2.hasSources = hasSources; + class Watcher { + constructor(notify) { + __privateAdd(this, _brand3); + __privateAdd(this, _assertSignals); + __publicField(this, _a2); + let node = Object.create(REACTIVE_NODE); + node.wrapper = this; + node.consumerMarkedDirty = notify; + node.consumerIsAlwaysLive = true; + node.consumerAllowSignalWrites = false; + node.producerNode = []; + this[NODE] = node; + } + watch(...signals) { + if (!(0, Signal2.isWatcher)(this)) + throw new TypeError("Called unwatch without Watcher receiver"); + __privateMethod(this, _assertSignals, assertSignals_fn).call(this, signals); + const node = this[NODE]; + node.dirty = false; + const prev = setActiveConsumer(node); + for (const signal of signals) producerAccessed(signal[NODE]); + setActiveConsumer(prev); + } + unwatch(...signals) { + if (!(0, Signal2.isWatcher)(this)) + throw new TypeError("Called unwatch without Watcher receiver"); + __privateMethod(this, _assertSignals, assertSignals_fn).call(this, signals); + const node = this[NODE]; + assertConsumerNode(node); + for (let i = node.producerNode.length - 1; i >= 0; i--) + if (signals.includes(node.producerNode[i].wrapper)) { + producerRemoveLiveConsumerAtIndex(node.producerNode[i], node.producerIndexOfThis[i]); + const lastIdx = node.producerNode.length - 1; + node.producerNode[i] = node.producerNode[lastIdx]; + node.producerIndexOfThis[i] = node.producerIndexOfThis[lastIdx]; + node.producerNode.length--; + node.producerIndexOfThis.length--; + node.nextProducerIndex--; + if (i < node.producerNode.length) { + const idxConsumer = node.producerIndexOfThis[i]; + const producer = node.producerNode[i]; + assertProducerNode(producer); + producer.liveConsumerIndexOfThis[idxConsumer] = i; + } + } + } + getPending() { + if (!(0, Signal2.isWatcher)(this)) + throw new TypeError("Called getPending without Watcher receiver"); + return this[NODE].producerNode.filter((n) => n.dirty).map((n) => n.wrapper); + } + } + _a2 = NODE; + _brand3 = /* @__PURE__ */ new WeakSet(); + _assertSignals = /* @__PURE__ */ new WeakSet(); + assertSignals_fn = function (signals) { + for (const signal of signals) + if (!(0, Signal2.isComputed)(signal) && !(0, Signal2.isState)(signal)) + throw new TypeError("Called watch/unwatch without a Computed or State argument"); + }; + Signal2.isWatcher = (w) => __privateIn(_brand3, w); + subtle2.Watcher = Watcher; + function currentComputed() { + var _a3; + return (_a3 = getActiveConsumer()) == null ? void 0 : _a3.wrapper; + } + subtle2.currentComputed = currentComputed; + subtle2.watched = Symbol("watched"); + subtle2.unwatched = Symbol("unwatched"); + })(Signal2.subtle || (Signal2.subtle = {})); })(Signal || (Signal = {})); /** -* equality check here is always false so that we can dirty the storage -* via setting to _anything_ -* -* -* This is for a pattern where we don't *directly* use signals to back the values used in collections -* so that instanceof checks and getters and other native features "just work" without having -* to do nested proxying. -* -* (though, see deep.ts for nested / deep behavior) -*/ + * equality check here is always false so that we can dirty the storage + * via setting to _anything_ + * + * + * This is for a pattern where we don't *directly* use signals to back the values used in collections + * so that instanceof checks and getters and other native features "just work" without having + * to do nested proxying. + * + * (though, see deep.ts for nested / deep behavior) + */ const createStorage = (initial = null) => new Signal.State(initial, { equals: () => false }); const ARRAY_GETTER_METHODS = new Set([ - Symbol.iterator, - "concat", - "entries", - "every", - "filter", - "find", - "findIndex", - "flat", - "flatMap", - "forEach", - "includes", - "indexOf", - "join", - "keys", - "lastIndexOf", - "map", - "reduce", - "reduceRight", - "slice", - "some", - "values" -]); -const ARRAY_WRITE_THEN_READ_METHODS = new Set([ - "fill", - "push", - "unshift" + Symbol.iterator, + "concat", + "entries", + "every", + "filter", + "find", + "findIndex", + "flat", + "flatMap", + "forEach", + "includes", + "indexOf", + "join", + "keys", + "lastIndexOf", + "map", + "reduce", + "reduceRight", + "slice", + "some", + "values", ]); +const ARRAY_WRITE_THEN_READ_METHODS = new Set(["fill", "push", "unshift"]); function convertToInt(prop) { - if (typeof prop === "symbol") return null; - const num = Number(prop); - if (isNaN(num)) return null; - return num % 1 === 0 ? num : null; + if (typeof prop === "symbol") return null; + const num = Number(prop); + if (isNaN(num)) return null; + return num % 1 === 0 ? num : null; } var SignalArray = class SignalArray { - /** - * Creates an array from an iterable object. - * @param iterable An iterable object to convert to an array. - */ - /** - * Creates an array from an iterable object. - * @param iterable An iterable object to convert to an array. - * @param mapfn A mapping function to call on every element of the array. - * @param thisArg Value of 'this' used to invoke the mapfn. - */ - static from(iterable, mapfn, thisArg) { - return mapfn ? new SignalArray(Array.from(iterable, mapfn, thisArg)) : new SignalArray(Array.from(iterable)); - } - static of(...arr) { - return new SignalArray(arr); - } - constructor(arr = []) { - let clone = arr.slice(); - let self = this; - let boundFns = /* @__PURE__ */ new Map(); - /** + /** + * Creates an array from an iterable object. + * @param iterable An iterable object to convert to an array. + */ + /** + * Creates an array from an iterable object. + * @param iterable An iterable object to convert to an array. + * @param mapfn A mapping function to call on every element of the array. + * @param thisArg Value of 'this' used to invoke the mapfn. + */ + static from(iterable, mapfn, thisArg) { + return mapfn + ? new SignalArray(Array.from(iterable, mapfn, thisArg)) + : new SignalArray(Array.from(iterable)); + } + static of(...arr) { + return new SignalArray(arr); + } + constructor(arr = []) { + let clone = arr.slice(); + let self = this; + let boundFns = /* @__PURE__ */ new Map(); + /** Flag to track whether we have *just* intercepted a call to `.push()` or `.unshift()`, since in those cases (and only those cases!) the `Array` itself checks `.length` to return from the function call. */ - let nativelyAccessingLengthFromPushOrUnshift = false; - return new Proxy(clone, { - get(target, prop) { - let index = convertToInt(prop); - if (index !== null) { - self.#readStorageFor(index); - self.#collection.get(); - return target[index]; - } - if (prop === "length") { - if (nativelyAccessingLengthFromPushOrUnshift) nativelyAccessingLengthFromPushOrUnshift = false; - else self.#collection.get(); - return target[prop]; - } - if (ARRAY_WRITE_THEN_READ_METHODS.has(prop)) nativelyAccessingLengthFromPushOrUnshift = true; - if (ARRAY_GETTER_METHODS.has(prop)) { - let fn = boundFns.get(prop); - if (fn === void 0) { - fn = (...args) => { - self.#collection.get(); - return target[prop](...args); - }; - boundFns.set(prop, fn); - } - return fn; - } - return target[prop]; - }, - set(target, prop, value) { - target[prop] = value; - let index = convertToInt(prop); - if (index !== null) { - self.#dirtyStorageFor(index); - self.#collection.set(null); - } else if (prop === "length") self.#collection.set(null); - return true; - }, - getPrototypeOf() { - return SignalArray.prototype; - } - }); - } - #collection = createStorage(); - #storages = /* @__PURE__ */ new Map(); - #readStorageFor(index) { - let storage = this.#storages.get(index); - if (storage === void 0) { - storage = createStorage(); - this.#storages.set(index, storage); - } - storage.get(); - } - #dirtyStorageFor(index) { - const storage = this.#storages.get(index); - if (storage) storage.set(null); - } + let nativelyAccessingLengthFromPushOrUnshift = false; + return new Proxy(clone, { + get(target, prop) { + let index = convertToInt(prop); + if (index !== null) { + self.#readStorageFor(index); + self.#collection.get(); + return target[index]; + } + if (prop === "length") { + if (nativelyAccessingLengthFromPushOrUnshift) + nativelyAccessingLengthFromPushOrUnshift = false; + else self.#collection.get(); + return target[prop]; + } + if (ARRAY_WRITE_THEN_READ_METHODS.has(prop)) + nativelyAccessingLengthFromPushOrUnshift = true; + if (ARRAY_GETTER_METHODS.has(prop)) { + let fn = boundFns.get(prop); + if (fn === void 0) { + fn = (...args) => { + self.#collection.get(); + return target[prop](...args); + }; + boundFns.set(prop, fn); + } + return fn; + } + return target[prop]; + }, + set(target, prop, value) { + target[prop] = value; + let index = convertToInt(prop); + if (index !== null) { + self.#dirtyStorageFor(index); + self.#collection.set(null); + } else if (prop === "length") self.#collection.set(null); + return true; + }, + getPrototypeOf() { + return SignalArray.prototype; + }, + }); + } + #collection = createStorage(); + #storages = /* @__PURE__ */ new Map(); + #readStorageFor(index) { + let storage = this.#storages.get(index); + if (storage === void 0) { + storage = createStorage(); + this.#storages.set(index, storage); + } + storage.get(); + } + #dirtyStorageFor(index) { + const storage = this.#storages.get(index); + if (storage) storage.set(null); + } }; Object.setPrototypeOf(SignalArray.prototype, Array.prototype); var SignalMap = class { - collection = createStorage(); - storages = /* @__PURE__ */ new Map(); - vals; - readStorageFor(key) { - const { storages } = this; - let storage = storages.get(key); - if (storage === void 0) { - storage = createStorage(); - storages.set(key, storage); - } - storage.get(); - } - dirtyStorageFor(key) { - const storage = this.storages.get(key); - if (storage) storage.set(null); - } - constructor(existing) { - this.vals = existing ? new Map(existing) : /* @__PURE__ */ new Map(); - } - get(key) { - this.readStorageFor(key); - return this.vals.get(key); - } - has(key) { - this.readStorageFor(key); - return this.vals.has(key); - } - entries() { - this.collection.get(); - return this.vals.entries(); - } - keys() { - this.collection.get(); - return this.vals.keys(); - } - values() { - this.collection.get(); - return this.vals.values(); - } - forEach(fn) { - this.collection.get(); - this.vals.forEach(fn); - } - get size() { - this.collection.get(); - return this.vals.size; - } - [Symbol.iterator]() { - this.collection.get(); - return this.vals[Symbol.iterator](); - } - get [Symbol.toStringTag]() { - return this.vals[Symbol.toStringTag]; - } - set(key, value) { - this.dirtyStorageFor(key); - this.collection.set(null); - this.vals.set(key, value); - return this; - } - delete(key) { - this.dirtyStorageFor(key); - this.collection.set(null); - return this.vals.delete(key); - } - clear() { - this.storages.forEach((s) => s.set(null)); - this.collection.set(null); - this.vals.clear(); - } + collection = createStorage(); + storages = /* @__PURE__ */ new Map(); + vals; + readStorageFor(key) { + const { storages } = this; + let storage = storages.get(key); + if (storage === void 0) { + storage = createStorage(); + storages.set(key, storage); + } + storage.get(); + } + dirtyStorageFor(key) { + const storage = this.storages.get(key); + if (storage) storage.set(null); + } + constructor(existing) { + this.vals = existing ? new Map(existing) : /* @__PURE__ */ new Map(); + } + get(key) { + this.readStorageFor(key); + return this.vals.get(key); + } + has(key) { + this.readStorageFor(key); + return this.vals.has(key); + } + entries() { + this.collection.get(); + return this.vals.entries(); + } + keys() { + this.collection.get(); + return this.vals.keys(); + } + values() { + this.collection.get(); + return this.vals.values(); + } + forEach(fn) { + this.collection.get(); + this.vals.forEach(fn); + } + get size() { + this.collection.get(); + return this.vals.size; + } + [Symbol.iterator]() { + this.collection.get(); + return this.vals[Symbol.iterator](); + } + get [Symbol.toStringTag]() { + return this.vals[Symbol.toStringTag]; + } + set(key, value) { + this.dirtyStorageFor(key); + this.collection.set(null); + this.vals.set(key, value); + return this; + } + delete(key) { + this.dirtyStorageFor(key); + this.collection.set(null); + return this.vals.delete(key); + } + clear() { + this.storages.forEach((s) => s.set(null)); + this.collection.set(null); + this.vals.clear(); + } }; Object.setPrototypeOf(SignalMap.prototype, Map.prototype); /** -* Create a reactive Object, backed by Signals, using a Proxy. -* This allows dynamic creation and deletion of signals using the object primitive -* APIs that most folks are familiar with -- the only difference is instantiation. -* ```js -* const obj = new SignalObject({ foo: 123 }); -* -* obj.foo // 123 -* obj.foo = 456 -* obj.foo // 456 -* obj.bar = 2 -* obj.bar // 2 -* ``` -*/ + * Create a reactive Object, backed by Signals, using a Proxy. + * This allows dynamic creation and deletion of signals using the object primitive + * APIs that most folks are familiar with -- the only difference is instantiation. + * ```js + * const obj = new SignalObject({ foo: 123 }); + * + * obj.foo // 123 + * obj.foo = 456 + * obj.foo // 456 + * obj.bar = 2 + * obj.bar // 2 + * ``` + */ const SignalObject = class SignalObjectImpl { - static fromEntries(entries) { - return new SignalObjectImpl(Object.fromEntries(entries)); - } - #storages = /* @__PURE__ */ new Map(); - #collection = createStorage(); - constructor(obj = {}) { - let proto = Object.getPrototypeOf(obj); - let descs = Object.getOwnPropertyDescriptors(obj); - let clone = Object.create(proto); - for (let prop in descs) Object.defineProperty(clone, prop, descs[prop]); - let self = this; - return new Proxy(clone, { - get(target, prop, receiver) { - self.#readStorageFor(prop); - return Reflect.get(target, prop, receiver); - }, - has(target, prop) { - self.#readStorageFor(prop); - return prop in target; - }, - ownKeys(target) { - self.#collection.get(); - return Reflect.ownKeys(target); - }, - set(target, prop, value, receiver) { - let result = Reflect.set(target, prop, value, receiver); - self.#dirtyStorageFor(prop); - self.#dirtyCollection(); - return result; - }, - deleteProperty(target, prop) { - if (prop in target) { - delete target[prop]; - self.#dirtyStorageFor(prop); - self.#dirtyCollection(); - } - return true; - }, - getPrototypeOf() { - return SignalObjectImpl.prototype; - } - }); - } - #readStorageFor(key) { - let storage = this.#storages.get(key); - if (storage === void 0) { - storage = createStorage(); - this.#storages.set(key, storage); - } - storage.get(); - } - #dirtyStorageFor(key) { - const storage = this.#storages.get(key); - if (storage) storage.set(null); - } - #dirtyCollection() { - this.#collection.set(null); - } -}; -var SignalSet = class { - collection = createStorage(); - storages = /* @__PURE__ */ new Map(); - vals; - storageFor(key) { - const storages = this.storages; - let storage = storages.get(key); - if (storage === void 0) { - storage = createStorage(); - storages.set(key, storage); - } - return storage; - } - dirtyStorageFor(key) { - const storage = this.storages.get(key); - if (storage) storage.set(null); - } - constructor(existing) { - this.vals = new Set(existing); - } - has(value) { - this.storageFor(value).get(); - return this.vals.has(value); - } - entries() { - this.collection.get(); - return this.vals.entries(); - } - keys() { - this.collection.get(); - return this.vals.keys(); - } - values() { - this.collection.get(); - return this.vals.values(); - } - forEach(fn) { - this.collection.get(); - this.vals.forEach(fn); - } - get size() { - this.collection.get(); - return this.vals.size; - } - [Symbol.iterator]() { - this.collection.get(); - return this.vals[Symbol.iterator](); - } - get [Symbol.toStringTag]() { - return this.vals[Symbol.toStringTag]; - } - add(value) { - this.dirtyStorageFor(value); - this.collection.set(null); - this.vals.add(value); - return this; - } - delete(value) { - this.dirtyStorageFor(value); - this.collection.set(null); - return this.vals.delete(value); - } - clear() { - this.storages.forEach((s) => s.set(null)); - this.collection.set(null); - this.vals.clear(); - } -}; + static fromEntries(entries) { + return new SignalObjectImpl(Object.fromEntries(entries)); + } + #storages = /* @__PURE__ */ new Map(); + #collection = createStorage(); + constructor(obj = {}) { + let proto = Object.getPrototypeOf(obj); + let descs = Object.getOwnPropertyDescriptors(obj); + let clone = Object.create(proto); + for (let prop in descs) Object.defineProperty(clone, prop, descs[prop]); + let self = this; + return new Proxy(clone, { + get(target, prop, receiver) { + self.#readStorageFor(prop); + return Reflect.get(target, prop, receiver); + }, + has(target, prop) { + self.#readStorageFor(prop); + return prop in target; + }, + ownKeys(target) { + self.#collection.get(); + return Reflect.ownKeys(target); + }, + set(target, prop, value, receiver) { + let result = Reflect.set(target, prop, value, receiver); + self.#dirtyStorageFor(prop); + self.#dirtyCollection(); + return result; + }, + deleteProperty(target, prop) { + if (prop in target) { + delete target[prop]; + self.#dirtyStorageFor(prop); + self.#dirtyCollection(); + } + return true; + }, + getPrototypeOf() { + return SignalObjectImpl.prototype; + }, + }); + } + #readStorageFor(key) { + let storage = this.#storages.get(key); + if (storage === void 0) { + storage = createStorage(); + this.#storages.set(key, storage); + } + storage.get(); + } + #dirtyStorageFor(key) { + const storage = this.#storages.get(key); + if (storage) storage.set(null); + } + #dirtyCollection() { + this.#collection.set(null); + } +}; +var SignalSet = class { + collection = createStorage(); + storages = /* @__PURE__ */ new Map(); + vals; + storageFor(key) { + const storages = this.storages; + let storage = storages.get(key); + if (storage === void 0) { + storage = createStorage(); + storages.set(key, storage); + } + return storage; + } + dirtyStorageFor(key) { + const storage = this.storages.get(key); + if (storage) storage.set(null); + } + constructor(existing) { + this.vals = new Set(existing); + } + has(value) { + this.storageFor(value).get(); + return this.vals.has(value); + } + entries() { + this.collection.get(); + return this.vals.entries(); + } + keys() { + this.collection.get(); + return this.vals.keys(); + } + values() { + this.collection.get(); + return this.vals.values(); + } + forEach(fn) { + this.collection.get(); + this.vals.forEach(fn); + } + get size() { + this.collection.get(); + return this.vals.size; + } + [Symbol.iterator]() { + this.collection.get(); + return this.vals[Symbol.iterator](); + } + get [Symbol.toStringTag]() { + return this.vals[Symbol.toStringTag]; + } + add(value) { + this.dirtyStorageFor(value); + this.collection.set(null); + this.vals.add(value); + return this; + } + delete(value) { + this.dirtyStorageFor(value); + this.collection.set(null); + return this.vals.delete(value); + } + clear() { + this.storages.forEach((s) => s.set(null)); + this.collection.set(null); + this.vals.clear(); + } +}; Object.setPrototypeOf(SignalSet.prototype, Set.prototype); function create() { - return new A2uiMessageProcessor({ - arrayCtor: SignalArray, - mapCtor: SignalMap, - objCtor: SignalObject, - setCtor: SignalSet - }); + return new A2uiMessageProcessor({ + arrayCtor: SignalArray, + mapCtor: SignalMap, + objCtor: SignalObject, + setCtor: SignalSet, + }); } const Data = { - createSignalA2uiMessageProcessor: create, - A2uiMessageProcessor, - Guards: guards_exports + createSignalA2uiMessageProcessor: create, + A2uiMessageProcessor, + Guards: guards_exports, }; /** -* @license -* Copyright 2017 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ + * @license + * Copyright 2017 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ const t$1 = (t) => (e, o) => { - void 0 !== o ? o.addInitializer(() => { - customElements.define(t, e); - }) : customElements.define(t, e); + void 0 !== o + ? o.addInitializer(() => { + customElements.define(t, e); + }) + : customElements.define(t, e); }; /** -* @license -* Copyright 2017 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ const o$9 = { - attribute: !0, - type: String, - converter: u$3, - reflect: !1, - hasChanged: f$3 -}, r$7 = (t = o$9, e, r) => { - const { kind: n, metadata: i } = r; - let s = globalThis.litPropertyMetadata.get(i); - if (void 0 === s && globalThis.litPropertyMetadata.set(i, s = /* @__PURE__ */ new Map()), "setter" === n && ((t = Object.create(t)).wrapped = !0), s.set(r.name, t), "accessor" === n) { - const { name: o } = r; - return { - set(r) { - const n = e.get.call(this); - e.set.call(this, r), this.requestUpdate(o, n, t, !0, r); - }, - init(e) { - return void 0 !== e && this.C(o, void 0, t, e), e; - } - }; - } - if ("setter" === n) { - const { name: o } = r; - return function(r) { - const n = this[o]; - e.call(this, r), this.requestUpdate(o, n, t, !0, r); - }; - } - throw Error("Unsupported decorator location: " + n); -}; + * @license + * Copyright 2017 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ const o$9 = { + attribute: !0, + type: String, + converter: u$3, + reflect: !1, + hasChanged: f$3, + }, + r$7 = (t = o$9, e, r) => { + const { kind: n, metadata: i } = r; + let s = globalThis.litPropertyMetadata.get(i); + if ( + (void 0 === s && globalThis.litPropertyMetadata.set(i, (s = /* @__PURE__ */ new Map())), + "setter" === n && ((t = Object.create(t)).wrapped = !0), + s.set(r.name, t), + "accessor" === n) + ) { + const { name: o } = r; + return { + set(r) { + const n = e.get.call(this); + (e.set.call(this, r), this.requestUpdate(o, n, t, !0, r)); + }, + init(e) { + return (void 0 !== e && this.C(o, void 0, t, e), e); + }, + }; + } + if ("setter" === n) { + const { name: o } = r; + return function (r) { + const n = this[o]; + (e.call(this, r), this.requestUpdate(o, n, t, !0, r)); + }; + } + throw Error("Unsupported decorator location: " + n); + }; function n$6(t) { - return (e, o) => "object" == typeof o ? r$7(t, e, o) : ((t, e, o) => { - const r = e.hasOwnProperty(o); - return e.constructor.createProperty(o, t), r ? Object.getOwnPropertyDescriptor(e, o) : void 0; - })(t, e, o); + return (e, o) => + "object" == typeof o + ? r$7(t, e, o) + : ((t, e, o) => { + const r = e.hasOwnProperty(o); + return ( + e.constructor.createProperty(o, t), r ? Object.getOwnPropertyDescriptor(e, o) : void 0 + ); + })(t, e, o); } /** -* @license -* Copyright 2017 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ function r$6(r) { - return n$6({ - ...r, - state: !0, - attribute: !1 - }); + * @license + * Copyright 2017 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ function r$6(r) { + return n$6({ + ...r, + state: !0, + attribute: !1, + }); } /** -* @license -* Copyright 2017 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ -const e$6 = (e, t, c) => (c.configurable = !0, c.enumerable = !0, Reflect.decorate && "object" != typeof t && Object.defineProperty(e, t, c), c); + * @license + * Copyright 2017 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ +const e$6 = (e, t, c) => ( + (c.configurable = !0), + (c.enumerable = !0), + Reflect.decorate && "object" != typeof t && Object.defineProperty(e, t, c), + c +); /** -* @license -* Copyright 2017 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ function e$5(e, r) { - return (n, s, i) => { - const o = (t) => t.renderRoot?.querySelector(e) ?? null; - if (r) { - const { get: e, set: r } = "object" == typeof s ? n : i ?? (() => { - const t = Symbol(); - return { - get() { - return this[t]; - }, - set(e) { - this[t] = e; - } - }; - })(); - return e$6(n, s, { get() { - let t = e.call(this); - return void 0 === t && (t = o(this), (null !== t || this.hasUpdated) && r.call(this, t)), t; - } }); - } - return e$6(n, s, { get() { - return o(this); - } }); - }; + * @license + * Copyright 2017 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ function e$5(e, r) { + return (n, s, i) => { + const o = (t) => t.renderRoot?.querySelector(e) ?? null; + if (r) { + const { get: e, set: r } = + "object" == typeof s + ? n + : (i ?? + (() => { + const t = Symbol(); + return { + get() { + return this[t]; + }, + set(e) { + this[t] = e; + }, + }; + })()); + return e$6(n, s, { + get() { + let t = e.call(this); + return ( + void 0 === t && ((t = o(this)), (null !== t || this.hasUpdated) && r.call(this, t)), t + ); + }, + }); + } + return e$6(n, s, { + get() { + return o(this); + }, + }); + }; } /** -* @license -* Copyright 2023 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ let i$2 = !1; + * @license + * Copyright 2023 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ let i$2 = !1; const s$1 = new Signal.subtle.Watcher(() => { - i$2 || (i$2 = !0, queueMicrotask(() => { - i$2 = !1; - for (const t of s$1.getPending()) t.get(); - s$1.watch(); - })); -}), h$3 = Symbol("SignalWatcherBrand"), e$3 = new FinalizationRegistry((i) => { - i.unwatch(...Signal.subtle.introspectSources(i)); -}), n$4 = /* @__PURE__ */ new WeakMap(); + i$2 || + ((i$2 = !0), + queueMicrotask(() => { + i$2 = !1; + for (const t of s$1.getPending()) t.get(); + s$1.watch(); + })); + }), + h$3 = Symbol("SignalWatcherBrand"), + e$3 = new FinalizationRegistry((i) => { + i.unwatch(...Signal.subtle.introspectSources(i)); + }), + n$4 = /* @__PURE__ */ new WeakMap(); function o$7(i) { - return !0 === i[h$3] ? (console.warn("SignalWatcher should not be applied to the same class more than once."), i) : class extends i { - constructor() { - super(...arguments), this._$St = /* @__PURE__ */ new Map(), this._$So = new Signal.State(0), this._$Si = !1; - } - _$Sl() { - var t, i; - const s = [], h = []; - this._$St.forEach((t, i) => { - ((null == t ? void 0 : t.beforeUpdate) ? s : h).push(i); - }); - const e = null === (t = this.h) || void 0 === t ? void 0 : t.getPending().filter((t) => t !== this._$Su && !this._$St.has(t)); - s.forEach((t) => t.get()), null === (i = this._$Su) || void 0 === i || i.get(), e.forEach((t) => t.get()), h.forEach((t) => t.get()); - } - _$Sv() { - this.isUpdatePending || queueMicrotask(() => { - this.isUpdatePending || this._$Sl(); - }); - } - _$S_() { - if (void 0 !== this.h) return; - this._$Su = new Signal.Computed(() => { - this._$So.get(), super.performUpdate(); - }); - const i = this.h = new Signal.subtle.Watcher(function() { - const t = n$4.get(this); - void 0 !== t && (!1 === t._$Si && (new Set(this.getPending()).has(t._$Su) ? t.requestUpdate() : t._$Sv()), this.watch()); - }); - n$4.set(i, this), e$3.register(this, i), i.watch(this._$Su), i.watch(...Array.from(this._$St).map(([t]) => t)); - } - _$Sp() { - if (void 0 === this.h) return; - let i = !1; - this.h.unwatch(...Signal.subtle.introspectSources(this.h).filter((t) => { - var s; - const h = !0 !== (null === (s = this._$St.get(t)) || void 0 === s ? void 0 : s.manualDispose); - return h && this._$St.delete(t), i || (i = !h), h; - })), i || (this._$Su = void 0, this.h = void 0, this._$St.clear()); - } - updateEffect(i, s) { - var h; - this._$S_(); - const e = new Signal.Computed(() => { - i(); - }); - return this.h.watch(e), this._$St.set(e, s), null !== (h = null == s ? void 0 : s.beforeUpdate) && void 0 !== h && h ? Signal.subtle.untrack(() => e.get()) : this.updateComplete.then(() => Signal.subtle.untrack(() => e.get())), () => { - this._$St.delete(e), this.h.unwatch(e), !1 === this.isConnected && this._$Sp(); - }; - } - performUpdate() { - this.isUpdatePending && (this._$S_(), this._$Si = !0, this._$So.set(this._$So.get() + 1), this._$Si = !1, this._$Sl()); - } - connectedCallback() { - super.connectedCallback(), this.requestUpdate(); - } - disconnectedCallback() { - super.disconnectedCallback(), queueMicrotask(() => { - !1 === this.isConnected && this._$Sp(); - }); - } - }; + return !0 === i[h$3] + ? (console.warn("SignalWatcher should not be applied to the same class more than once."), i) + : class extends i { + constructor() { + (super(...arguments), + (this._$St = /* @__PURE__ */ new Map()), + (this._$So = new Signal.State(0)), + (this._$Si = !1)); + } + _$Sl() { + var t, i; + const s = [], + h = []; + this._$St.forEach((t, i) => { + ((null == t ? void 0 : t.beforeUpdate) ? s : h).push(i); + }); + const e = + null === (t = this.h) || void 0 === t + ? void 0 + : t.getPending().filter((t) => t !== this._$Su && !this._$St.has(t)); + (s.forEach((t) => t.get()), + null === (i = this._$Su) || void 0 === i || i.get(), + e.forEach((t) => t.get()), + h.forEach((t) => t.get())); + } + _$Sv() { + this.isUpdatePending || + queueMicrotask(() => { + this.isUpdatePending || this._$Sl(); + }); + } + _$S_() { + if (void 0 !== this.h) return; + this._$Su = new Signal.Computed(() => { + (this._$So.get(), super.performUpdate()); + }); + const i = (this.h = new Signal.subtle.Watcher(function () { + const t = n$4.get(this); + void 0 !== t && + (!1 === t._$Si && + (new Set(this.getPending()).has(t._$Su) ? t.requestUpdate() : t._$Sv()), + this.watch()); + })); + (n$4.set(i, this), + e$3.register(this, i), + i.watch(this._$Su), + i.watch(...Array.from(this._$St).map(([t]) => t))); + } + _$Sp() { + if (void 0 === this.h) return; + let i = !1; + (this.h.unwatch( + ...Signal.subtle.introspectSources(this.h).filter((t) => { + var s; + const h = + !0 !== (null === (s = this._$St.get(t)) || void 0 === s ? void 0 : s.manualDispose); + return (h && this._$St.delete(t), i || (i = !h), h); + }), + ), + i || ((this._$Su = void 0), (this.h = void 0), this._$St.clear())); + } + updateEffect(i, s) { + var h; + this._$S_(); + const e = new Signal.Computed(() => { + i(); + }); + return ( + this.h.watch(e), + this._$St.set(e, s), + null !== (h = null == s ? void 0 : s.beforeUpdate) && void 0 !== h && h + ? Signal.subtle.untrack(() => e.get()) + : this.updateComplete.then(() => Signal.subtle.untrack(() => e.get())), + () => { + (this._$St.delete(e), this.h.unwatch(e), !1 === this.isConnected && this._$Sp()); + } + ); + } + performUpdate() { + this.isUpdatePending && + (this._$S_(), + (this._$Si = !0), + this._$So.set(this._$So.get() + 1), + (this._$Si = !1), + this._$Sl()); + } + connectedCallback() { + (super.connectedCallback(), this.requestUpdate()); + } + disconnectedCallback() { + (super.disconnectedCallback(), + queueMicrotask(() => { + !1 === this.isConnected && this._$Sp(); + })); + } + }; } /** -* @license -* Copyright 2017 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ const s = (i, t) => { - const e = i._$AN; - if (void 0 === e) return !1; - for (const i of e) i._$AO?.(t, !1), s(i, t); - return !0; -}, o$6 = (i) => { - let t, e; - do { - if (void 0 === (t = i._$AM)) break; - e = t._$AN, e.delete(i), i = t; - } while (0 === e?.size); -}, r$3 = (i) => { - for (let t; t = i._$AM; i = t) { - let e = t._$AN; - if (void 0 === e) t._$AN = e = /* @__PURE__ */ new Set(); - else if (e.has(i)) break; - e.add(i), c(t); - } -}; + * @license + * Copyright 2017 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ const s = (i, t) => { + const e = i._$AN; + if (void 0 === e) return !1; + for (const i of e) (i._$AO?.(t, !1), s(i, t)); + return !0; + }, + o$6 = (i) => { + let t, e; + do { + if (void 0 === (t = i._$AM)) break; + ((e = t._$AN), e.delete(i), (i = t)); + } while (0 === e?.size); + }, + r$3 = (i) => { + for (let t; (t = i._$AM); i = t) { + let e = t._$AN; + if (void 0 === e) t._$AN = e = /* @__PURE__ */ new Set(); + else if (e.has(i)) break; + (e.add(i), c(t)); + } + }; function h$2(i) { - void 0 !== this._$AN ? (o$6(this), this._$AM = i, r$3(this)) : this._$AM = i; + void 0 !== this._$AN ? (o$6(this), (this._$AM = i), r$3(this)) : (this._$AM = i); } function n$3(i, t = !1, e = 0) { - const r = this._$AH, h = this._$AN; - if (void 0 !== h && 0 !== h.size) if (t) if (Array.isArray(r)) for (let i = e; i < r.length; i++) s(r[i], !1), o$6(r[i]); - else null != r && (s(r, !1), o$6(r)); - else s(this, i); + const r = this._$AH, + h = this._$AN; + if (void 0 !== h && 0 !== h.size) + if (t) + if (Array.isArray(r)) for (let i = e; i < r.length; i++) (s(r[i], !1), o$6(r[i])); + else null != r && (s(r, !1), o$6(r)); + else s(this, i); } const c = (i) => { - i.type == t$4.CHILD && (i._$AP ??= n$3, i._$AQ ??= h$2); + i.type == t$4.CHILD && ((i._$AP ??= n$3), (i._$AQ ??= h$2)); }; var f = class extends i$5 { - constructor() { - super(...arguments), this._$AN = void 0; - } - _$AT(i, t, e) { - super._$AT(i, t, e), r$3(this), this.isConnected = i._$AU; - } - _$AO(i, t = !0) { - i !== this.isConnected && (this.isConnected = i, i ? this.reconnected?.() : this.disconnected?.()), t && (s(this, i), o$6(this)); - } - setValue(t) { - if (r$8(this._$Ct)) this._$Ct._$AI(t, this); - else { - const i = [...this._$Ct._$AH]; - i[this._$Ci] = t, this._$Ct._$AI(i, this, 0); - } - } - disconnected() {} - reconnected() {} + constructor() { + (super(...arguments), (this._$AN = void 0)); + } + _$AT(i, t, e) { + (super._$AT(i, t, e), r$3(this), (this.isConnected = i._$AU)); + } + _$AO(i, t = !0) { + (i !== this.isConnected && + ((this.isConnected = i), i ? this.reconnected?.() : this.disconnected?.()), + t && (s(this, i), o$6(this))); + } + setValue(t) { + if (r$8(this._$Ct)) this._$Ct._$AI(t, this); + else { + const i = [...this._$Ct._$AH]; + ((i[this._$Ci] = t), this._$Ct._$AI(i, this, 0)); + } + } + disconnected() {} + reconnected() {} }; /** -* @license -* Copyright 2023 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ + * @license + * Copyright 2023 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ let o$5 = !1; const n$2 = new Signal.subtle.Watcher(async () => { - o$5 || (o$5 = !0, queueMicrotask(() => { - o$5 = !1; - for (const i of n$2.getPending()) i.get(); - n$2.watch(); - })); + o$5 || + ((o$5 = !0), + queueMicrotask(() => { + o$5 = !1; + for (const i of n$2.getPending()) i.get(); + n$2.watch(); + })); }); var r$2 = class extends f { - _$S_() { - var i, t; - void 0 === this._$Sm && (this._$Sj = new Signal.Computed(() => { - var i; - const t = null === (i = this._$SW) || void 0 === i ? void 0 : i.get(); - return this.setValue(t), t; - }), this._$Sm = null !== (t = null === (i = this._$Sk) || void 0 === i ? void 0 : i.h) && void 0 !== t ? t : n$2, this._$Sm.watch(this._$Sj), Signal.subtle.untrack(() => { - var i; - return null === (i = this._$Sj) || void 0 === i ? void 0 : i.get(); - })); - } - _$Sp() { - void 0 !== this._$Sm && (this._$Sm.unwatch(this._$SW), this._$Sm = void 0); - } - render(i) { - return Signal.subtle.untrack(() => i.get()); - } - update(i, [t]) { - var o, n; - return null !== (o = this._$Sk) && void 0 !== o || (this._$Sk = null === (n = i.options) || void 0 === n ? void 0 : n.host), t !== this._$SW && void 0 !== this._$SW && this._$Sp(), this._$SW = t, this._$S_(), Signal.subtle.untrack(() => this._$SW.get()); - } - disconnected() { - this._$Sp(); - } - reconnected() { - this._$S_(); - } -}; -const h$1 = e$10(r$2), m = (o) => (t, ...m) => o(t, ...m.map((o) => o instanceof Signal.State || o instanceof Signal.Computed ? h$1(o) : o)); + _$S_() { + var i, t; + void 0 === this._$Sm && + ((this._$Sj = new Signal.Computed(() => { + var i; + const t = null === (i = this._$SW) || void 0 === i ? void 0 : i.get(); + return (this.setValue(t), t); + })), + (this._$Sm = + null !== (t = null === (i = this._$Sk) || void 0 === i ? void 0 : i.h) && void 0 !== t + ? t + : n$2), + this._$Sm.watch(this._$Sj), + Signal.subtle.untrack(() => { + var i; + return null === (i = this._$Sj) || void 0 === i ? void 0 : i.get(); + })); + } + _$Sp() { + void 0 !== this._$Sm && (this._$Sm.unwatch(this._$SW), (this._$Sm = void 0)); + } + render(i) { + return Signal.subtle.untrack(() => i.get()); + } + update(i, [t]) { + var o, n; + return ( + (null !== (o = this._$Sk) && void 0 !== o) || + (this._$Sk = null === (n = i.options) || void 0 === n ? void 0 : n.host), + t !== this._$SW && void 0 !== this._$SW && this._$Sp(), + (this._$SW = t), + this._$S_(), + Signal.subtle.untrack(() => this._$SW.get()) + ); + } + disconnected() { + this._$Sp(); + } + reconnected() { + this._$S_(); + } +}; +const h$1 = e$10(r$2), + m = + (o) => + (t, ...m) => + o( + t, + ...m.map((o) => (o instanceof Signal.State || o instanceof Signal.Computed ? h$1(o) : o)), + ); m(b); m(w); Signal.State; Signal.Computed; /** -* @license -* Copyright 2021 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ + * @license + * Copyright 2021 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ function* o$3(o, f) { - if (void 0 !== o) { - let i = 0; - for (const t of o) yield f(t, i++); - } + if (void 0 !== o) { + let i = 0; + for (const t of o) yield f(t, i++); + } } let pending = false; let watcher = new Signal.subtle.Watcher(() => { - if (!pending) { - pending = true; - queueMicrotask(() => { - pending = false; - flushPending(); - }); - } + if (!pending) { + pending = true; + queueMicrotask(() => { + pending = false; + flushPending(); + }); + } }); function flushPending() { - for (const signal of watcher.getPending()) signal.get(); - watcher.watch(); + for (const signal of watcher.getPending()) signal.get(); + watcher.watch(); } /** -* ⚠️ WARNING: Nothing unwatches ⚠️ -* This will produce a memory leak. -*/ + * ⚠️ WARNING: Nothing unwatches ⚠️ + * This will produce a memory leak. + */ function effect(cb) { - let c = new Signal.Computed(() => cb()); - watcher.watch(c); - c.get(); - return () => { - watcher.unwatch(c); - }; + let c = new Signal.Computed(() => cb()); + watcher.watch(c); + c.get(); + return () => { + watcher.unwatch(c); + }; } const themeContext = n$7("A2UITheme"); const structuralStyles = r$11(structuralStyles$1); var ComponentRegistry = class { - constructor() { - this.registry = /* @__PURE__ */ new Map(); - } - register(typeName, constructor, tagName) { - if (!/^[a-zA-Z0-9]+$/.test(typeName)) throw new Error(`[Registry] Invalid typeName '${typeName}'. Must be alphanumeric.`); - this.registry.set(typeName, constructor); - const actualTagName = tagName || `a2ui-custom-${typeName.toLowerCase()}`; - const existingName = customElements.getName(constructor); - if (existingName) { - if (existingName !== actualTagName) throw new Error(`Component ${typeName} is already registered as ${existingName}, but requested as ${actualTagName}.`); - return; - } - if (!customElements.get(actualTagName)) customElements.define(actualTagName, constructor); - } - get(typeName) { - return this.registry.get(typeName); - } + constructor() { + this.registry = /* @__PURE__ */ new Map(); + } + register(typeName, constructor, tagName) { + if (!/^[a-zA-Z0-9]+$/.test(typeName)) + throw new Error(`[Registry] Invalid typeName '${typeName}'. Must be alphanumeric.`); + this.registry.set(typeName, constructor); + const actualTagName = tagName || `a2ui-custom-${typeName.toLowerCase()}`; + const existingName = customElements.getName(constructor); + if (existingName) { + if (existingName !== actualTagName) + throw new Error( + `Component ${typeName} is already registered as ${existingName}, but requested as ${actualTagName}.`, + ); + return; + } + if (!customElements.get(actualTagName)) customElements.define(actualTagName, constructor); + } + get(typeName) { + return this.registry.get(typeName); + } }; const componentRegistry = new ComponentRegistry(); -var __runInitializers$19 = function(thisArg, initializers, value) { - var useValue = arguments.length > 2; - for (var i = 0; i < initializers.length; i++) value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); - return useValue ? value : void 0; -}; -var __esDecorate$19 = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { - function accept(f) { - if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); - return f; - } - var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; - var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; - var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); - var _, done = false; - for (var i = decorators.length - 1; i >= 0; i--) { - var context = {}; - for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; - for (var p in contextIn.access) context.access[p] = contextIn.access[p]; - context.addInitializer = function(f) { - if (done) throw new TypeError("Cannot add initializers after decoration has completed"); - extraInitializers.push(accept(f || null)); - }; - var result = (0, decorators[i])(kind === "accessor" ? { - get: descriptor.get, - set: descriptor.set - } : descriptor[key], context); - if (kind === "accessor") { - if (result === void 0) continue; - if (result === null || typeof result !== "object") throw new TypeError("Object expected"); - if (_ = accept(result.get)) descriptor.get = _; - if (_ = accept(result.set)) descriptor.set = _; - if (_ = accept(result.init)) initializers.unshift(_); - } else if (_ = accept(result)) if (kind === "field") initializers.unshift(_); - else descriptor[key] = _; - } - if (target) Object.defineProperty(target, contextIn.name, descriptor); - done = true; +var __runInitializers$19 = function (thisArg, initializers, value) { + var useValue = arguments.length > 2; + for (var i = 0; i < initializers.length; i++) + value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); + return useValue ? value : void 0; +}; +var __esDecorate$19 = function ( + ctor, + descriptorIn, + decorators, + contextIn, + initializers, + extraInitializers, +) { + function accept(f) { + if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); + return f; + } + var kind = contextIn.kind, + key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; + var target = !descriptorIn && ctor ? (contextIn["static"] ? ctor : ctor.prototype) : null; + var descriptor = + descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); + var _, + done = false; + for (var i = decorators.length - 1; i >= 0; i--) { + var context = {}; + for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; + for (var p in contextIn.access) context.access[p] = contextIn.access[p]; + context.addInitializer = function (f) { + if (done) throw new TypeError("Cannot add initializers after decoration has completed"); + extraInitializers.push(accept(f || null)); + }; + var result = (0, decorators[i])( + kind === "accessor" + ? { + get: descriptor.get, + set: descriptor.set, + } + : descriptor[key], + context, + ); + if (kind === "accessor") { + if (result === void 0) continue; + if (result === null || typeof result !== "object") throw new TypeError("Object expected"); + if ((_ = accept(result.get))) descriptor.get = _; + if ((_ = accept(result.set))) descriptor.set = _; + if ((_ = accept(result.init))) initializers.unshift(_); + } else if ((_ = accept(result))) + if (kind === "field") initializers.unshift(_); + else descriptor[key] = _; + } + if (target) Object.defineProperty(target, contextIn.name, descriptor); + done = true; }; let Root = (() => { - let _classDecorators = [t$1("a2ui-root")]; - let _classDescriptor; - let _classExtraInitializers = []; - let _classThis; - let _classSuper = o$7(i$6); - let _instanceExtraInitializers = []; - let _surfaceId_decorators; - let _surfaceId_initializers = []; - let _surfaceId_extraInitializers = []; - let _component_decorators; - let _component_initializers = []; - let _component_extraInitializers = []; - let _theme_decorators; - let _theme_initializers = []; - let _theme_extraInitializers = []; - let _childComponents_decorators; - let _childComponents_initializers = []; - let _childComponents_extraInitializers = []; - let _processor_decorators; - let _processor_initializers = []; - let _processor_extraInitializers = []; - let _dataContextPath_decorators; - let _dataContextPath_initializers = []; - let _dataContextPath_extraInitializers = []; - let _enableCustomElements_decorators; - let _enableCustomElements_initializers = []; - let _enableCustomElements_extraInitializers = []; - let _set_weight_decorators; - var Root = class extends _classSuper { - static { - _classThis = this; - } - static { - const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0; - _surfaceId_decorators = [n$6()]; - _component_decorators = [n$6()]; - _theme_decorators = [c$1({ context: themeContext })]; - _childComponents_decorators = [n$6({ attribute: false })]; - _processor_decorators = [n$6({ attribute: false })]; - _dataContextPath_decorators = [n$6()]; - _enableCustomElements_decorators = [n$6()]; - _set_weight_decorators = [n$6()]; - __esDecorate$19(this, null, _surfaceId_decorators, { - kind: "accessor", - name: "surfaceId", - static: false, - private: false, - access: { - has: (obj) => "surfaceId" in obj, - get: (obj) => obj.surfaceId, - set: (obj, value) => { - obj.surfaceId = value; - } - }, - metadata: _metadata - }, _surfaceId_initializers, _surfaceId_extraInitializers); - __esDecorate$19(this, null, _component_decorators, { - kind: "accessor", - name: "component", - static: false, - private: false, - access: { - has: (obj) => "component" in obj, - get: (obj) => obj.component, - set: (obj, value) => { - obj.component = value; - } - }, - metadata: _metadata - }, _component_initializers, _component_extraInitializers); - __esDecorate$19(this, null, _theme_decorators, { - kind: "accessor", - name: "theme", - static: false, - private: false, - access: { - has: (obj) => "theme" in obj, - get: (obj) => obj.theme, - set: (obj, value) => { - obj.theme = value; - } - }, - metadata: _metadata - }, _theme_initializers, _theme_extraInitializers); - __esDecorate$19(this, null, _childComponents_decorators, { - kind: "accessor", - name: "childComponents", - static: false, - private: false, - access: { - has: (obj) => "childComponents" in obj, - get: (obj) => obj.childComponents, - set: (obj, value) => { - obj.childComponents = value; - } - }, - metadata: _metadata - }, _childComponents_initializers, _childComponents_extraInitializers); - __esDecorate$19(this, null, _processor_decorators, { - kind: "accessor", - name: "processor", - static: false, - private: false, - access: { - has: (obj) => "processor" in obj, - get: (obj) => obj.processor, - set: (obj, value) => { - obj.processor = value; - } - }, - metadata: _metadata - }, _processor_initializers, _processor_extraInitializers); - __esDecorate$19(this, null, _dataContextPath_decorators, { - kind: "accessor", - name: "dataContextPath", - static: false, - private: false, - access: { - has: (obj) => "dataContextPath" in obj, - get: (obj) => obj.dataContextPath, - set: (obj, value) => { - obj.dataContextPath = value; - } - }, - metadata: _metadata - }, _dataContextPath_initializers, _dataContextPath_extraInitializers); - __esDecorate$19(this, null, _enableCustomElements_decorators, { - kind: "accessor", - name: "enableCustomElements", - static: false, - private: false, - access: { - has: (obj) => "enableCustomElements" in obj, - get: (obj) => obj.enableCustomElements, - set: (obj, value) => { - obj.enableCustomElements = value; - } - }, - metadata: _metadata - }, _enableCustomElements_initializers, _enableCustomElements_extraInitializers); - __esDecorate$19(this, null, _set_weight_decorators, { - kind: "setter", - name: "weight", - static: false, - private: false, - access: { - has: (obj) => "weight" in obj, - set: (obj, value) => { - obj.weight = value; - } - }, - metadata: _metadata - }, null, _instanceExtraInitializers); - __esDecorate$19(null, _classDescriptor = { value: _classThis }, _classDecorators, { - kind: "class", - name: _classThis.name, - metadata: _metadata - }, null, _classExtraInitializers); - Root = _classThis = _classDescriptor.value; - if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { - enumerable: true, - configurable: true, - writable: true, - value: _metadata - }); - } - #surfaceId_accessor_storage = (__runInitializers$19(this, _instanceExtraInitializers), __runInitializers$19(this, _surfaceId_initializers, null)); - get surfaceId() { - return this.#surfaceId_accessor_storage; - } - set surfaceId(value) { - this.#surfaceId_accessor_storage = value; - } - #component_accessor_storage = (__runInitializers$19(this, _surfaceId_extraInitializers), __runInitializers$19(this, _component_initializers, null)); - get component() { - return this.#component_accessor_storage; - } - set component(value) { - this.#component_accessor_storage = value; - } - #theme_accessor_storage = (__runInitializers$19(this, _component_extraInitializers), __runInitializers$19(this, _theme_initializers, void 0)); - get theme() { - return this.#theme_accessor_storage; - } - set theme(value) { - this.#theme_accessor_storage = value; - } - #childComponents_accessor_storage = (__runInitializers$19(this, _theme_extraInitializers), __runInitializers$19(this, _childComponents_initializers, null)); - get childComponents() { - return this.#childComponents_accessor_storage; - } - set childComponents(value) { - this.#childComponents_accessor_storage = value; - } - #processor_accessor_storage = (__runInitializers$19(this, _childComponents_extraInitializers), __runInitializers$19(this, _processor_initializers, null)); - get processor() { - return this.#processor_accessor_storage; - } - set processor(value) { - this.#processor_accessor_storage = value; - } - #dataContextPath_accessor_storage = (__runInitializers$19(this, _processor_extraInitializers), __runInitializers$19(this, _dataContextPath_initializers, "")); - get dataContextPath() { - return this.#dataContextPath_accessor_storage; - } - set dataContextPath(value) { - this.#dataContextPath_accessor_storage = value; - } - #enableCustomElements_accessor_storage = (__runInitializers$19(this, _dataContextPath_extraInitializers), __runInitializers$19(this, _enableCustomElements_initializers, false)); - get enableCustomElements() { - return this.#enableCustomElements_accessor_storage; - } - set enableCustomElements(value) { - this.#enableCustomElements_accessor_storage = value; - } - set weight(weight) { - this.#weight = weight; - this.style.setProperty("--weight", `${weight}`); - } - get weight() { - return this.#weight; - } - #weight = (__runInitializers$19(this, _enableCustomElements_extraInitializers), 1); - static { - this.styles = [structuralStyles, i$9` + let _classDecorators = [t$1("a2ui-root")]; + let _classDescriptor; + let _classExtraInitializers = []; + let _classThis; + let _classSuper = o$7(i$6); + let _instanceExtraInitializers = []; + let _surfaceId_decorators; + let _surfaceId_initializers = []; + let _surfaceId_extraInitializers = []; + let _component_decorators; + let _component_initializers = []; + let _component_extraInitializers = []; + let _theme_decorators; + let _theme_initializers = []; + let _theme_extraInitializers = []; + let _childComponents_decorators; + let _childComponents_initializers = []; + let _childComponents_extraInitializers = []; + let _processor_decorators; + let _processor_initializers = []; + let _processor_extraInitializers = []; + let _dataContextPath_decorators; + let _dataContextPath_initializers = []; + let _dataContextPath_extraInitializers = []; + let _enableCustomElements_decorators; + let _enableCustomElements_initializers = []; + let _enableCustomElements_extraInitializers = []; + let _set_weight_decorators; + var Root = class extends _classSuper { + static { + _classThis = this; + } + static { + const _metadata = + typeof Symbol === "function" && Symbol.metadata + ? Object.create(_classSuper[Symbol.metadata] ?? null) + : void 0; + _surfaceId_decorators = [n$6()]; + _component_decorators = [n$6()]; + _theme_decorators = [c$1({ context: themeContext })]; + _childComponents_decorators = [n$6({ attribute: false })]; + _processor_decorators = [n$6({ attribute: false })]; + _dataContextPath_decorators = [n$6()]; + _enableCustomElements_decorators = [n$6()]; + _set_weight_decorators = [n$6()]; + __esDecorate$19( + this, + null, + _surfaceId_decorators, + { + kind: "accessor", + name: "surfaceId", + static: false, + private: false, + access: { + has: (obj) => "surfaceId" in obj, + get: (obj) => obj.surfaceId, + set: (obj, value) => { + obj.surfaceId = value; + }, + }, + metadata: _metadata, + }, + _surfaceId_initializers, + _surfaceId_extraInitializers, + ); + __esDecorate$19( + this, + null, + _component_decorators, + { + kind: "accessor", + name: "component", + static: false, + private: false, + access: { + has: (obj) => "component" in obj, + get: (obj) => obj.component, + set: (obj, value) => { + obj.component = value; + }, + }, + metadata: _metadata, + }, + _component_initializers, + _component_extraInitializers, + ); + __esDecorate$19( + this, + null, + _theme_decorators, + { + kind: "accessor", + name: "theme", + static: false, + private: false, + access: { + has: (obj) => "theme" in obj, + get: (obj) => obj.theme, + set: (obj, value) => { + obj.theme = value; + }, + }, + metadata: _metadata, + }, + _theme_initializers, + _theme_extraInitializers, + ); + __esDecorate$19( + this, + null, + _childComponents_decorators, + { + kind: "accessor", + name: "childComponents", + static: false, + private: false, + access: { + has: (obj) => "childComponents" in obj, + get: (obj) => obj.childComponents, + set: (obj, value) => { + obj.childComponents = value; + }, + }, + metadata: _metadata, + }, + _childComponents_initializers, + _childComponents_extraInitializers, + ); + __esDecorate$19( + this, + null, + _processor_decorators, + { + kind: "accessor", + name: "processor", + static: false, + private: false, + access: { + has: (obj) => "processor" in obj, + get: (obj) => obj.processor, + set: (obj, value) => { + obj.processor = value; + }, + }, + metadata: _metadata, + }, + _processor_initializers, + _processor_extraInitializers, + ); + __esDecorate$19( + this, + null, + _dataContextPath_decorators, + { + kind: "accessor", + name: "dataContextPath", + static: false, + private: false, + access: { + has: (obj) => "dataContextPath" in obj, + get: (obj) => obj.dataContextPath, + set: (obj, value) => { + obj.dataContextPath = value; + }, + }, + metadata: _metadata, + }, + _dataContextPath_initializers, + _dataContextPath_extraInitializers, + ); + __esDecorate$19( + this, + null, + _enableCustomElements_decorators, + { + kind: "accessor", + name: "enableCustomElements", + static: false, + private: false, + access: { + has: (obj) => "enableCustomElements" in obj, + get: (obj) => obj.enableCustomElements, + set: (obj, value) => { + obj.enableCustomElements = value; + }, + }, + metadata: _metadata, + }, + _enableCustomElements_initializers, + _enableCustomElements_extraInitializers, + ); + __esDecorate$19( + this, + null, + _set_weight_decorators, + { + kind: "setter", + name: "weight", + static: false, + private: false, + access: { + has: (obj) => "weight" in obj, + set: (obj, value) => { + obj.weight = value; + }, + }, + metadata: _metadata, + }, + null, + _instanceExtraInitializers, + ); + __esDecorate$19( + null, + (_classDescriptor = { value: _classThis }), + _classDecorators, + { + kind: "class", + name: _classThis.name, + metadata: _metadata, + }, + null, + _classExtraInitializers, + ); + Root = _classThis = _classDescriptor.value; + if (_metadata) + Object.defineProperty(_classThis, Symbol.metadata, { + enumerable: true, + configurable: true, + writable: true, + value: _metadata, + }); + } + #surfaceId_accessor_storage = + (__runInitializers$19(this, _instanceExtraInitializers), + __runInitializers$19(this, _surfaceId_initializers, null)); + get surfaceId() { + return this.#surfaceId_accessor_storage; + } + set surfaceId(value) { + this.#surfaceId_accessor_storage = value; + } + #component_accessor_storage = + (__runInitializers$19(this, _surfaceId_extraInitializers), + __runInitializers$19(this, _component_initializers, null)); + get component() { + return this.#component_accessor_storage; + } + set component(value) { + this.#component_accessor_storage = value; + } + #theme_accessor_storage = + (__runInitializers$19(this, _component_extraInitializers), + __runInitializers$19(this, _theme_initializers, void 0)); + get theme() { + return this.#theme_accessor_storage; + } + set theme(value) { + this.#theme_accessor_storage = value; + } + #childComponents_accessor_storage = + (__runInitializers$19(this, _theme_extraInitializers), + __runInitializers$19(this, _childComponents_initializers, null)); + get childComponents() { + return this.#childComponents_accessor_storage; + } + set childComponents(value) { + this.#childComponents_accessor_storage = value; + } + #processor_accessor_storage = + (__runInitializers$19(this, _childComponents_extraInitializers), + __runInitializers$19(this, _processor_initializers, null)); + get processor() { + return this.#processor_accessor_storage; + } + set processor(value) { + this.#processor_accessor_storage = value; + } + #dataContextPath_accessor_storage = + (__runInitializers$19(this, _processor_extraInitializers), + __runInitializers$19(this, _dataContextPath_initializers, "")); + get dataContextPath() { + return this.#dataContextPath_accessor_storage; + } + set dataContextPath(value) { + this.#dataContextPath_accessor_storage = value; + } + #enableCustomElements_accessor_storage = + (__runInitializers$19(this, _dataContextPath_extraInitializers), + __runInitializers$19(this, _enableCustomElements_initializers, false)); + get enableCustomElements() { + return this.#enableCustomElements_accessor_storage; + } + set enableCustomElements(value) { + this.#enableCustomElements_accessor_storage = value; + } + set weight(weight) { + this.#weight = weight; + this.style.setProperty("--weight", `${weight}`); + } + get weight() { + return this.#weight; + } + #weight = (__runInitializers$19(this, _enableCustomElements_extraInitializers), 1); + static { + this.styles = [ + structuralStyles, + i$9` :host { display: flex; flex-direction: column; gap: 8px; max-height: 80%; } - `]; - } - /** - * Holds the cleanup function for our effect. - * We need this to stop the effect when the component is disconnected. - */ - #lightDomEffectDisposer = null; - willUpdate(changedProperties) { - if (changedProperties.has("childComponents")) { - if (this.#lightDomEffectDisposer) this.#lightDomEffectDisposer(); - this.#lightDomEffectDisposer = effect(() => { - const allChildren = this.childComponents ?? null; - D(this.renderComponentTree(allChildren), this, { host: this }); - }); - } - } - /** - * Clean up the effect when the component is removed from the DOM. - */ - disconnectedCallback() { - super.disconnectedCallback(); - if (this.#lightDomEffectDisposer) this.#lightDomEffectDisposer(); - } - /** - * Turns the SignalMap into a renderable TemplateResult for Lit. - */ - renderComponentTree(components) { - if (!components) return A; - if (!Array.isArray(components)) return A; - return b` ${o$3(components, (component) => { - if (this.enableCustomElements) { - const elCtor = componentRegistry.get(component.type) || customElements.get(component.type); - if (elCtor) { - const node = component; - const el = new elCtor(); - el.id = node.id; - if (node.slotName) el.slot = node.slotName; - el.component = node; - el.weight = node.weight ?? "initial"; - el.processor = this.processor; - el.surfaceId = this.surfaceId; - el.dataContextPath = node.dataContextPath ?? "/"; - for (const [prop, val] of Object.entries(component.properties)) el[prop] = val; - return b`${el}`; - } - } - switch (component.type) { - case "List": { - const node = component; - const childComponents = node.properties.children; - return b` { + const allChildren = this.childComponents ?? null; + D(this.renderComponentTree(allChildren), this, { host: this }); + }); + } + } + /** + * Clean up the effect when the component is removed from the DOM. + */ + disconnectedCallback() { + super.disconnectedCallback(); + if (this.#lightDomEffectDisposer) this.#lightDomEffectDisposer(); + } + /** + * Turns the SignalMap into a renderable TemplateResult for Lit. + */ + renderComponentTree(components) { + if (!components) return A; + if (!Array.isArray(components)) return A; + return b` ${o$3(components, (component) => { + if (this.enableCustomElements) { + const elCtor = + componentRegistry.get(component.type) || customElements.get(component.type); + if (elCtor) { + const node = component; + const el = new elCtor(); + el.id = node.id; + if (node.slotName) el.slot = node.slotName; + el.component = node; + el.weight = node.weight ?? "initial"; + el.processor = this.processor; + el.surfaceId = this.surfaceId; + el.dataContextPath = node.dataContextPath ?? "/"; + for (const [prop, val] of Object.entries(component.properties)) el[prop] = val; + return b`${el}`; + } + } + switch (component.type) { + case "List": { + const node = component; + const childComponents = node.properties.children; + return b` { .childComponents=${childComponents} .enableCustomElements=${this.enableCustomElements} >`; - } - case "Card": { - const node = component; - let childComponents = node.properties.children; - if (!childComponents && node.properties.child) childComponents = [node.properties.child]; - return b` { .dataContextPath=${node.dataContextPath ?? ""} .enableCustomElements=${this.enableCustomElements} >`; - } - case "Column": { - const node = component; - return b` { .distribution=${node.properties.distribution ?? "start"} .enableCustomElements=${this.enableCustomElements} >`; - } - case "Row": { - const node = component; - return b` { .distribution=${node.properties.distribution ?? "start"} .enableCustomElements=${this.enableCustomElements} >`; - } - case "Image": { - const node = component; - return b` { .fit=${node.properties.fit} .enableCustomElements=${this.enableCustomElements} >`; - } - case "Icon": { - const node = component; - return b` { .dataContextPath=${node.dataContextPath ?? ""} .enableCustomElements=${this.enableCustomElements} >`; - } - case "AudioPlayer": { - const node = component; - return b` { .dataContextPath=${node.dataContextPath ?? ""} .enableCustomElements=${this.enableCustomElements} >`; - } - case "Button": { - const node = component; - return b` { .childComponents=${[node.properties.child]} .enableCustomElements=${this.enableCustomElements} >`; - } - case "Text": { - const node = component; - return b` { .usageHint=${node.properties.usageHint} .enableCustomElements=${this.enableCustomElements} >`; - } - case "CheckBox": { - const node = component; - return b` { .value=${node.properties.value} .enableCustomElements=${this.enableCustomElements} >`; - } - case "DateTimeInput": { - const node = component; - return b` { .value=${node.properties.value} .enableCustomElements=${this.enableCustomElements} >`; - } - case "Divider": { - const node = component; - return b` { .color=${node.properties.color} .enableCustomElements=${this.enableCustomElements} >`; - } - case "MultipleChoice": { - const node = component; - return b` { .selections=${node.properties.selections} .enableCustomElements=${this.enableCustomElements} >`; - } - case "Slider": { - const node = component; - return b` { .maxValue=${node.properties.maxValue} .enableCustomElements=${this.enableCustomElements} >`; - } - case "TextField": { - const node = component; - return b` { .validationRegexp=${node.properties.validationRegexp} .enableCustomElements=${this.enableCustomElements} >`; - } - case "Video": { - const node = component; - return b` { .url=${node.properties.url} .enableCustomElements=${this.enableCustomElements} >`; - } - case "Tabs": { - const node = component; - const titles = []; - const childComponents = []; - if (node.properties.tabItems) for (const item of node.properties.tabItems) { - titles.push(item.title); - childComponents.push(item.child); - } - return b` { .childComponents=${childComponents} .enableCustomElements=${this.enableCustomElements} >`; - } - case "Modal": { - const node = component; - const childComponents = [node.properties.entryPointChild, node.properties.contentChild]; - node.properties.entryPointChild.slotName = "entry"; - return b` { .childComponents=${childComponents} .enableCustomElements=${this.enableCustomElements} >`; - } - default: return this.renderCustomComponent(component); - } - })}`; - } - renderCustomComponent(component) { - if (!this.enableCustomElements) return; - const node = component; - const elCtor = componentRegistry.get(component.type) || customElements.get(component.type); - if (!elCtor) return b`Unknown element ${component.type}`; - const el = new elCtor(); - el.id = node.id; - if (node.slotName) el.slot = node.slotName; - el.component = node; - el.weight = node.weight ?? "initial"; - el.processor = this.processor; - el.surfaceId = this.surfaceId; - el.dataContextPath = node.dataContextPath ?? "/"; - for (const [prop, val] of Object.entries(component.properties)) el[prop] = val; - return b`${el}`; - } - render() { - return b``; - } - static { - __runInitializers$19(_classThis, _classExtraInitializers); - } - }; - return _classThis; + } + default: + return this.renderCustomComponent(component); + } + })}`; + } + renderCustomComponent(component) { + if (!this.enableCustomElements) return; + const node = component; + const elCtor = componentRegistry.get(component.type) || customElements.get(component.type); + if (!elCtor) return b`Unknown element ${component.type}`; + const el = new elCtor(); + el.id = node.id; + if (node.slotName) el.slot = node.slotName; + el.component = node; + el.weight = node.weight ?? "initial"; + el.processor = this.processor; + el.surfaceId = this.surfaceId; + el.dataContextPath = node.dataContextPath ?? "/"; + for (const [prop, val] of Object.entries(component.properties)) el[prop] = val; + return b`${el}`; + } + render() { + return b``; + } + static { + __runInitializers$19(_classThis, _classExtraInitializers); + } + }; + return _classThis; })(); /** -* @license -* Copyright 2018 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ const e$2 = e$10(class extends i$5 { - constructor(t) { - if (super(t), t.type !== t$4.ATTRIBUTE || "class" !== t.name || t.strings?.length > 2) throw Error("`classMap()` can only be used in the `class` attribute and must be the only part in the attribute."); - } - render(t) { - return " " + Object.keys(t).filter((s) => t[s]).join(" ") + " "; - } - update(s, [i]) { - if (void 0 === this.st) { - this.st = /* @__PURE__ */ new Set(), void 0 !== s.strings && (this.nt = new Set(s.strings.join(" ").split(/\s/).filter((t) => "" !== t))); - for (const t in i) i[t] && !this.nt?.has(t) && this.st.add(t); - return this.render(i); - } - const r = s.element.classList; - for (const t of this.st) t in i || (r.remove(t), this.st.delete(t)); - for (const t in i) { - const s = !!i[t]; - s === this.st.has(t) || this.nt?.has(t) || (s ? (r.add(t), this.st.add(t)) : (r.remove(t), this.st.delete(t))); - } - return E; - } -}); + * @license + * Copyright 2018 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ const e$2 = e$10( + class extends i$5 { + constructor(t) { + if ((super(t), t.type !== t$4.ATTRIBUTE || "class" !== t.name || t.strings?.length > 2)) + throw Error( + "`classMap()` can only be used in the `class` attribute and must be the only part in the attribute.", + ); + } + render(t) { + return ( + " " + + Object.keys(t) + .filter((s) => t[s]) + .join(" ") + + " " + ); + } + update(s, [i]) { + if (void 0 === this.st) { + ((this.st = /* @__PURE__ */ new Set()), + void 0 !== s.strings && + (this.nt = new Set( + s.strings + .join(" ") + .split(/\s/) + .filter((t) => "" !== t), + ))); + for (const t in i) i[t] && !this.nt?.has(t) && this.st.add(t); + return this.render(i); + } + const r = s.element.classList; + for (const t of this.st) t in i || (r.remove(t), this.st.delete(t)); + for (const t in i) { + const s = !!i[t]; + s === this.st.has(t) || + this.nt?.has(t) || + (s ? (r.add(t), this.st.add(t)) : (r.remove(t), this.st.delete(t))); + } + return E; + } + }, +); /** -* @license -* Copyright 2018 Google LLC -* SPDX-License-Identifier: BSD-3-Clause -*/ const n$1 = "important", i = " !" + n$1, o$2 = e$10(class extends i$5 { - constructor(t) { - if (super(t), t.type !== t$4.ATTRIBUTE || "style" !== t.name || t.strings?.length > 2) throw Error("The `styleMap` directive must be used in the `style` attribute and must be the only part in the attribute."); - } - render(t) { - return Object.keys(t).reduce((e, r) => { - const s = t[r]; - return null == s ? e : e + `${r = r.includes("-") ? r : r.replace(/(?:^(webkit|moz|ms|o)|)(?=[A-Z])/g, "-$&").toLowerCase()}:${s};`; - }, ""); - } - update(e, [r]) { - const { style: s } = e.element; - if (void 0 === this.ft) return this.ft = new Set(Object.keys(r)), this.render(r); - for (const t of this.ft) null == r[t] && (this.ft.delete(t), t.includes("-") ? s.removeProperty(t) : s[t] = null); - for (const t in r) { - const e = r[t]; - if (null != e) { - this.ft.add(t); - const r = "string" == typeof e && e.endsWith(i); - t.includes("-") || r ? s.setProperty(t, r ? e.slice(0, -11) : e, r ? n$1 : "") : s[t] = e; - } - } - return E; - } -}); -var __esDecorate$18 = function(ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) { - function accept(f) { - if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); - return f; - } - var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; - var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null; - var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); - var _, done = false; - for (var i = decorators.length - 1; i >= 0; i--) { - var context = {}; - for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; - for (var p in contextIn.access) context.access[p] = contextIn.access[p]; - context.addInitializer = function(f) { - if (done) throw new TypeError("Cannot add initializers after decoration has completed"); - extraInitializers.push(accept(f || null)); - }; - var result = (0, decorators[i])(kind === "accessor" ? { - get: descriptor.get, - set: descriptor.set - } : descriptor[key], context); - if (kind === "accessor") { - if (result === void 0) continue; - if (result === null || typeof result !== "object") throw new TypeError("Object expected"); - if (_ = accept(result.get)) descriptor.get = _; - if (_ = accept(result.set)) descriptor.set = _; - if (_ = accept(result.init)) initializers.unshift(_); - } else if (_ = accept(result)) if (kind === "field") initializers.unshift(_); - else descriptor[key] = _; - } - if (target) Object.defineProperty(target, contextIn.name, descriptor); - done = true; -}; -var __runInitializers$18 = function(thisArg, initializers, value) { - var useValue = arguments.length > 2; - for (var i = 0; i < initializers.length; i++) value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); - return useValue ? value : void 0; + * @license + * Copyright 2018 Google LLC + * SPDX-License-Identifier: BSD-3-Clause + */ const n$1 = "important", + i = " !" + n$1, + o$2 = e$10( + class extends i$5 { + constructor(t) { + if ((super(t), t.type !== t$4.ATTRIBUTE || "style" !== t.name || t.strings?.length > 2)) + throw Error( + "The `styleMap` directive must be used in the `style` attribute and must be the only part in the attribute.", + ); + } + render(t) { + return Object.keys(t).reduce((e, r) => { + const s = t[r]; + return null == s + ? e + : e + + `${(r = r.includes("-") ? r : r.replace(/(?:^(webkit|moz|ms|o)|)(?=[A-Z])/g, "-$&").toLowerCase())}:${s};`; + }, ""); + } + update(e, [r]) { + const { style: s } = e.element; + if (void 0 === this.ft) return ((this.ft = new Set(Object.keys(r))), this.render(r)); + for (const t of this.ft) + null == r[t] && + (this.ft.delete(t), t.includes("-") ? s.removeProperty(t) : (s[t] = null)); + for (const t in r) { + const e = r[t]; + if (null != e) { + this.ft.add(t); + const r = "string" == typeof e && e.endsWith(i); + t.includes("-") || r + ? s.setProperty(t, r ? e.slice(0, -11) : e, r ? n$1 : "") + : (s[t] = e); + } + } + return E; + } + }, + ); +var __esDecorate$18 = function ( + ctor, + descriptorIn, + decorators, + contextIn, + initializers, + extraInitializers, +) { + function accept(f) { + if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); + return f; + } + var kind = contextIn.kind, + key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value"; + var target = !descriptorIn && ctor ? (contextIn["static"] ? ctor : ctor.prototype) : null; + var descriptor = + descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {}); + var _, + done = false; + for (var i = decorators.length - 1; i >= 0; i--) { + var context = {}; + for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p]; + for (var p in contextIn.access) context.access[p] = contextIn.access[p]; + context.addInitializer = function (f) { + if (done) throw new TypeError("Cannot add initializers after decoration has completed"); + extraInitializers.push(accept(f || null)); + }; + var result = (0, decorators[i])( + kind === "accessor" + ? { + get: descriptor.get, + set: descriptor.set, + } + : descriptor[key], + context, + ); + if (kind === "accessor") { + if (result === void 0) continue; + if (result === null || typeof result !== "object") throw new TypeError("Object expected"); + if ((_ = accept(result.get))) descriptor.get = _; + if ((_ = accept(result.set))) descriptor.set = _; + if ((_ = accept(result.init))) initializers.unshift(_); + } else if ((_ = accept(result))) + if (kind === "field") initializers.unshift(_); + else descriptor[key] = _; + } + if (target) Object.defineProperty(target, contextIn.name, descriptor); + done = true; +}; +var __runInitializers$18 = function (thisArg, initializers, value) { + var useValue = arguments.length > 2; + for (var i = 0; i < initializers.length; i++) + value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg); + return useValue ? value : void 0; }; (() => { - let _classDecorators = [t$1("a2ui-audioplayer")]; - let _classDescriptor; - let _classExtraInitializers = []; - let _classThis; - let _classSuper = Root; - let _url_decorators; - let _url_initializers = []; - let _url_extraInitializers = []; - var Audio = class extends _classSuper { - static { - _classThis = this; - } - static { - const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0; - _url_decorators = [n$6()]; - __esDecorate$18(this, null, _url_decorators, { - kind: "accessor", - name: "url", - static: false, - private: false, - access: { - has: (obj) => "url" in obj, - get: (obj) => obj.url, - set: (obj, value) => { - obj.url = value; - } - }, - metadata: _metadata - }, _url_initializers, _url_extraInitializers); - __esDecorate$18(null, _classDescriptor = { value: _classThis }, _classDecorators, { - kind: "class", - name: _classThis.name, - metadata: _metadata - }, null, _classExtraInitializers); - Audio = _classThis = _classDescriptor.value; - if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { - enumerable: true, - configurable: true, - writable: true, - value: _metadata - }); - } - #url_accessor_storage = __runInitializers$18(this, _url_initializers, null); - get url() { - return this.#url_accessor_storage; - } - set url(value) { - this.#url_accessor_storage = value; - } - static { - this.styles = [structuralStyles, i$9` + let _classDecorators = [t$1("a2ui-audioplayer")]; + let _classDescriptor; + let _classExtraInitializers = []; + let _classThis; + let _classSuper = Root; + let _url_decorators; + let _url_initializers = []; + let _url_extraInitializers = []; + var Audio = class extends _classSuper { + static { + _classThis = this; + } + static { + const _metadata = + typeof Symbol === "function" && Symbol.metadata + ? Object.create(_classSuper[Symbol.metadata] ?? null) + : void 0; + _url_decorators = [n$6()]; + __esDecorate$18( + this, + null, + _url_decorators, + { + kind: "accessor", + name: "url", + static: false, + private: false, + access: { + has: (obj) => "url" in obj, + get: (obj) => obj.url, + set: (obj, value) => { + obj.url = value; + }, + }, + metadata: _metadata, + }, + _url_initializers, + _url_extraInitializers, + ); + __esDecorate$18( + null, + (_classDescriptor = { value: _classThis }), + _classDecorators, + { + kind: "class", + name: _classThis.name, + metadata: _metadata, + }, + null, + _classExtraInitializers, + ); + Audio = _classThis = _classDescriptor.value; + if (_metadata) + Object.defineProperty(_classThis, Symbol.metadata, { + enumerable: true, + configurable: true, + writable: true, + value: _metadata, + }); + } + #url_accessor_storage = __runInitializers$18(this, _url_initializers, null); + get url() { + return this.#url_accessor_storage; + } + set url(value) { + this.#url_accessor_storage = value; + } + static { + this.styles = [ + structuralStyles, + i$9` * { box-sizing: border-box; } @@ -3855,232 +4731,305 @@ var __runInitializers$18 = function(thisArg, initializers, value) { display: block; width: 100%; } - `]; - } - #renderAudio() { - if (!this.url) return A; - if (this.url && typeof this.url === "object") { - if ("literalString" in this.url) return b`