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`.
|
||||
- `pdf-pages.js` shells out to `pdftotext -layout`, splits pages on `\f`, and appends prompts
|
||||
to `examples/prompts.log`.
|
||||
- `OpenRouterProvider._readStream` currently writes reasoning straight to `process.stdout`
|
||||
(debug-style side effect) rather than only via `onReasoning` — worth knowing if refactoring.
|
||||
- `OpenRouterProvider` streams reasoning cumulatively via `onReasoning`.
|
||||
|
||||
## Style conventions observed
|
||||
|
||||
|
||||
@@ -78,7 +78,6 @@ class OpenRouterProvider {
|
||||
const result = {};
|
||||
const state = { workingSent: false };
|
||||
let firstPayload = true;
|
||||
let completeReasoning = '';
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
@@ -94,14 +93,6 @@ class OpenRouterProvider {
|
||||
const payload = trimmed.slice(5).trim();
|
||||
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) {
|
||||
firstPayload = false;
|
||||
handlers.onStatus?.('streaming');
|
||||
@@ -111,12 +102,11 @@ class OpenRouterProvider {
|
||||
}
|
||||
}
|
||||
|
||||
if (completeReasoning) {
|
||||
result.reasoning = completeReasoning;
|
||||
if (result.reasoning) {
|
||||
if (Array.isArray(messages)) {
|
||||
messages.push({
|
||||
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 (!result.reasoning_details) result.reasoning_details = [];
|
||||
for (const rd of choice.delta.reasoning_details) {
|
||||
const slot = result.reasoning_details[rd.index] ||= { type: rd.type, format: rd.format, text: '' };
|
||||
if (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