@idcloudhost/ai-connect 0.1.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/LICENSE +21 -0
- package/README.md +287 -0
- package/dist/adapters/aider.d.ts +11 -0
- package/dist/adapters/aider.d.ts.map +1 -0
- package/dist/adapters/aider.js +69 -0
- package/dist/adapters/aider.js.map +1 -0
- package/dist/adapters/claude-code.d.ts +17 -0
- package/dist/adapters/claude-code.d.ts.map +1 -0
- package/dist/adapters/claude-code.js +73 -0
- package/dist/adapters/claude-code.js.map +1 -0
- package/dist/adapters/codex.d.ts +11 -0
- package/dist/adapters/codex.d.ts.map +1 -0
- package/dist/adapters/codex.js +71 -0
- package/dist/adapters/codex.js.map +1 -0
- package/dist/adapters/continue.d.ts +7 -0
- package/dist/adapters/continue.d.ts.map +1 -0
- package/dist/adapters/continue.js +79 -0
- package/dist/adapters/continue.js.map +1 -0
- package/dist/adapters/crush.d.ts +4 -0
- package/dist/adapters/crush.d.ts.map +1 -0
- package/dist/adapters/crush.js +72 -0
- package/dist/adapters/crush.js.map +1 -0
- package/dist/adapters/goose.d.ts +11 -0
- package/dist/adapters/goose.d.ts.map +1 -0
- package/dist/adapters/goose.js +68 -0
- package/dist/adapters/goose.js.map +1 -0
- package/dist/adapters/helpers.d.ts +33 -0
- package/dist/adapters/helpers.d.ts.map +1 -0
- package/dist/adapters/helpers.js +117 -0
- package/dist/adapters/helpers.js.map +1 -0
- package/dist/adapters/hermes.d.ts +11 -0
- package/dist/adapters/hermes.d.ts.map +1 -0
- package/dist/adapters/hermes.js +100 -0
- package/dist/adapters/hermes.js.map +1 -0
- package/dist/adapters/index.d.ts +20 -0
- package/dist/adapters/index.d.ts.map +1 -0
- package/dist/adapters/index.js +60 -0
- package/dist/adapters/index.js.map +1 -0
- package/dist/adapters/manual.d.ts +6 -0
- package/dist/adapters/manual.d.ts.map +1 -0
- package/dist/adapters/manual.js +87 -0
- package/dist/adapters/manual.js.map +1 -0
- package/dist/adapters/omp.d.ts +8 -0
- package/dist/adapters/omp.d.ts.map +1 -0
- package/dist/adapters/omp.js +64 -0
- package/dist/adapters/omp.js.map +1 -0
- package/dist/adapters/openclaw.d.ts +10 -0
- package/dist/adapters/openclaw.d.ts.map +1 -0
- package/dist/adapters/openclaw.js +107 -0
- package/dist/adapters/openclaw.js.map +1 -0
- package/dist/adapters/opencode.d.ts +11 -0
- package/dist/adapters/opencode.d.ts.map +1 -0
- package/dist/adapters/opencode.js +86 -0
- package/dist/adapters/opencode.js.map +1 -0
- package/dist/adapters/pi-family.d.ts +14 -0
- package/dist/adapters/pi-family.d.ts.map +1 -0
- package/dist/adapters/pi-family.js +27 -0
- package/dist/adapters/pi-family.js.map +1 -0
- package/dist/adapters/pi.d.ts +8 -0
- package/dist/adapters/pi.d.ts.map +1 -0
- package/dist/adapters/pi.js +56 -0
- package/dist/adapters/pi.js.map +1 -0
- package/dist/adapters/shell-env.d.ts +12 -0
- package/dist/adapters/shell-env.d.ts.map +1 -0
- package/dist/adapters/shell-env.js +81 -0
- package/dist/adapters/shell-env.js.map +1 -0
- package/dist/adapters/zed.d.ts +10 -0
- package/dist/adapters/zed.d.ts.map +1 -0
- package/dist/adapters/zed.js +91 -0
- package/dist/adapters/zed.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +207 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/connect.d.ts +3 -0
- package/dist/commands/connect.d.ts.map +1 -0
- package/dist/commands/connect.js +179 -0
- package/dist/commands/connect.js.map +1 -0
- package/dist/commands/context.d.ts +21 -0
- package/dist/commands/context.d.ts.map +1 -0
- package/dist/commands/context.js +4 -0
- package/dist/commands/context.js.map +1 -0
- package/dist/commands/doctor.d.ts +11 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +85 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/env.d.ts +7 -0
- package/dist/commands/env.d.ts.map +1 -0
- package/dist/commands/env.js +37 -0
- package/dist/commands/env.js.map +1 -0
- package/dist/commands/list.d.ts +3 -0
- package/dist/commands/list.d.ts.map +1 -0
- package/dist/commands/list.js +39 -0
- package/dist/commands/list.js.map +1 -0
- package/dist/commands/login.d.ts +7 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +130 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/models.d.ts +9 -0
- package/dist/commands/models.d.ts.map +1 -0
- package/dist/commands/models.js +51 -0
- package/dist/commands/models.js.map +1 -0
- package/dist/commands/remove.d.ts +3 -0
- package/dist/commands/remove.d.ts.map +1 -0
- package/dist/commands/remove.js +43 -0
- package/dist/commands/remove.js.map +1 -0
- package/dist/commands/snippet.d.ts +7 -0
- package/dist/commands/snippet.d.ts.map +1 -0
- package/dist/commands/snippet.js +91 -0
- package/dist/commands/snippet.js.map +1 -0
- package/dist/core/detect.d.ts +12 -0
- package/dist/core/detect.d.ts.map +1 -0
- package/dist/core/detect.js +59 -0
- package/dist/core/detect.js.map +1 -0
- package/dist/core/discovery.d.ts +46 -0
- package/dist/core/discovery.d.ts.map +1 -0
- package/dist/core/discovery.js +124 -0
- package/dist/core/discovery.js.map +1 -0
- package/dist/core/gateway.d.ts +59 -0
- package/dist/core/gateway.d.ts.map +1 -0
- package/dist/core/gateway.js +385 -0
- package/dist/core/gateway.js.map +1 -0
- package/dist/core/http.d.ts +18 -0
- package/dist/core/http.d.ts.map +1 -0
- package/dist/core/http.js +73 -0
- package/dist/core/http.js.map +1 -0
- package/dist/core/management.d.ts +47 -0
- package/dist/core/management.d.ts.map +1 -0
- package/dist/core/management.js +88 -0
- package/dist/core/management.js.map +1 -0
- package/dist/core/store.d.ts +25 -0
- package/dist/core/store.d.ts.map +1 -0
- package/dist/core/store.js +48 -0
- package/dist/core/store.js.map +1 -0
- package/dist/fsutil/edit.d.ts +18 -0
- package/dist/fsutil/edit.d.ts.map +1 -0
- package/dist/fsutil/edit.js +102 -0
- package/dist/fsutil/edit.js.map +1 -0
- package/dist/fsutil/formats.d.ts +32 -0
- package/dist/fsutil/formats.d.ts.map +1 -0
- package/dist/fsutil/formats.js +154 -0
- package/dist/fsutil/formats.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +134 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/ui.d.ts +20 -0
- package/dist/ui.d.ts.map +1 -0
- package/dist/ui.js +69 -0
- package/dist/ui.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { opencodeAdapter } from './opencode.js';
|
|
2
|
+
import { piAdapter } from './pi.js';
|
|
3
|
+
import { ompAdapter } from './omp.js';
|
|
4
|
+
import { hermesAdapter } from './hermes.js';
|
|
5
|
+
import { openclawAdapter } from './openclaw.js';
|
|
6
|
+
import { codexAdapter } from './codex.js';
|
|
7
|
+
import { claudeCodeAdapter } from './claude-code.js';
|
|
8
|
+
import { gooseAdapter } from './goose.js';
|
|
9
|
+
import { crushAdapter } from './crush.js';
|
|
10
|
+
import { continueAdapter } from './continue.js';
|
|
11
|
+
import { aiderAdapter } from './aider.js';
|
|
12
|
+
import { zedAdapter } from './zed.js';
|
|
13
|
+
import { shellEnvAdapter } from './shell-env.js';
|
|
14
|
+
import { manualAdapters } from './manual.js';
|
|
15
|
+
/** Every adapter, in the order `idch-ai list` shows them. */
|
|
16
|
+
export const adapters = [
|
|
17
|
+
opencodeAdapter,
|
|
18
|
+
piAdapter,
|
|
19
|
+
ompAdapter,
|
|
20
|
+
hermesAdapter,
|
|
21
|
+
openclawAdapter,
|
|
22
|
+
codexAdapter,
|
|
23
|
+
claudeCodeAdapter,
|
|
24
|
+
crushAdapter,
|
|
25
|
+
gooseAdapter,
|
|
26
|
+
aiderAdapter,
|
|
27
|
+
continueAdapter,
|
|
28
|
+
zedAdapter,
|
|
29
|
+
...manualAdapters,
|
|
30
|
+
shellEnvAdapter,
|
|
31
|
+
];
|
|
32
|
+
const byId = new Map(adapters.map((a) => [a.id, a]));
|
|
33
|
+
/** Aliases people actually type. */
|
|
34
|
+
const aliases = {
|
|
35
|
+
'oh-my-pi': 'omp',
|
|
36
|
+
'open-claw': 'openclaw',
|
|
37
|
+
clawdbot: 'openclaw',
|
|
38
|
+
'hermes-agent': 'hermes',
|
|
39
|
+
claude: 'claude-code',
|
|
40
|
+
claudecode: 'claude-code',
|
|
41
|
+
'codex-cli': 'codex',
|
|
42
|
+
'continue.dev': 'continue',
|
|
43
|
+
roo: 'cline',
|
|
44
|
+
'roo-code': 'cline',
|
|
45
|
+
kilo: 'cline',
|
|
46
|
+
'kilo-code': 'cline',
|
|
47
|
+
qwen: 'qwen-code',
|
|
48
|
+
gemini: 'qwen-code',
|
|
49
|
+
shell: 'env',
|
|
50
|
+
dotenv: 'env',
|
|
51
|
+
};
|
|
52
|
+
export function getAdapter(id) {
|
|
53
|
+
const key = id.trim().toLowerCase();
|
|
54
|
+
return byId.get(key) ?? byId.get(aliases[key] ?? '');
|
|
55
|
+
}
|
|
56
|
+
export function adapterIds() {
|
|
57
|
+
return adapters.map((a) => a.id);
|
|
58
|
+
}
|
|
59
|
+
export { opencodeAdapter, piAdapter, ompAdapter, hermesAdapter, openclawAdapter, codexAdapter, claudeCodeAdapter, gooseAdapter, crushAdapter, continueAdapter, aiderAdapter, zedAdapter, shellEnvAdapter, };
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,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AAO;IACb,WAAW,EAAE,OAAO;IACpB,IAAI,EAAE,WAAW;IACjB,MAAM,EAAE,WAAW;IACnB,KAAK,EAAE,KAAK;IACZ,MAAM,EAAE,KAAK;CACd,CAAC;AAEF,MAAM,UAAU,UAAU,CAAC,EAAU;IACnC,MAAM,GAAG,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACpC,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACnC,CAAC;AAED,OAAO,EACL,eAAe,EACf,SAAS,EACT,UAAU,EACV,aAAa,EACb,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,UAAU,EACV,eAAe,GAChB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Adapter } from '../types.js';
|
|
2
|
+
export declare const clineAdapter: Adapter;
|
|
3
|
+
export declare const cursorAdapter: Adapter;
|
|
4
|
+
export declare const qwenCodeAdapter: Adapter;
|
|
5
|
+
export declare const manualAdapters: Adapter[];
|
|
6
|
+
//# sourceMappingURL=manual.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manual.d.ts","sourceRoot":"","sources":["../../src/adapters/manual.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAA+C,MAAM,aAAa,CAAC;AAyDxF,eAAO,MAAM,YAAY,SAgBvB,CAAC;AAEH,eAAO,MAAM,aAAa,SAexB,CAAC;AAEH,eAAO,MAAM,eAAe,SAe1B,CAAC;AAEH,eAAO,MAAM,cAAc,WAAiD,CAAC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { detectByBinOrConfig } from '../core/detect.js';
|
|
2
|
+
import { expandHome } from '../fsutil/edit.js';
|
|
3
|
+
import { result } from './helpers.js';
|
|
4
|
+
/**
|
|
5
|
+
* Some agents keep their settings somewhere a CLI has no business writing:
|
|
6
|
+
* VS Code's encrypted global state, a GUI keychain, an app's own database.
|
|
7
|
+
* Rather than reverse-engineer those and risk corrupting them, we print the
|
|
8
|
+
* exact values to paste. Everything is still discovered live, so the URL and
|
|
9
|
+
* model list in the instructions are real.
|
|
10
|
+
*/
|
|
11
|
+
function manualAdapter(spec) {
|
|
12
|
+
return {
|
|
13
|
+
id: spec.id,
|
|
14
|
+
name: spec.name,
|
|
15
|
+
summary: spec.summary,
|
|
16
|
+
docsUrl: spec.docsUrl,
|
|
17
|
+
bins: spec.bins,
|
|
18
|
+
mode: 'manual',
|
|
19
|
+
secretModes: ['inline'],
|
|
20
|
+
async detect() {
|
|
21
|
+
return detectByBinOrConfig(spec.bins, (spec.configHints ?? []).map(expandHome));
|
|
22
|
+
},
|
|
23
|
+
configPath() {
|
|
24
|
+
return '(entered in the app, not a file we write)';
|
|
25
|
+
},
|
|
26
|
+
async apply(opts) {
|
|
27
|
+
return result(spec.id, [], { notes: spec.steps(opts.target) });
|
|
28
|
+
},
|
|
29
|
+
async remove() {
|
|
30
|
+
return result(spec.id, [], {
|
|
31
|
+
notes: [`${spec.name} stores its settings in the app. Remove the provider there — nothing on disk to undo.`],
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const modelHint = (t) => t.defaultModel ? t.defaultModel : t.models[0]?.id ?? '<pick one from `idch-ai models`>';
|
|
37
|
+
export const clineAdapter = manualAdapter({
|
|
38
|
+
id: 'cline',
|
|
39
|
+
name: 'Cline',
|
|
40
|
+
summary: 'VS Code agent. Settings live in the extension, not on disk.',
|
|
41
|
+
docsUrl: 'https://docs.cline.bot/provider-config/openai-compatible',
|
|
42
|
+
bins: [],
|
|
43
|
+
configHints: ['~/.vscode/extensions', '~/Library/Application Support/Code/User'],
|
|
44
|
+
steps: (t) => [
|
|
45
|
+
'Open the Cline panel in VS Code and click the settings gear.',
|
|
46
|
+
'Set API Provider to "OpenAI Compatible".',
|
|
47
|
+
`Base URL: ${t.apiBase}`,
|
|
48
|
+
'API Key: paste the key (Cline stores it in VS Code secret storage).',
|
|
49
|
+
`Model ID: ${modelHint(t)}`,
|
|
50
|
+
'Tick "Supports Images" only for models that do — run `idch-ai models` to see which.',
|
|
51
|
+
'Roo Code and Kilo Code are Cline forks: the same four fields, same place.',
|
|
52
|
+
],
|
|
53
|
+
});
|
|
54
|
+
export const cursorAdapter = manualAdapter({
|
|
55
|
+
id: 'cursor',
|
|
56
|
+
name: 'Cursor',
|
|
57
|
+
summary: 'Cursor IDE. Custom OpenAI base URL is set in Settings → Models.',
|
|
58
|
+
docsUrl: 'https://docs.cursor.com/settings/models',
|
|
59
|
+
bins: ['cursor'],
|
|
60
|
+
configHints: ['~/Library/Application Support/Cursor', '~/.cursor'],
|
|
61
|
+
steps: (t) => [
|
|
62
|
+
'Cursor → Settings → Models.',
|
|
63
|
+
'Turn on "Override OpenAI Base URL".',
|
|
64
|
+
`Base URL: ${t.apiBase}`,
|
|
65
|
+
'Paste the key into the OpenAI API Key field and click Verify.',
|
|
66
|
+
`Add ${modelHint(t)} under "Add model" — Cursor only sends model names it knows about.`,
|
|
67
|
+
'Overriding the base URL routes Cursor\'s OpenAI models here; its own Composer models are unaffected.',
|
|
68
|
+
],
|
|
69
|
+
});
|
|
70
|
+
export const qwenCodeAdapter = manualAdapter({
|
|
71
|
+
id: 'qwen-code',
|
|
72
|
+
name: 'Qwen Code / Gemini CLI forks',
|
|
73
|
+
summary: 'Reads OPENAI_API_KEY, OPENAI_BASE_URL and OPENAI_MODEL from the environment.',
|
|
74
|
+
docsUrl: 'https://github.com/QwenLM/qwen-code',
|
|
75
|
+
bins: ['qwen'],
|
|
76
|
+
configHints: ['~/.qwen'],
|
|
77
|
+
steps: (t) => [
|
|
78
|
+
'These forks configure themselves entirely from the environment.',
|
|
79
|
+
'Run `idch-ai connect --agent env` and source the file it writes, or put these in ~/.qwen/.env:',
|
|
80
|
+
` OPENAI_BASE_URL=${t.apiBase}`,
|
|
81
|
+
' OPENAI_API_KEY=<your key>',
|
|
82
|
+
` OPENAI_MODEL=${modelHint(t)}`,
|
|
83
|
+
'Then start `qwen` in that shell.',
|
|
84
|
+
],
|
|
85
|
+
});
|
|
86
|
+
export const manualAdapters = [clineAdapter, cursorAdapter, qwenCodeAdapter];
|
|
87
|
+
//# sourceMappingURL=manual.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manual.js","sourceRoot":"","sources":["../../src/adapters/manual.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AActC;;;;;;GAMG;AACH,SAAS,aAAa,CAAC,IAAgB;IACrC,OAAO;QACL,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,CAAC,QAAQ,CAAC;QAEvB,KAAK,CAAC,MAAM;YACV,OAAO,mBAAmB,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC;QAClF,CAAC;QAED,UAAU;YACR,OAAO,2CAA2C,CAAC;QACrD,CAAC;QAED,KAAK,CAAC,KAAK,CAAC,IAAkB;YAC5B,OAAO,M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KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;QACZ,6BAA6B;QAC7B,qCAAqC;QACrC,aAAa,CAAC,CAAC,OAAO,EAAE;QACxB,+DAA+D;QAC/D,OAAO,SAAS,CAAC,CAAC,CAAC,oEAAoE;QACvF,sGAAsG;KACvG;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAC;IAC3C,EAAE,EAAE,WAAW;IACf,IAAI,EAAE,8BAA8B;IACpC,OAAO,EAAE,8EAA8E;IACvF,OAAO,EAAE,qCAAqC;IAC9C,IAAI,EAAE,CAAC,MAAM,CAAC;IACd,WAAW,EAAE,CAAC,SAAS,CAAC;IACxB,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;QACZ,iEAAiE;QACjE,gGAAgG;QAChG,qBAAqB,CAAC,CAAC,OAAO,EAAE;QAChC,6BAA6B;QAC7B,kBAAkB,SAAS,CAAC,CAAC,CAAC,EAAE;QAChC,kCAAkC;KACnC;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,YAAY,EAAE,aAAa,EAAE,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Adapter } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* omp (oh-my-pi) reads ~/.omp/agent/models.yml, falling back to models.yaml.
|
|
4
|
+
* Same provider schema as pi, expressed in YAML. We edit the document rather
|
|
5
|
+
* than re-serialise it so any comments the user wrote survive.
|
|
6
|
+
*/
|
|
7
|
+
export declare const ompAdapter: Adapter;
|
|
8
|
+
//# sourceMappingURL=omp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"omp.d.ts","sourceRoot":"","sources":["../../src/adapters/omp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAA6B,MAAM,aAAa,CAAC;AAWtE;;;;GAIG;AACH,eAAO,MAAM,UAAU,EAAE,OAqDxB,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { readIfExists, shortenHome, writeFileSafely } from '../fsutil/edit.js';
|
|
2
|
+
import { editYaml, editYamlPruned, parseYaml } from '../fsutil/formats.js';
|
|
3
|
+
import { detectByBinOrConfig } from '../core/detect.js';
|
|
4
|
+
import { envVarsFor, getIn, home, result } from './helpers.js';
|
|
5
|
+
import { buildPiProvider } from './pi-family.js';
|
|
6
|
+
function userConfig() {
|
|
7
|
+
return home('.omp', 'agent', 'models.yml');
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* omp (oh-my-pi) reads ~/.omp/agent/models.yml, falling back to models.yaml.
|
|
11
|
+
* Same provider schema as pi, expressed in YAML. We edit the document rather
|
|
12
|
+
* than re-serialise it so any comments the user wrote survive.
|
|
13
|
+
*/
|
|
14
|
+
export const ompAdapter = {
|
|
15
|
+
id: 'omp',
|
|
16
|
+
name: 'omp (oh-my-pi)',
|
|
17
|
+
summary: 'Terminal coding agent forked from pi. Providers live in ~/.omp/agent/models.yml.',
|
|
18
|
+
docsUrl: 'https://github.com/can1357/oh-my-pi/blob/main/docs/models.md',
|
|
19
|
+
bins: ['omp'],
|
|
20
|
+
mode: 'auto',
|
|
21
|
+
secretModes: ['inline', 'env'],
|
|
22
|
+
async detect() {
|
|
23
|
+
return detectByBinOrConfig(['omp'], [userConfig(), home('.omp', 'agent', 'models.yaml'), home('.omp', 'agent')]);
|
|
24
|
+
},
|
|
25
|
+
configPath({ configPathOverride }) {
|
|
26
|
+
return configPathOverride ?? userConfig();
|
|
27
|
+
},
|
|
28
|
+
async apply(opts) {
|
|
29
|
+
const file = this.configPath(opts);
|
|
30
|
+
const before = await readIfExists(file);
|
|
31
|
+
const provider = buildPiProvider(opts, opts.target);
|
|
32
|
+
const after = editYaml(before, (doc) => {
|
|
33
|
+
doc.setIn(['providers', opts.target.providerId], doc.createNode(provider));
|
|
34
|
+
});
|
|
35
|
+
const change = await writeFileSafely(file, after, { dryRun: opts.dryRun });
|
|
36
|
+
const model = opts.target.defaultModel;
|
|
37
|
+
const selector = model ? `${opts.target.providerId}/${model}` : undefined;
|
|
38
|
+
return result(this.id, [change], {
|
|
39
|
+
envVars: envVarsFor(opts),
|
|
40
|
+
notes: [
|
|
41
|
+
selector
|
|
42
|
+
? `Start with: omp --model ${selector}`
|
|
43
|
+
: 'Run `omp --list-models` to see the registered models.',
|
|
44
|
+
'Use the full provider/model selector when the same model id exists under more than one provider.',
|
|
45
|
+
],
|
|
46
|
+
...(selector ? { tryCommand: `omp --model ${selector}` } : {}),
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
async remove(opts) {
|
|
50
|
+
const file = this.configPath(opts);
|
|
51
|
+
const before = await readIfExists(file);
|
|
52
|
+
if (before === null)
|
|
53
|
+
return result(this.id, []);
|
|
54
|
+
if (!getIn(parseYaml(before), ['providers', opts.providerId]))
|
|
55
|
+
return result(this.id, []);
|
|
56
|
+
// Edit the document rather than reserialise it, so the user's comments survive.
|
|
57
|
+
const after = editYamlPruned(before, (doc) => {
|
|
58
|
+
doc.deleteIn(['providers', opts.providerId]);
|
|
59
|
+
});
|
|
60
|
+
const change = await writeFileSafely(file, after, { dryRun: opts.dryRun });
|
|
61
|
+
return result(this.id, [change], { notes: [`Removed provider "${opts.providerId}" from ${shortenHome(file)}.`] });
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=omp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"omp.js","sourceRoot":"","sources":["../../src/adapters/omp.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,UAAU,E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AC,GAAG,EAAE,EAAE;YAC3C,GAAG,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QAC3E,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,qBAAqB,IAAI,CAAC,UAAU,UAAU,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACpH,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Adapter } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* OpenClaw keeps its main config at ~/.openclaw/openclaw.json in JSON5.
|
|
4
|
+
*
|
|
5
|
+
* Two things have to line up or the model is silently rejected: the provider
|
|
6
|
+
* under `models.providers`, and an allowlist entry under `agents.defaults.models`
|
|
7
|
+
* keyed by the full `provider/model` reference.
|
|
8
|
+
*/
|
|
9
|
+
export declare const openclawAdapter: Adapter;
|
|
10
|
+
//# sourceMappingURL=openclaw.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openclaw.d.ts","sourceRoot":"","sources":["../../src/adapters/openclaw.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAA6B,MAAM,aAAa,CAAC;AAUtE;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,EAAE,OA2G7B,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { readIfExists, shortenHome, writeFileSafely } from '../fsutil/edit.js';
|
|
2
|
+
import { parseJson, stringifyJson } from '../fsutil/formats.js';
|
|
3
|
+
import { detectByBinOrConfig } from '../core/detect.js';
|
|
4
|
+
import { costOf, ctx, deleteIn, envVarsFor, home, inputKinds, maxOut, modelsToWrite, result, secretValue, setIn } from './helpers.js';
|
|
5
|
+
function userConfig() {
|
|
6
|
+
return home('.openclaw', 'openclaw.json');
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* OpenClaw keeps its main config at ~/.openclaw/openclaw.json in JSON5.
|
|
10
|
+
*
|
|
11
|
+
* Two things have to line up or the model is silently rejected: the provider
|
|
12
|
+
* under `models.providers`, and an allowlist entry under `agents.defaults.models`
|
|
13
|
+
* keyed by the full `provider/model` reference.
|
|
14
|
+
*/
|
|
15
|
+
export const openclawAdapter = {
|
|
16
|
+
id: 'openclaw',
|
|
17
|
+
name: 'OpenClaw',
|
|
18
|
+
summary: 'Personal AI assistant / gateway. Config lives in ~/.openclaw/openclaw.json.',
|
|
19
|
+
docsUrl: 'https://docs.openclaw.ai/gateway/config-tools',
|
|
20
|
+
bins: ['openclaw'],
|
|
21
|
+
mode: 'auto',
|
|
22
|
+
secretModes: ['inline', 'env'],
|
|
23
|
+
async detect() {
|
|
24
|
+
return detectByBinOrConfig(['openclaw'], [userConfig(), home('.openclaw')]);
|
|
25
|
+
},
|
|
26
|
+
configPath({ configPathOverride }) {
|
|
27
|
+
return configPathOverride ?? userConfig();
|
|
28
|
+
},
|
|
29
|
+
async apply(opts) {
|
|
30
|
+
const file = this.configPath(opts);
|
|
31
|
+
const before = await readIfExists(file);
|
|
32
|
+
const { target } = opts;
|
|
33
|
+
let doc;
|
|
34
|
+
try {
|
|
35
|
+
doc = parseJson(before);
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
// JSON5 allows unquoted keys, which we cannot round-trip safely. Rather than
|
|
39
|
+
// mangle a working config, hand the user the exact block to paste.
|
|
40
|
+
throw new Error(`${shortenHome(file)} uses JSON5 syntax this tool cannot rewrite safely (${err.message}).\n` +
|
|
41
|
+
`Run with --dry-run --print to get the provider block and paste it in by hand.`);
|
|
42
|
+
}
|
|
43
|
+
const models = modelsToWrite(target);
|
|
44
|
+
setIn(doc, ['models', 'providers', target.providerId], {
|
|
45
|
+
baseUrl: target.apiBase,
|
|
46
|
+
apiKey: secretValue(opts, 'raw'),
|
|
47
|
+
api: 'openai-completions',
|
|
48
|
+
models: models.map((m) => ({
|
|
49
|
+
id: m.id,
|
|
50
|
+
name: m.label,
|
|
51
|
+
reasoning: false,
|
|
52
|
+
input: inputKinds(m),
|
|
53
|
+
cost: { ...costOf(m), cacheRead: 0, cacheWrite: 0 },
|
|
54
|
+
contextWindow: ctx(m),
|
|
55
|
+
maxTokens: maxOut(m),
|
|
56
|
+
})),
|
|
57
|
+
});
|
|
58
|
+
// `mode: merge` keeps OpenClaw's built-in providers instead of replacing them.
|
|
59
|
+
setIn(doc, ['models', 'mode'], 'merge');
|
|
60
|
+
// Without the allowlist entry OpenClaw refuses the model at request time.
|
|
61
|
+
const allow = doc.agents?.defaults
|
|
62
|
+
?.models;
|
|
63
|
+
const allowlist = allow && typeof allow === 'object' ? { ...allow } : {};
|
|
64
|
+
for (const m of models)
|
|
65
|
+
allowlist[`${target.providerId}/${m.id}`] = { alias: m.label };
|
|
66
|
+
setIn(doc, ['agents', 'defaults', 'models'], allowlist);
|
|
67
|
+
if (target.defaultModel) {
|
|
68
|
+
setIn(doc, ['agents', 'defaults', 'model', 'primary'], `${target.providerId}/${target.defaultModel}`);
|
|
69
|
+
}
|
|
70
|
+
if (opts.secretMode === 'env') {
|
|
71
|
+
setIn(doc, ['env', 'vars', 'IDCH_AI_API_KEY'], target.apiKey);
|
|
72
|
+
}
|
|
73
|
+
const change = await writeFileSafely(file, stringifyJson(doc, before), { dryRun: opts.dryRun });
|
|
74
|
+
return result(this.id, [change], {
|
|
75
|
+
envVars: envVarsFor(opts),
|
|
76
|
+
notes: [
|
|
77
|
+
`Registered ${models.length} model(s) and allowlisted them under agents.defaults.models.`,
|
|
78
|
+
'Restart the OpenClaw gateway for the change to take effect.',
|
|
79
|
+
'Pointing a provider at a custom baseUrl also tells OpenClaw to trust that origin for model traffic.',
|
|
80
|
+
],
|
|
81
|
+
tryCommand: 'openclaw',
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
async remove(opts) {
|
|
85
|
+
const file = this.configPath(opts);
|
|
86
|
+
const before = await readIfExists(file);
|
|
87
|
+
if (before === null)
|
|
88
|
+
return result(this.id, []);
|
|
89
|
+
const doc = parseJson(before);
|
|
90
|
+
deleteIn(doc, ['models', 'providers', opts.providerId]);
|
|
91
|
+
const allow = doc.agents?.defaults
|
|
92
|
+
?.models;
|
|
93
|
+
if (allow && typeof allow === 'object') {
|
|
94
|
+
for (const key of Object.keys(allow)) {
|
|
95
|
+
if (key.startsWith(`${opts.providerId}/`))
|
|
96
|
+
delete allow[key];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const primary = doc.agents?.defaults?.model?.primary;
|
|
100
|
+
if (typeof primary === 'string' && primary.startsWith(`${opts.providerId}/`)) {
|
|
101
|
+
deleteIn(doc, ['agents', 'defaults', 'model', 'primary']);
|
|
102
|
+
}
|
|
103
|
+
const change = await writeFileSafely(file, stringifyJson(doc, before), { dryRun: opts.dryRun });
|
|
104
|
+
return result(this.id, [change], { notes: [`Removed provider "${opts.providerId}" from ${shortenHome(file)}.`] });
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=openclaw.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openclaw.js","sourceRoot":"","sources":["../../src/adapters/openclaw.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,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;QAExD,MAAM,KAAK,GAAK,GAAG,CAAC,MAA8C,EAAE,QAAgD;YAClH,EAAE,MAAM,CAAC;QACX,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YACvC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAe,CAAC,EAAE,CAAC;gBAC/C,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,UAAU,GAAG,CAAC;oBAAE,OAAQ,KAAiC,CAAC,GAAG,CAAC,CAAC;YAC5F,CAAC;QACH,CAAC;QACD,MAAM,OAAO,GACT,GAAG,CAAC,MAA8C,EAAE,QAAgD,EAAE,KAGzG,EAAE,OAAO,CAAC;QACX,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,UAAU,GAAG,CAAC,EAAE,CAAC;YAC7E,QAAQ,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;QAC5D,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,eAAe,CAAC,IAAI,EAAE,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QAChG,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,qBAAqB,IAAI,CAAC,UAAU,UAAU,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACpH,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Adapter } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* opencode reads providers from `opencode.json`. Custom OpenAI-compatible
|
|
4
|
+
* endpoints go through the Vercel AI SDK's `@ai-sdk/openai-compatible` package,
|
|
5
|
+
* with `options.baseURL` pointing at the `/v1` root.
|
|
6
|
+
*/
|
|
7
|
+
export declare const opencodeAdapter: Adapter;
|
|
8
|
+
/** Used by `doctor` to tell whether our block is still present and current. */
|
|
9
|
+
export declare function opencodeInstalledBase(configText: string | null, providerId: string): string | undefined;
|
|
10
|
+
export declare const OPENCODE_KEY_ENV = "IDCH_AI_API_KEY";
|
|
11
|
+
//# sourceMappingURL=opencode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencode.d.ts","sourceRoot":"","sources":["../../src/adapters/opencode.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAA6B,MAAM,aAAa,CAAC;AAUtE;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,OAwE7B,CAAC;AAEF,+EAA+E;AAC/E,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAGvG;AAED,eAAO,MAAM,gBAAgB,oBAAU,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { readIfExists, shortenHome, writeFileSafely } from '../fsutil/edit.js';
|
|
3
|
+
import { parseJson, stringifyJson } from '../fsutil/formats.js';
|
|
4
|
+
import { detectByBinOrConfig } from '../core/detect.js';
|
|
5
|
+
import { KEY_ENV, ctx, deleteIn, envVarsFor, getIn, home, maxOut, modelsToWrite, result, secretValue, setIn, xdgConfigHome } from './helpers.js';
|
|
6
|
+
function userConfig() {
|
|
7
|
+
return path.join(xdgConfigHome(), 'opencode', 'opencode.json');
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* opencode reads providers from `opencode.json`. Custom OpenAI-compatible
|
|
11
|
+
* endpoints go through the Vercel AI SDK's `@ai-sdk/openai-compatible` package,
|
|
12
|
+
* with `options.baseURL` pointing at the `/v1` root.
|
|
13
|
+
*/
|
|
14
|
+
export const opencodeAdapter = {
|
|
15
|
+
id: 'opencode',
|
|
16
|
+
name: 'opencode',
|
|
17
|
+
summary: 'Terminal coding agent by SST. Provider config lives in opencode.json.',
|
|
18
|
+
docsUrl: 'https://opencode.ai/docs/providers/',
|
|
19
|
+
bins: ['opencode'],
|
|
20
|
+
mode: 'auto',
|
|
21
|
+
supportsProjectScope: true,
|
|
22
|
+
secretModes: ['inline', 'env'],
|
|
23
|
+
async detect() {
|
|
24
|
+
return detectByBinOrConfig(['opencode'], [userConfig(), home('.opencode', 'opencode.json')]);
|
|
25
|
+
},
|
|
26
|
+
configPath({ scope, cwd, configPathOverride }) {
|
|
27
|
+
if (configPathOverride)
|
|
28
|
+
return configPathOverride;
|
|
29
|
+
return scope === 'project' ? path.join(cwd, 'opencode.json') : userConfig();
|
|
30
|
+
},
|
|
31
|
+
async apply(opts) {
|
|
32
|
+
const file = this.configPath(opts);
|
|
33
|
+
const before = await readIfExists(file);
|
|
34
|
+
const doc = parseJson(before);
|
|
35
|
+
const { target } = opts;
|
|
36
|
+
doc.$schema ??= 'https://opencode.ai/config.json';
|
|
37
|
+
const models = {};
|
|
38
|
+
for (const m of modelsToWrite(target)) {
|
|
39
|
+
models[m.id] = {
|
|
40
|
+
name: m.label,
|
|
41
|
+
limit: { context: ctx(m), output: maxOut(m) },
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
setIn(doc, ['provider', target.providerId], {
|
|
45
|
+
npm: '@ai-sdk/openai-compatible',
|
|
46
|
+
name: target.providerLabel,
|
|
47
|
+
options: {
|
|
48
|
+
baseURL: target.apiBase,
|
|
49
|
+
apiKey: secretValue(opts, 'braced-env'),
|
|
50
|
+
},
|
|
51
|
+
models,
|
|
52
|
+
});
|
|
53
|
+
if (target.defaultModel)
|
|
54
|
+
doc.model = `${target.providerId}/${target.defaultModel}`;
|
|
55
|
+
const change = await writeFileSafely(file, stringifyJson(doc, before), { dryRun: opts.dryRun });
|
|
56
|
+
return result(this.id, [change], {
|
|
57
|
+
envVars: envVarsFor(opts),
|
|
58
|
+
notes: [
|
|
59
|
+
`Restart opencode, then run /models and pick "${target.providerLabel}".`,
|
|
60
|
+
target.defaultModel
|
|
61
|
+
? `Default model set to ${target.providerId}/${target.defaultModel}.`
|
|
62
|
+
: 'No default model was set — choose one with /models.',
|
|
63
|
+
],
|
|
64
|
+
tryCommand: 'opencode',
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
async remove(opts) {
|
|
68
|
+
const file = this.configPath(opts);
|
|
69
|
+
const before = await readIfExists(file);
|
|
70
|
+
if (before === null)
|
|
71
|
+
return result(this.id, []);
|
|
72
|
+
const doc = parseJson(before);
|
|
73
|
+
deleteIn(doc, ['provider', opts.providerId]);
|
|
74
|
+
if (typeof doc.model === 'string' && doc.model.startsWith(`${opts.providerId}/`))
|
|
75
|
+
delete doc.model;
|
|
76
|
+
const change = await writeFileSafely(file, stringifyJson(doc, before), { dryRun: opts.dryRun });
|
|
77
|
+
return result(this.id, [change], { notes: [`Removed provider "${opts.providerId}" from ${shortenHome(file)}.`] });
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
/** Used by `doctor` to tell whether our block is still present and current. */
|
|
81
|
+
export function opencodeInstalledBase(configText, providerId) {
|
|
82
|
+
const v = getIn(parseJson(configText), ['provider', providerId, 'options', 'baseURL']);
|
|
83
|
+
return typeof v === 'string' ? v : undefined;
|
|
84
|
+
}
|
|
85
|
+
export const OPENCODE_KEY_ENV = KEY_ENV;
|
|
86
|
+
//# sourceMappingURL=opencode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencode.js","sourceRoot":"","sources":["../../src/adapters/opencode.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,E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AS,CAAC,CAAC,CAAC;IACvF,OAAO,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/C,CAAC;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pi and omp share a provider schema — omp is a fork of pi, and its models.yml
|
|
3
|
+
* is the same document in YAML. One builder, two adapters.
|
|
4
|
+
*/
|
|
5
|
+
import type { ApplyOptions, ConnectionTarget } from '../types.js';
|
|
6
|
+
export declare function buildPiProvider(opts: ApplyOptions, target: ConnectionTarget): Record<string, unknown>;
|
|
7
|
+
/**
|
|
8
|
+
* Some OpenAI-compatible servers reject the `developer` role that pi sends for
|
|
9
|
+
* reasoning models. LiteLLM passes the role through to the upstream, so whether
|
|
10
|
+
* it works depends on the model behind the alias. Leaving the flag unset keeps
|
|
11
|
+
* pi's own default; `doctor` reports the truth after a live call.
|
|
12
|
+
*/
|
|
13
|
+
export declare const PI_COMPAT_NOTE = "If a reasoning model errors on the `developer` role, set compat.supportsDeveloperRole=false for that model.";
|
|
14
|
+
//# sourceMappingURL=pi-family.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-family.d.ts","sourceRoot":"","sources":["../../src/adapters/pi-family.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAGlE,wBAAgB,eAAe,CAAC,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiBrG;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,gHACoF,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { costOf, ctx, inputKinds, maxOut, modelsToWrite, secretValue } from './helpers.js';
|
|
2
|
+
export function buildPiProvider(opts, target) {
|
|
3
|
+
return {
|
|
4
|
+
name: target.providerLabel,
|
|
5
|
+
baseUrl: target.apiBase,
|
|
6
|
+
api: 'openai-completions',
|
|
7
|
+
apiKey: secretValue(opts, 'dollar'),
|
|
8
|
+
authHeader: true,
|
|
9
|
+
models: modelsToWrite(target).map((m) => ({
|
|
10
|
+
id: m.id,
|
|
11
|
+
name: m.label,
|
|
12
|
+
reasoning: false,
|
|
13
|
+
input: inputKinds(m),
|
|
14
|
+
contextWindow: ctx(m),
|
|
15
|
+
maxTokens: maxOut(m),
|
|
16
|
+
cost: costOf(m),
|
|
17
|
+
})),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Some OpenAI-compatible servers reject the `developer` role that pi sends for
|
|
22
|
+
* reasoning models. LiteLLM passes the role through to the upstream, so whether
|
|
23
|
+
* it works depends on the model behind the alias. Leaving the flag unset keeps
|
|
24
|
+
* pi's own default; `doctor` reports the truth after a live call.
|
|
25
|
+
*/
|
|
26
|
+
export const PI_COMPAT_NOTE = 'If a reasoning model errors on the `developer` role, set compat.supportsDeveloperRole=false for that model.';
|
|
27
|
+
//# sourceMappingURL=pi-family.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-family.js","sourceRoot":"","sources":["../../src/adapters/pi-family.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3F,MAAM,UAAU,eAAe,CAAC,IAAkB,EAAE,MAAwB;IAC1E,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,aAAa;QAC1B,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,GAAG,EAAE,oBAAoB;QACzB,MAAM,EAAE,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC;QACnC,UAAU,EAAE,IAAI;QAChB,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACxC,EAAE,EAAE,CAAC,CAAC,EAAE;YACR,IAAI,EAAE,CAAC,CAAC,KAAK;YACb,SAAS,EAAE,KAAK;YAChB,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC;YACpB,aAAa,EAAE,GAAG,CAAC,CAAC,CAAC;YACrB,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;YACpB,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;SAChB,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GACzB,6GAA6G,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Adapter } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* pi (badlogic/pi-mono) registers custom providers in ~/.pi/agent/models.json.
|
|
4
|
+
* `apiKey` accepts `$ENV_VAR`, a literal, or `!shell-command`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const piAdapter: Adapter;
|
|
7
|
+
export declare const PI_CONFIG: string;
|
|
8
|
+
//# sourceMappingURL=pi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi.d.ts","sourceRoot":"","sources":["../../src/adapters/pi.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAA6B,MAAM,aAAa,CAAC;AAWtE;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,OA6CvB,CAAC;AAEF,eAAO,MAAM,SAAS,QAA+B,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { readIfExists, shortenHome, writeFileSafely } from '../fsutil/edit.js';
|
|
3
|
+
import { parseJson, stringifyJson } from '../fsutil/formats.js';
|
|
4
|
+
import { detectByBinOrConfig } from '../core/detect.js';
|
|
5
|
+
import { deleteIn, envVarsFor, home, result, setIn } from './helpers.js';
|
|
6
|
+
import { PI_COMPAT_NOTE, buildPiProvider } from './pi-family.js';
|
|
7
|
+
function userConfig() {
|
|
8
|
+
return home('.pi', 'agent', 'models.json');
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* pi (badlogic/pi-mono) registers custom providers in ~/.pi/agent/models.json.
|
|
12
|
+
* `apiKey` accepts `$ENV_VAR`, a literal, or `!shell-command`.
|
|
13
|
+
*/
|
|
14
|
+
export const piAdapter = {
|
|
15
|
+
id: 'pi',
|
|
16
|
+
name: 'pi',
|
|
17
|
+
summary: 'Terminal coding agent by Mario Zechner. Providers live in ~/.pi/agent/models.json.',
|
|
18
|
+
docsUrl: 'https://github.com/badlogic/pi-mono/blob/main/packages/coding-agent/docs/models.md',
|
|
19
|
+
bins: ['pi'],
|
|
20
|
+
mode: 'auto',
|
|
21
|
+
secretModes: ['inline', 'env'],
|
|
22
|
+
async detect() {
|
|
23
|
+
return detectByBinOrConfig(['pi'], [userConfig(), home('.pi', 'agent')]);
|
|
24
|
+
},
|
|
25
|
+
configPath({ configPathOverride }) {
|
|
26
|
+
return configPathOverride ?? userConfig();
|
|
27
|
+
},
|
|
28
|
+
async apply(opts) {
|
|
29
|
+
const file = this.configPath(opts);
|
|
30
|
+
const before = await readIfExists(file);
|
|
31
|
+
const doc = parseJson(before);
|
|
32
|
+
setIn(doc, ['providers', opts.target.providerId], buildPiProvider(opts, opts.target));
|
|
33
|
+
const change = await writeFileSafely(file, stringifyJson(doc, before), { dryRun: opts.dryRun });
|
|
34
|
+
const model = opts.target.defaultModel;
|
|
35
|
+
return result(this.id, [change], {
|
|
36
|
+
envVars: envVarsFor(opts),
|
|
37
|
+
notes: [
|
|
38
|
+
model ? `Start with: pi --model ${model}` : 'Run `pi --list-models` to see the registered models.',
|
|
39
|
+
PI_COMPAT_NOTE,
|
|
40
|
+
],
|
|
41
|
+
...(model ? { tryCommand: `pi --model ${model}` } : {}),
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
async remove(opts) {
|
|
45
|
+
const file = this.configPath(opts);
|
|
46
|
+
const before = await readIfExists(file);
|
|
47
|
+
if (before === null)
|
|
48
|
+
return result(this.id, []);
|
|
49
|
+
const doc = parseJson(before);
|
|
50
|
+
deleteIn(doc, ['providers', opts.providerId]);
|
|
51
|
+
const change = await writeFileSafely(file, stringifyJson(doc, before), { dryRun: opts.dryRun });
|
|
52
|
+
return result(this.id, [change], { notes: [`Removed provider "${opts.providerId}" from ${shortenHome(file)}.`] });
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
export const PI_CONFIG = path.normalize(userConfig());
|
|
56
|
+
//# sourceMappingURL=pi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi.js","sourceRoot":"","sources":["../../src/adapters/pi.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjE,SAAS,UAAU;IACjB,OAAO,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;AAC7C,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAY;IAChC,EAAE,EAAE,IAAI;IACR,IAAI,EAAE,IAAI;IACV,OAAO,EAAE,oFAAoF;IAC7F,OAAO,EAAE,oFAAoF;IAC7F,IAAI,EAAE,CAAC,IAAI,CAAC;IACZ,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE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