Commit graph

190 commits

Author SHA1 Message Date
Max
d67807ca2e feat: Extend SchemaProperty and Parameter structures with new fields
- Add Items field to SchemaProperty for better JSON Schema representation.
- Introduce Strict field to Parameter for enhanced parameter validation options.
- Improve data structure flexibility for future tool enhancements.
2025-03-22 18:29:27 +08:00
Max
211e523759 Implement built-in assistant deletion and loading improvements
- Retrieve existing built-in assistants before deletion to ensure accurate removal.
- Update LoadBuiltIn function to track and delete assistants that are no longer present.
- Enhance error handling during the deletion process for better reliability.
2025-03-21 19:57:46 +08:00
Max
6edaa712df Update error message for missing assistant data in GetAssistant method
- Change error message from "assistant not found" to "the assistant is empty" for improved clarity in the Xun store.
2025-03-21 18:36:59 +08:00
Max
f820e376ab Refactor assistant save and delete methods for cache management
- Rename variable for clarity in handleAssistantSave method.
- Implement cache removal and reloading for assistants after save and delete operations to ensure data consistency.
- Add GetCache method to retrieve the loaded cache for better cache management.
2025-03-18 15:36:44 +08:00
Max
586ad9866c Enhance assistant loading and ID generation
- Update loadMap function to handle prompts as both string and array types, improving flexibility in data loading.
- Refactor assistant ID generation in SaveAssistant method to use a dedicated GenerateAssistantID function, ensuring unique IDs are created with error handling.
- Add GenerateAssistantID method to create a random 6-digit ID while checking for uniqueness in the database.
2025-03-17 18:28:02 +08:00
Max
97a469bc03 Add type filtering for assistants in API and data loading
- Introduce 'Type' field in AssistantFilter for filtering assistant lists
- Update handleAssistantList and handleAssistantDetail methods to set 'Type' to 'assistant'
- Modify LoadPath function to ensure 'type' is set if not already present
- Adjust GetAssistants and GetAssistantTags methods to apply type filtering in queries
2025-03-15 17:57:35 +08:00
Max
d3734cf1d0 Add support for passing arguments in assistant method calls
- Extend Context struct to include Args field for storing call arguments
- Modify objectCall.run to capture and store arguments in chat context
- Update context mapping to include arguments when present
2025-03-12 17:24:36 +08:00
Max
b89a39b192 Refactor error handling and logging in chat streaming and API methods
- Update error handling in handleChat to return and log errors
- Modify streamChat to remove explicit error logging and improve retry mechanism
- Adjust HookRetry method to return nil for more flexible error handling
- Improve error handling in retryMessages method with better index tracking
- Remove redundant error logging in requestMessages method
2025-03-07 16:57:58 +08:00
Max
47da72bbee Handle null return for non-existent shared space keys
- Modify jsGet method to return null when key is not found
- Add string-based error checking to differentiate between missing keys and other errors
- Improve shared space key retrieval error handling in JavaScript bridge
2025-03-04 17:31:07 +08:00
Max
dafd6b029b Enhance retry mechanism with flexible action handling
- Modify HookRetry to support returning NextAction
- Update streamChat to handle different retry response types
- Add type switching for retry hook return values
- Implement execution of NextAction in retry flow
- Improve error handling and response processing during retry
2025-03-04 15:27:40 +08:00
Max
f469568d85 Improve request context handling in chat streaming
- Use request context for client connection tracking
- Replace CloseNotify with context cancellation
- Enhance streaming method to handle request context termination
2025-03-04 12:03:19 +08:00
Max
709c7ec738 Add optional options handling in objectCall.run method
- Modify options unmarshaling to handle undefined JavaScript options
- Add null check to prevent unmarshaling errors when no options are provided
- Improve robustness of method call argument processing
2025-03-03 18:13:10 +08:00
Max
48d65c0e39 Handle empty prompt in chat streaming with error callback
- Add error handling for empty prompts in streamChat method
- Ensure proper error message generation and callback invocation
- Improve error propagation in chat streaming scenarios
2025-03-03 15:26:24 +08:00
Max
c74d32390c Add retry mechanism for chat streaming with error handling
- Implement HookRetry method to handle retry scenarios in chat streaming
- Add retry tracking with RetryTimes and Retry flag in context
- Create retryMessages method to modify messages for retry attempts
- Enhance error handling and logging for retry scenarios
- Add color-coded error output for retry failures
2025-03-03 14:49:31 +08:00
Max
392676f2cb Add silent mode support for chat history and filtering
- Implement silent flag in chat and history storage
- Add filter options to retrieve chats and messages with silent mode
- Update store interfaces to support silent message filtering
- Enhance GetChats, GetHistory, and related methods to handle silent messages
- Add comprehensive test cases for silent mode functionality
2025-03-01 16:08:56 +08:00
Max
dcc126ef95 Implement retry mechanism for assistant method calls
- Add comprehensive retry handling in objectCall.run method
- Support configurable retry times, delay, and custom retry prompts
- Enhance error handling and input processing during retry attempts
- Modify method signatures to return interface{} for more flexible result handling
- Implement retry event hook for custom retry logic in JavaScript
2025-03-01 12:20:02 +08:00
Max
86dd04728d Enhance input handling and message processing in assistant methods
- Modify Execute and withHistory methods to support multiple input types
- Add flexible type conversion for input messages using jsoniter
- Implement robust handling of string, map, and slice input formats
- Update method signatures to accept interface{} for more dynamic input processing
- Improve error handling during input marshaling and unmarshaling
2025-02-28 20:13:59 +08:00
Max
ca6d075a22 Add shared space methods to JavaScript bridge
- Implement Set, Get, Del, and Clear methods for shared space interactions
- Add error handling and validation for shared space method calls
- Enhance context management with Release method to clear shared space
- Update context initialization to create a default memory shared space
2025-02-27 16:32:25 +08:00
Max
ae599d9b83 Improve JavaScript argument handling in jsCall method
- Add null check for jsArgs to prevent potential nil pointer dereferences
- Refactor argument parsing logic to handle optional arguments more robustly
- Ensure safe conversion of JavaScript arguments to Go slice
- Enhance error handling for argument type conversion
2025-02-27 15:15:27 +08:00
Max
6b15a1763e Enhance message processing in assistant chat method
- Implement comprehensive message formatting function
- Add filtering for duplicate messages
- Reorder messages to ensure proper system and user message placement
- Merge consecutive assistant messages
- Improve message preprocessing for API requests
2025-02-26 08:27:16 +08:00
Max
f1e6c2c62f Add result handling in assistant streaming and hook responses
- Introduce Result field in ResHookDone struct to support additional data
- Update NextAction.Execute method to pass optional callback arguments
- Modify streamChat method to propagate result data to output messages
- Add Result field to Message struct for flexible result storage
2025-02-25 17:32:58 +08:00
Max
5fe43f8103 Enhance JavaScript bridge argument handling in assistant method calls
- Add support for passing additional arguments to callback functions
- Implement flexible argument parsing for JavaScript method calls
- Handle both array and single argument scenarios
- Update method signature to accommodate optional arguments
2025-02-25 16:11:53 +08:00
Max
5475e0ab39 Add Assets method to assistant for retrieving and processing asset files
- Implement Assets method in Assistant struct to read asset files
- Add jsAssets function to JavaScript bridge for accessing assets
- Support optional data replacement in asset file content
- Enable dynamic asset retrieval with optional template data processing
2025-02-25 11:27:04 +08:00
Max
358f327dee Improve native tool calls handling in assistant streaming
- Refactor tool calls processing to handle multiple tool calls more robustly
- Add new message flags (IsBeginTool, IsEndTool) to track tool call stages
- Modify streaming logic to correctly wrap and manage tool call messages
- Ensure only the first tool call is fully processed and displayed
2025-02-24 19:29:57 +08:00
Max
101927e343 Add thread-safe write method with mutex synchronization
- Introduce sync.Mutex to protect concurrent writes to response writer
- Add locking mechanism in Write method to prevent race conditions
- Ensure safe and synchronized message writing in multi-threaded contexts
2025-02-24 17:24:34 +08:00
Max
3c51f16d95 Refactor assistant script loading and improve error diagnostics
- Comment out assistant script loading in script package
- Enhance global variable error message with detailed type information
- Prepare for moving assistant script loading to a dedicated package
2025-02-24 14:33:04 +08:00
Max
9c9f137a8a Improve error handling and logging in assistant methods
- Add nil checks for callbacks in message and object methods
- Enhance error logging in plan subscription with more descriptive messages
- Improve write method error handling with additional context logging
- Add safeguards against potential nil function calls
2025-02-24 10:44:15 +08:00
Max
df99b9a228 Add Plan function to JavaScript bridge in InitObject method
- Introduce new jsPlan function to script context initialization
- Extend InitObject method with Plan method for script interactions
- Enhance JavaScript bridge capabilities in assistant script contexts
2025-02-22 18:37:35 +08:00
Max
05af5d1514 Rename Context to GinContext in GlobalVariables struct
- Update GlobalVariables struct to use more descriptive GinContext field
- Modify all references to Context to use GinContext in assistant methods
- Improve clarity of Gin context usage in JavaScript bridge functions
2025-02-22 14:07:11 +08:00
Max
f3e009c3a7 Refactor assistant initialization and script context methods
- Rename HookInit to HookCreate for clarity
- Modify call method to simplify script context initialization
- Remove explicit SendMessage and Run function additions
- Add InitObject method to handle script context setup
- Streamline assistant script method invocation
2025-02-22 13:53:56 +08:00
Max
9a9d1e38a8 Update run method to support SendMessage in nested script contexts
- Modify run method signature to include contents parameter
- Add SendMessage function to nested script context during execution
- Ensure consistent message sending capabilities across script levels
2025-02-19 09:39:16 +08:00
Max
979acb27a8 Add callback support for assistant chat processing
- Introduce optional callback mechanism for chat messages
- Modify Execute and streamChat methods to support callback functions
- Add support for process and script method callbacks
- Update message handling to trigger callbacks during chat streaming
- Enhance flexibility of assistant chat interactions with dynamic callbacks
2025-02-18 18:13:42 +08:00
Max
13c4e65a95 Add retry and silent modes to assistant chat processing
- Introduce retry and silent mode flags in context and message structures
- Modify API and hooks to support new context modes
- Update message handling to propagate retry and silent flags
- Replace debug print statements with structured logging
- Enhance tool call and message processing with new context options
2025-02-18 11:20:20 +08:00
Max
2eaee671da Add JSON repair utility for robust parsing
- Integrate jsonrepair library to improve JSON parsing resilience
- Replace manual JSON repair attempts with a more comprehensive repair method
- Update go.mod and go.sum to include jsonrepair dependency
- Simplify ParseJSON function with a single repair approach
2025-02-11 17:00:22 +08:00
Max
8bc7f6ddb1 Refactor tool call prompts and message handling
- Update tool call prompts with more detailed schema and usage guidelines
- Add dynamic tool call examples based on available tools
- Modify message name generation to use assistant ID with underscores
- Improve system message formatting for tool calls
- Simplify tool call prompt generation logic
2025-02-11 16:31:09 +08:00
Max
c38bce89dc Enhance tool call processing and message handling
- Refactor tool call prompts with more detailed guidelines
- Improve message name handling for system and user messages
- Add robust JSON parsing utility with error recovery
- Update debug logging for request messages and tool calls
- Modify tool call extraction in HookDone method for better reliability
2025-02-10 20:40:59 +08:00
Max
617893a579 Improve tool call parsing and formatting
- Refine tool call text extraction in HookDone method
- Add URL decoding for JSON-encoded tool call arguments
- Enhance error handling for tool call parsing
- Modify tool call tag handling in streaming chat
2025-02-10 11:13:59 +08:00
Max
dc6967805e Fix assistant context switching and ID handling
- Prevent switching to an empty assistant ID
- Update context assistant ID during execution
- Ensure proper assistant context management in chat flow
2025-02-09 18:25:09 +08:00
Max
4ba27390d8 Add assistant details to chat API responses
- Enhance chat API endpoints to include assistant information
- Add support for retrieving and displaying assistant details in chat responses
- Update database schema to store assistant_id in chat table
- Modify GetChats, GetChat, and SaveHistory methods to handle assistant metadata
- Improve test coverage for assistant-related chat functionality
2025-02-09 16:54:20 +08:00
Max
5be65d91cd Remove debug print statement in OpenAI message parsing
- Remove unnecessary debug print of arguments and finish reason
- Maintain clean and concise message processing logic
- Align with previous refactoring efforts to simplify code
2025-02-09 10:08:51 +08:00
Max
38ee806cff Refactor OpenAI message parsing for improved streaming support
- Completely restructure NewOpenAI method to handle different message types more robustly
- Add support for new ChatCompletionChunk type to parse streaming responses
- Improve error handling and message type detection
- Simplify message processing logic with more explicit type checking
- Remove commented-out legacy code and improve overall readability
2025-02-09 09:46:41 +08:00
Max
142b07b0ce Enhance tool call handling and message processing
- Add support for native tool call streaming with XML-like tags
- Implement stringHash for message name anonymization
- Add debug environment variable for printing request messages
- Remove unused function and arguments fields in message contents
- Modify message type handling for tool calls in streaming chat
2025-02-08 18:09:26 +08:00
Max
a7a05fbec8 Add Azure OpenAI support and improve message parsing
- Implement Azure OpenAI authentication with `azure` flag in OpenAI struct
- Update HTTP request headers to support Azure API key authentication
- Enhance message parsing to handle additional edge cases in OpenAI responses
- Add debug logging for OpenAI messages when debug environment is set
- Improve error and usage detection in stream message processing
2025-02-08 11:18:06 +08:00
Max
b19c5d63ff Enhance message processing and user identification
- Add user ID to input name when not explicitly set
- Update stream chat to mark final message as "think" type
- Modify history retrieval to add system prompts after fetching chat history
- Remove debug print statement in message data mapping
2025-02-07 10:30:12 +08:00
Max
dabba1a744 Refactor chat history and message processing
- Added `Hidden` flag to `Message` struct for controlling message visibility
- Modified `saveChatHistory` to conditionally save messages based on hidden status
- Simplified stream chat processing by removing debug print statements
- Restructured message output and next action handling in stream chat
- Commented out unused process action execution method
2025-02-06 16:39:31 +08:00
Max
d69370551a Refactor streaming chat and message processing
- Updated NextAction execution to send loading message and create new contents
- Disabled stream hook temporarily to simplify message handling
- Modified HookDone to filter and parse tool call messages
- Removed debug print statements and simplified message generation
- Improved message content processing during stream chat
2025-02-06 14:21:29 +08:00
Max
96f4b5e55a Add support for reasoning content and thinking state in OpenAI streaming
- Implemented handling of reasoning_content in OpenAI message parsing
- Added support for tracking thinking state with `<think>` tags
- Updated message generation to handle delta messages and thinking states
- Modified OpenAI API to support flexible base URL configuration
- Enhanced token scanning and message processing for reasoning content
2025-02-05 16:55:09 +08:00
Max
5a38cf77c1 Improve message ID tracking in streaming chat processing
- Updated ScanTokens method to preserve and reuse existing message IDs
- Modified streaming chat to track and pass current message ID during token scanning
- Ensured consistent message ID generation when not explicitly provided
2025-02-04 19:22:45 +08:00
Max
75d55ae13b Add unique ID tracking for message contents and streaming
- Introduced UUID generation for message contents during token scanning
- Updated message and contents methods to support optional ID parameter
- Modified streaming chat processing to include message ID tracking
- Enhanced message parsing and appending with ID preservation
2025-02-04 17:17:24 +08:00
Max
991c884d78 Simplify token scanning and streaming logic in chat processing
- Removed unnecessary breakpoint and token tracking variables
- Streamlined token scanning and message processing in assistant API
- Simplified text handling and token parsing in contents scanning
- Reduced complexity of stream chat message generation
2025-02-03 19:24:52 +08:00