poe-code 2.0.57 → 2.0.58
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 +41 -0
- package/dist/cli/commands/spawn.js +10 -27
- package/dist/cli/commands/spawn.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/sdk/container.d.ts +18 -0
- package/dist/sdk/container.js +127 -0
- package/dist/sdk/container.js.map +1 -0
- package/dist/sdk/credentials.d.ts +9 -0
- package/dist/sdk/credentials.js +35 -0
- package/dist/sdk/credentials.js.map +1 -0
- package/dist/sdk/spawn-core.d.ts +23 -0
- package/dist/sdk/spawn-core.js +81 -0
- package/dist/sdk/spawn-core.js.map +1 -0
- package/dist/sdk/spawn.d.ts +23 -0
- package/dist/sdk/spawn.js +41 -0
- package/dist/sdk/spawn.js.map +1 -0
- package/dist/sdk/types.d.ts +24 -0
- package/dist/sdk/types.js +2 -0
- package/dist/sdk/types.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -80,3 +80,44 @@ npx poe-code@latest install kimi
|
|
|
80
80
|
|
|
81
81
|
- `--dry-run` – show every mutation without touching disk.
|
|
82
82
|
- `--yes` – accept defaults for prompts.
|
|
83
|
+
|
|
84
|
+
## SDK
|
|
85
|
+
|
|
86
|
+
Use `poe-code` programmatically in your own code:
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { spawn, getPoeApiKey } from "poe-code"
|
|
90
|
+
|
|
91
|
+
// Get stored API key
|
|
92
|
+
const apiKey = await getPoeApiKey()
|
|
93
|
+
|
|
94
|
+
// Run a prompt through a provider
|
|
95
|
+
const result = await spawn("claude-code", {
|
|
96
|
+
prompt: "Fix the bug in auth.ts",
|
|
97
|
+
cwd: "/path/to/project",
|
|
98
|
+
model: "claude-sonnet-4"
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
console.log(result.stdout)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### `spawn(service, options)`
|
|
105
|
+
|
|
106
|
+
Runs a single prompt through a configured service CLI.
|
|
107
|
+
|
|
108
|
+
- `service` – Service identifier (`claude-code`, `codex`, `opencode`)
|
|
109
|
+
- `options.prompt` – The prompt to send
|
|
110
|
+
- `options.cwd` – Working directory for the service CLI (optional)
|
|
111
|
+
- `options.model` – Model identifier override (optional)
|
|
112
|
+
- `options.args` – Additional arguments forwarded to the CLI (optional)
|
|
113
|
+
|
|
114
|
+
Returns `{ stdout, stderr, exitCode }`.
|
|
115
|
+
|
|
116
|
+
### `getPoeApiKey()`
|
|
117
|
+
|
|
118
|
+
Reads the Poe API key with the following priority:
|
|
119
|
+
|
|
120
|
+
1. `POE_API_KEY` environment variable
|
|
121
|
+
2. Credentials file (`~/.poe-code/credentials.json`)
|
|
122
|
+
|
|
123
|
+
Throws if no credentials found.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import {
|
|
2
|
+
import { createExecutionResources, resolveCommandFlags, resolveServiceAdapter } from "./shared.js";
|
|
3
|
+
import { spawnCore } from "../../sdk/spawn-core.js";
|
|
3
4
|
export function registerSpawnCommand(program, container, options = {}) {
|
|
4
5
|
const defaultServices = ["claude-code", "codex", "opencode"];
|
|
5
6
|
const serviceList = options.extraServices && options.extraServices.length > 0
|
|
@@ -50,6 +51,7 @@ export function registerSpawnCommand(program, container, options = {}) {
|
|
|
50
51
|
cwd: cwdOverride,
|
|
51
52
|
useStdin: shouldReadFromStdin
|
|
52
53
|
};
|
|
54
|
+
// Check for custom handlers first
|
|
53
55
|
const directHandler = options.handlers?.[service];
|
|
54
56
|
if (directHandler) {
|
|
55
57
|
await directHandler({
|
|
@@ -74,35 +76,16 @@ export function registerSpawnCommand(program, container, options = {}) {
|
|
|
74
76
|
});
|
|
75
77
|
return;
|
|
76
78
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const providerContext = buildProviderContext(container, adapter, resources);
|
|
79
|
+
// Use SDK core spawn implementation
|
|
80
|
+
const result = await spawnCore(container, service, spawnOptions, {
|
|
81
|
+
dryRun: flags.dryRun,
|
|
82
|
+
verbose: flags.verbose
|
|
83
|
+
});
|
|
84
|
+
// Handle dry run - spawnCore already logged the message
|
|
84
85
|
if (flags.dryRun) {
|
|
85
|
-
const extra = spawnOptions.args && spawnOptions.args.length > 0
|
|
86
|
-
? ` with args ${JSON.stringify(spawnOptions.args)}`
|
|
87
|
-
: "";
|
|
88
|
-
const cwdSuffix = spawnOptions.cwd ? ` from ${spawnOptions.cwd}` : "";
|
|
89
|
-
const promptDetail = spawnOptions.useStdin
|
|
90
|
-
? `(stdin, ${spawnOptions.prompt.length} chars)`
|
|
91
|
-
: `"${spawnOptions.prompt}"`;
|
|
92
|
-
resources.logger.dryRun(`Dry run: would spawn ${adapter.label} with prompt ${promptDetail}${extra}${cwdSuffix}.`);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
const result = (await container.registry.invoke(canonicalService, "spawn", async (entry) => {
|
|
96
|
-
if (!entry.spawn) {
|
|
97
|
-
throw new Error(`${adapter.label} does not support spawn.`);
|
|
98
|
-
}
|
|
99
|
-
const output = await entry.spawn(providerContext, spawnOptions);
|
|
100
|
-
return output;
|
|
101
|
-
}));
|
|
102
|
-
if (!result) {
|
|
103
|
-
resources.logger.info(`${adapter.label} spawn completed.`);
|
|
104
86
|
return;
|
|
105
87
|
}
|
|
88
|
+
// Handle result output
|
|
106
89
|
if (result.exitCode !== 0) {
|
|
107
90
|
const detail = result.stderr.trim() || result.stdout.trim();
|
|
108
91
|
const suffix = detail ? `: ${detail}` : "";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spawn.js","sourceRoot":"","sources":["../../../src/cli/commands/spawn.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,EACL,
|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M,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAC3C,MAAM,IAAI,KAAK,CACb,GAAG,OAAO,CAAC,KAAK,gCAAgC,MAAM,CAAC,QAAQ,GAAG,MAAM,EAAE,CAC3E,CAAC;QACJ,CAAC;QAED,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QAC3C,IAAI,aAAa,EAAE,CAAC;YAClB,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YACrC,OAAO;QACT,CAAC;QAED,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QAC3C,IAAI,aAAa,EAAE,CAAC;YAClB,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YACrC,OAAO;QACT,CAAC;QAED,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,mBAAmB,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;AACP,CAAC;AAED,SAAS,4BAA4B,CACnC,OAAe,EACf,SAAkB;IAElB,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChD,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC/B,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AAC1C,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { isCliInvocation } from "./cli/bootstrap.js";
|
|
3
|
+
export { spawn } from "./sdk/spawn.js";
|
|
4
|
+
export { getPoeApiKey } from "./sdk/credentials.js";
|
|
5
|
+
export type { SpawnOptions, SpawnResult } from "./sdk/types.js";
|
|
3
6
|
declare const main: () => Promise<void>;
|
|
4
7
|
export { main, isCliInvocation };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createProgram } from "./cli/program.js";
|
|
3
3
|
import { createCliMain, isCliInvocation } from "./cli/bootstrap.js";
|
|
4
|
+
// SDK exports
|
|
5
|
+
export { spawn } from "./sdk/spawn.js";
|
|
6
|
+
export { getPoeApiKey } from "./sdk/credentials.js";
|
|
4
7
|
const main = createCliMain(createProgram);
|
|
5
8
|
if (isCliInvocation(process.argv, import.meta.url)) {
|
|
6
9
|
void main();
|
|
7
10
|
}
|
|
11
|
+
// CLI exports
|
|
8
12
|
export { main, isCliInvocation };
|
|
9
13
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEpE,MAAM,IAAI,GAAG,aAAa,CAAC,aAAa,CAAC,CAAC;AAE1C,IAAI,eAAe,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACnD,KAAK,IAAI,EAAE,CAAC;AACd,CAAC;AAED,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAEpE,cAAc;AACd,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,MAAM,IAAI,GAAG,aAAa,CAAC,aAAa,CAAC,CAAC;AAE1C,IAAI,eAAe,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACnD,KAAK,IAAI,EAAE,CAAC;AACd,CAAC;AAED,cAAc;AACd,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CliContainer } from "../cli/container.js";
|
|
2
|
+
export interface SdkContainerOptions {
|
|
3
|
+
/** Working directory (defaults to process.cwd()) */
|
|
4
|
+
cwd?: string;
|
|
5
|
+
/** Home directory (defaults to os.homedir()) */
|
|
6
|
+
homeDir?: string;
|
|
7
|
+
/** Environment variables (defaults to process.env) */
|
|
8
|
+
variables?: Record<string, string | undefined>;
|
|
9
|
+
/** Enable verbose logging (defaults to false) */
|
|
10
|
+
verbose?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates a lightweight container for SDK usage.
|
|
14
|
+
* Uses real file system and command runner.
|
|
15
|
+
* No prompts needed (non-interactive).
|
|
16
|
+
* Minimal logger (silent by default).
|
|
17
|
+
*/
|
|
18
|
+
export declare function createSdkContainer(options?: SdkContainerOptions): CliContainer;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import * as fs from "node:fs/promises";
|
|
2
|
+
import * as os from "node:os";
|
|
3
|
+
import { createCliEnvironment } from "../cli/environment.js";
|
|
4
|
+
import { createServiceRegistry } from "../cli/service-registry.js";
|
|
5
|
+
import { createCommandContextFactory } from "../cli/context.js";
|
|
6
|
+
import { createPromptLibrary } from "../cli/prompts.js";
|
|
7
|
+
import { createOptionResolvers } from "../cli/options.js";
|
|
8
|
+
import { createLoggerFactory } from "../cli/logger.js";
|
|
9
|
+
import { ErrorLogger } from "../cli/error-logger.js";
|
|
10
|
+
import { createDefaultCommandRunner } from "../cli/command-runner.js";
|
|
11
|
+
import { getDefaultProviders } from "../providers/index.js";
|
|
12
|
+
import { createPoeCodeCommandRunner } from "../cli/poe-code-command-runner.js";
|
|
13
|
+
import { loadCredentials, saveCredentials } from "../services/credentials.js";
|
|
14
|
+
import * as nodeFsSync from "node:fs";
|
|
15
|
+
/**
|
|
16
|
+
* Creates a lightweight container for SDK usage.
|
|
17
|
+
* Uses real file system and command runner.
|
|
18
|
+
* No prompts needed (non-interactive).
|
|
19
|
+
* Minimal logger (silent by default).
|
|
20
|
+
*/
|
|
21
|
+
export function createSdkContainer(options) {
|
|
22
|
+
const cwd = options?.cwd ?? process.cwd();
|
|
23
|
+
const homeDir = options?.homeDir ?? os.homedir();
|
|
24
|
+
const variables = options?.variables ?? process.env;
|
|
25
|
+
const verbose = options?.verbose ?? false;
|
|
26
|
+
const environment = createCliEnvironment({
|
|
27
|
+
cwd,
|
|
28
|
+
homeDir,
|
|
29
|
+
platform: process.platform,
|
|
30
|
+
variables
|
|
31
|
+
});
|
|
32
|
+
// Silent logger for SDK - only emits if verbose
|
|
33
|
+
const silentEmitter = verbose ? undefined : () => { };
|
|
34
|
+
const loggerFactory = createLoggerFactory(silentEmitter);
|
|
35
|
+
// Create error logger with sync fs
|
|
36
|
+
const errorLogger = new ErrorLogger({
|
|
37
|
+
fs: nodeFsSync,
|
|
38
|
+
logDir: environment.logDir,
|
|
39
|
+
logToStderr: false
|
|
40
|
+
});
|
|
41
|
+
loggerFactory.setErrorLogger(errorLogger);
|
|
42
|
+
// Create async file system adapter
|
|
43
|
+
const asyncFs = {
|
|
44
|
+
readFile: ((path, encoding) => {
|
|
45
|
+
if (encoding) {
|
|
46
|
+
return fs.readFile(path, encoding);
|
|
47
|
+
}
|
|
48
|
+
return fs.readFile(path);
|
|
49
|
+
}),
|
|
50
|
+
writeFile: (path, data, opts) => fs.writeFile(path, data, opts),
|
|
51
|
+
mkdir: (path, opts) => fs.mkdir(path, opts).then(() => { }),
|
|
52
|
+
stat: (path) => fs.stat(path),
|
|
53
|
+
rm: (path, opts) => fs.rm(path, opts),
|
|
54
|
+
unlink: (path) => fs.unlink(path),
|
|
55
|
+
readdir: (path) => fs.readdir(path),
|
|
56
|
+
copyFile: (src, dest) => fs.copyFile(src, dest),
|
|
57
|
+
chmod: (path, mode) => fs.chmod(path, mode)
|
|
58
|
+
};
|
|
59
|
+
const contextFactory = createCommandContextFactory({ fs: asyncFs });
|
|
60
|
+
// No-op prompts for SDK (non-interactive)
|
|
61
|
+
const noopPrompts = async () => {
|
|
62
|
+
throw new Error("SDK does not support interactive prompts");
|
|
63
|
+
};
|
|
64
|
+
const promptLibrary = createPromptLibrary();
|
|
65
|
+
const optionResolvers = createOptionResolvers({
|
|
66
|
+
prompts: noopPrompts,
|
|
67
|
+
promptLibrary,
|
|
68
|
+
apiKeyStore: {
|
|
69
|
+
read: () => loadCredentials({
|
|
70
|
+
fs: asyncFs,
|
|
71
|
+
filePath: environment.credentialsPath
|
|
72
|
+
}),
|
|
73
|
+
write: (value) => saveCredentials({
|
|
74
|
+
fs: asyncFs,
|
|
75
|
+
filePath: environment.credentialsPath,
|
|
76
|
+
apiKey: value
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
const registry = createServiceRegistry();
|
|
81
|
+
const providers = getDefaultProviders().filter((adapter) => !adapter.disabled);
|
|
82
|
+
for (const adapter of providers) {
|
|
83
|
+
registry.register(adapter);
|
|
84
|
+
}
|
|
85
|
+
const baseRunner = createDefaultCommandRunner();
|
|
86
|
+
// Create container with wrapped runner
|
|
87
|
+
let container = null;
|
|
88
|
+
const wrappedRunner = createPoeCodeCommandRunner({
|
|
89
|
+
getContainer: () => container,
|
|
90
|
+
baseRunner
|
|
91
|
+
});
|
|
92
|
+
// HTTP client using global fetch
|
|
93
|
+
const httpClient = async (url, init) => {
|
|
94
|
+
const response = await globalThis.fetch(url, init);
|
|
95
|
+
return {
|
|
96
|
+
ok: response.ok,
|
|
97
|
+
status: response.status,
|
|
98
|
+
json: () => response.json()
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
container = {
|
|
102
|
+
env: environment,
|
|
103
|
+
fs: asyncFs,
|
|
104
|
+
prompts: noopPrompts,
|
|
105
|
+
promptLibrary,
|
|
106
|
+
loggerFactory,
|
|
107
|
+
errorLogger,
|
|
108
|
+
options: optionResolvers,
|
|
109
|
+
contextFactory,
|
|
110
|
+
registry,
|
|
111
|
+
httpClient,
|
|
112
|
+
commandRunner: wrappedRunner,
|
|
113
|
+
providers,
|
|
114
|
+
dependencies: {
|
|
115
|
+
fs: asyncFs,
|
|
116
|
+
prompts: noopPrompts,
|
|
117
|
+
env: {
|
|
118
|
+
cwd,
|
|
119
|
+
homeDir,
|
|
120
|
+
platform: process.platform,
|
|
121
|
+
variables
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
return container;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=container.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"container.js","sourceRoot":"","sources":["../../src/sdk/container.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAG9B,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,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AAC;IAEF,SAAS,GAAG;QACV,GAAG,EAAE,WAAW;QAChB,EAAE,EAAE,OAAO;QACX,OAAO,EAAE,WAAW;QACpB,aAAa;QACb,aAAa;QACb,WAAW;QACX,OAAO,EAAE,eAAe;QACxB,cAAc;QACd,QAAQ;QACR,UAAU;QACV,aAAa,EAAE,aAAa;QAC5B,SAAS;QACT,YAAY,EAAE;YACZ,EAAE,EAAE,OAAO;YACX,OAAO,EAAE,WAAW;YACpB,GAAG,EAAE;gBACH,GAAG;gBACH,OAAO;gBACP,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,SAAS;aACV;SACF;KACF,CAAC;IAEF,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads the Poe API key with the following priority:
|
|
3
|
+
* 1. `POE_API_KEY` environment variable (if set)
|
|
4
|
+
* 2. Credentials file (`~/.poe-code/credentials.json`)
|
|
5
|
+
*
|
|
6
|
+
* @returns The API key
|
|
7
|
+
* @throws Error if no credentials found
|
|
8
|
+
*/
|
|
9
|
+
export declare function getPoeApiKey(): Promise<string>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as fs from "node:fs/promises";
|
|
2
|
+
import * as os from "node:os";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
const CREDENTIALS_RELATIVE_PATH = ".poe-code/credentials.json";
|
|
5
|
+
/**
|
|
6
|
+
* Reads the Poe API key with the following priority:
|
|
7
|
+
* 1. `POE_API_KEY` environment variable (if set)
|
|
8
|
+
* 2. Credentials file (`~/.poe-code/credentials.json`)
|
|
9
|
+
*
|
|
10
|
+
* @returns The API key
|
|
11
|
+
* @throws Error if no credentials found
|
|
12
|
+
*/
|
|
13
|
+
export async function getPoeApiKey() {
|
|
14
|
+
const envKey = process.env.POE_API_KEY;
|
|
15
|
+
if (typeof envKey === "string" && envKey.trim().length > 0) {
|
|
16
|
+
return envKey.trim();
|
|
17
|
+
}
|
|
18
|
+
const homeDir = os.homedir();
|
|
19
|
+
const credentialsPath = path.join(homeDir, CREDENTIALS_RELATIVE_PATH);
|
|
20
|
+
try {
|
|
21
|
+
const content = await fs.readFile(credentialsPath, "utf8");
|
|
22
|
+
const parsed = JSON.parse(content);
|
|
23
|
+
if (typeof parsed === "object" &&
|
|
24
|
+
parsed !== null &&
|
|
25
|
+
typeof parsed.apiKey === "string" &&
|
|
26
|
+
parsed.apiKey.length > 0) {
|
|
27
|
+
return parsed.apiKey;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// File doesn't exist or is invalid
|
|
32
|
+
}
|
|
33
|
+
throw new Error("No API key found. Set POE_API_KEY or run 'poe-code login'.");
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=credentials.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/sdk/credentials.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAElC,MAAM,yBAAyB,GAAG,4BAA4B,CAAC;AAE/D;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY;IAChC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;IACvC,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3D,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;IACvB,CAAC;IAED,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;IAC7B,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,yBAAyB,CAAC,CAAC;IAEtE,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;QAC3D,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACnC,IACE,OAAO,MAAM,KAAK,QAAQ;YAC1B,MAAM,KAAK,IAAI;YACf,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ;YACjC,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EACxB,CAAC;YACD,OAAO,MAAM,CAAC,MAAM,CAAC;QACvB,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,mCAAmC;IACrC,CAAC;IAED,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CliContainer } from "../cli/container.js";
|
|
2
|
+
import type { SpawnResult } from "./types.js";
|
|
3
|
+
export interface SpawnCoreOptions {
|
|
4
|
+
/** The prompt to send to the provider */
|
|
5
|
+
prompt: string;
|
|
6
|
+
/** Working directory for the service CLI */
|
|
7
|
+
cwd?: string;
|
|
8
|
+
/** Model identifier override */
|
|
9
|
+
model?: string;
|
|
10
|
+
/** Additional arguments forwarded to the CLI */
|
|
11
|
+
args?: string[];
|
|
12
|
+
/** Whether prompt was read from stdin */
|
|
13
|
+
useStdin?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface SpawnCoreFlags {
|
|
16
|
+
dryRun: boolean;
|
|
17
|
+
verbose: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Core spawn implementation used by both SDK and CLI.
|
|
21
|
+
* Accepts an existing container to avoid creating a new one.
|
|
22
|
+
*/
|
|
23
|
+
export declare function spawnCore(container: CliContainer, service: string, options: SpawnCoreOptions, flags?: SpawnCoreFlags): Promise<SpawnResult>;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { buildProviderContext, createExecutionResources } from "../cli/commands/shared.js";
|
|
3
|
+
/**
|
|
4
|
+
* Core spawn implementation used by both SDK and CLI.
|
|
5
|
+
* Accepts an existing container to avoid creating a new one.
|
|
6
|
+
*/
|
|
7
|
+
export async function spawnCore(container, service, options, flags = { dryRun: false, verbose: false }) {
|
|
8
|
+
// Resolve working directory
|
|
9
|
+
const cwdOverride = resolveSpawnWorkingDirectory(container.env.cwd, options.cwd);
|
|
10
|
+
// Build spawn command options (internal format)
|
|
11
|
+
const spawnOptions = {
|
|
12
|
+
prompt: options.prompt,
|
|
13
|
+
args: options.args,
|
|
14
|
+
model: options.model,
|
|
15
|
+
cwd: cwdOverride,
|
|
16
|
+
useStdin: options.useStdin ?? false
|
|
17
|
+
};
|
|
18
|
+
// Resolve service adapter
|
|
19
|
+
const adapter = container.registry.get(service);
|
|
20
|
+
if (!adapter) {
|
|
21
|
+
throw new Error(`Unknown service "${service}".`);
|
|
22
|
+
}
|
|
23
|
+
if (typeof adapter.spawn !== "function") {
|
|
24
|
+
throw new Error(`${adapter.label} does not support spawn.`);
|
|
25
|
+
}
|
|
26
|
+
if (spawnOptions.useStdin && !adapter.supportsStdinPrompt) {
|
|
27
|
+
throw new Error(`${adapter.label} does not support stdin prompts. Use a different service (e.g. "codex") or pass the prompt as an argument.`);
|
|
28
|
+
}
|
|
29
|
+
// Create execution resources (logger, context)
|
|
30
|
+
const commandFlags = { dryRun: flags.dryRun, assumeYes: true, verbose: flags.verbose };
|
|
31
|
+
const resources = createExecutionResources(container, commandFlags, `spawn:${service}`);
|
|
32
|
+
// Build provider context
|
|
33
|
+
const providerContext = buildProviderContext(container, adapter, resources);
|
|
34
|
+
// Handle dry run
|
|
35
|
+
if (flags.dryRun) {
|
|
36
|
+
const extra = spawnOptions.args && spawnOptions.args.length > 0
|
|
37
|
+
? ` with args ${JSON.stringify(spawnOptions.args)}`
|
|
38
|
+
: "";
|
|
39
|
+
const cwdSuffix = spawnOptions.cwd ? ` from ${spawnOptions.cwd}` : "";
|
|
40
|
+
const promptDetail = spawnOptions.useStdin
|
|
41
|
+
? `(stdin, ${spawnOptions.prompt.length} chars)`
|
|
42
|
+
: `"${spawnOptions.prompt}"`;
|
|
43
|
+
resources.logger.dryRun(`Dry run: would spawn ${adapter.label} with prompt ${promptDetail}${extra}${cwdSuffix}.`);
|
|
44
|
+
return {
|
|
45
|
+
stdout: "",
|
|
46
|
+
stderr: "",
|
|
47
|
+
exitCode: 0
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// Invoke spawn through registry
|
|
51
|
+
const result = (await container.registry.invoke(adapter.name, "spawn", async (entry) => {
|
|
52
|
+
if (!entry.spawn) {
|
|
53
|
+
throw new Error(`${adapter.label} does not support spawn.`);
|
|
54
|
+
}
|
|
55
|
+
const output = await entry.spawn(providerContext, spawnOptions);
|
|
56
|
+
return output;
|
|
57
|
+
}));
|
|
58
|
+
// Return normalized result
|
|
59
|
+
if (!result) {
|
|
60
|
+
return {
|
|
61
|
+
stdout: "",
|
|
62
|
+
stderr: "",
|
|
63
|
+
exitCode: 0
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
stdout: result.stdout,
|
|
68
|
+
stderr: result.stderr,
|
|
69
|
+
exitCode: result.exitCode
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function resolveSpawnWorkingDirectory(baseDir, candidate) {
|
|
73
|
+
if (!candidate || candidate.trim().length === 0) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
if (path.isAbsolute(candidate)) {
|
|
77
|
+
return candidate;
|
|
78
|
+
}
|
|
79
|
+
return path.resolve(baseDir, candidate);
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=spawn-core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn-core.js","sourceRoot":"","sources":["../../src/sdk/spawn-core.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,OAAO,EACL,oBAAoB,E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MAAM,GAAG,MAAM,KAAK,CAAC,KAAK,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;QAChE,OAAO,MAAoC,CAAC;IAC9C,CAAC,CACF,CAA+B,CAAC;IAEjC,2BAA2B;IAC3B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO;YACL,MAAM,EAAE,EAAE;YACV,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE,CAAC;SACZ,CAAC;IACJ,CAAC;IAED,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;KAC1B,CAAC;AACJ,CAAC;AAED,SAAS,4BAA4B,CACnC,OAAe,EACf,SAAkB;IAElB,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChD,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC/B,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SpawnOptions, SpawnResult } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Runs a single prompt through a configured service CLI.
|
|
4
|
+
*
|
|
5
|
+
* @param service - Service identifier (claude-code, codex, opencode)
|
|
6
|
+
* @param options - Configuration for the spawn
|
|
7
|
+
* @returns Promise resolving to SpawnResult with stdout, stderr, and exitCode
|
|
8
|
+
* @throws Error if no API key found or service doesn't support spawn
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import { spawn } from "poe-code"
|
|
13
|
+
*
|
|
14
|
+
* const result = await spawn("claude-code", {
|
|
15
|
+
* prompt: "Fix the bug in auth.ts",
|
|
16
|
+
* cwd: "/path/to/project",
|
|
17
|
+
* model: "claude-sonnet-4"
|
|
18
|
+
* })
|
|
19
|
+
*
|
|
20
|
+
* console.log(result.stdout)
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function spawn(service: string, options: SpawnOptions): Promise<SpawnResult>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createSdkContainer } from "./container.js";
|
|
2
|
+
import { getPoeApiKey } from "./credentials.js";
|
|
3
|
+
import { spawnCore } from "./spawn-core.js";
|
|
4
|
+
/**
|
|
5
|
+
* Runs a single prompt through a configured service CLI.
|
|
6
|
+
*
|
|
7
|
+
* @param service - Service identifier (claude-code, codex, opencode)
|
|
8
|
+
* @param options - Configuration for the spawn
|
|
9
|
+
* @returns Promise resolving to SpawnResult with stdout, stderr, and exitCode
|
|
10
|
+
* @throws Error if no API key found or service doesn't support spawn
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { spawn } from "poe-code"
|
|
15
|
+
*
|
|
16
|
+
* const result = await spawn("claude-code", {
|
|
17
|
+
* prompt: "Fix the bug in auth.ts",
|
|
18
|
+
* cwd: "/path/to/project",
|
|
19
|
+
* model: "claude-sonnet-4"
|
|
20
|
+
* })
|
|
21
|
+
*
|
|
22
|
+
* console.log(result.stdout)
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export async function spawn(service, options) {
|
|
26
|
+
// Validate API key exists (throws if not found)
|
|
27
|
+
await getPoeApiKey();
|
|
28
|
+
// Create SDK container with cwd from options
|
|
29
|
+
const container = createSdkContainer({
|
|
30
|
+
cwd: options.cwd
|
|
31
|
+
});
|
|
32
|
+
// Delegate to core spawn implementation
|
|
33
|
+
return spawnCore(container, service, {
|
|
34
|
+
prompt: options.prompt,
|
|
35
|
+
cwd: options.cwd,
|
|
36
|
+
model: options.model,
|
|
37
|
+
args: options.args,
|
|
38
|
+
useStdin: false
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=spawn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn.js","sourceRoot":"","sources":["../../src/sdk/spawn.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CACzB,OAAe,EACf,OAAqB;IAErB,gDAAgD;IAChD,MAAM,YAAY,EAAE,CAAC;IAErB,6CAA6C;IAC7C,MAAM,SAAS,GAAG,kBAAkB,CAAC;QACnC,GAAG,EAAE,OAAO,CAAC,GAAG;KACjB,CAAC,CAAC;IAEH,wCAAwC;IACxC,OAAO,SAAS,CAAC,SAAS,EAAE,OAAO,EAAE;QACnC,MAAM,EAAE,OAAO,CAAC,MAAM;QACtB,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,QAAQ,EAAE,KAAK;KAChB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for spawning a provider CLI.
|
|
3
|
+
*/
|
|
4
|
+
export interface SpawnOptions {
|
|
5
|
+
/** The prompt to send to the provider */
|
|
6
|
+
prompt: string;
|
|
7
|
+
/** Working directory for the service CLI */
|
|
8
|
+
cwd?: string;
|
|
9
|
+
/** Model identifier override */
|
|
10
|
+
model?: string;
|
|
11
|
+
/** Additional arguments forwarded to the CLI */
|
|
12
|
+
args?: string[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Result from spawning a provider CLI.
|
|
16
|
+
*/
|
|
17
|
+
export interface SpawnResult {
|
|
18
|
+
/** Standard output from the CLI */
|
|
19
|
+
stdout: string;
|
|
20
|
+
/** Standard error from the CLI */
|
|
21
|
+
stderr: string;
|
|
22
|
+
/** Exit code from the CLI process */
|
|
23
|
+
exitCode: number;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/sdk/types.ts"],"names":[],"mappings":""}
|