@code-yeongyu/senpi-ai 2026.7.29 → 2026.7.30-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.
Files changed (45) hide show
  1. package/dist/api/openai-completions.d.ts.map +1 -1
  2. package/dist/api/openai-completions.js +121 -38
  3. package/dist/api/openai-completions.js.map +1 -1
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/providers/data/.manifest.json +1 -1
  9. package/dist/providers/data/openrouter.json +1 -1
  10. package/dist/providers/data/vercel-ai-gateway.json +1 -1
  11. package/dist/tool-call-middleware/index.d.ts +2 -1
  12. package/dist/tool-call-middleware/index.d.ts.map +1 -1
  13. package/dist/tool-call-middleware/index.js +13 -0
  14. package/dist/tool-call-middleware/index.js.map +1 -1
  15. package/dist/tool-call-middleware/protocols/kimi-xtml/recovery-stream.js +2 -2
  16. package/dist/tool-call-middleware/protocols/kimi-xtml/recovery-stream.js.map +1 -1
  17. package/dist/tool-call-middleware/protocols/kimi-xtml/thinking-recovery-stream.d.ts +3 -0
  18. package/dist/tool-call-middleware/protocols/kimi-xtml/thinking-recovery-stream.d.ts.map +1 -0
  19. package/dist/tool-call-middleware/protocols/kimi-xtml/thinking-recovery-stream.js +29 -0
  20. package/dist/tool-call-middleware/protocols/kimi-xtml/thinking-recovery-stream.js.map +1 -0
  21. package/dist/tool-call-middleware/protocols/kimi-xtml/thinking-recovery.d.ts +3 -0
  22. package/dist/tool-call-middleware/protocols/kimi-xtml/thinking-recovery.d.ts.map +1 -0
  23. package/dist/tool-call-middleware/protocols/kimi-xtml/thinking-recovery.js +82 -0
  24. package/dist/tool-call-middleware/protocols/kimi-xtml/thinking-recovery.js.map +1 -0
  25. package/dist/tool-call-middleware/recovery-diagnostics.d.ts +2 -1
  26. package/dist/tool-call-middleware/recovery-diagnostics.d.ts.map +1 -1
  27. package/dist/tool-call-middleware/recovery-diagnostics.js +2 -2
  28. package/dist/tool-call-middleware/recovery-diagnostics.js.map +1 -1
  29. package/dist/tool-call-middleware/recovery-native-projection.d.ts +3 -2
  30. package/dist/tool-call-middleware/recovery-native-projection.d.ts.map +1 -1
  31. package/dist/tool-call-middleware/recovery-native-projection.js +3 -2
  32. package/dist/tool-call-middleware/recovery-native-projection.js.map +1 -1
  33. package/dist/tool-call-middleware/recovery-stream-failure.d.ts +6 -1
  34. package/dist/tool-call-middleware/recovery-stream-failure.d.ts.map +1 -1
  35. package/dist/tool-call-middleware/recovery-stream-failure.js +3 -2
  36. package/dist/tool-call-middleware/recovery-stream-failure.js.map +1 -1
  37. package/dist/tool-call-middleware/recovery-stream-wrapper.d.ts +6 -1
  38. package/dist/tool-call-middleware/recovery-stream-wrapper.d.ts.map +1 -1
  39. package/dist/tool-call-middleware/recovery-stream-wrapper.js +11 -5
  40. package/dist/tool-call-middleware/recovery-stream-wrapper.js.map +1 -1
  41. package/dist/tool-call-middleware/recovery-text-projection.d.ts +6 -1
  42. package/dist/tool-call-middleware/recovery-text-projection.d.ts.map +1 -1
  43. package/dist/tool-call-middleware/recovery-text-projection.js +6 -4
  44. package/dist/tool-call-middleware/recovery-text-projection.js.map +1 -1
  45. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"recovery-stream-wrapper.js","sourceRoot":"","sources":["../../src/tool-call-middleware/recovery-stream-wrapper.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qCAAqC,EAAE,MAAM,sCAAsC,CAAC;AAC7F,OAAO,EAA4B,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AACrG,OAAO,EAAE,mCAAmC,EAAE,MAAM,4BAA4B,CAAC;AACjF,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAA8B,iCAAiC,EAAE,MAAM,8BAA8B,CAAC;AAC7G,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAA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AM;gBACR,CAAC;YACF,CAAC;YAED,IAAI,qBAAqB,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE;gBAAE,OAAO;YACrE,UAAU,EAAE,CAAC;YACb,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAChC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,IAAI,qBAAqB,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE;gBAAE,OAAO;YACrE,UAAU,EAAE,CAAC;YACb,QAAQ,CAAC,eAAe,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QAC7C,CAAC;IACF,CAAC,CAAC,EAAE,CAAC;IAEL,OAAO,WAAW,CAAC;AACpB,CAAC","sourcesContent":["import type { AssistantMessage, AssistantMessageEvent, AssistantMessageEventStream, Tool } from \"../types.ts\";\nimport type { RecoveryStreamParser } from \"./protocols/anthropic-xml/recovery-stream.ts\";\nimport { createAntmlInvokeRecoveryStreamParser } from \"./protocols/antml/recovery-stream.ts\";\nimport { type RecoveryContentKind, RecoveryContentLifecycle } from \"./recovery-content-lifecycle.ts\";\nimport { RecoveryAssistantMessageEventStream } from \"./recovery-event-stream.ts\";\nimport { RecoveryNativeProjection } from \"./recovery-native-projection.ts\";\nimport { type RecoveryStreamFailure, terminateRecoveryStreamForFailure } from \"./recovery-stream-failure.ts\";\nimport { RecoveryStreamTerminal } from \"./recovery-stream-terminal.ts\";\nimport { RecoveryTextProjection } from \"./recovery-text-projection.ts\";\nimport { StreamMessageProjection } from \"./stream-wrapper-shared.ts\";\n\nexport function wrapStreamWithInvokeRecovery(\n\tinnerStream: AssistantMessageEventStream,\n\ttools: readonly Tool[],\n\tcreateParser: (tools: readonly Tool[]) => RecoveryStreamParser = createAntmlInvokeRecoveryStreamParser,\n): AssistantMessageEventStream {\n\tconst outerStream = new RecoveryAssistantMessageEventStream();\n\n\tvoid (async (): Promise<void> => {\n\t\tconst innerIterator = innerStream[Symbol.asyncIterator]();\n\t\tconst innerEvents: AsyncIterable<AssistantMessageEvent> = { [Symbol.asyncIterator]: () => innerIterator };\n\t\tlet projection: StreamMessageProjection | null = null;\n\t\tlet nativeProjection: RecoveryNativeProjection | null = null;\n\t\tlet textProjection: RecoveryTextProjection | null = null;\n\t\tlet sawToolCall = false;\n\t\tlet cancellationRequested = false;\n\t\tconst contentLifecycle = new RecoveryContentLifecycle();\n\t\tconst terminal = new RecoveryStreamTerminal(outerStream);\n\n\t\tconst finishText = (): void => {\n\t\t\tif (!textProjection) return;\n\t\t\tsawToolCall = textProjection.finish() || sawToolCall;\n\t\t\ttextProjection = null;\n\t\t};\n\n\t\touterStream.setCancellationHandler(async () => {\n\t\t\tcancellationRequested = true;\n\t\t\ttry {\n\t\t\t\tawait innerIterator.return?.();\n\t\t\t\tfinishText();\n\t\t\t\tterminal.cancelled(projection);\n\t\t\t} catch (error) {\n\t\t\t\tfinishText();\n\t\t\t\tterminal.iteratorFailure(projection, error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t});\n\n\t\tconst terminateForFailure = (source: AssistantMessage, failure: RecoveryStreamFailure): void => {\n\t\t\tif (!projection || !outerStream.markSourceClosed()) return;\n\t\t\tfinishText();\n\t\t\tterminateRecoveryStreamForFailure(outerStream, projection, source, failure);\n\t\t};\n\n\t\tconst prepareContentEvent = (source: AssistantMessage, contentIndex: number): boolean => {\n\t\t\tif (!projection || !nativeProjection) return false;\n\t\t\tif (!Number.isSafeInteger(contentIndex) || contentIndex < 0 || contentIndex >= source.content.length) {\n\t\t\t\tterminateForFailure(source, \"invalid_native_event_order\");\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tprojection.sync(source);\n\t\t\tnativeProjection.reserveVisibleIds(source);\n\t\t\tif (nativeProjection.synchronizeLower(source, contentIndex)) return true;\n\t\t\tterminateForFailure(source, \"collision\");\n\t\t\treturn false;\n\t\t};\n\n\t\tconst canStart = (\n\t\t\tsource: AssistantMessage,\n\t\t\tcontentIndex: number,\n\t\t\tkind: RecoveryContentKind,\n\t\t\tfailure: RecoveryStreamFailure = \"invalid_content_event_order\",\n\t\t): boolean => {\n\t\t\tif (!Number.isSafeInteger(contentIndex) || contentIndex < 0 || contentIndex >= source.content.length) {\n\t\t\t\tterminateForFailure(source, failure);\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tconst block = source.content[contentIndex];\n\t\t\tconst blockMatches =\n\t\t\t\t(kind === \"text\" && block?.type === \"text\") ||\n\t\t\t\t(kind === \"thinking\" && block?.type === \"thinking\") ||\n\t\t\t\t(kind === \"toolCall\" && block?.type === \"toolCall\");\n\t\t\tif (blockMatches && contentLifecycle.canStart(contentIndex)) return true;\n\t\t\tterminateForFailure(source, failure);\n\t\t\treturn false;\n\t\t};\n\n\t\tconst isActive = (\n\t\t\tsource: AssistantMessage,\n\t\t\tcontentIndex: number,\n\t\t\tkind: RecoveryContentKind,\n\t\t\tfailure: RecoveryStreamFailure = \"invalid_content_event_order\",\n\t\t): boolean => {\n\t\t\tif (contentLifecycle.isActive(contentIndex, kind)) return true;\n\t\t\tterminateForFailure(source, failure);\n\t\t\treturn false;\n\t\t};\n\n\t\tconst synchronizeTerminal = (source: AssistantMessage): boolean => {\n\t\t\tprojection ??= new StreamMessageProjection(outerStream, source, { preserveSourceMetadata: true });\n\t\t\tnativeProjection ??= new RecoveryNativeProjection(outerStream, projection.message);\n\t\t\tprojection.sync(source);\n\t\t\tnativeProjection.reserveVisibleIds(source);\n\t\t\tfinishText();\n\t\t\tif (nativeProjection.synchronizeRemaining(source)) return true;\n\t\t\tterminateForFailure(source, \"collision\");\n\t\t\treturn false;\n\t\t};\n\n\t\ttry {\n\t\t\tfor await (const event of innerEvents) {\n\t\t\t\tif (cancellationRequested) continue;\n\t\t\t\tswitch (event.type) {\n\t\t\t\t\tcase \"start\":\n\t\t\t\t\t\tprojection = new StreamMessageProjection(outerStream, event.partial, {\n\t\t\t\t\t\t\tpreserveSourceMetadata: true,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tnativeProjection = new RecoveryNativeProjection(outerStream, projection.message);\n\t\t\t\t\t\tnativeProjection.reserveVisibleIds(event.partial);\n\t\t\t\t\t\touterStream.push({ type: \"start\", partial: projection.message });\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"text_start\": {\n\t\t\t\t\t\tif (!canStart(event.partial, event.contentIndex, \"text\")) return;\n\t\t\t\t\t\tif (!prepareContentEvent(event.partial, event.contentIndex) || !projection || !nativeProjection)\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\tconst nextText = new RecoveryTextProjection(\n\t\t\t\t\t\t\ttools,\n\t\t\t\t\t\t\tprojection,\n\t\t\t\t\t\t\tnativeProjection,\n\t\t\t\t\t\t\tevent.contentIndex,\n\t\t\t\t\t\t\tcreateParser,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (!nextText.start(event.partial)) {\n\t\t\t\t\t\t\tterminateForFailure(event.partial, \"invalid_native_event_order\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttextProjection = nextText;\n\t\t\t\t\t\tcontentLifecycle.start(event.contentIndex, \"text\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"text_delta\":\n\t\t\t\t\t\tif (!isActive(event.partial, event.contentIndex, \"text\")) return;\n\t\t\t\t\t\tif (!prepareContentEvent(event.partial, event.contentIndex) || !textProjection) return;\n\t\t\t\t\t\tsawToolCall = textProjection.feed(event.delta) || sawToolCall;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"text_end\":\n\t\t\t\t\t\tif (!isActive(event.partial, event.contentIndex, \"text\")) return;\n\t\t\t\t\t\tif (!prepareContentEvent(event.partial, event.contentIndex)) return;\n\t\t\t\t\t\tfinishText();\n\t\t\t\t\t\tcontentLifecycle.end(event.contentIndex, \"text\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"done\":\n\t\t\t\t\t\tif (!synchronizeTerminal(event.message) || !projection) return;\n\t\t\t\t\t\tif (!outerStream.markSourceClosed()) return;\n\t\t\t\t\t\tterminal.done(projection, event.message, sawToolCall, event.reason);\n\t\t\t\t\t\treturn;\n\t\t\t\t\tcase \"error\":\n\t\t\t\t\t\tif (!projection) {\n\t\t\t\t\t\t\tif (!outerStream.markSourceClosed()) return;\n\t\t\t\t\t\t\touterStream.push(event);\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\tif (!synchronizeTerminal(event.error)) return;\n\t\t\t\t\t\tif (!outerStream.markSourceClosed()) return;\n\t\t\t\t\t\tterminal.sourceError(projection, event.error, sawToolCall, event.reason);\n\t\t\t\t\t\treturn;\n\t\t\t\t\tcase \"toolcall_start\": {\n\t\t\t\t\t\tif (!canStart(event.partial, event.contentIndex, \"toolCall\", \"invalid_native_event_order\")) return;\n\t\t\t\t\t\tif (!prepareContentEvent(event.partial, event.contentIndex) || !nativeProjection) return;\n\t\t\t\t\t\tconst status = nativeProjection.projectNativeStart(event.partial, event.contentIndex);\n\t\t\t\t\t\tif (status !== \"projected\") {\n\t\t\t\t\t\t\tterminateForFailure(\n\t\t\t\t\t\t\t\tevent.partial,\n\t\t\t\t\t\t\t\tstatus === \"collision\" ? \"collision\" : \"invalid_native_event_order\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontentLifecycle.start(event.contentIndex, \"toolCall\");\n\t\t\t\t\t\tsawToolCall = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"toolcall_delta\":\n\t\t\t\t\t\tif (!isActive(event.partial, event.contentIndex, \"toolCall\", \"invalid_native_event_order\")) return;\n\t\t\t\t\t\tif (!prepareContentEvent(event.partial, event.contentIndex) || !nativeProjection) return;\n\t\t\t\t\t\tif (!nativeProjection.projectNativeDelta(event.partial, event.contentIndex, event.delta)) {\n\t\t\t\t\t\t\tterminateForFailure(event.partial, \"invalid_native_event_order\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"toolcall_end\":\n\t\t\t\t\t\tif (!isActive(event.partial, event.contentIndex, \"toolCall\", \"invalid_native_event_order\")) return;\n\t\t\t\t\t\tif (!prepareContentEvent(event.partial, event.contentIndex) || !nativeProjection) return;\n\t\t\t\t\t\tif (!nativeProjection.projectNativeEnd(event.contentIndex, event.toolCall)) {\n\t\t\t\t\t\t\tterminateForFailure(event.partial, \"invalid_native_event_order\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontentLifecycle.end(event.contentIndex, \"toolCall\");\n\t\t\t\t\t\tsawToolCall = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"thinking_start\": {\n\t\t\t\t\t\tif (!canStart(event.partial, event.contentIndex, \"thinking\")) return;\n\t\t\t\t\t\tif (!prepareContentEvent(event.partial, event.contentIndex) || !projection || !nativeProjection)\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\tconst outerIndex = projection.startThinking(event.contentIndex, event.partial);\n\t\t\t\t\t\tif (!nativeProjection.recordProjectedBlock(event.contentIndex, outerIndex)) {\n\t\t\t\t\t\t\tterminateForFailure(event.partial, \"invalid_native_event_order\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontentLifecycle.start(event.contentIndex, \"thinking\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"thinking_delta\":\n\t\t\t\t\t\tif (!isActive(event.partial, event.contentIndex, \"thinking\")) return;\n\t\t\t\t\t\tif (!prepareContentEvent(event.partial, event.contentIndex) || !projection) return;\n\t\t\t\t\t\tprojection.projectThinkingDelta(event.contentIndex, event.delta, event.partial);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"thinking_end\":\n\t\t\t\t\t\tif (!isActive(event.partial, event.contentIndex, \"thinking\")) return;\n\t\t\t\t\t\tif (!prepareContentEvent(event.partial, event.contentIndex) || !projection) return;\n\t\t\t\t\t\tprojection.finishThinking(event.contentIndex, event.content, event.partial);\n\t\t\t\t\t\tcontentLifecycle.end(event.contentIndex, \"thinking\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (cancellationRequested || !outerStream.markSourceClosed()) return;\n\t\t\tfinishText();\n\t\t\tterminal.exhausted(projection);\n\t\t} catch (error) {\n\t\t\tif (cancellationRequested || !outerStream.markSourceClosed()) return;\n\t\t\tfinishText();\n\t\t\tterminal.iteratorFailure(projection, error);\n\t\t}\n\t})();\n\n\treturn outerStream;\n}\n"]}
