Skip to content

Commit 616322c

Browse files
authored
Add "turbo types" command to codegen all types, don't generate env types and instead use dedicated context files which define env types in each app. (#77)
- Add helper in mcp-common to cast env as any generic Env type
1 parent fe09782 commit 616322c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+11675
-504
lines changed

apps/docs-autorag/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"deploy": "run-wrangler-deploy",
99
"dev": "wrangler dev",
1010
"start": "wrangler dev",
11-
"cf-typegen": "wrangler types",
11+
"types": "wrangler types --include-env=false",
1212
"test": "vitest run"
1313
},
1414
"dependencies": {
@@ -25,7 +25,6 @@
2525
},
2626
"devDependencies": {
2727
"@cloudflare/vitest-pool-workers": "0.8.14",
28-
"@cloudflare/workers-types": "4.20250414.0",
2928
"@types/node": "22.14.1",
3029
"prettier": "3.5.3",
3130
"typescript": "5.5.4",

apps/docs-autorag/src/context.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { CloudflareDocumentationMCP } from './index'
2+
3+
export interface Env {
4+
ENVIRONMENT: 'development' | 'staging' | 'production'
5+
AUTORAG_NAME: 'cloudflare-docs-autorag'
6+
MCP_SERVER_NAME: 'PLACEHOLDER'
7+
MCP_SERVER_VERSION: 'PLACEHOLDER'
8+
MCP_OBJECT: DurableObjectNamespace<CloudflareDocumentationMCP>
9+
MCP_METRICS: AnalyticsEngineDataset
10+
AI: Ai
11+
}

apps/docs-autorag/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { McpAgent } from 'agents/mcp'
2-
import { env } from 'cloudflare:workers'
32

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

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

8+
import type { Env } from './context'
9+
10+
const env = getEnv<Env>()
11+
812
// The docs MCP server isn't stateful, so we don't have state/props
913
export type Props = never
1014

apps/docs-autorag/vitest.config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config'
22

3+
import type { Env } from './src/context'
4+
35
export interface TestEnv extends Env {
46
CLOUDFLARE_MOCK_ACCOUNT_ID: string
57
CLOUDFLARE_MOCK_API_TOKEN: string

apps/docs-autorag/worker-configuration.d.ts

Lines changed: 35 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
1-
/* eslint-disable */
2-
// Generated by Wrangler by running `wrangler types` (hash: 23bfeb1ecdb06845b72c16f50728901d)
3-
// Runtime types generated with [email protected] 2025-03-10 nodejs_compat
4-
declare namespace Cloudflare {
5-
interface Env {
6-
ENVIRONMENT: "development" | "staging" | "production";
7-
AUTORAG_NAME: "cloudflare-docs-autorag";
8-
MCP_SERVER_NAME: "PLACEHOLDER";
9-
MCP_SERVER_VERSION: "PLACEHOLDER";
10-
MCP_OBJECT: DurableObjectNamespace<import("./src/index").CloudflareDocumentationMCP>;
11-
MCP_METRICS: AnalyticsEngineDataset;
12-
AI: Ai;
13-
}
14-
}
15-
interface Env extends Cloudflare.Env {}
16-
1+
// Runtime types generated with [email protected] 2025-03-10 nodejs_compat
172
// Begin runtime types
183
/*! *****************************************************************************
194
Copyright (c) Cloudflare. All rights reserved.
@@ -1603,11 +1588,11 @@ interface R2PutOptions {
16031588
onlyIf?: (R2Conditional | Headers);
16041589
httpMetadata?: (R2HTTPMetadata | Headers);
16051590
customMetadata?: Record<string, string>;
1606-
md5?: ((ArrayBuffer | ArrayBufferView) | string);
1607-
sha1?: ((ArrayBuffer | ArrayBufferView) | string);
1608-
sha256?: ((ArrayBuffer | ArrayBufferView) | string);
1609-
sha384?: ((ArrayBuffer | ArrayBufferView) | string);
1610-
sha512?: ((ArrayBuffer | ArrayBufferView) | string);
1591+
md5?: (ArrayBuffer | string);
1592+
sha1?: (ArrayBuffer | string);
1593+
sha256?: (ArrayBuffer | string);
1594+
sha384?: (ArrayBuffer | string);
1595+
sha512?: (ArrayBuffer | string);
16111596
storageClass?: string;
16121597
ssecKey?: (ArrayBuffer | string);
16131598
}
@@ -2202,7 +2187,7 @@ declare class URLSearchParams {
22022187
]>;
22032188
}
22042189
declare class URLPattern {
2205-
constructor(input?: (string | URLPatternInit), baseURL?: (string | URLPatternOptions), patternOptions?: URLPatternOptions);
2190+
constructor(input?: (string | URLPatternURLPatternInit), baseURL?: (string | URLPatternURLPatternOptions), patternOptions?: URLPatternURLPatternOptions);
22062191
get protocol(): string;
22072192
get username(): string;
22082193
get password(): string;
@@ -2211,10 +2196,10 @@ declare class URLPattern {
22112196
get pathname(): string;
22122197
get search(): string;
22132198
get hash(): string;
2214-
test(input?: (string | URLPatternInit), baseURL?: string): boolean;
2215-
exec(input?: (string | URLPatternInit), baseURL?: string): URLPatternResult | null;
2199+
test(input?: (string | URLPatternURLPatternInit), baseURL?: string): boolean;
2200+
exec(input?: (string | URLPatternURLPatternInit), baseURL?: string): URLPatternURLPatternResult | null;
22162201
}
2217-
interface URLPatternInit {
2202+
interface URLPatternURLPatternInit {
22182203
protocol?: string;
22192204
username?: string;
22202205
password?: string;
@@ -2225,22 +2210,22 @@ interface URLPatternInit {
22252210
hash?: string;
22262211
baseURL?: string;
22272212
}
2228-
interface URLPatternComponentResult {
2213+
interface URLPatternURLPatternComponentResult {
22292214
input: string;
22302215
groups: Record<string, string>;
22312216
}
2232-
interface URLPatternResult {
2233-
inputs: (string | URLPatternInit)[];
2234-
protocol: URLPatternComponentResult;
2235-
username: URLPatternComponentResult;
2236-
password: URLPatternComponentResult;
2237-
hostname: URLPatternComponentResult;
2238-
port: URLPatternComponentResult;
2239-
pathname: URLPatternComponentResult;
2240-
search: URLPatternComponentResult;
2241-
hash: URLPatternComponentResult;
2242-
}
2243-
interface URLPatternOptions {
2217+
interface URLPatternURLPatternResult {
2218+
inputs: (string | URLPatternURLPatternInit)[];
2219+
protocol: URLPatternURLPatternComponentResult;
2220+
username: URLPatternURLPatternComponentResult;
2221+
password: URLPatternURLPatternComponentResult;
2222+
hostname: URLPatternURLPatternComponentResult;
2223+
port: URLPatternURLPatternComponentResult;
2224+
pathname: URLPatternURLPatternComponentResult;
2225+
search: URLPatternURLPatternComponentResult;
2226+
hash: URLPatternURLPatternComponentResult;
2227+
}
2228+
interface URLPatternURLPatternOptions {
22442229
ignoreCase?: boolean;
22452230
}
22462231
/**
@@ -2396,8 +2381,6 @@ interface Socket {
23962381
get writable(): WritableStream;
23972382
get closed(): Promise<void>;
23982383
get opened(): Promise<SocketInfo>;
2399-
get upgraded(): boolean;
2400-
get secureTransport(): "on" | "off" | "starttls";
24012384
close(): Promise<void>;
24022385
startTls(options?: TlsOptions): Socket;
24032386
}
@@ -3724,21 +3707,13 @@ declare abstract class Ai<AiModelList extends AiModelListType = AiModels> {
37243707
extraHeaders?: object;
37253708
}): Promise<ConversionResponse>;
37263709
}
3727-
type GatewayRetries = {
3728-
maxAttempts?: 1 | 2 | 3 | 4 | 5;
3729-
retryDelayMs?: number;
3730-
backoff?: 'constant' | 'linear' | 'exponential';
3731-
};
37323710
type GatewayOptions = {
37333711
id: string;
37343712
cacheKey?: string;
37353713
cacheTtl?: number;
37363714
skipCache?: boolean;
37373715
metadata?: Record<string, number | string | boolean | null | bigint>;
37383716
collectLog?: boolean;
3739-
eventId?: string;
3740-
requestTimeoutMs?: number;
3741-
retries?: GatewayRetries;
37423717
};
37433718
type AiGatewayPatchLog = {
37443719
score?: number | null;
@@ -3772,26 +3747,21 @@ type AiGatewayLog = {
37723747
response_head_complete: boolean;
37733748
created_at: Date;
37743749
};
3775-
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';
3750+
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";
37763751
type AIGatewayHeaders = {
3777-
'cf-aig-metadata': Record<string, number | string | boolean | null | bigint> | string;
3778-
'cf-aig-custom-cost': {
3752+
"cf-aig-metadata": Record<string, number | string | boolean | null | bigint> | string;
3753+
"cf-aig-custom-cost": {
37793754
per_token_in?: number;
37803755
per_token_out?: number;
37813756
} | {
37823757
total_cost?: number;
37833758
} | string;
3784-
'cf-aig-cache-ttl': number | string;
3785-
'cf-aig-skip-cache': boolean | string;
3786-
'cf-aig-cache-key': string;
3787-
'cf-aig-event-id': string;
3788-
'cf-aig-request-timeout': number | string;
3789-
'cf-aig-max-attempts': number | string;
3790-
'cf-aig-retry-delay': number | string;
3791-
'cf-aig-backoff': string;
3792-
'cf-aig-collect-log': boolean | string;
3759+
"cf-aig-cache-ttl": number | string;
3760+
"cf-aig-skip-cache": boolean | string;
3761+
"cf-aig-cache-key": string;
3762+
"cf-aig-collect-log": boolean | string;
37933763
Authorization: string;
3794-
'Content-Type': string;
3764+
"Content-Type": string;
37953765
[key: string]: string | number | boolean | object;
37963766
};
37973767
type AIGatewayUniversalRequest = {
@@ -3807,10 +3777,7 @@ interface AiGatewayLogNotFound extends Error {
38073777
declare abstract class AiGateway {
38083778
patchLog(logId: string, data: AiGatewayPatchLog): Promise<void>;
38093779
getLog(logId: string): Promise<AiGatewayLog>;
3810-
run(data: AIGatewayUniversalRequest | AIGatewayUniversalRequest[], options?: {
3811-
gateway?: GatewayOptions;
3812-
extraHeaders?: object;
3813-
}): Promise<Response>;
3780+
run(data: AIGatewayUniversalRequest | AIGatewayUniversalRequest[]): Promise<Response>;
38143781
getUrl(provider?: AIGatewayProviders | string): Promise<string>; // eslint-disable-line
38153782
}
38163783
interface AutoRAGInternalError extends Error {
@@ -3828,22 +3795,16 @@ type AutoRagSearchRequest = {
38283795
};
38293796
rewrite_query?: boolean;
38303797
};
3831-
type AutoRagAiSearchRequest = AutoRagSearchRequest & {
3832-
stream?: boolean;
3833-
};
3834-
type AutoRagAiSearchRequestStreaming = Omit<AutoRagAiSearchRequest, 'stream'> & {
3835-
stream: true;
3836-
};
38373798
type AutoRagSearchResponse = {
3838-
object: 'vector_store.search_results.page';
3799+
object: "vector_store.search_results.page";
38393800
search_query: string;
38403801
data: {
38413802
file_id: string;
38423803
filename: string;
38433804
score: number;
38443805
attributes: Record<string, string | number | boolean | null>;
38453806
content: {
3846-
type: 'text';
3807+
type: "text";
38473808
text: string;
38483809
}[];
38493810
}[];
@@ -3855,9 +3816,7 @@ type AutoRagAiSearchResponse = AutoRagSearchResponse & {
38553816
};
38563817
declare abstract class AutoRAG {
38573818
search(params: AutoRagSearchRequest): Promise<AutoRagSearchResponse>;
3858-
aiSearch(params: AutoRagAiSearchRequestStreaming): Promise<Response>;
3859-
aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse>;
3860-
aiSearch(params: AutoRagAiSearchRequest): Promise<AutoRagAiSearchResponse | Response>;
3819+
aiSearch(params: AutoRagSearchRequest): Promise<AutoRagAiSearchResponse>;
38613820
}
38623821
interface BasicImageTransformations {
38633822
/**

apps/sandbox-container/evals/env.d.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

apps/sandbox-container/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@
1212
"start:container": "tsx container/index.ts",
1313
"postinstall": "mkdir -p workdir",
1414
"test": "vitest",
15-
"types": "wrangler types",
15+
"types": "wrangler types --include-env=false",
1616
"eval:dev": "start-server-and-test --expect 404 eval:server http://localhost:8976 'vitest --testTimeout=60000 --config vitest.config.evals.ts'",
1717
"eval:server": "concurrently \"tsx container/index.ts\" \"wrangler dev --var \"ENVIRONMENT:test\"\"",
1818
"eval:ci": "start-server-and-test --expect 404 eval:server http://localhost:8976 'vitest run --testTimeout=60000 --config vitest.config.evals.ts'"
1919
},
2020
"dependencies": {
2121
"@cloudflare/workers-oauth-provider": "0.0.2",
22-
"@cloudflare/workers-types": "4.20250414.0",
2322
"@hono/node-server": "1.13.8",
2423
"@hono/zod-validator": "0.4.3",
2524
"@modelcontextprotocol/sdk": "1.9.0",

apps/sandbox-container/server/containerManager.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { DurableObject } from 'cloudflare:workers'
22

3+
import type { Env } from './context'
4+
35
export class ContainerManager extends DurableObject<Env> {
46
constructor(
57
public ctx: DurableObjectState,

apps/sandbox-container/server/containerMcp.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { BASE_INSTRUCTIONS } from './prompts'
1010
import { fileToBase64, stripProtocolFromFilePath } from './utils'
1111

1212
import type { FileList } from '../shared/schema'
13+
import type { Env } from './context'
1314
import type { Props } from '.'
1415

1516
export class ContainerMcpAgent extends McpAgent<Env, {}, Props> {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { ContainerManager, ContainerMcpAgent } from './index'
2+
3+
export interface Env {
4+
OAUTH_KV: KVNamespace
5+
CLOUDFLARE_CLIENT_ID: '<PLACEHOLDER>'
6+
CLOUDFLARE_CLIENT_SECRET: '<PLACEHOLDER>'
7+
ENVIRONMENT: 'dev'
8+
MCP_SERVER_NAME: '<PLACEHOLDER>'
9+
MCP_SERVER_VERSION: '<PLACEHOLDER>'
10+
OPENAI_API_KEY: string
11+
CONTAINER_MCP_AGENT: DurableObjectNamespace<ContainerMcpAgent>
12+
CONTAINER_MANAGER: DurableObjectNamespace<ContainerManager>
13+
MCP_METRICS: AnalyticsEngineDataset
14+
AI: Ai
15+
}

0 commit comments

Comments
 (0)