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
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ Maintainers answer the same questions, triage vague reports and review routine
changes every day. Gitdog indexes your repository and drafts the work for you,
with the actual code as evidence instead of generic advice.

| | What it does |
| ------------------------ | --------------------------------------------------------------------------------------- |
| **Issue assistant** | Turns rough reports into clear, structured issues and answers questions |
| **Discussion assistant** | Replies to GitHub Discussions with context from your codebase |
| **Pull request reviews** | Reviews changed code against the repository, suggests fixes and approves clean code |
| **Review commands** | `@gitdogai review`, `full review`, `resolve` and `help` in a pull request, or the CLI |
| **Maintainer tagging** | Notifies the right people when a request needs a code change |
| **Approval first** | With approval on (the default), drafts wait in your queue until you approve them |
| **Your own AI keys** | Run generation on your Anthropic or OpenAI key, encrypted at rest and never shown again |
| **Team workspace** | Share projects with members and keep per-project settings and usage in one place |
| | What it does |
| ------------------------ | ------------------------------------------------------------------------------------------- |
| **Issue assistant** | Turns rough reports into clear, structured issues and answers questions |
| **Discussion assistant** | Replies to GitHub Discussions with context from your codebase |
| **Pull request reviews** | Reviews changed code against the repository, suggests fixes and approves clean code |
| **Review commands** | `@gitdogai review`, `full review`, `resolve` and `help` in a pull request, or the CLI |
| **Maintainer tagging** | Notifies the right people when a request needs a code change |
| **Approval first** | With approval on (the default), drafts wait in your queue until you approve them |
| **Your own AI keys** | Run on your Anthropic or OpenAI key with the model and effort you choose, encrypted at rest |
| **Team workspace** | Share projects with members and keep per-project settings and usage in one place |

## Get started

