@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,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The org's machines: its own computers a run can be sent to, beside the sandbox.
|
|
3
|
+
*
|
|
4
|
+
* GET /v1/agent/targets {targets: [...]}, newest first
|
|
5
|
+
* POST /v1/agent/targets register one by hand {label, kind, host}
|
|
6
|
+
* PATCH /v1/agent/targets/{id} rename it, drain it, bring it back
|
|
7
|
+
* DELETE /v1/agent/targets/{id} deregister it
|
|
8
|
+
* POST /v1/agent/targets/{id}/key mint or rotate its claim key, answered once
|
|
9
|
+
* POST /v1/agent/targets/{id}/folders {folder} let the web start runs in a folder there
|
|
10
|
+
* DELETE /v1/agent/targets/{id}/folders?folder=… stop letting it
|
|
11
|
+
*
|
|
12
|
+
* A machine belongs to the member who registered it. Only that member or an org
|
|
13
|
+
* admin changes, removes or keys it, and the platform answers anyone else the
|
|
14
|
+
* same 404 an unknown id gets — the record names no owner — so a 404 here is
|
|
15
|
+
* said as that rule. `hanzo link`, run on the machine, registers it under its
|
|
16
|
+
* hostname and keeps it online while it runs.
|
|
17
|
+
*
|
|
18
|
+
* A run started from the web works in a folder of a machine only inside one its
|
|
19
|
+
* owner granted (`folders`, hanzo-inc/app#310). Only the owner grants, from Hanzo
|
|
20
|
+
* Desktop or `hanzo link grant <folder>`, and only the owner revokes; the platform
|
|
21
|
+
* answers anyone else 403, an org admin included.
|
|
22
|
+
*/
|
|
23
|
+
import { phrase } from '@hanzo/i18n';
|
|
24
|
+
import { formatDeviceLabel } from '../dev-mode.js';
|
|
25
|
+
import { deviceKey } from '../names.js';
|
|
26
|
+
import { call, query, Refusal, seg } from './call.js';
|
|
27
|
+
export const KINDS = ['laptop', 'gpu', 'cloud', 'cluster', 'machine'];
|
|
28
|
+
const str = (v) => (typeof v === 'string' ? v : '');
|
|
29
|
+
const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : 0);
|
|
30
|
+
const obj = (v) => (v && typeof v === 'object' ? v : {});
|
|
31
|
+
export function formatBytes(bytes) {
|
|
32
|
+
if (!bytes || bytes <= 0)
|
|
33
|
+
return '';
|
|
34
|
+
const k = 1024;
|
|
35
|
+
const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
|
36
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
37
|
+
const val = bytes / Math.pow(k, i);
|
|
38
|
+
return `${val >= 10 || i === 0 ? Math.round(val) : val.toFixed(1)} ${sizes[i]}`;
|
|
39
|
+
}
|
|
40
|
+
export function formatPercent(fraction) {
|
|
41
|
+
if (fraction === undefined || !Number.isFinite(fraction))
|
|
42
|
+
return '';
|
|
43
|
+
return `${Math.round(fraction * 100)}%`;
|
|
44
|
+
}
|
|
45
|
+
export function formatRelative(isoDate) {
|
|
46
|
+
if (!isoDate)
|
|
47
|
+
return '';
|
|
48
|
+
const t = new Date(isoDate).getTime();
|
|
49
|
+
if (Number.isNaN(t))
|
|
50
|
+
return '';
|
|
51
|
+
const diffSec = Math.max(0, Math.floor((Date.now() - t) / 1000));
|
|
52
|
+
if (diffSec < 60)
|
|
53
|
+
return `${diffSec}s ago`;
|
|
54
|
+
if (diffSec < 3600)
|
|
55
|
+
return `${Math.floor(diffSec / 60)}m ago`;
|
|
56
|
+
if (diffSec < 86400)
|
|
57
|
+
return `${Math.floor(diffSec / 3600)}h ago`;
|
|
58
|
+
return `${Math.floor(diffSec / 86400)}d ago`;
|
|
59
|
+
}
|
|
60
|
+
export function specSummary(m) {
|
|
61
|
+
if (m.spec) {
|
|
62
|
+
const parts = [];
|
|
63
|
+
if (m.spec.gpus && m.spec.gpus.length > 0) {
|
|
64
|
+
const g = m.spec.gpus[0];
|
|
65
|
+
const gpuLabel = g.model || g.vendor || 'GPU';
|
|
66
|
+
parts.push(m.spec.gpus.length > 1 ? `${m.spec.gpus.length}× ${gpuLabel}` : gpuLabel);
|
|
67
|
+
}
|
|
68
|
+
else if (m.spec.cpus) {
|
|
69
|
+
parts.push(`${m.spec.cpus} vCPU`);
|
|
70
|
+
}
|
|
71
|
+
if (m.spec.memory)
|
|
72
|
+
parts.push(formatBytes(m.spec.memory));
|
|
73
|
+
if (parts.length > 0)
|
|
74
|
+
return parts.join(' · ');
|
|
75
|
+
}
|
|
76
|
+
return m.capacity || '';
|
|
77
|
+
}
|
|
78
|
+
function hardwareSummary(m) {
|
|
79
|
+
const hw = specSummary(m);
|
|
80
|
+
const host = m.host && m.host !== hw ? m.host : '';
|
|
81
|
+
return [hw, host].filter(Boolean).join(' · ');
|
|
82
|
+
}
|
|
83
|
+
/** The key a machine's name is kept under (names.ts): its hostname, else its label, else its id. */
|
|
84
|
+
export const machineKey = (m) => deviceKey(m.host, m.label, m.id);
|
|
85
|
+
/** A machine as a person reads it: the name they gave it (`names`, from `useDeviceNames`), else its own as a person says it. */
|
|
86
|
+
export function displayMachine(m, opts) {
|
|
87
|
+
return formatDeviceLabel(m.label, { hardware: hardwareSummary(m), host: m.host, name: opts?.names?.[machineKey(m)], devMode: opts?.devMode, say: opts?.say });
|
|
88
|
+
}
|
|
89
|
+
export function machine(raw) {
|
|
90
|
+
const o = (raw && typeof raw === 'object' ? raw : {});
|
|
91
|
+
const specObj = obj(o.spec);
|
|
92
|
+
const metricsObj = obj(o.metrics);
|
|
93
|
+
let spec;
|
|
94
|
+
if (Object.keys(specObj).length > 0) {
|
|
95
|
+
const rawGpus = Array.isArray(specObj.gpus) ? specObj.gpus : [];
|
|
96
|
+
spec = {
|
|
97
|
+
os: str(specObj.os),
|
|
98
|
+
arch: str(specObj.arch),
|
|
99
|
+
cpus: num(specObj.cpus),
|
|
100
|
+
memory: num(specObj.memory),
|
|
101
|
+
gpus: rawGpus.map((g) => {
|
|
102
|
+
const go = obj(g);
|
|
103
|
+
return { vendor: str(go.vendor), model: str(go.model), memory: num(go.memory) };
|
|
104
|
+
}),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
let metrics;
|
|
108
|
+
if (Object.keys(metricsObj).length > 0) {
|
|
109
|
+
metrics = {
|
|
110
|
+
load1: num(metricsObj.load1),
|
|
111
|
+
load5: num(metricsObj.load5),
|
|
112
|
+
load15: num(metricsObj.load15),
|
|
113
|
+
memUsed: num(metricsObj.memUsed),
|
|
114
|
+
memFree: num(metricsObj.memFree),
|
|
115
|
+
gpuUtil: num(metricsObj.gpuUtil),
|
|
116
|
+
cpuUtil: num(metricsObj.cpuUtil),
|
|
117
|
+
cpuTemp: num(metricsObj.cpuTemp),
|
|
118
|
+
gpuTemp: num(metricsObj.gpuTemp),
|
|
119
|
+
gpuPower: num(metricsObj.gpuPower),
|
|
120
|
+
gpuPowerLimit: num(metricsObj.gpuPowerLimit),
|
|
121
|
+
gpuMemUsed: num(metricsObj.gpuMemUsed),
|
|
122
|
+
gpuMemTotal: num(metricsObj.gpuMemTotal),
|
|
123
|
+
diskUsed: num(metricsObj.diskUsed),
|
|
124
|
+
diskTotal: num(metricsObj.diskTotal),
|
|
125
|
+
diskRead: num(metricsObj.diskRead),
|
|
126
|
+
diskWrite: num(metricsObj.diskWrite),
|
|
127
|
+
netRx: num(metricsObj.netRx),
|
|
128
|
+
netTx: num(metricsObj.netTx),
|
|
129
|
+
model: str(metricsObj.model),
|
|
130
|
+
decode: num(metricsObj.decode),
|
|
131
|
+
prefill: num(metricsObj.prefill),
|
|
132
|
+
ttft: num(metricsObj.ttft),
|
|
133
|
+
running: num(metricsObj.running),
|
|
134
|
+
waiting: num(metricsObj.waiting),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
const m = {
|
|
138
|
+
id: str(o.id),
|
|
139
|
+
label: str(o.label) || str(o.host) || str(o.id),
|
|
140
|
+
kind: str(o.kind),
|
|
141
|
+
status: str(o.status),
|
|
142
|
+
capacity: str(o.capacity),
|
|
143
|
+
host: str(o.host),
|
|
144
|
+
sessions: num(o.sessions),
|
|
145
|
+
running: num(o.running),
|
|
146
|
+
seen: str(o.metricsAt),
|
|
147
|
+
folders: Array.isArray(o.folders) ? o.folders.filter((f) => typeof f === 'string' && f !== '') : [],
|
|
148
|
+
};
|
|
149
|
+
Object.defineProperties(m, {
|
|
150
|
+
serving: { value: o.serving === true, enumerable: false, writable: true },
|
|
151
|
+
createdAt: { value: str(o.createdAt), enumerable: false, writable: true },
|
|
152
|
+
updatedAt: { value: str(o.updatedAt), enumerable: false, writable: true },
|
|
153
|
+
spec: { value: spec, enumerable: false, writable: true },
|
|
154
|
+
metrics: { value: metrics, enumerable: false, writable: true },
|
|
155
|
+
});
|
|
156
|
+
return m;
|
|
157
|
+
}
|
|
158
|
+
export async function machines(t) {
|
|
159
|
+
const raw = (await call(t, 'GET', '/v1/agent/targets')) ?? {};
|
|
160
|
+
return (Array.isArray(raw.targets) ? raw.targets : []).map(machine).filter((m) => m.id);
|
|
161
|
+
}
|
|
162
|
+
/** The platform's 404 for a machine that is someone else's, said as the rule it is. */
|
|
163
|
+
async function owned(p) {
|
|
164
|
+
try {
|
|
165
|
+
return await p;
|
|
166
|
+
}
|
|
167
|
+
catch (e) {
|
|
168
|
+
if (e instanceof Refusal && e.status === 404)
|
|
169
|
+
throw new Refusal(404, phrase('This machine is gone, or not yours to change: only the member who linked it, or an org admin, can.'));
|
|
170
|
+
throw e;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Register a machine by hand. One left unnamed takes its hostname, the name `hanzo
|
|
175
|
+
* link` gives it; `hanzo link` on a machine with this hostname takes the row over.
|
|
176
|
+
*/
|
|
177
|
+
export async function add(t, what) {
|
|
178
|
+
const host = (what.host ?? '').trim();
|
|
179
|
+
const label = what.label.trim() || host;
|
|
180
|
+
if (!label)
|
|
181
|
+
throw new Error(phrase('A machine needs a name or a hostname'));
|
|
182
|
+
const body = { label, kind: what.kind };
|
|
183
|
+
if (host)
|
|
184
|
+
body.host = host;
|
|
185
|
+
if (what.capacity?.trim())
|
|
186
|
+
body.capacity = what.capacity.trim();
|
|
187
|
+
return machine(await call(t, 'POST', '/v1/agent/targets', body));
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* A machine's status as a person reads it. The platform reports a hand-registered
|
|
191
|
+
* machine at its registered status until a heartbeat arrives, so `online` holds only
|
|
192
|
+
* once one has; before that it is `not seen yet`, and nothing is there to take a run.
|
|
193
|
+
*/
|
|
194
|
+
export function state(m) {
|
|
195
|
+
return m.status === 'online' && !m.seen ? phrase('not seen yet') : m.status;
|
|
196
|
+
}
|
|
197
|
+
/** Rename a machine, or drain it (`draining`) and bring it back (`online`). */
|
|
198
|
+
export async function change(t, id, what) {
|
|
199
|
+
const body = {};
|
|
200
|
+
if (what.label !== undefined) {
|
|
201
|
+
const label = what.label.trim();
|
|
202
|
+
if (!label)
|
|
203
|
+
throw new Error(phrase('A machine needs a name'));
|
|
204
|
+
body.label = label;
|
|
205
|
+
}
|
|
206
|
+
if (what.status !== undefined)
|
|
207
|
+
body.status = what.status;
|
|
208
|
+
if (what.capacity !== undefined)
|
|
209
|
+
body.capacity = what.capacity.trim();
|
|
210
|
+
if (what.kind !== undefined)
|
|
211
|
+
body.kind = what.kind;
|
|
212
|
+
if (what.host !== undefined)
|
|
213
|
+
body.host = what.host.trim();
|
|
214
|
+
return machine(await owned(call(t, 'PATCH', `/v1/agent/targets/${seg(id)}`, body)));
|
|
215
|
+
}
|
|
216
|
+
export async function remove(t, id) {
|
|
217
|
+
await owned(call(t, 'DELETE', `/v1/agent/targets/${seg(id)}`));
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Mint the machine's claim key, answered this once: only its hash is kept, and
|
|
221
|
+
* minting again ends the key before it. A runner on the machine sends it as
|
|
222
|
+
* `X-Target-Key` when it claims the runs sent there.
|
|
223
|
+
*/
|
|
224
|
+
export async function key(t, id) {
|
|
225
|
+
const r = await owned(call(t, 'POST', `/v1/agent/targets/${seg(id)}/key`));
|
|
226
|
+
const k = str(r?.claimKey);
|
|
227
|
+
if (!k)
|
|
228
|
+
throw new Error(phrase('The platform answered no key'));
|
|
229
|
+
return k;
|
|
230
|
+
}
|
|
231
|
+
/** Let runs started from the web work in `folder` on the machine, and in every folder under it. The owner's alone. */
|
|
232
|
+
export async function grant(t, id, folder) {
|
|
233
|
+
await call(t, 'POST', `/v1/agent/targets/${seg(id)}/folders`, { folder });
|
|
234
|
+
}
|
|
235
|
+
/** Stop letting runs started from the web work in `folder` on the machine. The owner's alone. */
|
|
236
|
+
export async function revoke(t, id, folder) {
|
|
237
|
+
await call(t, 'DELETE', `/v1/agent/targets/${seg(id)}/folders${query({ folder })}`);
|
|
238
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Target } from './call.ts';
|
|
2
|
+
export interface Native {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
ops: string[];
|
|
6
|
+
}
|
|
7
|
+
/** The servers in one tools/list answer. A missing tool array is a refusal. */
|
|
8
|
+
export declare function nativesOf(body: unknown): Native[];
|
|
9
|
+
/** Every native server the fleet MCP server is serving. */
|
|
10
|
+
export declare function natives(t: Target): Promise<Native[]>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The fleet's native MCP servers, as the MCP server itself lists them.
|
|
3
|
+
*
|
|
4
|
+
* POST /v1/mcp {"method":"tools/list"} → {result:{tools:[…]}}
|
|
5
|
+
*
|
|
6
|
+
* One tool is one native server. Its operations are the names in `op`. A run
|
|
7
|
+
* starts a server the first time it calls it; the server stays up afterwards.
|
|
8
|
+
* `describe` is how a caller reads one operation's schema, so it is not a server.
|
|
9
|
+
*/
|
|
10
|
+
import { phrase } from '@hanzo/i18n';
|
|
11
|
+
import { call, Refusal } from './call.js';
|
|
12
|
+
const words = (v) => (Array.isArray(v) ? v.filter((x) => typeof x === 'string' && x !== '') : []);
|
|
13
|
+
/** The servers in one tools/list answer. A missing tool array is a refusal. */
|
|
14
|
+
export function nativesOf(body) {
|
|
15
|
+
const root = body && typeof body === 'object' ? body : {};
|
|
16
|
+
const err = root.error;
|
|
17
|
+
if (err && typeof err === 'object') {
|
|
18
|
+
const message = err.message;
|
|
19
|
+
throw new Refusal(200, typeof message === 'string' && message ? message : phrase('The MCP server refused the list'));
|
|
20
|
+
}
|
|
21
|
+
const result = root.result && typeof root.result === 'object' ? root.result : null;
|
|
22
|
+
const tools = result && Array.isArray(result.tools) ? result.tools : null;
|
|
23
|
+
if (!tools)
|
|
24
|
+
throw new Refusal(502, phrase('The MCP server did not list its tools'));
|
|
25
|
+
const out = [];
|
|
26
|
+
for (const raw of tools) {
|
|
27
|
+
if (!raw || typeof raw !== 'object')
|
|
28
|
+
continue;
|
|
29
|
+
const t = raw;
|
|
30
|
+
const name = typeof t.name === 'string' ? t.name : '';
|
|
31
|
+
if (!name || name === 'describe')
|
|
32
|
+
continue;
|
|
33
|
+
const schema = t.inputSchema && typeof t.inputSchema === 'object' ? t.inputSchema : {};
|
|
34
|
+
const props = schema.properties && typeof schema.properties === 'object' ? schema.properties : {};
|
|
35
|
+
const op = props.op && typeof props.op === 'object' ? props.op : {};
|
|
36
|
+
out.push({
|
|
37
|
+
name,
|
|
38
|
+
description: typeof t.description === 'string' ? t.description : '',
|
|
39
|
+
ops: words(op.enum),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
/** Every native server the fleet MCP server is serving. */
|
|
45
|
+
export async function natives(t) {
|
|
46
|
+
return nativesOf(await call(t, 'POST', '/v1/mcp', { jsonrpc: '2.0', id: 1, method: 'tools/list' }));
|
|
47
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type Target } from './call.ts';
|
|
2
|
+
export type Role = 'owner' | 'admin' | 'member';
|
|
3
|
+
export interface Member {
|
|
4
|
+
/** `<homeOrg>/<username>`, IAM's id for the person. */
|
|
5
|
+
user: string;
|
|
6
|
+
/** The username alone. */
|
|
7
|
+
name: string;
|
|
8
|
+
role: Role;
|
|
9
|
+
since: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function member(raw: unknown): Member;
|
|
12
|
+
/** The org's people, owners first. Grants to a team or narrowed to one project are not the org's roster. */
|
|
13
|
+
export declare function roster(t: Target, org: string): Promise<Member[]>;
|
|
14
|
+
export interface Invitation {
|
|
15
|
+
owner: string;
|
|
16
|
+
name: string;
|
|
17
|
+
email: string;
|
|
18
|
+
/** What the invitee enters when they sign up. */
|
|
19
|
+
code: string;
|
|
20
|
+
/** How many may join with it, and how many have. */
|
|
21
|
+
seats: number;
|
|
22
|
+
used: number;
|
|
23
|
+
/** `Active` is redeemable; anything else is not. */
|
|
24
|
+
state: string;
|
|
25
|
+
created: string;
|
|
26
|
+
}
|
|
27
|
+
export declare function invitation(raw: unknown): Invitation;
|
|
28
|
+
export declare function invitations(t: Target, org: string): Promise<Invitation[]>;
|
|
29
|
+
/** An address that can receive an invitation. */
|
|
30
|
+
export declare const EMAIL: RegExp;
|
|
31
|
+
/** Invite one address into the org: one seat, redeemable now, pinned to that address. */
|
|
32
|
+
export declare function invite(t: Target, org: string, email: string): Promise<Invitation>;
|
|
33
|
+
export declare function revoke(t: Target, i: Pick<Invitation, 'owner' | 'name'>): Promise<void>;
|
|
34
|
+
/** The org's own logo address as IAM holds it, or '' when it has none. */
|
|
35
|
+
export declare function logo(t: Target, org: string): Promise<string>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who is in the organization, and who has been asked to join it, as Hanzo IAM
|
|
3
|
+
* holds them.
|
|
4
|
+
*
|
|
5
|
+
* GET /v1/iam/memberships?org= the roster: {status, data: [membership], data2: count}
|
|
6
|
+
* GET /v1/iam/invitations?owner= {invitations, total} (org admin)
|
|
7
|
+
* POST /v1/iam/invitations issue one (org admin)
|
|
8
|
+
* DELETE /v1/iam/invitations/{owner}/{name} withdraw one (org admin)
|
|
9
|
+
* GET /v1/iam/organizations/admin/{org} the org's record, whose `logo` is its mark (member)
|
|
10
|
+
*
|
|
11
|
+
* IAM decides the scope from the credential: a member reads the roster of an org
|
|
12
|
+
* they belong to, and only an admin of the org reads or writes its invitations.
|
|
13
|
+
* An invitation is a code IAM redeems when someone signs up with it; IAM sends
|
|
14
|
+
* no email of its own.
|
|
15
|
+
*/
|
|
16
|
+
import { phrase } from '@hanzo/i18n';
|
|
17
|
+
import { call, query, seg, Sentence } from './call.js';
|
|
18
|
+
const str = (v) => (typeof v === 'string' ? v : '');
|
|
19
|
+
const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : 0);
|
|
20
|
+
const obj = (v) => (v && typeof v === 'object' ? v : {});
|
|
21
|
+
const arr = (v) => (Array.isArray(v) ? v : []);
|
|
22
|
+
const ROLES = ['owner', 'admin', 'member'];
|
|
23
|
+
export function member(raw) {
|
|
24
|
+
const m = obj(raw);
|
|
25
|
+
const user = str(m.user);
|
|
26
|
+
const role = str(m.role);
|
|
27
|
+
return {
|
|
28
|
+
user,
|
|
29
|
+
name: user.includes('/') ? user.slice(user.indexOf('/') + 1) : user,
|
|
30
|
+
role: ROLES.includes(role) ? role : 'member',
|
|
31
|
+
since: str(m.createdTime),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** The org's people, owners first. Grants to a team or narrowed to one project are not the org's roster. */
|
|
35
|
+
export async function roster(t, org) {
|
|
36
|
+
const raw = obj(await call(t, 'GET', `/v1/iam/memberships${query({ org })}`));
|
|
37
|
+
if (raw.status === 'error')
|
|
38
|
+
throw new Error(str(raw.msg) || phrase('IAM refused the roster'));
|
|
39
|
+
const rank = (r) => ROLES.indexOf(r);
|
|
40
|
+
return arr(raw.data)
|
|
41
|
+
.map(obj)
|
|
42
|
+
.filter((m) => str(m.user) && !str(m.workspace) && !str(m.project))
|
|
43
|
+
.map(member)
|
|
44
|
+
.sort((a, b) => rank(a.role) - rank(b.role) || a.name.localeCompare(b.name));
|
|
45
|
+
}
|
|
46
|
+
export function invitation(raw) {
|
|
47
|
+
const i = obj(raw);
|
|
48
|
+
return {
|
|
49
|
+
owner: str(i.owner),
|
|
50
|
+
name: str(i.name),
|
|
51
|
+
email: str(i.email),
|
|
52
|
+
code: str(i.code),
|
|
53
|
+
seats: num(i.quota),
|
|
54
|
+
used: num(i.usedCount),
|
|
55
|
+
state: str(i.state),
|
|
56
|
+
created: str(i.createdTime) || str(i.createdAt),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export async function invitations(t, org) {
|
|
60
|
+
const raw = obj(await call(t, 'GET', `/v1/iam/invitations${query({ owner: org })}`));
|
|
61
|
+
return arr(raw.invitations).map(invitation).filter((i) => i.name);
|
|
62
|
+
}
|
|
63
|
+
/** An address that can receive an invitation. */
|
|
64
|
+
export const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
65
|
+
/** Random hex, from the browser's own generator. */
|
|
66
|
+
function hex(bytes) {
|
|
67
|
+
const b = new Uint8Array(bytes);
|
|
68
|
+
crypto.getRandomValues(b);
|
|
69
|
+
return Array.from(b, (x) => x.toString(16).padStart(2, '0')).join('');
|
|
70
|
+
}
|
|
71
|
+
/** Invite one address into the org: one seat, redeemable now, pinned to that address. */
|
|
72
|
+
export async function invite(t, org, email) {
|
|
73
|
+
const address = email.trim().toLowerCase();
|
|
74
|
+
if (!EMAIL.test(address))
|
|
75
|
+
throw email.trim() ? new Sentence(phrase('{email} is not an email address'), { email: email.trim() }) : new Error(phrase('That is not an email address'));
|
|
76
|
+
const local = address.slice(0, address.indexOf('@')).replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 24);
|
|
77
|
+
return invitation(await call(t, 'POST', '/v1/iam/invitations', {
|
|
78
|
+
owner: org,
|
|
79
|
+
name: `invite-${local || 'member'}-${hex(3)}`,
|
|
80
|
+
displayName: address,
|
|
81
|
+
email: address,
|
|
82
|
+
code: hex(8),
|
|
83
|
+
quota: 1,
|
|
84
|
+
usedCount: 0,
|
|
85
|
+
state: 'Active',
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
export async function revoke(t, i) {
|
|
89
|
+
await call(t, 'DELETE', `/v1/iam/invitations/${seg(i.owner)}/${seg(i.name)}`);
|
|
90
|
+
}
|
|
91
|
+
/** The org's own logo address as IAM holds it, or '' when it has none. */
|
|
92
|
+
export async function logo(t, org) {
|
|
93
|
+
const raw = obj(await call(t, 'GET', `/v1/iam/organizations/admin/${encodeURIComponent(org)}`));
|
|
94
|
+
return str(obj(raw.data ?? raw).logo);
|
|
95
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Target } from './call.ts';
|
|
2
|
+
export interface Memory {
|
|
3
|
+
/** `<owner>/<name>`, what a delete names. */
|
|
4
|
+
id: string;
|
|
5
|
+
content: string;
|
|
6
|
+
/** user, fact, … as the platform files it. */
|
|
7
|
+
kind: string;
|
|
8
|
+
/** When it was last written, as the platform wrote it. */
|
|
9
|
+
updated: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function memoryOf(raw: unknown): Memory | null;
|
|
12
|
+
export declare function memories(t: Target, limit?: number): Promise<Memory[]>;
|
|
13
|
+
export declare function remember(t: Target, content: string): Promise<Memory | null>;
|
|
14
|
+
export declare function forget(t: Target, id: string): Promise<void>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What Hanzo remembers about the signed-in person, in the org they act in.
|
|
3
|
+
*
|
|
4
|
+
* GET /v1/ai/memory/list?limit= {status, data: [memory]}, newest first
|
|
5
|
+
* POST /v1/ai/memory/remember {content} → {status, data: memory}
|
|
6
|
+
* POST /v1/ai/memory/delete {id: "<owner>/<name>"}
|
|
7
|
+
*
|
|
8
|
+
* The platform keys every memory on the validated caller and org, never on the
|
|
9
|
+
* request, so these read and change the caller's own and nobody else's. A
|
|
10
|
+
* refusal arrives in the envelope, usually under a 200.
|
|
11
|
+
*/
|
|
12
|
+
import { phrase } from '@hanzo/i18n';
|
|
13
|
+
import { call, query, unwrap } from './call.js';
|
|
14
|
+
const str = (v) => (typeof v === 'string' ? v : '');
|
|
15
|
+
export function memoryOf(raw) {
|
|
16
|
+
const o = (raw && typeof raw === 'object' ? raw : {});
|
|
17
|
+
const owner = str(o.owner);
|
|
18
|
+
const name = str(o.name);
|
|
19
|
+
if (!owner || !name)
|
|
20
|
+
return null;
|
|
21
|
+
return { id: `${owner}/${name}`, content: str(o.content), kind: str(o.kind), updated: str(o.updatedTime) || str(o.createdTime) };
|
|
22
|
+
}
|
|
23
|
+
export async function memories(t, limit = 100) {
|
|
24
|
+
const rows = unwrap(await call(t, 'GET', `/v1/ai/memory/list${query({ limit })}`));
|
|
25
|
+
return (Array.isArray(rows) ? rows : []).map(memoryOf).filter((m) => m !== null);
|
|
26
|
+
}
|
|
27
|
+
export async function remember(t, content) {
|
|
28
|
+
const said = content.trim();
|
|
29
|
+
if (!said)
|
|
30
|
+
throw new Error(phrase('Say what Hanzo should remember'));
|
|
31
|
+
return memoryOf(unwrap(await call(t, 'POST', '/v1/ai/memory/remember', { content: said })));
|
|
32
|
+
}
|
|
33
|
+
export async function forget(t, id) {
|
|
34
|
+
unwrap(await call(t, 'POST', '/v1/ai/memory/delete', { id }));
|
|
35
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The models a run can be routed through, from the platform's own catalog.
|
|
3
|
+
*
|
|
4
|
+
* GET /v1/models → {data: [{id, class, family, …}]}
|
|
5
|
+
*
|
|
6
|
+
* Read by `@hanzo/ui/models` `parseModels`, so a model's class and family are
|
|
7
|
+
* the gateway's fields, never guessed from its id. `ENSO` is the router: it
|
|
8
|
+
* picks a model per step, which is why it is the default, and a run that names
|
|
9
|
+
* it names no model at all.
|
|
10
|
+
*/
|
|
11
|
+
import { type ModelCatalogEntry } from '@hanzo/ui/models/catalog';
|
|
12
|
+
import { type Target } from './call.ts';
|
|
13
|
+
export { ENSO } from '@hanzo/ui/models/catalog';
|
|
14
|
+
export type Model = ModelCatalogEntry;
|
|
15
|
+
export declare function models(t: Target): Promise<Model[]>;
|
|
16
|
+
/** The payer's plan usage, as `GET /v1/ai/limits` answers it: what a picker marks paused. */
|
|
17
|
+
export declare function limits(t: Target, signal?: AbortSignal): Promise<unknown>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The models a run can be routed through, from the platform's own catalog.
|
|
3
|
+
*
|
|
4
|
+
* GET /v1/models → {data: [{id, class, family, …}]}
|
|
5
|
+
*
|
|
6
|
+
* Read by `@hanzo/ui/models` `parseModels`, so a model's class and family are
|
|
7
|
+
* the gateway's fields, never guessed from its id. `ENSO` is the router: it
|
|
8
|
+
* picks a model per step, which is why it is the default, and a run that names
|
|
9
|
+
* it names no model at all.
|
|
10
|
+
*/
|
|
11
|
+
import { parseModels } from '@hanzo/ui/models/catalog';
|
|
12
|
+
import { call } from './call.js';
|
|
13
|
+
export { ENSO } from '@hanzo/ui/models/catalog';
|
|
14
|
+
export async function models(t) {
|
|
15
|
+
return parseModels(await call(t, 'GET', '/v1/models'));
|
|
16
|
+
}
|
|
17
|
+
/** The payer's plan usage, as `GET /v1/ai/limits` answers it: what a picker marks paused. */
|
|
18
|
+
export function limits(t, signal) {
|
|
19
|
+
return call(t, 'GET', '/v1/ai/limits', undefined, { signal });
|
|
20
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Say } from '@hanzo/i18n/react';
|
|
2
|
+
import { type Names } from '../names.ts';
|
|
3
|
+
import type { Target } from './call.ts';
|
|
4
|
+
export interface Place {
|
|
5
|
+
/** `tgt_…`, or '' for the cloud workspace. */
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
/** laptop | gpu | cloud | … as the platform names it; 'sandbox' for the cloud workspace. */
|
|
9
|
+
kind: string;
|
|
10
|
+
/** online | offline | draining | not seen yet, as machines.ts `state` reads it; the cloud workspace is always online. */
|
|
11
|
+
status: string;
|
|
12
|
+
/** "10 vCPU / 122G / 1× GB10", when the machine reported one. */
|
|
13
|
+
capacity: string;
|
|
14
|
+
/** The hostname its runs report, or '' (the cloud workspace, or a machine addressed by id only). */
|
|
15
|
+
host?: string;
|
|
16
|
+
/** A machine's folders its owner lets a run from the web work in (machines.ts); none elsewhere. */
|
|
17
|
+
folders?: string[];
|
|
18
|
+
}
|
|
19
|
+
/** The cloud workspace, named in English and marked (`phrase`): a screen draws its label through `t`. */
|
|
20
|
+
export declare const SANDBOX: Place;
|
|
21
|
+
export declare function places(t: Target): Promise<Place[]>;
|
|
22
|
+
/** A place as a person reads it: the name they gave the machine (`names`, from `useDeviceNames`), else its own as a person says it. */
|
|
23
|
+
export declare function displayPlace(p: Place, opts?: {
|
|
24
|
+
devMode?: boolean;
|
|
25
|
+
say?: Say;
|
|
26
|
+
names?: Names;
|
|
27
|
+
}): {
|
|
28
|
+
title: string;
|
|
29
|
+
detail?: string;
|
|
30
|
+
};
|
|
31
|
+
/** Whether a run sent here now would be taken. */
|
|
32
|
+
export declare const ready: (p: Place) => boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a run can run: the platform's cloud workspace, or one of the org's machines.
|
|
3
|
+
*
|
|
4
|
+
* GET /v1/agent/targets → {targets: [...]}, newest first (machines.ts)
|
|
5
|
+
*
|
|
6
|
+
* The cloud workspace is not a row the platform lists — it is what a run gets when it
|
|
7
|
+
* names no target — so it is the first place here and carries no id. A machine
|
|
8
|
+
* can take a run only while it is online.
|
|
9
|
+
*/
|
|
10
|
+
import { phrase } from '@hanzo/i18n';
|
|
11
|
+
import { formatDeviceLabel } from '../dev-mode.js';
|
|
12
|
+
import { deviceKey } from '../names.js';
|
|
13
|
+
import { english } from '../say.js';
|
|
14
|
+
import { machines, state } from './machines.js';
|
|
15
|
+
/** The cloud workspace, named in English and marked (`phrase`): a screen draws its label through `t`. */
|
|
16
|
+
export const SANDBOX = { id: '', label: phrase('Hanzo sandbox'), kind: 'sandbox', status: 'online', capacity: '' };
|
|
17
|
+
export async function places(t) {
|
|
18
|
+
const list = await machines(t);
|
|
19
|
+
return [SANDBOX, ...list.map((m) => ({ id: m.id, label: m.label, kind: m.kind, status: state(m), capacity: m.capacity, ...(m.host ? { host: m.host } : {}), ...(m.folders.length ? { folders: m.folders } : {}) }))];
|
|
20
|
+
}
|
|
21
|
+
/** A place as a person reads it: the name they gave the machine (`names`, from `useDeviceNames`), else its own as a person says it. */
|
|
22
|
+
export function displayPlace(p, opts) {
|
|
23
|
+
const say = opts?.say ?? english;
|
|
24
|
+
if (!p.id)
|
|
25
|
+
return opts?.devMode ? { title: 'Cloud' } : { title: say('Auto (Cloud)'), detail: say('Runs automatically in your Hanzo cloud workspace') };
|
|
26
|
+
return formatDeviceLabel(p.label, { hardware: p.capacity, host: p.host, name: opts?.names?.[deviceKey(p.host, p.label, p.id)], devMode: opts?.devMode, say });
|
|
27
|
+
}
|
|
28
|
+
/** Whether a run sent here now would be taken. */
|
|
29
|
+
export const ready = (p) => p.status === 'online';
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adding a repository to a project, which is how a project is published.
|
|
3
|
+
*
|
|
4
|
+
* POST /v1/platform/apps {repo, ref, name, partOf, mode, tag?}
|
|
5
|
+
* → 202 {app, build?: {id, job, image, status}, declaration: {mode, ref, review, live, …}, notice?}
|
|
6
|
+
* GET /v1/platform/builds → {builds: [{id, repo, commit, status, startedAt, duration}]}
|
|
7
|
+
*
|
|
8
|
+
* The declaration is a values file in universe. `branch` (the default) opens a
|
|
9
|
+
* review and deploys nothing; `commit` writes main and CD applies it — and it
|
|
10
|
+
* refuses to name an image that is not built yet, so publishing to main is two
|
|
11
|
+
* calls: build on a branch, then commit that tag once the build is green. An
|
|
12
|
+
* org admin gets both; anyone else gets the review link.
|
|
13
|
+
*
|
|
14
|
+
* A repository in the org's own code workspace is its project's site instead:
|
|
15
|
+
* built in a sandbox and served at the project's address when the build
|
|
16
|
+
* finishes. That answer is `declaration.live` with a `notice` saying so, and no
|
|
17
|
+
* review; its build is on the same board, building, succeeded or failed.
|
|
18
|
+
*/
|
|
19
|
+
import { type Target } from './call.ts';
|
|
20
|
+
export interface Declare {
|
|
21
|
+
/** The https clone URL. */
|
|
22
|
+
repo: string;
|
|
23
|
+
/** Branch, tag or sha to build. */
|
|
24
|
+
ref: string;
|
|
25
|
+
/** The app's name: a DNS-1123 label. */
|
|
26
|
+
name: string;
|
|
27
|
+
/** The project it joins. */
|
|
28
|
+
project: string;
|
|
29
|
+
mode: 'branch' | 'commit';
|
|
30
|
+
/** Release an image an earlier call built, instead of building. */
|
|
31
|
+
tag?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface Declared {
|
|
34
|
+
build: {
|
|
35
|
+
id: string;
|
|
36
|
+
job: string;
|
|
37
|
+
image: string;
|
|
38
|
+
status: string;
|
|
39
|
+
} | null;
|
|
40
|
+
mode: string;
|
|
41
|
+
/** Where the declaration landed: main for a commit, the review branch otherwise. */
|
|
42
|
+
ref: string;
|
|
43
|
+
/** The pull request to open for a branch write, or ''. */
|
|
44
|
+
review: string;
|
|
45
|
+
/** Whether anything can deploy from this write. */
|
|
46
|
+
live: boolean;
|
|
47
|
+
/** Verified https live host URLs declared on the app, if returned by the platform (#365). */
|
|
48
|
+
hosts: string[];
|
|
49
|
+
/** What the platform says of this write in a sentence, or ''. */
|
|
50
|
+
notice: string;
|
|
51
|
+
}
|
|
52
|
+
export interface Build {
|
|
53
|
+
id: string;
|
|
54
|
+
repo: string;
|
|
55
|
+
commit: string;
|
|
56
|
+
status: string;
|
|
57
|
+
startedAt: string;
|
|
58
|
+
duration: string;
|
|
59
|
+
}
|
|
60
|
+
/** A DNS-1123 label from anything: what an app may be named. */
|
|
61
|
+
export declare function label(s: string): string;
|
|
62
|
+
/** An https address, or '' — a review link is shown as a link only when it is one. */
|
|
63
|
+
export declare const https: (url: string) => string;
|
|
64
|
+
export declare function body(d: Declare): Record<string, string>;
|
|
65
|
+
export declare function declare(t: Target, d: Declare): Promise<Declared>;
|
|
66
|
+
export declare function builds(t: Target): Promise<Build[]>;
|
|
67
|
+
/** The clone URL for a GitHub repository. */
|
|
68
|
+
export declare const clone: (fullName: string) => string;
|