@caplets/pi 0.0.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.
Files changed (3) hide show
  1. package/README.md +29 -0
  2. package/dist/index.js +51 -0
  3. package/package.json +36 -0
package/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # @caplets/pi
2
+
3
+ Native Pi extension for Caplets.
4
+
5
+ This package exposes configured Caplets as native Pi tools named `caplets_<id>`. It does not start the Caplets MCP server. Pi prompt guidance is provided through `promptSnippet` and `promptGuidelines`.
6
+
7
+ ## Install
8
+
9
+ Install the extension with Pi:
10
+
11
+ ```sh
12
+ pi install npm:@caplets/pi
13
+ ```
14
+
15
+ For package-manager-based installs, install it in the same environment where Pi resolves extension packages:
16
+
17
+ ```sh
18
+ npm install -g @caplets/pi
19
+ ```
20
+
21
+ Or install it project-locally:
22
+
23
+ ```sh
24
+ pnpm add -D @caplets/pi
25
+ ```
26
+
27
+ The extension reads your existing Caplets configuration through `@caplets/core`; it does not create or mutate Pi config files.
28
+
29
+ New or removed Caplets are snapshotted at extension load. Restart Pi or reload extensions to refresh the native tool list.
package/dist/index.js ADDED
@@ -0,0 +1,51 @@
1
+ import { createNativeCapletsService } from "@caplets/core/native";
2
+ import { Type } from "@sinclair/typebox";
3
+ import { operations } from "@caplets/core/generated-tool-input-schema";
4
+ //#region src/schema.ts
5
+ function capletsPiParameters() {
6
+ return Type.Object({
7
+ operation: Type.Union(operations.map((operation) => Type.Literal(operation))),
8
+ query: Type.Optional(Type.String()),
9
+ limit: Type.Optional(Type.Integer({ minimum: 1 })),
10
+ tool: Type.Optional(Type.String()),
11
+ arguments: Type.Optional(Type.Record(Type.String(), Type.Unknown())),
12
+ fields: Type.Optional(Type.Array(Type.String({ minLength: 1 }), { minItems: 1 }))
13
+ }, { additionalProperties: false });
14
+ }
15
+ //#endregion
16
+ //#region src/index.ts
17
+ function capletsPiExtension(pi, options = {}) {
18
+ const service = options.service ?? createNativeCapletsService();
19
+ if (!options.service) registerProcessCleanup(service);
20
+ for (const caplet of service.listTools()) pi.registerTool({
21
+ name: caplet.toolName,
22
+ label: caplet.title,
23
+ description: caplet.description,
24
+ promptSnippet: `Use ${caplet.toolName} for the ${caplet.title} Caplet capability domain.`,
25
+ promptGuidelines: caplet.promptGuidance,
26
+ parameters: capletsPiParameters(),
27
+ async execute(_toolCallId, params) {
28
+ const result = await service.execute(caplet.caplet, params);
29
+ return {
30
+ content: [{
31
+ type: "text",
32
+ text: JSON.stringify(result, null, 2)
33
+ }],
34
+ details: { result }
35
+ };
36
+ }
37
+ });
38
+ }
39
+ function registerProcessCleanup(service) {
40
+ let closed = false;
41
+ const close = () => {
42
+ if (closed) return;
43
+ closed = true;
44
+ service.close();
45
+ };
46
+ process.once("beforeExit", close);
47
+ process.once("SIGINT", close);
48
+ process.once("SIGTERM", close);
49
+ }
50
+ //#endregion
51
+ export { capletsPiExtension as default };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@caplets/pi",
3
+ "version": "0.0.0",
4
+ "description": "Native Pi extension for Caplets.",
5
+ "files": [
6
+ "dist",
7
+ "README.md"
8
+ ],
9
+ "type": "module",
10
+ "main": "dist/index.js",
11
+ "exports": {
12
+ ".": "./dist/index.js"
13
+ },
14
+ "scripts": {
15
+ "build": "rm -rf dist && rolldown -c",
16
+ "prepack": "pnpm build",
17
+ "typecheck": "tsc --noEmit",
18
+ "test": "vitest run"
19
+ },
20
+ "dependencies": {
21
+ "@caplets/core": "workspace:*",
22
+ "@sinclair/typebox": "^0.34.49"
23
+ },
24
+ "devDependencies": {
25
+ "@types/node": "^25.7.0",
26
+ "rolldown": "^1.0.0",
27
+ "typescript": "^6.0.3",
28
+ "vitest": "^4.1.6"
29
+ },
30
+ "peerDependencies": {
31
+ "@earendil-works/pi-coding-agent": ">=0"
32
+ },
33
+ "engines": {
34
+ "node": ">=22"
35
+ }
36
+ }