@myrialabs/clopen 0.3.8 → 0.3.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/backend/auth/permissions.ts +41 -2
- package/backend/chat/stream-manager.ts +71 -0
- package/backend/database/migrations/032_seed_copilot_provider.ts +19 -0
- package/backend/database/migrations/033_seed_codex_provider.ts +19 -0
- package/backend/database/migrations/034_seed_qwen_provider.ts +119 -0
- package/backend/database/migrations/035_add_owner_to_db_client_connections.ts +34 -0
- package/backend/database/migrations/index.ts +29 -1
- package/backend/database/queries/db-client-connection-queries.ts +160 -54
- package/backend/database/queries/engine-queries.ts +12 -0
- package/backend/database/queries/project-queries.ts +10 -5
- package/backend/engine/README.md +1702 -0
- package/backend/engine/adapters/claude/models.ts +141 -0
- package/backend/engine/adapters/claude/stream.ts +1 -1
- package/backend/engine/adapters/codex/credential.ts +179 -0
- package/backend/engine/adapters/codex/error-handler.ts +65 -0
- package/backend/engine/adapters/codex/index.ts +1 -0
- package/backend/engine/adapters/codex/message-converter.ts +646 -0
- package/backend/engine/adapters/codex/models.ts +105 -0
- package/backend/engine/adapters/codex/patch-rollout.ts +169 -0
- package/backend/engine/adapters/codex/session-fork.ts +149 -0
- package/backend/engine/adapters/codex/stream.ts +310 -0
- package/backend/engine/adapters/codex/usage-rollout.ts +145 -0
- package/backend/engine/adapters/copilot/error-handler.ts +94 -0
- package/backend/engine/adapters/copilot/index.ts +1 -0
- package/backend/engine/adapters/copilot/message-converter.ts +973 -0
- package/backend/engine/adapters/copilot/models.ts +92 -0
- package/backend/engine/adapters/copilot/session-fork.ts +111 -0
- package/backend/engine/adapters/copilot/stream.ts +573 -0
- package/backend/engine/adapters/opencode/config.ts +56 -104
- package/backend/engine/adapters/opencode/error-handler.ts +71 -0
- package/backend/engine/adapters/opencode/models.ts +79 -0
- package/backend/engine/adapters/opencode/presets.ts +91 -0
- package/backend/engine/adapters/opencode/stream.ts +5 -115
- package/backend/engine/adapters/qwen/credential.ts +78 -0
- package/backend/engine/adapters/qwen/environment.ts +84 -0
- package/backend/engine/adapters/qwen/error-handler.ts +71 -0
- package/backend/engine/adapters/qwen/index.ts +1 -0
- package/backend/engine/adapters/qwen/message-converter.ts +1055 -0
- package/backend/engine/adapters/qwen/models.ts +81 -0
- package/backend/engine/adapters/qwen/presets.ts +51 -0
- package/backend/engine/adapters/qwen/session-fork.ts +97 -0
- package/backend/engine/adapters/qwen/stream.ts +380 -0
- package/backend/engine/index.ts +35 -0
- package/backend/engine/install-recipes.ts +80 -1
- package/backend/engine/install-runner.ts +4 -0
- package/backend/mcp/README.md +84 -14
- package/backend/mcp/config.ts +218 -17
- package/backend/mcp/index.ts +2 -0
- package/backend/mcp/project-context.ts +55 -0
- package/backend/mcp/servers/browser-automation/actions.ts +6 -1
- package/backend/mcp/servers/helper.ts +13 -0
- package/backend/middleware/error-handler.ts +16 -2
- package/backend/preview/browser/browser-preview-service.ts +4 -4
- package/backend/ws/README.md +128 -3
- package/backend/ws/access.ts +56 -0
- package/backend/ws/chat/stream.ts +36 -12
- package/backend/ws/db-client/access.ts +19 -0
- package/backend/ws/db-client/connections.ts +31 -17
- package/backend/ws/db-client/io.ts +7 -9
- package/backend/ws/db-client/query.ts +83 -31
- package/backend/ws/db-client/schema.ts +9 -4
- package/backend/ws/db-client/structure.ts +22 -10
- package/backend/ws/engine/access.ts +39 -0
- package/backend/ws/engine/claude/accounts.ts +15 -10
- package/backend/ws/engine/codex/accounts.ts +516 -0
- package/backend/ws/engine/codex/index.ts +14 -0
- package/backend/ws/engine/codex/status.ts +87 -0
- package/backend/ws/engine/copilot/accounts.ts +122 -0
- package/backend/ws/engine/copilot/index.ts +13 -0
- package/backend/ws/engine/copilot/status.ts +54 -0
- package/backend/ws/engine/index.ts +7 -1
- package/backend/ws/engine/opencode/providers.ts +1 -1
- package/backend/ws/engine/qwen/accounts.ts +137 -0
- package/backend/ws/engine/qwen/index.ts +15 -0
- package/backend/ws/engine/qwen/presets.ts +40 -0
- package/backend/ws/engine/qwen/status.ts +54 -0
- package/backend/ws/files/read.ts +3 -1
- package/backend/ws/files/state.ts +3 -0
- package/backend/ws/files/watch.ts +7 -1
- package/backend/ws/git/branch.ts +13 -19
- package/backend/ws/git/commit-message.ts +3 -4
- package/backend/ws/git/commit.ts +5 -7
- package/backend/ws/git/conflict.ts +7 -10
- package/backend/ws/git/diff.ts +7 -10
- package/backend/ws/git/log.ts +3 -4
- package/backend/ws/git/remote.ts +30 -43
- package/backend/ws/git/staging.ts +13 -19
- package/backend/ws/git/status.ts +7 -11
- package/backend/ws/messages/crud.ts +7 -13
- package/backend/ws/preview/access.ts +45 -0
- package/backend/ws/preview/browser/cleanup.ts +3 -11
- package/backend/ws/preview/browser/console.ts +5 -40
- package/backend/ws/preview/browser/interact.ts +2 -6
- package/backend/ws/preview/browser/native-ui.ts +5 -18
- package/backend/ws/preview/browser/stats.ts +2 -12
- package/backend/ws/preview/browser/tab-info.ts +4 -20
- package/backend/ws/preview/browser/tab.ts +4 -27
- package/backend/ws/preview/browser/webcodecs.ts +6 -47
- package/backend/ws/projects/crud.ts +4 -10
- package/backend/ws/projects/status.ts +2 -0
- package/backend/ws/sessions/crud.ts +22 -33
- package/backend/ws/settings/crud.ts +13 -13
- package/backend/ws/snapshot/restore.ts +5 -2
- package/backend/ws/snapshot/timeline.ts +3 -1
- package/backend/ws/system-tools/access.ts +28 -0
- package/backend/ws/system-tools/install.ts +13 -4
- package/backend/ws/system-tools/status.ts +5 -2
- package/backend/ws/terminal/access.ts +56 -0
- package/backend/ws/terminal/persistence.ts +12 -6
- package/backend/ws/terminal/session.ts +35 -14
- package/backend/ws/terminal/stream.ts +4 -1
- package/dist/assets/{index-DqAGCTFT.js → index-D8V2wj9B.js} +2 -2
- package/dist/assets/{main-DsED0rLr.js → main-C9nYVmnw.js} +206 -198
- package/dist/assets/main-hspyFOoK.css +1 -0
- package/dist/index.html +2 -2
- package/package.json +4 -1
- package/shared/constants/engines.ts +45 -140
- package/shared/types/database/schema.ts +1 -0
- package/shared/types/unified/common.ts +1 -1
- package/shared/types/unified/engine.ts +29 -1
- package/shared/types/unified/index.ts +2 -0
- package/shared/types/unified/message.ts +1 -1
- package/shared/types/unified/tool.ts +17 -2
- package/shared/utils/ws-server.ts +14 -0
- package/dist/assets/main-eWY9R8g9.css +0 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copilot dynamic model discovery.
|
|
3
|
+
*
|
|
4
|
+
* Wraps `CopilotClient.listModels()` and translates `ModelInfo[]` into
|
|
5
|
+
* `EngineModel[]`. Returns `[]` on any failure with a friendly error
|
|
6
|
+
* message logged via `summariseModelsError` — common 4xx responses (PAT
|
|
7
|
+
* missing the "Copilot Requests" scope, fine-grained PAT not accepted)
|
|
8
|
+
* are mapped to actionable hints for the server log.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { CopilotClient, ModelInfo } from '@github/copilot-sdk';
|
|
12
|
+
import type { EngineModel } from '$shared/types/unified';
|
|
13
|
+
import { debug } from '$shared/utils/logger';
|
|
14
|
+
|
|
15
|
+
export async function fetchCopilotModels(
|
|
16
|
+
client: CopilotClient,
|
|
17
|
+
cache: ModelInfo[] | null,
|
|
18
|
+
): Promise<{ models: EngineModel[]; cache: ModelInfo[] | null }> {
|
|
19
|
+
try {
|
|
20
|
+
const infos = cache ?? await client.listModels();
|
|
21
|
+
return {
|
|
22
|
+
models: infos.map(info => mapModelInfoToEngineModel(info)),
|
|
23
|
+
cache: infos,
|
|
24
|
+
};
|
|
25
|
+
} catch (error) {
|
|
26
|
+
debug.warn('engine', `Copilot models unavailable: ${summariseModelsError(error)}`);
|
|
27
|
+
return { models: [], cache };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Build a one-line, human-readable summary of a models.list failure for the
|
|
33
|
+
* server log. Strips the JSON-RPC stack frame noise and maps known GitHub
|
|
34
|
+
* Copilot 4xx responses to actionable hints.
|
|
35
|
+
*/
|
|
36
|
+
function summariseModelsError(error: unknown): string {
|
|
37
|
+
const raw = error instanceof Error ? error.message : String(error);
|
|
38
|
+
const firstLine = raw.split('\n')[0]?.trim() || raw;
|
|
39
|
+
|
|
40
|
+
if (raw.includes('Personal Access Tokens are not supported')) {
|
|
41
|
+
return 'the models.list endpoint does not accept fine-grained PATs (chat will still work if the PAT has Copilot Requests).';
|
|
42
|
+
}
|
|
43
|
+
if (raw.includes('Copilot Requests')) {
|
|
44
|
+
return 'PAT is missing the "Copilot Requests" permission.';
|
|
45
|
+
}
|
|
46
|
+
if (raw.includes('401') || raw.toLowerCase().includes('unauthorized')) {
|
|
47
|
+
return 'unauthorized — check that the GitHub PAT is valid and has Copilot access.';
|
|
48
|
+
}
|
|
49
|
+
return firstLine;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function mapModelInfoToEngineModel(info: ModelInfo): EngineModel {
|
|
53
|
+
const limits = info.capabilities?.limits;
|
|
54
|
+
const supports = info.capabilities?.supports;
|
|
55
|
+
return {
|
|
56
|
+
engine: {
|
|
57
|
+
type: 'copilot',
|
|
58
|
+
provider: 'github',
|
|
59
|
+
model: { id: info.id, name: info.name },
|
|
60
|
+
account: { id: 0, name: '' },
|
|
61
|
+
},
|
|
62
|
+
limit: {
|
|
63
|
+
input: limits?.max_context_window_tokens ?? 0,
|
|
64
|
+
output: 0,
|
|
65
|
+
},
|
|
66
|
+
modalities: {
|
|
67
|
+
input: {
|
|
68
|
+
text: true,
|
|
69
|
+
image: !!supports?.vision,
|
|
70
|
+
audio: false,
|
|
71
|
+
video: false,
|
|
72
|
+
pdf: false,
|
|
73
|
+
},
|
|
74
|
+
output: {
|
|
75
|
+
text: true,
|
|
76
|
+
image: false,
|
|
77
|
+
audio: false,
|
|
78
|
+
video: false,
|
|
79
|
+
pdf: false,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
capabilities: {
|
|
83
|
+
reasoning: !!supports?.reasoningEffort,
|
|
84
|
+
tools: true,
|
|
85
|
+
structuredOutput: false,
|
|
86
|
+
},
|
|
87
|
+
cost: {
|
|
88
|
+
input: info.billing?.multiplier ?? 0,
|
|
89
|
+
output: 0,
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copilot Session Fork (workaround)
|
|
3
|
+
*
|
|
4
|
+
* The Copilot SDK does not yet expose a native `forkSession()` API
|
|
5
|
+
* (tracking issues: github/copilot-cli#1313, #1697, #2058). To support our
|
|
6
|
+
* multi-branch checkpoints feature — which lets the user replay an earlier
|
|
7
|
+
* point in the conversation as a sibling branch — we replicate the SDK's
|
|
8
|
+
* own recommended workaround: copy the on-disk session state directory to
|
|
9
|
+
* a fresh ID and patch the embedded session identifiers.
|
|
10
|
+
*
|
|
11
|
+
* On-disk layout (`~/.copilot/session-state/<sessionId>/`):
|
|
12
|
+
* ├── workspace.yaml — first line is `id: <sessionId>`
|
|
13
|
+
* ├── events.jsonl — first event is `session.start { data.sessionId }`
|
|
14
|
+
* ├── checkpoints/
|
|
15
|
+
* ├── files/
|
|
16
|
+
* └── research/
|
|
17
|
+
*
|
|
18
|
+
* Both `workspace.yaml#id` and the first `events.jsonl` line's
|
|
19
|
+
* `data.sessionId` must be rewritten to the new ID so that resume picks the
|
|
20
|
+
* fork up as an independent session.
|
|
21
|
+
*
|
|
22
|
+
* TODO: When @github/copilot-sdk gains a native `forkSession()` (or an
|
|
23
|
+
* equivalent like `client.session.fork()`), delete this helper and switch
|
|
24
|
+
* `CopilotEngine.streamQuery` to use the SDK API directly — the same way
|
|
25
|
+
* the Claude adapter passes `forkSession: true` and the OpenCode adapter
|
|
26
|
+
* calls `client.session.fork({ path: { id } })`.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import fs from 'node:fs';
|
|
30
|
+
import path from 'node:path';
|
|
31
|
+
import os from 'node:os';
|
|
32
|
+
import { debug } from '$shared/utils/logger';
|
|
33
|
+
|
|
34
|
+
const SESSION_STATE_DIR = path.join(os.homedir(), '.copilot', 'session-state');
|
|
35
|
+
|
|
36
|
+
export function getSessionStatePath(sessionId: string): string {
|
|
37
|
+
return path.join(SESSION_STATE_DIR, sessionId);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function sessionStateExists(sessionId: string): boolean {
|
|
41
|
+
return fs.existsSync(getSessionStatePath(sessionId));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Copy `sourceSessionId`'s state directory to `forkSessionId` and patch the
|
|
46
|
+
* session identifiers stored inside. Returns true on success, false if the
|
|
47
|
+
* source directory is missing (caller should fall back to a fresh session).
|
|
48
|
+
*
|
|
49
|
+
* The destination is removed first if it already exists so a re-fork from
|
|
50
|
+
* the same source produces a clean copy.
|
|
51
|
+
*/
|
|
52
|
+
export function forkCopilotSessionState(sourceSessionId: string, forkSessionId: string): boolean {
|
|
53
|
+
const srcDir = getSessionStatePath(sourceSessionId);
|
|
54
|
+
const dstDir = getSessionStatePath(forkSessionId);
|
|
55
|
+
|
|
56
|
+
if (!fs.existsSync(srcDir)) {
|
|
57
|
+
debug.warn('engine', `Copilot fork: source session ${sourceSessionId} not found on disk`);
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (fs.existsSync(dstDir)) {
|
|
62
|
+
fs.rmSync(dstDir, { recursive: true, force: true });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
fs.cpSync(srcDir, dstDir, { recursive: true });
|
|
66
|
+
patchWorkspaceYaml(dstDir, forkSessionId);
|
|
67
|
+
patchEventsJsonl(dstDir, forkSessionId);
|
|
68
|
+
|
|
69
|
+
debug.log('engine', `Copilot fork: ${sourceSessionId} → ${forkSessionId}`);
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Replace the `id:` field at the top of workspace.yaml with the fork ID.
|
|
75
|
+
* The file is a small YAML map written by the SDK with one key per line, so
|
|
76
|
+
* a targeted regex replace is safer than parsing & re-serialising YAML
|
|
77
|
+
* (which would lose comments / formatting).
|
|
78
|
+
*/
|
|
79
|
+
function patchWorkspaceYaml(dstDir: string, forkSessionId: string): void {
|
|
80
|
+
const wsPath = path.join(dstDir, 'workspace.yaml');
|
|
81
|
+
if (!fs.existsSync(wsPath)) return;
|
|
82
|
+
|
|
83
|
+
const original = fs.readFileSync(wsPath, 'utf-8');
|
|
84
|
+
const patched = original.replace(/^id:\s*.*$/m, `id: ${forkSessionId}`);
|
|
85
|
+
fs.writeFileSync(wsPath, patched);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Rewrite `data.sessionId` on the first line of events.jsonl (the
|
|
90
|
+
* `session.start` event) so the SDK's resume path treats this directory
|
|
91
|
+
* as the fork's own history.
|
|
92
|
+
*/
|
|
93
|
+
function patchEventsJsonl(dstDir: string, forkSessionId: string): void {
|
|
94
|
+
const evPath = path.join(dstDir, 'events.jsonl');
|
|
95
|
+
if (!fs.existsSync(evPath)) return;
|
|
96
|
+
|
|
97
|
+
const raw = fs.readFileSync(evPath, 'utf-8');
|
|
98
|
+
const newlineIdx = raw.indexOf('\n');
|
|
99
|
+
const firstLine = newlineIdx === -1 ? raw : raw.slice(0, newlineIdx);
|
|
100
|
+
const rest = newlineIdx === -1 ? '' : raw.slice(newlineIdx);
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
const parsed = JSON.parse(firstLine) as { data?: { sessionId?: string } };
|
|
104
|
+
if (parsed?.data) {
|
|
105
|
+
parsed.data.sessionId = forkSessionId;
|
|
106
|
+
fs.writeFileSync(evPath, JSON.stringify(parsed) + rest);
|
|
107
|
+
}
|
|
108
|
+
} catch (err) {
|
|
109
|
+
debug.warn('engine', `Copilot fork: failed to patch events.jsonl session.start (non-fatal):`, err);
|
|
110
|
+
}
|
|
111
|
+
}
|