lua-cli 3.36.0 → 3.38.0

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.
@@ -10,6 +10,39 @@ import { z as z2 } from "zod";
10
10
  import { z as z3 } from "zod";
11
11
  var __defProp2 = Object.defineProperty;
12
12
  var __name2 = /* @__PURE__ */ __name((target, value3) => __defProp2(target, "name", { value: value3, configurable: true }), "__name");
13
+ var PLUMBING_THREAD_CHANNELS = [
14
+ "trigger",
15
+ "template-install",
16
+ "template-uninstall"
17
+ ];
18
+ var CHANNEL_CONVERSATION_CHANNELS = [
19
+ "whatsapp",
20
+ "slack",
21
+ "teams",
22
+ "front",
23
+ "email",
24
+ "messagebird",
25
+ "sms",
26
+ "mms",
27
+ "rcs",
28
+ "instagram",
29
+ "facebook",
30
+ "imessage"
31
+ ];
32
+ var HIDDEN_THREAD_CHANNELS = [
33
+ ...PLUMBING_THREAD_CHANNELS,
34
+ ...CHANNEL_CONVERSATION_CHANNELS
35
+ ];
36
+ function isChannelConversationChannel(channel) {
37
+ return !!channel && CHANNEL_CONVERSATION_CHANNELS.includes(channel);
38
+ }
39
+ __name(isChannelConversationChannel, "isChannelConversationChannel");
40
+ __name2(isChannelConversationChannel, "isChannelConversationChannel");
41
+ function isChannelConversationThread(threadId, channel) {
42
+ return !!threadId && isChannelConversationChannel(channel);
43
+ }
44
+ __name(isChannelConversationThread, "isChannelConversationThread");
45
+ __name2(isChannelConversationThread, "isChannelConversationThread");
13
46
  function isPersonaTextObject(value3) {
14
47
  if (value3 === null || typeof value3 !== "object" || Array.isArray(value3)) return false;
15
48
  const obj = value3;
@@ -1174,6 +1207,188 @@ function buildPersonalSpaceStartingPersona(agentName) {
1174
1207
  }
1175
1208
  __name(buildPersonalSpaceStartingPersona, "buildPersonalSpaceStartingPersona");
1176
1209
  __name2(buildPersonalSpaceStartingPersona, "buildPersonalSpaceStartingPersona");
1210
+ var AGENT_LOG_SOURCES = [
1211
+ "skill",
1212
+ "job",
1213
+ "webhook",
1214
+ "trigger",
1215
+ "preprocessor",
1216
+ "postprocessor",
1217
+ "user_message",
1218
+ "agent_response",
1219
+ "agent_error",
1220
+ "runtime",
1221
+ "mcp",
1222
+ "rag",
1223
+ "device",
1224
+ "device-trigger",
1225
+ "model-resolver",
1226
+ "workflow-step",
1227
+ "workflow-script",
1228
+ "workflow"
1229
+ ];
1230
+ var LOG_DRAIN_SOURCES = [
1231
+ ...AGENT_LOG_SOURCES,
1232
+ "execution",
1233
+ // ── phase 2 ──
1234
+ "delivery",
1235
+ "trigger-execution",
1236
+ "job-execution",
1237
+ "workflow-run",
1238
+ "workflow-audit"
1239
+ ];
1240
+ var LOG_DRAIN_MAX_PER_ORG = 5;
1241
+ var LOG_DRAIN_MAX_PER_ORG_ENTERPRISE = 10;
1242
+ function maxDrainsForTier(tier) {
1243
+ return tier === "enterprise" ? LOG_DRAIN_MAX_PER_ORG_ENTERPRISE : LOG_DRAIN_MAX_PER_ORG;
1244
+ }
1245
+ __name(maxDrainsForTier, "maxDrainsForTier");
1246
+ __name2(maxDrainsForTier, "maxDrainsForTier");
1247
+ var LOG_DRAIN_ENDPOINT_TEMPLATES = {
1248
+ datadog: "https://http-intake.logs.{site}/api/v2/logs"
1249
+ };
1250
+ function resolvePresetEndpoint(type, site) {
1251
+ const template3 = LOG_DRAIN_ENDPOINT_TEMPLATES[type];
1252
+ if (!template3 || !site) return void 0;
1253
+ return template3.replace("{site}", site);
1254
+ }
1255
+ __name(resolvePresetEndpoint, "resolvePresetEndpoint");
1256
+ __name2(resolvePresetEndpoint, "resolvePresetEndpoint");
1257
+ var LOG_DRAIN_QUOTAS = {
1258
+ team: {
1259
+ eventsPerDay: 1e6,
1260
+ bytesPerDay: 1 * 1024 ** 3
1261
+ },
1262
+ business: {
1263
+ eventsPerDay: 1e7,
1264
+ bytesPerDay: 10 * 1024 ** 3
1265
+ },
1266
+ enterprise: {
1267
+ eventsPerDay: Number.MAX_SAFE_INTEGER,
1268
+ bytesPerDay: Number.MAX_SAFE_INTEGER
1269
+ }
1270
+ };
1271
+ var LOG_DRAIN_QUOTA_WARN_RATIO = 0.8;
1272
+ var LOG_DRAIN_QUOTA_DROP_DEBUG_RATIO = 1;
1273
+ var LOG_DRAIN_QUOTA_DROP_INFO_RATIO = 1.25;
1274
+ var LOG_DRAIN_QUOTA_PAUSE_RATIO = 1.5;
1275
+ function nextLogDrainQuotaResetAt(now) {
1276
+ return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate() + 1)).toISOString();
1277
+ }
1278
+ __name(nextLogDrainQuotaResetAt, "nextLogDrainQuotaResetAt");
1279
+ __name2(nextLogDrainQuotaResetAt, "nextLogDrainQuotaResetAt");
1280
+ function logDrainQuotaWindowExpired(usage, now) {
1281
+ const resetsAt = Date.parse(usage?.resetsAt ?? "");
1282
+ if (!Number.isFinite(resetsAt)) return true;
1283
+ return now.getTime() >= resetsAt;
1284
+ }
1285
+ __name(logDrainQuotaWindowExpired, "logDrainQuotaWindowExpired");
1286
+ __name2(logDrainQuotaWindowExpired, "logDrainQuotaWindowExpired");
1287
+ function logDrainQuotaRatio(usage, now) {
1288
+ if (!usage) return 0;
1289
+ if (now && logDrainQuotaWindowExpired(usage, now)) return 0;
1290
+ const dimension = /* @__PURE__ */ __name2((used, limit) => {
1291
+ if (!Number.isFinite(limit) || limit <= 0) return 0;
1292
+ if (!Number.isFinite(used) || used <= 0) return 0;
1293
+ return used / limit;
1294
+ }, "dimension");
1295
+ return Math.max(dimension(usage.usedEvents, usage.eventsPerDay), dimension(usage.usedBytes, usage.bytesPerDay));
1296
+ }
1297
+ __name(logDrainQuotaRatio, "logDrainQuotaRatio");
1298
+ __name2(logDrainQuotaRatio, "logDrainQuotaRatio");
1299
+ function logDrainQuotaDegradationForRatio(ratio) {
1300
+ if (!Number.isFinite(ratio)) return "none";
1301
+ if (ratio >= LOG_DRAIN_QUOTA_PAUSE_RATIO) return "paused";
1302
+ if (ratio >= LOG_DRAIN_QUOTA_DROP_INFO_RATIO) return "info_dropped";
1303
+ if (ratio >= LOG_DRAIN_QUOTA_DROP_DEBUG_RATIO) return "debug_dropped";
1304
+ return "none";
1305
+ }
1306
+ __name(logDrainQuotaDegradationForRatio, "logDrainQuotaDegradationForRatio");
1307
+ __name2(logDrainQuotaDegradationForRatio, "logDrainQuotaDegradationForRatio");
1308
+ function logDrainQuotaDegradation(usage, now) {
1309
+ return logDrainQuotaDegradationForRatio(logDrainQuotaRatio(usage, now));
1310
+ }
1311
+ __name(logDrainQuotaDegradation, "logDrainQuotaDegradation");
1312
+ __name2(logDrainQuotaDegradation, "logDrainQuotaDegradation");
1313
+ function logDrainQuotaWarned(usage, now) {
1314
+ return logDrainQuotaRatio(usage, now) >= LOG_DRAIN_QUOTA_WARN_RATIO;
1315
+ }
1316
+ __name(logDrainQuotaWarned, "logDrainQuotaWarned");
1317
+ __name2(logDrainQuotaWarned, "logDrainQuotaWarned");
1318
+ function logDrainQuotaDroppedSeverities(degradation) {
1319
+ switch (degradation) {
1320
+ case "debug_dropped":
1321
+ return [
1322
+ 5
1323
+ ];
1324
+ case "info_dropped":
1325
+ return [
1326
+ 5,
1327
+ 9
1328
+ ];
1329
+ default:
1330
+ return [];
1331
+ }
1332
+ }
1333
+ __name(logDrainQuotaDroppedSeverities, "logDrainQuotaDroppedSeverities");
1334
+ __name2(logDrainQuotaDroppedSeverities, "logDrainQuotaDroppedSeverities");
1335
+ var LOG_CURSOR_MAX_LENGTH = 512;
1336
+ var LOG_CURSOR_MAX_ID_LENGTH = 128;
1337
+ var LOG_RELATIVE_TIME_PATTERN = /^(\d{1,9})([smhd])$/;
1338
+ var LOG_ISO_TIME_PATTERN = /^\d{4}-\d{2}-\d{2}([Tt ]\d{2}:\d{2}(:\d{2}(\.\d{1,9})?)?([Zz]|[+-]\d{2}:?\d{2})?)?$/;
1339
+ var RELATIVE_UNIT_MS = {
1340
+ s: 1e3,
1341
+ m: 6e4,
1342
+ h: 36e5,
1343
+ d: 864e5
1344
+ };
1345
+ function encodeLogCursor(c) {
1346
+ return Buffer.from(JSON.stringify({
1347
+ t: c.t,
1348
+ id: c.id
1349
+ }), "utf8").toString("base64url");
1350
+ }
1351
+ __name(encodeLogCursor, "encodeLogCursor");
1352
+ __name2(encodeLogCursor, "encodeLogCursor");
1353
+ function decodeLogCursor(raw) {
1354
+ if (typeof raw !== "string") return null;
1355
+ const trimmed = raw.trim();
1356
+ if (!trimmed || trimmed.length > LOG_CURSOR_MAX_LENGTH) return null;
1357
+ let parsed;
1358
+ try {
1359
+ parsed = JSON.parse(Buffer.from(trimmed, "base64url").toString("utf8"));
1360
+ } catch {
1361
+ return null;
1362
+ }
1363
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return null;
1364
+ const { t, id } = parsed;
1365
+ if (typeof t !== "number" || !Number.isSafeInteger(t) || t < 0) return null;
1366
+ if (typeof id !== "string" || !id || id.length > LOG_CURSOR_MAX_ID_LENGTH) return null;
1367
+ return {
1368
+ t,
1369
+ id
1370
+ };
1371
+ }
1372
+ __name(decodeLogCursor, "decodeLogCursor");
1373
+ __name2(decodeLogCursor, "decodeLogCursor");
1374
+ function parseLogTimeBound(raw, now = /* @__PURE__ */ new Date()) {
1375
+ if (typeof raw !== "string") return null;
1376
+ const value3 = raw.trim();
1377
+ if (!value3) return null;
1378
+ const relative = LOG_RELATIVE_TIME_PATTERN.exec(value3);
1379
+ if (relative) {
1380
+ const amount = Number(relative[1]);
1381
+ const unitMs = RELATIVE_UNIT_MS[relative[2]];
1382
+ if (!Number.isFinite(amount) || unitMs === void 0) return null;
1383
+ const at2 = now.getTime() - amount * unitMs;
1384
+ return Number.isFinite(at2) ? new Date(at2) : null;
1385
+ }
1386
+ if (!LOG_ISO_TIME_PATTERN.test(value3)) return null;
1387
+ const at = Date.parse(value3);
1388
+ return Number.isNaN(at) ? null : new Date(at);
1389
+ }
1390
+ __name(parseLogTimeBound, "parseLogTimeBound");
1391
+ __name2(parseLogTimeBound, "parseLogTimeBound");
1177
1392
  var CORE_DRAINING_CODE = "CORE_DRAINING";
