@quilltap/plugin-types 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/CHANGELOG.md ADDED
@@ -0,0 +1,41 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [1.0.0] - 2024-12-30
9
+
10
+ ### Added
11
+
12
+ - Initial release of `@quilltap/plugin-types`
13
+ - Core LLM types:
14
+ - `LLMProvider` interface
15
+ - `LLMParams`, `LLMResponse`, `StreamChunk` types
16
+ - `LLMMessage`, `FileAttachment` types
17
+ - `ImageGenParams`, `ImageGenResponse` types
18
+ - `ModelMetadata`, `ModelWarning` types
19
+ - Tool/function calling types:
20
+ - `OpenAIToolDefinition`, `AnthropicToolDefinition`, `GoogleToolDefinition`
21
+ - `UniversalTool` (alias for OpenAI format)
22
+ - `ToolCall`, `ToolCallRequest`, `ToolResult`
23
+ - Plugin interface types:
24
+ - `LLMProviderPlugin` main interface
25
+ - `ProviderMetadata`, `ProviderCapabilities`
26
+ - `AttachmentSupport`, `ModelInfo`
27
+ - `EmbeddingModelInfo`, `ImageGenerationModelInfo`
28
+ - Plugin manifest types:
29
+ - `PluginManifest` schema
30
+ - `PluginCapability`, `PluginCategory`, `PluginStatus`
31
+ - `InstalledPluginInfo`
32
+ - Common utilities:
33
+ - Error classes: `PluginError`, `ApiKeyError`, `ProviderApiError`, `RateLimitError`
34
+ - Additional errors: `ConfigurationError`, `ModelNotFoundError`, `AttachmentError`, `ToolExecutionError`
35
+ - Logger interface: `PluginLogger`
36
+ - Logger factories: `createConsoleLogger`, `createNoopLogger`
37
+ - Submodule exports for granular imports:
38
+ - `@quilltap/plugin-types/llm`
39
+ - `@quilltap/plugin-types/plugins`
40
+ - `@quilltap/plugin-types/common`
41
+ - `PLUGIN_TYPES_VERSION` export for runtime compatibility checks
package/README.md ADDED
@@ -0,0 +1,187 @@
1
+ # @quilltap/plugin-types
2
+
3
+ Type definitions for building Quilltap plugins.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install --save-dev @quilltap/plugin-types
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Basic Plugin
14
+
15
+ ```typescript
16
+ import type {
17
+ LLMProviderPlugin,
18
+ LLMProvider,
19
+ LLMParams,
20
+ LLMResponse
21
+ } from '@quilltap/plugin-types';
22
+
23
+ export const plugin: LLMProviderPlugin = {
24
+ metadata: {
25
+ providerName: 'MY_PROVIDER',
26
+ displayName: 'My Provider',
27
+ description: 'A custom LLM provider',
28
+ abbreviation: 'MYP',
29
+ colors: {
30
+ bg: 'bg-blue-100',
31
+ text: 'text-blue-800',
32
+ icon: 'text-blue-600',
33
+ },
34
+ },
35
+ config: {
36
+ requiresApiKey: true,
37
+ requiresBaseUrl: false,
38
+ apiKeyLabel: 'API Key',
39
+ },
40
+ capabilities: {
41
+ chat: true,
42
+ imageGeneration: false,
43
+ embeddings: false,
44
+ webSearch: false,
45
+ },
46
+ attachmentSupport: {
47
+ supportsAttachments: false,
48
+ supportedMimeTypes: [],
49
+ description: 'No file attachments supported',
50
+ },
51
+ createProvider: () => new MyProvider(),
52
+ getAvailableModels: async (apiKey) => ['model-1', 'model-2'],
53
+ validateApiKey: async (apiKey) => true,
54
+ renderIcon: ({ className }) => <MyIcon className={className} />,
55
+ };
56
+ ```
57
+
58
+ ### Submodule Imports
59
+
60
+ You can import from specific submodules for more granular imports:
61
+
62
+ ```typescript
63
+ // LLM types only
64
+ import type { LLMProvider, LLMParams, LLMResponse } from '@quilltap/plugin-types/llm';
65
+
66
+ // Plugin types only
67
+ import type { LLMProviderPlugin, PluginManifest } from '@quilltap/plugin-types/plugins';
68
+
69
+ // Common utilities
70
+ import { createConsoleLogger, PluginError } from '@quilltap/plugin-types/common';
71
+ ```
72
+
73
+ ### Error Handling
74
+
75
+ The package provides standard error classes for consistent error handling:
76
+
77
+ ```typescript
78
+ import {
79
+ PluginError,
80
+ ApiKeyError,
81
+ ProviderApiError,
82
+ RateLimitError
83
+ } from '@quilltap/plugin-types';
84
+
85
+ // Throwing errors
86
+ throw new ApiKeyError('Invalid API key', 'my-plugin');
87
+ throw new RateLimitError('Rate limited', 60, 'my-plugin');
88
+
89
+ // Catching errors
90
+ try {
91
+ await provider.sendMessage(params, apiKey);
92
+ } catch (error) {
93
+ if (error instanceof RateLimitError) {
94
+ console.log(`Retry after ${error.retryAfter} seconds`);
95
+ } else if (error instanceof ProviderApiError) {
96
+ console.log(`API error: ${error.statusCode}`);
97
+ }
98
+ }
99
+ ```
100
+
101
+ ### Logging
102
+
103
+ Use the built-in logger for development:
104
+
105
+ ```typescript
106
+ import { createConsoleLogger } from '@quilltap/plugin-types';
107
+
108
+ const logger = createConsoleLogger('my-plugin', 'debug');
109
+
110
+ logger.debug('Initializing plugin', { version: '1.0.0' });
111
+ logger.info('Plugin ready');
112
+ logger.warn('Deprecated feature used');
113
+ logger.error('Failed to connect', { endpoint: 'api.example.com' }, error);
114
+ ```
115
+
116
+ ## Type Reference
117
+
118
+ ### LLM Types
119
+
120
+ | Type | Description |
121
+ |------|-------------|
122
+ | `LLMProvider` | Core provider interface |
123
+ | `LLMParams` | Request parameters |
124
+ | `LLMResponse` | Complete response |
125
+ | `StreamChunk` | Streaming response chunk |
126
+ | `LLMMessage` | Conversation message |
127
+ | `FileAttachment` | File attachment for multimodal |
128
+ | `ToolCall` | Tool/function call |
129
+ | `ImageGenParams` | Image generation parameters |
130
+ | `ImageGenResponse` | Image generation response |
131
+
132
+ ### Plugin Types
133
+
134
+ | Type | Description |
135
+ |------|-------------|
136
+ | `LLMProviderPlugin` | Main plugin interface |
137
+ | `ProviderMetadata` | UI display metadata |
138
+ | `ProviderCapabilities` | Capability flags |
139
+ | `AttachmentSupport` | File attachment config |
140
+ | `PluginManifest` | Plugin manifest schema |
141
+
142
+ ### Common Types
143
+
144
+ | Type | Description |
145
+ |------|-------------|
146
+ | `PluginLogger` | Logger interface |
147
+ | `LogLevel` | Log level type |
148
+ | `PluginError` | Base error class |
149
+ | `ApiKeyError` | API key validation error |
150
+ | `ProviderApiError` | Provider API error |
151
+ | `RateLimitError` | Rate limit error |
152
+
153
+ ## Plugin Manifest
154
+
155
+ Every Quilltap plugin needs a `quilltap-manifest.json` file:
156
+
157
+ ```json
158
+ {
159
+ "$schema": "https://quilltap.io/schemas/plugin-manifest.json",
160
+ "name": "qtap-plugin-my-provider",
161
+ "title": "My Provider",
162
+ "description": "A custom LLM provider for Quilltap",
163
+ "version": "1.0.0",
164
+ "author": {
165
+ "name": "Your Name",
166
+ "email": "you@example.com"
167
+ },
168
+ "license": "MIT",
169
+ "compatibility": {
170
+ "quilltapVersion": ">=1.7.0"
171
+ },
172
+ "capabilities": ["LLM_PROVIDER"],
173
+ "category": "PROVIDER",
174
+ "main": "dist/index.js",
175
+ "status": "STABLE"
176
+ }
177
+ ```
178
+
179
+ ## Documentation
180
+
181
+ - [Plugin Development Guide](https://docs.quilltap.io/plugins/development)
182
+ - [API Reference](https://docs.quilltap.io/plugins/api)
183
+ - [Example Plugins](https://github.com/foundry-9/quilltap/tree/main/plugins/dist)
184
+
185
+ ## License
186
+
187
+ MIT
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Logger types for Quilltap plugin development
3
+ *
4
+ * @module @quilltap/plugin-types/common/logger
5
+ */
6
+ /**
7
+ * Log level type
8
+ */
9
+ type LogLevel = 'debug' | 'info' | 'warn' | 'error';
10
+ /**
11
+ * Log context metadata
12
+ */
13
+ interface LogContext {
14
+ /** Context identifier (e.g., module name) */
15
+ context?: string;
16
+ /** Additional metadata */
17
+ [key: string]: unknown;
18
+ }
19
+ /**
20
+ * Logger interface that plugins can implement or receive
21
+ *
22
+ * This interface is compatible with Quilltap's built-in logger.
23
+ * Plugins can use this interface to accept a logger from the host
24
+ * application or implement their own logging.
25
+ */
26
+ interface PluginLogger {
27
+ /**
28
+ * Log a debug message
29
+ * @param message Message to log
30
+ * @param context Optional context metadata
31
+ */
32
+ debug(message: string, context?: LogContext): void;
33
+ /**
34
+ * Log an info message
35
+ * @param message Message to log
36
+ * @param context Optional context metadata
37
+ */
38
+ info(message: string, context?: LogContext): void;
39
+ /**
40
+ * Log a warning message
41
+ * @param message Message to log
42
+ * @param context Optional context metadata
43
+ */
44
+ warn(message: string, context?: LogContext): void;
45
+ /**
46
+ * Log an error message
47
+ * @param message Message to log
48
+ * @param context Optional context metadata
49
+ * @param error Optional error object
50
+ */
51
+ error(message: string, context?: LogContext, error?: Error): void;
52
+ }
53
+ /**
54
+ * Simple console-based logger for standalone plugin development
55
+ *
56
+ * This logger writes to the console and is useful for local
57
+ * plugin development and testing.
58
+ *
59
+ * @param prefix Prefix to add to all log messages
60
+ * @param minLevel Minimum log level to output (default: 'info')
61
+ * @returns A PluginLogger instance
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const logger = createConsoleLogger('my-plugin', 'debug');
66
+ * logger.debug('Initializing plugin', { version: '1.0.0' });
67
+ * logger.info('Plugin ready');
68
+ * logger.error('Failed to connect', { endpoint: 'api.example.com' }, new Error('Connection refused'));
69
+ * ```
70
+ */
71
+ declare function createConsoleLogger(prefix: string, minLevel?: LogLevel): PluginLogger;
72
+ /**
73
+ * No-op logger for production or when logging is disabled
74
+ *
75
+ * @returns A PluginLogger that does nothing
76
+ */
77
+ declare function createNoopLogger(): PluginLogger;
78
+
79
+ /**
80
+ * Common error types for Quilltap plugin development
81
+ *
82
+ * @module @quilltap/plugin-types/common/errors
83
+ */
84
+ /**
85
+ * Base plugin error
86
+ *
87
+ * All plugin-specific errors should extend this class.
88
+ */
89
+ declare class PluginError extends Error {
90
+ readonly code: string;
91
+ readonly pluginName?: string | undefined;
92
+ constructor(message: string, code: string, pluginName?: string | undefined);
93
+ }
94
+ /**
95
+ * API key validation error
96
+ *
97
+ * Thrown when an API key is invalid or has insufficient permissions.
98
+ */
99
+ declare class ApiKeyError extends PluginError {
100
+ constructor(message: string, pluginName?: string);
101
+ }
102
+ /**
103
+ * Provider API error
104
+ *
105
+ * Thrown when the provider API returns an error.
106
+ */
107
+ declare class ProviderApiError extends PluginError {
108
+ readonly statusCode?: number | undefined;
109
+ readonly response?: unknown | undefined;
110
+ constructor(message: string, statusCode?: number | undefined, response?: unknown | undefined, pluginName?: string);
111
+ }
112
+ /**
113
+ * Rate limit error
114
+ *
115
+ * Thrown when the provider rate limits the request.
116
+ */
117
+ declare class RateLimitError extends ProviderApiError {
118
+ readonly retryAfter?: number | undefined;
119
+ readonly code = "RATE_LIMIT_ERROR";
120
+ constructor(message: string, retryAfter?: number | undefined, pluginName?: string);
121
+ }
122
+ /**
123
+ * Configuration error
124
+ *
125
+ * Thrown when plugin configuration is invalid.
126
+ */
127
+ declare class ConfigurationError extends PluginError {
128
+ constructor(message: string, pluginName?: string);
129
+ }
130
+ /**
131
+ * Model not found error
132
+ *
133
+ * Thrown when a requested model is not available.
134
+ */
135
+ declare class ModelNotFoundError extends PluginError {
136
+ readonly modelId?: string | undefined;
137
+ constructor(message: string, modelId?: string | undefined, pluginName?: string);
138
+ }
139
+ /**
140
+ * Attachment error
141
+ *
142
+ * Thrown when there's an issue processing file attachments.
143
+ */
144
+ declare class AttachmentError extends PluginError {
145
+ readonly attachmentId?: string | undefined;
146
+ constructor(message: string, attachmentId?: string | undefined, pluginName?: string);
147
+ }
148
+ /**
149
+ * Tool execution error
150
+ *
151
+ * Thrown when a tool call fails to execute.
152
+ */
153
+ declare class ToolExecutionError extends PluginError {
154
+ readonly toolName?: string | undefined;
155
+ constructor(message: string, toolName?: string | undefined, pluginName?: string);
156
+ }
157
+
158
+ export { ApiKeyError, AttachmentError, ConfigurationError, type LogContext, type LogLevel, ModelNotFoundError, PluginError, type PluginLogger, ProviderApiError, RateLimitError, ToolExecutionError, createConsoleLogger, createNoopLogger };
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Logger types for Quilltap plugin development
3
+ *
4
+ * @module @quilltap/plugin-types/common/logger
5
+ */
6
+ /**
7
+ * Log level type
8
+ */
9
+ type LogLevel = 'debug' | 'info' | 'warn' | 'error';
10
+ /**
11
+ * Log context metadata
12
+ */
13
+ interface LogContext {
14
+ /** Context identifier (e.g., module name) */
15
+ context?: string;
16
+ /** Additional metadata */
17
+ [key: string]: unknown;
18
+ }
19
+ /**
20
+ * Logger interface that plugins can implement or receive
21
+ *
22
+ * This interface is compatible with Quilltap's built-in logger.
23
+ * Plugins can use this interface to accept a logger from the host
24
+ * application or implement their own logging.
25
+ */
26
+ interface PluginLogger {
27
+ /**
28
+ * Log a debug message
29
+ * @param message Message to log
30
+ * @param context Optional context metadata
31
+ */
32
+ debug(message: string, context?: LogContext): void;
33
+ /**
34
+ * Log an info message
35
+ * @param message Message to log
36
+ * @param context Optional context metadata
37
+ */
38
+ info(message: string, context?: LogContext): void;
39
+ /**
40
+ * Log a warning message
41
+ * @param message Message to log
42
+ * @param context Optional context metadata
43
+ */
44
+ warn(message: string, context?: LogContext): void;
45
+ /**
46
+ * Log an error message
47
+ * @param message Message to log
48
+ * @param context Optional context metadata
49
+ * @param error Optional error object
50
+ */
51
+ error(message: string, context?: LogContext, error?: Error): void;
52
+ }
53
+ /**
54
+ * Simple console-based logger for standalone plugin development
55
+ *
56
+ * This logger writes to the console and is useful for local
57
+ * plugin development and testing.
58
+ *
59
+ * @param prefix Prefix to add to all log messages
60
+ * @param minLevel Minimum log level to output (default: 'info')
61
+ * @returns A PluginLogger instance
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const logger = createConsoleLogger('my-plugin', 'debug');
66
+ * logger.debug('Initializing plugin', { version: '1.0.0' });
67
+ * logger.info('Plugin ready');
68
+ * logger.error('Failed to connect', { endpoint: 'api.example.com' }, new Error('Connection refused'));
69
+ * ```
70
+ */
71
+ declare function createConsoleLogger(prefix: string, minLevel?: LogLevel): PluginLogger;
72
+ /**
73
+ * No-op logger for production or when logging is disabled
74
+ *
75
+ * @returns A PluginLogger that does nothing
76
+ */
77
+ declare function createNoopLogger(): PluginLogger;
78
+
79
+ /**
80
+ * Common error types for Quilltap plugin development
81
+ *
82
+ * @module @quilltap/plugin-types/common/errors
83
+ */
84
+ /**
85
+ * Base plugin error
86
+ *
87
+ * All plugin-specific errors should extend this class.
88
+ */
89
+ declare class PluginError extends Error {
90
+ readonly code: string;
91
+ readonly pluginName?: string | undefined;
92
+ constructor(message: string, code: string, pluginName?: string | undefined);
93
+ }
94
+ /**
95
+ * API key validation error
96
+ *
97
+ * Thrown when an API key is invalid or has insufficient permissions.
98
+ */
99
+ declare class ApiKeyError extends PluginError {
100
+ constructor(message: string, pluginName?: string);
101
+ }
102
+ /**
103
+ * Provider API error
104
+ *
105
+ * Thrown when the provider API returns an error.
106
+ */
107
+ declare class ProviderApiError extends PluginError {
108
+ readonly statusCode?: number | undefined;
109
+ readonly response?: unknown | undefined;
110
+ constructor(message: string, statusCode?: number | undefined, response?: unknown | undefined, pluginName?: string);
111
+ }
112
+ /**
113
+ * Rate limit error
114
+ *
115
+ * Thrown when the provider rate limits the request.
116
+ */
117
+ declare class RateLimitError extends ProviderApiError {
118
+ readonly retryAfter?: number | undefined;
119
+ readonly code = "RATE_LIMIT_ERROR";
120
+ constructor(message: string, retryAfter?: number | undefined, pluginName?: string);
121
+ }
122
+ /**
123
+ * Configuration error
124
+ *
125
+ * Thrown when plugin configuration is invalid.
126
+ */
127
+ declare class ConfigurationError extends PluginError {
128
+ constructor(message: string, pluginName?: string);
129
+ }
130
+ /**
131
+ * Model not found error
132
+ *
133
+ * Thrown when a requested model is not available.
134
+ */
135
+ declare class ModelNotFoundError extends PluginError {
136
+ readonly modelId?: string | undefined;
137
+ constructor(message: string, modelId?: string | undefined, pluginName?: string);
138
+ }
139
+ /**
140
+ * Attachment error
141
+ *
142
+ * Thrown when there's an issue processing file attachments.
143
+ */
144
+ declare class AttachmentError extends PluginError {
145
+ readonly attachmentId?: string | undefined;
146
+ constructor(message: string, attachmentId?: string | undefined, pluginName?: string);
147
+ }
148
+ /**
149
+ * Tool execution error
150
+ *
151
+ * Thrown when a tool call fails to execute.
152
+ */
153
+ declare class ToolExecutionError extends PluginError {
154
+ readonly toolName?: string | undefined;
155
+ constructor(message: string, toolName?: string | undefined, pluginName?: string);
156
+ }
157
+
158
+ export { ApiKeyError, AttachmentError, ConfigurationError, type LogContext, type LogLevel, ModelNotFoundError, PluginError, type PluginLogger, ProviderApiError, RateLimitError, ToolExecutionError, createConsoleLogger, createNoopLogger };
@@ -0,0 +1,120 @@
1
+ 'use strict';
2
+
3
+ // src/common/errors.ts
4
+ var PluginError = class extends Error {
5
+ constructor(message, code, pluginName) {
6
+ super(message);
7
+ this.code = code;
8
+ this.pluginName = pluginName;
9
+ this.name = "PluginError";
10
+ }
11
+ };
12
+ var ApiKeyError = class extends PluginError {
13
+ constructor(message, pluginName) {
14
+ super(message, "API_KEY_ERROR", pluginName);
15
+ this.name = "ApiKeyError";
16
+ }
17
+ };
18
+ var ProviderApiError = class extends PluginError {
19
+ constructor(message, statusCode, response, pluginName) {
20
+ super(message, "PROVIDER_API_ERROR", pluginName);
21
+ this.statusCode = statusCode;
22
+ this.response = response;
23
+ this.name = "ProviderApiError";
24
+ }
25
+ };
26
+ var RateLimitError = class extends ProviderApiError {
27
+ constructor(message, retryAfter, pluginName) {
28
+ super(message, 429, void 0, pluginName);
29
+ this.retryAfter = retryAfter;
30
+ this.code = "RATE_LIMIT_ERROR";
31
+ this.name = "RateLimitError";
32
+ }
33
+ };
34
+ var ConfigurationError = class extends PluginError {
35
+ constructor(message, pluginName) {
36
+ super(message, "CONFIGURATION_ERROR", pluginName);
37
+ this.name = "ConfigurationError";
38
+ }
39
+ };
40
+ var ModelNotFoundError = class extends PluginError {
41
+ constructor(message, modelId, pluginName) {
42
+ super(message, "MODEL_NOT_FOUND", pluginName);
43
+ this.modelId = modelId;
44
+ this.name = "ModelNotFoundError";
45
+ }
46
+ };
47
+ var AttachmentError = class extends PluginError {
48
+ constructor(message, attachmentId, pluginName) {
49
+ super(message, "ATTACHMENT_ERROR", pluginName);
50
+ this.attachmentId = attachmentId;
51
+ this.name = "AttachmentError";
52
+ }
53
+ };
54
+ var ToolExecutionError = class extends PluginError {
55
+ constructor(message, toolName, pluginName) {
56
+ super(message, "TOOL_EXECUTION_ERROR", pluginName);
57
+ this.toolName = toolName;
58
+ this.name = "ToolExecutionError";
59
+ }
60
+ };
61
+
62
+ // src/common/logger.ts
63
+ function createConsoleLogger(prefix, minLevel = "info") {
64
+ const levels = ["debug", "info", "warn", "error"];
65
+ const shouldLog = (level) => levels.indexOf(level) >= levels.indexOf(minLevel);
66
+ const formatContext = (context) => {
67
+ if (!context) return "";
68
+ const entries = Object.entries(context).filter(([key]) => key !== "context").map(([key, value]) => `${key}=${JSON.stringify(value)}`).join(" ");
69
+ return entries ? ` ${entries}` : "";
70
+ };
71
+ return {
72
+ debug: (message, context) => {
73
+ if (shouldLog("debug")) {
74
+ console.debug(`[${prefix}] ${message}${formatContext(context)}`);
75
+ }
76
+ },
77
+ info: (message, context) => {
78
+ if (shouldLog("info")) {
79
+ console.info(`[${prefix}] ${message}${formatContext(context)}`);
80
+ }
81
+ },
82
+ warn: (message, context) => {
83
+ if (shouldLog("warn")) {
84
+ console.warn(`[${prefix}] ${message}${formatContext(context)}`);
85
+ }
86
+ },
87
+ error: (message, context, error) => {
88
+ if (shouldLog("error")) {
89
+ console.error(
90
+ `[${prefix}] ${message}${formatContext(context)}`,
91
+ error ? `
92
+ ${error.stack || error.message}` : ""
93
+ );
94
+ }
95
+ }
96
+ };
97
+ }
98
+ function createNoopLogger() {
99
+ const noop = () => {
100
+ };
101
+ return {
102
+ debug: noop,
103
+ info: noop,
104
+ warn: noop,
105
+ error: noop
106
+ };
107
+ }
108
+
109
+ exports.ApiKeyError = ApiKeyError;
110
+ exports.AttachmentError = AttachmentError;
111
+ exports.ConfigurationError = ConfigurationError;
112
+ exports.ModelNotFoundError = ModelNotFoundError;
113
+ exports.PluginError = PluginError;
114
+ exports.ProviderApiError = ProviderApiError;
115
+ exports.RateLimitError = RateLimitError;
116
+ exports.ToolExecutionError = ToolExecutionError;
117
+ exports.createConsoleLogger = createConsoleLogger;
118
+ exports.createNoopLogger = createNoopLogger;
119
+ //# sourceMappingURL=index.js.map
120
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/common/errors.ts","../../src/common/logger.ts"],"names":[],"mappings":";;;AAWO,IAAM,WAAA,GAAN,cAA0B,KAAA,CAAM;AAAA,EACrC,WAAA,CACE,OAAA,EACgB,IAAA,EACA,UAAA,EAChB;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AAHG,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AACA,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AAGhB,IAAA,IAAA,CAAK,IAAA,GAAO,aAAA;AAAA,EACd;AACF;AAOO,IAAM,WAAA,GAAN,cAA0B,WAAA,CAAY;AAAA,EAC3C,WAAA,CAAY,SAAiB,UAAA,EAAqB;AAChD,IAAA,KAAA,CAAM,OAAA,EAAS,iBAAiB,UAAU,CAAA;AAC1C,IAAA,IAAA,CAAK,IAAA,GAAO,aAAA;AAAA,EACd;AACF;AAOO,IAAM,gBAAA,GAAN,cAA+B,WAAA,CAAY;AAAA,EAChD,WAAA,CACE,OAAA,EACgB,UAAA,EACA,QAAA,EAChB,UAAA,EACA;AACA,IAAA,KAAA,CAAM,OAAA,EAAS,sBAAsB,UAAU,CAAA;AAJ/B,IAAA,IAAA,CAAA,UAAA,GAAA,UAAA;AACA,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AAIhB,IAAA,IAAA,CAAK,IAAA,GAAO,kBAAA;AAAA,EACd;AACF;AAOO,IAAM,cAAA,GAAN,cAA6B,gBAAA,CAAiB;AAAA,EAGnD,WAAA,CACE,OAAA,EACgB,UAAA,EAChB,UAAA,EACA;AACA,IAAA,KAAA,CAAM,OAAA,EAAS,GAAA,EA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ChE;AAAA,IACF,CAAA;AAAA,IAEA,IAAA,EAAM,CAAC,OAAA,EAAiB,OAAA,KAA+B;AACrD,MAAA,IAAI,SAAA,CAAU,MAAM,CAAA,EAAG;AACrB,QAAA,OAAA,CAAQ,IAAA,CAAK,IAAI,MAAM,CAAA,EAAA,EAAK,OAAO,CAAA,EAAG,aAAA,CAAc,OAAO,CAAC,CAAA,CAAE,CAAA;AAAA,MAChE;AAAA,IACF,CAAA;AAAA,IAEA,KAAA,EAAO,CAAC,OAAA,EAAiB,OAAA,EAAsB,KAAA,KAAwB;AACrE,MAAA,IAAI,SAAA,CAAU,OAAO,CAAA,EAAG;AACtB,QAAA,OAAA,CAAQ,KAAA;AAAA,UACN,IAAI,MAAM,CAAA,EAAA,EAAK,OAAO,CAAA,EAAG,aAAA,CAAc,OAAO,CAAC,CAAA,CAAA;AAAA,UAC/C,KAAA,GAAQ;AAAA,EAAK,KAAA,CAAM,KAAA,IAAS,KAAA,CAAM,OAAO,CAAA,CAAA,GAAK;AAAA,SAChD;AAAA,MACF;AAAA,IACF;AAAA,GACF;AACF;AAOO,SAAS,gBAAA,GAAiC;AAC/C,EAAA,MAAM,OAAO,MAAY;AAAA,EAAC,CAAA;AAC1B,EAAA,OAAO;AAAA,IACL,KAAA,EAAO,IAAA;AAAA,IACP,IAAA,EAAM,IAAA;AAAA,IACN,IAAA,EAAM,IAAA;AAAA,IACN,KAAA,EAAO;AAAA,GACT;AACF","file":"index.js","sourcesContent":["/**\n * Common error types for Quilltap plugin development\n *\n * @module @quilltap/plugin-types/common/errors\n */\n\n/**\n * Base plugin error\n *\n * All plugin-specific errors should extend this class.\n */\nexport class PluginError extends Error {\n constructor(\n message: string,\n public readonly code: string,\n public readonly pluginName?: string\n ) {\n super(message);\n this.name = 'PluginError';\n }\n}\n\n/**\n * API key validation error\n *\n * Thrown when an API key is invalid or has insufficient permissions.\n */\nexport class ApiKeyError extends PluginError {\n constructor(message: string, pluginName?: string) {\n super(message, 'API_KEY_ERROR', pluginName);\n this.name = 'ApiKeyError';\n }\n}\n\n/**\n * Provider API error\n *\n * Thrown when the provider API returns an error.\n */\nexport class ProviderApiError extends PluginError {\n constructor(\n message: string,\n public readonly statusCode?: number,\n public readonly response?: unknown,\n pluginName?: string\n ) {\n super(message, 'PROVIDER_API_ERROR', pluginName);\n this.name = 'ProviderApiError';\n }\n}\n\n/**\n * Rate limit error\n *\n * Thrown when the provider rate limits the request.\n */\nexport class RateLimitError extends ProviderApiError {\n public override readonly code = 'RATE_LIMIT_ERROR';\n\n constructor(\n message: string,\n public readonly retryAfter?: number,\n pluginName?: string\n ) {\n super(message, 429, undefined, pluginName);\n this.name = 'RateLimitError';\n }\n}\n\n/**\n * Configuration error\n *\n * Thrown when plugin configuration is invalid.\n */\nexport class ConfigurationError extends PluginError {\n constructor(message: string, pluginName?: string) {\n super(message, 'CONFIGURATION_ERROR', pluginName);\n this.name = 'ConfigurationError';\n }\n}\n\n/**\n * Model not found error\n *\n * Thrown when a requested model is not available.\n */\nexport class ModelNotFoundError extends PluginError {\n constructor(\n message: string,\n public readonly modelId?: string,\n pluginName?: string\n ) {\n super(message, 'MODEL_NOT_FOUND', pluginName);\n this.name = 'ModelNotFoundError';\n }\n}\n\n/**\n * Attachment error\n *\n * Thrown when there's an issue processing file attachments.\n */\nexport class AttachmentError extends PluginError {\n constructor(\n message: string,\n public readonly attachmentId?: string,\n pluginName?: string\n ) {\n super(message, 'ATTACHMENT_ERROR', pluginName);\n this.name = 'AttachmentError';\n }\n}\n\n/**\n * Tool execution error\n *\n * Thrown when a tool call fails to execute.\n */\nexport class ToolExecutionError extends PluginError {\n constructor(\n message: string,\n public readonly toolName?: string,\n pluginName?: string\n ) {\n super(message, 'TOOL_EXECUTION_ERROR', pluginName);\n this.name = 'ToolExecutionError';\n }\n}\n","/**\n * Logger types for Quilltap plugin development\n *\n * @module @quilltap/plugin-types/common/logger\n */\n\n/**\n * Log level type\n */\nexport type LogLevel = 'debug' | 'info' | 'warn' | 'error';\n\n/**\n * Log context metadata\n */\nexport interface LogContext {\n /** Context identifier (e.g., module name) */\n context?: string;\n /** Additional metadata */\n [key: string]: unknown;\n}\n\n/**\n * Logger interface that plugins can implement or receive\n *\n * This interface is compatible with Quilltap's built-in logger.\n * Plugins can use this interface to accept a logger from the host\n * application or implement their own logging.\n */\nexport interface PluginLogger {\n /**\n * Log a debug message\n * @param message Message to log\n * @param context Optional context metadata\n */\n debug(message: string, context?: LogContext): void;\n\n /**\n * Log an info message\n * @param message Message to log\n * @param context Optional context metadata\n */\n info(message: string, context?: LogContext): void;\n\n /**\n * Log a warning message\n * @param message Message to log\n * @param context Optional context metadata\n */\n warn(message: string, context?: LogContext): void;\n\n /**\n * Log an error message\n * @param message Message to log\n * @param context Optional context metadata\n * @param error Optional error object\n */\n error(message: string, context?: LogContext, error?: Error): void;\n}\n\n/**\n * Simple console-based logger for standalone plugin development\n *\n * This logger writes to the console and is useful for local\n * plugin development and testing.\n *\n * @param prefix Prefix to add to all log messages\n * @param minLevel Minimum log level to output (default: 'info')\n * @returns A PluginLogger instance\n *\n * @example\n * ```typescript\n * const logger = createConsoleLogger('my-plugin', 'debug');\n * logger.debug('Initializing plugin', { version: '1.0.0' });\n * logger.info('Plugin ready');\n * logger.error('Failed to connect', { endpoint: 'api.example.com' }, new Error('Connection refused'));\n * ```\n */\nexport function createConsoleLogger(prefix: string, minLevel: LogLevel = 'info'): PluginLogger {\n const levels: LogLevel[] = ['debug', 'info', 'warn', 'error'];\n const shouldLog = (level: LogLevel): boolean =>\n levels.indexOf(level) >= levels.indexOf(minLevel);\n\n const formatContext = (context?: LogContext): string => {\n if (!context) return '';\n const entries = Object.entries(context)\n .filter(([key]) => key !== 'context')\n .map(([key, value]) => `${key}=${JSON.stringify(value)}`)\n .join(' ');\n return entries ? ` ${entries}` : '';\n };\n\n return {\n debug: (message: string, context?: LogContext): void => {\n if (shouldLog('debug')) {\n console.debug(`[${prefix}] ${message}${formatContext(context)}`);\n }\n },\n\n info: (message: string, context?: LogContext): void => {\n if (shouldLog('info')) {\n console.info(`[${prefix}] ${message}${formatContext(context)}`);\n }\n },\n\n warn: (message: string, context?: LogContext): void => {\n if (shouldLog('warn')) {\n console.warn(`[${prefix}] ${message}${formatContext(context)}`);\n }\n },\n\n error: (message: string, context?: LogContext, error?: Error): void => {\n if (shouldLog('error')) {\n console.error(\n `[${prefix}] ${message}${formatContext(context)}`,\n error ? `\\n${error.stack || error.message}` : ''\n );\n }\n },\n };\n}\n\n/**\n * No-op logger for production or when logging is disabled\n *\n * @returns A PluginLogger that does nothing\n */\nexport function createNoopLogger(): PluginLogger {\n const noop = (): void => {};\n return {\n debug: noop,\n info: noop,\n warn: noop,\n error: noop,\n };\n}\n"]}