@a5c-ai/agent-mux-cli 5.0.1-staging.efc2092bb → 5.0.1-staging.f01483e80761
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/commands/launch-bridge-hooks.d.ts +59 -0
- package/dist/commands/launch-bridge-hooks.d.ts.map +1 -0
- package/dist/commands/launch-bridge-hooks.js +222 -0
- package/dist/commands/launch-bridge-hooks.js.map +1 -0
- package/dist/commands/launch-completion-engine.d.ts +4 -10
- package/dist/commands/launch-completion-engine.d.ts.map +1 -1
- package/dist/commands/launch-completion-engine.js +4 -104
- package/dist/commands/launch-completion-engine.js.map +1 -1
- package/dist/commands/launch.d.ts +3 -0
- package/dist/commands/launch.d.ts.map +1 -1
- package/dist/commands/launch.js +1032 -40
- package/dist/commands/launch.js.map +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge hook emulation for non-interactive mode.
|
|
3
|
+
*
|
|
4
|
+
* When --bridge-hooks is set, emulates lifecycle hooks (session-start, stop
|
|
5
|
+
* with block-continue, session-end) that the underlying CLI harness may not
|
|
6
|
+
* support natively. The emulator shells out to the babysitter CLI to trigger
|
|
7
|
+
* hook handling and run-status queries.
|
|
8
|
+
*/
|
|
9
|
+
export interface BridgeHookContext {
|
|
10
|
+
harness: string;
|
|
11
|
+
cwd: string;
|
|
12
|
+
env: Record<string, string>;
|
|
13
|
+
sessionId?: string;
|
|
14
|
+
runsDir?: string;
|
|
15
|
+
verbose?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface SessionStartResult {
|
|
18
|
+
runId?: string;
|
|
19
|
+
emulated: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface StopResult {
|
|
22
|
+
shouldContinue: boolean;
|
|
23
|
+
resumeId?: string;
|
|
24
|
+
emulated: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare class BridgeHookEmulator {
|
|
27
|
+
private readonly ctx;
|
|
28
|
+
private readonly bin;
|
|
29
|
+
private runId;
|
|
30
|
+
constructor(ctx: BridgeHookContext);
|
|
31
|
+
/**
|
|
32
|
+
* Emulate the session-start lifecycle hook.
|
|
33
|
+
*
|
|
34
|
+
* If the harness supports session-start natively, this is a no-op.
|
|
35
|
+
* If emulated, it invokes `babysitter hook:run --hook-type session-start`
|
|
36
|
+
* which creates a bare run and initializes session state.
|
|
37
|
+
*/
|
|
38
|
+
emulateSessionStart(): Promise<SessionStartResult>;
|
|
39
|
+
/**
|
|
40
|
+
* Emulate the stop lifecycle hook.
|
|
41
|
+
*
|
|
42
|
+
* If the harness supports stop natively, this is a no-op.
|
|
43
|
+
* If emulated:
|
|
44
|
+
* 1. Queries `babysitter run:status <runDir> --json` to check run state
|
|
45
|
+
* 2. If run has pending effects or is not completed: shouldContinue=true
|
|
46
|
+
* 3. If run is completed: shouldContinue=false
|
|
47
|
+
* 4. Returns a resumeId for session resume if continuing
|
|
48
|
+
*/
|
|
49
|
+
emulateStop(runId?: string): Promise<StopResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Emulate the session-end lifecycle hook.
|
|
52
|
+
*
|
|
53
|
+
* If the harness supports session-end natively, this is a no-op.
|
|
54
|
+
* If emulated, invokes `babysitter hook:run --hook-type session-end`.
|
|
55
|
+
*/
|
|
56
|
+
emulateSessionEnd(): Promise<void>;
|
|
57
|
+
/** Return the current run ID, if one was created during session-start. */
|
|
58
|
+
getRunId(): string | undefined;
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launch-bridge-hooks.d.ts","sourceRoot":"","sources":["../../src/commands/launch-bridge-hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;CACnB;AAgED,qBAAa,kBAAkB;IAIjB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAHhC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,KAAK,CAAqB;gBAEL,GAAG,EAAE,iBAAiB;IAInD;;;;;;OAMG;IACG,mBAAmB,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAiDxD;;;;;;;;;OASG;IACG,WAAW,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAwEtD;;;;;OAKG;IACG,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC;IAuCxC,0EAA0E;IAC1E,QAAQ,IAAI,MAAM,GAAG,SAAS;CAG/B"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge hook emulation for non-interactive mode.
|
|
3
|
+
*
|
|
4
|
+
* When --bridge-hooks is set, emulates lifecycle hooks (session-start, stop
|
|
5
|
+
* with block-continue, session-end) that the underlying CLI harness may not
|
|
6
|
+
* support natively. The emulator shells out to the babysitter CLI to trigger
|
|
7
|
+
* hook handling and run-status queries.
|
|
8
|
+
*/
|
|
9
|
+
import { getHookSupport } from '@a5c-ai/agent-catalog';
|
|
10
|
+
// ---------------------------------------------------------------------------
|
|
11
|
+
// Internal helpers
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
/** Resolve the babysitter CLI binary path from env or default. */
|
|
14
|
+
function resolveBabysitterBin(env) {
|
|
15
|
+
return env['BABYSITTER_BIN'] || 'babysitter';
|
|
16
|
+
}
|
|
17
|
+
/** Run a babysitter CLI command and return stdout. Throws on non-zero exit. */
|
|
18
|
+
async function execBabysitterCommand(bin, args, options) {
|
|
19
|
+
const { execFileSync } = await import('node:child_process');
|
|
20
|
+
const mergedEnv = { ...process.env, ...options.env };
|
|
21
|
+
if (options.verbose) {
|
|
22
|
+
console.error(`[bridge-hooks] exec: ${bin} ${args.join(' ')}`);
|
|
23
|
+
}
|
|
24
|
+
const result = execFileSync(bin, args, {
|
|
25
|
+
cwd: options.cwd,
|
|
26
|
+
env: mergedEnv,
|
|
27
|
+
encoding: 'utf-8',
|
|
28
|
+
timeout: 30_000,
|
|
29
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
30
|
+
});
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Query the agent-catalog for hook support in non-interactive mode.
|
|
35
|
+
* Returns the support level for a given hook, or undefined if the catalog
|
|
36
|
+
* is not available.
|
|
37
|
+
*/
|
|
38
|
+
async function getHookSupportLevel(harness, hookName) {
|
|
39
|
+
const support = getHookSupport(harness, 'nonInteractive');
|
|
40
|
+
return support?.[hookName];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Parse JSON output from a babysitter CLI command, returning null on failure.
|
|
44
|
+
*/
|
|
45
|
+
function parseJsonOutput(output) {
|
|
46
|
+
try {
|
|
47
|
+
return JSON.parse(output.trim());
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
// BridgeHookEmulator
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
export class BridgeHookEmulator {
|
|
57
|
+
ctx;
|
|
58
|
+
bin;
|
|
59
|
+
runId;
|
|
60
|
+
constructor(ctx) {
|
|
61
|
+
this.ctx = ctx;
|
|
62
|
+
this.bin = resolveBabysitterBin(ctx.env);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Emulate the session-start lifecycle hook.
|
|
66
|
+
*
|
|
67
|
+
* If the harness supports session-start natively, this is a no-op.
|
|
68
|
+
* If emulated, it invokes `babysitter hook:run --hook-type session-start`
|
|
69
|
+
* which creates a bare run and initializes session state.
|
|
70
|
+
*/
|
|
71
|
+
async emulateSessionStart() {
|
|
72
|
+
const level = await getHookSupportLevel(this.ctx.harness, 'sessionStart');
|
|
73
|
+
if (level === 'native') {
|
|
74
|
+
return { emulated: false };
|
|
75
|
+
}
|
|
76
|
+
if (level === 'unsupported' || level === 'emulated' || level === undefined) {
|
|
77
|
+
try {
|
|
78
|
+
const args = [
|
|
79
|
+
'hook:run',
|
|
80
|
+
'--hook-type', 'session-start',
|
|
81
|
+
'--harness', this.ctx.harness,
|
|
82
|
+
'--json',
|
|
83
|
+
];
|
|
84
|
+
if (this.ctx.runsDir) {
|
|
85
|
+
args.push('--runs-dir', this.ctx.runsDir);
|
|
86
|
+
}
|
|
87
|
+
const output = await execBabysitterCommand(this.bin, args, {
|
|
88
|
+
cwd: this.ctx.cwd,
|
|
89
|
+
env: this.ctx.env,
|
|
90
|
+
verbose: this.ctx.verbose,
|
|
91
|
+
});
|
|
92
|
+
const result = parseJsonOutput(output);
|
|
93
|
+
if (result?.runId) {
|
|
94
|
+
this.runId = result.runId;
|
|
95
|
+
}
|
|
96
|
+
if (this.ctx.verbose) {
|
|
97
|
+
console.error(`[bridge-hooks] session-start emulated, runId=${this.runId ?? 'none'}`);
|
|
98
|
+
}
|
|
99
|
+
return { runId: this.runId, emulated: true };
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
if (this.ctx.verbose) {
|
|
103
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
104
|
+
console.error(`[bridge-hooks] session-start emulation failed: ${msg}`);
|
|
105
|
+
}
|
|
106
|
+
// Non-fatal: continue without a run ID
|
|
107
|
+
return { emulated: true };
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return { emulated: false };
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Emulate the stop lifecycle hook.
|
|
114
|
+
*
|
|
115
|
+
* If the harness supports stop natively, this is a no-op.
|
|
116
|
+
* If emulated:
|
|
117
|
+
* 1. Queries `babysitter run:status <runDir> --json` to check run state
|
|
118
|
+
* 2. If run has pending effects or is not completed: shouldContinue=true
|
|
119
|
+
* 3. If run is completed: shouldContinue=false
|
|
120
|
+
* 4. Returns a resumeId for session resume if continuing
|
|
121
|
+
*/
|
|
122
|
+
async emulateStop(runId) {
|
|
123
|
+
const effectiveRunId = runId ?? this.runId;
|
|
124
|
+
const level = await getHookSupportLevel(this.ctx.harness, 'stop');
|
|
125
|
+
if (level === 'native') {
|
|
126
|
+
return { shouldContinue: false, emulated: false };
|
|
127
|
+
}
|
|
128
|
+
if (!effectiveRunId) {
|
|
129
|
+
if (this.ctx.verbose) {
|
|
130
|
+
console.error('[bridge-hooks] stop: no runId available, cannot check run state');
|
|
131
|
+
}
|
|
132
|
+
return { shouldContinue: false, emulated: true };
|
|
133
|
+
}
|
|
134
|
+
if (level === 'unsupported' || level === 'emulated' || level === undefined) {
|
|
135
|
+
try {
|
|
136
|
+
const runDir = this.ctx.runsDir
|
|
137
|
+
? `${this.ctx.runsDir}/${effectiveRunId}`
|
|
138
|
+
: effectiveRunId;
|
|
139
|
+
const args = ['run:status', runDir, '--json'];
|
|
140
|
+
const output = await execBabysitterCommand(this.bin, args, {
|
|
141
|
+
cwd: this.ctx.cwd,
|
|
142
|
+
env: this.ctx.env,
|
|
143
|
+
verbose: this.ctx.verbose,
|
|
144
|
+
});
|
|
145
|
+
const status = parseJsonOutput(output);
|
|
146
|
+
if (!status) {
|
|
147
|
+
if (this.ctx.verbose) {
|
|
148
|
+
console.error('[bridge-hooks] stop: failed to parse run:status output');
|
|
149
|
+
}
|
|
150
|
+
return { shouldContinue: false, emulated: true };
|
|
151
|
+
}
|
|
152
|
+
const isCompleted = status.state === 'completed';
|
|
153
|
+
const hasPending = (status.pendingEffectsSummary?.totalPending ?? 0) > 0;
|
|
154
|
+
const needsMore = status.needsMoreIterations === true;
|
|
155
|
+
const shouldContinue = !isCompleted && (hasPending || needsMore);
|
|
156
|
+
if (this.ctx.verbose) {
|
|
157
|
+
console.error(`[bridge-hooks] stop: state=${status.state}, pending=${hasPending}, ` +
|
|
158
|
+
`needsMore=${needsMore}, shouldContinue=${shouldContinue}`);
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
shouldContinue,
|
|
162
|
+
resumeId: shouldContinue ? this.ctx.sessionId : undefined,
|
|
163
|
+
emulated: true,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
if (this.ctx.verbose) {
|
|
168
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
169
|
+
console.error(`[bridge-hooks] stop emulation failed: ${msg}`);
|
|
170
|
+
}
|
|
171
|
+
// On error, don't continue — safer default
|
|
172
|
+
return { shouldContinue: false, emulated: true };
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return { shouldContinue: false, emulated: false };
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Emulate the session-end lifecycle hook.
|
|
179
|
+
*
|
|
180
|
+
* If the harness supports session-end natively, this is a no-op.
|
|
181
|
+
* If emulated, invokes `babysitter hook:run --hook-type session-end`.
|
|
182
|
+
*/
|
|
183
|
+
async emulateSessionEnd() {
|
|
184
|
+
const level = await getHookSupportLevel(this.ctx.harness, 'sessionEnd');
|
|
185
|
+
if (level === 'native') {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (level === 'unsupported' || level === 'emulated' || level === undefined) {
|
|
189
|
+
try {
|
|
190
|
+
const args = [
|
|
191
|
+
'hook:run',
|
|
192
|
+
'--hook-type', 'session-end',
|
|
193
|
+
'--harness', this.ctx.harness,
|
|
194
|
+
'--json',
|
|
195
|
+
];
|
|
196
|
+
if (this.ctx.runsDir) {
|
|
197
|
+
args.push('--runs-dir', this.ctx.runsDir);
|
|
198
|
+
}
|
|
199
|
+
await execBabysitterCommand(this.bin, args, {
|
|
200
|
+
cwd: this.ctx.cwd,
|
|
201
|
+
env: this.ctx.env,
|
|
202
|
+
verbose: this.ctx.verbose,
|
|
203
|
+
});
|
|
204
|
+
if (this.ctx.verbose) {
|
|
205
|
+
console.error('[bridge-hooks] session-end emulated');
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
catch (err) {
|
|
209
|
+
if (this.ctx.verbose) {
|
|
210
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
211
|
+
console.error(`[bridge-hooks] session-end emulation failed: ${msg}`);
|
|
212
|
+
}
|
|
213
|
+
// Non-fatal: swallow errors on session-end
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/** Return the current run ID, if one was created during session-start. */
|
|
218
|
+
getRunId() {
|
|
219
|
+
return this.runId;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=launch-bridge-hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launch-bridge-hooks.js","sourceRoot":"","sources":["../../src/commands/launch-bridge-hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,EAAyB,MAAM,uBAAuB,CAAC;AA0B9E,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E,kEAAkE;AAClE,SAAS,oBAAoB,CAAC,GAA2B;IACvD,OAAO,GAAG,CAAC,gBAAgB,CAAC,IAAI,YAAY,CAAC;AAC/C,CAAC;AAED,+EAA+E;AAC/E,KAAK,UAAU,qBAAqB,CAClC,GAAW,EACX,IAAc,EACd,OAAwE;IAExE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,MAAM,CAAC,oBAAoB,CAAC,CAAC;IAE5D,MAAM,S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O,CAAC,CAAC;gBAC5C,CAAC;gBAED,MAAM,qBAAqB,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE;oBAC1C,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG;oBACjB,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG;oBACjB,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO;iBAC1B,CAAC,CAAC;gBAEH,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;oBACrB,OAAO,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;gBACvD,CAAC;YACH,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;oBACrB,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;oBAC7D,OAAO,CAAC,KAAK,CAAC,gDAAgD,GAAG,EAAE,CAAC,CAAC;gBACvE,CAAC;gBACD,2CAA2C;YAC7C,CAAC;QACH,CAAC;IACH,CAAC;IAED,0EAA0E;IAC1E,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Backward-compatibility re-exports.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* proxy needs a completion engine to translate between formats.
|
|
4
|
+
* The completion engine implementations now live in @a5c-ai/transport-mux.
|
|
5
|
+
* This module re-exports them so existing import paths continue to work.
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
export declare function createOpenAICompletionEngine(options: {
|
|
10
|
-
apiBase: string;
|
|
11
|
-
apiKey: string;
|
|
12
|
-
targetModel: string;
|
|
13
|
-
}): CompletionEngine;
|
|
7
|
+
export { createOpenAICompletionEngine, createGoogleCompletionEngine } from '@a5c-ai/transport-mux';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"launch-completion-engine.d.ts","sourceRoot":"","sources":["../../src/commands/launch-completion-engine.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"launch-completion-engine.d.ts","sourceRoot":"","sources":["../../src/commands/launch-completion-engine.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,4BAA4B,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1,108 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Backward-compatibility re-exports.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* proxy needs a completion engine to translate between formats.
|
|
4
|
+
* The completion engine implementations now live in @a5c-ai/transport-mux.
|
|
5
|
+
* This module re-exports them so existing import paths continue to work.
|
|
7
6
|
*/
|
|
8
|
-
|
|
9
|
-
return `${apiBase}/openai/deployments/${model}/chat/completions?api-version=2025-04-01-preview`;
|
|
10
|
-
}
|
|
11
|
-
function buildHeaders(apiKey) {
|
|
12
|
-
return {
|
|
13
|
-
'Content-Type': 'application/json',
|
|
14
|
-
'api-key': apiKey,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function buildBody(messages, model, stream) {
|
|
18
|
-
return JSON.stringify({ messages, model, stream });
|
|
19
|
-
}
|
|
20
|
-
export function createOpenAICompletionEngine(options) {
|
|
21
|
-
return {
|
|
22
|
-
async complete(request) {
|
|
23
|
-
const messages = request.messages.map((m) => ({ role: m.role, content: m.content }));
|
|
24
|
-
const response = await fetch(buildUrl(options.apiBase, options.targetModel), {
|
|
25
|
-
method: 'POST',
|
|
26
|
-
headers: buildHeaders(options.apiKey),
|
|
27
|
-
body: buildBody(messages, options.targetModel, false),
|
|
28
|
-
});
|
|
29
|
-
if (!response.ok) {
|
|
30
|
-
const errorText = await response.text();
|
|
31
|
-
throw new Error(`OpenAI API error ${response.status}: ${errorText}`);
|
|
32
|
-
}
|
|
33
|
-
const data = await response.json();
|
|
34
|
-
const choice = data.choices[0];
|
|
35
|
-
return {
|
|
36
|
-
id: data.id,
|
|
37
|
-
model: options.targetModel,
|
|
38
|
-
role: 'assistant',
|
|
39
|
-
text: choice?.message?.content ?? '',
|
|
40
|
-
finishReason: choice?.finish_reason ?? 'stop',
|
|
41
|
-
usage: {
|
|
42
|
-
promptTokens: data.usage?.prompt_tokens ?? 0,
|
|
43
|
-
completionTokens: data.usage?.completion_tokens ?? 0,
|
|
44
|
-
totalTokens: data.usage?.total_tokens ?? 0,
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
},
|
|
48
|
-
async *stream(request) {
|
|
49
|
-
const messages = request.messages.map((m) => ({ role: m.role, content: m.content }));
|
|
50
|
-
const response = await fetch(buildUrl(options.apiBase, options.targetModel), {
|
|
51
|
-
method: 'POST',
|
|
52
|
-
headers: buildHeaders(options.apiKey),
|
|
53
|
-
body: buildBody(messages, options.targetModel, true),
|
|
54
|
-
});
|
|
55
|
-
if (!response.ok) {
|
|
56
|
-
const errorText = await response.text();
|
|
57
|
-
throw new Error(`OpenAI API error ${response.status}: ${errorText}`);
|
|
58
|
-
}
|
|
59
|
-
const reader = response.body?.getReader();
|
|
60
|
-
if (!reader)
|
|
61
|
-
throw new Error('No response body');
|
|
62
|
-
const decoder = new TextDecoder();
|
|
63
|
-
let buffer = '';
|
|
64
|
-
while (true) {
|
|
65
|
-
const { done, value } = await reader.read();
|
|
66
|
-
if (done)
|
|
67
|
-
break;
|
|
68
|
-
buffer += decoder.decode(value, { stream: true });
|
|
69
|
-
const lines = buffer.split('\n');
|
|
70
|
-
buffer = lines.pop() ?? '';
|
|
71
|
-
for (const line of lines) {
|
|
72
|
-
const trimmed = line.trim();
|
|
73
|
-
if (!trimmed || !trimmed.startsWith('data: '))
|
|
74
|
-
continue;
|
|
75
|
-
const payload = trimmed.slice(6);
|
|
76
|
-
if (payload === '[DONE]') {
|
|
77
|
-
yield { type: 'done' };
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
try {
|
|
81
|
-
const chunk = JSON.parse(payload);
|
|
82
|
-
const delta = chunk.choices[0]?.delta?.content;
|
|
83
|
-
if (delta) {
|
|
84
|
-
yield { type: 'text-delta', text: delta };
|
|
85
|
-
}
|
|
86
|
-
if (chunk.choices[0]?.finish_reason) {
|
|
87
|
-
yield {
|
|
88
|
-
type: 'done',
|
|
89
|
-
finishReason: chunk.choices[0].finish_reason,
|
|
90
|
-
usage: chunk.usage ? {
|
|
91
|
-
promptTokens: chunk.usage.prompt_tokens,
|
|
92
|
-
completionTokens: chunk.usage.completion_tokens,
|
|
93
|
-
totalTokens: chunk.usage.total_tokens,
|
|
94
|
-
} : undefined,
|
|
95
|
-
};
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
catch {
|
|
100
|
-
// skip malformed chunks
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
yield { type: 'done' };
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
}
|
|
7
|
+
export { createOpenAICompletionEngine, createGoogleCompletionEngine } from '@a5c-ai/transport-mux';
|
|
108
8
|
//# sourceMappingURL=launch-completion-engine.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"launch-completion-engine.js","sourceRoot":"","sources":["../../src/commands/launch-completion-engine.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"launch-completion-engine.js","sourceRoot":"","sources":["../../src/commands/launch-completion-engine.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,4BAA4B,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"launch.d.ts","sourceRoot":"","sources":["../../src/commands/launch.ts"],"names":[],"mappings":"AAA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