@tpmjs/tools-sprites-checkpoint-create 0.1.1 → 0.1.3

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.
Files changed (4) hide show
  1. package/README.md +68 -0
  2. package/dist/index.js +31 -8
  3. package/package.json +10 -10
  4. package/LICENSE +0 -21
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # @tpmjs/sprites-checkpoint-create
2
+
3
+ Create a point-in-time snapshot (checkpoint) of a sprite's filesystem state for later restoration.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @tpmjs/sprites-checkpoint-create
9
+ ```
10
+
11
+ ## Requirements
12
+
13
+ - `SPRITES_TOKEN` environment variable - Get your token from https://sprites.dev
14
+
15
+ ## Usage
16
+
17
+ ```typescript
18
+ import { spritesCheckpointCreateTool } from '@tpmjs/sprites-checkpoint-create';
19
+
20
+ const result = await spritesCheckpointCreateTool.execute({
21
+ name: 'my-sandbox',
22
+ checkpointName: 'before-experiment'
23
+ });
24
+
25
+ console.log(result);
26
+ // {
27
+ // id: 'chk_abc123',
28
+ // name: 'before-experiment',
29
+ // createdAt: '2024-01-15T10:30:00Z',
30
+ // size: 52428800
31
+ // }
32
+ ```
33
+
34
+ ## Input Parameters
35
+
36
+ | Parameter | Type | Required | Description |
37
+ |-----------|------|----------|-------------|
38
+ | `name` | `string` | Yes | Name of the sprite to checkpoint |
39
+ | `checkpointName` | `string` | No | Optional human-readable name for the checkpoint |
40
+
41
+ ## Output
42
+
43
+ | Field | Type | Description |
44
+ |-------|------|-------------|
45
+ | `id` | `string` | Unique checkpoint identifier (use this for restore) |
46
+ | `name` | `string?` | Human-readable checkpoint name if provided |
47
+ | `createdAt` | `string` | ISO 8601 timestamp of creation |
48
+ | `size` | `number?` | Checkpoint size in bytes |
49
+
50
+ ## Use Cases
51
+
52
+ - Save state before risky operations
53
+ - Create restore points for experiments
54
+ - Backup filesystem before installing packages
55
+ - Version control for sprite state
56
+
57
+ ## Error Handling
58
+
59
+ The tool throws errors in these cases:
60
+ - `SPRITES_TOKEN` environment variable is not set
61
+ - Sprite not found (HTTP 404)
62
+ - Invalid or expired API token (HTTP 401)
63
+ - Network timeout (120 second limit for large checkpoints)
64
+ - API errors with descriptive messages
65
+
66
+ ## License
67
+
68
+ MIT
package/dist/index.js CHANGED
@@ -42,7 +42,7 @@ var spritesCheckpointCreateTool = tool({
42
42
  body.name = checkpointName;
43
43
  }
44
44
  response = await fetch(
45
- `${SPRITES_API_BASE}/sprites/${encodeURIComponent(name)}/checkpoints`,
45
+ `${SPRITES_API_BASE}/sprites/${encodeURIComponent(name)}/checkpoint`,
46
46
  {
47
47
  method: "POST",
48
48
  headers: {
@@ -76,17 +76,40 @@ var spritesCheckpointCreateTool = tool({
76
76
  `Failed to create checkpoint for sprite "${name}": HTTP ${response.status} - ${errorText}`
77
77
  );
78
78
  }
79
- let data;
79
+ let text;
80
80
  try {
81
- data = await response.json();
81
+ text = await response.text();
82
82
  } catch {
83
- throw new Error("Failed to parse response from Sprites API");
83
+ throw new Error("Failed to read response from Sprites API");
84
+ }
85
+ const lines = text.trim().split("\n").filter((line) => line.trim());
86
+ let checkpointData = null;
87
+ for (const line of lines) {
88
+ try {
89
+ const parsed = JSON.parse(line);
90
+ if (parsed.id || parsed.checkpoint_id) {
91
+ checkpointData = parsed;
92
+ }
93
+ if (parsed.error) {
94
+ throw new Error(`Checkpoint creation failed: ${parsed.error}`);
95
+ }
96
+ } catch (parseError) {
97
+ if (parseError instanceof SyntaxError) continue;
98
+ throw parseError;
99
+ }
100
+ }
101
+ if (!checkpointData) {
102
+ try {
103
+ checkpointData = JSON.parse(text);
104
+ } catch {
105
+ throw new Error(`Failed to parse checkpoint response. Raw response: ${text.slice(0, 200)}`);
106
+ }
84
107
  }
85
108
  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
109
+ id: checkpointData.id || checkpointData.checkpoint_id || "",
110
+ name: checkpointData.name || checkpointName,
111
+ createdAt: checkpointData.createdAt || checkpointData.created_at || (/* @__PURE__ */ new Date()).toISOString(),
112
+ size: checkpointData.size
90
113
  };
91
114
  }
92
115
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tpmjs/tools-sprites-checkpoint-create",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Create a point-in-time snapshot of a sprite's filesystem state for later restoration",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -20,10 +20,16 @@
20
20
  "files": [
21
21
  "dist"
22
22
  ],
23
+ "scripts": {
24
+ "build": "tsup",
25
+ "dev": "tsup --watch",
26
+ "type-check": "tsc --noEmit",
27
+ "clean": "rm -rf dist .turbo"
28
+ },
23
29
  "devDependencies": {
30
+ "@tpmjs/tsconfig": "workspace:*",
24
31
  "tsup": "^8.5.1",
25
- "typescript": "^5.9.3",
26
- "@tpmjs/tsconfig": "0.0.0"
32
+ "typescript": "^5.9.3"
27
33
  },
28
34
  "publishConfig": {
29
35
  "access": "public"
@@ -67,11 +73,5 @@
67
73
  },
68
74
  "dependencies": {
69
75
  "ai": "6.0.23"
70
- },
71
- "scripts": {
72
- "build": "tsup",
73
- "dev": "tsup --watch",
74
- "type-check": "tsc --noEmit",
75
- "clean": "rm -rf dist .turbo"
76
76
  }
77
- }
77
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024-2025 TPMJS
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.