# V18.5 — University Cloud Workspace

The offline Instructor and Student releases and public static release are retained. This is an optional **connected deployment candidate**, not a deployed university service. It uses a Cloudflare Worker and D1 database, with an institutional identity provider configured through Cloudflare Access. Do not upload the connected ZIP to Pages as if it were a static-only ZIP. Do not upload the Instructor ZIP to a public host.

## Local and public-static use

Extract Instructor or Student; run `START_LOCAL_SERVER.cmd` (or `python3 local_portal.py`). Open any experiment. Dr. Mohammad and the V18.4 Copy & Open ChatGPT/Gemini/Claude workflow work without a connected backend. The new connected controls check availability only when requested; no automatic AI submission. Static public hosting uses the separate Cloudflare Student Static package. Its connected controls remain inactive without the Worker.

## Connected deployment (administrator)

1. Use a separate institutional subdomain (for example engineering.example.edu) in your Cloudflare account. Arrange university authorization, a data processing agreement, privacy/retention policies, and identity provider configuration before enrolling real students. Use Cloudflare Access self-hosted application policies that require verified institutional user identities and restrict the entire connected hostname; do not create a bypass policy for `/api/*`. Keep a separate static public portal if public access is wanted. Use a short session lifetime, MFA where available, and do not use service tokens as student identities.
2. Extract the **Connected Worker** ZIP. Only `public/` is the static assets directory. The server, database migrations, test files and administrator configuration remain outside it. No production credentials or student accounts are supplied. Install Node.js 22+ and Wrangler with your approved package version. Authenticate `npx wrangler login` and review the generated configuration before deployment.
3. `npx wrangler d1 create psut-engineering`. Copy its database ID into `wrangler.toml` (replace the placeholder). Set `ACCESS_ISSUER` to your exact `https://<team>.cloudflareaccess.com` and `ACCESS_AUD` to the Access application's audience tag. Attach the approved custom domain to the Worker using the dashboard or Wrangler routes configuration; do not enable workers.dev or public preview URLs. Use Access on that hostname. Apply `npx wrangler d1 migrations apply psut-engineering --remote`.
4. Provision accounts in D1 using your authenticated admin console or Wrangler. Example SQL with dummy addresses (replace with approved, lower-case institutional emails):

```sql
INSERT INTO accounts(email,role) VALUES ('student@example.edu','student');
INSERT INTO accounts(email,role) VALUES ('instructor@example.edu','instructor');
UPDATE accounts SET active=0 WHERE email='student@example.edu';
```

The database allowlist is independent of Access policy. Instructor role allows aggregate account counts and ordinary owner/member workflows, **not** arbitrary student-data access. Disable accounts when enrollment ends; changes are checked on subsequent API requests. Account management is intentionally administrator SQL, not a public signup form. Cloudflare administrators can access D1 data. Review access logs and remove unused accounts according to policy.

5. `npx wrangler deploy`. Confirm Access protects the hostname and `/api/v185/me`; test actual sign-in as an approved student, instructor, a denied user and a disabled account. Confirm private API responses are not cached. Verify cross-account workspace isolation and collaboration revocation. Test browser behavior with your institutional IdP. Do not consider the service production-ready until these checks pass.

## Optional in-site AI

AI is disabled by default (`AI_ENABLED="false"`). Set only the providers you authorize. The administrator chooses current API model IDs in `OPENAI_MODEL`, `GEMINI_MODEL`, `ANTHROPIC_MODEL` (empty disables a provider). Store credentials as Worker secrets using `npx wrangler secret put OPENAI_API_KEY`, `... GEMINI_API_KEY`, `... ANTHROPIC_API_KEY`. Never add keys to HTML, JavaScript, TOML vars, or shared project exports. Then set `AI_ENABLED="true"` and deploy. Live provider calls are not part of local tests. Test one approved nonconfidential prompt with each configured model. Model APIs and chat subscriptions are separate; actual API charges depend on the provider, and the free browser-chat handoff remains available.

Default limits: 5 attempts/account/UTC day, 30 attempts total/UTC day, 1,024 output tokens; 32,000 characters/prompt, 30 s upstream timeout, no automatic retries. Request counts include upstream failures. These are operational guards, **not a hard monetary spending cap**. Configure provider-side budget alerts and limits where supported. Monitor costs and disable AI if needed. No tools, code execution or provider web browsing are enabled by this adapter. API calls return plain text (not streamed), and may return a partial response if the provider reaches its output limit. Each call sends the reviewed prompt; use “Use reply as follow-up context” to include it in a fresh prompt. Save history is opt-in, up to 100 interactions per account. Deleting history removes active database rows, not provider retention or backup copies. Never submit actual grades, credentials, private question banks, personal identifiers or unpublished confidential research. Existing redaction is best-effort only.

## Workspaces

Connect in Cloud Workspace. Create a project, notebook, research or progress record. Import a JSON export from the originating tool, edit/review it, approve saving, then save a revision. Capture local Project Builder design or lab completion flags with dedicated controls. Retrieve on another authenticated browser; export the JSON for manual import into the originating tool where supported. Progress snapshots merge completed flags without removing existing completions; these are self-reported, not grades. Only owners can invite/remove enrolled collaborators and delete their workspaces. Collaborators can read and edit the entire shared record; share only appropriate content. A stale revision is rejected (409), not silently overwritten. Reload manually and reconcile local changes before retrying. Max 100 owned records per account, 20 members per record, 70 KB JSON content per record. No binary uploads, live cursors, automatic background synchronization, revision history beyond current revision, or gradebook integration. Export before deleting. No official LMS data is copied.

## Verification and limitations

`node tests/test-worker.mjs` runs the actual Worker request handler against a Node SQLite adapter, with real generated RSA signatures and intercepted upstream provider fixtures. This does not validate the hosted D1 runtime, actual Cloudflare Access, distributed concurrency or live AI billing. The local browser smoke test uses an intercepted API; it is not a deployment. Production security review, backup/restore and data retention policy, privacy review, accessibility testing, and load testing remain required. No actual account, domain, provider key or deployment was accessed or created.

References: https://developers.cloudflare.com/workers/static-assets/binding/ ; https://developers.cloudflare.com/cloudflare-one/access-controls/applications/http-apps/authorization-cookie/validating-json/ ; https://developers.cloudflare.com/d1/ ; https://developers.openai.com/api/docs/guides/text ; https://ai.google.dev/api/generate-content ; https://platform.claude.com/docs/en/api/messages/create .
