@animalabs/membrane 0.5.46 → 0.5.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/dist/membrane.d.ts.map +1 -1
  2. package/dist/membrane.js +104 -11
  3. package/dist/membrane.js.map +1 -1
  4. package/dist/providers/anthropic.d.ts.map +1 -1
  5. package/dist/providers/anthropic.js +11 -1
  6. package/dist/providers/anthropic.js.map +1 -1
  7. package/dist/providers/bedrock.d.ts.map +1 -1
  8. package/dist/providers/bedrock.js +23 -4
  9. package/dist/providers/bedrock.js.map +1 -1
  10. package/dist/types/yielding-stream.d.ts +10 -1
  11. package/dist/types/yielding-stream.d.ts.map +1 -1
  12. package/dist/types/yielding-stream.js.map +1 -1
  13. package/package.json +5 -1
  14. package/src/membrane.ts +127 -13
  15. package/src/providers/anthropic.ts +12 -0
  16. package/src/providers/bedrock.ts +21 -4
  17. package/src/types/yielding-stream.ts +10 -1
  18. package/dist/context/index.d.ts +0 -12
  19. package/dist/context/index.js +0 -11
  20. package/dist/context/index.js.map +0 -1
  21. package/dist/context/process.d.ts +0 -43
  22. package/dist/context/process.js +0 -381
  23. package/dist/context/process.js.map +0 -1
  24. package/dist/context/types.d.ts +0 -164
  25. package/dist/context/types.js +0 -61
  26. package/dist/context/types.js.map +0 -1
  27. package/dist/formatters/anthropic-xml.d.ts +0 -63
  28. package/dist/formatters/anthropic-xml.js +0 -417
  29. package/dist/formatters/anthropic-xml.js.map +0 -1
  30. package/dist/formatters/completions.d.ts +0 -68
  31. package/dist/formatters/completions.js +0 -261
  32. package/dist/formatters/completions.js.map +0 -1
  33. package/dist/formatters/index.d.ts +0 -8
  34. package/dist/formatters/index.js +0 -7
  35. package/dist/formatters/index.js.map +0 -1
  36. package/dist/formatters/native.d.ts +0 -35
  37. package/dist/formatters/native.js +0 -336
  38. package/dist/formatters/native.js.map +0 -1
  39. package/dist/formatters/types.d.ts +0 -167
  40. package/dist/formatters/types.js +0 -7
  41. package/dist/formatters/types.js.map +0 -1
  42. package/dist/index.d.ts +0 -13
  43. package/dist/index.js +0 -20
  44. package/dist/index.js.map +0 -1
  45. package/dist/membrane.d.ts +0 -146
  46. package/dist/providers/anthropic.d.ts +0 -36
  47. package/dist/providers/bedrock.d.ts +0 -43
  48. package/dist/providers/gemini.d.ts +0 -68
  49. package/dist/providers/gemini.js +0 -538
  50. package/dist/providers/gemini.js.map +0 -1
  51. package/dist/providers/index.d.ts +0 -13
  52. package/dist/providers/index.js +0 -13
  53. package/dist/providers/index.js.map +0 -1
  54. package/dist/providers/mock.d.ts +0 -90
  55. package/dist/providers/mock.d.ts.map +0 -1
  56. package/dist/providers/mock.js +0 -210
  57. package/dist/providers/mock.js.map +0 -1
  58. package/dist/providers/openai-compatible.d.ts +0 -82
  59. package/dist/providers/openai-compatible.js +0 -480
  60. package/dist/providers/openai-compatible.js.map +0 -1
  61. package/dist/providers/openai-completions.d.ts +0 -89
  62. package/dist/providers/openai-completions.js +0 -347
  63. package/dist/providers/openai-completions.js.map +0 -1
  64. package/dist/providers/openai-responses.d.ts +0 -77
  65. package/dist/providers/openai-responses.js +0 -333
  66. package/dist/providers/openai-responses.js.map +0 -1
  67. package/dist/providers/openai.d.ts +0 -77
  68. package/dist/providers/openai.js +0 -533
  69. package/dist/providers/openai.js.map +0 -1
  70. package/dist/providers/openrouter.d.ts +0 -82
  71. package/dist/providers/openrouter.js +0 -556
  72. package/dist/providers/openrouter.js.map +0 -1
  73. package/dist/providers/utils.d.ts +0 -44
  74. package/dist/providers/utils.d.ts.map +0 -1
  75. package/dist/providers/utils.js +0 -100
  76. package/dist/providers/utils.js.map +0 -1
  77. package/dist/registry/default-pricing.d.ts +0 -3
  78. package/dist/registry/default-pricing.d.ts.map +0 -1
  79. package/dist/registry/default-pricing.js +0 -75
  80. package/dist/registry/default-pricing.js.map +0 -1
  81. package/dist/transforms/chat.d.ts +0 -52
  82. package/dist/transforms/chat.js +0 -136
  83. package/dist/transforms/chat.js.map +0 -1
  84. package/dist/transforms/index.d.ts +0 -5
  85. package/dist/transforms/index.js +0 -7
  86. package/dist/transforms/index.js.map +0 -1
  87. package/dist/types/config.d.ts +0 -110
  88. package/dist/types/config.js +0 -21
  89. package/dist/types/config.js.map +0 -1
  90. package/dist/types/content.d.ts +0 -87
  91. package/dist/types/content.d.ts.map +0 -1
  92. package/dist/types/content.js +0 -40
  93. package/dist/types/content.js.map +0 -1
  94. package/dist/types/errors.d.ts +0 -50
  95. package/dist/types/errors.d.ts.map +0 -1
  96. package/dist/types/errors.js +0 -253
  97. package/dist/types/errors.js.map +0 -1
  98. package/dist/types/index.d.ts +0 -20
  99. package/dist/types/index.js +0 -10
  100. package/dist/types/index.js.map +0 -1
  101. package/dist/types/message.d.ts +0 -52
  102. package/dist/types/message.d.ts.map +0 -1
  103. package/dist/types/message.js +0 -38
  104. package/dist/types/message.js.map +0 -1
  105. package/dist/types/provider.d.ts +0 -169
  106. package/dist/types/provider.d.ts.map +0 -1
  107. package/dist/types/provider.js +0 -5
  108. package/dist/types/provider.js.map +0 -1
  109. package/dist/types/request.d.ts +0 -116
  110. package/dist/types/request.d.ts.map +0 -1
  111. package/dist/types/request.js +0 -5
  112. package/dist/types/request.js.map +0 -1
  113. package/dist/types/response.d.ts +0 -131
  114. package/dist/types/response.d.ts.map +0 -1
  115. package/dist/types/response.js +0 -7
  116. package/dist/types/response.js.map +0 -1
  117. package/dist/types/streaming.d.ts +0 -194
  118. package/dist/types/streaming.js +0 -5
  119. package/dist/types/streaming.js.map +0 -1
  120. package/dist/types/tools.d.ts +0 -71
  121. package/dist/types/tools.d.ts.map +0 -1
  122. package/dist/types/tools.js +0 -5
  123. package/dist/types/tools.js.map +0 -1
  124. package/dist/utils/cost.d.ts +0 -10
  125. package/dist/utils/cost.d.ts.map +0 -1
  126. package/dist/utils/cost.js +0 -19
  127. package/dist/utils/cost.js.map +0 -1
  128. package/dist/utils/index.d.ts +0 -7
  129. package/dist/utils/index.js +0 -6
  130. package/dist/utils/index.js.map +0 -1
  131. package/dist/utils/stream-parser.d.ts +0 -84
  132. package/dist/utils/stream-parser.js +0 -418
  133. package/dist/utils/stream-parser.js.map +0 -1
  134. package/dist/utils/tool-parser.d.ts +0 -134
  135. package/dist/utils/tool-parser.js +0 -600
  136. package/dist/utils/tool-parser.js.map +0 -1
  137. package/dist/yielding-stream.d.ts +0 -60
  138. package/dist/yielding-stream.js +0 -206
  139. package/dist/yielding-stream.js.map +0 -1
