- Add GPT-5 model definitions (gpt-5, gpt-5-mini, gpt-5-nano, gpt-5-chat-latest) - Implement GPT-5 Responses API support with intelligent fallback to Chat Completions - Add GPT-5 specific parameter handling (max_completion_tokens, temperature=1) - Support custom tools and freeform function calling capabilities - Add reasoning effort and verbosity control parameters - Implement GPT-5 connection testing service - Add model capability detection and automatic parameter transformation - Support both official OpenAI and third-party GPT-5 providers - Add todo list and sticker request UI components - Improve notebook support with better type definitions - Enhance debug logging and error handling for GPT-5 - Update model selector with GPT-5 compatibility checks This commit provides full GPT-5 support while maintaining backward compatibility with existing models.
56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import fs from 'fs/promises'
|
|
import { logError } from './log'
|
|
import { Tool } from '../Tool'
|
|
|
|
/**
|
|
* Load messages from a log file
|
|
* @param logPath Path to the log file
|
|
* @param tools Available tools for deserializing tool usage
|
|
* @returns Array of deserialized messages
|
|
*/
|
|
export async function loadMessagesFromLog(
|
|
logPath: string,
|
|
tools: Tool[],
|
|
): Promise<any[]> {
|
|
try {
|
|
const content = await fs.readFile(logPath, 'utf-8')
|
|
const messages = JSON.parse(content)
|
|
return deserializeMessages(messages, tools)
|
|
} catch (error) {
|
|
logError(`Failed to load messages from ${logPath}: ${error}`)
|
|
throw new Error(`Failed to load messages from log: ${error}`)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Deserialize messages from a saved format, reconnecting any tool references
|
|
* @param messages The serialized message array
|
|
* @param tools Available tools to reconnect
|
|
* @returns Deserialized messages with reconnected tool references
|
|
*/
|
|
export function deserializeMessages(messages: any[], tools: Tool[]): any[] {
|
|
// Map of tool names to actual tool instances for reconnection
|
|
const toolMap = new Map(tools.map(tool => [tool.name, tool]))
|
|
|
|
return messages.map(message => {
|
|
// Deep clone the message to avoid mutation issues
|
|
const clonedMessage = JSON.parse(JSON.stringify(message))
|
|
|
|
// If the message has tool calls, reconnect them to actual tool instances
|
|
if (clonedMessage.toolCalls) {
|
|
clonedMessage.toolCalls = clonedMessage.toolCalls.map((toolCall: any) => {
|
|
// Reconnect tool reference if it exists
|
|
if (toolCall.tool && typeof toolCall.tool === 'string') {
|
|
const actualTool = toolMap.get(toolCall.tool)
|
|
if (actualTool) {
|
|
toolCall.tool = actualTool
|
|
}
|
|
}
|
|
return toolCall
|
|
})
|
|
}
|
|
|
|
return clonedMessage
|
|
})
|
|
}
|