@blockrun/franklin 3.29.3 → 3.29.4
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/serve/cloud-sync.js +5 -1
- package/dist/tools/imagegen.js +19 -70
- package/dist/tools/videogen.js +20 -60
- package/package.json +1 -1
package/dist/serve/cloud-sync.js
CHANGED
|
@@ -17,7 +17,11 @@ const NONCE_COOKIE = 'franklin_try_nonce';
|
|
|
17
17
|
const SESSION_COOKIE = 'franklin_try_session';
|
|
18
18
|
const TIMEOUT = 8000;
|
|
19
19
|
export function isCloudSyncEnabled() {
|
|
20
|
-
|
|
20
|
+
// Local-first by default (matches Claude Code / Codex): conversation history
|
|
21
|
+
// stays on disk and is NOT uploaded to franklin.run unless the user opts in
|
|
22
|
+
// with FRANKLIN_CLOUD_SYNC=on. Cross-device sync is a deliberate choice, not
|
|
23
|
+
// the default.
|
|
24
|
+
return process.env.FRANKLIN_CLOUD_SYNC === 'on';
|
|
21
25
|
}
|
|
22
26
|
let sessionCookie = null;
|
|
23
27
|
// Track what we've pushed so save only sends changed/removed conversations.
|
package/dist/tools/imagegen.js
CHANGED
|
@@ -7,8 +7,6 @@ import path from 'node:path';
|
|
|
7
7
|
import { getOrCreateWallet, getOrCreateSolanaWallet, createPaymentPayload, createSolanaPaymentPayload, parsePaymentRequired, extractPaymentDetails, solanaKeyToBytes, SOLANA_NETWORK, } from '@blockrun/llm';
|
|
8
8
|
import { loadChain, API_URLS, VERSION } from '../config.js';
|
|
9
9
|
import { checkImageBudget, recordImageAsset } from '../content/record-image.js';
|
|
10
|
-
import { ModelClient } from '../agent/llm.js';
|
|
11
|
-
import { analyzeMediaRequest, renderProposalForAskUser } from '../agent/media-router.js';
|
|
12
10
|
import { recordUsage } from '../stats/tracker.js';
|
|
13
11
|
import { findModel, estimateCostUsd } from '../gateway-models.js';
|
|
14
12
|
import { logger } from '../logger.js';
|
|
@@ -140,21 +138,8 @@ function buildExecute(deps) {
|
|
|
140
138
|
isError: true,
|
|
141
139
|
};
|
|
142
140
|
}
|
|
143
|
-
//
|
|
144
|
-
|
|
145
|
-
// and pass skipRefine through to the router.
|
|
146
|
-
let prompt = rawInput.prompt;
|
|
147
|
-
let skipRefine = false;
|
|
148
|
-
if (prompt.trimStart().startsWith('///')) {
|
|
149
|
-
prompt = prompt.replace(/^\s*\/\/\/\s?/, '');
|
|
150
|
-
skipRefine = true;
|
|
151
|
-
}
|
|
152
|
-
// ── Media router + AskUser flow ────────────────────────────────────
|
|
153
|
-
// If the caller explicitly named a model, or the env auto-approves, or
|
|
154
|
-
// no AskUser bridge exists (batch / --prompt mode), skip the proposal
|
|
155
|
-
// step and use the old default. Otherwise: classifier picks a fitting
|
|
156
|
-
// model + rewrites the prompt, the preview goes to AskUser, user
|
|
157
|
-
// chooses or cancels.
|
|
141
|
+
// Pure tool: use exactly the prompt the caller gave — no LLM rewriting.
|
|
142
|
+
const prompt = rawInput.prompt;
|
|
158
143
|
// Reference-image mode forces an edit-capable model. If the caller named
|
|
159
144
|
// an unsupported one, fail loudly so we don't silently downgrade their
|
|
160
145
|
// request to text-only generation.
|
|
@@ -165,9 +150,9 @@ function buildExecute(deps) {
|
|
|
165
150
|
isError: true,
|
|
166
151
|
};
|
|
167
152
|
}
|
|
168
|
-
|
|
153
|
+
const imageModel = model || (editMode ? 'openai/gpt-image-2' : 'openai/gpt-image-1');
|
|
169
154
|
let imageSize = size || '1024x1024';
|
|
170
|
-
|
|
155
|
+
const chosenPrompt = prompt;
|
|
171
156
|
// ── Edit-mode constraint checks (mirror the gateway, fail before paying) ──
|
|
172
157
|
if (editMode) {
|
|
173
158
|
// Mask inpainting is OpenAI-only.
|
|
@@ -198,57 +183,6 @@ function buildExecute(deps) {
|
|
|
198
183
|
};
|
|
199
184
|
}
|
|
200
185
|
}
|
|
201
|
-
// Skip the proposal flow when a reference image is set: the media router
|
|
202
|
-
// doesn't know which models support image-to-image, so its suggestions
|
|
203
|
-
// would frequently be unusable (text-only models). Default to gpt-image-1
|
|
204
|
-
// for now; a future router upgrade can pick between the four edit-capable
|
|
205
|
-
// models based on the prompt.
|
|
206
|
-
const autoApprove = process.env.FRANKLIN_MEDIA_AUTO_APPROVE_ALL === '1';
|
|
207
|
-
if (!model && !autoApprove && ctx.onAskUser && !editMode) {
|
|
208
|
-
try {
|
|
209
|
-
const chain = loadChain();
|
|
210
|
-
const client = new ModelClient({ apiUrl: API_URLS[chain], chain });
|
|
211
|
-
const proposal = await analyzeMediaRequest({
|
|
212
|
-
kind: 'image',
|
|
213
|
-
prompt,
|
|
214
|
-
quantity: n,
|
|
215
|
-
client,
|
|
216
|
-
signal: ctx.abortSignal,
|
|
217
|
-
skipRefine,
|
|
218
|
-
});
|
|
219
|
-
if (proposal) {
|
|
220
|
-
const { question, options } = renderProposalForAskUser(proposal, prompt);
|
|
221
|
-
const labels = options.map(o => o.label);
|
|
222
|
-
const answer = await ctx.onAskUser(question, labels);
|
|
223
|
-
// Map the user's returned label back to an option id
|
|
224
|
-
const chosen = options.find(o => o.label === answer) ?? { id: 'cancel' };
|
|
225
|
-
switch (chosen.id) {
|
|
226
|
-
case 'cheaper':
|
|
227
|
-
imageModel = proposal.cheaper?.model ?? proposal.recommended.model;
|
|
228
|
-
break;
|
|
229
|
-
case 'premium':
|
|
230
|
-
imageModel = proposal.premium?.model ?? proposal.recommended.model;
|
|
231
|
-
break;
|
|
232
|
-
case 'cancel':
|
|
233
|
-
return {
|
|
234
|
-
output: `## Image generation cancelled\n\nNo USDC was spent. Ask again when ready, or pass an explicit \`model\` to skip the confirmation step.`,
|
|
235
|
-
};
|
|
236
|
-
case 'use-raw':
|
|
237
|
-
imageModel = proposal.recommended.model;
|
|
238
|
-
// chosenPrompt stays as the raw input
|
|
239
|
-
break;
|
|
240
|
-
case 'recommended':
|
|
241
|
-
default:
|
|
242
|
-
imageModel = proposal.recommended.model;
|
|
243
|
-
if (proposal.refinedPrompt)
|
|
244
|
-
chosenPrompt = proposal.refinedPrompt;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
catch {
|
|
249
|
-
// Router / AskUser failed — fall back to default model silently.
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
186
|
// gpt-image-2 reliably serves 1024x1024 only — other sizes time out at
|
|
253
187
|
// the gateway. Force the supported size regardless of caller / router
|
|
254
188
|
// input so we never burn USDC on a request that's going to abort.
|
|
@@ -280,6 +214,21 @@ function buildExecute(deps) {
|
|
|
280
214
|
};
|
|
281
215
|
}
|
|
282
216
|
}
|
|
217
|
+
// Confirm the spend before the paid call (parity with VideoGen). Pure price
|
|
218
|
+
// math — no LLM. Interactive callers (CLI / agent) get a prompt via
|
|
219
|
+
// onAskUser; direct callers (e.g. the desktop media path) pass no onAskUser
|
|
220
|
+
// and generate straight away — the explicit "generate" action is consent.
|
|
221
|
+
const autoApprove = process.env.FRANKLIN_MEDIA_AUTO_APPROVE_ALL === '1';
|
|
222
|
+
if (!autoApprove && ctx.onAskUser) {
|
|
223
|
+
const m = await findModel(imageModel);
|
|
224
|
+
const est = m ? estimateCostUsd(m, { quantity: n }) : 0;
|
|
225
|
+
const priceNote = est > 0 ? ` for ~$${est.toFixed(2)}` : '';
|
|
226
|
+
const countNote = n > 1 ? `${n} images` : 'an image';
|
|
227
|
+
const answer = await ctx.onAskUser(`Generate ${countNote} with ${imageModel}${priceNote}? No USDC is spent if you cancel.`, ['Generate', 'Cancel']);
|
|
228
|
+
if (answer !== 'Generate') {
|
|
229
|
+
return { output: `## Image generation cancelled\n\nNo USDC was spent.` };
|
|
230
|
+
}
|
|
231
|
+
}
|
|
283
232
|
// Resolve all reference images + the mask into base64 data URIs now, right
|
|
284
233
|
// before the paid call. Done after the cheap validations so bad paths /
|
|
285
234
|
// oversize attachments / unsupported combinations fail without any network
|
package/dist/tools/videogen.js
CHANGED
|
@@ -24,8 +24,6 @@ import { getOrCreateWallet, getOrCreateSolanaWallet, createPaymentPayload, creat
|
|
|
24
24
|
import { loadChain, API_URLS, VERSION } from '../config.js';
|
|
25
25
|
import { logger } from '../logger.js';
|
|
26
26
|
import { resolveReferenceImage } from './imagegen.js';
|
|
27
|
-
import { ModelClient } from '../agent/llm.js';
|
|
28
|
-
import { analyzeMediaRequest, renderProposalForAskUser } from '../agent/media-router.js';
|
|
29
27
|
import { recordUsage } from '../stats/tracker.js';
|
|
30
28
|
import { findModel, estimateCostUsd } from '../gateway-models.js';
|
|
31
29
|
// BytePlus RealFace asset IDs from the RealFace tool (after H5 liveness +
|
|
@@ -100,65 +98,27 @@ function buildExecute(deps) {
|
|
|
100
98
|
};
|
|
101
99
|
}
|
|
102
100
|
}
|
|
103
|
-
//
|
|
104
|
-
//
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
//
|
|
101
|
+
// Pure tool: use exactly the model + prompt + duration the caller gave.
|
|
102
|
+
// No LLM prompt-rewriting or model "routing" — the UI / agent decides those
|
|
103
|
+
// upstream. (This removes a second, flaky free-model call that used to time
|
|
104
|
+
// out and made "video generation" appear broken.)
|
|
105
|
+
const prompt = rawInput.prompt;
|
|
106
|
+
const videoModel = model || DEFAULT_MODEL;
|
|
107
|
+
const duration = duration_seconds ?? DEFAULT_DURATION;
|
|
108
|
+
const chosenPrompt = prompt;
|
|
109
|
+
// Video bills per second — confirm the cost before spending. This is pure
|
|
110
|
+
// price math (no LLM). Interactive callers (CLI / agent) get a prompt via
|
|
111
|
+
// onAskUser; direct callers (e.g. the desktop media path) pass no onAskUser
|
|
112
|
+
// and generate straight away — the explicit "generate" action is consent.
|
|
115
113
|
const autoApprove = process.env.FRANKLIN_MEDIA_AUTO_APPROVE_ALL === '1';
|
|
116
|
-
if (!
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
client,
|
|
125
|
-
signal: ctx.abortSignal,
|
|
126
|
-
skipRefine,
|
|
127
|
-
});
|
|
128
|
-
if (proposal) {
|
|
129
|
-
const { question, options } = renderProposalForAskUser(proposal, prompt);
|
|
130
|
-
const labels = options.map(o => o.label);
|
|
131
|
-
const answer = await ctx.onAskUser(question, labels);
|
|
132
|
-
const chosen = options.find(o => o.label === answer) ?? { id: 'cancel' };
|
|
133
|
-
switch (chosen.id) {
|
|
134
|
-
case 'cheaper':
|
|
135
|
-
videoModel = proposal.cheaper?.model ?? proposal.recommended.model;
|
|
136
|
-
break;
|
|
137
|
-
case 'premium':
|
|
138
|
-
videoModel = proposal.premium?.model ?? proposal.recommended.model;
|
|
139
|
-
break;
|
|
140
|
-
case 'cancel':
|
|
141
|
-
return {
|
|
142
|
-
output: `## Video generation cancelled\n\nNo USDC was spent.`,
|
|
143
|
-
};
|
|
144
|
-
case 'use-raw':
|
|
145
|
-
videoModel = proposal.recommended.model;
|
|
146
|
-
// chosenPrompt stays as the raw input
|
|
147
|
-
break;
|
|
148
|
-
case 'recommended':
|
|
149
|
-
default:
|
|
150
|
-
videoModel = proposal.recommended.model;
|
|
151
|
-
if (proposal.refinedPrompt)
|
|
152
|
-
chosenPrompt = proposal.refinedPrompt;
|
|
153
|
-
}
|
|
154
|
-
// Use the proposal's duration — the router honored the user's
|
|
155
|
-
// duration_seconds or filled in the model's default.
|
|
156
|
-
if (proposal.durationSeconds)
|
|
157
|
-
duration = proposal.durationSeconds;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
catch {
|
|
161
|
-
// Router / AskUser failed — fall through to legacy default.
|
|
114
|
+
if (!autoApprove && ctx.onAskUser) {
|
|
115
|
+
// Model-aware estimate so the quoted price matches the model we name in
|
|
116
|
+
// the prompt (flat per-second fallback only when the model is unknown).
|
|
117
|
+
const m = await findModel(videoModel);
|
|
118
|
+
const est = m ? estimateCostUsd(m, { duration_seconds: duration }) : estimateVideoCostUsd(duration);
|
|
119
|
+
const answer = await ctx.onAskUser(`Generate a ${duration}s video with ${videoModel} for ~$${est.toFixed(2)}? No USDC is spent if you cancel.`, ['Generate', 'Cancel']);
|
|
120
|
+
if (answer !== 'Generate') {
|
|
121
|
+
return { output: `## Video generation cancelled\n\nNo USDC was spent.` };
|
|
162
122
|
}
|
|
163
123
|
}
|
|
164
124
|
const estCost = estimateVideoCostUsd(duration);
|
package/package.json
CHANGED