@t3mode/plugin-sdk 1.3.0 → 1.5.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/dist/index.d.ts +102 -12
- package/dist/index.js +3 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -42,13 +42,6 @@ export interface PluginUi {
|
|
|
42
42
|
readonly row: (options: RowOptions) => HTMLElement;
|
|
43
43
|
readonly button: (options: ButtonOptions) => HTMLButtonElement;
|
|
44
44
|
}
|
|
45
|
-
export interface LocalSocket {
|
|
46
|
-
readonly name: string;
|
|
47
|
-
write(data: Uint8Array): void;
|
|
48
|
-
close(): void;
|
|
49
|
-
onData(callback: (data: Uint8Array) => void): void;
|
|
50
|
-
onClose(callback: (error?: string) => void): void;
|
|
51
|
-
}
|
|
52
45
|
/** A local fixed drive. */
|
|
53
46
|
export interface Disk {
|
|
54
47
|
/** The drive's root, such as `C:\`. */
|
|
@@ -58,13 +51,36 @@ export interface Disk {
|
|
|
58
51
|
/** Bytes available to the user. */
|
|
59
52
|
readonly free: number;
|
|
60
53
|
}
|
|
54
|
+
/** A plugin's backend as its page code sees it. Null: no backend runs for it. */
|
|
55
|
+
export type BackendStatus = {
|
|
56
|
+
readonly state: "starting";
|
|
57
|
+
} | {
|
|
58
|
+
readonly state: "running";
|
|
59
|
+
} | {
|
|
60
|
+
readonly state: "restarting";
|
|
61
|
+
readonly crashes: number;
|
|
62
|
+
readonly error: string;
|
|
63
|
+
readonly retryAt: number;
|
|
64
|
+
} | {
|
|
65
|
+
readonly state: "failed";
|
|
66
|
+
readonly crashes: number;
|
|
67
|
+
readonly error: string;
|
|
68
|
+
};
|
|
69
|
+
/** The page side of a plugin's backend: messages to and from its own process. */
|
|
70
|
+
export interface PluginBackend {
|
|
71
|
+
/**
|
|
72
|
+
* Sends `data` (anything structured clone can copy) to the backend. Resolves false when no
|
|
73
|
+
* backend runs for the plugin, and the message is dropped.
|
|
74
|
+
*/
|
|
75
|
+
readonly send: (data: unknown) => Promise<boolean>;
|
|
76
|
+
/** Called for every message the backend sends. */
|
|
77
|
+
readonly onMessage: (callback: (data: unknown) => void) => void;
|
|
78
|
+
/** Called now with the current status, then on every change. */
|
|
79
|
+
readonly onStatus: (callback: (status: BackendStatus | null) => void) => void;
|
|
80
|
+
}
|
|
61
81
|
export interface PluginApi<O extends OptionsSpec = OptionsSpec> {
|
|
62
82
|
/** The id from the plugin's manifest.json. */
|
|
63
83
|
readonly id: string;
|
|
64
|
-
/** Connects to a local socket whose name must be declared in the manifest. */
|
|
65
|
-
readonly sockets: {
|
|
66
|
-
readonly connect: (name: string) => Promise<LocalSocket>;
|
|
67
|
-
};
|
|
68
84
|
readonly options: OptionValues<O>;
|
|
69
85
|
/** Adds a stylesheet, removed when the plugin stops. */
|
|
70
86
|
readonly css: (text: string) => void;
|
|
@@ -113,6 +129,11 @@ export interface PluginApi<O extends OptionsSpec = OptionsSpec> {
|
|
|
113
129
|
* drives are left out. Added in SDK 1.3.0, so check for it before calling.
|
|
114
130
|
*/
|
|
115
131
|
readonly disks?: () => Promise<ReadonlyArray<Disk>>;
|
|
132
|
+
/**
|
|
133
|
+
* The plugin's backend, the program its manifest's `backend` names. Added in SDK 1.4.0, so
|
|
134
|
+
* check for it before calling.
|
|
135
|
+
*/
|
|
136
|
+
readonly backend?: PluginBackend;
|
|
116
137
|
}
|
|
117
138
|
export interface PluginDefinition<O extends OptionsSpec = OptionsSpec> {
|
|
118
139
|
readonly options: O;
|
|
@@ -120,4 +141,73 @@ export interface PluginDefinition<O extends OptionsSpec = OptionsSpec> {
|
|
|
120
141
|
start(api: PluginApi<O>): void;
|
|
121
142
|
}
|
|
122
143
|
/** Returns the definition unchanged, typing `api.options` from `options`. */
|
|
123
|
-
export declare const definePlugin: <const O extends OptionsSpec>(definition: PluginDefinition<O>) => PluginDefinition<O>;
|
|
144
|
+
export declare const definePlugin: <const O extends OptionsSpec>(definition: PluginDefinition<O>) => PluginDefinition<O>;
|
|
145
|
+
/** What the desktop indicator shows. t3mode draws it from its own template: no plugin code runs in it. */
|
|
146
|
+
export interface IndicatorModel {
|
|
147
|
+
/** Such as "Claude · Book a flight". Capped at 160 characters, ellipsised. */
|
|
148
|
+
readonly label: string;
|
|
149
|
+
/** Such as "wait 500 ms". Capped at 160 characters. */
|
|
150
|
+
readonly detail: string | null;
|
|
151
|
+
}
|
|
152
|
+
/** A rectangle in physical desktop pixels, the space input coordinates use. */
|
|
153
|
+
export interface ScreenRect {
|
|
154
|
+
readonly x: number;
|
|
155
|
+
readonly y: number;
|
|
156
|
+
readonly width: number;
|
|
157
|
+
readonly height: number;
|
|
158
|
+
}
|
|
159
|
+
/** One shown indicator. t3mode keeps proving it is painted; the plugin only reads the result. */
|
|
160
|
+
export interface DrivingIndicator {
|
|
161
|
+
/**
|
|
162
|
+
* Aborts once. `reason.message` is "stop" when the user pressed its Stop button, and
|
|
163
|
+
* "unavailable" when it was lost or its proof expired. Never aborts on close().
|
|
164
|
+
*/
|
|
165
|
+
readonly signal: AbortSignal;
|
|
166
|
+
/** True while not closed, not aborted, and painted in the last 3 seconds. */
|
|
167
|
+
readonly live: () => boolean;
|
|
168
|
+
/** The whole window, from the first proof. Fixed for the handle's life: a move revokes it. */
|
|
169
|
+
readonly rect: ScreenRect;
|
|
170
|
+
/** Changes the detail line. Does not renew presence. */
|
|
171
|
+
readonly setDetail: (detail: string | null) => void;
|
|
172
|
+
/**
|
|
173
|
+
* Idempotent. live() is false at once, then t3mode destroys the window. A pill stopped by the
|
|
174
|
+
* user shows "Stopping…" until this is called.
|
|
175
|
+
*/
|
|
176
|
+
readonly close: () => void;
|
|
177
|
+
}
|
|
178
|
+
/** A pill with a Stop button above every app, for a backend that drives the desktop. */
|
|
179
|
+
export interface BackendIndicator {
|
|
180
|
+
/**
|
|
181
|
+
* Shows the pill. Resolves on its first paint proof. Rejects after 3000 ms without one, when
|
|
182
|
+
* the user stops it first, when no T3 Code window is open, or while a shown handle is not
|
|
183
|
+
* closed yet. A handle lost as "unavailable" closes itself.
|
|
184
|
+
*/
|
|
185
|
+
readonly show: (model: IndicatorModel) => Promise<DrivingIndicator>;
|
|
186
|
+
}
|
|
187
|
+
/** What a backend's `start` gets. Added in SDK 1.4.0. */
|
|
188
|
+
export interface BackendApi {
|
|
189
|
+
/** The id from the plugin's manifest.json. */
|
|
190
|
+
readonly id: string;
|
|
191
|
+
/**
|
|
192
|
+
* The backend's own folder, `<home>/plugin-data/<id>/`. It exists when `start` runs, and is
|
|
193
|
+
* deleted when the plugin is removed.
|
|
194
|
+
*/
|
|
195
|
+
readonly dataDir: string;
|
|
196
|
+
/** Sends `data` (anything structured clone can copy) to the plugin's page code. */
|
|
197
|
+
readonly send: (data: unknown) => void;
|
|
198
|
+
/** Called for every message the page code sends. Messages that came before are delivered too. */
|
|
199
|
+
readonly onMessage: (callback: (data: unknown) => void) => void;
|
|
200
|
+
/** A line in `<home>/logs/plugins/<id>.log`, where the backend's stdout and stderr go too. */
|
|
201
|
+
readonly log: (level: LogLevel, message: string) => void;
|
|
202
|
+
/** The desktop indicator. Added in SDK 1.5.0, so check for it before calling. */
|
|
203
|
+
readonly indicator?: BackendIndicator;
|
|
204
|
+
}
|
|
205
|
+
export interface BackendDefinition {
|
|
206
|
+
/**
|
|
207
|
+
* Called once when the process starts. The backend runs until the plugin is turned off,
|
|
208
|
+
* updated or removed, or T3 Code quits; a throw, a rejected promise or an exit is a crash.
|
|
209
|
+
*/
|
|
210
|
+
start(api: BackendApi): void | Promise<void>;
|
|
211
|
+
}
|
|
212
|
+
/** Returns the definition unchanged: the default export of the plugin's backend script. */
|
|
213
|
+
export declare const defineBackend: (definition: BackendDefinition) => BackendDefinition;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
/** Returns the definition unchanged, typing `api.options` from `options`. */
|
|
3
3
|
const definePlugin = (definition) => definition;
|
|
4
|
-
export
|
|
4
|
+
/** Returns the definition unchanged: the default export of the plugin's backend script. */
|
|
5
|
+
const defineBackend = (definition) => definition;
|
|
6
|
+
export { defineBackend, definePlugin };
|