@blockrun/franklin 3.49.16 → 3.49.18
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/agent/commands.js +1 -1
- package/dist/agent/evaluator.d.ts +1 -0
- package/dist/agent/evaluator.js +12 -4
- package/dist/agent/input-queue.d.ts +3 -2
- package/dist/agent/loop.d.ts +2 -2
- package/dist/agent/loop.js +33 -6
- package/dist/agent/types.d.ts +6 -1
- package/dist/gateway-models.d.ts +2 -0
- package/dist/serve/desktop-input.d.ts +4 -0
- package/dist/serve/desktop-input.js +33 -0
- package/dist/serve/desktop-questions.d.ts +10 -0
- package/dist/serve/desktop-questions.js +40 -0
- package/dist/serve/model-list.d.ts +10 -0
- package/dist/serve/model-list.js +40 -0
- package/dist/serve/server.js +51 -48
- package/dist/skills/bootstrap.d.ts +3 -1
- package/dist/skills/bootstrap.js +4 -2
- package/dist/skills/invoke.js +4 -1
- package/dist/skills/loader.d.ts +1 -9
- package/dist/skills/loader.js +16 -77
- package/dist/skills/management.d.ts +28 -0
- package/dist/skills/management.js +113 -0
- package/dist/skills/state.d.ts +2 -0
- package/dist/skills/state.js +26 -0
- package/dist/tools/glob.js +47 -19
- package/dist/tools/sensitive-paths.d.ts +2 -0
- package/dist/tools/sensitive-paths.js +23 -0
- package/dist/ui/model-picker.js +11 -110
- package/package.json +5 -4
package/dist/agent/commands.js
CHANGED
|
@@ -1344,7 +1344,7 @@ export async function handleSlashCommand(input, ctx) {
|
|
|
1344
1344
|
}
|
|
1345
1345
|
// Argument-based rewrite commands (prefix match)
|
|
1346
1346
|
for (const { prefix, rewrite } of ARG_COMMANDS) {
|
|
1347
|
-
if (input.startsWith(prefix)) {
|
|
1347
|
+
if (input.startsWith(prefix) && (prefix.endsWith(' ') || input === prefix)) {
|
|
1348
1348
|
const arg = input.slice(prefix.length).trim();
|
|
1349
1349
|
return { handled: false, rewritten: rewrite(arg) };
|
|
1350
1350
|
}
|
|
@@ -54,6 +54,7 @@ export declare function evaluatorModel(): string;
|
|
|
54
54
|
export declare function checkGrounding(userInput: string, history: Dialogue[], assistantText: string, client: ModelClient, opts?: {
|
|
55
55
|
abortSignal?: AbortSignal;
|
|
56
56
|
model?: string;
|
|
57
|
+
userImageCount?: number;
|
|
57
58
|
}): Promise<GroundingResult>;
|
|
58
59
|
/**
|
|
59
60
|
* Convert a grounding result into a user-facing follow-up message. Returns
|
package/dist/agent/evaluator.js
CHANGED
|
@@ -39,7 +39,10 @@ const EVALUATOR_PROMPT = `You are a GROUNDING CHECK agent. Your job is to verify
|
|
|
39
39
|
### A. Ungrounded claims
|
|
40
40
|
Every **factual claim** in the answer must trace to ONE of:
|
|
41
41
|
(a) A tool call result from this turn (model-initiated OR listed under "Pre-fetched by Franklin harness"), OR
|
|
42
|
-
(b)
|
|
42
|
+
(b) User-provided material, including observations of an attached image when the summary confirms an image was supplied, OR
|
|
43
|
+
(c) Explicit acknowledgment of uncertainty ("I'm not sure", "based on older data")
|
|
44
|
+
|
|
45
|
+
**User-provided images are evidence for visual observations.** The main assistant can see attached images directly; a Read or web tool is not required to transcribe visible text or describe shapes. When the summary confirms user-provided images, do not flag those observations merely because no tool ran. This text-only check cannot verify their visual accuracy: use PARTIAL if that is the only uncertainty, not a demand for a tool call. Images do NOT establish fresh external facts: claims about live prices, latest news, or facts beyond the supplied image still require appropriate evidence.
|
|
43
46
|
|
|
44
47
|
**Harness-prefetched data is evidence.** When the turn includes a "Pre-fetched by Franklin harness" section, the data listed there was fetched live from tools on the assistant's behalf (TradingMarket, ExaAnswer, etc). Treat it identically to a model-initiated tool call — claims that reference prefetched prices, numbers, or news snippets are GROUNDED.
|
|
45
48
|
|
|
@@ -141,11 +144,16 @@ export function shouldCheckGrounding(userInput, assistantText) {
|
|
|
141
144
|
* + tool result snippets + assistant's final answer. Bounded to keep the
|
|
142
145
|
* evaluator call cheap; it doesn't need every byte of every tool output.
|
|
143
146
|
*/
|
|
144
|
-
function summarizeTurn(userInput, history, assistantText) {
|
|
147
|
+
function summarizeTurn(userInput, history, assistantText, userImageCount = 0) {
|
|
145
148
|
const lines = [];
|
|
146
149
|
lines.push(`## User question`);
|
|
147
150
|
lines.push(userInput.trim().slice(0, 800));
|
|
148
151
|
lines.push('');
|
|
152
|
+
if (userImageCount > 0) {
|
|
153
|
+
lines.push(`## User-provided images: ${userImageCount}`);
|
|
154
|
+
lines.push('The assistant received these images directly in this turn. Visual observations and transcription can use them as evidence without a tool call. Image bytes are omitted from this text-only check.');
|
|
155
|
+
lines.push('');
|
|
156
|
+
}
|
|
149
157
|
// ── Harness prefetch (treated as synthetic tool calls) ──
|
|
150
158
|
// When intent-prefetch fires, it prepends a [FRANKLIN HARNESS PREFETCH]
|
|
151
159
|
// block to the user message. The LLM answers based on that data, but
|
|
@@ -166,7 +174,7 @@ function summarizeTurn(userInput, history, assistantText) {
|
|
|
166
174
|
const toolLines = [];
|
|
167
175
|
for (let i = history.length - 1; i >= 0 && found < 40; i--) {
|
|
168
176
|
const msg = history[i];
|
|
169
|
-
if (msg.role === 'user' && typeof msg.content === 'string')
|
|
177
|
+
if (msg.role === 'user' && (typeof msg.content === 'string' || !msg.content.some(part => part.type === 'tool_result')))
|
|
170
178
|
break;
|
|
171
179
|
if (msg.role === 'assistant' && Array.isArray(msg.content)) {
|
|
172
180
|
for (const part of msg.content) {
|
|
@@ -257,7 +265,7 @@ const MAX_EVAL_TOKENS = 512;
|
|
|
257
265
|
const EVAL_TIMEOUT_MS = 15_000;
|
|
258
266
|
export async function checkGrounding(userInput, history, assistantText, client, opts = {}) {
|
|
259
267
|
const model = opts.model || evaluatorModel();
|
|
260
|
-
const summary = summarizeTurn(userInput, history, assistantText);
|
|
268
|
+
const summary = summarizeTurn(userInput, history, assistantText, opts.userImageCount);
|
|
261
269
|
// Run independently of the main agent — the evaluator gets NO tools
|
|
262
270
|
// (it just reads and grades). Limit tokens so a chatty evaluator can't
|
|
263
271
|
// balloon the cost of a cheap check.
|
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
* user input keeps waiting and is delivered at the next boundary. The
|
|
14
14
|
* user's typing is never dropped.
|
|
15
15
|
*/
|
|
16
|
+
import type { AgentInput } from './types.js';
|
|
16
17
|
export interface InputMultiplexer {
|
|
17
18
|
/** Drop-in replacement for the driver's getUserInput. */
|
|
18
|
-
getUserInput: () => Promise<
|
|
19
|
+
getUserInput: () => Promise<AgentInput | null>;
|
|
19
20
|
/** Queue a synthetic input for the next turn boundary. */
|
|
20
21
|
enqueue: (text: string, opts?: {
|
|
21
22
|
priority?: boolean;
|
|
@@ -23,4 +24,4 @@ export interface InputMultiplexer {
|
|
|
23
24
|
/** Number of injected inputs currently waiting. */
|
|
24
25
|
pending: () => number;
|
|
25
26
|
}
|
|
26
|
-
export declare function createInputMultiplexer(base: () => Promise<
|
|
27
|
+
export declare function createInputMultiplexer(base: () => Promise<AgentInput | null>): InputMultiplexer;
|
package/dist/agent/loop.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Franklin Agent Loop
|
|
3
3
|
* The core reasoning-action cycle: prompt → model → extract capabilities → execute → repeat.
|
|
4
4
|
*/
|
|
5
|
-
import type { AgentConfig, ContentPart, Dialogue, StreamEvent } from './types.js';
|
|
5
|
+
import type { AgentConfig, ContentPart, Dialogue, StreamEvent, AgentInput } from './types.js';
|
|
6
6
|
export declare function isExternalWallFailure(toolName: string, output: string, isError?: boolean): boolean;
|
|
7
7
|
/**
|
|
8
8
|
* Detect when the gateway leaked an upstream rate-limit / quota error as a
|
|
@@ -60,4 +60,4 @@ export declare function isWeakModel(model: string): boolean;
|
|
|
60
60
|
* Each user message triggers a full agent loop.
|
|
61
61
|
* Returns the accumulated conversation history.
|
|
62
62
|
*/
|
|
63
|
-
export declare function interactiveSession(config: AgentConfig, getUserInput: () => Promise<
|
|
63
|
+
export declare function interactiveSession(config: AgentConfig, getUserInput: () => Promise<AgentInput | null>, onEvent: (event: StreamEvent) => void, onAbortReady?: (abort: () => void) => void): Promise<Dialogue[]>;
|
package/dist/agent/loop.js
CHANGED
|
@@ -418,6 +418,22 @@ export function stripLargeImageData(message) {
|
|
|
418
418
|
// in via the loop's outcome-building path. Runtime structure is what
|
|
419
419
|
// matters here; we only mutate when we positively identify the shape.
|
|
420
420
|
const newContent = message.content.map((part) => {
|
|
421
|
+
// Images the user attached directly (Desktop paste / file picker) sit at
|
|
422
|
+
// the top level of the user message, not inside a tool_result. They have
|
|
423
|
+
// no source path to re-Read, so the placeholder asks for a re-attach.
|
|
424
|
+
if (typeof part === 'object' &&
|
|
425
|
+
part !== null &&
|
|
426
|
+
part.type === 'image' &&
|
|
427
|
+
part.source?.type === 'base64' &&
|
|
428
|
+
(part.source.data?.length ?? 0) > SESSION_IMAGE_STRIP_THRESHOLD) {
|
|
429
|
+
mutated = true;
|
|
430
|
+
const sz = part.source.data.length;
|
|
431
|
+
return {
|
|
432
|
+
type: 'text',
|
|
433
|
+
text: `<user-attached image stripped from session log: ${(sz / 1024).toFixed(1)} KB base64. ` +
|
|
434
|
+
`Ask the user to attach it again if you need to see it.>`,
|
|
435
|
+
};
|
|
436
|
+
}
|
|
421
437
|
if (typeof part === 'object' &&
|
|
422
438
|
part !== null &&
|
|
423
439
|
part.type === 'tool_result' &&
|
|
@@ -599,6 +615,7 @@ async function runInteractiveSession(config, getUserInput, onEvent, onAbortReady
|
|
|
599
615
|
const inputMux = createInputMultiplexer(getUserInput);
|
|
600
616
|
const history = [];
|
|
601
617
|
let lastUserInput = ''; // For /retry
|
|
618
|
+
let lastUserImages = [];
|
|
602
619
|
// budget-cap-usd of the skill that kicked off this turn (`/name` invocation);
|
|
603
620
|
// kept across /retry, which replays the same skill prompt.
|
|
604
621
|
let turnSkillBudgetUsd;
|
|
@@ -616,7 +633,7 @@ async function runInteractiveSession(config, getUserInput, onEvent, onAbortReady
|
|
|
616
633
|
onEvent({ kind: 'text_delta', text: `[skills] ${err.path}: ${err.error}\n` });
|
|
617
634
|
}
|
|
618
635
|
}
|
|
619
|
-
|
|
636
|
+
let skillRegistry = skillBoot.registry;
|
|
620
637
|
// Track models that failed with 402 (payment required) across turns.
|
|
621
638
|
// These persist until the session ends — unlike transient errors, payment failures
|
|
622
639
|
// will keep failing until the user adds funds. Map stores failure timestamp for future TTL.
|
|
@@ -795,11 +812,15 @@ async function runInteractiveSession(config, getUserInput, onEvent, onAbortReady
|
|
|
795
812
|
process.once('SIGINT', exitFlush);
|
|
796
813
|
process.once('SIGTERM', exitFlush);
|
|
797
814
|
while (true) {
|
|
798
|
-
|
|
799
|
-
if (
|
|
815
|
+
const incoming = await inputMux.getUserInput();
|
|
816
|
+
if (incoming === null)
|
|
800
817
|
break; // User wants to exit
|
|
818
|
+
let input = typeof incoming === 'string' ? incoming : incoming.text;
|
|
819
|
+
let images = typeof incoming === 'string' ? [] : incoming.images;
|
|
801
820
|
if (input === '')
|
|
802
821
|
continue; // Empty input → re-prompt
|
|
822
|
+
// Desktop imports and toggles take effect without restarting this session.
|
|
823
|
+
skillRegistry = loadAllSkills(workDir).registry;
|
|
803
824
|
// ── Slash command dispatch ──
|
|
804
825
|
if (!input.startsWith('/'))
|
|
805
826
|
turnSkillBudgetUsd = undefined;
|
|
@@ -816,6 +837,7 @@ async function runInteractiveSession(config, getUserInput, onEvent, onAbortReady
|
|
|
816
837
|
continue;
|
|
817
838
|
}
|
|
818
839
|
input = lastUserInput;
|
|
840
|
+
images = lastUserImages;
|
|
819
841
|
}
|
|
820
842
|
else {
|
|
821
843
|
const cmdResult = await handleSlashCommand(input, {
|
|
@@ -847,6 +869,7 @@ async function runInteractiveSession(config, getUserInput, onEvent, onAbortReady
|
|
|
847
869
|
input = redactedText;
|
|
848
870
|
}
|
|
849
871
|
lastUserInput = input;
|
|
872
|
+
lastUserImages = images;
|
|
850
873
|
fireLifecycleHook('UserPromptSubmit');
|
|
851
874
|
// ── Skill trigger auto-invoke ──
|
|
852
875
|
// Match the user message against every skill's `triggers:` list. Strong
|
|
@@ -891,11 +914,14 @@ async function runInteractiveSession(config, getUserInput, onEvent, onAbortReady
|
|
|
891
914
|
// (pushback SYSTEM NOTE, prefetch context block) are applied AFTER
|
|
892
915
|
// the turn analyzer runs so they get driven by model-decided flags
|
|
893
916
|
// instead of keyword regex.
|
|
894
|
-
|
|
917
|
+
const userContent = images.length
|
|
918
|
+
? [{ type: 'text', text: input }, ...images]
|
|
919
|
+
: input;
|
|
920
|
+
history.push({ role: 'user', content: userContent });
|
|
895
921
|
turnCount++;
|
|
896
922
|
toolGuard.startTurn();
|
|
897
923
|
publishLiveState('working');
|
|
898
|
-
persistSessionMessage({ role: 'user', content:
|
|
924
|
+
persistSessionMessage({ role: 'user', content: userContent });
|
|
899
925
|
// ── Model recovery: try original model at the start of each new turn ──
|
|
900
926
|
// If we fell back to a free model last turn due to a transient error, try original again.
|
|
901
927
|
// But DON'T reset if the original model had a payment failure — it will just fail again.
|
|
@@ -1397,7 +1423,7 @@ async function runInteractiveSession(config, getUserInput, onEvent, onAbortReady
|
|
|
1397
1423
|
// images, Read's tool_result image blocks get tokenized as base64 text
|
|
1398
1424
|
// by the gateway (verified 2026-05-09) and the model hallucinates from
|
|
1399
1425
|
// the "Image file: <path>" stub. Detect upfront, route accordingly.
|
|
1400
|
-
const turnNeedsVision = loopCount === 1 && messageNeedsVision(lastUserInput);
|
|
1426
|
+
const turnNeedsVision = loopCount === 1 && (images.length > 0 || messageNeedsVision(lastUserInput));
|
|
1401
1427
|
// ── Router: resolve routing profiles to concrete models ──
|
|
1402
1428
|
// The shared Router is local/deterministic and runs once per user turn.
|
|
1403
1429
|
// The turn analyzer remains useful for planning and pushback, but no
|
|
@@ -2413,6 +2439,7 @@ async function runInteractiveSession(config, getUserInput, onEvent, onAbortReady
|
|
|
2413
2439
|
if (!config.disableGroundingRetry && shouldCheckGrounding(lastUserInput || '', assistantText)) {
|
|
2414
2440
|
const gResult = await checkGrounding(lastUserInput, history, assistantText, client, {
|
|
2415
2441
|
abortSignal: abort.signal,
|
|
2442
|
+
userImageCount: images.length,
|
|
2416
2443
|
});
|
|
2417
2444
|
if (gResult.verdict === 'UNGROUNDED' && groundingRetryCount < MAX_GROUNDING_RETRIES) {
|
|
2418
2445
|
groundingRetryCount++;
|
package/dist/agent/types.d.ts
CHANGED
|
@@ -37,7 +37,12 @@ export interface CapabilityOutcome {
|
|
|
37
37
|
is_error?: boolean;
|
|
38
38
|
}
|
|
39
39
|
export type ContentPart = TextSegment | CapabilityInvocation | ThinkingSegment;
|
|
40
|
-
export type UserContentPart = TextSegment | CapabilityOutcome;
|
|
40
|
+
export type UserContentPart = TextSegment | ImageSegment | CapabilityOutcome;
|
|
41
|
+
/** Structured driver input; CLI and scheduled prompts can remain plain text. */
|
|
42
|
+
export type AgentInput = string | {
|
|
43
|
+
text: string;
|
|
44
|
+
images: ImageSegment[];
|
|
45
|
+
};
|
|
41
46
|
export interface Dialogue {
|
|
42
47
|
role: Role;
|
|
43
48
|
content: ContentPart[] | UserContentPart[] | string;
|
package/dist/gateway-models.d.ts
CHANGED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AgentInput } from '../agent/types.js';
|
|
2
|
+
/** Accept only inline image bytes. Never turn a renderer-supplied path into a
|
|
3
|
+
* server-side file read or URL fetch. Keep image data out of the text prompt. */
|
|
4
|
+
export declare function desktopInput(text: unknown, attachments: unknown): AgentInput;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const MAX_IMAGE_BYTES = 4_000_000;
|
|
2
|
+
const MAX_DATA_URL_LENGTH = Math.ceil(MAX_IMAGE_BYTES / 3) * 4 + 64;
|
|
3
|
+
/** Accept only inline image bytes. Never turn a renderer-supplied path into a
|
|
4
|
+
* server-side file read or URL fetch. Keep image data out of the text prompt. */
|
|
5
|
+
export function desktopInput(text, attachments) {
|
|
6
|
+
const prompt = typeof text === 'string' ? text.trim() : '';
|
|
7
|
+
if (attachments === undefined || (Array.isArray(attachments) && attachments.length === 0)) {
|
|
8
|
+
if (!prompt)
|
|
9
|
+
throw new Error('empty input');
|
|
10
|
+
return prompt;
|
|
11
|
+
}
|
|
12
|
+
if (!Array.isArray(attachments) || attachments.length !== 1) {
|
|
13
|
+
throw new Error('Attach one image per message.');
|
|
14
|
+
}
|
|
15
|
+
const value = attachments[0]?.path;
|
|
16
|
+
if (typeof value !== 'string' || value.length > MAX_DATA_URL_LENGTH)
|
|
17
|
+
throw new Error('Image attachment exceeds the 4 MB limit.');
|
|
18
|
+
const match = /^data:(image\/(?:png|jpeg|webp|gif));base64,([A-Za-z0-9+/]+={0,2})$/.exec(value);
|
|
19
|
+
if (!match)
|
|
20
|
+
throw new Error('Attach a PNG, JPEG, WebP or GIF image.');
|
|
21
|
+
const [, mediaType, data] = match;
|
|
22
|
+
const bytes = Buffer.from(data, 'base64');
|
|
23
|
+
if (bytes.length > MAX_IMAGE_BYTES || bytes.toString('base64') !== data)
|
|
24
|
+
throw new Error('Invalid or oversized image attachment.');
|
|
25
|
+
const valid = mediaType === 'image/png' ? bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))
|
|
26
|
+
: mediaType === 'image/jpeg' ? bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255
|
|
27
|
+
: mediaType === 'image/webp' ? bytes.toString('ascii', 0, 4) === 'RIFF' && bytes.toString('ascii', 8, 12) === 'WEBP'
|
|
28
|
+
: /^GIF8[79]a$/.test(bytes.toString('ascii', 0, 6));
|
|
29
|
+
if (!valid)
|
|
30
|
+
throw new Error('Image attachment does not match its declared format.');
|
|
31
|
+
const image = { type: 'image', source: { type: 'base64', media_type: mediaType, data } };
|
|
32
|
+
return { text: prompt || 'Describe the attached image.', images: [image] };
|
|
33
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Free-text questions have their own protocol; answers never grant tool permissions. */
|
|
2
|
+
export declare class DesktopQuestions<Owner> {
|
|
3
|
+
private timeoutMs;
|
|
4
|
+
private sequence;
|
|
5
|
+
private pending;
|
|
6
|
+
constructor(timeoutMs?: number);
|
|
7
|
+
request(owner: Owner, question: string, options: string[] | undefined, emit: (kind: 'agent.questionAsk' | 'agent.questionClosed', payload: object) => void): Promise<string>;
|
|
8
|
+
respond(owner: Owner, askId: unknown, answer: unknown): boolean;
|
|
9
|
+
cancel(owner: Owner): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Free-text questions have their own protocol; answers never grant tool permissions. */
|
|
2
|
+
export class DesktopQuestions {
|
|
3
|
+
timeoutMs;
|
|
4
|
+
sequence = 0;
|
|
5
|
+
pending = new Map();
|
|
6
|
+
constructor(timeoutMs = 15 * 60 * 1000) {
|
|
7
|
+
this.timeoutMs = timeoutMs;
|
|
8
|
+
}
|
|
9
|
+
request(owner, question, options, emit) {
|
|
10
|
+
const askId = `question_${++this.sequence}`;
|
|
11
|
+
return new Promise(resolve => {
|
|
12
|
+
const finish = (answer) => {
|
|
13
|
+
if (!this.pending.delete(askId))
|
|
14
|
+
return;
|
|
15
|
+
clearTimeout(timer);
|
|
16
|
+
emit('agent.questionClosed', { askId });
|
|
17
|
+
resolve(answer);
|
|
18
|
+
};
|
|
19
|
+
const timer = setTimeout(() => finish(''), this.timeoutMs);
|
|
20
|
+
timer.unref?.();
|
|
21
|
+
this.pending.set(askId, { owner, finish });
|
|
22
|
+
emit('agent.questionAsk', { askId, question, options: options ?? [] });
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
respond(owner, askId, answer) {
|
|
26
|
+
if (typeof askId !== 'string' || typeof answer !== 'string' || answer.length > 16_000)
|
|
27
|
+
return false;
|
|
28
|
+
const request = this.pending.get(askId);
|
|
29
|
+
if (!request || request.owner !== owner)
|
|
30
|
+
return false;
|
|
31
|
+
request.finish(answer);
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
cancel(owner) {
|
|
35
|
+
for (const request of [...this.pending.values()]) {
|
|
36
|
+
if (request.owner === owner)
|
|
37
|
+
request.finish('');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { GatewayModel } from '../gateway-models.js';
|
|
2
|
+
/** The models.list payload used by both Desktop and the browser UI. */
|
|
3
|
+
export declare function buildModelList(models: GatewayModel[]): {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
free: boolean;
|
|
7
|
+
group: string;
|
|
8
|
+
provider: string;
|
|
9
|
+
contextWindow: number | undefined;
|
|
10
|
+
}[];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { sortModelsNewestFirst } from '@blockrun/model-catalog';
|
|
2
|
+
// Keep company sections in the established picker order. Recency within each
|
|
3
|
+
// section belongs to Model Core, shared with the expanded terminal picker.
|
|
4
|
+
const PROVIDER_LABEL = {
|
|
5
|
+
anthropic: 'Anthropic', openai: 'OpenAI', azure: 'OpenAI', google: 'Google', 'google-vertex': 'Google',
|
|
6
|
+
xai: 'xAI', deepseek: 'DeepSeek', meta: 'Meta', 'meta-llama': 'Meta', nvidia: 'NVIDIA',
|
|
7
|
+
moonshot: 'Moonshot', moonshotai: 'Moonshot', qwen: 'Qwen', alibaba: 'Qwen', mistral: 'Mistral',
|
|
8
|
+
mistralai: 'Mistral', minimax: 'MiniMax', zhipu: 'Zhipu', bytedance: 'ByteDance', cohere: 'Cohere',
|
|
9
|
+
perplexity: 'Perplexity', amazon: 'Amazon', microsoft: 'Microsoft', '01-ai': 'Yi', ai21: 'AI21',
|
|
10
|
+
};
|
|
11
|
+
const PROVIDER_ORDER = ['Anthropic', 'OpenAI', 'Google', 'xAI', 'DeepSeek', 'Qwen', 'Moonshot', 'Meta', 'Mistral', 'MiniMax', 'NVIDIA'];
|
|
12
|
+
function providerLabel(id, ownedBy) {
|
|
13
|
+
const p = (id.split('/')[0] || ownedBy || '').toLowerCase();
|
|
14
|
+
return PROVIDER_LABEL[p] || (p ? p.charAt(0).toUpperCase() + p.slice(1) : 'Other');
|
|
15
|
+
}
|
|
16
|
+
/** The models.list payload used by both Desktop and the browser UI. */
|
|
17
|
+
export function buildModelList(models) {
|
|
18
|
+
const groups = new Map();
|
|
19
|
+
for (const model of models) {
|
|
20
|
+
if (model.available === false || !model.categories.includes('chat'))
|
|
21
|
+
continue;
|
|
22
|
+
const provider = providerLabel(model.id, model.owned_by);
|
|
23
|
+
const group = groups.get(provider) ?? [];
|
|
24
|
+
group.push(model);
|
|
25
|
+
groups.set(provider, group);
|
|
26
|
+
}
|
|
27
|
+
const rank = (provider) => {
|
|
28
|
+
const index = PROVIDER_ORDER.indexOf(provider);
|
|
29
|
+
return index < 0 ? PROVIDER_ORDER.length : index;
|
|
30
|
+
};
|
|
31
|
+
return [...groups].sort(([a], [b]) => rank(a) - rank(b) || a.localeCompare(b))
|
|
32
|
+
.flatMap(([provider, rows]) => sortModelsNewestFirst(rows).map(model => ({
|
|
33
|
+
id: model.id,
|
|
34
|
+
label: model.name,
|
|
35
|
+
free: model.billing_mode === 'free',
|
|
36
|
+
group: provider,
|
|
37
|
+
provider,
|
|
38
|
+
contextWindow: model.context_window,
|
|
39
|
+
})));
|
|
40
|
+
}
|
package/dist/serve/server.js
CHANGED
|
@@ -16,6 +16,8 @@
|
|
|
16
16
|
* fed by a getUserInput queue. Good enough for the desktop app; multi-session
|
|
17
17
|
* fan-out can come later.
|
|
18
18
|
*/
|
|
19
|
+
import { desktopInput } from './desktop-input.js';
|
|
20
|
+
import { listManagedSkills, importSkill, toggleSkill, removeSkill, resolveManagedSkill } from '../skills/management.js';
|
|
19
21
|
import http from 'node:http';
|
|
20
22
|
import crypto from 'node:crypto';
|
|
21
23
|
import fs from 'node:fs';
|
|
@@ -30,6 +32,7 @@ import { assembleInstructions } from '../agent/context.js';
|
|
|
30
32
|
import { interactiveSession } from '../agent/loop.js';
|
|
31
33
|
import { allCapabilities, createSubAgentCapability } from '../tools/index.js';
|
|
32
34
|
import { getModelsByCategory } from '../gateway-models.js';
|
|
35
|
+
import { buildModelList } from './model-list.js';
|
|
33
36
|
import { listSessions, loadSessionHistory } from '../session/storage.js';
|
|
34
37
|
import { loadSdkSettlements } from '../stats/cost-log.js';
|
|
35
38
|
import { readSwaps } from '../stats/swap-log.js';
|
|
@@ -37,6 +40,7 @@ import { isCloudSyncEnabled, cloudList, cloudSync } from './cloud-sync.js';
|
|
|
37
40
|
import { setupAgentWallet, setupAgentSolanaWallet } from '@blockrun/llm';
|
|
38
41
|
import { retryFetchBalance } from '../commands/balance-retry.js';
|
|
39
42
|
import { AgentHost } from './agent-host.js';
|
|
43
|
+
import { DesktopQuestions } from './desktop-questions.js';
|
|
40
44
|
import { bus } from '../events/bus.js';
|
|
41
45
|
import { FREE_DEFAULT_MODEL } from '../free-models.js';
|
|
42
46
|
import { readEvmBalance } from '../wallet/manager.js';
|
|
@@ -144,26 +148,11 @@ const TOOL_LABELS = {
|
|
|
144
148
|
function labelFor(name) {
|
|
145
149
|
return TOOL_LABELS[name] ?? name;
|
|
146
150
|
}
|
|
147
|
-
// Model list grouping — by provider (company), like OpenRouter/Together. The
|
|
148
|
-
// provider is the id's vendor prefix (e.g. "anthropic/claude-…"); PROVIDER_ORDER
|
|
149
|
-
// puts the most-wanted vendors first, the rest fall in alphabetically.
|
|
150
|
-
const PROVIDER_LABEL = {
|
|
151
|
-
anthropic: 'Anthropic', openai: 'OpenAI', azure: 'OpenAI', google: 'Google', 'google-vertex': 'Google',
|
|
152
|
-
xai: 'xAI', deepseek: 'DeepSeek', meta: 'Meta', 'meta-llama': 'Meta', nvidia: 'NVIDIA',
|
|
153
|
-
moonshot: 'Moonshot', moonshotai: 'Moonshot', qwen: 'Qwen', alibaba: 'Qwen', mistral: 'Mistral',
|
|
154
|
-
mistralai: 'Mistral', minimax: 'MiniMax', zhipu: 'Zhipu', bytedance: 'ByteDance', cohere: 'Cohere',
|
|
155
|
-
perplexity: 'Perplexity', amazon: 'Amazon', microsoft: 'Microsoft', '01-ai': 'Yi', ai21: 'AI21',
|
|
156
|
-
};
|
|
157
|
-
const PROVIDER_ORDER = ['Anthropic', 'OpenAI', 'Google', 'xAI', 'DeepSeek', 'Qwen', 'Moonshot', 'Meta', 'Mistral', 'MiniMax', 'NVIDIA'];
|
|
158
151
|
const MEDIA_MIME = {
|
|
159
152
|
mp3: 'audio/mpeg', wav: 'audio/wav', m4a: 'audio/mp4', ogg: 'audio/ogg', flac: 'audio/flac',
|
|
160
153
|
mp4: 'video/mp4', webm: 'video/webm',
|
|
161
154
|
png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', webp: 'image/webp', gif: 'image/gif',
|
|
162
155
|
};
|
|
163
|
-
function providerLabel(id, ownedBy) {
|
|
164
|
-
const p = (id.split('/')[0] || ownedBy || '').toLowerCase();
|
|
165
|
-
return PROVIDER_LABEL[p] || (p ? p.charAt(0).toUpperCase() + p.slice(1) : 'Other');
|
|
166
|
-
}
|
|
167
156
|
// ─── Browser-attack surface gate ────────────────────────────────────────────
|
|
168
157
|
// Loopback binding alone is NOT an auth boundary: any web page the user has
|
|
169
158
|
// open can reach 127.0.0.1 (the browser attaches an Origin header but happily
|
|
@@ -453,6 +442,7 @@ export async function startServer(opts) {
|
|
|
453
442
|
// Pending approval asks for the legacy desktop session (tools + trade plans).
|
|
454
443
|
// Keyed by askId — the wire contract the desktop UI already declares
|
|
455
444
|
// (agent.permissionAsk / agent.permissionResponse with askId + decision).
|
|
445
|
+
const questions = new DesktopQuestions();
|
|
456
446
|
let askSeq = 0;
|
|
457
447
|
const legacyAsks = new Map();
|
|
458
448
|
const requestDesktopPermission = (toolName, description, timeoutMs = 15 * 60 * 1000) => new Promise((resolve) => {
|
|
@@ -615,6 +605,8 @@ export async function startServer(opts) {
|
|
|
615
605
|
break;
|
|
616
606
|
}
|
|
617
607
|
case 'turn_done':
|
|
608
|
+
if (activeWs)
|
|
609
|
+
questions.cancel(activeWs);
|
|
618
610
|
if (event.reason === 'completed') {
|
|
619
611
|
emit('agent.done', { sessionId: '', costUsd: 0 });
|
|
620
612
|
}
|
|
@@ -667,13 +659,12 @@ export async function startServer(opts) {
|
|
|
667
659
|
allowPaidPrefetch: !desktopBoundary,
|
|
668
660
|
...(desktopBoundary ? { maxSpendUsd: 5 } : {}),
|
|
669
661
|
costSaver,
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
return options?.[options.length - 1] ?? 'no';
|
|
662
|
+
onAskUser: (question, options) => {
|
|
663
|
+
const ws = activeWs;
|
|
664
|
+
const turnId = activeTurnId;
|
|
665
|
+
if (!ws || !turnId)
|
|
666
|
+
return Promise.resolve('');
|
|
667
|
+
return questions.request(ws, question, options, (kind, payload) => send(ws, turnId, kind, payload));
|
|
677
668
|
},
|
|
678
669
|
// Structured approvals (trade plans): surfaced to the desktop over the
|
|
679
670
|
// in-flight turn stream as agent.permissionAsk; the UI answers with
|
|
@@ -701,6 +692,27 @@ export async function startServer(opts) {
|
|
|
701
692
|
const { id, kind, payload } = msg;
|
|
702
693
|
const p = (payload ?? {});
|
|
703
694
|
switch (kind) {
|
|
695
|
+
case 'skills.list':
|
|
696
|
+
case 'skills.upload':
|
|
697
|
+
case 'skills.toggle':
|
|
698
|
+
case 'skills.remove':
|
|
699
|
+
case 'skills.resolve': {
|
|
700
|
+
try {
|
|
701
|
+
const result = kind === 'skills.list' ? listManagedSkills(workDir)
|
|
702
|
+
: kind === 'skills.upload' ? importSkill(workDir, p.content)
|
|
703
|
+
: kind === 'skills.toggle' ? toggleSkill(workDir, p.name, p.enabled)
|
|
704
|
+
: kind === 'skills.remove' ? removeSkill(workDir, p.name)
|
|
705
|
+
: resolveManagedSkill(workDir, p.input);
|
|
706
|
+
send(ws, id, 'response', result);
|
|
707
|
+
}
|
|
708
|
+
catch (err) {
|
|
709
|
+
send(ws, id, 'error', { message: err instanceof Error ? err.message : 'Skill management failed' });
|
|
710
|
+
}
|
|
711
|
+
break;
|
|
712
|
+
}
|
|
713
|
+
case 'skills.create':
|
|
714
|
+
send(ws, id, 'error', { message: 'Automatic skill generation is not available. Import a SKILL.md from Skills instead.' });
|
|
715
|
+
break;
|
|
704
716
|
case 'session.list': {
|
|
705
717
|
const metas = listSessions();
|
|
706
718
|
send(ws, id, 'response', {
|
|
@@ -863,26 +875,7 @@ export async function startServer(opts) {
|
|
|
863
875
|
case 'models.list': {
|
|
864
876
|
try {
|
|
865
877
|
const models = await getModelsByCategory('chat');
|
|
866
|
-
|
|
867
|
-
const provider = providerLabel(m.id, m.owned_by);
|
|
868
|
-
return {
|
|
869
|
-
id: m.id,
|
|
870
|
-
label: m.name,
|
|
871
|
-
free: m.billing_mode === 'free',
|
|
872
|
-
group: provider,
|
|
873
|
-
provider,
|
|
874
|
-
contextWindow: m.context_window,
|
|
875
|
-
};
|
|
876
|
-
});
|
|
877
|
-
// Group by provider (PROVIDER_ORDER first, then alphabetical); free
|
|
878
|
-
// models surface first within each provider. The picker renders
|
|
879
|
-
// consecutive same-`group` items as one section, so sort accordingly.
|
|
880
|
-
const rank = (g) => { const i = PROVIDER_ORDER.indexOf(g); return i < 0 ? 999 : i; };
|
|
881
|
-
mapped.sort((a, b) => rank(a.group) - rank(b.group) ||
|
|
882
|
-
a.group.localeCompare(b.group) ||
|
|
883
|
-
(a.free === b.free ? 0 : a.free ? -1 : 1) ||
|
|
884
|
-
a.label.localeCompare(b.label));
|
|
885
|
-
send(ws, id, 'response', { models: mapped });
|
|
878
|
+
send(ws, id, 'response', { models: buildModelList(models) });
|
|
886
879
|
}
|
|
887
880
|
catch (err) {
|
|
888
881
|
send(ws, id, 'error', { message: err instanceof Error ? err.message : 'models error' });
|
|
@@ -890,9 +883,12 @@ export async function startServer(opts) {
|
|
|
890
883
|
break;
|
|
891
884
|
}
|
|
892
885
|
case 'agent.send': {
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
886
|
+
let input;
|
|
887
|
+
try {
|
|
888
|
+
input = desktopInput(p.text, p.attachments);
|
|
889
|
+
}
|
|
890
|
+
catch (error) {
|
|
891
|
+
send(ws, id, 'agent.error', { sessionId: '', message: error instanceof Error ? error.message : 'Invalid attachment' });
|
|
896
892
|
break;
|
|
897
893
|
}
|
|
898
894
|
activeWs = ws;
|
|
@@ -919,7 +915,7 @@ export async function startServer(opts) {
|
|
|
919
915
|
pushInput(`/model ${desiredModel}`);
|
|
920
916
|
currentModel = desiredModel;
|
|
921
917
|
}
|
|
922
|
-
pushInput(
|
|
918
|
+
pushInput(input);
|
|
923
919
|
break;
|
|
924
920
|
}
|
|
925
921
|
case 'settings.get':
|
|
@@ -936,8 +932,14 @@ export async function startServer(opts) {
|
|
|
936
932
|
break;
|
|
937
933
|
}
|
|
938
934
|
case 'agent.cancel':
|
|
939
|
-
if (
|
|
940
|
-
abortFn
|
|
935
|
+
if (ws === activeWs) {
|
|
936
|
+
if (abortFn)
|
|
937
|
+
abortFn();
|
|
938
|
+
questions.cancel(ws);
|
|
939
|
+
}
|
|
940
|
+
break;
|
|
941
|
+
case 'agent.questionResponse':
|
|
942
|
+
send(ws, id, 'response', { ok: questions.respond(ws, p.askId, p.answer) });
|
|
941
943
|
break;
|
|
942
944
|
case 'agent.permissionResponse': {
|
|
943
945
|
// Two resolution paths:
|
|
@@ -1115,6 +1117,7 @@ export async function startServer(opts) {
|
|
|
1115
1117
|
});
|
|
1116
1118
|
});
|
|
1117
1119
|
ws.on('close', () => {
|
|
1120
|
+
questions.cancel(ws);
|
|
1118
1121
|
// Tear down this socket's agent subscriptions; the agents keep running.
|
|
1119
1122
|
const subs = wsSubs.get(ws);
|
|
1120
1123
|
if (subs)
|
|
@@ -40,7 +40,9 @@ export declare function loadBundledSkills(): BundledLoad;
|
|
|
40
40
|
* unioned; the Registry resolves name collisions by source precedence
|
|
41
41
|
* (project > user > learned > bundled).
|
|
42
42
|
*/
|
|
43
|
-
export declare function loadAllSkills(workDir: string
|
|
43
|
+
export declare function loadAllSkills(workDir: string, options?: {
|
|
44
|
+
includeDisabled?: boolean;
|
|
45
|
+
}): AllSkillsLoad;
|
|
44
46
|
/** Ensure the user-global skills root exists so `~/.blockrun/skills/<name>/`
|
|
45
47
|
* edits don't fail with ENOENT. Idempotent. */
|
|
46
48
|
export declare function ensureUserSkillsDir(): string;
|
package/dist/skills/bootstrap.js
CHANGED
|
@@ -25,6 +25,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
25
25
|
import { dirname, join } from 'node:path';
|
|
26
26
|
import { existsSync, mkdirSync } from 'node:fs';
|
|
27
27
|
import { loadSkillsFromDir } from './loader.js';
|
|
28
|
+
import { disabledSkills } from './state.js';
|
|
28
29
|
import { Registry } from './registry.js';
|
|
29
30
|
import { BLOCKRUN_DIR } from '../config.js';
|
|
30
31
|
import { migrateLegacyLearnedSkills } from '../learnings/store.js';
|
|
@@ -51,7 +52,7 @@ export function loadBundledSkills() {
|
|
|
51
52
|
* unioned; the Registry resolves name collisions by source precedence
|
|
52
53
|
* (project > user > learned > bundled).
|
|
53
54
|
*/
|
|
54
|
-
export function loadAllSkills(workDir) {
|
|
55
|
+
export function loadAllSkills(workDir, options = {}) {
|
|
55
56
|
const errors = [];
|
|
56
57
|
const all = [];
|
|
57
58
|
const counts = {};
|
|
@@ -85,7 +86,8 @@ export function loadAllSkills(workDir) {
|
|
|
85
86
|
errors.push(...result.errors);
|
|
86
87
|
counts[source] = (counts[source] ?? 0) + result.skills.length;
|
|
87
88
|
}
|
|
88
|
-
|
|
89
|
+
const disabled = options.includeDisabled ? new Set() : disabledSkills();
|
|
90
|
+
return { registry: Registry.fromLoaded(all.filter((s) => !disabled.has(s.skill.name))), errors, counts };
|
|
89
91
|
}
|
|
90
92
|
/** Ensure the user-global skills root exists so `~/.blockrun/skills/<name>/`
|
|
91
93
|
* edits don't fail with ENOENT. Idempotent. */
|
package/dist/skills/invoke.js
CHANGED
|
@@ -33,6 +33,9 @@ export function matchSkill(input, registry, vars) {
|
|
|
33
33
|
if (!skill)
|
|
34
34
|
return null;
|
|
35
35
|
const args = space < 0 ? '' : input.slice(space + 1).trim();
|
|
36
|
-
const
|
|
36
|
+
const rendered = substituteVariables(skill.skill.body, vars, args);
|
|
37
|
+
// External SKILL.md files often omit Franklin's argument placeholder.
|
|
38
|
+
const rewritten = args && !skill.skill.body.includes('$ARGUMENTS')
|
|
39
|
+
? `${rendered}\n\nUser request:\n${args}` : rendered;
|
|
37
40
|
return { rewritten, skill: skill.skill };
|
|
38
41
|
}
|
package/dist/skills/loader.d.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SKILL.md loader — parses Anthropic-spec frontmatter + markdown body.
|
|
3
|
-
*
|
|
4
|
-
* The frontmatter parser is intentionally minimal: flat `key: value` lines
|
|
5
|
-
* with scalar values (string, boolean, number). Quoted strings, nested
|
|
6
|
-
* objects, and arrays are out of scope for MVP — Anthropic's SKILL.md spec
|
|
7
|
-
* never needs them and adding a YAML dependency would be heavier than the
|
|
8
|
-
* spec warrants.
|
|
9
|
-
*/
|
|
1
|
+
/** SKILL.md frontmatter and Markdown loader. Metadata is data, never executable. */
|
|
10
2
|
import type { LoadResult, ParseResult, SkillSource } from './types.js';
|
|
11
3
|
export declare function parseSkill(content: string): ParseResult;
|
|
12
4
|
/**
|