@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,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Starting a coding run, and what it left.
|
|
3
|
+
*
|
|
4
|
+
* POST /v1/agent/coding → 202 {sessionId, repo, branch, routed, targetId}
|
|
5
|
+
* POST /v1/agent/coding/{session}/steer {text} 202 {ok}
|
|
6
|
+
* GET /v1/agent/coding/{session}/artifacts {session, saved, artifacts}
|
|
7
|
+
* GET /v1/agent/coding/{session}/artifacts/{name} one stored artifact's bytes
|
|
8
|
+
*
|
|
9
|
+
* 202 is ADMITTED, not finished: the answer is the session the run narrates
|
|
10
|
+
* itself in, and the session stream is how it is watched.
|
|
11
|
+
*
|
|
12
|
+
* Where it runs is one field. No `targetId` is the platform's sandbox; a target
|
|
13
|
+
* id routes it to one of the org's machines, and `routed` says whether it got
|
|
14
|
+
* there. `dir` with a target id and no repository is a folder there its owner
|
|
15
|
+
* granted (shared.ts); the platform refuses any other 403 `folder_not_granted`.
|
|
16
|
+
*
|
|
17
|
+
* `mode` is what the run may do: `build` edits, commits and pushes its branch;
|
|
18
|
+
* `plan` reads the repository with a credential that can only read and answers
|
|
19
|
+
* with a plan, as its final status. A plan runs in the platform's sandbox only —
|
|
20
|
+
* a claimed machine clones and pushes with its own credential — so a plan
|
|
21
|
+
* routed to one is refused, here before sending as on the platform.
|
|
22
|
+
*
|
|
23
|
+
* `model` and `effort` are taken by the dev harness the builder runs (and by
|
|
24
|
+
* codex); the builder names no other harness, so they are always honoured.
|
|
25
|
+
*
|
|
26
|
+
* `setup` is a plan's shape put to one question: how this codebase is installed,
|
|
27
|
+
* started and checked. Its agent may install and run things in its sandbox, and
|
|
28
|
+
* its answer is kept as the codebase's proposed environment (environment.ts).
|
|
29
|
+
*
|
|
30
|
+
* A sandbox run keeps its sandbox after it ends, so `after` continues the earlier
|
|
31
|
+
* run in that same sandbox and working tree, resumed if it parked.
|
|
32
|
+
*/
|
|
33
|
+
import { phrase } from '@hanzo/i18n';
|
|
34
|
+
import { english } from '../say.js';
|
|
35
|
+
import { call, headers, reason, Refusal, seg } from './call.js';
|
|
36
|
+
/** Why this mode cannot run where it is sent, in the words of the `t` handed (English without one), or '' when it can. */
|
|
37
|
+
export const unhonoured = (mode, target, t = english) => !target?.trim()
|
|
38
|
+
? ''
|
|
39
|
+
: mode === 'plan'
|
|
40
|
+
? t('A plan runs in the Hanzo sandbox: a machine clones and pushes with its own credential. Choose Cloud, or switch to Build.')
|
|
41
|
+
: mode === 'setup'
|
|
42
|
+
? t('A setup runs in the Hanzo sandbox: a machine clones and pushes with its own credential. Choose Cloud, or switch to Build.')
|
|
43
|
+
: '';
|
|
44
|
+
let reqSeq = 0;
|
|
45
|
+
function newRequestId() {
|
|
46
|
+
const uuid = globalThis.crypto?.randomUUID?.();
|
|
47
|
+
if (uuid)
|
|
48
|
+
return uuid;
|
|
49
|
+
reqSeq += 1;
|
|
50
|
+
return `req_${Date.now().toString(36)}_${reqSeq.toString(36)}`;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The request body: only what was asked, with no empty strings sent as values.
|
|
54
|
+
* A run in the sandbox asks for one with a desktop, so its Desktop tab has a
|
|
55
|
+
* screen to show; a machine is whatever it is.
|
|
56
|
+
*/
|
|
57
|
+
export function body(ask) {
|
|
58
|
+
const out = { prompt: ask.prompt.trim() };
|
|
59
|
+
for (const k of [
|
|
60
|
+
'repo',
|
|
61
|
+
'base',
|
|
62
|
+
'targetId',
|
|
63
|
+
'dir',
|
|
64
|
+
'project',
|
|
65
|
+
'after',
|
|
66
|
+
'mode',
|
|
67
|
+
'model',
|
|
68
|
+
'effort',
|
|
69
|
+
'requestId',
|
|
70
|
+
'instructions',
|
|
71
|
+
'developerInstructions',
|
|
72
|
+
]) {
|
|
73
|
+
const v = ask[k]?.trim();
|
|
74
|
+
if (v)
|
|
75
|
+
out[k] = v;
|
|
76
|
+
}
|
|
77
|
+
if (ask.issue && Number.isInteger(ask.issue) && ask.issue > 0)
|
|
78
|
+
out.issue = ask.issue;
|
|
79
|
+
if (!out.targetId)
|
|
80
|
+
out.desktop = true;
|
|
81
|
+
return out;
|
|
82
|
+
}
|
|
83
|
+
export async function start(t, ask) {
|
|
84
|
+
if (!ask.prompt.trim())
|
|
85
|
+
throw new Refusal(400, phrase('Say what the run should do'));
|
|
86
|
+
const why = unhonoured(ask.mode, ask.targetId);
|
|
87
|
+
if (why)
|
|
88
|
+
throw new Refusal(400, why);
|
|
89
|
+
const r = await call(t, 'POST', '/v1/agent/coding', body({ ...ask, requestId: ask.requestId?.trim() || newRequestId() }));
|
|
90
|
+
const s = (k) => (typeof r?.[k] === 'string' ? r[k] : '');
|
|
91
|
+
if (!s('sessionId'))
|
|
92
|
+
throw new Refusal(502, phrase('The run was admitted but named no session'));
|
|
93
|
+
return {
|
|
94
|
+
session: s('sessionId'),
|
|
95
|
+
repo: s('repo'),
|
|
96
|
+
branch: s('branch'),
|
|
97
|
+
routed: r?.routed === true,
|
|
98
|
+
target: s('targetId'),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* New words for a sandbox run that is working. The run takes its task on its
|
|
103
|
+
* command line and reads nothing after (apps/coding steer.go), so the platform
|
|
104
|
+
* stops it with its work kept on its branch and starts a follow-up from there
|
|
105
|
+
* with the words; the follow-up's session arrives on this run's own stream as
|
|
106
|
+
* its `followed` status (turn.ts `followed`).
|
|
107
|
+
*/
|
|
108
|
+
export async function steer(t, session, text, requestId) {
|
|
109
|
+
const words = text.trim();
|
|
110
|
+
if (!words)
|
|
111
|
+
throw new Refusal(400, phrase('Say something to the run'));
|
|
112
|
+
await call(t, 'POST', `/v1/agent/coding/${seg(session)}/steer`, {
|
|
113
|
+
text: words,
|
|
114
|
+
requestId: requestId?.trim() || newRequestId(),
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The earlier run's ask, without the codebase its title leads with (`universe:
|
|
119
|
+
* add the widget`), or the `new project:` the platform titles a run that made its
|
|
120
|
+
* codebase with (apps/coding start.go).
|
|
121
|
+
*/
|
|
122
|
+
export function headline(title, repo) {
|
|
123
|
+
const name = repo.split('/').filter(Boolean).pop() ?? '';
|
|
124
|
+
const t = title.trim();
|
|
125
|
+
for (const lead of [name, 'new project', 'workspace'])
|
|
126
|
+
if (lead && t.startsWith(`${lead}: `))
|
|
127
|
+
return t.slice(lead.length + 2).trim();
|
|
128
|
+
return t;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The same codebase, place and project as the earlier run. In the sandbox it goes
|
|
132
|
+
* on in the earlier run's own sandbox and working tree (`after`), whatever that
|
|
133
|
+
* run pushed. A machine keeps no sandbox: there `after` is the branch the earlier
|
|
134
|
+
* run pushed, named only when it pushed one, and otherwise the follow-up starts
|
|
135
|
+
* where it did.
|
|
136
|
+
*/
|
|
137
|
+
function from(e) {
|
|
138
|
+
const place = e.environment && e.environment !== 'sandbox' ? e.environment : undefined;
|
|
139
|
+
const base = e.base && !e.base.startsWith('agent/') ? e.base : undefined;
|
|
140
|
+
return {
|
|
141
|
+
repo: e.repo || undefined,
|
|
142
|
+
project: e.project || undefined,
|
|
143
|
+
targetId: place,
|
|
144
|
+
...(!place || e.pushed ? { after: e.id } : { base }),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
const modeOf = (m) => (m === 'plan' || m === 'setup' ? m : 'build');
|
|
148
|
+
/**
|
|
149
|
+
* A new run continuing an earlier one in its mode: what the person said, and
|
|
150
|
+
* which run it follows, because the new run's agent reads nothing else. With
|
|
151
|
+
* nothing said it goes on with the earlier ask, in the words the platform uses
|
|
152
|
+
* when it carries a paused run on (apps/coding steer.go followUp).
|
|
153
|
+
*/
|
|
154
|
+
export function followUp(e, said) {
|
|
155
|
+
const next = from(e);
|
|
156
|
+
const head = headline(e.title, e.repo);
|
|
157
|
+
const words = said.trim();
|
|
158
|
+
let prompt;
|
|
159
|
+
if (next.after) {
|
|
160
|
+
prompt = words || 'Continue where the earlier run left off.';
|
|
161
|
+
}
|
|
162
|
+
else if (words) {
|
|
163
|
+
const was = head ? `This follows an earlier run on this codebase: “${head}”.` : 'This follows an earlier run on this codebase.';
|
|
164
|
+
prompt = `${words}\n\n${was}${e.pushed ? ' Its work so far is on this branch; build on it.' : ''}`;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
const kept = e.pushed ? 'An earlier run already worked on this; its work so far is on this branch. Build on it. ' : '';
|
|
168
|
+
prompt = `${head}\n\n${kept}Continue where the earlier run left off.`.trim();
|
|
169
|
+
}
|
|
170
|
+
return { ...next, prompt, mode: modeOf(e.mode) };
|
|
171
|
+
}
|
|
172
|
+
/** A build of what a plan run answered: its ask as the title, and the plan to carry out. */
|
|
173
|
+
export function approve(e, plan) {
|
|
174
|
+
const head = headline(e.title, e.repo);
|
|
175
|
+
const ask = `Carry out this plan:\n\n${plan.trim()}`;
|
|
176
|
+
return { ...from(e), prompt: head ? `${head}\n\n${ask}` : ask, mode: 'build' };
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* The same ask again, where the earlier run worked and in its mode: what a failed
|
|
180
|
+
* run's Try again starts. `ask` is the person's words as the run recorded them;
|
|
181
|
+
* with none recorded, its title's.
|
|
182
|
+
*/
|
|
183
|
+
export function retry(e, ask) {
|
|
184
|
+
const place = e.environment && e.environment !== 'sandbox' ? e.environment : undefined;
|
|
185
|
+
const base = e.base && !e.base.startsWith('agent/') ? e.base : undefined;
|
|
186
|
+
return {
|
|
187
|
+
repo: e.repo || undefined,
|
|
188
|
+
project: e.project || undefined,
|
|
189
|
+
targetId: place,
|
|
190
|
+
...(e.pushed ? { after: e.id } : { base }),
|
|
191
|
+
prompt: ask.trim() || headline(e.title, e.repo),
|
|
192
|
+
mode: modeOf(e.mode),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
const KINDS = ['file', 'patch', 'preview', 'pull', 'deploy'];
|
|
196
|
+
/** What a run left, kept after its sandbox is gone. */
|
|
197
|
+
export async function artifacts(t, session) {
|
|
198
|
+
const r = (await call(t, 'GET', `/v1/agent/coding/${seg(session)}/artifacts`)) ?? {};
|
|
199
|
+
const list = Array.isArray(r.artifacts) ? r.artifacts : [];
|
|
200
|
+
return {
|
|
201
|
+
saved: typeof r.saved === 'string' ? r.saved : '',
|
|
202
|
+
artifacts: list.flatMap((raw) => {
|
|
203
|
+
const a = raw && typeof raw === 'object' ? raw : {};
|
|
204
|
+
const kind = KINDS.find((k) => k === a.kind);
|
|
205
|
+
const name = typeof a.name === 'string' ? a.name : '';
|
|
206
|
+
if (!kind || !name)
|
|
207
|
+
return [];
|
|
208
|
+
return [{ name, kind, size: typeof a.size === 'number' ? a.size : 0, url: typeof a.url === 'string' ? a.url : '', port: typeof a.port === 'number' ? a.port : 0 }];
|
|
209
|
+
}),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/** One stored artifact's bytes. */
|
|
213
|
+
export async function artifact(t, session, name) {
|
|
214
|
+
const parts = name.split('/');
|
|
215
|
+
if (parts.some((p) => p === '' || p === '.' || p === '..'))
|
|
216
|
+
throw new Refusal(400, phrase('That artifact has no name to fetch it by'));
|
|
217
|
+
const res = await fetch(`${t.api}/v1/agent/coding/${seg(session)}/artifacts/${parts.map(seg).join('/')}`, { headers: headers(t), cache: 'no-store' });
|
|
218
|
+
if (!res.ok)
|
|
219
|
+
throw new Refusal(res.status, (await reason(res)) || `The artifact answered ${res.status}`);
|
|
220
|
+
// Bytes, whatever type the store named: a page is saved, never opened here.
|
|
221
|
+
return new Blob([await res.arrayBuffer()], { type: 'application/octet-stream' });
|
|
222
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type Target } from './call.ts';
|
|
2
|
+
export interface Server {
|
|
3
|
+
/** The server's id in the org, and the prefix of every tool it brings. */
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
url: string;
|
|
7
|
+
/** The header the sealed secret is sent in, or ''. */
|
|
8
|
+
header: string;
|
|
9
|
+
/** Whether a secret is sealed for it. */
|
|
10
|
+
secret: boolean;
|
|
11
|
+
/** The catalog listing it was added from, or '' for a URL typed in. */
|
|
12
|
+
listing: string;
|
|
13
|
+
created: number;
|
|
14
|
+
/** False when no admin put it in place, so no run carries it; true, or unsaid by an older platform. */
|
|
15
|
+
admitted: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface Remote {
|
|
18
|
+
transport: string;
|
|
19
|
+
url: string;
|
|
20
|
+
}
|
|
21
|
+
export interface Package {
|
|
22
|
+
registry: string;
|
|
23
|
+
identifier: string;
|
|
24
|
+
runtime: string;
|
|
25
|
+
version: string;
|
|
26
|
+
}
|
|
27
|
+
export interface Listing {
|
|
28
|
+
id: string;
|
|
29
|
+
/** The publisher's reverse-DNS name, `com.stripe/mcp`. */
|
|
30
|
+
name: string;
|
|
31
|
+
title: string;
|
|
32
|
+
description: string;
|
|
33
|
+
vendor: string;
|
|
34
|
+
version: string;
|
|
35
|
+
logo: string;
|
|
36
|
+
featured: boolean;
|
|
37
|
+
official: boolean;
|
|
38
|
+
transports: string[];
|
|
39
|
+
remotes: Remote[];
|
|
40
|
+
packages: Package[];
|
|
41
|
+
repo: string;
|
|
42
|
+
site: string;
|
|
43
|
+
}
|
|
44
|
+
export interface Page {
|
|
45
|
+
listings: Listing[];
|
|
46
|
+
total: number;
|
|
47
|
+
offset: number;
|
|
48
|
+
}
|
|
49
|
+
export declare function server(raw: unknown): Server;
|
|
50
|
+
export declare function listing(raw: unknown): Listing;
|
|
51
|
+
/** What a listing is called on screen. */
|
|
52
|
+
export declare const titleOf: (l: Listing) => string;
|
|
53
|
+
/** Whether a listing can be added here and now: the platform dials its streamable-HTTP remote. */
|
|
54
|
+
export declare const ready: (l: Listing) => boolean;
|
|
55
|
+
/** A server's tools among the plane's, by the prefix its id gives them. */
|
|
56
|
+
export declare const owns: (s: Server, toolName: string) => boolean;
|
|
57
|
+
export declare function servers(t: Target): Promise<Server[]>;
|
|
58
|
+
export interface Adding {
|
|
59
|
+
/** Required with a URL; a listing takes its own title when this is empty. */
|
|
60
|
+
name?: string;
|
|
61
|
+
url?: string;
|
|
62
|
+
listing?: string;
|
|
63
|
+
header?: string;
|
|
64
|
+
secret?: string;
|
|
65
|
+
}
|
|
66
|
+
/** Why a server cannot be added as it stands, or '' when it can. English, marked (`phrase`): a screen says it through `t`. */
|
|
67
|
+
export declare function refuse(a: Adding): string;
|
|
68
|
+
export declare function add(t: Target, a: Adding): Promise<Server>;
|
|
69
|
+
export declare function remove(t: Target, id: string): Promise<void>;
|
|
70
|
+
/** A page of the shelf, featured first, then by name. */
|
|
71
|
+
export declare function shelf(t: Target, q?: {
|
|
72
|
+
text?: string;
|
|
73
|
+
limit?: number;
|
|
74
|
+
offset?: number;
|
|
75
|
+
}): Promise<Page>;
|
|
76
|
+
export declare function one(t: Target, id: string): Promise<Listing>;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Connectors: the MCP servers an org adds, and the shelf it picks them from.
|
|
3
|
+
*
|
|
4
|
+
* GET /v1/tool/mcp/servers {servers: [server]}
|
|
5
|
+
* POST /v1/tool/mcp/servers {name, url} or {listing, name?}, with {authHeader, secret} → 201 server
|
|
6
|
+
* DELETE /v1/tool/mcp/servers/{id} 204
|
|
7
|
+
* GET /v1/tool/catalog?q=&limit=&offset= {catalog: [listing], total, limit, offset}
|
|
8
|
+
* GET /v1/tool/catalog/{id} one listing in full
|
|
9
|
+
*
|
|
10
|
+
* A server's secret is sealed in KMS by the platform and never answered again;
|
|
11
|
+
* a record says only whether it has one. Its tools are GET /v1/tool?source=mcp
|
|
12
|
+
* (tools.ts), named `<server id>_<tool>`, and each is called only once it is on.
|
|
13
|
+
* A listing can be added here only when it serves streamable HTTP; one that
|
|
14
|
+
* ships only a package needs somewhere to run first. The fleet's own servers,
|
|
15
|
+
* on for every run, are mcp.ts.
|
|
16
|
+
*/
|
|
17
|
+
import { phrase } from '@hanzo/i18n';
|
|
18
|
+
import { call, query, seg } from './call.js';
|
|
19
|
+
const str = (v) => (typeof v === 'string' ? v : '');
|
|
20
|
+
const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : 0);
|
|
21
|
+
const obj = (v) => (v && typeof v === 'object' ? v : {});
|
|
22
|
+
const rows = (v) => (Array.isArray(v) ? v : []);
|
|
23
|
+
export function server(raw) {
|
|
24
|
+
const o = obj(raw);
|
|
25
|
+
return {
|
|
26
|
+
id: str(o.id),
|
|
27
|
+
name: str(o.name),
|
|
28
|
+
url: str(o.url),
|
|
29
|
+
header: str(o.authHeader),
|
|
30
|
+
secret: o.hasSecret === true,
|
|
31
|
+
listing: str(o.listing),
|
|
32
|
+
created: num(o.createdAt),
|
|
33
|
+
admitted: o.admitted !== false,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export function listing(raw) {
|
|
37
|
+
const o = obj(raw);
|
|
38
|
+
return {
|
|
39
|
+
id: str(o.id),
|
|
40
|
+
name: str(o.name),
|
|
41
|
+
title: str(o.title),
|
|
42
|
+
description: str(o.description),
|
|
43
|
+
vendor: str(o.vendor),
|
|
44
|
+
version: str(o.version),
|
|
45
|
+
logo: str(o.logo),
|
|
46
|
+
featured: o.featured === true,
|
|
47
|
+
official: o.official === true,
|
|
48
|
+
transports: rows(o.transports).map(str).filter(Boolean),
|
|
49
|
+
remotes: rows(o.remotes)
|
|
50
|
+
.map((r) => ({ transport: str(obj(r).transport), url: str(obj(r).url) }))
|
|
51
|
+
.filter((r) => r.url),
|
|
52
|
+
packages: rows(o.packages)
|
|
53
|
+
.map((p) => {
|
|
54
|
+
const x = obj(p);
|
|
55
|
+
return { registry: str(x.registry), identifier: str(x.identifier), runtime: str(x.runtime), version: str(x.version) };
|
|
56
|
+
})
|
|
57
|
+
.filter((p) => p.identifier),
|
|
58
|
+
repo: str(o.repo),
|
|
59
|
+
site: str(o.site),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** What a listing is called on screen. */
|
|
63
|
+
export const titleOf = (l) => l.title || l.name;
|
|
64
|
+
/** Whether a listing can be added here and now: the platform dials its streamable-HTTP remote. */
|
|
65
|
+
export const ready = (l) => l.remotes.some((r) => r.transport === 'streamable-http');
|
|
66
|
+
/** A server's tools among the plane's, by the prefix its id gives them. */
|
|
67
|
+
export const owns = (s, toolName) => toolName.startsWith(`${s.id}_`);
|
|
68
|
+
export async function servers(t) {
|
|
69
|
+
return rows(obj(await call(t, 'GET', '/v1/tool/mcp/servers')).servers).map(server).filter((s) => s.id);
|
|
70
|
+
}
|
|
71
|
+
/** Why a server cannot be added as it stands, or '' when it can. English, marked (`phrase`): a screen says it through `t`. */
|
|
72
|
+
export function refuse(a) {
|
|
73
|
+
if (!a.listing) {
|
|
74
|
+
if (!a.name?.trim())
|
|
75
|
+
return phrase('A connector needs a name');
|
|
76
|
+
if (!/^https?:\/\/[^\s/]+/.test(a.url?.trim() ?? ''))
|
|
77
|
+
return phrase('The URL is an http(s) address');
|
|
78
|
+
}
|
|
79
|
+
if (a.secret && !a.header?.trim())
|
|
80
|
+
return phrase('Name the header the secret is sent in');
|
|
81
|
+
return '';
|
|
82
|
+
}
|
|
83
|
+
export async function add(t, a) {
|
|
84
|
+
const why = refuse(a);
|
|
85
|
+
if (why)
|
|
86
|
+
throw new Error(why);
|
|
87
|
+
const body = {};
|
|
88
|
+
if (a.listing)
|
|
89
|
+
body.listing = a.listing;
|
|
90
|
+
else
|
|
91
|
+
body.url = a.url.trim();
|
|
92
|
+
if (a.name?.trim())
|
|
93
|
+
body.name = a.name.trim();
|
|
94
|
+
// The header names where the secret goes, so it rides with one or not at all.
|
|
95
|
+
if (a.secret) {
|
|
96
|
+
body.authHeader = a.header.trim();
|
|
97
|
+
body.secret = a.secret;
|
|
98
|
+
}
|
|
99
|
+
return server(await call(t, 'POST', '/v1/tool/mcp/servers', body));
|
|
100
|
+
}
|
|
101
|
+
export async function remove(t, id) {
|
|
102
|
+
await call(t, 'DELETE', `/v1/tool/mcp/servers/${seg(id)}`);
|
|
103
|
+
}
|
|
104
|
+
/** A page of the shelf, featured first, then by name. */
|
|
105
|
+
export async function shelf(t, q = {}) {
|
|
106
|
+
const r = obj(await call(t, 'GET', `/v1/tool/catalog${query({ q: q.text?.trim(), limit: q.limit, offset: q.offset || undefined })}`));
|
|
107
|
+
return { listings: rows(r.catalog).map(listing).filter((l) => l.id), total: num(r.total), offset: num(r.offset) };
|
|
108
|
+
}
|
|
109
|
+
export async function one(t, id) {
|
|
110
|
+
return listing(await call(t, 'GET', `/v1/tool/catalog/${seg(id)}`));
|
|
111
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The signed-in person's answers to Hanzo's data-sharing questions, as IAM
|
|
3
|
+
* records them for every Hanzo surface.
|
|
4
|
+
*
|
|
5
|
+
* GET /v1/iam/consent → {status, data: {insights, training}}
|
|
6
|
+
* PUT /v1/iam/consent {insights?, training?} only the answers sent change
|
|
7
|
+
*
|
|
8
|
+
* `training` has three states: unanswered (''), granted, refused. Only granted
|
|
9
|
+
* lets Hanzo train on this person's data; unanswered is read as no. `insights`
|
|
10
|
+
* is anonymous product usage, with no prompt or answer text, and is on until
|
|
11
|
+
* turned off. Every change is audited by IAM with the answer before and after.
|
|
12
|
+
*/
|
|
13
|
+
import { type Target } from './call.ts';
|
|
14
|
+
export type Answer = '' | 'granted' | 'refused';
|
|
15
|
+
export interface Consent {
|
|
16
|
+
insights: boolean;
|
|
17
|
+
training: Answer;
|
|
18
|
+
}
|
|
19
|
+
/** IAM's defaults for anything it did not say: insights on, training unanswered. */
|
|
20
|
+
export declare function consentOf(raw: unknown): Consent;
|
|
21
|
+
export declare function consent(t: Target): Promise<Consent>;
|
|
22
|
+
export declare function setConsent(t: Target, change: Partial<Consent>): Promise<Consent>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The signed-in person's answers to Hanzo's data-sharing questions, as IAM
|
|
3
|
+
* records them for every Hanzo surface.
|
|
4
|
+
*
|
|
5
|
+
* GET /v1/iam/consent → {status, data: {insights, training}}
|
|
6
|
+
* PUT /v1/iam/consent {insights?, training?} only the answers sent change
|
|
7
|
+
*
|
|
8
|
+
* `training` has three states: unanswered (''), granted, refused. Only granted
|
|
9
|
+
* lets Hanzo train on this person's data; unanswered is read as no. `insights`
|
|
10
|
+
* is anonymous product usage, with no prompt or answer text, and is on until
|
|
11
|
+
* turned off. Every change is audited by IAM with the answer before and after.
|
|
12
|
+
*/
|
|
13
|
+
import { call, unwrap } from './call.js';
|
|
14
|
+
const ANSWERS = ['', 'granted', 'refused'];
|
|
15
|
+
/** IAM's defaults for anything it did not say: insights on, training unanswered. */
|
|
16
|
+
export function consentOf(raw) {
|
|
17
|
+
const o = (raw && typeof raw === 'object' ? raw : {});
|
|
18
|
+
return {
|
|
19
|
+
insights: typeof o.insights === 'boolean' ? o.insights : true,
|
|
20
|
+
training: ANSWERS.includes(o.training) ? o.training : '',
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export async function consent(t) {
|
|
24
|
+
return consentOf(unwrap(await call(t, 'GET', '/v1/iam/consent')));
|
|
25
|
+
}
|
|
26
|
+
export async function setConsent(t, change) {
|
|
27
|
+
return consentOf(unwrap(await call(t, 'PUT', '/v1/iam/consent', change)));
|
|
28
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The person's Chat conversations, as the agent service keeps them (the list
|
|
3
|
+
* @hanzo/ai `threads.list` and @hanzo/rooms read).
|
|
4
|
+
*
|
|
5
|
+
* GET /v1/agents/chat/conversations → {conversations: [{id, title, updatedAt, pinned, archived}]}
|
|
6
|
+
*
|
|
7
|
+
* Pinned first, then most recently spoken in; archived ones are left out. Only
|
|
8
|
+
* the caller's own: another member's conversations are never listed.
|
|
9
|
+
*/
|
|
10
|
+
import { type Target } from './call.ts';
|
|
11
|
+
export interface Conversation {
|
|
12
|
+
id: string;
|
|
13
|
+
/** Taken from the opening message until renamed. */
|
|
14
|
+
title: string;
|
|
15
|
+
/** RFC 3339: when it was last spoken in, or ''. */
|
|
16
|
+
updated: string;
|
|
17
|
+
pinned: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare function conversation(raw: unknown): Conversation | null;
|
|
20
|
+
export declare function conversations(t: Target, signal?: AbortSignal): Promise<Conversation[]>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The person's Chat conversations, as the agent service keeps them (the list
|
|
3
|
+
* @hanzo/ai `threads.list` and @hanzo/rooms read).
|
|
4
|
+
*
|
|
5
|
+
* GET /v1/agents/chat/conversations → {conversations: [{id, title, updatedAt, pinned, archived}]}
|
|
6
|
+
*
|
|
7
|
+
* Pinned first, then most recently spoken in; archived ones are left out. Only
|
|
8
|
+
* the caller's own: another member's conversations are never listed.
|
|
9
|
+
*/
|
|
10
|
+
import { call } from './call.js';
|
|
11
|
+
const str = (v) => (typeof v === 'string' ? v : '');
|
|
12
|
+
const obj = (v) => (v && typeof v === 'object' ? v : {});
|
|
13
|
+
export function conversation(raw) {
|
|
14
|
+
const o = obj(raw);
|
|
15
|
+
const id = str(o.id);
|
|
16
|
+
if (!id)
|
|
17
|
+
return null;
|
|
18
|
+
return { id, title: str(o.title), updated: str(o.updatedAt), pinned: o.pinned === true };
|
|
19
|
+
}
|
|
20
|
+
export async function conversations(t, signal) {
|
|
21
|
+
const raw = obj(await call(t, 'GET', '/v1/agents/chat/conversations', undefined, { signal }));
|
|
22
|
+
return (Array.isArray(raw.conversations) ? raw.conversations : []).map(conversation).filter((c) => c !== null);
|
|
23
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { Target } from './call.ts';
|
|
2
|
+
/** What the model drafts. */
|
|
3
|
+
export interface Sketch {
|
|
4
|
+
/** One short word the agent is called by. */
|
|
5
|
+
name: string;
|
|
6
|
+
role: string;
|
|
7
|
+
instructions: string;
|
|
8
|
+
/** The first line it says, kept in its instructions. */
|
|
9
|
+
opening: string;
|
|
10
|
+
/** One emoji for a role; '' for a person. */
|
|
11
|
+
emoji: string;
|
|
12
|
+
/** The full name of a real historical person, '' for anyone or anything else. */
|
|
13
|
+
figure: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const SYSTEM: string;
|
|
16
|
+
/** A model's answer as a draft: the fields that are text, or null where it named no one to draft. */
|
|
17
|
+
export declare function parse(said: string): Sketch | null;
|
|
18
|
+
/**
|
|
19
|
+
* The tokens a draft is allowed: Enso reasons before it answers, and under 4,000 the answer
|
|
20
|
+
* is cut off with nothing said (measured: 1,200 came back empty, 4,000 in full).
|
|
21
|
+
*/
|
|
22
|
+
export declare const ROOM = 4000;
|
|
23
|
+
/** The line they typed, drafted; asked a second time when the first answer was not one. */
|
|
24
|
+
export declare function sketch(t: Target, line: string, signal?: AbortSignal): Promise<Sketch>;
|
|
25
|
+
/** The instructions as saved: what the model wrote, then the first line it says. */
|
|
26
|
+
export declare const saved: (s: Pick<Sketch, 'instructions' | 'opening'>) => string;
|
|
27
|
+
/** A portrait that is free to use, and where it came from. */
|
|
28
|
+
export interface Portrait {
|
|
29
|
+
url: string;
|
|
30
|
+
page: string;
|
|
31
|
+
licence: string;
|
|
32
|
+
}
|
|
33
|
+
/** A licence the portrait may be used under without asking: public domain or CC0. */
|
|
34
|
+
export declare const free: (licence: string) => boolean;
|
|
35
|
+
/** The Commons answer for a search over files, as a portrait that is free to use, or null. */
|
|
36
|
+
export declare function portraitOf(body: unknown): Portrait | null;
|
|
37
|
+
/** A public-domain portrait of a historical figure from Wikimedia Commons, or null; any failure is no portrait. */
|
|
38
|
+
export declare function portrait(name: string, signal?: AbortSignal): Promise<Portrait | null>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An agent drafted from one line: a name ("Marie Curie") or a description ("a
|
|
3
|
+
* skeptical CFO", "my grandmother who taught maths"). A Hanzo model, asked with
|
|
4
|
+
* the person's own bearer, writes the draft; nothing is created until they save it.
|
|
5
|
+
*
|
|
6
|
+
* POST /v1/chat/completions Enso, the router every plan grants
|
|
7
|
+
* GET commons.wikimedia.org a public-domain portrait, for a historical figure only
|
|
8
|
+
*/
|
|
9
|
+
import { ask, json } from './chat.js';
|
|
10
|
+
import { ENSO } from './models.js';
|
|
11
|
+
export const SYSTEM = [
|
|
12
|
+
'You draft one agent for a person\'s own team from one line they typed: a name or a description.',
|
|
13
|
+
'Reply with one JSON object and nothing else: {"name","role","instructions","opening","emoji","figure"}.',
|
|
14
|
+
'name: one short word the agent goes by, letters and digits only (Curie, Marie, Cfo).',
|
|
15
|
+
'role: two to four words.',
|
|
16
|
+
'instructions: second person, "You are ...", plain and specific: what you do, how you speak, how you work. For a real historical person, speak in their own voice and from what they wrote and did, and say when a question is past what they could have known.',
|
|
17
|
+
'opening: the one short line you say first.',
|
|
18
|
+
'emoji: one emoji that fits a role; "" for a real person.',
|
|
19
|
+
'figure: the full name of a real historical person who died more than seventy years ago when the line names one; "" otherwise.',
|
|
20
|
+
].join(' ');
|
|
21
|
+
const word = (v) => (typeof v === 'string' ? v.trim() : '');
|
|
22
|
+
/** A model's answer as a draft: the fields that are text, or null where it named no one to draft. */
|
|
23
|
+
export function parse(said) {
|
|
24
|
+
const o = json(said);
|
|
25
|
+
if (!o)
|
|
26
|
+
return null;
|
|
27
|
+
const name = word(o.name).replace(/[^\p{L}\p{N}._-]+/gu, '').slice(0, 40);
|
|
28
|
+
const instructions = word(o.instructions);
|
|
29
|
+
if (!name || !instructions)
|
|
30
|
+
return null;
|
|
31
|
+
return { name, role: word(o.role), instructions, opening: word(o.opening), emoji: word(o.emoji).slice(0, 8), figure: word(o.figure) };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The tokens a draft is allowed: Enso reasons before it answers, and under 4,000 the answer
|
|
35
|
+
* is cut off with nothing said (measured: 1,200 came back empty, 4,000 in full).
|
|
36
|
+
*/
|
|
37
|
+
export const ROOM = 4000;
|
|
38
|
+
/** The line they typed, drafted; asked a second time when the first answer was not one. */
|
|
39
|
+
export async function sketch(t, line, signal) {
|
|
40
|
+
for (let tried = 0; tried < 2; tried++) {
|
|
41
|
+
const draft = parse(await ask(t, SYSTEM, line.trim(), signal, ROOM, ENSO));
|
|
42
|
+
if (draft)
|
|
43
|
+
return draft;
|
|
44
|
+
}
|
|
45
|
+
throw new Error('The draft did not come out. Try again.');
|
|
46
|
+
}
|
|
47
|
+
/** The instructions as saved: what the model wrote, then the first line it says. */
|
|
48
|
+
export const saved = (s) => (s.opening ? `${s.instructions.trim()}\n\nBegin a new conversation with: ${s.opening}` : s.instructions.trim());
|
|
49
|
+
/** A licence the portrait may be used under without asking: public domain or CC0. */
|
|
50
|
+
export const free = (licence) => /^(public domain|pd\b|cc0)/i.test(licence.trim());
|
|
51
|
+
/** The Commons answer for a search over files, as a portrait that is free to use, or null. */
|
|
52
|
+
export function portraitOf(body) {
|
|
53
|
+
const pages = body?.query?.pages;
|
|
54
|
+
if (!pages)
|
|
55
|
+
return null;
|
|
56
|
+
const rows = Object.values(pages);
|
|
57
|
+
for (const r of rows.sort((a, b) => (a.index ?? 0) - (b.index ?? 0))) {
|
|
58
|
+
const info = r.imageinfo?.[0];
|
|
59
|
+
const licence = word(info?.extmetadata?.LicenseShortName?.value);
|
|
60
|
+
const url = word(info?.thumburl) || word(info?.url);
|
|
61
|
+
if (info && url.startsWith('https://') && free(licence))
|
|
62
|
+
return { url, page: word(info.descriptionurl), licence };
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
/** A public-domain portrait of a historical figure from Wikimedia Commons, or null; any failure is no portrait. */
|
|
67
|
+
export async function portrait(name, signal) {
|
|
68
|
+
const q = new URLSearchParams({
|
|
69
|
+
action: 'query',
|
|
70
|
+
format: 'json',
|
|
71
|
+
origin: '*',
|
|
72
|
+
generator: 'search',
|
|
73
|
+
gsrsearch: `${name} portrait`,
|
|
74
|
+
gsrnamespace: '6',
|
|
75
|
+
gsrlimit: '8',
|
|
76
|
+
prop: 'imageinfo',
|
|
77
|
+
iiprop: 'url|extmetadata',
|
|
78
|
+
iiurlwidth: '256',
|
|
79
|
+
});
|
|
80
|
+
try {
|
|
81
|
+
const r = await fetch(`https://commons.wikimedia.org/w/api.php?${q}`, { signal });
|
|
82
|
+
return r.ok ? portraitOf(await r.json()) : null;
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|