@baryonlabs/cli 0.2.0 → 0.2.2
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 +2 -0
- package/package.json +1 -1
- package/src/config.js +20 -0
- package/src/constants.js +11 -1
- package/src/pi.js +8 -0
package/README.md
CHANGED
|
@@ -56,6 +56,8 @@ baryon --provider openai # 다른 모델로 전환·비교
|
|
|
56
56
|
- **인터랙티브 셸** ([pi-interactive-shell](https://github.com/nicobailon/pi-interactive-shell))
|
|
57
57
|
- **웹 액세스** ([pi-web-access](https://github.com/nicobailon/pi-web-access))
|
|
58
58
|
- **웹 페치** ([pi-web-fetch](https://github.com/georgebashi/pi-web-fetch))
|
|
59
|
+
- **웹 검색** ([pi-search](https://github.com/buddingnewinsights/pi-search))
|
|
60
|
+
- **병렬 웹 검색** ([pi-parallel-web-search](https://github.com/philipp-spiess/pi-parallel-web-search))
|
|
59
61
|
|
|
60
62
|
## 설정
|
|
61
63
|
|
package/package.json
CHANGED
package/src/config.js
CHANGED
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
PI_AGENT_DIR,
|
|
12
12
|
PI_MODELS_JSON,
|
|
13
13
|
PROVIDER,
|
|
14
|
+
SESSION_HEADER,
|
|
15
|
+
SESSION_ID_ENV,
|
|
14
16
|
} from "./constants.js";
|
|
15
17
|
|
|
16
18
|
function readJson(file, fallback) {
|
|
@@ -69,6 +71,9 @@ export function syncPiModels({ baseUrl, models }) {
|
|
|
69
71
|
api: "openai-completions",
|
|
70
72
|
apiKey: `$${API_KEY_ENV}`,
|
|
71
73
|
authHeader: true,
|
|
74
|
+
// Per-launch session id (resolved by pi from the env at request time) so the
|
|
75
|
+
// gateway can group a run's turns into one session. Gateway requires it.
|
|
76
|
+
headers: { [SESSION_HEADER]: `$${SESSION_ID_ENV}` },
|
|
72
77
|
models:
|
|
73
78
|
Array.isArray(models) && models.length ? models : DEFAULT_MODELS,
|
|
74
79
|
};
|
|
@@ -83,4 +88,19 @@ export function piProviderConfigured() {
|
|
|
83
88
|
return Boolean(root?.providers?.[PROVIDER]);
|
|
84
89
|
}
|
|
85
90
|
|
|
91
|
+
/**
|
|
92
|
+
* Auto-heal older installs: ensure the baryon provider sends the session
|
|
93
|
+
* header. Safe to call on every launch — only writes when something changed.
|
|
94
|
+
* Returns true if the provider exists (after any patch).
|
|
95
|
+
*/
|
|
96
|
+
export function ensurePiSessionHeader() {
|
|
97
|
+
const root = readJson(PI_MODELS_JSON, {});
|
|
98
|
+
const p = root?.providers?.[PROVIDER];
|
|
99
|
+
if (!p) return false;
|
|
100
|
+
if (p.headers?.[SESSION_HEADER] === `$${SESSION_ID_ENV}`) return true;
|
|
101
|
+
p.headers = { ...(p.headers || {}), [SESSION_HEADER]: `$${SESSION_ID_ENV}` };
|
|
102
|
+
writeJson(PI_MODELS_JSON, root);
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
|
|
86
106
|
export { PI_MODELS_JSON, BARYON_CONFIG };
|
package/src/constants.js
CHANGED
|
@@ -11,6 +11,14 @@ export const DEFAULT_BASE_URL =
|
|
|
11
11
|
/** Env var pi resolves at request time (apiKey: "$BARYON_API_KEY"). */
|
|
12
12
|
export const API_KEY_ENV = "BARYON_API_KEY";
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Session id env var. The baryon provider sends it as `X-Baryon-Session` so the
|
|
16
|
+
* gateway can group every turn of one `baryon` run into a single session. A
|
|
17
|
+
* fresh id is minted per launch (see pi.js). The gateway requires it.
|
|
18
|
+
*/
|
|
19
|
+
export const SESSION_ID_ENV = "BARYON_SESSION_ID";
|
|
20
|
+
export const SESSION_HEADER = "X-Baryon-Session";
|
|
21
|
+
|
|
14
22
|
/** Underlying coding agent package + binary. */
|
|
15
23
|
export const PI_PACKAGE = "@earendil-works/pi-coding-agent";
|
|
16
24
|
export const PI_BIN = "pi";
|
|
@@ -57,7 +65,9 @@ export const DEFAULT_EXTENSIONS = [
|
|
|
57
65
|
{ name: "pi-canvas", src: "https://github.com/jyaunches/pi-canvas", note: "캔버스" },
|
|
58
66
|
{ name: "pi-interactive-shell", src: "https://github.com/nicobailon/pi-interactive-shell", note: "인터랙티브 셸" },
|
|
59
67
|
{ name: "pi-web-access", src: "https://github.com/nicobailon/pi-web-access", note: "웹 액세스(브라우징)" },
|
|
60
|
-
{ name: "pi-web-fetch", src: "https://github.com/georgebashi/pi-web-fetch", note: "웹 페치" }
|
|
68
|
+
{ name: "pi-web-fetch", src: "https://github.com/georgebashi/pi-web-fetch", note: "웹 페치" },
|
|
69
|
+
{ name: "pi-search", src: "https://github.com/buddingnewinsights/pi-search", note: "웹 검색" },
|
|
70
|
+
{ name: "pi-parallel-web-search", src: "https://github.com/philipp-spiess/pi-parallel-web-search", note: "병렬 웹 검색" }
|
|
61
71
|
];
|
|
62
72
|
|
|
63
73
|
export const HOMEPAGE = "https://cli.baryon.ai";
|
package/src/pi.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { spawn } from "node:child_process";
|
|
4
4
|
import { createRequire } from "node:module";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { randomUUID } from "node:crypto";
|
|
6
7
|
import fs from "node:fs";
|
|
7
8
|
import path from "node:path";
|
|
8
9
|
import {
|
|
@@ -10,7 +11,9 @@ import {
|
|
|
10
11
|
PI_BIN,
|
|
11
12
|
PI_PACKAGE,
|
|
12
13
|
PROVIDER,
|
|
14
|
+
SESSION_ID_ENV,
|
|
13
15
|
} from "./constants.js";
|
|
16
|
+
import { ensurePiSessionHeader } from "./config.js";
|
|
14
17
|
|
|
15
18
|
const require = createRequire(import.meta.url);
|
|
16
19
|
|
|
@@ -98,6 +101,11 @@ export function runPi(args, config, { injectTargeting = true } = {}) {
|
|
|
98
101
|
if (config.apiKey) env[API_KEY_ENV] = config.apiKey;
|
|
99
102
|
if (config.baseUrl) env.BARYON_BASE_URL = config.baseUrl;
|
|
100
103
|
|
|
104
|
+
// One session per launch: mint an id (unless the caller pinned one) and make
|
|
105
|
+
// sure the provider forwards it. The gateway requires a session id.
|
|
106
|
+
if (!env[SESSION_ID_ENV]) env[SESSION_ID_ENV] = `cli_${randomUUID()}`;
|
|
107
|
+
ensurePiSessionHeader();
|
|
108
|
+
|
|
101
109
|
return new Promise((resolve, reject) => {
|
|
102
110
|
const child = spawn(process.execPath, [entry, ...finalArgs], {
|
|
103
111
|
stdio: "inherit",
|