crewx-pi-kit 0.1.2 → 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.
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { basename } from "node:path";
|
|
3
5
|
|
|
4
6
|
const API_PATH = "/api/agent/v1";
|
|
5
7
|
const MAX_RESULT_CHARS = 100_000;
|
|
@@ -48,6 +50,37 @@ async function crewxRequest(
|
|
|
48
50
|
return payload;
|
|
49
51
|
}
|
|
50
52
|
|
|
53
|
+
async function crewxUpload(
|
|
54
|
+
path: string,
|
|
55
|
+
caption: string | undefined,
|
|
56
|
+
signal?: AbortSignal,
|
|
57
|
+
): Promise<unknown> {
|
|
58
|
+
const { baseUrl, token } = connection();
|
|
59
|
+
const contents = await readFile(path);
|
|
60
|
+
const form = new FormData();
|
|
61
|
+
form.set("file", new Blob([contents]), basename(path));
|
|
62
|
+
if (caption?.trim()) form.set("caption", caption.trim());
|
|
63
|
+
const response = await fetch(`${baseUrl}${API_PATH}/files`, {
|
|
64
|
+
method: "POST",
|
|
65
|
+
headers: {
|
|
66
|
+
accept: "application/json",
|
|
67
|
+
authorization: `Bearer ${token}`,
|
|
68
|
+
},
|
|
69
|
+
body: form,
|
|
70
|
+
redirect: "error",
|
|
71
|
+
...(signal ? { signal } : {}),
|
|
72
|
+
});
|
|
73
|
+
const payload = (await response.json().catch(() => ({
|
|
74
|
+
message: `CrewX returned HTTP ${response.status}.`,
|
|
75
|
+
}))) as JsonRecord;
|
|
76
|
+
if (!response.ok) {
|
|
77
|
+
throw new Error(typeof payload.message === "string"
|
|
78
|
+
? payload.message
|
|
79
|
+
: `CrewX returned HTTP ${response.status}.`);
|
|
80
|
+
}
|
|
81
|
+
return payload;
|
|
82
|
+
}
|
|
83
|
+
|
|
51
84
|
function result(value: unknown) {
|
|
52
85
|
return {content: [{type: "text" as const, text: jsonText(value)}], details: {}};
|
|
53
86
|
}
|
|
@@ -61,6 +94,41 @@ function query(parameters: Record<string, string | number | boolean | undefined>
|
|
|
61
94
|
}
|
|
62
95
|
|
|
63
96
|
export default function crewxTools(pi: ExtensionAPI) {
|
|
97
|
+
pi.registerTool({
|
|
98
|
+
name: "crewx_attach_file",
|
|
99
|
+
label: "Attach CrewX file",
|
|
100
|
+
description: "Upload a durable file and attach it to the current CrewX reply.",
|
|
101
|
+
parameters: Type.Object({
|
|
102
|
+
path: Type.String({minLength: 1, maxLength: 4096}),
|
|
103
|
+
caption: Type.Optional(Type.String({maxLength: 1000})),
|
|
104
|
+
}),
|
|
105
|
+
promptSnippet: "Deliver generated files directly into the CrewX conversation.",
|
|
106
|
+
promptGuidelines: [
|
|
107
|
+
"Use crewx_attach_file for requested screenshots, reports, exports, and other deliverables instead of returning a local path.",
|
|
108
|
+
],
|
|
109
|
+
async execute(_id, params, signal) {
|
|
110
|
+
return result(await crewxUpload(params.path, params.caption, signal));
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
pi.registerTool({
|
|
115
|
+
name: "crewx_publish_preview",
|
|
116
|
+
label: "Publish CrewX preview",
|
|
117
|
+
description: "Publish a web service running on this CrewX Cloud Agent as a live preview.",
|
|
118
|
+
parameters: Type.Object({
|
|
119
|
+
port: Type.Integer({minimum: 1024, maximum: 65535}),
|
|
120
|
+
title: Type.Optional(Type.String({maxLength: 120})),
|
|
121
|
+
}),
|
|
122
|
+
promptSnippet: "Share interactive work as a managed CrewX live preview.",
|
|
123
|
+
promptGuidelines: [
|
|
124
|
+
"Bind the service to 0.0.0.0, verify it locally, then publish the port.",
|
|
125
|
+
"Do not reveal provider URLs, access tokens, or local file paths in the reply.",
|
|
126
|
+
],
|
|
127
|
+
async execute(_id, params, signal) {
|
|
128
|
+
return result(await crewxRequest("/previews", {method: "POST", body: params, signal}));
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
|
|
64
132
|
pi.registerTool({
|
|
65
133
|
name: "crewx_memory_search",
|
|
66
134
|
label: "Search CrewX memory",
|
package/package.json
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: artifact-delivery
|
|
3
|
+
description: Deliver files and interactive previews back to the CrewX conversation. Use when an assignment produces screenshots, reports, exports, generated media, or a locally running web experience.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Artifact Delivery
|
|
7
|
+
|
|
8
|
+
1. Treat the final CrewX reply as the handoff, not the machine filesystem. Never ask a teammate to retrieve `/home`, `/tmp`, or another local path.
|
|
9
|
+
2. Use `crewx_attach_file` for durable outputs such as screenshots, documents, archives, data exports, and generated media. Add a short caption that explains what the file contains.
|
|
10
|
+
3. Use `crewx_publish_preview` only when interaction materially improves the handoff. Bind the service to `0.0.0.0`, verify the local port, then publish it.
|
|
11
|
+
4. A preview is a running service, not permanent storage. Also attach durable source or output files when the teammate may need them later.
|
|
12
|
+
5. Do not include provider URLs, preview tokens, credentials, or local paths in the response. CrewX presents the safe file and preview controls automatically.
|
|
13
|
+
6. Confirm that every requested deliverable was attached before sending the concise final response.
|