pi-roundtable 0.22.0 → 0.22.2

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.
@@ -0,0 +1,61 @@
1
+ import type { AgentSessionEvent } from "@earendil-works/pi-coding-agent";
2
+ import type { TurnResult } from "../domain/conversation.ts";
3
+ import { AgentRunError } from "../domain/errors.ts";
4
+ import { type TurnTimeout, TurnTimeoutError } from "../domain/turn-timeout.ts";
5
+ import { catalogFor } from "../i18n/index.ts";
6
+ import type { ChannelKey } from "../sessions.ts";
7
+ import type { PromptSlot } from "./prompt-slot.ts";
8
+ import { activityTracker } from "./turn-activity.ts";
9
+ import { runtimeTurnBudget, type TurnBudget } from "./turn-budget.ts";
10
+
11
+ /** One turn's time limit, with what it follows of the turn to say why it fired. */
12
+ export interface TurnLimits {
13
+ budget: TurnBudget;
14
+ /** Follows the turn's events: its tools and its compactions. */
15
+ observe(event: AgentSessionEvent): void;
16
+ /** The turn's failure when a limit aborted it, its reason as a `TurnTimeoutError`; else undefined. */
17
+ failure(): TurnResult | undefined;
18
+ }
19
+
20
+ /** The answer to a turn whose prompt threw, when no limit aborted it. */
21
+ export function promptFailed(error: unknown): TurnResult {
22
+ return {
23
+ ok: false,
24
+ error: new AgentRunError(`prompt failed: ${String(error)}`),
25
+ };
26
+ }
27
+
28
+ /** A timed-out turn's reason in English, for its error and the logs. */
29
+ export function timeoutMessage(timeout: TurnTimeout): string {
30
+ return catalogFor("en").turnTimedOutNotice(timeout);
31
+ }
32
+
33
+ /** The time limit of a turn of the built-in runtime; see `runtimeTurnBudget`. `abort` aborts the turn. */
34
+ export function turnLimits(
35
+ options: Parameters<typeof runtimeTurnBudget>[0],
36
+ slot: Pick<PromptSlot, "waitedMs" | "cards">,
37
+ channel: ChannelKey,
38
+ abort: () => void,
39
+ ): TurnLimits {
40
+ const activity = activityTracker();
41
+ let timedOut: TurnTimeout | undefined;
42
+ const budget = runtimeTurnBudget(
43
+ options,
44
+ slot,
45
+ channel,
46
+ (timeout) => {
47
+ timedOut = timeout;
48
+ abort();
49
+ },
50
+ { activity },
51
+ );
52
+ return {
53
+ budget,
54
+ observe: (event) => activity.observe(event),
55
+ failure: () =>
56
+ timedOut && {
57
+ ok: false,
58
+ error: new TurnTimeoutError(timedOut, timeoutMessage(timedOut)),
59
+ },
60
+ };
61
+ }
package/src/index.ts CHANGED
@@ -139,6 +139,12 @@ export type {
139
139
  } from "./core/domain/interim.ts";
140
140
  export type { TurnConversation, TurnRequest } from "./core/domain/ports.ts";
141
141
  export type { HoldRefusal, TurnProgress } from "./core/domain/progress.ts";
142
+ export {
143
+ type TurnLimit,
144
+ type TurnTimeout,
145
+ type TurnTimeoutEnd,
146
+ TurnTimeoutError,
147
+ } from "./core/domain/turn-timeout.ts";
142
148
  export type { DrainOptions } from "./core/drain.ts";
143
149
  export {
144
150
  HostStoppingError,
@@ -194,6 +200,7 @@ export type {
194
200
  ApprovalDetails,
195
201
  ApprovalFile,
196
202
  ApprovalOptions,
203
+ ApprovalWording,
197
204
  ApprovedBy,
198
205
  AskOption,
199
206
  AskSupport,