@hanzo/dev 4.0.1 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/{BinaryViewer-qn8xfPZp.js → BinaryViewer-CmFUK4zZ.js} +2 -2
- package/dist/{ChatMarkdown-Cyujn3JJ.js → ChatMarkdown-nvEI7iCv.js} +4 -4
- package/dist/{DiffCommentAnnotation-BZu1TP6E.js → DiffCommentAnnotation-BPTN_2a6.js} +1 -1
- package/dist/{DiffFileTree-CcJ91zOM.js → DiffFileTree-B_br90vY.js} +2 -2
- package/dist/{DiffPanel-BXC88NMs.js → DiffPanel-V5R5TPuK.js} +5 -5
- package/dist/{ExpandedImageDialog-BZnGRBJR.js → ExpandedImageDialog-CAorLacL.js} +1 -1
- package/dist/{FileExplorerPane-vBJS6V75.js → FileExplorerPane-CeHulcPz.js} +1 -1
- package/dist/{FilePreviewPanel-jJHWsMzm.js → FilePreviewPanel-BVNLvWOc.js} +8 -8
- package/dist/{MermaidDiagram-paNwQY33.js → MermaidDiagram-CTolIzQD.js} +1 -1
- package/dist/{MermaidFilePreview-B9KxfnIN.js → MermaidFilePreview-CP2zP4FU.js} +1 -1
- package/dist/{MermaidViewer-CAEGpLyD.js → MermaidViewer-BDfYkS9E.js} +2 -2
- package/dist/{NotebookPreview-D01mMCpR.js → NotebookPreview-Cybs5uM0.js} +1 -1
- package/dist/{OfficeFilePreview-DWaRgfQU.js → OfficeFilePreview-7JsmSoKU.js} +1 -1
- package/dist/{OfficeViewer-BudrZbBA.js → OfficeViewer-CJoojlJK.js} +1 -1
- package/dist/{OpenInPicker-Dd3ifHa1.js → OpenInPicker-BIMWUxBP.js} +7 -7
- package/dist/{OpenXmlOfficeViewer-CXcKdq7k.js → OpenXmlOfficeViewer-C24Kj8DM.js} +1 -1
- package/dist/{PreviewImage-C4Ku4z7v.js → PreviewImage-oY5YnuTr.js} +1 -1
- package/dist/{PreviewImageContent-BwOB9Lyd.js → PreviewImageContent-n6eLzY99.js} +1 -1
- package/dist/{PullRequestCodeTab-BcwyMk7d.js → PullRequestCodeTab-Dv_0kVad.js} +7 -7
- package/dist/{PullRequestReviewAnnotation-BU5t_1fC.js → PullRequestReviewAnnotation-LeuwO-iH.js} +4 -4
- package/dist/builder/activity.d.ts +16 -0
- package/dist/builder/activity.js +51 -0
- package/dist/builder/address.d.ts +11 -0
- package/dist/builder/address.js +50 -0
- package/dist/builder/ago.d.ts +2 -0
- package/dist/builder/ago.js +18 -0
- package/dist/builder/api/agents.d.ts +139 -0
- package/dist/builder/api/agents.js +253 -0
- package/dist/builder/api/auto.d.ts +166 -0
- package/dist/builder/api/auto.js +300 -0
- package/dist/builder/api/billing.d.ts +263 -0
- package/dist/builder/api/billing.js +401 -0
- package/dist/builder/api/call.d.ts +53 -0
- package/dist/builder/api/call.js +123 -0
- package/dist/builder/api/capabilities.d.ts +14 -0
- package/dist/builder/api/capabilities.js +41 -0
- package/dist/builder/api/changes.d.ts +74 -0
- package/dist/builder/api/changes.js +75 -0
- package/dist/builder/api/chat.d.ts +12 -0
- package/dist/builder/api/chat.js +28 -0
- package/dist/builder/api/cli.d.ts +59 -0
- package/dist/builder/api/cli.js +133 -0
- package/dist/builder/api/codebases.d.ts +46 -0
- package/dist/builder/api/codebases.js +100 -0
- package/dist/builder/api/coding.d.ts +117 -0
- package/dist/builder/api/coding.js +222 -0
- package/dist/builder/api/connectors.d.ts +76 -0
- package/dist/builder/api/connectors.js +111 -0
- package/dist/builder/api/consent.d.ts +22 -0
- package/dist/builder/api/consent.js +28 -0
- package/dist/builder/api/conversations.d.ts +20 -0
- package/dist/builder/api/conversations.js +23 -0
- package/dist/builder/api/draft.d.ts +38 -0
- package/dist/builder/api/draft.js +87 -0
- package/dist/builder/api/environment.d.ts +55 -0
- package/dist/builder/api/environment.js +126 -0
- package/dist/builder/api/gallery.d.ts +32 -0
- package/dist/builder/api/gallery.js +85 -0
- package/dist/builder/api/git.d.ts +31 -0
- package/dist/builder/api/git.js +47 -0
- package/dist/builder/api/github.d.ts +176 -0
- package/dist/builder/api/github.js +271 -0
- package/dist/builder/api/keys.d.ts +35 -0
- package/dist/builder/api/keys.js +72 -0
- package/dist/builder/api/library.d.ts +116 -0
- package/dist/builder/api/library.js +214 -0
- package/dist/builder/api/limits.d.ts +69 -0
- package/dist/builder/api/limits.js +86 -0
- package/dist/builder/api/links.d.ts +51 -0
- package/dist/builder/api/links.js +75 -0
- package/dist/builder/api/machines.d.ts +122 -0
- package/dist/builder/api/machines.js +238 -0
- package/dist/builder/api/mcp.d.ts +10 -0
- package/dist/builder/api/mcp.js +47 -0
- package/dist/builder/api/members.d.ts +35 -0
- package/dist/builder/api/members.js +95 -0
- package/dist/builder/api/memory.d.ts +14 -0
- package/dist/builder/api/memory.js +35 -0
- package/dist/builder/api/models.d.ts +17 -0
- package/dist/builder/api/models.js +20 -0
- package/dist/builder/api/places.d.ts +32 -0
- package/dist/builder/api/places.js +29 -0
- package/dist/builder/api/platform.d.ts +68 -0
- package/dist/builder/api/platform.js +87 -0
- package/dist/builder/api/plugins.d.ts +42 -0
- package/dist/builder/api/plugins.js +175 -0
- package/dist/builder/api/pref.d.ts +77 -0
- package/dist/builder/api/pref.js +93 -0
- package/dist/builder/api/profile.d.ts +11 -0
- package/dist/builder/api/profile.js +41 -0
- package/dist/builder/api/projects.d.ts +99 -0
- package/dist/builder/api/projects.js +166 -0
- package/dist/builder/api/provider.d.ts +49 -0
- package/dist/builder/api/provider.js +96 -0
- package/dist/builder/api/sandbox.d.ts +90 -0
- package/dist/builder/api/sandbox.js +223 -0
- package/dist/builder/api/sessions.d.ts +123 -0
- package/dist/builder/api/sessions.js +255 -0
- package/dist/builder/api/skills.d.ts +82 -0
- package/dist/builder/api/skills.js +117 -0
- package/dist/builder/api/sse.d.ts +24 -0
- package/dist/builder/api/sse.js +68 -0
- package/dist/builder/api/studio.d.ts +59 -0
- package/dist/builder/api/studio.js +91 -0
- package/dist/builder/api/talk.d.ts +48 -0
- package/dist/builder/api/talk.js +81 -0
- package/dist/builder/api/tools.d.ts +34 -0
- package/dist/builder/api/tools.js +37 -0
- package/dist/builder/api/turn.d.ts +202 -0
- package/dist/builder/api/turn.js +772 -0
- package/dist/builder/api/verdict.d.ts +3 -0
- package/dist/builder/api/verdict.js +21 -0
- package/dist/builder/api/webhooks.d.ts +47 -0
- package/dist/builder/api/webhooks.js +82 -0
- package/dist/builder/api/work.d.ts +110 -0
- package/dist/builder/api/work.js +218 -0
- package/dist/builder/ask.d.ts +51 -0
- package/dist/builder/ask.js +147 -0
- package/dist/builder/automations.d.ts +33 -0
- package/dist/builder/automations.js +453 -0
- package/dist/builder/awake.d.ts +24 -0
- package/dist/builder/awake.js +68 -0
- package/dist/builder/back.d.ts +30 -0
- package/dist/builder/back.js +105 -0
- package/dist/builder/builder.d.ts +12 -0
- package/dist/builder/builder.js +162 -0
- package/dist/builder/carry.d.ts +48 -0
- package/dist/builder/carry.js +278 -0
- package/dist/builder/choice.d.ts +134 -0
- package/dist/builder/choice.js +152 -0
- package/dist/builder/claims.d.ts +13 -0
- package/dist/builder/claims.js +35 -0
- package/dist/builder/clipboard.d.ts +2 -0
- package/dist/builder/clipboard.js +10 -0
- package/dist/builder/customize/agents.d.ts +11 -0
- package/dist/builder/customize/agents.js +513 -0
- package/dist/builder/customize/connectors.d.ts +2 -0
- package/dist/builder/customize/connectors.js +319 -0
- package/dist/builder/customize/drafted.d.ts +4 -0
- package/dist/builder/customize/drafted.js +92 -0
- package/dist/builder/customize/index.d.ts +8 -0
- package/dist/builder/customize/index.js +127 -0
- package/dist/builder/customize/inventory.d.ts +14 -0
- package/dist/builder/customize/inventory.js +127 -0
- package/dist/builder/customize/load.d.ts +9 -0
- package/dist/builder/customize/load.js +22 -0
- package/dist/builder/customize/ocean.d.ts +41 -0
- package/dist/builder/customize/ocean.js +332 -0
- package/dist/builder/customize/plugins.d.ts +2 -0
- package/dist/builder/customize/plugins.js +136 -0
- package/dist/builder/customize/roles.d.ts +4 -0
- package/dist/builder/customize/roles.js +105 -0
- package/dist/builder/customize/say.d.ts +13 -0
- package/dist/builder/customize/say.js +32 -0
- package/dist/builder/customize/skills.d.ts +2 -0
- package/dist/builder/customize/skills.js +208 -0
- package/dist/builder/customize/ui.d.ts +152 -0
- package/dist/builder/customize/ui.js +208 -0
- package/dist/builder/data.d.ts +57 -0
- package/dist/builder/data.js +322 -0
- package/dist/builder/design.d.ts +140 -0
- package/dist/builder/design.js +175 -0
- package/dist/builder/desk.d.ts +48 -0
- package/dist/builder/desk.js +449 -0
- package/dist/builder/dev-mode.d.ts +43 -0
- package/dist/builder/dev-mode.js +120 -0
- package/dist/builder/door.d.ts +11 -0
- package/dist/builder/door.js +126 -0
- package/dist/builder/environment.d.ts +23 -0
- package/dist/builder/environment.js +193 -0
- package/dist/builder/files.d.ts +23 -0
- package/dist/builder/files.js +175 -0
- package/dist/builder/find.d.ts +7 -0
- package/dist/builder/find.js +80 -0
- package/dist/builder/foot.d.ts +30 -0
- package/dist/builder/foot.js +79 -0
- package/dist/builder/forge.d.ts +4 -0
- package/dist/builder/forge.js +570 -0
- package/dist/builder/gear.d.ts +60 -0
- package/dist/builder/gear.js +180 -0
- package/dist/builder/git.d.ts +21 -0
- package/dist/builder/git.js +118 -0
- package/dist/builder/gutter.d.ts +17 -0
- package/dist/builder/gutter.js +25 -0
- package/dist/builder/handoff.d.ts +8 -0
- package/dist/builder/handoff.js +22 -0
- package/dist/builder/host.d.ts +189 -0
- package/dist/builder/host.js +46 -0
- package/dist/builder/index.d.ts +108 -0
- package/dist/builder/index.js +99 -0
- package/dist/builder/landing.d.ts +34 -0
- package/dist/builder/landing.js +725 -0
- package/dist/builder/library.d.ts +21 -0
- package/dist/builder/library.js +526 -0
- package/dist/builder/local.d.ts +80 -0
- package/dist/builder/local.js +124 -0
- package/dist/builder/make.d.ts +10 -0
- package/dist/builder/make.js +120 -0
- package/dist/builder/markdown.d.ts +49 -0
- package/dist/builder/markdown.js +125 -0
- package/dist/builder/marks.d.ts +15 -0
- package/dist/builder/marks.js +18 -0
- package/dist/builder/merge.d.ts +223 -0
- package/dist/builder/merge.js +380 -0
- package/dist/builder/meter.d.ts +31 -0
- package/dist/builder/meter.js +54 -0
- package/dist/builder/mind.d.ts +107 -0
- package/dist/builder/mind.js +335 -0
- package/dist/builder/names.d.ts +40 -0
- package/dist/builder/names.js +189 -0
- package/dist/builder/nav.d.ts +28 -0
- package/dist/builder/nav.js +218 -0
- package/dist/builder/out.d.ts +16 -0
- package/dist/builder/out.js +24 -0
- package/dist/builder/page.d.ts +55 -0
- package/dist/builder/page.js +217 -0
- package/dist/builder/pane.d.ts +30 -0
- package/dist/builder/pane.js +21 -0
- package/dist/builder/panel.d.ts +101 -0
- package/dist/builder/panel.js +408 -0
- package/dist/builder/pdf.d.ts +139 -0
- package/dist/builder/pdf.js +847 -0
- package/dist/builder/pick.d.ts +10 -0
- package/dist/builder/pick.js +38 -0
- package/dist/builder/plain.d.ts +59 -0
- package/dist/builder/plain.js +209 -0
- package/dist/builder/plan.d.ts +63 -0
- package/dist/builder/plan.js +155 -0
- package/dist/builder/plans.d.ts +1 -0
- package/dist/builder/plans.js +157 -0
- package/dist/builder/plugin.d.ts +60 -0
- package/dist/builder/plugin.js +1 -0
- package/dist/builder/plugins/design.d.ts +8 -0
- package/dist/builder/plugins/design.js +71 -0
- package/dist/builder/plugins/index.d.ts +46 -0
- package/dist/builder/plugins/index.js +117 -0
- package/dist/builder/plugins/pdf.d.ts +18 -0
- package/dist/builder/plugins/pdf.js +83 -0
- package/dist/builder/plugins/project.d.ts +5 -0
- package/dist/builder/plugins/project.js +68 -0
- package/dist/builder/plugins/research.d.ts +24 -0
- package/dist/builder/plugins/research.js +147 -0
- package/dist/builder/plugins/sketch.d.ts +9 -0
- package/dist/builder/plugins/sketch.js +101 -0
- package/dist/builder/plugins/slides.d.ts +14 -0
- package/dist/builder/plugins/slides.js +55 -0
- package/dist/builder/plugins/template.d.ts +13 -0
- package/dist/builder/plugins/template.js +95 -0
- package/dist/builder/prefs.d.ts +29 -0
- package/dist/builder/prefs.js +91 -0
- package/dist/builder/preview-url.d.ts +47 -0
- package/dist/builder/preview-url.js +107 -0
- package/dist/builder/project.d.ts +18 -0
- package/dist/builder/project.js +591 -0
- package/dist/builder/prose.d.ts +4 -0
- package/dist/builder/prose.js +57 -0
- package/dist/builder/publish.d.ts +18 -0
- package/dist/builder/publish.js +141 -0
- package/dist/builder/question.d.ts +33 -0
- package/dist/builder/question.js +64 -0
- package/dist/builder/redesign.d.ts +32 -0
- package/dist/builder/redesign.js +117 -0
- package/dist/builder/removal.d.ts +71 -0
- package/dist/builder/removal.js +73 -0
- package/dist/builder/reply.d.ts +50 -0
- package/dist/builder/reply.js +196 -0
- package/dist/builder/roles.d.ts +10 -0
- package/dist/builder/roles.js +28 -0
- package/dist/builder/route.d.ts +85 -0
- package/dist/builder/route.js +126 -0
- package/dist/builder/run.d.ts +4 -0
- package/dist/builder/run.js +804 -0
- package/dist/builder/runmeta.d.ts +16 -0
- package/dist/builder/runmeta.js +69 -0
- package/dist/builder/say.d.ts +2 -0
- package/dist/builder/say.js +7 -0
- package/dist/builder/scheduled.d.ts +3 -0
- package/dist/builder/scheduled.js +328 -0
- package/dist/builder/section.d.ts +27 -0
- package/dist/builder/section.js +60 -0
- package/dist/builder/settings/account.d.ts +1 -0
- package/dist/builder/settings/account.js +111 -0
- package/dist/builder/settings/billing.d.ts +1 -0
- package/dist/builder/settings/billing.js +210 -0
- package/dist/builder/settings/capabilities.d.ts +1 -0
- package/dist/builder/settings/capabilities.js +66 -0
- package/dist/builder/settings/card.d.ts +31 -0
- package/dist/builder/settings/card.js +140 -0
- package/dist/builder/settings/code.d.ts +1 -0
- package/dist/builder/settings/code.js +70 -0
- package/dist/builder/settings/credits.d.ts +10 -0
- package/dist/builder/settings/credits.js +123 -0
- package/dist/builder/settings/environments.d.ts +1 -0
- package/dist/builder/settings/environments.js +60 -0
- package/dist/builder/settings/general.d.ts +1 -0
- package/dist/builder/settings/general.js +58 -0
- package/dist/builder/settings/index.d.ts +4 -0
- package/dist/builder/settings/index.js +25 -0
- package/dist/builder/settings/integrations.d.ts +8 -0
- package/dist/builder/settings/integrations.js +138 -0
- package/dist/builder/settings/keys.d.ts +1 -0
- package/dist/builder/settings/keys.js +114 -0
- package/dist/builder/settings/list.d.ts +10 -0
- package/dist/builder/settings/list.js +28 -0
- package/dist/builder/settings/machines.d.ts +4 -0
- package/dist/builder/settings/machines.js +243 -0
- package/dist/builder/settings/members.d.ts +1 -0
- package/dist/builder/settings/members.js +77 -0
- package/dist/builder/settings/memory.d.ts +1 -0
- package/dist/builder/settings/memory.js +62 -0
- package/dist/builder/settings/notifications.d.ts +1 -0
- package/dist/builder/settings/notifications.js +111 -0
- package/dist/builder/settings/plan.d.ts +17 -0
- package/dist/builder/settings/plan.js +131 -0
- package/dist/builder/settings/privacy.d.ts +1 -0
- package/dist/builder/settings/privacy.js +76 -0
- package/dist/builder/settings/sections.d.ts +16 -0
- package/dist/builder/settings/sections.js +34 -0
- package/dist/builder/settings/shared.d.ts +6 -0
- package/dist/builder/settings/shared.js +58 -0
- package/dist/builder/settings/ui.d.ts +50 -0
- package/dist/builder/settings/ui.js +53 -0
- package/dist/builder/settings/usage.d.ts +1 -0
- package/dist/builder/settings/usage.js +24 -0
- package/dist/builder/shared.d.ts +26 -0
- package/dist/builder/shared.js +15 -0
- package/dist/builder/shelf.d.ts +16 -0
- package/dist/builder/shelf.js +219 -0
- package/dist/builder/side.d.ts +40 -0
- package/dist/builder/side.js +208 -0
- package/dist/builder/site.d.ts +75 -0
- package/dist/builder/site.js +138 -0
- package/dist/builder/spend.d.ts +21 -0
- package/dist/builder/spend.js +80 -0
- package/dist/builder/standing.d.ts +36 -0
- package/dist/builder/standing.js +66 -0
- package/dist/builder/suggest.d.ts +238 -0
- package/dist/builder/suggest.js +463 -0
- package/dist/builder/suggestions.d.ts +49 -0
- package/dist/builder/suggestions.js +260 -0
- package/dist/builder/summary.d.ts +60 -0
- package/dist/builder/summary.js +81 -0
- package/dist/builder/sync.d.ts +1 -0
- package/dist/builder/sync.js +164 -0
- package/dist/builder/tabs.d.ts +85 -0
- package/dist/builder/tabs.js +288 -0
- package/dist/builder/talk.d.ts +5 -0
- package/dist/builder/talk.js +108 -0
- package/dist/builder/thread.d.ts +60 -0
- package/dist/builder/thread.js +302 -0
- package/dist/builder/tools.d.ts +22 -0
- package/dist/builder/tools.js +52 -0
- package/dist/builder/transcript.d.ts +47 -0
- package/dist/builder/transcript.js +108 -0
- package/dist/builder/voice.d.ts +8 -0
- package/dist/builder/voice.js +24 -0
- package/dist/{changedFileKind-DqgCCDUs.js → changedFileKind-D6QYvIez.js} +1 -1
- package/dist/core.js +1 -0
- package/dist/{decodeImagePreview-CesVZYP4.js → decodeImagePreview-DnfFEjhw.js} +1 -1
- package/dist/{embed-DYP-OUlb.js → embed-c030vUqM.js} +11 -11
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -1
- package/dist/{micromark-util-decode-string-NQjVkmZH.js → micromark-util-decode-string-C-5AXkOV.js} +5 -3
- package/dist/{readBinaryPreview-D2X4Uahu.js → readBinaryPreview-BAQ4fFjm.js} +1 -1
- package/dist/{useTextFieldSpeech-CyOZZPrV.js → useTextFieldSpeech-COa9XcRx.js} +1 -1
- package/package.json +101 -11
- /package/{index.d.ts → dist/core.d.ts} +0 -0
- /package/{keymap.d.ts → dist/keymap.d.ts} +0 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The suggestions under the composer (above it on a phone): up to three rows,
|
|
4
|
+
* each the source's mark and one short action, its summary on hover. Pressing
|
|
5
|
+
* a row DOES it (suggest.ts `Act`): it opens what it names, sends its prompt as
|
|
6
|
+
* a new chat, starts its run, or makes its scheduled task. Nothing only fills
|
|
7
|
+
* the composer. Its × dismisses it, and the account remembers.
|
|
8
|
+
*
|
|
9
|
+
* A row's words are the person's own, made from their activity, and drawn as
|
|
10
|
+
* given; a starter's are authored (suggest.ts `STARTERS`), so drawn and sent in
|
|
11
|
+
* the reader's language (@hanzo/i18n `t`).
|
|
12
|
+
*
|
|
13
|
+
* `useSuggestions` reads the kept rows from the account (`suggest` in /v1/pref)
|
|
14
|
+
* and, when they are due (suggest.ts `due`), reads the person's activity and
|
|
15
|
+
* asks Hanzo's model for new ones, only for a person who turned them on.
|
|
16
|
+
* Whether they are on is the account's (`suggestions` in /v1/pref, set only by
|
|
17
|
+
* `setSuggestions`; unset is off), read here, so every composer that draws them
|
|
18
|
+
* obeys it: off, or signed out, nothing of the person's is read but that switch
|
|
19
|
+
* and nothing is sent, and the one line drawn offers to turn them on. On, the
|
|
20
|
+
* rows say a model made them and offer to turn them off. One document per page, read once per person and org,
|
|
21
|
+
* shared by every composer on it.
|
|
22
|
+
*
|
|
23
|
+
* GET /v1/pref the kept rows, and callName, work, instructions
|
|
24
|
+
* GET /v1/agents/chat/conversations their conversations
|
|
25
|
+
* GET /v1/task/board the org's issues and pull requests
|
|
26
|
+
* GET /v1/agent/sessions?limit=20 Dev runs; their own are read
|
|
27
|
+
* GET /v1/auto/automations automations
|
|
28
|
+
* GET /v1/library?scope=mine their files
|
|
29
|
+
* POST /v1/iam/preferences {} what signup kept (`onboarding`)
|
|
30
|
+
* POST /v1/chat/completions the rows, as `MODEL` writes them
|
|
31
|
+
* PATCH /v1/pref {suggest} the rows kept, and each dismissal
|
|
32
|
+
* POST /v1/auto/automations a `schedule` row's task
|
|
33
|
+
*/
|
|
34
|
+
import { SizableText, useMedia, XStack, YStack } from '@hanzo/gui';
|
|
35
|
+
import { Bot, CalendarClock, FileText, Github, MessageSquare, X } from '@hanzogui/lucide-icons-2';
|
|
36
|
+
import { useI18n } from '@hanzo/i18n/react';
|
|
37
|
+
import { Button, HoverCard, HoverCardContent, HoverCardTrigger } from '@hanzo/ui';
|
|
38
|
+
import { useCallback, useEffect, useMemo, useState, useSyncExternalStore } from 'react';
|
|
39
|
+
import { RING } from './pane.js';
|
|
40
|
+
import { automations } from './api/auto.js';
|
|
41
|
+
import { call, Refusal, unwrap } from './api/call.js';
|
|
42
|
+
import { conversations } from './api/conversations.js';
|
|
43
|
+
import { items } from './api/library.js';
|
|
44
|
+
import { read, save } from './api/pref.js';
|
|
45
|
+
import { list } from './api/sessions.js';
|
|
46
|
+
import { everything } from './api/work.js';
|
|
47
|
+
import { claims } from './claims.js';
|
|
48
|
+
import { answer, dismissed, due, fill, inputs, request, seed, sig, skip, stale, starter, TAKE } from './suggest.js';
|
|
49
|
+
/** A source that refuses this person (a 4xx other than an expired sign-in or a rate) has nothing for them; any other failure leaves it unknown. */
|
|
50
|
+
function soft(p, none) {
|
|
51
|
+
return p.catch((e) => {
|
|
52
|
+
if (e instanceof Refusal && e.status >= 400 && e.status < 500 && e.status !== 401 && e.status !== 429)
|
|
53
|
+
return none;
|
|
54
|
+
throw e;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/** The person's activity and seed, or null when a source could not be read: rows are never made from half of it. */
|
|
58
|
+
async function gather(t, p) {
|
|
59
|
+
const c = claims(t.token());
|
|
60
|
+
const me = typeof c?.owner === 'string' && typeof c?.sub === 'string' ? `${c.owner}/${c.sub}` : '';
|
|
61
|
+
try {
|
|
62
|
+
const [cs, is, rs, as, fs, iam] = await Promise.all([
|
|
63
|
+
soft(conversations(t), []),
|
|
64
|
+
soft(everything(t), []),
|
|
65
|
+
soft(list(t, { limit: 20 }), []),
|
|
66
|
+
soft(automations(t), []),
|
|
67
|
+
soft(items(t, { scope: 'mine', limit: TAKE.file }).then((page) => page.data), []),
|
|
68
|
+
soft(call(t, 'POST', '/v1/iam/preferences', {}).then(unwrap), {}),
|
|
69
|
+
]);
|
|
70
|
+
return { inputs: inputs({ conversations: cs, issues: is, runs: rs, automations: as, files: fs, me }), seed: seed(p, iam) };
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// One document per page: the kept rows of whoever `loaded` names.
|
|
77
|
+
let doc = null;
|
|
78
|
+
let loaded = null;
|
|
79
|
+
let state = 'none';
|
|
80
|
+
/** The run making rows now, and the save of what it made: the switch calls off the one and waits out the other. */
|
|
81
|
+
let run = null;
|
|
82
|
+
let saving = null;
|
|
83
|
+
const listeners = new Set();
|
|
84
|
+
const emit = () => listeners.forEach((f) => f());
|
|
85
|
+
const subscribe = (f) => {
|
|
86
|
+
listeners.add(f);
|
|
87
|
+
return () => listeners.delete(f);
|
|
88
|
+
};
|
|
89
|
+
/** Read the kept rows, and make new ones when they are due. Each await checks it still speaks for `id`. */
|
|
90
|
+
async function refresh(t, id) {
|
|
91
|
+
// One run at a time; a newer one, or the switch, calls this one off.
|
|
92
|
+
run?.abort();
|
|
93
|
+
const ctl = new AbortController();
|
|
94
|
+
run = ctl;
|
|
95
|
+
// Still wanted: not called off, still this person, and still switched on. Asked after every wait.
|
|
96
|
+
const live = () => !ctl.signal.aborted && loaded === id && state === 'on';
|
|
97
|
+
try {
|
|
98
|
+
const p = await read(t);
|
|
99
|
+
if (ctl.signal.aborted || loaded !== id)
|
|
100
|
+
return;
|
|
101
|
+
// Off unless the person turned them on: none of their activity is read and nothing is sent.
|
|
102
|
+
state = p.suggestions === 'on' ? 'on' : 'off';
|
|
103
|
+
doc = state === 'on' ? (p.suggest ?? null) : null;
|
|
104
|
+
emit();
|
|
105
|
+
if (!live() || !stale(doc, Date.now()))
|
|
106
|
+
return;
|
|
107
|
+
const got = await gather(t, p);
|
|
108
|
+
if (!live() || !got)
|
|
109
|
+
return;
|
|
110
|
+
const fingerprint = sig(got.inputs, got.seed);
|
|
111
|
+
if (!due(doc, fingerprint, Date.now()))
|
|
112
|
+
return;
|
|
113
|
+
const ask = request(got.inputs, got.seed, skip(doc, got.inputs), new Date());
|
|
114
|
+
const rows = ask ? answer(await call(t, 'POST', '/v1/chat/completions', ask, { signal: ctl.signal }), got.inputs) : [];
|
|
115
|
+
if (!live())
|
|
116
|
+
return;
|
|
117
|
+
// Dismissals made while the model wrote are the latest document's.
|
|
118
|
+
const gone = doc?.dismissed ?? [];
|
|
119
|
+
doc = { at: new Date().toISOString(), sig: fingerprint, rows: rows.filter((r) => !gone.includes(r.id)), dismissed: gone };
|
|
120
|
+
emit();
|
|
121
|
+
if (!live())
|
|
122
|
+
return;
|
|
123
|
+
saving = save(t, { suggest: doc });
|
|
124
|
+
await saving;
|
|
125
|
+
}
|
|
126
|
+
catch (e) {
|
|
127
|
+
// Called off is not a failure.
|
|
128
|
+
if (!ctl.signal.aborted)
|
|
129
|
+
throw e;
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
if (run === ctl)
|
|
133
|
+
run = null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/** Whose rows: the platform, the org and the person. Signed out is nobody, and has none. */
|
|
137
|
+
const whose = (t) => {
|
|
138
|
+
const token = t.token();
|
|
139
|
+
if (!token)
|
|
140
|
+
return '';
|
|
141
|
+
const sub = claims(token)?.sub;
|
|
142
|
+
return `${t.api}|${t.org ?? ''}|${typeof sub === 'string' ? sub : ''}`;
|
|
143
|
+
};
|
|
144
|
+
function load(t) {
|
|
145
|
+
const id = whose(t);
|
|
146
|
+
if (loaded === id)
|
|
147
|
+
return Promise.resolve();
|
|
148
|
+
loaded = id;
|
|
149
|
+
doc = null;
|
|
150
|
+
state = 'none';
|
|
151
|
+
emit();
|
|
152
|
+
return id ? refresh(t, id) : Promise.resolve();
|
|
153
|
+
}
|
|
154
|
+
const said = (e) => (e instanceof Error && e.message ? e.message : 'Suggestions could not be read.');
|
|
155
|
+
/** The person's suggestions. Signed out, or with nothing worth saying, there are none. */
|
|
156
|
+
export function useSuggestions(t) {
|
|
157
|
+
const [error, setError] = useState(null);
|
|
158
|
+
useEffect(() => {
|
|
159
|
+
load(t).then(() => setError(null), (e) => setError(said(e)));
|
|
160
|
+
}, [t]);
|
|
161
|
+
const now = useSyncExternalStore(subscribe, () => doc, () => doc);
|
|
162
|
+
const known = useSyncExternalStore(subscribe, () => state, () => state);
|
|
163
|
+
const shown = whose(t) ? known : 'none';
|
|
164
|
+
// Filled to three with what Hanzo does, so a new account and a quiet one never see one lonely row.
|
|
165
|
+
const rows = useMemo(() => (shown === 'on' ? fill(now) : []), [shown, now]);
|
|
166
|
+
const dismiss = useCallback((id) => {
|
|
167
|
+
if (!doc || state !== 'on')
|
|
168
|
+
return;
|
|
169
|
+
doc = dismissed(doc, id);
|
|
170
|
+
emit();
|
|
171
|
+
if (t.token())
|
|
172
|
+
save(t, { suggest: doc }).then(() => setError(null), (e) => setError(said(e)));
|
|
173
|
+
}, [t]);
|
|
174
|
+
const turn = useCallback((on) => {
|
|
175
|
+
setSuggestions(t, on).then(() => setError(null), (e) => setError(said(e)));
|
|
176
|
+
}, [t]);
|
|
177
|
+
return useMemo(() => ({ rows, dismiss, state: shown, turn, error }), [rows, dismiss, shown, turn, error]);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* THE one way to turn suggestions on or off: the account's `suggestions` preference, so the switch follows the
|
|
181
|
+
* person across devices and every `useSuggestions` on the page obeys at once. Off calls off a run in flight before
|
|
182
|
+
* it sends anything more, waits out a save it already sent so nothing is saved back after, and forgets the rows
|
|
183
|
+
* kept from their activity. On, they are read and made.
|
|
184
|
+
*/
|
|
185
|
+
export async function setSuggestions(t, on) {
|
|
186
|
+
if (!t.token())
|
|
187
|
+
return;
|
|
188
|
+
run?.abort();
|
|
189
|
+
run = null;
|
|
190
|
+
state = on ? 'on' : 'off';
|
|
191
|
+
doc = null;
|
|
192
|
+
emit();
|
|
193
|
+
await saving?.catch(() => undefined);
|
|
194
|
+
await save(t, on ? { suggestions: 'on' } : { suggestions: 'off', suggest: null });
|
|
195
|
+
if (!on)
|
|
196
|
+
return;
|
|
197
|
+
loaded = null;
|
|
198
|
+
await load(t);
|
|
199
|
+
}
|
|
200
|
+
/** Where a row leaves its act for the product that does it. */
|
|
201
|
+
const HAND = 'hanzo.suggest.hand';
|
|
202
|
+
/**
|
|
203
|
+
* Leave `prompt` for the product `kind` names, which does it on arrival, once:
|
|
204
|
+
* Chat sends a `send` as a new chat, Dev starts a `task` as a run. Same-tab
|
|
205
|
+
* session storage, written by the person's own press, so an address can never
|
|
206
|
+
* carry one (a link is not consent to spend).
|
|
207
|
+
*/
|
|
208
|
+
export function hand(kind, prompt) {
|
|
209
|
+
try {
|
|
210
|
+
window.sessionStorage.setItem(HAND, JSON.stringify({ kind, prompt }));
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
// Without storage the product opens without it.
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/** The prompt left for `kind`, taken so it is done once, or ''. */
|
|
217
|
+
export function taken(kind) {
|
|
218
|
+
try {
|
|
219
|
+
const v = JSON.parse(window.sessionStorage.getItem(HAND) ?? 'null');
|
|
220
|
+
if (v?.kind !== kind || typeof v.prompt !== 'string')
|
|
221
|
+
return '';
|
|
222
|
+
window.sessionStorage.removeItem(HAND);
|
|
223
|
+
return v.prompt.trim();
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
return '';
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const MARKS = {
|
|
230
|
+
github: Github,
|
|
231
|
+
agent: Bot,
|
|
232
|
+
chat: MessageSquare,
|
|
233
|
+
file: FileText,
|
|
234
|
+
task: CalendarClock,
|
|
235
|
+
};
|
|
236
|
+
/** The row's pitch, px: a finger's on a phone, and the same at a desk. */
|
|
237
|
+
const PITCH = 44;
|
|
238
|
+
/** The rows, or nothing when there are none. */
|
|
239
|
+
export function Suggestions({ rows, onAct, onDismiss, state, onTurn }) {
|
|
240
|
+
const { t } = useI18n();
|
|
241
|
+
// A phone has no hover: its × stays in sight.
|
|
242
|
+
const touch = !useMedia().sm;
|
|
243
|
+
if (state === 'off') {
|
|
244
|
+
return (_jsxs(XStack, { "data-slot": "suggestions-said", items: "center", gap: "$2", flexWrap: "wrap", paddingInlineStart: "$3", minH: PITCH, children: [_jsx(SizableText, { size: "$1", color: "$soft", children: t('Hanzo’s model can suggest what to do next from your recent activity.') }), _jsx(Button, { size: "xs", variant: "ghost", onPress: () => onTurn(true), children: t('Turn on suggestions') })] }));
|
|
245
|
+
}
|
|
246
|
+
if (!rows.length)
|
|
247
|
+
return null;
|
|
248
|
+
return (_jsxs(YStack, { "data-slot": "suggestions", children: [_jsx(YStack, { role: "list", "aria-label": t('Suggestions'), children: rows.map((r) => (_jsx(Row, { row: r, touch: touch, onAct: onAct, onDismiss: onDismiss }, r.id))) }), _jsxs(XStack, { "data-slot": "suggestions-said", items: "center", gap: "$2", flexWrap: "wrap", paddingInlineStart: "$3", minH: PITCH, children: [_jsx(SizableText, { size: "$1", color: "$soft", children: t('Hanzo’s model reads your recent activity to suggest these.') }), _jsx(Button, { size: "xs", variant: "ghost", onPress: () => onTurn(false), children: t('Turn off suggestions') })] })] }));
|
|
249
|
+
}
|
|
250
|
+
/** One row: the whole of it one button that does the act, and its × beside it. Two stops for the keyboard, neither inside the other. */
|
|
251
|
+
function Row({ row: kept, touch, onAct, onDismiss }) {
|
|
252
|
+
const { t } = useI18n();
|
|
253
|
+
const [near, setNear] = useState(false);
|
|
254
|
+
// A starter in the reader's words, its prompt too: what is sent is what they pressed.
|
|
255
|
+
const row = starter(kept) ? { ...kept, title: t(kept.title), act: 'prompt' in kept.act ? { ...kept.act, prompt: t(kept.act.prompt) } : kept.act } : kept;
|
|
256
|
+
const Mark = MARKS[row.icon];
|
|
257
|
+
const handleAct = () => onAct(row.act, row);
|
|
258
|
+
const button = (_jsxs(XStack, { render: "button", "data-act": row.act.kind, "aria-label": row.title, onPress: handleAct, flex: 1, minW: 0, self: "stretch", items: "center", gap: "$3", paddingInlineStart: "$3", rounded: "$4", cursor: "pointer", focusVisibleStyle: RING, children: [_jsx(Mark, { size: 18, color: "$soft" }), _jsx(SizableText, { fontSize: 15, color: "$soft", numberOfLines: 1, shrink: 1, minW: 0, children: row.title })] }));
|
|
259
|
+
return (_jsxs(XStack, { role: "listitem", "data-slot": "suggestion", items: "center", gap: "$1", minH: PITCH, paddingInlineEnd: "$2", rounded: "$4", hoverStyle: { bg: '$hover' }, onPointerEnter: () => setNear(true), onPointerLeave: () => setNear(false), children: [row.summary && !touch ? (_jsxs(HoverCard, { openDelay: 300, closeDelay: 150, children: [_jsx(HoverCardTrigger, { flex: 1, minW: 0, self: "stretch", flexDirection: "row", children: button }), _jsx(HoverCardContent, { side: "top", align: "start", sideOffset: 8, width: 470, maxW: "calc(100vw - 32px)", rounded: "$6", p: "$4", children: _jsx(SizableText, { fontSize: 16, lineHeight: 26, color: "$ink", children: row.summary }) })] })) : (button), _jsx(XStack, { render: "button", "aria-label": t('Dismiss {suggestion}', { suggestion: row.title }), onPress: () => onDismiss(row.id), p: "$1.5", rounded: "$2", cursor: "pointer", opacity: touch || near ? 1 : 0, hoverStyle: { bg: '$hover' }, focusVisibleStyle: { opacity: 1, outlineWidth: 2, outlineStyle: 'solid', outlineColor: '$outlineColor' }, children: _jsx(X, { size: 16, color: "$soft" }) })] }));
|
|
260
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A surface's summary: what it made and what went into it, as sections of
|
|
3
|
+
* rows, each one press from a tab beside it. Chat draws its Outputs and Sources
|
|
4
|
+
* here; Studio its artifacts. The rows are the caller's: this draws them and
|
|
5
|
+
* knows nothing of a conversation.
|
|
6
|
+
*
|
|
7
|
+
* `Summary` is the popover off the header's outline mark: each section's
|
|
8
|
+
* heading with what it adds at its end, its leading action (Chat's Create file
|
|
9
|
+
* or site), its rows, and one quiet line when it has none. `useKinds` makes
|
|
10
|
+
* each section a kind of tab for `Panel`, the same rows in the panel.
|
|
11
|
+
*/
|
|
12
|
+
import { type ReactNode } from 'react';
|
|
13
|
+
import type { Kind } from './panel.tsx';
|
|
14
|
+
/** One row: what it is called, its mark, and what pressing it opens. */
|
|
15
|
+
export interface Entry {
|
|
16
|
+
id: string;
|
|
17
|
+
title: string;
|
|
18
|
+
icon?: ReactNode;
|
|
19
|
+
/** A quieter second line: what a lookup asked, what came back. */
|
|
20
|
+
detail?: string;
|
|
21
|
+
open?: () => void;
|
|
22
|
+
}
|
|
23
|
+
/** A section: its heading, its rows, and what it says with none. */
|
|
24
|
+
export interface Section {
|
|
25
|
+
id: string;
|
|
26
|
+
title: string;
|
|
27
|
+
entries: readonly Entry[];
|
|
28
|
+
/** The line drawn when it has no rows; none, and it draws only its heading. */
|
|
29
|
+
empty?: string;
|
|
30
|
+
/** At the heading's end: what adds to it (Chat's `+` on Sources). */
|
|
31
|
+
action?: ReactNode;
|
|
32
|
+
/** A row before the others that does something rather than opens something. */
|
|
33
|
+
lead?: {
|
|
34
|
+
title: string;
|
|
35
|
+
run: () => void;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The summary, from the outline mark in a header. `onOpen` runs after a row is
|
|
40
|
+
* pressed, for the host to show the panel the row opened a tab in.
|
|
41
|
+
*
|
|
42
|
+
* When `docked` is true (wide viewports where space allows), the header mark
|
|
43
|
+
* toggles `open` via `onOpenChange` without opening a floating popover, and a
|
|
44
|
+
* second `<Summary sections={sections} onOpen={...} pane />` docks the summary
|
|
45
|
+
* inline on the right edge of the inner pane, shifting the main content left so
|
|
46
|
+
* it stays open while toggled.
|
|
47
|
+
*/
|
|
48
|
+
export declare function Summary({ sections, onOpen, label: named, open: controlledOpen, onOpenChange, docked, pane, }: {
|
|
49
|
+
sections: readonly Section[];
|
|
50
|
+
onOpen?: () => void;
|
|
51
|
+
label?: string;
|
|
52
|
+
open?: boolean;
|
|
53
|
+
onOpenChange?: (open: boolean) => void;
|
|
54
|
+
docked?: boolean;
|
|
55
|
+
pane?: boolean;
|
|
56
|
+
}): import("react").JSX.Element;
|
|
57
|
+
/** Each section as a kind of tab for `Panel`: the same rows, with their second lines. */
|
|
58
|
+
export declare function kinds(sections: readonly Section[], icons?: Record<string, ReactNode>): Kind[];
|
|
59
|
+
/** `kinds`, kept while the sections are the same. */
|
|
60
|
+
export declare function useKinds(sections: readonly Section[], icons?: Record<string, ReactNode>): Kind[];
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A surface's summary: what it made and what went into it, as sections of
|
|
4
|
+
* rows, each one press from a tab beside it. Chat draws its Outputs and Sources
|
|
5
|
+
* here; Studio its artifacts. The rows are the caller's: this draws them and
|
|
6
|
+
* knows nothing of a conversation.
|
|
7
|
+
*
|
|
8
|
+
* `Summary` is the popover off the header's outline mark: each section's
|
|
9
|
+
* heading with what it adds at its end, its leading action (Chat's Create file
|
|
10
|
+
* or site), its rows, and one quiet line when it has none. `useKinds` makes
|
|
11
|
+
* each section a kind of tab for `Panel`, the same rows in the panel.
|
|
12
|
+
*/
|
|
13
|
+
import { useMemo, useState } from 'react';
|
|
14
|
+
import { SizableText, XStack, YStack } from '@hanzo/gui';
|
|
15
|
+
import { useI18n } from '@hanzo/i18n/react';
|
|
16
|
+
import { FilePlus2, ListTodo } from '@hanzogui/lucide-icons-2';
|
|
17
|
+
import { Popover, PopoverContent, PopoverTrigger } from '@hanzo/ui';
|
|
18
|
+
import { RING } from './pane.js';
|
|
19
|
+
/** A row's pitch and inset, px: the kit menu's, so this panel reads as every other one. */
|
|
20
|
+
const ROW_H = 32;
|
|
21
|
+
const ROW_PX = 8;
|
|
22
|
+
/** A row of the summary: its mark and its name, one press from a tab. */
|
|
23
|
+
function Line({ icon, children, detail, onPress, quiet = false }) {
|
|
24
|
+
return (_jsxs(XStack, { render: onPress ? 'button' : undefined, role: onPress ? 'button' : undefined, onPress: onPress, items: "center", justify: "flex-start", gap: ROW_PX, px: ROW_PX, minH: ROW_H, width: "100%", rounded: 4, cursor: onPress ? 'pointer' : undefined, hoverStyle: onPress ? { bg: '$hover' } : undefined, focusVisibleStyle: RING, children: [icon ? (_jsx(XStack, { width: 16, justify: "center", shrink: 0, opacity: 0.75, children: icon })) : null, _jsxs(YStack, { flex: 1, minW: 0, items: "flex-start", py: detail ? '$1' : 0, children: [_jsx(SizableText, { fontSize: 14, color: quiet ? '$soft' : '$ink', numberOfLines: 1, style: { textAlign: 'left' }, children: children }), detail ? (_jsx(SizableText, { fontSize: 12, color: "$soft", numberOfLines: 2, style: { textAlign: 'left' }, children: detail })) : null] })] }));
|
|
25
|
+
}
|
|
26
|
+
/** A section's heading, with what it adds at its end. */
|
|
27
|
+
const Head = ({ children, action }) => (_jsxs(XStack, { items: "center", justify: "space-between", px: ROW_PX, minH: ROW_H, children: [_jsx(SizableText, { fontSize: 13, color: "$soft", children: children }), action] }));
|
|
28
|
+
/** One section's rows; `done` runs after a row is pressed (the popover puts itself away). */
|
|
29
|
+
function Rows({ section, done, details = false }) {
|
|
30
|
+
const { entries, empty, lead } = section;
|
|
31
|
+
return (_jsxs(_Fragment, { children: [lead ? (_jsx(Line, { icon: _jsx(FilePlus2, { size: 15, "aria-hidden": true }), onPress: () => {
|
|
32
|
+
done?.();
|
|
33
|
+
lead.run();
|
|
34
|
+
}, children: lead.title })) : null, entries.map((e) => (_jsx(Line, { icon: e.icon, detail: details ? e.detail : undefined, onPress: e.open
|
|
35
|
+
? () => {
|
|
36
|
+
done?.();
|
|
37
|
+
e.open?.();
|
|
38
|
+
}
|
|
39
|
+
: undefined, children: e.title }, e.id))), !entries.length && empty ? _jsx(Line, { quiet: true, children: empty }) : null] }));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The summary, from the outline mark in a header. `onOpen` runs after a row is
|
|
43
|
+
* pressed, for the host to show the panel the row opened a tab in.
|
|
44
|
+
*
|
|
45
|
+
* When `docked` is true (wide viewports where space allows), the header mark
|
|
46
|
+
* toggles `open` via `onOpenChange` without opening a floating popover, and a
|
|
47
|
+
* second `<Summary sections={sections} onOpen={...} pane />` docks the summary
|
|
48
|
+
* inline on the right edge of the inner pane, shifting the main content left so
|
|
49
|
+
* it stays open while toggled.
|
|
50
|
+
*/
|
|
51
|
+
export function Summary({ sections, onOpen, label: named, open: controlledOpen, onOpenChange, docked = false, pane = false, }) {
|
|
52
|
+
const { t } = useI18n();
|
|
53
|
+
const label = named ?? t('Summary');
|
|
54
|
+
const [uncontrolledOpen, setUncontrolledOpen] = useState(false);
|
|
55
|
+
const open = controlledOpen ?? uncontrolledOpen;
|
|
56
|
+
const setOpen = onOpenChange ?? setUncontrolledOpen;
|
|
57
|
+
if (pane) {
|
|
58
|
+
return (_jsx(YStack, { "data-slot": "summary", role: "complementary", "aria-label": label, width: 280, shrink: 0, minH: 0, self: "stretch", p: 8, overflowY: "auto", overflowX: "hidden", children: sections.map((s, i) => (_jsxs(YStack, { pt: i ? 8 : 0, children: [_jsx(Head, { action: s.action, children: s.title }), _jsx(Rows, { section: s, done: onOpen, details: true })] }, s.id))) }));
|
|
59
|
+
}
|
|
60
|
+
const toggle = (_jsx(XStack, { render: "button", "data-slot": "summary-toggle", "aria-label": label, "aria-haspopup": docked ? undefined : 'dialog', "aria-expanded": open, ...{ title: label }, onPress: docked ? () => setOpen(!open) : undefined, width: 32, height: 32, rounded: "$3", items: "center", justify: "center", cursor: "pointer", bg: open ? '$hover' : 'transparent', hoverStyle: { bg: '$hover' }, focusVisibleStyle: RING, children: _jsx(ListTodo, { size: 16, "aria-hidden": true }) }));
|
|
61
|
+
if (docked)
|
|
62
|
+
return toggle;
|
|
63
|
+
const done = () => {
|
|
64
|
+
setOpen(false);
|
|
65
|
+
onOpen?.();
|
|
66
|
+
};
|
|
67
|
+
return (_jsxs(Popover, { open: open, onOpenChange: setOpen, allowFlip: true, children: [_jsx(PopoverTrigger, { children: toggle }), _jsx(PopoverContent, { solid: true, align: "end", sideOffset: 8, p: 4, width: 288, maxW: "calc(100vw - 24px)", children: _jsx(YStack, { "data-slot": "summary", role: "dialog", "aria-label": label, self: "stretch", width: "100%", maxH: "min(70dvh, 520px)", overflowY: "auto", overflowX: "hidden", children: sections.map((s, i) => (_jsxs(YStack, { pt: i ? 8 : 0, children: [_jsx(Head, { action: s.action, children: s.title }), _jsx(Rows, { section: s, done: done })] }, s.id))) }) })] }));
|
|
68
|
+
}
|
|
69
|
+
/** Each section as a kind of tab for `Panel`: the same rows, with their second lines. */
|
|
70
|
+
export function kinds(sections, icons = {}) {
|
|
71
|
+
return sections.map((s) => ({
|
|
72
|
+
id: s.id,
|
|
73
|
+
label: s.title,
|
|
74
|
+
icon: icons[s.id],
|
|
75
|
+
render: () => (_jsxs(YStack, { gap: 1, children: [_jsx(Head, { action: s.action, children: s.title }), _jsx(Rows, { section: s, details: true })] })),
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
/** `kinds`, kept while the sections are the same. */
|
|
79
|
+
export function useKinds(sections, icons) {
|
|
80
|
+
return useMemo(() => kinds(sections, icons), [sections, icons]);
|
|
81
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Sync(): import("react").JSX.Element;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Bring repositories the GitHub connection already grants onto the forge.
|
|
4
|
+
*
|
|
5
|
+
* The list is GET /v1/provider/github/repos, narrowed to the accounts this
|
|
6
|
+
* organization added (github.ts `added`): those are the only ones the import
|
|
7
|
+
* brings repositories in through. The queue is POST
|
|
8
|
+
* /v1/provider/github/repos/import, which mirrors `owner/name` into this
|
|
9
|
+
* organization's forge in the background. An account named unread and holding
|
|
10
|
+
* no repositories is shown as needing an organization admin. One repository
|
|
11
|
+
* brought in becomes the one New starts the next run on (choice.ts `pinHub`).
|
|
12
|
+
*
|
|
13
|
+
* Its words are the reader's language (@hanzo/i18n `t`); account and
|
|
14
|
+
* repository names, and Forge, the forge's own name, are drawn as given.
|
|
15
|
+
*/
|
|
16
|
+
import { SizableText, XStack, YStack } from '@hanzo/gui';
|
|
17
|
+
import { useI18n } from '@hanzo/i18n/react';
|
|
18
|
+
import { Check, ChevronLeft, ChevronRight, Plus, X } from '@hanzogui/lucide-icons-2';
|
|
19
|
+
import { Button, Input } from '@hanzo/ui';
|
|
20
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
21
|
+
import { here, useBack } from './back.js';
|
|
22
|
+
import { Refusal } from './api/call.js';
|
|
23
|
+
import { accounts, added, bring, grants } from './api/github.js';
|
|
24
|
+
import { authorize } from './api/provider.js';
|
|
25
|
+
import { pinHub, readPending, writePending } from './choice.js';
|
|
26
|
+
import { useRead } from './data.js';
|
|
27
|
+
import { useHost, useTarget } from './host.js';
|
|
28
|
+
import { path } from './route.js';
|
|
29
|
+
const EMPTY = { repos: [], unread: [] };
|
|
30
|
+
export function Sync() {
|
|
31
|
+
const host = useHost();
|
|
32
|
+
const target = useTarget();
|
|
33
|
+
const { t } = useI18n();
|
|
34
|
+
const signed = Boolean(host.person);
|
|
35
|
+
const [q, setQ] = useState('');
|
|
36
|
+
const [owner, setOwner] = useState('');
|
|
37
|
+
const [step, setStep] = useState('pick');
|
|
38
|
+
const [picked, setPicked] = useState([]);
|
|
39
|
+
const [busy, setBusy] = useState(false);
|
|
40
|
+
const [syncing, setSyncing] = useState(false);
|
|
41
|
+
const [error, setError] = useState('');
|
|
42
|
+
// The import was refused because this organization holds no GitHub account of its own (the list is the person's).
|
|
43
|
+
const [unbound, setUnbound] = useState(false);
|
|
44
|
+
const list = useRead(signed ? () => added(target) : null, EMPTY, [target, signed]);
|
|
45
|
+
const rows = list.value.repos;
|
|
46
|
+
const orgs = useMemo(() => accounts(list.value), [list.value]);
|
|
47
|
+
const needle = q.trim().toLowerCase();
|
|
48
|
+
const shownOrgs = orgs.filter((a) => !needle || a.name.toLowerCase().includes(needle));
|
|
49
|
+
const ofOwner = rows.filter((r) => r.owner === owner);
|
|
50
|
+
const shownRepos = ofOwner.filter((r) => !needle || r.name.toLowerCase().includes(needle) || r.fullName.toLowerCase().includes(needle));
|
|
51
|
+
const chosen = rows.filter((r) => picked.includes(r.fullName));
|
|
52
|
+
const lead = chosen[0]?.name ?? '';
|
|
53
|
+
const more = Math.max(0, chosen.length - 1);
|
|
54
|
+
const dest = host.org || 'Forge';
|
|
55
|
+
const toggle = (fullName) => {
|
|
56
|
+
setPicked((cur) => (cur.includes(fullName) ? cur.filter((n) => n !== fullName) : [...cur, fullName]));
|
|
57
|
+
};
|
|
58
|
+
const selectShown = () => {
|
|
59
|
+
const names = shownRepos.map((r) => r.fullName);
|
|
60
|
+
const all = names.every((n) => picked.includes(n));
|
|
61
|
+
setPicked((cur) => (all ? cur.filter((n) => !names.includes(n)) : [...new Set([...cur, ...names])]));
|
|
62
|
+
};
|
|
63
|
+
// Coming back from GitHub's App install lands here, says what happened, and reads the list again.
|
|
64
|
+
useBack(target, signed, setError, list.reload);
|
|
65
|
+
/**
|
|
66
|
+
* Install the platform's GitHub App on another account — an organization admin's
|
|
67
|
+
* act — and come back to this page: the App, not a person's own sign-in, is what
|
|
68
|
+
* grants an organization's repositories.
|
|
69
|
+
*/
|
|
70
|
+
const addOrg = async () => {
|
|
71
|
+
setError('');
|
|
72
|
+
if (!host.admin) {
|
|
73
|
+
setError(t('An organization admin installs the GitHub App on another account.'));
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
host.open(await authorize(target, 'github', here()));
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
setError(e instanceof Refusal && e.status === 403 ? t('An organization admin installs the GitHub App on another account.') : t('GitHub could not be reached to install the App. Try again.'));
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
const send = async () => {
|
|
84
|
+
setBusy(true);
|
|
85
|
+
setError('');
|
|
86
|
+
setUnbound(false);
|
|
87
|
+
try {
|
|
88
|
+
const queued = await bring(target, picked);
|
|
89
|
+
// Each waits under the name it takes on the forge, as the import says it, else as GitHub's listing says it will.
|
|
90
|
+
const next = [
|
|
91
|
+
...readPending(host.org).filter((p) => !picked.includes(p.fullName)),
|
|
92
|
+
...chosen.map((r) => ({ fullName: r.fullName, name: queued.codebases[r.fullName.toLowerCase()] || r.codebase || r.name })),
|
|
93
|
+
];
|
|
94
|
+
writePending(host.org, next);
|
|
95
|
+
// One repository brought in is the one the person means to work on next, so
|
|
96
|
+
// New opens on it rather than on what it held before. Several say no one.
|
|
97
|
+
if (picked.length === 1 && chosen.length === 1)
|
|
98
|
+
pinHub(host.org, chosen[0]);
|
|
99
|
+
setSyncing(true);
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
// The list can be the person's own GitHub, which reaches accounts this organization has not connected; the
|
|
103
|
+
// import goes through the organization's own, and the platform's 409 says only "not connected".
|
|
104
|
+
if (e instanceof Refusal && e.status === 409) {
|
|
105
|
+
setUnbound(true);
|
|
106
|
+
setError(t('Your GitHub lists these repositories, but {place} has no GitHub account of its own to bring them in through. Add organization installs the Hanzo app on one for {place}; an account another Hanzo workspace uses has to be disconnected there first.', { place: dest }));
|
|
107
|
+
}
|
|
108
|
+
else
|
|
109
|
+
setError(e.message);
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
setBusy(false);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const back = () => {
|
|
116
|
+
host.go(path({ kind: 'screen', screen: 'projects' }));
|
|
117
|
+
};
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (!syncing)
|
|
120
|
+
return;
|
|
121
|
+
let stop = false;
|
|
122
|
+
const tick = async () => {
|
|
123
|
+
try {
|
|
124
|
+
const g = await grants(target);
|
|
125
|
+
const landed = new Set(g.repos.filter((r) => r.imported).map((r) => r.fullName));
|
|
126
|
+
const left = readPending(host.org).filter((p) => !landed.has(p.fullName));
|
|
127
|
+
writePending(host.org, left);
|
|
128
|
+
if (!stop && picked.every((n) => landed.has(n)))
|
|
129
|
+
back();
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
/* the button stays on Syncing until the next look */
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
const id = window.setInterval(() => void tick(), 4000);
|
|
136
|
+
return () => {
|
|
137
|
+
stop = true;
|
|
138
|
+
window.clearInterval(id);
|
|
139
|
+
};
|
|
140
|
+
}, [syncing, target, host.org, host.go, picked]);
|
|
141
|
+
return (_jsxs(YStack, { flex: 1, minH: 0, overflow: "scroll", children: [_jsxs(XStack, { px: "$6", pt: "$5", pb: "$2", gap: "$2", items: "center", children: [_jsx(XStack, { render: "button", "aria-label": t('Back to projects'), onPress: back, children: _jsx(SizableText, { size: "$2", color: "$soft", children: t('Projects') }) }), _jsx(SizableText, { size: "$2", color: "$soft", children: "/" }), _jsx(SizableText, { size: "$2", color: "$ink", children: t('Sync') })] }), _jsxs(YStack, { flex: 1, items: "center", justify: "center", px: "$6", pb: "$10", gap: "$5", children: [_jsxs(XStack, { justify: "center", gap: "$6", children: [_jsx(Step, { label: t('Select repositories'), done: step === 'access', current: step === 'pick' }), _jsx(Step, { label: t('Repository access'), done: false, current: step === 'access' })] }), _jsxs(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$5", bg: "$panel", px: "$6", py: "$6", gap: "$4", width: "100%", maxW: 460, children: [step === 'pick' && !owner ? (_jsxs(_Fragment, { children: [_jsxs(YStack, { gap: "$1", items: "center", children: [_jsx(SizableText, { size: "$5", color: "$ink", children: t('Select repositories') }), _jsx(SizableText, { size: "$2", color: "$soft", text: "center", children: t('Choose repositories to bring into {place}', { place: dest }) })] }), _jsxs(Panel, { children: [_jsx(Input, { value: q, onChangeText: setQ, placeholder: t('Search organizations'), "aria-label": t('Search organizations'), disabled: !signed }), signed && !(list.loading && orgs.length === 0) ? (_jsx(SizableText, { size: "$1", color: "$soft", children: orgs.length === 1 ? t('1 organization') : t('{n} organizations', { n: orgs.length }) })) : null, list.error ? _jsx(Soft, { children: t('The GitHub connection could not be read right now.') }) : null, !signed ? (_jsx(Soft, { children: t('Sign in to choose repositories the GitHub connection can read.') })) : list.loading && rows.length === 0 && orgs.length === 0 ? (_jsx(Soft, { children: t('Reading the connection…') })) : list.error && orgs.length === 0 ? null : shownOrgs.length === 0 ? (_jsx(Soft, { children: orgs.length === 0
|
|
142
|
+
? t('No GitHub account is added to {place} yet. Add organization installs the Hanzo app on one.', { place: dest })
|
|
143
|
+
: t('Nothing matches.') })) : (shownOrgs.map((a) => (_jsxs(XStack, { render: "button", "aria-label": a.blocked ? t('{name} needs an organization admin', { name: a.name }) : t('Open {name}', { name: a.name }), disabled: a.blocked, items: "center", gap: "$2", py: "$2", borderTopWidth: 1, borderColor: "$borderColor", onPress: () => {
|
|
144
|
+
setOwner(a.name);
|
|
145
|
+
setQ('');
|
|
146
|
+
}, children: [_jsx(SizableText, { flex: 1, size: "$2", color: a.blocked ? '$soft' : '$ink', numberOfLines: 1, children: a.name }), a.blocked ? (_jsx(SizableText, { size: "$1", color: "$soft", children: t('Needs organization admin') })) : (_jsx(ChevronRight, { size: 14, 'data-i18n-mirror': '' }))] }, a.name)))), _jsxs(XStack, { render: "button", "aria-label": t('Add organization'), items: "center", gap: "$2", py: "$2", onPress: () => void addOrg(), disabled: !signed, children: [_jsx(Plus, { size: 14 }), _jsx(SizableText, { size: "$2", color: "$ink", children: t('Add organization') })] })] })] })) : null, step === 'pick' && owner ? (_jsxs(_Fragment, { children: [_jsxs(YStack, { gap: "$1", items: "center", children: [_jsx(SizableText, { size: "$5", color: "$ink", children: t('Select repositories') }), _jsx(SizableText, { size: "$2", color: "$soft", text: "center", children: t('Choose repositories to bring into {place}', { place: dest }) })] }), _jsxs(Panel, { children: [_jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(XStack, { render: "button", "aria-label": t('All organizations'), onPress: () => setOwner(''), children: _jsx(ChevronLeft, { size: 16, 'data-i18n-mirror': '' }) }), _jsx(SizableText, { flex: 1, size: "$2", color: "$ink", numberOfLines: 1, children: owner })] }), _jsx(Input, { value: q, onChangeText: setQ, placeholder: t('Search repositories'), "aria-label": t('Search repositories') }), _jsxs(XStack, { justify: "space-between", items: "center", children: [_jsx(SizableText, { size: "$1", color: "$soft", children: ofOwner.length === 1 ? t('1 repository') : t('{n} repositories', { n: ofOwner.length }) }), _jsx(XStack, { render: "button", "aria-label": t('Select all'), onPress: selectShown, disabled: shownRepos.length === 0, children: _jsx(SizableText, { size: "$1", color: "$ink", children: t('Select all') }) })] }), shownRepos.length === 0 ? (_jsx(Soft, { children: t('Nothing matches.') })) : (shownRepos.map((r) => (_jsx(RepoRow, { repo: r, on: picked.includes(r.fullName), onPress: () => toggle(r.fullName) }, r.fullName)))), _jsxs(XStack, { render: "button", "aria-label": t('Grant more repositories'), items: "center", gap: "$2", py: "$2", onPress: () => void addOrg(), children: [_jsx(Plus, { size: 14 }), _jsx(SizableText, { size: "$2", color: "$ink", children: t('Add repositories') })] })] })] })) : null, step === 'access' ? (_jsxs(_Fragment, { children: [_jsxs(YStack, { gap: "$1", items: "center", children: [_jsx(SizableText, { size: "$5", color: "$ink", children: t('Repository access') }), _jsx(SizableText, { size: "$2", color: "$soft", text: "center", children: t('Review who can read these repositories') })] }), _jsxs(XStack, { gap: "$2", items: "center", children: [_jsxs(XStack, { flex: 1, items: "center", gap: "$2", px: "$3", py: "$2", rounded: "$3", borderWidth: 1, borderColor: "$borderColor", children: [_jsx(XStack, { render: "button", "aria-label": t('Clear the selection'), onPress: () => { setPicked([]); setStep('pick'); }, children: _jsx(X, { size: 12 }) }), _jsx(SizableText, { flex: 1, size: "$2", color: "$ink", numberOfLines: 1, children: more ? t('{name}, +{n} more', { name: lead, n: more }) : lead })] }), _jsx(Button, { size: "sm", variant: "outline", onPress: () => setStep('pick'), children: t('Edit') })] }), _jsxs(XStack, { justify: "space-between", gap: "$4", children: [_jsxs(YStack, { gap: "$1", children: [_jsx(SizableText, { size: "$1", color: "$soft", children: t('Who gets access') }), _jsx(SizableText, { size: "$2", color: "$ink", children: t('{name} · You', { name: host.person?.name || host.person?.email || t('You') }) })] }), _jsxs(YStack, { gap: "$1", items: "flex-end", children: [_jsx(SizableText, { size: "$1", color: "$soft", children: t('Role') }), _jsx(SizableText, { size: "$2", color: "$ink", children: host.admin ? t('Repository admin') : t('Member') })] })] }), _jsx(SizableText, { size: "$2", color: "$soft", text: "center", children: t('Anyone with access to {place}', { place: dest }) })] })) : null, error ? _jsx(Soft, { children: error }) : null, unbound && step === 'access' ? (_jsxs(Button, { width: "100%", variant: "outline", onPress: () => void addOrg(), children: [_jsx(Plus, { size: 14 }), t('Add organization')] })) : null, step === 'pick' ? (_jsx(Button, { width: "100%", disabled: !owner || picked.length === 0, onPress: () => setStep('access'), children: t('Continue') })) : (_jsxs(YStack, { gap: "$3", items: "center", width: "100%", children: [_jsx(Button, { width: "100%", disabled: busy || syncing || picked.length === 0, onPress: () => void send(), children: syncing || busy
|
|
147
|
+
? t('Syncing…')
|
|
148
|
+
: picked.length === 1
|
|
149
|
+
? t('Sync 1 repository to {place}', { place: dest })
|
|
150
|
+
: t('Sync {n} repositories to {place}', { n: picked.length, place: dest }) }), syncing ? null : (_jsx(XStack, { render: "button", "aria-label": t('Sync later'), onPress: back, children: _jsx(SizableText, { size: "$2", color: "$soft", children: t('Sync later') }) }))] })), !signed ? (_jsx(Button, { width: "100%", onPress: () => host.signIn?.(), children: t('Sign in') })) : null] })] })] }));
|
|
151
|
+
}
|
|
152
|
+
function Step({ label, done, current }) {
|
|
153
|
+
return (_jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(YStack, { width: 14, height: 14, rounded: 999, borderWidth: 1, items: "center", justify: "center", children: done ? _jsx(Check, { size: 10, color: "white" }) : null }), _jsx(SizableText, { size: "$1", color: current || done ? '$ink' : '$soft', children: label })] }));
|
|
154
|
+
}
|
|
155
|
+
function Panel({ children }) {
|
|
156
|
+
return (_jsx(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$3", px: "$3", py: "$2", gap: "$2", maxH: 360, overflow: "scroll", children: children }));
|
|
157
|
+
}
|
|
158
|
+
function Soft({ children }) {
|
|
159
|
+
return (_jsx(SizableText, { size: "$2", color: "$soft", children: children }));
|
|
160
|
+
}
|
|
161
|
+
function RepoRow({ repo, on, onPress }) {
|
|
162
|
+
const { t } = useI18n();
|
|
163
|
+
return (_jsxs(XStack, { render: "button", "aria-label": on ? t('Selected {name}', { name: repo.name }) : t('Select {name}', { name: repo.name }), "aria-pressed": on, items: "center", gap: "$2", py: "$2", borderTopWidth: 1, borderColor: "$borderColor", onPress: onPress, children: [_jsx(YStack, { width: 14, height: 14, rounded: "$1", borderWidth: 1, borderColor: on ? '$ink' : '$borderColor', bg: on ? '$ink' : 'transparent' }), _jsx(SizableText, { flex: 1, size: "$2", color: "$ink", numberOfLines: 1, children: repo.name }), repo.imported || repo.status === 'pending' ? (_jsx(SizableText, { size: "$1", color: "$soft", children: repo.imported ? (repo.status === 'conflict' ? t('On Forge · diverged') : t('On Forge')) : t('Syncing…') })) : null] }));
|
|
164
|
+
}
|