@@ -1,134 +0,0 @@
1
- /**
2
- * Tool parsing utilities for XML-based tool calls
3
- *
4
- * Supports both plain and antml:-prefixed formats:
5
- * <function_calls> or <function_calls>
6
- * <invoke name="..."> or <invoke name="...">
7
- * <parameter name="..."> or <parameter name="...">
8
- *
9
- * Also supports self-closing invoke tags:
10
- * <invoke name="tool"/> or <invoke name="tool"/>
11
- */
12
- import type { ToolCall, ToolResult, ParsedToolCalls, ContentBlock } from '../types/index.js';
13
- /**
14
- * Parse tool calls from text containing XML function_calls blocks
15
- *
16
- * Uses "last-unexecuted-block" logic: finds the last function_calls block
17
- * that doesn't have function_results immediately following it.
18
- */
19
- export declare function parseToolCalls(text: string): ParsedToolCalls | null;
20
- /**
21
- * Check if text contains an unclosed function_calls block
22
- * Used for false-positive stop sequence detection
23
- * Supports both plain and antml: prefixed tags
24
- */
25
- export declare function hasUnclosedToolBlock(text: string): boolean;
26
- /**
27
- * Check if text ends with a partial/unclosed tool block
28
- * Supports both plain and antml: prefixed tags
29
- */
30
- export declare function endsWithPartialToolBlock(text: string): boolean;
31
- /**
32
- * Format tool results as XML for injection.
33
- * Handles both string content and structured content blocks (with images).
34
- */
35
- export declare function formatToolResults(results: ToolResult[]): string;
36
- /**
37
- * Format a single tool result
38
- */
39
- export declare function formatToolResult(result: ToolResult): string;
40
- export interface ToolDefinitionForPrompt {
41
- name: string;
42
- description: string;
43
- parameters: Record<string, {
44
- type: string;
45
- description?: string;
46
- required?: boolean;
47
- enum?: string[];
48
- }>;
49
- }
50
- /**
51
- * Format tool definitions as XML for system prompt
52
- */
53
- export declare function formatToolDefinitions(tools: ToolDefinitionForPrompt[]): string;
54
- /**
55
- * Parse accumulated assistant text into structured ContentBlock[].
56
- * Extracts thinking blocks, tool calls, tool results, and plain text.
57
- *
58
- * @param text - The accumulated assistant output text
59
- * @param options - Optional parsing context
60
- * @param options.startInsideBlock - Block type we're starting inside (from prefill context)
61
- * @returns Array of ContentBlock in order of appearance
62
- */
63
- export declare function parseAccumulatedIntoBlocks(text: string, options?: {
64
- startInsideBlock?: 'thinking' | 'tool_call' | 'tool_result';
65
- }): {
66
- blocks: ContentBlock[];
67
- toolCalls: ToolCall[];
68
- toolResults: ToolResult[];
69
- };
70
- import type { ToolDefinition } from '../types/index.js';
71
- /**
72
- * Get tool instructions string for manual placement.
73
- * Use this when you want to control where tool instructions appear
74
- * (e.g., injected into conversation rather than system prompt).
75
- *
76
- * @param tools - Tool definitions
77
- * @returns Complete instruction string with definitions and usage example
78
- */
79
- export declare function getToolInstructions(tools: ToolDefinition[]): string;
80
- /**
81
- * Provider image block format (Anthropic-style)
82
- */
83
- export interface ProviderImageBlock {
84
- type: 'image';
85
- source: {
86
- type: 'base64';
87
- media_type: string;
88
- data: string;
89
- };
90
- }
91
- /**
92
- * Check if any tool result contains image content
93
- */
94
- export declare function hasImageInToolResults(results: ToolResult[]): boolean;
95
- /**
96
- * Result of separating tool result content for split-turn injection.
97
- *
98
- * When tool results contain images in prefill mode, we need to:
99
- * 1. Put text content in the assistant turn (as XML)
100
- * 2. Extract images into a separate user turn
101
- * 3. Continue assistant turn with closing XML
102
- */
103
- export interface SplitTurnContent {
104
- /** XML up to and including text content, ending mid-result if images present */
105
- beforeImageXml: string;
106
- /** Images extracted from results (in provider format) */
107
- images: ProviderImageBlock[];
108
- /** Closing XML after images (closing result tags, function_results) */
109
- afterImageXml: string;
110
- /** Whether any images were found */
111
- hasImages: boolean;
112
- }
113
- /**
114
- * Format tool results for split-turn injection when images are present.
115
- *
116
- * This separates the XML into parts that go in the assistant turn (text)
117
- * and the user turn (images), with continuation XML for the next assistant turn.
118
- *
119
- * Structure when images present:
120
- * ```
121
- * Assistant: <function_results>
122
- * <result tool_use_id="...">
123
- * text content here
124
- * [END - mid XML]
125
- *
126
- * User: [image blocks]
127
- *
128
- * Assistant (prefill): </result>
129
- * </function_results>
130
- * ```
131
- */
132
- export declare function formatToolResultsForSplitTurn(results: ToolResult[]): SplitTurnContent;
133
- export declare function unescapeXml(text: string): string;
134
- //# sourceMappingURL=tool-parser.d.ts.map