Luigit
repositories / pi-ext

pi-ext

bugabingas pi extensions

owned by admin

extensions/quota/demo/scene.json

Raw
{
	"title": "Synthetic quota dashboard",
	"extensions": ["quota"],
	"cols": 100,
	"rows": 26,
	"args": [
		"-e",
		"./quota-fixture.js",
		"--provider",
		"openai-codex",
		"--model",
		"quota-demo"
	],
	"files": {
		"quota-fixture.js": "export default function (pi) {\n  const original = globalThis.fetch;\n  globalThis.fetch = async (input) => {\n    if (String(input) !== \"https://chatgpt.com/backend-api/wham/usage\") throw new Error(\"Unexpected fixture request\");\n    return Response.json({ rate_limit: { primary_window: { used_percent: 25, limit_window_seconds: 18000, reset_at: Math.floor(Date.now() / 1000) + 3600 }, secondary_window: { used_percent: 10, limit_window_seconds: 604800, reset_at: Math.floor(Date.now() / 1000) + 86400 } }, credits: { balance: \"12.5\" } });\n  };\n  const claim = Buffer.from(JSON.stringify({ \"https://api.openai.com/auth\": { chatgpt_account_id: \"synthetic-demo\" } })).toString(\"base64url\");\n  pi.registerProvider(\"openai-codex\", {\n    api: \"openai\", apiKey: \"header.\" + claim + \".signature\", baseUrl: \"https://fixture.invalid\",\n    streamSimple: () => { throw new Error(\"Quota demo must not make model requests\"); },\n    models: [{ id: \"quota-demo\", name: \"Synthetic quota\", reasoning: false, input: [\"text\"], cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, contextWindow: 128000, maxTokens: 1024 }]\n  });\n  pi.on(\"session_shutdown\", () => { globalThis.fetch = original; });\n}"
	},
	"steps": [
		{
			"type": "/quota",
			"key": "enter",
			"fresh": true,
			"expect": "25%",
			"hold": 10
		},
		{
			"expect": "Weekly.*10%",
			"hold": 6
		},
		{
			"expect": "Credits.*12.5",
			"hold": 6
		},
		{
			"type": "/quota",
			"key": "enter",
			"hold": 6
		},
		{
			"key": "ctrl-c"
		},
		{
			"key": "ctrl-c"
		}
	]
}