lua-cli 3.48.0 → 3.49.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.
@@ -1188,6 +1188,31 @@ var DECISION_PROVIDERS = [
1188
1188
  "openai"
1189
1189
  ];
1190
1190
  var DECISION_NAME_PATTERN = /^[a-zA-Z0-9_-]{1,64}$/;
1191
+ var DECISION_SANDBOX_TOOL_SEPARATOR = "#";
1192
+ function formatDecisionSandboxPrimitive(name, tool) {
1193
+ return tool ? `${name}${DECISION_SANDBOX_TOOL_SEPARATOR}${tool}` : name;
1194
+ }
1195
+ __name(formatDecisionSandboxPrimitive, "formatDecisionSandboxPrimitive");
1196
+ __name4(formatDecisionSandboxPrimitive, "formatDecisionSandboxPrimitive");
1197
+ function parseDecisionSandboxPrimitive(value3) {
1198
+ const at = value3.indexOf(DECISION_SANDBOX_TOOL_SEPARATOR);
1199
+ const name = at < 0 ? value3 : value3.slice(0, at);
1200
+ const tool = at < 0 ? "" : value3.slice(at + DECISION_SANDBOX_TOOL_SEPARATOR.length);
1201
+ if (name.length === 0) return void 0;
1202
+ return tool.length > 0 ? {
1203
+ name,
1204
+ tool
1205
+ } : {
1206
+ name
1207
+ };
1208
+ }
1209
+ __name(parseDecisionSandboxPrimitive, "parseDecisionSandboxPrimitive");
1210
+ __name4(parseDecisionSandboxPrimitive, "parseDecisionSandboxPrimitive");
1211
+ function decisionPublishStampKey(agentId2) {
1212
+ return `decisions:stamp:${agentId2}`;
1213
+ }
1214
+ __name(decisionPublishStampKey, "decisionPublishStampKey");
1215
+ __name4(decisionPublishStampKey, "decisionPublishStampKey");
1191
1216
  var DECISION_LIMITS = {
1192
1217
  maxQuestions: 64,
1193
1218
  minOptions: 2,
@@ -1195,6 +1220,7 @@ var DECISION_LIMITS = {
1195
1220
  minLevels: 2,
1196
1221
  maxLevels: 10,
1197
1222
  maxInstructionChars: 4e3,
1223
+ maxQuestionsChars: 1e5,
1198
1224
  maxStateChars: 12e4,
1199
1225
  maxImages: 4,
1200
1226
  maxImageBytes: 5 * 1024 * 1024,
@@ -1260,7 +1286,14 @@ var DecisionOptionsSchema = z.object({
1260
1286
  "none"
1261
1287
  ]).optional()
1262
1288
  });
