-
Notifications
You must be signed in to change notification settings - Fork 259
fix: remove dead code after tools throw and fix transport leak on connect error #342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -261,47 +261,15 @@ export class StripeLanguageModel implements LanguageModelV2 { | |
| // Convert AI SDK prompt to OpenAI-compatible format | ||
| const messages = convertToOpenAIMessages(options.prompt); | ||
|
|
||
| // Check if tools are provided and throw error (tool calling not supported by Stripe API) | ||
| // Tool calling is not supported by the Stripe AI SDK Provider. | ||
| if (options.tools && options.tools.length > 0) { | ||
| throw new Error( | ||
| 'Tool calling is not supported by the Stripe AI SDK Provider. ' + | ||
| 'The llm.stripe.com API does not currently support function calling or tool use. ' + | ||
| 'Please remove the tools parameter from your request.' | ||
| 'The llm.stripe.com API does not currently support function calling or tool use. ' + | ||
| 'Please remove the tools parameter from your request.' | ||
| ); | ||
| } | ||
|
Comment on lines
+264
to
279
|
||
|
|
||
| // Prepare tools if provided | ||
| const tools = | ||
| options.tools && options.tools.length > 0 | ||
| ? options.tools.map((tool) => { | ||
| if (tool.type === 'function') { | ||
| return { | ||
| type: 'function', | ||
| function: { | ||
| name: tool.name, | ||
| description: tool.description, | ||
| parameters: tool.inputSchema, | ||
| }, | ||
| }; | ||
| } | ||
| // Provider-defined tools | ||
| return tool; | ||
| }) | ||
| : undefined; | ||
|
|
||
| // Map tool choice | ||
| let toolChoice: string | {type: string; function?: {name: string}} | undefined; | ||
| if (options.toolChoice) { | ||
| if (options.toolChoice.type === 'tool') { | ||
| toolChoice = { | ||
| type: 'function', | ||
| function: {name: options.toolChoice.toolName}, | ||
| }; | ||
| } else { | ||
| toolChoice = options.toolChoice.type; // 'auto', 'none', 'required' | ||
| } | ||
| } | ||
|
|
||
| // Build request body, only including defined values | ||
| const body: Record<string, any> = { | ||
| model: this.modelId, | ||
|
|
@@ -310,18 +278,18 @@ export class StripeLanguageModel implements LanguageModelV2 { | |
|
|
||
| // Add optional parameters only if they're defined | ||
| if (options.temperature !== undefined) body.temperature = options.temperature; | ||
|
|
||
| // Handle max_tokens with model-specific defaults for Anthropic | ||
| const maxTokens = options.maxOutputTokens ?? this.getDefaultMaxTokens(this.modelId); | ||
| if (maxTokens !== undefined) body.max_tokens = maxTokens; | ||
|
|
||
| if (options.topP !== undefined) body.top_p = options.topP; | ||
| if (options.frequencyPenalty !== undefined) body.frequency_penalty = options.frequencyPenalty; | ||
| if (options.presencePenalty !== undefined) body.presence_penalty = options.presencePenalty; | ||
| if (options.frequencyPenalty !== undefined) | ||
| body.frequency_penalty = options.frequencyPenalty; | ||
| if (options.presencePenalty !== undefined) | ||
| body.presence_penalty = options.presencePenalty; | ||
| if (options.stopSequences !== undefined) body.stop = options.stopSequences; | ||
| if (options.seed !== undefined) body.seed = options.seed; | ||
| if (tools !== undefined) body.tools = tools; | ||
| if (toolChoice !== undefined) body.tool_choice = toolChoice; | ||
|
|
||
| return {args: body, warnings}; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,7 +113,13 @@ export class StripeMcpClient { | |
| const result = await this.client.listTools(); | ||
| this.tools = result.tools as McpTool[]; | ||
| } catch (error) { | ||
| // Clean up on failure | ||
| // Close the active connection before clearing references to avoid leaking | ||
| // the underlying transport if connect() succeeded but listTools() failed. | ||
| try { | ||
| if (this.client) await this.client.close(); | ||
| } catch { | ||
| // Ignore close errors during cleanup | ||
| } | ||
| this.client = null; | ||
| this.transport = null; | ||
|
Comment on lines
+116
to
124
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
options.toolChoiceis no longer forwarded (and is silently ignored) whenoptions.toolsis empty. Given the explicit “tool calling not supported” stance, consider explicitly throwing whentoolChoiceis provided as well (and adjusting the message), so callers don’t think the setting is taking effect.