@code-yeongyu/senpi-agent-core 2026.8.7 → 2026.8.9-2
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"empty-assistant-recovery.d.ts","sourceRoot":"","sources":["../src/empty-assistant-recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,GAAG,
|
|
1
|
+
{"version":3,"file":"empty-assistant-recovery.d.ts","sourceRoot":"","sources":["../src/empty-assistant-recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,GAAG,EAQR,KAAK,KAAK,EAEV,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAqG3C,wBAAgB,0BAA0B,CAAC,IAAI,SAAS,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,cAAc,EAAE,QAAQ,GAAG,QAAQ,CAMnH"}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import { createAssistantMessageEventStream,
|
|
1
|
+
import { createAssistantMessageEventStream, getToolCallFormat, hasVisibleAssistantContent, hasVisibleText, shouldRecoverTextToolCalls, } from "@earendil-works/pi-ai";
|
|
2
2
|
const EMPTY_RESPONSE_ERROR = "Model returned an empty response twice";
|
|
3
|
-
function hasVisibleContent(message) {
|
|
4
|
-
return message.content.some((block) => block.type === "toolCall" || (block.type === "text" && block.text.trim().length > 0));
|
|
5
|
-
}
|
|
6
3
|
function isEmptyStop(message) {
|
|
7
|
-
return message.stopReason === "stop" && !
|
|
4
|
+
return message.stopReason === "stop" && !hasVisibleAssistantContent(message);
|
|
8
5
|
}
|
|
9
6
|
function eventStartsVisibleContent(event) {
|
|
10
|
-
return event.type === "toolcall_start" || (event.type === "text_delta" && event.delta
|
|
7
|
+
return event.type === "toolcall_start" || (event.type === "text_delta" && hasVisibleText(event.delta));
|
|
11
8
|
}
|
|
12
9
|
function appendRetryDiagnostic(message) {
|
|
13
10
|
return {
|
|
@@ -96,7 +93,7 @@ function createRetryingStream(firstStream, createStream) {
|
|
|
96
93
|
return outerStream;
|
|
97
94
|
}
|
|
98
95
|
export function withEmptyAssistantRecovery(model, streamFunction) {
|
|
99
|
-
if (!
|
|
96
|
+
if (!shouldRecoverTextToolCalls(model) && getToolCallFormat(model) === undefined)
|
|
100
97
|
return streamFunction;
|
|
101
98
|
return async (requestedModel, context, options) => {
|
|
102
99
|
const createStream = () => streamFunction(requestedModel, context, options);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"empty-assistant-recovery.js","sourceRoot":"","sources":["../src/empty-assistant-recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,iCAAiC,EACjC,
|
|
1
|
+
{"version":3,"file":"empty-assistant-recovery.js","sourceRoot":"","sources":["../src/empty-assistant-recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,iCAAiC,EACjC,iBAAiB,EACjB,0BAA0B,EAC1B,cAAc,EAEd,0BAA0B,GAC1B,MAAM,uBAAuB,CAAC;AAK/B,MAAM,oBAAoB,GAAG,wCAAwC,CAAC;AAEtE,SAAS,WAAW,CAAC,OAAyB;IAC7C,OAAO,OAAO,CAAC,UAAU,KAAK,MAAM,IAAI,CAAC,0BAA0B,CAAC,OAAO,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,yBAAyB,CAAC,KAA4B;IAC9D,OAAO,KAAK,CAAC,IAAI,KAAK,gBAAgB,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,YAAY,IAAI,cAAc,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AACxG,CAAC;AAED,SAAS,qBAAqB,CAAC,OAAyB;IACvD,OAAO;QACN,GAAG,OAAO;QACV,WAAW,EAAE;YACZ,GAAG,CAAC,OAAO,CAAC,WAAW,IAAI,EAAE,CAAC;YAC9B;gBACC,IAAI,EAAE,mCAAmC;gBACzC,SAAS,E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CAAC,MAAM,EAAE,CAAC,CAAC;oBACjG,OAAO;gBACR,CAAC;gBACD,QAAQ,GAAG,IAAI,CAAC;gBAChB,MAAM,GAAG,MAAM,YAAY,EAAE,CAAC;YAC/B,CAAC;QACF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzB,CAAC;IACF,CAAC,CAAC,EAAE,CAAC;IAEL,OAAO,WAAW,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAmB,KAAkB,EAAE,cAAwB;IACxG,IAAI,CAAC,0BAA0B,CAAC,KAAK,CAAC,IAAI,iBAAiB,CAAC,KAAK,CAAC,KAAK,SAAS;QAAE,OAAO,cAAc,CAAC;IACxG,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE;QACjD,MAAM,YAAY,GAAG,GAAyB,EAAE,CAAC,cAAc,CAAC,cAAc,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAClG,OAAO,oBAAoB,CAAC,MAAM,YAAY,EAAE,EAAE,YAAY,CAAC,CAAC;IACjE,CAAC,CAAC;AACH,CAAC","sourcesContent":["import {\n\ttype Api,\n\ttype AssistantMessage,\n\ttype AssistantMessageEvent,\n\ttype AssistantMessageEventStream,\n\tcreateAssistantMessageEventStream,\n\tgetToolCallFormat,\n\thasVisibleAssistantContent,\n\thasVisibleText,\n\ttype Model,\n\tshouldRecoverTextToolCalls,\n} from \"@earendil-works/pi-ai\";\nimport type { StreamFn } from \"./types.ts\";\n\ntype StreamFactory = () => AssistantMessageEventStream | Promise<AssistantMessageEventStream>;\n\nconst EMPTY_RESPONSE_ERROR = \"Model returned an empty response twice\";\n\nfunction isEmptyStop(message: AssistantMessage): boolean {\n\treturn message.stopReason === \"stop\" && !hasVisibleAssistantContent(message);\n}\n\nfunction eventStartsVisibleContent(event: AssistantMessageEvent): boolean {\n\treturn event.type === \"toolcall_start\" || (event.type === \"text_delta\" && hasVisibleText(event.delta));\n}\n\nfunction appendRetryDiagnostic(message: AssistantMessage): AssistantMessage {\n\treturn {\n\t\t...message,\n\t\tdiagnostics: [\n\t\t\t...(message.diagnostics ?? []),\n\t\t\t{\n\t\t\t\ttype: \"empty_assistant_response_recovery\",\n\t\t\t\ttimestamp: Date.now(),\n\t\t\t\tdetails: { retries: 1 },\n\t\t\t},\n\t\t],\n\t};\n}\n\nfunction createEmptyResponseFailure(message: AssistantMessage): AssistantMessage {\n\treturn {\n\t\t...appendRetryDiagnostic(message),\n\t\tcontent: [{ type: \"text\", text: EMPTY_RESPONSE_ERROR }],\n\t\tstopReason: \"error\",\n\t\terrorMessage: EMPTY_RESPONSE_ERROR,\n\t};\n}\n\nfunction createRetryingStream(firstStream: AssistantMessageEventStream, createStream: StreamFactory) {\n\tconst outerStream = createAssistantMessageEventStream();\n\n\tvoid (async (): Promise<void> => {\n\t\ttry {\n\t\t\tlet stream = firstStream;\n\t\t\tlet retrying = false;\n\t\t\tfor (;;) {\n\t\t\t\tconst buffered: AssistantMessageEvent[] = [];\n\t\t\t\tlet forwarding = false;\n\t\t\t\tlet retry = false;\n\t\t\t\tfor await (const event of stream) {\n\t\t\t\t\tif (event.type === \"done\") {\n\t\t\t\t\t\tif (isEmptyStop(event.message)) {\n\t\t\t\t\t\t\tif (!retrying) {\n\t\t\t\t\t\t\t\tretry = true;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst error = createEmptyResponseFailure(event.message);\n\t\t\t\t\t\t\touterStream.push({ type: \"error\", reason: \"error\", error });\n\t\t\t\t\t\t\touterStream.end();\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst terminal = retrying ? { ...event, message: appendRetryDiagnostic(event.message) } : event;\n\t\t\t\t\t\tif (!forwarding) {\n\t\t\t\t\t\t\tfor (const pending of buffered) outerStream.push(pending);\n\t\t\t\t\t\t}\n\t\t\t\t\t\touterStream.push(terminal);\n\t\t\t\t\t\touterStream.end();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (event.type === \"error\") {\n\t\t\t\t\t\tif (!forwarding) {\n\t\t\t\t\t\t\tfor (const pending of buffered) outerStream.push(pending);\n\t\t\t\t\t\t}\n\t\t\t\t\t\touterStream.push(event);\n\t\t\t\t\t\touterStream.end();\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif (forwarding) {\n\t\t\t\t\t\touterStream.push(event);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tbuffered.push(event);\n\t\t\t\t\tif (eventStartsVisibleContent(event)) {\n\t\t\t\t\t\tfor (const pending of buffered) outerStream.push(pending);\n\t\t\t\t\t\tforwarding = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (!retry) {\n\t\t\t\t\touterStream.end(retrying ? appendRetryDiagnostic(await stream.result()) : await stream.result());\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tretrying = true;\n\t\t\t\tstream = await createStream();\n\t\t\t}\n\t\t} catch (error) {\n\t\t\touterStream.fail(error);\n\t\t}\n\t})();\n\n\treturn outerStream;\n}\n\nexport function withEmptyAssistantRecovery<TApi extends Api>(model: Model<TApi>, streamFunction: StreamFn): StreamFn {\n\tif (!shouldRecoverTextToolCalls(model) && getToolCallFormat(model) === undefined) return streamFunction;\n\treturn async (requestedModel, context, options) => {\n\t\tconst createStream = (): ReturnType<StreamFn> => streamFunction(requestedModel, context, options);\n\t\treturn createRetryingStream(await createStream(), createStream);\n\t};\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-yeongyu/senpi-agent-core",
|
|
3
|
-
"version": "2026.8.
|
|
3
|
+
"version": "2026.8.9-2",
|
|
4
4
|
"description": "General-purpose agent with transport abstraction, state management, and attachment support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"prepublishOnly": "npm run build"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.8.
|
|
32
|
+
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.8.9-2",
|
|
33
33
|
"diff": "9.0.0",
|
|
34
34
|
"ignore": "7.0.6",
|
|
35
35
|
"typebox": "1.3.8",
|