@optimizely-opal/opal-tools-sdk 0.1.3-dev → 0.1.6-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/dist/block.js ADDED
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ /**
3
+ * Generated by json-schema-to-typescript
4
+ * DO NOT MODIFY - This file is auto-generated from block-document-spec.json
5
+ * Run 'npm run generate:block' to regenerate
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.Block = void 0;
9
+ exports.isBlockResponse = isBlockResponse;
10
+ /**
11
+ * Builder namespace for Adaptive Block Document components.
12
+ *
13
+ * Usage:
14
+ * Block.Document({ children: [...] })
15
+ * Block.Heading({ children: "Title", level: "2" })
16
+ * Block.Input({ name: "field_name", placeholder: "Enter..." })
17
+ */
18
+ exports.Block = {
19
+ Action: (props) => ({
20
+ $type: "Block.Action",
21
+ ...props,
22
+ }),
23
+ Alert: (props) => ({
24
+ $type: "Block.Alert",
25
+ ...props,
26
+ }),
27
+ Badge: (props) => ({
28
+ $type: "Block.Badge",
29
+ ...props,
30
+ }),
31
+ Box: (props) => ({
32
+ $type: "Block.Box",
33
+ ...props,
34
+ }),
35
+ CancelAction: (props) => ({ $type: "Block.CancelAction", ...props }),
36
+ Checkbox: (props) => ({
37
+ $type: "Block.Checkbox",
38
+ ...props,
39
+ }),
40
+ Code: (props) => ({
41
+ $type: "Block.Code",
42
+ ...props,
43
+ }),
44
+ Document: (props) => ({
45
+ $type: "Block.Document",
46
+ ...props,
47
+ }),
48
+ Field: (props) => ({
49
+ $type: "Block.Field",
50
+ ...props,
51
+ }),
52
+ Group: (props) => ({
53
+ $type: "Block.Group",
54
+ ...props,
55
+ }),
56
+ Heading: (props) => ({
57
+ $type: "Block.Heading",
58
+ ...props,
59
+ }),
60
+ Input: (props) => ({
61
+ $type: "Block.Input",
62
+ ...props,
63
+ }),
64
+ Link: (props) => ({
65
+ $type: "Block.Link",
66
+ ...props,
67
+ }),
68
+ Range: (props) => ({
69
+ $type: "Block.Range",
70
+ ...props,
71
+ }),
72
+ Select: (props) => ({
73
+ $type: "Block.Select",
74
+ ...props,
75
+ }),
76
+ Separator: (props) => ({
77
+ $type: "Block.Separator",
78
+ ...props,
79
+ }),
80
+ Switch: (props) => ({
81
+ $type: "Block.Switch",
82
+ ...props,
83
+ }),
84
+ Text: (props) => ({
85
+ $type: "Block.Text",
86
+ ...props,
87
+ }),
88
+ Textarea: (props) => ({
89
+ $type: "Block.Textarea",
90
+ ...props,
91
+ }),
92
+ };
93
+ /**
94
+ * Type guard to check if a value is a BlockResponse.
95
+ */
96
+ function isBlockResponse(value) {
97
+ return (typeof value === "object" &&
98
+ value !== null &&
99
+ ("content" in value ||
100
+ "data" in value ||
101
+ "artifact" in value ||
102
+ "rollback" in value ||
103
+ "error" in value));
104
+ }
@@ -1,20 +1,20 @@
1
- import 'reflect-metadata';
2
- import { ParameterType } from './models';
1
+ import "reflect-metadata";
2
+ import { ParameterType } from "./models";
3
3
  interface ParameterDefinition {
4
- name: string;
5
- type: ParameterType;
6
4
  description: string;
5
+ name: string;
7
6
  required: boolean;
7
+ type: ParameterType;
8
8
  }
9
9
  interface ToolOptions {
10
- name: string;
11
- description: string;
12
- parameters?: ParameterDefinition[];
13
10
  authRequirements?: {
14
11
  provider: string;
15
- scopeBundle: string;
16
12
  required?: boolean;
13
+ scopeBundle: string;
17
14
  };
15
+ description: string;
16
+ name: string;
17
+ parameters?: ParameterDefinition[];
18
18
  }
