Files
Daniel Salazar d4d78ac7db rework: change backend and backend extensions to use simpler code structure and patterns (#2815)
* fix:  dynamodb health checks and client recreation (#2789)

* wip: no nanoServices groundwork

* feat: data clients in new shape

* wip: auth and perms in new system

* more wip

* middlewaters mainly done

* wip: fsv2 in new layout

* old fs v2 migration

* driver system

* driver and old fs fixes

* ai drivers wip

* stream support

* metering in ai chat driver

* wip: new auth

* rate limit and auth routes

* captcha and anti csrf

* fix: types

* auth store

* app logic

* wip most other dricvers

* fs

* mostly kill all legacy stuff

* fs finish

* fix: redis usage

* ai controller

* driver cleanup

* socket io in v2

* broadcast and crudq stuff

* subdomains

* notifcations and shares

* fix bad syntaxes

* auth wip

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* extensions

* extension setup

* more routes

* sql migrations and default services

* home router

* tier 7

* everything else

* everything else

* remaining missing bits

* server health

* logs

* cleanup

* deps

* cleanup 2

* more cleanup 2

* boot

* fix launch

* config fix

* move file

* fix: tsconfig things

* fix: extension loading

* launching

* fix: drivers

* fix: others

* fix: icons

* fix: file uploads

* fs fixes

* fix: fs api

* fix: dev-center

* config

* add back telemetry

* lint stuff

* husky hooks

* fix: fs oss

* fix: config migration

* config migration

* migrate scripts + replicate

* runner

* fix: merge defafult config

* fix: default region

* fix: api domain

* fix paths in readfile

* fix fs entry default s3

* NS: Remove Referral && Entri Service

* dep cleanups

* fix: static assets

* fix: kv and perms

* fix: driver registrations

* fix: home mapping

* fix: rao

* adding back 500 alarm

* fix: build paths

* fix: fs and kv shapes

* fix: kv shape

* more kv coercing and ai chat matching format as prior

* fix:  private app gates

* private app caches

* fix: whole bunch of legacy shape issues

* update template jsonc

* fix caching partial oidc and fs signed paths

* more oidc fixes

* fix: wip

* fix: private apps

* admin route fixes

* fix: last few things hopefully

* claude uploads

* fix security for app only routes

* fix kv system namespace

* stuff

* fix: app and kv and suggested apps

* fix:open item

* fix: FS operations

* fix: default app icons

* add back token-read and WSL support

* metering fixes

* fix: fsEntry

* perm scanners and implicators

* proper download endpoint

* fix: download

* fix anti csrft on v2

* fix file extensions, app icons

* fold in v1 fixes from origin/main into v2 equivalents

Re-applies the v1 fixes that landed on origin/main into their v2
counterparts since the v1 files were deleted on DS/wip during the v2
migration. v1 commits referenced below.

- SQLBatcher: flush immediately when queue hits maxBatchSize instead
  of racing the timer (v1 12f48238).
- RedisClient: drop maxRetriesPerRequest from 2 to 1 to shrink failure
  window (v1 b6776ab4).
- ChatCompletionDriver: default minimumCredits to 1 when unset/zero so
  zero-cost precheck doesn't auto-pass (v1 36bd6073).
- OpenAiImageProvider: add gpt-image-2 support — open-ended size rules,
  token-based cost estimator, arbitrary-size normalizer, isGpt prefix
  broadened to gpt-image- (v1 f14f1bf4). models.ts auto-merged via
  rename detection.
- AppStore: bump row cache TTL from 5m to 24h (v1 6b3196ed).

Not ported: v1 app-object Redis cache (bdfa12b5/b886dde3) — v2's
#toClient recomputes filetype_associations/created_from_origin per
read; adding a second cache layer is a larger change for a follow-up.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* remoe anti-csrf from auth routes that had not used them

* more icon fixes

* fix worker functionality

* fix: app and subdomain es

Co-authored-by: Copilot <copilot@github.com>

* fix PUT-761

* fix: PUT-748

* fix: rename fsService

* Add security back to WorkerDriver

* Migrate worker from fsEntry to fs. Fix cache issue

* remove ability to create symlinks

* strict webdav acl

* require auth for wisp

* chore: service renames

* Add metering back to puter peer api

* fix: PUT-760 PUT-749

* fix: PUT-746

* fix: peer cost

Co-authored-by: Copilot <copilot@github.com>

* fix: 771

* change order of peer controller

* fix: create appdata folder for app on get auth token

* fix: align delete site and list sites

* delete: putility

* fix subdomains

* Add support for tilde in subdomains, fix subdomain update

* cleanup PeerController.ts and fix billing oversight (#2844)

* fix: PUT-786

* fix: bugs

* fix: issues with multiple subdomain queries, or permission checks

* fix: harden response shapes to not contain uneeded fields

* fix: move state to redis

* fix: missing kv methods + better sec

Co-authored-by: Copilot <copilot@github.com>

* fix: subdomainStore limit

* fix: missing path resolution

Co-authored-by: Copilot <copilot@github.com>

* fs fixes

* fix: undef error

* fix fs + cleanup

* fix: npm audit fixes

* heal path entries where missing

Co-authored-by: Copilot <copilot@github.com>

* fix: caching

Co-authored-by: Copilot <copilot@github.com>

* fix: cache inconsistencies

Co-authored-by: Copilot <copilot@github.com>

* fix: app driver metadata

Co-authored-by: Copilot <copilot@github.com>

* remove extraneous comma

* fix: associated app icons

* fix: bad tool call

* Add validation to WorkerDriver#getFilePaths

* misc fs and auth issues

Co-authored-by: Copilot <copilot@github.com>

* fix: oidc errors

Co-authored-by: Copilot <copilot@github.com>

* fix: PUT-797

* fix: legacy appdata_app

Co-authored-by: Copilot <copilot@github.com>

* fix: add alert logs

Co-authored-by: Copilot <copilot@github.com>

* fix: error handling

* Disable sharecontroller

* fix: remove private user identifier for ai

* fix: private app fixes

* Add backback signup_server

* fix: completionId size

Co-authored-by: Copilot <copilot@github.com>

* fix: revalidate path for oidc

* fix: revalidate path for oidc

* fix: email validation

Co-authored-by: Copilot <copilot@github.com>

* fix: user create query

* fix: middleware extensions

Co-authored-by: Copilot <copilot@github.com>

* use x-forwarded-for for req ip forwarded

* fix: missing last_activity ts

* feat: add cache broadcast to subdomains

* fix: update config typing

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: ProgrammerIn-wonderland <3838shah@gmail.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Nariman Jelveh <nj@puter.com>
Co-authored-by: velzie <velzie@velzie.rip>
2026-04-30 12:13:43 -07:00

99 lines
5.2 KiB
TypeScript

import { extension } from '@heyputer/backend/src/extensions';
const page = `
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Puter Worker Sandbox Playground</title>
<style>
:root {
color-scheme: light;
--bg: #0f172a;
--panel: #111827;
--panel-2: #1f2937;
--text: #e5e7eb;
--muted: #94a3b8;
--accent: #22d3ee;
--danger: #fb7185;
--ok: #34d399;
--border: #334155;
}
* { box-sizing: border-box; }
body {
margin: 0;
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
background: radial-gradient(circle at top, #1e293b, var(--bg) 55%);
color: var(--text);
min-height: 100vh;
padding: 20px;
}
.wrap { max-width: 980px; margin: 0 auto; }
h1 { margin: 0 0 8px; font-size: 24px; }
p { margin: 0 0 14px; color: var(--muted); }
.toolbar { display: flex; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
button { border: 1px solid var(--border); background: var(--panel-2); color: var(--text); padding: 8px 12px; border-radius: 8px; cursor: pointer; }
button:hover { border-color: var(--accent); }
.layout { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .layout { grid-template-columns: 1fr 1fr; } }
.card { border: 1px solid var(--border); border-radius: 10px; background: color-mix(in srgb, var(--panel) 88%, black 12%); overflow: hidden; }
.card h2 { margin: 0; padding: 10px 12px; font-size: 14px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--panel-2) 90%, black 10%); }
textarea { display: block; width: 100%; min-height: 420px; border: 0; resize: vertical; background: transparent; color: var(--text); padding: 12px; outline: none; font-size: 13px; line-height: 1.5; }
#logs { margin: 0; padding: 12px; min-height: 420px; max-height: 70vh; overflow: auto; white-space: pre-wrap; word-break: break-word; font-size: 13px; line-height: 1.45; }
.line { margin: 0 0 8px; }
.info { color: var(--muted); }
.ok { color: var(--ok); }
.warn { color: #fbbf24; }
.error { color: var(--danger); }
code { color: var(--accent); }
</style>
</head>
<body>
<main class="wrap">
<h1>Puter Worker Sandbox Playground</h1>
<p>Use this page to interact with the puter APIs in the same sandbox as your worker.</p>
<div class="toolbar">
<button id="run">Run</button>
<button id="clear">Clear Logs</button>
</div>
<section class="layout">
<article class="card">
<h2>Code</h2>
<textarea id="code" spellcheck="false">console.log(JSON.stringify(await puter.kv.list({limit: 100})))</textarea>
</article>
<article class="card">
<h2>Logs</h2>
<pre id="logs"></pre>
</article>
</section>
</main>
<script src="https://js.puter.com/v2/"></script>
<script>
(() => {
const codeEl = document.getElementById('code');
const logsEl = document.getElementById('logs');
const runBtn = document.getElementById('run');
const clearBtn = document.getElementById('clear');
const originalConsole = { log: console.log.bind(console), info: console.info.bind(console), warn: console.warn.bind(console), error: console.error.bind(console) };
const safeStringify = (v) => { if (typeof v === 'string') return v; if (v instanceof Error) return v.stack || v.message || String(v); try { return JSON.stringify(v, null, 2); } catch { return String(v); } };
const appendLog = (level, parts) => { const line = document.createElement('div'); line.className = 'line ' + level; line.textContent = '[' + new Date().toLocaleTimeString() + '] ' + parts.map(safeStringify).join(' '); logsEl.appendChild(line); logsEl.scrollTop = logsEl.scrollHeight; };
['log', 'info', 'warn', 'error'].forEach((level) => { console[level] = (...args) => { appendLog(level === 'log' ? 'ok' : level, args); originalConsole[level](...args); }; });
window.addEventListener('error', (event) => { appendLog('error', [event.error || event.message]); });
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
runBtn.addEventListener('click', async () => { const source = codeEl.value; appendLog('info', ['Running...']); try { const fn = new AsyncFunction(source); const result = await fn.call(window); appendLog('ok', ['Result:', result]); } catch (err) { appendLog('error', ['Execution failed:', err]); } });
clearBtn.addEventListener('click', () => { logsEl.textContent = ''; });
})();
</script>
</body>
</html>
`;
extension.get(
'/',
{ requireAuth: false, subdomain: 'worker-sandbox' },
(_req, res) => {
res.type('html').send(page);
},
);