Skip to content

Add "turbo types" command to codegen all types, don't generate env types via wrangler types #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2025
Merged
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
3 changes: 1 addition & 2 deletions apps/docs-autorag/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"deploy": "run-wrangler-deploy",
"dev": "wrangler dev",
"start": "wrangler dev",
"cf-typegen": "wrangler types",
"types": "wrangler types --include-env=false",
"test": "vitest run"
},
"dependencies": {
Expand All @@ -25,7 +25,6 @@
},
"devDependencies": {
"@cloudflare/vitest-pool-workers": "0.8.14",
"@cloudflare/workers-types": "4.20250414.0",
"@types/node": "22.14.1",
"prettier": "3.5.3",
"typescript": "5.5.4",
Expand Down
11 changes: 11 additions & 0 deletions apps/docs-autorag/src/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { CloudflareDocumentationMCP } from './index'

export interface Env {
ENVIRONMENT: 'development' | 'staging' | 'production'
AUTORAG_NAME: 'cloudflare-docs-autorag'
MCP_SERVER_NAME: 'PLACEHOLDER'
MCP_SERVER_VERSION: 'PLACEHOLDER'
MCP_OBJECT: DurableObjectNamespace<CloudflareDocumentationMCP>
MCP_METRICS: AnalyticsEngineDataset
AI: Ai
}
6 changes: 5 additions & 1 deletion apps/docs-autorag/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { McpAgent } from 'agents/mcp'
import { env } from 'cloudflare:workers'

import { getEnv } from '@repo/mcp-common/src/env'
import { CloudflareMCPServer } from '@repo/mcp-common/src/server'

import { registerDocsTools } from './tools/docs'

import type { Env } from './context'

const env = getEnv<Env>()

// The docs MCP server isn't stateful, so we don't have state/props
export type Props = never

Expand Down
2 changes: 2 additions & 0 deletions apps/docs-autorag/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config'

import type { Env } from './src/context'

export interface TestEnv extends Env {
CLOUDFLARE_MOCK_ACCOUNT_ID: string
CLOUDFLARE_MOCK_API_TOKEN: string
Expand Down
111 changes: 35 additions & 76 deletions apps/docs-autorag/worker-configuration.d.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
/* eslint-disable */
// Generated by Wrangler by running `wrangler types` (hash: 23bfeb1ecdb06845b72c16f50728901d)
// Runtime types generated with [email protected] 2025-03-10 nodejs_compat
declare namespace Cloudflare {
interface Env {
ENVIRONMENT: "development" | "staging" | "production";
AUTORAG_NAME: "cloudflare-docs-autorag";
MCP_SERVER_NAME: "PLACEHOLDER";
MCP_SERVER_VERSION: "PLACEHOLDER";
MCP_OBJECT: DurableObjectNamespace<import("./src/index").CloudflareDocumentationMCP>;
MCP_METRICS: AnalyticsEngineDataset;
AI: Ai;
}
}
interface Env extends Cloudflare.Env {}

// Runtime types generated with [email protected] 2025-03-10 nodejs_compat
// Begin runtime types
/*! *****************************************************************************
Copyright (c) Cloudflare. All rights reserved.
Expand Down Expand Up @@ -1603,11 +1588,11 @@ interface R2PutOptions {
onlyIf?: (R2Conditional | Headers);
httpMetadata?: (R2HTTPMetadata | Headers);
customMetadata?: Record<string, string>;
md5?: ((ArrayBuffer | ArrayBufferView) | string);
sha1?: ((ArrayBuffer | ArrayBufferView) | string);
sha256?: ((ArrayBuffer | ArrayBufferView) | string);
sha384?: ((ArrayBuffer | ArrayBufferView) | string);
sha512?: ((ArrayBuffer | ArrayBufferView) | string);
md5?: (ArrayBuffer | string);
sha1?: (ArrayBuffer | string);
sha256?: (ArrayBuffer | string);
sha384?: (ArrayBuffer | string);
sha512?: (ArrayBuffer | string);
storageClass?: string;
ssecKey?: (ArrayBuffer | string);
}
Expand Down Expand Up @@ -2202,7 +2187,7 @@ declare class URLSearchParams {
]>;
}
declare class URLPattern {
constructor(input?: (string | URLPatternInit), baseURL?: (string | URLPatternOptions), patternOptions?: URLPatternOptions);
constructor(input?: (string | URLPatternURLPatternInit), baseURL?: (string | URLPatternURLPatternOptions), patternOptions?: URLPatternURLPatternOptions);
get protocol(): string;
get username(): string;
get password(): string;
Expand All @@ -2211,10 +2196,10 @@ declare class URLPattern {
get pathname(): string;
get search(): string;
get hash(): string;
test(input?: (string | URLPatternInit), baseURL?: string): boolean;
exec(input?: (string | URLPatternInit), baseURL?: string): URLPatternResult | null;
test(input?: (string | URLPatternURLPatternInit), baseURL?: string): boolean;
exec(input?: (string | URLPatternURLPatternInit), baseURL?: string): URLPatternURLPatternResult | null;
}
interface URLPatternInit {
interface URLPatternURLPatternInit {
protocol?: string;
username?: string;
password?: string;
Expand All @@ -2225,22 +2210,22 @@ interface URLPatternInit {
hash?: string;
baseURL?: string;
}
interface URLPatternComponentResult {
interface URLPatternURLPatternComponentResult {
input: string;
groups: Record<string, string>;
}
interface URLPatternResult {
inputs: (string | URLPatternInit)[];
protocol: URLPatternComponentResult;
username: URLPatternComponentResult;
password: URLPatternComponentResult;
hostname: URLPatternComponentResult;
port: URLPatternComponentResult;
pathname: URLPatternComponentResult;
search: URLPatternComponentResult;
hash: URLPatternComponentResult;
}
interface URLPatternOptions {
interface URLPatternURLPatternResult {
inputs: (string | URLPatternURLPatternInit)[];
protocol: URLPatternURLPatternComponentResult;
username: URLPatternURLPatternComponentResult;
password: URLPatternURLPatternComponentResult;
hostname: URLPatternURLPatternComponentResult;
port: URLPatternURLPatternComponentResult;
pathname: URLPatternURLPatternComponentResult;
search: URLPatternURLPatternComponentResult;
hash: URLPatternURLPatternComponentResult;
}
interface URLPatternURLPatternOptions {
ignoreCase?: boolean;
}
/**
Expand Down Expand Up @@ -2396,8 +2381,6 @@ interface Socket {
get writable(): WritableStream;
get closed(): Promise<void>;
get opened(): Promise<SocketInfo>;
get upgraded(): boolean;
get secureTransport(): "on" | "off" | "starttls";
close(): Promise<void>;
startTls(options?: TlsOptions): Socket;
}
Expand Down Expand Up @@ -3724,21 +3707,13 @@ declare abstract class Ai<AiModelList extends AiModelListType = AiModels> {
extraHeaders?: object;
}): Promise<ConversionResponse>;
}
type GatewayRetries = {
maxAttempts?: 1 | 2 | 3 | 4 | 5;
retryDelayMs?: number;
backoff?: 'constant' | 'linear' | 'exponential';
};
type GatewayOptions = {
id: string;
cacheKey?: string;
cacheTtl?: number;
skipCache?: boolean;
metadata?: Record<string, number | string | boolean | null | bigint>;
collectLog?: boolean;
eventId?: string;
requestTimeoutMs?: number;
retries?: GatewayRetries;
};
type AiGatewayPatchLog = {
score?: number | null;
Expand Down Expand Up @@ -3772,26 +3747,21 @@ type AiGatewayLog = {
response_head_complete: boolean;
created_at: Date;
};
type AIGatewayProviders = 'workers-ai' | 'anthropic' | 'aws-bedrock' | 'azure-openai' | 'google-vertex-ai' | 'huggingface' | 'openai' | 'perplexity-ai' | 'replicate' | 'groq' | 'cohere' | 'google-ai-studio' | 'mistral' | 'grok' | 'openrouter' | 'deepseek' | 'cerebras' | 'cartesia' | 'elevenlabs' | 'adobe-firefly';
type AIGatewayProviders = "workers-ai" | "anthropic" | "aws-bedrock" | "azure-openai" | "google-vertex-ai" | "huggingface" | "openai" | "perplexity-ai" | "replicate" | "groq" | "cohere" | "google-ai-studio" | "mistral" | "grok" | "openrouter" | "deepseek" | "cerebras" | "cartesia" | "elevenlabs" | "adobe-firefly";
type AIGatewayHeaders = {
'cf-aig-metadata': Record<string, number | string | boolean | null | bigint> | string;
'cf-aig-custom-cost': {
"cf-aig-metadata": Record<string, number | string | boolean | null | bigint> | string;
"cf-aig-custom-cost": {
per_token_in?: number;
per_token_out?: number;
} | {
total_cost?: number;
} | string;
'cf-aig-cache-ttl': number | string;
'cf-aig-skip-cache': boolean | string;
'cf-aig-cache-key': string;
'cf-aig-event-id': string;
'cf-aig-request-timeout': number | string;
'cf-aig-max-attempts': number | string;
'cf-aig-retry-delay': number | string;
'cf-aig-backoff': string;
'cf-aig-collect-log': boolean | string;
"cf-aig-cache-ttl": number | string;
"cf-aig-skip-cache": boolean | string;
"cf-aig-cache-key": string;
"cf-aig-collect-log": boolean | string;
Authorization: string;
'Content-Type': string;
"Content-Type": string;
[key: string]: string | number | boolean | object;
};
type AIGatewayUniversalRequest = {
Expand All @@ -3807,10 +3777,7 @@ interface AiGatewayLogNotFound extends Error {
declare abstract class AiGateway {
patchLog(logId: string, data: AiGatewayPatchLog): Promise<void>;
getLog(logId: string): Promise<AiGatewayLog>;
run(data: AIGatewayUniversalRequest | AIGatewayUniversalRequest[], options?: {
gateway?: GatewayOptions;
extraHeaders?: object;
}): Promise<Response>;
run(data: AIGatewayUniversalRequest | AIGatewayUniversalRequest[]): Promise<Response>;
getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
}
interface AutoRAGInternalError extends Error {
Expand All @@ -3828,22 +3795,16 @@ type AutoRagSearchRequest = {
};
rewrite_query?: boolean;
};
type AutoRagAiSearchRequest = AutoRagSearchRequest & {
stream?: boolean;
};
type AutoRagAiSearchRequestStreaming = Omit<AutoRagAiSearchRequest, 'stream'> & {
stream: true;
};
type AutoRagSearchResponse = {
object: 'vector_store.search_results.page';
object: "vector_store.search_results.page";
search_query: string;
data: {
file_id: string;
filename: string;
score: number;
attributes: Record<string, string | number | boolean | null>;
content: {
type: 'text';
type: "text";
text: string;
}[];
}[];
Expand All @@ -3855,9 +3816,7 @@ type AutoRagAiSearchResponse = AutoRagSearchResponse & {
};
declare abstract class AutoRAG {
search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
aiSearch(params: AutoRagAiSearchRequestStreaming): Promise<Response>;
aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse>;
aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse | Response>;
aiSearch(params: AutoRagSearchRequest): Promise<AutoRagAiSearchResponse>;
}
interface BasicImageTransformations {
/**
Expand Down
3 changes: 0 additions & 3 deletions apps/sandbox-container/evals/env.d.ts

This file was deleted.

3 changes: 1 addition & 2 deletions apps/sandbox-container/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
"start:container": "tsx container/index.ts",
"postinstall": "mkdir -p workdir",
"test": "vitest",
"types": "wrangler types",
"types": "wrangler types --include-env=false",
"eval:dev": "start-server-and-test --expect 404 eval:server http://localhost:8976 'vitest --testTimeout=60000 --config vitest.config.evals.ts'",
"eval:server": "concurrently \"tsx container/index.ts\" \"wrangler dev --var \"ENVIRONMENT:test\"\"",
"eval:ci": "start-server-and-test --expect 404 eval:server http://localhost:8976 'vitest run --testTimeout=60000 --config vitest.config.evals.ts'"
},
"dependencies": {
"@cloudflare/workers-oauth-provider": "0.0.2",
"@cloudflare/workers-types": "4.20250414.0",
"@hono/node-server": "1.13.8",
"@hono/zod-validator": "0.4.3",
"@modelcontextprotocol/sdk": "1.9.0",
Expand Down
2 changes: 2 additions & 0 deletions apps/sandbox-container/server/containerManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { DurableObject } from 'cloudflare:workers'

import type { Env } from './context'

export class ContainerManager extends DurableObject<Env> {
constructor(
public ctx: DurableObjectState,
Expand Down
1 change: 1 addition & 0 deletions apps/sandbox-container/server/containerMcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { BASE_INSTRUCTIONS } from './prompts'
import { fileToBase64, stripProtocolFromFilePath } from './utils'

import type { FileList } from '../shared/schema'
import type { Env } from './context'
import type { Props } from '.'

export class ContainerMcpAgent extends McpAgent<Env, {}, Props> {
Expand Down
15 changes: 15 additions & 0 deletions apps/sandbox-container/server/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { ContainerManager, ContainerMcpAgent } from './index'

export interface Env {
OAUTH_KV: KVNamespace
CLOUDFLARE_CLIENT_ID: '<PLACEHOLDER>'
CLOUDFLARE_CLIENT_SECRET: '<PLACEHOLDER>'
ENVIRONMENT: 'dev'
MCP_SERVER_NAME: '<PLACEHOLDER>'
MCP_SERVER_VERSION: '<PLACEHOLDER>'
OPENAI_API_KEY: string
CONTAINER_MCP_AGENT: DurableObjectNamespace<ContainerMcpAgent>
CONTAINER_MANAGER: DurableObjectNamespace<ContainerManager>
MCP_METRICS: AnalyticsEngineDataset
AI: Ai
}
7 changes: 5 additions & 2 deletions apps/sandbox-container/server/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import OAuthProvider from '@cloudflare/workers-oauth-provider'
import { McpAgent } from 'agents/mcp'
import { env } from 'cloudflare:workers'

import {
createAuthHandlers,
handleTokenExchangeCallback,
} from '@repo/mcp-common/src/cloudflare-oauth-handler'
import { getEnv } from '@repo/mcp-common/src/env'
import { MetricsTracker } from '@repo/mcp-observability'

import { ContainerManager } from './containerManager'
import { ContainerMcpAgent } from './containerMcp'

import type { McpAgent } from 'agents/mcp'
import type { AccountSchema, UserSchema } from '@repo/mcp-common/src/cloudflare-oauth-handler'
import type { Env } from './context'

export { ContainerManager, ContainerMcpAgent }

const env = getEnv<Env>()

const metrics = new MetricsTracker(env.MCP_METRICS, {
name: env.MCP_SERVER_NAME,
version: env.MCP_SERVER_VERSION,
Expand Down
2 changes: 1 addition & 1 deletion apps/sandbox-container/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@repo/typescript-config/workers.json",
"include": ["*/**.ts", "./vitest.config.evals.ts"],
"include": ["*/**.ts", "./vitest.config.evals.ts", "./types.d.ts"],
"exclude": ["container/**.ts"]
}
6 changes: 6 additions & 0 deletions apps/sandbox-container/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare module 'cloudflare:test' {
interface ProvidedEnv {
OPENAI_API_KEY: 'TODO'
AI: Ai
}
}
Loading