@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/dist/agent.d.ts CHANGED
@@ -41,7 +41,11 @@ export declare class Agent {
41
41
  private readonly loaded;
42
42
  private createdAt;
43
43
  /** The session's title, fixed once known (a later compaction must not turn it into the summary's first words). */
44
- private title;
44
+ private fixedTitle;
45
+ /** The conversation's title as the session list shows it (the first thing the user wrote, unless `setTitle` fixed another); undefined before there is one. */
46
+ get title(): string | undefined;
47
+ /** Fixes the conversation's title (a scheduled task's name, say); saved with the session. */
48
+ setTitle(title: string): void;
45
49
  private _ended;
46
50
  private persist;
47
51
  /** `provider`: a ModelProvider, or a RunApps SDK client (wrapped in runappsProvider). */
@@ -272,4 +276,24 @@ export declare class Agent {
272
276
  /** The model's context window in tokens (from the catalogue); same as `(await limits()).input`. */
273
277
  contextWindow(): Promise<number>;
274
278
  }
279
+ /**
280
+ * What the chat UI (`renderChat`) needs of an agent. `Agent` is one; a host
281
+ * may give `renderChat` its own object with these members instead — say one
282
+ * whose loop runs on a server, with `prompt` a request and the events relayed
283
+ * from a stream. Such an agent keeps three promises the UI relies on:
284
+ * - the objects in `messages` are stable: the message a `run_start` or
285
+ * `steered` event carried is the very object later found in `messages`;
286
+ * - `busy` is true from `run_start` until after `run_end`;
287
+ * - `rewind`, and `remove` / `clear` when it has them, emit `rewind` (or
288
+ * `history`) so the transcript is drawn again.
289
+ * The members in the second group belong to features a host can switch off
290
+ * (`queue`, `replyActions`, `clearButton`, `commands`, `debug` in ChatOptions);
291
+ * an agent without one of them must have its feature off.
292
+ */
293
+ export type ChatAgent = Pick<Agent, "id" | "provider" | "workspace" | "tools" | "messages" | "usage" | "lastEnd" | "busy" | "model" | "settings" | "title" | "on" | "ready" | "configure" | "prompt" | "abort" | "rewind" | "continue" | "compact" | "context" | "limits" | "modelInfo" | "accepts" | "compactionFor"> & Partial<Pick<Agent, "queued" | "steer" | "followUp" | "dequeue" | "remove" | "clear" | "summarize" | "seed" | "setTitle" | "systemPrompt">> & {
294
+ /** There are messages older than the first of `messages` that `loadOlder` can bring in. */
295
+ readonly hasOlder?: boolean;
296
+ /** Puts older messages before the ones in `messages`, then emits `history` (`reason: "older"`). */
297
+ loadOlder?(): Promise<void>;
298
+ };
275
299
  export {};
package/dist/agent.js CHANGED
@@ -171,7 +171,11 @@ export class Agent {
171
171
  loaded;
172
172
  createdAt = Date.now();
173
173
  /** The session's title, fixed once known (a later compaction must not turn it into the summary's first words). */
174
- title;
174
+ fixedTitle;
175
+ /** The conversation's title as the session list shows it (the first thing the user wrote, unless `setTitle` fixed another); undefined before there is one. */
176
+ get title() { return this.fixedTitle; }
177
+ /** Fixes the conversation's title (a scheduled task's name, say); saved with the session. */
178
+ setTitle(title) { this.fixedTitle = title.trim() || undefined; }
175
179
  _ended = null;
176
180
  persist;
177
181
  /** `provider`: a ModelProvider, or a RunApps SDK client (wrapped in runappsProvider). */
@@ -240,7 +244,7 @@ export class Agent {
240
244
  this.createdAt = data.createdAt ?? data.savedAt ?? Date.now();
241
245
  this._ended = data.ended ?? null;
242
246
  // Titles saved before titleOf skipped summaries and expanded commands are worked out again.
243
- this.title = data.title && !isMachineTitle(data.title) ? data.title : undefined;
247
+ this.fixedTitle = data.title && !isMachineTitle(data.title) ? data.title : undefined;
244
248
  if (data.model && !this.opts.model) {
245
249
  this.opts.model = data.model;
246
250
  this.catalogue = null;
@@ -379,12 +383,12 @@ export class Agent {
379
383
  savedAt: Date.now(),
380
384
  ...(this._ended ? { ended: this._ended } : {}),
381
385
  };
382
- if (!this.title) {
386
+ if (!this.fixedTitle) {
383
387
  const tt = titleOf(data);
384
388
  if (tt !== UNTITLED)
385
- this.title = tt;
389
+ this.fixedTitle = tt;
386
390
  }
387
- data.title = this.title ?? UNTITLED;
391
+ data.title = this.fixedTitle ?? UNTITLED;
388
392
  return data;
389
393
  }
390
394
  /** Forgets the conversation (the workspace stays). */
@@ -392,7 +396,7 @@ export class Agent {
392
396
  if (this.current)
393
397
  throw new Error("cannot reset while a run is active; abort() first");
394
398
  this.history = [];
395
- this.title = undefined;
399
+ this.fixedTitle = undefined;
396
400
  this._ended = null;
397
401
  this.committed = 0;
398
402
  this.droppedTurns = 0;
@@ -1281,7 +1285,7 @@ export class Agent {
1281
1285
  if (question === false)
1282
1286
  return true;
1283
1287
  const { title, message, always, ok, body } = typeof question === "string" ? { title: question, message: undefined, always: undefined, ok: undefined, body: undefined } : question;
1284
- return this.ui.confirm(title, message, { danger: !!tool.destructive, signal, always, ...(ok ? { ok } : {}), ...(body ? { body } : {}) });
1288
+ return this.ui.confirm(title, message, { danger: !!tool.destructive, signal, always, permission: true, ...(ok ? { ok } : {}), ...(body ? { body } : {}) });
1285
1289
  }
1286
1290
  /** After an abort, every open tool call gets a result so the transcript stays valid. */
1287
1291
  closeOpenToolCalls() {