@getmateo/plugin 0.19.9 → 0.19.11

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.
@@ -8,6 +8,7 @@ const ADAPTER_CAPABILITIES = [
8
8
  "prompt.command",
9
9
  "session.configure",
10
10
  "permission",
11
+ "request.cancel",
11
12
  ];
12
13
  export async function createAcpProviderConnection(options, request) {
13
14
  if (!request.versions.includes(PROVIDER_PROTOCOL_VERSION)) {
@@ -35,6 +36,8 @@ export async function createAcpProviderConnection(options, request) {
35
36
  const listeners = new Set();
36
37
  const sessions = new Map();
37
38
  const inFlight = new Set();
39
+ // Catalogue and listing requests each run a probe runtime that cancellation stops.
40
+ const cancellable = new Map();
38
41
  let closed = false;
39
42
  let closePromise = null;
40
43
  const emit = (event) => {
@@ -60,17 +63,33 @@ export async function createAcpProviderConnection(options, request) {
60
63
  throw new Error("ACP provider connection is closed");
61
64
  input = ProviderInputSchema.parse(input);
62
65
  validateAdmission(input, { capabilities, sessions });
66
+ if (input.type === "request.cancel") {
67
+ cancellable.get(input.requestId)?.abort(new Error("Mateo canceled the request"));
68
+ return;
69
+ }
70
+ const admitted = input;
71
+ const controller = new AbortController();
72
+ const { signal } = controller;
73
+ if (admitted.type === "catalog" || admitted.type === "sessions") {
74
+ cancellable.set(admitted.requestId, controller);
75
+ }
63
76
  const operation = Promise.resolve().then(async () => {
64
77
  if (closed)
65
78
  return undefined;
66
- await dispatch(input, state);
79
+ await dispatch(admitted, state, signal);
67
80
  return undefined;
68
81
  });
69
82
  const settled = operation.catch((error) => {
70
- emitOperationFailure(input, emit, error);
83
+ if (!signal.aborted)
84
+ emitOperationFailure(admitted, emit, error);
71
85
  });
72
86
  inFlight.add(settled);
73
- void settled.finally(() => inFlight.delete(settled));
87
+ void settled.finally(() => {
88
+ inFlight.delete(settled);
89
+ if ("requestId" in admitted && cancellable.get(admitted.requestId) === controller) {
90
+ cancellable.delete(admitted.requestId);
91
+ }
92
+ });
74
93
  },
75
94
  onEvent(listener) {
76
95
  listeners.add(listener);
@@ -81,6 +100,9 @@ export async function createAcpProviderConnection(options, request) {
81
100
  return closePromise;
82
101
  closed = true;
83
102
  closePromise = (async () => {
103
+ for (const controller of cancellable.values()) {
104
+ controller.abort(new Error("ACP provider connection closed"));
105
+ }
84
106
  await Promise.all(inFlight);
85
107
  const active = [...sessions.values()];
86
108
  sessions.clear();
@@ -124,13 +146,13 @@ function emitOperationFailure(input, emit, error) {
124
146
  emit({ type: "session.runtime_failed", sessionId: input.sessionId, error: failure });
125
147
  }
126
148
  }
127
- async function dispatch(input, state) {
149
+ async function dispatch(input, state, signal) {
128
150
  switch (input.type) {
129
151
  case "catalog":
130
- await discover(input, state);
152
+ await discover(input, state, signal);
131
153
  return;
132
154
  case "sessions":
133
- await listSessions(input, state);
155
+ await listSessions(input, state, signal);
134
156
  return;
135
157
  case "session.open":
136
158
  await openSession(input, state);
@@ -169,53 +191,74 @@ async function dispatch(input, state) {
169
191
  });
170
192
  }
171
193
  }
172
- async function discover(input, state) {
194
+ /**
195
+ * Runs one request in its own short-lived runtime and publishes its result before shutting the
196
+ * runtime down, so a slow session close cannot delay the reply. Aborting `signal` until shutdown
197
+ * ends closes the runtime, which terminates its process and fails whatever the request awaits.
198
+ */
199
+ async function withRequestRuntime(state, request) {
200
+ const { signal } = request;
173
201
  const runtime = await AcpRuntime.start({
174
202
  options: state.options,
175
203
  launch: state.launch,
176
- boundarySessionId: "catalog",
204
+ boundarySessionId: request.boundarySessionId,
177
205
  env: {},
178
206
  emit: state.emit,
207
+ signal,
179
208
  });
209
+ const closeOnAbort = () => void runtime.close().catch(() => undefined);
210
+ signal.addEventListener("abort", closeOnAbort, { once: true });
180
211
  try {
181
- let catalog = await runtime.discover(input.cwd);
182
- const config = runtime.configAccess();
183
- for (const transformer of state.options.transformers ?? []) {
184
- if (transformer.discover) {
185
- catalog = await transformer.discover(catalog, { sessionId: "catalog", config });
186
- }
187
- }
188
- state.emit({ type: "catalog", requestId: input.requestId, catalog });
212
+ signal.throwIfAborted();
213
+ const result = await request.run(runtime);
214
+ signal.throwIfAborted();
215
+ request.publish(result);
189
216
  }
190
217
  finally {
191
- await runtime.closeSession();
218
+ await (signal.aborted ? runtime.close() : runtime.closeSession());
219
+ signal.removeEventListener("abort", closeOnAbort);
192
220
  }
193
221
  }
194
- async function listSessions(input, state) {
195
- const runtime = await AcpRuntime.start({
196
- options: state.options,
197
- launch: state.launch,
222
+ async function discover(input, state, signal) {
223
+ await withRequestRuntime(state, {
224
+ boundarySessionId: "catalog",
225
+ signal,
226
+ async run(runtime) {
227
+ let catalog = await runtime.discover(input.cwd);
228
+ const config = runtime.configAccess();
229
+ for (const transformer of state.options.transformers ?? []) {
230
+ if (transformer.discover) {
231
+ catalog = await transformer.discover(catalog, { sessionId: "catalog", config });
232
+ }
233
+ }
234
+ return catalog;
235
+ },
236
+ publish(catalog) {
237
+ state.emit({ type: "catalog", requestId: input.requestId, catalog });
238
+ },
239
+ });
240
+ }
241
+ async function listSessions(input, state, signal) {
242
+ await withRequestRuntime(state, {
198
243
  boundarySessionId: "sessions",
199
- env: {},
200
- emit: state.emit,
244
+ signal,
245
+ async run(runtime) {
246
+ const response = await runtime.listSessions(input.cwd);
247
+ return input.limit ? response.sessions.slice(0, input.limit) : response.sessions;
248
+ },
249
+ publish(selected) {
250
+ state.emit({
251
+ type: "sessions",
252
+ requestId: input.requestId,
253
+ sessions: selected.map((session) => ({
254
+ persistence: nativePersistence(session.sessionId),
255
+ cwd: session.cwd,
256
+ title: session.title ?? undefined,
257
+ updatedAt: session.updatedAt ?? undefined,
258
+ })),
259
+ });
260
+ },
201
261
  });
202
- try {
203
- const response = await runtime.listSessions(input.cwd);
204
- const selected = input.limit ? response.sessions.slice(0, input.limit) : response.sessions;
205
- state.emit({
206
- type: "sessions",
207
- requestId: input.requestId,
208
- sessions: selected.map((session) => ({
209
- persistence: nativePersistence(session.sessionId),
210
- cwd: session.cwd,
211
- title: session.title ?? undefined,
212
- updatedAt: session.updatedAt ?? undefined,
213
- })),
214
- });
215
- }
216
- finally {
217
- await runtime.close();
218
- }
219
262
  }
220
263
  async function openSession(input, state) {
221
264
  if (state.sessions.has(input.sessionId))
@@ -257,6 +300,7 @@ function requireSession(state, sessionId) {
257
300
  }
258
301
  class AcpRuntime {
259
302
  static async start(options) {
303
+ options.signal?.throwIfAborted();
260
304
  let child = null;
261
305
  let spawnFailure = null;
262
306
  let stream;
@@ -285,6 +329,9 @@ class AcpRuntime {
285
329
  closeConnector = owned.close;
286
330
  }
287
331
  const runtime = new AcpRuntime(stream, child, closeConnector, options);
332
+ // Closing ends the transport, which fails the pending initialize below.
333
+ const closeOnAbort = () => void runtime.close().catch(() => undefined);
334
+ options.signal?.addEventListener("abort", closeOnAbort, { once: true });
288
335
  try {
289
336
  const initialize = withTimeout(runtime.call(runtime.connection.agent.request(methods.agent.initialize, {
290
337
  protocolVersion: PROTOCOL_VERSION,
@@ -294,13 +341,18 @@ class AcpRuntime {
294
341
  const initialized = spawnFailure
295
342
  ? await Promise.race([initialize, spawnFailure])
296
343
  : await initialize;
344
+ options.signal?.throwIfAborted();
297
345
  runtime.agentCapabilities = initialized.agentCapabilities ?? {};
298
346
  return runtime;
299
347
  }
300
348
  catch (error) {
301
349
  await runtime.close();
350
+ options.signal?.throwIfAborted();
302
351
  throw error;
303
352
  }
353
+ finally {
354
+ options.signal?.removeEventListener("abort", closeOnAbort);
355
+ }
304
356
  }
305
357
  constructor(stream, child, closeConnector, options) {
306
358
  this.options = options;
@@ -328,6 +380,7 @@ class AcpRuntime {
328
380
  */
329
381
  this.replayWindow = null;
330
382
  this.closing = false;
383
+ this.closePromise = null;
331
384
  this.processFailed = false;
332
385
  this.configTransaction = false;
333
386
  this.stagedTransformerConfig = null;
@@ -612,10 +665,20 @@ class AcpRuntime {
612
665
  }
613
666
  await this.close();
614
667
  }
615
- async close() {
616
- if (this.closing)
617
- return;
668
+ /** Concurrent callers share one shutdown, so each resolves only once the process has exited. */
669
+ close() {
670
+ if (this.closePromise)
671
+ return this.closePromise;
618
672
  this.closing = true;
673
+ const promise = this.closeInternal().catch((error) => {
674
+ if (this.closePromise === promise)
675
+ this.closePromise = null;
676
+ throw error;
677
+ });
678
+ this.closePromise = promise;
679
+ return promise;
680
+ }
681
+ async closeInternal() {
619
682
  this.settlePendingWork();
620
683
  await this.closeConnector();
621
684
  const child = this.child;
@@ -1,4 +1,5 @@
1
1
  import type { MateoApi, MateoWorkspaceActions, MateoWorkspaceHandle } from "@getmateo/client";
2
+ import type { BrowserAutomationCommand, BrowserAutomationDialogEvent, BrowserAutomationErrorCode, BrowserAutomationResult, BrowserAutomationTabInfo, BrowserDownloadReceipt } from "@getmateo/protocol/browser-automation/rpc-schemas";
2
3
  import type { ZodType, input as ZodInput, output as ZodOutput } from "zod";
3
4
  import type { PluginRpcContract } from "../rpc.js";
4
5
  import type { PluginCleanup } from "../contracts.js";
@@ -6,7 +7,108 @@ import type { ProviderRegistration } from "./provider.js";
6
7
  import type { UsageSourceRegistration } from "./usage.js";
7
8
  import type { ModelSourceRegistration } from "./models.js";
8
9
  import type { PluginLifecycleRegistration } from "./lifecycle.js";
9
- export interface PluginWorkspaceBrowser {
10
+ export type { BrowserAutomationCommand, BrowserAutomationDialogEvent, BrowserAutomationErrorCode, BrowserAutomationResult, BrowserAutomationTabInfo, BrowserDownloadReceipt, };
11
+ export interface PluginBrowserTab extends BrowserAutomationTabInfo {
12
+ origin: string;
13
+ }
14
+ export interface PluginBrowserExecuteOptions {
15
+ workspaceId?: string;
16
+ timeoutMs?: number;
17
+ }
18
+ export interface PluginBrowserAutomation {
19
+ /** Execute any browser-automation command directly so new protocol commands work without SDK changes. */
20
+ execute<C extends BrowserAutomationCommand>(command: C, options?: PluginBrowserExecuteOptions): Promise<Extract<BrowserAutomationResult, {
21
+ command: C["command"];
22
+ }>>;
23
+ listTabs(options?: PluginBrowserExecuteOptions): Promise<PluginBrowserTab[]>;
24
+ newTab(url?: string, options?: PluginBrowserExecuteOptions): Promise<{
25
+ browserId: string;
26
+ url: string;
27
+ workspaceId?: string;
28
+ }>;
29
+ closeTab(browserId: string, options?: PluginBrowserExecuteOptions): Promise<void>;
30
+ navigate(browserId: string, url: string, options?: PluginBrowserExecuteOptions): Promise<void>;
31
+ back(browserId: string, options?: PluginBrowserExecuteOptions): Promise<void>;
32
+ forward(browserId: string, options?: PluginBrowserExecuteOptions): Promise<void>;
33
+ reload(browserId: string, options?: PluginBrowserExecuteOptions): Promise<void>;
34
+ wait(browserId: string, condition: {
35
+ text?: string;
36
+ url?: string;
37
+ timeoutMs?: number;
38
+ }, options?: PluginBrowserExecuteOptions): Promise<{
39
+ matched: "text" | "url";
40
+ }>;
41
+ snapshot(browserId: string, options?: PluginBrowserExecuteOptions): Promise<Extract<BrowserAutomationResult, {
42
+ command: "snapshot";
43
+ }>>;
44
+ screenshot(browserId: string, options?: {
45
+ fullPage?: boolean;
46
+ } & PluginBrowserExecuteOptions): Promise<Extract<BrowserAutomationResult, {
47
+ command: "screenshot";
48
+ }>>;
49
+ click(browserId: string, input: {
50
+ ref: string;
51
+ button?: "left" | "right" | "middle";
52
+ doubleClick?: boolean;
53
+ modifiers?: readonly ("Alt" | "Control" | "Meta" | "Shift")[];
54
+ }, options?: PluginBrowserExecuteOptions): Promise<Extract<BrowserAutomationResult, {
55
+ command: "click";
56
+ }>>;
57
+ fill(browserId: string, input: {
58
+ ref: string;
59
+ value: string;
60
+ }, options?: PluginBrowserExecuteOptions): Promise<void>;
61
+ type(browserId: string, input: {
62
+ text: string;
63
+ ref?: string;
64
+ }, options?: PluginBrowserExecuteOptions): Promise<void>;
65
+ keypress(browserId: string, input: {
66
+ key: string;
67
+ ref?: string;
68
+ }, options?: PluginBrowserExecuteOptions): Promise<void>;
69
+ select(browserId: string, input: {
70
+ ref: string;
71
+ value: string;
72
+ }, options?: PluginBrowserExecuteOptions): Promise<void>;
73
+ hover(browserId: string, input: {
74
+ ref: string;
75
+ }, options?: PluginBrowserExecuteOptions): Promise<void>;
76
+ drag(browserId: string, input: {
77
+ sourceRef: string;
78
+ targetRef: string;
79
+ }, options?: PluginBrowserExecuteOptions): Promise<void>;
80
+ scroll(browserId: string, input: {
81
+ deltaX: number;
82
+ deltaY: number;
83
+ ref?: string;
84
+ }, options?: PluginBrowserExecuteOptions): Promise<void>;
85
+ resize(browserId: string, input: {
86
+ width: number;
87
+ height: number;
88
+ }, options?: PluginBrowserExecuteOptions): Promise<{
89
+ width: number;
90
+ height: number;
91
+ }>;
92
+ logs(browserId: string, options?: {
93
+ maxEntries?: number;
94
+ } & PluginBrowserExecuteOptions): Promise<Extract<BrowserAutomationResult, {
95
+ command: "logs";
96
+ }>>;
97
+ evaluate<T = unknown>(browserId: string, fn: string, options?: {
98
+ ref?: string;
99
+ } & PluginBrowserExecuteOptions): Promise<{
100
+ value: T;
101
+ resultJson: string;
102
+ truncated: boolean;
103
+ }>;
104
+ uploadFiles(browserId: string, input: {
105
+ ref: string;
106
+ filePaths: readonly string[];
107
+ }, options?: PluginBrowserExecuteOptions): Promise<void>;
108
+ listDownloads(options?: PluginBrowserExecuteOptions): Promise<BrowserDownloadReceipt[]>;
109
+ }
110
+ export interface PluginWorkspaceBrowser extends Omit<PluginBrowserAutomation, "listTabs" | "navigate" | "wait"> {
111
+ readonly automation: PluginBrowserAutomation;
10
112
  listTabs(): Promise<{
11
113
  browserId: string;
12
114
  origin: string;
@@ -24,6 +126,7 @@ export interface PluginWorkspaceBrowser {
24
126
  }): Promise<void>;
25
127
  }
26
128
  export interface PluginMateoApi extends MateoApi {
129
+ readonly browser: PluginBrowserAutomation;
27
130
  readonly workspaces: Omit<MateoWorkspaceActions, "ref"> & {
28
131
  ref(...args: Parameters<MateoWorkspaceActions["ref"]>): MateoWorkspaceHandle & {
29
132
  readonly browser: PluginWorkspaceBrowser;
@@ -68,6 +171,12 @@ export interface PluginServerPlugins {
68
171
  */
69
172
  setBuiltinEnabled(id: string, enabled: boolean): Promise<PluginBuiltinState>;
70
173
  }
174
+ /** The running plugin, as `server.plugin` reports it. Mateo addition. */
175
+ export interface PluginServerIdentity {
176
+ readonly id: string;
177
+ /** Absolute path of the plugin's installed directory, the one holding its manifest. */
178
+ readonly directory: string;
179
+ }
71
180
  export interface PluginServerContext extends PluginLifecycleRegistration {
72
181
  registerSettings<Schema extends ZodType>(definition: import("../settings.js").SettingsDefinition<Schema>): PluginSettings<Schema>;
73
182
  handle<InputSchema extends ZodType, OutputSchema extends ZodType>(contract: PluginRpcContract<InputSchema, OutputSchema>, handler: (input: ZodOutput<InputSchema>, context: PluginHandlerContext) => ZodInput<OutputSchema> | Promise<ZodInput<OutputSchema>>): void;
@@ -76,6 +185,8 @@ export interface PluginServerContext extends PluginLifecycleRegistration {
76
185
  /** Mateo: contributes models to an existing provider. */
77
186
  registerModelSource(source: ModelSourceRegistration): void;
78
187
  plugins: PluginServerPlugins;
188
+ /** Mateo: the plugin this contribution belongs to. */
189
+ plugin: PluginServerIdentity;
79
190
  }
80
191
  export type PluginServerContribution = (server: PluginServerContext) => PluginCleanup;
81
192
  //# sourceMappingURL=contracts.d.ts.map
@@ -1,6 +1,6 @@
1
1
  export type { UsageSourceRegistration, UsageReport, UsageWindow, UsageBalance, UsageDetail, } from "./usage.js";
2
2
  export type { ModelSourceMode, ModelSourceModel, ModelSourceRegistration, ModelSourceRequest, ModelSourceResult, } from "./models.js";
3
- export type { PluginBuiltinState, PluginHandlerContext, PluginMateoApi, PluginWorkspaceBrowser, PluginServerContext, PluginServerContribution, PluginServerPlugins, PluginSettings, PluginSettingsState, } from "./contracts.js";
3
+ export type { BrowserAutomationCommand, BrowserAutomationDialogEvent, BrowserAutomationErrorCode, BrowserAutomationResult, BrowserAutomationTabInfo, BrowserDownloadReceipt, PluginBrowserAutomation, PluginBrowserExecuteOptions, PluginBrowserTab, PluginBuiltinState, PluginHandlerContext, PluginMateoApi, PluginWorkspaceBrowser, PluginServerContext, PluginServerContribution, PluginServerIdentity, PluginServerPlugins, PluginSettings, PluginSettingsState, } from "./contracts.js";
4
4
  export type { PluginHookContext, PluginHookWorkspace, PluginHookAgent, PluginSessionOpenRequest, PluginTurnOutcome, PluginLifecycleEvents, PluginBeforeRequests, PluginLifecycleRegistration, } from "./lifecycle.js";
5
5
  export { spawnProcess, execCommand, terminateProcess } from "./process.js";
6
6
  //# sourceMappingURL=index.d.ts.map
@@ -1,7 +1,7 @@
1
1
  import type { JsonValue } from "@getmateo/protocol/agent-types";
2
2
  import { z } from "zod";
3
3
  export declare const PROVIDER_PROTOCOL_VERSION: 1;
4
- export declare const PROVIDER_CAPABILITIES: readonly ["prompt.message", "prompt.command", "prompt.image", "prompt.output_schema", "prompt.steer", "session.archive", "session.configure", "session.list", "session.persistence", "session.revert.both", "session.revert.conversation", "session.revert.files", "session.subsession", "session.unarchive", "permission", "permission.tool_policy", "timeline.plugin"];
4
+ export declare const PROVIDER_CAPABILITIES: readonly ["prompt.message", "prompt.command", "prompt.image", "prompt.output_schema", "prompt.steer", "session.archive", "session.configure", "session.list", "session.persistence", "session.revert.both", "session.revert.conversation", "session.revert.files", "session.subsession", "session.unarchive", "permission", "permission.tool_policy", "request.cancel", "timeline.plugin"];
5
5
  export type ProviderCapability = (typeof PROVIDER_CAPABILITIES)[number];
6
6
  export interface ProviderRegistration {
7
7
  /** Equal keys share discovery within this provider. Include effective configuration and execution environment. */
@@ -359,6 +359,15 @@ export type ProviderInput = {
359
359
  type: "session.close";
360
360
  requestId: string;
361
361
  sessionId: string;
362
+ }
363
+ /**
364
+ * Mateo stopped waiting for the request with this `requestId`, such as a catalogue refresh that
365
+ * passed its deadline. Stop its work and release what it started; Mateo ignores later events for
366
+ * it. Sent only when the connection offers `request.cancel`.
367
+ */
368
+ | {
369
+ type: "request.cancel";
370
+ requestId: string;
362
371
  };
363
372
  export interface ProviderThinkingOption {
364
373
  id: string;
@@ -17,6 +17,7 @@ export const PROVIDER_CAPABILITIES = [
17
17
  "session.unarchive",
18
18
  "permission",
19
19
  "permission.tool_policy",
20
+ "request.cancel",
20
21
  "timeline.plugin",
21
22
  ];
22
23
  export const ProviderLaunchSchema = z
@@ -109,6 +110,8 @@ function requiredPromptCapabilities(prompt) {
109
110
  }
110
111
  export function requiredProviderCapabilities(input) {
111
112
  switch (input.type) {
113
+ case "request.cancel":
114
+ return ["request.cancel"];
112
115
  case "catalog":
113
116
  case "session.interrupt":
114
117
  case "session.close":
@@ -419,6 +422,7 @@ export const ProviderInputSchema = z.discriminatedUnion("type", [
419
422
  })
420
423
  .strict(),
421
424
  z.object({ type: z.literal("session.close"), requestId: idSchema, sessionId: idSchema }).strict(),
425
+ z.object({ type: z.literal("request.cancel"), requestId: idSchema }).strict(),
422
426
  ]);
423
427
  const modeSchema = z
424
428
  .object({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getmateo/plugin",
3
- "version": "0.19.9",
3
+ "version": "0.19.11",
4
4
  "description": "Mateo plugin SDK package",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -76,8 +76,8 @@
76
76
  "use-sync-external-store": "^1.6.0"
77
77
  },
78
78
  "devDependencies": {
79
- "@getmateo/client": "0.19.9",
80
- "@getmateo/protocol": "0.19.9",
79
+ "@getmateo/client": "0.19.11",
80
+ "@getmateo/protocol": "0.19.11",
81
81
  "@types/node": "^20.9.0",
82
82
  "@types/react": "~19.3.0",
83
83
  "react": "19.3.0",
@@ -87,8 +87,8 @@
87
87
  "zod": "4.6.7"
88
88
  },
89
89
  "peerDependencies": {
90
- "@getmateo/client": "0.19.9",
91
- "@getmateo/protocol": "0.19.9",
90
+ "@getmateo/client": "0.19.11",
91
+ "@getmateo/protocol": "0.19.11",
92
92
  "react": "^19.1.0",
93
93
  "react-native": ">=0.81.5",
94
94
  "zod": "4.6.7"