@tokentop/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/LICENSE +21 -0
- package/README.md +121 -0
- package/dist/helpers/auth.d.ts +15 -0
- package/dist/helpers/auth.d.ts.map +1 -0
- package/dist/helpers/create.d.ts +11 -0
- package/dist/helpers/create.d.ts.map +1 -0
- package/dist/helpers/index.d.ts +4 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +182 -0
- package/dist/helpers/version.d.ts +6 -0
- package/dist/helpers/version.d.ts.map +1 -0
- package/dist/index-y0tp0jk5.js +15 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +41 -0
- package/dist/testing/harness.d.ts +49 -0
- package/dist/testing/harness.d.ts.map +1 -0
- package/dist/testing/index.d.ts +3 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +134 -0
- package/dist/types/agent.d.ts +89 -0
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/context.d.ts +93 -0
- package/dist/types/context.d.ts.map +1 -0
- package/dist/types/index.d.ts +21 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/notification.d.ts +33 -0
- package/dist/types/notification.d.ts.map +1 -0
- package/dist/types/plugin.d.ts +167 -0
- package/dist/types/plugin.d.ts.map +1 -0
- package/dist/types/provider.d.ts +138 -0
- package/dist/types/provider.d.ts.map +1 -0
- package/dist/types/theme.d.ts +53 -0
- package/dist/types/theme.d.ts.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { BasePlugin, PluginLogger } from './plugin.ts';
|
|
2
|
+
import type { PluginHttpClient, PluginContext } from './context.ts';
|
|
3
|
+
import type { Credentials, CredentialResult } from './provider.ts';
|
|
4
|
+
export interface AgentConfig {
|
|
5
|
+
/** Display name for this coding agent (e.g. "Claude Code", "Cursor"). */
|
|
6
|
+
name: string;
|
|
7
|
+
/** Path to the agent's config directory (for display/debugging). */
|
|
8
|
+
configPath?: string;
|
|
9
|
+
/** Path to the agent's session storage. */
|
|
10
|
+
sessionPath?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface AgentCapabilities {
|
|
13
|
+
sessionParsing: boolean;
|
|
14
|
+
authReading: boolean;
|
|
15
|
+
realTimeTracking: boolean;
|
|
16
|
+
multiProvider: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface AgentCredentials {
|
|
19
|
+
providers: Record<string, Credentials | undefined>;
|
|
20
|
+
}
|
|
21
|
+
export interface AgentProviderConfig {
|
|
22
|
+
id: string;
|
|
23
|
+
name: string;
|
|
24
|
+
configured: boolean;
|
|
25
|
+
enabled?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface SessionParseOptions {
|
|
28
|
+
sessionId?: string;
|
|
29
|
+
timePeriod?: 'session' | 'daily' | 'weekly' | 'monthly';
|
|
30
|
+
limit?: number;
|
|
31
|
+
}
|
|
32
|
+
export interface SessionUsageData {
|
|
33
|
+
sessionId: string;
|
|
34
|
+
sessionName?: string;
|
|
35
|
+
providerId: string;
|
|
36
|
+
modelId: string;
|
|
37
|
+
tokens: {
|
|
38
|
+
input: number;
|
|
39
|
+
output: number;
|
|
40
|
+
cacheRead?: number;
|
|
41
|
+
cacheWrite?: number;
|
|
42
|
+
};
|
|
43
|
+
timestamp: number;
|
|
44
|
+
sessionUpdatedAt?: number;
|
|
45
|
+
projectPath?: string;
|
|
46
|
+
cost?: number;
|
|
47
|
+
}
|
|
48
|
+
export interface ActivityUpdate {
|
|
49
|
+
sessionId: string;
|
|
50
|
+
messageId: string;
|
|
51
|
+
tokens: {
|
|
52
|
+
input: number;
|
|
53
|
+
output: number;
|
|
54
|
+
reasoning?: number;
|
|
55
|
+
cacheRead?: number;
|
|
56
|
+
cacheWrite?: number;
|
|
57
|
+
};
|
|
58
|
+
timestamp: number;
|
|
59
|
+
}
|
|
60
|
+
export type ActivityCallback = (update: ActivityUpdate) => void;
|
|
61
|
+
export interface AgentFetchContext {
|
|
62
|
+
readonly http: PluginHttpClient;
|
|
63
|
+
readonly logger: PluginLogger;
|
|
64
|
+
readonly config: Record<string, unknown>;
|
|
65
|
+
readonly signal: AbortSignal;
|
|
66
|
+
}
|
|
67
|
+
export interface AgentPlugin extends BasePlugin {
|
|
68
|
+
readonly type: 'agent';
|
|
69
|
+
readonly agent: AgentConfig;
|
|
70
|
+
readonly capabilities: AgentCapabilities;
|
|
71
|
+
/** Optional plugin-owned credential discovery for the agent's auth files. */
|
|
72
|
+
readonly auth?: {
|
|
73
|
+
discover(ctx: PluginContext): Promise<CredentialResult>;
|
|
74
|
+
isConfigured(credentials: Credentials): boolean;
|
|
75
|
+
};
|
|
76
|
+
/** Check if this coding agent is installed on the user's machine. */
|
|
77
|
+
isInstalled(ctx: PluginContext): Promise<boolean>;
|
|
78
|
+
/** Read credentials that the coding agent has stored. */
|
|
79
|
+
readCredentials?(ctx: AgentFetchContext): Promise<AgentCredentials>;
|
|
80
|
+
/** Parse session usage data from the agent's local storage. */
|
|
81
|
+
parseSessions(options: SessionParseOptions, ctx: AgentFetchContext): Promise<SessionUsageData[]>;
|
|
82
|
+
/** List which model providers this agent is configured to use. */
|
|
83
|
+
getProviders?(ctx: AgentFetchContext): Promise<AgentProviderConfig[]>;
|
|
84
|
+
/** Start watching for real-time activity updates. */
|
|
85
|
+
startActivityWatch?(ctx: PluginContext, callback: ActivityCallback): void;
|
|
86
|
+
/** Stop watching for real-time activity updates. */
|
|
87
|
+
stopActivityWatch?(ctx: PluginContext): void;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/types/agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC5D,OA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eAAe,CAAC,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAEpE,+DAA+D;IAC/D,aAAa,CAAC,OAAO,EAAE,mBAAmB,EAAE,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAEjG,kEAAkE;IAClE,YAAY,CAAC,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAAC;IAEtE,qDAAqD;IACrD,kBAAkB,CAAC,CAAC,GAAG,EAAE,aAAa,EAAE,QAAQ,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAE1E,oDAAoD;IACpD,iBAAiB,CAAC,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI,CAAC;CAC9C"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context interfaces injected into plugins at runtime by core.
|
|
3
|
+
*
|
|
4
|
+
* Plugins never construct these — core creates and injects them.
|
|
5
|
+
* The SDK defines the shapes so plugins can type their method signatures.
|
|
6
|
+
*/
|
|
7
|
+
import type { PluginLogger } from './plugin.ts';
|
|
8
|
+
/**
|
|
9
|
+
* Sandboxed HTTP client.
|
|
10
|
+
* Enforces the plugin's declared `permissions.network.allowedDomains`.
|
|
11
|
+
*/
|
|
12
|
+
export interface PluginHttpClient {
|
|
13
|
+
fetch(url: string, init?: RequestInit): Promise<Response>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Helpers for credential discovery, injected by core.
|
|
17
|
+
*
|
|
18
|
+
* All methods respect the plugin's declared permissions.
|
|
19
|
+
* Plugins use these to implement their own `auth.discover()` method
|
|
20
|
+
* instead of relying on centralized core logic.
|
|
21
|
+
*/
|
|
22
|
+
export interface AuthSources {
|
|
23
|
+
/** Read an environment variable (sandboxed to `permissions.env.vars`). */
|
|
24
|
+
env: {
|
|
25
|
+
get(name: string): string | undefined;
|
|
26
|
+
};
|
|
27
|
+
/** Read files from the filesystem (sandboxed to `permissions.filesystem.paths`). */
|
|
28
|
+
files: {
|
|
29
|
+
readText(path: string): Promise<string | null>;
|
|
30
|
+
readJson<T = unknown>(path: string): Promise<T | null>;
|
|
31
|
+
exists(path: string): Promise<boolean>;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Read from OpenCode's auth storage.
|
|
35
|
+
* Core handles locating the auth file; plugin provides the provider key.
|
|
36
|
+
*/
|
|
37
|
+
opencode: {
|
|
38
|
+
getProviderEntry(key: string): Promise<OpenCodeAuthEntry | null>;
|
|
39
|
+
};
|
|
40
|
+
/** Platform information for cross-platform credential path resolution. */
|
|
41
|
+
platform: {
|
|
42
|
+
os: 'darwin' | 'linux' | 'win32';
|
|
43
|
+
homedir: string;
|
|
44
|
+
arch: string;
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** Shape of an entry in OpenCode's auth.json file. */
|
|
48
|
+
export interface OpenCodeAuthEntry {
|
|
49
|
+
type: 'api' | 'oauth' | 'codex' | 'github' | 'wellknown';
|
|
50
|
+
key?: string;
|
|
51
|
+
access?: string;
|
|
52
|
+
refresh?: string;
|
|
53
|
+
expires?: number;
|
|
54
|
+
token?: string;
|
|
55
|
+
accessToken?: string;
|
|
56
|
+
refreshToken?: string;
|
|
57
|
+
expiresAt?: number;
|
|
58
|
+
accountId?: string;
|
|
59
|
+
groupId?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Per-plugin key-value storage.
|
|
63
|
+
*
|
|
64
|
+
* Namespaced by plugin ID — plugins can only access their own data.
|
|
65
|
+
* Backed by core's storage engine (SQLite or filesystem).
|
|
66
|
+
*/
|
|
67
|
+
export interface PluginStorage {
|
|
68
|
+
get(key: string): Promise<string | null>;
|
|
69
|
+
set(key: string, value: string): Promise<void>;
|
|
70
|
+
delete(key: string): Promise<void>;
|
|
71
|
+
has(key: string): Promise<boolean>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Full runtime context provided to plugin methods like
|
|
75
|
+
* `auth.discover()`, `fetchUsage()`, `parseSessions()`, etc.
|
|
76
|
+
*
|
|
77
|
+
* Extends lifecycle context with HTTP, auth, and storage capabilities.
|
|
78
|
+
*/
|
|
79
|
+
export interface PluginContext {
|
|
80
|
+
/** Plugin's validated configuration values. */
|
|
81
|
+
readonly config: Record<string, unknown>;
|
|
82
|
+
/** Scoped logger. */
|
|
83
|
+
readonly logger: PluginLogger;
|
|
84
|
+
/** Sandboxed HTTP client. */
|
|
85
|
+
readonly http: PluginHttpClient;
|
|
86
|
+
/** Credential discovery helpers. */
|
|
87
|
+
readonly authSources: AuthSources;
|
|
88
|
+
/** Per-plugin persistent key-value storage. */
|
|
89
|
+
readonly storage: PluginStorage;
|
|
90
|
+
/** Abort signal — fired when the plugin is being stopped or the app is shutting down. */
|
|
91
|
+
readonly signal: AbortSignal;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/types/context.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAMhD;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC3D;AAMD;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,0EAA0E;IAC1E,GAAG,EAAE;QACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;KACvC,CAAC;IAEF,oFAAoF;IACpF,KAAK,EAAE;QACL,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;QAC/C,QAAQ,CAAC,CAAC,GAAG,O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AAC;IACnC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACpC;AAMD;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,+CAA+C;IAC/C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,qBAAqB;IACrB,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,6BAA6B;IAC7B,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,oCAAoC;IACpC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,+CAA+C;IAC/C,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAChC,yFAAyF;IACzF,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;CAC9B"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type { PluginId, PluginType, PluginPermissions, PluginMeta, ConfigField, BasePlugin, PluginLifecycleContext, PluginLogger, } from './plugin.ts';
|
|
2
|
+
export { CURRENT_API_VERSION, PluginPermissionError } from './plugin.ts';
|
|
3
|
+
export type { PluginHttpClient, AuthSources, OpenCodeAuthEntry, PluginStorage, PluginContext, } from './context.ts';
|
|
4
|
+
export type { CredentialSource, Credentials, OAuthCredentials, RefreshedCredentials, CredentialResult, ProviderAuth, ProviderCapabilities, ModelPricing, ProviderPricing, UsageLimit, CostBreakdown, ProviderUsageData, ProviderFetchContext, ProviderPlugin, } from './provider.ts';
|
|
5
|
+
export type { AgentConfig, AgentCapabilities, AgentCredentials, AgentProviderConfig, SessionParseOptions, SessionUsageData, ActivityUpdate, ActivityCallback, AgentFetchContext, AgentPlugin, } from './agent.ts';
|
|
6
|
+
export type { ThemeColors, GaugeColors, ThemeComponents, ThemePlugin, } from './theme.ts';
|
|
7
|
+
export type { NotificationSeverity, NotificationEventType, NotificationEvent, NotificationContext, NotificationPlugin, } from './notification.ts';
|
|
8
|
+
export type AnyPlugin = ProviderPlugin | AgentPlugin | ThemePlugin | NotificationPlugin;
|
|
9
|
+
import type { ProviderPlugin } from './provider.ts';
|
|
10
|
+
import type { AgentPlugin } from './agent.ts';
|
|
11
|
+
import type { ThemePlugin } from './theme.ts';
|
|
12
|
+
import type { NotificationPlugin } from './notification.ts';
|
|
13
|
+
import type { PluginType } from './plugin.ts';
|
|
14
|
+
export type PluginByType = {
|
|
15
|
+
provider: ProviderPlugin;
|
|
16
|
+
agent: AgentPlugin;
|
|
17
|
+
theme: ThemePlugin;
|
|
18
|
+
notification: NotificationPlugin;
|
|
19
|
+
};
|
|
20
|
+
export type PluginOfType<T extends PluginType> = PluginByType[T];
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,QAAQ,EACR,UAAU,EACV,iBAAiB,EACjB,UAAU,EACV,WAAW,EACX,UAAU,EACV,sBAAsB,EACtB,YAAY,GACb,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEzE,YAAY,EACV,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,aAAa,GACd,MAAM,cAAc,CAAC;AAEtB,YAAY,EACV,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EAChB,YAAY,EACZ,oBAAoB,EACpB,YAAY,EACZ,eAAe,EACf,UAAU,EACV,aAAa,EACb,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,GACf,MAAM,eAAe,CAAC;AAEvB,YAAY,EACV,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,WAAW,EACX,WAAW,EACX,eAAe,EACf,WAAW,GACZ,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAE3B,MAAM,MAAM,SAAS,GAAG,cAAc,GAAG,WAAW,GAAG,WAAW,GAAG,kBAAkB,CAAC;AAExF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE,cAAc,CAAC;IACzB,KAAK,EAAE,WAAW,CAAC;IACnB,KAAK,EAAE,WAAW,CAAC;IACnB,YAAY,EAAE,kBAAkB,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,UAAU,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { BasePlugin, PluginLogger } from './plugin.ts';
|
|
2
|
+
export type NotificationSeverity = 'info' | 'warning' | 'critical';
|
|
3
|
+
export type NotificationEventType = 'budget.thresholdCrossed' | 'budget.limitReached' | 'provider.fetchFailed' | 'provider.limitReached' | 'provider.recovered' | 'plugin.crashed' | 'plugin.disabled' | 'app.started' | 'app.updated';
|
|
4
|
+
export interface NotificationEvent {
|
|
5
|
+
type: NotificationEventType;
|
|
6
|
+
severity: NotificationSeverity;
|
|
7
|
+
title: string;
|
|
8
|
+
message: string;
|
|
9
|
+
timestamp: number;
|
|
10
|
+
data?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
export interface NotificationContext {
|
|
13
|
+
readonly logger: PluginLogger;
|
|
14
|
+
readonly config: Record<string, unknown>;
|
|
15
|
+
readonly signal: AbortSignal;
|
|
16
|
+
}
|
|
17
|
+
export interface NotificationPlugin extends BasePlugin {
|
|
18
|
+
readonly type: 'notification';
|
|
19
|
+
/** Set up the notification channel (e.g. verify webhook URL, open connection). */
|
|
20
|
+
initialize(ctx: NotificationContext): Promise<void>;
|
|
21
|
+
/** Deliver a notification event. */
|
|
22
|
+
notify(ctx: NotificationContext, event: NotificationEvent): Promise<void>;
|
|
23
|
+
/** Optional: test the notification channel (e.g. send a test message). */
|
|
24
|
+
test?(ctx: NotificationContext): Promise<boolean>;
|
|
25
|
+
/**
|
|
26
|
+
* Optional: filter which events this plugin handles.
|
|
27
|
+
* If not implemented, the plugin receives all events.
|
|
28
|
+
*/
|
|
29
|
+
supports?(event: NotificationEvent): boolean;
|
|
30
|
+
/** Clean up resources (e.g. close connections). */
|
|
31
|
+
destroy?(): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=notification.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notification.d.ts","sourceRoot":"","sources":["../../src/types/notification.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM5D,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,SAAS,GAAG,UAAU,CAAC;AAEnE,MAAM,MAAM,qBAAqB,GAC7B,yBAAyB,GACzB,qBAAqB,GACrB,sBAAsB,GACtB,uBAAuB,GACvB,oBAAoB,GACpB,gBAAgB,GAChB,iBAAiB,GACjB,aAAa,GACb,aAAa,CAAC;AAElB,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,qBAAqB,CAAC;IAC5B,QAAQ,EAAE,oBAAoB,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAMD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;CAC9B;AAMD,MAAM,WAAW,kBAAmB,SAAQ,UAAU;IACpD,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC;IAE9B,kFAAkF;IAClF,UAAU,CAAC,GAAG,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpD,oCAAoC;IACpC,MAAM,CAAC,GAAG,EAAE,mBAAmB,EAAE,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1E,0EAA0E;IAC1E,IAAI,CAAC,CAAC,GAAG,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAElD;;;OAGG;IACH,QAAQ,CAAC,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC;IAE7C,mDAAmD;IACnD,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core plugin types and interfaces for the tokentop plugin system.
|
|
3
|
+
*
|
|
4
|
+
* All plugin types extend {@link BasePlugin} and must declare their
|
|
5
|
+
* permissions, metadata, and optional lifecycle hooks.
|
|
6
|
+
*/
|
|
7
|
+
/** Opaque plugin identifier — kebab-case string, globally unique. */
|
|
8
|
+
export type PluginId = string;
|
|
9
|
+
/** Discriminator for the four plugin categories. */
|
|
10
|
+
export type PluginType = 'provider' | 'agent' | 'theme' | 'notification';
|
|
11
|
+
/**
|
|
12
|
+
* Current API contract version.
|
|
13
|
+
* Core checks this at load time to ensure compatibility.
|
|
14
|
+
*/
|
|
15
|
+
export declare const CURRENT_API_VERSION = 2;
|
|
16
|
+
/** Controls what a plugin is allowed to access at runtime. */
|
|
17
|
+
export interface PluginPermissions {
|
|
18
|
+
/** Network access — domain allowlisting for outbound HTTP. */
|
|
19
|
+
network?: {
|
|
20
|
+
enabled: boolean;
|
|
21
|
+
allowedDomains?: string[];
|
|
22
|
+
};
|
|
23
|
+
/** Filesystem access — path allowlisting for read/write. */
|
|
24
|
+
filesystem?: {
|
|
25
|
+
read?: boolean;
|
|
26
|
+
write?: boolean;
|
|
27
|
+
paths?: string[];
|
|
28
|
+
};
|
|
29
|
+
/** Environment variable access — var name allowlisting. */
|
|
30
|
+
env?: {
|
|
31
|
+
read?: boolean;
|
|
32
|
+
vars?: string[];
|
|
33
|
+
};
|
|
34
|
+
/** System integration access. */
|
|
35
|
+
system?: {
|
|
36
|
+
notifications?: boolean;
|
|
37
|
+
clipboard?: boolean;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** Public-facing metadata about a plugin. */
|
|
41
|
+
export interface PluginMeta {
|
|
42
|
+
/** Plugin author name or handle. */
|
|
43
|
+
author?: string;
|
|
44
|
+
/** Brief description of what the plugin does. */
|
|
45
|
+
description?: string;
|
|
46
|
+
/** Plugin homepage or documentation URL. */
|
|
47
|
+
homepage?: string;
|
|
48
|
+
/** Source repository URL. */
|
|
49
|
+
repository?: string;
|
|
50
|
+
/** SPDX license identifier. */
|
|
51
|
+
license?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Brand color as a hex string (e.g. `"#d97757"`).
|
|
54
|
+
* Used by the TUI for provider cards, charts, and status indicators.
|
|
55
|
+
*/
|
|
56
|
+
brandColor?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Single-character icon or short glyph for compact displays.
|
|
59
|
+
* Example: `"◆"`, `"▲"`, `"⚡"`
|
|
60
|
+
*/
|
|
61
|
+
icon?: string;
|
|
62
|
+
}
|
|
63
|
+
/** Describes a user-configurable setting that the plugin exposes. */
|
|
64
|
+
export interface ConfigField {
|
|
65
|
+
/** Data type of the setting value. */
|
|
66
|
+
type: 'string' | 'number' | 'boolean' | 'select';
|
|
67
|
+
/** Label shown in the settings UI. */
|
|
68
|
+
label?: string;
|
|
69
|
+
/** Help text shown below the field. */
|
|
70
|
+
description?: string;
|
|
71
|
+
/** Whether the field must have a value. */
|
|
72
|
+
required?: boolean;
|
|
73
|
+
/** Default value when no user config exists. */
|
|
74
|
+
default?: unknown;
|
|
75
|
+
/** Available options (for `select` type only). */
|
|
76
|
+
options?: Array<{
|
|
77
|
+
value: string;
|
|
78
|
+
label: string;
|
|
79
|
+
}>;
|
|
80
|
+
/** Minimum value (for `number` type only). */
|
|
81
|
+
min?: number;
|
|
82
|
+
/** Maximum value (for `number` type only). */
|
|
83
|
+
max?: number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Base interface that all plugins must implement.
|
|
87
|
+
*
|
|
88
|
+
* Provides identity, metadata, permissions, optional configuration schema,
|
|
89
|
+
* and lifecycle hooks.
|
|
90
|
+
*/
|
|
91
|
+
export interface BasePlugin {
|
|
92
|
+
/** API version this plugin targets. Must equal {@link CURRENT_API_VERSION}. */
|
|
93
|
+
readonly apiVersion: 2;
|
|
94
|
+
/** Unique plugin identifier (kebab-case). */
|
|
95
|
+
readonly id: PluginId;
|
|
96
|
+
/** Plugin type discriminator. */
|
|
97
|
+
readonly type: PluginType;
|
|
98
|
+
/** Human-readable display name. */
|
|
99
|
+
readonly name: string;
|
|
100
|
+
/** Semantic version string of this plugin (e.g. `"1.0.0"`). */
|
|
101
|
+
readonly version: string;
|
|
102
|
+
/** Public-facing metadata. */
|
|
103
|
+
readonly meta?: PluginMeta;
|
|
104
|
+
/** Required permissions. */
|
|
105
|
+
readonly permissions: PluginPermissions;
|
|
106
|
+
/**
|
|
107
|
+
* Optional configuration schema.
|
|
108
|
+
* Core renders these fields in the settings UI and persists user values.
|
|
109
|
+
* Keys are the config field identifiers.
|
|
110
|
+
*/
|
|
111
|
+
readonly configSchema?: Record<string, ConfigField>;
|
|
112
|
+
/**
|
|
113
|
+
* Default config values. Used when no user configuration exists.
|
|
114
|
+
* Keys must match those in {@link configSchema}.
|
|
115
|
+
*/
|
|
116
|
+
readonly defaultConfig?: Record<string, unknown>;
|
|
117
|
+
/**
|
|
118
|
+
* Called once after the plugin is loaded and validated.
|
|
119
|
+
* Use for one-time setup (open connections, allocate resources).
|
|
120
|
+
*/
|
|
121
|
+
initialize?(ctx: PluginLifecycleContext): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Called when the plugin should begin active work (e.g. polling).
|
|
124
|
+
* Called after `initialize()` during app startup, and after re-enable.
|
|
125
|
+
*/
|
|
126
|
+
start?(ctx: PluginLifecycleContext): Promise<void>;
|
|
127
|
+
/**
|
|
128
|
+
* Called when the plugin should pause active work.
|
|
129
|
+
* Called before `destroy()` during app shutdown, and on disable.
|
|
130
|
+
*/
|
|
131
|
+
stop?(ctx: PluginLifecycleContext): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Called once before the plugin is unloaded.
|
|
134
|
+
* Use for cleanup (close connections, flush buffers).
|
|
135
|
+
*/
|
|
136
|
+
destroy?(ctx: PluginLifecycleContext): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Called when the user changes this plugin's configuration.
|
|
139
|
+
* Receive the new validated config values.
|
|
140
|
+
*/
|
|
141
|
+
onConfigChange?(config: Record<string, unknown>, ctx: PluginLifecycleContext): Promise<void> | void;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Minimal context provided to lifecycle hooks.
|
|
145
|
+
* More specific contexts (e.g. {@link ProviderFetchContext}) extend this
|
|
146
|
+
* for domain-specific methods.
|
|
147
|
+
*/
|
|
148
|
+
export interface PluginLifecycleContext {
|
|
149
|
+
/** Plugin's validated configuration values. */
|
|
150
|
+
readonly config: Record<string, unknown>;
|
|
151
|
+
/** Scoped logger that prefixes all output with the plugin ID. */
|
|
152
|
+
readonly logger: PluginLogger;
|
|
153
|
+
}
|
|
154
|
+
/** Scoped logging interface provided to plugins. */
|
|
155
|
+
export interface PluginLogger {
|
|
156
|
+
debug(message: string, data?: Record<string, unknown>): void;
|
|
157
|
+
info(message: string, data?: Record<string, unknown>): void;
|
|
158
|
+
warn(message: string, data?: Record<string, unknown>): void;
|
|
159
|
+
error(message: string, data?: Record<string, unknown>): void;
|
|
160
|
+
}
|
|
161
|
+
/** Thrown when a plugin attempts an action not allowed by its permissions. */
|
|
162
|
+
export declare class PluginPermissionError extends Error {
|
|
163
|
+
readonly pluginId: PluginId;
|
|
164
|
+
readonly permission: keyof PluginPermissions;
|
|
165
|
+
constructor(pluginId: PluginId, permission: keyof PluginPermissions, message: string);
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/types/plugin.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,qEAAqE;AACrE,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAE9B,oDAAoD;AACpD,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,cAAc,CAAC;AAEzE;;;GAGG;AACH,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAMrC,8DAA8D;AAC9D,MAAM,WAAW,iBAAiB;IAChC,8DAA8D;IAC9D,OAAO,CAAC,EAAE;QACR,OAAO,EAAE,OAAO,CAAC;QACjB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;KAC3B,CAAC;IACF,4DAA4D;IAC5D,UAAU,CAAC,EAAE;QACX,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;KAClB,CAAC;IACF,2DAA2D;IAC3D,GAAG,CAAC,E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AAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,iEAAiE;IACjE,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;CAC/B;AAMD,oDAAoD;AACpD,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC7D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC5D,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC5D,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAC9D;AAMD,8EAA8E;AAC9E,qBAAa,qBAAsB,SAAQ,KAAK;aAE5B,QAAQ,EAAE,QAAQ;aAClB,UAAU,EAAE,MAAM,iBAAiB;gBADnC,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,MAAM,iBAAiB,EACnD,OAAO,EAAE,MAAM;CAKlB"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { BasePlugin, PluginLogger } from './plugin.ts';
|
|
2
|
+
import type { PluginHttpClient, PluginContext } from './context.ts';
|
|
3
|
+
export type CredentialSource = 'env' | 'opencode' | 'external' | 'config';
|
|
4
|
+
export interface Credentials {
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
oauth?: OAuthCredentials;
|
|
7
|
+
groupId?: string;
|
|
8
|
+
source: CredentialSource;
|
|
9
|
+
}
|
|
10
|
+
export interface OAuthCredentials {
|
|
11
|
+
accessToken: string;
|
|
12
|
+
refreshToken?: string;
|
|
13
|
+
expiresAt?: number;
|
|
14
|
+
accountId?: string;
|
|
15
|
+
managedProjectId?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface RefreshedCredentials {
|
|
18
|
+
accessToken: string;
|
|
19
|
+
refreshToken: string;
|
|
20
|
+
expiresAt: number;
|
|
21
|
+
}
|
|
22
|
+
export interface CredentialResult {
|
|
23
|
+
ok: boolean;
|
|
24
|
+
credentials?: Credentials;
|
|
25
|
+
reason?: 'missing' | 'expired' | 'invalid' | 'error';
|
|
26
|
+
message?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Plugin-owned credential discovery and validation.
|
|
30
|
+
*
|
|
31
|
+
* Replaces the old declarative `auth: { envVars, externalPaths }` pattern.
|
|
32
|
+
* The plugin decides *how* to find credentials; core provides sandboxed helpers.
|
|
33
|
+
*/
|
|
34
|
+
export interface ProviderAuth {
|
|
35
|
+
/** Discover credentials using the provided context helpers. */
|
|
36
|
+
discover(ctx: PluginContext): Promise<CredentialResult>;
|
|
37
|
+
/** Check whether discovered credentials are sufficient to operate. */
|
|
38
|
+
isConfigured(credentials: Credentials): boolean;
|
|
39
|
+
}
|
|
40
|
+
export interface ProviderCapabilities {
|
|
41
|
+
usageLimits: boolean;
|
|
42
|
+
apiRateLimits: boolean;
|
|
43
|
+
tokenUsage: boolean;
|
|
44
|
+
actualCosts: boolean;
|
|
45
|
+
}
|
|
46
|
+
export interface ModelPricing {
|
|
47
|
+
input: number;
|
|
48
|
+
output: number;
|
|
49
|
+
cacheRead?: number;
|
|
50
|
+
cacheWrite?: number;
|
|
51
|
+
source?: string;
|
|
52
|
+
}
|
|
53
|
+
export interface ProviderPricing {
|
|
54
|
+
/**
|
|
55
|
+
* Map a model ID to the identifier used by the pricing service.
|
|
56
|
+
* Return `undefined` to use the model ID as-is.
|
|
57
|
+
*/
|
|
58
|
+
mapModelId?(modelId: string): string | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* The provider ID to use when querying models.dev.
|
|
61
|
+
* Defaults to `plugin.id` if not specified.
|
|
62
|
+
*/
|
|
63
|
+
modelsDevProviderId?: string;
|
|
64
|
+
/** Static fallback prices keyed by model ID. */
|
|
65
|
+
staticPrices?: Record<string, ModelPricing>;
|
|
66
|
+
}
|
|
67
|
+
export interface UsageLimit {
|
|
68
|
+
usedPercent: number | null;
|
|
69
|
+
resetsAt?: number;
|
|
70
|
+
label?: string;
|
|
71
|
+
windowMinutes?: number;
|
|
72
|
+
}
|
|
73
|
+
export interface CostBreakdown {
|
|
74
|
+
total: number;
|
|
75
|
+
input?: number;
|
|
76
|
+
output?: number;
|
|
77
|
+
cacheRead?: number;
|
|
78
|
+
cacheWrite?: number;
|
|
79
|
+
currency: string;
|
|
80
|
+
}
|
|
81
|
+
export interface ProviderUsageData {
|
|
82
|
+
planType?: string;
|
|
83
|
+
allowed?: boolean;
|
|
84
|
+
limitReached?: boolean;
|
|
85
|
+
limits?: {
|
|
86
|
+
primary?: UsageLimit;
|
|
87
|
+
secondary?: UsageLimit;
|
|
88
|
+
items?: UsageLimit[];
|
|
89
|
+
};
|
|
90
|
+
tokens?: {
|
|
91
|
+
input: number;
|
|
92
|
+
output: number;
|
|
93
|
+
cacheRead?: number;
|
|
94
|
+
cacheWrite?: number;
|
|
95
|
+
};
|
|
96
|
+
credits?: {
|
|
97
|
+
hasCredits: boolean;
|
|
98
|
+
unlimited: boolean;
|
|
99
|
+
balance?: string;
|
|
100
|
+
};
|
|
101
|
+
cost?: {
|
|
102
|
+
actual?: CostBreakdown;
|
|
103
|
+
estimated?: CostBreakdown;
|
|
104
|
+
source: 'api' | 'estimated';
|
|
105
|
+
};
|
|
106
|
+
fetchedAt: number;
|
|
107
|
+
error?: string;
|
|
108
|
+
}
|
|
109
|
+
/** Context injected into `fetchUsage()`. Includes resolved credentials. */
|
|
110
|
+
export interface ProviderFetchContext {
|
|
111
|
+
readonly credentials: Credentials;
|
|
112
|
+
readonly http: PluginHttpClient;
|
|
113
|
+
readonly logger: PluginLogger;
|
|
114
|
+
readonly config: Record<string, unknown>;
|
|
115
|
+
readonly signal: AbortSignal;
|
|
116
|
+
readonly options?: {
|
|
117
|
+
timePeriod?: 'session' | 'daily' | 'weekly' | 'monthly';
|
|
118
|
+
sessionId?: string;
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
export interface ProviderPlugin extends BasePlugin {
|
|
122
|
+
readonly type: 'provider';
|
|
123
|
+
readonly capabilities: ProviderCapabilities;
|
|
124
|
+
/** Plugin-owned credential discovery. */
|
|
125
|
+
readonly auth: ProviderAuth;
|
|
126
|
+
/** Optional pricing configuration for the models this provider serves. */
|
|
127
|
+
readonly pricing?: ProviderPricing;
|
|
128
|
+
/** Fetch current usage data from the provider's API. */
|
|
129
|
+
fetchUsage(ctx: ProviderFetchContext): Promise<ProviderUsageData>;
|
|
130
|
+
/** Optional OAuth token refresh. */
|
|
131
|
+
refreshToken?(oauth: OAuthCredentials): Promise<RefreshedCredentials>;
|
|
132
|
+
/** Optional health check (e.g. verify API key validity without fetching usage). */
|
|
133
|
+
healthCheck?(ctx: PluginContext): Promise<{
|
|
134
|
+
ok: boolean;
|
|
135
|
+
message?: string;
|
|
136
|
+
}>;
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/types/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAMpE,MAAM,MAAM,gBAAgB,GAAG,KAAK,GAAG,UAAU,GAAG,UAAU,GAAG,QAAQ,CAAC;AAE1E,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,gBAAgB,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,gBA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ugin } from './plugin.ts';
|
|
2
|
+
export interface ThemeColors {
|
|
3
|
+
bg: string;
|
|
4
|
+
fg: string;
|
|
5
|
+
border: string;
|
|
6
|
+
borderFocused: string;
|
|
7
|
+
primary: string;
|
|
8
|
+
secondary: string;
|
|
9
|
+
accent: string;
|
|
10
|
+
muted: string;
|
|
11
|
+
success: string;
|
|
12
|
+
warning: string;
|
|
13
|
+
error: string;
|
|
14
|
+
info: string;
|
|
15
|
+
headerBg: string;
|
|
16
|
+
headerFg: string;
|
|
17
|
+
statusBarBg: string;
|
|
18
|
+
statusBarFg: string;
|
|
19
|
+
tableBg: string;
|
|
20
|
+
tableHeaderBg: string;
|
|
21
|
+
tableHeaderFg: string;
|
|
22
|
+
tableRowBg: string;
|
|
23
|
+
tableRowAltBg: string;
|
|
24
|
+
tableRowFg: string;
|
|
25
|
+
tableSelectedBg: string;
|
|
26
|
+
tableSelectedFg: string;
|
|
27
|
+
}
|
|
28
|
+
export interface GaugeColors {
|
|
29
|
+
low: string;
|
|
30
|
+
medium: string;
|
|
31
|
+
high: string;
|
|
32
|
+
critical: string;
|
|
33
|
+
bg: string;
|
|
34
|
+
}
|
|
35
|
+
export interface ThemeComponents {
|
|
36
|
+
gauge?: GaugeColors;
|
|
37
|
+
}
|
|
38
|
+
export interface ThemePlugin extends BasePlugin {
|
|
39
|
+
readonly type: 'theme';
|
|
40
|
+
readonly theme: {
|
|
41
|
+
colorScheme: 'light' | 'dark';
|
|
42
|
+
colors: ThemeColors;
|
|
43
|
+
components?: ThemeComponents;
|
|
44
|
+
/**
|
|
45
|
+
* If `true`, core uses this theme when no user preference is set.
|
|
46
|
+
* If multiple themes set this, `priority` breaks the tie (higher wins).
|
|
47
|
+
*/
|
|
48
|
+
isDefault?: boolean;
|
|
49
|
+
/** Tie-breaker for default theme selection. Higher wins. Default: `0`. */
|
|
50
|
+
priority?: number;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=theme.d.ts.map
|
|
@@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