@dexto/agent-management 1.5.6 → 1.5.7

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 (128) hide show
  1. package/dist/config/config-enrichment.cjs +70 -20
  2. package/dist/config/config-enrichment.d.ts +10 -2
  3. package/dist/config/config-enrichment.d.ts.map +1 -1
  4. package/dist/config/config-enrichment.js +74 -20
  5. package/dist/config/discover-prompts.cjs +1 -1
  6. package/dist/config/discover-prompts.d.ts +11 -11
  7. package/dist/config/discover-prompts.d.ts.map +1 -1
  8. package/dist/config/discover-prompts.js +1 -1
  9. package/dist/config/loader.cjs +31 -13
  10. package/dist/config/loader.d.ts.map +1 -1
  11. package/dist/config/loader.js +31 -13
  12. package/dist/index.cjs +65 -0
  13. package/dist/index.d.ts +3 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +66 -0
  16. package/dist/models/custom-models.cjs +2 -1
  17. package/dist/models/custom-models.d.ts +7 -6
  18. package/dist/models/custom-models.d.ts.map +1 -1
  19. package/dist/models/custom-models.js +2 -1
  20. package/dist/plugins/discover-plugins.cjs +176 -0
  21. package/dist/plugins/discover-plugins.d.ts +39 -0
  22. package/dist/plugins/discover-plugins.d.ts.map +1 -0
  23. package/dist/plugins/discover-plugins.js +140 -0
  24. package/dist/plugins/discover-skills.cjs +89 -0
  25. package/dist/plugins/discover-skills.d.ts +46 -0
  26. package/dist/plugins/discover-skills.d.ts.map +1 -0
  27. package/dist/plugins/discover-skills.js +54 -0
  28. package/dist/plugins/error-codes.cjs +47 -0
  29. package/dist/plugins/error-codes.d.ts +24 -0
  30. package/dist/plugins/error-codes.d.ts.map +1 -0
  31. package/dist/plugins/error-codes.js +23 -0
  32. package/dist/plugins/errors.cjs +197 -0
  33. package/dist/plugins/errors.d.ts +68 -0
  34. package/dist/plugins/errors.d.ts.map +1 -0
  35. package/dist/plugins/errors.js +173 -0
  36. package/dist/plugins/index.cjs +144 -0
  37. package/dist/plugins/index.d.ts +23 -0
  38. package/dist/plugins/index.d.ts.map +1 -0
  39. package/dist/plugins/index.js +115 -0
  40. package/dist/plugins/install-plugin.cjs +211 -0
  41. package/dist/plugins/install-plugin.d.ts +47 -0
  42. package/dist/plugins/install-plugin.d.ts.map +1 -0
  43. package/dist/plugins/install-plugin.js +173 -0
  44. package/dist/plugins/list-plugins.cjs +134 -0
  45. package/dist/plugins/list-plugins.d.ts +26 -0
  46. package/dist/plugins/list-plugins.d.ts.map +1 -0
  47. package/dist/plugins/list-plugins.js +99 -0
  48. package/dist/plugins/load-plugin.cjs +197 -0
  49. package/dist/plugins/load-plugin.d.ts +20 -0
  50. package/dist/plugins/load-plugin.d.ts.map +1 -0
  51. package/dist/plugins/load-plugin.js +163 -0
  52. package/dist/plugins/marketplace/error-codes.cjs +45 -0
  53. package/dist/plugins/marketplace/error-codes.d.ts +21 -0
  54. package/dist/plugins/marketplace/error-codes.d.ts.map +1 -0
  55. package/dist/plugins/marketplace/error-codes.js +21 -0
  56. package/dist/plugins/marketplace/errors.cjs +188 -0
  57. package/dist/plugins/marketplace/errors.d.ts +64 -0
  58. package/dist/plugins/marketplace/errors.d.ts.map +1 -0
  59. package/dist/plugins/marketplace/errors.js +164 -0
  60. package/dist/plugins/marketplace/index.cjs +95 -0
  61. package/dist/plugins/marketplace/index.d.ts +14 -0
  62. package/dist/plugins/marketplace/index.d.ts.map +1 -0
  63. package/dist/plugins/marketplace/index.js +74 -0
  64. package/dist/plugins/marketplace/install-from-marketplace.cjs +152 -0
  65. package/dist/plugins/marketplace/install-from-marketplace.d.ts +25 -0
  66. package/dist/plugins/marketplace/install-from-marketplace.d.ts.map +1 -0
  67. package/dist/plugins/marketplace/install-from-marketplace.js +120 -0
  68. package/dist/plugins/marketplace/operations.cjs +374 -0
  69. package/dist/plugins/marketplace/operations.d.ts +43 -0
  70. package/dist/plugins/marketplace/operations.d.ts.map +1 -0
  71. package/dist/plugins/marketplace/operations.js +339 -0
  72. package/dist/plugins/marketplace/registry.cjs +166 -0
  73. package/dist/plugins/marketplace/registry.d.ts +72 -0
  74. package/dist/plugins/marketplace/registry.d.ts.map +1 -0
  75. package/dist/plugins/marketplace/registry.js +119 -0
  76. package/dist/plugins/marketplace/schemas.cjs +79 -0
  77. package/dist/plugins/marketplace/schemas.d.ts +260 -0
  78. package/dist/plugins/marketplace/schemas.d.ts.map +1 -0
  79. package/dist/plugins/marketplace/schemas.js +49 -0
  80. package/dist/plugins/marketplace/types.cjs +16 -0
  81. package/dist/plugins/marketplace/types.d.ts +156 -0
  82. package/dist/plugins/marketplace/types.d.ts.map +1 -0
  83. package/dist/plugins/marketplace/types.js +0 -0
  84. package/dist/plugins/schemas.cjs +74 -0
  85. package/dist/plugins/schemas.d.ts +262 -0
  86. package/dist/plugins/schemas.d.ts.map +1 -0
  87. package/dist/plugins/schemas.js +46 -0
  88. package/dist/plugins/types.cjs +16 -0
  89. package/dist/plugins/types.d.ts +186 -0
  90. package/dist/plugins/types.d.ts.map +1 -0
  91. package/dist/plugins/types.js +0 -0
  92. package/dist/plugins/uninstall-plugin.cjs +133 -0
  93. package/dist/plugins/uninstall-plugin.d.ts +24 -0
  94. package/dist/plugins/uninstall-plugin.d.ts.map +1 -0
  95. package/dist/plugins/uninstall-plugin.js +99 -0
  96. package/dist/plugins/validate-plugin.cjs +180 -0
  97. package/dist/plugins/validate-plugin.d.ts +53 -0
  98. package/dist/plugins/validate-plugin.d.ts.map +1 -0
  99. package/dist/plugins/validate-plugin.js +145 -0
  100. package/dist/preferences/schemas.d.ts +12 -12
  101. package/dist/runtime/AgentRuntime.cjs +1 -2
  102. package/dist/runtime/AgentRuntime.d.ts.map +1 -1
  103. package/dist/runtime/AgentRuntime.js +1 -2
  104. package/dist/tool-provider/llm-resolution.cjs +74 -0
  105. package/dist/tool-provider/llm-resolution.d.ts +51 -0
  106. package/dist/tool-provider/llm-resolution.d.ts.map +1 -0
  107. package/dist/tool-provider/llm-resolution.js +50 -0
  108. package/dist/tool-provider/runtime-service.cjs +158 -23
  109. package/dist/tool-provider/runtime-service.d.ts +32 -2
  110. package/dist/tool-provider/runtime-service.d.ts.map +1 -1
  111. package/dist/tool-provider/runtime-service.js +158 -23
  112. package/dist/tool-provider/tool-provider.cjs +2 -0
  113. package/dist/tool-provider/tool-provider.d.ts.map +1 -1
  114. package/dist/tool-provider/tool-provider.js +2 -0
  115. package/dist/tool-provider/types.d.ts +2 -0
  116. package/dist/tool-provider/types.d.ts.map +1 -1
  117. package/dist/utils/api-key-resolver.cjs +5 -2
  118. package/dist/utils/api-key-resolver.d.ts.map +1 -1
  119. package/dist/utils/api-key-resolver.js +5 -2
  120. package/dist/utils/dexto-auth.cjs +83 -0
  121. package/dist/utils/dexto-auth.d.ts +23 -0
  122. package/dist/utils/dexto-auth.d.ts.map +1 -0
  123. package/dist/utils/dexto-auth.js +57 -0
  124. package/dist/utils/feature-flags.cjs +30 -0
  125. package/dist/utils/feature-flags.d.ts +21 -0
  126. package/dist/utils/feature-flags.d.ts.map +1 -0
  127. package/dist/utils/feature-flags.js +6 -0
  128. package/package.json +2 -2
