osborn 0.9.294 → 0.9.296
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/.claude/skills/deploy-workflow/SKILL.md +5 -0
- package/Dockerfile +1 -1
- package/Dockerfile.sandbox +71 -7
- package/dist/claude-auth.d.ts +2 -2
- package/dist/claude-auth.js +5 -13
- package/dist/claude-llm.d.ts +1 -0
- package/dist/claude-llm.js +2 -1
- package/dist/content/compaction-lens.js +5 -5
- package/dist/content/content-checks.d.ts +7 -0
- package/dist/content/content-checks.js +4 -3
- package/dist/content/content-ingest.js +2 -3
- package/dist/content/content-llm.d.ts +69 -3
- package/dist/content/content-llm.js +127 -18
- package/dist/content/content-run.js +3 -4
- package/dist/content/lens-ingest.d.ts +2 -0
- package/dist/content/lens-ingest.js +2 -0
- package/dist/content/lens-launch.js +4 -3
- package/dist/content/lens-library-digest.js +8 -10
- package/dist/content/lens-library-sweep.js +2 -2
- package/dist/content/lens-library.js +3 -2
- package/dist/content/lens-model.d.ts +15 -6
- package/dist/content/lens-model.js +44 -32
- package/dist/content/period-run.d.ts +3 -1
- package/dist/content/period-run.js +8 -8
- package/dist/data-sender-auth.d.ts +14 -0
- package/dist/data-sender-auth.js +25 -0
- package/dist/env-key.d.ts +15 -0
- package/dist/env-key.js +25 -0
- package/dist/index.js +86 -42
- package/dist/meeting-tts.d.ts +2 -0
- package/dist/meeting-tts.js +3 -1
- package/dist/pipeline-direct-llm.d.ts +1 -0
- package/dist/pipeline-fastbrain.js +4 -6
- package/dist/prompts/chain-after-writer.md +1 -1
- package/dist/prompts/steward.md +3 -0
- package/dist/steward-verdict.js +2 -2
- package/dist/volume-sync-status.d.ts +15 -0
- package/dist/volume-sync-status.js +35 -0
- package/package.json +4 -5
|
@@ -60,6 +60,8 @@ export function resolveIngestConfig() {
|
|
|
60
60
|
return { ok: false, reason: 'no-key' };
|
|
61
61
|
return { ok: true, url, anonKey, token };
|
|
62
62
|
}
|
|
63
|
+
/** A content_ingest row key (its content_hash): sha256 of the kind and its parts, one per line. */
|
|
64
|
+
export const ingestRowKey = (kind, ...parts) => createHash('sha256').update([kind, ...parts].join('\n')).digest('hex');
|
|
63
65
|
export function contentHashFor(p) {
|
|
64
66
|
return createHash('sha256').update(`${p.sessionId}\n${p.startRowId}\n${p.markdown}`).digest('hex');
|
|
65
67
|
}
|
|
@@ -13,6 +13,7 @@ import { tmpdir } from 'node:os';
|
|
|
13
13
|
import { dirname, join } from 'node:path';
|
|
14
14
|
import { randomBytes } from 'node:crypto';
|
|
15
15
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
16
|
+
import { hasContentModelKey } from './content-llm.js';
|
|
16
17
|
import { LOCK_FILE, LOCK_TTL_MS, LOG_FILE, acquireLock, findTranscriptBySessionId, libraryHomeDir, readSweepStatus, releaseLock, resolveProjectDir, slugDir, sweepCoolingDown, writeLiveSessions, writeSweepStatus } from './lens-paths.js';
|
|
17
18
|
/** ON by default; kill switch: OSBORN_CONTENT_LENS=0 | off | false | no. */
|
|
18
19
|
export function isContentLensEnabled() {
|
|
@@ -41,12 +42,12 @@ export function resolveWorkerCommand() {
|
|
|
41
42
|
return null;
|
|
42
43
|
}
|
|
43
44
|
let warnedSpawn = false;
|
|
44
|
-
/** The worker command, or why no worker can run (switched off, no
|
|
45
|
+
/** The worker command, or why no worker can run (switched off, no model key, no worker file). */
|
|
45
46
|
function workerOrSkip() {
|
|
46
47
|
if (!isContentLensEnabled())
|
|
47
48
|
return { status: 'disabled' };
|
|
48
|
-
//
|
|
49
|
-
if (!(
|
|
49
|
+
// Without an OpenRouter or z.ai key the worker can do nothing.
|
|
50
|
+
if (!hasContentModelKey())
|
|
50
51
|
return { status: 'no-key' };
|
|
51
52
|
return resolveWorkerCommand() ?? { status: 'no-worker' };
|
|
52
53
|
}
|
|
@@ -25,9 +25,9 @@ import { loadConversationRows } from './lens-db.js';
|
|
|
25
25
|
import { Budget, chat, getModelInfo, isTransportError, modelCallFailed } from './lens-model.js';
|
|
26
26
|
import { loadClientRedactor } from './lens-redact.js';
|
|
27
27
|
import { redactSecrets } from './transcript-sanitizer.js';
|
|
28
|
-
import { parseJsonLoose } from './content-llm.js';
|
|
28
|
+
import { NO_CONTENT_KEY, hasContentModelKey, parseJsonLoose } from './content-llm.js';
|
|
29
29
|
import { machineTimeZone, parseDigest, rebuildIndex } from './lens-library-index.js';
|
|
30
|
-
import { clip, needsIngest, postContentIngest, resolveIngestConfig } from './lens-ingest.js';
|
|
30
|
+
import { clip, ingestRowKey, needsIngest, postContentIngest, resolveIngestConfig } from './lens-ingest.js';
|
|
31
31
|
import { writeAtomic } from './content-manifest.js';
|
|
32
32
|
import { libraryHomeDir } from './lens-paths.js';
|
|
33
33
|
const DIGEST_MANIFEST_FILE = '.digest-manifest.json';
|
|
@@ -132,9 +132,7 @@ function renderDigestMd(day, items, o) {
|
|
|
132
132
|
return L.join('\n');
|
|
133
133
|
}
|
|
134
134
|
/** Stable per machine + day, so a rewritten digest updates its draft in place. */
|
|
135
|
-
|
|
136
|
-
return createHash('sha256').update(`osborn-library-digest\n${hostname()}\n${day}`).digest('hex');
|
|
137
|
-
}
|
|
135
|
+
const digestContentHash = (day) => ingestRowKey('osborn-library-digest', hostname(), day);
|
|
138
136
|
const bodyHash = (md) => createHash('sha256').update(md).digest('hex');
|
|
139
137
|
/** Send one digest page through the shared content_ingest seam. Never throws; updates `e`. */
|
|
140
138
|
async function ingestDigest(e, markdown, o) {
|
|
@@ -224,19 +222,19 @@ export async function runDigestDay(o) {
|
|
|
224
222
|
return { ...res, status };
|
|
225
223
|
};
|
|
226
224
|
if (!o.dry) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const info = await getModelInfo(key);
|
|
225
|
+
if (!hasContentModelKey())
|
|
226
|
+
throw new Error(NO_CONTENT_KEY);
|
|
227
|
+
const info = await getModelInfo();
|
|
231
228
|
if (!info)
|
|
232
229
|
throw new Error('model info unavailable (cannot enforce the cost cap)');
|
|
233
230
|
const prompt = digestPrompt(o.day, items);
|
|
234
231
|
const budget = new Budget(info, { maxCalls: 1, maxCostUsd: DIGEST_CAP_USD });
|
|
235
232
|
try {
|
|
236
|
-
const r = await chat(budget, prompt,
|
|
233
|
+
const r = await chat(budget, prompt, MAX_OUT);
|
|
237
234
|
if (!r)
|
|
238
235
|
res.errors.push('refused by the cost cap');
|
|
239
236
|
else {
|
|
237
|
+
log(`digest ${o.day}: via ${r.via} (${r.provider || '?'})`);
|
|
240
238
|
const parsed = parseJsonLoose(r.content);
|
|
241
239
|
for (const c of Array.isArray(parsed?.chats) ? parsed.chats : []) {
|
|
242
240
|
const it = items.find(i => i.n === Number(c?.n));
|
|
@@ -26,7 +26,7 @@ import { logLine } from './lens-profile.js';
|
|
|
26
26
|
import { libraryBacklog, libraryDirFor, libraryMinSpanMs, readManifest, runLibraryStep } from './lens-library.js';
|
|
27
27
|
import { isTransportError } from './lens-model.js';
|
|
28
28
|
import { DIGEST_CAP_USD, digestDir, ingestPendingDigests, pendingDigestDays, readDigestManifest, removeDigestDay, runDigestDay, writeDigestManifest } from './lens-library-digest.js';
|
|
29
|
-
import { CapError, LIBRARY_LEDGER_SCOPE, SpendGuard, libraryDailyUsd } from './content-llm.js';
|
|
29
|
+
import { CapError, LIBRARY_LEDGER_SCOPE, hasContentModelKey, SpendGuard, libraryDailyUsd } from './content-llm.js';
|
|
30
30
|
import { PERIOD_CAP_USD } from './period-run.js';
|
|
31
31
|
import { loadClientRedactor } from './lens-redact.js';
|
|
32
32
|
import { listSessionDbs } from './lens-db.js';
|
|
@@ -99,7 +99,7 @@ export async function runLibrarySweep(o = {}) {
|
|
|
99
99
|
try {
|
|
100
100
|
if (!isContentLensEnabled())
|
|
101
101
|
return finish('disabled');
|
|
102
|
-
if (!o.dry && !(
|
|
102
|
+
if (!o.dry && !hasContentModelKey())
|
|
103
103
|
return finish('no-key');
|
|
104
104
|
if (sweepCoolingDown(o.cooldownMs ?? SWEEP_COOLDOWN_MS, home)) {
|
|
105
105
|
log(`${st.trigger}: skipped, the last sweep finished under ${Math.round((o.cooldownMs ?? SWEEP_COOLDOWN_MS) / 60_000)} min ago`);
|
|
@@ -27,6 +27,7 @@ import { loadClientRedactor } from './lens-redact.js';
|
|
|
27
27
|
import { redactSecrets } from './transcript-sanitizer.js';
|
|
28
28
|
import { runPeriodMap } from './period-run.js';
|
|
29
29
|
import { isTransportError } from './lens-model.js';
|
|
30
|
+
import { hasContentModelKey } from './content-llm.js';
|
|
30
31
|
import { DEFAULT_MIN_SPAN_MS, pageFileName, period, pickLibraryPeriod, segmentPeriods } from './lens-library-select.js';
|
|
31
32
|
import { rebuildIndex } from './lens-library-index.js';
|
|
32
33
|
import { contentHashFor, ingestPage, needsIngest, resolveIngestConfig } from './lens-ingest.js';
|
|
@@ -215,7 +216,7 @@ export async function runLibraryStep(o) {
|
|
|
215
216
|
try {
|
|
216
217
|
if (!isContentLensEnabled())
|
|
217
218
|
return { ...res, status: 'disabled' };
|
|
218
|
-
if (!o.dry && !(
|
|
219
|
+
if (!o.dry && !hasContentModelKey())
|
|
219
220
|
return { ...res, status: 'no-key' };
|
|
220
221
|
const db = resolveSessionDb(o.sessionId, o.projectDir, o.cwd);
|
|
221
222
|
if (!db)
|
|
@@ -265,7 +266,7 @@ export async function runLibraryStep(o) {
|
|
|
265
266
|
// Period map on exactly this row range, staged first; published only when a map came back.
|
|
266
267
|
mkdirSync(join(dir, STAGING_DIR), { recursive: true });
|
|
267
268
|
const staged = join(dir, STAGING_DIR, file);
|
|
268
|
-
const r = await runPeriodMap({ sessionId: o.sessionId, outPath: staged, fromRowId: p.startRowId, toRowId: p.endRowId, dry: o.dry, log });
|
|
269
|
+
const r = await runPeriodMap({ sessionId: o.sessionId, outPath: staged, fromRowId: p.startRowId, toRowId: p.endRowId, projectDir, dry: o.dry, log });
|
|
269
270
|
res.costUsd = r.costUsd;
|
|
270
271
|
res.errors = [...r.errors];
|
|
271
272
|
const ok = !!r.map || !!o.dry;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* lens-model.ts —
|
|
3
|
-
*
|
|
2
|
+
* lens-model.ts — model calls for the content lens (map-reduce) and the Library.
|
|
3
|
+
* Every call goes through contentChat (content-llm.ts): OpenRouter, else z.ai.
|
|
4
|
+
* Never the Claude subscription / Anthropic SDK.
|
|
4
5
|
*
|
|
5
6
|
* Model: big-window, env-overridable (OSBORN_CONTENT_LENS_MODEL). Default
|
|
6
7
|
* minimax/minimax-m3 — verified 2026-10-05 via GET /api/v1/models:
|
|
@@ -13,6 +14,7 @@
|
|
|
13
14
|
* if its worst-case cost would cross the cap; actual cost comes from OpenRouter's
|
|
14
15
|
* usage accounting when present.
|
|
15
16
|
*/
|
|
17
|
+
import { type ContentProviderId } from './content-llm.js';
|
|
16
18
|
export declare const DEFAULT_MODEL = "minimax/minimax-m3";
|
|
17
19
|
export declare const WINDOW_FRACTION = 0.25;
|
|
18
20
|
export declare const lensModel: () => string;
|
|
@@ -21,11 +23,15 @@ export interface ModelInfo {
|
|
|
21
23
|
contextLength: number;
|
|
22
24
|
promptPerTok: number;
|
|
23
25
|
completionPerTok: number;
|
|
24
|
-
/** true = read from the OpenRouter models API this run; false = built-in
|
|
26
|
+
/** true = read from the OpenRouter models API this run; false = built-in (or z.ai's documented) values. */
|
|
25
27
|
verified: boolean;
|
|
26
28
|
}
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Context length + price of the model the next call runs on: z.ai's documented
|
|
31
|
+
* values when z.ai serves; else live from OpenRouter. Null for an unknown
|
|
32
|
+
* overridden OpenRouter model (can't enforce the cost cap).
|
|
33
|
+
*/
|
|
34
|
+
export declare function getModelInfo(id?: string): Promise<ModelInfo | null>;
|
|
29
35
|
export declare const windowTokensFor: (info: ModelInfo) => number;
|
|
30
36
|
export declare class Budget {
|
|
31
37
|
readonly info: ModelInfo;
|
|
@@ -55,7 +61,10 @@ export interface ChatResult {
|
|
|
55
61
|
content: string;
|
|
56
62
|
/** 'stop' normally; 'length' = output cap hit (JSON likely truncated). */
|
|
57
63
|
finish: string;
|
|
64
|
+
/** Who answered: OpenRouter's upstream provider name, or "z.ai". */
|
|
58
65
|
provider: string;
|
|
66
|
+
/** The content provider that took the call (content-llm.ts contentChat). */
|
|
67
|
+
via: ContentProviderId;
|
|
59
68
|
promptTokens: number;
|
|
60
69
|
completionTokens: number;
|
|
61
70
|
costUsd: number;
|
|
@@ -65,4 +74,4 @@ export declare const modelCallFailed: (e: any) => string;
|
|
|
65
74
|
/** The model call itself failed: an outage, not a bad reply. */
|
|
66
75
|
export declare const isTransportError: (errors: string[]) => boolean;
|
|
67
76
|
/** One chat call. Returns null when the budget refuses; throws on HTTP/timeout errors. */
|
|
68
|
-
export declare function chat(budget: Budget, user: string,
|
|
77
|
+
export declare function chat(budget: Budget, user: string, maxOut?: number): Promise<ChatResult | null>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* lens-model.ts —
|
|
3
|
-
*
|
|
2
|
+
* lens-model.ts — model calls for the content lens (map-reduce) and the Library.
|
|
3
|
+
* Every call goes through contentChat (content-llm.ts): OpenRouter, else z.ai.
|
|
4
|
+
* Never the Claude subscription / Anthropic SDK.
|
|
4
5
|
*
|
|
5
6
|
* Model: big-window, env-overridable (OSBORN_CONTENT_LENS_MODEL). Default
|
|
6
7
|
* minimax/minimax-m3 — verified 2026-10-05 via GET /api/v1/models:
|
|
@@ -13,6 +14,8 @@
|
|
|
13
14
|
* if its worst-case cost would cross the cap; actual cost comes from OpenRouter's
|
|
14
15
|
* usage accounting when present.
|
|
15
16
|
*/
|
|
17
|
+
import { ZAI_NOMINAL_PRICE, contentChat, contentProviderId, extraOutputTokens, markOpenRouterRejected, openRouterKey } from './content-llm.js';
|
|
18
|
+
import { ZAI_CONTEXT_LENGTH, zaiModel } from '../env-key.js';
|
|
16
19
|
const OPENROUTER = 'https://openrouter.ai/api/v1';
|
|
17
20
|
export const DEFAULT_MODEL = 'minimax/minimax-m3';
|
|
18
21
|
const DEFAULT_MODEL_INFO = { contextLength: 1_048_576, promptPerTok: 0.3e-6, completionPerTok: 1.2e-6 };
|
|
@@ -24,12 +27,26 @@ const envNum = (k, d) => {
|
|
|
24
27
|
return Number.isFinite(n) && n > 0 ? n : d;
|
|
25
28
|
};
|
|
26
29
|
export const lensModel = () => (process.env.OSBORN_CONTENT_LENS_MODEL || '').trim() || DEFAULT_MODEL;
|
|
27
|
-
/**
|
|
28
|
-
|
|
30
|
+
/** z.ai's model: documented context, nominal price (content-llm.ts ZAI_NOMINAL_PRICE). */
|
|
31
|
+
const zaiModelInfo = () => ({ id: zaiModel(), contextLength: ZAI_CONTEXT_LENGTH, promptPerTok: ZAI_NOMINAL_PRICE.p, completionPerTok: ZAI_NOMINAL_PRICE.c, verified: false });
|
|
32
|
+
/**
|
|
33
|
+
* Context length + price of the model the next call runs on: z.ai's documented
|
|
34
|
+
* values when z.ai serves; else live from OpenRouter. Null for an unknown
|
|
35
|
+
* overridden OpenRouter model (can't enforce the cost cap).
|
|
36
|
+
*/
|
|
37
|
+
export async function getModelInfo(id = lensModel()) {
|
|
38
|
+
if (contentProviderId() === 'zai')
|
|
39
|
+
return zaiModelInfo();
|
|
40
|
+
const key = openRouterKey();
|
|
29
41
|
const ctrl = new AbortController();
|
|
30
42
|
const timer = setTimeout(() => ctrl.abort(), META_TIMEOUT_MS);
|
|
31
43
|
try {
|
|
32
|
-
const resp = await fetch(`${OPENROUTER}/models`, { signal: ctrl.signal, headers: { Authorization: `Bearer ${
|
|
44
|
+
const resp = await fetch(`${OPENROUTER}/models`, { signal: ctrl.signal, headers: key ? { Authorization: `Bearer ${key}` } : {} });
|
|
45
|
+
if (key && resp.status === 401) {
|
|
46
|
+
markOpenRouterRejected(resp.status);
|
|
47
|
+
if (contentProviderId() === 'zai')
|
|
48
|
+
return zaiModelInfo();
|
|
49
|
+
}
|
|
33
50
|
if (resp.ok) {
|
|
34
51
|
const data = await resp.json();
|
|
35
52
|
const m = (data?.data ?? []).find((x) => x?.id === id);
|
|
@@ -142,36 +159,30 @@ export const modelCallFailed = (e) => `${CALL_FAILED}: ${e?.message ?? e}`;
|
|
|
142
159
|
/** The model call itself failed: an outage, not a bad reply. */
|
|
143
160
|
export const isTransportError = (errors) => errors.some(e => e.startsWith(CALL_FAILED));
|
|
144
161
|
/** One chat call. Returns null when the budget refuses; throws on HTTP/timeout errors. */
|
|
145
|
-
export async function chat(budget, user,
|
|
162
|
+
export async function chat(budget, user, maxOut = 16_000) {
|
|
146
163
|
const estPrompt = Math.ceil((SYSTEM.length + user.length) / 4);
|
|
147
|
-
|
|
164
|
+
// z.ai cannot switch reasoning off: its worst case includes the reasoning headroom.
|
|
165
|
+
const worstOut = maxOut + extraOutputTokens();
|
|
166
|
+
if (!budget.take(estPrompt, worstOut))
|
|
148
167
|
return null;
|
|
149
168
|
const ctrl = new AbortController();
|
|
150
169
|
const timer = setTimeout(() => ctrl.abort(), CALL_TIMEOUT_MS);
|
|
151
170
|
try {
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
{ role: 'system', content: SYSTEM },
|
|
168
|
-
{ role: 'user', content: user },
|
|
169
|
-
],
|
|
170
|
-
}),
|
|
171
|
-
});
|
|
172
|
-
if (!resp.ok)
|
|
173
|
-
throw new Error(`OpenRouter HTTP ${resp.status}`);
|
|
174
|
-
const data = await resp.json();
|
|
171
|
+
const { data, served, provider: via } = await contentChat({
|
|
172
|
+
model: budget.info.id,
|
|
173
|
+
temperature: 0.1,
|
|
174
|
+
max_tokens: maxOut,
|
|
175
|
+
// Reasoning OFF: measured on minimax-m3, effort:'low' still burned ~5k hidden
|
|
176
|
+
// tokens of a 6k cap (finish=length, truncated JSON); enabled:false → 0, finish=stop.
|
|
177
|
+
reasoning: { enabled: false },
|
|
178
|
+
usage: { include: true },
|
|
179
|
+
// Cheapest provider that fits the prompt (OpenRouter skips too-small contexts).
|
|
180
|
+
provider: { sort: 'price' },
|
|
181
|
+
messages: [
|
|
182
|
+
{ role: 'system', content: SYSTEM },
|
|
183
|
+
{ role: 'user', content: user },
|
|
184
|
+
],
|
|
185
|
+
}, { signal: ctrl.signal });
|
|
175
186
|
const pt = Number(data?.usage?.prompt_tokens) || estPrompt;
|
|
176
187
|
const ct = Number(data?.usage?.completion_tokens) || 0;
|
|
177
188
|
const reported = Number(data?.usage?.cost);
|
|
@@ -180,7 +191,8 @@ export async function chat(budget, user, apiKey, maxOut = 16_000) {
|
|
|
180
191
|
return {
|
|
181
192
|
content: String(data?.choices?.[0]?.message?.content ?? ''),
|
|
182
193
|
finish: String(data?.choices?.[0]?.finish_reason ?? ''),
|
|
183
|
-
provider:
|
|
194
|
+
provider: served,
|
|
195
|
+
via,
|
|
184
196
|
promptTokens: pt,
|
|
185
197
|
completionTokens: ct,
|
|
186
198
|
costUsd: cost,
|
|
@@ -189,7 +201,7 @@ export async function chat(budget, user, apiKey, maxOut = 16_000) {
|
|
|
189
201
|
catch (err) {
|
|
190
202
|
budget.failures++;
|
|
191
203
|
// A failed/timed-out call may still bill: charge the worst case so the cap stays hard.
|
|
192
|
-
budget.spentUsd += budget.estimate(estPrompt,
|
|
204
|
+
budget.spentUsd += budget.estimate(estPrompt, worstOut);
|
|
193
205
|
throw err;
|
|
194
206
|
}
|
|
195
207
|
finally {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* 3. period map lens-period (one OpenRouter call, quotes verified deterministically)
|
|
7
7
|
* 4. audio (opt.) lens-audio AudioAdapter — offsets only when a recording exists
|
|
8
8
|
* 5. render lens-period-render → review .md (redacted again)
|
|
9
|
-
* OpenRouter
|
|
9
|
+
* Model via contentChat (OpenRouter, else z.ai). Hard cap: 1 call, $0.50. Never writes content-profile.md or the HWM.
|
|
10
10
|
*
|
|
11
11
|
* CLI: npx tsx agent/src/content/period-run.ts --session <id> --out <file.md>
|
|
12
12
|
* [--since 24h|ISO] [--until ISO] [--from-row N] [--dry]
|
|
@@ -25,6 +25,8 @@ export interface PeriodOptions {
|
|
|
25
25
|
/** Block stats only — no model call. */
|
|
26
26
|
dry?: boolean;
|
|
27
27
|
audio?: AudioAdapter;
|
|
28
|
+
/** The session's project dir: a session id can have a store under more than one project. */
|
|
29
|
+
projectDir?: string | null;
|
|
28
30
|
log?: (m: string) => void;
|
|
29
31
|
}
|
|
30
32
|
export declare function runPeriodMap(o: PeriodOptions): Promise<PeriodRunReport>;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* 3. period map lens-period (one OpenRouter call, quotes verified deterministically)
|
|
7
7
|
* 4. audio (opt.) lens-audio AudioAdapter — offsets only when a recording exists
|
|
8
8
|
* 5. render lens-period-render → review .md (redacted again)
|
|
9
|
-
* OpenRouter
|
|
9
|
+
* Model via contentChat (OpenRouter, else z.ai). Hard cap: 1 call, $0.50. Never writes content-profile.md or the HWM.
|
|
10
10
|
*
|
|
11
11
|
* CLI: npx tsx agent/src/content/period-run.ts --session <id> --out <file.md>
|
|
12
12
|
* [--since 24h|ISO] [--until ISO] [--from-row N] [--dry]
|
|
@@ -21,6 +21,7 @@ import { redactSecrets } from './transcript-sanitizer.js';
|
|
|
21
21
|
import { readCompactionBoundaries } from './lens-period-boundaries.js';
|
|
22
22
|
import { localRecordingAdapter } from './lens-audio.js';
|
|
23
23
|
import { refuseOutPath } from './lens-paths.js';
|
|
24
|
+
import { NO_CONTENT_KEY, hasContentModelKey } from './content-llm.js';
|
|
24
25
|
import { parseSince, selectBlock } from './lens-period-block.js';
|
|
25
26
|
import { attachAudio, periodPrompt, readPeriodMap } from './lens-period.js';
|
|
26
27
|
import { renderPeriodMd } from './lens-period-render.js';
|
|
@@ -28,17 +29,16 @@ export const PERIOD_CAP_USD = 0.5;
|
|
|
28
29
|
const MAX_OUT = 12_000;
|
|
29
30
|
export async function runPeriodMap(o) {
|
|
30
31
|
const log = o.log ?? (() => { });
|
|
31
|
-
const db = resolveSessionDb(o.sessionId);
|
|
32
|
+
const db = resolveSessionDb(o.sessionId, o.projectDir);
|
|
32
33
|
if (!db)
|
|
33
34
|
throw new Error(`no session.db for ${o.sessionId}`);
|
|
34
35
|
const projectDir = dirname(dirname(dirname(db)));
|
|
35
36
|
const refused = refuseOutPath(o.outPath, projectDir);
|
|
36
37
|
if (refused)
|
|
37
38
|
throw new Error(refused);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const info = await getModelInfo(key ?? '');
|
|
39
|
+
if (!o.dry && !hasContentModelKey())
|
|
40
|
+
throw new Error(NO_CONTENT_KEY);
|
|
41
|
+
const info = await getModelInfo();
|
|
42
42
|
if (!info)
|
|
43
43
|
throw new Error('model info unavailable (cannot enforce the cost cap)');
|
|
44
44
|
const capTokens = windowTokensFor(info);
|
|
@@ -77,12 +77,12 @@ export async function runPeriodMap(o) {
|
|
|
77
77
|
const budget = new Budget(info, { maxCalls: 1, maxCostUsd: PERIOD_CAP_USD });
|
|
78
78
|
const prompt = periodPrompt(block.text, { from: block.from, to: block.to, rows: block.records.length });
|
|
79
79
|
try {
|
|
80
|
-
const res = await chat(budget, prompt,
|
|
80
|
+
const res = await chat(budget, prompt, MAX_OUT);
|
|
81
81
|
if (!res)
|
|
82
82
|
r.errors.push('refused by the cost cap');
|
|
83
83
|
else {
|
|
84
84
|
Object.assign(r, { promptTokens: res.promptTokens, completionTokens: res.completionTokens, finish: res.finish, provider: res.provider });
|
|
85
|
-
log(`map: ${res.promptTokens}+${res.completionTokens} tok, $${res.costUsd.toFixed(4)}, finish=${res.finish}`);
|
|
85
|
+
log(`map: via ${res.via} (${res.provider || '?'}), ${res.promptTokens}+${res.completionTokens} tok, $${res.costUsd.toFixed(4)}, finish=${res.finish}`);
|
|
86
86
|
if (res.finish === 'length')
|
|
87
87
|
r.errors.push('output cap hit (JSON may be truncated)');
|
|
88
88
|
r.map = readPeriodMap(res.content, block.records);
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* dropped. The gate FAILS CLOSED: a type that is not on the read-only list
|
|
11
11
|
* (including any new type added to index.ts later) requires the controller.
|
|
12
12
|
*
|
|
13
|
+
* Read-only viewers (`viewer-*`, #383) are refused for every type.
|
|
14
|
+
*
|
|
13
15
|
* Full set of types handleDataReceived handles (2026-11-07):
|
|
14
16
|
* Gated (state-changing or leaks session/process ids):
|
|
15
17
|
* user_text, claude_auth_code, permission_response, list_sessions,
|
|
@@ -58,6 +60,16 @@ export declare const USER_IDENTITY_PREFIX = "user-";
|
|
|
58
60
|
* for anything else.
|
|
59
61
|
*/
|
|
60
62
|
export declare const AGENT_SELF_IDENTITY = "osborn-agent";
|
|
63
|
+
/**
|
|
64
|
+
* Identity prefix of the read-only room view (#383, GET /view-token). A viewer
|
|
65
|
+
* joins hidden and subscribe-only (no publish, no data), is never adopted as
|
|
66
|
+
* the voice user or the controller, never counts as someone in the room, and
|
|
67
|
+
* its leaving ends nothing.
|
|
68
|
+
*/
|
|
69
|
+
export declare const VIEWER_IDENTITY_PREFIX = "viewer-";
|
|
70
|
+
export declare function isViewerIdentity(identity: string | undefined | null): boolean;
|
|
71
|
+
/** People in the room for the leave and idle timers: everyone but read-only viewers. */
|
|
72
|
+
export declare function roomOccupants(identities: Iterable<string>): number;
|
|
61
73
|
export interface SenderCheck {
|
|
62
74
|
ok: boolean;
|
|
63
75
|
reason?: string;
|
|
@@ -189,6 +201,8 @@ export interface JoinDecision {
|
|
|
189
201
|
* gets the voice session only in a room the agent joined through an
|
|
190
202
|
* authorised phone connect, and only while no controller holds the session.
|
|
191
203
|
* Anywhere else it is ignored, in single-tenant mode too.
|
|
204
|
+
* - A read-only viewer (`viewer-*`): never the controller and never adopted,
|
|
205
|
+
* in a phone room and in single-tenant mode too.
|
|
192
206
|
* - Any other identity: never the controller; gets a session only in
|
|
193
207
|
* single-tenant mode (no owner), matching the old behavior there.
|
|
194
208
|
*/
|
package/dist/data-sender-auth.js
CHANGED
|
@@ -78,7 +78,28 @@ export const USER_IDENTITY_PREFIX = 'user-';
|
|
|
78
78
|
* for anything else.
|
|
79
79
|
*/
|
|
80
80
|
export const AGENT_SELF_IDENTITY = 'osborn-agent';
|
|
81
|
+
/**
|
|
82
|
+
* Identity prefix of the read-only room view (#383, GET /view-token). A viewer
|
|
83
|
+
* joins hidden and subscribe-only (no publish, no data), is never adopted as
|
|
84
|
+
* the voice user or the controller, never counts as someone in the room, and
|
|
85
|
+
* its leaving ends nothing.
|
|
86
|
+
*/
|
|
87
|
+
export const VIEWER_IDENTITY_PREFIX = 'viewer-';
|
|
88
|
+
export function isViewerIdentity(identity) {
|
|
89
|
+
return !!identity && identity.startsWith(VIEWER_IDENTITY_PREFIX);
|
|
90
|
+
}
|
|
91
|
+
/** People in the room for the leave and idle timers: everyone but read-only viewers. */
|
|
92
|
+
export function roomOccupants(identities) {
|
|
93
|
+
let n = 0;
|
|
94
|
+
for (const id of identities)
|
|
95
|
+
if (!isViewerIdentity(id))
|
|
96
|
+
n++;
|
|
97
|
+
return n;
|
|
98
|
+
}
|
|
81
99
|
export function checkControlSender(type, senderIdentity, controllingIdentity) {
|
|
100
|
+
// A viewer's token cannot publish data; refuse it here too, read-only queries included.
|
|
101
|
+
if (isViewerIdentity(senderIdentity))
|
|
102
|
+
return { ok: false, reason: `sender ${senderIdentity} is a read-only viewer` };
|
|
82
103
|
if (READ_ONLY_MESSAGE_TYPES.has(type))
|
|
83
104
|
return { ok: true };
|
|
84
105
|
if (!senderIdentity)
|
|
@@ -258,10 +279,14 @@ export async function readBodyCapped(body, max) {
|
|
|
258
279
|
* gets the voice session only in a room the agent joined through an
|
|
259
280
|
* authorised phone connect, and only while no controller holds the session.
|
|
260
281
|
* Anywhere else it is ignored, in single-tenant mode too.
|
|
282
|
+
* - A read-only viewer (`viewer-*`): never the controller and never adopted,
|
|
283
|
+
* in a phone room and in single-tenant mode too.
|
|
261
284
|
* - Any other identity: never the controller; gets a session only in
|
|
262
285
|
* single-tenant mode (no owner), matching the old behavior there.
|
|
263
286
|
*/
|
|
264
287
|
export function resolveJoin(joinerIdentity, joinerUserId, ownerUserId, currentController, opts = {}) {
|
|
288
|
+
if (isViewerIdentity(joinerIdentity))
|
|
289
|
+
return { adoptSession: false, controller: currentController };
|
|
265
290
|
if (opts.sip) {
|
|
266
291
|
return { adoptSession: !!opts.phoneRoom && !currentController, controller: currentController };
|
|
267
292
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* env-key.ts — model keys and the z.ai Coding Plan settings, read from the
|
|
3
|
+
* environment. Dependency-free so the content workers can share it with
|
|
4
|
+
* claude-auth.ts (which pulls in node-pty) and pipeline-fastbrain.ts.
|
|
5
|
+
*/
|
|
6
|
+
/** Trim whitespace and strip one layer of surrounding quotes from an env value. */
|
|
7
|
+
export declare function cleanEnvKey(value: string | undefined | null): string;
|
|
8
|
+
/** The z.ai GLM Coding Plan key: Z_AI_PERSONAL_API_KEY, then ZAI_API_KEY. Empty when neither is set. */
|
|
9
|
+
export declare function zaiApiKey(env?: NodeJS.ProcessEnv): string;
|
|
10
|
+
/** The Coding Plan's OpenAI-compatible endpoint; the plain /api/paas/v4 bills the pay-as-you-go wallet instead. */
|
|
11
|
+
export declare const ZAI_CODING_BASE = "https://api.z.ai/api/coding/paas/v4";
|
|
12
|
+
/** The plan's main model: OSBORN_DEMO_MODEL, default glm-5.3 (docs.z.ai/devpack/overview). */
|
|
13
|
+
export declare const zaiModel: () => string;
|
|
14
|
+
/** GLM-5.3 / GLM-5.3-Flash: 1M-token context (docs.z.ai/guides/llm/glm-5.3, …/glm-5.3-flash). */
|
|
15
|
+
export declare const ZAI_CONTEXT_LENGTH = 1000000;
|
package/dist/env-key.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* env-key.ts — model keys and the z.ai Coding Plan settings, read from the
|
|
3
|
+
* environment. Dependency-free so the content workers can share it with
|
|
4
|
+
* claude-auth.ts (which pulls in node-pty) and pipeline-fastbrain.ts.
|
|
5
|
+
*/
|
|
6
|
+
/** Trim whitespace and strip one layer of surrounding quotes from an env value. */
|
|
7
|
+
export function cleanEnvKey(value) {
|
|
8
|
+
if (!value)
|
|
9
|
+
return '';
|
|
10
|
+
let v = value.trim();
|
|
11
|
+
if (v.length >= 2 && ((v.startsWith('"') && v.endsWith('"')) || (v.startsWith("'") && v.endsWith("'")))) {
|
|
12
|
+
v = v.slice(1, -1).trim();
|
|
13
|
+
}
|
|
14
|
+
return v;
|
|
15
|
+
}
|
|
16
|
+
/** The z.ai GLM Coding Plan key: Z_AI_PERSONAL_API_KEY, then ZAI_API_KEY. Empty when neither is set. */
|
|
17
|
+
export function zaiApiKey(env = process.env) {
|
|
18
|
+
return cleanEnvKey(env.Z_AI_PERSONAL_API_KEY) || cleanEnvKey(env.ZAI_API_KEY);
|
|
19
|
+
}
|
|
20
|
+
/** The Coding Plan's OpenAI-compatible endpoint; the plain /api/paas/v4 bills the pay-as-you-go wallet instead. */
|
|
21
|
+
export const ZAI_CODING_BASE = 'https://api.z.ai/api/coding/paas/v4';
|
|
22
|
+
/** The plan's main model: OSBORN_DEMO_MODEL, default glm-5.3 (docs.z.ai/devpack/overview). */
|
|
23
|
+
export const zaiModel = () => (process.env.OSBORN_DEMO_MODEL || '').trim() || 'glm-5.3';
|
|
24
|
+
/** GLM-5.3 / GLM-5.3-Flash: 1M-token context (docs.z.ai/guides/llm/glm-5.3, …/glm-5.3-flash). */
|
|
25
|
+
export const ZAI_CONTEXT_LENGTH = 1_000_000;
|