@illuminis/comprism 0.1.7 → 2.4.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/out/{graph → build/machine/codemap}/read-python.js +2 -2
- package/out/{executor → build/machine/executor}/diagnostics.js +1 -1
- package/out/{executor → build/machine/executor}/hooks.js +1 -1
- package/out/{executor → build/machine/executor}/sandbox.js +1 -1
- package/out/build/machine/line/index.js +339 -0
- package/out/{commands/privacy.js → build/machine/runtime/home.js} +10 -19
- package/out/build/machine/runtime/needs.js +89 -0
- package/out/{lib → build/machine/runtime}/self.js +25 -3
- package/out/build/machine/terminal/jobs.js +67 -0
- package/out/build/machine/terminal/sign-in.js +212 -0
- package/out/build/machine/terminal/steps.js +460 -0
- package/out/build/machine/terminal/voice.js +136 -0
- package/out/build/machine/voice/record.js +286 -0
- package/out/cli-start.js +128 -0
- package/out/machine/line/index.js +339 -0
- package/out/machine/runtime/self.js +22 -0
- package/out/machine/terminal/clipboard.js +182 -0
- package/out/machine/terminal/jobs.js +67 -0
- package/out/machine/terminal/sign-in.js +212 -0
- package/out/machine/terminal/steps.js +460 -0
- package/out/machine/terminal/voice.js +136 -0
- package/out/machine/voice/record.js +79 -1
- package/out/native/dictate +0 -0
- package/out/server.generated.js +6 -0
- package/package.json +8 -40
- package/README.md +0 -343
- package/out/agent/command.d.ts +0 -157
- package/out/agent/command.js +0 -454
- package/out/agent/render.d.ts +0 -169
- package/out/agent/render.js +0 -689
- package/out/agent/session.d.ts +0 -334
- package/out/agent/session.js +0 -1223
- package/out/commands/agents.d.ts +0 -2
- package/out/commands/agents.js +0 -79
- package/out/commands/ask.d.ts +0 -1
- package/out/commands/ask.js +0 -222
- package/out/commands/codemap.d.ts +0 -2
- package/out/commands/codemap.js +0 -151
- package/out/commands/commands-thin.d.ts +0 -39
- package/out/commands/commands-thin.js +0 -244
- package/out/commands/config.d.ts +0 -1
- package/out/commands/config.js +0 -138
- package/out/commands/cost.d.ts +0 -1
- package/out/commands/cost.js +0 -167
- package/out/commands/decisionEngine.d.ts +0 -1
- package/out/commands/decisionEngine.js +0 -66
- package/out/commands/hooks.d.ts +0 -1
- package/out/commands/hooks.js +0 -83
- package/out/commands/install.d.ts +0 -206
- package/out/commands/install.js +0 -738
- package/out/commands/instructions.d.ts +0 -1
- package/out/commands/instructions.js +0 -113
- package/out/commands/integrations.d.ts +0 -3
- package/out/commands/integrations.js +0 -215
- package/out/commands/jobs.d.ts +0 -5
- package/out/commands/jobs.js +0 -157
- package/out/commands/keys.d.ts +0 -55
- package/out/commands/keys.js +0 -344
- package/out/commands/login.d.ts +0 -9
- package/out/commands/login.js +0 -606
- package/out/commands/memory.d.ts +0 -3
- package/out/commands/memory.js +0 -113
- package/out/commands/permissions.d.ts +0 -1
- package/out/commands/permissions.js +0 -94
- package/out/commands/plugins.d.ts +0 -4
- package/out/commands/plugins.js +0 -192
- package/out/commands/privacy.d.ts +0 -1
- package/out/commands/providerKey.d.ts +0 -32
- package/out/commands/providerKey.js +0 -108
- package/out/commands/repl.d.ts +0 -12
- package/out/commands/repl.js +0 -2303
- package/out/commands/report.d.ts +0 -39
- package/out/commands/report.js +0 -115
- package/out/commands/review.d.ts +0 -5
- package/out/commands/review.js +0 -223
- package/out/commands/sessions.d.ts +0 -23
- package/out/commands/sessions.js +0 -115
- package/out/commands/settings.d.ts +0 -23
- package/out/commands/settings.js +0 -153
- package/out/commands/skills.d.ts +0 -21
- package/out/commands/skills.js +0 -207
- package/out/commands/unattended.d.ts +0 -7
- package/out/commands/unattended.js +0 -351
- package/out/commands/update.d.ts +0 -1
- package/out/commands/update.js +0 -123
- package/out/commands/welcome.d.ts +0 -25
- package/out/commands/welcome.js +0 -223
- package/out/commands/worktrees.d.ts +0 -5
- package/out/commands/worktrees.js +0 -186
- package/out/executor/browser.d.ts +0 -14
- package/out/executor/diagnostics.d.ts +0 -2
- package/out/executor/documents.d.ts +0 -40
- package/out/executor/files.d.ts +0 -2
- package/out/executor/git.d.ts +0 -48
- package/out/executor/hooks.d.ts +0 -51
- package/out/executor/index.d.ts +0 -45
- package/out/executor/notebook.d.ts +0 -2
- package/out/executor/paths.d.ts +0 -20
- package/out/executor/sandbox.d.ts +0 -40
- package/out/executor/shell.d.ts +0 -86
- package/out/executor/toolservers.d.ts +0 -20
- package/out/executor/worktree.d.ts +0 -9
- package/out/graph/build.d.ts +0 -45
- package/out/graph/facts.d.ts +0 -47
- package/out/graph/files.d.ts +0 -45
- package/out/graph/read-locales.d.ts +0 -29
- package/out/graph/read-python.d.ts +0 -11
- package/out/graph/read-typescript.d.ts +0 -16
- package/out/graph/sync.d.ts +0 -66
- package/out/graph/sync.js +0 -242
- package/out/lib/attach.d.ts +0 -106
- package/out/lib/attach.js +0 -396
- package/out/lib/clipboard.d.ts +0 -23
- package/out/lib/commandlist.d.ts +0 -20
- package/out/lib/commandlist.js +0 -58
- package/out/lib/config.d.ts +0 -94
- package/out/lib/config.js +0 -197
- package/out/lib/connection.d.ts +0 -73
- package/out/lib/connection.js +0 -188
- package/out/lib/decision.d.ts +0 -22
- package/out/lib/decision.js +0 -50
- package/out/lib/fingerprint.d.ts +0 -25
- package/out/lib/fingerprint.js +0 -58
- package/out/lib/gateway.d.ts +0 -427
- package/out/lib/gateway.js +0 -226
- package/out/lib/history.d.ts +0 -24
- package/out/lib/history.js +0 -137
- package/out/lib/ide.d.ts +0 -19
- package/out/lib/ide.js +0 -131
- package/out/lib/keyboard.d.ts +0 -98
- package/out/lib/keyboard.js +0 -390
- package/out/lib/lastlogin.d.ts +0 -14
- package/out/lib/lastlogin.js +0 -105
- package/out/lib/machine.d.ts +0 -21
- package/out/lib/machine.js +0 -91
- package/out/lib/notify.d.ts +0 -4
- package/out/lib/notify.js +0 -52
- package/out/lib/output.d.ts +0 -48
- package/out/lib/output.js +0 -108
- package/out/lib/picker.d.ts +0 -1
- package/out/lib/picker.js +0 -158
- package/out/lib/project-ops.d.ts +0 -19
- package/out/lib/project-ops.js +0 -146
- package/out/lib/project.d.ts +0 -28
- package/out/lib/prompt.d.ts +0 -37
- package/out/lib/prompt.js +0 -142
- package/out/lib/queue.d.ts +0 -13
- package/out/lib/queue.js +0 -116
- package/out/lib/readiness.d.ts +0 -22
- package/out/lib/readiness.js +0 -207
- package/out/lib/self.d.ts +0 -23
- package/out/lib/servicecommand.d.ts +0 -14
- package/out/lib/servicecommand.js +0 -74
- package/out/lib/sessions.d.ts +0 -19
- package/out/lib/sessions.js +0 -221
- package/out/lib/startcache.d.ts +0 -13
- package/out/lib/startcache.js +0 -78
- package/out/lib/stdin.d.ts +0 -32
- package/out/lib/stdin.js +0 -117
- package/out/lib/store.d.ts +0 -40
- package/out/lib/store.js +0 -138
- package/out/lib/sync.d.ts +0 -18
- package/out/lib/sync.js +0 -81
- package/out/lib/types.d.ts +0 -417
- package/out/lib/types.js +0 -21
- package/out/lib/ui.d.ts +0 -123
- package/out/lib/ui.js +0 -299
- package/out/lib/version.d.ts +0 -23
- package/out/lib/version.js +0 -46
- package/out/lib/voice.d.ts +0 -49
- package/out/lib/voice.js +0 -236
- package/out/lib/words.d.ts +0 -20
- package/out/lib/words.js +0 -27
- package/out/machine/codemap/build.d.ts +0 -45
- package/out/machine/codemap/facts.d.ts +0 -47
- package/out/machine/codemap/files.d.ts +0 -45
- package/out/machine/codemap/read-locales.d.ts +0 -29
- package/out/machine/codemap/read-python.d.ts +0 -11
- package/out/machine/codemap/read-typescript.d.ts +0 -16
- package/out/machine/executor/browser.d.ts +0 -14
- package/out/machine/executor/diagnostics.d.ts +0 -2
- package/out/machine/executor/documents.d.ts +0 -40
- package/out/machine/executor/files.d.ts +0 -2
- package/out/machine/executor/git.d.ts +0 -48
- package/out/machine/executor/hooks.d.ts +0 -51
- package/out/machine/executor/index.d.ts +0 -45
- package/out/machine/executor/notebook.d.ts +0 -2
- package/out/machine/executor/paths.d.ts +0 -20
- package/out/machine/executor/sandbox.d.ts +0 -40
- package/out/machine/executor/shell.d.ts +0 -86
- package/out/machine/executor/toolservers.d.ts +0 -20
- package/out/machine/executor/worktree.d.ts +0 -9
- package/out/machine/folder/project.d.ts +0 -28
- package/out/machine/runtime/home.d.ts +0 -2
- package/out/machine/runtime/needs.d.ts +0 -30
- package/out/machine/runtime/self.d.ts +0 -23
- package/out/machine/voice/record.d.ts +0 -38
- package/out/postinstall.d.ts +0 -2
- package/out/postinstall.js +0 -120
- package/out/providers/anthropic.d.ts +0 -22
- package/out/providers/anthropic.js +0 -80
- package/out/providers/index.d.ts +0 -8
- package/out/providers/index.js +0 -84
- package/out/providers/openai.d.ts +0 -11
- package/out/providers/openai.js +0 -57
- package/out/thin.d.ts +0 -2
- package/out/thin.js +0 -855
- package/scripts/read_python.py +0 -270
- /package/out/{graph → build/machine/codemap}/build.js +0 -0
- /package/out/{graph → build/machine/codemap}/facts.js +0 -0
- /package/out/{graph → build/machine/codemap}/files.js +0 -0
- /package/out/{graph → build/machine/codemap}/read-locales.js +0 -0
- /package/out/{graph → build/machine/codemap}/read-typescript.js +0 -0
- /package/out/{executor → build/machine/executor}/browser.js +0 -0
- /package/out/{executor → build/machine/executor}/documents.js +0 -0
- /package/out/{executor → build/machine/executor}/files.js +0 -0
- /package/out/{executor → build/machine/executor}/git.js +0 -0
- /package/out/{executor → build/machine/executor}/index.js +0 -0
- /package/out/{executor → build/machine/executor}/notebook.js +0 -0
- /package/out/{executor → build/machine/executor}/paths.js +0 -0
- /package/out/{executor → build/machine/executor}/shell.js +0 -0
- /package/out/{executor → build/machine/executor}/toolservers.js +0 -0
- /package/out/{executor → build/machine/executor}/worktree.js +0 -0
- /package/out/{lib → build/machine/folder}/project.js +0 -0
- /package/out/{lib → build/machine/terminal}/clipboard.js +0 -0
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export interface Requirement {
|
|
2
|
-
/** What it is for, said as the work it makes possible. */
|
|
3
|
-
purpose: string;
|
|
4
|
-
/** Any one of these being present is enough. */
|
|
5
|
-
anyOf: string[];
|
|
6
|
-
/** Work that cannot be done without it, for the message. */
|
|
7
|
-
without: string;
|
|
8
|
-
/** True when the tool cannot function at all without this. */
|
|
9
|
-
essential: boolean;
|
|
10
|
-
}
|
|
11
|
-
export declare const REQUIREMENTS: Requirement[];
|
|
12
|
-
/** Is this program on the machine, by name, without running anything of theirs. */
|
|
13
|
-
export declare function present(program: string): boolean;
|
|
14
|
-
/**
|
|
15
|
-
* The one command that installs what is missing, for the machine it is on.
|
|
16
|
-
*
|
|
17
|
-
* Named per platform rather than guessed: telling somebody on Ubuntu to run a
|
|
18
|
-
* Homebrew command is worse than saying nothing, because they now have to work
|
|
19
|
-
* out that the instruction was wrong before they can work out what is right.
|
|
20
|
-
*/
|
|
21
|
-
export declare function howToInstall(missing: string[]): string;
|
|
22
|
-
export interface Readiness {
|
|
23
|
-
ready: boolean;
|
|
24
|
-
/** One line per requirement, ready to print. */
|
|
25
|
-
lines: string[];
|
|
26
|
-
/** The command to run, empty when nothing is missing. */
|
|
27
|
-
fix: string;
|
|
28
|
-
}
|
|
29
|
-
/** What this machine can and cannot do, and how to close the gap. */
|
|
30
|
-
export declare function check(): Readiness;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/** True when running as the ready to run program rather than under Node. */
|
|
2
|
-
export declare function isStandalone(): boolean;
|
|
3
|
-
/** Where the install script keeps the program: `~/.comprism/bin`. */
|
|
4
|
-
export declare function standaloneBinDir(): string;
|
|
5
|
-
export type InstallMethod = "script" | "npm" | "python";
|
|
6
|
-
/**
|
|
7
|
-
* Which of the three install options put this copy here.
|
|
8
|
-
*
|
|
9
|
-
* The program is only ever distributed two ways, so where it sits decides it:
|
|
10
|
-
* in `~/.comprism/bin` it came from the install script, anywhere else pip put
|
|
11
|
-
* it. Under Node it came from npm.
|
|
12
|
-
*/
|
|
13
|
-
export declare function installMethod(): InstallMethod;
|
|
14
|
-
/** The command and arguments that start another copy of this tool. */
|
|
15
|
-
export declare function selfLaunch(args: string[], nodeFlags?: string[]): [string, string[]];
|
|
16
|
-
/**
|
|
17
|
-
* A file shipped beside the code, as a path on disk.
|
|
18
|
-
*
|
|
19
|
-
* Under npm it sits in the package. Inside the program it is carried as an
|
|
20
|
-
* asset and written once to `~/.comprism/assets`, because the programs it is
|
|
21
|
-
* handed to (Python, for the reader script) need a real file.
|
|
22
|
-
*/
|
|
23
|
-
export declare function shippedFile(name: string, packagePath: string): string;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/** One recording tool, as this file needs to drive it. */
|
|
2
|
-
export interface Recorder {
|
|
3
|
-
/** What to tell somebody who wants to know what is listening. */
|
|
4
|
-
name: string;
|
|
5
|
-
command: string;
|
|
6
|
-
args: (out: string) => string[];
|
|
7
|
-
}
|
|
8
|
-
/** The first recording tool this machine has, or null. */
|
|
9
|
-
export declare function recorder(): Recorder | null;
|
|
10
|
-
/**
|
|
11
|
-
* What to tell somebody who has no recording tool, or null when they do.
|
|
12
|
-
*
|
|
13
|
-
* One sentence and one command. Not a list of three options with trade-offs:
|
|
14
|
-
* somebody who just wanted to say a sentence out loud is not shopping for audio
|
|
15
|
-
* software.
|
|
16
|
-
*/
|
|
17
|
-
export declare function missing(): string | null;
|
|
18
|
-
/** A recording in progress. */
|
|
19
|
-
export interface Recording {
|
|
20
|
-
/** Where the audio is being written. */
|
|
21
|
-
file: string;
|
|
22
|
-
/** What is doing the listening, for the line on screen. */
|
|
23
|
-
by: string;
|
|
24
|
-
/** Stop, wait for the file to be finished properly, and hand it back. */
|
|
25
|
-
stop: () => Promise<{
|
|
26
|
-
file: string;
|
|
27
|
-
bytes: number;
|
|
28
|
-
}>;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Start listening.
|
|
32
|
-
*
|
|
33
|
-
* Throws when there is nothing to listen with, which the caller should have
|
|
34
|
-
* headed off with `missing` so the person gets a sentence rather than an error.
|
|
35
|
-
*/
|
|
36
|
-
export declare function start(): Recording;
|
|
37
|
-
/** Delete the recording and the folder holding it. Always, and immediately. */
|
|
38
|
-
export declare function discard(file: string): void;
|
package/out/postinstall.d.ts
DELETED
package/out/postinstall.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
/**
|
|
8
|
-
* Runs on `npm install -g @illuminis/comprism`. Rule R1.
|
|
9
|
-
*
|
|
10
|
-
* The whole point is that the user types one command and is finished. So the
|
|
11
|
-
* install configures interception itself rather than printing instructions.
|
|
12
|
-
*
|
|
13
|
-
* Three things make that safe to do to somebody's machine automatically:
|
|
14
|
-
*
|
|
15
|
-
* - It is fenced and reversible. One marked block in the shell profile, and
|
|
16
|
-
* `comprism uninstall` removes exactly it.
|
|
17
|
-
* - It says out loud what it touched. No silent edits.
|
|
18
|
-
* - It cannot break anything. The script it installs exports nothing unless a
|
|
19
|
-
* recorder is actually answering, so a broken or missing proxy leaves every
|
|
20
|
-
* AI tool on the machine talking straight to its provider, as before.
|
|
21
|
-
*
|
|
22
|
-
* And it never fails the install: `|| true` in the npm script, plus this file
|
|
23
|
-
* swallowing its own errors. A package that fails to install because its
|
|
24
|
-
* telemetry could not configure itself deserves to be uninstalled.
|
|
25
|
-
*/
|
|
26
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
27
|
-
const install_1 = require("./commands/install");
|
|
28
|
-
const readiness_1 = require("./lib/readiness");
|
|
29
|
-
/**
|
|
30
|
-
* Written to the terminal itself, not to npm. npm hides everything an install
|
|
31
|
-
* script prints unless the install fails, so the next steps a person needs
|
|
32
|
-
* right now never reached the screen (owner, 27 September 2026). Falls back to
|
|
33
|
-
* standard output where there is no terminal, such as a build server's log.
|
|
34
|
-
*/
|
|
35
|
-
function say(text) {
|
|
36
|
-
const tty = process.platform === 'win32' ? 'CONOUT$' : '/dev/tty';
|
|
37
|
-
try {
|
|
38
|
-
const fd = node_fs_1.default.openSync(tty, 'w');
|
|
39
|
-
node_fs_1.default.writeSync(fd, text);
|
|
40
|
-
node_fs_1.default.closeSync(fd);
|
|
41
|
-
}
|
|
42
|
-
catch {
|
|
43
|
-
process.stdout.write(text);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
async function main() {
|
|
47
|
-
// Local development installs (`npm install` inside the repo) should not touch
|
|
48
|
-
// the developer's shell profile. Only a global install means "set me up".
|
|
49
|
-
const isGlobal = process.env.npm_config_global === 'true';
|
|
50
|
-
if (!isGlobal)
|
|
51
|
-
return;
|
|
52
|
-
try {
|
|
53
|
-
const report = (0, install_1.install)();
|
|
54
|
-
// Claude Desktop is not something this script can finish. A remote
|
|
55
|
-
// connector is authorized by a consent screen, so the honest output is the
|
|
56
|
-
// address to paste - never a claim that it is live.
|
|
57
|
-
//
|
|
58
|
-
// This path is the one that used to get it wrong twice over: npm runs this
|
|
59
|
-
// script, so anything derived from the running file is derived from
|
|
60
|
-
// POSTINSTALL rather than the CLI, and the entry it wrote looked perfectly
|
|
61
|
-
// reasonable in the config file while being a server that could only
|
|
62
|
-
// observe. It reported "registered and answering" and the user then saw no
|
|
63
|
-
// receipt and an empty Sessions screen, with nothing anywhere saying why.
|
|
64
|
-
const desktopLines = [];
|
|
65
|
-
if (report.desktop.staleRemoved) {
|
|
66
|
-
desktopLines.push(' · removed an old CompletionPrism entry from Claude Desktop (it could not answer)');
|
|
67
|
-
}
|
|
68
|
-
// Only when Claude Desktop is on this machine: a line about an app somebody
|
|
69
|
-
// does not have is noise in a list of next steps.
|
|
70
|
-
if (report.desktop.note && report.desktop.present) {
|
|
71
|
-
desktopLines.push(` · ${report.desktop.note}`);
|
|
72
|
-
}
|
|
73
|
-
else if (report.desktop.present && report.baseUrl) {
|
|
74
|
-
desktopLines.push(` · Claude Desktop: add ${report.baseUrl}/mcp under Settings > Connectors`);
|
|
75
|
-
}
|
|
76
|
-
// A short numbered list of what to do next, and nothing a person has to
|
|
77
|
-
// decode. The setup detail (which profile got a line) is one quiet line.
|
|
78
|
-
const signIn = !(report.enrolled && report.baseUrl);
|
|
79
|
-
const steps = [
|
|
80
|
-
'Open a new terminal window.',
|
|
81
|
-
...(signIn ? ['Sign in: comprism login'] : []),
|
|
82
|
-
'Start working: comprism (or claude, already measured)',
|
|
83
|
-
...(report.baseUrl ? [`See what it saved: ${report.baseUrl}`] : []),
|
|
84
|
-
];
|
|
85
|
-
say([
|
|
86
|
-
'',
|
|
87
|
-
' CompletionPrism is installed.',
|
|
88
|
-
'',
|
|
89
|
-
' Next steps',
|
|
90
|
-
...steps.map((line, i) => ` ${i + 1}. ${line}`),
|
|
91
|
-
...desktopLines,
|
|
92
|
-
'',
|
|
93
|
-
...report.profilesTouched.map((p) => ` Set up in ${p}.`),
|
|
94
|
-
' To remove it later, one command: comprism uninstall',
|
|
95
|
-
'',
|
|
96
|
-
].join('\n'));
|
|
97
|
-
// What this machine still needs, said at the only moment somebody is
|
|
98
|
-
// thinking about setup. Finding out three days later, mid job, that a PDF
|
|
99
|
-
// cannot be read is the same information delivered at the worst possible
|
|
100
|
-
// time. Said only when something IS missing: a list of things that are
|
|
101
|
-
// already fine is noise on a screen somebody is about to close.
|
|
102
|
-
const machine = (0, readiness_1.check)();
|
|
103
|
-
if (!machine.ready) {
|
|
104
|
-
say([
|
|
105
|
-
' Two things the work itself may need on this machine:',
|
|
106
|
-
...machine.lines,
|
|
107
|
-
'',
|
|
108
|
-
` To add what is missing: ${machine.fix}`,
|
|
109
|
-
' Everything else, including Word, PowerPoint and PDF documents, is',
|
|
110
|
-
' built on our servers and needs nothing installed here.',
|
|
111
|
-
'',
|
|
112
|
-
].join('\n'));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
catch {
|
|
116
|
-
// Never fail an install over setup. The user can run `comprism install`.
|
|
117
|
-
say('\n CompletionPrism is installed. Next step: open a new terminal and run `comprism install`.\n\n');
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
void main();
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Anthropic adapter.
|
|
3
|
-
*
|
|
4
|
-
* Deliberately dependency-free: the Messages API over `fetch`, nothing else.
|
|
5
|
-
* The Companion has to install into someone else's tool without dragging a
|
|
6
|
-
* dependency tree behind it, and a proxy that sits in front of a provider is a
|
|
7
|
-
* poor place to inherit somebody's transitive supply chain.
|
|
8
|
-
*/
|
|
9
|
-
import type { Message, ProviderResult } from '../lib/types';
|
|
10
|
-
export interface AnthropicCall {
|
|
11
|
-
model: string;
|
|
12
|
-
messages: Message[];
|
|
13
|
-
maxTokens: number;
|
|
14
|
-
apiKey: string;
|
|
15
|
-
}
|
|
16
|
-
export declare function callAnthropic(call: AnthropicCall): Promise<ProviderResult>;
|
|
17
|
-
/** Carries the status code so the shared retry policy can read it. */
|
|
18
|
-
export declare class ProviderHttpError extends Error {
|
|
19
|
-
status: number;
|
|
20
|
-
latencyMs: number;
|
|
21
|
-
constructor(status: number, message: string);
|
|
22
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProviderHttpError = void 0;
|
|
4
|
-
exports.callAnthropic = callAnthropic;
|
|
5
|
-
const DEFAULT_BASE = 'https://api.anthropic.com';
|
|
6
|
-
const API_VERSION = '2023-06-01';
|
|
7
|
-
/**
|
|
8
|
-
* Honor the same base-URL override every client in this ecosystem supports.
|
|
9
|
-
*
|
|
10
|
-
* It is the mechanism our own proxy is installed with, so the Companion's SDK
|
|
11
|
-
* respecting it is not a test hook: it is what lets one instrumented tool sit
|
|
12
|
-
* behind another, and what lets a customer point us at a gateway they already
|
|
13
|
-
* run.
|
|
14
|
-
*/
|
|
15
|
-
function endpoint() {
|
|
16
|
-
const base = (process.env.ANTHROPIC_BASE_URL || DEFAULT_BASE).replace(/\/+$/, '');
|
|
17
|
-
return `${base}/v1/messages`;
|
|
18
|
-
}
|
|
19
|
-
async function callAnthropic(call) {
|
|
20
|
-
const started = Date.now();
|
|
21
|
-
const res = await fetch(endpoint(), {
|
|
22
|
-
method: 'POST',
|
|
23
|
-
headers: {
|
|
24
|
-
'content-type': 'application/json',
|
|
25
|
-
'x-api-key': call.apiKey,
|
|
26
|
-
'anthropic-version': API_VERSION,
|
|
27
|
-
},
|
|
28
|
-
body: JSON.stringify({
|
|
29
|
-
model: call.model,
|
|
30
|
-
max_tokens: call.maxTokens,
|
|
31
|
-
messages: call.messages.map((m) => ({ role: m.role, content: m.content })),
|
|
32
|
-
}),
|
|
33
|
-
});
|
|
34
|
-
const latencyMs = Date.now() - started;
|
|
35
|
-
if (!res.ok) {
|
|
36
|
-
// The status line, never the body: a provider error body can echo the
|
|
37
|
-
// request, and the request is the customer's content.
|
|
38
|
-
const err = new ProviderHttpError(res.status, `anthropic ${res.status} ${res.statusText}`);
|
|
39
|
-
err.latencyMs = latencyMs;
|
|
40
|
-
throw err;
|
|
41
|
-
}
|
|
42
|
-
const body = (await res.json());
|
|
43
|
-
const blocks = body.content || [];
|
|
44
|
-
const text = blocks
|
|
45
|
-
.filter((b) => b.type === 'text' && typeof b.text === 'string')
|
|
46
|
-
.map((b) => b.text)
|
|
47
|
-
.join('');
|
|
48
|
-
// A model that thinks by default and is given a tight token ceiling spends the
|
|
49
|
-
// ceiling on thinking and answers with nothing. That returns as an empty
|
|
50
|
-
// string, which is indistinguishable from a bad answer - and it cost a real
|
|
51
|
-
// bake-off run before it was caught. Name it instead of hiding it.
|
|
52
|
-
const thoughtButDidNotAnswer = text.length === 0 && blocks.some((b) => b.type === 'thinking' || b.type === 'redacted_thinking');
|
|
53
|
-
const usage = {
|
|
54
|
-
inputTokens: typeof body.usage?.input_tokens === 'number' ? body.usage.input_tokens : null,
|
|
55
|
-
outputTokens: typeof body.usage?.output_tokens === 'number' ? body.usage.output_tokens : null,
|
|
56
|
-
};
|
|
57
|
-
return {
|
|
58
|
-
text,
|
|
59
|
-
usage,
|
|
60
|
-
finishReason: thoughtButDidNotAnswer ? 'thinking_exhausted_budget' : body.stop_reason || 'end_turn',
|
|
61
|
-
latencyMs,
|
|
62
|
-
usageReported: usage.inputTokens !== null && usage.outputTokens !== null,
|
|
63
|
-
...(thoughtButDidNotAnswer
|
|
64
|
-
? {
|
|
65
|
-
errorMessage: 'the model used its whole token budget thinking and had none left to answer; raise maxTokens',
|
|
66
|
-
}
|
|
67
|
-
: {}),
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
/** Carries the status code so the shared retry policy can read it. */
|
|
71
|
-
class ProviderHttpError extends Error {
|
|
72
|
-
status;
|
|
73
|
-
latencyMs = 0;
|
|
74
|
-
constructor(status, message) {
|
|
75
|
-
super(message);
|
|
76
|
-
this.name = 'ProviderHttpError';
|
|
77
|
-
this.status = status;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
exports.ProviderHttpError = ProviderHttpError;
|
package/out/providers/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Keys } from '../lib/config';
|
|
2
|
-
import type { Provider, ProviderCall, ProviderResult } from '../lib/types';
|
|
3
|
-
export { ProviderHttpError } from './anthropic';
|
|
4
|
-
export declare function providerOf(model: string): Provider | null;
|
|
5
|
-
/**
|
|
6
|
-
* Dispatch one call. Returns a result in every case, including failure.
|
|
7
|
-
*/
|
|
8
|
-
export declare function callModel(call: ProviderCall, keys: Keys): Promise<ProviderResult>;
|
package/out/providers/index.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ProviderHttpError = void 0;
|
|
4
|
-
exports.providerOf = providerOf;
|
|
5
|
-
exports.callModel = callModel;
|
|
6
|
-
/**
|
|
7
|
-
* One normalized call interface across every provider.
|
|
8
|
-
*
|
|
9
|
-
* Two properties matter to everything downstream:
|
|
10
|
-
*
|
|
11
|
-
* 1. `callModel` never throws out of `send()`. A provider error becomes
|
|
12
|
-
* `finishReason: 'error'` with an empty body, so the ledger still gets its
|
|
13
|
-
* row and the client still records what happened. Rule 10, fail open: the
|
|
14
|
-
* product being unable to reach a provider must look like a recorded
|
|
15
|
-
* failure, not like a crash in someone's editor.
|
|
16
|
-
* 2. One retry on 429 and 5xx with jitter, then surface. A second retry buys
|
|
17
|
-
* little and doubles the worst-case wait a person is sitting through.
|
|
18
|
-
*/
|
|
19
|
-
const catalog_1 = require("../internal/catalog");
|
|
20
|
-
const anthropic_1 = require("./anthropic");
|
|
21
|
-
const openai_1 = require("./openai");
|
|
22
|
-
const words_1 = require("../lib/words");
|
|
23
|
-
var anthropic_2 = require("./anthropic");
|
|
24
|
-
Object.defineProperty(exports, "ProviderHttpError", { enumerable: true, get: function () { return anthropic_2.ProviderHttpError; } });
|
|
25
|
-
const DEFAULT_MAX_TOKENS = 4096;
|
|
26
|
-
const RETRY_BASE_MS = 400;
|
|
27
|
-
function isRetryable(err) {
|
|
28
|
-
if (err instanceof anthropic_1.ProviderHttpError)
|
|
29
|
-
return err.status === 429 || err.status >= 500;
|
|
30
|
-
// A transport failure - DNS, reset connection, timeout - is worth one retry.
|
|
31
|
-
return err instanceof TypeError;
|
|
32
|
-
}
|
|
33
|
-
function jitteredDelay() {
|
|
34
|
-
return RETRY_BASE_MS + Math.floor(Math.random() * RETRY_BASE_MS);
|
|
35
|
-
}
|
|
36
|
-
function sleep(ms) {
|
|
37
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
38
|
-
}
|
|
39
|
-
function providerOf(model) {
|
|
40
|
-
return (0, catalog_1.findModel)(model)?.provider ?? null;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Dispatch one call. Returns a result in every case, including failure.
|
|
44
|
-
*/
|
|
45
|
-
async function callModel(call, keys) {
|
|
46
|
-
const provider = providerOf(call.model);
|
|
47
|
-
if (!provider) {
|
|
48
|
-
return errorResult(`unknown model: ${call.model}`, 0);
|
|
49
|
-
}
|
|
50
|
-
const apiKey = keys[provider];
|
|
51
|
-
if (!apiKey) {
|
|
52
|
-
return errorResult(`no key resolved for ${provider}`, 0);
|
|
53
|
-
}
|
|
54
|
-
const maxTokens = call.maxTokens ?? DEFAULT_MAX_TOKENS;
|
|
55
|
-
const args = { model: call.model, messages: call.messages, maxTokens, apiKey };
|
|
56
|
-
for (let attempt = 0; attempt < 2; attempt++) {
|
|
57
|
-
try {
|
|
58
|
-
return provider === 'anthropic' ? await (0, anthropic_1.callAnthropic)(args) : await (0, openai_1.callOpenAi)(args);
|
|
59
|
-
}
|
|
60
|
-
catch (err) {
|
|
61
|
-
if (attempt === 0 && isRetryable(err)) {
|
|
62
|
-
await sleep(jitteredDelay());
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
const latency = err instanceof anthropic_1.ProviderHttpError ? err.latencyMs : 0;
|
|
66
|
-
return errorResult(err instanceof Error ? err.message : (0, words_1.word)('providerCallFailed'), latency);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return errorResult('provider call failed', 0);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* The failure shape. The message is a status line or a transport error - never
|
|
73
|
-
* a response body, which can contain the request that produced it.
|
|
74
|
-
*/
|
|
75
|
-
function errorResult(message, latencyMs) {
|
|
76
|
-
return {
|
|
77
|
-
text: '',
|
|
78
|
-
usage: { inputTokens: null, outputTokens: null },
|
|
79
|
-
finishReason: 'error',
|
|
80
|
-
latencyMs,
|
|
81
|
-
usageReported: false,
|
|
82
|
-
errorMessage: message,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OpenAI adapter. Same shape as the Anthropic one, same dependency-free stance.
|
|
3
|
-
*/
|
|
4
|
-
import type { Message, ProviderResult } from '../lib/types';
|
|
5
|
-
export interface OpenAiCall {
|
|
6
|
-
model: string;
|
|
7
|
-
messages: Message[];
|
|
8
|
-
maxTokens: number;
|
|
9
|
-
apiKey: string;
|
|
10
|
-
}
|
|
11
|
-
export declare function callOpenAi(call: OpenAiCall): Promise<ProviderResult>;
|
package/out/providers/openai.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.callOpenAi = callOpenAi;
|
|
4
|
-
const anthropic_1 = require("./anthropic");
|
|
5
|
-
const DEFAULT_BASE = 'https://api.openai.com/v1';
|
|
6
|
-
/** Same base-URL override every OpenAI-compatible client already supports. */
|
|
7
|
-
function endpoint() {
|
|
8
|
-
const base = (process.env.OPENAI_BASE_URL || DEFAULT_BASE).replace(/\/+$/, '');
|
|
9
|
-
return `${base}/chat/completions`;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* The reasoning-model families take `max_completion_tokens`; the older chat
|
|
13
|
-
* families take `max_tokens`. Sending the wrong one is a 400, so the choice is
|
|
14
|
-
* made from the model id rather than left to the caller.
|
|
15
|
-
*/
|
|
16
|
-
function tokenLimitField(model) {
|
|
17
|
-
return /^gpt-4/.test(model) ? 'max_tokens' : 'max_completion_tokens';
|
|
18
|
-
}
|
|
19
|
-
async function callOpenAi(call) {
|
|
20
|
-
const started = Date.now();
|
|
21
|
-
const body = {
|
|
22
|
-
model: call.model,
|
|
23
|
-
messages: call.messages.map((m) => ({ role: m.role, content: m.content })),
|
|
24
|
-
};
|
|
25
|
-
body[tokenLimitField(call.model)] = call.maxTokens;
|
|
26
|
-
const res = await fetch(endpoint(), {
|
|
27
|
-
method: 'POST',
|
|
28
|
-
headers: {
|
|
29
|
-
'content-type': 'application/json',
|
|
30
|
-
authorization: `Bearer ${call.apiKey}`,
|
|
31
|
-
},
|
|
32
|
-
body: JSON.stringify(body),
|
|
33
|
-
});
|
|
34
|
-
const latencyMs = Date.now() - started;
|
|
35
|
-
if (!res.ok) {
|
|
36
|
-
const err = new anthropic_1.ProviderHttpError(res.status, `openai ${res.status} ${res.statusText}`);
|
|
37
|
-
err.latencyMs = latencyMs;
|
|
38
|
-
throw err;
|
|
39
|
-
}
|
|
40
|
-
const parsed = (await res.json());
|
|
41
|
-
const choice = parsed.choices?.[0];
|
|
42
|
-
const text = choice?.message?.content || '';
|
|
43
|
-
const usage = {
|
|
44
|
-
inputTokens: typeof parsed.usage?.prompt_tokens === 'number' ? parsed.usage.prompt_tokens : null,
|
|
45
|
-
outputTokens: typeof parsed.usage?.completion_tokens === 'number' ? parsed.usage.completion_tokens : null,
|
|
46
|
-
reasoningTokens: typeof parsed.usage?.completion_tokens_details?.reasoning_tokens === 'number'
|
|
47
|
-
? parsed.usage.completion_tokens_details.reasoning_tokens
|
|
48
|
-
: null,
|
|
49
|
-
};
|
|
50
|
-
return {
|
|
51
|
-
text,
|
|
52
|
-
usage,
|
|
53
|
-
finishReason: choice?.finish_reason || 'stop',
|
|
54
|
-
latencyMs,
|
|
55
|
-
usageReported: usage.inputTokens !== null && usage.outputTokens !== null,
|
|
56
|
-
};
|
|
57
|
-
}
|
package/out/thin.d.ts
DELETED