bridge: roll tool for the player, glm 5.3 example config

This commit is contained in:
2026-11-11 21:26:26 +00:00
parent 1a4dcf9a2e
commit 9d7273c599
6 changed files with 36 additions and 16 deletions
+3 -2
View File
@@ -263,8 +263,9 @@ pedantic, whatever housekeeping needs. The two prompts are independent.
**Substrate:** `tool/bridge.mjs` is the thin bridge — a player session with
native tools, no UI. It assembles the bundle from the run's files (views
refreshed), offers the player tools (status always; records only when the
run's gate allows — the tool list is the capability surface), executes
refreshed), offers the player tools (status and a coin-flip roll always;
records only when the run's gate allows — the tool list is the capability
surface), executes
model tool calls against the clerk, logs the full exchange to
`runs/<story>/sessions/<stamp>.jsonl` (the housekeeping transcript), and
elides old tool results to stubs in the live context (use-and-discard).
+3 -3
View File
@@ -1,5 +1,5 @@
{
"baseUrl": "https://api.openai.com/v1",
"model": "gpt-4o",
"apiKeyEnv": "RP_API_KEY"
"baseUrl": "https://open.bigmodel.cn/api/paas/v4",
"model": "glm-5.3",
"apiKeyEnv": "ZHIPU_API_KEY"
}
+1 -1
View File
@@ -4,4 +4,4 @@
# Status
- **mood:** testing the bridge
(nothing set — fresh start)
+2 -1
View File
@@ -51,6 +51,7 @@ CREATE TABLE IF NOT EXISTS events (
CREATE INDEX IF NOT EXISTS events_window ON events (window);
BEGIN TRANSACTION;
INSERT INTO status VALUES ('mood','','testing the bridge','2026-11-11');
INSERT INTO events VALUES (1,'pc','status','s:mood','mock turn');
INSERT INTO events VALUES (2,'pc','status','s:mood','excursion declared');
INSERT INTO events VALUES (3,'pc','status','s:mood','field dropped');
COMMIT;
+2
View File
@@ -51,4 +51,6 @@ CREATE TABLE IF NOT EXISTS events (
CREATE INDEX IF NOT EXISTS events_window ON events (window);
BEGIN TRANSACTION;
INSERT INTO events VALUES (1,'pc','status','s:mood','excursion declared');
INSERT INTO events VALUES (2,'pc','status','s:mood','field dropped');
COMMIT;
+25 -9
View File
@@ -67,6 +67,11 @@ const STATUS_TOOLS = [
{ key: { type: 'string' } }),
];
const ROLL_TOOL = T('roll',
'Flip a coin: pick one of the options at random. For genuinely non-obvious choices, or in-fiction chance she herself controls (a tossed coin, a drawn straw). Randomizes choices, never outcomes — whether an attempt succeeds is the GM\'s to resolve. Commit to the result; do not re-roll.',
{ options: { type: 'array', items: { type: 'string' }, minItems: 2, description: 'the options, equal weight' } },
['options']);
const RECORD_TOOLS = [
T('records_search', 'Consult her files. Narrow terms — what this beat needs. The result is capped at 10. A miss is a miss: do not rephrase, broaden, or retry this scene.',
{ terms: { type: 'array', items: { type: 'string' }, description: 'all terms must match' } },
@@ -87,7 +92,7 @@ function recordsEnabled() {
return false;
}
}
const TOOLS = [...STATUS_TOOLS, ...(recordsEnabled() ? RECORD_TOOLS : [])];
const TOOLS = [...STATUS_TOOLS, ROLL_TOOL, ...(recordsEnabled() ? RECORD_TOOLS : [])];
// tool name → clerk argv
const DISPATCH = {
@@ -95,6 +100,7 @@ const DISPATCH = {
status_norm: (a) => ['norm', a.key, a.baseline],
status_clear: (a) => ['clear', a.key],
status_drop: (a) => ['unset', a.key],
roll: (a) => ['pick', ...a.options],
records_search: (a) => ['search', ...a.terms],
records_file: (a) => ['file', a.kind, a.label, a.detail ?? ''],
records_amend: (a) => ['amend', a.rid, a.detail],
@@ -142,8 +148,10 @@ function assembleSystem() {
+ 'Tool mode: the mechanical verbs described above — status declarations'
+ ' and records work — are available to you as function tools. Prefer the'
+ ' tools over writing the ((...)) lines; tool calls happen between prose'
+ ' beats without narrating them. The OOC channel remains for talking to'
+ ' the GM: points of order, canon questions, proposals.\n';
+ ' beats without narrating them. The roll tool is your coin flip for'
+ ' non-obvious choices — commit to what it returns. The OOC channel'
+ ' remains for talking to the GM: points of order, canon questions,'
+ ' proposals.\n';
if (!recordsEnabled()) {
sys += 'There are no records tools: this character keeps no files to consult.\n';
}
@@ -181,18 +189,26 @@ async function callModel(cfg, messages, tools) {
function mockModel(messages) {
const last = messages[messages.length - 1];
if (last.role === 'tool') {
return { role: 'assistant', content: 'Mock: the tool result is noted. *She settles back against the container, watching the light.* ((mock turn complete))' };
if (last.content.startsWith('picked:')) {
return {
role: 'assistant',
content: null,
tool_calls: [{
id: `mock-status-${messages.length}`,
type: 'function',
function: { name: 'status_set', arguments: JSON.stringify({ key: 'mood', value: 'committed to the roll' }) },
}],
};
}
return { role: 'assistant', content: 'Mock: noted. *She commits to the path the coin chose.*' };
}
return {
role: 'assistant',
content: null,
tool_calls: [{
id: `mock-${messages.length}`,
id: `mock-roll-${messages.length}`,
type: 'function',
function: {
name: 'status_set',
arguments: JSON.stringify({ key: 'mood', value: 'testing the bridge', reason: 'mock turn' }),
},
function: { name: 'roll', arguments: JSON.stringify({ options: ['press on to the lighthouse', 'go back for Dessa'] }) },
}],
};
}