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
155 changes: 91 additions & 64 deletions bun.lock

Large diffs are not rendered by default.

31 changes: 21 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,23 @@
"dependencies": {
"@alcalzone/ansi-tokenize": "0.3.0",
"@anthropic-ai/bedrock-sdk": "0.29.1",
"@anthropic-ai/sandbox-runtime": "0.0.46",
"@anthropic-ai/sandbox-runtime": "0.0.81",
"@anthropic-ai/sdk": "0.91.1",
"@aws-sdk/client-bedrock": "^3.1045.0",
"@aws-sdk/client-bedrock-runtime": "^3.1045.0",
"@aws-sdk/client-sts": "^3.1045.0",
"@aws-sdk/credential-providers": "^3.1045.0",
"@commander-js/extra-typings": "12.1.0",
"@grpc/grpc-js": "^1.14.3",
"@grpc/grpc-js": "^1.14.7",
"@grpc/proto-loader": "^0.8.0",
"@mendable/firecrawl-js": "4.23.0",
"@modelcontextprotocol/sdk": "1.29.0",
"@mendable/firecrawl-js": "4.51.0",
"@modelcontextprotocol/sdk": "1.32.2",
"@orama/orama": "^3.1.18",
"@orama/plugin-data-persistence": "^3.1.18",
"@vscode/ripgrep": "^1.17.1",
"ajv": "8.18.0",
"auto-bind": "5.0.1",
"axios": "1.15.2",
"axios": "1.21.0",
"bidi-js": "1.0.3",
"chalk": "5.6.2",
"chokidar": "4.0.3",
Expand Down Expand Up @@ -131,22 +131,22 @@
"react-compiler-runtime": "1.0.0",
"react-reconciler": "0.33.0",
"semver": "7.7.4",
"sharp": "^0.34.5",
"sharp": "^0.35.5",
"shell-quote": "1.8.3",
"signal-exit": "4.1.0",
"strip-ansi": "7.2.0",
"supports-hyperlinks": "3.2.0",
"tree-kill": "1.2.2",
"turndown": "7.2.2",
"type-fest": "4.41.0",
"undici": "7.24.6",
"undici": "7.30.1",
"usehooks-ts": "3.1.1",
"vscode-languageserver-protocol": "3.17.5",
"wrap-ansi": "9.0.2",
"ws": "8.20.0",
"ws": "8.22.1",
"xss": "1.0.15",
"yaml": "2.8.3",
"zod": "3.25.76"
"zod": "4.6.7"
},
"devDependencies": {
"@mswjs/interceptors": "0.42.4",
Expand Down Expand Up @@ -185,6 +185,17 @@
"access": "public"
},
"overrides": {
"lodash-es": "4.18.1"
"lodash-es": "4.18.1",
"axios": "1.21.0",
"body-parser": "2.4.0",
"brace-expansion": "2.1.7",
"fast-uri": "3.1.9",
"follow-redirects": "1.16.2",
"hono": "4.13.16",
"ip-address": "10.7.6",
"protobufjs": "7.6.6",
"proxy-addr": "2.0.8",
"qs": "6.17.1",
"zod": "4.6.7"
}
}
2 changes: 1 addition & 1 deletion src/entrypoints/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export async function startMCPServer(
content: [
{
type: 'text',
text: `Tool ${name} input is invalid:\n${error.errors.map(e => `- ${e.path.join('.')}: ${e.message}`).join('\n')}`,
text: `Tool ${name} input is invalid:\n${error.issues.map(e => `- ${e.path.join('.')}: ${e.message}`).join('\n')}`,
},
],
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/api/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {

const bootstrapResponseSchema = lazySchema(() =>
z.object({
client_data: z.record(z.unknown()).nullish(),
client_data: z.record(z.string(), z.unknown()).nullish(),
additional_model_options: z
.array(
z
Expand Down
33 changes: 33 additions & 0 deletions src/services/api/codexShim.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2405,3 +2405,36 @@ describe('convertSystemPrompt', () => {
)
})
})

test('strict tool schemas turn oneOf into anyOf, as zod 4 emits for discriminated unions', () => {
const [tool] = convertToolsToResponsesTools([
{
name: 'SendMessage',
description: 'd',
input_schema: {
type: 'object',
properties: {
message: {
anyOf: [
{ type: 'string' },
{
oneOf: [
{
type: 'object',
properties: { type: { type: 'string', const: 'shutdown_request' } },
required: ['type'],
additionalProperties: false,
},
],
},
],
},
},
required: ['message'],
additionalProperties: false,
},
},
])
expect(JSON.stringify(tool?.parameters)).not.toContain('oneOf')
expect(JSON.stringify(tool?.parameters)).toContain('shutdown_request')
})
10 changes: 10 additions & 0 deletions src/services/api/codexShim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,16 @@ function enforceStrictSchema(schema: unknown): Record<string, unknown> {
}
}

// VERBOO-BRAND: strict function schemas only document anyOf, and zod 4 emits
// oneOf for discriminated unions (the SendMessage tool, for one).
if (Array.isArray(record.oneOf)) {
record.anyOf = [
...(Array.isArray(record.anyOf) ? record.anyOf : []),
...record.oneOf,
]
delete record.oneOf
}

// Recurse into combinators
for (const key of ['anyOf', 'oneOf', 'allOf'] as const) {
if (key in record && Array.isArray(record[key])) {
Expand Down
24 changes: 12 additions & 12 deletions src/services/api/verbooCheckout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ const checkoutResultSchema = z.discriminatedUnion('mode', [
z
.object({
mode: z.literal('stripe'),
attemptId: z.string().uuid(),
attemptId: z.guid(),
url: httpUrlSchema,
})
.passthrough(),
z
.object({
mode: z.literal('woovi'),
attemptId: z.string().uuid(),
attemptId: z.guid(),
wooviQrCode: z.string().min(1),
wooviSubscriptionId: z.string().min(1),
})
Expand All @@ -44,7 +44,7 @@ const checkoutInputSchema = z
.object({
paymentMethod: z.enum(['stripe', 'woovi']),
billingInterval: z.enum(['month', 'year']).optional(),
requestId: z.string().uuid().optional(),
requestId: z.guid().optional(),
purchaseIntent: z.enum(['new', 'additional']).optional(),
woovi: z
.object({
Expand Down Expand Up @@ -101,7 +101,7 @@ const cardlessTrialInputSchema = z.discriminatedUnion('useVerifiedPhone', [
const verificationRequiredSchema = z
.object({
mode: z.literal('verification_required'),
verificationId: z.string().uuid(),
verificationId: z.guid(),
maskedPhone: z.string().min(1),
expiresAt: z.string().datetime({ offset: true }),
resendAt: z.string().datetime({ offset: true }),
Expand All @@ -112,7 +112,7 @@ const verificationRequiredSchema = z
const trialActivatedSchema = z
.object({
mode: z.literal('trial_activated'),
groupId: z.string().uuid(),
groupId: z.guid(),
status: z.literal('trialing'),
})
.passthrough()
Expand Down Expand Up @@ -148,7 +148,7 @@ function actorScope(accessToken: string): string {
let actor = accessToken
try {
const claims = JSON.parse(Buffer.from(accessToken.split('.')[1] ?? '', 'base64url').toString('utf8'))
if (typeof claims.sub === 'string' && z.string().uuid().safeParse(claims.sub).success) actor = claims.sub
if (typeof claims.sub === 'string' && z.guid().safeParse(claims.sub).success) actor = claims.sub
} catch { /* Opaque tokens remain bound to their exact authenticated token. */ }
return createHash('sha256').update(actor).digest('hex')
}
Expand Down Expand Up @@ -210,7 +210,7 @@ export async function getPurchaseOptions(accessToken: string, groupId: string, b
const observation = commercialOperation('catalog', undefined, actorScope(accessToken))
try {
const response = await commercialGet(`${VERBOO_API_BASE_URL}/api/me/groups/${groupId}/purchase-options`, {headers: {...authHeaders(accessToken), ...observation.headers},params: {billingInterval},timeout: 10_000})
const result = parseApiEnvelope(z.object({version: z.literal(1),groupId: z.string().uuid(),billingInterval: z.enum(['month', 'year']),recommendation: z.enum(['checkout', 'choose', 'change', 'manage', 'convert', 'resume', 'recover', 'support'])}),response.data,'opções de compra')
const result = parseApiEnvelope(z.object({version: z.literal(1),groupId: z.guid(),billingInterval: z.enum(['month', 'year']),recommendation: z.enum(['checkout', 'choose', 'change', 'manage', 'convert', 'resume', 'recover', 'support'])}),response.data,'opções de compra')
if (result.groupId !== groupId || result.billingInterval !== billingInterval) throw new VerbooApiError({kind:'contract',code:'contract_error',message:'Opções de compra incompatíveis.'})
observation.complete();return result
} catch (error) {observation.fail(error);throw toVerbooApiError(error,'Não foi possível consultar as opções de compra.')}
Expand All @@ -219,7 +219,7 @@ export async function isPurchaseAttemptSucceeded(accessToken: string, attemptId:
const observation = commercialOperation('payment_return', attemptId, actorScope(accessToken))
try {
const response = await commercialGet(`${VERBOO_API_BASE_URL}/api/me/purchase-attempts/${attemptId}`, {headers: {...authHeaders(accessToken), ...observation.headers},signal,timeout:10_000})
const attempt = parseApiEnvelope(z.object({id:z.string().uuid(),groupId:z.string().uuid(),status:z.enum(['pending','requires_action','succeeded','failed','expired','review'])}),response.data,'confirmação da compra')
const attempt = parseApiEnvelope(z.object({id:z.guid(),groupId:z.guid(),status:z.enum(['pending','requires_action','succeeded','failed','expired','review'])}),response.data,'confirmação da compra')
if (attempt.id !== attemptId || attempt.groupId !== groupId) throw new VerbooApiError({kind:'contract',code:'contract_error',message:'Identidade de compra incompatível.'})
if (['failed','expired','review'].includes(attempt.status)) throw new VerbooApiError({kind:'request',code:`purchase_attempt_${attempt.status}`,message:'A compra exige revisão no billing.'})
observation.complete();return attempt.status === 'succeeded'
Expand All @@ -234,7 +234,7 @@ export async function createCheckoutSession(
const requestId = checkoutRequest(accessToken,groupId,input)
let request: z.infer<typeof checkoutInputSchema>
try {
parseRequest(z.string().uuid(), groupId, 'checkout')
parseRequest(z.guid(), groupId, 'checkout')
request = parseRequest(checkoutInputSchema, {...input, requestId, purchaseIntent: input.purchaseIntent ?? 'new'}, 'checkout')
} catch (error) { commercialOperation('checkout_request', requestId, actorScope(accessToken)).fail(error); throw error }
return postAndParse(
Expand Down Expand Up @@ -287,7 +287,7 @@ export async function startCardlessTrial(
groupId: string,
input: CardlessTrialInput,
): Promise<CardlessTrialResult> {
parseRequest(z.string().uuid(), groupId, 'trial')
parseRequest(z.guid(), groupId, 'trial')
const request = parseRequest(cardlessTrialInputSchema, input, 'trial')
return postAndParse(
`${VERBOO_API_BASE_URL}/api/me/groups/${groupId}/cardless-trial`,
Expand All @@ -303,7 +303,7 @@ export async function confirmCardlessTrial(
verificationId: string,
code: string,
): Promise<CardlessTrialResult> {
parseRequest(z.string().uuid(), verificationId, 'confirmação do trial')
parseRequest(z.guid(), verificationId, 'confirmação do trial')
const request = parseRequest(
z.object({ code: z.string().regex(/^\d{6}$/) }),
{ code },
Expand All @@ -322,7 +322,7 @@ export async function resendCardlessTrialCode(
accessToken: string,
verificationId: string,
): Promise<z.infer<typeof verificationRequiredSchema>> {
parseRequest(z.string().uuid(), verificationId, 'reenvio do código')
parseRequest(z.guid(), verificationId, 'reenvio do código')
return postAndParse(
`${VERBOO_API_BASE_URL}/api/me/cardless-trial-verifications/${verificationId}/resend`,
accessToken,
Expand Down
8 changes: 4 additions & 4 deletions src/services/api/verbooFeedback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { withOAuth401Retry } from '../../utils/http.js'
import { parseApiEnvelope } from './verbooApiError.js'

const optionSchema = z.object({
id: z.string().uuid(),
id: z.guid(),
position: z.number().int().min(1).max(9),
label: z.string().min(1).max(300),
})

const questionSchema = z.object({
id: z.string().uuid(),
id: z.guid(),
position: z.number().int().min(1).max(5),
type: z.enum(['single_choice', 'multiple_choice']),
text: z.string().min(1).max(500),
Expand All @@ -26,8 +26,8 @@ const questionSchema = z.object({
})

const offerSchema = z.object({
deliveryId: z.string().uuid(),
campaignId: z.string().uuid(),
deliveryId: z.guid(),
campaignId: z.guid(),
title: z.string().min(1).max(200),
intro: z.string().max(1000),
locale: z.enum(['pt', 'en']),
Expand Down
6 changes: 3 additions & 3 deletions src/services/api/verbooFreeTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ export const freeTokenStatusSchema = z.object({
eligible: z.boolean(),
state: z.enum(['unavailable', 'eligible', 'pending_setup', 'active', 'exhausted', 'activating', 'checkout_required', 'converted']),
tokenLimit: z.number().int().nonnegative(), tokensUsed: z.number().int().nonnegative(), tokensRemaining: z.number().int().nonnegative(),
groupId: z.string().uuid().optional(), subscriptionId: z.string().uuid().optional(),
groupId: z.guid().optional(), subscriptionId: z.guid().optional(),
billingInterval: z.enum(['month', 'year']).optional(), accountingPending: z.boolean(),
accountingBlocked: z.boolean().optional(),
accountingOpenRequests: z.number().int().nonnegative().optional(),
accountingRequestLimit: z.number().int().min(1).max(100).optional(),
activationUrl: z.string().url(), checkoutUrl: z.string().url().optional(), attemptId: z.string().uuid().optional(),
activationUrl: z.string().url(), checkoutUrl: z.string().url().optional(), attemptId: z.guid().optional(),
})
export const freeTokenQuoteSchema = z.object({
token: z.string().min(1), groupId: z.string().uuid(), groupName: z.string(),
token: z.string().min(1), groupId: z.guid(), groupName: z.string(),
amountCents: z.number().int().nonnegative(), renewalAmountCents: z.number().int().nonnegative(),
currency: z.string().length(3), billingInterval: z.enum(['month', 'year']), expiresAt: z.string().datetime({ offset: true }),
})
Expand Down
2 changes: 1 addition & 1 deletion src/services/api/verbooMarketplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const paymentProviderSchema = z

const marketplaceGroupSchema = z
.object({
id: z.string().uuid(),
id: z.guid(),
name: z.string().min(1),
slug: z.string().min(1),
description: z.string().optional(),
Expand Down
4 changes: 2 additions & 2 deletions src/services/api/verbooModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export type VerbooRouterCapabilities = {

const modelsResponseSchema = z
.object({
data: z.array(z.record(z.unknown())),
agent_model_roles: z.record(z.unknown()).optional(),
data: z.array(z.record(z.string(), z.unknown())),
agent_model_roles: z.record(z.string(), z.unknown()).optional(),
capabilities: z.unknown().optional(),
})
.passthrough()
Expand Down
6 changes: 3 additions & 3 deletions src/services/api/verbooSubscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export const subscriptionSourceSchema = z.union([

const subscriptionSchema = z
.object({
id: z.string().uuid(),
groupId: z.string().uuid(),
id: z.guid(),
groupId: z.guid(),
group: z
.object({
id: z.string().uuid(),
id: z.guid(),
name: z.string().min(1),
slug: z.string().min(1),
priceCents: z.number().int().nonnegative(),
Expand Down
4 changes: 2 additions & 2 deletions src/services/api/verbooUsageWindows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { parseApiEnvelope } from './verbooApiError.js'
import { readWithRetry, retryableReadStatus, retryAfterMilliseconds } from './readRetry.js'

export const usageWindowsSchema = z.array(z.object({
groupId: z.string().uuid(), groupName: z.string(), limited: z.boolean(), blocked: z.boolean(), accountingPending: z.boolean(), availableAt: z.string().nullable(),
windows: z.array(z.object({ id: z.string().uuid(), durationSeconds: z.number().int().positive(), usedPercent: z.number().min(0).max(100), resetsAt: z.string().nullable() })),
groupId: z.guid(), groupName: z.string(), limited: z.boolean(), blocked: z.boolean(), accountingPending: z.boolean(), availableAt: z.string().nullable(),
windows: z.array(z.object({ id: z.guid(), durationSeconds: z.number().int().positive(), usedPercent: z.number().min(0).max(100), resetsAt: z.string().nullable() })),
}))
export type UsageWindowsStatus = z.infer<typeof usageWindowsSchema>
export async function fetchUsageWindows(signal?: AbortSignal): Promise<UsageWindowsStatus> {
Expand Down
5 changes: 5 additions & 0 deletions src/services/mcp/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ import type {
ServerResource,
} from './types.js'

const MCP_STDIO_MAX_MESSAGE_BYTES = 256 * 1024 * 1024

/**
* Custom error class to indicate that an MCP tool call failed due to
* authentication issues (e.g., expired OAuth token returning 401).
Expand Down Expand Up @@ -977,6 +979,9 @@ export const connectToServer = memoize(
...serverRef.env,
} as Record<string, string>,
stderr: 'pipe', // prevents error output from the MCP server from printing to the UI
// VERBOO-BRAND: SDK 1.32 closes the server on a message above 10 MB.
// Larger results used to arrive and be saved to a file by the CLI.
maxBufferSize: MCP_STDIO_MAX_MESSAGE_BYTES,
})
} else {
throw new Error(`Unsupported server type: ${serverRef.type}`)
Expand Down
Loading