@tpmjs/tools-sprites-checkpoint-create 0.1.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/dist/index.d.ts +21 -0
- package/dist/index.js +95 -0
- package/package.json +50 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as ai from 'ai';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sprites Checkpoint Create Tool for TPMJS
|
|
5
|
+
* Creates a point-in-time snapshot of a sprite's filesystem state for later restoration.
|
|
6
|
+
*
|
|
7
|
+
* @requires SPRITES_TOKEN environment variable
|
|
8
|
+
*/
|
|
9
|
+
interface Checkpoint {
|
|
10
|
+
id: string;
|
|
11
|
+
name?: string;
|
|
12
|
+
createdAt: string;
|
|
13
|
+
size?: number;
|
|
14
|
+
}
|
|
15
|
+
type SpritesCheckpointCreateInput = {
|
|
16
|
+
name: string;
|
|
17
|
+
checkpointName?: string;
|
|
18
|
+
};
|
|
19
|
+
declare const spritesCheckpointCreateTool: ai.Tool<SpritesCheckpointCreateInput, Checkpoint>;
|
|
20
|
+
|
|
21
|
+
export { type Checkpoint, spritesCheckpointCreateTool as default, spritesCheckpointCreateTool };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { tool, jsonSchema } from 'ai';
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
var SPRITES_API_BASE = "https://api.sprites.dev/v1";
|
|
5
|
+
function getSpritesToken() {
|
|
6
|
+
const token = process.env.SPRITES_TOKEN;
|
|
7
|
+
if (!token) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
"SPRITES_TOKEN environment variable is required. Get your token from https://sprites.dev"
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
return token;
|
|
13
|
+
}
|
|
14
|
+
var spritesCheckpointCreateTool = tool({
|
|
15
|
+
description: "Create a point-in-time snapshot (checkpoint) of a sprite's filesystem state for later restoration. Useful for saving state before risky operations.",
|
|
16
|
+
inputSchema: jsonSchema({
|
|
17
|
+
type: "object",
|
|
18
|
+
properties: {
|
|
19
|
+
name: {
|
|
20
|
+
type: "string",
|
|
21
|
+
description: "Name of the sprite to checkpoint"
|
|
22
|
+
},
|
|
23
|
+
checkpointName: {
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "Optional human-readable name for the checkpoint"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
required: ["name"],
|
|
29
|
+
additionalProperties: false
|
|
30
|
+
}),
|
|
31
|
+
async execute({ name, checkpointName }) {
|
|
32
|
+
if (!name || typeof name !== "string") {
|
|
33
|
+
throw new Error("Sprite name is required and must be a string");
|
|
34
|
+
}
|
|
35
|
+
const token = getSpritesToken();
|
|
36
|
+
let response;
|
|
37
|
+
try {
|
|
38
|
+
const controller = new AbortController();
|
|
39
|
+
const timeoutId = setTimeout(() => controller.abort(), 12e4);
|
|
40
|
+
const body = {};
|
|
41
|
+
if (checkpointName) {
|
|
42
|
+
body.name = checkpointName;
|
|
43
|
+
}
|
|
44
|
+
response = await fetch(
|
|
45
|
+
`${SPRITES_API_BASE}/sprites/${encodeURIComponent(name)}/checkpoints`,
|
|
46
|
+
{
|
|
47
|
+
method: "POST",
|
|
48
|
+
headers: {
|
|
49
|
+
Authorization: `Bearer ${token}`,
|
|
50
|
+
"Content-Type": "application/json",
|
|
51
|
+
"User-Agent": "TPMJS/1.0"
|
|
52
|
+
},
|
|
53
|
+
body: JSON.stringify(body),
|
|
54
|
+
signal: controller.signal
|
|
55
|
+
}
|
|
56
|
+
);
|
|
57
|
+
clearTimeout(timeoutId);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
if (error instanceof Error) {
|
|
60
|
+
if (error.name === "AbortError") {
|
|
61
|
+
throw new Error(`Request to create checkpoint for sprite "${name}" timed out`);
|
|
62
|
+
}
|
|
63
|
+
throw new Error(`Failed to create checkpoint for sprite "${name}": ${error.message}`);
|
|
64
|
+
}
|
|
65
|
+
throw new Error(`Failed to create checkpoint for sprite "${name}": Unknown network error`);
|
|
66
|
+
}
|
|
67
|
+
if (!response.ok) {
|
|
68
|
+
if (response.status === 404) {
|
|
69
|
+
throw new Error(`Sprite "${name}" not found`);
|
|
70
|
+
}
|
|
71
|
+
if (response.status === 401) {
|
|
72
|
+
throw new Error("Invalid SPRITES_TOKEN. Check your API token at https://sprites.dev");
|
|
73
|
+
}
|
|
74
|
+
const errorText = await response.text().catch(() => "Unknown error");
|
|
75
|
+
throw new Error(
|
|
76
|
+
`Failed to create checkpoint for sprite "${name}": HTTP ${response.status} - ${errorText}`
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
let data;
|
|
80
|
+
try {
|
|
81
|
+
data = await response.json();
|
|
82
|
+
} catch {
|
|
83
|
+
throw new Error("Failed to parse response from Sprites API");
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
id: data.id || "",
|
|
87
|
+
name: data.name || checkpointName,
|
|
88
|
+
createdAt: data.createdAt || data.created_at || (/* @__PURE__ */ new Date()).toISOString(),
|
|
89
|
+
size: data.size
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
var index_default = spritesCheckpointCreateTool;
|
|
94
|
+
|
|
95
|
+
export { index_default as default, spritesCheckpointCreateTool };
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tpmjs/tools-sprites-checkpoint-create",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Create a point-in-time snapshot of a sprite's filesystem state for later restoration",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"keywords": ["tpmjs", "sprites", "sandbox", "checkpoint", "snapshot", "ai"],
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": ["dist"],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsup",
|
|
16
|
+
"dev": "tsup --watch",
|
|
17
|
+
"type-check": "tsc --noEmit",
|
|
18
|
+
"clean": "rm -rf dist .turbo"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@tpmjs/tsconfig": "workspace:*",
|
|
22
|
+
"tsup": "^8.5.1",
|
|
23
|
+
"typescript": "^5.9.3"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": { "access": "public" },
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/anthropics/tpmjs.git",
|
|
29
|
+
"directory": "packages/tools/official/sprites-checkpoint-create"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://tpmjs.com",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"tpmjs": {
|
|
34
|
+
"category": "sandbox",
|
|
35
|
+
"frameworks": ["vercel-ai"],
|
|
36
|
+
"tools": [{
|
|
37
|
+
"name": "spritesCheckpointCreateTool",
|
|
38
|
+
"description": "Create a point-in-time snapshot of a sprite's filesystem state for later restoration",
|
|
39
|
+
"parameters": [
|
|
40
|
+
{ "name": "name", "type": "string", "description": "Name of the sprite to checkpoint", "required": true },
|
|
41
|
+
{ "name": "checkpointName", "type": "string", "description": "Optional name for the checkpoint", "required": false }
|
|
42
|
+
],
|
|
43
|
+
"returns": {
|
|
44
|
+
"type": "Checkpoint",
|
|
45
|
+
"description": "Created checkpoint with ID and metadata"
|
|
46
|
+
}
|
|
47
|
+
}]
|
|
48
|
+
},
|
|
49
|
+
"dependencies": { "ai": "6.0.23" }
|
|
50
|
+
}
|