@xpert-ai/plugin-sdk 3.16.0 → 3.17.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.
Files changed (53) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/_extends.cjs.js +14 -0
  3. package/_extends.esm.js +12 -0
  4. package/collaboration-client.cjs.js +392 -8
  5. package/collaboration-client.esm.js +389 -1
  6. package/index.cjs.js +513 -286
  7. package/index.esm.js +458 -249
  8. package/model-provider-http-client.cjs.default.js +1 -0
  9. package/model-provider-http-client.cjs.js +118 -0
  10. package/model-provider-http-client.cjs.mjs +2 -0
  11. package/model-provider-http-client.d.ts +1 -0
  12. package/model-provider-http-client.esm.js +115 -0
  13. package/model-provider-toolset.cjs.default.js +1 -0
  14. package/model-provider-toolset.cjs.js +12 -0
  15. package/model-provider-toolset.cjs.mjs +2 -0
  16. package/model-provider-toolset.d.ts +1 -0
  17. package/model-provider-toolset.esm.js +6 -0
  18. package/model-provider.cjs.js +348 -0
  19. package/model-provider.esm.js +328 -0
  20. package/package.json +14 -2
  21. package/src/index.d.ts +1 -0
  22. package/src/lib/agent/middleware/capabilities/assistant-task.d.ts +3 -0
  23. package/src/lib/agent/middleware/index.d.ts +1 -0
  24. package/src/lib/agent/middleware/model-output-validation-error.d.ts +27 -0
  25. package/src/lib/agent/middleware/runtime.d.ts +43 -4
  26. package/src/lib/ai-model/abstract-provider.d.ts +2 -2
  27. package/src/lib/ai-model/ai-model-provider.interface.d.ts +3 -3
  28. package/src/lib/ai-model/ai-model.d.ts +4 -1
  29. package/src/lib/ai-model/index.d.ts +2 -0
  30. package/src/lib/ai-model/llm.d.ts +49 -3
  31. package/src/lib/ai-model/managed-aigc-job.d.ts +37 -0
  32. package/src/lib/ai-model/model-provider-http-client.d.ts +51 -0
  33. package/src/lib/ai-model/pricing.d.ts +13 -1
  34. package/src/lib/ai-model/types/aigc.d.ts +39 -0
  35. package/src/lib/ai-model/types/index.d.ts +1 -0
  36. package/src/lib/ai-model/types/model.d.ts +10 -4
  37. package/src/lib/core/runtime-capability.d.ts +2 -0
  38. package/src/lib/evolution/index.d.ts +4 -0
  39. package/src/lib/evolution/provider.decorator.d.ts +2 -0
  40. package/src/lib/evolution/provider.registry.d.ts +7 -0
  41. package/src/lib/evolution/runtime-capability.d.ts +3 -0
  42. package/src/lib/managed-queue/index.d.ts +3 -1
  43. package/src/lib/runtime/capabilities/knowledgebase-documents.d.ts +59 -1
  44. package/src/lib/runtime/capabilities/knowledgebase.d.ts +95 -3
  45. package/src/lib/runtime/capabilities/workspace-files.d.ts +5 -0
  46. package/src/lib/toolset/builtin.d.ts +28 -0
  47. package/src/lib/toolset/index.d.ts +1 -0
  48. package/src/lib/toolset/model-provider.d.ts +31 -0
  49. package/src/lib/vectorstore/strategy.interface.d.ts +3 -0
  50. package/src/model-provider-http-client.d.ts +1 -0
  51. package/src/model-provider-toolset.d.ts +1 -0
  52. package/collaboration-client.cjs2.js +0 -406
  53. package/collaboration-client.esm2.js +0 -398
