@code-yeongyu/senpi 2026.7.11 → 2026.7.14-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.
- package/CHANGELOG.md +48 -0
- package/dist/core/agent-session.d.ts +9 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +56 -15
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js +86 -26
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/runtime-session.d.ts +1 -1
- package/dist/core/extensions/builtin/terminal/runtime-session.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/runtime-session.js +3 -2
- package/dist/core/extensions/builtin/terminal/runtime-session.js.map +1 -1
- package/dist/core/extensions/builtin/websearch/websearch/native.d.ts +1 -1
- package/dist/core/extensions/builtin/websearch/websearch/native.d.ts.map +1 -1
- package/dist/core/extensions/builtin/websearch/websearch/native.js +83 -33
- package/dist/core/extensions/builtin/websearch/websearch/native.js.map +1 -1
- package/dist/core/extensions/builtin/websearch/websearch/provider-endpoints.d.ts.map +1 -1
- package/dist/core/extensions/builtin/websearch/websearch/provider-endpoints.js +2 -1
- package/dist/core/extensions/builtin/websearch/websearch/provider-endpoints.js.map +1 -1
- package/dist/core/extensions/builtin/websearch/websearch/tool.d.ts.map +1 -1
- package/dist/core/extensions/builtin/websearch/websearch/tool.js +3 -3
- package/dist/core/extensions/builtin/websearch/websearch/tool.js.map +1 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +1 -0
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/resource-loader.d.ts +1 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +20 -2
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/modes/interactive/compaction-queue-transfer.d.ts +22 -0
- package/dist/modes/interactive/compaction-queue-transfer.d.ts.map +1 -0
- package/dist/modes/interactive/compaction-queue-transfer.js +82 -0
- package/dist/modes/interactive/compaction-queue-transfer.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +4 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +83 -69
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/node_modules/@babel/helper-string-parser/LICENSE +22 -0
- package/node_modules/@babel/helper-string-parser/README.md +19 -0
- package/node_modules/@babel/helper-string-parser/lib/index.js +295 -0
- package/node_modules/@babel/helper-string-parser/lib/index.js.map +1 -0
- package/node_modules/@babel/helper-string-parser/package.json +31 -0
- package/node_modules/@babel/helper-validator-identifier/LICENSE +22 -0
- package/node_modules/@babel/helper-validator-identifier/README.md +19 -0
- package/node_modules/@babel/helper-validator-identifier/lib/identifier.js +70 -0
- package/node_modules/@babel/helper-validator-identifier/lib/identifier.js.map +1 -0
- package/node_modules/@babel/helper-validator-identifier/lib/index.js +57 -0
- package/node_modules/@babel/helper-validator-identifier/lib/index.js.map +1 -0
- package/node_modules/@babel/helper-validator-identifier/lib/keyword.js +35 -0
- package/node_modules/@babel/helper-validator-identifier/lib/keyword.js.map +1 -0
- package/node_modules/@babel/helper-validator-identifier/package.json +31 -0
- package/node_modules/@babel/parser/LICENSE +19 -0
- package/node_modules/@babel/parser/README.md +19 -0
- package/node_modules/@babel/parser/bin/babel-parser.js +15 -0
- package/node_modules/@babel/parser/lib/index.js +14599 -0
- package/node_modules/@babel/parser/lib/index.js.map +1 -0
- package/node_modules/@babel/parser/package.json +50 -0
- package/node_modules/@babel/parser/typings/babel-parser.d.ts +262 -0
- package/node_modules/@babel/types/LICENSE +22 -0
- package/node_modules/@babel/types/README.md +19 -0
- package/node_modules/@babel/types/lib/asserts/assertNode.js +16 -0
- package/node_modules/@babel/types/lib/asserts/assertNode.js.map +1 -0
- package/node_modules/@babel/types/lib/asserts/generated/index.js +1251 -0
- package/node_modules/@babel/types/lib/asserts/generated/index.js.map +1 -0
- package/node_modules/@babel/types/lib/ast-types/generated/index.js +3 -0
- package/node_modules/@babel/types/lib/ast-types/generated/index.js.map +1 -0
- package/node_modules/@babel/types/lib/builders/flow/createFlowUnionType.js +18 -0
- package/node_modules/@babel/types/lib/builders/flow/createFlowUnionType.js.map +1 -0
- package/node_modules/@babel/types/lib/builders/flow/createTypeAnnotationBasedOnTypeof.js +31 -0
- package/node_modules/@babel/types/lib/builders/flow/createTypeAnnotationBasedOnTypeof.js.map +1 -0
- package/node_modules/@babel/types/lib/builders/generated/index.js +29 -0
- package/node_modules/@babel/types/lib/builders/generated/index.js.map +1 -0
- package/node_modules/@babel/types/lib/builders/generated/lowercase.js +2902 -0
- package/node_modules/@babel/types/lib/builders/generated/lowercase.js.map +1 -0
- package/node_modules/@babel/types/lib/builders/generated/uppercase.js +272 -0
- package/node_modules/@babel/types/lib/builders/generated/uppercase.js.map +1 -0
- package/node_modules/@babel/types/lib/builders/productions.js +12 -0
- package/node_modules/@babel/types/lib/builders/productions.js.map +1 -0
- package/node_modules/@babel/types/lib/builders/react/buildChildren.js +24 -0
- package/node_modules/@babel/types/lib/builders/react/buildChildren.js.map +1 -0
- package/node_modules/@babel/types/lib/builders/typescript/createTSUnionType.js +22 -0
- package/node_modules/@babel/types/lib/builders/typescript/createTSUnionType.js.map +1 -0
- package/node_modules/@babel/types/lib/builders/validateNode.js +21 -0
- package/node_modules/@babel/types/lib/builders/validateNode.js.map +1 -0
- package/node_modules/@babel/types/lib/clone/clone.js +12 -0
- package/node_modules/@babel/types/lib/clone/clone.js.map +1 -0
- package/node_modules/@babel/types/lib/clone/cloneDeep.js +12 -0
- package/node_modules/@babel/types/lib/clone/cloneDeep.js.map +1 -0
- package/node_modules/@babel/types/lib/clone/cloneDeepWithoutLoc.js +12 -0
- package/node_modules/@babel/types/lib/clone/cloneDeepWithoutLoc.js.map +1 -0
- package/node_modules/@babel/types/lib/clone/cloneNode.js +107 -0
- package/node_modules/@babel/types/lib/clone/cloneNode.js.map +1 -0
- package/node_modules/@babel/types/lib/clone/cloneWithoutLoc.js +12 -0
- package/node_modules/@babel/types/lib/clone/cloneWithoutLoc.js.map +1 -0
- package/node_modules/@babel/types/lib/comments/addComment.js +15 -0
- package/node_modules/@babel/types/lib/comments/addComment.js.map +1 -0
- package/node_modules/@babel/types/lib/comments/addComments.js +22 -0
- package/node_modules/@babel/types/lib/comments/addComments.js.map +1 -0
- package/node_modules/@babel/types/lib/comments/inheritInnerComments.js +12 -0
- package/node_modules/@babel/types/lib/comments/inheritInnerComments.js.map +1 -0
- package/node_modules/@babel/types/lib/comments/inheritLeadingComments.js +12 -0
- package/node_modules/@babel/types/lib/comments/inheritLeadingComments.js.map +1 -0
- package/node_modules/@babel/types/lib/comments/inheritTrailingComments.js +12 -0
- package/node_modules/@babel/types/lib/comments/inheritTrailingComments.js.map +1 -0
- package/node_modules/@babel/types/lib/comments/inheritsComments.js +17 -0
- package/node_modules/@babel/types/lib/comments/inheritsComments.js.map +1 -0
- package/node_modules/@babel/types/lib/comments/removeComments.js +15 -0
- package/node_modules/@babel/types/lib/comments/removeComments.js.map +1 -0
- package/node_modules/@babel/types/lib/constants/generated/index.js +60 -0
- package/node_modules/@babel/types/lib/constants/generated/index.js.map +1 -0
- package/node_modules/@babel/types/lib/constants/index.js +31 -0
- package/node_modules/@babel/types/lib/constants/index.js.map +1 -0
- package/node_modules/@babel/types/lib/converters/ensureBlock.js +14 -0
- package/node_modules/@babel/types/lib/converters/ensureBlock.js.map +1 -0
- package/node_modules/@babel/types/lib/converters/gatherSequenceExpressions.js +65 -0
- package/node_modules/@babel/types/lib/converters/gatherSequenceExpressions.js.map +1 -0
- package/node_modules/@babel/types/lib/converters/toBindingIdentifierName.js +14 -0
- package/node_modules/@babel/types/lib/converters/toBindingIdentifierName.js.map +1 -0
- package/node_modules/@babel/types/lib/converters/toBlock.js +29 -0
- package/node_modules/@babel/types/lib/converters/toBlock.js.map +1 -0
- package/node_modules/@babel/types/lib/converters/toComputedKey.js +14 -0
- package/node_modules/@babel/types/lib/converters/toComputedKey.js.map +1 -0
- package/node_modules/@babel/types/lib/converters/toExpression.js +28 -0
- package/node_modules/@babel/types/lib/converters/toExpression.js.map +1 -0
- package/node_modules/@babel/types/lib/converters/toIdentifier.js +25 -0
- package/node_modules/@babel/types/lib/converters/toIdentifier.js.map +1 -0
- package/node_modules/@babel/types/lib/converters/toKeyAlias.js +38 -0
- package/node_modules/@babel/types/lib/converters/toKeyAlias.js.map +1 -0
- package/node_modules/@babel/types/lib/converters/toSequenceExpression.js +19 -0
- package/node_modules/@babel/types/lib/converters/toSequenceExpression.js.map +1 -0
- package/node_modules/@babel/types/lib/converters/toStatement.js +39 -0
- package/node_modules/@babel/types/lib/converters/toStatement.js.map +1 -0
- package/node_modules/@babel/types/lib/converters/valueToNode.js +89 -0
- package/node_modules/@babel/types/lib/converters/valueToNode.js.map +1 -0
- package/node_modules/@babel/types/lib/definitions/core.js +1725 -0
- package/node_modules/@babel/types/lib/definitions/core.js.map +1 -0
- package/node_modules/@babel/types/lib/definitions/deprecated-aliases.js +11 -0
- package/node_modules/@babel/types/lib/definitions/deprecated-aliases.js.map +1 -0
- package/node_modules/@babel/types/lib/definitions/experimental.js +124 -0
- package/node_modules/@babel/types/lib/definitions/experimental.js.map +1 -0
- package/node_modules/@babel/types/lib/definitions/flow.js +495 -0
- package/node_modules/@babel/types/lib/definitions/flow.js.map +1 -0
- package/node_modules/@babel/types/lib/definitions/index.js +106 -0
- package/node_modules/@babel/types/lib/definitions/index.js.map +1 -0
- package/node_modules/@babel/types/lib/definitions/jsx.js +157 -0
- package/node_modules/@babel/types/lib/definitions/jsx.js.map +1 -0
- package/node_modules/@babel/types/lib/definitions/misc.js +31 -0
- package/node_modules/@babel/types/lib/definitions/misc.js.map +1 -0
- package/node_modules/@babel/types/lib/definitions/placeholders.js +27 -0
- package/node_modules/@babel/types/lib/definitions/placeholders.js.map +1 -0
- package/node_modules/@babel/types/lib/definitions/typescript.js +528 -0
- package/node_modules/@babel/types/lib/definitions/typescript.js.map +1 -0
- package/node_modules/@babel/types/lib/definitions/utils.js +296 -0
- package/node_modules/@babel/types/lib/definitions/utils.js.map +1 -0
- package/node_modules/@babel/types/lib/index-legacy.d.ts +2797 -0
- package/node_modules/@babel/types/lib/index.d.ts +3617 -0
- package/node_modules/@babel/types/lib/index.js +582 -0
- package/node_modules/@babel/types/lib/index.js.flow +2650 -0
- package/node_modules/@babel/types/lib/index.js.map +1 -0
- package/node_modules/@babel/types/lib/modifications/appendToMemberExpression.js +15 -0
- package/node_modules/@babel/types/lib/modifications/appendToMemberExpression.js.map +1 -0
- package/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js +65 -0
- package/node_modules/@babel/types/lib/modifications/flow/removeTypeDuplicates.js.map +1 -0
- package/node_modules/@babel/types/lib/modifications/inherits.js +28 -0
- package/node_modules/@babel/types/lib/modifications/inherits.js.map +1 -0
- package/node_modules/@babel/types/lib/modifications/prependToMemberExpression.js +17 -0
- package/node_modules/@babel/types/lib/modifications/prependToMemberExpression.js.map +1 -0
- package/node_modules/@babel/types/lib/modifications/removeProperties.js +24 -0
- package/node_modules/@babel/types/lib/modifications/removeProperties.js.map +1 -0
- package/node_modules/@babel/types/lib/modifications/removePropertiesDeep.js +14 -0
- package/node_modules/@babel/types/lib/modifications/removePropertiesDeep.js.map +1 -0
- package/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js +66 -0
- package/node_modules/@babel/types/lib/modifications/typescript/removeTypeDuplicates.js.map +1 -0
- package/node_modules/@babel/types/lib/retrievers/getAssignmentIdentifiers.js +48 -0
- package/node_modules/@babel/types/lib/retrievers/getAssignmentIdentifiers.js.map +1 -0
- package/node_modules/@babel/types/lib/retrievers/getBindingIdentifiers.js +102 -0
- package/node_modules/@babel/types/lib/retrievers/getBindingIdentifiers.js.map +1 -0
- package/node_modules/@babel/types/lib/retrievers/getFunctionName.js +63 -0
- package/node_modules/@babel/types/lib/retrievers/getFunctionName.js.map +1 -0
- package/node_modules/@babel/types/lib/retrievers/getOuterBindingIdentifiers.js +13 -0
- package/node_modules/@babel/types/lib/retrievers/getOuterBindingIdentifiers.js.map +1 -0
- package/node_modules/@babel/types/lib/traverse/traverse.js +50 -0
- package/node_modules/@babel/types/lib/traverse/traverse.js.map +1 -0
- package/node_modules/@babel/types/lib/traverse/traverseFast.js +40 -0
- package/node_modules/@babel/types/lib/traverse/traverseFast.js.map +1 -0
- package/node_modules/@babel/types/lib/utils/deprecationWarning.js +44 -0
- package/node_modules/@babel/types/lib/utils/deprecationWarning.js.map +1 -0
- package/node_modules/@babel/types/lib/utils/inherit.js +13 -0
- package/node_modules/@babel/types/lib/utils/inherit.js.map +1 -0
- package/node_modules/@babel/types/lib/utils/react/cleanJSXElementLiteralChild.js +40 -0
- package/node_modules/@babel/types/lib/utils/react/cleanJSXElementLiteralChild.js.map +1 -0
- package/node_modules/@babel/types/lib/utils/shallowEqual.js +17 -0
- package/node_modules/@babel/types/lib/utils/shallowEqual.js.map +1 -0
- package/node_modules/@babel/types/lib/validators/buildMatchMemberExpression.js +13 -0
- package/node_modules/@babel/types/lib/validators/buildMatchMemberExpression.js.map +1 -0
- package/node_modules/@babel/types/lib/validators/generated/index.js +2797 -0
- package/node_modules/@babel/types/lib/validators/generated/index.js.map +1 -0
- package/node_modules/@babel/types/lib/validators/is.js +27 -0
- package/node_modules/@babel/types/lib/validators/is.js.map +1 -0
- package/node_modules/@babel/types/lib/validators/isBinding.js +27 -0
- package/node_modules/@babel/types/lib/validators/isBinding.js.map +1 -0
- package/node_modules/@babel/types/lib/validators/isBlockScoped.js +13 -0
- package/node_modules/@babel/types/lib/validators/isBlockScoped.js.map +1 -0
- package/node_modules/@babel/types/lib/validators/isImmutable.js +21 -0
- package/node_modules/@babel/types/lib/validators/isImmutable.js.map +1 -0
- package/node_modules/@babel/types/lib/validators/isLet.js +13 -0
- package/node_modules/@babel/types/lib/validators/isLet.js.map +1 -0
- package/node_modules/@babel/types/lib/validators/isNode.js +12 -0
- package/node_modules/@babel/types/lib/validators/isNode.js.map +1 -0
- package/node_modules/@babel/types/lib/validators/isNodesEquivalent.js +57 -0
- package/node_modules/@babel/types/lib/validators/isNodesEquivalent.js.map +1 -0
- package/node_modules/@babel/types/lib/validators/isPlaceholderType.js +15 -0
- package/node_modules/@babel/types/lib/validators/isPlaceholderType.js.map +1 -0
- package/node_modules/@babel/types/lib/validators/isReferenced.js +96 -0
- package/node_modules/@babel/types/lib/validators/isReferenced.js.map +1 -0
- package/node_modules/@babel/types/lib/validators/isScope.js +18 -0
- package/node_modules/@babel/types/lib/validators/isScope.js.map +1 -0
- package/node_modules/@babel/types/lib/validators/isSpecifierDefault.js +14 -0
- package/node_modules/@babel/types/lib/validators/isSpecifierDefault.js.map +1 -0
- package/node_modules/@babel/types/lib/validators/isType.js +17 -0
- package/node_modules/@babel/types/lib/validators/isType.js.map +1 -0
- package/node_modules/@babel/types/lib/validators/isValidES3Identifier.js +13 -0
- package/node_modules/@babel/types/lib/validators/isValidES3Identifier.js.map +1 -0
- package/node_modules/@babel/types/lib/validators/isValidIdentifier.js +18 -0
- package/node_modules/@babel/types/lib/validators/isValidIdentifier.js.map +1 -0
- package/node_modules/@babel/types/lib/validators/isVar.js +15 -0
- package/node_modules/@babel/types/lib/validators/isVar.js.map +1 -0
- package/node_modules/@babel/types/lib/validators/matchesPattern.js +44 -0
- package/node_modules/@babel/types/lib/validators/matchesPattern.js.map +1 -0
- package/node_modules/@babel/types/lib/validators/react/isCompatTag.js +11 -0
- package/node_modules/@babel/types/lib/validators/react/isCompatTag.js.map +1 -0
- package/node_modules/@babel/types/lib/validators/react/isReactComponent.js +11 -0
- package/node_modules/@babel/types/lib/validators/react/isReactComponent.js.map +1 -0
- package/node_modules/@babel/types/lib/validators/validate.js +42 -0
- package/node_modules/@babel/types/lib/validators/validate.js.map +1 -0
- package/node_modules/@babel/types/package.json +39 -0
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +28 -2
- package/node_modules/@code-yeongyu/senpi-codemode/README.md +128 -78
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -3
- package/node_modules/@code-yeongyu/senpi-codemode/src/bridge/protocol.ts +15 -2
- package/node_modules/@code-yeongyu/senpi-codemode/src/bridge/reserved.ts +9 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/bridges/agent-bridge.ts +197 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/bridges/output-bridge.ts +96 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/bridges/schema-injection.ts +3 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/completion/handler.ts +95 -26
- package/node_modules/@code-yeongyu/senpi-codemode/src/completion/tool-bridge.ts +11 -2
- package/node_modules/@code-yeongyu/senpi-codemode/src/config/settings.ts +96 -8
- package/node_modules/@code-yeongyu/senpi-codemode/src/extension/session-manager.ts +24 -3
- package/node_modules/@code-yeongyu/senpi-codemode/src/index.ts +155 -21
- package/node_modules/@code-yeongyu/senpi-codemode/src/interpreters/detect.ts +1 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/jl/prelude.jl +252 -48
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/jl/runner.jl +263 -83
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/context-manager.ts +11 -5
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/local-module-loader.ts +108 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/prelude.ts +8 -6
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/rewrite-imports.ts +164 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-core.js +6 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-runtime.js +307 -41
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/py/kernel.ts +3 -2
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/py/prelude.py +792 -79
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/rb/prelude.rb +234 -21
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/rb/runner.rb +154 -51
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/shared/subprocess-queue.ts +1 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/output/output-meta.ts +89 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/output/streaming-output.ts +296 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt.ts +101 -31
- package/node_modules/@code-yeongyu/senpi-codemode/src/timeouts/bridge-timeout.ts +2 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/timeouts/idle-timeout.ts +8 -19
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/cell-handler.ts +175 -113
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-tool.ts +130 -120
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/image.ts +274 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/json-tree.ts +247 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/render.ts +641 -38
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/status-events.ts +12 -0
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/types.ts +29 -1
- package/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +2 -23
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts +175 -158
- package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.models.d.ts +60 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.models.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.models.js +54 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/cerebras.models.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/cerebras.models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.models.d.ts +92 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.models.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.models.js +72 -0
- package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare-ai-gateway.models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.d.ts +23 -22
- package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.js +63 -63
- package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.d.ts +0 -136
- package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.js +6 -142
- package/node_modules/@earendil-works/pi-ai/dist/providers/vercel-ai-gateway.models.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.js +9 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.d.ts +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.js +6 -2
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.d.ts +8 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.js +92 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.d.ts +6 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.js +54 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/index.d.ts +4 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/index.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/index.js +4 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/index.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-match.d.ts +7 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-match.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-match.js +16 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-match.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.d.ts +19 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.js +217 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.d.ts +4 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.js +46 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream-boundary.d.ts +13 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream-boundary.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream-boundary.js +144 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream-boundary.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.d.ts +5 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.js +208 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.d.ts +4 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.js +17 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/xml-entities.d.ts +5 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/xml-entities.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/xml-entities.js +34 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/xml-entities.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.d.ts +3 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/types.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/node_modules/@earendil-works/pi-pty/native/prebuilds/darwin-arm64/senpi_pty.darwin-arm64.node +0 -0
- package/node_modules/@earendil-works/pi-pty/package.json +1 -1
- package/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { decodeXmlEntities } from "./xml-entities.js";
|
|
2
|
+
const PROTOCOL_TAG_NAMES = ["invoke", "parameter", "function_calls"];
|
|
3
|
+
const INVOKE_OPEN_TAG_BODY = String.raw `<\s*invoke\b\s+name\s*=\s*(?:"([^"]+)"|'([^']+)')`;
|
|
4
|
+
const INVOKE_OPEN_TAG = new RegExp(`${INVOKE_OPEN_TAG_BODY}\\s*>`, "g");
|
|
5
|
+
const INVOKE_CLOSE_TAG = /<\s*\/\s*invoke\s*>/g;
|
|
6
|
+
const NESTED_INVOKE_OPEN_TAG = /<\s*invoke\b[^>]*>/g;
|
|
7
|
+
const PARAMETER_MARKUP = /<\s*\/?\s*parameter\b/g;
|
|
8
|
+
const PARAMETER_OPEN_TAG = /<\s*parameter\b\s+name\s*=\s*(?:"([^"]+)"|'([^']+)')\s*>/g;
|
|
9
|
+
const PARAMETER_CLOSE_TAG = /<\s*\/\s*parameter\s*>/g;
|
|
10
|
+
function findTag(pattern, text, fromIndex) {
|
|
11
|
+
pattern.lastIndex = Math.max(0, fromIndex);
|
|
12
|
+
const match = pattern.exec(text);
|
|
13
|
+
return match ? { index: match.index, length: match[0].length } : null;
|
|
14
|
+
}
|
|
15
|
+
function findParameterOpenTagAt(text, index) {
|
|
16
|
+
PARAMETER_OPEN_TAG.lastIndex = index;
|
|
17
|
+
const match = PARAMETER_OPEN_TAG.exec(text);
|
|
18
|
+
if (!match || match.index !== index) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const name = match[1] ?? match[2];
|
|
22
|
+
return name ? { index, length: match[0].length, name: decodeXmlEntities(name) } : null;
|
|
23
|
+
}
|
|
24
|
+
function findParameterBoundary(text, fromIndex) {
|
|
25
|
+
let cursor = fromIndex;
|
|
26
|
+
let nestedInvokeDepth = 0;
|
|
27
|
+
while (cursor < text.length) {
|
|
28
|
+
const parameterClose = findTag(PARAMETER_CLOSE_TAG, text, cursor);
|
|
29
|
+
const invokeOpen = findTag(NESTED_INVOKE_OPEN_TAG, text, cursor);
|
|
30
|
+
const invokeClose = findTag(INVOKE_CLOSE_TAG, text, cursor);
|
|
31
|
+
const nextIndex = Math.min(parameterClose?.index ?? Number.POSITIVE_INFINITY, invokeOpen?.index ?? Number.POSITIVE_INFINITY, invokeClose?.index ?? Number.POSITIVE_INFINITY);
|
|
32
|
+
if (!Number.isFinite(nextIndex)) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
if (invokeOpen && invokeOpen.index === nextIndex) {
|
|
36
|
+
const nextParameterClose = findTag(PARAMETER_CLOSE_TAG, text, invokeOpen.index + invokeOpen.length);
|
|
37
|
+
const nestedParameterOpen = findTag(PARAMETER_OPEN_TAG, text, invokeOpen.index + invokeOpen.length);
|
|
38
|
+
const nestedInvokeClose = findTag(INVOKE_CLOSE_TAG, text, invokeOpen.index + invokeOpen.length);
|
|
39
|
+
if (nestedInvokeClose === null ||
|
|
40
|
+
((nestedParameterOpen === null || nestedParameterOpen.index > nestedInvokeClose.index) &&
|
|
41
|
+
nextParameterClose !== null &&
|
|
42
|
+
nestedInvokeClose.index > nextParameterClose.index)) {
|
|
43
|
+
cursor = invokeOpen.index + invokeOpen.length;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
nestedInvokeDepth += 1;
|
|
47
|
+
cursor = invokeOpen.index + invokeOpen.length;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (invokeClose && invokeClose.index === nextIndex) {
|
|
51
|
+
if (nestedInvokeDepth === 0) {
|
|
52
|
+
return { kind: "invoke-close", match: invokeClose };
|
|
53
|
+
}
|
|
54
|
+
nestedInvokeDepth -= 1;
|
|
55
|
+
cursor = invokeClose.index + invokeClose.length;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (parameterClose) {
|
|
59
|
+
if (nestedInvokeDepth === 0) {
|
|
60
|
+
return { kind: "parameter-close", match: parameterClose };
|
|
61
|
+
}
|
|
62
|
+
cursor = parameterClose.index + parameterClose.length;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
export function findInvokeOpenTag(text, fromIndex) {
|
|
68
|
+
INVOKE_OPEN_TAG.lastIndex = Math.max(0, fromIndex);
|
|
69
|
+
const match = INVOKE_OPEN_TAG.exec(text);
|
|
70
|
+
if (!match || match.index === undefined) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
const toolName = match[1] ?? match[2];
|
|
74
|
+
return toolName ? { index: match.index, length: match[0].length, toolName: decodeXmlEntities(toolName) } : null;
|
|
75
|
+
}
|
|
76
|
+
export function findIncompleteInvokeOpenTag(text, fromIndex) {
|
|
77
|
+
const index = Math.max(0, fromIndex);
|
|
78
|
+
const candidate = text.slice(index);
|
|
79
|
+
const match = /^<\s*invoke\b\s+name\s*=\s*/.exec(candidate);
|
|
80
|
+
if (!match) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
const quoteIndex = match[0].length;
|
|
84
|
+
const quote = candidate[quoteIndex];
|
|
85
|
+
if (quote !== '"' && quote !== "'") {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
const toolNameStart = quoteIndex + 1;
|
|
89
|
+
const closingQuoteIndex = candidate.indexOf(quote, toolNameStart);
|
|
90
|
+
if (closingQuoteIndex === -1) {
|
|
91
|
+
const toolName = decodeXmlEntities(candidate.slice(toolNameStart));
|
|
92
|
+
return toolName.length > 0 ? { index, length: candidate.length, toolName } : null;
|
|
93
|
+
}
|
|
94
|
+
const toolName = decodeXmlEntities(candidate.slice(toolNameStart, closingQuoteIndex));
|
|
95
|
+
if (toolName.length === 0 || candidate.slice(closingQuoteIndex + 1).trim().length > 0) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
return { index, length: candidate.length, toolName };
|
|
99
|
+
}
|
|
100
|
+
export function scanInvokeBlock(text, openingTag) {
|
|
101
|
+
const parameters = [];
|
|
102
|
+
let cursor = Math.max(0, openingTag.index + openingTag.length);
|
|
103
|
+
while (cursor <= text.length) {
|
|
104
|
+
const invokeClose = findTag(INVOKE_CLOSE_TAG, text, cursor);
|
|
105
|
+
if (!invokeClose) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
const parameterMarkup = findTag(PARAMETER_MARKUP, text, cursor);
|
|
109
|
+
const nestedInvokeOpen = findTag(NESTED_INVOKE_OPEN_TAG, text, cursor);
|
|
110
|
+
if (nestedInvokeOpen &&
|
|
111
|
+
nestedInvokeOpen.index < invokeClose.index &&
|
|
112
|
+
(!parameterMarkup || nestedInvokeOpen.index < parameterMarkup.index)) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
if (!parameterMarkup || invokeClose.index < parameterMarkup.index) {
|
|
116
|
+
return {
|
|
117
|
+
contentEnd: invokeClose.index,
|
|
118
|
+
end: invokeClose.index + invokeClose.length,
|
|
119
|
+
parameters,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
const parameterOpen = findParameterOpenTagAt(text, parameterMarkup.index);
|
|
123
|
+
if (!parameterOpen) {
|
|
124
|
+
return {
|
|
125
|
+
contentEnd: invokeClose.index,
|
|
126
|
+
end: invokeClose.index + invokeClose.length,
|
|
127
|
+
parameters: null,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
const valueStart = parameterOpen.index + parameterOpen.length;
|
|
131
|
+
const boundary = findParameterBoundary(text, valueStart);
|
|
132
|
+
if (!boundary) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
switch (boundary.kind) {
|
|
136
|
+
case "invoke-close":
|
|
137
|
+
return {
|
|
138
|
+
contentEnd: boundary.match.index,
|
|
139
|
+
end: boundary.match.index + boundary.match.length,
|
|
140
|
+
parameters: null,
|
|
141
|
+
};
|
|
142
|
+
case "parameter-close":
|
|
143
|
+
parameters.push({
|
|
144
|
+
name: parameterOpen.name,
|
|
145
|
+
rawValue: text.slice(valueStart, boundary.match.index),
|
|
146
|
+
});
|
|
147
|
+
cursor = boundary.match.index + boundary.match.length;
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
function isAttributePrefix(remainder) {
|
|
154
|
+
const attributeMatch = /^(\s*)([A-Za-z]*)/.exec(remainder);
|
|
155
|
+
if (!attributeMatch) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
const attributeName = attributeMatch[2] ?? "";
|
|
159
|
+
const afterAttributeName = remainder.slice(attributeMatch[0].length);
|
|
160
|
+
if (attributeName.length < "name".length) {
|
|
161
|
+
return "name".startsWith(attributeName) && afterAttributeName.trim().length === 0;
|
|
162
|
+
}
|
|
163
|
+
if (attributeName !== "name") {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
if (afterAttributeName.trim().length === 0) {
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
const equalsMatch = /^\s*=\s*(.*)$/.exec(afterAttributeName);
|
|
170
|
+
if (!equalsMatch) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
const valuePrefix = equalsMatch[1] ?? "";
|
|
174
|
+
if (valuePrefix.length === 0) {
|
|
175
|
+
return true;
|
|
176
|
+
}
|
|
177
|
+
const quote = valuePrefix[0];
|
|
178
|
+
if (quote !== '"' && quote !== "'") {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
const closingQuoteIndex = valuePrefix.indexOf(quote, 1);
|
|
182
|
+
return closingQuoteIndex === -1 || valuePrefix.slice(closingQuoteIndex + 1).trim().length === 0;
|
|
183
|
+
}
|
|
184
|
+
function isPotentialProtocolStart(candidate) {
|
|
185
|
+
if (!candidate.startsWith("<")) {
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
const body = candidate.slice(1);
|
|
189
|
+
const leadingWhitespace = /^\s*/.exec(body)?.[0] ?? "";
|
|
190
|
+
const namePart = body.slice(leadingWhitespace.length);
|
|
191
|
+
if (namePart.length === 0) {
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
const tagName = PROTOCOL_TAG_NAMES.find((name) => name.startsWith(namePart) || namePart.startsWith(name));
|
|
195
|
+
if (!tagName) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
if (namePart.length < tagName.length) {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
const remainder = namePart.slice(tagName.length);
|
|
202
|
+
if (remainder.includes(">")) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
if (tagName === "function_calls") {
|
|
206
|
+
return /^\s*$/.test(remainder);
|
|
207
|
+
}
|
|
208
|
+
return isAttributePrefix(remainder);
|
|
209
|
+
}
|
|
210
|
+
export function getSafeInvokeTextLength(text) {
|
|
211
|
+
const lastTagIndex = text.lastIndexOf("<");
|
|
212
|
+
if (lastTagIndex === -1) {
|
|
213
|
+
return text.length;
|
|
214
|
+
}
|
|
215
|
+
return isPotentialProtocolStart(text.slice(lastTagIndex)) ? lastTagIndex : text.length;
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=invoke-tag-scanner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invoke-tag-scanner.js","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,MAAM,kBAAkB,GAAG,CAAC,QAAQ,EAAE,WAAW,EAAE,gBAAgB,CAAU,CAAC;AAE9E,MAAM,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAA,mDAAmD,CAAC;AAC3F,MAAM,eAAe,GAAG,IAAI,MAAM,CAAC,GAAG,oBAAoB,OAAO,EAAE,GAAG,CAAC,CAAC;AACxE,MAAM,gBAAgB,GAAG,sBAAsB,CAAC;AAChD,MAAM,sBAAsB,GAAG,qBAAqB,CAAC;AACrD,MAAM,gBAAgB,GAAG,wBAAwB,CAAC;AAClD,MAAM,kBAAkB,GAAG,2DAA2D,CAAC;AACvF,MAAM,mBAAmB,GAAG,yBAAyB,CAAC;AAgCtD,SAAS,OAAO,CAAC,OAAe,EAAE,IAAY,EAAE,SAAiB;IAChE,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;IAC3C,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE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,MAAM,CAAC;AACxF,CAAC","sourcesContent":["import { decodeXmlEntities } from \"./xml-entities.ts\";\n\nconst PROTOCOL_TAG_NAMES = [\"invoke\", \"parameter\", \"function_calls\"] as const;\n\nconst INVOKE_OPEN_TAG_BODY = String.raw`<\\s*invoke\\b\\s+name\\s*=\\s*(?:\"([^\"]+)\"|'([^']+)')`;\nconst INVOKE_OPEN_TAG = new RegExp(`${INVOKE_OPEN_TAG_BODY}\\\\s*>`, \"g\");\nconst INVOKE_CLOSE_TAG = /<\\s*\\/\\s*invoke\\s*>/g;\nconst NESTED_INVOKE_OPEN_TAG = /<\\s*invoke\\b[^>]*>/g;\nconst PARAMETER_MARKUP = /<\\s*\\/?\\s*parameter\\b/g;\nconst PARAMETER_OPEN_TAG = /<\\s*parameter\\b\\s+name\\s*=\\s*(?:\"([^\"]+)\"|'([^']+)')\\s*>/g;\nconst PARAMETER_CLOSE_TAG = /<\\s*\\/\\s*parameter\\s*>/g;\n\ntype TagMatch = {\n\treadonly index: number;\n\treadonly length: number;\n};\n\ntype ParameterOpenTagMatch = TagMatch & {\n\treadonly name: string;\n};\n\ntype ParameterBoundary =\n\t| { readonly kind: \"parameter-close\"; readonly match: TagMatch }\n\t| { readonly kind: \"invoke-close\"; readonly match: TagMatch };\n\nexport type InvokeOpenTagMatch = {\n\treadonly index: number;\n\treadonly length: number;\n\treadonly toolName: string;\n};\n\nexport type InvokeParameter = {\n\treadonly name: string;\n\treadonly rawValue: string;\n};\n\nexport type InvokeBlockMatch = {\n\treadonly contentEnd: number;\n\treadonly end: number;\n\treadonly parameters: InvokeParameter[] | null;\n};\n\nfunction findTag(pattern: RegExp, text: string, fromIndex: number): TagMatch | null {\n\tpattern.lastIndex = Math.max(0, fromIndex);\n\tconst match = pattern.exec(text);\n\treturn match ? { index: match.index, length: match[0].length } : null;\n}\n\nfunction findParameterOpenTagAt(text: string, index: number): ParameterOpenTagMatch | null {\n\tPARAMETER_OPEN_TAG.lastIndex = index;\n\tconst match = PARAMETER_OPEN_TAG.exec(text);\n\tif (!match || match.index !== index) {\n\t\treturn null;\n\t}\n\n\tconst name = match[1] ?? match[2];\n\treturn name ? { index, length: match[0].length, name: decodeXmlEntities(name) } : null;\n}\n\nfunction findParameterBoundary(text: string, fromIndex: number): ParameterBoundary | null {\n\tlet cursor = fromIndex;\n\tlet nestedInvokeDepth = 0;\n\n\twhile (cursor < text.length) {\n\t\tconst parameterClose = findTag(PARAMETER_CLOSE_TAG, text, cursor);\n\t\tconst invokeOpen = findTag(NESTED_INVOKE_OPEN_TAG, text, cursor);\n\t\tconst invokeClose = findTag(INVOKE_CLOSE_TAG, text, cursor);\n\t\tconst nextIndex = Math.min(\n\t\t\tparameterClose?.index ?? Number.POSITIVE_INFINITY,\n\t\t\tinvokeOpen?.index ?? Number.POSITIVE_INFINITY,\n\t\t\tinvokeClose?.index ?? Number.POSITIVE_INFINITY,\n\t\t);\n\n\t\tif (!Number.isFinite(nextIndex)) {\n\t\t\treturn null;\n\t\t}\n\t\tif (invokeOpen && invokeOpen.index === nextIndex) {\n\t\t\tconst nextParameterClose = findTag(PARAMETER_CLOSE_TAG, text, invokeOpen.index + invokeOpen.length);\n\t\t\tconst nestedParameterOpen = findTag(PARAMETER_OPEN_TAG, text, invokeOpen.index + invokeOpen.length);\n\t\t\tconst nestedInvokeClose = findTag(INVOKE_CLOSE_TAG, text, invokeOpen.index + invokeOpen.length);\n\t\t\tif (\n\t\t\t\tnestedInvokeClose === null ||\n\t\t\t\t((nestedParameterOpen === null || nestedParameterOpen.index > nestedInvokeClose.index) &&\n\t\t\t\t\tnextParameterClose !== null &&\n\t\t\t\t\tnestedInvokeClose.index > nextParameterClose.index)\n\t\t\t) {\n\t\t\t\tcursor = invokeOpen.index + invokeOpen.length;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tnestedInvokeDepth += 1;\n\t\t\tcursor = invokeOpen.index + invokeOpen.length;\n\t\t\tcontinue;\n\t\t}\n\t\tif (invokeClose && invokeClose.index === nextIndex) {\n\t\t\tif (nestedInvokeDepth === 0) {\n\t\t\t\treturn { kind: \"invoke-close\", match: invokeClose };\n\t\t\t}\n\t\t\tnestedInvokeDepth -= 1;\n\t\t\tcursor = invokeClose.index + invokeClose.length;\n\t\t\tcontinue;\n\t\t}\n\t\tif (parameterClose) {\n\t\t\tif (nestedInvokeDepth === 0) {\n\t\t\t\treturn { kind: \"parameter-close\", match: parameterClose };\n\t\t\t}\n\t\t\tcursor = parameterClose.index + parameterClose.length;\n\t\t}\n\t}\n\n\treturn null;\n}\n\nexport function findInvokeOpenTag(text: string, fromIndex: number): InvokeOpenTagMatch | null {\n\tINVOKE_OPEN_TAG.lastIndex = Math.max(0, fromIndex);\n\tconst match = INVOKE_OPEN_TAG.exec(text);\n\tif (!match || match.index === undefined) {\n\t\treturn null;\n\t}\n\n\tconst toolName = match[1] ?? match[2];\n\treturn toolName ? { index: match.index, length: match[0].length, toolName: decodeXmlEntities(toolName) } : null;\n}\n\nexport function findIncompleteInvokeOpenTag(text: string, fromIndex: number): InvokeOpenTagMatch | null {\n\tconst index = Math.max(0, fromIndex);\n\tconst candidate = text.slice(index);\n\tconst match = /^<\\s*invoke\\b\\s+name\\s*=\\s*/.exec(candidate);\n\tif (!match) {\n\t\treturn null;\n\t}\n\n\tconst quoteIndex = match[0].length;\n\tconst quote = candidate[quoteIndex];\n\tif (quote !== '\"' && quote !== \"'\") {\n\t\treturn null;\n\t}\n\n\tconst toolNameStart = quoteIndex + 1;\n\tconst closingQuoteIndex = candidate.indexOf(quote, toolNameStart);\n\tif (closingQuoteIndex === -1) {\n\t\tconst toolName = decodeXmlEntities(candidate.slice(toolNameStart));\n\t\treturn toolName.length > 0 ? { index, length: candidate.length, toolName } : null;\n\t}\n\n\tconst toolName = decodeXmlEntities(candidate.slice(toolNameStart, closingQuoteIndex));\n\tif (toolName.length === 0 || candidate.slice(closingQuoteIndex + 1).trim().length > 0) {\n\t\treturn null;\n\t}\n\n\treturn { index, length: candidate.length, toolName };\n}\n\nexport function scanInvokeBlock(text: string, openingTag: InvokeOpenTagMatch): InvokeBlockMatch | null {\n\tconst parameters: InvokeParameter[] = [];\n\tlet cursor = Math.max(0, openingTag.index + openingTag.length);\n\n\twhile (cursor <= text.length) {\n\t\tconst invokeClose = findTag(INVOKE_CLOSE_TAG, text, cursor);\n\t\tif (!invokeClose) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst parameterMarkup = findTag(PARAMETER_MARKUP, text, cursor);\n\t\tconst nestedInvokeOpen = findTag(NESTED_INVOKE_OPEN_TAG, text, cursor);\n\t\tif (\n\t\t\tnestedInvokeOpen &&\n\t\t\tnestedInvokeOpen.index < invokeClose.index &&\n\t\t\t(!parameterMarkup || nestedInvokeOpen.index < parameterMarkup.index)\n\t\t) {\n\t\t\treturn null;\n\t\t}\n\t\tif (!parameterMarkup || invokeClose.index < parameterMarkup.index) {\n\t\t\treturn {\n\t\t\t\tcontentEnd: invokeClose.index,\n\t\t\t\tend: invokeClose.index + invokeClose.length,\n\t\t\t\tparameters,\n\t\t\t};\n\t\t}\n\n\t\tconst parameterOpen = findParameterOpenTagAt(text, parameterMarkup.index);\n\t\tif (!parameterOpen) {\n\t\t\treturn {\n\t\t\t\tcontentEnd: invokeClose.index,\n\t\t\t\tend: invokeClose.index + invokeClose.length,\n\t\t\t\tparameters: null,\n\t\t\t};\n\t\t}\n\n\t\tconst valueStart = parameterOpen.index + parameterOpen.length;\n\t\tconst boundary = findParameterBoundary(text, valueStart);\n\t\tif (!boundary) {\n\t\t\treturn null;\n\t\t}\n\n\t\tswitch (boundary.kind) {\n\t\t\tcase \"invoke-close\":\n\t\t\t\treturn {\n\t\t\t\t\tcontentEnd: boundary.match.index,\n\t\t\t\t\tend: boundary.match.index + boundary.match.length,\n\t\t\t\t\tparameters: null,\n\t\t\t\t};\n\t\t\tcase \"parameter-close\":\n\t\t\t\tparameters.push({\n\t\t\t\t\tname: parameterOpen.name,\n\t\t\t\t\trawValue: text.slice(valueStart, boundary.match.index),\n\t\t\t\t});\n\t\t\t\tcursor = boundary.match.index + boundary.match.length;\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\treturn null;\n}\n\nfunction isAttributePrefix(remainder: string): boolean {\n\tconst attributeMatch = /^(\\s*)([A-Za-z]*)/.exec(remainder);\n\tif (!attributeMatch) {\n\t\treturn false;\n\t}\n\n\tconst attributeName = attributeMatch[2] ?? \"\";\n\tconst afterAttributeName = remainder.slice(attributeMatch[0].length);\n\tif (attributeName.length < \"name\".length) {\n\t\treturn \"name\".startsWith(attributeName) && afterAttributeName.trim().length === 0;\n\t}\n\tif (attributeName !== \"name\") {\n\t\treturn false;\n\t}\n\tif (afterAttributeName.trim().length === 0) {\n\t\treturn true;\n\t}\n\n\tconst equalsMatch = /^\\s*=\\s*(.*)$/.exec(afterAttributeName);\n\tif (!equalsMatch) {\n\t\treturn false;\n\t}\n\n\tconst valuePrefix = equalsMatch[1] ?? \"\";\n\tif (valuePrefix.length === 0) {\n\t\treturn true;\n\t}\n\n\tconst quote = valuePrefix[0];\n\tif (quote !== '\"' && quote !== \"'\") {\n\t\treturn false;\n\t}\n\n\tconst closingQuoteIndex = valuePrefix.indexOf(quote, 1);\n\treturn closingQuoteIndex === -1 || valuePrefix.slice(closingQuoteIndex + 1).trim().length === 0;\n}\n\nfunction isPotentialProtocolStart(candidate: string): boolean {\n\tif (!candidate.startsWith(\"<\")) {\n\t\treturn false;\n\t}\n\n\tconst body = candidate.slice(1);\n\tconst leadingWhitespace = /^\\s*/.exec(body)?.[0] ?? \"\";\n\tconst namePart = body.slice(leadingWhitespace.length);\n\tif (namePart.length === 0) {\n\t\treturn true;\n\t}\n\n\tconst tagName = PROTOCOL_TAG_NAMES.find((name) => name.startsWith(namePart) || namePart.startsWith(name));\n\tif (!tagName) {\n\t\treturn false;\n\t}\n\tif (namePart.length < tagName.length) {\n\t\treturn true;\n\t}\n\n\tconst remainder = namePart.slice(tagName.length);\n\tif (remainder.includes(\">\")) {\n\t\treturn false;\n\t}\n\tif (tagName === \"function_calls\") {\n\t\treturn /^\\s*$/.test(remainder);\n\t}\n\treturn isAttributePrefix(remainder);\n}\n\nexport function getSafeInvokeTextLength(text: string): number {\n\tconst lastTagIndex = text.lastIndexOf(\"<\");\n\tif (lastTagIndex === -1) {\n\t\treturn text.length;\n\t}\n\n\treturn isPotentialProtocolStart(text.slice(lastTagIndex)) ? lastTagIndex : text.length;\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Tool } from "../../../types.ts";
|
|
2
|
+
import type { ParsedToolCall, ParserOptions } from "../../types.ts";
|
|
3
|
+
export declare function parseAnthropicXmlGeneratedText(text: string, tools: Tool[], options?: ParserOptions): ParsedToolCall[];
|
|
4
|
+
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAMpE,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,cAAc,EAAE,CAsDrH"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { coerceParameters } from "./coerce-parameters.js";
|
|
2
|
+
import { findNextInvokeMatch } from "./invoke-match.js";
|
|
3
|
+
import { findInvokeOpenTag, scanInvokeBlock } from "./invoke-tag-scanner.js";
|
|
4
|
+
import { createToolResolver } from "./tool-resolver.js";
|
|
5
|
+
export function parseAnthropicXmlGeneratedText(text, tools, options) {
|
|
6
|
+
if (text.length === 0 || tools.length === 0) {
|
|
7
|
+
return [];
|
|
8
|
+
}
|
|
9
|
+
const resolveTool = createToolResolver(tools);
|
|
10
|
+
const parsedToolCalls = [];
|
|
11
|
+
let cursor = 0;
|
|
12
|
+
while (cursor < text.length) {
|
|
13
|
+
const openingTag = findInvokeOpenTag(text, cursor);
|
|
14
|
+
if (!openingTag) {
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
const tool = resolveTool(openingTag.toolName);
|
|
18
|
+
const block = scanInvokeBlock(text, openingTag);
|
|
19
|
+
if (!tool) {
|
|
20
|
+
const nextKnownInvoke = findNextInvokeMatch(text, openingTag.index + openingTag.length, (toolName) => resolveTool(toolName) !== undefined);
|
|
21
|
+
if (nextKnownInvoke &&
|
|
22
|
+
(block === null || (nextKnownInvoke.block !== null && nextKnownInvoke.block.end === block.end))) {
|
|
23
|
+
cursor = nextKnownInvoke.openingTag.index;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (!block) {
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
const originalCallText = text.slice(openingTag.index, block.end);
|
|
31
|
+
cursor = block.end;
|
|
32
|
+
if (!tool) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const argumentsRecord = block.parameters ? coerceParameters(block.parameters, tool) : null;
|
|
36
|
+
if (!argumentsRecord) {
|
|
37
|
+
options?.onError?.("Could not process anthropic-xml tool call, keeping original text.", {
|
|
38
|
+
toolCall: originalCallText,
|
|
39
|
+
});
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
parsedToolCalls.push({ name: tool.name, arguments: argumentsRecord });
|
|
43
|
+
}
|
|
44
|
+
return parsedToolCalls;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/parse.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,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C,SAAS;YACV,CAAC;QACF,CAAC;QACD,IAAI,CAAC,KAAK,EAAE,CAAC;YACZ,MAAM;QACP,CAAC;QAED,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;QACjE,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC;QAEnB,IAAI,CAAC,IAAI,EAAE,CAAC;YACX,SAAS;QACV,CAAC;QAED,MAAM,eAAe,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,gBAAgB,CAAC,KAAK,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC3F,IAAI,CAAC,eAAe,EAAE,CAAC;YACtB,OAAO,EAAE,OAAO,EAAE,CAAC,mEAAmE,EAAE;gBACvF,QAAQ,EAAE,gBAAgB;aAC1B,CAAC,CAAC;YACH,SAAS;QACV,CAAC;QAED,eAAe,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC,CAAC;IACvE,CAAC;IAED,OAAO,eAAe,CAAC;AACxB,CAAC","sourcesContent":["import type { Tool } from \"../../../types.ts\";\nimport type { ParsedToolCall, ParserOptions } from \"../../types.ts\";\nimport { coerceParameters } from \"./coerce-parameters.ts\";\nimport { findNextInvokeMatch } from \"./invoke-match.ts\";\nimport { findInvokeOpenTag, scanInvokeBlock } from \"./invoke-tag-scanner.ts\";\nimport { createToolResolver } from \"./tool-resolver.ts\";\n\nexport function parseAnthropicXmlGeneratedText(text: string, tools: Tool[], options?: ParserOptions): ParsedToolCall[] {\n\tif (text.length === 0 || tools.length === 0) {\n\t\treturn [];\n\t}\n\n\tconst resolveTool = createToolResolver(tools);\n\tconst parsedToolCalls: ParsedToolCall[] = [];\n\tlet cursor = 0;\n\n\twhile (cursor < text.length) {\n\t\tconst openingTag = findInvokeOpenTag(text, cursor);\n\t\tif (!openingTag) {\n\t\t\tbreak;\n\t\t}\n\n\t\tconst tool = resolveTool(openingTag.toolName);\n\t\tconst block = scanInvokeBlock(text, openingTag);\n\t\tif (!tool) {\n\t\t\tconst nextKnownInvoke = findNextInvokeMatch(\n\t\t\t\ttext,\n\t\t\t\topeningTag.index + openingTag.length,\n\t\t\t\t(toolName) => resolveTool(toolName) !== undefined,\n\t\t\t);\n\t\t\tif (\n\t\t\t\tnextKnownInvoke &&\n\t\t\t\t(block === null || (nextKnownInvoke.block !== null && nextKnownInvoke.block.end === block.end))\n\t\t\t) {\n\t\t\t\tcursor = nextKnownInvoke.openingTag.index;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tif (!block) {\n\t\t\tbreak;\n\t\t}\n\n\t\tconst originalCallText = text.slice(openingTag.index, block.end);\n\t\tcursor = block.end;\n\n\t\tif (!tool) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst argumentsRecord = block.parameters ? coerceParameters(block.parameters, tool) : null;\n\t\tif (!argumentsRecord) {\n\t\t\toptions?.onError?.(\"Could not process anthropic-xml tool call, keeping original text.\", {\n\t\t\t\ttoolCall: originalCallText,\n\t\t\t});\n\t\t\tcontinue;\n\t\t}\n\n\t\tparsedToolCalls.push({ name: tool.name, arguments: argumentsRecord });\n\t}\n\n\treturn parsedToolCalls;\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Incomplete protocol fragments are rejected before retained input can exceed this many UTF-16 code units. */
|
|
2
|
+
export declare const ANTHROPIC_XML_MAX_RETAINED_FRAGMENT_LENGTH: number;
|
|
3
|
+
export type StreamBoundaryMatcher = {
|
|
4
|
+
feed(text: string): boolean;
|
|
5
|
+
};
|
|
6
|
+
export type PendingFragment = {
|
|
7
|
+
readonly kind: "invoke" | "function-calls" | "open-tag";
|
|
8
|
+
readonly matcher: StreamBoundaryMatcher;
|
|
9
|
+
};
|
|
10
|
+
export declare function createClosingTagMatcher(tagName: "invoke" | "function_calls"): StreamBoundaryMatcher;
|
|
11
|
+
export declare function createTagEndMatcher(): StreamBoundaryMatcher;
|
|
12
|
+
export declare function createPendingFragment(kind: PendingFragment["kind"], text: string): PendingFragment;
|
|
13
|
+
//# sourceMappingURL=stream-boundary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-boundary.d.ts","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/stream-boundary.ts"],"names":[],"mappings":"AAMA,+GAA+G;AAC/G,eAAO,MAAM,0CAA0C,QAAY,CAAC;AAEpE,MAAM,MAAM,qBAAqB,GAAG;IACnC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC7B,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,gBAAgB,GAAG,UAAU,CAAC;IACxD,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAAC;CACxC,CAAC;AAsEF,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,QAAQ,GAAG,gBAAgB,GAAG,qBAAqB,CA0DnG;AAED,wBAAgB,mBAAmB,IAAI,qBAAqB,CAM3D;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,eAAe,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,eAAe,CASlG"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
const WHITESPACE = /\s/;
|
|
2
|
+
const INVOKE_OPEN_TAG = /^<\s*invoke\b[^>]*>$/;
|
|
3
|
+
const INVOKE_CLOSE_TAG = /^<\s*\/\s*invoke\s*>$/;
|
|
4
|
+
const PARAMETER_OPEN_TAG = /^<\s*parameter\b[^>]*>$/;
|
|
5
|
+
const PARAMETER_CLOSE_TAG = /^<\s*\/\s*parameter\s*>$/;
|
|
6
|
+
/** Incomplete protocol fragments are rejected before retained input can exceed this many UTF-16 code units. */
|
|
7
|
+
export const ANTHROPIC_XML_MAX_RETAINED_FRAGMENT_LENGTH = 64 * 1024;
|
|
8
|
+
function isWhitespace(character) {
|
|
9
|
+
return WHITESPACE.test(character);
|
|
10
|
+
}
|
|
11
|
+
function createInvokeBoundaryMatcher() {
|
|
12
|
+
let invokeDepth = 0;
|
|
13
|
+
const parameterInvokeDepths = [];
|
|
14
|
+
let tagCharacters = null;
|
|
15
|
+
return {
|
|
16
|
+
feed(text) {
|
|
17
|
+
for (const character of text) {
|
|
18
|
+
if (tagCharacters === null) {
|
|
19
|
+
if (character === "<") {
|
|
20
|
+
tagCharacters = [character];
|
|
21
|
+
}
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (character === "<") {
|
|
25
|
+
tagCharacters = [character];
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
tagCharacters.push(character);
|
|
29
|
+
if (character !== ">") {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const tag = tagCharacters.join("");
|
|
33
|
+
tagCharacters = null;
|
|
34
|
+
if (INVOKE_OPEN_TAG.test(tag)) {
|
|
35
|
+
invokeDepth += 1;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (PARAMETER_OPEN_TAG.test(tag)) {
|
|
39
|
+
parameterInvokeDepths.push(invokeDepth);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (PARAMETER_CLOSE_TAG.test(tag)) {
|
|
43
|
+
const parameterInvokeDepth = parameterInvokeDepths.pop();
|
|
44
|
+
if (parameterInvokeDepth !== undefined && invokeDepth > parameterInvokeDepth) {
|
|
45
|
+
invokeDepth = parameterInvokeDepth;
|
|
46
|
+
}
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (!INVOKE_CLOSE_TAG.test(tag) || invokeDepth === 0) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
invokeDepth -= 1;
|
|
53
|
+
while (parameterInvokeDepths.length > 0) {
|
|
54
|
+
const parameterInvokeDepth = parameterInvokeDepths[parameterInvokeDepths.length - 1];
|
|
55
|
+
if (parameterInvokeDepth === undefined || parameterInvokeDepth <= invokeDepth) {
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
parameterInvokeDepths.pop();
|
|
59
|
+
}
|
|
60
|
+
if (invokeDepth === 0) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return false;
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export function createClosingTagMatcher(tagName) {
|
|
69
|
+
let state = "seek";
|
|
70
|
+
let nameIndex = 0;
|
|
71
|
+
function restart(character) {
|
|
72
|
+
state = character === "<" ? "after-open" : "seek";
|
|
73
|
+
nameIndex = 0;
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
feed(text) {
|
|
77
|
+
let matched = false;
|
|
78
|
+
for (const character of text) {
|
|
79
|
+
switch (state) {
|
|
80
|
+
case "seek":
|
|
81
|
+
if (character === "<") {
|
|
82
|
+
state = "after-open";
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
case "after-open":
|
|
86
|
+
if (character === "/") {
|
|
87
|
+
state = "after-slash";
|
|
88
|
+
}
|
|
89
|
+
else if (!isWhitespace(character)) {
|
|
90
|
+
restart(character);
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
case "after-slash":
|
|
94
|
+
if (character === tagName[0]) {
|
|
95
|
+
nameIndex = 1;
|
|
96
|
+
state = "name";
|
|
97
|
+
}
|
|
98
|
+
else if (!isWhitespace(character)) {
|
|
99
|
+
restart(character);
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
case "name":
|
|
103
|
+
if (character !== tagName[nameIndex]) {
|
|
104
|
+
restart(character);
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
nameIndex += 1;
|
|
108
|
+
if (nameIndex === tagName.length) {
|
|
109
|
+
state = "after-name";
|
|
110
|
+
}
|
|
111
|
+
break;
|
|
112
|
+
case "after-name":
|
|
113
|
+
if (character === ">") {
|
|
114
|
+
matched = true;
|
|
115
|
+
state = "seek";
|
|
116
|
+
nameIndex = 0;
|
|
117
|
+
}
|
|
118
|
+
else if (!isWhitespace(character)) {
|
|
119
|
+
restart(character);
|
|
120
|
+
}
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return matched;
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
export function createTagEndMatcher() {
|
|
129
|
+
return {
|
|
130
|
+
feed(text) {
|
|
131
|
+
return text.includes(">");
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
export function createPendingFragment(kind, text) {
|
|
136
|
+
const matcher = kind === "invoke"
|
|
137
|
+
? createInvokeBoundaryMatcher()
|
|
138
|
+
: kind === "function-calls"
|
|
139
|
+
? createClosingTagMatcher("function_calls")
|
|
140
|
+
: createTagEndMatcher();
|
|
141
|
+
matcher.feed(text);
|
|
142
|
+
return { kind, matcher };
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=stream-boundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-boundary.js","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/stream-boundary.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,eAAe,GAAG,sBAAsB,CAAC;AAC/C,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AACjD,MAAM,kBAAkB,GAAG,yBAAyB,CAAC;AACrD,MAAM,mBAAmB,GAAG,0BAA0B,CAAC;AAEvD,+GAA+G;AAC/G,MAAM,CAAC,MAAM,0CAA0C,GAAG,EAAE,GAAG,IAAI,CAAC;AAapE,SAAS,YAAY,CAAC,SAAiB;IACtC,OAAO,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,2BAA2B;IACnC,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MAAM,OAAO,GACZ,IAAI,KAAK,QAAQ;QAChB,CAAC,CAAC,2BAA2B,EAAE;QAC/B,CAAC,CAAC,IAAI,KAAK,gBAAgB;YAC1B,CAAC,CAAC,uBAAuB,CAAC,gBAAgB,CAAC;YAC3C,CAAC,CAAC,mBAAmB,EAAE,CAAC;IAC3B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC1B,CAAC","sourcesContent":["const WHITESPACE = /\\s/;\nconst INVOKE_OPEN_TAG = /^<\\s*invoke\\b[^>]*>$/;\nconst INVOKE_CLOSE_TAG = /^<\\s*\\/\\s*invoke\\s*>$/;\nconst PARAMETER_OPEN_TAG = /^<\\s*parameter\\b[^>]*>$/;\nconst PARAMETER_CLOSE_TAG = /^<\\s*\\/\\s*parameter\\s*>$/;\n\n/** Incomplete protocol fragments are rejected before retained input can exceed this many UTF-16 code units. */\nexport const ANTHROPIC_XML_MAX_RETAINED_FRAGMENT_LENGTH = 64 * 1024;\n\nexport type StreamBoundaryMatcher = {\n\tfeed(text: string): boolean;\n};\n\nexport type PendingFragment = {\n\treadonly kind: \"invoke\" | \"function-calls\" | \"open-tag\";\n\treadonly matcher: StreamBoundaryMatcher;\n};\n\ntype ClosingTagState = \"seek\" | \"after-open\" | \"after-slash\" | \"name\" | \"after-name\";\n\nfunction isWhitespace(character: string): boolean {\n\treturn WHITESPACE.test(character);\n}\n\nfunction createInvokeBoundaryMatcher(): StreamBoundaryMatcher {\n\tlet invokeDepth = 0;\n\tconst parameterInvokeDepths: number[] = [];\n\tlet tagCharacters: string[] | null = null;\n\n\treturn {\n\t\tfeed(text: string): boolean {\n\t\t\tfor (const character of text) {\n\t\t\t\tif (tagCharacters === null) {\n\t\t\t\t\tif (character === \"<\") {\n\t\t\t\t\t\ttagCharacters = [character];\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tif (character === \"<\") {\n\t\t\t\t\ttagCharacters = [character];\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\ttagCharacters.push(character);\n\t\t\t\tif (character !== \">\") {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst tag = tagCharacters.join(\"\");\n\t\t\t\ttagCharacters = null;\n\t\t\t\tif (INVOKE_OPEN_TAG.test(tag)) {\n\t\t\t\t\tinvokeDepth += 1;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (PARAMETER_OPEN_TAG.test(tag)) {\n\t\t\t\t\tparameterInvokeDepths.push(invokeDepth);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (PARAMETER_CLOSE_TAG.test(tag)) {\n\t\t\t\t\tconst parameterInvokeDepth = parameterInvokeDepths.pop();\n\t\t\t\t\tif (parameterInvokeDepth !== undefined && invokeDepth > parameterInvokeDepth) {\n\t\t\t\t\t\tinvokeDepth = parameterInvokeDepth;\n\t\t\t\t\t}\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (!INVOKE_CLOSE_TAG.test(tag) || invokeDepth === 0) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tinvokeDepth -= 1;\n\t\t\t\twhile (parameterInvokeDepths.length > 0) {\n\t\t\t\t\tconst parameterInvokeDepth = parameterInvokeDepths[parameterInvokeDepths.length - 1];\n\t\t\t\t\tif (parameterInvokeDepth === undefined || parameterInvokeDepth <= invokeDepth) {\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tparameterInvokeDepths.pop();\n\t\t\t\t}\n\t\t\t\tif (invokeDepth === 0) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t},\n\t};\n}\n\nexport function createClosingTagMatcher(tagName: \"invoke\" | \"function_calls\"): StreamBoundaryMatcher {\n\tlet state: ClosingTagState = \"seek\";\n\tlet nameIndex = 0;\n\n\tfunction restart(character: string): void {\n\t\tstate = character === \"<\" ? \"after-open\" : \"seek\";\n\t\tnameIndex = 0;\n\t}\n\n\treturn {\n\t\tfeed(text: string): boolean {\n\t\t\tlet matched = false;\n\t\t\tfor (const character of text) {\n\t\t\t\tswitch (state) {\n\t\t\t\t\tcase \"seek\":\n\t\t\t\t\t\tif (character === \"<\") {\n\t\t\t\t\t\t\tstate = \"after-open\";\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"after-open\":\n\t\t\t\t\t\tif (character === \"/\") {\n\t\t\t\t\t\t\tstate = \"after-slash\";\n\t\t\t\t\t\t} else if (!isWhitespace(character)) {\n\t\t\t\t\t\t\trestart(character);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"after-slash\":\n\t\t\t\t\t\tif (character === tagName[0]) {\n\t\t\t\t\t\t\tnameIndex = 1;\n\t\t\t\t\t\t\tstate = \"name\";\n\t\t\t\t\t\t} else if (!isWhitespace(character)) {\n\t\t\t\t\t\t\trestart(character);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"name\":\n\t\t\t\t\t\tif (character !== tagName[nameIndex]) {\n\t\t\t\t\t\t\trestart(character);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tnameIndex += 1;\n\t\t\t\t\t\tif (nameIndex === tagName.length) {\n\t\t\t\t\t\t\tstate = \"after-name\";\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase \"after-name\":\n\t\t\t\t\t\tif (character === \">\") {\n\t\t\t\t\t\t\tmatched = true;\n\t\t\t\t\t\t\tstate = \"seek\";\n\t\t\t\t\t\t\tnameIndex = 0;\n\t\t\t\t\t\t} else if (!isWhitespace(character)) {\n\t\t\t\t\t\t\trestart(character);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn matched;\n\t\t},\n\t};\n}\n\nexport function createTagEndMatcher(): StreamBoundaryMatcher {\n\treturn {\n\t\tfeed(text: string): boolean {\n\t\t\treturn text.includes(\">\");\n\t\t},\n\t};\n}\n\nexport function createPendingFragment(kind: PendingFragment[\"kind\"], text: string): PendingFragment {\n\tconst matcher =\n\t\tkind === \"invoke\"\n\t\t\t? createInvokeBoundaryMatcher()\n\t\t\t: kind === \"function-calls\"\n\t\t\t\t? createClosingTagMatcher(\"function_calls\")\n\t\t\t\t: createTagEndMatcher();\n\tmatcher.feed(text);\n\treturn { kind, matcher };\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Tool } from "../../../types.ts";
|
|
2
|
+
import type { ParserOptions, StreamParser } from "../../types.ts";
|
|
3
|
+
export { ANTHROPIC_XML_MAX_RETAINED_FRAGMENT_LENGTH } from "./stream-boundary.ts";
|
|
4
|
+
export declare function createAnthropicXmlStreamParser(tools: Tool[], options?: ParserOptions): StreamParser;
|
|
5
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAqB,MAAM,gBAAgB,CAAC;AAiBrF,OAAO,EAAE,0CAA0C,EAAE,MAAM,sBAAsB,CAAC;AA6DlF,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,YAAY,CA6LnG"}
|