@redonvn/open-claw-sdk 0.1.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.
package/dist/index.cjs ADDED
@@ -0,0 +1,559 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ convertOpenApiToTools: () => convertOpenApiToTools,
34
+ createOpenApiPlugin: () => createOpenApiPlugin,
35
+ generatePluginFromOpenApi: () => generatePluginFromOpenApi,
36
+ loadOpenApiDocument: () => loadOpenApiDocument,
37
+ openApiSchemaToJsonSchema: () => openApiSchemaToJsonSchema,
38
+ renderCatalogFile: () => renderCatalogFile,
39
+ renderPluginManifest: () => renderPluginManifest,
40
+ renderPluginModule: () => renderPluginModule,
41
+ writeGeneratedPlugin: () => writeGeneratedPlugin
42
+ });
43
+ module.exports = __toCommonJS(index_exports);
44
+
45
+ // src/generator.ts
46
+ var import_node_fs2 = require("fs");
47
+ var import_node_path = __toESM(require("path"), 1);
48
+
49
+ // src/openapi.ts
50
+ var import_node_fs = require("fs");
51
+
52
+ // src/utils.ts
53
+ var HTTP_METHODS = [
54
+ "get",
55
+ "post",
56
+ "put",
57
+ "patch",
58
+ "delete",
59
+ "options",
60
+ "head"
61
+ ];
62
+ var AUTH_HEADER_NAMES = /* @__PURE__ */ new Set([
63
+ "authorization",
64
+ "x-api-key",
65
+ "api-key",
66
+ "dt-jwt"
67
+ ]);
68
+ var sanitizeIdentifier = (value) => value.trim().replace(/[^a-zA-Z0-9]+/g, "_").replace(/^_+|_+$/g, "").replace(/_{2,}/g, "_").toLowerCase() || "tool";
69
+ var toTitleCase = (value) => value.split(/[^a-zA-Z0-9]+/).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
70
+ var buildToolName = (toolPrefix, rawName) => {
71
+ const base = sanitizeIdentifier(rawName);
72
+ const prefix = sanitizeIdentifier(toolPrefix ?? "");
73
+ return prefix ? `${prefix}_${base}` : base;
74
+ };
75
+ var buildOperationId = (method, path2, operationId) => {
76
+ if (operationId?.trim()) {
77
+ return sanitizeIdentifier(operationId);
78
+ }
79
+ const pathPart = path2.replace(/\{([^}]+)\}/g, "by_$1").replace(/\/+/g, "_");
80
+ return sanitizeIdentifier(`${method}_${pathPart}`);
81
+ };
82
+ var pickContentSchema = (content) => content?.["application/json"]?.schema ?? content?.["application/*+json"]?.schema ?? Object.values(content ?? {})[0]?.schema;
83
+ var dedupeParameters = (pathLevel, operationLevel) => {
84
+ const byKey = /* @__PURE__ */ new Map();
85
+ for (const param of [...pathLevel ?? [], ...operationLevel ?? []]) {
86
+ byKey.set(`${param.in}:${param.name}`, param);
87
+ }
88
+ return [...byKey.values()];
89
+ };
90
+ var compactObject = (value) => {
91
+ const output = {};
92
+ for (const [key, item] of Object.entries(value)) {
93
+ if (item !== void 0) {
94
+ output[key] = item;
95
+ }
96
+ }
97
+ return output;
98
+ };
99
+ var hasSchemaContent = (schema) => Boolean(
100
+ schema && (schema.properties && Object.keys(schema.properties).length > 0 || schema.required && schema.required.length > 0 || schema.type || schema.oneOf || schema.anyOf || schema.allOf)
101
+ );
102
+
103
+ // src/openapi.ts
104
+ var isHttpUrl = (value) => /^https?:\/\//i.test(value);
105
+ var readUrl = async (url) => {
106
+ const response = await fetch(url);
107
+ if (!response.ok) {
108
+ throw new Error(`Unable to load OpenAPI document from ${url}: ${response.status} ${response.statusText}`);
109
+ }
110
+ return response.text();
111
+ };
112
+ var loadOpenApiDocument = async (source) => {
113
+ const raw = isHttpUrl(source) ? await readUrl(source) : await import_node_fs.promises.readFile(source, "utf8");
114
+ const document = JSON.parse(raw);
115
+ if (!document.openapi || !document.paths) {
116
+ throw new Error("Invalid OpenAPI document: missing `openapi` or `paths`.");
117
+ }
118
+ return document;
119
+ };
120
+ var resolveRefName = (ref) => ref.split("/").pop() ?? "UnknownSchema";
121
+ var resolveSchemaRef = (document, ref) => {
122
+ const schemaName = resolveRefName(ref);
123
+ return document.components?.schemas?.[schemaName];
124
+ };
125
+ var openApiSchemaToJsonSchema = (schema, document, seen = /* @__PURE__ */ new Set()) => {
126
+ if (!schema) {
127
+ return { type: "object", additionalProperties: true };
128
+ }
129
+ if (schema.$ref) {
130
+ if (seen.has(schema.$ref)) {
131
+ return { type: "object", additionalProperties: true };
132
+ }
133
+ const resolved = resolveSchemaRef(document, schema.$ref);
134
+ if (!resolved) {
135
+ return { type: "object", additionalProperties: true };
136
+ }
137
+ const nextSeen = new Set(seen);
138
+ nextSeen.add(schema.$ref);
139
+ return openApiSchemaToJsonSchema(resolved, document, nextSeen);
140
+ }
141
+ const jsonSchema = compactObject({
142
+ type: Array.isArray(schema.type) ? [...schema.type] : schema.type,
143
+ description: schema.description,
144
+ default: schema.default,
145
+ enum: schema.enum ? [...schema.enum] : void 0
146
+ });
147
+ if (schema.oneOf?.length) {
148
+ jsonSchema.oneOf = schema.oneOf.map((item) => openApiSchemaToJsonSchema(item, document, seen));
149
+ }
150
+ if (schema.anyOf?.length) {
151
+ jsonSchema.anyOf = schema.anyOf.map((item) => openApiSchemaToJsonSchema(item, document, seen));
152
+ }
153
+ if (schema.allOf?.length) {
154
+ jsonSchema.allOf = schema.allOf.map((item) => openApiSchemaToJsonSchema(item, document, seen));
155
+ }
156
+ if (schema.items) {
157
+ jsonSchema.items = openApiSchemaToJsonSchema(schema.items, document, seen);
158
+ }
159
+ if (schema.properties) {
160
+ jsonSchema.properties = Object.fromEntries(
161
+ Object.entries(schema.properties).map(([key, value]) => [
162
+ key,
163
+ openApiSchemaToJsonSchema(value, document, seen)
164
+ ])
165
+ );
166
+ }
167
+ if (schema.required?.length) {
168
+ jsonSchema.required = [...schema.required];
169
+ }
170
+ if (schema.additionalProperties !== void 0) {
171
+ jsonSchema.additionalProperties = schema.additionalProperties === true || schema.additionalProperties === false ? schema.additionalProperties : openApiSchemaToJsonSchema(schema.additionalProperties, document, seen);
172
+ }
173
+ if (schema.nullable) {
174
+ const currentType = jsonSchema.type;
175
+ if (Array.isArray(currentType)) {
176
+ jsonSchema.type = currentType.includes("null") ? currentType : [...currentType, "null"];
177
+ } else if (currentType) {
178
+ jsonSchema.type = currentType === "null" ? "null" : [currentType, "null"];
179
+ } else {
180
+ jsonSchema.type = ["object", "null"];
181
+ }
182
+ }
183
+ return jsonSchema;
184
+ };
185
+ var buildParameterSection = (sectionName, parameters, document) => {
186
+ if (!parameters.length) {
187
+ return null;
188
+ }
189
+ const properties = {};
190
+ const required = [];
191
+ for (const parameter of parameters) {
192
+ properties[parameter.name] = compactObject({
193
+ ...openApiSchemaToJsonSchema(parameter.schema, document),
194
+ description: parameter.description ?? parameter.schema?.description
195
+ });
196
+ if (parameter.required) {
197
+ required.push(parameter.name);
198
+ }
199
+ }
200
+ return {
201
+ name: sectionName,
202
+ required: required.length > 0,
203
+ schema: compactObject({
204
+ type: "object",
205
+ properties,
206
+ required: required.length ? required : void 0,
207
+ additionalProperties: false
208
+ })
209
+ };
210
+ };
211
+ var buildToolParameters = (document, path2, operation, options, pathParameters, queryParameters, headerParameters) => {
212
+ const requestBodySchema = pickContentSchema(operation.requestBody?.content);
213
+ const properties = {};
214
+ const required = [];
215
+ const sections = [
216
+ buildParameterSection("path", pathParameters, document),
217
+ buildParameterSection("query", queryParameters, document),
218
+ options.includeHeaders ? buildParameterSection("headers", headerParameters, document) : null
219
+ ].filter((value) => Boolean(value));
220
+ for (const section of sections) {
221
+ if (hasSchemaContent(section.schema)) {
222
+ properties[section.name] = section.schema;
223
+ if (section.required) {
224
+ required.push(section.name);
225
+ }
226
+ }
227
+ }
228
+ if (requestBodySchema) {
229
+ properties.body = openApiSchemaToJsonSchema(requestBodySchema, document);
230
+ if (operation.requestBody?.required) {
231
+ required.push("body");
232
+ }
233
+ }
234
+ return compactObject({
235
+ type: "object",
236
+ properties,
237
+ required: required.length ? required : void 0,
238
+ additionalProperties: false,
239
+ description: `${operation.summary ?? operation.operationId ?? `${path2} request`} tool arguments`
240
+ });
241
+ };
242
+ var buildToolDescription = (path2, method, operation) => {
243
+ const summary = operation.summary?.trim();
244
+ const description = operation.description?.trim();
245
+ if (summary && description && description !== summary) {
246
+ return `${summary}. ${description}`;
247
+ }
248
+ if (summary) {
249
+ return summary;
250
+ }
251
+ if (description) {
252
+ return description;
253
+ }
254
+ return `${method.toUpperCase()} ${path2}`;
255
+ };
256
+ var buildToolDefinition = (document, path2, method, operation, options, pathParameters, queryParameters, headerParameters) => {
257
+ const operationId = buildOperationId(method, path2, operation.operationId);
258
+ return {
259
+ name: buildToolName(options.toolPrefix, operationId),
260
+ description: buildToolDescription(path2, method, operation),
261
+ method: method.toUpperCase(),
262
+ path: path2,
263
+ operationId,
264
+ parameters: buildToolParameters(
265
+ document,
266
+ path2,
267
+ operation,
268
+ options,
269
+ pathParameters,
270
+ queryParameters,
271
+ headerParameters
272
+ ),
273
+ tags: operation.tags ?? []
274
+ };
275
+ };
276
+ var convertOpenApiToTools = (document, options) => {
277
+ const tools = [];
278
+ for (const [path2, pathItem] of Object.entries(document.paths)) {
279
+ for (const method of HTTP_METHODS) {
280
+ const operation = pathItem[method];
281
+ if (!operation) {
282
+ continue;
283
+ }
284
+ const parameters = dedupeParameters(pathItem.parameters, operation.parameters);
285
+ const pathParameters = parameters.filter((parameter) => parameter.in === "path");
286
+ const queryParameters = parameters.filter((parameter) => parameter.in === "query");
287
+ const headerParameters = parameters.filter(
288
+ (parameter) => parameter.in === "header" && !AUTH_HEADER_NAMES.has(parameter.name.toLowerCase())
289
+ );
290
+ tools.push(
291
+ buildToolDefinition(
292
+ document,
293
+ path2,
294
+ method,
295
+ operation,
296
+ options,
297
+ pathParameters,
298
+ queryParameters,
299
+ headerParameters
300
+ )
301
+ );
302
+ }
303
+ }
304
+ tools.sort((left, right) => left.name.localeCompare(right.name));
305
+ return {
306
+ pluginId: options.pluginId,
307
+ pluginName: options.pluginName ?? toTitleCase(options.pluginId),
308
+ description: document.info?.description?.trim() ?? `Generated OpenClaw tool plugin for ${document.info?.title ?? options.pluginId}`,
309
+ serverUrl: options.defaultServerUrl ?? document.servers?.[0]?.url,
310
+ optional: options.optional ?? true,
311
+ tools
312
+ };
313
+ };
314
+
315
+ // src/generator.ts
316
+ var serialize = (value) => JSON.stringify(value, null, 2);
317
+ var renderPluginManifest = (catalog) => `${serialize({
318
+ id: catalog.pluginId,
319
+ name: catalog.pluginName,
320
+ version: "0.1.0",
321
+ description: catalog.description,
322
+ configSchema: {
323
+ type: "object",
324
+ additionalProperties: false,
325
+ properties: {
326
+ baseUrl: {
327
+ type: "string",
328
+ description: "Base URL of the target HTTP API"
329
+ },
330
+ bearerToken: {
331
+ type: "string",
332
+ description: "Bearer token used for Authorization header"
333
+ },
334
+ apiKey: {
335
+ type: "string",
336
+ description: "Static API key for the upstream API"
337
+ },
338
+ apiKeyHeader: {
339
+ type: "string",
340
+ description: "Header name used when apiKey is set",
341
+ default: "x-api-key"
342
+ },
343
+ timeoutMs: {
344
+ type: "number",
345
+ description: "Timeout in milliseconds for outbound tool calls"
346
+ },
347
+ defaultHeaders: {
348
+ type: "object",
349
+ additionalProperties: {
350
+ type: "string"
351
+ },
352
+ description: "Additional headers added to every request"
353
+ }
354
+ }
355
+ },
356
+ uiHints: {
357
+ baseUrl: {
358
+ label: "Base URL",
359
+ placeholder: catalog.serverUrl ?? "https://api.example.com"
360
+ },
361
+ bearerToken: {
362
+ label: "Bearer Token",
363
+ sensitive: true
364
+ },
365
+ apiKey: {
366
+ label: "API Key",
367
+ sensitive: true
368
+ },
369
+ apiKeyHeader: {
370
+ label: "API Key Header"
371
+ },
372
+ timeoutMs: {
373
+ label: "Timeout (ms)"
374
+ }
375
+ }
376
+ })}
377
+ `;
378
+ var renderPluginModule = (catalog) => `import { createOpenApiPlugin } from "@redonvn/open-claw-sdk";
379
+
380
+ export const catalog = ${serialize(catalog)} as const;
381
+
382
+ export default createOpenApiPlugin(catalog);
383
+ `;
384
+ var renderCatalogFile = (catalog) => `${serialize(catalog)}
385
+ `;
386
+ var ensureDir = async (dirPath) => {
387
+ await import_node_fs2.promises.mkdir(dirPath, { recursive: true });
388
+ };
389
+ var writeGeneratedPlugin = async (catalog, outDir) => {
390
+ await ensureDir(outDir);
391
+ const manifestPath = import_node_path.default.join(outDir, "openclaw.plugin.json");
392
+ const indexPath = import_node_path.default.join(outDir, "index.ts");
393
+ const catalogPath = import_node_path.default.join(outDir, "tool-catalog.json");
394
+ await Promise.all([
395
+ import_node_fs2.promises.writeFile(manifestPath, renderPluginManifest(catalog), "utf8"),
396
+ import_node_fs2.promises.writeFile(indexPath, renderPluginModule(catalog), "utf8"),
397
+ import_node_fs2.promises.writeFile(catalogPath, renderCatalogFile(catalog), "utf8")
398
+ ]);
399
+ return { manifestPath, indexPath, catalogPath };
400
+ };
401
+ var generatePluginFromOpenApi = async (options) => {
402
+ const document = await loadOpenApiDocument(options.input);
403
+ const convertOptions = {
404
+ pluginId: options.pluginId,
405
+ pluginName: options.pluginName,
406
+ toolPrefix: options.toolPrefix,
407
+ optional: options.optional,
408
+ includeHeaders: options.includeHeaders,
409
+ defaultServerUrl: options.defaultServerUrl
410
+ };
411
+ const catalog = convertOpenApiToTools(document, convertOptions);
412
+ const files = await writeGeneratedPlugin(catalog, options.outDir);
413
+ return { catalog, files };
414
+ };
415
+
416
+ // src/runtime.ts
417
+ var encodeQueryValue = (value) => {
418
+ if (value === null) {
419
+ return "null";
420
+ }
421
+ if (typeof value === "string") {
422
+ return value;
423
+ }
424
+ if (typeof value === "number" || typeof value === "boolean") {
425
+ return String(value);
426
+ }
427
+ return JSON.stringify(value);
428
+ };
429
+ var applyPathParams = (pathTemplate, pathParams) => pathTemplate.replace(/\{([^}]+)\}/g, (_, key) => {
430
+ const raw = pathParams?.[key];
431
+ if (raw === void 0 || raw === null) {
432
+ throw new Error(`Missing required path parameter: ${key}`);
433
+ }
434
+ return encodeURIComponent(String(raw));
435
+ });
436
+ var appendQueryParams = (url, query) => {
437
+ if (!query) {
438
+ return;
439
+ }
440
+ for (const [key, value] of Object.entries(query)) {
441
+ if (value === void 0) {
442
+ continue;
443
+ }
444
+ if (Array.isArray(value)) {
445
+ for (const item of value) {
446
+ url.searchParams.append(key, encodeQueryValue(item));
447
+ }
448
+ continue;
449
+ }
450
+ url.searchParams.set(key, encodeQueryValue(value));
451
+ }
452
+ };
453
+ var resolvePluginConfig = (api, pluginId) => api.config?.plugins?.entries?.[pluginId]?.config ?? {};
454
+ var buildHeaders = (runtimeConfig, requestHeaders, hasBody) => {
455
+ const headers = new Headers();
456
+ for (const [key, value] of Object.entries(runtimeConfig.defaultHeaders ?? {})) {
457
+ headers.set(key, value);
458
+ }
459
+ if (runtimeConfig.bearerToken) {
460
+ headers.set("authorization", `Bearer ${runtimeConfig.bearerToken}`);
461
+ } else if (runtimeConfig.apiKey) {
462
+ headers.set(runtimeConfig.apiKeyHeader ?? "x-api-key", runtimeConfig.apiKey);
463
+ }
464
+ for (const [key, value] of Object.entries(requestHeaders ?? {})) {
465
+ if (value !== void 0 && value !== null) {
466
+ headers.set(key, String(value));
467
+ }
468
+ }
469
+ if (hasBody && !headers.has("content-type")) {
470
+ headers.set("content-type", "application/json");
471
+ }
472
+ return headers;
473
+ };
474
+ var parseResponse = async (response) => {
475
+ const contentType = response.headers.get("content-type") ?? "";
476
+ if (contentType.includes("application/json")) {
477
+ return response.json();
478
+ }
479
+ return response.text();
480
+ };
481
+ var formatToolResult = (payload) => ({
482
+ content: [
483
+ {
484
+ type: "text",
485
+ text: typeof payload === "string" ? payload : JSON.stringify(payload, null, 2)
486
+ }
487
+ ]
488
+ });
489
+ var createOpenApiPlugin = (catalog, options) => {
490
+ return function register(api) {
491
+ for (const tool of catalog.tools) {
492
+ api.registerTool(
493
+ {
494
+ name: tool.name,
495
+ description: tool.description,
496
+ parameters: tool.parameters,
497
+ execute: async (_id, params) => {
498
+ const runtimeConfig = resolvePluginConfig(api, catalog.pluginId);
499
+ const baseUrl = runtimeConfig.baseUrl ?? catalog.serverUrl;
500
+ if (!baseUrl) {
501
+ throw new Error(
502
+ `Missing baseUrl for plugin ${catalog.pluginId}. Set plugins.entries.${catalog.pluginId}.config.baseUrl.`
503
+ );
504
+ }
505
+ const input = params ?? {};
506
+ const finalUrl = new URL(
507
+ applyPathParams(tool.path, input.path),
508
+ baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`
509
+ );
510
+ appendQueryParams(finalUrl, input.query);
511
+ const controller = new AbortController();
512
+ const timeoutMs = runtimeConfig.timeoutMs ?? options?.timeoutMs;
513
+ const timeout = timeoutMs ? setTimeout(() => controller.abort(), timeoutMs) : void 0;
514
+ try {
515
+ const hasBody = input.body !== void 0;
516
+ const requestInit = {
517
+ method: tool.method,
518
+ headers: buildHeaders(runtimeConfig, input.headers, hasBody),
519
+ signal: controller.signal
520
+ };
521
+ if (hasBody) {
522
+ requestInit.body = JSON.stringify(input.body);
523
+ }
524
+ const response = await fetch(finalUrl, requestInit);
525
+ const payload = await parseResponse(response);
526
+ if (!response.ok) {
527
+ return formatToolResult({
528
+ ok: false,
529
+ status: response.status,
530
+ statusText: response.statusText,
531
+ data: payload
532
+ });
533
+ }
534
+ return formatToolResult(payload);
535
+ } finally {
536
+ if (timeout) {
537
+ clearTimeout(timeout);
538
+ }
539
+ }
540
+ }
541
+ },
542
+ { optional: catalog.optional ?? true }
543
+ );
544
+ }
545
+ };
546
+ };
547
+ // Annotate the CommonJS export names for ESM import in node:
548
+ 0 && (module.exports = {
549
+ convertOpenApiToTools,
550
+ createOpenApiPlugin,
551
+ generatePluginFromOpenApi,
552
+ loadOpenApiDocument,
553
+ openApiSchemaToJsonSchema,
554
+ renderCatalogFile,
555
+ renderPluginManifest,
556
+ renderPluginModule,
557
+ writeGeneratedPlugin
558
+ });
559
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/generator.ts","../src/openapi.ts","../src/utils.ts","../src/runtime.ts"],"sourcesContent":["export * from \"./generator\";\nexport * from \"./openapi\";\nexport * from \"./runtime\";\nexport * from \"./types\";\n","import { promises as fs } from \"node:fs\";\nimport path from \"node:path\";\nimport {\n ConvertOpenApiOptions,\n GeneratedPluginFiles,\n GeneratePluginOptions,\n OpenClawPluginCatalog\n} from \"./types\";\nimport { convertOpenApiToTools, loadOpenApiDocument } from \"./openapi\";\n\nconst serialize = (value: unknown): string => JSON.stringify(value, null, 2);\n\nexport const renderPluginManifest = (catalog: OpenClawPluginCatalog): string =>\n `${serialize({\n id: catalog.pluginId,\n name: catalog.pluginName,\n version: \"0.1.0\",\n description: catalog.description,\n configSchema: {\n type: \"object\",\n additionalProperties: false,\n properties: {\n baseUrl: {\n type: \"string\",\n description: \"Base URL of the target HTTP API\"\n },\n bearerToken: {\n type: \"string\",\n description: \"Bearer token used for Authorization header\"\n },\n apiKey: {\n type: \"string\",\n description: \"Static API key for the upstream API\"\n },\n apiKeyHeader: {\n type: \"string\",\n description: \"Header name used when apiKey is set\",\n default: \"x-api-key\"\n },\n timeoutMs: {\n type: \"number\",\n description: \"Timeout in milliseconds for outbound tool calls\"\n },\n defaultHeaders: {\n type: \"object\",\n additionalProperties: {\n type: \"string\"\n },\n description: \"Additional headers added to every request\"\n }\n }\n },\n uiHints: {\n baseUrl: {\n label: \"Base URL\",\n placeholder: catalog.serverUrl ?? \"https://api.example.com\"\n },\n bearerToken: {\n label: \"Bearer Token\",\n sensitive: true\n },\n apiKey: {\n label: \"API Key\",\n sensitive: true\n },\n apiKeyHeader: {\n label: \"API Key Header\"\n },\n timeoutMs: {\n label: \"Timeout (ms)\"\n }\n }\n })}\\n`;\n\nexport const renderPluginModule = (catalog: OpenClawPluginCatalog): string =>\n `import { createOpenApiPlugin } from \"@redonvn/open-claw-sdk\";\n\nexport const catalog = ${serialize(catalog)} as const;\n\nexport default createOpenApiPlugin(catalog);\n`;\n\nexport const renderCatalogFile = (catalog: OpenClawPluginCatalog): string =>\n `${serialize(catalog)}\\n`;\n\nconst ensureDir = async (dirPath: string): Promise<void> => {\n await fs.mkdir(dirPath, { recursive: true });\n};\n\nexport const writeGeneratedPlugin = async (\n catalog: OpenClawPluginCatalog,\n outDir: string\n): Promise<GeneratedPluginFiles> => {\n await ensureDir(outDir);\n\n const manifestPath = path.join(outDir, \"openclaw.plugin.json\");\n const indexPath = path.join(outDir, \"index.ts\");\n const catalogPath = path.join(outDir, \"tool-catalog.json\");\n\n await Promise.all([\n fs.writeFile(manifestPath, renderPluginManifest(catalog), \"utf8\"),\n fs.writeFile(indexPath, renderPluginModule(catalog), \"utf8\"),\n fs.writeFile(catalogPath, renderCatalogFile(catalog), \"utf8\")\n ]);\n\n return { manifestPath, indexPath, catalogPath };\n};\n\nexport const generatePluginFromOpenApi = async (\n options: GeneratePluginOptions\n): Promise<{ catalog: OpenClawPluginCatalog; files: GeneratedPluginFiles }> => {\n const document = await loadOpenApiDocument(options.input);\n const convertOptions: ConvertOpenApiOptions = {\n pluginId: options.pluginId,\n pluginName: options.pluginName,\n toolPrefix: options.toolPrefix,\n optional: options.optional,\n includeHeaders: options.includeHeaders,\n defaultServerUrl: options.defaultServerUrl\n };\n const catalog = convertOpenApiToTools(document, convertOptions);\n const files = await writeGeneratedPlugin(catalog, options.outDir);\n\n return { catalog, files };\n};\n","import { promises as fs } from \"node:fs\";\nimport {\n ConvertOpenApiOptions,\n JsonSchema,\n OpenApiDocument,\n OpenApiOperationObject,\n OpenClawPluginCatalog,\n OpenClawToolDefinition\n} from \"./types\";\nimport {\n AUTH_HEADER_NAMES,\n HTTP_METHODS,\n buildOperationId,\n buildToolName,\n compactObject,\n dedupeParameters,\n hasSchemaContent,\n pickContentSchema,\n toTitleCase\n} from \"./utils\";\n\nconst isHttpUrl = (value: string): boolean => /^https?:\\/\\//i.test(value);\n\nconst readUrl = async (url: string): Promise<string> => {\n const response = await fetch(url);\n\n if (!response.ok) {\n throw new Error(`Unable to load OpenAPI document from ${url}: ${response.status} ${response.statusText}`);\n }\n\n return response.text();\n};\n\nexport const loadOpenApiDocument = async (source: string): Promise<OpenApiDocument> => {\n const raw = isHttpUrl(source)\n ? await readUrl(source)\n : await fs.readFile(source, \"utf8\");\n\n const document = JSON.parse(raw) as OpenApiDocument;\n\n if (!document.openapi || !document.paths) {\n throw new Error(\"Invalid OpenAPI document: missing `openapi` or `paths`.\");\n }\n\n return document;\n};\n\nconst cloneJsonSchema = (value: JsonSchema): JsonSchema => JSON.parse(JSON.stringify(value)) as JsonSchema;\n\nconst resolveRefName = (ref: string): string => ref.split(\"/\").pop() ?? \"UnknownSchema\";\n\nconst resolveSchemaRef = (\n document: OpenApiDocument,\n ref: string\n): import(\"./types\").OpenApiSchemaObject | undefined => {\n const schemaName = resolveRefName(ref);\n return document.components?.schemas?.[schemaName];\n};\n\nexport const openApiSchemaToJsonSchema = (\n schema: import(\"./types\").OpenApiSchemaObject | undefined,\n document: OpenApiDocument,\n seen = new Set<string>()\n): JsonSchema => {\n if (!schema) {\n return { type: \"object\", additionalProperties: true };\n }\n\n if (schema.$ref) {\n if (seen.has(schema.$ref)) {\n return { type: \"object\", additionalProperties: true };\n }\n\n const resolved = resolveSchemaRef(document, schema.$ref);\n\n if (!resolved) {\n return { type: \"object\", additionalProperties: true };\n }\n\n const nextSeen = new Set(seen);\n nextSeen.add(schema.$ref);\n return openApiSchemaToJsonSchema(resolved, document, nextSeen);\n }\n\n const jsonSchema: JsonSchema = compactObject({\n type: Array.isArray(schema.type) ? [...schema.type] : schema.type,\n description: schema.description,\n default: schema.default,\n enum: schema.enum ? [...schema.enum] : undefined\n });\n\n if (schema.oneOf?.length) {\n jsonSchema.oneOf = schema.oneOf.map((item) => openApiSchemaToJsonSchema(item, document, seen));\n }\n\n if (schema.anyOf?.length) {\n jsonSchema.anyOf = schema.anyOf.map((item) => openApiSchemaToJsonSchema(item, document, seen));\n }\n\n if (schema.allOf?.length) {\n jsonSchema.allOf = schema.allOf.map((item) => openApiSchemaToJsonSchema(item, document, seen));\n }\n\n if (schema.items) {\n jsonSchema.items = openApiSchemaToJsonSchema(schema.items, document, seen);\n }\n\n if (schema.properties) {\n jsonSchema.properties = Object.fromEntries(\n Object.entries(schema.properties).map(([key, value]) => [\n key,\n openApiSchemaToJsonSchema(value, document, seen)\n ])\n );\n }\n\n if (schema.required?.length) {\n jsonSchema.required = [...schema.required];\n }\n\n if (schema.additionalProperties !== undefined) {\n jsonSchema.additionalProperties =\n schema.additionalProperties === true || schema.additionalProperties === false\n ? schema.additionalProperties\n : openApiSchemaToJsonSchema(schema.additionalProperties, document, seen);\n }\n\n if (schema.nullable) {\n const currentType = jsonSchema.type;\n\n if (Array.isArray(currentType)) {\n jsonSchema.type = currentType.includes(\"null\") ? currentType : [...currentType, \"null\"];\n } else if (currentType) {\n jsonSchema.type = currentType === \"null\" ? \"null\" : [currentType, \"null\"];\n } else {\n jsonSchema.type = [\"object\", \"null\"];\n }\n }\n\n return jsonSchema;\n};\n\nconst buildParameterSection = (\n sectionName: string,\n parameters: import(\"./types\").OpenApiParameterObject[],\n document: OpenApiDocument\n): { name: string; schema: JsonSchema; required: boolean } | null => {\n if (!parameters.length) {\n return null;\n }\n\n const properties: Record<string, JsonSchema> = {};\n const required: string[] = [];\n\n for (const parameter of parameters) {\n properties[parameter.name] = compactObject({\n ...openApiSchemaToJsonSchema(parameter.schema, document),\n description: parameter.description ?? parameter.schema?.description\n });\n\n if (parameter.required) {\n required.push(parameter.name);\n }\n }\n\n return {\n name: sectionName,\n required: required.length > 0,\n schema: compactObject({\n type: \"object\",\n properties,\n required: required.length ? required : undefined,\n additionalProperties: false\n })\n };\n};\n\nconst buildToolParameters = (\n document: OpenApiDocument,\n path: string,\n operation: OpenApiOperationObject,\n options: ConvertOpenApiOptions,\n pathParameters: import(\"./types\").OpenApiParameterObject[],\n queryParameters: import(\"./types\").OpenApiParameterObject[],\n headerParameters: import(\"./types\").OpenApiParameterObject[]\n): JsonSchema => {\n const requestBodySchema = pickContentSchema(operation.requestBody?.content);\n const properties: Record<string, JsonSchema> = {};\n const required: string[] = [];\n\n const sections = [\n buildParameterSection(\"path\", pathParameters, document),\n buildParameterSection(\"query\", queryParameters, document),\n options.includeHeaders ? buildParameterSection(\"headers\", headerParameters, document) : null\n ].filter((value): value is { name: string; schema: JsonSchema; required: boolean } => Boolean(value));\n\n for (const section of sections) {\n if (hasSchemaContent(section.schema)) {\n properties[section.name] = section.schema;\n if (section.required) {\n required.push(section.name);\n }\n }\n }\n\n if (requestBodySchema) {\n properties.body = openApiSchemaToJsonSchema(requestBodySchema, document);\n if (operation.requestBody?.required) {\n required.push(\"body\");\n }\n }\n\n return compactObject({\n type: \"object\",\n properties,\n required: required.length ? required : undefined,\n additionalProperties: false,\n description: `${operation.summary ?? operation.operationId ?? `${path} request`} tool arguments`\n });\n};\n\nconst buildToolDescription = (path: string, method: string, operation: OpenApiOperationObject): string => {\n const summary = operation.summary?.trim();\n const description = operation.description?.trim();\n\n if (summary && description && description !== summary) {\n return `${summary}. ${description}`;\n }\n\n if (summary) {\n return summary;\n }\n\n if (description) {\n return description;\n }\n\n return `${method.toUpperCase()} ${path}`;\n};\n\nconst buildToolDefinition = (\n document: OpenApiDocument,\n path: string,\n method: import(\"./types\").HttpMethod,\n operation: OpenApiOperationObject,\n options: ConvertOpenApiOptions,\n pathParameters: import(\"./types\").OpenApiParameterObject[],\n queryParameters: import(\"./types\").OpenApiParameterObject[],\n headerParameters: import(\"./types\").OpenApiParameterObject[]\n): OpenClawToolDefinition => {\n const operationId = buildOperationId(method, path, operation.operationId);\n\n return {\n name: buildToolName(options.toolPrefix, operationId),\n description: buildToolDescription(path, method, operation),\n method: method.toUpperCase() as Uppercase<typeof method>,\n path,\n operationId,\n parameters: buildToolParameters(\n document,\n path,\n operation,\n options,\n pathParameters,\n queryParameters,\n headerParameters\n ),\n tags: operation.tags ?? []\n };\n};\n\nexport const convertOpenApiToTools = (\n document: OpenApiDocument,\n options: ConvertOpenApiOptions\n): OpenClawPluginCatalog => {\n const tools: OpenClawToolDefinition[] = [];\n\n for (const [path, pathItem] of Object.entries(document.paths)) {\n for (const method of HTTP_METHODS) {\n const operation = pathItem[method];\n\n if (!operation) {\n continue;\n }\n\n const parameters = dedupeParameters(pathItem.parameters, operation.parameters);\n const pathParameters = parameters.filter((parameter) => parameter.in === \"path\");\n const queryParameters = parameters.filter((parameter) => parameter.in === \"query\");\n const headerParameters = parameters.filter(\n (parameter) =>\n parameter.in === \"header\" &&\n !AUTH_HEADER_NAMES.has(parameter.name.toLowerCase())\n );\n\n tools.push(\n buildToolDefinition(\n document,\n path,\n method,\n operation,\n options,\n pathParameters,\n queryParameters,\n headerParameters\n )\n );\n }\n }\n\n tools.sort((left, right) => left.name.localeCompare(right.name));\n\n return {\n pluginId: options.pluginId,\n pluginName: options.pluginName ?? toTitleCase(options.pluginId),\n description:\n document.info?.description?.trim() ??\n `Generated OpenClaw tool plugin for ${document.info?.title ?? options.pluginId}`,\n serverUrl: options.defaultServerUrl ?? document.servers?.[0]?.url,\n optional: options.optional ?? true,\n tools\n };\n};\n","import { HttpMethod, JsonSchema, OpenApiParameterObject } from \"./types\";\n\nexport const HTTP_METHODS: HttpMethod[] = [\n \"get\",\n \"post\",\n \"put\",\n \"patch\",\n \"delete\",\n \"options\",\n \"head\"\n];\n\nexport const AUTH_HEADER_NAMES = new Set([\n \"authorization\",\n \"x-api-key\",\n \"api-key\",\n \"dt-jwt\"\n]);\n\nexport const sanitizeIdentifier = (value: string): string =>\n value\n .trim()\n .replace(/[^a-zA-Z0-9]+/g, \"_\")\n .replace(/^_+|_+$/g, \"\")\n .replace(/_{2,}/g, \"_\")\n .toLowerCase() || \"tool\";\n\nexport const toTitleCase = (value: string): string =>\n value\n .split(/[^a-zA-Z0-9]+/)\n .filter(Boolean)\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join(\" \");\n\nexport const buildToolName = (toolPrefix: string | undefined, rawName: string): string => {\n const base = sanitizeIdentifier(rawName);\n const prefix = sanitizeIdentifier(toolPrefix ?? \"\");\n return prefix ? `${prefix}_${base}` : base;\n};\n\nexport const buildOperationId = (method: HttpMethod, path: string, operationId?: string): string => {\n if (operationId?.trim()) {\n return sanitizeIdentifier(operationId);\n }\n\n const pathPart = path\n .replace(/\\{([^}]+)\\}/g, \"by_$1\")\n .replace(/\\/+/g, \"_\");\n\n return sanitizeIdentifier(`${method}_${pathPart}`);\n};\n\nexport const pickContentSchema = (\n content: Record<string, { schema?: import(\"./types\").OpenApiSchemaObject | undefined }> | undefined\n): import(\"./types\").OpenApiSchemaObject | undefined =>\n content?.[\"application/json\"]?.schema ??\n content?.[\"application/*+json\"]?.schema ??\n Object.values(content ?? {})[0]?.schema;\n\nexport const dedupeParameters = (\n pathLevel: OpenApiParameterObject[] | undefined,\n operationLevel: OpenApiParameterObject[] | undefined\n): OpenApiParameterObject[] => {\n const byKey = new Map<string, OpenApiParameterObject>();\n\n for (const param of [...(pathLevel ?? []), ...(operationLevel ?? [])]) {\n byKey.set(`${param.in}:${param.name}`, param);\n }\n\n return [...byKey.values()];\n};\n\nexport const compactObject = <T extends Record<string, unknown>>(value: T): T => {\n const output = {} as T;\n\n for (const [key, item] of Object.entries(value)) {\n if (item !== undefined) {\n output[key as keyof T] = item as T[keyof T];\n }\n }\n\n return output;\n};\n\nexport const hasSchemaContent = (schema: JsonSchema | undefined): boolean =>\n Boolean(\n schema &&\n ((schema.properties && Object.keys(schema.properties).length > 0) ||\n (schema.required && schema.required.length > 0) ||\n schema.type ||\n schema.oneOf ||\n schema.anyOf ||\n schema.allOf)\n );\n","import { CreatePluginFactoryOptions, OpenClawApiLike, OpenClawPluginCatalog, PluginRuntimeConfig } from \"./types\";\n\nconst encodeQueryValue = (value: unknown): string => {\n if (value === null) {\n return \"null\";\n }\n\n if (typeof value === \"string\") {\n return value;\n }\n\n if (typeof value === \"number\" || typeof value === \"boolean\") {\n return String(value);\n }\n\n return JSON.stringify(value);\n};\n\nconst applyPathParams = (pathTemplate: string, pathParams: Record<string, unknown> | undefined): string =>\n pathTemplate.replace(/\\{([^}]+)\\}/g, (_, key: string) => {\n const raw = pathParams?.[key];\n\n if (raw === undefined || raw === null) {\n throw new Error(`Missing required path parameter: ${key}`);\n }\n\n return encodeURIComponent(String(raw));\n });\n\nconst appendQueryParams = (url: URL, query: Record<string, unknown> | undefined): void => {\n if (!query) {\n return;\n }\n\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined) {\n continue;\n }\n\n if (Array.isArray(value)) {\n for (const item of value) {\n url.searchParams.append(key, encodeQueryValue(item));\n }\n continue;\n }\n\n url.searchParams.set(key, encodeQueryValue(value));\n }\n};\n\nconst resolvePluginConfig = (api: OpenClawApiLike, pluginId: string): PluginRuntimeConfig =>\n api.config?.plugins?.entries?.[pluginId]?.config ?? {};\n\nconst buildHeaders = (\n runtimeConfig: PluginRuntimeConfig,\n requestHeaders: Record<string, unknown> | undefined,\n hasBody: boolean\n): Headers => {\n const headers = new Headers();\n\n for (const [key, value] of Object.entries(runtimeConfig.defaultHeaders ?? {})) {\n headers.set(key, value);\n }\n\n if (runtimeConfig.bearerToken) {\n headers.set(\"authorization\", `Bearer ${runtimeConfig.bearerToken}`);\n } else if (runtimeConfig.apiKey) {\n headers.set(runtimeConfig.apiKeyHeader ?? \"x-api-key\", runtimeConfig.apiKey);\n }\n\n for (const [key, value] of Object.entries(requestHeaders ?? {})) {\n if (value !== undefined && value !== null) {\n headers.set(key, String(value));\n }\n }\n\n if (hasBody && !headers.has(\"content-type\")) {\n headers.set(\"content-type\", \"application/json\");\n }\n\n return headers;\n};\n\nconst parseResponse = async (response: Response): Promise<unknown> => {\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n\n if (contentType.includes(\"application/json\")) {\n return response.json();\n }\n\n return response.text();\n};\n\nconst formatToolResult = (payload: unknown): { content: Array<{ type: \"text\"; text: string }> } => ({\n content: [\n {\n type: \"text\",\n text: typeof payload === \"string\" ? payload : JSON.stringify(payload, null, 2)\n }\n ]\n});\n\nexport const createOpenApiPlugin = (\n catalog: OpenClawPluginCatalog,\n options?: CreatePluginFactoryOptions\n) => {\n return function register(api: OpenClawApiLike): void {\n for (const tool of catalog.tools) {\n api.registerTool(\n {\n name: tool.name,\n description: tool.description,\n parameters: tool.parameters,\n execute: async (_id, params) => {\n const runtimeConfig = resolvePluginConfig(api, catalog.pluginId);\n const baseUrl = runtimeConfig.baseUrl ?? catalog.serverUrl;\n\n if (!baseUrl) {\n throw new Error(\n `Missing baseUrl for plugin ${catalog.pluginId}. Set plugins.entries.${catalog.pluginId}.config.baseUrl.`\n );\n }\n\n const input = (params ?? {}) as {\n path?: Record<string, unknown>;\n query?: Record<string, unknown>;\n headers?: Record<string, unknown>;\n body?: unknown;\n };\n\n const finalUrl = new URL(\n applyPathParams(tool.path, input.path),\n baseUrl.endsWith(\"/\") ? baseUrl : `${baseUrl}/`\n );\n\n appendQueryParams(finalUrl, input.query);\n\n const controller = new AbortController();\n const timeoutMs = runtimeConfig.timeoutMs ?? options?.timeoutMs;\n const timeout = timeoutMs\n ? setTimeout(() => controller.abort(), timeoutMs)\n : undefined;\n\n try {\n const hasBody = input.body !== undefined;\n const requestInit: RequestInit = {\n method: tool.method,\n headers: buildHeaders(runtimeConfig, input.headers, hasBody),\n signal: controller.signal\n };\n\n if (hasBody) {\n requestInit.body = JSON.stringify(input.body);\n }\n\n const response = await fetch(finalUrl, requestInit);\n\n const payload = await parseResponse(response);\n\n if (!response.ok) {\n return formatToolResult({\n ok: false,\n status: response.status,\n statusText: response.statusText,\n data: payload\n });\n }\n\n return formatToolResult(payload);\n } finally {\n if (timeout) {\n clearTimeout(timeout);\n }\n }\n }\n },\n { optional: catalog.optional ?? true }\n );\n }\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,kBAA+B;AAC/B,uBAAiB;;;ACDjB,qBAA+B;;;ACExB,IAAM,eAA6B;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,IAAM,oBAAoB,oBAAI,IAAI;AAAA,EACvC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEM,IAAM,qBAAqB,CAAC,UACjC,MACG,KAAK,EACL,QAAQ,kBAAkB,GAAG,EAC7B,QAAQ,YAAY,EAAE,EACtB,QAAQ,UAAU,GAAG,EACrB,YAAY,KAAK;AAEf,IAAM,cAAc,CAAC,UAC1B,MACG,MAAM,eAAe,EACrB,OAAO,OAAO,EACd,IAAI,CAAC,SAAS,KAAK,OAAO,CAAC,EAAE,YAAY,IAAI,KAAK,MAAM,CAAC,CAAC,EAC1D,KAAK,GAAG;AAEN,IAAM,gBAAg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