Compare commits

..

3 Commits

Author SHA1 Message Date
YeonGyu-Kim
adaeaca8e9 fix: add NODE_AUTH_TOKEN to publish-main job for npm auth
The publish-main job relied on npm trusted publishing (OIDC) which
broke after the repo rename from oh-my-opencode to oh-my-openagent.
Adding explicit NODE_AUTH_TOKEN restores auth while --provenance
still uses OIDC for Sigstore attestation.

Fixes #2373
2026-03-08 03:36:52 +09:00
YeonGyu-Kim
63ed7a5448 fix: update repository URLs to oh-my-openagent for npm provenance
npm --provenance validates repository.url against the actual GitHub
repo. Since the repo was renamed to oh-my-openagent, all platform
binary publishes failed with E422 provenance mismatch.
2026-03-08 02:59:40 +09:00
YeonGyu-Kim
e2444031ff ci(publish): deploy both oh-my-opencode and oh-my-openagent simultaneously 2026-03-08 02:31:26 +09:00
21 changed files with 52 additions and 539 deletions

View File

@@ -121,7 +121,7 @@ jobs:
publish-main:
runs-on: ubuntu-latest
needs: [test, typecheck]
if: github.repository == 'code-yeongyu/oh-my-opencode'
if: github.repository == 'code-yeongyu/oh-my-openagent'
outputs:
version: ${{ steps.version.outputs.version }}
dist_tag: ${{ steps.version.outputs.dist_tag }}
@@ -204,7 +204,7 @@ jobs:
bunx tsc --emitDeclarationOnly
bun run build:schema
- name: Publish main package
- name: Publish oh-my-opencode
if: steps.check.outputs.skip != 'true'
run: |
TAG_ARG=""
@@ -213,20 +213,42 @@ jobs:
fi
npm publish --access public --provenance $TAG_ARG
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
NPM_CONFIG_PROVENANCE: true
- name: Git commit and tag
- name: Publish oh-my-openagent
if: steps.check.outputs.skip != 'true'
run: |
git config user.email "github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git add package.json assets/oh-my-opencode.schema.json packages/*/package.json || true
git diff --cached --quiet || git commit -m "release: v${{ steps.version.outputs.version }}"
git tag -f "v${{ steps.version.outputs.version }}"
git push origin --tags --force
git push origin HEAD || echo "Branch push failed (non-critical)"
# Update package name to oh-my-openagent
jq '.name = "oh-my-openagent"' package.json > tmp.json && mv tmp.json package.json
# Update optionalDependencies to use oh-my-openagent naming
jq '.optionalDependencies = {
"oh-my-openagent-darwin-arm64": "${{ steps.version.outputs.version }}",
"oh-my-openagent-darwin-x64": "${{ steps.version.outputs.version }}",
"oh-my-openagent-darwin-x64-baseline": "${{ steps.version.outputs.version }}",
"oh-my-openagent-linux-arm64": "${{ steps.version.outputs.version }}",
"oh-my-openagent-linux-arm64-musl": "${{ steps.version.outputs.version }}",
"oh-my-openagent-linux-x64": "${{ steps.version.outputs.version }}",
"oh-my-openagent-linux-x64-baseline": "${{ steps.version.outputs.version }}",
"oh-my-openagent-linux-x64-musl": "${{ steps.version.outputs.version }}",
"oh-my-openagent-linux-x64-musl-baseline": "${{ steps.version.outputs.version }}",
"oh-my-openagent-windows-x64": "${{ steps.version.outputs.version }}",
"oh-my-openagent-windows-x64-baseline": "${{ steps.version.outputs.version }}"
}' package.json > tmp.json && mv tmp.json package.json
TAG_ARG=""
if [ -n "${{ steps.version.outputs.dist_tag }}" ]; then
TAG_ARG="--tag ${{ steps.version.outputs.dist_tag }}"
fi
npm publish --access public --provenance $TAG_ARG || echo "oh-my-openagent publish may have failed (package may already exist)"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
NPM_CONFIG_PROVENANCE: true
- name: Restore package.json
if: steps.check.outputs.skip != 'true'
run: |
# Restore original package name
jq '.name = "oh-my-opencode"' package.json > tmp.json && mv tmp.json package.json
trigger-platform:
runs-on: ubuntu-latest

View File

