@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,300 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automations: a task that runs itself, on a schedule or when asked.
|
|
3
|
+
*
|
|
4
|
+
* GET /v1/auto/automations {data: [automation]}
|
|
5
|
+
* POST /v1/auto/automations create one: name and instructions
|
|
6
|
+
* GET /v1/auto/automations/{id} one
|
|
7
|
+
* PATCH /v1/auto/automations/{id} change it, or switch it on or off
|
|
8
|
+
* DELETE /v1/auto/automations/{id} delete it, its schedule and its runs
|
|
9
|
+
* POST /v1/auto/automations/{id}/run {run: {id, status}} one run, now
|
|
10
|
+
* GET /v1/auto/automations/{id}/runs {data: [run]} newest first
|
|
11
|
+
* POST /v1/auto/automations/{id}/runs/{run}/review {post} post a held post, or discard it
|
|
12
|
+
* GET /v1/auto/templates {data: [starter]} to start a new one from
|
|
13
|
+
* POST /v1/auto/cron {schedule, says, next} a schedule from a person's words
|
|
14
|
+
* GET /v1/auto/jobs {data: [job]} what runs without you, across products
|
|
15
|
+
* GET /v1/auto/jobs/{id} one job
|
|
16
|
+
* GET /v1/auto/events text/event-stream: `job` and `automation`, the reader's own
|
|
17
|
+
*
|
|
18
|
+
* Each run is one Dev run in this organization, started as the person who last
|
|
19
|
+
* saved what it does. A draft is a flow named and not yet told what to do: it
|
|
20
|
+
* runs once its instructions are saved.
|
|
21
|
+
*/
|
|
22
|
+
import { phrase } from '@hanzo/i18n';
|
|
23
|
+
import { english } from '../say.js';
|
|
24
|
+
import { call, headers, query, reason, Refusal, seg } from './call.js';
|
|
25
|
+
import { inApp } from './library.js';
|
|
26
|
+
import { read as stream } from './sse.js';
|
|
27
|
+
const str = (v) => (typeof v === 'string' ? v : '');
|
|
28
|
+
const nullable = (v) => (typeof v === 'string' && v ? v : null);
|
|
29
|
+
const obj = (v) => (v && typeof v === 'object' ? v : {});
|
|
30
|
+
const KINDS = ['manual', 'once', 'hourly', 'daily', 'weekdays', 'weekly', 'cron'];
|
|
31
|
+
const SOURCES = ['chat', 'dev', 'studio', 'workflow'];
|
|
32
|
+
const sourceOf = (v) => (SOURCES.includes(v) ? v : 'dev');
|
|
33
|
+
const strings = (v) => (Array.isArray(v) ? v : []).filter((x) => typeof x === 'string' && x !== '');
|
|
34
|
+
function schedule(raw) {
|
|
35
|
+
const o = obj(raw);
|
|
36
|
+
const kind = KINDS.includes(o.kind) ? o.kind : 'manual';
|
|
37
|
+
const out = { kind };
|
|
38
|
+
for (const k of ['at', 'day', 'cron', 'tz'])
|
|
39
|
+
if (str(o[k]))
|
|
40
|
+
out[k] = str(o[k]);
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
/** One automation as the platform answers it, or null for a row with no id. */
|
|
44
|
+
export function read(raw) {
|
|
45
|
+
const o = obj(raw);
|
|
46
|
+
const id = str(o.id);
|
|
47
|
+
if (!id)
|
|
48
|
+
return null;
|
|
49
|
+
const last = obj(o.last);
|
|
50
|
+
return {
|
|
51
|
+
id,
|
|
52
|
+
name: str(o.name) || id,
|
|
53
|
+
instructions: str(o.instructions),
|
|
54
|
+
project: nullable(o.project),
|
|
55
|
+
model: nullable(o.model),
|
|
56
|
+
schedule: schedule(o.schedule),
|
|
57
|
+
permissions: o.permissions === 'auto' ? 'auto' : 'ask',
|
|
58
|
+
notify: o.notify === true,
|
|
59
|
+
postTo: (Array.isArray(o.postTo) ? o.postTo : []).filter((x) => typeof x === 'string'),
|
|
60
|
+
enabled: o.enabled === true,
|
|
61
|
+
source: sourceOf(o.source),
|
|
62
|
+
draft: o.draft === true,
|
|
63
|
+
next: nullable(o.next),
|
|
64
|
+
last: str(last.id) ? { id: str(last.id), status: str(last.status), at: str(last.at), summary: str(last.summary) } : null,
|
|
65
|
+
created: str(o.created),
|
|
66
|
+
updated: str(o.updated),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/** The Dev run a transcript link opens: `…/dev?run=sess_…`. */
|
|
70
|
+
function session(link) {
|
|
71
|
+
const m = str(link).match(/[?&]run=(sess_[0-9a-f]{32})\b/);
|
|
72
|
+
return m ? m[1] : null;
|
|
73
|
+
}
|
|
74
|
+
const list = (raw) => (Array.isArray(obj(raw).data) ? obj(raw).data : []);
|
|
75
|
+
export async function automations(t) {
|
|
76
|
+
return list(await call(t, 'GET', '/v1/auto/automations'))
|
|
77
|
+
.map(read)
|
|
78
|
+
.filter((a) => a !== null);
|
|
79
|
+
}
|
|
80
|
+
export async function automation(t, id) {
|
|
81
|
+
const a = read(await call(t, 'GET', `/v1/auto/automations/${seg(id)}`));
|
|
82
|
+
if (!a)
|
|
83
|
+
throw new Error(phrase('The automation came back without an id'));
|
|
84
|
+
return a;
|
|
85
|
+
}
|
|
86
|
+
export async function create(t, d) {
|
|
87
|
+
const a = read(await call(t, 'POST', '/v1/auto/automations', d));
|
|
88
|
+
if (!a)
|
|
89
|
+
throw new Error(phrase('The automation was created and came back without an id'));
|
|
90
|
+
return a;
|
|
91
|
+
}
|
|
92
|
+
/** What changed between two drafts, field by field: what a save sends. */
|
|
93
|
+
export function changes(was, now) {
|
|
94
|
+
const out = {};
|
|
95
|
+
for (const k of Object.keys(now)) {
|
|
96
|
+
if (JSON.stringify(was[k]) !== JSON.stringify(now[k]))
|
|
97
|
+
out[k] = now[k];
|
|
98
|
+
}
|
|
99
|
+
return out;
|
|
100
|
+
}
|
|
101
|
+
/** Change an automation. A change to anything but `enabled` makes the caller the person it runs as. */
|
|
102
|
+
export async function save(t, id, change) {
|
|
103
|
+
const a = read(await call(t, 'PATCH', `/v1/auto/automations/${seg(id)}`, change));
|
|
104
|
+
if (!a)
|
|
105
|
+
throw new Error(phrase('The automation was saved and came back without an id'));
|
|
106
|
+
return a;
|
|
107
|
+
}
|
|
108
|
+
export async function remove(t, id) {
|
|
109
|
+
await call(t, 'DELETE', `/v1/auto/automations/${seg(id)}`);
|
|
110
|
+
}
|
|
111
|
+
/** Start one run now. While one is going, the platform records this start as skipped. */
|
|
112
|
+
export async function start(t, id) {
|
|
113
|
+
const run = obj(obj(await call(t, 'POST', `/v1/auto/automations/${seg(id)}/run`)).run);
|
|
114
|
+
return { id: str(run.id), status: str(run.status) };
|
|
115
|
+
}
|
|
116
|
+
export async function runs(t, id) {
|
|
117
|
+
return list(await call(t, 'GET', `/v1/auto/automations/${seg(id)}/runs`))
|
|
118
|
+
.map((raw) => {
|
|
119
|
+
const o = obj(raw);
|
|
120
|
+
return run(o);
|
|
121
|
+
})
|
|
122
|
+
.filter((r) => r.id);
|
|
123
|
+
}
|
|
124
|
+
function run(o) {
|
|
125
|
+
const posts = (Array.isArray(o.posts) ? o.posts : [])
|
|
126
|
+
.map(obj)
|
|
127
|
+
.filter((p) => str(p.to))
|
|
128
|
+
.map((p) => ({ to: str(p.to), url: /^https:\/\//.test(str(p.url)) ? str(p.url) : '', error: str(p.error) }));
|
|
129
|
+
return { id: str(o.id), status: str(o.status), at: str(o.at), finished: nullable(o.finished), summary: str(o.summary), session: session(o.transcript), draft: str(o.draft), posts, outputs: strings(o.outputs) };
|
|
130
|
+
}
|
|
131
|
+
/** Post a held post to the automation's accounts, or discard it. */
|
|
132
|
+
export async function review(t, id, runId, post) {
|
|
133
|
+
return run(obj(await call(t, 'POST', `/v1/auto/automations/${seg(id)}/runs/${seg(runId)}/review`, { post })));
|
|
134
|
+
}
|
|
135
|
+
/** A weekly schedule's sentence by its day: one sentence each, so a language says the day its own way. */
|
|
136
|
+
const DAYS = {
|
|
137
|
+
mon: phrase('Mondays at {time} · {zone}'),
|
|
138
|
+
tue: phrase('Tuesdays at {time} · {zone}'),
|
|
139
|
+
wed: phrase('Wednesdays at {time} · {zone}'),
|
|
140
|
+
thu: phrase('Thursdays at {time} · {zone}'),
|
|
141
|
+
fri: phrase('Fridays at {time} · {zone}'),
|
|
142
|
+
sat: phrase('Saturdays at {time} · {zone}'),
|
|
143
|
+
sun: phrase('Sundays at {time} · {zone}'),
|
|
144
|
+
};
|
|
145
|
+
/** A once schedule's local date, as a person reads it, and its time. */
|
|
146
|
+
function once(at) {
|
|
147
|
+
const m = at.match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})$/);
|
|
148
|
+
if (!m)
|
|
149
|
+
return null;
|
|
150
|
+
const d = new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3]), Number(m[4]), Number(m[5]));
|
|
151
|
+
return { date: d.toLocaleDateString(undefined, { weekday: 'short', month: 'short', day: 'numeric' }), time: `${m[4]}:${m[5]}` };
|
|
152
|
+
}
|
|
153
|
+
/** A schedule the way a person says it, in the words of the `t` handed (English without one). */
|
|
154
|
+
export function words(s, t = english) {
|
|
155
|
+
const zone = s.tz || 'UTC';
|
|
156
|
+
switch (s.kind) {
|
|
157
|
+
case 'manual':
|
|
158
|
+
return t('When you run it');
|
|
159
|
+
case 'once': {
|
|
160
|
+
if (!s.at)
|
|
161
|
+
return t('Once, now');
|
|
162
|
+
const when = once(s.at);
|
|
163
|
+
return when ? t('Once, {date} at {time} · {zone}', { ...when, zone }) : t('Once, {at} · {zone}', { at: s.at, zone });
|
|
164
|
+
}
|
|
165
|
+
case 'hourly':
|
|
166
|
+
return t('Every hour at :{minute}', { minute: (s.at ?? '00:00').slice(3) || '00' });
|
|
167
|
+
case 'daily':
|
|
168
|
+
return t('Every day at {time} · {zone}', { time: s.at ?? '', zone });
|
|
169
|
+
case 'weekdays':
|
|
170
|
+
return t('Weekdays at {time} · {zone}', { time: s.at ?? '', zone });
|
|
171
|
+
case 'weekly': {
|
|
172
|
+
const day = DAYS[s.day ?? ''];
|
|
173
|
+
return day ? t(day, { time: s.at ?? '', zone }) : t('{day} at {time} · {zone}', { day: s.day ?? '', time: s.at ?? '', zone });
|
|
174
|
+
}
|
|
175
|
+
case 'cron': {
|
|
176
|
+
// The two a person says most, in their words; any other expression as written.
|
|
177
|
+
const minutes = (s.cron ?? '').match(/^\*\/(\d+) \* \* \* \*$/);
|
|
178
|
+
if (minutes)
|
|
179
|
+
return t('Every {n} minutes · {zone}', { n: minutes[1], zone });
|
|
180
|
+
const hours = (s.cron ?? '').match(/^0 \*\/(\d+) \* \* \*$/);
|
|
181
|
+
if (hours)
|
|
182
|
+
return t('Every {n} hours · {zone}', { n: hours[1], zone });
|
|
183
|
+
return t('Cron {cron} · {zone}', { cron: s.cron ?? '', zone });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/** The starters, from GET /v1/auto/templates. */
|
|
188
|
+
export async function starters(t) {
|
|
189
|
+
return list(await call(t, 'GET', '/v1/auto/templates'))
|
|
190
|
+
.map((raw) => {
|
|
191
|
+
const o = obj(raw);
|
|
192
|
+
return { key: str(o.key), name: str(o.name), description: str(o.description), instructions: str(o.instructions), schedule: schedule(o.schedule) };
|
|
193
|
+
})
|
|
194
|
+
.filter((x) => x.key && x.name && x.instructions);
|
|
195
|
+
}
|
|
196
|
+
/** A schedule from a person's own words ("every monday at 9am"), read in `tz`. */
|
|
197
|
+
export async function cron(t, text, tz, init) {
|
|
198
|
+
const o = obj(await call(t, 'POST', '/v1/auto/cron', { text, tz }, init));
|
|
199
|
+
return { schedule: schedule(o.schedule), says: str(o.says), next: nullable(o.next) };
|
|
200
|
+
}
|
|
201
|
+
export const STATES = ['scheduled', 'running', 'succeeded', 'failed', 'cancelled'];
|
|
202
|
+
/** A state the platform did not name is read from the product's own word. */
|
|
203
|
+
function stateOf(state, status) {
|
|
204
|
+
if (STATES.includes(state))
|
|
205
|
+
return state;
|
|
206
|
+
switch (status) {
|
|
207
|
+
case 'queued':
|
|
208
|
+
return 'scheduled';
|
|
209
|
+
case 'running':
|
|
210
|
+
case 'review':
|
|
211
|
+
return 'running';
|
|
212
|
+
case 'succeeded':
|
|
213
|
+
return 'succeeded';
|
|
214
|
+
case 'failed':
|
|
215
|
+
case 'refused':
|
|
216
|
+
return 'failed';
|
|
217
|
+
case 'skipped':
|
|
218
|
+
return 'cancelled';
|
|
219
|
+
}
|
|
220
|
+
return 'scheduled';
|
|
221
|
+
}
|
|
222
|
+
/** One job as the platform answers it, or null for a row with no id. */
|
|
223
|
+
export function job(raw) {
|
|
224
|
+
const o = obj(raw);
|
|
225
|
+
const id = str(o.id);
|
|
226
|
+
if (!id)
|
|
227
|
+
return null;
|
|
228
|
+
const status = str(o.status);
|
|
229
|
+
const progress = typeof o.progress === 'number' && Number.isFinite(o.progress) ? Math.min(1, Math.max(0, o.progress)) : null;
|
|
230
|
+
const cost = typeof o.cost === 'number' && Number.isFinite(o.cost) && o.cost >= 0 ? Math.round(o.cost) : null;
|
|
231
|
+
const sess = str(o.session);
|
|
232
|
+
return {
|
|
233
|
+
id,
|
|
234
|
+
product: sourceOf(o.product),
|
|
235
|
+
kind: str(o.kind),
|
|
236
|
+
title: str(o.title) || id,
|
|
237
|
+
state: stateOf(o.state, status),
|
|
238
|
+
status,
|
|
239
|
+
progress,
|
|
240
|
+
automation: nullable(o.automation),
|
|
241
|
+
session: /^sess_[0-9a-f]{32}$/.test(sess) ? sess : null,
|
|
242
|
+
ref: str(o.ref),
|
|
243
|
+
origin: inApp(o.origin),
|
|
244
|
+
summary: str(o.summary),
|
|
245
|
+
error: str(o.error),
|
|
246
|
+
outputs: strings(o.outputs),
|
|
247
|
+
cost,
|
|
248
|
+
started: str(o.started),
|
|
249
|
+
finished: nullable(o.finished),
|
|
250
|
+
updated: str(o.updated),
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
export async function jobs(t, f = {}) {
|
|
254
|
+
return list(await call(t, 'GET', `/v1/auto/jobs${query({ product: f.product, state: f.state, limit: f.limit })}`))
|
|
255
|
+
.map(job)
|
|
256
|
+
.filter((j) => j !== null);
|
|
257
|
+
}
|
|
258
|
+
export async function one(t, id) {
|
|
259
|
+
const j = job(await call(t, 'GET', `/v1/auto/jobs/${seg(id)}`));
|
|
260
|
+
if (!j)
|
|
261
|
+
throw new Error(phrase('The job came back without an id'));
|
|
262
|
+
return j;
|
|
263
|
+
}
|
|
264
|
+
/** One frame of /v1/auto/events, or null for one this page does not read. */
|
|
265
|
+
export function heard(event, data) {
|
|
266
|
+
let raw;
|
|
267
|
+
try {
|
|
268
|
+
raw = JSON.parse(data);
|
|
269
|
+
}
|
|
270
|
+
catch {
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
if (event === 'job') {
|
|
274
|
+
const j = job(raw);
|
|
275
|
+
return j ? { kind: 'job', job: j } : null;
|
|
276
|
+
}
|
|
277
|
+
if (event === 'automation') {
|
|
278
|
+
const a = read(raw);
|
|
279
|
+
return a ? { kind: 'automation', automation: a } : null;
|
|
280
|
+
}
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Read /v1/auto/events until `signal` ends it or the stream closes, calling `on`
|
|
285
|
+
* for each job and automation it names. A fetch, because EventSource cannot
|
|
286
|
+
* carry the bearer.
|
|
287
|
+
*/
|
|
288
|
+
export async function events(t, on, signal, opened) {
|
|
289
|
+
const res = await fetch(`${t.api}/v1/auto/events`, { headers: headers(t, { Accept: 'text/event-stream' }), cache: 'no-store', signal });
|
|
290
|
+
if (!res.ok)
|
|
291
|
+
throw new Refusal(res.status, (await reason(res)) || `GET /v1/auto/events answered ${res.status}`);
|
|
292
|
+
if (!res.body)
|
|
293
|
+
return;
|
|
294
|
+
opened?.();
|
|
295
|
+
await stream(res.body, (f) => {
|
|
296
|
+
const h = heard(f.event, f.data);
|
|
297
|
+
if (h)
|
|
298
|
+
on(h);
|
|
299
|
+
}, signal);
|
|
300
|
+
}
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { type Target } from './call.ts';
|
|
2
|
+
/** `$1,234.56` from whole cents; whole dollars drop the cents. */
|
|
3
|
+
export declare function money(cents: number, currency?: string): string;
|
|
4
|
+
/** Whole cents from what a person typed as dollars — `25`, `$25.50` — or null. */
|
|
5
|
+
export declare function cents(typed: string): number | null;
|
|
6
|
+
export interface Plan {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
/** personal, team, enterprise, … */
|
|
11
|
+
category: string;
|
|
12
|
+
/** Per month, billed monthly. 0 is free. */
|
|
13
|
+
monthly: number;
|
|
14
|
+
/** Per month, billed yearly; 0 when the plan has no yearly price. */
|
|
15
|
+
yearly: number;
|
|
16
|
+
currency: string;
|
|
17
|
+
perSeat: boolean;
|
|
18
|
+
/** Priced by talking to sales; nothing to buy here. */
|
|
19
|
+
sales: boolean;
|
|
20
|
+
popular: boolean;
|
|
21
|
+
features: string[];
|
|
22
|
+
}
|
|
23
|
+
export declare function plan(raw: unknown): Plan;
|
|
24
|
+
export declare function plans(t: Target): Promise<Plan[]>;
|
|
25
|
+
export interface Subscription {
|
|
26
|
+
id: string;
|
|
27
|
+
plan: string;
|
|
28
|
+
name: string;
|
|
29
|
+
/** Per period, per seat. */
|
|
30
|
+
price: number;
|
|
31
|
+
interval: string;
|
|
32
|
+
currency: string;
|
|
33
|
+
seats: number;
|
|
34
|
+
/** trialing, active, past_due, canceled, unpaid. */
|
|
35
|
+
status: string;
|
|
36
|
+
/** RFC 3339: paid through, and renews or ends then. */
|
|
37
|
+
ends: string;
|
|
38
|
+
/** Ends at `ends` rather than renewing. */
|
|
39
|
+
ending: boolean;
|
|
40
|
+
/** The saved card a renewal charges, or ''. */
|
|
41
|
+
method: string;
|
|
42
|
+
}
|
|
43
|
+
export declare function subscription(raw: unknown): Subscription;
|
|
44
|
+
/** The plan the org is on, or null for none (the free tier). */
|
|
45
|
+
export declare function current(list: Subscription[]): Subscription | null;
|
|
46
|
+
export declare function subscriptions(t: Target): Promise<Subscription[]>;
|
|
47
|
+
export interface Purchase {
|
|
48
|
+
plan: string;
|
|
49
|
+
/** month | year */
|
|
50
|
+
interval: 'month' | 'year';
|
|
51
|
+
/** The saved card that pays. */
|
|
52
|
+
method: string;
|
|
53
|
+
}
|
|
54
|
+
/** Buy a plan. No amount is sent: the catalog prices it, and the platform charges that. */
|
|
55
|
+
export declare function subscribe(t: Target, p: Purchase): Promise<{
|
|
56
|
+
subscription: string;
|
|
57
|
+
charged: number;
|
|
58
|
+
}>;
|
|
59
|
+
/** End a plan when its paid period does, not before. */
|
|
60
|
+
export declare function cancel(t: Target, id: string): Promise<Subscription>;
|
|
61
|
+
export declare function reactivate(t: Target, id: string): Promise<Subscription>;
|
|
62
|
+
export interface Address {
|
|
63
|
+
name?: string;
|
|
64
|
+
line1?: string;
|
|
65
|
+
line2?: string;
|
|
66
|
+
city?: string;
|
|
67
|
+
state?: string;
|
|
68
|
+
postalCode?: string;
|
|
69
|
+
country?: string;
|
|
70
|
+
}
|
|
71
|
+
export interface Method {
|
|
72
|
+
id: string;
|
|
73
|
+
type: string;
|
|
74
|
+
brand: string;
|
|
75
|
+
last4: string;
|
|
76
|
+
/** `MM/YY`, or ''. */
|
|
77
|
+
expires: string;
|
|
78
|
+
default: boolean;
|
|
79
|
+
/** What the platform calls it when it is not a card. */
|
|
80
|
+
name: string;
|
|
81
|
+
billingAddress?: Address;
|
|
82
|
+
}
|
|
83
|
+
export declare function method(raw: unknown): Method;
|
|
84
|
+
/** Formats a billing address as a readable line: `Acme Inc · 123 Main St · San Francisco CA 94105 · US`. */
|
|
85
|
+
export declare function formatAddress(a?: Address): string;
|
|
86
|
+
/** How a saved method reads in a row: `Visa •••• 4242`. */
|
|
87
|
+
export declare function label(m: Method): string;
|
|
88
|
+
export declare function methods(t: Target): Promise<Method[]>;
|
|
89
|
+
/** The card a charge uses: the default, or the newest. */
|
|
90
|
+
export declare function chosen(list: Method[]): Method | null;
|
|
91
|
+
/** Save a card from the single-use token the processor's form returned, optionally with billing info. */
|
|
92
|
+
export declare function save(t: Target, token: string, billingAddress?: Address): Promise<Method>;
|
|
93
|
+
export declare function updateMethod(t: Target, id: string, what: {
|
|
94
|
+
billingAddress?: Address;
|
|
95
|
+
}): Promise<Method>;
|
|
96
|
+
export declare function detach(t: Target, id: string): Promise<void>;
|
|
97
|
+
export declare function makeDefault(t: Target, id: string): Promise<Method>;
|
|
98
|
+
export interface Processor {
|
|
99
|
+
/** `square`, or '' where none is configured. */
|
|
100
|
+
provider: string;
|
|
101
|
+
application: string;
|
|
102
|
+
location: string;
|
|
103
|
+
/** `production` charges real cards; anything else is the sandbox. */
|
|
104
|
+
environment: string;
|
|
105
|
+
live: boolean;
|
|
106
|
+
}
|
|
107
|
+
export declare function processor(t: Target): Promise<Processor>;
|
|
108
|
+
export interface Line {
|
|
109
|
+
description: string;
|
|
110
|
+
amount: number;
|
|
111
|
+
}
|
|
112
|
+
export interface Invoice {
|
|
113
|
+
id: string;
|
|
114
|
+
/** `INV-0042`, or '' for a draft. */
|
|
115
|
+
number: string;
|
|
116
|
+
date: string;
|
|
117
|
+
status: string;
|
|
118
|
+
currency: string;
|
|
119
|
+
subtotal: number;
|
|
120
|
+
tax: number;
|
|
121
|
+
discount: number;
|
|
122
|
+
credit: number;
|
|
123
|
+
paid: number;
|
|
124
|
+
due: number;
|
|
125
|
+
/** What the invoice comes to before credit is applied. */
|
|
126
|
+
total: number;
|
|
127
|
+
start: string;
|
|
128
|
+
end: string;
|
|
129
|
+
lines: Line[];
|
|
130
|
+
}
|
|
131
|
+
export declare function invoice(raw: unknown): Invoice;
|
|
132
|
+
export declare function invoices(t: Target): Promise<Invoice[]>;
|
|
133
|
+
/** The invoice as a PDF, read with the caller's bearer. */
|
|
134
|
+
export declare function pdf(t: Target, id: string): Promise<Blob>;
|
|
135
|
+
/** What the org can still spend from its prepaid balance, in cents. */
|
|
136
|
+
export declare function balance(t: Target): Promise<number>;
|
|
137
|
+
/**
|
|
138
|
+
* What can pay for another maker's models, whole cents: cash and the credit line, never
|
|
139
|
+
* granted credit (`GET /v1/billing/balance` `prepaid`). Null where the answer carries no
|
|
140
|
+
* such figure, so a caller does not assume it.
|
|
141
|
+
*/
|
|
142
|
+
export declare function prepaid(t: Target): Promise<number | null>;
|
|
143
|
+
/** Granted credit the org can spend, in US cents. */
|
|
144
|
+
export declare function credit(t: Target): Promise<number>;
|
|
145
|
+
/** One grant of credit, spent, lapsed and voided included: the ledger, not the spendable figure. */
|
|
146
|
+
export interface Grant {
|
|
147
|
+
id: string;
|
|
148
|
+
name: string;
|
|
149
|
+
amount: number;
|
|
150
|
+
remaining: number;
|
|
151
|
+
currency: string;
|
|
152
|
+
/** RFC 3339, or '' for one that does not lapse. */
|
|
153
|
+
expires: string;
|
|
154
|
+
active: boolean;
|
|
155
|
+
}
|
|
156
|
+
export declare function grants(t: Target): Promise<Grant[]>;
|
|
157
|
+
/**
|
|
158
|
+
* The rung an organization is served as (`max-20x`, '' with none), the tier
|
|
159
|
+
* class it is served under (`pro`), and the display name of the plan its
|
|
160
|
+
* subscription is on (`planName`, `Unlimited`; '' with none).
|
|
161
|
+
*/
|
|
162
|
+
export interface Tier {
|
|
163
|
+
plan: string;
|
|
164
|
+
tier: string;
|
|
165
|
+
name: string;
|
|
166
|
+
}
|
|
167
|
+
export declare function tier(t: Target): Promise<Tier>;
|
|
168
|
+
/** Auto-reload: top the balance up by `amount` whenever it falls below `threshold`, charging the card on file. */
|
|
169
|
+
export interface Recharge {
|
|
170
|
+
enabled: boolean;
|
|
171
|
+
threshold: number;
|
|
172
|
+
amount: number;
|
|
173
|
+
currency: string;
|
|
174
|
+
/** RFC 3339 of the last reload, or ''. */
|
|
175
|
+
last: string;
|
|
176
|
+
}
|
|
177
|
+
/** The rule as stored; one never set reads as off. */
|
|
178
|
+
export declare function recharge(t: Target): Promise<Recharge>;
|
|
179
|
+
/** Arm or disarm the rule. Turning it on needs a card on file, and the platform says so when there is none. */
|
|
180
|
+
export declare function arm(t: Target, rule: {
|
|
181
|
+
enabled: boolean;
|
|
182
|
+
threshold: number;
|
|
183
|
+
amount: number;
|
|
184
|
+
}): Promise<Recharge>;
|
|
185
|
+
/** Charge a saved card and add the amount to the balance; answers the balance after. */
|
|
186
|
+
export declare function topup(t: Target, amount: number, card: string): Promise<number>;
|
|
187
|
+
export interface Window {
|
|
188
|
+
/** hour, day, week or month. */
|
|
189
|
+
span: string;
|
|
190
|
+
/** Requests the plan includes in this span; 0 is no bound. */
|
|
191
|
+
limit: number;
|
|
192
|
+
used: number;
|
|
193
|
+
/** RFC 3339. */
|
|
194
|
+
resets: string;
|
|
195
|
+
}
|
|
196
|
+
export interface Month {
|
|
197
|
+
plan: string;
|
|
198
|
+
/** `2026-09`. */
|
|
199
|
+
period: string;
|
|
200
|
+
/** Spend the plan includes this month, and how much of it is used. */
|
|
201
|
+
included: number;
|
|
202
|
+
used: number;
|
|
203
|
+
overage: number;
|
|
204
|
+
windows: Window[];
|
|
205
|
+
}
|
|
206
|
+
export declare function month(t: Target): Promise<Month>;
|
|
207
|
+
export interface Spend {
|
|
208
|
+
/** Whether the ledger answered; false means the zeros are not measurements. */
|
|
209
|
+
known: boolean;
|
|
210
|
+
/** Month to date. */
|
|
211
|
+
total: number;
|
|
212
|
+
categories: {
|
|
213
|
+
name: string;
|
|
214
|
+
cents: number;
|
|
215
|
+
}[];
|
|
216
|
+
}
|
|
217
|
+
export declare function spend(t: Target): Promise<Spend>;
|
|
218
|
+
/** The pool every free user shares, as its vendor accounts last said. */
|
|
219
|
+
export interface Pool {
|
|
220
|
+
/** available, busy or exhausted. */
|
|
221
|
+
state: string;
|
|
222
|
+
/** RFC 3339: when the pool refills, where the platform says; ''. */
|
|
223
|
+
resets: string;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* What the caller has left of the Free plan: limited usage, from a pool shared
|
|
227
|
+
* by all free users. `pooled` is false for a paid plan, whose usage is its spend.
|
|
228
|
+
*/
|
|
229
|
+
export interface Allowance {
|
|
230
|
+
plan: string;
|
|
231
|
+
/** Requests allowed in `window`; 0 is no bound. */
|
|
232
|
+
limit: number;
|
|
233
|
+
used: number;
|
|
234
|
+
spent: boolean;
|
|
235
|
+
/** hour or day. */
|
|
236
|
+
window: string;
|
|
237
|
+
/** RFC 3339. */
|
|
238
|
+
resets: string;
|
|
239
|
+
pooled: boolean;
|
|
240
|
+
/** Absent when the platform could not read it. */
|
|
241
|
+
pool: Pool | null;
|
|
242
|
+
}
|
|
243
|
+
export declare function allowance(t: Target): Promise<Allowance>;
|
|
244
|
+
export interface Cap {
|
|
245
|
+
id: string;
|
|
246
|
+
title: string;
|
|
247
|
+
/** The ceiling for the calendar month, in cents; 0 bounds no spend. */
|
|
248
|
+
threshold: number;
|
|
249
|
+
/** Refuses spend past the ceiling, rather than only warning. */
|
|
250
|
+
enforce: boolean;
|
|
251
|
+
project: string;
|
|
252
|
+
service: string;
|
|
253
|
+
/** Spent this month against it, or null when the platform could not read it. */
|
|
254
|
+
spent: number | null;
|
|
255
|
+
resets: string;
|
|
256
|
+
}
|
|
257
|
+
export declare function cap(raw: unknown): Cap;
|
|
258
|
+
export declare function caps(t: Target): Promise<Cap[]>;
|
|
259
|
+
/** The org-wide monthly cap: no project, no service, a ceiling. */
|
|
260
|
+
export declare function monthly(list: Cap[]): Cap | null;
|
|
261
|
+
/** Set the org's monthly cap: change the one there is, or open one that refuses spend past it. */
|
|
262
|
+
export declare function limit(t: Target, list: Cap[], threshold: number): Promise<Cap>;
|
|
263
|
+
export declare function lift(t: Target, id: string): Promise<void>;
|