@code-yeongyu/senpi 2026.7.14-2 → 2026.7.14
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 +0 -17
- 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 +5 -14
- 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 +2 -3
- package/dist/core/extensions/builtin/terminal/runtime-session.js.map +1 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +0 -1
- package/dist/core/model-registry.js.map +1 -1
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +0 -8
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +3 -3
- 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 +23 -2
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.models.js +10 -10
- package/node_modules/@earendil-works/pi-ai/dist/providers/openrouter.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 +0 -9
- 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 +2 -6
- 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/types.d.ts +1 -3
- 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 +1 -1
- 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
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.d.ts +0 -8
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.js +0 -92
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.js.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.d.ts +0 -6
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.js +0 -54
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/format.js.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/index.d.ts +0 -4
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/index.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/index.js +0 -4
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/index.js.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-match.d.ts +0 -7
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-match.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-match.js +0 -16
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-match.js.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.d.ts +0 -19
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.js +0 -217
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.js.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.d.ts +0 -4
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.js +0 -46
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/parse.js.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream-boundary.d.ts +0 -13
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream-boundary.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream-boundary.js +0 -144
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream-boundary.js.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.d.ts +0 -5
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.js +0 -208
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/stream.js.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.d.ts +0 -4
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.js +0 -17
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/tool-resolver.js.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/xml-entities.d.ts +0 -5
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/xml-entities.d.ts.map +0 -1
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/xml-entities.js +0 -34
- package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/anthropic-xml/xml-entities.js.map +0 -1
package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-transformer.d.ts","sourceRoot":"","sources":["../../src/tool-call-middleware/context-transformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEX,OAAO,EAMP,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"context-transformer.d.ts","sourceRoot":"","sources":["../../src/tool-call-middleware/context-transformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEX,OAAO,EAMP,MAAM,aAAa,CAAC;AA6BrB,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAqDnE;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,cAAc,GAAG,gBAAgB,CAMpE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAiBtF"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { anthropicXmlFormatToolCall, anthropicXmlFormatToolResponse, anthropicXmlFormatToolsSystemPrompt, createAnthropicXmlStreamParser, parseAnthropicXmlGeneratedText, } from "./protocols/anthropic-xml/index.js";
|
|
2
1
|
import { gemma4CreateStreamParser, gemma4FormatToolCall, gemma4FormatToolResponse, gemma4FormatToolsSystemPrompt, gemma4ParseGeneratedText, } from "./protocols/gemma4.js";
|
|
3
2
|
import { hermesCreateStreamParser, hermesFormatToolCall, hermesFormatToolResponse, hermesFormatToolsSystemPrompt, hermesParseGeneratedText, } from "./protocols/hermes.js";
|
|
4
3
|
import { createMorphXmlStreamParser, morphXmlFormatToolCall, morphXmlFormatToolResponse, morphXmlFormatToolsSystemPrompt, parseMorphXmlGeneratedText, } from "./protocols/morph-xml.js";
|
|
@@ -40,18 +39,10 @@ const gemma4Protocol = {
|
|
|
40
39
|
parseGeneratedText: gemma4ParseGeneratedText,
|
|
41
40
|
createStreamParser: gemma4CreateStreamParser,
|
|
42
41
|
};
|
|
43
|
-
const anthropicXmlProtocol = {
|
|
44
|
-
formatToolsSystemPrompt: anthropicXmlFormatToolsSystemPrompt,
|
|
45
|
-
formatToolResponse: anthropicXmlFormatToolResponse,
|
|
46
|
-
formatToolCall: anthropicXmlFormatToolCall,
|
|
47
|
-
parseGeneratedText: parseAnthropicXmlGeneratedText,
|
|
48
|
-
createStreamParser: createAnthropicXmlStreamParser,
|
|
49
|
-
};
|
|
50
42
|
/**
|
|
51
43
|
* Protocol registry mapping format strings to protocol implementations.
|
|
52
44
|
*/
|
|
53
45
|
const protocolRegistry = {
|
|
54
|
-
"anthropic-xml": anthropicXmlProtocol,
|
|
55
46
|
hermes: hermesProtocol,
|
|
56
47
|
xml: morphXmlProtocol,
|
|
57
48
|
"yaml-xml": yamlXmlProtocol,
|
package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/context-transformer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-transformer.js","sourceRoot":"","sources":["../../src/tool-call-middleware/context-transformer.ts"],"names":[],"mappings":"AASA,OAAO,EACN,0BAA0B,EAC1B,8BAA8B,EAC9B,mCAAmC,EACnC,8BAA8B,EAC9B,8BAA8B,GAC9B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACN,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,6BAA6B,EAC7B,wBAAwB,GACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,6BAA6B,EAC7B,wBAAwB,GACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,0BAA0B,EAC1B,sBAAsB,EACtB,0BAA0B,EAC1B,+BAA+B,EAC/B,0BAA0B,GAC1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACN,yBAAyB,EACzB,yBAAyB,EACzB,qBAAqB,EACrB,yBAAyB,EACzB,8BAA8B,GAC9B,MAAM,yBAAyB,CAAC;AAGjC;;GAEG;AACH,MAAM,cAAc,GAAqB;IACxC,uBAAuB,EAAE,6BAA6B;IACtD,kBAAkB,EAAE,wBAAwB;IAC5C,cAAc,EAAE,oBAAoB;IACpC,kBAAkB,EAAE,wBAAwB;IAC5C,kBAAkB,EAAE,wBAAwB;CAC5C,CAAC;AAEF;;GAEG;AACH,MAAM,gBAAgB,GAAqB;IAC1C,uBAAuB,EAAE,+BAA+B;IACxD,kBAAkB,EAAE,0BAA0B;IAC9C,cAAc,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yCAAyC;QACzC,OAAO,OAAO,CAAC;IAChB,CAAC;IAED,2BAA2B;IAC3B,MAAM,UAAU,GAAsC,EAAE,CAAC;IAEzD,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACrC,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;YACpB,KAAK,MAAM,EAAE,CAAC;gBACb,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACvB,MAAM;YACP,CAAC;YACD,KAAK,UAAU,EAAE,CAAC;gBACjB,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACvB,MAAM;YACP,CAAC;YACD,KAAK,UAAU,EAAE,CAAC;gBACjB,MAAM,YAAY,GAAG,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;gBAC1E,UAAU,CAAC,IAAI,CAAC;oBACf,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,YAAY;iBAClB,CAAC,CAAC;gBACH,MAAM;YACP,CAAC;QACF,CAAC;IACF,CAAC;IAED,uDAAuD;IACvD,OAAO;QACN,GAAG,OAAO;QACV,OAAO,EAAE,UAAU;KACnB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,0BAA0B,CAAC,OAA0B,EAAE,QAA0B;IACzF,sDAAsD;IACtD,MAAM,iBAAiB,GAAG,QAAQ,CAAC,kBAAkB,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAE7G,0CAA0C;IAC1C,OAAO;QACN,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,iBAAiB;QAC1B,SAAS,EAAE,OAAO,CAAC,SAAS;KAC5B,CAAC;AACH,CAAC","sourcesContent":["import type {\n\tAssistantMessage,\n\tContext,\n\tMessage,\n\tTextContent,\n\tThinkingContent,\n\tToolResultMessage,\n\tUserMessage,\n} from \"../types.ts\";\nimport {\n\tanthropicXmlFormatToolCall,\n\tanthropicXmlFormatToolResponse,\n\tanthropicXmlFormatToolsSystemPrompt,\n\tcreateAnthropicXmlStreamParser,\n\tparseAnthropicXmlGeneratedText,\n} from \"./protocols/anthropic-xml/index.ts\";\nimport {\n\tgemma4CreateStreamParser,\n\tgemma4FormatToolCall,\n\tgemma4FormatToolResponse,\n\tgemma4FormatToolsSystemPrompt,\n\tgemma4ParseGeneratedText,\n} from \"./protocols/gemma4.ts\";\nimport {\n\thermesCreateStreamParser,\n\thermesFormatToolCall,\n\thermesFormatToolResponse,\n\thermesFormatToolsSystemPrompt,\n\thermesParseGeneratedText,\n} from \"./protocols/hermes.ts\";\nimport {\n\tcreateMorphXmlStreamParser,\n\tmorphXmlFormatToolCall,\n\tmorphXmlFormatToolResponse,\n\tmorphXmlFormatToolsSystemPrompt,\n\tparseMorphXmlGeneratedText,\n} from \"./protocols/morph-xml.ts\";\nimport {\n\tcreateYamlXmlStreamParser,\n\tparseYamlXmlGeneratedText,\n\tyamlXmlFormatToolCall,\n\tyamlXmlFormatToolResponse,\n\tyamlXmlFormatToolsSystemPrompt,\n} from \"./protocols/yaml-xml.ts\";\nimport type { ToolCallFormat, ToolCallProtocol } from \"./types.ts\";\n\n/**\n * Hermes protocol implementation for tool call formatting and parsing.\n */\nconst hermesProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: hermesFormatToolsSystemPrompt,\n\tformatToolResponse: hermesFormatToolResponse,\n\tformatToolCall: hermesFormatToolCall,\n\tparseGeneratedText: hermesParseGeneratedText,\n\tcreateStreamParser: hermesCreateStreamParser,\n};\n\n/**\n * MorphXml protocol implementation for tool call formatting and parsing.\n */\nconst morphXmlProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: morphXmlFormatToolsSystemPrompt,\n\tformatToolResponse: morphXmlFormatToolResponse,\n\tformatToolCall: morphXmlFormatToolCall,\n\tparseGeneratedText: parseMorphXmlGeneratedText,\n\tcreateStreamParser: createMorphXmlStreamParser,\n};\n\nconst yamlXmlProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: yamlXmlFormatToolsSystemPrompt,\n\tformatToolResponse: yamlXmlFormatToolResponse,\n\tformatToolCall: yamlXmlFormatToolCall,\n\tparseGeneratedText: parseYamlXmlGeneratedText,\n\tcreateStreamParser: createYamlXmlStreamParser,\n};\n\n/**\n * Gemma 4 protocol implementation for tool call formatting and parsing.\n */\nconst gemma4Protocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: gemma4FormatToolsSystemPrompt,\n\tformatToolResponse: gemma4FormatToolResponse,\n\tformatToolCall: gemma4FormatToolCall,\n\tparseGeneratedText: gemma4ParseGeneratedText,\n\tcreateStreamParser: gemma4CreateStreamParser,\n};\n\nconst anthropicXmlProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: anthropicXmlFormatToolsSystemPrompt,\n\tformatToolResponse: anthropicXmlFormatToolResponse,\n\tformatToolCall: anthropicXmlFormatToolCall,\n\tparseGeneratedText: parseAnthropicXmlGeneratedText,\n\tcreateStreamParser: createAnthropicXmlStreamParser,\n};\n\n/**\n * Protocol registry mapping format strings to protocol implementations.\n */\nconst protocolRegistry: Record<ToolCallFormat, ToolCallProtocol> = {\n\t\"anthropic-xml\": anthropicXmlProtocol,\n\thermes: hermesProtocol,\n\txml: morphXmlProtocol,\n\t\"yaml-xml\": yamlXmlProtocol,\n\t\"gemma4-delimiter\": gemma4Protocol,\n};\n\n/**\n * Gets the protocol implementation for a given tool call format.\n * @param format - The tool call format\n * @returns The protocol implementation\n * @throws Error if the format is not supported\n */\nexport function getProtocol(format: ToolCallFormat): ToolCallProtocol {\n\tconst protocol = protocolRegistry[format];\n\tif (!protocol) {\n\t\tthrow new Error(`Unsupported tool call format: ${format}`);\n\t}\n\treturn protocol;\n}\n\n/**\n * Transforms a context for text-based tool calling.\n * - Strips tools from context (provider sees tool-free request)\n * - Injects tool definitions into system prompt\n * - Converts tool call messages in history to text format\n * - Converts tool result messages to user messages with text content\n *\n * @param context - The original context\n * @param protocol - The protocol to use for formatting\n * @returns A new transformed context (original is not mutated)\n */\nexport function transformContext(context: Context, protocol: ToolCallProtocol): Context {\n\t// Build new context without mutating original\n\tconst transformed: Context = {\n\t\tsystemPrompt: context.systemPrompt,\n\t\tmessages: context.messages.map((msg) => transformMessage(msg, protocol)),\n\t\ttools: undefined, // Strip tools - provider sees tool-free request\n\t};\n\n\t// Inject tool definitions into system prompt if tools exist\n\tif (context.tools && context.tools.length > 0) {\n\t\tconst toolPrompt = protocol.formatToolsSystemPrompt(context.tools);\n\t\tif (toolPrompt) {\n\t\t\ttransformed.systemPrompt = context.systemPrompt ? `${toolPrompt}\\n\\n${context.systemPrompt}` : toolPrompt;\n\t\t}\n\t}\n\n\treturn transformed;\n}\n\n/**\n * Transforms a single message for text-based tool calling.\n * - AssistantMessage with ToolCall blocks: convert to text\n * - ToolResultMessage: convert to UserMessage with text content\n * - Other messages: pass through unchanged\n */\nfunction transformMessage(message: Message, protocol: ToolCallProtocol): Message {\n\tswitch (message.role) {\n\t\tcase \"assistant\": {\n\t\t\treturn transformAssistantMessage(message, protocol);\n\t\t}\n\t\tcase \"toolResult\": {\n\t\t\treturn transformToolResultMessage(message, protocol);\n\t\t}\n\t\tdefault: {\n\t\t\treturn message;\n\t\t}\n\t}\n}\n\n/**\n * Transforms an AssistantMessage, converting ToolCall content blocks to text.\n */\nfunction transformAssistantMessage(message: AssistantMessage, protocol: ToolCallProtocol): AssistantMessage {\n\t// Check if message has any ToolCall content blocks\n\tconst hasToolCalls = message.content.some((block) => block.type === \"toolCall\");\n\tif (!hasToolCalls) {\n\t\t// No tool calls - pass through unchanged\n\t\treturn message;\n\t}\n\n\t// Transform content blocks\n\tconst newContent: (TextContent | ThinkingContent)[] = [];\n\n\tfor (const block of message.content) {\n\t\tswitch (block.type) {\n\t\t\tcase \"text\": {\n\t\t\t\tnewContent.push(block);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"thinking\": {\n\t\t\t\tnewContent.push(block);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"toolCall\": {\n\t\t\t\tconst toolCallText = protocol.formatToolCall(block.name, block.arguments);\n\t\t\t\tnewContent.push({\n\t\t\t\t\ttype: \"text\",\n\t\t\t\t\ttext: toolCallText,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Return new AssistantMessage with transformed content\n\treturn {\n\t\t...message,\n\t\tcontent: newContent,\n\t};\n}\n\n/**\n * Transforms a ToolResultMessage to a UserMessage with text content.\n */\nfunction transformToolResultMessage(message: ToolResultMessage, protocol: ToolCallProtocol): UserMessage {\n\t// Format tool result as text using protocol formatter\n\tconst formattedResponse = protocol.formatToolResponse(message.toolName, message.toolCallId, message.content);\n\n\t// Return as UserMessage with text content\n\treturn {\n\t\trole: \"user\",\n\t\tcontent: formattedResponse,\n\t\ttimestamp: message.timestamp,\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"context-transformer.js","sourceRoot":"","sources":["../../src/tool-call-middleware/context-transformer.ts"],"names":[],"mappings":"AASA,OAAO,EACN,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,6BAA6B,EAC7B,wBAAwB,GACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,6BAA6B,EAC7B,wBAAwB,GACxB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,0BAA0B,EAC1B,sBAAsB,EACtB,0BAA0B,EAC1B,+BAA+B,EAC/B,0BAA0B,GAC1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACN,yBAAyB,EACzB,yBAAyB,EACzB,qBAAqB,EACrB,yBAAyB,EACzB,8BAA8B,GAC9B,MAAM,yBAAyB,CAAC;AAGjC;;GAEG;AACH,MAAM,cAAc,GAAqB;IACxC,uBAAuB,EAAE,6BAA6B;IACtD,kBAAkB,EAAE,wBAAwB;IAC5C,cA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ACzC,OAAO,OAAO,CAAC;IAChB,CAAC;IAED,2BAA2B;IAC3B,MAAM,UAAU,GAAsC,EAAE,CAAC;IAEzD,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACrC,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;YACpB,KAAK,MAAM,EAAE,CAAC;gBACb,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACvB,MAAM;YACP,CAAC;YACD,KAAK,UAAU,EAAE,CAAC;gBACjB,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACvB,MAAM;YACP,CAAC;YACD,KAAK,UAAU,EAAE,CAAC;gBACjB,MAAM,YAAY,GAAG,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;gBAC1E,UAAU,CAAC,IAAI,CAAC;oBACf,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,YAAY;iBAClB,CAAC,CAAC;gBACH,MAAM;YACP,CAAC;QACF,CAAC;IACF,CAAC;IAED,uDAAuD;IACvD,OAAO;QACN,GAAG,OAAO;QACV,OAAO,EAAE,UAAU;KACnB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAS,0BAA0B,CAAC,OAA0B,EAAE,QAA0B;IACzF,sDAAsD;IACtD,MAAM,iBAAiB,GAAG,QAAQ,CAAC,kBAAkB,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAE7G,0CAA0C;IAC1C,OAAO;QACN,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,iBAAiB;QAC1B,SAAS,EAAE,OAAO,CAAC,SAAS;KAC5B,CAAC;AACH,CAAC","sourcesContent":["import type {\n\tAssistantMessage,\n\tContext,\n\tMessage,\n\tTextContent,\n\tThinkingContent,\n\tToolResultMessage,\n\tUserMessage,\n} from \"../types.ts\";\nimport {\n\tgemma4CreateStreamParser,\n\tgemma4FormatToolCall,\n\tgemma4FormatToolResponse,\n\tgemma4FormatToolsSystemPrompt,\n\tgemma4ParseGeneratedText,\n} from \"./protocols/gemma4.ts\";\nimport {\n\thermesCreateStreamParser,\n\thermesFormatToolCall,\n\thermesFormatToolResponse,\n\thermesFormatToolsSystemPrompt,\n\thermesParseGeneratedText,\n} from \"./protocols/hermes.ts\";\nimport {\n\tcreateMorphXmlStreamParser,\n\tmorphXmlFormatToolCall,\n\tmorphXmlFormatToolResponse,\n\tmorphXmlFormatToolsSystemPrompt,\n\tparseMorphXmlGeneratedText,\n} from \"./protocols/morph-xml.ts\";\nimport {\n\tcreateYamlXmlStreamParser,\n\tparseYamlXmlGeneratedText,\n\tyamlXmlFormatToolCall,\n\tyamlXmlFormatToolResponse,\n\tyamlXmlFormatToolsSystemPrompt,\n} from \"./protocols/yaml-xml.ts\";\nimport type { ToolCallFormat, ToolCallProtocol } from \"./types.ts\";\n\n/**\n * Hermes protocol implementation for tool call formatting and parsing.\n */\nconst hermesProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: hermesFormatToolsSystemPrompt,\n\tformatToolResponse: hermesFormatToolResponse,\n\tformatToolCall: hermesFormatToolCall,\n\tparseGeneratedText: hermesParseGeneratedText,\n\tcreateStreamParser: hermesCreateStreamParser,\n};\n\n/**\n * MorphXml protocol implementation for tool call formatting and parsing.\n */\nconst morphXmlProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: morphXmlFormatToolsSystemPrompt,\n\tformatToolResponse: morphXmlFormatToolResponse,\n\tformatToolCall: morphXmlFormatToolCall,\n\tparseGeneratedText: parseMorphXmlGeneratedText,\n\tcreateStreamParser: createMorphXmlStreamParser,\n};\n\nconst yamlXmlProtocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: yamlXmlFormatToolsSystemPrompt,\n\tformatToolResponse: yamlXmlFormatToolResponse,\n\tformatToolCall: yamlXmlFormatToolCall,\n\tparseGeneratedText: parseYamlXmlGeneratedText,\n\tcreateStreamParser: createYamlXmlStreamParser,\n};\n\n/**\n * Gemma 4 protocol implementation for tool call formatting and parsing.\n */\nconst gemma4Protocol: ToolCallProtocol = {\n\tformatToolsSystemPrompt: gemma4FormatToolsSystemPrompt,\n\tformatToolResponse: gemma4FormatToolResponse,\n\tformatToolCall: gemma4FormatToolCall,\n\tparseGeneratedText: gemma4ParseGeneratedText,\n\tcreateStreamParser: gemma4CreateStreamParser,\n};\n\n/**\n * Protocol registry mapping format strings to protocol implementations.\n */\nconst protocolRegistry: Record<ToolCallFormat, ToolCallProtocol> = {\n\thermes: hermesProtocol,\n\txml: morphXmlProtocol,\n\t\"yaml-xml\": yamlXmlProtocol,\n\t\"gemma4-delimiter\": gemma4Protocol,\n};\n\n/**\n * Gets the protocol implementation for a given tool call format.\n * @param format - The tool call format\n * @returns The protocol implementation\n * @throws Error if the format is not supported\n */\nexport function getProtocol(format: ToolCallFormat): ToolCallProtocol {\n\tconst protocol = protocolRegistry[format];\n\tif (!protocol) {\n\t\tthrow new Error(`Unsupported tool call format: ${format}`);\n\t}\n\treturn protocol;\n}\n\n/**\n * Transforms a context for text-based tool calling.\n * - Strips tools from context (provider sees tool-free request)\n * - Injects tool definitions into system prompt\n * - Converts tool call messages in history to text format\n * - Converts tool result messages to user messages with text content\n *\n * @param context - The original context\n * @param protocol - The protocol to use for formatting\n * @returns A new transformed context (original is not mutated)\n */\nexport function transformContext(context: Context, protocol: ToolCallProtocol): Context {\n\t// Build new context without mutating original\n\tconst transformed: Context = {\n\t\tsystemPrompt: context.systemPrompt,\n\t\tmessages: context.messages.map((msg) => transformMessage(msg, protocol)),\n\t\ttools: undefined, // Strip tools - provider sees tool-free request\n\t};\n\n\t// Inject tool definitions into system prompt if tools exist\n\tif (context.tools && context.tools.length > 0) {\n\t\tconst toolPrompt = protocol.formatToolsSystemPrompt(context.tools);\n\t\tif (toolPrompt) {\n\t\t\ttransformed.systemPrompt = context.systemPrompt ? `${toolPrompt}\\n\\n${context.systemPrompt}` : toolPrompt;\n\t\t}\n\t}\n\n\treturn transformed;\n}\n\n/**\n * Transforms a single message for text-based tool calling.\n * - AssistantMessage with ToolCall blocks: convert to text\n * - ToolResultMessage: convert to UserMessage with text content\n * - Other messages: pass through unchanged\n */\nfunction transformMessage(message: Message, protocol: ToolCallProtocol): Message {\n\tswitch (message.role) {\n\t\tcase \"assistant\": {\n\t\t\treturn transformAssistantMessage(message, protocol);\n\t\t}\n\t\tcase \"toolResult\": {\n\t\t\treturn transformToolResultMessage(message, protocol);\n\t\t}\n\t\tdefault: {\n\t\t\treturn message;\n\t\t}\n\t}\n}\n\n/**\n * Transforms an AssistantMessage, converting ToolCall content blocks to text.\n */\nfunction transformAssistantMessage(message: AssistantMessage, protocol: ToolCallProtocol): AssistantMessage {\n\t// Check if message has any ToolCall content blocks\n\tconst hasToolCalls = message.content.some((block) => block.type === \"toolCall\");\n\tif (!hasToolCalls) {\n\t\t// No tool calls - pass through unchanged\n\t\treturn message;\n\t}\n\n\t// Transform content blocks\n\tconst newContent: (TextContent | ThinkingContent)[] = [];\n\n\tfor (const block of message.content) {\n\t\tswitch (block.type) {\n\t\t\tcase \"text\": {\n\t\t\t\tnewContent.push(block);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"thinking\": {\n\t\t\t\tnewContent.push(block);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase \"toolCall\": {\n\t\t\t\tconst toolCallText = protocol.formatToolCall(block.name, block.arguments);\n\t\t\t\tnewContent.push({\n\t\t\t\t\ttype: \"text\",\n\t\t\t\t\ttext: toolCallText,\n\t\t\t\t});\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t// Return new AssistantMessage with transformed content\n\treturn {\n\t\t...message,\n\t\tcontent: newContent,\n\t};\n}\n\n/**\n * Transforms a ToolResultMessage to a UserMessage with text content.\n */\nfunction transformToolResultMessage(message: ToolResultMessage, protocol: ToolCallProtocol): UserMessage {\n\t// Format tool result as text using protocol formatter\n\tconst formattedResponse = protocol.formatToolResponse(message.toolName, message.toolCallId, message.content);\n\n\t// Return as UserMessage with text content\n\treturn {\n\t\trole: \"user\",\n\t\tcontent: formattedResponse,\n\t\ttimestamp: message.timestamp,\n\t};\n}\n"]}
|
|
@@ -7,7 +7,7 @@ export type { ParsedToolCall, StreamParser, StreamParserEvent, ToolCallFormat, T
|
|
|
7
7
|
* Extracts the tool call format from a model's compatibility settings.
|
|
8
8
|
* Only applies to models using the "openai-completions" API with compat settings.
|
|
9
9
|
* @param model - The model to check
|
|
10
|
-
* @returns The
|
|
10
|
+
* @returns The tool call format ("hermes", "xml", "yaml-xml", or "gemma4-delimiter") or undefined if not set
|
|
11
11
|
*/
|
|
12
12
|
export declare function getToolCallFormat<TApi extends Api>(model: Model<TApi>): ToolCallFormat | undefined;
|
|
13
13
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tool-call-middleware/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAA2B,MAAM,aAAa,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;AACvE,YAAY,EACX,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,GACjB,MAAM,YAAY,CAAC;AAEpB;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,SAAS,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,cAAc,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tool-call-middleware/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAA2B,MAAM,aAAa,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;AACvE,YAAY,EACX,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,GACjB,MAAM,YAAY,CAAC;AAEpB;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,SAAS,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,GAAG,cAAc,GAAG,SAAS,CAalG"}
|
|
@@ -4,7 +4,7 @@ export { wrapStreamWithToolCallMiddleware } from "./stream-wrapper.js";
|
|
|
4
4
|
* Extracts the tool call format from a model's compatibility settings.
|
|
5
5
|
* Only applies to models using the "openai-completions" API with compat settings.
|
|
6
6
|
* @param model - The model to check
|
|
7
|
-
* @returns The
|
|
7
|
+
* @returns The tool call format ("hermes", "xml", "yaml-xml", or "gemma4-delimiter") or undefined if not set
|
|
8
8
|
*/
|
|
9
9
|
export function getToolCallFormat(model) {
|
|
10
10
|
if (model.api !== "openai-completions") {
|
|
@@ -15,11 +15,7 @@ export function getToolCallFormat(model) {
|
|
|
15
15
|
if (!format) {
|
|
16
16
|
return undefined;
|
|
17
17
|
}
|
|
18
|
-
if (format === "hermes" ||
|
|
19
|
-
format === "xml" ||
|
|
20
|
-
format === "yaml-xml" ||
|
|
21
|
-
format === "gemma4-delimiter" ||
|
|
22
|
-
format === "anthropic-xml") {
|
|
18
|
+
if (format === "hermes" || format === "xml" || format === "yaml-xml" || format === "gemma4-delimiter") {
|
|
23
19
|
return format;
|
|
24
20
|
}
|
|
25
21
|
return undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tool-call-middleware/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;AAUvE;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAmB,KAAkB;IACrE,IAAI,KAAK,CAAC,GAAG,KAAK,oBAAoB,EAAE,CAAC;QACxC,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,MAAM,MAAM,GAAG,KAAK,CAAC,MAA6C,CAAC;IACnE,MAAM,MAAM,GAAG,MAAM,EAAE,cAAc,CAAC;IACtC,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tool-call-middleware/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAE,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;AAUvE;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAmB,KAAkB;IACrE,IAAI,KAAK,CAAC,GAAG,KAAK,oBAAoB,EAAE,CAAC;QACxC,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,MAAM,MAAM,GAAG,KAAK,CAAC,MAA6C,CAAC;IACnE,MAAM,MAAM,GAAG,MAAM,EAAE,cAAc,CAAC;IACtC,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,IAAI,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,KAAK,IAAI,MAAM,KAAK,UAAU,IAAI,MAAM,KAAK,kBAAkB,EAAE,CAAC;QACvG,OAAO,MAAM,CAAC;IACf,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["import type { Api, Model, OpenAICompletionsCompat } from \"../types.ts\";\nimport type { ToolCallFormat } from \"./types.ts\";\n\nexport { getProtocol, transformContext } from \"./context-transformer.ts\";\nexport { wrapStreamWithToolCallMiddleware } from \"./stream-wrapper.ts\";\nexport type {\n\tParsedToolCall,\n\tStreamParser,\n\tStreamParserEvent,\n\tToolCallFormat,\n\tToolCallProtocol,\n\tToolResultContent,\n} from \"./types.ts\";\n\n/**\n * Extracts the tool call format from a model's compatibility settings.\n * Only applies to models using the \"openai-completions\" API with compat settings.\n * @param model - The model to check\n * @returns The tool call format (\"hermes\", \"xml\", \"yaml-xml\", or \"gemma4-delimiter\") or undefined if not set\n */\nexport function getToolCallFormat<TApi extends Api>(model: Model<TApi>): ToolCallFormat | undefined {\n\tif (model.api !== \"openai-completions\") {\n\t\treturn undefined;\n\t}\n\tconst compat = model.compat as OpenAICompletionsCompat | undefined;\n\tconst format = compat?.toolCallFormat;\n\tif (!format) {\n\t\treturn undefined;\n\t}\n\tif (format === \"hermes\" || format === \"xml\" || format === \"yaml-xml\" || format === \"gemma4-delimiter\") {\n\t\treturn format;\n\t}\n\treturn undefined;\n}\n"]}
|
|
@@ -3,11 +3,9 @@ import type { ImageContent, TextContent, Tool } from "../types.ts";
|
|
|
3
3
|
* Supported tool call formats for models that don't natively support tool calling.
|
|
4
4
|
* - "hermes": Hermes 2/3 format with special delimiters
|
|
5
5
|
* - "xml": XML-based tool call format
|
|
6
|
-
* - "yaml-xml": YAML arguments inside XML tool tags
|
|
7
6
|
* - "gemma4-delimiter": Gemma 4 specific delimiter format
|
|
8
|
-
* - "anthropic-xml": Legacy Anthropic invoke/parameter XML format
|
|
9
7
|
*/
|
|
10
|
-
export type ToolCallFormat = "hermes" | "xml" | "yaml-xml" | "gemma4-delimiter"
|
|
8
|
+
export type ToolCallFormat = "hermes" | "xml" | "yaml-xml" | "gemma4-delimiter";
|
|
11
9
|
/**
|
|
12
10
|
* Content type for tool results (text or image)
|
|
13
11
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tool-call-middleware/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnE
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tool-call-middleware/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnE;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,KAAK,GAAG,UAAU,GAAG,kBAAkB,CAAC;AAEhF;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,YAAY,CAAC;AAE3D,MAAM,WAAW,aAAa;IAC7B,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;CACxE;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAC1B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GACnE;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,GACjE;IACA,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC,CAAC;AAEL;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B;;;;OAIG;IACH,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,iBAAiB,EAAE,CAAC;IAE7C;;;OAGG;IACH,MAAM,IAAI,iBAAiB,EAAE,CAAC;CAC9B;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAChC;;;;OAIG;IACH,uBAAuB,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC;IAE/C;;;;;;OAMG;IACH,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;IAE/F;;;;;OAKG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC;IAEpE;;;;;OAKG;IACH,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,cAAc,EAAE,CAAC;IAE3F;;;;OAIG;IACH,kBAAkB,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,YAAY,CAAC;CACzE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tool-call-middleware/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ImageContent, TextContent, Tool } from \"../types.ts\";\n\n/**\n * Supported tool call formats for models that don't natively support tool calling.\n * - \"hermes\": Hermes 2/3 format with special delimiters\n * - \"xml\": XML-based tool call format\n * - \"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tool-call-middleware/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ImageContent, TextContent, Tool } from \"../types.ts\";\n\n/**\n * Supported tool call formats for models that don't natively support tool calling.\n * - \"hermes\": Hermes 2/3 format with special delimiters\n * - \"xml\": XML-based tool call format\n * - \"gemma4-delimiter\": Gemma 4 specific delimiter format\n */\nexport type ToolCallFormat = \"hermes\" | \"xml\" | \"yaml-xml\" | \"gemma4-delimiter\";\n\n/**\n * Content type for tool results (text or image)\n */\nexport type ToolResultContent = TextContent | ImageContent;\n\nexport interface ParserOptions {\n\temitRawToolCallTextOnError?: boolean;\n\tonError?: (message: string, metadata?: Record<string, unknown>) => void;\n}\n\n/**\n * A parsed tool call extracted from generated text\n */\nexport interface ParsedToolCall {\n\tname: string;\n\targuments: Record<string, unknown>;\n}\n\n/**\n * Events emitted by the stream parser during text processing.\n * Maps 1:1 to AssistantMessageEventStream events for seamless integration.\n */\nexport type StreamParserEvent =\n\t| { type: \"text\"; text: string }\n\t| { type: \"toolcall_start\"; index: number; name: string; id: string }\n\t| { type: \"toolcall_delta\"; index: number; argumentsDelta: string }\n\t| {\n\t\t\ttype: \"toolcall_end\";\n\t\t\tindex: number;\n\t\t\tname: string;\n\t\t\tid: string;\n\t\t\targuments: Record<string, unknown>;\n\t };\n\n/**\n * Stream parser for incremental tool call parsing during streaming.\n */\nexport interface StreamParser {\n\t/**\n\t * Feed a text delta into the parser and receive any events generated.\n\t * @param textDelta - The next chunk of text to parse\n\t * @returns Array of parser events (text or tool call events)\n\t */\n\tfeed(textDelta: string): StreamParserEvent[];\n\n\t/**\n\t * Signal that the stream has ended and receive any final events.\n\t * @returns Array of final parser events\n\t */\n\tfinish(): StreamParserEvent[];\n}\n\n/**\n * Protocol interface for formatting and parsing tool calls in different formats.\n * Implementations handle the specifics of each tool call format (Hermes, XML, etc.)\n */\nexport interface ToolCallProtocol {\n\t/**\n\t * Format tools into a system prompt that instructs the model how to use tools.\n\t * @param tools - Array of available tools\n\t * @returns Formatted system prompt string\n\t */\n\tformatToolsSystemPrompt(tools: Tool[]): string;\n\n\t/**\n\t * Format a tool response for inclusion in the conversation context.\n\t * @param toolName - Name of the tool that was called\n\t * @param toolCallId - Unique identifier for this tool call\n\t * @param content - Array of content blocks (text or images) representing the result\n\t * @returns Formatted tool response string\n\t */\n\tformatToolResponse(toolName: string, toolCallId: string, content: ToolResultContent[]): string;\n\n\t/**\n\t * Format a tool call for sending to the model.\n\t * @param name - Name of the tool to call\n\t * @param args - Arguments for the tool call\n\t * @returns Formatted tool call string\n\t */\n\tformatToolCall(name: string, args: Record<string, unknown>): string;\n\n\t/**\n\t * Parse generated text to extract tool calls.\n\t * @param text - The generated text to parse\n\t * @param tools - Available tools for validation\n\t * @returns Array of parsed tool calls\n\t */\n\tparseGeneratedText(text: string, tools: Tool[], options?: ParserOptions): ParsedToolCall[];\n\n\t/**\n\t * Create a stream parser for incremental parsing during streaming.\n\t * @param tools - Available tools for the parser to recognize\n\t * @returns A new StreamParser instance\n\t */\n\tcreateStreamParser(tools: Tool[], options?: ParserOptions): StreamParser;\n}\n"]}
|
|
Binary file
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@earendil-works/pi-tui",
|
|
3
3
|
"private": true,
|
|
4
|
-
"version": "2026.7.14
|
|
4
|
+
"version": "2026.7.14",
|
|
5
5
|
"description": "Terminal User Interface library with differential rendering for efficient text-based applications",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "dist/index.js",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-yeongyu/senpi",
|
|
3
|
-
"version": "2026.7.14
|
|
3
|
+
"version": "2026.7.14",
|
|
4
4
|
"description": "Coding agent CLI with read, bash, edit, write tools and session management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"piConfig": {
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@anthropic-ai/sdk": "0.91.1",
|
|
45
45
|
"@aws-sdk/client-bedrock-runtime": "3.1048.0",
|
|
46
|
-
"@code-yeongyu/senpi-codemode": "^2026.7.14
|
|
47
|
-
"@earendil-works/pi-agent-core": "^2026.7.14
|
|
48
|
-
"@earendil-works/pi-ai": "^2026.7.14
|
|
49
|
-
"@earendil-works/pi-pty": "^2026.7.14
|
|
50
|
-
"@earendil-works/pi-tui": "^2026.7.14
|
|
46
|
+
"@code-yeongyu/senpi-codemode": "^2026.7.14",
|
|
47
|
+
"@earendil-works/pi-agent-core": "^2026.7.14",
|
|
48
|
+
"@earendil-works/pi-ai": "^2026.7.14",
|
|
49
|
+
"@earendil-works/pi-pty": "^2026.7.14",
|
|
50
|
+
"@earendil-works/pi-tui": "^2026.7.14",
|
|
51
51
|
"@mistralai/mistralai": "2.2.6",
|
|
52
52
|
"@modelcontextprotocol/sdk": "1.29.0",
|
|
53
53
|
"@mozilla/readability": "0.6.0",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Tool } from "../../../types.ts";
|
|
2
|
-
type RawParameter = {
|
|
3
|
-
readonly name: string;
|
|
4
|
-
readonly rawValue: string;
|
|
5
|
-
};
|
|
6
|
-
export declare function coerceParameters(rawParams: readonly RawParameter[], tool: Tool): Record<string, unknown> | null;
|
|
7
|
-
export {};
|
|
8
|
-
//# sourceMappingURL=coerce-parameters.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"coerce-parameters.d.ts","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAG9C,KAAK,YAAY,GAAG;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC1B,CAAC;AAYF,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,SAAS,YAAY,EAAE,EAAE,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CA6B/G"}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { IsArray, IsBoolean, IsInteger, IsNumber, IsObject, IsString } from "typebox";
|
|
2
|
-
import { Value } from "typebox/value";
|
|
3
|
-
import { decodeXmlEntities } from "./xml-entities.js";
|
|
4
|
-
const INVALID = { ok: false };
|
|
5
|
-
const LEADING_RAW_NEWLINE = /^(?:\r\n|\r|\n)/;
|
|
6
|
-
const TRAILING_RAW_NEWLINE = /(?:\r\n|\r|\n)$/;
|
|
7
|
-
function trimRawBoundaryNewlines(value) {
|
|
8
|
-
return value.replace(LEADING_RAW_NEWLINE, "").replace(TRAILING_RAW_NEWLINE, "");
|
|
9
|
-
}
|
|
10
|
-
export function coerceParameters(rawParams, tool) {
|
|
11
|
-
if (!IsObject(tool.parameters)) {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
const argumentsRecord = {};
|
|
15
|
-
for (const rawParam of rawParams) {
|
|
16
|
-
if (Object.hasOwn(argumentsRecord, rawParam.name)) {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
const propertySchema = tool.parameters.properties[rawParam.name];
|
|
20
|
-
const rawValue = trimRawBoundaryNewlines(rawParam.rawValue);
|
|
21
|
-
const result = propertySchema
|
|
22
|
-
? coerceKnownValue(rawValue, propertySchema)
|
|
23
|
-
: { ok: true, value: coerceUnknownValue(rawValue) };
|
|
24
|
-
if (!result.ok) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
Object.defineProperty(argumentsRecord, rawParam.name, {
|
|
28
|
-
configurable: true,
|
|
29
|
-
enumerable: true,
|
|
30
|
-
value: result.value,
|
|
31
|
-
writable: true,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
return passesToolValidation(tool, argumentsRecord) ? argumentsRecord : null;
|
|
35
|
-
}
|
|
36
|
-
function coerceKnownValue(rawValue, schema) {
|
|
37
|
-
const value = decodeXmlEntities(rawValue);
|
|
38
|
-
if (IsString(schema)) {
|
|
39
|
-
return { ok: true, value };
|
|
40
|
-
}
|
|
41
|
-
if (IsNumber(schema) || IsInteger(schema)) {
|
|
42
|
-
if (value.trim().length === 0) {
|
|
43
|
-
return INVALID;
|
|
44
|
-
}
|
|
45
|
-
const parsed = Number(value);
|
|
46
|
-
if (!Number.isFinite(parsed) || (IsInteger(schema) && !Number.isInteger(parsed))) {
|
|
47
|
-
return INVALID;
|
|
48
|
-
}
|
|
49
|
-
return { ok: true, value: parsed };
|
|
50
|
-
}
|
|
51
|
-
if (IsBoolean(schema)) {
|
|
52
|
-
if (value === "true") {
|
|
53
|
-
return { ok: true, value: true };
|
|
54
|
-
}
|
|
55
|
-
if (value === "false") {
|
|
56
|
-
return { ok: true, value: false };
|
|
57
|
-
}
|
|
58
|
-
return INVALID;
|
|
59
|
-
}
|
|
60
|
-
if (IsArray(schema)) {
|
|
61
|
-
const parsed = tryParseJson(value);
|
|
62
|
-
return parsed.ok && Array.isArray(parsed.value) ? parsed : INVALID;
|
|
63
|
-
}
|
|
64
|
-
if (IsObject(schema)) {
|
|
65
|
-
const parsed = tryParseJson(value);
|
|
66
|
-
return parsed.ok && isJsonObject(parsed.value) ? parsed : INVALID;
|
|
67
|
-
}
|
|
68
|
-
return { ok: true, value: coerceUnknownValue(rawValue) };
|
|
69
|
-
}
|
|
70
|
-
function coerceUnknownValue(rawValue) {
|
|
71
|
-
const value = decodeXmlEntities(rawValue);
|
|
72
|
-
const parsed = tryParseJson(value);
|
|
73
|
-
return parsed.ok ? parsed.value : value;
|
|
74
|
-
}
|
|
75
|
-
function tryParseJson(value) {
|
|
76
|
-
try {
|
|
77
|
-
return { ok: true, value: JSON.parse(value) };
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
if (error instanceof SyntaxError) {
|
|
81
|
-
return INVALID;
|
|
82
|
-
}
|
|
83
|
-
throw error;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function isJsonObject(value) {
|
|
87
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
88
|
-
}
|
|
89
|
-
function passesToolValidation(tool, argumentsRecord) {
|
|
90
|
-
return Value.Check(tool.parameters, argumentsRecord);
|
|
91
|
-
}
|
|
92
|
-
//# sourceMappingURL=coerce-parameters.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"coerce-parameters.js","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/coerce-parameters.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACtF,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAStD,MAAM,OAAO,GAAmB,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC;AAC9C,MAAM,mBAAmB,GAAG,iBAAiB,CAAC;AAC9C,MAAM,oBAAoB,GAAG,iBAAiB,CAAC;AAE/C,SAAS,uBAAuB,CAAC,KAAa;IAC7C,OAAO,KAAK,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAC;AACjF,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,SAAkC,EAAE,IAAU;IAC9E,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,MAAM,eAAe,GAA4B,EAAE,CAAC;IACpD,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QAClC,IAAI,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YACnD,OAAO,IAAI,CAAC;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B,CAAC,QAAgB;IAC3C,MAAM,KAAK,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAC1C,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IACnC,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;AACzC,CAAC;AAED,SAAS,YAAY,CAAC,KAAa;IAClC,IAAI,CAAC;QACJ,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;IAC/C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YAClC,OAAO,OAAO,CAAC;QAChB,CAAC;QACD,MAAM,KAAK,CAAC;IACb,CAAC;AACF,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,oBAAoB,CAAC,IAAU,EAAE,eAAwC;IACjF,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;AACtD,CAAC","sourcesContent":["import type { TSchema } from \"typebox\";\nimport { IsArray, IsBoolean, IsInteger, IsNumber, IsObject, IsString } from \"typebox\";\nimport { Value } from \"typebox/value\";\nimport type { Tool } from \"../../../types.ts\";\nimport { decodeXmlEntities } from \"./xml-entities.ts\";\n\ntype RawParameter = {\n\treadonly name: string;\n\treadonly rawValue: string;\n};\n\ntype CoercionResult = { readonly ok: true; readonly value: unknown } | { readonly ok: false };\n\nconst INVALID: CoercionResult = { ok: false };\nconst LEADING_RAW_NEWLINE = /^(?:\\r\\n|\\r|\\n)/;\nconst TRAILING_RAW_NEWLINE = /(?:\\r\\n|\\r|\\n)$/;\n\nfunction trimRawBoundaryNewlines(value: string): string {\n\treturn value.replace(LEADING_RAW_NEWLINE, \"\").replace(TRAILING_RAW_NEWLINE, \"\");\n}\n\nexport function coerceParameters(rawParams: readonly RawParameter[], tool: Tool): Record<string, unknown> | null {\n\tif (!IsObject(tool.parameters)) {\n\t\treturn null;\n\t}\n\n\tconst argumentsRecord: Record<string, unknown> = {};\n\tfor (const rawParam of rawParams) {\n\t\tif (Object.hasOwn(argumentsRecord, rawParam.name)) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst propertySchema = tool.parameters.properties[rawParam.name];\n\t\tconst rawValue = trimRawBoundaryNewlines(rawParam.rawValue);\n\t\tconst result = propertySchema\n\t\t\t? coerceKnownValue(rawValue, propertySchema)\n\t\t\t: { ok: true, value: coerceUnknownValue(rawValue) };\n\t\tif (!result.ok) {\n\t\t\treturn null;\n\t\t}\n\n\t\tObject.defineProperty(argumentsRecord, rawParam.name, {\n\t\t\tconfigurable: true,\n\t\t\tenumerable: true,\n\t\t\tvalue: result.value,\n\t\t\twritable: true,\n\t\t});\n\t}\n\n\treturn passesToolValidation(tool, argumentsRecord) ? argumentsRecord : null;\n}\n\nfunction coerceKnownValue(rawValue: string, schema: TSchema): CoercionResult {\n\tconst value = decodeXmlEntities(rawValue);\n\n\tif (IsString(schema)) {\n\t\treturn { ok: true, value };\n\t}\n\n\tif (IsNumber(schema) || IsInteger(schema)) {\n\t\tif (value.trim().length === 0) {\n\t\t\treturn INVALID;\n\t\t}\n\t\tconst parsed = Number(value);\n\t\tif (!Number.isFinite(parsed) || (IsInteger(schema) && !Number.isInteger(parsed))) {\n\t\t\treturn INVALID;\n\t\t}\n\t\treturn { ok: true, value: parsed };\n\t}\n\n\tif (IsBoolean(schema)) {\n\t\tif (value === \"true\") {\n\t\t\treturn { ok: true, value: true };\n\t\t}\n\t\tif (value === \"false\") {\n\t\t\treturn { ok: true, value: false };\n\t\t}\n\t\treturn INVALID;\n\t}\n\n\tif (IsArray(schema)) {\n\t\tconst parsed = tryParseJson(value);\n\t\treturn parsed.ok && Array.isArray(parsed.value) ? parsed : INVALID;\n\t}\n\n\tif (IsObject(schema)) {\n\t\tconst parsed = tryParseJson(value);\n\t\treturn parsed.ok && isJsonObject(parsed.value) ? parsed : INVALID;\n\t}\n\n\treturn { ok: true, value: coerceUnknownValue(rawValue) };\n}\n\nfunction coerceUnknownValue(rawValue: string): unknown {\n\tconst value = decodeXmlEntities(rawValue);\n\tconst parsed = tryParseJson(value);\n\treturn parsed.ok ? parsed.value : value;\n}\n\nfunction tryParseJson(value: string): CoercionResult {\n\ttry {\n\t\treturn { ok: true, value: JSON.parse(value) };\n\t} catch (error) {\n\t\tif (error instanceof SyntaxError) {\n\t\t\treturn INVALID;\n\t\t}\n\t\tthrow error;\n\t}\n}\n\nfunction isJsonObject(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction passesToolValidation(tool: Tool, argumentsRecord: Record<string, unknown>): boolean {\n\treturn Value.Check(tool.parameters, argumentsRecord);\n}\n"]}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Tool } from "../../../types.ts";
|
|
2
|
-
import type { ToolResultContent } from "../../types.ts";
|
|
3
|
-
export declare function anthropicXmlFormatToolsSystemPrompt(tools: Tool[]): string;
|
|
4
|
-
export declare function anthropicXmlFormatToolCall(name: string, args: Record<string, unknown>): string;
|
|
5
|
-
export declare function anthropicXmlFormatToolResponse(toolName: string, _toolCallId: string, content: ToolResultContent[]): string;
|
|
6
|
-
//# sourceMappingURL=format.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAuBxD,wBAAgB,mCAAmC,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,CAoBzE;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAO9F;AAED,wBAAgB,8BAA8B,CAC7C,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,iBAAiB,EAAE,GAC1B,MAAM,CAcR"}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { encodeXmlAttribute, encodeXmlParameterText, encodeXmlText } from "./xml-entities.js";
|
|
2
|
-
function serializeToolValue(value) {
|
|
3
|
-
if (typeof value === "object" && value !== null) {
|
|
4
|
-
return JSON.stringify(value) ?? "null";
|
|
5
|
-
}
|
|
6
|
-
return String(value);
|
|
7
|
-
}
|
|
8
|
-
function renderToolDefinitions(tools) {
|
|
9
|
-
const json = JSON.stringify(tools.map((tool) => ({
|
|
10
|
-
name: tool.name,
|
|
11
|
-
description: tool.description,
|
|
12
|
-
parameters: tool.parameters,
|
|
13
|
-
})));
|
|
14
|
-
return json.replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026");
|
|
15
|
-
}
|
|
16
|
-
export function anthropicXmlFormatToolsSystemPrompt(tools) {
|
|
17
|
-
if (tools.length === 0) {
|
|
18
|
-
return "";
|
|
19
|
-
}
|
|
20
|
-
return `# Tools
|
|
21
|
-
|
|
22
|
-
You may call one or more functions to assist with the user query.
|
|
23
|
-
|
|
24
|
-
You are provided with function signatures as JSON within <tools></tools> XML tags:
|
|
25
|
-
<tools>${renderToolDefinitions(tools)}</tools>
|
|
26
|
-
|
|
27
|
-
# Format
|
|
28
|
-
|
|
29
|
-
For each function call, emit exactly one bare <invoke> element with the tool name in its name attribute.
|
|
30
|
-
Put each argument in one <parameter> element with its name in the name attribute.
|
|
31
|
-
Do not wrap the invoke element in another XML element.
|
|
32
|
-
|
|
33
|
-
# Example
|
|
34
|
-
<invoke name="get_weather"><parameter name="city">Seoul</parameter></invoke>`;
|
|
35
|
-
}
|
|
36
|
-
export function anthropicXmlFormatToolCall(name, args) {
|
|
37
|
-
const parameters = Object.entries(args).map(([parameterName, value]) => `<parameter name="${encodeXmlAttribute(parameterName)}">${encodeXmlParameterText(serializeToolValue(value))}</parameter>`);
|
|
38
|
-
return [`<invoke name="${encodeXmlAttribute(name)}">`, ...parameters, "</invoke>"].join("\n");
|
|
39
|
-
}
|
|
40
|
-
export function anthropicXmlFormatToolResponse(toolName, _toolCallId, content) {
|
|
41
|
-
const textContent = content
|
|
42
|
-
.filter((entry) => entry.type === "text")
|
|
43
|
-
.map((entry) => entry.text)
|
|
44
|
-
.join("\n");
|
|
45
|
-
return [
|
|
46
|
-
"<function_results>",
|
|
47
|
-
"<result>",
|
|
48
|
-
`<tool_name>${encodeXmlText(toolName)}</tool_name>`,
|
|
49
|
-
`<stdout>${encodeXmlText(textContent)}</stdout>`,
|
|
50
|
-
"</result>",
|
|
51
|
-
"</function_results>",
|
|
52
|
-
].join("\n");
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=format.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/format.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAE9F,SAAS,kBAAkB,CAAC,KAAc;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACjD,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC;IACxC,CAAC;IAED,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACtB,CAAC;AAED,SAAS,qBAAqB,CAAC,KAAa;IAC3C,MAAM,IAAI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AAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC;SAC1B,IAAI,CAAC,IAAI,CAAC,CAAC;IAEb,OAAO;QACN,oBAAoB;QACpB,UAAU;QACV,cAAc,aAAa,CAAC,QAAQ,CAAC,cAAc;QACnD,WAAW,aAAa,CAAC,WAAW,CAAC,WAAW;QAChD,WAAW;QACX,qBAAqB;KACrB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC","sourcesContent":["import type { Tool } from \"../../../types.ts\";\nimport type { ToolResultContent } from \"../../types.ts\";\nimport { encodeXmlAttribute, encodeXmlParameterText, encodeXmlText } from \"./xml-entities.ts\";\n\nfunction serializeToolValue(value: unknown): string {\n\tif (typeof value === \"object\" && value !== null) {\n\t\treturn JSON.stringify(value) ?? \"null\";\n\t}\n\n\treturn String(value);\n}\n\nfunction renderToolDefinitions(tools: Tool[]): string {\n\tconst json = JSON.stringify(\n\t\ttools.map((tool) => ({\n\t\t\tname: tool.name,\n\t\t\tdescription: tool.description,\n\t\t\tparameters: tool.parameters,\n\t\t})),\n\t);\n\n\treturn json.replace(/</g, \"\\\\u003c\").replace(/>/g, \"\\\\u003e\").replace(/&/g, \"\\\\u0026\");\n}\n\nexport function anthropicXmlFormatToolsSystemPrompt(tools: Tool[]): string {\n\tif (tools.length === 0) {\n\t\treturn \"\";\n\t}\n\n\treturn `# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures as JSON within <tools></tools> XML tags:\n<tools>${renderToolDefinitions(tools)}</tools>\n\n# Format\n\nFor each function call, emit exactly one bare <invoke> element with the tool name in its name attribute.\nPut each argument in one <parameter> element with its name in the name attribute.\nDo not wrap the invoke element in another XML element.\n\n# Example\n<invoke name=\"get_weather\"><parameter name=\"city\">Seoul</parameter></invoke>`;\n}\n\nexport function anthropicXmlFormatToolCall(name: string, args: Record<string, unknown>): string {\n\tconst parameters = Object.entries(args).map(\n\t\t([parameterName, value]) =>\n\t\t\t`<parameter name=\"${encodeXmlAttribute(parameterName)}\">${encodeXmlParameterText(serializeToolValue(value))}</parameter>`,\n\t);\n\n\treturn [`<invoke name=\"${encodeXmlAttribute(name)}\">`, ...parameters, \"</invoke>\"].join(\"\\n\");\n}\n\nexport function anthropicXmlFormatToolResponse(\n\ttoolName: string,\n\t_toolCallId: string,\n\tcontent: ToolResultContent[],\n): string {\n\tconst textContent = content\n\t\t.filter((entry): entry is Extract<ToolResultContent, { type: \"text\" }> => entry.type === \"text\")\n\t\t.map((entry) => entry.text)\n\t\t.join(\"\\n\");\n\n\treturn [\n\t\t\"<function_results>\",\n\t\t\"<result>\",\n\t\t`<tool_name>${encodeXmlText(toolName)}</tool_name>`,\n\t\t`<stdout>${encodeXmlText(textContent)}</stdout>`,\n\t\t\"</result>\",\n\t\t\"</function_results>\",\n\t].join(\"\\n\");\n}\n"]}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { anthropicXmlFormatToolCall, anthropicXmlFormatToolResponse, anthropicXmlFormatToolsSystemPrompt, } from "./format.ts";
|
|
2
|
-
export { parseAnthropicXmlGeneratedText } from "./parse.ts";
|
|
3
|
-
export { createAnthropicXmlStreamParser } from "./stream.ts";
|
|
4
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,0BAA0B,EAC1B,8BAA8B,EAC9B,mCAAmC,GACnC,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { anthropicXmlFormatToolCall, anthropicXmlFormatToolResponse, anthropicXmlFormatToolsSystemPrompt, } from "./format.js";
|
|
2
|
-
export { parseAnthropicXmlGeneratedText } from "./parse.js";
|
|
3
|
-
export { createAnthropicXmlStreamParser } from "./stream.js";
|
|
4
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,0BAA0B,EAC1B,8BAA8B,EAC9B,mCAAmC,GACnC,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,8BAA8B,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export {\n\tanthropicXmlFormatToolCall,\n\tanthropicXmlFormatToolResponse,\n\tanthropicXmlFormatToolsSystemPrompt,\n} from \"./format.ts\";\nexport { parseAnthropicXmlGeneratedText } from \"./parse.ts\";\nexport { createAnthropicXmlStreamParser } from \"./stream.ts\";\n"]}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { InvokeBlockMatch, InvokeOpenTagMatch } from "./invoke-tag-scanner.ts";
|
|
2
|
-
export type InvokeMatch = {
|
|
3
|
-
readonly openingTag: InvokeOpenTagMatch;
|
|
4
|
-
readonly block: InvokeBlockMatch | null;
|
|
5
|
-
};
|
|
6
|
-
export declare function findNextInvokeMatch(text: string, fromIndex: number, matchesToolName: (toolName: string) => boolean): InvokeMatch | null;
|
|
7
|
-
//# sourceMappingURL=invoke-match.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"invoke-match.d.ts","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/invoke-match.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAGpF,MAAM,MAAM,WAAW,GAAG;IACzB,QAAQ,CAAC,UAAU,EAAE,kBAAkB,CAAC;IACxC,QAAQ,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI,CAAC;CACxC,CAAC;AAEF,wBAAgB,mBAAmB,CAClC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,GAC5C,WAAW,GAAG,IAAI,CAapB"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { findInvokeOpenTag, scanInvokeBlock } from "./invoke-tag-scanner.js";
|
|
2
|
-
export function findNextInvokeMatch(text, fromIndex, matchesToolName) {
|
|
3
|
-
let cursor = Math.max(0, fromIndex);
|
|
4
|
-
while (cursor < text.length) {
|
|
5
|
-
const openingTag = findInvokeOpenTag(text, cursor);
|
|
6
|
-
if (!openingTag) {
|
|
7
|
-
return null;
|
|
8
|
-
}
|
|
9
|
-
if (matchesToolName(openingTag.toolName)) {
|
|
10
|
-
return { openingTag, block: scanInvokeBlock(text, openingTag) };
|
|
11
|
-
}
|
|
12
|
-
cursor = openingTag.index + openingTag.length;
|
|
13
|
-
}
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=invoke-match.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"invoke-match.js","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/invoke-match.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAO7E,MAAM,UAAU,mBAAmB,CAClC,IAAY,EACZ,SAAiB,EACjB,eAA8C;IAE9C,IAAI,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;IACpC,OAAO,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QAC7B,MAAM,UAAU,GAAG,iBAAiB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACnD,IAAI,CAAC,UAAU,EAAE,CAAC;YACjB,OAAO,IAAI,CAAC;QACb,CAAC;QACD,IAAI,eAAe,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC1C,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,eAAe,CAAC,IAAI,EAAE,UAAU,CAAC,EAAE,CAAC;QACjE,CAAC;QACD,MAAM,GAAG,UAAU,CAAC,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/C,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["import type { InvokeBlockMatch, InvokeOpenTagMatch } from \"./invoke-tag-scanner.ts\";\nimport { findInvokeOpenTag, scanInvokeBlock } from \"./invoke-tag-scanner.ts\";\n\nexport type InvokeMatch = {\n\treadonly openingTag: InvokeOpenTagMatch;\n\treadonly block: InvokeBlockMatch | null;\n};\n\nexport function findNextInvokeMatch(\n\ttext: string,\n\tfromIndex: number,\n\tmatchesToolName: (toolName: string) => boolean,\n): InvokeMatch | null {\n\tlet cursor = Math.max(0, fromIndex);\n\twhile (cursor < text.length) {\n\t\tconst openingTag = findInvokeOpenTag(text, cursor);\n\t\tif (!openingTag) {\n\t\t\treturn null;\n\t\t}\n\t\tif (matchesToolName(openingTag.toolName)) {\n\t\t\treturn { openingTag, block: scanInvokeBlock(text, openingTag) };\n\t\t}\n\t\tcursor = openingTag.index + openingTag.length;\n\t}\n\treturn null;\n}\n"]}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export type InvokeOpenTagMatch = {
|
|
2
|
-
readonly index: number;
|
|
3
|
-
readonly length: number;
|
|
4
|
-
readonly toolName: string;
|
|
5
|
-
};
|
|
6
|
-
export type InvokeParameter = {
|
|
7
|
-
readonly name: string;
|
|
8
|
-
readonly rawValue: string;
|
|
9
|
-
};
|
|
10
|
-
export type InvokeBlockMatch = {
|
|
11
|
-
readonly contentEnd: number;
|
|
12
|
-
readonly end: number;
|
|
13
|
-
readonly parameters: InvokeParameter[] | null;
|
|
14
|
-
};
|
|
15
|
-
export declare function findInvokeOpenTag(text: string, fromIndex: number): InvokeOpenTagMatch | null;
|
|
16
|
-
export declare function findIncompleteInvokeOpenTag(text: string, fromIndex: number): InvokeOpenTagMatch | null;
|
|
17
|
-
export declare function scanInvokeBlock(text: string, openingTag: InvokeOpenTagMatch): InvokeBlockMatch | null;
|
|
18
|
-
export declare function getSafeInvokeTextLength(text: string): number;
|
|
19
|
-
//# sourceMappingURL=invoke-tag-scanner.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"invoke-tag-scanner.d.ts","sourceRoot":"","sources":["../../../../src/tool-call-middleware/protocols/anthropic-xml/invoke-tag-scanner.ts"],"names":[],"mappings":"AAyBA,MAAM,MAAM,kBAAkB,GAAG;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,UAAU,EAAE,eAAe,EAAE,GAAG,IAAI,CAAC;CAC9C,CAAC;AAwEF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,kBAAkB,GAAG,IAAI,CAS5F;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,kBAAkB,GAAG,IAAI,CA2BtG;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,GAAG,gBAAgB,GAAG,IAAI,CA4DrG;AAqED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAO5D"}
|