@powerformer/refly-cli 0.1.13 → 0.1.15
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/bin/refly.js +2842 -2043
- package/dist/bin/refly.js.map +1 -1
- package/dist/index.d.ts +1 -370
- package/dist/index.js +64 -329
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
- package/skill/SKILL.md +21 -18
- package/skill/references/file.md +21 -9
- package/skill/references/node.md +64 -40
- package/skill/references/skill.md +376 -31
- package/skill/references/workflow.md +136 -43
package/dist/index.js
CHANGED
|
@@ -32,23 +32,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
32
32
|
var src_exports = {};
|
|
33
33
|
__export(src_exports, {
|
|
34
34
|
AuthError: () => AuthError,
|
|
35
|
-
BuilderError: () => BuilderError,
|
|
36
35
|
CLIError: () => CLIError,
|
|
37
36
|
ErrorCodes: () => ErrorCodes,
|
|
38
37
|
ValidationError: () => ValidationError,
|
|
39
38
|
apiRequest: () => apiRequest,
|
|
40
|
-
createSession: () => createSession,
|
|
41
|
-
generateGraph: () => generateGraph,
|
|
42
39
|
getApiEndpoint: () => getApiEndpoint,
|
|
43
|
-
getCurrentSession: () => getCurrentSession,
|
|
44
40
|
installSkill: () => installSkill,
|
|
45
41
|
isAuthenticated: () => isAuthenticated,
|
|
46
42
|
isSkillInstalled: () => isSkillInstalled,
|
|
47
43
|
loadConfig: () => loadConfig,
|
|
48
|
-
loadSession: () => loadSession,
|
|
49
44
|
saveConfig: () => saveConfig,
|
|
50
|
-
saveSession: () => saveSession,
|
|
51
|
-
validateDraft: () => validateDraft,
|
|
52
45
|
verifyConnection: () => verifyConnection
|
|
53
46
|
});
|
|
54
47
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -167,8 +160,6 @@ var AuthError = class extends CLIError {
|
|
|
167
160
|
super(ErrorCodes.AUTH_REQUIRED, message, void 0, hint ?? "refly login");
|
|
168
161
|
}
|
|
169
162
|
};
|
|
170
|
-
var BuilderError = class extends CLIError {
|
|
171
|
-
};
|
|
172
163
|
var ValidationError = class extends CLIError {
|
|
173
164
|
constructor(message, details) {
|
|
174
165
|
super(ErrorCodes.VALIDATION_ERROR, message, details, "Fix validation errors and retry");
|
|
@@ -180,46 +171,12 @@ var NetworkError = class extends CLIError {
|
|
|
180
171
|
}
|
|
181
172
|
};
|
|
182
173
|
|
|
183
|
-
// src/
|
|
174
|
+
// src/config/config.ts
|
|
184
175
|
var fs2 = __toESM(require("fs"));
|
|
185
176
|
var path2 = __toESM(require("path"));
|
|
177
|
+
var os2 = __toESM(require("os"));
|
|
186
178
|
var crypto = __toESM(require("crypto"));
|
|
187
179
|
|
|
188
|
-
// src/config/paths.ts
|
|
189
|
-
var os = __toESM(require("os"));
|
|
190
|
-
var path = __toESM(require("path"));
|
|
191
|
-
var fs = __toESM(require("fs"));
|
|
192
|
-
function getReflyDir() {
|
|
193
|
-
const dir = path.join(os.homedir(), ".refly");
|
|
194
|
-
ensureDir(dir);
|
|
195
|
-
return dir;
|
|
196
|
-
}
|
|
197
|
-
function getBuilderDir() {
|
|
198
|
-
const dir = path.join(getReflyDir(), "builder");
|
|
199
|
-
ensureDir(dir);
|
|
200
|
-
return dir;
|
|
201
|
-
}
|
|
202
|
-
function getClaudeSkillDir() {
|
|
203
|
-
return path.join(os.homedir(), ".claude", "skills", "refly");
|
|
204
|
-
}
|
|
205
|
-
function getClaudeCommandsDir() {
|
|
206
|
-
return path.join(os.homedir(), ".claude", "commands");
|
|
207
|
-
}
|
|
208
|
-
function ensureDir(dir) {
|
|
209
|
-
if (!fs.existsSync(dir)) {
|
|
210
|
-
fs.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
function getConfigPath() {
|
|
214
|
-
return path.join(getReflyDir(), "config.json");
|
|
215
|
-
}
|
|
216
|
-
function getCurrentSessionPath() {
|
|
217
|
-
return path.join(getBuilderDir(), "current");
|
|
218
|
-
}
|
|
219
|
-
function getSessionPath(sessionId) {
|
|
220
|
-
return path.join(getBuilderDir(), `session-${sessionId}.json`);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
180
|
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
|
|
224
181
|
var external_exports = {};
|
|
225
182
|
__export(external_exports, {
|
|
@@ -4261,276 +4218,31 @@ var coerce = {
|
|
|
4261
4218
|
};
|
|
4262
4219
|
var NEVER = INVALID;
|
|
4263
4220
|
|
|
4264
|
-
// src/
|
|
4265
|
-
var
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4269
|
-
|
|
4270
|
-
|
|
4271
|
-
|
|
4272
|
-
name: external_exports.string().min(1),
|
|
4273
|
-
description: external_exports.string().optional(),
|
|
4274
|
-
nodes: external_exports.array(NodeSchema).default([]),
|
|
4275
|
-
metadata: external_exports.object({
|
|
4276
|
-
tags: external_exports.array(external_exports.string()).optional(),
|
|
4277
|
-
owner: external_exports.string().optional()
|
|
4278
|
-
}).optional()
|
|
4279
|
-
});
|
|
4280
|
-
var ValidationResultSchema = external_exports.object({
|
|
4281
|
-
ok: external_exports.boolean(),
|
|
4282
|
-
errors: external_exports.array(
|
|
4283
|
-
external_exports.object({
|
|
4284
|
-
code: external_exports.string(),
|
|
4285
|
-
message: external_exports.string(),
|
|
4286
|
-
nodeId: external_exports.string().optional(),
|
|
4287
|
-
details: external_exports.record(external_exports.unknown()).optional()
|
|
4288
|
-
})
|
|
4289
|
-
).default([])
|
|
4290
|
-
});
|
|
4291
|
-
var BuilderState = {
|
|
4292
|
-
IDLE: "IDLE",
|
|
4293
|
-
DRAFT: "DRAFT",
|
|
4294
|
-
VALIDATED: "VALIDATED",
|
|
4295
|
-
COMMITTED: "COMMITTED",
|
|
4296
|
-
ABORTED: "ABORTED"
|
|
4297
|
-
};
|
|
4298
|
-
var CommitInfoSchema = external_exports.object({
|
|
4299
|
-
workflowId: external_exports.string().optional(),
|
|
4300
|
-
committedAt: external_exports.string().optional()
|
|
4301
|
-
});
|
|
4302
|
-
var BuilderSessionSchema = external_exports.object({
|
|
4303
|
-
id: external_exports.string(),
|
|
4304
|
-
version: external_exports.number().default(1),
|
|
4305
|
-
state: external_exports.enum(["IDLE", "DRAFT", "VALIDATED", "COMMITTED", "ABORTED"]),
|
|
4306
|
-
createdAt: external_exports.string(),
|
|
4307
|
-
updatedAt: external_exports.string(),
|
|
4308
|
-
workflowDraft: WorkflowDraftSchema,
|
|
4309
|
-
validation: ValidationResultSchema.default({ ok: false, errors: [] }),
|
|
4310
|
-
commit: CommitInfoSchema.optional()
|
|
4311
|
-
});
|
|
4312
|
-
|
|
4313
|
-
// src/builder/store.ts
|
|
4314
|
-
function generateSessionId() {
|
|
4315
|
-
return crypto.randomUUID();
|
|
4316
|
-
}
|
|
4317
|
-
function createSession(name, description) {
|
|
4318
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
4319
|
-
const session = {
|
|
4320
|
-
id: generateSessionId(),
|
|
4321
|
-
version: 1,
|
|
4322
|
-
state: BuilderState.DRAFT,
|
|
4323
|
-
createdAt: now,
|
|
4324
|
-
updatedAt: now,
|
|
4325
|
-
workflowDraft: {
|
|
4326
|
-
name,
|
|
4327
|
-
description,
|
|
4328
|
-
nodes: []
|
|
4329
|
-
},
|
|
4330
|
-
validation: { ok: false, errors: [] }
|
|
4331
|
-
};
|
|
4332
|
-
return session;
|
|
4333
|
-
}
|
|
4334
|
-
function saveSession(session) {
|
|
4335
|
-
const sessionPath = getSessionPath(session.id);
|
|
4336
|
-
const tempPath = path2.join(getBuilderDir(), `.session-${session.id}-${Date.now()}.tmp`);
|
|
4337
|
-
session.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
4338
|
-
const validated = BuilderSessionSchema.parse(session);
|
|
4339
|
-
fs2.writeFileSync(tempPath, JSON.stringify(validated, null, 2), {
|
|
4340
|
-
mode: 384
|
|
4341
|
-
});
|
|
4342
|
-
fs2.renameSync(tempPath, sessionPath);
|
|
4343
|
-
}
|
|
4344
|
-
function loadSession(sessionId) {
|
|
4345
|
-
const sessionPath = getSessionPath(sessionId);
|
|
4346
|
-
try {
|
|
4347
|
-
if (!fs2.existsSync(sessionPath)) {
|
|
4348
|
-
return null;
|
|
4349
|
-
}
|
|
4350
|
-
const content = fs2.readFileSync(sessionPath, "utf-8");
|
|
4351
|
-
const parsed = JSON.parse(content);
|
|
4352
|
-
return BuilderSessionSchema.parse(parsed);
|
|
4353
|
-
} catch {
|
|
4354
|
-
return null;
|
|
4355
|
-
}
|
|
4356
|
-
}
|
|
4357
|
-
function getCurrentSessionId() {
|
|
4358
|
-
const currentPath = getCurrentSessionPath();
|
|
4359
|
-
try {
|
|
4360
|
-
if (!fs2.existsSync(currentPath)) {
|
|
4361
|
-
return null;
|
|
4362
|
-
}
|
|
4363
|
-
return fs2.readFileSync(currentPath, "utf-8").trim();
|
|
4364
|
-
} catch {
|
|
4365
|
-
return null;
|
|
4366
|
-
}
|
|
4221
|
+
// src/config/paths.ts
|
|
4222
|
+
var os = __toESM(require("os"));
|
|
4223
|
+
var path = __toESM(require("path"));
|
|
4224
|
+
var fs = __toESM(require("fs"));
|
|
4225
|
+
function getReflyDir() {
|
|
4226
|
+
const dir = path.join(os.homedir(), ".refly");
|
|
4227
|
+
ensureDir(dir);
|
|
4228
|
+
return dir;
|
|
4367
4229
|
}
|
|
4368
|
-
function
|
|
4369
|
-
|
|
4370
|
-
if (!sessionId) return null;
|
|
4371
|
-
return loadSession(sessionId);
|
|
4230
|
+
function getClaudeSkillDir() {
|
|
4231
|
+
return path.join(os.homedir(), ".claude", "skills", "refly");
|
|
4372
4232
|
}
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
function validateDraft(session) {
|
|
4376
|
-
const errors = [];
|
|
4377
|
-
const nodes = session.workflowDraft.nodes;
|
|
4378
|
-
if (!session.workflowDraft.name || session.workflowDraft.name.trim() === "") {
|
|
4379
|
-
errors.push({
|
|
4380
|
-
code: "MISSING_NAME",
|
|
4381
|
-
message: "Workflow name is required"
|
|
4382
|
-
});
|
|
4383
|
-
}
|
|
4384
|
-
if (nodes.length === 0) {
|
|
4385
|
-
errors.push({
|
|
4386
|
-
code: "EMPTY_WORKFLOW",
|
|
4387
|
-
message: "Workflow must have at least one node"
|
|
4388
|
-
});
|
|
4389
|
-
}
|
|
4390
|
-
const nodeIds = /* @__PURE__ */ new Set();
|
|
4391
|
-
for (const node of nodes) {
|
|
4392
|
-
if (nodeIds.has(node.id)) {
|
|
4393
|
-
errors.push({
|
|
4394
|
-
code: "DUPLICATE_NODE_ID",
|
|
4395
|
-
message: `Duplicate node ID: ${node.id}`,
|
|
4396
|
-
nodeId: node.id
|
|
4397
|
-
});
|
|
4398
|
-
}
|
|
4399
|
-
nodeIds.add(node.id);
|
|
4400
|
-
}
|
|
4401
|
-
for (const node of nodes) {
|
|
4402
|
-
if (!node.id || node.id.trim() === "") {
|
|
4403
|
-
errors.push({
|
|
4404
|
-
code: "MISSING_NODE_ID",
|
|
4405
|
-
message: "Node ID is required",
|
|
4406
|
-
details: { node }
|
|
4407
|
-
});
|
|
4408
|
-
}
|
|
4409
|
-
if (!node.type || node.type.trim() === "") {
|
|
4410
|
-
errors.push({
|
|
4411
|
-
code: "MISSING_NODE_TYPE",
|
|
4412
|
-
message: "Node type is required",
|
|
4413
|
-
nodeId: node.id
|
|
4414
|
-
});
|
|
4415
|
-
}
|
|
4416
|
-
}
|
|
4417
|
-
for (const node of nodes) {
|
|
4418
|
-
for (const depId of node.dependsOn) {
|
|
4419
|
-
if (!nodeIds.has(depId)) {
|
|
4420
|
-
errors.push({
|
|
4421
|
-
code: "MISSING_DEPENDENCY",
|
|
4422
|
-
message: `Node "${node.id}" depends on non-existent node "${depId}"`,
|
|
4423
|
-
nodeId: node.id,
|
|
4424
|
-
details: { missingDep: depId }
|
|
4425
|
-
});
|
|
4426
|
-
}
|
|
4427
|
-
if (depId === node.id) {
|
|
4428
|
-
errors.push({
|
|
4429
|
-
code: "SELF_REFERENCE",
|
|
4430
|
-
message: `Node "${node.id}" cannot depend on itself`,
|
|
4431
|
-
nodeId: node.id
|
|
4432
|
-
});
|
|
4433
|
-
}
|
|
4434
|
-
}
|
|
4435
|
-
}
|
|
4436
|
-
const cycleResult = detectCycles(nodes);
|
|
4437
|
-
if (cycleResult.hasCycle) {
|
|
4438
|
-
errors.push({
|
|
4439
|
-
code: "CYCLE_DETECTED",
|
|
4440
|
-
message: `Circular dependency detected: ${cycleResult.cycle?.join(" -> ")}`,
|
|
4441
|
-
details: { cycle: cycleResult.cycle }
|
|
4442
|
-
});
|
|
4443
|
-
}
|
|
4444
|
-
const result = {
|
|
4445
|
-
ok: errors.length === 0,
|
|
4446
|
-
errors
|
|
4447
|
-
};
|
|
4448
|
-
session.validation = result;
|
|
4449
|
-
if (result.ok && session.state === BuilderState.DRAFT) {
|
|
4450
|
-
session.state = BuilderState.VALIDATED;
|
|
4451
|
-
}
|
|
4452
|
-
saveSession(session);
|
|
4453
|
-
return result;
|
|
4233
|
+
function getClaudeCommandsDir() {
|
|
4234
|
+
return path.join(os.homedir(), ".claude", "commands");
|
|
4454
4235
|
}
|
|
4455
|
-
function
|
|
4456
|
-
|
|
4457
|
-
|
|
4458
|
-
nodeMap.set(node.id, node);
|
|
4459
|
-
}
|
|
4460
|
-
const visited = /* @__PURE__ */ new Set();
|
|
4461
|
-
const recursionStack = /* @__PURE__ */ new Set();
|
|
4462
|
-
const path6 = [];
|
|
4463
|
-
function dfs(nodeId) {
|
|
4464
|
-
if (recursionStack.has(nodeId)) {
|
|
4465
|
-
const cycleStart = path6.indexOf(nodeId);
|
|
4466
|
-
return [...path6.slice(cycleStart), nodeId];
|
|
4467
|
-
}
|
|
4468
|
-
if (visited.has(nodeId)) {
|
|
4469
|
-
return null;
|
|
4470
|
-
}
|
|
4471
|
-
visited.add(nodeId);
|
|
4472
|
-
recursionStack.add(nodeId);
|
|
4473
|
-
path6.push(nodeId);
|
|
4474
|
-
const node = nodeMap.get(nodeId);
|
|
4475
|
-
if (node) {
|
|
4476
|
-
for (const depId of node.dependsOn) {
|
|
4477
|
-
const cycle = dfs(depId);
|
|
4478
|
-
if (cycle) {
|
|
4479
|
-
return cycle;
|
|
4480
|
-
}
|
|
4481
|
-
}
|
|
4482
|
-
}
|
|
4483
|
-
path6.pop();
|
|
4484
|
-
recursionStack.delete(nodeId);
|
|
4485
|
-
return null;
|
|
4486
|
-
}
|
|
4487
|
-
for (const node of nodes) {
|
|
4488
|
-
const cycle = dfs(node.id);
|
|
4489
|
-
if (cycle) {
|
|
4490
|
-
return { hasCycle: true, cycle };
|
|
4491
|
-
}
|
|
4236
|
+
function ensureDir(dir) {
|
|
4237
|
+
if (!fs.existsSync(dir)) {
|
|
4238
|
+
fs.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
4492
4239
|
}
|
|
4493
|
-
return { hasCycle: false };
|
|
4494
4240
|
}
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
function generateGraph(session) {
|
|
4498
|
-
const nodes = session.workflowDraft.nodes;
|
|
4499
|
-
const edges = [];
|
|
4500
|
-
for (const node of nodes) {
|
|
4501
|
-
for (const depId of node.dependsOn) {
|
|
4502
|
-
edges.push({ from: depId, to: node.id });
|
|
4503
|
-
}
|
|
4504
|
-
}
|
|
4505
|
-
const rootNodes = nodes.filter((n) => n.dependsOn.length === 0).map((n) => n.id);
|
|
4506
|
-
const hasDependent = /* @__PURE__ */ new Set();
|
|
4507
|
-
for (const node of nodes) {
|
|
4508
|
-
for (const depId of node.dependsOn) {
|
|
4509
|
-
hasDependent.add(depId);
|
|
4510
|
-
}
|
|
4511
|
-
}
|
|
4512
|
-
const leafNodes = nodes.filter((n) => !hasDependent.has(n.id)).map((n) => n.id);
|
|
4513
|
-
return {
|
|
4514
|
-
nodes: nodes.map((n) => ({
|
|
4515
|
-
id: n.id,
|
|
4516
|
-
type: n.type,
|
|
4517
|
-
dependsOn: n.dependsOn
|
|
4518
|
-
})),
|
|
4519
|
-
edges,
|
|
4520
|
-
stats: {
|
|
4521
|
-
nodeCount: nodes.length,
|
|
4522
|
-
edgeCount: edges.length,
|
|
4523
|
-
rootNodes,
|
|
4524
|
-
leafNodes
|
|
4525
|
-
}
|
|
4526
|
-
};
|
|
4241
|
+
function getConfigPath() {
|
|
4242
|
+
return path.join(getReflyDir(), "config.json");
|
|
4527
4243
|
}
|
|
4528
4244
|
|
|
4529
4245
|
// src/config/config.ts
|
|
4530
|
-
var fs3 = __toESM(require("fs"));
|
|
4531
|
-
var path3 = __toESM(require("path"));
|
|
4532
|
-
var os2 = __toESM(require("os"));
|
|
4533
|
-
var crypto2 = __toESM(require("crypto"));
|
|
4534
4246
|
var ConfigSchema = external_exports.object({
|
|
4535
4247
|
version: external_exports.number().default(1),
|
|
4536
4248
|
auth: external_exports.object({
|
|
@@ -4570,10 +4282,10 @@ var DEFAULT_CONFIG = {
|
|
|
4570
4282
|
function loadConfig() {
|
|
4571
4283
|
const configPath = getConfigPath();
|
|
4572
4284
|
try {
|
|
4573
|
-
if (!
|
|
4285
|
+
if (!fs2.existsSync(configPath)) {
|
|
4574
4286
|
return DEFAULT_CONFIG;
|
|
4575
4287
|
}
|
|
4576
|
-
const content =
|
|
4288
|
+
const content = fs2.readFileSync(configPath, "utf-8");
|
|
4577
4289
|
const parsed = JSON.parse(content);
|
|
4578
4290
|
return ConfigSchema.parse(parsed);
|
|
4579
4291
|
} catch {
|
|
@@ -4582,15 +4294,15 @@ function loadConfig() {
|
|
|
4582
4294
|
}
|
|
4583
4295
|
function saveConfig(config) {
|
|
4584
4296
|
const configPath = getConfigPath();
|
|
4585
|
-
const tempPath =
|
|
4297
|
+
const tempPath = path2.join(getReflyDir(), `.config-${crypto.randomUUID()}.tmp`);
|
|
4586
4298
|
const validated = ConfigSchema.parse(config);
|
|
4587
|
-
|
|
4299
|
+
fs2.writeFileSync(tempPath, JSON.stringify(validated, null, 2), {
|
|
4588
4300
|
mode: 384
|
|
4589
4301
|
// Owner read/write only
|
|
4590
4302
|
});
|
|
4591
|
-
|
|
4303
|
+
fs2.renameSync(tempPath, configPath);
|
|
4592
4304
|
if (os2.platform() !== "win32") {
|
|
4593
|
-
|
|
4305
|
+
fs2.chmodSync(configPath, 384);
|
|
4594
4306
|
}
|
|
4595
4307
|
}
|
|
4596
4308
|
function getApiEndpoint(override) {
|
|
@@ -4657,9 +4369,15 @@ function getApiKey() {
|
|
|
4657
4369
|
return config.auth?.apiKey;
|
|
4658
4370
|
}
|
|
4659
4371
|
|
|
4660
|
-
// src/
|
|
4372
|
+
// src/api/client.ts
|
|
4661
4373
|
var fs4 = __toESM(require("fs"));
|
|
4374
|
+
var import_node_fs = require("fs");
|
|
4662
4375
|
var path4 = __toESM(require("path"));
|
|
4376
|
+
var import_mime = __toESM(require("mime"));
|
|
4377
|
+
|
|
4378
|
+
// src/utils/logger.ts
|
|
4379
|
+
var fs3 = __toESM(require("fs"));
|
|
4380
|
+
var path3 = __toESM(require("path"));
|
|
4663
4381
|
var LOG_FILE = "cli.log";
|
|
4664
4382
|
var MAX_LOG_SIZE = 5 * 1024 * 1024;
|
|
4665
4383
|
var LOG_LEVELS = {
|
|
@@ -4701,15 +4419,15 @@ var Logger = class {
|
|
|
4701
4419
|
writeToFile(formatted) {
|
|
4702
4420
|
if (!this.logToFile) return;
|
|
4703
4421
|
try {
|
|
4704
|
-
const logPath =
|
|
4422
|
+
const logPath = path3.join(getReflyDir(), LOG_FILE);
|
|
4705
4423
|
try {
|
|
4706
|
-
const stats =
|
|
4424
|
+
const stats = fs3.statSync(logPath);
|
|
4707
4425
|
if (stats.size > MAX_LOG_SIZE) {
|
|
4708
|
-
|
|
4426
|
+
fs3.renameSync(logPath, `${logPath}.old`);
|
|
4709
4427
|
}
|
|
4710
4428
|
} catch {
|
|
4711
4429
|
}
|
|
4712
|
-
|
|
4430
|
+
fs3.appendFileSync(logPath, `${formatted}
|
|
4713
4431
|
`);
|
|
4714
4432
|
} catch {
|
|
4715
4433
|
}
|
|
@@ -4792,11 +4510,26 @@ async function apiRequest(path6, options = {}) {
|
|
|
4792
4510
|
signal: controller.signal
|
|
4793
4511
|
});
|
|
4794
4512
|
clearTimeout(timeoutId);
|
|
4513
|
+
const contentLength = response.headers.get("content-length");
|
|
4514
|
+
const contentType = response.headers.get("content-type");
|
|
4515
|
+
if (response.status === 204 || contentLength === "0" || !contentType?.includes("application/json") && response.status >= 200 && response.status < 300) {
|
|
4516
|
+
if (!response.ok) {
|
|
4517
|
+
throw new CLIError(ErrorCodes.API_ERROR, `HTTP ${response.status}: ${response.statusText}`);
|
|
4518
|
+
}
|
|
4519
|
+
return void 0;
|
|
4520
|
+
}
|
|
4795
4521
|
const data = await response.json();
|
|
4796
|
-
|
|
4522
|
+
const hasSuccessFlag = typeof data === "object" && data !== null && "success" in data;
|
|
4523
|
+
if (!response.ok) {
|
|
4524
|
+
throw mapAPIError(response.status, data);
|
|
4525
|
+
}
|
|
4526
|
+
if (hasSuccessFlag) {
|
|
4527
|
+
if (data.success) {
|
|
4528
|
+
return data.data;
|
|
4529
|
+
}
|
|
4797
4530
|
throw mapAPIError(response.status, data);
|
|
4798
4531
|
}
|
|
4799
|
-
return data
|
|
4532
|
+
return data;
|
|
4800
4533
|
} catch (error) {
|
|
4801
4534
|
clearTimeout(timeoutId);
|
|
4802
4535
|
if (error instanceof CLIError) {
|
|
@@ -4855,8 +4588,17 @@ async function refreshAccessToken() {
|
|
|
4855
4588
|
return data.data.accessToken;
|
|
4856
4589
|
}
|
|
4857
4590
|
function mapAPIError(status, response) {
|
|
4858
|
-
|
|
4859
|
-
|
|
4591
|
+
if (response.error && typeof response.error === "object") {
|
|
4592
|
+
const cliError = response.error;
|
|
4593
|
+
return new CLIError(
|
|
4594
|
+
cliError.code || "UNKNOWN",
|
|
4595
|
+
cliError.message || "Unknown error",
|
|
4596
|
+
void 0,
|
|
4597
|
+
cliError.hint
|
|
4598
|
+
);
|
|
4599
|
+
}
|
|
4600
|
+
const errCode = response.errCode ?? response.error ?? "UNKNOWN";
|
|
4601
|
+
const errMsg = response.errMsg ?? response.message ?? "Unknown error";
|
|
4860
4602
|
if (status === 401 || status === 403) {
|
|
4861
4603
|
return new AuthError(errMsg);
|
|
4862
4604
|
}
|
|
@@ -5031,23 +4773,16 @@ function isSkillInstalled() {
|
|
|
5031
4773
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5032
4774
|
0 && (module.exports = {
|
|
5033
4775
|
AuthError,
|
|
5034
|
-
BuilderError,
|
|
5035
4776
|
CLIError,
|
|
5036
4777
|
ErrorCodes,
|
|
5037
4778
|
ValidationError,
|
|
5038
4779
|
apiRequest,
|
|
5039
|
-
createSession,
|
|
5040
|
-
generateGraph,
|
|
5041
4780
|
getApiEndpoint,
|
|
5042
|
-
getCurrentSession,
|
|
5043
4781
|
installSkill,
|
|
5044
4782
|
isAuthenticated,
|
|
5045
4783
|
isSkillInstalled,
|
|
5046
4784
|
loadConfig,
|
|
5047
|
-
loadSession,
|
|
5048
4785
|
saveConfig,
|
|
5049
|
-
saveSession,
|
|
5050
|
-
validateDraft,
|
|
5051
4786
|
verifyConnection
|
|
5052
4787
|
});
|
|
5053
4788
|
//# sourceMappingURL=index.js.map
|