@thinkingai/ae-cli 6.0.53 → 6.0.55

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.
Files changed (121) hide show
  1. package/README.md +28 -9
  2. package/README.zh.md +25 -9
  3. package/bin/ae-cli.js +6 -1
  4. package/cli-installation-guide.md +91 -0
  5. package/dist/{auth-LHM7NQPR.js → auth-RQBO6MTY.js} +9 -11
  6. package/dist/automation-VAAQBM7Y.js +459 -0
  7. package/dist/{capability-F2RIR5DS.js → capability-JRIFC4AJ.js} +6 -6
  8. package/dist/{chunk-647BRKZK.js → chunk-374V5R6N.js} +3 -3
  9. package/dist/{chunk-KJDOTPYU.js → chunk-3YVEAZUN.js} +59 -26
  10. package/dist/{chunk-KS4DE3MX.js → chunk-5XJYLEVC.js} +4 -4
  11. package/dist/{chunk-BW7JUDEI.js → chunk-6VNIR4AP.js} +514 -213
  12. package/dist/{chunk-5XRQ3CZR.js → chunk-7KU2WNQE.js} +43 -8
  13. package/dist/{chunk-7WZACOAI.js → chunk-AP7YP2NX.js} +2 -2
  14. package/dist/chunk-CI24BDR2.js +43 -0
  15. package/dist/{chunk-SO5LKIWP.js → chunk-CT7QDJS6.js} +2 -2
  16. package/dist/{chunk-DU72X2IO.js → chunk-GHXZK54S.js} +22 -10
  17. package/dist/{chunk-N4BLPJC7.js → chunk-OP44TT4H.js} +1 -1
  18. package/dist/chunk-Q5US7JC5.js +133 -0
  19. package/dist/{chunk-PGCIKZRE.js → chunk-RGYPSEYD.js} +3 -3
  20. package/dist/chunk-RK6GLDGI.js +27 -0
  21. package/dist/chunk-RPBOAQQQ.js +56 -0
  22. package/dist/{chunk-GK7WDY7E.js → chunk-S6M42KND.js} +1 -1
  23. package/dist/{chunk-QYXDJOLA.js → chunk-VZZNLV3I.js} +19 -11
  24. package/dist/{chunk-YVGXGTD6.js → chunk-WNGFSIOB.js} +7 -1
  25. package/dist/{chunk-IG3DYEIR.js → chunk-ZL7SGNIA.js} +5 -3
  26. package/dist/{community-report-client-6VJDDMJJ.js → community-report-client-PEERQCX2.js} +1 -1
  27. package/dist/{config-XQWOPDHN.js → config-SICKWZ2A.js} +8 -8
  28. package/dist/context-NGVFPCBK.js +136 -0
  29. package/dist/{data-integration-XBTCGXQT.js → data-integration-BCLQFTGU.js} +6 -6
  30. package/dist/index.js +125 -48
  31. package/dist/{local-data-upload-client-3P7NIVQ4.js → local-data-upload-client-TWMHFLUA.js} +1 -1
  32. package/dist/memory-CQKH2JAV.js +580 -0
  33. package/dist/{metadata-V5ZDTKWZ.js → metadata-EMFGUI2W.js} +7 -7
  34. package/dist/{model-ZS7HVGKN.js → model-VX5M2CJ6.js} +9 -5
  35. package/dist/{personal-semantic-preference-2XANU3F6.js → personal-semantic-preference-SLWVVYZ4.js} +117 -11
  36. package/dist/{project-semantic-LP3LY7QP.js → project-semantic-DPSZBKQD.js} +6 -6
  37. package/dist/{sync-EQLSTUS7.js → sync-RZIAV37C.js} +12 -8
  38. package/dist/{te-agent-Z3HCTKR7.js → te-agent-AORRE2FM.js} +90 -454
  39. package/dist/{te-analysis-3EVYQ3IO.js → te-analysis-ISXKJKRT.js} +297 -20
  40. package/dist/{te-community-Z7JACGF3.js → te-community-42M7ICDO.js} +3 -3
  41. package/dist/{te-dataops-F7GQOIS6.js → te-dataops-BNKNZ4F2.js} +5 -5
  42. package/dist/{te-engage-LFBU6WWH.js → te-engage-BZE3MBKT.js} +6 -6
  43. package/dist/{te-kb-QJLJEX5K.js → te-kb-ULATOTQ3.js} +494 -214
  44. package/dist/{te-system-IXC43QHZ.js → te-system-UGHVKBVV.js} +10 -9
  45. package/dist/{te-team-BIZIKIHZ.js → te-team-YA6SNOJ3.js} +6 -6
  46. package/dist/things-DTCOQIQB.js +1091 -0
  47. package/dist/{update-W2SGQNKT.js → update-ESNYKUVR.js} +59 -51
  48. package/dist/workspace-JEOHKFPX.js +554 -0
  49. package/package.json +21 -9
  50. package/skills/ae-agent/SKILL.md +91 -139
  51. package/skills/ae-agent/references/add-model.md +1 -1
  52. package/skills/ae-agent/references/create-agent.md +1 -1
  53. package/skills/ae-agent/references/find-archived-conversations.md +12 -5
  54. package/skills/ae-agent/references/get-agent.md +1 -1
  55. package/skills/ae-agent/references/list-agents.md +2 -2
  56. package/skills/ae-agent/references/list-models.md +2 -2
  57. package/skills/ae-agent/references/restore-conversation.md +3 -1
  58. package/skills/ae-analysis/SKILL.md +15 -6
  59. package/skills/ae-analysis/references/ai_models/funnel.md +5 -3
  60. package/skills/ae-analysis/references/ai_models.md +27 -0
  61. package/skills/ae-analysis/references/command_index.md +12 -4
  62. package/skills/ae-analysis/references/dashboard_move.md +21 -0
  63. package/skills/ae-analysis/references/dashboard_report_add.md +2 -0
  64. package/skills/ae-analysis/references/dashboard_report_get.md +19 -0
  65. package/skills/ae-analysis/references/dashboard_report_update.md +27 -0
  66. package/skills/ae-analysis/references/dashboard_update.md +1 -1
  67. package/skills/ae-analysis/references/event_report_presentation.md +76 -0
  68. package/skills/ae-analysis/references/feedback_submit.md +37 -0
  69. package/skills/ae-analysis/references/metadata_resolution.md +15 -0
  70. package/skills/ae-analysis/references/personal_semantic_preference_review.md +9 -0
  71. package/skills/ae-analysis/references/personal_semantic_preference_review_list.md +7 -0
  72. package/skills/ae-analysis/references/personal_semantic_preference_submit.md +7 -0
  73. package/skills/ae-analysis/references/project_semantic_knowledge_wiki.md +90 -31
  74. package/skills/ae-analysis/references/project_semantic_knowledge_wiki_plan_schema.md +99 -1
  75. package/skills/ae-analysis/references/report_create.md +13 -3
  76. package/skills/ae-analysis/references/report_get.md +5 -1
  77. package/skills/ae-analysis/references/report_update.md +15 -4
  78. package/skills/ae-analysis/references/system_query_monitor_overview.md +2 -0
  79. package/skills/ae-analysis/references/system_query_task_cancel.md +2 -0
  80. package/skills/ae-analysis/references/system_query_task_export.md +6 -2
  81. package/skills/ae-analysis/references/system_query_task_get.md +2 -0
  82. package/skills/ae-analysis/references/system_query_task_list.md +7 -3
  83. package/skills/ae-analysis/references/system_query_task_options.md +2 -2
  84. package/skills/ae-analysis/references/system_query_task_realtime_list.md +15 -0
  85. package/skills/ae-analysis/references/user_tag_models.md +2 -0
  86. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/build-empty-skeleton.mjs +105 -0
  87. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/build-project-semantic-wiki.mjs +669 -29
  88. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/company-kb.mjs +21 -8
  89. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/default-compile-rules.md +28 -10
  90. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/default-compile-schema.md +66 -0
  91. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/generate-build-ir.mjs +285 -24
  92. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/package-wiki-source-zip.mjs +262 -30
  93. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/plan-kb-source-sync.mjs +1 -1
  94. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/precompiled-source.mjs +46 -2
  95. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/prepare-compile-schema.mjs +64 -0
  96. package/skills/ae-analysis/scripts/project-semantic-knowledge-wiki/refresh-state-parts.mjs +91 -0
  97. package/skills/ae-automation/SKILL.md +16 -0
  98. package/skills/ae-automation/references/cli.md +53 -0
  99. package/skills/ae-automation/references/command_index.md +17 -0
  100. package/skills/ae-capability/SKILL.md +15 -6
  101. package/skills/ae-current-context/SKILL.md +3 -2
  102. package/skills/ae-kb/SKILL.md +62 -12
  103. package/skills/ae-kb/references/analysis-workflow.md +73 -36
  104. package/skills/ae-kb/references/query-workflow.md +67 -33
  105. package/skills/ae-kb/references/schema-import.md +5 -3
  106. package/skills/ae-kb/references/source-mutations.md +6 -4
  107. package/skills/ae-kb/references/text-sources.md +53 -0
  108. package/skills/ae-kb-discovery/SKILL.md +1 -1
  109. package/skills/ae-team/SKILL.md +23 -17
  110. package/skills/ae-things/SKILL.md +85 -0
  111. package/skills/ae-things/references/cli.md +103 -0
  112. package/skills/ae-things-progress/SKILL.md +43 -0
  113. package/skills/ae-things-review/SKILL.md +42 -0
  114. package/skills/ae-workspace/SKILL.md +43 -0
  115. package/skills/ae-workspace/references/commands.md +51 -0
  116. package/dist/chunk-E2JKXMVO.js +0 -29
  117. package/dist/context-M3HDGEIR.js +0 -46
  118. package/dist/memory-6APEB2JB.js +0 -892
  119. package/skills/ae-agent/references/create-automation.md +0 -125
  120. package/skills/ae-agent/references/list-automations.md +0 -56
  121. package/skills/ae-agent/references/update-automation.md +0 -107
