@noodleseed/assistant 1.25.0 → 1.25.1
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 +9 -4
- package/dist/{app-view-element-BM4lral-.d.ts → app-view-element-BNkQab1B.d.ts} +1 -2
- package/dist/{app-view-element-9ojWWYov.d.cts → app-view-element-DhuiNW_x.d.cts} +1 -2
- package/dist/app-view.cjs +36 -208
- package/dist/app-view.cjs.map +1 -1
- package/dist/app-view.d.cts +1 -1
- package/dist/app-view.d.ts +1 -1
- package/dist/app-view.js +2 -2
- package/dist/{chunk-LNBUYHL7.js → chunk-5TYS2Q6S.js} +2 -2
- package/dist/chunk-5TYS2Q6S.js.map +1 -0
- package/dist/{chunk-P32MAR4K.js → chunk-CF2SCDLF.js} +37 -209
- package/dist/chunk-CF2SCDLF.js.map +1 -0
- package/dist/{chunk-SGMECNNU.js → chunk-FJYPE4GC.js} +2 -2
- package/dist/embed.global.js +91 -124
- package/dist/index.cjs +58 -230
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/react.cjs +58 -230
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +3 -3
- package/package.json +1 -1
- package/dist/chunk-LNBUYHL7.js.map +0 -1
- package/dist/chunk-P32MAR4K.js.map +0 -1
- /package/dist/{chunk-SGMECNNU.js.map → chunk-FJYPE4GC.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -21798,15 +21798,6 @@ var E = class {
|
|
|
21798
21798
|
sessionId;
|
|
21799
21799
|
setProtocolVersion;
|
|
21800
21800
|
};
|
|
21801
|
-
function AZ(X2) {
|
|
21802
|
-
if (!X2) return "";
|
|
21803
|
-
let Y = [];
|
|
21804
|
-
if (X2.camera) Y.push("camera");
|
|
21805
|
-
if (X2.microphone) Y.push("microphone");
|
|
21806
|
-
if (X2.geolocation) Y.push("geolocation");
|
|
21807
|
-
if (X2.clipboardWrite) Y.push("clipboard-write");
|
|
21808
|
-
return Y.join("; ");
|
|
21809
|
-
}
|
|
21810
21801
|
var KX = [j];
|
|
21811
21802
|
var DX = class extends _ {
|
|
21812
21803
|
_client;
|
|
@@ -22077,131 +22068,34 @@ function GX(X2, Y) {
|
|
|
22077
22068
|
return JSON.stringify(X2) === JSON.stringify(Y);
|
|
22078
22069
|
}
|
|
22079
22070
|
|
|
22080
|
-
// src/app-sandbox-policy.ts
|
|
22081
|
-
var MAX_DOMAINS_PER_DIRECTIVE = 32;
|
|
22082
|
-
function isRecord(value) {
|
|
22083
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22084
|
-
}
|
|
22085
|
-
function isLoopback(hostname3) {
|
|
22086
|
-
return hostname3 === "localhost" || hostname3 === "127.0.0.1" || hostname3 === "[::1]";
|
|
22087
|
-
}
|
|
22088
|
-
function normalizeDomain(value, connect) {
|
|
22089
|
-
if (value.length > 512 || /[;\r\n'"\s]/u.test(value)) return void 0;
|
|
22090
|
-
try {
|
|
22091
|
-
const parsed = new URL(value);
|
|
22092
|
-
const secure = parsed.protocol === "https:" || connect && parsed.protocol === "wss:";
|
|
22093
|
-
const local = isLoopback(parsed.hostname) && (parsed.protocol === "http:" || connect && parsed.protocol === "ws:");
|
|
22094
|
-
if (!secure && !local) return void 0;
|
|
22095
|
-
if (parsed.username || parsed.password || parsed.pathname !== "/" || parsed.search || parsed.hash) {
|
|
22096
|
-
return void 0;
|
|
22097
|
-
}
|
|
22098
|
-
return parsed.origin;
|
|
22099
|
-
} catch {
|
|
22100
|
-
return void 0;
|
|
22101
|
-
}
|
|
22102
|
-
}
|
|
22103
|
-
function normalizeDomains(values, connect) {
|
|
22104
|
-
const normalized = [
|
|
22105
|
-
...new Set(
|
|
22106
|
-
values.slice(0, MAX_DOMAINS_PER_DIRECTIVE).map((value) => typeof value === "string" ? normalizeDomain(value, connect) : void 0).filter((value) => value !== void 0)
|
|
22107
|
-
)
|
|
22108
|
-
];
|
|
22109
|
-
return normalized;
|
|
22110
|
-
}
|
|
22111
|
-
function resolveAssistantAppSandboxPolicy(resourceMeta) {
|
|
22112
|
-
if (!isRecord(resourceMeta)) return {};
|
|
22113
|
-
const rawCsp = resourceMeta.csp;
|
|
22114
|
-
const csp = isRecord(rawCsp) ? {
|
|
22115
|
-
...Array.isArray(rawCsp.connectDomains) ? { connectDomains: normalizeDomains(rawCsp.connectDomains, true) } : {},
|
|
22116
|
-
...Array.isArray(rawCsp.resourceDomains) ? { resourceDomains: normalizeDomains(rawCsp.resourceDomains, false) } : {},
|
|
22117
|
-
...Array.isArray(rawCsp.frameDomains) ? { frameDomains: normalizeDomains(rawCsp.frameDomains, false) } : {},
|
|
22118
|
-
...Array.isArray(rawCsp.baseUriDomains) ? { baseUriDomains: normalizeDomains(rawCsp.baseUriDomains, false) } : {}
|
|
22119
|
-
} : void 0;
|
|
22120
|
-
const rawPermissions = resourceMeta.permissions;
|
|
22121
|
-
const permissions = isRecord(rawPermissions) ? {
|
|
22122
|
-
...isRecord(rawPermissions.camera) ? { camera: {} } : {},
|
|
22123
|
-
...isRecord(rawPermissions.microphone) ? { microphone: {} } : {},
|
|
22124
|
-
...isRecord(rawPermissions.geolocation) ? { geolocation: {} } : {},
|
|
22125
|
-
...isRecord(rawPermissions.clipboardWrite) ? { clipboardWrite: {} } : {}
|
|
22126
|
-
} : void 0;
|
|
22127
|
-
const allowAttribute = AZ(permissions);
|
|
22128
|
-
return {
|
|
22129
|
-
...csp === void 0 ? {} : { csp },
|
|
22130
|
-
...permissions === void 0 ? {} : { permissions },
|
|
22131
|
-
...allowAttribute ? { allowAttribute } : {}
|
|
22132
|
-
};
|
|
22133
|
-
}
|
|
22134
|
-
function assistantAppSandboxUrl(sandboxUrl, policy) {
|
|
22135
|
-
const parsed = new URL(sandboxUrl);
|
|
22136
|
-
if (policy.csp) parsed.searchParams.set("csp", JSON.stringify(policy.csp));
|
|
22137
|
-
const parentOrigin = globalThis.location?.origin;
|
|
22138
|
-
if (parentOrigin && parentOrigin !== "null") {
|
|
22139
|
-
parsed.hash = new URLSearchParams({ parentOrigin }).toString();
|
|
22140
|
-
}
|
|
22141
|
-
return parsed.href;
|
|
22142
|
-
}
|
|
22143
|
-
|
|
22144
22071
|
// src/app-host.ts
|
|
22145
|
-
var PROXY_DOCUMENT = `<!doctype html><meta charset="utf-8"><style>html,body,iframe{border:0;margin:0;width:100%;height:100%;overflow:hidden}body{background:transparent}</style><
|
|
22146
|
-
let inner
|
|
22147
|
-
if(self===top)throw new Error('The assistant sandbox relay must be embedded');
|
|
22148
|
-
const standardSandbox='allow-scripts allow-same-origin allow-forms';
|
|
22149
|
-
const rawParentOrigin=new URLSearchParams(location.hash.slice(1)).get('parentOrigin');
|
|
22150
|
-
let expectedParentOrigin;
|
|
22151
|
-
try{const parsed=new URL(rawParentOrigin||'');if(parsed.origin===rawParentOrigin&&/^https?:$/.test(parsed.protocol))expectedParentOrigin=parsed.origin}catch{}
|
|
22152
|
-
const parentTarget=expectedParentOrigin||'*';
|
|
22153
|
-
const ownOrigin=self.origin;
|
|
22072
|
+
var PROXY_DOCUMENT = `<!doctype html><meta charset="utf-8"><style>html,body,iframe{border:0;margin:0;width:100%;height:100%;overflow:hidden}body{background:transparent}</style><script>
|
|
22073
|
+
let inner;
|
|
22154
22074
|
const ready={jsonrpc:'2.0',method:'ui/notifications/sandbox-proxy-ready',params:{}};
|
|
22155
22075
|
// Re-announce until the host acknowledges with the resource: when this document is hosted
|
|
22156
22076
|
// cross-origin, the first announcement can arrive before the host's load handler is listening.
|
|
22157
|
-
const announce=setInterval(()=>parent.postMessage(ready,
|
|
22077
|
+
const announce=setInterval(()=>parent.postMessage(ready,'*'),120);
|
|
22158
22078
|
setTimeout(()=>clearInterval(announce),15000);
|
|
22159
22079
|
addEventListener('message',(event)=>{
|
|
22160
22080
|
if(event.source===parent){
|
|
22161
|
-
if(expectedParentOrigin&&event.origin!==expectedParentOrigin)return;
|
|
22162
22081
|
const message=event.data;
|
|
22163
22082
|
if(message?.method==='ui/notifications/sandbox-resource-ready'){
|
|
22164
22083
|
clearInterval(announce);
|
|
22165
|
-
if(
|
|
22166
|
-
loaded=true;
|
|
22167
|
-
const requestedSandbox=message.params?.sandbox;
|
|
22084
|
+
if(inner)return;
|
|
22168
22085
|
inner=document.createElement('iframe');
|
|
22169
|
-
inner.setAttribute('sandbox',
|
|
22086
|
+
inner.setAttribute('sandbox',message.params?.sandbox||'allow-scripts');
|
|
22170
22087
|
inner.setAttribute('referrerpolicy','no-referrer');
|
|
22171
|
-
|
|
22172
|
-
|
|
22173
|
-
if(permissions?.camera)allow.push('camera');
|
|
22174
|
-
if(permissions?.microphone)allow.push('microphone');
|
|
22175
|
-
if(permissions?.geolocation)allow.push('geolocation');
|
|
22176
|
-
if(permissions?.clipboardWrite)allow.push('clipboard-write');
|
|
22177
|
-
if(allow.length)inner.setAttribute('allow',allow.join('; '));
|
|
22178
|
-
document.body.append(inner);
|
|
22179
|
-
let html=String(message.params?.html||'');
|
|
22180
|
-
const csp=message.params?.csp;
|
|
22181
|
-
if(csp&&typeof csp==='object'){
|
|
22182
|
-
const list=(value,fallback)=>Array.isArray(value)&&value.length?value.join(' '):fallback;
|
|
22183
|
-
const resources=Array.isArray(csp.resourceDomains)?csp.resourceDomains:[];
|
|
22184
|
-
const suffix=resources.length?' '+resources.join(' '):'';
|
|
22185
|
-
const policy=["default-src 'none'","script-src 'unsafe-inline'"+suffix,"style-src 'unsafe-inline'"+suffix,'img-src data: blob:'+suffix,'font-src data: blob:'+suffix,'media-src data: blob:'+suffix,'worker-src blob:'+suffix,'connect-src '+list(csp.connectDomains,"'none'"),'frame-src '+list(csp.frameDomains,"'none'"),"object-src 'none'","form-action 'none'",'base-uri '+list(csp.baseUriDomains,"'none'")].join('; ');
|
|
22186
|
-
const meta='<meta http-equiv="Content-Security-Policy" content="'+policy.replace(/&/g,'&').replace(/"/g,'"')+'">';
|
|
22187
|
-
const doctype=html.match(/^\\s*<!doctype[^>]*>/i);
|
|
22188
|
-
html=doctype?html.slice(0,doctype[0].length)+meta+html.slice(doctype[0].length):meta+html;
|
|
22189
|
-
}
|
|
22190
|
-
try{
|
|
22191
|
-
const doc=inner.contentDocument||inner.contentWindow?.document;
|
|
22192
|
-
if(!doc)throw new Error('document unavailable');
|
|
22193
|
-
doc.open();doc.write(html);doc.close();
|
|
22194
|
-
}catch{inner.srcdoc=html}
|
|
22088
|
+
inner.srcdoc=String(message.params?.html||'');
|
|
22089
|
+
document.body.replaceChildren(inner);
|
|
22195
22090
|
return;
|
|
22196
22091
|
}
|
|
22197
22092
|
inner?.contentWindow?.postMessage(message,'*');
|
|
22198
22093
|
} else if(inner && event.source===inner.contentWindow) {
|
|
22199
|
-
|
|
22200
|
-
parent.postMessage(event.data,parentTarget);
|
|
22094
|
+
parent.postMessage(event.data,'*');
|
|
22201
22095
|
}
|
|
22202
22096
|
});
|
|
22203
|
-
parent.postMessage(ready,
|
|
22204
|
-
</script
|
|
22097
|
+
parent.postMessage(ready,'*');
|
|
22098
|
+
</script>`;
|
|
22205
22099
|
function isAllowedAppLink(value, allowedDomains, baseUrl) {
|
|
22206
22100
|
try {
|
|
22207
22101
|
const parsed = new URL(value, baseUrl);
|
|
@@ -22228,42 +22122,16 @@ function createAssistantAppHostContext(theme, allowFullscreen = false, displayMo
|
|
|
22228
22122
|
}
|
|
22229
22123
|
var APP_RENDER_TIMEOUT_MS = 1e4;
|
|
22230
22124
|
var APP_TEARDOWN_TIMEOUT_MS = 1e3;
|
|
22231
|
-
var STANDARD_SANDBOX = "allow-scripts allow-same-origin allow-forms";
|
|
22232
22125
|
var mountedApps = /* @__PURE__ */ new WeakMap();
|
|
22233
22126
|
function resolveSandboxUrl(value) {
|
|
22234
22127
|
if (!value) return void 0;
|
|
22235
22128
|
try {
|
|
22236
22129
|
const parsed = new URL(value);
|
|
22237
|
-
|
|
22238
|
-
const permittedProtocol = parsed.protocol === "https:" || parsed.protocol === "http:" && loopback;
|
|
22239
|
-
const embedderOrigin = globalThis.location?.origin;
|
|
22240
|
-
if (!permittedProtocol || embedderOrigin && embedderOrigin !== "null" && parsed.origin === embedderOrigin) {
|
|
22241
|
-
return void 0;
|
|
22242
|
-
}
|
|
22243
|
-
return parsed.href;
|
|
22130
|
+
return parsed.protocol === "https:" || parsed.protocol === "http:" ? parsed.href : void 0;
|
|
22244
22131
|
} catch {
|
|
22245
22132
|
return void 0;
|
|
22246
22133
|
}
|
|
22247
22134
|
}
|
|
22248
|
-
function copyAppJson(value, depth = 0) {
|
|
22249
|
-
if (depth > 64) throw new Error("App payload nesting exceeds the host limit");
|
|
22250
|
-
if (value === null || typeof value === "string" || typeof value === "boolean") return value;
|
|
22251
|
-
if (typeof value === "number") {
|
|
22252
|
-
if (!Number.isFinite(value)) throw new Error("App payload numbers must be finite");
|
|
22253
|
-
return value;
|
|
22254
|
-
}
|
|
22255
|
-
if (Array.isArray(value)) return value.map((entry) => copyAppJson(entry, depth + 1));
|
|
22256
|
-
const copied = {};
|
|
22257
|
-
for (const [key, entry] of Object.entries(value)) {
|
|
22258
|
-
Object.defineProperty(copied, key, {
|
|
22259
|
-
value: copyAppJson(entry, depth + 1),
|
|
22260
|
-
enumerable: true,
|
|
22261
|
-
configurable: true,
|
|
22262
|
-
writable: true
|
|
22263
|
-
});
|
|
22264
|
-
}
|
|
22265
|
-
return copied;
|
|
22266
|
-
}
|
|
22267
22135
|
function mountAssistantApp(detail, actions, options = {}) {
|
|
22268
22136
|
if (!detail.html) return void 0;
|
|
22269
22137
|
const card = document.createElement("section");
|
|
@@ -22284,25 +22152,16 @@ function mountAssistantApp(detail, actions, options = {}) {
|
|
|
22284
22152
|
const frame = document.createElement("iframe");
|
|
22285
22153
|
frame.className = "noodle-app-frame";
|
|
22286
22154
|
frame.title = detail.title ?? detail.tool;
|
|
22287
|
-
|
|
22155
|
+
frame.setAttribute("sandbox", "allow-scripts");
|
|
22288
22156
|
frame.setAttribute("referrerpolicy", "no-referrer");
|
|
22289
22157
|
const sandboxUrl = resolveSandboxUrl(options.sandboxUrl);
|
|
22290
|
-
|
|
22291
|
-
|
|
22292
|
-
frame.setAttribute("sandbox", STANDARD_SANDBOX);
|
|
22293
|
-
if (policy.allowAttribute) frame.setAttribute("allow", policy.allowAttribute);
|
|
22294
|
-
frame.src = assistantAppSandboxUrl(sandboxUrl, policy);
|
|
22295
|
-
} else {
|
|
22296
|
-
frame.setAttribute("sandbox", "allow-scripts");
|
|
22297
|
-
frame.srcdoc = PROXY_DOCUMENT;
|
|
22298
|
-
}
|
|
22158
|
+
if (sandboxUrl) frame.src = sandboxUrl;
|
|
22159
|
+
else frame.srcdoc = PROXY_DOCUMENT;
|
|
22299
22160
|
card.append(frame);
|
|
22300
22161
|
let mountedBridge;
|
|
22301
22162
|
let mountedTransport;
|
|
22302
22163
|
let destroyed = false;
|
|
22303
22164
|
let initialized = false;
|
|
22304
|
-
let renderFailed = false;
|
|
22305
|
-
let renderStage = "sandbox_load";
|
|
22306
22165
|
let currentTheme = actions.theme;
|
|
22307
22166
|
let displayMode = "inline";
|
|
22308
22167
|
let hostContext = createAssistantAppHostContext(
|
|
@@ -22311,15 +22170,6 @@ function mountAssistantApp(detail, actions, options = {}) {
|
|
|
22311
22170
|
displayMode
|
|
22312
22171
|
);
|
|
22313
22172
|
let destroyPromise;
|
|
22314
|
-
let transportClosePromise;
|
|
22315
|
-
let renderTimer;
|
|
22316
|
-
const closeTransport = () => {
|
|
22317
|
-
if (transportClosePromise) return transportClosePromise;
|
|
22318
|
-
const closing = mountedTransport?.close().catch(() => {
|
|
22319
|
-
}) ?? Promise.resolve();
|
|
22320
|
-
transportClosePromise = closing;
|
|
22321
|
-
return closing;
|
|
22322
|
-
};
|
|
22323
22173
|
const applyDisplayMode = (requestedMode) => {
|
|
22324
22174
|
displayMode = requestedMode === "fullscreen" && options.allowFullscreen === true ? "fullscreen" : "inline";
|
|
22325
22175
|
card.toggleAttribute("data-fullscreen", displayMode === "fullscreen");
|
|
@@ -22337,26 +22187,18 @@ function mountAssistantApp(detail, actions, options = {}) {
|
|
|
22337
22187
|
applyDisplayMode("inline");
|
|
22338
22188
|
frame.focus();
|
|
22339
22189
|
});
|
|
22340
|
-
const
|
|
22341
|
-
if (
|
|
22342
|
-
return;
|
|
22343
|
-
renderFailed = true;
|
|
22344
|
-
clearTimeout(renderTimer);
|
|
22190
|
+
const renderTimer = setTimeout(() => {
|
|
22191
|
+
if (initialized || !frame.isConnected) return;
|
|
22345
22192
|
const note = document.createElement("div");
|
|
22346
22193
|
note.className = "noodle-app-fallback";
|
|
22347
22194
|
note.textContent = "This app view could not be displayed.";
|
|
22348
22195
|
frame.replaceWith(note);
|
|
22349
|
-
options.onRenderFailure?.({ code, retryable: false
|
|
22350
|
-
void closeTransport();
|
|
22351
|
-
};
|
|
22352
|
-
renderTimer = setTimeout(() => {
|
|
22353
|
-
showRenderFailure("view_render_timeout");
|
|
22196
|
+
options.onRenderFailure?.({ code: "view_render_timeout", retryable: false });
|
|
22354
22197
|
}, APP_RENDER_TIMEOUT_MS);
|
|
22355
22198
|
frame.addEventListener(
|
|
22356
22199
|
"load",
|
|
22357
22200
|
() => {
|
|
22358
|
-
if (destroyed
|
|
22359
|
-
renderStage = "sandbox_proxy";
|
|
22201
|
+
if (destroyed) return;
|
|
22360
22202
|
const target = frame.contentWindow;
|
|
22361
22203
|
if (!target) return;
|
|
22362
22204
|
const bridge = new DX(
|
|
@@ -22367,11 +22209,7 @@ function mountAssistantApp(detail, actions, options = {}) {
|
|
|
22367
22209
|
serverTools: {},
|
|
22368
22210
|
serverResources: {},
|
|
22369
22211
|
updateModelContext: { text: {}, structuredContent: {} },
|
|
22370
|
-
message: { text: {} }
|
|
22371
|
-
sandbox: {
|
|
22372
|
-
...appliedPolicy.csp === void 0 ? {} : { csp: appliedPolicy.csp },
|
|
22373
|
-
...appliedPolicy.permissions === void 0 ? {} : { permissions: appliedPolicy.permissions }
|
|
22374
|
-
}
|
|
22212
|
+
message: { text: {} }
|
|
22375
22213
|
},
|
|
22376
22214
|
{
|
|
22377
22215
|
hostContext
|
|
@@ -22379,15 +22217,13 @@ function mountAssistantApp(detail, actions, options = {}) {
|
|
|
22379
22217
|
);
|
|
22380
22218
|
mountedBridge = bridge;
|
|
22381
22219
|
bridge.onsandboxready = () => {
|
|
22382
|
-
if (destroyed
|
|
22383
|
-
renderStage = "app_initialize";
|
|
22220
|
+
if (destroyed) return;
|
|
22384
22221
|
const current = options.getDetail?.() ?? detail;
|
|
22385
22222
|
void bridge.sendSandboxResourceReady({
|
|
22386
22223
|
html: current.html,
|
|
22387
|
-
sandbox:
|
|
22388
|
-
...
|
|
22389
|
-
|
|
22390
|
-
}).catch(() => showRenderFailure("view_bridge_error"));
|
|
22224
|
+
sandbox: "allow-scripts",
|
|
22225
|
+
...current.resourceMeta ?? {}
|
|
22226
|
+
});
|
|
22391
22227
|
};
|
|
22392
22228
|
bridge.onsizechange = ({ height }) => {
|
|
22393
22229
|
if (destroyed) return;
|
|
@@ -22451,30 +22287,21 @@ function mountAssistantApp(detail, actions, options = {}) {
|
|
|
22451
22287
|
return await actions.client.requestApp("resources/read", params);
|
|
22452
22288
|
};
|
|
22453
22289
|
bridge.oninitialized = () => {
|
|
22454
|
-
if (destroyed
|
|
22455
|
-
|
|
22456
|
-
|
|
22457
|
-
|
|
22458
|
-
|
|
22459
|
-
|
|
22460
|
-
|
|
22461
|
-
|
|
22462
|
-
|
|
22463
|
-
|
|
22464
|
-
bridge.sendToolInput({ arguments: argumentsRecord }),
|
|
22465
|
-
bridge.sendToolResult({
|
|
22466
|
-
content: [{ type: "text", text: JSON.stringify(copiedResult) }],
|
|
22467
|
-
...typeof copiedResult === "object" && copiedResult !== null && !Array.isArray(copiedResult) ? { structuredContent: copiedResult } : {}
|
|
22468
|
-
})
|
|
22469
|
-
]).catch(() => showRenderFailure("view_bridge_error"));
|
|
22470
|
-
} catch {
|
|
22471
|
-
showRenderFailure("view_bridge_error");
|
|
22472
|
-
}
|
|
22290
|
+
if (destroyed) return;
|
|
22291
|
+
initialized = true;
|
|
22292
|
+
clearTimeout(renderTimer);
|
|
22293
|
+
bridge.setHostContext(hostContext);
|
|
22294
|
+
const current = options.getDetail?.() ?? detail;
|
|
22295
|
+
void bridge.sendToolInput({ arguments: current.arguments ?? {} });
|
|
22296
|
+
void bridge.sendToolResult({
|
|
22297
|
+
content: [{ type: "text", text: JSON.stringify(current.result) }],
|
|
22298
|
+
...typeof current.result === "object" && current.result !== null && !Array.isArray(current.result) ? { structuredContent: current.result } : {}
|
|
22299
|
+
});
|
|
22473
22300
|
};
|
|
22474
22301
|
const transport = new E(target, target);
|
|
22475
22302
|
mountedTransport = transport;
|
|
22476
22303
|
void bridge.connect(transport).catch(() => {
|
|
22477
|
-
|
|
22304
|
+
void destroy();
|
|
22478
22305
|
});
|
|
22479
22306
|
},
|
|
22480
22307
|
{ once: true }
|
|
@@ -22500,7 +22327,8 @@ function mountAssistantApp(detail, actions, options = {}) {
|
|
|
22500
22327
|
}
|
|
22501
22328
|
} catch {
|
|
22502
22329
|
}
|
|
22503
|
-
await
|
|
22330
|
+
await mountedTransport?.close().catch(() => {
|
|
22331
|
+
});
|
|
22504
22332
|
card.remove();
|
|
22505
22333
|
mountedApps.delete(card);
|
|
22506
22334
|
})();
|
|
@@ -27499,14 +27327,14 @@ function toChatError(error51) {
|
|
|
27499
27327
|
}
|
|
27500
27328
|
function readErrorDetail(error51) {
|
|
27501
27329
|
const detail = Reflect.get(error51, "detail");
|
|
27502
|
-
if (!
|
|
27330
|
+
if (!isRecord(detail) || typeof detail.code !== "string") return void 0;
|
|
27503
27331
|
return {
|
|
27504
27332
|
code: detail.code,
|
|
27505
27333
|
...typeof detail.status === "number" ? { status: detail.status } : {},
|
|
27506
27334
|
retryable: detail.retryable === true
|
|
27507
27335
|
};
|
|
27508
27336
|
}
|
|
27509
|
-
function
|
|
27337
|
+
function isRecord(value) {
|
|
27510
27338
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27511
27339
|
}
|
|
27512
27340
|
|
|
@@ -27533,7 +27361,7 @@ var AssistantClientError = class extends Error {
|
|
|
27533
27361
|
}
|
|
27534
27362
|
};
|
|
27535
27363
|
function parseSession(value) {
|
|
27536
|
-
if (!
|
|
27364
|
+
if (!isRecord2(value) || !isRecord2(value.endpoints)) {
|
|
27537
27365
|
throw clientError("session_failed", "Assistant session response is invalid", true);
|
|
27538
27366
|
}
|
|
27539
27367
|
const interactions = value.endpoints.interactions;
|
|
@@ -27554,11 +27382,11 @@ function parseSession(value) {
|
|
|
27554
27382
|
...typeof sandbox === "string" ? { sandbox } : {},
|
|
27555
27383
|
...typeof transcript === "string" ? { transcript } : {}
|
|
27556
27384
|
},
|
|
27557
|
-
...
|
|
27558
|
-
...
|
|
27385
|
+
...isRecord2(value.configuration) ? { configuration: value.configuration } : {},
|
|
27386
|
+
...isRecord2(value.resume) && typeof value.resume.tool === "string" ? { resume: { tool: value.resume.tool } } : {}
|
|
27559
27387
|
};
|
|
27560
27388
|
}
|
|
27561
|
-
function
|
|
27389
|
+
function isRecord2(value) {
|
|
27562
27390
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27563
27391
|
}
|
|
27564
27392
|
async function readStableErrorCode(response) {
|
|
@@ -27568,7 +27396,7 @@ async function readStableErrorCode(response) {
|
|
|
27568
27396
|
} catch {
|
|
27569
27397
|
return void 0;
|
|
27570
27398
|
}
|
|
27571
|
-
if (!
|
|
27399
|
+
if (!isRecord2(value) || typeof value.code !== "string") return void 0;
|
|
27572
27400
|
return /^[A-Za-z0-9_.-]{1,64}$/.test(value.code) ? value.code : void 0;
|
|
27573
27401
|
}
|
|
27574
27402
|
function clientError(code, message, retryable, status, options, serviceCode) {
|
|
@@ -27599,12 +27427,12 @@ function toAssistantClientEvent(event) {
|
|
|
27599
27427
|
}
|
|
27600
27428
|
break;
|
|
27601
27429
|
case "tool_proposed":
|
|
27602
|
-
if (hasString(value, "id") && hasString(value, "tool") && hasOptionalString(value.title) && hasOptionalString(value.description) && hasOptionalJson(value.arguments) && (value.reviewSchema === void 0 ||
|
|
27430
|
+
if (hasString(value, "id") && hasString(value, "tool") && hasOptionalString(value.title) && hasOptionalString(value.description) && hasOptionalJson(value.arguments) && (value.reviewSchema === void 0 || isRecord3(value.reviewSchema)) && hasOptionalString(value.expiresAt) && (value.requiresConfirmation === void 0 || value.requiresConfirmation === true) && hasOptionalTurnId(value)) {
|
|
27603
27431
|
return event;
|
|
27604
27432
|
}
|
|
27605
27433
|
break;
|
|
27606
27434
|
case "input_requested":
|
|
27607
|
-
if (hasString(value, "id") && hasString(value, "message") &&
|
|
27435
|
+
if (hasString(value, "id") && hasString(value, "message") && isRecord3(value.requestedSchema) && hasString(value, "expiresAt") && hasOptionalTurnId(value)) {
|
|
27608
27436
|
return event;
|
|
27609
27437
|
}
|
|
27610
27438
|
break;
|
|
@@ -27648,7 +27476,7 @@ function toAssistantClientEvent(event) {
|
|
|
27648
27476
|
return { event: "unrecognized", data: { name: event.event, payload: value } };
|
|
27649
27477
|
}
|
|
27650
27478
|
function isViewAvailableDetail(value) {
|
|
27651
|
-
return hasString(value, "id") && hasString(value, "tool") && typeof value.resourceUri === "string" && value.resourceUri.startsWith("ui://") && hasOptionalString(value.title) && (value.replayed === void 0 || value.replayed === true) && isJsonValue(value.result, 0) && hasOptionalJson(value.arguments) && hasOptionalString(value.html) && (value.resourceMeta === void 0 ||
|
|
27479
|
+
return hasString(value, "id") && hasString(value, "tool") && typeof value.resourceUri === "string" && value.resourceUri.startsWith("ui://") && hasOptionalString(value.title) && (value.replayed === void 0 || value.replayed === true) && isJsonValue(value.result, 0) && hasOptionalJson(value.arguments) && hasOptionalString(value.html) && (value.resourceMeta === void 0 || isRecord3(value.resourceMeta)) && (value.allowedOpenDomains === void 0 || Array.isArray(value.allowedOpenDomains) && value.allowedOpenDomains.every(isHttpsUrl)) && hasOptionalTurnId(value);
|
|
27652
27480
|
}
|
|
27653
27481
|
function isHttpsUrl(value) {
|
|
27654
27482
|
if (typeof value !== "string") return false;
|
|
@@ -27681,11 +27509,11 @@ function isJsonValue(value, depth) {
|
|
|
27681
27509
|
if (Array.isArray(value)) {
|
|
27682
27510
|
return value.length <= 256 && value.every((entry) => isJsonValue(entry, depth + 1));
|
|
27683
27511
|
}
|
|
27684
|
-
if (!
|
|
27512
|
+
if (!isRecord3(value)) return false;
|
|
27685
27513
|
const entries2 = Object.entries(value);
|
|
27686
27514
|
return entries2.length <= 256 && entries2.every(([, entry]) => isJsonValue(entry, depth + 1));
|
|
27687
27515
|
}
|
|
27688
|
-
function
|
|
27516
|
+
function isRecord3(value) {
|
|
27689
27517
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27690
27518
|
}
|
|
27691
27519
|
|
|
@@ -27852,15 +27680,15 @@ function parseFrame(frame) {
|
|
|
27852
27680
|
if (event === "done" && !isValidDonePayload(parsed)) {
|
|
27853
27681
|
throw invalidStream("assistant event stream contained an invalid done event");
|
|
27854
27682
|
}
|
|
27855
|
-
return { event, data:
|
|
27683
|
+
return { event, data: isRecord4(parsed) ? parsed : { value: parsed } };
|
|
27856
27684
|
}
|
|
27857
27685
|
function normalizeLineEndings(input) {
|
|
27858
27686
|
return input.replaceAll("\r\n", "\n").replaceAll("\r", "\n");
|
|
27859
27687
|
}
|
|
27860
27688
|
function isValidDonePayload(value) {
|
|
27861
|
-
return
|
|
27689
|
+
return isRecord4(value) && (value.turnId === void 0 || typeof value.turnId === "string" && value.turnId.length > 0);
|
|
27862
27690
|
}
|
|
27863
|
-
function
|
|
27691
|
+
function isRecord4(value) {
|
|
27864
27692
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
27865
27693
|
}
|
|
27866
27694
|
function invalidStream(message, cause) {
|
|
@@ -28379,10 +28207,10 @@ function authorizedHeaders(token, accept) {
|
|
|
28379
28207
|
};
|
|
28380
28208
|
}
|
|
28381
28209
|
function parseAppInteraction(value) {
|
|
28382
|
-
if (!
|
|
28210
|
+
if (!isRecord2(value) || !isRecord2(value.interaction)) return void 0;
|
|
28383
28211
|
const event = value.interaction.event;
|
|
28384
28212
|
const data = value.interaction.data;
|
|
28385
|
-
if (event !== "tool_proposed" && event !== "input_requested" || !
|
|
28213
|
+
if (event !== "tool_proposed" && event !== "input_requested" || !isRecord2(data)) {
|
|
28386
28214
|
return void 0;
|
|
28387
28215
|
}
|
|
28388
28216
|
const parsed = toAssistantClientEvent({ event, data });
|
|
@@ -31581,7 +31409,7 @@ var AssistantElementEventController = class {
|
|
|
31581
31409
|
if (event.event === "unrecognized") return;
|
|
31582
31410
|
const { event: name21, data } = event;
|
|
31583
31411
|
if (name21 === "session_started") {
|
|
31584
|
-
if (
|
|
31412
|
+
if (isRecord5(data.configuration)) {
|
|
31585
31413
|
this.#host.applyConfiguration(data.configuration);
|
|
31586
31414
|
}
|
|
31587
31415
|
this.#host.element.dispatchEvent(
|
|
@@ -31649,10 +31477,10 @@ var AssistantElementEventController = class {
|
|
|
31649
31477
|
this.#appendToolProposal(
|
|
31650
31478
|
String(data.id ?? ""),
|
|
31651
31479
|
String(data.tool ?? "action"),
|
|
31652
|
-
|
|
31480
|
+
isRecord5(data.arguments) ? data.arguments : void 0,
|
|
31653
31481
|
typeof data.title === "string" ? data.title : void 0,
|
|
31654
31482
|
"description" in data && typeof data.description === "string" ? data.description : void 0,
|
|
31655
|
-
"reviewSchema" in data &&
|
|
31483
|
+
"reviewSchema" in data && isRecord5(data.reviewSchema) ? data.reviewSchema : void 0
|
|
31656
31484
|
);
|
|
31657
31485
|
return;
|
|
31658
31486
|
}
|
|
@@ -31665,7 +31493,7 @@ var AssistantElementEventController = class {
|
|
|
31665
31493
|
);
|
|
31666
31494
|
return;
|
|
31667
31495
|
}
|
|
31668
|
-
if (name21 === "input_requested" &&
|
|
31496
|
+
if (name21 === "input_requested" && isRecord5(data.requestedSchema)) {
|
|
31669
31497
|
this.#appendInputRequest(
|
|
31670
31498
|
String(data.id ?? ""),
|
|
31671
31499
|
String(data.message ?? "More information is required"),
|
|
@@ -31836,7 +31664,7 @@ var AssistantElementEventController = class {
|
|
|
31836
31664
|
this.#host.revealLatest();
|
|
31837
31665
|
}
|
|
31838
31666
|
};
|
|
31839
|
-
function
|
|
31667
|
+
function isRecord5(value) {
|
|
31840
31668
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31841
31669
|
}
|
|
31842
31670
|
|