@ansight/capacitor 1.3.0-preview.8 → 1.4.0-preview.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/AnsightCapacitor.podspec +1 -1
- package/Package.swift +1 -1
- package/README.md +116 -29
- package/android/build.gradle +2 -2
- package/android/src/main/kotlin/ai/ansight/capacitor/AnsightCapacitorPlugin.kt +74 -22
- package/dist/esm/definitions.d.ts +73 -10
- package/dist/esm/definitions.d.ts.map +1 -1
- package/dist/esm/dom.d.ts +11 -0
- package/dist/esm/dom.d.ts.map +1 -1
- package/dist/esm/dom.js +73 -23
- package/dist/esm/dom.js.map +1 -1
- package/dist/esm/index.d.ts +10 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +113 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/network.d.ts +6 -0
- package/dist/esm/network.d.ts.map +1 -0
- package/dist/esm/network.js +742 -0
- package/dist/esm/network.js.map +1 -0
- package/dist/esm/options.d.ts +7 -1
- package/dist/esm/options.d.ts.map +1 -1
- package/dist/esm/options.js +44 -0
- package/dist/esm/options.js.map +1 -1
- package/dist/esm/session-properties.d.ts +16 -0
- package/dist/esm/session-properties.d.ts.map +1 -0
- package/dist/esm/session-properties.js +123 -0
- package/dist/esm/session-properties.js.map +1 -0
- package/dist/esm/standalone-options.d.ts +3 -0
- package/dist/esm/standalone-options.d.ts.map +1 -0
- package/dist/esm/standalone-options.js +15 -0
- package/dist/esm/standalone-options.js.map +1 -0
- package/dist/esm/standalone.d.ts.map +1 -1
- package/dist/esm/standalone.js +2 -11
- package/dist/esm/standalone.js.map +1 -1
- package/dist/plugin.cjs.js +1096 -28
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +1096 -28
- package/dist/plugin.js.map +1 -1
- package/dist/standalone.js +1099 -31
- package/dist/standalone.js.map +1 -1
- package/ios/Sources/AnsightCapacitorPlugin/AnsightCapacitorPlugin.swift +75 -21
- package/package.json +1 -1
|
@@ -15,6 +15,7 @@ public final class AnsightCapacitorPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
15
15
|
CAPPluginMethod(name: "registerMetricChannel", returnType: CAPPluginReturnPromise),
|
|
16
16
|
CAPPluginMethod(name: "recordMetric", returnType: CAPPluginReturnPromise),
|
|
17
17
|
CAPPluginMethod(name: "recordEvent", returnType: CAPPluginReturnPromise),
|
|
18
|
+
CAPPluginMethod(name: "recordNetworkRequest", returnType: CAPPluginReturnPromise),
|
|
18
19
|
CAPPluginMethod(name: "recordCrashCandidate", returnType: CAPPluginReturnPromise),
|
|
19
20
|
CAPPluginMethod(name: "screenViewed", returnType: CAPPluginReturnPromise),
|
|
20
21
|
CAPPluginMethod(name: "setAppLifecycleState", returnType: CAPPluginReturnPromise),
|
|
@@ -82,6 +83,44 @@ public final class AnsightCapacitorPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
|
|
86
|
+
private final class CapacitorVisualTreeProvider: AnsightVisualTreeProvider, AnsightVisualTreeInteractionProvider, @unchecked Sendable {
|
|
87
|
+
let source = "dom"
|
|
88
|
+
let displayName = "Capacitor DOM"
|
|
89
|
+
private weak var plugin: AnsightCapacitorPlugin?
|
|
90
|
+
private let timeoutMilliseconds: Int
|
|
91
|
+
|
|
92
|
+
init(plugin: AnsightCapacitorPlugin, timeoutMilliseconds: Int) {
|
|
93
|
+
self.plugin = plugin
|
|
94
|
+
self.timeoutMilliseconds = timeoutMilliseconds
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
func getVisualTree(arguments: [String: String]) -> AnsightToolExecutionResult {
|
|
98
|
+
plugin?.executeJavaScriptTool(
|
|
99
|
+
toolId: "dom.get_document",
|
|
100
|
+
arguments: arguments,
|
|
101
|
+
timeoutMilliseconds: timeoutMilliseconds
|
|
102
|
+
) ?? .failure("Capacitor bridge is unavailable.", errorCode: "javascript_bridge_unavailable")
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
func inspectNode(arguments: [String: String]) -> AnsightToolExecutionResult {
|
|
106
|
+
plugin?.executeJavaScriptTool(
|
|
107
|
+
toolId: "dom.inspect_node",
|
|
108
|
+
arguments: arguments,
|
|
109
|
+
timeoutMilliseconds: timeoutMilliseconds
|
|
110
|
+
) ?? .failure("Capacitor bridge is unavailable.", errorCode: "javascript_bridge_unavailable")
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
func performAction(_ request: AnsightVisualTreeActionRequest) -> AnsightToolExecutionResult {
|
|
114
|
+
var arguments = ["nodeId": request.nodeId, "action": request.action]
|
|
115
|
+
if let value = request.value?.stringValue { arguments["value"] = value }
|
|
116
|
+
return plugin?.executeJavaScriptTool(
|
|
117
|
+
toolId: "dom.invoke_action",
|
|
118
|
+
arguments: arguments,
|
|
119
|
+
timeoutMilliseconds: timeoutMilliseconds
|
|
120
|
+
) ?? .failure("Capacitor bridge is unavailable.", errorCode: "javascript_bridge_unavailable")
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
85
124
|
private let lock = NSLock()
|
|
86
125
|
private var activeCustomToolIds: Set<String> = []
|
|
87
126
|
private var pendingToolCalls: [String: PendingToolCall] = [:]
|
|
@@ -96,13 +135,21 @@ public final class AnsightCapacitorPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
96
135
|
}
|
|
97
136
|
self?.notifyListeners("ansightLog", data: data)
|
|
98
137
|
}
|
|
138
|
+
private var hostConnectionStatusSubscription: HostConnectionStatusSubscription?
|
|
99
139
|
|
|
100
140
|
public override func load() {
|
|
101
141
|
AnsightLogger.registerCallback(logCallback)
|
|
142
|
+
hostConnectionStatusSubscription = AnsightRuntime.shared.addHostConnectionStatusListener { [weak self] status, _ in
|
|
143
|
+
self?.notifyListeners(
|
|
144
|
+
"ansightHostConnectionStatus",
|
|
145
|
+
data: self?.hostConnectionStatusDictionary(status) ?? [:]
|
|
146
|
+
)
|
|
147
|
+
}
|
|
102
148
|
}
|
|
103
149
|
|
|
104
150
|
deinit {
|
|
105
151
|
AnsightLogger.removeCallback(logCallback)
|
|
152
|
+
hostConnectionStatusSubscription?.remove()
|
|
106
153
|
}
|
|
107
154
|
|
|
108
155
|
@objc func initialize(_ call: CAPPluginCall) {
|
|
@@ -195,6 +242,25 @@ public final class AnsightCapacitorPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
195
242
|
}
|
|
196
243
|
}
|
|
197
244
|
|
|
245
|
+
@objc func recordNetworkRequest(_ call: CAPPluginCall) {
|
|
246
|
+
let input = dictionary(call)
|
|
247
|
+
guard JSONSerialization.isValidJSONObject(input),
|
|
248
|
+
let data = try? JSONSerialization.data(withJSONObject: input),
|
|
249
|
+
let request = try? JSONDecoder().decode(AnsightNetworkRequest.self, from: data),
|
|
250
|
+
request.schema == AnsightNetworkRequest.schemaName
|
|
251
|
+
else {
|
|
252
|
+
call.resolve(operationResultDictionary(
|
|
253
|
+
.failure("Network request must use the ansight.network-request.v1 schema.")
|
|
254
|
+
))
|
|
255
|
+
return
|
|
256
|
+
}
|
|
257
|
+
call.keepAlive = true
|
|
258
|
+
Task {
|
|
259
|
+
call.resolve(operationResultDictionary(await AnsightRuntime.shared.recordNetworkRequest(request)))
|
|
260
|
+
call.keepAlive = false
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
198
264
|
@objc func recordCrashCandidate(_ call: CAPPluginCall) {
|
|
199
265
|
let metadata: [String: String]
|
|
200
266
|
if let metadataJson = call.getString("metadata"),
|
|
@@ -460,6 +526,12 @@ public final class AnsightCapacitorPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
460
526
|
CapacitorTool(descriptor: descriptor, plugin: self, timeoutMilliseconds: timeout),
|
|
461
527
|
replaceExisting: true
|
|
462
528
|
)
|
|
529
|
+
if descriptor.id == "dom.get_document" {
|
|
530
|
+
try AnsightVisualTreeProviderRegistry.register(
|
|
531
|
+
CapacitorVisualTreeProvider(plugin: self, timeoutMilliseconds: timeout),
|
|
532
|
+
replaceExisting: true
|
|
533
|
+
)
|
|
534
|
+
}
|
|
463
535
|
call.resolve(["success": true, "message": "Tool registered.", "id": descriptor.id])
|
|
464
536
|
} catch {
|
|
465
537
|
call.reject(error.localizedDescription, "ansight_error", error)
|
|
@@ -772,9 +844,8 @@ public final class AnsightCapacitorPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
772
844
|
name: stringValue(dictionary, "name") ?? stringValue(dictionary, "id") ?? "",
|
|
773
845
|
description: stringValue(dictionary, "description") ?? "",
|
|
774
846
|
category: stringValue(dictionary, "category") ?? "custom",
|
|
775
|
-
|
|
847
|
+
policy: toolPolicy(stringValue(dictionary, "policy")),
|
|
776
848
|
keywords: keywords(dictionary?["keywords"]),
|
|
777
|
-
security: toolSecurity(dictionary?["security"] as? NSDictionary),
|
|
778
849
|
argumentsSchema: AnsightToolSchema(json: jsonValue(dictionary?["argumentsSchema"]) ?? .object([:])),
|
|
779
850
|
resultSchema: AnsightToolSchema(json: jsonValue(dictionary?["resultSchema"]) ?? .object([:]))
|
|
780
851
|
)
|
|
@@ -1138,31 +1209,14 @@ private func toolGuardName(_ value: AnsightToolGuard) -> String {
|
|
|
1138
1209
|
return "custom"
|
|
1139
1210
|
}
|
|
1140
1211
|
|
|
1141
|
-
private func
|
|
1212
|
+
private func toolPolicy(_ value: String?) -> AnsightToolPolicy {
|
|
1142
1213
|
switch value?.lowercased() {
|
|
1143
1214
|
case "write": return .write
|
|
1144
|
-
case "delete": return .
|
|
1215
|
+
case "critical", "delete": return .critical
|
|
1145
1216
|
default: return .read
|
|
1146
1217
|
}
|
|
1147
1218
|
}
|
|
1148
1219
|
|
|
1149
|
-
private func toolSecurity(_ dictionary: NSDictionary?) -> AnsightToolSecurity {
|
|
1150
|
-
guard let dictionary else { return .unspecified }
|
|
1151
|
-
let level: AnsightToolSecurityLevel
|
|
1152
|
-
switch stringValue(dictionary, "level")?.lowercased() {
|
|
1153
|
-
case "low": level = .low
|
|
1154
|
-
case "medium", "moderate": level = .moderate
|
|
1155
|
-
case "high": level = .high
|
|
1156
|
-
case "critical": level = .critical
|
|
1157
|
-
default: level = .unspecified
|
|
1158
|
-
}
|
|
1159
|
-
return AnsightToolSecurity(
|
|
1160
|
-
level: level,
|
|
1161
|
-
summary: stringValue(dictionary, "summary") ?? "",
|
|
1162
|
-
implications: (dictionary["implications"] as? [Any])?.compactMap { $0 as? String } ?? []
|
|
1163
|
-
)
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
1220
|
private func keywords(_ value: Any?) -> String {
|
|
1167
1221
|
if let value = value as? String { return value }
|
|
1168
1222
|
if let value = value as? [Any] { return value.compactMap { $0 as? String }.joined(separator: " ") }
|
package/package.json
CHANGED