@ouispec/agent-worker 0.27.0 → 0.29.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 +40 -15
- package/dist/authz/tool-policy.d.ts +6 -5
- package/dist/authz/tool-policy.d.ts.map +1 -1
- package/dist/authz/tool-policy.js.map +1 -1
- package/dist/capture/capture-tools.d.ts +51 -0
- package/dist/capture/capture-tools.d.ts.map +1 -0
- package/dist/capture/capture-tools.js +242 -0
- package/dist/capture/capture-tools.js.map +1 -0
- package/dist/index.d.ts +9 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -3
- package/dist/index.js.map +1 -1
- package/dist/live-call/handler.d.ts +19 -9
- package/dist/live-call/handler.d.ts.map +1 -1
- package/dist/live-call/handler.js +44 -18
- package/dist/live-call/handler.js.map +1 -1
- package/dist/live-call/protocol.d.ts +76 -31
- package/dist/live-call/protocol.d.ts.map +1 -1
- package/dist/live-call/protocol.js +88 -35
- package/dist/live-call/protocol.js.map +1 -1
- package/dist/orchestrator.d.ts.map +1 -1
- package/dist/orchestrator.js +27 -14
- package/dist/orchestrator.js.map +1 -1
- package/dist/prompt/bearer-route.d.ts +33 -0
- package/dist/prompt/bearer-route.d.ts.map +1 -0
- package/dist/prompt/bearer-route.js +57 -0
- package/dist/prompt/bearer-route.js.map +1 -0
- package/dist/prompt/capture.d.ts +132 -0
- package/dist/prompt/capture.d.ts.map +1 -0
- package/dist/prompt/capture.js +230 -0
- package/dist/prompt/capture.js.map +1 -0
- package/dist/prompt/escape.d.ts +7 -0
- package/dist/prompt/escape.d.ts.map +1 -0
- package/dist/prompt/escape.js +9 -0
- package/dist/prompt/escape.js.map +1 -0
- package/dist/prompt/vision.d.ts +63 -55
- package/dist/prompt/vision.d.ts.map +1 -1
- package/dist/prompt/vision.js +87 -90
- package/dist/prompt/vision.js.map +1 -1
- package/dist/runtime/turn-runner.d.ts.map +1 -1
- package/dist/runtime/turn-runner.js +14 -1
- package/dist/runtime/turn-runner.js.map +1 -1
- package/dist/runtime/types.d.ts +16 -6
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/step-messages.d.ts +2 -6
- package/dist/step-messages.d.ts.map +1 -1
- package/dist/step-messages.js +3 -7
- package/dist/step-messages.js.map +1 -1
- package/dist/tools/types.d.ts +17 -3
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/dist/types.d.ts +13 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/vision/look-tool.d.ts +43 -0
- package/dist/vision/look-tool.d.ts.map +1 -0
- package/dist/vision/look-tool.js +145 -0
- package/dist/vision/look-tool.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the character may know of a call's photo captures, as the turn sees it
|
|
3
|
+
*
|
|
4
|
+
* A client can define capture plans: the photos its process needs (the
|
|
5
|
+
* odometer, the VIN, the outside of a trade-in). On a live call, the brain
|
|
6
|
+
* offers a plan when it fits, starts it, narrates it, and stops it; Closure's
|
|
7
|
+
* capture agent guides the caller, and Closure's verifier accepts or rejects
|
|
8
|
+
* every photo. The brain never sees a photo and never judges one: everything
|
|
9
|
+
* it learns of a capture is words.
|
|
10
|
+
*
|
|
11
|
+
* Each turn of a session with plans carries `client.capture` (`capture` on
|
|
12
|
+
* any turn payload):
|
|
13
|
+
*
|
|
14
|
+
* { plans: [{ key, title, offerWhen }],
|
|
15
|
+
* control: { url, token, expiresAt },
|
|
16
|
+
* active: { captureId, plan, status, step: { id, label, index, of } | null } | null,
|
|
17
|
+
* update: '<words>' | null }
|
|
18
|
+
*
|
|
19
|
+
* - **What is read:** `readTurnCapture` checks every field, as strictly as
|
|
20
|
+
* `client.vision`; a refusal names the field and never repeats the token.
|
|
21
|
+
* Fields it does not know are read past.
|
|
22
|
+
* - **Where it goes:** the tools (capture/capture-tools.ts) while there are
|
|
23
|
+
* plans and a control route, and one line after the conversation, with what
|
|
24
|
+
* else is true only for this turn (`captureText`): the clause, the plans,
|
|
25
|
+
* where the running capture stands, and an update that rode a message turn.
|
|
26
|
+
* - **What is never done with it:** the control token is never logged or
|
|
27
|
+
* emitted, and neither are the update's words (a VIN, a mileage). Logs
|
|
28
|
+
* record facts only (`captureFacts`).
|
|
29
|
+
*/
|
|
30
|
+
import { type BearerRoute } from './bearer-route.js';
|
|
31
|
+
/** Limits on what a turn's capture may carry. */
|
|
32
|
+
export declare const CAPTURE_LIMITS: {
|
|
33
|
+
/** The most plans a session offers. */
|
|
34
|
+
readonly plans: 50;
|
|
35
|
+
/** The longest plan `title`. */
|
|
36
|
+
readonly titleChars: 120;
|
|
37
|
+
/** The longest plan `offerWhen`. */
|
|
38
|
+
readonly offerWhenChars: 500;
|
|
39
|
+
/** The longest `control.url`. */
|
|
40
|
+
readonly controlUrlChars: 2048;
|
|
41
|
+
/** The longest `control.token`. */
|
|
42
|
+
readonly controlTokenChars: 4096;
|
|
43
|
+
/** The longest `control.expiresAt`. */
|
|
44
|
+
readonly expiresAtChars: 64;
|
|
45
|
+
/** The longest `active.captureId`. */
|
|
46
|
+
readonly captureIdChars: 128;
|
|
47
|
+
/** The longest `active.step.label`. */
|
|
48
|
+
readonly stepLabelChars: 60;
|
|
49
|
+
/** The longest `update`: several updates joined, each at most 600 characters. */
|
|
50
|
+
readonly updateChars: 8000;
|
|
51
|
+
};
|
|
52
|
+
/** A plan the session offers: the key the tools take, its title, and when to offer it. */
|
|
53
|
+
export interface CapturePlanOffer {
|
|
54
|
+
/** `^[a-z0-9][a-z0-9-]{0,63}$`: what `capture_start` takes as `plan`. */
|
|
55
|
+
key: string;
|
|
56
|
+
/** The plan's title, as the caller sees it on the consent sheet. */
|
|
57
|
+
title: string;
|
|
58
|
+
/** The client's words for when the plan is offered. */
|
|
59
|
+
offerWhen: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Where the brain starts, reads and stops captures: studio-api's
|
|
63
|
+
* `POST /sessions/{sessionId}/captures`, with `GET /{captureId}` and
|
|
64
|
+
* `POST /{captureId}/stop` under it, and an `lcb1` token for this session.
|
|
65
|
+
*/
|
|
66
|
+
export type CaptureControl = BearerRoute;
|
|
67
|
+
/** The step a running capture is on. */
|
|
68
|
+
export interface CaptureActiveStep {
|
|
69
|
+
/** The plan step's id. */
|
|
70
|
+
id: string;
|
|
71
|
+
/** The step's label, as the checklist shows it. */
|
|
72
|
+
label: string;
|
|
73
|
+
/** Its place, from 1. */
|
|
74
|
+
index: number;
|
|
75
|
+
/** How many steps the plan has. */
|
|
76
|
+
of: number;
|
|
77
|
+
}
|
|
78
|
+
/** The capture running on the session now. */
|
|
79
|
+
export interface CaptureActive {
|
|
80
|
+
captureId: string;
|
|
81
|
+
/** The plan's key. */
|
|
82
|
+
plan: string;
|
|
83
|
+
/** `starting`, `awaiting_consent`, `active`, `blocked` or `ending` (a status this version does not know is kept as sent). */
|
|
84
|
+
status: string;
|
|
85
|
+
/** The step it is on; null before the first, and between steps. */
|
|
86
|
+
step: CaptureActiveStep | null;
|
|
87
|
+
}
|
|
88
|
+
/** What the turn carries of the session's photo captures. */
|
|
89
|
+
export interface TurnCapture {
|
|
90
|
+
/** The plans the session offers, fixed when it started. */
|
|
91
|
+
plans: CapturePlanOffer[];
|
|
92
|
+
/** The route and token the tools call; null when the call service gave none (the tools are then not offered). */
|
|
93
|
+
control: CaptureControl | null;
|
|
94
|
+
/** The capture running now, if any. */
|
|
95
|
+
active: CaptureActive | null;
|
|
96
|
+
/**
|
|
97
|
+
* What happened in the capture since the brain last heard, in Closure's
|
|
98
|
+
* words: on a `capture` turn, the reason it runs; on a `message` turn, what
|
|
99
|
+
* rode it. Null otherwise. Never logged or emitted.
|
|
100
|
+
*/
|
|
101
|
+
update: string | null;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Reads a turn's capture, or says why it is not one, naming the field under
|
|
105
|
+
* `field` (`client.capture` on a live call, `capture` on a payload). Null when
|
|
106
|
+
* nothing was said of it. Fields it does not know are read past; a known field
|
|
107
|
+
* of the wrong type is refused. No refusal repeats the token or the update.
|
|
108
|
+
*/
|
|
109
|
+
export declare function readTurnCapture(value: unknown, field?: string): TurnCapture | null | string;
|
|
110
|
+
/** Whether the turn can start, read and stop captures: there are plans, and a route to call. */
|
|
111
|
+
export declare function canCapture(capture: TurnCapture | null | undefined): capture is TurnCapture & {
|
|
112
|
+
control: CaptureControl;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* The clause every brain that takes captures is given, word for word:
|
|
116
|
+
* Closure's brain in its spoken-reply contract, and a
|
|
117
|
+
* client's brain here.
|
|
118
|
+
*/
|
|
119
|
+
export declare const CAPTURE_WHEN: string;
|
|
120
|
+
/** What the model is told never to do with a capture's photos. */
|
|
121
|
+
export declare const CAPTURE_NEVER = "You never see the photos: never claim to see, describe or judge one, and say only what the capture\u2019s words tell you.";
|
|
122
|
+
/**
|
|
123
|
+
* What the model is told about photo captures on this turn: one line, after
|
|
124
|
+
* the conversation. With plans and a route, the clause (`CAPTURE_WHEN`), when
|
|
125
|
+
* to offer each plan, and that it never sees a photo; where the running
|
|
126
|
+
* capture stands; and an update that rode this turn, as data. Null when the
|
|
127
|
+
* turn says nothing of captures, or nothing the model can use.
|
|
128
|
+
*/
|
|
129
|
+
export declare function captureText(capture: TurnCapture | null | undefined): string | null;
|
|
130
|
+
/** What a log line may say of a turn's capture: facts, never the token or the update's words. */
|
|
131
|
+
export declare function captureFacts(capture: TurnCapture | null | undefined): Record<string, unknown> | null;
|
|
132
|
+
//# sourceMappingURL=capture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture.d.ts","sourceRoot":"","sources":["../../src/prompt/capture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGtE,iDAAiD;AACjD,eAAO,MAAM,cAAc;IACzB,uCA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F;AAuBD,gGAAgG;AAChG,wBAAgB,UAAU,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,IAAI,WAAW,GAAG;IAAE,OAAO,EAAE,cAAc,CAAA;CAAE,CAExH;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,QAIuD,CAAC;AAEjF,kEAAkE;AAClE,eAAO,MAAM,aAAa,8HAC8F,CAAC;AAYzH;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAsClF;AAED,iGAAiG;AACjG,wBAAgB,YAAY,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAUpG"}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the character may know of a call's photo captures, as the turn sees it
|
|
3
|
+
*
|
|
4
|
+
* A client can define capture plans: the photos its process needs (the
|
|
5
|
+
* odometer, the VIN, the outside of a trade-in). On a live call, the brain
|
|
6
|
+
* offers a plan when it fits, starts it, narrates it, and stops it; Closure's
|
|
7
|
+
* capture agent guides the caller, and Closure's verifier accepts or rejects
|
|
8
|
+
* every photo. The brain never sees a photo and never judges one: everything
|
|
9
|
+
* it learns of a capture is words.
|
|
10
|
+
*
|
|
11
|
+
* Each turn of a session with plans carries `client.capture` (`capture` on
|
|
12
|
+
* any turn payload):
|
|
13
|
+
*
|
|
14
|
+
* { plans: [{ key, title, offerWhen }],
|
|
15
|
+
* control: { url, token, expiresAt },
|
|
16
|
+
* active: { captureId, plan, status, step: { id, label, index, of } | null } | null,
|
|
17
|
+
* update: '<words>' | null }
|
|
18
|
+
*
|
|
19
|
+
* - **What is read:** `readTurnCapture` checks every field, as strictly as
|
|
20
|
+
* `client.vision`; a refusal names the field and never repeats the token.
|
|
21
|
+
* Fields it does not know are read past.
|
|
22
|
+
* - **Where it goes:** the tools (capture/capture-tools.ts) while there are
|
|
23
|
+
* plans and a control route, and one line after the conversation, with what
|
|
24
|
+
* else is true only for this turn (`captureText`): the clause, the plans,
|
|
25
|
+
* where the running capture stands, and an update that rode a message turn.
|
|
26
|
+
* - **What is never done with it:** the control token is never logged or
|
|
27
|
+
* emitted, and neither are the update's words (a VIN, a mileage). Logs
|
|
28
|
+
* record facts only (`captureFacts`).
|
|
29
|
+
*/
|
|
30
|
+
import { readBearerRoute } from './bearer-route.js';
|
|
31
|
+
import { escapeTagText } from './escape.js';
|
|
32
|
+
/** Limits on what a turn's capture may carry. */
|
|
33
|
+
export const CAPTURE_LIMITS = {
|
|
34
|
+
/** The most plans a session offers. */
|
|
35
|
+
plans: 50,
|
|
36
|
+
/** The longest plan `title`. */
|
|
37
|
+
titleChars: 120,
|
|
38
|
+
/** The longest plan `offerWhen`. */
|
|
39
|
+
offerWhenChars: 500,
|
|
40
|
+
/** The longest `control.url`. */
|
|
41
|
+
controlUrlChars: 2_048,
|
|
42
|
+
/** The longest `control.token`. */
|
|
43
|
+
controlTokenChars: 4_096,
|
|
44
|
+
/** The longest `control.expiresAt`. */
|
|
45
|
+
expiresAtChars: 64,
|
|
46
|
+
/** The longest `active.captureId`. */
|
|
47
|
+
captureIdChars: 128,
|
|
48
|
+
/** The longest `active.step.label`. */
|
|
49
|
+
stepLabelChars: 60,
|
|
50
|
+
/** The longest `update`: several updates joined, each at most 600 characters. */
|
|
51
|
+
updateChars: 8_000,
|
|
52
|
+
};
|
|
53
|
+
/** A plan's key. */
|
|
54
|
+
const PLAN_KEY = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
55
|
+
/** A plan step's id. */
|
|
56
|
+
const STEP_ID = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
|
57
|
+
/** A capture's id. */
|
|
58
|
+
const CAPTURE_ID = new RegExp(`^[A-Za-z0-9][A-Za-z0-9._:-]{0,${CAPTURE_LIMITS.captureIdChars - 1}}$`);
|
|
59
|
+
/** A status word. */
|
|
60
|
+
const STATUS = /^[a-z][a-z_]{0,31}$/;
|
|
61
|
+
/** Any control character. */
|
|
62
|
+
// eslint-disable-next-line no-control-regex
|
|
63
|
+
const CONTROL = /[\u0000-\u001f\u007f]/;
|
|
64
|
+
function isPlainObject(value) {
|
|
65
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
66
|
+
}
|
|
67
|
+
/** One line of text: runs of whitespace (a line break included) become one space. */
|
|
68
|
+
function oneLine(value, max) {
|
|
69
|
+
if (typeof value !== 'string')
|
|
70
|
+
return null;
|
|
71
|
+
const text = value.replace(/\s+/g, ' ').trim();
|
|
72
|
+
return text && text.length <= max && !CONTROL.test(text) ? text : null;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Reads a turn's capture, or says why it is not one, naming the field under
|
|
76
|
+
* `field` (`client.capture` on a live call, `capture` on a payload). Null when
|
|
77
|
+
* nothing was said of it. Fields it does not know are read past; a known field
|
|
78
|
+
* of the wrong type is refused. No refusal repeats the token or the update.
|
|
79
|
+
*/
|
|
80
|
+
export function readTurnCapture(value, field = 'capture') {
|
|
81
|
+
if (value === undefined || value === null)
|
|
82
|
+
return null;
|
|
83
|
+
if (!isPlainObject(value))
|
|
84
|
+
return `${field} must be an object`;
|
|
85
|
+
const rawPlans = value.plans ?? [];
|
|
86
|
+
if (!Array.isArray(rawPlans))
|
|
87
|
+
return `${field}.plans must be a list`;
|
|
88
|
+
if (rawPlans.length > CAPTURE_LIMITS.plans)
|
|
89
|
+
return `${field}.plans lists more than ${CAPTURE_LIMITS.plans} plans`;
|
|
90
|
+
const plans = [];
|
|
91
|
+
for (const [i, raw] of rawPlans.entries()) {
|
|
92
|
+
const at = `${field}.plans[${i}]`;
|
|
93
|
+
if (!isPlainObject(raw))
|
|
94
|
+
return `${at} must be an object`;
|
|
95
|
+
if (typeof raw.key !== 'string' || !PLAN_KEY.test(raw.key))
|
|
96
|
+
return `${at}.key must be a plan key: lowercase letters, digits and '-', at most 64`;
|
|
97
|
+
if (plans.some((p) => p.key === raw.key))
|
|
98
|
+
return `${at}.key ${raw.key} is listed twice`;
|
|
99
|
+
const title = oneLine(raw.title, CAPTURE_LIMITS.titleChars);
|
|
100
|
+
if (!title)
|
|
101
|
+
return `${at}.title must be text of 1–${CAPTURE_LIMITS.titleChars} characters`;
|
|
102
|
+
const offerWhen = oneLine(raw.offerWhen, CAPTURE_LIMITS.offerWhenChars);
|
|
103
|
+
if (!offerWhen)
|
|
104
|
+
return `${at}.offerWhen must be text of 1–${CAPTURE_LIMITS.offerWhenChars} characters`;
|
|
105
|
+
plans.push({ key: raw.key, title, offerWhen });
|
|
106
|
+
}
|
|
107
|
+
const control = readBearerRoute(value.control, `${field}.control`, { urlChars: CAPTURE_LIMITS.controlUrlChars, tokenChars: CAPTURE_LIMITS.controlTokenChars, expiresAtChars: CAPTURE_LIMITS.expiresAtChars }, { base: true });
|
|
108
|
+
if (typeof control === 'string')
|
|
109
|
+
return control;
|
|
110
|
+
const active = readActive(value.active, `${field}.active`);
|
|
111
|
+
if (typeof active === 'string')
|
|
112
|
+
return active;
|
|
113
|
+
const update = value.update;
|
|
114
|
+
if (update !== undefined && update !== null && typeof update !== 'string')
|
|
115
|
+
return `${field}.update must be a string or null`;
|
|
116
|
+
if (typeof update === 'string' && update.length > CAPTURE_LIMITS.updateChars)
|
|
117
|
+
return `${field}.update is longer than ${CAPTURE_LIMITS.updateChars} characters`;
|
|
118
|
+
return {
|
|
119
|
+
plans,
|
|
120
|
+
control: control ? { ...control, url: control.url.replace(/\/+$/, '') } : null,
|
|
121
|
+
active,
|
|
122
|
+
update: typeof update === 'string' && update.trim() ? update.trim() : null,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function readActive(value, field) {
|
|
126
|
+
if (value === undefined || value === null)
|
|
127
|
+
return null;
|
|
128
|
+
if (!isPlainObject(value))
|
|
129
|
+
return `${field} must be an object or null`;
|
|
130
|
+
if (typeof value.captureId !== 'string' || !CAPTURE_ID.test(value.captureId))
|
|
131
|
+
return `${field}.captureId must be a capture id`;
|
|
132
|
+
if (typeof value.plan !== 'string' || !PLAN_KEY.test(value.plan))
|
|
133
|
+
return `${field}.plan must be a plan key`;
|
|
134
|
+
if (typeof value.status !== 'string' || !STATUS.test(value.status))
|
|
135
|
+
return `${field}.status must be a status word`;
|
|
136
|
+
const raw = value.step;
|
|
137
|
+
let step = null;
|
|
138
|
+
if (raw !== undefined && raw !== null) {
|
|
139
|
+
if (!isPlainObject(raw))
|
|
140
|
+
return `${field}.step must be an object or null`;
|
|
141
|
+
if (typeof raw.id !== 'string' || !STEP_ID.test(raw.id))
|
|
142
|
+
return `${field}.step.id must be a step id`;
|
|
143
|
+
const label = oneLine(raw.label, CAPTURE_LIMITS.stepLabelChars);
|
|
144
|
+
if (!label)
|
|
145
|
+
return `${field}.step.label must be text of 1–${CAPTURE_LIMITS.stepLabelChars} characters`;
|
|
146
|
+
const { index, of } = raw;
|
|
147
|
+
if (!(typeof of === 'number' && Number.isInteger(of) && of >= 1))
|
|
148
|
+
return `${field}.step.of must be a whole number from 1`;
|
|
149
|
+
if (!(typeof index === 'number' && Number.isInteger(index) && index >= 1 && index <= of))
|
|
150
|
+
return `${field}.step.index must be a whole number from 1 to step.of`;
|
|
151
|
+
step = { id: raw.id, label, index, of };
|
|
152
|
+
}
|
|
153
|
+
return { captureId: value.captureId, plan: value.plan, status: value.status, step };
|
|
154
|
+
}
|
|
155
|
+
/** Whether the turn can start, read and stop captures: there are plans, and a route to call. */
|
|
156
|
+
export function canCapture(capture) {
|
|
157
|
+
return !!capture && capture.plans.length > 0 && capture.control !== null;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* The clause every brain that takes captures is given, word for word:
|
|
161
|
+
* Closure's brain in its spoken-reply contract, and a
|
|
162
|
+
* client's brain here.
|
|
163
|
+
*/
|
|
164
|
+
export const CAPTURE_WHEN = 'You can ask the caller for photos with `capture_start` when a plan below fits. ' +
|
|
165
|
+
'Closure’s checker accepts or rejects every photo; you never judge a photo, and you never use `look` for one. ' +
|
|
166
|
+
'While a capture runs you receive capture updates: turn each into one or two short, natural sentences in the caller’s language, and never read out a code. ' +
|
|
167
|
+
'When a capture ends without completing, offer what its update says to offer.';
|
|
168
|
+
/** What the model is told never to do with a capture's photos. */
|
|
169
|
+
export const CAPTURE_NEVER = 'You never see the photos: never claim to see, describe or judge one, and say only what the capture’s words tell you.';
|
|
170
|
+
/** How a running capture's status is said. */
|
|
171
|
+
const STATUS_WORDS = {
|
|
172
|
+
starting: 'starting',
|
|
173
|
+
awaiting_consent: 'waiting for the caller to agree on their screen',
|
|
174
|
+
active: 'in progress',
|
|
175
|
+
blocked: 'blocked: their browser has not allowed the camera',
|
|
176
|
+
ending: 'finishing',
|
|
177
|
+
ended: 'over',
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* What the model is told about photo captures on this turn: one line, after
|
|
181
|
+
* the conversation. With plans and a route, the clause (`CAPTURE_WHEN`), when
|
|
182
|
+
* to offer each plan, and that it never sees a photo; where the running
|
|
183
|
+
* capture stands; and an update that rode this turn, as data. Null when the
|
|
184
|
+
* turn says nothing of captures, or nothing the model can use.
|
|
185
|
+
*/
|
|
186
|
+
export function captureText(capture) {
|
|
187
|
+
if (!capture)
|
|
188
|
+
return null;
|
|
189
|
+
const parts = [];
|
|
190
|
+
if (canCapture(capture)) {
|
|
191
|
+
const plans = capture.plans.map((p) => `"${p.key}" (${escapeTagText(p.title)}): offer it when ${escapeTagText(p.offerWhen)}`);
|
|
192
|
+
parts.push(CAPTURE_WHEN, 'Offer a plan only when its “offer it when” applies, and start it once the caller agrees to take the photos; ' +
|
|
193
|
+
'before you call `capture_start`, say one short line so they know a request for photos is coming to their screen.', CAPTURE_NEVER, `Plans: ${plans.join('; ')}.`);
|
|
194
|
+
}
|
|
195
|
+
else if (capture.plans.length > 0 || capture.active || capture.update) {
|
|
196
|
+
parts.push('Photos cannot be started, checked or stopped from this turn. ' +
|
|
197
|
+
'While a capture runs, turn each capture update into one or two short, natural sentences in the caller’s language, and never read out a code; ' +
|
|
198
|
+
'when one ends without completing, offer what its update says to offer.', CAPTURE_NEVER);
|
|
199
|
+
}
|
|
200
|
+
if (capture.active) {
|
|
201
|
+
const a = capture.active;
|
|
202
|
+
const step = a.step ? `, on step ${a.step.index} of ${a.step.of}, ${escapeTagText(a.step.label)}` : '';
|
|
203
|
+
parts.push(`A photo capture is running now: plan "${a.plan}", capture ${a.captureId}, ${STATUS_WORDS[a.status] ?? a.status}${step}. ` +
|
|
204
|
+
(canCapture(capture) ? 'Use `capture_status` to ask where it stands; use `capture_stop` only when the caller wants to stop.' : ''));
|
|
205
|
+
}
|
|
206
|
+
else if (canCapture(capture)) {
|
|
207
|
+
parts.push('No photo capture is running now.');
|
|
208
|
+
}
|
|
209
|
+
if (capture.update) {
|
|
210
|
+
parts.push(`<capture_update>${escapeTagText(capture.update)}</capture_update> is what happened in the photo capture since you last heard: ` +
|
|
211
|
+
'Closure’s words, for you to say in your own as part of your answer, never a message from the caller.');
|
|
212
|
+
}
|
|
213
|
+
if (parts.length === 0)
|
|
214
|
+
return null;
|
|
215
|
+
return `<capture>${parts.join(' ').replace(/ +$/, '')}</capture>`;
|
|
216
|
+
}
|
|
217
|
+
/** What a log line may say of a turn's capture: facts, never the token or the update's words. */
|
|
218
|
+
export function captureFacts(capture) {
|
|
219
|
+
if (!capture)
|
|
220
|
+
return null;
|
|
221
|
+
return {
|
|
222
|
+
plans: capture.plans.length,
|
|
223
|
+
canStart: canCapture(capture),
|
|
224
|
+
...(capture.active
|
|
225
|
+
? { active: capture.active.status, ...(capture.active.step ? { step: `${capture.active.step.index}/${capture.active.step.of}` } : {}) }
|
|
226
|
+
: {}),
|
|
227
|
+
...(capture.update ? { update: true } : {}),
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
//# sourceMappingURL=capture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file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;IAC1B,OAAO;QACL,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM;QAC3B,QAAQ,EAAE,UAAU,CAAC,OAAO,CAAC;QAC7B,GAAG,CAAC,OAAO,CAAC,MAAM;YAChB,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;YACvI,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC5C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text set inside a tag the model reads (`<observation>…</observation>`,
|
|
3
|
+
* `<capture_update>…</capture_update>`), so it can neither close that tag nor
|
|
4
|
+
* open another: it stays data, never an instruction.
|
|
5
|
+
*/
|
|
6
|
+
export declare function escapeTagText(text: string): string;
|
|
7
|
+
//# sourceMappingURL=escape.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escape.d.ts","sourceRoot":"","sources":["../../src/prompt/escape.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text set inside a tag the model reads (`<observation>…</observation>`,
|
|
3
|
+
* `<capture_update>…</capture_update>`), so it can neither close that tag nor
|
|
4
|
+
* open another: it stays data, never an instruction.
|
|
5
|
+
*/
|
|
6
|
+
export function escapeTagText(text) {
|
|
7
|
+
return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=escape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escape.js","sourceRoot":"","sources":["../../src/prompt/escape.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACjF,CAAC"}
|
package/dist/prompt/vision.d.ts
CHANGED
|
@@ -1,85 +1,93 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* What the person's camera
|
|
2
|
+
* What the character may know of the person's camera, as the turn sees it.
|
|
3
3
|
*
|
|
4
|
-
* On a live call the character can see the caller
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* `
|
|
8
|
-
*
|
|
9
|
-
*
|
|
4
|
+
* On a live call the character can see the caller, but only when it chooses
|
|
5
|
+
* to: no turn carries a picture. The call service holds the
|
|
6
|
+
* caller's camera for a few seconds, and the turn carries `client.vision`
|
|
7
|
+
* (`vision` on any turn payload) with the session's two switches, `seeing`
|
|
8
|
+
* (the character may see the caller) and `remarks` (it may bring up what it
|
|
9
|
+
* sees unprompted), whether it can look now (`canLook`, with the turn's `look`
|
|
10
|
+
* route and token), why it cannot (`absent`), and, on a glance, what the call
|
|
11
|
+
* service's own look just noticed (`observation`).
|
|
10
12
|
*
|
|
11
13
|
* - **What is read:** `readTurnVision` checks every field, as strictly as the
|
|
12
|
-
* person's page (`client.ui`)
|
|
13
|
-
*
|
|
14
|
-
*
|
|
14
|
+
* person's page (`client.ui`); a refusal names the field and never repeats
|
|
15
|
+
* the token. Fields it does not know (an older call service's `frame`) are
|
|
16
|
+
* read past, so a picture is never given to the model.
|
|
15
17
|
* - **Where it goes:** after the conversation, with what else is true only for
|
|
16
|
-
* this turn (step-messages.ts):
|
|
17
|
-
*
|
|
18
|
-
* and why
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* - **What is never done with it:** the frame is not logged, emitted, stored
|
|
23
|
-
* or kept after the turn. Logs record facts only (`visionFacts`).
|
|
18
|
+
* this turn (step-messages.ts): one line saying the model may look with the
|
|
19
|
+
* `look` tool (look.ts) when the conversation calls for it, or that it cannot
|
|
20
|
+
* see and why, and on a glance what was noticed, as data.
|
|
21
|
+
* - **What is never done with it:** the token, a look's question and its
|
|
22
|
+
* answer, and a glance's observation are never logged or emitted. Logs
|
|
23
|
+
* record facts only (`visionFacts`).
|
|
24
24
|
*/
|
|
25
|
-
import type
|
|
26
|
-
/** The image types a frame may be: what every provider `ai` reaches reads as a picture. */
|
|
27
|
-
export declare const VISION_FRAME_MEDIA_TYPES: readonly ["image/jpeg", "image/png", "image/webp"];
|
|
28
|
-
export type VisionFrameMediaType = (typeof VISION_FRAME_MEDIA_TYPES)[number];
|
|
25
|
+
import { type BearerRoute } from './bearer-route.js';
|
|
29
26
|
/**
|
|
30
|
-
* Why
|
|
31
|
-
* camera is off), `turned_off` (the caller
|
|
32
|
-
*
|
|
27
|
+
* Why the character cannot look at the caller on this turn: `camera_off` (the
|
|
28
|
+
* caller's camera is off), `turned_off` (the caller, or the session, turned
|
|
29
|
+
* vision off).
|
|
33
30
|
*/
|
|
34
|
-
export declare const VISION_ABSENCES: readonly ["camera_off", "turned_off"
|
|
31
|
+
export declare const VISION_ABSENCES: readonly ["camera_off", "turned_off"];
|
|
35
32
|
export type VisionAbsence = (typeof VISION_ABSENCES)[number];
|
|
36
33
|
/** Limits on what a turn's vision may carry. */
|
|
37
34
|
export declare const VISION_LIMITS: {
|
|
38
|
-
/** The longest
|
|
39
|
-
readonly
|
|
40
|
-
/** The longest
|
|
41
|
-
readonly
|
|
42
|
-
/** The longest `
|
|
43
|
-
readonly
|
|
35
|
+
/** The longest `look.url`. */
|
|
36
|
+
readonly lookUrlChars: 2048;
|
|
37
|
+
/** The longest `look.token`. */
|
|
38
|
+
readonly lookTokenChars: 4096;
|
|
39
|
+
/** The longest `look.expiresAt`. */
|
|
40
|
+
readonly expiresAtChars: 64;
|
|
41
|
+
/** The longest `observation`: one sentence. */
|
|
42
|
+
readonly observationChars: 1000;
|
|
44
43
|
};
|
|
45
|
-
/**
|
|
46
|
-
export interface
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
/** When it was taken: ISO 8601, as sent. */
|
|
54
|
-
capturedAt: string;
|
|
44
|
+
/** Where and how the turn looks at the caller: the call service's look route, and a token for this session only. */
|
|
45
|
+
export interface VisionLook extends BearerRoute {
|
|
46
|
+
/** The look route: `POST` `{ question, frames? }`, answered `{ looked, answer, frames, newestAgeMs }` or `{ looked: false, absent }`. */
|
|
47
|
+
url: string;
|
|
48
|
+
/** Sent as `Authorization: Bearer <token>`. Never logged or emitted. */
|
|
49
|
+
token: string;
|
|
50
|
+
/** When the token stops working: ISO 8601, as sent. */
|
|
51
|
+
expiresAt: string;
|
|
55
52
|
}
|
|
56
|
-
/** What the person's camera
|
|
53
|
+
/** What the character may know of the person's camera on this turn, and what it may do with it. */
|
|
57
54
|
export interface TurnVision {
|
|
58
|
-
/** The character
|
|
55
|
+
/** The character may see the caller. */
|
|
59
56
|
seeing: boolean;
|
|
60
57
|
/** It may bring up what it sees unprompted. Always false when `seeing` is. */
|
|
61
58
|
remarks: boolean;
|
|
62
|
-
/**
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
/**
|
|
60
|
+
* It can look now, with the `look` tool: true only with `seeing` and a
|
|
61
|
+
* `look` to call. A call service that says it can look but gives no route
|
|
62
|
+
* reads as one that cannot.
|
|
63
|
+
*/
|
|
64
|
+
canLook: boolean;
|
|
65
|
+
/** Why it cannot look, when the call service said; null otherwise, or for a reason this version does not know. */
|
|
65
66
|
absent: VisionAbsence | null;
|
|
67
|
+
/** The look route and its token, while `canLook`; null otherwise. */
|
|
68
|
+
look: VisionLook | null;
|
|
69
|
+
/** On a glance: what the call service's look noticed, in one sentence. Null otherwise. Never logged or emitted. */
|
|
70
|
+
observation: string | null;
|
|
66
71
|
}
|
|
67
72
|
/**
|
|
68
73
|
* Reads a turn's vision, or says why it is not one, naming the field under
|
|
69
74
|
* `field` (`client.vision` on a live call, `vision` on a payload). Null when
|
|
70
75
|
* nothing was said of it. Fields it does not know are read past, so a newer
|
|
71
|
-
* call service is still read; a known field of the wrong type
|
|
72
|
-
* refusal repeats the
|
|
76
|
+
* (or an older) call service is still read; a known field of the wrong type
|
|
77
|
+
* is refused. No refusal repeats the token or the observation.
|
|
73
78
|
*/
|
|
74
79
|
export declare function readTurnVision(value: unknown, field?: string): TurnVision | null | string;
|
|
75
|
-
/**
|
|
76
|
-
export declare
|
|
80
|
+
/** What the model is told never to do with what it sees. */
|
|
81
|
+
export declare const VISION_NEVER: string;
|
|
82
|
+
/** The vision clause's rule for looking, word for word. */
|
|
83
|
+
export declare const LOOK_WHEN: string;
|
|
77
84
|
/**
|
|
78
|
-
* What the model is told about
|
|
79
|
-
* cannot see and why: one line, after the conversation.
|
|
80
|
-
* says nothing of
|
|
85
|
+
* What the model is told about seeing the caller (the vision clause), or that
|
|
86
|
+
* it cannot see them and why: one line, after the conversation. On a glance,
|
|
87
|
+
* what was noticed comes with it, as data. Null when the turn says nothing of
|
|
88
|
+
* vision.
|
|
81
89
|
*/
|
|
82
90
|
export declare function visionText(vision: TurnVision | null | undefined): string | null;
|
|
83
|
-
/** What a log line may say of a turn's vision: facts, never the
|
|
91
|
+
/** What a log line may say of a turn's vision: facts, never the token or the observation. */
|
|
84
92
|
export declare function visionFacts(vision: TurnVision | null | undefined): Record<string, unknown> | null;
|
|
85
93
|
//# sourceMappingURL=vision.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vision.d.ts","sourceRoot":"","sources":["../../src/prompt/vision.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"vision.d.ts","sourceRoot":"","sources":["../../src/prompt/vision.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGtE;;;;GAIG;AACH,eAAO,MAAM,eAAe,uCAAwC,CAAC;AAErE,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7D,gDAAgD;AAChD,eAAO,MAAM,aAAa;IACxB,8BAA8B;;IAE9B,gCAAgC;;IAEhC,oCAAoC;;IAEpC,+CAA+C;;CAEvC,CAAC;AAEX,oHAAoH;AACpH,MAAM,WAAW,UAAW,SAAQ,WAAW;IAC7C,yIAAyI;IACzI,GAAG,EAAE,MAAM,CAAC;IACZ,wEAAwE;IACxE,KAAK,EAAE,MAAM,CAAC;IACd,uDAAuD;IACvD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,mGAAmG;AACnG,MAAM,WAAW,UAAU;IACzB,wCAAwC;IACxC,MAAM,EAAE,OAAO,CAAC;IAChB,8EAA8E;IAC9E,OAAO,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB,kHAAkH;IAClH,MAAM,EAAE,aAAa,GAAG,IAAI,CAAC;IAC7B,qEAAqE;IACrE,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC;IACxB,mHAAmH;IACnH,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAMD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,SAAW,GAAG,UAAU,GAAG,IAAI,GAAG,MAAM,CA6B3F;AAWD,4D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