xyne-plugin 1.0.2
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/package.json +28 -0
- package/src/hooks.ts +107 -0
- package/src/index.ts +32 -0
- package/src/tool.ts +60 -0
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "xyne-plugin",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "SDK for writing Xyne plugins — define custom tools, hooks, and extensions",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "./src/index.ts"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"src"
|
|
11
|
+
],
|
|
12
|
+
"keywords": [
|
|
13
|
+
"xyne",
|
|
14
|
+
"plugin",
|
|
15
|
+
"ai",
|
|
16
|
+
"agent",
|
|
17
|
+
"coding"
|
|
18
|
+
],
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/xynehq/xyne.git",
|
|
23
|
+
"directory": "npm/xyne-plugin"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"zod": "^3.25.0"
|
|
27
|
+
}
|
|
28
|
+
}
|
package/src/hooks.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { ToolDefinition } from "./tool"
|
|
2
|
+
|
|
3
|
+
// ─── Simplified types for hook signatures ───────────────────────────────────
|
|
4
|
+
// These are minimal versions of internal types — just enough for plugin authors
|
|
5
|
+
// to work with hook parameters.
|
|
6
|
+
|
|
7
|
+
/** Model descriptor passed to chat hooks. */
|
|
8
|
+
export interface ModelSpec {
|
|
9
|
+
/** Model identifier, e.g. "claude-opus-4-6" */
|
|
10
|
+
id: string
|
|
11
|
+
/** Provider identifier, e.g. "anthropic" */
|
|
12
|
+
providerID: string
|
|
13
|
+
/** Human-readable name */
|
|
14
|
+
name: string
|
|
15
|
+
[key: string]: unknown
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** LLM message — opaque to plugins, passed through for transformation. */
|
|
19
|
+
export type Message = Record<string, unknown>
|
|
20
|
+
|
|
21
|
+
// ─── Plugin function types ───────────────────────────────────────────────────
|
|
22
|
+
|
|
23
|
+
export type PluginInput = {
|
|
24
|
+
directory: string
|
|
25
|
+
worktree: string
|
|
26
|
+
appName: string
|
|
27
|
+
/** SDK client — available for plugins that need session/message/tool APIs. */
|
|
28
|
+
client?: unknown
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type Plugin = (input: PluginInput) => Promise<Hooks>
|
|
32
|
+
|
|
33
|
+
// ─── Hook definitions ────────────────────────────────────────────────────────
|
|
34
|
+
|
|
35
|
+
export interface Hooks {
|
|
36
|
+
/** Subscribe to bus events. */
|
|
37
|
+
event?: (input: { event: unknown }) => Promise<void>
|
|
38
|
+
|
|
39
|
+
/** Called once after all plugins are loaded — receive merged config. */
|
|
40
|
+
config?: (input: Record<string, unknown>) => Promise<void>
|
|
41
|
+
|
|
42
|
+
/** Register custom tools. Keyed by tool ID. */
|
|
43
|
+
tool?: Record<string, ToolDefinition>
|
|
44
|
+
|
|
45
|
+
/** Auth provider stub — expand later with full OAuth / API key flows. */
|
|
46
|
+
auth?: { provider: string }
|
|
47
|
+
|
|
48
|
+
/** Mutate LLM sampling parameters before a chat request. */
|
|
49
|
+
"chat.params"?: (
|
|
50
|
+
input: { sessionID: string; agent: string; model: ModelSpec },
|
|
51
|
+
output: { temperature?: number; topP?: number; topK?: number },
|
|
52
|
+
) => Promise<void>
|
|
53
|
+
|
|
54
|
+
/** Inject extra HTTP headers into the provider request. */
|
|
55
|
+
"chat.headers"?: (
|
|
56
|
+
input: { sessionID: string; agent: string; model: ModelSpec },
|
|
57
|
+
output: { headers: Record<string, string> },
|
|
58
|
+
) => Promise<void>
|
|
59
|
+
|
|
60
|
+
/** Transform the system prompt parts before they are joined. */
|
|
61
|
+
"chat.system.transform"?: (
|
|
62
|
+
input: { sessionID: string; model: ModelSpec },
|
|
63
|
+
output: { system: string[] },
|
|
64
|
+
) => Promise<void>
|
|
65
|
+
|
|
66
|
+
/** Transform the message array before it is sent to the LLM. */
|
|
67
|
+
"chat.messages.transform"?: (
|
|
68
|
+
input: { sessionID: string },
|
|
69
|
+
output: { messages: Message[] },
|
|
70
|
+
) => Promise<void>
|
|
71
|
+
|
|
72
|
+
/** Intercept permission decisions. */
|
|
73
|
+
"permission.ask"?: (
|
|
74
|
+
input: { permission: string; patterns: string[]; metadata: Record<string, unknown> },
|
|
75
|
+
output: { status: "ask" | "deny" | "allow" },
|
|
76
|
+
) => Promise<void>
|
|
77
|
+
|
|
78
|
+
/** Modify tool args before execution. */
|
|
79
|
+
"tool.execute.before"?: (
|
|
80
|
+
input: { tool: string; sessionID: string; callID: string },
|
|
81
|
+
output: { args: unknown },
|
|
82
|
+
) => Promise<void>
|
|
83
|
+
|
|
84
|
+
/** Modify tool output after execution. */
|
|
85
|
+
"tool.execute.after"?: (
|
|
86
|
+
input: { tool: string; sessionID: string; callID: string; args: unknown },
|
|
87
|
+
output: { title: string; output: string; metadata: unknown },
|
|
88
|
+
) => Promise<void>
|
|
89
|
+
|
|
90
|
+
/** Modify a tool's description or parameters at registration time. */
|
|
91
|
+
"tool.definition"?: (
|
|
92
|
+
input: { toolID: string },
|
|
93
|
+
output: { description: string; parameters: unknown },
|
|
94
|
+
) => Promise<void>
|
|
95
|
+
|
|
96
|
+
/** Inject environment variables into bash tool spawns. */
|
|
97
|
+
"shell.env"?: (
|
|
98
|
+
input: { cwd: string; sessionID?: string; callID?: string },
|
|
99
|
+
output: { env: Record<string, string> },
|
|
100
|
+
) => Promise<void>
|
|
101
|
+
|
|
102
|
+
/** Customise context preservation during session compaction. */
|
|
103
|
+
"session.compacting"?: (
|
|
104
|
+
input: { sessionID: string },
|
|
105
|
+
output: { context: string[]; prompt?: string },
|
|
106
|
+
) => Promise<void>
|
|
107
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* xyne-plugin — SDK for writing Xyne plugins.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { type Plugin, tool, z } from "xyne-plugin"
|
|
7
|
+
*
|
|
8
|
+
* const plugin: Plugin = async ({ directory }) => ({
|
|
9
|
+
* tool: {
|
|
10
|
+
* "my-tool": tool({
|
|
11
|
+
* description: "Does something",
|
|
12
|
+
* args: { query: z.string().describe("Search query") },
|
|
13
|
+
* async execute(args, ctx) {
|
|
14
|
+
* return `Result for ${args.query}`
|
|
15
|
+
* },
|
|
16
|
+
* }),
|
|
17
|
+
* },
|
|
18
|
+
* })
|
|
19
|
+
*
|
|
20
|
+
* export default plugin
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
// Plugin types
|
|
25
|
+
export type { Plugin, PluginInput, Hooks } from "./hooks"
|
|
26
|
+
|
|
27
|
+
// Tool authoring
|
|
28
|
+
export { tool } from "./tool"
|
|
29
|
+
export type { ToolDefinition, ToolContext } from "./tool"
|
|
30
|
+
|
|
31
|
+
// Zod re-export for convenience
|
|
32
|
+
export { z } from "zod"
|
package/src/tool.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { z } from "zod"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Execution context passed to every custom tool's execute function.
|
|
5
|
+
*/
|
|
6
|
+
export type ToolContext = {
|
|
7
|
+
sessionID: string
|
|
8
|
+
messageID: string
|
|
9
|
+
agent: string
|
|
10
|
+
/**
|
|
11
|
+
* Current project directory for this session.
|
|
12
|
+
* Prefer this over process.cwd() when resolving relative paths.
|
|
13
|
+
*/
|
|
14
|
+
directory: string
|
|
15
|
+
/**
|
|
16
|
+
* Project worktree root for this session.
|
|
17
|
+
* Useful for generating stable relative paths (e.g. path.relative(worktree, absPath)).
|
|
18
|
+
*/
|
|
19
|
+
worktree: string
|
|
20
|
+
abort: AbortSignal
|
|
21
|
+
metadata(input: { title?: string; metadata?: { [key: string]: unknown } }): void
|
|
22
|
+
ask(input: AskInput): Promise<void>
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type AskInput = {
|
|
26
|
+
permission: string
|
|
27
|
+
patterns: string[]
|
|
28
|
+
always: string[]
|
|
29
|
+
metadata: { [key: string]: unknown }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Define a custom tool. Use this in plugin packages or local tool files.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { tool, z } from "xyne-plugin"
|
|
38
|
+
*
|
|
39
|
+
* export default tool({
|
|
40
|
+
* description: "Search the web",
|
|
41
|
+
* args: {
|
|
42
|
+
* query: z.string().describe("Search query"),
|
|
43
|
+
* },
|
|
44
|
+
* async execute(args, ctx) {
|
|
45
|
+
* return `Results for ${args.query}`
|
|
46
|
+
* },
|
|
47
|
+
* })
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export function tool<Args extends z.ZodRawShape>(input: {
|
|
51
|
+
description: string
|
|
52
|
+
args: Args
|
|
53
|
+
execute(args: z.infer<z.ZodObject<Args>>, context: ToolContext): Promise<string>
|
|
54
|
+
}) {
|
|
55
|
+
return input
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
tool.schema = z
|
|
59
|
+
|
|
60
|
+
export type ToolDefinition = ReturnType<typeof tool>
|