@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.
- package/custom-tools.d.ts +40 -0
- package/custom-tools.d.ts.map +1 -0
- package/custom-tools.js +29 -0
- package/custom-tools.js.map +1 -0
- package/gen/client.d.ts +1 -1
- package/gen/client.d.ts.map +1 -1
- package/gen/run.d.ts +7 -0
- package/gen/run.d.ts.map +1 -1
- package/gen/run.js +18 -1
- package/gen/run.js.map +1 -1
- package/gen/session.d.ts +10 -2
- package/gen/session.d.ts.map +1 -1
- package/gen/session.js +26 -1
- package/gen/session.js.map +1 -1
- package/index.d.ts +3 -2
- package/index.d.ts.map +1 -1
- package/index.js +2 -1
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/run/step-words.d.ts +13 -0
- package/run/step-words.d.ts.map +1 -1
- package/run/step-words.js +15 -0
- package/run/step-words.js.map +1 -1
- package/run/tool-view.d.ts +13 -4
- package/run/tool-view.d.ts.map +1 -1
- package/run/tool-view.js +11 -2
- package/run/tool-view.js.map +1 -1
- package/run/transcript.d.ts.map +1 -1
- package/run/transcript.js +1 -0
- package/run/transcript.js.map +1 -1
- package/run/turn-activity.d.ts +6 -1
- package/run/turn-activity.d.ts.map +1 -1
- package/run/turn-activity.js +7 -2
- package/run/turn-activity.js.map +1 -1
- package/session-events.d.ts +20 -9
- package/session-events.d.ts.map +1 -1
- package/session-events.js +12 -7
- package/session-events.js.map +1 -1
- package/src/custom-tools.ts +43 -0
- package/src/gen/client.ts +1 -1
- package/src/gen/run.ts +27 -1
- package/src/gen/session.ts +36 -3
- package/src/index.ts +3 -0
- package/src/run/step-words.ts +16 -0
- package/src/run/tool-view.ts +11 -4
- package/src/run/transcript.ts +1 -0
- package/src/run/turn-activity.ts +8 -2
- package/src/session-events.ts +22 -10
package/src/session-events.ts
CHANGED
|
@@ -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
|
|
22
|
-
*
|
|
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
|
|
271
|
-
* {@link asks}). The wait returns on nothing
|
|
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
|
|
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`)
|
|
303
|
-
*
|
|
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
|
|
364
|
-
* (`pending` before its first status); its asks
|
|
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((
|
|
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
|
}
|