@distri/core 0.2.8 → 0.3.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.mjs CHANGED
@@ -681,6 +681,17 @@ function convertA2AStatusUpdateToDistri(statusUpdate) {
681
681
  };
682
682
  return hookRequested;
683
683
  }
684
+ case "browser_session_started": {
685
+ const browserSessionStarted = {
686
+ type: "browser_session_started",
687
+ data: {
688
+ session_id: metadata.session_id || "",
689
+ viewer_url: metadata.viewer_url,
690
+ stream_url: metadata.stream_url
691
+ }
692
+ };
693
+ return browserSessionStarted;
694
+ }
684
695
  default: {
685
696
  console.warn(`Unhandled status update metadata type: ${metadata.type}`, metadata);
686
697
  const defaultResult = {
@@ -1263,6 +1274,31 @@ var _DistriClient = class _DistriClient {
1263
1274
  throw new DistriError(`Failed to fetch agent ${agentId}`, "FETCH_ERROR", error);
1264
1275
  }
1265
1276
  }
1277
+ /**
1278
+ * Update an agent's definition (markdown only)
1279
+ */
1280
+ async updateAgent(agentId, update) {
1281
+ try {
1282
+ const response = await this.fetch(`/agents/${agentId}`, {
1283
+ method: "PUT",
1284
+ headers: {
1285
+ "Content-Type": "application/json",
1286
+ ...this.config.headers
1287
+ },
1288
+ body: JSON.stringify(update)
1289
+ });
1290
+ if (!response.ok) {
1291
+ if (response.status === 404) {
1292
+ throw new ApiError(`Agent not found: ${agentId}`, 404);
1293
+ }
1294
+ throw new ApiError(`Failed to update agent: ${response.statusText}`, response.status);
1295
+ }
1296
+ return await response.json();
1297
+ } catch (error) {
1298
+ if (error instanceof ApiError) throw error;
1299
+ throw new DistriError(`Failed to update agent ${agentId}`, "UPDATE_ERROR", error);
1300
+ }
1301
+ }
1266
1302
  /**
1267
1303
  * Get or create A2AClient for an agent
1268
1304
  */
@@ -1348,11 +1384,22 @@ var _DistriClient = class _DistriClient {
1348
1384
  }
1349
1385
  }
1350
1386
  /**
1351
- * Get threads from Distri server
1387
+ * Get threads from Distri server with filtering and pagination
1352
1388
  */
1353
- async getThreads() {
1389
+ async getThreads(params = {}) {
1354
1390
  try {
1355
- const response = await this.fetch(`/threads`);
1391
+ const searchParams = new URLSearchParams();
1392
+ if (params.agent_id) searchParams.set("agent_id", params.agent_id);
1393
+ if (params.external_id) searchParams.set("external_id", params.external_id);
1394
+ if (params.search) searchParams.set("search", params.search);
1395
+ if (params.from_date) searchParams.set("from_date", params.from_date);
1396
+ if (params.to_date) searchParams.set("to_date", params.to_date);
1397
+ if (params.tags?.length) searchParams.set("tags", params.tags.join(","));
1398
+ if (params.limit !== void 0) searchParams.set("limit", params.limit.toString());
1399
+ if (params.offset !== void 0) searchParams.set("offset", params.offset.toString());
1400
+ const queryString = searchParams.toString();
1401
+ const url = queryString ? `/threads?${queryString}` : "/threads";
1402
+ const response = await this.fetch(url);
1356
1403
  if (!response.ok) {
1357
1404
  throw new ApiError(`Failed to fetch threads: ${response.statusText}`, response.status);
1358
1405
  }
@@ -1362,6 +1409,39 @@ var _DistriClient = class _DistriClient {
1362
1409
  throw new DistriError("Failed to fetch threads", "FETCH_ERROR", error);
1363
1410
  }
1364
1411
  }
1412
+ /**
1413
+ * Get agents sorted by thread count (most active first)
1414
+ */
1415
+ async getAgentsByUsage() {
1416
+ try {
1417
+ const response = await this.fetch("/threads/agents");
1418
+ if (!response.ok) {
1419
+ throw new ApiError(`Failed to fetch agents by usage: ${response.statusText}`, response.status);
1420
+ }
1421
+ return await response.json();
1422
+ } catch (error) {
1423
+ if (error instanceof ApiError) throw error;
1424
+ throw new DistriError("Failed to fetch agents by usage", "FETCH_ERROR", error);
1425
+ }
1426
+ }
1427
+ /**
1428
+ * Create a new browser session
1429
+ * Returns session info including viewer_url and stream_url from browsr
1430
+ */
1431
+ async createBrowserSession() {
1432
+ try {
1433
+ const response = await this.fetch("/browser/session", {
1434
+ method: "POST"
1435
+ });
1436
+ if (!response.ok) {
1437
+ throw new ApiError(`Failed to create browser session: ${response.statusText}`, response.status);
1438
+ }
1439
+ return await response.json();
1440
+ } catch (error) {
1441
+ if (error instanceof ApiError) throw error;
1442
+ throw new DistriError("Failed to create browser session", "FETCH_ERROR", error);
1443
+ }
1444
+ }
1365
1445
  async getThread(threadId) {
1366
1446
  try {
1367
1447
  const response = await this.fetch(`/threads/${threadId}`);
@@ -1816,7 +1896,7 @@ var Agent = class _Agent {
1816
1896
  const enhancedParams = this.enhanceParamsWithTools(params, tools);
1817
1897
  const a2aStream = this.client.sendMessageStream(this.agentDefinition.id, enhancedParams);
1818
1898
  const self = this;
1819
- return async function* () {
1899
+ return (async function* () {
1820
1900
  for await (const event of a2aStream) {
1821
1901
  const converted = decodeA2AStreamEvent(event);
1822
1902
  if (converted && converted.type === "inline_hook_requested") {
@@ -1837,7 +1917,7 @@ var Agent = class _Agent {
1837
1917
  yield converted;
1838
1918
  }
1839
1919
  }
1840
- }();
1920
+ })();
1841
1921
  }
1842
1922
  /**
1843
1923
  * Validate that required external tools are registered before invoking.