akribes 0.21.17
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/CHANGELOG.md +30 -0
- package/LICENSE +21 -0
- package/README.md +160 -0
- package/dist/client.d.ts +240 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +272 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +196 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +274 -0
- package/dist/errors.js.map +1 -0
- package/dist/execution/index.d.ts +3 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +3 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/execution/replay.d.ts +37 -0
- package/dist/execution/replay.d.ts.map +1 -0
- package/dist/execution/replay.js +59 -0
- package/dist/execution/replay.js.map +1 -0
- package/dist/execution/steps.d.ts +327 -0
- package/dist/execution/steps.d.ts.map +1 -0
- package/dist/execution/steps.js +1068 -0
- package/dist/execution/steps.js.map +1 -0
- package/dist/http.d.ts +53 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +141 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/runStream.d.ts +176 -0
- package/dist/runStream.d.ts.map +1 -0
- package/dist/runStream.js +408 -0
- package/dist/runStream.js.map +1 -0
- package/dist/sse.d.ts +46 -0
- package/dist/sse.d.ts.map +1 -0
- package/dist/sse.js +218 -0
- package/dist/sse.js.map +1 -0
- package/dist/sub/bench.d.ts +182 -0
- package/dist/sub/bench.d.ts.map +1 -0
- package/dist/sub/bench.js +420 -0
- package/dist/sub/bench.js.map +1 -0
- package/dist/sub/channels.d.ts +22 -0
- package/dist/sub/channels.d.ts.map +1 -0
- package/dist/sub/channels.js +32 -0
- package/dist/sub/channels.js.map +1 -0
- package/dist/sub/clients.d.ts +79 -0
- package/dist/sub/clients.d.ts.map +1 -0
- package/dist/sub/clients.js +190 -0
- package/dist/sub/clients.js.map +1 -0
- package/dist/sub/documents.d.ts +113 -0
- package/dist/sub/documents.d.ts.map +1 -0
- package/dist/sub/documents.js +329 -0
- package/dist/sub/documents.js.map +1 -0
- package/dist/sub/evals.d.ts +71 -0
- package/dist/sub/evals.d.ts.map +1 -0
- package/dist/sub/evals.js +86 -0
- package/dist/sub/evals.js.map +1 -0
- package/dist/sub/events.d.ts +65 -0
- package/dist/sub/events.d.ts.map +1 -0
- package/dist/sub/events.js +154 -0
- package/dist/sub/events.js.map +1 -0
- package/dist/sub/executions.d.ts +255 -0
- package/dist/sub/executions.d.ts.map +1 -0
- package/dist/sub/executions.js +322 -0
- package/dist/sub/executions.js.map +1 -0
- package/dist/sub/mcp.d.ts +51 -0
- package/dist/sub/mcp.d.ts.map +1 -0
- package/dist/sub/mcp.js +42 -0
- package/dist/sub/mcp.js.map +1 -0
- package/dist/sub/projects.d.ts +73 -0
- package/dist/sub/projects.d.ts.map +1 -0
- package/dist/sub/projects.js +101 -0
- package/dist/sub/projects.js.map +1 -0
- package/dist/sub/scripts.d.ts +58 -0
- package/dist/sub/scripts.d.ts.map +1 -0
- package/dist/sub/scripts.js +82 -0
- package/dist/sub/scripts.js.map +1 -0
- package/dist/sub/tokens.d.ts +126 -0
- package/dist/sub/tokens.d.ts.map +1 -0
- package/dist/sub/tokens.js +105 -0
- package/dist/sub/tokens.js.map +1 -0
- package/dist/sub/versions.d.ts +29 -0
- package/dist/sub/versions.d.ts.map +1 -0
- package/dist/sub/versions.js +52 -0
- package/dist/sub/versions.js.map +1 -0
- package/dist/tokenSafety.d.ts +15 -0
- package/dist/tokenSafety.d.ts.map +1 -0
- package/dist/tokenSafety.js +24 -0
- package/dist/tokenSafety.js.map +1 -0
- package/dist/types.d.ts +1147 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +132 -0
- package/dist/types.js.map +1 -0
- package/dist/workflowEvents.d.ts +297 -0
- package/dist/workflowEvents.d.ts.map +1 -0
- package/dist/workflowEvents.js +612 -0
- package/dist/workflowEvents.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import type { HttpClient } from '../http';
|
|
2
|
+
import type { ContractState } from './clients';
|
|
3
|
+
import type { RunResult, ExecutionStatus, ExecutionOutput, ExecutionEvents, S3DocumentRef, ScriptGraph, ScriptCost, ProjectCost } from '../types';
|
|
4
|
+
import { type RunStream, type RunStreamEventsSource, type RunStreamOptions } from '../runStream';
|
|
5
|
+
/** Summary of a child execution spawned via the `spawn_child_execution`
|
|
6
|
+
* callback. Returned by `GET /executions/:id/children`. For v1 the parent
|
|
7
|
+
* linkage columns are typically NULL; this type is forward-looking. */
|
|
8
|
+
export type ExecutionChildSummary = {
|
|
9
|
+
id: string;
|
|
10
|
+
parent_node_id: string | null;
|
|
11
|
+
status: string;
|
|
12
|
+
started_at: string | null;
|
|
13
|
+
finished_at: string | null;
|
|
14
|
+
script_name: string;
|
|
15
|
+
};
|
|
16
|
+
/** Per-task cost / token breakdown row returned by
|
|
17
|
+
* `GET /executions/:id/tasks`. Mirrors the shape produced by
|
|
18
|
+
* `get_execution_tasks` in akribes-server: one row per `execution_tasks`
|
|
19
|
+
* entry, populated as `TaskEnd` events arrive. */
|
|
20
|
+
export type ExecutionTaskSummary = {
|
|
21
|
+
task_name: string;
|
|
22
|
+
model: string | null;
|
|
23
|
+
provider: string | null;
|
|
24
|
+
input_tokens: number;
|
|
25
|
+
output_tokens: number;
|
|
26
|
+
cached_input_tokens: number;
|
|
27
|
+
cache_write_input_tokens: number;
|
|
28
|
+
cost_usd: number | null;
|
|
29
|
+
duration_ms: number | null;
|
|
30
|
+
attempt: number;
|
|
31
|
+
finished_at: string;
|
|
32
|
+
};
|
|
33
|
+
/** Envelope returned by `GET /executions/:id/tasks`. */
|
|
34
|
+
export type ExecutionTasksResponse = {
|
|
35
|
+
execution_id: string;
|
|
36
|
+
tasks: ExecutionTaskSummary[];
|
|
37
|
+
};
|
|
38
|
+
export declare class ExecutionsClient {
|
|
39
|
+
private http;
|
|
40
|
+
private projectId;
|
|
41
|
+
private defaultTriggeredBy;
|
|
42
|
+
private contractState?;
|
|
43
|
+
/** Lazy getter for the SSE source. Called on each `runStream()` call so
|
|
44
|
+
* `AkribesClient` can instantiate both sub-clients without a circular init. */
|
|
45
|
+
private eventsSourceFactory?;
|
|
46
|
+
constructor(http: HttpClient, projectId: number, defaultTriggeredBy: string | undefined, contractState?: ContractState | undefined,
|
|
47
|
+
/** Lazy getter for the SSE source. Called on each `runStream()` call so
|
|
48
|
+
* `AkribesClient` can instantiate both sub-clients without a circular init. */
|
|
49
|
+
eventsSourceFactory?: (() => RunStreamEventsSource) | undefined);
|
|
50
|
+
private path;
|
|
51
|
+
/** Pre-dispatch validation: check contract state before sending the request.
|
|
52
|
+
* Server is authoritative for per-input type checking; the client only
|
|
53
|
+
* short-circuits on a known schema break. */
|
|
54
|
+
private validateContract;
|
|
55
|
+
run(scriptName: string, opts?: {
|
|
56
|
+
inputs?: Record<string, unknown>;
|
|
57
|
+
channel?: string;
|
|
58
|
+
triggeredBy?: string;
|
|
59
|
+
signal?: AbortSignal;
|
|
60
|
+
breakpointLines?: number[];
|
|
61
|
+
/** When true, MCP tool calls execute in dry-run mode (no side effects).
|
|
62
|
+
* Server-side enforcement lands in Phase 4 (Task 38) — flag passes through today. */
|
|
63
|
+
dryRunTools?: boolean;
|
|
64
|
+
}): Promise<RunResult>;
|
|
65
|
+
/** Run a script with files uploaded via multipart form data. */
|
|
66
|
+
runWithUpload(scriptName: string, files: Record<string, {
|
|
67
|
+
filename: string;
|
|
68
|
+
data: Blob | File;
|
|
69
|
+
}>, opts?: {
|
|
70
|
+
channel?: string;
|
|
71
|
+
triggeredBy?: string;
|
|
72
|
+
signal?: AbortSignal;
|
|
73
|
+
}): Promise<RunResult>;
|
|
74
|
+
/** Run a script with documents referenced from S3. */
|
|
75
|
+
runWithS3(scriptName: string, inputs: Record<string, S3DocumentRef>, opts?: {
|
|
76
|
+
channel?: string;
|
|
77
|
+
triggeredBy?: string;
|
|
78
|
+
signal?: AbortSignal;
|
|
79
|
+
}): Promise<RunResult>;
|
|
80
|
+
get(executionId: string, opts?: {
|
|
81
|
+
signal?: AbortSignal;
|
|
82
|
+
}): Promise<ExecutionStatus | null>;
|
|
83
|
+
getOutput(executionId: string, opts?: {
|
|
84
|
+
signal?: AbortSignal;
|
|
85
|
+
}): Promise<ExecutionOutput | null>;
|
|
86
|
+
getEvents(executionId: string, opts?: {
|
|
87
|
+
afterId?: number;
|
|
88
|
+
limit?: number;
|
|
89
|
+
signal?: AbortSignal;
|
|
90
|
+
}): Promise<ExecutionEvents | null>;
|
|
91
|
+
list(scriptName: string, options?: {
|
|
92
|
+
status?: string;
|
|
93
|
+
channel?: string;
|
|
94
|
+
limit?: number;
|
|
95
|
+
offset?: number;
|
|
96
|
+
signal?: AbortSignal;
|
|
97
|
+
}): Promise<ExecutionStatus[]>;
|
|
98
|
+
/** List child executions spawned by this execution via the engine's
|
|
99
|
+
* spawn_child_execution callback. Returns an empty array when no children
|
|
100
|
+
* exist (the common case for v1 where parent linkage isn't yet wired). */
|
|
101
|
+
children(executionId: string, opts?: {
|
|
102
|
+
signal?: AbortSignal;
|
|
103
|
+
}): Promise<ExecutionChildSummary[]>;
|
|
104
|
+
/** Per-task cost / token / duration breakdown for an execution. Reads from
|
|
105
|
+
* the `execution_tasks` table populated as `TaskEnd` events arrive. Useful
|
|
106
|
+
* for monolith workflows where there are no spawned children — every
|
|
107
|
+
* agent invocation lives in `execution_tasks` keyed by `task_name`. */
|
|
108
|
+
tasks(executionId: string, opts?: {
|
|
109
|
+
signal?: AbortSignal;
|
|
110
|
+
}): Promise<ExecutionTasksResponse>;
|
|
111
|
+
cancel(executionId: string, opts?: {
|
|
112
|
+
signal?: AbortSignal;
|
|
113
|
+
}): Promise<void>;
|
|
114
|
+
cancelRun(scriptName: string, opts?: {
|
|
115
|
+
signal?: AbortSignal;
|
|
116
|
+
}): Promise<void>;
|
|
117
|
+
/** Cross-SDK naming alias for {@link cancelRun}. Mirrors the Python SDK's
|
|
118
|
+
* `cancel_all`. Refs #109 (item 3: method-naming consistency). */
|
|
119
|
+
cancelAll(scriptName: string, opts?: {
|
|
120
|
+
signal?: AbortSignal;
|
|
121
|
+
}): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Resume a suspended checkpoint.
|
|
124
|
+
*
|
|
125
|
+
* For plain `checkpoint` resumes pass `data` (the payload that satisfies
|
|
126
|
+
* the checkpoint's schema). For tool-approval gates pass
|
|
127
|
+
* `{ approve: true|false, args_override? }`; the server builds the
|
|
128
|
+
* `{approve, args}` payload the engine's approval gate expects. (#729)
|
|
129
|
+
*/
|
|
130
|
+
resume(executionId: string, token: string, data: unknown, opts?: {
|
|
131
|
+
signal?: AbortSignal;
|
|
132
|
+
approve?: boolean;
|
|
133
|
+
args_override?: unknown;
|
|
134
|
+
}): Promise<void>;
|
|
135
|
+
/** Poll until execution reaches a terminal state. */
|
|
136
|
+
waitFor(executionId: string, options?: {
|
|
137
|
+
timeoutMs?: number;
|
|
138
|
+
pollIntervalMs?: number;
|
|
139
|
+
signal?: AbortSignal;
|
|
140
|
+
}): Promise<ExecutionOutput>;
|
|
141
|
+
/**
|
|
142
|
+
* Poll an execution to completion and return its final output.
|
|
143
|
+
*
|
|
144
|
+
* Mirrors the Rust SDK's `await_execution`. Unlike {@link RunStream.output}
|
|
145
|
+
* (which only resolves for streams the caller initiated), this works for any
|
|
146
|
+
* `executionId` — including ones discovered via {@link list} or surfaced by
|
|
147
|
+
* another process.
|
|
148
|
+
*
|
|
149
|
+
* Defaults: 5-minute timeout. Pass `timeout: 0` to wait indefinitely. The
|
|
150
|
+
* optional `AbortSignal` short-circuits the poll loop and is forwarded to
|
|
151
|
+
* the underlying HTTP request.
|
|
152
|
+
*
|
|
153
|
+
* Throws {@link AkribesTransientError} on retryable failures (`RateLimit`,
|
|
154
|
+
* `ServerError`, `NetworkError`), {@link AkribesFatalError} on `AuthError` /
|
|
155
|
+
* `TokenLimit`, and {@link AkribesScriptError} for everything else (including
|
|
156
|
+
* cancellation).
|
|
157
|
+
*/
|
|
158
|
+
await(executionId: string, opts?: {
|
|
159
|
+
timeout?: number;
|
|
160
|
+
signal?: AbortSignal;
|
|
161
|
+
}): Promise<ExecutionOutput>;
|
|
162
|
+
/** Cross-SDK naming alias for {@link await}. Mirrors the Rust SDK's
|
|
163
|
+
* `await_execution`. Refs #109 (item 3: method-naming consistency). */
|
|
164
|
+
awaitExecution(executionId: string, opts?: {
|
|
165
|
+
timeout?: number;
|
|
166
|
+
signal?: AbortSignal;
|
|
167
|
+
}): Promise<ExecutionOutput>;
|
|
168
|
+
/** Cross-SDK naming alias for {@link await}. Mirrors the Python SDK's
|
|
169
|
+
* `await_result`. Refs #109 (item 3: method-naming consistency). */
|
|
170
|
+
awaitResult(executionId: string, opts?: {
|
|
171
|
+
timeout?: number;
|
|
172
|
+
signal?: AbortSignal;
|
|
173
|
+
}): Promise<ExecutionOutput>;
|
|
174
|
+
/** Run a script from a specific point, with pre-seeded environment values.
|
|
175
|
+
* Skips nodes whose outputs are provided in seedEnv.
|
|
176
|
+
*/
|
|
177
|
+
runFrom(scriptName: string, opts: {
|
|
178
|
+
seedEnv: Record<string, unknown>;
|
|
179
|
+
skipNodeIds: number[];
|
|
180
|
+
inputs?: Record<string, unknown>;
|
|
181
|
+
channel?: string;
|
|
182
|
+
triggeredBy?: string;
|
|
183
|
+
signal?: AbortSignal;
|
|
184
|
+
}): Promise<RunResult>;
|
|
185
|
+
/** Get the compiled execution DAG for a script. If versionId is omitted, uses the draft. */
|
|
186
|
+
getGraph(scriptName: string, opts?: {
|
|
187
|
+
versionId?: number;
|
|
188
|
+
signal?: AbortSignal;
|
|
189
|
+
}): Promise<ScriptGraph>;
|
|
190
|
+
/** Get cost aggregation for the entire project, optionally filtered by date range.
|
|
191
|
+
* Rolls up: per-script totals, per-channel totals, and overall totals.
|
|
192
|
+
* `unknown_cost_executions` counts runs whose model wasn't in the pricing
|
|
193
|
+
* table; their tokens are still included, but they contribute `0` to cost.
|
|
194
|
+
*/
|
|
195
|
+
getProjectCost(opts?: {
|
|
196
|
+
since?: string;
|
|
197
|
+
until?: string;
|
|
198
|
+
signal?: AbortSignal;
|
|
199
|
+
}): Promise<ProjectCost>;
|
|
200
|
+
/** Get cost aggregation for a script (total, avg, per-version, per-channel). */
|
|
201
|
+
getCost(scriptName: string, opts?: {
|
|
202
|
+
since?: string;
|
|
203
|
+
until?: string;
|
|
204
|
+
signal?: AbortSignal;
|
|
205
|
+
}): Promise<ScriptCost>;
|
|
206
|
+
/** Run a script and wait for the result. Returns [execution_id, output]. */
|
|
207
|
+
runAndAwait(scriptName: string, opts?: {
|
|
208
|
+
inputs?: Record<string, unknown>;
|
|
209
|
+
channel?: string;
|
|
210
|
+
triggeredBy?: string;
|
|
211
|
+
timeoutMs?: number;
|
|
212
|
+
pollIntervalMs?: number;
|
|
213
|
+
signal?: AbortSignal;
|
|
214
|
+
}): Promise<[string, ExecutionOutput]>;
|
|
215
|
+
/**
|
|
216
|
+
* Start a run and return a {@link RunStream} lifecycle handle. The stream
|
|
217
|
+
* subscribes to events BEFORE issuing the run POST so no early events are
|
|
218
|
+
* missed. It's async-iterable, exposes `.output` / `.executionId` promises,
|
|
219
|
+
* and offers category-based `.on.<cat>()` callback registration.
|
|
220
|
+
*
|
|
221
|
+
* Requires the client was constructed with a `projectId` so the events
|
|
222
|
+
* sub-client is available.
|
|
223
|
+
*/
|
|
224
|
+
runStream(scriptName: string, opts?: RunStreamOptions): RunStream;
|
|
225
|
+
/** Get document metadata by ID. */
|
|
226
|
+
getDocument(documentId: string, opts?: {
|
|
227
|
+
signal?: AbortSignal;
|
|
228
|
+
}): Promise<{
|
|
229
|
+
id: string;
|
|
230
|
+
filename: string;
|
|
231
|
+
content_type: string;
|
|
232
|
+
size_bytes: number;
|
|
233
|
+
content_hash: string;
|
|
234
|
+
conversion_status: string;
|
|
235
|
+
conversion_error: string | null;
|
|
236
|
+
created_at: string;
|
|
237
|
+
} | null>;
|
|
238
|
+
/** Get converted markdown for a document. */
|
|
239
|
+
getDocumentMarkdown(documentId: string, opts?: {
|
|
240
|
+
signal?: AbortSignal;
|
|
241
|
+
}): Promise<{
|
|
242
|
+
markdown: string;
|
|
243
|
+
}>;
|
|
244
|
+
/** Get a presigned download URL for the original document file. */
|
|
245
|
+
getDocumentUrl(documentId: string, opts?: {
|
|
246
|
+
signal?: AbortSignal;
|
|
247
|
+
}): Promise<string>;
|
|
248
|
+
/** Retry conversion on a failed document. */
|
|
249
|
+
reconvertDocument(documentId: string, opts?: {
|
|
250
|
+
signal?: AbortSignal;
|
|
251
|
+
}): Promise<{
|
|
252
|
+
status: string;
|
|
253
|
+
}>;
|
|
254
|
+
}
|
|
255
|
+
//# sourceMappingURL=executions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executions.d.ts","sourceRoot":"","sources":["../../src/sub/executions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG1C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,eAAe,EAAE,eAAe,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAClJ,OAAO,EAAmB,KAAK,SAAS,EAAE,KAAK,qBAAqB,EAAE,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAElH;;wEAEwE;AACxE,MAAM,MAAM,qBAAqB,GAAG;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC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,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC;QAC9E,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QACvE,YAAY,EAAE,MAAM,CAAC;QAAC,iBAAiB,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;QACjF,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,IAAI,CAAC;IAMT,6CAA6C;IACvC,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAM7G,mEAAmE;IAC7D,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAQ1F,6CAA6C;IACvC,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAM1G"}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import { nullOn404 } from '../http';
|
|
2
|
+
import { AkribesTransientError, AkribesFatalError, AkribesScriptError, AkribesTimeoutError, ScriptSchemaChangedError } from '../errors';
|
|
3
|
+
import { createRunStream } from '../runStream';
|
|
4
|
+
/** Default timeout for {@link ExecutionsClient.await} — 5 minutes. */
|
|
5
|
+
const DEFAULT_AWAIT_TIMEOUT_MS = 5 * 60 * 1000;
|
|
6
|
+
/** Sleep for `ms`, returning early if `signal` aborts. */
|
|
7
|
+
function sleepUntilAborted(ms, signal) {
|
|
8
|
+
if (signal?.aborted)
|
|
9
|
+
return Promise.resolve();
|
|
10
|
+
return new Promise((resolve) => {
|
|
11
|
+
const t = setTimeout(() => {
|
|
12
|
+
signal?.removeEventListener('abort', onAbort);
|
|
13
|
+
resolve();
|
|
14
|
+
}, ms);
|
|
15
|
+
const onAbort = () => { clearTimeout(t); resolve(); };
|
|
16
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export class ExecutionsClient {
|
|
20
|
+
http;
|
|
21
|
+
projectId;
|
|
22
|
+
defaultTriggeredBy;
|
|
23
|
+
contractState;
|
|
24
|
+
eventsSourceFactory;
|
|
25
|
+
constructor(http, projectId, defaultTriggeredBy, contractState,
|
|
26
|
+
/** Lazy getter for the SSE source. Called on each `runStream()` call so
|
|
27
|
+
* `AkribesClient` can instantiate both sub-clients without a circular init. */
|
|
28
|
+
eventsSourceFactory) {
|
|
29
|
+
this.http = http;
|
|
30
|
+
this.projectId = projectId;
|
|
31
|
+
this.defaultTriggeredBy = defaultTriggeredBy;
|
|
32
|
+
this.contractState = contractState;
|
|
33
|
+
this.eventsSourceFactory = eventsSourceFactory;
|
|
34
|
+
}
|
|
35
|
+
path(scriptName, ...segments) {
|
|
36
|
+
return this.http.scriptPath(this.projectId, scriptName, ...segments);
|
|
37
|
+
}
|
|
38
|
+
/** Pre-dispatch validation: check contract state before sending the request.
|
|
39
|
+
* Server is authoritative for per-input type checking; the client only
|
|
40
|
+
* short-circuits on a known schema break. */
|
|
41
|
+
validateContract(scriptName) {
|
|
42
|
+
if (!this.contractState)
|
|
43
|
+
return;
|
|
44
|
+
if (this.contractState.brokenScripts.has(scriptName)) {
|
|
45
|
+
throw new ScriptSchemaChangedError(scriptName);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async run(scriptName, opts) {
|
|
49
|
+
this.validateContract(scriptName);
|
|
50
|
+
const channel = opts?.channel ?? 'production';
|
|
51
|
+
const url = `${this.path(scriptName, 'run')}?channel=${encodeURIComponent(channel)}`;
|
|
52
|
+
return (await this.http.fetchOk(url, {
|
|
53
|
+
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
|
54
|
+
body: JSON.stringify({
|
|
55
|
+
inputs: opts?.inputs,
|
|
56
|
+
triggered_by: opts?.triggeredBy ?? this.defaultTriggeredBy,
|
|
57
|
+
breakpoint_lines: opts?.breakpointLines,
|
|
58
|
+
dry_run_tools: opts?.dryRunTools,
|
|
59
|
+
}),
|
|
60
|
+
signal: opts?.signal,
|
|
61
|
+
})).json();
|
|
62
|
+
}
|
|
63
|
+
/** Run a script with files uploaded via multipart form data. */
|
|
64
|
+
async runWithUpload(scriptName, files, opts) {
|
|
65
|
+
const channel = opts?.channel ?? 'production';
|
|
66
|
+
const url = `${this.path(scriptName, 'run', 'upload')}?channel=${encodeURIComponent(channel)}`;
|
|
67
|
+
const form = new FormData();
|
|
68
|
+
for (const [name, file] of Object.entries(files)) {
|
|
69
|
+
form.append(name, file.data, file.filename);
|
|
70
|
+
}
|
|
71
|
+
if (opts?.triggeredBy ?? this.defaultTriggeredBy) {
|
|
72
|
+
form.append('_meta', JSON.stringify({ triggered_by: opts?.triggeredBy ?? this.defaultTriggeredBy }));
|
|
73
|
+
}
|
|
74
|
+
return (await this.http.fetchOk(url, { method: 'POST', body: form, signal: opts?.signal })).json();
|
|
75
|
+
}
|
|
76
|
+
/** Run a script with documents referenced from S3. */
|
|
77
|
+
async runWithS3(scriptName, inputs, opts) {
|
|
78
|
+
const url = this.path(scriptName, 'run', 's3');
|
|
79
|
+
return (await this.http.fetchOk(url, {
|
|
80
|
+
method: 'POST',
|
|
81
|
+
headers: { 'Content-Type': 'application/json' },
|
|
82
|
+
body: JSON.stringify({
|
|
83
|
+
inputs,
|
|
84
|
+
channel: opts?.channel ?? 'production',
|
|
85
|
+
triggered_by: opts?.triggeredBy ?? this.defaultTriggeredBy,
|
|
86
|
+
}),
|
|
87
|
+
signal: opts?.signal,
|
|
88
|
+
})).json();
|
|
89
|
+
}
|
|
90
|
+
async get(executionId, opts) {
|
|
91
|
+
return nullOn404(async () => (await this.http.fetchOk(`${this.http.getBaseUrl()}/executions/${encodeURIComponent(executionId)}`, opts)).json());
|
|
92
|
+
}
|
|
93
|
+
async getOutput(executionId, opts) {
|
|
94
|
+
return nullOn404(async () => (await this.http.fetchOk(`${this.http.getBaseUrl()}/executions/${encodeURIComponent(executionId)}/output`, opts)).json());
|
|
95
|
+
}
|
|
96
|
+
async getEvents(executionId, opts) {
|
|
97
|
+
const params = new URLSearchParams();
|
|
98
|
+
if (opts?.afterId != null)
|
|
99
|
+
params.set('after_id', String(opts.afterId));
|
|
100
|
+
if (opts?.limit != null)
|
|
101
|
+
params.set('limit', String(opts.limit));
|
|
102
|
+
const qs = params.toString();
|
|
103
|
+
const url = `${this.http.getBaseUrl()}/executions/${encodeURIComponent(executionId)}/events${qs ? `?${qs}` : ''}`;
|
|
104
|
+
return nullOn404(async () => (await this.http.fetchOk(url, { signal: opts?.signal })).json());
|
|
105
|
+
}
|
|
106
|
+
async list(scriptName, options) {
|
|
107
|
+
const params = new URLSearchParams();
|
|
108
|
+
if (options?.status)
|
|
109
|
+
params.set('status', options.status);
|
|
110
|
+
if (options?.channel)
|
|
111
|
+
params.set('channel', options.channel);
|
|
112
|
+
if (options?.limit != null)
|
|
113
|
+
params.set('limit', String(options.limit));
|
|
114
|
+
if (options?.offset != null)
|
|
115
|
+
params.set('offset', String(options.offset));
|
|
116
|
+
const qs = params.toString();
|
|
117
|
+
const url = `${this.path(scriptName, 'executions')}${qs ? '?' + qs : ''}`;
|
|
118
|
+
return (await this.http.fetchOk(url, { signal: options?.signal })).json();
|
|
119
|
+
}
|
|
120
|
+
/** List child executions spawned by this execution via the engine's
|
|
121
|
+
* spawn_child_execution callback. Returns an empty array when no children
|
|
122
|
+
* exist (the common case for v1 where parent linkage isn't yet wired). */
|
|
123
|
+
async children(executionId, opts) {
|
|
124
|
+
return (await this.http.fetchOk(`${this.http.getBaseUrl()}/executions/${encodeURIComponent(executionId)}/children`, opts)).json();
|
|
125
|
+
}
|
|
126
|
+
/** Per-task cost / token / duration breakdown for an execution. Reads from
|
|
127
|
+
* the `execution_tasks` table populated as `TaskEnd` events arrive. Useful
|
|
128
|
+
* for monolith workflows where there are no spawned children — every
|
|
129
|
+
* agent invocation lives in `execution_tasks` keyed by `task_name`. */
|
|
130
|
+
async tasks(executionId, opts) {
|
|
131
|
+
return (await this.http.fetchOk(`${this.http.getBaseUrl()}/executions/${encodeURIComponent(executionId)}/tasks`, opts)).json();
|
|
132
|
+
}
|
|
133
|
+
async cancel(executionId, opts) {
|
|
134
|
+
await this.http.fetchOk(`${this.http.getBaseUrl()}/executions/${encodeURIComponent(executionId)}`, {
|
|
135
|
+
method: 'DELETE', signal: opts?.signal,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
async cancelRun(scriptName, opts) {
|
|
139
|
+
await this.http.fetchOk(this.path(scriptName, 'run'), { method: 'DELETE', signal: opts?.signal });
|
|
140
|
+
}
|
|
141
|
+
/** Cross-SDK naming alias for {@link cancelRun}. Mirrors the Python SDK's
|
|
142
|
+
* `cancel_all`. Refs #109 (item 3: method-naming consistency). */
|
|
143
|
+
async cancelAll(scriptName, opts) {
|
|
144
|
+
return this.cancelRun(scriptName, opts);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Resume a suspended checkpoint.
|
|
148
|
+
*
|
|
149
|
+
* For plain `checkpoint` resumes pass `data` (the payload that satisfies
|
|
150
|
+
* the checkpoint's schema). For tool-approval gates pass
|
|
151
|
+
* `{ approve: true|false, args_override? }`; the server builds the
|
|
152
|
+
* `{approve, args}` payload the engine's approval gate expects. (#729)
|
|
153
|
+
*/
|
|
154
|
+
async resume(executionId, token, data, opts) {
|
|
155
|
+
const body = { token, data };
|
|
156
|
+
if (opts?.approve !== undefined)
|
|
157
|
+
body.approve = opts.approve;
|
|
158
|
+
if (opts?.args_override !== undefined)
|
|
159
|
+
body.args_override = opts.args_override;
|
|
160
|
+
await this.http.fetchOk(`${this.http.getBaseUrl()}/executions/${encodeURIComponent(executionId)}/resume`, {
|
|
161
|
+
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
|
162
|
+
body: JSON.stringify(body), signal: opts?.signal,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
/** Poll until execution reaches a terminal state. */
|
|
166
|
+
async waitFor(executionId, options) {
|
|
167
|
+
const timeout = options?.timeoutMs ?? 0;
|
|
168
|
+
const interval = options?.pollIntervalMs ?? 500;
|
|
169
|
+
const start = Date.now();
|
|
170
|
+
while (true) {
|
|
171
|
+
if (options?.signal?.aborted) {
|
|
172
|
+
throw new Error(`Execution ${executionId} await aborted`);
|
|
173
|
+
}
|
|
174
|
+
const output = await this.getOutput(executionId, { signal: options?.signal });
|
|
175
|
+
const terminalStates = ['completed', 'failed', 'cancelled'];
|
|
176
|
+
if (output && terminalStates.includes(output.status)) {
|
|
177
|
+
if (output.status === 'failed') {
|
|
178
|
+
const msg = output.error || 'Execution failed';
|
|
179
|
+
const kind = output.error_kind;
|
|
180
|
+
if (kind === 'RateLimit' || kind === 'ServerError' || kind === 'NetworkError') {
|
|
181
|
+
throw new AkribesTransientError(msg, executionId);
|
|
182
|
+
}
|
|
183
|
+
else if (kind === 'AuthError' || kind === 'TokenLimit') {
|
|
184
|
+
throw new AkribesFatalError(msg, executionId);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
throw new AkribesScriptError(msg, executionId);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return output;
|
|
191
|
+
}
|
|
192
|
+
if (timeout > 0 && Date.now() - start > timeout) {
|
|
193
|
+
throw new AkribesTimeoutError(`Execution ${executionId} timed out after ${timeout}ms`, executionId, timeout);
|
|
194
|
+
}
|
|
195
|
+
await sleepUntilAborted(interval, options?.signal);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Poll an execution to completion and return its final output.
|
|
200
|
+
*
|
|
201
|
+
* Mirrors the Rust SDK's `await_execution`. Unlike {@link RunStream.output}
|
|
202
|
+
* (which only resolves for streams the caller initiated), this works for any
|
|
203
|
+
* `executionId` — including ones discovered via {@link list} or surfaced by
|
|
204
|
+
* another process.
|
|
205
|
+
*
|
|
206
|
+
* Defaults: 5-minute timeout. Pass `timeout: 0` to wait indefinitely. The
|
|
207
|
+
* optional `AbortSignal` short-circuits the poll loop and is forwarded to
|
|
208
|
+
* the underlying HTTP request.
|
|
209
|
+
*
|
|
210
|
+
* Throws {@link AkribesTransientError} on retryable failures (`RateLimit`,
|
|
211
|
+
* `ServerError`, `NetworkError`), {@link AkribesFatalError} on `AuthError` /
|
|
212
|
+
* `TokenLimit`, and {@link AkribesScriptError} for everything else (including
|
|
213
|
+
* cancellation).
|
|
214
|
+
*/
|
|
215
|
+
async await(executionId, opts) {
|
|
216
|
+
return this.waitFor(executionId, {
|
|
217
|
+
timeoutMs: opts?.timeout ?? DEFAULT_AWAIT_TIMEOUT_MS,
|
|
218
|
+
signal: opts?.signal,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
/** Cross-SDK naming alias for {@link await}. Mirrors the Rust SDK's
|
|
222
|
+
* `await_execution`. Refs #109 (item 3: method-naming consistency). */
|
|
223
|
+
async awaitExecution(executionId, opts) {
|
|
224
|
+
return this.await(executionId, opts);
|
|
225
|
+
}
|
|
226
|
+
/** Cross-SDK naming alias for {@link await}. Mirrors the Python SDK's
|
|
227
|
+
* `await_result`. Refs #109 (item 3: method-naming consistency). */
|
|
228
|
+
async awaitResult(executionId, opts) {
|
|
229
|
+
return this.await(executionId, opts);
|
|
230
|
+
}
|
|
231
|
+
/** Run a script from a specific point, with pre-seeded environment values.
|
|
232
|
+
* Skips nodes whose outputs are provided in seedEnv.
|
|
233
|
+
*/
|
|
234
|
+
async runFrom(scriptName, opts) {
|
|
235
|
+
const channel = opts.channel ?? 'draft';
|
|
236
|
+
const url = `${this.path(scriptName, 'run', 'from')}?channel=${encodeURIComponent(channel)}`;
|
|
237
|
+
return (await this.http.fetchOk(url, {
|
|
238
|
+
method: 'POST',
|
|
239
|
+
headers: { 'Content-Type': 'application/json' },
|
|
240
|
+
body: JSON.stringify({
|
|
241
|
+
inputs: opts.inputs,
|
|
242
|
+
seed_env: opts.seedEnv,
|
|
243
|
+
skip_node_ids: opts.skipNodeIds,
|
|
244
|
+
triggered_by: opts.triggeredBy ?? this.defaultTriggeredBy,
|
|
245
|
+
}),
|
|
246
|
+
signal: opts.signal,
|
|
247
|
+
})).json();
|
|
248
|
+
}
|
|
249
|
+
/** Get the compiled execution DAG for a script. If versionId is omitted, uses the draft. */
|
|
250
|
+
async getGraph(scriptName, opts) {
|
|
251
|
+
const params = new URLSearchParams();
|
|
252
|
+
if (opts?.versionId != null)
|
|
253
|
+
params.set('version', String(opts.versionId));
|
|
254
|
+
const qs = params.toString();
|
|
255
|
+
return (await this.http.fetchOk(`${this.path(scriptName, 'graph')}${qs ? `?${qs}` : ''}`, { signal: opts?.signal })).json();
|
|
256
|
+
}
|
|
257
|
+
/** Get cost aggregation for the entire project, optionally filtered by date range.
|
|
258
|
+
* Rolls up: per-script totals, per-channel totals, and overall totals.
|
|
259
|
+
* `unknown_cost_executions` counts runs whose model wasn't in the pricing
|
|
260
|
+
* table; their tokens are still included, but they contribute `0` to cost.
|
|
261
|
+
*/
|
|
262
|
+
async getProjectCost(opts) {
|
|
263
|
+
const params = new URLSearchParams();
|
|
264
|
+
if (opts?.since)
|
|
265
|
+
params.set('since', opts.since);
|
|
266
|
+
if (opts?.until)
|
|
267
|
+
params.set('until', opts.until);
|
|
268
|
+
const qs = params.toString();
|
|
269
|
+
return (await this.http.fetchOk(`${this.http.getBaseUrl()}/projects/${this.projectId}/cost${qs ? `?${qs}` : ''}`, { signal: opts?.signal })).json();
|
|
270
|
+
}
|
|
271
|
+
/** Get cost aggregation for a script (total, avg, per-version, per-channel). */
|
|
272
|
+
async getCost(scriptName, opts) {
|
|
273
|
+
const params = new URLSearchParams();
|
|
274
|
+
if (opts?.since)
|
|
275
|
+
params.set('since', opts.since);
|
|
276
|
+
if (opts?.until)
|
|
277
|
+
params.set('until', opts.until);
|
|
278
|
+
const qs = params.toString();
|
|
279
|
+
return (await this.http.fetchOk(`${this.path(scriptName, 'cost')}${qs ? `?${qs}` : ''}`, { signal: opts?.signal })).json();
|
|
280
|
+
}
|
|
281
|
+
/** Run a script and wait for the result. Returns [execution_id, output]. */
|
|
282
|
+
async runAndAwait(scriptName, opts) {
|
|
283
|
+
const { execution_id } = await this.run(scriptName, opts);
|
|
284
|
+
const output = await this.waitFor(execution_id, opts);
|
|
285
|
+
return [execution_id, output];
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Start a run and return a {@link RunStream} lifecycle handle. The stream
|
|
289
|
+
* subscribes to events BEFORE issuing the run POST so no early events are
|
|
290
|
+
* missed. It's async-iterable, exposes `.output` / `.executionId` promises,
|
|
291
|
+
* and offers category-based `.on.<cat>()` callback registration.
|
|
292
|
+
*
|
|
293
|
+
* Requires the client was constructed with a `projectId` so the events
|
|
294
|
+
* sub-client is available.
|
|
295
|
+
*/
|
|
296
|
+
runStream(scriptName, opts) {
|
|
297
|
+
if (!this.eventsSourceFactory) {
|
|
298
|
+
throw new Error('runStream() requires the EventsClient to be wired. Construct AkribesClient with a projectId.');
|
|
299
|
+
}
|
|
300
|
+
this.validateContract(scriptName);
|
|
301
|
+
return createRunStream(scriptName, opts, this.eventsSourceFactory(), (name, o) => this.run(name, o));
|
|
302
|
+
}
|
|
303
|
+
// ── Document helpers ──────────────────────────────────────────────────
|
|
304
|
+
/** Get document metadata by ID. */
|
|
305
|
+
async getDocument(documentId, opts) {
|
|
306
|
+
return nullOn404(async () => (await this.http.fetchOk(`${this.http.getBaseUrl()}/documents/${encodeURIComponent(documentId)}`, opts)).json());
|
|
307
|
+
}
|
|
308
|
+
/** Get converted markdown for a document. */
|
|
309
|
+
async getDocumentMarkdown(documentId, opts) {
|
|
310
|
+
return (await this.http.fetchOk(`${this.http.getBaseUrl()}/documents/${encodeURIComponent(documentId)}/markdown`, opts)).json();
|
|
311
|
+
}
|
|
312
|
+
/** Get a presigned download URL for the original document file. */
|
|
313
|
+
async getDocumentUrl(documentId, opts) {
|
|
314
|
+
const resp = await this.http.fetchOk(`${this.http.getBaseUrl()}/documents/${encodeURIComponent(documentId)}/content`, { ...opts, redirect: 'manual' });
|
|
315
|
+
return resp.headers.get('location') || resp.url;
|
|
316
|
+
}
|
|
317
|
+
/** Retry conversion on a failed document. */
|
|
318
|
+
async reconvertDocument(documentId, opts) {
|
|
319
|
+
return (await this.http.fetchOk(`${this.http.getBaseUrl()}/documents/${encodeURIComponent(documentId)}/convert`, { method: 'POST', signal: opts?.signal })).json();
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
//# sourceMappingURL=executions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executions.js","sourceRoot":"","sources":["../../src/sub/executions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAGxI,OAAO,EAAE,eAAe,EAAqE,MAAM,cAAc,CAAC;AAsClH,sEAAsE;AACtE,MAAM,wBAAwB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAE/C,0DAA0D;AAC1D,SAAS,iBAAiB,CAAC,EAAU,EAAE,MAAoB;IACzD,IAAI,MAAM,EAAE,OAAO;QAAE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC9C,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QACnC,MAAM,CAAC,GAAG,UAAU,CAAC,GAAG,EAAE;YACxB,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC9C,OAAO,EAAE,CAAC;QACZ,CAAC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AAkB,CAAC,UAAU,CAAC,WAAW,EAAE,IAAI,CACvF,CAAC,CAAC,IAAI,EAAE,CAAC;IACZ,CAAC;IAED,mEAAmE;IACnE,KAAK,CAAC,cAAc,CAAC,UAAkB,EAAE,IAA+B;QACtE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAClC,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,kBAAkB,CAAC,UAAU,CAAC,UAAU,EAC/E,EAAE,GAAG,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAChC,CAAC;QACF,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC;IAClD,CAAC;IAED,6CAA6C;IAC7C,KAAK,CAAC,iBAAiB,CAAC,UAAkB,EAAE,IAA+B;QACzE,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAC7B,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,kBAAkB,CAAC,UAAU,CAAC,UAAU,EAC/E,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CACzC,CAAC,CAAC,IAAI,EAAE,CAAC;IACZ,CAAC;CACF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { HttpClient } from '../http';
|
|
2
|
+
import type { McpServerSummary, McpToolSummary } from '../types';
|
|
3
|
+
export type McpHealth = {
|
|
4
|
+
status: 'connected' | 'degraded' | 'offline' | 'pinned_offline';
|
|
5
|
+
last_error?: string;
|
|
6
|
+
last_check_at?: string;
|
|
7
|
+
};
|
|
8
|
+
/** Response from `POST /projects/{id}/mcp/servers/{alias}/refresh`. */
|
|
9
|
+
export type McpRefreshResult = {
|
|
10
|
+
refreshed: boolean;
|
|
11
|
+
alias: string;
|
|
12
|
+
tool_count: number;
|
|
13
|
+
};
|
|
14
|
+
/** Response from `GET /projects/{id}/mcp/servers/{alias}/drift`. */
|
|
15
|
+
export type McpDriftResult = {
|
|
16
|
+
drifted: boolean;
|
|
17
|
+
added: string[];
|
|
18
|
+
removed: string[];
|
|
19
|
+
reason?: string;
|
|
20
|
+
};
|
|
21
|
+
export declare class McpClient {
|
|
22
|
+
private http;
|
|
23
|
+
private projectId;
|
|
24
|
+
constructor(http: HttpClient, projectId: number);
|
|
25
|
+
private base;
|
|
26
|
+
listServers(opts?: {
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
}): Promise<McpServerSummary[]>;
|
|
29
|
+
listTools(opts?: {
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
}): Promise<McpToolSummary[]>;
|
|
32
|
+
health(alias: string, opts?: {
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
}): Promise<McpHealth>;
|
|
35
|
+
/**
|
|
36
|
+
* Force a fresh `tools/list` against the remote MCP server and update the
|
|
37
|
+
* pinned schema in the DB. Returns the new tool count.
|
|
38
|
+
*/
|
|
39
|
+
refresh(alias: string, opts?: {
|
|
40
|
+
signal?: AbortSignal;
|
|
41
|
+
}): Promise<McpRefreshResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Compare the pinned schema against the remote server's live `tools/list`
|
|
44
|
+
* and report added/removed tool names. The server populates `added` and
|
|
45
|
+
* `removed` arrays even when nothing has drifted (both empty in that case).
|
|
46
|
+
*/
|
|
47
|
+
drift(alias: string, opts?: {
|
|
48
|
+
signal?: AbortSignal;
|
|
49
|
+
}): Promise<McpDriftResult>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=mcp.d.ts.map
|