openmates 0.10.0-alpha.0 → 0.10.0-alpha.2

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.
@@ -1337,7 +1337,11 @@ async function generateEmbedShareBlob(embedId, embedKeyBytes, durationSeconds =
1337
1337
  function deriveWebOrigin(apiUrl) {
1338
1338
  try {
1339
1339
  const url = new URL(apiUrl);
1340
- url.hostname = url.hostname.replace(/^api\./, "");
1340
+ if (url.hostname === "api.dev.openmates.org") {
1341
+ url.hostname = "app.dev.openmates.org";
1342
+ } else {
1343
+ url.hostname = url.hostname.replace(/^api\./, "");
1344
+ }
1341
1345
  url.port = "";
1342
1346
  return url.origin;
1343
1347
  } catch {
@@ -1689,6 +1693,8 @@ var MATE_NAMES = {
1689
1693
  };
1690
1694
  var DEFAULT_API_URL = process.env.OPENMATES_API_URL ?? "https://api.openmates.org";
1691
1695
  var SETTINGS_GET_RATE_LIMIT_RETRY_MS = 61e3;
1696
+ var SKILL_TASK_POLL_INTERVAL_MS = 2e3;
1697
+ var SKILL_TASK_POLL_TIMEOUT_MS = 3e5;
1692
1698
  function deriveAppUrl(apiUrl) {
1693
1699
  if (process.env.OPENMATES_APP_URL) {
1694
1700
  return process.env.OPENMATES_APP_URL.replace(/\/$/, "");
@@ -2468,6 +2474,81 @@ var OpenMatesClient = class _OpenMatesClient {
2468
2474
  }
2469
2475
  return response.data;
2470
2476
  }
2477
+ async resolveAsyncSkillResponse(responseData, headers) {
2478
+ const envelope = responseData;
2479
+ const data = envelope?.data ?? envelope;
2480
+ const taskId = typeof data?.task_id === "string" ? data.task_id : null;
2481
+ const taskIds = Array.isArray(data?.task_ids) ? data.task_ids.filter((id) => typeof id === "string") : [];
2482
+ if (taskId) {
2483
+ const result = await this.pollTaskUntilComplete(taskId, headers);
2484
+ return this.wrapResolvedSkillResult(responseData, result.result);
2485
+ }
2486
+ if (taskIds.length > 0) {
2487
+ const taskResults = await Promise.all(
2488
+ taskIds.map((id) => this.pollTaskUntilComplete(id, headers))
2489
+ );
2490
+ return this.wrapResolvedSkillResult(
2491
+ responseData,
2492
+ this.mergeTaskResults(taskResults.map((task) => task.result))
2493
+ );
2494
+ }
2495
+ return responseData;
2496
+ }
2497
+ async pollTaskUntilComplete(taskId, headers) {
2498
+ const started = Date.now();
2499
+ while (Date.now() - started < SKILL_TASK_POLL_TIMEOUT_MS) {
2500
+ const response = await this.http.get(
2501
+ `/v1/tasks/${encodeURIComponent(taskId)}`,
2502
+ headers
2503
+ );
2504
+ if (!response.ok) {
2505
+ throw new Error(`Task polling failed with HTTP ${response.status}`);
2506
+ }
2507
+ if (response.data.status === "completed") {
2508
+ return response.data;
2509
+ }
2510
+ if (response.data.status === "failed") {
2511
+ throw new Error(response.data.error ?? "Task failed");
2512
+ }
2513
+ await new Promise((resolve4) => setTimeout(resolve4, SKILL_TASK_POLL_INTERVAL_MS));
2514
+ }
2515
+ throw new Error(`Task ${taskId} did not complete within ${SKILL_TASK_POLL_TIMEOUT_MS / 1e3}s`);
2516
+ }
2517
+ wrapResolvedSkillResult(original, result) {
2518
+ const envelope = original;
2519
+ if (envelope && typeof envelope === "object" && "success" in envelope) {
2520
+ return { ...envelope, data: result };
2521
+ }
2522
+ return result;
2523
+ }
2524
+ mergeTaskResults(results) {
2525
+ const resultObjects = results.filter(
2526
+ (result) => result !== null && typeof result === "object"
2527
+ );
2528
+ const groupedResults = resultObjects.flatMap(
2529
+ (result) => Array.isArray(result.results) ? result.results : []
2530
+ );
2531
+ if (groupedResults.length === 0) {
2532
+ return { results };
2533
+ }
2534
+ const first = resultObjects[0] ?? {};
2535
+ return {
2536
+ ...first,
2537
+ results: groupedResults,
2538
+ items: resultObjects.flatMap(
2539
+ (result) => Array.isArray(result.items) ? result.items : []
2540
+ ),
2541
+ result_count: groupedResults.length,
2542
+ post_count: resultObjects.reduce(
2543
+ (count, result) => count + (typeof result.post_count === "number" ? result.post_count : 0),
2544
+ 0
2545
+ ),
2546
+ request_count: resultObjects.reduce(
2547
+ (count, result) => count + (typeof result.request_count === "number" ? result.request_count : 0),
2548
+ 0
2549
+ )
2550
+ };
2551
+ }
2471
2552
  async getApp(appId) {
2472
2553
  const response = await this.http.get(
2473
2554
  `/v1/apps/${encodeURIComponent(appId)}/metadata?include_unavailable=true`,
@@ -2579,7 +2660,7 @@ var OpenMatesClient = class _OpenMatesClient {
2579
2660
  err.statusCode = response.status;
2580
2661
  throw err;
2581
2662
  }
2582
- return response.data;
2663
+ return this.resolveAsyncSkillResponse(response.data, headers);
2583
2664
  }
2584
2665
  // -------------------------------------------------------------------------
2585
2666
  // Travel: booking link resolution
package/dist/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  getExtForLang,
4
4
  serializeToYaml
5
- } from "./chunk-KZRK26R5.js";
5
+ } from "./chunk-XIGU2TJJ.js";
6
6
  export {
7
7
  getExtForLang,
8
8
  serializeToYaml
package/dist/index.d.ts CHANGED
@@ -430,6 +430,10 @@ declare class OpenMatesClient {
430
430
  */
431
431
  deleteChat(chatIdInput: string): Promise<void>;
432
432
  listApps(apiKey?: string): Promise<unknown>;
433
+ private resolveAsyncSkillResponse;
434
+ private pollTaskUntilComplete;
435
+ private wrapResolvedSkillResult;
436
+ private mergeTaskResults;
433
437
  getApp(appId: string): Promise<unknown>;
434
438
  getSkillInfo(appId: string, skillId: string, apiKey?: string): Promise<unknown>;
435
439
  /** A single parameter entry from the skill schema. */
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  getExtForLang,
7
7
  parseNewChatSuggestionText,
8
8
  serializeToYaml
9
- } from "./chunk-KZRK26R5.js";
9
+ } from "./chunk-XIGU2TJJ.js";
10
10
  export {
11
11
  MATE_NAMES,
12
12
  MEMORY_TYPE_REGISTRY,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openmates",
3
- "version": "0.10.0-alpha.0",
3
+ "version": "0.10.0-alpha.2",
4
4
  "description": "OpenMates CLI and SDK",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",