@koda-sl/baker-bridge 0.125.0 → 0.127.0-dev.c97e2d09a
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 +1 -0
- package/dist/hono/avatar-accent.d.ts +23 -5
- package/dist/hono/avatar-accent.d.ts.map +1 -1
- package/dist/hono/avatar-accent.js +54 -63
- package/dist/hono/avatar-accent.js.map +1 -1
- package/dist/hono/avatar-accent.test.js +64 -35
- package/dist/hono/avatar-accent.test.js.map +1 -1
- package/dist/hono/avatar-face-question.d.ts +23 -6
- package/dist/hono/avatar-face-question.d.ts.map +1 -1
- package/dist/hono/avatar-face-question.js +48 -59
- package/dist/hono/avatar-face-question.js.map +1 -1
- package/dist/hono/avatar-face-question.test.js +46 -101
- package/dist/hono/avatar-face-question.test.js.map +1 -1
- package/dist/hono/bridge-job.d.ts +4 -0
- package/dist/hono/bridge-job.d.ts.map +1 -1
- package/dist/hono/bridge-job.js +9 -6
- package/dist/hono/bridge-job.js.map +1 -1
- package/dist/hono/bridge-job.test.js +3 -0
- package/dist/hono/bridge-job.test.js.map +1 -1
- package/dist/hono/jev.d.ts +16 -0
- package/dist/hono/jev.d.ts.map +1 -0
- package/dist/hono/jev.js +60 -0
- package/dist/hono/jev.js.map +1 -0
- package/dist/hono/jev.test.d.ts +2 -0
- package/dist/hono/jev.test.d.ts.map +1 -0
- package/dist/hono/jev.test.js +15 -0
- package/dist/hono/jev.test.js.map +1 -0
- package/dist/review/digest.d.ts +8 -1
- package/dist/review/digest.d.ts.map +1 -1
- package/dist/review/digest.js +10 -43
- package/dist/review/digest.js.map +1 -1
- package/dist/review/digest.test.js +11 -6
- package/dist/review/digest.test.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,6 +43,7 @@ await server.start();
|
|
|
43
43
|
| `INTERNAL_SECRET_KEY` | AES key for encrypting flow `_data.json` config at rest |
|
|
44
44
|
| `ANTHROPIC_API_KEY` | Anthropic API key (required by the Agent SDK) |
|
|
45
45
|
| `ANTHROPIC_BASE_URL` / `ANTHROPIC_AUTH_TOKEN` | OpenRouter routing (base URL + per-org key) injected into the sandbox. Forwarded to the Agent SDK subprocess so the agent can reach its model |
|
|
46
|
+
| `OPENROUTER_API_KEY` | The same per-org key under its own name. The bridge reads the user's and the agent's words with it before letting two kinds of call through: a question asking the user to pick an avatar's face (the casting picker shows real portraits), and an avatar accent in a language nobody asked for. Unset or unreachable, both calls go through unchecked |
|
|
46
47
|
| `CLAUDE_CODE_EXTRA_BODY` | Optional JSON merged by the CLI into every model request body. The bridge sets/extends it per turn with a per-thread `session_id` so OpenRouter sticky-routes the whole conversation to one provider instance and its instance-scoped prompt cache is re-read across the turn's many tool-call requests (see [Prompt-cache pinning](#prompt-cache-pinning)). It also defaults `provider` to Bedrock first (see [Bedrock is the preferred provider](#bedrock-is-the-preferred-provider)). Any inherited value is merged; our `session_id` and the `web`-plugin opt-out win (see [OpenRouter web plugin is forced off](#openrouter-web-plugin-is-forced-off)). An inherited `provider` replaces the Bedrock default |
|
|
47
48
|
| `BAKER_CHAT_ID` | Present only when running inside a chat sandbox. When set, the bridge relocates Claude Code auto-memory into the cloned repo (`.claude/memory`) — see [Session journal](#session-journal-agent-memory) |
|
|
48
49
|
| `BAKER_ACTING_USER_ID` | Injected into the Agent SDK subprocess env per turn (when the turn's sender is known) so in-sandbox `baker` CLI calls can scope work to the acting user — e.g. `baker mcp add --scope user` |
|
|
@@ -13,11 +13,29 @@
|
|
|
13
13
|
* own description, in the creation hint and in the family doc by now, so this is the
|
|
14
14
|
* layer left.
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* language
|
|
19
|
-
*
|
|
16
|
+
* Whether the accent fits is read by Jev from what the user said, in whatever language
|
|
17
|
+
* they write, and from the company's own Knowledge (COMPANY.md): their own language, the
|
|
18
|
+
* language the company's content is written in, a regional accent of either, or a language
|
|
19
|
+
* or market they asked for all fit. An agency member writing in English for a
|
|
20
|
+
* Spanish-market client wants a Spanish presenter. A wrong refusal leaves the user nothing
|
|
21
|
+
* to type, so a judge that cannot answer, or a company whose Knowledge cannot be read, lets
|
|
22
|
+
* the command through.
|
|
20
23
|
*/
|
|
24
|
+
import type { Judge } from "./jev.ts";
|
|
25
|
+
/**
|
|
26
|
+
* Three judgments, each its own Noul in one request: an accent fits when the user writes in
|
|
27
|
+
* its language, or asked for it, or it names no language at all. Asked as one question, a
|
|
28
|
+
* face ("eher südländischer Typ") read as a request for Italian (0.79). Re-run
|
|
29
|
+
* `scripts/avatar-guard-evals` after changing any of them.
|
|
30
|
+
*/
|
|
31
|
+
export declare const ACCENT_WRITTEN_IN_QUESTION: string;
|
|
32
|
+
export declare const ACCENT_ASKED_FOR_QUESTION: string;
|
|
33
|
+
export declare const ACCENT_COMPANY_LANGUAGE_QUESTION: string;
|
|
34
|
+
export declare const ACCENT_NAMES_LANGUAGE_QUESTION = "Does `accent` name a language, a country or a regional accent?";
|
|
35
|
+
/** Each answer is a yes at or above this. Measured in `scripts/avatar-guard-evals`. */
|
|
36
|
+
export declare const ACCENT_HELD = 0.5;
|
|
37
|
+
/** The company's own description (COMPANY.md in the Company Workspace), or undefined when unreadable. */
|
|
38
|
+
export type CompanyText = () => Promise<string | undefined>;
|
|
21
39
|
/** The `--accent` value in a `baker avatars create|update` command, if it has one. */
|
|
22
40
|
export declare function accentFrom(command: string): string | null;
|
|
23
41
|
/** The refusal, or null when the accent is consistent with what the user asked for. */
|
|
@@ -30,5 +48,5 @@ export declare function accentContradictsUser(command: string | undefined, userT
|
|
|
30
48
|
* the UK, in English" — and writes the next in Spanish had their own decision refused,
|
|
31
49
|
* with nothing they could type to get past it short of repeating themselves every time.
|
|
32
50
|
*/
|
|
33
|
-
priorUserText?:
|
|
51
|
+
priorUserText: string | undefined, judge: Judge, companyText?: CompanyText): Promise<string | null>;
|
|
34
52
|
//# sourceMappingURL=avatar-accent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avatar-accent.d.ts","sourceRoot":"","sources":["../../src/hono/avatar-accent.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"avatar-accent.d.ts","sourceRoot":"","sources":["../../src/hono/avatar-accent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAGtC;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,QAES,CAAC;AACjD,eAAO,MAAM,yBAAyB,QAG6E,CAAC;AACpH,eAAO,MAAM,gCAAgC,QAEwD,CAAC;AACtG,eAAO,MAAM,8BAA8B,mEAAmE,CAAC;AAC/G,uFAAuF;AACvF,eAAO,MAAM,WAAW,MAAM,CAAC;AAM/B,yGAAyG;AACzG,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;AAO5D,sFAAsF;AACtF,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAIzD;AAED,uFAAuF;AACvF,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,QAAQ,EAAE,MAAM,GAAG,SAAS;AAC5B;;;;;;;GAOG;AACH,aAAa,EAAE,MAAM,GAAG,SAAS,EACjC,KAAK,EAAE,KAAK,EACZ,WAAW,GAAE,WAA6B,GACzC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAqCxB"}
|
|
@@ -1,51 +1,28 @@
|
|
|
1
|
+
import { bridgeRuntimeFiles, runtimeFileStore } from "./runtime-files.js";
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* a row, each from the same Spanish sentence asking for "aspecto europeo" — a face:
|
|
7
|
-
*
|
|
8
|
-
* --accent "Dutch, neutral European accent"
|
|
9
|
-
* --accent "German, clear and authoritative"
|
|
10
|
-
* --accent "English from UK, Southern England accent"
|
|
11
|
-
*
|
|
12
|
-
* The first shipped: a Spanish client's ad, spoken in German. The rule is in the flag's
|
|
13
|
-
* own description, in the creation hint and in the family doc by now, so this is the
|
|
14
|
-
* layer left.
|
|
15
|
-
*
|
|
16
|
-
* Narrow by construction — it only fires when the user is clearly writing Spanish AND
|
|
17
|
-
* the accent clearly names another language AND nothing the user said asks for that
|
|
18
|
-
* language or market. An ad a Spaniard genuinely wants in English says so, and then
|
|
19
|
-
* this stays out of the way.
|
|
3
|
+
* Three judgments, each its own Noul in one request: an accent fits when the user writes in
|
|
4
|
+
* its language, or asked for it, or it names no language at all. Asked as one question, a
|
|
5
|
+
* face ("eher südländischer Typ") read as a request for Italian (0.79). Re-run
|
|
6
|
+
* `scripts/avatar-guard-evals` after changing any of them.
|
|
20
7
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
justification: /\b(holand[ée]s|neerland[ée]s|pa[íi]ses bajos|holanda|b[ée]lgica)\b/i,
|
|
40
|
-
},
|
|
41
|
-
{ name: "Italian", accent: /\b(italian)\b/i, justification: /\b(italiano|italiana|italia)\b/i },
|
|
42
|
-
{ name: "Portuguese", accent: /\b(portuguese|brazilian)\b/i, justification: /\b(portugu[ée]s|portugal|brasil)\b/i },
|
|
43
|
-
];
|
|
44
|
-
/** Enough Spanish function words that the user is plainly writing Spanish. */
|
|
45
|
-
const SPANISH_CONFIDENCE = 3;
|
|
46
|
-
function writesSpanish(text) {
|
|
47
|
-
return (text.match(SPANISH_MARKERS) ?? []).length >= SPANISH_CONFIDENCE;
|
|
48
|
-
}
|
|
8
|
+
export const ACCENT_WRITTEN_IN_QUESTION = "`accent` is how an ad's presenter will speak. Is `conversation` written in the language `accent` names? " +
|
|
9
|
+
"Any regional accent of that language counts.";
|
|
10
|
+
export const ACCENT_ASKED_FOR_QUESTION = "`accent` is how an ad's presenter will speak. Does `conversation` ask for the ad or presenter in the language " +
|
|
11
|
+
"`accent` names, or for a country, region or market where that language is spoken? Asking for how the " +
|
|
12
|
+
"presenter should look (a European, Nordic, Asian, Mediterranean or American look) is not asking for a language.";
|
|
13
|
+
export const ACCENT_COMPANY_LANGUAGE_QUESTION = "`accent` is how an ad's presenter will speak. `company` is the company's own description of itself. " +
|
|
14
|
+
"Is `company` written in the language `accent` names? Any regional accent of that language counts.";
|
|
15
|
+
export const ACCENT_NAMES_LANGUAGE_QUESTION = "Does `accent` name a language, a country or a regional accent?";
|
|
16
|
+
/** Each answer is a yes at or above this. Measured in `scripts/avatar-guard-evals`. */
|
|
17
|
+
export const ACCENT_HELD = 0.5;
|
|
18
|
+
/** The most of the conversation read, from its end: the latest turns carry the decision. */
|
|
19
|
+
const CONVERSATION_CHARS = 12_000;
|
|
20
|
+
/** The most of the company's Knowledge read, from its start: enough to tell its language. */
|
|
21
|
+
const COMPANY_CHARS = 4_000;
|
|
22
|
+
const readCompanyFile = async () => {
|
|
23
|
+
const read = await runtimeFileStore.readText(bridgeRuntimeFiles.companyFile());
|
|
24
|
+
return read.ok ? read.value : undefined;
|
|
25
|
+
};
|
|
49
26
|
/** The `--accent` value in a `baker avatars create|update` command, if it has one. */
|
|
50
27
|
export function accentFrom(command) {
|
|
51
28
|
if (!/\bbaker\s+avatars\s+(create|update)\b/.test(command))
|
|
@@ -54,7 +31,7 @@ export function accentFrom(command) {
|
|
|
54
31
|
return match ? (match[2] ?? match[3] ?? match[4] ?? null) : null;
|
|
55
32
|
}
|
|
56
33
|
/** The refusal, or null when the accent is consistent with what the user asked for. */
|
|
57
|
-
export function accentContradictsUser(command, userText,
|
|
34
|
+
export async function accentContradictsUser(command, userText,
|
|
58
35
|
/**
|
|
59
36
|
* What the user said EARLIER in the same conversation.
|
|
60
37
|
*
|
|
@@ -63,24 +40,38 @@ export function accentContradictsUser(command, userText,
|
|
|
63
40
|
* the UK, in English" — and writes the next in Spanish had their own decision refused,
|
|
64
41
|
* with nothing they could type to get past it short of repeating themselves every time.
|
|
65
42
|
*/
|
|
66
|
-
priorUserText) {
|
|
67
|
-
const said = [priorUserText ?? "", userText ?? ""].join("
|
|
68
|
-
|
|
43
|
+
priorUserText, judge, companyText = readCompanyFile) {
|
|
44
|
+
const said = [priorUserText ?? "", userText ?? ""].join("\n").trim().slice(-CONVERSATION_CHARS);
|
|
45
|
+
const accent = command ? accentFrom(command) : null;
|
|
46
|
+
if (!accent || !said)
|
|
47
|
+
return null;
|
|
48
|
+
const company = (await companyText())?.trim().slice(0, COMPANY_CHARS);
|
|
49
|
+
if (!company)
|
|
69
50
|
return null;
|
|
70
|
-
const
|
|
71
|
-
|
|
51
|
+
const answers = await judge([
|
|
52
|
+
...[ACCENT_WRITTEN_IN_QUESTION, ACCENT_ASKED_FOR_QUESTION, ACCENT_NAMES_LANGUAGE_QUESTION].map((question) => ({
|
|
53
|
+
instructions: { accent, conversation: said, question },
|
|
54
|
+
})),
|
|
55
|
+
{ instructions: { accent, company, question: ACCENT_COMPANY_LANGUAGE_QUESTION } },
|
|
56
|
+
]);
|
|
57
|
+
const [writtenIn, askedFor, namesLanguage, companyWritesIt] = answers ?? [];
|
|
58
|
+
if (writtenIn === undefined ||
|
|
59
|
+
askedFor === undefined ||
|
|
60
|
+
namesLanguage === undefined ||
|
|
61
|
+
companyWritesIt === undefined) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
if (writtenIn >= ACCENT_HELD ||
|
|
65
|
+
askedFor >= ACCENT_HELD ||
|
|
66
|
+
companyWritesIt >= ACCENT_HELD ||
|
|
67
|
+
namesLanguage < ACCENT_HELD) {
|
|
72
68
|
return null;
|
|
73
|
-
for (const language of FOREIGN_LANGUAGES) {
|
|
74
|
-
if (!language.accent.test(accent))
|
|
75
|
-
continue;
|
|
76
|
-
if (language.justification.test(said))
|
|
77
|
-
return null;
|
|
78
|
-
return (`Blocked: --accent "${accent}" makes this avatar speak ${language.name}, and the user is writing to you in ` +
|
|
79
|
-
`Spanish without asking for ${language.name} anywhere. --accent sets the LANGUAGE of every clip, not the ` +
|
|
80
|
-
`person's looks — "aspecto europeo", "Nordic" and "Mediterranean" describe a FACE and belong in --subject. ` +
|
|
81
|
-
`Use the user's own language (e.g. --accent "Spanish from Spain, Madrid accent"). If the ad really is for a ` +
|
|
82
|
-
`${language.name}-speaking market, ask them first and say so in the same turn.`);
|
|
83
69
|
}
|
|
84
|
-
return
|
|
70
|
+
return (`Blocked: --accent "${accent}" sets the language this avatar speaks, and nothing points to it: it is not the ` +
|
|
71
|
+
`language the user writes to you in, nor one they asked for, nor the language the company's own content is ` +
|
|
72
|
+
`written in. --accent sets the LANGUAGE of every clip, not the person's looks — "aspecto europeo", "Nordic" ` +
|
|
73
|
+
`and "Mediterranean" describe a FACE and belong in --subject. Use the language of the market the ad is for: ` +
|
|
74
|
+
`the user's own, or the company's. If the ad really is for a market that speaks another language, ask them ` +
|
|
75
|
+
`first and say so in the same turn.`);
|
|
85
76
|
}
|
|
86
77
|
//# sourceMappingURL=avatar-accent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avatar-accent.js","sourceRoot":"","sources":["../../src/hono/avatar-accent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"avatar-accent.js","sourceRoot":"","sources":["../../src/hono/avatar-accent.ts"],"names":[],"mappings":"AAwBA,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE1E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,0BAA0B,GACrC,0GAA0G;IAC1G,8CAA8C,CAAC;AACjD,MAAM,CAAC,MAAM,yBAAyB,GACpC,gHAAgH;IAChH,uGAAuG;IACvG,iHAAiH,CAAC;AACpH,MAAM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,CAAC;AACJ,CAAC"}
|
|
@@ -1,48 +1,77 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { accentContradictsUser, accentFrom } from "./avatar-accent.js";
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
import { ACCENT_ASKED_FOR_QUESTION, ACCENT_NAMES_LANGUAGE_QUESTION, accentContradictsUser, accentFrom, } from "./avatar-accent.js";
|
|
3
|
+
const CREATE = (accent) => `baker avatars create --name "X" --accent "${accent}"`;
|
|
4
|
+
/** A company whose Knowledge `fitsWhen` never reads as written in the accent's language. */
|
|
5
|
+
const COMPANY = async () => "# Słoneczne Panele\n\nMontujemy panele słoneczne w Polsce.";
|
|
6
|
+
/**
|
|
7
|
+
* A judge that reads every accent as naming a language unless it mentions `noLanguage`, and
|
|
8
|
+
* holds it asked for only when the conversation mentions `marker`. The user never writes in it.
|
|
9
|
+
*/
|
|
10
|
+
function fitsWhen(marker, noLanguage = "warm") {
|
|
11
|
+
return async (questions) => questions.map(({ instructions }) => {
|
|
12
|
+
if (instructions.question === ACCENT_NAMES_LANGUAGE_QUESTION) {
|
|
13
|
+
return instructions.accent?.includes(noLanguage) ? 0.02 : 0.9;
|
|
14
|
+
}
|
|
15
|
+
if (instructions.question === ACCENT_ASKED_FOR_QUESTION) {
|
|
16
|
+
return instructions.conversation?.includes(marker) ? 0.9 : 0.1;
|
|
13
17
|
}
|
|
18
|
+
return 0.05;
|
|
14
19
|
});
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
}
|
|
21
|
+
describe("accentContradictsUser", () => {
|
|
22
|
+
it("refuses an accent the judge reads as a language nobody asked for, in any language the user writes", async () => {
|
|
23
|
+
const refusal = await accentContradictsUser(CREATE("Swedish, neutral"), "Zrób awatara do reklamy na TikToka o panelach słonecznych, ma wyglądać skandynawsko.", undefined, fitsWhen("po szwedzku"), COMPANY);
|
|
24
|
+
expect(refusal).toContain("--accent sets the LANGUAGE");
|
|
25
|
+
expect(refusal).toContain("the market the ad is for");
|
|
17
26
|
});
|
|
18
|
-
it("
|
|
19
|
-
|
|
20
|
-
expect(
|
|
27
|
+
it("lets the command through when the company's Knowledge cannot be read, rather than refuse on a guess", async () => {
|
|
28
|
+
const refusal = await accentContradictsUser(CREATE("Swedish, neutral"), "Zrób awatara do reklamy na TikToka o panelach słonecznych.", undefined, fitsWhen("po szwedzku"), async () => undefined);
|
|
29
|
+
expect(refusal).toBeNull();
|
|
21
30
|
});
|
|
22
|
-
it("
|
|
23
|
-
|
|
31
|
+
it("allows the language the company's own Knowledge is written in, when the conversation is in another", async () => {
|
|
32
|
+
// An agency member writing in English for a Spanish-market client: the ad is for the
|
|
33
|
+
// client's market, so its presenter speaks the client's language.
|
|
34
|
+
const companyWritesIt = async (questions) => questions.map(({ instructions }) => {
|
|
35
|
+
if (instructions.question === ACCENT_NAMES_LANGUAGE_QUESTION)
|
|
36
|
+
return 0.9;
|
|
37
|
+
return instructions.company?.includes("Clínica dental en Valencia") ? 0.95 : 0.05;
|
|
38
|
+
});
|
|
39
|
+
const refusal = await accentContradictsUser(CREATE("Spanish from Spain"), "UGC ad for our summer promo", undefined, companyWritesIt, async () => "# Sonrisa\n\nClínica dental en Valencia con tres sedes.");
|
|
40
|
+
expect(refusal).toBeNull();
|
|
24
41
|
});
|
|
25
|
-
it("
|
|
26
|
-
|
|
27
|
-
expect(
|
|
42
|
+
it("allows an accent the judge reads as asked for", async () => {
|
|
43
|
+
const refusal = await accentContradictsUser(CREATE("German, standard"), "Reklama jest na rynek niemiecki, awatar ma mówić po niemiecku.", undefined, fitsWhen("po niemiecku"), COMPANY);
|
|
44
|
+
expect(refusal).toBeNull();
|
|
28
45
|
});
|
|
29
|
-
it("reads the
|
|
30
|
-
|
|
31
|
-
|
|
46
|
+
it("reads what the user said in an earlier turn on the same footing as this one", async () => {
|
|
47
|
+
// A user who settles the market in one turn and writes the next in Spanish had their
|
|
48
|
+
// own decision refused, with nothing they could type short of repeating it every time.
|
|
49
|
+
const refusal = await accentContradictsUser(CREATE("English from UK, Southern England accent"), "Crea el avatar y empieza con el primer clip.", "La campaña es para UK y el anuncio va en inglés.", fitsWhen("para UK"), COMPANY);
|
|
50
|
+
expect(refusal).toBeNull();
|
|
32
51
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// The gate reads the turn in front of it. A user who settles the market in one turn —
|
|
37
|
-
// "the campaign is for the UK, in English" — and then writes the next one in Spanish
|
|
38
|
-
// got their own decision refused, with nothing they could type to get past it short of
|
|
39
|
-
// repeating themselves in every message.
|
|
40
|
-
const refusal = accentContradictsUser('baker avatars create --name "X" --accent "English from UK, Southern England accent"', "Crea el avatar y empieza con el primer clip.", "La campaña es para UK y el anuncio va en inglés.");
|
|
52
|
+
it("allows the language the user writes in, which nobody has to ask for", async () => {
|
|
53
|
+
const writesIt = async (questions) => questions.map(({ instructions }) => (instructions.question === ACCENT_ASKED_FOR_QUESTION ? 0.1 : 0.95));
|
|
54
|
+
const refusal = await accentContradictsUser(CREATE("Polish, Warsaw"), "Zrób awatara do reklamy.", undefined, writesIt, COMPANY);
|
|
41
55
|
expect(refusal).toBeNull();
|
|
42
56
|
});
|
|
43
|
-
it("
|
|
44
|
-
const refusal = accentContradictsUser(
|
|
45
|
-
expect(refusal).
|
|
57
|
+
it("lets an accent that names no language through: it cannot contradict anything", async () => {
|
|
58
|
+
const refusal = await accentContradictsUser(CREATE("warm and friendly"), "Crea un avatar para la clínica dental.", undefined, fitsWhen("nothing asked"), COMPANY);
|
|
59
|
+
expect(refusal).toBeNull();
|
|
60
|
+
});
|
|
61
|
+
it("lets the command through when the judge cannot answer, rather than refuse on a guess", async () => {
|
|
62
|
+
expect(await accentContradictsUser(CREATE("German"), "Hazme un avatar", undefined, async () => null, COMPANY)).toBeNull();
|
|
63
|
+
});
|
|
64
|
+
it("ignores commands that set no accent, without asking the judge", async () => {
|
|
65
|
+
const unreachable = () => Promise.reject(new Error("the judge should not be asked"));
|
|
66
|
+
expect(await accentContradictsUser("grep -rn -- --accent docs/", "Hazme un avatar", undefined, unreachable)).toBeNull();
|
|
67
|
+
expect(await accentContradictsUser('baker avatars create --name "X"', "Hazme un avatar", undefined, unreachable)).toBeNull();
|
|
68
|
+
expect(await accentContradictsUser(undefined, "Hazme un avatar", undefined, unreachable)).toBeNull();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
describe("accentFrom", () => {
|
|
72
|
+
it("reads the accent however it was quoted", () => {
|
|
73
|
+
expect(accentFrom('baker avatars create --accent "German, firm"')).toBe("German, firm");
|
|
74
|
+
expect(accentFrom("baker avatars update marta --accent='British English'")).toBe("British English");
|
|
46
75
|
});
|
|
47
76
|
});
|
|
48
77
|
//# sourceMappingURL=avatar-accent.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avatar-accent.test.js","sourceRoot":"","sources":["../../src/hono/avatar-accent.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,
|
|
1
|
+
{"version":3,"file":"avatar-accent.test.js","sourceRoot":"","sources":["../../src/hono/avatar-accent.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,yBAAyB,EACzB,8BAA8B,EAC9B,qBAAqB,EACrB,UAAU,GACX,MAAM,oBAAoB,CAAC;AAG5B,MAAM,MAAM,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,6CAA6C,MAAM,GAAG,CAAC;AAC1F,4FAA4F;AAC5F,MAAM,OAAO,GAAG,KAAK,IAAI,EAAE,CAAC,4DAA4D,CAAC;AAEzF;;;GAGG;AACH,SAAS,QAAQ,CAAC,MAAc,EAAE,UAA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AC,CAAC;QAC5F,MAAM,CACJ,MAAM,qBAAqB,CAAC,4BAA4B,EAAE,iBAAiB,EAAE,SAAS,EAAE,WAAW,CAAC,CACrG,CAAC,QAAQ,EAAE,CAAC;QACb,MAAM,CACJ,MAAM,qBAAqB,CAAC,iCAAiC,EAAE,iBAAiB,EAAE,SAAS,EAAE,WAAW,CAAC,CAC1G,CAAC,QAAQ,EAAE,CAAC;QACb,MAAM,CAAC,MAAM,qBAAqB,CAAC,SAAS,EAAE,iBAAiB,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IACvG,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAChD,MAAM,CAAC,UAAU,CAAC,8CAA8C,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QACxF,MAAM,CAAC,UAAU,CAAC,uDAAuD,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACtG,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -11,15 +11,32 @@
|
|
|
11
11
|
* before asking anyway — three times, in both casting modes. A rule that survives being
|
|
12
12
|
* read needs a gate, and `routeToolUse` is the one path every question travels.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
* Read by Jev, so a face asked for in any language or wording is caught, with no list of
|
|
15
|
+
* face words to fall out of date. Its own module, with the judge as a parameter, so it can be
|
|
16
|
+
* tested without the network or the bridge's environment.
|
|
16
17
|
*/
|
|
18
|
+
import type { Judge } from "./jev.ts";
|
|
19
|
+
/**
|
|
20
|
+
* The two questions Jev answers about each question the agent asks, as the user would read
|
|
21
|
+
* it: is it a face pick, and is it about a page. A presenter section on a landing is a photo
|
|
22
|
+
* the user already has, which the casting picker cannot offer, and asked in one question it
|
|
23
|
+
* read as a face pick (0.81). Kept word for word in step with the scaffold's
|
|
24
|
+
* guard-avatar-face-question hook, the same rule one layer in. Re-run
|
|
25
|
+
* `scripts/avatar-guard-evals` after changing either.
|
|
26
|
+
*/
|
|
27
|
+
export declare const FACE_PICK_QUESTION: string;
|
|
28
|
+
export declare const ON_A_PAGE_QUESTION = "Does `asked` mention a website, a landing page or a section of a web page?";
|
|
29
|
+
/** At or above, a face pick; below, not about a page. Measured in `scripts/avatar-guard-evals`. */
|
|
30
|
+
export declare const FACE_PICK_HELD = 0.5;
|
|
31
|
+
export declare const ON_A_PAGE_HELD = 0.5;
|
|
17
32
|
/** What the agent is told when this is refused — names both ways out. */
|
|
18
33
|
export declare const FACE_QUESTION_MESSAGE: string;
|
|
34
|
+
/** One question as the user would read it: header, question, then each option. Pure. */
|
|
35
|
+
export declare function questionText(question: unknown): string;
|
|
19
36
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
37
|
+
* Whether any question asks the user to pick a face. Each question is put to the judge as
|
|
38
|
+
* two Nouls, all in one request. A wrong refusal costs the user a real question, so a judge that
|
|
39
|
+
* cannot answer lets every question through.
|
|
23
40
|
*/
|
|
24
|
-
export declare function asksForAvatarFace(input: Record<string, unknown> | undefined): boolean
|
|
41
|
+
export declare function asksForAvatarFace(input: Record<string, unknown> | undefined, judge: Judge): Promise<boolean>;
|
|
25
42
|
//# sourceMappingURL=avatar-face-question.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avatar-face-question.d.ts","sourceRoot":"","sources":["../../src/hono/avatar-face-question.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"avatar-face-question.d.ts","sourceRoot":"","sources":["../../src/hono/avatar-face-question.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,QAKpB,CAAC;AACZ,eAAO,MAAM,kBAAkB,+EAA+E,CAAC;AAC/G,mGAAmG;AACnG,eAAO,MAAM,cAAc,MAAM,CAAC;AAClC,eAAO,MAAM,cAAc,MAAM,CAAC;AAElC,yEAAyE;AACzE,eAAO,MAAM,qBAAqB,QAK4B,CAAC;AAE/D,wFAAwF;AACxF,wBAAgB,YAAY,CAAC,QAAQ,EAAE,OAAO,GAAG,MAAM,CAWtD;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAalH"}
|
|
@@ -11,78 +11,67 @@
|
|
|
11
11
|
* before asking anyway — three times, in both casting modes. A rule that survives being
|
|
12
12
|
* read needs a gate, and `routeToolUse` is the one path every question travels.
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
14
|
+
* Read by Jev, so a face asked for in any language or wording is caught, with no list of
|
|
15
|
+
* face words to fall out of date. Its own module, with the judge as a parameter, so it can be
|
|
16
|
+
* tested without the network or the bridge's environment.
|
|
16
17
|
*/
|
|
17
|
-
/** A face, in the languages the product is used in. `typeface` must not match. */
|
|
18
|
-
const FACE_WORD = /(?<!type)\b(faces?|rostros?|caras?|retratos?|portraits?)\b/i;
|
|
19
18
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
19
|
+
* The two questions Jev answers about each question the agent asks, as the user would read
|
|
20
|
+
* it: is it a face pick, and is it about a page. A presenter section on a landing is a photo
|
|
21
|
+
* the user already has, which the casting picker cannot offer, and asked in one question it
|
|
22
|
+
* read as a face pick (0.81). Kept word for word in step with the scaffold's
|
|
23
|
+
* guard-avatar-face-question hook, the same rule one layer in. Re-run
|
|
24
|
+
* `scripts/avatar-guard-evals` after changing either.
|
|
22
25
|
*/
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const CASTING_WORD = /\b(avatars?|casting)\b/i;
|
|
33
|
-
const ROLE_WORD = /\b(presentador[ao]s?|presenters?)\b/i;
|
|
34
|
-
/**
|
|
35
|
-
* An asset the user ALREADY has, which is never a face waiting to be cast. Only
|
|
36
|
-
* consulted for the weak `ROLE_WORD` tier: under an explicit avatar or casting
|
|
37
|
-
* header the picker is still the answer however the question is worded.
|
|
38
|
-
*/
|
|
39
|
-
const EXISTING_ASSET_WORD = /\b(landings?|p[áa]ginas?|pages?|secci[óo]n|seccion|sections?|hero|fotos?|photos?|im[áa]genes|imagen|images?)\b/i;
|
|
40
|
-
/**
|
|
41
|
-
* "Portrait" the ORIENTATION, which is not a face at all.
|
|
42
|
-
*
|
|
43
|
-
* An aspect ratio beside it, or a sibling that names a frame shape, says the question
|
|
44
|
-
* is about the shape of the frame. Under an "Avatar" header that question read as a
|
|
45
|
-
* face picker and was refused — and a wrong refusal costs the user a real question
|
|
46
|
-
* this tool is exactly right for. `vertical` is in the list because it is the
|
|
47
|
-
* commonest phrasing of it and the only one Spanish uses; without it the exemption
|
|
48
|
-
* only ever fired on a question that happened to offer landscape as the alternative.
|
|
49
|
-
*/
|
|
50
|
-
const ORIENTATION_WORD = /\b(\d{1,2}:\d{1,2}|landscape|square|horizontal|vertical|apaisado|cuadrado|aspect ratio|relaci[óo]n de aspecto)\b/i;
|
|
26
|
+
export const FACE_PICK_QUESTION = "`asked` is a question an AI assistant puts to a marketer while making a video ad with a generated presenter " +
|
|
27
|
+
"(an avatar), shown as text with options. Does it ask the marketer to pick which person the presenter is, by " +
|
|
28
|
+
"their face, age, hair or general appearance? Not when it asks about the video format or orientation, where " +
|
|
29
|
+
"the presenter looks or how they move, their accent, language, voice or clothes, or whether to use a presenter " +
|
|
30
|
+
"at all.";
|
|
31
|
+
export const ON_A_PAGE_QUESTION = "Does `asked` mention a website, a landing page or a section of a web page?";
|
|
32
|
+
/** At or above, a face pick; below, not about a page. Measured in `scripts/avatar-guard-evals`. */
|
|
33
|
+
export const FACE_PICK_HELD = 0.5;
|
|
34
|
+
export const ON_A_PAGE_HELD = 0.5;
|
|
51
35
|
/** What the agent is told when this is refused — names both ways out. */
|
|
52
36
|
export const FACE_QUESTION_MESSAGE = "Blocked: this tool renders text, so it cannot show a face — the user would be choosing between descriptions of " +
|
|
53
37
|
"people they cannot see. If they should choose, invoke the request_avatar_casting TOOL instead — as a tool call with " +
|
|
54
38
|
"avatarHandle, never as a shell command — it renders " +
|
|
55
39
|
"the real portraits and blocks until they pick. If nobody is there to ask, create the avatar with --face auto, ask " +
|
|
56
40
|
"nothing, and do not describe the resulting face as chosen.";
|
|
41
|
+
/** One question as the user would read it: header, question, then each option. Pure. */
|
|
42
|
+
export function questionText(question) {
|
|
43
|
+
if (typeof question !== "object" || question === null)
|
|
44
|
+
return "";
|
|
45
|
+
const { header, question: asked, options } = question;
|
|
46
|
+
const lines = [[header, asked].filter((part) => typeof part === "string" && part.trim()).join(" — ")];
|
|
47
|
+
for (const option of Array.isArray(options) ? options : []) {
|
|
48
|
+
if (typeof option !== "object" || option === null)
|
|
49
|
+
continue;
|
|
50
|
+
const { label, description } = option;
|
|
51
|
+
const parts = [label, description].filter((part) => typeof part === "string" && part.trim());
|
|
52
|
+
if (parts.length > 0)
|
|
53
|
+
lines.push(`- ${parts.join(": ")}`);
|
|
54
|
+
}
|
|
55
|
+
return lines.join("\n").trim();
|
|
56
|
+
}
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
58
|
+
* Whether any question asks the user to pick a face. Each question is put to the judge as
|
|
59
|
+
* two Nouls, all in one request. A wrong refusal costs the user a real question, so a judge that
|
|
60
|
+
* cannot answer lets every question through.
|
|
61
61
|
*/
|
|
62
|
-
export function asksForAvatarFace(input) {
|
|
62
|
+
export async function asksForAvatarFace(input, judge) {
|
|
63
63
|
const questions = input?.questions;
|
|
64
64
|
if (!Array.isArray(questions))
|
|
65
65
|
return false;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// The verb is dropped before anything else looks for a face, so a question that
|
|
77
|
-
// only ever used `face` that way has no face in it at all.
|
|
78
|
-
const text = `${String(q.header ?? "")} ${String(q.question ?? "")} ${options}`.replace(FACE_VERB, " ");
|
|
79
|
-
if (ORIENTATION_WORD.test(text) && !/(faces?|rostros?|caras?)\b/i.test(text))
|
|
80
|
-
return false;
|
|
81
|
-
if (!FACE_WORD.test(text))
|
|
82
|
-
return false;
|
|
83
|
-
if (CASTING_WORD.test(text))
|
|
84
|
-
return true;
|
|
85
|
-
return ROLE_WORD.test(text) && !EXISTING_ASSET_WORD.test(text);
|
|
86
|
-
});
|
|
66
|
+
const asked = questions.map(questionText).filter(Boolean);
|
|
67
|
+
if (asked.length === 0)
|
|
68
|
+
return false;
|
|
69
|
+
const answers = await judge(asked.flatMap((text) => [
|
|
70
|
+
{ instructions: { asked: text, question: FACE_PICK_QUESTION } },
|
|
71
|
+
{ instructions: { asked: text, question: ON_A_PAGE_QUESTION } },
|
|
72
|
+
]));
|
|
73
|
+
if (!answers)
|
|
74
|
+
return false;
|
|
75
|
+
return asked.some((_, i) => (answers[2 * i] ?? 0) >= FACE_PICK_HELD && (answers[2 * i + 1] ?? 1) < ON_A_PAGE_HELD);
|
|
87
76
|
}
|
|
88
77
|
//# sourceMappingURL=avatar-face-question.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avatar-face-question.js","sourceRoot":"","sources":["../../src/hono/avatar-face-question.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"avatar-face-question.js","sourceRoot":"","sources":["../../src/hono/avatar-face-question.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH;;;;;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