19
19
  /**
20
20
  * Decorator to register a function as an Opal tool
@@ -1,50 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tool = tool;
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
4
5
  require("reflect-metadata");
5
6
  const models_1 = require("./models");
6
7
  const registry_1 = require("./registry");
7
- /**
8
- * Map a TypeScript type to a ParameterType
9
- * @param type TypeScript type
10
- */
11
- function mapTypeToParameterType(type) {
12
- if (type === String || type.name === 'String') {
13
- return models_1.ParameterType.String;
14
- }
15
- else if (type === Number || type.name === 'Number') {
16
- return models_1.ParameterType.Number;
17
- }
18
- else if (type === Boolean || type.name === 'Boolean') {
19
- return models_1.ParameterType.Boolean;
20
- }
21
- else if (type === Array || type.name === 'Array') {
22
- return models_1.ParameterType.List;
23
- }
24
- else if (type === Object || type.name === 'Object') {
25
- return models_1.ParameterType.Dictionary;
26
- }
27
- // Default to string
28
- return models_1.ParameterType.String;
29
- }
30
- /**
31
- * Extract parameters from a TypeScript interface
32
- * @param paramType Parameter type object
33
- */
34
- function extractParameters(paramType) {
35
- const parameters = [];
36
- // This is very basic and doesn't handle complex types
37
- // For production use, this would need to be more sophisticated
38
- for (const key in paramType) {
39
- if (paramType.hasOwnProperty(key)) {
40
- const type = typeof paramType[key] === 'undefined' ? String : paramType[key].constructor;
41
- const required = true; // In a real implementation, we'd detect optional parameters
42
- parameters.push(new models_1.Parameter(key, mapTypeToParameterType(type), '', // Description - in a real impl we'd use TypeDoc or similar
43
- required));
44
- }
45
- }
46
- return parameters;
47
- }
48
8
  /**
49
9
  * Decorator to register a function as an Opal tool
50
10
  * @param options Tool options including:
@@ -66,7 +26,7 @@ function tool(options) {
66
26
  const isMethod = propertyKey && descriptor;
67
27
  const handler = isMethod ? descriptor.value : target;
68
28
  // Generate endpoint from name - ensure hyphens instead of underscores
69
- const endpoint = `/tools/${options.name.replace(/_/g, '-')}`;
29
+ const endpoint = `/tools/${options.name.replace(/_/g, "-")}`;
70
30
  // Convert parameter definitions to Parameter objects
71
31
  const parameters = [];
72
32
  if (options.parameters && options.parameters.length > 0) {
@@ -79,7 +39,7 @@ function tool(options) {
79
39
  let authRequirements;
80
40
  if (options.authRequirements) {
81
41
  authRequirements = [
82
- new models_1.AuthRequirement(options.authRequirements.provider, options.authRequirements.scopeBundle, options.authRequirements.required ?? true)
42
+ new models_1.AuthRequirement(options.authRequirements.provider, options.authRequirements.scopeBundle, options.authRequirements.required ?? true),
83
43
  ];
84
44
  }
85
45
  // Register the tool with all services
package/dist/index.d.ts CHANGED
@@ -1,5 +1,9 @@
1
- import 'reflect-metadata';
2
- export { ToolsService } from './service';
3
- export { tool } from './decorators';
4
- export { requiresAuth } from './auth';
5
- export * from './models';
1
+ import "reflect-metadata";
2
+ export { requiresAuth } from "./auth";
3
+ export { Block, isBlockResponse } from "./block";
4
+ export type * from "./block";
5
+ export { tool } from "./decorators";
6
+ export * from "./models";
7
+ export { registerTool } from "./registerTool";
8
+ export type { RequestHandlerExtra } from "./registerTool";
9
+ export { ToolsService } from "./service";
package/dist/index.js CHANGED
@@ -14,12 +14,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.requiresAuth = exports.tool = exports.ToolsService = void 0;
17
+ exports.ToolsService = exports.registerTool = exports.tool = exports.isBlockResponse = exports.Block = exports.requiresAuth = void 0;
18
18
  require("reflect-metadata");
19
- var service_1 = require("./service");
20
- Object.defineProperty(exports, "ToolsService", { enumerable: true, get: function () { return service_1.ToolsService; } });
21
- var decorators_1 = require("./decorators");
22
- Object.defineProperty(exports, "tool", { enumerable: true, get: function () { return decorators_1.tool; } });
23
19
  var auth_1 = require("./auth");
24
20
  Object.defineProperty(exports, "requiresAuth", { enumerable: true, get: function () { return auth_1.requiresAuth; } });
21
+ var block_1 = require("./block");
22
+ Object.defineProperty(exports, "Block", { enumerable: true, get: function () { return block_1.Block; } });
23
+ Object.defineProperty(exports, "isBlockResponse", { enumerable: true, get: function () { return block_1.isBlockResponse; } });
24
+ var decorators_1 = require("./decorators");
25
+ Object.defineProperty(exports, "tool", { enumerable: true, get: function () { return decorators_1.tool; } });
25
26
  __exportStar(require("./models"), exports);
27
+ var registerTool_1 = require("./registerTool");
28
+ Object.defineProperty(exports, "registerTool", { enumerable: true, get: function () { return registerTool_1.registerTool; } });
29
+ var service_1 = require("./service");
30
+ Object.defineProperty(exports, "ToolsService", { enumerable: true, get: function () { return service_1.ToolsService; } });
package/dist/models.d.ts CHANGED
@@ -2,39 +2,36 @@
2
2
  * Types of parameters supported by Opal tools
3
3
  */
