| 659 | } |
| 660 | |
| 661 | func (c *Client) CreateSession(ctx context.Context, config *SessionConfig) (*Session, error) { |
| 662 | if config == nil { |
| 663 | config = &SessionConfig{} |
| 664 | } |
| 665 | |
| 666 | if err := c.ensureConnected(ctx); err != nil { |
| 667 | return nil, err |
| 668 | } |
| 669 | |
| 670 | c.applyConfigDefaultsForMode(config) |
| 671 | |
| 672 | req := createSessionRequest{} |
| 673 | req.Model = config.Model |
| 674 | req.ClientName = config.ClientName |
| 675 | req.ReasoningEffort = config.ReasoningEffort |
| 676 | req.ReasoningSummary = config.ReasoningSummary |
| 677 | req.ContextTier = config.ContextTier |
| 678 | req.ConfigDir = config.ConfigDirectory |
| 679 | req.EnableConfigDiscovery = config.EnableConfigDiscovery |
| 680 | req.SkipEmbeddingRetrieval = config.SkipEmbeddingRetrieval |
| 681 | req.EmbeddingCacheStorage = config.EmbeddingCacheStorage |
| 682 | req.OrganizationCustomInstructions = config.OrganizationCustomInstructions |
| 683 | req.EnableOnDemandInstructionDiscovery = config.EnableOnDemandInstructionDiscovery |
| 684 | req.EnableFileHooks = config.EnableFileHooks |
| 685 | req.EnableHostGitOperations = config.EnableHostGitOperations |
| 686 | req.EnableSessionStore = config.EnableSessionStore |
| 687 | req.EnableSkills = config.EnableSkills |
| 688 | req.Tools = config.Tools |
| 689 | systemMessage := c.systemMessageForMode(config.SystemMessage) |
| 690 | wireSystemMessage, transformCallbacks := extractTransformCallbacks(systemMessage) |
| 691 | req.SystemMessage = wireSystemMessage |
| 692 | availableTools, excludedTools, precedence, ferr := c.resolveToolFilterOptions(config.AvailableTools, config.ExcludedTools) |
| 693 | if ferr != nil { |
| 694 | return nil, ferr |
| 695 | } |
| 696 | req.AvailableTools = availableTools |
| 697 | req.ExcludedTools = excludedTools |
| 698 | req.ToolFilterPrecedence = precedence |
| 699 | req.ExcludedBuiltInAgents = config.ExcludedBuiltInAgents |
| 700 | req.Provider = config.Provider |
| 701 | req.Capi = config.Capi |
| 702 | req.Providers = config.Providers |
| 703 | req.Models = config.Models |
| 704 | req.EnableSessionTelemetry = config.EnableSessionTelemetry |
| 705 | req.EnableCitations = config.EnableCitations |
| 706 | req.SessionLimits = config.SessionLimits |
| 707 | req.SkipCustomInstructions = config.SkipCustomInstructions |
| 708 | req.CustomAgentsLocalOnly = config.CustomAgentsLocalOnly |
| 709 | req.CoauthorEnabled = config.CoauthorEnabled |
| 710 | req.ManageScheduleEnabled = config.ManageScheduleEnabled |
| 711 | req.ModelCapabilities = config.ModelCapabilities |
| 712 | req.WorkingDirectory = config.WorkingDirectory |
| 713 | req.MCPServers = config.MCPServers |
| 714 | req.MCPOAuthTokenStorage = config.MCPOAuthTokenStorage |
| 715 | req.EnvValueMode = "direct" |
| 716 | req.CustomAgents = config.CustomAgents |
| 717 | req.DefaultAgent = config.DefaultAgent |
| 718 | req.Agent = config.Agent |