@map-audio/pam-mcp-server 1.7.0 → 1.18.1
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 +21 -5
- package/dist/bridge.d.ts +18 -3
- package/dist/bridge.js +122 -19
- package/dist/bridge.js.map +1 -1
- package/dist/fgemma-format.d.ts +119 -0
- package/dist/fgemma-format.js +292 -0
- package/dist/fgemma-format.js.map +1 -0
- package/dist/fgemma-runner.d.ts +27 -0
- package/dist/fgemma-runner.js +475 -0
- package/dist/fgemma-runner.js.map +1 -0
- package/dist/manifest-cell1.json +7950 -0
- package/dist/manifest-mfx.json +13381 -0
- package/dist/manifest.d.ts +2 -1
- package/dist/manifest.js +79 -29
- package/dist/manifest.js.map +1 -1
- package/dist/manifest.json +19774 -6576
- package/dist/mixAssist.d.ts +155 -0
- package/dist/mixAssist.js +647 -0
- package/dist/mixAssist.js.map +1 -0
- package/dist/presetSave.d.ts +10 -0
- package/dist/presetSave.js +22 -0
- package/dist/presetSave.js.map +1 -0
- package/dist/server.js +3137 -196
- package/dist/server.js.map +1 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -77,11 +77,27 @@ Use the same `mcpServers` block in the client's MCP config. Any stdio-compatible
|
|
|
77
77
|
|
|
78
78
|
## What's in the box
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
80
|
+
~137 tools. The high-value entry points:
|
|
81
|
+
|
|
82
|
+
- **Read first**: `design_context` (curated parameter cheat sheet, works offline) and `get_design_overview` (compact live snapshot). Prefer these over full `get_state` dumps or broad `get_parameter_info` sweeps.
|
|
83
|
+
- **Sound design**: `set_parameters`, `update_pattern`, `add_modulation` / `add_param_seq`, `update_effect_config`, `set_master_effects`, `set_drum_synth`, `randomize` / `randomize_samples` / `randomize_patterns`.
|
|
84
|
+
- **Samples**: `get_default_locations` → `list_samples` → `load_sample`, plus `trim/reverse/gain/normalize_sample`, `analyze_sample_tempo`, `resample_sample_to_bpm`, `build_sample_chain`.
|
|
85
|
+
- **Transport & MIDI**: `start_transport` / `stop_transport` / `full_stop_transport`, `set_bpm`, `trigger_midi` (+ CC / program change), `midi_recording`.
|
|
86
|
+
- **Presets, variations & songs**: `load_preset` / `save_preset` / `new_preset`, `save_variation` / `load_variation` / `queue_variation`, `song_mode`, `export_song` (full-track bounce), `export_audio` (incl. per-cell stems).
|
|
87
|
+
- **Looper**: full 8-track control — arm/record/capture, `load_audio_to_looper_track`, warp, looper variations, `live_resample`.
|
|
88
|
+
- **Plugin host** (PAM builds with hosting): `scan_plugins` → `get_plugin_scan_status` → `list_plugins` → `load_plugin` → `list_loaded_plugins` → `set_plugin_param` / `set_plugin_bypass`.
|
|
89
|
+
- **AI models & generation** (experimental flags required): `download_model` / `load_model` / `get_model_status` / `list_models` (engines: aigen, magenta, notochord), `generate_sample`, `generate_kit`.
|
|
90
|
+
- **Video (VX) & UI** — require PAM's window to be open: `get_video_state`, `add_video_layer`, `bind_video_param`, `video_command`, …, and `capture_ui` (deterministic UI screenshot).
|
|
91
|
+
- **Offline (manifest-only)**: `get_parameter_info`, `design_context`, `list_presets`, `read_preset`, `get_manifest_summary`.
|
|
92
|
+
|
|
93
|
+
All three product manifests (PAM / CELL1 / MFX) are bundled; the server auto-selects by the connected instance's product, so one config entry drives all three products.
|
|
94
|
+
|
|
95
|
+
## Agent ergonomics
|
|
96
|
+
|
|
97
|
+
- **Tool annotations.** Every tool carries MCP annotations. Tools with `readOnlyHint: true` never change plugin state, so clients can approve them freely. `destructiveHint: true` marks tools that discard user state (`delete_preset`, `reset_cell`, `load_preset` over unsaved edits). `openWorldHint` is `false` on every tool; the server only talks to the local plugin.
|
|
98
|
+
- **Structured output.** The status tools (`connection_status`, `select_instance`, `get_transport`, `get_manifest_summary`, `get_model_status`, `get_plugin_scan_status`, `workbench_sidecar_status`) return `structuredContent` with a declared output schema, alongside the same JSON as text.
|
|
99
|
+
- **Prompts.** Five guided workflows ship as MCP prompts: `build-a-beat`, `make-a-song`, `design-a-preset`, `mix-and-master`, `troubleshoot-bridge`. In Claude Code they appear as slash commands (e.g. `/pam:build-a-beat`).
|
|
100
|
+
- **Multiple instances.** When several products run at once (say PAM and MFX), `select_instance` picks which one the live tools drive, matched by product name, instanceId, or port. Setting `PAM_BRIDGE_PRODUCT=MFX` in the server's `env` block pins the choice at launch. Offline parameter validation follows the selected product's manifest.
|
|
85
101
|
|
|
86
102
|
## License
|
|
87
103
|
|
package/dist/bridge.d.ts
CHANGED
|
@@ -1,22 +1,37 @@
|
|
|
1
|
-
interface BridgeInfo {
|
|
1
|
+
export interface BridgeInfo {
|
|
2
2
|
port: number;
|
|
3
3
|
instanceId: string;
|
|
4
4
|
product: string;
|
|
5
5
|
pid: number;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Instance selector for connect(). `instanceId` matches exactly, `product`
|
|
9
|
+
* case-insensitively ("PAM" / "CELL1" / "MFX"), `port` directly. When a
|
|
10
|
+
* selector is given and nothing matches, connect() fails rather than silently
|
|
11
|
+
* driving a different instance. PAM_BRIDGE_PRODUCT env pins the default.
|
|
12
|
+
*/
|
|
13
|
+
export interface ConnectTarget {
|
|
14
|
+
port?: number;
|
|
15
|
+
product?: string;
|
|
16
|
+
instanceId?: string;
|
|
17
|
+
}
|
|
7
18
|
export declare class PluginBridge {
|
|
8
19
|
private socket;
|
|
9
20
|
private buffer;
|
|
10
21
|
private nextId;
|
|
11
22
|
private pending;
|
|
12
23
|
private connected;
|
|
24
|
+
private connectedInstance;
|
|
13
25
|
discover(): Promise<BridgeInfo[]>;
|
|
14
|
-
|
|
26
|
+
private static matchesTarget;
|
|
27
|
+
connect(target?: ConnectTarget): Promise<boolean>;
|
|
15
28
|
disconnect(): void;
|
|
16
29
|
isConnected(): boolean;
|
|
30
|
+
/** The discovery entry of the instance this bridge is connected to, if known. */
|
|
31
|
+
getConnectedInstance(): BridgeInfo | null;
|
|
17
32
|
private static readonly SLOW_ACTIONS;
|
|
33
|
+
private static readonly VERY_SLOW_ACTIONS;
|
|
18
34
|
send(action: string, ...args: unknown[]): Promise<unknown>;
|
|
19
35
|
private translateBridgeError;
|
|
20
36
|
private processBuffer;
|
|
21
37
|
}
|
|
22
|
-
export {};
|
package/dist/bridge.js
CHANGED
|
@@ -91,11 +91,36 @@ const NEW_ACTIONS_ADDED_IN_1_7_0 = new Set([
|
|
|
91
91
|
"previewSampleNative",
|
|
92
92
|
"stopPreviewNative",
|
|
93
93
|
]);
|
|
94
|
-
//
|
|
95
|
-
//
|
|
96
|
-
//
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
// Actions added in MCP server 1.8.0 — VX video subsystem control (layers, FX chains,
|
|
95
|
+
// audio-reactive bindings, output FX, mod routes, model overlay, render/sync settings)
|
|
96
|
+
// plus the full-scene read channel. Require a PAM build with the mcpVideoBridge wiring.
|
|
97
|
+
const NEW_ACTIONS_ADDED_IN_1_8_0 = new Set([
|
|
98
|
+
"videoCommand",
|
|
99
|
+
"getVideoState",
|
|
100
|
+
]);
|
|
101
|
+
// Actions added in MCP server 1.13.0 — drum-synth control routed through the WebView
|
|
102
|
+
// (the engine-aware randomizer + the drawable-wave LUT). Require a PAM build whose
|
|
103
|
+
// MCPBridge forwards them via postToUI; older builds return "unknown action 'X'".
|
|
104
|
+
const NEW_ACTIONS_ADDED_IN_1_13_0 = new Set([
|
|
105
|
+
"randomizeDrumSynth",
|
|
106
|
+
"setDrumSynthWaveCurve",
|
|
107
|
+
]);
|
|
108
|
+
// Actions added in MCP server 1.15.0 — the assistant-surface UI forwards
|
|
109
|
+
// (set_view navigation + the lfos/mods modulation randomizer), routed through
|
|
110
|
+
// the WebView like randomizeDrumSynth. Older builds return "unknown action 'X'".
|
|
111
|
+
const NEW_ACTIONS_ADDED_IN_1_15_0 = new Set([
|
|
112
|
+
"setView",
|
|
113
|
+
"randomizeModulations",
|
|
114
|
+
]);
|
|
115
|
+
const NEW_ACTIONS_ADDED_IN_1_17_0 = new Set([
|
|
116
|
+
"analyzeMix",
|
|
117
|
+
"getMixAnalysis",
|
|
118
|
+
]);
|
|
119
|
+
// Plugin-host actions ship on builds with PAM_PLUGIN_HOST=1. Older builds or
|
|
120
|
+
// non-host SKUs like Cell1 won't recognize them and will return
|
|
121
|
+
// "unknown action 'X'". MFX can compile FX-side hosting, but these shared MCP
|
|
122
|
+
// actions are still PAM-manager-shaped until product-aware FX-host tooling lands.
|
|
123
|
+
// The bridge handler translates unknown actions into an actionable tool error.
|
|
99
124
|
const PLUGIN_HOST_ACTIONS = new Set([
|
|
100
125
|
"listPlugins",
|
|
101
126
|
"scanPlugins",
|
|
@@ -110,12 +135,25 @@ const PLUGIN_HOST_ACTIONS = new Set([
|
|
|
110
135
|
"skipCurrentPluginScan",
|
|
111
136
|
"removeFromBlocklist",
|
|
112
137
|
]);
|
|
138
|
+
// The unified AI model-management actions (download/status/load/unload/delete/list
|
|
139
|
+
// for aigen/magenta/notochord) are compiled out on standalone MFX builds
|
|
140
|
+
// (#if !PAM_IS_MFX in MCPBridge.cpp) and absent on PAM builds older than 1.9.0 —
|
|
141
|
+
// both return "unknown action 'X'". Translate that into an actionable hint.
|
|
142
|
+
const MODEL_ACTIONS = new Set([
|
|
143
|
+
"modelDownload",
|
|
144
|
+
"modelStatus",
|
|
145
|
+
"modelLoad",
|
|
146
|
+
"modelUnload",
|
|
147
|
+
"modelDelete",
|
|
148
|
+
"modelList",
|
|
149
|
+
]);
|
|
113
150
|
export class PluginBridge {
|
|
114
151
|
socket = null;
|
|
115
152
|
buffer = "";
|
|
116
153
|
nextId = 1;
|
|
117
154
|
pending = new Map();
|
|
118
155
|
connected = false;
|
|
156
|
+
connectedInstance = null;
|
|
119
157
|
async discover() {
|
|
120
158
|
try {
|
|
121
159
|
const raw = await readFile(DISCOVERY_FILE, "utf-8");
|
|
@@ -141,14 +179,44 @@ export class PluginBridge {
|
|
|
141
179
|
return [];
|
|
142
180
|
}
|
|
143
181
|
}
|
|
144
|
-
|
|
145
|
-
if (
|
|
146
|
-
return
|
|
147
|
-
if (
|
|
148
|
-
|
|
182
|
+
static matchesTarget(instance, target) {
|
|
183
|
+
if (target.instanceId !== undefined && instance.instanceId !== target.instanceId)
|
|
184
|
+
return false;
|
|
185
|
+
if (target.port !== undefined && instance.port !== target.port)
|
|
186
|
+
return false;
|
|
187
|
+
if (target.product !== undefined &&
|
|
188
|
+
instance.product?.toLowerCase() !== target.product.toLowerCase())
|
|
189
|
+
return false;
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
async connect(target) {
|
|
193
|
+
// Default target: the PAM_BRIDGE_PRODUCT env pin, if set. The pin is hard —
|
|
194
|
+
// silently connecting to a different product would mutate the wrong plugin.
|
|
195
|
+
if (!target && process.env.PAM_BRIDGE_PRODUCT) {
|
|
196
|
+
target = { product: process.env.PAM_BRIDGE_PRODUCT };
|
|
197
|
+
}
|
|
198
|
+
if (this.connected) {
|
|
199
|
+
if (!target || (this.connectedInstance && PluginBridge.matchesTarget(this.connectedInstance, target)))
|
|
200
|
+
return true;
|
|
201
|
+
this.disconnect();
|
|
202
|
+
}
|
|
203
|
+
let port = target?.port;
|
|
204
|
+
let instance = null;
|
|
205
|
+
const instances = await this.discover();
|
|
206
|
+
if (target && (target.product !== undefined || target.instanceId !== undefined)) {
|
|
207
|
+
instance = instances.find((i) => PluginBridge.matchesTarget(i, target)) ?? null;
|
|
208
|
+
if (!instance)
|
|
209
|
+
return false;
|
|
210
|
+
port = instance.port;
|
|
211
|
+
}
|
|
212
|
+
else if (!port) {
|
|
149
213
|
if (instances.length === 0)
|
|
150
214
|
return false;
|
|
151
|
-
|
|
215
|
+
instance = instances[0];
|
|
216
|
+
port = instance.port;
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
instance = instances.find((i) => i.port === port) ?? null;
|
|
152
220
|
}
|
|
153
221
|
return new Promise((resolve) => {
|
|
154
222
|
const timer = setTimeout(() => {
|
|
@@ -160,6 +228,7 @@ export class PluginBridge {
|
|
|
160
228
|
this.socket = createConnection({ host: "127.0.0.1", port }, () => {
|
|
161
229
|
clearTimeout(timer);
|
|
162
230
|
this.connected = true;
|
|
231
|
+
this.connectedInstance = instance;
|
|
163
232
|
resolve(true);
|
|
164
233
|
});
|
|
165
234
|
this.socket.setEncoding("utf-8");
|
|
@@ -186,10 +255,15 @@ export class PluginBridge {
|
|
|
186
255
|
this.socket?.destroy();
|
|
187
256
|
this.socket = null;
|
|
188
257
|
this.connected = false;
|
|
258
|
+
this.connectedInstance = null;
|
|
189
259
|
}
|
|
190
260
|
isConnected() {
|
|
191
261
|
return this.connected;
|
|
192
262
|
}
|
|
263
|
+
/** The discovery entry of the instance this bridge is connected to, if known. */
|
|
264
|
+
getConnectedInstance() {
|
|
265
|
+
return this.connected ? this.connectedInstance : null;
|
|
266
|
+
}
|
|
193
267
|
// Actions that block the message thread for disk I/O + graph rebuild
|
|
194
268
|
static SLOW_ACTIONS = new Set([
|
|
195
269
|
"loadPreset",
|
|
@@ -204,14 +278,30 @@ export class PluginBridge {
|
|
|
204
278
|
"listDirectory",
|
|
205
279
|
"importVisualFolder",
|
|
206
280
|
"loadPlugin",
|
|
281
|
+
// Model lifecycle: trigger is fast, but load/unload/delete can join a
|
|
282
|
+
// manager bootstrap thread for seconds (non-interruptible ORT/MLX loads).
|
|
283
|
+
"modelDownload",
|
|
284
|
+
"modelLoad",
|
|
285
|
+
"modelUnload",
|
|
286
|
+
"modelDelete",
|
|
287
|
+
// Workbench: loadTake is a loadSampleToCell (disk + graph rebuild).
|
|
288
|
+
"workbenchLoadTake",
|
|
207
289
|
]);
|
|
290
|
+
// Actions that block on an external render process — the C++ handler itself
|
|
291
|
+
// waits up to 180 s on the sidecar (pipeline rebuild + sequential inpaints),
|
|
292
|
+
// so the TCP timeout must outlast it.
|
|
293
|
+
static VERY_SLOW_ACTIONS = new Set(["workbenchRender"]);
|
|
208
294
|
async send(action, ...args) {
|
|
209
295
|
if (!this.connected || !this.socket) {
|
|
210
296
|
throw new Error("Not connected to PAM plugin. Start PAM and ensure the MCP bridge is enabled.");
|
|
211
297
|
}
|
|
212
298
|
const id = this.nextId++;
|
|
213
299
|
const msg = { id, action, args };
|
|
214
|
-
const timeoutMs = PluginBridge.
|
|
300
|
+
const timeoutMs = PluginBridge.VERY_SLOW_ACTIONS.has(action)
|
|
301
|
+
? 190000
|
|
302
|
+
: PluginBridge.SLOW_ACTIONS.has(action)
|
|
303
|
+
? 30000
|
|
304
|
+
: 10000;
|
|
215
305
|
return new Promise((resolve, reject) => {
|
|
216
306
|
const timer = setTimeout(() => {
|
|
217
307
|
if (this.pending.has(id)) {
|
|
@@ -232,14 +322,27 @@ export class PluginBridge {
|
|
|
232
322
|
if (message.startsWith("unknown action '")) {
|
|
233
323
|
if (PLUGIN_HOST_ACTIONS.has(action)) {
|
|
234
324
|
return (`PAM build does not include the plugin host ('${action}' not recognized). ` +
|
|
235
|
-
`Plugin-host tools require a
|
|
236
|
-
`Cell1
|
|
325
|
+
`Plugin-host tools require a build with PAM_PLUGIN_HOST=1. ` +
|
|
326
|
+
`Cell1 does not host third-party plugins; MFX only exposes FX-side hosting and needs product-aware FX-host MCP support.`);
|
|
327
|
+
}
|
|
328
|
+
if (MODEL_ACTIONS.has(action)) {
|
|
329
|
+
return (`PAM build does not include the AI model managers ('${action}' not recognized). ` +
|
|
330
|
+
`Model-management tools require PAM ≥ 1.9.0 with the AIGen/Magenta/Notochord managers; ` +
|
|
331
|
+
`they are not available on standalone MFX builds.`);
|
|
237
332
|
}
|
|
238
|
-
const requiredVersion =
|
|
239
|
-
? "1.
|
|
240
|
-
:
|
|
241
|
-
?
|
|
242
|
-
:
|
|
333
|
+
const requiredVersion = NEW_ACTIONS_ADDED_IN_1_17_0.has(action)
|
|
334
|
+
? "1.17.0"
|
|
335
|
+
: NEW_ACTIONS_ADDED_IN_1_15_0.has(action)
|
|
336
|
+
? "1.15.0"
|
|
337
|
+
: NEW_ACTIONS_ADDED_IN_1_13_0.has(action)
|
|
338
|
+
? "1.13.0"
|
|
339
|
+
: NEW_ACTIONS_ADDED_IN_1_8_0.has(action)
|
|
340
|
+
? "1.8.0"
|
|
341
|
+
: NEW_ACTIONS_ADDED_IN_1_7_0.has(action)
|
|
342
|
+
? "1.7.0"
|
|
343
|
+
: NEW_ACTIONS_ADDED_IN_1_1_0.has(action) || NEW_ACTIONS_ADDED_IN_1_5_0.has(action)
|
|
344
|
+
? MIN_PAM_VERSION_FOR_NEW_ACTIONS
|
|
345
|
+
: null;
|
|
243
346
|
if (requiredVersion) {
|
|
244
347
|
return (`PAM build does not support '${action}'. ` +
|
|
245
348
|
`This action requires PAM ≥ ${requiredVersion} ` +
|
package/dist/bridge.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAe,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,EAAE,EAAE,sBAAsB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../src/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAe,MAAM,UAAU,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,cAAc,GAAG,OAAO,CAAC,OAAO,EAAE,EAAE,sBAAsB,CAAC,CAAC;AAiClE,iFAAiF;AACjF,6EAA6E;AAC7E,4EAA4E;AAC5E,+CAA+C;AAC/C,MA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
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FunctionGemma wire format — renderer + parser.
|
|
3
|
+
*
|
|
4
|
+
* Byte-parity with HF `tokenizer.apply_chat_template` is REQUIRED and pinned by
|
|
5
|
+
* scripts/check-fgemma-format.mjs against fixtures dumped by
|
|
6
|
+
* packages/fgemma-poc/dump_template_fixture.py. Empirical rules (from the
|
|
7
|
+
* fixtures, 2026-07-03, google/functiongemma-270m-it template):
|
|
8
|
+
*
|
|
9
|
+
* - Prompt starts with literal `<bos>` (template-added; serving layers that
|
|
10
|
+
* add BOS themselves must not receive it twice — see buildGenerationPrompt).
|
|
11
|
+
* - Developer turn: trigger phrase + declarations back-to-back, input order.
|
|
12
|
+
* - Schema objects render with keys sorted alphabetically at every level;
|
|
13
|
+
* `type` values are UPPERCASED; all schema strings are <escape>-wrapped.
|
|
14
|
+
* - Tool call/response argument objects ALSO sort keys at every level (the
|
|
15
|
+
* template dictsorts them — pinned by fixtures/hf_dictsort_probe.txt; the
|
|
16
|
+
* original fixtures were accidentally all-alphabetical and hid this);
|
|
17
|
+
* strings are <escape>-wrapped, numbers/booleans bare.
|
|
18
|
+
* - The tool call AND its function response live inside ONE continuous
|
|
19
|
+
* `model` turn: app appends `<start_function_response>response:…` inline
|
|
20
|
+
* and generation resumes — no new turn markers.
|
|
21
|
+
* - Multi-exchange history (fixtures hf_followup_prompt.txt /
|
|
22
|
+
* hf_followup_text_prompt.txt): a user message directly after a tool
|
|
23
|
+
* response is INLINED into the same model turn (no `<end_of_turn>` /
|
|
24
|
+
* `<start_of_turn>user` markers); a user message after assistant TEXT gets
|
|
25
|
+
* normal turn markers. buildGenerationPrompt's `history` option reproduces
|
|
26
|
+
* this byte-exactly.
|
|
27
|
+
* - Session context: `renderContextLine` renders the compact `[ctx]` state
|
|
28
|
+
* line prepended to the LAST user turn (grammar pinned against
|
|
29
|
+
* fixtures/context_line.txt; Python twin: packages/fgemma-poc/fgemma_context.py).
|
|
30
|
+
*/
|
|
31
|
+
export interface ToolDef {
|
|
32
|
+
name: string;
|
|
33
|
+
description: string;
|
|
34
|
+
parameters: Record<string, unknown>;
|
|
35
|
+
aliasOf?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface FunctionCall {
|
|
38
|
+
name: string;
|
|
39
|
+
arguments: Record<string, unknown>;
|
|
40
|
+
}
|
|
41
|
+
export declare const TRIGGER_PHRASE = "You are a model that can do function calling with the following functions";
|
|
42
|
+
/** Stop sequences for generation (per docs; <end_function_call> is deliberately
|
|
43
|
+
* absent — parallel calls arrive in one turn). */
|
|
44
|
+
export declare const STOP_SEQUENCES: string[];
|
|
45
|
+
/** Render a call/response VALUE: keys sorted at every level (matches the
|
|
46
|
+
* template's dictsort — training/inference byte-parity), strings escaped,
|
|
47
|
+
* no uppercasing. null/undefined render as bare `null` — never trained, but
|
|
48
|
+
* reachable at runtime (get_state of an absent key) and must not throw. */
|
|
49
|
+
export declare function renderValue(v: unknown): string;
|
|
50
|
+
export declare function renderDeclaration(tool: ToolDef): string;
|
|
51
|
+
export declare function renderDeveloperTurn(tools: ToolDef[]): string;
|
|
52
|
+
export declare function renderUserTurn(text: string): string;
|
|
53
|
+
export declare function renderFunctionCall(call: FunctionCall): string;
|
|
54
|
+
export declare function renderFunctionResponse(name: string, response: unknown): string;
|
|
55
|
+
export interface ContextCell {
|
|
56
|
+
id: number;
|
|
57
|
+
/** RAW name — sample path/basename or `Engine(synth)`; sanitized here. */
|
|
58
|
+
name: string;
|
|
59
|
+
}
|
|
60
|
+
export interface AssistantContext {
|
|
61
|
+
bpm: number;
|
|
62
|
+
playing: boolean;
|
|
63
|
+
/** Current main view — the set_view tool's lowercase token vocabulary
|
|
64
|
+
* (fgemma_context.py CTX_VIEWS); absent renders as the default `cells`. */
|
|
65
|
+
view?: string;
|
|
66
|
+
/** Active preset display name (RAW — sanitized here); absent → `none`. */
|
|
67
|
+
preset?: string | null;
|
|
68
|
+
/** Selected cell id (1-based); null/undefined/0 renders as `none`. */
|
|
69
|
+
sel?: number | null;
|
|
70
|
+
/** Muted cell ids (1-based); omitted/empty renders as `none`. */
|
|
71
|
+
muted?: number[];
|
|
72
|
+
cells: ContextCell[];
|
|
73
|
+
}
|
|
74
|
+
/** Basename, one extension stripped, whitespace→_, grammar-safe, ≤24 chars.
|
|
75
|
+
* Must match fgemma_context.py `sanitize_label` step for step. */
|
|
76
|
+
export declare function sanitizeContextLabel(name: string): string;
|
|
77
|
+
/** The compact `[ctx]` session-state line (fixed field order, all fields
|
|
78
|
+
* always present) — pinned against fixtures/context_line.txt. */
|
|
79
|
+
export declare function renderContextLine(ctx: AssistantContext): string;
|
|
80
|
+
/** The exact user-turn content shape: ctx line, newline, raw text. */
|
|
81
|
+
export declare function withContext(userText: string, ctx?: AssistantContext | null): string;
|
|
82
|
+
export interface HistoryExchange {
|
|
83
|
+
/** RAW user text of the past exchange (history turns carry no ctx line). */
|
|
84
|
+
user: string;
|
|
85
|
+
/** The full model-turn inner text as generated/executed: call blocks +
|
|
86
|
+
* inline function responses + any final text. */
|
|
87
|
+
model: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Full generation prompt: declarations [+ completed history exchanges] +
|
|
91
|
+
* user turn + `<start_of_turn>model\n`.
|
|
92
|
+
* `bos: "text"` embeds the literal `<bos>` (matches the HF render exactly);
|
|
93
|
+
* `bos: "none"` (runner default) leaves BOS insertion to the serving layer.
|
|
94
|
+
* History stitching mirrors the chat template exactly (pinned by
|
|
95
|
+
* hf_followup_prompt.txt / hf_followup_text_prompt.txt): an exchange whose
|
|
96
|
+
* model turn ends in a function response leaves the turn OPEN — the next user
|
|
97
|
+
* content is inlined with no turn markers; a text-final turn is closed with
|
|
98
|
+
* `<end_of_turn>` and the next user turn opens normally.
|
|
99
|
+
*/
|
|
100
|
+
export declare function buildGenerationPrompt(tools: ToolDef[], userText: string, opts?: {
|
|
101
|
+
bos?: "text" | "none";
|
|
102
|
+
history?: HistoryExchange[];
|
|
103
|
+
}): string;
|
|
104
|
+
/**
|
|
105
|
+
* Parse every `<start_function_call>call:name{…}<end_function_call>` block.
|
|
106
|
+
* Balanced-brace scan with <escape>-span awareness (the docs' flat reference
|
|
107
|
+
* regex cannot handle object/array argument values like update_pattern's
|
|
108
|
+
* sequence or get_state's keys).
|
|
109
|
+
*/
|
|
110
|
+
export declare function parseFunctionCalls(text: string): FunctionCall[];
|
|
111
|
+
/**
|
|
112
|
+
* Cut a completion at the first model-FABRICATED function response. Serving
|
|
113
|
+
* stacks that strip special tokens from output (LM Studio; llama-server
|
|
114
|
+
* without --special) erase <start_function_response> before the stop-string
|
|
115
|
+
* matcher can see it, so generation runs on and invents response:{…} payloads
|
|
116
|
+
* plus follow-up calls conditioned on them. Text before the first fabricated
|
|
117
|
+
* response is the model's real intent; everything after must not be executed.
|
|
118
|
+
*/
|
|
119
|
+
export declare function truncateAtFabricatedResponse(text: string): string;
|