Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions coderd/apidoc/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions coderd/apidoc/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions coderd/database/db2sdk/db2sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -1713,6 +1713,10 @@ func Chat(c database.Chat, diffStatus *database.ChatDiffStatus, files []database
if c.LastTurnSummary.Valid {
chat.LastTurnSummary = &c.LastTurnSummary.String
}
if c.LastReasoningEffort.Valid {
lastReasoningEffort := string(c.LastReasoningEffort.ChatReasoningEffort)
chat.LastReasoningEffort = &lastReasoningEffort
}
if c.PlanMode.Valid {
chat.PlanMode = codersdk.ChatPlanMode(c.PlanMode.ChatPlanMode)
}
Expand Down
49 changes: 25 additions & 24 deletions coderd/database/db2sdk/db2sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -696,30 +696,31 @@ func TestChat_AllFieldsPopulated(t *testing.T) {
require.NoError(t, err)

input := database.Chat{
ID: uuid.New(),
OwnerID: uuid.New(),
OwnerUsername: "owner-username",
OwnerName: "Owner Name",
OrganizationID: uuid.New(),
WorkspaceID: uuid.NullUUID{UUID: uuid.New(), Valid: true},
BuildID: uuid.NullUUID{UUID: uuid.New(), Valid: true},
AgentID: uuid.NullUUID{UUID: uuid.New(), Valid: true},
ParentChatID: uuid.NullUUID{UUID: uuid.New(), Valid: true},
RootChatID: uuid.NullUUID{UUID: uuid.New(), Valid: true},
LastModelConfigID: uuid.New(),
Title: "all-fields-test",
Status: database.ChatStatusRunning,
ClientType: database.ChatClientTypeUi,
LastError: pqtype.NullRawMessage{RawMessage: lastErrorRaw, Valid: true},
LastTurnSummary: sql.NullString{String: "turn completed", Valid: true},
CreatedAt: now,
UpdatedAt: now,
Archived: true,
UserACL: database.ChatACL{uuid.NewString(): database.ChatACLEntry{}},
PinOrder: 1,
PlanMode: database.NullChatPlanMode{ChatPlanMode: database.ChatPlanModePlan, Valid: true},
MCPServerIDs: []uuid.UUID{uuid.New()},
Labels: database.StringMap{"env": "prod"},
ID: uuid.New(),
OwnerID: uuid.New(),
OwnerUsername: "owner-username",
OwnerName: "Owner Name",
OrganizationID: uuid.New(),
WorkspaceID: uuid.NullUUID{UUID: uuid.New(), Valid: true},
BuildID: uuid.NullUUID{UUID: uuid.New(), Valid: true},
AgentID: uuid.NullUUID{UUID: uuid.New(), Valid: true},
ParentChatID: uuid.NullUUID{UUID: uuid.New(), Valid: true},
RootChatID: uuid.NullUUID{UUID: uuid.New(), Valid: true},
LastModelConfigID: uuid.New(),
LastReasoningEffort: database.NullChatReasoningEffort{ChatReasoningEffort: database.ChatReasoningEffortHigh, Valid: true},
Title: "all-fields-test",
Status: database.ChatStatusRunning,
ClientType: database.ChatClientTypeUi,
LastError: pqtype.NullRawMessage{RawMessage: lastErrorRaw, Valid: true},
LastTurnSummary: sql.NullString{String: "turn completed", Valid: true},
CreatedAt: now,
UpdatedAt: now,
Archived: true,
UserACL: database.ChatACL{uuid.NewString(): database.ChatACLEntry{}},
PinOrder: 1,
PlanMode: database.NullChatPlanMode{ChatPlanMode: database.ChatPlanModePlan, Valid: true},
MCPServerIDs: []uuid.UUID{uuid.New()},
Labels: database.StringMap{"env": "prod"},
DynamicTools: pqtype.NullRawMessage{
RawMessage: json.RawMessage(`[{"name":"tool1","description":"test tool","inputSchema":{"type":"object"}}]`),
Valid: true,
Expand Down
1 change: 1 addition & 0 deletions coderd/database/dbgen/dbgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func ChatMessage(t testing.TB, db database.Store, seed database.ChatMessage) dat
CreatedBy: []uuid.UUID{seed.CreatedBy.UUID},
APIKeyID: []string{apiKeyID},
ModelConfigID: []uuid.UUID{seed.ModelConfigID.UUID},
ReasoningEffort: []string{string(seed.ReasoningEffort.ChatReasoningEffort)},
Role: []database.ChatMessageRole{role},
Content: []string{content},
ContentVersion: []int16{takeFirst(seed.ContentVersion, chatprompt.CurrentContentVersion)},
Expand Down
24 changes: 22 additions & 2 deletions coderd/database/dump.sql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 61 additions & 0 deletions coderd/database/migrations/000542_chat_reasoning_effort.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
DROP VIEW IF EXISTS chats_expanded;

-- The up migration left the legacy per-provider effort keys in
-- place, so removing the reasoning_effort key restores the previous
-- state exactly.
UPDATE chat_model_configs
SET options = options - 'reasoning_effort'
WHERE options ? 'reasoning_effort';

ALTER TABLE chats DROP COLUMN last_reasoning_effort;
ALTER TABLE chat_messages DROP COLUMN reasoning_effort;
ALTER TABLE chat_queued_messages DROP COLUMN reasoning_effort;
DROP TYPE chat_reasoning_effort;

CREATE VIEW chats_expanded AS
SELECT c.id,
c.owner_id,
c.workspace_id,
c.title,
c.status,
c.worker_id,
c.started_at,
c.heartbeat_at,
c.created_at,
c.updated_at,
c.parent_chat_id,
c.root_chat_id,
c.last_model_config_id,
c.archived,
c.last_error,
c.mode,
c.mcp_server_ids,
c.labels,
c.build_id,
c.agent_id,
c.pin_order,
c.last_read_message_id,
c.dynamic_tools,
c.organization_id,
c.plan_mode,
c.client_type,
c.last_turn_summary,
c.snapshot_version,
c.history_version,
c.queue_version,
c.generation_attempt,
c.retry_state,
c.retry_state_version,
c.runner_id,
c.requires_action_deadline_at,
COALESCE(root.user_acl, c.user_acl) AS user_acl,
COALESCE(root.group_acl, c.group_acl) AS group_acl,
owner.username AS owner_username,
owner.name AS owner_name,
c.context_aggregate_hash,
c.context_dirty_since,
c.context_dirty_resources,
c.context_error
FROM ((chats c
LEFT JOIN chats root ON ((root.id = COALESCE(c.root_chat_id, c.parent_chat_id))))
JOIN visible_users owner ON ((owner.id = c.owner_id)));
88 changes: 88 additions & 0 deletions coderd/database/migrations/000542_chat_reasoning_effort.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
-- Per-turn reasoning effort. The chats_expanded view must be dropped
-- and recreated so the new chats column can appear in its column list.
DROP VIEW IF EXISTS chats_expanded;

CREATE TYPE chat_reasoning_effort AS ENUM ('none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max');

ALTER TABLE chats ADD COLUMN last_reasoning_effort chat_reasoning_effort;
ALTER TABLE chat_messages ADD COLUMN reasoning_effort chat_reasoning_effort;
ALTER TABLE chat_queued_messages ADD COLUMN reasoning_effort chat_reasoning_effort;

COMMENT ON COLUMN chats.last_reasoning_effort IS 'Stores the most recent message effort once per-turn selection is wired.';
COMMENT ON COLUMN chat_messages.reasoning_effort IS 'Stores the selected effort for the turn triggered by this message.';
COMMENT ON COLUMN chat_queued_messages.reasoning_effort IS 'Stores the selected effort until the queued row is promoted.';

CREATE VIEW chats_expanded AS
SELECT c.id,
c.owner_id,
c.workspace_id,
c.title,
c.status,
c.worker_id,
c.started_at,
c.heartbeat_at,
c.created_at,
c.updated_at,
c.parent_chat_id,
c.root_chat_id,
c.last_model_config_id,
c.last_reasoning_effort,
c.archived,
c.last_error,
c.mode,
c.mcp_server_ids,
c.labels,
c.build_id,
c.agent_id,
c.pin_order,
c.last_read_message_id,
c.dynamic_tools,
c.organization_id,
c.plan_mode,
c.client_type,
c.last_turn_summary,
c.snapshot_version,
c.history_version,
c.queue_version,
c.generation_attempt,
c.retry_state,
c.retry_state_version,
c.runner_id,
c.requires_action_deadline_at,
COALESCE(root.user_acl, c.user_acl) AS user_acl,
COALESCE(root.group_acl, c.group_acl) AS group_acl,
owner.username AS owner_username,
owner.name AS owner_name,
c.context_aggregate_hash,
c.context_dirty_since,
c.context_dirty_resources,
c.context_error
FROM ((chats c
LEFT JOIN chats root ON ((root.id = COALESCE(c.root_chat_id, c.parent_chat_id))))
JOIN visible_users owner ON ((owner.id = c.owner_id)));

-- Copy legacy per-provider effort values to top-level
-- reasoning_effort. Preserve legacy keys so the down migration can
-- restore the original options shape.
UPDATE chat_model_configs
Comment thread
DanielleMaywood marked this conversation as resolved.
SET options = options || jsonb_build_object(
'reasoning_effort',
jsonb_build_object('default', legacy.effort, 'max', legacy.effort)
)
FROM (
SELECT
id,
COALESCE(
NULLIF(lower(trim(options #>> '{provider_options,openai,reasoning_effort}')), ''),
NULLIF(lower(trim(options #>> '{provider_options,azure,reasoning_effort}')), ''),
NULLIF(lower(trim(options #>> '{provider_options,anthropic,effort}')), ''),
NULLIF(lower(trim(options #>> '{provider_options,bedrock,effort}')), ''),
NULLIF(lower(trim(options #>> '{provider_options,openaicompat,reasoning_effort}')), ''),
NULLIF(lower(trim(options #>> '{provider_options,openrouter,reasoning,effort}')), ''),
NULLIF(lower(trim(options #>> '{provider_options,vercel,reasoning,effort}')), '')
Comment thread
DanielleMaywood marked this conversation as resolved.
) AS effort
FROM chat_model_configs
) legacy
WHERE chat_model_configs.id = legacy.id
AND legacy.effort IS NOT NULL
AND legacy.effort IN ('none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max');
Loading
Loading