@astralbeam/sdk 0.23.7 → 0.25.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 +7 -5
- package/dist/{api-SpkUzEv3.js → api-CzXKVU8Z.js} +33 -4
- package/dist/api.d.ts +2 -2
- package/dist/api.js +1 -1
- package/dist/{badge-CN5Cq8Xf.js → badge-Do9jhFNO.js} +1 -1
- package/dist/client.d.ts +6418 -46
- package/dist/client.js +51 -1
- package/dist/combobox-B6w-LeTo.js +42 -0
- package/dist/{core-Bn3w2Q44.js → core-zgz5sorX.js} +347 -194
- package/dist/core.d.ts +1 -1
- package/dist/core.js +1 -1
- package/dist/{index-D8X2hDGe.d.ts → index-CI5Jut1h.d.ts} +32 -8
- package/dist/{index-DGfDkU_f.d.ts → index-Cg2qqahU.d.ts} +38 -22
- package/dist/{item-Dl9F5Xpc.js → item-U0ZPJBqA.js} +1 -1
- package/dist/listings-BMUU5Ssj.js +1 -0
- package/dist/{mcp-servers-BIGSawh_.js → mcp-servers-B4IbhRo_.js} +1 -1
- package/dist/react.d.ts +4 -27
- package/dist/react.js +13 -42
- package/dist/{styles.generated-CW6iaZWa.js → styles.generated-BBScqnSk.js} +11 -11
- package/dist/widget-DxIW_E_U.js +27 -0
- package/package.json +5 -6
- package/dist/listings-UNePN1vA.js +0 -1
- package/dist/threads-CZIvwSRC.js +0 -42
- package/dist/widget-D_AwRq1A.js +0 -27
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { At as personalMcpTestConnection, Bt as uploadChatFile, C as getChatConfig, Ct as personalMcpAuthorizeConnection, Dt as personalMcpDisconnectConnection, Et as personalMcpCreateConnection, Ht as isAstralBeamApiError, Lt as updateChatThread, Ot as personalMcpGetCatalog, S as deleteChatThread, Tt as personalMcpCompleteAuthorization, Ut as resolveApiUrl, Vt as astralBeamChatFetch, dt as getThreadAttachment, gt as listChatMessages, it as getRunChatUrl, k as getCurrentUser, kt as personalMcpSetHeaders, rt as getResolveChatToolResultUrl, vt as listChatThreads, wt as personalMcpBindBrowser, y as createChatThread } from "./api-CzXKVU8Z.js";
|
|
2
2
|
import { _ as strictDecoder, i as isObject, l as decode, p as JWTInvalid } from "./validate-BOw-BAyv.js";
|
|
3
3
|
//#region \0rolldown/runtime.js
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -366,7 +366,7 @@ function effect(fn) {
|
|
|
366
366
|
return effectObj;
|
|
367
367
|
}
|
|
368
368
|
//#endregion
|
|
369
|
-
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+
|
|
369
|
+
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai-client/dist/esm/snapshot-atom.js
|
|
370
370
|
function isPlainObject(value) {
|
|
371
371
|
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
372
372
|
const proto = Object.getPrototypeOf(value);
|
|
@@ -471,7 +471,7 @@ function subscribeAtom(atom, listener) {
|
|
|
471
471
|
new TextEncoder();
|
|
472
472
|
new TextDecoder();
|
|
473
473
|
//#endregion
|
|
474
|
-
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+
|
|
474
|
+
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai-client/dist/esm/response-stream.js
|
|
475
475
|
var UnsupportedResponseStreamError = class extends Error {
|
|
476
476
|
missingFeature;
|
|
477
477
|
constructor(missingFeature) {
|
|
@@ -493,14 +493,14 @@ function createResponseStreamTextDecoder() {
|
|
|
493
493
|
return new globalThis.TextDecoder();
|
|
494
494
|
}
|
|
495
495
|
//#endregion
|
|
496
|
-
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+
|
|
496
|
+
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai-client/dist/esm/sse-utils.js
|
|
497
497
|
function parseSseDataLine(line) {
|
|
498
498
|
if (!line.startsWith("data:")) return line;
|
|
499
499
|
const data = line.slice(5);
|
|
500
500
|
return data.startsWith(" ") ? data.slice(1) : data;
|
|
501
501
|
}
|
|
502
502
|
//#endregion
|
|
503
|
-
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+
|
|
503
|
+
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai-client/dist/esm/message-date-normalizer.js
|
|
504
504
|
function validDate(value) {
|
|
505
505
|
if (value instanceof Date) return Number.isNaN(value.getTime()) ? void 0 : value;
|
|
506
506
|
if (typeof value !== "string") return void 0;
|
|
@@ -532,7 +532,7 @@ function normalizeMessagesDates(messages) {
|
|
|
532
532
|
return messages.map(normalizeMessageDates);
|
|
533
533
|
}
|
|
534
534
|
//#endregion
|
|
535
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
535
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/utilities/ag-ui-usage.js
|
|
536
536
|
function definedDetails(value) {
|
|
537
537
|
return Object.keys(value).length > 0 ? value : void 0;
|
|
538
538
|
}
|
|
@@ -577,7 +577,7 @@ function fromSpecTokenUsage(usage, leftover) {
|
|
|
577
577
|
};
|
|
578
578
|
}
|
|
579
579
|
//#endregion
|
|
580
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
580
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/utilities/merge-metadata.js
|
|
581
581
|
function isPlainRecord$1(value) {
|
|
582
582
|
return value != null && typeof value === "object" && !Array.isArray(value);
|
|
583
583
|
}
|
|
@@ -656,7 +656,7 @@ let EventType = /* @__PURE__ */ function(EventType) {
|
|
|
656
656
|
return EventType;
|
|
657
657
|
}({});
|
|
658
658
|
//#endregion
|
|
659
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
659
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/utilities/tool-call-arguments.js
|
|
660
660
|
function sameJsonValue(left, right) {
|
|
661
661
|
if (Object.is(left, right)) return true;
|
|
662
662
|
if (Array.isArray(left) && Array.isArray(right)) return left.length === right.length && left.every((value, index) => sameJsonValue(value, right[index]));
|
|
@@ -821,7 +821,7 @@ function finishToolCallArguments(streamed, end) {
|
|
|
821
821
|
};
|
|
822
822
|
}
|
|
823
823
|
//#endregion
|
|
824
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
824
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/utilities/reasoning-encrypted-value.js
|
|
825
825
|
/**
|
|
826
826
|
* Id prefix for the reasoning message of a redacted thinking block (Anthropic
|
|
827
827
|
* `redacted_thinking`). AG-UI's `encryptedValue` does not say what kind of
|
|
@@ -833,7 +833,7 @@ function isRedactedThinkingId(id) {
|
|
|
833
833
|
return typeof id === "string" && id.startsWith("redacted_thinking-");
|
|
834
834
|
}
|
|
835
835
|
//#endregion
|
|
836
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
836
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/interrupt-serialization.js
|
|
837
837
|
var SHA256_K = new Uint32Array([
|
|
838
838
|
1116352408,
|
|
839
839
|
1899447441,
|
|
@@ -1008,7 +1008,7 @@ function cloneAndDeepFreezeJson(value) {
|
|
|
1008
1008
|
return clone;
|
|
1009
1009
|
}
|
|
1010
1010
|
//#endregion
|
|
1011
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
1011
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/interrupts.js
|
|
1012
1012
|
function canonicalizeInterruptResolutions(resolutions) {
|
|
1013
1013
|
const frozen = cloneAndDeepFreezeJson([...resolutions].sort((left, right) => left.interruptId.localeCompare(right.interruptId)));
|
|
1014
1014
|
const canonicalResolutions = canonicalInterruptJson(frozen);
|
|
@@ -1019,7 +1019,7 @@ function canonicalizeInterruptResolutions(resolutions) {
|
|
|
1019
1019
|
});
|
|
1020
1020
|
}
|
|
1021
1021
|
//#endregion
|
|
1022
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
1022
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/activities/chat/tools/schema-converter.js
|
|
1023
1023
|
/**
|
|
1024
1024
|
* Build a JSONSchema object from any plain key/value source. The `JSONSchema`
|
|
1025
1025
|
* interface's `[key: string]: any` index signature makes every property
|
|
@@ -1287,7 +1287,7 @@ async function validateWithStandardSchema(schema, data) {
|
|
|
1287
1287
|
};
|
|
1288
1288
|
}
|
|
1289
1289
|
//#endregion
|
|
1290
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
1290
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/activities/chat/tools/approval-schema.js
|
|
1291
1291
|
var jsonSchemaKeywords = /* @__PURE__ */ new Set([
|
|
1292
1292
|
"$schema",
|
|
1293
1293
|
"$id",
|
|
@@ -1401,7 +1401,7 @@ function hashSchemaInput(schema) {
|
|
|
1401
1401
|
return digestInterruptJson(canonicalInterruptJson(schemaToWire(schema).jsonSchema ?? { standardValidator: "unserialized" }));
|
|
1402
1402
|
}
|
|
1403
1403
|
//#endregion
|
|
1404
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
1404
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/interrupt-resume.js
|
|
1405
1405
|
/**
|
|
1406
1406
|
* The `Interrupt.metadata` key under which this package's resume binding
|
|
1407
1407
|
* travels.
|
|
@@ -1522,7 +1522,7 @@ function readInterruptBinding(descriptor) {
|
|
|
1522
1522
|
};
|
|
1523
1523
|
}
|
|
1524
1524
|
//#endregion
|
|
1525
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
1525
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/interrupt-definition.js
|
|
1526
1526
|
var INTERRUPT_PAYLOAD_METADATA_KEY = "tanstack:interruptPayload";
|
|
1527
1527
|
function schemaJson(schema, name) {
|
|
1528
1528
|
if (!isStandardJSONSchema(schema)) throw new TypeError(`${name} must be a Standard Schema with a JSON Schema converter.`);
|
|
@@ -1547,7 +1547,7 @@ function hashInterruptDefinitionSchema(schema) {
|
|
|
1547
1547
|
return digestInterruptJson(schemaJson(schema, "Interrupt schema").canonicalJson);
|
|
1548
1548
|
}
|
|
1549
1549
|
//#endregion
|
|
1550
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
1550
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/generic-interrupt-continuation.js
|
|
1551
1551
|
/**
|
|
1552
1552
|
* `ResumeEntry.metadata` key for a first-party generic request.
|
|
1553
1553
|
*
|
|
@@ -1586,7 +1586,7 @@ function genericInterruptContinuationFromDescriptor(interrupt) {
|
|
|
1586
1586
|
};
|
|
1587
1587
|
}
|
|
1588
1588
|
//#endregion
|
|
1589
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
1589
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/utilities/subagent-wire.js
|
|
1590
1590
|
function isRecord$2(value) {
|
|
1591
1591
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1592
1592
|
}
|
|
@@ -1700,7 +1700,7 @@ function splitSubagentWire(messages) {
|
|
|
1700
1700
|
};
|
|
1701
1701
|
}
|
|
1702
1702
|
//#endregion
|
|
1703
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
1703
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/utilities/provider-executed.js
|
|
1704
1704
|
/**
|
|
1705
1705
|
* Narrow a tool call's opaque `metadata` to the provider-executed convention.
|
|
1706
1706
|
* Returns the typed metadata when the call is provider-executed, else `null`.
|
|
@@ -1730,7 +1730,7 @@ function isAssistantSegmentOf(id, parentId) {
|
|
|
1730
1730
|
return id?.startsWith(`${parentId}-segment-`) === true;
|
|
1731
1731
|
}
|
|
1732
1732
|
//#endregion
|
|
1733
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
1733
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/utilities/tool-result.js
|
|
1734
1734
|
var CONTENT_PART_TYPES = /* @__PURE__ */ new Set([
|
|
1735
1735
|
"text",
|
|
1736
1736
|
"image",
|
|
@@ -1791,7 +1791,7 @@ function normalizeToolResult(result) {
|
|
|
1791
1791
|
return JSON.stringify(result);
|
|
1792
1792
|
}
|
|
1793
1793
|
//#endregion
|
|
1794
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
1794
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/utilities/block-order.js
|
|
1795
1795
|
/**
|
|
1796
1796
|
* The order map for these entries in produced order, or undefined when they
|
|
1797
1797
|
* are in the default order (all thinking, then text, then tool calls).
|
|
@@ -1879,7 +1879,7 @@ function orderedAssistantBlocks(message) {
|
|
|
1879
1879
|
return blocks;
|
|
1880
1880
|
}
|
|
1881
1881
|
//#endregion
|
|
1882
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
1882
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/activities/chat/messages.js
|
|
1883
1883
|
function isRecord$1(value) {
|
|
1884
1884
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1885
1885
|
}
|
|
@@ -2591,7 +2591,7 @@ function generateMessageId() {
|
|
|
2591
2591
|
return `msg-${Date.now()}-${Math.random().toString(36).substring(7)}`;
|
|
2592
2592
|
}
|
|
2593
2593
|
//#endregion
|
|
2594
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
2594
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/utilities/ag-ui-wire.js
|
|
2595
2595
|
function isRecord(value) {
|
|
2596
2596
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2597
2597
|
}
|
|
@@ -2974,7 +2974,7 @@ function hashContent(s) {
|
|
|
2974
2974
|
return Math.abs(h).toString(36);
|
|
2975
2975
|
}
|
|
2976
2976
|
//#endregion
|
|
2977
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
2977
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/utilities/restore-inbound-chunk.js
|
|
2978
2978
|
/**
|
|
2979
2979
|
* Rebuild TanStack `TokenUsage` (`promptTokens`) from spec `usage[]` plus
|
|
2980
2980
|
* leftover fields in `metadata.tanstack.usage`. Restore the in-process field
|
|
@@ -3011,7 +3011,7 @@ function restoreInboundChunk(chunk) {
|
|
|
3011
3011
|
return next;
|
|
3012
3012
|
}
|
|
3013
3013
|
//#endregion
|
|
3014
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
3014
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/activities/chat/tools/tool-definition.js
|
|
3015
3015
|
/**
|
|
3016
3016
|
* Create an isomorphic tool definition that can be used directly or instantiated for server/client
|
|
3017
3017
|
*
|
|
@@ -3109,7 +3109,7 @@ function toolDefinition(config) {
|
|
|
3109
3109
|
};
|
|
3110
3110
|
}
|
|
3111
3111
|
//#endregion
|
|
3112
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
3112
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/utilities/chunk-ids.js
|
|
3113
3113
|
function stringField(value) {
|
|
3114
3114
|
return typeof value === "string" && value !== "" ? value : void 0;
|
|
3115
3115
|
}
|
|
@@ -3212,7 +3212,7 @@ var require_options = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
3212
3212
|
exports.default = exports.Allow;
|
|
3213
3213
|
}));
|
|
3214
3214
|
//#endregion
|
|
3215
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
3215
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/activities/chat/stream/json-parser.js
|
|
3216
3216
|
var import_dist = (/* @__PURE__ */ __commonJSMin(((exports, module, this$1) => {
|
|
3217
3217
|
var __createBinding = this$1 && this$1.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
3218
3218
|
if (k2 === void 0) k2 = k;
|
|
@@ -3434,7 +3434,7 @@ function parsePartialJSON(jsonString) {
|
|
|
3434
3434
|
return defaultJSONParser.parse(jsonString);
|
|
3435
3435
|
}
|
|
3436
3436
|
//#endregion
|
|
3437
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
3437
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/activities/chat/stream/strategies.js
|
|
3438
3438
|
/**
|
|
3439
3439
|
* Immediate Strategy - emit on every chunk (default behavior)
|
|
3440
3440
|
*/
|
|
@@ -3444,7 +3444,7 @@ var ImmediateStrategy = class {
|
|
|
3444
3444
|
}
|
|
3445
3445
|
};
|
|
3446
3446
|
//#endregion
|
|
3447
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
3447
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/utilities/errors.js
|
|
3448
3448
|
/**
|
|
3449
3449
|
* Convert an AG-UI RUN_ERROR event to the Error shape exposed to consumers.
|
|
3450
3450
|
* Preserves the provider code and sanitized raw event when available.
|
|
@@ -4105,7 +4105,7 @@ var fast_json_patch_default = Object.assign({}, core_exports, duplex_exports, {
|
|
|
4105
4105
|
unescapePathComponent
|
|
4106
4106
|
});
|
|
4107
4107
|
//#endregion
|
|
4108
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
4108
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/activities/chat/activity-records.js
|
|
4109
4109
|
function isActivityPart(part) {
|
|
4110
4110
|
return part.type === "activity";
|
|
4111
4111
|
}
|
|
@@ -4181,7 +4181,7 @@ function applyActivityDeltaToUIMessages(messages, chunk) {
|
|
|
4181
4181
|
}
|
|
4182
4182
|
}
|
|
4183
4183
|
//#endregion
|
|
4184
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
4184
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/activities/chat/stream/message-updaters.js
|
|
4185
4185
|
/**
|
|
4186
4186
|
* Message Updaters (Internal)
|
|
4187
4187
|
*
|
|
@@ -4483,7 +4483,7 @@ function updateThinkingPart(messages, messageId, stepId, content, signature) {
|
|
|
4483
4483
|
});
|
|
4484
4484
|
}
|
|
4485
4485
|
//#endregion
|
|
4486
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
4486
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/activities/chat/stream/processor.js
|
|
4487
4487
|
/**
|
|
4488
4488
|
* Unified Stream Processor
|
|
4489
4489
|
*
|
|
@@ -6612,7 +6612,7 @@ function createReplayStream(recording) {
|
|
|
6612
6612
|
} };
|
|
6613
6613
|
}
|
|
6614
6614
|
//#endregion
|
|
6615
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
6615
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/byok/errors.js
|
|
6616
6616
|
var ByokMissingError = class extends Error {
|
|
6617
6617
|
provider;
|
|
6618
6618
|
constructor(provider) {
|
|
@@ -6638,14 +6638,14 @@ var ByokUnresolvedProviderError = class extends Error {
|
|
|
6638
6638
|
}
|
|
6639
6639
|
};
|
|
6640
6640
|
//#endregion
|
|
6641
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
6641
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/byok/providers.js
|
|
6642
6642
|
/** `[a-z][a-z0-9-]{0,63}` — lowercase, no underscores, max 64 chars. */
|
|
6643
6643
|
var BYOK_PROVIDER_ID_PATTERN = /^[a-z][a-z0-9-]{0,63}$/;
|
|
6644
6644
|
function isProviderId(value) {
|
|
6645
6645
|
return typeof value === "string" && BYOK_PROVIDER_ID_PATTERN.test(value);
|
|
6646
6646
|
}
|
|
6647
6647
|
//#endregion
|
|
6648
|
-
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+
|
|
6648
|
+
//#region ../node_modules/.bun/@tanstack+ai@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai/dist/esm/byok/missing.js
|
|
6649
6649
|
function isByokMissingBody(value) {
|
|
6650
6650
|
if (typeof value !== "object" || value === null) return false;
|
|
6651
6651
|
if (!("error" in value)) return false;
|
|
@@ -6658,7 +6658,7 @@ function isByokMissingBody(value) {
|
|
|
6658
6658
|
return true;
|
|
6659
6659
|
}
|
|
6660
6660
|
//#endregion
|
|
6661
|
-
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+
|
|
6661
|
+
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai-client/dist/esm/connection-adapters.js
|
|
6662
6662
|
/**
|
|
6663
6663
|
* Associates connect-wrapped chunks with the run they were produced under.
|
|
6664
6664
|
* Content events (TEXT_MESSAGE_CONTENT, TOOL_CALL_*, …) carry no `runId` of
|
|
@@ -7352,7 +7352,7 @@ async function* abortableIterable(iterable, signal) {
|
|
|
7352
7352
|
}
|
|
7353
7353
|
}
|
|
7354
7354
|
//#endregion
|
|
7355
|
-
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+
|
|
7355
|
+
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai-client/dist/esm/interrupt-manager.js
|
|
7356
7356
|
function isClientOwnedInterrupt(item) {
|
|
7357
7357
|
return item.resumable;
|
|
7358
7358
|
}
|
|
@@ -8270,7 +8270,7 @@ var InterruptManager = class {
|
|
|
8270
8270
|
}
|
|
8271
8271
|
};
|
|
8272
8272
|
//#endregion
|
|
8273
|
-
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+
|
|
8273
|
+
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai-client/dist/esm/byok/client.js
|
|
8274
8274
|
var registeredProviderIds = /* @__PURE__ */ new WeakMap();
|
|
8275
8275
|
/**
|
|
8276
8276
|
* Provider to stamp when the caller did not pass a slug.
|
|
@@ -8283,7 +8283,7 @@ function byokFallbackProviderId(byok) {
|
|
|
8283
8283
|
if (registered.length === 1) return registered[0];
|
|
8284
8284
|
}
|
|
8285
8285
|
//#endregion
|
|
8286
|
-
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+
|
|
8286
|
+
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai-client/dist/esm/byok/resolve.js
|
|
8287
8287
|
function resolveByokProviderId(byokProvider, ...candidates) {
|
|
8288
8288
|
const fromFn = byokProvider?.();
|
|
8289
8289
|
if (isProviderId(fromFn)) return fromFn;
|
|
@@ -8299,7 +8299,7 @@ async function prepareResolvedByokHeaders(byok, provider) {
|
|
|
8299
8299
|
return byok.headers(provider);
|
|
8300
8300
|
}
|
|
8301
8301
|
//#endregion
|
|
8302
|
-
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+
|
|
8302
|
+
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai-client/dist/esm/events.js
|
|
8303
8303
|
/**
|
|
8304
8304
|
* Abstract base class for ChatClient event emission
|
|
8305
8305
|
*/
|
|
@@ -8462,7 +8462,7 @@ var ChatClientEventEmitter = class {
|
|
|
8462
8462
|
}
|
|
8463
8463
|
};
|
|
8464
8464
|
//#endregion
|
|
8465
|
-
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+
|
|
8465
|
+
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai-client/dist/esm/devtools-noop.js
|
|
8466
8466
|
var NoOpChatClientEventEmitter = class extends ChatClientEventEmitter {
|
|
8467
8467
|
emitEvent() {}
|
|
8468
8468
|
};
|
|
@@ -8507,7 +8507,7 @@ var NoOpChatDevtoolsBridge = class {
|
|
|
8507
8507
|
};
|
|
8508
8508
|
var createNoOpChatDevtoolsBridge = (options) => new NoOpChatDevtoolsBridge(options);
|
|
8509
8509
|
//#endregion
|
|
8510
|
-
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+
|
|
8510
|
+
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai-client/dist/esm/client-persistor.js
|
|
8511
8511
|
function getChunkToolCallId$1(chunk) {
|
|
8512
8512
|
return "toolCallId" in chunk && typeof chunk.toolCallId === "string" ? chunk.toolCallId : void 0;
|
|
8513
8513
|
}
|
|
@@ -8779,7 +8779,7 @@ var ChatPersistor = class {
|
|
|
8779
8779
|
}
|
|
8780
8780
|
};
|
|
8781
8781
|
//#endregion
|
|
8782
|
-
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+
|
|
8782
|
+
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai-client/dist/esm/cleared-stream-tracker.js
|
|
8783
8783
|
function getChunkToolCallId(chunk) {
|
|
8784
8784
|
return "toolCallId" in chunk && typeof chunk.toolCallId === "string" ? chunk.toolCallId : void 0;
|
|
8785
8785
|
}
|
|
@@ -8872,7 +8872,7 @@ var ClearedStreamTracker = class {
|
|
|
8872
8872
|
}
|
|
8873
8873
|
};
|
|
8874
8874
|
//#endregion
|
|
8875
|
-
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+
|
|
8875
|
+
//#region ../node_modules/.bun/@tanstack+ai-client@1.0.0+ac75b968c23456b3/node_modules/@tanstack/ai-client/dist/esm/chat-client.js
|
|
8876
8876
|
var STREAM_PROCESSING_BUDGET_MS = 8;
|
|
8877
8877
|
function yieldToHost() {
|
|
8878
8878
|
const { scheduler } = globalThis;
|
|
@@ -11060,6 +11060,186 @@ function createDebugLogger(enabled) {
|
|
|
11060
11060
|
};
|
|
11061
11061
|
}
|
|
11062
11062
|
//#endregion
|
|
11063
|
+
//#region src/core/threads.ts
|
|
11064
|
+
function newUuid() {
|
|
11065
|
+
const bytes = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16));
|
|
11066
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
11067
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
11068
|
+
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
11069
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
11070
|
+
}
|
|
11071
|
+
function threadFromRecord(record, hasMessages = true) {
|
|
11072
|
+
return {
|
|
11073
|
+
id: record.id,
|
|
11074
|
+
title: record.title,
|
|
11075
|
+
agentId: record.agent_id,
|
|
11076
|
+
version: record.version,
|
|
11077
|
+
role: record.role,
|
|
11078
|
+
writerActive: record.writer_active,
|
|
11079
|
+
hasMessages,
|
|
11080
|
+
updatedAt: record.updated_at
|
|
11081
|
+
};
|
|
11082
|
+
}
|
|
11083
|
+
function savedToolCallId(messageId, partId, targetId) {
|
|
11084
|
+
return `saved:${messageId}:${partId}${targetId ? `:${targetId}` : ""}`;
|
|
11085
|
+
}
|
|
11086
|
+
async function loadThreadMessages(id, options, pageAfter, liveToolMessageIds = /* @__PURE__ */ new Map()) {
|
|
11087
|
+
const page = await listChatMessages(id, {
|
|
11088
|
+
page_size: 100,
|
|
11089
|
+
...pageAfter ? { page_after: pageAfter } : {}
|
|
11090
|
+
}, options);
|
|
11091
|
+
const pendingInteractions = page.pending_interactions.map((pending) => ({
|
|
11092
|
+
sourceMessageId: pending.source_message_id,
|
|
11093
|
+
sourcePartId: pending.source_part_id,
|
|
11094
|
+
responseTargetId: pending.response_target_id,
|
|
11095
|
+
toolCallId: liveToolMessageIds.get(pending.tool_call_id) === pending.source_message_id ? pending.tool_call_id : savedToolCallId(pending.source_message_id, pending.source_part_id, pending.response_target_id),
|
|
11096
|
+
targetTenantUserId: pending.target_tenant_user_id,
|
|
11097
|
+
targetClientId: pending.target_client_id,
|
|
11098
|
+
executionLocation: pending.execution_location
|
|
11099
|
+
}));
|
|
11100
|
+
return {
|
|
11101
|
+
...page,
|
|
11102
|
+
pendingInteractions
|
|
11103
|
+
};
|
|
11104
|
+
}
|
|
11105
|
+
function projectThreadMessages(records, pendingInteractions = [], liveToolMessageIds = /* @__PURE__ */ new Map()) {
|
|
11106
|
+
const messages = [];
|
|
11107
|
+
const calls = /* @__PURE__ */ new Map();
|
|
11108
|
+
for (const message of records) {
|
|
11109
|
+
if (message.role === "tool") {
|
|
11110
|
+
for (const part of message.parts) {
|
|
11111
|
+
const call = calls.get(savedToolCallId(message.source_assistant_message_id, message.source_tool_part_id, message.response_target_id));
|
|
11112
|
+
if (!call) continue;
|
|
11113
|
+
call.output = part.output ?? null;
|
|
11114
|
+
Object.assign(call, { resultOutcome: part.outcome });
|
|
11115
|
+
call.state = part.outcome === "succeeded" ? "complete" : "error";
|
|
11116
|
+
}
|
|
11117
|
+
continue;
|
|
11118
|
+
}
|
|
11119
|
+
const parts = message.parts.flatMap((part) => {
|
|
11120
|
+
const source = part.source;
|
|
11121
|
+
if (typeof part.type === "string" && [
|
|
11122
|
+
"image",
|
|
11123
|
+
"document",
|
|
11124
|
+
"audio",
|
|
11125
|
+
"video"
|
|
11126
|
+
].includes(part.type) && source && typeof source === "object" && !Array.isArray(source) && "type" in source && source.type === "attachment") return [{
|
|
11127
|
+
...part,
|
|
11128
|
+
source: {
|
|
11129
|
+
...source,
|
|
11130
|
+
type: "url",
|
|
11131
|
+
value: ""
|
|
11132
|
+
},
|
|
11133
|
+
fileId: "id" in source && typeof source.id === "string" ? source.id : void 0
|
|
11134
|
+
}];
|
|
11135
|
+
if (part.type !== "tool-call") return [part];
|
|
11136
|
+
if (part.executionLocation === "provider") return [part];
|
|
11137
|
+
const toolCallId = String(part.toolCallId);
|
|
11138
|
+
const targets = Array.isArray(part.targets) ? part.targets.flatMap((target) => target && typeof target === "object" && !Array.isArray(target) && "id" in target && typeof target.id === "string" ? [target.id] : []) : pendingInteractions.filter((pending) => pending.sourceMessageId === message.id && pending.sourcePartId === part.id).map((pending) => pending.responseTargetId);
|
|
11139
|
+
return (targets.length ? targets : [void 0]).map((responseTargetId) => {
|
|
11140
|
+
const savedId = savedToolCallId(message.id, String(part.id), responseTargetId);
|
|
11141
|
+
const call = {
|
|
11142
|
+
...part,
|
|
11143
|
+
savedToolTitle: part.declaration && typeof part.declaration === "object" && !Array.isArray(part.declaration) && "title" in part.declaration && typeof part.declaration.title === "string" ? part.declaration.title : void 0,
|
|
11144
|
+
id: liveToolMessageIds.get(toolCallId) === message.id ? toolCallId : savedId,
|
|
11145
|
+
upstreamToolCallId: toolCallId,
|
|
11146
|
+
applicationPartId: part.id,
|
|
11147
|
+
sourceMessageId: message.id,
|
|
11148
|
+
responseTargetId
|
|
11149
|
+
};
|
|
11150
|
+
calls.set(savedId, call);
|
|
11151
|
+
return call;
|
|
11152
|
+
});
|
|
11153
|
+
});
|
|
11154
|
+
messages.push({
|
|
11155
|
+
id: message.id,
|
|
11156
|
+
role: message.role,
|
|
11157
|
+
parts,
|
|
11158
|
+
createdAt: new Date(message.created_at),
|
|
11159
|
+
metadata: { astralbeam: {
|
|
11160
|
+
state: message.state,
|
|
11161
|
+
authorTenantUserId: message.author_tenant_user_id
|
|
11162
|
+
} }
|
|
11163
|
+
});
|
|
11164
|
+
}
|
|
11165
|
+
return messages;
|
|
11166
|
+
}
|
|
11167
|
+
function chatPlacementKey(options) {
|
|
11168
|
+
return options.placementKey ?? options.agentId ?? "default";
|
|
11169
|
+
}
|
|
11170
|
+
/** Cache selection within this tab. Stored IDs are reauthorized before loading history. */
|
|
11171
|
+
function selectedThread(key, id) {
|
|
11172
|
+
try {
|
|
11173
|
+
if (id === void 0) return globalThis.sessionStorage?.getItem(key) ?? void 0;
|
|
11174
|
+
if (id === null) globalThis.sessionStorage?.removeItem(key);
|
|
11175
|
+
else globalThis.sessionStorage?.setItem(key, id);
|
|
11176
|
+
} catch {}
|
|
11177
|
+
}
|
|
11178
|
+
//#endregion
|
|
11179
|
+
//#region src/lib/drafts.ts
|
|
11180
|
+
let draftSessionId;
|
|
11181
|
+
function draftStorageKey(apiUrl, identity, threadId) {
|
|
11182
|
+
if (!threadId) {
|
|
11183
|
+
if (!draftSessionId) try {
|
|
11184
|
+
const key = "astralbeam:draft-session";
|
|
11185
|
+
draftSessionId = globalThis.sessionStorage?.getItem(key) ?? newUuid();
|
|
11186
|
+
globalThis.sessionStorage?.setItem(key, draftSessionId);
|
|
11187
|
+
} catch {
|
|
11188
|
+
draftSessionId ??= newUuid();
|
|
11189
|
+
}
|
|
11190
|
+
threadId = `new:${draftSessionId}`;
|
|
11191
|
+
}
|
|
11192
|
+
return JSON.stringify([
|
|
11193
|
+
apiUrl.replace(/\/+$/, ""),
|
|
11194
|
+
identity,
|
|
11195
|
+
threadId
|
|
11196
|
+
]);
|
|
11197
|
+
}
|
|
11198
|
+
function isStoredDraftAttachment(file) {
|
|
11199
|
+
return typeof file === "object" && file !== null && "id" in file && typeof file.id === "string" && "name" in file && typeof file.name === "string" && "size" in file && typeof file.size === "number" && Number.isFinite(file.size) && file.size >= 0 && "mimeType" in file && typeof file.mimeType === "string" && "status" in file && file.status === "ready" && "fileId" in file && typeof file.fileId === "string" && (!("kind" in file) || typeof file.kind === "string" && [
|
|
11200
|
+
"image",
|
|
11201
|
+
"pdf",
|
|
11202
|
+
"text",
|
|
11203
|
+
"data",
|
|
11204
|
+
"office"
|
|
11205
|
+
].includes(file.kind)) && (!("error" in file) || typeof file.error === "string");
|
|
11206
|
+
}
|
|
11207
|
+
/** Reads or writes unsent text, or with `sent`, the recovery copy of a send not yet accepted. */
|
|
11208
|
+
function storedThreadDraft(apiUrl, identity, threadId, text, slot = "draft") {
|
|
11209
|
+
if (!identity) return "";
|
|
11210
|
+
const key = `astralbeam:${slot}:${draftStorageKey(apiUrl, identity, threadId)}`;
|
|
11211
|
+
try {
|
|
11212
|
+
if (text === void 0) return globalThis.localStorage?.getItem(key) ?? "";
|
|
11213
|
+
if (text) globalThis.localStorage?.setItem(key, text);
|
|
11214
|
+
else globalThis.localStorage?.removeItem(key);
|
|
11215
|
+
} catch {}
|
|
11216
|
+
return "";
|
|
11217
|
+
}
|
|
11218
|
+
function storedThreadAttachments({ apiUrl, identity, threadId, update, moveTo }) {
|
|
11219
|
+
const applyChanges = () => {
|
|
11220
|
+
if (!identity) return [];
|
|
11221
|
+
const key = `astralbeam:attachments:${draftStorageKey(apiUrl, identity, threadId)}`;
|
|
11222
|
+
const read = (key) => {
|
|
11223
|
+
const files = JSON.parse(globalThis.localStorage?.getItem(key) ?? "[]");
|
|
11224
|
+
if (!Array.isArray(files) || !files.every(isStoredDraftAttachment)) throw new TypeError("Stored attachment draft is invalid");
|
|
11225
|
+
return files;
|
|
11226
|
+
};
|
|
11227
|
+
let attachments = read(key);
|
|
11228
|
+
if (update) attachments = update(attachments).filter((file) => file.status === "ready" && file.fileId !== void 0);
|
|
11229
|
+
if (moveTo !== void 0) {
|
|
11230
|
+
const destinationKey = `astralbeam:attachments:${draftStorageKey(apiUrl, identity, moveTo)}`;
|
|
11231
|
+
attachments = [...new Map([...read(destinationKey), ...attachments].map((file) => [file.id, file])).values()];
|
|
11232
|
+
globalThis.localStorage?.setItem(destinationKey, JSON.stringify(attachments));
|
|
11233
|
+
globalThis.localStorage?.removeItem(key);
|
|
11234
|
+
} else if (update) {
|
|
11235
|
+
if (attachments.length) globalThis.localStorage?.setItem(key, JSON.stringify(attachments));
|
|
11236
|
+
else globalThis.localStorage?.removeItem(key);
|
|
11237
|
+
}
|
|
11238
|
+
return attachments;
|
|
11239
|
+
};
|
|
11240
|
+
return globalThis.navigator?.locks ? navigator.locks.request("astralbeam:attachment-drafts", applyChanges) : Promise.resolve().then(applyChanges);
|
|
11241
|
+
}
|
|
11242
|
+
//#endregion
|
|
11063
11243
|
//#region src/core/protocol.ts
|
|
11064
11244
|
const RENDER_WIDGET_TOOL = "render_widget";
|
|
11065
11245
|
const ASK_QUESTIONNAIRE_TOOL = "ask_questionnaire";
|
|
@@ -11696,124 +11876,12 @@ function describeSandboxCommandRun(run) {
|
|
|
11696
11876
|
return parts.join(" · ");
|
|
11697
11877
|
}
|
|
11698
11878
|
//#endregion
|
|
11699
|
-
//#region src/core/threads.ts
|
|
11700
|
-
function newUuid() {
|
|
11701
|
-
const bytes = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16));
|
|
11702
|
-
bytes[6] = bytes[6] & 15 | 64;
|
|
11703
|
-
bytes[8] = bytes[8] & 63 | 128;
|
|
11704
|
-
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
11705
|
-
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
11706
|
-
}
|
|
11707
|
-
function threadFromRecord(record, hasMessages = true) {
|
|
11708
|
-
return {
|
|
11709
|
-
id: record.id,
|
|
11710
|
-
title: record.title,
|
|
11711
|
-
agentId: record.agent_id,
|
|
11712
|
-
version: record.version,
|
|
11713
|
-
role: record.role,
|
|
11714
|
-
writerActive: record.writer_active,
|
|
11715
|
-
hasMessages,
|
|
11716
|
-
updatedAt: record.updated_at
|
|
11717
|
-
};
|
|
11718
|
-
}
|
|
11719
|
-
function savedToolCallId(messageId, partId, targetId) {
|
|
11720
|
-
return `saved:${messageId}:${partId}${targetId ? `:${targetId}` : ""}`;
|
|
11721
|
-
}
|
|
11722
|
-
async function loadThreadMessages(id, options, pageAfter, liveToolMessageIds = /* @__PURE__ */ new Map()) {
|
|
11723
|
-
const page = await listChatMessages(id, {
|
|
11724
|
-
page_size: 100,
|
|
11725
|
-
...pageAfter ? { page_after: pageAfter } : {}
|
|
11726
|
-
}, options);
|
|
11727
|
-
const pendingInteractions = page.pending_interactions.map((pending) => ({
|
|
11728
|
-
sourceMessageId: pending.source_message_id,
|
|
11729
|
-
sourcePartId: pending.source_part_id,
|
|
11730
|
-
responseTargetId: pending.response_target_id,
|
|
11731
|
-
toolCallId: liveToolMessageIds.get(pending.tool_call_id) === pending.source_message_id ? pending.tool_call_id : savedToolCallId(pending.source_message_id, pending.source_part_id, pending.response_target_id),
|
|
11732
|
-
targetTenantUserId: pending.target_tenant_user_id,
|
|
11733
|
-
targetClientId: pending.target_client_id,
|
|
11734
|
-
executionLocation: pending.execution_location
|
|
11735
|
-
}));
|
|
11736
|
-
return {
|
|
11737
|
-
...page,
|
|
11738
|
-
pendingInteractions
|
|
11739
|
-
};
|
|
11740
|
-
}
|
|
11741
|
-
function projectThreadMessages(records, pendingInteractions = [], liveToolMessageIds = /* @__PURE__ */ new Map()) {
|
|
11742
|
-
const messages = [];
|
|
11743
|
-
const calls = /* @__PURE__ */ new Map();
|
|
11744
|
-
for (const message of records) {
|
|
11745
|
-
if (message.role === "tool") {
|
|
11746
|
-
for (const part of message.parts) {
|
|
11747
|
-
const call = calls.get(savedToolCallId(message.source_assistant_message_id, message.source_tool_part_id, message.response_target_id));
|
|
11748
|
-
if (!call) continue;
|
|
11749
|
-
call.output = part.output ?? null;
|
|
11750
|
-
Object.assign(call, { resultOutcome: part.outcome });
|
|
11751
|
-
call.state = part.outcome === "succeeded" ? "complete" : "error";
|
|
11752
|
-
}
|
|
11753
|
-
continue;
|
|
11754
|
-
}
|
|
11755
|
-
const parts = message.parts.flatMap((part) => {
|
|
11756
|
-
const source = part.source;
|
|
11757
|
-
if (typeof part.type === "string" && [
|
|
11758
|
-
"image",
|
|
11759
|
-
"document",
|
|
11760
|
-
"audio",
|
|
11761
|
-
"video"
|
|
11762
|
-
].includes(part.type) && source && typeof source === "object" && !Array.isArray(source) && "type" in source && source.type === "attachment") return [{
|
|
11763
|
-
...part,
|
|
11764
|
-
source: {
|
|
11765
|
-
...source,
|
|
11766
|
-
type: "url",
|
|
11767
|
-
value: ""
|
|
11768
|
-
},
|
|
11769
|
-
fileId: "id" in source && typeof source.id === "string" ? source.id : void 0
|
|
11770
|
-
}];
|
|
11771
|
-
if (part.type !== "tool-call") return [part];
|
|
11772
|
-
if (part.executionLocation === "provider") return [part];
|
|
11773
|
-
const toolCallId = String(part.toolCallId);
|
|
11774
|
-
const targets = Array.isArray(part.targets) ? part.targets.flatMap((target) => target && typeof target === "object" && !Array.isArray(target) && "id" in target && typeof target.id === "string" ? [target.id] : []) : pendingInteractions.filter((pending) => pending.sourceMessageId === message.id && pending.sourcePartId === part.id).map((pending) => pending.responseTargetId);
|
|
11775
|
-
return (targets.length ? targets : [void 0]).map((responseTargetId) => {
|
|
11776
|
-
const savedId = savedToolCallId(message.id, String(part.id), responseTargetId);
|
|
11777
|
-
const call = {
|
|
11778
|
-
...part,
|
|
11779
|
-
savedToolTitle: part.declaration && typeof part.declaration === "object" && !Array.isArray(part.declaration) && "title" in part.declaration && typeof part.declaration.title === "string" ? part.declaration.title : void 0,
|
|
11780
|
-
id: liveToolMessageIds.get(toolCallId) === message.id ? toolCallId : savedId,
|
|
11781
|
-
upstreamToolCallId: toolCallId,
|
|
11782
|
-
applicationPartId: part.id,
|
|
11783
|
-
sourceMessageId: message.id,
|
|
11784
|
-
responseTargetId
|
|
11785
|
-
};
|
|
11786
|
-
calls.set(savedId, call);
|
|
11787
|
-
return call;
|
|
11788
|
-
});
|
|
11789
|
-
});
|
|
11790
|
-
messages.push({
|
|
11791
|
-
id: message.id,
|
|
11792
|
-
role: message.role,
|
|
11793
|
-
parts,
|
|
11794
|
-
createdAt: new Date(message.created_at),
|
|
11795
|
-
metadata: { astralbeam: {
|
|
11796
|
-
state: message.state,
|
|
11797
|
-
authorTenantUserId: message.author_tenant_user_id
|
|
11798
|
-
} }
|
|
11799
|
-
});
|
|
11800
|
-
}
|
|
11801
|
-
return messages;
|
|
11802
|
-
}
|
|
11803
|
-
/** Cache selection within this tab. Stored IDs are reauthorized before loading history. */
|
|
11804
|
-
function selectedThread(key, id) {
|
|
11805
|
-
try {
|
|
11806
|
-
if (id === void 0) return globalThis.sessionStorage?.getItem(key) ?? void 0;
|
|
11807
|
-
if (id === null) globalThis.sessionStorage?.removeItem(key);
|
|
11808
|
-
else globalThis.sessionStorage?.setItem(key, id);
|
|
11809
|
-
} catch {}
|
|
11810
|
-
}
|
|
11811
|
-
//#endregion
|
|
11812
11879
|
//#region src/core/session.ts
|
|
11813
11880
|
const HISTORY_FAILED = "Reopen this conversation or start a new one before sending.";
|
|
11814
11881
|
const CORE_OPTION_KEYS = Object.keys({
|
|
11815
11882
|
agentId: true,
|
|
11816
11883
|
threadId: true,
|
|
11884
|
+
placementKey: true,
|
|
11817
11885
|
apiUrl: true,
|
|
11818
11886
|
fetchAstralBeamToken: true,
|
|
11819
11887
|
tools: true,
|
|
@@ -11834,6 +11902,8 @@ function createAstralBeamChat(options, deferStart = false) {
|
|
|
11834
11902
|
let live = { ...options };
|
|
11835
11903
|
let debug = createDebugLogger(live.debug);
|
|
11836
11904
|
const listeners = /* @__PURE__ */ new Set();
|
|
11905
|
+
let view;
|
|
11906
|
+
const widgetOptions = () => view?.options ?? live;
|
|
11837
11907
|
let state = {
|
|
11838
11908
|
messages: [],
|
|
11839
11909
|
status: "ready",
|
|
@@ -11858,8 +11928,9 @@ function createAstralBeamChat(options, deferStart = false) {
|
|
|
11858
11928
|
let submission;
|
|
11859
11929
|
const submissions = /* @__PURE__ */ new Map();
|
|
11860
11930
|
let clientStatus = "ready";
|
|
11931
|
+
let operation;
|
|
11861
11932
|
const update = (next) => {
|
|
11862
|
-
const status = submission?.phase === "submitting"
|
|
11933
|
+
const status = operation || submission?.phase === "submitting" ? clientStatus === "streaming" || state.status === "streaming" ? "streaming" : "submitted" : clientStatus;
|
|
11863
11934
|
state = {
|
|
11864
11935
|
...state,
|
|
11865
11936
|
...next,
|
|
@@ -11867,6 +11938,11 @@ function createAstralBeamChat(options, deferStart = false) {
|
|
|
11867
11938
|
};
|
|
11868
11939
|
for (const listener of listeners) listener();
|
|
11869
11940
|
};
|
|
11941
|
+
const finishOperation = (owner) => {
|
|
11942
|
+
if (operation !== owner) return;
|
|
11943
|
+
operation = void 0;
|
|
11944
|
+
update({});
|
|
11945
|
+
};
|
|
11870
11946
|
const project = ({ id, content, phase, error }) => ({
|
|
11871
11947
|
id,
|
|
11872
11948
|
content,
|
|
@@ -11888,15 +11964,15 @@ function createAstralBeamChat(options, deferStart = false) {
|
|
|
11888
11964
|
sent.phase = phase;
|
|
11889
11965
|
sent.error = error;
|
|
11890
11966
|
if (sent === submission) update({ submission: project(sent) });
|
|
11891
|
-
if (phase === "refused") sent.onRefused?.();
|
|
11892
11967
|
return true;
|
|
11893
11968
|
};
|
|
11894
|
-
const current = (sent, attempt) => sent === submission &&
|
|
11969
|
+
const current = (sent, attempt) => sent === submission && operation === attempt;
|
|
11895
11970
|
const owns = (sent, attempt) => current(sent, attempt) && sent.phase === "submitting";
|
|
11896
11971
|
const endUnaccepted = (sent, error) => settle(sent, sent.tools ? "failed" : "refused", error ?? (sent.tools ? /* @__PURE__ */ new Error("This message may not have been sent. Retry to send it.") : void 0));
|
|
11897
11972
|
const releaseSubmission = (reason) => {
|
|
11898
11973
|
const released = submission;
|
|
11899
11974
|
if (released?.phase === "submitting") endUnaccepted(released, released.tools ? void 0 : new Error(reason));
|
|
11975
|
+
if (released?.phase === "refused") released.onRefused?.();
|
|
11900
11976
|
submission = void 0;
|
|
11901
11977
|
return released;
|
|
11902
11978
|
};
|
|
@@ -12028,25 +12104,32 @@ function createAstralBeamChat(options, deferStart = false) {
|
|
|
12028
12104
|
const renderCleanups = /* @__PURE__ */ new Map();
|
|
12029
12105
|
const restoredWidgets = /* @__PURE__ */ new Set();
|
|
12030
12106
|
const restoringWidgets = /* @__PURE__ */ new Set();
|
|
12107
|
+
let renderGeneration = 0;
|
|
12031
12108
|
const disposeRenders = () => {
|
|
12109
|
+
renderGeneration++;
|
|
12032
12110
|
for (const cleanup of renderCleanups.values()) cleanup();
|
|
12033
12111
|
renderCleanups.clear();
|
|
12034
12112
|
restoredWidgets.clear();
|
|
12035
12113
|
restoringWidgets.clear();
|
|
12036
12114
|
};
|
|
12037
12115
|
const renderWidget = async (input, toolCallId) => {
|
|
12116
|
+
if (!widgetOptions().onRenderWidget) return {
|
|
12117
|
+
widget: input.widget,
|
|
12118
|
+
rendered: false
|
|
12119
|
+
};
|
|
12038
12120
|
const generation = selectionGeneration;
|
|
12039
|
-
const
|
|
12121
|
+
const rendering = renderGeneration;
|
|
12122
|
+
const widgets = widgetOptions().widgets ?? {};
|
|
12040
12123
|
if (!Object.hasOwn(widgets, input.widget)) throw new Error(`Unknown widget "${input.widget}"`);
|
|
12041
12124
|
const declaration = widgets[input.widget];
|
|
12042
12125
|
const validated = await validateParameters(declaration?.parameters, input.props ?? {});
|
|
12043
|
-
if (generation !== selectionGeneration || state.thread?.role === "viewer") return {
|
|
12126
|
+
if (generation !== selectionGeneration || rendering !== renderGeneration || state.thread?.role === "viewer") return {
|
|
12044
12127
|
widget: input.widget,
|
|
12045
12128
|
rendered: false
|
|
12046
12129
|
};
|
|
12047
|
-
if (declaration !==
|
|
12130
|
+
if (declaration !== widgetOptions().widgets?.[input.widget]) return renderWidget(input, toolCallId);
|
|
12048
12131
|
if (validated == null) throw new Error(`Props for widget "${input.widget}" failed validation`);
|
|
12049
|
-
const onRenderWidget =
|
|
12132
|
+
const onRenderWidget = widgetOptions().onRenderWidget;
|
|
12050
12133
|
if (!onRenderWidget) return {
|
|
12051
12134
|
widget: input.widget,
|
|
12052
12135
|
rendered: false
|
|
@@ -12122,17 +12205,18 @@ function createAstralBeamChat(options, deferStart = false) {
|
|
|
12122
12205
|
if (restoredWidgets.has(renderId) || restoringWidgets.has(renderId)) continue;
|
|
12123
12206
|
restoringWidgets.add(renderId);
|
|
12124
12207
|
const generation = selectionGeneration;
|
|
12125
|
-
const
|
|
12208
|
+
const rendering = renderGeneration;
|
|
12209
|
+
const { widgets, onRenderWidget } = widgetOptions();
|
|
12126
12210
|
renderWidget(part.input, renderId).catch((error) => debug?.("error", "Saved widget could not be rendered", error)).finally(() => {
|
|
12127
|
-
if (generation !== selectionGeneration) return;
|
|
12211
|
+
if (generation !== selectionGeneration || rendering !== renderGeneration) return;
|
|
12128
12212
|
restoringWidgets.delete(renderId);
|
|
12129
|
-
if (widgets !==
|
|
12213
|
+
if (widgets !== widgetOptions().widgets || onRenderWidget !== widgetOptions().onRenderWidget) restoreCompletedWidgets(state.messages);
|
|
12130
12214
|
});
|
|
12131
12215
|
}
|
|
12132
12216
|
};
|
|
12133
12217
|
const buildTools = () => {
|
|
12134
12218
|
const selection = selectionGeneration;
|
|
12135
|
-
return buildAgentTools(
|
|
12219
|
+
return buildAgentTools(widgetOptions().widgets ?? {}, live.tools ?? {}, renderWidget, debug, (name, declaration, toolCallId) => {
|
|
12136
12220
|
const execution = toolExecutionGeneration;
|
|
12137
12221
|
const executingClient = client;
|
|
12138
12222
|
const executingIdentity = identity;
|
|
@@ -12511,6 +12595,7 @@ function createAstralBeamChat(options, deferStart = false) {
|
|
|
12511
12595
|
};
|
|
12512
12596
|
const replaceClient = (messages) => {
|
|
12513
12597
|
const previous = client;
|
|
12598
|
+
operation = void 0;
|
|
12514
12599
|
unsubscribeSnapshot?.();
|
|
12515
12600
|
unsubscribeSnapshot = void 0;
|
|
12516
12601
|
snapshotMessages = void 0;
|
|
@@ -12539,7 +12624,7 @@ function createAstralBeamChat(options, deferStart = false) {
|
|
|
12539
12624
|
...part,
|
|
12540
12625
|
upstreamToolCallId,
|
|
12541
12626
|
id,
|
|
12542
|
-
...part.name === "render_widget"
|
|
12627
|
+
...part.name === "render_widget" ? { widgetRenderId: stored.widgetRenderId ?? messagePresentation.get(message.id)?.renderIds?.get(savedToolCallId(message.id, part.id)) ?? part.id } : {}
|
|
12543
12628
|
};
|
|
12544
12629
|
});
|
|
12545
12630
|
if (aliases.size) historicalToolIds.set(message.id, aliases);
|
|
@@ -12617,8 +12702,10 @@ function createAstralBeamChat(options, deferStart = false) {
|
|
|
12617
12702
|
if (!threadKey) return;
|
|
12618
12703
|
selected = selectedThread(threadKey);
|
|
12619
12704
|
}
|
|
12620
|
-
if (selected && selected !== "new")
|
|
12621
|
-
|
|
12705
|
+
if (selected && selected !== "new") {
|
|
12706
|
+
if (selected === state.thread?.id && threadKey) selectedThread(threadKey, selected);
|
|
12707
|
+
else openThread(selected, restoring);
|
|
12708
|
+
} else if (!restoring) newThread();
|
|
12622
12709
|
};
|
|
12623
12710
|
const ensureThread = async (sent, attempt) => {
|
|
12624
12711
|
if (state.thread) return;
|
|
@@ -12689,7 +12776,7 @@ function createAstralBeamChat(options, deferStart = false) {
|
|
|
12689
12776
|
};
|
|
12690
12777
|
const addToolResult = async (result) => {
|
|
12691
12778
|
const generation = selectionGeneration;
|
|
12692
|
-
if (submission?.phase === "submitting" || client.getIsLoading()) {
|
|
12779
|
+
if (operation || submission?.phase === "submitting" || client.getIsLoading()) {
|
|
12693
12780
|
reportError(/* @__PURE__ */ new Error("Wait for this client's current request to finish before responding."));
|
|
12694
12781
|
return;
|
|
12695
12782
|
}
|
|
@@ -12712,22 +12799,30 @@ function createAstralBeamChat(options, deferStart = false) {
|
|
|
12712
12799
|
output: output ?? null
|
|
12713
12800
|
});
|
|
12714
12801
|
}
|
|
12715
|
-
|
|
12716
|
-
|
|
12717
|
-
|
|
12718
|
-
|
|
12719
|
-
|
|
12720
|
-
|
|
12721
|
-
|
|
12722
|
-
|
|
12723
|
-
|
|
12724
|
-
|
|
12725
|
-
|
|
12726
|
-
|
|
12802
|
+
const owner = operation = {};
|
|
12803
|
+
try {
|
|
12804
|
+
update({});
|
|
12805
|
+
if (operation !== owner) return;
|
|
12806
|
+
scopeCompletedToolCalls();
|
|
12807
|
+
if (pending) {
|
|
12808
|
+
client.stop();
|
|
12809
|
+
await refreshThread(false);
|
|
12810
|
+
if (operation !== owner || generation !== selectionGeneration) return;
|
|
12811
|
+
await client.append({
|
|
12812
|
+
role: "tool",
|
|
12813
|
+
toolCallId: result.toolCallId,
|
|
12814
|
+
content: JSON.stringify(toolResults.get(toolResultKey(result.toolCallId)))
|
|
12815
|
+
});
|
|
12816
|
+
} else if ("tool" in result) await client.addToolResult(result);
|
|
12817
|
+
if (operation === owner && generation === selectionGeneration) await refreshThread(false);
|
|
12818
|
+
} finally {
|
|
12819
|
+
finishOperation(owner);
|
|
12820
|
+
}
|
|
12727
12821
|
};
|
|
12728
12822
|
const abandonToolCall = (toolCallId) => addToolResult({ toolCallId });
|
|
12729
12823
|
const deliver = async (sent) => {
|
|
12730
|
-
|
|
12824
|
+
if (sent !== submission || sent.phase !== "submitting") return project(sent);
|
|
12825
|
+
const attempt = operation = {};
|
|
12731
12826
|
try {
|
|
12732
12827
|
await getValidChatAuthToken(authentication);
|
|
12733
12828
|
await hydration.catch(() => void 0);
|
|
@@ -12747,11 +12842,13 @@ function createAstralBeamChat(options, deferStart = false) {
|
|
|
12747
12842
|
const failure = error instanceof Error ? error : new Error(String(error));
|
|
12748
12843
|
if (failure.name === "AbortError") endUnaccepted(sent);
|
|
12749
12844
|
else if (endUnaccepted(sent, failure)) notifyError(failure);
|
|
12845
|
+
} finally {
|
|
12846
|
+
finishOperation(attempt);
|
|
12750
12847
|
}
|
|
12751
12848
|
return project(sent);
|
|
12752
12849
|
};
|
|
12753
12850
|
const sendMessage = async (content, callbacks) => {
|
|
12754
|
-
const rejection = submission?.phase === "submitting" ||
|
|
12851
|
+
const rejection = operation || submission?.phase === "submitting" || client.getIsLoading() ? "Wait for this client's current request to finish before sending." : state.history === "loading" ? "Wait for this conversation to load before sending." : state.history === "failed" ? HISTORY_FAILED : state.thread?.agentId === null ? "This conversation’s agent is unavailable. Start a new conversation to continue." : state.thread?.role === "viewer" ? "You have read-only access to this conversation." : submission?.phase === "failed" ? "The previous message’s acceptance is unconfirmed. Retry that message before sending different text, or start a new conversation." : void 0;
|
|
12755
12852
|
if (rejection) return {
|
|
12756
12853
|
id: newUuid(),
|
|
12757
12854
|
content,
|
|
@@ -12763,8 +12860,7 @@ function createAstralBeamChat(options, deferStart = false) {
|
|
|
12763
12860
|
content,
|
|
12764
12861
|
phase: "submitting",
|
|
12765
12862
|
key: newUuid(),
|
|
12766
|
-
callbacks
|
|
12767
|
-
attempt: 0
|
|
12863
|
+
callbacks
|
|
12768
12864
|
};
|
|
12769
12865
|
submission = sent;
|
|
12770
12866
|
update({
|
|
@@ -12781,9 +12877,10 @@ function createAstralBeamChat(options, deferStart = false) {
|
|
|
12781
12877
|
return Promise.race([deliver(sent), refused.then(() => project(sent))]);
|
|
12782
12878
|
};
|
|
12783
12879
|
const retry = async () => {
|
|
12784
|
-
|
|
12880
|
+
const sent = submission;
|
|
12881
|
+
if (operation || client.getIsLoading() || !sent || !settle(sent, "submitting")) return void 0;
|
|
12785
12882
|
update({ error: void 0 });
|
|
12786
|
-
return deliver(
|
|
12883
|
+
return deliver(sent);
|
|
12787
12884
|
};
|
|
12788
12885
|
const observeAuthentication = () => {
|
|
12789
12886
|
const auth = authenticationState(authentication);
|
|
@@ -12795,9 +12892,12 @@ function createAstralBeamChat(options, deferStart = false) {
|
|
|
12795
12892
|
submissions.clear();
|
|
12796
12893
|
threadToolResults.clear();
|
|
12797
12894
|
toolResults.clear();
|
|
12895
|
+
changeSelection();
|
|
12896
|
+
threadKey = void 0;
|
|
12798
12897
|
}
|
|
12799
12898
|
identity = nextIdentity;
|
|
12800
|
-
const
|
|
12899
|
+
const scope = JSON.stringify(chatPlacementKey(live));
|
|
12900
|
+
const nextThreadKey = `astralbeam:thread:${live.apiUrl ?? "https://astralbeam.ai/api"}:${nextIdentity}:session:${scope}`;
|
|
12801
12901
|
if (threadKey !== nextThreadKey) {
|
|
12802
12902
|
if (threadKey !== void 0) changeSelection();
|
|
12803
12903
|
threadKey = nextThreadKey;
|
|
@@ -12830,6 +12930,32 @@ function createAstralBeamChat(options, deferStart = false) {
|
|
|
12830
12930
|
return {
|
|
12831
12931
|
start,
|
|
12832
12932
|
getState: () => state,
|
|
12933
|
+
getOptions: () => live,
|
|
12934
|
+
attachView: (options) => {
|
|
12935
|
+
if (view) throw new Error("This chat session already has a view attached");
|
|
12936
|
+
const binding = { options };
|
|
12937
|
+
const refresh = () => {
|
|
12938
|
+
client.updateOptions({ tools: declareTools() });
|
|
12939
|
+
restoreCompletedWidgets(state.messages);
|
|
12940
|
+
};
|
|
12941
|
+
disposeRenders();
|
|
12942
|
+
view = binding;
|
|
12943
|
+
refresh();
|
|
12944
|
+
return {
|
|
12945
|
+
update: (next) => {
|
|
12946
|
+
if (view !== binding) return;
|
|
12947
|
+
const previous = binding.options;
|
|
12948
|
+
binding.options = next;
|
|
12949
|
+
if (previous.widgets !== next.widgets || previous.onRenderWidget !== next.onRenderWidget) refresh();
|
|
12950
|
+
},
|
|
12951
|
+
dispose: () => {
|
|
12952
|
+
if (view !== binding) return;
|
|
12953
|
+
disposeRenders();
|
|
12954
|
+
view = void 0;
|
|
12955
|
+
refresh();
|
|
12956
|
+
}
|
|
12957
|
+
};
|
|
12958
|
+
},
|
|
12833
12959
|
subscribe: (listener) => {
|
|
12834
12960
|
listeners.add(listener);
|
|
12835
12961
|
return () => listeners.delete(listener);
|
|
@@ -12838,11 +12964,13 @@ function createAstralBeamChat(options, deferStart = false) {
|
|
|
12838
12964
|
const agent = live.agentId;
|
|
12839
12965
|
const apiUrl = live.apiUrl;
|
|
12840
12966
|
const selectedId = live.threadId;
|
|
12967
|
+
const placementKey = chatPlacementKey(live);
|
|
12841
12968
|
const { widgets, onRenderWidget } = live;
|
|
12842
12969
|
live = {
|
|
12843
12970
|
...live,
|
|
12844
12971
|
...next
|
|
12845
12972
|
};
|
|
12973
|
+
const placementChanged = chatPlacementKey(live) !== placementKey;
|
|
12846
12974
|
debug = createDebugLogger(live.debug);
|
|
12847
12975
|
updateAuthentication(authentication, {
|
|
12848
12976
|
apiUrl: live.apiUrl,
|
|
@@ -12861,17 +12989,26 @@ function createAstralBeamChat(options, deferStart = false) {
|
|
|
12861
12989
|
changeSelection();
|
|
12862
12990
|
threadKey = void 0;
|
|
12863
12991
|
observeAuthentication();
|
|
12992
|
+
} else if (placementChanged) {
|
|
12993
|
+
startWithNewThread = false;
|
|
12994
|
+
if (!state.thread || live.threadId !== state.thread.id) changeSelection();
|
|
12995
|
+
threadKey = void 0;
|
|
12996
|
+
observeAuthentication();
|
|
12864
12997
|
} else if (live.threadId !== selectedId) selectConfiguredThread();
|
|
12865
12998
|
if (widgets !== live.widgets || onRenderWidget !== live.onRenderWidget) restoreCompletedWidgets(state.messages);
|
|
12866
|
-
if (started && (live.agentId !== agent || live.apiUrl !== apiUrl)) resolveCapabilities();
|
|
12999
|
+
if (started && (live.agentId !== agent || live.apiUrl !== apiUrl || placementChanged)) resolveCapabilities();
|
|
12867
13000
|
},
|
|
12868
13001
|
sendMessage,
|
|
12869
13002
|
retry,
|
|
12870
13003
|
addToolResult,
|
|
12871
13004
|
stop: () => {
|
|
12872
13005
|
toolExecutionGeneration++;
|
|
12873
|
-
|
|
13006
|
+
const stopped = submission;
|
|
13007
|
+
const owner = operation;
|
|
13008
|
+
if (stopped?.phase === "submitting") endUnaccepted(stopped);
|
|
12874
13009
|
client.stop();
|
|
13010
|
+
if (owner) finishOperation(owner);
|
|
13011
|
+
if (stopped?.phase === "refused") stopped.onRefused?.();
|
|
12875
13012
|
},
|
|
12876
13013
|
retryAuthentication: () => {
|
|
12877
13014
|
getValidChatAuthToken({
|
|
@@ -12928,9 +13065,11 @@ function createAstralBeamChat(options, deferStart = false) {
|
|
|
12928
13065
|
},
|
|
12929
13066
|
getThreadAttachment: async (params, options) => {
|
|
12930
13067
|
if (!params.threadId && !options?.preview) throw new Error("A conversation ID is required to download files.");
|
|
12931
|
-
return (await getThreadAttachment(
|
|
13068
|
+
return (await getThreadAttachment({
|
|
13069
|
+
...params,
|
|
13070
|
+
delivery: "direct"
|
|
13071
|
+
}, {
|
|
12932
13072
|
...await requestOptions(!!params.threadId || !options?.preview),
|
|
12933
|
-
cache: "default",
|
|
12934
13073
|
headers: options?.preview ? { "X-File-Preview": "true" } : {}
|
|
12935
13074
|
})).blob();
|
|
12936
13075
|
},
|
|
@@ -12949,9 +13088,23 @@ function createAstralBeamChat(options, deferStart = false) {
|
|
|
12949
13088
|
reset: () => {
|
|
12950
13089
|
debug?.("status", "conversation reset");
|
|
12951
13090
|
newThread();
|
|
13091
|
+
if (state.auth.status === "ready") {
|
|
13092
|
+
const draftIdentity = JSON.stringify([identity, chatPlacementKey(live)]);
|
|
13093
|
+
const apiUrl = live.apiUrl ?? "https://astralbeam.ai/api";
|
|
13094
|
+
storedThreadDraft(apiUrl, draftIdentity, "", "");
|
|
13095
|
+
storedThreadDraft(apiUrl, draftIdentity, "", "", "sent");
|
|
13096
|
+
storedThreadAttachments({
|
|
13097
|
+
apiUrl,
|
|
13098
|
+
identity: draftIdentity,
|
|
13099
|
+
threadId: "",
|
|
13100
|
+
update: () => []
|
|
13101
|
+
}).catch((error) => debug?.("error", "Draft could not be cleared", error));
|
|
13102
|
+
}
|
|
13103
|
+
view?.options.onReset();
|
|
12952
13104
|
},
|
|
12953
13105
|
dispose: () => {
|
|
12954
13106
|
releaseSubmission("The chat closed before this was sent.");
|
|
13107
|
+
operation = void 0;
|
|
12955
13108
|
unsubscribeSnapshot?.();
|
|
12956
13109
|
unsubscribeSnapshot = void 0;
|
|
12957
13110
|
client.detach();
|