@@ -0,0 +1,459 @@
1
+ import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
+ import {
3
+ TeAgentApiError,
4
+ deleteFromMainApp,
5
+ getFromMainApp,
6
+ patchToMainApp,
7
+ postToMainApp
8
+ } from "./chunk-3YVEAZUN.js";
9
+ import "./chunk-Y74WTIKJ.js";
10
+ import "./chunk-GHXZK54S.js";
11
+ import "./chunk-ZL7SGNIA.js";
12
+ import "./chunk-WNGFSIOB.js";
13
+
14
+ // src/commands/automation/index.ts
15
+ import { randomUUID } from "crypto";
16
+ var base = "/api/cli/automation/v1";
17
+ var flag = (name, desc, type = "string", required = false) => ({ name, desc, type, required });
18
+ var idFlag = flag("id", "Automation ID from list or create", "string", true);
19
+ var typeFlag = flag(
20
+ "target-type",
21
+ "agent | team; identifies the existing target on update",
22
+ "string",
23
+ true
24
+ );
25
+ var scopeFlag = flag(
26
+ "agent-space-id",
27
+ "Explicit space; otherwise server resolves sandbox context or personal space"
28
+ );
29
+ var runFlag = flag(
30
+ "run-id",
31
+ "Execution ID from run or runs list",
32
+ "string",
33
+ true
34
+ );
35
+ var pageFlags = [
36
+ flag("limit", "Page size, 1-100 (default 20)", "number"),
37
+ flag("cursor", "Opaque nextCursor from the previous page")
38
+ ];
39
+ var waitFlags = [
40
+ flag("wait", "Wait for this execution to finish", "boolean"),
41
+ flag("timeout", "Wait timeout in seconds, 1-86400 (default 300)", "number")
42
+ ];
43
+ var requestFlag = flag(
44
+ "command-id",
45
+ "Stable idempotency key; reuse it after an uncertain response"
46
+ );
47
+ var configFlags = [
48
+ typeFlag,
49
+ flag("name", "Automation name"),
50
+ {
51
+ ...flag("message", "Task instructions; an empty string clears it"),
52
+ sensitive: true
53
+ },
54
+ flag("clear-message", "Clear task instructions explicitly", "boolean"),
55
+ flag("trigger-type", "scheduled | manual"),
56
+ flag("status", "active | paused"),
57
+ flag(
58
+ "cron-expression",
59
+ "Five-field hourly, daily, weekly or monthly schedule"
60
+ ),
61
+ flag("schedule-kind", "hourly | daily | weekly | monthly"),
62
+ flag("time", "HH:mm in server timezone"),
63
+ flag("minute", "Hourly minute, 0-59", "number"),
64
+ flag("weekday", "Weekly day, 0=Sunday through 6=Saturday", "number"),
65
+ flag("day-of-month", "Monthly day, 1-28", "number"),
66
+ flag("model", "Agent model configuration ID; null clears the override"),
67
+ flag("reuse-conversation", "Agent: true | false", "json"),
68
+ {
69
+ ...flag("scope", "Team data scope JSON; null clears it", "json"),
70
+ sensitive: true
71
+ },
72
+ flag(
73
+ "channels",
74
+ "Team notification channel array; [] clears channels",
75
+ "json"
76
+ ),
77
+ flag("feishu-chat-id", "Team Feishu destination; null clears it"),
78
+ flag("lark-chat-id", "Team Lark destination; null clears it"),
79
+ flag("slack-channel-id", "Team Slack destination; null clears it"),
80
+ flag(
81
+ "save-to-knowledge-base-id",
82
+ "Team output knowledge base ID; null clears it"
83
+ )
84
+ ];
85
+ function enumValue(value, values, name) {
86
+ if (value && !values.includes(value))
87
+ throw new Error(`--${name} must be ${values.join(" | ")}`);
88
+ }
89
+ function range(value, min, max, name) {
90
+ if (!Number.isInteger(value) || value < min || value > max)
91
+ throw new Error(`--${name} must be an integer from ${min} to ${max}`);
92
+ return value;
93
+ }
94
+ function key(ctx, name) {
95
+ const value = ctx.str(name);
96
+ if (!value || value.length > 191)
97
+ throw new Error(`${name} must be a non-empty ID of at most 191 characters`);
98
+ return encodeURIComponent(value);
99
+ }
100
+ function configuration(ctx, create) {
101
+ const targetType = ctx.str("targetType");
102
+ enumValue(targetType, ["agent", "team"], "target-type");
103
+ if (!targetType) throw new Error("--target-type is required");
104
+ const result = {};
105
+ if (create) {
106
+ result.targetType = targetType;
107
+ result[targetType === "agent" ? "agentId" : "teamId"] = decodeURIComponent(
108
+ key(ctx, targetType === "agent" ? "agentId" : "teamId")
109
+ );
110
+ }
111
+ for (const name2 of ["name", "message", "triggerType", "status"]) {
112
+ if (ctx.str(name2)) result[name2] = ctx.str(name2);
113
+ }
114
+ if (ctx.bool("clearMessage")) {
115
+ if (ctx.str("message")) throw new Error("Use --message or --clear-message");
116
+ result.message = "";
117
+ }
118
+ if (create && ctx.str(targetType === "agent" ? "teamId" : "agentId"))
119
+ throw new Error("Specify only the selected target ID");
120
+ if (create && !ctx.str("name").trim()) throw new Error("--name is required");
121
+ const name = ctx.str("name");
122
+ if (name && !name.trim()) throw new Error("--name must not be blank");
123
+ if (targetType === "team") {
124
+ if (name.length > 191 || Array.from(name.replace(/\s/g, "")).length > 50)
125
+ throw new Error(
126
+ "--name must contain at most 50 non-whitespace characters (191 raw code units)"
127
+ );
128
+ } else if (name.trim().length > 100) {
129
+ throw new Error("--name must contain at most 100 characters");
130
+ }
131
+ enumValue(ctx.str("triggerType"), ["scheduled", "manual"], "trigger-type");
132
+ enumValue(ctx.str("status"), ["active", "paused"], "status");
133
+ const kind = ctx.str("scheduleKind"), cron = ctx.str("cronExpression");
134
+ enumValue(kind, ["hourly", "daily", "weekly", "monthly"], "schedule-kind");
135
+ if (kind && cron) throw new Error("Use --schedule-kind or --cron-expression");
136
+ if (!kind && ["time", "minute", "weekday", "dayOfMonth"].some((name2) => ctx.str(name2)))
137
+ throw new Error("Schedule details require --schedule-kind");
138
+ if (kind && ctx.str("weekday") && kind !== "weekly" || kind && ctx.str("dayOfMonth") && kind !== "monthly" || kind && ctx.str("minute") && kind !== "hourly")
139
+ throw new Error("Schedule field is not applicable to this frequency");
140
+ if (kind) {
141
+ const schedule = { kind };
142
+ if (kind === "hourly")
143
+ schedule.minute = range(ctx.optionalNum("minute") ?? 0, 0, 59, "minute");
144
+ else {
145
+ if (!/^([01]\d|2[0-3]):[0-5]\d$/.test(ctx.str("time")))
146
+ throw new Error("--time must use HH:mm");
147
+ schedule.time = ctx.str("time");
148
+ if (kind === "weekly")
149
+ schedule.weekday = range(
150
+ ctx.optionalNum("weekday") ?? NaN,
151
+ 0,
152
+ 6,
153
+ "weekday"
154
+ );
155
+ if (kind === "monthly")
156
+ schedule.dayOfMonth = range(
157
+ ctx.optionalNum("dayOfMonth") ?? NaN,
158
+ 1,
159
+ 28,
160
+ "day-of-month"
161
+ );
162
+ }
163
+ result.schedule = schedule;
164
+ }
165
+ if (cron) {
166
+ const parts = cron.trim().split(/\s+/);
167
+ const validNumber = (v, a, b) => /^\d+$/.test(v) && Number(v) >= a && Number(v) <= b;
168
+ const [m, h, d, mo, w] = parts;
169
+ if (parts.length !== 5 || !validNumber(m, 0, 59) || !(h === "*" || validNumber(h, 0, 23)) || mo !== "*" || !(d === "*" || validNumber(d, 1, 28)) || !(w === "*" || validNumber(w, 0, 6)) || d !== "*" && w !== "*" || h === "*" && (d !== "*" || w !== "*"))
170
+ throw new Error(
171
+ "--cron-expression must specify an hourly, daily, weekly or monthly schedule"
172
+ );
173
+ result.cronExpression = cron;
174
+ }
175
+ if (create && (ctx.str("triggerType") || "scheduled") === "scheduled" && !kind && !cron)
176
+ throw new Error("Scheduled automation requires a schedule");
177
+ const agentNames = ["model", "reuseConversation"];
178
+ const teamNames = [
179
+ "scope",
180
+ "channels",
181
+ "feishuChatId",
182
+ "larkChatId",
183
+ "slackChannelId",
184
+ "saveToKnowledgeBaseId"
185
+ ];
186
+ for (const name2 of [...agentNames, ...teamNames]) {
187
+ const json = ["scope", "channels", "reuseConversation"].includes(name2);
188
+ const value = json ? ctx.json(name2) : ctx.str(name2) || void 0;
189
+ if (value === void 0) continue;
190
+ if ((agentNames.includes(name2) ? "agent" : "team") !== targetType)
191
+ throw new Error(`${name2} is not applicable to ${targetType} automations`);
192
+ if (name2 === "reuseConversation" && typeof value !== "boolean")
193
+ throw new Error("--reuse-conversation must be true or false");
194
+ if (name2 === "channels" && (!Array.isArray(value) || value.some(
195
+ (v) => ![
196
+ "feishu",
197
+ "lark",
198
+ "slack",
199
+ "discord",
200
+ "dingtalk",
201
+ "wecom",
202
+ "mattermost",
203
+ "google_chat",
204
+ "zoom_chat",
205
+ "whatsapp"
206
+ ].includes(v)
207
+ )))
208
+ throw new Error(
209
+ "--channels must contain supported notification channels"
210
+ );
211
+ if (name2 === "scope" && value !== null && (typeof value !== "object" || Array.isArray(value)))
212
+ throw new Error("--scope must be an object or null");
213
+ result[name2 === "scope" ? "scopeJson" : name2] = name2 === "scope" ? value === null ? null : JSON.stringify(value) : value === "null" ? null : value;
214
+ }
215
+ if (!create && !Object.keys(result).length)
216
+ throw new Error("No fields to update");
217
+ if (create) result.triggerImmediately = ctx.bool("triggerImmediately");
218
+ return result;
219
+ }
220
+ function query(ctx, list = false, typed = false) {
221
+ const p = new URLSearchParams();
222
+ if (ctx.str("agentSpaceId")) p.set("agentSpaceId", ctx.str("agentSpaceId"));
223
+ if (typed && ctx.str("targetType"))
224
+ p.set("targetType", ctx.str("targetType"));
225
+ if (list) {
226
+ for (const k of ["limit", "cursor", "status", "q", "targetType"])
227
+ if (ctx.str(k)) p.set(k, ctx.str(k));
228
+ }
229
+ return p.size ? `?${p}` : "";
230
+ }
231
+ async function request(ctx, method, path, body) {
232
+ if (method === "GET")
233
+ return getFromMainApp(
234
+ path,
235
+ ctx.hostOverride ? ctx.hostOverride() : ctx.host()
236
+ );
237
+ if (method === "POST")
238
+ return postToMainApp(
239
+ path,
240
+ body,
241
+ ctx.hostOverride ? ctx.hostOverride() : ctx.host()
242
+ );
243
+ if (method === "PATCH")
244
+ return patchToMainApp(
245
+ path,
246
+ body,
247
+ ctx.hostOverride ? ctx.hostOverride() : ctx.host()
248
+ );
249
+ return deleteFromMainApp(
250
+ path,
251
+ ctx.hostOverride ? ctx.hostOverride() : ctx.host()
252
+ );
253
+ }
254
+ function withDryRun(path) {
255
+ return `${path}${path.includes("?") ? "&" : "?"}dryRun=true`;
256
+ }
257
+ function redactedPreview(method, path, body) {
258
+ return {
259
+ method,
260
+ url: path,
261
+ ...body === void 0 ? {} : { body: { payload: "[REDACTED]" } }
262
+ };
263
+ }
264
+ async function waitForRun(ctx, id, runId) {
265
+ const deadline = Date.now() + (ctx.optionalNum("timeout") ?? 300) * 1e3;
266
+ do {
267
+ const result = await request(
268
+ ctx,
269
+ "GET",
270
+ `${base}/${encodeURIComponent(id)}/runs/${encodeURIComponent(runId)}/result${query(ctx)}`
271
+ );
272
+ if (result.status !== "running")
273
+ return { ...result, executionCompleted: true, timedOut: false };
274
+ if (Date.now() >= deadline)
275
+ return { ...result, executionCompleted: false, timedOut: true };
276
+ await new Promise(
277
+ (resolve) => setTimeout(resolve, Math.min(1e3, deadline - Date.now()))
278
+ );
279
+ } while (true);
280
+ }
281
+ var actions = [
282
+ {
283
+ command: "list",
284
+ method: "GET",
285
+ suffix: () => "",
286
+ flags: [
287
+ ...pageFlags,
288
+ flag("target-type", "Filter agent | team"),
289
+ flag("status", "Filter active | paused"),
290
+ flag("q", "Search automation name")
291
+ ],
292
+ list: true
293
+ },
294
+ {
295
+ command: "get",
296
+ method: "GET",
297
+ suffix: (c) => `/${key(c, "id")}`,
298
+ flags: [idFlag]
299
+ },
300
+ {
301
+ command: "create",
302
+ method: "POST",
303
+ suffix: () => "",
304
+ flags: [
305
+ ...configFlags,
306
+ flag("agent-id", "Agent target ID"),
307
+ flag("team-id", "Team target ID"),
308
+ flag(
309
+ "trigger-immediately",
310
+ "Execute once after successful creation",
311
+ "boolean"
312
+ ),
313
+ requestFlag,
314
+ ...waitFlags
315
+ ],
316
+ body: (c) => configuration(c, true),
317
+ wait: true
318
+ },
319
+ {
320
+ command: "update",
321
+ method: "PATCH",
322
+ suffix: (c) => `/${key(c, "id")}`,
323
+ flags: [idFlag, ...configFlags],
324
+ body: (c) => configuration(c, false),
325
+ typed: true
326
+ },
327
+ ...["enable", "disable"].map((command) => ({
328
+ command,
329
+ method: "PATCH",
330
+ suffix: (c) => `/${key(c, "id")}`,
331
+ flags: [idFlag],
332
+ body: () => ({ status: command === "enable" ? "active" : "paused" })
333
+ })),
334
+ {
335
+ command: "delete",
336
+ method: "DELETE",
337
+ suffix: (c) => `/${key(c, "id")}`,
338
+ flags: [idFlag],
339
+ highRisk: true
340
+ },
341
+ {
342
+ command: "run",
343
+ method: "POST",
344
+ suffix: (c) => `/${key(c, "id")}/run`,
345
+ flags: [idFlag, requestFlag, ...waitFlags],
346
+ body: () => ({}),
347
+ wait: true
348
+ },
349
+ {
350
+ command: "list",
351
+ resource: "runs",
352
+ method: "GET",
353
+ suffix: (c) => `/${key(c, "id")}/runs`,
354
+ flags: [idFlag, ...pageFlags],
355
+ list: true
356
+ },
357
+ ...["get", "result", "stop", "retry"].map((command) => ({
358
+ command,
359
+ resource: "runs",
360
+ method: ["stop", "retry"].includes(command) ? "POST" : "GET",
361
+ suffix: (c) => `/${key(c, "id")}/runs/${key(c, "runId")}${command === "get" ? "" : `/${command}`}`,
362
+ flags: [
363
+ idFlag,
364
+ runFlag,
365
+ ...command === "retry" ? [requestFlag, ...waitFlags] : []
366
+ ],
367
+ body: ["stop", "retry"].includes(command) ? () => ({}) : void 0,
368
+ highRisk: command === "stop",
369
+ wait: command === "retry"
370
+ }))
371
+ ];
372
+ var automationCommands = actions.map((a) => ({
373
+ service: "automation",
374
+ resource: a.resource,
375
+ command: a.command,
376
+ description: `${a.command} ${a.resource ? "an automation execution" : "Agent or team automations"} (Transitional TE REST)`,
377
+ risk: a.highRisk ? "high-risk-write" : a.method === "GET" ? "read" : "write",
378
+ flags: [scopeFlag, ...a.flags ?? []],
379
+ validate: (ctx) => {
380
+ a.suffix(ctx);
381
+ a.body?.(ctx);
382
+ if (ctx.str("commandId").length > 191)
383
+ throw new Error("--command-id must contain at most 191 characters");
384
+ if (ctx.optionalNum("limit") !== void 0)
385
+ range(ctx.num("limit"), 1, 100, "limit");
386
+ if (ctx.optionalNum("timeout") !== void 0)
387
+ range(ctx.num("timeout"), 1, 86400, "timeout");
388
+ enumValue(ctx.str("targetType"), ["agent", "team"], "target-type");
389
+ enumValue(ctx.str("status"), ["active", "paused"], "status");
390
+ if (a.command === "create" && ctx.bool("wait") && !ctx.bool("triggerImmediately"))
391
+ throw new Error("--wait on create requires --trigger-immediately");
392
+ },
393
+ dryRun: async (ctx) => {
394
+ const body = a.body?.(ctx);
395
+ const commandId = ctx.str("commandId") || randomUUID();
396
+ const requestBody = body && {
397
+ ...body,
398
+ ...a.wait ? { commandId } : {}
399
+ };
400
+ const path = base + a.suffix(ctx) + query(ctx, a.list, a.typed);
401
+ return {
402
+ request: redactedPreview(a.method, path, requestBody),
403
+ validation: await request(ctx, a.method, withDryRun(path), requestBody)
404
+ };
405
+ },
406
+ execute: async (ctx) => {
407
+ const body = a.body?.(ctx), commandId = ctx.str("commandId") || randomUUID();
408
+ let output;
409
+ try {
410
+ output = await request(
411
+ ctx,
412
+ a.method,
413
+ base + a.suffix(ctx) + query(ctx, a.list, a.typed),
414
+ body && { ...body, ...a.wait ? { commandId } : {} }
415
+ );
416
+ } catch (error) {
417
+ if (a.wait && a.command !== "create" && error instanceof TeAgentApiError)
418
+ throw new TeAgentApiError(
419
+ error.message,
420
+ error.status,
421
+ error.code,
422
+ error.body,
423
+ error.errorType,
424
+ [
425
+ error.hint,
426
+ `Keep command ID ${commandId}. Reuse it when checking or retrying this execution request.`
427
+ ].filter(Boolean).join(" "),
428
+ error.details
429
+ );
430
+ throw error;
431
+ }
432
+ if (!a.wait) return output;
433
+ const runId = a.command === "create" ? output.execution?.runId : output.runId;
434
+ const id = a.command === "create" ? output.automation.id : ctx.str("id");
435
+ const accepted = { ...output, commandId };
436
+ if (!ctx.bool("wait") || !runId) return accepted;
437
+ try {
438
+ return { ...accepted, result: await waitForRun(ctx, id, runId) };
439
+ } catch (error) {
440
+ return {
441
+ ...accepted,
442
+ observation: {
443
+ status: "failed",
444
+ code: error instanceof TeAgentApiError ? error.code : "OBSERVATION_FAILED",
445
+ message: "Execution was accepted, but result polling failed. Read the existing run; do not create or trigger again.",
446
+ automationId: id,
447
+ runId
448
+ }
449
+ };
450
+ }
451
+ }
452
+ }));
453
+ var automation_default = automationCommands;
454
+ export {
455
+ automationCommands,
456
+ configuration,
457
+ automation_default as default,
458
+ waitForRun
459
+ };
@@ -11,7 +11,7 @@ import {
11
11
  } from "./chunk-KPQY44JQ.js";
