@data-fair/lib-agents-sim 0.2.0 → 0.3.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/README.md +5 -0
- package/chat-driver.d.ts +12 -1
- package/chat-driver.js +25 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,6 +68,11 @@ chat embedded in an iframe (the common case for a host application), pass
|
|
|
68
68
|
*is* the page, pass `page` itself — the driver's selectors are identical
|
|
69
69
|
either way.
|
|
70
70
|
|
|
71
|
+
The driver matches the composer's visible strings, which the chat renders in the
|
|
72
|
+
session's locale. Pass the locale your application runs in — `createChatDriver(root,
|
|
73
|
+
{ locale: 'fr' })` — or the run dies as a 15-minute "element not found" with
|
|
74
|
+
nothing pointing at the cause. The default is `'en'`.
|
|
75
|
+
|
|
71
76
|
```ts
|
|
72
77
|
import { test } from '@playwright/test'
|
|
73
78
|
import {
|
package/chat-driver.d.ts
CHANGED
|
@@ -9,11 +9,22 @@
|
|
|
9
9
|
* AgentChatInput renders a Stop button while streaming and a Send button
|
|
10
10
|
* otherwise. Waiting for text would end the turn at the first token of a
|
|
11
11
|
* multi-step tool conversation.
|
|
12
|
+
*
|
|
13
|
+
* The composer's strings are locale-dependent; `readConversation`'s are not.
|
|
14
|
+
* Pass the locale the host application runs in — the default is English.
|
|
12
15
|
*/
|
|
13
16
|
import { type Page, type FrameLocator } from '@playwright/test';
|
|
14
17
|
export type ChatRoot = Page | FrameLocator;
|
|
18
|
+
export type ChatDriverLocale = 'fr' | 'en';
|
|
19
|
+
export declare function chatDriverStrings(locale: ChatDriverLocale): {
|
|
20
|
+
input: string;
|
|
21
|
+
send: string;
|
|
22
|
+
stop: string;
|
|
23
|
+
};
|
|
15
24
|
export declare const TURN_TIMEOUT_MS: number;
|
|
16
|
-
export declare function createChatDriver(root: ChatRoot
|
|
25
|
+
export declare function createChatDriver(root: ChatRoot, opts?: {
|
|
26
|
+
locale?: ChatDriverLocale;
|
|
27
|
+
}): {
|
|
17
28
|
sendMessage(text: string): Promise<void>;
|
|
18
29
|
waitForTurn(timeoutMs?: number): Promise<void>;
|
|
19
30
|
readConversation(): Promise<{
|
package/chat-driver.js
CHANGED
|
@@ -9,21 +9,41 @@
|
|
|
9
9
|
* AgentChatInput renders a Stop button while streaming and a Send button
|
|
10
10
|
* otherwise. Waiting for text would end the turn at the first token of a
|
|
11
11
|
* multi-step tool conversation.
|
|
12
|
+
*
|
|
13
|
+
* The composer's strings are locale-dependent; `readConversation`'s are not.
|
|
14
|
+
* Pass the locale the host application runs in — the default is English.
|
|
12
15
|
*/
|
|
13
16
|
import { expect } from '@playwright/test';
|
|
14
|
-
|
|
17
|
+
/**
|
|
18
|
+
* The chat takes its locale from the session (`i18n_lang`), so a host
|
|
19
|
+
* application running in French renders a French composer. These are the only
|
|
20
|
+
* locale-dependent selectors: `readConversation` matches on classes.
|
|
21
|
+
*/
|
|
22
|
+
const STRINGS = {
|
|
23
|
+
en: { input: 'Type your message...', send: 'Send', stop: 'Stop' },
|
|
24
|
+
fr: { input: 'Tapez votre message...', send: 'Envoyer', stop: 'Arrêter' }
|
|
25
|
+
};
|
|
26
|
+
export function chatDriverStrings(locale) {
|
|
27
|
+
const strings = STRINGS[locale];
|
|
28
|
+
// Throw rather than fall back: a silent fallback turns a one-word config
|
|
29
|
+
// mistake into a timeout with no diagnosis.
|
|
30
|
+
if (!strings)
|
|
31
|
+
throw new Error(`unsupported chat locale: ${locale} (have: ${Object.keys(STRINGS).join(', ')})`);
|
|
32
|
+
return strings;
|
|
33
|
+
}
|
|
15
34
|
// The app's own watchdog is a 90s IDLE timer that re-arms per stream part, so a
|
|
16
35
|
// legitimate multi-step turn has no fixed ceiling on total time. This bounds the
|
|
17
36
|
// harness generously rather than recording a slow-but-working turn as a failure.
|
|
18
37
|
export const TURN_TIMEOUT_MS = 10 * 60 * 1000;
|
|
19
|
-
export function createChatDriver(root) {
|
|
38
|
+
export function createChatDriver(root, opts = {}) {
|
|
39
|
+
const strings = chatDriverStrings(opts.locale ?? 'en');
|
|
20
40
|
return {
|
|
21
41
|
async sendMessage(text) {
|
|
22
|
-
await root.getByPlaceholder(
|
|
23
|
-
await root.getByRole('button', { name:
|
|
42
|
+
await root.getByPlaceholder(strings.input).fill(text);
|
|
43
|
+
await root.getByRole('button', { name: strings.send }).click();
|
|
24
44
|
},
|
|
25
45
|
async waitForTurn(timeoutMs = TURN_TIMEOUT_MS) {
|
|
26
|
-
const stop = root.getByRole('button', { name:
|
|
46
|
+
const stop = root.getByRole('button', { name: strings.stop });
|
|
27
47
|
// The turn may already be finished by the time we look, so a missing Stop
|
|
28
48
|
// button is not an error — only one that never goes away is.
|
|
29
49
|
await stop.waitFor({ state: 'visible', timeout: 15000 }).catch(() => { });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@data-fair/lib-agents-sim",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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",
|