@saleso.innovations/bridge 0.1.32 → 0.1.34
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/dist/shellSession.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export declare const EXIT_SENTINEL_PREFIX = "__CLEOS_EXIT_";
|
|
2
2
|
export declare const EXIT_SENTINEL_SUFFIX = "__";
|
|
3
3
|
export declare const MAX_OUTPUT_BYTES: number;
|
|
4
|
-
export declare const DEFAULT_COMMAND_TIMEOUT_MS =
|
|
4
|
+
export declare const DEFAULT_COMMAND_TIMEOUT_MS = 60000;
|
|
5
5
|
export type ShellDeltaEmitter = (stream: "stdout" | "stderr", delta: string, sequence: number) => void;
|
|
6
6
|
export type ParsedShellFooter = {
|
|
7
7
|
output: string;
|
|
@@ -13,6 +13,7 @@ export declare function parseShellFooter(raw: string): ParsedShellFooter | null;
|
|
|
13
13
|
export declare function executeShellExec(args: Record<string, unknown>, onDelta: ShellDeltaEmitter, timeoutMs?: number): Promise<{
|
|
14
14
|
exitCode: number;
|
|
15
15
|
sessionId: string;
|
|
16
|
+
output: string;
|
|
16
17
|
}>;
|
|
17
18
|
export declare function resetShellSession(sessionId: string): {
|
|
18
19
|
sessionId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shellSession.d.ts","sourceRoot":"","sources":["../src/shellSession.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,oBAAoB,kBAAkB,CAAC;AACpD,eAAO,MAAM,oBAAoB,OAAO,CAAC;AACzC,eAAO,MAAM,gBAAgB,QAAa,CAAC;AAC3C,eAAO,MAAM,0BAA0B,
|
|
1
|
+
{"version":3,"file":"shellSession.d.ts","sourceRoot":"","sources":["../src/shellSession.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,oBAAoB,kBAAkB,CAAC;AACpD,eAAO,MAAM,oBAAoB,OAAO,CAAC;AACzC,eAAO,MAAM,gBAAgB,QAAa,CAAC;AAC3C,eAAO,MAAM,0BAA0B,QAAS,CAAC;AAGjD,MAAM,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE,QAAQ,GAAG,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;AAEvG,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAmBF,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAG/D;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI,CAWtE;AAmJD,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,EAAE,iBAAiB,EAC1B,SAAS,GAAE,MAAmC,GAC7C,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAwClE;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,MAAM,GAAG;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,CAU1E;AAED,wBAAgB,0BAA0B,IAAI,IAAI,CAOjD"}
|
package/dist/shellSession.js
CHANGED
|
@@ -3,7 +3,7 @@ import { homedir } from "node:os";
|
|
|
3
3
|
export const EXIT_SENTINEL_PREFIX = "__CLEOS_EXIT_";
|
|
4
4
|
export const EXIT_SENTINEL_SUFFIX = "__";
|
|
5
5
|
export const MAX_OUTPUT_BYTES = 512 * 1024;
|
|
6
|
-
export const DEFAULT_COMMAND_TIMEOUT_MS =
|
|
6
|
+
export const DEFAULT_COMMAND_TIMEOUT_MS = 60_000;
|
|
7
7
|
const SENTINEL_TAIL_RESERVE = 64;
|
|
8
8
|
const sessions = new Map();
|
|
9
9
|
export function buildWrappedCommand(userCommand) {
|
|
@@ -11,7 +11,7 @@ export function buildWrappedCommand(userCommand) {
|
|
|
11
11
|
return `{ eval "$(printf '%s' '${encoded}' | base64 -d)"; ec=$?; echo "${EXIT_SENTINEL_PREFIX}\${ec}${EXIT_SENTINEL_SUFFIX}"; pwd; } 2>&1\n`;
|
|
12
12
|
}
|
|
13
13
|
export function parseShellFooter(raw) {
|
|
14
|
-
const pattern = new RegExp(
|
|
14
|
+
const pattern = new RegExp(`(?:^|\\n)${EXIT_SENTINEL_PREFIX}(\\d+)${EXIT_SENTINEL_SUFFIX}\\n([^\\n]*)\\n?$`);
|
|
15
15
|
const match = raw.match(pattern);
|
|
16
16
|
if (!match || match.index === undefined)
|
|
17
17
|
return null;
|
|
@@ -177,7 +177,7 @@ export async function executeShellExec(args, onDelta, timeoutMs = DEFAULT_COMMAN
|
|
|
177
177
|
const wrapped = buildWrappedCommand(command);
|
|
178
178
|
return await new Promise((resolve, reject) => {
|
|
179
179
|
session.pendingResolve = (footer) => {
|
|
180
|
-
resolve({ exitCode: footer.exitCode, sessionId });
|
|
180
|
+
resolve({ exitCode: footer.exitCode, sessionId, output: footer.output });
|
|
181
181
|
};
|
|
182
182
|
session.pendingReject = reject;
|
|
183
183
|
session.pendingTimeout = setTimeout(() => {
|
|
@@ -193,7 +193,7 @@ export function resetShellSession(sessionId) {
|
|
|
193
193
|
const existing = sessions.get(sessionId);
|
|
194
194
|
if (existing) {
|
|
195
195
|
if (existing.busy) {
|
|
196
|
-
|
|
196
|
+
failPending(existing, new Error("Shell session reset"));
|
|
197
197
|
}
|
|
198
198
|
existing.process.kill("SIGTERM");
|
|
199
199
|
sessions.delete(sessionId);
|
|
@@ -19,6 +19,14 @@ test("parseShellFooter handles exit code zero", () => {
|
|
|
19
19
|
assert.equal(parsed.exitCode, 0);
|
|
20
20
|
assert.equal(parsed.cwd, "/home/user");
|
|
21
21
|
});
|
|
22
|
+
test("parseShellFooter handles empty command output", () => {
|
|
23
|
+
const raw = `${EXIT_SENTINEL_PREFIX}0${EXIT_SENTINEL_SUFFIX}\n/home/user\n`;
|
|
24
|
+
const parsed = parseShellFooter(raw);
|
|
25
|
+
assert.ok(parsed);
|
|
26
|
+
assert.equal(parsed.output, "");
|
|
27
|
+
assert.equal(parsed.exitCode, 0);
|
|
28
|
+
assert.equal(parsed.cwd, "/home/user");
|
|
29
|
+
});
|
|
22
30
|
test("buildWrappedCommand base64-encodes user input", () => {
|
|
23
31
|
const wrapped = buildWrappedCommand("echo hello");
|
|
24
32
|
assert.match(wrapped, /base64 -d/);
|