How stackosofficial/ai-access-package works
Project type and purpose
• This is an NPM-distributed, TypeScript-based middleware library (“sky-ai-accesspoint”) that you embed into an Express server to provide a secure AI endpoint.
• Its purpose is to expose a single HTTP API (POST /natural-request) that enforces NFT-based access control, tracks and updates user balances in Firebase, and proxies requests to an OpenAI model and Skynet’s blockchain infrastructure.
File structure
• Top level: Dockerfile, GitHub workflows, package.json, src/ (TypeScript sources), lib/ (compiled JS + typings).
• src/ contains core modules:
• init.ts – bootstrapper (initAIAccessPoint)
• balanceRunMain.ts – orchestrator class
• balanceExtractService.ts – cost-parsing logic
• serverBalanceDatabaseService.ts – Firebase reads/writes
• databaseWriterExecution.ts, timeIntervalExecution.ts, nonReentrantExecution.ts, mutex.ts – background-job and concurrency helpers
• middleware/ – Express middleware: parseAuth, auth (protect), checkBalance
• envConfig.ts, utils.ts, types/ – config and type definitions
• Configuration: tsconfig.json, .npmrc, Dockerfile for containerization, GitHub Actions for CI/CD.
README for extra insights
• Environment variables: JSON_RPC_PROVIDER, FIREBASE_*, OPENAI_API_KEY, etc.
• Usage:
• Developer calls initAIAccessPoint(env, SkyMainNodeJS, expressApp, runNaturalFunction, runUpdate)
• initAIAccessPoint registers middleware and endpoint(s), returns BalanceRunMain instance.
• runNaturalFunction uses balanceRunMain.callAIModel() to hit OpenAI.
• Middleware chain enforces authentication, NFT ownership, balance checks.
• Cost management: balanceRunMain.addCost() writes to Firebase.
Be detailed
• Middleware components, the initAIAccessPoint bootstrap, the BalanceRunMain methods, scheduler modules, and each external integration.
• Don’t hesitate to break out sub-components (for example, separate the scheduler into timeIntervalExecution + databaseWriterExecution).