deepline 0.3.306 → 0.3.308

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 (104) hide show
  1. package/README.md +2 -1
  2. package/dist/bundling-sources/sdk/src/client.ts +270 -11
  3. package/dist/bundling-sources/sdk/src/compat.ts +27 -9
  4. package/dist/bundling-sources/sdk/src/index.ts +35 -0
  5. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  6. package/dist/bundling-sources/shared_libs/play-runtime/batch-runtime.ts +4 -0
  7. package/dist/bundling-sources/shared_libs/play-runtime/batching-types.ts +3 -0
  8. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +46 -16
  9. package/dist/bundling-sources/shared_libs/play-runtime/fullenrich-batching.ts +24 -1
  10. package/dist/bundling-sources/shared_libs/play-runtime/run-event-query.ts +872 -0
  11. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/absurd-shared.ts +10 -5
  12. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/postgres.ts +4 -1
  13. package/dist/bundling-sources/shared_libs/play-runtime/scheduler-backends/runtime-event-search.ts +720 -19
  14. package/dist/cli/auth-LWNR7TQB.js +31 -0
  15. package/dist/cli/{auth-WTC7LCQ6.mjs → auth-ZWX4BF5K.mjs} +4 -4
  16. package/dist/cli/{billing-VQM65LVP.mjs → billing-CLV5QRFQ.mjs} +4 -4
  17. package/dist/cli/{billing-3DYTHO32.js → billing-H24FGAKE.js} +70 -70
  18. package/dist/cli/{chunk-WV64SNDV.mjs → chunk-3GIUCJAT.mjs} +1 -1
  19. package/dist/cli/{chunk-5V56XCQN.mjs → chunk-ABMGEW3C.mjs} +1 -1
  20. package/dist/cli/{chunk-UT3VLSLM.mjs → chunk-ASWZTTKT.mjs} +13 -5
  21. package/dist/cli/{chunk-FJ3DANI4.mjs → chunk-BPD7TR27.mjs} +1 -1
  22. package/dist/cli/{chunk-7XORS6WQ.mjs → chunk-CXU7ME5X.mjs} +2 -2
  23. package/dist/cli/{chunk-RODIZCGU.js → chunk-GBFIAI4L.js} +68 -60
  24. package/dist/cli/{chunk-OZIFVQRY.js → chunk-GONK2N7U.js} +1 -1
  25. package/dist/cli/{chunk-LLGF6V6I.mjs → chunk-HGI6RGHB.mjs} +653 -5
  26. package/dist/cli/{chunk-FZNO6B4W.js → chunk-IFIGQWHC.js} +6 -6
  27. package/dist/cli/{chunk-6CRUYVU7.mjs → chunk-JUAVGRD7.mjs} +4 -4
  28. package/dist/cli/{chunk-SZQPJW2L.js → chunk-O7NNH76S.js} +6 -6
  29. package/dist/cli/{chunk-2IKIG333.js → chunk-QJBJZVG6.js} +15 -4
  30. package/dist/cli/{chunk-M6HCRRV2.js → chunk-QTCFSRGC.js} +4 -4
  31. package/dist/cli/{chunk-W7ELTWDM.js → chunk-SRZ6XDX3.js} +26 -26
  32. package/dist/cli/{chunk-4PSSDZQB.mjs → chunk-T3P4NRZU.mjs} +1 -1
  33. package/dist/cli/{chunk-PHNAFCSB.js → chunk-TH3YBIJT.js} +852 -204
  34. package/dist/cli/{chunk-U37SW6IK.js → chunk-UGTYNMRX.js} +48 -48
  35. package/dist/cli/{chunk-2KR56MPF.js → chunk-WEZVPZPE.js} +2 -2
  36. package/dist/cli/{chunk-UABLQKTZ.mjs → chunk-WXLOW623.mjs} +11 -0
  37. package/dist/cli/{chunk-QDC4XTO3.mjs → chunk-XFYVL7EM.mjs} +2 -2
  38. package/dist/cli/{chunk-5HS5EEFE.mjs → chunk-XSDL3NHZ.mjs} +3 -3
  39. package/dist/cli/{chunk-MMNZ6GBT.js → chunk-YEJMVAD3.js} +6 -6
  40. package/dist/cli/{chunk-WWPI4GJI.mjs → chunk-YSZSERRZ.mjs} +1 -1
  41. package/dist/cli/{chunk-OF7QP2XX.js → chunk-ZHHF24O5.js} +15 -15
  42. package/dist/cli/client-3J76AMVE.js +20 -0
  43. package/dist/cli/{client-DCEK34D5.mjs → client-A5ILG5GT.mjs} +3 -3
  44. package/dist/cli/{csv-LXBF5UIV.mjs → csv-NZ7KAYEF.mjs} +3 -3
  45. package/dist/cli/{csv-H42JDJ6G.js → csv-VSSAAXFX.js} +12 -12
  46. package/dist/cli/{db-DP5GU4MU.js → db-ICLEBSNO.js} +20 -20
  47. package/dist/cli/{db-3O5CFLNP.mjs → db-YSAJUBLD.mjs} +4 -4
  48. package/dist/cli/{executions-QC2UZKIP.mjs → executions-MUJRAT5R.mjs} +4 -4
  49. package/dist/cli/{executions-5FFTPHEX.js → executions-XCAJB5TF.js} +6 -6
  50. package/dist/cli/{feedback-JCGE6JFW.mjs → feedback-6C7Y2SCJ.mjs} +3 -3
  51. package/dist/cli/{feedback-XAU3FI5S.js → feedback-DBZMBHZG.js} +6 -6
  52. package/dist/cli/git-2NSE4WIK.js +23 -0
  53. package/dist/cli/{git-S3Y3E2NL.mjs → git-EAH67ITA.mjs} +4 -4
  54. package/dist/cli/index.js +79 -77
  55. package/dist/cli/index.mjs +33 -31
  56. package/dist/cli/{legacy-noops-TXOUX4FX.js → legacy-noops-EJTOLTVO.js} +7 -7
  57. package/dist/cli/{legacy-noops-FQF2IRVS.mjs → legacy-noops-O5INQP6Q.mjs} +4 -4
  58. package/dist/cli/{monitors-4BQCO6B7.js → monitors-5OYO2DPJ.js} +85 -85
  59. package/dist/cli/{monitors-F3PELPSH.mjs → monitors-SBBBMUFY.mjs} +4 -4
  60. package/dist/cli/{org-VQM6OOLK.js → org-SJRPJG42.js} +60 -60
  61. package/dist/cli/{org-ER5J3ATG.mjs → org-Z7LTOL3H.mjs} +4 -4
  62. package/dist/cli/{play-B5H2RN4N.mjs → play-2JTIEOZM.mjs} +472 -55
  63. package/dist/cli/{play-WKZPAOW3.js → play-VQJ6ABZ2.js} +961 -544
  64. package/dist/cli/{providers-5TEA2FJG.js → providers-43MR5XOV.js} +7 -7
  65. package/dist/cli/{providers-6ODEAYC2.mjs → providers-MX4CV2EH.mjs} +4 -4
  66. package/dist/cli/{quickstart-GJYCNMFC.js → quickstart-A6W3HEE2.js} +5 -5
  67. package/dist/cli/{quickstart-BCYT7BCY.mjs → quickstart-Y4YLKRZ3.mjs} +3 -3
  68. package/dist/cli/{search-KKJ535OX.js → search-AMUFSAFP.js} +6 -6
  69. package/dist/cli/{search-RY547KOT.mjs → search-FRKDLJQG.mjs} +5 -5
  70. package/dist/cli/{secrets-U42ZEYIU.mjs → secrets-E4EX7O3J.mjs} +4 -4
  71. package/dist/cli/{secrets-RFGDXSEW.js → secrets-XITHKZW2.js} +13 -13
  72. package/dist/cli/{sessions-ZRTWHMIH.js → sessions-6HJFDIR2.js} +5 -5
  73. package/dist/cli/{sessions-YWEFB62D.mjs → sessions-6YXAUJII.mjs} +4 -4
  74. package/dist/cli/{settings-XUWFXIL7.js → settings-J5NRLCV2.js} +74 -74
  75. package/dist/cli/{settings-AS4U6NVP.mjs → settings-LBJSZIET.mjs} +7 -7
  76. package/dist/cli/{setup-2QPWP2FI.js → setup-2ES4CTO5.js} +41 -41
  77. package/dist/cli/{setup-2GUIV2EW.mjs → setup-75FENNVH.mjs} +6 -6
  78. package/dist/cli/skills-VLTAVA4K.js +28 -0
  79. package/dist/cli/{skills-5QS7ERVF.mjs → skills-XGZDUXW6.mjs} +4 -4
  80. package/dist/cli/{tools-PVWSGCZD.mjs → tools-2LEKXOGY.mjs} +58 -42
  81. package/dist/cli/{tools-J47LIO2H.js → tools-ZOQOGDKI.js} +111 -95
  82. package/dist/cli/update-5CZOVYQT.js +28 -0
  83. package/dist/cli/{update-KS4TRSZI.mjs → update-SNK3IN3I.mjs} +6 -6
  84. package/dist/cli/{workflow-QCLR7GVC.mjs → workflow-G7ZM3MAC.mjs} +5 -5
  85. package/dist/cli/{workflow-HQRUUTTL.js → workflow-W3AYTB3J.js} +15 -15
  86. package/dist/{client-Dj8MAkDc.d.mts → client-DpnkGBn-.d.mts} +324 -11
  87. package/dist/{client-DsrFGXJf.d.ts → client-ypdBvf1o.d.ts} +324 -11
  88. package/dist/index.d.mts +2 -2
  89. package/dist/index.d.ts +2 -2
  90. package/dist/index.js +8 -6
  91. package/dist/index.mjs +5 -3
  92. package/dist/install-integrity.json +73 -72
  93. package/dist/plays/run-request.d.mts +1 -1
  94. package/dist/plays/run-request.d.ts +1 -1
  95. package/dist/release.d.mts +1 -1
  96. package/dist/release.d.ts +1 -1
  97. package/dist/release.js +2 -2
  98. package/dist/release.mjs +1 -1
  99. package/package.json +1 -1
  100. package/dist/cli/auth-ZT3UF33R.js +0 -31
  101. package/dist/cli/client-UQXVU2T6.js +0 -20
  102. package/dist/cli/git-CNO2UFZE.js +0 -23
  103. package/dist/cli/skills-4E5KYW2Y.js +0 -28
  104. package/dist/cli/update-GZKGOMKD.js +0 -28
