@optimizely-opal/opal-tools-sdk 0.1.5-dev → 0.1.8-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.
package/src/models.ts CHANGED
@@ -2,44 +2,39 @@
2
2
  * Types of parameters supported by Opal tools
3
3
  */
4
4
  export enum ParameterType {
5
- String = 'string',
6
- Integer = 'integer',
7
- Number = 'number',
8
- Boolean = 'boolean',
9
- List = 'array',
10
- Dictionary = 'object'
5
+ Boolean = "boolean",
6
+ Dictionary = "object",
7
+ Integer = "integer",
8
+ List = "array",
9
+ Number = "number",
10
+ String = "string",
11
11
  }
12
12
 
13
13
  /**
14
- * Parameter definition for an Opal tool
14
+ * Authentication data for an Opal tool
15
15
  */
16
- export class Parameter {
17
- /**
18
- * Create a new parameter definition
19
- * @param name Parameter name
20
- * @param type Parameter type
21
- * @param description Parameter description
22
- * @param required Whether the parameter is required
23
- */
24
- constructor(
25
- public name: string,
26
- public type: ParameterType,
27
- public description: string,
28
- public required: boolean
29
- ) {}
16
+ export type AuthData = {
17
+ credentials: Credentials;
18
+ provider: string;
19
+ };
30
20
 
31
- /**
32
- * Convert to JSON for the discovery endpoint
33
- */
34
- toJSON() {
35
- return {
36
- name: this.name,
37
- type: this.type,
38
- description: this.description,
39
- required: this.required
40
- };
41
- }
42
- }
21
+ /**
22
+ * Authentication credentials structure
23
+ */
24
+ export type Credentials = {
25
+ access_token: string;
26
+ customer_id: string;
27
+ instance_id: string;
28
+ org_sso_id?: string;
29
+ product_sku: string;
30
+ };
31
+
32
+ /**
33
+ * Execution environment for an Opal tool
34
+ */
35
+ export type Environment = {
36
+ execution_mode: "headless" | "interactive";
37
+ };
43
38
 
44
39
  /**
45
40
  * Authentication requirements for an Opal tool
@@ -54,7 +49,7 @@ export class AuthRequirement {
54
49
  constructor(
55
50
  public provider: string,
56
51
  public scopeBundle: string,
57
- public required: boolean = true
52
+ public required: boolean = true,
58
53
  ) {}
59
54
 
60
55
  /**
@@ -63,8 +58,8 @@ export class AuthRequirement {
63
58
  toJSON() {
64
59
  return {
65
60
  provider: this.provider,
61
+ required: this.required,
66
62
  scope_bundle: this.scopeBundle,
67
- required: this.required
68
63
  };
69
64
  }
70
65
  }
@@ -76,7 +71,7 @@ export class Function {
76
71
  /**
77
72
  * HTTP method for the endpoint (default: POST)
78
73
  */
79
- public httpMethod: string = 'POST';
74
+ public httpMethod: string = "POST";
80
75
 
81
76
  /**
82
77
  * Create a new function definition
@@ -85,29 +80,38 @@ export class Function {
85
80
  * @param parameters Function parameters
86
81
  * @param endpoint API endpoint
87
82
  * @param authRequirements Authentication requirements (optional)
83
+ * @param uiResource URI of associated UI resource for dynamic rendering (optional)
88
84
  */
89
85
  constructor(
90
86
  public name: string,
91
87
  public description: string,
92
88
  public parameters: Parameter[],
93
89
  public endpoint: string,
94
- public authRequirements?: AuthRequirement[]
90
+ public authRequirements?: AuthRequirement[],
91
+ public uiResource?: string,
95
92
  ) {}
96
93
 
97
94
  /**
98
95
  * Convert to JSON for the discovery endpoint
99
96
  */
