u
This commit is contained in:
@@ -66,8 +66,7 @@ system prompt). `orbiter.abort(reason)` cancels the active run; aborts surface a
|
|||||||
- `.gitignore` ignores `node_modules/`, `examples/.env`, `examples/invoice.pdf`.
|
- `.gitignore` ignores `node_modules/`, `examples/.env`, `examples/invoice.pdf`.
|
||||||
- `pdf-pages.js` shells out to `pdftotext -layout`, splits pages on `\f`, and appends prompts
|
- `pdf-pages.js` shells out to `pdftotext -layout`, splits pages on `\f`, and appends prompts
|
||||||
to `examples/prompts.log`.
|
to `examples/prompts.log`.
|
||||||
- `OpenRouterProvider._readStream` currently writes reasoning straight to `process.stdout`
|
- `OpenRouterProvider` streams reasoning cumulatively via `onReasoning`.
|
||||||
(debug-style side effect) rather than only via `onReasoning` — worth knowing if refactoring.
|
|
||||||
|
|
||||||
## Style conventions observed
|
## Style conventions observed
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,6 @@ class OpenRouterProvider {
|
|||||||
const result = {};
|
const result = {};
|
||||||
const state = { workingSent: false };
|
const state = { workingSent: false };
|
||||||
let firstPayload = true;
|
let firstPayload = true;
|
||||||
let completeReasoning = '';
|
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const { done, value } = await reader.read();
|
const { done, value } = await reader.read();
|
||||||
@@ -94,14 +93,6 @@ class OpenRouterProvider {
|
|||||||
const payload = trimmed.slice(5).trim();
|
const payload = trimmed.slice(5).trim();
|
||||||
if (payload === '[DONE]') continue;
|
if (payload === '[DONE]') continue;
|
||||||
|
|
||||||
//console.log('OpenRouter SSE payload:', payload);
|
|
||||||
const payloadObj = JSON.parse(payload);
|
|
||||||
const reasoning = payloadObj.choices?.[0].delta.reasoning;
|
|
||||||
if (reasoning) {
|
|
||||||
process.stdout.write(reasoning);
|
|
||||||
completeReasoning += reasoning;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (firstPayload) {
|
if (firstPayload) {
|
||||||
firstPayload = false;
|
firstPayload = false;
|
||||||
handlers.onStatus?.('streaming');
|
handlers.onStatus?.('streaming');
|
||||||
@@ -111,12 +102,11 @@ class OpenRouterProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (completeReasoning) {
|
if (result.reasoning) {
|
||||||
result.reasoning = completeReasoning;
|
|
||||||
if (Array.isArray(messages)) {
|
if (Array.isArray(messages)) {
|
||||||
messages.push({
|
messages.push({
|
||||||
role: 'assistant',
|
role: 'assistant',
|
||||||
content: completeReasoning,
|
content: result.reasoning,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,14 +154,20 @@ class OpenRouterProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reasoning
|
// Reasoning (delta.reasoning or delta.reasoning_details)
|
||||||
|
if (choice.delta?.reasoning) {
|
||||||
|
result.reasoning = (result.reasoning || '') + choice.delta.reasoning;
|
||||||
|
onReasoning?.(result.reasoning);
|
||||||
|
}
|
||||||
|
|
||||||
if (choice.delta?.reasoning_details) {
|
if (choice.delta?.reasoning_details) {
|
||||||
if (!result.reasoning_details) result.reasoning_details = [];
|
if (!result.reasoning_details) result.reasoning_details = [];
|
||||||
for (const rd of choice.delta.reasoning_details) {
|
for (const rd of choice.delta.reasoning_details) {
|
||||||
const slot = result.reasoning_details[rd.index] ||= { type: rd.type, format: rd.format, text: '' };
|
const slot = result.reasoning_details[rd.index] ||= { type: rd.type, format: rd.format, text: '' };
|
||||||
if (rd.text) {
|
if (rd.text) {
|
||||||
slot.text += rd.text;
|
slot.text += rd.text;
|
||||||
onReasoning?.(slot.text);
|
result.reasoning = (result.reasoning || '') + rd.text;
|
||||||
|
onReasoning?.(result.reasoning);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user