12
12
  import {
13
13
  resolveHost
14
- } from "./chunk-N4BLPJC7.js";
14
+ } from "./chunk-OP44TT4H.js";
15
15
  import {
16
16
  CapabilityGatewayError,
17
17
  dryRunCapabilityWithEnvelope,
@@ -20,24 +20,24 @@ import {
20
20
  inspectCapabilityWithEnvelope,
21
21
  listCapabilitiesWithEnvelope,
22
22
  validateCapabilityWithEnvelope
23
- } from "./chunk-QYXDJOLA.js";
23
+ } from "./chunk-VZZNLV3I.js";
24
24
  import {
25
25
  printError,
26
26
  printOutput,
27
27
  withOutputMetadata
28
- } from "./chunk-BW7JUDEI.js";
28
+ } from "./chunk-6VNIR4AP.js";
29
29
  import "./chunk-Y74WTIKJ.js";
30
30
  import {
31
31
  CredentialStoreUnreadableError,
32
32
  SecureStoreAuthError
33
- } from "./chunk-DU72X2IO.js";
33
+ } from "./chunk-GHXZK54S.js";
34
34
  import {
35
35
  safeJsonParse
36
- } from "./chunk-IG3DYEIR.js";
36
+ } from "./chunk-ZL7SGNIA.js";
37
37
  import {
38
38
  CliValidationError,
39
39
  PermissionError
40
- } from "./chunk-YVGXGTD6.js";
40
+ } from "./chunk-WNGFSIOB.js";
41
41
 