1178
1393
  var CORE_DRAINING_DEFAULT_RETRY_MS = 1e3;
1179
1394
  var CORE_DRAINING_MAX_RETRY_MS = 5e3;
@@ -2279,6 +2494,19 @@ function workflowOrgSlotKey(orgId, kind) {
2279
2494
  __name(workflowOrgSlotKey, "workflowOrgSlotKey");
2280
2495
  __name2(workflowOrgSlotKey, "workflowOrgSlotKey");
2281
2496
  var WORKFLOW_CONNECTION_KEY_RE = /^[a-z][a-z0-9_-]{0,63}$/;
2497
+ var WORKFLOW_JOB_MODEL_SOURCE_LABELS = {
2498
+ stamp: "lease stamp",
2499
+ initData: "run input",
2500
+ default: "placeholder default",
2501
+ node: "node.model",
2502
+ env: "platform default",
2503
+ org: "org default"
2504
+ };
2505
+ function workflowJobModelSourceLabel(source) {
2506
+ return WORKFLOW_JOB_MODEL_SOURCE_LABELS[source];
2507
+ }
2508
+ __name(workflowJobModelSourceLabel, "workflowJobModelSourceLabel");
2509
+ __name2(workflowJobModelSourceLabel, "workflowJobModelSourceLabel");
2282
2510
  function scheduledTimeKey(scheduledTime) {
2283
2511
  return scheduledTime.replace(/[^0-9TZ]/g, "");
2284
2512
  }
@@ -2601,7 +2829,23 @@ var WORKFLOW_AUDIT_EVENTS = [
2601
2829
  * gated and nobody approved it, and conflating the two would make "who approved this run"
2602
2830
  * unanswerable for every run of either kind (§H2 "Audit").
2603
2831
  */
2604
- "workflow.run.autonomy_applied"
2832
+ "workflow.run.autonomy_applied",
2833
+ // --- run budget cap enforcement (Job-tier billing plan D4; BAC-677) ---
2834
+ /**
2835
+ * The audit twin of the `run.budget_exceeded` run event (WJB-B2a): the run overshot its
2836
+ * `budget.maxCredits` on its LAST step and completed anyway, `budget.exceeded: true`. The budget family
2837
+ * already mirrors run events here — `workflow.run.budget_parked` / `workflow.run.budget_raised` are the
2838
+ * twins of `run.budget_parked` / `run.budget_raised` — and an organisation reviewing what it was charged
2839
+ * needs the overshoot in the audit store beside the raise that preceded it, not only in the run's own
2840
+ * event stream.
2841
+ *
2842
+ * Declared with the run event rather than after it because the emitter port
2843
+ * (`WorkflowAuditPort.action`, typed `workflow.run.${string}`) does not check against this tuple: a name
2844
+ * that is NOT declared here is written to the audit store all the same and no compiler says so.
2845
+ * Declaring it is what makes the later emitter checkable. `workflow.run.budget_parked` is likewise
2846
+ * declared and not yet emitted.
2847
+ */
2848
+ "workflow.run.budget_exceeded"
2605
2849
  ];
2606
2850
  var WORKFLOW_AUDIT_METADATA_MAX_BYTES = 4 * 1024;
2607
2851
  function isWorkflowAuditEvent(action) {
@@ -7245,6 +7489,55 @@ function graphHasJobTierStep(envelopeOrGraph) {
7245
7489
  }
7246
7490
  __name(graphHasJobTierStep, "graphHasJobTierStep");
7247
7491
  __name4(graphHasJobTierStep, "graphHasJobTierStep");
7492
+ function jobTierSteps(envelopeOrGraph) {
7493
+ const out = [];
7494
+ if (!envelopeOrGraph || typeof envelopeOrGraph !== "object") return out;
7495
+ const env = envelopeOrGraph;
7496
+ const graph = Array.isArray(envelopeOrGraph) ? envelopeOrGraph : env.definition?.graph ?? [];
7497
+ if (!Array.isArray(graph)) return out;
7498
+ for (const entry of graph) collectJobTierSteps(entry, out);
7499
+ return out;
7500
+ }
7501
+ __name(jobTierSteps, "jobTierSteps");
7502
+ __name4(jobTierSteps, "jobTierSteps");
7503
+ function jobTierStepIds(envelopeOrGraph) {
7504
+ return jobTierSteps(envelopeOrGraph).map((s) => s.stepId);
7505
+ }
7506
+ __name(jobTierStepIds, "jobTierStepIds");
7507
+ __name4(jobTierStepIds, "jobTierStepIds");
7508
+ function collectJobTierSteps(entry, out) {
7509
+ const n2 = armEntry2(entry);
7510
+ if (!n2 || typeof n2 !== "object") return;
7511
+ const node = n2;
7512
+ const ws = node.workspace;
7513
+ if (node.tier === "job" || ws !== void 0 && ws !== "inherit") {
7514
+ const stepId = typeof node.id === "string" && node.id ? node.id : "(unnamed)";
7515
+ const model = typeof node.model === "string" && node.model.trim() ? node.model.trim() : void 0;
7516
+ out.push(model === void 0 ? {
7517
+ stepId
7518
+ } : {
7519
+ stepId,
7520
+ model
7521
+ });
7522
+ }
7523
+ switch (node.type) {
7524
+ case "parallel":
7525
+ if (Array.isArray(node.steps)) for (const s of node.steps) collectJobTierSteps(s, out);
7526
+ return;
7527
+ case "conditional":
7528
+ if (Array.isArray(node.steps)) for (const s of node.steps) collectJobTierSteps(s, out);
7529
+ if (node.otherwise !== void 0) collectJobTierSteps(node.otherwise, out);
7530
+ return;
7531
+ case "foreach":
7532
+ case "loop":
7533
+ collectJobTierSteps(node.step, out);
7534
+ return;
7535
+ default:
7536
+ return;
7537
+ }
7538
+ }
7539
+ __name(collectJobTierSteps, "collectJobTierSteps");
7540
+ __name4(collectJobTierSteps, "collectJobTierSteps");
7248
7541
 
7249
7542
  // src/types/workflow.ts
7250
7543
  function createStep(s) {