mirror of
https://github.com/harivansh-afk/clanker-agent.git
synced 2026-04-15 05:02:07 +00:00
abort route
This commit is contained in:
parent
e19f575229
commit
a5e8a69cd4
3 changed files with 127 additions and 15 deletions
|
|
@ -9395,7 +9395,7 @@ export const MODELS = {
|
||||||
cacheWrite: 0,
|
cacheWrite: 0,
|
||||||
},
|
},
|
||||||
contextWindow: 262144,
|
contextWindow: 262144,
|
||||||
maxTokens: 65536,
|
maxTokens: 32000,
|
||||||
} satisfies Model<"openai-completions">,
|
} satisfies Model<"openai-completions">,
|
||||||
"openrouter/hunter-alpha": {
|
"openrouter/hunter-alpha": {
|
||||||
id: "openrouter/hunter-alpha",
|
id: "openrouter/hunter-alpha",
|
||||||
|
|
@ -9412,7 +9412,7 @@ export const MODELS = {
|
||||||
cacheWrite: 0,
|
cacheWrite: 0,
|
||||||
},
|
},
|
||||||
contextWindow: 1048576,
|
contextWindow: 1048576,
|
||||||
maxTokens: 65536,
|
maxTokens: 32000,
|
||||||
} satisfies Model<"openai-completions">,
|
} satisfies Model<"openai-completions">,
|
||||||
"prime-intellect/intellect-3": {
|
"prime-intellect/intellect-3": {
|
||||||
id: "prime-intellect/intellect-3",
|
id: "prime-intellect/intellect-3",
|
||||||
|
|
@ -10451,6 +10451,23 @@ export const MODELS = {
|
||||||
contextWindow: 2000000,
|
contextWindow: 2000000,
|
||||||
maxTokens: 30000,
|
maxTokens: 30000,
|
||||||
} satisfies Model<"openai-completions">,
|
} satisfies Model<"openai-completions">,
|
||||||
|
"x-ai/grok-4.20-beta": {
|
||||||
|
id: "x-ai/grok-4.20-beta",
|
||||||
|
name: "xAI: Grok 4.20 Beta",
|
||||||
|
api: "openai-completions",
|
||||||
|
provider: "openrouter",
|
||||||
|
baseUrl: "https://openrouter.ai/api/v1",
|
||||||
|
reasoning: true,
|
||||||
|
input: ["text", "image"],
|
||||||
|
cost: {
|
||||||
|
input: 2,
|
||||||
|
output: 6,
|
||||||
|
cacheRead: 0.19999999999999998,
|
||||||
|
cacheWrite: 0,
|
||||||
|
},
|
||||||
|
contextWindow: 2000000,
|
||||||
|
maxTokens: 4096,
|
||||||
|
} satisfies Model<"openai-completions">,
|
||||||
"x-ai/grok-code-fast-1": {
|
"x-ai/grok-code-fast-1": {
|
||||||
id: "x-ai/grok-code-fast-1",
|
id: "x-ai/grok-code-fast-1",
|
||||||
name: "xAI: Grok Code Fast 1",
|
name: "xAI: Grok Code Fast 1",
|
||||||
|
|
@ -12793,7 +12810,7 @@ export const MODELS = {
|
||||||
cost: {
|
cost: {
|
||||||
input: 3,
|
input: 3,
|
||||||
output: 15,
|
output: 15,
|
||||||
cacheRead: 0,
|
cacheRead: 0.75,
|
||||||
cacheWrite: 0,
|
cacheWrite: 0,
|
||||||
},
|
},
|
||||||
contextWindow: 256000,
|
contextWindow: 256000,
|
||||||
|
|
@ -12867,6 +12884,57 @@ export const MODELS = {
|
||||||
contextWindow: 2000000,
|
contextWindow: 2000000,
|
||||||
maxTokens: 30000,
|
maxTokens: 30000,
|
||||||
} satisfies Model<"anthropic-messages">,
|
} satisfies Model<"anthropic-messages">,
|
||||||
|
"xai/grok-4.20-multi-agent-beta": {
|
||||||
|
id: "xai/grok-4.20-multi-agent-beta",
|
||||||
|
name: "Grok 4.20 Multi Agent Beta",
|
||||||
|
api: "anthropic-messages",
|
||||||
|
provider: "vercel-ai-gateway",
|
||||||
|
baseUrl: "https://ai-gateway.vercel.sh",
|
||||||
|
reasoning: true,
|
||||||
|
input: ["text"],
|
||||||
|
cost: {
|
||||||
|
input: 2,
|
||||||
|
output: 6,
|
||||||
|
cacheRead: 0.19999999999999998,
|
||||||
|
cacheWrite: 0,
|
||||||
|
},
|
||||||
|
contextWindow: 2000000,
|
||||||
|
maxTokens: 2000000,
|
||||||
|
} satisfies Model<"anthropic-messages">,
|
||||||
|
"xai/grok-4.20-non-reasoning-beta": {
|
||||||
|
id: "xai/grok-4.20-non-reasoning-beta",
|
||||||
|
name: "Grok 4.20 Beta Non-Reasoning",
|
||||||
|
api: "anthropic-messages",
|
||||||
|
provider: "vercel-ai-gateway",
|
||||||
|
baseUrl: "https://ai-gateway.vercel.sh",
|
||||||
|
reasoning: false,
|
||||||
|
input: ["text", "image"],
|
||||||
|
cost: {
|
||||||
|
input: 2,
|
||||||
|
output: 6,
|
||||||
|
cacheRead: 0.19999999999999998,
|
||||||
|
cacheWrite: 0,
|
||||||
|
},
|
||||||
|
contextWindow: 2000000,
|
||||||
|
maxTokens: 2000000,
|
||||||
|
} satisfies Model<"anthropic-messages">,
|
||||||
|
"xai/grok-4.20-reasoning-beta": {
|
||||||
|
id: "xai/grok-4.20-reasoning-beta",
|
||||||
|
name: "Grok 4.20 Beta Reasoning",
|
||||||
|
api: "anthropic-messages",
|
||||||
|
provider: "vercel-ai-gateway",
|
||||||
|
baseUrl: "https://ai-gateway.vercel.sh",
|
||||||
|
reasoning: true,
|
||||||
|
input: ["text", "image"],
|
||||||
|
cost: {
|
||||||
|
input: 2,
|
||||||
|
output: 6,
|
||||||
|
cacheRead: 0.19999999999999998,
|
||||||
|
cacheWrite: 0,
|
||||||
|
},
|
||||||
|
contextWindow: 2000000,
|
||||||
|
maxTokens: 2000000,
|
||||||
|
} satisfies Model<"anthropic-messages">,
|
||||||
"xai/grok-code-fast-1": {
|
"xai/grok-code-fast-1": {
|
||||||
id: "xai/grok-code-fast-1",
|
id: "xai/grok-code-fast-1",
|
||||||
name: "Grok Code Fast 1",
|
name: "Grok Code Fast 1",
|
||||||
|
|
@ -13396,9 +13464,9 @@ export const MODELS = {
|
||||||
contextWindow: 2000000,
|
contextWindow: 2000000,
|
||||||
maxTokens: 30000,
|
maxTokens: 30000,
|
||||||
} satisfies Model<"openai-completions">,
|
} satisfies Model<"openai-completions">,
|
||||||
"grok-4.20-experimental-beta-0304-non-reasoning": {
|
"grok-4.20-beta-latest-non-reasoning": {
|
||||||
id: "grok-4.20-experimental-beta-0304-non-reasoning",
|
id: "grok-4.20-beta-latest-non-reasoning",
|
||||||
name: "Grok 4.20 (Experimental, Non-Reasoning)",
|
name: "Grok 4.20 Beta (Non-Reasoning)",
|
||||||
api: "openai-completions",
|
api: "openai-completions",
|
||||||
provider: "xai",
|
provider: "xai",
|
||||||
baseUrl: "https://api.x.ai/v1",
|
baseUrl: "https://api.x.ai/v1",
|
||||||
|
|
@ -13413,9 +13481,9 @@ export const MODELS = {
|
||||||
contextWindow: 2000000,
|
contextWindow: 2000000,
|
||||||
maxTokens: 30000,
|
maxTokens: 30000,
|
||||||
} satisfies Model<"openai-completions">,
|
} satisfies Model<"openai-completions">,
|
||||||
"grok-4.20-experimental-beta-0304-reasoning": {
|
"grok-4.20-beta-latest-reasoning": {
|
||||||
id: "grok-4.20-experimental-beta-0304-reasoning",
|
id: "grok-4.20-beta-latest-reasoning",
|
||||||
name: "Grok 4.20 (Experimental, Reasoning)",
|
name: "Grok 4.20 Beta (Reasoning)",
|
||||||
api: "openai-completions",
|
api: "openai-completions",
|
||||||
provider: "xai",
|
provider: "xai",
|
||||||
baseUrl: "https://api.x.ai/v1",
|
baseUrl: "https://api.x.ai/v1",
|
||||||
|
|
@ -13430,9 +13498,9 @@ export const MODELS = {
|
||||||
contextWindow: 2000000,
|
contextWindow: 2000000,
|
||||||
maxTokens: 30000,
|
maxTokens: 30000,
|
||||||
} satisfies Model<"openai-completions">,
|
} satisfies Model<"openai-completions">,
|
||||||
"grok-4.20-multi-agent-experimental-beta-0304": {
|
"grok-4.20-multi-agent-beta-latest": {
|
||||||
id: "grok-4.20-multi-agent-experimental-beta-0304",
|
id: "grok-4.20-multi-agent-beta-latest",
|
||||||
name: "Grok 4.20 Multi-Agent (Experimental)",
|
name: "Grok 4.20 Multi-Agent Beta",
|
||||||
api: "openai-completions",
|
api: "openai-completions",
|
||||||
provider: "xai",
|
provider: "xai",
|
||||||
baseUrl: "https://api.x.ai/v1",
|
baseUrl: "https://api.x.ai/v1",
|
||||||
|
|
|
||||||
|
|
@ -282,9 +282,20 @@ export class GatewayRuntime {
|
||||||
|
|
||||||
abortSession(sessionKey: string): boolean {
|
abortSession(sessionKey: string): boolean {
|
||||||
const managedSession = this.sessions.get(sessionKey);
|
const managedSession = this.sessions.get(sessionKey);
|
||||||
if (!managedSession?.processing) {
|
if (!managedSession) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hadQueuedMessages = managedSession.queue.length > 0;
|
||||||
|
if (hadQueuedMessages) {
|
||||||
|
this.rejectQueuedMessages(managedSession, "Session aborted");
|
||||||
|
this.emitState(managedSession);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!managedSession.processing) {
|
||||||
|
return hadQueuedMessages;
|
||||||
|
}
|
||||||
|
|
||||||
void managedSession.session.abort().catch((error) => {
|
void managedSession.session.abort().catch((error) => {
|
||||||
this.emit(managedSession, {
|
this.emit(managedSession, {
|
||||||
type: "error",
|
type: "error",
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
import type { ManagedGatewaySession } from "../src/core/gateway/internal-types.js";
|
||||||
import { GatewayRuntime } from "../src/core/gateway/runtime.js";
|
import { GatewayRuntime } from "../src/core/gateway/runtime.js";
|
||||||
|
|
||||||
function createMockSession() {
|
function createMockSession() {
|
||||||
|
|
@ -43,9 +44,9 @@ function addManagedSession(
|
||||||
session: ReturnType<typeof createMockSession>,
|
session: ReturnType<typeof createMockSession>,
|
||||||
processing: boolean,
|
processing: boolean,
|
||||||
) {
|
) {
|
||||||
const managedSession = {
|
const managedSession: ManagedGatewaySession = {
|
||||||
sessionKey,
|
sessionKey,
|
||||||
session,
|
session: session as never,
|
||||||
queue: [],
|
queue: [],
|
||||||
processing,
|
processing,
|
||||||
activeAssistantMessage: null,
|
activeAssistantMessage: null,
|
||||||
|
|
@ -124,4 +125,36 @@ describe("GatewayRuntime steer handling", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("abort clears queued follow-ups before aborting the active session", () => {
|
||||||
|
const session = createMockSession();
|
||||||
|
const runtime = createRuntime(session);
|
||||||
|
const managedSession = addManagedSession(runtime, "chat", session, true);
|
||||||
|
const resolve = vi.fn();
|
||||||
|
|
||||||
|
managedSession.queue.push({
|
||||||
|
request: {
|
||||||
|
sessionKey: "chat",
|
||||||
|
text: "stale follow-up",
|
||||||
|
source: "extension",
|
||||||
|
},
|
||||||
|
resolve,
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = (
|
||||||
|
runtime as unknown as {
|
||||||
|
abortSession: (sessionKey: string) => boolean;
|
||||||
|
}
|
||||||
|
).abortSession("chat");
|
||||||
|
|
||||||
|
expect(result).toBe(true);
|
||||||
|
expect(managedSession.queue).toHaveLength(0);
|
||||||
|
expect(resolve).toHaveBeenCalledWith({
|
||||||
|
ok: false,
|
||||||
|
response: "",
|
||||||
|
error: "Session aborted",
|
||||||
|
sessionKey: "chat",
|
||||||
|
});
|
||||||
|
expect(session.abort).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue