@get-bb/plugin-sdk 0.4.108 → 0.5.9
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/README.md +4 -3
- package/bundled-types/bb-plugin-sdk-app.d.ts +16711 -313
- package/bundled-types/bb-plugin-sdk-testing-app.d.ts +48 -2
- package/bundled-types/bb-plugin-sdk.d.ts +4321 -4052
- package/dist/app.js +19 -1
- package/dist/host.js +60 -13827
- package/dist/internal/composer-customization-validation.js +0 -7
- package/dist/internal/plugin-app-collector.js +15 -13793
- package/dist/provider-bridge-acp.js +461 -183
- package/dist/provider-bridge.js +19 -2
- package/dist/testing/app.js +261 -13951
- package/package.json +6 -8
|
@@ -3757,11 +3757,11 @@ function describeResultContentBlock(block) {
|
|
|
3757
3757
|
if (!type) {
|
|
3758
3758
|
return null;
|
|
3759
3759
|
}
|
|
3760
|
-
const
|
|
3760
|
+
const path6 = getStringProperty(block, "path");
|
|
3761
3761
|
const toolName = getStringProperty(block, "tool_name");
|
|
3762
3762
|
const url = getStringProperty(block, "url") ?? getStringProperty(block, "imageUrl");
|
|
3763
|
-
if (
|
|
3764
|
-
return `[${type}: ${
|
|
3763
|
+
if (path6) {
|
|
3764
|
+
return `[${type}: ${path6}]`;
|
|
3765
3765
|
}
|
|
3766
3766
|
if (toolName) {
|
|
3767
3767
|
return `[${type}: ${toolName}]`;
|
|
@@ -4224,6 +4224,23 @@ function mimeTypeFromExtension(filePath) {
|
|
|
4224
4224
|
}
|
|
4225
4225
|
}
|
|
4226
4226
|
|
|
4227
|
+
// ../text-utils/src/utf16.ts
|
|
4228
|
+
function isHighSurrogateAt(value, index) {
|
|
4229
|
+
const code = value.charCodeAt(index);
|
|
4230
|
+
return code >= 55296 && code <= 56319;
|
|
4231
|
+
}
|
|
4232
|
+
function isLowSurrogateAt(value, index) {
|
|
4233
|
+
const code = value.charCodeAt(index);
|
|
4234
|
+
return code >= 56320 && code <= 57343;
|
|
4235
|
+
}
|
|
4236
|
+
function sliceUtf16Head(value, maxChars) {
|
|
4237
|
+
let end = Math.min(value.length, Math.max(0, maxChars));
|
|
4238
|
+
if (isHighSurrogateAt(value, end - 1) && isLowSurrogateAt(value, end)) {
|
|
4239
|
+
end -= 1;
|
|
4240
|
+
}
|
|
4241
|
+
return value.slice(0, end);
|
|
4242
|
+
}
|
|
4243
|
+
|
|
4227
4244
|
// ../provider-bridge-protocol/src/bridge-kit/presentation.ts
|
|
4228
4245
|
var PRESENTATION_TITLE_MAX_LENGTH = 160;
|
|
4229
4246
|
function presentationTitle(text) {
|
|
@@ -4231,14 +4248,14 @@ function presentationTitle(text) {
|
|
|
4231
4248
|
if (firstLine.length === 0) {
|
|
4232
4249
|
return void 0;
|
|
4233
4250
|
}
|
|
4234
|
-
return firstLine.length > PRESENTATION_TITLE_MAX_LENGTH ? `${firstLine
|
|
4251
|
+
return firstLine.length > PRESENTATION_TITLE_MAX_LENGTH ? `${sliceUtf16Head(firstLine, PRESENTATION_TITLE_MAX_LENGTH - 1)}\u2026` : firstLine;
|
|
4235
4252
|
}
|
|
4236
4253
|
function withTitle(presentation, title) {
|
|
4237
4254
|
return title === void 0 ? presentation : { ...presentation, title };
|
|
4238
4255
|
}
|
|
4239
|
-
function presentationFileName(
|
|
4240
|
-
const segments =
|
|
4241
|
-
return segments[segments.length - 1] ??
|
|
4256
|
+
function presentationFileName(path6) {
|
|
4257
|
+
const segments = path6.split("/").filter((segment) => segment.length > 0);
|
|
4258
|
+
return segments[segments.length - 1] ?? path6;
|
|
4242
4259
|
}
|
|
4243
4260
|
var COMPACTION_PRESENTATION = {
|
|
4244
4261
|
label: { pending: "Compacting context", completed: "Compacted context" },
|
|
@@ -4248,13 +4265,13 @@ var REASONING_PRESENTATION = {
|
|
|
4248
4265
|
label: { pending: "Thinking", completed: "Thought" },
|
|
4249
4266
|
icon: { glyph: "Brain" }
|
|
4250
4267
|
};
|
|
4251
|
-
function fileReadPresentation(
|
|
4268
|
+
function fileReadPresentation(path6) {
|
|
4252
4269
|
return withTitle(
|
|
4253
4270
|
{
|
|
4254
4271
|
label: { pending: "Reading file", completed: "Read file" },
|
|
4255
4272
|
icon: { glyph: "FileText" }
|
|
4256
4273
|
},
|
|
4257
|
-
presentationTitle(presentationFileName(
|
|
4274
|
+
presentationTitle(presentationFileName(path6))
|
|
4258
4275
|
);
|
|
4259
4276
|
}
|
|
4260
4277
|
function searchPresentation(args) {
|
|
@@ -4389,12 +4406,12 @@ var ignoredJsonRpcResultSchema = z34.unknown();
|
|
|
4389
4406
|
// ../provider-bridge-acp/src/bridge/bridge.ts
|
|
4390
4407
|
import { execFile as execFile4 } from "node:child_process";
|
|
4391
4408
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
4392
|
-
import { promises as
|
|
4409
|
+
import { promises as fs3, readFileSync } from "node:fs";
|
|
4393
4410
|
import { createServer } from "node:net";
|
|
4394
4411
|
import { dirname as dirname2, isAbsolute, basename as basename3, relative, resolve as resolve3 } from "node:path";
|
|
4395
4412
|
import { fileURLToPath } from "node:url";
|
|
4396
4413
|
import { isDeepStrictEqual } from "node:util";
|
|
4397
|
-
import { z as
|
|
4414
|
+
import { z as z43 } from "zod";
|
|
4398
4415
|
|
|
4399
4416
|
// ../provider-bridge-acp/src/bridge-protocol.ts
|
|
4400
4417
|
import { z as z36 } from "zod";
|
|
@@ -4816,17 +4833,189 @@ var acpWarningNotificationParamsSchema = z36.object({
|
|
|
4816
4833
|
|
|
4817
4834
|
// ../provider-bridge-acp/src/dialect.ts
|
|
4818
4835
|
import { basename } from "node:path";
|
|
4819
|
-
import { z as
|
|
4836
|
+
import { z as z41 } from "zod";
|
|
4820
4837
|
|
|
4821
4838
|
// ../provider-bridge-acp/src/bridge/provider-maintenance.ts
|
|
4822
4839
|
import { execFile as execFile2 } from "node:child_process";
|
|
4823
4840
|
import { existsSync } from "node:fs";
|
|
4841
|
+
import fs2 from "node:fs/promises";
|
|
4842
|
+
import os2 from "node:os";
|
|
4843
|
+
import path3 from "node:path";
|
|
4844
|
+
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
4845
|
+
import { promisify as promisify2 } from "node:util";
|
|
4846
|
+
import { z as z38 } from "zod";
|
|
4847
|
+
|
|
4848
|
+
// ../provider-bridge-acp/src/bridge/opencode-usage.ts
|
|
4824
4849
|
import fs from "node:fs/promises";
|
|
4825
4850
|
import os from "node:os";
|
|
4826
4851
|
import path2 from "node:path";
|
|
4827
4852
|
import { DatabaseSync } from "node:sqlite";
|
|
4828
|
-
import { promisify as promisify2 } from "node:util";
|
|
4829
4853
|
import { z as z37 } from "zod";
|
|
4854
|
+
var apiCredentialSchema = z37.object({
|
|
4855
|
+
type: z37.literal("api"),
|
|
4856
|
+
key: z37.string().trim().min(1)
|
|
4857
|
+
});
|
|
4858
|
+
var credentialsSchema = z37.record(z37.string(), z37.unknown());
|
|
4859
|
+
var accountSchema = z37.object({
|
|
4860
|
+
id: z37.string().min(1),
|
|
4861
|
+
email: z37.email().nullable().catch(null),
|
|
4862
|
+
url: z37.url(),
|
|
4863
|
+
access_token: z37.string().min(1),
|
|
4864
|
+
token_expiry: z37.number().nullable(),
|
|
4865
|
+
active_org_id: z37.string().min(1).nullable()
|
|
4866
|
+
});
|
|
4867
|
+
var windowSchema = z37.object({
|
|
4868
|
+
status: z37.enum(["ok", "rate-limited"]),
|
|
4869
|
+
percent: z37.number().nonnegative(),
|
|
4870
|
+
resetsAt: z37.iso.datetime({ offset: true })
|
|
4871
|
+
});
|
|
4872
|
+
var usageSchema = z37.object({
|
|
4873
|
+
usage: z37.object({
|
|
4874
|
+
rolling: windowSchema,
|
|
4875
|
+
weekly: windowSchema,
|
|
4876
|
+
monthly: windowSchema
|
|
4877
|
+
})
|
|
4878
|
+
});
|
|
4879
|
+
function dataDirectory(env) {
|
|
4880
|
+
const dataHome = env.XDG_DATA_HOME;
|
|
4881
|
+
return path2.join(
|
|
4882
|
+
dataHome && path2.isAbsolute(dataHome) ? dataHome : path2.join(env.HOME || os.homedir(), ".local", "share"),
|
|
4883
|
+
"opencode"
|
|
4884
|
+
);
|
|
4885
|
+
}
|
|
4886
|
+
async function readAccount(env) {
|
|
4887
|
+
const databasePath = path2.join(dataDirectory(env), "opencode.db");
|
|
4888
|
+
try {
|
|
4889
|
+
await fs.access(databasePath);
|
|
4890
|
+
} catch (error) {
|
|
4891
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT")
|
|
4892
|
+
return null;
|
|
4893
|
+
throw error;
|
|
4894
|
+
}
|
|
4895
|
+
const database = new DatabaseSync(databasePath, { readOnly: true });
|
|
4896
|
+
try {
|
|
4897
|
+
const tables = database.prepare(
|
|
4898
|
+
"SELECT name FROM sqlite_master WHERE type = 'table' AND name IN ('account', 'account_state')"
|
|
4899
|
+
).all();
|
|
4900
|
+
if (tables.length !== 2) return null;
|
|
4901
|
+
const row = database.prepare(
|
|
4902
|
+
"SELECT a.id, a.email, a.url, a.access_token, a.token_expiry, s.active_org_id FROM account a JOIN account_state s ON s.active_account_id = a.id WHERE s.id = 1"
|
|
4903
|
+
).get();
|
|
4904
|
+
if (!row) return null;
|
|
4905
|
+
const account = accountSchema.parse(row);
|
|
4906
|
+
const issuer = new URL(account.url);
|
|
4907
|
+
if (issuer.origin !== "https://opencode.ai" || !["/", "/console", "/console/"].includes(issuer.pathname) || account.active_org_id === null)
|
|
4908
|
+
return null;
|
|
4909
|
+
return account;
|
|
4910
|
+
} finally {
|
|
4911
|
+
database.close();
|
|
4912
|
+
}
|
|
4913
|
+
}
|
|
4914
|
+
async function readApiKey(env) {
|
|
4915
|
+
if (env.OPENCODE_API_KEY?.trim()) return env.OPENCODE_API_KEY.trim();
|
|
4916
|
+
let content = env.OPENCODE_AUTH_CONTENT;
|
|
4917
|
+
if (content) {
|
|
4918
|
+
try {
|
|
4919
|
+
JSON.parse(content);
|
|
4920
|
+
} catch {
|
|
4921
|
+
content = void 0;
|
|
4922
|
+
}
|
|
4923
|
+
}
|
|
4924
|
+
if (!content) {
|
|
4925
|
+
try {
|
|
4926
|
+
content = await fs.readFile(
|
|
4927
|
+
path2.join(dataDirectory(env), "auth.json"),
|
|
4928
|
+
"utf8"
|
|
4929
|
+
);
|
|
4930
|
+
} catch (error) {
|
|
4931
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT")
|
|
4932
|
+
return null;
|
|
4933
|
+
throw error;
|
|
4934
|
+
}
|
|
4935
|
+
}
|
|
4936
|
+
const credentials = credentialsSchema.parse(JSON.parse(content));
|
|
4937
|
+
for (const provider of ["opencode-go", "opencode"]) {
|
|
4938
|
+
const credential = apiCredentialSchema.safeParse(credentials[provider]);
|
|
4939
|
+
if (credential.success) return credential.data.key;
|
|
4940
|
+
}
|
|
4941
|
+
return null;
|
|
4942
|
+
}
|
|
4943
|
+
async function readOpenCodeGoUsage(env) {
|
|
4944
|
+
const failure = (message) => ({
|
|
4945
|
+
supported: true,
|
|
4946
|
+
usage: {
|
|
4947
|
+
status: "error",
|
|
4948
|
+
message,
|
|
4949
|
+
planLabel: "OpenCode Go",
|
|
4950
|
+
accountEmail: null
|
|
4951
|
+
}
|
|
4952
|
+
});
|
|
4953
|
+
let apiKey;
|
|
4954
|
+
let account;
|
|
4955
|
+
try {
|
|
4956
|
+
account = env.OPENCODE_API_KEY?.trim() ? null : await readAccount(env);
|
|
4957
|
+
apiKey = account?.access_token ?? await readApiKey(env);
|
|
4958
|
+
} catch {
|
|
4959
|
+
return failure("OpenCode credentials could not be read.");
|
|
4960
|
+
}
|
|
4961
|
+
if (apiKey === null)
|
|
4962
|
+
return { supported: true, usage: { status: "unauthenticated" } };
|
|
4963
|
+
if (account?.token_expiry != null && account.token_expiry <= Date.now())
|
|
4964
|
+
return { supported: true, usage: { status: "expired" } };
|
|
4965
|
+
try {
|
|
4966
|
+
const response = await fetch(
|
|
4967
|
+
account ? "https://opencode.ai/inference/go/v1/usage" : "https://opencode.ai/zen/go/v1/usage",
|
|
4968
|
+
{
|
|
4969
|
+
headers: {
|
|
4970
|
+
Authorization: `Bearer ${apiKey}`,
|
|
4971
|
+
Accept: "application/json",
|
|
4972
|
+
"User-Agent": "bb-provider-acp",
|
|
4973
|
+
...account?.active_org_id ? { "x-opencode-org-id": account.active_org_id } : {}
|
|
4974
|
+
},
|
|
4975
|
+
redirect: "error",
|
|
4976
|
+
signal: AbortSignal.timeout(15e3)
|
|
4977
|
+
}
|
|
4978
|
+
);
|
|
4979
|
+
if (response.status === 401)
|
|
4980
|
+
return { supported: true, usage: { status: "expired" } };
|
|
4981
|
+
if (response.status === 403)
|
|
4982
|
+
return failure(
|
|
4983
|
+
"OpenCode Go usage access was denied. Check that the account has an active Go subscription."
|
|
4984
|
+
);
|
|
4985
|
+
if (!response.ok)
|
|
4986
|
+
return failure(
|
|
4987
|
+
`OpenCode Go usage request failed (HTTP ${response.status}).`
|
|
4988
|
+
);
|
|
4989
|
+
const parsed = usageSchema.safeParse(await response.json());
|
|
4990
|
+
if (!parsed.success)
|
|
4991
|
+
return failure("OpenCode Go returned invalid usage information.");
|
|
4992
|
+
const { rolling, weekly, monthly } = parsed.data.usage;
|
|
4993
|
+
return {
|
|
4994
|
+
supported: true,
|
|
4995
|
+
usage: {
|
|
4996
|
+
status: "ok",
|
|
4997
|
+
accountEmail: account?.email ?? null,
|
|
4998
|
+
accountKey: account ? `opencode:organization:${account.active_org_id}:account:${account.id}` : null,
|
|
4999
|
+
planLabel: "OpenCode Go",
|
|
5000
|
+
windows: [
|
|
5001
|
+
{ label: "5 hour", kind: "five-hour", window: rolling },
|
|
5002
|
+
{ label: "Weekly", kind: "weekly", window: weekly },
|
|
5003
|
+
{ label: "Monthly", kind: "custom", window: monthly }
|
|
5004
|
+
].map(({ label, kind, window }) => ({
|
|
5005
|
+
label,
|
|
5006
|
+
kind,
|
|
5007
|
+
model: null,
|
|
5008
|
+
usedPercent: Math.min(100, window.percent),
|
|
5009
|
+
resetsAt: window.resetsAt
|
|
5010
|
+
}))
|
|
5011
|
+
}
|
|
5012
|
+
};
|
|
5013
|
+
} catch {
|
|
5014
|
+
return failure("OpenCode Go usage could not be collected. Try again.");
|
|
5015
|
+
}
|
|
5016
|
+
}
|
|
5017
|
+
|
|
5018
|
+
// ../provider-bridge-acp/src/bridge/provider-maintenance.ts
|
|
4830
5019
|
var execFileAsync2 = promisify2(execFile2);
|
|
4831
5020
|
var USAGE_FETCH_TIMEOUT_MS = 15e3;
|
|
4832
5021
|
var CURSOR_DASHBOARD_URL = "https://api2.cursor.sh/aiserver.v1.DashboardService";
|
|
@@ -4835,14 +5024,14 @@ var CURSOR_ACCESS_TOKEN_SERVICE = "cursor-access-token";
|
|
|
4835
5024
|
var CURSOR_INSTALL_SCRIPT_URL = "https://cursor.com/install";
|
|
4836
5025
|
function cursorAuthFilePath() {
|
|
4837
5026
|
if (process.platform === "win32") {
|
|
4838
|
-
const appData = process.env.APPDATA ??
|
|
4839
|
-
return
|
|
5027
|
+
const appData = process.env.APPDATA ?? path3.join(os2.homedir(), "AppData", "Roaming");
|
|
5028
|
+
return path3.join(appData, "Cursor", "auth.json");
|
|
4840
5029
|
}
|
|
4841
5030
|
if (process.platform === "darwin") {
|
|
4842
|
-
return
|
|
5031
|
+
return path3.join(os2.homedir(), ".cursor", "auth.json");
|
|
4843
5032
|
}
|
|
4844
|
-
const configHome = process.env.XDG_CONFIG_HOME ??
|
|
4845
|
-
return
|
|
5033
|
+
const configHome = process.env.XDG_CONFIG_HOME ?? path3.join(os2.homedir(), ".config");
|
|
5034
|
+
return path3.join(configHome, "cursor", "auth.json");
|
|
4846
5035
|
}
|
|
4847
5036
|
async function readKeychainAccessToken() {
|
|
4848
5037
|
if (process.platform !== "darwin") return null;
|
|
@@ -4864,15 +5053,15 @@ async function readKeychainAccessToken() {
|
|
|
4864
5053
|
return null;
|
|
4865
5054
|
}
|
|
4866
5055
|
}
|
|
4867
|
-
var cursorFileCredentialsSchema =
|
|
4868
|
-
accessToken:
|
|
5056
|
+
var cursorFileCredentialsSchema = z38.object({
|
|
5057
|
+
accessToken: z38.string().min(1).nullish()
|
|
4869
5058
|
});
|
|
4870
5059
|
async function readAccessToken() {
|
|
4871
5060
|
const keychain = await readKeychainAccessToken();
|
|
4872
5061
|
if (keychain) return keychain;
|
|
4873
5062
|
try {
|
|
4874
5063
|
const parsed = cursorFileCredentialsSchema.safeParse(
|
|
4875
|
-
JSON.parse(await
|
|
5064
|
+
JSON.parse(await fs2.readFile(cursorAuthFilePath(), "utf8"))
|
|
4876
5065
|
);
|
|
4877
5066
|
return parsed.success ? parsed.data.accessToken ?? null : null;
|
|
4878
5067
|
} catch {
|
|
@@ -4881,12 +5070,12 @@ async function readAccessToken() {
|
|
|
4881
5070
|
}
|
|
4882
5071
|
function cursorStateDatabasePath() {
|
|
4883
5072
|
if (process.platform === "win32") {
|
|
4884
|
-
const appData = process.env.APPDATA ??
|
|
4885
|
-
return
|
|
5073
|
+
const appData = process.env.APPDATA ?? path3.join(os2.homedir(), "AppData", "Roaming");
|
|
5074
|
+
return path3.join(appData, "Cursor", "User", "globalStorage", "state.vscdb");
|
|
4886
5075
|
}
|
|
4887
5076
|
if (process.platform === "darwin") {
|
|
4888
|
-
return
|
|
4889
|
-
|
|
5077
|
+
return path3.join(
|
|
5078
|
+
os2.homedir(),
|
|
4890
5079
|
"Library",
|
|
4891
5080
|
"Application Support",
|
|
4892
5081
|
"Cursor",
|
|
@@ -4895,8 +5084,8 @@ function cursorStateDatabasePath() {
|
|
|
4895
5084
|
"state.vscdb"
|
|
4896
5085
|
);
|
|
4897
5086
|
}
|
|
4898
|
-
const configHome = process.env.XDG_CONFIG_HOME ??
|
|
4899
|
-
return
|
|
5087
|
+
const configHome = process.env.XDG_CONFIG_HOME ?? path3.join(os2.homedir(), ".config");
|
|
5088
|
+
return path3.join(
|
|
4900
5089
|
configHome,
|
|
4901
5090
|
"Cursor",
|
|
4902
5091
|
"User",
|
|
@@ -4909,10 +5098,10 @@ function readAccountEmail() {
|
|
|
4909
5098
|
if (!existsSync(databasePath)) return null;
|
|
4910
5099
|
let database = null;
|
|
4911
5100
|
try {
|
|
4912
|
-
database = new
|
|
5101
|
+
database = new DatabaseSync2(databasePath);
|
|
4913
5102
|
database.exec("PRAGMA query_only = true");
|
|
4914
5103
|
const row = database.prepare("SELECT value FROM ItemTable WHERE key = ?").get("cursorAuth/cachedEmail");
|
|
4915
|
-
const parsed =
|
|
5104
|
+
const parsed = z38.object({ value: z38.string().email() }).safeParse(row);
|
|
4916
5105
|
return parsed.success ? parsed.data.value : null;
|
|
4917
5106
|
} catch {
|
|
4918
5107
|
return null;
|
|
@@ -5016,14 +5205,14 @@ function buildAcpProviderInstallationRun(status, args) {
|
|
|
5016
5205
|
verification: { kind: "installed" }
|
|
5017
5206
|
};
|
|
5018
5207
|
}
|
|
5019
|
-
var cursorNonNegativeIntegerSchema =
|
|
5020
|
-
|
|
5021
|
-
|
|
5208
|
+
var cursorNonNegativeIntegerSchema = z38.union([
|
|
5209
|
+
z38.number().int().nonnegative(),
|
|
5210
|
+
z38.string().regex(/^\d+$/u).transform(Number)
|
|
5022
5211
|
]).refine(Number.isSafeInteger);
|
|
5023
|
-
var cursorUsageResponseSchema =
|
|
5212
|
+
var cursorUsageResponseSchema = z38.object({
|
|
5024
5213
|
billingCycleEnd: cursorNonNegativeIntegerSchema.nullish(),
|
|
5025
|
-
planUsage:
|
|
5026
|
-
spendLimitUsage:
|
|
5214
|
+
planUsage: z38.object({ totalPercentUsed: z38.number().nonnegative().default(0) }).nullish(),
|
|
5215
|
+
spendLimitUsage: z38.object({
|
|
5027
5216
|
overallLimit: cursorNonNegativeIntegerSchema.nullish(),
|
|
5028
5217
|
overallUsed: cursorNonNegativeIntegerSchema.nullish(),
|
|
5029
5218
|
individualLimit: cursorNonNegativeIntegerSchema.nullish(),
|
|
@@ -5032,8 +5221,8 @@ var cursorUsageResponseSchema = z37.object({
|
|
|
5032
5221
|
pooledUsed: cursorNonNegativeIntegerSchema.nullish()
|
|
5033
5222
|
}).nullish()
|
|
5034
5223
|
}).passthrough();
|
|
5035
|
-
var cursorPlanResponseSchema =
|
|
5036
|
-
planInfo:
|
|
5224
|
+
var cursorPlanResponseSchema = z38.object({
|
|
5225
|
+
planInfo: z38.object({ planName: z38.string().min(1) }).nullish()
|
|
5037
5226
|
}).passthrough();
|
|
5038
5227
|
function normalizeUsage(rawUsage, rawPlan, accountEmail = null) {
|
|
5039
5228
|
const usage = cursorUsageResponseSchema.safeParse(rawUsage);
|
|
@@ -5088,11 +5277,12 @@ function fetchDashboard(method, accessToken) {
|
|
|
5088
5277
|
});
|
|
5089
5278
|
}
|
|
5090
5279
|
async function getAcpProviderUsage(args) {
|
|
5091
|
-
|
|
5280
|
+
const readUsage = args.dialectId === "opencode" ? () => readOpenCodeGoUsage(args.env) : args.maintenance?.readUsage;
|
|
5281
|
+
if (readUsage === void 0) return { supported: false };
|
|
5092
5282
|
if (args.command === null || await resolveExecutablePath(args.command) === null) {
|
|
5093
5283
|
return { supported: true, usage: { status: "not_installed" } };
|
|
5094
5284
|
}
|
|
5095
|
-
return
|
|
5285
|
+
return readUsage();
|
|
5096
5286
|
}
|
|
5097
5287
|
var CURSOR_ACP_MAINTENANCE = {
|
|
5098
5288
|
loginCommand: "cursor-agent login",
|
|
@@ -5245,24 +5435,24 @@ function toolKindPresentation(args) {
|
|
|
5245
5435
|
}
|
|
5246
5436
|
|
|
5247
5437
|
// ../provider-bridge-acp/src/tool-classification.ts
|
|
5248
|
-
import { z as
|
|
5438
|
+
import { z as z40 } from "zod";
|
|
5249
5439
|
|
|
5250
5440
|
// ../provider-bridge-acp/src/tool-call-operation.ts
|
|
5251
|
-
import
|
|
5252
|
-
import { z as
|
|
5253
|
-
var acpRawInputCommandSchema =
|
|
5254
|
-
var acpRawInputPathSchema =
|
|
5255
|
-
path:
|
|
5256
|
-
filePath:
|
|
5257
|
-
file_path:
|
|
5258
|
-
target_file:
|
|
5441
|
+
import path4 from "node:path";
|
|
5442
|
+
import { z as z39 } from "zod";
|
|
5443
|
+
var acpRawInputCommandSchema = z39.object({ command: z39.string() }).passthrough();
|
|
5444
|
+
var acpRawInputPathSchema = z39.object({
|
|
5445
|
+
path: z39.string().optional(),
|
|
5446
|
+
filePath: z39.string().optional(),
|
|
5447
|
+
file_path: z39.string().optional(),
|
|
5448
|
+
target_file: z39.string().optional()
|
|
5259
5449
|
}).passthrough();
|
|
5260
5450
|
function resolveAcpToolCallPath(value, options) {
|
|
5261
5451
|
const cwd = options?.cwd;
|
|
5262
|
-
if (cwd === void 0 ||
|
|
5452
|
+
if (cwd === void 0 || path4.isAbsolute(value) || value.startsWith("~")) {
|
|
5263
5453
|
return value;
|
|
5264
5454
|
}
|
|
5265
|
-
return
|
|
5455
|
+
return path4.resolve(cwd, value);
|
|
5266
5456
|
}
|
|
5267
5457
|
function extractAcpCommand(event) {
|
|
5268
5458
|
const parsed = acpRawInputCommandSchema.safeParse(event.rawInput);
|
|
@@ -5320,8 +5510,8 @@ function classifyAcpToolCall(event, options) {
|
|
|
5320
5510
|
}
|
|
5321
5511
|
function resolveAcpFileChangeWriteScope(paths) {
|
|
5322
5512
|
const normalized = paths.filter(isNonBlank).map((entry) => {
|
|
5323
|
-
const value =
|
|
5324
|
-
return value.length > 1 && value.endsWith(
|
|
5513
|
+
const value = path4.normalize(entry);
|
|
5514
|
+
return value.length > 1 && value.endsWith(path4.sep) ? value.slice(0, -1) : value;
|
|
5325
5515
|
});
|
|
5326
5516
|
const [first, ...rest] = normalized;
|
|
5327
5517
|
if (first === void 0) {
|
|
@@ -5333,7 +5523,7 @@ function resolveAcpFileChangeWriteScope(paths) {
|
|
|
5333
5523
|
candidate = entry;
|
|
5334
5524
|
}
|
|
5335
5525
|
}
|
|
5336
|
-
const prefix = candidate.endsWith(
|
|
5526
|
+
const prefix = candidate.endsWith(path4.sep) ? candidate : candidate + path4.sep;
|
|
5337
5527
|
for (const entry of normalized) {
|
|
5338
5528
|
if (entry !== candidate && !entry.startsWith(prefix)) {
|
|
5339
5529
|
return null;
|
|
@@ -5432,14 +5622,14 @@ function extractAcpToolCallOutputText(event) {
|
|
|
5432
5622
|
).trim();
|
|
5433
5623
|
return rawOutputText.length > 0 ? rawOutputText : void 0;
|
|
5434
5624
|
}
|
|
5435
|
-
var commandRawOutputSchema =
|
|
5436
|
-
exitCode:
|
|
5437
|
-
exit_code:
|
|
5438
|
-
stdout:
|
|
5439
|
-
stderr:
|
|
5440
|
-
output_for_prompt:
|
|
5441
|
-
signal:
|
|
5442
|
-
timed_out:
|
|
5625
|
+
var commandRawOutputSchema = z40.object({
|
|
5626
|
+
exitCode: z40.number().int().nullable().optional(),
|
|
5627
|
+
exit_code: z40.number().int().nullable().optional(),
|
|
5628
|
+
stdout: z40.string().optional(),
|
|
5629
|
+
stderr: z40.string().optional(),
|
|
5630
|
+
output_for_prompt: z40.string().optional(),
|
|
5631
|
+
signal: z40.string().nullable().optional(),
|
|
5632
|
+
timed_out: z40.boolean().optional()
|
|
5443
5633
|
}).passthrough();
|
|
5444
5634
|
function emptyToUndefined(value) {
|
|
5445
5635
|
return value === void 0 || value.length === 0 ? void 0 : value;
|
|
@@ -5508,10 +5698,10 @@ function extractAcpCommandResult(event) {
|
|
|
5508
5698
|
...output === void 0 ? {} : { output: scrubInlineImageDataUrls(output) }
|
|
5509
5699
|
};
|
|
5510
5700
|
}
|
|
5511
|
-
var optionalNonBlank =
|
|
5701
|
+
var optionalNonBlank = z40.string().optional().transform(
|
|
5512
5702
|
(value) => value !== void 0 && value.trim().length > 0 ? value : void 0
|
|
5513
5703
|
);
|
|
5514
|
-
var searchRawInputSchema =
|
|
5704
|
+
var searchRawInputSchema = z40.object({
|
|
5515
5705
|
pattern: optionalNonBlank,
|
|
5516
5706
|
query: optionalNonBlank,
|
|
5517
5707
|
regex: optionalNonBlank,
|
|
@@ -5520,8 +5710,8 @@ var searchRawInputSchema = z39.object({
|
|
|
5520
5710
|
path: optionalNonBlank,
|
|
5521
5711
|
directory: optionalNonBlank
|
|
5522
5712
|
}).passthrough();
|
|
5523
|
-
var fetchRawInputSchema =
|
|
5524
|
-
var thinkRawInputSchema =
|
|
5713
|
+
var fetchRawInputSchema = z40.object({ url: optionalNonBlank, uri: optionalNonBlank }).passthrough();
|
|
5714
|
+
var thinkRawInputSchema = z40.object({ thought: optionalNonBlank, thinking: optionalNonBlank }).passthrough();
|
|
5525
5715
|
var SINGLE_TICKED_TOKEN_PATTERN = /^[^`]*`([^`\n]+)`[^`]*$/;
|
|
5526
5716
|
var URL_PATTERN = /https?:\/\/[^\s`'"<>]+/g;
|
|
5527
5717
|
function tickedTokenFromTitle(title) {
|
|
@@ -5571,8 +5761,8 @@ function buildAcpFileChanges(event, operation, options) {
|
|
|
5571
5761
|
if (changes.length > 0) {
|
|
5572
5762
|
return changes;
|
|
5573
5763
|
}
|
|
5574
|
-
const [
|
|
5575
|
-
return
|
|
5764
|
+
const [path6] = operation.paths;
|
|
5765
|
+
return path6 === void 0 ? [] : [{ path: path6, kind: operation.changeKind }];
|
|
5576
5766
|
}
|
|
5577
5767
|
function fileChangeItem(changes, fallbackVerb) {
|
|
5578
5768
|
return {
|
|
@@ -5585,13 +5775,13 @@ function fileChangeItem(changes, fallbackVerb) {
|
|
|
5585
5775
|
}
|
|
5586
5776
|
function fileReadItem(event, title, options) {
|
|
5587
5777
|
const ticked = tickedTokenFromTitle(title);
|
|
5588
|
-
const
|
|
5589
|
-
if (
|
|
5778
|
+
const path6 = extractAcpToolCallPaths(event, options)[0] ?? (ticked !== void 0 && looksLikePath(ticked) ? ticked : void 0);
|
|
5779
|
+
if (path6 === void 0) {
|
|
5590
5780
|
return null;
|
|
5591
5781
|
}
|
|
5592
5782
|
return {
|
|
5593
|
-
item: { type: "fileRead", path:
|
|
5594
|
-
presentation: fileReadPresentation(
|
|
5783
|
+
item: { type: "fileRead", path: path6 },
|
|
5784
|
+
presentation: fileReadPresentation(path6)
|
|
5595
5785
|
};
|
|
5596
5786
|
}
|
|
5597
5787
|
function searchItem(event) {
|
|
@@ -5714,10 +5904,10 @@ function classifyAcpToolCall2(event, injected, options) {
|
|
|
5714
5904
|
|
|
5715
5905
|
// ../provider-bridge-acp/src/dialect.ts
|
|
5716
5906
|
var GENERIC_ACP_DIALECT = { id: "acp" };
|
|
5717
|
-
var grokToolMetaSchema =
|
|
5718
|
-
"x.ai/tool":
|
|
5719
|
-
name:
|
|
5720
|
-
kind:
|
|
5907
|
+
var grokToolMetaSchema = z41.object({
|
|
5908
|
+
"x.ai/tool": z41.object({
|
|
5909
|
+
name: z41.string().optional(),
|
|
5910
|
+
kind: z41.string().optional()
|
|
5721
5911
|
}).passthrough()
|
|
5722
5912
|
}).passthrough();
|
|
5723
5913
|
function grokToolIdentity(event) {
|
|
@@ -5733,10 +5923,10 @@ function grokToolIdentity(event) {
|
|
|
5733
5923
|
};
|
|
5734
5924
|
}
|
|
5735
5925
|
var GROK_SPAWN_SUBAGENT_TOOL = "spawn_subagent";
|
|
5736
|
-
var grokSpawnSubagentInputSchema =
|
|
5737
|
-
description:
|
|
5738
|
-
prompt:
|
|
5739
|
-
subagent_type:
|
|
5926
|
+
var grokSpawnSubagentInputSchema = z41.object({
|
|
5927
|
+
description: z41.string().optional(),
|
|
5928
|
+
prompt: z41.string().optional(),
|
|
5929
|
+
subagent_type: z41.string().optional()
|
|
5740
5930
|
}).passthrough();
|
|
5741
5931
|
function grokClassifyToolCall(event) {
|
|
5742
5932
|
if (grokToolIdentity(event)?.name !== GROK_SPAWN_SUBAGENT_TOOL) {
|
|
@@ -5764,15 +5954,64 @@ var GROK_ACP_DIALECT = {
|
|
|
5764
5954
|
toolIdentity: grokToolIdentity,
|
|
5765
5955
|
classifyToolCall: grokClassifyToolCall
|
|
5766
5956
|
};
|
|
5957
|
+
var grokModelMetaSchema = z41.object({
|
|
5958
|
+
totalContextTokens: z41.number().int().positive()
|
|
5959
|
+
}).passthrough();
|
|
5960
|
+
var grokPromptMetaSchema = z41.object({
|
|
5961
|
+
inputTokens: z41.number().int().nonnegative().optional(),
|
|
5962
|
+
totalTokens: z41.number().int().nonnegative().optional(),
|
|
5963
|
+
usage: z41.object({
|
|
5964
|
+
inputTokens: z41.number().int().nonnegative().optional(),
|
|
5965
|
+
totalTokens: z41.number().int().nonnegative().optional()
|
|
5966
|
+
}).passthrough().optional()
|
|
5967
|
+
}).passthrough();
|
|
5968
|
+
var grokPromptResultSchema = z41.object({
|
|
5969
|
+
_meta: grokPromptMetaSchema.optional()
|
|
5970
|
+
}).passthrough();
|
|
5971
|
+
var grokSessionModelSchema = z41.object({
|
|
5972
|
+
modelId: z41.string(),
|
|
5973
|
+
_meta: grokModelMetaSchema.optional()
|
|
5974
|
+
}).passthrough();
|
|
5975
|
+
var grokSessionModelsSchema = z41.object({
|
|
5976
|
+
currentModelId: z41.string().optional(),
|
|
5977
|
+
availableModels: z41.array(grokSessionModelSchema).optional()
|
|
5978
|
+
}).passthrough();
|
|
5979
|
+
function grokContextWindowSizeFromSessionModels(models) {
|
|
5980
|
+
const parsed = grokSessionModelsSchema.safeParse(models);
|
|
5981
|
+
if (!parsed.success) {
|
|
5982
|
+
return void 0;
|
|
5983
|
+
}
|
|
5984
|
+
const available = parsed.data.availableModels ?? [];
|
|
5985
|
+
const currentId = parsed.data.currentModelId;
|
|
5986
|
+
const ordered = [
|
|
5987
|
+
...currentId === void 0 ? [] : available.filter((model) => model.modelId === currentId),
|
|
5988
|
+
...available
|
|
5989
|
+
];
|
|
5990
|
+
for (const model of ordered) {
|
|
5991
|
+
if (model._meta !== void 0) {
|
|
5992
|
+
return model._meta.totalContextTokens;
|
|
5993
|
+
}
|
|
5994
|
+
}
|
|
5995
|
+
return void 0;
|
|
5996
|
+
}
|
|
5997
|
+
function grokContextUsageFromPromptResult(result) {
|
|
5998
|
+
const parsed = grokPromptResultSchema.safeParse(result);
|
|
5999
|
+
if (!parsed.success) {
|
|
6000
|
+
return void 0;
|
|
6001
|
+
}
|
|
6002
|
+
const meta = parsed.data._meta;
|
|
6003
|
+
const used = meta?.usage?.inputTokens ?? meta?.inputTokens ?? meta?.usage?.totalTokens ?? meta?.totalTokens;
|
|
6004
|
+
return used === void 0 ? void 0 : { used };
|
|
6005
|
+
}
|
|
5767
6006
|
var CURSOR_TASK_TOOL = "task";
|
|
5768
|
-
var cursorTaskRawInputSchema =
|
|
6007
|
+
var cursorTaskRawInputSchema = z41.object({ _toolName: z41.string().optional() }).passthrough();
|
|
5769
6008
|
var CURSOR_TASK_METHOD = "cursor/task";
|
|
5770
|
-
var cursorTaskParamsSchema =
|
|
5771
|
-
toolCallId:
|
|
5772
|
-
description:
|
|
5773
|
-
prompt:
|
|
5774
|
-
agentId:
|
|
5775
|
-
model:
|
|
6009
|
+
var cursorTaskParamsSchema = z41.object({
|
|
6010
|
+
toolCallId: z41.string(),
|
|
6011
|
+
description: z41.string().optional(),
|
|
6012
|
+
prompt: z41.string().optional(),
|
|
6013
|
+
agentId: z41.string().optional(),
|
|
6014
|
+
model: z41.string().optional()
|
|
5776
6015
|
}).passthrough();
|
|
5777
6016
|
function cursorClassifyToolCall(event) {
|
|
5778
6017
|
const parsed = cursorTaskRawInputSchema.safeParse(event.rawInput);
|
|
@@ -5820,23 +6059,23 @@ var CURSOR_ACP_DIALECT = {
|
|
|
5820
6059
|
handleClientRequest: cursorHandleClientRequest,
|
|
5821
6060
|
maintenance: CURSOR_ACP_MAINTENANCE
|
|
5822
6061
|
};
|
|
5823
|
-
var ompBashRawInputSchema =
|
|
5824
|
-
command:
|
|
5825
|
-
async:
|
|
6062
|
+
var ompBashRawInputSchema = z41.object({
|
|
6063
|
+
command: z41.string(),
|
|
6064
|
+
async: z41.boolean().optional()
|
|
5826
6065
|
}).passthrough();
|
|
5827
6066
|
var ompBashRawOutputSchema = commandRawOutputSchema.extend({
|
|
5828
|
-
content:
|
|
5829
|
-
|
|
5830
|
-
type:
|
|
5831
|
-
text:
|
|
6067
|
+
content: z41.array(
|
|
6068
|
+
z41.object({
|
|
6069
|
+
type: z41.literal("text"),
|
|
6070
|
+
text: z41.string()
|
|
5832
6071
|
}).passthrough()
|
|
5833
6072
|
),
|
|
5834
|
-
details:
|
|
5835
|
-
exitCode:
|
|
5836
|
-
wallTimeMs:
|
|
5837
|
-
timedOut:
|
|
5838
|
-
signal:
|
|
5839
|
-
async:
|
|
6073
|
+
details: z41.object({
|
|
6074
|
+
exitCode: z41.number().int().optional(),
|
|
6075
|
+
wallTimeMs: z41.number().nonnegative().optional(),
|
|
6076
|
+
timedOut: z41.boolean().optional(),
|
|
6077
|
+
signal: z41.unknown().optional(),
|
|
6078
|
+
async: z41.unknown().optional()
|
|
5840
6079
|
}).passthrough()
|
|
5841
6080
|
});
|
|
5842
6081
|
function stripOmpTrailingNotice(text, notice) {
|
|
@@ -5899,11 +6138,11 @@ var OMP_ACP_DIALECT = {
|
|
|
5899
6138
|
id: "omp",
|
|
5900
6139
|
commandResult: ompCommandResult
|
|
5901
6140
|
};
|
|
5902
|
-
var openCodeCommandRawOutputSchema =
|
|
5903
|
-
output:
|
|
5904
|
-
metadata:
|
|
5905
|
-
exit:
|
|
5906
|
-
output:
|
|
6141
|
+
var openCodeCommandRawOutputSchema = z41.object({
|
|
6142
|
+
output: z41.unknown().optional(),
|
|
6143
|
+
metadata: z41.object({
|
|
6144
|
+
exit: z41.number().int().nullable().optional(),
|
|
6145
|
+
output: z41.string().optional()
|
|
5907
6146
|
}).passthrough().optional()
|
|
5908
6147
|
}).passthrough();
|
|
5909
6148
|
function normalizeOpenCodeCommandEvent(event) {
|
|
@@ -6919,7 +7158,7 @@ function resolveAcpPermissionDecision(args) {
|
|
|
6919
7158
|
}
|
|
6920
7159
|
|
|
6921
7160
|
// ../provider-bridge-acp/src/session-params.ts
|
|
6922
|
-
import
|
|
7161
|
+
import path5 from "node:path";
|
|
6923
7162
|
|
|
6924
7163
|
// ../provider-bridge-acp/src/bridge/model-catalog.ts
|
|
6925
7164
|
var ACP_NATIVE_REASONING_EFFORTS = [
|
|
@@ -7378,7 +7617,7 @@ function buildAcpSkillsInstructions(skillRoots) {
|
|
|
7378
7617
|
}
|
|
7379
7618
|
const skillLines = skillRoots.flatMap((skillRoot) => {
|
|
7380
7619
|
return skillRoot.skills.map((skill) => {
|
|
7381
|
-
const skillFilePath =
|
|
7620
|
+
const skillFilePath = path5.join(
|
|
7382
7621
|
skillRoot.skillDirectoryRootPath,
|
|
7383
7622
|
skill.name,
|
|
7384
7623
|
"SKILL.md"
|
|
@@ -7821,7 +8060,7 @@ import { basename as basename2, dirname, join as join2, resolve as resolve2 } fr
|
|
|
7821
8060
|
// ../provider-bridge-acp/src/bridge/tool-proxy-mcp.ts
|
|
7822
8061
|
import { createConnection } from "node:net";
|
|
7823
8062
|
import { createInterface as createInterface2 } from "node:readline";
|
|
7824
|
-
import { z as
|
|
8063
|
+
import { z as z42 } from "zod";
|
|
7825
8064
|
var ACP_BRIDGE_MCP_SERVER_NAME = "bb-bridge";
|
|
7826
8065
|
var ENV_HOST = "BB_ACP_DYNAMIC_TOOL_HOST";
|
|
7827
8066
|
var ENV_PORT = "BB_ACP_DYNAMIC_TOOL_PORT";
|
|
@@ -7829,45 +8068,45 @@ var ENV_TOKEN = "BB_ACP_DYNAMIC_TOOL_TOKEN";
|
|
|
7829
8068
|
var ENV_THREAD_ID = "BB_ACP_DYNAMIC_TOOL_THREAD_ID";
|
|
7830
8069
|
var ENV_TOOLS = "BB_ACP_DYNAMIC_TOOLS";
|
|
7831
8070
|
var ENV_PROGRESS_INTERVAL_MS = "BB_ACP_DYNAMIC_TOOL_PROGRESS_INTERVAL_MS";
|
|
7832
|
-
var dynamicToolBridgeRequestSchema =
|
|
7833
|
-
|
|
7834
|
-
kind:
|
|
7835
|
-
threadId:
|
|
7836
|
-
token:
|
|
7837
|
-
toolCount:
|
|
8071
|
+
var dynamicToolBridgeRequestSchema = z42.discriminatedUnion("kind", [
|
|
8072
|
+
z42.object({
|
|
8073
|
+
kind: z42.literal("initialized"),
|
|
8074
|
+
threadId: z42.string().min(1),
|
|
8075
|
+
token: z42.string().min(1),
|
|
8076
|
+
toolCount: z42.number().int().nonnegative()
|
|
7838
8077
|
}),
|
|
7839
|
-
|
|
7840
|
-
kind:
|
|
7841
|
-
arguments:
|
|
7842
|
-
callId:
|
|
7843
|
-
threadId:
|
|
7844
|
-
token:
|
|
7845
|
-
tool:
|
|
8078
|
+
z42.object({
|
|
8079
|
+
kind: z42.literal("toolCall"),
|
|
8080
|
+
arguments: z42.record(z42.string(), z42.unknown()).default({}),
|
|
8081
|
+
callId: z42.string().min(1),
|
|
8082
|
+
threadId: z42.string().min(1),
|
|
8083
|
+
token: z42.string().min(1),
|
|
8084
|
+
tool: z42.string().min(1)
|
|
7846
8085
|
})
|
|
7847
8086
|
]);
|
|
7848
|
-
var bridgeToolCallResponseSchema =
|
|
7849
|
-
|
|
7850
|
-
ok:
|
|
7851
|
-
content:
|
|
7852
|
-
contentBlocks:
|
|
7853
|
-
|
|
7854
|
-
|
|
7855
|
-
|
|
7856
|
-
type:
|
|
7857
|
-
data:
|
|
7858
|
-
mimeType:
|
|
8087
|
+
var bridgeToolCallResponseSchema = z42.union([
|
|
8088
|
+
z42.object({
|
|
8089
|
+
ok: z42.literal(true),
|
|
8090
|
+
content: z42.string(),
|
|
8091
|
+
contentBlocks: z42.array(
|
|
8092
|
+
z42.discriminatedUnion("type", [
|
|
8093
|
+
z42.object({ type: z42.literal("text"), text: z42.string() }),
|
|
8094
|
+
z42.object({
|
|
8095
|
+
type: z42.literal("image"),
|
|
8096
|
+
data: z42.string(),
|
|
8097
|
+
mimeType: z42.string()
|
|
7859
8098
|
})
|
|
7860
8099
|
])
|
|
7861
8100
|
).optional(),
|
|
7862
|
-
images:
|
|
7863
|
-
isError:
|
|
8101
|
+
images: z42.array(z42.object({ data: z42.string(), mimeType: z42.string() })).default([]),
|
|
8102
|
+
isError: z42.boolean().optional()
|
|
7864
8103
|
}),
|
|
7865
|
-
|
|
8104
|
+
z42.object({ ok: z42.literal(false), error: z42.string() })
|
|
7866
8105
|
]);
|
|
7867
|
-
var jsonRpcMessageSchema =
|
|
7868
|
-
id:
|
|
7869
|
-
method:
|
|
7870
|
-
params:
|
|
8106
|
+
var jsonRpcMessageSchema = z42.object({
|
|
8107
|
+
id: z42.union([z42.string(), z42.number().int()]).optional(),
|
|
8108
|
+
method: z42.string().optional(),
|
|
8109
|
+
params: z42.unknown().optional()
|
|
7871
8110
|
});
|
|
7872
8111
|
var nextMcpToolCallId = 0;
|
|
7873
8112
|
var TOOL_CALL_PROGRESS_INTERVAL_MS = 15e3;
|
|
@@ -8167,10 +8406,10 @@ async function resolveCursorProjectRoot(args) {
|
|
|
8167
8406
|
);
|
|
8168
8407
|
});
|
|
8169
8408
|
}
|
|
8170
|
-
async function readApprovals(
|
|
8409
|
+
async function readApprovals(path6) {
|
|
8171
8410
|
let text;
|
|
8172
8411
|
try {
|
|
8173
|
-
text = await readFile(
|
|
8412
|
+
text = await readFile(path6, "utf8");
|
|
8174
8413
|
} catch (error) {
|
|
8175
8414
|
if (errorCode(error) === "ENOENT") {
|
|
8176
8415
|
return [];
|
|
@@ -8179,29 +8418,29 @@ async function readApprovals(path5) {
|
|
|
8179
8418
|
}
|
|
8180
8419
|
const value = JSON.parse(text);
|
|
8181
8420
|
if (!Array.isArray(value) || !value.every((item) => typeof item === "string")) {
|
|
8182
|
-
throw new Error(`Cursor MCP approval file is not a string array: ${
|
|
8421
|
+
throw new Error(`Cursor MCP approval file is not a string array: ${path6}`);
|
|
8183
8422
|
}
|
|
8184
8423
|
return value;
|
|
8185
8424
|
}
|
|
8186
|
-
async function writeApprovals(
|
|
8187
|
-
await mkdir(dirname(
|
|
8188
|
-
const tempPath = `${
|
|
8425
|
+
async function writeApprovals(path6, approvals) {
|
|
8426
|
+
await mkdir(dirname(path6), { recursive: true });
|
|
8427
|
+
const tempPath = `${path6}.bb-${process.pid}-${randomBytes(6).toString("hex")}.tmp`;
|
|
8189
8428
|
try {
|
|
8190
8429
|
await writeFile(tempPath, `${JSON.stringify(approvals, null, 2)}
|
|
8191
8430
|
`, {
|
|
8192
8431
|
encoding: "utf8",
|
|
8193
8432
|
mode: 384
|
|
8194
8433
|
});
|
|
8195
|
-
await rename(tempPath,
|
|
8434
|
+
await rename(tempPath, path6);
|
|
8196
8435
|
} catch (error) {
|
|
8197
8436
|
await rm(tempPath, { force: true });
|
|
8198
8437
|
throw error;
|
|
8199
8438
|
}
|
|
8200
8439
|
}
|
|
8201
|
-
async function acquireApprovalLock(
|
|
8202
|
-
const lockPath = `${
|
|
8440
|
+
async function acquireApprovalLock(path6) {
|
|
8441
|
+
const lockPath = `${path6}.bb-lock`;
|
|
8203
8442
|
const deadline = Date.now() + CURSOR_APPROVAL_LOCK_TIMEOUT_MS;
|
|
8204
|
-
await mkdir(dirname(
|
|
8443
|
+
await mkdir(dirname(path6), { recursive: true });
|
|
8205
8444
|
for (; ; ) {
|
|
8206
8445
|
try {
|
|
8207
8446
|
await mkdir(lockPath, { mode: 448 });
|
|
@@ -8224,18 +8463,18 @@ async function acquireApprovalLock(path5) {
|
|
|
8224
8463
|
throw error;
|
|
8225
8464
|
}
|
|
8226
8465
|
if (Date.now() >= deadline) {
|
|
8227
|
-
throw new Error(`Timed out updating Cursor MCP approvals: ${
|
|
8466
|
+
throw new Error(`Timed out updating Cursor MCP approvals: ${path6}`);
|
|
8228
8467
|
}
|
|
8229
8468
|
await new Promise((resolveDelay) => setTimeout(resolveDelay, 25));
|
|
8230
8469
|
}
|
|
8231
8470
|
}
|
|
8232
|
-
async function mutateApprovals(
|
|
8233
|
-
const releaseLock = await acquireApprovalLock(
|
|
8471
|
+
async function mutateApprovals(path6, mutate) {
|
|
8472
|
+
const releaseLock = await acquireApprovalLock(path6);
|
|
8234
8473
|
try {
|
|
8235
|
-
const approvals = await readApprovals(
|
|
8474
|
+
const approvals = await readApprovals(path6);
|
|
8236
8475
|
const nextApprovals = mutate(approvals);
|
|
8237
8476
|
if (approvals.length !== nextApprovals.length || approvals.some((approval, index) => approval !== nextApprovals[index])) {
|
|
8238
|
-
await writeApprovals(
|
|
8477
|
+
await writeApprovals(path6, nextApprovals);
|
|
8239
8478
|
}
|
|
8240
8479
|
} finally {
|
|
8241
8480
|
await releaseLock();
|
|
@@ -8249,7 +8488,7 @@ async function approveCursorSessionMcpServer(args) {
|
|
|
8249
8488
|
cwd: args.cwd,
|
|
8250
8489
|
env: args.env
|
|
8251
8490
|
});
|
|
8252
|
-
const
|
|
8491
|
+
const path6 = join2(
|
|
8253
8492
|
cursorDataDirectory(args.env),
|
|
8254
8493
|
"projects",
|
|
8255
8494
|
cursorProjectSlug(projectRoot),
|
|
@@ -8260,14 +8499,14 @@ async function approveCursorSessionMcpServer(args) {
|
|
|
8260
8499
|
projectRoot
|
|
8261
8500
|
});
|
|
8262
8501
|
let installedByBb = false;
|
|
8263
|
-
await mutateApprovals(
|
|
8502
|
+
await mutateApprovals(path6, (approvals) => {
|
|
8264
8503
|
if (approvals.includes(approval)) {
|
|
8265
8504
|
return approvals;
|
|
8266
8505
|
}
|
|
8267
8506
|
installedByBb = true;
|
|
8268
8507
|
return [...approvals, approval];
|
|
8269
8508
|
});
|
|
8270
|
-
return { approval, installedByBb, path:
|
|
8509
|
+
return { approval, installedByBb, path: path6 };
|
|
8271
8510
|
}
|
|
8272
8511
|
async function revokeCursorSessionMcpServer(approval) {
|
|
8273
8512
|
if (!approval.installedByBb) {
|
|
@@ -8334,6 +8573,29 @@ function sendThreadDeltas(threadId, deltas) {
|
|
|
8334
8573
|
deltas: [...deltas]
|
|
8335
8574
|
});
|
|
8336
8575
|
}
|
|
8576
|
+
function rememberGrokContextWindow(session, models) {
|
|
8577
|
+
if (session.dialect.id !== "grok") {
|
|
8578
|
+
return;
|
|
8579
|
+
}
|
|
8580
|
+
const size = grokContextWindowSizeFromSessionModels(models);
|
|
8581
|
+
if (size !== void 0) {
|
|
8582
|
+
session.grokContextWindowSize = size;
|
|
8583
|
+
}
|
|
8584
|
+
}
|
|
8585
|
+
function emitGrokContextWindow(session, used) {
|
|
8586
|
+
if (session.dialect.id !== "grok" || session.grokContextWindowSize === void 0) {
|
|
8587
|
+
return;
|
|
8588
|
+
}
|
|
8589
|
+
sendThreadDeltas(session.bbThreadId, [
|
|
8590
|
+
{
|
|
8591
|
+
kind: "contextWindow",
|
|
8592
|
+
used,
|
|
8593
|
+
size: session.grokContextWindowSize,
|
|
8594
|
+
estimated: false,
|
|
8595
|
+
attach: "open"
|
|
8596
|
+
}
|
|
8597
|
+
]);
|
|
8598
|
+
}
|
|
8337
8599
|
function emitForSession(session, method, params) {
|
|
8338
8600
|
sendThreadDeltas(
|
|
8339
8601
|
session.bbThreadId,
|
|
@@ -8641,7 +8903,7 @@ async function authenticateAcpAgent(args) {
|
|
|
8641
8903
|
await args.connection.request({
|
|
8642
8904
|
method: "authenticate",
|
|
8643
8905
|
params: { methodId, _meta: { headless: true } },
|
|
8644
|
-
resultSchema:
|
|
8906
|
+
resultSchema: z43.unknown()
|
|
8645
8907
|
});
|
|
8646
8908
|
} catch (error) {
|
|
8647
8909
|
throw new AcpAuthRequiredError(
|
|
@@ -8971,7 +9233,7 @@ async function selectAcpNativeModel(args) {
|
|
|
8971
9233
|
configId: modelOption.id,
|
|
8972
9234
|
value: selection.modelId
|
|
8973
9235
|
},
|
|
8974
|
-
resultSchema:
|
|
9236
|
+
resultSchema: z43.union([acpConfigStateResultSchema, z43.null()])
|
|
8975
9237
|
});
|
|
8976
9238
|
setModel = false;
|
|
8977
9239
|
} catch {
|
|
@@ -8982,7 +9244,7 @@ async function selectAcpNativeModel(args) {
|
|
|
8982
9244
|
configState = await args.connection.request({
|
|
8983
9245
|
method: "session/set_model",
|
|
8984
9246
|
params: { sessionId: args.sessionId, modelId: selection.modelId },
|
|
8985
|
-
resultSchema:
|
|
9247
|
+
resultSchema: z43.union([acpConfigStateResultSchema, z43.null()])
|
|
8986
9248
|
});
|
|
8987
9249
|
}
|
|
8988
9250
|
configOptions = configState?.configOptions ?? configOptions;
|
|
@@ -9237,7 +9499,7 @@ async function handleFsReadTextFile(params, responder) {
|
|
|
9237
9499
|
return;
|
|
9238
9500
|
}
|
|
9239
9501
|
try {
|
|
9240
|
-
const content = await
|
|
9502
|
+
const content = await fs3.readFile(parsed.data.path, "utf8");
|
|
9241
9503
|
responder.result({
|
|
9242
9504
|
content: sliceFileContent(content, parsed.data.line, parsed.data.limit)
|
|
9243
9505
|
});
|
|
@@ -9264,12 +9526,12 @@ async function handleFsWriteTextFile(session, params, responder) {
|
|
|
9264
9526
|
try {
|
|
9265
9527
|
let oldText;
|
|
9266
9528
|
try {
|
|
9267
|
-
oldText = await
|
|
9529
|
+
oldText = await fs3.readFile(parsed.data.path, "utf8");
|
|
9268
9530
|
} catch {
|
|
9269
9531
|
oldText = void 0;
|
|
9270
9532
|
}
|
|
9271
|
-
await
|
|
9272
|
-
await
|
|
9533
|
+
await fs3.mkdir(dirname2(parsed.data.path), { recursive: true });
|
|
9534
|
+
await fs3.writeFile(parsed.data.path, parsed.data.content, "utf8");
|
|
9273
9535
|
emitForSession(session, ACP_FS_WRITE_METHOD, {
|
|
9274
9536
|
threadId: session.bbThreadId,
|
|
9275
9537
|
path: parsed.data.path,
|
|
@@ -9403,6 +9665,7 @@ async function startAgentSession(request) {
|
|
|
9403
9665
|
loading: false,
|
|
9404
9666
|
loadingSessionId: void 0,
|
|
9405
9667
|
pendingLoadUsageUpdate: void 0,
|
|
9668
|
+
grokContextWindowSize: void 0,
|
|
9406
9669
|
stopping: false,
|
|
9407
9670
|
turnSettled: void 0,
|
|
9408
9671
|
pendingPermissions: /* @__PURE__ */ new Set(),
|
|
@@ -9449,6 +9712,7 @@ async function startAgentSession(request) {
|
|
|
9449
9712
|
let sessionId;
|
|
9450
9713
|
let loadedConfigOptions;
|
|
9451
9714
|
let loadedModels;
|
|
9715
|
+
let createdFreshSession = false;
|
|
9452
9716
|
if (request.kind === "fork") {
|
|
9453
9717
|
const forkedSession = await connection.request({
|
|
9454
9718
|
method: "session/fork",
|
|
@@ -9467,6 +9731,7 @@ async function startAgentSession(request) {
|
|
|
9467
9731
|
sessionId = forkedSession.sessionId;
|
|
9468
9732
|
loadedConfigOptions = forkedSession.configOptions;
|
|
9469
9733
|
loadedModels = forkedSession.models;
|
|
9734
|
+
rememberGrokContextWindow(session, forkedSession.models);
|
|
9470
9735
|
} else if (request.kind === "resume" && supportsLoadSession) {
|
|
9471
9736
|
session.loading = true;
|
|
9472
9737
|
session.loadingSessionId = request.resumeProviderThreadId;
|
|
@@ -9479,10 +9744,11 @@ async function startAgentSession(request) {
|
|
|
9479
9744
|
cwd: params.cwd,
|
|
9480
9745
|
mcpServers
|
|
9481
9746
|
},
|
|
9482
|
-
resultSchema:
|
|
9747
|
+
resultSchema: z43.union([acpConfigStateResultSchema, z43.null()])
|
|
9483
9748
|
});
|
|
9484
9749
|
loadedConfigOptions = configState?.configOptions;
|
|
9485
9750
|
loadedModels = configState?.models;
|
|
9751
|
+
rememberGrokContextWindow(session, configState?.models);
|
|
9486
9752
|
sessionId = request.resumeProviderThreadId;
|
|
9487
9753
|
} catch {
|
|
9488
9754
|
sessionId = void 0;
|
|
@@ -9501,6 +9767,8 @@ async function startAgentSession(request) {
|
|
|
9501
9767
|
resultSchema: acpSessionNewResultSchema
|
|
9502
9768
|
});
|
|
9503
9769
|
sessionId = newSession.sessionId;
|
|
9770
|
+
createdFreshSession = true;
|
|
9771
|
+
rememberGrokContextWindow(session, newSession.models);
|
|
9504
9772
|
await selectAcpNativeModel({
|
|
9505
9773
|
connection,
|
|
9506
9774
|
sessionId,
|
|
@@ -9548,6 +9816,9 @@ async function startAgentSession(request) {
|
|
|
9548
9816
|
sessionRestorable: session.supportsLoadSession
|
|
9549
9817
|
});
|
|
9550
9818
|
sendThreadDeltas(bbThreadId, [{ kind: "session.reset" }]);
|
|
9819
|
+
if (createdFreshSession) {
|
|
9820
|
+
emitGrokContextWindow(session, 0);
|
|
9821
|
+
}
|
|
9551
9822
|
session.deferStartEmit = void 0;
|
|
9552
9823
|
for (const deferred of deferredEmits) {
|
|
9553
9824
|
if (deferred.sessionId !== void 0 && deferred.sessionId !== sessionId) {
|
|
@@ -9700,6 +9971,10 @@ function runTurn(session, firstInput) {
|
|
|
9700
9971
|
}
|
|
9701
9972
|
const result = await promptResult;
|
|
9702
9973
|
stopReason = result.stopReason;
|
|
9974
|
+
const grokUsage = grokContextUsageFromPromptResult(result);
|
|
9975
|
+
if (grokUsage !== void 0) {
|
|
9976
|
+
emitGrokContextWindow(session, grokUsage.used);
|
|
9977
|
+
}
|
|
9703
9978
|
} catch (error) {
|
|
9704
9979
|
session.promptRequestPending = false;
|
|
9705
9980
|
dropTurnInput(pending, "ACP turn failed before the prompt was sent");
|
|
@@ -9749,6 +10024,10 @@ function startCompaction(session, pending) {
|
|
|
9749
10024
|
});
|
|
9750
10025
|
acceptTurnInput(session, pending);
|
|
9751
10026
|
session.turnSettled = promptResult.then((result) => {
|
|
10027
|
+
const grokUsage = grokContextUsageFromPromptResult(result);
|
|
10028
|
+
if (grokUsage !== void 0) {
|
|
10029
|
+
emitGrokContextWindow(session, grokUsage.used);
|
|
10030
|
+
}
|
|
9752
10031
|
finish(
|
|
9753
10032
|
result.stopReason === "end_turn" ? compactionOutcomeForEndTurn(
|
|
9754
10033
|
session.dialect,
|
|
@@ -9925,12 +10204,12 @@ function decodeLaunchSpec(providerOptions) {
|
|
|
9925
10204
|
);
|
|
9926
10205
|
return launchSpec.success ? launchSpec.data : null;
|
|
9927
10206
|
}
|
|
9928
|
-
var acpProviderOptionsSchema =
|
|
9929
|
-
additionalWorkspaceWriteRoots:
|
|
9930
|
-
acpDialect:
|
|
9931
|
-
parameterizedModelPicker:
|
|
9932
|
-
primaryModels:
|
|
9933
|
-
reasoningProbePriorityModelIds:
|
|
10207
|
+
var acpProviderOptionsSchema = z43.object({
|
|
10208
|
+
additionalWorkspaceWriteRoots: z43.array(z43.string()).optional(),
|
|
10209
|
+
acpDialect: z43.string().min(1).optional(),
|
|
10210
|
+
parameterizedModelPicker: z43.boolean().optional(),
|
|
10211
|
+
primaryModels: z43.array(z43.string().min(1)).optional(),
|
|
10212
|
+
reasoningProbePriorityModelIds: z43.array(z43.string().min(1)).optional()
|
|
9934
10213
|
}).passthrough();
|
|
9935
10214
|
function decodeAcpModelPickerOptions(providerOptions) {
|
|
9936
10215
|
const parsed = acpProviderOptionsSchema.parse(providerOptions ?? {});
|
|
@@ -9948,18 +10227,17 @@ function decodeAdditionalWorkspaceWriteRoots(providerOptions) {
|
|
|
9948
10227
|
function decodeDialectId(providerOptions) {
|
|
9949
10228
|
return acpProviderOptionsSchema.parse(providerOptions ?? {}).acpDialect;
|
|
9950
10229
|
}
|
|
9951
|
-
function maintenanceForRequest(providerOptions, launchSpec) {
|
|
9952
|
-
const dialectId = decodeDialectId(providerOptions);
|
|
9953
|
-
return resolveAcpDialect({
|
|
9954
|
-
...dialectId === void 0 ? {} : { dialectId },
|
|
9955
|
-
command: launchSpec?.command ?? ""
|
|
9956
|
-
}).maintenance;
|
|
9957
|
-
}
|
|
9958
10230
|
function maintenanceTarget(providerOptions) {
|
|
9959
10231
|
const launchSpec = decodeLaunchSpec(providerOptions);
|
|
10232
|
+
const dialect = resolveAcpDialect({
|
|
10233
|
+
dialectId: decodeDialectId(providerOptions),
|
|
10234
|
+
command: launchSpec?.command ?? ""
|
|
10235
|
+
});
|
|
9960
10236
|
return {
|
|
9961
|
-
maintenance:
|
|
9962
|
-
command: launchSpec?.command ?? null
|
|
10237
|
+
maintenance: dialect.maintenance,
|
|
10238
|
+
command: launchSpec?.command ?? null,
|
|
10239
|
+
dialectId: dialect.id,
|
|
10240
|
+
env: { ...process.env, ...launchSpec?.env }
|
|
9963
10241
|
};
|
|
9964
10242
|
}
|
|
9965
10243
|
async function handleRequest2(request) {
|
|
@@ -10247,7 +10525,7 @@ var experimental_providerBridge = experimental_defineProviderBridge({
|
|
|
10247
10525
|
});
|
|
10248
10526
|
|
|
10249
10527
|
// ../provider-bridge-acp/src/probe.ts
|
|
10250
|
-
import { z as
|
|
10528
|
+
import { z as z44 } from "zod";
|
|
10251
10529
|
var PROBE_TIMEOUT_MS = 1e4;
|
|
10252
10530
|
function describe(error) {
|
|
10253
10531
|
if (error instanceof AcpAgentExitedError) {
|
|
@@ -10305,9 +10583,9 @@ async function probeAcpAgent(request) {
|
|
|
10305
10583
|
connected.kill();
|
|
10306
10584
|
}
|
|
10307
10585
|
}
|
|
10308
|
-
var acpAgentProbeSchema =
|
|
10309
|
-
|
|
10310
|
-
|
|
10586
|
+
var acpAgentProbeSchema = z44.union([
|
|
10587
|
+
z44.object({ reachable: z44.literal(true), fork: z44.boolean() }),
|
|
10588
|
+
z44.object({ reachable: z44.literal(false), reason: z44.string() })
|
|
10311
10589
|
]);
|
|
10312
10590
|
export {
|
|
10313
10591
|
acpAgentProbeSchema as experimental_acpAgentProbeSchema,
|