@supersolutions/super-chat-core 0.2.3 → 0.4.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/dist/index.d.ts +133 -4
- package/dist/index.js +226 -37
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1070,12 +1070,15 @@ var SkillRegistry = class {
|
|
|
1070
1070
|
};
|
|
1071
1071
|
|
|
1072
1072
|
// src/cards/types.ts
|
|
1073
|
+
var CARD_PLACEMENTS = ["inline", "panel", "document"];
|
|
1074
|
+
var isCardPlacement = (value) => CARD_PLACEMENTS.includes(value);
|
|
1073
1075
|
var CARD_KEY = "$card";
|
|
1074
1076
|
function isCardCarrier(value) {
|
|
1075
1077
|
return typeof value === "object" && value !== null && CARD_KEY in value && typeof value[CARD_KEY] === "object";
|
|
1076
1078
|
}
|
|
1077
|
-
function withCard(data, spec, id) {
|
|
1078
|
-
|
|
1079
|
+
function withCard(data, spec, id, placement) {
|
|
1080
|
+
const card = { id: id ?? `card_${Math.random().toString(36).slice(2, 10)}`, spec, ...placement && placement !== "inline" ? { placement } : {} };
|
|
1081
|
+
return { ...data, [CARD_KEY]: card };
|
|
1079
1082
|
}
|
|
1080
1083
|
function stripCardPayload(output) {
|
|
1081
1084
|
if (!isCardCarrier(output)) return output;
|
|
@@ -2119,14 +2122,14 @@ var CardRegistry = class {
|
|
|
2119
2122
|
if (!isObj(spec) || typeof spec["kind"] !== "string") return void 0;
|
|
2120
2123
|
const def = this.kinds.get(spec["kind"]);
|
|
2121
2124
|
if (!def?.partial || def.interactive) return void 0;
|
|
2122
|
-
let
|
|
2125
|
+
let preview;
|
|
2123
2126
|
try {
|
|
2124
|
-
|
|
2127
|
+
preview = def.partial(spec);
|
|
2125
2128
|
} catch {
|
|
2126
2129
|
return void 0;
|
|
2127
2130
|
}
|
|
2128
|
-
if (!isObj(
|
|
2129
|
-
return def.validate(
|
|
2131
|
+
if (!isObj(preview) || preview["kind"] !== def.kind) return void 0;
|
|
2132
|
+
return def.validate(preview).ok ? preview : void 0;
|
|
2130
2133
|
}
|
|
2131
2134
|
/** The catalogue text embedded in the `visualize` tool description. */
|
|
2132
2135
|
describe() {
|
|
@@ -2138,10 +2141,80 @@ var CardRegistry = class {
|
|
|
2138
2141
|
}
|
|
2139
2142
|
};
|
|
2140
2143
|
var cardCounter = 0;
|
|
2141
|
-
function makeCard(spec, callId, id) {
|
|
2142
|
-
|
|
2144
|
+
function makeCard(spec, callId, id, placement) {
|
|
2145
|
+
const where = placement && placement !== "inline" ? { placement } : {};
|
|
2146
|
+
if (id) return { id, spec, ...callId ? { callId } : {}, ...where };
|
|
2143
2147
|
cardCounter += 1;
|
|
2144
|
-
return { id: `card_${Date.now().toString(36)}${cardCounter.toString(36)}`, spec, ...callId ? { callId } : {} };
|
|
2148
|
+
return { id: `card_${Date.now().toString(36)}${cardCounter.toString(36)}`, spec, ...callId ? { callId } : {}, ...where };
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2151
|
+
// src/cards/card-ref.ts
|
|
2152
|
+
var CARD_REF_SCHEME = "ref";
|
|
2153
|
+
var CARD_REF_LIMITS = Object.freeze({
|
|
2154
|
+
/** The whole link, in UTF-16 code units. */
|
|
2155
|
+
length: 512,
|
|
2156
|
+
/** The target (the card's id). */
|
|
2157
|
+
target: 128,
|
|
2158
|
+
/** Distinct param names. */
|
|
2159
|
+
names: 16,
|
|
2160
|
+
/** Values of one param name (`key=a&key=b`). */
|
|
2161
|
+
values: 32,
|
|
2162
|
+
/** One param name. */
|
|
2163
|
+
name: 32,
|
|
2164
|
+
/** One decoded value, in UTF-16 code units. */
|
|
2165
|
+
value: 256
|
|
2166
|
+
});
|
|
2167
|
+
var TARGET = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
|
|
2168
|
+
var NAME = /^[a-z][A-Za-z0-9_-]{0,31}$/;
|
|
2169
|
+
var RAW_VALUE = /^(?:[A-Za-z0-9._~-]|%[0-9A-Fa-f]{2})+$/;
|
|
2170
|
+
var hasOwn = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
|
|
2171
|
+
function decodeValue(raw) {
|
|
2172
|
+
const bytes = [];
|
|
2173
|
+
for (let i = 0; i < raw.length; i++) {
|
|
2174
|
+
if (raw[i] === "%") {
|
|
2175
|
+
bytes.push(parseInt(raw.slice(i + 1, i + 3), 16));
|
|
2176
|
+
i += 2;
|
|
2177
|
+
} else bytes.push(raw.charCodeAt(i));
|
|
2178
|
+
}
|
|
2179
|
+
try {
|
|
2180
|
+
return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(Uint8Array.from(bytes));
|
|
2181
|
+
} catch {
|
|
2182
|
+
return null;
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
function parseCardRef(href) {
|
|
2186
|
+
const fail = (error) => ({ ok: false, error });
|
|
2187
|
+
if (typeof href !== "string") return fail("a ref must be a string.");
|
|
2188
|
+
if (href.length > CARD_REF_LIMITS.length) return fail(`a ref is at most ${CARD_REF_LIMITS.length} characters.`);
|
|
2189
|
+
if (!href.startsWith(`${CARD_REF_SCHEME}:`)) return fail(`a ref starts with "${CARD_REF_SCHEME}:".`);
|
|
2190
|
+
const rest = href.slice(CARD_REF_SCHEME.length + 1);
|
|
2191
|
+
if (rest.includes("#")) return fail("a ref has no fragment.");
|
|
2192
|
+
const q = rest.indexOf("?");
|
|
2193
|
+
const target = q < 0 ? rest : rest.slice(0, q);
|
|
2194
|
+
if (!TARGET.test(target)) return fail("a ref target is 1 to 128 letters, digits, dot, underscore, colon or dash, starting with a letter or digit.");
|
|
2195
|
+
const params = {};
|
|
2196
|
+
if (q >= 0) {
|
|
2197
|
+
const query = rest.slice(q + 1);
|
|
2198
|
+
if (query === "") return fail("a ref query is empty.");
|
|
2199
|
+
for (const part of query.split("&")) {
|
|
2200
|
+
const eq = part.indexOf("=");
|
|
2201
|
+
if (eq < 0) return fail("each ref param is name=value.");
|
|
2202
|
+
const name = part.slice(0, eq);
|
|
2203
|
+
const raw = part.slice(eq + 1);
|
|
2204
|
+
if (!NAME.test(name)) return fail("a ref param name is 1 to 32 letters, digits, dash or underscore, starting with a lowercase letter.");
|
|
2205
|
+
if (!RAW_VALUE.test(raw)) return fail("a ref param value is not empty and uses letters, digits, dot, dash, underscore, tilde or %XX only.");
|
|
2206
|
+
const value = decodeValue(raw);
|
|
2207
|
+
if (value === null) return fail("a ref param value must be valid UTF-8.");
|
|
2208
|
+
if (value.length > CARD_REF_LIMITS.value) return fail(`a ref param value is at most ${CARD_REF_LIMITS.value} characters.`);
|
|
2209
|
+
if (!hasOwn(params, name)) {
|
|
2210
|
+
if (Object.keys(params).length >= CARD_REF_LIMITS.names) return fail(`a ref has at most ${CARD_REF_LIMITS.names} param names.`);
|
|
2211
|
+
params[name] = [];
|
|
2212
|
+
}
|
|
2213
|
+
if (params[name].length >= CARD_REF_LIMITS.values) return fail(`a ref param has at most ${CARD_REF_LIMITS.values} values.`);
|
|
2214
|
+
params[name].push(value);
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2217
|
+
return { ok: true, ref: { target, params } };
|
|
2145
2218
|
}
|
|
2146
2219
|
|
|
2147
2220
|
// src/cards/builtin.ts
|
|
@@ -3067,7 +3140,7 @@ var formCard = {
|
|
|
3067
3140
|
var confirmCard = {
|
|
3068
3141
|
kind: "confirm",
|
|
3069
3142
|
interactive: true,
|
|
3070
|
-
summary: "Get explicit approval before a consequential action. `
|
|
3143
|
+
summary: "Get explicit approval before a consequential action. `description` says what will happen in plain words, `summary` lists exact amounts, targets, and anything irreversible, and `title` is the one question the buttons answer.",
|
|
3071
3144
|
estimateTokens: tokensOf,
|
|
3072
3145
|
schema: {
|
|
3073
3146
|
type: "object",
|
|
@@ -3099,7 +3172,8 @@ var confirmCard = {
|
|
|
3099
3172
|
if (failed(s)) return s;
|
|
3100
3173
|
const o = s;
|
|
3101
3174
|
if (typeof o["title"] !== "string") return { ok: false, error: "confirm.title is required." };
|
|
3102
|
-
const
|
|
3175
|
+
const hasDescription = typeof o["description"] === "string" && o["description"].trim() !== "";
|
|
3176
|
+
const summary = check.arrayField(o, "summary", "confirm", hasDescription ? 0 : 1);
|
|
3103
3177
|
if (failed(summary)) return summary;
|
|
3104
3178
|
return ok;
|
|
3105
3179
|
}
|
|
@@ -4626,6 +4700,97 @@ var EventChannel = class {
|
|
|
4626
4700
|
}
|
|
4627
4701
|
};
|
|
4628
4702
|
|
|
4703
|
+
// src/tools/approval.ts
|
|
4704
|
+
var MAX_FIELDS = 6;
|
|
4705
|
+
var MAX_VALUE_CHARS = 160;
|
|
4706
|
+
var MAX_DESCRIPTION_CHARS = 240;
|
|
4707
|
+
var clip = (text3, max) => text3.length > max ? `${text3.slice(0, max - 1)}\u2026` : text3;
|
|
4708
|
+
function humanizeFieldName(key) {
|
|
4709
|
+
const words = key.replace(/([a-z0-9])([A-Z])/g, "$1 $2").split(/[\s_\-.]+/).filter(Boolean).map((word) => word.toLowerCase());
|
|
4710
|
+
if (words.length > 1 && (words[words.length - 1] === "id" || words[words.length - 1] === "ids")) words.pop();
|
|
4711
|
+
const text3 = words.join(" ");
|
|
4712
|
+
return text3 ? text3.charAt(0).toUpperCase() + text3.slice(1) : key;
|
|
4713
|
+
}
|
|
4714
|
+
function plainValue(value) {
|
|
4715
|
+
if (typeof value === "string") return value.trim() ? clip(value.trim(), MAX_VALUE_CHARS) : void 0;
|
|
4716
|
+
if (typeof value === "number" || typeof value === "bigint") return String(value);
|
|
4717
|
+
if (typeof value === "boolean") return value ? "Yes" : "No";
|
|
4718
|
+
if (Array.isArray(value)) {
|
|
4719
|
+
const items = value.map(plainValue);
|
|
4720
|
+
if (value.length && items.every((item) => item !== void 0)) return clip(items.join(", "), MAX_VALUE_CHARS);
|
|
4721
|
+
return value.length === 1 ? "1 item" : `${value.length} items`;
|
|
4722
|
+
}
|
|
4723
|
+
return void 0;
|
|
4724
|
+
}
|
|
4725
|
+
function firstSentence(description) {
|
|
4726
|
+
const text3 = description.trim().replace(/\s+/g, " ");
|
|
4727
|
+
const end = text3.search(/[.!?](\s|$)/);
|
|
4728
|
+
return clip(end === -1 ? text3 : text3.slice(0, end + 1), MAX_DESCRIPTION_CHARS);
|
|
4729
|
+
}
|
|
4730
|
+
function fieldsOf(input) {
|
|
4731
|
+
if (input === void 0 || input === null) return [];
|
|
4732
|
+
if (typeof input !== "object" || Array.isArray(input)) {
|
|
4733
|
+
const value = plainValue(input);
|
|
4734
|
+
return value === void 0 ? [] : [{ label: "Details", value }];
|
|
4735
|
+
}
|
|
4736
|
+
const fields = [];
|
|
4737
|
+
for (const [key, raw] of Object.entries(input)) {
|
|
4738
|
+
const value = plainValue(raw);
|
|
4739
|
+
if (value !== void 0) fields.push({ label: humanizeFieldName(key), value });
|
|
4740
|
+
if (fields.length === MAX_FIELDS) break;
|
|
4741
|
+
}
|
|
4742
|
+
return fields;
|
|
4743
|
+
}
|
|
4744
|
+
var MAX_TITLE_CHARS = 120;
|
|
4745
|
+
var MAX_LABEL_CHARS = 40;
|
|
4746
|
+
var textOr = (value, max) => typeof value === "string" && value.trim() ? clip(value.trim().replace(/\s+/g, " "), max) : void 0;
|
|
4747
|
+
function customApproval(tool, input) {
|
|
4748
|
+
if (typeof tool.approval !== "function") return void 0;
|
|
4749
|
+
let raw;
|
|
4750
|
+
try {
|
|
4751
|
+
raw = tool.approval(input);
|
|
4752
|
+
} catch {
|
|
4753
|
+
return void 0;
|
|
4754
|
+
}
|
|
4755
|
+
if (typeof raw !== "object" || raw === null) return void 0;
|
|
4756
|
+
const r = raw;
|
|
4757
|
+
const title = textOr(r["title"], MAX_TITLE_CHARS);
|
|
4758
|
+
const description = textOr(r["description"], MAX_DESCRIPTION_CHARS);
|
|
4759
|
+
const confirmLabel = textOr(r["confirmLabel"], MAX_LABEL_CHARS);
|
|
4760
|
+
const cancelLabel = textOr(r["cancelLabel"], MAX_LABEL_CHARS);
|
|
4761
|
+
const summary = Array.isArray(r["summary"]) ? r["summary"].flatMap((row) => {
|
|
4762
|
+
const label = textOr(row?.label, MAX_LABEL_CHARS);
|
|
4763
|
+
const value = textOr(row?.value, MAX_VALUE_CHARS);
|
|
4764
|
+
return label && value ? [{ label, value }] : [];
|
|
4765
|
+
}).slice(0, MAX_FIELDS) : void 0;
|
|
4766
|
+
if (!title && !description) return void 0;
|
|
4767
|
+
return {
|
|
4768
|
+
...title ? { title } : {},
|
|
4769
|
+
...description ? { description } : {},
|
|
4770
|
+
...summary ? { summary } : {},
|
|
4771
|
+
...confirmLabel ? { confirmLabel } : {},
|
|
4772
|
+
...cancelLabel ? { cancelLabel } : {},
|
|
4773
|
+
...typeof r["danger"] === "boolean" ? { danger: r["danger"] } : {}
|
|
4774
|
+
};
|
|
4775
|
+
}
|
|
4776
|
+
function approvalCard(tool, input, options = {}) {
|
|
4777
|
+
const custom = customApproval(tool, input);
|
|
4778
|
+
let description = custom?.description ?? firstSentence(tool.description);
|
|
4779
|
+
let summary = custom ? custom.summary ?? [] : fieldsOf(input);
|
|
4780
|
+
if (!summary.length && !description) summary = [{ label: "Action", value: "Run a tool" }];
|
|
4781
|
+
description ||= void 0;
|
|
4782
|
+
const danger = custom?.danger ?? options.danger;
|
|
4783
|
+
return {
|
|
4784
|
+
kind: "confirm",
|
|
4785
|
+
title: custom?.title ?? "Allow this?",
|
|
4786
|
+
...description ? { description } : {},
|
|
4787
|
+
summary,
|
|
4788
|
+
confirmLabel: custom?.confirmLabel ?? "Allow",
|
|
4789
|
+
cancelLabel: custom?.cancelLabel ?? "Not now",
|
|
4790
|
+
...danger ? { danger: true } : {}
|
|
4791
|
+
};
|
|
4792
|
+
}
|
|
4793
|
+
|
|
4629
4794
|
// src/runtime/execute-tools.ts
|
|
4630
4795
|
var MAX_ERROR_CHARS = 400;
|
|
4631
4796
|
function compactError(e) {
|
|
@@ -4635,23 +4800,6 @@ function compactError(e) {
|
|
|
4635
4800
|
const message2 = e instanceof Error ? e.message : String(e);
|
|
4636
4801
|
return { error: message2.slice(0, MAX_ERROR_CHARS) || "Tool failed with no message." };
|
|
4637
4802
|
}
|
|
4638
|
-
var PREVIEW_CHARS = 200;
|
|
4639
|
-
var PREVIEW_FIELDS = 8;
|
|
4640
|
-
var preview = (value) => {
|
|
4641
|
-
const text3 = typeof value === "string" ? value : JSON.stringify(value) ?? String(value);
|
|
4642
|
-
return text3.length > PREVIEW_CHARS ? `${text3.slice(0, PREVIEW_CHARS)}\u2026` : text3;
|
|
4643
|
-
};
|
|
4644
|
-
function approvalCard(tool, input) {
|
|
4645
|
-
const fields = typeof input === "object" && input !== null && !Array.isArray(input) ? Object.entries(input).slice(0, PREVIEW_FIELDS).map(([label, value]) => ({ label, value: preview(value), mono: true })) : input === void 0 || input === null ? [] : [{ label: "Input", value: preview(input), mono: true }];
|
|
4646
|
-
return {
|
|
4647
|
-
kind: "confirm",
|
|
4648
|
-
title: `Allow ${tool.name}?`,
|
|
4649
|
-
description: preview(tool.description),
|
|
4650
|
-
summary: fields.length ? fields : [{ label: "Tool", value: tool.name, mono: true }],
|
|
4651
|
-
confirmLabel: "Allow",
|
|
4652
|
-
cancelLabel: "Decline"
|
|
4653
|
-
};
|
|
4654
|
-
}
|
|
4655
4803
|
async function confirmationRefusal(tool, call, opts) {
|
|
4656
4804
|
if (!opts.requestCard) return `"${tool.name}" needs the user's approval and this host cannot ask for it.`;
|
|
4657
4805
|
if (tool.confirmation === "tool") return void 0;
|
|
@@ -4659,7 +4807,7 @@ async function confirmationRefusal(tool, call, opts) {
|
|
|
4659
4807
|
if (opts.signal?.aborted) return "The run was stopped before this was approved.";
|
|
4660
4808
|
return answer?.confirmed === true ? void 0 : "The user declined.";
|
|
4661
4809
|
}
|
|
4662
|
-
var isToolResult = (v) => typeof v === "object" && v !== null && "output" in v && Object.keys(v).every((k) => ["output", "card", "failure", "cardId", "unlockTools"].includes(k));
|
|
4810
|
+
var isToolResult = (v) => typeof v === "object" && v !== null && "output" in v && Object.keys(v).every((k) => ["output", "card", "failure", "cardId", "unlockTools", "placement"].includes(k));
|
|
4663
4811
|
async function executeToolCall(call, opts) {
|
|
4664
4812
|
const started = Date.now();
|
|
4665
4813
|
const tool = opts.toolIndex ? opts.toolIndex.get(call.name) : opts.tools.find((t) => t.name === call.name);
|
|
@@ -4705,8 +4853,8 @@ async function executeToolCall(call, opts) {
|
|
|
4705
4853
|
let card = emittedCard;
|
|
4706
4854
|
let output = result.output;
|
|
4707
4855
|
if (result.card) {
|
|
4708
|
-
card = makeCard(result.card, call.callId, result.cardId);
|
|
4709
|
-
output = withCard(asRecord(result.output), card.spec, card.id);
|
|
4856
|
+
card = makeCard(result.card, call.callId, result.cardId, result.placement === "panel" ? "panel" : void 0);
|
|
4857
|
+
output = withCard(asRecord(result.output), card.spec, card.id, card.placement);
|
|
4710
4858
|
opts.onCard?.(card);
|
|
4711
4859
|
} else if (isCardCarrier(result.output)) {
|
|
4712
4860
|
const embedded = result.output[CARD_KEY];
|
|
@@ -5343,6 +5491,7 @@ function parsePartialJson(text3) {
|
|
|
5343
5491
|
function createVisualizeTool(opts) {
|
|
5344
5492
|
const { cards } = opts;
|
|
5345
5493
|
const available = opts.kinds ? cards.list().filter((k) => opts.kinds.includes(k.kind)) : cards.list();
|
|
5494
|
+
const panel = (opts.placements ?? ["inline"]).includes("panel");
|
|
5346
5495
|
const catalogue = available.map((k) => `- ${k.kind}${k.interactive ? " (interactive \u2014 the user replies)" : ""}: ${k.summary}`).join("\n");
|
|
5347
5496
|
return {
|
|
5348
5497
|
name: "visualize",
|
|
@@ -5358,13 +5507,19 @@ function createVisualizeTool(opts) {
|
|
|
5358
5507
|
"- Put the data IN the card. Do not also repeat every row in your prose \u2014 say what it means instead.",
|
|
5359
5508
|
"- Interactive kinds (choice, form, confirm) pause for the user's answer, which is returned to you as this tool's result. Use them instead of guessing.",
|
|
5360
5509
|
"- Use `confirm` before anything consequential or irreversible.",
|
|
5361
|
-
"- One card per distinct idea. Do not wrap a one-line answer in a card."
|
|
5510
|
+
"- One card per distinct idea. Do not wrap a one-line answer in a card.",
|
|
5511
|
+
...panel ? [
|
|
5512
|
+
'- `placement: "panel"` opens the card in the side panel beside the chat, with room to explore: use it for a chart the user will work with or a long document. Keep small results (a few figures, a short table) inline, the default.',
|
|
5513
|
+
"- Interactive kinds are always inline."
|
|
5514
|
+
] : []
|
|
5362
5515
|
].join("\n"),
|
|
5363
5516
|
inputSchema: {
|
|
5364
5517
|
type: "object",
|
|
5365
5518
|
required: ["kind", "spec"],
|
|
5366
5519
|
properties: {
|
|
5367
5520
|
kind: { type: "string", enum: available.map((k) => k.kind), description: "Which card to render." },
|
|
5521
|
+
// Before `spec`, so it streams first: a panel card is not previewed in the chat.
|
|
5522
|
+
...panel ? { placement: { type: "string", enum: ["inline", "panel"], description: "Where to show the card: in the chat (inline, default) or in the side panel." } } : {},
|
|
5368
5523
|
spec: {
|
|
5369
5524
|
type: "object",
|
|
5370
5525
|
description: "The card body. Must match the schema for `kind`, and must include `kind` itself.",
|
|
@@ -5392,14 +5547,19 @@ function createVisualizeTool(opts) {
|
|
|
5392
5547
|
// `cards.partial` refuses interactive kinds and anything its own validator
|
|
5393
5548
|
// rejects; `execute` below stays the only path to a real card.
|
|
5394
5549
|
partialCard: (input) => {
|
|
5395
|
-
const { kind, spec } = input ?? {};
|
|
5550
|
+
const { kind, spec, placement } = input ?? {};
|
|
5396
5551
|
if (typeof kind !== "string" || !isObj(spec)) return void 0;
|
|
5552
|
+
if (placement === "panel") return void 0;
|
|
5397
5553
|
if (opts.kinds && !opts.kinds.includes(kind)) return void 0;
|
|
5398
5554
|
return cards.partial({ ...spec, kind });
|
|
5399
5555
|
},
|
|
5400
5556
|
async execute(input, ctx) {
|
|
5401
|
-
const { kind, spec } = input ?? {};
|
|
5557
|
+
const { kind, spec, placement } = input ?? {};
|
|
5402
5558
|
if (!kind) return { output: { ok: false, error: "`kind` is required." }, failure: "invalid-input" };
|
|
5559
|
+
if (placement !== void 0 && placement !== "inline" && !(panel && placement === "panel")) {
|
|
5560
|
+
const allowed = panel ? '"inline" or "panel"' : '"inline" (this chat has no side panel)';
|
|
5561
|
+
return { output: { ok: false, error: `placement must be ${allowed}.` }, failure: "invalid-input" };
|
|
5562
|
+
}
|
|
5403
5563
|
const full = { ...spec ?? {}, kind };
|
|
5404
5564
|
const verdict = cards.validate(full);
|
|
5405
5565
|
if (!verdict.ok) {
|
|
@@ -5411,10 +5571,14 @@ function createVisualizeTool(opts) {
|
|
|
5411
5571
|
};
|
|
5412
5572
|
}
|
|
5413
5573
|
const def = cards.get(kind);
|
|
5574
|
+
if (placement === "panel" && def?.interactive) {
|
|
5575
|
+
return { output: { ok: false, error: `${kind} asks the user something, so it is shown in the chat: send it without placement.` }, failure: "invalid-input" };
|
|
5576
|
+
}
|
|
5414
5577
|
if (def?.interactive && ctx.requestCard) {
|
|
5415
5578
|
const answer = await ctx.requestCard(full);
|
|
5416
5579
|
return { output: { ok: true, kind, response: answer } };
|
|
5417
5580
|
}
|
|
5581
|
+
if (placement === "panel") return { output: { ok: true, kind, rendered: true, placement: "panel" }, card: full, placement: "panel" };
|
|
5418
5582
|
return { output: { ok: true, kind, rendered: true }, card: full };
|
|
5419
5583
|
}
|
|
5420
5584
|
};
|
|
@@ -5480,7 +5644,7 @@ function createUpdateCardTool(cards) {
|
|
|
5480
5644
|
};
|
|
5481
5645
|
}
|
|
5482
5646
|
function createBuiltinTools(opts) {
|
|
5483
|
-
const tools = [createVisualizeTool({ cards: opts.cards }), createUpdateCardTool(opts.cards)];
|
|
5647
|
+
const tools = [createVisualizeTool({ cards: opts.cards, ...opts.placements ? { placements: opts.placements } : {} }), createUpdateCardTool(opts.cards)];
|
|
5484
5648
|
if (opts.surfaces) tools.push(...createSurfaceTools({ catalogue: opts.surfaces }));
|
|
5485
5649
|
if (opts.skills && opts.skills.list().some((s) => s.mode === "manual")) {
|
|
5486
5650
|
tools.push(createLoadSkillTool(opts.skills));
|
|
@@ -5507,6 +5671,22 @@ function reduceRunEvent(state, event) {
|
|
|
5507
5671
|
switch (event.type) {
|
|
5508
5672
|
case "run-start":
|
|
5509
5673
|
return { ...state, runId: event.runId, mode: event.mode, status: "running" };
|
|
5674
|
+
case "run-snapshot":
|
|
5675
|
+
return {
|
|
5676
|
+
...state,
|
|
5677
|
+
status: "running",
|
|
5678
|
+
parts: event.parts,
|
|
5679
|
+
cards: event.cards,
|
|
5680
|
+
pendingCard: void 0,
|
|
5681
|
+
pendingTools: Object.fromEntries(
|
|
5682
|
+
event.parts.flatMap(
|
|
5683
|
+
(p) => p.type === "tool-call" && p.status === "running" ? [[p.callId, { callId: p.callId, name: p.name }]] : []
|
|
5684
|
+
)
|
|
5685
|
+
),
|
|
5686
|
+
partialTools: {},
|
|
5687
|
+
...event.usage ? { usage: event.usage } : {},
|
|
5688
|
+
...event.steps != null ? { steps: event.steps } : {}
|
|
5689
|
+
};
|
|
5510
5690
|
case "context-built":
|
|
5511
5691
|
return { ...state, trace: event.trace, toolNames: event.toolNames };
|
|
5512
5692
|
case "step-start":
|
|
@@ -5639,8 +5819,10 @@ function upsertCard(cards, card) {
|
|
|
5639
5819
|
const i = cards.findIndex((c) => c.id === card.id);
|
|
5640
5820
|
if (i === -1) return [...cards, card];
|
|
5641
5821
|
const next = [...cards];
|
|
5642
|
-
const
|
|
5643
|
-
|
|
5822
|
+
const prev = cards[i];
|
|
5823
|
+
const home = prev.callId;
|
|
5824
|
+
const placement = card.placement ?? prev.placement;
|
|
5825
|
+
next[i] = { ...card, ...home ? { callId: home } : {}, ...placement ? { placement } : {} };
|
|
5644
5826
|
return next;
|
|
5645
5827
|
}
|
|
5646
5828
|
function markCallDone(parts, callId, status) {
|
|
@@ -6969,6 +7151,9 @@ export {
|
|
|
6969
7151
|
CARD_COMPONENT,
|
|
6970
7152
|
CARD_ENTRY_PREFIX,
|
|
6971
7153
|
CARD_KEY,
|
|
7154
|
+
CARD_PLACEMENTS,
|
|
7155
|
+
CARD_REF_LIMITS,
|
|
7156
|
+
CARD_REF_SCHEME,
|
|
6972
7157
|
CardRegistry,
|
|
6973
7158
|
ContextBuilder,
|
|
6974
7159
|
DEFAULT_PRESETS,
|
|
@@ -7002,6 +7187,7 @@ export {
|
|
|
7002
7187
|
appendText,
|
|
7003
7188
|
applyEdits,
|
|
7004
7189
|
applySurfaceOperations,
|
|
7190
|
+
approvalCard,
|
|
7005
7191
|
assistantMessage,
|
|
7006
7192
|
authorizeSurfaceTool,
|
|
7007
7193
|
awaitJob,
|
|
@@ -7097,12 +7283,14 @@ export {
|
|
|
7097
7283
|
generatedMediaUrl,
|
|
7098
7284
|
getAt,
|
|
7099
7285
|
hasTurnOrder,
|
|
7286
|
+
humanizeFieldName,
|
|
7100
7287
|
hunksOf,
|
|
7101
7288
|
image,
|
|
7102
7289
|
importMcpTools,
|
|
7103
7290
|
initialRunState,
|
|
7104
7291
|
isAgentError,
|
|
7105
7292
|
isCardCarrier,
|
|
7293
|
+
isCardPlacement,
|
|
7106
7294
|
isMultipartBody,
|
|
7107
7295
|
isScriptUrl,
|
|
7108
7296
|
isSurfaceBinding,
|
|
@@ -7131,6 +7319,7 @@ export {
|
|
|
7131
7319
|
normalizeToolName,
|
|
7132
7320
|
outlineOf,
|
|
7133
7321
|
packByPriority,
|
|
7322
|
+
parseCardRef,
|
|
7134
7323
|
parsePartialJson,
|
|
7135
7324
|
parsePointer,
|
|
7136
7325
|
parseRetryAfter,
|