1263
- var DecisionQuestionsSchema = z.record(NameSchema, DecisionQuestionSchema).refine((questions) => Object.keys(questions).length >= 1 && Object.keys(questions).length <= DECISION_LIMITS.maxQuestions, `a decision needs between 1 and ${DECISION_LIMITS.maxQuestions} questions`);
1289
+ var DecisionQuestionsSchema = z.record(NameSchema, DecisionQuestionSchema).refine((questions) => Object.keys(questions).length >= 1 && Object.keys(questions).length <= DECISION_LIMITS.maxQuestions, `a decision needs between 1 and ${DECISION_LIMITS.maxQuestions} questions`).superRefine((questions, ctx) => {
1290
+ const chars = JSON.stringify(questions).length;
1291
+ if (chars <= DECISION_LIMITS.maxQuestionsChars) return;
1292
+ ctx.addIssue({
1293
+ code: z.ZodIssueCode.custom,
1294
+ message: `the questions take ${chars} characters as JSON, more than the ${DECISION_LIMITS.maxQuestionsChars} characters a decision may hold`
1295
+ });
1296
+ });
1264
1297
  var DecisionDefinitionSchema = DecisionOptionsSchema.extend({
1265
1298
  name: z.string().regex(DECISION_NAME_PATTERN, "a decision name is 1 to 64 letters, digits, underscores or hyphens"),
1266
1299
  description: z.string().max(DECISION_LIMITS.maxInstructionChars).optional(),
@@ -1351,6 +1384,158 @@ function supervisionSubjectId(agentId2) {
1351
1384
  }
1352
1385
  __name(supervisionSubjectId, "supervisionSubjectId");
1353
1386
  __name4(supervisionSubjectId, "supervisionSubjectId");
1387
+ var MESSAGING_CHANNELS = new Set(CHANNEL_CONVERSATION_CHANNELS);
1388
+ var VOICE_CHANNELS = /* @__PURE__ */ new Set([
1389
+ "phone",
1390
+ "meeting",
1391
+ "voice"
1392
+ ]);
1393
+ var TURN_CATEGORIES = /* @__PURE__ */ new Set([
1394
+ "llm:inference",
1395
+ "llm:chat-modes",
1396
+ "llm:delegation",
1397
+ "decision:ask"
1398
+ ]);
1399
+ var AGENT_TOOL_CATEGORIES = /* @__PURE__ */ new Set([
1400
+ "llm:media:describe",
1401
+ "tool:image-generate",
1402
+ "tool:image-edit"
1403
+ ]);
1404
+ function isModelCallCategory(category) {
1405
+ return category.startsWith("llm:") || category.startsWith("voice:") || category === "embedding" || category === "workflow:job" || category === "decision:ask" || category.startsWith("tool:image-");
1406
+ }
1407
+ __name(isModelCallCategory, "isModelCallCategory");
1408
+ __name4(isModelCallCategory, "isModelCallCategory");
1409
+ function deriveUsageSurface(row) {
1410
+ const { category, channel } = row;
1411
+ const data = row.data;
1412
+ if (!isModelCallCategory(category)) return void 0;
1413
+ if (category === "workflow:job") return "workflow-job";
1414
+ if (category === "llm:sandbox") return "tool-code";
1415
+ if (category === "llm:builder") return "builder";
1416
+ if (category === "llm:website") return "website";
1417
+ if (category.startsWith("voice:") || category === "llm:voice") return "voice";
1418
+ if (category.startsWith("llm:tool:") || AGENT_TOOL_CATEGORIES.has(category)) return "agent-tool";
1419
+ if (!TURN_CATEGORIES.has(category)) return "background";
1420
+ if (channel === "workflow") return "workflow-step";
1421
+ if (data?.gateway === "livekit-inference") return "voice";
1422
+ if (channel === "dev") return "dev";
1423
+ if (channel && VOICE_CHANNELS.has(channel)) return "voice";
1424
+ if (channel && MESSAGING_CHANNELS.has(channel)) return "channel";
1425
+ return "chat";
1426
+ }
1427
+ __name(deriveUsageSurface, "deriveUsageSurface");
1428
+ __name4(deriveUsageSurface, "deriveUsageSurface");
1429
+ var count = /* @__PURE__ */ __name4((v) => typeof v === "number" && Number.isFinite(v) && v >= 0 ? Math.floor(v) : void 0, "count");
1430
+ function fromRaw(raw, id2, model) {
1431
+ const fiveMin = count(raw.cache_creation?.ephemeral_5m_input_tokens);
1432
+ const oneHour = count(raw.cache_creation?.ephemeral_1h_input_tokens);
1433
+ const split = !!(fiveMin || oneHour);
1434
+ const flatWrite = count(raw.cache_creation_input_tokens);
1435
+ const read = count(raw.cache_read_input_tokens);
1436
+ return {
1437
+ ...typeof id2 === "string" && id2 ? {
1438
+ id: id2
1439
+ } : {},
1440
+ ...typeof model === "string" && model ? {
1441
+ model
1442
+ } : {},
1443
+ inputTokens: count(raw.input_tokens) ?? 0,
1444
+ outputTokens: count(raw.output_tokens) ?? 0,
1445
+ ...read ? {
1446
+ cacheReadTokens: read
1447
+ } : {},
1448
+ ...split ? {
1449
+ ...fiveMin ? {
1450
+ cacheCreationTokens5m: fiveMin
1451
+ } : {},
1452
+ ...oneHour ? {
1453
+ cacheCreationTokens1h: oneHour
1454
+ } : {}
1455
+ } : flatWrite ? {
1456
+ cacheCreationTokens: flatWrite
1457
+ } : {},
1458
+ ...typeof raw.service_tier === "string" && raw.service_tier && raw.service_tier !== "standard" ? {
1459
+ serviceTier: raw.service_tier
1460
+ } : {}
1461
+ };
1462
+ }
1463
+ __name(fromRaw, "fromRaw");
1464
+ __name4(fromRaw, "fromRaw");
1465
+ function anthropicMessageUsage(message) {
1466
+ if (!message || typeof message !== "object") return void 0;
1467
+ const m = message;
1468
+ if (!m.usage || typeof m.usage !== "object") return void 0;
1469
+ return fromRaw(m.usage, m.id, m.model);
1470
+ }
1471
+ __name(anthropicMessageUsage, "anthropicMessageUsage");
1472
+ __name4(anthropicMessageUsage, "anthropicMessageUsage");
1473
+ var AnthropicSseUsageReader = class {
1474
+ static {
1475
+ __name(this, "AnthropicSseUsageReader");
1476
+ }
1477
+ static {
1478
+ __name4(this, "AnthropicSseUsageReader");
1479
+ }
1480
+ pending = "";
1481
+ raw;
1482
+ id;
1483
+ model;
1484
+ push(chunk) {
1485
+ const text2 = this.pending + chunk;
1486
+ const lines = text2.split("\n");
1487
+ this.pending = lines.pop() ?? "";
1488
+ for (const line of lines) this.line(line);
1489
+ }
1490
+ result() {
1491
+ if (this.pending) {
1492
+ this.line(this.pending);
1493
+ this.pending = "";
1494
+ }
1495
+ return this.raw ? fromRaw(this.raw, this.id, this.model) : void 0;
1496
+ }
1497
+ line(line) {
1498
+ const trimmed = line.trim();
1499
+ if (!trimmed.startsWith("data:")) return;
1500
+ let event;
1501
+ try {
1502
+ event = JSON.parse(trimmed.slice(5).trim());
1503
+ } catch {
1504
+ return;
1505
+ }
1506
+ if (event.type === "message_start" && event.message) {
1507
+ this.id = event.message.id;
1508
+ this.model = event.message.model;
1509
+ this.raw = {
1510
+ ...event.message.usage ?? {}
1511
+ };
1512
+ } else if (event.type === "message_delta" && event.usage && typeof event.usage === "object") {
1513
+ const delta = event.usage;
1514
+ const merged = {
1515
+ ...this.raw ?? {}
1516
+ };
1517
+ for (const [key, value3] of Object.entries(delta)) {
1518
+ if (value3 !== null && value3 !== void 0) merged[key] = value3;
1519
+ }
1520
+ this.raw = merged;
1521
+ }
1522
+ }
1523
+ };
1524
+ function parseAnthropicReplyUsage(body) {
1525
+ const start = body.trimStart();
1526
+ if (start.startsWith("{")) {
1527
+ try {
1528
+ return anthropicMessageUsage(JSON.parse(start));
1529
+ } catch {
1530
+ return void 0;
1531
+ }
1532
+ }
1533
+ const reader = new AnthropicSseUsageReader();
1534
+ reader.push(body);
1535
+ return reader.result();
1536
+ }
1537
+ __name(parseAnthropicReplyUsage, "parseAnthropicReplyUsage");
1538
+ __name4(parseAnthropicReplyUsage, "parseAnthropicReplyUsage");
1354
1539
  var SUPERVISION_OPS = {
1355
1540
  "agents.list": "discover",
1356
1541
  "agents.get": "discover",
@@ -3430,24 +3615,24 @@ __name4(addresses, "addresses");
3430
3615
  function recordFacts(value3) {
3431
3616
  const senders = [];
3432
3617
  const labels = [];
3433
- let isRecord22 = false;
3618
+ let isRecord32 = false;
3434
3619
  if (isPlainObject(value3.author_member)) {
3435
- isRecord22 = true;
3620
+ isRecord32 = true;
3436
3621
  const email = lower(value3.author_member.email);
3437
3622
  if (email) senders.push(email);
3438
3623
  const userId = lower(value3.author_member.user_id);
3439
3624
  if (userId) senders.push(userId);
3440
3625
  }
3441
3626
  if (typeof value3.channel_id === "string") {
3442
- isRecord22 = true;
3627
+ isRecord32 = true;
3443
3628
  labels.push(...idOrName(value3.channel_id));
3444
3629
  }
3445
3630
  if (Array.isArray(value3.channel_ids)) {
3446
- isRecord22 = true;
3631
+ isRecord32 = true;
3447
3632
  for (const id2 of value3.channel_ids) labels.push(...idOrName(id2));
3448
3633
  }
3449
3634
  if (Array.isArray(value3.channels) && (value3.author_member || value3.message !== void 0)) {
3450
- isRecord22 = true;
3635
+ isRecord32 = true;
3451
3636
  for (const channel of value3.channels) labels.push(...idOrName(channel));
3452
3637
  }
3453
3638
  for (const key of [
@@ -3456,11 +3641,11 @@ function recordFacts(value3) {
3456
3641
  ]) {
3457
3642
  const field = value3[key];
3458
3643
  if (isPlainObject(field) && isPlainObject(field.emailAddress)) {
3459
- isRecord22 = true;
3644
+ isRecord32 = true;
3460
3645
  const address = lower(field.emailAddress.address);
3461
3646
  if (address) senders.push(address);
3462
3647
  } else if (key === "from" && typeof field === "string" && field.includes("@")) {
3463
- isRecord22 = true;
3648
+ isRecord32 = true;
3464
3649
  senders.push(...addresses(field));
3465
3650
  }
3466
3651
  }
@@ -3468,12 +3653,12 @@ function recordFacts(value3) {
3468
3653
  const organizer = value3.organizer;
3469
3654
  const address = isPlainObject(organizer.emailAddress) ? lower(organizer.emailAddress.address) : lower(organizer.email);
3470
3655
  if (address) {
3471
- isRecord22 = true;
3656
+ isRecord32 = true;
3472
3657
  senders.push(address);
3473
3658
  }
3474
3659
  }
3475
3660
  if (Array.isArray(value3.categories)) {
3476
- isRecord22 = true;
3661
+ isRecord32 = true;
3477
3662
  for (const category of value3.categories) labels.push(...idOrName(category));
3478
3663
  }
3479
3664
  if (isPlainObject(value3.from)) {
@@ -3484,13 +3669,13 @@ function recordFacts(value3) {
3484
3669
  ]) {
3485
3670
  const identity = value3.from[key];
3486
3671
  if (!isPlainObject(identity)) continue;
3487
- isRecord22 = true;
3672
+ isRecord32 = true;
3488
3673
  const id2 = lower(identity.id);
3489
3674
  if (id2) senders.push(id2);
3490
3675
  }
3491
3676
  }
3492
3677
  if (isPlainObject(value3.channelIdentity)) {
3493
- isRecord22 = true;
3678
+ isRecord32 = true;
3494
3679
  for (const key of [
3495
3680
  "channelId",
3496
3681
  "teamId"
@@ -3500,21 +3685,21 @@ function recordFacts(value3) {
3500
3685
  }
3501
3686
  }
3502
3687
  if (typeof value3.chatId === "string") {
3503
- isRecord22 = true;
3688
+ isRecord32 = true;
3504
3689
  labels.push(...idOrName(value3.chatId));
3505
3690
  }
3506
3691
  if (typeof value3.parentFolderId === "string") {
3507
- isRecord22 = true;
3692
+ isRecord32 = true;
3508
3693
  labels.push(...idOrName(value3.parentFolderId));
3509
3694
  }
3510
3695
  let gmailSenderUnknown = false;
3511
3696
  const gmailMessage = typeof value3.threadId === "string" && (Array.isArray(value3.labelIds) || "payload" in value3 || "raw" in value3) || isPlainObject(value3.payload) && Array.isArray(value3.payload.headers);
3512
3697
  if (Array.isArray(value3.labelIds)) {
3513
- isRecord22 = true;
3698
+ isRecord32 = true;
3514
3699
  for (const id2 of value3.labelIds) labels.push(...idOrName(id2));
3515
3700
  }
3516
3701
  if (gmailMessage) {
3517
- isRecord22 = true;
3702
+ isRecord32 = true;
3518
3703
  const headers = isPlainObject(value3.payload) && Array.isArray(value3.payload.headers) ? value3.payload.headers : [];
3519
3704
  const from = headers.find((header) => isPlainObject(header) && lower(header.name) === "from");
3520
3705
  const fromAddresses = addresses(from?.value);
@@ -3522,11 +3707,11 @@ function recordFacts(value3) {
3522
3707
  else gmailSenderUnknown = true;
3523
3708
  }
3524
3709
  if (Array.isArray(value3.labels)) {
3525
- isRecord22 = true;
3710
+ isRecord32 = true;
3526
3711
  for (const label of value3.labels) labels.push(...idOrName(label));
3527
3712
  }
3528
3713
  if (typeof value3.ts === "string" && (typeof value3.user === "string" || typeof value3.bot_id === "string")) {
3529
- isRecord22 = true;
3714
+ isRecord32 = true;
3530
3715
  for (const id2 of [
3531
3716
  value3.user,
3532
3717
  value3.bot_id,
@@ -3542,7 +3727,7 @@ function recordFacts(value3) {
3542
3727
  labels.push(...idOrName(value3.channel));
3543
3728
  }
3544
3729
  return {
3545
- isRecord: isRecord22,
3730
+ isRecord: isRecord32,
3546
3731
  senders,
3547
3732
  labels,
3548
3733
  gmailSenderUnknown
@@ -6477,6 +6662,10 @@ var BROWSER_COMMANDS = [
6477
6662
  name: "close",
6478
6663
  description: "Close the session\u2019s browser."
6479
6664
  },
6665
+ {
6666
+ name: "read",
6667
+ description: "Read one page in a fresh session that is closed afterwards: open the URL, wait, return its title and content. Args: url, waitFor?(load|networkidle|selector), selector?, format?(text|html|markdown), timeoutMs?."
6668
+ },
6480
6669
  // perception
6481
6670
  {
6482
6671
  name: "snapshot",
@@ -6650,6 +6839,91 @@ var BROWSER_COMMANDS = [
6650
6839
  }
6651
6840
  ];
6652
6841
  var BROWSER_COMMAND_NAMES = BROWSER_COMMANDS.map((c) => c.name);
6842
+ var SERVER_TRIGGERED_BROWSER_SOURCES = [
6843
+ "job",
6844
+ "webhook",
6845
+ "web-route",
6846
+ "trigger",
6847
+ "workflow-step",
6848
+ "workflow-script"
6849
+ ];
6850
+ function isServerTriggeredBrowserSource(logSource) {
6851
+ return SERVER_TRIGGERED_BROWSER_SOURCES.includes(logSource);
6852
+ }
6853
+ __name(isServerTriggeredBrowserSource, "isServerTriggeredBrowserSource");
6854
+ __name4(isServerTriggeredBrowserSource, "isServerTriggeredBrowserSource");
6855
+ var BROWSER_FALLBACKS = [
6856
+ "browser-use",
6857
+ "none"
6858
+ ];
6859
+ var DEFAULT_BROWSER_FALLBACK = "browser-use";
6860
+ function resolveBrowserFallback(raw) {
6861
+ return BROWSER_FALLBACKS.includes(raw) ? raw : DEFAULT_BROWSER_FALLBACK;
6862
+ }
6863
+ __name(resolveBrowserFallback, "resolveBrowserFallback");
6864
+ __name4(resolveBrowserFallback, "resolveBrowserFallback");
6865
+ var PROXY_COUNTRY_CODE = /^[a-z]{2}$/;
6866
+ function resolveBrowserProxyCountry(raw) {
6867
+ if (typeof raw !== "string") return void 0;
6868
+ const code = raw.trim().toLowerCase();
6869
+ return PROXY_COUNTRY_CODE.test(code) ? code : void 0;
6870
+ }
6871
+ __name(resolveBrowserProxyCountry, "resolveBrowserProxyCountry");
6872
+ __name4(resolveBrowserProxyCountry, "resolveBrowserProxyCountry");
6873
+ var BROWSER_LOG_CONTENT_MODES = [
6874
+ "summary",
6875
+ "full",
6876
+ "none"
6877
+ ];
6878
+ var DEFAULT_BROWSER_LOG_CONTENT = "summary";
6879
+ var BROWSER_SCREENSHOT_POLICIES = [
6880
+ "always",
6881
+ "onError",
6882
+ "never"
6883
+ ];
6884
+ var DEFAULT_BROWSER_SCREENSHOT_POLICY = "onError";
6885
+ function resolveBrowserLogOptions(raw) {
6886
+ const logContent = BROWSER_LOG_CONTENT_MODES.includes(raw.logContent) ? raw.logContent : DEFAULT_BROWSER_LOG_CONTENT;
6887
+ const screenshots = BROWSER_SCREENSHOT_POLICIES.includes(raw.screenshots) ? raw.screenshots : DEFAULT_BROWSER_SCREENSHOT_POLICY;
6888
+ return {
6889
+ logContent,
6890
+ screenshots
6891
+ };
6892
+ }
6893
+ __name(resolveBrowserLogOptions, "resolveBrowserLogOptions");
6894
+ __name4(resolveBrowserLogOptions, "resolveBrowserLogOptions");
6895
+ function browserProfileNotFoundMessage(name) {
6896
+ return `No browser named '${name}' is attached to this agent. Add it to the agent's \`browsers\` list and push again.`;
6897
+ }
6898
+ __name(browserProfileNotFoundMessage, "browserProfileNotFoundMessage");
6899
+ __name4(browserProfileNotFoundMessage, "browserProfileNotFoundMessage");
6900
+ var BROWSER_LIMIT_KEYS = [
6901
+ "maxSessionMinutes",
6902
+ "idleTimeoutSeconds",
6903
+ "maxConcurrentSessions"
6904
+ ];
6905
+ var BROWSER_LIMIT_MAX = {
6906
+ maxSessionMinutes: 60,
6907
+ idleTimeoutSeconds: 15 * 60,
6908
+ maxConcurrentSessions: 100
6909
+ };
6910
+ function resolveBrowserLimits(pick) {
6911
+ const limits = {};
6912
+ for (const key of BROWSER_LIMIT_KEYS) {
6913
+ const value3 = pick(key);
6914
+ if (typeof value3 === "number" && Number.isInteger(value3) && value3 > 0) limits[key] = value3;
6915
+ }
6916
+ return limits;
6917
+ }
6918
+ __name(resolveBrowserLimits, "resolveBrowserLimits");
6919
+ __name4(resolveBrowserLimits, "resolveBrowserLimits");
6920
+ var BROWSER_EXECUTE_METHOD = "execute";
6921
+ var BROWSER_GLOBAL_METHODS = [
6922
+ ...BROWSER_COMMAND_NAMES,
6923
+ BROWSER_EXECUTE_METHOD
6924
+ ];
6925
+ var BROWSER_EXECUTE_DEFAULT_TIMEOUT_MS = 5 * 60 * 1e3;
6926
+ var BROWSER_EXECUTE_MAX_TIMEOUT_MS = 15 * 60 * 1e3;
6653
6927
  var LOG_FIELDS_MAX_KEYS = 32;
6654
6928
  var LOG_FIELD_MAX_VALUE_BYTES = 1024;
6655
6929
  var LOG_FIELDS_MAX_BYTES = 8192;
@@ -6870,6 +7144,640 @@ function isDesktopFileSessionId(value3) {
6870
7144
  }
6871
7145
  __name(isDesktopFileSessionId, "isDesktopFileSessionId");
6872
7146
  __name4(isDesktopFileSessionId, "isDesktopFileSessionId");
7147
+ var BROWSER_READ_FORMATS = [
7148
+ "text",
7149
+ "html",
7150
+ "markdown"
7151
+ ];
7152
+ var BROWSER_READ_DEFAULT_TIMEOUT_MS = 6e4;
7153
+ var BROWSER_READ_MIN_TIMEOUT_MS = 1e3;
7154
+ var BROWSER_READ_MAX_TIMEOUT_MS = 1e5;
7155
+ var BROWSER_READ_MAX_CONTENT_CHARS = 1e5;
7156
+ var BROWSER_READ_DEFAULT_SELECTOR = "body";
7157
+ var BROWSER_READ_MATCH_SEPARATOR = "\n\n";
7158
+ var BROWSER_READ_LOGIN_BLOCKER = "login_required";
7159
+ var BROWSER_ERROR_NAME = "BrowserError";
7160
+ function browserError(code, message, status) {
7161
+ return Object.assign(new Error(message), {
7162
+ name: BROWSER_ERROR_NAME,
7163
+ code,
7164
+ ...typeof status === "number" ? {
7165
+ status
7166
+ } : {}
7167
+ });
7168
+ }
7169
+ __name(browserError, "browserError");
7170
+ __name4(browserError, "browserError");
7171
+ function isRecord(value3) {
7172
+ return typeof value3 === "object" && value3 !== null && !Array.isArray(value3);
7173
+ }
7174
+ __name(isRecord, "isRecord");
7175
+ __name4(isRecord, "isRecord");
7176
+ function optionalString(raw, field) {
7177
+ const value3 = raw[field];
7178
+ if (value3 === void 0 || value3 === null || value3 === "") return void 0;
7179
+ if (typeof value3 !== "string") throw new TypeError(`${field} must be a string`);
7180
+ if (value3.startsWith("-")) throw new TypeError(`${field} may not start with '-'`);
7181
+ if (value3.includes("\0")) throw new TypeError(`${field} may not contain NUL`);
7182
+ return value3;
7183
+ }
7184
+ __name(optionalString, "optionalString");
7185
+ __name4(optionalString, "optionalString");
7186
+ function readUrl(value3) {
7187
+ if (typeof value3 !== "string" || !/^https?:\/\//i.test(value3.trim()) || value3.includes("\0")) {
7188
+ throw new TypeError("url must be an absolute http(s) URL");
7189
+ }
7190
+ return value3.trim();
7191
+ }
7192
+ __name(readUrl, "readUrl");
7193
+ __name4(readUrl, "readUrl");
7194
+ function readFormat(value3) {
7195
+ if (value3 === void 0 || value3 === null || value3 === "") return "text";
7196
+ if (!BROWSER_READ_FORMATS.includes(value3)) {
7197
+ throw new TypeError(`format must be one of: ${BROWSER_READ_FORMATS.join(", ")}`);
7198
+ }
7199
+ return value3;
7200
+ }
7201
+ __name(readFormat, "readFormat");
7202
+ __name4(readFormat, "readFormat");
7203
+ function readTimeout(value3) {
7204
+ if (value3 === void 0 || value3 === null) return BROWSER_READ_DEFAULT_TIMEOUT_MS;
7205
+ if (typeof value3 !== "number" || !Number.isFinite(value3)) throw new TypeError("timeoutMs must be a number");
7206
+ return Math.min(BROWSER_READ_MAX_TIMEOUT_MS, Math.max(BROWSER_READ_MIN_TIMEOUT_MS, Math.round(value3)));
7207
+ }
7208
+ __name(readTimeout, "readTimeout");
7209
+ __name4(readTimeout, "readTimeout");
7210
+ function parseBrowserReadPayload(raw) {
7211
+ try {
7212
+ const input = isRecord(raw) ? raw : {};
7213
+ const waitFor = optionalString(input, "waitFor");
7214
+ return {
7215
+ payload: {
7216
+ url: readUrl(input.url),
7217
+ ...waitFor ? {
7218
+ waitFor
7219
+ } : {},
7220
+ selector: optionalString(input, "selector") ?? BROWSER_READ_DEFAULT_SELECTOR,
7221
+ format: readFormat(input.format),
7222
+ timeoutMs: readTimeout(input.timeoutMs)
7223
+ }
7224
+ };
7225
+ } catch (error) {
7226
+ return {
7227
+ error: {
7228
+ code: "invalid_argument",
7229
+ message: `read: ${error.message}`
7230
+ }
7231
+ };
7232
+ }
7233
+ }
7234
+ __name(parseBrowserReadPayload, "parseBrowserReadPayload");
7235
+ __name4(parseBrowserReadPayload, "parseBrowserReadPayload");
7236
+ function clampBrowserReadContent(content, maxChars = BROWSER_READ_MAX_CONTENT_CHARS) {
7237
+ if (content.length <= maxChars) return {
7238
+ content,
7239
+ truncated: false
7240
+ };
7241
+ return {
7242
+ content: content.slice(0, maxChars),
7243
+ truncated: true
7244
+ };
7245
+ }
7246
+ __name(clampBrowserReadContent, "clampBrowserReadContent");
7247
+ __name4(clampBrowserReadContent, "clampBrowserReadContent");
7248
+ function joinBrowserReadMatches(parts, maxChars = BROWSER_READ_MAX_CONTENT_CHARS) {
7249
+ const kept = parts.map((part) => part.trim()).filter((part) => part.length > 0);
7250
+ return clampBrowserReadContent(kept.join(BROWSER_READ_MATCH_SEPARATOR), maxChars);
7251
+ }
7252
+ __name(joinBrowserReadMatches, "joinBrowserReadMatches");
7253
+ __name4(joinBrowserReadMatches, "joinBrowserReadMatches");
7254
+ var HTTP_STATUS_FAILURE = /ERR_HTTP_RESPONSE_CODE_FAILURE/;
7255
+ function isBrowserReadHttpFailure(message) {
7256
+ return HTTP_STATUS_FAILURE.test(message ?? "");
7257
+ }
7258
+ __name(isBrowserReadHttpFailure, "isBrowserReadHttpFailure");
7259
+ __name4(isBrowserReadHttpFailure, "isBrowserReadHttpFailure");
7260
+ function browserReadHttpErrorMessage(url, status) {
7261
+ const answered = status === void 0 ? "an HTTP error status" : `HTTP ${status}`;
7262
+ return `read: ${url} answered ${answered} with no page to read`;
7263
+ }
7264
+ __name(browserReadHttpErrorMessage, "browserReadHttpErrorMessage");
7265
+ __name4(browserReadHttpErrorMessage, "browserReadHttpErrorMessage");
7266
+ function urlOf(value3) {
7267
+ if (!value3) return void 0;
7268
+ try {
7269
+ return new URL(value3);
7270
+ } catch {
7271
+ return void 0;
7272
+ }
7273
+ }
7274
+ __name(urlOf, "urlOf");
7275
+ __name4(urlOf, "urlOf");
7276
+ function answeredDocuments(requests) {
7277
+ if (!Array.isArray(requests)) return [];
7278
+ const answered = [];
7279
+ for (const entry of requests) {
7280
+ if (!isRecord(entry) || typeof entry.status !== "number" || typeof entry.url !== "string") continue;
7281
+ const url = urlOf(entry.url);
7282
+ if (url) answered.unshift({
7283
+ url,
7284
+ status: entry.status
7285
+ });
7286
+ }
7287
+ return answered;
7288
+ }
7289
+ __name(answeredDocuments, "answeredDocuments");
7290
+ __name4(answeredDocuments, "answeredDocuments");
7291
+ function documentStatusOf(requests, requestedUrl, finalUrl) {
7292
+ const latestFirst = answeredDocuments(requests);
7293
+ const final = urlOf(finalUrl);
7294
+ const requested = urlOf(requestedUrl);
7295
+ const match = latestFirst.find((doc) => doc.url.href === final?.href) ?? latestFirst.find((doc) => doc.url.href === requested?.href) ?? latestFirst.find((doc) => doc.url.host === final?.host);
7296
+ return match?.status;
7297
+ }
7298
+ __name(documentStatusOf, "documentStatusOf");
7299
+ __name4(documentStatusOf, "documentStatusOf");
7300
+ var LOGIN_PATH_SEGMENTS = /* @__PURE__ */ new Set([
7301
+ "login",
7302
+ "log-in",
7303
+ "logon",
7304
+ "signin",
7305
+ "sign-in",
7306
+ "sign_in",
7307
+ "auth",
7308
+ "authenticate",
7309
+ "authorize",
7310
+ "sso"
7311
+ ]);
7312
+ var LOGIN_HOST_LABELS = /* @__PURE__ */ new Set([
7313
+ "login",
7314
+ "signin",
7315
+ "auth",
7316
+ "sso"
7317
+ ]);
7318
+ function isLoginUrl(url) {
7319
+ const segments = url.pathname.toLowerCase().split("/");
7320
+ return segments.some((segment) => LOGIN_PATH_SEGMENTS.has(segment)) || LOGIN_HOST_LABELS.has(url.hostname.split(".")[0]);
7321
+ }
7322
+ __name(isLoginUrl, "isLoginUrl");
7323
+ __name4(isLoginUrl, "isLoginUrl");
7324
+ function isLoginRedirect(requestedUrl, finalUrl) {
7325
+ const requested = urlOf(requestedUrl);
7326
+ const final = urlOf(finalUrl);
7327
+ return Boolean(requested && final && !isLoginUrl(requested) && isLoginUrl(final));
7328
+ }
7329
+ __name(isLoginRedirect, "isLoginRedirect");
7330
+ __name4(isLoginRedirect, "isLoginRedirect");
7331
+ function browserReadLoginBlock() {
7332
+ return {
7333
+ blocked: true,
7334
+ blocker: BROWSER_READ_LOGIN_BLOCKER,
7335
+ blockerKind: "login",
7336
+ blockerGuidance: "This URL redirected to a sign-in page, so the content is the sign-in form, not the page you asked for. The page needs a signed-in session: read it on the desktop browser where the user is signed in, or use a public URL."
7337
+ };
7338
+ }
7339
+ __name(browserReadLoginBlock, "browserReadLoginBlock");
7340
+ __name4(browserReadLoginBlock, "browserReadLoginBlock");
7341
+ var AGENT_LOG_SOURCES = [
7342
+ "skill",
7343
+ "job",
7344
+ "webhook",
7345
+ "web-route",
7346
+ "trigger",
7347
+ "preprocessor",
7348
+ "postprocessor",
7349
+ "user_message",
7350
+ "agent_response",
7351
+ "agent_error",
7352
+ "runtime",
7353
+ "mcp",
7354
+ "rag",
7355
+ "device",
7356
+ "device-trigger",
7357
+ "model-resolver",
7358
+ "workflow-step",
7359
+ "workflow-script",
7360
+ "workflow",
7361
+ "supervision",
7362
+ "browser",
7363
+ "decisions"
7364
+ ];
7365
+ var AGENT_LOG_ENVIRONMENTS = [
7366
+ "production",
7367
+ "sandbox"
7368
+ ];
7369
+ var AGENT_LOG_FIELDS_MAX_WIRE_KEYS = LOG_FIELDS_MAX_KEYS + 1;
7370
+ function utf8Bytes(value3) {
7371
+ let bytes = 0;
7372
+ for (let i = 0; i < value3.length; ) {
7373
+ const code = value3.charCodeAt(i);
7374
+ if (code < 128) {
7375
+ bytes += 1;
7376
+ i += 1;
7377
+ } else if (code < 2048) {
7378
+ bytes += 2;
7379
+ i += 1;
7380
+ } else if (code >= 55296 && code <= 56319) {
7381
+ const next = value3.charCodeAt(i + 1);
7382
+ if (next >= 56320 && next <= 57343) {
7383
+ bytes += 4;
7384
+ i += 2;
7385
+ } else {
7386
+ bytes += 3;
7387
+ i += 1;
7388
+ }
7389
+ } else {
7390
+ bytes += 3;
7391
+ i += 1;
7392
+ }
7393
+ }
7394
+ return bytes;
7395
+ }
7396
+ __name(utf8Bytes, "utf8Bytes");
7397
+ __name4(utf8Bytes, "utf8Bytes");
7398
+ function isPlainFieldKey(key) {
7399
+ if (!LOG_FIELD_KEY_PATTERN.test(key)) return false;
7400
+ if (key === LOG_FIELDS_CLAMPED_KEY) return false;
7401
+ return !LOG_FIELD_SECRET_SHAPED_KEY_PATTERNS.some((pattern) => pattern.test(key));
7402
+ }
7403
+ __name(isPlainFieldKey, "isPlainFieldKey");
7404
+ __name4(isPlainFieldKey, "isPlainFieldKey");
7405
+ function describeAgentLogFieldsViolation(value3) {
7406
+ if (typeof value3 !== "object" || value3 === null || Array.isArray(value3)) {
7407
+ return "fields must be an object";
7408
+ }
7409
+ const entries = Object.entries(value3);
7410
+ let userKeys = 0;
7411
+ for (const [key, entry] of entries) {
7412
+ if (key === LOG_FIELDS_CLAMPED_KEY) {
7413
+ if (entry !== true) return `fields.${key} must be true`;
7414
+ continue;
7415
+ }
7416
+ userKeys += 1;
7417
+ if (key.endsWith(LOG_FIELD_ARRAY_COUNT_SUFFIX)) {
7418
+ const base = key.slice(0, -LOG_FIELD_ARRAY_COUNT_SUFFIX.length);
7419
+ if (!isPlainFieldKey(base)) return `fields key \`${key}\` is not a legal field key`;
7420
+ if (typeof entry !== "number" || !Number.isFinite(entry)) {
7421
+ return `fields.${key} must be a finite number`;
7422
+ }
7423
+ continue;
7424
+ }
7425
+ if (!isPlainFieldKey(key)) return `fields key \`${key}\` is not a legal field key`;
7426
+ if (typeof entry === "string") {
7427
+ if (utf8Bytes(entry) > LOG_FIELD_MAX_VALUE_BYTES) {
7428
+ return `fields.${key} exceeds ${LOG_FIELD_MAX_VALUE_BYTES} bytes`;
7429
+ }
7430
+ continue;
7431
+ }
7432
+ if (typeof entry === "boolean") continue;
7433
+ if (typeof entry === "number") {
7434
+ if (!Number.isFinite(entry)) return `fields.${key} must be a finite number`;
7435
+ continue;
7436
+ }
7437
+ return `fields.${key} must be a string, number or boolean`;
7438
+ }
7439
+ if (userKeys > LOG_FIELDS_MAX_KEYS) {
7440
+ return `fields has ${userKeys} keys, over the cap of ${LOG_FIELDS_MAX_KEYS}`;
7441
+ }
7442
+ if (utf8Bytes(JSON.stringify(value3)) > LOG_FIELDS_MAX_BYTES) {
7443
+ return `fields exceeds ${LOG_FIELDS_MAX_BYTES} bytes`;
7444
+ }
7445
+ return void 0;
7446
+ }
7447
+ __name(describeAgentLogFieldsViolation, "describeAgentLogFieldsViolation");
7448
+ __name4(describeAgentLogFieldsViolation, "describeAgentLogFieldsViolation");
7449
+ function isAgentLogFields(value3) {
7450
+ return describeAgentLogFieldsViolation(value3) === void 0;
7451
+ }
7452
+ __name(isAgentLogFields, "isAgentLogFields");
7453
+ __name4(isAgentLogFields, "isAgentLogFields");
7454
+ var BROWSER_LOG_EVENT_KINDS = [
7455
+ "session.opened",
7456
+ "command",
7457
+ "navigation",
7458
+ "blocked",
7459
+ "wall",
7460
+ "fallback",
7461
+ "confirm",
7462
+ "agent.step",
7463
+ "session.closed"
7464
+ ];
7465
+ var BROWSER_LOG_ENGINES = [
7466
+ "desktop",
7467
+ "agent-browser",
7468
+ "browser-use",
7469
+ "none"
7470
+ ];
7471
+ var BROWSER_SESSION_OPEN_REASONS = [
7472
+ "desktop-online",
7473
+ "cloud-fallback",
7474
+ "stepwise-cloud",
7475
+ "pinned",
7476
+ "none"
7477
+ ];
7478
+ var BROWSER_BLOCK_KINDS = [
7479
+ "domain",
7480
+ "private-network",
7481
+ "policy",
7482
+ "concurrency",
7483
+ "bot-block"
7484
+ ];
7485
+ var BROWSER_WALL_KINDS = [
7486
+ "captcha",
7487
+ "bot-block",
7488
+ "consent",
7489
+ "login",
7490
+ "empty-content"
7491
+ ];
7492
+ var BROWSER_WALL_NEXT_ACTIONS = [
7493
+ "fallback",
7494
+ "retry",
7495
+ "ask-user",
7496
+ "gave-up"
7497
+ ];
7498
+ var BROWSER_CONFIRM_DECISIONS = [
7499
+ "pending",
7500
+ "approved",
7501
+ "denied",
7502
+ "expired"
7503
+ ];
7504
+ var BROWSER_SESSION_CLOSE_REASONS = [
7505
+ "done",
7506
+ "idle",
7507
+ "max-minutes",
7508
+ "max-steps",
7509
+ "cost-cap",
7510
+ "error",
7511
+ "reaped"
7512
+ ];
7513
+ var BROWSER_LOG_CONTEXT_KEYS = [
7514
+ "runId",
7515
+ "executionId",
7516
+ "primitiveId",
7517
+ "primitiveName",
7518
+ "channel",
7519
+ "orgId",
7520
+ "environment",
7521
+ "agentVersion"
7522
+ ];
7523
+ var BROWSER_LOG_ID_MAX_CHARS = 256;
7524
+ var BROWSER_LOG_TEXT_MAX_CHARS = 64 * 1024;
7525
+ var isString = /* @__PURE__ */ __name4((value3) => typeof value3 === "string", "isString");
7526
+ var isBoolean = /* @__PURE__ */ __name4((value3) => typeof value3 === "boolean", "isBoolean");
7527
+ var isCount = /* @__PURE__ */ __name4((value3) => typeof value3 === "number" && Number.isFinite(value3) && value3 >= 0, "isCount");
7528
+ var isPlainObject2 = /* @__PURE__ */ __name4((value3) => typeof value3 === "object" && value3 !== null && !Array.isArray(value3), "isPlainObject");
7529
+ var oneOf = /* @__PURE__ */ __name4((values) => (value3) => typeof value3 === "string" && values.includes(value3), "oneOf");
7530
+ var isLimits = /* @__PURE__ */ __name4((value3) => isPlainObject2(value3) && Object.values(value3).every((entry) => isCount(entry)), "isLimits");
7531
+ var EVENT_SHAPES = {
7532
+ "session.opened": {
7533
+ required: {
7534
+ reason: oneOf(BROWSER_SESSION_OPEN_REASONS)
7535
+ },
7536
+ optional: {
7537
+ limits: isLimits,
7538
+ region: isString,
7539
+ liveUrl: isString
7540
+ }
7541
+ },
7542
+ command: {
7543
+ required: {
7544
+ name: oneOf(BROWSER_COMMAND_NAMES),
7545
+ durationMs: isCount,
7546
+ ok: isBoolean
7547
+ },
7548
+ optional: {
7549
+ args: isPlainObject2,
7550
+ urlBefore: isString,
7551
+ urlAfter: isString,
7552
+ resultBytes: isCount,
7553
+ errorCode: isString,
7554
+ errorMessage: isString,
7555
+ title: isString,
7556
+ pageText: isString,
7557
+ screenshotRef: isString
7558
+ }
7559
+ },
7560
+ navigation: {
7561
+ required: {
7562
+ url: isString
7563
+ },
7564
+ optional: {
7565
+ finalUrl: isString,
7566
+ status: isCount,
7567
+ redirects: isCount
7568
+ }
7569
+ },
7570
+ blocked: {
7571
+ required: {
7572
+ kind: oneOf(BROWSER_BLOCK_KINDS)
7573
+ },
7574
+ optional: {
7575
+ rule: isString,
7576
+ target: isString,
7577
+ command: oneOf(BROWSER_COMMAND_NAMES),
7578
+ reason: isString
7579
+ }
7580
+ },
7581
+ wall: {
7582
+ required: {
7583
+ kind: oneOf(BROWSER_WALL_KINDS),
7584
+ url: isString,
7585
+ nextAction: oneOf(BROWSER_WALL_NEXT_ACTIONS)
7586
+ },
7587
+ optional: {}
7588
+ },
7589
+ fallback: {
7590
+ required: {
7591
+ from: oneOf(BROWSER_LOG_ENGINES),
7592
+ to: oneOf(BROWSER_LOG_ENGINES),
7593
+ reason: isString,
7594
+ provider: isString
7595
+ },
7596
+ optional: {}
7597
+ },
7598
+ confirm: {
7599
+ required: {
7600
+ action: isString,
7601
+ decision: oneOf(BROWSER_CONFIRM_DECISIONS)
7602
+ },
7603
+ optional: {
7604
+ decidedBy: isString
7605
+ }
7606
+ },
7607
+ "agent.step": {
7608
+ required: {
7609
+ step: isCount,
7610
+ action: isString
7611
+ },
7612
+ optional: {
7613
+ intent: isString,
7614
+ url: isString
7615
+ }
7616
+ },
7617
+ "session.closed": {
7618
+ required: {
7619
+ reason: oneOf(BROWSER_SESSION_CLOSE_REASONS),
7620
+ durationMs: isCount,
7621
+ pagesVisited: isCount,
7622
+ bytes: isCount
7623
+ },
7624
+ optional: {
7625
+ costUsd: isCount
7626
+ }
7627
+ }
7628
+ };
7629
+ var BASE_KEYS = /* @__PURE__ */ new Set([
7630
+ "event",
7631
+ "sessionId",
7632
+ "engine",
7633
+ "at"
7634
+ ]);
7635
+ function describeBaseViolation(event) {
7636
+ if (!BROWSER_LOG_EVENT_KINDS.includes(event.event)) return "event is not a known kind";
7637
+ if (typeof event.sessionId !== "string" || event.sessionId.length === 0) return "sessionId must be a string";
7638
+ if (event.sessionId.length > BROWSER_LOG_ID_MAX_CHARS) return "sessionId is too long";
7639
+ if (!BROWSER_LOG_ENGINES.includes(event.engine)) return "engine is not a known engine";
7640
+ if (typeof event.at !== "string" || Number.isNaN(Date.parse(event.at))) return "at must be an ISO timestamp";
7641
+ return void 0;
7642
+ }
7643
+ __name(describeBaseViolation, "describeBaseViolation");
7644
+ __name4(describeBaseViolation, "describeBaseViolation");
7645
+ function describeFieldViolation(key, value3, check) {
7646
+ if (!check) return `${key} is not a field of this event`;
7647
+ if (!check(value3)) return `${key} has the wrong type`;
7648
+ if (typeof value3 === "string" && value3.length > BROWSER_LOG_TEXT_MAX_CHARS) return `${key} is too long`;
7649
+ return void 0;
7650
+ }
7651
+ __name(describeFieldViolation, "describeFieldViolation");
7652
+ __name4(describeFieldViolation, "describeFieldViolation");
7653
+ function describeBrowserLogEventViolation(value3) {
7654
+ if (!isPlainObject2(value3)) return "event must be an object";
7655
+ const event = value3;
7656
+ const base = describeBaseViolation(event);
7657
+ if (base) return base;
7658
+ const shape = EVENT_SHAPES[event.event];
7659
+ for (const key of Object.keys(shape.required)) {
7660
+ if (event[key] === void 0) return `${key} is required`;
7661
+ }
7662
+ for (const [key, entry] of Object.entries(event)) {
7663
+ if (BASE_KEYS.has(key) || entry === void 0) continue;
7664
+ const violation = describeFieldViolation(key, entry, shape.required[key] ?? shape.optional[key]);
7665
+ if (violation) return violation;
7666
+ }
7667
+ return void 0;
7668
+ }
7669
+ __name(describeBrowserLogEventViolation, "describeBrowserLogEventViolation");
7670
+ __name4(describeBrowserLogEventViolation, "describeBrowserLogEventViolation");
7671
+ function isBrowserLogEvent(value3) {
7672
+ return describeBrowserLogEventViolation(value3) === void 0;
7673
+ }
7674
+ __name(isBrowserLogEvent, "isBrowserLogEvent");
7675
+ __name4(isBrowserLogEvent, "isBrowserLogEvent");
7676
+ function describeBrowserLogContextViolation(value3) {
7677
+ if (value3 === void 0) return void 0;
7678
+ if (!isPlainObject2(value3)) return "logContext must be an object";
7679
+ for (const [key, entry] of Object.entries(value3)) {
7680
+ if (!BROWSER_LOG_CONTEXT_KEYS.includes(key)) return `logContext.${key} is not allowed`;
7681
+ if (entry === void 0) continue;
7682
+ if (typeof entry !== "string") return `logContext.${key} must be a string`;
7683
+ if (entry.length > BROWSER_LOG_ID_MAX_CHARS) return `logContext.${key} is too long`;
7684
+ if (key === "environment" && !AGENT_LOG_ENVIRONMENTS.includes(entry)) {
7685
+ return "logContext.environment is not a known environment";
7686
+ }
7687
+ }
7688
+ return void 0;
7689
+ }
7690
+ __name(describeBrowserLogContextViolation, "describeBrowserLogContextViolation");
7691
+ __name4(describeBrowserLogContextViolation, "describeBrowserLogContextViolation");
7692
+ var BROWSER_WORKER_SESSION_ID_SEPARATOR = ":";
7693
+ function browserWorkerSessionId(ref) {
7694
+ return [
7695
+ ref.agentId,
7696
+ ref.userId,
7697
+ ref.sessionKey
7698
+ ].join(BROWSER_WORKER_SESSION_ID_SEPARATOR);
7699
+ }
7700
+ __name(browserWorkerSessionId, "browserWorkerSessionId");
7701
+ __name4(browserWorkerSessionId, "browserWorkerSessionId");
7702
+ var BROWSER_WORKER_BLOCK_REASON_MAX_CHARS = 1024;
7703
+ function browserLogContextOfWorkerContext(context) {
7704
+ const out = {};
7705
+ if (context?.runId) out.runId = context.runId;
7706
+ if (context?.primitiveId) out.primitiveId = context.primitiveId;
7707
+ if (context?.primitiveName) out.primitiveName = context.primitiveName;
7708
+ if (context?.channel) out.channel = context.channel;
7709
+ return out;
7710
+ }
7711
+ __name(browserLogContextOfWorkerContext, "browserLogContextOfWorkerContext");
7712
+ __name4(browserLogContextOfWorkerContext, "browserLogContextOfWorkerContext");
7713
+ function browserLogEventOfWorkerEvent(event, mapping = {}) {
7714
+ const base = {
7715
+ sessionId: mapping.sessionId ?? event.sessionId,
7716
+ engine: "agent-browser",
7717
+ at: event.at
7718
+ };
7719
+ switch (event.event) {
7720
+ case "session.opened":
7721
+ return {
7722
+ ...base,
7723
+ event: "session.opened",
7724
+ reason: mapping.reason ?? "stepwise-cloud",
7725
+ limits: {
7726
+ ...event.limits
7727
+ }
7728
+ };
7729
+ case "session.closed":
7730
+ return {
7731
+ ...base,
7732
+ event: "session.closed",
7733
+ reason: event.reason,
7734
+ durationMs: event.durationMs,
7735
+ pagesVisited: event.pagesVisited,
7736
+ bytes: event.bytes
7737
+ };
7738
+ case "command":
7739
+ return {
7740
+ ...base,
7741
+ event: "command",
7742
+ name: event.name,
7743
+ ok: event.ok,
7744
+ durationMs: event.durationMs,
7745
+ resultBytes: event.resultBytes,
7746
+ urlAfter: event.urlAfter,
7747
+ title: event.title,
7748
+ errorCode: event.errorCode,
7749
+ errorMessage: event.errorMessage
7750
+ };
7751
+ case "navigation":
7752
+ if (!event.ok) return void 0;
7753
+ return {
7754
+ ...base,
7755
+ event: "navigation",
7756
+ url: event.url,
7757
+ finalUrl: event.finalUrl
7758
+ };
7759
+ case "blocked":
7760
+ return {
7761
+ ...base,
7762
+ event: "blocked",
7763
+ kind: event.kind,
7764
+ rule: event.rule,
7765
+ target: event.target,
7766
+ command: event.command,
7767
+ reason: event.detail ? event.detail.slice(0, BROWSER_WORKER_BLOCK_REASON_MAX_CHARS) : void 0
7768
+ };
7769
+ case "wall":
7770
+ return {
7771
+ ...base,
7772
+ event: "wall",
7773
+ kind: event.kind,
7774
+ url: event.url,
7775
+ nextAction: event.nextAction
7776
+ };
7777
+ }
7778
+ }
7779
+ __name(browserLogEventOfWorkerEvent, "browserLogEventOfWorkerEvent");
7780
+ __name4(browserLogEventOfWorkerEvent, "browserLogEventOfWorkerEvent");
6873
7781
  var WORKFLOW_RETRY_BACKOFFS = [
6874
7782
  "fixed",
6875
7783
  "exponential"
@@ -7376,114 +8284,6 @@ function buildPersonalSpaceStartingPersona(agentName) {
7376
8284
  }
7377
8285
  __name(buildPersonalSpaceStartingPersona, "buildPersonalSpaceStartingPersona");
7378
8286
  __name4(buildPersonalSpaceStartingPersona, "buildPersonalSpaceStartingPersona");
7379
- var AGENT_LOG_SOURCES = [
7380
- "skill",
7381
- "job",
7382
- "webhook",
7383
- "web-route",
7384
- "trigger",
7385
- "preprocessor",
7386
- "postprocessor",
7387
- "user_message",
7388
- "agent_response",
7389
- "agent_error",
7390
- "runtime",
7391
- "mcp",
7392
- "rag",
7393
- "device",
7394
- "device-trigger",
7395
- "model-resolver",
7396
- "workflow-step",
7397
- "workflow-script",
7398
- "workflow",
7399
- "supervision",
7400
- "decisions"
7401
- ];
7402
- var AGENT_LOG_FIELDS_MAX_WIRE_KEYS = LOG_FIELDS_MAX_KEYS + 1;
7403
- function utf8Bytes(value3) {
7404
- let bytes = 0;
7405
- for (let i = 0; i < value3.length; ) {
7406
- const code = value3.charCodeAt(i);
7407
- if (code < 128) {
7408
- bytes += 1;
7409
- i += 1;
7410
- } else if (code < 2048) {
7411
- bytes += 2;
7412
- i += 1;
7413
- } else if (code >= 55296 && code <= 56319) {
7414
- const next = value3.charCodeAt(i + 1);
7415
- if (next >= 56320 && next <= 57343) {
7416
- bytes += 4;
7417
- i += 2;
7418
- } else {
7419
- bytes += 3;
7420
- i += 1;
7421
- }
7422
- } else {
7423
- bytes += 3;
7424
- i += 1;
7425
- }
7426
- }
7427
- return bytes;
7428
- }
7429
- __name(utf8Bytes, "utf8Bytes");
7430
- __name4(utf8Bytes, "utf8Bytes");
7431
- function isPlainFieldKey(key) {
7432
- if (!LOG_FIELD_KEY_PATTERN.test(key)) return false;
7433
- if (key === LOG_FIELDS_CLAMPED_KEY) return false;
7434
- return !LOG_FIELD_SECRET_SHAPED_KEY_PATTERNS.some((pattern) => pattern.test(key));
7435
- }
7436
- __name(isPlainFieldKey, "isPlainFieldKey");
7437
- __name4(isPlainFieldKey, "isPlainFieldKey");
7438
- function describeAgentLogFieldsViolation(value3) {
7439
- if (typeof value3 !== "object" || value3 === null || Array.isArray(value3)) {
7440
- return "fields must be an object";
7441
- }
7442
- const entries = Object.entries(value3);
7443
- let userKeys = 0;
7444
- for (const [key, entry] of entries) {
7445
- if (key === LOG_FIELDS_CLAMPED_KEY) {
7446
- if (entry !== true) return `fields.${key} must be true`;
7447
- continue;
7448
- }
7449
- userKeys += 1;
7450
- if (key.endsWith(LOG_FIELD_ARRAY_COUNT_SUFFIX)) {
7451
- const base = key.slice(0, -LOG_FIELD_ARRAY_COUNT_SUFFIX.length);
7452
- if (!isPlainFieldKey(base)) return `fields key \`${key}\` is not a legal field key`;
7453
- if (typeof entry !== "number" || !Number.isFinite(entry)) {
7454
- return `fields.${key} must be a finite number`;
7455
- }
7456
- continue;
7457
- }
7458
- if (!isPlainFieldKey(key)) return `fields key \`${key}\` is not a legal field key`;
7459
- if (typeof entry === "string") {
7460
- if (utf8Bytes(entry) > LOG_FIELD_MAX_VALUE_BYTES) {
7461
- return `fields.${key} exceeds ${LOG_FIELD_MAX_VALUE_BYTES} bytes`;
7462
- }
7463
- continue;
7464
- }
7465
- if (typeof entry === "boolean") continue;
7466
- if (typeof entry === "number") {
7467
- if (!Number.isFinite(entry)) return `fields.${key} must be a finite number`;
7468
- continue;
7469
- }
7470
- return `fields.${key} must be a string, number or boolean`;
7471
- }
7472
- if (userKeys > LOG_FIELDS_MAX_KEYS) {
7473
- return `fields has ${userKeys} keys, over the cap of ${LOG_FIELDS_MAX_KEYS}`;
7474
- }
7475
- if (utf8Bytes(JSON.stringify(value3)) > LOG_FIELDS_MAX_BYTES) {
7476
- return `fields exceeds ${LOG_FIELDS_MAX_BYTES} bytes`;
7477
- }
7478
- return void 0;
7479
- }
7480
- __name(describeAgentLogFieldsViolation, "describeAgentLogFieldsViolation");
7481
- __name4(describeAgentLogFieldsViolation, "describeAgentLogFieldsViolation");
7482
- function isAgentLogFields(value3) {
7483
- return describeAgentLogFieldsViolation(value3) === void 0;
7484
- }
7485
- __name(isAgentLogFields, "isAgentLogFields");
7486
- __name4(isAgentLogFields, "isAgentLogFields");
7487
8287
  var LOG_DRAIN_TYPES_PHASE1 = [
7488
8288
  "http",
7489
8289
  "otlp",
@@ -8271,13 +9071,13 @@ __name4(parseLogTimeBound, "parseLogTimeBound");
8271
9071
  var CORE_DRAINING_CODE = "CORE_DRAINING";
8272
9072
  var CORE_DRAINING_DEFAULT_RETRY_MS = 1e3;
8273
9073
  var CORE_DRAINING_MAX_RETRY_MS = 5e3;
8274
- function isRecord(value3) {
9074
+ function isRecord2(value3) {
8275
9075
  return typeof value3 === "object" && value3 !== null;
8276
9076
  }
8277
- __name(isRecord, "isRecord");
8278
- __name4(isRecord, "isRecord");
9077
+ __name(isRecord2, "isRecord2");
9078
+ __name4(isRecord2, "isRecord");
8279
9079
  function isCoreDrainingErrorResponse(value3) {
8280
- if (!isRecord(value3) || !isRecord(value3.error)) return false;
9080
+ if (!isRecord2(value3) || !isRecord2(value3.error)) return false;
8281
9081
  return value3.error.code === CORE_DRAINING_CODE && typeof value3.error.message === "string" && value3.error.retryable === true;
8282
9082
  }
8283
9083
  __name(isCoreDrainingErrorResponse, "isCoreDrainingErrorResponse");
@@ -8360,7 +9160,7 @@ var PluginClassSchema = z2.enum([
8360
9160
  var ModelDescriptorSchema = z2.string().min(1).max(200);
8361
9161
  var InferenceModelSchema = z2.object({
8362
9162
  kind: z2.literal("inference"),
8363
- /** Provider-prefixed model id (e.g. `'openai/gpt-5.2-chat-latest'`). */
9163
+ /** Provider-prefixed model id (e.g. `'openai/chat-latest'`). */
8364
9164
  model: ModelDescriptorSchema,
8365
9165
  /**
8366
9166
  * TTS-only — provider voice id. Inference's TTS API takes voice
@@ -10960,11 +11760,11 @@ function confidenceOf(n2) {
10960
11760
  }
10961
11761
  __name(confidenceOf, "confidenceOf");
10962
11762
  __name4(confidenceOf, "confidenceOf");
10963
- function rateOf(count, conversations) {
11763
+ function rateOf(count2, conversations) {
10964
11764
  return {
10965
- count,
10966
- rate: conversations > 0 ? count / conversations : null,
10967
- confidence: confidenceOf(count)
11765
+ count: count2,
11766
+ rate: conversations > 0 ? count2 / conversations : null,
11767
+ confidence: confidenceOf(count2)
10968
11768
  };
10969
11769
  }
10970
11770
  __name(rateOf, "rateOf");
@@ -15148,11 +15948,11 @@ function isConditionalJoinId(stepId) {
15148
15948
  }
15149
15949
  __name(isConditionalJoinId, "isConditionalJoinId");
15150
15950
  __name5(isConditionalJoinId, "isConditionalJoinId");
15151
- function isPlainObject2(v) {
15951
+ function isPlainObject3(v) {
15152
15952
  return typeof v === "object" && v !== null && !Array.isArray(v);
15153
15953
  }
15154
- __name(isPlainObject2, "isPlainObject");
15155
- __name5(isPlainObject2, "isPlainObject");
15954
+ __name(isPlainObject3, "isPlainObject");
15955
+ __name5(isPlainObject3, "isPlainObject");
15156
15956
  function leafValue(row) {
15157
15957
  if (row.status === "completed") return row.output === void 0 ? null : row.output;
15158
15958
  return continuedFailureValue(row.error, row.killReason);
@@ -15175,7 +15975,7 @@ function deriveRunOutput(steps) {
15175
15975
  if (leaves.length === 1) {
15176
15976
  const leaf = leaves[0];
15177
15977
  const value22 = leafValue(leaf);
15178
- if (isConditionalJoinId(leaf.stepId) && isPlainObject2(value22)) {
15978
+ if (isConditionalJoinId(leaf.stepId) && isPlainObject3(value22)) {
15179
15979
  const keys = Object.keys(value22);
15180
15980
  if (keys.length === 1) return {
15181
15981
  output: value22[keys[0]],
@@ -16802,9 +17602,9 @@ function estimateGraph(envelopeOrGraph) {
16802
17602
  }
16803
17603
  __name(estimateGraph, "estimateGraph");
16804
17604
  __name5(estimateGraph, "estimateGraph");
16805
- var isRecord2 = /* @__PURE__ */ __name5((v) => !!v && typeof v === "object" && !Array.isArray(v), "isRecord");
17605
+ var isRecord3 = /* @__PURE__ */ __name5((v) => !!v && typeof v === "object" && !Array.isArray(v), "isRecord");
16806
17606
  function* singleStepsOf(entry) {
16807
- if (!isRecord2(entry)) return;
17607
+ if (!isRecord3(entry)) return;
16808
17608
  switch (entry.type) {
16809
17609
  case "step":
16810
17610
  case "agent":
@@ -16830,8 +17630,8 @@ function* singleStepsOf(entry) {
16830
17630
  __name(singleStepsOf, "singleStepsOf");
16831
17631
  __name5(singleStepsOf, "singleStepsOf");
16832
17632
  function entriesOf(graph) {
16833
- const definition = isRecord2(graph) ? graph.definition : void 0;
16834
- const entries = isRecord2(definition) ? definition.graph : void 0;
17633
+ const definition = isRecord3(graph) ? graph.definition : void 0;
17634
+ const entries = isRecord3(definition) ? definition.graph : void 0;
16835
17635
  return Array.isArray(entries) ? entries : [];
16836
17636
  }
16837
17637
  __name(entriesOf, "entriesOf");
@@ -16852,7 +17652,7 @@ function inheritTargets(graphs) {
16852
17652
  __name(inheritTargets, "inheritTargets");
16853
17653
  __name5(inheritTargets, "inheritTargets");
16854
17654
  function needsInheritedWorkspace(graph) {
16855
- if (!isRecord2(graph) || graph.workspace !== void 0) return false;
17655
+ if (!isRecord3(graph) || graph.workspace !== void 0) return false;
16856
17656
  for (const entry of entriesOf(graph)) {
16857
17657
  for (const node of singleStepsOf(entry)) {
16858
17658
  if (node.workspace !== void 0 && node.workspace !== "inherit") return true;
@@ -17876,6 +18676,10 @@ function createWorkflow(cfg) {
17876
18676
  const n2 = cfg.backfillOnEnable.maxOccurrences;
17877
18677
  if (!Number.isInteger(n2) || n2 < 1 || n2 > 200) throw new LuaWorkflowBuildError("invalid-envelope", "backfillOnEnable.maxOccurrences must be an integer in 1..200 (backfill-max-occurrences-out-of-range; the org maxBatchItems twin is checked at publish/R56)");
17878
18678
  }
18679
+ if (cfg.concurrencyKey !== void 0) {
18680
+ if (cfg.concurrencyKey !== "correlationKey") throw new LuaWorkflowBuildError("invalid-envelope", "concurrencyKey must be 'correlationKey'");
18681
+ if (cfg.concurrencyPolicy !== "forbid") throw new LuaWorkflowBuildError("concurrency-key-requires-forbid", `workflow "${cfg.name}": concurrencyKey requires concurrencyPolicy:'forbid'`, "set concurrencyPolicy:'forbid' or remove concurrencyKey");
18682
+ }
17879
18683
  if (cfg.health !== void 0) {
17880
18684
  const issues = validateScheduleHealth(cfg.health, {
17881
18685
  target: "workflow",