openmates 0.10.0-alpha.1 → 0.10.0-alpha.3
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/{chunk-ZJKUUM2P.js → chunk-R4HKMYBT.js} +79 -2
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -1693,6 +1693,8 @@ var MATE_NAMES = {
|
|
|
1693
1693
|
};
|
|
1694
1694
|
var DEFAULT_API_URL = process.env.OPENMATES_API_URL ?? "https://api.openmates.org";
|
|
1695
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;
|
|
1696
1698
|
function deriveAppUrl(apiUrl) {
|
|
1697
1699
|
if (process.env.OPENMATES_APP_URL) {
|
|
1698
1700
|
return process.env.OPENMATES_APP_URL.replace(/\/$/, "");
|
|
@@ -2472,6 +2474,81 @@ var OpenMatesClient = class _OpenMatesClient {
|
|
|
2472
2474
|
}
|
|
2473
2475
|
return response.data;
|
|
2474
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
|
+
}
|
|
2475
2552
|
async getApp(appId) {
|
|
2476
2553
|
const response = await this.http.get(
|
|
2477
2554
|
`/v1/apps/${encodeURIComponent(appId)}/metadata?include_unavailable=true`,
|
|
@@ -2583,7 +2660,7 @@ var OpenMatesClient = class _OpenMatesClient {
|
|
|
2583
2660
|
err.statusCode = response.status;
|
|
2584
2661
|
throw err;
|
|
2585
2662
|
}
|
|
2586
|
-
return response.data;
|
|
2663
|
+
return this.resolveAsyncSkillResponse(response.data, headers);
|
|
2587
2664
|
}
|
|
2588
2665
|
// -------------------------------------------------------------------------
|
|
2589
2666
|
// Travel: booking link resolution
|
|
@@ -8046,6 +8123,7 @@ async function sendMessageStreaming(client, params, redactor) {
|
|
|
8046
8123
|
try {
|
|
8047
8124
|
const mentionCtx = await client.buildMentionContext();
|
|
8048
8125
|
const parsed = parseMentions(params.message, mentionCtx);
|
|
8126
|
+
finalMessage = parsed.processedMessage;
|
|
8049
8127
|
if (parsed.unresolved.length > 0) {
|
|
8050
8128
|
clearTyping();
|
|
8051
8129
|
for (const u of parsed.unresolved) {
|
|
@@ -8182,7 +8260,6 @@ async function sendMessageStreaming(client, params, redactor) {
|
|
|
8182
8260
|
);
|
|
8183
8261
|
}
|
|
8184
8262
|
}
|
|
8185
|
-
finalMessage = parsed.processedMessage;
|
|
8186
8263
|
} catch {
|
|
8187
8264
|
}
|
|
8188
8265
|
}
|
package/dist/cli.js
CHANGED
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