-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.ts
More file actions
170 lines (162 loc) · 4.37 KB
/
Copy pathserver.ts
File metadata and controls
170 lines (162 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import {
defineRpcContract,
type BbPluginApi,
type PluginProviderDeclaration,
} from "@get-bb/plugin-sdk";
import { z } from "zod";
import { loadUsageSnapshot } from "./lib/load-usage.ts";
import {
enabledSidebarProviderIds,
SIDEBAR_PROVIDER_IDS,
} from "./lib/preferences.ts";
import { PROVIDER_IDS } from "./lib/usage.ts";
const costSchema = z
.object({
usedUsdCents: z.number().finite(),
limitUsdCents: z.number().finite(),
})
.strict();
const usageWindowSchema = z
.object({
label: z.string(),
usedPercent: z.number().finite(),
barPercent: z.number().finite().min(0).max(100),
resetsAt: z.string().nullable(),
cost: costSchema.nullable(),
})
.strict();
const providerSchema = z
.object({
id: z.enum(PROVIDER_IDS),
name: z.string(),
status: z.enum([
"ok",
"not_installed",
"unauthenticated",
"expired",
"error",
]),
accountEmail: z.string().nullable(),
planLabel: z.string().nullable(),
message: z.string().nullable(),
windows: z.array(usageWindowSchema),
})
.strict();
export const usageRpcContract = defineRpcContract({
getPreferences: {
input: z.null(),
output: z
.object({
enabledProviderIds: z.array(z.enum(SIDEBAR_PROVIDER_IDS)),
})
.strict(),
},
getUsage: {
input: z
.object({ threadId: z.string().trim().min(1).nullable() })
.strict(),
output: z
.object({
fetchedAt: z.string(),
host: z
.object({
id: z.string().nullable(),
name: z.string().nullable(),
})
.strict(),
providers: z.array(providerSchema),
})
.strict(),
},
});
const OPENCODE2_PROVIDER: PluginProviderDeclaration = {
id: "acp-opencode2",
displayName: "OpenCode 2",
experimental_visibility: "installed",
experimental_strings: {
signInHint: "Run `opencode2 auth login` on the machine to sign in.",
expiredHint:
"Your OpenCode 2 session expired. Run `opencode2 auth login`, then reload.",
installUrl: "https://opencode.ai/v2/docs",
iconTint: { light: "#2563EB", dark: "#2563EB" },
},
experimental_serviceTiers: [
{ id: "default", label: "Default" },
{ id: "fast", label: "Fast" },
],
experimental_bridgeOptions: {
acpLaunchSpec: {
displayName: "OpenCode 2",
command: "opencode2",
args: ["acp"],
env: {},
},
},
capabilities: {
experimental_providerHealth: true,
experimental_providerUsage: false,
experimental_providerInstallation: false,
supportsServiceTier: true,
supportsNativeUserQuestion: false,
fork: "tip",
supportsManualCompaction: true,
supportsThreadArchive: false,
supportsThreadRename: false,
permissionModes: ["accept-edits", "full"],
reasoningLevels: ["low", "medium", "high", "xhigh", "max"],
},
// BB's ACP provider tier contributes the native `/` skills action.
composerActions: [],
};
export default function plugin(bb: BbPluginApi) {
const settings = bb.settings.define({
enableClaudeCode: {
type: "boolean",
label: "Enable Claude Code",
description: "Show Claude Code usage in the sidebar footer.",
default: true,
},
enableCodex: {
type: "boolean",
label: "Enable Codex",
description: "Show Codex usage in the sidebar footer.",
default: true,
},
enableCursor: {
type: "boolean",
label: "Enable Cursor",
description: "Show Cursor usage in the sidebar footer.",
default: true,
},
enableOpenCodeGo: {
type: "boolean",
label: "Enable OpenCode Go",
description: "Show the shared OpenCode and OpenCode 2 Go allowance in the sidebar footer.",
default: true,
},
openCodeGoApiKey: {
type: "string",
label: "OpenCode Go API key",
description:
"Used only by the BB host to read the shared OpenCode and OpenCode 2 Go allowance.",
secret: true,
},
});
bb.providers.register(OPENCODE2_PROVIDER);
bb.rpc.register(usageRpcContract, {
async getPreferences() {
return {
enabledProviderIds: enabledSidebarProviderIds(await settings.get()),
};
},
async getUsage({ threadId }) {
const { openCodeGoApiKey } = await settings.get();
return loadUsageSnapshot(
bb.sdk,
threadId,
new Date(),
openCodeGoApiKey ?? "",
);
},
});
}