@optimizely-opal/opal-tools-sdk 0.1.0-dev → 0.1.2-dev

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.
Files changed (2) hide show
  1. package/README.md +87 -9
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -4,11 +4,11 @@ This SDK simplifies the creation of tools services compatible with the Opal Tool
4
4
 
5
5
  ## Features
6
6
 
7
- - Type definitions for tools and parameters
8
- - Express middleware for discovery endpoints
9
- - Decorators for tool registration
10
- - Parameter validation
7
+ - Easy definition of tool functions with decorators
8
+ - Automatic generation of discovery endpoints
9
+ - Parameter validation and type checking
11
10
  - Authentication helpers
11
+ - Express integration
12
12
 
13
13
  ## Installation
14
14
 
@@ -22,14 +22,14 @@ npm install @optimizely-opal/opal-tools-sdk
22
22
  import { ToolsService, tool } from '@optimizely-opal/opal-tools-sdk';
23
23
  import express from 'express';
24
24
 
25
+ const app = express();
26
+ const toolsService = new ToolsService(app);
27
+
25
28
  interface WeatherParameters {
26
29
  location: string;
27
- units?: string;
30
+ units: string;
28
31
  }
29
32
 
30
- const app = express();
31
- const toolsService = new ToolsService(app);
32
-
33
33
  @tool({
34
34
  name: 'get_weather',
35
35
  description: 'Gets current weather for a location'
@@ -40,7 +40,85 @@ async function getWeather(parameters: WeatherParameters) {
40
40
  }
41
41
 
42
42
  // Discovery endpoint is automatically created at /discovery
43
- app.listen(3000);
43
+ ```
44
+
45
+ ## Authentication
46
+
47
+ The SDK provides two ways to require authentication for your tools:
48
+
49
+ ### 1. Using the `@requiresAuth` decorator
50
+
51
+ ```typescript
52
+ import { ToolsService, tool } from '@optimizely-opal/opal-tools-sdk';
53
+ import { requiresAuth } from '@optimizely-opal/opal-tools-sdk/auth';
54
+ import express from 'express';
55
+
56
+ const app = express();
57
+ const toolsService = new ToolsService(app);
58
+
59
+ interface CalendarParameters {
60
+ date: string;
61
+ timezone?: string;
62
+ }
63
+
64
+ // Single authentication requirement
65
+ @requiresAuth({ provider: 'google', scopeBundle: 'calendar', required: true })
66
+ @tool({
67
+ name: 'get_calendar_events',
68
+ description: 'Gets calendar events for a date'
69
+ })
70
+ async function getCalendarEvents(parameters: CalendarParameters, authData?: any) {
71
+ // The authData parameter contains authentication information
72
+ const token = authData?.credentials?.token || '';
73
+
74
+ // Use the token to make authenticated requests
75
+ // ...
76
+
77
+ return { events: ['Meeting at 10:00', 'Lunch at 12:00'] };
78
+ }
79
+
80
+ // Multiple authentication requirements (tool can work with either provider)
81
+ @requiresAuth({ provider: 'google', scopeBundle: 'calendar', required: true })
82
+ @requiresAuth({ provider: 'microsoft', scopeBundle: 'outlook', required: true })
83
+ @tool({
84
+ name: 'get_calendar_availability',
85
+ description: 'Check calendar availability'
86
+ })
87
+ async function getCalendarAvailability(parameters: CalendarParameters, authData?: any) {
88
+ const provider = authData?.provider || '';
89
+ const token = authData?.credentials?.token || '';
90
+
91
+ if (provider === 'google') {
92
+ // Use Google Calendar API
93
+ } else if (provider === 'microsoft') {
94
+ // Use Microsoft Outlook API
95
+ }
96
+
97
+ return { available: true, provider_used: provider };
98
+ }
99
+ ```
100
+
101
+ ### 2. Specifying auth requirements in the `@tool` decorator
102
+
103
+ ```typescript
104
+ interface EmailParameters {
105
+ limit?: number;
106
+ folder?: string;
107
+ }
108
+
109
+ @tool({
110
+ name: 'get_email',
111
+ description: 'Gets emails from the user\'s inbox',
112
+ authRequirements: {
113
+ provider: 'google',
114
+ scopeBundle: 'gmail',
115
+ required: true
116
+ }
117
+ })
118
+ async function getEmail(parameters: EmailParameters, authData?: any) {
119
+ // Implementation...
120
+ return { emails: ['Email 1', 'Email 2'] };
121
+ }
44
122
  ```
45
123
 
46
124
  ## Documentation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimizely-opal/opal-tools-sdk",
3
- "version": "0.1.0-dev",
3
+ "version": "0.1.2-dev",
4
4
  "description": "SDK for creating Opal-compatible tools services",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",