@ashdev/codex-plugin-sdk 1.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.
- package/README.md +260 -0
- package/dist/errors.d.ts +53 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +72 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +67 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +36 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +77 -0
- package/dist/logger.js.map +1 -0
- package/dist/server.d.ts +103 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +306 -0
- package/dist/server.js.map +1 -0
- package/dist/types/capabilities.d.ts +89 -0
- package/dist/types/capabilities.d.ts.map +1 -0
- package/dist/types/capabilities.js +20 -0
- package/dist/types/capabilities.js.map +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/manifest.d.ts +88 -0
- package/dist/types/manifest.d.ts.map +1 -0
- package/dist/types/manifest.js +21 -0
- package/dist/types/manifest.js.map +1 -0
- package/dist/types/protocol.d.ts +185 -0
- package/dist/types/protocol.d.ts.map +1 -0
- package/dist/types/protocol.js +10 -0
- package/dist/types/protocol.js.map +1 -0
- package/dist/types/rpc.d.ts +56 -0
- package/dist/types/rpc.d.ts.map +1 -0
- package/dist/types/rpc.js +34 -0
- package/dist/types/rpc.js.map +1 -0
- package/package.json +55 -0
package/README.md
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
# @ashdev/codex-plugin-sdk
|
|
2
|
+
|
|
3
|
+
Official SDK for building Codex plugins. Provides type-safe interfaces, utilities, and a server framework for communicating with Codex via JSON-RPC over stdio.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @ashdev/codex-plugin-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import {
|
|
15
|
+
createMetadataPlugin,
|
|
16
|
+
type MetadataContentType,
|
|
17
|
+
type MetadataProvider,
|
|
18
|
+
type PluginManifest,
|
|
19
|
+
} from "@ashdev/codex-plugin-sdk";
|
|
20
|
+
|
|
21
|
+
// Define your plugin manifest
|
|
22
|
+
const manifest = {
|
|
23
|
+
name: "metadata-my-plugin",
|
|
24
|
+
displayName: "My Plugin",
|
|
25
|
+
version: "1.0.0",
|
|
26
|
+
description: "A custom metadata provider",
|
|
27
|
+
author: "Your Name",
|
|
28
|
+
protocolVersion: "1.0",
|
|
29
|
+
capabilities: {
|
|
30
|
+
metadataProvider: ["series"] as MetadataContentType[],
|
|
31
|
+
},
|
|
32
|
+
} as const satisfies PluginManifest & {
|
|
33
|
+
capabilities: { metadataProvider: MetadataContentType[] };
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Implement the MetadataProvider interface
|
|
37
|
+
const provider: MetadataProvider = {
|
|
38
|
+
async search(params) {
|
|
39
|
+
// Search your data source
|
|
40
|
+
return {
|
|
41
|
+
results: [
|
|
42
|
+
{
|
|
43
|
+
externalId: "123",
|
|
44
|
+
title: "Example Series",
|
|
45
|
+
alternateTitles: [],
|
|
46
|
+
relevanceScore: 0.95,
|
|
47
|
+
preview: {
|
|
48
|
+
status: "ongoing",
|
|
49
|
+
genres: ["Action", "Adventure"],
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
async get(params) {
|
|
57
|
+
// Fetch full metadata
|
|
58
|
+
return {
|
|
59
|
+
externalId: params.externalId,
|
|
60
|
+
externalUrl: `https://example.com/series/${params.externalId}`,
|
|
61
|
+
title: "Example Series",
|
|
62
|
+
alternateTitles: [],
|
|
63
|
+
summary: "An exciting series...",
|
|
64
|
+
status: "ongoing",
|
|
65
|
+
year: 2024,
|
|
66
|
+
genres: ["Action", "Adventure"],
|
|
67
|
+
tags: [],
|
|
68
|
+
authors: ["Author Name"],
|
|
69
|
+
artists: [],
|
|
70
|
+
externalLinks: [],
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
// Optional: implement match for auto-matching during library scans
|
|
75
|
+
async match(params) {
|
|
76
|
+
const result = await this.search({
|
|
77
|
+
query: params.title,
|
|
78
|
+
contentType: params.contentType,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
match: result.results[0] ?? null,
|
|
83
|
+
confidence: result.results[0] ? 0.8 : 0,
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// Start the plugin
|
|
89
|
+
createMetadataPlugin({ manifest, provider });
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Features
|
|
93
|
+
|
|
94
|
+
- **Type-safe**: Full TypeScript support with interface contracts
|
|
95
|
+
- **Protocol compliance**: Types match the Codex JSON-RPC protocol exactly
|
|
96
|
+
- **Simple API**: Implement the `MetadataProvider` interface, SDK handles the rest
|
|
97
|
+
- **Error handling**: Built-in error classes that map to JSON-RPC errors
|
|
98
|
+
- **Logging**: Safe logging to stderr (stdout is reserved for protocol)
|
|
99
|
+
|
|
100
|
+
## Concepts
|
|
101
|
+
|
|
102
|
+
### Capabilities
|
|
103
|
+
|
|
104
|
+
Plugins declare capabilities in their manifest. Each capability has a corresponding interface:
|
|
105
|
+
|
|
106
|
+
| Capability | Interface | Description |
|
|
107
|
+
|------------|-----------|-------------|
|
|
108
|
+
| `metadataProvider` | `MetadataProvider` | Search and fetch metadata for content |
|
|
109
|
+
|
|
110
|
+
The `metadataProvider` capability is an array of content types your plugin supports:
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
capabilities: {
|
|
114
|
+
metadataProvider: ["series"] as MetadataContentType[],
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Supported content types: `"series"` (future: `"book"`)
|
|
119
|
+
|
|
120
|
+
### Protocol Types
|
|
121
|
+
|
|
122
|
+
The SDK provides TypeScript types that exactly match the Codex JSON-RPC protocol:
|
|
123
|
+
|
|
124
|
+
- `MetadataSearchParams` / `MetadataSearchResponse` - Search parameters and results
|
|
125
|
+
- `MetadataGetParams` / `PluginSeriesMetadata` - Get full metadata
|
|
126
|
+
- `MetadataMatchParams` / `MetadataMatchResponse` - Auto-match content
|
|
127
|
+
- `SearchResult` - Individual search result with `relevanceScore`
|
|
128
|
+
|
|
129
|
+
### Relevance Score
|
|
130
|
+
|
|
131
|
+
Search results must include a `relevanceScore` between 0.0 and 1.0:
|
|
132
|
+
|
|
133
|
+
- `1.0` = Perfect match
|
|
134
|
+
- `0.7-0.9` = Good match
|
|
135
|
+
- `0.5-0.7` = Partial match
|
|
136
|
+
- `< 0.5` = Weak match
|
|
137
|
+
|
|
138
|
+
## API Reference
|
|
139
|
+
|
|
140
|
+
### `createMetadataPlugin(options)`
|
|
141
|
+
|
|
142
|
+
Creates and starts a metadata provider plugin.
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
interface MetadataPluginOptions {
|
|
146
|
+
manifest: PluginManifest & { capabilities: { metadataProvider: MetadataContentType[] } };
|
|
147
|
+
provider: MetadataProvider;
|
|
148
|
+
onInitialize?: (params: InitializeParams) => void | Promise<void>;
|
|
149
|
+
logLevel?: "debug" | "info" | "warn" | "error";
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### `MetadataProvider`
|
|
154
|
+
|
|
155
|
+
Interface for metadata provider plugins:
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
interface MetadataProvider {
|
|
159
|
+
search(params: MetadataSearchParams): Promise<MetadataSearchResponse>;
|
|
160
|
+
get(params: MetadataGetParams): Promise<PluginSeriesMetadata>;
|
|
161
|
+
match?(params: MetadataMatchParams): Promise<MetadataMatchResponse>;
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Error Handling
|
|
166
|
+
|
|
167
|
+
Use built-in error classes for proper error responses:
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
import { NotFoundError, RateLimitError, AuthError, ApiError } from "@ashdev/codex-plugin-sdk";
|
|
171
|
+
|
|
172
|
+
// In your provider:
|
|
173
|
+
async get(params) {
|
|
174
|
+
const data = await fetchFromApi(params.externalId);
|
|
175
|
+
|
|
176
|
+
if (!data) {
|
|
177
|
+
throw new NotFoundError(`Series ${params.externalId} not found`);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return data;
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Logging
|
|
185
|
+
|
|
186
|
+
Plugins should log to stderr (stdout is reserved for JSON-RPC):
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
import { createLogger } from "@ashdev/codex-plugin-sdk";
|
|
190
|
+
|
|
191
|
+
const logger = createLogger({ name: "my-plugin", level: "debug" });
|
|
192
|
+
logger.info("Plugin started");
|
|
193
|
+
logger.debug("Processing request", { query: "..." });
|
|
194
|
+
logger.error("Failed to fetch", error);
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Credentials
|
|
198
|
+
|
|
199
|
+
Plugins can receive credentials (API keys, tokens) via the `onInitialize` callback:
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
let apiKey: string | undefined;
|
|
203
|
+
|
|
204
|
+
createMetadataPlugin({
|
|
205
|
+
manifest,
|
|
206
|
+
provider,
|
|
207
|
+
onInitialize(params) {
|
|
208
|
+
apiKey = params.credentials?.api_key;
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Credentials are configured by admins in Codex and delivered securely to the plugin.
|
|
214
|
+
|
|
215
|
+
## Protocol
|
|
216
|
+
|
|
217
|
+
Plugins communicate with Codex via JSON-RPC 2.0 over stdio:
|
|
218
|
+
|
|
219
|
+
- **stdin**: Receives JSON-RPC requests (one per line)
|
|
220
|
+
- **stdout**: Sends JSON-RPC responses (one per line)
|
|
221
|
+
- **stderr**: Logging output (visible in Codex logs)
|
|
222
|
+
|
|
223
|
+
## Building Your Plugin
|
|
224
|
+
|
|
225
|
+
1. Create a new npm package
|
|
226
|
+
2. Install the SDK: `npm install @ashdev/codex-plugin-sdk`
|
|
227
|
+
3. Implement your provider
|
|
228
|
+
4. Bundle with esbuild (include shebang for npx support):
|
|
229
|
+
|
|
230
|
+
```json
|
|
231
|
+
{
|
|
232
|
+
"name": "@your-org/plugin-metadata-example",
|
|
233
|
+
"version": "1.0.0",
|
|
234
|
+
"main": "dist/index.js",
|
|
235
|
+
"bin": "dist/index.js",
|
|
236
|
+
"type": "module",
|
|
237
|
+
"files": ["dist", "README.md"],
|
|
238
|
+
"engines": {
|
|
239
|
+
"node": ">=22.0.0"
|
|
240
|
+
},
|
|
241
|
+
"scripts": {
|
|
242
|
+
"build": "esbuild src/index.ts --bundle --platform=node --target=node22 --format=esm --outfile=dist/index.js --sourcemap --banner:js='#!/usr/bin/env node'",
|
|
243
|
+
"prepublishOnly": "npm run lint && npm run build"
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
**Key fields for npx support:**
|
|
249
|
+
- `bin`: Points to the entry file, tells npx what to execute
|
|
250
|
+
- `--banner:js='#!/usr/bin/env node'`: Adds shebang so the file is directly executable
|
|
251
|
+
- `files`: Only publish dist and README to npm
|
|
252
|
+
|
|
253
|
+
## Example Plugins
|
|
254
|
+
|
|
255
|
+
- [`@ashdev/codex-plugin-metadata-echo`](https://github.com/AshDevFr/codex/tree/main/plugins/metadata-echo) - Test metadata plugin that echoes back queries
|
|
256
|
+
- [`@ashdev/codex-plugin-metadata-mangabaka`](https://github.com/AshDevFr/codex/tree/main/plugins/metadata-mangabaka) - MangaBaka metadata provider
|
|
257
|
+
|
|
258
|
+
## License
|
|
259
|
+
|
|
260
|
+
MIT
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin error classes for structured error handling
|
|
3
|
+
*/
|
|
4
|
+
import { type JsonRpcError } from "./types/rpc.js";
|
|
5
|
+
/**
|
|
6
|
+
* Base class for plugin errors that map to JSON-RPC errors
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class PluginError extends Error {
|
|
9
|
+
abstract readonly code: number;
|
|
10
|
+
readonly data?: unknown;
|
|
11
|
+
constructor(message: string, data?: unknown);
|
|
12
|
+
/**
|
|
13
|
+
* Convert to JSON-RPC error format
|
|
14
|
+
*/
|
|
15
|
+
toJsonRpcError(): JsonRpcError;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Thrown when rate limited by an external API
|
|
19
|
+
*/
|
|
20
|
+
export declare class RateLimitError extends PluginError {
|
|
21
|
+
readonly code: -32001;
|
|
22
|
+
/** Seconds to wait before retrying */
|
|
23
|
+
readonly retryAfterSeconds: number;
|
|
24
|
+
constructor(retryAfterSeconds: number, message?: string);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Thrown when a requested resource is not found
|
|
28
|
+
*/
|
|
29
|
+
export declare class NotFoundError extends PluginError {
|
|
30
|
+
readonly code: -32002;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Thrown when authentication fails (invalid credentials)
|
|
34
|
+
*/
|
|
35
|
+
export declare class AuthError extends PluginError {
|
|
36
|
+
readonly code: -32003;
|
|
37
|
+
constructor(message?: string);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Thrown when an external API returns an error
|
|
41
|
+
*/
|
|
42
|
+
export declare class ApiError extends PluginError {
|
|
43
|
+
readonly code: -32004;
|
|
44
|
+
readonly statusCode: number | undefined;
|
|
45
|
+
constructor(message: string, statusCode?: number);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Thrown when the plugin is misconfigured
|
|
49
|
+
*/
|
|
50
|
+
export declare class ConfigError extends PluginError {
|
|
51
|
+
readonly code: -32005;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAsB,MAAM,gBAAgB,CAAC;AAEvE;;GAEG;AACH,8BAAsB,WAAY,SAAQ,KAAK;IAC7C,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;gBAEZ,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;IAM3C;;OAEG;IACH,cAAc,IAAI,YAAY;CAO/B;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,WAAW;IAC7C,QAAQ,CAAC,IAAI,SAAmC;IAChD,sCAAsC;IACtC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;gBAEvB,iBAAiB,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM;CAMxD;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,WAAW;IAC5C,QAAQ,CAAC,IAAI,SAAgC;CAC9C;AAED;;GAEG;AACH,qBAAa,SAAU,SAAQ,WAAW;IACxC,QAAQ,CAAC,IAAI,SAAkC;gBAEnC,OAAO,CAAC,EAAE,MAAM;CAG7B;AAED;;GAEG;AACH,qBAAa,QAAS,SAAQ,WAAW;IACvC,QAAQ,CAAC,IAAI,SAAgC;IAC7C,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;gBAE5B,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM;CAIjD;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,WAAW;IAC1C,QAAQ,CAAC,IAAI,SAAmC;CACjD"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin error classes for structured error handling
|
|
3
|
+
*/
|
|
4
|
+
import { PLUGIN_ERROR_CODES } from "./types/rpc.js";
|
|
5
|
+
/**
|
|
6
|
+
* Base class for plugin errors that map to JSON-RPC errors
|
|
7
|
+
*/
|
|
8
|
+
export class PluginError extends Error {
|
|
9
|
+
data;
|
|
10
|
+
constructor(message, data) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = this.constructor.name;
|
|
13
|
+
this.data = data;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Convert to JSON-RPC error format
|
|
17
|
+
*/
|
|
18
|
+
toJsonRpcError() {
|
|
19
|
+
return {
|
|
20
|
+
code: this.code,
|
|
21
|
+
message: this.message,
|
|
22
|
+
data: this.data,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Thrown when rate limited by an external API
|
|
28
|
+
*/
|
|
29
|
+
export class RateLimitError extends PluginError {
|
|
30
|
+
code = PLUGIN_ERROR_CODES.RATE_LIMITED;
|
|
31
|
+
/** Seconds to wait before retrying */
|
|
32
|
+
retryAfterSeconds;
|
|
33
|
+
constructor(retryAfterSeconds, message) {
|
|
34
|
+
super(message ?? `Rate limited, retry after ${retryAfterSeconds}s`, {
|
|
35
|
+
retryAfterSeconds,
|
|
36
|
+
});
|
|
37
|
+
this.retryAfterSeconds = retryAfterSeconds;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Thrown when a requested resource is not found
|
|
42
|
+
*/
|
|
43
|
+
export class NotFoundError extends PluginError {
|
|
44
|
+
code = PLUGIN_ERROR_CODES.NOT_FOUND;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Thrown when authentication fails (invalid credentials)
|
|
48
|
+
*/
|
|
49
|
+
export class AuthError extends PluginError {
|
|
50
|
+
code = PLUGIN_ERROR_CODES.AUTH_FAILED;
|
|
51
|
+
constructor(message) {
|
|
52
|
+
super(message ?? "Authentication failed");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Thrown when an external API returns an error
|
|
57
|
+
*/
|
|
58
|
+
export class ApiError extends PluginError {
|
|
59
|
+
code = PLUGIN_ERROR_CODES.API_ERROR;
|
|
60
|
+
statusCode;
|
|
61
|
+
constructor(message, statusCode) {
|
|
62
|
+
super(message, statusCode !== undefined ? { statusCode } : undefined);
|
|
63
|
+
this.statusCode = statusCode;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Thrown when the plugin is misconfigured
|
|
68
|
+
*/
|
|
69
|
+
export class ConfigError extends PluginError {
|
|
70
|
+
code = PLUGIN_ERROR_CODES.CONFIG_ERROR;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAqB,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEvE;;GAEG;AACH,MAAM,OAAgB,WAAY,SAAQ,KAAK;IAEpC,IAAI,CAAW;IAExB,YAAY,OAAe,EAAE,IAAc;QACzC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,IAAI,EAAE,IAAI,CAAC,IAAI;SAChB,CAAC;IACJ,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,cAAe,SAAQ,WAAW;IACpC,IAAI,GAAG,kBAAkB,CAAC,YAAY,CAAC;IAChD,sCAAsC;IAC7B,iBAAiB,CAAS;IAEnC,YAAY,iBAAyB,EAAE,OAAgB;QACrD,KAAK,CAAC,OAAO,IAAI,6BAA6B,iBAAiB,GAAG,EAAE;YAClE,iBAAiB;SAClB,CAAC,CAAC;QACH,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC7C,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,WAAW;IACnC,IAAI,GAAG,kBAAkB,CAAC,SAAS,CAAC;CAC9C;AAED;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,WAAW;IAC/B,IAAI,GAAG,kBAAkB,CAAC,WAAW,CAAC;IAE/C,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,IAAI,uBAAuB,CAAC,CAAC;IAC5C,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,QAAS,SAAQ,WAAW;IAC9B,IAAI,GAAG,kBAAkB,CAAC,SAAS,CAAC;IACpC,UAAU,CAAqB;IAExC,YAAY,OAAe,EAAE,UAAmB;QAC9C,KAAK,CAAC,OAAO,EAAE,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QACtE,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,WAAW;IACjC,IAAI,GAAG,kBAAkB,CAAC,YAAY,CAAC;CACjD"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ashdev/codex-plugin-sdk
|
|
3
|
+
*
|
|
4
|
+
* SDK for building Codex plugins. Provides types, utilities, and a server
|
|
5
|
+
* framework for communicating with Codex via JSON-RPC over stdio.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import {
|
|
10
|
+
* createMetadataPlugin,
|
|
11
|
+
* type MetadataProvider,
|
|
12
|
+
* type PluginManifest,
|
|
13
|
+
* } from "@ashdev/codex-plugin-sdk";
|
|
14
|
+
*
|
|
15
|
+
* const manifest: PluginManifest = {
|
|
16
|
+
* name: "my-plugin",
|
|
17
|
+
* displayName: "My Plugin",
|
|
18
|
+
* version: "1.0.0",
|
|
19
|
+
* description: "A custom metadata plugin",
|
|
20
|
+
* author: "Your Name",
|
|
21
|
+
* protocolVersion: "1.0",
|
|
22
|
+
* capabilities: { metadataProvider: ["series"] },
|
|
23
|
+
* };
|
|
24
|
+
*
|
|
25
|
+
* const provider: MetadataProvider = {
|
|
26
|
+
* async search(params) {
|
|
27
|
+
* return {
|
|
28
|
+
* results: [{
|
|
29
|
+
* externalId: "123",
|
|
30
|
+
* title: "Example",
|
|
31
|
+
* alternateTitles: [],
|
|
32
|
+
* relevanceScore: 0.95,
|
|
33
|
+
* }],
|
|
34
|
+
* };
|
|
35
|
+
* },
|
|
36
|
+
* async get(params) {
|
|
37
|
+
* return {
|
|
38
|
+
* externalId: params.externalId,
|
|
39
|
+
* externalUrl: "https://example.com/123",
|
|
40
|
+
* alternateTitles: [],
|
|
41
|
+
* genres: [],
|
|
42
|
+
* tags: [],
|
|
43
|
+
* authors: [],
|
|
44
|
+
* artists: [],
|
|
45
|
+
* externalLinks: [],
|
|
46
|
+
* };
|
|
47
|
+
* },
|
|
48
|
+
* };
|
|
49
|
+
*
|
|
50
|
+
* createMetadataPlugin({ manifest, provider });
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @packageDocumentation
|
|
54
|
+
*/
|
|
55
|
+
export { ApiError, AuthError, ConfigError, NotFoundError, PluginError, RateLimitError, } from "./errors.js";
|
|
56
|
+
export { createLogger, Logger, type LoggerOptions, type LogLevel } from "./logger.js";
|
|
57
|
+
export { createMetadataPlugin, createSeriesMetadataPlugin, type InitializeParams, type MetadataPluginOptions, type SeriesMetadataPluginOptions, } from "./server.js";
|
|
58
|
+
export * from "./types/index.js";
|
|
59
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAGH,OAAO,EACL,QAAQ,EACR,SAAS,EACT,WAAW,EACX,aAAa,EACb,WAAW,EACX,cAAc,GACf,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEtF,OAAO,EAEL,oBAAoB,EAEpB,0BAA0B,EAC1B,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,2BAA2B,GACjC,MAAM,aAAa,CAAC;AAGrB,cAAc,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ashdev/codex-plugin-sdk
|
|
3
|
+
*
|
|
4
|
+
* SDK for building Codex plugins. Provides types, utilities, and a server
|
|
5
|
+
* framework for communicating with Codex via JSON-RPC over stdio.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import {
|
|
10
|
+
* createMetadataPlugin,
|
|
11
|
+
* type MetadataProvider,
|
|
12
|
+
* type PluginManifest,
|
|
13
|
+
* } from "@ashdev/codex-plugin-sdk";
|
|
14
|
+
*
|
|
15
|
+
* const manifest: PluginManifest = {
|
|
16
|
+
* name: "my-plugin",
|
|
17
|
+
* displayName: "My Plugin",
|
|
18
|
+
* version: "1.0.0",
|
|
19
|
+
* description: "A custom metadata plugin",
|
|
20
|
+
* author: "Your Name",
|
|
21
|
+
* protocolVersion: "1.0",
|
|
22
|
+
* capabilities: { metadataProvider: ["series"] },
|
|
23
|
+
* };
|
|
24
|
+
*
|
|
25
|
+
* const provider: MetadataProvider = {
|
|
26
|
+
* async search(params) {
|
|
27
|
+
* return {
|
|
28
|
+
* results: [{
|
|
29
|
+
* externalId: "123",
|
|
30
|
+
* title: "Example",
|
|
31
|
+
* alternateTitles: [],
|
|
32
|
+
* relevanceScore: 0.95,
|
|
33
|
+
* }],
|
|
34
|
+
* };
|
|
35
|
+
* },
|
|
36
|
+
* async get(params) {
|
|
37
|
+
* return {
|
|
38
|
+
* externalId: params.externalId,
|
|
39
|
+
* externalUrl: "https://example.com/123",
|
|
40
|
+
* alternateTitles: [],
|
|
41
|
+
* genres: [],
|
|
42
|
+
* tags: [],
|
|
43
|
+
* authors: [],
|
|
44
|
+
* artists: [],
|
|
45
|
+
* externalLinks: [],
|
|
46
|
+
* };
|
|
47
|
+
* },
|
|
48
|
+
* };
|
|
49
|
+
*
|
|
50
|
+
* createMetadataPlugin({ manifest, provider });
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @packageDocumentation
|
|
54
|
+
*/
|
|
55
|
+
// Errors
|
|
56
|
+
export { ApiError, AuthError, ConfigError, NotFoundError, PluginError, RateLimitError, } from "./errors.js";
|
|
57
|
+
// Logger
|
|
58
|
+
export { createLogger, Logger } from "./logger.js";
|
|
59
|
+
// Server
|
|
60
|
+
export {
|
|
61
|
+
// Primary exports
|
|
62
|
+
createMetadataPlugin,
|
|
63
|
+
// Deprecated aliases
|
|
64
|
+
createSeriesMetadataPlugin, } from "./server.js";
|
|
65
|
+
// Types
|
|
66
|
+
export * from "./types/index.js";
|
|
67
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAEH,SAAS;AACT,OAAO,EACL,QAAQ,EACR,SAAS,EACT,WAAW,EACX,aAAa,EACb,WAAW,EACX,cAAc,GACf,MAAM,aAAa,CAAC;AAErB,SAAS;AACT,OAAO,EAAE,YAAY,EAAE,MAAM,EAAqC,MAAM,aAAa,CAAC;AACtF,SAAS;AACT,OAAO;AACL,kBAAkB;AAClB,oBAAoB;AACpB,qBAAqB;AACrB,0BAA0B,GAI3B,MAAM,aAAa,CAAC;AAErB,QAAQ;AACR,cAAc,kBAAkB,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logging utilities for plugins
|
|
3
|
+
*
|
|
4
|
+
* IMPORTANT: Plugins must ONLY write to stderr for logging.
|
|
5
|
+
* stdout is reserved for JSON-RPC communication.
|
|
6
|
+
*/
|
|
7
|
+
export type LogLevel = "debug" | "info" | "warn" | "error";
|
|
8
|
+
export interface LoggerOptions {
|
|
9
|
+
/** Plugin name to prefix log messages */
|
|
10
|
+
name: string;
|
|
11
|
+
/** Minimum log level (default: "info") */
|
|
12
|
+
level?: LogLevel;
|
|
13
|
+
/** Whether to include timestamps (default: true) */
|
|
14
|
+
timestamps?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Logger that writes to stderr (safe for plugins)
|
|
18
|
+
*/
|
|
19
|
+
export declare class Logger {
|
|
20
|
+
private readonly name;
|
|
21
|
+
private readonly minLevel;
|
|
22
|
+
private readonly timestamps;
|
|
23
|
+
constructor(options: LoggerOptions);
|
|
24
|
+
private shouldLog;
|
|
25
|
+
private format;
|
|
26
|
+
private log;
|
|
27
|
+
debug(message: string, data?: unknown): void;
|
|
28
|
+
info(message: string, data?: unknown): void;
|
|
29
|
+
warn(message: string, data?: unknown): void;
|
|
30
|
+
error(message: string, data?: unknown): void;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a logger for a plugin
|
|
34
|
+
*/
|
|
35
|
+
export declare function createLogger(options: LoggerOptions): Logger;
|
|
36
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAS3D,MAAM,WAAW,aAAa;IAC5B,yCAAyC;IACzC,IAAI,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,KAAK,CAAC,EAAE,QAAQ,CAAC;IACjB,oDAAoD;IACpD,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAU;gBAEzB,OAAO,EAAE,aAAa;IAMlC,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,MAAM;IA2Bd,OAAO,CAAC,GAAG;IAOX,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAI5C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAI3C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAI3C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;CAG7C;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAE3D"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logging utilities for plugins
|
|
3
|
+
*
|
|
4
|
+
* IMPORTANT: Plugins must ONLY write to stderr for logging.
|
|
5
|
+
* stdout is reserved for JSON-RPC communication.
|
|
6
|
+
*/
|
|
7
|
+
const LOG_LEVELS = {
|
|
8
|
+
debug: 0,
|
|
9
|
+
info: 1,
|
|
10
|
+
warn: 2,
|
|
11
|
+
error: 3,
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Logger that writes to stderr (safe for plugins)
|
|
15
|
+
*/
|
|
16
|
+
export class Logger {
|
|
17
|
+
name;
|
|
18
|
+
minLevel;
|
|
19
|
+
timestamps;
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.name = options.name;
|
|
22
|
+
this.minLevel = LOG_LEVELS[options.level ?? "info"];
|
|
23
|
+
this.timestamps = options.timestamps ?? true;
|
|
24
|
+
}
|
|
25
|
+
shouldLog(level) {
|
|
26
|
+
return LOG_LEVELS[level] >= this.minLevel;
|
|
27
|
+
}
|
|
28
|
+
format(level, message, data) {
|
|
29
|
+
const parts = [];
|
|
30
|
+
if (this.timestamps) {
|
|
31
|
+
parts.push(new Date().toISOString());
|
|
32
|
+
}
|
|
33
|
+
parts.push(`[${level.toUpperCase()}]`);
|
|
34
|
+
parts.push(`[${this.name}]`);
|
|
35
|
+
parts.push(message);
|
|
36
|
+
if (data !== undefined) {
|
|
37
|
+
if (data instanceof Error) {
|
|
38
|
+
parts.push(`- ${data.message}`);
|
|
39
|
+
if (data.stack) {
|
|
40
|
+
parts.push(`\n${data.stack}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else if (typeof data === "object") {
|
|
44
|
+
parts.push(`- ${JSON.stringify(data)}`);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
parts.push(`- ${String(data)}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return parts.join(" ");
|
|
51
|
+
}
|
|
52
|
+
log(level, message, data) {
|
|
53
|
+
if (this.shouldLog(level)) {
|
|
54
|
+
// Write to stderr (not stdout!) - stdout is for JSON-RPC only
|
|
55
|
+
process.stderr.write(`${this.format(level, message, data)}\n`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
debug(message, data) {
|
|
59
|
+
this.log("debug", message, data);
|
|
60
|
+
}
|
|
61
|
+
info(message, data) {
|
|
62
|
+
this.log("info", message, data);
|
|
63
|
+
}
|
|
64
|
+
warn(message, data) {
|
|
65
|
+
this.log("warn", message, data);
|
|
66
|
+
}
|
|
67
|
+
error(message, data) {
|
|
68
|
+
this.log("error", message, data);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Create a logger for a plugin
|
|
73
|
+
*/
|
|
74
|
+
export function createLogger(options) {
|
|
75
|
+
return new Logger(options);
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"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"}
|