@teamkeel/functions-runtime 0.429.2 → 0.431.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.
package/dist/index.cjs CHANGED
@@ -34,6 +34,7 @@ __export(index_exports, {
34
34
  Duration: () => Duration,
35
35
  ErrorPresets: () => ErrorPresets,
36
36
  File: () => File,
37
+ FlowsAPI: () => FlowsAPI,
37
38
  InlineFile: () => InlineFile,
38
39
  KSUID: () => import_ksuid2.default,
39
40
  ModelAPI: () => ModelAPI,
@@ -398,7 +399,13 @@ __name(init, "init");
398
399
  async function forceFlush() {
399
400
  const provider = opentelemetry.trace.getTracerProvider().getDelegate();
400
401
  if (provider && provider.forceFlush) {
401
- await provider.forceFlush();
402
+ try {
403
+ await provider.forceFlush();
404
+ } catch (err) {
405
+ if (process.env.DEBUG) {
406
+ console.error("tracing forceFlush failed:", err.message);
407
+ }
408
+ }
402
409
  }
403
410
  }
404
411
  __name(forceFlush, "forceFlush");
@@ -1081,7 +1088,9 @@ var opMapping = {
1081
1088
  onOrBefore: { op: "<=" },
1082
1089
  after: { op: ">" },
1083
1090
  onOrAfter: { op: ">=" },
1084
- equals: { op: import_kysely4.sql`is not distinct from` },
1091
+ equals: {
1092
+ op: /* @__PURE__ */ __name((v) => v === null || Array.isArray(v) ? import_kysely4.sql`is not distinct from` : "=", "op")
1093
+ },
1085
1094
  notEquals: { op: import_kysely4.sql`is distinct from` },
1086
1095
  equalsRelative: {
1087
1096
  op: import_kysely4.sql`BETWEEN`,
@@ -1137,7 +1146,8 @@ function applyWhereConditions(context6, qb, where = {}) {
1137
1146
  }
1138
1147
  const fieldName = `${context6.tableAlias()}.${(0, import_change_case.snakeCase)(key)}`;
1139
1148
  if (Object.prototype.toString.call(v) !== "[object Object]") {
1140
- qb = qb.where(fieldName, import_kysely4.sql`is not distinct from`, import_kysely4.sql`${v}`);
1149
+ const operator = v === null || Array.isArray(v) ? import_kysely4.sql`is not distinct from` : "=";
1150
+ qb = qb.where(fieldName, operator, import_kysely4.sql`${v}`);
1141
1151
  continue;
1142
1152
  }
1143
1153
  for (const op of Object.keys(v)) {
@@ -1154,9 +1164,10 @@ function applyWhereConditions(context6, qb, where = {}) {
1154
1164
  );
1155
1165
  }
1156
1166
  } else {
1167
+ const operator = typeof mapping.op === "function" ? mapping.op(v[op]) : mapping.op;
1157
1168
  qb = qb.where(
1158
1169
  fieldName,
1159
- mapping.op,
1170
+ operator,
1160
1171
  mapping.value ? mapping.value(v[op]) : import_kysely4.sql`${v[op]}`
1161
1172
  );
1162
1173
  }
@@ -1842,72 +1853,51 @@ function getApiUrl() {
1842
1853
  return apiUrl;
1843
1854
  }
1844
1855
  __name(getApiUrl, "getApiUrl");
1845
- var Task = class _Task {
1856
+ var Task = class {
1846
1857
  static {
1847
1858
  __name(this, "Task");
1848
1859
  }
1849
1860
  /**
1850
- * @param {Object} data The task data from the API
1851
- * @param {string} taskName The name of the task/topic
1852
- * @param {Object|null} identity Optional identity object for authentication
1853
- * @param {string|null} authToken Optional auth token for authentication
1854
- */
1855
- constructor(data, taskName, identity = null, authToken = null) {
1856
- this.id = data.id;
1857
- this.topic = data.name;
1858
- this.status = data.status;
1859
- this.deferredUntil = data.deferredUntil ? new Date(data.deferredUntil) : void 0;
1860
- this.createdAt = new Date(data.createdAt);
1861
- this.updatedAt = new Date(data.updatedAt);
1862
- this.assignedTo = data.assignedTo;
1863
- this.assignedAt = data.assignedAt ? new Date(data.assignedAt) : void 0;
1864
- this.resolvedAt = data.resolvedAt ? new Date(data.resolvedAt) : void 0;
1865
- this.flowRunId = data.flowRunId;
1866
- this._taskName = taskName;
1867
- this._identity = identity;
1868
- this._authToken = authToken;
1869
- }
1870
- /**
1871
- * Returns a new Task instance that will use the given identity for authentication.
1861
+ * Sets the identity for authentication and returns this instance.
1872
1862
  * @param {Object} identity The identity object
1873
- * @returns {Task} A new Task instance with the identity set
1863
+ * @returns {Task} This Task instance with the identity set
1874
1864
  */
1875
1865
  withIdentity(identity) {
1876
- const data = this._toApiData();
1877
- return new _Task(data, this._taskName, identity, null);
1866
+ this._identity = identity;
1867
+ this._authToken = null;
1868
+ return this;
1878
1869
  }
1879
1870
  /**
1880
- * Returns a new Task instance that will use the given auth token for authentication.
1871
+ * Sets the auth token for authentication and returns this instance.
1881
1872
  * @param {string} token The auth token to use
1882
- * @returns {Task} A new Task instance with the auth token set
1873
+ * @returns {Task} This Task instance with the auth token set
1883
1874
  */
1884
1875
  withAuthToken(token) {
1885
- const data = this._toApiData();
1886
- return new _Task(data, this._taskName, null, token);
1876
+ this._identity = null;
1877
+ this._authToken = token;
1878
+ return this;
1887
1879
  }
1888
1880
  /**
1889
- * Converts the task back to API data format for creating new instances.
1890
- * @returns {Object} The task data in API format
1881
+ * Updates the current task instance with data from the API response.
1882
+ * The API returns camelCase fields matching the Go struct JSON tags.
1883
+ * @param {Object} data The API response data
1891
1884
  */
1892
- _toApiData() {
1893
- return {
1894
- id: this.id,
1895
- name: this.topic,
1896
- status: this.status,
1897
- deferredUntil: this.deferredUntil?.toISOString(),
1898
- createdAt: this.createdAt.toISOString(),
1899
- updatedAt: this.updatedAt.toISOString(),
1900
- assignedTo: this.assignedTo,
1901
- assignedAt: this.assignedAt?.toISOString(),
1902
- resolvedAt: this.resolvedAt?.toISOString(),
1903
- flowRunId: this.flowRunId
1904
- };
1885
+ _updateFromResponse(data) {
1886
+ this.id = data.id;
1887
+ this.status = data.status;
1888
+ this.deferredUntil = data.deferredUntil ? new Date(data.deferredUntil) : null;
1889
+ this.createdAt = new Date(data.createdAt);
1890
+ this.updatedAt = new Date(data.updatedAt);
1891
+ this.assignedToId = data.assignedTo ?? null;
1892
+ this.assignedAt = data.assignedAt ? new Date(data.assignedAt) : null;
1893
+ this.resolvedAt = data.resolvedAt ? new Date(data.resolvedAt) : null;
1894
+ this.flowRunId = data.flowRunId ?? null;
1905
1895
  }
1906
1896
  /**
1907
1897
  * Assigns the task to an identity.
1908
1898
  * @param {Object} options Options containing identityId
1909
1899
  * @param {string} options.identityId The ID of the identity to assign the task to
1910
- * @returns {Promise<Task>} The updated task
1900
+ * @returns {Promise<void>}
1911
1901
  */
1912
1902
  async assign({ identityId }) {
1913
1903
  const name = spanNameForModelAPI(this._taskName, "assign");
@@ -1926,12 +1916,12 @@ var Task = class _Task {
1926
1916
  );
1927
1917
  }
1928
1918
  const result = await response.json();
1929
- return new _Task(result, this._taskName, this._identity, this._authToken);
1919
+ this._updateFromResponse(result);
1930
1920
  });
1931
1921
  }
1932
1922
  /**
1933
1923
  * Starts the task, creating and running the associated flow.
1934
- * @returns {Promise<Task>} The updated task with flowRunId
1924
+ * @returns {Promise<void>}
1935
1925
  */
1936
1926
  async start() {
1937
1927
  const name = spanNameForModelAPI(this._taskName, "start");
@@ -1949,12 +1939,12 @@ var Task = class _Task {
1949
1939
  );
1950
1940
  }
1951
1941
  const result = await response.json();
1952
- return new _Task(result, this._taskName, this._identity, this._authToken);
1942
+ this._updateFromResponse(result);
1953
1943
  });
1954
1944
  }
