@omnara/sdk 0.1.43 → 0.1.44
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 +98 -0
- package/dist/browser.js +22 -13
- package/dist/browser.js.map +1 -1
- package/dist/{chunk-WM4BXMLD.js → chunk-BUM22BVJ.js} +194 -11
- package/dist/chunk-BUM22BVJ.js.map +1 -0
- package/dist/chunk-HFFDN2XF.js +1604 -0
- package/dist/chunk-HFFDN2XF.js.map +1 -0
- package/dist/{chunk-PPREVIWL.js → chunk-WVD6U2JJ.js} +217 -820
- package/dist/chunk-WVD6U2JJ.js.map +1 -0
- package/dist/index.d.ts +104 -13
- package/dist/index.js +344 -138
- package/dist/index.js.map +1 -1
- package/dist/{sdk.gen-Bp5seXss.d.ts → sdk.gen-BG9nJQHq.d.ts} +1600 -515
- package/dist/tanstack.d.ts +426 -2206
- package/dist/tanstack.js +305 -32
- package/dist/tanstack.js.map +1 -1
- package/dist/zod.d.ts +1 -1
- package/dist/{zod.gen-ArHIe1NX.d.ts → zod.gen-DMsuMMrB.d.ts} +850 -9
- package/dist/zod.js +61 -1
- package/package.json +8 -5
- package/dist/chunk-6YKVAVCM.js +0 -73
- package/dist/chunk-6YKVAVCM.js.map +0 -1
- package/dist/chunk-NZCMY3BC.js +0 -50
- package/dist/chunk-NZCMY3BC.js.map +0 -1
- package/dist/chunk-PPREVIWL.js.map +0 -1
- package/dist/chunk-WM4BXMLD.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,27 +1,36 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getToolCall,
|
|
3
|
+
listProjectToolCalls,
|
|
4
|
+
sdk_gen_exports,
|
|
5
|
+
submitToolCallResult
|
|
6
|
+
} from "./chunk-WVD6U2JJ.js";
|
|
1
7
|
import {
|
|
2
8
|
ApiError,
|
|
9
|
+
abortableDelay,
|
|
10
|
+
createOmnaraClient,
|
|
11
|
+
forwardAbort,
|
|
12
|
+
jsonBodySerializer,
|
|
13
|
+
notifyObserver,
|
|
14
|
+
parseRetryAfter,
|
|
15
|
+
relaxedSchema,
|
|
16
|
+
retryAfterMaximumDelayMs,
|
|
17
|
+
retryDelay,
|
|
18
|
+
untilAborted,
|
|
3
19
|
zErrorResponse,
|
|
4
20
|
zJsonText
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import {
|
|
7
|
-
client,
|
|
8
|
-
createClient,
|
|
9
|
-
createConfig,
|
|
10
|
-
formDataBodySerializer,
|
|
11
|
-
sdk_gen_exports
|
|
12
|
-
} from "./chunk-PPREVIWL.js";
|
|
13
|
-
import {
|
|
14
|
-
relaxedSchema
|
|
15
|
-
} from "./chunk-NZCMY3BC.js";
|
|
21
|
+
} from "./chunk-HFFDN2XF.js";
|
|
16
22
|
import {
|
|
17
23
|
zAgentProfileId,
|
|
18
24
|
zAgentSequence,
|
|
19
25
|
zChatIntegrationLauncher,
|
|
26
|
+
zEventWebhookPayload,
|
|
20
27
|
zGitHubIntegrationLauncher,
|
|
21
28
|
zIntegrationName,
|
|
29
|
+
zListProjectToolCallsQuery,
|
|
22
30
|
zStreamEventsResponse,
|
|
31
|
+
zSubmitToolCallResultRequest,
|
|
23
32
|
zod_gen_exports
|
|
24
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-BUM22BVJ.js";
|
|
25
34
|
|
|
26
35
|
// src/agent-event-stream.ts
|
|
27
36
|
import * as z from "zod";
|
|
@@ -88,9 +97,6 @@ var AgentEventStreamError = class extends Error {
|
|
|
88
97
|
}
|
|
89
98
|
};
|
|
90
99
|
var streamUrl = "/orgs/{orgID}/projects/{projectID}/agents/{agentID}/events/stream";
|
|
91
|
-
var retryBaseDelayMs = 1e3;
|
|
92
|
-
var retryMaximumDelayMs = 3e4;
|
|
93
|
-
var retryAfterMaximumDelayMs = 6e4;
|
|
94
100
|
var stableConnectionResetMs = 1e4;
|
|
95
101
|
var stallTimeoutMs = 35e3;
|
|
96
102
|
var zDurableCursor = z.object({
|
|
@@ -107,27 +113,6 @@ function retryable(error) {
|
|
|
107
113
|
if (error.kind === "api") return error.code === "service_unavailable";
|
|
108
114
|
return error.kind === "http" && (error.status === 408 || error.status === 429 || error.status != null && error.status >= 500);
|
|
109
115
|
}
|
|
110
|
-
function reconnectDelay(attempt) {
|
|
111
|
-
const maximum = Math.min(retryBaseDelayMs * 2 ** Math.max(attempt - 1, 0), retryMaximumDelayMs);
|
|
112
|
-
return Math.floor(Math.random() * maximum);
|
|
113
|
-
}
|
|
114
|
-
function abortableDelay(ms, signal) {
|
|
115
|
-
if (signal?.aborted === true) return Promise.resolve(false);
|
|
116
|
-
return new Promise((resolve) => {
|
|
117
|
-
const timeout = globalThis.setTimeout(() => {
|
|
118
|
-
finish(true);
|
|
119
|
-
}, ms);
|
|
120
|
-
const onAbort = () => {
|
|
121
|
-
finish(false);
|
|
122
|
-
};
|
|
123
|
-
function finish(completed) {
|
|
124
|
-
globalThis.clearTimeout(timeout);
|
|
125
|
-
signal?.removeEventListener("abort", onAbort);
|
|
126
|
-
resolve(completed);
|
|
127
|
-
}
|
|
128
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
116
|
async function settleWithin(pending, ms, attempt) {
|
|
132
117
|
let timer;
|
|
133
118
|
const deadline = new Promise((_, reject) => {
|
|
@@ -143,14 +128,15 @@ async function settleWithin(pending, ms, attempt) {
|
|
|
143
128
|
globalThis.clearTimeout(timer);
|
|
144
129
|
}
|
|
145
130
|
}
|
|
146
|
-
async function* openConnection(
|
|
131
|
+
async function* openConnection(client, { path, query, headers }, callerSignal) {
|
|
147
132
|
const attempt = new AbortController();
|
|
148
|
-
const
|
|
133
|
+
const disposeCaller = forwardAbort(callerSignal, attempt);
|
|
134
|
+
const { signal } = attempt;
|
|
149
135
|
let reader;
|
|
150
136
|
try {
|
|
151
137
|
const dispatch = { started: false };
|
|
152
138
|
const { error, response } = await settleWithin(
|
|
153
|
-
|
|
139
|
+
client.request({
|
|
154
140
|
method: "GET",
|
|
155
141
|
url: streamUrl,
|
|
156
142
|
path,
|
|
@@ -161,7 +147,7 @@ async function* openConnection(client2, { path, query, headers }, callerSignal)
|
|
|
161
147
|
throwOnError: false,
|
|
162
148
|
fetch: (input, init) => {
|
|
163
149
|
dispatch.started = true;
|
|
164
|
-
return (
|
|
150
|
+
return (client.getConfig().fetch ?? globalThis.fetch)(input, init);
|
|
165
151
|
}
|
|
166
152
|
}),
|
|
167
153
|
stallTimeoutMs,
|
|
@@ -209,7 +195,9 @@ async function* openConnection(client2, { path, query, headers }, callerSignal)
|
|
|
209
195
|
} catch (error) {
|
|
210
196
|
throw error instanceof AgentEventStreamError ? error : streamError("transport", "Agent event stream disconnected", { cause: error });
|
|
211
197
|
} finally {
|
|
198
|
+
disposeCaller();
|
|
212
199
|
await reader?.cancel().catch(() => void 0);
|
|
200
|
+
reader?.releaseLock();
|
|
213
201
|
}
|
|
214
202
|
}
|
|
215
203
|
function decodeFrame(text) {
|
|
@@ -229,7 +217,7 @@ function durableSequence(data) {
|
|
|
229
217
|
return cursor.success ? cursor.data.sequence : void 0;
|
|
230
218
|
}
|
|
231
219
|
async function* openAgentEventStream({
|
|
232
|
-
client
|
|
220
|
+
client,
|
|
233
221
|
path,
|
|
234
222
|
query,
|
|
235
223
|
headers,
|
|
@@ -243,7 +231,7 @@ async function* openAgentEventStream({
|
|
|
243
231
|
let connectedAt;
|
|
244
232
|
try {
|
|
245
233
|
const connection = openConnection(
|
|
246
|
-
|
|
234
|
+
client,
|
|
247
235
|
{
|
|
248
236
|
path,
|
|
249
237
|
query,
|
|
@@ -273,7 +261,7 @@ async function* openAgentEventStream({
|
|
|
273
261
|
consecutiveFailures = 0;
|
|
274
262
|
}
|
|
275
263
|
consecutiveFailures += 1;
|
|
276
|
-
const delayMs = Math.max(
|
|
264
|
+
const delayMs = Math.max(retryDelay(consecutiveFailures), error.retryAfterMs ?? 0);
|
|
277
265
|
onConnectionStateChange?.({
|
|
278
266
|
state: "reconnecting",
|
|
279
267
|
attempt: consecutiveFailures,
|
|
@@ -317,111 +305,315 @@ function cliLoginTokenHost(token) {
|
|
|
317
305
|
return host === "" ? token.name : host;
|
|
318
306
|
}
|
|
319
307
|
|
|
320
|
-
// src/
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
"post",
|
|
330
|
-
"put",
|
|
331
|
-
"trace"
|
|
332
|
-
];
|
|
333
|
-
var zMultipartPart = z2.union([
|
|
334
|
-
z2.string(),
|
|
335
|
-
z2.instanceof(Blob),
|
|
336
|
-
z2.date().transform((date2) => date2.toISOString()),
|
|
337
|
-
z2.union([z2.number(), z2.boolean(), z2.bigint()]).transform(String),
|
|
338
|
-
z2.json().transform((value) => new Blob([JSON.stringify(value)], { type: "application/json" }))
|
|
339
|
-
]);
|
|
340
|
-
var zMultipartBody = z2.record(
|
|
341
|
-
z2.string(),
|
|
342
|
-
z2.union([z2.array(zMultipartPart), zMultipartPart]).nullish()
|
|
343
|
-
);
|
|
344
|
-
var serializeMultipartBody = ((body) => {
|
|
345
|
-
const form = new FormData();
|
|
346
|
-
for (const [key, value] of Object.entries(zMultipartBody.parse(body))) {
|
|
347
|
-
if (value === null || value === void 0) continue;
|
|
348
|
-
for (const part of Array.isArray(value) ? value : [value]) form.append(key, part);
|
|
308
|
+
// src/custom-tool-request.ts
|
|
309
|
+
var CustomToolDeliveryError = class extends Error {
|
|
310
|
+
constructor(call, result, cause, retryAt) {
|
|
311
|
+
super(`Could not deliver the result for custom tool call ${call.toolCallID}`, { cause });
|
|
312
|
+
this.call = call;
|
|
313
|
+
this.result = result;
|
|
314
|
+
this.cause = cause;
|
|
315
|
+
this.retryAt = retryAt;
|
|
316
|
+
this.name = "CustomToolDeliveryError";
|
|
349
317
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
318
|
+
call;
|
|
319
|
+
result;
|
|
320
|
+
cause;
|
|
321
|
+
retryAt;
|
|
322
|
+
};
|
|
323
|
+
function toolError(cause) {
|
|
324
|
+
return cause instanceof Error ? cause : new Error(String(cause));
|
|
325
|
+
}
|
|
326
|
+
async function deliverToolResult(client, call, result, request) {
|
|
327
|
+
let retryAt;
|
|
328
|
+
try {
|
|
329
|
+
return await request(async (input, init) => {
|
|
330
|
+
const response = await (client.getConfig().fetch ?? globalThis.fetch)(input, init);
|
|
331
|
+
const delay = parseRetryAfter(response.headers.get("Retry-After"));
|
|
332
|
+
retryAt = delay === void 0 ? void 0 : Date.now() + delay;
|
|
333
|
+
return response;
|
|
334
|
+
});
|
|
335
|
+
} catch (cause) {
|
|
336
|
+
throw new CustomToolDeliveryError(call, result, cause, retryAt);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// src/custom-tool-execution.ts
|
|
341
|
+
function failedResult() {
|
|
342
|
+
return {
|
|
343
|
+
outcome: "failed",
|
|
344
|
+
content_blocks: [{ type: "text", text: "The tool could not complete the request." }]
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
async function executeCustomTool(task, options) {
|
|
348
|
+
const { client } = options;
|
|
349
|
+
const observe = (event) => {
|
|
350
|
+
notifyObserver(options.onObserve, event);
|
|
351
|
+
};
|
|
352
|
+
const { call, cancel } = task;
|
|
353
|
+
const { signal } = cancel;
|
|
354
|
+
const path = { ...options.path, agentID: call.agentID, toolCallID: call.toolCallID };
|
|
355
|
+
let current;
|
|
356
|
+
if (task.source === "recovery") {
|
|
357
|
+
current = task.current;
|
|
358
|
+
} else {
|
|
359
|
+
const readStarted = performance.now();
|
|
360
|
+
let readiness = "failed";
|
|
361
|
+
try {
|
|
362
|
+
current = (await getToolCall({
|
|
363
|
+
client,
|
|
364
|
+
path,
|
|
365
|
+
signal,
|
|
366
|
+
throwOnError: true,
|
|
367
|
+
responseStyle: "fields"
|
|
368
|
+
})).data;
|
|
369
|
+
if (current.state !== "ready") {
|
|
370
|
+
readiness = current.state === "completed" ? "completed" : "ignored";
|
|
371
|
+
return { status: readiness };
|
|
372
|
+
}
|
|
373
|
+
if (current.type !== "custom" || current.name !== call.name) {
|
|
374
|
+
readiness = "ignored";
|
|
375
|
+
return { status: readiness };
|
|
376
|
+
}
|
|
377
|
+
readiness = "ready";
|
|
378
|
+
} finally {
|
|
379
|
+
observe({
|
|
380
|
+
stage: "readiness",
|
|
381
|
+
durationMs: performance.now() - readStarted,
|
|
382
|
+
outcome: readiness
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
signal.throwIfAborted();
|
|
387
|
+
const handlerStarted = performance.now();
|
|
388
|
+
let handlerOutcome = "canceled";
|
|
389
|
+
let body;
|
|
390
|
+
try {
|
|
391
|
+
const result = await options.handler({ ...call, input: current.input, signal });
|
|
392
|
+
if (task.completed) return { status: "completed" };
|
|
393
|
+
if (result.outcome === "deferred") {
|
|
394
|
+
signal.throwIfAborted();
|
|
395
|
+
handlerOutcome = "deferred";
|
|
396
|
+
return { status: "deferred" };
|
|
397
|
+
}
|
|
398
|
+
body = zSubmitToolCallResultRequest.parse(
|
|
399
|
+
JSON.parse(jsonBodySerializer.bodySerializer(zSubmitToolCallResultRequest.parse(result)))
|
|
400
|
+
);
|
|
401
|
+
handlerOutcome = body.outcome;
|
|
402
|
+
} catch (cause) {
|
|
403
|
+
if (task.completed) return { status: "completed" };
|
|
404
|
+
signal.throwIfAborted();
|
|
405
|
+
notifyObserver((error) => options.onError?.(error, call), toolError(cause));
|
|
406
|
+
body = failedResult();
|
|
407
|
+
handlerOutcome = "failed";
|
|
408
|
+
} finally {
|
|
409
|
+
observe({
|
|
410
|
+
stage: "handler",
|
|
411
|
+
source: task.source,
|
|
412
|
+
durationMs: performance.now() - handlerStarted,
|
|
413
|
+
outcome: handlerOutcome
|
|
414
|
+
});
|
|
357
415
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
416
|
+
const submitStarted = performance.now();
|
|
417
|
+
let submission = "failed";
|
|
418
|
+
try {
|
|
419
|
+
await deliverToolResult(
|
|
420
|
+
client,
|
|
421
|
+
call,
|
|
422
|
+
body,
|
|
423
|
+
(fetch2) => submitToolCallResult({
|
|
424
|
+
client,
|
|
425
|
+
path,
|
|
426
|
+
body,
|
|
427
|
+
signal,
|
|
428
|
+
fetch: fetch2,
|
|
429
|
+
throwOnError: true,
|
|
430
|
+
responseStyle: "fields"
|
|
431
|
+
})
|
|
432
|
+
);
|
|
433
|
+
submission = "accepted";
|
|
434
|
+
return { status: "completed" };
|
|
435
|
+
} catch (error) {
|
|
436
|
+
if (
|
|
437
|
+
// A completed update can change this flag while the POST is awaiting a response.
|
|
438
|
+
// oxlint-disable-next-line typescript/no-unnecessary-condition
|
|
439
|
+
task.completed || error instanceof CustomToolDeliveryError && error.cause instanceof ApiError && error.cause.status === 409 && error.cause.code === "tool_call_already_completed"
|
|
440
|
+
) {
|
|
441
|
+
submission = "already_completed";
|
|
442
|
+
return { status: "completed" };
|
|
443
|
+
}
|
|
444
|
+
throw error;
|
|
445
|
+
} finally {
|
|
446
|
+
observe({
|
|
447
|
+
stage: "submission",
|
|
448
|
+
durationMs: performance.now() - submitStarted,
|
|
449
|
+
outcome: submission
|
|
450
|
+
});
|
|
368
451
|
}
|
|
369
452
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
const
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
453
|
+
|
|
454
|
+
// src/custom-tool-worker.ts
|
|
455
|
+
function createCustomToolWorker(options) {
|
|
456
|
+
const handlers = new Map(Object.entries(options.tools));
|
|
457
|
+
const nameSchema = zListProjectToolCallsQuery.shape.names.unwrap().element;
|
|
458
|
+
for (const name of handlers.keys()) {
|
|
459
|
+
const result = nameSchema.safeParse(name);
|
|
460
|
+
if (!result.success)
|
|
461
|
+
throw new TypeError(
|
|
462
|
+
`Invalid custom tool name ${JSON.stringify(name)}: ${result.error.message}`
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
const running = /* @__PURE__ */ new Map();
|
|
466
|
+
const listingCompletions = /* @__PURE__ */ new Set();
|
|
467
|
+
function observedCompletion(id) {
|
|
468
|
+
for (const completed of listingCompletions) completed.add(id);
|
|
469
|
+
}
|
|
470
|
+
const observe = options.onObserve;
|
|
471
|
+
const report = (cause, call) => {
|
|
472
|
+
notifyObserver((error) => options.onError?.(error, call), toolError(cause));
|
|
473
|
+
};
|
|
474
|
+
function start(work, signal) {
|
|
475
|
+
signal?.throwIfAborted();
|
|
476
|
+
const { call, source } = work;
|
|
477
|
+
const handler = handlers.get(call.name);
|
|
478
|
+
if (handler === void 0) return Promise.resolve({ status: "ignored" });
|
|
479
|
+
const id = `${call.agentID}/${call.toolCallID}`;
|
|
480
|
+
const active = running.get(id);
|
|
481
|
+
if (active !== void 0) {
|
|
482
|
+
notifyObserver(observe, { stage: "admission", source, outcome: "joined" });
|
|
483
|
+
return signal ? untilAborted(() => active.done, signal) : active.done;
|
|
484
|
+
}
|
|
485
|
+
const task = { ...work, cancel: new AbortController(), completed: false };
|
|
486
|
+
const unlink = forwardAbort(signal, task.cancel);
|
|
487
|
+
const done = Promise.resolve().then(() => executeCustomTool(task, { ...options, handler })).catch((cause) => {
|
|
488
|
+
if (task.completed) return { status: "completed" };
|
|
489
|
+
report(cause, task.call);
|
|
490
|
+
throw cause;
|
|
491
|
+
}).then((outcome) => {
|
|
492
|
+
if (outcome.status === "completed") observedCompletion(id);
|
|
493
|
+
return outcome;
|
|
494
|
+
}).finally(() => {
|
|
495
|
+
unlink();
|
|
496
|
+
running.delete(id);
|
|
388
497
|
});
|
|
498
|
+
running.set(id, Object.assign(task, { done }));
|
|
499
|
+
notifyObserver(observe, { stage: "admission", source, outcome: "started" });
|
|
500
|
+
return done;
|
|
389
501
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
502
|
+
async function check(checkOptions = {}) {
|
|
503
|
+
const query = zListProjectToolCallsQuery.parse({
|
|
504
|
+
state: "ready",
|
|
505
|
+
type: "custom",
|
|
506
|
+
names: handlers.size > 0 && handlers.size <= 100 ? [...handlers.keys()] : void 0,
|
|
507
|
+
agent_profile_id: options.agentProfileID,
|
|
508
|
+
cursor: checkOptions.cursor,
|
|
509
|
+
limit: checkOptions.limit
|
|
510
|
+
});
|
|
511
|
+
checkOptions.signal?.throwIfAborted();
|
|
512
|
+
if (handlers.size === 0) return { results: [], nextCursor: null };
|
|
513
|
+
const started = performance.now();
|
|
514
|
+
let rows = 0;
|
|
515
|
+
let outcome = "failed";
|
|
516
|
+
const completed = /* @__PURE__ */ new Set();
|
|
517
|
+
listingCompletions.add(completed);
|
|
518
|
+
try {
|
|
519
|
+
const { data: page } = await listProjectToolCalls({
|
|
520
|
+
client: options.client,
|
|
521
|
+
path: options.path,
|
|
522
|
+
query,
|
|
523
|
+
signal: checkOptions.signal,
|
|
524
|
+
throwOnError: true,
|
|
525
|
+
responseStyle: "fields"
|
|
526
|
+
});
|
|
527
|
+
if (page.data.length > query.limit)
|
|
528
|
+
throw new Error("tool-call page exceeded its requested limit");
|
|
529
|
+
rows = page.data.length;
|
|
530
|
+
const pending = page.data.filter(
|
|
531
|
+
(call) => call.type === "custom" && call.state === "ready" && handlers.has(call.name)
|
|
532
|
+
).map(async (current) => {
|
|
533
|
+
const call = { agentID: current.agent_id, toolCallID: current.id, name: current.name };
|
|
534
|
+
try {
|
|
535
|
+
return {
|
|
536
|
+
call,
|
|
537
|
+
outcome: completed.has(`${call.agentID}/${call.toolCallID}`) ? { status: "completed" } : await start({ call, source: "recovery", current }, checkOptions.signal)
|
|
538
|
+
};
|
|
539
|
+
} catch (cause) {
|
|
540
|
+
return { call, outcome: { status: "failed", error: toolError(cause) } };
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
listingCompletions.delete(completed);
|
|
544
|
+
const results = await Promise.all(pending);
|
|
545
|
+
outcome = "page";
|
|
546
|
+
return { results, nextCursor: page.next_cursor };
|
|
547
|
+
} catch (cause) {
|
|
548
|
+
report(cause);
|
|
549
|
+
throw cause;
|
|
550
|
+
} finally {
|
|
551
|
+
listingCompletions.delete(completed);
|
|
552
|
+
notifyObserver(observe, {
|
|
553
|
+
stage: "recovery",
|
|
554
|
+
durationMs: performance.now() - started,
|
|
555
|
+
outcome,
|
|
556
|
+
rows
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
return {
|
|
561
|
+
async handle(update, operation = {}) {
|
|
562
|
+
if (update.org_id !== options.path.orgID || update.project_id !== options.path.projectID || options.agentProfileID !== void 0 && update.agent_profile_id !== options.agentProfileID)
|
|
563
|
+
return { status: "ignored" };
|
|
564
|
+
if (update.state === "completed") {
|
|
565
|
+
const id = `${update.agent_id}/${update.tool_call_id}`;
|
|
566
|
+
observedCompletion(id);
|
|
567
|
+
const task = running.get(id);
|
|
568
|
+
if (task) {
|
|
569
|
+
task.completed = true;
|
|
570
|
+
task.cancel.abort();
|
|
571
|
+
if (operation.signal) await untilAborted(() => task.done, operation.signal);
|
|
572
|
+
else await task.done;
|
|
573
|
+
}
|
|
574
|
+
return { status: "completed" };
|
|
575
|
+
}
|
|
576
|
+
if (update.state !== "ready" || update.name === void 0 || !handlers.has(update.name))
|
|
577
|
+
return { status: "ignored" };
|
|
578
|
+
return start(
|
|
579
|
+
{
|
|
580
|
+
call: { agentID: update.agent_id, toolCallID: update.tool_call_id, name: update.name },
|
|
581
|
+
source: "notification"
|
|
582
|
+
},
|
|
583
|
+
operation.signal
|
|
584
|
+
);
|
|
585
|
+
},
|
|
586
|
+
check
|
|
587
|
+
};
|
|
396
588
|
}
|
|
397
589
|
|
|
398
590
|
// src/device.ts
|
|
399
|
-
import * as
|
|
591
|
+
import * as z2 from "zod";
|
|
400
592
|
var OMNARA_CLI_OAUTH_CLIENT_ID = "omnara-cli";
|
|
401
593
|
var OAUTH_DEVICE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
|
|
402
|
-
var zAuthorizationServerMetadata =
|
|
403
|
-
issuer:
|
|
404
|
-
device_authorization_endpoint:
|
|
405
|
-
token_endpoint:
|
|
406
|
-
grant_types_supported:
|
|
407
|
-
token_endpoint_auth_methods_supported:
|
|
594
|
+
var zAuthorizationServerMetadata = z2.object({
|
|
595
|
+
issuer: z2.url(),
|
|
596
|
+
device_authorization_endpoint: z2.url(),
|
|
597
|
+
token_endpoint: z2.url(),
|
|
598
|
+
grant_types_supported: z2.array(z2.string()),
|
|
599
|
+
token_endpoint_auth_methods_supported: z2.array(z2.string())
|
|
408
600
|
});
|
|
409
|
-
var zDeviceAuthStartResponse =
|
|
410
|
-
device_code:
|
|
411
|
-
user_code:
|
|
412
|
-
verification_uri:
|
|
413
|
-
verification_uri_complete:
|
|
414
|
-
expires_in:
|
|
415
|
-
interval:
|
|
601
|
+
var zDeviceAuthStartResponse = z2.object({
|
|
602
|
+
device_code: z2.string().min(1),
|
|
603
|
+
user_code: z2.string().min(1),
|
|
604
|
+
verification_uri: z2.string().min(1),
|
|
605
|
+
verification_uri_complete: z2.string().min(1),
|
|
606
|
+
expires_in: z2.number().int().positive(),
|
|
607
|
+
interval: z2.number().int().positive()
|
|
416
608
|
});
|
|
417
|
-
var zDeviceAuthErrorResponse =
|
|
418
|
-
error:
|
|
419
|
-
error_description:
|
|
609
|
+
var zDeviceAuthErrorResponse = z2.object({
|
|
610
|
+
error: z2.string().min(1),
|
|
611
|
+
error_description: z2.string().optional()
|
|
420
612
|
});
|
|
421
613
|
var zDeviceAuthFailure = zJsonText.pipe(zDeviceAuthErrorResponse);
|
|
422
|
-
var zDeviceAuthApprovedResponse =
|
|
423
|
-
access_token:
|
|
424
|
-
token_type:
|
|
614
|
+
var zDeviceAuthApprovedResponse = z2.object({
|
|
615
|
+
access_token: z2.string().min(1),
|
|
616
|
+
token_type: z2.string()
|
|
425
617
|
});
|
|
426
618
|
var DEVICE_AUTH_FAILURE_MESSAGES = {
|
|
427
619
|
access_denied: "the login request was denied",
|
|
@@ -524,17 +716,28 @@ async function pollDeviceAuthToken(options) {
|
|
|
524
716
|
}
|
|
525
717
|
}
|
|
526
718
|
|
|
719
|
+
// src/event-webhook.ts
|
|
720
|
+
var webhookPayload = relaxedSchema(zEventWebhookPayload);
|
|
721
|
+
async function verifyEventWebhook(options) {
|
|
722
|
+
const { Webhook } = await import("standardwebhooks");
|
|
723
|
+
const verified = new Webhook(options.signingSecret).verify(
|
|
724
|
+
options.body,
|
|
725
|
+
Object.fromEntries(new Headers(options.headers))
|
|
726
|
+
);
|
|
727
|
+
return webhookPayload.parse(verified);
|
|
728
|
+
}
|
|
729
|
+
|
|
527
730
|
// src/memory.ts
|
|
528
731
|
var MAX_MEMORY_FILE_BYTES = 10 * 1024 * 1024;
|
|
529
732
|
var FILE_DIGEST_HEADER = "X-Omnara-File-Digest";
|
|
530
733
|
|
|
531
734
|
// src/profile-integration.ts
|
|
532
|
-
import * as
|
|
735
|
+
import * as z3 from "zod";
|
|
533
736
|
var discordPublicKeyPattern = "[a-fA-F0-9]{64}";
|
|
534
|
-
var discordPublicKey =
|
|
535
|
-
var profilesSchema =
|
|
536
|
-
var chatLauncherSchema =
|
|
537
|
-
var githubLauncherSchema =
|
|
737
|
+
var discordPublicKey = z3.string().regex(new RegExp(`^${discordPublicKeyPattern}$`));
|
|
738
|
+
var profilesSchema = z3.array(zAgentProfileId).max(16).refine((ids) => new Set(ids).size === ids.length, "Choose each profile only once.");
|
|
739
|
+
var chatLauncherSchema = z3.strictObject(zChatIntegrationLauncher.shape);
|
|
740
|
+
var githubLauncherSchema = z3.strictObject(zGitHubIntegrationLauncher.shape);
|
|
538
741
|
function chatIntegrationLauncher(settings) {
|
|
539
742
|
return settings.launcher === void 0 ? void 0 : chatLauncherSchema.parse(settings.launcher);
|
|
540
743
|
}
|
|
@@ -594,6 +797,7 @@ function profileIntegrationProfileUpdate(integration, profileIds) {
|
|
|
594
797
|
export {
|
|
595
798
|
AgentEventStreamError,
|
|
596
799
|
ApiError,
|
|
800
|
+
CustomToolDeliveryError,
|
|
597
801
|
DeviceAuthError,
|
|
598
802
|
FILE_DIGEST_HEADER,
|
|
599
803
|
MAX_MEMORY_FILE_BYTES,
|
|
@@ -603,6 +807,7 @@ export {
|
|
|
603
807
|
chatIntegrationLauncher,
|
|
604
808
|
cliLoginTokenHost,
|
|
605
809
|
cliLoginTokenName,
|
|
810
|
+
createCustomToolWorker,
|
|
606
811
|
createOmnaraClient,
|
|
607
812
|
githubIntegrationSettings,
|
|
608
813
|
isCliLoginToken,
|
|
@@ -615,6 +820,7 @@ export {
|
|
|
615
820
|
zod_gen_exports as schemas,
|
|
616
821
|
sdk_gen_exports as sdk,
|
|
617
822
|
startDeviceAuth,
|
|
823
|
+
verifyEventWebhook,
|
|
618
824
|
zJsonText
|
|
619
825
|
};
|
|
620
826
|
//# sourceMappingURL=index.js.map
|