@matrix-ai/plugin 1.6.0 → 1.6.1

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 CHANGED
@@ -1,4 +1,5 @@
1
- import type { Event, createOpencodeClient, Project, Model, Provider, Permission, UserMessage, Message, Part, Auth, Config } from "@matrix-ai/sdk";
1
+ import type { Event, createOpencodeClient, Project, Model, Provider, Permission, UserMessage, Message, Part, Auth, Config as SDKConfig } from "@matrix-ai/sdk";
2
+ import type { Provider as ProviderV2, Model as ModelV2 } from "@matrix-ai/sdk/v2";
2
3
  import type { BunShell } from "./shell.js";
3
4
  import { type ToolDefinition } from "./tool.js";
4
5
  export * from "./tool.js";
@@ -15,7 +16,16 @@ export type PluginInput = {
15
16
  serverUrl: URL;
16
17
  $: BunShell;
17
18
  };
18
- export type Plugin = (input: PluginInput) => Promise<Hooks>;
19
+ export type PluginOptions = Record<string, unknown>;
20
+ export type Config = Omit<SDKConfig, "plugin"> & {
21
+ plugin?: Array<string | [string, PluginOptions]>;
22
+ };
23
+ export type Plugin = (input: PluginInput, options?: PluginOptions) => Promise<Hooks>;
24
+ export type PluginModule = {
25
+ id?: string;
26
+ server: Plugin;
27
+ tui?: never;
28
+ };
19
29
  type Rule = {
20
30
  key: string;
21
31
  op: "eq" | "neq";
@@ -49,7 +59,7 @@ export type AuthHook = {
49
59
  condition?: (inputs: Record<string, string>) => boolean;
50
60
  when?: Rule;
51
61
  }>;
52
- authorize(inputs?: Record<string, string>): Promise<AuthOuathResult>;
62
+ authorize(inputs?: Record<string, string>): Promise<AuthOAuthResult>;
53
63
  } | {
54
64
  type: "api";
55
65
  label: string;
@@ -84,7 +94,7 @@ export type AuthHook = {
84
94
  }>;
85
95
  })[];
86
96
  };
87
- export type AuthOuathResult = {
97
+ export type AuthOAuthResult = {
88
98
  url: string;
89
99
  instructions: string;
90
100
  } & ({
@@ -97,6 +107,7 @@ export type AuthOuathResult = {
97
107
  access: string;
98
108
  expires: number;
99
109
  accountId?: string;
110
+ enterpriseUrl?: string;
100
111
  } | {
101
112
  key: string;
102
113
  })) | {
@@ -112,12 +123,22 @@ export type AuthOuathResult = {
112
123
  access: string;
113
124
  expires: number;
114
125
  accountId?: string;
126
+ enterpriseUrl?: string;
115
127
  } | {
116
128
  key: string;
117
129
  })) | {
118
130
  type: "failed";
119
131
  }>;
120
132
  });
