@tangle-network/hub-sdk 0.2.2 → 0.3.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/README.md +40 -1
- package/dist/index.d.ts +489 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +483 -7
- package/dist/index.js.map +1 -1
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -125,11 +125,50 @@ const hub = HubClient.fromEnv({
|
|
|
125
125
|
});
|
|
126
126
|
```
|
|
127
127
|
|
|
128
|
+
## Workflows
|
|
129
|
+
|
|
130
|
+
`hub.workflows` covers the `/v1/workflows` surface — the same resource the
|
|
131
|
+
platform web UI and the `tangle workflows` CLI drive. It authenticates with the
|
|
132
|
+
`sk-tan-*` API key (or a session), **not** a hub capability token. Alongside
|
|
133
|
+
CRUD (`list`/`get`/`create`/`update`/`delete`), `setEnabled`, `validate`, and
|
|
134
|
+
`schema`, it can trigger and observe runs:
|
|
135
|
+
|
|
136
|
+
```ts
|
|
137
|
+
const hub = HubClient.fromEnv();
|
|
138
|
+
|
|
139
|
+
// Trigger a run with the trigger fields the workflow reads, then wait for it.
|
|
140
|
+
const { runId } = await hub.workflows.run("wf_123", {
|
|
141
|
+
"pull_request.number": "123",
|
|
142
|
+
});
|
|
143
|
+
const run = await hub.workflows.waitForRun("wf_123", runId, {
|
|
144
|
+
timeoutMs: 300_000,
|
|
145
|
+
});
|
|
146
|
+
console.log(run.status, run.actionResults);
|
|
147
|
+
|
|
148
|
+
// Or tail live progress as it executes.
|
|
149
|
+
for await (const event of hub.workflows.watchRun("wf_123", runId)) {
|
|
150
|
+
if (event.type === "token") process.stdout.write(event.delta);
|
|
151
|
+
if (event.type === "run.done") console.log("\n", event.status);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// One page of run history + a single run's full detail.
|
|
155
|
+
const { runs, nextCursor } = await hub.workflows.listRuns("wf_123");
|
|
156
|
+
const detail = await hub.workflows.getRun("wf_123", runs[0].id);
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
`run` throws `HubSdkError` with `MISSING_RUN_INPUTS` (the workflow reads trigger
|
|
160
|
+
fields none were supplied for — `details.missing` names them) or
|
|
161
|
+
`WORKFLOW_DISABLED` (enable it first). `waitForRun` throws
|
|
162
|
+
`WORKFLOW_RUN_TIMEOUT` if the run has not finished within `timeoutMs`. Live
|
|
163
|
+
`watchRun` ticks require the worker executing the run to share the API process;
|
|
164
|
+
across instances only `snapshot` + `run.done` arrive, and the persisted record
|
|
165
|
+
read via `getRun` stays the source of truth.
|
|
166
|
+
|
|
128
167
|
## Exports
|
|
129
168
|
|
|
130
169
|
- `HubClient`, `HubClient.fromEnv(options?)`
|
|
131
170
|
- `HubConnectionsClient`, `HubPermissionsClient`, `HubTokensClient`,
|
|
132
|
-
`HubToolsClient`, `HubApprovalsClient`, `HubAuditClient`
|
|
171
|
+
`HubToolsClient`, `HubApprovalsClient`, `HubAuditClient`, `HubWorkflowsClient`
|
|
133
172
|
- `HubSdkError` — typed `code: HubErrorCode`, redacted `details`, optional
|
|
134
173
|
HTTP `status`
|
|
135
174
|
- `HUB_URL_ENV_VAR`, `HUB_API_KEY_ENV_VAR`, `HUB_CAPABILITY_TOKEN_ENV_VAR` —
|
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ interface HubErrorBody {
|
|
|
14
14
|
message: string;
|
|
15
15
|
details?: unknown;
|
|
16
16
|
}
|
|
17
|
-
type HubErrorCode = "HUB_UNAUTHENTICATED" | "HUB_FORBIDDEN" | "HUB_INVALID_INPUT" | "HUB_PROVIDER_MISSING" | "HUB_CONNECTION_MISSING" | "HUB_CONNECTION_REVOKED" | "HUB_TOKEN_EXPIRED" | "HUB_TOKEN_REPLAYED" | "HUB_TOKEN_REVOKED" | "HUB_TOKEN_ACTION_MISMATCH" | "HUB_POLICY_DENIED" | "HUB_APPROVAL_REQUIRED" | "HUB_EXECUTOR_FAILURE" | "HUB_PROVIDER_FAILURE" | "HUB_CONFIG_MISSING" | "HUB_CONFIG_INVALID" | "HUB_NOT_FOUND" | "HUB_NOT_IMPLEMENTED"
|
|
17
|
+
type HubErrorCode = "HUB_UNAUTHENTICATED" | "HUB_FORBIDDEN" | "HUB_INVALID_INPUT" | "HUB_INVALID_STATE" | "HUB_PROVIDER_MISSING" | "HUB_CONNECTION_MISSING" | "HUB_CONNECTION_REVOKED" | "HUB_TOKEN_EXPIRED" | "HUB_TOKEN_REPLAYED" | "HUB_TOKEN_REVOKED" | "HUB_TOKEN_ACTION_MISMATCH" | "HUB_POLICY_DENIED" | "HUB_APPROVAL_REQUIRED" | "HUB_EXECUTOR_FAILURE" | "HUB_PROVIDER_FAILURE" | "HUB_CONFIG_MISSING" | "HUB_CONFIG_INVALID" | "HUB_NOT_FOUND" | "HUB_NOT_IMPLEMENTED" | "HUB_CONFLICT" | "VALIDATION_ERROR" | "WORKFLOW_INVALID" | "NOT_FOUND" | "UNAUTHORIZED" | "CONFLICT" | "MISSING_RUN_INPUTS" | "WORKFLOW_DISABLED" | "PAYLOAD_TOO_LARGE" | "WORKFLOW_RUN_TIMEOUT" | `HUB_HTTP_${number}`;
|
|
18
18
|
interface HubStatusResponse {
|
|
19
19
|
contract: unknown;
|
|
20
20
|
principal: HubPrincipal;
|
|
@@ -46,6 +46,39 @@ interface HubConnection {
|
|
|
46
46
|
interface HubConnectionsResponse {
|
|
47
47
|
connections: HubConnection[];
|
|
48
48
|
}
|
|
49
|
+
/** A connector's auth model. */
|
|
50
|
+
type HubProviderAuthKind = "oauth2" | "api_key" | "none" | "custom";
|
|
51
|
+
interface HubProvider {
|
|
52
|
+
providerId: string;
|
|
53
|
+
title: string;
|
|
54
|
+
/** The connector's auth model. */
|
|
55
|
+
authKind: HubProviderAuthKind;
|
|
56
|
+
/** For api-key connectors, the manifest's free-text hint shown when
|
|
57
|
+
* collecting the key (e.g. "Paste your Airtable personal access token");
|
|
58
|
+
* null for OAuth/native providers that don't collect a key inline. */
|
|
59
|
+
authHint: string | null;
|
|
60
|
+
category: string;
|
|
61
|
+
scopes: string[];
|
|
62
|
+
/** Actions + trigger events combined (legacy census; prefer the split
|
|
63
|
+
* counts below when present). */
|
|
64
|
+
capabilityCount: number;
|
|
65
|
+
/** Actions callable via `integration.invoke`. Absent on older servers, and
|
|
66
|
+
* for native GitHub when the executor catalog is unavailable. */
|
|
67
|
+
actionCount?: number;
|
|
68
|
+
/** Trigger events the connector delivers (not invokable). Absent on older
|
|
69
|
+
* servers. */
|
|
70
|
+
triggerCount?: number;
|
|
71
|
+
/** True for the native GitHub path; false for substrate-bundled connectors. */
|
|
72
|
+
native: boolean;
|
|
73
|
+
/** True when the provider's OAuth app credentials are wired, i.e. a connect
|
|
74
|
+
* flow can actually start. UIs offer Connect only for configured providers. */
|
|
75
|
+
configured: boolean;
|
|
76
|
+
}
|
|
77
|
+
interface HubProvidersResponse {
|
|
78
|
+
providers: HubProvider[];
|
|
79
|
+
/** Count of substrate-bundled connector manifests behind this catalog. */
|
|
80
|
+
substrateBundled: number;
|
|
81
|
+
}
|
|
49
82
|
interface HubOAuthStartRequest {
|
|
50
83
|
provider: string;
|
|
51
84
|
returnUrl?: string;
|
|
@@ -72,12 +105,51 @@ interface HubOAuthStartResponse {
|
|
|
72
105
|
scopes: string[];
|
|
73
106
|
cli: boolean;
|
|
74
107
|
}
|
|
108
|
+
interface HubWhatsappEmbeddedSignupStartRequest {
|
|
109
|
+
returnUrl?: string;
|
|
110
|
+
}
|
|
111
|
+
interface HubWhatsappEmbeddedSignupStartResponse {
|
|
112
|
+
provider: "whatsapp-business";
|
|
113
|
+
appId: string;
|
|
114
|
+
configId: string;
|
|
115
|
+
sdkVersion: string;
|
|
116
|
+
state: string;
|
|
117
|
+
expiresAt: string;
|
|
118
|
+
scopes: string[];
|
|
119
|
+
}
|
|
120
|
+
interface HubWhatsappEmbeddedSignupCompleteRequest {
|
|
121
|
+
code: string;
|
|
122
|
+
state: string;
|
|
123
|
+
wabaId: string;
|
|
124
|
+
phoneNumberId: string;
|
|
125
|
+
businessId?: string;
|
|
126
|
+
flowEvent?: string;
|
|
127
|
+
}
|
|
128
|
+
interface HubWhatsappEmbeddedSignupCompleteResponse {
|
|
129
|
+
connectionId: string;
|
|
130
|
+
provider: "whatsapp-business";
|
|
131
|
+
reconnected: boolean;
|
|
132
|
+
connection: HubConnection | null;
|
|
133
|
+
}
|
|
75
134
|
interface HubOAuthCallbackResponse {
|
|
76
135
|
connectionId: string;
|
|
77
136
|
provider: string;
|
|
78
137
|
cli: boolean;
|
|
79
138
|
reconnected: boolean;
|
|
80
139
|
}
|
|
140
|
+
/** Connect a non-OAuth (api-key) connector by submitting the user's key. The
|
|
141
|
+
* server validates the key with a live probe before persisting; `provider` is
|
|
142
|
+
* carried in the path, `apiKey` in the body. */
|
|
143
|
+
interface HubApiKeyConnectRequest {
|
|
144
|
+
provider: string;
|
|
145
|
+
apiKey: string;
|
|
146
|
+
}
|
|
147
|
+
/** Result of an api-key connect: the created (or reconnected) connection.
|
|
148
|
+
* Synchronous — there is no redirect leg, unlike the OAuth flow. */
|
|
149
|
+
interface HubApiKeyConnectResponse {
|
|
150
|
+
connection: HubConnection;
|
|
151
|
+
reconnected: boolean;
|
|
152
|
+
}
|
|
81
153
|
interface HubConnectionDeleteRequest {
|
|
82
154
|
connectionId: string;
|
|
83
155
|
}
|
|
@@ -110,6 +182,10 @@ interface HubToolSource {
|
|
|
110
182
|
health: "healthy" | "unhealthy" | "rate_limited" | "unknown";
|
|
111
183
|
configured: boolean;
|
|
112
184
|
}
|
|
185
|
+
/** Per-tool catalog risk class. The first three mirror the platform's
|
|
186
|
+
* `HubActionRisk`; `unknown` is surfaced honestly for tools the catalog can't
|
|
187
|
+
* classify (substrate connectors). */
|
|
188
|
+
type HubToolRisk = "read" | "write" | "destructive" | "unknown";
|
|
113
189
|
interface HubTool {
|
|
114
190
|
path: string;
|
|
115
191
|
providerId?: string;
|
|
@@ -121,6 +197,7 @@ interface HubTool {
|
|
|
121
197
|
connectionStatus?: "connected" | "missing" | "unknown";
|
|
122
198
|
requiredConnectionProviderId?: string;
|
|
123
199
|
policyState?: "allow" | "ask" | "deny" | "unknown";
|
|
200
|
+
risk?: HubToolRisk;
|
|
124
201
|
}
|
|
125
202
|
interface HubToolSourcesResponse {
|
|
126
203
|
sources: HubToolSource[];
|
|
@@ -184,6 +261,16 @@ interface HubPolicyUpdateRequest {
|
|
|
184
261
|
interface HubPolicyListRequest {
|
|
185
262
|
connectionId: string;
|
|
186
263
|
}
|
|
264
|
+
interface HubPolicyDeleteRequest {
|
|
265
|
+
connectionId: string;
|
|
266
|
+
actionPath: string;
|
|
267
|
+
}
|
|
268
|
+
interface HubPolicyDeleteResponse {
|
|
269
|
+
connectionId: string;
|
|
270
|
+
actionPath: string;
|
|
271
|
+
/** Whether a stored override existed and was removed (false = already default). */
|
|
272
|
+
deleted: boolean;
|
|
273
|
+
}
|
|
187
274
|
interface HubPolicy {
|
|
188
275
|
id: string;
|
|
189
276
|
connectionId: string;
|
|
@@ -199,6 +286,20 @@ interface HubPolicyResponse {
|
|
|
199
286
|
interface HubPolicyListResponse {
|
|
200
287
|
policies: HubPolicy[];
|
|
201
288
|
}
|
|
289
|
+
interface HubAllowWritesResponse {
|
|
290
|
+
connectionId: string;
|
|
291
|
+
providerId: string;
|
|
292
|
+
/** Write actions the connection's provider exposes. */
|
|
293
|
+
writeActions: number;
|
|
294
|
+
/** Rows newly created (excludes actions that already had a policy). */
|
|
295
|
+
granted: number;
|
|
296
|
+
actionPaths: string[];
|
|
297
|
+
}
|
|
298
|
+
interface HubRevertWritesResponse {
|
|
299
|
+
connectionId: string;
|
|
300
|
+
/** `allow_writes` rows deleted. */
|
|
301
|
+
reverted: number;
|
|
302
|
+
}
|
|
202
303
|
type HubApprovalStatus = "pending" | "approved" | "denied" | "expired" | "consumed";
|
|
203
304
|
interface HubApproval {
|
|
204
305
|
id: string;
|
|
@@ -298,6 +399,253 @@ interface HubGithubAppIsRepoInstalledResponse {
|
|
|
298
399
|
installed: boolean;
|
|
299
400
|
installationId: number | null;
|
|
300
401
|
}
|
|
402
|
+
interface HubWorkflowAction {
|
|
403
|
+
kind: string;
|
|
404
|
+
config: Record<string, unknown>;
|
|
405
|
+
}
|
|
406
|
+
/** Inbound-event matcher for a `provider_event` trigger. */
|
|
407
|
+
interface HubWorkflowEventFilter {
|
|
408
|
+
event: string;
|
|
409
|
+
action?: string;
|
|
410
|
+
repo?: string;
|
|
411
|
+
}
|
|
412
|
+
interface HubWorkflowTrigger {
|
|
413
|
+
id: string;
|
|
414
|
+
kind: "provider_event" | "schedule";
|
|
415
|
+
enabled: boolean;
|
|
416
|
+
provider: string | null;
|
|
417
|
+
connectionId: string | null;
|
|
418
|
+
eventFilter: HubWorkflowEventFilter | null;
|
|
419
|
+
cron: string | null;
|
|
420
|
+
timezone: string | null;
|
|
421
|
+
nextFireAt: string | null;
|
|
422
|
+
lastFiredAt: string | null;
|
|
423
|
+
}
|
|
424
|
+
interface HubWorkflowValidationError {
|
|
425
|
+
path: string;
|
|
426
|
+
message: string;
|
|
427
|
+
}
|
|
428
|
+
type HubWorkflowRunStatus = "queued" | "running" | "waiting" | "succeeded" | "failed" | "cancelled";
|
|
429
|
+
/** One agent iteration of an `agent.run`, as the single-run detail carries it
|
|
430
|
+
* (JSON-clean ISO timestamps) — including the round's own output `text`. */
|
|
431
|
+
interface HubAgentIterationSpan {
|
|
432
|
+
index: number;
|
|
433
|
+
name: string;
|
|
434
|
+
status: "succeeded" | "failed";
|
|
435
|
+
startedAt: string;
|
|
436
|
+
completedAt: string;
|
|
437
|
+
model?: string;
|
|
438
|
+
inputTokens?: number;
|
|
439
|
+
outputTokens?: number;
|
|
440
|
+
costUsd?: number;
|
|
441
|
+
error?: string;
|
|
442
|
+
text?: string;
|
|
443
|
+
}
|
|
444
|
+
/** An `agent.run`'s execution detail (single-run detail endpoint): per-iteration
|
|
445
|
+
* spans plus aggregate usage, present on success AND failure. `partialText` is
|
|
446
|
+
* failure-only — on success the final text is the action's `output`. */
|
|
447
|
+
interface HubAgentRunDetail {
|
|
448
|
+
model?: string;
|
|
449
|
+
inputTokens?: number;
|
|
450
|
+
outputTokens?: number;
|
|
451
|
+
costUsd?: number;
|
|
452
|
+
partialText?: string;
|
|
453
|
+
iterations?: HubAgentIterationSpan[];
|
|
454
|
+
}
|
|
455
|
+
/** Per-action result inside a run. `output` on success, `error` on failure. */
|
|
456
|
+
interface HubWorkflowActionResult {
|
|
457
|
+
index: number;
|
|
458
|
+
kind: string;
|
|
459
|
+
/** `running` is the provisional in-flight status the run-history list and
|
|
460
|
+
* single-run detail endpoints return for an action of a run that is still
|
|
461
|
+
* executing (reconciled to `failed` only once the run itself reaches a
|
|
462
|
+
* terminal state); a consumer polling either endpoint can observe it.
|
|
463
|
+
* `skipped` is an action whose `if` guard resolved false, so it never ran —
|
|
464
|
+
* terminal and distinct from `failed` (it has no `output`, `error`, or cost). */
|
|
465
|
+
status: "succeeded" | "failed" | "running" | "skipped";
|
|
466
|
+
/**
|
|
467
|
+
* Action output on success. Present on the single-run detail endpoint;
|
|
468
|
+
* intentionally omitted from the paginated run-history list response (an
|
|
469
|
+
* output can be an arbitrarily large response body, and the list would
|
|
470
|
+
* otherwise carry unbounded payloads), so it is absent there.
|
|
471
|
+
*/
|
|
472
|
+
output?: unknown;
|
|
473
|
+
error?: string;
|
|
474
|
+
costUsd?: number;
|
|
475
|
+
/** `agent.run` only (single-run detail): the agent's execution detail —
|
|
476
|
+
* per-iteration spans (each with text), aggregate usage, partial text. */
|
|
477
|
+
agentRun?: HubAgentRunDetail;
|
|
478
|
+
}
|
|
479
|
+
/** A single workflow run, as returned by the run-history endpoint. */
|
|
480
|
+
interface HubWorkflowRun {
|
|
481
|
+
id: string;
|
|
482
|
+
status: HubWorkflowRunStatus;
|
|
483
|
+
actionResults: HubWorkflowActionResult[];
|
|
484
|
+
/** Terminal run error (credit-exhausted, connection revoked, …); null on a clean run. */
|
|
485
|
+
error: string | null;
|
|
486
|
+
attempts: number;
|
|
487
|
+
/** Single-run detail only: the definition YAML captured at enqueue (null for
|
|
488
|
+
* runs from before snapshots, or a workflow with no stored definition). */
|
|
489
|
+
definitionSnapshot?: string | null;
|
|
490
|
+
/** Single-run detail only: the trigger payload/context the run executed
|
|
491
|
+
* against (capped server-side). Absent on the paginated list. */
|
|
492
|
+
triggerContext?: unknown;
|
|
493
|
+
createdAt: string;
|
|
494
|
+
startedAt: string | null;
|
|
495
|
+
completedAt: string | null;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* A single run as returned by the single-run detail endpoint
|
|
499
|
+
* (`GET /v1/workflows/:id/runs/:runId`) and carried in the `snapshot` stream
|
|
500
|
+
* event. Unlike a run-history list item it always carries `workflowId` and the
|
|
501
|
+
* per-action `output` / `agentRun` detail (all size-capped server-side).
|
|
502
|
+
*/
|
|
503
|
+
interface HubWorkflowRunDetail extends HubWorkflowRun {
|
|
504
|
+
workflowId: string;
|
|
505
|
+
/** The detail endpoint always returns these (unlike the run-history list,
|
|
506
|
+
* where they're absent) — narrowed to required here so a consumer of
|
|
507
|
+
* `getRun` / a `snapshot` event reads them without re-checking presence. */
|
|
508
|
+
triggerContext: unknown;
|
|
509
|
+
definitionSnapshot: string | null;
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* The trigger fields a manual "Run now" supplies, as a flat `{ path: value }`
|
|
513
|
+
* map (e.g. `{ "pull_request.number": "123" }`). Keys are the `path`s of the
|
|
514
|
+
* workflow's {@link HubManualRunInput}s; the server nests them into a trigger
|
|
515
|
+
* context so the run resolves exactly as a real trigger delivery would.
|
|
516
|
+
*/
|
|
517
|
+
type HubWorkflowRunInputs = Record<string, string>;
|
|
518
|
+
/** Response of a manual run enqueue (`POST /v1/workflows/:id/run`). */
|
|
519
|
+
interface HubWorkflowRunEnqueued {
|
|
520
|
+
runId: string;
|
|
521
|
+
}
|
|
522
|
+
/**
|
|
523
|
+
* Result of cancelling a run (`POST /v1/workflows/:id/runs/:runId/cancel`).
|
|
524
|
+
*
|
|
525
|
+
* `cancelled` — a `queued` run was stopped synchronously in the store; it is
|
|
526
|
+
* already terminal. `cancelling` — a `running` run was signalled to abort; it
|
|
527
|
+
* settles `cancelled` a moment later as its in-flight action tears down. Observe
|
|
528
|
+
* the true terminal state via {@link HubWorkflowRunDetail} (`getRun`) or the run
|
|
529
|
+
* event stream (`watchRun`). A finished run throws `HubSdkError` with code
|
|
530
|
+
* `RUN_NOT_CANCELLABLE`; an unknown/foreign run throws `NOT_FOUND`.
|
|
531
|
+
*/
|
|
532
|
+
interface HubWorkflowRunCancelResult {
|
|
533
|
+
runId: string;
|
|
534
|
+
status: "cancelled" | "cancelling";
|
|
535
|
+
/** Only on a `cancelling` result: whether the abort reached a worker running
|
|
536
|
+
* this run on the API instance that served the request. `false` → the run
|
|
537
|
+
* just finished, or executes on another instance and will stop on its own;
|
|
538
|
+
* watch/poll the run to confirm it settled `cancelled`. */
|
|
539
|
+
signalled?: boolean;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* A live event from a run's SSE stream (`GET /v1/workflows/:id/runs/:runId/events`),
|
|
543
|
+
* as surfaced by {@link HubWorkflowsClient.watchRun}. `snapshot` is the current
|
|
544
|
+
* persisted run detail sent first; the lifecycle/token events mirror the run as
|
|
545
|
+
* it executes; `ping` is a keepalive; `run.done` is terminal and closes the
|
|
546
|
+
* stream. Unknown server event types are dropped rather than surfaced, so new
|
|
547
|
+
* event kinds don't break older clients.
|
|
548
|
+
*/
|
|
549
|
+
type HubWorkflowRunStreamEvent = {
|
|
550
|
+
type: "snapshot";
|
|
551
|
+
run: HubWorkflowRunDetail;
|
|
552
|
+
} | {
|
|
553
|
+
type: "action.started";
|
|
554
|
+
index: number;
|
|
555
|
+
kind: string;
|
|
556
|
+
at: string;
|
|
557
|
+
} | {
|
|
558
|
+
type: "action.finished";
|
|
559
|
+
index: number;
|
|
560
|
+
kind: string;
|
|
561
|
+
status: "succeeded" | "failed" | "skipped";
|
|
562
|
+
costUsd?: number;
|
|
563
|
+
error?: string;
|
|
564
|
+
at: string;
|
|
565
|
+
} | {
|
|
566
|
+
type: "iteration.started";
|
|
567
|
+
actionIndex: number;
|
|
568
|
+
iterationIndex: number;
|
|
569
|
+
model?: string;
|
|
570
|
+
at: string;
|
|
571
|
+
} | {
|
|
572
|
+
type: "iteration.ended";
|
|
573
|
+
actionIndex: number;
|
|
574
|
+
iterationIndex: number;
|
|
575
|
+
status: "succeeded" | "failed";
|
|
576
|
+
outputPreview?: string;
|
|
577
|
+
inputTokens?: number;
|
|
578
|
+
outputTokens?: number;
|
|
579
|
+
costUsd?: number;
|
|
580
|
+
at: string;
|
|
581
|
+
} | {
|
|
582
|
+
type: "token";
|
|
583
|
+
actionIndex: number;
|
|
584
|
+
delta: string;
|
|
585
|
+
at: string;
|
|
586
|
+
} | {
|
|
587
|
+
type: "ping";
|
|
588
|
+
} | {
|
|
589
|
+
type: "run.done";
|
|
590
|
+
status: "succeeded" | "failed" | "cancelled";
|
|
591
|
+
error?: string | null;
|
|
592
|
+
at?: string;
|
|
593
|
+
} | {
|
|
594
|
+
type: "run.waiting";
|
|
595
|
+
decisionId: string;
|
|
596
|
+
at?: string;
|
|
597
|
+
};
|
|
598
|
+
/** Latest-run snapshot attached to each workflow on the list response. */
|
|
599
|
+
interface HubWorkflowRunSummary {
|
|
600
|
+
id: string;
|
|
601
|
+
status: HubWorkflowRunStatus;
|
|
602
|
+
error: string | null;
|
|
603
|
+
createdAt: string;
|
|
604
|
+
completedAt: string | null;
|
|
605
|
+
}
|
|
606
|
+
/** One page of run history; `nextCursor` is null on the last page. */
|
|
607
|
+
interface HubWorkflowRunsPage {
|
|
608
|
+
runs: HubWorkflowRun[];
|
|
609
|
+
nextCursor: string | null;
|
|
610
|
+
}
|
|
611
|
+
interface HubWorkflow {
|
|
612
|
+
id: string;
|
|
613
|
+
name: string;
|
|
614
|
+
description: string | null;
|
|
615
|
+
enabled: boolean;
|
|
616
|
+
/** Compiled engine actions (connection refs resolved to ids). */
|
|
617
|
+
actions: HubWorkflowAction[];
|
|
618
|
+
/** The durable YAML this workflow compiled from. */
|
|
619
|
+
definitionYaml: string | null;
|
|
620
|
+
validationErrors: HubWorkflowValidationError[];
|
|
621
|
+
/** Present on get/create/update detail responses; omitted on list. */
|
|
622
|
+
triggers?: HubWorkflowTrigger[];
|
|
623
|
+
/** Present on the detail response: the trigger fields a manual run must supply,
|
|
624
|
+
* derived from the definition's `${trigger.*}` references (empty when none). */
|
|
625
|
+
manualRunInputs?: HubManualRunInput[];
|
|
626
|
+
/** Present on the list response (latest run, or null if never run); omitted on detail. */
|
|
627
|
+
lastRun?: HubWorkflowRunSummary | null;
|
|
628
|
+
createdAt: string;
|
|
629
|
+
updatedAt: string;
|
|
630
|
+
}
|
|
631
|
+
/** A trigger field a manual "Run now" must supply (derived from the
|
|
632
|
+
* definition's `${trigger.*}` references). `required` is false only when every
|
|
633
|
+
* read is wrapped in a `default(...)`. */
|
|
634
|
+
interface HubManualRunInput {
|
|
635
|
+
path: string;
|
|
636
|
+
required: boolean;
|
|
637
|
+
}
|
|
638
|
+
type HubWorkflowValidateResponse = {
|
|
639
|
+
valid: true;
|
|
640
|
+
name: string;
|
|
641
|
+
actionCount: number;
|
|
642
|
+
triggerCount: number;
|
|
643
|
+
} | {
|
|
644
|
+
valid: false;
|
|
645
|
+
errors: HubWorkflowValidationError[];
|
|
646
|
+
};
|
|
647
|
+
/** JSON Schema for the YAML workflow definition. */
|
|
648
|
+
type HubWorkflowSchemaResponse = Record<string, unknown>;
|
|
301
649
|
//#endregion
|
|
302
650
|
//#region src/client.d.ts
|
|
303
651
|
type HubAuthHeaders = () => HeadersInit | Promise<HeadersInit>;
|
|
@@ -339,10 +687,23 @@ declare class HubClient {
|
|
|
339
687
|
readonly approvals: HubApprovalsClient;
|
|
340
688
|
readonly audit: HubAuditClient;
|
|
341
689
|
readonly githubApp: HubGithubAppClient;
|
|
690
|
+
readonly workflows: HubWorkflowsClient;
|
|
342
691
|
constructor(options: HubClientOptions);
|
|
343
692
|
static fromEnv(options?: HubClientFromEnvOptions): HubClient;
|
|
344
693
|
status(): Promise<HubStatusResponse>;
|
|
345
694
|
private request;
|
|
695
|
+
/**
|
|
696
|
+
* Open a streaming (Server-Sent Events) response and return its raw body.
|
|
697
|
+
* Shares auth-header building + `fetch` with {@link request}, but does NOT
|
|
698
|
+
* buffer or JSON-parse the body — the caller consumes the stream.
|
|
699
|
+
*
|
|
700
|
+
* A successful stream comes back as `text/event-stream`. Anything else is an
|
|
701
|
+
* error envelope (404/429/401 JSON) or a transport failure (gateway/HTML
|
|
702
|
+
* page); it is surfaced the same way {@link request} surfaces errors — a
|
|
703
|
+
* typed `HubSdkError` from a `{success:false}` envelope, otherwise an
|
|
704
|
+
* `HUB_HTTP_<status>` transport error — rather than handed back as bogus SSE.
|
|
705
|
+
*/
|
|
706
|
+
private stream;
|
|
346
707
|
private buildHeaders;
|
|
347
708
|
}
|
|
348
709
|
interface HubTokenListOptions {
|
|
@@ -365,9 +726,25 @@ declare class HubPermissionsClient {
|
|
|
365
726
|
constructor(request: <TData>(path: string, init: RequestInit) => Promise<TData>);
|
|
366
727
|
list(connectionId: string): Promise<HubPolicyListResponse>;
|
|
367
728
|
set(input: HubPolicyUpdateRequest): Promise<HubPolicyResponse>;
|
|
729
|
+
/** Reset an action to its default by deleting any stored override. */
|
|
730
|
+
delete(input: HubPolicyDeleteRequest): Promise<HubPolicyDeleteResponse>;
|
|
731
|
+
/** Bulk-allow every write action of a connection's provider. Reads are
|
|
732
|
+
* already allowed for sandbox agents; destructive actions stay `ask`.
|
|
733
|
+
* Idempotent: actions with an existing policy are left untouched. */
|
|
734
|
+
allowWrites(connectionId: string): Promise<HubAllowWritesResponse>;
|
|
735
|
+
/** Inverse of `allowWrites`: delete only the rows it created for this
|
|
736
|
+
* connection. Manual per-action decisions are left intact. */
|
|
737
|
+
revertWrites(connectionId: string): Promise<HubRevertWritesResponse>;
|
|
368
738
|
}
|
|
369
739
|
interface HubToolSearchOptions {
|
|
370
740
|
provider?: string;
|
|
741
|
+
/** Max tools to return. The server defaults to a relevance-ranked shortlist
|
|
742
|
+
* (20); pass a higher value (bounded server-side) to enumerate a provider's
|
|
743
|
+
* full action list, e.g. for a catalog/browse UI. The cap bounds the MERGED
|
|
744
|
+
* response across sources — with no `provider` set, a low limit can exclude
|
|
745
|
+
* some providers' tools, so scope by `provider` when you need one connector's
|
|
746
|
+
* complete list. */
|
|
747
|
+
limit?: number;
|
|
371
748
|
}
|
|
372
749
|
interface HubToolInvokeOptions {
|
|
373
750
|
connectionId?: string;
|
|
@@ -390,7 +767,18 @@ declare class HubConnectionsClient {
|
|
|
390
767
|
private readonly request;
|
|
391
768
|
constructor(request: <TData>(path: string, init: RequestInit) => Promise<TData>);
|
|
392
769
|
list(): Promise<HubConnectionsResponse>;
|
|
770
|
+
/** Connector catalog: every provider the hub can expose, each flagged with
|
|
771
|
+
* `configured` (whether its OAuth app credentials are wired). Callers render
|
|
772
|
+
* this alongside `list()` to offer Connect for not-yet-connected providers. */
|
|
773
|
+
providers(): Promise<HubProvidersResponse>;
|
|
393
774
|
start(provider: string, options?: HubConnectionStartOptions): Promise<HubOAuthStartResponse>;
|
|
775
|
+
startWhatsappEmbeddedSignup(options?: HubWhatsappEmbeddedSignupStartRequest): Promise<HubWhatsappEmbeddedSignupStartResponse>;
|
|
776
|
+
completeWhatsappEmbeddedSignup(input: HubWhatsappEmbeddedSignupCompleteRequest): Promise<HubWhatsappEmbeddedSignupCompleteResponse>;
|
|
777
|
+
/** Connect a non-OAuth (api-key) connector by submitting the user's key.
|
|
778
|
+
* The server validates the key with a live probe before persisting and
|
|
779
|
+
* returns the created (or reconnected) connection — there is no redirect,
|
|
780
|
+
* unlike `start`. */
|
|
781
|
+
connectApiKey(provider: string, apiKey: string): Promise<HubApiKeyConnectResponse>;
|
|
394
782
|
revoke(connectionId: string): Promise<HubConnectionDeleteResponse>;
|
|
395
783
|
health(connectionId: string): Promise<HubConnectionHealthResponse>;
|
|
396
784
|
}
|
|
@@ -417,9 +805,108 @@ declare class HubAuditClient {
|
|
|
417
805
|
constructor(request: <TData>(path: string, init: RequestInit) => Promise<TData>);
|
|
418
806
|
list(options?: HubAuditListRequest): Promise<HubAuditResponse>;
|
|
419
807
|
}
|
|
808
|
+
declare class HubWorkflowsClient {
|
|
809
|
+
private readonly request;
|
|
810
|
+
private readonly stream?;
|
|
811
|
+
constructor(request: <TData>(path: string, init: RequestInit) => Promise<TData>, stream?: ((path: string, init: RequestInit) => Promise<ReadableStream<Uint8Array>>) | undefined);
|
|
812
|
+
list(): Promise<HubWorkflow[]>;
|
|
813
|
+
get(id: string): Promise<HubWorkflow>;
|
|
814
|
+
create(yaml: string): Promise<HubWorkflow>;
|
|
815
|
+
update(id: string, yaml: string): Promise<HubWorkflow>;
|
|
816
|
+
delete(id: string): Promise<void>;
|
|
817
|
+
/**
|
|
818
|
+
* Enable or disable a workflow without editing its YAML. Works even when the
|
|
819
|
+
* workflow's connection was revoked (a disabled workflow can't be recompiled
|
|
820
|
+
* via `update`, but it can still be paused/resumed here).
|
|
821
|
+
*/
|
|
822
|
+
setEnabled(id: string, enabled: boolean): Promise<HubWorkflow>;
|
|
823
|
+
/**
|
|
824
|
+
* One page of run history, newest first. Pass the previous page's
|
|
825
|
+
* `nextCursor` to fetch the next; a null `nextCursor` means the last page.
|
|
826
|
+
*/
|
|
827
|
+
listRuns(id: string, opts?: {
|
|
828
|
+
limit?: number;
|
|
829
|
+
cursor?: string;
|
|
830
|
+
}): Promise<HubWorkflowRunsPage>;
|
|
831
|
+
/**
|
|
832
|
+
* Enqueue an immediate ("Run now") run and return its `runId`. The run goes
|
|
833
|
+
* through the identical execution path a trigger delivery uses.
|
|
834
|
+
*
|
|
835
|
+
* `inputs` supplies the trigger fields the workflow reads (its
|
|
836
|
+
* {@link HubWorkflow.manualRunInputs}), as a flat `{ path: value }` map — e.g.
|
|
837
|
+
* `{ "pull_request.number": "123" }`. Omit it for a one-click run of a
|
|
838
|
+
* workflow that reads no trigger fields. Throws `HubSdkError`:
|
|
839
|
+
* `MISSING_RUN_INPUTS` when a required field is absent (`details.missing`
|
|
840
|
+
* names them), `WORKFLOW_DISABLED` when the workflow is paused, `NOT_FOUND`
|
|
841
|
+
* for an unknown/foreign id. Pass `opts.signal` to abort a slow request.
|
|
842
|
+
*/
|
|
843
|
+
run(id: string, inputs?: HubWorkflowRunInputs, opts?: {
|
|
844
|
+
signal?: AbortSignal;
|
|
845
|
+
}): Promise<HubWorkflowRunEnqueued>;
|
|
846
|
+
/**
|
|
847
|
+
* A single run's full detail: per-action `output` + `agentRun` execution
|
|
848
|
+
* detail (size-capped server-side) and the trigger context — the deep "why
|
|
849
|
+
* did this run do what it did" view. `NOT_FOUND` when the run is unknown or
|
|
850
|
+
* does not belong to both the caller and this workflow.
|
|
851
|
+
*/
|
|
852
|
+
getRun(id: string, runId: string, opts?: {
|
|
853
|
+
signal?: AbortSignal;
|
|
854
|
+
}): Promise<HubWorkflowRunDetail>;
|
|
855
|
+
/**
|
|
856
|
+
* Stop a queued or in-flight run. A `queued` run is cancelled synchronously
|
|
857
|
+
* and comes back `{ status: "cancelled" }` (already terminal); a `running` run
|
|
858
|
+
* is signalled to abort and comes back `{ status: "cancelling", signalled }` —
|
|
859
|
+
* it settles `cancelled` a moment later as its current action tears down, which
|
|
860
|
+
* a {@link watchRun}/{@link getRun} observes. Throws `HubSdkError`:
|
|
861
|
+
* `RUN_NOT_CANCELLABLE` when the run already finished, `NOT_FOUND` for an
|
|
862
|
+
* unknown/foreign run id. Pass `opts.signal` to abort a slow request.
|
|
863
|
+
*/
|
|
864
|
+
cancel(id: string, runId: string, opts?: {
|
|
865
|
+
signal?: AbortSignal;
|
|
866
|
+
}): Promise<HubWorkflowRunCancelResult>;
|
|
867
|
+
/**
|
|
868
|
+
* Stream a run's live progress as an async iterable of typed events. The
|
|
869
|
+
* first event is always a `snapshot` of the current persisted state; then
|
|
870
|
+
* `action.*` / `iteration.*` / `token` ticks arrive as the run executes;
|
|
871
|
+
* `ping` is a keepalive; a terminal `run.done` ends the iteration. If the run
|
|
872
|
+
* is already finished when the stream opens, it yields the snapshot then
|
|
873
|
+
* `run.done` and completes.
|
|
874
|
+
*
|
|
875
|
+
* Live ticks require the worker executing the run to share the API process;
|
|
876
|
+
* across instances only `snapshot` + `run.done` (from the server's terminal
|
|
877
|
+
* poll) arrive — the persisted record, read via {@link getRun}, stays the
|
|
878
|
+
* source of truth. Pass `signal` to cancel; iterating to `run.done` (or
|
|
879
|
+
* breaking early) releases the connection.
|
|
880
|
+
*/
|
|
881
|
+
watchRun(id: string, runId: string, opts?: {
|
|
882
|
+
signal?: AbortSignal;
|
|
883
|
+
}): AsyncGenerator<HubWorkflowRunStreamEvent>;
|
|
884
|
+
/**
|
|
885
|
+
* Poll {@link getRun} until the run reaches a terminal state (`succeeded` or
|
|
886
|
+
* `failed`) and return its detail. The scripting primitive behind "run and
|
|
887
|
+
* print the result": pairs with {@link run} for a one-call trigger-and-wait.
|
|
888
|
+
*
|
|
889
|
+
* Returns as soon as the run leaves the active set (`queued` / `running`) —
|
|
890
|
+
* i.e. on `succeeded`, `failed`, or any future non-active status — so a new
|
|
891
|
+
* terminal state can never hang the wait. Polls every `pollIntervalMs`
|
|
892
|
+
* (default 2000). With `timeoutMs` set, throws
|
|
893
|
+
* `HubSdkError(WORKFLOW_RUN_TIMEOUT)` — carrying the last observed status on
|
|
894
|
+
* `details.status` — only once the deadline has actually passed; the last
|
|
895
|
+
* wait is clamped to the remaining time so a `timeoutMs` shorter than the
|
|
896
|
+
* poll interval still waits the full requested window rather than giving up a
|
|
897
|
+
* poll early. Pass `signal` to cancel the wait between polls.
|
|
898
|
+
*/
|
|
899
|
+
waitForRun(id: string, runId: string, opts?: {
|
|
900
|
+
pollIntervalMs?: number;
|
|
901
|
+
timeoutMs?: number;
|
|
902
|
+
signal?: AbortSignal;
|
|
903
|
+
}): Promise<HubWorkflowRunDetail>;
|
|
904
|
+
validate(yaml: string): Promise<HubWorkflowValidateResponse>;
|
|
905
|
+
schema(): Promise<HubWorkflowSchemaResponse>;
|
|
906
|
+
}
|
|
420
907
|
//#endregion
|
|
421
908
|
//#region src/redaction.d.ts
|
|
422
909
|
declare function redactHubValue(value: unknown): unknown;
|
|
423
910
|
//#endregion
|
|
424
|
-
export { HUB_API_KEY_ENV_VAR, HUB_CAPABILITY_TOKEN_ENV_VAR, HUB_URL_ENV_VAR, type HubApproval, type HubApprovalCapabilityToken, type HubApprovalDecisionResponse, type HubApprovalStatus, HubApprovalsClient, HubAuditClient, type HubAuditEvent, type HubAuditListRequest, type HubAuditResponse, type HubAuthHeaders, type HubCapabilityToken, HubClient, type HubClientFromEnvOptions, type HubClientOptions, type HubConnection, type HubConnectionDeleteRequest, type HubConnectionDeleteResponse, type HubConnectionHealthError, type HubConnectionHealthInfo, type HubConnectionHealthRequest, type HubConnectionHealthResponse, type HubConnectionHealthStatus, type HubConnectionStartOptions, HubConnectionsClient, type HubConnectionsResponse, type HubEnv, type HubEnvelope, type HubErrorBody, type HubErrorCode, type HubErrorEnvelope, type HubExecRequest, type HubExecResponse, HubGithubAppClient, type HubGithubAppInstallation, type HubGithubAppInstallationResponse, type HubGithubAppIsRepoInstalledRequest, type HubGithubAppIsRepoInstalledResponse, type HubGithubAppListReposResponse, type HubGithubAppMintInstallationTokenRequest, type HubGithubAppMintInstallationTokenResponse, type HubOAuthCallbackErrorQuery, type HubOAuthCallbackQuery, type HubOAuthCallbackResponse, type HubOAuthCallbackSuccessQuery, type HubOAuthStartRequest, type HubOAuthStartResponse, HubPermissionsClient, type HubPolicy, type HubPolicyDecision, type HubPolicyListRequest, type HubPolicyListResponse, type HubPolicyResponse, type HubPolicyUpdateRequest, type HubPrincipal, type HubPrincipalKind, HubSdkError, type HubStatusConnections, type HubStatusResponse, type HubSuccessEnvelope, type HubTokenListOptions, type HubTokenMintRequest, type HubTokenMintResponse, type HubTokenRevokeResponse, HubTokensClient, type HubTokensListResponse, type HubTool, type HubToolInvokeOptions, type HubToolSearchOptions, type HubToolSource, type HubToolSourcesResponse, HubToolsClient, type HubToolsDescribeRequest, type HubToolsDescribeResponse, type HubToolsSearchRequest, type HubToolsSearchResponse, type HubUnimplementedErrorEnvelope, redactHubValue, resolveHubAuth, resolveHubBaseUrl };
|
|
911
|
+
export { HUB_API_KEY_ENV_VAR, HUB_CAPABILITY_TOKEN_ENV_VAR, HUB_URL_ENV_VAR, type HubAgentIterationSpan, type HubAgentRunDetail, type HubApiKeyConnectRequest, type HubApiKeyConnectResponse, type HubApproval, type HubApprovalCapabilityToken, type HubApprovalDecisionResponse, type HubApprovalStatus, HubApprovalsClient, HubAuditClient, type HubAuditEvent, type HubAuditListRequest, type HubAuditResponse, type HubAuthHeaders, type HubCapabilityToken, HubClient, type HubClientFromEnvOptions, type HubClientOptions, type HubConnection, type HubConnectionDeleteRequest, type HubConnectionDeleteResponse, type HubConnectionHealthError, type HubConnectionHealthInfo, type HubConnectionHealthRequest, type HubConnectionHealthResponse, type HubConnectionHealthStatus, type HubConnectionStartOptions, HubConnectionsClient, type HubConnectionsResponse, type HubEnv, type HubEnvelope, type HubErrorBody, type HubErrorCode, type HubErrorEnvelope, type HubExecRequest, type HubExecResponse, HubGithubAppClient, type HubGithubAppInstallation, type HubGithubAppInstallationResponse, type HubGithubAppIsRepoInstalledRequest, type HubGithubAppIsRepoInstalledResponse, type HubGithubAppListReposResponse, type HubGithubAppMintInstallationTokenRequest, type HubGithubAppMintInstallationTokenResponse, type HubManualRunInput, type HubOAuthCallbackErrorQuery, type HubOAuthCallbackQuery, type HubOAuthCallbackResponse, type HubOAuthCallbackSuccessQuery, type HubOAuthStartRequest, type HubOAuthStartResponse, HubPermissionsClient, type HubPolicy, type HubPolicyDecision, type HubPolicyDeleteRequest, type HubPolicyDeleteResponse, type HubPolicyListRequest, type HubPolicyListResponse, type HubPolicyResponse, type HubPolicyUpdateRequest, type HubPrincipal, type HubPrincipalKind, type HubProvider, type HubProviderAuthKind, type HubProvidersResponse, HubSdkError, type HubStatusConnections, type HubStatusResponse, type HubSuccessEnvelope, type HubTokenListOptions, type HubTokenMintRequest, type HubTokenMintResponse, type HubTokenRevokeResponse, HubTokensClient, type HubTokensListResponse, type HubTool, type HubToolInvokeOptions, type HubToolRisk, type HubToolSearchOptions, type HubToolSource, type HubToolSourcesResponse, HubToolsClient, type HubToolsDescribeRequest, type HubToolsDescribeResponse, type HubToolsSearchRequest, type HubToolsSearchResponse, type HubUnimplementedErrorEnvelope, type HubWhatsappEmbeddedSignupCompleteRequest, type HubWhatsappEmbeddedSignupCompleteResponse, type HubWhatsappEmbeddedSignupStartRequest, type HubWhatsappEmbeddedSignupStartResponse, type HubWorkflow, type HubWorkflowAction, type HubWorkflowActionResult, type HubWorkflowEventFilter, type HubWorkflowRun, type HubWorkflowRunCancelResult, type HubWorkflowRunDetail, type HubWorkflowRunEnqueued, type HubWorkflowRunInputs, type HubWorkflowRunStatus, type HubWorkflowRunStreamEvent, type HubWorkflowRunSummary, type HubWorkflowRunsPage, type HubWorkflowSchemaResponse, type HubWorkflowTrigger, type HubWorkflowValidateResponse, type HubWorkflowValidationError, HubWorkflowsClient, redactHubValue, resolveHubAuth, resolveHubBaseUrl };
|
|
425
912
|
//# sourceMappingURL=index.d.ts.map
|