42
42
  // src/commands/capability/index.ts
43
43
  import * as readline from "readline";
@@ -6,13 +6,13 @@ import {
6
6
  dryRunCapability,
7
7
  executeCapabilityWithEnvelope,
8
8
  validateCapability
9
- } from "./chunk-QYXDJOLA.js";
9
+ } from "./chunk-VZZNLV3I.js";
10
10
  import {
11
11
  withOutputMetadata
12
- } from "./chunk-BW7JUDEI.js";
12
+ } from "./chunk-6VNIR4AP.js";
13
13
  import {
14
14
  CliValidationError
15
- } from "./chunk-YVGXGTD6.js";
15
+ } from "./chunk-WNGFSIOB.js";
16
16
 
17
17
  // src/core/definition-intent.ts
18
18
  import { createHash } from "crypto";
@@ -4,14 +4,15 @@ import {
4
4
  } from "./chunk-Y74WTIKJ.js";
5
5
  import {
6
6
  getCliToken
7
- } from "./chunk-DU72X2IO.js";
7
+ } from "./chunk-GHXZK54S.js";
8
8
  import {
9
9
  getActiveHost,
10
10
  getSandboxRuntimeRoot
11
- } from "./chunk-IG3DYEIR.js";
11
+ } from "./chunk-ZL7SGNIA.js";
12
12
  import {
13
- PermissionError
14
- } from "./chunk-YVGXGTD6.js";
13
+ PermissionError,
14
+ isApiErrorType
15
+ } from "./chunk-WNGFSIOB.js";
15
16
 