133
+ export type ProviderHookContext = {
134
+ auth?: Auth;
135
+ };
136
+ export type ProviderHook = {
137
+ id: string;
138
+ models?: (provider: ProviderV2, ctx: ProviderHookContext) => Promise<Record<string, ModelV2>>;
139
+ };
140
+ /** @deprecated Use AuthOAuthResult instead. */
141
+ export type AuthOuathResult = AuthOAuthResult;
121
142
  export interface Hooks {
122
143
  event?: (input: {
123
144
  event: Event;
@@ -127,6 +148,7 @@ export interface Hooks {
127
148
  [key: string]: ToolDefinition;
128
149
  };
129
150
  auth?: AuthHook;
151
+ provider?: ProviderHook;
130
152
  /**
131
153
  * Called when a new message is received
132
154
  */
@@ -188,17 +210,10 @@ export interface Hooks {
188
210
  cwd: string;
189
211
  sessionID?: string;
190
212
  callID?: string;
213
+ command?: string;
191
214
  }, output: {
192
215
  env: Record<string, string>;
193
216
  }) => Promise<void>;
194
- "shell.pre-exec"?: (input: {
195
- command: string;
196
- cwd: string;
197
- env: Record<string, string>;
198
- }, output: {
199
- env: Record<string, string>;
200
- command?: string;
201
- }) => Promise<void>;
202
217
  "tool.execute.after"?: (input: {
203
218
  tool: string;
204
219
  sessionID: string;
package/dist/tui.d.ts ADDED
@@ -0,0 +1,429 @@
1
+ import type { AgentPart, OpencodeClient, Event, FilePart, LspStatus, McpStatus, Todo, Message, Part, Provider, PermissionRequest, QuestionRequest, SessionStatus, TextPart, Workspace, Config as SdkConfig } from "@matrix-ai/sdk/v2";
2
+ import type { CliRenderer, ParsedKey, RGBA, SlotMode } from "@opentui/core";
3
+ import type { JSX, SolidPlugin } from "@opentui/solid";
4
+ import type { Config as PluginConfig, PluginOptions } from "./index.js";
5
+ export type { CliRenderer, SlotMode } from "@opentui/core";
6
+ export type TuiRouteCurrent = {
7
+ name: "home";
8
+ } | {
9
+ name: "session";
10
+ params: {
11
+ sessionID: string;
12
+ initialPrompt?: unknown;
13
+ };
14
+ } | {
15
+ name: string;
16
+ params?: Record<string, unknown>;
17
+ };
18
+ export type TuiRouteDefinition = {
19
+ name: string;
20
+ render: (input: {
21
+ params?: Record<string, unknown>;
22
+ }) => JSX.Element;
23
+ };
24
+ export type TuiCommand = {
25
+ title: string;
26
+ value: string;
27
+ description?: string;
28
+ category?: string;
29
+ keybind?: string;
30
+ suggested?: boolean;
31
+ hidden?: boolean;
32
+ enabled?: boolean;
33
+ slash?: {
34
+ name: string;
35
+ aliases?: string[];
36
+ };
37
+ onSelect?: () => void;
38
+ };
39
+ export type TuiKeybind = {
40
+ name: string;
41
+ ctrl: boolean;
42
+ meta: boolean;
43
+ shift: boolean;
44
+ super?: boolean;
45
+ leader: boolean;
46
+ };
47
+ export type TuiKeybindMap = Record<string, string>;
48
+ export type TuiKeybindSet = {
49
+ readonly all: TuiKeybindMap;
50
+ get: (name: string) => string;
51
+ match: (name: string, evt: ParsedKey) => boolean;
52
+ print: (name: string) => string;
53
+ };
54
+ export type TuiDialogProps = {
55
+ size?: "medium" | "large" | "xlarge";
56
+ onClose: () => void;
57
+ children?: JSX.Element;
58
+ };
59
+ export type TuiDialogStack = {
60
+ replace: (render: () => JSX.Element, onClose?: () => void) => void;
61
+ clear: () => void;
62
+ setSize: (size: "medium" | "large" | "xlarge") => void;
63
+ readonly size: "medium" | "large" | "xlarge";
64
+ readonly depth: number;
65
+ readonly open: boolean;
66
+ };
67
+ export type TuiDialogAlertProps = {
68
+ title: string;
69
+ message: string;
70
+ onConfirm?: () => void;
71
+ };
72
+ export type TuiDialogConfirmProps = {
73
+ title: string;
74
+ message: string;
75
+ onConfirm?: () => void;
76
+ onCancel?: () => void;
77
+ };
78
+ export type TuiDialogPromptProps = {
79
+ title: string;
80
+ description?: () => JSX.Element;
81
+ placeholder?: string;
82
+ value?: string;
83
+ busy?: boolean;
84
+ busyText?: string;
85
+ onConfirm?: (value: string) => void;
86
+ onCancel?: () => void;
87
+ };
88
+ export type TuiDialogSelectOption<Value = unknown> = {
89
+ title: string;
90
+ value: Value;
91
+ description?: string;
92
+ footer?: JSX.Element | string;
93
+ category?: string;
94
+ disabled?: boolean;
95
+ onSelect?: () => void;
96
+ };
97
+ export type TuiDialogSelectProps<Value = unknown> = {
98
+ title: string;
99
+ placeholder?: string;
100
+ options: TuiDialogSelectOption<Value>[];
101
+ flat?: boolean;
102
+ onMove?: (option: TuiDialogSelectOption<Value>) => void;
103
+ onFilter?: (query: string) => void;
104
+ onSelect?: (option: TuiDialogSelectOption<Value>) => void;
105
+ skipFilter?: boolean;
106
+ current?: Value;
107
+ };
108
+ export type TuiPromptInfo = {
109
+ input: string;
110
+ mode?: "normal" | "shell";
111
+ parts: (Omit<FilePart, "id" | "messageID" | "sessionID"> | Omit<AgentPart, "id" | "messageID" | "sessionID"> | (Omit<TextPart, "id" | "messageID" | "sessionID"> & {
112
+ source?: {
113
+ text: {
114
+ start: number;
115
+ end: number;
116
+ value: string;
117
+ };
118
+ };
119
+ }))[];
120
+ };
121
+ export type TuiPromptRef = {
122
+ focused: boolean;
123
+ current: TuiPromptInfo;
124
+ set(prompt: TuiPromptInfo): void;
125
+ reset(): void;
126
+ blur(): void;
127
+ focus(): void;
128
+ submit(): void;
129
+ };
130
+ export type TuiPromptProps = {
131
+ sessionID?: string;
132
+ workspaceID?: string;
133
+ visible?: boolean;
134
+ disabled?: boolean;
135
+ onSubmit?: () => void;
136
+ ref?: (ref: TuiPromptRef | undefined) => void;
137
+ hint?: JSX.Element;
138
+ right?: JSX.Element;
139
+ showPlaceholder?: boolean;
140
+ placeholders?: {
141
+ normal?: string[];
142
+ shell?: string[];
143
+ };
144
+ };
145
+ export type TuiToast = {
146
+ variant?: "info" | "success" | "warning" | "error";
147
+ title?: string;
148
+ message: string;
149
+ duration?: number;
150
+ };
151
+ export type TuiThemeCurrent = {
152
+ readonly primary: RGBA;
153
+ readonly secondary: RGBA;
154
+ readonly accent: RGBA;
155
+ readonly error: RGBA;
156
+ readonly warning: RGBA;
157
+ readonly success: RGBA;
158
+ readonly info: RGBA;
159
+ readonly text: RGBA;
160
+ readonly textMuted: RGBA;
161
+ readonly selectedListItemText: RGBA;
162
+ readonly background: RGBA;
163
+ readonly backgroundPanel: RGBA;
164
+ readonly backgroundElement: RGBA;
165
+ readonly backgroundMenu: RGBA;
166
+ readonly border: RGBA;
167
+ readonly borderActive: RGBA;
168
+ readonly borderSubtle: RGBA;
169
+ readonly diffAdded: RGBA;
170
+ readonly diffRemoved: RGBA;
171
+ readonly diffContext: RGBA;
172
+ readonly diffHunkHeader: RGBA;
173
+ readonly diffHighlightAdded: RGBA;
174
+ readonly diffHighlightRemoved: RGBA;
175
+ readonly diffAddedBg: RGBA;
176
+ readonly diffRemovedBg: RGBA;
177
+ readonly diffContextBg: RGBA;
178
+ readonly diffLineNumber: RGBA;
179
+ readonly diffAddedLineNumberBg: RGBA;
180
+ readonly diffRemovedLineNumberBg: RGBA;
181
+ readonly markdownText: RGBA;
182
+ readonly markdownHeading: RGBA;
183
+ readonly markdownLink: RGBA;
184
+ readonly markdownLinkText: RGBA;
185
+ readonly markdownCode: RGBA;
186
+ readonly markdownBlockQuote: RGBA;
187
+ readonly markdownEmph: RGBA;
188
+ readonly markdownStrong: RGBA;
189
+ readonly markdownHorizontalRule: RGBA;
190
+ readonly markdownListItem: RGBA;
191
+ readonly markdownListEnumeration: RGBA;
192
+ readonly markdownImage: RGBA;
193
+ readonly markdownImageText: RGBA;
194
+ readonly markdownCodeBlock: RGBA;
195
+ readonly syntaxComment: RGBA;
196
+ readonly syntaxKeyword: RGBA;
197
+ readonly syntaxFunction: RGBA;
198
+ readonly syntaxVariable: RGBA;
199
+ readonly syntaxString: RGBA;
200
+ readonly syntaxNumber: RGBA;
201
+ readonly syntaxType: RGBA;
202
+ readonly syntaxOperator: RGBA;
203
+ readonly syntaxPunctuation: RGBA;
204
+ readonly thinkingOpacity: number;
205
+ };
206
+ export type TuiTheme = {
207
+ readonly current: TuiThemeCurrent;
208
+ readonly selected: string;
209
+ has: (name: string) => boolean;
210
+ set: (name: string) => boolean;
211
+ install: (jsonPath: string) => Promise<void>;
212
+ mode: () => "dark" | "light";
213
+ readonly ready: boolean;
214
+ };
215
+ export type TuiKV = {
216
+ get: <Value = unknown>(key: string, fallback?: Value) => Value;
217
+ set: (key: string, value: unknown) => void;
218
+ readonly ready: boolean;
219
+ };
220
+ export type TuiState = {
221
+ readonly ready: boolean;
222
+ readonly config: SdkConfig;
223
+ readonly provider: ReadonlyArray<Provider>;
224
+ readonly path: {
225
+ state: string;
226
+ config: string;
227
+ worktree: string;
228
+ directory: string;
229
+ };
230
+ readonly vcs: {
231
+ branch?: string;
232
+ } | undefined;
233
+ readonly workspace: {
234
+ list: () => ReadonlyArray<Workspace>;
235
+ get: (workspaceID: string) => Workspace | undefined;
236
+ };
237
+ session: {
238
+ count: () => number;
239
+ diff: (sessionID: string) => ReadonlyArray<TuiSidebarFileItem>;
240
+ todo: (sessionID: string) => ReadonlyArray<TuiSidebarTodoItem>;
241
+ messages: (sessionID: string) => ReadonlyArray<Message>;
242
+ status: (sessionID: string) => SessionStatus | undefined;
243
+ permission: (sessionID: string) => ReadonlyArray<PermissionRequest>;
244
+ question: (sessionID: string) => ReadonlyArray<QuestionRequest>;
245
+ };
246
+ part: (messageID: string) => ReadonlyArray<Part>;
247
+ lsp: () => ReadonlyArray<TuiSidebarLspItem>;
248
+ mcp: () => ReadonlyArray<TuiSidebarMcpItem>;
249
+ };
250
+ type TuiConfigView = Pick<PluginConfig, "$schema" | "theme" | "keybinds" | "plugin"> & NonNullable<PluginConfig["tui"]> & {
251
+ plugin_enabled?: Record<string, boolean>;
252
+ };
253
+ export type TuiApp = {
254
+ readonly version: string;
255
+ };
256
+ type Frozen<Value> = Value extends (...args: never[]) => unknown ? Value : Value extends ReadonlyArray<infer Item> ? ReadonlyArray<Frozen<Item>> : Value extends object ? {
257
+ readonly [Key in keyof Value]: Frozen<Value[Key]>;
258
+ } : Value;
259
+ export type TuiSidebarMcpItem = {
260
+ name: string;
261
+ status: McpStatus["status"];
262
+ error?: string;
263
+ };
264
+ export type TuiSidebarLspItem = Pick<LspStatus, "id" | "root" | "status">;
265
+ export type TuiSidebarTodoItem = Pick<Todo, "content" | "status">;
266
+ export type TuiSidebarFileItem = {
267
+ file: string;
268
+ additions: number;
269
+ deletions: number;
270
+ };
271
+ export type TuiHostSlotMap = {
272
+ app: {};
273
+ home_logo: {};
274
+ home_prompt: {
275
+ workspace_id?: string;
276
+ ref?: (ref: TuiPromptRef | undefined) => void;
277
+ };
278
+ home_prompt_right: {
279
+ workspace_id?: string;
280
+ };
281
+ session_prompt: {
282
+ session_id: string;
283
+ visible?: boolean;
284
+ disabled?: boolean;
285
+ on_submit?: () => void;
286
+ ref?: (ref: TuiPromptRef | undefined) => void;
287
+ };
288
+ session_prompt_right: {
289
+ session_id: string;
290
+ };
291
+ home_bottom: {};
292
+ home_footer: {};
293
+ sidebar_title: {
294
+ session_id: string;
295
+ title: string;
296
+ share_url?: string;
297
+ };
298
+ sidebar_content: {
299
+ session_id: string;
300
+ };
301
+ sidebar_footer: {
302
+ session_id: string;
303
+ };
304
+ };
305
+ export type TuiSlotMap<Slots extends Record<string, object> = {}> = TuiHostSlotMap & Slots;
306
+ type TuiSlotShape<Name extends string, Slots extends Record<string, object>> = Name extends keyof TuiHostSlotMap ? TuiHostSlotMap[Name] : Name extends keyof Slots ? Slots[Name] : Record<string, unknown>;
307
+ export type TuiSlotProps<Name extends string = string, Slots extends Record<string, object> = {}> = {
308
+ name: Name;
309
+ mode?: SlotMode;
310
+ children?: JSX.Element;
311
+ } & TuiSlotShape<Name, Slots>;
312
+ export type TuiSlotContext = {
313
+ theme: TuiTheme;
314
+ };
315
+ type SlotCore<Slots extends Record<string, object> = {}> = SolidPlugin<TuiSlotMap<Slots>, TuiSlotContext>;
316
+ export type TuiSlotPlugin<Slots extends Record<string, object> = {}> = Omit<SlotCore<Slots>, "id"> & {
317
+ id?: never;
318
+ };
319
+ export type TuiSlots = {
320
+ register: {
321
+ (plugin: TuiSlotPlugin): string;
322
+ <Slots extends Record<string, object>>(plugin: TuiSlotPlugin<Slots>): string;
323
+ };
324
+ };
325
+ export type TuiEventBus = {
326
+ on: <Type extends Event["type"]>(type: Type, handler: (event: Extract<Event, {
327
+ type: Type;
328
+ }>) => void) => () => void;
329
+ };
330
+ export type TuiDispose = () => void | Promise<void>;
331
+ export type TuiLifecycle = {
332
+ readonly signal: AbortSignal;
333
+ onDispose: (fn: TuiDispose) => () => void;
334
+ };
335
+ export type TuiPluginState = "first" | "updated" | "same";
336
+ export type TuiPluginEntry = {
337
+ id: string;
338
+ source: "file" | "npm" | "internal";
339
+ spec: string;
340
+ target: string;
341
+ requested?: string;
342
+ version?: string;
343
+ modified?: number;
344
+ first_time: number;
345
+ last_time: number;
346
+ time_changed: number;
347
+ load_count: number;
348
+ fingerprint: string;
349
+ };
350
+ export type TuiPluginMeta = TuiPluginEntry & {
351
+ state: TuiPluginState;
352
+ };
353
+ export type TuiPluginStatus = {
354
+ id: string;
355
+ source: TuiPluginEntry["source"];
356
+ spec: string;
357
+ target: string;
358
+ enabled: boolean;
359
+ active: boolean;
360
+ };
361
+ export type TuiPluginInstallOptions = {
362
+ global?: boolean;
363
+ };
364
+ export type TuiPluginInstallResult = {
365
+ ok: true;
366
+ dir: string;
367
+ tui: boolean;
368
+ } | {
369
+ ok: false;
370
+ message: string;
371
+ missing?: boolean;
372
+ };
373
+ export type TuiWorkspace = {
374
+ current: () => string | undefined;
375
+ set: (workspaceID?: string) => void;
376
+ };
377
+ export type TuiPluginApi = {
378
+ app: TuiApp;
379
+ command: {
380
+ register: (cb: () => TuiCommand[]) => () => void;
381
+ trigger: (value: string) => void;
382
+ show: () => void;
383
+ };
384
+ route: {
385
+ register: (routes: TuiRouteDefinition[]) => () => void;
386
+ navigate: (name: string, params?: Record<string, unknown>) => void;
387
+ readonly current: TuiRouteCurrent;
388
+ };
389
+ ui: {
390
+ Dialog: (props: TuiDialogProps) => JSX.Element;
391
+ DialogAlert: (props: TuiDialogAlertProps) => JSX.Element;
392
+ DialogConfirm: (props: TuiDialogConfirmProps) => JSX.Element;
393
+ DialogPrompt: (props: TuiDialogPromptProps) => JSX.Element;
394
+ DialogSelect: <Value = unknown>(props: TuiDialogSelectProps<Value>) => JSX.Element;
395
+ Slot: <Name extends string>(props: TuiSlotProps<Name>) => JSX.Element | null;
396
+ Prompt: (props: TuiPromptProps) => JSX.Element;
397
+ toast: (input: TuiToast) => void;
398
+ dialog: TuiDialogStack;
399
+ };
400
+ keybind: {
401
+ match: (key: string, evt: ParsedKey) => boolean;
402
+ print: (key: string) => string;
403
+ create: (defaults: TuiKeybindMap, overrides?: Record<string, unknown>) => TuiKeybindSet;
404
+ };
405
+ readonly tuiConfig: Frozen<TuiConfigView>;
406
+ kv: TuiKV;
407
+ state: TuiState;
408
+ theme: TuiTheme;
409
+ client: OpencodeClient;
410
+ scopedClient: (workspaceID?: string) => OpencodeClient;
411
+ workspace: TuiWorkspace;
412
+ event: TuiEventBus;
413
+ renderer: CliRenderer;
414
+ slots: TuiSlots;
415
+ plugins: {
416
+ list: () => ReadonlyArray<TuiPluginStatus>;
417
+ activate: (id: string) => Promise<boolean>;
418
+ deactivate: (id: string) => Promise<boolean>;
419
+ add: (spec: string) => Promise<boolean>;
420
+ install: (spec: string, options?: TuiPluginInstallOptions) => Promise<TuiPluginInstallResult>;
421
+ };
422
+ lifecycle: TuiLifecycle;
423
+ };
424
+ export type TuiPlugin = (api: TuiPluginApi, options: PluginOptions | undefined, meta: TuiPluginMeta) => Promise<void>;
425
+ export type TuiPluginModule = {
426
+ id?: string;
427
+ tui: TuiPlugin;
428
+ server?: never;
429
+ };
package/dist/tui.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@matrix-ai/plugin",
4
- "version": "1.6.0",
4
+ "version": "1.6.1",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "scripts": {
@@ -16,16 +16,34 @@
16
16
  "./tool": {
17
17
  "import": "./dist/tool.js",
18
18
  "types": "./dist/tool.d.ts"
19
+ },
20
+ "./tui": {
21
+ "import": "./dist/tui.js",
22
+ "types": "./dist/tui.d.ts"
19
23
  }
20
24
  },
21
25
  "files": [
22
26
  "dist"
23
27
  ],
24
28
  "dependencies": {
25
- "@matrix-ai/sdk": "1.6.0",
29
+ "@matrix-ai/sdk": "1.6.1",
26
30
  "zod": "4.1.8"
27
31
  },
32
+ "peerDependencies": {
33
+ "@opentui/core": ">=0.1.96",
34
+ "@opentui/solid": ">=0.1.96"
35
+ },
36
+ "peerDependenciesMeta": {
37
+ "@opentui/core": {
38
+ "optional": true
39
+ },
40
+ "@opentui/solid": {
41
+ "optional": true
42
+ }
43
+ },
28
44
  "devDependencies": {
45
+ "@opentui/core": "0.1.96",
46
+ "@opentui/solid": "0.1.96",
29
47
  "@tsconfig/node22": "22.0.2",
30
48
  "@types/node": "22.13.9",
31
49
  "typescript": "5.8.2",