@polycode-projects/the-mechanical-code-talker 7.0.0 → 7.1.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/package.json +1 -1
- package/src/services/chat-session.mjs +17 -9
- package/src/services/chat-voice.mjs +27 -0
- package/src/services/chat.mjs +274 -209
- package/src/services/world-teach.mjs +14 -7
- package/src/surfaces/web/chat-browser-entry.mjs +15 -4
- package/src/surfaces/web/memory-ask-browser.bundle.js +135 -135
- package/src/surfaces/web/turn-session.mjs +5 -3
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
// the cast moves in response to a sentence. That is the same trade the
|
|
34
34
|
// page's own edit mode already makes.
|
|
35
35
|
import { appendFacts, loadMemory, readFactRows } from "../adapters/memory/core.mjs";
|
|
36
|
+
import { DEFAULT_VOICE, PLAIN_VOICE, resolveChatVoice, plainSentence } from "./chat-voice.mjs";
|
|
36
37
|
import { worldProvenanceTag } from "../domain/worlds-pack.mjs";
|
|
37
38
|
import { correctMisspellings, QUESTION_LEAD_RE } from "../domain/interpret/normalize.mjs";
|
|
38
39
|
import {
|
|
@@ -105,16 +106,19 @@ function mintedIdFor(rows, noun) {
|
|
|
105
106
|
return taken ? freshObjectId(rows, noun) : noun;
|
|
106
107
|
}
|
|
107
108
|
|
|
108
|
-
|
|
109
|
+
/** What a world teach says it changed. The default voice opens with "noted — ";
|
|
110
|
+
* the plain voice states the same sentence on its own. */
|
|
111
|
+
function confirmation(triple, { thing, minted, rooms, voice = DEFAULT_VOICE }) {
|
|
112
|
+
const said = (sentence) => (voice === PLAIN_VOICE ? plainSentence(sentence) : `noted — ${sentence}`);
|
|
109
113
|
if (triple.predicate === "mgx:is-open") {
|
|
110
|
-
return `
|
|
114
|
+
return said(`the ${thing} is ${triple.object === "true" ? "open" : "closed"} now.`);
|
|
111
115
|
}
|
|
112
116
|
if (PLACEMENT_PREDICATES.has(triple.predicate)) {
|
|
113
117
|
const where = rooms.includes(triple.object) ? `in the ${triple.object}` : `with the ${triple.object}`;
|
|
114
|
-
return minted ? `
|
|
118
|
+
return minted ? said(`there's a ${thing} ${where} now.`) : said(`the ${thing} is ${where} now.`);
|
|
115
119
|
}
|
|
116
|
-
if (triple.predicate === "rdf:type") return `
|
|
117
|
-
return
|
|
120
|
+
if (triple.predicate === "rdf:type") return said(`the ${thing} is a ${triple.object} now.`);
|
|
121
|
+
return said("the world says that now.");
|
|
118
122
|
}
|
|
119
123
|
|
|
120
124
|
/**
|
|
@@ -128,10 +132,13 @@ function confirmation(triple, { thing, minted, rooms }) {
|
|
|
128
132
|
* Returns the ordinary lane answer shape — `{ text, lane, note }`, plus
|
|
129
133
|
* `miss: true` on every decline so the transcript styles it like any other
|
|
130
134
|
* honest refusal, and `taught` (the rows actually written) on a success.
|
|
135
|
+
* `voice` (chat-voice.mjs's CHAT_VOICES) picks the confirmation's wording;
|
|
136
|
+
* any other value throws.
|
|
131
137
|
*/
|
|
132
138
|
export async function worldTeachTurn(line, {
|
|
133
|
-
parseLine, planTriple, rows, state, memoryDir, world, actingSubject = "player", cache = null, graph = null,
|
|
139
|
+
parseLine, planTriple, rows, state, memoryDir, world, actingSubject = "player", cache = null, graph = null, voice: voiceOption,
|
|
134
140
|
}) {
|
|
141
|
+
const voice = resolveChatVoice(voiceOption);
|
|
135
142
|
const trimmed = String(line || "").trim();
|
|
136
143
|
if (!trimmed || !parseLine || !planTriple || !memoryDir) return null;
|
|
137
144
|
if (/\?\s*$/.test(trimmed)) return null;
|
|
@@ -201,7 +208,7 @@ export async function worldTeachTurn(line, {
|
|
|
201
208
|
|
|
202
209
|
const freshState = foldWorldState(worldActionRows(readFactRows(await loadMemory(memoryDir))));
|
|
203
210
|
const here = freshState.placements.get(actingSubject)?.object ?? null;
|
|
204
|
-
const said = confirmation(triple, { thing: triple.subject, minted: minting, rooms });
|
|
211
|
+
const said = confirmation(triple, { thing: triple.subject, minted: minting, rooms, voice });
|
|
205
212
|
const relook = here ? ` ${await worldRelook(here, { memoryDir, graph, actingSubject })}` : "";
|
|
206
213
|
return {
|
|
207
214
|
text: `${said}${relook}`,
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
// (see that module's header), so the call is harmless either way, never
|
|
39
39
|
// a load error and never a behavior change on the Node side.
|
|
40
40
|
import { vocabExampleHint } from "../../services/chat.mjs";
|
|
41
|
+
import { resolveChatVoice } from "../../services/chat-voice.mjs";
|
|
41
42
|
import { createInMemoryStore, normFactTerm, loadMemory, readFactRows, applySeedPayload, wrapRowBackend, isRowHandle } from "../../adapters/memory/core.mjs";
|
|
42
43
|
import { createHttpRowBackend, withOneRetryOnUnavailable } from "./http-row-backend.mjs";
|
|
43
44
|
import { splitSentencesPreservingPaths } from "../../services/sentences.mjs";
|
|
@@ -101,9 +102,16 @@ import { graphAsk, enginePlan } from "./engine-surface.mjs";
|
|
|
101
102
|
* backend calls through — a page never passes it; a test points it at a
|
|
102
103
|
* running row-service double instead.
|
|
103
104
|
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
105
|
+
* `voice` (optional) is "default" (the default) or "plain" (chat-voice.mjs's
|
|
106
|
+
* CHAT_VOICES). The plain voice states teach confirmations, cited facts and
|
|
107
|
+
* the greeting in plain sentences that do not name the engine, for a host
|
|
108
|
+
* page that shows the answer under its own name. Any other value throws.
|
|
109
|
+
*
|
|
110
|
+
* Returns { memoryDir, sessionId, voice, graph, codeGraph, refreshGraph, turn }.
|
|
111
|
+
* `turn(line)` resolves to { answer, end, record, plan, research, taught } and
|
|
112
|
+
* threads focus/last/planState between calls exactly as the CLI session does.
|
|
113
|
+
* `taught` is true when the turn stored or forgot a fact or a rule on the
|
|
114
|
+
* user's word; a host reads it instead of the reply's wording.
|
|
107
115
|
*
|
|
108
116
|
* The two graphs are separate on purpose. `codeGraph` is the known-empty index
|
|
109
117
|
* the turn engine reads, and `graph` is this session's memory store projected
|
|
@@ -155,8 +163,9 @@ function newsProvidersFor(config) {
|
|
|
155
163
|
export function createChatSession({
|
|
156
164
|
seedPayload = null, vocabSeeded = false, liveReference = false, onLiveLookup = null,
|
|
157
165
|
synthesisBudget = 12, digestStructures = null, awsSessionKey = null,
|
|
158
|
-
fetchImpl = (...args) => globalThis.fetch(...args),
|
|
166
|
+
fetchImpl = (...args) => globalThis.fetch(...args), voice: voiceOption,
|
|
159
167
|
} = {}) {
|
|
168
|
+
const voice = resolveChatVoice(voiceOption);
|
|
160
169
|
setDigestStructures(digestStructures || []);
|
|
161
170
|
// onOversizedRow: "drop" — a WRITE-side posture only (core.mjs's own
|
|
162
171
|
// read-side base projection always keeps every seed row regardless, so the
|
|
@@ -215,6 +224,7 @@ export function createChatSession({
|
|
|
215
224
|
buildExtraOptions: () => ({
|
|
216
225
|
liveReference: liveReferenceOn, onLiveLookup,
|
|
217
226
|
synthesisBudget: synthesisBudgetOn,
|
|
227
|
+
voice,
|
|
218
228
|
newsConfig,
|
|
219
229
|
newsProviders: registeredNewsProviders ?? defaultNewsProviders(),
|
|
220
230
|
}),
|
|
@@ -228,6 +238,7 @@ export function createChatSession({
|
|
|
228
238
|
return {
|
|
229
239
|
memoryDir,
|
|
230
240
|
sessionId,
|
|
241
|
+
voice,
|
|
231
242
|
get graph() { return memoryGraph; },
|
|
232
243
|
codeGraph,
|
|
233
244
|
refreshGraph,
|