nanobridge 0.2.1 → 0.2.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nanobridge",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Chrome Built-in AI CLI bridge to on-device language models via CDP",
5
5
  "type": "module",
6
6
  "bin": {
@@ -48,6 +48,7 @@ export function formatChatHelp(capabilities = {}) {
48
48
  ' /schema <file> Load JSON schema file (/schema clear to remove)',
49
49
  ' /context Show context window usage and token count',
50
50
  ' /settings Show current configuration and capabilities',
51
+ ' /continue, /c Continue previous generation if cut off by token limit',
51
52
  ' /clear Clear conversation history (keeps config & sampling)',
52
53
  ' /new Start a fresh session with default configuration',
53
54
  ' /history Show turn history',
@@ -138,21 +138,11 @@ export class ChatSessionManager {
138
138
 
139
139
  const stream = session.promptStreaming(${JSON.stringify(promptToSend)}, promptOpts);
140
140
  let finalOutput = '';
141
- let prev = '';
142
141
 
143
142
  for await (const chunk of stream) {
144
- let delta = '';
145
- if (chunk.startsWith(prev) && prev.length > 0) {
146
- delta = chunk.slice(prev.length);
147
- prev = chunk;
148
- finalOutput = chunk;
149
- } else {
150
- delta = chunk;
151
- prev = chunk;
143
+ if (chunk) {
152
144
  finalOutput += chunk;
153
- }
154
- if (delta) {
155
- console.debug('${prefix}' + JSON.stringify({ d: delta }));
145
+ console.debug('${prefix}' + JSON.stringify({ d: chunk }));
156
146
  }
157
147
  }
158
148
 
@@ -305,12 +305,11 @@ export class ChromeBridge {
305
305
  const session = await window.LanguageModel.create(${createArgs});
306
306
  const stream = session.promptStreaming(${escapedPrompt});
307
307
  let finalResult = '';
308
- let prev = '';
309
308
  for await (const chunk of stream) {
310
- finalResult = chunk;
311
- const delta = chunk.startsWith(prev) ? chunk.slice(prev.length) : chunk;
312
- prev = chunk;
313
- console.debug('${prefix}' + JSON.stringify({ d: delta }));
309
+ if (chunk) {
310
+ finalResult += chunk;
311
+ console.debug('${prefix}' + JSON.stringify({ d: chunk }));
312
+ }
314
313
  }
315
314
  if (typeof session.destroy === 'function') {
316
315
  session.destroy();
@@ -404,7 +403,7 @@ export class ChromeBridge {
404
403
  console.debug('${prefix}' + JSON.stringify({ type: 'first_chunk' }));
405
404
  }
406
405
  chunkCount++;
407
- finalOutput = chunk;
406
+ finalOutput += chunk;
408
407
  console.debug('${prefix}' + JSON.stringify({ type: 'chunk' }));
409
408
  }
410
409
 
@@ -82,14 +82,19 @@ ${style('Type', 'dim')} ${style('/help', 'yellow')} ${style('to see available co
82
82
  promptUser();
83
83
 
84
84
  for await (const line of rl) {
85
- const rawInput = line.trim();
85
+ let rawInput = line.trim();
86
86
 
87
87
  if (!rawInput) {
88
88
  promptUser();
89
89
  continue;
90
90
  }
91
91
 
92
- const parsed = parseCommand(rawInput);
92
+ let parsed = parseCommand(rawInput);
93
+
94
+ if (parsed.isCommand && (parsed.command === 'continue' || parsed.command === 'c')) {
95
+ rawInput = parsed.value ? `kaldığın yerden devam et: ${parsed.value}` : 'kaldığın yerden devam et';
96
+ parsed = { isCommand: false };
97
+ }
93
98
 
94
99
  if (parsed.isCommand) {
95
100
  const cmd = parsed.command;
@@ -384,7 +389,19 @@ Run ${style('/help', 'bold')} to see available commands.
384
389
 
385
390
  history.addTurn('user', finalPrompt);
386
391
  history.addTurn('assistant', accumulated);
387
- process.stdout.write('\n\n');
392
+ process.stdout.write('\n');
393
+
394
+ const trimmedAcc = (accumulated || '').trim();
395
+ const likelyTruncated = trimmedAcc.length > 300 &&
396
+ !/[.?!:;]\s*$/.test(trimmedAcc) &&
397
+ !trimmedAcc.endsWith('```') &&
398
+ !trimmedAcc.endsWith('}') &&
399
+ !trimmedAcc.endsWith(']');
400
+
401
+ if (likelyTruncated) {
402
+ log(style('↳ [Yanıt token sınırına ulaştı. Devam ettirmek için: "devam et" veya /c yazabilirsiniz]', 'dim'));
403
+ }
404
+ process.stdout.write('\n');
388
405
  } catch (err) {
389
406
  log(`\n${style('Error:', 'red')} ${err.message}\n`);
390
407
  } finally {
@@ -547,7 +547,6 @@ export class DaemonServer {
547
547
  ? session.promptStreaming(${escapedPrompt}, { responseConstraint: constraint })
548
548
  : session.promptStreaming(${escapedPrompt});
549
549
  let fullResult = '';
550
- let prev = '';
551
550
 
552
551
  for await (const chunk of stream) {
553
552
  if (window.__nanobridge_abort_req === '${reqId}') {
@@ -556,18 +555,9 @@ export class DaemonServer {
556
555
  }
557
556
  return { success: false, error: 'Request cancelled' };
558
557
  }
559
- let delta = '';
560
- if (chunk.startsWith(prev) && prev.length > 0) {
561
- delta = chunk.slice(prev.length);
562
- prev = chunk;
563
- fullResult = chunk;
564
- } else {
565
- delta = chunk;
566
- prev = chunk;
558
+ if (chunk) {
567
559
  fullResult += chunk;
568
- }
569
- if (delta) {
570
- console.debug('${prefix}' + JSON.stringify({ d: delta }));
560
+ console.debug('${prefix}' + JSON.stringify({ d: chunk }));
571
561
  }
572
562
  }
573
563
 
package/test/chat.test.js CHANGED
@@ -49,6 +49,8 @@ describe('Chat Slash Command Parser', () => {
49
49
  assert.strictEqual(parseCommand('/new').command, 'new');
50
50
  assert.strictEqual(parseCommand('/settings').command, 'settings');
51
51
  assert.strictEqual(parseCommand('/help').command, 'help');
52
+ assert.strictEqual(parseCommand('/continue').command, 'continue');
53
+ assert.strictEqual(parseCommand('/c').command, 'c');
52
54
  });
53
55
 
54
56
  test('recognizes exit aliases', () => {