toolnexus 0.28.0 → 0.29.0

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/src/wire.ts CHANGED
@@ -72,7 +72,7 @@ export function toOpenAIWire(messages: any[], opts: WireOptions = {}): any[] {
72
72
  const parts = partsOf(m)
73
73
  const { parts: _drop, ...rest } = m ?? {}
74
74
  if (!parts) {
75
- out.push(m)
75
+ out.push(m && "parts" in m ? rest : m)
76
76
  continue
77
77
  }
78
78
  const { texts, others } = split(parts)
@@ -109,7 +109,12 @@ export function toAnthropicWire(messages: any[], opts: WireOptions = {}): any[]
109
109
  const content = m.content.map((block: any) => {
110
110
  if (block?.type !== "tool_result") return block
111
111
  const parts = partsOf(block)
112
- if (!parts) return block
112
+ if (!parts) {
113
+ if (!("parts" in block)) return block
114
+ touched = true
115
+ const { parts: _drop, ...rest } = block
116
+ return rest
117
+ }
113
118
  touched = true
114
119
  const { parts: _drop, ...rest } = block
115
120
  return {
@@ -124,6 +129,18 @@ export function toAnthropicWire(messages: any[], opts: WireOptions = {}): any[]
124
129
  })
125
130
  }
126
131
 
132
+ /**
133
+ * The parts of a tool result that reach the model (SPEC §7G.6). A media tool result
134
+ * (`metadata.source === "media"`) contributes only its **image** parts; its video (`file`) and
135
+ * `audio` parts stay in `toolCalls[].parts` / `RunResult.files` and the model sees just the
136
+ * output line. Every other tool result keeps all its parts.
137
+ */
138
+ export function modelParts(result: { parts?: ContentPart[]; metadata?: Record<string, unknown> }): ContentPart[] {
139
+ const parts = result.parts ?? []
140
+ if (result.metadata?.source !== "media") return parts
141
+ return parts.filter((p) => p.type === "image")
142
+ }
143
+
127
144
  /** Validate every attached part before assembly, so `maxPartBytes` cannot be bypassed. */
128
145
  export function checkPromptParts(prompt: unknown, opts: WireOptions): void {
129
146
  if (!Array.isArray(prompt)) return