@cmdop/sdk 2.0.0 → 3.0.1
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/LICENSE +21 -0
- package/README.md +17 -119
- package/dist/carriers/carrier.d.ts +40 -0
- package/dist/carriers/carrier.js +16 -0
- package/dist/carriers/http.d.ts +15 -0
- package/dist/carriers/http.js +114 -0
- package/dist/carriers/memory.d.ts +11 -0
- package/dist/carriers/memory.js +35 -0
- package/dist/carriers/ndjson.d.ts +16 -0
- package/dist/carriers/ndjson.js +31 -0
- package/dist/client.d.ts +113 -0
- package/dist/client.js +220 -0
- package/dist/generated/call.gen.d.ts +78 -0
- package/dist/generated/call.gen.js +5 -0
- package/dist/generated/tools.gen.d.ts +1046 -0
- package/dist/generated/tools.gen.js +34 -0
- package/dist/index.d.ts +8 -959
- package/dist/index.js +8 -626
- package/dist/screen.d.ts +19 -0
- package/dist/screen.js +16 -0
- package/dist/vendor.d.ts +52 -0
- package/dist/vendor.js +291 -0
- package/package.json +12 -36
- package/bin/cmdop-core-darwin-arm64 +0 -0
- package/bin/cmdop-core-darwin-x64 +0 -0
- package/bin/cmdop-core-linux-arm64 +0 -0
- package/bin/cmdop-core-linux-x64 +0 -0
- package/bin/cmdop-core-win32-x64.exe +0 -0
- package/dist/index.cjs +0 -647
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -959
- package/dist/index.js.map +0 -1
package/dist/index.cjs
DELETED
|
@@ -1,647 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var fs = require('fs');
|
|
4
|
-
var path = require('path');
|
|
5
|
-
var url = require('url');
|
|
6
|
-
var protobuf = require('@bufbuild/protobuf');
|
|
7
|
-
var codegenv2 = require('@bufbuild/protobuf/codegenv2');
|
|
8
|
-
var child_process = require('child_process');
|
|
9
|
-
var wire = require('@bufbuild/protobuf/wire');
|
|
10
|
-
|
|
11
|
-
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
12
|
-
// src/config.ts
|
|
13
|
-
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
14
|
-
function resolveConfig(opts = {}) {
|
|
15
|
-
const env = typeof process !== "undefined" && process.env ? process.env : {};
|
|
16
|
-
const timeoutMs = opts.timeoutMs ?? (env.CMDOP_TIMEOUT_MS ? Number(env.CMDOP_TIMEOUT_MS) : DEFAULT_TIMEOUT_MS);
|
|
17
|
-
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
18
|
-
throw new Error("timeoutMs must be greater than zero");
|
|
19
|
-
}
|
|
20
|
-
const rawBase = opts.baseUrl ?? env.CMDOP_BASE_URL;
|
|
21
|
-
return {
|
|
22
|
-
token: opts.token ?? env.CMDOP_TOKEN ?? void 0,
|
|
23
|
-
baseUrl: rawBase ? rawBase.replace(/\/+$/, "") : void 0,
|
|
24
|
-
timeoutMs
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
var SUPPORTED_PLATFORMS = /* @__PURE__ */ new Set([
|
|
28
|
-
"darwin-arm64",
|
|
29
|
-
"darwin-x64",
|
|
30
|
-
"linux-x64",
|
|
31
|
-
"linux-arm64",
|
|
32
|
-
"win32-x64"
|
|
33
|
-
]);
|
|
34
|
-
function binaryName() {
|
|
35
|
-
const key = `${process.platform}-${process.arch}`;
|
|
36
|
-
const exe = process.platform === "win32" ? ".exe" : "";
|
|
37
|
-
return `cmdop-core-${key}${exe}`;
|
|
38
|
-
}
|
|
39
|
-
function moduleDir() {
|
|
40
|
-
try {
|
|
41
|
-
const metaUrl = (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href));
|
|
42
|
-
if (metaUrl) return path.dirname(url.fileURLToPath(metaUrl));
|
|
43
|
-
} catch {
|
|
44
|
-
}
|
|
45
|
-
if (typeof __dirname !== "undefined") return __dirname;
|
|
46
|
-
return path.resolve(".");
|
|
47
|
-
}
|
|
48
|
-
function packageBinDir() {
|
|
49
|
-
const here = moduleDir();
|
|
50
|
-
const candidates = [
|
|
51
|
-
path.join(here, "bin"),
|
|
52
|
-
// module sits at package root (unbundled / tests)
|
|
53
|
-
path.join(here, "..", "bin"),
|
|
54
|
-
// module sits in dist/ (the published bundle)
|
|
55
|
-
path.join(here, "..", "..", "bin")
|
|
56
|
-
];
|
|
57
|
-
for (const c of candidates) {
|
|
58
|
-
if (fs.existsSync(c)) return c;
|
|
59
|
-
}
|
|
60
|
-
return path.join(here, "..", "bin");
|
|
61
|
-
}
|
|
62
|
-
function locateBinary() {
|
|
63
|
-
const override = process.env.CMDOP_CORE_BINARY;
|
|
64
|
-
if (override) {
|
|
65
|
-
if (!fs.existsSync(override)) {
|
|
66
|
-
throw new Error(`CMDOP_CORE_BINARY points at a missing file: ${override}`);
|
|
67
|
-
}
|
|
68
|
-
makeExecutable(override);
|
|
69
|
-
return override;
|
|
70
|
-
}
|
|
71
|
-
const key = `${process.platform}-${process.arch}`;
|
|
72
|
-
if (!SUPPORTED_PLATFORMS.has(key)) {
|
|
73
|
-
throw new Error(
|
|
74
|
-
`cmdop-core has no prebuilt binary for ${key}. Set CMDOP_CORE_BINARY to a \`go build -o /path/cmdop-core ./cmd/cmdop-core\` output.`
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
const binPath = path.join(packageBinDir(), binaryName());
|
|
78
|
-
if (!fs.existsSync(binPath)) {
|
|
79
|
-
throw new Error(
|
|
80
|
-
`cmdop-core binary not found at ${binPath}. Reinstall @cmdop/sdk (the 5 baked binaries ship in its bin/ dir), or set CMDOP_CORE_BINARY to a local \`go build\` output.`
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
makeExecutable(binPath);
|
|
84
|
-
return binPath;
|
|
85
|
-
}
|
|
86
|
-
function makeExecutable(path) {
|
|
87
|
-
if (process.platform === "win32") return;
|
|
88
|
-
try {
|
|
89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hoKFkVSUk9SX0NPREVfVU5TVVBQT1JURUQQCxIXChNFUlJPUl9DT0RFX1BST1RPQ09MEAxCtgEKEWNvbS5jbWRvcC5jb3JlLnYyQg1Db250cmFjdFByb3RvUAFaPGdpdGh1Yi5jb20vY21kb3AvY21kb3AvZ28vcGtnL2NvcmVwcm90by9jbWRvcC9jb3JlL3YyO2NvcmV2MqICA0NDWKoCDUNtZG9wLkNvcmUuVjLKAg1DbWRvcFxDb3JlXFYy4gIZQ21kb3BcQ29yZVxWMlxHUEJNZXRhZGF0YeoCD0NtZG9wOjpDb3JlOjpWMmIGcHJvdG8z");
|
|
94
|
-
var EnvelopeSchema = /* @__PURE__ */ codegenv2.messageDesc(file_cmdop_core_v2_contract, 0);
|
|
95
|
-
|
|
96
|
-
// src/resources/base.ts
|
|
97
|
-
var BaseResource = class {
|
|
98
|
-
constructor(client) {
|
|
99
|
-
this.client = client;
|
|
100
|
-
this.t = client._t;
|
|
101
|
-
}
|
|
102
|
-
client;
|
|
103
|
-
t;
|
|
104
|
-
unary(request) {
|
|
105
|
-
return this.t.callUnary(request);
|
|
106
|
-
}
|
|
107
|
-
request(payload) {
|
|
108
|
-
return protobuf.create(EnvelopeSchema, { payload });
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
// src/resources/machines.ts
|
|
113
|
-
var MachinesResource = class extends BaseResource {
|
|
114
|
-
async list() {
|
|
115
|
-
const response = await this.unary(
|
|
116
|
-
this.request({ case: "listMachinesReq", value: {} })
|
|
117
|
-
);
|
|
118
|
-
if (response.payload.case !== "machineRosterSnapshot") {
|
|
119
|
-
throw new Error("cmdop-core returned the wrong roster response arm");
|
|
120
|
-
}
|
|
121
|
-
return response.payload.value;
|
|
122
|
-
}
|
|
123
|
-
ask(machineId, prompt = "", options = {}) {
|
|
124
|
-
const attachmentIds = [...options.attachmentIds ?? []];
|
|
125
|
-
if (!prompt && attachmentIds.length === 0) {
|
|
126
|
-
throw new Error("prompt or at least one attachmentId is required");
|
|
127
|
-
}
|
|
128
|
-
return this.t.callStream(
|
|
129
|
-
this.request({
|
|
130
|
-
case: "askMachineReq",
|
|
131
|
-
value: {
|
|
132
|
-
machineId,
|
|
133
|
-
prompt,
|
|
134
|
-
options: {
|
|
135
|
-
pin: options.pin,
|
|
136
|
-
session: options.session,
|
|
137
|
-
attachmentIds,
|
|
138
|
-
engine: options.engine,
|
|
139
|
-
workingDir: options.workingDir,
|
|
140
|
-
projectRootId: options.projectRootId,
|
|
141
|
-
model: options.model
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
})
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
async messages(machineId, options = {}) {
|
|
148
|
-
if (options.limit !== void 0 && (options.limit < 1 || options.limit > 500)) {
|
|
149
|
-
throw new Error("limit must be between 1 and 500");
|
|
150
|
-
}
|
|
151
|
-
const response = await this.unary(
|
|
152
|
-
this.request({
|
|
153
|
-
case: "listMachineMessagesReq",
|
|
154
|
-
value: { machineId, session: options.session, limit: options.limit }
|
|
155
|
-
})
|
|
156
|
-
);
|
|
157
|
-
if (response.payload.case !== "machineMessageList") {
|
|
158
|
-
throw new Error("cmdop-core returned the wrong messages response arm");
|
|
159
|
-
}
|
|
160
|
-
return response.payload.value;
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
// src/resources/system.ts
|
|
165
|
-
var SystemResource = class extends BaseResource {
|
|
166
|
-
async bootstrap() {
|
|
167
|
-
const response = await this.unary(
|
|
168
|
-
this.request({ case: "systemBootstrapReq", value: {} })
|
|
169
|
-
);
|
|
170
|
-
if (response.payload.case !== "systemBootstrapResp") {
|
|
171
|
-
throw new Error("cmdop-core returned the wrong bootstrap response arm");
|
|
172
|
-
}
|
|
173
|
-
return response.payload.value;
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
// src/errors.ts
|
|
178
|
-
var CmdopError = class extends Error {
|
|
179
|
-
constructor(message, code = "internal", status, retryable = false, details) {
|
|
180
|
-
super(message);
|
|
181
|
-
this.code = code;
|
|
182
|
-
this.status = status;
|
|
183
|
-
this.details = details;
|
|
184
|
-
this.name = new.target.name;
|
|
185
|
-
this.retryable = retryable;
|
|
186
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
187
|
-
}
|
|
188
|
-
code;
|
|
189
|
-
status;
|
|
190
|
-
details;
|
|
191
|
-
retryable;
|
|
192
|
-
};
|
|
193
|
-
var AuthError = class extends CmdopError {
|
|
194
|
-
};
|
|
195
|
-
var PermissionError = class extends CmdopError {
|
|
196
|
-
};
|
|
197
|
-
var NotFoundError = class extends CmdopError {
|
|
198
|
-
};
|
|
199
|
-
var ConflictError = class extends CmdopError {
|
|
200
|
-
};
|
|
201
|
-
var ValidationError = class extends CmdopError {
|
|
202
|
-
};
|
|
203
|
-
var RateLimitError = class extends CmdopError {
|
|
204
|
-
};
|
|
205
|
-
var ServerError = class extends CmdopError {
|
|
206
|
-
};
|
|
207
|
-
var ConnectionError = class extends CmdopError {
|
|
208
|
-
};
|
|
209
|
-
var TimeoutError = class extends ConnectionError {
|
|
210
|
-
};
|
|
211
|
-
var UnavailableError = class extends CmdopError {
|
|
212
|
-
};
|
|
213
|
-
var UnsupportedError = class extends CmdopError {
|
|
214
|
-
};
|
|
215
|
-
var ProtocolError = class extends CmdopError {
|
|
216
|
-
};
|
|
217
|
-
var AgentStreamError = class extends CmdopError {
|
|
218
|
-
};
|
|
219
|
-
var NAMES = {
|
|
220
|
-
[0 /* UNSPECIFIED */]: "unspecified",
|
|
221
|
-
[1 /* INVALID_ARGUMENT */]: "invalid_argument",
|
|
222
|
-
[2 /* UNAUTHENTICATED */]: "unauthenticated",
|
|
223
|
-
[3 /* PERMISSION_DENIED */]: "permission_denied",
|
|
224
|
-
[4 /* NOT_FOUND */]: "not_found",
|
|
225
|
-
[5 /* CONFLICT */]: "conflict",
|
|
226
|
-
[6 /* RATE_LIMITED */]: "rate_limited",
|
|
227
|
-
[7 /* INTERNAL */]: "internal",
|
|
228
|
-
[8 /* UNAVAILABLE */]: "unavailable",
|
|
229
|
-
[9 /* DEADLINE_EXCEEDED */]: "deadline_exceeded",
|
|
230
|
-
[10 /* TRANSPORT */]: "transport",
|
|
231
|
-
[11 /* UNSUPPORTED */]: "unsupported",
|
|
232
|
-
[12 /* PROTOCOL */]: "protocol"
|
|
233
|
-
};
|
|
234
|
-
var TYPES = {
|
|
235
|
-
invalid_argument: ValidationError,
|
|
236
|
-
unauthenticated: AuthError,
|
|
237
|
-
permission_denied: PermissionError,
|
|
238
|
-
not_found: NotFoundError,
|
|
239
|
-
conflict: ConflictError,
|
|
240
|
-
rate_limited: RateLimitError,
|
|
241
|
-
internal: ServerError,
|
|
242
|
-
unavailable: UnavailableError,
|
|
243
|
-
deadline_exceeded: TimeoutError,
|
|
244
|
-
transport: ConnectionError,
|
|
245
|
-
unsupported: UnsupportedError,
|
|
246
|
-
protocol: ProtocolError
|
|
247
|
-
};
|
|
248
|
-
function mapCoreError(info) {
|
|
249
|
-
const code = NAMES[info.code] ?? "internal";
|
|
250
|
-
let details = info.detailsJson;
|
|
251
|
-
if (info.detailsJson) {
|
|
252
|
-
try {
|
|
253
|
-
details = JSON.parse(info.detailsJson);
|
|
254
|
-
} catch {
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
const ErrorType = TYPES[code] ?? CmdopError;
|
|
258
|
-
return new ErrorType(
|
|
259
|
-
info.message || code.replaceAll("_", " "),
|
|
260
|
-
code,
|
|
261
|
-
info.httpStatus,
|
|
262
|
-
info.retryable,
|
|
263
|
-
details
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// src/streaming.ts
|
|
268
|
-
var STREAM_ERROR_NAMES = {
|
|
269
|
-
[0 /* UNSPECIFIED */]: "unspecified",
|
|
270
|
-
[1 /* MACHINE_OFFLINE */]: "machine_offline",
|
|
271
|
-
[2 /* NO_TARGETS */]: "no_targets",
|
|
272
|
-
[3 /* INTERNAL */]: "internal",
|
|
273
|
-
[4 /* PIN_DENIED */]: "pin_denied"
|
|
274
|
-
};
|
|
275
|
-
var AskStream = class {
|
|
276
|
-
constructor(source, timeoutMs) {
|
|
277
|
-
this.source = source;
|
|
278
|
-
this.timeoutMs = timeoutMs;
|
|
279
|
-
}
|
|
280
|
-
source;
|
|
281
|
-
timeoutMs;
|
|
282
|
-
#consumed = false;
|
|
283
|
-
async *[Symbol.asyncIterator]() {
|
|
284
|
-
if (this.#consumed) throw new Error("an AskStream can only be consumed once");
|
|
285
|
-
this.#consumed = true;
|
|
286
|
-
const iterator = this.source.envelopes();
|
|
287
|
-
for (; ; ) {
|
|
288
|
-
const result = await withTimeout(iterator.next(), this.timeoutMs);
|
|
289
|
-
if (result.done) return;
|
|
290
|
-
const env = result.value;
|
|
291
|
-
if (env.kind === 3 /* EVENT */ && env.payload.case === "askEvent") {
|
|
292
|
-
let payload = env.payload.value.payloadJson;
|
|
293
|
-
try {
|
|
294
|
-
payload = JSON.parse(env.payload.value.payloadJson);
|
|
295
|
-
} catch {
|
|
296
|
-
}
|
|
297
|
-
yield {
|
|
298
|
-
type: "event",
|
|
299
|
-
eventType: env.payload.value.eventType,
|
|
300
|
-
payload,
|
|
301
|
-
machineId: env.payload.value.machineId
|
|
302
|
-
};
|
|
303
|
-
} else if (env.kind === 3 /* EVENT */ && env.payload.case === "askStreamError") {
|
|
304
|
-
yield {
|
|
305
|
-
type: "error",
|
|
306
|
-
code: STREAM_ERROR_NAMES[env.payload.value.code] ?? "internal",
|
|
307
|
-
message: env.payload.value.message
|
|
308
|
-
};
|
|
309
|
-
} else if (env.kind === 4 /* DONE */ && env.payload.case === "askDone") {
|
|
310
|
-
const value = env.payload.value;
|
|
311
|
-
yield { type: "done", ...value };
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
async collect() {
|
|
316
|
-
let text = "";
|
|
317
|
-
let streamError;
|
|
318
|
-
for await (const frame of this) {
|
|
319
|
-
if (frame.type === "event") {
|
|
320
|
-
const payload = frame.payload;
|
|
321
|
-
text += payload?.delta ?? payload?.text ?? "";
|
|
322
|
-
} else if (frame.type === "error") {
|
|
323
|
-
streamError = frame;
|
|
324
|
-
} else if (!frame.success) {
|
|
325
|
-
throw new AgentStreamError(
|
|
326
|
-
frame.error ?? streamError?.message ?? "agent run failed",
|
|
327
|
-
streamError?.code ?? "internal",
|
|
328
|
-
frame.upstreamStatus
|
|
329
|
-
);
|
|
330
|
-
} else {
|
|
331
|
-
return frame.text || text;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
return text;
|
|
335
|
-
}
|
|
336
|
-
};
|
|
337
|
-
async function withTimeout(promise, timeoutMs) {
|
|
338
|
-
let timer;
|
|
339
|
-
try {
|
|
340
|
-
return await Promise.race([
|
|
341
|
-
promise,
|
|
342
|
-
new Promise((_, reject) => {
|
|
343
|
-
timer = setTimeout(
|
|
344
|
-
() => reject(new TimeoutError("agent stream timed out", "deadline_exceeded", void 0, true)),
|
|
345
|
-
timeoutMs
|
|
346
|
-
);
|
|
347
|
-
})
|
|
348
|
-
]);
|
|
349
|
-
} finally {
|
|
350
|
-
if (timer) clearTimeout(timer);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
// src/transport.ts
|
|
355
|
-
var MAX_QUEUED_FRAMES = 256;
|
|
356
|
-
var MAX_REQUEST_FRAME_BYTES = 4 * 1024 * 1024;
|
|
357
|
-
var FrameQueue = class {
|
|
358
|
-
#frames = [];
|
|
359
|
-
#wait;
|
|
360
|
-
#done = false;
|
|
361
|
-
#error;
|
|
362
|
-
push(envelope) {
|
|
363
|
-
if (this.#done) return;
|
|
364
|
-
if (this.#wait) {
|
|
365
|
-
const waiter = this.#wait;
|
|
366
|
-
this.#wait = void 0;
|
|
367
|
-
waiter({ value: envelope, done: false });
|
|
368
|
-
return;
|
|
369
|
-
}
|
|
370
|
-
if (this.#frames.length >= MAX_QUEUED_FRAMES) {
|
|
371
|
-
this.fail(new ConnectionError("agent stream consumer is too slow", "transport"));
|
|
372
|
-
return;
|
|
373
|
-
}
|
|
374
|
-
this.#frames.push(envelope);
|
|
375
|
-
}
|
|
376
|
-
end() {
|
|
377
|
-
this.#done = true;
|
|
378
|
-
this.#wakeDone();
|
|
379
|
-
}
|
|
380
|
-
fail(error) {
|
|
381
|
-
this.#error = error;
|
|
382
|
-
this.#done = true;
|
|
383
|
-
this.#wakeDone();
|
|
384
|
-
}
|
|
385
|
-
#wakeDone() {
|
|
386
|
-
if (this.#wait) {
|
|
387
|
-
const waiter = this.#wait;
|
|
388
|
-
this.#wait = void 0;
|
|
389
|
-
waiter({ value: void 0, done: true });
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
async *iterate() {
|
|
393
|
-
for (; ; ) {
|
|
394
|
-
if (this.#error) throw this.#error;
|
|
395
|
-
if (this.#frames.length) {
|
|
396
|
-
yield this.#frames.shift();
|
|
397
|
-
continue;
|
|
398
|
-
}
|
|
399
|
-
if (this.#done) return;
|
|
400
|
-
const result = await new Promise((resolve2) => {
|
|
401
|
-
this.#wait = resolve2;
|
|
402
|
-
});
|
|
403
|
-
if (this.#error) throw this.#error;
|
|
404
|
-
if (result.done) return;
|
|
405
|
-
yield result.value;
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
};
|
|
409
|
-
var Transport = class {
|
|
410
|
-
constructor(config, binaryPath) {
|
|
411
|
-
this.config = config;
|
|
412
|
-
this.binaryPath = binaryPath;
|
|
413
|
-
}
|
|
414
|
-
config;
|
|
415
|
-
binaryPath;
|
|
416
|
-
#child;
|
|
417
|
-
#stdin;
|
|
418
|
-
#pending = /* @__PURE__ */ new Map();
|
|
419
|
-
#nextId = 1n;
|
|
420
|
-
#closed = false;
|
|
421
|
-
#starting;
|
|
422
|
-
/** @internal test seam */
|
|
423
|
-
attachStreamsForTest(stdin, stdout) {
|
|
424
|
-
this.#stdin = stdin;
|
|
425
|
-
this.#child = { stdin };
|
|
426
|
-
this.#startReader(stdout);
|
|
427
|
-
}
|
|
428
|
-
async #ensureStarted() {
|
|
429
|
-
if (this.#child) return;
|
|
430
|
-
if (this.#starting) return this.#starting;
|
|
431
|
-
this.#starting = this.#spawn();
|
|
432
|
-
try {
|
|
433
|
-
await this.#starting;
|
|
434
|
-
} finally {
|
|
435
|
-
this.#starting = void 0;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
async #spawn() {
|
|
439
|
-
const env = { ...process.env };
|
|
440
|
-
if (this.config.token) env.CMDOP_TOKEN = this.config.token;
|
|
441
|
-
else delete env.CMDOP_TOKEN;
|
|
442
|
-
if (this.config.baseUrl) env.CMDOP_BASE_URL = this.config.baseUrl;
|
|
443
|
-
else delete env.CMDOP_BASE_URL;
|
|
444
|
-
const child = child_process.spawn(this.binaryPath, ["--stdio"], {
|
|
445
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
446
|
-
env,
|
|
447
|
-
windowsHide: true
|
|
448
|
-
});
|
|
449
|
-
this.#child = child;
|
|
450
|
-
this.#stdin = child.stdin;
|
|
451
|
-
child.stderr.on("data", () => {
|
|
452
|
-
});
|
|
453
|
-
child.on("exit", () => this.#failAll(new ConnectionError("cmdop-core exited", "transport")));
|
|
454
|
-
child.on(
|
|
455
|
-
"error",
|
|
456
|
-
(error) => this.#failAll(new ConnectionError(`cmdop-core spawn failed: ${error.message}`, "transport"))
|
|
457
|
-
);
|
|
458
|
-
this.#startReader(child.stdout);
|
|
459
|
-
}
|
|
460
|
-
#startReader(stdout) {
|
|
461
|
-
void (async () => {
|
|
462
|
-
try {
|
|
463
|
-
for await (const envelope of wire.sizeDelimitedDecodeStream(EnvelopeSchema, stdout)) {
|
|
464
|
-
this.#dispatch(envelope);
|
|
465
|
-
}
|
|
466
|
-
this.#failAll(new ConnectionError("cmdop-core stdout closed", "transport"));
|
|
467
|
-
} catch (error) {
|
|
468
|
-
this.#failAll(
|
|
469
|
-
new ConnectionError(
|
|
470
|
-
`core read failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
471
|
-
"transport"
|
|
472
|
-
)
|
|
473
|
-
);
|
|
474
|
-
}
|
|
475
|
-
})();
|
|
476
|
-
}
|
|
477
|
-
#dispatch(envelope) {
|
|
478
|
-
const pending = this.#pending.get(envelope.id);
|
|
479
|
-
if (!pending) return;
|
|
480
|
-
if (pending.kind === "unary") {
|
|
481
|
-
if (envelope.kind === 2 /* RESPONSE */) {
|
|
482
|
-
this.#pending.delete(envelope.id);
|
|
483
|
-
clearTimeout(pending.timer);
|
|
484
|
-
pending.resolve(envelope);
|
|
485
|
-
} else if (envelope.kind === 5 /* ERROR */ && envelope.payload.case === "error") {
|
|
486
|
-
this.#pending.delete(envelope.id);
|
|
487
|
-
clearTimeout(pending.timer);
|
|
488
|
-
pending.reject(mapCoreError(envelope.payload.value));
|
|
489
|
-
}
|
|
490
|
-
return;
|
|
491
|
-
}
|
|
492
|
-
if (envelope.kind === 3 /* EVENT */) {
|
|
493
|
-
pending.queue.push(envelope);
|
|
494
|
-
} else if (envelope.kind === 4 /* DONE */) {
|
|
495
|
-
this.#pending.delete(envelope.id);
|
|
496
|
-
pending.queue.push(envelope);
|
|
497
|
-
pending.queue.end();
|
|
498
|
-
} else if (envelope.kind === 5 /* ERROR */ && envelope.payload.case === "error") {
|
|
499
|
-
this.#pending.delete(envelope.id);
|
|
500
|
-
pending.queue.fail(mapCoreError(envelope.payload.value));
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
#failAll(error) {
|
|
504
|
-
const pending = this.#pending;
|
|
505
|
-
this.#pending = /* @__PURE__ */ new Map();
|
|
506
|
-
for (const call of pending.values()) {
|
|
507
|
-
if (call.kind === "unary") {
|
|
508
|
-
clearTimeout(call.timer);
|
|
509
|
-
call.reject(error);
|
|
510
|
-
} else {
|
|
511
|
-
call.queue.fail(error);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
#write(envelope) {
|
|
516
|
-
if (!this.#stdin) throw new ConnectionError("cmdop-core is not running", "transport");
|
|
517
|
-
if (protobuf.toBinary(EnvelopeSchema, envelope).byteLength > MAX_REQUEST_FRAME_BYTES) {
|
|
518
|
-
throw new ConnectionError(
|
|
519
|
-
`request frame exceeds ${MAX_REQUEST_FRAME_BYTES} bytes`,
|
|
520
|
-
"transport"
|
|
521
|
-
);
|
|
522
|
-
}
|
|
523
|
-
this.#stdin.write(wire.sizeDelimitedEncode(EnvelopeSchema, envelope));
|
|
524
|
-
}
|
|
525
|
-
async callUnary(request) {
|
|
526
|
-
await this.#ensureStarted();
|
|
527
|
-
request.id = this.#nextId++;
|
|
528
|
-
request.kind = 1 /* REQUEST */;
|
|
529
|
-
return new Promise((resolve2, reject) => {
|
|
530
|
-
const timer = setTimeout(() => {
|
|
531
|
-
this.#pending.delete(request.id);
|
|
532
|
-
reject(new TimeoutError("cmdop-core request timed out", "deadline_exceeded", void 0, true));
|
|
533
|
-
}, this.config.timeoutMs);
|
|
534
|
-
this.#pending.set(request.id, { kind: "unary", resolve: resolve2, reject, timer });
|
|
535
|
-
try {
|
|
536
|
-
this.#write(request);
|
|
537
|
-
} catch (error) {
|
|
538
|
-
clearTimeout(timer);
|
|
539
|
-
this.#pending.delete(request.id);
|
|
540
|
-
reject(error);
|
|
541
|
-
}
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
callStream(request) {
|
|
545
|
-
const transport = this;
|
|
546
|
-
let started = false;
|
|
547
|
-
const source = {
|
|
548
|
-
async *envelopes() {
|
|
549
|
-
if (started) throw new Error("an AskStream can only be consumed once");
|
|
550
|
-
started = true;
|
|
551
|
-
await transport.#ensureStarted();
|
|
552
|
-
request.id = transport.#nextId++;
|
|
553
|
-
request.kind = 1 /* REQUEST */;
|
|
554
|
-
const queue = new FrameQueue();
|
|
555
|
-
transport.#pending.set(request.id, { kind: "stream", queue });
|
|
556
|
-
try {
|
|
557
|
-
transport.#write(request);
|
|
558
|
-
yield* queue.iterate();
|
|
559
|
-
} finally {
|
|
560
|
-
transport.#pending.delete(request.id);
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
};
|
|
564
|
-
return new AskStream(source, this.config.timeoutMs);
|
|
565
|
-
}
|
|
566
|
-
async close() {
|
|
567
|
-
if (this.#closed) return;
|
|
568
|
-
this.#closed = true;
|
|
569
|
-
const child = this.#child;
|
|
570
|
-
if (!child) return;
|
|
571
|
-
this.#stdin?.end();
|
|
572
|
-
if (typeof child.once === "function" && typeof child.kill === "function") {
|
|
573
|
-
await new Promise((resolve2) => {
|
|
574
|
-
let finished = false;
|
|
575
|
-
const done = () => {
|
|
576
|
-
if (!finished) {
|
|
577
|
-
finished = true;
|
|
578
|
-
resolve2();
|
|
579
|
-
}
|
|
580
|
-
};
|
|
581
|
-
child.once("exit", done);
|
|
582
|
-
setTimeout(() => {
|
|
583
|
-
if (!finished) child.kill();
|
|
584
|
-
done();
|
|
585
|
-
}, 5e3);
|
|
586
|
-
});
|
|
587
|
-
}
|
|
588
|
-
this.#failAll(new ConnectionError("client closed", "transport"));
|
|
589
|
-
}
|
|
590
|
-
};
|
|
591
|
-
|
|
592
|
-
// src/client.ts
|
|
593
|
-
var Client = class _Client {
|
|
594
|
-
config;
|
|
595
|
-
/** @internal */
|
|
596
|
-
_t;
|
|
597
|
-
constructor(opts = {}) {
|
|
598
|
-
const resolved = typeof opts === "string" ? { token: opts } : opts;
|
|
599
|
-
this.config = resolveConfig(resolved);
|
|
600
|
-
this._t = new Transport(this.config, resolved.binaryPath ?? locateBinary());
|
|
601
|
-
}
|
|
602
|
-
static fromEnv() {
|
|
603
|
-
return new _Client();
|
|
604
|
-
}
|
|
605
|
-
get baseUrl() {
|
|
606
|
-
return this.config.baseUrl;
|
|
607
|
-
}
|
|
608
|
-
#system;
|
|
609
|
-
get system() {
|
|
610
|
-
return this.#system ??= new SystemResource(this);
|
|
611
|
-
}
|
|
612
|
-
#machines;
|
|
613
|
-
get machines() {
|
|
614
|
-
return this.#machines ??= new MachinesResource(this);
|
|
615
|
-
}
|
|
616
|
-
async close() {
|
|
617
|
-
await this._t.close();
|
|
618
|
-
}
|
|
619
|
-
async [Symbol.asyncDispose]() {
|
|
620
|
-
await this.close();
|
|
621
|
-
}
|
|
622
|
-
};
|
|
623
|
-
|
|
624
|
-
// src/types.ts
|
|
625
|
-
var types_exports = {};
|
|
626
|
-
|
|
627
|
-
exports.AgentStreamError = AgentStreamError;
|
|
628
|
-
exports.AskStream = AskStream;
|
|
629
|
-
exports.AuthError = AuthError;
|
|
630
|
-
exports.Client = Client;
|
|
631
|
-
exports.CmdopError = CmdopError;
|
|
632
|
-
exports.ConflictError = ConflictError;
|
|
633
|
-
exports.ConnectionError = ConnectionError;
|
|
634
|
-
exports.DEFAULT_TIMEOUT_MS = DEFAULT_TIMEOUT_MS;
|
|
635
|
-
exports.NotFoundError = NotFoundError;
|
|
636
|
-
exports.PermissionError = PermissionError;
|
|
637
|
-
exports.ProtocolError = ProtocolError;
|
|
638
|
-
exports.RateLimitError = RateLimitError;
|
|
639
|
-
exports.ServerError = ServerError;
|
|
640
|
-
exports.TimeoutError = TimeoutError;
|
|
641
|
-
exports.UnavailableError = UnavailableError;
|
|
642
|
-
exports.UnsupportedError = UnsupportedError;
|
|
643
|
-
exports.ValidationError = ValidationError;
|
|
644
|
-
exports.resolveConfig = resolveConfig;
|
|
645
|
-
exports.types = types_exports;
|
|
646
|
-
//# sourceMappingURL=index.cjs.map
|
|
647
|
-
//# sourceMappingURL=index.cjs.map
|