@getmateo/plugin 0.19.10 → 0.19.12
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(
|
|
79
|
+
await dispatch(admitted, state, signal);
|
|
67
80
|
return undefined;
|
|
68
81
|
});
|
|
69
82
|
const settled = operation.catch((error) => {
|
|
70
|
-
|
|
83
|
+
if (!signal.aborted)
|
|
84
|
+
emitOperationFailure(admitted, emit, error);
|
|
71
85
|
});
|
|
72
86
|
inFlight.add(settled);
|
|
73
|
-
void settled.finally(() =>
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
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
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
|
|
200
|
-
|
|
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
|
-
|
|
616
|
-
|
|
617
|
-
|
|
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;
|
|
@@ -171,6 +171,12 @@ export interface PluginServerPlugins {
|
|
|
171
171
|
*/
|
|
172
172
|
setBuiltinEnabled(id: string, enabled: boolean): Promise<PluginBuiltinState>;
|
|
173
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
|
+
}
|
|
174
180
|
export interface PluginServerContext extends PluginLifecycleRegistration {
|
|
175
181
|
registerSettings<Schema extends ZodType>(definition: import("../settings.js").SettingsDefinition<Schema>): PluginSettings<Schema>;
|
|
176
182
|
handle<InputSchema extends ZodType, OutputSchema extends ZodType>(contract: PluginRpcContract<InputSchema, OutputSchema>, handler: (input: ZodOutput<InputSchema>, context: PluginHandlerContext) => ZodInput<OutputSchema> | Promise<ZodInput<OutputSchema>>): void;
|
|
@@ -179,6 +185,8 @@ export interface PluginServerContext extends PluginLifecycleRegistration {
|
|
|
179
185
|
/** Mateo: contributes models to an existing provider. */
|
|
180
186
|
registerModelSource(source: ModelSourceRegistration): void;
|
|
181
187
|
plugins: PluginServerPlugins;
|
|
188
|
+
/** Mateo: the plugin this contribution belongs to. */
|
|
189
|
+
plugin: PluginServerIdentity;
|
|
182
190
|
}
|
|
183
191
|
export type PluginServerContribution = (server: PluginServerContext) => PluginCleanup;
|
|
184
192
|
//# sourceMappingURL=contracts.d.ts.map
|
package/dist/server/index.d.ts
CHANGED
|
@@ -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 { BrowserAutomationCommand, BrowserAutomationDialogEvent, BrowserAutomationErrorCode, BrowserAutomationResult, BrowserAutomationTabInfo, BrowserDownloadReceipt, PluginBrowserAutomation, PluginBrowserExecuteOptions, PluginBrowserTab, 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;
|
package/dist/server/provider.js
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.19.12",
|
|
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.
|
|
80
|
-
"@getmateo/protocol": "0.19.
|
|
79
|
+
"@getmateo/client": "0.19.12",
|
|
80
|
+
"@getmateo/protocol": "0.19.12",
|
|
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.
|
|
91
|
-
"@getmateo/protocol": "0.19.
|
|
90
|
+
"@getmateo/client": "0.19.12",
|
|
91
|
+
"@getmateo/protocol": "0.19.12",
|
|
92
92
|
"react": "^19.1.0",
|
|
93
93
|
"react-native": ">=0.81.5",
|
|
94
94
|
"zod": "4.6.7"
|