@simplelayer/graniteer-core 0.3.9 → 0.3.10
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/dist/functions/conductor.js +39 -16
- package/package.json +1 -1
|
@@ -28,9 +28,8 @@ import { checkConductorRateLimit, fetchConductorKey, insertConductorEvent, } fro
|
|
|
28
28
|
const MODEL = 'claude-haiku-4-5-20251001';
|
|
29
29
|
/** Short Q&A answer, not a report — deliberately not ls-quarterly-brief's 8000. */
|
|
30
30
|
const MAX_TOKENS = 1024;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const KB_BODY_CHARS = 2500;
|
|
31
|
+
/** Per-article body cap. At most eight ranked articles are loaded, so each can keep more of its text. */
|
|
32
|
+
const KB_BODY_CHARS = 6000;
|
|
34
33
|
const QUESTION_MAX_CHARS = 2000;
|
|
35
34
|
/**
|
|
36
35
|
* Bound on what gets stored in the audit row. MAX_TOKENS = 1024 caps a real
|
|
@@ -271,19 +270,43 @@ export async function handle(req, operator) {
|
|
|
271
270
|
// future third audience value cannot silently start appearing in members'
|
|
272
271
|
// prompts before anyone revisits this line.
|
|
273
272
|
//
|
|
274
|
-
//
|
|
275
|
-
//
|
|
276
|
-
//
|
|
277
|
-
//
|
|
273
|
+
// Ranking is public.search_kb_articles(), called on this same caller-JWT
|
|
274
|
+
// client. The function is SECURITY INVOKER, so RLS stays the authorization
|
|
275
|
+
// boundary; `audiences` is the same narrowing filter as the old select
|
|
276
|
+
// (member: ['member'], staff: ['admin','member']) and is applied again inside
|
|
277
|
+
// the function. A full-text miss falls back to newest-first there — still
|
|
278
|
+
// inside that audience list, still capped. This package does not apply that
|
|
279
|
+
// SQL. PGRST202 (function not in the PostgREST schema cache) means the
|
|
280
|
+
// operator has not applied the migration yet: fall back in-process to the
|
|
281
|
+
// previous newest-30 table select on the same caller-JWT client, so an
|
|
282
|
+
// upgrade without the RPC does not silently wipe the knowledge base. Any
|
|
283
|
+
// other RPC error, or a payload that is not an article array, still takes
|
|
284
|
+
// the fail-soft path below rather than telling the model the library is empty.
|
|
278
285
|
const kbAudiences = actorType === 'staff' ? ['admin', 'member'] : ['member'];
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
286
|
+
let { data: kbRows, error: kbErr } = await reader.rpc('search_kb_articles', {
|
|
287
|
+
q: question,
|
|
288
|
+
audiences: kbAudiences,
|
|
289
|
+
max_rows: 8,
|
|
290
|
+
});
|
|
291
|
+
if (kbErr?.code === 'PGRST202') {
|
|
292
|
+
console.warn('[conductor] search_kb_articles missing (PGRST202); falling back to newest-30 table select');
|
|
293
|
+
const fallback = await reader
|
|
294
|
+
.from('kb_articles')
|
|
295
|
+
.select('slug,title,audience,tool,tags,body_markdown')
|
|
296
|
+
.in('audience', kbAudiences)
|
|
297
|
+
.order('updated_at', { ascending: false })
|
|
298
|
+
.limit(30);
|
|
299
|
+
kbRows = fallback.data;
|
|
300
|
+
kbErr = fallback.error;
|
|
301
|
+
}
|
|
302
|
+
// null / non-array is "returned nothing", distinct from a real empty list
|
|
303
|
+
// (no articles in this audience). Only the former is a failed load.
|
|
304
|
+
const kbList = Array.isArray(kbRows) ? kbRows : null;
|
|
285
305
|
if (kbErr)
|
|
286
306
|
console.warn('[conductor] kb_articles read failed', kbErr.message);
|
|
307
|
+
else if (kbList === null)
|
|
308
|
+
console.warn('[conductor] kb_articles read failed', 'search_kb_articles returned nothing');
|
|
309
|
+
const kbUnavailable = Boolean(kbErr) || kbList === null;
|
|
287
310
|
// Own-record context is member-only in v1. Staff Conductor answers
|
|
288
311
|
// wayfinding from kb_articles only — there is no "which member" input, and
|
|
289
312
|
// building a staff member-lookup is explicitly out of scope.
|
|
@@ -337,10 +360,10 @@ export async function handle(req, operator) {
|
|
|
337
360
|
const open = `<<<${fence}>>>`;
|
|
338
361
|
const close = `<<<END ${fence}>>>`;
|
|
339
362
|
const fenced = (label, body) => [`## ${label}`, open, body, close].join('\n');
|
|
340
|
-
const kbBlock =
|
|
363
|
+
const kbBlock = kbUnavailable
|
|
341
364
|
? '(Help articles could NOT be loaded for this request. This is not a statement that none exist.)'
|
|
342
|
-
:
|
|
343
|
-
?
|
|
365
|
+
: kbList.length
|
|
366
|
+
? kbList
|
|
344
367
|
.map((a) => {
|
|
345
368
|
const tags = Array.isArray(a.tags) ? a.tags.join(', ') : '';
|
|
346
369
|
return [
|