Files
sigil/src/index.ts
T
xiaoju f20b19a71e feat: implement Sigil Phase 1 MVP 🔮
- Wrangler project setup (TypeScript + Vitest)
- SigilBackend interface + WorkerPool implementation
- KV store with layered key schema (code/meta/lru/route/auth/stats)
- LRU scheduler with eviction priority (ephemeral_expired > ephemeral > normal > persistent)
- AuthModule: Bearer token validation, agent isolation, deploy cooldown
- Router: /_health, /_api/deploy, /_api/remove, /_api/list, /_api/inspect, /{agent}/{capability}
- 13 test scenarios, all passing (38 tests)
- MockKV + MockCfApi for isolated testing

Tests: 38/38  | Build: 22KB gzip:5KB 

小橘 🍊(NEKO Team)
2026-04-03 04:17:43 +00:00

37 lines
1.1 KiB
TypeScript

import { WorkerPool, type CfApi } from './backend/worker-pool.js'
import { AuthModule } from './auth.js'
import { KvStore } from './kv.js'
import { handleRequest } from './router.js'
import { CONFIG } from './config.js'
export interface Env {
SIGIL_KV: KVNamespace
}
const defaultCfApi: CfApi = {
async deployWorker(name: string, _code: string): Promise<void> {
// Production: use CF API to deploy
console.log(`[sigil] deploy worker: ${name}`)
},
async deleteWorker(name: string): Promise<void> {
console.log(`[sigil] delete worker: ${name}`)
},
getWorkerSubdomain(name: string): string {
return `${name}${CONFIG.SUBDOMAIN_SUFFIX}`
},
async invoke(_workerName: string, request: Request): Promise<Response> {
// Production: fetch from worker subdomain
return new Response('Not implemented', { status: 501 })
},
}
export default {
async fetch(request: Request, env: Env): Promise<Response> {
const kv = new KvStore(env.SIGIL_KV)
const backend = new WorkerPool(env.SIGIL_KV, defaultCfApi)
const auth = new AuthModule(kv)
return handleRequest(request, { SIGIL_KV: env.SIGIL_KV, backend, auth, kv })
},
}