@data-fair/lib-agents-sim 0.6.0 → 0.7.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 +9 -1
- package/chat-driver.js +31 -3
- package/package.json +1 -1
package/chat-driver.d.ts
CHANGED
|
@@ -35,11 +35,19 @@ export type TurnOutcome = 'ended' | 'waiting';
|
|
|
35
35
|
* words interpolated into a translated string, so any text match would be both
|
|
36
36
|
* locale-dependent and at the mercy of what the assistant wrote.
|
|
37
37
|
*/
|
|
38
|
+
/**
|
|
39
|
+
* How long an armed wait must persist before the driver calls it the person's
|
|
40
|
+
* move. Long enough for a resolving wait's indicator to clear, short enough to be
|
|
41
|
+
* nothing against a wait a person is actually thinking through.
|
|
42
|
+
*/
|
|
43
|
+
export declare const WAIT_SETTLE_MS = 500;
|
|
38
44
|
export declare const WAITING_SELECTOR = "[data-testid=\"chat-activity\"][data-activity=\"waiting\"]";
|
|
39
45
|
export declare function createChatDriver(root: ChatRoot, opts?: {
|
|
40
46
|
locale?: ChatDriverLocale;
|
|
41
47
|
}): {
|
|
42
|
-
sendMessage(text: string
|
|
48
|
+
sendMessage(text: string, opts?: {
|
|
49
|
+
readyTimeoutMs?: number;
|
|
50
|
+
}): Promise<void>;
|
|
43
51
|
waitForTurn(timeoutMs?: number): Promise<TurnOutcome>;
|
|
44
52
|
readConversation(): Promise<{
|
|
45
53
|
role: "user" | "assistant";
|
package/chat-driver.js
CHANGED
|
@@ -51,14 +51,29 @@ export const SEND_TIMEOUT_MS = 15000;
|
|
|
51
51
|
* words interpolated into a translated string, so any text match would be both
|
|
52
52
|
* locale-dependent and at the mercy of what the assistant wrote.
|
|
53
53
|
*/
|
|
54
|
+
/**
|
|
55
|
+
* How long an armed wait must persist before the driver calls it the person's
|
|
56
|
+
* move. Long enough for a resolving wait's indicator to clear, short enough to be
|
|
57
|
+
* nothing against a wait a person is actually thinking through.
|
|
58
|
+
*/
|
|
59
|
+
export const WAIT_SETTLE_MS = 500;
|
|
54
60
|
export const WAITING_SELECTOR = '[data-testid="chat-activity"][data-activity="waiting"]';
|
|
55
61
|
export function createChatDriver(root, opts = {}) {
|
|
56
62
|
const strings = chatDriverStrings(opts.locale ?? 'en');
|
|
57
63
|
return {
|
|
58
|
-
async sendMessage(text) {
|
|
64
|
+
async sendMessage(text, opts = {}) {
|
|
59
65
|
const fillAndSend = async () => {
|
|
60
66
|
await root.getByPlaceholder(strings.input).fill(text, { timeout: SEND_TIMEOUT_MS });
|
|
61
|
-
|
|
67
|
+
// Wait for the composer to be able to take it. While the assistant is
|
|
68
|
+
// genuinely working the send control IS the Stop button, so there is no
|
|
69
|
+
// Send to click — and a caller that tried anyway spent SEND_TIMEOUT_MS
|
|
70
|
+
// failing, pressed Escape, failed again, and left the text sitting in the
|
|
71
|
+
// box. A judged run lost six of its nine turns exactly so, and read as an
|
|
72
|
+
// assistant that had gone silent. Waiting for the turn is not a wedged
|
|
73
|
+
// page; it is the normal case, so it gets the caller's own ceiling.
|
|
74
|
+
const send = root.getByRole('button', { name: strings.send });
|
|
75
|
+
await send.waitFor({ state: 'visible', timeout: opts.readyTimeoutMs ?? SEND_TIMEOUT_MS });
|
|
76
|
+
await send.click({ timeout: SEND_TIMEOUT_MS });
|
|
62
77
|
};
|
|
63
78
|
try {
|
|
64
79
|
await fillAndSend();
|
|
@@ -95,7 +110,20 @@ export function createChatDriver(root, opts = {}) {
|
|
|
95
110
|
// recorded as a wedged turn; at a wait window as long as the harness's own
|
|
96
111
|
// ceiling, that is every run.
|
|
97
112
|
const ended = expect(stop).toHaveCount(0, { timeout: timeoutMs }).then(() => 'ended');
|
|
98
|
-
const armed = expect(waiting).toHaveCount(1, { timeout: timeoutMs }).then(
|
|
113
|
+
const armed = expect(waiting).toHaveCount(1, { timeout: timeoutMs }).then(
|
|
114
|
+
// Still armed a moment later, not merely armed at the instant we looked.
|
|
115
|
+
// A wait that the person has just resolved keeps its indicator for as long
|
|
116
|
+
// as the click takes to round-trip, and reporting THAT as "control is
|
|
117
|
+
// yours" hands the caller a turn that is already resuming underneath: the
|
|
118
|
+
// simulation loop then sends into a working turn, where the message used
|
|
119
|
+
// to be dropped in silence. Settling costs half a second on a real wait,
|
|
120
|
+
// which is a pause measured in minutes.
|
|
121
|
+
async () => {
|
|
122
|
+
await waiting.page().waitForTimeout(WAIT_SETTLE_MS);
|
|
123
|
+
if (await waiting.count() === 0)
|
|
124
|
+
return await new Promise(() => { });
|
|
125
|
+
return 'waiting';
|
|
126
|
+
},
|
|
99
127
|
// Never rejects: a wait that is simply not what this turn did must not be
|
|
100
128
|
// the error a caller sees. The Stop arm owns the timeout message.
|
|
101
129
|
() => new Promise(() => { }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@data-fair/lib-agents-sim",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.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",
|