@shobyde/boaz 0.0.0-stage → 0.8.2
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/LICENSE +21 -0
- package/README.md +422 -2
- package/dist/build/codes.d.ts +16 -0
- package/dist/build/codes.d.ts.map +1 -0
- package/dist/build/codes.js +72 -0
- package/dist/build/codes.js.map +1 -0
- package/dist/build/extract.d.ts +45 -0
- package/dist/build/extract.d.ts.map +1 -0
- package/dist/build/extract.js +484 -0
- package/dist/build/extract.js.map +1 -0
- package/dist/build/glob.d.ts +11 -0
- package/dist/build/glob.d.ts.map +1 -0
- package/dist/build/glob.js +88 -0
- package/dist/build/glob.js.map +1 -0
- package/dist/build/index.d.ts +7 -0
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +4 -0
- package/dist/build/index.js.map +1 -0
- package/dist/build/probes.d.ts +41 -0
- package/dist/build/probes.d.ts.map +1 -0
- package/dist/build/probes.js +134 -0
- package/dist/build/probes.js.map +1 -0
- package/dist/build/report.d.ts +11 -0
- package/dist/build/report.d.ts.map +1 -0
- package/dist/build/report.js +39 -0
- package/dist/build/report.js.map +1 -0
- package/dist/cli/audit.d.ts +15 -0
- package/dist/cli/audit.d.ts.map +1 -0
- package/dist/cli/audit.js +68 -0
- package/dist/cli/audit.js.map +1 -0
- package/dist/cli/bench.d.ts +7 -0
- package/dist/cli/bench.d.ts.map +1 -0
- package/dist/cli/bench.js +147 -0
- package/dist/cli/bench.js.map +1 -0
- package/dist/cli/harness.d.ts +45 -0
- package/dist/cli/harness.d.ts.map +1 -0
- package/dist/cli/harness.js +90 -0
- package/dist/cli/harness.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +404 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/probes.d.ts +20 -0
- package/dist/cli/probes.d.ts.map +1 -0
- package/dist/cli/probes.js +27 -0
- package/dist/cli/probes.js.map +1 -0
- package/dist/cli/skill-template.d.ts +2 -0
- package/dist/cli/skill-template.d.ts.map +1 -0
- package/dist/cli/skill-template.js +254 -0
- package/dist/cli/skill-template.js.map +1 -0
- package/dist/core/actions.d.ts +67 -0
- package/dist/core/actions.d.ts.map +1 -0
- package/dist/core/actions.js +357 -0
- package/dist/core/actions.js.map +1 -0
- package/dist/core/define.d.ts +25 -0
- package/dist/core/define.d.ts.map +1 -0
- package/dist/core/define.js +76 -0
- package/dist/core/define.js.map +1 -0
- package/dist/core/execute.d.ts +75 -0
- package/dist/core/execute.d.ts.map +1 -0
- package/dist/core/execute.js +145 -0
- package/dist/core/execute.js.map +1 -0
- package/dist/core/index.d.ts +35 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +20 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/lemmas.d.ts +32 -0
- package/dist/core/lemmas.d.ts.map +1 -0
- package/dist/core/lemmas.js +80 -0
- package/dist/core/lemmas.js.map +1 -0
- package/dist/core/lexical-engine.d.ts +18 -0
- package/dist/core/lexical-engine.d.ts.map +1 -0
- package/dist/core/lexical-engine.js +296 -0
- package/dist/core/lexical-engine.js.map +1 -0
- package/dist/core/loop.d.ts +51 -0
- package/dist/core/loop.d.ts.map +1 -0
- package/dist/core/loop.js +432 -0
- package/dist/core/loop.js.map +1 -0
- package/dist/core/mcp.d.ts +119 -0
- package/dist/core/mcp.d.ts.map +1 -0
- package/dist/core/mcp.js +253 -0
- package/dist/core/mcp.js.map +1 -0
- package/dist/core/memory.d.ts +106 -0
- package/dist/core/memory.d.ts.map +1 -0
- package/dist/core/memory.js +185 -0
- package/dist/core/memory.js.map +1 -0
- package/dist/core/plan.d.ts +83 -0
- package/dist/core/plan.d.ts.map +1 -0
- package/dist/core/plan.js +258 -0
- package/dist/core/plan.js.map +1 -0
- package/dist/core/preferences.d.ts +54 -0
- package/dist/core/preferences.d.ts.map +1 -0
- package/dist/core/preferences.js +83 -0
- package/dist/core/preferences.js.map +1 -0
- package/dist/core/prompt.d.ts +23 -0
- package/dist/core/prompt.d.ts.map +1 -0
- package/dist/core/prompt.js +76 -0
- package/dist/core/prompt.js.map +1 -0
- package/dist/core/question.d.ts +96 -0
- package/dist/core/question.d.ts.map +1 -0
- package/dist/core/question.js +501 -0
- package/dist/core/question.js.map +1 -0
- package/dist/core/registry.d.ts +33 -0
- package/dist/core/registry.d.ts.map +1 -0
- package/dist/core/registry.js +72 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/retriever.d.ts +48 -0
- package/dist/core/retriever.d.ts.map +1 -0
- package/dist/core/retriever.js +123 -0
- package/dist/core/retriever.js.map +1 -0
- package/dist/core/schema.d.ts +27 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js +231 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/skill.d.ts +105 -0
- package/dist/core/skill.d.ts.map +1 -0
- package/dist/core/skill.js +205 -0
- package/dist/core/skill.js.map +1 -0
- package/dist/core/summarise.d.ts +52 -0
- package/dist/core/summarise.d.ts.map +1 -0
- package/dist/core/summarise.js +146 -0
- package/dist/core/summarise.js.map +1 -0
- package/dist/core/tools.d.ts +21 -0
- package/dist/core/tools.d.ts.map +1 -0
- package/dist/core/tools.js +120 -0
- package/dist/core/tools.js.map +1 -0
- package/dist/core/types.d.ts +199 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +5 -0
- package/dist/core/types.js.map +1 -0
- package/dist/dom/index.d.ts +22 -0
- package/dist/dom/index.d.ts.map +1 -0
- package/dist/dom/index.js +94 -0
- package/dist/dom/index.js.map +1 -0
- package/dist/extract/index.d.ts +36 -0
- package/dist/extract/index.d.ts.map +1 -0
- package/dist/extract/index.js +86 -0
- package/dist/extract/index.js.map +1 -0
- package/dist/react/index.d.ts +52 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +131 -0
- package/dist/react/index.js.map +1 -0
- package/dist/rules/engine.d.ts +152 -0
- package/dist/rules/engine.d.ts.map +1 -0
- package/dist/rules/engine.js +364 -0
- package/dist/rules/engine.js.map +1 -0
- package/dist/rules/facts.d.ts +63 -0
- package/dist/rules/facts.d.ts.map +1 -0
- package/dist/rules/facts.js +115 -0
- package/dist/rules/facts.js.map +1 -0
- package/dist/rules/index.d.ts +10 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +5 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/knowledge.d.ts +78 -0
- package/dist/rules/knowledge.d.ts.map +1 -0
- package/dist/rules/knowledge.js +254 -0
- package/dist/rules/knowledge.js.map +1 -0
- package/dist/vite/index.d.ts +26 -0
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +112 -0
- package/dist/vite/index.js.map +1 -0
- package/package.json +108 -4
package/dist/core/mcp.js
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { analyzeQuestion } from './question.js';
|
|
2
|
+
import { planRequest, routeRequest } from './plan.js';
|
|
3
|
+
/**
|
|
4
|
+
* The protocol's tool-name pattern is `[a-zA-Z0-9_-]`, and every capability id
|
|
5
|
+
* here carries a dot (`projects.list`). Sanitising rather than renaming keeps
|
|
6
|
+
* the id as the record and the name as the wire format.
|
|
7
|
+
*/
|
|
8
|
+
export function toolName(capabilityId) {
|
|
9
|
+
return capabilityId.replace(/[^A-Za-z0-9_-]+/g, '_').slice(0, 64);
|
|
10
|
+
}
|
|
11
|
+
const EMPTY_SCHEMA = { type: 'object', properties: {}, additionalProperties: false };
|
|
12
|
+
export function toolsFromCapabilities(capabilities) {
|
|
13
|
+
return capabilities.map((capability) => {
|
|
14
|
+
const description = [capability.title, capability.description].filter(Boolean).join(': ');
|
|
15
|
+
const schema = capability.paramsSchema;
|
|
16
|
+
return {
|
|
17
|
+
name: toolName(capability.id),
|
|
18
|
+
description: description || capability.id,
|
|
19
|
+
inputSchema: schema ?? { ...EMPTY_SCHEMA },
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/** "3 items: Hobnob, Readback, Boaz" — an array is described, never stringified. */
|
|
24
|
+
function describeValue(value, depth = 0) {
|
|
25
|
+
if (value === null || value === undefined)
|
|
26
|
+
return 'nothing';
|
|
27
|
+
if (typeof value === 'string')
|
|
28
|
+
return value;
|
|
29
|
+
if (typeof value === 'number' || typeof value === 'boolean')
|
|
30
|
+
return String(value);
|
|
31
|
+
if (Array.isArray(value)) {
|
|
32
|
+
const names = value.map((entry) => {
|
|
33
|
+
if (entry && typeof entry === 'object') {
|
|
34
|
+
const record = entry;
|
|
35
|
+
const label = record.title ?? record.name ?? record.id ?? record.label;
|
|
36
|
+
if (label !== undefined)
|
|
37
|
+
return String(label);
|
|
38
|
+
}
|
|
39
|
+
return describeValue(entry, depth + 1);
|
|
40
|
+
});
|
|
41
|
+
const shown = names.slice(0, 3).join(', ');
|
|
42
|
+
return names.length > 3 ? `${shown} and ${names.length - 3} more` : shown;
|
|
43
|
+
}
|
|
44
|
+
if (depth > 0)
|
|
45
|
+
return Object.keys(value).join(', ');
|
|
46
|
+
const record = value;
|
|
47
|
+
return Object.entries(record)
|
|
48
|
+
.slice(0, 6)
|
|
49
|
+
.map(([key, entry]) => `${key}: ${describeValue(entry, depth + 1)}`)
|
|
50
|
+
.join('; ');
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A tool result a reader can use and a program can parse. The text is a
|
|
54
|
+
* sentence, because the first consumer of an MCP result is often a model that
|
|
55
|
+
* will quote it; the structure rides alongside for the deterministic caller.
|
|
56
|
+
*/
|
|
57
|
+
export function describeToolResult(title, value) {
|
|
58
|
+
if (typeof value === 'string')
|
|
59
|
+
return value;
|
|
60
|
+
if (Array.isArray(value))
|
|
61
|
+
return `${title}: ${describeValue(value)}`;
|
|
62
|
+
return `${title}: ${describeValue(value)}`;
|
|
63
|
+
}
|
|
64
|
+
function validateArgs(capability, args) {
|
|
65
|
+
const schema = capability.paramsSchema;
|
|
66
|
+
const required = schema?.required ?? [];
|
|
67
|
+
const properties = schema?.properties ?? {};
|
|
68
|
+
for (const name of required) {
|
|
69
|
+
if (!(name in args) || args[name] === undefined) {
|
|
70
|
+
const property = properties[name];
|
|
71
|
+
const allowed = property?.enum ? ` (one of: ${property.enum.join(', ')})` : '';
|
|
72
|
+
return `Tool ${toolName(capability.id)} needs the argument "${name}"${allowed}.`;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
for (const key of Object.keys(args)) {
|
|
76
|
+
if (!(key in properties)) {
|
|
77
|
+
return `Tool ${toolName(capability.id)} has no argument "${key}".`;
|
|
78
|
+
}
|
|
79
|
+
const property = properties[key];
|
|
80
|
+
if (property?.enum && !property.enum.includes(args[key])) {
|
|
81
|
+
return `"${String(args[key])}" is not one of ${property.enum.join(', ')} for "${key}".`;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
export function createToolServer(options) {
|
|
87
|
+
const tools = toolsFromCapabilities(options.capabilities);
|
|
88
|
+
const byName = new Map(tools.map((tool) => [tool.name, tool.name]));
|
|
89
|
+
const byCapability = new Map(options.capabilities.map((capability) => [toolName(capability.id), capability]));
|
|
90
|
+
const byTool = new Map(tools.map((tool) => [tool.name, tool]));
|
|
91
|
+
async function callTool(name, args = {}) {
|
|
92
|
+
const capability = byCapability.get(name);
|
|
93
|
+
const tool = byTool.get(name);
|
|
94
|
+
if (!capability || !tool) {
|
|
95
|
+
throw Object.assign(new Error(`Unknown tool: ${name}`), {
|
|
96
|
+
code: -32602,
|
|
97
|
+
data: { tools: tools.map((entry) => entry.name) },
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const problem = validateArgs(capability, args);
|
|
101
|
+
if (problem) {
|
|
102
|
+
return { content: [{ type: 'text', text: problem }], isError: true, _meta: { capabilityId: capability.id } };
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
const result = await options.run(capability.id, args);
|
|
106
|
+
return {
|
|
107
|
+
content: [{ type: 'text', text: describeToolResult(capability.title || capability.id, result) }],
|
|
108
|
+
structuredContent: result,
|
|
109
|
+
_meta: { capabilityId: capability.id },
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
114
|
+
return {
|
|
115
|
+
content: [{ type: 'text', text: `${capability.title || capability.id} failed: ${message}` }],
|
|
116
|
+
isError: true,
|
|
117
|
+
_meta: { capabilityId: capability.id },
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
async function handle(message) {
|
|
122
|
+
const id = message?.id ?? null;
|
|
123
|
+
const reply = (result) => ({ jsonrpc: '2.0', id, result });
|
|
124
|
+
const fail = (code, text, data) => ({
|
|
125
|
+
jsonrpc: '2.0',
|
|
126
|
+
id,
|
|
127
|
+
error: { code, message: text, ...(data === undefined ? {} : { data }) },
|
|
128
|
+
});
|
|
129
|
+
if (!message || message.jsonrpc !== '2.0' || typeof message.method !== 'string') {
|
|
130
|
+
return fail(-32600, 'Invalid Request');
|
|
131
|
+
}
|
|
132
|
+
// A notification has no id and gets no reply, but it still runs: the client
|
|
133
|
+
// sends `notifications/initialized` and expects the conversation to continue.
|
|
134
|
+
const notification = message.id === undefined;
|
|
135
|
+
switch (message.method) {
|
|
136
|
+
case 'initialize':
|
|
137
|
+
return reply({
|
|
138
|
+
protocolVersion: options.protocolVersion ?? '2025-06-18',
|
|
139
|
+
capabilities: { tools: { listChanged: false } },
|
|
140
|
+
serverInfo: { name: options.name, version: options.version },
|
|
141
|
+
instructions: `${tools.length} deterministic tools. No model runs behind them; every result is computed from the data this server was given.`,
|
|
142
|
+
});
|
|
143
|
+
case 'notifications/initialized':
|
|
144
|
+
case 'notifications/cancelled':
|
|
145
|
+
case 'ping':
|
|
146
|
+
return notification ? null : reply({});
|
|
147
|
+
case 'tools/list':
|
|
148
|
+
return reply({ tools });
|
|
149
|
+
case 'tools/call': {
|
|
150
|
+
const params = (message.params ?? {});
|
|
151
|
+
const name = typeof params.name === 'string' ? params.name : '';
|
|
152
|
+
// `arguments` is an object in the protocol. A caller that sends the
|
|
153
|
+
// string "{}" is not making a call with no arguments, it is sending a
|
|
154
|
+
// payload this server does not read, and silently treating it as empty
|
|
155
|
+
// is how a malformed call looks like a valid one.
|
|
156
|
+
if (params.arguments !== undefined && (params.arguments === null || typeof params.arguments !== 'object' || Array.isArray(params.arguments))) {
|
|
157
|
+
return fail(-32602, 'params.arguments must be an object');
|
|
158
|
+
}
|
|
159
|
+
const args = (params.arguments ?? {});
|
|
160
|
+
try {
|
|
161
|
+
return reply(await callTool(name, args));
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
const typed = error;
|
|
165
|
+
return fail(typed.code ?? -32603, typed.message ?? 'Tool call failed', typed.data);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
default:
|
|
169
|
+
return fail(-32601, `Method not found: ${message.method}`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
tools,
|
|
174
|
+
capabilityFor: (name) => (byName.has(name) ? byCapability.get(name).id : undefined),
|
|
175
|
+
callTool,
|
|
176
|
+
handle,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* A client over any transport: a `send` that takes one JSON-RPC message and
|
|
181
|
+
* resolves the matching response. In-process it is the server's `handle`; over
|
|
182
|
+
* stdio it is one line in, one line out. Neither path knows about the other.
|
|
183
|
+
*/
|
|
184
|
+
export function createToolClient(send) {
|
|
185
|
+
let nextId = 1;
|
|
186
|
+
async function request(method, params) {
|
|
187
|
+
const id = nextId++;
|
|
188
|
+
const response = await send({ jsonrpc: '2.0', id, method, ...(params ? { params } : {}) });
|
|
189
|
+
if (!response)
|
|
190
|
+
throw new Error(`${method}: no response`);
|
|
191
|
+
// A client that accepts someone else's reply is how a bridge mixes up two
|
|
192
|
+
// calls in flight, so the id check is part of the contract.
|
|
193
|
+
if (response.id !== id)
|
|
194
|
+
throw new Error(`${method}: response id ${String(response.id)} is not ${id}`);
|
|
195
|
+
if (response.error) {
|
|
196
|
+
throw Object.assign(new Error(response.error.message), {
|
|
197
|
+
code: response.error.code,
|
|
198
|
+
data: response.error.data,
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
return response.result;
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
initialize: async () => (await request('initialize', { protocolVersion: '2025-06-18', capabilities: {} })),
|
|
205
|
+
listTools: async () => {
|
|
206
|
+
const result = (await request('tools/list'));
|
|
207
|
+
return result.tools ?? [];
|
|
208
|
+
},
|
|
209
|
+
callTool: async (name, args = {}) => (await request('tools/call', { name, arguments: args })),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* The deterministic planner behind a tool client. One sentence becomes one
|
|
214
|
+
* call, a sentence with two requests becomes two calls in order, and a request
|
|
215
|
+
* no capability serves is declined rather than mapped onto the nearest tool.
|
|
216
|
+
*
|
|
217
|
+
* It keeps `needs` instead of ignoring it: a tool call with a missing argument
|
|
218
|
+
* is the MCP version of asking a page for a card it was never told to open.
|
|
219
|
+
*/
|
|
220
|
+
export function planToolCall(query, options) {
|
|
221
|
+
const plan = planRequest(query, options);
|
|
222
|
+
if (plan.steps.length > 0) {
|
|
223
|
+
const calls = plan.steps.map((step) => ({
|
|
224
|
+
name: toolName(step.capabilityId),
|
|
225
|
+
capabilityId: step.capabilityId,
|
|
226
|
+
args: (step.args ?? {}),
|
|
227
|
+
runnable: step.needs === 'none' && step.args !== null,
|
|
228
|
+
...(step.args === null ? { reason: 'args' } : step.needs === 'route' ? { reason: 'route' } : {}),
|
|
229
|
+
}));
|
|
230
|
+
return { calls, summary: plan.summary };
|
|
231
|
+
}
|
|
232
|
+
const routed = routeRequest(query, {
|
|
233
|
+
...options,
|
|
234
|
+
prefer: analyzeQuestion(query).questionShaped ? 'question' : 'request',
|
|
235
|
+
});
|
|
236
|
+
if (routed.declined) {
|
|
237
|
+
return { calls: [], declined: routed.declined, failed: query, summary: '' };
|
|
238
|
+
}
|
|
239
|
+
const args = (routed.args ?? {});
|
|
240
|
+
return {
|
|
241
|
+
calls: [
|
|
242
|
+
{
|
|
243
|
+
name: toolName(routed.capabilityId),
|
|
244
|
+
capabilityId: routed.capabilityId,
|
|
245
|
+
args,
|
|
246
|
+
runnable: routed.args !== null,
|
|
247
|
+
...(routed.args === null ? { reason: 'args' } : {}),
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
summary: routed.title,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
//# sourceMappingURL=mcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/core/mcp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAsC,MAAM,WAAW,CAAC;AAyE1F;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,YAAoB;IAC3C,OAAO,YAAY,CAAC,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,YAAY,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE,oBAAoB,EAAE,KAAK,EAAW,CAAC;AAE9F,MAAM,UAAU,qBAAqB,CAAC,YAAkC;IACtE,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE;QACrC,MAAM,WAAW,GAAG,CAAC,UAAU,CAAC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1F,MAAM,MAAM,GAAG,UAAU,CAAC,YAAmD,CAAC;QAC9E,OAAO;YACL,IAAI,EAAE,QAAQ,CAAC,UAA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E,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IAC9E,CAAC;IACD,MAAM,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE,CAA4B,CAAC;IAC5D,OAAO;QACL,KAAK,EAAE;YACL;gBACE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC;gBACnC,YAAY,EAAE,MAAM,CAAC,YAAY;gBACjC,IAAI;gBACJ,QAAQ,EAAE,MAAM,CAAC,IAAI,KAAK,IAAI;gBAC9B,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC7D;SACF;QACD,OAAO,EAAE,MAAM,CAAC,KAAK;KACtB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { ReferenceContext } from './question.js';
|
|
2
|
+
/**
|
|
3
|
+
* Working memory with salience (0.7.10).
|
|
4
|
+
*
|
|
5
|
+
* The rules engine keeps one turn of memory: the rule that answered, the terms
|
|
6
|
+
* that matched, and the entities that answer bound. That is enough to resolve
|
|
7
|
+
* "and?" or "its stack" one turn later. It is not enough for a conversation,
|
|
8
|
+
* because a visitor who changes subject twice and comes back expects "that
|
|
9
|
+
* project" to still mean the project, and expects "what did we cover" to name
|
|
10
|
+
* what actually happened rather than reciting the last answer.
|
|
11
|
+
*
|
|
12
|
+
* Two decisions make this measurable instead of magic:
|
|
13
|
+
*
|
|
14
|
+
* - Salience is a number, not a ranking rule. Every mention adds weight, and
|
|
15
|
+
* weight halves every `halfLife` turns. Repeating an entity is the only way
|
|
16
|
+
* to keep it: this is why a one-off mention of an unrelated project decays
|
|
17
|
+
* out while a project discussed three times stays. No model, no embeddings,
|
|
18
|
+
* and the visitor can see the arithmetic in `salient()`.
|
|
19
|
+
* - Recall is scoped by turn, never global. `context()` hands the question
|
|
20
|
+
* analyzer the most salient subject and the items the last answer listed,
|
|
21
|
+
* so a pointer resolves against what was talked about, in the order it was
|
|
22
|
+
* talked about.
|
|
23
|
+
*
|
|
24
|
+
* The ceiling this buys: salience is frequency plus recency, so a single
|
|
25
|
+
* mention of the thing the visitor actually cares about loses to a project
|
|
26
|
+
* named incidentally three times. "What we covered" is a list of subjects, not
|
|
27
|
+
* a summary of claims; the summariser (0.7.4) is a different rung for a
|
|
28
|
+
* different question.
|
|
29
|
+
*/
|
|
30
|
+
export interface MemoryTurn {
|
|
31
|
+
/** 1-based, so a trace line reads the way a person counts. */
|
|
32
|
+
turn: number;
|
|
33
|
+
text: string;
|
|
34
|
+
capabilityId: string | null;
|
|
35
|
+
/** Subject the turn was about, canonicalised against `subjects`. */
|
|
36
|
+
subject: string | null;
|
|
37
|
+
/** Every declared subject the turn named, in order of appearance. */
|
|
38
|
+
entities: string[];
|
|
39
|
+
/** Content words no subject accounted for, for "what was that about". */
|
|
40
|
+
topics: string[];
|
|
41
|
+
/** What the answer listed, in order, so an ordinal can point at it. */
|
|
42
|
+
items: string[];
|
|
43
|
+
}
|
|
44
|
+
export interface SalientEntity {
|
|
45
|
+
name: string;
|
|
46
|
+
/** Decayed weight, 0..n. Repeats accumulate; age divides. */
|
|
47
|
+
salience: number;
|
|
48
|
+
mentions: number;
|
|
49
|
+
firstTurn: number;
|
|
50
|
+
lastTurn: number;
|
|
51
|
+
}
|
|
52
|
+
export interface SalientTopic {
|
|
53
|
+
term: string;
|
|
54
|
+
salience: number;
|
|
55
|
+
lastTurn: number;
|
|
56
|
+
}
|
|
57
|
+
export interface Coverage {
|
|
58
|
+
entities: string[];
|
|
59
|
+
topics: string[];
|
|
60
|
+
/** One sentence a host can print, composed from the surviving turns. */
|
|
61
|
+
sentence: string;
|
|
62
|
+
/** True when everything in the session has decayed out of the working set. */
|
|
63
|
+
faded: boolean;
|
|
64
|
+
/** True when the session holds nothing above the salience floor. */
|
|
65
|
+
empty: boolean;
|
|
66
|
+
}
|
|
67
|
+
export interface WorkingMemoryOptions {
|
|
68
|
+
/** Values the app can name, handed to `analyzeQuestion`. */
|
|
69
|
+
subjects?: string[];
|
|
70
|
+
/** Attribute words per app, handed to `analyzeQuestion`. */
|
|
71
|
+
attributes?: Record<string, string[]>;
|
|
72
|
+
/** Turns after which a mention's weight halves. Default 2.5. */
|
|
73
|
+
halfLife?: number;
|
|
74
|
+
/** Weight below which a mention is gone. Default 0.2. */
|
|
75
|
+
minSalience?: number;
|
|
76
|
+
/** Turns kept verbatim. Default 12. */
|
|
77
|
+
limit?: number;
|
|
78
|
+
}
|
|
79
|
+
export interface ObserveOptions {
|
|
80
|
+
capabilityId?: string | null;
|
|
81
|
+
/** Entities the host knows about that the analyzer cannot see (a tool result). */
|
|
82
|
+
entities?: string[];
|
|
83
|
+
/** What the answer listed, in order. */
|
|
84
|
+
items?: string[];
|
|
85
|
+
}
|
|
86
|
+
export interface WorkingMemory {
|
|
87
|
+
readonly turns: MemoryTurn[];
|
|
88
|
+
observe(text: string, options?: ObserveOptions): MemoryTurn;
|
|
89
|
+
salient(): SalientEntity[];
|
|
90
|
+
salientTopics(): SalientTopic[];
|
|
91
|
+
context(): ReferenceContext;
|
|
92
|
+
covered(options?: {
|
|
93
|
+
limit?: number;
|
|
94
|
+
floor?: number;
|
|
95
|
+
}): Coverage;
|
|
96
|
+
reset(): void;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* True when the visitor is asking about the conversation instead of the site.
|
|
100
|
+
* A closed list on purpose: this is the same trade rung 5's synonym table
|
|
101
|
+
* makes, and the failure mode is the same, which is that a phrasing outside
|
|
102
|
+
* the list is not recognised and routes to a capability instead.
|
|
103
|
+
*/
|
|
104
|
+
export declare function isCoverageQuery(query: string): boolean;
|
|
105
|
+
export declare function createWorkingMemory(options?: WorkingMemoryOptions): WorkingMemory;
|
|
106
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts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;IACtC,gEAAgE;IAChE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,yDAAyD;IACzD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uCAAuC;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,kFAAkF;IAClF,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,wCAAwC;IACxC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,CAAC;IAC7B,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,UAAU,CAAC;IAC5D,OAAO,IAAI,aAAa,EAAE,CAAC;IAC3B,aAAa,IAAI,YAAY,EAAE,CAAC;IAChC,OAAO,IAAI,gBAAgB,CAAC;IAC5B,OAAO,CAAC,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,QAAQ,CAAC;IAChE,KAAK,IAAI,IAAI,CAAC;CACf;AAYD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAGtD;AAqCD,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,oBAAyB,GAAG,aAAa,CAiIrF"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { analyzeQuestion } from './question.js';
|
|
2
|
+
import { tokenize } from './retriever.js';
|
|
3
|
+
const COVERAGE_PATTERNS = [
|
|
4
|
+
/\bwhat (?:did|have) we (?:cover|covered|discuss|discussed|talk(?:ed)? about|go over|gone over)\b/,
|
|
5
|
+
/\bwhat have we (?:covered|discussed|been through)\b/,
|
|
6
|
+
/\bwhere were we\b/,
|
|
7
|
+
/\bwhat were we (?:talking|discussing) about\b/,
|
|
8
|
+
/\bremind me what we\b/,
|
|
9
|
+
/\brecap (?:of )?(?:this|our) (?:chat|conversation|session)\b/,
|
|
10
|
+
/\bsummari[sz]e (?:our|this) (?:conversation|chat|session)\b/,
|
|
11
|
+
];
|
|
12
|
+
/**
|
|
13
|
+
* True when the visitor is asking about the conversation instead of the site.
|
|
14
|
+
* A closed list on purpose: this is the same trade rung 5's synonym table
|
|
15
|
+
* makes, and the failure mode is the same, which is that a phrasing outside
|
|
16
|
+
* the list is not recognised and routes to a capability instead.
|
|
17
|
+
*/
|
|
18
|
+
export function isCoverageQuery(query) {
|
|
19
|
+
const text = String(query ?? '').toLowerCase();
|
|
20
|
+
return COVERAGE_PATTERNS.some((pattern) => pattern.test(text));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Words about the asking, not about the subject. `tokenize()` already drops the
|
|
24
|
+
* library's stopwords; these are the discourse words a recap should not repeat
|
|
25
|
+
* back ("tell", "about", "anything").
|
|
26
|
+
*/
|
|
27
|
+
const DISCOURSE = new Set([
|
|
28
|
+
'tell', 'about', 'cover', 'covered', 'discuss', 'discussed', 'say', 'said', 'anything',
|
|
29
|
+
'something', 'else', 'again', 'more', 'now', 'then', 'also', 'just', 'really', 'thing',
|
|
30
|
+
'things', 'know', 'show', 'give', 'list', 'use', 'used', 'using',
|
|
31
|
+
]);
|
|
32
|
+
/** Attributes ("stack", "writing") are not topics; they say what is asked. */
|
|
33
|
+
function topicWords(query, attribute, entities) {
|
|
34
|
+
const entityTokens = new Set(entities.flatMap((entity) => tokenize(entity)));
|
|
35
|
+
const attributeTokens = new Set(attribute ? tokenize(attribute) : []);
|
|
36
|
+
const words = [];
|
|
37
|
+
for (const token of tokenize(query)) {
|
|
38
|
+
if (token.length < 3)
|
|
39
|
+
continue;
|
|
40
|
+
if (DISCOURSE.has(token))
|
|
41
|
+
continue;
|
|
42
|
+
if (entityTokens.has(token))
|
|
43
|
+
continue;
|
|
44
|
+
if (attributeTokens.has(token))
|
|
45
|
+
continue;
|
|
46
|
+
if (words.includes(token))
|
|
47
|
+
continue;
|
|
48
|
+
words.push(token);
|
|
49
|
+
}
|
|
50
|
+
return words;
|
|
51
|
+
}
|
|
52
|
+
function listed(values, limit = 4) {
|
|
53
|
+
const unique = [...new Set(values.filter(Boolean))];
|
|
54
|
+
if (unique.length === 0)
|
|
55
|
+
return '';
|
|
56
|
+
if (unique.length === 1)
|
|
57
|
+
return unique[0];
|
|
58
|
+
if (unique.length <= limit)
|
|
59
|
+
return `${unique.slice(0, -1).join(', ')} and ${unique[unique.length - 1]}`;
|
|
60
|
+
return `${unique.slice(0, limit).join(', ')}, and ${unique.length - limit} more`;
|
|
61
|
+
}
|
|
62
|
+
export function createWorkingMemory(options = {}) {
|
|
63
|
+
const halfLife = options.halfLife ?? 2.5;
|
|
64
|
+
const minSalience = options.minSalience ?? 0.2;
|
|
65
|
+
const limit = options.limit ?? 12;
|
|
66
|
+
const subjects = options.subjects ?? [];
|
|
67
|
+
const attributes = options.attributes ?? {};
|
|
68
|
+
let turns = [];
|
|
69
|
+
/**
|
|
70
|
+
* Mentions are logged apart from the turns they came from, because a cap on
|
|
71
|
+
* verbatim turns must not erase what the session talked about: a recap after
|
|
72
|
+
* twenty turns would otherwise know only the last twelve.
|
|
73
|
+
*/
|
|
74
|
+
let mentions = [];
|
|
75
|
+
let topicMentions = [];
|
|
76
|
+
const now = () => (turns.length ? turns[turns.length - 1].turn : 0);
|
|
77
|
+
/** Weight of a mention `age` turns old. Exactly one at age 0. */
|
|
78
|
+
const decay = (age) => Math.pow(0.5, age / halfLife);
|
|
79
|
+
/** Every surviving entity with its decayed weight, newest turn last. */
|
|
80
|
+
function scored(floor = minSalience) {
|
|
81
|
+
const seen = new Map();
|
|
82
|
+
for (const mention of mentions) {
|
|
83
|
+
const age = now() - mention.turn;
|
|
84
|
+
{
|
|
85
|
+
const name = mention.name;
|
|
86
|
+
const current = seen.get(name);
|
|
87
|
+
const weight = decay(age);
|
|
88
|
+
if (current) {
|
|
89
|
+
current.salience += weight;
|
|
90
|
+
current.mentions += 1;
|
|
91
|
+
current.lastTurn = mention.turn;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
seen.set(name, { name, salience: weight, mentions: 1, firstTurn: mention.turn, lastTurn: mention.turn });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return [...seen.values()]
|
|
99
|
+
.filter((entity) => entity.salience >= floor)
|
|
100
|
+
.sort((a, b) => b.salience - a.salience || b.lastTurn - a.lastTurn || a.name.localeCompare(b.name));
|
|
101
|
+
}
|
|
102
|
+
function scoredTopics(floor = minSalience) {
|
|
103
|
+
const seen = new Map();
|
|
104
|
+
for (const mention of topicMentions) {
|
|
105
|
+
const age = now() - mention.turn;
|
|
106
|
+
{
|
|
107
|
+
const term = mention.term;
|
|
108
|
+
const weight = decay(age);
|
|
109
|
+
const current = seen.get(term);
|
|
110
|
+
if (current) {
|
|
111
|
+
current.salience += weight;
|
|
112
|
+
current.lastTurn = mention.turn;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
seen.set(term, { term, salience: weight, lastTurn: mention.turn });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return [...seen.values()]
|
|
120
|
+
.filter((topic) => topic.salience >= floor)
|
|
121
|
+
.sort((a, b) => b.salience - a.salience || b.lastTurn - a.lastTurn || a.term.localeCompare(b.term));
|
|
122
|
+
}
|
|
123
|
+
function observe(text, observeOptions = {}) {
|
|
124
|
+
const last = turns[turns.length - 1];
|
|
125
|
+
const small = turns.length === 0 ? undefined : { subject: scored()[0]?.name ?? null, items: last.items };
|
|
126
|
+
const analysis = analyzeQuestion(text, { subjects, attributes, context: small });
|
|
127
|
+
const named = analysis.slots.entities;
|
|
128
|
+
const extra = (observeOptions.entities ?? []).filter((entity) => !named.includes(entity));
|
|
129
|
+
const entities = [...named, ...extra];
|
|
130
|
+
const turn = (last?.turn ?? 0) + 1;
|
|
131
|
+
const record = {
|
|
132
|
+
turn,
|
|
133
|
+
text,
|
|
134
|
+
capabilityId: observeOptions.capabilityId ?? null,
|
|
135
|
+
subject: analysis.slots.subject ?? entities[0] ?? null,
|
|
136
|
+
entities,
|
|
137
|
+
topics: topicWords(text, analysis.slots.attribute, entities),
|
|
138
|
+
items: observeOptions.items ?? analysis.slots.entities,
|
|
139
|
+
};
|
|
140
|
+
mentions = [...mentions, ...entities.map((name) => ({ name, turn }))].slice(-limit * 4);
|
|
141
|
+
topicMentions = [...topicMentions, ...record.topics.map((term) => ({ term, turn }))].slice(-limit * 8);
|
|
142
|
+
turns = [...turns, record].slice(-limit);
|
|
143
|
+
return record;
|
|
144
|
+
}
|
|
145
|
+
function context() {
|
|
146
|
+
const salient = scored();
|
|
147
|
+
return {
|
|
148
|
+
subject: salient[0]?.name ?? null,
|
|
149
|
+
items: turns.length ? turns[turns.length - 1].items : [],
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function covered(coveredOptions = {}) {
|
|
153
|
+
// A recap reports the session, so it keeps what the working set has already
|
|
154
|
+
// let go: a subject named once at turn 1 is gone from `salient()` by turn 7
|
|
155
|
+
// and must still appear here, or the answer quietly rewrites history.
|
|
156
|
+
const floor = coveredOptions.floor ?? minSalience / 4;
|
|
157
|
+
const ranked = scored(floor);
|
|
158
|
+
const entities = ranked.map((entity) => entity.name);
|
|
159
|
+
const topics = scoredTopics(floor).map((topic) => topic.term);
|
|
160
|
+
// The sentence reads in the order things came up; `entities` stays ranked.
|
|
161
|
+
const names = [...ranked].sort((a, b) => a.firstTurn - b.firstTurn).slice(0, coveredOptions.limit ?? 4).map((entity) => entity.name);
|
|
162
|
+
const count = entities.length;
|
|
163
|
+
const sentence = count === 0
|
|
164
|
+
? 'Nothing yet. This is the first thing you have asked in this session.'
|
|
165
|
+
: `So far we covered ${listed(names)}${count > names.length ? `, and ${count - names.length} more` : ''}.`;
|
|
166
|
+
const faded = scored().length === 0 && (count > 0 || topics.length > 0);
|
|
167
|
+
return { entities, topics, sentence, empty: count === 0 && topics.length === 0, faded };
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
get turns() {
|
|
171
|
+
return turns;
|
|
172
|
+
},
|
|
173
|
+
observe,
|
|
174
|
+
salient: scored,
|
|
175
|
+
salientTopics: scoredTopics,
|
|
176
|
+
context,
|
|
177
|
+
covered,
|
|
178
|
+
reset() {
|
|
179
|
+
turns = [];
|
|
180
|
+
mentions = [];
|
|
181
|
+
topicMentions = [];
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../../src/core/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAuG1C,MAAM,iBAAiB,GAAa;IAClC,kGAAkG;IAClG,qDAAqD;IACrD,mBAAmB;IACnB,+CAA+C;IAC/C,uBAAuB;IACvB,8DAA8D;IAC9D,6DAA6D;CAC9D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa;IAC3C,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IAC/C,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AACjE,CAAC;AAED;;;;GAIG;AACH,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACxB,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU;IACtF,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,M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