4
4
  export declare enum ParameterType {
5
- String = "string",
6
- Integer = "integer",
7
- Number = "number",
8
5
  Boolean = "boolean",
6
+ Dictionary = "object",
7
+ Integer = "integer",
9
8
  List = "array",
10
- Dictionary = "object"
9
+ Number = "number",
10
+ String = "string"
11
11
  }
12
12
  /**
13
- * Parameter definition for an Opal tool
13
+ * Authentication data for an Opal tool
14
14
  */
15
- export declare class Parameter {
16
- name: string;
17
- type: ParameterType;
18
- description: string;
19
- required: boolean;
20
- /**
21
- * Create a new parameter definition
22
- * @param name Parameter name
23
- * @param type Parameter type
24
- * @param description Parameter description
25
- * @param required Whether the parameter is required
26
- */
27
- constructor(name: string, type: ParameterType, description: string, required: boolean);
28
- /**
29
- * Convert to JSON for the discovery endpoint
30
- */
31
- toJSON(): {
32
- name: string;
33
- type: ParameterType;
34
- description: string;
35
- required: boolean;
36
- };
37
- }
15
+ export type AuthData = {
16
+ credentials: Credentials;
17
+ provider: string;
18
+ };
19
+ /**
20
+ * Authentication credentials structure
21
+ */
22
+ export type Credentials = {
23
+ access_token: string;
24
+ customer_id: string;
25
+ instance_id: string;
26
+ org_sso_id?: string;
27
+ product_sku: string;
28
+ };
29
+ /**
30
+ * Execution environment for an Opal tool
31
+ */
32
+ export type Environment = {
33
+ execution_mode: "headless" | "interactive";
34
+ };
38
35
  /**
39
36
  * Authentication requirements for an Opal tool
40
37
  */
@@ -54,8 +51,8 @@ export declare class AuthRequirement {
54
51
  */
55
52
  toJSON(): {
56
53
  provider: string;
57
- scope_bundle: string;
58
54
  required: boolean;
55
+ scope_bundle: string;
59
56
  };
60
57
  }
61
58
  /**
@@ -86,35 +83,41 @@ export declare class Function {
86
83
  toJSON(): any;
87
84
  }
88
85
  /**
89
- * Authentication credentials structure
90
- */
91
- export type Credentials = {
92
- access_token: string;
93
- org_sso_id?: string;
94
- customer_id: string;
95
- instance_id: string;
96
- product_sku: string;
97
- };
98
- /**
99
- * Authentication data for an Opal tool
100
- */
101
- export type AuthData = {
102
- provider: string;
103
- credentials: Credentials;
104
- };
105
- /**
106
- * Execution environment for an Opal tool
86
+ * Island action definition for interactive UI components
107
87
  */