1955
1945
  /**
1956
1946
  * Completes the task.
1957
- * @returns {Promise<Task>} The updated task
1947
+ * @returns {Promise<void>}
1958
1948
  */
1959
1949
  async complete() {
1960
1950
  const name = spanNameForModelAPI(this._taskName, "complete");
@@ -1972,14 +1962,14 @@ var Task = class _Task {
1972
1962
  );
1973
1963
  }
1974
1964
  const result = await response.json();
1975
- return new _Task(result, this._taskName, this._identity, this._authToken);
1965
+ this._updateFromResponse(result);
1976
1966
  });
1977
1967
  }
1978
1968
  /**
1979
1969
  * Defers the task until a specified date.
1980
1970
  * @param {Object} options Options containing deferUntil
1981
1971
  * @param {Date} options.deferUntil The date to defer the task until
1982
- * @returns {Promise<Task>} The updated task
1972
+ * @returns {Promise<void>}
1983
1973
  */
1984
1974
  async defer({ deferUntil }) {
1985
1975
  const name = spanNameForModelAPI(this._taskName, "defer");
@@ -1998,12 +1988,12 @@ var Task = class _Task {
1998
1988
  );
1999
1989
  }
2000
1990
  const result = await response.json();
2001
- return new _Task(result, this._taskName, this._identity, this._authToken);
1991
+ this._updateFromResponse(result);
2002
1992
  });
