@blario/react-native 0.0.0 → 0.1.1
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/LICENSE +21 -0
- package/README.md +401 -0
- package/dist/BlarProvider.d.ts +74 -0
- package/dist/actions/batched.d.ts +1 -0
- package/dist/actions/click.d.ts +4 -0
- package/dist/actions/commit-watch.d.ts +15 -0
- package/dist/actions/events.d.ts +35 -0
- package/dist/actions/executor.d.ts +29 -0
- package/dist/actions/highlight.d.ts +4 -0
- package/dist/actions/interaction-guards.d.ts +9 -0
- package/dist/actions/landing.d.ts +11 -0
- package/dist/actions/navigation-driver.d.ts +22 -0
- package/dist/actions/parse.d.ts +4 -0
- package/dist/actions/result.d.ts +4 -0
- package/dist/actions/scrolling.d.ts +12 -0
- package/dist/actions/services.d.ts +20 -0
- package/dist/actions/settle.d.ts +13 -0
- package/dist/actions/switch.d.ts +3 -0
- package/dist/actions/target.d.ts +25 -0
- package/dist/actions/text-input.d.ts +9 -0
- package/dist/actions/types.d.ts +59 -0
- package/dist/agent/batch-commands.d.ts +17 -0
- package/dist/agent/compose.d.ts +23 -0
- package/dist/agent/controller.d.ts +28 -0
- package/dist/agent/frame-runner.d.ts +9 -0
- package/dist/agent/frames.d.ts +180 -0
- package/dist/agent/handlers/agent-command.d.ts +5 -0
- package/dist/agent/handlers/batch.d.ts +5 -0
- package/dist/agent/handlers/consent-screenshot.d.ts +4 -0
- package/dist/agent/handlers/context.d.ts +16 -0
- package/dist/agent/handlers/dom-state.d.ts +4 -0
- package/dist/agent/handlers/element-context.d.ts +2 -0
- package/dist/agent/handlers/screenshot.d.ts +3 -0
- package/dist/agent/handlers/text-dom.d.ts +5 -0
- package/dist/agent/stage.d.ts +13 -0
- package/dist/agent-mode/action-description.d.ts +3 -0
- package/dist/agent-mode/bubbles.d.ts +10 -0
- package/dist/agent-mode/colors.d.ts +12 -0
- package/dist/agent-mode/controller.d.ts +92 -0
- package/dist/agent-mode/cursor-follow.d.ts +12 -0
- package/dist/agent-mode/cursor.d.ts +37 -0
- package/dist/agent-mode/frames.d.ts +36 -0
- package/dist/agent-mode/haptics.d.ts +6 -0
- package/dist/agent-mode/keep-awake.d.ts +19 -0
- package/dist/agent-mode/layer-stacking.d.ts +7 -0
- package/dist/agent-mode/markdown.d.ts +19 -0
- package/dist/agent-mode/panel-geometry.d.ts +6 -0
- package/dist/agent-mode/resume.d.ts +13 -0
- package/dist/agent-mode/run-memory.d.ts +19 -0
- package/dist/agent-mode/spotlight-controller.d.ts +68 -0
- package/dist/agent-mode/spotlight.d.ts +6 -0
- package/dist/agent-mode/state.d.ts +9 -0
- package/dist/agent-mode/status.d.ts +11 -0
- package/dist/agent-mode/timers.d.ts +6 -0
- package/dist/agent-mode/ui/AgentDock.d.ts +37 -0
- package/dist/agent-mode/ui/AgentLayer.d.ts +19 -0
- package/dist/agent-mode/ui/AgentLayerHost.d.ts +8 -0
- package/dist/agent-mode/ui/AgentPanel.d.ts +19 -0
- package/dist/agent-mode/ui/AgentTap.d.ts +10 -0
- package/dist/agent-mode/ui/MarkdownText.d.ts +8 -0
- package/dist/agent-mode/ui/MessageBubbles.d.ts +9 -0
- package/dist/agent-mode/ui/PendingOverlay.d.ts +5 -0
- package/dist/agent-mode/ui/SpotlightLayer.d.ts +9 -0
- package/dist/agent-mode/ui/SpotlightOverlay.d.ts +7 -0
- package/dist/agent-mode/ui/StatusCard.d.ts +14 -0
- package/dist/agent-mode/ui/TargetPulse.d.ts +9 -0
- package/dist/agent-mode/ui/TouchShield.d.ts +5 -0
- package/dist/agent-mode/ui/WarningIcon.d.ts +6 -0
- package/dist/agent-mode/ui/full-window-overlay.d.ts +5 -0
- package/dist/agent-mode/ui/layer-host.d.ts +2 -0
- package/dist/backend/api-client.d.ts +38 -0
- package/dist/backend/api-types.d.ts +25 -0
- package/dist/backend/app-info.d.ts +14 -0
- package/dist/backend/backend-transport.d.ts +70 -0
- package/dist/backend/backoff.d.ts +9 -0
- package/dist/backend/base64.d.ts +1 -0
- package/dist/backend/errors.d.ts +17 -0
- package/dist/backend/foreground.d.ts +1 -0
- package/dist/backend/health.d.ts +17 -0
- package/dist/backend/identity-proof.d.ts +23 -0
- package/dist/backend/identity.d.ts +27 -0
- package/dist/backend/message-metadata.d.ts +19 -0
- package/dist/backend/presence.d.ts +20 -0
- package/dist/backend/response-cache.d.ts +9 -0
- package/dist/backend/session-change.d.ts +2 -0
- package/dist/backend/session-socket.d.ts +49 -0
- package/dist/backend/session.d.ts +39 -0
- package/dist/backend/socket-url.d.ts +9 -0
- package/dist/backend/storage.d.ts +13 -0
- package/dist/backend/tab-id.d.ts +2 -0
- package/dist/blar.d.ts +37 -0
- package/dist/chat/ChatLayer.d.ts +29 -0
- package/dist/chat/ChatSheet.d.ts +11 -0
- package/dist/chat/ChatView.d.ts +19 -0
- package/dist/chat/Launcher.d.ts +14 -0
- package/dist/chat/bridge.d.ts +22 -0
- package/dist/chat/chat-coordinator.d.ts +57 -0
- package/dist/chat/chat-state.d.ts +20 -0
- package/dist/chat/navigation.d.ts +5 -0
- package/dist/chat/options.d.ts +22 -0
- package/dist/chat/webview.d.ts +10 -0
- package/dist/chat/widget-bundle.generated.d.ts +2 -0
- package/dist/chat/widget-shell.d.ts +24 -0
- package/dist/confirmation/port.d.ts +12 -0
- package/dist/fiber/locate.d.ts +7 -0
- package/dist/fiber/narrow.d.ts +5 -0
- package/dist/fiber/reader.d.ts +10 -0
- package/dist/fiber/text.d.ts +4 -0
- package/dist/fiber/types.d.ts +21 -0
- package/dist/host/border-radius.d.ts +1 -0
- package/dist/host/instance.d.ts +9 -0
- package/dist/host/measure.d.ts +3 -0
- package/dist/host/rect.d.ts +22 -0
- package/dist/host/visible-area.d.ts +2 -0
- package/dist/index.d.ts +10 -0
- package/dist/nudge/NudgeBubble.d.ts +15 -0
- package/dist/nudge/nudge.d.ts +23 -0
- package/dist/optional/expo-haptics.d.ts +1 -0
- package/dist/optional/expo-keep-awake.d.ts +1 -0
- package/dist/optional/react-native-haptic-feedback.d.ts +1 -0
- package/dist/optional/react-native-keep-awake.d.ts +1 -0
- package/dist/overlay/AgentOverlay.d.ts +5 -0
- package/dist/screenshot/capture-backend.d.ts +6 -0
- package/dist/screenshot/screenshotter.d.ts +18 -0
- package/dist/screenshot/skia.d.ts +35 -0
- package/dist/screenshot/view-shot.d.ts +2 -0
- package/dist/snapshot/capture.d.ts +36 -0
- package/dist/snapshot/classify.d.ts +11 -0
- package/dist/snapshot/collect.d.ts +27 -0
- package/dist/snapshot/element-context.d.ts +9 -0
- package/dist/snapshot/icon.d.ts +2 -0
- package/dist/snapshot/kinds.d.ts +3 -0
- package/dist/snapshot/modals.d.ts +2 -0
- package/dist/snapshot/navigation.d.ts +14 -0
- package/dist/snapshot/ordering.d.ts +2 -0
- package/dist/snapshot/properties.d.ts +14 -0
- package/dist/snapshot/registry.d.ts +16 -0
- package/dist/snapshot/render.d.ts +10 -0
- package/dist/snapshot/route-summary.d.ts +3 -0
- package/dist/snapshot/scroll.d.ts +15 -0
- package/dist/snapshot/text-layout.d.ts +8 -0
- package/dist/snapshot/view.d.ts +30 -0
- package/dist/snapshot/visibility.d.ts +17 -0
- package/dist/snapshot/wrappers.d.ts +11 -0
- package/dist/telemetry/SdkErrorBoundary.d.ts +15 -0
- package/dist/telemetry/build-info.generated.d.ts +2 -0
- package/dist/telemetry/envelope.d.ts +53 -0
- package/dist/telemetry/reporter.d.ts +33 -0
- package/dist/telemetry/scrub.d.ts +1 -0
- package/dist/telemetry/sdk-reporter.d.ts +5 -0
- package/dist/transport/connection-options.d.ts +18 -0
- package/dist/transport/relay-transport.d.ts +17 -0
- package/dist/transport/transport.d.ts +7 -0
- package/dist/ui/insets.d.ts +8 -0
- package/dist/ui/strings.d.ts +33 -0
- package/dist/ui/useInsets.d.ts +2 -0
- package/dist/version.d.ts +1 -0
- package/package.json +87 -3
- package/src/BlarProvider.tsx +462 -0
- package/src/actions/batched.ts +16 -0
- package/src/actions/click.ts +54 -0
- package/src/actions/commit-watch.ts +86 -0
- package/src/actions/events.ts +58 -0
- package/src/actions/executor.ts +147 -0
- package/src/actions/highlight.ts +13 -0
- package/src/actions/interaction-guards.ts +44 -0
- package/src/actions/landing.ts +26 -0
- package/src/actions/navigation-driver.ts +131 -0
- package/src/actions/parse.ts +82 -0
- package/src/actions/result.ts +14 -0
- package/src/actions/scrolling.ts +112 -0
- package/src/actions/services.ts +24 -0
- package/src/actions/settle.ts +40 -0
- package/src/actions/switch.ts +31 -0
- package/src/actions/target.ts +77 -0
- package/src/actions/text-input.ts +82 -0
- package/src/actions/types.ts +52 -0
- package/src/agent/batch-commands.ts +33 -0
- package/src/agent/compose.ts +67 -0
- package/src/agent/controller.ts +106 -0
- package/src/agent/frame-runner.ts +27 -0
- package/src/agent/frames.ts +193 -0
- package/src/agent/handlers/agent-command.ts +74 -0
- package/src/agent/handlers/batch.ts +72 -0
- package/src/agent/handlers/consent-screenshot.ts +44 -0
- package/src/agent/handlers/context.ts +17 -0
- package/src/agent/handlers/dom-state.ts +19 -0
- package/src/agent/handlers/element-context.ts +9 -0
- package/src/agent/handlers/screenshot.ts +24 -0
- package/src/agent/handlers/text-dom.ts +17 -0
- package/src/agent/stage.ts +22 -0
- package/src/agent-mode/action-description.ts +25 -0
- package/src/agent-mode/bubbles.ts +31 -0
- package/src/agent-mode/colors.ts +40 -0
- package/src/agent-mode/controller.ts +459 -0
- package/src/agent-mode/cursor-follow.ts +43 -0
- package/src/agent-mode/cursor.ts +118 -0
- package/src/agent-mode/frames.ts +70 -0
- package/src/agent-mode/haptics.ts +49 -0
- package/src/agent-mode/keep-awake.ts +107 -0
- package/src/agent-mode/layer-stacking.ts +16 -0
- package/src/agent-mode/markdown.ts +84 -0
- package/src/agent-mode/panel-geometry.ts +27 -0
- package/src/agent-mode/resume.ts +16 -0
- package/src/agent-mode/run-memory.ts +65 -0
- package/src/agent-mode/spotlight-controller.ts +255 -0
- package/src/agent-mode/spotlight.ts +14 -0
- package/src/agent-mode/state.ts +36 -0
- package/src/agent-mode/status.ts +13 -0
- package/src/agent-mode/timers.ts +11 -0
- package/src/agent-mode/ui/AgentDock.tsx +285 -0
- package/src/agent-mode/ui/AgentLayer.tsx +123 -0
- package/src/agent-mode/ui/AgentLayerHost.tsx +37 -0
- package/src/agent-mode/ui/AgentPanel.tsx +187 -0
- package/src/agent-mode/ui/AgentTap.tsx +190 -0
- package/src/agent-mode/ui/MarkdownText.tsx +55 -0
- package/src/agent-mode/ui/MessageBubbles.tsx +58 -0
- package/src/agent-mode/ui/PendingOverlay.tsx +32 -0
- package/src/agent-mode/ui/SpotlightLayer.tsx +60 -0
- package/src/agent-mode/ui/SpotlightOverlay.tsx +35 -0
- package/src/agent-mode/ui/StatusCard.tsx +137 -0
- package/src/agent-mode/ui/TargetPulse.tsx +74 -0
- package/src/agent-mode/ui/TouchShield.tsx +22 -0
- package/src/agent-mode/ui/WarningIcon.tsx +32 -0
- package/src/agent-mode/ui/full-window-overlay.ts +16 -0
- package/src/agent-mode/ui/layer-host.ts +11 -0
- package/src/backend/api-client.ts +210 -0
- package/src/backend/api-types.ts +56 -0
- package/src/backend/app-info.ts +40 -0
- package/src/backend/backend-transport.ts +338 -0
- package/src/backend/backoff.ts +16 -0
- package/src/backend/base64.ts +25 -0
- package/src/backend/errors.ts +32 -0
- package/src/backend/foreground.ts +10 -0
- package/src/backend/health.ts +64 -0
- package/src/backend/identity-proof.ts +151 -0
- package/src/backend/identity.ts +31 -0
- package/src/backend/message-metadata.ts +28 -0
- package/src/backend/presence.ts +95 -0
- package/src/backend/response-cache.ts +45 -0
- package/src/backend/session-change.ts +14 -0
- package/src/backend/session-socket.ts +292 -0
- package/src/backend/session.ts +188 -0
- package/src/backend/socket-url.ts +25 -0
- package/src/backend/storage.ts +49 -0
- package/src/backend/tab-id.ts +24 -0
- package/src/blar.ts +100 -0
- package/src/chat/ChatLayer.tsx +109 -0
- package/src/chat/ChatSheet.tsx +84 -0
- package/src/chat/ChatView.tsx +133 -0
- package/src/chat/Launcher.tsx +72 -0
- package/src/chat/bridge.ts +56 -0
- package/src/chat/chat-coordinator.ts +189 -0
- package/src/chat/chat-state.ts +35 -0
- package/src/chat/navigation.ts +15 -0
- package/src/chat/options.ts +39 -0
- package/src/chat/webview.ts +23 -0
- package/src/chat/widget-bundle.generated.ts +2 -0
- package/src/chat/widget-shell.ts +170 -0
- package/src/confirmation/port.ts +15 -0
- package/src/fiber/locate.ts +41 -0
- package/src/fiber/narrow.ts +15 -0
- package/src/fiber/reader.ts +98 -0
- package/src/fiber/text.ts +52 -0
- package/src/fiber/types.ts +24 -0
- package/src/host/border-radius.ts +11 -0
- package/src/host/instance.ts +30 -0
- package/src/host/measure.ts +25 -0
- package/src/host/rect.ts +45 -0
- package/src/host/visible-area.ts +5 -0
- package/src/index.ts +10 -0
- package/src/nudge/NudgeBubble.tsx +117 -0
- package/src/nudge/nudge.ts +100 -0
- package/src/optional/expo-haptics.ts +11 -0
- package/src/optional/expo-keep-awake.ts +11 -0
- package/src/optional/react-native-haptic-feedback.ts +11 -0
- package/src/optional/react-native-keep-awake.ts +11 -0
- package/src/overlay/AgentOverlay.tsx +16 -0
- package/src/screenshot/capture-backend.ts +7 -0
- package/src/screenshot/screenshotter.ts +39 -0
- package/src/screenshot/skia.ts +107 -0
- package/src/screenshot/view-shot.ts +41 -0
- package/src/snapshot/capture.ts +163 -0
- package/src/snapshot/classify.ts +40 -0
- package/src/snapshot/collect.ts +136 -0
- package/src/snapshot/element-context.ts +66 -0
- package/src/snapshot/icon.ts +21 -0
- package/src/snapshot/kinds.ts +10 -0
- package/src/snapshot/modals.ts +21 -0
- package/src/snapshot/navigation.ts +47 -0
- package/src/snapshot/ordering.ts +26 -0
- package/src/snapshot/properties.ts +71 -0
- package/src/snapshot/registry.ts +33 -0
- package/src/snapshot/render.ts +140 -0
- package/src/snapshot/route-summary.ts +15 -0
- package/src/snapshot/scroll.ts +90 -0
- package/src/snapshot/text-layout.ts +59 -0
- package/src/snapshot/view.ts +87 -0
- package/src/snapshot/visibility.ts +63 -0
- package/src/snapshot/wrappers.ts +69 -0
- package/src/telemetry/SdkErrorBoundary.tsx +28 -0
- package/src/telemetry/build-info.generated.ts +2 -0
- package/src/telemetry/envelope.ts +83 -0
- package/src/telemetry/reporter.ts +170 -0
- package/src/telemetry/scrub.ts +10 -0
- package/src/telemetry/sdk-reporter.ts +37 -0
- package/src/transport/connection-options.ts +65 -0
- package/src/transport/relay-transport.ts +82 -0
- package/src/transport/transport.ts +8 -0
- package/src/ui/insets.ts +31 -0
- package/src/ui/strings.ts +102 -0
- package/src/ui/useInsets.ts +10 -0
- package/src/version.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,90 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blario/react-native",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"license": "MIT"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Blar agent SDK for React Native",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/blarApp/support-web-component.git",
|
|
9
|
+
"directory": "react-native-sdk"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"main": "src/index.ts",
|
|
15
|
+
"types": "dist/index.d.ts",
|
|
16
|
+
"react-native": "src/index.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"src",
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc -p tsconfig.build.json",
|
|
23
|
+
"prepack": "npm run build",
|
|
24
|
+
"version": "node scripts/sync-version.ts",
|
|
25
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p test/tsconfig.json && tsc --noEmit -p relay/tsconfig.json && tsc --noEmit -p harness/tsconfig.json && tsc --noEmit -p scripts/tsconfig.json",
|
|
26
|
+
"test": "node --test --experimental-transform-types test/*.test.ts",
|
|
27
|
+
"relay": "node relay/server.ts",
|
|
28
|
+
"harness": "node harness/run.ts",
|
|
29
|
+
"embed-widget": "node scripts/embed-widget.ts",
|
|
30
|
+
"telemetry-config": "node scripts/telemetry-config.ts",
|
|
31
|
+
"proxy": "node harness/frame-proxy.ts",
|
|
32
|
+
"inject": "node harness/inject.ts"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"@react-native-async-storage/async-storage": ">=1.0.0",
|
|
36
|
+
"@shopify/react-native-skia": ">=0.1.0",
|
|
37
|
+
"expo-haptics": ">=12.0.0",
|
|
38
|
+
"expo-keep-awake": ">=12.0.0",
|
|
39
|
+
"react": ">=18.2.0",
|
|
40
|
+
"react-native": ">=0.74.0",
|
|
41
|
+
"react-native-haptic-feedback": ">=1.0.0",
|
|
42
|
+
"react-native-keep-awake": ">=4.0.0",
|
|
43
|
+
"react-native-safe-area-context": ">=4.0.0",
|
|
44
|
+
"react-native-screens": ">=3.29.0",
|
|
45
|
+
"react-native-view-shot": ">=3.8.0",
|
|
46
|
+
"react-native-webview": ">=13.0.0"
|
|
47
|
+
},
|
|
48
|
+
"peerDependenciesMeta": {
|
|
49
|
+
"@react-native-async-storage/async-storage": {
|
|
50
|
+
"optional": true
|
|
51
|
+
},
|
|
52
|
+
"@shopify/react-native-skia": {
|
|
53
|
+
"optional": true
|
|
54
|
+
},
|
|
55
|
+
"expo-haptics": {
|
|
56
|
+
"optional": true
|
|
57
|
+
},
|
|
58
|
+
"expo-keep-awake": {
|
|
59
|
+
"optional": true
|
|
60
|
+
},
|
|
61
|
+
"react-native-haptic-feedback": {
|
|
62
|
+
"optional": true
|
|
63
|
+
},
|
|
64
|
+
"react-native-keep-awake": {
|
|
65
|
+
"optional": true
|
|
66
|
+
},
|
|
67
|
+
"react-native-safe-area-context": {
|
|
68
|
+
"optional": true
|
|
69
|
+
},
|
|
70
|
+
"react-native-screens": {
|
|
71
|
+
"optional": true
|
|
72
|
+
},
|
|
73
|
+
"react-native-view-shot": {
|
|
74
|
+
"optional": true
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"devDependencies": {
|
|
78
|
+
"@types/node": "^22.0.0",
|
|
79
|
+
"@types/react": "~18.2.45",
|
|
80
|
+
"@types/ws": "^8.5.12",
|
|
81
|
+
"react": "18.2.0",
|
|
82
|
+
"react-native": "0.74.5",
|
|
83
|
+
"react-native-webview": "^13.8.6",
|
|
84
|
+
"typescript": "^5.3.3",
|
|
85
|
+
"ws": "^8.18.0"
|
|
86
|
+
},
|
|
87
|
+
"overrides": {
|
|
88
|
+
"fast-xml-parser": "^5.7.0"
|
|
89
|
+
}
|
|
6
90
|
}
|
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
import React, { Component, createRef, type ReactNode } from 'react';
|
|
2
|
+
import { AccessibilityInfo, AppState, Dimensions, Keyboard, StyleSheet, View } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { createAgentController } from './agent/compose.ts';
|
|
5
|
+
import { SYSTEM_CLOCK } from './actions/settle.ts';
|
|
6
|
+
import { AgentModeController, type AgentModeSnapshot } from './agent-mode/controller.ts';
|
|
7
|
+
import { CursorController, type CursorSnapshot } from './agent-mode/cursor.ts';
|
|
8
|
+
import { HAPTICS_ADAPTER, warnByHaptics } from './agent-mode/haptics.ts';
|
|
9
|
+
import { SpotlightController, type SpotlightSnapshot } from './agent-mode/spotlight-controller.ts';
|
|
10
|
+
import { SYSTEM_TIMERS } from './agent-mode/timers.ts';
|
|
11
|
+
import { readAgentModeEvent } from './agent-mode/frames.ts';
|
|
12
|
+
import type { AgentModePhase } from './agent-mode/state.ts';
|
|
13
|
+
import { KEEP_AWAKE_ADAPTER, KeepAwake } from './agent-mode/keep-awake.ts';
|
|
14
|
+
import { LayerStacking } from './agent-mode/layer-stacking.ts';
|
|
15
|
+
import { AgentLayer } from './agent-mode/ui/AgentLayer.tsx';
|
|
16
|
+
import { AgentLayerHost } from './agent-mode/ui/AgentLayerHost.tsx';
|
|
17
|
+
import { BackendTransport, type WidgetProof } from './backend/backend-transport.ts';
|
|
18
|
+
import type { BlarIdentity } from './backend/identity.ts';
|
|
19
|
+
import type { MessageMetadata } from './backend/message-metadata.ts';
|
|
20
|
+
import { Blar, type ChatControls } from './blar.ts';
|
|
21
|
+
import type { AgentController } from './agent/controller.ts';
|
|
22
|
+
import type { NavigationRefLike } from './actions/navigation-driver.ts';
|
|
23
|
+
import { ChatCoordinator, type ChatBackend, type ChatSnapshot } from './chat/chat-coordinator.ts';
|
|
24
|
+
import { ChatLayer } from './chat/ChatLayer.tsx';
|
|
25
|
+
import { type ChatOptions, resolveChatOptions, type ResolvedChatOptions } from './chat/options.ts';
|
|
26
|
+
import { currentRootFiber } from './fiber/locate.ts';
|
|
27
|
+
import type { Fiber } from './fiber/types.ts';
|
|
28
|
+
import { visibleViewport } from './host/visible-area.ts';
|
|
29
|
+
import { AgentOverlay } from './overlay/AgentOverlay.tsx';
|
|
30
|
+
import { CAPTURE_BACKEND } from './screenshot/screenshotter.ts';
|
|
31
|
+
import { countOpenModals } from './snapshot/modals.ts';
|
|
32
|
+
import { SdkErrorBoundary } from './telemetry/SdkErrorBoundary.tsx';
|
|
33
|
+
import { resolveConnectionOptions, type ConnectionConfig } from './transport/connection-options.ts';
|
|
34
|
+
import { RelayTransport } from './transport/relay-transport.ts';
|
|
35
|
+
import type { AgentTransport } from './transport/transport.ts';
|
|
36
|
+
import { type Language, resolveLanguage, resolveStrings, type UiStringOverrides, type UiStrings } from './ui/strings.ts';
|
|
37
|
+
|
|
38
|
+
export interface BlarProviderProps {
|
|
39
|
+
children: ReactNode;
|
|
40
|
+
publishableKey?: string;
|
|
41
|
+
apiBaseUrl?: string;
|
|
42
|
+
user?: BlarIdentity | null;
|
|
43
|
+
relayUrl?: string;
|
|
44
|
+
navigationRef?: NavigationRefLike | null;
|
|
45
|
+
language?: Language;
|
|
46
|
+
strings?: UiStringOverrides;
|
|
47
|
+
chat?: ChatOptions;
|
|
48
|
+
enabled?: boolean;
|
|
49
|
+
debug?: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface BlarProviderState {
|
|
53
|
+
spotlight: SpotlightSnapshot;
|
|
54
|
+
chat: ChatSnapshot | null;
|
|
55
|
+
agentMode: AgentModeSnapshot | null;
|
|
56
|
+
cursor: CursorSnapshot;
|
|
57
|
+
reduceMotion: boolean;
|
|
58
|
+
layerGeneration: number;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface WithReactInternals {
|
|
62
|
+
_reactInternals?: Fiber;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export class BlarProvider extends Component<BlarProviderProps, BlarProviderState> {
|
|
66
|
+
private connection: ConnectionConfig = { kind: 'disabled' };
|
|
67
|
+
|
|
68
|
+
private readonly cursor = new CursorController({
|
|
69
|
+
clock: SYSTEM_CLOCK,
|
|
70
|
+
isForeground: () => AppState.currentState === 'active',
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
private readonly spotlight = new SpotlightController({
|
|
74
|
+
timers: SYSTEM_TIMERS,
|
|
75
|
+
isForeground: () => AppState.currentState === 'active',
|
|
76
|
+
stopRun: () => this.agentMode?.stop(),
|
|
77
|
+
alert: () => warnByHaptics(HAPTICS_ADAPTER),
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
override state: BlarProviderState = {
|
|
81
|
+
spotlight: this.spotlight.getSnapshot(),
|
|
82
|
+
chat: null,
|
|
83
|
+
agentMode: null,
|
|
84
|
+
cursor: this.cursor.getSnapshot(),
|
|
85
|
+
reduceMotion: false,
|
|
86
|
+
layerGeneration: 0,
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
private readonly contentRef = createRef<View>();
|
|
90
|
+
|
|
91
|
+
private controller: AgentController | null = null;
|
|
92
|
+
|
|
93
|
+
private agentMode: AgentModeController | null = null;
|
|
94
|
+
|
|
95
|
+
private transport: AgentTransport | null = null;
|
|
96
|
+
|
|
97
|
+
private backend: BackendTransport | null = null;
|
|
98
|
+
|
|
99
|
+
private coordinator: ChatCoordinator | null = null;
|
|
100
|
+
|
|
101
|
+
private chatControls: ChatControls | null = null;
|
|
102
|
+
|
|
103
|
+
private shownNudge: number | null = null;
|
|
104
|
+
|
|
105
|
+
private readonly releases: Array<() => void> = [];
|
|
106
|
+
|
|
107
|
+
private stackingCheckQueued = false;
|
|
108
|
+
|
|
109
|
+
private loggedPhase: AgentModePhase = 'idle';
|
|
110
|
+
|
|
111
|
+
private readonly stacking = new LayerStacking(() => this.countHostModals());
|
|
112
|
+
|
|
113
|
+
private readonly attachCursor = (): void => this.cursor.attach();
|
|
114
|
+
|
|
115
|
+
private readonly detachCursor = (): void => this.cursor.detach();
|
|
116
|
+
|
|
117
|
+
override componentDidMount(): void {
|
|
118
|
+
if (this.props.enabled !== false) {
|
|
119
|
+
this.startSdk();
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
override componentDidUpdate(previous: BlarProviderProps): void {
|
|
124
|
+
const enabled = this.props.enabled !== false;
|
|
125
|
+
if (enabled !== (previous.enabled !== false)) {
|
|
126
|
+
if (enabled) {
|
|
127
|
+
this.startSdk();
|
|
128
|
+
} else {
|
|
129
|
+
this.stopSdk();
|
|
130
|
+
this.setState({ chat: null, agentMode: null, spotlight: this.spotlight.getSnapshot(), cursor: this.cursor.getSnapshot() });
|
|
131
|
+
}
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (this.backend === null || previous.user?.externalId === this.props.user?.externalId) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (this.props.user === undefined || this.props.user === null) {
|
|
138
|
+
void Blar.logout();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
void Blar.setUser(this.props.user);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
override componentWillUnmount(): void {
|
|
145
|
+
this.stopSdk();
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private startSdk(): void {
|
|
149
|
+
this.connection = resolveConnectionOptions(this.props, typeof __DEV__ !== 'undefined' && __DEV__);
|
|
150
|
+
const transport = this.createTransport();
|
|
151
|
+
if (transport === null) {
|
|
152
|
+
this.debug('SDK disabled: provide a valid publishableKey and apiBaseUrl, or an explicit relayUrl');
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
this.watchMotionPreference();
|
|
156
|
+
this.releases.push(this.cursor.subscribe((cursor) => this.setState({ cursor })));
|
|
157
|
+
this.releases.push(this.spotlight.subscribe((spotlight) => this.setState({ spotlight })));
|
|
158
|
+
this.watchForeground();
|
|
159
|
+
const agentMode = this.createAgentMode();
|
|
160
|
+
this.transport = transport;
|
|
161
|
+
this.createChat();
|
|
162
|
+
this.controller = createAgentController({
|
|
163
|
+
transport,
|
|
164
|
+
getAnchorFiber: () => (this as WithReactInternals)._reactInternals ?? null,
|
|
165
|
+
getViewport: () => visibleViewport(Dimensions.get('window'), Keyboard.metrics()?.height ?? 0),
|
|
166
|
+
getNavigationRef: () => this.props.navigationRef ?? null,
|
|
167
|
+
getCaptureTarget: () => this.contentRef.current,
|
|
168
|
+
reading: this.spotlight,
|
|
169
|
+
cursor: this.cursor,
|
|
170
|
+
confirmation: this.spotlight,
|
|
171
|
+
stage: agentMode,
|
|
172
|
+
onCommit: () => this.queueStackingCheck(),
|
|
173
|
+
onSettled: () => this.keepLayerOnTop(),
|
|
174
|
+
});
|
|
175
|
+
this.controller.start();
|
|
176
|
+
this.debug(`screenshots ${CAPTURE_BACKEND?.name ?? 'unavailable'}, haptics ${HAPTICS_ADAPTER?.name ?? 'unavailable'}`);
|
|
177
|
+
this.attachBackend();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private stopSdk(): void {
|
|
181
|
+
if (this.backend !== null) {
|
|
182
|
+
Blar.detach(this.backend);
|
|
183
|
+
this.backend = null;
|
|
184
|
+
}
|
|
185
|
+
if (this.chatControls !== null) {
|
|
186
|
+
Blar.detachChat(this.chatControls);
|
|
187
|
+
this.chatControls = null;
|
|
188
|
+
}
|
|
189
|
+
this.releases.splice(0).forEach((release) => release());
|
|
190
|
+
this.coordinator = null;
|
|
191
|
+
this.controller?.stop();
|
|
192
|
+
this.controller = null;
|
|
193
|
+
this.agentMode?.dispose();
|
|
194
|
+
this.agentMode = null;
|
|
195
|
+
this.transport = null;
|
|
196
|
+
this.spotlight.clear();
|
|
197
|
+
this.loggedPhase = 'idle';
|
|
198
|
+
this.shownNudge = null;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
override render(): React.JSX.Element {
|
|
202
|
+
const strings = resolveStrings(this.props.language ?? 'es', this.props.strings);
|
|
203
|
+
const phase = this.state.agentMode?.phase ?? 'idle';
|
|
204
|
+
return (
|
|
205
|
+
<View style={styles.root} collapsable={false} onTouchStart={() => this.backend?.noteInteraction()}>
|
|
206
|
+
<View ref={this.contentRef} style={styles.root} collapsable={false}>
|
|
207
|
+
{this.props.children}
|
|
208
|
+
</View>
|
|
209
|
+
<SdkErrorBoundary context="BlarProvider.overlay">
|
|
210
|
+
<AgentOverlay>
|
|
211
|
+
{this.renderChat(strings)}
|
|
212
|
+
<AgentLayerHost visible={phase !== 'idle'} generation={this.state.layerGeneration} onRequestClose={() => this.agentMode?.stop()}>
|
|
213
|
+
{this.renderAgentLayer(strings)}
|
|
214
|
+
</AgentLayerHost>
|
|
215
|
+
</AgentOverlay>
|
|
216
|
+
</SdkErrorBoundary>
|
|
217
|
+
</View>
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
private renderAgentLayer(strings: UiStrings): React.JSX.Element | null {
|
|
222
|
+
const { agentMode } = this.state;
|
|
223
|
+
if (agentMode === null || agentMode.phase === 'idle') {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
return (
|
|
227
|
+
<AgentLayer
|
|
228
|
+
snapshot={agentMode}
|
|
229
|
+
strings={strings}
|
|
230
|
+
color={this.chatOptions().primaryColor}
|
|
231
|
+
spotlight={this.state.spotlight}
|
|
232
|
+
spotlightActions={this.spotlight}
|
|
233
|
+
cursor={this.state.cursor}
|
|
234
|
+
reduceMotion={this.state.reduceMotion}
|
|
235
|
+
onCursorAttach={this.attachCursor}
|
|
236
|
+
onCursorDetach={this.detachCursor}
|
|
237
|
+
onStop={() => this.agentMode?.stop()}
|
|
238
|
+
/>
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
private renderChat(strings: UiStrings): React.JSX.Element | null {
|
|
243
|
+
const { chat } = this.state;
|
|
244
|
+
const backend = this.backend;
|
|
245
|
+
const coordinator = this.coordinator;
|
|
246
|
+
const connection = this.connection;
|
|
247
|
+
if (chat === null || backend === null || coordinator === null || connection.kind !== 'backend') {
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
return (
|
|
251
|
+
<ChatLayer
|
|
252
|
+
snapshot={chat}
|
|
253
|
+
options={this.chatOptions()}
|
|
254
|
+
strings={strings}
|
|
255
|
+
language={resolveLanguage(this.props.language)}
|
|
256
|
+
publishableKey={connection.publishableKey}
|
|
257
|
+
apiBaseUrl={connection.apiBaseUrl}
|
|
258
|
+
tabId={backend.getTabId()}
|
|
259
|
+
identity={backend.getIdentity()}
|
|
260
|
+
getMetadata={(options) => this.readChatMetadata(options)}
|
|
261
|
+
getProof={() => this.readChatProof()}
|
|
262
|
+
onOpen={() => coordinator.open()}
|
|
263
|
+
onClose={() => coordinator.close()}
|
|
264
|
+
onSessionChanged={(sessionId) => this.followWidgetSession(sessionId)}
|
|
265
|
+
onAcceptNudge={() => void coordinator.acceptNudge()}
|
|
266
|
+
onDeclineNudge={() => coordinator.declineNudge()}
|
|
267
|
+
onSnoozeNudge={() => coordinator.snoozeNudge()}
|
|
268
|
+
log={this.props.debug === true ? (message) => console.log(`[blar] ${message}`) : undefined}
|
|
269
|
+
/>
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
private chatOptions(): ResolvedChatOptions {
|
|
274
|
+
return resolveChatOptions(this.props.chat);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
private watchForeground(): void {
|
|
278
|
+
const subscription = AppState.addEventListener('change', (state) => {
|
|
279
|
+
if (state !== 'active') {
|
|
280
|
+
this.spotlight.backgrounded();
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
this.releases.push(() => subscription.remove());
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
private watchMotionPreference(): void {
|
|
287
|
+
void AccessibilityInfo.isReduceMotionEnabled().then((reduceMotion) => this.setState({ reduceMotion }));
|
|
288
|
+
const subscription = AccessibilityInfo.addEventListener('reduceMotionChanged', (reduceMotion) => this.setState({ reduceMotion }));
|
|
289
|
+
this.releases.push(() => subscription.remove());
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
private createAgentMode(): AgentModeController {
|
|
293
|
+
const agentMode = new AgentModeController(
|
|
294
|
+
{
|
|
295
|
+
sendCancel: (reason) => this.transport?.send({ type: 'agent_cancel', reason }),
|
|
296
|
+
onActive: () => {
|
|
297
|
+
this.cursor.beginSession();
|
|
298
|
+
this.stacking.baseline();
|
|
299
|
+
this.coordinator?.agentEngaged();
|
|
300
|
+
},
|
|
301
|
+
onIdle: () => {
|
|
302
|
+
this.cursor.endSession();
|
|
303
|
+
this.spotlight.clear();
|
|
304
|
+
this.coordinator?.agentReleased();
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
new KeepAwake(KEEP_AWAKE_ADAPTER, (message) => this.debug(message)),
|
|
308
|
+
this.backend?.getRunMemory(),
|
|
309
|
+
);
|
|
310
|
+
this.agentMode = agentMode;
|
|
311
|
+
this.setState({ agentMode: agentMode.getSnapshot() });
|
|
312
|
+
this.releases.push(
|
|
313
|
+
agentMode.subscribe((snapshot) => {
|
|
314
|
+
if (snapshot.phase !== this.loggedPhase) {
|
|
315
|
+
this.loggedPhase = snapshot.phase;
|
|
316
|
+
this.debug(`agent mode ${snapshot.phase}`);
|
|
317
|
+
}
|
|
318
|
+
this.setState({ agentMode: snapshot });
|
|
319
|
+
}),
|
|
320
|
+
);
|
|
321
|
+
return agentMode;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
private createTransport(): AgentTransport | null {
|
|
325
|
+
const connection = this.connection;
|
|
326
|
+
if (connection.kind === 'disabled') {
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
if (connection.kind === 'relay') {
|
|
330
|
+
return new RelayTransport(connection.relayUrl);
|
|
331
|
+
}
|
|
332
|
+
const backend = new BackendTransport({
|
|
333
|
+
publishableKey: connection.publishableKey,
|
|
334
|
+
apiBaseUrl: connection.apiBaseUrl,
|
|
335
|
+
user: this.props.user ?? Blar.consumePendingUser(),
|
|
336
|
+
log: this.props.debug === true ? (message) => console.log(`[blar] ${message}`) : undefined,
|
|
337
|
+
onSocketState: (state) => {
|
|
338
|
+
if (state === 'failed') {
|
|
339
|
+
this.agentMode?.socketFailed();
|
|
340
|
+
}
|
|
341
|
+
},
|
|
342
|
+
onConnecting: (sessionId) => this.debug(`agent resume ${this.agentMode?.connecting(sessionId) ?? 'none'} session=${sessionId}`),
|
|
343
|
+
onSessionChanged: () => this.agentMode?.endClosedRun(),
|
|
344
|
+
});
|
|
345
|
+
this.backend = backend;
|
|
346
|
+
this.releases.push(
|
|
347
|
+
backend.onFrame((frame) => {
|
|
348
|
+
const event = readAgentModeEvent(frame);
|
|
349
|
+
if (event !== null) {
|
|
350
|
+
this.agentMode?.handleEvent(event);
|
|
351
|
+
}
|
|
352
|
+
}),
|
|
353
|
+
);
|
|
354
|
+
return backend;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
private createChat(): void {
|
|
358
|
+
const backend = this.backend;
|
|
359
|
+
if (backend === null || !this.chatOptions().enabled) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
const adapter: ChatBackend = {
|
|
363
|
+
getSessionId: () => backend.getState().sessionId,
|
|
364
|
+
openNudge: () => backend.openNudge(),
|
|
365
|
+
dismissNudge: (milestoneMessageId) => backend.dismissNudge(milestoneMessageId),
|
|
366
|
+
snoozeNudge: (milestoneMessageId) => backend.snoozeNudge(milestoneMessageId),
|
|
367
|
+
switchSession: (sessionId) => backend.switchSession(sessionId),
|
|
368
|
+
};
|
|
369
|
+
const coordinator = new ChatCoordinator(adapter, { onSessionReplaced: () => this.agentMode?.endClosedRun() });
|
|
370
|
+
this.coordinator = coordinator;
|
|
371
|
+
this.setState({ chat: coordinator.getSnapshot() });
|
|
372
|
+
this.releases.push(
|
|
373
|
+
coordinator.subscribe((chat) => {
|
|
374
|
+
this.noteNudge(chat);
|
|
375
|
+
this.setState({ chat });
|
|
376
|
+
}),
|
|
377
|
+
);
|
|
378
|
+
this.releases.push(backend.onFrame((frame) => coordinator.handleFrame(frame)));
|
|
379
|
+
this.releases.push(backend.onIdentityChange(() => coordinator.reset()));
|
|
380
|
+
this.chatControls = {
|
|
381
|
+
open: () => coordinator.open(),
|
|
382
|
+
close: () => coordinator.close(),
|
|
383
|
+
getUnread: () => coordinator.getSnapshot().chat.unread,
|
|
384
|
+
isOpen: () => coordinator.getSnapshot().chat.mode === 'open',
|
|
385
|
+
};
|
|
386
|
+
Blar.attachChat(this.chatControls);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
private attachBackend(): void {
|
|
390
|
+
const backend = this.backend;
|
|
391
|
+
const controller = this.controller;
|
|
392
|
+
if (backend === null || controller === null) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
Blar.attach(backend, (options) => controller.readMessageMetadata({ ...options, tabId: backend.getTabId() }));
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
private queueStackingCheck(): void {
|
|
399
|
+
if (this.stackingCheckQueued || (this.agentMode?.getSnapshot().phase ?? 'idle') === 'idle') {
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
this.stackingCheckQueued = true;
|
|
403
|
+
requestAnimationFrame(() => {
|
|
404
|
+
this.stackingCheckQueued = false;
|
|
405
|
+
this.keepLayerOnTop();
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
private keepLayerOnTop(): void {
|
|
410
|
+
if ((this.agentMode?.getSnapshot().phase ?? 'idle') === 'idle' || !this.stacking.coveredByNewModal()) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
this.debug('host modal opened above the agent layer, remounting it');
|
|
414
|
+
this.setState(({ layerGeneration }) => ({ layerGeneration: layerGeneration + 1 }));
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
private countHostModals(): number {
|
|
418
|
+
const anchor = (this as WithReactInternals)._reactInternals ?? null;
|
|
419
|
+
const root = anchor === null ? null : currentRootFiber(anchor);
|
|
420
|
+
return root === null ? 0 : countOpenModals(root);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
private noteNudge(chat: ChatSnapshot): void {
|
|
424
|
+
const milestone = chat.nudge?.milestoneMessageId ?? null;
|
|
425
|
+
if (milestone !== this.shownNudge) {
|
|
426
|
+
this.shownNudge = milestone;
|
|
427
|
+
this.debug(milestone === null ? 'nudge hidden' : `nudge shown milestone=${milestone}`);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
private debug(message: string): void {
|
|
432
|
+
if (this.props.debug === true) {
|
|
433
|
+
console.log(`[blar] ${message}`);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
private followWidgetSession(sessionId: number | null): void {
|
|
438
|
+
const backend = this.backend;
|
|
439
|
+
if (backend === null || backend.getState().sessionId === sessionId) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
if (sessionId === null) {
|
|
443
|
+
this.agentMode?.endClosedRun();
|
|
444
|
+
backend.leaveSession();
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
void backend.switchSession(sessionId);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
private readChatMetadata(options: { includeTextDom: boolean }): Promise<MessageMetadata | null> {
|
|
451
|
+
return Blar.getMessageMetadata(options);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
private async readChatProof(): Promise<WidgetProof | null> {
|
|
455
|
+
return this.backend?.readWidgetProof() ?? null;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
const styles = StyleSheet.create({
|
|
461
|
+
root: { flex: 1 },
|
|
462
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as ReactNative from 'react-native';
|
|
2
|
+
|
|
3
|
+
import { isFunction } from '../fiber/narrow.ts';
|
|
4
|
+
|
|
5
|
+
interface BatchingApi {
|
|
6
|
+
unstable_batchedUpdates?: unknown;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function runBatched(callback: () => void): void {
|
|
10
|
+
const batch = (ReactNative as unknown as BatchingApi).unstable_batchedUpdates;
|
|
11
|
+
if (isFunction(batch)) {
|
|
12
|
+
batch(callback);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
callback();
|
|
16
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { isFunction } from '../fiber/narrow.ts';
|
|
2
|
+
import { hostInstanceOf } from '../host/instance.ts';
|
|
3
|
+
import { measureHost } from '../host/measure.ts';
|
|
4
|
+
import { runBatched } from './batched.ts';
|
|
5
|
+
import { buildPressEvent } from './events.ts';
|
|
6
|
+
import { checkInteractable } from './interaction-guards.ts';
|
|
7
|
+
import { failed, failedFromException, succeeded } from './result.ts';
|
|
8
|
+
import type { ActionServices } from './services.ts';
|
|
9
|
+
import type { ResolvedTarget } from './target.ts';
|
|
10
|
+
import type { HandlerResult } from './types.ts';
|
|
11
|
+
import { toggleSwitch } from './switch.ts';
|
|
12
|
+
|
|
13
|
+
async function pressButton(target: ResolvedTarget): Promise<HandlerResult> {
|
|
14
|
+
const onPress = target.props.onPress;
|
|
15
|
+
if (!isFunction(onPress)) {
|
|
16
|
+
return failed('element_not_interactable', 'the element no longer has an onPress handler');
|
|
17
|
+
}
|
|
18
|
+
const rect = (target.host === null ? null : await measureHost(target.host)) ?? target.element.rect;
|
|
19
|
+
try {
|
|
20
|
+
runBatched(() => onPress(buildPressEvent(rect)));
|
|
21
|
+
return succeeded();
|
|
22
|
+
} catch (error) {
|
|
23
|
+
return failedFromException(error);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function focusInput(target: ResolvedTarget, services: ActionServices): HandlerResult {
|
|
28
|
+
const instance = target.host === null ? null : hostInstanceOf(target.host);
|
|
29
|
+
try {
|
|
30
|
+
instance?.focus?.();
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return failedFromException(error);
|
|
33
|
+
}
|
|
34
|
+
services.inputMemory.last = target.element;
|
|
35
|
+
return succeeded('focused the input');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function click(target: ResolvedTarget, services: ActionServices): Promise<HandlerResult> {
|
|
39
|
+
if (target.element.kind === 'scroll') {
|
|
40
|
+
return failed('element_not_interactable', 'scroll containers cannot be clicked; use scroll or scroll_to');
|
|
41
|
+
}
|
|
42
|
+
const verdict = checkInteractable(target.fiber, target.ancestors);
|
|
43
|
+
if (!verdict.allowed) {
|
|
44
|
+
return failed('element_not_interactable', verdict.reason);
|
|
45
|
+
}
|
|
46
|
+
switch (target.element.kind) {
|
|
47
|
+
case 'switch':
|
|
48
|
+
return toggleSwitch(target, null);
|
|
49
|
+
case 'text_input':
|
|
50
|
+
return focusInput(target, services);
|
|
51
|
+
default:
|
|
52
|
+
return pressButton(target);
|
|
53
|
+
}
|
|
54
|
+
}
|