@pixelml/plugin 0.0.0-dev-202512250746

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.
@@ -0,0 +1,2 @@
1
+ import { Plugin } from "./index";
2
+ export declare const ExamplePlugin: Plugin;
@@ -0,0 +1,16 @@
1
+ import { tool } from "./tool";
2
+ export const ExamplePlugin = async (ctx) => {
3
+ return {
4
+ tool: {
5
+ mytool: tool({
6
+ description: "This is a custom tool",
7
+ args: {
8
+ foo: tool.schema.string().describe("foo"),
9
+ },
10
+ async execute(args) {
11
+ return `Hello ${args.foo}!`;
12
+ },
13
+ }),
14
+ },
15
+ };
16
+ };
@@ -0,0 +1,192 @@
1
+ import type { Event, createClawClient, Project, Model, Provider, Permission, UserMessage, Message, Part, Auth, Config } from "@pixelml/sdk";
2
+ import type { BunShell } from "./shell";
3
+ import { type ToolDefinition } from "./tool";
4
+ export * from "./tool";
5
+ export type ProviderContext = {
6
+ source: "env" | "config" | "custom" | "api";
7
+ info: Provider;
8
+ options: Record<string, any>;
9
+ };
10
+ export type PluginInput = {
11
+ client: ReturnType<typeof createClawClient>;
12
+ project: Project;
13
+ directory: string;
14
+ worktree: string;
15
+ $: BunShell;
16
+ };
17
+ export type Plugin = (input: PluginInput) => Promise<Hooks>;
18
+ export type AuthHook = {
19
+ provider: string;
20
+ loader?: (auth: () => Promise<Auth>, provider: Provider) => Promise<Record<string, any>>;
21
+ methods: ({
22
+ type: "oauth";
23
+ label: string;
24
+ prompts?: Array<{
25
+ type: "text";
26
+ key: string;
27
+ message: string;
28
+ placeholder?: string;
29
+ validate?: (value: string) => string | undefined;
30
+ condition?: (inputs: Record<string, string>) => boolean;
31
+ } | {
32
+ type: "select";
33
+ key: string;
34
+ message: string;
35
+ options: Array<{
36
+ label: string;
37
+ value: string;
38
+ hint?: string;
39
+ }>;
40
+ condition?: (inputs: Record<string, string>) => boolean;
41
+ }>;
42
+ authorize(inputs?: Record<string, string>): Promise<AuthOuathResult>;
43
+ } | {
44
+ type: "api";
45
+ label: string;
46
+ prompts?: Array<{
47
+ type: "text";
48
+ key: string;
49
+ message: string;
50
+ placeholder?: string;
51
+ validate?: (value: string) => string | undefined;
52
+ condition?: (inputs: Record<string, string>) => boolean;
53
+ } | {
54
+ type: "select";
55
+ key: string;
56
+ message: string;
57
+ options: Array<{
58
+ label: string;
59
+ value: string;
60
+ hint?: string;
61
+ }>;
62
+ condition?: (inputs: Record<string, string>) => boolean;
63
+ }>;
64
+ authorize?(inputs?: Record<string, string>): Promise<{
65
+ type: "success";
66
+ key: string;
67
+ provider?: string;
68
+ } | {
69
+ type: "failed";
70
+ }>;
71
+ })[];
72
+ };
73
+ export type AuthOuathResult = {
74
+ url: string;
75
+ instructions: string;
76
+ } & ({
77
+ method: "auto";
78
+ callback(): Promise<({
79
+ type: "success";
80
+ provider?: string;
81
+ } & ({
82
+ refresh: string;
83
+ access: string;
84
+ expires: number;
85
+ } | {
86
+ key: string;
87
+ })) | {
88
+ type: "failed";
89
+ }>;
90
+ } | {
91
+ method: "code";
92
+ callback(code: string): Promise<({
93
+ type: "success";
94
+ provider?: string;
95
+ } & ({
96
+ refresh: string;
97
+ access: string;
98
+ expires: number;
99
+ } | {
100
+ key: string;
101
+ })) | {
102
+ type: "failed";
103
+ }>;
104
+ });
105
+ export interface Hooks {
106
+ event?: (input: {
107
+ event: Event;
108
+ }) => Promise<void>;
109
+ config?: (input: Config) => Promise<void>;
110
+ tool?: {
111
+ [key: string]: ToolDefinition;
112
+ };
113
+ auth?: AuthHook;
114
+ /**
115
+ * Called when a new message is received
116
+ */
117
+ "chat.message"?: (input: {
118
+ sessionID: string;
119
+ agent?: string;
120
+ model?: {
121
+ providerID: string;
122
+ modelID: string;
123
+ };
124
+ messageID?: string;
125
+ }, output: {
126
+ message: UserMessage;
127
+ parts: Part[];
128
+ }) => Promise<void>;
129
+ /**
130
+ * Modify parameters sent to LLM
131
+ */
132
+ "chat.params"?: (input: {
133
+ sessionID: string;
134
+ agent: string;
135
+ model: Model;
136
+ provider: ProviderContext;
137
+ message: UserMessage;
138
+ }, output: {
139
+ temperature: number;
140
+ topP: number;
141
+ topK: number;
142
+ options: Record<string, any>;
143
+ }) => Promise<void>;
144
+ "permission.ask"?: (input: Permission, output: {
145
+ status: "ask" | "deny" | "allow";
146
+ }) => Promise<void>;
147
+ "tool.execute.before"?: (input: {
148
+ tool: string;
149
+ sessionID: string;
150
+ callID: string;
151
+ }, output: {
152
+ args: any;
153
+ }) => Promise<void>;
154
+ "tool.execute.after"?: (input: {
155
+ tool: string;
156
+ sessionID: string;
157
+ callID: string;
158
+ }, output: {
159
+ title: string;
160
+ output: string;
161
+ metadata: any;
162
+ }) => Promise<void>;
163
+ "experimental.chat.messages.transform"?: (input: {}, output: {
164
+ messages: {
165
+ info: Message;
166
+ parts: Part[];
167
+ }[];
168
+ }) => Promise<void>;
169
+ "experimental.chat.system.transform"?: (input: {}, output: {
170
+ system: string[];
171
+ }) => Promise<void>;
172
+ /**
173
+ * Called before session compaction starts. Allows plugins to customize
174
+ * the compaction prompt.
175
+ *
176
+ * - `context`: Additional context strings appended to the default prompt
177
+ * - `prompt`: If set, replaces the default compaction prompt entirely
178
+ */
179
+ "experimental.session.compacting"?: (input: {
180
+ sessionID: string;
181
+ }, output: {
182
+ context: string[];
183
+ prompt?: string;
184
+ }) => Promise<void>;
185
+ "experimental.text.complete"?: (input: {
186
+ sessionID: string;
187
+ messageID: string;
188
+ partID: string;
189
+ }, output: {
190
+ text: string;
191
+ }) => Promise<void>;
192
+ }
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./tool";
@@ -0,0 +1,109 @@
1
+ export type ShellFunction = (input: Uint8Array) => Uint8Array;
2
+ export type ShellExpression = {
3
+ toString(): string;
4
+ } | Array<ShellExpression> | string | {
5
+ raw: string;
6
+ } | ReadableStream;
7
+ export interface BunShell {
8
+ (strings: TemplateStringsArray, ...expressions: ShellExpression[]): BunShellPromise;
9
+ /**
10
+ * Perform bash-like brace expansion on the given pattern.
11
+ * @param pattern - Brace pattern to expand
12
+ */
13
+ braces(pattern: string): string[];
14
+ /**
15
+ * Escape strings for input into shell commands.
16
+ */
17
+ escape(input: string): string;
18
+ /**
19
+ * Change the default environment variables for shells created by this instance.
20
+ */
21
+ env(newEnv?: Record<string, string | undefined>): BunShell;
22
+ /**
23
+ * Default working directory to use for shells created by this instance.
24
+ */
25
+ cwd(newCwd?: string): BunShell;
26
+ /**
27
+ * Configure the shell to not throw an exception on non-zero exit codes.
28
+ */
29
+ nothrow(): BunShell;
30
+ /**
31
+ * Configure whether or not the shell should throw an exception on non-zero exit codes.
32
+ */
33
+ throws(shouldThrow: boolean): BunShell;
34
+ }
35
+ export interface BunShellPromise extends Promise<BunShellOutput> {
36
+ readonly stdin: WritableStream;
37
+ /**
38
+ * Change the current working directory of the shell.
39
+ */
40
+ cwd(newCwd: string): this;
41
+ /**
42
+ * Set environment variables for the shell.
43
+ */
44
+ env(newEnv: Record<string, string> | undefined): this;
45
+ /**
46
+ * By default, the shell will write to the current process's stdout and stderr, as well as buffering that output.
47
+ * This configures the shell to only buffer the output.
48
+ */
49
+ quiet(): this;
50
+ /**
51
+ * Read from stdout as a string, line by line
52
+ * Automatically calls quiet() to disable echoing to stdout.
53
+ */
54
+ lines(): AsyncIterable<string>;
55
+ /**
56
+ * Read from stdout as a string.
57
+ * Automatically calls quiet() to disable echoing to stdout.
58
+ */
59
+ text(encoding?: BufferEncoding): Promise<string>;
60
+ /**
61
+ * Read from stdout as a JSON object
62
+ * Automatically calls quiet()
63
+ */
64
+ json(): Promise<any>;
65
+ /**
66
+ * Read from stdout as an ArrayBuffer
67
+ * Automatically calls quiet()
68
+ */
69
+ arrayBuffer(): Promise<ArrayBuffer>;
70
+ /**
71
+ * Read from stdout as a Blob
72
+ * Automatically calls quiet()
73
+ */
74
+ blob(): Promise<Blob>;
75
+ /**
76
+ * Configure the shell to not throw an exception on non-zero exit codes.
77
+ */
78
+ nothrow(): this;
79
+ /**
80
+ * Configure whether or not the shell should throw an exception on non-zero exit codes.
81
+ */
82
+ throws(shouldThrow: boolean): this;
83
+ }
84
+ export interface BunShellOutput {
85
+ readonly stdout: Buffer;
86
+ readonly stderr: Buffer;
87
+ readonly exitCode: number;
88
+ /**
89
+ * Read from stdout as a string
90
+ */
91
+ text(encoding?: BufferEncoding): string;
92
+ /**
93
+ * Read from stdout as a JSON object
94
+ */
95
+ json(): any;
96
+ /**
97
+ * Read from stdout as an ArrayBuffer
98
+ */
99
+ arrayBuffer(): ArrayBuffer;
100
+ /**
101
+ * Read from stdout as an Uint8Array
102
+ */
103
+ bytes(): Uint8Array;
104
+ /**
105
+ * Read from stdout as a Blob
106
+ */
107
+ blob(): Blob;
108
+ }
109
+ export type BunShellError = Error & BunShellOutput;
package/dist/shell.js ADDED
File without changes
package/dist/tool.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { z } from "zod";
2
+ export type ToolContext = {
3
+ sessionID: string;
4
+ messageID: string;
5
+ agent: string;
6
+ abort: AbortSignal;
7
+ };
8
+ export declare function tool<Args extends z.ZodRawShape>(input: {
9
+ description: string;
10
+ args: Args;
11
+ execute(args: z.infer<z.ZodObject<Args>>, context: ToolContext): Promise<string>;
12
+ }): {
13
+ description: string;
14
+ args: Args;
15
+ execute(args: z.infer<z.ZodObject<Args>>, context: ToolContext): Promise<string>;
16
+ };
17
+ export declare namespace tool {
18
+ var schema: typeof z;
19
+ }
20
+ export type ToolDefinition = ReturnType<typeof tool>;
package/dist/tool.js ADDED
@@ -0,0 +1,5 @@
1
+ import { z } from "zod";
2
+ export function tool(input) {
3
+ return input;
4
+ }
5
+ tool.schema = z;
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/package.json",
3
+ "name": "@pixelml/plugin",
4
+ "version": "0.0.0-dev-202512250746",
5
+ "type": "module",
6
+ "scripts": {
7
+ "typecheck": "tsgo --noEmit",
8
+ "build": "tsc"
9
+ },
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/index.js",
13
+ "types": "./dist/index.d.ts"
14
+ },
15
+ "./tool": {
16
+ "import": "./dist/tool.js",
17
+ "types": "./dist/tool.d.ts"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "dependencies": {
24
+ "@pixelml/sdk": "workspace:*",
25
+ "zod": "catalog:"
26
+ },
27
+ "devDependencies": {
28
+ "@tsconfig/node22": "catalog:",
29
+ "@types/node": "catalog:",
30
+ "typescript": "catalog:",
31
+ "@typescript/native-preview": "catalog:"
32
+ }
33
+ }