@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,463 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Three suggestions under the composer, each one person's own and each a thing
|
|
3
|
+
* done at once when pressed (`Act`): open what it names (a conversation, a run,
|
|
4
|
+
* a Studio creation, an item, an issue), send a new chat, start a Dev run, or
|
|
5
|
+
* schedule a task. None only fills the composer.
|
|
6
|
+
*
|
|
7
|
+
* Nothing here is written by hand. The rows are generated by Hanzo's own model
|
|
8
|
+
* (`MODEL`, POST /v1/chat/completions with the person's bearer, so the call is
|
|
9
|
+
* theirs like any other) from that person's activity alone: their recent
|
|
10
|
+
* conversations, their Dev runs, the org's issues and pull requests, their
|
|
11
|
+
* automations and their files. An account with no activity yet is given rows
|
|
12
|
+
* from what signup learned (its role, its use, what it said about its work),
|
|
13
|
+
* until there is activity to read. No input and no answer is no row: the model
|
|
14
|
+
* may answer none, and nothing pads it.
|
|
15
|
+
*
|
|
16
|
+
* Kept in the account (`suggest` in /v1/pref), so the rows follow the person:
|
|
17
|
+
*
|
|
18
|
+
* {at, sig, rows, dismissed} when they were made, the fingerprint of what
|
|
19
|
+
* they were made from, the rows, and the rows
|
|
20
|
+
* the person dismissed (by id)
|
|
21
|
+
*
|
|
22
|
+
* They are made again a day later, or once the activity's fingerprint has moved
|
|
23
|
+
* and the rows are at least `QUIET` old, so a busy hour asks the model once.
|
|
24
|
+
*
|
|
25
|
+
* This file is the pure half: inputs to a request, an answer to validated rows,
|
|
26
|
+
* the fingerprint and the policy. suggestions.tsx reads the sources and draws them.
|
|
27
|
+
*/
|
|
28
|
+
import { phrase } from '@hanzo/i18n';
|
|
29
|
+
import { create } from './api/auto.js';
|
|
30
|
+
import { spend, switchOn } from './question.js';
|
|
31
|
+
import { english } from './say.js';
|
|
32
|
+
export const ICONS = ['github', 'agent', 'chat', 'file', 'task'];
|
|
33
|
+
/** Hanzo's model the rows are asked of: it decodes under a strict JSON schema at api.hanzo.ai. */
|
|
34
|
+
export const MODEL = 'zen5-flash';
|
|
35
|
+
/** At most this many rows. */
|
|
36
|
+
export const MOST = 3;
|
|
37
|
+
const HOUR = 3_600_000;
|
|
38
|
+
/** Rows this old are made again whatever happened. */
|
|
39
|
+
export const DAY = 24 * HOUR;
|
|
40
|
+
/** Rows younger than this are kept even when the activity has moved. */
|
|
41
|
+
export const QUIET = HOUR;
|
|
42
|
+
/** How many dismissals are remembered. */
|
|
43
|
+
export const REMEMBER = 100;
|
|
44
|
+
/** How many of each source the model reads. */
|
|
45
|
+
export const TAKE = { conversation: 8, issue: 6, pull: 4, run: 6, automation: 4, file: 4 };
|
|
46
|
+
const str = (v) => (typeof v === 'string' ? v : '');
|
|
47
|
+
const obj = (v) => (v && typeof v === 'object' && !Array.isArray(v) ? v : {});
|
|
48
|
+
/** One line, at most `n` characters. */
|
|
49
|
+
export function line(v, n) {
|
|
50
|
+
const s = str(v).replace(/\s+/g, ' ').trim();
|
|
51
|
+
return s.length > n ? `${s.slice(0, n - 1).trimEnd()}…` : s;
|
|
52
|
+
}
|
|
53
|
+
/** An https address, or ''. A row links to nothing else. */
|
|
54
|
+
export function https(v) {
|
|
55
|
+
try {
|
|
56
|
+
const u = new URL(str(v));
|
|
57
|
+
return u.protocol === 'https:' ? u.href : '';
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return '';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** cyrb53: a 53-bit string hash, as 14 hex digits. A fingerprint, never a secret. */
|
|
64
|
+
export function hash(s) {
|
|
65
|
+
let h1 = 0xdeadbeef;
|
|
66
|
+
let h2 = 0x41c6ce57;
|
|
67
|
+
for (let i = 0; i < s.length; i++) {
|
|
68
|
+
const c = s.charCodeAt(i);
|
|
69
|
+
h1 = Math.imul(h1 ^ c, 2654435761);
|
|
70
|
+
h2 = Math.imul(h2 ^ c, 1597334677);
|
|
71
|
+
}
|
|
72
|
+
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
|
73
|
+
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
|
74
|
+
return (4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(16).padStart(14, '0');
|
|
75
|
+
}
|
|
76
|
+
const time = (iso) => {
|
|
77
|
+
const t = Date.parse(iso);
|
|
78
|
+
return Number.isFinite(t) ? t : 0;
|
|
79
|
+
};
|
|
80
|
+
/** The first line of a text. */
|
|
81
|
+
const first = (s) => s.split('\n').find((l) => l.trim()) ?? '';
|
|
82
|
+
/** The person's activity as inputs: their own runs only, each kind's newest `TAKE`. */
|
|
83
|
+
export function inputs(a) {
|
|
84
|
+
const all = [
|
|
85
|
+
...a.conversations.map((c) => ({ kind: 'conversation', key: c.id, title: c.title, state: '', text: '', href: '', to: `/chat/${encodeURIComponent(c.id)}`, updated: c.updated })),
|
|
86
|
+
...a.issues.map((i) => ({
|
|
87
|
+
kind: i.pull ? 'pull' : 'issue',
|
|
88
|
+
key: i.key,
|
|
89
|
+
title: i.title,
|
|
90
|
+
state: i.state === 'closed' ? 'closed' : i.status || 'open',
|
|
91
|
+
text: [i.repo || i.forge || i.board, first(i.body)].filter(Boolean).join(': '),
|
|
92
|
+
href: https(i.url),
|
|
93
|
+
to: https(i.url),
|
|
94
|
+
updated: i.updated,
|
|
95
|
+
})),
|
|
96
|
+
...a.runs
|
|
97
|
+
.filter((r) => a.me && r.actor === a.me)
|
|
98
|
+
.map((r) => ({
|
|
99
|
+
kind: 'run',
|
|
100
|
+
key: r.id,
|
|
101
|
+
title: r.title,
|
|
102
|
+
state: r.status,
|
|
103
|
+
text: [r.repo, r.branch].filter(Boolean).join(' @ '),
|
|
104
|
+
href: https(r.pr),
|
|
105
|
+
to: r.id,
|
|
106
|
+
updated: r.updatedAt || r.createdAt,
|
|
107
|
+
})),
|
|
108
|
+
...a.automations
|
|
109
|
+
.filter((x) => !x.draft)
|
|
110
|
+
.map((x) => ({
|
|
111
|
+
kind: 'automation',
|
|
112
|
+
key: x.id,
|
|
113
|
+
title: x.name,
|
|
114
|
+
state: x.last?.status || (x.enabled ? 'on' : 'off'),
|
|
115
|
+
text: x.last?.summary || first(x.instructions),
|
|
116
|
+
href: '',
|
|
117
|
+
to: `-/automations/${x.id}`,
|
|
118
|
+
updated: x.last?.at || x.updated,
|
|
119
|
+
})),
|
|
120
|
+
// An item opens where it was made when that has an address (a Studio creation), else in the Library at it.
|
|
121
|
+
...a.files.map((f) => ({ kind: 'file', key: f.id, title: f.name, state: f.kind, text: f.source, href: '', ...(f.origin.startsWith('/') ? { to: f.origin } : { to: '-/artifacts', item: f.id }), updated: f.updated || f.created })),
|
|
122
|
+
];
|
|
123
|
+
return pick(all);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* The seed: what the account's preferences say (`callName`, `work`,
|
|
127
|
+
* `instructions` in /v1/pref) and what signup kept on the IAM user (`onboarding`
|
|
128
|
+
* in /v1/iam/preferences: the role picked, and personal, team or enterprise).
|
|
129
|
+
*/
|
|
130
|
+
export function seed(p, iam) {
|
|
131
|
+
const o = obj(obj(iam).onboarding);
|
|
132
|
+
const out = {
|
|
133
|
+
name: line(p.callName, 60),
|
|
134
|
+
work: line(p.work, 240),
|
|
135
|
+
role: line(o.role, 80),
|
|
136
|
+
use: line(o.use, 20),
|
|
137
|
+
instructions: line(p.instructions, 400),
|
|
138
|
+
};
|
|
139
|
+
return Object.fromEntries(Object.entries(out).filter(([, v]) => v));
|
|
140
|
+
}
|
|
141
|
+
/** Each kind's newest `TAKE`, newest first overall. */
|
|
142
|
+
export function pick(all) {
|
|
143
|
+
const out = [];
|
|
144
|
+
for (const kind of Object.keys(TAKE)) {
|
|
145
|
+
out.push(...all
|
|
146
|
+
.filter((i) => i.kind === kind && i.title)
|
|
147
|
+
.sort((a, b) => time(b.updated) - time(a.updated))
|
|
148
|
+
.slice(0, TAKE[kind]));
|
|
149
|
+
}
|
|
150
|
+
return out.sort((a, b) => time(b.updated) - time(a.updated));
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* The fingerprint of what the rows are made from: each input's identity and
|
|
154
|
+
* state, and the seed. A new conversation, a closed issue or a finished run
|
|
155
|
+
* moves it; another turn in a conversation already read does not.
|
|
156
|
+
*/
|
|
157
|
+
export function sig(inputs, seed) {
|
|
158
|
+
const lines = inputs.map((i) => `${i.kind}\t${i.key}\t${i.state}`).sort();
|
|
159
|
+
const s = [seed.name, seed.work, seed.role, seed.use, seed.instructions].map((x) => x ?? '').join('\t');
|
|
160
|
+
return hash(`${lines.join('\n')}\n--\n${s}`);
|
|
161
|
+
}
|
|
162
|
+
/** Whether rows kept at `kept` are to be made again, now that the inputs read as `now`. */
|
|
163
|
+
export function due(kept, fingerprint, now) {
|
|
164
|
+
if (!kept)
|
|
165
|
+
return true;
|
|
166
|
+
const age = now - time(kept.at);
|
|
167
|
+
if (!time(kept.at) || age < 0 || age >= DAY)
|
|
168
|
+
return true;
|
|
169
|
+
return kept.sig !== fingerprint && age >= QUIET;
|
|
170
|
+
}
|
|
171
|
+
/** Whether anything newer could change kept rows yet: false while they are younger than `QUIET`. */
|
|
172
|
+
export function stale(kept, now) {
|
|
173
|
+
if (!kept)
|
|
174
|
+
return true;
|
|
175
|
+
const age = now - time(kept.at);
|
|
176
|
+
return !time(kept.at) || age < 0 || age >= QUIET;
|
|
177
|
+
}
|
|
178
|
+
/** The icon a row about `i` carries: GitHub's mark only for GitHub's own address. */
|
|
179
|
+
export function iconOf(i) {
|
|
180
|
+
switch (i.kind) {
|
|
181
|
+
case 'conversation':
|
|
182
|
+
return 'chat';
|
|
183
|
+
case 'issue':
|
|
184
|
+
case 'pull':
|
|
185
|
+
return /^https:\/\/github\.com\//.test(i.href) ? 'github' : 'task';
|
|
186
|
+
case 'run':
|
|
187
|
+
case 'automation':
|
|
188
|
+
return 'agent';
|
|
189
|
+
case 'file':
|
|
190
|
+
return 'file';
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/** What a row does, as the model names it. */
|
|
194
|
+
export const ACTIONS = ['open', 'send', 'task', 'schedule'];
|
|
195
|
+
/** The answer's shape, decoded strictly by the model. */
|
|
196
|
+
export const SCHEMA = {
|
|
197
|
+
type: 'object',
|
|
198
|
+
additionalProperties: false,
|
|
199
|
+
required: ['rows'],
|
|
200
|
+
properties: {
|
|
201
|
+
rows: {
|
|
202
|
+
type: 'array',
|
|
203
|
+
maxItems: MOST,
|
|
204
|
+
items: {
|
|
205
|
+
type: 'object',
|
|
206
|
+
additionalProperties: false,
|
|
207
|
+
required: ['icon', 'title', 'summary', 'action', 'source', 'prompt', 'every'],
|
|
208
|
+
properties: {
|
|
209
|
+
icon: { type: 'string', enum: [...ICONS] },
|
|
210
|
+
title: { type: 'string' },
|
|
211
|
+
summary: { type: 'string' },
|
|
212
|
+
action: { type: 'string', enum: [...ACTIONS] },
|
|
213
|
+
source: { type: 'string' },
|
|
214
|
+
prompt: { type: 'string' },
|
|
215
|
+
every: { type: 'string' },
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
const SYSTEM = [
|
|
222
|
+
'You choose three things for one person to do next with Hanzo, from their own recent activity, shown under the box where they type. Pressing a row DOES it at once, so every row is an action, never a draft.',
|
|
223
|
+
'Each row has one action:',
|
|
224
|
+
'- open: open the thing an activity item names (a conversation to pick up, a run to check, a creation or file to review, an issue to read). source is that item\'s key, copied exactly.',
|
|
225
|
+
'- send: start a new chat and ask prompt. Use it for a question or a piece of work a chat answers (a summary, a draft, research).',
|
|
226
|
+
'- task: start a Dev coding run on prompt, in the person\'s current project. Use it for a change to code.',
|
|
227
|
+
'- schedule: make a scheduled task that runs prompt every `every`. every is one of: hourly · daily HH:MM · weekdays HH:MM · weekly mon|tue|wed|thu|fri|sat|sun HH:MM (24-hour).',
|
|
228
|
+
'Fields:',
|
|
229
|
+
'- title: the action itself, plain words, at most 7, naming the thing: "Review poster.png in Studio", "Continue the physics chat", "Pick up the Oct 10 hello thread". Never a label and an action glued together.',
|
|
230
|
+
'- summary: one or two plain sentences of what the source says, for the hover card. Only facts from the input; never invent numbers, names or dates.',
|
|
231
|
+
'- source: for open, the key of the activity item; else "".',
|
|
232
|
+
'- prompt: for send, task and schedule, the complete message, first person, naming its source; for open, "".',
|
|
233
|
+
'- every: for schedule; else "".',
|
|
234
|
+
'- icon: github for a github.com issue or pull request, agent for a run, a task or a schedule, chat for a conversation or a send, file for a file or creation, task for any other issue.',
|
|
235
|
+
'Answer three rows: the activity first, then from what the person told us at signup (their role, their work). A row you cannot bind to one of the actions is no row. Never repeat an item under skip, and never the same item twice.',
|
|
236
|
+
].join('\n');
|
|
237
|
+
/** The chat completion that asks for rows, or null when there is nothing to make them from. */
|
|
238
|
+
export function request(inputs, seed, skip, now) {
|
|
239
|
+
const person = Object.fromEntries(Object.entries(seed).filter(([, v]) => typeof v === 'string' && v.trim()));
|
|
240
|
+
if (!inputs.length && !Object.keys(person).length)
|
|
241
|
+
return null;
|
|
242
|
+
const activity = inputs.map((i) => ({
|
|
243
|
+
key: i.key,
|
|
244
|
+
kind: i.kind,
|
|
245
|
+
title: line(i.title, 140),
|
|
246
|
+
...(i.state ? { state: i.state } : {}),
|
|
247
|
+
...(i.text ? { text: line(i.text, 240) } : {}),
|
|
248
|
+
...(i.updated ? { updated: i.updated.slice(0, 10) } : {}),
|
|
249
|
+
}));
|
|
250
|
+
return {
|
|
251
|
+
model: MODEL,
|
|
252
|
+
messages: [
|
|
253
|
+
{ role: 'system', content: SYSTEM },
|
|
254
|
+
{ role: 'user', content: JSON.stringify({ today: now.toISOString().slice(0, 10), person, activity, skip }) },
|
|
255
|
+
],
|
|
256
|
+
response_format: { type: 'json_schema', json_schema: { name: 'suggestions', strict: true, schema: SCHEMA } },
|
|
257
|
+
max_tokens: 1200,
|
|
258
|
+
temperature: 0.3,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
const DAYS = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];
|
|
262
|
+
const HHMM = /^([01]\d|2[0-3]):[0-5]\d$/;
|
|
263
|
+
/** `every` as a schedule, or null for words that are not one. */
|
|
264
|
+
export function every(v) {
|
|
265
|
+
const [kind, a, b] = v.trim().toLowerCase().split(/\s+/);
|
|
266
|
+
if (kind === 'hourly' && !a)
|
|
267
|
+
return { kind: 'hourly', at: '00:00' };
|
|
268
|
+
if ((kind === 'daily' || kind === 'weekdays') && a && HHMM.test(a) && !b)
|
|
269
|
+
return { kind, at: a };
|
|
270
|
+
if (kind === 'weekly' && a && DAYS.includes(a) && b && HHMM.test(b))
|
|
271
|
+
return { kind: 'weekly', day: a, at: b };
|
|
272
|
+
return null;
|
|
273
|
+
}
|
|
274
|
+
/** The first JSON object in a model's text: all of it, or from its first `{` to its last `}`. */
|
|
275
|
+
function json(text) {
|
|
276
|
+
try {
|
|
277
|
+
return JSON.parse(text);
|
|
278
|
+
}
|
|
279
|
+
catch {
|
|
280
|
+
const a = text.indexOf('{');
|
|
281
|
+
const b = text.lastIndexOf('}');
|
|
282
|
+
if (a < 0 || b <= a)
|
|
283
|
+
return null;
|
|
284
|
+
try {
|
|
285
|
+
return JSON.parse(text.slice(a, b + 1));
|
|
286
|
+
}
|
|
287
|
+
catch {
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
/** The text of a chat completion's first choice, or ''. */
|
|
293
|
+
export function content(raw) {
|
|
294
|
+
const choices = obj(raw).choices;
|
|
295
|
+
const first = obj(Array.isArray(choices) ? choices[0] : null);
|
|
296
|
+
return str(obj(first.message).content);
|
|
297
|
+
}
|
|
298
|
+
/** A row's id: what it opens, or its words. */
|
|
299
|
+
export const idOf = (to, title) => hash(to || title.toLowerCase());
|
|
300
|
+
/** A model's row bound to what pressing it does, or null for one that binds to nothing. */
|
|
301
|
+
function bind(o, inputs) {
|
|
302
|
+
const prompt = str(o.prompt).trim().slice(0, 2000);
|
|
303
|
+
switch (str(o.action)) {
|
|
304
|
+
case 'open': {
|
|
305
|
+
const i = inputs.find((x) => x.key === str(o.source).trim());
|
|
306
|
+
if (!i?.to)
|
|
307
|
+
return null;
|
|
308
|
+
return i.item ? { kind: 'open', to: i.to, item: i.item } : { kind: 'open', to: i.to };
|
|
309
|
+
}
|
|
310
|
+
case 'send':
|
|
311
|
+
case 'task':
|
|
312
|
+
return prompt ? { kind: str(o.action), prompt } : null;
|
|
313
|
+
case 'schedule': {
|
|
314
|
+
const when = every(str(o.every));
|
|
315
|
+
return prompt && when ? { kind: 'schedule', name: line(o.title, 80), prompt, schedule: when } : null;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
/** What a row is about, for its mark: the input it opens, if it opens one. */
|
|
321
|
+
const about = (act, inputs) => (act.kind === 'open' ? inputs.find((i) => i.to === act.to && i.item === act.item) : undefined);
|
|
322
|
+
/**
|
|
323
|
+
* The rows of a chat completion, validated: each with words and an action that
|
|
324
|
+
* binds (an open names an input's key; a send, a task or a schedule carries its
|
|
325
|
+
* prompt, and a schedule a time it reads), one row per thing, at most `MOST`.
|
|
326
|
+
* Anything else is dropped, never repaired.
|
|
327
|
+
*/
|
|
328
|
+
export function answer(raw, inputs) {
|
|
329
|
+
const rows = obj(json(content(raw))).rows;
|
|
330
|
+
const out = [];
|
|
331
|
+
for (const r of Array.isArray(rows) ? rows : []) {
|
|
332
|
+
const o = obj(r);
|
|
333
|
+
const title = line(o.title, 80).replace(/\.$/, '');
|
|
334
|
+
const act = bind(o, inputs);
|
|
335
|
+
if (!title || !act)
|
|
336
|
+
continue;
|
|
337
|
+
const source = about(act, inputs);
|
|
338
|
+
// GitHub's mark only beside GitHub's own address: anything else is a task at most.
|
|
339
|
+
const named = ICONS.includes(o.icon) ? o.icon : 'chat';
|
|
340
|
+
const icon = source ? iconOf(source) : named === 'github' ? 'task' : named;
|
|
341
|
+
const id = idOf(act.kind === 'open' ? `${act.to}${act.item ?? ''}` : '', title);
|
|
342
|
+
if (out.some((x) => x.id === id))
|
|
343
|
+
continue;
|
|
344
|
+
out.push({ id, icon, title, summary: line(o.summary, 600), act });
|
|
345
|
+
if (out.length === MOST)
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
return out;
|
|
349
|
+
}
|
|
350
|
+
/** A kept action, or null for one that does not read as one. */
|
|
351
|
+
function actOf(raw) {
|
|
352
|
+
const o = obj(raw);
|
|
353
|
+
const prompt = str(o.prompt);
|
|
354
|
+
switch (str(o.kind)) {
|
|
355
|
+
case 'open':
|
|
356
|
+
return str(o.to) ? { kind: 'open', to: str(o.to), ...(str(o.item) ? { item: str(o.item) } : {}) } : null;
|
|
357
|
+
case 'send':
|
|
358
|
+
case 'task':
|
|
359
|
+
return prompt ? { kind: str(o.kind), prompt } : null;
|
|
360
|
+
case 'schedule': {
|
|
361
|
+
const sc = obj(o.schedule);
|
|
362
|
+
const kind = str(sc.kind);
|
|
363
|
+
return prompt && kind ? { kind: 'schedule', name: str(o.name), prompt, schedule: { kind, ...(str(sc.at) ? { at: str(sc.at) } : {}), ...(str(sc.day) ? { day: str(sc.day) } : {}) } } : null;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
/** One kept row, or null for one that does not read as a row (a row from before rows were actions, among them). */
|
|
369
|
+
function row(raw) {
|
|
370
|
+
const o = obj(raw);
|
|
371
|
+
const title = str(o.title);
|
|
372
|
+
const act = actOf(o.act);
|
|
373
|
+
if (!title || !act)
|
|
374
|
+
return null;
|
|
375
|
+
return {
|
|
376
|
+
id: str(o.id) || idOf(act.kind === 'open' ? act.to : '', title),
|
|
377
|
+
icon: ICONS.includes(o.icon) ? o.icon : 'chat',
|
|
378
|
+
title,
|
|
379
|
+
summary: str(o.summary),
|
|
380
|
+
act,
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
/** The `suggest` key of the preference document, or undefined when it holds none. */
|
|
384
|
+
export function kept(raw) {
|
|
385
|
+
const o = obj(raw);
|
|
386
|
+
if (!Object.keys(o).length)
|
|
387
|
+
return undefined;
|
|
388
|
+
return {
|
|
389
|
+
at: str(o.at),
|
|
390
|
+
sig: str(o.sig),
|
|
391
|
+
rows: (Array.isArray(o.rows) ? o.rows : []).map(row).filter((r) => r !== null).slice(0, MOST),
|
|
392
|
+
dismissed: (Array.isArray(o.dismissed) ? o.dismissed : []).filter((x) => typeof x === 'string' && x !== '').slice(0, REMEMBER),
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
/** The rows to draw: those not dismissed. */
|
|
396
|
+
export const shown = (k) => (k ? k.rows.filter((r) => !k.dismissed.includes(r.id)).slice(0, MOST) : []);
|
|
397
|
+
/**
|
|
398
|
+
* What Hanzo does, three ways in, each done at once: what fills the rows a
|
|
399
|
+
* person's activity and signup do not. The one copy here that is authored, so
|
|
400
|
+
* its words are marked (`phrase`) and drawn in the reader's language, the
|
|
401
|
+
* prompt too: it is sent as their message and shown as theirs.
|
|
402
|
+
*
|
|
403
|
+
* Dev's starter asks before it builds. A press names no project, no audience
|
|
404
|
+
* and no content, and a model handed "build a landing site for my project"
|
|
405
|
+
* with none of that invents all three: it built a Hanzo AI showcase nobody
|
|
406
|
+
* asked for (hanzo-inc/app#442). So the press starts the conversation about
|
|
407
|
+
* the page, and the build follows the answers.
|
|
408
|
+
*/
|
|
409
|
+
export const STARTERS = [
|
|
410
|
+
{ id: 'start:chat', icon: 'chat', title: phrase('Ask what Hanzo can do for you'), summary: '', act: { kind: 'send', prompt: phrase('What can you do for me? Give me three concrete things to try today.') } },
|
|
411
|
+
{ id: 'start:dev', icon: 'agent', title: phrase('Build a landing page with Dev'), summary: '', act: { kind: 'task', prompt: phrase('I want a one-page landing page. Before you build anything, ask me what it is for, who it is for and what it should say.') } },
|
|
412
|
+
{ id: 'start:research', icon: 'file', title: phrase('Get a cited brief on AI agents'), summary: '', act: { kind: 'send', prompt: phrase('Research the state of AI coding agents this month and give me a short brief with sources.') } },
|
|
413
|
+
];
|
|
414
|
+
/** Whether a row is a starter: authored, so drawn through `t`; every other row is the person's own words. */
|
|
415
|
+
export const starter = (r) => STARTERS.some((s) => s.id === r.id);
|
|
416
|
+
/** The kept rows, filled to `MOST` with the starters not dismissed: never one lonely row. */
|
|
417
|
+
export const fill = (k) => {
|
|
418
|
+
if (!k)
|
|
419
|
+
return [];
|
|
420
|
+
const rows = shown(k);
|
|
421
|
+
return [...rows, ...STARTERS.filter((r) => !k.dismissed.includes(r.id))].slice(0, Math.max(rows.length, MOST));
|
|
422
|
+
};
|
|
423
|
+
/** `k` with `id` dismissed: remembered first, the oldest forgotten past `REMEMBER`. */
|
|
424
|
+
export function dismissed(k, id) {
|
|
425
|
+
return { ...k, dismissed: [id, ...k.dismissed.filter((x) => x !== id)].slice(0, REMEMBER) };
|
|
426
|
+
}
|
|
427
|
+
/** The addresses and titles of dismissed rows the model is told to skip. */
|
|
428
|
+
export function skip(k, inputs) {
|
|
429
|
+
if (!k)
|
|
430
|
+
return [];
|
|
431
|
+
const gone = new Set(k.dismissed);
|
|
432
|
+
const out = new Set();
|
|
433
|
+
for (const i of inputs)
|
|
434
|
+
if (i.to && gone.has(idOf(`${i.to}${i.item ?? ''}`, '')))
|
|
435
|
+
out.add(i.key);
|
|
436
|
+
for (const r of k.rows)
|
|
437
|
+
if (gone.has(r.id))
|
|
438
|
+
out.add(r.title);
|
|
439
|
+
return [...out];
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Make a `schedule` row's task: on, asking before it acts, and notifying its person. It runs, and spends, by itself
|
|
443
|
+
* from then, so the person is asked first through the host's confirm (host.tsx `Host.confirm`, the same function);
|
|
444
|
+
* on anything but a yes nothing is made and the answer is null.
|
|
445
|
+
*/
|
|
446
|
+
export async function book(t, act, source, confirm, say = english) {
|
|
447
|
+
const name = act.name || act.prompt.slice(0, 80);
|
|
448
|
+
const asked = switchOn(name, say);
|
|
449
|
+
const yes = await confirm(spend(asked)).catch(() => false);
|
|
450
|
+
if (yes !== true)
|
|
451
|
+
return null;
|
|
452
|
+
return create(t, {
|
|
453
|
+
name,
|
|
454
|
+
instructions: act.prompt,
|
|
455
|
+
model: null,
|
|
456
|
+
schedule: { ...act.schedule, tz: Intl.DateTimeFormat().resolvedOptions().timeZone },
|
|
457
|
+
permissions: 'ask',
|
|
458
|
+
notify: true,
|
|
459
|
+
postTo: [],
|
|
460
|
+
enabled: true,
|
|
461
|
+
source,
|
|
462
|
+
});
|
|
463
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type Target } from './api/call.ts';
|
|
2
|
+
import { type Act, type Suggestion } from './suggest.ts';
|
|
3
|
+
/**
|
|
4
|
+
* The account's switch as last read: `none` until it is (and for a guest), `on` only when the person turned them on.
|
|
5
|
+
* Unset is off.
|
|
6
|
+
*/
|
|
7
|
+
export type Switch = 'none' | 'on' | 'off';
|
|
8
|
+
export interface Suggested {
|
|
9
|
+
/** The rows to draw: three when any are, none dismissed. */
|
|
10
|
+
rows: Suggestion[];
|
|
11
|
+
/** Dismiss one, remembered by the account. */
|
|
12
|
+
dismiss: (id: string) => void;
|
|
13
|
+
/** The account's switch: `none` for a guest or until it is read; off unless the person turned them on. */
|
|
14
|
+
state: Switch;
|
|
15
|
+
/** Turn suggestions on or off for the account (`setSuggestions`). */
|
|
16
|
+
turn: (on: boolean) => void;
|
|
17
|
+
/** Why the rows could not be read, made or kept, in the platform's words. */
|
|
18
|
+
error: string | null;
|
|
19
|
+
}
|
|
20
|
+
/** The person's suggestions. Signed out, or with nothing worth saying, there are none. */
|
|
21
|
+
export declare function useSuggestions(t: Target): Suggested;
|
|
22
|
+
/**
|
|
23
|
+
* THE one way to turn suggestions on or off: the account's `suggestions` preference, so the switch follows the
|
|
24
|
+
* person across devices and every `useSuggestions` on the page obeys at once. Off calls off a run in flight before
|
|
25
|
+
* it sends anything more, waits out a save it already sent so nothing is saved back after, and forgets the rows
|
|
26
|
+
* kept from their activity. On, they are read and made.
|
|
27
|
+
*/
|
|
28
|
+
export declare function setSuggestions(t: Target, on: boolean): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Leave `prompt` for the product `kind` names, which does it on arrival, once:
|
|
31
|
+
* Chat sends a `send` as a new chat, Dev starts a `task` as a run. Same-tab
|
|
32
|
+
* session storage, written by the person's own press, so an address can never
|
|
33
|
+
* carry one (a link is not consent to spend).
|
|
34
|
+
*/
|
|
35
|
+
export declare function hand(kind: 'send' | 'task', prompt: string): void;
|
|
36
|
+
/** The prompt left for `kind`, taken so it is done once, or ''. */
|
|
37
|
+
export declare function taken(kind: 'send' | 'task'): string;
|
|
38
|
+
export interface SuggestionsProps {
|
|
39
|
+
rows: readonly Suggestion[];
|
|
40
|
+
/** A row was pressed: do what it says. */
|
|
41
|
+
onAct: (act: Act, row: Suggestion) => void;
|
|
42
|
+
onDismiss: (id: string) => void;
|
|
43
|
+
/** The account's switch (`Suggested.state`). Required: off draws the one line that offers to turn them on. */
|
|
44
|
+
state: Switch;
|
|
45
|
+
/** Turn them on or off (`Suggested.turn`). Required: rows a model wrote always say so and can be turned off. */
|
|
46
|
+
onTurn: (on: boolean) => void;
|
|
47
|
+
}
|
|
48
|
+
/** The rows, or nothing when there are none. */
|
|
49
|
+
export declare function Suggestions({ rows, onAct, onDismiss, state, onTurn }: SuggestionsProps): import("react").JSX.Element | null;
|