@runappsai/agent 0.1.15 → 0.2.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/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
- if (!picked.length)
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/index.cjs CHANGED
@@ -3445,7 +3445,8 @@ function domUI() {
3445
3445
  button(zh ? "\u53D6\u6D88" : "Cancel", false, false, () => done(null)),
3446
3446
  button(zh ? "\u786E\u5B9A" : "OK", true, false, () => {
3447
3447
  const picked = inputs.filter((i) => i.checked).map((i) => i.value === "__other__" ? other?.value.trim() || "" : i.value).filter(Boolean);
3448
- if (!picked.length) return;
3448
+ const min = opts.multi ? opts.min ?? 1 : 1, max = opts.multi ? opts.max : void 0;
3449
+ if (picked.length < min || max !== void 0 && picked.length > max) return;
3449
3450
  done(picked);
3450
3451
  })
3451
3452
  );
@@ -3477,6 +3478,45 @@ function domUI() {
3477
3478
  }, opts.signal, null);
3478
3479
  return typeof v === "string" ? v : null;
3479
3480
  },
3481
+ async form(title, fields, opts = {}) {
3482
+ const zh = isZh();
3483
+ const v = await openDialog((d, done) => {
3484
+ d.append(el("div", "font-weight:600;font-size:15px;margin-bottom:6px", title));
3485
+ if (opts.message) d.append(el("div", "white-space:pre-wrap;opacity:.8;font-size:13px;margin-bottom:10px", opts.message));
3486
+ const inputs = fields.map((f) => {
3487
+ const label = el("label", "display:block;font-size:13px;margin:8px 0");
3488
+ label.append(el("div", "opacity:.8;margin-bottom:4px", (f.label ?? f.name) + (f.required ? " *" : "")));
3489
+ 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");
3490
+ input.type = f.type === "number" ? "number" : "text";
3491
+ if (f.type === "number") input.step = "any";
3492
+ if (f.placeholder) input.placeholder = f.placeholder;
3493
+ if (f.initial !== void 0) input.value = String(f.initial);
3494
+ label.append(input);
3495
+ d.append(label);
3496
+ return { f, input };
3497
+ });
3498
+ const submit = () => {
3499
+ const out = {};
3500
+ for (const { f, input } of inputs) {
3501
+ const raw = input.value.trim();
3502
+ if (!raw && f.required || raw && f.type === "number" && !Number.isFinite(Number(raw))) {
3503
+ input.focus();
3504
+ return;
3505
+ }
3506
+ if (raw) out[f.name] = f.type === "number" ? Number(raw) : raw;
3507
+ }
3508
+ done(out);
3509
+ };
3510
+ const row = el("div", "display:flex;justify-content:flex-end;gap:8px;margin-top:12px");
3511
+ row.append(
3512
+ button(zh ? "\u53D6\u6D88" : "Cancel", false, false, () => done(null)),
3513
+ button(opts.ok ?? (zh ? "\u786E\u5B9A" : "OK"), true, false, submit)
3514
+ );
3515
+ d.append(row);
3516
+ queueMicrotask(() => inputs[0]?.input.focus());
3517
+ }, opts.signal, null);
3518
+ return v && typeof v === "object" && !Array.isArray(v) ? v : null;
3519
+ },
3480
3520
  notify(message, level = "info") {
3481
3521
  const host = el("div", [
3482
3522
  "position:fixed",
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { Agent, type PromptContent } from "./agent.js";
1
+ export { Agent, type ChatAgent, type PromptContent } from "./agent.js";
2
2
  export { openAIProvider, runappsProvider, toProvider, ProviderError, ContextOverflowError, isContextOverflow, sseData, modelAccepts, type ContextOverflow, type OverflowCause, type ModelProvider, type ModelInfo, type ModelPrice, type InputKind, type OpenAIProviderOptions, type RunAppsClientLike, type PlatformTools } from "./provider.js";
3
3
  export { webTools, WEB_TOOL_NAMES } from "./web-tools.js";
4
4
  export type { ChatMessage, ContentPart, ChatTool, ChatToolCall, ChatCompletionParams, ChatCompletionChunk, ChatCompletion, Usage } from "./llm.js";
@@ -36,4 +36,4 @@ export { buildSystemPrompt, estimateTokens, fitBudget, groupTurns } from "./cont
36
36
  export { validateSchema } from "./json-schema.js";
37
37
  export { listZip, readZipEntry, buildZip, type ZipEntry, type Inflate } from "./zip.js";
38
38
  export { skillZipFS, skillFoldersOf, subFS } from "./skill-zips.js";
39
- export type { AgentEventMap, AgentEventName, AgentFS, AgentOptions, AgentUI, AgentUsage, FileStat, JSONSchema, Permissions, RunEnd, RunEndReason, RunResult, SelectOption, SessionData, SessionSummary, Skill, Tool, ToolCallHookEvent, ToolContext, ToolDefinition, ToolConfirm, ToolResultValue, ToolStatus, ToolDisplay, } from "./types.js";
39
+ export type { AgentEventMap, AgentEventName, AgentFS, AgentOptions, AgentUI, FormField, AgentUsage, FileStat, JSONSchema, Permissions, RunEnd, RunEndReason, RunResult, SelectOption, SessionData, SessionSummary, Skill, Tool, ToolCallHookEvent, ToolContext, ToolDefinition, ToolConfirm, ToolResultValue, ToolStatus, ToolDisplay, } from "./types.js";
@@ -10,7 +10,17 @@ export interface ModelInfo {
10
10
  max_input_tokens?: number;
11
11
  /** Most tokens one reply may have. */
12
12
  max_tokens?: number;
13
- /** Request options the model takes; `inputs.reasoning_effort.enum` lists its thinking levels. */
13
+ /**
14
+ * The model's request body as JSON Schema (RunApps' `/v1/models`);
15
+ * `properties.reasoning_effort.enum` lists its thinking levels.
16
+ */
17
+ input_schema?: {
18
+ properties?: Record<string, {
19
+ enum?: unknown[];
20
+ default?: unknown;
21
+ } | boolean>;
22
+ };
23
+ /** @deprecated The old form of `input_schema`, read when a model has none. */
14
24
  options?: {
15
25
  inputs?: Record<string, {
16
26
  enum?: unknown[];
package/dist/types.d.ts CHANGED
@@ -161,6 +161,8 @@ export interface ToolDisplay<A = any> {
161
161
  label?: (args: A) => string;
162
162
  /** The card's icon (SVG markup, about 14px). */
163
163
  icon?: string;
164
+ /** Marks the card's icon for a call the reader should notice: `warning` (it spends or acts for the user), `danger` (it deletes or publishes). */
165
+ tone?: "warning" | "danger";
164
166
  /**
165
167
  * Content of the app's own on the card, under its title and visible while
166
168
  * it is folded (a card's arguments and raw result stay behind it): called
@@ -221,7 +223,9 @@ export interface AgentUI {
221
223
  select(title: string, options: SelectOption[], opts?: {
222
224
  message?: string;
223
225
  multi?: boolean;
224
- allowOther?: boolean;
226
+ allowOther?: boolean; /** With `multi`: how many may be picked (default at least 1); OK waits until the count fits. */
227
+ min?: number;
228
+ max?: number;
225
229
  signal?: AbortSignal;
226
230
  }): Promise<string[] | null>;
227
231
  /** Free text; null when dismissed. */
@@ -232,8 +236,27 @@ export interface AgentUI {
232
236
  initial?: string;
233
237
  signal?: AbortSignal;
234
238
  }): Promise<string | null>;
239
+ /**
240
+ * Several fields in one question; resolves the values by field name (a
241
+ * `number` field gives a number, an empty optional field is left out), or
242
+ * null when dismissed. Optional: a UI without it cannot be asked for a form.
243
+ */
244
+ form?(title: string, fields: FormField[], opts?: {
245
+ message?: string;
246
+ ok?: string;
247
+ signal?: AbortSignal;
248
+ }): Promise<Record<string, string | number> | null>;
235
249
  notify(message: string, level?: "info" | "warning" | "error"): void;
236
250
  }
251
+ /** One field of `AgentUI.form`. */
252
+ export interface FormField {
253
+ name: string;
254
+ label?: string;
255
+ type?: "text" | "number";
256
+ required?: boolean;
257
+ placeholder?: string;
258
+ initial?: string | number;
259
+ }
237
260
  export interface FileStat {
238
261
  /** Absolute POSIX path inside the workspace. */
239
262
  path: string;
@@ -396,7 +419,8 @@ export interface AgentEventMap {
396
419
  tokensBefore: number;
397
420
  tokensAfter: number;
398
421
  droppedTurns: number;
399
- elidedResults: number;
422
+ elidedResults: number; /** The summary's text, from an agent that does not keep it as its first message. */
423
+ summaryText?: string;
400
424
  };
401
425
  /** The session was written to the workspace. */
402
426
  session_saved: {
@@ -433,6 +457,16 @@ export interface AgentEventMap {
433
457
  rewind: {
434
458
  index: number;
435
459
  };
460
+ /**
461
+ * The messages changed from outside a run of this agent (an agent whose
462
+ * conversation lives elsewhere: see ChatAgent): the transcript is drawn
463
+ * again. `older`: messages were put before the first one, the view stays
464
+ * on what it showed; `newer`: messages were added at the end, the view
465
+ * follows them when it was at the end; `replace`: another set, shown from its end.
466
+ */
467
+ history: {
468
+ reason: "older" | "newer" | "replace";
469
+ };
436
470
  queued: {
437
471
  kind: "steer" | "followUp";
438
472
  message: ChatMessage;