Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

ci: skip tsc on grok cjs packages and format grok-llm-proxy

Jose Gabriel Ramirez Encinas42eca61fdea3
diff --git a/.github/workflows/ci-public.yml b/.github/workflows/ci-public.yml
index 545efe064..4952950c0 100644
--- a/.github/workflows/ci-public.yml
+++ b/.github/workflows/ci-public.yml
@@ -162,11 +162,12 @@ jobs:
# .d.ts packages with no tsconfig, so
# `tsc --noEmit` resolves no project (like mcp-servers). Their declarations
# are kept aligned with runtime by "runtime exports stay aligned" node:tests.
- # llm-provider-attempt-contract and codex-catalog-projection are the same
- # shape: hand-authored .cjs + .d.ts, no tsconfig; node --test keeps the
+ # llm-provider-attempt-contract, grok-provider-attempt-contract,
+ # llm-providers, and codex-catalog-projection are the same shape:
+ # hand-authored .cjs + .d.ts, no tsconfig; node --test keeps the
# types aligned with the runtime.
- name: Typecheck (tsc --noEmit)
- if: matrix.service != 'mcp-servers' && matrix.service != 'packages/desktop-app-links' && matrix.service != 'packages/gfs-interaction-policy' && matrix.service != 'packages/network-policy-core' && matrix.service != 'packages/llm-provider-attempt-contract' && matrix.service != 'packages/codex-catalog-projection'
+ if: matrix.service != 'mcp-servers' && matrix.service != 'packages/desktop-app-links' && matrix.service != 'packages/gfs-interaction-policy' && matrix.service != 'packages/network-policy-core' && matrix.service != 'packages/llm-provider-attempt-contract' && matrix.service != 'packages/grok-provider-attempt-contract' && matrix.service != 'packages/llm-providers' && matrix.service != 'packages/codex-catalog-projection'
working-directory: ${{ matrix.service }}
run: npx tsc --noEmit
diff --git a/grok-llm-proxy/src/config.ts b/grok-llm-proxy/src/config.ts
index be667fddd..804b4d782 100644
--- a/grok-llm-proxy/src/config.ts
+++ b/grok-llm-proxy/src/config.ts
@@ -34,9 +34,21 @@ function requiredPem(name: string, raw: string | undefined): string {
export function loadConfig(env: NodeJS.ProcessEnv = process.env): GrokLlmProxyConfig {
return {
- runtimePort: requiredPositiveInt('GROK_LLM_PROXY_RUNTIME_PORT', env.GROK_LLM_PROXY_RUNTIME_PORT, 8080),
- adminPort: requiredPositiveInt('GROK_LLM_PROXY_ADMIN_PORT', env.GROK_LLM_PROXY_ADMIN_PORT, 8081),
- probePort: requiredPositiveInt('GROK_LLM_PROXY_PROBE_PORT', env.GROK_LLM_PROXY_PROBE_PORT, 9090),
+ runtimePort: requiredPositiveInt(
+ 'GROK_LLM_PROXY_RUNTIME_PORT',
+ env.GROK_LLM_PROXY_RUNTIME_PORT,
+ 8080
+ ),
+ adminPort: requiredPositiveInt(
+ 'GROK_LLM_PROXY_ADMIN_PORT',
+ env.GROK_LLM_PROXY_ADMIN_PORT,
+ 8081
+ ),
+ probePort: requiredPositiveInt(
+ 'GROK_LLM_PROXY_PROBE_PORT',
+ env.GROK_LLM_PROXY_PROBE_PORT,
+ 9090
+ ),
maxBodyBytes: requiredPositiveInt(
'GROK_LLM_PROXY_MAX_BODY_BYTES',
env.GROK_LLM_PROXY_MAX_BODY_BYTES,
diff --git a/grok-llm-proxy/src/controlApiClient.ts b/grok-llm-proxy/src/controlApiClient.ts
index 5a5672a76..d7646964d 100644
--- a/grok-llm-proxy/src/controlApiClient.ts
+++ b/grok-llm-proxy/src/controlApiClient.ts
@@ -80,7 +80,11 @@ export class ControlApiClient {
receipt: input.receipt,
})
if (!isPlainObject(body)) {
- return { providerAttemptId: input.receipt.providerAttemptId, outcome: input.receipt.outcome, duplicate: false }
+ return {
+ providerAttemptId: input.receipt.providerAttemptId,
+ outcome: input.receipt.outcome,
+ duplicate: false,
+ }
}
return {
providerAttemptId: String(body.providerAttemptId ?? input.receipt.providerAttemptId),
@@ -116,8 +120,13 @@ export class ControlApiClient {
}
if (!response.ok) {
const code =
- isPlainObject(parsed) && typeof parsed.error === 'string' ? parsed.error : 'provider_unavailable'
- logger.warn({ event: 'grok_proxy_control_api_denied', code, path }, 'control API request denied')
+ isPlainObject(parsed) && typeof parsed.error === 'string'
+ ? parsed.error
+ : 'provider_unavailable'
+ logger.warn(
+ { event: 'grok_proxy_control_api_denied', code, path },
+ 'control API request denied'
+ )
throw new ControlApiClientError(code, 'control API request denied')
}
return parsed
@@ -125,7 +134,11 @@ export class ControlApiClient {
}
function parseRedeem(body: unknown): RedeemAttemptSuccess {
- if (!isPlainObject(body) || typeof body.accessToken !== 'string' || !isPlainObject(body.transport)) {
+ if (
+ !isPlainObject(body) ||
+ typeof body.accessToken !== 'string' ||
+ !isPlainObject(body.transport)
+ ) {
throw new ControlApiClientError('provider_unavailable', 'redeem response is invalid')
}
const transport = body.transport
@@ -155,7 +168,8 @@ function parseRedeem(body: unknown): RedeemAttemptSuccess {
: 'completion_stream',
servedModel: transport.servedModel,
maxStreamDurationMs:
- typeof transport.maxStreamDurationMs === 'number' && Number.isFinite(transport.maxStreamDurationMs)
+ typeof transport.maxStreamDurationMs === 'number' &&
+ Number.isFinite(transport.maxStreamDurationMs)
? transport.maxStreamDurationMs
: 300_000,
},
diff --git a/grok-llm-proxy/src/grokTransport.ts b/grok-llm-proxy/src/grokTransport.ts
index 8a79b7184..f75ec70d3 100644
--- a/grok-llm-proxy/src/grokTransport.ts
+++ b/grok-llm-proxy/src/grokTransport.ts
@@ -4,8 +4,8 @@ import {
hashGrokCompletionRequestV1,
parseGrokCompletionRequestV1,
} from '@clerum/grok-provider-attempt-contract'
-import { grokUpstreamHeaders } from './grokUpstreamHeaders.js'
import type { FinalizeAttemptSuccess, RedeemAttemptSuccess } from './controlApiClient.js'
+import { grokUpstreamHeaders } from './grokUpstreamHeaders.js'
import { logger } from './logger.js'
import {
GROK_CATALOG_ORIGIN,
diff --git a/grok-llm-proxy/src/requestLimits.ts b/grok-llm-proxy/src/requestLimits.ts
index 6389c66f3..5ee10f58b 100644
--- a/grok-llm-proxy/src/requestLimits.ts
+++ b/grok-llm-proxy/src/requestLimits.ts
@@ -14,12 +14,20 @@ export class RequestLimitError extends Error {
}
}
-export function assertBoundedDeadline(deadlineMs: number | undefined, maxDeadlineMs: number): number {
+export function assertBoundedDeadline(
+ deadlineMs: number | undefined,
+ maxDeadlineMs: number
+): number {
const requested = deadlineMs ?? Math.min(maxDeadlineMs, STREAM_LIMITS.maxStreamDurationMs)
if (!Number.isFinite(requested) || !Number.isInteger(requested) || requested <= 0) {
throw new RequestLimitError('deadline is invalid')
}
- return Math.min(requested, maxDeadlineMs, STREAM_LIMITS.maxStreamDurationMs, CONTRACT_LIMITS.maxDeadlineMs)
+ return Math.min(
+ requested,
+ maxDeadlineMs,
+ STREAM_LIMITS.maxStreamDurationMs,
+ CONTRACT_LIMITS.maxDeadlineMs
+ )
}
export class StreamGate {
diff --git a/grok-llm-proxy/src/server.ts b/grok-llm-proxy/src/server.ts
index a3c6344e3..8d9648e6e 100644
--- a/grok-llm-proxy/src/server.ts
+++ b/grok-llm-proxy/src/server.ts
@@ -1,25 +1,25 @@
import express, { type Express, type Request, type Response } from 'express'
import { rateLimit } from 'express-rate-limit'
-import { createServer, type Server } from 'node:http'
+import { type Server, createServer } from 'node:http'
import { Registry, collectDefaultMetrics } from 'prom-client'
import { z } from 'zod'
import { verifyAdminPermit } from './auth/adminPermitVerifier.js'
import { verifyExecutionTicket } from './auth/executionTicketVerifier.js'
import { verifyPlatformJwt } from './auth/platformJwtVerifier.js'
+import type { GrokLlmProxyConfig } from './config.js'
+import { ControlApiClient, ControlApiClientError } from './controlApiClient.js'
import {
GrokTransportError,
listGrokModels,
streamGrokCompletion,
testGrokConnection,
} from './grokTransport.js'
-import type { GrokLlmProxyConfig } from './config.js'
-import { ControlApiClient, ControlApiClientError } from './controlApiClient.js'
import { logger } from './logger.js'
import { createProxyMetrics } from './metrics.js'
import {
- defaultAddressLookup,
OriginDeniedError,
type OriginPolicyOptions,
+ defaultAddressLookup,
} from './originPolicy.js'
import { RequestLimitError, streamGate } from './requestLimits.js'
@@ -84,7 +84,10 @@ export type ProxyServers = {
close: () => Promise<void>
}
-export function createProxyApps(config: GrokLlmProxyConfig, deps: ProxyRuntimeDeps = {}): ProxyServers {
+export function createProxyApps(
+ config: GrokLlmProxyConfig,
+ deps: ProxyRuntimeDeps = {}
+): ProxyServers {
const metricsRegistry = new Registry()
collectDefaultMetrics({ register: metricsRegistry })
const metrics = createProxyMetrics(metricsRegistry)
@@ -223,7 +226,13 @@ export function createProxyApps(config: GrokLlmProxyConfig, deps: ProxyRuntimeDe
reject(res, 403, 'insufficient_scope')
return
}
- if (!verifyAdminPermit(bearer(req), config, kind === 'models' ? 'catalog_list' : 'connection_test')) {
+ if (
+ !verifyAdminPermit(
+ bearer(req),
+ config,
+ kind === 'models' ? 'catalog_list' : 'connection_test'
+ )
+ ) {
reject(res, 401, 'Unauthorized')
return
}
diff --git a/grok-llm-proxy/src/usage.ts b/grok-llm-proxy/src/usage.ts
index d935531ce..df63d401f 100644
--- a/grok-llm-proxy/src/usage.ts
+++ b/grok-llm-proxy/src/usage.ts
@@ -4,7 +4,9 @@ export function parseSafeUsage(input: unknown): SafeUsage | undefined {
if (!input || typeof input !== 'object' || Array.isArray(input)) return undefined
const row = input as Record<string, unknown>
const inputTokens = asNonNegativeInt(row.input_tokens ?? row.inputTokens ?? row.prompt_tokens)
- const outputTokens = asNonNegativeInt(row.output_tokens ?? row.outputTokens ?? row.completion_tokens)
+ const outputTokens = asNonNegativeInt(
+ row.output_tokens ?? row.outputTokens ?? row.completion_tokens
+ )
if (inputTokens === undefined && outputTokens === undefined) return undefined
const usage: SafeUsage = {}
if (inputTokens !== undefined) usage.inputTokens = inputTokens
@@ -13,7 +15,12 @@ export function parseSafeUsage(input: unknown): SafeUsage | undefined {
}
function asNonNegativeInt(value: unknown): number | undefined {
- if (typeof value !== 'number' || !Number.isFinite(value) || !Number.isInteger(value) || value < 0) {
+ if (
+ typeof value !== 'number' ||
+ !Number.isFinite(value) ||
+ !Number.isInteger(value) ||
+ value < 0
+ ) {
return undefined
}
return value
diff --git a/grok-llm-proxy/test/abortWhenClientDisconnects.test.ts b/grok-llm-proxy/test/abortWhenClientDisconnects.test.ts
index 7ada74ba6..67ebb86c7 100644
--- a/grok-llm-proxy/test/abortWhenClientDisconnects.test.ts
+++ b/grok-llm-proxy/test/abortWhenClientDisconnects.test.ts
@@ -1,5 +1,5 @@
-import { EventEmitter } from 'node:events'
import { describe, expect, it } from 'vitest'
+import { EventEmitter } from 'node:events'
import { abortWhenClientDisconnects } from '../src/server.js'
function fakeReqRes(): {
diff --git a/grok-llm-proxy/test/approvedToolsUpstream.test.ts b/grok-llm-proxy/test/approvedToolsUpstream.test.ts
index 3c5cb7eb5..5f12dcee0 100644
--- a/grok-llm-proxy/test/approvedToolsUpstream.test.ts
+++ b/grok-llm-proxy/test/approvedToolsUpstream.test.ts
@@ -321,9 +321,7 @@ describe('approved-tools isolated upstream boundary', () => {
it('accepts only the frozen catalog and completion operations without making network calls', async () => {
const simulator = createApprovedToolsUpstream()
- const catalog = await simulator.fetchFn(
- 'https://cli-chat-proxy.grok.com/v1/models'
- )
+ const catalog = await simulator.fetchFn('https://cli-chat-proxy.grok.com/v1/models')
expect(await catalog.json()).toMatchObject({ models: [{ slug: 'gpt-5.3-grok' }] })
for (const url of [
'http://cli-chat-proxy.grok.com/backend-api/grok/responses',
diff --git a/grok-llm-proxy/test/approvedToolsUpstream.ts b/grok-llm-proxy/test/approvedToolsUpstream.ts
index 608475c90..40358ddfe 100644
--- a/grok-llm-proxy/test/approvedToolsUpstream.ts
+++ b/grok-llm-proxy/test/approvedToolsUpstream.ts
@@ -49,10 +49,7 @@ type Exchange = { call: Row; args: Row; result: Row }
type Decision = { stage: string; args?: Row; result?: Row }
function expectedCall(exchange: Exchange, decision: Decision): void {
- if (
- exchange.call.name !== decision.stage ||
- !isDeepStrictEqual(exchange.args, decision.args)
- ) {
+ if (exchange.call.name !== decision.stage || !isDeepStrictEqual(exchange.args, decision.args)) {
throw new Error('unexpected_fixture_call')
}
}
diff --git a/grok-llm-proxy/test/contractFreeze.test.ts b/grok-llm-proxy/test/contractFreeze.test.ts
index 07322a8a7..cb9d43b1a 100644
--- a/grok-llm-proxy/test/contractFreeze.test.ts
+++ b/grok-llm-proxy/test/contractFreeze.test.ts
@@ -8,12 +8,12 @@ import {
LIMITS,
TRANSPORT_PROTOCOL_VERSION,
} from '@clerum/grok-provider-attempt-contract'
+import { GROK_UPSTREAM_USER_AGENT } from '../src/grokUpstreamHeaders.js'
import {
GROK_CATALOG_ORIGIN,
GROK_COMPLETIONS_ORIGIN,
GROK_TRANSPORT_PROTOCOL,
} from '../src/originPolicy.js'
-import { GROK_UPSTREAM_USER_AGENT } from '../src/grokUpstreamHeaders.js'
const here = dirname(fileURLToPath(import.meta.url))
const fixturePath = join(
diff --git a/grok-llm-proxy/test/controlApiClient.test.ts b/grok-llm-proxy/test/controlApiClient.test.ts
index da4bbe69b..b7c723e2e 100644
--- a/grok-llm-proxy/test/controlApiClient.test.ts
+++ b/grok-llm-proxy/test/controlApiClient.test.ts
@@ -1,5 +1,5 @@
-import { createServer, type IncomingMessage, type Server } from 'node:http'
import { describe, expect, it } from 'vitest'
+import { type IncomingMessage, type Server, createServer } from 'node:http'
import { ControlApiClient, ControlApiClientError } from '../src/controlApiClient.js'
const LOOPBACK_V4 = ['127', '0', '0', '1'].join('.')
@@ -85,11 +85,13 @@ describe('ControlApiClient', () => {
expect(second.accessToken).toBe('tok-live')
expect(seenTokens).toEqual(['ticket-1', 'ticket-2'])
expect(server.requests[0]?.headers['x-service-token']).toBe('grok-llm-proxy')
- expect(String(server.requests[0]?.headers.authorization)).toContain('dev-grok-llm-proxy-token')
- expect(server.requests[0]?.url).toBe('/api/v1/internal/llm/grok/provider-attempts/redeem')
- expect(server.requests.some(item => item.url === '/api/v1/internal/llm/provider-attempts/redeem')).toBe(
- false
+ expect(String(server.requests[0]?.headers.authorization)).toContain(
+ 'dev-grok-llm-proxy-token'
)
+ expect(server.requests[0]?.url).toBe('/api/v1/internal/llm/grok/provider-attempts/redeem')
+ expect(
+ server.requests.some(item => item.url === '/api/v1/internal/llm/provider-attempts/redeem')
+ ).toBe(false)
const finalized = await client.finalize({
attemptReceipt: 'a'.repeat(64),
@@ -109,7 +111,8 @@ describe('ControlApiClient', () => {
it('maps redeem failures to bounded codes and never retries an ambiguous attempt', async () => {
const server = await listen((req, _body, res) => {
- ;(res as unknown as { statusCode: number; setHeader: Function; end: Function }).statusCode = 409
+ ;(res as unknown as { statusCode: number; setHeader: Function; end: Function }).statusCode =
+ 409
;(res as unknown as { setHeader: Function }).setHeader('content-type', 'application/json')
;(res as unknown as { end: Function }).end(JSON.stringify({ error: 'ticket_replayed' }))
})
diff --git a/grok-llm-proxy/test/grokTransport.conformance.test.ts b/grok-llm-proxy/test/grokTransport.conformance.test.ts
index 017009577..bd4cb3294 100644
--- a/grok-llm-proxy/test/grokTransport.conformance.test.ts
+++ b/grok-llm-proxy/test/grokTransport.conformance.test.ts
@@ -3,8 +3,8 @@ import {
hashGrokCompletionRequestV1,
parseGrokCompletionRequestV1,
} from '@clerum/grok-provider-attempt-contract'
-import { GrokTransportError, streamGrokCompletion } from '../src/grokTransport.js'
import type { RedeemAttemptSuccess } from '../src/controlApiClient.js'
+import { GrokTransportError, streamGrokCompletion } from '../src/grokTransport.js'
import { GROK_COMPLETIONS_ORIGIN } from '../src/originPolicy.js'
const REQUEST = {
diff --git a/grok-llm-proxy/test/originPolicy.test.ts b/grok-llm-proxy/test/originPolicy.test.ts
index 6fe55d9da..fa57f4a6b 100644
--- a/grok-llm-proxy/test/originPolicy.test.ts
+++ b/grok-llm-proxy/test/originPolicy.test.ts
@@ -38,27 +38,35 @@ describe('originPolicy', () => {
expect(() =>
assertAllowedUpstreamUrl('https://api.x.ai/v1/chat/completions', 'completions')
).toThrow(OriginDeniedError)
- expect(() => assertAllowedUpstreamUrl('http://cli-chat-proxy.grok.com/backend-api/grok/responses', 'completions')).toThrow(
- /origin_denied/
- )
- expect(() => assertAllowedUpstreamUrl(`https://${LOOPBACK_V4}/backend-api/grok/responses`, 'completions')).toThrow(
+ expect(() =>
+ assertAllowedUpstreamUrl(
+ 'http://cli-chat-proxy.grok.com/backend-api/grok/responses',
+ 'completions'
+ )
+ ).toThrow(/origin_denied/)
+ expect(() =>
+ assertAllowedUpstreamUrl(`https://${LOOPBACK_V4}/backend-api/grok/responses`, 'completions')
+ ).toThrow(OriginDeniedError)
+ expect(() => assertAllowedUpstreamUrl('https://169.254.169.254/', 'catalog')).toThrow(
OriginDeniedError
)
- expect(() => assertAllowedUpstreamUrl('https://169.254.169.254/', 'catalog')).toThrow(OriginDeniedError)
expect(isBlockedAddress('100.64.0.1')).toBe(true)
expect(isBlockedAddress('198.18.0.1')).toBe(true)
expect(isBlockedAddress('198.19.255.1')).toBe(true)
expect(isBlockedAddress('64:ff9b::1')).toBe(true)
expect(isBlockedAddress('ff02::1')).toBe(true)
expect(() =>
- assertAllowedUpstreamUrl('https://cli-chat-proxy.grok.com/v1/responses?hijack=1', 'completions')
+ assertAllowedUpstreamUrl(
+ 'https://cli-chat-proxy.grok.com/v1/responses?hijack=1',
+ 'completions'
+ )
).toThrow(OriginDeniedError)
expect(() =>
assertAllowedUpstreamUrl('https://cli-chat-proxy.grok.com/v1/models?hijack=1', 'catalog')
).toThrow(OriginDeniedError)
- expect(() =>
- assertAllowedUpstreamUrl('https://api.x.ai/v1/responses', 'completions')
- ).toThrow(OriginDeniedError)
+ expect(() => assertAllowedUpstreamUrl('https://api.x.ai/v1/responses', 'completions')).toThrow(
+ OriginDeniedError
+ )
})
it('rejects cross-origin and private-address redirects', () => {
@@ -69,7 +77,10 @@ describe('originPolicy', () => {
assertRedirectLocation(`https://${LOOPBACK_V4}/loopback`, new URL(GROK_COMPLETIONS_ORIGIN))
).toThrow(OriginDeniedError)
expect(() =>
- assertRedirectLocation('http://cli-chat-proxy.grok.com/backend-api/grok/responses', new URL(GROK_COMPLETIONS_ORIGIN))
+ assertRedirectLocation(
+ 'http://cli-chat-proxy.grok.com/backend-api/grok/responses',
+ new URL(GROK_COMPLETIONS_ORIGIN)
+ )
).toThrow(OriginDeniedError)
expect(
assertRedirectLocation(
diff --git a/grok-llm-proxy/test/server.security.test.ts b/grok-llm-proxy/test/server.security.test.ts
index 0e8b17263..e7cddaffa 100644
--- a/grok-llm-proxy/test/server.security.test.ts
+++ b/grok-llm-proxy/test/server.security.test.ts
@@ -1,10 +1,10 @@
-import { generateKeyPairSync } from 'node:crypto'
+import { describe, expect, it } from 'vitest'
import jwt from 'jsonwebtoken'
+import { generateKeyPairSync } from 'node:crypto'
import request from 'supertest'
-import { describe, expect, it } from 'vitest'
import { verifyAdminPermit } from '../src/auth/adminPermitVerifier.js'
import { verifyExecutionTicket } from '../src/auth/executionTicketVerifier.js'
-import { loadConfig, type GrokLlmProxyConfig } from '../src/config.js'
+import { type GrokLlmProxyConfig, loadConfig } from '../src/config.js'
import { createProxyApps } from '../src/server.js'
const { privateKey, publicKey } = generateKeyPairSync('rsa', {
@@ -82,7 +82,9 @@ describe('grok-llm-proxy security surface', () => {
const metrics = await request(probeApp).get('/metrics')
expect(metrics.status).toBe(200)
expect(metrics.text).not.toMatch(/account|refresh|accessToken/i)
- expect((await request(runtimeApp).get('/internal/runtime/v1/grok/completions')).status).toBe(404)
+ expect((await request(runtimeApp).get('/internal/runtime/v1/grok/completions')).status).toBe(
+ 404
+ )
expect((await request(adminApp).get('/internal/admin/v1/grok/models')).status).toBe(404)
})
diff --git a/packages/grok-provider-attempt-contract/index.cjs b/packages/grok-provider-attempt-contract/index.cjs
index 1a794d6ea..93182c587 100644
--- a/packages/grok-provider-attempt-contract/index.cjs
+++ b/packages/grok-provider-attempt-contract/index.cjs
@@ -68,13 +68,14 @@ const CLAIMS_KEYS = new Set([
'connectionRevision',
'connectionId',
])
-const AUTHORIZE_KEYS = new Set([
+const AUTHORIZE_KEYS = new Set(['providerAttemptId', 'requestHash', 'executionTicket', 'expiresAt'])
+const RECEIPT_KEYS = new Set([
+ 'schemaVersion',
'providerAttemptId',
'requestHash',
- 'executionTicket',
- 'expiresAt',
+ 'outcome',
+ 'usage',
])
-const RECEIPT_KEYS = new Set(['schemaVersion', 'providerAttemptId', 'requestHash', 'outcome', 'usage'])
const USAGE_KEYS = new Set(['inputTokens', 'outputTokens'])
function fail(code, message) {
@@ -182,14 +183,16 @@ function parseMessages(raw) {
const extra = rejectUnknown(item, MESSAGE_KEYS, `messages[${i}]`)
if (extra) return extra
if (!MESSAGE_ROLES.has(item.role)) return fail('invalid', `messages[${i}].role is not allowed`)
- if (typeof item.content !== 'string') return fail('invalid', `messages[${i}].content must be a string`)
+ if (typeof item.content !== 'string')
+ return fail('invalid', `messages[${i}].content must be a string`)
const message = { role: item.role, content: item.content }
if (item.name !== undefined) {
if (!isToolName(item.name)) return fail('invalid', `messages[${i}].name is invalid`)
message.name = item.name
}
if (item.toolCallId !== undefined) {
- if (!isBoundedId(item.toolCallId)) return fail('invalid', `messages[${i}].toolCallId is invalid`)
+ if (!isBoundedId(item.toolCallId))
+ return fail('invalid', `messages[${i}].toolCallId is invalid`)
message.toolCallId = item.toolCallId
}
if (item.toolCalls !== undefined) {
@@ -409,7 +412,12 @@ function requireHex64(obj, key) {
function requireInt(obj, key, min) {
const value = obj[key]
- if (typeof value !== 'number' || !Number.isFinite(value) || !Number.isInteger(value) || value < min) {
+ if (
+ typeof value !== 'number' ||
+ !Number.isFinite(value) ||
+ !Number.isInteger(value) ||
+ value < min
+ ) {
return fail('non-finite', `${key} must be a finite integer`)
}
return null
@@ -419,7 +427,15 @@ function parseGrokExecutionTicketClaims(input) {
if (!isPlainObject(input)) return fail('invalid', 'ticket claims must be an object')
const extra = rejectUnknown(input, CLAIMS_KEYS, 'ticket claims')
if (extra) return extra
- for (const key of ['jti', 'sub', 'hostRef', 'invocationId', 'providerAttemptId', 'budgetReservationId', 'model']) {
+ for (const key of [
+ 'jti',
+ 'sub',
+ 'hostRef',
+ 'invocationId',
+ 'providerAttemptId',
+ 'budgetReservationId',
+ 'model',
+ ]) {
const bad = requireId(input, key)
if (bad) return bad
}
diff --git a/packages/llm-providers/index.d.ts b/packages/llm-providers/index.d.ts
index ac42965b9..2635874cd 100644
--- a/packages/llm-providers/index.d.ts
+++ b/packages/llm-providers/index.d.ts
@@ -89,7 +89,7 @@ export declare function isLlmProviderId(s: unknown): s is LlmProviderId
*/
export declare function isCredentialSlotOwnedByProvider(
provider: string,
- credentialSlot: string,
+ credentialSlot: string
): boolean
export type ProviderAuthMode = 'static-credentials' | 'oauth-broker'
@@ -113,12 +113,12 @@ export declare const PROVIDER_MODEL_CATALOG_MODE: Record<LlmProviderId, Provider
export declare const OAUTH_BROKER_IDS: readonly ['codex-subscription', 'grok-subscription']
export declare function buildProviderMaps(
ids: readonly string[],
- brokerIds: readonly string[],
+ brokerIds: readonly string[]
): {
PROVIDER_AUTH_MODE: Readonly<Record<string, ProviderAuthMode>>
PROVIDER_MODEL_CATALOG_MODE: Readonly<Record<string, ProviderModelCatalogMode>>
}
export declare function providerDescriptor(id: LlmProviderId): ProviderDescriptor
export declare function requireStaticCredentialSlot(
- descriptor: Pick<ProviderDescriptor, 'authMode' | 'credentialSlots'>,
+ descriptor: Pick<ProviderDescriptor, 'authMode' | 'credentialSlots'>
): CredentialSlot