@@ -0,0 +1 @@
1
+ exports._default = require('./model-provider-http-client.cjs.js').default;
@@ -0,0 +1,118 @@
1
+ 'use strict';
2
+
3
+ var _extends = require('./_extends.cjs.js');
4
+
5
+ class ModelProviderHttpError extends Error {
6
+ constructor(message, status){
7
+ super(message);
8
+ this.status = status;
9
+ this.name = 'ModelProviderHttpError';
10
+ }
11
+ }
12
+ /**
13
+ * Shared HTTP transport for model Provider adapters.
14
+ *
15
+ * Provider-specific authentication headers are supplied at construction time;
16
+ * response parsing, task semantics, and download URL policy stay in each adapter.
17
+ */ class ModelProviderHttpClient {
18
+ async requestJson(pathOrUrl, init, parse) {
19
+ const response = await this.fetchResponse(this.resolveRequestUrl(pathOrUrl), _extends._extends({}, init, {
20
+ headers: this.mergeHeaders(init.headers)
21
+ }), this.requestTimeoutMs);
22
+ if (!response.ok) {
23
+ throw await this.createHttpError(response);
24
+ }
25
+ return parse(await response.json());
26
+ }
27
+ async fetchResponse(input, init = {}, timeoutMs) {
28
+ var _init_signal;
29
+ if (!timeoutMs) {
30
+ return this.fetchImpl(input, init);
31
+ }
32
+ const controller = new AbortController();
33
+ let timedOut = false;
34
+ const abortFromCaller = ()=>{
35
+ var _init_signal;
36
+ return controller.abort((_init_signal = init.signal) == null ? void 0 : _init_signal.reason);
37
+ };
38
+ if ((_init_signal = init.signal) == null ? void 0 : _init_signal.aborted) {
39
+ abortFromCaller();
40
+ } else {
41
+ var _init_signal1;
42
+ (_init_signal1 = init.signal) == null ? void 0 : _init_signal1.addEventListener('abort', abortFromCaller, {
43
+ once: true
44
+ });
45
+ }
46
+ const timeout = setTimeout(()=>{
47
+ timedOut = true;
48
+ controller.abort();
49
+ }, timeoutMs);
50
+ try {
51
+ return await this.fetchImpl(input, _extends._extends({}, init, {
52
+ signal: controller.signal
53
+ }));
54
+ } catch (error) {
55
+ if (timedOut) {
56
+ throw this.createTimeoutError(timeoutMs);
57
+ }
58
+ throw error;
59
+ } finally{
60
+ var _init_signal2;
61
+ clearTimeout(timeout);
62
+ (_init_signal2 = init.signal) == null ? void 0 : _init_signal2.removeEventListener('abort', abortFromCaller);
63
+ }
64
+ }
65
+ async readBufferResponse(response, options = {}) {
66
+ var _response_headers_get_split_, _response_headers_get;
67
+ const contentLength = response.headers.get('content-length');
68
+ const declaredBytes = contentLength && /^\d+$/u.test(contentLength) ? Number(contentLength) : undefined;
69
+ if (options.maxBytes && declaredBytes && declaredBytes > options.maxBytes) {
70
+ var _options_maxBytesError;
71
+ throw new Error((_options_maxBytesError = options.maxBytesError) != null ? _options_maxBytesError : `${this.provider} result exceeds the download limit`);
72
+ }
73
+ const buffer = Buffer.from(await response.arrayBuffer());
74
+ if (options.maxBytes && buffer.length > options.maxBytes) {
75
+ var _options_maxBytesError1;
76
+ throw new Error((_options_maxBytesError1 = options.maxBytesError) != null ? _options_maxBytesError1 : `${this.provider} result exceeds the download limit`);
77
+ }
78
+ return {
79
+ buffer,
80
+ mimeType: ((_response_headers_get = response.headers.get('content-type')) == null ? void 0 : (_response_headers_get_split_ = _response_headers_get.split(';')[0]) == null ? void 0 : _response_headers_get_split_.trim()) || options.defaultMimeType || undefined
81
+ };
82
+ }
83
+ async createHttpError(response) {
84
+ const text = await response.text().catch(()=>'');
85
+ return new ModelProviderHttpError(`${this.provider} API error ${response.status}: ${text || response.statusText}`, response.status);
86
+ }
87
+ createTimeoutError(timeoutMs) {
88
+ return new Error(`${this.provider} request timed out after ${timeoutMs}ms`);
89
+ }
90
+ resolveRequestUrl(pathOrUrl) {
91
+ return /^https?:\/\//iu.test(pathOrUrl) ? pathOrUrl : `${this.baseUrl}${pathOrUrl.startsWith('/') ? '' : '/'}${pathOrUrl}`;
92
+ }
93
+ mergeHeaders(headers) {
94
+ const merged = _extends._extends({}, this.defaultHeaders);
95
+ const headerNames = new Map(Object.keys(merged).map((key)=>[
96
+ key.toLowerCase(),
97
+ key
98
+ ]));
99
+ new Headers(headers).forEach((value, key)=>{
100
+ var _headerNames_get;
101
+ const targetKey = (_headerNames_get = headerNames.get(key)) != null ? _headerNames_get : key;
102
+ merged[targetKey] = value;
103
+ });
104
+ return merged;
105
+ }
106
+ constructor(options){
107
+ this.provider = options.provider;
108
+ this.baseUrl = options.baseUrl.replace(/\/$/u, '');
109
+ var _options_defaultHeaders;
110
+ this.defaultHeaders = (_options_defaultHeaders = options.defaultHeaders) != null ? _options_defaultHeaders : {};
111
+ var _options_fetchImpl;
112
+ this.fetchImpl = (_options_fetchImpl = options.fetchImpl) != null ? _options_fetchImpl : fetch;
113
+ this.requestTimeoutMs = options.requestTimeoutMs;
114
+ }
115
+ }
116
+
117
+ exports.ModelProviderHttpClient = ModelProviderHttpClient;
118
+ exports.ModelProviderHttpError = ModelProviderHttpError;
@@ -0,0 +1,2 @@
1
+ export * from './model-provider-http-client.cjs.js';
2
+ export { _default as default } from './model-provider-http-client.cjs.default.js';
@@ -0,0 +1 @@
1
+ export * from "./src/model-provider-http-client";
@@ -0,0 +1,115 @@
1
+ import { _ as _extends } from './_extends.esm.js';
2
+
3
+ class ModelProviderHttpError extends Error {
4
+ constructor(message, status){
5
+ super(message);
6
+ this.status = status;
7
+ this.name = 'ModelProviderHttpError';
8
+ }
9
+ }
10
+ /**
11
+ * Shared HTTP transport for model Provider adapters.
12
+ *
13
+ * Provider-specific authentication headers are supplied at construction time;
14
+ * response parsing, task semantics, and download URL policy stay in each adapter.
15
+ */ class ModelProviderHttpClient {
16
+ async requestJson(pathOrUrl, init, parse) {
17
+ const response = await this.fetchResponse(this.resolveRequestUrl(pathOrUrl), _extends({}, init, {
18
+ headers: this.mergeHeaders(init.headers)
19
+ }), this.requestTimeoutMs);
20
+ if (!response.ok) {
21
+ throw await this.createHttpError(response);
22
+ }
23
+ return parse(await response.json());
24
+ }
25
+ async fetchResponse(input, init = {}, timeoutMs) {
26
+ var _init_signal;
27
+ if (!timeoutMs) {
28
+ return this.fetchImpl(input, init);
29
+ }
30
+ const controller = new AbortController();
31
+ let timedOut = false;
32
+ const abortFromCaller = ()=>{
33
+ var _init_signal;
34
+ return controller.abort((_init_signal = init.signal) == null ? void 0 : _init_signal.reason);
35
+ };
36
+ if ((_init_signal = init.signal) == null ? void 0 : _init_signal.aborted) {
37
+ abortFromCaller();
38
+ } else {
39
+ var _init_signal1;
40
+ (_init_signal1 = init.signal) == null ? void 0 : _init_signal1.addEventListener('abort', abortFromCaller, {
41
+ once: true
42
+ });
43
+ }
44
+ const timeout = setTimeout(()=>{
45
+ timedOut = true;
46
+ controller.abort();
47
+ }, timeoutMs);
48
+ try {
49
+ return await this.fetchImpl(input, _extends({}, init, {
50
+ signal: controller.signal
51
+ }));
52
+ } catch (error) {
53
+ if (timedOut) {
54
+ throw this.createTimeoutError(timeoutMs);
55
+ }
56
+ throw error;
57
+ } finally{
58
+ var _init_signal2;
59
+ clearTimeout(timeout);
60
+ (_init_signal2 = init.signal) == null ? void 0 : _init_signal2.removeEventListener('abort', abortFromCaller);
61
+ }
62
+ }
63
+ async readBufferResponse(response, options = {}) {
64
+ var _response_headers_get_split_, _response_headers_get;
65
+ const contentLength = response.headers.get('content-length');
66
+ const declaredBytes = contentLength && /^\d+$/u.test(contentLength) ? Number(contentLength) : undefined;
67
+ if (options.maxBytes && declaredBytes && declaredBytes > options.maxBytes) {
68
+ var _options_maxBytesError;
69
+ throw new Error((_options_maxBytesError = options.maxBytesError) != null ? _options_maxBytesError : `${this.provider} result exceeds the download limit`);
70
+ }
71
+ const buffer = Buffer.from(await response.arrayBuffer());
72
+ if (options.maxBytes && buffer.length > options.maxBytes) {
73
+ var _options_maxBytesError1;
74
+ throw new Error((_options_maxBytesError1 = options.maxBytesError) != null ? _options_maxBytesError1 : `${this.provider} result exceeds the download limit`);
75
+ }
76
+ return {
77
+ buffer,
78
+ mimeType: ((_response_headers_get = response.headers.get('content-type')) == null ? void 0 : (_response_headers_get_split_ = _response_headers_get.split(';')[0]) == null ? void 0 : _response_headers_get_split_.trim()) || options.defaultMimeType || undefined
79
+ };
80
+ }
81
+ async createHttpError(response) {
82
+ const text = await response.text().catch(()=>'');
83
+ return new ModelProviderHttpError(`${this.provider} API error ${response.status}: ${text || response.statusText}`, response.status);
84
+ }
85
+ createTimeoutError(timeoutMs) {
86
+ return new Error(`${this.provider} request timed out after ${timeoutMs}ms`);
87
+ }
88
+ resolveRequestUrl(pathOrUrl) {
89
+ return /^https?:\/\//iu.test(pathOrUrl) ? pathOrUrl : `${this.baseUrl}${pathOrUrl.startsWith('/') ? '' : '/'}${pathOrUrl}`;
90
+ }
91
+ mergeHeaders(headers) {
92
+ const merged = _extends({}, this.defaultHeaders);
93
+ const headerNames = new Map(Object.keys(merged).map((key)=>[
94
+ key.toLowerCase(),
95
+ key
96
+ ]));
97
+ new Headers(headers).forEach((value, key)=>{
98
+ var _headerNames_get;
99
+ const targetKey = (_headerNames_get = headerNames.get(key)) != null ? _headerNames_get : key;
100
+ merged[targetKey] = value;
101
+ });
102
+ return merged;
103
+ }
104
+ constructor(options){
105
+ this.provider = options.provider;
106
+ this.baseUrl = options.baseUrl.replace(/\/$/u, '');
107
+ var _options_defaultHeaders;
108
+ this.defaultHeaders = (_options_defaultHeaders = options.defaultHeaders) != null ? _options_defaultHeaders : {};
109
+ var _options_fetchImpl;
110
+ this.fetchImpl = (_options_fetchImpl = options.fetchImpl) != null ? _options_fetchImpl : fetch;
111
+ this.requestTimeoutMs = options.requestTimeoutMs;
112
+ }
113
+ }
114
+
115
+ export { ModelProviderHttpClient, ModelProviderHttpError };
@@ -0,0 +1 @@
1
+ exports._default = require('./model-provider-toolset.cjs.js').default;
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ var modelProvider = require('./model-provider.cjs.js');
4
+ require('@xpert-ai/contracts');
5
+ require('./_extends.cjs.js');
6
+ require('@nestjs/common');
7
+ require('@langchain/core/tools');
8
+ require('zod');
9
+
10
+
11
+
12
+ exports.ModelProviderBuiltinToolset = modelProvider.ModelProviderBuiltinToolset;
@@ -0,0 +1,2 @@
1
+ export * from './model-provider-toolset.cjs.js';
2
+ export { _default as default } from './model-provider-toolset.cjs.default.js';
@@ -0,0 +1 @@
1
+ export * from "./src/model-provider-toolset";
@@ -0,0 +1,6 @@
1
+ export { M as ModelProviderBuiltinToolset } from './model-provider.esm.js';
2
+ import '@xpert-ai/contracts';
3
+ import './_extends.esm.js';
4
+ import '@nestjs/common';
5
+ import '@langchain/core/tools';
6
+ import 'zod';
@@ -0,0 +1,348 @@
1
+ 'use strict';
2
+
3
+ var contracts = require('@xpert-ai/contracts');
4
+ var _extends = require('./_extends.cjs.js');
5
+ var common = require('@nestjs/common');
6
+ var tools = require('@langchain/core/tools');
7
+ var zod = require('zod');
8
+
9
+ /**
10
+ * Base ability for all toolsets
11
+ */ class BaseToolset extends tools.BaseToolkit {
12
+ /**
13
+ * Async init tools
14
+ *
15
+ * @returns
16
+ */ async initTools() {
17
+ return this.tools;
18
+ }
19
+ /**
20
+ * Get one tool
21
+ *
22
+ * @param toolName
23
+ * @returns
24
+ */ getTool(toolName) {
25
+ var _this_getTools;
26
+ return (_this_getTools = this.getTools()) == null ? void 0 : _this_getTools.find((tool)=>tool.name === toolName);
27
+ }
28
+ /**
29
+ * Get state variables config
30
+ *
31
+ * @returns State variables
32
+ */ async getVariables() {
33
+ return null;
34
+ }
35
+ /**
36
+ * Close all (connections).
37
+ */ async close() {
38
+ //
39
+ }
40
+ constructor(params){
41
+ super();
42
+ this.params = params;
43
+ }
44
+ }
45
+ class BaseTool extends tools.StructuredTool {
46
+ constructor(...args){
47
+ super(...args);
48
+ this.schema = zod.z.object({
49
+ input: zod.z.string().optional()
50
+ }).transform((obj)=>obj.input);
51
+ }
52
+ }
53
+
54
+ class BuiltinToolset extends BaseToolset {
55
+ get tenantId() {
56
+ var _this_params;
57
+ return (_this_params = this.params) == null ? void 0 : _this_params.tenantId;
58
+ }
59
+ get organizationId() {
60
+ var _this_params;
61
+ return (_this_params = this.params) == null ? void 0 : _this_params.organizationId;
62
+ }
63
+ get commandBus() {
64
+ var _this_params;
65
+ return (_this_params = this.params) == null ? void 0 : _this_params.commandBus;
66
+ }
67
+ get queryBus() {
68
+ var _this_params;
69
+ return (_this_params = this.params) == null ? void 0 : _this_params.queryBus;
70
+ }
71
+ get xpertId() {
72
+ var _this_params;
73
+ return (_this_params = this.params) == null ? void 0 : _this_params.xpertId;
74
+ }
75
+ get modelRuntime() {
76
+ var _this_params;
77
+ return (_this_params = this.params) == null ? void 0 : _this_params.modelRuntime;
78
+ }
79
+ get managedQueue() {
80
+ var _this_params;
81
+ return (_this_params = this.params) == null ? void 0 : _this_params.managedQueue;
82
+ }
83
+ get pluginScopeKey() {
84
+ var _this_params;
85
+ return (_this_params = this.params) == null ? void 0 : _this_params.pluginScopeKey;
86
+ }
87
+ async validateCredentials(credentials) {
88
+ await this._validateCredentials(credentials);
89
+ }
90
+ async _validateCredentials(credentials) {
91
+ throw new Error('Method not implemented.');
92
+ }
93
+ getId() {
94
+ var _this_toolset;
95
+ return (_this_toolset = this.toolset) == null ? void 0 : _this_toolset.id;
96
+ }
97
+ getCredentials() {
98
+ var _this_toolset;
99
+ return (_this_toolset = this.toolset) == null ? void 0 : _this_toolset.credentials;
100
+ }
101
+ getToolTitle(name) {
102
+ var _this_toolset_tools, _this_toolset, _tool_schema;
103
+ const tool = (_this_toolset = this.toolset) == null ? void 0 : (_this_toolset_tools = _this_toolset.tools) == null ? void 0 : _this_toolset_tools.find((tool)=>tool.name === name);
104
+ const identity = tool == null ? void 0 : (_tool_schema = tool.schema) == null ? void 0 : _tool_schema.identity;
105
+ if (identity) {
106
+ return identity.label;
107
+ }
108
+ return null;
109
+ }
110
+ /**
111
+ * Get credentials schema
112
+ *
113
+ * @returns Credentials schema
114
+ */ getCredentialsSchema() {
115
+ return _extends._extends({}, this.credentialsSchema);
116
+ }
117
+ /**
118
+ * Get toolset entity
119
+ *
120
+ * @returns XpertToolset
121
+ */ getToolset() {
122
+ return this.toolset;
123
+ }
124
+ getName() {
125
+ var _this_getToolset;
126
+ return (_this_getToolset = this.getToolset()) == null ? void 0 : _this_getToolset.name;
127
+ }
128
+ constructor(providerName, toolset, params){
129
+ super(params);
130
+ this.logger = new common.Logger(this.constructor.name);
131
+ this.providerName = providerName;
132
+ this.toolset = toolset;
133
+ this.params = params;
134
+ }
135
+ }
136
+ BuiltinToolset.provider = '';
137
+
138
+ function createRuntimeCapability(id, options = {}) {
139
+ return Object.freeze({
140
+ id,
141
+ description: options.description
142
+ });
143
+ }
144
+ const XPERT_RUNTIME_CAPABILITIES_TOKEN = 'XPERT_RUNTIME_CAPABILITIES';
145
+ class DefaultRuntimeCapabilityRegistry {
146
+ register(key, implementation) {
147
+ this.capabilities.set(runtimeCapabilityId(key), implementation);
148
+ return this;
149
+ }
150
+ has(key) {
151
+ return this.capabilities.has(runtimeCapabilityId(key));
152
+ }
153
+ get(key) {
154
+ return this.capabilities.get(runtimeCapabilityId(key));
155
+ }
156
+ require(key) {
157
+ const implementation = this.get(key);
158
+ if (!implementation) {
159
+ throw new Error(`Runtime capability '${runtimeCapabilityId(key)}' is not available`);
160
+ }
161
+ return implementation;
162
+ }
163
+ constructor(entries = []){
164
+ this.capabilities = new Map();
165
+ entries.forEach(([key, implementation])=>this.register(key, implementation));
166
+ }
167
+ }
168
+ function runtimeCapabilityId(key) {
169
+ return typeof key === 'string' ? key : key.id;
170
+ }
171
+
172
+ const KnowledgebaseRuntimeCapability = createRuntimeCapability('platform.knowledgebase', {
173
+ description: 'List, search, and write chunks in platform knowledgebases.'
174
+ });
175
+ const KnowledgebaseProvisioningRuntimeCapability = createRuntimeCapability('platform.knowledgebase.provisioning', {
176
+ description: 'Idempotently provision managed platform knowledgebases and connect them to an Agent.'
177
+ });
178
+
179
+ const KnowledgebaseDocumentsRuntimeCapability = createRuntimeCapability('platform.knowledgebase.documents', {
180
+ description: 'Upload, import, create, process, inspect, and delete persistent knowledgebase documents.'
181
+ });
182
+
183
+ const ActorTokenRuntimeCapability = createRuntimeCapability('platform.actor-token', {
184
+ description: 'Mint a short-lived host-issued actor bearer token for outbound API calls.'
185
+ });
186
+
187
+ const ArtifactsRuntimeCapability = createRuntimeCapability('platform.artifacts', {
188
+ description: 'Create, version, preview, download, share, archive, and delete platform-managed plugin and Agent artifacts.'
189
+ });
190
+
191
+ /** Stable source identifier for portable workspace file references. */ const WORKSPACE_FILES_SOURCE = 'platform.workspace.files';
192
+ const WorkspaceFilesRuntimeCapability = createRuntimeCapability('platform.workspace.files', {
193
+ description: 'Upload, understand, resolve, read, and delete raw files in Xpert workspace volumes.'
194
+ });
195
+
196
+ /** Stable machine-readable failures emitted by the Sandbox Jobs capability. */ const SANDBOX_JOB_ERROR_CODES = [
197
+ 'SANDBOX_ACTION_UNAVAILABLE',
198
+ 'SANDBOX_ACTION_INVALID',
199
+ 'SANDBOX_PROFILE_UNAVAILABLE',
200
+ 'SANDBOX_RUNTIME_UNAVAILABLE',
201
+ 'SANDBOX_VERSION_MISMATCH',
202
+ 'SANDBOX_CAPACITY_UNAVAILABLE',
203
+ 'SANDBOX_START_FAILED',
204
+ 'BROWSER_LAUNCH_FAILED',
205
+ 'EXPORT_TIMEOUT',
206
+ 'EXPORT_OOM',
207
+ 'EXPORT_MEDIA_FAILED',
208
+ 'EXPORT_INPUT_INVALID',
209
+ 'EXPORT_OUTPUT_INVALID',
210
+ 'SANDBOX_CANCELLED'
211
+ ];
212
+ /** Line prefix used by trusted Actions to report structured, provider-neutral progress. */ const SANDBOX_JOB_PROGRESS_PREFIX = 'XPERT_SANDBOX_PROGRESS ';
213
+ /** Error carrying retry policy and Job identity across plugin queue handlers. */ class SandboxJobRuntimeError extends Error {
214
+ constructor(code, message, retryable, jobId){
215
+ super(message);
216
+ this.code = code;
217
+ this.retryable = retryable;
218
+ this.jobId = jobId;
219
+ this.name = 'SandboxJobRuntimeError';
220
+ }
221
+ }
222
+ const SANDBOX_JOB_ERROR_CODE_SET = new Set(SANDBOX_JOB_ERROR_CODES);
223
+ /** Narrows an unknown failure to the structured Sandbox Jobs runtime error contract. */ function isSandboxJobRuntimeError(error) {
224
+ if (error instanceof SandboxJobRuntimeError) return true;
225
+ if (typeof error !== 'object' || error === null) return false;
226
+ // Dynamically loaded plugins may resolve another Plugin SDK module instance,
227
+ // so class identity is not a reliable runtime boundary. Validate the stable shape.
228
+ const candidate = error;
229
+ return candidate.name === 'SandboxJobRuntimeError' && typeof candidate.message === 'string' && typeof candidate.code === 'string' && SANDBOX_JOB_ERROR_CODE_SET.has(candidate.code) && typeof candidate.retryable === 'boolean' && (candidate.jobId === undefined || typeof candidate.jobId === 'string');
230
+ }
231
+ /** Runtime capability key used to resolve SandboxJobsApi from the platform registry. */ const SandboxJobsRuntimeCapability = createRuntimeCapability('platform.sandbox.jobs', {
232
+ description: 'Run registered plugin actions in isolated, short-lived Sandbox Runtime jobs.'
233
+ });
234
+
235
+ /**
236
+ * Shared host-runtime plumbing for built-in tools backed by a configured model provider.
237
+ * Provider request/response semantics remain owned by each plugin.
238
+ */ class ModelProviderBuiltinToolset extends BuiltinToolset {
239
+ async _validateCredentials(_credentials) {
240
+ await this.getModelProviderRuntime();
241
+ }
242
+ getModelProviderRuntime() {
243
+ var _this_modelRuntime;
244
+ if (!((_this_modelRuntime = this.modelRuntime) == null ? void 0 : _this_modelRuntime.getModelProvider)) {
245
+ throw new Error(this.modelProviderOptions.missingProviderMessage);
246
+ }
247
+ var _this_modelProvider;
248
+ (_this_modelProvider = this.modelProvider) != null ? _this_modelProvider : this.modelProvider = this.modelRuntime.getModelProvider(this.modelProviderOptions.modelProviderName);
249
+ return this.modelProvider;
250
+ }
251
+ getModelProviderCredential(modelProvider) {
252
+ const scheme = this.modelProviderOptions.authorizationScheme;
253
+ const match = new RegExp(`^${scheme}\\s+(.+)$`, 'i').exec(modelProvider.authorization.trim());
254
+ if (!(match == null ? void 0 : match[1])) {
255
+ throw new Error(this.modelProviderOptions.invalidCredentialsMessage);
256
+ }
257
+ return match[1];
258
+ }
259
+ getWorkspaceFiles() {
260
+ var _this_runtimeCapabilities;
261
+ const workspaceFiles = (_this_runtimeCapabilities = this.runtimeCapabilities) == null ? void 0 : _this_runtimeCapabilities.get(WorkspaceFilesRuntimeCapability);
262
+ if (!workspaceFiles) {
263
+ throw new Error(this.modelProviderOptions.missingWorkspaceMessage);
264
+ }
265
+ return workspaceFiles;
266
+ }
267
+ createWorkspaceScope() {
268
+ var _this_params, _this_params1, _this_params2;
269
+ const projectId = normalizeOptionalString((_this_params = this.params) == null ? void 0 : _this_params.projectId);
270
+ if (projectId) {
271
+ var _this_params3, _this_params4;
272
+ return {
273
+ tenantId: normalizeOptionalString((_this_params3 = this.params) == null ? void 0 : _this_params3.tenantId),
274
+ userId: normalizeOptionalString((_this_params4 = this.params) == null ? void 0 : _this_params4.userId),
275
+ catalog: 'projects',
276
+ scopeId: projectId,
277
+ projectId
278
+ };
279
+ }
280
+ const xpertId = normalizeOptionalString(this.xpertId);
281
+ if (!xpertId) return undefined;
282
+ return {
283
+ tenantId: normalizeOptionalString((_this_params1 = this.params) == null ? void 0 : _this_params1.tenantId),
284
+ userId: normalizeOptionalString((_this_params2 = this.params) == null ? void 0 : _this_params2.userId),
285
+ catalog: 'xperts',
286
+ scopeId: xpertId,
287
+ xpertId,
288
+ isolateByUser: false
289
+ };
290
+ }
291
+ async createAsyncModelClient(model, modality, purpose = 'invoke') {
292
+ const modelProvider = await this.getModelProviderRuntime();
293
+ const copilotId = normalizeOptionalString(modelProvider.copilotId);
294
+ if (!copilotId) {
295
+ throw new Error(this.modelProviderOptions.missingProviderMessage);
296
+ }
297
+ const modelType = modality === 'image' ? contracts.AiModelTypeEnum.IMAGE : contracts.AiModelTypeEnum.VIDEO;
298
+ return this.modelRuntime.createModelClient({
299
+ copilotId,
300
+ model,
301
+ modelType
302
+ }, {
303
+ purpose
304
+ });
305
+ }
306
+ async createModelClient(model, modality) {
307
+ const modelProvider = await this.getModelProviderRuntime();
308
+ const copilotId = normalizeOptionalString(modelProvider.copilotId);
309
+ if (!copilotId) {
310
+ throw new Error(this.modelProviderOptions.missingProviderMessage);
311
+ }
312
+ const modelType = modality === 'image' ? contracts.AiModelTypeEnum.IMAGE : contracts.AiModelTypeEnum.VIDEO;
313
+ return this.modelRuntime.createModelClient({
314
+ copilotId,
315
+ model,
316
+ modelType
317
+ }, {});
318
+ }
319
+ constructor(modelProviderOptions, toolset, runtimeCapabilities, params){
320
+ super(modelProviderOptions.toolsetProviderName, toolset, params);
321
+ this.modelProviderOptions = modelProviderOptions;
322
+ this.runtimeCapabilities = runtimeCapabilities;
323
+ }
324
+ }
325
+ function normalizeOptionalString(value) {
326
+ const normalized = value == null ? void 0 : value.trim();
327
+ return normalized || undefined;
328
+ }
329
+
330
+ exports.ActorTokenRuntimeCapability = ActorTokenRuntimeCapability;
331
+ exports.ArtifactsRuntimeCapability = ArtifactsRuntimeCapability;
332
+ exports.BaseTool = BaseTool;
333
+ exports.BaseToolset = BaseToolset;
334
+ exports.BuiltinToolset = BuiltinToolset;
335
+ exports.DefaultRuntimeCapabilityRegistry = DefaultRuntimeCapabilityRegistry;
336
+ exports.KnowledgebaseDocumentsRuntimeCapability = KnowledgebaseDocumentsRuntimeCapability;
337
+ exports.KnowledgebaseProvisioningRuntimeCapability = KnowledgebaseProvisioningRuntimeCapability;
338
+ exports.KnowledgebaseRuntimeCapability = KnowledgebaseRuntimeCapability;
339
+ exports.ModelProviderBuiltinToolset = ModelProviderBuiltinToolset;
340
+ exports.SANDBOX_JOB_ERROR_CODES = SANDBOX_JOB_ERROR_CODES;
341
+ exports.SANDBOX_JOB_PROGRESS_PREFIX = SANDBOX_JOB_PROGRESS_PREFIX;
342
+ exports.SandboxJobRuntimeError = SandboxJobRuntimeError;
343
+ exports.SandboxJobsRuntimeCapability = SandboxJobsRuntimeCapability;
344
+ exports.WORKSPACE_FILES_SOURCE = WORKSPACE_FILES_SOURCE;
345
+ exports.WorkspaceFilesRuntimeCapability = WorkspaceFilesRuntimeCapability;
346
+ exports.XPERT_RUNTIME_CAPABILITIES_TOKEN = XPERT_RUNTIME_CAPABILITIES_TOKEN;
347
+ exports.createRuntimeCapability = createRuntimeCapability;
348
+ exports.isSandboxJobRuntimeError = isSandboxJobRuntimeError;