2003
1993
  }
2004
1994
  /**
2005
1995
  * Cancels the task.
2006
- * @returns {Promise<Task>} The updated task
1996
+ * @returns {Promise<void>}
2007
1997
  */
2008
1998
  async cancel() {
2009
1999
  const name = spanNameForModelAPI(this._taskName, "cancel");
@@ -2021,7 +2011,30 @@ var Task = class _Task {
2021
2011
  );
2022
2012
  }
2023
2013
  const result = await response.json();
2024
- return new _Task(result, this._taskName, this._identity, this._authToken);
2014
+ this._updateFromResponse(result);
2015
+ });
2016
+ }
2017
+ /**
2018
+ * Unassigns the task, removing the current assignee.
2019
+ * @returns {Promise<void>}
2020
+ */
2021
+ async unassign() {
2022
+ const name = spanNameForModelAPI(this._taskName, "unassign");
2023
+ return withSpan(name, async () => {
2024
+ const apiUrl = getApiUrl();
2025
+ const url = `${apiUrl}/topics/json/${this._taskName}/tasks/${this.id}/unassign`;
2026
+ const response = await fetch(url, {
2027
+ method: "PUT",
2028
+ headers: buildHeaders(this._identity, this._authToken)
2029
+ });
2030
+ if (!response.ok) {
2031
+ const errorBody = await response.json().catch(() => ({}));
2032
+ throw new Error(
2033
+ `Failed to unassign task: ${response.status} ${response.statusText} - ${errorBody.message || JSON.stringify(errorBody)}`
2034
+ );
2035
+ }
2036
+ const result = await response.json();
2037
+ this._updateFromResponse(result);
2025
2038
  });
2026
2039
  }
2027
2040
  };
@@ -2031,13 +2044,17 @@ var TaskAPI = class _TaskAPI {
2031
2044
  }
2032
2045
  /**
2033
2046
  * @param {string} taskName The name of the task/topic
2047
+ * @param {Object} tableConfigMap Configuration for table relationships
2034
2048
  * @param {Object|null} identity Optional identity object for authentication
2035
2049
  * @param {string|null} authToken Optional auth token for authentication
2036
2050
  */
