@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,453 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* One scheduled task: what it does and when, its switch, Run now and its runs.
|
|
4
|
+
* The list of them all is Scheduled (scheduled.tsx).
|
|
5
|
+
*
|
|
6
|
+
* -/automations/new a new one: its name, what it does, when it runs
|
|
7
|
+
* -/automations/<id> its editor, its switch, Run now and its runs
|
|
8
|
+
*
|
|
9
|
+
* Every read and write is /v1/auto/automations (api/auto.ts), the caller's
|
|
10
|
+
* own: a task is its person's, in the org the builder is in. A save sends only
|
|
11
|
+
* what changed; the switch sends `enabled` alone, so turning one on or off never
|
|
12
|
+
* changes who it runs as.
|
|
13
|
+
*
|
|
14
|
+
* Its words are the reader's language (@hanzo/i18n `t`); a task's name, its
|
|
15
|
+
* instructions, a run's summary and post and the platform's refusals are drawn
|
|
16
|
+
* as given.
|
|
17
|
+
*/
|
|
18
|
+
import { SizableText, useMedia, XStack, YStack } from '@hanzo/gui';
|
|
19
|
+
import { ChevronDown, ChevronLeft, ChevronRight, ExternalLink, Play, RotateCcw, SlidersHorizontal, Trash2 } from '@hanzogui/lucide-icons-2';
|
|
20
|
+
import { phrase } from '@hanzo/i18n';
|
|
21
|
+
import { useI18n } from '@hanzo/i18n/react';
|
|
22
|
+
import { Button, Input, Skeleton, Switch, Textarea, toast } from '@hanzo/ui';
|
|
23
|
+
import { StatusDot } from '@hanzo/ui/chat';
|
|
24
|
+
import { ModelPicker } from '@hanzo/ui/models';
|
|
25
|
+
import { ChipSelect } from '@hanzo/ui/product';
|
|
26
|
+
import { useLimits } from '@hanzo/ui/product/useLimits';
|
|
27
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
28
|
+
import { RING, RING_INSET } from './pane.js';
|
|
29
|
+
import { automation, changes, create, remove, review, runs, save, start, starters, words } from './api/auto.js';
|
|
30
|
+
import { current, subscriptions } from './api/billing.js';
|
|
31
|
+
import { SOCIAL } from './api/provider.js';
|
|
32
|
+
import { Out } from './out.js';
|
|
33
|
+
import { useSocial } from './settings/integrations.js';
|
|
34
|
+
import { Refusal, told } from './api/call.js';
|
|
35
|
+
import { ENSO, limits as readLimits, models } from './api/models.js';
|
|
36
|
+
import { Choice, Field, Sheet } from './customize/ui.js';
|
|
37
|
+
import { useRead } from './data.js';
|
|
38
|
+
import { useHost, useTarget } from './host.js';
|
|
39
|
+
import { runNow, switchOn } from './question.js';
|
|
40
|
+
import { useSpend } from './spend.js';
|
|
41
|
+
import { SOURCE } from './api/library.js';
|
|
42
|
+
import { Outputs } from './library.js';
|
|
43
|
+
import { path } from './route.js';
|
|
44
|
+
import { Confirm } from './ask.js';
|
|
45
|
+
export const zone = () => {
|
|
46
|
+
try {
|
|
47
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC';
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return 'UTC';
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
/** The lists' words are English, marked (`phrase`), and drawn through `t`. */
|
|
54
|
+
export const KINDS = [
|
|
55
|
+
{ id: 'manual', label: phrase('When I run it') },
|
|
56
|
+
{ id: 'once', label: phrase('Once') },
|
|
57
|
+
{ id: 'hourly', label: phrase('Every hour') },
|
|
58
|
+
{ id: 'daily', label: phrase('Every day') },
|
|
59
|
+
{ id: 'weekdays', label: phrase('Weekdays') },
|
|
60
|
+
{ id: 'weekly', label: phrase('Every week') },
|
|
61
|
+
{ id: 'cron', label: phrase('Cron') },
|
|
62
|
+
];
|
|
63
|
+
const DAYS = [
|
|
64
|
+
{ id: 'mon', label: phrase('Monday') },
|
|
65
|
+
{ id: 'tue', label: phrase('Tuesday') },
|
|
66
|
+
{ id: 'wed', label: phrase('Wednesday') },
|
|
67
|
+
{ id: 'thu', label: phrase('Thursday') },
|
|
68
|
+
{ id: 'fri', label: phrase('Friday') },
|
|
69
|
+
{ id: 'sat', label: phrase('Saturday') },
|
|
70
|
+
{ id: 'sun', label: phrase('Sunday') },
|
|
71
|
+
];
|
|
72
|
+
const PERMISSIONS = [
|
|
73
|
+
{ id: 'ask', label: phrase('Ask first') },
|
|
74
|
+
{ id: 'auto', label: phrase('Act on its own') },
|
|
75
|
+
];
|
|
76
|
+
/** A run's status as the rail's dot draws it, and in words (marked, drawn through `t`). */
|
|
77
|
+
export const DOT = { succeeded: 'done', failed: 'error', running: 'running', queued: 'running', review: 'paused', skipped: 'stopped', refused: 'stopped' };
|
|
78
|
+
export const WORD = {
|
|
79
|
+
succeeded: phrase('Succeeded'),
|
|
80
|
+
failed: phrase('Failed'),
|
|
81
|
+
running: phrase('Running'),
|
|
82
|
+
queued: phrase('Queued'),
|
|
83
|
+
review: phrase('Waiting for your review'),
|
|
84
|
+
skipped: phrase('Skipped'),
|
|
85
|
+
refused: phrase('Refused'),
|
|
86
|
+
};
|
|
87
|
+
const NAME = Object.fromEntries(SOCIAL.map((p) => [p.id, p.name]));
|
|
88
|
+
export const live = (s) => s === 'running' || s === 'queued';
|
|
89
|
+
/** A local date and time an hour from now, as a once schedule's `at`. */
|
|
90
|
+
const soon = () => {
|
|
91
|
+
const d = new Date(Date.now() + 3_600_000);
|
|
92
|
+
const two = (n) => String(n).padStart(2, '0');
|
|
93
|
+
return `${d.getFullYear()}-${two(d.getMonth() + 1)}-${two(d.getDate())}T${two(d.getHours())}:00`;
|
|
94
|
+
};
|
|
95
|
+
/** The schedule a kind starts from, keeping whatever of `was` still applies. */
|
|
96
|
+
export function shaped(kind, was) {
|
|
97
|
+
// A schedule that runs only when asked keeps no zone worth keeping: leaving it takes the person's own.
|
|
98
|
+
const tz = was.kind === 'manual' || !was.tz ? zone() : was.tz;
|
|
99
|
+
switch (kind) {
|
|
100
|
+
case 'manual':
|
|
101
|
+
return { kind };
|
|
102
|
+
case 'once':
|
|
103
|
+
return { kind, at: soon(), tz };
|
|
104
|
+
case 'hourly':
|
|
105
|
+
return { kind, at: `00:${(was.at ?? '00:00').slice(3) || '00'}`, tz };
|
|
106
|
+
case 'daily':
|
|
107
|
+
case 'weekdays':
|
|
108
|
+
return { kind, at: was.kind === 'hourly' || !was.at ? '09:00' : was.at, tz };
|
|
109
|
+
case 'weekly':
|
|
110
|
+
return { kind, at: was.kind === 'hourly' || !was.at ? '09:00' : was.at, day: was.day || 'mon', tz };
|
|
111
|
+
case 'cron':
|
|
112
|
+
return { kind, cron: was.cron || '0 9 * * 1-5', tz };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** What is wrong with a schedule before it is sent, or '': English, marked (`phrase`), so a screen says it through `t`. */
|
|
116
|
+
export function unready(s) {
|
|
117
|
+
if ((s.kind === 'daily' || s.kind === 'weekdays' || s.kind === 'weekly') && !/^([01]?\d|2[0-3]):[0-5]\d$/.test(s.at ?? ''))
|
|
118
|
+
return phrase('Time of day is HH:MM on a 24-hour clock.');
|
|
119
|
+
if (s.kind === 'once' && s.at && !/^\d{4}-\d{2}-\d{2}T([01]\d|2[0-3]):[0-5]\d$/.test(s.at))
|
|
120
|
+
return phrase('Once is a date and a time: YYYY-MM-DDTHH:MM.');
|
|
121
|
+
if (s.kind === 'cron' && (s.cron ?? '').trim().split(/\s+/).length !== 5)
|
|
122
|
+
return phrase('Cron is five fields: minute, hour, day of month, month, day of week.');
|
|
123
|
+
return '';
|
|
124
|
+
}
|
|
125
|
+
/** A schedule as the platform reads it: an hourly minute in two digits. */
|
|
126
|
+
export function tidy(d) {
|
|
127
|
+
const s = d.schedule;
|
|
128
|
+
if (s.kind !== 'hourly')
|
|
129
|
+
return d;
|
|
130
|
+
const m = Math.min(59, Number((s.at ?? '').slice(3)) || 0);
|
|
131
|
+
return { ...d, schedule: { ...s, at: `00:${String(m).padStart(2, '0')}` } };
|
|
132
|
+
}
|
|
133
|
+
/** A local time and date for an RFC 3339 instant. */
|
|
134
|
+
export const local = (iso) => {
|
|
135
|
+
const d = new Date(iso);
|
|
136
|
+
return Number.isNaN(d.getTime()) ? '' : d.toLocaleString(undefined, { weekday: 'short', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' });
|
|
137
|
+
};
|
|
138
|
+
/** The editor's copy of an automation: what a save compares against. */
|
|
139
|
+
const drafted = (a) => ({
|
|
140
|
+
name: a.name,
|
|
141
|
+
instructions: a.instructions,
|
|
142
|
+
model: a.model,
|
|
143
|
+
schedule: a.schedule,
|
|
144
|
+
permissions: a.permissions,
|
|
145
|
+
notify: a.notify,
|
|
146
|
+
postTo: a.postTo,
|
|
147
|
+
enabled: a.draft ? true : a.enabled,
|
|
148
|
+
source: a.source,
|
|
149
|
+
});
|
|
150
|
+
/** `next`, keeping each field of `cur` the person changed from `was` since. */
|
|
151
|
+
function rebase(cur, was, next) {
|
|
152
|
+
const out = { ...next };
|
|
153
|
+
for (const k of Object.keys(next)) {
|
|
154
|
+
if (JSON.stringify(cur[k]) !== JSON.stringify(was[k]))
|
|
155
|
+
out[k] = cur[k];
|
|
156
|
+
}
|
|
157
|
+
return out;
|
|
158
|
+
}
|
|
159
|
+
/** A run the platform refused for want of a plan: a free org with no credit for the run fee. `PLAN` says so, marked, drawn through `t`. */
|
|
160
|
+
export const unplanned = (e) => e instanceof Refusal && e.status === 402;
|
|
161
|
+
export const PLAN = phrase('Automations run on a paid plan; on Free each run needs $1 of credit, and this organization has none. Upgrade to run it.');
|
|
162
|
+
const BLANK = () => ({ name: '', instructions: '', model: null, schedule: { kind: 'manual' }, permissions: 'ask', notify: false, postTo: [], enabled: true, source: 'dev' });
|
|
163
|
+
/** When a task runs, chosen: how often, the day and time, and the zone it is read in. */
|
|
164
|
+
export function When({ s, onChange, disabled }) {
|
|
165
|
+
const { t } = useI18n();
|
|
166
|
+
const setWhen = (p) => onChange({ ...s, ...p });
|
|
167
|
+
const kinds = useMemo(() => KINDS.map((k) => ({ ...k, label: t(k.label) })), [t]);
|
|
168
|
+
const days = useMemo(() => DAYS.map((x) => ({ ...x, label: t(x.label) })), [t]);
|
|
169
|
+
const zones = useMemo(() => {
|
|
170
|
+
try {
|
|
171
|
+
return ['UTC', ...Intl.supportedValuesOf('timeZone').filter((z) => z !== 'UTC')].map((z) => ({ id: z, label: z }));
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return [{ id: 'UTC', label: 'UTC' }];
|
|
175
|
+
}
|
|
176
|
+
}, []);
|
|
177
|
+
const kind = kinds.find((k) => k.id === s.kind) ?? kinds[0];
|
|
178
|
+
return (_jsxs(XStack, { gap: "$2", flexWrap: "wrap", rowGap: "$2", items: "center", opacity: disabled ? 0.6 : 1, pointerEvents: disabled ? 'none' : 'auto', children: [_jsx(ChipSelect, { name: t('When it runs'), label: kind.label, chosen: kind, items: kinds, onChange: (k) => onChange(shaped(k.id, s)), placement: "bottom-start", width: 200 }), s.kind === 'weekly' ? _jsx(ChipSelect, { name: t('Day'), label: days.find((x) => x.id === s.day)?.label ?? t('Monday'), chosen: days.find((x) => x.id === s.day), items: days, onChange: (x) => setWhen({ day: x.id }), placement: "bottom-start", width: 180 }) : null, s.kind === 'daily' || s.kind === 'weekdays' || s.kind === 'weekly' ? (_jsx(YStack, { width: 110, children: _jsx(Input, { value: s.at ?? '', onChangeText: (v) => setWhen({ at: v.trim() }), placeholder: "09:00", "aria-label": t('Time of day'), inputMode: "text" }) })) : null, s.kind === 'once' ? (_jsx(YStack, { width: 190, children: _jsx(Input, { value: s.at ?? '', onChangeText: (v) => setWhen({ at: v.trim() }), placeholder: "2026-10-20T09:00", "aria-label": t('Date and time'), autoCapitalize: "none" }) })) : null, s.kind === 'hourly' ? (_jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(SizableText, { size: "$2", color: "$soft", children: t('at minute') }), _jsx(YStack, { width: 70, children: _jsx(Input, { value: (s.at ?? '00:00').slice(3), onChangeText: (v) => setWhen({ at: `00:${v.replace(/\D/g, '').slice(0, 2)}` }), placeholder: "00", "aria-label": t('Minute'), inputMode: "numeric" }) })] })) : null, s.kind === 'cron' ? (_jsx(YStack, { width: 200, children: _jsx(Input, { value: s.cron ?? '', onChangeText: (v) => setWhen({ cron: v }), placeholder: "0 9 * * 1-5", "aria-label": t('Cron'), autoCapitalize: "none" }) })) : null, s.kind !== 'manual' ? _jsx(ChipSelect, { name: t('Time zone'), label: s.tz || 'UTC', chosen: { id: s.tz || 'UTC', label: s.tz || 'UTC' }, items: zones, onChange: (z) => setWhen({ tz: z.id }), placeholder: t('Search zones…'), placement: "bottom-start", width: 260 }) : null] }));
|
|
179
|
+
}
|
|
180
|
+
/** One automation: what it does and when, its switch, Run now, and its runs. `new` writes one. */
|
|
181
|
+
export function Editor({ id }) {
|
|
182
|
+
const host = useHost();
|
|
183
|
+
const { t } = useI18n();
|
|
184
|
+
const target = useTarget();
|
|
185
|
+
const desktop = Boolean(useMedia().sm);
|
|
186
|
+
const spend = useSpend();
|
|
187
|
+
const signed = Boolean(host.person);
|
|
188
|
+
const fresh = id === 'new';
|
|
189
|
+
// `tick` reads the automation again; `beat` reads its runs again.
|
|
190
|
+
const [tick, setTick] = useState(0);
|
|
191
|
+
const [beat, setBeat] = useState(0);
|
|
192
|
+
const saved = useRead(signed && !fresh ? () => automation(target, id) : null, null, [target, signed, id, tick]);
|
|
193
|
+
const history = useRead(signed && !fresh ? () => runs(target, id) : null, [], [target, signed, id, beat]);
|
|
194
|
+
const catalog = useRead(signed ? () => models(target) : null, [], [target, signed]);
|
|
195
|
+
const { limits } = useLimits(signed ? (signal) => readLimits(target, signal) : null, target);
|
|
196
|
+
// `base` is what the form started from; a save sends what changed since, and only that.
|
|
197
|
+
const [base, setBase] = useState(BLANK);
|
|
198
|
+
const [d, setD] = useState(BLANK);
|
|
199
|
+
const [ready, setReady] = useState(fresh);
|
|
200
|
+
const [busy, setBusy] = useState('');
|
|
201
|
+
const [note, setNote] = useState('');
|
|
202
|
+
const [noteError, setNoteError] = useState(false);
|
|
203
|
+
const [asking, setAsking] = useState(false);
|
|
204
|
+
// Where a move away from unsaved work was headed, while it asks first; '' for nowhere.
|
|
205
|
+
const [leaving, setLeaving] = useState('');
|
|
206
|
+
const [upgrade, setUpgrade] = useState(false);
|
|
207
|
+
const [moreStarters, setMoreStarters] = useState(false);
|
|
208
|
+
const [optionsOpen, setOptionsOpen] = useState(null);
|
|
209
|
+
const [allRuns, setAllRuns] = useState(false);
|
|
210
|
+
const social = useSocial(signed, SOCIAL.filter((p) => p.posts).map((p) => p.id));
|
|
211
|
+
const subs = useRead(signed ? () => subscriptions(target) : null, [], [target, signed]);
|
|
212
|
+
// Free is what the platform says when it names no live subscription; a read that failed says nothing.
|
|
213
|
+
const free = !subs.loading && !subs.error && !current(subs.value);
|
|
214
|
+
const nameRef = useRef(null);
|
|
215
|
+
const asksRef = useRef(null);
|
|
216
|
+
const offered = useRead(signed && fresh ? () => starters(target) : null, [], [target, signed, fresh]);
|
|
217
|
+
const here = useRef(true);
|
|
218
|
+
useEffect(() => {
|
|
219
|
+
here.current = true;
|
|
220
|
+
return () => {
|
|
221
|
+
here.current = false;
|
|
222
|
+
};
|
|
223
|
+
}, []);
|
|
224
|
+
const a = saved.value;
|
|
225
|
+
// The switch of a saved automation is saved as it moves; of a new one or a draft, with the rest.
|
|
226
|
+
const switchesAlone = Boolean(a && !a.draft);
|
|
227
|
+
const change = changes(base, d);
|
|
228
|
+
if (switchesAlone)
|
|
229
|
+
delete change.enabled;
|
|
230
|
+
const dirty = Object.keys(change).length > 0;
|
|
231
|
+
// What is saved now becomes the form's start, unless the person is mid-edit: then
|
|
232
|
+
// their edit stands, and what they did not touch is not sent back over it.
|
|
233
|
+
const clean = useRef(true);
|
|
234
|
+
clean.current = !dirty;
|
|
235
|
+
useEffect(() => {
|
|
236
|
+
if (!a)
|
|
237
|
+
return;
|
|
238
|
+
if (clean.current) {
|
|
239
|
+
setBase(drafted(a));
|
|
240
|
+
setD(drafted(a));
|
|
241
|
+
}
|
|
242
|
+
setReady(true);
|
|
243
|
+
}, [a]);
|
|
244
|
+
// A run going is read every 4s; a scheduled automation's runs every 30s, so a tick's run appears.
|
|
245
|
+
const going = history.value.some((r) => live(r.status));
|
|
246
|
+
const every = going ? 4000 : a && a.enabled && a.schedule.kind !== 'manual' ? 30_000 : 0;
|
|
247
|
+
useEffect(() => {
|
|
248
|
+
if (!every)
|
|
249
|
+
return;
|
|
250
|
+
const timer = setInterval(() => setBeat((n) => n + 1), every);
|
|
251
|
+
return () => clearInterval(timer);
|
|
252
|
+
}, [every]);
|
|
253
|
+
// An edit answers what the last line asked for, so the line goes with it.
|
|
254
|
+
const set = (p) => {
|
|
255
|
+
setNote('');
|
|
256
|
+
setNoteError(false);
|
|
257
|
+
setUpgrade(false);
|
|
258
|
+
setD((x) => ({ ...x, ...p }));
|
|
259
|
+
};
|
|
260
|
+
const wrong = t(unready(d.schedule));
|
|
261
|
+
// A draft waits on its instructions: they have the focus when it opens.
|
|
262
|
+
const drafty = Boolean(a?.draft);
|
|
263
|
+
useEffect(() => {
|
|
264
|
+
if (ready && drafty)
|
|
265
|
+
asksRef.current?.focus();
|
|
266
|
+
}, [ready, drafty]);
|
|
267
|
+
const act = async (what, work) => {
|
|
268
|
+
setBusy(what);
|
|
269
|
+
setNote('');
|
|
270
|
+
setNoteError(false);
|
|
271
|
+
setUpgrade(false);
|
|
272
|
+
try {
|
|
273
|
+
await work();
|
|
274
|
+
}
|
|
275
|
+
catch (e) {
|
|
276
|
+
// Wanting a plan is said in these words only where a run was asked for.
|
|
277
|
+
const run = what === 'run' && unplanned(e);
|
|
278
|
+
setNote(run ? t(PLAN) : told(e, t));
|
|
279
|
+
setNoteError(true);
|
|
280
|
+
setUpgrade(run);
|
|
281
|
+
}
|
|
282
|
+
finally {
|
|
283
|
+
setBusy('');
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
/** What a save still needs, said, with the focus on where to give it; true when nothing. */
|
|
287
|
+
const complete = () => {
|
|
288
|
+
const ask = !d.name.trim() ? [t('Name it first.'), nameRef] : !d.instructions.trim() ? [t('Add instructions first.'), asksRef] : null;
|
|
289
|
+
if (ask) {
|
|
290
|
+
setNote(ask[0]);
|
|
291
|
+
setNoteError(true);
|
|
292
|
+
ask[1].current?.focus();
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
if (wrong) {
|
|
296
|
+
setNote(wrong);
|
|
297
|
+
setNoteError(true);
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
return true;
|
|
301
|
+
};
|
|
302
|
+
const keep = async () => {
|
|
303
|
+
// A save after which it runs, and spends, by itself where it did not before (a new one, a draft finished On, one
|
|
304
|
+
// switched on in the form) is asked first. A draft never ran, whatever its switch said.
|
|
305
|
+
// A task that runs already is switched on and off by its switch alone, which asks for itself.
|
|
306
|
+
const ran = !fresh && Boolean(a) && !a.draft && base.enabled;
|
|
307
|
+
const turning = tidy(d).enabled && (fresh || !switchesAlone) && !ran;
|
|
308
|
+
if (turning && !(await spend.ask(switchOn(d.name.trim(), t))))
|
|
309
|
+
return;
|
|
310
|
+
await act('save', async () => {
|
|
311
|
+
if (fresh) {
|
|
312
|
+
const made = await create(target, tidy(d));
|
|
313
|
+
// Only while still here: a person who left during the create stays where they went.
|
|
314
|
+
if (here.current)
|
|
315
|
+
host.go(path({ kind: 'automation', id: made.id }), { replace: true });
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const snap = d;
|
|
319
|
+
const send = changes(base, tidy(snap));
|
|
320
|
+
if (switchesAlone)
|
|
321
|
+
delete send.enabled;
|
|
322
|
+
const now = Object.keys(send).length ? await save(target, id, send) : a;
|
|
323
|
+
// What was typed while the save was in flight stands.
|
|
324
|
+
setBase(drafted(now));
|
|
325
|
+
setD((cur) => rebase(cur, snap, drafted(now)));
|
|
326
|
+
setTick((n) => n + 1);
|
|
327
|
+
setNoteError(false);
|
|
328
|
+
setNote(t('Saved.'));
|
|
329
|
+
});
|
|
330
|
+
};
|
|
331
|
+
const flip = async (on) => {
|
|
332
|
+
if (!switchesAlone)
|
|
333
|
+
return set({ enabled: on });
|
|
334
|
+
if (on && !(await spend.ask(switchOn(a.name, t))))
|
|
335
|
+
return;
|
|
336
|
+
void act('switch', async () => {
|
|
337
|
+
await save(target, id, { enabled: on });
|
|
338
|
+
setTick((n) => n + 1);
|
|
339
|
+
toast.success(on ? t('Automation turned on') : t('Automation paused'));
|
|
340
|
+
});
|
|
341
|
+
};
|
|
342
|
+
const go = async () => {
|
|
343
|
+
if (!(await spend.ask(runNow(a.name, t))))
|
|
344
|
+
return;
|
|
345
|
+
await act('run', async () => {
|
|
346
|
+
const run = await start(target, id);
|
|
347
|
+
setBeat((n) => n + 1);
|
|
348
|
+
if (run.status === 'skipped') {
|
|
349
|
+
setNote(t('Not started: the previous run is still going.'));
|
|
350
|
+
setNoteError(true);
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
toast.success(t('Run started'));
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
};
|
|
357
|
+
const leave = (how) => host.go(path({ kind: 'screen', screen: 'automations' }), how);
|
|
358
|
+
// A held post is answered once; its buttons go when it is.
|
|
359
|
+
const [answered, setAnswered] = useState(() => new Set());
|
|
360
|
+
const answer = (r, post) => act('review', async () => {
|
|
361
|
+
await review(target, id, r.id, post);
|
|
362
|
+
setAnswered((x) => new Set(x).add(r.id));
|
|
363
|
+
setBeat((n) => n + 1);
|
|
364
|
+
setTick((n) => n + 1);
|
|
365
|
+
});
|
|
366
|
+
// Unsaved work is not left without a word, wherever the move goes.
|
|
367
|
+
const away = (to) => (dirty ? setLeaving(to) : host.go(to));
|
|
368
|
+
const back = () => away(path({ kind: 'screen', screen: 'automations' }));
|
|
369
|
+
const begin = (x) => {
|
|
370
|
+
const tz = x.schedule.kind === 'manual' ? undefined : zone();
|
|
371
|
+
set({ name: x.name, instructions: x.instructions, schedule: tz ? { ...x.schedule, tz } : { kind: 'manual' } });
|
|
372
|
+
asksRef.current?.focus();
|
|
373
|
+
};
|
|
374
|
+
if (!signed)
|
|
375
|
+
return _jsx(Page, { title: t('Automation'), onBack: () => leave(), says: t("Sign in to see this organization's automations.") });
|
|
376
|
+
if (!fresh && saved.error && !a)
|
|
377
|
+
return _jsx(Page, { title: t('Automation'), onBack: () => leave(), says: told(saved.error, t), error: true, onRetry: () => setTick((n) => n + 1) });
|
|
378
|
+
if (!ready)
|
|
379
|
+
return _jsx(Page, { title: t('Automation'), onBack: () => leave(), says: t('Reading the automation…'), loading: true });
|
|
380
|
+
const s = d.schedule;
|
|
381
|
+
// An automation that posts speaks for the organization: only an admin changes it.
|
|
382
|
+
const locked = !host.admin && Boolean(a?.postTo.length);
|
|
383
|
+
// A new automation or a draft has nothing to switch on until it says what to do.
|
|
384
|
+
const can = switchesAlone || Boolean(d.instructions.trim());
|
|
385
|
+
const on = switchesAlone ? Boolean(a?.enabled) : can && d.enabled;
|
|
386
|
+
const says = switchesAlone ? (on ? t('On') : t('Off')) : !can ? t('Add instructions first') : on ? t('On when saved') : t('Off when saved');
|
|
387
|
+
const state = fresh ? t('Not created yet') : dirty ? t('Unsaved changes') : '';
|
|
388
|
+
const sayId = `${id}-switch`;
|
|
389
|
+
const starterCap = 4;
|
|
390
|
+
const starterOverflow = offered.value.length > starterCap;
|
|
391
|
+
const visibleStarters = !moreStarters && starterOverflow ? offered.value.slice(0, starterCap) : offered.value;
|
|
392
|
+
const showOptions = optionsOpen ?? (desktop || Boolean(d.postTo.length));
|
|
393
|
+
const modelLabel = d.model ? (catalog.value.find((m) => m.id === d.model)?.name ?? d.model) : 'Enso';
|
|
394
|
+
const permLabel = d.permissions === 'auto' ? t('Act on its own') : t('Ask first');
|
|
395
|
+
const optionsSummary = [
|
|
396
|
+
modelLabel,
|
|
397
|
+
permLabel,
|
|
398
|
+
d.postTo.length ? t('Posts to {n}', { n: d.postTo.length }) : '',
|
|
399
|
+
d.notify ? t('Email on') : '',
|
|
400
|
+
]
|
|
401
|
+
.filter(Boolean)
|
|
402
|
+
.join(' · ');
|
|
403
|
+
const runsCap = 8;
|
|
404
|
+
const runsOverflow = history.value.length > runsCap;
|
|
405
|
+
const visibleHistory = !allRuns && runsOverflow ? history.value.slice(0, runsCap) : history.value;
|
|
406
|
+
return (_jsxs(YStack, { flex: 1, minH: 0, children: [spend.dialog, _jsxs(YStack, { shrink: 0, px: "$6", pt: "$4", pb: "$3", "$max-md": { px: '$4' }, borderBottomWidth: 1, borderColor: "$borderColor", children: [_jsxs(XStack, { width: "100%", maxW: 760, mx: "auto", items: "center", justify: "space-between", gap: "$3", flexWrap: "wrap", rowGap: "$2", children: [_jsxs(XStack, { items: "center", gap: "$2", children: [_jsxs(Button, { size: "sm", variant: "ghost", onPress: back, "aria-label": t('All scheduled tasks'), children: [_jsx(ChevronLeft, { size: 14, 'data-i18n-mirror': '' }), t('Scheduled tasks')] }), state ? (_jsx(SizableText, { size: "$1", color: "$soft", role: "status", children: state })) : null] }), _jsxs(XStack, { items: "center", gap: "$2", flexWrap: "wrap", children: [_jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(SizableText, { id: sayId, size: "$2", color: "$soft", children: says }), _jsx(Switch, { checked: on, disabled: busy === 'switch' || !can, onCheckedChange: (next) => void flip(next), "aria-label": switchesAlone ? t('{name} on', { name: a.name }) : t('On when saved'), "aria-describedby": sayId })] }), a && !a.draft ? (_jsxs(Button, { size: "sm", variant: "outline", disabled: Boolean(busy) || dirty, onPress: () => void go(), children: [_jsx(Play, { size: 14 }), busy === 'run' ? t('Starting…') : t('Run now')] })) : null, a && dirty ? (_jsxs(Button, { size: "sm", variant: "ghost", disabled: Boolean(busy), onPress: () => {
|
|
407
|
+
setBase(drafted(a));
|
|
408
|
+
setD(drafted(a));
|
|
409
|
+
setNote('');
|
|
410
|
+
setNoteError(false);
|
|
411
|
+
toast.info(t('Changes discarded'));
|
|
412
|
+
}, children: [_jsx(RotateCcw, { size: 14 }), t('Discard changes')] })) : null, _jsx(Button, { size: "sm", variant: "primary", disabled: Boolean(busy) || locked || !(fresh || drafty || dirty), onPress: () => complete() && void keep(), children: busy === 'save' ? t('Saving…') : fresh ? t('Create') : t('Save') })] })] }), note ? (_jsxs(XStack, { width: "100%", maxW: 760, mx: "auto", items: "center", gap: "$3", pt: "$2", flexWrap: "wrap", children: [_jsx(SizableText, { size: "$1", color: noteError ? 'var(--state-error)' : '$soft', role: "status", children: note }), upgrade ? (_jsx(Button, { size: "sm", variant: "outline", onPress: () => away(path({ kind: 'screen', screen: 'plans' })), children: t('See plans') })) : null] })) : null] }), _jsxs(YStack, { flex: 1, minH: 0, overflow: "scroll", px: "$6", py: "$5", children: [_jsxs(YStack, { width: "100%", maxW: 760, mx: "auto", gap: "$5", children: [locked ? (_jsx(SizableText, { size: "$1", color: "$soft", role: "note", children: t('This automation posts to the organization’s accounts, so only an org admin changes it.') })) : null, free ? (_jsxs(XStack, { items: "center", gap: "$3", px: "$3", py: "$2", rounded: "$3", borderWidth: 1, borderColor: "$borderColor", flexWrap: "wrap", rowGap: "$2", children: [_jsx(SizableText, { flex: 1, minW: 200, size: "$1", color: "$soft", children: t('Paid plans include automation runs. On the Free plan each run needs $1 of credit.') }), _jsx(Button, { size: "sm", variant: "outline", onPress: () => away(path({ kind: 'screen', screen: 'plans' })), children: t('See plans') })] })) : null, _jsxs(YStack, { gap: "$1", children: [_jsx(SizableText, { render: "h1", size: "$6", color: "$ink", numberOfLines: 1, children: fresh ? t('New automation') : a?.name }), _jsx(SizableText, { size: "$2", color: "$soft", children: fresh
|
|
413
|
+
? t('Name it, say what it should do, and when. It runs as you, in this organization.')
|
|
414
|
+
: a?.draft
|
|
415
|
+
? t('A draft: say what it should do and save it, and it runs.')
|
|
416
|
+
: [
|
|
417
|
+
t('From {product}', { product: t(SOURCE[a.source]) }),
|
|
418
|
+
words(a.schedule, t),
|
|
419
|
+
a.next && a.enabled ? t('next {when}', { when: local(a.next) }) : a.schedule.kind === 'manual' ? '' : t('off'),
|
|
420
|
+
]
|
|
421
|
+
.filter(Boolean)
|
|
422
|
+
.join(' · ') })] }), fresh && offered.value.length && !d.instructions.trim() ? (_jsxs(XStack, { gap: "$2", flexWrap: "wrap", rowGap: "$2", items: "center", children: [_jsx(SizableText, { size: "$2", color: "$soft", children: t('Start from') }), visibleStarters.map((x) => (_jsx(Button, { size: "sm", variant: "outline", onPress: () => begin(x), "aria-label": t('Start from {name}', { name: x.name }), children: x.name }, x.key))), starterOverflow ? (_jsx(XStack, { render: "button", "aria-expanded": moreStarters, onPress: () => setMoreStarters((v) => !v), px: "$2.5", py: "$1", minH: 32, items: "center", focusVisibleStyle: RING, children: _jsx(SizableText, { size: "$1", fontWeight: "500", color: "$ink", children: moreStarters ? t('Show less') : t('+{n} more', { n: offered.value.length - visibleStarters.length }) }) })) : null] })) : null, _jsx(Field, { label: t('Name'), children: _jsx(Input, { ref: nameRef, value: d.name, onChangeText: (v) => set({ name: v }), onSubmitEditing: () => asksRef.current?.focus(), placeholder: t('Morning briefing'), "aria-label": t('Automation name'), autoFocus: fresh, disabled: locked }) }), _jsx(Field, { label: t('Instructions (required)'), hint: t("What the agent does each run. It works in a Dev sandbox with this organization's connectors, MCP servers and skills."), children: _jsx(Textarea, { ref: asksRef, disabled: locked, value: d.instructions, onChangeText: (v) => set({ instructions: v }), placeholder: t('What should it do each run? For example: summarize what needs my attention today across calendar, email and messages.'), "aria-label": t('Instructions'), rows: 7 }) }), _jsx(Field, { label: t('When it runs'), hint: s.kind === 'cron' ? t('Five fields: minute, hour, day of month, month, day of week.') : s.kind === 'once' ? t('It runs at that time and then switches itself off.') : undefined, children: _jsx(When, { s: s, onChange: (next) => set({ schedule: next }), disabled: locked }) }), _jsxs(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$4", bg: "$panel", overflow: "hidden", children: [_jsxs(XStack, { render: "button", "aria-expanded": showOptions, onPress: () => setOptionsOpen(!showOptions), items: "center", gap: "$2.5", px: "$4", py: "$3", minH: 44, width: "100%", "$platform-web": { textAlign: 'start' }, focusVisibleStyle: RING_INSET, children: [_jsx(SlidersHorizontal, { size: 15, color: "$soft" }), _jsxs(YStack, { flex: 1, minW: 0, gap: "$0.5", children: [_jsx(SizableText, { size: "$2", fontWeight: "500", color: "$ink", children: t('Options & delivery') }), _jsx(SizableText, { size: "$1", color: "$soft", numberOfLines: 1, children: optionsSummary })] }), showOptions ? _jsx(ChevronDown, { size: 15, color: "$soft" }) : _jsx(ChevronRight, { size: 15, color: "$soft" })] }), showOptions ? (_jsxs(YStack, { gap: "$4", px: "$4", pb: "$4", pt: "$3", borderTopWidth: 1, borderColor: "$borderColor", children: [_jsxs(XStack, { gap: "$4", items: "flex-start", "$max-sm": { flexDirection: 'column', gap: '$3' }, children: [_jsx(YStack, { flex: 1, minW: 0, "$max-sm": { flexBasis: 'auto', grow: 0, minW: 0, width: '100%' }, children: _jsx(Field, { label: t('Model'), children: _jsx(XStack, { children: _jsx(ModelPicker, { size: "sm", name: t('Model'), models: catalog.value, scope: "chat", limits: limits, value: d.model ?? ENSO, onChange: (id) => set({ model: id === ENSO ? null : id }), loading: catalog.loading, error: catalog.error ? told(catalog.error, t) : null }) }) }) }), _jsx(YStack, { flex: 1, minW: 0, "$max-sm": { flexBasis: 'auto', grow: 0, minW: 0, width: '100%' }, children: _jsx(Field, { label: t('Permissions'), hint: d.permissions === 'auto' ? t('Works and uses connectors without stopping.') : t('Reads and researches, changes nothing, and ends with the actions it would take for you to approve.'), children: _jsx(Choice, { label: t('Permissions'), value: d.permissions, options: PERMISSIONS.map((p) => ({ ...p, label: t(p.label) })), onChange: (p) => set({ permissions: p }) }) }) })] }), _jsxs(Field, { label: t('Post to'), hint: !host.admin
|
|
423
|
+
? t('An org admin chooses where automations post: the accounts are the organization’s.')
|
|
424
|
+
: !d.postTo.length
|
|
425
|
+
? t('Turn an account on and each run’s answer is a post for it.')
|
|
426
|
+
: d.permissions === 'auto'
|
|
427
|
+
? t('Each run posts what the agent writes, as written.')
|
|
428
|
+
: t('Each run holds what the agent writes for you to post or discard.'), children: [_jsx(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$3", bg: "$background", overflow: "hidden", children: SOCIAL.filter((p) => p.posts).map((p, i) => {
|
|
429
|
+
const c = social.value[p.id];
|
|
430
|
+
const on = d.postTo.includes(p.id);
|
|
431
|
+
return (_jsxs(XStack, { items: "center", gap: "$3", px: "$3", py: "$2.5", borderTopWidth: i ? 1 : 0, borderColor: "$borderColor", children: [_jsxs(YStack, { flex: 1, minW: 0, gap: "$0.5", children: [_jsx(SizableText, { size: "$2", fontWeight: "500", color: "$ink", children: p.name }), _jsx(SizableText, { size: "$1", color: "$soft", children: social.error
|
|
432
|
+
? told(social.error, t)
|
|
433
|
+
: !c
|
|
434
|
+
? t('Reading…')
|
|
435
|
+
: c.connected
|
|
436
|
+
? c.account
|
|
437
|
+
? t('Connected as {account}', { account: c.account })
|
|
438
|
+
: t('Connected')
|
|
439
|
+
: `${c.available ? t('Not connected: an org admin connects it in Settings → Integrations.') : t(p.needs)} ${on || d.permissions === 'ask'
|
|
440
|
+
? t('Runs hold the post for you to read; posting it fails until it is connected.')
|
|
441
|
+
: t('Acting on its own, it posts only to a connected account.')}` })] }), _jsx(Switch, { checked: on, disabled: !host.admin || (!on && !c?.connected && d.permissions === 'auto'), onCheckedChange: (v) => set({ postTo: v ? [...d.postTo, p.id].sort() : d.postTo.filter((x) => x !== p.id) }), "aria-label": t('Post to {name}', { name: p.name }) })] }, p.id));
|
|
442
|
+
}) }), _jsx(XStack, { children: _jsx(Button, { size: "sm", variant: "ghost", onPress: () => away(path({ kind: 'settings', section: 'integrations' })), children: t('Connect accounts') }) })] }), _jsxs(XStack, { items: "center", gap: "$3", pt: "$2", borderTopWidth: 1, borderColor: "$borderColor", children: [_jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(SizableText, { size: "$2", fontWeight: "500", color: "$ink", children: t('Email me when a run ends') }), _jsx(SizableText, { size: "$1", color: "$soft", children: t('One line on how it went, with a link to the run.') })] }), _jsx(Switch, { checked: d.notify, onCheckedChange: (v) => set({ notify: v }), "aria-label": t('Email me when a run ends') })] })] })) : null] }), dirty && wrong && note !== wrong ? (_jsx(SizableText, { size: "$1", color: "var(--state-error)", role: "status", children: wrong })) : null, a ? (_jsxs(XStack, { items: "center", justify: "space-between", gap: "$3", pt: "$3", borderTopWidth: 1, borderColor: "$borderColor", flexWrap: "wrap", children: [_jsx(SizableText, { size: "$1", color: "$soft", children: t('Stops the schedule and deletes this automation’s run history.') }), _jsxs(Button, { size: "sm", variant: "ghost", tone: "danger", disabled: Boolean(busy), onPress: () => setAsking(true), children: [_jsx(Trash2, { size: 14 }), t('Delete')] })] })) : null, a ? (_jsxs(YStack, { gap: "$2.5", children: [_jsx(SizableText, { render: "h2", size: "$3", fontWeight: "500", color: "$ink", children: t('Runs') }), history.error && !history.value.length ? (_jsxs(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$4", bg: "$panel", px: "$4", py: "$5", gap: "$2.5", items: "flex-start", children: [_jsx(SizableText, { size: "$2", color: "var(--state-error)", children: told(history.error, t) }), _jsx(Button, { size: "sm", variant: "outline", onPress: () => setBeat((n) => n + 1), children: t('Try again') })] })) : history.loading && !history.value.length ? (_jsxs(YStack, { gap: "$2", "aria-busy": true, children: [_jsx(SizableText, { size: "$2", color: "$soft", children: t('Reading its runs…') }), _jsx(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$3", bg: "$panel", overflow: "hidden", children: [0, 1, 2].map((i) => (_jsxs(XStack, { items: "center", gap: "$3", px: "$3", py: "$2.5", borderTopWidth: i ? 1 : 0, borderColor: "$borderColor", children: [_jsx(Skeleton, { layout: "block", width: 10, height: 10, rounded: 999, shrink: 0 }), _jsxs(YStack, { flex: 1, gap: "$1.5", children: [_jsx(Skeleton, { layout: "block", width: "44%", height: 14, rounded: "$2" }), _jsx(Skeleton, { layout: "block", width: "68%", height: 12, rounded: "$2" })] })] }, i))) })] })) : !history.value.length ? (_jsx(YStack, { borderWidth: 1, borderColor: "$borderColor", rounded: "$3", bg: "$panel", px: "$4", py: "$5", children: _jsx(SizableText, { size: "$2", color: "$soft", children: a.draft ? t('It runs once its instructions are saved.') : t('No runs yet. Run now starts one.') }) })) : (_jsxs(YStack, { gap: "$2", children: [_jsx(YStack, { role: "list", borderWidth: 1, borderColor: "$borderColor", rounded: "$3", bg: "$panel", overflow: "hidden", "aria-label": t('Run history'), children: visibleHistory.map((r, i) => (_jsxs(XStack, { role: "listitem", items: "flex-start", gap: "$3", rowGap: "$2", px: "$3", py: "$2.5", borderTopWidth: i ? 1 : 0, borderColor: "$borderColor", flexWrap: "wrap", children: [_jsx(YStack, { pt: "$1", children: _jsx(StatusDot, { status: DOT[r.status] ?? 'idle' }) }), _jsxs(YStack, { flex: 1, minW: 180, gap: "$0.5", children: [_jsx(SizableText, { size: "$2", fontWeight: "500", color: "$ink", children: `${WORD[r.status] ? t(WORD[r.status]) : r.status} · ${local(r.at)}` }), _jsx(SizableText, { size: "$1", color: "$soft", "$platform-web": { whiteSpace: 'pre-wrap' }, children: r.summary || (live(r.status) ? t('Working…') : '') }), r.draft ? (_jsx(YStack, { mt: "$1.5", px: "$3", py: "$2", rounded: "$2", bg: "$raised", borderWidth: 1, borderColor: "$borderColor", role: "group", "aria-label": t('The post'), children: _jsx(SizableText, { size: "$2", color: "$ink", "$platform-web": { whiteSpace: 'pre-wrap' }, children: r.draft }) })) : null, r.outputs.length ? _jsx(Outputs, { ids: r.outputs }) : null, r.posts.map((x) => (_jsxs(XStack, { items: "center", gap: "$2", pt: "$1", children: [_jsx(SizableText, { size: "$1", color: "$ink", children: NAME[x.to] ?? x.to }), x.url ? (_jsxs(Out, { href: x.url, label: t('Open the {name} post', { name: NAME[x.to] ?? x.to }), children: [_jsx(SizableText, { size: "$1", color: "$ink", textDecorationLine: "underline", children: t('Posted · open') }), _jsx(ExternalLink, { size: 11, color: "$soft" })] })) : (_jsx(SizableText, { size: "$1", color: "var(--state-error)", children: x.error }))] }, x.to))), r.status === 'review' && host.admin && !answered.has(r.id) ? (_jsxs(XStack, { gap: "$2", pt: "$2", flexWrap: "wrap", children: [_jsx(Button, { size: "sm", variant: "primary", disabled: Boolean(busy), onPress: () => void answer(r, true), "aria-label": t('Post the post of {when}', { when: local(r.at) }), children: t('Post it') }), _jsx(Button, { size: "sm", variant: "ghost", disabled: Boolean(busy), onPress: () => void answer(r, false), "aria-label": t('Discard the post of {when}', { when: local(r.at) }), children: t('Discard') })] })) : r.status === 'review' && !host.admin ? (_jsx(SizableText, { size: "$1", color: "$soft", pt: "$1", children: t('An org admin posts or discards it.') })) : null] }), r.session ? (_jsxs(Button, { size: "sm", variant: "ghost", onPress: () => host.go(r.session), "aria-label": t('Open the Dev run of {when}', { when: local(r.at) }), children: [_jsx(ExternalLink, { size: 13 }), t('Open run')] })) : null] }, r.id))) }), runsOverflow ? (_jsx(XStack, { children: _jsx(XStack, { render: "button", "aria-expanded": allRuns, onPress: () => setAllRuns((v) => !v), px: "$2.5", py: "$1.5", minH: 32, items: "center", focusVisibleStyle: RING, children: _jsx(SizableText, { size: "$1", fontWeight: "500", color: "$soft", children: allRuns ? t('Show fewer runs') : t('Show all {n} runs', { n: history.value.length }) }) }) })) : null] }))] })) : null] }), a ? (_jsx(Confirm, { title: t('Delete {name}?', { name: a.name }), act: t('Delete'), says: t('It stops running, and its schedule and its runs go with it. A run going now is stopped.'), open: asking, onOpenChange: setAsking, run: async () => {
|
|
443
|
+
const name = a.name;
|
|
444
|
+
await remove(target, a.id);
|
|
445
|
+
toast.success(t('{name} deleted', { name }));
|
|
446
|
+
leave({ replace: true });
|
|
447
|
+
} })) : null, _jsxs(Sheet, { title: t('Leave without saving?'), open: Boolean(leaving), onOpenChange: (o) => !o && setLeaving(''), width: 420, children: [_jsx(SizableText, { size: "$2", color: "$soft", children: fresh ? t('This automation is not created yet.') : t('Your changes to this automation are not saved.') }), _jsxs(XStack, { gap: "$2", justify: "flex-end", children: [_jsx(Button, { size: "sm", variant: "ghost", onPress: () => setLeaving(''), children: t('Keep editing') }), _jsx(Button, { size: "sm", variant: "destructive", onPress: () => host.go(leaving), children: t('Leave') })] })] })] })] }));
|
|
448
|
+
}
|
|
449
|
+
/** A page with nothing to edit yet: its title and what it says come already said. */
|
|
450
|
+
function Page({ title, says, onBack, loading = false, error = false, onRetry }) {
|
|
451
|
+
const { t } = useI18n();
|
|
452
|
+
return (_jsx(YStack, { flex: 1, minH: 0, overflow: "scroll", px: "$6", py: "$6", children: _jsxs(YStack, { width: "100%", maxW: 760, mx: "auto", gap: "$4", children: [_jsx(XStack, { children: _jsxs(Button, { size: "sm", variant: "ghost", onPress: onBack, "aria-label": t('All scheduled tasks'), children: [_jsx(ChevronLeft, { size: 14, 'data-i18n-mirror': '' }), t('Scheduled tasks')] }) }), _jsx(SizableText, { render: "h1", size: "$6", color: "$ink", children: title }), _jsx(SizableText, { size: "$2", color: "$soft", children: says }), loading ? (_jsxs(YStack, { gap: "$3", "aria-busy": true, children: [_jsx(Skeleton, { layout: "block", width: "100%", height: 40, rounded: "$3" }), _jsx(Skeleton, { layout: "block", width: "100%", height: 140, rounded: "$3" }), _jsx(Skeleton, { layout: "block", width: "60%", height: 36, rounded: "$3" })] })) : null, error && onRetry ? (_jsx(XStack, { children: _jsx(Button, { size: "sm", variant: "outline", onPress: onRetry, children: t('Try again') }) })) : null] }) }));
|
|
453
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface Lock {
|
|
2
|
+
release: () => Promise<void>;
|
|
3
|
+
/** The browser fires `release` when it takes the lock back (a hidden tab, low power). */
|
|
4
|
+
addEventListener?: (type: 'release', listener: () => void) => void;
|
|
5
|
+
}
|
|
6
|
+
type Wake = {
|
|
7
|
+
wakeLock?: {
|
|
8
|
+
request: (type: 'screen') => Promise<Lock>;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
/** The lock held after asking for `on`: a new one when it is granted, none when it is refused, unsupported or let go. */
|
|
12
|
+
export declare function hold(nav: Wake, held: Lock | null, on: boolean): Promise<Lock | null>;
|
|
13
|
+
/**
|
|
14
|
+
* Ask for the lock and see it through: a lock granted after the view has closed
|
|
15
|
+
* is let go at once, and one the browser later takes back is reported to `dropped`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function grant(nav: Wake, held: Lock | null, on: boolean, closed: () => boolean, dropped: (lock: Lock) => void): Promise<Lock | null>;
|
|
18
|
+
/** [on, set]: `on` follows the lock itself, and the lock goes when the view does. */
|
|
19
|
+
export declare function useKeepAwake(): [boolean, (on: boolean) => Promise<void>];
|
|
20
|
+
export declare function KeepAwake({ on, onToggle }: {
|
|
21
|
+
on: boolean;
|
|
22
|
+
onToggle: (on: boolean) => void;
|
|
23
|
+
}): import("react").JSX.Element;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The run menu's "Keep computer awake": a checkbox row (so a screen reader hears
|
|
4
|
+
* on or off) over the browser's screen wake lock. It reads "on" only once the
|
|
5
|
+
* lock is granted, and the lock is let go when the run view closes.
|
|
6
|
+
*/
|
|
7
|
+
import { SizableText, YStack } from '@hanzo/gui';
|
|
8
|
+
import { useI18n } from '@hanzo/i18n/react';
|
|
9
|
+
import { DropdownMenuCheckboxItem } from '@hanzo/ui';
|
|
10
|
+
import { useEffect, useRef, useState } from 'react';
|
|
11
|
+
/** The lock held after asking for `on`: a new one when it is granted, none when it is refused, unsupported or let go. */
|
|
12
|
+
export async function hold(nav, held, on) {
|
|
13
|
+
if (!on) {
|
|
14
|
+
await held?.release().catch(() => undefined);
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
if (held)
|
|
18
|
+
return held;
|
|
19
|
+
try {
|
|
20
|
+
return (await nav.wakeLock?.request('screen')) ?? null;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Ask for the lock and see it through: a lock granted after the view has closed
|
|
28
|
+
* is let go at once, and one the browser later takes back is reported to `dropped`.
|
|
29
|
+
*/
|
|
30
|
+
export async function grant(nav, held, on, closed, dropped) {
|
|
31
|
+
const next = await hold(nav, held, on);
|
|
32
|
+
if (!next || next === held)
|
|
33
|
+
return next;
|
|
34
|
+
if (closed()) {
|
|
35
|
+
await next.release().catch(() => undefined);
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
next.addEventListener?.('release', () => dropped(next));
|
|
39
|
+
return next;
|
|
40
|
+
}
|
|
41
|
+
/** [on, set]: `on` follows the lock itself, and the lock goes when the view does. */
|
|
42
|
+
export function useKeepAwake() {
|
|
43
|
+
const [on, setOn] = useState(false);
|
|
44
|
+
const lock = useRef(null);
|
|
45
|
+
const closed = useRef(false);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
closed.current = false;
|
|
48
|
+
return () => {
|
|
49
|
+
closed.current = true;
|
|
50
|
+
void lock.current?.release().catch(() => undefined);
|
|
51
|
+
};
|
|
52
|
+
}, []);
|
|
53
|
+
const set = async (want) => {
|
|
54
|
+
lock.current = await grant(navigator, lock.current, want, () => closed.current, (l) => {
|
|
55
|
+
if (lock.current === l) {
|
|
56
|
+
lock.current = null;
|
|
57
|
+
setOn(false);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
if (!closed.current)
|
|
61
|
+
setOn(lock.current !== null);
|
|
62
|
+
};
|
|
63
|
+
return [on, set];
|
|
64
|
+
}
|
|
65
|
+
export function KeepAwake({ on, onToggle }) {
|
|
66
|
+
const { t } = useI18n();
|
|
67
|
+
return (_jsx(DropdownMenuCheckboxItem, { checked: on, onCheckedChange: onToggle, preventCloseOnSelect: true, children: _jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(SizableText, { size: "$2", color: "$ink", children: t('Keep computer awake') }), _jsx(SizableText, { size: "$1", color: "$soft", children: t('Only for this session') })] }) }));
|
|
68
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Target } from './api/call.ts';
|
|
2
|
+
/** The query keys a return carries its answer in. */
|
|
3
|
+
export declare const ANSWER: readonly ['complete', 'grant', 'connected', 'account', 'error', 'reason'];
|
|
4
|
+
export type Landing = {
|
|
5
|
+
kind: 'grant';
|
|
6
|
+
provider: string;
|
|
7
|
+
grant: string;
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'connected';
|
|
10
|
+
provider: string;
|
|
11
|
+
account: string;
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'error';
|
|
14
|
+
provider: string;
|
|
15
|
+
reason: string;
|
|
16
|
+
};
|
|
17
|
+
/** The answer a return carried in `search`, or null when it carried none. */
|
|
18
|
+
export declare function landed(search: string): Landing | null;
|
|
19
|
+
/** `href` without the answer keys, every other pair exactly as written; `href` itself when it carries none. */
|
|
20
|
+
export declare function clean(href: string): string;
|
|
21
|
+
/** This page's address, as a connect's return. */
|
|
22
|
+
export declare function here(): string;
|
|
23
|
+
/** A provider id as people write it. */
|
|
24
|
+
export declare const named: (id: string) => string;
|
|
25
|
+
/**
|
|
26
|
+
* Finish what a return carried, once a person is signed in: `say` gets the
|
|
27
|
+
* sentence, and `after` runs once something was connected. GitHub's own
|
|
28
|
+
* readers hear `changed` instead (api/github.ts `heard`).
|
|
29
|
+
*/
|
|
30
|
+
export declare function useBack(t: Target, signed: boolean, say: (note: string) => void, after?: () => void): void;
|