@flytedesk/app-kit 7.6.0 → 9.0.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 +49 -10
- package/dist/auth/client/authSession.d.ts +6 -0
- package/dist/auth/client/authSession.js +34 -10
- package/dist/auth/client/authSession.js.map +1 -1
- package/dist/auth/client/httpClient.d.ts +1 -3
- package/dist/auth/client/httpClient.js +4 -3
- package/dist/auth/client/httpClient.js.map +1 -1
- package/dist/bigquery/client.d.ts +3 -0
- package/dist/bigquery/client.js +2 -0
- package/dist/bigquery/client.js.map +1 -1
- package/dist/bigquery/errors.d.ts +60 -8
- package/dist/bigquery/errors.js +221 -22
- package/dist/bigquery/errors.js.map +1 -1
- package/dist/bigquery/index.d.ts +7 -3
- package/dist/bigquery/index.js +3 -2
- package/dist/bigquery/index.js.map +1 -1
- package/dist/bigquery/insert.d.ts +10 -0
- package/dist/bigquery/insert.js +22 -0
- package/dist/bigquery/insert.js.map +1 -0
- package/dist/bigquery/jobIdentity.d.ts +39 -0
- package/dist/bigquery/jobIdentity.js +83 -0
- package/dist/bigquery/jobIdentity.js.map +1 -0
- package/dist/bigquery/load.d.ts +11 -14
- package/dist/bigquery/load.js +132 -56
- package/dist/bigquery/load.js.map +1 -1
- package/dist/bigquery/query.d.ts +19 -1
- package/dist/bigquery/query.js +143 -48
- package/dist/bigquery/query.js.map +1 -1
- package/dist/bigquery/retry.d.ts +56 -0
- package/dist/bigquery/retry.js +110 -0
- package/dist/bigquery/retry.js.map +1 -0
- package/dist/bigquery/types.d.ts +51 -5
- package/dist/bigquery/values.d.ts +3 -0
- package/dist/bigquery/values.js +5 -0
- package/dist/bigquery/values.js.map +1 -1
- package/dist/chat/callback-secret.js +6 -1
- package/dist/chat/callback-secret.js.map +1 -1
- package/dist/chat/env.js.map +1 -1
- package/dist/chat/index.d.ts +8 -4
- package/dist/chat/index.js +7 -3
- package/dist/chat/index.js.map +1 -1
- package/dist/chat/job-status.js +10 -3
- package/dist/chat/job-status.js.map +1 -1
- package/dist/chat/launcher.d.ts +3 -4
- package/dist/chat/launcher.js +21 -29
- package/dist/chat/launcher.js.map +1 -1
- package/dist/chat/mcp-protocol.js +45 -13
- package/dist/chat/mcp-protocol.js.map +1 -1
- package/dist/chat/mcp-server.js +6 -2
- package/dist/chat/mcp-server.js.map +1 -1
- package/dist/chat/types.d.ts +8 -12
- package/package.json +1 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export interface RetryOptions {
|
|
2
|
+
/** Total attempts before giving up, including the first, counted across every
|
|
3
|
+
* step of the call (creating the job, checking it, resubmitting it). A
|
|
4
|
+
* positive integer; default 5. Pass 1 for a call that must never be
|
|
5
|
+
* repeated. */
|
|
6
|
+
attempts?: number;
|
|
7
|
+
/** Delay before the first retry; doubles every subsequent retry. Default 1000ms. */
|
|
8
|
+
initialDelayMs?: number;
|
|
9
|
+
/** Injectable for tests — real code always uses a real timer. */
|
|
10
|
+
sleep?: (ms: number) => Promise<void>;
|
|
11
|
+
/** Injectable clock (ms) for tests — real code always uses `Date.now`. */
|
|
12
|
+
now?: () => number;
|
|
13
|
+
}
|
|
14
|
+
/** One call's retry state: the attempts used so far and the time left. */
|
|
15
|
+
export declare class RetryPolicy {
|
|
16
|
+
private readonly what;
|
|
17
|
+
private readonly attempts;
|
|
18
|
+
private readonly initialDelayMs;
|
|
19
|
+
private readonly sleep;
|
|
20
|
+
private readonly now;
|
|
21
|
+
private readonly startedAt;
|
|
22
|
+
private readonly budgetMs;
|
|
23
|
+
private tried;
|
|
24
|
+
private lastTransient;
|
|
25
|
+
/** `budgetMs` is the TOTAL time the whole call may take, backoffs included. */
|
|
26
|
+
constructor(options: RetryOptions, what: string, budgetMs?: number);
|
|
27
|
+
/** Milliseconds of the budget still unspent, rounded up (the whole budget
|
|
28
|
+
* while the clock has not moved), or `undefined` when the call has no
|
|
29
|
+
* budget. Never negative. */
|
|
30
|
+
remainingMs(): number | undefined;
|
|
31
|
+
/** Starts an attempt: counts it and returns the budget left for it
|
|
32
|
+
* (`undefined` when the call has none). Never starts one with no time left:
|
|
33
|
+
* that gives up with the last transient error, or a `JobTimeoutError` when
|
|
34
|
+
* there was none. */
|
|
35
|
+
begin(): number | undefined;
|
|
36
|
+
/** The budget still unspent for a request inside an attempt, or throws when it
|
|
37
|
+
* is gone, so no request is sent with a zero wait. `undefined` when the call
|
|
38
|
+
* has no budget. */
|
|
39
|
+
timeLeft(): number | undefined;
|
|
40
|
+
private giveUp;
|
|
41
|
+
/**
|
|
42
|
+
* Called after an attempt failed with a transient `err` the caller has
|
|
43
|
+
* decided to retry: waits (doubling backoff, never past the budget) so the
|
|
44
|
+
* caller can `begin()` the next attempt. Throws the classified error, with
|
|
45
|
+
* the attempt count, when no attempt is left. When the budget runs out, the
|
|
46
|
+
* backoff is clamped to what is left and the next `begin()` gives up.
|
|
47
|
+
*/
|
|
48
|
+
retryAfter(err: unknown): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Runs `step` (one whole attempt, handed the budget left), retrying it while
|
|
51
|
+
* it fails with an error `shouldRetry` accepts and attempts and budget
|
|
52
|
+
* remain. Any other error is classified and thrown on the attempt that raised
|
|
53
|
+
* it.
|
|
54
|
+
*/
|
|
55
|
+
run<T>(step: (remainingMs: number | undefined) => Promise<T>, shouldRetry: (err: unknown) => boolean): Promise<T>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one bounded retry of every BigQuery call this module runs (queries, dry
|
|
3
|
+
* runs and load jobs): exponential backoff, a fixed number of attempts shared
|
|
4
|
+
* by every step of one call, and an optional ONE total time budget for the
|
|
5
|
+
* whole call. What may be retried is the caller's predicate for each step
|
|
6
|
+
* (see `isJobLevelFailure`, `isTransientRequestError` in ./errors.js): a
|
|
7
|
+
* request about an existing job is asked again, a job is resubmitted only when
|
|
8
|
+
* the job itself failed or was never created.
|
|
9
|
+
*/
|
|
10
|
+
import { BadQueryError, classifyBigQueryError, JobTimeoutError, } from "./errors.js";
|
|
11
|
+
const DEFAULT_ATTEMPTS = 5;
|
|
12
|
+
const DEFAULT_INITIAL_DELAY_MS = 1_000;
|
|
13
|
+
function defaultSleep(ms) {
|
|
14
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
15
|
+
}
|
|
16
|
+
/** One call's retry state: the attempts used so far and the time left. */
|
|
17
|
+
export class RetryPolicy {
|
|
18
|
+
what;
|
|
19
|
+
attempts;
|
|
20
|
+
initialDelayMs;
|
|
21
|
+
sleep;
|
|
22
|
+
now;
|
|
23
|
+
startedAt;
|
|
24
|
+
budgetMs;
|
|
25
|
+
tried = 0;
|
|
26
|
+
lastTransient;
|
|
27
|
+
/** `budgetMs` is the TOTAL time the whole call may take, backoffs included. */
|
|
28
|
+
constructor(options, what, budgetMs) {
|
|
29
|
+
this.what = what;
|
|
30
|
+
const attempts = options.attempts ?? DEFAULT_ATTEMPTS;
|
|
31
|
+
if (!Number.isInteger(attempts) || attempts < 1) {
|
|
32
|
+
throw new BadQueryError(`${what}: attempts must be a positive integer (got ${String(attempts)})`);
|
|
33
|
+
}
|
|
34
|
+
this.attempts = attempts;
|
|
35
|
+
this.initialDelayMs = options.initialDelayMs ?? DEFAULT_INITIAL_DELAY_MS;
|
|
36
|
+
this.sleep = options.sleep ?? defaultSleep;
|
|
37
|
+
this.now = options.now ?? Date.now;
|
|
38
|
+
this.startedAt = this.now();
|
|
39
|
+
this.budgetMs = budgetMs;
|
|
40
|
+
}
|
|
41
|
+
/** Milliseconds of the budget still unspent, rounded up (the whole budget
|
|
42
|
+
* while the clock has not moved), or `undefined` when the call has no
|
|
43
|
+
* budget. Never negative. */
|
|
44
|
+
remainingMs() {
|
|
45
|
+
if (this.budgetMs === undefined)
|
|
46
|
+
return undefined;
|
|
47
|
+
const elapsed = Math.max(0, this.now() - this.startedAt);
|
|
48
|
+
return Math.max(0, Math.ceil(this.budgetMs - elapsed));
|
|
49
|
+
}
|
|
50
|
+
/** Starts an attempt: counts it and returns the budget left for it
|
|
51
|
+
* (`undefined` when the call has none). Never starts one with no time left:
|
|
52
|
+
* that gives up with the last transient error, or a `JobTimeoutError` when
|
|
53
|
+
* there was none. */
|
|
54
|
+
begin() {
|
|
55
|
+
this.timeLeft();
|
|
56
|
+
this.tried += 1;
|
|
57
|
+
return this.remainingMs();
|
|
58
|
+
}
|
|
59
|
+
/** The budget still unspent for a request inside an attempt, or throws when it
|
|
60
|
+
* is gone, so no request is sent with a zero wait. `undefined` when the call
|
|
61
|
+
* has no budget. */
|
|
62
|
+
timeLeft() {
|
|
63
|
+
const remaining = this.remainingMs();
|
|
64
|
+
if (remaining !== 0)
|
|
65
|
+
return remaining;
|
|
66
|
+
if (this.lastTransient !== undefined) {
|
|
67
|
+
throw this.giveUp(this.lastTransient, "time budget spent");
|
|
68
|
+
}
|
|
69
|
+
throw new JobTimeoutError(this.budgetMs ?? 0);
|
|
70
|
+
}
|
|
71
|
+
giveUp(err, reason) {
|
|
72
|
+
const classified = classifyBigQueryError(err);
|
|
73
|
+
const Ctor = classified.constructor;
|
|
74
|
+
return new Ctor(`${classified.message} (gave up after ${this.tried} attempt${this.tried === 1 ? "" : "s"}: ${reason})`, classified.cause ?? err);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Called after an attempt failed with a transient `err` the caller has
|
|
78
|
+
* decided to retry: waits (doubling backoff, never past the budget) so the
|
|
79
|
+
* caller can `begin()` the next attempt. Throws the classified error, with
|
|
80
|
+
* the attempt count, when no attempt is left. When the budget runs out, the
|
|
81
|
+
* backoff is clamped to what is left and the next `begin()` gives up.
|
|
82
|
+
*/
|
|
83
|
+
async retryAfter(err) {
|
|
84
|
+
this.lastTransient = err;
|
|
85
|
+
if (this.tried >= this.attempts)
|
|
86
|
+
throw this.giveUp(err, "no attempts left");
|
|
87
|
+
const delayMs = Math.min(this.initialDelayMs * 2 ** (this.tried - 1), this.remainingMs() ?? Number.POSITIVE_INFINITY);
|
|
88
|
+
console.warn(`[bigquery/retry] ${this.what}: ${classifyBigQueryError(err).name} on attempt ${this.tried}/${this.attempts}, retrying in ${delayMs}ms`);
|
|
89
|
+
await this.sleep(delayMs);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Runs `step` (one whole attempt, handed the budget left), retrying it while
|
|
93
|
+
* it fails with an error `shouldRetry` accepts and attempts and budget
|
|
94
|
+
* remain. Any other error is classified and thrown on the attempt that raised
|
|
95
|
+
* it.
|
|
96
|
+
*/
|
|
97
|
+
async run(step, shouldRetry) {
|
|
98
|
+
for (;;) {
|
|
99
|
+
try {
|
|
100
|
+
return await step(this.begin());
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
if (!shouldRetry(err))
|
|
104
|
+
throw classifyBigQueryError(err);
|
|
105
|
+
await this.retryAfter(err);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/bigquery/retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EACL,aAAa,EACb,qBAAqB,EACrB,eAAe,GAChB,MAAM,aAAa,CAAC;AAiBrB,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAM,wBAAwB,GAAG,KAAK,CAAC;AAEvC,SAAS,YAAY,CAAC,EAAU;IAC9B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC;AAOD,0EAA0E;AAC1E,MAAM,OAAO,WAAW;IAaH;IAZF,QAAQ,CAAS;IACjB,cAAc,CAAS;IACvB,KAAK,CAAgC;IACrC,GAAG,CAAe;IAClB,SAAS,CAAS;IAClB,QAAQ,CAAqB;IACtC,KAAK,GAAG,CAAC,CAAC;IACV,aAAa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AC,IAAI,KAAK,qBAAqB,CAAC,GAAG,CAAC,CAAC,IAAI,eAAe,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,QAAQ,iBAAiB,OAAO,IAAI,CACxI,CAAC;QACF,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAG,CACP,IAAqD,EACrD,WAAsC;QAEtC,SAAS,CAAC;YACR,IAAI,CAAC;gBACH,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;YAClC,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC;oBAAE,MAAM,qBAAqB,CAAC,GAAG,CAAC,CAAC;gBACxD,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;YAC7B,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
package/dist/bigquery/types.d.ts
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* in media-planner.
|
|
13
13
|
*/
|
|
14
14
|
import type { Writable } from "node:stream";
|
|
15
|
+
import type { RetryOptions } from "./retry.js";
|
|
15
16
|
/** One structured error entry, same shape the Google APIs client library
|
|
16
17
|
* attaches to a rejected job promise's `.errors` array. */
|
|
17
18
|
export interface BigQueryApiErrorDetail {
|
|
@@ -47,6 +48,9 @@ export interface BigQueryRawSchema {
|
|
|
47
48
|
fields?: BigQueryRawSchemaField[];
|
|
48
49
|
}
|
|
49
50
|
export interface BigQueryJobStatistics {
|
|
51
|
+
load?: {
|
|
52
|
+
outputRows?: string;
|
|
53
|
+
};
|
|
50
54
|
query?: {
|
|
51
55
|
totalBytesProcessed?: string | number;
|
|
52
56
|
totalBytesBilled?: string | number;
|
|
@@ -73,6 +77,9 @@ export interface BigQueryJobMetadata {
|
|
|
73
77
|
export interface BigQueryQueryResultsOptions {
|
|
74
78
|
maxResults?: number;
|
|
75
79
|
pageToken?: string;
|
|
80
|
+
/** Client-side wait deadline: the SDK's `getQueryResults` rejects with "The
|
|
81
|
+
* query did not complete before Nms" instead of polling forever. */
|
|
82
|
+
timeoutMs?: number;
|
|
76
83
|
}
|
|
77
84
|
/** The next-page cursor `Job#getQueryResults` hands back as its second tuple
|
|
78
85
|
* element — `null` once there are no more pages. */
|
|
@@ -80,12 +87,18 @@ export type BigQueryNextQuery = {
|
|
|
80
87
|
pageToken?: string;
|
|
81
88
|
} | null;
|
|
82
89
|
export interface BigQueryJobLike {
|
|
90
|
+
/** The location BigQuery created the job in (the real `Job#location`). */
|
|
91
|
+
location?: string;
|
|
83
92
|
/** `@google-cloud/bigquery`'s real `Job#id` is itself `string | undefined`
|
|
84
93
|
* (inherited from its generic Operation base) — present in practice once a
|
|
85
94
|
* job has actually been created, but the SDK's own type never guarantees
|
|
86
95
|
* it. Callers fall back to `""` rather than assume non-null. */
|
|
87
96
|
id?: string;
|
|
88
97
|
getMetadata(): Promise<[BigQueryJobMetadata, unknown]>;
|
|
98
|
+
/** Resolves when the job is done; rejects with the job's error if it failed.
|
|
99
|
+
* The load helpers use it on a handle from `BigQueryLike#job` to wait on an
|
|
100
|
+
* existing load job again. */
|
|
101
|
+
promise?(): Promise<unknown>;
|
|
89
102
|
/** `@google-cloud/bigquery`'s real `Job#getQueryResults` return type varies
|
|
90
103
|
* in tuple length by overload (a plain `[rows]` when there is nothing else
|
|
91
104
|
* to report, up to `[rows, nextQuery, apiResponse]`) — accept any prefix of
|
|
@@ -196,7 +209,19 @@ export interface BigQueryLoadOptions {
|
|
|
196
209
|
writeDisposition?: "WRITE_TRUNCATE" | "WRITE_APPEND" | "WRITE_EMPTY";
|
|
197
210
|
createDisposition?: "CREATE_IF_NEEDED" | "CREATE_NEVER";
|
|
198
211
|
labels?: Record<string, string>;
|
|
212
|
+
/** The id the load job is submitted under, reused by every retry of the call
|
|
213
|
+
* (a random one when omitted). Submitting an id that already exists does not
|
|
214
|
+
* fail: the load helpers wait on that job and report ITS result, loading
|
|
215
|
+
* nothing again. */
|
|
199
216
|
jobId?: string;
|
|
217
|
+
/** The location of the dataset and the load job. BigQuery jobs are per
|
|
218
|
+
* location, so finding the job again after a failed submission needs it for
|
|
219
|
+
* data outside the US and EU multi-regions. */
|
|
220
|
+
location?: string;
|
|
221
|
+
}
|
|
222
|
+
export interface BigQueryInsertOptions {
|
|
223
|
+
skipInvalidRows: boolean;
|
|
224
|
+
ignoreUnknownValues: boolean;
|
|
200
225
|
}
|
|
201
226
|
export interface BigQueryTableLike {
|
|
202
227
|
createExtractJob(destination: GcsFileLike, options?: BigQueryExtractOptions): Promise<[BigQueryJobLike, BigQueryJobMetadata]>;
|
|
@@ -209,12 +234,19 @@ export interface BigQueryTableLike {
|
|
|
209
234
|
* need it — only `loadRowsWithRetry` (./load.js) does, and it fails loudly
|
|
210
235
|
* if missing. */
|
|
211
236
|
createWriteStream?(options: BigQueryLoadOptions): Writable;
|
|
237
|
+
/** Streaming insert, mirroring `@google-cloud/bigquery`'s `Table#insert`.
|
|
238
|
+
* Rejects with a `PartialFailureError` when rows are rejected. Optional:
|
|
239
|
+
* only `insertRows` (./insert.js) needs it, and it fails loudly if missing. */
|
|
240
|
+
insert?(rows: readonly object[], options: BigQueryInsertOptions): Promise<unknown>;
|
|
212
241
|
}
|
|
213
242
|
export interface BigQueryDatasetLike {
|
|
214
243
|
table(id: string): BigQueryTableLike;
|
|
215
244
|
}
|
|
216
245
|
/** A submitted load job, as `BigQuery#createJob` resolves it. */
|
|
217
246
|
export interface BigQueryLoadJobLike {
|
|
247
|
+
/** The location BigQuery created the job in. BigQuery jobs are per location,
|
|
248
|
+
* so the load helpers keep it to find the job again. */
|
|
249
|
+
location?: string;
|
|
218
250
|
/** Resolves when the job is done; rejects with the job's error if it failed. */
|
|
219
251
|
promise(): Promise<unknown>;
|
|
220
252
|
getMetadata(): Promise<readonly [{
|
|
@@ -232,14 +264,22 @@ export interface BigQueryLike {
|
|
|
232
264
|
* missing. Mirrors `@google-cloud/bigquery`'s `BigQuery#createJob`. */
|
|
233
265
|
createJob?(options: {
|
|
234
266
|
configuration: Record<string, unknown>;
|
|
267
|
+
/** The id to submit the job under (the SDK honours it). */
|
|
268
|
+
jobId?: string;
|
|
269
|
+
/** The location to create the job in (the SDK honours it). */
|
|
270
|
+
location?: string;
|
|
235
271
|
}): Promise<readonly [BigQueryLoadJobLike, ...unknown[]]>;
|
|
236
272
|
createQueryJob(options: BigQueryCreateQueryJobOptions): Promise<[BigQueryJobLike, BigQueryJobMetadata]>;
|
|
237
|
-
dataset(id: string
|
|
273
|
+
dataset(id: string, options?: {
|
|
274
|
+
location?: string;
|
|
275
|
+
}): BigQueryDatasetLike;
|
|
238
276
|
/** Looks up an already-submitted job by id — used to poll extract-job status
|
|
239
277
|
* independently of the handle returned at submission time. */
|
|
240
|
-
job(id: string
|
|
278
|
+
job(id: string, options?: {
|
|
279
|
+
location?: string;
|
|
280
|
+
}): BigQueryJobLike;
|
|
241
281
|
}
|
|
242
|
-
export interface RunQueryOptions {
|
|
282
|
+
export interface RunQueryOptions extends RetryOptions {
|
|
243
283
|
/** The parameterised SQL. Always use `params`/`types` for user-supplied
|
|
244
284
|
* values — never string-interpolate them into `sql`. */
|
|
245
285
|
sql: string;
|
|
@@ -257,7 +297,9 @@ export interface RunQueryOptions {
|
|
|
257
297
|
* it a token it never issued (AK-26). */
|
|
258
298
|
pageToken?: string;
|
|
259
299
|
/** The job that produced `pageToken` — required together with it to fetch
|
|
260
|
-
* the next page of that same job instead of starting a new one.
|
|
300
|
+
* the next page of that same job instead of starting a new one. Without a
|
|
301
|
+
* `pageToken` it is the id the new job is submitted under (a random one when
|
|
302
|
+
* omitted), reused by every retry of the call. */
|
|
261
303
|
jobId?: string;
|
|
262
304
|
/** Hard cap BigQuery itself enforces on the real job — a job that would
|
|
263
305
|
* bill more than this many bytes is refused by BigQuery before running,
|
|
@@ -282,10 +324,14 @@ export interface RunQueryOptions {
|
|
|
282
324
|
export interface QueryPage<T = Record<string, unknown>> {
|
|
283
325
|
rows: T[];
|
|
284
326
|
jobId: string;
|
|
327
|
+
/** The location the job runs in, as BigQuery reports it (else the one
|
|
328
|
+
* requested). Pass it back as `RunQueryOptions.location` with `pageToken` to
|
|
329
|
+
* fetch a later page: BigQuery jobs are per location. `runQueryAllPages` does. */
|
|
330
|
+
location?: string;
|
|
285
331
|
/** Present when another page is available. */
|
|
286
332
|
nextPageToken?: string;
|
|
287
333
|
}
|
|
288
|
-
export interface EstimateQueryBytesOptions {
|
|
334
|
+
export interface EstimateQueryBytesOptions extends RetryOptions {
|
|
289
335
|
sql: string;
|
|
290
336
|
params?: unknown[] | Record<string, unknown>;
|
|
291
337
|
/** Declared BigQuery parameter types — see `BigQueryParamTypes`. */
|
|
@@ -16,3 +16,6 @@ export declare function unwrapBigQueryValue(value: unknown): unknown;
|
|
|
16
16
|
* results, which the client library may hand back as a NUMERIC wrapper
|
|
17
17
|
* rather than a plain number. Missing/unparseable values become 0. */
|
|
18
18
|
export declare function unwrapBigQueryCount(value: unknown): number;
|
|
19
|
+
/** Applies `unwrapBigQueryValue` to every field of a result row, returning a
|
|
20
|
+
* new object. */
|
|
21
|
+
export declare function unwrapBigQueryRow(row: Record<string, unknown>): Record<string, unknown>;
|
package/dist/bigquery/values.js
CHANGED
|
@@ -33,4 +33,9 @@ export function unwrapBigQueryCount(value) {
|
|
|
33
33
|
const num = typeof raw === "number" ? raw : Number(raw ?? 0);
|
|
34
34
|
return Number.isFinite(num) ? num : 0;
|
|
35
35
|
}
|
|
36
|
+
/** Applies `unwrapBigQueryValue` to every field of a result row, returning a
|
|
37
|
+
* new object. */
|
|
38
|
+
export function unwrapBigQueryRow(row) {
|
|
39
|
+
return Object.fromEntries(Object.entries(row).map(([k, v]) => [k, unwrapBigQueryValue(v)]));
|
|
40
|
+
}
|
|
36
41
|
//# sourceMappingURL=values.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"values.js","sourceRoot":"","sources":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U,EAC/D,CAAC;YACD,OAAQ,KAAgC,CAAC,QAAQ,EAAE,CAAC;QACtD,CAAC;QACD,IAAI,OAAO,IAAI,KAAK,EAAE,CAAC;YACrB,OAAQ,KAA4B,CAAC,KAAK,CAAC;QAC7C,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;uEAGuE;AACvE,MAAM,UAAU,mBAAmB,CAAC,KAAc;IAChD,MAAM,GAAG,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;IACvC,MAAM,GAAG,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IAC7D,OAAO,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACxC,CAAC;AAED;kBACkB;AAClB,MAAM,UAAU,iBAAiB,CAC/B,GAA4B;IAE5B,OAAO,MAAM,CAAC,WAAW,CACvB,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,CACjE,CAAC;AACJ,CAAC"}
|
|
@@ -24,7 +24,12 @@ export function requireCallbackSecret(expectedSecret) {
|
|
|
24
24
|
const header = request.headers.authorization;
|
|
25
25
|
if (!header?.startsWith(BEARER_PREFIX) ||
|
|
26
26
|
!callbackSecretMatches(expectedSecret, header.slice(BEARER_PREFIX.length))) {
|
|
27
|
-
reply
|
|
27
|
+
reply
|
|
28
|
+
.code(401)
|
|
29
|
+
.send({
|
|
30
|
+
error: "Invalid callback credentials",
|
|
31
|
+
code: "unauthenticated",
|
|
32
|
+
});
|
|
28
33
|
return;
|
|
29
34
|
}
|
|
30
35
|
done();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callback-secret.js","sourceRoot":"","sources":["../../src/chat/callback-secret.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,aAAa,GAAG,SAAS,CAAC;AAEhC;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,
|
|
1
|
+
{"version":3,"file":"callback-secret.js","sourceRoot":"","sources":["../../src/chat/callback-secret.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,aAAa,GAAG,SAAS,CAAC;AAEhC;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAAgB,EAChB,SAAiB;IAEjB,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACxC,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACzC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAC1D,OAAO,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAC/B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CACnC,cAAsB;IAEtB,OAAO,SAAS,wBAAwB,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI;QAC3D,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC;QAC7C,IACE,CAAC,MAAM,EAAE,UAAU,CAAC,aAAa,CAAC;YAClC,CAAC,qBAAqB,CAAC,cAAc,EAAE,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,EAC1E,CAAC;YACD,KAAK;iBACF,IAAI,CAAC,GAAG,CAAC;iBACT,IAAI,CAAC;gBACJ,KAAK,EAAE,8BAA8B;gBACrC,IAAI,EAAE,iBAAiB;aACxB,CAAC,CAAC;YACL,OAAO;QACT,CAAC;QACD,IAAI,EAAE,CAAC;IACT,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/chat/env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/chat/env.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,YAAY,
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/chat/env.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,YAAY,CAC1B,MAA0C;IAE1C,MAAM,OAAO,GAAG,MAAM,CAAC,gBAAgB,CAAC;IACxC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,YAAY,CACpB,sFAAsF,CACvF,CAAC;IACJ,CAAC;IACD,MAAM,cAAc,GAAG,MAAM,CAAC,wBAAwB,CAAC;IACvD,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,IAAI,YAAY,CACpB,2GAA2G,CAC5G,CAAC;IACJ,CAAC;IACD,OAAO;QACL,iFAAiF;QACjF,wEAAwE;QACxE,6EAA6E;QAC7E,6EAA6E;QAC7E,aAAa,EAAE,MAAM,CAAC,eAAe,IAAI,uBAAuB;QAChE,cAAc,EAAE,OAAO;QACvB,eAAe,EAAE,MAAM,CAAC,iBAAiB,IAAI,EAAE;QAC/C,qBAAqB,EAAE,cAAc;QACrC,qBAAqB,EAAE,MAAM,CAAC,uBAAuB,IAAI,EAAE;KAC5D,CAAC;AACJ,CAAC"}
|
package/dist/chat/index.d.ts
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Four pieces, usable independently or together:
|
|
9
9
|
*
|
|
10
|
-
* - `createDanxbotLauncher` —
|
|
11
|
-
*
|
|
10
|
+
* - `createDanxbotLauncher` — launch or resume a danxbot agent session with
|
|
11
|
+
* `dispatch`; its end is reported to a URL
|
|
12
12
|
* (`parseJobStatusReport`, `isTerminalJobStatus`, `isFailedJobStatus`).
|
|
13
13
|
* - `createChatMcpProtocol` + `createReplyTool` — the MCP server the dispatched
|
|
14
14
|
* agent talks to the user through, with an extension point for app-registered
|
|
@@ -32,8 +32,12 @@
|
|
|
32
32
|
* profile: "audience-chat",
|
|
33
33
|
* });
|
|
34
34
|
*
|
|
35
|
-
* const { jobId } = await launcher.
|
|
35
|
+
* const { jobId } = await launcher.dispatch({
|
|
36
36
|
* task: prompt,
|
|
37
|
+
* statusUrl: `${publicApiUrl}/chat/turns/${turn.id}/status`,
|
|
38
|
+
* apiToken: turnToken,
|
|
39
|
+
* maxRuntimeMs: 30 * 60_000,
|
|
40
|
+
* title: "Audience chat",
|
|
37
41
|
* overlay: { TURN_ID: turn.id, API_URL: chatEnv.danxbotCallbackApiUrl, CALLBACK_SECRET: chatEnv.danxbotCallbackSecret },
|
|
38
42
|
* });
|
|
39
43
|
*
|
|
@@ -100,7 +104,7 @@ export { callbackSecretMatches, requireCallbackSecret, } from "./callback-secret
|
|
|
100
104
|
export { createChatMcpProtocol, createReplyTool, parseReplyArguments, FALLBACK_PROTOCOL_VERSION, JSON_RPC, } from "./mcp-protocol.js";
|
|
101
105
|
export { createChatMcpStdioServer } from "./mcp-server.js";
|
|
102
106
|
export { parseChatEnv, ChatEnvError } from "./env.js";
|
|
103
|
-
export type { AppRegisteredTool, ChatEnv, ChatToolCallResult, ChatToolContent, DanxbotDispatchResult, DanxbotJobStatus, DanxbotLauncher, DanxbotLauncherOptions,
|
|
107
|
+
export type { AppRegisteredTool, ChatEnv, ChatToolCallResult, ChatToolContent, DanxbotDispatchResult, DanxbotJobStatus, DanxbotLauncher, DanxbotLauncherOptions, DispatchInput, } from "./types.js";
|
|
104
108
|
export type { JobStatusReport } from "./job-status.js";
|
|
105
109
|
export type { ChatMcpProtocol, ChatMcpProtocolOptions, ChatReplyPayload, ParseReplyArgumentsOptions, ReplyDeliverResult, ReplyToolOptions, } from "./mcp-protocol.js";
|
|
106
110
|
export type { ChatMcpStdioServer, ChatMcpStdioServerOptions, } from "./mcp-server.js";
|
package/dist/chat/index.js
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Four pieces, usable independently or together:
|
|
9
9
|
*
|
|
10
|
-
* - `createDanxbotLauncher` —
|
|
11
|
-
*
|
|
10
|
+
* - `createDanxbotLauncher` — launch or resume a danxbot agent session with
|
|
11
|
+
* `dispatch`; its end is reported to a URL
|
|
12
12
|
* (`parseJobStatusReport`, `isTerminalJobStatus`, `isFailedJobStatus`).
|
|
13
13
|
* - `createChatMcpProtocol` + `createReplyTool` — the MCP server the dispatched
|
|
14
14
|
* agent talks to the user through, with an extension point for app-registered
|
|
@@ -32,8 +32,12 @@
|
|
|
32
32
|
* profile: "audience-chat",
|
|
33
33
|
* });
|
|
34
34
|
*
|
|
35
|
-
* const { jobId } = await launcher.
|
|
35
|
+
* const { jobId } = await launcher.dispatch({
|
|
36
36
|
* task: prompt,
|
|
37
|
+
* statusUrl: `${publicApiUrl}/chat/turns/${turn.id}/status`,
|
|
38
|
+
* apiToken: turnToken,
|
|
39
|
+
* maxRuntimeMs: 30 * 60_000,
|
|
40
|
+
* title: "Audience chat",
|
|
37
41
|
* overlay: { TURN_ID: turn.id, API_URL: chatEnv.danxbotCallbackApiUrl, CALLBACK_SECRET: chatEnv.danxbotCallbackSecret },
|
|
38
42
|
* });
|
|
39
43
|
*
|
package/dist/chat/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/chat/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/chat/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmGG;AACH,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,yBAAyB,EACzB,QAAQ,GACT,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/chat/job-status.js
CHANGED
|
@@ -59,16 +59,23 @@ export function isFailedJobStatus(status) {
|
|
|
59
59
|
*/
|
|
60
60
|
export function parseJobStatusReport(body) {
|
|
61
61
|
if (body === null || typeof body !== "object" || Array.isArray(body)) {
|
|
62
|
-
return {
|
|
62
|
+
return {
|
|
63
|
+
ok: false,
|
|
64
|
+
message: "The body must be an object with a `status`.",
|
|
65
|
+
};
|
|
63
66
|
}
|
|
64
67
|
const { status, message, data } = body;
|
|
65
68
|
if (typeof status !== "string" || status.trim() === "") {
|
|
66
69
|
return { ok: false, message: "`status` must be a non-empty string." };
|
|
67
70
|
}
|
|
68
|
-
if (message !== undefined &&
|
|
71
|
+
if (message !== undefined &&
|
|
72
|
+
message !== null &&
|
|
73
|
+
typeof message !== "string") {
|
|
69
74
|
return { ok: false, message: "`message` must be a string." };
|
|
70
75
|
}
|
|
71
|
-
if (data !== undefined &&
|
|
76
|
+
if (data !== undefined &&
|
|
77
|
+
data !== null &&
|
|
78
|
+
(typeof data !== "object" || Array.isArray(data))) {
|
|
72
79
|
return { ok: false, message: "`data` must be an object." };
|
|
73
80
|
}
|
|
74
81
|
const value = { status };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"job-status.js","sourceRoot":"","sources":["../../src/chat/job-status.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH;;+DAE+D;AAC/D,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;AAElE,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,GAAG,sBAAsB;IACzB,QAAQ;IACR,kBAAkB;IAClB,WAAW;IACX,UAAU;IACV,SAAS;IACT,cAAc;IACd,mBAAmB;IACnB,uBAAuB;IACvB,mBAAmB;IACnB,kBAAkB;IAClB,qBAAqB;IACrB,cAAc;IACd,gBAAgB;CACjB,CAAC,CAAC;AAEH;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAc;IAChD,OAAO,qBAAqB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AAC3C,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,iBAAiB,CAAC,MAAc;IAC9C,OAAO,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AAC5E,CAAC;AASD;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAClC,IAAa;IAEb,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACrE,OAAO,EAAE,EAAE,
|
|
1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AAC;IACxE,CAAC;IACD,IACE,OAAO,KAAK,SAAS;QACrB,OAAO,KAAK,IAAI;QAChB,OAAO,OAAO,KAAK,QAAQ,EAC3B,CAAC;QACD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,6BAA6B,EAAE,CAAC;IAC/D,CAAC;IACD,IACE,IAAI,KAAK,SAAS;QAClB,IAAI,KAAK,IAAI;QACb,CAAC,OAAO,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,EACjD,CAAC;QACD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,2BAA2B,EAAE,CAAC;IAC7D,CAAC;IAED,MAAM,KAAK,GAAoB,EAAE,MAAM,EAAE,CAAC;IAC1C,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;IACzD,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI;QACrC,KAAK,CAAC,IAAI,GAAG,IAA+B,CAAC;IAC/C,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC"}
|
package/dist/chat/launcher.d.ts
CHANGED
|
@@ -15,10 +15,9 @@
|
|
|
15
15
|
* "input_tokens":…,"output_tokens":…,"cache_read_input_tokens":…,
|
|
16
16
|
* "cache_creation_input_tokens":…}
|
|
17
17
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* `status_url` as the job runs and ends — see job-status.ts.
|
|
18
|
+
* `dispatch` additionally sends {status_url, api_token, max_runtime_ms, title,
|
|
19
|
+
* model?, effort?} on both: danxbot PUTs {status, message?, data?} to `status_url`
|
|
20
|
+
* as the job runs and ends — see job-status.ts.
|
|
22
21
|
*
|
|
23
22
|
* `resume` is what makes a thread a thread: passing the previous turn's `job_id`
|
|
24
23
|
* resumes the underlying Claude session (`claude --resume`), so a later turn
|
package/dist/chat/launcher.js
CHANGED
|
@@ -19,7 +19,9 @@ async function danxbotFetch(options, path, init) {
|
|
|
19
19
|
method: init.method,
|
|
20
20
|
headers: {
|
|
21
21
|
Authorization: `Bearer ${options.apiToken}`,
|
|
22
|
-
...(init.body !== undefined
|
|
22
|
+
...(init.body !== undefined
|
|
23
|
+
? { "Content-Type": "application/json" }
|
|
24
|
+
: {}),
|
|
23
25
|
},
|
|
24
26
|
body: init.body !== undefined ? JSON.stringify(init.body) : undefined,
|
|
25
27
|
});
|
|
@@ -53,7 +55,7 @@ async function postDispatch(options, path, body) {
|
|
|
53
55
|
}
|
|
54
56
|
/** danxbot ignores a `max_runtime_ms` that is not a number and runs the job with no
|
|
55
57
|
* cap, so a bad value is refused here rather than launching an unbounded job. */
|
|
56
|
-
function
|
|
58
|
+
function assertValidDispatchInput(input) {
|
|
57
59
|
if (!Number.isInteger(input.maxRuntimeMs) || input.maxRuntimeMs <= 0) {
|
|
58
60
|
throw new RangeError(`maxRuntimeMs must be a positive integer; got ${input.maxRuntimeMs}`);
|
|
59
61
|
}
|
|
@@ -69,43 +71,31 @@ function assertValidLaunchJobInput(input) {
|
|
|
69
71
|
export function createDanxbotLauncher(options) {
|
|
70
72
|
return {
|
|
71
73
|
/**
|
|
72
|
-
* Dispatch
|
|
73
|
-
* fresh Claude session (`/api/launch`), present
|
|
74
|
-
* belongs to (`/api/resume`). Both carry the
|
|
75
|
-
*
|
|
74
|
+
* Dispatch one agent session. `parentJobId` selects the endpoint: absent starts
|
|
75
|
+
* a fresh Claude session (`/api/launch`), present resumes the one that job
|
|
76
|
+
* belongs to (`/api/resume`, sent as `job_id`). Both carry the status callback:
|
|
77
|
+
* danxbot PUTs its progress and end to `statusUrl` (sending `apiToken` back as
|
|
78
|
+
* the `Authorization: Bearer` of every status PUT) and stops the job after
|
|
79
|
+
* `maxRuntimeMs`. `title` names the job on danxbot's dashboard; `model` and
|
|
80
|
+
* `effort` override the profile's, and are given together or not at all.
|
|
76
81
|
*/
|
|
77
|
-
async
|
|
78
|
-
|
|
82
|
+
async dispatch(input) {
|
|
83
|
+
assertValidDispatchInput(input);
|
|
84
|
+
const result = await postDispatch(options, input.parentJobId ? "/api/resume" : "/api/launch", {
|
|
79
85
|
board: options.board,
|
|
80
86
|
profile: options.profile,
|
|
81
87
|
task: input.task,
|
|
82
88
|
overlay: input.overlay,
|
|
83
89
|
...(input.parentJobId ? { job_id: input.parentJobId } : {}),
|
|
84
|
-
};
|
|
85
|
-
const result = await postDispatch(options, input.parentJobId ? "/api/resume" : "/api/launch", body);
|
|
86
|
-
return { jobId: result.job_id, parentJobId: result.parent_job_id };
|
|
87
|
-
},
|
|
88
|
-
/**
|
|
89
|
-
* Launch a one-shot job: a session with no conversation, whose end danxbot
|
|
90
|
-
* reports to `statusUrl` (sending `apiToken` back as the `Authorization: Bearer`
|
|
91
|
-
* of every status PUT) and which danxbot stops after `maxRuntimeMs`. `title`
|
|
92
|
-
* names the job on danxbot's dashboard. Sends exactly danxbot's documented
|
|
93
|
-
* `/api/launch` body.
|
|
94
|
-
*/
|
|
95
|
-
async launchJob(input) {
|
|
96
|
-
assertValidLaunchJobInput(input);
|
|
97
|
-
const result = await postDispatch(options, "/api/launch", {
|
|
98
|
-
board: options.board,
|
|
99
|
-
profile: options.profile,
|
|
100
|
-
task: input.task,
|
|
101
|
-
overlay: input.overlay,
|
|
102
90
|
status_url: input.statusUrl,
|
|
103
91
|
api_token: input.apiToken,
|
|
104
92
|
max_runtime_ms: input.maxRuntimeMs,
|
|
105
93
|
title: input.title,
|
|
106
|
-
...(input.model !== undefined
|
|
94
|
+
...(input.model !== undefined
|
|
95
|
+
? { model: input.model, effort: input.effort }
|
|
96
|
+
: {}),
|
|
107
97
|
});
|
|
108
|
-
return { jobId: result.job_id };
|
|
98
|
+
return { jobId: result.job_id, parentJobId: result.parent_job_id };
|
|
109
99
|
},
|
|
110
100
|
/**
|
|
111
101
|
* Stop a running job and free its danxbot worker slot. `reason` is recorded on
|
|
@@ -124,7 +114,9 @@ export function createDanxbotLauncher(options) {
|
|
|
124
114
|
});
|
|
125
115
|
},
|
|
126
116
|
async getJobStatus(jobId) {
|
|
127
|
-
const result = await danxbotFetch(options, `/api/status/${encodeURIComponent(jobId)}`, {
|
|
117
|
+
const result = await danxbotFetch(options, `/api/status/${encodeURIComponent(jobId)}`, {
|
|
118
|
+
method: "GET",
|
|
119
|
+
});
|
|
128
120
|
return {
|
|
129
121
|
jobId: result.job_id,
|
|
130
122
|
status: result.status,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"launcher.js","sourceRoot":"","sources":["../../src/chat/launcher.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"launcher.js","sourceRoot":"","sources":["../../src/chat/launcher.ts"],"names":[],"mappings":"AAmCA;;;;;GAKG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IAG1B;IAFX,YACE,OAAe,EACN,UAAyB;QAElC,KAAK,CAAC,OAAO,CAAC,CAAC;QAFN,eAAU,GAAV,UAAU,CAAe;QAGlC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED,KAAK,UAAU,YAAY,CACzB,OAA+B,EAC/B,IAAY,EACZ,IAAgD;IAEhD,IAAI,QAAkB,CAAC;IACvB,IAAI,CAAC;QACH,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,EAAE,EAAE;YACjD,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,OAAO,CAAC,QAAQ,EAAE;gBAC3C,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS;oBACzB,CAAC,CAAC,EAAE,cAAc,EAAE,kBAAkB,EAAE;oBACxC,CAAC,CAAC,EAAE,CAAC;aACR;YACD,IAAI,EAAE,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,C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