capacitor-mobile-claw 1.0.10 → 1.0.11

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.
@@ -768,6 +768,37 @@ async function gitDiffTool(args) {
768
768
  const pendingPreExecuteHooks = new Map();
769
769
  const PRE_EXECUTE_TTL_MS = 120_000; // Auto-cancel after 2 minutes
770
770
 
771
+ // Map of requestId → resolver callback for skill bridge tools that wait for client result
772
+ const pendingSkillToolResults = new Map();
773
+ const SKILL_TOOL_TTL_MS = 300_000; // 5 minutes — user may need time to complete OAuth
774
+
775
+ function waitForSkillToolResult(requestId, eventType, signal) {
776
+ return new Promise((resolve) => {
777
+ const ttlTimer = setTimeout(() => {
778
+ if (pendingSkillToolResults.has(requestId)) {
779
+ pendingSkillToolResults.delete(requestId);
780
+ resolve(null);
781
+ }
782
+ }, SKILL_TOOL_TTL_MS);
783
+
784
+ pendingSkillToolResults.set(requestId, (result) => {
785
+ clearTimeout(ttlTimer);
786
+ resolve(result);
787
+ });
788
+
789
+ if (signal) {
790
+ const onAbort = () => {
791
+ clearTimeout(ttlTimer);
792
+ if (pendingSkillToolResults.has(requestId)) {
793
+ pendingSkillToolResults.delete(requestId);
794
+ resolve(null);
795
+ }
796
+ };
797
+ signal.addEventListener('abort', onAbort, { once: true });
798
+ }
799
+ });
800
+ }
801
+
771
802
  function waitForPreExecuteResult(toolCallId, toolName, signal) {
772
803
  return new Promise((resolve) => {
773
804
  const ttlTimer = setTimeout(() => {
@@ -1456,12 +1487,25 @@ function buildSkillTools(injectedTools, milestones) {
1456
1487
  return base;
1457
1488
  }
1458
1489
 
1459
- // bridgeEvent tools — emit tool input as a bridge message to the UI
1490
+ // bridgeEvent tools — emit tool input as a bridge message to the UI.
1491
+ // If waitForResult is true, the tool suspends until the client sends
1492
+ // a skill.tool_result message (same pattern as pendingPreExecuteHooks).
1460
1493
  if (toolDef.bridgeEvent) {
1461
1494
  const eventType = toolDef.bridgeEvent;
1462
- base.execute = async (_id, params) => {
1463
- channel.send('message', { type: eventType, ...params });
1464
- return toToolResult({ success: true, applied: true });
1495
+ const waitForResult = !!toolDef.waitForResult;
1496
+ base.execute = async (_id, params, signal) => {
1497
+ if (!waitForResult) {
1498
+ channel.send('message', { type: eventType, ...params });
1499
+ return toToolResult({ success: true, applied: true });
1500
+ }
1501
+ // Send bridge event then suspend until client responds
1502
+ const requestId = `${eventType}-${Date.now()}-${Math.random().toString(36).slice(2)}`;
1503
+ channel.send('message', { type: eventType, requestId, ...params });
1504
+ const result = await waitForSkillToolResult(requestId, eventType, signal);
1505
+ if (!result) {
1506
+ return toToolResult({ success: false, error: 'Request timed out or was cancelled.' });
1507
+ }
1508
+ return toToolResult(result);
1465
1509
  };
1466
1510
  return base;
1467
1511
  }
@@ -1833,6 +1877,16 @@ channel.addListener('message', async (event) => {
1833
1877
  break;
1834
1878
  }
1835
1879
 
1880
+ case 'skill.tool_result': {
1881
+ // Client resolved a waiting bridgeEvent tool (e.g. accounts_start_oauth after user taps "Connect")
1882
+ const resolver = pendingSkillToolResults.get(msg.requestId);
1883
+ if (resolver) {
1884
+ pendingSkillToolResults.delete(msg.requestId);
1885
+ resolver(msg.result);
1886
+ }
1887
+ break;
1888
+ }
1889
+
1836
1890
  case 'agent.steer': {
1837
1891
  if (currentAgent) {
1838
1892
  currentAgent.steer({ role: 'user', content: msg.text, timestamp: Date.now() });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-mobile-claw",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "description": "On-device AI agent engine for Capacitor apps — embedded Node.js worker with LLM, file tools, code execution, git, and extensible MCP server",
5
5
  "main": "dist/esm/index.js",
6
6
  "types": "dist/esm/index.d.ts",