@hanzo/dev 4.0.1 → 4.2.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 +59 -0
- package/dist/builder/api/git.js +117 -0
- package/dist/builder/api/github.d.ts +230 -0
- package/dist/builder/api/github.js +373 -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 +639 -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/github-sync.d.ts +70 -0
- package/dist/builder/github-sync.js +435 -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 +604 -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 +187 -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,322 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The builder's reads, as hooks: one per thing on screen, each answering
|
|
3
|
+
* `{value, error, loading, reload}` so every pane owes the same three states.
|
|
4
|
+
*
|
|
5
|
+
* A read that fails says so and keeps what it had; a read with no person
|
|
6
|
+
* signed in is not attempted — the platform would refuse it and the refusal
|
|
7
|
+
* would read as an outage.
|
|
8
|
+
*/
|
|
9
|
+
import { phrase } from '@hanzo/i18n';
|
|
10
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
11
|
+
import { places } from './api/places.js';
|
|
12
|
+
import { projects } from './api/projects.js';
|
|
13
|
+
import { get, list, watch } from './api/sessions.js';
|
|
14
|
+
import { TALK } from './api/talk.js';
|
|
15
|
+
import { merge } from './api/turn.js';
|
|
16
|
+
import { groupSessions, syncThreadsFromSessions, threadRoot, useThreadLinks } from './thread.js';
|
|
17
|
+
/** Run `load` whenever `key` changes (and on `reload`), keeping the last good value. */
|
|
18
|
+
export function useRead(load, initial, key) {
|
|
19
|
+
const [value, setValue] = useState(initial);
|
|
20
|
+
const [error, setError] = useState(null);
|
|
21
|
+
const [loading, setLoading] = useState(Boolean(load));
|
|
22
|
+
const [tick, setTick] = useState(0);
|
|
23
|
+
const reload = useCallback(() => setTick((n) => n + 1), []);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!load) {
|
|
26
|
+
setLoading(false);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
let live = true;
|
|
30
|
+
setLoading(true);
|
|
31
|
+
load()
|
|
32
|
+
.then((v) => {
|
|
33
|
+
if (!live)
|
|
34
|
+
return;
|
|
35
|
+
setValue(v);
|
|
36
|
+
setError(null);
|
|
37
|
+
})
|
|
38
|
+
// Every read goes through the platform's client, which refuses with an Error.
|
|
39
|
+
.catch((e) => live && setError(e))
|
|
40
|
+
.finally(() => live && setLoading(false));
|
|
41
|
+
return () => {
|
|
42
|
+
live = false;
|
|
43
|
+
};
|
|
44
|
+
// `key` is the dependency list, by contract.
|
|
45
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
46
|
+
}, [...key, tick]);
|
|
47
|
+
return { value, error, loading, reload };
|
|
48
|
+
}
|
|
49
|
+
/** How long a read is waited on before the screen says it is taking too long. */
|
|
50
|
+
export const WAIT = 15_000;
|
|
51
|
+
/** A read that did not answer in time. Its message is ours, marked, so a screen drawing it through `t` says it in the reader's language. */
|
|
52
|
+
export class Slow extends Error {
|
|
53
|
+
constructor() {
|
|
54
|
+
super(phrase('Hanzo is taking too long to answer.'));
|
|
55
|
+
this.name = 'Slow';
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** What this page last read, per key, for the life of the page. */
|
|
59
|
+
const seen = new Map();
|
|
60
|
+
/**
|
|
61
|
+
* A read drawn at once from what this page last read under the same `key`, then
|
|
62
|
+
* read again behind it: stale while it revalidates, so moving between tabs is
|
|
63
|
+
* instant and a list never blanks to "reading" on the way back. A read that has
|
|
64
|
+
* not answered after `wait` ms is let go, as `Slow`. A null key reads nothing.
|
|
65
|
+
*/
|
|
66
|
+
export function useCached(key, load, initial, wait = WAIT) {
|
|
67
|
+
const [value, setValue] = useState(() => (key !== null && seen.has(key) ? seen.get(key) : initial));
|
|
68
|
+
const [error, setError] = useState(null);
|
|
69
|
+
const [loading, setLoading] = useState(key !== null);
|
|
70
|
+
const [tick, setTick] = useState(0);
|
|
71
|
+
const reload = useCallback(() => setTick((n) => n + 1), []);
|
|
72
|
+
const loader = useRef(load);
|
|
73
|
+
loader.current = load;
|
|
74
|
+
const was = useRef(key);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
// Another key (another org, another search) never shows the last one's answer or failure.
|
|
77
|
+
if (was.current !== key) {
|
|
78
|
+
was.current = key;
|
|
79
|
+
setValue(key !== null && seen.has(key) ? seen.get(key) : initial);
|
|
80
|
+
setError(null);
|
|
81
|
+
}
|
|
82
|
+
if (key === null) {
|
|
83
|
+
setLoading(false);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const ctl = new AbortController();
|
|
87
|
+
const timer = setTimeout(() => {
|
|
88
|
+
ctl.abort();
|
|
89
|
+
setError(new Slow());
|
|
90
|
+
setLoading(false);
|
|
91
|
+
}, wait);
|
|
92
|
+
setLoading(true);
|
|
93
|
+
loader
|
|
94
|
+
.current(ctl.signal)
|
|
95
|
+
.then((v) => {
|
|
96
|
+
if (ctl.signal.aborted)
|
|
97
|
+
return;
|
|
98
|
+
seen.set(key, v);
|
|
99
|
+
setValue(v);
|
|
100
|
+
setError(null);
|
|
101
|
+
setLoading(false);
|
|
102
|
+
})
|
|
103
|
+
.catch((e) => {
|
|
104
|
+
if (ctl.signal.aborted)
|
|
105
|
+
return;
|
|
106
|
+
setError(e);
|
|
107
|
+
setLoading(false);
|
|
108
|
+
})
|
|
109
|
+
.finally(() => clearTimeout(timer));
|
|
110
|
+
return () => {
|
|
111
|
+
clearTimeout(timer);
|
|
112
|
+
ctl.abort();
|
|
113
|
+
};
|
|
114
|
+
// `initial` is the empty value, read only when the key changes.
|
|
115
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
116
|
+
}, [key, tick, wait]);
|
|
117
|
+
return { value, error, loading, reload };
|
|
118
|
+
}
|
|
119
|
+
/** Last coding runs read per `api\norg`, so mounting another rail or switching tabs starts warm. */
|
|
120
|
+
const recentRuns = new Map();
|
|
121
|
+
/**
|
|
122
|
+
* The org's conversations and coding runs, newest first, kept current by the
|
|
123
|
+
* org's own session stream: a status that moves moves its dot, and one started
|
|
124
|
+
* anywhere appears. A conversation's own coding runs are in its tree, not here:
|
|
125
|
+
* the platform lists roots.
|
|
126
|
+
*/
|
|
127
|
+
export function useRecents(t, signed) {
|
|
128
|
+
const scope = signed ? `${t.api}\n${t.org ?? ''}` : null;
|
|
129
|
+
const warm = scope !== null ? recentRuns.get(scope) : undefined;
|
|
130
|
+
const threadLinks = useThreadLinks();
|
|
131
|
+
const read = useRead(signed
|
|
132
|
+
? async () => {
|
|
133
|
+
const [runs, talked] = await Promise.all([list(t, { kind: 'coding', limit: 50 }), list(t, { channel: TALK, limit: 50 })]);
|
|
134
|
+
const seen = new Set();
|
|
135
|
+
const unique = [...runs, ...talked]
|
|
136
|
+
.filter((s) => !seen.has(s.id) && Boolean(seen.add(s.id)))
|
|
137
|
+
.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
|
|
138
|
+
const links = syncThreadsFromSessions(unique);
|
|
139
|
+
const next = groupSessions(unique, links).slice(0, 50);
|
|
140
|
+
if (scope !== null)
|
|
141
|
+
recentRuns.set(scope, next);
|
|
142
|
+
return next;
|
|
143
|
+
}
|
|
144
|
+
: null, warm ?? [], [t.api, t.org, signed]);
|
|
145
|
+
const [settled, setSettled] = useState(warm !== undefined);
|
|
146
|
+
useEffect(() => {
|
|
147
|
+
setSettled(scope !== null && recentRuns.has(scope));
|
|
148
|
+
}, [scope]);
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
if (!read.loading)
|
|
151
|
+
setSettled(true);
|
|
152
|
+
}, [read.loading]);
|
|
153
|
+
const [rows, setRows] = useState(() => warm ?? read.value);
|
|
154
|
+
useEffect(() => setRows(read.value), [read.value]);
|
|
155
|
+
const grouped = useMemo(() => groupSessions(rows, threadLinks), [rows, threadLinks]);
|
|
156
|
+
const last = useRef(0);
|
|
157
|
+
// useRead's reload is the same function every render, so it never reopens the feed.
|
|
158
|
+
const again = read.reload;
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
if (!signed)
|
|
161
|
+
return;
|
|
162
|
+
// A feed of the whole org carries every agent's heartbeat, so an unseen id
|
|
163
|
+
// re-reads the list at most every five seconds.
|
|
164
|
+
const reload = () => {
|
|
165
|
+
const now = Date.now();
|
|
166
|
+
if (now - last.current < 5000)
|
|
167
|
+
return;
|
|
168
|
+
last.current = now;
|
|
169
|
+
again();
|
|
170
|
+
};
|
|
171
|
+
const ctl = new AbortController();
|
|
172
|
+
void watch(t, '', {
|
|
173
|
+
session: (s) => setRows((prev) => {
|
|
174
|
+
const rootId = threadRoot(s.id);
|
|
175
|
+
const i = prev.findIndex((r) => r.id === s.id ||
|
|
176
|
+
r.id === rootId ||
|
|
177
|
+
(s.kind === 'coding' &&
|
|
178
|
+
r.kind === 'coding' &&
|
|
179
|
+
Boolean(s.branch) &&
|
|
180
|
+
s.branch.startsWith('agent/') &&
|
|
181
|
+
r.branch === s.branch &&
|
|
182
|
+
r.repo.toLowerCase() === s.repo.toLowerCase()));
|
|
183
|
+
if (i === -1) {
|
|
184
|
+
// A session this list has not seen: re-read rather than guess its kind.
|
|
185
|
+
if (!s.kind || s.kind === 'coding')
|
|
186
|
+
reload();
|
|
187
|
+
return prev;
|
|
188
|
+
}
|
|
189
|
+
const next = prev.slice();
|
|
190
|
+
const existing = prev[i];
|
|
191
|
+
next[i] = {
|
|
192
|
+
...existing,
|
|
193
|
+
status: s.status || existing.status,
|
|
194
|
+
title: existing.id === s.id ? s.title || existing.title : existing.title || s.title,
|
|
195
|
+
branch: s.branch || existing.branch,
|
|
196
|
+
pr: s.pr || existing.pr,
|
|
197
|
+
sandbox: s.sandbox || existing.sandbox,
|
|
198
|
+
updatedAt: s.updatedAt || s.createdAt || existing.updatedAt,
|
|
199
|
+
endedAt: s.endedAt,
|
|
200
|
+
};
|
|
201
|
+
return next;
|
|
202
|
+
}),
|
|
203
|
+
open: (n) => {
|
|
204
|
+
if (n > 0)
|
|
205
|
+
reload();
|
|
206
|
+
},
|
|
207
|
+
}, ctl.signal).catch(() => {
|
|
208
|
+
/* a refused feed leaves the list as read */
|
|
209
|
+
});
|
|
210
|
+
return () => ctl.abort();
|
|
211
|
+
}, [t, signed, again]);
|
|
212
|
+
return { ...read, value: grouped, loading: read.loading && !settled };
|
|
213
|
+
}
|
|
214
|
+
export function usePlaces(t, signed) {
|
|
215
|
+
return useRead(signed ? () => places(t) : null, [], [t, signed]);
|
|
216
|
+
}
|
|
217
|
+
export function useProjects(t, signed) {
|
|
218
|
+
return useRead(signed ? () => projects(t) : null, [], [t, signed]);
|
|
219
|
+
}
|
|
220
|
+
/** A value kept in this browser, per key; storage that throws keeps it in memory. */
|
|
221
|
+
export function useKept(key, initial) {
|
|
222
|
+
const [value, setValue] = useState(() => {
|
|
223
|
+
try {
|
|
224
|
+
const raw = window.localStorage.getItem(key);
|
|
225
|
+
return raw === null ? initial : JSON.parse(raw);
|
|
226
|
+
}
|
|
227
|
+
catch {
|
|
228
|
+
return initial;
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
const set = useCallback((v) => {
|
|
232
|
+
setValue(v);
|
|
233
|
+
try {
|
|
234
|
+
window.localStorage.setItem(key, JSON.stringify(v));
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
/* kept for this page only */
|
|
238
|
+
}
|
|
239
|
+
}, [key]);
|
|
240
|
+
return [value, set];
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* One run: the recorded detail, then the live feed added to it. A reconnect
|
|
244
|
+
* after a drop re-reads the detail — frames missed while dropped are only in
|
|
245
|
+
* the record. `id` null reads nothing.
|
|
246
|
+
*/
|
|
247
|
+
export function useRun(t, id) {
|
|
248
|
+
const detail = useRead(id ? () => get(t, id, { limit: 500 }) : null, null, [t, id]);
|
|
249
|
+
const [live, setLive] = useState([]);
|
|
250
|
+
const [pushed, setPushed] = useState(null);
|
|
251
|
+
const [refused, setRefused] = useState('');
|
|
252
|
+
const reload = useRef(detail.reload);
|
|
253
|
+
reload.current = detail.reload;
|
|
254
|
+
const seenId = useRef(null);
|
|
255
|
+
const highestSeq = useRef(0);
|
|
256
|
+
if (seenId.current !== id) {
|
|
257
|
+
seenId.current = id;
|
|
258
|
+
highestSeq.current = 0;
|
|
259
|
+
}
|
|
260
|
+
if (detail.value && detail.value.id === id) {
|
|
261
|
+
for (const e of detail.value.recent) {
|
|
262
|
+
if (e.sessionId === id && e.seq > highestSeq.current)
|
|
263
|
+
highestSeq.current = e.seq;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// The stream is followed by the run's tree: a conversation's coding run is in the
|
|
267
|
+
// conversation's (talk.ts), and its frames carry that root.
|
|
268
|
+
const root = (detail.value?.id === id && detail.value.root) || id;
|
|
269
|
+
useEffect(() => {
|
|
270
|
+
setLive([]);
|
|
271
|
+
setPushed(null);
|
|
272
|
+
setRefused('');
|
|
273
|
+
if (!id || !root)
|
|
274
|
+
return;
|
|
275
|
+
const ctl = new AbortController();
|
|
276
|
+
void watch(t, root, {
|
|
277
|
+
// A frame from a stream this run has already left is not this run's.
|
|
278
|
+
event: (e) => {
|
|
279
|
+
if (!ctl.signal.aborted && e.sessionId === id) {
|
|
280
|
+
if (e.seq > highestSeq.current)
|
|
281
|
+
highestSeq.current = e.seq;
|
|
282
|
+
setLive((prev) => [...prev, e]);
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
session: (s) => {
|
|
286
|
+
if (!ctl.signal.aborted && s.id === id)
|
|
287
|
+
setPushed(s);
|
|
288
|
+
},
|
|
289
|
+
// A reconnect may have missed frames, and so may the move to the run's
|
|
290
|
+
// own tree once its read named one: either is read again.
|
|
291
|
+
open: (n) => {
|
|
292
|
+
if (n > 0 || root !== id)
|
|
293
|
+
reload.current();
|
|
294
|
+
},
|
|
295
|
+
}, ctl.signal, { after: root === id ? highestSeq.current : 0 }).catch((e) => setRefused(e.message));
|
|
296
|
+
return () => ctl.abort();
|
|
297
|
+
}, [t, id, root]);
|
|
298
|
+
// The read and the frames describe THIS run or nothing: a read kept from the
|
|
299
|
+
// run before (it stays until the next one lands, or forever if it fails) must
|
|
300
|
+
// not lend this run its pull request.
|
|
301
|
+
const read = detail.value && detail.value.id === id ? detail.value : null;
|
|
302
|
+
const frame = pushed && pushed.id === id ? pushed : null;
|
|
303
|
+
const events = useMemo(() => merge(read?.recent ?? [], live), [read, live]);
|
|
304
|
+
// A frame newer than the read wins; the read fills what a frame left empty.
|
|
305
|
+
const record = useMemo(() => {
|
|
306
|
+
const base = read;
|
|
307
|
+
const pushed = frame;
|
|
308
|
+
if (!pushed)
|
|
309
|
+
return base;
|
|
310
|
+
if (!base)
|
|
311
|
+
return pushed;
|
|
312
|
+
return {
|
|
313
|
+
...base,
|
|
314
|
+
...pushed,
|
|
315
|
+
title: pushed.title || base.title,
|
|
316
|
+
branch: pushed.branch || base.branch,
|
|
317
|
+
pr: pushed.pr || base.pr,
|
|
318
|
+
mode: pushed.mode || base.mode,
|
|
319
|
+
};
|
|
320
|
+
}, [read, frame]);
|
|
321
|
+
return { detail, record, events, status: record?.status ?? '', refused };
|
|
322
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A design system as the composer handles it: drafted by a model, kept as a
|
|
3
|
+
* Studio brand (CSS custom properties, the form Studio's renderer reads), said to the
|
|
4
|
+
* model on every message of a conversation it is attached to, and drawn as a
|
|
5
|
+
* page to look at. Pure, so it is tested without a browser.
|
|
6
|
+
*/
|
|
7
|
+
import type { Brand } from './api/studio.ts';
|
|
8
|
+
/** What a model is asked to answer: the system in plain fields. */
|
|
9
|
+
export interface Draft {
|
|
10
|
+
name: string;
|
|
11
|
+
colors: Record<string, string>;
|
|
12
|
+
fonts: {
|
|
13
|
+
heading: string;
|
|
14
|
+
body: string;
|
|
15
|
+
mono: string;
|
|
16
|
+
};
|
|
17
|
+
/** Type sizes, px, smallest first. */
|
|
18
|
+
scale: number[];
|
|
19
|
+
/** Spacing steps, px. */
|
|
20
|
+
spacing: number[];
|
|
21
|
+
radius: Record<string, number>;
|
|
22
|
+
/** One line each: how a button, card, input, nav… looks and behaves. */
|
|
23
|
+
components: Record<string, string>;
|
|
24
|
+
voice: {
|
|
25
|
+
tone: string;
|
|
26
|
+
do: string[];
|
|
27
|
+
dont: string[];
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/** The schema the drafting call decodes under. */
|
|
31
|
+
export declare const SCHEMA: {
|
|
32
|
+
readonly type: 'object';
|
|
33
|
+
readonly additionalProperties: false;
|
|
34
|
+
readonly required: readonly ['name', 'colors', 'fonts', 'scale', 'spacing', 'radius', 'components', 'voice'];
|
|
35
|
+
readonly properties: {
|
|
36
|
+
readonly name: {
|
|
37
|
+
readonly type: 'string';
|
|
38
|
+
};
|
|
39
|
+
readonly colors: {
|
|
40
|
+
readonly type: 'object';
|
|
41
|
+
readonly additionalProperties: false;
|
|
42
|
+
readonly required: readonly ['primary', 'secondary', 'accent', 'background', 'surface', 'text', 'muted', 'border'];
|
|
43
|
+
readonly properties: {
|
|
44
|
+
[k: string]: {
|
|
45
|
+
type: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
readonly fonts: {
|
|
50
|
+
readonly type: 'object';
|
|
51
|
+
readonly additionalProperties: false;
|
|
52
|
+
readonly required: readonly ['heading', 'body', 'mono'];
|
|
53
|
+
readonly properties: {
|
|
54
|
+
readonly heading: {
|
|
55
|
+
readonly type: 'string';
|
|
56
|
+
};
|
|
57
|
+
readonly body: {
|
|
58
|
+
readonly type: 'string';
|
|
59
|
+
};
|
|
60
|
+
readonly mono: {
|
|
61
|
+
readonly type: 'string';
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
readonly scale: {
|
|
66
|
+
readonly type: 'array';
|
|
67
|
+
readonly items: {
|
|
68
|
+
readonly type: 'number';
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
readonly spacing: {
|
|
72
|
+
readonly type: 'array';
|
|
73
|
+
readonly items: {
|
|
74
|
+
readonly type: 'number';
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
readonly radius: {
|
|
78
|
+
readonly type: 'object';
|
|
79
|
+
readonly additionalProperties: false;
|
|
80
|
+
readonly required: readonly ['sm', 'md', 'lg'];
|
|
81
|
+
readonly properties: {
|
|
82
|
+
readonly sm: {
|
|
83
|
+
readonly type: 'number';
|
|
84
|
+
};
|
|
85
|
+
readonly md: {
|
|
86
|
+
readonly type: 'number';
|
|
87
|
+
};
|
|
88
|
+
readonly lg: {
|
|
89
|
+
readonly type: 'number';
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
readonly components: {
|
|
94
|
+
readonly type: 'object';
|
|
95
|
+
readonly additionalProperties: false;
|
|
96
|
+
readonly required: readonly ['button', 'card', 'input', 'nav', 'hero'];
|
|
97
|
+
readonly properties: {
|
|
98
|
+
[k: string]: {
|
|
99
|
+
type: string;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
readonly voice: {
|
|
104
|
+
readonly type: 'object';
|
|
105
|
+
readonly additionalProperties: false;
|
|
106
|
+
readonly required: readonly ['tone', 'do', 'dont'];
|
|
107
|
+
readonly properties: {
|
|
108
|
+
readonly tone: {
|
|
109
|
+
readonly type: 'string';
|
|
110
|
+
};
|
|
111
|
+
readonly do: {
|
|
112
|
+
readonly type: 'array';
|
|
113
|
+
readonly items: {
|
|
114
|
+
readonly type: 'string';
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
readonly dont: {
|
|
118
|
+
readonly type: 'array';
|
|
119
|
+
readonly items: {
|
|
120
|
+
readonly type: 'string';
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
/** A model's answer as a Draft, or why it is not one. */
|
|
128
|
+
export declare function drafted(raw: unknown): Draft | string;
|
|
129
|
+
/**
|
|
130
|
+
* A Draft as design tokens: CSS custom properties, the names @hanzo/design uses
|
|
131
|
+
* (--background, --foreground, --primary, --font-sans, …). That is the one form
|
|
132
|
+
* Studio's renderer takes (hanzo/render `tokens`: every key `--name`, every value
|
|
133
|
+
* one declaration), so a deck, a document and a page draw from the same map.
|
|
134
|
+
* The components and the voice ride along as quoted strings under their own names.
|
|
135
|
+
*/
|
|
136
|
+
export declare function tokensOf(d: Draft): Record<string, string>;
|
|
137
|
+
/** What a model is told on every message of a conversation the system is attached to. */
|
|
138
|
+
export declare function said(b: Brand): string;
|
|
139
|
+
/** The system drawn as a page: its palette, type, a button, a card, an input, its voice. */
|
|
140
|
+
export declare function preview(b: Brand): string;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/** The schema the drafting call decodes under. */
|
|
2
|
+
export const SCHEMA = {
|
|
3
|
+
type: 'object',
|
|
4
|
+
additionalProperties: false,
|
|
5
|
+
required: ['name', 'colors', 'fonts', 'scale', 'spacing', 'radius', 'components', 'voice'],
|
|
6
|
+
properties: {
|
|
7
|
+
name: { type: 'string' },
|
|
8
|
+
colors: {
|
|
9
|
+
type: 'object',
|
|
10
|
+
additionalProperties: false,
|
|
11
|
+
required: ['primary', 'secondary', 'accent', 'background', 'surface', 'text', 'muted', 'border'],
|
|
12
|
+
properties: Object.fromEntries(['primary', 'secondary', 'accent', 'background', 'surface', 'text', 'muted', 'border'].map((k) => [k, { type: 'string' }])),
|
|
13
|
+
},
|
|
14
|
+
fonts: { type: 'object', additionalProperties: false, required: ['heading', 'body', 'mono'], properties: { heading: { type: 'string' }, body: { type: 'string' }, mono: { type: 'string' } } },
|
|
15
|
+
scale: { type: 'array', items: { type: 'number' } },
|
|
16
|
+
spacing: { type: 'array', items: { type: 'number' } },
|
|
17
|
+
radius: { type: 'object', additionalProperties: false, required: ['sm', 'md', 'lg'], properties: { sm: { type: 'number' }, md: { type: 'number' }, lg: { type: 'number' } } },
|
|
18
|
+
components: {
|
|
19
|
+
type: 'object',
|
|
20
|
+
additionalProperties: false,
|
|
21
|
+
required: ['button', 'card', 'input', 'nav', 'hero'],
|
|
22
|
+
properties: Object.fromEntries(['button', 'card', 'input', 'nav', 'hero'].map((k) => [k, { type: 'string' }])),
|
|
23
|
+
},
|
|
24
|
+
voice: { type: 'object', additionalProperties: false, required: ['tone', 'do', 'dont'], properties: { tone: { type: 'string' }, do: { type: 'array', items: { type: 'string' } }, dont: { type: 'array', items: { type: 'string' } } } },
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
const HEX = /^#[0-9a-f]{3}([0-9a-f]{3})?$/i;
|
|
28
|
+
const str = (v) => (typeof v === 'string' ? v.trim() : '');
|
|
29
|
+
const obj = (v) => (v && typeof v === 'object' && !Array.isArray(v) ? v : {});
|
|
30
|
+
const nums = (v, lo, hi) => (Array.isArray(v) ? v.filter((n) => typeof n === 'number' && n >= lo && n <= hi) : []);
|
|
31
|
+
const lines = (v) => (Array.isArray(v) ? v.map(str).filter(Boolean).slice(0, 8) : []);
|
|
32
|
+
/** A model's answer as a Draft, or why it is not one. */
|
|
33
|
+
export function drafted(raw) {
|
|
34
|
+
const o = obj(raw);
|
|
35
|
+
const name = str(o.name).slice(0, 80);
|
|
36
|
+
if (!name)
|
|
37
|
+
return 'The design system has no name.';
|
|
38
|
+
const colors = Object.fromEntries(Object.entries(obj(o.colors)).filter(([, v]) => HEX.test(str(v))).map(([k, v]) => [k, str(v)]));
|
|
39
|
+
if (!colors.primary || !colors.background || !colors.text)
|
|
40
|
+
return 'The design system needs at least a primary, a background and a text colour.';
|
|
41
|
+
const f = obj(o.fonts);
|
|
42
|
+
const fonts = { heading: str(f.heading) || 'Inter', body: str(f.body) || 'Inter', mono: str(f.mono) || 'ui-monospace' };
|
|
43
|
+
const r = obj(o.radius);
|
|
44
|
+
const radius = Object.fromEntries(Object.entries(r).filter(([, v]) => typeof v === 'number' && v >= 0 && v <= 64));
|
|
45
|
+
const v = obj(o.voice);
|
|
46
|
+
return {
|
|
47
|
+
name,
|
|
48
|
+
colors,
|
|
49
|
+
fonts,
|
|
50
|
+
scale: nums(o.scale, 8, 160).slice(0, 10),
|
|
51
|
+
spacing: nums(o.spacing, 0, 256).slice(0, 12),
|
|
52
|
+
radius,
|
|
53
|
+
components: Object.fromEntries(Object.entries(obj(o.components)).map(([k, d]) => [k, str(d)]).filter(([, d]) => d)),
|
|
54
|
+
voice: { tone: str(v.tone), do: lines(v.do), dont: lines(v.dont) },
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A Draft as design tokens: CSS custom properties, the names @hanzo/design uses
|
|
59
|
+
* (--background, --foreground, --primary, --font-sans, …). That is the one form
|
|
60
|
+
* Studio's renderer takes (hanzo/render `tokens`: every key `--name`, every value
|
|
61
|
+
* one declaration), so a deck, a document and a page draw from the same map.
|
|
62
|
+
* The components and the voice ride along as quoted strings under their own names.
|
|
63
|
+
*/
|
|
64
|
+
export function tokensOf(d) {
|
|
65
|
+
// Quoted, with nothing that would make JSON escape it or end the declaration.
|
|
66
|
+
const q = (v) => JSON.stringify(v.replace(/["\\;{}<>\u0000-\u001f]|\/\*/g, ' ').slice(0, 280));
|
|
67
|
+
const c = d.colors;
|
|
68
|
+
const out = {
|
|
69
|
+
'--background': c.background,
|
|
70
|
+
'--foreground': c.text,
|
|
71
|
+
'--primary': c.primary,
|
|
72
|
+
};
|
|
73
|
+
const more = { '--secondary': c.secondary, '--accent': c.accent, '--card': c.surface, '--muted-foreground': c.muted, '--border': c.border };
|
|
74
|
+
for (const [k, v] of Object.entries(more))
|
|
75
|
+
if (v)
|
|
76
|
+
out[k] = v;
|
|
77
|
+
out['--font-display'] = d.fonts.heading;
|
|
78
|
+
out['--font-sans'] = d.fonts.body;
|
|
79
|
+
out['--font-mono'] = d.fonts.mono;
|
|
80
|
+
for (const [k, v] of Object.entries(d.radius))
|
|
81
|
+
out[`--radius-${k}`] = `${v}px`;
|
|
82
|
+
d.scale.forEach((n, i) => (out[`--text-${i}`] = `${n}px`));
|
|
83
|
+
d.spacing.forEach((n, i) => (out[`--space-${i}`] = `${n}px`));
|
|
84
|
+
for (const [k, v] of Object.entries(d.components))
|
|
85
|
+
out[`--component-${k.replace(/[^a-z0-9-]/gi, '-').toLowerCase()}`] = q(v);
|
|
86
|
+
if (d.voice.tone)
|
|
87
|
+
out['--voice-tone'] = q(d.voice.tone);
|
|
88
|
+
if (d.voice.do.length)
|
|
89
|
+
out['--voice-do'] = q(d.voice.do.join('; ').replace(/;/g, ','));
|
|
90
|
+
if (d.voice.dont.length)
|
|
91
|
+
out['--voice-dont'] = q(d.voice.dont.join('; ').replace(/;/g, ','));
|
|
92
|
+
return out;
|
|
93
|
+
}
|
|
94
|
+
/** A token's value as written, a quoted string unquoted. */
|
|
95
|
+
const value = (v) => {
|
|
96
|
+
const s = typeof v === 'string' ? v : '';
|
|
97
|
+
try {
|
|
98
|
+
return s.startsWith('"') ? String(JSON.parse(s)) : s;
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return s;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
/** The tokens whose names start `prefix`, as `name value` pairs, the prefix dropped. */
|
|
105
|
+
function pairs(tokens, prefix) {
|
|
106
|
+
return Object.entries(tokens)
|
|
107
|
+
.filter(([k]) => k.startsWith(prefix))
|
|
108
|
+
.map(([k, v]) => [k.slice(prefix.length), value(v)]);
|
|
109
|
+
}
|
|
110
|
+
/** The colours by the names a person reads them. */
|
|
111
|
+
const COLOURS = [
|
|
112
|
+
['primary', '--primary'],
|
|
113
|
+
['secondary', '--secondary'],
|
|
114
|
+
['accent', '--accent'],
|
|
115
|
+
['background', '--background'],
|
|
116
|
+
['surface', '--card'],
|
|
117
|
+
['text', '--foreground'],
|
|
118
|
+
['muted', '--muted-foreground'],
|
|
119
|
+
['border', '--border'],
|
|
120
|
+
];
|
|
121
|
+
const colours = (t) => COLOURS.filter(([, k]) => t[k]).map(([n, k]) => [n, value(t[k])]);
|
|
122
|
+
/** What a model is told on every message of a conversation the system is attached to. */
|
|
123
|
+
export function said(b) {
|
|
124
|
+
const t = b.tokens;
|
|
125
|
+
const row = (list) => list.map(([k, v]) => `${k} ${v}`).join(', ');
|
|
126
|
+
const fonts = [
|
|
127
|
+
['heading', value(t['--font-display'])],
|
|
128
|
+
['body', value(t['--font-sans'])],
|
|
129
|
+
['mono', value(t['--font-mono'])],
|
|
130
|
+
].filter(([, v]) => v);
|
|
131
|
+
const comps = pairs(t, '--component-');
|
|
132
|
+
const voice = [value(t['--voice-tone']), value(t['--voice-do']) && `do: ${value(t['--voice-do'])}`, value(t['--voice-dont']) && `don't: ${value(t['--voice-dont'])}`].filter(Boolean);
|
|
133
|
+
const parts = [
|
|
134
|
+
`Design system "${b.name}" is attached to this conversation. Everything you make — pages, apps, components, slides, images and copy — follows it exactly; never invent other colours, fonts or radii.`,
|
|
135
|
+
colours(t).length && `Colours: ${row(colours(t))}.`,
|
|
136
|
+
fonts.length && `Fonts: ${row(fonts)}.`,
|
|
137
|
+
pairs(t, '--text-').length && `Type scale: ${row(pairs(t, '--text-'))}.`,
|
|
138
|
+
pairs(t, '--space-').length && `Spacing: ${row(pairs(t, '--space-'))}.`,
|
|
139
|
+
pairs(t, '--radius-').length && `Radius: ${row(pairs(t, '--radius-'))}.`,
|
|
140
|
+
comps.length && `Components: ${comps.map(([k, v]) => `${k} — ${v}`).join(' ')}`,
|
|
141
|
+
voice.length && `Voice: ${voice.join(' | ')}`,
|
|
142
|
+
`In HTML, declare these exact custom properties on :root and use them: ${Object.keys(t).filter((k) => !k.startsWith('--component-') && !k.startsWith('--voice-')).join(', ')}. Load the fonts from Google Fonts when they are web fonts.`,
|
|
143
|
+
];
|
|
144
|
+
return parts.filter(Boolean).join('\n');
|
|
145
|
+
}
|
|
146
|
+
const esc = (s) => s.replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' })[c]);
|
|
147
|
+
/** The system drawn as a page: its palette, type, a button, a card, an input, its voice. */
|
|
148
|
+
export function preview(b) {
|
|
149
|
+
const t = b.tokens;
|
|
150
|
+
const v = (k, d) => value(t[k]) || d;
|
|
151
|
+
const sizes = pairs(t, '--text-').map(([, x]) => x);
|
|
152
|
+
const comps = pairs(t, '--component-');
|
|
153
|
+
const heading = v('--font-display', 'Inter');
|
|
154
|
+
const body = v('--font-sans', 'Inter');
|
|
155
|
+
const fonts = [heading, body].filter((x) => x && !/^ui-|system|sans-serif|serif$/i.test(x));
|
|
156
|
+
const link = fonts.length ? `<link rel="stylesheet" href="https://fonts.googleapis.com/css2?${fonts.map((x) => `family=${encodeURIComponent(x)}:wght@400;600;700`).join('&')}&display=swap">` : '';
|
|
157
|
+
const swatches = colours(t).map(([k, c]) => `<div class="sw"><span style="background:${esc(c)}"></span><b>${esc(k)}</b><code>${esc(c)}</code></div>`).join('');
|
|
158
|
+
const scale = sizes.map((x) => `<div style="font-size:${esc(x)}">${esc(b.name)} — ${esc(x)}</div>`).join('');
|
|
159
|
+
const root = Object.entries(t).filter(([k]) => !k.startsWith('--component-') && !k.startsWith('--voice-')).map(([k, x]) => `${k}:${value(x)}`).join(';');
|
|
160
|
+
return `<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${esc(b.name)}</title>${link}
|
|
161
|
+
<style>:root{${root}}
|
|
162
|
+
body{margin:0;background:var(--background);color:var(--foreground);font-family:'${esc(body)}',system-ui,sans-serif;padding:40px;line-height:1.5}
|
|
163
|
+
h1,h2{font-family:'${esc(heading)}',system-ui,sans-serif;margin:0 0 12px}h2{margin-top:40px;font-size:14px;letter-spacing:.08em;text-transform:uppercase;color:var(--muted-foreground,var(--foreground))}
|
|
164
|
+
.row{display:flex;flex-wrap:wrap;gap:16px}.sw{display:flex;flex-direction:column;gap:4px;width:120px}.sw span{height:64px;border-radius:var(--radius-md,8px);border:1px solid var(--border,var(--foreground))}.sw code{color:var(--muted-foreground);font-size:12px}
|
|
165
|
+
.btn{background:var(--primary);color:var(--background);border:0;border-radius:var(--radius-md,8px);padding:12px 20px;font:inherit;font-weight:600}.btn.ghost{background:transparent;color:var(--foreground);border:1px solid var(--border,var(--foreground))}
|
|
166
|
+
.card{background:var(--card,var(--background));border:1px solid var(--border,var(--foreground));border-radius:var(--radius-lg,16px);padding:20px;max-width:320px}input{background:var(--card,var(--background));color:var(--foreground);border:1px solid var(--border,var(--foreground));border-radius:var(--radius-sm,4px);padding:10px 12px;font:inherit;width:260px}
|
|
167
|
+
li{color:var(--muted-foreground)}</style></head><body>
|
|
168
|
+
<h1 style="font-size:40px">${esc(b.name)}</h1><p style="color:var(--muted-foreground)">${esc(value(t['--voice-tone']))}</p>
|
|
169
|
+
<h2>Colour</h2><div class="row">${swatches}</div>
|
|
170
|
+
<h2>Type</h2>${scale}
|
|
171
|
+
<h2>Components</h2><div class="row" style="align-items:flex-start"><button class="btn">Primary action</button><button class="btn ghost">Secondary</button><input placeholder="An input"><div class="card"><b>A card</b><p style="color:var(--muted-foreground);margin:8px 0 0">${esc(comps.find(([k]) => k === 'card')?.[1] ?? '')}</p></div></div>
|
|
172
|
+
<ul>${comps.map(([k, x]) => `<li><b style="color:var(--foreground)">${esc(k)}</b> — ${esc(x)}</li>`).join('')}</ul>
|
|
173
|
+
<h2>Voice</h2><p><b>Do</b>: ${esc(value(t['--voice-do']))}</p><p><b>Don't</b>: ${esc(value(t['--voice-dont']))}</p>
|
|
174
|
+
</body></html>`;
|
|
175
|
+
}
|