16
17
  // src/core/te-agent-credentials.ts
17
18
  import { readFileSync } from "fs";
@@ -81,19 +82,27 @@ function readLegacyCredentials() {
81
82
  }
82
83
  }
83
84
  function tryLoadTeAgentSandboxCredentials() {
84
- const legacy = readLegacyCredentials();
85
- const persistent = readPersistentEnv();
86
- const url = process.env.TE_CLAUDE_BASE_URL || persistent?.TE_CLAUDE_BASE_URL || legacy?.url;
87
- if (typeof url !== "string" || !url) {
88
- return null;
85
+ const credentials = readSandboxCredentials();
86
+ return credentials.url ? { ...credentials, url: credentials.url } : null;
87
+ }
88
+ function readSandboxCredentials() {
89
+ let url = process.env.TE_CLAUDE_BASE_URL || null;
90
+ let sandboxId = process.env.SANDBOX_ID || null;
91
+ let sandboxSecretKey = process.env.SECRET_KEY || process.env.SANDBOX_SECRET_KEY || null;
92
+ if (!url || !sandboxId || !sandboxSecretKey) {
93
+ const persistent = readPersistentEnv();
94
+ url ||= persistent?.TE_CLAUDE_BASE_URL || null;
95
+ sandboxId ||= persistent?.SANDBOX_ID || null;
96
+ sandboxSecretKey ||= persistent?.SECRET_KEY || persistent?.SANDBOX_SECRET_KEY || null;
89
97
  }
90
- const sandboxId = process.env.SANDBOX_ID || persistent?.SANDBOX_ID || legacy?.sandboxId || null;
91
- const sandboxSecretKey = process.env.SECRET_KEY || process.env.SANDBOX_SECRET_KEY || persistent?.SECRET_KEY || persistent?.SANDBOX_SECRET_KEY || legacy?.sandboxSecretKey || legacy?.secretKey || null;
92
- return {
93
- url,
94
- sandboxId: typeof sandboxId === "string" ? sandboxId : null,
95
- sandboxSecretKey: typeof sandboxSecretKey === "string" ? sandboxSecretKey : null
96
- };
98
+ if (!url || !sandboxId || !sandboxSecretKey) {
99
+ const legacy = readLegacyCredentials();
100
+ url ||= typeof legacy?.url === "string" ? legacy.url : null;
101
+ sandboxId ||= typeof legacy?.sandboxId === "string" ? legacy.sandboxId : null;
102
+ const legacySecret = legacy?.sandboxSecretKey || legacy?.secretKey;
103
+ sandboxSecretKey ||= typeof legacySecret === "string" ? legacySecret : null;
104
+ }
105
+ return { url, sandboxId, sandboxSecretKey };
97
106
  }
98
107
  function getClaudeConfigDir() {
99
108
  const fromEnv = process.env.CLAUDE_CONFIG_DIR;
@@ -120,16 +129,22 @@ function resolveTeClaudeBaseUrl(host) {
120
129
 
121
130
  // src/core/te-agent-client.ts
122
131
  var TeAgentApiError = class extends Error {
123
- constructor(message, status, code, body) {
132
+ constructor(message, status, code, body, errorType = "api", hint, details) {
124
133
  super(message);
125
134
  this.status = status;
126
135
  this.code = code;
127
136
  this.body = body;
137
+ this.errorType = errorType;
138
+ this.hint = hint;
139
+ this.details = details;
128
140
  this.name = "TeAgentApiError";
129
141
  }
130
142
  status;
131
143
  code;
132
144
  body;
145
+ errorType;
146
+ hint;
147
+ details;
133
148
  };
134
149
  var DEFAULT_TIMEOUT_MS = 3e4;
135
150
  var UPLOAD_TIMEOUT_MS = 12e4;
@@ -183,7 +198,16 @@ function teClaudeBaseFromActiveHost(hostOverride) {
183
198
  return resolveTeClaudeBaseUrl(h);
184
199
  }
185
200
  async function signRequest(method, path2, hostOverride, includeJsonContentType = true) {
186
- const sandboxCred = tryLoadTeAgentSandboxCredentials();
201
+ const configuredHost = hostOverride || getActiveHost();
202
+ const sandboxOnly = !hostOverride && (/* @__PURE__ */ new Set([
203
+ "/api/sandbox/models",
204
+ "/api/sandbox/models/select",
205
+ "/api/sandbox/sync/push",
206
+ "/api/sandbox/sync/push/skill",
207
+ "/api/sandbox/sync/pull",
208
+ "/api/sandbox/sync/pull/candidates"
209
+ ])).has(path2.split("?")[0]);
210
+ const sandboxCred = configuredHost && !sandboxOnly ? null : tryLoadTeAgentSandboxCredentials();
187
211
  if (!hostOverride && sandboxCred && sandboxCred.sandboxId && sandboxCred.sandboxSecretKey) {
188
212
  const headers = {
189
213
  "X-Sandbox-Id": sandboxCred.sandboxId,
@@ -205,7 +229,7 @@ async function signRequest(method, path2, hostOverride, includeJsonContentType =
205
229
  "Run ae-cli config set-host <url> to configure the service URL, or execute inside a te-agent sandbox"
206
230
  );
207
231
  }
208
- const hostForToken = hostOverride || getActiveHost() || baseUrl;
232
+ const hostForToken = configuredHost || baseUrl;
209
233
  const contentTypeHeader = includeJsonContentType && (method === "POST" || method === "PATCH" || method === "PUT") ? { "Content-Type": "application/json" } : {};
210
234
  const cliToken = await getCliToken(hostForToken);
211
235
  return {
@@ -241,7 +265,13 @@ function errorDetails(parsed, defaultErrorPrefix, status) {
241
265
  const message = typeof parsed?.error === "string" ? parsed.error : typeof nested?.message === "string" ? nested.message : typeof parsed?.message === "string" ? parsed.message : typeof parsed?.return_message === "string" ? parsed.return_message : `${defaultErrorPrefix} ${status}`;
242
266
  const code = typeof nested?.code === "string" ? nested.code : typeof parsed?.code === "string" ? parsed.code : void 0;
243
267
  const hint = typeof nested?.hint === "string" ? nested.hint : typeof parsed?.hint === "string" ? parsed.hint : void 0;
244
- return { message, code, hint };
268
+ const declaredType = isApiErrorType(nested?.type) ? nested.type : void 0;
269
+ const type = status === 401 ? "auth" : status === 403 ? "permission" : declaredType ?? ([400, 413, 422].includes(status) ? "validation" : status === 404 ? "not_found" : "api");
270
+ return { message, code, hint, type, details: declaredType ? nested?.details : void 0 };
271
+ }
272
+ function createTeAgentApiError(body, status, defaultErrorPrefix = "Main app returned") {
273
+ const error = errorDetails(body, defaultErrorPrefix, status);
274
+ return new TeAgentApiError(error.message, status, error.code, body, error.type, error.hint, error.details);
245
275
  }
246
276
  async function parseResponse(response, defaultErrorPrefix) {
247
277
  const text = await response.text();
@@ -256,17 +286,20 @@ async function parseResponse(response, defaultErrorPrefix) {
256
286
  if (!response.ok) {
257
287
  const details = errorDetails(parsed, defaultErrorPrefix, response.status);
258
288
  if (response.status === 403) {
259
- throw new PermissionError(details.message, details.code, details.hint);
289
+ throw new PermissionError(details.message, details.code, details.hint, details.details);
260
290
  }
261
291
  if (response.status === 401) {
262
292
  throw new TeAgentApiError(
263
- "Session expired or unauthorized. Please run: ae-cli auth login",
293
+ isApiErrorType(parsed?.error?.type) && typeof parsed.error.message === "string" && parsed.error.message.trim() ? details.message : "Session expired or unauthorized. Please run: ae-cli auth login",
264
294
  response.status,
265
- "auth_expired",
266
- parsed
295
+ details.code ?? "auth_expired",
296
+ parsed,
297
+ "auth",
298
+ details.hint ?? "Run: ae-cli auth login",
299
+ details.details
267
300
  );
268
301
  }
269
- throw new TeAgentApiError(details.message, response.status, details.code, parsed);
302
+ throw createTeAgentApiError(parsed, response.status, defaultErrorPrefix);
270
303
  }
271
304
  return parsed;
272
305
  }
@@ -483,10 +516,10 @@ async function uploadToMainApp(path2, formData, hostOverride) {
483
516
 
484
517
  export {
485
518
  TeAgentCredentialsError,
486
- tryLoadTeAgentSandboxCredentials,
487
519
  getClaudeConfigDir,
488
520
  resolveTeClaudeBaseUrl,
489
521
  TeAgentApiError,
522
+ createTeAgentApiError,
490
523
  postToMainApp,
491
524
  getFromMainApp,
492
525
  getSandboxModels,