@runappsai/agent 0.1.11 → 0.2.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 +1 -1
- package/dist/agent-core.umd.js +90 -87
- package/dist/agent.d.ts +25 -1
- package/dist/agent.js +11 -7
- package/dist/agent.umd.js +140 -107
- package/dist/chat.d.ts +77 -8
- package/dist/chat.js +526 -49
- package/dist/debug-panel.d.ts +1 -1
- package/dist/debug-panel.js +1 -1
- package/dist/dialogs.js +43 -1
- package/dist/dom.d.ts +28 -1
- package/dist/dom.js +38 -1
- package/dist/files-panel.js +2 -2
- package/dist/index.cjs +555 -38
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -0
- package/dist/schedule.d.ts +152 -0
- package/dist/schedule.js +505 -0
- package/dist/types.d.ts +39 -2
- package/dist/ui.cjs +1094 -43
- package/dist/ui.d.ts +2 -0
- package/dist/vlist.d.ts +6 -0
- package/dist/vlist.js +16 -0
- package/docs/chat-ui.md +72 -1
- package/docs/tools.md +1 -0
- package/package.json +1 -1
package/dist/debug-panel.d.ts
CHANGED
package/dist/debug-panel.js
CHANGED
|
@@ -164,7 +164,7 @@ export function debugPanel(opts) {
|
|
|
164
164
|
rows.append(h("span", "ra-dmuted", "context"), ctx);
|
|
165
165
|
void a.context().then((c) => { ctx.textContent = `${c.used} / ${c.window} (${((c.used / c.window) * 100).toFixed(2)}%)`; }).catch(() => { ctx.textContent = "—"; });
|
|
166
166
|
const sys = pre("…", "tall");
|
|
167
|
-
void a.systemPrompt().then((p) => { sys.textContent = p; }).catch((err) => { sys.textContent = String(err); });
|
|
167
|
+
void (a.systemPrompt?.() ?? Promise.resolve("(this agent does not expose its system prompt)")).then((p) => { sys.textContent = p; }).catch((err) => { sys.textContent = String(err); });
|
|
168
168
|
box.append(rows, label(t.dSystem), sys, label(`${t.dMessages} (${msgs.length})`), pre(msgs, "tall"));
|
|
169
169
|
return [box];
|
|
170
170
|
};
|
package/dist/dialogs.js
CHANGED
|
@@ -110,7 +110,8 @@ export function domUI() {
|
|
|
110
110
|
const row = el("div", "display:flex;justify-content:flex-end;gap:8px");
|
|
111
111
|
row.append(button(zh ? "取消" : "Cancel", false, false, () => done(null)), button(zh ? "确定" : "OK", true, false, () => {
|
|
112
112
|
const picked = inputs.filter((i) => i.checked).map((i) => (i.value === "__other__" ? (other?.value.trim() || "") : i.value)).filter(Boolean);
|
|
113
|
-
|
|
113
|
+
const min = opts.multi ? opts.min ?? 1 : 1, max = opts.multi ? opts.max : undefined;
|
|
114
|
+
if (picked.length < min || (max !== undefined && picked.length > max))
|
|
114
115
|
return;
|
|
115
116
|
done(picked);
|
|
116
117
|
}));
|
|
@@ -141,6 +142,47 @@ export function domUI() {
|
|
|
141
142
|
}, opts.signal, null);
|
|
142
143
|
return typeof v === "string" ? v : null;
|
|
143
144
|
},
|
|
145
|
+
async form(title, fields, opts = {}) {
|
|
146
|
+
const zh = isZh();
|
|
147
|
+
const v = await openDialog((d, done) => {
|
|
148
|
+
d.append(el("div", "font-weight:600;font-size:15px;margin-bottom:6px", title));
|
|
149
|
+
if (opts.message)
|
|
150
|
+
d.append(el("div", "white-space:pre-wrap;opacity:.8;font-size:13px;margin-bottom:10px", opts.message));
|
|
151
|
+
const inputs = fields.map((f) => {
|
|
152
|
+
const label = el("label", "display:block;font-size:13px;margin:8px 0");
|
|
153
|
+
label.append(el("div", "opacity:.8;margin-bottom:4px", (f.label ?? f.name) + (f.required ? " *" : "")));
|
|
154
|
+
const input = el("input", "font:inherit;padding:8px 10px;border:1px solid rgba(127,127,127,.35);border-radius:8px;background:transparent;color:inherit;width:100%;box-sizing:border-box");
|
|
155
|
+
input.type = f.type === "number" ? "number" : "text";
|
|
156
|
+
if (f.type === "number")
|
|
157
|
+
input.step = "any";
|
|
158
|
+
if (f.placeholder)
|
|
159
|
+
input.placeholder = f.placeholder;
|
|
160
|
+
if (f.initial !== undefined)
|
|
161
|
+
input.value = String(f.initial);
|
|
162
|
+
label.append(input);
|
|
163
|
+
d.append(label);
|
|
164
|
+
return { f, input };
|
|
165
|
+
});
|
|
166
|
+
const submit = () => {
|
|
167
|
+
const out = {};
|
|
168
|
+
for (const { f, input } of inputs) {
|
|
169
|
+
const raw = input.value.trim();
|
|
170
|
+
if ((!raw && f.required) || (raw && f.type === "number" && !Number.isFinite(Number(raw)))) {
|
|
171
|
+
input.focus();
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (raw)
|
|
175
|
+
out[f.name] = f.type === "number" ? Number(raw) : raw;
|
|
176
|
+
}
|
|
177
|
+
done(out);
|
|
178
|
+
};
|
|
179
|
+
const row = el("div", "display:flex;justify-content:flex-end;gap:8px;margin-top:12px");
|
|
180
|
+
row.append(button(zh ? "取消" : "Cancel", false, false, () => done(null)), button(opts.ok ?? (zh ? "确定" : "OK"), true, false, submit));
|
|
181
|
+
d.append(row);
|
|
182
|
+
queueMicrotask(() => inputs[0]?.input.focus());
|
|
183
|
+
}, opts.signal, null);
|
|
184
|
+
return v && typeof v === "object" && !Array.isArray(v) ? v : null;
|
|
185
|
+
},
|
|
144
186
|
notify(message, level = "info") {
|
|
145
187
|
const host = el("div", [
|
|
146
188
|
"position:fixed", "right:16px", "bottom:16px", "z-index:2147483647", "max-width:min(360px,calc(100vw - 32px))",
|
package/dist/dom.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export declare function h<K extends keyof HTMLElementTagNameMap>(tag: K, cls?: string, text?: string): HTMLElementTagNameMap[K];
|
|
2
2
|
export declare const svg: (size: number, body: string, stroke?: number) => string;
|
|
3
3
|
export declare const I: {
|
|
4
|
+
clock: (s?: number) => string;
|
|
5
|
+
play: (s?: number) => string;
|
|
6
|
+
pause: (s?: number) => string;
|
|
7
|
+
pencil: (s?: number) => string;
|
|
4
8
|
tick: (s?: number) => string;
|
|
5
9
|
enter: (s?: number) => string;
|
|
6
10
|
lock: (s?: number) => string;
|
|
@@ -78,7 +82,30 @@ export declare function modalInput(root: HTMLElement, title: string, opts: {
|
|
|
78
82
|
initial?: string;
|
|
79
83
|
placeholder?: string;
|
|
80
84
|
}): Promise<string | null>;
|
|
81
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* A file dialog the chat uses instead of the browser's own chooser and
|
|
87
|
+
* downloads: on RunApps, the platform's dialog (the user's files or this
|
|
88
|
+
* device). Set by `renderChat({ fileDialog })`; otherwise the page's
|
|
89
|
+
* `puter.ui.openFiles` / `saveFile` when the RunApps shim is loaded.
|
|
90
|
+
*/
|
|
91
|
+
export interface FileDialog {
|
|
92
|
+
/** Files to open; [] when cancelled. */
|
|
93
|
+
openFiles(opts: {
|
|
94
|
+
accept?: string;
|
|
95
|
+
multiple?: boolean;
|
|
96
|
+
}): Promise<File[]>;
|
|
97
|
+
/** Save a file (the dialog may download it); resolves null when cancelled. */
|
|
98
|
+
saveFile(blob: Blob, name: string): Promise<unknown>;
|
|
99
|
+
}
|
|
100
|
+
/** Used by renderChat: the host's dialog, `false` for the browser's own, undefined to detect the platform's. */
|
|
101
|
+
export declare function setFileDialog(d: FileDialog | false | undefined): void;
|
|
102
|
+
/**
|
|
103
|
+
* Asks for files the way `input` would (its accept and multiple), through
|
|
104
|
+
* the file dialog when there is one, else by clicking the input (whose
|
|
105
|
+
* change handler takes over). `onFiles` hears the dialog's choice.
|
|
106
|
+
*/
|
|
107
|
+
export declare function chooseFiles(input: HTMLInputElement, onFiles: (files: File[]) => void): void;
|
|
108
|
+
/** Hands the user a file to save: the file dialog when there is one, else a download. */
|
|
82
109
|
export declare function downloadBlob(name: string, data: string | Uint8Array, type?: string): void;
|
|
83
110
|
/** Markdown → DOM, with a header (language, copy) on each code block and a scroll wrapper on tables. */
|
|
84
111
|
export declare function renderMD(el: HTMLElement, md: string, streaming: boolean): void;
|
package/dist/dom.js
CHANGED
|
@@ -12,6 +12,10 @@ export function h(tag, cls, text) {
|
|
|
12
12
|
}
|
|
13
13
|
export const svg = (size, body, stroke = 2) => `<svg width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="${stroke}" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${body}</svg>`;
|
|
14
14
|
export const I = {
|
|
15
|
+
clock: (s = 14) => svg(s, '<circle cx="12" cy="13" r="8"/><path d="M12 9v4l2 2"/><path d="M5 3 2 6"/><path d="m22 6-3-3"/>'),
|
|
16
|
+
play: (s = 13) => svg(s, '<polygon points="6 3 20 12 6 21 6 3"/>'),
|
|
17
|
+
pause: (s = 13) => svg(s, '<rect x="14" y="4" width="4" height="16" rx="1"/><rect x="6" y="4" width="4" height="16" rx="1"/>'),
|
|
18
|
+
pencil: (s = 13) => svg(s, '<path d="M21.17 6.81a1 1 0 0 0-3.99-3.99L3.84 16.17a2 2 0 0 0-.5.83l-1.32 4.35a.5.5 0 0 0 .62.62l4.35-1.32a2 2 0 0 0 .83-.5z"/>'),
|
|
15
19
|
tick: (s = 14) => svg(s, '<path d="M20 6 9 17l-5-5"/>'),
|
|
16
20
|
enter: (s = 14) => svg(s, '<polyline points="9 10 4 15 9 20"/><path d="M20 4v7a4 4 0 0 1-4 4H4"/>'),
|
|
17
21
|
lock: (s = 12) => svg(s, '<rect width="18" height="11" x="3" y="11" rx="2" ry="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/>'),
|
|
@@ -122,9 +126,42 @@ export async function modalInput(root, title, opts) {
|
|
|
122
126
|
const ok = await modal(root, { title, body: [field], ok: opts.ok, cancel: opts.cancel, focus: field, submitOnEnter: true });
|
|
123
127
|
return ok ? field.value.trim() || null : null;
|
|
124
128
|
}
|
|
125
|
-
|
|
129
|
+
let fileDialogOpt;
|
|
130
|
+
/** Used by renderChat: the host's dialog, `false` for the browser's own, undefined to detect the platform's. */
|
|
131
|
+
export function setFileDialog(d) { fileDialogOpt = d; }
|
|
132
|
+
function fileDialog() {
|
|
133
|
+
if (fileDialogOpt === false)
|
|
134
|
+
return undefined;
|
|
135
|
+
if (fileDialogOpt)
|
|
136
|
+
return fileDialogOpt;
|
|
137
|
+
const ui = globalThis.puter?.ui;
|
|
138
|
+
return typeof ui?.openFiles === "function" && typeof ui?.saveFile === "function" ? ui : undefined;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Asks for files the way `input` would (its accept and multiple), through
|
|
142
|
+
* the file dialog when there is one, else by clicking the input (whose
|
|
143
|
+
* change handler takes over). `onFiles` hears the dialog's choice.
|
|
144
|
+
*/
|
|
145
|
+
export function chooseFiles(input, onFiles) {
|
|
146
|
+
const d = fileDialog();
|
|
147
|
+
if (!d) {
|
|
148
|
+
input.click();
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
d.openFiles({ accept: input.accept || undefined, multiple: input.multiple }).then((files) => { if (files?.length)
|
|
152
|
+
onFiles(files); }, () => input.click());
|
|
153
|
+
}
|
|
154
|
+
/** Hands the user a file to save: the file dialog when there is one, else a download. */
|
|
126
155
|
export function downloadBlob(name, data, type) {
|
|
127
156
|
const blob = new Blob([data], { type: type || "application/octet-stream" });
|
|
157
|
+
const d = fileDialog();
|
|
158
|
+
if (d) {
|
|
159
|
+
void d.saveFile(blob, name).catch(() => plainDownload(blob, name));
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
plainDownload(blob, name);
|
|
163
|
+
}
|
|
164
|
+
function plainDownload(blob, name) {
|
|
128
165
|
const url = URL.createObjectURL(blob);
|
|
129
166
|
const a = h("a");
|
|
130
167
|
a.href = url;
|
package/dist/files-panel.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// delete. Modelled on the harness app's sidebar + editor pane, in one
|
|
5
5
|
// panel beside the transcript.
|
|
6
6
|
import { buildZip } from "./index.js";
|
|
7
|
-
import { h, I, modalConfirm, modalInput, downloadBlob, renderMD } from "./dom.js";
|
|
7
|
+
import { h, I, modalConfirm, modalInput, downloadBlob, chooseFiles, renderMD } from "./dom.js";
|
|
8
8
|
const IMAGE_RE = /\.(png|jpe?g|gif|webp|svg|bmp|avif)$/i;
|
|
9
9
|
const basename = (p) => p.slice(p.lastIndexOf("/") + 1);
|
|
10
10
|
const dirname = (p) => p.slice(0, p.lastIndexOf("/")) || "/";
|
|
@@ -69,7 +69,7 @@ export function filesPanel(opts) {
|
|
|
69
69
|
fileInput.type = "file";
|
|
70
70
|
fileInput.multiple = true;
|
|
71
71
|
fileInput.style.display = "none";
|
|
72
|
-
const uploadBtn = ibtn(I.upload(), t.upload, () => fileInput
|
|
72
|
+
const uploadBtn = ibtn(I.upload(), t.upload, () => chooseFiles(fileInput, (picked) => void upload(picked)));
|
|
73
73
|
const zipBtn = ibtn(I.download(), t.downloadZip, () => void downloadFolder("/"));
|
|
74
74
|
const newBtn = ibtn(I.filePlus(14), t.newFile, () => void newFile());
|
|
75
75
|
const refreshBtn = ibtn(I.refresh(), t.refresh, () => void refresh());
|