Expand Down
77 changes: 77 additions & 0 deletions convex/_ai/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ export const CHAT_MODELS: Record<
outputPer1M: 10,
quotaWeight: 1,
},
// Available on an owner's own key only; priced for recorded cost.
"claude-haiku-5-5": {
provider: "anthropic",
inputPer1M: 0.1,
outputPer1M: 0.5,
quotaWeight: 0.05,
longContext: {
inputTokens: 100_000,
inputMultiplier: 5,
outputMultiplier: 5,
},
},
"gpt-6.1-sol": {
provider: "openai",
inputPer1M: 2,
Expand Down Expand Up @@ -112,6 +124,71 @@ export function getChatModel(model: string, provider: string) {
return entry;
}

export type ModelEffort = "low" | "medium" | "high";
export type UserKeyModel = {
modelId: string;
name: string;
efforts: readonly ModelEffort[];
defaultEffort: ModelEffort;
};

/**
* Models an owner can choose for their own provider key, the default first.
* The provider bills that usage, so it never counts against Gitdog tokens.
* Requests are not streamed and stop after two minutes, so settings that can
Comment thread
hyochan marked this conversation as resolved.
Resolved
* think for longer, such as Fable 5.1 or xhigh and max effort, are left out.
*/
export const USER_KEY_MODELS: Record<"anthropic" | "openai", UserKeyModel[]> = {
anthropic: [
{
modelId: "claude-opus-5-5",
name: "Claude Opus 5.5",
efforts: ["low", "medium", "high"],
defaultEffort: "medium",
},
{
modelId: "claude-sonnet-5-5",
name: "Claude Sonnet 5.5",
efforts: ["low", "medium", "high"],
defaultEffort: "high",
},
{
modelId: "claude-haiku-5-5",
name: "Claude Haiku 5.5",
efforts: ["low", "medium", "high"],
defaultEffort: "medium",
},
],
openai: [
{
modelId: "gpt-6.1-sol",
name: "GPT-6.1 Sol",
efforts: ["low", "medium", "high"],
defaultEffort: "high",
},
],
};

/**
* The model and effort an owner's key runs with. A choice that is no longer
* offered falls back to the default, so a key never stops working.
*/
export function userKeyModel(
provider: "anthropic" | "openai",
modelId?: string,
effort?: string,
): { modelId: string; name: string; effort: ModelEffort } {
const models = USER_KEY_MODELS[provider];
const model = models.find((m) => m.modelId === modelId) ?? models[0];
return {
modelId: model.modelId,
name: model.name,
effort: model.efforts.includes(effort as ModelEffort)
? (effort as ModelEffort)
: model.defaultEffort,
};
}

/**
* Quota weight held by every chat reservation: the highest weight among the
* models a Gitdog request may be routed to, so a reservation stays valid
Expand Down
10 changes: 8 additions & 2 deletions convex/_ai/providerResolution.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { userKeyModel } from "./config";
import { internal } from "../_generated/api";
import type { Doc, Id } from "../_generated/dataModel";
import type { ActionCtx } from "../_generated/server";
Expand Down Expand Up @@ -193,13 +194,18 @@ async function userKeyLeaf(
}
return "unreadable";
}
// The owner's chosen model and effort; the provider bills this usage.
const model = userKeyModel(row.provider, row.modelId, row.effort);
return new UserKeyProvider(
ctx,
row.userId,
row.provider,
row.provider === "anthropic"
? new ClaudeProvider(apiKey, undefined, { enforceAccessDeadline: false })
: new OpenAIProvider(apiKey),
? new ClaudeProvider(apiKey, undefined, {
enforceAccessDeadline: false,
model,
})
: new OpenAIProvider(apiKey, model),
row.iv,
);
}
Expand Down
40 changes: 30 additions & 10 deletions convex/_ai/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,29 @@ function parseTool(value: RecordValue, input: unknown): ToolUseContent {
return { type: "tool_use", id: value.id, name: value.name, input };
}

/** The model and effort a provider runs with; Gitdog's own by default. */
export type ProviderModel = { modelId: string; name: string; effort: string };

export class ClaudeProvider implements AiProvider {
readonly name = GENERATION_MODELS.anthropic.name;
readonly modelId = GENERATION_MODELS.anthropic.modelId;
readonly name: string;
readonly modelId: string;
readonly providerId = "anthropic";
private readonly effort: string;
constructor(
private readonly apiKey: string,
private readonly authorize?: () => Promise<Record<string, string>>,
// Gitdog's own Claude access ends at CLAUDE_API_ENDS_AT; a user's own
// key is not affected by that deadline.
private readonly routing: { enforceAccessDeadline?: boolean } = {},
) {}
// key is not affected by that deadline, and may choose its model.
private readonly routing: {
enforceAccessDeadline?: boolean;
model?: ProviderModel;
} = {},
) {
const model = routing.model ?? GENERATION_MODELS.anthropic;
this.name = model.name;
this.modelId = model.modelId;
this.effort = model.effort;
}

private get enforceDeadline() {
return this.routing.enforceAccessDeadline !== false;
Expand Down Expand Up @@ -244,7 +256,7 @@ export class ClaudeProvider implements AiProvider {
max_tokens: options?.maxTokens ?? 4096,
thinking: { type: "adaptive" },
output_config: {
effort: GENERATION_MODELS.anthropic.effort,
effort: this.effort,
...(options?.responseFormat
? {
format: {
Expand Down Expand Up @@ -376,10 +388,18 @@ export class ClaudeProvider implements AiProvider {
}

export class OpenAIProvider implements AiProvider {
readonly name = GENERATION_MODELS.openai.name;
readonly modelId = GENERATION_MODELS.openai.modelId;
readonly name: string;
readonly modelId: string;
readonly providerId = "openai";
constructor(private readonly apiKey: string) {}
private readonly effort: string;
constructor(
private readonly apiKey: string,
model: ProviderModel = GENERATION_MODELS.openai,
) {
this.name = model.name;
this.modelId = model.modelId;
this.effort = model.effort;
}

async chat(
messages: ChatMessage[],
Expand Down Expand Up @@ -441,7 +461,7 @@ export class OpenAIProvider implements AiProvider {
instructions: systemPrompt(messages),
input,
store: false,
reasoning: { effort: GENERATION_MODELS.openai.effort },
reasoning: { effort: this.effort },
include: ["reasoning.encrypted_content"],
max_output_tokens: options?.maxTokens ?? 4096,
...(options?.responseFormat
Expand Down
Loading
Loading