@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
package/docs/response-audit.md
CHANGED
|
@@ -10,8 +10,8 @@ deliverable fit, clear underdelivery and its observable reason. Memory gaps are
|
|
|
10
10
|
an optional diagnostic lead, not a proxy for performance.
|
|
11
11
|
|
|
12
12
|
This reads the host transcript database directly: it does not require a `sessions`
|
|
13
|
-
corpus, People Primer, whisperers or clustering. Configure [shared
|
|
14
|
-
credentials](configuration.md#shared-
|
|
13
|
+
corpus, People Primer, whisperers or clustering. Configure [shared decision model
|
|
14
|
+
credentials](configuration.md#shared-decision-model-credentials) separately. Begin with
|
|
15
15
|
the dry-run command below before requesting inference.
|
|
16
16
|
Only approved Slack sender IDs with trusted `senderKind: human` or owner metadata
|
|
17
17
|
qualify (older Slack records use unknown senderKind even for known owners).
|
|
@@ -44,15 +44,17 @@ investigation while still tracking response quality and sentiment.
|
|
|
44
44
|
}
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
This is explicit approval to send those exchanges to
|
|
47
|
+
This is explicit approval to send those exchanges to the configured decision-model
|
|
48
|
+
endpoint (defaulting to `https://codex.unblocklabs.ai/v1/decisions` -> OpenRouter
|
|
49
|
+
`liquid/d1.2-ultra`). Sender IDs apply
|
|
48
50
|
across the agent's Slack accounts; use only identities approved in all such accounts.
|
|
49
51
|
`memoryCorpora` is optional and separately approves configured **file** corpora for
|
|
50
52
|
memory-gap investigation. Leave it empty to send no indexed memory evidence.
|
|
51
|
-
`
|
|
53
|
+
`decisionModel.enabled: false` or missing credentials prevents evaluation. An interval
|
|
52
54
|
of zero means manual-only. Defaults are disabled, no approved senders, direct chats,
|
|
53
55
|
6 preceding visible messages, 30 days, 20 episodes per run and a 60-minute interval.
|
|
54
56
|
`sentimentEnabled` defaults to **true within that opt-in audit**; it does not bypass
|
|
55
|
-
approved senders or
|
|
57
|
+
approved senders or decision model credentials. Set it false to omit polarity, annoyance,
|
|
56
58
|
frustration and intensity questions while retaining quality/repair judgments.
|
|
57
59
|
`intervalMinutes` controls their shared cadence; no second sentiment timer is needed.
|
|
58
60
|
For example, `720` means every 12 hours; `0` means manual-only. `maxEpisodes`
|
|
@@ -80,7 +82,7 @@ openclaw memory-responses report --agent main --episode EPISODE_ID
|
|
|
80
82
|
openclaw memory-responses report --agent main --sender SLACK_USER_ID --account ACCOUNT_SCOPE --bucket day --since 2026-09-01 --until 2026-10-01
|
|
81
83
|
openclaw memory-responses report --agent main --person PERSON_ID
|
|
82
84
|
openclaw memory-responses tasks --agent main
|
|
83
|
-
openclaw memory-responses review --agent main --id TASK_ID --status deferred --reviewer human --note "Review the linked exchanges before changing preferences"
|
|
85
|
+
openclaw memory-responses review --agent main --id TASK_ID --evidence-hash EVIDENCE_HASH --status deferred --reviewer human --note "Review the linked exchanges before changing preferences"
|
|
84
86
|
openclaw memory-responses annotate --agent main --date 2026-09-18 --kind prompt --note "Known prompt revision deployed"
|
|
85
87
|
openclaw memory-responses retry-failed --agent main
|
|
86
88
|
```
|
|
@@ -88,7 +90,7 @@ openclaw memory-responses retry-failed --agent main
|
|
|
88
90
|
Reports group by scoped human identity as well as task/model/time. Names are not
|
|
89
91
|
identity keys. Existing active people-store links are resolved read-only at assessment
|
|
90
92
|
time; missing links do not prevent analysis. Unknown account scopes stay isolated
|
|
91
|
-
per session. No new identity fields are sent to
|
|
93
|
+
per session. No new identity fields are sent to the decision endpoint. Date ranges are UTC with
|
|
92
94
|
an inclusive start and exclusive end. `periodStart` identifies a day/week bucket;
|
|
93
95
|
legacy `week`/`fromWeek`/`toWeek` fields remain aliases. `--task-type` and `--model`
|
|
94
96
|
further narrow comparisons. Human-specific scores are not rankings of the humans:
|
|
@@ -126,7 +128,7 @@ fulfillment/deliverable-fit grade. The feedback pass distinguishes acceptance,
|
|
|
126
128
|
correction, continuation, unrelated replies, expressed sentiment, repeated constraints
|
|
127
129
|
and avoidable rework. Current-index memory investigation runs only for a strong
|
|
128
130
|
memory-gap signal: lexical retrieval selects up to three whole short documents from
|
|
129
|
-
approved collections. Each document is graded in its own concurrent
|
|
131
|
+
approved collections. Each document is graded in its own concurrent decision model request
|
|
130
132
|
against the same request/answer/feedback; no candidate sees the other documents.
|
|
131
133
|
The isolated memory-stage cache version does not reuse old multi-candidate scores.
|
|
132
134
|
This is an investigation lead, **not proof of historical
|
package/docs/retrieval.md
CHANGED
|
@@ -9,7 +9,7 @@ default. Select named corpora, or use `["all"]` alone. An empty list or unknown
|
|
|
9
9
|
name is an error. Supply `bm25Query` (distinctive keywords/names) and
|
|
10
10
|
`vectorQuery` (a natural-language question describing the information needed).
|
|
11
11
|
Each lane retrieves ten candidates; complete passages are deduplicated and
|
|
12
|
-
independently judged
|
|
12
|
+
independently judged against `vectorQuery`. No query generation or
|
|
13
13
|
recall gate runs. Default: **5 results**, `minUsefulness: 0.7`;
|
|
14
14
|
`maxResults` is 1–20 and `minUsefulness` is 0–1. The old `query` and vector
|
|
15
15
|
`minScore` parameters are removed, not silently reinterpreted.
|
|
@@ -21,7 +21,7 @@ Example tool input (the `memory` corpus exists by default):
|
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
Results use compact JSON and carry `path`, `startLine`, `endLine`, `snippet`,
|
|
24
|
-
`corpus`, and a `score`. With `rankingMode: "
|
|
24
|
+
`corpus`, and a `score`. With `rankingMode: "decision"`, this is a
|
|
25
25
|
usefulness probability rounded to hundredths; ranking and threshold filtering
|
|
26
26
|
still use full precision. With `rankingMode: "retrieval"`, passage-level
|
|
27
27
|
reciprocal rank fusion (RRF, `k = 60`, with QMD's top-rank bonuses) scores
|
|
@@ -74,8 +74,9 @@ Search snippets are leads. Inspect attribution, qualifications, dates and adjace
|
|
|
74
74
|
context before relying on a factual claim. An old plan is not proof it happened,
|
|
75
75
|
and memory does not grant permission to act. No results may mean the wrong corpus,
|
|
76
76
|
a high threshold, an unsynced session or an unavailable index—not absence of the fact.
|
|
77
|
-
When enabled and configured,
|
|
78
|
-
excerpts, dates, corpus and source paths.
|
|
77
|
+
When enabled and configured, the decision endpoint receives the semantic query,
|
|
78
|
+
candidate excerpts, dates, corpus and source paths. The default route is Codex LB →
|
|
79
|
+
OpenRouter `liquid/d1.2-ultra`. If disabled, missing/unreadable credentials,
|
|
79
80
|
or **all** eligible usefulness requests fail (including billing HTTP 402, timeouts,
|
|
80
81
|
network or invalid responses), explicit search returns local retrieval-ranked leads.
|
|
81
82
|
The response includes `rankingMode: "retrieval"`, `scoreMeaning: "retrieval_rank"`,
|
|
@@ -119,7 +120,7 @@ Both `memorySearch` and `memoryWhisperer` also report per-call stage measurement
|
|
|
119
120
|
`vectorScanMs`, `hydrationMs`, and `vectorMappingMs`. Repeated scan/hydration stages are summed;
|
|
120
121
|
`vectorScanAttempts` counts native scans. Embedding time includes any lazy model/context setup.
|
|
121
122
|
- `passageMs`: rendering merged candidates; `candidatePrepMs`: eligibility checks and deduplication
|
|
122
|
-
before disclosure to
|
|
123
|
+
before disclosure to the decision endpoint. `judgeMs` covers the concurrent candidate judgments, not their sum.
|
|
123
124
|
- `vectorOtherMs` and `retrievalOtherMs` expose time outside measured child stages. `otherMs` accounts
|
|
124
125
|
for the remaining manual tool execution; Whisperer tracks individual stage timings without a
|
|
125
126
|
separate whole-run residual. Parent durations must not be added to their child durations.
|
|
@@ -135,7 +136,7 @@ path, credential or session identifier is retained; samples are process-local an
|
|
|
135
136
|
Corpora and session filters select evidence; they are not audience ACLs. Normal
|
|
136
137
|
tools can access this agent's configured non-skill corpora, not just its current
|
|
137
138
|
chat. Only index material suitable for the agent's tool callers. Per-feature
|
|
138
|
-
|
|
139
|
+
decision model allowlists do not restrict ordinary retrieval.
|
|
139
140
|
|
|
140
141
|
## QMD entry points
|
|
141
142
|
|
|
@@ -290,7 +291,7 @@ incomplete envelopes leave the entire message unchanged rather than blocking syn
|
|
|
290
291
|
The companion QMD semantic-chunking update skips only source-confirmed standalone
|
|
291
292
|
REM heading/marker spans and orphan closing fences. Reflections and useful text
|
|
292
293
|
remain searchable, with original source offsets. These are deterministic rules,
|
|
293
|
-
not
|
|
294
|
+
not decision model judgments; audit flags never authorize automatic memory deletion.
|
|
294
295
|
|
|
295
296
|
The plugin installs its exact release-pinned QMD dependency (see
|
|
296
297
|
[package metadata](../package.json)). Projector/chunker version changes refresh derived
|
|
@@ -318,13 +319,14 @@ or `memory_get`. Enable it in the plugin config with an explicit corpus allowlis
|
|
|
318
319
|
```
|
|
319
320
|
|
|
320
321
|
Requires `hooks.allowConversationAccess: true` on the plugin entry, prompt
|
|
321
|
-
injection permission, and [shared
|
|
322
|
+
injection permission, and [shared decision model credentials](configuration.md#shared-decision-model-credentials).
|
|
322
323
|
An empty allowlist is invalid when enabled; `all`, unknown names, and `skills`
|
|
323
324
|
are not accepted. When `sessions` is enabled for Memory Whisperer, automatic recall
|
|
324
325
|
can retrieve across this agent's indexed sessions. The sessions corpus's `chatTypes`
|
|
325
326
|
setting controls whether direct messages are included; no additional session-scope
|
|
326
|
-
toggle is required. Selected excerpts are sent to
|
|
327
|
-
|
|
327
|
+
toggle is required. Selected excerpts are sent to the configured decision endpoint
|
|
328
|
+
(defaults to `https://codex.unblocklabs.ai/v1/decisions` -> OpenRouter `liquid/d1.2-ultra`)
|
|
329
|
+
and may be injected into any conversation using this agent. Session availability still depends on the normal
|
|
328
330
|
indexing/sync schedule.
|
|
329
331
|
|
|
330
332
|
The example is a plugin config fragment; `knowledge` must already be configured.
|
|
@@ -340,9 +342,9 @@ complete approved collection scope (not ten per collection) and fusing them via
|
|
|
340
342
|
passage-level RRF (`k = 60`, with QMD top-rank bonuses). The lexical adapter
|
|
341
343
|
uses literal OR keywords; quotation marks do not enable exact-phrase matching.
|
|
342
344
|
After deduplication and cooldown filtering, Whisperer sends at most the top **six**
|
|
343
|
-
fused candidates to
|
|
345
|
+
fused candidates to the decision endpoint, paired with a compact conversation context (the
|
|
344
346
|
current request plus at most the last two visible messages, bounded to 1,500
|
|
345
|
-
characters).
|
|
347
|
+
characters). decision model evaluates one independent Noul question per candidate in
|
|
346
348
|
its own concurrent HTTP request: would a careful assistant use a specific factual
|
|
347
349
|
detail from the excerpt when answering the current request? Partial answers and
|
|
348
350
|
concrete leads count; repeated facts, topic/name matches without answer content,
|
|
@@ -359,7 +361,7 @@ Explicit configured thresholds are preserved. Evaluate it on your own conversati
|
|
|
359
361
|
current request and most recent whole messages are retained; an oversized current
|
|
360
362
|
request skips automatic memory before query generation or retrieval.
|
|
361
363
|
Diagnostics count `input_too_large`; completed logs report `outcome: "skipped"` and
|
|
362
|
-
`reason: "input_too_large"`, without recording the input. Each
|
|
364
|
+
`reason: "input_too_large"`, without recording the input. Each decision model usefulness
|
|
363
365
|
request receives the compacted conversation (at most 1,500 characters across the
|
|
364
366
|
current request and up to two prior visible messages) plus one complete
|
|
365
367
|
1,200-character excerpt, its corpus/source path, all represented message timestamps,
|
|
@@ -396,10 +398,10 @@ All whisperer contributions share that appended block, in this order: `<memory>`
|
|
|
396
398
|
are omitted; no wrapper is emitted when none qualify. The independent whisperers
|
|
397
399
|
run concurrently, and a failed contribution does not discard successful siblings.
|
|
398
400
|
|
|
399
|
-
Unlike Skill Whisperer, **disabled
|
|
401
|
+
Unlike Skill Whisperer, **disabled decision model, a missing key, or no qualifying successful
|
|
400
402
|
judgments means no memory hint**—there is no vector-only fallback. A failed candidate
|
|
401
403
|
does not discard successful siblings. The overall process
|
|
402
|
-
has a 3-second deadline, with the shared 1.5-second
|
|
404
|
+
has a 3-second deadline, with the shared 1.5-second decision model request deadline inside it;
|
|
403
405
|
neither performs retries. Timed-out or superseded runs cannot inject late hints.
|
|
404
406
|
Already-running local QMD work may finish in the background, but does not keep the
|
|
405
407
|
agent waiting beyond the deadline. No new indexing, clustering, or summarization runs
|
|
@@ -446,7 +448,7 @@ between that private worker protocol and the HTTP API below.
|
|
|
446
448
|
missing credentials, timeouts (capped at half the whisperer deadline, up to 1.5s),
|
|
447
449
|
and HTTP failures log `generation_fallback` and fall back to deterministic local
|
|
448
450
|
`lex`/`vec` extraction rather than aborting retrieval; all fallback hits still pass
|
|
449
|
-
through
|
|
451
|
+
through decision model usefulness judging.
|
|
450
452
|
Turn cancellation aborts HTTP and prevents late hints; already-running server-side
|
|
451
453
|
generation may finish independently. Gateway shutdown does not stop the shared API.
|
|
452
454
|
Old `mlx` config is accepted but ignored; remove it after migrating.
|
|
@@ -478,7 +480,7 @@ scores.
|
|
|
478
480
|
Query output requires exactly the two nonempty string fields `lex` and `vec`;
|
|
479
481
|
surrounding whitespace is trimmed. Old query arrays are not accepted. Unparseable,
|
|
480
482
|
timed-out, or unavailable v2 output falls back to deterministic local `lex`/`vec`
|
|
481
|
-
queries for that turn and still requires
|
|
483
|
+
queries for that turn and still requires decision model passage judgments.
|
|
482
484
|
Nothing changes in manual `memory_search` beyond passage-level RRF scoring in
|
|
483
485
|
shared candidate discovery. The default total deadline remains three seconds;
|
|
484
486
|
measure the full path before choosing a larger explicit budget.
|
|
@@ -508,8 +510,8 @@ disabled; an explicit `skillWhisperer.enabled: true` without one logs a warning.
|
|
|
508
510
|
Set `skillWhisperer.enabled` to `false` to opt out. It
|
|
509
511
|
embeds the current prompt plus the configured number of prior user/assistant
|
|
510
512
|
messages, compares it with each configured skill's frontmatter `name` and
|
|
511
|
-
`description`. With
|
|
512
|
-
candidates are graded in separate concurrent
|
|
513
|
+
`description`. With decision model enabled and a key available, the top three valid
|
|
514
|
+
candidates are graded in separate concurrent decision model requests, without a vector-score cutoff.
|
|
513
515
|
Each request sees only one skill's name/description plus the conversation. Code chooses
|
|
514
516
|
the highest usefulness probability at or above **0.7**, with retrieval order breaking ties.
|
|
515
517
|
If none qualifies, no skill is suggested; there is no vector fallback. This is an
|
|
@@ -520,10 +522,10 @@ The reminder follows memory, when present, in the same appended `<unblock_memory
|
|
|
520
522
|
block: `<skill>This skill may be relevant: "/path/to/SKILL.md"</skill>`.
|
|
521
523
|
It includes the path but does not repeat the skill name.
|
|
522
524
|
|
|
523
|
-
See [shared
|
|
525
|
+
See [shared decision model credentials](configuration.md#shared-decision-model-credentials) for key setup,
|
|
524
526
|
rotation and the `enabled: true` / `timeoutMs: 1500` defaults.
|
|
525
527
|
|
|
526
|
-
If
|
|
528
|
+
If the decision model is disabled or no key is found, selection uses the original local
|
|
527
529
|
vector process and `skillWhisperer.minScore`. With a key present, an API error,
|
|
528
530
|
invalid response, or timeout excludes that candidate and logs a sanitized warning;
|
|
529
531
|
successful siblings can still qualify. If all fail, no hint is emitted. It does
|
|
@@ -535,21 +537,21 @@ credential resolution, retrieval and provider calls. A slow skill lookup cannot
|
|
|
535
537
|
hold up ready memory or people hints beyond that budget. Session teardown,
|
|
536
538
|
superseding turns and Gateway shutdown cancel its wait and provider requests;
|
|
537
539
|
shared indexing/embedding work can finish for other callers, but cannot trigger
|
|
538
|
-
late
|
|
540
|
+
late decision model calls or hints for the cancelled run.
|
|
539
541
|
|
|
540
|
-
**Privacy:** enabled
|
|
541
|
-
prompt/recent user-assistant text, plus the shortlisted names/descriptions, to
|
|
542
|
-
`
|
|
543
|
-
|
|
542
|
+
**Privacy:** enabled decision-model selection sends up to 12,000 characters of current
|
|
543
|
+
prompt/recent user-assistant text, plus the shortlisted names/descriptions, to the
|
|
544
|
+
configured `decisionModel.endpoint` (defaulting to `https://codex.unblocklabs.ai/v1/decisions`,
|
|
545
|
+
routed to OpenRouter's `liquid/d1.2-ultra`). Source-path fields, full skill procedures, tool-result
|
|
546
|
+
messages, and system messages are excluded; dossiers and ordinary memory files are not read
|
|
544
547
|
for this call. Material already quoted in user/assistant text can still be included.
|
|
545
|
-
Disable `
|
|
546
|
-
is `jev-1.13.0`.
|
|
548
|
+
Disable `decisionModel.enabled` to keep Skill Whisperer entirely local.
|
|
547
549
|
|
|
548
550
|
The defaults use five prior messages, a vector-only score threshold of `0.5`,
|
|
549
551
|
and a ten-turn cooldown. A skill is cooling down after either a suggestion or a
|
|
550
552
|
successful direct `read` of its indexed `SKILL.md`. When the selected
|
|
551
553
|
skill is cooling down, no hint is emitted; Skill Whisperer does not fall through
|
|
552
|
-
to a weaker match. When every shortlisted skill is cooling down,
|
|
554
|
+
to a weaker match. When every shortlisted skill is cooling down, no decision requests are made.
|
|
553
555
|
Cooldown state is per session and intentionally resets with
|
|
554
556
|
the Gateway. Shell-command reads are not tracked.
|
|
555
557
|
|
|
@@ -571,7 +573,7 @@ rebuild the skill index from the updated configuration.
|
|
|
571
573
|
- `memory_diagnostics` reports credential **availability only**, per-agent process-local
|
|
572
574
|
whisperer counters, projection version, old indexed-session projection count, and
|
|
573
575
|
embedding readiness. Counters are bounded to 100 agents and reset on restart.
|
|
574
|
-
This is not a complete people/response feature-status report; it makes no
|
|
576
|
+
This is not a complete people/response feature-status report; it makes no decision model
|
|
575
577
|
request, but can initialize the memory manager/index on first use.
|
|
576
578
|
No prompts, excerpts, paths, keys, or provider error bodies enter these counters.
|
|
577
579
|
Parser cleanup/budget-skip counts are persisted with the latest completed
|
|
@@ -606,19 +608,20 @@ Optional plugin config fragment (corpora must already be configured):
|
|
|
606
608
|
```
|
|
607
609
|
|
|
608
610
|
Both additions default off. Claim review sends the proposed claim and approved
|
|
609
|
-
source excerpts to
|
|
611
|
+
source excerpts to the decision endpoint; cluster review sends one approved sampled excerpt per request.
|
|
610
612
|
Complementary hints use up to six concurrent directional-pair requests over at most four already-useful
|
|
611
613
|
candidates. Each request sees only its pair, not the other candidates. Only redundancy probability >=0.9
|
|
612
614
|
removes a hint; distinct evidence and contradictions should remain. Provider errors
|
|
613
615
|
retain baseline hints, while the existing total turn deadline/cancellation still
|
|
614
|
-
suppresses late results. Missing keys or disabled
|
|
616
|
+
suppresses late results. Missing keys or disabled decision model never enable these calls.
|
|
615
617
|
The retrieval corpus/session boundaries are unchanged.
|
|
616
618
|
|
|
617
619
|
## Memory quality audit
|
|
618
620
|
|
|
619
|
-
`memory_audit_quality` is an on-demand, source-read-only audit.
|
|
620
|
-
ingestion noise for agent investigation; it never deletes, rewrites,
|
|
621
|
-
memory. Enable it with explicit approval for the corpora sent to
|
|
621
|
+
`memory_audit_quality` is an on-demand, source-read-only audit. The configured decision
|
|
622
|
+
model flags likely ingestion noise for agent investigation; it never deletes, rewrites,
|
|
623
|
+
or suppresses memory. Enable it with explicit approval for the corpora sent to the
|
|
624
|
+
configured decision endpoint (defaults to `https://codex.unblocklabs.ai/v1/decisions` -> OpenRouter `liquid/d1.2-ultra`):
|
|
622
625
|
|
|
623
626
|
```json
|
|
624
627
|
{
|
|
@@ -631,8 +634,8 @@ memory. Enable it with explicit approval for the corpora sent to TypeSafe:
|
|
|
631
634
|
```
|
|
632
635
|
|
|
633
636
|
This is a plugin config fragment; both corpora must already be configured.
|
|
634
|
-
Off by default. Uses the shared
|
|
635
|
-
credentials or disabled
|
|
637
|
+
Off by default. Uses the shared decision model credentials and request timeout. Missing
|
|
638
|
+
credentials or disabled decision model produces no audit. Approval includes transmission
|
|
636
639
|
of full eligible chunks and visibility of findings to all audiences using the agent.
|
|
637
640
|
Unlike Memory Whisperer, approving `sessions` includes **all indexed sessions** in
|
|
638
641
|
that corpus, including configured direct conversations. Only approve that when intended.
|
package/openclaw.plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "unblock-memory",
|
|
3
3
|
"name": "Unblock Memory",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.13.0",
|
|
5
5
|
"description": "Indexes, retrieves, and analyzes configured workspace memory with existing QMD vectors.",
|
|
6
6
|
"kind": "memory",
|
|
7
7
|
"activation": { "onStartup": true },
|
|
@@ -47,35 +47,43 @@
|
|
|
47
47
|
"memory_people_learning": { "sideEffecting": true }
|
|
48
48
|
},
|
|
49
49
|
"uiHints": {
|
|
50
|
-
"myTurn.enabled": { "label": "My Turn", "help": "Opt in to sending recent group/channel conversation text and agent identity to
|
|
50
|
+
"myTurn.enabled": { "label": "My Turn", "help": "Opt in to sending recent group/channel conversation text and agent identity to the configured decision model (default: https://codex.unblocklabs.ai/v1/decisions -> OpenRouter Liquid d1.2-ultra). Appends an advisory NO_REPLY hint only when the model clearly favors silence. DMs and internal wakes are excluded. Failures never prevent a turn. Requires hook conversation access and prompt injection. Disabled by default." },
|
|
51
51
|
"myTurn.historyMessages": { "label": "My Turn Message Window", "help": "Recent host-confirmed human messages including the trigger (1-50, default 10). Agent/bot/internal messages and unverified bundled history are excluded. If the trigger cannot be verified human, My Turn skips without affecting the agent turn." },
|
|
52
52
|
"myTurn.channels": { "label": "My Turn Channel Overrides", "help": "Canonical provider IDs, e.g. slack or imessage. Once My Turn is enabled, omitted providers and omitted enabled flags default on. Set a provider's enabled to false to exclude it." },
|
|
53
|
-
"peoplePrimer.enabled": { "label": "People Background Primer", "help": "Opt in to sending identity, approved excerpts and proposed snippets to
|
|
53
|
+
"peoplePrimer.enabled": { "label": "People Background Primer", "help": "Opt in to sending identity, approved excerpts and proposed snippets to the configured decision model (default: Codex LB -> OpenRouter Liquid d1.2-ultra). Prepares evidence and checks <=70-word blurbs before replace_dossier saves; disabled/unavailable reviews require explicit manual verification. Existing dossiers are not evidence. Results are accessible to the agent's tool callers." },
|
|
54
54
|
"peoplePrimer.corpora": { "label": "Primer Approved Corpora", "help": "Explicit non-skill corpus allowlist. Sessions includes all indexed conversations; approve only content suitable for this agent's audiences." },
|
|
55
|
-
"responseAudit.enabled": { "label": "Response Quality Audit", "help": "Opt in to background
|
|
55
|
+
"responseAudit.enabled": { "label": "Response Quality Audit", "help": "Opt in to background decision-model evaluation (default: Codex LB -> OpenRouter Liquid d1.2-ultra) of approved Slack humans. Operator-only reports; no prompt or memory writes." },
|
|
56
56
|
"responseAudit.sentimentEnabled": { "label": "Human Sentiment Analysis", "help": "Default on within an enabled, approved response audit. Includes annoyance, frustration and expressed intensity; does not imply agent fault." },
|
|
57
57
|
"responseAudit.intervalMinutes": { "label": "Response Audit Interval (minutes)", "help": "Shared cadence for quality and enabled sentiment analysis. Unchanged successful exchanges are cached. Zero means manual-only." },
|
|
58
|
-
"responseAudit.senderIds": { "label": "Approved Human Sender IDs", "help": "Explicit human Slack user IDs whose exchanges may be sent to
|
|
58
|
+
"responseAudit.senderIds": { "label": "Approved Human Sender IDs", "help": "Explicit human Slack user IDs whose exchanges may be sent to the configured decision model. Also requires trusted human identity or owner metadata; explicit bots are always excluded." },
|
|
59
59
|
"responseAudit.memoryCorpora": { "label": "Response Audit Memory Evidence", "help": "Optional configured file corpora approved for current-index memory-gap investigation. Does not prove historical availability." },
|
|
60
60
|
"qualityAudit.enabled": {
|
|
61
61
|
"label": "Memory Quality Audit",
|
|
62
|
-
"help": "Enable an on-demand
|
|
62
|
+
"help": "Enable an on-demand decision-model audit (default: Codex LB -> OpenRouter Liquid d1.2-ultra). Records review indicators only; never edits or suppresses data."
|
|
63
63
|
},
|
|
64
|
-
"evidenceReview.enabled": { "label": "Evidence Review", "help": "Opt in to sending proposed claims and explicitly approved indexed evidence to
|
|
65
|
-
"evidenceReview.corpora": { "label": "Evidence Review Corpora", "help": "Explicit non-skill corpus approval for claim evidence sent to
|
|
64
|
+
"evidenceReview.enabled": { "label": "Evidence Review", "help": "Opt in to sending proposed claims and explicitly approved indexed evidence to the configured decision model (default: Codex LB -> OpenRouter Liquid d1.2-ultra). Advisory only; never writes." },
|
|
65
|
+
"evidenceReview.corpora": { "label": "Evidence Review Corpora", "help": "Explicit non-skill corpus approval for claim evidence sent to the configured decision model." },
|
|
66
66
|
"qualityAudit.corpora": {
|
|
67
67
|
"label": "Approved Audit Corpora",
|
|
68
|
-
"help": "Explicit non-skill corpora approved for external
|
|
68
|
+
"help": "Explicit non-skill corpora approved for external decision-model processing and maintenance results visible to every audience using this agent. Sessions means ALL indexed sessions, not only the current conversation."
|
|
69
69
|
},
|
|
70
|
-
"
|
|
71
|
-
"label": "
|
|
72
|
-
"help": "Shared provider gate for My Turn, opted-in whisperers, people primer/save review, evidence/quality reviews and response audits. Does not enable features or approve corpora by itself. Memory search discovers locally and uses
|
|
70
|
+
"decisionModel.enabled": {
|
|
71
|
+
"label": "Decision Model Judgments",
|
|
72
|
+
"help": "Shared provider gate for My Turn, opted-in whisperers, people primer/save review, evidence/quality reviews and response audits. Does not enable features or approve corpora by itself. Memory search discovers locally and uses the configured decision model to rank usefulness; People Whisperer injection stays local."
|
|
73
73
|
},
|
|
74
|
-
"
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
"decisionModel.endpoint": {
|
|
75
|
+
"label": "Decision Model Endpoint",
|
|
76
|
+
"help": "HTTPS (or loopback HTTP) decision API endpoint without credentials, query, or fragment. Defaults to https://codex.unblocklabs.ai/v1/decisions (OpenRouter Liquid d1.2-ultra)."
|
|
77
|
+
},
|
|
78
|
+
"decisionModel.model": {
|
|
79
|
+
"label": "Decision Model ID",
|
|
80
|
+
"help": "Model alias sent to the decision endpoint. Defaults to liquid/d1.2-ultra."
|
|
81
|
+
},
|
|
82
|
+
"decisionModel.apiKey": { "label": "Decision API Key", "sensitive": true },
|
|
83
|
+
"decisionModel.timeoutMs": { "label": "Decision Request Timeout", "help": "Per-request timeout, not the whole operation. People primer/dossier review use peoplePrimer.timeoutMs instead; Memory Whisperer has its own total deadline, Skill Whisperer has a fixed 3-second total budget, and My Turn has a fixed 1.5-second total budget." },
|
|
84
|
+
"decisionModel.apiKeyFile": {
|
|
85
|
+
"label": "Decision API Key File",
|
|
86
|
+
"help": "Absolute path to a plaintext API key or a dotenv file (CODEX_LB_API_KEY, or DECISION_MODEL_API_KEY for custom endpoints). Use a key for the configured endpoint."
|
|
79
87
|
},
|
|
80
88
|
"keepEmbeddingModelWarm": {
|
|
81
89
|
"label": "Keep Embedding Model Warm",
|
|
@@ -91,15 +99,15 @@
|
|
|
91
99
|
},
|
|
92
100
|
"memoryWhisperer.enabled": {
|
|
93
101
|
"label": "Memory Whisperer",
|
|
94
|
-
"help": "Append up to three
|
|
102
|
+
"help": "Append up to three decision-model-approved historical excerpts after the user prompt. Requires explicit corpora, decision-model credentials (defaults to https://codex.unblocklabs.ai/v1/decisions -> OpenRouter liquid/d1.2-ultra), and hook conversation access. Disabled by default."
|
|
95
103
|
},
|
|
96
104
|
"memoryWhisperer.corpora": {
|
|
97
105
|
"label": "Approved Hint Corpora",
|
|
98
|
-
"help": "Explicit non-skill corpus allowlist for automatic recall and
|
|
106
|
+
"help": "Explicit non-skill corpus allowlist for automatic recall and decision-model processing (defaults to https://codex.unblocklabs.ai/v1/decisions -> OpenRouter liquid/d1.2-ultra). Session recall spans this agent's indexed sessions; the sessions corpus chatTypes setting controls direct-message inclusion."
|
|
99
107
|
},
|
|
100
108
|
"safetyWhisperer.enabled": {
|
|
101
109
|
"label": "Safety Whisperer",
|
|
102
|
-
"help": "Prompt-level guardrail, not access control. Sends every checked human message and bounded recent history to
|
|
110
|
+
"help": "Prompt-level guardrail, not access control. Sends every checked human message and bounded recent history to the configured decision endpoint (defaults to https://codex.unblocklabs.ai/v1/decisions -> OpenRouter liquid/d1.2-ultra) and appends a scenario's flaggedPrompt when an unapproved requestor's message matches. Fails open: if the check cannot run, the turn proceeds without it. Requires hook conversation access and prompt injection. Disabled by default."
|
|
103
111
|
},
|
|
104
112
|
"safetyWhisperer.scenarios": {
|
|
105
113
|
"label": "Safety Scenarios",
|
|
@@ -107,7 +115,7 @@
|
|
|
107
115
|
},
|
|
108
116
|
"people.enabled": {
|
|
109
117
|
"label": "PeopleSQL",
|
|
110
|
-
"help": "Enable the agent-local people store, Slack identity observation and people tools. Disabled by default; whispering and
|
|
118
|
+
"help": "Enable the agent-local people store, Slack identity observation and people tools. Disabled by default; whispering and decision-model primer/review are separate opt-ins."
|
|
111
119
|
},
|
|
112
120
|
"people.whisperer.enabled": {
|
|
113
121
|
"label": "People Whisperer",
|
|
@@ -329,17 +337,23 @@
|
|
|
329
337
|
"todos": { "maxOpen": 1000 }
|
|
330
338
|
}
|
|
331
339
|
},
|
|
332
|
-
"
|
|
340
|
+
"decisionModel": {
|
|
333
341
|
"type": "object",
|
|
334
342
|
"additionalProperties": false,
|
|
335
343
|
"not": { "required": ["apiKey", "apiKeyFile"] },
|
|
336
344
|
"properties": {
|
|
337
345
|
"enabled": { "type": "boolean", "default": true },
|
|
346
|
+
"endpoint": {
|
|
347
|
+
"type": "string",
|
|
348
|
+
"format": "uri",
|
|
349
|
+
"pattern": "^[Hh][Tt][Tt][Pp](?:[Ss]://(?:\\[[0-9A-Fa-f:.]+\\]|[A-Za-z0-9](?:[A-Za-z0-9.-]*[A-Za-z0-9])?\\.?)|://(?:[Ll][Oo][Cc][Aa][Ll][Hh][Oo][Ss][Tt]|127\\.0\\.0\\.1|\\[::1\\]))(?::\\d+)?(?:/[^\\s?#]*)?$",
|
|
350
|
+
"default": "https://codex.unblocklabs.ai/v1/decisions"
|
|
351
|
+
},
|
|
352
|
+
"model": { "type": "string", "pattern": "\\S" },
|
|
338
353
|
"apiKey": { "type": "string", "pattern": "\\S" },
|
|
339
354
|
"apiKeyFile": { "type": "string", "pattern": "\\S" },
|
|
340
355
|
"timeoutMs": { "type": "integer", "minimum": 1, "maximum": 10000, "default": 1500 }
|
|
341
|
-
}
|
|
342
|
-
"default": { "enabled": true, "timeoutMs": 1500 }
|
|
356
|
+
}
|
|
343
357
|
},
|
|
344
358
|
"memoryWhisperer": {
|
|
345
359
|
"type": "object",
|
|
@@ -363,7 +377,7 @@
|
|
|
363
377
|
"modelPath": { "type": "string", "pattern": "^/" }
|
|
364
378
|
}
|
|
365
379
|
},
|
|
366
|
-
"complementaryHints": { "type": "boolean", "default": false, "description": "Optionally remove confidently redundant hints with up to six concurrent
|
|
380
|
+
"complementaryHints": { "type": "boolean", "default": false, "description": "Optionally remove confidently redundant hints with up to six concurrent decision-model requests, one per directional pair. Uncertainty retains hints." },
|
|
367
381
|
"enabled": { "type": "boolean", "default": false },
|
|
368
382
|
"corpora": { "type": "array", "items": { "type": "string", "pattern": "\\S" }, "default": [] },
|
|
369
383
|
"minUsefulness": { "type": "number", "minimum": 0, "maximum": 1, "default": 0.5 },
|
|
@@ -445,7 +459,7 @@
|
|
|
445
459
|
"enabled": { "type": "boolean", "default": true },
|
|
446
460
|
"instructions": { "type": "string", "pattern": "\\S", "maxLength": 2000, "description": "What requests this scenario covers, including exclusions." },
|
|
447
461
|
"flaggedPrompt": { "type": "string", "pattern": "\\S", "maxLength": 2000, "description": "Appended next to the human message when an unapproved requestor's message matches." },
|
|
448
|
-
"minProbability": { "type": "number", "minimum": 0, "maximum": 1, "default": 0.4, "description": "Minimum
|
|
462
|
+
"minProbability": { "type": "number", "minimum": 0, "maximum": 1, "default": 0.4, "description": "Minimum decision-model yes-probability that the current request is covered." },
|
|
449
463
|
"agentIds": {
|
|
450
464
|
"type": "array",
|
|
451
465
|
"minItems": 1,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unblocklabs/unblock-memory",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Workspace-native memory for OpenClaw, powered by QMD",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,7 +51,8 @@
|
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"@huggingface/tokenizers": "0.2.0",
|
|
54
|
-
"@unblocklabs/
|
|
54
|
+
"@unblocklabs/decisions": "^0.1.2",
|
|
55
|
+
"@unblocklabs/qmd": "3.1.0",
|
|
55
56
|
"chokidar": "5.0.0",
|
|
56
57
|
"js-tiktoken": "1.0.21",
|
|
57
58
|
"picomatch": "^4.0.5",
|
|
@@ -32,7 +32,7 @@ knowledge.
|
|
|
32
32
|
## Investigate
|
|
33
33
|
|
|
34
34
|
For suspected ingestion defects, `memory_review_cluster` inspects a bounded
|
|
35
|
-
center/edge sample using
|
|
35
|
+
center/edge sample using the decision model when quality auditing is enabled. Its findings
|
|
36
36
|
apply only to those members; a shared label is a hypothesis, not permission to
|
|
37
37
|
discard a cluster. Inspect original sources before proposing an ingestion fix.
|
|
38
38
|
|
|
@@ -23,7 +23,7 @@ Research original sources using `memory_people_prime`, `memory_search` and
|
|
|
23
23
|
preferences and working-style feedback, including corrections. Sync sessions with
|
|
24
24
|
`memory_sync_sessions` and inspect `memory_sync_status` when needed. Existing
|
|
25
25
|
dossiers and the agent's earlier assertions are not independent evidence. Do not
|
|
26
|
-
send evidence outside the approved corpora to
|
|
26
|
+
send evidence outside the approved corpora to the decision endpoint.
|
|
27
27
|
|
|
28
28
|
## Store a compact, sourced dossier
|
|
29
29
|
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Type } from "typebox";
|
|
2
|
-
import type { UnblockMemoryConfig } from "./config.js";
|
|
3
|
-
export declare const TYPESAFE_MODEL = "jev-1.13.0";
|
|
4
|
-
export declare const TYPESAFE_NOUL_SCHEMA: Type.TObject<{
|
|
5
|
-
type: Type.TLiteral<"noul">;
|
|
6
|
-
noul: Type.TNumber;
|
|
7
|
-
}>;
|
|
8
|
-
export declare const TYPESAFE_NOUL_ANSWERS_SCHEMA: Type.TObject<{
|
|
9
|
-
answers: Type.TRecord<"^.*$", Type.TObject<{
|
|
10
|
-
type: Type.TLiteral<"noul">;
|
|
11
|
-
noul: Type.TNumber;
|
|
12
|
-
}>>;
|
|
13
|
-
}>;
|
|
14
|
-
/** A conservative estimate of serialized size, not Jev's tokenizer. Non-ASCII is budgeted separately. */
|
|
15
|
-
export declare function estimateJevTokens(value: unknown): number;
|
|
16
|
-
export declare class TypeSafeRequestError extends Error {
|
|
17
|
-
readonly code: "timeout" | "cancelled" | "http_error" | "invalid_response" | "network_error";
|
|
18
|
-
readonly status?: number | undefined;
|
|
19
|
-
constructor(message: string, code: "timeout" | "cancelled" | "http_error" | "invalid_response" | "network_error", status?: number | undefined);
|
|
20
|
-
}
|
|
21
|
-
/** A TypeSafe deadline: the request's own timeout, or the caller's timed-out signal. */
|
|
22
|
-
export declare function isTypeSafeTimeout(error: unknown, signal: AbortSignal): boolean;
|
|
23
|
-
/** Explicit credentials take precedence; a missing explicit file never selects another key. */
|
|
24
|
-
export declare function resolveTypeSafeApiKey(config: UnblockMemoryConfig["typesafe"]): Promise<string | undefined>;
|
|
25
|
-
/** One TypeSafe request. The caller owns the response schema and failure policy. */
|
|
26
|
-
export declare function requestTypeSafe(params: {
|
|
27
|
-
apiKey: string;
|
|
28
|
-
timeoutMs?: number;
|
|
29
|
-
signal?: AbortSignal;
|
|
30
|
-
}, state: unknown, questions: unknown): Promise<unknown>;
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
-
import { parseEnv } from "node:util";
|
|
3
|
-
import { Type } from "typebox";
|
|
4
|
-
import { abortedByTimeout } from "./abortable.js";
|
|
5
|
-
export const TYPESAFE_MODEL = "jev-1.13.0";
|
|
6
|
-
export const TYPESAFE_NOUL_SCHEMA = Type.Object({
|
|
7
|
-
type: Type.Literal("noul"), noul: Type.Number({ minimum: 0, maximum: 1 }),
|
|
8
|
-
});
|
|
9
|
-
export const TYPESAFE_NOUL_ANSWERS_SCHEMA = Type.Object({ answers: Type.Record(Type.String(), TYPESAFE_NOUL_SCHEMA) });
|
|
10
|
-
/** A conservative estimate of serialized size, not Jev's tokenizer. Non-ASCII is budgeted separately. */
|
|
11
|
-
export function estimateJevTokens(value) {
|
|
12
|
-
let n = 0;
|
|
13
|
-
for (const c of JSON.stringify(value))
|
|
14
|
-
n += c.codePointAt(0) < 128 ? 1 / 3 : 2;
|
|
15
|
-
return Math.ceil(n);
|
|
16
|
-
}
|
|
17
|
-
export class TypeSafeRequestError extends Error {
|
|
18
|
-
code;
|
|
19
|
-
status;
|
|
20
|
-
constructor(message, code, status) {
|
|
21
|
-
super(message);
|
|
22
|
-
this.code = code;
|
|
23
|
-
this.status = status;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
/** A TypeSafe deadline: the request's own timeout, or the caller's timed-out signal. */
|
|
27
|
-
export function isTypeSafeTimeout(error, signal) {
|
|
28
|
-
return (error instanceof TypeSafeRequestError && error.code === "timeout") || abortedByTimeout(signal);
|
|
29
|
-
}
|
|
30
|
-
/** Explicit credentials take precedence; a missing explicit file never selects another key. */
|
|
31
|
-
export async function resolveTypeSafeApiKey(config) {
|
|
32
|
-
if (!config.enabled)
|
|
33
|
-
return undefined;
|
|
34
|
-
if (config.apiKey)
|
|
35
|
-
return config.apiKey.trim() || undefined;
|
|
36
|
-
if (!config.apiKeyFile)
|
|
37
|
-
return process.env.TYPESAFE_API_KEY?.trim() || undefined;
|
|
38
|
-
let contents;
|
|
39
|
-
try {
|
|
40
|
-
contents = (await readFile(config.apiKeyFile, "utf8")).trim();
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT")
|
|
44
|
-
return undefined;
|
|
45
|
-
throw new Error("TypeSafe credential file could not be read");
|
|
46
|
-
}
|
|
47
|
-
if (!contents)
|
|
48
|
-
return undefined;
|
|
49
|
-
if (/^(?:export\s+)?[A-Za-z_][A-Za-z0-9_]*\s*=/m.test(contents) || contents.startsWith("#")) {
|
|
50
|
-
return parseEnv(contents).TYPESAFE_API_KEY?.trim() || undefined;
|
|
51
|
-
}
|
|
52
|
-
if (/\s/.test(contents))
|
|
53
|
-
throw new Error("TypeSafe credential file must contain a key or dotenv entries");
|
|
54
|
-
return contents;
|
|
55
|
-
}
|
|
56
|
-
/** One TypeSafe request. The caller owns the response schema and failure policy. */
|
|
57
|
-
export async function requestTypeSafe(params, state, questions) {
|
|
58
|
-
const timeout = params.timeoutMs === undefined ? undefined : AbortSignal.timeout(params.timeoutMs);
|
|
59
|
-
const signal = params.signal && timeout ? AbortSignal.any([params.signal, timeout]) : params.signal ?? timeout;
|
|
60
|
-
try {
|
|
61
|
-
signal?.throwIfAborted();
|
|
62
|
-
const response = await fetch("https://api.typesafe.ai/v1/systemone", {
|
|
63
|
-
method: "POST", redirect: "error", signal,
|
|
64
|
-
headers: { Authorization: `Bearer ${params.apiKey}`, "Content-Type": "application/json" },
|
|
65
|
-
body: JSON.stringify({ model: TYPESAFE_MODEL, state, questions }),
|
|
66
|
-
});
|
|
67
|
-
if (!response.ok) {
|
|
68
|
-
try {
|
|
69
|
-
await response.body?.cancel();
|
|
70
|
-
}
|
|
71
|
-
catch { /* Status is authoritative; discard unsafe cancellation detail. */ }
|
|
72
|
-
throw new TypeSafeRequestError(`TypeSafe HTTP ${response.status}`, "http_error", response.status);
|
|
73
|
-
}
|
|
74
|
-
try {
|
|
75
|
-
return await response.json();
|
|
76
|
-
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
if (error instanceof SyntaxError)
|
|
79
|
-
throw new TypeSafeRequestError("TypeSafe returned invalid JSON", "invalid_response");
|
|
80
|
-
throw error;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
catch (error) {
|
|
84
|
-
if (error instanceof TypeSafeRequestError)
|
|
85
|
-
throw error;
|
|
86
|
-
if (signal?.aborted) {
|
|
87
|
-
const timedOut = abortedByTimeout(signal);
|
|
88
|
-
throw new TypeSafeRequestError(timedOut ? "TypeSafe request timed out" : "TypeSafe request cancelled", timedOut ? "timeout" : "cancelled");
|
|
89
|
-
}
|
|
90
|
-
throw new TypeSafeRequestError("TypeSafe request failed", "network_error");
|
|
91
|
-
}
|
|
92
|
-
}
|