100
97
  toJSON() {
98
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
101
99
  const result: any = {
102
- name: this.name,
103
100
  description: this.description,
104
- parameters: this.parameters.map(p => p.toJSON()),
105
101
  endpoint: this.endpoint,
106
- http_method: this.httpMethod
102
+ http_method: this.httpMethod,
103
+ name: this.name,
104
+ parameters: this.parameters.map((p) => p.toJSON()),
107
105
  };
108
106
 
109
107
  if (this.authRequirements && this.authRequirements.length > 0) {
110
- result.auth_requirements = this.authRequirements.map(auth => auth.toJSON());
108
+ result.auth_requirements = this.authRequirements.map((auth) =>
109
+ auth.toJSON(),
110
+ );
111
+ }
112
+
113
+ if (this.uiResource !== undefined) {
114
+ result.ui_resource = this.uiResource;
111
115
  }
112
116
 
113
117
  return result;
@@ -115,51 +119,23 @@ export class Function {
115
119
  }
116
120
 
117
121
  /**
118
- * Authentication credentials structure
119
- */
120
- export type Credentials ={
121
- access_token: string;
122
- org_sso_id?: string;
123
- customer_id: string;
124
- instance_id: string;
125
- product_sku: string;
126
- }
127
-
128
- /**
129
- * Authentication data for an Opal tool
130
- */
131
- export type AuthData = {
132
- provider: string;
133
- credentials: Credentials;
134
- }
135
-
136
- /**
137
- * Execution environment for an Opal tool
138
- */
139
- export type Environment = {
140
- execution_mode: "headless" | "interactive";
141
- }
142
-
143
- /**
144
- * Island field definition for interactive UI components
122
+ * Island action definition for interactive UI components
145
123
  */
146
- export class IslandField {
124
+ export class IslandAction {
147
125
  /**
148
- * Create a new island field
149
- * @param name Programmatic field identifier
150
- * @param label Human-readable label
151
- * @param type Field type
152
- * @param value Current field value
153
- * @param hidden Whether to hide from user
154
- * @param options Available options for selection
126
+ * Create a new island action
127
+ * @param name Programmatic action identifier
128
+ * @param label Human-readable button label
129
+ * @param type UI element type
130
+ * @param endpoint API endpoint to call
131
+ * @param operation Operation type
155
132
  */
156
133
  constructor(
157
134
  public name: string,
158
135
  public label: string,
159
- public type: "string" | "boolean" | "json",
160
- public value: string = "",
161
- public hidden: boolean = false,
162
- public options: string[] = []
136
+ public type: string,
137
+ public endpoint: string,
138
+ public operation: string = "create",
163
139
  ) {}
164
140
 
165
141
  /**
@@ -167,34 +143,35 @@ export class IslandField {
167
143
  */
168
144
  toJSON() {
169
145
  return {
170
- name: this.name,
146
+ endpoint: this.endpoint,
171
147
  label: this.label,
148
+ name: this.name,
149
+ operation: this.operation,
172
150
  type: this.type,
173
- value: this.value,
174
- hidden: this.hidden,
175
- options: this.options,
176
151
  };
177
152
  }
178
153
  }
179
154
 
180
155
  /**
181
- * Island action definition for interactive UI components
156
+ * Island field definition for interactive UI components
182
157
  */
183
- export class IslandAction {
158
+ export class IslandField {
184
159
  /**
185
- * Create a new island action
186
- * @param name Programmatic action identifier
187
- * @param label Human-readable button label
188
- * @param type UI element type
189
- * @param endpoint API endpoint to call
190
- * @param operation Operation type
160
+ * Create a new island field
161
+ * @param name Programmatic field identifier
162
+ * @param label Human-readable label
163
+ * @param type Field type
164
+ * @param value Current field value
165
+ * @param hidden Whether to hide from user
166
+ * @param options Available options for selection
191
167
  */
192
168
  constructor(
193
169
  public name: string,
194
170
  public label: string,
195
- public type: string,
196
- public endpoint: string,
197
- public operation: string = "create"
171
+ public type: "boolean" | "json" | "string",
172
+ public value: string = "",
173
+ public hidden: boolean = false,
174
+ public options: string[] = [],
198
175
  ) {}
199
176
 
200
177
  /**
@@ -202,11 +179,12 @@ export class IslandAction {
202
179
  */
203
180
  toJSON() {
204
181
  return {
205
- name: this.name,
182
+ hidden: this.hidden,
206
183
  label: this.label,
184
+ name: this.name,
185
+ options: this.options,
207
186
  type: this.type,
208
- endpoint: this.endpoint,
209
- operation: this.operation,
187
+ value: this.value,
210
188
  };
211
189
  }
212
190
  }
@@ -215,8 +193,8 @@ export class IslandAction {
215
193
  * Island configuration for interactive UI components
216
194
  */
217
195
  export class IslandConfig {
218
- static Field = IslandField;
219
196
  static Action = IslandAction;
197
+ static Field = IslandField;
220
198
 
221
199
  /**
222
200
  * Create a new island configuration
@@ -229,7 +207,7 @@ export class IslandConfig {
229
207
  public fields: IslandField[],
230
208
  public actions: IslandAction[],
231
209
  public type?: string,
232
- public icon?: string
210
+ public icon?: string,
233
211
  ) {}
234
212
 
235
213
  /**
@@ -237,8 +215,8 @@ export class IslandConfig {
237
215
  */
238
216
  toJSON() {
239
217
  return {
240
- fields: this.fields.map((field) => field.toJSON()),
241
218
  actions: this.actions.map((action) => action.toJSON()),
219
+ fields: this.fields.map((field) => field.toJSON()),
242
220
  };
243
221
  }
244
222
  }
@@ -269,7 +247,7 @@ export class IslandResponseConfig {
269
247
  export class IslandResponse {
270
248
  static ResponseConfig = IslandResponseConfig;
271
249
 
272
- public type: "island" = "island";
250
+ public type = "island" as const;
273
251
 
274
252
  /**
275
253
  * Create a new island response
@@ -278,7 +256,7 @@ export class IslandResponse {
278
256
  */
279
257
  constructor(
280
258
  public config: IslandResponseConfig,
281
- public message?: string
259
+ public message?: string,
282
260
  ) {}
283
261
 
284
262
  /**
@@ -300,3 +278,55 @@ export class IslandResponse {
300
278
  };
301
279
  }
302
280
  }
281
+
282
+ /**
283
+ * Parameter definition for an Opal tool
284
+ */
285
+ export class Parameter {
286
+ /**
287
+ * Create a new parameter definition
288
+ * @param name Parameter name
289
+ * @param type Parameter type
290
+ * @param description Parameter description
291
+ * @param required Whether the parameter is required
292
+ */
293
+ constructor(
294
+ public name: string,
295
+ public type: ParameterType,
296
+ public description: string,
297
+ public required: boolean,
298
+ ) {}
299
+
300
+ /**
301
+ * Convert to JSON for the discovery endpoint
302
+ */
303
+ toJSON() {
304
+ return {
305
+ description: this.description,
306
+ name: this.name,
307
+ required: this.required,
308
+ type: this.type,
309
+ };
310
+ }
311
+ }
312
+
313
+ /**
314
+ * Resource definition for MCP resources
315
+ */
316
+ export class Resource {
317
+ /**
318
+ * Create a new resource definition
319
+ * @param uri The unique URI for this resource (e.g., "ui://my-app/create-form")
320
+ * @param name Name of the resource
321
+ * @param description Description of the resource (optional)
322
+ * @param mimeType MIME type of the resource content (optional)
323
+ * @param title Human-readable title for the resource (optional)
324
+ */
325
+ constructor(
326
+ public uri: string,
327
+ public name: string,
328
+ public description?: string,
329
+ public mimeType?: string,
330
+ public title?: string,
331
+ ) {}
332
+ }