1
+ {"version":3,"file":"recovery-stream-wrapper.js","sourceRoot":"","sources":["../../src/tool-call-middleware/recovery-stream-wrapper.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qCAAqC,EAAE,MAAM,sCAAsC,CAAC;AAC7F,OAAO,EAA4B,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AACrG,OAAO,EAAE,mCAAmC,EAAE,MAAM,4BAA4B,CAAC;AACjF,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAA8B,iCAAiC,EAAE,MAAM,8BAA8B,CAAC;AAC7G,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAQrE,MAAM,UAAU,4BAA4B,CAC3C,WAAwC,EACxC,KAAsB,EACtB,OAAO,GAA+E,EAAE;IAExF,MAAM,WAAW,GAAG,IAAI,mCAAmC,EAAE,CAAC;IAC9D,MAAM,eAAe,GAAG,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IAC5F,MAAM,YAAY,GAA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B,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE;gBAAE,OAAO;YACrE,UAAU,EAAE,CAAC;YACb,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAChC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,IAAI,qBAAqB,IAAI,CAAC,WAAW,CAAC,gBAAgB,EAAE;gBAAE,OAAO;YACrE,UAAU,EAAE,CAAC;YACb,QAAQ,CAAC,eAAe,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;QAC7C,CAAC;IACF,CAAC,CAAC,EAAE,CAAC;IAEL,OAAO,WAAW,CAAC;AACpB,CAAC","sourcesContent":["import type { AssistantMessage, AssistantMessageEvent, AssistantMessageEventStream, Tool } from \"../types.ts\";\nimport type { RecoveryStreamParser } from \"./protocols/anthropic-xml/recovery-stream.ts\";\nimport { createAntmlInvokeRecoveryStreamParser } from \"./protocols/antml/recovery-stream.ts\";\nimport { type RecoveryContentKind, RecoveryContentLifecycle } from \"./recovery-content-lifecycle.ts\";\nimport { RecoveryAssistantMessageEventStream } from \"./recovery-event-stream.ts\";\nimport { RecoveryNativeProjection } from \"./recovery-native-projection.ts\";\nimport { type RecoveryStreamFailure, terminateRecoveryStreamForFailure } from \"./recovery-stream-failure.ts\";\nimport { RecoveryStreamTerminal } from \"./recovery-stream-terminal.ts\";\nimport { RecoveryTextProjection } from \"./recovery-text-projection.ts\";\nimport { StreamMessageProjection } from \"./stream-wrapper-shared.ts\";\nimport type { ToolCallFormat } from \"./types.ts\";\n\nexport interface InvokeRecoveryOptions {\n\tcreateParser?: (tools: readonly Tool[]) => RecoveryStreamParser;\n\tprotocol?: ToolCallFormat;\n}\n\nexport function wrapStreamWithInvokeRecovery(\n\tinnerStream: AssistantMessageEventStream,\n\ttools: readonly Tool[],\n\toptions: InvokeRecoveryOptions | ((tools: readonly Tool[]) => RecoveryStreamParser) = {},\n): AssistantMessageEventStream {\n\tconst outerStream = new RecoveryAssistantMessageEventStream();\n\tconst resolvedOptions = typeof options === \"function\" ? { createParser: options } : options;\n\tconst createParser = resolvedOptions.createParser ?? createAntmlInvokeRecoveryStreamParser;\n\tconst protocol = resolvedOptions.protocol ?? \"antml\";\n\n\tvoid (async (): Promise<void> => {\n\t\tconst innerIterator = innerStream[Symbol.asyncIterator]();\n\t\tconst innerEvents: AsyncIterable<AssistantMessageEvent> = { [Symbol.asyncIterator]: () => innerIterator };\n\t\tlet projection: StreamMessageProjection | null = null;\n\t\tlet nativeProjection: RecoveryNativeProjection | null = null;\n\t\tlet textProjection: RecoveryTextProjection | null = null;\n\t\tlet sawToolCall = false;\n\t\tlet cancellationRequested = false;\n\t\tconst contentLifecycle = new RecoveryContentLifecycle();\n\t\tconst terminal = new RecoveryStreamTerminal(outerStream);\n\n\t\tconst finishText = (): void => {\n\t\t\tif (!textProjection) return;\n\t\t\tsawToolCall = textProjection.finish() || sawToolCall;\n\t\t\ttextProjection = null;\n\t\t};\n\n\t\touterStream.setCancellationHandler(async () => {\n\t\t\tcancellationRequested = true;\n\t\t\ttry {\n\t\t\t\tawait innerIterator.return?.();\n\t\t\t\tfinishText();\n\t\t\t\tterminal.cancelled(projection);\n\t\t\t} catch (error) {\n\t\t\t\tfinishText();\n\t\t\t\tterminal.iteratorFailure(projection, error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t});\n\n\t\tconst terminateForFailure = (source: AssistantMessage, failure: RecoveryStreamFailure): void => {\n\t\t\tif (!projection || !outerStream.markSourceClosed()) return;\n\t\t\tfinishText();\n\t\t\tterminateRecoveryStreamForFailure(outerStream, projection, { source, failure, protocol });\n\t\t};\n\n\t\tconst prepareContentEvent = (source: AssistantMessage, contentIndex: number): boolean => {\n\t\t\tif (!projection || !nativeProjection) return false;\n\t\t\tif (!Number.isSafeInteger(contentIndex) || contentIndex < 0 || contentIndex >= source.content.length) {\n\t\t\t\tterminateForFailure(source, \"invalid_native_event_order\");\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tprojection.sync(source);\n\t\t\tnativeProjection.reserveVisibleIds(source);\n\t\t\tif (nativeProjection.synchronizeLower(source, contentIndex)) return true;\n\t\t\tterminateForFailure(source, \"collision\");\n\t\t\treturn false;\n\t\t};\n\n\t\tconst canStart = (\n\t\t\tsource: AssistantMessage,\n\t\t\tcontentIndex: number,\n\t\t\tkind: RecoveryContentKind,\n\t\t\tfailure: RecoveryStreamFailure = \"invalid_content_event_order\",\n\t\t): boolean => {\n\t\t\tif (!Number.isSafeInteger(contentIndex) || contentIndex < 0 || contentIndex >= source.content.length) {\n\t\t\t\tterminateForFailure(source, failure);\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tconst block = source.content[contentIndex];\n\t\t\tconst blockMatches =\n\t\t\t\t(kind === \"text\" && block?.type === \"text\") ||\n\t\t\t\t(kind === \"thinking\" && block?.type === \"thinking\") ||\n\t\t\t\t(kind === \"toolCall\" && block?.type === \"toolCall\");\n\t\t\tif (blockMatches && contentLifecycle.canStart(contentIndex)) return true;\n\t\t\tterminateForFailure(source, failure);\n\t\t\treturn false;\n\t\t};\n\n\t\tconst isActive = (\n\t\t\tsource: AssistantMessage,\n\t\t\tcontentIndex: number,\n\t\t\tkind: RecoveryContentKind,\n\t\t\tfailure: RecoveryStreamFailure = \"invalid_content_event_order\",\n\t\t): boolean => {\n\t\t\tif (contentLifecycle.isActive(contentIndex, kind)) return true;\n\t\t\tterminateForFailure(source, failure);\n\t\t\treturn false;\n\t\t};\n\n\t\tconst synchronizeTerminal = (source: AssistantMessage): boolean => {\n\t\t\tprojection ??= new StreamMessageProjection(outerStream, source, { preserveSourceMetadata: true });\n\t\t\tnativeProjection ??= new RecoveryNativeProjection(outerStream, projection.message, protocol);\n\t\t\tprojection.sync(source);\n\t\t\tnativeProjection.reserveVisibleIds(source);\n\t\t\tfinishText();\n\t\t\tif (nativeProjection.synchronizeRemaining(source)) return true;\n\t\t\tterminateForFailure(source, \"collision\");\n\t\t\treturn false;\n\t\t};\n\n\t\ttry {\n\t\t\tfor await (const event of innerEvents) {\n\t\t\t\tif (cancellationRequested) continue;\n\t\t\t\tswitch (event.type) {\n\t\t\t\t\tcase \"start\":\n\t\t\t\t\t\tprojection = new StreamMessageProjection(outerStream, event.partial, {\n\t\t\t\t\t\t\tpreserveSourceMetadata: true,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tnativeProjection = new RecoveryNativeProjection(outerStream, projection.message, protocol);\n\t\t\t\t\t\tnativeProjection.reserveVisibleIds(event.partial);\n\t\t\t\t\t\touterStream.push({ type: \"start\", partial: projection.message });\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"text_start\": {\n\t\t\t\t\t\tif (!canStart(event.partial, event.contentIndex, \"text\")) return;\n\t\t\t\t\t\tif (!prepareContentEvent(event.partial, event.contentIndex) || !projection || !nativeProjection)\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\tconst nextText = new RecoveryTextProjection(tools, projection, nativeProjection, event.contentIndex, {\n\t\t\t\t\t\t\tcreateParser,\n\t\t\t\t\t\t\tprotocol,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tif (!nextText.start(event.partial)) {\n\t\t\t\t\t\t\tterminateForFailure(event.partial, \"invalid_native_event_order\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttextProjection = nextText;\n\t\t\t\t\t\tcontentLifecycle.start(event.contentIndex, \"text\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"text_delta\":\n\t\t\t\t\t\tif (!isActive(event.partial, event.contentIndex, \"text\")) return;\n\t\t\t\t\t\tif (!prepareContentEvent(event.partial, event.contentIndex) || !textProjection) return;\n\t\t\t\t\t\tsawToolCall = textProjection.feed(event.delta) || sawToolCall;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"text_end\":\n\t\t\t\t\t\tif (!isActive(event.partial, event.contentIndex, \"text\")) return;\n\t\t\t\t\t\tif (!prepareContentEvent(event.partial, event.contentIndex)) return;\n\t\t\t\t\t\tfinishText();\n\t\t\t\t\t\tcontentLifecycle.end(event.contentIndex, \"text\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"done\":\n\t\t\t\t\t\tif (!synchronizeTerminal(event.message) || !projection) return;\n\t\t\t\t\t\tif (!outerStream.markSourceClosed()) return;\n\t\t\t\t\t\tterminal.done(projection, event.message, sawToolCall, event.reason);\n\t\t\t\t\t\treturn;\n\t\t\t\t\tcase \"error\":\n\t\t\t\t\t\tif (!projection) {\n\t\t\t\t\t\t\tif (!outerStream.markSourceClosed()) return;\n\t\t\t\t\t\t\touterStream.push(event);\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\tif (!synchronizeTerminal(event.error)) return;\n\t\t\t\t\t\tif (!outerStream.markSourceClosed()) return;\n\t\t\t\t\t\tterminal.sourceError(projection, event.error, sawToolCall, event.reason);\n\t\t\t\t\t\treturn;\n\t\t\t\t\tcase \"toolcall_start\": {\n\t\t\t\t\t\tif (!canStart(event.partial, event.contentIndex, \"toolCall\", \"invalid_native_event_order\")) return;\n\t\t\t\t\t\tif (!prepareContentEvent(event.partial, event.contentIndex) || !nativeProjection) return;\n\t\t\t\t\t\tconst status = nativeProjection.projectNativeStart(event.partial, event.contentIndex);\n\t\t\t\t\t\tif (status !== \"projected\") {\n\t\t\t\t\t\t\tterminateForFailure(\n\t\t\t\t\t\t\t\tevent.partial,\n\t\t\t\t\t\t\t\tstatus === \"collision\" ? \"collision\" : \"invalid_native_event_order\",\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontentLifecycle.start(event.contentIndex, \"toolCall\");\n\t\t\t\t\t\tsawToolCall = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"toolcall_delta\":\n\t\t\t\t\t\tif (!isActive(event.partial, event.contentIndex, \"toolCall\", \"invalid_native_event_order\")) return;\n\t\t\t\t\t\tif (!prepareContentEvent(event.partial, event.contentIndex) || !nativeProjection) return;\n\t\t\t\t\t\tif (!nativeProjection.projectNativeDelta(event.partial, event.contentIndex, event.delta)) {\n\t\t\t\t\t\t\tterminateForFailure(event.partial, \"invalid_native_event_order\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"toolcall_end\":\n\t\t\t\t\t\tif (!isActive(event.partial, event.contentIndex, \"toolCall\", \"invalid_native_event_order\")) return;\n\t\t\t\t\t\tif (!prepareContentEvent(event.partial, event.contentIndex) || !nativeProjection) return;\n\t\t\t\t\t\tif (!nativeProjection.projectNativeEnd(event.contentIndex, event.toolCall)) {\n\t\t\t\t\t\t\tterminateForFailure(event.partial, \"invalid_native_event_order\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontentLifecycle.end(event.contentIndex, \"toolCall\");\n\t\t\t\t\t\tsawToolCall = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"thinking_start\": {\n\t\t\t\t\t\tif (!canStart(event.partial, event.contentIndex, \"thinking\")) return;\n\t\t\t\t\t\tif (!prepareContentEvent(event.partial, event.contentIndex) || !projection || !nativeProjection)\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\tconst outerIndex = projection.startThinking(event.contentIndex, event.partial);\n\t\t\t\t\t\tif (!nativeProjection.recordProjectedBlock(event.contentIndex, outerIndex)) {\n\t\t\t\t\t\t\tterminateForFailure(event.partial, \"invalid_native_event_order\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcontentLifecycle.start(event.contentIndex, \"thinking\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase \"thinking_delta\":\n\t\t\t\t\t\tif (!isActive(event.partial, event.contentIndex, \"thinking\")) return;\n\t\t\t\t\t\tif (!prepareContentEvent(event.partial, event.contentIndex) || !projection) return;\n\t\t\t\t\t\tprojection.projectThinkingDelta(event.contentIndex, event.delta, event.partial);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"thinking_end\":\n\t\t\t\t\t\tif (!isActive(event.partial, event.contentIndex, \"thinking\")) return;\n\t\t\t\t\t\tif (!prepareContentEvent(event.partial, event.contentIndex) || !projection) return;\n\t\t\t\t\t\tprojection.finishThinking(event.contentIndex, event.content, event.partial);\n\t\t\t\t\t\tcontentLifecycle.end(event.contentIndex, \"thinking\");\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (cancellationRequested || !outerStream.markSourceClosed()) return;\n\t\t\tfinishText();\n\t\t\tterminal.exhausted(projection);\n\t\t} catch (error) {\n\t\t\tif (cancellationRequested || !outerStream.markSourceClosed()) return;\n\t\t\tfinishText();\n\t\t\tterminal.iteratorFailure(projection, error);\n\t\t}\n\t})();\n\n\treturn outerStream;\n}\n"]}
@@ -2,18 +2,23 @@ import type { AssistantMessage, Tool } from "../types.ts";
2
2
  import type { RecoveryStreamParser } from "./protocols/anthropic-xml/recovery-stream.ts";
3
3
  import type { RecoveryNativeProjection } from "./recovery-native-projection.ts";
4
4
  import type { StreamMessageProjection } from "./stream-wrapper-shared.ts";
5
+ import type { ToolCallFormat } from "./types.ts";
5
6
  /** Owns one ordinary assistant text block's mask/parser/projection lifecycle. */
6
7
  export declare class RecoveryTextProjection {
7
8
  private readonly projection;
8
9
  private readonly nativeProjection;
9
10
  private readonly innerIndex;
10
11
  private readonly parser;
12
+ private readonly protocol;
11
13
  private readonly mask;
12
14
  private activeInvoke;
13
15
  private textBuffer;
14
16
  private sawToolCall;
15
17
  private finished;
16
- constructor(tools: readonly Tool[], projection: StreamMessageProjection, nativeProjection: RecoveryNativeProjection, innerIndex: number, createParser?: (tools: readonly Tool[]) => RecoveryStreamParser);
18
+ constructor(tools: readonly Tool[], projection: StreamMessageProjection, nativeProjection: RecoveryNativeProjection, innerIndex: number, options?: {
19
+ createParser?: (tools: readonly Tool[]) => RecoveryStreamParser;
20
+ protocol?: ToolCallFormat;
21
+ });
17
22
  start(source: AssistantMessage): boolean;
18
23
  feed(text: string): boolean;
19
24
  finish(): boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"recovery-text-projection.d.ts","sourceRoot":"","sources":["../../src/tool-call-middleware/recovery-text-projection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8CAA8C,CAAC;AAIzF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAG1E,iFAAiF;AACjF,qBAAa,sBAAsB;IAClC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA0B;IACrD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA2B;IAC5D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAC9C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA4B;IACjD,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,UAAU,CAAM;IACxB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAS;IAEzB,YACC,KAAK,EAAE,SAAS,IAAI,EAAE,EACtB,UAAU,EAAE,uBAAuB,EACnC,gBAAgB,EAAE,wBAAwB,EAC1C,UAAU,EAAE,MAAM,EAClB,YAAY,GAAE,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,KAAK,oBAA4D,EAMtG;IAED,KAAK,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAGvC;IAED,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAQ1B;IAED,MAAM,IAAI,OAAO,CAShB;IAED,OAAO,CAAC,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IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAQ1B;IAED,MAAM,IAAI,OAAO,CAShB;IAED,OAAO,CAAC,cAAc;IAMtB,OAAO,CAAC,mBAAmB;IAoB3B,OAAO,CAAC,SAAS;CAKjB"}
@@ -3,7 +3,7 @@ import { createRecoveryCodeMask } from "./recovery-code-mask.js";
3
3
  import { appendRecoveryDiagnostic } from "./recovery-diagnostics.js";
4
4
  /** Owns one ordinary assistant text block's mask/parser/projection lifecycle. */
5
5
  export class RecoveryTextProjection {
6
- constructor(tools, projection, nativeProjection, innerIndex, createParser = createAntmlInvokeRecoveryStreamParser) {
6
+ constructor(tools, projection, nativeProjection, innerIndex, options = {}) {
7
7
  this.mask = createRecoveryCodeMask();
8
8
  this.activeInvoke = false;
9
9
  this.textBuffer = "";
@@ -12,7 +12,8 @@ export class RecoveryTextProjection {
12
12
  this.projection = projection;
13
13
  this.nativeProjection = nativeProjection;
14
14
  this.innerIndex = innerIndex;
15
- this.parser = createParser(tools);
15
+ this.parser = (options.createParser ?? createAntmlInvokeRecoveryStreamParser)(tools);
16
+ this.protocol = options.protocol ?? "antml";
16
17
  }
17
18
  start(source) {
18
19
  const outerIndex = this.projection.startText(this.innerIndex, source.content[this.innerIndex]);
@@ -61,8 +62,9 @@ export class RecoveryTextProjection {
61
62
  this.activeInvoke = true;
62
63
  if (event.type === "toolcall_end") {
63
64
  this.activeInvoke = false;
64
- for (const toolCall of result.completedToolCalls)
65
- appendRecoveryDiagnostic(this.projection, toolCall);
65
+ for (const toolCall of result.completedToolCalls) {
66
+ appendRecoveryDiagnostic(this.projection, toolCall, this.protocol);
67
+ }
66
68
  }
67
69
  }
68
70
  this.nativeProjection.extendText(this.innerIndex);
@@ -1 +1 @@
1
- {"version":3,"file":"recovery-text-projection.js","sourceRoot":"","sources":["../../src/tool-call-middleware/recovery-text-projection.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qCAAqC,EAAE,MAAM,sCAAsC,CAAC;AAC7F,O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AE,CAAC;gBAC3B,IAAI,CAAC,UAAU,IAAI,KAAK,CAAC,IAAI,CAAC;gBAC9B,SAAS;YACV,CAAC;YACD,IAAI,CAAC,SAAS,EAAE,CAAC;YACjB,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;YAC5D,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,IAAI,MAAM,CAAC,WAAW,CAAC;YAC1D,IAAI,KAAK,CAAC,IAAI,KAAK,gBAAgB;gBAAE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;YAC9D,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;gBACnC,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;gBAC1B,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,kBAAkB;oBAAE,wBAAwB,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;YACvG,CAAC;QACF,CAAC;QACD,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACnD,CAAC;IAEO,SAAS;QAChB,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QACzC,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;QAC/E,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACtB,CAAC;CACD","sourcesContent":["import type { AssistantMessage, Tool } from \"../types.ts\";\nimport type { RecoveryStreamParser } from \"./protocols/anthropic-xml/recovery-stream.ts\";\nimport { createAntmlInvokeRecoveryStreamParser } from \"./protocols/antml/recovery-stream.ts\";\nimport { createRecoveryCodeMask, type RecoveryCodeMaskSegment } from \"./recovery-code-mask.ts\";\nimport { appendRecoveryDiagnostic } from \"./recovery-diagnostics.ts\";\nimport type { RecoveryNativeProjection } from \"./recovery-native-projection.ts\";\nimport type { StreamMessageProjection } from \"./stream-wrapper-shared.ts\";\nimport type { StreamParserEvent } from \"./types.ts\";\n\n/** Owns one ordinary assistant text block's mask/parser/projection lifecycle. */\nexport class RecoveryTextProjection {\n\tprivate readonly projection: StreamMessageProjection;\n\tprivate readonly nativeProjection: RecoveryNativeProjection;\n\tprivate readonly innerIndex: number;\n\tprivate readonly parser: RecoveryStreamParser;\n\tprivate readonly mask = createRecoveryCodeMask();\n\tprivate activeInvoke = false;\n\tprivate textBuffer = \"\";\n\tprivate sawToolCall = false;\n\tprivate finished = false;\n\n\tconstructor(\n\t\ttools: readonly Tool[],\n\t\tprojection: StreamMessageProjection,\n\t\tnativeProjection: RecoveryNativeProjection,\n\t\tinnerIndex: number,\n\t\tcreateParser: (tools: readonly Tool[]) => RecoveryStreamParser = createAntmlInvokeRecoveryStreamParser,\n\t) {\n\t\tthis.projection = projection;\n\t\tthis.nativeProjection = nativeProjection;\n\t\tthis.innerIndex = innerIndex;\n\t\tthis.parser = createParser(tools);\n\t}\n\n\tstart(source: AssistantMessage): boolean {\n\t\tconst outerIndex = this.projection.startText(this.innerIndex, source.content[this.innerIndex]);\n\t\treturn this.nativeProjection.startText(this.innerIndex, outerIndex);\n\t}\n\n\tfeed(text: string): boolean {\n\t\tfor (let index = 0; index < text.length; index += 1) {\n\t\t\tconst character = text.charAt(index);\n\t\t\tconst options = this.activeInvoke ? { activeInvoke: true } : undefined;\n\t\t\tfor (const segment of this.mask.feed(character, options)) this.processSegment(segment);\n\t\t}\n\t\tthis.flushText();\n\t\treturn this.sawToolCall;\n\t}\n\n\tfinish(): boolean {\n\t\tif (this.finished) return this.sawToolCall;\n\t\tfor (const segment of this.mask.finish()) this.processSegment(segment);\n\t\tthis.projectParserEvents(this.parser.finish());\n\t\tthis.flushText();\n\t\tthis.projection.finishText();\n\t\tthis.nativeProjection.extendText(this.innerIndex);\n\t\tthis.finished = true;\n\t\treturn this.sawToolCall;\n\t}\n\n\tprivate processSegment(segment: RecoveryCodeMaskSegment): void {\n\t\tif (segment.recoveryBoundary) this.projectParserEvents(this.parser.interrupt());\n\t\tif (segment.scan) this.projectParserEvents(this.parser.feed(segment.text));\n\t\telse this.textBuffer += segment.text;\n\t}\n\n\tprivate projectParserEvents(events: readonly StreamParserEvent[]): void {\n\t\tfor (const event of this.nativeProjection.assignRecoveredIds(events)) {\n\t\t\tif (event.type === \"text\") {\n\t\t\t\tthis.textBuffer += event.text;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.flushText();\n\t\t\tconst result = this.projection.projectParserEvents([event]);\n\t\t\tthis.sawToolCall = this.sawToolCall || result.sawToolCall;\n\t\t\tif (event.type === \"toolcall_start\") this.activeInvoke = true;\n\t\t\tif (event.type === \"toolcall_end\") {\n\t\t\t\tthis.activeInvoke = false;\n\t\t\t\tfor (const toolCall of result.completedToolCalls) appendRecoveryDiagnostic(this.projection, toolCall);\n\t\t\t}\n\t\t}\n\t\tthis.nativeProjection.extendText(this.innerIndex);\n\t}\n\n\tprivate flushText(): void {\n\t\tif (this.textBuffer.length === 0) return;\n\t\tthis.projection.projectParserEvents([{ type: \"text\", text: this.textBuffer }]);\n\t\tthis.textBuffer = \"\";\n\t}\n}\n"]}
1
+ {"version":3,"file":"recovery-text-projection.js","sourceRoot":"","sources":["../../src/tool-call-middleware/recovery-text-projection.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qCAAqC,EAAE,MAAM,sCAAsC,CAAC;AAC7F,OAAO,EAAE,sBAAsB,EAAgC,MAAM,yBAAyB,CAAC;AAC/F,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAKrE,iFAAiF;AACjF,MAAM,OAAO,sBAAsB;IAYlC,YACC,KAAsB,EACtB,UAAmC,EACnC,gBAA0C,EAC1C,UAAkB,EAClB,OAAO,GAGH,EAAE;QAdU,SAAI,GAAG,sBAAsB,EAAE,CAAC;QACzC,iBAA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,mBAAmB,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;YAC5D,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,IAAI,MAAM,CAAC,WAAW,CAAC;YAC1D,IAAI,KAAK,CAAC,IAAI,KAAK,gBAAgB;gBAAE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;YAC9D,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,EAAE,CAAC;gBACnC,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;gBAC1B,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,kBAAkB,EAAE,CAAC;oBAClD,wBAAwB,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACpE,CAAC;YACF,CAAC;QACF,CAAC;QACD,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACnD,CAAC;IAEO,SAAS;QAChB,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QACzC,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;QAC/E,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACtB,CAAC;CACD","sourcesContent":["import type { AssistantMessage, Tool } from \"../types.ts\";\nimport type { RecoveryStreamParser } from \"./protocols/anthropic-xml/recovery-stream.ts\";\nimport { createAntmlInvokeRecoveryStreamParser } from \"./protocols/antml/recovery-stream.ts\";\nimport { createRecoveryCodeMask, type RecoveryCodeMaskSegment } from \"./recovery-code-mask.ts\";\nimport { appendRecoveryDiagnostic } from \"./recovery-diagnostics.ts\";\nimport type { RecoveryNativeProjection } from \"./recovery-native-projection.ts\";\nimport type { StreamMessageProjection } from \"./stream-wrapper-shared.ts\";\nimport type { StreamParserEvent, ToolCallFormat } from \"./types.ts\";\n\n/** Owns one ordinary assistant text block's mask/parser/projection lifecycle. */\nexport class RecoveryTextProjection {\n\tprivate readonly projection: StreamMessageProjection;\n\tprivate readonly nativeProjection: RecoveryNativeProjection;\n\tprivate readonly innerIndex: number;\n\tprivate readonly parser: RecoveryStreamParser;\n\tprivate readonly protocol: ToolCallFormat;\n\tprivate readonly mask = createRecoveryCodeMask();\n\tprivate activeInvoke = false;\n\tprivate textBuffer = \"\";\n\tprivate sawToolCall = false;\n\tprivate finished = false;\n\n\tconstructor(\n\t\ttools: readonly Tool[],\n\t\tprojection: StreamMessageProjection,\n\t\tnativeProjection: RecoveryNativeProjection,\n\t\tinnerIndex: number,\n\t\toptions: {\n\t\t\tcreateParser?: (tools: readonly Tool[]) => RecoveryStreamParser;\n\t\t\tprotocol?: ToolCallFormat;\n\t\t} = {},\n\t) {\n\t\tthis.projection = projection;\n\t\tthis.nativeProjection = nativeProjection;\n\t\tthis.innerIndex = innerIndex;\n\t\tthis.parser = (options.createParser ?? createAntmlInvokeRecoveryStreamParser)(tools);\n\t\tthis.protocol = options.protocol ?? \"antml\";\n\t}\n\n\tstart(source: AssistantMessage): boolean {\n\t\tconst outerIndex = this.projection.startText(this.innerIndex, source.content[this.innerIndex]);\n\t\treturn this.nativeProjection.startText(this.innerIndex, outerIndex);\n\t}\n\n\tfeed(text: string): boolean {\n\t\tfor (let index = 0; index < text.length; index += 1) {\n\t\t\tconst character = text.charAt(index);\n\t\t\tconst options = this.activeInvoke ? { activeInvoke: true } : undefined;\n\t\t\tfor (const segment of this.mask.feed(character, options)) this.processSegment(segment);\n\t\t}\n\t\tthis.flushText();\n\t\treturn this.sawToolCall;\n\t}\n\n\tfinish(): boolean {\n\t\tif (this.finished) return this.sawToolCall;\n\t\tfor (const segment of this.mask.finish()) this.processSegment(segment);\n\t\tthis.projectParserEvents(this.parser.finish());\n\t\tthis.flushText();\n\t\tthis.projection.finishText();\n\t\tthis.nativeProjection.extendText(this.innerIndex);\n\t\tthis.finished = true;\n\t\treturn this.sawToolCall;\n\t}\n\n\tprivate processSegment(segment: RecoveryCodeMaskSegment): void {\n\t\tif (segment.recoveryBoundary) this.projectParserEvents(this.parser.interrupt());\n\t\tif (segment.scan) this.projectParserEvents(this.parser.feed(segment.text));\n\t\telse this.textBuffer += segment.text;\n\t}\n\n\tprivate projectParserEvents(events: readonly StreamParserEvent[]): void {\n\t\tfor (const event of this.nativeProjection.assignRecoveredIds(events)) {\n\t\t\tif (event.type === \"text\") {\n\t\t\t\tthis.textBuffer += event.text;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tthis.flushText();\n\t\t\tconst result = this.projection.projectParserEvents([event]);\n\t\t\tthis.sawToolCall = this.sawToolCall || result.sawToolCall;\n\t\t\tif (event.type === \"toolcall_start\") this.activeInvoke = true;\n\t\t\tif (event.type === \"toolcall_end\") {\n\t\t\t\tthis.activeInvoke = false;\n\t\t\t\tfor (const toolCall of result.completedToolCalls) {\n\t\t\t\t\tappendRecoveryDiagnostic(this.projection, toolCall, this.protocol);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthis.nativeProjection.extendText(this.innerIndex);\n\t}\n\n\tprivate flushText(): void {\n\t\tif (this.textBuffer.length === 0) return;\n\t\tthis.projection.projectParserEvents([{ type: \"text\", text: this.textBuffer }]);\n\t\tthis.textBuffer = \"\";\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-yeongyu/senpi-ai",
3
- "version": "2026.7.29",
3
+ "version": "2026.7.30-2",
4
4
  "description": "Unified LLM API with automatic model discovery and provider configuration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",