@chrisromp/copilot-bridge 0.10.0 → 0.11.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/README.md +4 -0
- package/config.sample.json +20 -0
- package/dist/config.d.ts +9 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +117 -0
- package/dist/config.js.map +1 -1
- package/dist/core/bridge-docs.d.ts +1 -1
- package/dist/core/bridge-docs.d.ts.map +1 -1
- package/dist/core/bridge-docs.js +133 -1
- package/dist/core/bridge-docs.js.map +1 -1
- package/dist/core/bridge.d.ts +14 -1
- package/dist/core/bridge.d.ts.map +1 -1
- package/dist/core/bridge.js +22 -2
- package/dist/core/bridge.js.map +1 -1
- package/dist/core/command-handler.d.ts +16 -4
- package/dist/core/command-handler.d.ts.map +1 -1
- package/dist/core/command-handler.js +246 -49
- package/dist/core/command-handler.js.map +1 -1
- package/dist/core/model-fallback.d.ts +2 -2
- package/dist/core/model-fallback.d.ts.map +1 -1
- package/dist/core/model-fallback.js +11 -4
- package/dist/core/model-fallback.js.map +1 -1
- package/dist/core/session-manager.d.ts +3 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +126 -21
- package/dist/core/session-manager.js.map +1 -1
- package/dist/index.js +90 -7
- package/dist/index.js.map +1 -1
- package/dist/state/store.d.ts +1 -0
- package/dist/state/store.d.ts.map +1 -1
- package/dist/state/store.js +13 -2
- package/dist/state/store.js.map +1 -1
- package/dist/types.d.ts +20 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/templates/admin/AGENTS.md +36 -0
package/dist/core/bridge.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CopilotSession, type SessionMetadata, type ModelInfo, type GetAuthStatusResponse, type SessionListFilter, type PermissionHandler, type CustomAgentConfig, type MCPServerConfig, type SystemMessageConfig, type SessionLifecycleHandler, type Tool } from '@github/copilot-sdk';
|
|
2
2
|
import type { SessionHooks } from './hooks-loader.js';
|
|
3
|
+
import type { BridgeProviderConfig } from '../types.js';
|
|
3
4
|
type UserInputHandler = (request: {
|
|
4
5
|
question: string;
|
|
5
6
|
choices?: string[];
|
|
@@ -13,6 +14,16 @@ type UserInputHandler = (request: {
|
|
|
13
14
|
answer: string;
|
|
14
15
|
wasFreeform: boolean;
|
|
15
16
|
};
|
|
17
|
+
export interface SDKProviderConfig {
|
|
18
|
+
type?: 'openai' | 'azure' | 'anthropic';
|
|
19
|
+
wireApi?: 'completions' | 'responses';
|
|
20
|
+
baseUrl: string;
|
|
21
|
+
apiKey?: string;
|
|
22
|
+
bearerToken?: string;
|
|
23
|
+
azure?: {
|
|
24
|
+
apiVersion?: string;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
16
27
|
export declare class CopilotBridge {
|
|
17
28
|
private client;
|
|
18
29
|
private sessions;
|
|
@@ -24,6 +35,7 @@ export declare class CopilotBridge {
|
|
|
24
35
|
stop(): Promise<void>;
|
|
25
36
|
createSession(opts: {
|
|
26
37
|
model?: string;
|
|
38
|
+
provider?: SDKProviderConfig;
|
|
27
39
|
workingDirectory?: string;
|
|
28
40
|
configDir?: string;
|
|
29
41
|
reasoningEffort?: 'low' | 'medium' | 'high' | 'xhigh';
|
|
@@ -45,6 +57,7 @@ export declare class CopilotBridge {
|
|
|
45
57
|
customAgents?: CustomAgentConfig[];
|
|
46
58
|
configDir?: string;
|
|
47
59
|
workingDirectory?: string;
|
|
60
|
+
provider?: SDKProviderConfig;
|
|
48
61
|
reasoningEffort?: 'low' | 'medium' | 'high' | 'xhigh';
|
|
49
62
|
mcpServers?: Record<string, MCPServerConfig>;
|
|
50
63
|
skillDirectories?: string[];
|
|
@@ -54,7 +67,7 @@ export declare class CopilotBridge {
|
|
|
54
67
|
infiniteSessions?: boolean;
|
|
55
68
|
}): Promise<CopilotSession>;
|
|
56
69
|
listSessions(filter?: SessionListFilter): Promise<SessionMetadata[]>;
|
|
57
|
-
listModels(): Promise<ModelInfo[]>;
|
|
70
|
+
listModels(providers?: Record<string, BridgeProviderConfig>): Promise<ModelInfo[]>;
|
|
58
71
|
getAuthStatus(): Promise<GetAuthStatusResponse>;
|
|
59
72
|
getSession(id: string): CopilotSession | undefined;
|
|
60
73
|
releaseSession(id: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../src/core/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EAId,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,EAC5B,KAAK,IAAI,EACV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../src/core/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EAId,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,EAC5B,KAAK,IAAI,EACV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAGxD,KAAK,gBAAgB,GAAG,CACtB,OAAO,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,aAAa,CAAC,EAAE,OAAO,CAAA;CAAE,EAC1E,UAAU,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAA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AAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAMxD,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAMvC,SAAS,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,cAAc,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAK3G"}
|
package/dist/core/bridge.js
CHANGED
|
@@ -40,6 +40,7 @@ export class CopilotBridge {
|
|
|
40
40
|
const session = await this.client.createSession({
|
|
41
41
|
clientName: 'copilot-bridge',
|
|
42
42
|
model: opts.model,
|
|
43
|
+
provider: opts.provider,
|
|
43
44
|
workingDirectory: opts.workingDirectory,
|
|
44
45
|
configDir: opts.configDir,
|
|
45
46
|
reasoningEffort: opts.reasoningEffort,
|
|
@@ -72,6 +73,7 @@ export class CopilotBridge {
|
|
|
72
73
|
customAgents: opts?.customAgents,
|
|
73
74
|
configDir: opts?.configDir,
|
|
74
75
|
workingDirectory: opts?.workingDirectory,
|
|
76
|
+
provider: opts?.provider,
|
|
75
77
|
reasoningEffort: opts?.reasoningEffort,
|
|
76
78
|
mcpServers: opts?.mcpServers,
|
|
77
79
|
skillDirectories: opts?.skillDirectories,
|
|
@@ -87,9 +89,27 @@ export class CopilotBridge {
|
|
|
87
89
|
await this.start();
|
|
88
90
|
return this.client.listSessions(filter);
|
|
89
91
|
}
|
|
90
|
-
async listModels() {
|
|
92
|
+
async listModels(providers) {
|
|
91
93
|
await this.start();
|
|
92
|
-
|
|
94
|
+
const copilotModels = await this.client.listModels();
|
|
95
|
+
if (!providers || Object.keys(providers).length === 0) {
|
|
96
|
+
return copilotModels;
|
|
97
|
+
}
|
|
98
|
+
// Append BYOK provider models with prefixed IDs
|
|
99
|
+
const byokModels = [];
|
|
100
|
+
for (const [provName, prov] of Object.entries(providers)) {
|
|
101
|
+
for (const m of prov.models) {
|
|
102
|
+
byokModels.push({
|
|
103
|
+
id: `${provName}:${m.id}`,
|
|
104
|
+
name: m.name ?? m.id,
|
|
105
|
+
capabilities: {
|
|
106
|
+
supports: { vision: false, reasoningEffort: false },
|
|
107
|
+
limits: { max_context_window_tokens: m.contextWindow ?? 0 },
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return [...copilotModels, ...byokModels];
|
|
93
113
|
}
|
|
94
114
|
async getAuthStatus() {
|
|
95
115
|
await this.start();
|
package/dist/core/bridge.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../src/core/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,UAAU,GAaX,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../src/core/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,UAAU,GAaX,MAAM,qBAAqB,CAAC;AAoB7B,MAAM,OAAO,aAAa;IAChB,MAAM,CAAgB;IACtB,QAAQ,GAAG,IAAI,GAAG,EAA0B,CAAC;IAC7C,OAAO,GAAG,KAAK,CAAC;IAChB,oBAAoB,CAAc;IAE1C,gBAAgB,CAA2B;IAE3C;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,aAAa,CAAC;YAC9B,SAAS,EAAE,IAAI;YACf,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO;QACzB,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE;YACnD,IAAI,CAAC,gBAAgB,EAAE,CA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U,EAAE,SAAiB;QAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACtC,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;QAC1D,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;IACvD,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAAU;QAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACtC,IAAI,CAAC,OAAO;YAAE,MAAM,IAAI,KAAK,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;QAC1D,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,KAAc;QAC5B,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QACnB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAC3D,OAAO,MAAM,CAAC,KAAK,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { BridgeProviderConfig } from '../types.js';
|
|
1
2
|
export interface ModelInfo {
|
|
2
3
|
id: string;
|
|
3
4
|
name: string;
|
|
@@ -10,16 +11,27 @@ export interface ModelInfo {
|
|
|
10
11
|
export interface CommandResult {
|
|
11
12
|
handled: boolean;
|
|
12
13
|
response?: string;
|
|
13
|
-
action?: 'new_session' | 'reload_session' | 'reload_config' | 'resume_session' | 'list_sessions' | 'switch_model' | 'switch_agent' | 'toggle_verbose' | 'approve' | 'deny' | 'toggle_autopilot' | 'remember' | 'remember_deny' | 'remember_list' | 'remember_clear' | 'set_reasoning' | 'stop_session' | 'schedule' | 'skills' | 'skill_toggle' | 'mcp' | 'plan' | 'implement';
|
|
14
|
+
action?: 'new_session' | 'reload_session' | 'reload_config' | 'resume_session' | 'list_sessions' | 'switch_model' | 'switch_agent' | 'toggle_verbose' | 'approve' | 'deny' | 'toggle_autopilot' | 'remember' | 'remember_deny' | 'remember_list' | 'remember_clear' | 'set_reasoning' | 'stop_session' | 'schedule' | 'skills' | 'skill_toggle' | 'mcp' | 'plan' | 'implement' | 'provider_test';
|
|
14
15
|
payload?: any;
|
|
15
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Parse user input that may contain a provider prefix (e.g., "ollama-local:qwen3:8b").
|
|
19
|
+
* Splits on the first colon, checks if the prefix is a known provider name.
|
|
20
|
+
* Returns { provider, bareModel } if a provider prefix was found, or null if not.
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseProviderModel(input: string, providerNames: string[]): {
|
|
23
|
+
provider: string;
|
|
24
|
+
bareModel: string;
|
|
25
|
+
} | null;
|
|
16
26
|
/**
|
|
17
27
|
* Fuzzy-match user input to a model from the available list.
|
|
18
|
-
*
|
|
28
|
+
* Supports provider:model syntax (e.g., "ollama-local:qwen3:8b") and bare model
|
|
29
|
+
* names that resolve against Copilot models first, then BYOK providers.
|
|
30
|
+
* Returns:
|
|
19
31
|
* - { model, alternatives } on success (alternatives may be empty)
|
|
20
32
|
* - { error } only when truly no match is found
|
|
21
33
|
*/
|
|
22
|
-
export declare function resolveModel(input: string, models: ModelInfo[]): {
|
|
34
|
+
export declare function resolveModel(input: string, models: ModelInfo[], providerNames?: string[]): {
|
|
23
35
|
model: ModelInfo;
|
|
24
36
|
alternatives: ModelInfo[];
|
|
25
37
|
} | {
|
|
@@ -50,5 +62,5 @@ export declare function handleCommand(channelId: string, text: string, sessionIn
|
|
|
50
62
|
currentTokens: number;
|
|
51
63
|
tokenLimit: number;
|
|
52
64
|
contextWindowTokens?: number;
|
|
53
|
-
} | null): CommandResult;
|
|
65
|
+
} | null, providers?: Record<string, BridgeProviderConfig>): CommandResult;
|
|
54
66
|
//# sourceMappingURL=command-handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-handler.d.ts","sourceRoot":"","sources":["../../src/core/command-handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"command-handler.d.ts","sourceRoot":"","sources":["../../src/core/command-handler.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AA6BxD,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IACjC,yBAAyB,CAAC,EAAE,MAAM,EAAE,CAAC;IACrC,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,aAAa,GAAG,gBAAgB,GAAG,eAAe,GAAG,gBAAgB,GAAG,eAAe,GAAG,cAAc,GAAG,cAAc,GAAG,gBAAgB,GAC5I,SAAS,GAAG,MAAM,GAAG,kBAAkB,GAAG,UAAU,GAAG,eAAe,GAAG,eAAe,GAAG,gBAAgB,GAAG,eAAe,GAAG,cAAc,GAAG,UAAU,GAAG,QAAQ,GAAG,cAAc,GAAG,KAAK,GAAG,MAAM,GAAG,WAAW,GAAG,eAAe,CAAC;IAClP,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CASzH;AAED;;;;;;;GAOG;AACH,wBA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AAE,oBAAoB,CAAC,GAAG,aAAa,CA0bvf"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { setChannelPrefs, getChannelPrefs, getGlobalSetting, setGlobalSetting } from '../state/store.js';
|
|
2
2
|
import { discoverAgentDefinitions, discoverAgentNames } from './inter-agent.js';
|
|
3
|
+
import { isBotAdminAny } from '../config.js';
|
|
3
4
|
const VALID_REASONING_EFFORTS = new Set(['low', 'medium', 'high', 'xhigh']);
|
|
4
5
|
const TRUTHY = new Set(['on', 'true', 'yes', '1', 'enable', 'enabled']);
|
|
5
6
|
const FALSY = new Set(['off', 'false', 'no', '0', 'disable', 'disabled']);
|
|
@@ -24,40 +25,73 @@ function redactedModelLabel(index) {
|
|
|
24
25
|
function isStreamerMode() {
|
|
25
26
|
return getGlobalSetting('streamer_mode') === '1';
|
|
26
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Parse user input that may contain a provider prefix (e.g., "ollama-local:qwen3:8b").
|
|
30
|
+
* Splits on the first colon, checks if the prefix is a known provider name.
|
|
31
|
+
* Returns { provider, bareModel } if a provider prefix was found, or null if not.
|
|
32
|
+
*/
|
|
33
|
+
export function parseProviderModel(input, providerNames) {
|
|
34
|
+
const colonIdx = input.indexOf(':');
|
|
35
|
+
if (colonIdx <= 0)
|
|
36
|
+
return null;
|
|
37
|
+
const prefix = input.slice(0, colonIdx);
|
|
38
|
+
const canonical = providerNames.find(p => p.toLowerCase() === prefix.toLowerCase());
|
|
39
|
+
if (canonical) {
|
|
40
|
+
return { provider: canonical, bareModel: input.slice(colonIdx + 1) };
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
27
44
|
/**
|
|
28
45
|
* Fuzzy-match user input to a model from the available list.
|
|
29
|
-
*
|
|
46
|
+
* Supports provider:model syntax (e.g., "ollama-local:qwen3:8b") and bare model
|
|
47
|
+
* names that resolve against Copilot models first, then BYOK providers.
|
|
48
|
+
* Returns:
|
|
30
49
|
* - { model, alternatives } on success (alternatives may be empty)
|
|
31
50
|
* - { error } only when truly no match is found
|
|
32
51
|
*/
|
|
33
|
-
export function resolveModel(input, models) {
|
|
52
|
+
export function resolveModel(input, models, providerNames) {
|
|
34
53
|
const lower = input.toLowerCase().trim();
|
|
35
54
|
if (!lower)
|
|
36
55
|
return { error: '⚠️ Please specify a model name.' };
|
|
37
|
-
|
|
56
|
+
const providers = providerNames ?? [];
|
|
57
|
+
// Check for provider:model syntax — if prefix is a known provider, scope to that provider's models
|
|
58
|
+
const parsed = parseProviderModel(lower, providers);
|
|
59
|
+
if (parsed) {
|
|
60
|
+
if (!parsed.bareModel)
|
|
61
|
+
return { error: '⚠️ Please specify a model name after the provider prefix.' };
|
|
62
|
+
const prefixed = `${parsed.provider}:${parsed.bareModel}`;
|
|
63
|
+
const scoped = models.filter(m => m.id.toLowerCase().startsWith(`${parsed.provider.toLowerCase()}:`));
|
|
64
|
+
// Exact match on full prefixed ID
|
|
65
|
+
const exact = scoped.find(m => m.id.toLowerCase() === prefixed);
|
|
66
|
+
if (exact)
|
|
67
|
+
return { model: exact, alternatives: [] };
|
|
68
|
+
// Fuzzy within provider scope
|
|
69
|
+
return fuzzyMatch(parsed.bareModel, scoped, `provider "${parsed.provider}"`);
|
|
70
|
+
}
|
|
71
|
+
// Exact match on id or name (works for both Copilot and full BYOK IDs)
|
|
38
72
|
const exact = models.find(m => m.id.toLowerCase() === lower || m.name.toLowerCase() === lower);
|
|
39
73
|
if (exact)
|
|
40
74
|
return { model: exact, alternatives: [] };
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
75
|
+
// For bare model input, try Copilot models first, then BYOK
|
|
76
|
+
if (providers.length > 0) {
|
|
77
|
+
const copilotModels = models.filter(m => !providers.some(p => m.id.toLowerCase().startsWith(`${p.toLowerCase()}:`)));
|
|
78
|
+
const copilotResult = fuzzyMatch(lower, copilotModels);
|
|
79
|
+
if ('model' in copilotResult)
|
|
80
|
+
return copilotResult;
|
|
81
|
+
// Try each BYOK provider in config order
|
|
82
|
+
for (const prov of providers) {
|
|
83
|
+
const provModels = models.filter(m => m.id.toLowerCase().startsWith(`${prov.toLowerCase()}:`));
|
|
84
|
+
// Match against the bare part of the ID (after provider prefix)
|
|
85
|
+
const bareExact = provModels.find(m => {
|
|
86
|
+
const bare = m.id.slice(prov.length + 1);
|
|
87
|
+
return bare.toLowerCase() === lower;
|
|
88
|
+
});
|
|
89
|
+
if (bareExact)
|
|
90
|
+
return { model: bareExact, alternatives: [] };
|
|
91
|
+
}
|
|
92
|
+
// Fall through to global fuzzy match
|
|
59
93
|
}
|
|
60
|
-
return
|
|
94
|
+
return fuzzyMatch(lower, models);
|
|
61
95
|
}
|
|
62
96
|
/** Pick the best model from ambiguous candidates. Prefers shorter IDs and closer matches. */
|
|
63
97
|
function pickBestMatch(input, candidates) {
|
|
@@ -74,6 +108,111 @@ function pickBestMatch(input, candidates) {
|
|
|
74
108
|
return a.name.length - b.name.length;
|
|
75
109
|
})[0];
|
|
76
110
|
}
|
|
111
|
+
/** Fuzzy-match input against a set of models. */
|
|
112
|
+
function fuzzyMatch(input, models, scope) {
|
|
113
|
+
if (models.length === 0) {
|
|
114
|
+
return { error: scope
|
|
115
|
+
? `⚠️ No models found for ${scope}.`
|
|
116
|
+
: `⚠️ Unknown model "${input}". Use \`/model\` to see available models.` };
|
|
117
|
+
}
|
|
118
|
+
// Substring match
|
|
119
|
+
const substringMatches = models.filter(m => m.id.toLowerCase().includes(input) || m.name.toLowerCase().includes(input));
|
|
120
|
+
if (substringMatches.length === 1)
|
|
121
|
+
return { model: substringMatches[0], alternatives: [] };
|
|
122
|
+
// Token match
|
|
123
|
+
const tokens = input.split(/[\s\-_.]+/).filter(Boolean);
|
|
124
|
+
const tokenMatches = models.filter(m => {
|
|
125
|
+
const haystack = `${m.id} ${m.name}`.toLowerCase();
|
|
126
|
+
return tokens.every(t => haystack.includes(t));
|
|
127
|
+
});
|
|
128
|
+
if (tokenMatches.length === 1)
|
|
129
|
+
return { model: tokenMatches[0], alternatives: [] };
|
|
130
|
+
// Multiple matches — pick best
|
|
131
|
+
const candidates = (substringMatches.length > 0 ? substringMatches : tokenMatches).slice(0, 8);
|
|
132
|
+
if (candidates.length > 1) {
|
|
133
|
+
const best = pickBestMatch(input, candidates);
|
|
134
|
+
const alternatives = candidates.filter(m => m.id !== best.id);
|
|
135
|
+
return { model: best, alternatives };
|
|
136
|
+
}
|
|
137
|
+
return { error: scope
|
|
138
|
+
? `⚠️ Unknown model "${input}" in ${scope}. Use \`/model\` to see available models.`
|
|
139
|
+
: `⚠️ Unknown model "${input}". Use \`/model\` to see available models.` };
|
|
140
|
+
}
|
|
141
|
+
/** Build the formatted model listing, optionally grouped by provider. */
|
|
142
|
+
function formatModelListing(models, providerNames, currentModel, currentProvider, filterProvider) {
|
|
143
|
+
const streamer = isStreamerMode();
|
|
144
|
+
let hiddenIndex = 0;
|
|
145
|
+
// Determine if the current model matches a given model entry
|
|
146
|
+
const isCurrent = (m) => {
|
|
147
|
+
if (!currentModel)
|
|
148
|
+
return false;
|
|
149
|
+
if (currentProvider) {
|
|
150
|
+
// BYOK active: only match the prefixed BYOK entry, not the Copilot model with the same bare name
|
|
151
|
+
return m.id === `${currentProvider}:${currentModel}`;
|
|
152
|
+
}
|
|
153
|
+
return m.id === currentModel;
|
|
154
|
+
};
|
|
155
|
+
const formatRow = (m, showBilling) => {
|
|
156
|
+
const current = isCurrent(m) ? ' ← current' : '';
|
|
157
|
+
const reasoning = m.supportedReasoningEfforts?.length ? ' 🧠' : '';
|
|
158
|
+
const hidden = streamer && isHiddenModel(m);
|
|
159
|
+
const displayName = hidden ? redactedModelLabel(++hiddenIndex) : `\`${m.id}\``;
|
|
160
|
+
if (showBilling) {
|
|
161
|
+
const billing = m.billing ? `${m.billing.multiplier}x` : '—';
|
|
162
|
+
return `| ${displayName} | ${billing} |${reasoning}${current} |`;
|
|
163
|
+
}
|
|
164
|
+
return `| ${displayName} |${reasoning}${current} |`;
|
|
165
|
+
};
|
|
166
|
+
const copilotHeader = '| Model | Billing | |\n|:------|--------:|:--|';
|
|
167
|
+
const byokHeader = '| Model | |\n|:------|:--|';
|
|
168
|
+
const title = filterProvider ? `**Models: ${filterProvider}**` : '**Available Models**';
|
|
169
|
+
const lines = [title, ''];
|
|
170
|
+
if (providerNames.length > 0 && !filterProvider) {
|
|
171
|
+
// Group by provider: Copilot first, then each BYOK provider
|
|
172
|
+
const copilotModels = models.filter(m => !providerNames.some(p => m.id.startsWith(`${p}:`)));
|
|
173
|
+
if (copilotModels.length > 0) {
|
|
174
|
+
lines.push('**GitHub Copilot**', '', copilotHeader);
|
|
175
|
+
for (const m of copilotModels)
|
|
176
|
+
lines.push(formatRow(m, true));
|
|
177
|
+
lines.push('');
|
|
178
|
+
}
|
|
179
|
+
for (const prov of providerNames) {
|
|
180
|
+
const provModels = models.filter(m => m.id.startsWith(`${prov}:`));
|
|
181
|
+
if (provModels.length > 0) {
|
|
182
|
+
lines.push(`**${prov}**`, '', byokHeader);
|
|
183
|
+
for (const m of provModels)
|
|
184
|
+
lines.push(formatRow(m, false));
|
|
185
|
+
lines.push('');
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
else if (filterProvider) {
|
|
190
|
+
// Filtered to single BYOK provider — no billing column
|
|
191
|
+
lines.push(byokHeader);
|
|
192
|
+
for (const m of models)
|
|
193
|
+
lines.push(formatRow(m, false));
|
|
194
|
+
lines.push('');
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
// Flat listing (no providers configured)
|
|
198
|
+
lines.push(copilotHeader);
|
|
199
|
+
for (const m of models)
|
|
200
|
+
lines.push(formatRow(m, true));
|
|
201
|
+
lines.push('');
|
|
202
|
+
}
|
|
203
|
+
const hasCopilotModels = !filterProvider && models.some(m => !providerNames.some(p => m.id.startsWith(`${p}:`)));
|
|
204
|
+
const legend = hasCopilotModels
|
|
205
|
+
? '🧠 = supports reasoning effort · Billing = premium request multiplier'
|
|
206
|
+
: '🧠 = supports reasoning effort';
|
|
207
|
+
lines.push(legend);
|
|
208
|
+
lines.push('↳ Use `/model <name>` to switch');
|
|
209
|
+
if (providerNames.length > 0 && !filterProvider) {
|
|
210
|
+
const shown = providerNames.slice(0, 3).join(', ');
|
|
211
|
+
const suffix = providerNames.length > 3 ? ', …' : '';
|
|
212
|
+
lines.push(`↳ Use \`/model <provider>\` to filter (${shown}${suffix})`);
|
|
213
|
+
}
|
|
214
|
+
return lines.join('\n');
|
|
215
|
+
}
|
|
77
216
|
/** Format a token count as a human-readable string (e.g., 109000 → "109k"). */
|
|
78
217
|
function formatTokens(n) {
|
|
79
218
|
if (n >= 1000)
|
|
@@ -149,13 +288,19 @@ export function parseCommand(text) {
|
|
|
149
288
|
args: trimmed.slice(spaceIdx + 1).trim(),
|
|
150
289
|
};
|
|
151
290
|
}
|
|
152
|
-
export function handleCommand(channelId, text, sessionInfo, effectivePrefs, channelMeta, models, mcpInfo, contextUsage) {
|
|
291
|
+
export function handleCommand(channelId, text, sessionInfo, effectivePrefs, channelMeta, models, mcpInfo, contextUsage, providers) {
|
|
153
292
|
const parsed = parseCommand(text);
|
|
154
293
|
if (!parsed)
|
|
155
294
|
return { handled: false };
|
|
156
|
-
// Resolve current model's info from models list
|
|
157
|
-
|
|
158
|
-
|
|
295
|
+
// Resolve current model's info from models list (only for commands that need it)
|
|
296
|
+
// When a BYOK provider is active, prefer the provider-prefixed entry to avoid
|
|
297
|
+
// inheriting metadata (e.g., supportedReasoningEfforts) from a same-named Copilot model
|
|
298
|
+
const needsModelInfo = ['reasoning', 'status', 'model', 'models'].includes(parsed.command);
|
|
299
|
+
const currentProvider = needsModelInfo ? (getChannelPrefs(channelId)?.provider ?? null) : null;
|
|
300
|
+
const currentModelInfo = needsModelInfo && models && sessionInfo
|
|
301
|
+
? (currentProvider
|
|
302
|
+
? models.find(m => m.id === `${currentProvider}:${sessionInfo.model}`) ?? null
|
|
303
|
+
: models.find(m => m.id === sessionInfo.model) ?? null)
|
|
159
304
|
: null;
|
|
160
305
|
switch (parsed.command) {
|
|
161
306
|
case 'new':
|
|
@@ -177,38 +322,41 @@ export function handleCommand(channelId, text, sessionInfo, effectivePrefs, chan
|
|
|
177
322
|
}
|
|
178
323
|
case 'model':
|
|
179
324
|
case 'models': {
|
|
325
|
+
const providerNames = providers ? Object.keys(providers) : [];
|
|
326
|
+
const currentProvider = getChannelPrefs(channelId)?.provider ?? null;
|
|
180
327
|
if (!parsed.args) {
|
|
181
|
-
// No args: show model table
|
|
328
|
+
// No args: show model table grouped by provider
|
|
182
329
|
if (!models || models.length === 0) {
|
|
183
330
|
return { handled: true, response: '⚠️ Model list not available.' };
|
|
184
331
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
'
|
|
191
|
-
'|:------|--------:|:--|',
|
|
192
|
-
];
|
|
193
|
-
for (const m of models) {
|
|
194
|
-
const current = sessionInfo?.model === m.id ? ' ← current' : '';
|
|
195
|
-
const reasoning = m.supportedReasoningEfforts?.length ? ' 🧠' : '';
|
|
196
|
-
const billing = m.billing ? `${m.billing.multiplier}x` : '—';
|
|
197
|
-
const hidden = streamer && isHiddenModel(m);
|
|
198
|
-
const displayName = hidden ? redactedModelLabel(++hiddenIndex) : `\`${m.id}\``;
|
|
199
|
-
lines.push(`| ${displayName} | ${billing} |${reasoning}${current} |`);
|
|
332
|
+
return { handled: true, response: formatModelListing(models, providerNames, sessionInfo?.model ?? null, currentProvider) };
|
|
333
|
+
}
|
|
334
|
+
// Check if arg is a provider name → show just that provider's models
|
|
335
|
+
if (providerNames.some(p => p.toLowerCase() === parsed.args.toLowerCase().trim())) {
|
|
336
|
+
if (!models || models.length === 0) {
|
|
337
|
+
return { handled: true, response: '⚠️ Model list not available.' };
|
|
200
338
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
339
|
+
const provName = providerNames.find(p => p.toLowerCase() === parsed.args.toLowerCase().trim());
|
|
340
|
+
const provModels = models.filter(m => m.id.toLowerCase().startsWith(`${provName.toLowerCase()}:`));
|
|
341
|
+
if (provModels.length === 0) {
|
|
342
|
+
return { handled: true, response: `⚠️ No models found for provider "${provName}".` };
|
|
343
|
+
}
|
|
344
|
+
return { handled: true, response: formatModelListing(provModels, providerNames, sessionInfo?.model ?? null, currentProvider, provName) };
|
|
204
345
|
}
|
|
205
346
|
if (!models || models.length === 0) {
|
|
206
|
-
|
|
347
|
+
// Best-effort provider parsing when model list is unavailable
|
|
348
|
+
const parsedInput = parseProviderModel(parsed.args, providerNames);
|
|
349
|
+
const fallbackProvider = parsedInput?.provider ?? null;
|
|
350
|
+
const fallbackModelId = parsedInput?.bareModel ?? parsed.args;
|
|
351
|
+
return { handled: true, action: 'switch_model', payload: { modelId: fallbackModelId, provider: fallbackProvider }, response: `🔄 Switching model to **${parsed.args}**...` };
|
|
207
352
|
}
|
|
208
|
-
const result = resolveModel(parsed.args, models);
|
|
353
|
+
const result = resolveModel(parsed.args, models, providerNames);
|
|
209
354
|
if ('error' in result) {
|
|
210
355
|
return { handled: true, response: result.error };
|
|
211
356
|
}
|
|
357
|
+
// Determine provider from the resolved model ID
|
|
358
|
+
const resolvedProvider = providerNames.find(p => result.model.id.toLowerCase().startsWith(`${p.toLowerCase()}:`)) ?? null;
|
|
359
|
+
const bareModelId = resolvedProvider ? result.model.id.slice(resolvedProvider.length + 1) : result.model.id;
|
|
212
360
|
const streamerSwitch = isStreamerMode();
|
|
213
361
|
const switchName = (streamerSwitch && isHiddenModel(result.model))
|
|
214
362
|
? 'a hidden model'
|
|
@@ -221,7 +369,53 @@ export function handleCommand(channelId, text, sessionInfo, effectivePrefs, chan
|
|
|
221
369
|
if (altList)
|
|
222
370
|
response += `\n↳ Also matched: ${altList}`;
|
|
223
371
|
}
|
|
224
|
-
return { handled: true, action: 'switch_model', payload:
|
|
372
|
+
return { handled: true, action: 'switch_model', payload: { modelId: bareModelId, provider: resolvedProvider }, response };
|
|
373
|
+
}
|
|
374
|
+
case 'provider':
|
|
375
|
+
case 'providers': {
|
|
376
|
+
const providerMap = providers ?? {};
|
|
377
|
+
const provNames = Object.keys(providerMap);
|
|
378
|
+
const args = parsed.args?.trim();
|
|
379
|
+
if (!args) {
|
|
380
|
+
// List all providers
|
|
381
|
+
if (provNames.length === 0) {
|
|
382
|
+
return { handled: true, response: 'No BYOK providers configured.\n↳ Add providers in `config.json` under the `"providers"` key, then `/reload config`.' };
|
|
383
|
+
}
|
|
384
|
+
const lines = ['**Configured Providers**', ''];
|
|
385
|
+
for (const name of provNames) {
|
|
386
|
+
const p = providerMap[name];
|
|
387
|
+
const modelCount = p.models?.length ?? 0;
|
|
388
|
+
const authMethod = p.apiKeyEnv ? `apiKeyEnv: ${p.apiKeyEnv}` : p.bearerTokenEnv ? `bearerTokenEnv: ${p.bearerTokenEnv}` : p.apiKey ? 'apiKey (inline)' : p.bearerToken ? 'bearerToken (inline)' : 'none';
|
|
389
|
+
lines.push(`**${name}**`);
|
|
390
|
+
lines.push(` URL: \`${p.baseUrl}\``);
|
|
391
|
+
lines.push(` Type: ${p.type ?? 'openai'} · Auth: ${authMethod} · Models: ${modelCount}`);
|
|
392
|
+
lines.push(` Models: ${p.models.map(m => `\`${m.id}\``).join(', ')}`);
|
|
393
|
+
lines.push('');
|
|
394
|
+
}
|
|
395
|
+
lines.push('↳ Use `/provider test <name>` to test connectivity');
|
|
396
|
+
lines.push('↳ Use `/model <provider>:<model>` to switch to a provider model');
|
|
397
|
+
return { handled: true, response: lines.join('\n') };
|
|
398
|
+
}
|
|
399
|
+
// /provider test <name>
|
|
400
|
+
const testMatch = args.match(/^test\s+(.+)$/i);
|
|
401
|
+
if (testMatch) {
|
|
402
|
+
const target = testMatch[1].trim();
|
|
403
|
+
const canonical = provNames.find(p => p.toLowerCase() === target.toLowerCase());
|
|
404
|
+
if (!canonical) {
|
|
405
|
+
return { handled: true, response: `⚠️ Unknown provider "${target}". Configured: ${provNames.join(', ')}` };
|
|
406
|
+
}
|
|
407
|
+
return { handled: true, action: 'provider_test', payload: canonical, response: `🔄 Testing provider "${canonical}"...` };
|
|
408
|
+
}
|
|
409
|
+
// /provider add|remove — guide to config file (admin can help)
|
|
410
|
+
if (/^(add|remove|delete)\b/i.test(args)) {
|
|
411
|
+
const botName = channelMeta?.bot;
|
|
412
|
+
const isAdmin = botName ? isBotAdminAny(botName) : false;
|
|
413
|
+
if (isAdmin) {
|
|
414
|
+
return { handled: true, response: `Sure — I can help with that. Tell me the provider details (name, base URL, auth, models) and I'll update \`config.json\` for you.` };
|
|
415
|
+
}
|
|
416
|
+
return { handled: true, response: 'Providers are managed in `config.json` under the `"providers"` key.\n↳ Ask the **admin** bot to add/remove providers, or edit the file directly, then `/reload config`.' };
|
|
417
|
+
}
|
|
418
|
+
return { handled: true, response: '⚠️ Unknown subcommand. Usage:\n `/provider` — list providers\n `/provider test <name>` — test connectivity\n `/model <provider>:<model>` — switch model' };
|
|
225
419
|
}
|
|
226
420
|
case 'agent': {
|
|
227
421
|
const agent = parsed.args || null;
|
|
@@ -324,10 +518,11 @@ export function handleCommand(channelId, text, sessionInfo, effectivePrefs, chan
|
|
|
324
518
|
};
|
|
325
519
|
const sessionMode = prefs?.sessionMode ?? 'interactive';
|
|
326
520
|
const modeDisplay = modeLabels[sessionMode] ?? '🛡️ Interactive';
|
|
521
|
+
const providerDisplay = prefs?.provider ? `${prefs.provider}:` : '';
|
|
327
522
|
const lines = [
|
|
328
523
|
'📊 **Session Status**',
|
|
329
524
|
`• Session: \`${sessionInfo.sessionId.slice(0, 8)}...\``,
|
|
330
|
-
`• Model: **${modelDisplay}**`,
|
|
525
|
+
`• Model: **${providerDisplay}${modelDisplay}**`,
|
|
331
526
|
`• Agent: ${sessionInfo.agent ? `**${sessionInfo.agent}**` : 'Default (Copilot)'}`,
|
|
332
527
|
`• Mode: ${modeDisplay}`,
|
|
333
528
|
`• Yolo: ${(effectivePrefs?.permissionMode ?? prefs?.permissionMode) === 'autopilot' ? '🤠 On' : '🛡️ Off'}`,
|
|
@@ -487,6 +682,8 @@ export function handleCommand(channelId, text, sessionInfo, effectivePrefs, chan
|
|
|
487
682
|
'`/skills disable <name...>` — Disable skills for this channel',
|
|
488
683
|
'`/skills enable|disable all` — Enable or disable all skills',
|
|
489
684
|
'`/mcp` — Show MCP servers and their source',
|
|
685
|
+
'`/provider` — List configured BYOK providers',
|
|
686
|
+
'`/provider test <name>` — Test provider connectivity',
|
|
490
687
|
'`/plan` — Toggle plan mode (on/off)',
|
|
491
688
|
'`/plan show` — Show current plan',
|
|
492
689
|
'`/plan summary` — Show plan summary',
|