@@ -14,7 +14,7 @@ import {
14
14
  RETAINED_PIPELINE_RECEIVERS_HEADER,
15
15
  RUNTIME_ENVIRONMENT_TOKEN_HEADER,
16
16
  resolveConfig
17
- } from "./chunk-4PSSDZQB.mjs";
17
+ } from "./chunk-T3P4NRZU.mjs";
18
18
  import {
19
19
  PLAY_RUNTIME_BACKENDS,
20
20
  RAW_V2_TOOL_RESPONSE_CONTRACT,
@@ -562,11 +562,11 @@ function resolveLegacySlackNotification(destinations) {
562
562
  const slackDestinations = destinations.filter(
563
563
  (destination) => destination.kind === "slack" && destination.archivedAt === void 0
564
564
  );
565
- const canonical = slackDestinations.filter(
565
+ const canonical2 = slackDestinations.filter(
566
566
  (destination) => destination.name === LEGACY_SLACK_NOTIFICATION_NAME
567
567
  );
568
- if (canonical.length === 1) return canonical[0];
569
- if (canonical.length > 1) {
568
+ if (canonical2.length === 1) return canonical2[0];
569
+ if (canonical2.length > 1) {
570
570
  throw new ProductNotificationLegacySelectionError(
571
571
  `More than one "${LEGACY_SLACK_NOTIFICATION_NAME}" Slack notification exists. Use the named notification API to choose one.`
572
572
  );
@@ -1223,6 +1223,7 @@ var RUN_EVENT_TERMINAL_KIND_VALUES = [
1223
1223
  RUN_EVENT_KIND.runCancelled
1224
1224
  ];
1225
1225
  var RUN_LOG_RETENTION_MAX_BYTES = 5 * 1024 * 1024;
1226
+ var RUN_LOG_LEVELS = ["debug", "info", "warn", "error"];
1226
1227
  function sqlStringLiteral(value) {
1227
1228
  return "'" + value.replaceAll("'", "''") + "'";
1228
1229
  }
@@ -2013,6 +2014,528 @@ function parseRunLogsCursor(value) {
2013
2014
  return parsed;
2014
2015
  }
2015
2016
 
2017
+ // ../play-runtime/run-event-query.ts
2018
+ var stringField = { type: "string", nullable: false };
2019
+ var optionalString = { type: "string", nullable: true };
2020
+ var RUN_EVENT_QUERY_FIELD_CATALOG = {
2021
+ eventId: stringField,
2022
+ orgId: stringField,
2023
+ runtimeScope: stringField,
2024
+ runId: stringField,
2025
+ playName: stringField,
2026
+ kind: stringField,
2027
+ source: optionalString,
2028
+ occurredAt: { type: "timestamp", nullable: false },
2029
+ status: optionalString,
2030
+ level: { type: "level", nullable: true },
2031
+ stepId: optionalString,
2032
+ stepKind: optionalString,
2033
+ datasetId: optionalString,
2034
+ phase: optionalString,
2035
+ provider: optionalString,
2036
+ operation: optionalString,
2037
+ producerAttempt: { type: "number", nullable: true }
2038
+ };
2039
+ var RUN_EVENT_QUERY_RETENTION_MS = 7 * 864e5;
2040
+ var RUN_EVENT_QUERY_MAX_LIMIT = 200;
2041
+ var RUN_EVENT_QUERY_MAX_PAYLOAD_LIMIT = 10;
2042
+ var RUN_EVENT_QUERY_MAX_CURSOR_BYTES = 48 * 1024;
2043
+ var RUN_EVENT_QUERY_MAX_REQUEST_BYTES = 64 * 1024;
2044
+ var MAX_BYTES = 8192;
2045
+ var MAX_DEPTH = 8;
2046
+ var MAX_PREDICATES = 64;
2047
+ var OPERATORS = [
2048
+ "eq",
2049
+ "ne",
2050
+ "gt",
2051
+ "gte",
2052
+ "lt",
2053
+ "lte",
2054
+ "exists",
2055
+ "in"
2056
+ ];
2057
+ var RunEventQueryInputError = class extends TypeError {
2058
+ constructor(message, code = "invalid_run_event_query") {
2059
+ super(message);
2060
+ this.code = code;
2061
+ this.name = "RunEventQueryInputError";
2062
+ }
2063
+ };
2064
+ function fail(message) {
2065
+ throw new RunEventQueryInputError(message);
2066
+ }
2067
+ function object(value) {
2068
+ return value !== null && typeof value === "object" && !Array.isArray(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
2069
+ }
2070
+ function bounded(value, maxBytes = MAX_BYTES) {
2071
+ let encoded;
2072
+ try {
2073
+ encoded = JSON.stringify(value);
2074
+ } catch {
2075
+ fail("Run event query must be bounded JSON without cycles.");
2076
+ }
2077
+ if (!encoded || new TextEncoder().encode(encoded).length > maxBytes)
2078
+ fail(`Run event query exceeds ${maxBytes} bytes.`);
2079
+ }
2080
+ function validateRunEventField(value) {
2081
+ if (typeof value !== "string") fail("Run event field must be a string.");
2082
+ const field = value.startsWith("$.") ? value.slice(2) : value;
2083
+ if (Object.prototype.hasOwnProperty.call(RUN_EVENT_QUERY_FIELD_CATALOG, field))
2084
+ return field;
2085
+ if (/^context\.[A-Za-z_][A-Za-z0-9_]{0,63}$/.test(field) && !["__proto__", "prototype", "constructor"].includes(field.slice(8)))
2086
+ return field;
2087
+ const alternatives = {
2088
+ step: "stepId",
2089
+ severity: "level",
2090
+ timestamp: "occurredAt",
2091
+ play: "playName",
2092
+ run: "runId",
2093
+ attempt: "producerAttempt"
2094
+ };
2095
+ fail(
2096
+ `Unsupported run event field: ${field}. Use ${alternatives[field] ?? "a catalog field or context.<key>"}; call fields() for supported fields.`
2097
+ );
2098
+ }
2099
+ function scalar(field, value, op) {
2100
+ if (value !== null && typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean")
2101
+ fail(`Run event ${field} requires a JSON scalar.`);
2102
+ if (typeof value === "number" && !Number.isFinite(value))
2103
+ fail(`Run event ${field} requires a finite number.`);
2104
+ if (typeof value === "string" && new TextEncoder().encode(value).length > 1024)
2105
+ fail(`Run event ${field} value exceeds 1024 bytes.`);
2106
+ const descriptor = RUN_EVENT_QUERY_FIELD_CATALOG[field];
2107
+ if (descriptor) {
2108
+ if (value === null) {
2109
+ if (!descriptor.nullable) fail(`Run event ${field} cannot be null.`);
2110
+ } else if (descriptor.type === "number") {
2111
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 1)
2112
+ fail(`Run event ${field} requires a positive integer.`);
2113
+ } else if (typeof value !== "string")
2114
+ fail(`Run event ${field} requires a string.`);
2115
+ else if (descriptor.type === "level" && !RUN_LOG_LEVELS.includes(value))
2116
+ fail("Run event level requires debug, info, warn or error.");
2117
+ else if (descriptor.type === "timestamp") {
2118
+ value = normalizeRunEventQueryTimestamp(value);
2119
+ }
2120
+ }
2121
+ if (["gt", "gte", "lt", "lte"].includes(op) && (value === null || typeof value === "boolean"))
2122
+ fail(`Run event ${op} requires a string or number.`);
2123
+ return value;
2124
+ }
2125
+ function comparison(field, op, value) {
2126
+ if (!OPERATORS.includes(op))
2127
+ fail(`Unsupported run event operator: ${op}. Use ${OPERATORS.join(", ")}.`);
2128
+ if (op === "exists") {
2129
+ if (typeof value !== "boolean")
2130
+ fail("Run event exists requires a boolean.");
2131
+ return { field, op, value };
2132
+ }
2133
+ if (op === "in") {
2134
+ if (!Array.isArray(value) || value.length < 1 || value.length > 32)
2135
+ fail("Run event in requires between 1 and 32 scalars.");
2136
+ return { field, op, value: value.map((item) => scalar(field, item, "eq")) };
2137
+ }
2138
+ return {
2139
+ field,
2140
+ op,
2141
+ value: scalar(field, value, op)
2142
+ };
2143
+ }
2144
+ function admitObject(input, depth = 0, budget = { count: 0 }) {
2145
+ if (depth > MAX_DEPTH) fail("Run event where exceeds depth 8.");
2146
+ if (!object(input) || !Object.keys(input).length)
2147
+ fail("Run event where requires a nonempty object.");
2148
+ const terms = [];
2149
+ const fieldTerms = (raw, filter) => {
2150
+ const field = validateRunEventField(raw);
2151
+ const operators = object(filter) ? Object.entries(filter) : [["eq", filter]];
2152
+ if (!operators.length)
2153
+ fail(`Run event ${field} has an empty operator object.`);
2154
+ for (const [op, value] of operators) {
2155
+ if (++budget.count > MAX_PREDICATES)
2156
+ fail("Run event where exceeds 64 predicates.");
2157
+ terms.push(comparison(field, op, value));
2158
+ }
2159
+ };
2160
+ for (const [key, filter] of Object.entries(input)) {
2161
+ if (key === "and" || key === "or") {
2162
+ if (!Array.isArray(filter) || filter.length < 1 || filter.length > MAX_PREDICATES)
2163
+ fail(`Run event ${key} requires a nonempty bounded array.`);
2164
+ const children = filter.map(
2165
+ (item) => admitObject(item, depth + 1, budget)
2166
+ );
2167
+ terms.push(key === "and" ? { and: children } : { or: children });
2168
+ } else if (key === "context") {
2169
+ if (!object(filter) || !Object.keys(filter).length)
2170
+ fail("Run event context requires flat scalar fields.");
2171
+ for (const [contextKey, value] of Object.entries(filter))
2172
+ fieldTerms(`context.${contextKey}`, value);
2173
+ } else fieldTerms(key, filter);
2174
+ }
2175
+ return terms.length === 1 ? terms[0] : { and: terms };
2176
+ }
2177
+ function compact(predicate) {
2178
+ if ("and" in predicate) {
2179
+ const merged = {};
2180
+ for (const term of predicate.and) {
2181
+ const child = compact(term);
2182
+ for (const [key, value] of Object.entries(child)) {
2183
+ if (key === "and") return { and: predicate.and.map(compact) };
2184
+ if (key === "context") {
2185
+ const context = merged.context ?? {};
2186
+ for (const [name, filter2] of Object.entries(value)) {
2187
+ if (Object.prototype.hasOwnProperty.call(context, name)) {
2188
+ const combined = combineFilters(context[name], filter2);
2189
+ if (!combined) return { and: predicate.and.map(compact) };
2190
+ context[name] = combined;
2191
+ } else context[name] = filter2;
2192
+ }
2193
+ merged.context = context;
2194
+ } else if (Object.prototype.hasOwnProperty.call(merged, key)) {
2195
+ const combined = key === "or" ? void 0 : combineFilters(merged[key], value);
2196
+ if (!combined) return { and: predicate.and.map(compact) };
2197
+ merged[key] = combined;
2198
+ } else merged[key] = value;
2199
+ }
2200
+ }
2201
+ return merged;
2202
+ }
2203
+ if ("or" in predicate) return { or: predicate.or.map(compact) };
2204
+ const filter = predicate.op === "eq" ? predicate.value : { [predicate.op]: predicate.value };
2205
+ if (predicate.field.startsWith("context."))
2206
+ return { context: { [predicate.field.slice(8)]: filter } };
2207
+ return { [predicate.field]: filter };
2208
+ }
2209
+ function combineFilters(left, right) {
2210
+ const first = object(left) ? left : { eq: left };
2211
+ const second = object(right) ? right : { eq: right };
2212
+ if (Object.keys(first).some(
2213
+ (key) => Object.prototype.hasOwnProperty.call(second, key)
2214
+ ))
2215
+ return void 0;
2216
+ return { ...first, ...second };
2217
+ }
2218
+ function canonical(predicate) {
2219
+ if ("field" in predicate) return predicate;
2220
+ const operator = "and" in predicate ? "and" : "or";
2221
+ const source = "and" in predicate ? predicate.and : predicate.or;
2222
+ const terms = source.map(canonical).flatMap((term) => {
2223
+ if (operator === "and" && "and" in term) return term.and;
2224
+ if (operator === "or" && "or" in term) return term.or;
2225
+ return [term];
2226
+ });
2227
+ terms.sort((a, b) => JSON.stringify(a).localeCompare(JSON.stringify(b)));
2228
+ const unique = terms.filter(
2229
+ (term, i) => i === 0 || JSON.stringify(term) !== JSON.stringify(terms[i - 1])
2230
+ );
2231
+ if (unique.length === 1) return unique[0];
2232
+ return operator === "and" ? { and: unique } : { or: unique };
2233
+ }
2234
+ function parseDsl(input) {
2235
+ let position = 0;
2236
+ let count = 0;
2237
+ const skip = () => {
2238
+ while (/\s/.test(input[position] ?? "") && position < input.length)
2239
+ position++;
2240
+ };
2241
+ const take = (token) => {
2242
+ skip();
2243
+ if (input.startsWith(token, position)) {
2244
+ position += token.length;
2245
+ return true;
2246
+ }
2247
+ return false;
2248
+ };
2249
+ const json = () => {
2250
+ skip();
2251
+ const start = position;
2252
+ if (input[position] === '"') {
2253
+ position++;
2254
+ let closed = false;
2255
+ while (position < input.length) {
2256
+ const char = input[position++];
2257
+ if (char === "\\") position++;
2258
+ else if (char === '"') {
2259
+ closed = true;
2260
+ break;
2261
+ }
2262
+ }
2263
+ if (!closed) fail("Run event DSL has an unterminated JSON string.");
2264
+ } else {
2265
+ const match = /^(?:true|false|null|-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?)/.exec(
2266
+ input.slice(position)
2267
+ );
2268
+ if (!match)
2269
+ fail("Run event DSL requires a JSON quoted string or scalar.");
2270
+ position += match[0].length;
2271
+ }
2272
+ try {
2273
+ return JSON.parse(input.slice(start, position));
2274
+ } catch {
2275
+ fail("Run event DSL requires valid JSON scalars.");
2276
+ }
2277
+ };
2278
+ const term = (depth) => {
2279
+ if (depth > MAX_DEPTH) fail("Run event where exceeds depth 8.");
2280
+ if (take("(")) {
2281
+ const nested = or(depth + 1);
2282
+ if (!take(")")) fail("Run event DSL is missing a closing parenthesis.");
2283
+ return nested;
2284
+ }
2285
+ skip();
2286
+ const match = /^(?:\$\.)?[A-Za-z_][A-Za-z0-9_.]*/.exec(
2287
+ input.slice(position)
2288
+ );
2289
+ if (!match) fail("Run event DSL requires a supported field.");
2290
+ position += match[0].length;
2291
+ const field = validateRunEventField(match[0]);
2292
+ if (++count > MAX_PREDICATES)
2293
+ fail("Run event where exceeds 64 predicates.");
2294
+ skip();
2295
+ const operation = /^(==|!=|>=|<=|>|<|\b(?:eq|ne|gte|gt|lte|lt|in|exists)\b)/.exec(
2296
+ input.slice(position)
2297
+ );
2298
+ if (!operation)
2299
+ fail("Run event DSL requires a supported comparison operator.");
2300
+ position += operation[0].length;
2301
+ const symbols = {
2302
+ "==": "eq",
2303
+ "!=": "ne",
2304
+ ">=": "gte",
2305
+ "<=": "lte",
2306
+ ">": "gt",
2307
+ "<": "lt"
2308
+ };
2309
+ const op = symbols[operation[0]] ?? operation[0];
2310
+ if (op === "in") {
2311
+ if (!take("[")) fail("Run event DSL in requires a JSON scalar array.");
2312
+ const values = [];
2313
+ if (!take("]")) {
2314
+ do {
2315
+ values.push(json());
2316
+ if (values.length > 32)
2317
+ fail("Run event in requires between 1 and 32 scalars.");
2318
+ } while (take(","));
2319
+ if (!take("]")) fail("Run event DSL in requires a closing bracket.");
2320
+ }
2321
+ return comparison(field, op, values);
2322
+ }
2323
+ return comparison(field, op, json());
2324
+ };
2325
+ const and = (depth) => {
2326
+ const terms = [term(depth)];
2327
+ while (take("&&")) terms.push(term(depth));
2328
+ return terms.length === 1 ? terms[0] : { and: terms };
2329
+ };
2330
+ const or = (depth) => {
2331
+ const terms = [and(depth)];
2332
+ while (take("||")) terms.push(and(depth));
2333
+ return terms.length === 1 ? terms[0] : { or: terms };
2334
+ };
2335
+ const result = or(0);
2336
+ skip();
2337
+ if (position !== input.length)
2338
+ fail(`Run event DSL has unsupported input at position ${position}.`);
2339
+ return result;
2340
+ }
2341
+ function parseRunEventWhere(input) {
2342
+ bounded(input);
2343
+ const where = compact(
2344
+ canonical(typeof input === "string" ? parseDsl(input) : admitObject(input))
2345
+ );
2346
+ bounded(where);
2347
+ return where;
2348
+ }
2349
+ function normalizeRunEventQueryTimestamp(value) {
2350
+ let extraMicros = "";
2351
+ if (typeof value === "string") {
2352
+ const timestamp = /^[+-]?\d{4,6}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.(\d{1,6}))?(?:Z|[+-]\d{2}:\d{2})$/.exec(
2353
+ value
2354
+ );
2355
+ if (!timestamp)
2356
+ fail(
2357
+ "Run event time bounds require an ISO timestamp with a timezone and at most six fractional digits."
2358
+ );
2359
+ extraMicros = (timestamp[1] ?? "").padEnd(6, "0").slice(3);
2360
+ }
2361
+ const date = new Date(value);
2362
+ if (!Number.isFinite(date.getTime()))
2363
+ fail("Run event time bound is invalid.");
2364
+ const canonical2 = date.toISOString();
2365
+ return /[1-9]/.test(extraMicros) ? canonical2.replace(/Z$/, `${extraMicros}Z`) : canonical2;
2366
+ }
2367
+ function timestampMicros(value) {
2368
+ const fraction = /\.(\d+)Z$/.exec(value)?.[1] ?? "";
2369
+ return BigInt(Date.parse(value)) * BigInt(1e3) + BigInt(fraction.padEnd(6, "0").slice(3));
2370
+ }
2371
+ function time(value, nowMs, fallback) {
2372
+ if (value === void 0) value = fallback;
2373
+ let timestamp;
2374
+ if (typeof value === "number") timestamp = value;
2375
+ else if (typeof value === "string") {
2376
+ const relative = /^(\d+(?:\.\d+)?)(ms|s|m|h|d)$/.exec(value);
2377
+ if (relative) {
2378
+ const units = {
2379
+ ms: 1,
2380
+ s: 1e3,
2381
+ m: 6e4,
2382
+ h: 36e5,
2383
+ d: 864e5
2384
+ };
2385
+ timestamp = nowMs - Number(relative[1]) * units[relative[2]];
2386
+ } else {
2387
+ return normalizeRunEventQueryTimestamp(value);
2388
+ }
2389
+ } else fail("Run event time bounds require a timestamp or duration.");
2390
+ return normalizeRunEventQueryTimestamp(timestamp);
2391
+ }
2392
+ function exact(value, name) {
2393
+ if (typeof value !== "string" || !value.trim() || value.length > 256)
2394
+ fail(
2395
+ `Run event ${name} requires a nonempty string of at most 256 characters.`
2396
+ );
2397
+ return value;
2398
+ }
2399
+ var CRITERIA_KEYS = [
2400
+ "since",
2401
+ "until",
2402
+ "where",
2403
+ "runId",
2404
+ "stepId",
2405
+ "minLevel",
2406
+ "text",
2407
+ "playName",
2408
+ "kind"
2409
+ ];
2410
+ function normalizeRunEventQuery(criteria, nowMs = Date.now()) {
2411
+ if (!object(criteria)) fail("Run event criteria requires an object.");
2412
+ bounded(criteria, RUN_EVENT_QUERY_MAX_REQUEST_BYTES);
2413
+ for (const key of Object.keys(criteria)) {
2414
+ if (!CRITERIA_KEYS.includes(key))
2415
+ fail(`Unsupported run event criterion: ${key}.`);
2416
+ }
2417
+ const until = time(criteria.until, nowMs, nowMs);
2418
+ const since = time(criteria.since, nowMs, Date.parse(until) - 36e5);
2419
+ if (timestampMicros(since) >= timestampMicros(until) || timestampMicros(until) - timestampMicros(since) > BigInt(RUN_EVENT_QUERY_RETENTION_MS) * BigInt(1e3))
2420
+ fail("Run event query requires a window of at most seven days.");
2421
+ const query = { since, until };
2422
+ if (criteria.where !== void 0)
2423
+ query.where = parseRunEventWhere(criteria.where);
2424
+ for (const name of ["runId", "stepId", "playName", "kind"]) {
2425
+ if (criteria[name] !== void 0) query[name] = exact(criteria[name], name);
2426
+ }
2427
+ if (criteria.minLevel !== void 0) {
2428
+ if (!RUN_LOG_LEVELS.includes(criteria.minLevel))
2429
+ fail("Run event minLevel requires debug, info, warn or error.");
2430
+ query.minLevel = criteria.minLevel;
2431
+ }
2432
+ if (criteria.text !== void 0) {
2433
+ if (typeof criteria.text !== "string" || !criteria.text.length || new TextEncoder().encode(criteria.text).length > 1024)
2434
+ fail("Run event text requires between 1 and 1024 bytes.");
2435
+ query.text = criteria.text;
2436
+ }
2437
+ return query;
2438
+ }
2439
+ function normalizeRunEventOperationRequest(input, nowMs = Date.now()) {
2440
+ bounded(input, RUN_EVENT_QUERY_MAX_REQUEST_BYTES);
2441
+ if (!object(input)) fail("Run event operation requires an object.");
2442
+ const operation = input.operation;
2443
+ if (!["list", "count", "summarize", "fields"].includes(String(operation)))
2444
+ fail("Run event operation requires list, count, summarize or fields.");
2445
+ if (input.resource !== "logs" && input.resource !== "events")
2446
+ fail("Run event resource requires logs or events.");
2447
+ const allowed = [
2448
+ "operation",
2449
+ "resource",
2450
+ "runId",
2451
+ ...operation === "fields" ? [] : CRITERIA_KEYS,
2452
+ ...operation === "list" ? ["limit", "cursor", "includePayloads"] : operation === "summarize" ? ["groupBy", "measures", "limit", "cursor"] : []
2453
+ ];
2454
+ for (const key of Object.keys(input)) {
2455
+ if (!allowed.includes(key))
2456
+ fail(`Run event ${operation} does not support ${key}.`);
2457
+ }
2458
+ const base = {
2459
+ operation,
2460
+ resource: input.resource,
2461
+ ...input.runId === void 0 ? {} : { runId: exact(input.runId, "runId") }
2462
+ };
2463
+ if (operation === "fields") return base;
2464
+ if (input.resource === "logs" && !base.runId)
2465
+ fail("Run event logs require runId.");
2466
+ if (input.cursor !== void 0 && (typeof input.cursor !== "string" || !input.cursor.length || input.cursor.length > RUN_EVENT_QUERY_MAX_CURSOR_BYTES))
2467
+ fail("Run event cursor is invalid.");
2468
+ const rawCriteria = Object.fromEntries(
2469
+ Object.entries(input).filter(
2470
+ ([key]) => CRITERIA_KEYS.includes(key) && (key !== "runId" || input.resource === "events")
2471
+ )
2472
+ );
2473
+ const query = normalizeRunEventQuery(
2474
+ input.cursor === void 0 ? rawCriteria : { ...rawCriteria, since: nowMs - 36e5, until: nowMs },
2475
+ nowMs
2476
+ );
2477
+ const criteria = { ...query };
2478
+ if (input.cursor !== void 0) {
2479
+ if (input.since === void 0) delete criteria.since;
2480
+ else criteria.since = time(input.since, nowMs, nowMs - 36e5);
2481
+ if (input.until === void 0) delete criteria.until;
2482
+ else criteria.until = time(input.until, nowMs, nowMs);
2483
+ }
2484
+ if (operation === "count")
2485
+ return { ...base, ...criteria };
2486
+ const limit = input.limit ?? (input.includePayloads === true ? 10 : 50);
2487
+ if (!Number.isSafeInteger(limit) || limit < 1 || limit > RUN_EVENT_QUERY_MAX_LIMIT)
2488
+ fail("Run event limit must be between 1 and 200.");
2489
+ const page = {
2490
+ limit,
2491
+ ...input.cursor === void 0 ? {} : { cursor: input.cursor }
2492
+ };
2493
+ if (operation === "list") {
2494
+ if (input.includePayloads !== void 0 && typeof input.includePayloads !== "boolean")
2495
+ fail("Run event includePayloads requires a boolean.");
2496
+ if (input.includePayloads === true && limit > RUN_EVENT_QUERY_MAX_PAYLOAD_LIMIT)
2497
+ fail("Run event payload pages cannot exceed 10 rows.");
2498
+ return {
2499
+ ...base,
2500
+ ...criteria,
2501
+ ...page,
2502
+ ...input.includePayloads === void 0 ? {} : { includePayloads: input.includePayloads }
2503
+ };
2504
+ }
2505
+ if (!Array.isArray(input.groupBy) || input.groupBy.length > 4)
2506
+ fail("Run event groupBy requires at most four fields.");
2507
+ const groupBy = input.groupBy.map(validateRunEventField);
2508
+ if (new Set(groupBy).size !== groupBy.length)
2509
+ fail("Run event groupBy fields must be distinct.");
2510
+ const rawMeasures = input.measures ?? [{ op: "count" }];
2511
+ if (!Array.isArray(rawMeasures) || rawMeasures.length < 1 || rawMeasures.length > 8)
2512
+ fail("Run event measures require between 1 and 8 entries.");
2513
+ const names = /* @__PURE__ */ new Set();
2514
+ const measures = rawMeasures.map((measure) => {
2515
+ if (!object(measure) || measure.op !== "count" && measure.op !== "sum")
2516
+ fail("Run event measures support count and sum.");
2517
+ for (const key of Object.keys(measure)) {
2518
+ if (!["op", "as", ...measure.op === "sum" ? ["field"] : []].includes(key))
2519
+ fail(`Unsupported run event measure option: ${key}.`);
2520
+ }
2521
+ const field = measure.op === "sum" ? validateRunEventField(measure.field) : void 0;
2522
+ if (field && !field.startsWith("context.") && RUN_EVENT_QUERY_FIELD_CATALOG[field].type !== "number")
2523
+ fail(`Run event sum requires a numeric field: ${field}.`);
2524
+ const name = measure.as ?? (field ? `sum_${field.replaceAll(".", "_")}` : "count");
2525
+ if (typeof name !== "string" || !/^[A-Za-z_][A-Za-z0-9_]{0,63}$/.test(name) || names.has(name))
2526
+ fail("Run event measure names must be distinct identifiers.");
2527
+ names.add(name);
2528
+ return field ? { op: "sum", field, as: name } : { op: "count", as: name };
2529
+ });
2530
+ return {
2531
+ ...base,
2532
+ ...criteria,
2533
+ ...page,
2534
+ groupBy,
2535
+ measures
2536
+ };
2537
+ }
2538
+
2016
2539
  // src/types.ts
2017
2540
  function isStopAllPlayRunsDryRunResult(result) {
2018
2541
  return "dryRun" in result && result.dryRun === true;
@@ -2555,7 +3078,21 @@ var DeeplineClient = class _DeeplineClient {
2555
3078
  history: (options2) => this.getRunsHistory(options2),
2556
3079
  watch: (runId, options2) => this.watchRunToTerminal(runId, options2),
2557
3080
  tail: (runId, options2) => this.tailRun(runId, options2),
2558
- logs: (runId, options2) => this.getRunLogs(runId, options2),
3081
+ logs: Object.assign(
3082
+ (runId, options2) => this.getRunLogs(runId, options2),
3083
+ {
3084
+ query: (runId, options2) => this.queryRunLogs(runId, options2),
3085
+ count: (runId, criteria) => this.countRunLogs(runId, criteria),
3086
+ summarize: (runId, options2) => this.summarizeRunLogs(runId, options2),
3087
+ fields: (options2) => this.getRunEventFields("logs", options2)
3088
+ }
3089
+ ),
3090
+ events: {
3091
+ list: (options2) => this.listRunEvents(options2),
3092
+ count: (criteria) => this.countRunEvents(criteria),
3093
+ summarize: (options2) => this.summarizeRunEvents(options2),
3094
+ fields: (options2) => this.getRunEventFields("events", options2)
3095
+ },
2559
3096
  searchEvents: (options2) => this.searchRunEvents(options2),
2560
3097
  input: (runId) => this.getRunInput(runId),
2561
3098
  rerun: (runId, options2) => this.rerun(runId, options2),
@@ -3951,6 +4488,115 @@ var DeeplineClient = class _DeeplineClient {
3951
4488
  ...probe.logsTruncated ? { logsTruncated: true } : {}
3952
4489
  };
3953
4490
  }
4491
+ /** Query one page of this run's retained logs. `where` accepts typed objects or the shared filter language. */
4492
+ async queryRunLogs(runId, options = {}) {
4493
+ this.assertRunLogQueryRunId(runId, options);
4494
+ const { runtime, ...query } = options;
4495
+ return this.postRunEventQuery(
4496
+ { ...query, operation: "list", resource: "logs", runId },
4497
+ runtime
4498
+ );
4499
+ }
4500
+ /** Count matching retained logs exactly, without fetching list pages or saved results. */
4501
+ async countRunLogs(runId, criteria = {}) {
4502
+ this.assertRunLogQueryRunId(runId, criteria);
4503
+ const { runtime, ...query } = criteria;
4504
+ return this.postRunEventQuery(
4505
+ { ...query, operation: "count", resource: "logs", runId },
4506
+ runtime
4507
+ );
4508
+ }
4509
+ /** Summarize retained logs with explicit group pagination and count or numeric sums. */
4510
+ async summarizeRunLogs(runId, options) {
4511
+ this.assertRunLogQueryRunId(runId, options);
4512
+ const { runtime, ...query } = options;
4513
+ return this.postRunEventQuery(
4514
+ { ...query, operation: "summarize", resource: "logs", runId },
4515
+ runtime
4516
+ );
4517
+ }
4518
+ /** Query one page of retained lifecycle, log and receipt events in the active organization. */
4519
+ async listRunEvents(options = {}) {
4520
+ const { runtime, ...query } = options;
4521
+ return this.postRunEventQuery(
4522
+ { ...query, operation: "list", resource: "events" },
4523
+ runtime
4524
+ );
4525
+ }
4526
+ /** Count matching retained events exactly in one server query. */
4527
+ async countRunEvents(criteria = {}) {
4528
+ const { runtime, ...query } = criteria;
4529
+ return this.postRunEventQuery(
4530
+ { ...query, operation: "count", resource: "events" },
4531
+ runtime
4532
+ );
4533
+ }
4534
+ /**
4535
+ * Group retained events with exact counts, numeric sums and continuation.
4536
+ * Fractional sums use JavaScript number precision.
4537
+ */
4538
+ async summarizeRunEvents(options) {
4539
+ const { runtime, ...query } = options;
4540
+ return this.postRunEventQuery(
4541
+ { ...query, operation: "summarize", resource: "events" },
4542
+ runtime
4543
+ );
4544
+ }
4545
+ /** Discover query fields and their recorded types; custom scalar fields use `context.<key>`. */
4546
+ async getRunEventFields(resource = "events", options = {}) {
4547
+ const { runtime, ...query } = options;
4548
+ return this.postRunEventQuery(
4549
+ { ...query, operation: "fields", resource },
4550
+ runtime
4551
+ );
4552
+ }
4553
+ async postRunEventQuery(input, selection) {
4554
+ const request = normalizeRunEventOperationRequest(input);
4555
+ const params = new URLSearchParams();
4556
+ let headers;
4557
+ let selectedRuntime;
4558
+ if (selection !== void 0) {
4559
+ const runtime = normalizePlayRuntimeSelection(selection);
4560
+ if (!runtime) {
4561
+ throw new DeeplineError(
4562
+ "Run event queries require a valid Preview runtime selection.",
4563
+ void 0,
4564
+ "INVALID_RUNTIME_SELECTION"
4565
+ );
4566
+ }
4567
+ params.set("runtime", "preview");
4568
+ params.set("namespace", runtime.namespace);
4569
+ if (runtime.backend) params.set("backend", runtime.backend);
4570
+ headers = runtimeSelectionHeaders(runtime);
4571
+ selectedRuntime = runtime;
4572
+ } else {
4573
+ headers = isolatedCiRuntimeEventReadHeaders();
4574
+ }
4575
+ const suffix = params.size > 0 ? `?${params.toString()}` : "";
4576
+ const result = await this.http.post(
4577
+ `/api/v2/runs/events${suffix}`,
4578
+ request,
4579
+ headers,
4580
+ { retryApiErrors: true }
4581
+ );
4582
+ if (selectedRuntime && result && typeof result === "object" && "query" in result) {
4583
+ return {
4584
+ ...result,
4585
+ query: {
4586
+ ...result.query,
4587
+ runtime: selectedRuntime
4588
+ }
4589
+ };
4590
+ }
4591
+ return result;
4592
+ }
4593
+ assertRunLogQueryRunId(runId, criteria) {
4594
+ if (criteria && typeof criteria === "object" && "runId" in criteria && criteria.runId !== void 0 && criteria.runId !== runId) {
4595
+ throw new RunEventQueryInputError(
4596
+ "Log criteria runId conflicts with the positional run ID. Pass the run ID only as the first argument."
4597
+ );
4598
+ }
4599
+ }
3954
4600
  /** Read structured history across the active organization without requiring a run ID. Defaults to the last hour, newest first; use the returned cursor and exact time bounds to continue. See [run logs and events](run-events.md) for all kinds, indexed fields, payloads and SDK/API response types. */
3955
4601
  async searchRunEvents(options = {}) {
3956
4602
  const now = Date.now();
@@ -5724,6 +6370,8 @@ export {
5724
6370
  isTransientPlayRunReadError,
5725
6371
  encodeRunLogsCursor,
5726
6372
  isRunLogsCursor,
6373
+ RunEventQueryInputError,
6374
+ normalizeRunEventOperationRequest,
5727
6375
  isStopAllPlayRunsDryRunResult,
5728
6376
  MONITOR_JOB_STATES,
5729
6377
  MONITOR_JOB_PHASES,