Skip to content
Open
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: 20 additions & 0 deletions src/components/swarm/router-chat.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { describe, expect, it } from 'vitest'
import { readFileSync } from 'node:fs'
import { join } from 'node:path'

function source(): string {
return readFileSync(
join(process.cwd(), 'src/components/swarm/router-chat.tsx'),
'utf-8',
)
}

describe('RouterChat dispatch request', () => {
it('does not block route mission UI while waiting for worker checkpoints', () => {
const src = source()

expect(src).toContain("fetch('/api/swarm-dispatch'")
expect(src).toContain('waitForCheckpoint: false')
expect(src).not.toContain('checkpointPollSeconds: 90')
})
})
5 changes: 3 additions & 2 deletions src/components/swarm/router-chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export function RouterChat({
prompt: prompt.trim(),
workers: eligibleWorkers,
}),
signal: AbortSignal.timeout(120_000),
})
if (!res.ok) {
const text = await res.text()
Expand Down Expand Up @@ -241,9 +242,9 @@ export function RouterChat({
body: JSON.stringify({
assignments: plan,
timeoutSeconds: 300,
waitForCheckpoint: true,
checkpointPollSeconds: 90,
waitForCheckpoint: false,
}),
signal: AbortSignal.timeout(60_000),
})
if (!res.ok) {
const text = await res.text()
Expand Down
25 changes: 25 additions & 0 deletions src/routes/api/-swarm-decompose.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { describe, expect, it } from 'vitest'
import { readFileSync } from 'node:fs'
import { join } from 'node:path'

function source(): string {
return readFileSync(
join(process.cwd(), 'src/routes/api/swarm-decompose.ts'),
'utf-8',
)
}

describe('/api/swarm-decompose auth', () => {
it('uses runtime bearer token helper for gateway chat completions', () => {
const src = source()

expect(src).toContain(
"import { getBearerToken } from '../../server/openai-compat-api'",
)
expect(src).toContain('const bearer = getBearerToken()')
expect(src).toContain(
'if (bearer) headers.Authorization = `Bearer ${bearer}`',
)
expect(src).not.toContain('if (BEARER_TOKEN) headers.Authorization')
})
})
6 changes: 4 additions & 2 deletions src/routes/api/swarm-decompose.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { createFileRoute } from '@tanstack/react-router'
import { json } from '@tanstack/react-start'
import { isAuthenticated } from '../../server/auth-middleware'
import { BEARER_TOKEN, ensureGatewayProbed, getResolvedUrls } from '../../server/gateway-capabilities'
import { ensureGatewayProbed, getResolvedUrls } from '../../server/gateway-capabilities'
import { getBearerToken } from '../../server/openai-compat-api'

type DecomposeRequest = {
prompt?: unknown
Expand Down Expand Up @@ -68,7 +69,8 @@ async function callOrchestrator(prompt: string, workers: WorkerHint[], model: st
}

const headers: Record<string, string> = { 'Content-Type': 'application/json' }
if (BEARER_TOKEN) headers.Authorization = `Bearer ${BEARER_TOKEN}`
const bearer = getBearerToken()
if (bearer) headers.Authorization = `Bearer ${bearer}`

const { gateway } = getResolvedUrls()
const res = await fetch(`${gateway}/v1/chat/completions`, {
Expand Down