@my-life-buddies/cli 0.17.0 → 0.17.3
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 +31 -11
- package/dist/bin/buddy.js +4 -1
- package/dist/bin/buddy.js.map +2 -2
- package/dist/bin/core.js +414 -313
- package/dist/bin/core.js.map +4 -4
- package/dist/bin/preview.js +41 -9
- package/dist/bin/preview.js.map +2 -2
- package/dist/web/app.js +1 -1
- package/dist/web/widgets.js +14 -13
- package/package.json +3 -3
- package/resources/agent-template/package-lock.json +4 -4
- package/resources/agent-template/package.json +1 -1
package/dist/bin/preview.js
CHANGED
|
@@ -366,14 +366,23 @@ var PreviewController = class {
|
|
|
366
366
|
return this.simulatorSnapshot();
|
|
367
367
|
}
|
|
368
368
|
/** Never allow an old conversation's delayed widget response to enter the new one. */
|
|
369
|
-
async simulatorWidgets(action, id = "", mediaId = "") {
|
|
369
|
+
async simulatorWidgets(action, id = "", mediaId = "", messageId) {
|
|
370
370
|
if (this.#resetting) throw Object.assign(new Error("\u4F1A\u8BDD\u6B63\u5728\u91CD\u7F6E"), { status: 409 });
|
|
371
371
|
const client = this.#requiredSimulator();
|
|
372
372
|
const revision = this.#conversationRevision;
|
|
373
373
|
let result;
|
|
374
374
|
if (action === "list" && client.widgets) result = { widgets: await client.widgets(), conversationRevision: revision, capabilities: { documentLifecycle: true, deleteWidget: Boolean(client.deleteWidget) } };
|
|
375
|
-
else if (action === "html" && client.widgetHtml)
|
|
376
|
-
|
|
375
|
+
else if (action === "html" && client.widgetHtml) {
|
|
376
|
+
let target;
|
|
377
|
+
if (messageId !== void 0) {
|
|
378
|
+
const state = await client.state();
|
|
379
|
+
const message2 = state.messages.find((item) => item.messageId === messageId && item.widget?.id === id);
|
|
380
|
+
if (!message2?.widget) throw Object.assign(new Error("\u8FD9\u6761\u5C0F\u6302\u4EF6\u6D88\u606F\u5DF2\u4E0D\u53EF\u7528\uFF0C\u8BF7\u5237\u65B0\u5BF9\u8BDD\u540E\u91CD\u8BD5"), { status: 404 });
|
|
381
|
+
target = message2.widget.openTarget;
|
|
382
|
+
}
|
|
383
|
+
if (this.#resetting || revision !== this.#conversationRevision || client !== this.#simulator) throw Object.assign(new Error("\u4F1A\u8BDD\u5DF2\u5207\u6362\uFF0C\u8BF7\u91CD\u65B0\u6253\u5F00\u5C0F\u6302\u4EF6"), { status: 409 });
|
|
384
|
+
result = await client.widgetHtml(id, target);
|
|
385
|
+
} else if (action === "delete" && client.deleteWidget) {
|
|
377
386
|
await client.deleteWidget(id);
|
|
378
387
|
result = { ok: true };
|
|
379
388
|
} else if (action === "image" && client.widgetImage) result = await client.widgetImage(id, mediaId);
|
|
@@ -1110,7 +1119,7 @@ data: ${JSON.stringify(value)}
|
|
|
1110
1119
|
return;
|
|
1111
1120
|
}
|
|
1112
1121
|
if (id && request.method === "GET" && !suffix) {
|
|
1113
|
-
const html = await options.controller.simulatorWidgets("html", id);
|
|
1122
|
+
const html = await options.controller.simulatorWidgets("html", id, "", url.searchParams.get("messageId") ?? void 0);
|
|
1114
1123
|
widgetDocument(response, html, url.searchParams.get("render"));
|
|
1115
1124
|
return;
|
|
1116
1125
|
}
|
|
@@ -1559,6 +1568,7 @@ function widgetId(value) {
|
|
|
1559
1568
|
}
|
|
1560
1569
|
function parseWidget(value) {
|
|
1561
1570
|
const item = object(value);
|
|
1571
|
+
const openTarget = parseOpenTarget(item?.openTarget);
|
|
1562
1572
|
return Object.freeze({
|
|
1563
1573
|
id: widgetId(item?.id),
|
|
1564
1574
|
title: typeof item?.title === "string" && item.title.trim() ? item.title : "\u5C0F\u6302\u4EF6",
|
|
@@ -1567,9 +1577,24 @@ function parseWidget(value) {
|
|
|
1567
1577
|
...typeof item?.imageMediaId === "string" && /^media_[a-zA-Z0-9_-]+$/u.test(item.imageMediaId) ? { imageMediaId: item.imageMediaId } : {},
|
|
1568
1578
|
...typeof item?.isPinned === "boolean" ? { isPinned: item.isPinned } : {},
|
|
1569
1579
|
...typeof item?.creatorName === "string" ? { creatorName: item.creatorName } : {},
|
|
1570
|
-
...item?.role === "owner" || item?.role === "editor" || item?.role === "viewer" ? { role: item.role } : {}
|
|
1580
|
+
...item?.role === "owner" || item?.role === "editor" || item?.role === "viewer" ? { role: item.role } : {},
|
|
1581
|
+
...openTarget ? { openTarget } : {}
|
|
1571
1582
|
});
|
|
1572
1583
|
}
|
|
1584
|
+
function parseOpenTarget(value) {
|
|
1585
|
+
if (value === void 0) return void 0;
|
|
1586
|
+
const target = object(value), resource = object(target?.resource);
|
|
1587
|
+
const name = (input) => typeof input === "string" && /^[^\s/\u0000-\u001f\u007f]{1,64}$/u.test(input);
|
|
1588
|
+
if (!target || target.version !== 1 || !name(target.entry) || target.resource !== void 0 && (!resource || !name(resource.module) || !name(resource.recordId)) || target.state !== void 0 && !object(target.state)) throw new TypeError("Widget \u6253\u5F00\u76EE\u6807\u683C\u5F0F\u65E0\u6548");
|
|
1589
|
+
const normalized = {
|
|
1590
|
+
version: 1,
|
|
1591
|
+
entry: target.entry,
|
|
1592
|
+
...resource ? { resource: { module: resource.module, recordId: resource.recordId } } : {},
|
|
1593
|
+
...target.state !== void 0 ? { state: object(target.state) } : {}
|
|
1594
|
+
};
|
|
1595
|
+
if (Buffer.byteLength(JSON.stringify(normalized), "utf8") > 8 * 1024) throw new TypeError("Widget \u6253\u5F00\u76EE\u6807\u8D85\u8FC7 8 KiB");
|
|
1596
|
+
return Object.freeze(normalized);
|
|
1597
|
+
}
|
|
1573
1598
|
function localReceipt(prefix, value) {
|
|
1574
1599
|
return `${prefix}-${createHash("sha256").update(value).digest("hex").slice(0, 20)}`;
|
|
1575
1600
|
}
|
|
@@ -1637,10 +1662,14 @@ var MlbSimulatorClient = class {
|
|
|
1637
1662
|
if (!Array.isArray(body?.widgets)) throw httpError(502, { error: "\u65E0\u6CD5\u8BFB\u53D6\u4F1A\u8BDD\u5C0F\u6302\u4EF6" });
|
|
1638
1663
|
return body.widgets.map(parseWidget).filter((item) => item.type !== void 0);
|
|
1639
1664
|
}
|
|
1640
|
-
async widgetHtml(id) {
|
|
1665
|
+
async widgetHtml(id, openTarget) {
|
|
1641
1666
|
this.#assertResetComplete();
|
|
1667
|
+
const target = parseOpenTarget(openTarget);
|
|
1642
1668
|
const privateId = await this.#ensurePrivate();
|
|
1643
|
-
const result = await this.#widgetResource(`/app/widgets/${encodeURIComponent(widgetId(id))}
|
|
1669
|
+
const result = await this.#widgetResource(`/app/widgets/${encodeURIComponent(widgetId(id))}/presentation`, true, {
|
|
1670
|
+
method: "POST",
|
|
1671
|
+
body: JSON.stringify({ conversationId: privateId, ...target ? { openTarget: target } : {} })
|
|
1672
|
+
});
|
|
1644
1673
|
return new TextDecoder("utf-8", { fatal: true }).decode(result.body);
|
|
1645
1674
|
}
|
|
1646
1675
|
async pinWidget(id, pinned) {
|
|
@@ -1661,8 +1690,11 @@ var MlbSimulatorClient = class {
|
|
|
1661
1690
|
if (url.protocol !== "https:" || url.username || url.password || access?.mediaId !== mediaId || typeof access.expiresAt !== "number" || access.expiresAt <= Date.now()) throw new Error("\u56FE\u7247\u94FE\u63A5\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u8BD5");
|
|
1662
1691
|
return this.#widgetResource(url.href, false);
|
|
1663
1692
|
}
|
|
1664
|
-
async #widgetResource(path, authenticated = true) {
|
|
1665
|
-
const response = await this.#fetch(authenticated ? endpoint(this.#baseUrl, path) : new URL(path), { headers:
|
|
1693
|
+
async #widgetResource(path, authenticated = true, init = {}) {
|
|
1694
|
+
const response = await this.#fetch(authenticated ? endpoint(this.#baseUrl, path) : new URL(path), { ...init, headers: {
|
|
1695
|
+
...authenticated ? { Authorization: `Bearer ${this.#accessToken}` } : {},
|
|
1696
|
+
...init.body ? { "Content-Type": "application/json" } : {}
|
|
1697
|
+
}, credentials: "omit", redirect: "error", signal: AbortSignal.timeout(15e3) });
|
|
1666
1698
|
if (!response.ok) throw httpError(response.status, { error: response.status === 403 || response.status === 404 ? "\u5C0F\u6302\u4EF6\u5DF2\u5220\u9664\u3001\u9875\u9762\u672A\u4E0A\u4F20\uFF0C\u6216\u4F60\u5DF2\u4E0D\u5728\u8FD9\u4E2A\u4F1A\u8BDD\u4E2D\u3002" : "\u5C0F\u6302\u4EF6\u6682\u65F6\u65E0\u6CD5\u6253\u5F00\uFF0C\u8BF7\u91CD\u65B0\u52A0\u8F7D\u3002" });
|
|
1667
1699
|
const reader = response.body?.getReader();
|
|
1668
1700
|
if (!reader) throw new Error("\u5C0F\u6302\u4EF6\u5185\u5BB9\u4E3A\u7A7A");
|