@@ -45,12 +45,12 @@
"license": "SUL-1.0",
"repository": {
"type": "git",
"url": "git+https://github.com/code-yeongyu/oh-my-opencode.git"
"url": "git+https://github.com/code-yeongyu/oh-my-openagent.git"
},
"bugs": {
"url": "https://github.com/code-yeongyu/oh-my-opencode/issues"
"url": "https://github.com/code-yeongyu/oh-my-openagent/issues"
},
"homepage": "https://github.com/code-yeongyu/oh-my-opencode#readme",
"homepage": "https://github.com/code-yeongyu/oh-my-openagent#readme",
"dependencies": {
"@ast-grep/cli": "^0.40.0",
"@ast-grep/napi": "^0.40.0",

View File

@@ -5,7 +5,7 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/code-yeongyu/oh-my-opencode"
"url": "https://github.com/code-yeongyu/oh-my-openagent"
},
"os": [
"darwin"

View File

@@ -5,7 +5,7 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/code-yeongyu/oh-my-opencode"
"url": "https://github.com/code-yeongyu/oh-my-openagent"
},
"os": [
"darwin"

View File

@@ -5,7 +5,7 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/code-yeongyu/oh-my-opencode"
"url": "https://github.com/code-yeongyu/oh-my-openagent"
},
"os": [
"darwin"

View File

@@ -5,7 +5,7 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/code-yeongyu/oh-my-opencode"
"url": "https://github.com/code-yeongyu/oh-my-openagent"
},
"os": [
"linux"

View File

@@ -5,7 +5,7 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/code-yeongyu/oh-my-opencode"
"url": "https://github.com/code-yeongyu/oh-my-openagent"
},
"os": [
"linux"

View File

@@ -5,7 +5,7 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/code-yeongyu/oh-my-opencode"
"url": "https://github.com/code-yeongyu/oh-my-openagent"
},
"os": [
"linux"

View File

@@ -5,7 +5,7 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/code-yeongyu/oh-my-opencode"
"url": "https://github.com/code-yeongyu/oh-my-openagent"
},
"os": [
"linux"

View File

@@ -5,7 +5,7 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/code-yeongyu/oh-my-opencode"
"url": "https://github.com/code-yeongyu/oh-my-openagent"
},
"os": [
"linux"

View File

@@ -5,7 +5,7 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/code-yeongyu/oh-my-opencode"
"url": "https://github.com/code-yeongyu/oh-my-openagent"
},
"os": [
"linux"

View File

@@ -5,7 +5,7 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/code-yeongyu/oh-my-opencode"
"url": "https://github.com/code-yeongyu/oh-my-openagent"
},
"os": [
"win32"

View File

@@ -5,7 +5,7 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/code-yeongyu/oh-my-opencode"
"url": "https://github.com/code-yeongyu/oh-my-openagent"
},
"os": [
"win32"

View File

@@ -26,11 +26,6 @@ export const RETRYABLE_ERROR_PATTERNS = [
/rate.?limit/i,
/too.?many.?requests/i,
/quota.?exceeded/i,
/quota\s+will\s+reset\s+after/i,
/all\s+credentials\s+for\s+model/i,
/cool(?:ing)?\s+down/i,
/cooldown/i,
/exhausted\s+your\s+capacity/i,
/usage\s+limit\s+has\s+been\s+reached/i,
/service.?unavailable/i,
/overloaded/i,

View File

@@ -6,11 +6,9 @@ import { extractStatusCode, extractErrorName, classifyErrorType, isRetryableErro
import { createFallbackState, prepareFallback } from "./fallback-state"
import { getFallbackModelsForSession } from "./fallback-models"
import { SessionCategoryRegistry } from "../../shared/session-category-registry"
import { createSessionStatusHandler } from "./session-status-handler"
export function createEventHandler(deps: HookDeps, helpers: AutoRetryHelpers) {
const { config, pluginConfig, sessionStates, sessionLastAccess, sessionRetryInFlight, sessionAwaitingFallbackResult, sessionFallbackTimeouts } = deps
const sessionStatusHandler = createSessionStatusHandler(deps, helpers)
const handleSessionCreated = (props: Record<string, unknown> | undefined) => {
const sessionInfo = props?.info as { id?: string; model?: string } | undefined
@@ -35,7 +33,6 @@ export function createEventHandler(deps: HookDeps, helpers: AutoRetryHelpers) {
sessionRetryInFlight.delete(sessionID)
sessionAwaitingFallbackResult.delete(sessionID)
helpers.clearSessionFallbackTimeout(sessionID)
sessionStatusHandler.clearRetryKey(sessionID)
SessionCategoryRegistry.remove(sessionID)
}
}
@@ -194,7 +191,6 @@ export function createEventHandler(deps: HookDeps, helpers: AutoRetryHelpers) {
if (event.type === "session.deleted") { handleSessionDeleted(props); return }
if (event.type === "session.stop") { await handleSessionStop(props); return }
if (event.type === "session.idle") { handleSessionIdle(props); return }
if (event.type === "session.status") { await sessionStatusHandler.handleSessionStatus(props); return }
if (event.type === "session.error") { await handleSessionError(props); return }
}
}

View File

@@ -387,133 +387,6 @@ describe("runtime-fallback", () => {
expect(fallbackLog?.data).toMatchObject({ from: "openai/gpt-5.3-codex", to: "anthropic/claude-opus-4-6" })
})
test("should trigger fallback on session.status auto-retry signal", async () => {
const promptCalls: unknown[] = []
const hook = createRuntimeFallbackHook(
createMockPluginInput({
session: {
messages: async () => ({
data: [
{
info: { role: "user" },
parts: [{ type: "text", text: "continue" }],
},
],
}),
promptAsync: async (args: unknown) => {
promptCalls.push(args)
return {}
},
},
}),
{
config: createMockConfig({ notify_on_fallback: false }),
pluginConfig: createMockPluginConfigWithCategoryFallback(["openai/gpt-5.4"]),
}
)
const sessionID = "test-session-status-auto-retry"
SessionCategoryRegistry.register(sessionID, "test")
await hook.event({
event: {
type: "session.created",
properties: { info: { id: sessionID, model: "quotio/claude-opus-4-6" } },
},
})
await hook.event({
event: {
type: "session.status",
properties: {
sessionID,
status: {
type: "retry",
attempt: 1,
next: 476,
message: "All credentials for model claude-opus-4-6 are cooling down [retrying in 7m 56s attempt #1]",
},
},
},
})
const signalLog = logCalls.find((c) => c.msg.includes("Detected provider auto-retry signal in session.status"))
expect(signalLog).toBeDefined()
const fallbackLog = logCalls.find((c) => c.msg.includes("Preparing fallback"))
expect(fallbackLog).toBeDefined()
expect(fallbackLog?.data).toMatchObject({ from: "quotio/claude-opus-4-6", to: "openai/gpt-5.4" })
expect(promptCalls).toHaveLength(1)
})
test("should deduplicate session.status countdown updates for the same retry attempt", async () => {
const promptCalls: unknown[] = []
const hook = createRuntimeFallbackHook(
createMockPluginInput({
session: {
messages: async () => ({
data: [
{
info: { role: "user" },
parts: [{ type: "text", text: "continue" }],
},
],
}),
promptAsync: async (args: unknown) => {
promptCalls.push(args)
return {}
},
},
}),
{
config: createMockConfig({ notify_on_fallback: false }),
pluginConfig: createMockPluginConfigWithCategoryFallback(["openai/gpt-5.4"]),
}
)
const sessionID = "test-session-status-countdown-dedup"
SessionCategoryRegistry.register(sessionID, "test")
await hook.event({
event: {
type: "session.created",
properties: { info: { id: sessionID, model: "quotio/claude-opus-4-6" } },
},
})
await hook.event({
event: {
type: "session.status",
properties: {
sessionID,
status: {
type: "retry",
attempt: 1,
next: 476,
message: "All credentials for model claude-opus-4-6 are cooling down [retrying in 7m 56s attempt #1]",
},
},
},
})
await hook.event({
event: {
type: "session.status",
properties: {
sessionID,
status: {
type: "retry",
attempt: 1,
next: 475,
message: "All credentials for model claude-opus-4-6 are cooling down [retrying in 7m 55s attempt #1]",
},
},
},
})
expect(promptCalls).toHaveLength(1)
})
test("should NOT trigger fallback on auto-retry signal when timeout_seconds is 0", async () => {
const hook = createRuntimeFallbackHook(createMockPluginInput(), {
config: createMockConfig({ notify_on_fallback: false, timeout_seconds: 0 }),

View File

@@ -1,160 +0,0 @@
import type { HookDeps } from "./types"
import type { AutoRetryHelpers } from "./auto-retry"
import { HOOK_NAME } from "./constants"
import { log } from "../../shared/logger"
import { isRetryableError } from "./error-classifier"
import { createFallbackState, prepareFallback } from "./fallback-state"
import { getFallbackModelsForSession } from "./fallback-models"
import { extractRetryAttempt, extractRetryStatusModel, normalizeRetryStatusMessage } from "../../shared/retry-status-utils"
type SessionStatus = {
type?: string
message?: string
attempt?: number
}
function resolveInitialModel(
props: Record<string, unknown> | undefined,
retryMessage: string,
resolvedAgent: string | undefined,
pluginConfig: HookDeps["pluginConfig"],
): string | undefined {
const eventModel = typeof props?.model === "string" ? props.model : undefined
if (eventModel) {
return eventModel
}
const retryModel = extractRetryStatusModel(retryMessage)
if (retryModel) {
return retryModel
}
const agentConfig = resolvedAgent
? pluginConfig?.agents?.[resolvedAgent as keyof typeof pluginConfig.agents]
: undefined
return typeof agentConfig?.model === "string" ? agentConfig.model : undefined
}
export function createSessionStatusHandler(deps: HookDeps, helpers: AutoRetryHelpers): {
clearRetryKey: (sessionID: string) => void
handleSessionStatus: (props: Record<string, unknown> | undefined) => Promise<void>
} {
const {
config,
pluginConfig,
sessionStates,
sessionLastAccess,
sessionRetryInFlight,
sessionAwaitingFallbackResult,
} = deps
const sessionStatusRetryKeys = new Map<string, string>()
const clearRetryKey = (sessionID: string): void => {
sessionStatusRetryKeys.delete(sessionID)
}
const handleSessionStatus = async (props: Record<string, unknown> | undefined): Promise<void> => {
const sessionID = props?.sessionID as string | undefined
const status = props?.status as SessionStatus | undefined
const agent = props?.agent as string | undefined
const timeoutEnabled = config.timeout_seconds > 0
if (!sessionID || status?.type !== "retry" || !timeoutEnabled) {
return
}
const retryMessage = typeof status.message === "string" ? status.message : ""
if (!retryMessage || !isRetryableError({ message: retryMessage }, config.retry_on_errors)) {
return
}
const currentState = sessionStates.get(sessionID)
const retryAttempt = extractRetryAttempt(status.attempt, retryMessage)
const retryModel =
(typeof props?.model === "string" ? props.model : undefined) ??
extractRetryStatusModel(retryMessage) ??
currentState?.currentModel ??
"unknown-model"
const retryKey = `${retryAttempt}:${retryModel}:${normalizeRetryStatusMessage(retryMessage)}`
if (sessionStatusRetryKeys.get(sessionID) === retryKey) {
return
}
sessionStatusRetryKeys.set(sessionID, retryKey)
if (sessionRetryInFlight.has(sessionID)) {
log(`[${HOOK_NAME}] Overriding in-flight retry due to provider session.status retry signal`, {
sessionID,
retryModel,
})
await helpers.abortSessionRequest(sessionID, "session.status.retry-signal")
sessionRetryInFlight.delete(sessionID)
}
sessionAwaitingFallbackResult.delete(sessionID)
const resolvedAgent = await helpers.resolveAgentForSessionFromContext(sessionID, agent)
const fallbackModels = getFallbackModelsForSession(sessionID, resolvedAgent, pluginConfig)
if (fallbackModels.length === 0) {
log(`[${HOOK_NAME}] No fallback models configured`, { sessionID, agent: resolvedAgent ?? agent })
return
}
let state = currentState
if (!state) {
const initialModel = resolveInitialModel(props, retryMessage, resolvedAgent, pluginConfig)
if (!initialModel) {
log(`[${HOOK_NAME}] session.status retry missing model info, cannot fallback`, { sessionID })
return
}
state = createFallbackState(initialModel)
sessionStates.set(sessionID, state)
}
sessionLastAccess.set(sessionID, Date.now())
if (state.pendingFallbackModel) {
log(`[${HOOK_NAME}] Clearing pending fallback due to provider session.status retry signal`, {
sessionID,
pendingFallbackModel: state.pendingFallbackModel,
})
state.pendingFallbackModel = undefined
}
log(`[${HOOK_NAME}] Detected provider auto-retry signal in session.status`, {
sessionID,
model: state.currentModel,
retryAttempt,
})
const result = prepareFallback(sessionID, state, fallbackModels, config)
if (result.success && config.notify_on_fallback) {
await deps.ctx.client.tui
.showToast({
body: {
title: "Model Fallback",
message: `Switching to ${result.newModel?.split("/").pop() || result.newModel} for next request`,
variant: "warning",
duration: 5000,
},
})
.catch(() => {})
}
if (result.success && result.newModel) {
await helpers.autoRetryWithFallback(sessionID, result.newModel, resolvedAgent, "session.status")
return
}
log(`[${HOOK_NAME}] Fallback preparation failed`, { sessionID, error: result.error })
}
return {
clearRetryKey,
handleSessionStatus,
}
}

View File

@@ -6,7 +6,7 @@ import { _resetForTesting, setMainSession } from "../features/claude-code-sessio
import { createModelFallbackHook, clearPendingModelFallback } from "../hooks/model-fallback/hook"
describe("createEventHandler - model fallback", () => {
const createHandler = (args?: { hooks?: any; pluginConfig?: any }) => {
const createHandler = (args?: { hooks?: any }) => {
const abortCalls: string[] = []
const promptCalls: string[] = []
@@ -26,7 +26,7 @@ describe("createEventHandler - model fallback", () => {
},
},
} as any,
pluginConfig: (args?.pluginConfig ?? {}) as any,
pluginConfig: {} as any,
firstMessageVariantGate: {
markSessionCreated: () => {},
clear: () => {},
@@ -213,121 +213,6 @@ describe("createEventHandler - model fallback", () => {
expect(output.message["variant"]).toBe("max")
})
test("deduplicates session.status countdown updates for the same retry attempt", async () => {
//#given
const sessionID = "ses_status_retry_dedup"
setMainSession(sessionID)
clearPendingModelFallback(sessionID)
const modelFallback = createModelFallbackHook()
const { handler, abortCalls, promptCalls } = createHandler({ hooks: { modelFallback } })
await handler({
event: {
type: "message.updated",
properties: {
info: {
id: "msg_user_status_dedup",
sessionID,
role: "user",
modelID: "claude-opus-4-6-thinking",
providerID: "anthropic",
agent: "Sisyphus (Ultraworker)",
},
},
},
})
//#when
await handler({
event: {
type: "session.status",
properties: {
sessionID,
status: {
type: "retry",
attempt: 1,
message:
"Bad Gateway: {\"error\":{\"message\":\"unknown provider for model claude-opus-4-6-thinking\"}} [retrying in 27s attempt #1]",
next: 27,
},
},
},
})
await handler({
event: {
type: "session.status",
properties: {
sessionID,
status: {
type: "retry",
attempt: 1,
message:
"Bad Gateway: {\"error\":{\"message\":\"unknown provider for model claude-opus-4-6-thinking\"}} [retrying in 26s attempt #1]",
next: 26,
},
},
},
})
//#then
expect(abortCalls).toEqual([sessionID])
expect(promptCalls).toEqual([sessionID])
})
test("does not trigger model fallback from session.status when runtime fallback is enabled", async () => {
//#given
const sessionID = "ses_status_retry_runtime_enabled"
setMainSession(sessionID)
clearPendingModelFallback(sessionID)
const modelFallback = createModelFallbackHook()
const runtimeFallback = {
event: async () => {},
"chat.message": async () => {},
}
const { handler, abortCalls, promptCalls } = createHandler({
hooks: { modelFallback, runtimeFallback },
pluginConfig: { runtime_fallback: { enabled: true } },
})
await handler({
event: {
type: "message.updated",
properties: {
info: {
id: "msg_user_status_runtime_enabled",
sessionID,
role: "user",
modelID: "claude-opus-4-6-thinking",
providerID: "anthropic",
agent: "Sisyphus (Ultraworker)",
},
},
},
})
//#when
await handler({
event: {
type: "session.status",
properties: {
sessionID,
status: {
type: "retry",
attempt: 1,
message:
"Bad Gateway: {\"error\":{\"message\":\"unknown provider for model claude-opus-4-6-thinking\"}} [retrying in 27s attempt #1]",
next: 27,
},
},
},
})
//#then
expect(abortCalls).toEqual([])
expect(promptCalls).toEqual([])
})
test("advances main-session fallback chain across repeated session.error retries end-to-end", async () => {
//#given
const abortCalls: string[] = []

View File

@@ -18,7 +18,6 @@ import {
import { resetMessageCursor } from "../shared";
import { log } from "../shared/logger";
import { shouldRetryError } from "../shared/model-error-classifier";
import { extractRetryAttempt, extractRetryStatusModel, normalizeRetryStatusMessage } from "../shared/retry-status-utils";
import { clearSessionModel, setSessionModel } from "../shared/session-model-state";
import { deleteSessionTools } from "../shared/session-tools-store";
import { lspManager } from "../tools";
@@ -343,15 +342,10 @@ export function createEventHandler(args: {
const sessionID = props?.sessionID as string | undefined;
const status = props?.status as { type?: string; attempt?: number; message?: string; next?: number } | undefined;
if (sessionID && status?.type === "retry" && !isRuntimeFallbackEnabled && isModelFallbackEnabled) {
if (sessionID && status?.type === "retry" && isModelFallbackEnabled) {
try {
const retryMessage = typeof status.message === "string" ? status.message : "";
const retryAttempt = extractRetryAttempt(status.attempt, retryMessage);
const retryModel =
extractRetryStatusModel(retryMessage) ??
lastKnownModelBySession.get(sessionID)?.modelID ??
"unknown-model";
const retryKey = `${retryAttempt}:${retryModel}:${normalizeRetryStatusMessage(retryMessage)}`;
const retryKey = `${status.attempt ?? "?"}:${status.next ?? "?"}:${retryMessage}`;
if (lastHandledRetryStatusKey.get(sessionID) === retryKey) {
return;
}

View File

@@ -1,41 +0,0 @@
import { describe, expect, test } from "bun:test"
import { extractRetryAttempt, extractRetryStatusModel, normalizeRetryStatusMessage } from "./retry-status-utils"
describe("retry-status-utils", () => {
test("extracts retry attempt from explicit status attempt", () => {
//#given
const attempt = 6
//#when
const result = extractRetryAttempt(attempt, "The usage limit has been reached [retrying in 27s attempt #6]")
//#then
expect(result).toBe(6)
})
test("extracts retry model from cooldown status text", () => {
//#given
const message = "All credentials for model claude-opus-4-6 are cooling down [retrying in 7m 56s attempt #1]"
//#when
const result = extractRetryStatusModel(message)
//#then
expect(result).toBe("claude-opus-4-6")
})
test("normalizes countdown jitter to a stable cooldown class", () => {
//#given
const firstMessage = "All credentials for model claude-opus-4-6 are cooling down [retrying in 7m 56s attempt #1]"
const secondMessage = "All credentials for model claude-opus-4-6 are cooling down [retrying in 7m 55s attempt #1]"
//#when
const firstResult = normalizeRetryStatusMessage(firstMessage)
const secondResult = normalizeRetryStatusMessage(secondMessage)
//#then
expect(firstResult).toBe("cooldown")
expect(secondResult).toBe("cooldown")
})
})

View File

@@ -1,51 +0,0 @@
const RETRY_COUNTDOWN_PATTERN = /\[\s*retrying\s+in[^\]]*\]/gi
function collapseWhitespace(value: string): string {
return value.toLowerCase().replace(/\s+/g, " ").trim()
}
export function extractRetryAttempt(attempt: number | undefined, message: string): number | "?" {
if (typeof attempt === "number" && Number.isFinite(attempt)) {
return attempt
}
const parsedAttempt = message.match(/attempt\s*#\s*(\d+)/i)?.[1]
return parsedAttempt ? Number.parseInt(parsedAttempt, 10) : "?"
}
export function extractRetryStatusModel(message: string): string | undefined {
return message.match(/model\s+([a-z0-9._/-]+)(?=\s+(?:are|is)\b)/i)?.[1]?.toLowerCase()
}
export function normalizeRetryStatusMessage(message: string): string {
const normalizedMessage = collapseWhitespace(message.replace(RETRY_COUNTDOWN_PATTERN, " "))
if (!normalizedMessage) {
return "retry"
}
if (/all\s+credentials\s+for\s+model|cool(?:ing)?\s+down|cooldown|exhausted\s+your\s+capacity/.test(normalizedMessage)) {
return "cooldown"
}
if (/too\s+many\s+requests/.test(normalizedMessage)) {
return "too-many-requests"
}
if (/quota\s+will\s+reset\s+after|quota\s*exceeded/.test(normalizedMessage)) {
return "quota"
}
if (/usage\s+limit\s+has\s+been\s+reached|limit\s+reached/.test(normalizedMessage)) {
return "usage-limit"
}
if (/rate\s+limit/.test(normalizedMessage)) {
return "rate-limit"
}
if (/service.?unavailable|temporarily.?unavailable|overloaded/.test(normalizedMessage)) {
return "service-unavailable"
}
return normalizedMessage
}