capacitor-gleap-plugin 15.3.4 → 15.4.0

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.
@@ -17,7 +17,8 @@ CAP_PLUGIN(GleapPlugin, "Gleap",
17
17
  CAP_PLUGIN_METHOD(setTicketAttribute, CAPPluginReturnPromise);
18
18
  CAP_PLUGIN_METHOD(unsetTicketAttribute, CAPPluginReturnPromise);
19
19
  CAP_PLUGIN_METHOD(clearTicketAttributes, CAPPluginReturnPromise);
20
- CAP_PLUGIN_METHOD(setAiTools, CAPPluginReturnPromise);
20
+ CAP_PLUGIN_METHOD(registerAgentTool, CAPPluginReturnPromise);
21
+ CAP_PLUGIN_METHOD(sendAgentToolResult, CAPPluginReturnPromise);
21
22
  CAP_PLUGIN_METHOD(trackEvent, CAPPluginReturnPromise);
22
23
  CAP_PLUGIN_METHOD(trackPage, CAPPluginReturnPromise);
23
24
  CAP_PLUGIN_METHOD(sendSilentCrashReport, CAPPluginReturnPromise);
@@ -13,6 +13,7 @@ public class GleapPlugin: CAPPlugin, GleapDelegate {
13
13
  }
14
14
 
15
15
  private var callQueue: [String: CallType] = [:]
16
+ private var pendingAgentToolExecutions: [String: GleapAgentToolCompletion] = [:]
16
17
 
17
18
  @objc func initialize(_ call: CAPPluginCall) {
18
19
  // Check if key is present
@@ -266,65 +267,44 @@ public class GleapPlugin: CAPPlugin, GleapDelegate {
266
267
  ])
267
268
  }
268
269
 
269
- @objc func setAiTools(_ call: CAPPluginCall) {
270
- guard let toolsArray = call.options["tools"] as? [[String: Any]] else {
271
- call.reject("Must provide a toolsArray")
270
+ @objc func registerAgentTool(_ call: CAPPluginCall) {
271
+ guard let name = call.options["name"] as? String else {
272
+ call.reject("Must provide a name")
272
273
  return
273
274
  }
274
-
275
- var aiTools = [GleapAiTool]()
276
-
277
- for toolDict in toolsArray {
278
- guard let name = toolDict["name"] as? String,
279
- let toolDescription = toolDict["description"] as? String,
280
- let response = toolDict["response"] as? String,
281
- let executionType = toolDict["executionType"] as? String,
282
- let parametersArray = toolDict["parameters"] as? [[String: Any]] else {
283
- // If any of the required properties are missing, skip this tool
284
- continue
285
- }
286
-
287
- var parameters = [GleapAiToolParameter]()
288
-
289
- for paramDict in parametersArray {
290
- guard let paramName = paramDict["name"] as? String,
291
- let paramDescription = paramDict["description"] as? String,
292
- let type = paramDict["type"] as? String,
293
- let required = paramDict["required"] as? Bool else {
294
- // If any of the required properties are missing, skip this parameter
295
- continue
296
- }
297
-
298
- let enums = paramDict["enum"] as? [String] ?? []
299
- let parameter = GleapAiToolParameter(
300
- name: paramName,
301
- parameterDescription: paramDescription,
302
- type: type,
303
- required: required,
304
- enums: enums
305
- )
306
-
307
- parameters.append(parameter)
275
+
276
+ DispatchQueue.main.async {
277
+ // Executions round-trip to JS via the agentToolExecution event and sendAgentToolResult.
278
+ Gleap.registerAgentTool(name, handler: { (params, completion) in
279
+ let executionId = UUID().uuidString
280
+ self.pendingAgentToolExecutions[executionId] = completion
281
+
282
+ self.notifyListeners("agentToolExecution", data: [
283
+ "executionId": executionId,
284
+ "name": name,
285
+ "params": params
286
+ ])
287
+ })
288
+ }
289
+
290
+ call.resolve()
291
+ }
292
+
293
+ @objc func sendAgentToolResult(_ call: CAPPluginCall) {
294
+ guard let executionId = call.options["executionId"] as? String else {
295
+ call.reject("Must provide an executionId")
296
+ return
297
+ }
298
+ let result = call.options["result"] as? String ?? ""
299
+
300
+ DispatchQueue.main.async {
301
+ if let completion = self.pendingAgentToolExecutions[executionId] {
302
+ self.pendingAgentToolExecutions.removeValue(forKey: executionId)
303
+ completion(result)
308
304
  }
309
-
310
- let aiTool = GleapAiTool(
311
- name: name,
312
- toolDescription: toolDescription,
313
- response: response,
314
- executionType: executionType,
315
- parameters: parameters
316
- )
317
-
318
- aiTools.append(aiTool)
319
305
  }
320
-
321
- // Set AI tools using your specific method to interact with the Gleap SDK
322
- Gleap.setAiTools(aiTools)
323
-
324
- // Provide feedback that the AI tools have been successfully set
325
- call.resolve([
326
- "aiToolsSet": true
327
- ])
306
+
307
+ call.resolve()
328
308
  }
329
309
 
330
310
  @objc func setTicketAttribute(_ call: CAPPluginCall) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-gleap-plugin",
3
- "version": "15.3.4",
3
+ "version": "15.4.0",
4
4
  "description": "Gleap SDK for Capacitor is the easiest way to integrate Gleap into your Ionic apps! Achieve better app quality with comprehensive in-app bug reporting & customer feedback for your web-apps and websites. Many thanks to Stephan Nagel (congrapp) for his work on the Gleap capacitor plugin.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -76,6 +76,6 @@
76
76
  }
77
77
  },
78
78
  "dependencies": {
79
- "gleap": "16.1.1"
79
+ "gleap": "16.2.4"
80
80
  }
81
81
  }