Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .opencode/plugin/core/daemon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,17 @@ const serveFake = (socket: string, opts: FakeOptions = {}): Fake => {
status: "ok",
version: opts.version ?? "test",
pid: 1,
...(opts.missingOperationFingerprint ? {} : { operationFingerprint: opts.operationFingerprint ?? OPERATION_FINGERPRINT }),
...(opts.missingOperationFingerprint
? {}
: { operationFingerprint: opts.operationFingerprint ?? OPERATION_FINGERPRINT }),
});
}
if (url.pathname === "/v1/status") {
return Response.json({
version: opts.version ?? "test",
...(opts.missingOperationFingerprint ? {} : { operationFingerprint: opts.operationFingerprint ?? OPERATION_FINGERPRINT }),
...(opts.missingOperationFingerprint
? {}
: { operationFingerprint: opts.operationFingerprint ?? OPERATION_FINGERPRINT }),
pid: 1,
socket,
config: opts.config,
Expand Down
35 changes: 30 additions & 5 deletions .opencode/plugin/core/daemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,16 @@ export const TUNING = {
*/
export const goDurationMs = (v: string | undefined): number | undefined => {
if (!v) return undefined;
const unit: Record<string, number> = { ns: 1e-6, us: 1e-3, µs: 1e-3, μs: 1e-3, ms: 1, s: 1000, m: 60_000, h: 3_600_000 };
const unit: Record<string, number> = {
ns: 1e-6,
us: 1e-3,
µs: 1e-3,
μs: 1e-3,
ms: 1,
s: 1000,
m: 60_000,
h: 3_600_000,
};
// Go's number grammar is digits[.digits*] or .digits, so ".5s" and
// "1.s" are whole components (#3490); Go also accepts both mu
// codepoints for microseconds -- U+00B5 (micro sign) and U+03BC
Expand Down Expand Up @@ -428,13 +437,19 @@ export class DaemonClient {
private async verifyOperationCompatibility(): Promise<void> {
const health = await this.health();
if (!health) {
throw new Error("mcpx: cannot verify /v1 operation compatibility because the daemon health endpoint did not answer; update or restart the mcpx daemon and plugin");
throw new Error(
"mcpx: cannot verify /v1 operation compatibility because the daemon health endpoint did not answer; update or restart the mcpx daemon and plugin",
);
}
if (typeof health.operationFingerprint !== "string" || health.operationFingerprint.length === 0) {
throw new Error("mcpx: cannot verify /v1 operation compatibility because the daemon does not publish an operation fingerprint; update and restart the mcpx daemon before using generated plugin operations");
throw new Error(
"mcpx: cannot verify /v1 operation compatibility because the daemon does not publish an operation fingerprint; update and restart the mcpx daemon before using generated plugin operations",
);
}
if (health.operationFingerprint !== OPERATION_FINGERPRINT) {
throw new Error(`mcpx: /v1 operation table mismatch (plugin ${OPERATION_FINGERPRINT}, daemon ${health.operationFingerprint}); update the mcpx plugin and daemon from matching versions`);
throw new Error(
`mcpx: /v1 operation table mismatch (plugin ${OPERATION_FINGERPRINT}, daemon ${health.operationFingerprint}); update the mcpx plugin and daemon from matching versions`,
);
}
}

Expand Down Expand Up @@ -503,7 +518,17 @@ export class DaemonClient {
*/
async health(
timeoutMs = TUNING.healthTimeoutMs,
): Promise<{ status: string; version?: string; pid?: number; uptime?: string; endpoint?: string; operationFingerprint?: string } | undefined> {
): Promise<
| {
status: string;
version?: string;
pid?: number;
uptime?: string;
endpoint?: string;
operationFingerprint?: string;
}
| undefined
> {
try {
return await this.get("/v1/health", timeoutMs);
} catch {
Expand Down
102 changes: 102 additions & 0 deletions .opencode/plugin/core/ops.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,31 @@ export const OPS: Record<string, OpSpec> = {
},
response: "json",
},
apis_add: {
method: "POST",
path: "/v1/apis",
params: {
name: { in: "body", required: true },
spec: { in: "body", required: true },
baseUrl: { in: "body" },
include: { in: "body" },
exclude: { in: "body" },
methods: { in: "body" },
includeDeprecated: { in: "body" },
headers: { in: "body" },
description: { in: "body" },
replace: { in: "body" },
},
response: "json",
},
apis_remove: {
method: "DELETE",
path: "/v1/apis/{name}",
params: {
name: { in: "path", required: true },
},
response: "json",
},
artifact_delete: {
method: "DELETE",
path: "/v1/artifacts/{id}",
Expand Down Expand Up @@ -446,6 +471,38 @@ export const OPS: Record<string, OpSpec> = {
params: {},
response: "json",
},
plugin_session_close: {
method: "DELETE",
path: "/v1/plugin-sessions/{id}",
params: {
id: { in: "path", required: true },
},
response: "json",
},
plugin_session_get: {
method: "GET",
path: "/v1/plugin-sessions/{id}",
params: {
id: { in: "path", required: true },
},
response: "json",
},
plugin_sessions_list: {
method: "GET",
path: "/v1/plugin-sessions",
params: {},
response: "json",
},
plugin_sessions_open: {
method: "POST",
path: "/v1/plugin-sessions",
params: {
plugin: { in: "body", required: true },
capabilities: { in: "body" },
hooks: { in: "body" },
},
response: "json",
},
preflight: {
method: "POST",
path: "/v1/preflight",
Expand Down Expand Up @@ -931,6 +988,23 @@ export class DaemonOps {
return this.invoke("adapters_remove", args, opts) as Promise<unknown>
}

/**
* Add an API declaration, live. `POST /v1/apis`.
* Privileged: it changes the daemon rather than reading it.
*/
apisAdd(args: { name: string; spec: string; baseUrl?: string; include?: unknown[]; exclude?: unknown[]; methods?: unknown[]; includeDeprecated?: boolean; headers?: Record<string, unknown>; description?: string; replace?: boolean }, opts: CallOptions = {}): Promise<unknown> {
return this.invoke("apis_add", args, opts) as Promise<unknown>
}

/**
* Remove an API declaration, live. `DELETE /v1/apis/{name}`.
* Privileged: it changes the daemon rather than reading it.
* Destructive: it cannot be undone, and other callers are affected.
*/
apisRemove(args: { name: string }, opts: CallOptions = {}): Promise<unknown> {
return this.invoke("apis_remove", args, opts) as Promise<unknown>
}

/**
* Forget one artifact. `DELETE /v1/artifacts/{id}`.
* Privileged: it changes the daemon rather than reading it.
Expand Down Expand Up @@ -1231,6 +1305,34 @@ export class DaemonOps {
return this.invoke("openapi", args, opts) as Promise<unknown>
}

/**
* End a plugin session, dropping everything it owns. `DELETE /v1/plugin-sessions/{id}`.
*/
pluginSessionClose(args: { id: string }, opts: CallOptions = {}): Promise<unknown> {
return this.invoke("plugin_session_close", args, opts) as Promise<unknown>
}

/**
* One live plugin session. `GET /v1/plugin-sessions/{id}`.
*/
pluginSessionGet(args: { id: string }, opts: CallOptions = {}): Promise<unknown> {
return this.invoke("plugin_session_get", args, opts) as Promise<unknown>
}

/**
* Live plugin sessions and what each one owns. `GET /v1/plugin-sessions`.
*/
pluginSessionsList(args: Record<string, never> = {}, opts: CallOptions = {}): Promise<unknown> {
return this.invoke("plugin_sessions_list", args, opts) as Promise<unknown>
}

/**
* Open a plugin session and be issued its id. `POST /v1/plugin-sessions`.
*/
pluginSessionsOpen(args: { plugin: string; capabilities?: unknown[]; hooks?: unknown[] }, opts: CallOptions = {}): Promise<unknown> {
return this.invoke("plugin_sessions_open", args, opts) as Promise<unknown>
}

/**
* Check a script's servers are ready before running it. `POST /v1/preflight`.
*/
Expand Down
Loading