@coswic/aipay 0.1.0 → 0.2.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 +22 -0
- package/package.json +1 -1
- package/dist/agent-guide.d.ts +0 -18
- package/dist/agent-guide.js +0 -60
- package/dist/args.d.ts +0 -15
- package/dist/args.js +0 -47
- package/dist/auth-store.d.ts +0 -23
- package/dist/auth-store.js +0 -113
- package/dist/bin.d.ts +0 -2
- package/dist/bin.js +0 -8
- package/dist/browser.d.ts +0 -1
- package/dist/browser.js +0 -18
- package/dist/commands/apps.d.ts +0 -15
- package/dist/commands/apps.js +0 -53
- package/dist/commands/doctor.d.ts +0 -17
- package/dist/commands/doctor.js +0 -153
- package/dist/commands/init.d.ts +0 -18
- package/dist/commands/init.js +0 -252
- package/dist/commands/login.d.ts +0 -25
- package/dist/commands/login.js +0 -149
- package/dist/commands/session.d.ts +0 -6
- package/dist/commands/session.js +0 -63
- package/dist/commands/status.d.ts +0 -3
- package/dist/commands/status.js +0 -24
- package/dist/commands/test.d.ts +0 -12
- package/dist/commands/test.js +0 -159
- package/dist/commands/unlink.d.ts +0 -5
- package/dist/commands/unlink.js +0 -70
- package/dist/detect.d.ts +0 -27
- package/dist/detect.js +0 -79
- package/dist/developer-api.d.ts +0 -14
- package/dist/developer-api.js +0 -74
- package/dist/gate.d.ts +0 -13
- package/dist/gate.js +0 -29
- package/dist/index.d.ts +0 -22
- package/dist/index.js +0 -22
- package/dist/loopback.d.ts +0 -37
- package/dist/loopback.js +0 -95
- package/dist/main.d.ts +0 -5
- package/dist/main.js +0 -90
- package/dist/output.d.ts +0 -36
- package/dist/output.js +0 -52
- package/dist/project.d.ts +0 -50
- package/dist/project.js +0 -107
- package/dist/remote.d.ts +0 -21
- package/dist/remote.js +0 -41
- package/dist/setup-events.d.ts +0 -3
- package/dist/setup-events.js +0 -28
- package/dist/templates.d.ts +0 -24
- package/dist/templates.js +0 -226
- package/dist/version.d.ts +0 -1
- package/dist/version.js +0 -10
package/dist/main.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export declare const HELP = "aipay \u2014 AI-Pay CLI\n\nUsage\n aipay login [--api <base>] [--no-open] [--json] developer sign-in for the CLI itself\n aipay whoami [--json] \u00B7 aipay logout [--json]\n aipay apps list [--json]\n aipay apps create --name <name> [--callback <url>] [--json]\n aipay init --app <client_id> [--auth <origin>] [--api <base>] [--callback <url>] [--name <app name>]\n [--dir <path>] [--dry-run] [--no-install] [--json]\n aipay init --create <app name> [--api <base>] ... create the app (needs login) and link it\n aipay test [--model <id>] [--port <n>] [--no-open] [--timeout <seconds>] [--dir <path>] [--json]\n aipay doctor [--offline] [--dir <path>] [--json]\n aipay status [--dir <path>] [--json]\n aipay unlink [--dry-run] [--dir <path>] [--json]\n\nlogin sign in as a developer (loopback PKCE, audience aipay-developer-api); tokens go to the\n OS keychain or a 0600 file \u2014 never into the project\napps list your apps / create one (Idempotency-Key: a retried create never makes a second app)\ninit link this project to an app: .aipay/project.json, .env.local, .gitignore,\n a callback route for your framework, aipay-agent.md, and the SDK install\n (--auth/--api are optional once you are signed in; --create makes the app first)\ntest real sign-in via a loopback callback (any free port on 127.0.0.1) + one chat completion \u2192 receipt\ndoctor check the link, files, SDK, and that AI-Pay is reachable\nstatus what this directory is linked to\nunlink forget the link (keeps your code)\n\nExit codes: 0 ok \u00B7 1 problem you can fix \u00B7 2 usage \u00B7 3 network/auth\nPilot gate: export AIPAY_GATE_TOKEN=<token from the Console>; never write it to files.\n";
|
|
2
|
-
export declare function main(argv: string[], io?: {
|
|
3
|
-
stdout?: (s: string) => void;
|
|
4
|
-
stderr?: (s: string) => void;
|
|
5
|
-
}): Promise<number>;
|
package/dist/main.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { flagBool, parseArgs } from './args.js';
|
|
2
|
-
import { runApps } from './commands/apps.js';
|
|
3
|
-
import { runDoctor } from './commands/doctor.js';
|
|
4
|
-
import { runInit } from './commands/init.js';
|
|
5
|
-
import { runLogin } from './commands/login.js';
|
|
6
|
-
import { runLogout, runWhoami } from './commands/session.js';
|
|
7
|
-
import { runStatus } from './commands/status.js';
|
|
8
|
-
import { runTest } from './commands/test.js';
|
|
9
|
-
import { runUnlink } from './commands/unlink.js';
|
|
10
|
-
import { CliError, createReporter, EXIT } from './output.js';
|
|
11
|
-
import { cliVersion } from './version.js';
|
|
12
|
-
export const HELP = `aipay — AI-Pay CLI
|
|
13
|
-
|
|
14
|
-
Usage
|
|
15
|
-
aipay login [--api <base>] [--no-open] [--json] developer sign-in for the CLI itself
|
|
16
|
-
aipay whoami [--json] · aipay logout [--json]
|
|
17
|
-
aipay apps list [--json]
|
|
18
|
-
aipay apps create --name <name> [--callback <url>] [--json]
|
|
19
|
-
aipay init --app <client_id> [--auth <origin>] [--api <base>] [--callback <url>] [--name <app name>]
|
|
20
|
-
[--dir <path>] [--dry-run] [--no-install] [--json]
|
|
21
|
-
aipay init --create <app name> [--api <base>] ... create the app (needs login) and link it
|
|
22
|
-
aipay test [--model <id>] [--port <n>] [--no-open] [--timeout <seconds>] [--dir <path>] [--json]
|
|
23
|
-
aipay doctor [--offline] [--dir <path>] [--json]
|
|
24
|
-
aipay status [--dir <path>] [--json]
|
|
25
|
-
aipay unlink [--dry-run] [--dir <path>] [--json]
|
|
26
|
-
|
|
27
|
-
login sign in as a developer (loopback PKCE, audience aipay-developer-api); tokens go to the
|
|
28
|
-
OS keychain or a 0600 file — never into the project
|
|
29
|
-
apps list your apps / create one (Idempotency-Key: a retried create never makes a second app)
|
|
30
|
-
init link this project to an app: .aipay/project.json, .env.local, .gitignore,
|
|
31
|
-
a callback route for your framework, aipay-agent.md, and the SDK install
|
|
32
|
-
(--auth/--api are optional once you are signed in; --create makes the app first)
|
|
33
|
-
test real sign-in via a loopback callback (any free port on 127.0.0.1) + one chat completion → receipt
|
|
34
|
-
doctor check the link, files, SDK, and that AI-Pay is reachable
|
|
35
|
-
status what this directory is linked to
|
|
36
|
-
unlink forget the link (keeps your code)
|
|
37
|
-
|
|
38
|
-
Exit codes: 0 ok · 1 problem you can fix · 2 usage · 3 network/auth
|
|
39
|
-
Pilot gate: export AIPAY_GATE_TOKEN=<token from the Console>; never write it to files.
|
|
40
|
-
`;
|
|
41
|
-
export async function main(argv, io) {
|
|
42
|
-
const args = parseArgs(argv);
|
|
43
|
-
const json = flagBool(args.flags, 'json');
|
|
44
|
-
const out = createReporter({ json, ...(io ?? {}) });
|
|
45
|
-
if (args.flags.version || args.command === 'version') {
|
|
46
|
-
;
|
|
47
|
-
(io?.stdout ?? ((s) => process.stdout.write(`${s}\n`)))(json ? JSON.stringify({ version: cliVersion() }) : cliVersion());
|
|
48
|
-
return EXIT.ok;
|
|
49
|
-
}
|
|
50
|
-
if (!args.command || args.flags.help || args.command === 'help') {
|
|
51
|
-
;
|
|
52
|
-
(io?.stdout ?? ((s) => process.stdout.write(`${s}\n`)))(HELP);
|
|
53
|
-
return args.command || args.flags.help ? EXIT.ok : EXIT.usage;
|
|
54
|
-
}
|
|
55
|
-
try {
|
|
56
|
-
switch (args.command) {
|
|
57
|
-
case 'login':
|
|
58
|
-
return await runLogin(args, out);
|
|
59
|
-
case 'logout':
|
|
60
|
-
return await runLogout(args, out);
|
|
61
|
-
case 'whoami':
|
|
62
|
-
return await runWhoami(args, out);
|
|
63
|
-
case 'apps':
|
|
64
|
-
return await runApps(args, out);
|
|
65
|
-
case 'init':
|
|
66
|
-
return await runInit(args, out);
|
|
67
|
-
case 'test':
|
|
68
|
-
return await runTest(args, out);
|
|
69
|
-
case 'doctor':
|
|
70
|
-
return await runDoctor(args, out);
|
|
71
|
-
case 'status':
|
|
72
|
-
return runStatus(args, out);
|
|
73
|
-
case 'unlink':
|
|
74
|
-
return runUnlink(args, out);
|
|
75
|
-
default:
|
|
76
|
-
throw new CliError('usage', `unknown command "${args.command}" (see \`aipay help\`)`, EXIT.usage);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
catch (e) {
|
|
80
|
-
if (e instanceof CliError) {
|
|
81
|
-
out.line('bad', e.message);
|
|
82
|
-
out.result({ ok: false, error: { code: e.code, message: e.message } });
|
|
83
|
-
return e.exitCode;
|
|
84
|
-
}
|
|
85
|
-
const msg = e instanceof Error ? e.message : String(e);
|
|
86
|
-
out.line('bad', msg);
|
|
87
|
-
out.result({ ok: false, error: { code: 'unexpected', message: msg } });
|
|
88
|
-
return EXIT.problem;
|
|
89
|
-
}
|
|
90
|
-
}
|
package/dist/output.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Output channel: human-readable lines on stderr-ish stdout, or one JSON document when
|
|
3
|
-
* `--json` is set (agents parse it; humans read the other one). Both go to stdout so
|
|
4
|
-
* `aipay status --json | jq` works; diagnostics that must never pollute JSON go to stderr.
|
|
5
|
-
*/
|
|
6
|
-
export type Level = 'ok' | 'warn' | 'bad' | 'info';
|
|
7
|
-
export interface Reporter {
|
|
8
|
-
readonly json: boolean;
|
|
9
|
-
line(level: Level, text: string): void;
|
|
10
|
-
kv(label: string, value: string): void;
|
|
11
|
-
blank(): void;
|
|
12
|
-
/** Final structured result — printed as JSON in --json mode, ignored otherwise. */
|
|
13
|
-
result(doc: Record<string, unknown>): void;
|
|
14
|
-
/** Debug/diagnostic text — always stderr, never in JSON. */
|
|
15
|
-
debug(text: string): void;
|
|
16
|
-
}
|
|
17
|
-
export declare function createReporter(opts: {
|
|
18
|
-
json: boolean;
|
|
19
|
-
stdout?: (s: string) => void;
|
|
20
|
-
stderr?: (s: string) => void;
|
|
21
|
-
}): Reporter;
|
|
22
|
-
/** Exit codes are part of the contract (agents branch on them). */
|
|
23
|
-
export declare const EXIT: {
|
|
24
|
-
readonly ok: 0;
|
|
25
|
-
/** Something in the project/config is wrong and the user can fix it. */
|
|
26
|
-
readonly problem: 1;
|
|
27
|
-
/** Bad invocation (unknown command/flag, missing required flag). */
|
|
28
|
-
readonly usage: 2;
|
|
29
|
-
/** Network/auth failure talking to AI-Pay. */
|
|
30
|
-
readonly remote: 3;
|
|
31
|
-
};
|
|
32
|
-
export declare class CliError extends Error {
|
|
33
|
-
readonly exitCode: number;
|
|
34
|
-
readonly code: string;
|
|
35
|
-
constructor(code: string, message: string, exitCode?: number);
|
|
36
|
-
}
|
package/dist/output.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
const GLYPH = { ok: '✔', warn: '⚠', bad: '✘', info: '·' };
|
|
2
|
-
export function createReporter(opts) {
|
|
3
|
-
const stdout = opts.stdout ?? ((s) => process.stdout.write(`${s}\n`));
|
|
4
|
-
const stderr = opts.stderr ?? ((s) => process.stderr.write(`${s}\n`));
|
|
5
|
-
const json = opts.json;
|
|
6
|
-
return {
|
|
7
|
-
json,
|
|
8
|
-
line(level, text) {
|
|
9
|
-
if (json)
|
|
10
|
-
return;
|
|
11
|
-
stdout(`${GLYPH[level]} ${text}`);
|
|
12
|
-
},
|
|
13
|
-
kv(label, value) {
|
|
14
|
-
if (json)
|
|
15
|
-
return;
|
|
16
|
-
stdout(` ${label.padEnd(14)} ${value}`);
|
|
17
|
-
},
|
|
18
|
-
blank() {
|
|
19
|
-
if (json)
|
|
20
|
-
return;
|
|
21
|
-
stdout('');
|
|
22
|
-
},
|
|
23
|
-
result(doc) {
|
|
24
|
-
if (!json)
|
|
25
|
-
return;
|
|
26
|
-
stdout(JSON.stringify(doc, null, 2));
|
|
27
|
-
},
|
|
28
|
-
debug(text) {
|
|
29
|
-
stderr(text);
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
/** Exit codes are part of the contract (agents branch on them). */
|
|
34
|
-
export const EXIT = {
|
|
35
|
-
ok: 0,
|
|
36
|
-
/** Something in the project/config is wrong and the user can fix it. */
|
|
37
|
-
problem: 1,
|
|
38
|
-
/** Bad invocation (unknown command/flag, missing required flag). */
|
|
39
|
-
usage: 2,
|
|
40
|
-
/** Network/auth failure talking to AI-Pay. */
|
|
41
|
-
remote: 3,
|
|
42
|
-
};
|
|
43
|
-
export class CliError extends Error {
|
|
44
|
-
exitCode;
|
|
45
|
-
code;
|
|
46
|
-
constructor(code, message, exitCode = EXIT.problem) {
|
|
47
|
-
super(message);
|
|
48
|
-
this.name = 'CliError';
|
|
49
|
-
this.code = code;
|
|
50
|
-
this.exitCode = exitCode;
|
|
51
|
-
}
|
|
52
|
-
}
|
package/dist/project.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
export interface ProjectConfig {
|
|
2
|
-
/** Schema version of this file. */
|
|
3
|
-
version: 1;
|
|
4
|
-
app: {
|
|
5
|
-
client_id: string;
|
|
6
|
-
name: string | null;
|
|
7
|
-
};
|
|
8
|
-
/** Authorization server origin (Hydra public), e.g. https://auth.ai-pay.example */
|
|
9
|
-
auth_origin: string;
|
|
10
|
-
/** API base for the SDK client, e.g. https://api.ai-pay.example */
|
|
11
|
-
api_base: string;
|
|
12
|
-
/** Registered loopback callback the CLI and the sample route use. */
|
|
13
|
-
callback: string;
|
|
14
|
-
/** What `aipay init` detected/scaffolded, for `doctor`/`status` and for humans. */
|
|
15
|
-
scaffold: {
|
|
16
|
-
package_manager: 'pnpm' | 'npm' | 'yarn' | 'bun' | null;
|
|
17
|
-
framework: Framework | null;
|
|
18
|
-
files: string[];
|
|
19
|
-
};
|
|
20
|
-
linked_at: string;
|
|
21
|
-
}
|
|
22
|
-
export type Framework = 'next' | 'express' | 'fastify' | 'hono' | 'node';
|
|
23
|
-
export declare const PROJECT_DIR = ".aipay";
|
|
24
|
-
export declare const PROJECT_FILE = "project.json";
|
|
25
|
-
export declare const ENV_FILE = ".env.local";
|
|
26
|
-
export declare function projectPath(dir: string): string;
|
|
27
|
-
export declare function readProject(dir: string): ProjectConfig | null;
|
|
28
|
-
export declare function writeProject(dir: string, cfg: ProjectConfig): string;
|
|
29
|
-
export declare function isProjectConfig(v: unknown): v is ProjectConfig;
|
|
30
|
-
/** Env var names the SDK samples and the scaffolded route read. Public values only. */
|
|
31
|
-
export declare const ENV_KEYS: {
|
|
32
|
-
readonly clientId: 'AIPAY_CLIENT_ID';
|
|
33
|
-
readonly authOrigin: 'AIPAY_AUTH_ORIGIN';
|
|
34
|
-
readonly apiBase: 'AIPAY_API_BASE';
|
|
35
|
-
readonly callback: 'AIPAY_CALLBACK_URL';
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Merge our keys into `.env.local` without touching anything else in it: existing lines
|
|
39
|
-
* for our keys are replaced in place, missing ones appended under a marker comment.
|
|
40
|
-
* Returns the keys that actually changed (so `--dry-run` and `status` can report).
|
|
41
|
-
*/
|
|
42
|
-
export declare function mergeEnvFile(existing: string | null, values: Record<string, string>): {
|
|
43
|
-
content: string;
|
|
44
|
-
changed: string[];
|
|
45
|
-
};
|
|
46
|
-
/** Append missing ignore entries; never reorder or remove anything. */
|
|
47
|
-
export declare function mergeGitignore(existing: string | null, entries: string[]): {
|
|
48
|
-
content: string;
|
|
49
|
-
added: string[];
|
|
50
|
-
};
|
package/dist/project.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Local artifacts (consultant report §6.5):
|
|
3
|
-
* .aipay/project.json — committable: which app this project is linked to (no secrets)
|
|
4
|
-
* .env.local — NOT committed: only public values today (client_id, URLs); the
|
|
5
|
-
* gate token is read from the environment and never written
|
|
6
|
-
* .gitignore — gets `.env.local` and `.aipay/local/` appended once
|
|
7
|
-
*
|
|
8
|
-
* Tokens live only in memory for the duration of `aipay test`. Nothing here writes them.
|
|
9
|
-
*/
|
|
10
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
11
|
-
import { join } from 'node:path';
|
|
12
|
-
export const PROJECT_DIR = '.aipay';
|
|
13
|
-
export const PROJECT_FILE = 'project.json';
|
|
14
|
-
export const ENV_FILE = '.env.local';
|
|
15
|
-
export function projectPath(dir) {
|
|
16
|
-
return join(dir, PROJECT_DIR, PROJECT_FILE);
|
|
17
|
-
}
|
|
18
|
-
export function readProject(dir) {
|
|
19
|
-
const p = projectPath(dir);
|
|
20
|
-
if (!existsSync(p))
|
|
21
|
-
return null;
|
|
22
|
-
const raw = readFileSync(p, 'utf8');
|
|
23
|
-
const parsed = JSON.parse(raw);
|
|
24
|
-
if (!isProjectConfig(parsed))
|
|
25
|
-
throw new Error(`${p} is not a valid AI-Pay project file`);
|
|
26
|
-
return parsed;
|
|
27
|
-
}
|
|
28
|
-
export function writeProject(dir, cfg) {
|
|
29
|
-
mkdirSync(join(dir, PROJECT_DIR), { recursive: true });
|
|
30
|
-
const p = projectPath(dir);
|
|
31
|
-
writeFileSync(p, `${JSON.stringify(cfg, null, 2)}\n`);
|
|
32
|
-
return p;
|
|
33
|
-
}
|
|
34
|
-
export function isProjectConfig(v) {
|
|
35
|
-
if (!v || typeof v !== 'object')
|
|
36
|
-
return false;
|
|
37
|
-
const o = v;
|
|
38
|
-
const app = o.app;
|
|
39
|
-
return (o.version === 1 &&
|
|
40
|
-
!!app &&
|
|
41
|
-
typeof app.client_id === 'string' &&
|
|
42
|
-
typeof o.auth_origin === 'string' &&
|
|
43
|
-
typeof o.api_base === 'string' &&
|
|
44
|
-
typeof o.callback === 'string');
|
|
45
|
-
}
|
|
46
|
-
/** Env var names the SDK samples and the scaffolded route read. Public values only. */
|
|
47
|
-
export const ENV_KEYS = {
|
|
48
|
-
clientId: 'AIPAY_CLIENT_ID',
|
|
49
|
-
authOrigin: 'AIPAY_AUTH_ORIGIN',
|
|
50
|
-
apiBase: 'AIPAY_API_BASE',
|
|
51
|
-
callback: 'AIPAY_CALLBACK_URL',
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Merge our keys into `.env.local` without touching anything else in it: existing lines
|
|
55
|
-
* for our keys are replaced in place, missing ones appended under a marker comment.
|
|
56
|
-
* Returns the keys that actually changed (so `--dry-run` and `status` can report).
|
|
57
|
-
*/
|
|
58
|
-
export function mergeEnvFile(existing, values) {
|
|
59
|
-
const lines = existing ? existing.split(/\r?\n/) : [];
|
|
60
|
-
if (lines.length && lines[lines.length - 1] === '')
|
|
61
|
-
lines.pop();
|
|
62
|
-
const changed = [];
|
|
63
|
-
const seen = new Set();
|
|
64
|
-
const out = lines.map((line) => {
|
|
65
|
-
const m = /^\s*(?:export\s+)?([A-Z0-9_]+)\s*=(.*)$/.exec(line);
|
|
66
|
-
if (!m)
|
|
67
|
-
return line;
|
|
68
|
-
const key = m[1];
|
|
69
|
-
if (!(key in values))
|
|
70
|
-
return line;
|
|
71
|
-
seen.add(key);
|
|
72
|
-
const want = values[key];
|
|
73
|
-
if (unquote(m[2] ?? '') === want)
|
|
74
|
-
return line;
|
|
75
|
-
changed.push(key);
|
|
76
|
-
return `${key}=${want}`;
|
|
77
|
-
});
|
|
78
|
-
const missing = Object.keys(values).filter((k) => !seen.has(k));
|
|
79
|
-
if (missing.length) {
|
|
80
|
-
if (out.length)
|
|
81
|
-
out.push('');
|
|
82
|
-
out.push('# AI-Pay (written by `aipay init`; public values, safe to keep local)');
|
|
83
|
-
for (const k of missing) {
|
|
84
|
-
out.push(`${k}=${values[k]}`);
|
|
85
|
-
changed.push(k);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return { content: `${out.join('\n')}\n`, changed };
|
|
89
|
-
}
|
|
90
|
-
function unquote(s) {
|
|
91
|
-
const t = s.trim();
|
|
92
|
-
if (t.length >= 2 &&
|
|
93
|
-
((t.startsWith('"') && t.endsWith('"')) || (t.startsWith("'") && t.endsWith("'"))))
|
|
94
|
-
return t.slice(1, -1);
|
|
95
|
-
return t;
|
|
96
|
-
}
|
|
97
|
-
/** Append missing ignore entries; never reorder or remove anything. */
|
|
98
|
-
export function mergeGitignore(existing, entries) {
|
|
99
|
-
const lines = existing ? existing.split(/\r?\n/) : [];
|
|
100
|
-
const have = new Set(lines.map((l) => l.trim()));
|
|
101
|
-
const added = entries.filter((e) => !have.has(e));
|
|
102
|
-
if (!added.length)
|
|
103
|
-
return { content: existing ?? '', added };
|
|
104
|
-
const base = existing ? (existing.endsWith('\n') ? existing : `${existing}\n`) : '';
|
|
105
|
-
const block = `${base}${base ? '\n' : ''}# AI-Pay local files (never commit)\n${added.join('\n')}\n`;
|
|
106
|
-
return { content: block, added };
|
|
107
|
-
}
|
package/dist/remote.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Everything that talks to AI-Pay over the network, in one place so the commands stay
|
|
3
|
-
* readable and tests can stub it. Gate header via the environment (see gate.ts).
|
|
4
|
-
*/
|
|
5
|
-
import { GATE_HINT } from './gate.js';
|
|
6
|
-
export interface Remote {
|
|
7
|
-
fetchDocs(apiBase: string, locale?: 'en' | 'zh-Hant'): Promise<{
|
|
8
|
-
markdown: string | null;
|
|
9
|
-
gated: boolean;
|
|
10
|
-
status: number;
|
|
11
|
-
}>;
|
|
12
|
-
probe(url: string): Promise<{
|
|
13
|
-
ok: boolean;
|
|
14
|
-
status: number;
|
|
15
|
-
gated: boolean;
|
|
16
|
-
error?: string;
|
|
17
|
-
}>;
|
|
18
|
-
}
|
|
19
|
-
export declare function createRemote(env?: NodeJS.ProcessEnv): Remote;
|
|
20
|
-
export declare function docsUrl(apiBase: string, locale?: 'en' | 'zh-Hant'): string;
|
|
21
|
-
export { GATE_HINT };
|
package/dist/remote.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Everything that talks to AI-Pay over the network, in one place so the commands stay
|
|
3
|
-
* readable and tests can stub it. Gate header via the environment (see gate.ts).
|
|
4
|
-
*/
|
|
5
|
-
import { GATE_HINT, gatedFetch, looksGated } from './gate.js';
|
|
6
|
-
import { CliError, EXIT } from './output.js';
|
|
7
|
-
export function createRemote(env = process.env) {
|
|
8
|
-
const f = gatedFetch(env);
|
|
9
|
-
return {
|
|
10
|
-
async fetchDocs(apiBase, locale = 'en') {
|
|
11
|
-
const url = docsUrl(apiBase, locale);
|
|
12
|
-
let res;
|
|
13
|
-
try {
|
|
14
|
-
res = await f(url, { headers: { accept: 'text/markdown, text/plain' } });
|
|
15
|
-
}
|
|
16
|
-
catch (e) {
|
|
17
|
-
throw new CliError('network', `cannot reach ${url}: ${e.message}`, EXIT.remote);
|
|
18
|
-
}
|
|
19
|
-
const text = await res.text();
|
|
20
|
-
if (res.ok)
|
|
21
|
-
return { markdown: text, gated: false, status: res.status };
|
|
22
|
-
return { markdown: null, gated: looksGated(res.status, text), status: res.status };
|
|
23
|
-
},
|
|
24
|
-
async probe(url) {
|
|
25
|
-
try {
|
|
26
|
-
const res = await f(url, { method: 'GET', redirect: 'manual' });
|
|
27
|
-
const text = await res.text();
|
|
28
|
-
return { ok: res.ok, status: res.status, gated: looksGated(res.status, text) };
|
|
29
|
-
}
|
|
30
|
-
catch (e) {
|
|
31
|
-
return { ok: false, status: 0, gated: false, error: e.message };
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
export function docsUrl(apiBase, locale = 'en') {
|
|
37
|
-
const u = new URL('/docs.md', apiBase);
|
|
38
|
-
u.searchParams.set('lang', locale);
|
|
39
|
-
return u.toString();
|
|
40
|
-
}
|
|
41
|
-
export { GATE_HINT };
|
package/dist/setup-events.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { Reporter } from './output.js';
|
|
2
|
-
export type SetupEventKind = 'cli.init' | 'cli.test' | 'cli.doctor';
|
|
3
|
-
export declare function reportSetupEvent(appId: string, kind: SetupEventKind, detail: Record<string, string | number | boolean | string[]>, out: Reporter, env?: NodeJS.ProcessEnv): Promise<boolean>;
|
package/dist/setup-events.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Setup-session events (consultant §6.3): after `init` / `test` the CLI tells the Console
|
|
3
|
-
* what happened so the "waiting for the tool" line turns into "the CLI finished init".
|
|
4
|
-
* Best effort and strictly opt-in by state: only when the developer is signed in with the
|
|
5
|
-
* CLI (`aipay login`); never blocks the command, never sends tokens or file contents.
|
|
6
|
-
*/
|
|
7
|
-
import { createAuthStore } from './auth-store.js';
|
|
8
|
-
import { openDeveloperApi } from './developer-api.js';
|
|
9
|
-
export async function reportSetupEvent(appId, kind, detail, out, env = process.env) {
|
|
10
|
-
const store = createAuthStore(env);
|
|
11
|
-
if (!store.load())
|
|
12
|
-
return false; // not signed in with the CLI → the Console still sees server facts
|
|
13
|
-
try {
|
|
14
|
-
const api = await openDeveloperApi(store, env);
|
|
15
|
-
const res = await api.request('POST', `/v1/developer/apps/${encodeURIComponent(appId)}/setup-events`, {
|
|
16
|
-
body: { kind, detail },
|
|
17
|
-
});
|
|
18
|
-
if (res.status === 201) {
|
|
19
|
-
out.line('info', `reported ${kind} to the Console`);
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
out.debug(`setup event ${kind} not recorded (HTTP ${res.status})`);
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
out.debug(`setup event ${kind} skipped: ${e.message}`);
|
|
26
|
-
}
|
|
27
|
-
return false;
|
|
28
|
-
}
|
package/dist/templates.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Scaffold templates: one `aipay` helper module (sign-in flow + first completion) and a
|
|
3
|
-
* thin wiring file per framework. Authored twice (TypeScript / JavaScript) so nothing is
|
|
4
|
-
* generated by stripping types. The callback path is the one registered in the Console
|
|
5
|
-
* for the app (default /auth/aipay/callback); the start path sits next to it.
|
|
6
|
-
*
|
|
7
|
-
* Sessions are the developer's business — the template keeps pending flows and signed-in
|
|
8
|
-
* users in memory with a loud comment, which is correct for a dev server and obviously
|
|
9
|
-
* wrong for production.
|
|
10
|
-
*/
|
|
11
|
-
import type { Framework } from './project.js';
|
|
12
|
-
export interface TemplateFile {
|
|
13
|
-
/** Path relative to the project root. */
|
|
14
|
-
path: string;
|
|
15
|
-
content: string;
|
|
16
|
-
}
|
|
17
|
-
export interface TemplateInput {
|
|
18
|
-
framework: Framework;
|
|
19
|
-
typescript: boolean;
|
|
20
|
-
srcDir: string;
|
|
21
|
-
callbackPath: string;
|
|
22
|
-
}
|
|
23
|
-
export declare function startPathFor(callbackPath: string): string;
|
|
24
|
-
export declare function scaffoldFiles(input: TemplateInput): TemplateFile[];
|