@optimizely-opal/opal-tool-ocp-sdk 1.0.0-beta.2 → 1.0.0-beta.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.
@@ -36,6 +36,9 @@ jest.mock('@zaiusinc/app-sdk', () => ({
36
36
  warn: jest.fn(),
37
37
  debug: jest.fn(),
38
38
  },
39
+ LogVisibility: {
40
+ Zaius: 'zaius'
41
+ },
39
42
  }));
40
43
 
41
44
  // Create a concrete implementation for testing
@@ -1,6 +1,7 @@
1
1
  import { GlobalFunction, Response, amendLogContext } from '@zaiusinc/app-sdk';
2
2
  import { authenticateGlobalRequest, extractAuthData } from '../auth/AuthUtils';
3
3
  import { toolsService } from '../service/Service';
4
+ import { ToolLogger } from '../logging/ToolLogger';
4
5
 
5
6
  /**
6
7
  * Abstract base class for global tool-based function execution
@@ -24,6 +25,8 @@ export abstract class GlobalToolFunction extends GlobalFunction {
24
25
  * @returns Response as the HTTP response
25
26
  */
26
27
  public async perform(): Promise<Response> {
28
+ const startTime = Date.now();
29
+
27
30
  // Extract customer_id from auth data for global context attribution
28
31
  const authInfo = extractAuthData(this.request);
29
32
  const customerId = authInfo?.authData?.credentials?.customer_id;
@@ -33,6 +36,14 @@ export abstract class GlobalToolFunction extends GlobalFunction {
33
36
  customerId: customerId || ''
34
37
  });
35
38
 
39
+ ToolLogger.logRequest(this.request);
40
+
41
+ const response = await this.handleRequest();
42
+ ToolLogger.logResponse(this.request, response, Date.now() - startTime);
43
+ return response;
44
+ }
45
+
46
+ private async handleRequest(): Promise<Response> {
36
47
  if (!(await this.authorizeRequest())) {
37
48
  return new Response(403, { error: 'Forbidden' });
38
49
  }
@@ -36,6 +36,9 @@ jest.mock('@zaiusinc/app-sdk', () => ({
36
36
  warn: jest.fn(),
37
37
  debug: jest.fn(),
38
38
  },
39
+ LogVisibility: {
40
+ Zaius: 'zaius'
41
+ },
39
42
  }));
40
43
 
41
44
  // Create a concrete implementation for testing
@@ -1,6 +1,7 @@
1
1
  import { Function, Response, amendLogContext } from '@zaiusinc/app-sdk';
2
2
  import { authenticateRegularRequest } from '../auth/AuthUtils';
3
3
  import { toolsService } from '../service/Service';
4
+ import { ToolLogger } from '../logging/ToolLogger';
4
5
 
5
6
  /**
6
7
  * Abstract base class for tool-based function execution
@@ -19,12 +20,28 @@ export abstract class ToolFunction extends Function {
19
20
  }
20
21
 
21
22
  /**
22
- * Process the incoming request using the tools service
23
+ * Process the incoming request with logging
23
24
  *
24
25
  * @returns Response as the HTTP response
25
26
  */
26
27
  public async perform(): Promise<Response> {
28
+ const startTime = Date.now();
27
29
  amendLogContext({ opalThreadId: this.request.headers.get('x-opal-thread-id') || '' });
30
+
31
+ ToolLogger.logRequest(this.request);
32
+
33
+ const response = await this.handleRequest();
34
+
35
+ ToolLogger.logResponse(this.request, response, Date.now() - startTime);
36
+ return response;
37
+ }
38
+
39
+ /**
40
+ * Handle the core request processing logic
41
+ *
42
+ * @returns Response as the HTTP response
43
+ */
44
+ private async handleRequest(): Promise<Response> {
28
45
  if (!(await this.authorizeRequest())) {
29
46
  return new Response(403, { error: 'Forbidden' });
30
47
  }
@@ -33,6 +50,7 @@ export abstract class ToolFunction extends Function {
33
50
  const isReady = await this.ready();
34
51
  return new Response(200, { ready: isReady });
35
52
  }
53
+
36
54
  // Pass 'this' as context so decorated methods can use the existing instance
37
55
  return toolsService.processRequest(this.request, this);
38
56
  }