@unblocklabs/unblock-memory 0.12.2 → 0.13.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 +19 -18
- package/dist/src/analysis.js +1 -1
- package/dist/src/cluster-review.d.ts +2 -0
- package/dist/src/cluster-review.js +3 -3
- package/dist/src/config.d.ts +9 -6
- package/dist/src/config.js +31 -20
- package/dist/src/curation.d.ts +1 -1
- package/dist/src/decision-client.d.ts +39 -0
- package/dist/src/decision-client.js +74 -0
- package/dist/src/{typesafe.d.ts → decision-ranking.d.ts} +15 -18
- package/dist/src/decision-ranking.js +154 -0
- package/dist/src/{typesafe-review.d.ts → decision-review.d.ts} +13 -9
- package/dist/src/decision-review.js +192 -0
- package/dist/src/diagnostics.d.ts +5 -5
- package/dist/src/emotion-baselines.d.ts +28 -3
- package/dist/src/emotion-baselines.js +309 -113
- package/dist/src/evidence-review.d.ts +22 -8
- package/dist/src/evidence-review.js +4 -4
- package/dist/src/extraction-chunk.d.ts +3 -0
- package/dist/src/extraction-chunk.js +23 -5
- package/dist/src/extraction-model.d.ts +2 -0
- package/dist/src/extraction-model.js +73 -48
- package/dist/src/extraction-runtime.d.ts +3 -1
- package/dist/src/extraction-runtime.js +43 -16
- package/dist/src/extraction-source.d.ts +1 -1
- package/dist/src/extraction-source.js +19 -11
- package/dist/src/extraction-store.d.ts +28 -3
- package/dist/src/extraction-store.js +145 -23
- package/dist/src/extraction-worker.d.ts +1 -0
- package/dist/src/extraction-worker.js +246 -93
- package/dist/src/inside-out-runtime.js +41 -29
- package/dist/src/inside-out-store.d.ts +2 -2
- package/dist/src/inside-out-store.js +110 -69
- package/dist/src/inside-out.d.ts +10 -9
- package/dist/src/inside-out.js +190 -105
- package/dist/src/manager.d.ts +22 -9
- package/dist/src/manager.js +275 -169
- package/dist/src/memory-search.d.ts +4 -2
- package/dist/src/memory-search.js +5 -5
- package/dist/src/memory-whisperer.d.ts +1 -1
- package/dist/src/memory-whisperer.js +189 -127
- package/dist/src/my-turn.d.ts +1 -1
- package/dist/src/my-turn.js +87 -68
- package/dist/src/people-background.d.ts +4 -0
- package/dist/src/people-background.js +29 -6
- package/dist/src/people-dossier-review.d.ts +20 -8
- package/dist/src/people-dossier-review.js +11 -8
- package/dist/src/people-hooks.js +127 -22
- package/dist/src/people-learning-cron.d.ts +1 -1
- package/dist/src/people-learning-cron.js +106 -57
- package/dist/src/people-learning-inventory.d.ts +1 -0
- package/dist/src/people-learning-inventory.js +281 -171
- package/dist/src/people-learning-prompt.js +1 -1
- package/dist/src/people-learning-runtime.d.ts +1 -1
- package/dist/src/people-learning-runtime.js +423 -204
- package/dist/src/people-learning-store.d.ts +27 -4
- package/dist/src/people-learning-store.js +312 -96
- package/dist/src/people-primer-tool.js +8 -6
- package/dist/src/people-primer.d.ts +3 -1
- package/dist/src/people-primer.js +61 -44
- package/dist/src/people-store.d.ts +18 -21
- package/dist/src/people-store.js +186 -63
- package/dist/src/people-tools.js +136 -92
- package/dist/src/plugin.js +16 -16
- package/dist/src/quality-audit.d.ts +2 -0
- package/dist/src/quality-audit.js +8 -7
- package/dist/src/query-generator.d.ts +1 -1
- package/dist/src/query-generator.js +15 -8
- package/dist/src/response-audit.d.ts +1 -1
- package/dist/src/response-audit.js +76 -43
- package/dist/src/response-episodes.d.ts +1 -1
- package/dist/src/response-episodes.js +12 -17
- package/dist/src/response-judge.d.ts +151 -145
- package/dist/src/response-judge.js +535 -204
- package/dist/src/response-reviews.d.ts +29 -1
- package/dist/src/response-reviews.js +110 -13
- package/dist/src/response-runtime.js +8 -8
- package/dist/src/response-stages.d.ts +50 -53
- package/dist/src/response-stages.js +10 -4
- package/dist/src/response-store.d.ts +7 -6
- package/dist/src/response-store.js +332 -210
- package/dist/src/response-text.d.ts +2 -0
- package/dist/src/response-text.js +182 -36
- package/dist/src/review-tools.d.ts +8 -2
- package/dist/src/review-tools.js +18 -18
- package/dist/src/runtime.d.ts +7 -4
- package/dist/src/runtime.js +624 -98
- package/dist/src/safety-whisperer.d.ts +2 -2
- package/dist/src/safety-whisperer.js +88 -71
- package/dist/src/session-sync.d.ts +3 -1
- package/dist/src/session-sync.js +200 -95
- package/dist/src/skill-whisperer.d.ts +1 -1
- package/dist/src/skill-whisperer.js +52 -30
- package/dist/src/training-gate.d.ts +8 -21
- package/dist/src/training-gate.js +32 -35
- package/dist/src/training-judge.d.ts +9 -16
- package/dist/src/training-judge.js +5 -5
- package/dist/src/training-queries.d.ts +13 -8
- package/dist/src/training-queries.js +370 -228
- package/dist/src/training-retrieval.d.ts +14 -24
- package/dist/src/training-retrieval.js +182 -136
- package/dist/src/training-runtime.d.ts +3 -0
- package/dist/src/training-runtime.js +76 -18
- package/dist/src/training-store.d.ts +18 -3
- package/dist/src/training-store.js +138 -50
- package/dist/src/training.js +8 -11
- package/dist/src/whisperer-context.d.ts +14 -0
- package/dist/src/whisperer-context.js +22 -1
- package/docs/configuration.md +76 -63
- package/docs/extraction.md +9 -7
- package/docs/memory-training.md +7 -6
- package/docs/people-learning.md +2 -2
- package/docs/peoplesql.md +6 -6
- package/docs/response-audit.md +10 -8
- package/docs/retrieval.md +40 -37
- package/openclaw.plugin.json +40 -26
- package/package.json +3 -2
- package/skills/memory-curator/SKILL.md +1 -1
- package/skills/people-whisperer/SKILL.md +1 -1
- package/dist/src/typesafe-client.d.ts +0 -30
- package/dist/src/typesafe-client.js +0 -92
- package/dist/src/typesafe-review.js +0 -154
- package/dist/src/typesafe.js +0 -147
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { setImmediate } from "node:timers/promises";
|
|
1
2
|
import { abortable } from "./abortable.js";
|
|
2
|
-
import {
|
|
3
|
+
import { decisionModelScope, resolveDecisionCredential, DEFAULT_DECISION_MODEL } from "./decision-client.js";
|
|
3
4
|
import { RESPONSE_EXTRACTOR_VERSION, ResponseTranscriptReader } from "./response-episodes.js";
|
|
4
|
-
import {
|
|
5
|
+
import { responseRubricVersion, RESPONSE_STAGE_VERSIONS, judgeMemoryOpportunity, } from "./response-judge.js";
|
|
5
6
|
import { ResponseAuditStore } from "./response-store.js";
|
|
6
7
|
import { responseMemoryCandidates } from "./response-memory.js";
|
|
7
8
|
import { assessResponseStages } from "./response-stages.js";
|
|
8
9
|
import { ResponsePeople } from "./response-identity.js";
|
|
9
10
|
import { jsonHash } from "./json-hash.js";
|
|
10
|
-
export function responseCohort(config) {
|
|
11
|
-
return
|
|
11
|
+
export function responseCohort(config, model = DEFAULT_DECISION_MODEL, endpoint) {
|
|
12
|
+
return responseRubricVersion(model, endpoint) + ":" + jsonHash({
|
|
12
13
|
extractor: RESPONSE_EXTRACTOR_VERSION, historyMessages: config.historyMessages,
|
|
13
14
|
stages: RESPONSE_STAGE_VERSIONS,
|
|
14
15
|
sentimentEnabled: config.sentimentEnabled,
|
|
@@ -18,20 +19,20 @@ export function responseCohort(config) {
|
|
|
18
19
|
/** All inference is outside memory's mutation queue and outside transcript DB transactions. */
|
|
19
20
|
export async function auditResponses(options) {
|
|
20
21
|
const { config, agentId } = options;
|
|
21
|
-
if (!config.responseAudit.enabled || !config.
|
|
22
|
+
if (!config.responseAudit.enabled || !config.decisionModel.enabled)
|
|
22
23
|
return { status: "disabled" };
|
|
23
24
|
const signal = AbortSignal.any([AbortSignal.timeout(120_000), ...(options.signal ? [options.signal] : [])]);
|
|
24
|
-
const cohort = responseCohort(config.responseAudit);
|
|
25
|
+
const cohort = responseCohort(config.responseAudit, config.decisionModel.model, config.decisionModel.endpoint);
|
|
25
26
|
let key;
|
|
26
27
|
if (!options.dryRun) {
|
|
27
28
|
try {
|
|
28
|
-
key = await abortable(
|
|
29
|
+
key = await abortable(resolveDecisionCredential(config.decisionModel), signal);
|
|
29
30
|
}
|
|
30
31
|
catch {
|
|
31
32
|
return { status: "unavailable", reason: "Credentials unavailable or audit cancelled" };
|
|
32
33
|
}
|
|
33
34
|
if (!key)
|
|
34
|
-
return { status: "unavailable", reason: "
|
|
35
|
+
return { status: "unavailable", reason: "Decision model API key not configured" };
|
|
35
36
|
}
|
|
36
37
|
let reader, store, lease;
|
|
37
38
|
let people;
|
|
@@ -62,7 +63,7 @@ export async function auditResponses(options) {
|
|
|
62
63
|
coverage.sessionLimitReached = sessions.length > 100;
|
|
63
64
|
let stoppedForBudget = false;
|
|
64
65
|
for (const session of sessions.slice(0, 100)) {
|
|
65
|
-
await
|
|
66
|
+
await setImmediate();
|
|
66
67
|
signal.throwIfAborted();
|
|
67
68
|
coverage.sessions++;
|
|
68
69
|
const checkpoint = store?.checkpoint(cohort, session);
|
|
@@ -85,16 +86,14 @@ export async function auditResponses(options) {
|
|
|
85
86
|
coverage.unchangedSessions++;
|
|
86
87
|
coverage.cachedOrBackoff += work?.total ?? 0;
|
|
87
88
|
if (checkpoint)
|
|
88
|
-
|
|
89
|
-
coverage[key] += checkpoint.coverage[key];
|
|
89
|
+
addCoverage(coverage, checkpoint.coverage);
|
|
90
90
|
store?.advance(cohort, session);
|
|
91
91
|
continue;
|
|
92
92
|
}
|
|
93
93
|
coverage.extractedSessions++;
|
|
94
94
|
if (tracked.has(session))
|
|
95
95
|
coverage.reconciledSessions++;
|
|
96
|
-
|
|
97
|
-
coverage[key] += snapshot.coverage[key];
|
|
96
|
+
addCoverage(coverage, snapshot.coverage);
|
|
98
97
|
const episodes = snapshot.episodes.filter(e => e.timestamp >= since);
|
|
99
98
|
coverage.outsideLookback += snapshot.episodes.length - episodes.length;
|
|
100
99
|
store?.observe(cohort, session, snapshot.episodes);
|
|
@@ -113,47 +112,47 @@ export async function auditResponses(options) {
|
|
|
113
112
|
continue;
|
|
114
113
|
}
|
|
115
114
|
coverage.attempted++;
|
|
115
|
+
const existing = store.memoryRetryResult(cohort, e);
|
|
116
116
|
store.attempted(cohort, e, Date.now());
|
|
117
117
|
try {
|
|
118
|
-
const params = {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
e.id, e.session, e.senderId, e.request, e.answer, e.feedback, candidates,
|
|
127
|
-
[...config.responseAudit.memoryCorpora].sort()]);
|
|
128
|
-
let judged = store.stage(cohort, e, "memory", memoryKey);
|
|
129
|
-
if (judged)
|
|
130
|
-
coverage.stageCacheHits++;
|
|
131
|
-
else {
|
|
132
|
-
store.stageBegin([memoryKey], Date.now());
|
|
133
|
-
coverage.stageAttempts++;
|
|
134
|
-
judged = await abortable(judgeMemoryOpportunity(e, candidates, params), signal);
|
|
135
|
-
store.stageSave(memoryKey, judged, Date.now());
|
|
136
|
-
}
|
|
137
|
-
memory = { status: "checked", candidates: judged };
|
|
118
|
+
const params = {
|
|
119
|
+
apiKey: key, endpoint: config.decisionModel.endpoint, model: config.decisionModel.model,
|
|
120
|
+
timeoutMs: config.decisionModel.timeoutMs, signal,
|
|
121
|
+
};
|
|
122
|
+
const result = existing
|
|
123
|
+
? {
|
|
124
|
+
...existing,
|
|
125
|
+
memory: await assessMemoryOpportunity(store, cohort, e, existing.feedback, options, params, coverage),
|
|
138
126
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
127
|
+
: await (async () => {
|
|
128
|
+
const judgment = await abortable(assessResponseStages(store, cohort, e, params, config.responseAudit.sentimentEnabled, coverage), signal);
|
|
129
|
+
const memory = await assessMemoryOpportunity(store, cohort, e, judgment.feedback, options, params, coverage);
|
|
130
|
+
return {
|
|
131
|
+
...judgment,
|
|
132
|
+
human: people.resolve(e),
|
|
133
|
+
references: references(e),
|
|
134
|
+
agentModel: e.model,
|
|
135
|
+
contextLimited: e.contextLimited,
|
|
136
|
+
memorySearchCalls: e.memorySearchCalls,
|
|
137
|
+
memory,
|
|
138
|
+
};
|
|
139
|
+
})();
|
|
143
140
|
signal.throwIfAborted();
|
|
144
141
|
const fresh = reader.read(session, config.responseAudit, snapshot.revision);
|
|
145
|
-
if (!fresh || !("unchanged" in fresh) && !fresh.episodes.some(candidate => candidate.id === e.id && candidate.inputHash === e.inputHash)) {
|
|
142
|
+
if (!fresh || (!("unchanged" in fresh) && !fresh.episodes.some(candidate => candidate.id === e.id && candidate.inputHash === e.inputHash))) {
|
|
146
143
|
coverage.stale++;
|
|
147
144
|
store.stale(cohort, e);
|
|
148
|
-
if (fresh !== undefined
|
|
145
|
+
if (fresh !== undefined) {
|
|
149
146
|
store.observe(cohort, session, fresh?.episodes ?? []);
|
|
150
147
|
store.checkpointForget(cohort, session);
|
|
151
148
|
}
|
|
152
149
|
break;
|
|
153
150
|
}
|
|
154
|
-
store.save(cohort, e,
|
|
155
|
-
|
|
156
|
-
|
|
151
|
+
store.save(cohort, e, result, Date.now());
|
|
152
|
+
if (existing && result.memory.status === "unavailable")
|
|
153
|
+
coverage.failed++;
|
|
154
|
+
else
|
|
155
|
+
coverage.evaluated++;
|
|
157
156
|
}
|
|
158
157
|
catch {
|
|
159
158
|
coverage.failed++;
|
|
@@ -162,7 +161,7 @@ export async function auditResponses(options) {
|
|
|
162
161
|
}
|
|
163
162
|
}
|
|
164
163
|
// Let stop/cancellation handlers run between bounded synchronous session reads.
|
|
165
|
-
await
|
|
164
|
+
await setImmediate();
|
|
166
165
|
store?.advance(cohort, session);
|
|
167
166
|
if (coverage.attempted >= config.responseAudit.maxEpisodes && session !== sessions.at(-1)) {
|
|
168
167
|
stoppedForBudget = true;
|
|
@@ -188,6 +187,40 @@ export async function auditResponses(options) {
|
|
|
188
187
|
people?.close();
|
|
189
188
|
}
|
|
190
189
|
}
|
|
190
|
+
function addCoverage(target, delta) {
|
|
191
|
+
for (const key of Object.keys(delta))
|
|
192
|
+
target[key] += delta[key];
|
|
193
|
+
}
|
|
194
|
+
async function assessMemoryOpportunity(store, cohort, e, feedback, options, params, usage) {
|
|
195
|
+
if (feedback.memoryGap.noul < 0.8 || !options.config.responseAudit.memoryCorpora.length) {
|
|
196
|
+
return { status: "not_requested", candidates: [] };
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
const approved = options.sources.filter(s => options.config.responseAudit.memoryCorpora.includes(s.corpus));
|
|
200
|
+
const candidates = responseMemoryCandidates(options.indexPath, approved, e);
|
|
201
|
+
const memoryKey = jsonHash([
|
|
202
|
+
decisionModelScope(options.config.decisionModel.model, options.config.decisionModel.endpoint),
|
|
203
|
+
RESPONSE_STAGE_VERSIONS.memory,
|
|
204
|
+
e.id, e.session, e.senderId, e.request, e.answer, e.feedback, candidates,
|
|
205
|
+
[...options.config.responseAudit.memoryCorpora].sort(),
|
|
206
|
+
]);
|
|
207
|
+
let judged = store.stage(cohort, e, "memory", memoryKey, candidates);
|
|
208
|
+
if (judged)
|
|
209
|
+
usage.stageCacheHits++;
|
|
210
|
+
else {
|
|
211
|
+
store.stageBegin([memoryKey], Date.now());
|
|
212
|
+
usage.stageAttempts++;
|
|
213
|
+
judged = await abortable(judgeMemoryOpportunity(e, candidates, params), params.signal);
|
|
214
|
+
store.stageSave(memoryKey, judged, Date.now());
|
|
215
|
+
}
|
|
216
|
+
return { status: "checked", candidates: judged };
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
if (params.signal.aborted)
|
|
220
|
+
throw new Error("Audit cancelled");
|
|
221
|
+
return { status: "unavailable", candidates: [] };
|
|
222
|
+
}
|
|
223
|
+
}
|
|
191
224
|
function references(e) {
|
|
192
225
|
return { sessionId: e.session.sessionId, request: e.request.map(m => m.seq), answer: e.answer.map(m => m.seq),
|
|
193
226
|
feedback: e.feedback.map(m => m.seq), followup: e.followup.messages.map(m => m.seq), inputHash: e.inputHash };
|
|
@@ -4,7 +4,7 @@ import { messageText } from "./whisperer-context.js";
|
|
|
4
4
|
import { responseUserText } from "./response-text.js";
|
|
5
5
|
import { jsonHash } from "./json-hash.js";
|
|
6
6
|
import { record } from "./guards.js";
|
|
7
|
-
export const RESPONSE_EXTRACTOR_VERSION =
|
|
7
|
+
export const RESPONSE_EXTRACTOR_VERSION = 7;
|
|
8
8
|
const MAX_EVENTS = 2000, MAX_SESSION_BYTES = 2_000_000, MAX_EPISODE_CHARS = 24_000;
|
|
9
9
|
/** Never deduce human identity from text or the user role alone. */
|
|
10
10
|
export function responseEpisodes(session, rows, config) {
|
|
@@ -50,6 +50,7 @@ export function responseEpisodes(session, rows, config) {
|
|
|
50
50
|
current = undefined;
|
|
51
51
|
};
|
|
52
52
|
const boundary = () => { closeFollowup(false); finish(false); history = []; historyDropped = false; pending = []; };
|
|
53
|
+
const filterOut = () => { coverage.filteredEvents++; boundary(); };
|
|
53
54
|
const remember = (text) => {
|
|
54
55
|
history.push(text);
|
|
55
56
|
if (history.length > config.historyMessages) {
|
|
@@ -63,8 +64,7 @@ export function responseEpisodes(session, rows, config) {
|
|
|
63
64
|
e = record(JSON.parse(row.eventJson));
|
|
64
65
|
}
|
|
65
66
|
catch {
|
|
66
|
-
|
|
67
|
-
boundary();
|
|
67
|
+
filterOut();
|
|
68
68
|
continue;
|
|
69
69
|
}
|
|
70
70
|
if (e?.type !== "message") {
|
|
@@ -87,15 +87,13 @@ export function responseEpisodes(session, rows, config) {
|
|
|
87
87
|
if (m.provenance !== undefined || !human ||
|
|
88
88
|
typeof senderId !== "string" || !config.senderIds.includes(senderId) ||
|
|
89
89
|
transport?.channel !== "slack" || transport.conversationRef !== session.conversationId) {
|
|
90
|
-
|
|
91
|
-
boundary();
|
|
90
|
+
filterOut();
|
|
92
91
|
continue;
|
|
93
92
|
}
|
|
94
93
|
const raw = typeof meta?.upstreamUserText === "string" ? meta.upstreamUserText : messageText(m)?.text;
|
|
95
94
|
const visible = raw ? responseUserText(raw, senderId) : undefined;
|
|
96
95
|
if (!visible) {
|
|
97
|
-
|
|
98
|
-
boundary();
|
|
96
|
+
filterOut();
|
|
99
97
|
continue;
|
|
100
98
|
}
|
|
101
99
|
const thread = typeof transport.threadId === "string" ? transport.threadId : "";
|
|
@@ -116,20 +114,21 @@ export function responseEpisodes(session, rows, config) {
|
|
|
116
114
|
continue;
|
|
117
115
|
}
|
|
118
116
|
if (m.role !== "assistant") {
|
|
119
|
-
|
|
120
|
-
boundary();
|
|
117
|
+
filterOut();
|
|
121
118
|
continue;
|
|
122
119
|
}
|
|
123
120
|
if (m.provenance !== undefined || meta?.turnTainted === true) {
|
|
124
|
-
|
|
125
|
-
boundary();
|
|
121
|
+
filterOut();
|
|
126
122
|
continue;
|
|
127
123
|
}
|
|
128
124
|
if (m.provider === "openclaw" && (m.model === "delivery-mirror" || m.model === "gateway-injected")) {
|
|
129
125
|
// Preserve only preceding clean assistant evidence, never the synthetic notice.
|
|
130
126
|
// This is not a completed response and cannot enter the original quality grade.
|
|
131
127
|
closeFollowup(true, true);
|
|
132
|
-
|
|
128
|
+
filterOut();
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (m.stopReason === "error" || m.stopReason === "aborted") {
|
|
133
132
|
boundary();
|
|
134
133
|
continue;
|
|
135
134
|
}
|
|
@@ -144,10 +143,6 @@ export function responseEpisodes(session, rows, config) {
|
|
|
144
143
|
}
|
|
145
144
|
if (!current)
|
|
146
145
|
continue;
|
|
147
|
-
if (meta?.turnTainted === true || m.stopReason === "error" || m.stopReason === "aborted") {
|
|
148
|
-
boundary();
|
|
149
|
-
continue;
|
|
150
|
-
}
|
|
151
146
|
if (Array.isArray(m.content)) {
|
|
152
147
|
current.memorySearchCalls += m.content.filter(p => {
|
|
153
148
|
const block = record(p);
|
|
@@ -162,7 +157,7 @@ export function responseEpisodes(session, rows, config) {
|
|
|
162
157
|
remember(item);
|
|
163
158
|
current.model = typeof m.model === "string" ? m.model : "unknown";
|
|
164
159
|
current.timestamp = row.createdAt;
|
|
165
|
-
current.final
|
|
160
|
+
current.final ||= meta?.runTerminal === true || (m.stopReason === "stop" && m.channel !== "commentary");
|
|
166
161
|
}
|
|
167
162
|
if (current?.final)
|
|
168
163
|
closeFollowup(true);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Type, type Static } from "typebox";
|
|
2
2
|
import type { ResponseEpisode } from "./response-episodes.js";
|
|
3
|
-
export declare
|
|
3
|
+
export declare function responseRubricVersion(model?: string, endpoint?: string): string;
|
|
4
4
|
export declare const RESPONSE_STAGE_VERSIONS: {
|
|
5
5
|
readonly quality: "quality-v9";
|
|
6
6
|
readonly feedback: "feedback-v9";
|
|
@@ -8,73 +8,78 @@ export declare const RESPONSE_STAGE_VERSIONS: {
|
|
|
8
8
|
readonly retrospective: "retrospective-v9";
|
|
9
9
|
readonly memory: "memory-v2-isolated";
|
|
10
10
|
};
|
|
11
|
+
export type ResponseJudgeParams = {
|
|
12
|
+
apiKey: string;
|
|
13
|
+
endpoint?: string;
|
|
14
|
+
model?: string;
|
|
15
|
+
timeoutMs: number;
|
|
16
|
+
signal: AbortSignal;
|
|
17
|
+
};
|
|
11
18
|
declare const qualitySchema: Type.TObject<{
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
[k: string]: Type.TNumber;
|
|
19
|
-
}>;
|
|
20
|
-
}>;
|
|
21
|
-
assessability: Type.TObject<{
|
|
22
|
-
type: Type.TLiteral<"choice">;
|
|
23
|
-
choice: Type.TEnum<("assessable" | "not_assessable")[]>;
|
|
24
|
-
confidence: Type.TNumber;
|
|
25
|
-
probabilities: Type.TObject<{
|
|
26
|
-
[k: string]: Type.TNumber;
|
|
27
|
-
}>;
|
|
19
|
+
taskType: Type.TObject<{
|
|
20
|
+
type: Type.TLiteral<"choice">;
|
|
21
|
+
choice: Type.TEnum<("question" | "action" | "other" | "artifact" | "discussion")[]>;
|
|
22
|
+
confidence: Type.TNumber;
|
|
23
|
+
probabilities: Type.TObject<{
|
|
24
|
+
[k: string]: Type.TNumber;
|
|
28
25
|
}>;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
}>;
|
|
27
|
+
assessability: Type.TObject<{
|
|
28
|
+
type: Type.TLiteral<"choice">;
|
|
29
|
+
choice: Type.TEnum<("assessable" | "not_assessable")[]>;
|
|
30
|
+
confidence: Type.TNumber;
|
|
31
|
+
probabilities: Type.TObject<{
|
|
32
|
+
[k: string]: Type.TNumber;
|
|
36
33
|
}>;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
}>;
|
|
35
|
+
fitAssessability: Type.TObject<{
|
|
36
|
+
type: Type.TLiteral<"choice">;
|
|
37
|
+
choice: Type.TEnum<("assessable" | "not_assessable")[]>;
|
|
38
|
+
confidence: Type.TNumber;
|
|
39
|
+
probabilities: Type.TObject<{
|
|
40
|
+
[k: string]: Type.TNumber;
|
|
40
41
|
}>;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
}>;
|
|
43
|
+
underdelivery: Type.TObject<{
|
|
44
|
+
type: Type.TLiteral<"noul">;
|
|
45
|
+
noul: Type.TNumber;
|
|
46
|
+
}>;
|
|
47
|
+
failureReason: Type.TObject<{
|
|
48
|
+
type: Type.TLiteral<"choice">;
|
|
49
|
+
choice: Type.TEnum<("none_or_unclear" | "missing_requested_work" | "wrong_deliverable" | "missed_constraint" | "insufficient_answer_depth" | "unnecessary_deferral")[]>;
|
|
50
|
+
confidence: Type.TNumber;
|
|
51
|
+
probabilities: Type.TObject<{
|
|
52
|
+
[k: string]: Type.TNumber;
|
|
48
53
|
}>;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
}>;
|
|
55
|
+
fulfillment: Type.TObject<{
|
|
56
|
+
type: Type.TLiteral<"score">;
|
|
57
|
+
score: Type.TNumber;
|
|
58
|
+
confidence: Type.TNumber;
|
|
59
|
+
probabilities: Type.TObject<{
|
|
60
|
+
"0": Type.TNumber;
|
|
61
|
+
"1": Type.TNumber;
|
|
62
|
+
"2": Type.TNumber;
|
|
63
|
+
"3": Type.TNumber;
|
|
59
64
|
}>;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
}>;
|
|
66
|
+
deliverableFit: Type.TObject<{
|
|
67
|
+
type: Type.TLiteral<"score">;
|
|
68
|
+
score: Type.TNumber;
|
|
69
|
+
confidence: Type.TNumber;
|
|
70
|
+
probabilities: Type.TObject<{
|
|
71
|
+
"0": Type.TNumber;
|
|
72
|
+
"1": Type.TNumber;
|
|
73
|
+
"2": Type.TNumber;
|
|
74
|
+
"3": Type.TNumber;
|
|
70
75
|
}>;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
}>;
|
|
77
|
+
consistency: Type.TObject<{
|
|
78
|
+
type: Type.TLiteral<"choice">;
|
|
79
|
+
choice: Type.TEnum<("contradicted" | "not_assessable" | "consistent")[]>;
|
|
80
|
+
confidence: Type.TNumber;
|
|
81
|
+
probabilities: Type.TObject<{
|
|
82
|
+
[k: string]: Type.TNumber;
|
|
78
83
|
}>;
|
|
79
84
|
}>;
|
|
80
85
|
}>;
|
|
@@ -108,114 +113,115 @@ declare const sentimentSchema: Type.TObject<{
|
|
|
108
113
|
}>;
|
|
109
114
|
}>;
|
|
110
115
|
declare const feedbackSchema: Type.TObject<{
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
[k: string]: Type.TNumber;
|
|
118
|
-
}>;
|
|
119
|
-
}>;
|
|
120
|
-
target: Type.TObject<{
|
|
121
|
-
type: Type.TLiteral<"choice">;
|
|
122
|
-
choice: Type.TEnum<("delivery" | "mixed" | "unclear" | "current_answer" | "earlier_behavior" | "proactive_action" | "external" | "new_work")[]>;
|
|
123
|
-
confidence: Type.TNumber;
|
|
124
|
-
probabilities: Type.TObject<{
|
|
125
|
-
[k: string]: Type.TNumber;
|
|
126
|
-
}>;
|
|
116
|
+
feedbackType: Type.TObject<{
|
|
117
|
+
type: Type.TLiteral<"choice">;
|
|
118
|
+
choice: Type.TEnum<("mixed" | "unrelated" | "unclear" | "acceptance" | "correction" | "continuation")[]>;
|
|
119
|
+
confidence: Type.TNumber;
|
|
120
|
+
probabilities: Type.TObject<{
|
|
121
|
+
[k: string]: Type.TNumber;
|
|
127
122
|
}>;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
123
|
+
}>;
|
|
124
|
+
target: Type.TObject<{
|
|
125
|
+
type: Type.TLiteral<"choice">;
|
|
126
|
+
choice: Type.TEnum<("delivery" | "mixed" | "unclear" | "current_answer" | "earlier_behavior" | "proactive_action" | "external" | "new_work")[]>;
|
|
127
|
+
confidence: Type.TNumber;
|
|
128
|
+
probabilities: Type.TObject<{
|
|
129
|
+
[k: string]: Type.TNumber;
|
|
131
130
|
}>;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
131
|
+
}>;
|
|
132
|
+
avoidableRework: Type.TObject<{
|
|
133
|
+
type: Type.TLiteral<"noul">;
|
|
134
|
+
noul: Type.TNumber;
|
|
135
|
+
}>;
|
|
136
|
+
repeatedConstraint: Type.TObject<{
|
|
137
|
+
type: Type.TLiteral<"noul">;
|
|
138
|
+
noul: Type.TNumber;
|
|
139
|
+
}>;
|
|
140
|
+
memoryGap: Type.TObject<{
|
|
141
|
+
type: Type.TLiteral<"noul">;
|
|
142
|
+
noul: Type.TNumber;
|
|
143
|
+
}>;
|
|
144
|
+
}>;
|
|
145
|
+
declare const retrospectiveSchema: Type.TObject<{
|
|
146
|
+
correction: Type.TObject<{
|
|
147
|
+
type: Type.TLiteral<"noul">;
|
|
148
|
+
noul: Type.TNumber;
|
|
149
|
+
}>;
|
|
150
|
+
deliveryAdmission: Type.TObject<{
|
|
151
|
+
type: Type.TLiteral<"noul">;
|
|
152
|
+
noul: Type.TNumber;
|
|
153
|
+
}>;
|
|
154
|
+
regression: Type.TObject<{
|
|
155
|
+
type: Type.TLiteral<"noul">;
|
|
156
|
+
noul: Type.TNumber;
|
|
157
|
+
}>;
|
|
158
|
+
scopeClarification: Type.TObject<{
|
|
159
|
+
type: Type.TLiteral<"noul">;
|
|
160
|
+
noul: Type.TNumber;
|
|
161
|
+
}>;
|
|
162
|
+
outcome: Type.TObject<{
|
|
163
|
+
type: Type.TLiteral<"choice">;
|
|
164
|
+
choice: Type.TEnum<("unknown" | "reported_shortfall" | "acknowledged_success")[]>;
|
|
165
|
+
confidence: Type.TNumber;
|
|
166
|
+
probabilities: Type.TObject<{
|
|
167
|
+
[k: string]: Type.TNumber;
|
|
135
168
|
}>;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
169
|
+
}>;
|
|
170
|
+
reason: Type.TObject<{
|
|
171
|
+
type: Type.TLiteral<"choice">;
|
|
172
|
+
choice: Type.TEnum<("none_or_unclear" | "missing_requested_work" | "unnecessary_deferral" | "regression" | "incorrect_claim" | "wrong_scope" | "failed_delivery")[]>;
|
|
173
|
+
confidence: Type.TNumber;
|
|
174
|
+
probabilities: Type.TObject<{
|
|
175
|
+
[k: string]: Type.TNumber;
|
|
139
176
|
}>;
|
|
140
177
|
}>;
|
|
141
178
|
}>;
|
|
142
|
-
type ResponseQuality = Static<typeof qualitySchema
|
|
143
|
-
type
|
|
179
|
+
type ResponseQuality = Static<typeof qualitySchema>;
|
|
180
|
+
type ResponseFeedbackBase = Static<typeof feedbackSchema>;
|
|
181
|
+
type ResponseSentiment = Static<typeof sentimentSchema>;
|
|
182
|
+
type ResponseFeedback = ResponseFeedbackBase & Partial<ResponseSentiment>;
|
|
183
|
+
type ResponseRetrospective = Static<typeof retrospectiveSchema>;
|
|
144
184
|
export type ResponseJudgment = {
|
|
145
185
|
quality: ResponseQuality;
|
|
146
186
|
feedback: ResponseFeedback;
|
|
147
187
|
};
|
|
148
188
|
export type ResponseStages = {
|
|
149
189
|
quality: ResponseQuality;
|
|
150
|
-
feedback:
|
|
151
|
-
sentiment:
|
|
190
|
+
feedback: ResponseFeedbackBase;
|
|
191
|
+
sentiment: ResponseSentiment;
|
|
152
192
|
retrospective: Awaited<ReturnType<typeof judgeResponseFollowup>>;
|
|
153
193
|
memory: Awaited<ReturnType<typeof judgeMemoryOpportunity>>;
|
|
154
194
|
};
|
|
155
|
-
type
|
|
156
|
-
|
|
157
|
-
|
|
195
|
+
export type ResponseStageContracts = {
|
|
196
|
+
quality?: undefined;
|
|
197
|
+
feedback?: undefined;
|
|
198
|
+
sentiment?: undefined;
|
|
199
|
+
retrospective?: {
|
|
200
|
+
status: ResponseEpisode["followup"]["status"];
|
|
201
|
+
};
|
|
202
|
+
memory?: readonly {
|
|
203
|
+
path: string;
|
|
204
|
+
hash: string;
|
|
205
|
+
}[];
|
|
158
206
|
};
|
|
207
|
+
type JudgeStage = "quality" | "feedback" | "sentiment";
|
|
208
|
+
type StageCache = Partial<Pick<ResponseStages, JudgeStage>> & {
|
|
209
|
+
begin: (stages: JudgeStage[]) => void;
|
|
210
|
+
save: <K extends JudgeStage>(stage: K, result: ResponseStages[K]) => void;
|
|
211
|
+
};
|
|
212
|
+
export declare function validateCachedStage<K extends keyof ResponseStages>(stage: K, value: unknown, contract?: ResponseStageContracts[K]): ResponseStages[K];
|
|
159
213
|
/** Separate requests are deliberate: later feedback must not leak into the original quality grade. */
|
|
160
|
-
export declare function judgeResponse(episode: ResponseEpisode, params:
|
|
161
|
-
apiKey: string;
|
|
162
|
-
timeoutMs: number;
|
|
163
|
-
signal: AbortSignal;
|
|
164
|
-
}, sentimentEnabled?: boolean, cache?: StageCache): Promise<ResponseJudgment>;
|
|
165
|
-
declare const retrospectiveSchema: Type.TObject<{
|
|
166
|
-
answers: Type.TObject<{
|
|
167
|
-
correction: Type.TObject<{
|
|
168
|
-
type: Type.TLiteral<"noul">;
|
|
169
|
-
noul: Type.TNumber;
|
|
170
|
-
}>;
|
|
171
|
-
deliveryAdmission: Type.TObject<{
|
|
172
|
-
type: Type.TLiteral<"noul">;
|
|
173
|
-
noul: Type.TNumber;
|
|
174
|
-
}>;
|
|
175
|
-
regression: Type.TObject<{
|
|
176
|
-
type: Type.TLiteral<"noul">;
|
|
177
|
-
noul: Type.TNumber;
|
|
178
|
-
}>;
|
|
179
|
-
scopeClarification: Type.TObject<{
|
|
180
|
-
type: Type.TLiteral<"noul">;
|
|
181
|
-
noul: Type.TNumber;
|
|
182
|
-
}>;
|
|
183
|
-
outcome: Type.TObject<{
|
|
184
|
-
type: Type.TLiteral<"choice">;
|
|
185
|
-
choice: Type.TEnum<("unknown" | "reported_shortfall" | "acknowledged_success")[]>;
|
|
186
|
-
confidence: Type.TNumber;
|
|
187
|
-
probabilities: Type.TObject<{
|
|
188
|
-
[k: string]: Type.TNumber;
|
|
189
|
-
}>;
|
|
190
|
-
}>;
|
|
191
|
-
reason: Type.TObject<{
|
|
192
|
-
type: Type.TLiteral<"choice">;
|
|
193
|
-
choice: Type.TEnum<("none_or_unclear" | "missing_requested_work" | "unnecessary_deferral" | "regression" | "incorrect_claim" | "wrong_scope" | "failed_delivery")[]>;
|
|
194
|
-
confidence: Type.TNumber;
|
|
195
|
-
probabilities: Type.TObject<{
|
|
196
|
-
[k: string]: Type.TNumber;
|
|
197
|
-
}>;
|
|
198
|
-
}>;
|
|
199
|
-
}>;
|
|
200
|
-
}>;
|
|
214
|
+
export declare function judgeResponse(episode: ResponseEpisode, params: ResponseJudgeParams, sentimentEnabled?: boolean, cache?: StageCache): Promise<ResponseJudgment>;
|
|
201
215
|
/** Later evidence is kept in a third request and never changes the original grade. */
|
|
202
|
-
export declare function judgeResponseFollowup(episode: ResponseEpisode, params: {
|
|
203
|
-
apiKey: string;
|
|
204
|
-
timeoutMs: number;
|
|
205
|
-
signal: AbortSignal;
|
|
206
|
-
}): Promise<{
|
|
216
|
+
export declare function judgeResponseFollowup(episode: ResponseEpisode, params: ResponseJudgeParams): Promise<{
|
|
207
217
|
status: ResponseEpisode["followup"]["status"];
|
|
208
|
-
judgment:
|
|
218
|
+
judgment: ResponseRetrospective | null;
|
|
209
219
|
}>;
|
|
210
220
|
export declare function judgeMemoryOpportunity(episode: ResponseEpisode, candidates: readonly {
|
|
211
221
|
path: string;
|
|
212
222
|
text: string;
|
|
213
223
|
hash: string;
|
|
214
|
-
}[], params: {
|
|
215
|
-
apiKey: string;
|
|
216
|
-
timeoutMs: number;
|
|
217
|
-
signal: AbortSignal;
|
|
218
|
-
}): Promise<{
|
|
224
|
+
}[], params: ResponseJudgeParams): Promise<{
|
|
219
225
|
path: string;
|
|
220
226
|
hash: string;
|
|
221
227
|
usefulness: number;
|