@caplets/core 0.18.8 → 0.19.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/dist/attach/options.d.ts +10 -0
- package/dist/attach/server.d.ts +5 -0
- package/dist/caplet-files-bundle.d.ts +415 -0
- package/dist/caplet-files.d.ts +3 -266
- package/dist/caplet-source/bundle.d.ts +7 -0
- package/dist/caplet-source/filesystem.d.ts +7 -0
- package/dist/caplet-source/filesystem.js +2 -0
- package/dist/caplet-source/index.d.ts +4 -0
- package/dist/caplet-source/parse.d.ts +35 -0
- package/dist/caplet-source/types.d.ts +9 -0
- package/dist/caplet-source.js +11231 -0
- package/dist/cli/commands.d.ts +9 -2
- package/dist/cli/doctor.d.ts +18 -0
- package/dist/cli/setup-caplet.d.ts +12 -0
- package/dist/cli/setup.d.ts +23 -0
- package/dist/cli.d.ts +9 -1
- package/dist/cloud/apply.d.ts +36 -0
- package/dist/cloud/client.d.ts +30 -0
- package/dist/cloud/presence.d.ts +29 -0
- package/dist/cloud/project-root.d.ts +2 -0
- package/dist/cloud/runtime-adapter.d.ts +23 -0
- package/dist/cloud/runtime-http.d.ts +6 -0
- package/dist/cloud/sync.d.ts +10 -0
- package/dist/cloud-auth/client.d.ts +42 -0
- package/dist/cloud-auth/errors.d.ts +11 -0
- package/dist/cloud-auth/open-url.d.ts +7 -0
- package/dist/cloud-auth/store.d.ts +35 -0
- package/dist/cloud-auth/types.d.ts +66 -0
- package/dist/{completion-DvWQk5qR.js → completion-brgziz4L.js} +32 -6
- package/dist/config-runtime.d.ts +174 -0
- package/dist/config-runtime.js +392 -0
- package/dist/config.d.ts +42 -0
- package/dist/filesystem-Kkg32TOJ.js +66 -0
- package/dist/generated-tool-input-schema.d.ts +9 -9
- package/dist/generated-tool-input-schema.js +161 -1
- package/dist/index.d.ts +35 -0
- package/dist/index.js +6132 -3196
- package/dist/native/options.d.ts +22 -3
- package/dist/native/remote.d.ts +2 -1
- package/dist/native/service.d.ts +7 -3
- package/dist/native.js +2 -430
- package/dist/project-binding/attach.d.ts +46 -0
- package/dist/project-binding/errors.d.ts +17 -0
- package/dist/project-binding/gitignore.d.ts +5 -0
- package/dist/project-binding/mutagen.d.ts +65 -0
- package/dist/project-binding/routes.d.ts +9 -0
- package/dist/project-binding/session.d.ts +82 -0
- package/dist/project-binding/sync-filter.d.ts +19 -0
- package/dist/project-binding/sync-size.d.ts +27 -0
- package/dist/project-binding/transport.d.ts +21 -0
- package/dist/project-binding/types.d.ts +31 -0
- package/dist/project-binding/workspaces.d.ts +60 -0
- package/dist/remote/options.d.ts +42 -0
- package/dist/remote/selection.d.ts +26 -0
- package/dist/remote-control/types.d.ts +1 -1
- package/dist/runtime-plan/features.d.ts +7 -0
- package/dist/runtime-plan/index.d.ts +4 -0
- package/dist/runtime-plan/planner.d.ts +5 -0
- package/dist/runtime-plan/resources.d.ts +11 -0
- package/dist/runtime-plan/types.d.ts +82 -0
- package/dist/runtime-plan.js +275 -0
- package/dist/{generated-tool-input-schema-MbYF5jMW.js → schemas-BZ6BBrh7.js} +1 -161
- package/dist/serve/daemon/config.d.ts +8 -0
- package/dist/serve/daemon/index.d.ts +16 -0
- package/dist/serve/daemon/paths.d.ts +3 -0
- package/dist/serve/daemon/platform-darwin.d.ts +2 -0
- package/dist/serve/daemon/platform-linux.d.ts +2 -0
- package/dist/serve/daemon/platform-windows.d.ts +2 -0
- package/dist/serve/daemon/platform.d.ts +9 -0
- package/dist/serve/daemon/process.d.ts +5 -0
- package/dist/serve/daemon/types.d.ts +86 -0
- package/dist/serve/http.d.ts +8 -0
- package/dist/serve/index.d.ts +5 -1
- package/dist/serve/native-session.d.ts +19 -0
- package/dist/serve/options.d.ts +1 -0
- package/dist/server/options.d.ts +1 -1
- package/dist/{options--RoZwWjs.js → service-BXcE4Rv8.js} +9932 -2218
- package/dist/setup/hash.d.ts +3 -0
- package/dist/setup/local-store.d.ts +34 -0
- package/dist/setup/runner.d.ts +40 -0
- package/dist/setup/types.d.ts +52 -0
- package/dist/tools.d.ts +17 -2
- package/dist/validation-BBG4skZf.js +153 -0
- package/package.json +21 -5
package/dist/native/options.d.ts
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type CapletsServerEnv, type CapletsServerInput } from "../server/options";
|
|
2
|
+
import { type CapletsRemoteEnv } from "../remote/options";
|
|
3
|
+
type CapletsMode = "auto" | "local" | "remote" | "cloud";
|
|
2
4
|
export type NativeCapletsMode = CapletsMode;
|
|
3
5
|
export type NativeRemoteCapletsOptions = {
|
|
4
6
|
pollIntervalMs?: number;
|
|
5
7
|
fetch?: typeof fetch;
|
|
8
|
+
cloud?: NativeCloudPresenceInput;
|
|
9
|
+
};
|
|
10
|
+
export type NativeCloudPresenceInput = {
|
|
11
|
+
url?: string;
|
|
12
|
+
accessToken?: string;
|
|
13
|
+
workspaceId?: string;
|
|
14
|
+
projectRoot?: string;
|
|
15
|
+
heartbeatIntervalMs?: number;
|
|
6
16
|
};
|
|
7
17
|
export type NativeCapletsServiceResolutionInput = {
|
|
8
18
|
mode?: NativeCapletsMode;
|
|
9
19
|
server?: CapletsServerInput;
|
|
10
20
|
remote?: NativeRemoteCapletsOptions;
|
|
11
21
|
};
|
|
12
|
-
export type NativeCapletsEnv = CapletsServerEnv;
|
|
22
|
+
export type NativeCapletsEnv = CapletsServerEnv & CapletsRemoteEnv;
|
|
13
23
|
export type NativeRemoteAuthOptions = {
|
|
14
24
|
enabled: false;
|
|
15
25
|
user: string;
|
|
@@ -21,13 +31,22 @@ export type NativeRemoteAuthOptions = {
|
|
|
21
31
|
export type ResolvedNativeCapletsServiceOptions = {
|
|
22
32
|
mode: "local";
|
|
23
33
|
} | {
|
|
24
|
-
mode: "remote";
|
|
34
|
+
mode: "remote" | "cloud";
|
|
25
35
|
remote: {
|
|
26
36
|
url: URL;
|
|
27
37
|
auth: NativeRemoteAuthOptions;
|
|
28
38
|
pollIntervalMs: number;
|
|
29
39
|
requestInit: RequestInit;
|
|
40
|
+
cloud?: ResolvedNativeCloudPresenceOptions;
|
|
30
41
|
fetch?: typeof fetch;
|
|
31
42
|
};
|
|
32
43
|
};
|
|
33
44
|
export declare function resolveNativeCapletsServiceOptions(input?: NativeCapletsServiceResolutionInput, env?: NativeCapletsEnv): ResolvedNativeCapletsServiceOptions;
|
|
45
|
+
export type ResolvedNativeCloudPresenceOptions = {
|
|
46
|
+
url: URL;
|
|
47
|
+
accessToken: string;
|
|
48
|
+
workspaceId: string;
|
|
49
|
+
projectRoot?: string;
|
|
50
|
+
heartbeatIntervalMs: number;
|
|
51
|
+
};
|
|
52
|
+
export {};
|
package/dist/native/remote.d.ts
CHANGED
|
@@ -13,12 +13,13 @@ export type RemoteCapletsClient = {
|
|
|
13
13
|
close(): Promise<void>;
|
|
14
14
|
};
|
|
15
15
|
export type RemoteCapletsClientOptions = ResolvedNativeCapletsServiceOptions & {
|
|
16
|
-
mode: "remote";
|
|
16
|
+
mode: "remote" | "cloud";
|
|
17
17
|
};
|
|
18
18
|
export type RemoteNativeCapletsServiceOptions = {
|
|
19
19
|
client: RemoteCapletsClient;
|
|
20
20
|
clientFactory?: () => RemoteCapletsClient;
|
|
21
21
|
pollIntervalMs: number;
|
|
22
|
+
authKind?: "self_hosted_remote" | "hosted_cloud";
|
|
22
23
|
writeErr?: (value: string) => void;
|
|
23
24
|
};
|
|
24
25
|
export declare function createSdkRemoteCapletsClient(options: RemoteCapletsClientOptions["remote"]): RemoteCapletsClient;
|
package/dist/native/service.d.ts
CHANGED
|
@@ -10,9 +10,7 @@ export type NativeCapletsServiceOptions = NativeCapletsServiceResolutionInput &
|
|
|
10
10
|
watchDebounceMs?: number;
|
|
11
11
|
watch?: boolean;
|
|
12
12
|
writeErr?: (value: string) => void;
|
|
13
|
-
remoteClientFactory?: (options:
|
|
14
|
-
mode: "remote";
|
|
15
|
-
}>["remote"]) => RemoteCapletsClient;
|
|
13
|
+
remoteClientFactory?: (options: ResolvedNativeRemoteOptions) => RemoteCapletsClient;
|
|
16
14
|
localServiceFactory?: (options: LocalNativeCapletsServiceOptions) => NativeCapletsService;
|
|
17
15
|
};
|
|
18
16
|
export type NativeCapletTool = {
|
|
@@ -33,7 +31,13 @@ export type NativeCapletsService = {
|
|
|
33
31
|
close(): Promise<void>;
|
|
34
32
|
};
|
|
35
33
|
export declare function createNativeCapletsService(options?: NativeCapletsServiceOptions): NativeCapletsService;
|
|
34
|
+
export declare function resetNativeProjectBindingFallbackWarningForTests(): void;
|
|
36
35
|
type LocalNativeCapletsServiceOptions = NativeCapletsServiceOptions & {
|
|
37
36
|
configLoader?: (configPath: string, projectConfigPath: string) => CapletsConfig;
|
|
38
37
|
};
|
|
38
|
+
type ResolvedNativeRemoteOptions = Extract<Exclude<ReturnType<typeof resolveNativeCapletsServiceOptions>, {
|
|
39
|
+
mode: "local";
|
|
40
|
+
}>, {
|
|
41
|
+
remote: unknown;
|
|
42
|
+
}>["remote"];
|
|
39
43
|
export {};
|
package/dist/native.js
CHANGED
|
@@ -1,433 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
//#region src/native/options.ts
|
|
4
|
-
const DEFAULT_POLL_INTERVAL_MS = 3e4;
|
|
5
|
-
function resolveNativeCapletsServiceOptions(input = {}, env = process.env) {
|
|
6
|
-
if (resolveCapletsMode({
|
|
7
|
-
...input.mode ? { mode: input.mode } : {},
|
|
8
|
-
...input.server?.url ? { serverUrl: input.server.url } : {}
|
|
9
|
-
}, env).mode === "local") return { mode: "local" };
|
|
10
|
-
const serverFetch = input.remote?.fetch ?? input.server?.fetch;
|
|
11
|
-
const server = resolveCapletsServer({
|
|
12
|
-
...input.server,
|
|
13
|
-
...serverFetch ? { fetch: serverFetch } : {}
|
|
14
|
-
}, env);
|
|
15
|
-
return {
|
|
16
|
-
mode: "remote",
|
|
17
|
-
remote: {
|
|
18
|
-
url: mcpUrlForBase(server.baseUrl),
|
|
19
|
-
auth: server.auth,
|
|
20
|
-
pollIntervalMs: parsePollInterval(input.remote?.pollIntervalMs),
|
|
21
|
-
requestInit: server.requestInit,
|
|
22
|
-
...server.fetch ? { fetch: server.fetch } : {}
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
function parsePollInterval(value) {
|
|
27
|
-
if (value === void 0) return DEFAULT_POLL_INTERVAL_MS;
|
|
28
|
-
if (!Number.isInteger(value) || value < 1e3) throw new CapletsError("REQUEST_INVALID", "remote.pollIntervalMs must be an integer >= 1000.");
|
|
29
|
-
return value;
|
|
30
|
-
}
|
|
31
|
-
//#endregion
|
|
32
|
-
//#region src/native/tools.ts
|
|
33
|
-
function nativeCapletToolName(capletId) {
|
|
34
|
-
return `caplets_${capletId.replace(/_/g, "__").replace(/-/g, "_")}`;
|
|
35
|
-
}
|
|
36
|
-
function nativeCapletsSystemGuidance(toolNames) {
|
|
37
|
-
return [
|
|
38
|
-
"## Caplets Native Tools",
|
|
39
|
-
"",
|
|
40
|
-
"Caplets tools expose configured capability domains through progressive discovery.",
|
|
41
|
-
"",
|
|
42
|
-
"Available Caplets native tools:",
|
|
43
|
-
toolNames.length > 0 ? toolNames.map((tool) => `- ${tool}`).join("\n") : "- none",
|
|
44
|
-
"",
|
|
45
|
-
"Flow: get_caplet when the domain is unfamiliar; use search_tools/list_tools for actions; MCP-backed Caplets may also expose resources, prompts, and completions in their tool schema.",
|
|
46
|
-
"Use fields on call_tool when a non-GraphQL downstream outputSchema allows selecting only needed structured paths."
|
|
47
|
-
].join("\n");
|
|
48
|
-
}
|
|
49
|
-
function nativeCapletPromptGuidance(toolName, caplet) {
|
|
50
|
-
return caplet.backend === "mcp" ? [`Use ${toolName} for the ${caplet.name} Caplet capability domain.`, "Prefer resources for readable context, prompts for reusable workflows, and tools for actions."] : [`Use ${toolName} for the ${caplet.name} Caplet capability domain.`];
|
|
51
|
-
}
|
|
52
|
-
function nativeCapletToolDescription(toolName, caplet) {
|
|
53
|
-
return [
|
|
54
|
-
capabilityDescription(caplet),
|
|
55
|
-
"",
|
|
56
|
-
`Native tool name: ${toolName}`,
|
|
57
|
-
`Original Caplet ID: ${caplet.server}`
|
|
58
|
-
].join("\n");
|
|
59
|
-
}
|
|
60
|
-
//#endregion
|
|
61
|
-
//#region src/native/remote.ts
|
|
62
|
-
function createSdkRemoteCapletsClient(options) {
|
|
63
|
-
const client = new Client({
|
|
64
|
-
name: "caplets-native",
|
|
65
|
-
version: "1.0.0"
|
|
66
|
-
}, { capabilities: {} });
|
|
67
|
-
const transport = new StreamableHTTPClientTransport(options.url, {
|
|
68
|
-
requestInit: options.requestInit,
|
|
69
|
-
...options.fetch ? { fetch: options.fetch } : {}
|
|
70
|
-
});
|
|
71
|
-
const ready = client.connect(transport);
|
|
72
|
-
const readyObserved = ready.catch(() => void 0);
|
|
73
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
74
|
-
client.setNotificationHandler(ToolListChangedNotificationSchema, () => {
|
|
75
|
-
for (const listener of listeners) listener();
|
|
76
|
-
});
|
|
77
|
-
return {
|
|
78
|
-
async listTools() {
|
|
79
|
-
await ready;
|
|
80
|
-
return ((await client.listTools()).tools ?? []).map((tool) => ({
|
|
81
|
-
name: tool.name,
|
|
82
|
-
...tool.title ? { title: tool.title } : {},
|
|
83
|
-
...tool.description ? { description: tool.description } : {},
|
|
84
|
-
...tool.inputSchema ? { inputSchema: tool.inputSchema } : {}
|
|
85
|
-
}));
|
|
86
|
-
},
|
|
87
|
-
async callTool(name, args) {
|
|
88
|
-
await ready;
|
|
89
|
-
const toolArguments = args && typeof args === "object" && !Array.isArray(args) ? args : void 0;
|
|
90
|
-
return await client.callTool({
|
|
91
|
-
name,
|
|
92
|
-
arguments: toolArguments
|
|
93
|
-
});
|
|
94
|
-
},
|
|
95
|
-
onToolsChanged(listener) {
|
|
96
|
-
listeners.add(listener);
|
|
97
|
-
return () => listeners.delete(listener);
|
|
98
|
-
},
|
|
99
|
-
async close() {
|
|
100
|
-
listeners.clear();
|
|
101
|
-
await readyObserved;
|
|
102
|
-
await transport.terminateSession().catch(() => void 0);
|
|
103
|
-
await client.close();
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
var RemoteNativeCapletsService = class {
|
|
108
|
-
options;
|
|
109
|
-
tools = [];
|
|
110
|
-
listeners = /* @__PURE__ */ new Set();
|
|
111
|
-
clientFactory;
|
|
112
|
-
client;
|
|
113
|
-
unsubscribeRemote;
|
|
114
|
-
pollTimer;
|
|
115
|
-
closed = false;
|
|
116
|
-
resetInFlight;
|
|
117
|
-
constructor(options) {
|
|
118
|
-
this.options = options;
|
|
119
|
-
this.client = options.client;
|
|
120
|
-
this.clientFactory = options.clientFactory ?? (() => options.client);
|
|
121
|
-
this.unsubscribeRemote = this.subscribeRemote(this.client);
|
|
122
|
-
this.pollTimer = setInterval(() => {
|
|
123
|
-
this.reload();
|
|
124
|
-
}, options.pollIntervalMs);
|
|
125
|
-
this.pollTimer.unref?.();
|
|
126
|
-
}
|
|
127
|
-
listTools() {
|
|
128
|
-
return [...this.tools];
|
|
129
|
-
}
|
|
130
|
-
async execute(capletId, request) {
|
|
131
|
-
try {
|
|
132
|
-
return await this.client.callTool(capletId, request);
|
|
133
|
-
} catch (error) {
|
|
134
|
-
if (isAuthFailure(error)) throw remoteAuthError();
|
|
135
|
-
if (isSessionFailure(error)) {
|
|
136
|
-
if (!await this.resetClient() || this.closed) throw error;
|
|
137
|
-
try {
|
|
138
|
-
return await this.client.callTool(capletId, request);
|
|
139
|
-
} catch (retryError) {
|
|
140
|
-
if (isAuthFailure(retryError)) throw remoteAuthError();
|
|
141
|
-
throw retryError;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
throw error;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
async reload() {
|
|
148
|
-
if (this.closed) return false;
|
|
149
|
-
try {
|
|
150
|
-
await this.reloadFromClient();
|
|
151
|
-
return true;
|
|
152
|
-
} catch (error) {
|
|
153
|
-
if (isSessionFailure(error)) try {
|
|
154
|
-
if (!await this.resetClient() || this.closed) return false;
|
|
155
|
-
await this.reloadFromClient();
|
|
156
|
-
return !this.closed;
|
|
157
|
-
} catch (retryError) {
|
|
158
|
-
this.warn(`Could not reload remote Caplets tools: ${errorMessage$2(retryError)}\n`);
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
this.warn(`Could not reload remote Caplets tools: ${errorMessage$2(error)}\n`);
|
|
162
|
-
return false;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
onToolsChanged(listener) {
|
|
166
|
-
this.listeners.add(listener);
|
|
167
|
-
return () => this.listeners.delete(listener);
|
|
168
|
-
}
|
|
169
|
-
async close() {
|
|
170
|
-
if (this.closed) return;
|
|
171
|
-
this.closed = true;
|
|
172
|
-
clearInterval(this.pollTimer);
|
|
173
|
-
this.unsubscribeRemote();
|
|
174
|
-
this.listeners.clear();
|
|
175
|
-
await this.client.close();
|
|
176
|
-
}
|
|
177
|
-
async reloadFromClient() {
|
|
178
|
-
const tools = (await this.client.listTools()).map(remoteToolToNativeTool);
|
|
179
|
-
const changed = JSON.stringify(tools) !== JSON.stringify(this.tools);
|
|
180
|
-
this.tools = tools;
|
|
181
|
-
if (changed) this.emitToolsChanged();
|
|
182
|
-
}
|
|
183
|
-
subscribeRemote(client) {
|
|
184
|
-
return client.onToolsChanged(() => {
|
|
185
|
-
this.reload();
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
async resetClient() {
|
|
189
|
-
if (this.resetInFlight) return await this.resetInFlight;
|
|
190
|
-
this.resetInFlight = this.doResetClient();
|
|
191
|
-
try {
|
|
192
|
-
return await this.resetInFlight;
|
|
193
|
-
} finally {
|
|
194
|
-
this.resetInFlight = void 0;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
async doResetClient() {
|
|
198
|
-
if (this.closed) return false;
|
|
199
|
-
this.unsubscribeRemote();
|
|
200
|
-
await this.client.close().catch(() => void 0);
|
|
201
|
-
if (this.closed) return false;
|
|
202
|
-
const nextClient = this.clientFactory();
|
|
203
|
-
if (this.closed) {
|
|
204
|
-
await nextClient.close().catch(() => void 0);
|
|
205
|
-
return false;
|
|
206
|
-
}
|
|
207
|
-
this.client = nextClient;
|
|
208
|
-
this.unsubscribeRemote = this.subscribeRemote(this.client);
|
|
209
|
-
return true;
|
|
210
|
-
}
|
|
211
|
-
emitToolsChanged() {
|
|
212
|
-
const tools = this.listTools();
|
|
213
|
-
for (const listener of this.listeners) listener(tools);
|
|
214
|
-
}
|
|
215
|
-
warn(message) {
|
|
216
|
-
this.options.writeErr?.(message);
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
function remoteToolToNativeTool(tool) {
|
|
220
|
-
const toolName = nativeCapletToolName(tool.name);
|
|
221
|
-
const inputSchema = isPlainObject(tool.inputSchema) ? tool.inputSchema : generatedToolInputJsonSchemaForCaplet({ backend: "tool" });
|
|
222
|
-
return {
|
|
223
|
-
caplet: tool.name,
|
|
224
|
-
toolName,
|
|
225
|
-
title: tool.title ?? tool.name,
|
|
226
|
-
description: [
|
|
227
|
-
tool.description ?? "Remote Caplets tool.",
|
|
228
|
-
"",
|
|
229
|
-
`Native tool name: ${toolName}`,
|
|
230
|
-
`Remote Caplet ID: ${tool.name}`
|
|
231
|
-
].join("\n"),
|
|
232
|
-
promptGuidance: [`Use ${toolName} through the remote Caplets service.`],
|
|
233
|
-
inputSchema,
|
|
234
|
-
operationNames: operationNamesFromSchema(inputSchema)
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
function operationNamesFromSchema(schema) {
|
|
238
|
-
const properties = schema.properties;
|
|
239
|
-
if (!isPlainObject(properties)) return [...operations];
|
|
240
|
-
const operation = properties.operation;
|
|
241
|
-
if (!isPlainObject(operation) || !Array.isArray(operation.enum)) return [...operations];
|
|
242
|
-
return operation.enum.filter((value) => typeof value === "string");
|
|
243
|
-
}
|
|
244
|
-
function isPlainObject(value) {
|
|
245
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
246
|
-
}
|
|
247
|
-
function errorMessage$2(error) {
|
|
248
|
-
return error instanceof Error ? error.message : String(error);
|
|
249
|
-
}
|
|
250
|
-
function remoteAuthError() {
|
|
251
|
-
return new CapletsError("AUTH_FAILED", "Remote Caplets authentication failed; check CAPLETS_SERVER_USER and CAPLETS_SERVER_PASSWORD.");
|
|
252
|
-
}
|
|
253
|
-
function isSessionFailure(error) {
|
|
254
|
-
const message = errorMessage$2(error).toLowerCase();
|
|
255
|
-
return /session|transport|connection|connect|closed|invalid/u.test(message);
|
|
256
|
-
}
|
|
257
|
-
function isAuthFailure(error) {
|
|
258
|
-
const candidate = error;
|
|
259
|
-
const status = typeof candidate?.status === "number" ? candidate.status : void 0;
|
|
260
|
-
const statusCode = typeof candidate?.statusCode === "number" ? candidate.statusCode : void 0;
|
|
261
|
-
const code = typeof candidate?.code === "number" ? candidate.code : void 0;
|
|
262
|
-
if (status === 401 || status === 403 || statusCode === 401 || statusCode === 403 || code === 401 || code === 403) return true;
|
|
263
|
-
return /\b(401|403|unauthorized|forbidden)\b/iu.test(errorMessage$2(error));
|
|
264
|
-
}
|
|
265
|
-
//#endregion
|
|
266
|
-
//#region src/native/service.ts
|
|
267
|
-
function createNativeCapletsService(options = {}) {
|
|
268
|
-
const resolved = resolveNativeCapletsServiceOptions(options);
|
|
269
|
-
if (resolved.mode === "remote") {
|
|
270
|
-
const localOptions = {
|
|
271
|
-
...options,
|
|
272
|
-
mode: "local",
|
|
273
|
-
configLoader: createLocalOverlayConfigLoader(options)
|
|
274
|
-
};
|
|
275
|
-
const local = (options.localServiceFactory ?? createDefaultNativeCapletsService)(localOptions);
|
|
276
|
-
try {
|
|
277
|
-
return new CompositeNativeCapletsService(new RemoteNativeCapletsService({
|
|
278
|
-
client: (options.remoteClientFactory ?? createSdkRemoteCapletsClient)(resolved.remote),
|
|
279
|
-
clientFactory: () => (options.remoteClientFactory ?? createSdkRemoteCapletsClient)(resolved.remote),
|
|
280
|
-
pollIntervalMs: resolved.remote.pollIntervalMs,
|
|
281
|
-
...options.writeErr ? { writeErr: options.writeErr } : {}
|
|
282
|
-
}), local, options);
|
|
283
|
-
} catch (error) {
|
|
284
|
-
local.close().catch((closeError) => {
|
|
285
|
-
writeErr(options, `Could not close local overlay Caplets service: ${errorMessage$1(closeError)}\n`);
|
|
286
|
-
});
|
|
287
|
-
throw error;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
return new DefaultNativeCapletsService(options);
|
|
291
|
-
}
|
|
292
|
-
var DefaultNativeCapletsService = class {
|
|
293
|
-
engine;
|
|
294
|
-
constructor(options) {
|
|
295
|
-
this.engine = new CapletsEngine({
|
|
296
|
-
...options,
|
|
297
|
-
writeErr: options.writeErr ?? (() => void 0)
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
listTools() {
|
|
301
|
-
return this.engine.enabledServers().map((caplet) => {
|
|
302
|
-
const toolName = nativeCapletToolName(caplet.server);
|
|
303
|
-
const inputSchema = generatedToolInputJsonSchemaForCaplet(caplet);
|
|
304
|
-
return {
|
|
305
|
-
caplet: caplet.server,
|
|
306
|
-
toolName,
|
|
307
|
-
title: caplet.name,
|
|
308
|
-
description: nativeCapletToolDescription(toolName, caplet),
|
|
309
|
-
promptGuidance: nativeCapletPromptGuidance(toolName, caplet),
|
|
310
|
-
inputSchema,
|
|
311
|
-
operationNames: [...inputSchema.properties.operation.enum]
|
|
312
|
-
};
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
async execute(capletId, request) {
|
|
316
|
-
return await this.engine.execute(capletId, request);
|
|
317
|
-
}
|
|
318
|
-
async reload() {
|
|
319
|
-
return await this.engine.reload();
|
|
320
|
-
}
|
|
321
|
-
onToolsChanged(listener) {
|
|
322
|
-
return this.engine.onReload(() => listener(this.listTools()));
|
|
323
|
-
}
|
|
324
|
-
async close() {
|
|
325
|
-
await this.engine.close();
|
|
326
|
-
}
|
|
327
|
-
};
|
|
328
|
-
function createDefaultNativeCapletsService(options) {
|
|
329
|
-
return new DefaultNativeCapletsService(options);
|
|
330
|
-
}
|
|
331
|
-
var CompositeNativeCapletsService = class {
|
|
332
|
-
remote;
|
|
333
|
-
local;
|
|
334
|
-
options;
|
|
335
|
-
listeners = /* @__PURE__ */ new Set();
|
|
336
|
-
unsubscribers;
|
|
337
|
-
tools = [];
|
|
338
|
-
closed = false;
|
|
339
|
-
batchingReload = false;
|
|
340
|
-
constructor(remote, local, options) {
|
|
341
|
-
this.remote = remote;
|
|
342
|
-
this.local = local;
|
|
343
|
-
this.options = options;
|
|
344
|
-
this.unsubscribers = [this.remote.onToolsChanged(() => this.updateMergedTools()), this.local.onToolsChanged(() => this.updateMergedTools())];
|
|
345
|
-
this.tools = this.mergeTools();
|
|
346
|
-
}
|
|
347
|
-
listTools() {
|
|
348
|
-
return [...this.tools];
|
|
349
|
-
}
|
|
350
|
-
async execute(capletId, request) {
|
|
351
|
-
if (this.local.listTools().some((tool) => tool.caplet === capletId)) return await this.local.execute(capletId, request);
|
|
352
|
-
return await this.remote.execute(capletId, request);
|
|
353
|
-
}
|
|
354
|
-
async reload() {
|
|
355
|
-
if (this.closed) return false;
|
|
356
|
-
this.batchingReload = true;
|
|
357
|
-
const remoteReloaded = await this.reloadChild(this.remote, "remote");
|
|
358
|
-
const localReloaded = await this.reloadChild(this.local, "local overlay");
|
|
359
|
-
this.batchingReload = false;
|
|
360
|
-
if (remoteReloaded === void 0 || localReloaded === void 0) return false;
|
|
361
|
-
this.updateMergedTools();
|
|
362
|
-
return remoteReloaded || localReloaded;
|
|
363
|
-
}
|
|
364
|
-
onToolsChanged(listener) {
|
|
365
|
-
this.listeners.add(listener);
|
|
366
|
-
return () => this.listeners.delete(listener);
|
|
367
|
-
}
|
|
368
|
-
async close() {
|
|
369
|
-
if (this.closed) return;
|
|
370
|
-
this.closed = true;
|
|
371
|
-
for (const unsubscribe of this.unsubscribers.splice(0)) unsubscribe();
|
|
372
|
-
this.listeners.clear();
|
|
373
|
-
await Promise.all([this.remote.close(), this.local.close()]);
|
|
374
|
-
}
|
|
375
|
-
updateMergedTools() {
|
|
376
|
-
if (this.closed || this.batchingReload) return;
|
|
377
|
-
const tools = this.mergeTools();
|
|
378
|
-
if (JSON.stringify(tools) === JSON.stringify(this.tools)) return;
|
|
379
|
-
this.tools = tools;
|
|
380
|
-
for (const listener of this.listeners) try {
|
|
381
|
-
listener(this.listTools());
|
|
382
|
-
} catch (error) {
|
|
383
|
-
writeErr(this.options, `Caplets tools-changed listener failed: ${errorMessage$1(error)}\n`);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
mergeTools() {
|
|
387
|
-
const localTools = this.local.listTools();
|
|
388
|
-
const localIds = new Set(localTools.map((tool) => tool.caplet));
|
|
389
|
-
return [...this.remote.listTools().filter((tool) => !localIds.has(tool.caplet)), ...localTools];
|
|
390
|
-
}
|
|
391
|
-
async reloadChild(service, label) {
|
|
392
|
-
try {
|
|
393
|
-
return await service.reload();
|
|
394
|
-
} catch (error) {
|
|
395
|
-
writeErr(this.options, `Could not reload composite Caplets tools from ${label}: ${errorMessage$1(error)}\n`);
|
|
396
|
-
return;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
};
|
|
400
|
-
function createLocalOverlayConfigLoader(options) {
|
|
401
|
-
let hasLoaded = false;
|
|
402
|
-
let previousWarnings = /* @__PURE__ */ new Set();
|
|
403
|
-
return (configPath, projectConfigPath) => {
|
|
404
|
-
let result;
|
|
405
|
-
try {
|
|
406
|
-
result = loadLocalOverlayConfigWithSources(configPath, projectConfigPath);
|
|
407
|
-
} catch (error) {
|
|
408
|
-
writeErr(options, `Caplets local overlay warning: Could not load local overlay config: ${errorMessage$1(error)}\n`);
|
|
409
|
-
if (hasLoaded) throw new CapletsError("CONFIG_INVALID", "Caplets local overlay reload failed; keeping last known-good config.", error);
|
|
410
|
-
hasLoaded = true;
|
|
411
|
-
return parseConfig({});
|
|
412
|
-
}
|
|
413
|
-
for (const warning of result.warnings) writeErr(options, `Caplets local overlay warning${typeof warning.path === "string" ? ` at ${warning.path}` : ""}: ${warning.message}\n`);
|
|
414
|
-
const warnings = new Set(result.warnings.map(warningKey));
|
|
415
|
-
if (hasLoaded && [...warnings].some((warning) => !previousWarnings.has(warning))) throw new CapletsError("CONFIG_INVALID", "Caplets local overlay reload produced new warnings; keeping last known-good config.");
|
|
416
|
-
previousWarnings = warnings;
|
|
417
|
-
hasLoaded = true;
|
|
418
|
-
return result.config;
|
|
419
|
-
};
|
|
420
|
-
}
|
|
421
|
-
function warningKey(warning) {
|
|
422
|
-
return `${warning.kind}\0${warning.path}\0${warning.message}`;
|
|
423
|
-
}
|
|
424
|
-
function writeErr(options, message) {
|
|
425
|
-
options.writeErr?.(message);
|
|
426
|
-
}
|
|
427
|
-
function errorMessage$1(error) {
|
|
428
|
-
return error instanceof Error ? error.message : String(error);
|
|
429
|
-
}
|
|
430
|
-
//#endregion
|
|
1
|
+
import { a as createSdkRemoteCapletsClient, c as nativeCapletToolName, i as RemoteNativeCapletsService, l as nativeCapletsSystemGuidance, o as nativeCapletPromptGuidance, r as resolveNativeCapletsServiceOptions, s as nativeCapletToolDescription, t as createNativeCapletsService } from "./service-BXcE4Rv8.js";
|
|
2
|
+
import { generatedToolInputJsonSchema, generatedToolInputSchema } from "./generated-tool-input-schema.js";
|
|
431
3
|
//#region src/native/process-cleanup.ts
|
|
432
4
|
function registerNativeCapletsProcessCleanup(service, options = {}) {
|
|
433
5
|
let closed = false;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ResolvedCapletsRemote } from "../remote/options";
|
|
2
|
+
import { type ProjectBindingSessionEvent } from "./session";
|
|
3
|
+
import type { ProjectBindingWebSocketFactory } from "./transport";
|
|
4
|
+
export type RawAttachOptions = {
|
|
5
|
+
remoteUrl?: string;
|
|
6
|
+
user?: string;
|
|
7
|
+
password?: string;
|
|
8
|
+
token?: string;
|
|
9
|
+
workspace?: string;
|
|
10
|
+
json?: boolean;
|
|
11
|
+
verbose?: boolean;
|
|
12
|
+
once?: boolean;
|
|
13
|
+
projectRoot?: string;
|
|
14
|
+
fetch?: typeof fetch;
|
|
15
|
+
};
|
|
16
|
+
export type ResolvedAttachOptions = {
|
|
17
|
+
projectRoot: string;
|
|
18
|
+
json: boolean;
|
|
19
|
+
verbose: boolean;
|
|
20
|
+
once: boolean;
|
|
21
|
+
remote: ResolvedCapletsRemote;
|
|
22
|
+
authMode: "self_hosted_remote" | "hosted_cloud";
|
|
23
|
+
selectedWorkspace?: string | undefined;
|
|
24
|
+
};
|
|
25
|
+
export declare function resolveAttachOptions(raw?: RawAttachOptions, env?: Record<string, string | undefined>): Promise<ResolvedAttachOptions>;
|
|
26
|
+
export declare function resolveAttachOptionsForRun(raw?: RawAttachOptions, env?: Record<string, string | undefined>): Promise<ResolvedAttachOptions>;
|
|
27
|
+
export declare function attachProjectOnce(raw?: RawAttachOptions, env?: Record<string, string | undefined>): Promise<{
|
|
28
|
+
ok: true;
|
|
29
|
+
projectRoot: string;
|
|
30
|
+
webSocketUrl: string;
|
|
31
|
+
}>;
|
|
32
|
+
export type AttachSessionEvent = ProjectBindingSessionEvent;
|
|
33
|
+
export declare function attachProjectSession(raw?: RawAttachOptions, env?: Record<string, string | undefined>, options?: {
|
|
34
|
+
heartbeatIntervalMs?: number | undefined;
|
|
35
|
+
signal?: AbortSignal | undefined;
|
|
36
|
+
webSocketFactory?: ProjectBindingWebSocketFactory | undefined;
|
|
37
|
+
onEvent?: (event: AttachSessionEvent) => void;
|
|
38
|
+
}): Promise<{
|
|
39
|
+
ok: true;
|
|
40
|
+
bindingId: string;
|
|
41
|
+
sessionId: string;
|
|
42
|
+
projectRoot: string;
|
|
43
|
+
projectFingerprint: string;
|
|
44
|
+
webSocketUrl: string;
|
|
45
|
+
ended: true;
|
|
46
|
+
}>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CapletsError } from "../errors";
|
|
2
|
+
export declare const PROJECT_BINDING_ERROR_CODES: readonly ["cloud_auth_required", "cloud_auth_expired", "cloud_auth_revoked", "workspace_selection_required", "workspace_switch_required", "workspace_forbidden", "project_binding_forbidden", "endpoint_unavailable", "websocket_upgrade_required", "sync_required", "sync_failed", "sync_size_limit_exceeded", "lease_conflict", "lease_expired", "policy_denied", "usage_limit_reached", "billing_required", "subscription_past_due", "email_verification_required", "remote_credentials_required", "remote_auth_failed"];
|
|
3
|
+
export type ProjectBindingErrorCode = (typeof PROJECT_BINDING_ERROR_CODES)[number];
|
|
4
|
+
export type ProjectBindingRecovery = {
|
|
5
|
+
code: ProjectBindingErrorCode;
|
|
6
|
+
message: string;
|
|
7
|
+
recoveryCommand?: string | undefined;
|
|
8
|
+
requestId?: string | undefined;
|
|
9
|
+
};
|
|
10
|
+
export declare class ProjectBindingError extends CapletsError {
|
|
11
|
+
readonly projectBindingCode: ProjectBindingErrorCode;
|
|
12
|
+
readonly recoveryCommand?: string | undefined;
|
|
13
|
+
readonly requestId?: string | undefined;
|
|
14
|
+
constructor(input: ProjectBindingRecovery);
|
|
15
|
+
}
|
|
16
|
+
export declare function projectBindingRecovery(code: ProjectBindingErrorCode, message?: string): ProjectBindingRecovery;
|
|
17
|
+
export declare function projectBindingError(code: ProjectBindingErrorCode, message?: string): ProjectBindingError;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export type ManagedSyncState = "idle" | "starting" | "syncing" | "ready" | "blocked" | "stopped";
|
|
2
|
+
export type ManagedSyncDiagnosticCode = "project_sync_binary_missing" | "project_sync_auth_failed" | "project_sync_conflict" | "project_sync_process_exit" | "project_sync_status_unavailable";
|
|
3
|
+
export type MutagenCommandPlan = {
|
|
4
|
+
command: string;
|
|
5
|
+
args: string[];
|
|
6
|
+
};
|
|
7
|
+
export type MutagenProcessResult = {
|
|
8
|
+
stdout?: string;
|
|
9
|
+
stderr?: string;
|
|
10
|
+
exitCode?: number;
|
|
11
|
+
};
|
|
12
|
+
export type MutagenProcessRunner = (command: string, args: string[]) => Promise<MutagenProcessResult>;
|
|
13
|
+
export type MutagenLastCommandStatus = MutagenCommandPlan & {
|
|
14
|
+
stdout: string;
|
|
15
|
+
stderr: string;
|
|
16
|
+
exitCode?: number;
|
|
17
|
+
};
|
|
18
|
+
export type ManagedSyncStateSnapshot = {
|
|
19
|
+
state: ManagedSyncState;
|
|
20
|
+
publicMessage: string;
|
|
21
|
+
bindingId?: string;
|
|
22
|
+
diagnosticCode?: ManagedSyncDiagnosticCode;
|
|
23
|
+
mutagenBinary?: string;
|
|
24
|
+
mutagenVersion?: string;
|
|
25
|
+
lastCommand?: MutagenLastCommandStatus;
|
|
26
|
+
};
|
|
27
|
+
export type MutagenProjectSyncDoctorData = {
|
|
28
|
+
state: ManagedSyncState;
|
|
29
|
+
diagnosticCode?: ManagedSyncDiagnosticCode;
|
|
30
|
+
mutagenBinary?: string;
|
|
31
|
+
mutagenVersion?: string;
|
|
32
|
+
lastCommand?: MutagenLastCommandStatus;
|
|
33
|
+
};
|
|
34
|
+
export type StartMutagenProjectSyncInput = {
|
|
35
|
+
bindingId: string;
|
|
36
|
+
localProjectRoot: string;
|
|
37
|
+
serverProjectRoot: string;
|
|
38
|
+
};
|
|
39
|
+
export type MutagenProjectSyncBindingInput = {
|
|
40
|
+
bindingId: string;
|
|
41
|
+
};
|
|
42
|
+
export type ManagedMutagenProjectSyncOptions = {
|
|
43
|
+
mutagenBinary?: string;
|
|
44
|
+
runner?: MutagenProcessRunner;
|
|
45
|
+
};
|
|
46
|
+
type MutagenVersionInfo = {
|
|
47
|
+
version: string;
|
|
48
|
+
};
|
|
49
|
+
export declare function planMutagenVersionCommand(mutagenBinary?: string): MutagenCommandPlan;
|
|
50
|
+
export declare function planMutagenSyncCreateCommand(input: StartMutagenProjectSyncInput, mutagenBinary?: string): MutagenCommandPlan;
|
|
51
|
+
export declare function planMutagenSyncListCommand(mutagenBinary?: string): MutagenCommandPlan;
|
|
52
|
+
export declare function planMutagenSyncTerminateCommand(bindingId: string, mutagenBinary?: string): MutagenCommandPlan;
|
|
53
|
+
export declare function mutagenSyncName(bindingId: string): string;
|
|
54
|
+
export declare class ManagedMutagenProjectSync {
|
|
55
|
+
#private;
|
|
56
|
+
readonly mutagenBinary: string;
|
|
57
|
+
constructor(options?: ManagedMutagenProjectSyncOptions);
|
|
58
|
+
start(input: StartMutagenProjectSyncInput): Promise<ManagedSyncStateSnapshot>;
|
|
59
|
+
refresh(input: MutagenProjectSyncBindingInput): Promise<ManagedSyncStateSnapshot>;
|
|
60
|
+
stop(input: MutagenProjectSyncBindingInput): Promise<ManagedSyncStateSnapshot>;
|
|
61
|
+
snapshot(): ManagedSyncStateSnapshot;
|
|
62
|
+
}
|
|
63
|
+
export declare function mutagenProjectSyncDoctorData(snapshot: ManagedSyncStateSnapshot): MutagenProjectSyncDoctorData;
|
|
64
|
+
export declare function parseMutagenVersionOutput(output: string): MutagenVersionInfo;
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PROJECT_BINDING_STATES, type ProjectBindingState } from "./types";
|
|
2
|
+
export { PROJECT_BINDING_STATES };
|
|
3
|
+
export type { ProjectBindingState };
|
|
4
|
+
export declare const PROJECT_BINDINGS_CONTROL_PATH = "/control/project-bindings";
|
|
5
|
+
export declare const PROJECT_BINDING_CONNECT_PATH = "/control/project-bindings/connect";
|
|
6
|
+
export declare function projectBindingConnectPath(): string;
|
|
7
|
+
export declare function projectBindingStatusPath(bindingId: string): string;
|
|
8
|
+
export declare function projectBindingConnectUrl(baseUrl: string | URL): string;
|
|
9
|
+
export declare function projectBindingStatusUrl(baseUrl: string | URL, bindingId: string): string;
|