108
- export type Environment = {
109
- execution_mode: "headless" | "interactive";
110
- };
88
+ export declare class IslandAction {
89
+ name: string;
90
+ label: string;
91
+ type: string;
92
+ endpoint: string;
93
+ operation: string;
94
+ /**
95
+ * Create a new island action
96
+ * @param name Programmatic action identifier
97
+ * @param label Human-readable button label
98
+ * @param type UI element type
99
+ * @param endpoint API endpoint to call
100
+ * @param operation Operation type
101
+ */
102
+ constructor(name: string, label: string, type: string, endpoint: string, operation?: string);
103
+ /**
104
+ * Convert to JSON for the discovery endpoint
105
+ */
106
+ toJSON(): {
107
+ endpoint: string;
108
+ label: string;
109
+ name: string;
110
+ operation: string;
111
+ type: string;
112
+ };
113
+ }
111
114
  /**
112
115
  * Island field definition for interactive UI components
113
116
  */
114
117
  export declare class IslandField {
115
118
  name: string;
116
119
  label: string;
117
- type: "string" | "boolean" | "json";
120
+ type: "boolean" | "json" | "string";
118
121
  value: string;
119
122
  hidden: boolean;
120
123
  options: string[];
@@ -127,46 +130,17 @@ export declare class IslandField {
127
130
  * @param hidden Whether to hide from user
128
131
  * @param options Available options for selection
129
132
  */
130
- constructor(name: string, label: string, type: "string" | "boolean" | "json", value?: string, hidden?: boolean, options?: string[]);
133
+ constructor(name: string, label: string, type: "boolean" | "json" | "string", value?: string, hidden?: boolean, options?: string[]);
131
134
  /**
132
135
  * Convert to JSON for the discovery endpoint
133
136
  */
134
137
  toJSON(): {
135
- name: string;
138
+ hidden: boolean;
136
139
  label: string;
140
+ name: string;
141
+ options: string[];
137
142
  type: "string" | "boolean" | "json";
138
143
  value: string;
139
- hidden: boolean;
140
- options: string[];
141
- };
142
- }
143
- /**
144
- * Island action definition for interactive UI components
145
- */
146
- export declare class IslandAction {
147
- name: string;
148
- label: string;
149
- type: string;
150
- endpoint: string;
151
- operation: string;
152
- /**
153
- * Create a new island action
154
- * @param name Programmatic action identifier
155
- * @param label Human-readable button label
156
- * @param type UI element type
157
- * @param endpoint API endpoint to call
158
- * @param operation Operation type
159
- */
160
- constructor(name: string, label: string, type: string, endpoint: string, operation?: string);
161
- /**
162
- * Convert to JSON for the discovery endpoint
163
- */
164
- toJSON(): {
165
- name: string;
166
- label: string;
167
- type: string;
168
- endpoint: string;
169
- operation: string;
170
144
  };
171
145
  }
172
146
  /**
@@ -175,32 +149,36 @@ export declare class IslandAction {
175
149
  export declare class IslandConfig {
176
150
  fields: IslandField[];
177
151
  actions: IslandAction[];
178
- static Field: typeof IslandField;
152
+ type?: string | undefined;
153
+ icon?: string | undefined;
179
154
  static Action: typeof IslandAction;
155
+ static Field: typeof IslandField;
180
156
  /**
181
157
  * Create a new island configuration
182
158
  * @param fields List of island fields
183
159
  * @param actions List of island actions
160
+ * @param type Optional island type
161
+ * @param icon Optional island icon
184
162
  */
185
- constructor(fields: IslandField[], actions: IslandAction[]);
163
+ constructor(fields: IslandField[], actions: IslandAction[], type?: string | undefined, icon?: string | undefined);
186
164
  /**
187
165
  * Convert to JSON for the discovery endpoint
188
166
  */
189
167
  toJSON(): {
190
- fields: {
168
+ actions: {
169
+ endpoint: string;
170
+ label: string;
191
171
  name: string;
172
+ operation: string;
173
+ type: string;
174
+ }[];
175
+ fields: {
176
+ hidden: boolean;
192
177
  label: string;
178
+ name: string;
179
+ options: string[];
193
180
  type: "string" | "boolean" | "json";
194
181
  value: string;
195
- hidden: boolean;
196
- options: string[];
197
- }[];
198
- actions: {
199
- name: string;
200
- label: string;
201
- type: string;
202
- endpoint: string;
203
- operation: string;
204
182
  }[];
205
183
  };
206
184
  }
@@ -219,20 +197,20 @@ export declare class IslandResponseConfig {
219
197
  */
220
198
  toJSON(): {
221
199
  islands: {
222
- fields: {
200
+ actions: {
201
+ endpoint: string;
202
+ label: string;
223
203
  name: string;
204
+ operation: string;
205
+ type: string;
206
+ }[];
207
+ fields: {
208
+ hidden: boolean;
224
209
  label: string;
210
+ name: string;
211
+ options: string[];
225
212
  type: "string" | "boolean" | "json";
226
213
  value: string;
227
- hidden: boolean;
228
- options: string[];
229
- }[];
230
- actions: {
231
- name: string;
232
- label: string;
233
- type: string;
234
- endpoint: string;
235
- operation: string;
236
214
  }[];
237
215
  }[];
238
216
  };
@@ -242,41 +220,70 @@ export declare class IslandResponseConfig {
242
220
  */
243
221
  export declare class IslandResponse {
244
222
  config: IslandResponseConfig;
223
+ message?: string | undefined;
245
224
  static ResponseConfig: typeof IslandResponseConfig;
246
225
  type: "island";
247
226
  /**
248
227
  * Create a new island response
249
228
  * @param config Response configuration
229
+ * @param message Optional message for the island response
250
230
  */
251
- constructor(config: IslandResponseConfig);
231
+ constructor(config: IslandResponseConfig, message?: string | undefined);
252
232
  /**
253
233
  * Create an island response with a list of islands
254
234
  * @param islands List of island configurations
235
+ * @param message Optional message for the island response
255
236
  * @returns New IslandResponse instance
256
237
  */
257
- static create(islands: IslandConfig[]): IslandResponse;
238
+ static create(islands: IslandConfig[], message?: string): IslandResponse;
258
239
  /**
259
240
  * Convert to JSON for the discovery endpoint
260
241
  */
261
242
  toJSON(): {
262
243
  config: {
263
244
  islands: {
264
- fields: {
245
+ actions: {
246
+ endpoint: string;
247
+ label: string;
265
248
  name: string;
249
+ operation: string;
250
+ type: string;
251
+ }[];
252
+ fields: {
253
+ hidden: boolean;
266
254
  label: string;
255
+ name: string;
256
+ options: string[];
267
257
  type: "string" | "boolean" | "json";
268
258
  value: string;
269
- hidden: boolean;
270
- options: string[];
271
- }[];
272
- actions: {
273
- name: string;
274
- label: string;
275
- type: string;
276
- endpoint: string;
277
- operation: string;
278
259
  }[];
279
260
  }[];
280
261
  };
281
262
  };
282
263
  }
264
+ /**
265
+ * Parameter definition for an Opal tool
266
+ */
267
+ export declare class Parameter {
268
+ name: string;
269
+ type: ParameterType;
270
+ description: string;
271
+ required: boolean;
272
+ /**
273
+ * Create a new parameter definition
274
+ * @param name Parameter name
275
+ * @param type Parameter type
276
+ * @param description Parameter description
277
+ * @param required Whether the parameter is required
278
+ */
279
+ constructor(name: string, type: ParameterType, description: string, required: boolean);
280
+ /**
281
+ * Convert to JSON for the discovery endpoint
282
+ */
283
+ toJSON(): {
284
+ description: string;
285
+ name: string;
286
+ required: boolean;
287
+ type: ParameterType;
288
+ };
289
+ }