@stigmer/client 0.3.2 → 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.
Files changed (48) hide show
  1. package/custom-tools.d.ts +40 -0
  2. package/custom-tools.d.ts.map +1 -0
  3. package/custom-tools.js +29 -0
  4. package/custom-tools.js.map +1 -0
  5. package/gen/client.d.ts +1 -1
  6. package/gen/client.d.ts.map +1 -1
  7. package/gen/run.d.ts +7 -0
  8. package/gen/run.d.ts.map +1 -1
  9. package/gen/run.js +18 -1
  10. package/gen/run.js.map +1 -1
  11. package/gen/session.d.ts +10 -2
  12. package/gen/session.d.ts.map +1 -1
  13. package/gen/session.js +26 -1
  14. package/gen/session.js.map +1 -1
  15. package/index.d.ts +3 -2
  16. package/index.d.ts.map +1 -1
  17. package/index.js +2 -1
  18. package/index.js.map +1 -1
  19. package/package.json +3 -3
  20. package/run/step-words.d.ts +13 -0
  21. package/run/step-words.d.ts.map +1 -1
  22. package/run/step-words.js +15 -0
  23. package/run/step-words.js.map +1 -1
  24. package/run/tool-view.d.ts +13 -4
  25. package/run/tool-view.d.ts.map +1 -1
  26. package/run/tool-view.js +11 -2
  27. package/run/tool-view.js.map +1 -1
  28. package/run/transcript.d.ts.map +1 -1
  29. package/run/transcript.js +1 -0
  30. package/run/transcript.js.map +1 -1
  31. package/run/turn-activity.d.ts +6 -1
  32. package/run/turn-activity.d.ts.map +1 -1
  33. package/run/turn-activity.js +7 -2
  34. package/run/turn-activity.js.map +1 -1
  35. package/session-events.d.ts +20 -9
  36. package/session-events.d.ts.map +1 -1
  37. package/session-events.js +12 -7
  38. package/session-events.js.map +1 -1
  39. package/src/custom-tools.ts +43 -0
  40. package/src/gen/client.ts +1 -1
  41. package/src/gen/run.ts +27 -1
  42. package/src/gen/session.ts +36 -3
  43. package/src/index.ts +3 -0
  44. package/src/run/step-words.ts +16 -0
  45. package/src/run/tool-view.ts +11 -4
  46. package/src/run/transcript.ts +1 -0
  47. package/src/run/turn-activity.ts +8 -2
  48. package/src/session-events.ts +22 -10
@@ -18,8 +18,10 @@
18
18
  * off for the rest of the follow.
19
19
  * - {@link sendAndWait} starts a turn (`run.create`, as every turn
20
20
  * starts) and follows the session until that turn's
21
- * `stigmer.run.status` says it ended, or it waits for a person's answer
22
- * (the session idles with `requires_action` naming its tool uses). It
21
+ * `stigmer.run.status` says it ended, or it waits for an answer (the
22
+ * session idles with `requires_action` naming its tool uses): a
23
+ * person's approval of an ask, or the host app's answer to a call of
24
+ * one of its own tools (the session's `custom_tools`). It
23
25
  * returns the turn's answer, structured output and how it ended;
24
26
  * {@link waitForTurn} resumes the wait after the caller answered. Its two
25
27
  * halves are exported for a caller that follows the turn its own way (a
@@ -267,8 +269,9 @@ export interface TurnOutcome {
267
269
  readonly sessionId: string;
268
270
  /**
269
271
  * The turn's phase: one that ends it (completed, failed, cancelled,
270
- * terminated), or `waiting` when it waits for a person's answer (see
271
- * {@link asks}). The wait returns on nothing else.
272
+ * terminated), or `waiting` when it waits for an answer (see
273
+ * {@link asks} and {@link customToolUses}). The wait returns on nothing
274
+ * else.
272
275
  */
273
276
  readonly phase: TurnPhase;
274
277
  /** The text of the turn's last message on its primary thread; "" when it wrote none. */
@@ -280,8 +283,14 @@ export interface TurnOutcome {
280
283
  readonly stopDetail?: TurnStopDetail;
281
284
  /** What went wrong, when it failed or was stopped with a reason. */
282
285
  readonly error: string;
283
- /** The tool uses that wait for an answer, when `phase` is waiting. */
286
+ /** The tool uses that wait for a person's approval, when `phase` is waiting: answer each with `confirmToolUse`. */
284
287
  readonly asks: ReadonlyArray<ToolUse>;
288
+ /**
289
+ * The calls of the host app's own tools that wait for its answer, when
290
+ * `phase` is waiting: answer each with `answerCustomToolUse`, never with
291
+ * an approval.
292
+ */
293
+ readonly customToolUses: ReadonlyArray<ToolUse>;
285
294
  /** The whole turn, folded. */
286
295
  readonly turn: Turn;
287
296
  /** The log's place when the wait returned: pass it to {@link waitForTurn} to resume. */
@@ -299,8 +308,9 @@ export interface WaitOptions {
299
308
  /**
300
309
  * Waits for one turn of a session: until its status says it ended, or it
301
310
  * waits for an answer. Answer each of {@link TurnOutcome.asks} (the
302
- * session's `confirmToolUse` or `grantPermission`), then call it again
303
- * with the outcome's `lastSeq`.
311
+ * session's `confirmToolUse` or `grantPermission`) and each of
312
+ * {@link TurnOutcome.customToolUses} (`answerCustomToolUse`), then call it
313
+ * again with the outcome's `lastSeq`.
304
314
  */
305
315
  export async function waitForTurn(
306
316
  client: SessionEventsClient,
@@ -360,8 +370,9 @@ export interface TurnPlace {
360
370
  /**
361
371
  * The outcome of a folded turn: its answer, output and how it stands. Its
362
372
  * phase is the status's once the turn ended, `waiting` when `waiting` says
363
- * the session waits on its asks, and otherwise the phase it reports now
364
- * (`pending` before its first status); its asks are empty once it ended.
373
+ * the session waits on its asks or custom tool uses, and otherwise the
374
+ * phase it reports now (`pending` before its first status); its asks and
375
+ * custom tool uses are empty once it ended.
365
376
  */
366
377
  export function turnOutcomeOf(turn: Turn, place: TurnPlace, lastSeq: bigint, waiting = false): TurnOutcome {
367
378
  const ended = turn.status !== undefined && turn.ended;
@@ -374,6 +385,7 @@ export function turnOutcomeOf(turn: Turn, place: TurnPlace, lastSeq: bigint, wai
374
385
  ...(ended && turn.status?.stopDetail !== undefined ? { stopDetail: turn.status.stopDetail } : {}),
375
386
  error: turn.status?.error ?? "",
376
387
  asks: ended ? [] : turn.asks,
388
+ customToolUses: ended ? [] : turn.customToolUses,
377
389
  turn,
378
390
  lastSeq,
379
391
  };
@@ -421,7 +433,7 @@ async function waitIn(
421
433
  const waiting =
422
434
  fold.status.state === "idle" &&
423
435
  fold.status.stopReason === "requires_action" &&
424
- turn.asks.some((ask) => fold.status.waitingOn.includes(ask.id));
436
+ [...turn.asks, ...turn.customToolUses].some((call) => fold.status.waitingOn.includes(call.id));
425
437
  if (ended || waiting) {
426
438
  return turnOutcomeOf(turn, { run, runId, sessionId }, fold.lastSeq, waiting);
427
439
  }