@runappsai/agent 0.2.1 → 0.3.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/dist/agent-core.umd.js +66 -57
- package/dist/agent.d.ts +2 -0
- package/dist/agent.js +10 -3
- package/dist/agent.umd.js +145 -113
- package/dist/chat.js +297 -25
- package/dist/dialogs.d.ts +1 -1
- package/dist/dialogs.js +117 -38
- package/dist/index.cjs +208 -29
- package/dist/index.d.ts +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/results.d.ts +9 -0
- package/dist/results.js +130 -0
- package/dist/tool.d.ts +1 -1
- package/dist/tool.js +2 -1
- package/dist/types.d.ts +27 -5
- package/dist/ui.cjs +293 -21
- package/dist/ui.d.ts +1 -1
- package/docs/chat-ui.md +6 -1
- package/docs/tools.md +2 -2
- package/package.json +1 -1
package/dist/ui.cjs
CHANGED
|
@@ -2546,6 +2546,11 @@ var STRINGS = {
|
|
|
2546
2546
|
ok: "OK",
|
|
2547
2547
|
other: "Other\u2026",
|
|
2548
2548
|
typeAnswer: "Type your answer",
|
|
2549
|
+
prev: "Back",
|
|
2550
|
+
next: "Next",
|
|
2551
|
+
skip: "Skip",
|
|
2552
|
+
swOn: "Yes",
|
|
2553
|
+
swOff: "No",
|
|
2549
2554
|
args: "Arguments",
|
|
2550
2555
|
result: "Result",
|
|
2551
2556
|
error: "Error",
|
|
@@ -2862,6 +2867,11 @@ var STRINGS = {
|
|
|
2862
2867
|
ok: "\u786E\u5B9A",
|
|
2863
2868
|
other: "\u5176\u4ED6\u2026",
|
|
2864
2869
|
typeAnswer: "\u8BF7\u8F93\u5165",
|
|
2870
|
+
prev: "\u4E0A\u4E00\u9898",
|
|
2871
|
+
next: "\u4E0B\u4E00\u9898",
|
|
2872
|
+
skip: "\u8DF3\u8FC7",
|
|
2873
|
+
swOn: "\u662F",
|
|
2874
|
+
swOff: "\u5426",
|
|
2865
2875
|
args: "\u53C2\u6570",
|
|
2866
2876
|
result: "\u7ED3\u679C",
|
|
2867
2877
|
error: "\u9519\u8BEF",
|
|
@@ -3472,6 +3482,29 @@ var CSS = tokenCSS() + `
|
|
|
3472
3482
|
.ra-q .ra-form{display:flex;flex-direction:column;gap:8px;margin:2px 0 4px}
|
|
3473
3483
|
.ra-q .ra-ff{display:flex;flex-direction:column;gap:4px;font-size:13px;color:var(--ra-fg-muted)}
|
|
3474
3484
|
.ra-q textarea.ra-field{min-height:96px;max-height:200px;resize:vertical}
|
|
3485
|
+
.ra-q .ra-qtabs{display:flex;gap:4px;overflow-x:auto;scrollbar-width:none;margin-top:-2px}
|
|
3486
|
+
.ra-q .ra-qtabs::-webkit-scrollbar{display:none}
|
|
3487
|
+
.ra-q .ra-qtab{flex:none;display:inline-flex;align-items:center;gap:4px;max-width:11em;height:24px;padding:0 9px;border-radius:12px;border:1px solid var(--ra-border);background:var(--ra-bg);font-size:12px;color:var(--ra-fg-muted)}
|
|
3488
|
+
.ra-q .ra-qtab>span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
3489
|
+
.ra-q .ra-qtab:hover{background:var(--ra-muted)}
|
|
3490
|
+
.ra-q .ra-qtab.done{color:var(--ra-fg)}
|
|
3491
|
+
.ra-q .ra-qtab.done::before{content:"\\2713";color:var(--ra-accent);font-weight:600}
|
|
3492
|
+
.ra-q .ra-qtab.cur{border-color:var(--ra-accent);color:var(--ra-fg)}
|
|
3493
|
+
.ra-q .ra-qpane{display:flex;flex-direction:column;gap:8px}
|
|
3494
|
+
.ra-q .ra-qq{font-size:14px;white-space:pre-wrap}
|
|
3495
|
+
.ra-q .ra-opt.on{border-color:var(--ra-accent)}
|
|
3496
|
+
.ra-q .ra-opts.bad .ra-opt{border-color:var(--ra-red)}
|
|
3497
|
+
.ra-q .ra-switch{display:inline-flex;align-items:center;gap:8px;font-size:14px;color:var(--ra-fg);cursor:pointer;align-self:flex-start}
|
|
3498
|
+
.ra-chat input.ra-sw{appearance:none;-webkit-appearance:none;box-sizing:border-box;position:relative;flex:none;width:34px;height:20px;margin:0;padding:0;border:0;border-radius:10px;background:color-mix(in srgb,var(--ra-fg-muted) 45%,transparent);cursor:pointer;transition:background-color .15s}
|
|
3499
|
+
.ra-chat input.ra-sw::before{content:"";position:absolute;top:2px;left:2px;width:16px;height:16px;border-radius:50%;background:#fff;box-shadow:0 1px 2px rgba(0,0,0,.25);transition:transform .15s}
|
|
3500
|
+
.ra-chat input.ra-sw:checked{background:var(--ra-accent)}
|
|
3501
|
+
.ra-chat input.ra-sw:checked::before{transform:translateX(14px)}
|
|
3502
|
+
.ra-chat input.ra-sw:focus{outline:0;box-shadow:none}
|
|
3503
|
+
.ra-chat input.ra-sw:focus-visible{outline:2px solid var(--ra-accent);outline-offset:2px}
|
|
3504
|
+
.ra-q .ra-ff .ra-switch{margin-top:2px}
|
|
3505
|
+
.ra-q input.ra-field:is([type=date],[type=datetime-local]){min-height:32px}
|
|
3506
|
+
.ra-chat[data-scheme=dark] .ra-q input.ra-field:is([type=date],[type=datetime-local]){color-scheme:dark}
|
|
3507
|
+
.ra-chat[data-scheme=light] .ra-q input.ra-field:is([type=date],[type=datetime-local]){color-scheme:light}
|
|
3475
3508
|
.ra-btns{display:flex;justify-content:flex-end;gap:8px}
|
|
3476
3509
|
.ra-cbody{margin:2px 0 10px;max-height:min(60vh,560px);overflow:auto;min-width:0}
|
|
3477
3510
|
.ra-status{font-size:14px;color:var(--ra-fg-muted);padding:4px 0}
|
|
@@ -3847,7 +3880,7 @@ function inlineUI(askArea, toasts, t, onChange) {
|
|
|
3847
3880
|
queueMicrotask(() => focus?.focus());
|
|
3848
3881
|
});
|
|
3849
3882
|
const head = (card, title, message) => {
|
|
3850
|
-
card.append(h("div", "ra-qt", title));
|
|
3883
|
+
if (title) card.append(h("div", "ra-qt", title));
|
|
3851
3884
|
if (message) card.append(h("div", "ra-qm", message));
|
|
3852
3885
|
};
|
|
3853
3886
|
const btn = (label, cls, onClick) => {
|
|
@@ -3856,6 +3889,245 @@ function inlineUI(askArea, toasts, t, onChange) {
|
|
|
3856
3889
|
b.addEventListener("click", onClick);
|
|
3857
3890
|
return b;
|
|
3858
3891
|
};
|
|
3892
|
+
const boxFor = (f, initial, onChange2) => {
|
|
3893
|
+
if (f.type === "boolean") {
|
|
3894
|
+
const label = h("label", "ra-switch");
|
|
3895
|
+
const input2 = h("input", "ra-x ra-sw");
|
|
3896
|
+
input2.type = "checkbox";
|
|
3897
|
+
input2.setAttribute("role", "switch");
|
|
3898
|
+
input2.name = f.name;
|
|
3899
|
+
input2.checked = initial === true;
|
|
3900
|
+
const state = h("span", "", input2.checked ? t.swOn : t.swOff);
|
|
3901
|
+
input2.addEventListener("change", () => {
|
|
3902
|
+
state.textContent = input2.checked ? t.swOn : t.swOff;
|
|
3903
|
+
onChange2();
|
|
3904
|
+
});
|
|
3905
|
+
label.append(input2, state);
|
|
3906
|
+
return { el: label, focus: input2, raw: () => input2.checked };
|
|
3907
|
+
}
|
|
3908
|
+
const area = f.type === "textarea";
|
|
3909
|
+
const input = area ? h("textarea", "ra-field") : h("input", "ra-field");
|
|
3910
|
+
if (input instanceof HTMLInputElement) {
|
|
3911
|
+
input.type = f.type === "number" ? "number" : f.type === "date" ? "date" : f.type === "datetime" ? "datetime-local" : "text";
|
|
3912
|
+
if (f.type === "number") input.step = "any";
|
|
3913
|
+
}
|
|
3914
|
+
input.name = f.name;
|
|
3915
|
+
if (f.placeholder) input.placeholder = f.placeholder;
|
|
3916
|
+
input.value = typeof initial === "string" ? initial : "";
|
|
3917
|
+
input.addEventListener("input", () => {
|
|
3918
|
+
input.classList.remove("bad");
|
|
3919
|
+
onChange2();
|
|
3920
|
+
});
|
|
3921
|
+
return { el: input, focus: input, raw: () => input.value };
|
|
3922
|
+
};
|
|
3923
|
+
const boxValue = (f, raw) => {
|
|
3924
|
+
if (typeof raw === "boolean") return raw;
|
|
3925
|
+
const text = f.type === "textarea" ? raw.replace(/\s+$/, "") : raw.trim();
|
|
3926
|
+
if (!text) return void 0;
|
|
3927
|
+
return f.type === "number" ? Number(text) : text;
|
|
3928
|
+
};
|
|
3929
|
+
const startOf = (f) => f.type === "boolean" ? f.initial === true || f.initial === "true" : f.initial !== void 0 && typeof f.initial !== "boolean" ? String(f.initial) : "";
|
|
3930
|
+
const stepForm = (card, fields, okLabel, done) => {
|
|
3931
|
+
const OTHER = "__other__";
|
|
3932
|
+
const n = fields.length;
|
|
3933
|
+
const isChoice = (f) => !!f.options?.length;
|
|
3934
|
+
const required = (f) => isChoice(f) ? f.required !== false : !!f.required;
|
|
3935
|
+
const state = fields.map((f) => ({ picked: [], other: "", raw: startOf(f) }));
|
|
3936
|
+
const valueOf = (i) => {
|
|
3937
|
+
const f = fields[i], s = state[i];
|
|
3938
|
+
if (isChoice(f)) {
|
|
3939
|
+
const vals = s.picked.map((v) => v === OTHER ? s.other.trim() : v).filter(Boolean);
|
|
3940
|
+
return vals.length ? f.multi ? vals : vals[0] : void 0;
|
|
3941
|
+
}
|
|
3942
|
+
return boxValue(f, s.raw);
|
|
3943
|
+
};
|
|
3944
|
+
const valid = (i) => {
|
|
3945
|
+
const v = valueOf(i);
|
|
3946
|
+
if (typeof v === "number" && !Number.isFinite(v)) return false;
|
|
3947
|
+
if (state[i].picked.includes(OTHER) && !state[i].other.trim()) return false;
|
|
3948
|
+
return v !== void 0 || !required(fields[i]);
|
|
3949
|
+
};
|
|
3950
|
+
let cur = 0;
|
|
3951
|
+
const tabs = h("div", "ra-qtabs");
|
|
3952
|
+
const tabEls = fields.map((f, i) => {
|
|
3953
|
+
const b = h("button", "ra-qtab");
|
|
3954
|
+
b.type = "button";
|
|
3955
|
+
const label = f.label ?? f.name;
|
|
3956
|
+
b.append(h("span", "", label));
|
|
3957
|
+
b.title = label;
|
|
3958
|
+
b.addEventListener("click", () => go(i));
|
|
3959
|
+
tabs.append(b);
|
|
3960
|
+
return b;
|
|
3961
|
+
});
|
|
3962
|
+
const pane = h("div", "ra-qpane");
|
|
3963
|
+
const row = h("div", "ra-btns");
|
|
3964
|
+
const prevBtn = btn(t.prev, "ghost", () => go(cur - 1));
|
|
3965
|
+
const nextBtn = btn(t.next, "solid", () => next());
|
|
3966
|
+
row.append(btn(t.skip, "ghost", () => done(null)), prevBtn, nextBtn);
|
|
3967
|
+
if (n > 1) card.append(tabs);
|
|
3968
|
+
card.append(pane, row);
|
|
3969
|
+
const sync = () => {
|
|
3970
|
+
tabEls.forEach((b, i) => {
|
|
3971
|
+
b.classList.toggle("cur", i === cur);
|
|
3972
|
+
b.classList.toggle("done", valueOf(i) !== void 0 && valid(i));
|
|
3973
|
+
});
|
|
3974
|
+
prevBtn.style.display = cur > 0 ? "" : "none";
|
|
3975
|
+
nextBtn.textContent = cur === n - 1 ? okLabel ?? t.submit : t.next;
|
|
3976
|
+
pane.querySelectorAll(".bad").forEach((e) => e.classList.remove("bad"));
|
|
3977
|
+
};
|
|
3978
|
+
const flag = () => {
|
|
3979
|
+
const s = state[cur];
|
|
3980
|
+
const target = s.picked.includes(OTHER) ? pane.querySelector("input.ra-field") : pane.querySelector(".ra-opts,.ra-field");
|
|
3981
|
+
target?.classList.add("bad");
|
|
3982
|
+
if (target instanceof HTMLInputElement) target.focus();
|
|
3983
|
+
};
|
|
3984
|
+
const go = (i) => {
|
|
3985
|
+
if (i < 0 || i >= n || i === cur) return;
|
|
3986
|
+
cur = i;
|
|
3987
|
+
render();
|
|
3988
|
+
tabEls[i]?.scrollIntoView?.({ block: "nearest", inline: "nearest" });
|
|
3989
|
+
};
|
|
3990
|
+
const next = () => {
|
|
3991
|
+
if (!valid(cur)) {
|
|
3992
|
+
flag();
|
|
3993
|
+
return;
|
|
3994
|
+
}
|
|
3995
|
+
if (cur < n - 1) {
|
|
3996
|
+
go(cur + 1);
|
|
3997
|
+
return;
|
|
3998
|
+
}
|
|
3999
|
+
const first = fields.findIndex((_, k) => !valid(k));
|
|
4000
|
+
if (first >= 0) {
|
|
4001
|
+
go(first);
|
|
4002
|
+
flag();
|
|
4003
|
+
return;
|
|
4004
|
+
}
|
|
4005
|
+
const out = {};
|
|
4006
|
+
fields.forEach((f, k) => {
|
|
4007
|
+
const v = valueOf(k);
|
|
4008
|
+
if (v !== void 0) out[f.name] = v;
|
|
4009
|
+
});
|
|
4010
|
+
done(out);
|
|
4011
|
+
};
|
|
4012
|
+
const optionText = (o) => {
|
|
4013
|
+
const text = h("div");
|
|
4014
|
+
text.append(h("span", "", o.label ?? o.value));
|
|
4015
|
+
if (o.description) text.append(h("small", "", o.description));
|
|
4016
|
+
return text;
|
|
4017
|
+
};
|
|
4018
|
+
const render = () => {
|
|
4019
|
+
pane.replaceChildren();
|
|
4020
|
+
const f = fields[cur], s = state[cur];
|
|
4021
|
+
pane.append(h("div", "ra-qq", (f.label ?? f.name) + (required(f) && !isChoice(f) && f.type !== "boolean" ? " *" : "")));
|
|
4022
|
+
let focus = null;
|
|
4023
|
+
if (isChoice(f) && !f.multi && !f.allowOther) {
|
|
4024
|
+
const list = h("div", "ra-opts");
|
|
4025
|
+
for (const o of f.options) {
|
|
4026
|
+
const b = h("button", "ra-opt");
|
|
4027
|
+
b.type = "button";
|
|
4028
|
+
if (s.picked[0] === o.value) {
|
|
4029
|
+
b.classList.add("on");
|
|
4030
|
+
focus = b;
|
|
4031
|
+
}
|
|
4032
|
+
b.append(optionText(o));
|
|
4033
|
+
b.addEventListener("click", () => {
|
|
4034
|
+
s.picked = [o.value];
|
|
4035
|
+
sync();
|
|
4036
|
+
next();
|
|
4037
|
+
});
|
|
4038
|
+
list.append(b);
|
|
4039
|
+
}
|
|
4040
|
+
pane.append(list);
|
|
4041
|
+
focus ?? (focus = list.querySelector("button"));
|
|
4042
|
+
} else if (isChoice(f)) {
|
|
4043
|
+
const list = h("div", "ra-opts");
|
|
4044
|
+
const name = "ra_" + Math.random().toString(36).slice(2, 8);
|
|
4045
|
+
const inputs = [];
|
|
4046
|
+
const read = () => {
|
|
4047
|
+
s.picked = inputs.filter((x) => x.checked).map((x) => x.value);
|
|
4048
|
+
sync();
|
|
4049
|
+
};
|
|
4050
|
+
const all = f.allowOther ? [...f.options, { value: OTHER, label: t.other }] : f.options;
|
|
4051
|
+
for (const o of all) {
|
|
4052
|
+
const label = h("label", "ra-opt");
|
|
4053
|
+
const input = h("input");
|
|
4054
|
+
input.type = f.multi ? "checkbox" : "radio";
|
|
4055
|
+
input.name = name;
|
|
4056
|
+
input.value = o.value;
|
|
4057
|
+
input.checked = s.picked.includes(o.value);
|
|
4058
|
+
input.addEventListener("change", read);
|
|
4059
|
+
inputs.push(input);
|
|
4060
|
+
label.append(input, optionText(o));
|
|
4061
|
+
list.append(label);
|
|
4062
|
+
}
|
|
4063
|
+
pane.append(list);
|
|
4064
|
+
if (f.allowOther) {
|
|
4065
|
+
const other = h("input", "ra-field");
|
|
4066
|
+
other.type = "text";
|
|
4067
|
+
other.placeholder = t.typeAnswer;
|
|
4068
|
+
other.value = s.other;
|
|
4069
|
+
other.addEventListener("focus", () => {
|
|
4070
|
+
const o = inputs.find((x) => x.value === OTHER);
|
|
4071
|
+
if (o && !o.checked) {
|
|
4072
|
+
o.checked = true;
|
|
4073
|
+
read();
|
|
4074
|
+
}
|
|
4075
|
+
});
|
|
4076
|
+
other.addEventListener("input", () => {
|
|
4077
|
+
s.other = other.value;
|
|
4078
|
+
sync();
|
|
4079
|
+
});
|
|
4080
|
+
pane.append(other);
|
|
4081
|
+
}
|
|
4082
|
+
focus = inputs.find((x) => x.checked) ?? inputs[0] ?? null;
|
|
4083
|
+
} else {
|
|
4084
|
+
const box = boxFor(f, s.raw, () => {
|
|
4085
|
+
s.raw = box.raw();
|
|
4086
|
+
sync();
|
|
4087
|
+
});
|
|
4088
|
+
pane.append(box.el);
|
|
4089
|
+
focus = box.focus;
|
|
4090
|
+
}
|
|
4091
|
+
sync();
|
|
4092
|
+
if (card.isConnected) queueMicrotask(() => focus?.focus());
|
|
4093
|
+
};
|
|
4094
|
+
card.addEventListener("keydown", (ev) => {
|
|
4095
|
+
const e = ev;
|
|
4096
|
+
if (e.isComposing) return;
|
|
4097
|
+
const target = e.target;
|
|
4098
|
+
if (e.key === "Enter" && (e.metaKey || e.ctrlKey)) {
|
|
4099
|
+
e.preventDefault();
|
|
4100
|
+
next();
|
|
4101
|
+
return;
|
|
4102
|
+
}
|
|
4103
|
+
if (e.metaKey || e.ctrlKey || e.altKey) return;
|
|
4104
|
+
if (target instanceof HTMLTextAreaElement) return;
|
|
4105
|
+
if (e.key === "Enter") {
|
|
4106
|
+
if (!(target instanceof HTMLButtonElement)) {
|
|
4107
|
+
e.preventDefault();
|
|
4108
|
+
next();
|
|
4109
|
+
}
|
|
4110
|
+
return;
|
|
4111
|
+
}
|
|
4112
|
+
const onInput = target instanceof HTMLInputElement;
|
|
4113
|
+
if (onInput && target.type !== "radio" && target.type !== "checkbox") return;
|
|
4114
|
+
if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
|
|
4115
|
+
if (!onInput) {
|
|
4116
|
+
e.preventDefault();
|
|
4117
|
+
go(cur + (e.key === "ArrowLeft" ? -1 : 1));
|
|
4118
|
+
}
|
|
4119
|
+
return;
|
|
4120
|
+
}
|
|
4121
|
+
if (/^[1-9]$/.test(e.key)) {
|
|
4122
|
+
const opt = pane.querySelectorAll(".ra-opt")[Number(e.key) - 1];
|
|
4123
|
+
if (opt) {
|
|
4124
|
+
e.preventDefault();
|
|
4125
|
+
opt.click();
|
|
4126
|
+
}
|
|
4127
|
+
}
|
|
4128
|
+
});
|
|
4129
|
+
render();
|
|
4130
|
+
};
|
|
3859
4131
|
return {
|
|
3860
4132
|
confirm: (title, message, opts = {}) => open((card, done) => {
|
|
3861
4133
|
head(card, title, message);
|
|
@@ -3953,40 +4225,39 @@ function inlineUI(askArea, toasts, t, onChange) {
|
|
|
3953
4225
|
}, null, opts.signal),
|
|
3954
4226
|
form: (title, fields, opts = {}) => open((card, done) => {
|
|
3955
4227
|
head(card, title, opts.message);
|
|
4228
|
+
if (fields.some((f) => f.options?.length)) {
|
|
4229
|
+
stepForm(card, fields, opts.ok, done);
|
|
4230
|
+
return;
|
|
4231
|
+
}
|
|
3956
4232
|
const box = h("div", "ra-form");
|
|
3957
4233
|
const inputs = fields.map((f) => {
|
|
3958
|
-
const label = h("label", "ra-ff");
|
|
3959
|
-
label.append(h("span", "", (f.label ?? f.name) + (f.required ? " *" : "")));
|
|
3960
|
-
const
|
|
3961
|
-
|
|
3962
|
-
input.name = f.name;
|
|
3963
|
-
if (f.type === "number") input.step = "any";
|
|
3964
|
-
if (f.placeholder) input.placeholder = f.placeholder;
|
|
3965
|
-
if (f.initial !== void 0) input.value = String(f.initial);
|
|
3966
|
-
label.append(input);
|
|
4234
|
+
const label = h(f.type === "boolean" ? "div" : "label", "ra-ff");
|
|
4235
|
+
label.append(h("span", "", (f.label ?? f.name) + (f.required && f.type !== "boolean" ? " *" : "")));
|
|
4236
|
+
const field = boxFor(f, startOf(f), () => void 0);
|
|
4237
|
+
label.append(field.el);
|
|
3967
4238
|
box.append(label);
|
|
3968
|
-
return { f,
|
|
4239
|
+
return { f, field };
|
|
3969
4240
|
});
|
|
3970
4241
|
const submit = () => {
|
|
3971
4242
|
const out = {};
|
|
3972
|
-
for (const { f,
|
|
3973
|
-
const
|
|
3974
|
-
const bad =
|
|
3975
|
-
|
|
4243
|
+
for (const { f, field } of inputs) {
|
|
4244
|
+
const v = boxValue(f, field.raw());
|
|
4245
|
+
const bad = v === void 0 && !!f.required || typeof v === "number" && !Number.isFinite(v);
|
|
4246
|
+
field.focus.classList.toggle("bad", bad);
|
|
3976
4247
|
if (bad) {
|
|
3977
|
-
|
|
4248
|
+
field.focus.focus();
|
|
3978
4249
|
return;
|
|
3979
4250
|
}
|
|
3980
|
-
if (
|
|
4251
|
+
if (v !== void 0) out[f.name] = v;
|
|
3981
4252
|
}
|
|
3982
4253
|
done(out);
|
|
3983
4254
|
};
|
|
3984
4255
|
box.addEventListener("keydown", (ev) => {
|
|
3985
4256
|
const e = ev;
|
|
3986
|
-
if (e.key
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
4257
|
+
if (e.key !== "Enter" || e.isComposing) return;
|
|
4258
|
+
if (e.target instanceof HTMLTextAreaElement && !e.metaKey && !e.ctrlKey) return;
|
|
4259
|
+
e.preventDefault();
|
|
4260
|
+
submit();
|
|
3990
4261
|
});
|
|
3991
4262
|
card.append(box);
|
|
3992
4263
|
const row = h("div", "ra-btns");
|
|
@@ -4417,6 +4688,7 @@ ${t.webHint}`;
|
|
|
4417
4688
|
confirm: async (title2, message, o) => await whenCurrent(id, o?.signal) ? ui.confirm(title2, message, o?.permission && permShown && !o.always ? { ...o, always: { label: t.permAlways, onChoose: () => setPerm("auto") } } : o) : false,
|
|
4418
4689
|
select: async (title2, options, o) => await whenCurrent(id, o?.signal) ? ui.select(title2, options, o) : null,
|
|
4419
4690
|
input: async (title2, o) => await whenCurrent(id, o?.signal) ? ui.input(title2, o) : null,
|
|
4691
|
+
form: async (title2, fields, o) => await whenCurrent(id, o?.signal) && ui.form ? ui.form(title2, fields, o) : null,
|
|
4420
4692
|
notify: (m, l) => ui.notify(m, l)
|
|
4421
4693
|
});
|
|
4422
4694
|
const restorable = (a) => !!a.workspace && typeof wsOpt === "function" && !a.workspace.root;
|
package/dist/ui.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { renderChat, enhanceSelect, type ChatOptions, type ChatHandle, type ComposerAction, type SettingsField, type SettingsTab } from "./chat.js";
|
|
2
2
|
export type { FileDialog } from "./dom.js";
|
|
3
|
-
export type { ChatAgent, FormField } from "./index.js";
|
|
3
|
+
export type { ChatAgent, FormField, FormValues } from "./index.js";
|
|
4
4
|
export { selectBox, type SelectBox, type SelectOption as SelectBoxOption } from "./select.js";
|
|
5
5
|
export { VirtualList, type VRow, type VListOptions } from "./vlist.js";
|
|
6
6
|
export { CHAT_PALETTES, CHAT_COLOR_TOKENS, CHAT_SHARED_TOKENS, type ChatPalette, type ChatVars, type ChatToken, type ChatColorToken } from "./chat-theme.js";
|
package/docs/chat-ui.md
CHANGED
|
@@ -334,7 +334,12 @@ What the chat relies on:
|
|
|
334
334
|
`replyActions.delete: false` without `remove`, `clearButton: false` (and no `/new` in `commands`) without `clear`.
|
|
335
335
|
- **Dialogs**: the host's agent asks through its own `ui`; pass it `chat.ui` to ask in the cards above the composer.
|
|
336
336
|
Besides `confirm`, `select` (now with `min` / `max` for several choices) and `input`, the built-in UIs have
|
|
337
|
-
`form(title, fields)` for several fields at once.
|
|
337
|
+
`form(title, fields)` for several fields at once. A field with `options` is a choice (`multi` for several,
|
|
338
|
+
`allowOther` for the user's own answer; answered unless `required: false`); a field without is a box by its
|
|
339
|
+
`type`: `text` (the default), `number`, `textarea` (several lines; Enter is a new line, Cmd/Ctrl+Enter goes
|
|
340
|
+
on), `date` (`YYYY-MM-DD`), `datetime` (`YYYY-MM-DDTHH:mm`) or `boolean` (a switch, always true or false).
|
|
341
|
+
A form with a choice in it is asked one question at a time — tabs to go back, the answers sent together at
|
|
342
|
+
the end — and a `multi` choice's value is an array.
|
|
338
343
|
|
|
339
344
|
Two things exist for an agent whose messages change outside its own runs:
|
|
340
345
|
|
package/docs/tools.md
CHANGED
|
@@ -76,7 +76,7 @@ const exportReport = defineTool({
|
|
|
76
76
|
| `{ content, details }` | `content` only; `details` stays for your app (in the `tool_end` event) |
|
|
77
77
|
| `undefined`, `null`, `""` | `"OK"` |
|
|
78
78
|
|
|
79
|
-
Results longer than `maxResultChars` (default
|
|
79
|
+
Results longer than `maxResultChars` (default 120 000 characters) are cut, with a note saying so. What each request carries is shorter: a result over 20 000 characters goes as its head and tail, a result from before the latest user message over 2 000 characters goes as a one-line notice, and while a request is over 60 % of the model's window the run's older results get the notice too (all but the newest four). The conversation keeps them whole, and the built-in `recall_result` tool reads any of them again, from an offset or only the lines containing a text. A thrown error is sent to the model as an error result.
|
|
80
80
|
|
|
81
81
|
A tool message can only carry text in the OpenAI format, so pictures (and audio or video) a tool returns go to the model in a user message right after the batch's results, each labelled with the call it came from. Only the latest two batches' pictures are sent again on later turns — each costs thousands of tokens; older ones are replaced by a note telling the model to call the tool again for the current state.
|
|
82
82
|
|
|
@@ -243,7 +243,7 @@ In `renderChat` the globe in the composer's toolbar switches them for the user (
|
|
|
243
243
|
|
|
244
244
|
| Tool | | Option |
|
|
245
245
|
|---|---|---|
|
|
246
|
-
| `ask_user` | One to
|
|
246
|
+
| `ask_user` | One to four questions to the user, with options or free text, when a request is unclear; several are asked together in one form when the UI has `form`. | `askUser: false` removes it |
|
|
247
247
|
| `run_js` | JavaScript the model writes, run in a Worker: no DOM, no network, a captured console, and `tools` for the agent's other tools ([below](#calling-tools-from-run_js)). The model computes, parses and transforms data with it instead of guessing, and runs skills' scripts. Stopping the run ends the worker, even one stuck in a loop. | `sandbox: false`, or `{ timeoutMs, network, maxToolCalls, maxCodeChars }` |
|
|
248
248
|
| `list_files` | Files under a folder, with sizes. | with a workspace |
|
|
249
249
|
| `read_file` | A file, 2000 lines / 50 KB per call, `offset` and `limit` to continue; a PDF as text; a picture shown to a model that sees pictures. | |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runappsai/agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Agent harness: the model ↔ tool loop with a workspace, skills, sessions, compaction, a sandbox and a chat UI. Bring any OpenAI-compatible model provider (RunApps included); no runtime dependencies.",
|
|
6
6
|
"license": "MIT",
|