@data-fair/lib-agents-sim 0.5.0 → 0.6.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/chat-driver.d.ts CHANGED
@@ -24,11 +24,23 @@ export declare function chatDriverStrings(locale: ChatDriverLocale): {
24
24
  };
25
25
  export declare const TURN_TIMEOUT_MS: number;
26
26
  export declare const SEND_TIMEOUT_MS = 15000;
27
+ /**
28
+ * How a turn ended. `waiting` means the assistant declared
29
+ * `wait_for_user_action` and is holding the turn open for the person — the
30
+ * caller's cue to let them act, then wait again for the turn it resumes.
31
+ */
32
+ export type TurnOutcome = 'ended' | 'waiting';
33
+ /**
34
+ * Matched on the activity's kind, not its label: the label is the model's own
35
+ * words interpolated into a translated string, so any text match would be both
36
+ * locale-dependent and at the mercy of what the assistant wrote.
37
+ */
38
+ export declare const WAITING_SELECTOR = "[data-testid=\"chat-activity\"][data-activity=\"waiting\"]";
27
39
  export declare function createChatDriver(root: ChatRoot, opts?: {
28
40
  locale?: ChatDriverLocale;
29
41
  }): {
30
42
  sendMessage(text: string): Promise<void>;
31
- waitForTurn(timeoutMs?: number): Promise<void>;
43
+ waitForTurn(timeoutMs?: number): Promise<TurnOutcome>;
32
44
  readConversation(): Promise<{
33
45
  role: "user" | "assistant";
34
46
  text: string;
package/chat-driver.js CHANGED
@@ -46,6 +46,12 @@ export const TURN_TIMEOUT_MS = 10 * 60 * 1000;
46
46
  // later with no diagnosis. Unrelated to TURN_TIMEOUT_MS, which bounds a
47
47
  // legitimately long model turn once the message has actually been sent.
48
48
  export const SEND_TIMEOUT_MS = 15000;
49
+ /**
50
+ * Matched on the activity's kind, not its label: the label is the model's own
51
+ * words interpolated into a translated string, so any text match would be both
52
+ * locale-dependent and at the mercy of what the assistant wrote.
53
+ */
54
+ export const WAITING_SELECTOR = '[data-testid="chat-activity"][data-activity="waiting"]';
49
55
  export function createChatDriver(root, opts = {}) {
50
56
  const strings = chatDriverStrings(opts.locale ?? 'en');
51
57
  return {
@@ -77,10 +83,23 @@ export function createChatDriver(root, opts = {}) {
77
83
  },
78
84
  async waitForTurn(timeoutMs = TURN_TIMEOUT_MS) {
79
85
  const stop = root.getByRole('button', { name: strings.stop });
86
+ const waiting = root.locator(WAITING_SELECTOR);
80
87
  // The turn may already be finished by the time we look, so a missing Stop
81
88
  // button is not an error — only one that never goes away is.
82
89
  await stop.waitFor({ state: 'visible', timeout: 15000 }).catch(() => { });
83
- await expect(stop).toHaveCount(0, { timeout: timeoutMs });
90
+ // A turn can finish two ways, and only one of them is the assistant being
91
+ // done. `wait_for_user_action` holds the turn open on purpose, having handed
92
+ // control back to the person — and a simulated person only acts between
93
+ // turns, so a harness that waited for the Stop button alone could never let
94
+ // them act on it. Every declared wait then ran its whole window and was
95
+ // recorded as a wedged turn; at a wait window as long as the harness's own
96
+ // ceiling, that is every run.
97
+ const ended = expect(stop).toHaveCount(0, { timeout: timeoutMs }).then(() => 'ended');
98
+ const armed = expect(waiting).toHaveCount(1, { timeout: timeoutMs }).then(() => 'waiting',
99
+ // Never rejects: a wait that is simply not what this turn did must not be
100
+ // the error a caller sees. The Stop arm owns the timeout message.
101
+ () => new Promise(() => { }));
102
+ return await Promise.race([ended, armed]);
84
103
  },
85
104
  async readConversation() {
86
105
  // evaluateAll, not page.evaluate: FrameLocator has no evaluate, and this
package/index.d.ts CHANGED
@@ -6,6 +6,6 @@ export { writeEvidence, evidenceDir } from './transcript.ts';
6
6
  export { computeMetrics, type RunMetrics } from './metrics.ts';
7
7
  export { selectCases } from './cases.ts';
8
8
  export { reportCases } from './report.ts';
9
- export { createChatDriver, chatDriverStrings, type ChatRoot, type ChatDriverLocale, TURN_TIMEOUT_MS, SEND_TIMEOUT_MS } from './chat-driver.ts';
9
+ export { createChatDriver, chatDriverStrings, type ChatRoot, type ChatDriverLocale, type TurnOutcome, TURN_TIMEOUT_MS, SEND_TIMEOUT_MS, WAITING_SELECTOR } from './chat-driver.ts';
10
10
  export { createPagePerception, truncate, SNAPSHOT_CAP, ACTION_TIMEOUT_MS, MCP_SERVER_NAME as PAGE_MCP_SERVER_NAME } from './page-perception.ts';
11
11
  export type { PerceptionRoot, Observation, PagePerception } from './page-perception.ts';
package/index.js CHANGED
@@ -5,5 +5,5 @@ export { writeEvidence, evidenceDir } from "./transcript.js";
5
5
  export { computeMetrics } from "./metrics.js";
6
6
  export { selectCases } from "./cases.js";
7
7
  export { reportCases } from "./report.js";
8
- export { createChatDriver, chatDriverStrings, TURN_TIMEOUT_MS, SEND_TIMEOUT_MS } from "./chat-driver.js";
8
+ export { createChatDriver, chatDriverStrings, TURN_TIMEOUT_MS, SEND_TIMEOUT_MS, WAITING_SELECTOR } from "./chat-driver.js";
9
9
  export { createPagePerception, truncate, SNAPSHOT_CAP, ACTION_TIMEOUT_MS, MCP_SERVER_NAME as PAGE_MCP_SERVER_NAME } from "./page-perception.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@data-fair/lib-agents-sim",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Primitives for judged browser simulations of the data-fair agents chat, plus a Claude Code bridge exposing the Agent SDK as an OpenAI-compatible provider.",
5
5
  "main": "index.js",
6
6
  "type": "module",