@escapeaihq/client-core 0.8.0 → 0.12.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 +22 -3
- package/dist/api.d.ts +114 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +62 -47
- package/dist/api.js.map +1 -1
- package/dist/graphSchema.d.ts +72 -0
- package/dist/graphSchema.d.ts.map +1 -0
- package/dist/graphSchema.js +105 -0
- package/dist/graphSchema.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/reactor/abortUtils.d.ts +16 -0
- package/dist/reactor/abortUtils.d.ts.map +1 -0
- package/dist/reactor/abortUtils.js +26 -0
- package/dist/reactor/abortUtils.js.map +1 -0
- package/dist/reactor/applyScenePrompt.d.ts +75 -0
- package/dist/reactor/applyScenePrompt.d.ts.map +1 -0
- package/dist/reactor/applyScenePrompt.js +60 -0
- package/dist/reactor/applyScenePrompt.js.map +1 -0
- package/dist/reactor/heliosCommandDispatcher.d.ts.map +1 -1
- package/dist/reactor/heliosCommandDispatcher.js +10 -15
- package/dist/reactor/heliosCommandDispatcher.js.map +1 -1
- package/dist/reactor/index.d.ts +2 -0
- package/dist/reactor/index.d.ts.map +1 -1
- package/dist/reactor/index.js +2 -0
- package/dist/reactor/index.js.map +1 -1
- package/dist/reactor/sceneEntry.d.ts +40 -6
- package/dist/reactor/sceneEntry.d.ts.map +1 -1
- package/dist/reactor/sceneEntry.js +63 -24
- package/dist/reactor/sceneEntry.js.map +1 -1
- package/dist/reactor/seedImageOrchestrator.d.ts +45 -2
- package/dist/reactor/seedImageOrchestrator.d.ts.map +1 -1
- package/dist/reactor/seedImageOrchestrator.js +174 -4
- package/dist/reactor/seedImageOrchestrator.js.map +1 -1
- package/dist/timeFormat.d.ts +10 -0
- package/dist/timeFormat.d.ts.map +1 -1
- package/dist/timeFormat.js +12 -0
- package/dist/timeFormat.js.map +1 -1
- package/dist/toolSchemas.d.ts +370 -0
- package/dist/toolSchemas.d.ts.map +1 -0
- package/dist/toolSchemas.js +182 -0
- package/dist/toolSchemas.js.map +1 -0
- package/dist/vision/VisionPublisher.d.ts +115 -0
- package/dist/vision/VisionPublisher.d.ts.map +1 -0
- package/dist/vision/VisionPublisher.js +475 -0
- package/dist/vision/VisionPublisher.js.map +1 -0
- package/dist/vision/credentials.d.ts +22 -0
- package/dist/vision/credentials.d.ts.map +1 -0
- package/dist/vision/credentials.js +34 -0
- package/dist/vision/credentials.js.map +1 -0
- package/dist/vision/index.d.ts +14 -0
- package/dist/vision/index.d.ts.map +1 -0
- package/dist/vision/index.js +11 -0
- package/dist/vision/index.js.map +1 -0
- package/dist/vision/startVisionPublisher.d.ts +38 -0
- package/dist/vision/startVisionPublisher.d.ts.map +1 -0
- package/dist/vision/startVisionPublisher.js +44 -0
- package/dist/vision/startVisionPublisher.js.map +1 -0
- package/dist/vision/types.d.ts +95 -0
- package/dist/vision/types.d.ts.map +1 -0
- package/dist/vision/types.js +12 -0
- package/dist/vision/types.js.map +1 -0
- package/dist/vision/visionScheduler.d.ts +63 -0
- package/dist/vision/visionScheduler.d.ts.map +1 -0
- package/dist/vision/visionScheduler.js +67 -0
- package/dist/vision/visionScheduler.js.map +1 -0
- package/dist/websocket.d.ts +122 -0
- package/dist/websocket.d.ts.map +1 -1
- package/dist/websocket.js +179 -1
- package/dist/websocket.js.map +1 -1
- package/package.json +11 -1
- package/src/__tests__/api-pollers.test.ts +100 -0
- package/src/__tests__/chat-auth.test.ts +91 -0
- package/src/__tests__/graphSchema.test.ts +117 -0
- package/src/__tests__/reactor/applyScenePrompt.test.ts +192 -0
- package/src/__tests__/reactor/heliosCommandDispatcher.test.ts +4 -3
- package/src/__tests__/reactor/sceneEntry.test.ts +134 -10
- package/src/__tests__/reactor/seedImageOrchestrator.test.ts +51 -16
- package/src/__tests__/timeFormat.test.ts +22 -1
- package/src/__tests__/toolSchemas.test.ts +57 -0
- package/src/__tests__/websocket-vision.test.ts +265 -0
- package/src/api.ts +160 -47
- package/src/graphSchema.ts +149 -0
- package/src/index.ts +3 -0
- package/src/reactor/abortUtils.ts +22 -0
- package/src/reactor/applyScenePrompt.ts +136 -0
- package/src/reactor/heliosCommandDispatcher.ts +10 -18
- package/src/reactor/index.ts +2 -0
- package/src/reactor/sceneEntry.ts +104 -33
- package/src/reactor/seedImageOrchestrator.ts +201 -4
- package/src/timeFormat.ts +13 -0
- package/src/toolSchemas.ts +225 -0
- package/src/vision/VisionPublisher.ts +553 -0
- package/src/vision/__tests__/VisionPublisher.kvs.test.ts +244 -0
- package/src/vision/__tests__/VisionPublisher.test.ts +301 -0
- package/src/vision/__tests__/startVisionPublisher.test.ts +251 -0
- package/src/vision/__tests__/toVisionRtcCredentials.test.ts +113 -0
- package/src/vision/__tests__/visionScheduler.test.ts +149 -0
- package/src/vision/credentials.ts +39 -0
- package/src/vision/index.ts +31 -0
- package/src/vision/startVisionPublisher.ts +64 -0
- package/src/vision/types.ts +101 -0
- package/src/vision/visionScheduler.ts +102 -0
- package/src/websocket.ts +259 -1
|
@@ -1,17 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Pure async orchestration of the "selected image → Reactor seed" flow.
|
|
3
3
|
*
|
|
4
|
+
* Wire shape: Helios's `set_image` command expects `{ image: <FileRef>,
|
|
5
|
+
* transition? }`. The FileRef comes from `reactor.uploadFile()`, which
|
|
6
|
+
* uploads the bytes via HTTP to Reactor's object store and returns a
|
|
7
|
+
* cheap reference. The command channel only carries the reference, so
|
|
8
|
+
* image size is decoupled from the 64KB-per-message data channel cap.
|
|
9
|
+
*
|
|
10
|
+
* Authoritative docs:
|
|
11
|
+
* - `ai_docs/reference/reactor/helios-overview.md:217` — set_image
|
|
12
|
+
* parameter table
|
|
13
|
+
* - `ai_docs/reference/reactor/file-uploads.md:33-54` — canonical
|
|
14
|
+
* uploadFile + set_image pattern
|
|
15
|
+
* - `ai_docs/reference/reactor/image-to-video-player.md:94` — full
|
|
16
|
+
* image-to-video example
|
|
17
|
+
*
|
|
18
|
+
* The shorter `ai_docs/reference/reactor/llms.txt:558` summary line
|
|
19
|
+
* lists `image_b64: string` for this command — that is misleading /
|
|
20
|
+
* out of date; the detailed reference pages above are authoritative.
|
|
21
|
+
*
|
|
4
22
|
* Lifted from three React copies (#116):
|
|
5
23
|
* - `web/app/interactive/InteractiveController.tsx` (Phase 1)
|
|
6
24
|
* - `web/app/interactive/director/useSeedImageEffect.ts` (Phase 2)
|
|
7
25
|
* - `web/app/interactive/chat/page.tsx` (Phase 3)
|
|
8
26
|
*
|
|
9
|
-
*
|
|
27
|
+
* Flow:
|
|
10
28
|
* load blob from `apiClient.getSeedImageBlob`
|
|
11
29
|
* → wrap as `File` with extension derived from MIME (round 14 fix)
|
|
12
30
|
* → `reactor.uploadFile(file)` → `FileRef`
|
|
13
31
|
* → `reactor.sendCommand('set_image', { image: ref, transition })`
|
|
14
|
-
* → optionally await `waitForImageReady()` (model echoes `
|
|
32
|
+
* → optionally await `waitForImageReady()` (model echoes `image_set`
|
|
33
|
+
* with width/height)
|
|
15
34
|
*
|
|
16
35
|
* The pending-file queue (selected image arrived before the session was
|
|
17
36
|
* ready) lives in the React hook on top of this — it's UI-lifecycle
|
|
@@ -27,6 +46,13 @@ import type { ApiClient } from '../api';
|
|
|
27
46
|
* Minimal Reactor surface needed by the orchestrator. Same shape used
|
|
28
47
|
* by `HeliosReactorBridge` in `heliosCommandDispatcher.ts` — the
|
|
29
48
|
* dispatcher and orchestrator share the bridge by structural typing.
|
|
49
|
+
*
|
|
50
|
+
* `uploadFile` must return a real `FileRef` instance (or a structural
|
|
51
|
+
* equivalent the SDK recognises). The SDK detects FileRef values in
|
|
52
|
+
* the `data` argument of `sendCommand` and lifts them into a separate
|
|
53
|
+
* `uploads` envelope section before transmitting — that's the only
|
|
54
|
+
* way image bytes reach Helios. Passing a plain object that looks
|
|
55
|
+
* like a FileRef but lacks the class identity will silently no-op.
|
|
30
56
|
*/
|
|
31
57
|
export interface SeedImageReactorBridge {
|
|
32
58
|
sendCommand: (command: string, data: unknown) => Promise<void>;
|
|
@@ -36,6 +62,140 @@ export interface SeedImageReactorBridge {
|
|
|
36
62
|
) => Promise<unknown>;
|
|
37
63
|
}
|
|
38
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Reactor's WebRTC data channel rejects messages over 65,536 bytes
|
|
67
|
+
* (the SDK enforces this client-side before send). A 1080p PNG from
|
|
68
|
+
* the extract-image endpoint is ~1.27 MB raw → ~1.69 MB base64 → the
|
|
69
|
+
* whole `set_image` envelope blows past the limit and the SDK throws
|
|
70
|
+
* "Data channel message too large". We have to keep the base64
|
|
71
|
+
* payload below ~64 KB, which means raw bytes ≤ ~48 KB.
|
|
72
|
+
*
|
|
73
|
+
* Strategy: load the blob into an HTMLImageElement, draw to canvas
|
|
74
|
+
* at a clamped dimension, encode as JPEG with a quality ramp until
|
|
75
|
+
* the result fits the budget. We don't lose meaningful conditioning
|
|
76
|
+
* fidelity — Helios's image encoder downsamples internally to a
|
|
77
|
+
* fixed latent resolution regardless of input size.
|
|
78
|
+
*
|
|
79
|
+
* Falls back to the original blob in environments without a canvas
|
|
80
|
+
* backend (jsdom in tests). Browser callers always exercise the
|
|
81
|
+
* downscale path.
|
|
82
|
+
*/
|
|
83
|
+
const DEFAULT_MAX_RAW_BYTES = 45 * 1024;
|
|
84
|
+
const DEFAULT_MAX_DIMENSION = 512;
|
|
85
|
+
|
|
86
|
+
export interface DownscaleOptions {
|
|
87
|
+
/** Upper bound on the post-encode raw byte size. Default ~45 KB so
|
|
88
|
+
* the resulting base64 string fits within Reactor's 64 KB data
|
|
89
|
+
* channel message cap with envelope overhead to spare. */
|
|
90
|
+
maxRawBytes?: number;
|
|
91
|
+
/** Cap on the longer image dimension. Default 512 (covers 16:9
|
|
92
|
+
* 512×288 etc.). Helios's image encoder downsamples internally so
|
|
93
|
+
* going larger gains nothing for conditioning. */
|
|
94
|
+
maxDimension?: number;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export async function downscaleImageForDataChannel(
|
|
98
|
+
blob: Blob,
|
|
99
|
+
options: DownscaleOptions = {},
|
|
100
|
+
): Promise<Blob> {
|
|
101
|
+
const maxRawBytes = options.maxRawBytes ?? DEFAULT_MAX_RAW_BYTES;
|
|
102
|
+
const maxDimension = options.maxDimension ?? DEFAULT_MAX_DIMENSION;
|
|
103
|
+
|
|
104
|
+
// Already small enough — short-circuit. (The "already small" fast
|
|
105
|
+
// path also lets character-image thumbnails through unchanged.)
|
|
106
|
+
if (blob.size <= maxRawBytes) return blob;
|
|
107
|
+
|
|
108
|
+
// jsdom / SSR — no canvas backend available. Pass through so unit
|
|
109
|
+
// tests don't have to mock canvas; browser code never hits this.
|
|
110
|
+
if (typeof document === 'undefined') return blob;
|
|
111
|
+
const canvas = document.createElement('canvas');
|
|
112
|
+
const ctx = canvas.getContext('2d');
|
|
113
|
+
if (!ctx) return blob;
|
|
114
|
+
|
|
115
|
+
let img: HTMLImageElement;
|
|
116
|
+
try {
|
|
117
|
+
img = await loadBlobAsImage(blob);
|
|
118
|
+
} catch {
|
|
119
|
+
// Image decode failed — return the original. The downstream
|
|
120
|
+
// sendCommand will surface the data-channel-too-large error
|
|
121
|
+
// instead of a misleading decode error.
|
|
122
|
+
return blob;
|
|
123
|
+
}
|
|
124
|
+
const width = img.naturalWidth || img.width;
|
|
125
|
+
const height = img.naturalHeight || img.height;
|
|
126
|
+
if (!width || !height) return blob;
|
|
127
|
+
const scale = Math.min(1, maxDimension / Math.max(width, height));
|
|
128
|
+
const w = Math.max(1, Math.round(width * scale));
|
|
129
|
+
const h = Math.max(1, Math.round(height * scale));
|
|
130
|
+
canvas.width = w;
|
|
131
|
+
canvas.height = h;
|
|
132
|
+
ctx.drawImage(img, 0, 0, w, h);
|
|
133
|
+
|
|
134
|
+
for (const quality of [0.85, 0.75, 0.65, 0.55, 0.45, 0.35]) {
|
|
135
|
+
const encoded = await canvasToBlob(canvas, 'image/jpeg', quality);
|
|
136
|
+
if (!encoded) continue;
|
|
137
|
+
if (encoded.size <= maxRawBytes) return encoded;
|
|
138
|
+
}
|
|
139
|
+
// Last-ditch: take whatever the lowest quality yields. Even if it
|
|
140
|
+
// exceeds the budget, the SDK will surface the same data-channel
|
|
141
|
+
// error and the operator can pick a smaller frame.
|
|
142
|
+
const lastResort = await canvasToBlob(canvas, 'image/jpeg', 0.3);
|
|
143
|
+
return lastResort ?? blob;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function loadBlobAsImage(blob: Blob): Promise<HTMLImageElement> {
|
|
147
|
+
return new Promise((resolve, reject) => {
|
|
148
|
+
const url = URL.createObjectURL(blob);
|
|
149
|
+
const img = new Image();
|
|
150
|
+
img.onload = () => {
|
|
151
|
+
URL.revokeObjectURL(url);
|
|
152
|
+
resolve(img);
|
|
153
|
+
};
|
|
154
|
+
img.onerror = () => {
|
|
155
|
+
URL.revokeObjectURL(url);
|
|
156
|
+
reject(new Error('image decode failed'));
|
|
157
|
+
};
|
|
158
|
+
img.src = url;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function canvasToBlob(
|
|
163
|
+
canvas: HTMLCanvasElement,
|
|
164
|
+
type: string,
|
|
165
|
+
quality: number,
|
|
166
|
+
): Promise<Blob | null> {
|
|
167
|
+
return new Promise(resolve => {
|
|
168
|
+
canvas.toBlob(b => resolve(b), type, quality);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Read a blob's bytes and base64-encode them. Uses FileReader (available
|
|
174
|
+
* in browsers AND jsdom) and strips the data-URL prefix so the output
|
|
175
|
+
* is the bare base64 payload, which is what Helios expects.
|
|
176
|
+
*/
|
|
177
|
+
export async function fileToBase64(file: Blob): Promise<string> {
|
|
178
|
+
return await new Promise<string>((resolve, reject) => {
|
|
179
|
+
const reader = new FileReader();
|
|
180
|
+
reader.onload = () => {
|
|
181
|
+
const result = reader.result;
|
|
182
|
+
if (typeof result !== 'string') {
|
|
183
|
+
reject(new Error('FileReader yielded non-string result'));
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const commaIdx = result.indexOf(',');
|
|
187
|
+
if (commaIdx === -1 || !result.startsWith('data:')) {
|
|
188
|
+
reject(new Error('Unexpected FileReader data-URL shape'));
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
resolve(result.slice(commaIdx + 1));
|
|
192
|
+
};
|
|
193
|
+
reader.onerror = () =>
|
|
194
|
+
reject(reader.error ?? new Error('FileReader error'));
|
|
195
|
+
reader.readAsDataURL(file);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
39
199
|
export interface ApplySeedImageOptions {
|
|
40
200
|
/** `'cut'` (default) for the first seed in a session, `'blend'` for
|
|
41
201
|
* subsequent swaps so the model smooths the visual transition.
|
|
@@ -102,9 +262,46 @@ export async function sendSeedFileToReactor(
|
|
|
102
262
|
reactor: SeedImageReactorBridge,
|
|
103
263
|
options: Omit<ApplySeedImageOptions, 'signal' | 'filenameStem'> = {},
|
|
104
264
|
): Promise<void> {
|
|
105
|
-
|
|
265
|
+
// Canonical Helios image-to-video pattern (file-uploads.md:33,
|
|
266
|
+
// image-to-video-player.md:94): uploadFile → FileRef → set_image
|
|
267
|
+
// with `{ image: ref, transition? }`. Bytes go via HTTP to Reactor's
|
|
268
|
+
// object store; the command channel carries only the ref.
|
|
269
|
+
//
|
|
270
|
+
// **Transition is opt-in.** The JS spike that reliably reproduced
|
|
271
|
+
// image-to-video (`scripts/spikes/helios_set_image_spike.html`) sends
|
|
272
|
+
// `{ image: ref }` with NO `transition` field, matching the docs
|
|
273
|
+
// imperative sample verbatim. We default to omitting it; the
|
|
274
|
+
// InteractiveController seed-swap path passes `'blend'` explicitly
|
|
275
|
+
// when swapping mid-stream.
|
|
276
|
+
//
|
|
277
|
+
// **Do not wait for an ack here.** The standalone Python spike
|
|
278
|
+
// (`scripts/spikes/helios_set_image_spike.py`) confirmed that the
|
|
279
|
+
// success event is `image_accepted` (NOT `image_set` as
|
|
280
|
+
// helios-overview.md:441 claims — those docs are wrong) and it
|
|
281
|
+
// only fires AFTER `start` is issued, during chunk 0 generation.
|
|
282
|
+
// Any wait between set_image and the subsequent set_prompt+start
|
|
283
|
+
// therefore deadlocks for `waitForImageReady`-timeout milliseconds
|
|
284
|
+
// and produces no value. Match the docs sample's back-to-back
|
|
285
|
+
// sequence.
|
|
286
|
+
//
|
|
287
|
+
// `waitForImageReady` is kept on the options surface for back-compat
|
|
288
|
+
// with InteractiveController's pending-seed flush (which DOES want
|
|
289
|
+
// to know when the seed has landed before letting the operator
|
|
290
|
+
// submit a prompt). Callers like bootstrapSceneInReactor that
|
|
291
|
+
// chain `start` right after should NOT pass it.
|
|
292
|
+
const uploadStart = Date.now();
|
|
106
293
|
const ref = await reactor.uploadFile(file);
|
|
107
|
-
|
|
294
|
+
console.info('[seedImage] uploaded', {
|
|
295
|
+
bytes: file.size,
|
|
296
|
+
mime: file.type,
|
|
297
|
+
ref,
|
|
298
|
+
elapsedMs: Date.now() - uploadStart,
|
|
299
|
+
});
|
|
300
|
+
const setImageData: { image: unknown; transition?: 'cut' | 'blend' } = {
|
|
301
|
+
image: ref,
|
|
302
|
+
};
|
|
303
|
+
if (options.transition) setImageData.transition = options.transition;
|
|
304
|
+
await reactor.sendCommand('set_image', setImageData);
|
|
108
305
|
if (options.waitForImageReady) await options.waitForImageReady();
|
|
109
306
|
}
|
|
110
307
|
|
package/src/timeFormat.ts
CHANGED
|
@@ -55,3 +55,16 @@ export function formatTimestamp(
|
|
|
55
55
|
|
|
56
56
|
return base;
|
|
57
57
|
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Preset of {@link formatTimestamp} with `centiseconds: true` — the format
|
|
61
|
+
* used for citation timestamps in chat surfaces where sub-second word/turn
|
|
62
|
+
* boundaries are load-bearing.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* formatCitationTimestamp(83.45) // "1:23.45"
|
|
66
|
+
* formatCitationTimestamp(0) // "0:00.00"
|
|
67
|
+
*/
|
|
68
|
+
export function formatCitationTimestamp(seconds: number): string {
|
|
69
|
+
return formatTimestamp(seconds, { centiseconds: true });
|
|
70
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent tool-schema TypeScript mirror.
|
|
3
|
+
*
|
|
4
|
+
* This is the framework-agnostic TS view of the SERVER-SIDE RAG tool
|
|
5
|
+
* vocabulary whose canonical (single-source-of-truth) definition lives in
|
|
6
|
+
* the backend at `shared/tool_schemas.py` (Agent OS Phase 5 / P3). The Python
|
|
7
|
+
* module derives Bedrock Converse tool specs from Pydantic request models;
|
|
8
|
+
* this file mirrors the same 12 tool names, descriptions, and request field
|
|
9
|
+
* shapes so frontend code can introspect the agent's tool surface (e.g. for
|
|
10
|
+
* UI affordances, debugging panels, or future browser-defined-tool routing)
|
|
11
|
+
* without copy-pasting strings into each consumer.
|
|
12
|
+
*
|
|
13
|
+
* SCOPE: these are the *server-side* tools the agent executes inline
|
|
14
|
+
* (semantic_search, extract_image, generate_character, …). They are a
|
|
15
|
+
* DIFFERENT vocabulary from the Helios *browser-side* tools encoded in
|
|
16
|
+
* `reactor/heliosTools.ts` (`BEDROCK_TOOL_SCHEMAS`: set_scene, swap_seed, …).
|
|
17
|
+
* The two do not converge; both are intentionally separate tool surfaces.
|
|
18
|
+
*
|
|
19
|
+
* KEEP IN SYNC: when the backend's `shared/tool_schemas.py` adds/removes a
|
|
20
|
+
* tool or changes a field, mirror it here. This file is the seed that lets
|
|
21
|
+
* the web clients stop hand-copying tool metadata; the backend remains the
|
|
22
|
+
* source of truth. There is no codegen yet (tracked in the backend
|
|
23
|
+
* `specs/technical-debt.md`).
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/** JSON-schema-ish primitive types we expose for request fields. */
|
|
27
|
+
export type ToolFieldType = 'string' | 'number' | 'integer' | 'boolean';
|
|
28
|
+
|
|
29
|
+
/** Description of a single request field on a tool. */
|
|
30
|
+
export interface ToolRequestField {
|
|
31
|
+
/** Field name as the backend Pydantic model expects it (camelCase). */
|
|
32
|
+
readonly name: string;
|
|
33
|
+
readonly type: ToolFieldType;
|
|
34
|
+
/** Whether the backend model requires this field. */
|
|
35
|
+
readonly required: boolean;
|
|
36
|
+
/** Allowed values when the field is a constrained enum. */
|
|
37
|
+
readonly enum?: readonly string[];
|
|
38
|
+
readonly description: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** A single agent tool's framework-agnostic metadata. */
|
|
42
|
+
export interface AgentToolSchema {
|
|
43
|
+
/** Tool name (matches the backend Bedrock toolSpec name). */
|
|
44
|
+
readonly name: string;
|
|
45
|
+
readonly description: string;
|
|
46
|
+
/** HTTP method the backend endpoint uses (mirrors ToolSchema.http_method). */
|
|
47
|
+
readonly httpMethod: 'GET' | 'POST';
|
|
48
|
+
/** Backend endpoint path the tool maps to. */
|
|
49
|
+
readonly endpoint: string;
|
|
50
|
+
readonly fields: readonly ToolRequestField[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The 12 server-side agent tools, mirroring `shared/tool_schemas.py`.
|
|
55
|
+
*
|
|
56
|
+
* Frozen at the type level via `as const` so consumers get literal
|
|
57
|
+
* `name`/`enum` types and cannot mutate the shared constant.
|
|
58
|
+
*/
|
|
59
|
+
export const AGENT_TOOL_SCHEMAS = [
|
|
60
|
+
{
|
|
61
|
+
name: 'list_videos',
|
|
62
|
+
description:
|
|
63
|
+
'List all ingested videos with metadata, download URLs, and durations.',
|
|
64
|
+
httpMethod: 'GET',
|
|
65
|
+
endpoint: '/api/v1/ingestion/videos',
|
|
66
|
+
fields: [
|
|
67
|
+
{ name: 'prefix', type: 'string', required: false, description: 'Optional prefix to filter objects by directory path' },
|
|
68
|
+
{ name: 'pageSize', type: 'integer', required: false, description: 'Maximum number of videos to return per page (1-100)' },
|
|
69
|
+
{ name: 'continuationToken', type: 'string', required: false, description: 'Token from previous response to continue pagination' },
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: 'semantic_search',
|
|
74
|
+
description:
|
|
75
|
+
'Hybrid semantic search across captions, entities, and vectors.',
|
|
76
|
+
httpMethod: 'POST',
|
|
77
|
+
endpoint: '/api/v1/tools/semantic-search',
|
|
78
|
+
fields: [
|
|
79
|
+
{ name: 'query', type: 'string', required: false, description: 'Natural language query' },
|
|
80
|
+
{ name: 'videoId', type: 'string', required: false, description: 'Video to scope the search' },
|
|
81
|
+
{ name: 'k', type: 'integer', required: false, description: 'Maximum records to return (1-50)' },
|
|
82
|
+
{ name: 'offset', type: 'integer', required: false, description: 'Number of matches to skip before returning results' },
|
|
83
|
+
{ name: 'scope', type: 'string', required: false, enum: ['shots', 'videos', 'hybrid'], description: 'Search scope: shots, videos, or hybrid' },
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: 'events_for_range',
|
|
88
|
+
description: 'Retrieve segments overlapping a provided time range.',
|
|
89
|
+
httpMethod: 'POST',
|
|
90
|
+
endpoint: '/api/v1/tools/events-for-range',
|
|
91
|
+
fields: [
|
|
92
|
+
{ name: 'videoId', type: 'string', required: true, description: 'Video identifier' },
|
|
93
|
+
{ name: 't0', type: 'number', required: true, description: 'Start time in seconds' },
|
|
94
|
+
{ name: 't1', type: 'number', required: true, description: 'End time in seconds' },
|
|
95
|
+
{ name: 'offset', type: 'integer', required: false, description: 'Number of segments to skip' },
|
|
96
|
+
{ name: 'limit', type: 'integer', required: false, description: 'Maximum number of segments to return (1-200)' },
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
name: 'clip_lookup',
|
|
101
|
+
description: 'Return a signed URL for the requested clip window.',
|
|
102
|
+
httpMethod: 'POST',
|
|
103
|
+
endpoint: '/api/v1/tools/clip-lookup',
|
|
104
|
+
fields: [
|
|
105
|
+
{ name: 'videoId', type: 'string', required: true, description: 'Video identifier' },
|
|
106
|
+
{ name: 't0', type: 'number', required: true, description: 'Start time in seconds' },
|
|
107
|
+
{ name: 't1', type: 'number', required: true, description: 'End time in seconds' },
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: 'entity_timeline',
|
|
112
|
+
description: 'Find occurrences of an entity across the timeline.',
|
|
113
|
+
httpMethod: 'POST',
|
|
114
|
+
endpoint: '/api/v1/tools/entity-timeline',
|
|
115
|
+
fields: [
|
|
116
|
+
{ name: 'videoId', type: 'string', required: true, description: 'Video identifier' },
|
|
117
|
+
{ name: 'entity', type: 'string', required: true, description: 'Entity name to locate' },
|
|
118
|
+
{ name: 't0', type: 'number', required: false, description: 'Optional start bound' },
|
|
119
|
+
{ name: 't1', type: 'number', required: false, description: 'Optional end bound' },
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: 'scene_neighbors',
|
|
124
|
+
description: 'Traverse graph neighbors for a shot within a video.',
|
|
125
|
+
httpMethod: 'POST',
|
|
126
|
+
endpoint: '/api/v1/tools/scene-neighbors',
|
|
127
|
+
fields: [
|
|
128
|
+
{ name: 'videoId', type: 'string', required: true, description: 'Video identifier' },
|
|
129
|
+
{ name: 'shotId', type: 'string', required: true, description: 'Shot identifier' },
|
|
130
|
+
{ name: 'depth', type: 'integer', required: false, description: 'Traversal depth (1-3)' },
|
|
131
|
+
],
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
name: 'dialog_search',
|
|
135
|
+
description:
|
|
136
|
+
'Search spoken dialog/transcript text within a video by keyword or phrase.',
|
|
137
|
+
httpMethod: 'POST',
|
|
138
|
+
endpoint: '/api/v1/tools/dialog-search',
|
|
139
|
+
fields: [
|
|
140
|
+
{ name: 'videoId', type: 'string', required: true, description: 'Video identifier' },
|
|
141
|
+
{ name: 'query', type: 'string', required: true, description: 'Search query for dialog text' },
|
|
142
|
+
{ name: 'limit', type: 'integer', required: false, description: 'Maximum results to return (1-100)' },
|
|
143
|
+
],
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
name: 'get_transcript',
|
|
147
|
+
description:
|
|
148
|
+
'Retrieve the full transcript of spoken dialog for a video, optionally filtered by time range.',
|
|
149
|
+
httpMethod: 'POST',
|
|
150
|
+
endpoint: '/api/v1/tools/get-transcript',
|
|
151
|
+
fields: [
|
|
152
|
+
{ name: 'videoId', type: 'string', required: true, description: 'Video identifier' },
|
|
153
|
+
{ name: 't0', type: 'number', required: false, description: 'Optional start time filter' },
|
|
154
|
+
{ name: 't1', type: 'number', required: false, description: 'Optional end time filter' },
|
|
155
|
+
],
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: 'speaker_dialog',
|
|
159
|
+
description:
|
|
160
|
+
'Retrieve all dialog spoken by a specific character in a video.',
|
|
161
|
+
httpMethod: 'POST',
|
|
162
|
+
endpoint: '/api/v1/tools/speaker-dialog',
|
|
163
|
+
fields: [
|
|
164
|
+
{ name: 'videoId', type: 'string', required: true, description: 'Video identifier' },
|
|
165
|
+
{ name: 'entity', type: 'string', required: true, description: 'Character/entity name' },
|
|
166
|
+
{ name: 't0', type: 'number', required: false, description: 'Optional start time filter' },
|
|
167
|
+
{ name: 't1', type: 'number', required: false, description: 'Optional end time filter' },
|
|
168
|
+
],
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
name: 'extract_image',
|
|
172
|
+
description:
|
|
173
|
+
'Extract and show an actual frame from the video without AI modification. Provide the entity parameter to locate a relevant scene; optionally provide a timestamp.',
|
|
174
|
+
httpMethod: 'POST',
|
|
175
|
+
endpoint: '/api/v1/tools/extract-image',
|
|
176
|
+
fields: [
|
|
177
|
+
{ name: 'videoId', type: 'string', required: true, description: 'Video identifier' },
|
|
178
|
+
{ name: 'entity', type: 'string', required: true, description: 'Name of a character, object, location, or visual element to locate' },
|
|
179
|
+
{ name: 'timestamp', type: 'number', required: false, description: 'Optional specific timestamp (seconds) to extract the frame from' },
|
|
180
|
+
],
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
name: 'regenerate_image',
|
|
184
|
+
description:
|
|
185
|
+
'Generate an AI-modified image based on a video frame. Use only for creative transformations. The entity locates a scene; the prompt controls the transformation.',
|
|
186
|
+
httpMethod: 'POST',
|
|
187
|
+
endpoint: '/api/v1/tools/regenerate-image',
|
|
188
|
+
fields: [
|
|
189
|
+
{ name: 'videoId', type: 'string', required: true, description: 'Video identifier' },
|
|
190
|
+
{ name: 'entity', type: 'string', required: true, description: 'Name of a character, object, location, or visual element to locate' },
|
|
191
|
+
{ name: 'prompt', type: 'string', required: true, description: 'Text prompt describing what to generate from the frame' },
|
|
192
|
+
{ name: 'timestamp', type: 'number', required: false, description: 'Optional specific timestamp (seconds) to extract the frame from' },
|
|
193
|
+
{ name: 'model', type: 'string', required: false, description: 'Optional Gemini model override' },
|
|
194
|
+
],
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
name: 'generate_character',
|
|
198
|
+
description:
|
|
199
|
+
'Generate a clean 2D rest-pose character image for viseme bundle generation. Provide videoId+entity to extract a frame, or sourceImageId to start from an existing tracked image.',
|
|
200
|
+
httpMethod: 'POST',
|
|
201
|
+
endpoint: '/api/v1/tools/generate-character',
|
|
202
|
+
fields: [
|
|
203
|
+
{ name: 'videoId', type: 'string', required: false, description: 'Video to extract a reference frame from' },
|
|
204
|
+
{ name: 'entity', type: 'string', required: false, description: 'Character/entity name to locate in the video' },
|
|
205
|
+
{ name: 'timestamp', type: 'number', required: false, description: 'Optional timestamp for frame extraction' },
|
|
206
|
+
{ name: 'sourceImageId', type: 'string', required: false, description: 'ID of an existing tracked image to use as reference' },
|
|
207
|
+
{ name: 'style', type: 'string', required: false, description: "Style hint (e.g., 'anime', 'pixel art', 'cartoon')" },
|
|
208
|
+
{ name: 'model', type: 'string', required: false, description: 'Optional Gemini model override' },
|
|
209
|
+
],
|
|
210
|
+
},
|
|
211
|
+
] as const satisfies readonly AgentToolSchema[];
|
|
212
|
+
|
|
213
|
+
/** Union of the 12 server-side tool names (literal type). */
|
|
214
|
+
export type AgentToolName = (typeof AGENT_TOOL_SCHEMAS)[number]['name'];
|
|
215
|
+
|
|
216
|
+
/** Look up a single tool schema by name. Returns undefined if unknown. */
|
|
217
|
+
export function getAgentToolSchema(
|
|
218
|
+
name: string,
|
|
219
|
+
): AgentToolSchema | undefined {
|
|
220
|
+
return AGENT_TOOL_SCHEMAS.find((tool) => tool.name === name);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** All 12 tool names, in canonical order. */
|
|
224
|
+
export const AGENT_TOOL_NAMES: readonly AgentToolName[] =
|
|
225
|
+
AGENT_TOOL_SCHEMAS.map((tool) => tool.name);
|