@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,123 @@
|
|
|
1
|
+
import { type Target } from './call.ts';
|
|
2
|
+
export type Status = 'running' | 'paused' | 'done' | 'error' | 'stopped' | string;
|
|
3
|
+
export interface Session {
|
|
4
|
+
id: string;
|
|
5
|
+
title: string;
|
|
6
|
+
status: Status;
|
|
7
|
+
agent: string;
|
|
8
|
+
actor: string;
|
|
9
|
+
repo: string;
|
|
10
|
+
project: string;
|
|
11
|
+
target: string;
|
|
12
|
+
/** The hostname of the machine it runs on, as that machine reported it, or ''. */
|
|
13
|
+
host: string;
|
|
14
|
+
/** The folder it is working in now, as its machine reports it (a linked shell moves), or ''. */
|
|
15
|
+
cwd: string;
|
|
16
|
+
/** What sort of run: 'coding' for a coding run. */
|
|
17
|
+
kind: string;
|
|
18
|
+
/** The branch the run started from, or ''. */
|
|
19
|
+
base: string;
|
|
20
|
+
/** The branch the run pushes to — the only one it may write. */
|
|
21
|
+
branch: string;
|
|
22
|
+
/** 'sandbox', or the id of the org's machine it runs on. */
|
|
23
|
+
environment: string;
|
|
24
|
+
/** 'build' or 'plan', as the coding service recorded it; '' for other runs. */
|
|
25
|
+
mode: string;
|
|
26
|
+
/** The pull request the run proposed, or ''. */
|
|
27
|
+
pr: string;
|
|
28
|
+
/** The sandbox the run leased, once it has one. It is gone when the run ends. */
|
|
29
|
+
sandbox: string;
|
|
30
|
+
/** The org the run is in, which the public build route is addressed by. */
|
|
31
|
+
org: string;
|
|
32
|
+
/** Whether its story is open to the public build route. Only a run that names a project can be. */
|
|
33
|
+
published: boolean;
|
|
34
|
+
/** Where it was started: 'app' for a conversation in Dev (talk.ts), '' for a run on its own. */
|
|
35
|
+
channel: string;
|
|
36
|
+
/** The session it belongs to — a conversation, for the coding runs it started — or ''. */
|
|
37
|
+
parent: string;
|
|
38
|
+
/** The top of its tree: its own id for a session of its own. A stream is followed by it. */
|
|
39
|
+
root: string;
|
|
40
|
+
events: number;
|
|
41
|
+
createdAt: string;
|
|
42
|
+
updatedAt: string;
|
|
43
|
+
endedAt: string;
|
|
44
|
+
}
|
|
45
|
+
export interface Event {
|
|
46
|
+
id: string;
|
|
47
|
+
sessionId: string;
|
|
48
|
+
seq: number;
|
|
49
|
+
kind: string;
|
|
50
|
+
actor: string;
|
|
51
|
+
payload: unknown;
|
|
52
|
+
createdAt: string;
|
|
53
|
+
}
|
|
54
|
+
export interface Detail extends Session {
|
|
55
|
+
recent: Event[];
|
|
56
|
+
}
|
|
57
|
+
export declare function session(raw: unknown): Session;
|
|
58
|
+
export declare function event(raw: unknown): Event;
|
|
59
|
+
/**
|
|
60
|
+
* How long runs in one mode took, in whole minutes: the median and the ninetieth
|
|
61
|
+
* percentile of the finished ones. Null under three, which is too few to say.
|
|
62
|
+
*/
|
|
63
|
+
export declare function took(runs: Session[], mode: string): [number, number] | null;
|
|
64
|
+
export interface ListQuery {
|
|
65
|
+
kind?: string;
|
|
66
|
+
/** The sessions started on one channel: 'app' for Dev's conversations. */
|
|
67
|
+
channel?: string;
|
|
68
|
+
project?: string;
|
|
69
|
+
/** running, paused, done or error: the four the platform filters on. */
|
|
70
|
+
status?: string;
|
|
71
|
+
limit?: number;
|
|
72
|
+
/** The `next` of the page before. */
|
|
73
|
+
after?: string;
|
|
74
|
+
}
|
|
75
|
+
export interface Page {
|
|
76
|
+
sessions: Session[];
|
|
77
|
+
/** The cursor for the page after this one, or '' on the last. */
|
|
78
|
+
next: string;
|
|
79
|
+
}
|
|
80
|
+
export declare function page(t: Target, q?: ListQuery): Promise<Page>;
|
|
81
|
+
export declare function list(t: Target, q?: ListQuery): Promise<Session[]>;
|
|
82
|
+
export interface GetOptions {
|
|
83
|
+
limit?: number;
|
|
84
|
+
after?: number;
|
|
85
|
+
}
|
|
86
|
+
export declare function get(t: Target, id: string, opts?: GetOptions): Promise<Detail>;
|
|
87
|
+
/**
|
|
88
|
+
* A session's whole log, oldest first, read a page at a time — what a conversation
|
|
89
|
+
* draws from its first word, where the detail carries only the latest fifty.
|
|
90
|
+
*/
|
|
91
|
+
export declare function log(t: Target, id: string): Promise<Event[]>;
|
|
92
|
+
export declare function message(t: Target, id: string, text: string): Promise<void>;
|
|
93
|
+
export declare function stop(t: Target, id: string, why?: string): Promise<void>;
|
|
94
|
+
/** A run, deleted for good: its record and every link it was shared by. */
|
|
95
|
+
export declare function remove(t: Target, id: string): Promise<void>;
|
|
96
|
+
export declare function pause(t: Target, id: string): Promise<void>;
|
|
97
|
+
export declare function resume(t: Target, id: string): Promise<void>;
|
|
98
|
+
/** A new title, up to the platform's 512 characters. */
|
|
99
|
+
export declare function rename(t: Target, id: string, title: string): Promise<Session>;
|
|
100
|
+
/**
|
|
101
|
+
* Open the run's story to the public build route, or close it. The platform
|
|
102
|
+
* refuses to open one that names no project, because that route is keyed on
|
|
103
|
+
* the org and the project.
|
|
104
|
+
*/
|
|
105
|
+
export declare function publish(t: Target, id: string, on: boolean): Promise<Session>;
|
|
106
|
+
/** Where anyone can read a published run's story: the public build route, by org and project. '' without both. */
|
|
107
|
+
export declare const story: (t: Target, org: string | null, project: string) => string;
|
|
108
|
+
export interface Watch {
|
|
109
|
+
session?: (s: Session) => void;
|
|
110
|
+
event?: (e: Event) => void;
|
|
111
|
+
/** Each (re)connect. The first is 0; a later one means frames may have been missed. */
|
|
112
|
+
open?: (attempt: number) => void;
|
|
113
|
+
}
|
|
114
|
+
export interface WatchOptions {
|
|
115
|
+
/** Resume replaying missed events strictly after this sequence number. */
|
|
116
|
+
after?: number;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Follow one run's tree until `signal` aborts. Reconnects with a capped backoff
|
|
120
|
+
* and replays missed frames via `?after=<lastSeq>` + `Last-Event-ID`; a refusal
|
|
121
|
+
* (401/403) ends it, because retrying a no is not recovery.
|
|
122
|
+
*/
|
|
123
|
+
export declare function watch(t: Target, root: string, on: Watch, signal: AbortSignal, opts?: WatchOptions): Promise<void>;
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs, as the platform records them: one session per run — and Dev's
|
|
3
|
+
* conversations (talk.ts), one session for every turn.
|
|
4
|
+
*
|
|
5
|
+
* GET /v1/agent/sessions?kind=&channel=&project=&status=&limit=&after= newest first, {sessions, next}
|
|
6
|
+
* GET /v1/agent/sessions/{id} + the 50 most recent events
|
|
7
|
+
* GET /v1/agent/sessions/{id}/events?after=&limit= its whole log, a page at a time, {events, next}
|
|
8
|
+
* PATCH /v1/agent/sessions/{id} {title}|{published} rename it; open its story to the public build route
|
|
9
|
+
* POST /v1/agent/sessions/{id}/message {message} steer a running run
|
|
10
|
+
* POST /v1/agent/sessions/{id}/pause pause it; a sandbox run keeps its work on its branch
|
|
11
|
+
* POST /v1/agent/sessions/{id}/resume ask a paused run to go on
|
|
12
|
+
* POST /v1/agent/sessions/{id}/stop {message} end it, work kept
|
|
13
|
+
* GET /v1/agent/sessions/stream?root={id} SSE: `session` and `event` frames,
|
|
14
|
+
* each wrapped: {"session":{…}}, {"event":{…}}
|
|
15
|
+
*
|
|
16
|
+
* The stream is best-effort by the platform's own statement: a subscriber that
|
|
17
|
+
* falls 256 frames behind is dropped. So `watch` reconnects, and every
|
|
18
|
+
* reconnect is reported, which is the caller's cue to re-read the detail.
|
|
19
|
+
*/
|
|
20
|
+
import { phrase } from '@hanzo/i18n';
|
|
21
|
+
import { call, headers, query, Refusal, seg } from './call.js';
|
|
22
|
+
import { read } from './sse.js';
|
|
23
|
+
const str = (v) => (typeof v === 'string' ? v : '');
|
|
24
|
+
const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : 0);
|
|
25
|
+
const obj = (v) => v && typeof v === 'object' ? v : {};
|
|
26
|
+
export function session(raw) {
|
|
27
|
+
const s = obj(raw);
|
|
28
|
+
return {
|
|
29
|
+
id: str(s.id),
|
|
30
|
+
title: str(s.title),
|
|
31
|
+
status: str(s.status),
|
|
32
|
+
agent: str(s.agent),
|
|
33
|
+
actor: str(s.actor),
|
|
34
|
+
repo: str(s.repo),
|
|
35
|
+
project: str(s.project),
|
|
36
|
+
target: str(s.target),
|
|
37
|
+
host: str(s.host),
|
|
38
|
+
cwd: str(s.cwd),
|
|
39
|
+
kind: str(s.kind),
|
|
40
|
+
base: str(s.base),
|
|
41
|
+
branch: str(s.branch),
|
|
42
|
+
environment: str(s.environment),
|
|
43
|
+
mode: str(s.mode),
|
|
44
|
+
pr: str(s.pr),
|
|
45
|
+
sandbox: str(s.sandbox),
|
|
46
|
+
org: str(s.org),
|
|
47
|
+
published: s.published === true,
|
|
48
|
+
channel: str(s.channel),
|
|
49
|
+
parent: str(s.parentSessionId),
|
|
50
|
+
root: str(s.rootSessionId),
|
|
51
|
+
events: num(s.events),
|
|
52
|
+
createdAt: str(s.createdAt),
|
|
53
|
+
updatedAt: str(s.updatedAt),
|
|
54
|
+
endedAt: str(s.endedAt),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export function event(raw) {
|
|
58
|
+
const e = obj(raw);
|
|
59
|
+
return {
|
|
60
|
+
id: str(e.id),
|
|
61
|
+
sessionId: str(e.sessionId),
|
|
62
|
+
seq: num(e.seq),
|
|
63
|
+
kind: str(e.kind),
|
|
64
|
+
actor: str(e.actor),
|
|
65
|
+
payload: e.payload,
|
|
66
|
+
createdAt: str(e.createdAt),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* How long runs in one mode took, in whole minutes: the median and the ninetieth
|
|
71
|
+
* percentile of the finished ones. Null under three, which is too few to say.
|
|
72
|
+
*/
|
|
73
|
+
export function took(runs, mode) {
|
|
74
|
+
const spans = runs
|
|
75
|
+
.filter((r) => r.mode === mode && r.status === 'done' && r.endedAt)
|
|
76
|
+
.map((r) => Date.parse(r.endedAt) - Date.parse(r.createdAt))
|
|
77
|
+
.filter((ms) => Number.isFinite(ms) && ms > 0)
|
|
78
|
+
.sort((a, b) => a - b);
|
|
79
|
+
if (spans.length < 3)
|
|
80
|
+
return null;
|
|
81
|
+
const at = (q) => Math.max(1, Math.round(spans[Math.min(spans.length - 1, Math.floor(q * spans.length))] / 60_000));
|
|
82
|
+
return [at(0.5), at(0.9)];
|
|
83
|
+
}
|
|
84
|
+
export async function page(t, q = {}) {
|
|
85
|
+
const raw = obj(await call(t, 'GET', `/v1/agent/sessions${query({ ...q })}`));
|
|
86
|
+
return {
|
|
87
|
+
sessions: (Array.isArray(raw.sessions) ? raw.sessions : []).map(session).filter((s) => s.id),
|
|
88
|
+
next: str(raw.next),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export async function list(t, q = {}) {
|
|
92
|
+
return (await page(t, q)).sessions;
|
|
93
|
+
}
|
|
94
|
+
export async function get(t, id, opts) {
|
|
95
|
+
const raw = obj(await call(t, 'GET', `/v1/agent/sessions/${seg(id)}${query({ limit: opts?.limit, after: opts?.after })}`));
|
|
96
|
+
let recent = (Array.isArray(raw.recentEvents) ? raw.recentEvents : []).map(event);
|
|
97
|
+
// When `limit` is explicitly requested (e.g. Run's initial 500-event load) and a
|
|
98
|
+
// long coding run still exceeds one page (`recent[0].seq > 1`), page forward from
|
|
99
|
+
// seq 0 so middle history is never dropped. Without `opts`, keep the lightweight
|
|
100
|
+
// 2-event head fetch so short summary callers stay single-hop.
|
|
101
|
+
if (recent.length > 0 && recent[0].seq > 1 && opts?.after === undefined) {
|
|
102
|
+
const tailFloor = recent[0].seq;
|
|
103
|
+
if (opts?.limit && opts.limit > 50) {
|
|
104
|
+
try {
|
|
105
|
+
const earlier = [];
|
|
106
|
+
let cursor = 0;
|
|
107
|
+
for (let page = 0; page < 6 && cursor < tailFloor - 1; page++) {
|
|
108
|
+
const chunk = obj(await call(t, 'GET', `/v1/agent/sessions/${seg(id)}/events${query({ after: cursor || undefined, limit: Math.min(1000, opts.limit) })}`));
|
|
109
|
+
const rows = (Array.isArray(chunk.events) ? chunk.events : []).map(event);
|
|
110
|
+
earlier.push(...rows.filter((e) => e.seq > 0 && e.seq < tailFloor));
|
|
111
|
+
const next = num(chunk.next);
|
|
112
|
+
if (next <= cursor || next >= tailFloor - 1)
|
|
113
|
+
break;
|
|
114
|
+
cursor = next;
|
|
115
|
+
}
|
|
116
|
+
const have = new Set(recent.map((e) => e.seq));
|
|
117
|
+
recent = [...earlier.filter((e) => !have.has(e.seq)), ...recent].sort((a, b) => a.seq - b.seq);
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
/* keep the tail */
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
try {
|
|
125
|
+
const head = obj(await call(t, 'GET', `/v1/agent/sessions/${seg(id)}/events?limit=2`));
|
|
126
|
+
const first = (Array.isArray(head.events) ? head.events : []).map(event);
|
|
127
|
+
const have = new Set(recent.map((e) => e.seq));
|
|
128
|
+
recent = [...first.filter((e) => e.seq > 0 && !have.has(e.seq)), ...recent].sort((a, b) => a.seq - b.seq);
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
/* keep the tail */
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
...session(raw),
|
|
137
|
+
recent,
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* A session's whole log, oldest first, read a page at a time — what a conversation
|
|
142
|
+
* draws from its first word, where the detail carries only the latest fifty.
|
|
143
|
+
*/
|
|
144
|
+
export async function log(t, id) {
|
|
145
|
+
const out = [];
|
|
146
|
+
let after = 0;
|
|
147
|
+
for (;;) {
|
|
148
|
+
const raw = obj(await call(t, 'GET', `/v1/agent/sessions/${seg(id)}/events${query({ after: after || undefined, limit: 1000 })}`));
|
|
149
|
+
out.push(...(Array.isArray(raw.events) ? raw.events : []).map(event));
|
|
150
|
+
const next = num(raw.next);
|
|
151
|
+
if (next <= after)
|
|
152
|
+
return out;
|
|
153
|
+
after = next;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
export async function message(t, id, text) {
|
|
157
|
+
const m = text.trim();
|
|
158
|
+
if (!m)
|
|
159
|
+
throw new Refusal(400, phrase('Say something to the run'));
|
|
160
|
+
await call(t, 'POST', `/v1/agent/sessions/${seg(id)}/message`, { message: m });
|
|
161
|
+
}
|
|
162
|
+
export async function stop(t, id, why = 'Stopped from the builder') {
|
|
163
|
+
await call(t, 'POST', `/v1/agent/sessions/${seg(id)}/stop`, { message: why });
|
|
164
|
+
}
|
|
165
|
+
/** A run, deleted for good: its record and every link it was shared by. */
|
|
166
|
+
export async function remove(t, id) {
|
|
167
|
+
await call(t, 'DELETE', `/v1/agent/sessions/${seg(id)}`);
|
|
168
|
+
}
|
|
169
|
+
export async function pause(t, id) {
|
|
170
|
+
await call(t, 'POST', `/v1/agent/sessions/${seg(id)}/pause`, {});
|
|
171
|
+
}
|
|
172
|
+
export async function resume(t, id) {
|
|
173
|
+
await call(t, 'POST', `/v1/agent/sessions/${seg(id)}/resume`, {});
|
|
174
|
+
}
|
|
175
|
+
/** A new title, up to the platform's 512 characters. */
|
|
176
|
+
export async function rename(t, id, title) {
|
|
177
|
+
const name = title.trim();
|
|
178
|
+
if (!name)
|
|
179
|
+
throw new Refusal(400, phrase('Give the run a name'));
|
|
180
|
+
if (name.length > 512)
|
|
181
|
+
throw new Refusal(400, phrase('A run’s name is at most 512 characters'));
|
|
182
|
+
return session(await call(t, 'PATCH', `/v1/agent/sessions/${seg(id)}`, { title: name }));
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Open the run's story to the public build route, or close it. The platform
|
|
186
|
+
* refuses to open one that names no project, because that route is keyed on
|
|
187
|
+
* the org and the project.
|
|
188
|
+
*/
|
|
189
|
+
export async function publish(t, id, on) {
|
|
190
|
+
return session(await call(t, 'PATCH', `/v1/agent/sessions/${seg(id)}`, { published: on }));
|
|
191
|
+
}
|
|
192
|
+
/** Where anyone can read a published run's story: the public build route, by org and project. '' without both. */
|
|
193
|
+
export const story = (t, org, project) => org && project ? `${t.api}/v1/agent/builds/${seg(org)}/${seg(project)}` : '';
|
|
194
|
+
/**
|
|
195
|
+
* Follow one run's tree until `signal` aborts. Reconnects with a capped backoff
|
|
196
|
+
* and replays missed frames via `?after=<lastSeq>` + `Last-Event-ID`; a refusal
|
|
197
|
+
* (401/403) ends it, because retrying a no is not recovery.
|
|
198
|
+
*/
|
|
199
|
+
export async function watch(t, root, on, signal, opts) {
|
|
200
|
+
let opened = 0;
|
|
201
|
+
let fails = 0;
|
|
202
|
+
let lastSeq = opts?.after && Number.isFinite(opts.after) && opts.after > 0 ? Math.floor(opts.after) : 0;
|
|
203
|
+
while (!signal.aborted) {
|
|
204
|
+
try {
|
|
205
|
+
const extra = { Accept: 'text/event-stream' };
|
|
206
|
+
if (lastSeq > 0)
|
|
207
|
+
extra['Last-Event-ID'] = String(lastSeq);
|
|
208
|
+
const res = await fetch(`${t.api}/v1/agent/sessions/stream${query({ root, after: lastSeq > 0 ? lastSeq : undefined })}`, {
|
|
209
|
+
headers: headers(t, extra),
|
|
210
|
+
cache: 'no-store',
|
|
211
|
+
signal,
|
|
212
|
+
});
|
|
213
|
+
if (res.status === 401 || res.status === 403)
|
|
214
|
+
throw new Refusal(res.status, phrase('This account cannot follow this run'));
|
|
215
|
+
if (!res.ok || !res.body)
|
|
216
|
+
throw new Error(`stream answered ${res.status}`);
|
|
217
|
+
on.open?.(opened++);
|
|
218
|
+
fails = 0;
|
|
219
|
+
await read(res.body, (f) => {
|
|
220
|
+
let data;
|
|
221
|
+
try {
|
|
222
|
+
data = JSON.parse(f.data);
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (f.event === 'session')
|
|
228
|
+
on.session?.(session(obj(data).session));
|
|
229
|
+
else if (f.event === 'event') {
|
|
230
|
+
const ev = event(obj(data).event);
|
|
231
|
+
if (!root || !ev.sessionId || ev.sessionId === root) {
|
|
232
|
+
const fid = Number(f.id);
|
|
233
|
+
if (Number.isInteger(fid) && fid > lastSeq)
|
|
234
|
+
lastSeq = fid;
|
|
235
|
+
if (ev.seq > lastSeq)
|
|
236
|
+
lastSeq = ev.seq;
|
|
237
|
+
}
|
|
238
|
+
on.event?.(ev);
|
|
239
|
+
}
|
|
240
|
+
}, signal);
|
|
241
|
+
}
|
|
242
|
+
catch (e) {
|
|
243
|
+
if (e instanceof Refusal)
|
|
244
|
+
throw e;
|
|
245
|
+
if (signal.aborted)
|
|
246
|
+
return;
|
|
247
|
+
fails += 1;
|
|
248
|
+
}
|
|
249
|
+
const wait = Math.min(15000, 1000 * 2 ** Math.min(fails, 4));
|
|
250
|
+
await new Promise((done) => {
|
|
251
|
+
const t = setTimeout(done, wait);
|
|
252
|
+
signal.addEventListener('abort', () => (clearTimeout(t), done()), { once: true });
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { type Target } from './call.ts';
|
|
2
|
+
import { type Tool } from './tools.ts';
|
|
3
|
+
/** An org's own skill. */
|
|
4
|
+
export interface Skill {
|
|
5
|
+
/** Derived from the name, and what a delete addresses. */
|
|
6
|
+
id: string;
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
/** The SKILL.md body. */
|
|
10
|
+
content: string;
|
|
11
|
+
/** When it was last written, Unix seconds. */
|
|
12
|
+
created: number;
|
|
13
|
+
/** The repository it was read from, or '' for one written here. */
|
|
14
|
+
source: string;
|
|
15
|
+
/** False when no admin wrote it, so no run carries it; true, or unsaid by an older platform. */
|
|
16
|
+
admitted: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** One skill of the brand's catalogue. */
|
|
19
|
+
export interface Entry {
|
|
20
|
+
name: string;
|
|
21
|
+
description: string;
|
|
22
|
+
/** The product it belongs to. */
|
|
23
|
+
product: string;
|
|
24
|
+
/** The kinds of work (`roles.ts` WORK) the catalogue recommends it for. */
|
|
25
|
+
works: string[];
|
|
26
|
+
}
|
|
27
|
+
export interface Catalogue {
|
|
28
|
+
skills: Entry[];
|
|
29
|
+
products: {
|
|
30
|
+
name: string;
|
|
31
|
+
count: number;
|
|
32
|
+
}[];
|
|
33
|
+
}
|
|
34
|
+
/** A skill's name: one lowercase path segment, as the handler takes it. */
|
|
35
|
+
export declare const NAME: RegExp;
|
|
36
|
+
/** The most SKILL.md the handler keeps. */
|
|
37
|
+
export declare const MAX: number;
|
|
38
|
+
/** The tool name a skill is switched on by. */
|
|
39
|
+
export declare const tool: (name: string) => string;
|
|
40
|
+
/** The skill a tool name switches, or '' when it is not a skill's. */
|
|
41
|
+
export declare const nameOf: (tool: string) => string;
|
|
42
|
+
export declare function skill(raw: unknown): Skill;
|
|
43
|
+
export declare function catalogue(raw: unknown): Catalogue;
|
|
44
|
+
/** The org's skills that are on, brand and own. */
|
|
45
|
+
export declare function active(t: Target): Promise<Tool[]>;
|
|
46
|
+
export declare function authored(t: Target): Promise<Skill[]>;
|
|
47
|
+
/** Why a skill cannot be written as it stands, or '' when it can. English, marked (`phrase`): a screen says it through `t`. */
|
|
48
|
+
export declare function refuse(s: {
|
|
49
|
+
name: string;
|
|
50
|
+
content: string;
|
|
51
|
+
}): string;
|
|
52
|
+
export declare function write(t: Target, s: {
|
|
53
|
+
name: string;
|
|
54
|
+
description: string;
|
|
55
|
+
content: string;
|
|
56
|
+
}): Promise<Skill>;
|
|
57
|
+
export declare function remove(t: Target, id: string): Promise<void>;
|
|
58
|
+
export declare function brand(t: Target): Promise<Catalogue>;
|
|
59
|
+
/** One catalogue skill's SKILL.md. */
|
|
60
|
+
export declare function document(t: Target, name: string): Promise<string>;
|
|
61
|
+
/** One thing Kai picked for a message: a skill (`skill_<name>`) or a tool, how likely it applies, and what it does. */
|
|
62
|
+
export interface Detected {
|
|
63
|
+
/** The skill's own name for a skill (`code-review`), else the tool's. */
|
|
64
|
+
name: string;
|
|
65
|
+
skill: boolean;
|
|
66
|
+
/** Where it comes from: skill, mcp, connector, function, agent. */
|
|
67
|
+
source: string;
|
|
68
|
+
description: string;
|
|
69
|
+
/** 0 to 1. */
|
|
70
|
+
probability: number;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Which skills and tools apply to `prompt`, as Kai decides it (cloud apps/tools
|
|
74
|
+
* detect.go; a lexical fallback answers when Kai does not). Only asks: nothing
|
|
75
|
+
* is switched on (`autoActivate` is left out), so a message carries what was
|
|
76
|
+
* picked for it and nothing more.
|
|
77
|
+
*/
|
|
78
|
+
export declare function detect(t: Target, prompt: string, opts?: {
|
|
79
|
+
maxSkills?: number;
|
|
80
|
+
maxTools?: number;
|
|
81
|
+
signal?: AbortSignal;
|
|
82
|
+
}): Promise<Detected[]>;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skills: what an agent knows how to do, as a SKILL.md it reads.
|
|
3
|
+
*
|
|
4
|
+
* GET /v1/tool/skills?activated=true {tools: [Tool]} the org's skills that are on, brand and own
|
|
5
|
+
* GET /v1/tool/skills/authored {skills: [skill]} the org's own, with their SKILL.md
|
|
6
|
+
* POST /v1/tool/skills {name, description, content} → 201 {skill}; the same name revises it
|
|
7
|
+
* DELETE /v1/tool/skills/{id} {deleted}
|
|
8
|
+
* GET /.well-known/agent-skills/index.json the brand's catalogue, public
|
|
9
|
+
* GET /.well-known/agent-skills/{name}/SKILL.md one of its documents, public
|
|
10
|
+
* POST /v1/tool/detect {prompt, maxSkills, maxTools} → {skills, tools} Kai's pick for one message
|
|
11
|
+
*
|
|
12
|
+
* A skill is on when its tool name, `skill_<name>`, is activated (tools.ts):
|
|
13
|
+
* that is how a catalogue skill is added to an org and how an org's own skill is
|
|
14
|
+
* switched off. The brand's skill wins a name an org's own skill also takes.
|
|
15
|
+
*/
|
|
16
|
+
import { phrase } from '@hanzo/i18n';
|
|
17
|
+
import { call, reason, Refusal, seg } from './call.js';
|
|
18
|
+
import { toolsOf } from './tools.js';
|
|
19
|
+
/** A skill's name: one lowercase path segment, as the handler takes it. */
|
|
20
|
+
export const NAME = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
21
|
+
/** The most SKILL.md the handler keeps. */
|
|
22
|
+
export const MAX = 256 << 10;
|
|
23
|
+
/** The tool name a skill is switched on by. */
|
|
24
|
+
export const tool = (name) => `skill_${name}`;
|
|
25
|
+
/** The skill a tool name switches, or '' when it is not a skill's. */
|
|
26
|
+
export const nameOf = (tool) => (tool.startsWith('skill_') ? tool.slice('skill_'.length) : '');
|
|
27
|
+
const str = (v) => (typeof v === 'string' ? v : '');
|
|
28
|
+
const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : 0);
|
|
29
|
+
const obj = (v) => (v && typeof v === 'object' ? v : {});
|
|
30
|
+
const rows = (v) => (Array.isArray(v) ? v : []);
|
|
31
|
+
export function skill(raw) {
|
|
32
|
+
const o = obj(raw);
|
|
33
|
+
const name = str(o.name);
|
|
34
|
+
return {
|
|
35
|
+
id: str(o.id) || name,
|
|
36
|
+
name,
|
|
37
|
+
description: str(o.description),
|
|
38
|
+
content: str(o.content),
|
|
39
|
+
created: num(o.createdAt),
|
|
40
|
+
source: str(o.source),
|
|
41
|
+
admitted: o.admitted !== false,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function catalogue(raw) {
|
|
45
|
+
const o = obj(raw);
|
|
46
|
+
return {
|
|
47
|
+
skills: rows(o.skills)
|
|
48
|
+
.map((r) => {
|
|
49
|
+
const e = obj(r);
|
|
50
|
+
return { name: str(e.name), description: str(e.description), product: str(e.service), works: rows(e.works).map(str).filter(Boolean) };
|
|
51
|
+
})
|
|
52
|
+
.filter((e) => e.name),
|
|
53
|
+
products: rows(o.products)
|
|
54
|
+
.map((r) => {
|
|
55
|
+
const p = obj(r);
|
|
56
|
+
return { name: str(p.name), count: num(p.skill_count) };
|
|
57
|
+
})
|
|
58
|
+
.filter((p) => p.name),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** The org's skills that are on, brand and own. */
|
|
62
|
+
export async function active(t) {
|
|
63
|
+
return toolsOf(await call(t, 'GET', '/v1/tool/skills?activated=true'));
|
|
64
|
+
}
|
|
65
|
+
export async function authored(t) {
|
|
66
|
+
return rows(obj(await call(t, 'GET', '/v1/tool/skills/authored')).skills).map(skill).filter((s) => s.name);
|
|
67
|
+
}
|
|
68
|
+
/** Why a skill cannot be written as it stands, or '' when it can. English, marked (`phrase`): a screen says it through `t`. */
|
|
69
|
+
export function refuse(s) {
|
|
70
|
+
if (!NAME.test(s.name))
|
|
71
|
+
return phrase('A name is one lowercase word: letters, digits, _ or -');
|
|
72
|
+
if (!s.content.trim())
|
|
73
|
+
return phrase('A skill needs its SKILL.md');
|
|
74
|
+
if (new TextEncoder().encode(s.content).length > MAX)
|
|
75
|
+
return phrase('A SKILL.md is at most 256 KB');
|
|
76
|
+
return '';
|
|
77
|
+
}
|
|
78
|
+
export async function write(t, s) {
|
|
79
|
+
const why = refuse(s);
|
|
80
|
+
if (why)
|
|
81
|
+
throw new Error(why);
|
|
82
|
+
return skill(obj(await call(t, 'POST', '/v1/tool/skills', { name: s.name, description: s.description, content: s.content })).skill);
|
|
83
|
+
}
|
|
84
|
+
export async function remove(t, id) {
|
|
85
|
+
await call(t, 'DELETE', `/v1/tool/skills/${seg(id)}`);
|
|
86
|
+
}
|
|
87
|
+
/** A public document of the brand's catalogue. It needs no bearer, so it sends none. */
|
|
88
|
+
async function open(t, path) {
|
|
89
|
+
const res = await fetch(`${t.api}/.well-known/agent-skills/${path}`);
|
|
90
|
+
if (!res.ok)
|
|
91
|
+
throw new Refusal(res.status, (await reason(res)) || `The catalogue answered ${res.status}`);
|
|
92
|
+
return res;
|
|
93
|
+
}
|
|
94
|
+
export async function brand(t) {
|
|
95
|
+
return catalogue(await (await open(t, 'index.json')).json());
|
|
96
|
+
}
|
|
97
|
+
/** One catalogue skill's SKILL.md. */
|
|
98
|
+
export async function document(t, name) {
|
|
99
|
+
return (await open(t, `${seg(name)}/SKILL.md`)).text();
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Which skills and tools apply to `prompt`, as Kai decides it (cloud apps/tools
|
|
103
|
+
* detect.go; a lexical fallback answers when Kai does not). Only asks: nothing
|
|
104
|
+
* is switched on (`autoActivate` is left out), so a message carries what was
|
|
105
|
+
* picked for it and nothing more.
|
|
106
|
+
*/
|
|
107
|
+
export async function detect(t, prompt, opts = {}) {
|
|
108
|
+
const raw = await call(t, 'POST', '/v1/tool/detect', { prompt, maxSkills: opts.maxSkills ?? 3, maxTools: opts.maxTools ?? 3 }, { signal: opts.signal });
|
|
109
|
+
const r = (raw && typeof raw === 'object' ? raw : {});
|
|
110
|
+
const read = (list, skill) => (Array.isArray(list) ? list : []).flatMap((x) => {
|
|
111
|
+
const o = (x && typeof x === 'object' ? x : {});
|
|
112
|
+
const tool = str(o.name);
|
|
113
|
+
const name = skill ? nameOf(tool) || tool : tool;
|
|
114
|
+
return name ? [{ name, skill, source: str(o.source), description: str(o.description), probability: num(o.probability) }] : [];
|
|
115
|
+
});
|
|
116
|
+
return [...read(r.skills, true), ...read(r.tools, false)];
|
|
117
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-Sent Events, read off a fetch body.
|
|
3
|
+
*
|
|
4
|
+
* `EventSource` cannot send an Authorization header, and the session stream
|
|
5
|
+
* refuses a request without a principal, so the stream is read as a plain
|
|
6
|
+
* response body and parsed here. The parser is pure: bytes in, frames and the
|
|
7
|
+
* unfinished tail out, so it is tested without a network.
|
|
8
|
+
*
|
|
9
|
+
* Per the spec a frame ends at a blank line; `event:` names it (default
|
|
10
|
+
* `message`), `data:` lines join with a newline, and a line starting `:` is a
|
|
11
|
+
* comment — the platform's 25-second `: ping` keep-alive.
|
|
12
|
+
*/
|
|
13
|
+
export interface Frame {
|
|
14
|
+
event: string;
|
|
15
|
+
data: string;
|
|
16
|
+
id: string;
|
|
17
|
+
}
|
|
18
|
+
/** Split `buffer` into complete frames and the tail that has not ended yet. */
|
|
19
|
+
export declare function parse(buffer: string): {
|
|
20
|
+
frames: Frame[];
|
|
21
|
+
rest: string;
|
|
22
|
+
};
|
|
23
|
+
/** Read `body` to its end, calling `on` for each frame. */
|
|
24
|
+
export declare function read(body: ReadableStream<Uint8Array>, on: (f: Frame) => void, signal?: AbortSignal): Promise<void>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-Sent Events, read off a fetch body.
|
|
3
|
+
*
|
|
4
|
+
* `EventSource` cannot send an Authorization header, and the session stream
|
|
5
|
+
* refuses a request without a principal, so the stream is read as a plain
|
|
6
|
+
* response body and parsed here. The parser is pure: bytes in, frames and the
|
|
7
|
+
* unfinished tail out, so it is tested without a network.
|
|
8
|
+
*
|
|
9
|
+
* Per the spec a frame ends at a blank line; `event:` names it (default
|
|
10
|
+
* `message`), `data:` lines join with a newline, and a line starting `:` is a
|
|
11
|
+
* comment — the platform's 25-second `: ping` keep-alive.
|
|
12
|
+
*/
|
|
13
|
+
/** Split `buffer` into complete frames and the tail that has not ended yet. */
|
|
14
|
+
export function parse(buffer) {
|
|
15
|
+
const text = buffer.replace(/\r\n?/g, '\n');
|
|
16
|
+
const frames = [];
|
|
17
|
+
let start = 0;
|
|
18
|
+
for (;;) {
|
|
19
|
+
const end = text.indexOf('\n\n', start);
|
|
20
|
+
if (end === -1)
|
|
21
|
+
break;
|
|
22
|
+
const block = text.slice(start, end);
|
|
23
|
+
start = end + 2;
|
|
24
|
+
let event = 'message';
|
|
25
|
+
let id = '';
|
|
26
|
+
const data = [];
|
|
27
|
+
for (const line of block.split('\n')) {
|
|
28
|
+
if (!line || line.startsWith(':'))
|
|
29
|
+
continue;
|
|
30
|
+
const colon = line.indexOf(':');
|
|
31
|
+
const field = colon === -1 ? line : line.slice(0, colon);
|
|
32
|
+
let value = colon === -1 ? '' : line.slice(colon + 1);
|
|
33
|
+
if (value.startsWith(' '))
|
|
34
|
+
value = value.slice(1);
|
|
35
|
+
if (field === 'event')
|
|
36
|
+
event = value;
|
|
37
|
+
else if (field === 'data')
|
|
38
|
+
data.push(value);
|
|
39
|
+
else if (field === 'id')
|
|
40
|
+
id = value;
|
|
41
|
+
}
|
|
42
|
+
if (data.length)
|
|
43
|
+
frames.push({ event, data: data.join('\n'), id });
|
|
44
|
+
}
|
|
45
|
+
return { frames, rest: text.slice(start) };
|
|
46
|
+
}
|
|
47
|
+
/** Read `body` to its end, calling `on` for each frame. */
|
|
48
|
+
export async function read(body, on, signal) {
|
|
49
|
+
const reader = body.getReader();
|
|
50
|
+
const decoder = new TextDecoder();
|
|
51
|
+
let rest = '';
|
|
52
|
+
const stop = () => void reader.cancel().catch(() => { });
|
|
53
|
+
signal?.addEventListener('abort', stop, { once: true });
|
|
54
|
+
try {
|
|
55
|
+
for (;;) {
|
|
56
|
+
const { value, done } = await reader.read();
|
|
57
|
+
if (done)
|
|
58
|
+
break;
|
|
59
|
+
const out = parse(rest + decoder.decode(value, { stream: true }));
|
|
60
|
+
rest = out.rest;
|
|
61
|
+
for (const f of out.frames)
|
|
62
|
+
on(f);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
signal?.removeEventListener('abort', stop);
|
|
67
|
+
}
|
|
68
|
+
}
|