2037
- constructor(taskName, identity = null, authToken = null) {
2051
+ constructor(taskName, tableConfigMap = {}, identity = null, authToken = null) {
2038
2052
  this._taskName = taskName;
2053
+ this._tableName = (0, import_change_case.snakeCase)(taskName);
2054
+ this._tableConfigMap = tableConfigMap;
2039
2055
  this._identity = identity;
2040
2056
  this._authToken = authToken;
2057
+ this._modelAPI = new ModelAPI(this._tableName, null, tableConfigMap);
2041
2058
  }
2042
2059
  /**
2043
2060
  * Returns a new TaskAPI instance that will use the given identity for authentication.
@@ -2045,7 +2062,7 @@ var TaskAPI = class _TaskAPI {
2045
2062
  * @returns {TaskAPI} A new TaskAPI instance with the identity set
2046
2063
  */
2047
2064
  withIdentity(identity) {
2048
- return new _TaskAPI(this._taskName, identity, null);
2065
+ return new _TaskAPI(this._taskName, this._tableConfigMap, identity, null);
2049
2066
  }
2050
2067
  /**
2051
2068
  * Returns a new TaskAPI instance that will use the given auth token for authentication.
@@ -2053,13 +2070,14 @@ var TaskAPI = class _TaskAPI {
2053
2070
  * @returns {TaskAPI} A new TaskAPI instance with the auth token set
2054
2071
  */
2055
2072
  withAuthToken(token) {
2056
- return new _TaskAPI(this._taskName, null, token);
2073
+ return new _TaskAPI(this._taskName, this._tableConfigMap, null, token);
2057
2074
  }
2058
2075
  /**
2059
2076
  * Creates a new task with the given data by calling the tasks API.
2077
+ * After creation, fetches the full task data from the database to include all fields.
2060
2078
  * @param {Object} data The task data fields
2061
2079
  * @param {Object} options Optional settings like deferredUntil
2062
- * @returns {Promise<Task>} The created task
2080
+ * @returns {Promise<Task>} The created task with all fields
2063
2081
  */
2064
2082
  async create(data = {}, options = {}) {
2065
2083
  const name = spanNameForModelAPI(this._taskName, "create");
@@ -2084,7 +2102,332 @@ var TaskAPI = class _TaskAPI {
2084
2102
  );
2085
2103
  }
2086
2104
  const result = await response.json();
2087
- return new Task(result, this._taskName, this._identity, this._authToken);
2105
+ const task = await this.findOne({ id: result.id });
2106
+ if (!task) {
2107
+ throw new Error(`Failed to fetch created task with id: ${result.id}`);
2108
+ }
2109
+ return task;
2110
+ });
2111
+ }
2112
+ /**
2113
+ * Wraps an entity with Task methods by setting its prototype and adding required fields.
2114
+ * @param {Object} entity The entity from ModelAPI
2115
+ * @returns {Task} The entity with Task methods
2116
+ */
2117
+ _wrapAsTask(entity) {
2118
+ if (!entity) return null;
2119
+ entity._taskName = this._taskName;
2120
+ entity._identity = this._identity;
2121
+ entity._authToken = this._authToken;
2122
+ Object.setPrototypeOf(entity, Task.prototype);
2123
+ return entity;
2124
+ }
2125
+ /**
2126
+ * Finds a single task matching the given conditions.
2127
+ * Returns a Task instance with both entity fields and action methods.
2128
+ * @param {Object} where Conditions to match
2129
+ * @returns {Promise<Task|null>} The Task instance or null if not found
2130
+ */
2131
+ async findOne(where = {}) {
2132
+ const entity = await this._modelAPI.findOne(where);
2133
+ return this._wrapAsTask(entity);
2134
+ }
2135
+ /**
2136
+ * Finds multiple tasks matching the given conditions.
2137
+ * Returns Task instances with both entity fields and action methods.
2138
+ * @param {Object} params Query parameters including where, limit, offset, orderBy
2139
+ * @returns {Promise<Array<Task>>} Array of Task instances
2140
+ */
2141
+ async findMany(params = {}) {
2142
+ const entities = await this._modelAPI.findMany(params);
2143
+ return entities.map((entity) => this._wrapAsTask(entity));
2144
+ }
2145
+ };
2146
+
2147
+ // src/FlowsAPI.js
2148
+ var import_jsonwebtoken2 = __toESM(require("jsonwebtoken"), 1);
2149
+ function buildHeaders2(identity, authToken) {
2150
+ const headers = { "Content-Type": "application/json" };
2151
+ if (identity !== null) {
2152
+ const base64pk = process.env.KEEL_PRIVATE_KEY;
2153
+ let privateKey = void 0;
2154
+ if (base64pk) {
2155
+ privateKey = Buffer.from(base64pk, "base64").toString("utf8");
2156
+ }
2157
+ headers["Authorization"] = "Bearer " + import_jsonwebtoken2.default.sign({}, privateKey, {
2158
+ algorithm: privateKey ? "RS256" : "none",
2159
+ expiresIn: 60 * 60 * 24,
2160
+ subject: identity.id,
2161
+ issuer: "https://keel.so"
2162
+ });
2163
+ }
2164
+ if (authToken !== null) {
2165
+ headers["Authorization"] = "Bearer " + authToken;
2166
+ }
2167
+ return headers;
2168
+ }
2169
+ __name(buildHeaders2, "buildHeaders");
2170
+ function getApiUrl2() {
2171
+ const apiUrl = process.env.KEEL_API_URL;
2172
+ if (!apiUrl) {
2173
+ throw new Error("KEEL_API_URL environment variable is not set");
2174
+ }
2175
+ return apiUrl;
2176
+ }
2177
+ __name(getApiUrl2, "getApiUrl");
2178
+ var FlowRun = class _FlowRun {
2179
+ static {
2180
+ __name(this, "FlowRun");
2181
+ }
2182
+ /**
2183
+ * @param {Object} data The flow run data from the API
2184
+ * @param {string} flowName The name of the flow
2185
+ * @param {Object|null} identity Optional identity object for authentication
2186
+ * @param {string|null} authToken Optional auth token for authentication
2187
+ */
2188
+ constructor(data, flowName, identity = null, authToken = null) {
2189
+ this.id = data.id;
2190
+ this.name = data.name;
2191
+ this.status = data.status;
2192
+ this.inputs = data.inputs;
2193
+ this.outputs = data.outputs;
2194
+ this.steps = data.steps;
2195
+ this.pendingStep = data.pendingStep;
2196
+ this.createdAt = data.createdAt ? new Date(data.createdAt) : void 0;
2197
+ this.updatedAt = data.updatedAt ? new Date(data.updatedAt) : void 0;
2198
+ this.completedAt = data.completedAt ? new Date(data.completedAt) : void 0;
2199
+ this._flowName = flowName;
2200
+ this._identity = identity;
2201
+ this._authToken = authToken;
2202
+ }
2203
+ /**
2204
+ * Returns a new FlowRun instance that will use the given identity for authentication.
2205
+ * @param {Object} identity The identity object
2206
+ * @returns {FlowRun} A new FlowRun instance with the identity set
2207
+ */
2208
+ withIdentity(identity) {
2209
+ const data = this._toApiData();
2210
+ return new _FlowRun(data, this._flowName, identity, null);
2211
+ }
2212
+ /**
2213
+ * Returns a new FlowRun instance that will use the given auth token for authentication.
2214
+ * @param {string} token The auth token to use
2215
+ * @returns {FlowRun} A new FlowRun instance with the auth token set
2216
+ */
2217
+ withAuthToken(token) {
2218
+ const data = this._toApiData();
2219
+ return new _FlowRun(data, this._flowName, null, token);
2220
+ }
2221
+ /**
2222
+ * Converts the flow run back to API data format for creating new instances.
2223
+ * @returns {Object} The flow run data in API format
2224
+ */
2225
+ _toApiData() {
2226
+ return {
2227
+ id: this.id,
2228
+ name: this.name,
2229
+ status: this.status,
2230
+ inputs: this.inputs,
2231
+ outputs: this.outputs,
2232
+ steps: this.steps,
2233
+ pendingStep: this.pendingStep,
2234
+ createdAt: this.createdAt?.toISOString(),
2235
+ updatedAt: this.updatedAt?.toISOString(),
2236
+ completedAt: this.completedAt?.toISOString()
2237
+ };
2238
+ }
2239
+ /**
2240
+ * Refreshes the flow run state from the API.
2241
+ * @returns {Promise<FlowRun>} The updated flow run
2242
+ */
2243
+ async refresh() {
2244
+ const name = spanNameForModelAPI(this._flowName, "refresh");
2245
+ return withSpan(name, async () => {
2246
+ const apiUrl = getApiUrl2();
2247
+ const url = `${apiUrl}/flows/json/${this._flowName}/${this.id}`;
2248
+ const response = await fetch(url, {
2249
+ method: "GET",
2250
+ headers: buildHeaders2(this._identity, this._authToken)
2251
+ });
2252
+ if (!response.ok) {
2253
+ const errorBody = await response.json().catch(() => ({}));
2254
+ throw new Error(
2255
+ `Failed to refresh flow run: ${response.status} ${response.statusText} - ${errorBody.message || JSON.stringify(errorBody)}`
2256
+ );
2257
+ }
2258
+ const result = await response.json();
2259
+ return new _FlowRun(
2260
+ result,
2261
+ this._flowName,
2262
+ this._identity,
2263
+ this._authToken
2264
+ );
2265
+ });
2266
+ }
2267
+ /**
2268
+ * Cancels the flow run.
2269
+ * @returns {Promise<FlowRun>} The updated flow run
2270
+ */
2271
+ async cancel() {
2272
+ const name = spanNameForModelAPI(this._flowName, "cancel");
2273
+ return withSpan(name, async () => {
2274
+ const apiUrl = getApiUrl2();
2275
+ const url = `${apiUrl}/flows/json/${this._flowName}/${this.id}/cancel`;
2276
+ const response = await fetch(url, {
2277
+ method: "POST",
2278
+ headers: buildHeaders2(this._identity, this._authToken)
2279
+ });
2280
+ if (!response.ok) {
2281
+ const errorBody = await response.json().catch(() => ({}));
2282
+ throw new Error(
2283
+ `Failed to cancel flow run: ${response.status} ${response.statusText} - ${errorBody.message || JSON.stringify(errorBody)}`
2284
+ );
2285
+ }
2286
+ const result = await response.json();
2287
+ return new _FlowRun(
2288
+ result,
2289
+ this._flowName,
2290
+ this._identity,
2291
+ this._authToken
2292
+ );
2293
+ });
2294
+ }
2295
+ };
2296
+ var FlowsAPI = class _FlowsAPI {
2297
+ static {
2298
+ __name(this, "FlowsAPI");
2299
+ }
2300
+ /**
2301
+ * @param {string} flowName The name of the flow
2302
+ * @param {Object|null} identity Optional identity object for authentication
2303
+ * @param {string|null} authToken Optional auth token for authentication
2304
+ */
2305
+ constructor(flowName, identity = null, authToken = null) {
2306
+ this._flowName = flowName;
2307
+ this._identity = identity;
2308
+ this._authToken = authToken;
2309
+ }
2310
+ /**
2311
+ * Returns a new FlowsAPI instance that will use the given identity for authentication.
2312
+ * @param {Object} identity The identity object
2313
+ * @returns {FlowsAPI} A new FlowsAPI instance with the identity set
2314
+ */
2315
+ withIdentity(identity) {
2316
+ return new _FlowsAPI(this._flowName, identity, null);
2317
+ }
2318
+ /**
2319
+ * Returns a new FlowsAPI instance that will use the given auth token for authentication.
2320
+ * @param {string} token The auth token to use
2321
+ * @returns {FlowsAPI} A new FlowsAPI instance with the auth token set
2322
+ */
2323
+ withAuthToken(token) {
2324
+ return new _FlowsAPI(this._flowName, null, token);
2325
+ }
2326
+ /**
2327
+ * Starts a new flow run with the given inputs.
2328
+ * @param {Object} inputs The flow input data
2329
+ * @returns {Promise<FlowRun>} The created flow run
2330
+ */
2331
+ async start(inputs = {}) {
2332
+ const name = spanNameForModelAPI(this._flowName, "start");
2333
+ return withSpan(name, async () => {
2334
+ const apiUrl = getApiUrl2();
2335
+ const url = `${apiUrl}/flows/json/${this._flowName}`;
2336
+ const response = await fetch(url, {
2337
+ method: "POST",
2338
+ headers: buildHeaders2(this._identity, this._authToken),
2339
+ body: JSON.stringify(inputs)
2340
+ });
2341
+ if (!response.ok) {
2342
+ const errorBody = await response.json().catch(() => ({}));
2343
+ throw new Error(
2344
+ `Failed to start flow: ${response.status} ${response.statusText} - ${errorBody.message || JSON.stringify(errorBody)}`
2345
+ );
2346
+ }
2347
+ const result = await response.json();
2348
+ return new FlowRun(
2349
+ result,
2350
+ this._flowName,
2351
+ this._identity,
2352
+ this._authToken
2353
+ );
2354
+ });
2355
+ }
2356
+ /**
2357
+ * Gets a flow run by ID.
2358
+ * @param {string} runId The flow run ID
2359
+ * @returns {Promise<FlowRun>} The flow run
2360
+ */
2361
+ async get(runId) {
2362
+ const name = spanNameForModelAPI(this._flowName, "get");
2363
+ return withSpan(name, async () => {
2364
+ const apiUrl = getApiUrl2();
2365
+ const url = `${apiUrl}/flows/json/${this._flowName}/${runId}`;
2366
+ const response = await fetch(url, {
2367
+ method: "GET",
2368
+ headers: buildHeaders2(this._identity, this._authToken)
2369
+ });
2370
+ if (!response.ok) {
2371
+ const errorBody = await response.json().catch(() => ({}));
2372
+ throw new Error(
2373
+ `Failed to get flow run: ${response.status} ${response.statusText} - ${errorBody.message || JSON.stringify(errorBody)}`
2374
+ );
2375
+ }
2376
+ const result = await response.json();
2377
+ return new FlowRun(
2378
+ result,
2379
+ this._flowName,
2380
+ this._identity,
2381
+ this._authToken
2382
+ );
2383
+ });
2384
+ }
2385
+ /**
2386
+ * Lists flow runs for this flow.
2387
+ * @param {Object} options Optional pagination options
2388
+ * @param {number} options.limit Maximum number of runs to return
2389
+ * @param {number} options.offset Offset for pagination
2390
+ * @returns {Promise<{results: FlowRun[], pageInfo: Object}>} List of flow runs with pagination info
2391
+ */
2392
+ async list(options = {}) {
2393
+ const name = spanNameForModelAPI(this._flowName, "list");
2394
+ return withSpan(name, async () => {
2395
+ const apiUrl = getApiUrl2();
2396
+ const params = new URLSearchParams();
2397
+ if (options.limit) params.set("limit", options.limit.toString());
2398
+ if (options.offset) params.set("offset", options.offset.toString());
2399
+ const url = `${apiUrl}/flows/json/${this._flowName}${params.toString() ? "?" + params.toString() : ""}`;
2400
+ const response = await fetch(url, {
2401
+ method: "GET",
2402
+ headers: buildHeaders2(this._identity, this._authToken)
2403
+ });
2404
+ if (!response.ok) {
2405
+ const errorBody = await response.json().catch(() => ({}));
2406
+ throw new Error(
2407
+ `Failed to list flow runs: ${response.status} ${response.statusText} - ${errorBody.message || JSON.stringify(errorBody)}`
2408
+ );
2409
+ }
2410
+ const result = await response.json();
2411
+ if (Array.isArray(result)) {
2412
+ return {
2413
+ results: result.map(
2414
+ (run) => new FlowRun(run, this._flowName, this._identity, this._authToken)
2415
+ ),
2416
+ pageInfo: {
2417
+ totalCount: result.length,
2418
+ hasNextPage: false
2419
+ }
2420
+ };
2421
+ }
2422
+ return {
2423
+ results: (result.results || []).map(
2424
+ (run) => new FlowRun(run, this._flowName, this._identity, this._authToken)
2425
+ ),
2426
+ pageInfo: result.pageInfo || {
2427
+ totalCount: (result.results || []).length,
2428
+ hasNextPage: false
2429
+ }
2430
+ };
2088
2431
  });
2089
2432
  }
2090
2433
  };
@@ -2262,6 +2605,9 @@ __name(tryExecuteFunction, "tryExecuteFunction");
2262
2605
  // src/handleRequest.js
2263
2606
  var opentelemetry2 = __toESM(require("@opentelemetry/api"), 1);
2264
2607
  async function handleRequest(request, config) {
2608
+ if (request.method === "__ping") {
2609
+ return (0, import_json_rpc_22.createJSONRPCSuccessResponse)(request.id, { status: "ok" });
2610
+ }
2265
2611
  const activeContext = opentelemetry2.propagation.extract(
2266
2612
  opentelemetry2.context.active(),
2267
2613
  request.meta?.tracing
@@ -3869,6 +4215,7 @@ __name(ksuid, "ksuid");
3869
4215
  Duration,
3870
4216
  ErrorPresets,
3871
4217
  File,
4218
+ FlowsAPI,
3872
4219
  InlineFile,
3873
4220
  KSUID,
3874
4221
  ModelAPI,