@langchain/langgraph-sdk 1.3.0 → 1.4.4

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 (181) hide show
  1. package/package.json +5 -5
  2. package/CHANGELOG.md +0 -275
  3. package/dist/_virtual/rolldown_runtime.cjs +0 -25
  4. package/dist/auth/error.cjs +0 -79
  5. package/dist/auth/error.cjs.map +0 -1
  6. package/dist/auth/error.d.cts +0 -13
  7. package/dist/auth/error.d.cts.map +0 -1
  8. package/dist/auth/error.d.ts +0 -13
  9. package/dist/auth/error.d.ts.map +0 -1
  10. package/dist/auth/error.js +0 -78
  11. package/dist/auth/error.js.map +0 -1
  12. package/dist/auth/index.cjs +0 -39
  13. package/dist/auth/index.cjs.map +0 -1
  14. package/dist/auth/index.d.cts +0 -31
  15. package/dist/auth/index.d.cts.map +0 -1
  16. package/dist/auth/index.d.ts +0 -31
  17. package/dist/auth/index.d.ts.map +0 -1
  18. package/dist/auth/index.js +0 -37
  19. package/dist/auth/index.js.map +0 -1
  20. package/dist/auth/types.d.cts +0 -294
  21. package/dist/auth/types.d.cts.map +0 -1
  22. package/dist/auth/types.d.ts +0 -294
  23. package/dist/auth/types.d.ts.map +0 -1
  24. package/dist/client.cjs +0 -1193
  25. package/dist/client.cjs.map +0 -1
  26. package/dist/client.d.cts +0 -780
  27. package/dist/client.d.cts.map +0 -1
  28. package/dist/client.d.ts +0 -780
  29. package/dist/client.d.ts.map +0 -1
  30. package/dist/client.js +0 -1186
  31. package/dist/client.js.map +0 -1
  32. package/dist/index.cjs +0 -6
  33. package/dist/index.d.cts +0 -7
  34. package/dist/index.d.ts +0 -7
  35. package/dist/index.js +0 -4
  36. package/dist/logging/index.cjs +0 -35
  37. package/dist/logging/index.cjs.map +0 -1
  38. package/dist/logging/index.d.cts +0 -47
  39. package/dist/logging/index.d.cts.map +0 -1
  40. package/dist/logging/index.d.ts +0 -47
  41. package/dist/logging/index.d.ts.map +0 -1
  42. package/dist/logging/index.js +0 -34
  43. package/dist/logging/index.js.map +0 -1
  44. package/dist/react/index.cjs +0 -5
  45. package/dist/react/index.d.cts +0 -4
  46. package/dist/react/index.d.ts +0 -4
  47. package/dist/react/index.js +0 -4
  48. package/dist/react/stream.cjs +0 -18
  49. package/dist/react/stream.cjs.map +0 -1
  50. package/dist/react/stream.custom.cjs +0 -129
  51. package/dist/react/stream.custom.cjs.map +0 -1
  52. package/dist/react/stream.custom.d.cts +0 -39
  53. package/dist/react/stream.custom.d.cts.map +0 -1
  54. package/dist/react/stream.custom.d.ts +0 -39
  55. package/dist/react/stream.custom.d.ts.map +0 -1
  56. package/dist/react/stream.custom.js +0 -127
  57. package/dist/react/stream.custom.js.map +0 -1
  58. package/dist/react/stream.d.cts +0 -73
  59. package/dist/react/stream.d.cts.map +0 -1
  60. package/dist/react/stream.d.ts +0 -73
  61. package/dist/react/stream.d.ts.map +0 -1
  62. package/dist/react/stream.js +0 -17
  63. package/dist/react/stream.js.map +0 -1
  64. package/dist/react/stream.lgp.cjs +0 -446
  65. package/dist/react/stream.lgp.cjs.map +0 -1
  66. package/dist/react/stream.lgp.js +0 -445
  67. package/dist/react/stream.lgp.js.map +0 -1
  68. package/dist/react/thread.cjs +0 -22
  69. package/dist/react/thread.cjs.map +0 -1
  70. package/dist/react/thread.js +0 -21
  71. package/dist/react/thread.js.map +0 -1
  72. package/dist/react/types.d.cts +0 -363
  73. package/dist/react/types.d.cts.map +0 -1
  74. package/dist/react/types.d.ts +0 -363
  75. package/dist/react/types.d.ts.map +0 -1
  76. package/dist/react-ui/client.cjs +0 -137
  77. package/dist/react-ui/client.cjs.map +0 -1
  78. package/dist/react-ui/client.d.cts +0 -90
  79. package/dist/react-ui/client.d.cts.map +0 -1
  80. package/dist/react-ui/client.d.ts +0 -90
  81. package/dist/react-ui/client.d.ts.map +0 -1
  82. package/dist/react-ui/client.js +0 -134
  83. package/dist/react-ui/client.js.map +0 -1
  84. package/dist/react-ui/index.cjs +0 -14
  85. package/dist/react-ui/index.cjs.map +0 -1
  86. package/dist/react-ui/index.d.cts +0 -3
  87. package/dist/react-ui/index.d.ts +0 -3
  88. package/dist/react-ui/index.js +0 -9
  89. package/dist/react-ui/index.js.map +0 -1
  90. package/dist/react-ui/server/index.cjs +0 -5
  91. package/dist/react-ui/server/index.d.cts +0 -3
  92. package/dist/react-ui/server/index.d.ts +0 -3
  93. package/dist/react-ui/server/index.js +0 -4
  94. package/dist/react-ui/server/server.cjs +0 -57
  95. package/dist/react-ui/server/server.cjs.map +0 -1
  96. package/dist/react-ui/server/server.d.cts +0 -55
  97. package/dist/react-ui/server/server.d.cts.map +0 -1
  98. package/dist/react-ui/server/server.d.ts +0 -55
  99. package/dist/react-ui/server/server.d.ts.map +0 -1
  100. package/dist/react-ui/server/server.js +0 -56
  101. package/dist/react-ui/server/server.js.map +0 -1
  102. package/dist/react-ui/types.cjs +0 -38
  103. package/dist/react-ui/types.cjs.map +0 -1
  104. package/dist/react-ui/types.d.cts +0 -25
  105. package/dist/react-ui/types.d.cts.map +0 -1
  106. package/dist/react-ui/types.d.ts +0 -25
  107. package/dist/react-ui/types.d.ts.map +0 -1
  108. package/dist/react-ui/types.js +0 -35
  109. package/dist/react-ui/types.js.map +0 -1
  110. package/dist/schema.d.cts +0 -284
  111. package/dist/schema.d.cts.map +0 -1
  112. package/dist/schema.d.ts +0 -284
  113. package/dist/schema.d.ts.map +0 -1
  114. package/dist/singletons/fetch.cjs +0 -24
  115. package/dist/singletons/fetch.cjs.map +0 -1
  116. package/dist/singletons/fetch.d.cts +0 -14
  117. package/dist/singletons/fetch.d.cts.map +0 -1
  118. package/dist/singletons/fetch.d.ts +0 -14
  119. package/dist/singletons/fetch.d.ts.map +0 -1
  120. package/dist/singletons/fetch.js +0 -22
  121. package/dist/singletons/fetch.js.map +0 -1
  122. package/dist/types.d.cts +0 -187
  123. package/dist/types.d.cts.map +0 -1
  124. package/dist/types.d.ts +0 -187
  125. package/dist/types.d.ts.map +0 -1
  126. package/dist/types.messages.d.cts +0 -91
  127. package/dist/types.messages.d.cts.map +0 -1
  128. package/dist/types.messages.d.ts +0 -91
  129. package/dist/types.messages.d.ts.map +0 -1
  130. package/dist/types.stream.d.cts +0 -235
  131. package/dist/types.stream.d.cts.map +0 -1
  132. package/dist/types.stream.d.ts +0 -235
  133. package/dist/types.stream.d.ts.map +0 -1
  134. package/dist/ui/branching.cjs +0 -153
  135. package/dist/ui/branching.cjs.map +0 -1
  136. package/dist/ui/branching.d.cts +0 -22
  137. package/dist/ui/branching.d.cts.map +0 -1
  138. package/dist/ui/branching.d.ts +0 -22
  139. package/dist/ui/branching.d.ts.map +0 -1
  140. package/dist/ui/branching.js +0 -152
  141. package/dist/ui/branching.js.map +0 -1
  142. package/dist/ui/errors.cjs +0 -15
  143. package/dist/ui/errors.cjs.map +0 -1
  144. package/dist/ui/errors.js +0 -14
  145. package/dist/ui/errors.js.map +0 -1
  146. package/dist/ui/manager.cjs +0 -182
  147. package/dist/ui/manager.cjs.map +0 -1
  148. package/dist/ui/manager.js +0 -182
  149. package/dist/ui/manager.js.map +0 -1
  150. package/dist/ui/messages.cjs +0 -70
  151. package/dist/ui/messages.cjs.map +0 -1
  152. package/dist/ui/messages.js +0 -68
  153. package/dist/ui/messages.js.map +0 -1
  154. package/dist/ui/utils.cjs +0 -14
  155. package/dist/ui/utils.cjs.map +0 -1
  156. package/dist/ui/utils.js +0 -12
  157. package/dist/ui/utils.js.map +0 -1
  158. package/dist/utils/async_caller.cjs +0 -111
  159. package/dist/utils/async_caller.cjs.map +0 -1
  160. package/dist/utils/async_caller.d.cts +0 -53
  161. package/dist/utils/async_caller.d.cts.map +0 -1
  162. package/dist/utils/async_caller.d.ts +0 -53
  163. package/dist/utils/async_caller.d.ts.map +0 -1
  164. package/dist/utils/async_caller.js +0 -110
  165. package/dist/utils/async_caller.js.map +0 -1
  166. package/dist/utils/env.cjs +0 -13
  167. package/dist/utils/env.cjs.map +0 -1
  168. package/dist/utils/env.js +0 -12
  169. package/dist/utils/env.js.map +0 -1
  170. package/dist/utils/signals.cjs +0 -20
  171. package/dist/utils/signals.cjs.map +0 -1
  172. package/dist/utils/signals.js +0 -19
  173. package/dist/utils/signals.js.map +0 -1
  174. package/dist/utils/sse.cjs +0 -124
  175. package/dist/utils/sse.cjs.map +0 -1
  176. package/dist/utils/sse.js +0 -122
  177. package/dist/utils/sse.js.map +0 -1
  178. package/dist/utils/stream.cjs +0 -91
  179. package/dist/utils/stream.cjs.map +0 -1
  180. package/dist/utils/stream.js +0 -90
  181. package/dist/utils/stream.js.map +0 -1
