@getmateo/plugin 0.0.0-stage → 0.18.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/LICENSE +211 -0
- package/dist/attachments.d.ts +26 -0
- package/dist/attachments.js +17 -0
- package/dist/client/buttons.d.ts +64 -0
- package/dist/client/buttons.js +2 -0
- package/dist/client/client-state.d.ts +15 -0
- package/dist/client/client-state.js +32 -0
- package/dist/client/contracts.d.ts +299 -0
- package/dist/client/contracts.js +2 -0
- package/dist/client/host.d.ts +19 -0
- package/dist/client/host.js +12 -0
- package/dist/client/index.d.ts +39 -0
- package/dist/client/index.js +4 -0
- package/dist/client/mateo-context.d.ts +9 -0
- package/dist/client/mateo-context.js +16 -0
- package/dist/client/menu.d.ts +45 -0
- package/dist/client/menu.js +2 -0
- package/dist/client/react-native.d.ts +53 -0
- package/dist/client/react-native.js +2 -0
- package/dist/client/rpc-context.d.ts +13 -0
- package/dist/client/rpc-context.js +18 -0
- package/dist/client/runtime-context-bridge.d.ts +5 -0
- package/dist/client/runtime-context-bridge.js +19 -0
- package/dist/client/settings-sections.d.ts +12 -0
- package/dist/client/settings-sections.js +2 -0
- package/dist/client/shallow.d.ts +2 -0
- package/dist/client/shallow.js +45 -0
- package/dist/client/sidebar-projects.d.ts +110 -0
- package/dist/client/sidebar-projects.js +2 -0
- package/dist/client/sidebar-workspaces.d.ts +17 -0
- package/dist/client/sidebar-workspaces.js +2 -0
- package/dist/client/storage.d.ts +12 -0
- package/dist/client/storage.js +2 -0
- package/dist/client/terminal-themes.d.ts +33 -0
- package/dist/client/terminal-themes.js +2 -0
- package/dist/client/ui.d.ts +161 -0
- package/dist/client/ui.js +2 -0
- package/dist/contracts.d.ts +90 -0
- package/dist/contracts.js +2 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +5 -0
- package/dist/rpc.d.ts +17 -0
- package/dist/rpc.js +12 -0
- package/dist/server/acp-internal/connection.d.ts +4 -0
- package/dist/server/acp-internal/connection.js +1301 -0
- package/dist/server/acp.d.ts +112 -0
- package/dist/server/acp.js +22 -0
- package/dist/server/contracts.d.ts +81 -0
- package/dist/server/contracts.js +2 -0
- package/dist/server/index.d.ts +6 -0
- package/dist/server/index.js +2 -0
- package/dist/server/lifecycle.d.ts +99 -0
- package/dist/server/lifecycle.js +2 -0
- package/dist/server/models.d.ts +55 -0
- package/dist/server/models.js +2 -0
- package/dist/server/process-internal/windows-command.d.ts +15 -0
- package/dist/server/process-internal/windows-command.js +41 -0
- package/dist/server/process.d.ts +25 -0
- package/dist/server/process.js +71 -0
- package/dist/server/provider.d.ts +735 -0
- package/dist/server/provider.js +871 -0
- package/dist/server/usage.d.ts +149 -0
- package/dist/server/usage.js +134 -0
- package/dist/settings.d.ts +70 -0
- package/dist/settings.js +40 -0
- package/package.json +99 -4
- package/README.md +0 -3
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { JsonValue } from "@getmateo/protocol/agent-types";
|
|
2
|
+
import type { ProviderCatalog, ProviderCommand, ProviderConfigState, ProviderNotice, ProviderRegistration, ProviderTimelineItem } from "./provider.js";
|
|
3
|
+
interface RunAcpProviderBaseOptions {
|
|
4
|
+
id: string;
|
|
5
|
+
label: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
icon?: string;
|
|
8
|
+
acpOptions?: AcpOptions;
|
|
9
|
+
transformers?: readonly AcpTransformer[];
|
|
10
|
+
}
|
|
11
|
+
export type RunAcpProviderOptions = RunAcpProviderBaseOptions & ({
|
|
12
|
+
command: readonly [string, ...string[]];
|
|
13
|
+
connector?: never;
|
|
14
|
+
} | {
|
|
15
|
+
connector: AcpConnector;
|
|
16
|
+
command?: never;
|
|
17
|
+
});
|
|
18
|
+
export type AcpStreamMessage = {
|
|
19
|
+
jsonrpc: "2.0";
|
|
20
|
+
id: string | number | null;
|
|
21
|
+
method: string;
|
|
22
|
+
params?: unknown;
|
|
23
|
+
} | {
|
|
24
|
+
jsonrpc: "2.0";
|
|
25
|
+
method: string;
|
|
26
|
+
params?: unknown;
|
|
27
|
+
} | {
|
|
28
|
+
jsonrpc: "2.0";
|
|
29
|
+
id: string | number | null;
|
|
30
|
+
result: unknown;
|
|
31
|
+
} | {
|
|
32
|
+
jsonrpc: "2.0";
|
|
33
|
+
id: string | number | null;
|
|
34
|
+
error: {
|
|
35
|
+
code: number;
|
|
36
|
+
message: string;
|
|
37
|
+
data?: unknown;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export interface AcpStream {
|
|
41
|
+
writable: WritableStream<AcpStreamMessage>;
|
|
42
|
+
readable: ReadableStream<AcpStreamMessage>;
|
|
43
|
+
}
|
|
44
|
+
export type AcpConnector = () => AcpStream | Promise<AcpStream>;
|
|
45
|
+
export interface AcpOptions {
|
|
46
|
+
protocol?: "auto" | "v1";
|
|
47
|
+
startupTimeoutMs?: number;
|
|
48
|
+
waitForInitialCommands?: boolean;
|
|
49
|
+
initialCommandsTimeoutMs?: number;
|
|
50
|
+
}
|
|
51
|
+
export interface AcpContext {
|
|
52
|
+
sessionId: string;
|
|
53
|
+
}
|
|
54
|
+
export interface AcpConfigAccess {
|
|
55
|
+
read(): Promise<Readonly<Record<string, JsonValue>>>;
|
|
56
|
+
set(id: string, value: JsonValue): Promise<void>;
|
|
57
|
+
}
|
|
58
|
+
export interface AcpDiscoveryContext extends AcpContext {
|
|
59
|
+
config: AcpConfigAccess;
|
|
60
|
+
}
|
|
61
|
+
export interface AcpConfigureContext extends AcpContext {
|
|
62
|
+
config: AcpConfigAccess;
|
|
63
|
+
}
|
|
64
|
+
export type AcpConfigChange = {
|
|
65
|
+
target: "model";
|
|
66
|
+
value: string | null;
|
|
67
|
+
} | {
|
|
68
|
+
target: "mode";
|
|
69
|
+
value: string | null;
|
|
70
|
+
} | {
|
|
71
|
+
target: "thinking";
|
|
72
|
+
value: string | null;
|
|
73
|
+
} | {
|
|
74
|
+
target: "setting";
|
|
75
|
+
id: string;
|
|
76
|
+
value: JsonValue;
|
|
77
|
+
};
|
|
78
|
+
export interface AcpToolCallSnapshot {
|
|
79
|
+
id: string;
|
|
80
|
+
name?: string;
|
|
81
|
+
title: string;
|
|
82
|
+
kind?: string;
|
|
83
|
+
status: "pending" | "in_progress" | "completed" | "failed";
|
|
84
|
+
input: JsonValue;
|
|
85
|
+
output: JsonValue;
|
|
86
|
+
locations: readonly string[];
|
|
87
|
+
}
|
|
88
|
+
export type AcpVendorUpdate = {
|
|
89
|
+
type: "commands";
|
|
90
|
+
commands: readonly ProviderCommand[];
|
|
91
|
+
} | {
|
|
92
|
+
type: "config";
|
|
93
|
+
config: ProviderConfigState;
|
|
94
|
+
} | {
|
|
95
|
+
type: "timeline";
|
|
96
|
+
item: ProviderTimelineItem;
|
|
97
|
+
} | {
|
|
98
|
+
type: "notice";
|
|
99
|
+
notice: ProviderNotice;
|
|
100
|
+
};
|
|
101
|
+
export interface AcpTransformer {
|
|
102
|
+
discover?(catalog: ProviderCatalog, context: AcpDiscoveryContext): Promise<ProviderCatalog> | ProviderCatalog;
|
|
103
|
+
configure?(change: AcpConfigChange, context: AcpConfigureContext): Promise<"handled" | "pass">;
|
|
104
|
+
notification?(notification: {
|
|
105
|
+
method: string;
|
|
106
|
+
params: JsonValue;
|
|
107
|
+
}, context: AcpContext): AcpVendorUpdate | readonly AcpVendorUpdate[] | null;
|
|
108
|
+
toolCall?(toolCall: AcpToolCallSnapshot, context: AcpContext): AcpToolCallSnapshot;
|
|
109
|
+
}
|
|
110
|
+
export declare function runAcpProvider(options: RunAcpProviderOptions): ProviderRegistration;
|
|
111
|
+
export {};
|
|
112
|
+
//# sourceMappingURL=acp.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createAcpProviderConnection } from "./acp-internal/connection.js";
|
|
2
|
+
export function runAcpProvider(options) {
|
|
3
|
+
const hasCommand = options.command !== undefined;
|
|
4
|
+
const hasConnector = options.connector !== undefined;
|
|
5
|
+
if (hasCommand === hasConnector) {
|
|
6
|
+
throw new Error("ACP provider requires exactly one command or SDK connector");
|
|
7
|
+
}
|
|
8
|
+
if (options.command && (options.command.length === 0 || options.command[0].trim().length === 0)) {
|
|
9
|
+
throw new Error("ACP provider command must contain an executable");
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
id: options.id,
|
|
13
|
+
label: options.label,
|
|
14
|
+
description: options.description,
|
|
15
|
+
icon: options.icon,
|
|
16
|
+
command: options.command,
|
|
17
|
+
connect(request) {
|
|
18
|
+
return createAcpProviderConnection(options, request);
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=acp.js.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { MateoApi, MateoWorkspaceActions, MateoWorkspaceHandle } from "@getmateo/client";
|
|
2
|
+
import type { ZodType, input as ZodInput, output as ZodOutput } from "zod";
|
|
3
|
+
import type { PluginRpcContract } from "../rpc.js";
|
|
4
|
+
import type { PluginCleanup } from "../contracts.js";
|
|
5
|
+
import type { ProviderRegistration } from "./provider.js";
|
|
6
|
+
import type { UsageSourceRegistration } from "./usage.js";
|
|
7
|
+
import type { ModelSourceRegistration } from "./models.js";
|
|
8
|
+
import type { PluginLifecycleRegistration } from "./lifecycle.js";
|
|
9
|
+
export interface PluginWorkspaceBrowser {
|
|
10
|
+
listTabs(): Promise<{
|
|
11
|
+
browserId: string;
|
|
12
|
+
origin: string;
|
|
13
|
+
}[]>;
|
|
14
|
+
navigate(browserId: string, url: string): Promise<void>;
|
|
15
|
+
readImageSource(browserId: string, selector: string | readonly string[]): Promise<string>;
|
|
16
|
+
wait(browserId: string, condition: {
|
|
17
|
+
text?: string;
|
|
18
|
+
url?: string;
|
|
19
|
+
timeoutMs?: number;
|
|
20
|
+
}): Promise<void>;
|
|
21
|
+
upload(browserId: string, input: {
|
|
22
|
+
selector: string;
|
|
23
|
+
filePath: string;
|
|
24
|
+
}): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export interface PluginMateoApi extends MateoApi {
|
|
27
|
+
readonly workspaces: Omit<MateoWorkspaceActions, "ref"> & {
|
|
28
|
+
ref(...args: Parameters<MateoWorkspaceActions["ref"]>): MateoWorkspaceHandle & {
|
|
29
|
+
readonly browser: PluginWorkspaceBrowser;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export interface PluginHandlerContext {
|
|
34
|
+
mateo: PluginMateoApi;
|
|
35
|
+
}
|
|
36
|
+
export type PluginSettingsState<Schema extends ZodType> = {
|
|
37
|
+
status: "ready";
|
|
38
|
+
revision: string;
|
|
39
|
+
values: ZodOutput<Schema>;
|
|
40
|
+
} | {
|
|
41
|
+
status: "invalid";
|
|
42
|
+
revision: string;
|
|
43
|
+
error: string;
|
|
44
|
+
};
|
|
45
|
+
export interface PluginSettings<Schema extends ZodType> {
|
|
46
|
+
read(): Promise<PluginSettingsState<Schema>>;
|
|
47
|
+
/** Saves the complete document; rejects validation failures, stale revisions, and I/O errors. */
|
|
48
|
+
save(values: ZodInput<Schema>, revision: string): Promise<Extract<PluginSettingsState<Schema>, {
|
|
49
|
+
status: "ready";
|
|
50
|
+
}>>;
|
|
51
|
+
subscribe(listener: (state: PluginSettingsState<Schema>) => void | Promise<void>): PluginCleanup;
|
|
52
|
+
}
|
|
53
|
+
/** A plugin that ships with the daemon, as `server.plugins.listBuiltin()` reports it. */
|
|
54
|
+
export interface PluginBuiltinState {
|
|
55
|
+
id: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
/** False while the user has it turned off; persisted across daemon restarts. */
|
|
58
|
+
enabled: boolean;
|
|
59
|
+
status: "running" | "disabled" | "failed";
|
|
60
|
+
error?: string;
|
|
61
|
+
}
|
|
62
|
+
/** Daemon plugin management. Mateo addition. */
|
|
63
|
+
export interface PluginServerPlugins {
|
|
64
|
+
listBuiltin(): Promise<PluginBuiltinState[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Turns a built-in plugin on or off, live and persisted. Rejects IDs that are not built-in and
|
|
67
|
+
* a plugin turning itself off; `mateo plugin disable <id>` stays the way to do that.
|
|
68
|
+
*/
|
|
69
|
+
setBuiltinEnabled(id: string, enabled: boolean): Promise<PluginBuiltinState>;
|
|
70
|
+
}
|
|
71
|
+
export interface PluginServerContext extends PluginLifecycleRegistration {
|
|
72
|
+
registerSettings<Schema extends ZodType>(definition: import("../settings.js").SettingsDefinition<Schema>): PluginSettings<Schema>;
|
|
73
|
+
handle<InputSchema extends ZodType, OutputSchema extends ZodType>(contract: PluginRpcContract<InputSchema, OutputSchema>, handler: (input: ZodOutput<InputSchema>, context: PluginHandlerContext) => ZodInput<OutputSchema> | Promise<ZodInput<OutputSchema>>): void;
|
|
74
|
+
registerProvider(provider: ProviderRegistration): void;
|
|
75
|
+
registerUsageSource(source: UsageSourceRegistration): void;
|
|
76
|
+
/** Mateo: contributes models to an existing provider. */
|
|
77
|
+
registerModelSource(source: ModelSourceRegistration): void;
|
|
78
|
+
plugins: PluginServerPlugins;
|
|
79
|
+
}
|
|
80
|
+
export type PluginServerContribution = (server: PluginServerContext) => PluginCleanup;
|
|
81
|
+
//# sourceMappingURL=contracts.d.ts.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { UsageSourceRegistration, UsageReport, UsageWindow, UsageBalance, UsageDetail, } from "./usage.js";
|
|
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";
|
|
4
|
+
export type { PluginHookContext, PluginHookWorkspace, PluginHookAgent, PluginSessionOpenRequest, PluginTurnOutcome, PluginLifecycleEvents, PluginBeforeRequests, PluginLifecycleRegistration, } from "./lifecycle.js";
|
|
5
|
+
export { spawnProcess, execCommand, terminateProcess } from "./process.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { AgentPermissionRequest, AgentPermissionResponse, AgentTimelineItem, AgentSessionConfig } from "@getmateo/protocol/agent-types";
|
|
2
|
+
import type { PluginMateoApi } from "./contracts.js";
|
|
3
|
+
import type { WorkspaceCreateRequest } from "@getmateo/protocol/messages";
|
|
4
|
+
export interface PluginHookContext {
|
|
5
|
+
mateo: PluginMateoApi;
|
|
6
|
+
signal: AbortSignal;
|
|
7
|
+
}
|
|
8
|
+
export interface PluginHookWorkspace {
|
|
9
|
+
id: string;
|
|
10
|
+
projectId: string;
|
|
11
|
+
cwd: string;
|
|
12
|
+
name: string | null;
|
|
13
|
+
archivedAt: string | null;
|
|
14
|
+
}
|
|
15
|
+
export interface PluginHookAgent {
|
|
16
|
+
id: string;
|
|
17
|
+
workspaceId: string | null;
|
|
18
|
+
parentAgentId: string | null;
|
|
19
|
+
provider: string;
|
|
20
|
+
cwd: string;
|
|
21
|
+
title: string | null;
|
|
22
|
+
}
|
|
23
|
+
export interface PluginSessionOpenRequest {
|
|
24
|
+
agentId: string;
|
|
25
|
+
workspaceId: string | null;
|
|
26
|
+
provider: string;
|
|
27
|
+
cwd: string;
|
|
28
|
+
reason: "create" | "resume" | "refresh" | "import";
|
|
29
|
+
purpose: "interactive" | "history";
|
|
30
|
+
env: Record<string, string>;
|
|
31
|
+
}
|
|
32
|
+
export type PluginTurnOutcome = {
|
|
33
|
+
kind: "completed";
|
|
34
|
+
} | {
|
|
35
|
+
kind: "failed";
|
|
36
|
+
error: {
|
|
37
|
+
message: string;
|
|
38
|
+
code?: string;
|
|
39
|
+
};
|
|
40
|
+
} | {
|
|
41
|
+
kind: "canceled";
|
|
42
|
+
reason: string;
|
|
43
|
+
};
|
|
44
|
+
export interface PluginLifecycleEvents {
|
|
45
|
+
"agent.turn_started": {
|
|
46
|
+
agent: PluginHookAgent;
|
|
47
|
+
turnId: string | null;
|
|
48
|
+
};
|
|
49
|
+
"agent.turn_ended": {
|
|
50
|
+
agent: PluginHookAgent;
|
|
51
|
+
turnId: string | null;
|
|
52
|
+
outcome: PluginTurnOutcome;
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated Always empty. Fetch history on demand with
|
|
55
|
+
* context.mateo.agents.ref(agent.id).timeline.refetch({ direction: "tail", limit: 20 }).
|
|
56
|
+
*/
|
|
57
|
+
timeline: readonly AgentTimelineItem[];
|
|
58
|
+
};
|
|
59
|
+
"agent.permission_requested": {
|
|
60
|
+
agent: PluginHookAgent;
|
|
61
|
+
request: AgentPermissionRequest;
|
|
62
|
+
};
|
|
63
|
+
"agent.permission_resolved": {
|
|
64
|
+
agent: PluginHookAgent;
|
|
65
|
+
requestId: string;
|
|
66
|
+
resolution: AgentPermissionResponse;
|
|
67
|
+
};
|
|
68
|
+
"agent.archived": {
|
|
69
|
+
agent: PluginHookAgent;
|
|
70
|
+
archivedAt: string;
|
|
71
|
+
};
|
|
72
|
+
"agent.created": {
|
|
73
|
+
agent: PluginHookAgent;
|
|
74
|
+
};
|
|
75
|
+
"agent.closed": {
|
|
76
|
+
agent: PluginHookAgent;
|
|
77
|
+
};
|
|
78
|
+
"workspace.created": {
|
|
79
|
+
workspace: PluginHookWorkspace;
|
|
80
|
+
};
|
|
81
|
+
"workspace.archived": {
|
|
82
|
+
workspace: PluginHookWorkspace;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export interface PluginBeforeRequests {
|
|
86
|
+
"agent.create": {
|
|
87
|
+
config: AgentSessionConfig;
|
|
88
|
+
env?: Record<string, string>;
|
|
89
|
+
};
|
|
90
|
+
"agent.session_open": PluginSessionOpenRequest;
|
|
91
|
+
"workspace.create": Omit<WorkspaceCreateRequest, "type" | "requestId">;
|
|
92
|
+
}
|
|
93
|
+
export interface PluginLifecycleRegistration {
|
|
94
|
+
on<Name extends keyof PluginLifecycleEvents>(name: Name, handler: (event: PluginLifecycleEvents[Name], context: PluginHookContext) => void | Promise<void>): () => void;
|
|
95
|
+
before<Name extends keyof PluginBeforeRequests>(name: Name, handler: (input: {
|
|
96
|
+
request: PluginBeforeRequests[Name];
|
|
97
|
+
}, context: PluginHookContext) => PluginBeforeRequests[Name] | void | Promise<PluginBeforeRequests[Name] | void>): () => void;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=lifecycle.d.ts.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** A model a model source contributes. Mirrors the daemon's provider model definition. */
|
|
2
|
+
export interface ModelSourceModel {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
aliases?: string[];
|
|
7
|
+
isSelectable?: boolean;
|
|
8
|
+
isDefault?: boolean;
|
|
9
|
+
contextWindowMaxTokens?: number;
|
|
10
|
+
thinkingOptions?: Array<{
|
|
11
|
+
id: string;
|
|
12
|
+
label: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
isDefault?: boolean;
|
|
15
|
+
}>;
|
|
16
|
+
defaultThinkingOptionId?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface ModelSourceRequest {
|
|
19
|
+
/** The provider being listed: `providerId` itself or a profile that extends it. */
|
|
20
|
+
providerId: string;
|
|
21
|
+
/** The provider's `env` from Mateo config. The plugin process already has the daemon env. */
|
|
22
|
+
env: Record<string, string>;
|
|
23
|
+
/** The provider's own list, before config `models`/`additionalModels` apply. */
|
|
24
|
+
baseModels: ModelSourceModel[];
|
|
25
|
+
/** True when the user asked for a refresh; bypass any cache. */
|
|
26
|
+
force: boolean;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* How a model source result combines with the provider's list:
|
|
30
|
+
* - `append` adds result IDs the provider's own list lacks.
|
|
31
|
+
* - `replace` swaps the provider's own list for the result. Config `models`/`additionalModels`
|
|
32
|
+
* and profile models still apply on top.
|
|
33
|
+
* - `exclusive` swaps the list like `replace` and also skips config `models`/`additionalModels`
|
|
34
|
+
* and profile models, so the result is the whole list.
|
|
35
|
+
*/
|
|
36
|
+
export type ModelSourceMode = "replace" | "append" | "exclusive";
|
|
37
|
+
/**
|
|
38
|
+
* What `list` returns. An array uses the registered mode; `{ mode, models }` picks the mode for
|
|
39
|
+
* this call, for example from a plugin setting. `null` or no models leaves the list unchanged.
|
|
40
|
+
*/
|
|
41
|
+
export type ModelSourceResult = ModelSourceModel[] | {
|
|
42
|
+
mode: ModelSourceMode;
|
|
43
|
+
models: ModelSourceModel[];
|
|
44
|
+
} | null;
|
|
45
|
+
/**
|
|
46
|
+
* Contributes models to an existing provider and the profiles that extend it. Mateo addition.
|
|
47
|
+
* Saving any of the plugin's settings re-lists the providers its sources extend.
|
|
48
|
+
*/
|
|
49
|
+
export interface ModelSourceRegistration {
|
|
50
|
+
id: string;
|
|
51
|
+
providerId: string;
|
|
52
|
+
mode: ModelSourceMode;
|
|
53
|
+
list(request: ModelSourceRequest): Promise<ModelSourceResult> | ModelSourceResult;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=models.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare function isWindowsCommandScript(executablePath: string): boolean;
|
|
2
|
+
/**
|
|
3
|
+
* When spawning with `shell: true` on Windows, the command is passed to
|
|
4
|
+
* `cmd.exe /d /s /c "command args"`. The `/s` strips outer quotes, so a
|
|
5
|
+
* command path with spaces (e.g. `C:\Program Files\...`) is split at the
|
|
6
|
+
* space. Wrapping it in quotes produces the correct `"C:\Program Files\..." args`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function quoteWindowsCommand(command: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* `spawn(..., { shell: true })` on Windows also passes argv through `cmd.exe`.
|
|
11
|
+
* Any argument containing spaces must be quoted or it will be split before the
|
|
12
|
+
* child process sees it.
|
|
13
|
+
*/
|
|
14
|
+
export declare function quoteWindowsArgument(argument: string): string;
|
|
15
|
+
//# sourceMappingURL=windows-command.d.ts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { extname } from "node:path";
|
|
2
|
+
export function isWindowsCommandScript(executablePath) {
|
|
3
|
+
const extension = extname(executablePath).toLowerCase();
|
|
4
|
+
return process.platform === "win32" && (extension === ".cmd" || extension === ".bat");
|
|
5
|
+
}
|
|
6
|
+
function escapeWindowsCmdValue(value) {
|
|
7
|
+
if (process.platform !== "win32")
|
|
8
|
+
return value;
|
|
9
|
+
const isQuoted = value.startsWith('"') && value.endsWith('"');
|
|
10
|
+
const unquoted = isQuoted ? value.slice(1, -1) : value;
|
|
11
|
+
// Do NOT double `%` here. cmd.exe only collapses `%%` → `%` inside batch
|
|
12
|
+
// files; on the command line / `cmd /c "..."` `%%` stays literal, which
|
|
13
|
+
// breaks args like git's `--format=%(refname)` (git treats `%%` as the
|
|
14
|
+
// escape for a literal `%`, so the format atoms become literals).
|
|
15
|
+
const escaped = unquoted.replace(/([&|^<>()!])/g, "^$1");
|
|
16
|
+
if (isQuoted || /[\s"]/u.test(unquoted)) {
|
|
17
|
+
const quoted = escaped
|
|
18
|
+
.replace(/(\\*)"/g, (_match, slashes) => `${slashes}${slashes}\\"`)
|
|
19
|
+
.replace(/\\+$/u, (slashes) => `${slashes}${slashes}`);
|
|
20
|
+
return `"${quoted}"`;
|
|
21
|
+
}
|
|
22
|
+
return escaped;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* When spawning with `shell: true` on Windows, the command is passed to
|
|
26
|
+
* `cmd.exe /d /s /c "command args"`. The `/s` strips outer quotes, so a
|
|
27
|
+
* command path with spaces (e.g. `C:\Program Files\...`) is split at the
|
|
28
|
+
* space. Wrapping it in quotes produces the correct `"C:\Program Files\..." args`.
|
|
29
|
+
*/
|
|
30
|
+
export function quoteWindowsCommand(command) {
|
|
31
|
+
return escapeWindowsCmdValue(command);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* `spawn(..., { shell: true })` on Windows also passes argv through `cmd.exe`.
|
|
35
|
+
* Any argument containing spaces must be quoted or it will be split before the
|
|
36
|
+
* child process sees it.
|
|
37
|
+
*/
|
|
38
|
+
export function quoteWindowsArgument(argument) {
|
|
39
|
+
return escapeWindowsCmdValue(argument);
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=windows-command.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type ChildProcess, type ChildProcessWithoutNullStreams, type SpawnOptions } from "node:child_process";
|
|
2
|
+
export interface ExecCommandOptions {
|
|
3
|
+
env?: NodeJS.ProcessEnv;
|
|
4
|
+
cwd?: string;
|
|
5
|
+
encoding?: BufferEncoding;
|
|
6
|
+
killSignal?: NodeJS.Signals;
|
|
7
|
+
timeout?: number;
|
|
8
|
+
maxBuffer?: number;
|
|
9
|
+
shell?: boolean | string;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}
|
|
12
|
+
interface ExecCommandResult {
|
|
13
|
+
stdout: string;
|
|
14
|
+
stderr: string;
|
|
15
|
+
}
|
|
16
|
+
/** Launch a CLI with Windows command-script handling and argv quoting. The caller owns env. */
|
|
17
|
+
export declare function spawnProcess(command: string, args: string[], options: SpawnOptions & {
|
|
18
|
+
stdio: "pipe";
|
|
19
|
+
}): ChildProcessWithoutNullStreams;
|
|
20
|
+
export declare function spawnProcess(command: string, args: string[], options?: SpawnOptions): ChildProcess;
|
|
21
|
+
export declare function execCommand(command: string, args: string[], options?: ExecCommandOptions): Promise<ExecCommandResult>;
|
|
22
|
+
/** Force-stop a CLI, including descendants behind Windows command-script launchers. */
|
|
23
|
+
export declare function terminateProcess(child: ChildProcess, signal?: NodeJS.Signals): Promise<void>;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=process.d.ts.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { execFile, spawn, } from "node:child_process";
|
|
2
|
+
import { extname } from "node:path";
|
|
3
|
+
import { promisify } from "node:util";
|
|
4
|
+
import { isWindowsCommandScript, quoteWindowsArgument, quoteWindowsCommand, } from "./process-internal/windows-command.js";
|
|
5
|
+
const execFileAsync = promisify(execFile);
|
|
6
|
+
function hasPathSeparator(value) {
|
|
7
|
+
return value.includes("/") || value.includes("\\");
|
|
8
|
+
}
|
|
9
|
+
function shouldUseWindowsShell(command, requestedShell) {
|
|
10
|
+
if (isWindowsCommandScript(command)) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
if (requestedShell !== undefined) {
|
|
14
|
+
return requestedShell;
|
|
15
|
+
}
|
|
16
|
+
return process.platform === "win32" && !hasPathSeparator(command) && !extname(command);
|
|
17
|
+
}
|
|
18
|
+
export function spawnProcess(command, args, options) {
|
|
19
|
+
const spawnOptions = options ?? {};
|
|
20
|
+
const isWindows = process.platform === "win32";
|
|
21
|
+
const shell = shouldUseWindowsShell(command, spawnOptions.shell);
|
|
22
|
+
const shouldQuoteForShell = isWindows && shell !== false;
|
|
23
|
+
const resolvedCommand = shouldQuoteForShell ? quoteWindowsCommand(command) : command;
|
|
24
|
+
const resolvedArgs = shouldQuoteForShell ? args.map(quoteWindowsArgument) : args;
|
|
25
|
+
return spawn(resolvedCommand, resolvedArgs, {
|
|
26
|
+
...spawnOptions,
|
|
27
|
+
env: options?.env,
|
|
28
|
+
shell,
|
|
29
|
+
signal: options?.signal,
|
|
30
|
+
windowsHide: true,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
export async function execCommand(command, args, options) {
|
|
34
|
+
const isWindows = process.platform === "win32";
|
|
35
|
+
const shell = shouldUseWindowsShell(command, options?.shell);
|
|
36
|
+
const shouldQuoteForShell = isWindows && shell !== false;
|
|
37
|
+
const resolvedCommand = shouldQuoteForShell ? quoteWindowsCommand(command) : command;
|
|
38
|
+
const resolvedArgs = shouldQuoteForShell ? args.map(quoteWindowsArgument) : args;
|
|
39
|
+
return execFileAsync(resolvedCommand, resolvedArgs, {
|
|
40
|
+
cwd: options?.cwd,
|
|
41
|
+
env: options?.env,
|
|
42
|
+
encoding: options?.encoding ?? "utf8",
|
|
43
|
+
signal: options?.signal,
|
|
44
|
+
killSignal: options?.killSignal,
|
|
45
|
+
timeout: options?.timeout,
|
|
46
|
+
maxBuffer: options?.maxBuffer,
|
|
47
|
+
shell,
|
|
48
|
+
windowsHide: true,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/** Force-stop a CLI, including descendants behind Windows command-script launchers. */
|
|
52
|
+
export async function terminateProcess(child, signal = "SIGKILL") {
|
|
53
|
+
if (process.platform !== "win32") {
|
|
54
|
+
child.kill(signal);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (child.pid === undefined)
|
|
58
|
+
return;
|
|
59
|
+
try {
|
|
60
|
+
await execCommand("taskkill.exe", ["/PID", String(child.pid), "/T", "/F"], {
|
|
61
|
+
shell: false,
|
|
62
|
+
timeout: 5000,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
// The process can finish between its close check and taskkill.
|
|
67
|
+
if (!(error instanceof Error && "code" in error && error.code === 128))
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=process.js.map
|