cloudgpu-mcp 0.14.1 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -0
- package/package.json +1 -1
- package/rules/cloudgpu.md +6 -2
- package/skills/cloudgpu/SKILL.md +4 -0
- package/src/agent-readiness.js +6 -0
- package/src/application-recipes.js +1 -1
- package/src/credentials.js +25 -5
- package/src/funding-tools.js +11 -0
- package/src/index.js +19 -9
- package/src/model-references.js +3 -3
- package/src/recipes/causal-lora.py +12 -2
- package/src/recipes/task-pipeline.py +41 -0
- package/src/storage.js +86 -41
- package/src/task-pipelines.js +39 -0
package/README.md
CHANGED
|
@@ -147,6 +147,10 @@ The same guidance is available as two [Agent Skills](https://agentskills.io):
|
|
|
147
147
|
| `run_job` | Starts a GPU, runs one command and destroys the GPU, all on CloudGPU's servers; safe to retry with the same `idempotency_key` |
|
|
148
148
|
| `get_job` / `list_jobs` | Job status, exit code, cost, the last ~4 KB of output and the job's history |
|
|
149
149
|
| `cancel_job` | Stops a job and destroys its GPU |
|
|
150
|
+
| `get_agent_readiness` / `assess_task_fit` | Anonymous capability, billing, task suitability and evidence checks; no GPU is created |
|
|
151
|
+
| `request_top_up` / `wait_for_funds` | Human-only payment link and bounded polling for actual credit; no automatic charge or Job |
|
|
152
|
+
| `quote_storage_budget` / `confirm_storage_budget` | Quote and explicitly approve an earmarked storage transfer; backend rollout and owner permissions apply |
|
|
153
|
+
| `resume_artifact_upload` | Resume the same owned multipart reservation with the original local file and checksum |
|
|
150
154
|
| `connect_account` / `finish_connect` | Gets a key without copying one: the user approves this assistant in the browser with a spending limit and a number of GPUs at once |
|
|
151
155
|
|
|
152
156
|
The server also provides a `train_on_cloudgpu` prompt.
|
|
@@ -379,3 +383,25 @@ Ask your connected Agent: “Compare compatible GPUs for this task, include prep
|
|
|
379
383
|
Can one GPU serve several Agent tasks? Yes: sequential approved `run_command` calls can use the same running rental, within its original budget, deadline and idle limit. Check `list_instances` / `get_status` first. Independent `run_job` calls and “rerun” each provision separately; they do not share an instance. Do not extend limits or keep an idle GPU merely because an hour was charged. Save outputs before stopping; Workspace is explicit persistence, not a disk snapshot.
|
|
380
384
|
|
|
381
385
|
MCP clients must install or upgrade this package and restart their local MCP process. The account connection link authorizes a supported client; it cannot install tools into any arbitrary AI service.
|
|
386
|
+
|
|
387
|
+
### Several tasks, one GPU allocation (0.15.0)
|
|
388
|
+
|
|
389
|
+
`prepare_task_pipeline` prepares 1–8 reviewed commands to run sequentially as one Job. They share the GPU and filesystem; each step has a new shell, so shell variables and in-memory model processes do not persist between steps. A nonzero step exit stops subsequent steps. Dependencies and any required models must already be prepared; this is not application-quality or GPU-model acceptance.
|
|
390
|
+
|
|
391
|
+
Preparation makes no API request or reservation. Review the returned command, obtain a compatible Job quote and explicit total GPU budget/deadline approval, then call `run_job` once. Retain that submission's idempotency key if its response is lost. The manifest fingerprint is informational, not a server-enforced approval or submission key. Independent Jobs still use independent allocations; this is not the durable batch coordinator.
|
|
392
|
+
|
|
393
|
+
For an existing rental, the reviewed command can instead be passed to `run_command` in the approved working directory, within its original limits. Apply a Workspace separately when needed. The draft never stops or extends an existing rental. Whole-hour sources remain usable through the existing explicitly approved rental path; this release does not remove their current automatic-Job compatibility gate.
|
|
394
|
+
|
|
395
|
+
With `persist_summary=true`, the Job draft explicitly collects only `pipeline-summary.json` through the existing output collector, using current storage quota/retention and `accept_storage_charges=false`. The summary contains step IDs, exit codes and state, not raw logs, commands or arbitrary task results. Result-file persistence must be configured and approved separately. The summary must not already exist; missing output collection or a conflicting file aborts before commands run.
|
|
396
|
+
|
|
397
|
+
### Candidate 0.16.0: funded connection and storage growth
|
|
398
|
+
|
|
399
|
+
This branch is a candidate, not a claim that npm, Registry or production have been updated. The current stdio inventory is 54 tools; remote MCP intentionally exposes only operations safe without local filesystem/SSH access. Always check live backend capabilities.
|
|
400
|
+
|
|
401
|
+
`connect_account` returns a direct Google link and email alternative. Pending connection state is private, origin-bound and survives restart; the server candidate extends approval time to 30 minutes. Browser payment does not approve compute. `request_top_up` creates only a short-lived owner link; `wait_for_funds` requires a real credit signal and sufficient live balance. Neither creates a Job.
|
|
402
|
+
|
|
403
|
+
Dedicated storage budget is a separate, explicitly confirmed wallet reservation, consumed only by actual UTC daily peak usage. Unused surplus can return after existing files, uploads and pending daily charges remain covered. It is not revenue or an automatic refill. Capacity can grow with budget, subject to published technical limits, and retention remains 30 days. Budget-limited Agent keys cannot reserve funds or consent to paid storage. Disabling new self-service transfers must not disable accounting for existing reserves.
|
|
404
|
+
|
|
405
|
+
Multipart resume keeps the same reservation and original file hash. GPU restore renewal is file-scoped, temporary and feature-gated; no general account key is installed on a GPU. Local fixtures do not certify TB-sized transfers. Backend automatic public-model preparation currently has a 600-second deadline: a 9.8GB Wan video case exceeded it on the measured link. Prepared images or explicitly reviewed bounded download commands need their own acceptance; do not promise that every size below the model byte limit loads in time.
|
|
406
|
+
|
|
407
|
+
The Python SDK candidate and optional framework adapters are under [`python/`](python/README.md). PyPI publication and actual third-party framework acceptance remain separate from package construction.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cloudgpu-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"mcpName": "io.github.cloudgpu-app/cloudgpu-mcp",
|
|
5
5
|
"description": "MCP server and command-line tool for cloudgpu.app: let Claude Code, Cursor, Cline, opencode, goose and other MCP clients (or you, from a terminal) rent a GPU with explicit billing quotes, run a job, fetch the results and shut it down, with spending limits the platform enforces.",
|
|
6
6
|
"type": "module",
|
package/rules/cloudgpu.md
CHANGED
|
@@ -21,7 +21,7 @@ Copy this file into your project as `AGENTS.md`, `.cursor/rules/cloudgpu.md` or
|
|
|
21
21
|
- Always set `max_spend_usd` and `max_hours`. CloudGPU's servers destroy the instance when either is reached, even if you have disconnected.
|
|
22
22
|
- Keep `idle_minutes` on (default 60). Raise it if setup will take long, because installing packages and downloading models leave the GPU idle.
|
|
23
23
|
- Call `get_status` at intervals, not in a tight loop, until the instance is `running`.
|
|
24
|
-
-
|
|
24
|
+
- On failure, inspect actual charges and independent release evidence. A failed platform status is not proof of release or zero cost; do not automatically create a replacement.
|
|
25
25
|
|
|
26
26
|
## Working on the instance
|
|
27
27
|
|
|
@@ -52,7 +52,7 @@ Call `connect_account` with a name for yourself and the spending limit the user
|
|
|
52
52
|
2. Call `stop_instance`.
|
|
53
53
|
3. Tell the user what ran, where the results are on their computer, and the final cost from `stop_instance`.
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
For an instance created specifically for this approved task, preserve results and request release if it fails. An existing user instance keeps its original lifecycle: failure to apply files or run one step does not authorize stopping it. Inspect and ask the owner before changing its lifecycle.
|
|
56
56
|
|
|
57
57
|
## Only need a model, not a GPU?
|
|
58
58
|
|
|
@@ -67,3 +67,7 @@ Application recipes reuse prepared environments. ComfyUI protocol fixtures and L
|
|
|
67
67
|
## Reuse a GPU across tasks
|
|
68
68
|
|
|
69
69
|
A running rental can execute multiple approved commands sequentially using its instance ID and `run_command`; check status, ownership, available memory/disk and remaining original budget/deadline first. Do not use another team or personal account's resource. This does not extend its existing limits. Separate `run_job` calls and `prepare_job_rerun` do not reuse that rental. Persist results, stop when finished and reconcile release; do not retain idle GPUs just because an hour was charged. Crossing the next started hour incurs a further full-hour charge. No warm pool is promised.
|
|
70
|
+
|
|
71
|
+
## Shared-allocation task drafts
|
|
72
|
+
|
|
73
|
+
Use `prepare_task_pipeline` to review up to eight sequential commands for one Job, with one overall approved budget and deadline, stopping later steps after failure. It is read-only preparation, not a paid submission or automatic retry. Independent Jobs still provision separately. Optional pipeline-summary.json collection does not collect arbitrary task results; approve their persistence separately. No installed dependencies, model quality, or whole-hour Job compatibility are inferred.
|
package/skills/cloudgpu/SKILL.md
CHANGED
|
@@ -93,3 +93,7 @@ Sequential approved `run_command` calls may reuse a running rental within its or
|
|
|
93
93
|
## Connect with an approval link
|
|
94
94
|
|
|
95
95
|
In a configured MCP client, call `connect_account`, show the owner its link, then `finish_connect` after approval. No password or API key is pasted in chat. The link grants scoped access; it does not automatically install an MCP server in arbitrary AI products.
|
|
96
|
+
|
|
97
|
+
## Several steps on one allocation
|
|
98
|
+
|
|
99
|
+
If installed, `prepare_task_pipeline` prepares up to eight reviewed sequential commands for one Job, or for `run_command` on an approved existing rental. It creates nothing. Commands share the filesystem and GPU but use separate shells; they do not share exported shell variables or a resident model process. Failure stops later steps. Python 3, bash and prepared dependencies are required. Review the returned command, obtain a compatible quote and explicit total budget/deadline approval, then submit one Job with a stable idempotency key. Preserve the original request on a lost response. The fingerprint is informational, not approval. Optional collection saves only pipeline-summary.json, never arbitrary results or logs; approve actual result persistence separately. Existing user instance limits and lifecycle remain unchanged.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Anonymous tools intentionally omit Authorization even when this client has a key. */
|
|
3
|
+
export function registerAgentReadinessTools(server,{api,wrap,ok}){
|
|
4
|
+
server.registerTool("get_agent_readiness",{title:"Read-only Agent self-check",description:"No login or spending: capabilities, source-specific billing, task prerequisites, limitations, recent aggregate Job evidence and known issues. Unknown data is not a healthy or verified result.",inputSchema:{},annotations:{readOnlyHint:true,openWorldHint:true}},wrap(async()=>ok(await api.request("GET","/v1/public/agent-self-check",undefined,{noAuth:true}))));
|
|
5
|
+
server.registerTool("assess_task_fit",{title:"Assess whether a task fits CloudGPU",description:"Read-only task suitability before quoting a GPU. Returns blockers, unverified requirements and evidence status; does not benchmark, approve spending or guarantee availability.",inputSchema:{task_type:z.enum(["gpu_environment_check","python_batch","comfyui_video","causal_lm_lora"]),needs_persistent_outputs:z.boolean().default(true),requires_kernel_control:z.boolean().default(false),requires_nested_virtualization:z.boolean().default(false),requires_resale:z.boolean().default(false)},annotations:{readOnlyHint:true,openWorldHint:true}},wrap(async input=>ok(await api.request("POST","/v1/public/task-fit",input,{noAuth:true}))));
|
|
6
|
+
}
|
|
@@ -6,7 +6,7 @@ const relative=z.string().min(1).max(240).regex(/^[A-Za-z0-9_][A-Za-z0-9_./-]*$/
|
|
|
6
6
|
const reference=z.object({name:z.string().regex(/^[A-Za-z][A-Za-z0-9_-]{0,47}$/),repo_id:z.string().regex(/^[A-Za-z0-9][A-Za-z0-9_.-]{0,95}\/[A-Za-z0-9][A-Za-z0-9_.-]{0,95}$/),revision:z.string().regex(/^[a-f0-9]{40}$/),files:z.array(z.object({path:relative,size_bytes:z.number().int().positive(),sha256:z.string().regex(/^[a-f0-9]{64}$/)}).strict()).min(1).max(32)}).strict();
|
|
7
7
|
export const APPLICATION_TASKS=[
|
|
8
8
|
{id:'comfyui-workflow',version:1,title:'Run a reviewed ComfyUI API workflow',requires_workspace:true,requirements:['Existing ComfyUI application on GPU loopback','Reviewed API-format workflow and prepared models','Explicit output persistence'],result_files:['image-0.png','task-summary.json'],description:'Submit one workflow, poll its history and collect explicit PNG files. Uses an existing compatible image; does not install custom nodes or claim all workflows are supported.',validation:'Local HTTP protocol fixtures; real GPU generation not yet accepted'},
|
|
9
|
-
{id:'causal-lm-lora',version:
|
|
9
|
+
{id:'causal-lm-lora',version:2,title:'Train a small causal-model LoRA adapter',requires_workspace:true,requirements:['CUDA, torch, transformers, peft and safetensors already installed','Pinned public causal model reference and JSONL text dataset','Explicit output persistence'],result_files:['adapter_config.json','adapter_model.safetensors','task-summary.json'],description:'Bounded single-GPU causal-language-model LoRA, not an image/SDXL trainer. Loads only local pinned model files, disables remote model code and does not install dependencies.',validation:'Real internal CUDA smoke: SmolLM2-135M, RTX 3090, 8 synthetic-text steps, trained adapter and R2 SHA-256 verified; 190 seconds total, USD 0.0097 for the successful run. Four attempts total, including failures; not model-quality or image-LoRA validation. See /agent-evidence.json'},
|
|
10
10
|
];
|
|
11
11
|
export const applicationFields={workflow_path:relative.optional(),comfy_port:z.number().int().min(1024).max(65535).optional(),timeout_seconds:z.number().int().min(30).max(7200).optional(),image_count:z.number().int().min(1).max(4).optional(),model_reference:reference.optional(),dataset_path:relative.optional(),target_modules:z.array(z.string().regex(/^[A-Za-z_][A-Za-z0-9_]{0,63}$/)).min(1).max(8).optional(),steps:z.number().int().min(1).max(200).optional(),rank:z.number().int().min(1).max(16).optional(),sequence_length:z.number().int().min(32).max(2048).optional(),learning_rate:z.number().positive().max(0.01).optional()};
|
|
12
12
|
export function prepareApplicationRecipe(p){
|
package/src/credentials.js
CHANGED
|
@@ -11,7 +11,10 @@ export function configDir(env = process.env) {
|
|
|
11
11
|
|
|
12
12
|
export function loadStoredKey(env = process.env) {
|
|
13
13
|
try {
|
|
14
|
-
const
|
|
14
|
+
const file=path.join(configDir(env),"credentials.json"),stat=fs.lstatSync(file);
|
|
15
|
+
if(!stat.isFile()||stat.isSymbolicLink()||(stat.mode&0o077)||(process.getuid&&stat.uid!==process.getuid()))return null;
|
|
16
|
+
const j = JSON.parse(fs.readFileSync(file,"utf8"));
|
|
17
|
+
if(j.base_url!==(env.CLOUDGPU_BASE_URL||"https://cloudgpu.app"))return null;
|
|
15
18
|
if (j && typeof j.api_key === "string" && j.api_key.trim()) {
|
|
16
19
|
if (j.expires_at && Number(j.expires_at) * 1000 < Date.now()) return null;
|
|
17
20
|
return j;
|
|
@@ -23,12 +26,29 @@ export function loadStoredKey(env = process.env) {
|
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
export function saveStoredKey(cred, env = process.env) {
|
|
29
|
+
cred={...cred,base_url:cred.base_url||(env.CLOUDGPU_BASE_URL||"https://cloudgpu.app")};
|
|
26
30
|
const dir = configDir(env);
|
|
27
31
|
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
32
|
+
const info=fs.lstatSync(dir);
|
|
33
|
+
if(!info.isDirectory()||info.isSymbolicLink()||(process.getuid&&info.uid!==process.getuid())||(info.mode&0o077))throw new Error('Credential directory must be private and owned by this user.');
|
|
28
34
|
const file = path.join(dir, "credentials.json");
|
|
29
|
-
const tmp = file + ".tmp";
|
|
30
|
-
fs.writeFileSync(tmp,
|
|
31
|
-
fs.renameSync(tmp, file);
|
|
32
|
-
fs.chmodSync(file, 0o600);
|
|
35
|
+
const tmp = file + "."+process.pid+"."+Date.now()+".tmp";
|
|
36
|
+
try{fs.writeFileSync(tmp,JSON.stringify(cred,null,2),{flag:'wx',mode:0o600});fs.renameSync(tmp,file);fs.chmodSync(file,0o600);}finally{try{fs.unlinkSync(tmp);}catch{}}
|
|
33
37
|
return file;
|
|
34
38
|
}
|
|
39
|
+
|
|
40
|
+
export function loadPendingConnect(baseUrl,env=process.env){
|
|
41
|
+
try{
|
|
42
|
+
const file=path.join(configDir(env),'pending-connect.json'),stat=fs.lstatSync(file);
|
|
43
|
+
if(!stat.isFile()||stat.isSymbolicLink()||(stat.mode&0o077)||(process.getuid&&stat.uid!==process.getuid()))return null;
|
|
44
|
+
const value=JSON.parse(fs.readFileSync(file,'utf8'));
|
|
45
|
+
return value.base_url===baseUrl&&/^[a-f0-9]{64}$/.test(value.device_code)&&Number.isFinite(value.until)&&value.until>Date.now()&&value.until<=Date.now()+1801000&&Number.isFinite(value.interval)&&value.interval>=5?value:null;
|
|
46
|
+
}catch{return null;}
|
|
47
|
+
}
|
|
48
|
+
export function savePendingConnect(value,env=process.env){
|
|
49
|
+
const dir=configDir(env);fs.mkdirSync(dir,{recursive:true,mode:0o700});
|
|
50
|
+
if(fs.lstatSync(dir).isSymbolicLink())throw new Error('Credential directory must not be a symlink.');
|
|
51
|
+
const file=path.join(dir,'pending-connect.json'),tmp=file+'.'+process.pid+'.'+Date.now()+'.tmp';
|
|
52
|
+
try{fs.writeFileSync(tmp,JSON.stringify(value),{flag:'wx',mode:0o600});fs.renameSync(tmp,file);fs.chmodSync(file,0o600);}finally{try{fs.unlinkSync(tmp);}catch{}}
|
|
53
|
+
}
|
|
54
|
+
export function clearPendingConnect(env=process.env){try{fs.unlinkSync(path.join(configDir(env),'pending-connect.json'));}catch{}}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {z} from 'zod';
|
|
2
|
+
export function registerFundingTools(server,{api,wrap,ok,readOnly,sleep=ms=>new Promise(r=>setTimeout(r,ms))}){
|
|
3
|
+
if(!readOnly)server.registerTool('request_top_up',{title:'Request an owner payment link',description:'Creates a short-lived link only. No checkout, card charge or transfer is made. Show the link to the human owner; never complete payment for them. Payment completion does not approve a GPU quote.',inputSchema:{amount_usd:z.number().min(1).max(10000)},annotations:{readOnlyHint:false,destructiveHint:false,openWorldHint:true}},wrap(async({amount_usd})=>ok(await api.request('POST','/v1/billing/top-up-link',{amount_usd}))));
|
|
4
|
+
server.registerTool('wait_for_funds',{title:'Wait for credited account funds',description:'Read-only polling of actual account balance and real-top-up signal for up to 60 seconds. No payment, job submission or authorization. If still pending, return to the owner; do not blindly repeat rentals.',inputSchema:{min_balance_usd:z.number().positive().max(100000),timeout:z.number().int().min(0).max(60).default(30)},annotations:{readOnlyHint:true,openWorldHint:true}},wrap(async({min_balance_usd,timeout=30})=>{
|
|
5
|
+
const deadline=Date.now()+Math.min(60,Math.max(0,timeout))*1000;
|
|
6
|
+
for(;;){const account=await api.account();const amount=Number(account.balance_usd);const funded=account.funded===true&&Number.isFinite(amount)&&amount>=min_balance_usd;
|
|
7
|
+
if(funded||Date.now()>=deadline)return ok({ready:funded,balance_usd:account.balance_usd,last_top_up_at:account.last_top_up_at??null,top_up_url:account.top_up_url??null,next:funded?'Funds are credited. Obtain or recheck the exact quote and user approval before spending.':'Waiting for credited funds; ask the owner to finish payment. Do not submit a paid task.'});
|
|
8
|
+
await sleep(Math.min(5000,deadline-Date.now()));
|
|
9
|
+
}
|
|
10
|
+
}));
|
|
11
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import {registerFundingTools} from "./funding-tools.js";
|
|
3
|
+
import {registerAgentReadinessTools} from "./agent-readiness.js";
|
|
2
4
|
import {rentalBilling} from "./rental-billing.js";
|
|
3
5
|
import {registerComputePlanningTools} from './compute-planning.js';
|
|
6
|
+
import {registerTaskPipelineTools} from './task-pipelines.js';
|
|
4
7
|
import {registerBatchTools} from './job-batches.js';
|
|
5
8
|
import {jobInputShape} from './job-input.js';
|
|
6
9
|
import {registerTaskTemplateTools} from './task-templates.js';
|
|
@@ -22,7 +25,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
22
25
|
import { z } from "zod";
|
|
23
26
|
import { CloudGpuApi, ApiError } from "./api.js";
|
|
24
27
|
import { SshPool, exec, upload, download, writeFile } from "./ssh.js";
|
|
25
|
-
import { loadStoredKey, saveStoredKey } from "./credentials.js";
|
|
28
|
+
import { loadStoredKey, saveStoredKey, loadPendingConnect, savePendingConnect, clearPendingConnect } from "./credentials.js";
|
|
26
29
|
import crypto from "node:crypto";
|
|
27
30
|
import { registerStorageTools } from "./storage.js";
|
|
28
31
|
import { registerJobResultTools } from "./job-results.js";
|
|
@@ -37,7 +40,7 @@ import {
|
|
|
37
40
|
shq,
|
|
38
41
|
} from "./guards.js";
|
|
39
42
|
|
|
40
|
-
const VERSION = "0.
|
|
43
|
+
const VERSION = "0.16.0";
|
|
41
44
|
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
42
45
|
const RULES = fs.readFileSync(path.join(HERE, "..", "rules", "cloudgpu.md"), "utf8");
|
|
43
46
|
|
|
@@ -65,6 +68,7 @@ const session = new Map();
|
|
|
65
68
|
const INSTRUCTIONS = `CloudGPU (cloudgpu.app) provides GPU compute scheduling for AI agents from a prepaid balance. Billing is source-specific: per-minute or minimum one hour with each started hour charged in full. Never infer the period from an hourly price label.
|
|
66
69
|
Planning: compare_compute_costs compares billed GPU cost for explicit candidates and duration; it is not a benchmark or creation approval. Check existing list_instances before renting: multiple approved commands can use the same running rental within its existing budget, time and idle limits. Separate run_job calls each provision and release independently; prepare_job_rerun does not reuse a live GPU. Never extend limits or keep idle GPUs merely to consume prepaid time.
|
|
67
70
|
Batches: prepare_job_batch reviews up to eight individually quoted Jobs and their combined GPU budget. run_job_batch requires an exact approved plan hash; partial submission is possible. Retain the manifest and stable batch key to reconcile lost responses. No automatic execution retries; get_job_batch never proves independent supplier release. Storage charges are additional to GPU caps.
|
|
71
|
+
Shared allocation: prepare_task_pipeline prepares 1–8 reviewed sequential commands as a single Job draft, or for an approved existing rental. It creates nothing. Independent run_job calls do not share a GPU. Pipeline summary persistence is explicit and does not save arbitrary results or authorize storage charges.
|
|
68
72
|
Task recipes: list_task_templates and prepare_task_template return local read-only drafts, never a paid submission. Check prerequisites, quote and obtain explicit approval before run_job. Prefer local CPU processing when a GPU is unnecessary.
|
|
69
73
|
Workflow: get_account and list_gpus -> estimate_cost -> show the quote to the user and get an explicit yes -> create_instance -> get_status until running -> upload -> run_command (background for long jobs) -> tail_logs -> download results -> stop_instance -> report the actual cost.
|
|
70
74
|
Rules: never rent without the user's yes on a quote; always set a budget and time limit (the platform shuts the instance down when either is hit); download results before stop_instance because destroying an instance erases its disk; never change passwords, SSH config, the firewall or the platform's monitoring agent on the instance; if anything fails, download what exists and stop the instance rather than leaving it running.
|
|
@@ -73,8 +77,11 @@ No API key yet? connect_account gives the user a link to approve this assistant
|
|
|
73
77
|
The same API key also works for the OpenAI-compatible model API at ${cfg.baseUrl}/v1 (see list_models).`;
|
|
74
78
|
|
|
75
79
|
const server = new McpServer({ name: "cloudgpu", version: VERSION }, { instructions: INSTRUCTIONS });
|
|
80
|
+
registerFundingTools(server,{api,wrap,ok,readOnly:cfg.readOnly});
|
|
81
|
+
registerAgentReadinessTools(server,{api,wrap,ok});
|
|
76
82
|
registerTaskTemplateTools(server, {wrap, ok});
|
|
77
83
|
registerComputePlanningTools(server,{api,wrap,ok});
|
|
84
|
+
registerTaskPipelineTools(server,{cfg,wrap,ok});
|
|
78
85
|
registerBatchTools(server,{api,cfg,wrap,ok});
|
|
79
86
|
registerStorageTools(server, { api, wrap, ok, fail, readOnly: cfg.readOnly, expandHome });
|
|
80
87
|
registerJobResultTools(server, { api, wrap, ok, readOnly: cfg.readOnly });
|
|
@@ -98,7 +105,7 @@ function wrap(fn) {
|
|
|
98
105
|
if (err instanceof ApiError) {
|
|
99
106
|
let hint = "";
|
|
100
107
|
if (err.status === 401) hint = " Check CLOUDGPU_API_KEY (create one at https://cloudgpu.app/api).";
|
|
101
|
-
if (err.status === 402) hint = "
|
|
108
|
+
if (err.status === 402) hint = " Call request_top_up to give the owner a payment link, then wait_for_funds. Never submit or repeat a paid task before approval.";
|
|
102
109
|
return fail(`CloudGPU API error ${err.status} ${err.code}: ${err.message}${hint}`);
|
|
103
110
|
}
|
|
104
111
|
return fail(`Error: ${err && err.message ? err.message : String(err)}`);
|
|
@@ -242,7 +249,7 @@ server.registerTool(
|
|
|
242
249
|
if (offer.available === "low") warnings.push("Only a few of these are free; renting may fail.");
|
|
243
250
|
if (balance != null && balance < estimate * 1.1) {
|
|
244
251
|
warnings.push(
|
|
245
|
-
`Balance $${balance} does not cover the estimate plus a 10% buffer. When the balance runs out the instance is destroyed and its disk erased.
|
|
252
|
+
`Balance $${balance} does not cover the estimate plus a 10% buffer. When the balance runs out the instance is destroyed and its disk erased. Call request_top_up and wait_for_funds; obtain approval before continuing.`,
|
|
246
253
|
);
|
|
247
254
|
}
|
|
248
255
|
const quote_id = quotes.put({ gpu_model: offer.gpu_model, gpu_count, template, hourly, hours, estimate, billingQuoteId:billing.billingQuoteId, billingExpiresAt:billing.expiresAt, minimumChargeUsd:Number(billing.minimumChargeUsd), billingIncrementSeconds:increment });
|
|
@@ -290,7 +297,7 @@ server.registerTool(
|
|
|
290
297
|
|
|
291
298
|
// ── connect (get a key with a budget, approved in the browser) ──────────────
|
|
292
299
|
|
|
293
|
-
let pendingConnect =
|
|
300
|
+
let pendingConnect = loadPendingConnect(cfg.baseUrl);
|
|
294
301
|
|
|
295
302
|
server.registerTool(
|
|
296
303
|
"connect_account",
|
|
@@ -309,8 +316,11 @@ server.registerTool(
|
|
|
309
316
|
},
|
|
310
317
|
wrap(async ({ agent_name, spend_limit_usd, max_concurrent = 1, expires_in_days = 30 }) => {
|
|
311
318
|
const r = await api.connectStart({ agent_name, spend_limit_usd, max_concurrent, expires_in_days });
|
|
312
|
-
pendingConnect = { device_code: r.device_code, until: Date.now() + Number(r.expires_in ||
|
|
319
|
+
pendingConnect = { device_code: r.device_code, until: Date.now() + Number(r.expires_in || 1800) * 1000, interval: Number(r.interval || 5) };
|
|
320
|
+
savePendingConnect({...pendingConnect,base_url:cfg.baseUrl});
|
|
313
321
|
return ok({
|
|
322
|
+
google_link: r.google_link || r.verification_uri_complete,
|
|
323
|
+
email_link: r.verification_uri_complete+"&provider=email",
|
|
314
324
|
link: r.verification_uri_complete,
|
|
315
325
|
code: r.user_code,
|
|
316
326
|
expires_in_seconds: r.expires_in,
|
|
@@ -346,7 +356,7 @@ server.registerTool(
|
|
|
346
356
|
});
|
|
347
357
|
cfg.apiKey = cred.api_key;
|
|
348
358
|
api.apiKey = cred.api_key;
|
|
349
|
-
pendingConnect = null;
|
|
359
|
+
pendingConnect = null;clearPendingConnect();
|
|
350
360
|
return ok({
|
|
351
361
|
connected: true,
|
|
352
362
|
agent_name: cred.agent_name,
|
|
@@ -364,7 +374,7 @@ server.registerTool(
|
|
|
364
374
|
if (err instanceof ApiError && err.code === "authorization_pending") {
|
|
365
375
|
return fail("Not approved yet. Ask the user to open the link and approve, then call finish_connect again.");
|
|
366
376
|
}
|
|
367
|
-
if (err instanceof ApiError && (err.code === "access_denied" || err.code === "expired_token"))
|
|
377
|
+
if (err instanceof ApiError && (err.code === "access_denied" || err.code === "expired_token")){pendingConnect = null;clearPendingConnect();}
|
|
368
378
|
throw err;
|
|
369
379
|
}
|
|
370
380
|
}
|
|
@@ -479,7 +489,7 @@ if (!cfg.readOnly) {
|
|
|
479
489
|
const needed = round2(Math.min(max_spend_usd, quote.estimate) * 1.1);
|
|
480
490
|
if (balance < needed) {
|
|
481
491
|
return fail(
|
|
482
|
-
`Not rented: balance $${balance} is below $${needed} (the estimate or budget plus 10%). If the balance runs out the instance is destroyed and its disk erased.
|
|
492
|
+
`Not rented: balance $${balance} is below $${needed} (the estimate or budget plus 10%). If the balance runs out the instance is destroyed and its disk erased. Call request_top_up and wait_for_funds; obtain approval before continuing.`,
|
|
483
493
|
);
|
|
484
494
|
}
|
|
485
495
|
const body = {
|
package/src/model-references.js
CHANGED
|
@@ -23,10 +23,10 @@ export async function resolveModelReference({repo_id, revision = "main", name, f
|
|
|
23
23
|
return {path,size_bytes:size,...(sha?{sha256:sha}:{})};
|
|
24
24
|
});
|
|
25
25
|
if(selected.reduce((n,f)=>n+f.size_bytes,0)>100_000_000_000)throw new Error("Model exceeds the first-version 100 GB job limit");
|
|
26
|
-
// Git-backed config files have no LFS SHA. Hash bounded public JSON metadata
|
|
26
|
+
// Git-backed tokenizer/config files have no LFS SHA. Bound each to 4 MiB and all to 8 MiB. Hash bounded public JSON metadata
|
|
27
27
|
// on the origin so the GPU can verify it even when using its existing mirror.
|
|
28
|
-
const configs=selected.filter(f=>!f.sha256
|
|
29
|
-
if(configs.length>8)throw new Error('Too many unhashed JSON metadata files; supply an independently verified manifest');
|
|
28
|
+
const configs=selected.filter(f=>!f.sha256&&/\.(json|txt|model|tiktoken)$/.test(f.path)&&f.size_bytes<=4*1024*1024);
|
|
29
|
+
if(configs.length>8||configs.reduce((total,f)=>total+f.size_bytes,0)>8*1024*1024)throw new Error('Too many unhashed JSON metadata files; supply an independently verified manifest');
|
|
30
30
|
const deadline=Date.now()+15000;
|
|
31
31
|
for(const file of configs){
|
|
32
32
|
const remaining=deadline-Date.now();
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import importlib.util,json,math,os,pathlib,stat
|
|
2
2
|
|
|
3
|
+
def training_dtype(torch):
|
|
4
|
+
# Device capability alone does not guarantee the installed torch CUDA kernels.
|
|
5
|
+
if not torch.cuda.is_bf16_supported(): return torch.float32
|
|
6
|
+
try:
|
|
7
|
+
torch.triu(torch.ones((2,2),device='cuda',dtype=torch.bfloat16),diagonal=1)
|
|
8
|
+
except RuntimeError as error:
|
|
9
|
+
if 'not implemented' not in str(error): raise
|
|
10
|
+
return torch.float32
|
|
11
|
+
return torch.bfloat16
|
|
12
|
+
|
|
3
13
|
def run(options, project_file, output_dir):
|
|
4
14
|
# Reuse a reviewed image; do not reinstall CUDA/torch or run remote model code.
|
|
5
15
|
if any(importlib.util.find_spec(m) is None for m in ['torch','transformers','peft','safetensors']):
|
|
@@ -23,7 +33,7 @@ def run(options, project_file, output_dir):
|
|
|
23
33
|
os.environ['HF_HUB_OFFLINE']='1';os.environ['TRANSFORMERS_OFFLINE']='1';os.environ['HF_HUB_DISABLE_TELEMETRY']='1'
|
|
24
34
|
torch.manual_seed(0)
|
|
25
35
|
tokenizer=AutoTokenizer.from_pretrained(str(model_root),local_files_only=True,trust_remote_code=False)
|
|
26
|
-
dtype=torch
|
|
36
|
+
dtype=training_dtype(torch)
|
|
27
37
|
model=AutoModelForCausalLM.from_pretrained(str(model_root),local_files_only=True,trust_remote_code=False,torch_dtype=dtype).to('cuda')
|
|
28
38
|
model=get_peft_model(model,LoraConfig(r=options['rank'],lora_alpha=options['rank']*2,lora_dropout=0.05,bias='none',task_type='CAUSAL_LM',target_modules=options['target_modules']))
|
|
29
39
|
model.train();optimizer=torch.optim.AdamW((p for p in model.parameters() if p.requires_grad),lr=options['learning_rate'])
|
|
@@ -43,4 +53,4 @@ def run(options, project_file, output_dir):
|
|
|
43
53
|
p=output_dir/name
|
|
44
54
|
if p.is_symlink() or not stat.S_ISREG(p.stat().st_mode) or p.stat().st_size<=0:
|
|
45
55
|
raise ValueError('Expected adapter output missing')
|
|
46
|
-
return {'task':'causal-lm-lora','steps_completed':options['steps'],'records':len(texts),'last_loss':loss_value,'base_model':ref['repo_id'],'revision':ref['revision'],'rank':options['rank']}
|
|
56
|
+
return {'task':'causal-lm-lora','steps_completed':options['steps'],'records':len(texts),'last_loss':loss_value,'base_model':ref['repo_id'],'revision':ref['revision'],'rank':options['rank'],'training_dtype':str(dtype)}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import os, pathlib, subprocess, sys
|
|
2
|
+
|
|
3
|
+
report={'pipeline_sha256':options['pipeline_sha256'],'state':'running','steps':[]}
|
|
4
|
+
fd=None
|
|
5
|
+
if options['persist_summary']:
|
|
6
|
+
root=os.environ.get('CLOUDGPU_OUTPUT_DIR')
|
|
7
|
+
if not root: raise RuntimeError('Explicit output collection directory is required')
|
|
8
|
+
target=pathlib.Path(root)/'pipeline-summary.json'
|
|
9
|
+
fd=os.open(str(target),os.O_WRONLY|os.O_CREAT|os.O_EXCL|getattr(os,'O_NOFOLLOW',0),0o600)
|
|
10
|
+
|
|
11
|
+
def record():
|
|
12
|
+
if fd is not None:
|
|
13
|
+
data=json.dumps(report,sort_keys=True).encode('utf-8')
|
|
14
|
+
os.lseek(fd,0,os.SEEK_SET)
|
|
15
|
+
os.ftruncate(fd,0)
|
|
16
|
+
view=memoryview(data)
|
|
17
|
+
while view:
|
|
18
|
+
written=os.write(fd,view)
|
|
19
|
+
if written<=0: raise RuntimeError('Summary could not be recorded')
|
|
20
|
+
view=view[written:]
|
|
21
|
+
os.fsync(fd)
|
|
22
|
+
|
|
23
|
+
exit_code=0
|
|
24
|
+
try:
|
|
25
|
+
record()
|
|
26
|
+
for step in options['steps']:
|
|
27
|
+
result=subprocess.run(['bash','-e','-o','pipefail','-c',step['command']],check=False)
|
|
28
|
+
report['steps'].append({'id':step['id'],'exit_code':result.returncode})
|
|
29
|
+
if result.returncode:
|
|
30
|
+
report['state']='failed'
|
|
31
|
+
exit_code=result.returncode if 0<result.returncode<256 else 1
|
|
32
|
+
record()
|
|
33
|
+
break
|
|
34
|
+
record()
|
|
35
|
+
else:
|
|
36
|
+
report['state']='succeeded'
|
|
37
|
+
record()
|
|
38
|
+
finally:
|
|
39
|
+
if fd is not None: os.close(fd)
|
|
40
|
+
print(json.dumps(report,sort_keys=True))
|
|
41
|
+
sys.exit(exit_code)
|
package/src/storage.js
CHANGED
|
@@ -1,62 +1,95 @@
|
|
|
1
1
|
// 持久文件直接流向对象存储;长期 key 只发给 CloudGPU,不发给签名 URL 的主机。
|
|
2
2
|
import fs from "node:fs";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
3
4
|
import fsp from "node:fs/promises";
|
|
4
5
|
import path from "node:path";
|
|
5
|
-
|
|
6
|
-
import { Readable
|
|
6
|
+
|
|
7
|
+
import { Readable } from "node:stream";
|
|
7
8
|
import { sensitiveReason } from "./guards.js";
|
|
8
9
|
import { z } from "zod";
|
|
9
10
|
|
|
10
11
|
export class PersistentStorage {
|
|
11
12
|
constructor(api, fetchImpl = globalThis.fetch) { this.api = api; this.fetch = fetchImpl; }
|
|
12
|
-
async
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
13
|
+
async digest(local) {
|
|
14
|
+
const hash = createHash("sha256");
|
|
15
|
+
for await (const chunk of fs.createReadStream(local)) hash.update(chunk);
|
|
16
|
+
return hash.digest("hex");
|
|
17
|
+
}
|
|
18
|
+
async upload(local, purpose = "artifact", name = path.basename(local), acceptStorageCharges = false, resume) {
|
|
19
|
+
const stat = await fsp.lstat(local);
|
|
20
|
+
if (!stat.isFile() || stat.isSymbolicLink()) throw new Error("Upload needs a regular file.");
|
|
21
|
+
const digest = await this.digest(local);
|
|
22
|
+
if (resume && digest !== resume.sha256) throw new Error("Local file differs from the original upload; do not mix file versions.");
|
|
23
|
+
const file = resume
|
|
24
|
+
? await this.api.request("GET", `/v1/files/${encodeURIComponent(resume.file_id)}/upload`)
|
|
25
|
+
: await this.api.request("POST", "/v1/files", { name, purpose, size_bytes: stat.size, accept_storage_charges: acceptStorageCharges === true });
|
|
26
|
+
if (resume && (Number(file.size_bytes) !== stat.size || file.name !== name)) throw new Error("Upload reservation differs from local file.");
|
|
27
|
+
const uploaded = new Set((file.uploaded_parts || []).map(p => Number(p.part_number)));
|
|
28
|
+
let offset = 0;
|
|
29
|
+
for (let i = 1; i <= file.part_count; i++) {
|
|
30
|
+
const expected = Math.min(Number(file.part_size_bytes), stat.size - offset);
|
|
31
|
+
if (!uploaded.has(i)) {
|
|
32
|
+
let done = false;
|
|
33
|
+
for (let attempt = 0; attempt < 3 && !done; attempt++) {
|
|
34
|
+
try {
|
|
35
|
+
const part = await this.api.request("POST", `/v1/files/${file.file_id}/parts/${i}`, {});
|
|
36
|
+
if (!String(part.url).startsWith("https://") || Number(part.content_length) !== expected) throw new Error("Invalid upload reservation.");
|
|
37
|
+
const stream = expected === 0 ? Buffer.alloc(0) : fs.createReadStream(local, { start: offset, end: offset + expected - 1 });
|
|
38
|
+
try {
|
|
39
|
+
const response = await this.fetch(part.url, { method: "PUT", headers: { "Content-Length": String(expected) }, body: stream, duplex: "half", redirect: "error", signal: AbortSignal.timeout(300000) });
|
|
40
|
+
if (response.body) await response.body.cancel();
|
|
41
|
+
if (!response.ok) throw new Error("Part failed.");
|
|
42
|
+
done = true;
|
|
43
|
+
} finally { if (stream.destroy) stream.destroy(); }
|
|
44
|
+
} catch { /* Renew only this part; never allocate a second reservation. */ }
|
|
45
|
+
}
|
|
46
|
+
if (!done) throw new Error(`Upload paused. Resume file_id=${file.file_id}, sha256=${digest}; reservation expires after 24 hours. No signed URL is retained.`);
|
|
30
47
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
48
|
+
offset += expected;
|
|
49
|
+
}
|
|
50
|
+
const after = await fsp.stat(local);
|
|
51
|
+
if (after.size !== stat.size || after.mtimeMs !== stat.mtimeMs || await this.digest(local) !== digest) {
|
|
35
52
|
await this.api.request("DELETE", `/v1/files/${file.file_id}`).catch(() => {});
|
|
36
|
-
throw
|
|
53
|
+
throw new Error("File changed during upload; snapshot was not saved.");
|
|
37
54
|
}
|
|
55
|
+
try { return await this.api.request("POST", `/v1/files/${file.file_id}/complete`, {}); }
|
|
56
|
+
catch { throw new Error(`Upload completion uncertain for file_id=${file.file_id}. Check list_files and retry completion; do not delete or create another upload.`); }
|
|
38
57
|
}
|
|
39
58
|
async download(id, local) {
|
|
40
|
-
const transfer = await this.api.request("POST", `/v1/files/${encodeURIComponent(id)}/download`, {});
|
|
41
|
-
if (!String(transfer.url).startsWith("https://")) throw new Error("Storage must use HTTPS.");
|
|
42
|
-
const expected = Number(transfer.size_bytes);
|
|
43
|
-
if (!Number.isSafeInteger(expected) || expected < 0) throw new Error("Invalid file size.");
|
|
44
59
|
await fsp.mkdir(path.dirname(local), { recursive: true });
|
|
45
|
-
const handle = await fsp.open(local, "wx", 0o600);
|
|
60
|
+
const handle = await fsp.open(local, "wx", 0o600);
|
|
61
|
+
let received = 0, expected;
|
|
46
62
|
try {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
63
|
+
for (let attempt = 0; attempt < 4; attempt++) {
|
|
64
|
+
try {
|
|
65
|
+
const transfer = await this.api.request("POST", `/v1/files/${encodeURIComponent(id)}/download`, {});
|
|
66
|
+
if (!String(transfer.url).startsWith("https://")) throw new Error("HTTPS required.");
|
|
67
|
+
const size = Number(transfer.size_bytes);
|
|
68
|
+
if (!Number.isSafeInteger(size) || size < 0 || (expected !== undefined && expected !== size)) throw new Error("Invalid immutable file size.");
|
|
69
|
+
expected = size;
|
|
70
|
+
const response = await this.fetch(transfer.url, { redirect: "error", headers: received ? { Range: `bytes=${received}-` } : {}, signal: AbortSignal.timeout(300000) });
|
|
71
|
+
try {
|
|
72
|
+
if (!response.ok || !response.body) throw new Error("Download failed.");
|
|
73
|
+
if (received && (response.status !== 206 || response.headers.get("content-range") !== `bytes ${received}-${expected - 1}/${expected}`)) throw new Error("Invalid resume range.");
|
|
74
|
+
for await (const chunk of Readable.fromWeb(response.body)) {
|
|
75
|
+
if (received + chunk.length > expected) throw new Error("Excess file bytes.");
|
|
76
|
+
let written = 0;
|
|
77
|
+
while (written < chunk.length) {
|
|
78
|
+
const result = await handle.write(chunk, written, chunk.length - written, received + written);
|
|
79
|
+
if (!result.bytesWritten) throw new Error("Local write failed.");
|
|
80
|
+
written += result.bytesWritten;
|
|
81
|
+
}
|
|
82
|
+
received += chunk.length;
|
|
83
|
+
}
|
|
84
|
+
} finally { if (response.body && !response.body.locked) await response.body.cancel().catch(() => {}); }
|
|
85
|
+
if (received !== expected) throw new Error("Incomplete download.");
|
|
86
|
+
await handle.close();
|
|
87
|
+
return { local_path: local, bytes: expected };
|
|
88
|
+
} catch { if (attempt === 3) throw new Error("Transfer failed."); }
|
|
89
|
+
}
|
|
57
90
|
} catch {
|
|
58
91
|
await handle.close().catch(() => {}); await fsp.unlink(local).catch(() => {});
|
|
59
|
-
throw new Error("Storage download failed; the partial file was removed.");
|
|
92
|
+
throw new Error("Storage download failed after bounded resume attempts; the partial file was removed.");
|
|
60
93
|
}
|
|
61
94
|
}
|
|
62
95
|
async saveWorkspace(localDir, name, workspaceId, acceptStorageCharges = false) {
|
|
@@ -100,6 +133,18 @@ export function registerStorageTools(server, { api, wrap, ok, fail, readOnly, ex
|
|
|
100
133
|
server.registerTool("list_workspace_instances", { title: "Running GPUs for Workspace restore", description: "Lists your running GPUs that this key may access. Budgeted Agent keys only see instances created by the same key.", inputSchema: {}, annotations: { readOnlyHint: true } }, wrap(async () => ok(await api.request("GET", "/v1/workspace-instances"))));
|
|
101
134
|
server.registerTool("get_workspace_application", { title: "Workspace application status", description: "Check file restoration on an existing GPU. This does not create, stop or restart a GPU. An uncertain result must be checked, never automatically resubmitted.", inputSchema: { version_id: z.string(), instance_id: z.string().regex(/^[0-9]{1,32}$/) }, annotations: { readOnlyHint: true } }, wrap(async ({ version_id, instance_id }) => ok(await api.request("GET", `/v1/workspace-versions/${encodeURIComponent(version_id)}/applications/${encodeURIComponent(instance_id)}`))));
|
|
102
135
|
if (readOnly) return;
|
|
136
|
+
server.registerTool("quote_storage_budget", {
|
|
137
|
+
title: "Quote separate storage budget", description: "Quote reserving GPU wallet funds for persistent storage, or returning unused surplus. No transfer yet. Shows USD rate, budget-based capacity and 30-day file expiry. Budget-limited keys cannot move funds; ask owner to use Web or unrestricted key.",
|
|
138
|
+
inputSchema: { action: z.enum(["reserve", "release"]), amount_usd: z.number().positive().max(1000000) }, annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true },
|
|
139
|
+
}, wrap(async ({ action, amount_usd }) => ok(await api.request("POST", "/v1/storage/budget/quotes", { action, amount_usd }))));
|
|
140
|
+
server.registerTool("confirm_storage_budget", {
|
|
141
|
+
title: "Confirm storage budget transfer", description: "Moves wallet funds only after the user approves the exact quote. Retrying the same quote cannot transfer twice. Reservation is not billed usage; daily actual peak consumes the budget. Never approve automatically.",
|
|
142
|
+
inputSchema: { quote_id: z.string().regex(/^sbq_[a-f0-9]{32}$/), user_confirmed: z.boolean() }, annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true },
|
|
143
|
+
}, wrap(async ({ quote_id, user_confirmed }) => user_confirmed === true ? ok(await api.request("POST", `/v1/storage/budget/quotes/${quote_id}/confirm`, { user_confirmed })) : fail("Ask the user to approve the exact storage quote first.")));
|
|
144
|
+
server.registerTool("resume_artifact_upload", {
|
|
145
|
+
title: "Resume interrupted file upload", description: "Resume the same unexpired multipart reservation. Requires the original SHA-256 reported when upload paused. Skips completed parts; renews expiring URLs. Never mixes changed files or creates another reservation.",
|
|
146
|
+
inputSchema: { local_path: z.string(), file_id: z.string().regex(/^file_[a-f0-9]{32}$/), sha256: z.string().regex(/^[a-f0-9]{64}$/) }, annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true },
|
|
147
|
+
}, wrap(async ({ local_path, file_id, sha256 }) => { const local = path.resolve(expandHome(local_path)); if (sensitiveReason(local)) return fail("Credential files cannot be uploaded."); return ok(await client.upload(local, "artifact", path.basename(local), false, { file_id, sha256 })); }));
|
|
103
148
|
server.registerTool("apply_workspace", {
|
|
104
149
|
title: "Apply Workspace to running GPU", description: "Restore project files to a new private directory on your existing running GPU. Does not install dependencies, execute code, overwrite existing files, rent, restart or stop a GPU. GPU rental billing continues; transfer consumes its network and disk. Ask the user before applying. Repeat requests for the same version and instance return the existing result; failures require inspection, not automatic retries.",
|
|
105
150
|
inputSchema: { version_id: z.string(), instance_id: z.string().regex(/^[0-9]{1,32}$/), user_confirmed: z.boolean() }, annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import {createHash} from 'node:crypto';
|
|
3
|
+
import {z} from 'zod';
|
|
4
|
+
import {checkCommand} from './guards.js';
|
|
5
|
+
import {checkedTail} from './job-results.js';
|
|
6
|
+
|
|
7
|
+
const input=z.object({
|
|
8
|
+
steps:z.array(z.object({id:z.string().regex(/^[a-z][a-z0-9_-]{0,39}$/).refine(v=>v.trim()===v),command:z.string().min(1).max(4096)}).strict()).min(1).max(8),
|
|
9
|
+
workspace_version_id:z.string().regex(/^wsv_[a-f0-9]{32}$/).refine(v=>v.trim()===v).optional(),
|
|
10
|
+
persist_summary:z.boolean().default(false),
|
|
11
|
+
}).strict();
|
|
12
|
+
const program=fs.readFileSync(new URL('./recipes/task-pipeline.py',import.meta.url),'utf8');
|
|
13
|
+
export function prepareTaskPipeline(raw,apiKey='') {
|
|
14
|
+
const p=input.parse(raw);
|
|
15
|
+
if(new Set(p.steps.map(s=>s.id)).size!==p.steps.length)throw Error('Pipeline step IDs must be unique.');
|
|
16
|
+
for(const step of p.steps) {
|
|
17
|
+
if(!step.command.trim()||step.command.includes('\0'))throw Error('Pipeline commands must be nonempty and contain no NUL.');
|
|
18
|
+
const refused=checkCommand(step.command);if(refused)throw Error(refused);
|
|
19
|
+
try{checkedTail(step.command,apiKey);}catch{throw Error('Pipeline command may contain credentials or a queried URL. Remove sensitive input before preparation.');}
|
|
20
|
+
}
|
|
21
|
+
const fingerprint=createHash('sha256').update(JSON.stringify(p)).digest('hex');
|
|
22
|
+
const options={...p,pipeline_sha256:fingerprint};
|
|
23
|
+
const command="python3 - <<'CGPU_PIPELINE'\nimport json\noptions=json.loads("+JSON.stringify(JSON.stringify(options))+")\n"+program+'\nCGPU_PIPELINE';
|
|
24
|
+
if(Buffer.byteLength(command)>32768)throw Error('Combined pipeline exceeds the execution size limit.');
|
|
25
|
+
return {requirements:['Python 3','bash','Reviewed commands and prepared dependencies'],preparation_only:true,starts_gpu:false,pipeline_sha256:fingerprint,steps:p.steps,
|
|
26
|
+
run_job_draft:{command,...(p.workspace_version_id?{workspace_version_id:p.workspace_version_id}:{}),...(p.persist_summary?{outputs:{files:['pipeline-summary.json'],max_bytes:1048576,accept_storage_charges:false}}:{})},
|
|
27
|
+
execution:'Sequential child shells in one GPU allocation. Shared filesystem and GPU; shell variables and in-memory model processes do not persist between steps. First failure stops later steps. No execution retry.',
|
|
28
|
+
next:'Review every command and prerequisites. Obtain a fresh compatible Job quote and explicit GPU/budget/time approval, then call run_job once with a stable idempotency key. Preserve that key on a lost response. This fingerprint is not server approval or an idempotency key.',
|
|
29
|
+
existing_rental:'The command can instead run with run_command on an owned, ready, explicitly approved existing rental within its original limits. Apply any Workspace separately and use its returned working directory. This preparation never applies files, extends limits or stops an existing user instance. With persist_summary=true, use the Job output collector; preparation does not configure an output directory on an existing rental.',
|
|
30
|
+
storage_note:p.persist_summary?'Summary persists only through enabled automatic output collection and existing quota/retention/fees. It contains step IDs, exit codes and state, not commands or output. No other results are collected by this draft; declare and approve result persistence separately.':'No persistent output collection requested. Save results explicitly before release.',
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function registerTaskPipelineTools(server,{wrap,ok,cfg}) {
|
|
34
|
+
server.registerTool('prepare_task_pipeline',{
|
|
35
|
+
title:'Prepare sequential tasks for one GPU allocation',
|
|
36
|
+
description:'Local read-only preparation of 1–8 reviewed commands for one bounded Job or an approved existing rental. Reuses GPU and disk across steps; stops on the first error. Does not create, retry, install dependencies, approve spending or change an instance lifecycle. Summary persistence is optional and never implies paid-storage consent.',
|
|
37
|
+
inputSchema:input.shape,annotations:{readOnlyHint:true,destructiveHint:false,idempotentHint:true,openWorldHint:false},
|
|
38
|
+
},wrap(async p=>ok(prepareTaskPipeline(p,cfg.apiKey))));
|
|
39
|
+
}
|