package/dist/client.cjs DELETED
@@ -1,1193 +0,0 @@
1
- const require_async_caller = require('./utils/async_caller.cjs');
2
- const require_env = require('./utils/env.cjs');
3
- const require_signals = require('./utils/signals.cjs');
4
- const require_sse = require('./utils/sse.cjs');
5
- const require_stream = require('./utils/stream.cjs');
6
-
7
- //#region src/client.ts
8
- function* iterateHeaders(headers) {
9
- let iter;
10
- let shouldClear = false;
11
- if (headers instanceof Headers) {
12
- const entries = [];
13
- headers.forEach((value, name) => {
14
- entries.push([name, value]);
15
- });
16
- iter = entries;
17
- } else if (Array.isArray(headers)) iter = headers;
18
- else {
19
- shouldClear = true;
20
- iter = Object.entries(headers ?? {});
21
- }
22
- for (const item of iter) {
23
- const name = item[0];
24
- if (typeof name !== "string") throw new TypeError(`Expected header name to be a string, got ${typeof name}`);
25
- const values = Array.isArray(item[1]) ? item[1] : [item[1]];
26
- let didClear = false;
27
- for (const value of values) {
28
- if (value === void 0) continue;
29
- if (shouldClear && !didClear) {
30
- didClear = true;
31
- yield [name, null];
32
- }
33
- yield [name, value];
34
- }
35
- }
36
- }
37
- function mergeHeaders(...headerObjects) {
38
- const outputHeaders = new Headers();
39
- for (const headers of headerObjects) {
40
- if (!headers) continue;
41
- for (const [name, value] of iterateHeaders(headers)) if (value === null) outputHeaders.delete(name);
42
- else outputHeaders.append(name, value);
43
- }
44
- const headerEntries = [];
45
- outputHeaders.forEach((value, name) => {
46
- headerEntries.push([name, value]);
47
- });
48
- return Object.fromEntries(headerEntries);
49
- }
50
- /**
51
- * Get the API key from the environment.
52
- * Precedence:
53
- * 1. explicit argument (if string)
54
- * 2. LANGGRAPH_API_KEY
55
- * 3. LANGSMITH_API_KEY
56
- * 4. LANGCHAIN_API_KEY
57
- *
58
- * @param apiKey - API key provided as an argument. If null, skips environment lookup. If undefined, tries environment.
59
- * @returns The API key if found, otherwise undefined
60
- */
61
- function getApiKey(apiKey) {
62
- if (apiKey === null) return void 0;
63
- if (apiKey) return apiKey;
64
- const prefixes = [
65
- "LANGGRAPH",
66
- "LANGSMITH",
67
- "LANGCHAIN"
68
- ];
69
- for (const prefix of prefixes) {
70
- const envKey = require_env.getEnvironmentVariable(`${prefix}_API_KEY`);
71
- if (envKey) return envKey.trim().replace(/^["']|["']$/g, "");
72
- }
73
- return void 0;
74
- }
75
- const REGEX_RUN_METADATA = /(\/threads\/(?<thread_id>.+))?\/runs\/(?<run_id>.+)/;
76
- function getRunMetadataFromResponse(response) {
77
- const contentLocation = response.headers.get("Content-Location");
78
- if (!contentLocation) return void 0;
79
- const match = REGEX_RUN_METADATA.exec(contentLocation);
80
- if (!match?.groups?.run_id) return void 0;
81
- return {
82
- run_id: match.groups.run_id,
83
- thread_id: match.groups.thread_id || void 0
84
- };
85
- }
86
- var BaseClient = class {
87
- asyncCaller;
88
- timeoutMs;
89
- apiUrl;
90
- defaultHeaders;
91
- onRequest;
92
- constructor(config) {
93
- const callerOptions = {
94
- maxRetries: 4,
95
- maxConcurrency: 4,
96
- ...config?.callerOptions
97
- };
98
- let defaultApiUrl = "http://localhost:8123";
99
- if (!config?.apiUrl && typeof globalThis === "object" && globalThis != null) {
100
- const fetchSmb = Symbol.for("langgraph_api:fetch");
101
- const urlSmb = Symbol.for("langgraph_api:url");
102
- const global = globalThis;
103
- if (global[fetchSmb]) callerOptions.fetch ??= global[fetchSmb];
104
- if (global[urlSmb]) defaultApiUrl = global[urlSmb];
105
- }
106
- this.asyncCaller = new require_async_caller.AsyncCaller(callerOptions);
107
- this.timeoutMs = config?.timeoutMs;
108
- this.apiUrl = config?.apiUrl?.replace(/\/$/, "") || defaultApiUrl;
109
- this.defaultHeaders = config?.defaultHeaders || {};
110
- this.onRequest = config?.onRequest;
111
- const apiKey = getApiKey(config?.apiKey);
112
- if (apiKey) this.defaultHeaders["x-api-key"] = apiKey;
113
- }
114
- prepareFetchOptions(path, options) {
115
- const mutatedOptions = {
116
- ...options,
117
- headers: mergeHeaders(this.defaultHeaders, options?.headers)
118
- };
119
- if (mutatedOptions.json) {
120
- mutatedOptions.body = JSON.stringify(mutatedOptions.json);
121
- mutatedOptions.headers = mergeHeaders(mutatedOptions.headers, { "content-type": "application/json" });
122
- delete mutatedOptions.json;
123
- }
124
- if (mutatedOptions.withResponse) delete mutatedOptions.withResponse;
125
- let timeoutSignal = null;
126
- if (typeof options?.timeoutMs !== "undefined") {
127
- if (options.timeoutMs != null) timeoutSignal = AbortSignal.timeout(options.timeoutMs);
128
- } else if (this.timeoutMs != null) timeoutSignal = AbortSignal.timeout(this.timeoutMs);
129
- mutatedOptions.signal = require_signals.mergeSignals(timeoutSignal, mutatedOptions.signal);
130
- const targetUrl = new URL(`${this.apiUrl}${path}`);
131
- if (mutatedOptions.params) {
132
- for (const [key, value] of Object.entries(mutatedOptions.params)) {
133
- if (value == null) continue;
134
- const strValue = typeof value === "string" || typeof value === "number" ? value.toString() : JSON.stringify(value);
135
- targetUrl.searchParams.append(key, strValue);
136
- }
137
- delete mutatedOptions.params;
138
- }
139
- return [targetUrl, mutatedOptions];
140
- }
141
- async fetch(path, options) {
142
- const [url, init] = this.prepareFetchOptions(path, options);
143
- let finalInit = init;
144
- if (this.onRequest) finalInit = await this.onRequest(url, init);
145
- const response = await this.asyncCaller.fetch(url, finalInit);
146
- const body = (() => {
147
- if (response.status === 202 || response.status === 204) return void 0;
148
- return response.json();
149
- })();
150
- if (options?.withResponse) return [await body, response];
151
- return body;
152
- }
153
- };
154
- var CronsClient = class extends BaseClient {
155
- /**
156
- *
157
- * @param threadId The ID of the thread.
158
- * @param assistantId Assistant ID to use for this cron job.
159
- * @param payload Payload for creating a cron job.
160
- * @returns The created background run.
161
- */
162
- async createForThread(threadId, assistantId, payload) {
163
- const json = {
164
- schedule: payload?.schedule,
165
- input: payload?.input,
166
- config: payload?.config,
167
- context: payload?.context,
168
- metadata: payload?.metadata,
169
- assistant_id: assistantId,
170
- interrupt_before: payload?.interruptBefore,
171
- interrupt_after: payload?.interruptAfter,
172
- webhook: payload?.webhook,
173
- multitask_strategy: payload?.multitaskStrategy,
174
- if_not_exists: payload?.ifNotExists,
175
- checkpoint_during: payload?.checkpointDuring,
176
- durability: payload?.durability
177
- };
178
- return this.fetch(`/threads/${threadId}/runs/crons`, {
179
- method: "POST",
180
- json,
181
- signal: payload?.signal
182
- });
183
- }
184
- /**
185
- *
186
- * @param assistantId Assistant ID to use for this cron job.
187
- * @param payload Payload for creating a cron job.
188
- * @returns
189
- */
190
- async create(assistantId, payload) {
191
- const json = {
192
- schedule: payload?.schedule,
193
- input: payload?.input,
194
- config: payload?.config,
195
- context: payload?.context,
196
- metadata: payload?.metadata,
197
- assistant_id: assistantId,
198
- interrupt_before: payload?.interruptBefore,
199
- interrupt_after: payload?.interruptAfter,
200
- webhook: payload?.webhook,
201
- multitask_strategy: payload?.multitaskStrategy,
202
- if_not_exists: payload?.ifNotExists,
203
- checkpoint_during: payload?.checkpointDuring,
204
- durability: payload?.durability
205
- };
206
- return this.fetch(`/runs/crons`, {
207
- method: "POST",
208
- json,
209
- signal: payload?.signal
210
- });
211
- }
212
- /**
213
- *
214
- * @param cronId Cron ID of Cron job to delete.
215
- */
216
- async delete(cronId, options) {
217
- await this.fetch(`/runs/crons/${cronId}`, {
218
- method: "DELETE",
219
- signal: options?.signal
220
- });
221
- }
222
- /**
223
- *
224
- * @param query Query options.
225
- * @returns List of crons.
226
- */
227
- async search(query) {
228
- return this.fetch("/runs/crons/search", {
229
- method: "POST",
230
- json: {
231
- assistant_id: query?.assistantId ?? void 0,
232
- thread_id: query?.threadId ?? void 0,
233
- limit: query?.limit ?? 10,
234
- offset: query?.offset ?? 0,
235
- sort_by: query?.sortBy ?? void 0,
236
- sort_order: query?.sortOrder ?? void 0,
237
- select: query?.select ?? void 0
238
- },
239
- signal: query?.signal
240
- });
241
- }
242
- /**
243
- * Count cron jobs matching filters.
244
- *
245
- * @param query.assistantId Assistant ID to filter by.
246
- * @param query.threadId Thread ID to filter by.
247
- * @returns Number of cron jobs matching the criteria.
248
- */
249
- async count(query) {
250
- return this.fetch(`/runs/crons/count`, {
251
- method: "POST",
252
- json: {
253
- assistant_id: query?.assistantId ?? void 0,
254
- thread_id: query?.threadId ?? void 0
255
- },
256
- signal: query?.signal
257
- });
258
- }
259
- };
260
- var AssistantsClient = class extends BaseClient {
261
- /**
262
- * Get an assistant by ID.
263
- *
264
- * @param assistantId The ID of the assistant.
265
- * @returns Assistant
266
- */
267
- async get(assistantId, options) {
268
- return this.fetch(`/assistants/${assistantId}`, { signal: options?.signal });
269
- }
270
- /**
271
- * Get the JSON representation of the graph assigned to a runnable
272
- * @param assistantId The ID of the assistant.
273
- * @param options.xray Whether to include subgraphs in the serialized graph representation. If an integer value is provided, only subgraphs with a depth less than or equal to the value will be included.
274
- * @returns Serialized graph
275
- */
276
- async getGraph(assistantId, options) {
277
- return this.fetch(`/assistants/${assistantId}/graph`, {
278
- params: { xray: options?.xray },
279
- signal: options?.signal
280
- });
281
- }
282
- /**
283
- * Get the state and config schema of the graph assigned to a runnable
284
- * @param assistantId The ID of the assistant.
285
- * @returns Graph schema
286
- */
287
- async getSchemas(assistantId, options) {
288
- return this.fetch(`/assistants/${assistantId}/schemas`, { signal: options?.signal });
289
- }
290
- /**
291
- * Get the schemas of an assistant by ID.
292
- *
293
- * @param assistantId The ID of the assistant to get the schema of.
294
- * @param options Additional options for getting subgraphs, such as namespace or recursion extraction.
295
- * @returns The subgraphs of the assistant.
296
- */
297
- async getSubgraphs(assistantId, options) {
298
- if (options?.namespace) return this.fetch(`/assistants/${assistantId}/subgraphs/${options.namespace}`, {
299
- params: { recurse: options?.recurse },
300
- signal: options?.signal
301
- });
302
- return this.fetch(`/assistants/${assistantId}/subgraphs`, {
303
- params: { recurse: options?.recurse },
304
- signal: options?.signal
305
- });
306
- }
307
- /**
308
- * Create a new assistant.
309
- * @param payload Payload for creating an assistant.
310
- * @returns The created assistant.
311
- */
312
- async create(payload) {
313
- return this.fetch("/assistants", {
314
- method: "POST",
315
- json: {
316
- graph_id: payload.graphId,
317
- config: payload.config,
318
- context: payload.context,
319
- metadata: payload.metadata,
320
- assistant_id: payload.assistantId,
321
- if_exists: payload.ifExists,
322
- name: payload.name,
323
- description: payload.description
324
- },
325
- signal: payload.signal
326
- });
327
- }
328
- /**
329
- * Update an assistant.
330
- * @param assistantId ID of the assistant.
331
- * @param payload Payload for updating the assistant.
332
- * @returns The updated assistant.
333
- */
334
- async update(assistantId, payload) {
335
- return this.fetch(`/assistants/${assistantId}`, {
336
- method: "PATCH",
337
- json: {
338
- graph_id: payload.graphId,
339
- config: payload.config,
340
- context: payload.context,
341
- metadata: payload.metadata,
342
- name: payload.name,
343
- description: payload.description
344
- },
345
- signal: payload.signal
346
- });
347
- }
348
- /**
349
- * Delete an assistant.
350
- *
351
- * @param assistantId ID of the assistant.
352
- */
353
- async delete(assistantId, options) {
354
- return this.fetch(`/assistants/${assistantId}`, {
355
- method: "DELETE",
356
- signal: options?.signal
357
- });
358
- }
359
- async search(query) {
360
- const json = {
361
- graph_id: query?.graphId ?? void 0,
362
- name: query?.name ?? void 0,
363
- metadata: query?.metadata ?? void 0,
364
- limit: query?.limit ?? 10,
365
- offset: query?.offset ?? 0,
366
- sort_by: query?.sortBy ?? void 0,
367
- sort_order: query?.sortOrder ?? void 0,
368
- select: query?.select ?? void 0
369
- };
370
- const [assistants, response] = await this.fetch("/assistants/search", {
371
- method: "POST",
372
- json,
373
- withResponse: true,
374
- signal: query?.signal
375
- });
376
- if (query?.includePagination) {
377
- const next = response.headers.get("X-Pagination-Next");
378
- return {
379
- assistants,
380
- next
381
- };
382
- }
383
- return assistants;
384
- }
385
- /**
386
- * Count assistants matching filters.
387
- *
388
- * @param query.metadata Metadata to filter by. Exact match for each key/value.
389
- * @param query.graphId Optional graph id to filter by.
390
- * @param query.name Optional name to filter by.
391
- * @returns Number of assistants matching the criteria.
392
- */
393
- async count(query) {
394
- return this.fetch(`/assistants/count`, {
395
- method: "POST",
396
- json: {
397
- metadata: query?.metadata ?? void 0,
398
- graph_id: query?.graphId ?? void 0,
399
- name: query?.name ?? void 0
400
- },
401
- signal: query?.signal
402
- });
403
- }
404
- /**
405
- * List all versions of an assistant.
406
- *
407
- * @param assistantId ID of the assistant.
408
- * @returns List of assistant versions.
409
- */
410
- async getVersions(assistantId, payload) {
411
- return this.fetch(`/assistants/${assistantId}/versions`, {
412
- method: "POST",
413
- json: {
414
- metadata: payload?.metadata ?? void 0,
415
- limit: payload?.limit ?? 10,
416
- offset: payload?.offset ?? 0
417
- },
418
- signal: payload?.signal
419
- });
420
- }
421
- /**
422
- * Change the version of an assistant.
423
- *
424
- * @param assistantId ID of the assistant.
425
- * @param version The version to change to.
426
- * @returns The updated assistant.
427
- */
428
- async setLatest(assistantId, version, options) {
429
- return this.fetch(`/assistants/${assistantId}/latest`, {
430
- method: "POST",
431
- json: { version },
432
- signal: options?.signal
433
- });
434
- }
435
- };
436
- var ThreadsClient = class extends BaseClient {
437
- /**
438
- * Get a thread by ID.
439
- *
440
- * @param threadId ID of the thread.
441
- * @returns The thread.
442
- */
443
- async get(threadId, options) {
444
- return this.fetch(`/threads/${threadId}`, { signal: options?.signal });
445
- }
446
- /**
447
- * Create a new thread.
448
- *
449
- * @param payload Payload for creating a thread.
450
- * @returns The created thread.
451
- */
452
- async create(payload) {
453
- const ttlPayload = typeof payload?.ttl === "number" ? {
454
- ttl: payload.ttl,
455
- strategy: "delete"
456
- } : payload?.ttl;
457
- return this.fetch(`/threads`, {
458
- method: "POST",
459
- json: {
460
- metadata: {
461
- ...payload?.metadata,
462
- graph_id: payload?.graphId
463
- },
464
- thread_id: payload?.threadId,
465
- if_exists: payload?.ifExists,
466
- supersteps: payload?.supersteps?.map((s) => ({ updates: s.updates.map((u) => ({
467
- values: u.values,
468
- command: u.command,
469
- as_node: u.asNode
470
- })) })),
471
- ttl: ttlPayload
472
- },
473
- signal: payload?.signal
474
- });
475
- }
476
- /**
477
- * Copy an existing thread
478
- * @param threadId ID of the thread to be copied
479
- * @returns Newly copied thread
480
- */
481
- async copy(threadId, options) {
482
- return this.fetch(`/threads/${threadId}/copy`, {
483
- method: "POST",
484
- signal: options?.signal
485
- });
486
- }
487
- /**
488
- * Update a thread.
489
- *
490
- * @param threadId ID of the thread.
491
- * @param payload Payload for updating the thread.
492
- * @returns The updated thread.
493
- */
494
- async update(threadId, payload) {
495
- const ttlPayload = typeof payload?.ttl === "number" ? {
496
- ttl: payload.ttl,
497
- strategy: "delete"
498
- } : payload?.ttl;
499
- return this.fetch(`/threads/${threadId}`, {
500
- method: "PATCH",
501
- json: {
502
- metadata: payload?.metadata,
503
- ttl: ttlPayload
504
- },
505
- signal: payload?.signal
506
- });
507
- }
508
- /**
509
- * Delete a thread.
510
- *
511
- * @param threadId ID of the thread.
512
- */
513
- async delete(threadId, options) {
514
- return this.fetch(`/threads/${threadId}`, {
515
- method: "DELETE",
516
- signal: options?.signal
517
- });
518
- }
519
- /**
520
- * List threads
521
- *
522
- * @param query Query options
523
- * @returns List of threads
524
- */
525
- async search(query) {
526
- return this.fetch("/threads/search", {
527
- method: "POST",
528
- json: {
529
- metadata: query?.metadata ?? void 0,
530
- ids: query?.ids ?? void 0,
531
- limit: query?.limit ?? 10,
532
- offset: query?.offset ?? 0,
533
- status: query?.status,
534
- sort_by: query?.sortBy,
535
- sort_order: query?.sortOrder,
536
- select: query?.select ?? void 0,
537
- values: query?.values ?? void 0
538
- },
539
- signal: query?.signal
540
- });
541
- }
542
- /**
543
- * Count threads matching filters.
544
- *
545
- * @param query.metadata Thread metadata to filter on.
546
- * @param query.values State values to filter on.
547
- * @param query.status Thread status to filter on.
548
- * @returns Number of threads matching the criteria.
549
- */
550
- async count(query) {
551
- return this.fetch(`/threads/count`, {
552
- method: "POST",
553
- json: {
554
- metadata: query?.metadata ?? void 0,
555
- values: query?.values ?? void 0,
556
- status: query?.status ?? void 0
557
- },
558
- signal: query?.signal
559
- });
560
- }
561
- /**
562
- * Get state for a thread.
563
- *
564
- * @param threadId ID of the thread.
565
- * @returns Thread state.
566
- */
567
- async getState(threadId, checkpoint, options) {
568
- if (checkpoint != null) {
569
- if (typeof checkpoint !== "string") return this.fetch(`/threads/${threadId}/state/checkpoint`, {
570
- method: "POST",
571
- json: {
572
- checkpoint,
573
- subgraphs: options?.subgraphs
574
- },
575
- signal: options?.signal
576
- });
577
- return this.fetch(`/threads/${threadId}/state/${checkpoint}`, {
578
- params: { subgraphs: options?.subgraphs },
579
- signal: options?.signal
580
- });
581
- }
582
- return this.fetch(`/threads/${threadId}/state`, {
583
- params: { subgraphs: options?.subgraphs },
584
- signal: options?.signal
585
- });
586
- }
587
- /**
588
- * Add state to a thread.
589
- *
590
- * @param threadId The ID of the thread.
591
- * @returns
592
- */
593
- async updateState(threadId, options) {
594
- return this.fetch(`/threads/${threadId}/state`, {
595
- method: "POST",
596
- json: {
597
- values: options.values,
598
- checkpoint_id: options.checkpointId,
599
- checkpoint: options.checkpoint,
600
- as_node: options?.asNode
601
- },
602
- signal: options?.signal
603
- });
604
- }
605
- /**
606
- * Patch the metadata of a thread.
607
- *
608
- * @param threadIdOrConfig Thread ID or config to patch the state of.
609
- * @param metadata Metadata to patch the state with.
610
- */
611
- async patchState(threadIdOrConfig, metadata, options) {
612
- let threadId;
613
- if (typeof threadIdOrConfig !== "string") {
614
- if (typeof threadIdOrConfig.configurable?.thread_id !== "string") throw new Error("Thread ID is required when updating state with a config.");
615
- threadId = threadIdOrConfig.configurable.thread_id;
616
- } else threadId = threadIdOrConfig;
617
- return this.fetch(`/threads/${threadId}/state`, {
618
- method: "PATCH",
619
- json: { metadata },
620
- signal: options?.signal
621
- });
622
- }
623
- /**
624
- * Get all past states for a thread.
625
- *
626
- * @param threadId ID of the thread.
627
- * @param options Additional options.
628
- * @returns List of thread states.
629
- */
630
- async getHistory(threadId, options) {
631
- return this.fetch(`/threads/${threadId}/history`, {
632
- method: "POST",
633
- json: {
634
- limit: options?.limit ?? 10,
635
- before: options?.before,
636
- metadata: options?.metadata,
637
- checkpoint: options?.checkpoint
638
- },
639
- signal: options?.signal
640
- });
641
- }
642
- async *joinStream(threadId, options) {
643
- let [url, init] = this.prepareFetchOptions(`/threads/${threadId}/stream`, {
644
- method: "GET",
645
- headers: options?.lastEventId ? { "Last-Event-ID": options.lastEventId } : void 0,
646
- params: options?.streamMode ? { stream_mode: options.streamMode } : void 0,
647
- signal: options?.signal
648
- });
649
- if (this.onRequest != null) init = await this.onRequest(url, init);
650
- const response = await this.asyncCaller.fetch(url, init);
651
- const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() })).pipeThrough(require_sse.BytesLineDecoder()).pipeThrough(require_sse.SSEDecoder());
652
- yield* require_stream.IterableReadableStream.fromReadableStream(stream);
653
- }
654
- };
655
- var RunsClient = class extends BaseClient {
656
- /**
657
- * Create a run and stream the results.
658
- *
659
- * @param threadId The ID of the thread.
660
- * @param assistantId Assistant ID to use for this run.
661
- * @param payload Payload for creating a run.
662
- */
663
- async *stream(threadId, assistantId, payload) {
664
- const json = {
665
- input: payload?.input,
666
- command: payload?.command,
667
- config: payload?.config,
668
- context: payload?.context,
669
- metadata: payload?.metadata,
670
- stream_mode: payload?.streamMode,
671
- stream_subgraphs: payload?.streamSubgraphs,
672
- stream_resumable: payload?.streamResumable,
673
- feedback_keys: payload?.feedbackKeys,
674
- assistant_id: assistantId,
675
- interrupt_before: payload?.interruptBefore,
676
- interrupt_after: payload?.interruptAfter,
677
- checkpoint: payload?.checkpoint,
678
- checkpoint_id: payload?.checkpointId,
679
- webhook: payload?.webhook,
680
- multitask_strategy: payload?.multitaskStrategy,
681
- on_completion: payload?.onCompletion,
682
- on_disconnect: payload?.onDisconnect,
683
- after_seconds: payload?.afterSeconds,
684
- if_not_exists: payload?.ifNotExists,
685
- checkpoint_during: payload?.checkpointDuring,
686
- durability: payload?.durability
687
- };
688
- const endpoint = threadId == null ? `/runs/stream` : `/threads/${threadId}/runs/stream`;
689
- let [url, init] = this.prepareFetchOptions(endpoint, {
690
- method: "POST",
691
- json,
692
- timeoutMs: null,
693
- signal: payload?.signal
694
- });
695
- if (this.onRequest != null) init = await this.onRequest(url, init);
696
- const response = await this.asyncCaller.fetch(url, init);
697
- const runMetadata = getRunMetadataFromResponse(response);
698
- if (runMetadata) payload?.onRunCreated?.(runMetadata);
699
- const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() })).pipeThrough(require_sse.BytesLineDecoder()).pipeThrough(require_sse.SSEDecoder());
700
- yield* require_stream.IterableReadableStream.fromReadableStream(stream);
701
- }
702
- /**
703
- * Create a run.
704
- *
705
- * @param threadId The ID of the thread.
706
- * @param assistantId Assistant ID to use for this run.
707
- * @param payload Payload for creating a run.
708
- * @returns The created run.
709
- */
710
- async create(threadId, assistantId, payload) {
711
- const json = {
712
- input: payload?.input,
713
- command: payload?.command,
714
- config: payload?.config,
715
- context: payload?.context,
716
- metadata: payload?.metadata,
717
- stream_mode: payload?.streamMode,
718
- stream_subgraphs: payload?.streamSubgraphs,
719
- stream_resumable: payload?.streamResumable,
720
- assistant_id: assistantId,
721
- interrupt_before: payload?.interruptBefore,
722
- interrupt_after: payload?.interruptAfter,
723
- webhook: payload?.webhook,
724
- checkpoint: payload?.checkpoint,
725
- checkpoint_id: payload?.checkpointId,
726
- multitask_strategy: payload?.multitaskStrategy,
727
- after_seconds: payload?.afterSeconds,
728
- if_not_exists: payload?.ifNotExists,
729
- checkpoint_during: payload?.checkpointDuring,
730
- durability: payload?.durability,
731
- langsmith_tracer: payload?._langsmithTracer ? {
732
- project_name: payload?._langsmithTracer?.projectName,
733
- example_id: payload?._langsmithTracer?.exampleId
734
- } : void 0
735
- };
736
- const endpoint = threadId === null ? "/runs" : `/threads/${threadId}/runs`;
737
- const [run, response] = await this.fetch(endpoint, {
738
- method: "POST",
739
- json,
740
- signal: payload?.signal,
741
- withResponse: true
742
- });
743
- const runMetadata = getRunMetadataFromResponse(response);
744
- if (runMetadata) payload?.onRunCreated?.(runMetadata);
745
- return run;
746
- }
747
- /**
748
- * Create a batch of stateless background runs.
749
- *
750
- * @param payloads An array of payloads for creating runs.
751
- * @returns An array of created runs.
752
- */
753
- async createBatch(payloads, options) {
754
- const filteredPayloads = payloads.map((payload) => ({
755
- ...payload,
756
- assistant_id: payload.assistantId
757
- })).map((payload) => {
758
- return Object.fromEntries(Object.entries(payload).filter(([_, v]) => v !== void 0));
759
- });
760
- return this.fetch("/runs/batch", {
761
- method: "POST",
762
- json: filteredPayloads,
763
- signal: options?.signal
764
- });
765
- }
766
- /**
767
- * Create a run and wait for it to complete.
768
- *
769
- * @param threadId The ID of the thread.
770
- * @param assistantId Assistant ID to use for this run.
771
- * @param payload Payload for creating a run.
772
- * @returns The last values chunk of the thread.
773
- */
774
- async wait(threadId, assistantId, payload) {
775
- const json = {
776
- input: payload?.input,
777
- command: payload?.command,
778
- config: payload?.config,
779
- context: payload?.context,
780
- metadata: payload?.metadata,
781
- assistant_id: assistantId,
782
- interrupt_before: payload?.interruptBefore,
783
- interrupt_after: payload?.interruptAfter,
784
- checkpoint: payload?.checkpoint,
785
- checkpoint_id: payload?.checkpointId,
786
- webhook: payload?.webhook,
787
- multitask_strategy: payload?.multitaskStrategy,
788
- on_completion: payload?.onCompletion,
789
- on_disconnect: payload?.onDisconnect,
790
- after_seconds: payload?.afterSeconds,
791
- if_not_exists: payload?.ifNotExists,
792
- checkpoint_during: payload?.checkpointDuring,
793
- durability: payload?.durability,
794
- langsmith_tracer: payload?._langsmithTracer ? {
795
- project_name: payload?._langsmithTracer?.projectName,
796
- example_id: payload?._langsmithTracer?.exampleId
797
- } : void 0
798
- };
799
- const endpoint = threadId == null ? `/runs/wait` : `/threads/${threadId}/runs/wait`;
800
- const [run, response] = await this.fetch(endpoint, {
801
- method: "POST",
802
- json,
803
- timeoutMs: null,
804
- signal: payload?.signal,
805
- withResponse: true
806
- });
807
- const runMetadata = getRunMetadataFromResponse(response);
808
- if (runMetadata) payload?.onRunCreated?.(runMetadata);
809
- const raiseError = payload?.raiseError !== void 0 ? payload.raiseError : true;
810
- if (raiseError && "__error__" in run && typeof run.__error__ === "object" && run.__error__ && "error" in run.__error__ && "message" in run.__error__) throw new Error(`${run.__error__?.error}: ${run.__error__?.message}`);
811
- return run;
812
- }
813
- /**
814
- * List all runs for a thread.
815
- *
816
- * @param threadId The ID of the thread.
817
- * @param options Filtering and pagination options.
818
- * @returns List of runs.
819
- */
820
- async list(threadId, options) {
821
- return this.fetch(`/threads/${threadId}/runs`, {
822
- params: {
823
- limit: options?.limit ?? 10,
824
- offset: options?.offset ?? 0,
825
- status: options?.status ?? void 0,
826
- select: options?.select ?? void 0
827
- },
828
- signal: options?.signal
829
- });
830
- }
831
- /**
832
- * Get a run by ID.
833
- *
834
- * @param threadId The ID of the thread.
835
- * @param runId The ID of the run.
836
- * @returns The run.
837
- */
838
- async get(threadId, runId, options) {
839
- return this.fetch(`/threads/${threadId}/runs/${runId}`, { signal: options?.signal });
840
- }
841
- /**
842
- * Cancel a run.
843
- *
844
- * @param threadId The ID of the thread.
845
- * @param runId The ID of the run.
846
- * @param wait Whether to block when canceling
847
- * @param action Action to take when cancelling the run. Possible values are `interrupt` or `rollback`. Default is `interrupt`.
848
- * @returns
849
- */
850
- async cancel(threadId, runId, wait = false, action = "interrupt", options = {}) {
851
- return this.fetch(`/threads/${threadId}/runs/${runId}/cancel`, {
852
- method: "POST",
853
- params: {
854
- wait: wait ? "1" : "0",
855
- action
856
- },
857
- signal: options?.signal
858
- });
859
- }
860
- /**
861
- * Block until a run is done.
862
- *
863
- * @param threadId The ID of the thread.
864
- * @param runId The ID of the run.
865
- * @returns
866
- */
867
- async join(threadId, runId, options) {
868
- return this.fetch(`/threads/${threadId}/runs/${runId}/join`, {
869
- timeoutMs: null,
870
- signal: options?.signal
871
- });
872
- }
873
- /**
874
- * Stream output from a run in real-time, until the run is done.
875
- *
876
- * @param threadId The ID of the thread. Can be set to `null` | `undefined` for stateless runs.
877
- * @param runId The ID of the run.
878
- * @param options Additional options for controlling the stream behavior:
879
- * - signal: An AbortSignal that can be used to cancel the stream request
880
- * - lastEventId: The ID of the last event received. Can be used to reconnect to a stream without losing events.
881
- * - cancelOnDisconnect: When true, automatically cancels the run if the client disconnects from the stream
882
- * - streamMode: Controls what types of events to receive from the stream (can be a single mode or array of modes)
883
- * Must be a subset of the stream modes passed when creating the run. Background runs default to having the union of all
884
- * stream modes enabled.
885
- * @returns An async generator yielding stream parts.
886
- */
887
- async *joinStream(threadId, runId, options) {
888
- const opts = typeof options === "object" && options != null && options instanceof AbortSignal ? { signal: options } : options;
889
- let [url, init] = this.prepareFetchOptions(threadId != null ? `/threads/${threadId}/runs/${runId}/stream` : `/runs/${runId}/stream`, {
890
- method: "GET",
891
- timeoutMs: null,
892
- signal: opts?.signal,
893
- headers: opts?.lastEventId ? { "Last-Event-ID": opts.lastEventId } : void 0,
894
- params: {
895
- cancel_on_disconnect: opts?.cancelOnDisconnect ? "1" : "0",
896
- stream_mode: opts?.streamMode
897
- }
898
- });
899
- if (this.onRequest != null) init = await this.onRequest(url, init);
900
- const response = await this.asyncCaller.fetch(url, init);
901
- const stream = (response.body || new ReadableStream({ start: (ctrl) => ctrl.close() })).pipeThrough(require_sse.BytesLineDecoder()).pipeThrough(require_sse.SSEDecoder());
902
- yield* require_stream.IterableReadableStream.fromReadableStream(stream);
903
- }
904
- /**
905
- * Delete a run.
906
- *
907
- * @param threadId The ID of the thread.
908
- * @param runId The ID of the run.
909
- * @returns
910
- */
911
- async delete(threadId, runId, options) {
912
- return this.fetch(`/threads/${threadId}/runs/${runId}`, {
913
- method: "DELETE",
914
- signal: options?.signal
915
- });
916
- }
917
- };
918
- var StoreClient = class extends BaseClient {
919
- /**
920
- * Store or update an item.
921
- *
922
- * @param namespace A list of strings representing the namespace path.
923
- * @param key The unique identifier for the item within the namespace.
924
- * @param value A dictionary containing the item's data.
925
- * @param options.index Controls search indexing - null (use defaults), false (disable), or list of field paths to index.
926
- * @param options.ttl Optional time-to-live in minutes for the item, or null for no expiration.
927
- * @returns Promise<void>
928
- *
929
- * @example
930
- * ```typescript
931
- * await client.store.putItem(
932
- * ["documents", "user123"],
933
- * "item456",
934
- * { title: "My Document", content: "Hello World" },
935
- * { ttl: 60 } // expires in 60 minutes
936
- * );
937
- * ```
938
- */
939
- async putItem(namespace, key, value, options) {
940
- namespace.forEach((label) => {
941
- if (label.includes(".")) throw new Error(`Invalid namespace label '${label}'. Namespace labels cannot contain periods ('.')`);
942
- });
943
- const payload = {
944
- namespace,
945
- key,
946
- value,
947
- index: options?.index,
948
- ttl: options?.ttl
949
- };
950
- return this.fetch("/store/items", {
951
- method: "PUT",
952
- json: payload,
953
- signal: options?.signal
954
- });
955
- }
956
- /**
957
- * Retrieve a single item.
958
- *
959
- * @param namespace A list of strings representing the namespace path.
960
- * @param key The unique identifier for the item.
961
- * @param options.refreshTtl Whether to refresh the TTL on this read operation. If null, uses the store's default behavior.
962
- * @returns Promise<Item>
963
- *
964
- * @example
965
- * ```typescript
966
- * const item = await client.store.getItem(
967
- * ["documents", "user123"],
968
- * "item456",
969
- * { refreshTtl: true }
970
- * );
971
- * console.log(item);
972
- * // {
973
- * // namespace: ["documents", "user123"],
974
- * // key: "item456",
975
- * // value: { title: "My Document", content: "Hello World" },
976
- * // createdAt: "2024-07-30T12:00:00Z",
977
- * // updatedAt: "2024-07-30T12:00:00Z"
978
- * // }
979
- * ```
980
- */
981
- async getItem(namespace, key, options) {
982
- namespace.forEach((label) => {
983
- if (label.includes(".")) throw new Error(`Invalid namespace label '${label}'. Namespace labels cannot contain periods ('.')`);
984
- });
985
- const params = {
986
- namespace: namespace.join("."),
987
- key
988
- };
989
- if (options?.refreshTtl !== void 0) params.refresh_ttl = options.refreshTtl;
990
- const response = await this.fetch("/store/items", {
991
- params,
992
- signal: options?.signal
993
- });
994
- return response ? {
995
- ...response,
996
- createdAt: response.created_at,
997
- updatedAt: response.updated_at
998
- } : null;
999
- }
1000
- /**
1001
- * Delete an item.
1002
- *
1003
- * @param namespace A list of strings representing the namespace path.
1004
- * @param key The unique identifier for the item.
1005
- * @returns Promise<void>
1006
- */
1007
- async deleteItem(namespace, key, options) {
1008
- namespace.forEach((label) => {
1009
- if (label.includes(".")) throw new Error(`Invalid namespace label '${label}'. Namespace labels cannot contain periods ('.')`);
1010
- });
1011
- return this.fetch("/store/items", {
1012
- method: "DELETE",
1013
- json: {
1014
- namespace,
1015
- key
1016
- },
1017
- signal: options?.signal
1018
- });
1019
- }
1020
- /**
1021
- * Search for items within a namespace prefix.
1022
- *
1023
- * @param namespacePrefix List of strings representing the namespace prefix.
1024
- * @param options.filter Optional dictionary of key-value pairs to filter results.
1025
- * @param options.limit Maximum number of items to return (default is 10).
1026
- * @param options.offset Number of items to skip before returning results (default is 0).
1027
- * @param options.query Optional search query.
1028
- * @param options.refreshTtl Whether to refresh the TTL on items returned by this search. If null, uses the store's default behavior.
1029
- * @returns Promise<SearchItemsResponse>
1030
- *
1031
- * @example
1032
- * ```typescript
1033
- * const results = await client.store.searchItems(
1034
- * ["documents"],
1035
- * {
1036
- * filter: { author: "John Doe" },
1037
- * limit: 5,
1038
- * refreshTtl: true
1039
- * }
1040
- * );
1041
- * console.log(results);
1042
- * // {
1043
- * // items: [
1044
- * // {
1045
- * // namespace: ["documents", "user123"],
1046
- * // key: "item789",
1047
- * // value: { title: "Another Document", author: "John Doe" },
1048
- * // createdAt: "2024-07-30T12:00:00Z",
1049
- * // updatedAt: "2024-07-30T12:00:00Z"
1050
- * // },
1051
- * // // ... additional items ...
1052
- * // ]
1053
- * // }
1054
- * ```
1055
- */
1056
- async searchItems(namespacePrefix, options) {
1057
- const payload = {
1058
- namespace_prefix: namespacePrefix,
1059
- filter: options?.filter,
1060
- limit: options?.limit ?? 10,
1061
- offset: options?.offset ?? 0,
1062
- query: options?.query,
1063
- refresh_ttl: options?.refreshTtl
1064
- };
1065
- const response = await this.fetch("/store/items/search", {
1066
- method: "POST",
1067
- json: payload,
1068
- signal: options?.signal
1069
- });
1070
- return { items: response.items.map((item) => ({
1071
- ...item,
1072
- createdAt: item.created_at,
1073
- updatedAt: item.updated_at
1074
- })) };
1075
- }
1076
- /**
1077
- * List namespaces with optional match conditions.
1078
- *
1079
- * @param options.prefix Optional list of strings representing the prefix to filter namespaces.
1080
- * @param options.suffix Optional list of strings representing the suffix to filter namespaces.
1081
- * @param options.maxDepth Optional integer specifying the maximum depth of namespaces to return.
1082
- * @param options.limit Maximum number of namespaces to return (default is 100).
1083
- * @param options.offset Number of namespaces to skip before returning results (default is 0).
1084
- * @returns Promise<ListNamespaceResponse>
1085
- */
1086
- async listNamespaces(options) {
1087
- const payload = {
1088
- prefix: options?.prefix,
1089
- suffix: options?.suffix,
1090
- max_depth: options?.maxDepth,
1091
- limit: options?.limit ?? 100,
1092
- offset: options?.offset ?? 0
1093
- };
1094
- return this.fetch("/store/namespaces", {
1095
- method: "POST",
1096
- json: payload,
1097
- signal: options?.signal
1098
- });
1099
- }
1100
- };
1101
- var UiClient = class UiClient extends BaseClient {
1102
- static promiseCache = {};
1103
- static getOrCached(key, fn) {
1104
- if (UiClient.promiseCache[key] != null) return UiClient.promiseCache[key];
1105
- const promise = fn();
1106
- UiClient.promiseCache[key] = promise;
1107
- return promise;
1108
- }
1109
- async getComponent(assistantId, agentName) {
1110
- return UiClient.getOrCached(`${this.apiUrl}-${assistantId}-${agentName}`, async () => {
1111
- let [url, init] = this.prepareFetchOptions(`/ui/${assistantId}`, {
1112
- headers: {
1113
- Accept: "text/html",
1114
- "Content-Type": "application/json"
1115
- },
1116
- method: "POST",
1117
- json: { name: agentName }
1118
- });
1119
- if (this.onRequest != null) init = await this.onRequest(url, init);
1120
- const response = await this.asyncCaller.fetch(url, init);
1121
- return response.text();
1122
- });
1123
- }
1124
- };
1125
- var Client = class {
1126
- /**
1127
- * The client for interacting with assistants.
1128
- */
1129
- assistants;
1130
- /**
1131
- * The client for interacting with threads.
1132
- */
1133
- threads;
1134
- /**
1135
- * The client for interacting with runs.
1136
- */
1137
- runs;
1138
- /**
1139
- * The client for interacting with cron runs.
1140
- */
1141
- crons;
1142
- /**
1143
- * The client for interacting with the KV store.
1144
- */
1145
- store;
1146
- /**
1147
- * The client for interacting with the UI.
1148
- * @internal Used by LoadExternalComponent and the API might change in the future.
1149
- */
1150
- "~ui";
1151
- /**
1152
- * @internal Used to obtain a stable key representing the client.
1153
- */
1154
- "~configHash";
1155
- constructor(config) {
1156
- this["~configHash"] = (() => JSON.stringify({
1157
- apiUrl: config?.apiUrl,
1158
- apiKey: config?.apiKey,
1159
- timeoutMs: config?.timeoutMs,
1160
- defaultHeaders: config?.defaultHeaders,
1161
- maxConcurrency: config?.callerOptions?.maxConcurrency,
1162
- maxRetries: config?.callerOptions?.maxRetries,
1163
- callbacks: {
1164
- onFailedResponseHook: config?.callerOptions?.onFailedResponseHook != null,
1165
- onRequest: config?.onRequest != null,
1166
- fetch: config?.callerOptions?.fetch != null
1167
- }
1168
- }))();
1169
- this.assistants = new AssistantsClient(config);
1170
- this.threads = new ThreadsClient(config);
1171
- this.runs = new RunsClient(config);
1172
- this.crons = new CronsClient(config);
1173
- this.store = new StoreClient(config);
1174
- this["~ui"] = new UiClient(config);
1175
- }
1176
- };
1177
- /**
1178
- * @internal Used to obtain a stable key representing the client.
1179
- */
1180
- function getClientConfigHash(client) {
1181
- return client["~configHash"];
1182
- }
1183
-
1184
- //#endregion
1185
- exports.AssistantsClient = AssistantsClient;
1186
- exports.Client = Client;
1187
- exports.CronsClient = CronsClient;
1188
- exports.RunsClient = RunsClient;
1189
- exports.StoreClient = StoreClient;
1190
- exports.ThreadsClient = ThreadsClient;
1191
- exports.getApiKey = getApiKey;
1192
- exports.getClientConfigHash = getClientConfigHash;
1193
- //# sourceMappingURL=client.cjs.map