@@ -0,0 +1,152 @@
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
+ var install_from_marketplace_exports = {};
30
+ __export(install_from_marketplace_exports, {
31
+ installPluginFromMarketplace: () => installPluginFromMarketplace,
32
+ parsePluginSpec: () => parsePluginSpec,
33
+ searchMarketplacePlugins: () => searchMarketplacePlugins
34
+ });
35
+ module.exports = __toCommonJS(install_from_marketplace_exports);
36
+ var path = __toESM(require("path"), 1);
37
+ var import_fs = require("fs");
38
+ var import_child_process = require("child_process");
39
+ var import_path = require("../../utils/path.js");
40
+ var import_registry = require("./registry.js");
41
+ var import_operations = require("./operations.js");
42
+ var import_errors = require("./errors.js");
43
+ var import_install_plugin = require("../install-plugin.js");
44
+ function parsePluginSpec(spec) {
45
+ const atIndex = spec.lastIndexOf("@");
46
+ if (atIndex <= 0) {
47
+ return { pluginName: spec };
48
+ }
49
+ return {
50
+ pluginName: spec.substring(0, atIndex),
51
+ marketplace: spec.substring(atIndex + 1)
52
+ };
53
+ }
54
+ function getGitSha(dir) {
55
+ try {
56
+ const result = (0, import_child_process.execSync)("git rev-parse HEAD", {
57
+ cwd: dir,
58
+ encoding: "utf-8",
59
+ stdio: ["pipe", "pipe", "pipe"]
60
+ });
61
+ return result.trim();
62
+ } catch {
63
+ return void 0;
64
+ }
65
+ }
66
+ function getShortSha(sha) {
67
+ if (!sha) return "unknown";
68
+ return sha.substring(0, 8);
69
+ }
70
+ async function installPluginFromMarketplace(pluginSpec, options = {}) {
71
+ const { scope = "user", projectPath, force = false } = options;
72
+ const warnings = [];
73
+ const { pluginName, marketplace: specifiedMarketplace } = parsePluginSpec(pluginSpec);
74
+ let plugin = null;
75
+ if (specifiedMarketplace) {
76
+ const marketplaceEntry2 = (0, import_registry.getMarketplaceEntry)(specifiedMarketplace);
77
+ if (!marketplaceEntry2) {
78
+ throw import_errors.MarketplaceError.installMarketplaceNotFound(specifiedMarketplace);
79
+ }
80
+ const plugins = (0, import_operations.scanMarketplacePlugins)(
81
+ marketplaceEntry2.installLocation,
82
+ marketplaceEntry2.name
83
+ );
84
+ plugin = plugins.find((p) => p.name.toLowerCase() === pluginName.toLowerCase()) || null;
85
+ if (!plugin) {
86
+ throw import_errors.MarketplaceError.installPluginNotFound(pluginName, specifiedMarketplace);
87
+ }
88
+ } else {
89
+ plugin = (0, import_operations.findPluginInMarketplaces)(pluginName);
90
+ if (!plugin) {
91
+ throw import_errors.MarketplaceError.installPluginNotFound(pluginName);
92
+ }
93
+ warnings.push(`Found plugin in marketplace: ${plugin.marketplace}`);
94
+ }
95
+ const marketplaceEntry = (0, import_registry.getMarketplaceEntry)(plugin.marketplace);
96
+ let gitCommitSha;
97
+ if (marketplaceEntry) {
98
+ gitCommitSha = getGitSha(marketplaceEntry.installLocation);
99
+ }
100
+ const cacheDir = (0, import_registry.getMarketplaceCacheDir)();
101
+ const shortSha = getShortSha(gitCommitSha);
102
+ const cachePath = path.join(cacheDir, plugin.marketplace, plugin.name, shortSha);
103
+ if (!(0, import_fs.existsSync)(cachePath)) {
104
+ try {
105
+ (0, import_fs.mkdirSync)(cachePath, { recursive: true });
106
+ await (0, import_path.copyDirectory)(plugin.sourcePath, cachePath);
107
+ } catch (error) {
108
+ throw import_errors.MarketplaceError.installCopyFailed(
109
+ pluginName,
110
+ error instanceof Error ? error.message : String(error)
111
+ );
112
+ }
113
+ }
114
+ const installOptions = {
115
+ scope,
116
+ force,
117
+ ...projectPath !== void 0 && { projectPath }
118
+ };
119
+ const installResult = await (0, import_install_plugin.installPluginFromPath)(cachePath, installOptions);
120
+ return {
121
+ success: installResult.success,
122
+ pluginName: installResult.pluginName,
123
+ marketplace: plugin.marketplace,
124
+ installPath: installResult.installPath,
125
+ ...gitCommitSha !== void 0 && { gitCommitSha },
126
+ warnings: [...warnings, ...installResult.warnings]
127
+ };
128
+ }
129
+ function searchMarketplacePlugins(query, marketplaceName) {
130
+ const lowerQuery = query.toLowerCase();
131
+ let plugins;
132
+ if (marketplaceName) {
133
+ const entry = (0, import_registry.getMarketplaceEntry)(marketplaceName);
134
+ if (!entry || !(0, import_fs.existsSync)(entry.installLocation)) {
135
+ return [];
136
+ }
137
+ plugins = (0, import_operations.scanMarketplacePlugins)(entry.installLocation, entry.name);
138
+ } else {
139
+ plugins = (0, import_operations.listAllMarketplacePlugins)();
140
+ }
141
+ return plugins.filter((p) => {
142
+ const nameMatch = p.name.toLowerCase().includes(lowerQuery);
143
+ const descMatch = p.description?.toLowerCase().includes(lowerQuery);
144
+ return nameMatch || descMatch;
145
+ });
146
+ }
147
+ // Annotate the CommonJS export names for ESM import in node:
148
+ 0 && (module.exports = {
149
+ installPluginFromMarketplace,
150
+ parsePluginSpec,
151
+ searchMarketplacePlugins
152
+ });
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Plugin Installation from Marketplace
3
+ *
4
+ * Handles installing plugins from registered marketplaces.
5
+ */
6
+ import type { MarketplaceInstallOptions, MarketplaceInstallResult, MarketplacePlugin } from './types.js';
7
+ /**
8
+ * Parse a plugin spec (name or name@marketplace)
9
+ */
10
+ export declare function parsePluginSpec(spec: string): {
11
+ pluginName: string;
12
+ marketplace?: string;
13
+ };
14
+ /**
15
+ * Install a plugin from a marketplace
16
+ *
17
+ * @param pluginSpec Plugin spec in format "name" or "name@marketplace"
18
+ * @param options Installation options
19
+ */
20
+ export declare function installPluginFromMarketplace(pluginSpec: string, options?: MarketplaceInstallOptions): Promise<MarketplaceInstallResult>;
21
+ /**
22
+ * Search for plugins by name pattern across all marketplaces
23
+ */
24
+ export declare function searchMarketplacePlugins(query: string, marketplaceName?: string): MarketplacePlugin[];
25
+ //# sourceMappingURL=install-from-marketplace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install-from-marketplace.d.ts","sourceRoot":"","sources":["../../../src/plugins/marketplace/install-from-marketplace.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAcH,OAAO,KAAK,EACR,yBAAyB,EACzB,wBAAwB,EACxB,iBAAiB,EACpB,MAAM,YAAY,CAAC;AAGpB;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAY1F;AA0BD;;;;;GAKG;AACH,wBAAsB,4BAA4B,CAC9C,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,yBAA8B,GACxC,OAAO,CAAC,wBAAwB,CAAC,CAgFnC;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACpC,KAAK,EAAE,MAAM,EACb,eAAe,CAAC,EAAE,MAAM,GACzB,iBAAiB,EAAE,CAqBrB"}
@@ -0,0 +1,120 @@
1
+ import * as path from "path";
2
+ import { existsSync, mkdirSync } from "fs";
3
+ import { execSync } from "child_process";
4
+ import { copyDirectory } from "../../utils/path.js";
5
+ import { getMarketplaceCacheDir, getMarketplaceEntry } from "./registry.js";
6
+ import {
7
+ findPluginInMarketplaces,
8
+ scanMarketplacePlugins,
9
+ listAllMarketplacePlugins
10
+ } from "./operations.js";
11
+ import { MarketplaceError } from "./errors.js";
12
+ import { installPluginFromPath } from "../install-plugin.js";
13
+ function parsePluginSpec(spec) {
14
+ const atIndex = spec.lastIndexOf("@");
15
+ if (atIndex <= 0) {
16
+ return { pluginName: spec };
17
+ }
18
+ return {
19
+ pluginName: spec.substring(0, atIndex),
20
+ marketplace: spec.substring(atIndex + 1)
21
+ };
22
+ }
23
+ function getGitSha(dir) {
24
+ try {
25
+ const result = execSync("git rev-parse HEAD", {
26
+ cwd: dir,
27
+ encoding: "utf-8",
28
+ stdio: ["pipe", "pipe", "pipe"]
29
+ });
30
+ return result.trim();
31
+ } catch {
32
+ return void 0;
33
+ }
34
+ }
35
+ function getShortSha(sha) {
36
+ if (!sha) return "unknown";
37
+ return sha.substring(0, 8);
38
+ }
39
+ async function installPluginFromMarketplace(pluginSpec, options = {}) {
40
+ const { scope = "user", projectPath, force = false } = options;
41
+ const warnings = [];
42
+ const { pluginName, marketplace: specifiedMarketplace } = parsePluginSpec(pluginSpec);
43
+ let plugin = null;
44
+ if (specifiedMarketplace) {
45
+ const marketplaceEntry2 = getMarketplaceEntry(specifiedMarketplace);
46
+ if (!marketplaceEntry2) {
47
+ throw MarketplaceError.installMarketplaceNotFound(specifiedMarketplace);
48
+ }
49
+ const plugins = scanMarketplacePlugins(
50
+ marketplaceEntry2.installLocation,
51
+ marketplaceEntry2.name
52
+ );
53
+ plugin = plugins.find((p) => p.name.toLowerCase() === pluginName.toLowerCase()) || null;
54
+ if (!plugin) {
55
+ throw MarketplaceError.installPluginNotFound(pluginName, specifiedMarketplace);
56
+ }
57
+ } else {
58
+ plugin = findPluginInMarketplaces(pluginName);
59
+ if (!plugin) {
60
+ throw MarketplaceError.installPluginNotFound(pluginName);
61
+ }
62
+ warnings.push(`Found plugin in marketplace: ${plugin.marketplace}`);
63
+ }
64
+ const marketplaceEntry = getMarketplaceEntry(plugin.marketplace);
65
+ let gitCommitSha;
66
+ if (marketplaceEntry) {
67
+ gitCommitSha = getGitSha(marketplaceEntry.installLocation);
68
+ }
69
+ const cacheDir = getMarketplaceCacheDir();
70
+ const shortSha = getShortSha(gitCommitSha);
71
+ const cachePath = path.join(cacheDir, plugin.marketplace, plugin.name, shortSha);
72
+ if (!existsSync(cachePath)) {
73
+ try {
74
+ mkdirSync(cachePath, { recursive: true });
75
+ await copyDirectory(plugin.sourcePath, cachePath);
76
+ } catch (error) {
77
+ throw MarketplaceError.installCopyFailed(
78
+ pluginName,
79
+ error instanceof Error ? error.message : String(error)
80
+ );
81
+ }
82
+ }
83
+ const installOptions = {
84
+ scope,
85
+ force,
86
+ ...projectPath !== void 0 && { projectPath }
87
+ };
88
+ const installResult = await installPluginFromPath(cachePath, installOptions);
89
+ return {
90
+ success: installResult.success,
91
+ pluginName: installResult.pluginName,
92
+ marketplace: plugin.marketplace,
93
+ installPath: installResult.installPath,
94
+ ...gitCommitSha !== void 0 && { gitCommitSha },
95
+ warnings: [...warnings, ...installResult.warnings]
96
+ };
97
+ }
98
+ function searchMarketplacePlugins(query, marketplaceName) {
99
+ const lowerQuery = query.toLowerCase();
100
+ let plugins;
101
+ if (marketplaceName) {
102
+ const entry = getMarketplaceEntry(marketplaceName);
103
+ if (!entry || !existsSync(entry.installLocation)) {
104
+ return [];
105
+ }
106
+ plugins = scanMarketplacePlugins(entry.installLocation, entry.name);
107
+ } else {
108
+ plugins = listAllMarketplacePlugins();
109
+ }
110
+ return plugins.filter((p) => {
111
+ const nameMatch = p.name.toLowerCase().includes(lowerQuery);
112
+ const descMatch = p.description?.toLowerCase().includes(lowerQuery);
113
+ return nameMatch || descMatch;
114
+ });
115
+ }
116
+ export {
117
+ installPluginFromMarketplace,
118
+ parsePluginSpec,
119
+ searchMarketplacePlugins
120
+ };
@@ -0,0 +1,374 @@
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
+ var operations_exports = {};
30
+ __export(operations_exports, {
31
+ addMarketplace: () => addMarketplace,
32
+ deriveMarketplaceName: () => deriveMarketplaceName,
33
+ findPluginInMarketplaces: () => findPluginInMarketplaces,
34
+ listAllMarketplacePlugins: () => listAllMarketplacePlugins,
35
+ listMarketplaces: () => listMarketplaces,
36
+ parseMarketplaceSource: () => parseMarketplaceSource,
37
+ removeMarketplace: () => removeMarketplace,
38
+ scanMarketplacePlugins: () => scanMarketplacePlugins,
39
+ updateMarketplace: () => updateMarketplace
40
+ });
41
+ module.exports = __toCommonJS(operations_exports);
42
+ var path = __toESM(require("path"), 1);
43
+ var import_fs = require("fs");
44
+ var import_child_process = require("child_process");
45
+ var import_registry = require("./registry.js");
46
+ var import_errors = require("./errors.js");
47
+ var import_schemas = require("./schemas.js");
48
+ var import_validate_plugin = require("../validate-plugin.js");
49
+ function parseMarketplaceSource(source) {
50
+ const trimmed = source.trim();
51
+ if (trimmed.startsWith("/") || trimmed.startsWith("./") || trimmed.startsWith("../") || trimmed.startsWith("~/")) {
52
+ return { type: "local", value: trimmed };
53
+ }
54
+ if (trimmed.includes("://") || trimmed.endsWith(".git")) {
55
+ return { type: "git", value: trimmed };
56
+ }
57
+ const githubMatch = /^([a-zA-Z0-9_-]+)\/([a-zA-Z0-9_.-]+)$/.exec(trimmed);
58
+ if (githubMatch) {
59
+ return { type: "github", value: trimmed };
60
+ }
61
+ return { type: "git", value: trimmed };
62
+ }
63
+ function deriveMarketplaceName(source) {
64
+ switch (source.type) {
65
+ case "github": {
66
+ const parts = source.value.split("/");
67
+ return parts[parts.length - 1] ?? source.value;
68
+ }
69
+ case "git": {
70
+ const url = source.value.replace(/\.git$/, "");
71
+ const parts = url.split("/");
72
+ return parts[parts.length - 1] ?? "marketplace";
73
+ }
74
+ case "local": {
75
+ const resolved = source.value.startsWith("~") ? source.value.replace("~", process.env.HOME || "") : path.resolve(source.value);
76
+ return path.basename(resolved);
77
+ }
78
+ }
79
+ }
80
+ function getCloneUrl(source) {
81
+ switch (source.type) {
82
+ case "github":
83
+ return `https://github.com/${source.value}.git`;
84
+ case "git":
85
+ return source.value;
86
+ case "local":
87
+ throw new Error("Cannot clone local source");
88
+ }
89
+ }
90
+ function getGitSha(dir) {
91
+ try {
92
+ const result = (0, import_child_process.execSync)("git rev-parse HEAD", {
93
+ cwd: dir,
94
+ encoding: "utf-8",
95
+ stdio: ["pipe", "pipe", "pipe"]
96
+ });
97
+ return result.trim();
98
+ } catch {
99
+ return void 0;
100
+ }
101
+ }
102
+ async function addMarketplace(source, options = {}) {
103
+ const parsedSource = parseMarketplaceSource(source);
104
+ const name = options.name || deriveMarketplaceName(parsedSource);
105
+ const warnings = [];
106
+ const existing = (0, import_registry.getMarketplaceEntry)(name);
107
+ if (existing) {
108
+ throw import_errors.MarketplaceError.addAlreadyExists(name, existing.installLocation);
109
+ }
110
+ let installLocation;
111
+ if (parsedSource.type === "local") {
112
+ const localPath = parsedSource.value.startsWith("~") ? parsedSource.value.replace("~", process.env.HOME || "") : path.resolve(parsedSource.value);
113
+ if (!(0, import_fs.existsSync)(localPath)) {
114
+ throw import_errors.MarketplaceError.addLocalNotFound(localPath);
115
+ }
116
+ installLocation = localPath;
117
+ } else {
118
+ const marketplacesDir = (0, import_registry.getMarketplacesDir)();
119
+ installLocation = path.join(marketplacesDir, name);
120
+ const cloneUrl = getCloneUrl(parsedSource);
121
+ try {
122
+ (0, import_child_process.execSync)(`git clone "${cloneUrl}" "${installLocation}"`, {
123
+ encoding: "utf-8",
124
+ stdio: ["pipe", "pipe", "pipe"]
125
+ });
126
+ } catch (error) {
127
+ throw import_errors.MarketplaceError.addCloneFailed(
128
+ source,
129
+ error instanceof Error ? error.message : String(error)
130
+ );
131
+ }
132
+ }
133
+ const plugins = scanMarketplacePlugins(installLocation, name);
134
+ if (plugins.length === 0) {
135
+ warnings.push("No plugins found in marketplace");
136
+ }
137
+ const entry = {
138
+ name,
139
+ source: parsedSource,
140
+ installLocation,
141
+ lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
142
+ };
143
+ (0, import_registry.addMarketplaceEntry)(entry);
144
+ return {
145
+ success: true,
146
+ name,
147
+ pluginCount: plugins.length,
148
+ warnings
149
+ };
150
+ }
151
+ async function removeMarketplace(name) {
152
+ const entry = (0, import_registry.getMarketplaceEntry)(name);
153
+ if (!entry) {
154
+ throw import_errors.MarketplaceError.removeNotFound(name);
155
+ }
156
+ if (entry.source.type !== "local") {
157
+ try {
158
+ if ((0, import_fs.existsSync)(entry.installLocation)) {
159
+ (0, import_fs.rmSync)(entry.installLocation, { recursive: true, force: true });
160
+ }
161
+ } catch (error) {
162
+ throw import_errors.MarketplaceError.removeDeleteFailed(
163
+ name,
164
+ entry.installLocation,
165
+ error instanceof Error ? error.message : String(error)
166
+ );
167
+ }
168
+ }
169
+ (0, import_registry.removeMarketplaceEntry)(name);
170
+ return {
171
+ success: true,
172
+ name
173
+ };
174
+ }
175
+ async function updateMarketplace(name) {
176
+ const results = [];
177
+ if (name) {
178
+ const result = await updateSingleMarketplace(name);
179
+ results.push(result);
180
+ } else {
181
+ const marketplaces = (0, import_registry.getAllMarketplaces)();
182
+ for (const marketplace of marketplaces) {
183
+ const result = await updateSingleMarketplace(marketplace.name);
184
+ results.push(result);
185
+ }
186
+ }
187
+ return results;
188
+ }
189
+ async function updateSingleMarketplace(name) {
190
+ const entry = (0, import_registry.getMarketplaceEntry)(name);
191
+ if (!entry) {
192
+ throw import_errors.MarketplaceError.updateNotFound(name);
193
+ }
194
+ const warnings = [];
195
+ if (entry.source.type === "local") {
196
+ return {
197
+ success: true,
198
+ name,
199
+ hasChanges: false,
200
+ warnings: ["Local marketplaces do not support automatic updates"]
201
+ };
202
+ }
203
+ if (!(0, import_fs.existsSync)(entry.installLocation)) {
204
+ warnings.push("Marketplace directory not found, re-cloning");
205
+ const cloneUrl = getCloneUrl(entry.source);
206
+ try {
207
+ (0, import_child_process.execSync)(`git clone "${cloneUrl}" "${entry.installLocation}"`, {
208
+ encoding: "utf-8",
209
+ stdio: ["pipe", "pipe", "pipe"]
210
+ });
211
+ } catch (error) {
212
+ throw import_errors.MarketplaceError.updatePullFailed(
213
+ name,
214
+ error instanceof Error ? error.message : String(error)
215
+ );
216
+ }
217
+ (0, import_registry.updateMarketplaceTimestamp)(name);
218
+ const newShaValue2 = getGitSha(entry.installLocation);
219
+ return {
220
+ success: true,
221
+ name,
222
+ ...newShaValue2 !== void 0 && { newSha: newShaValue2 },
223
+ hasChanges: true,
224
+ warnings
225
+ };
226
+ }
227
+ const previousShaValue = getGitSha(entry.installLocation);
228
+ try {
229
+ (0, import_child_process.execSync)("git pull --ff-only", {
230
+ cwd: entry.installLocation,
231
+ encoding: "utf-8",
232
+ stdio: ["pipe", "pipe", "pipe"]
233
+ });
234
+ } catch (error) {
235
+ throw import_errors.MarketplaceError.updatePullFailed(
236
+ name,
237
+ error instanceof Error ? error.message : String(error)
238
+ );
239
+ }
240
+ const newShaValue = getGitSha(entry.installLocation);
241
+ const hasChanges = previousShaValue !== newShaValue;
242
+ if (hasChanges) {
243
+ (0, import_registry.updateMarketplaceTimestamp)(name);
244
+ }
245
+ return {
246
+ success: true,
247
+ name,
248
+ ...previousShaValue !== void 0 && { previousSha: previousShaValue },
249
+ ...newShaValue !== void 0 && { newSha: newShaValue },
250
+ hasChanges,
251
+ warnings
252
+ };
253
+ }
254
+ function listMarketplaces() {
255
+ return (0, import_registry.getAllMarketplaces)();
256
+ }
257
+ function scanMarketplacePlugins(marketplacePath, marketplaceName) {
258
+ const plugins = [];
259
+ const manifestPath = path.join(marketplacePath, "marketplace.json");
260
+ if ((0, import_fs.existsSync)(manifestPath)) {
261
+ try {
262
+ const content = (0, import_fs.readFileSync)(manifestPath, "utf-8");
263
+ const parsed = JSON.parse(content);
264
+ const result = import_schemas.MarketplaceManifestSchema.safeParse(parsed);
265
+ if (result.success) {
266
+ const manifest = result.data;
267
+ if (manifest.plugins && manifest.plugins.length > 0) {
268
+ for (const plugin of manifest.plugins) {
269
+ const pluginPath = path.join(marketplacePath, plugin.source);
270
+ if ((0, import_fs.existsSync)(pluginPath)) {
271
+ plugins.push({
272
+ name: plugin.name,
273
+ ...plugin.description !== void 0 && {
274
+ description: plugin.description
275
+ },
276
+ ...plugin.version !== void 0 && { version: plugin.version },
277
+ ...plugin.category !== void 0 && { category: plugin.category },
278
+ sourcePath: pluginPath,
279
+ marketplace: marketplaceName
280
+ });
281
+ }
282
+ }
283
+ return plugins;
284
+ }
285
+ }
286
+ } catch {
287
+ }
288
+ }
289
+ const pluginDirs = ["plugins", "external_plugins"];
290
+ for (const dir of pluginDirs) {
291
+ const dirPath = path.join(marketplacePath, dir);
292
+ if (!(0, import_fs.existsSync)(dirPath)) continue;
293
+ try {
294
+ const entries = (0, import_fs.readdirSync)(dirPath, { withFileTypes: true });
295
+ for (const entry of entries) {
296
+ if (!entry.isDirectory()) continue;
297
+ const pluginPath = path.join(dirPath, entry.name);
298
+ const manifest = (0, import_validate_plugin.tryLoadManifest)(pluginPath);
299
+ if (manifest) {
300
+ plugins.push({
301
+ name: manifest.name,
302
+ ...manifest.description !== void 0 && {
303
+ description: manifest.description
304
+ },
305
+ ...manifest.version !== void 0 && { version: manifest.version },
306
+ sourcePath: pluginPath,
307
+ marketplace: marketplaceName
308
+ });
309
+ }
310
+ }
311
+ } catch {
312
+ }
313
+ }
314
+ try {
315
+ const rootEntries = (0, import_fs.readdirSync)(marketplacePath, { withFileTypes: true });
316
+ for (const entry of rootEntries) {
317
+ if (!entry.isDirectory()) continue;
318
+ if (["plugins", "external_plugins", ".git", "node_modules"].includes(entry.name))
319
+ continue;
320
+ const pluginPath = path.join(marketplacePath, entry.name);
321
+ const manifest = (0, import_validate_plugin.tryLoadManifest)(pluginPath);
322
+ if (manifest) {
323
+ const existing = plugins.find((p) => p.name === manifest.name);
324
+ if (!existing) {
325
+ plugins.push({
326
+ name: manifest.name,
327
+ ...manifest.description !== void 0 && {
328
+ description: manifest.description
329
+ },
330
+ ...manifest.version !== void 0 && { version: manifest.version },
331
+ sourcePath: pluginPath,
332
+ marketplace: marketplaceName
333
+ });
334
+ }
335
+ }
336
+ }
337
+ } catch {
338
+ }
339
+ return plugins;
340
+ }
341
+ function listAllMarketplacePlugins() {
342
+ const marketplaces = listMarketplaces();
343
+ const allPlugins = [];
344
+ for (const marketplace of marketplaces) {
345
+ if (!(0, import_fs.existsSync)(marketplace.installLocation)) continue;
346
+ const plugins = scanMarketplacePlugins(marketplace.installLocation, marketplace.name);
347
+ allPlugins.push(...plugins);
348
+ }
349
+ return allPlugins;
350
+ }
351
+ function findPluginInMarketplaces(pluginName, marketplaceName) {
352
+ const marketplaces = marketplaceName ? [(0, import_registry.getMarketplaceEntry)(marketplaceName)].filter(Boolean) : listMarketplaces();
353
+ for (const marketplace of marketplaces) {
354
+ if (!(0, import_fs.existsSync)(marketplace.installLocation)) continue;
355
+ const plugins = scanMarketplacePlugins(marketplace.installLocation, marketplace.name);
356
+ const found = plugins.find((p) => p.name.toLowerCase() === pluginName.toLowerCase());
357
+ if (found) {
358
+ return found;
359
+ }
360
+ }
361
+ return null;
362
+ }
363
+ // Annotate the CommonJS export names for ESM import in node:
364
+ 0 && (module.exports = {
365
+ addMarketplace,
366
+ deriveMarketplaceName,
367
+ findPluginInMarketplaces,
368
+ listAllMarketplacePlugins,
369
+ listMarketplaces,
370
+ parseMarketplaceSource,
371
+ removeMarketplace,
372
+ scanMarketplacePlugins,
373
+ updateMarketplace
374
+ });