@xpert-ai/plugin-sdk 3.29.1 → 3.30.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/artifact-document.cjs.js +26 -0
- package/artifact-document.esm.js +26 -0
- package/docs/README.md +4 -0
- package/docs/artifact-drafts.md +1 -1
- package/docs/artifact-types.md +8 -0
- package/docs/openai-compatible-embeddings.md +21 -0
- package/index.cjs.js +216 -119
- package/index.esm.js +216 -122
- package/model-provider.cjs.js +10 -0
- package/model-provider.esm.js +9 -1
- package/package.json +2 -2
- package/src/lib/ai-model/openai-compatible/embeddings.d.ts +8 -0
- package/src/lib/ai-model/openai-compatible/index.d.ts +1 -0
- package/src/lib/artifact-document/host.d.ts +1 -1
- package/src/lib/artifact-document/network.d.ts +3 -0
- package/src/lib/artifact-type/definition.schema.d.ts +79 -1
- package/src/lib/artifact-type/index.d.ts +12 -0
- package/src/lib/core/permissions/general.d.ts +3 -0
- package/src/lib/runtime/capabilities/artifact-content.d.ts +11 -0
- package/src/lib/runtime/capabilities/index.d.ts +1 -0
- package/src/lib/runtime/capabilities/workspace-storage.d.ts +2 -0
- package/src/lib/runtime/workspace-file-tools.d.ts +2 -0
- package/src/lib/sandbox/directory-listing-command.d.ts +4 -0
- package/src/lib/sandbox/runtime-provider.d.ts +1 -1
- package/src/lib/sandbox/sandbox.d.ts +3 -3
- package/src/lib/sandbox/workspace-path-display.d.ts +2 -0
- package/src/lib/workflow/trigger/strategy.interface.d.ts +5 -0
- package/docs/workspace-file-tools.md +0 -66
package/artifact-document.cjs.js
CHANGED
|
@@ -246,6 +246,10 @@ const origin = v3.z.string().max(250).refine((value)=>{
|
|
|
246
246
|
}, 'Use an exact HTTPS origin without a path, credentials or wildcard');
|
|
247
247
|
const origins = v3.z.array(origin).max(16);
|
|
248
248
|
const artifactDocumentNetworkPolicy = v3.z.object({
|
|
249
|
+
mode: v3.z.enum([
|
|
250
|
+
'restricted',
|
|
251
|
+
'unrestricted'
|
|
252
|
+
]).optional(),
|
|
249
253
|
scripts: origins.optional(),
|
|
250
254
|
styles: origins.optional(),
|
|
251
255
|
fonts: origins.optional(),
|
|
@@ -253,6 +257,20 @@ const artifactDocumentNetworkPolicy = v3.z.object({
|
|
|
253
257
|
}).strict();
|
|
254
258
|
function artifactDocumentCsp(input) {
|
|
255
259
|
const policy = artifactDocumentNetworkPolicy.parse(input != null ? input : {});
|
|
260
|
+
if (policy.mode === 'unrestricted') return [
|
|
261
|
+
'default-src * data: blob:',
|
|
262
|
+
"script-src * data: blob: 'unsafe-inline'",
|
|
263
|
+
"style-src * data: blob: 'unsafe-inline'",
|
|
264
|
+
'img-src * data: blob:',
|
|
265
|
+
'font-src * data: blob:',
|
|
266
|
+
'connect-src * data: blob: ws: wss:',
|
|
267
|
+
'media-src * data: blob:',
|
|
268
|
+
'frame-src * data: blob:',
|
|
269
|
+
'worker-src * data: blob:',
|
|
270
|
+
"object-src 'none'",
|
|
271
|
+
"base-uri 'none'",
|
|
272
|
+
"form-action 'none'"
|
|
273
|
+
].join('; ');
|
|
256
274
|
const sources = (values)=>(values == null ? void 0 : values.length) ? ` ${[
|
|
257
275
|
...new Set(values)
|
|
258
276
|
].join(' ')}` : '';
|
|
@@ -277,6 +295,14 @@ function artifactDocumentCsp(input) {
|
|
|
277
295
|
} catch (e) {
|
|
278
296
|
return false;
|
|
279
297
|
}
|
|
298
|
+
if (policy.mode === 'unrestricted') return [
|
|
299
|
+
'http:',
|
|
300
|
+
'https:',
|
|
301
|
+
'ws:',
|
|
302
|
+
'wss:',
|
|
303
|
+
'data:',
|
|
304
|
+
'blob:'
|
|
305
|
+
].includes(url.protocol);
|
|
280
306
|
if (url.protocol !== 'https:' || url.username || url.password) return false;
|
|
281
307
|
const allowed = resourceType === 'script' ? policy.scripts : resourceType === 'stylesheet' ? policy.styles : resourceType === 'font' ? policy.fonts : resourceType === 'image' ? policy.images : undefined;
|
|
282
308
|
var _allowed_includes;
|
package/artifact-document.esm.js
CHANGED
|
@@ -244,6 +244,10 @@ const origin = z.string().max(250).refine((value)=>{
|
|
|
244
244
|
}, 'Use an exact HTTPS origin without a path, credentials or wildcard');
|
|
245
245
|
const origins = z.array(origin).max(16);
|
|
246
246
|
const artifactDocumentNetworkPolicy = z.object({
|
|
247
|
+
mode: z.enum([
|
|
248
|
+
'restricted',
|
|
249
|
+
'unrestricted'
|
|
250
|
+
]).optional(),
|
|
247
251
|
scripts: origins.optional(),
|
|
248
252
|
styles: origins.optional(),
|
|
249
253
|
fonts: origins.optional(),
|
|
@@ -251,6 +255,20 @@ const artifactDocumentNetworkPolicy = z.object({
|
|
|
251
255
|
}).strict();
|
|
252
256
|
function artifactDocumentCsp(input) {
|
|
253
257
|
const policy = artifactDocumentNetworkPolicy.parse(input != null ? input : {});
|
|
258
|
+
if (policy.mode === 'unrestricted') return [
|
|
259
|
+
'default-src * data: blob:',
|
|
260
|
+
"script-src * data: blob: 'unsafe-inline'",
|
|
261
|
+
"style-src * data: blob: 'unsafe-inline'",
|
|
262
|
+
'img-src * data: blob:',
|
|
263
|
+
'font-src * data: blob:',
|
|
264
|
+
'connect-src * data: blob: ws: wss:',
|
|
265
|
+
'media-src * data: blob:',
|
|
266
|
+
'frame-src * data: blob:',
|
|
267
|
+
'worker-src * data: blob:',
|
|
268
|
+
"object-src 'none'",
|
|
269
|
+
"base-uri 'none'",
|
|
270
|
+
"form-action 'none'"
|
|
271
|
+
].join('; ');
|
|
254
272
|
const sources = (values)=>(values == null ? void 0 : values.length) ? ` ${[
|
|
255
273
|
...new Set(values)
|
|
256
274
|
].join(' ')}` : '';
|
|
@@ -275,6 +293,14 @@ function artifactDocumentCsp(input) {
|
|
|
275
293
|
} catch (e) {
|
|
276
294
|
return false;
|
|
277
295
|
}
|
|
296
|
+
if (policy.mode === 'unrestricted') return [
|
|
297
|
+
'http:',
|
|
298
|
+
'https:',
|
|
299
|
+
'ws:',
|
|
300
|
+
'wss:',
|
|
301
|
+
'data:',
|
|
302
|
+
'blob:'
|
|
303
|
+
].includes(url.protocol);
|
|
278
304
|
if (url.protocol !== 'https:' || url.username || url.password) return false;
|
|
279
305
|
const allowed = resourceType === 'script' ? policy.scripts : resourceType === 'stylesheet' ? policy.styles : resourceType === 'font' ? policy.fonts : resourceType === 'image' ? policy.images : undefined;
|
|
280
306
|
var _allowed_includes;
|
package/docs/README.md
CHANGED
|
@@ -6,6 +6,10 @@ See [platform capabilities and scoped factories](./en/runtime-capabilities.md) f
|
|
|
6
6
|
|
|
7
7
|
See [knowledgebase APIs](./en/KNOWLEDGEBASE_API.md) for resource discovery, readiness, permissions and migration from legacy listing.
|
|
8
8
|
|
|
9
|
+
## Model adapters
|
|
10
|
+
|
|
11
|
+
See [OpenAI-compatible Embedding usage callbacks](./openai-compatible-embeddings.md) for shared vector clients and host-owned accounting.
|
|
12
|
+
|
|
9
13
|
## Building
|
|
10
14
|
|
|
11
15
|
Run `nx build plugin-sdk` to build the library.
|
package/docs/artifact-drafts.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
Both mutations lock the Artifact row, sharing the same lock as ordinary version writes. Publication checks the draft revision and its base version, inserts the snapshot, advances the formal current version, and marks the draft published in one transaction. An identical publication retry returns the same version; stale writes or publication against a different current version fail. Publishing never silently rebases a draft.
|
|
11
11
|
|
|
12
|
-
Draft access
|
|
12
|
+
Draft access requires an active Artifact, its owner or Project policy, and the type provider’s optional `authorizeDraft` policy. Project membership alone need not grant access to drafts. Saving a draft leaves the formal current-version pointer and title unchanged; draft-aware selectors read the working title from the draft. Confirmed publication updates the formal title and version pointer atomically. Published versions and share links retain their existing behavior; links never expose unpublished drafts. File checksums, MIME policy and canonical Workspace authorization apply to drafts. Dependency snapshots can be part of the application-owned content package and therefore remain pinned in both drafts and published versions.
|
|
13
13
|
|
|
14
14
|
Installations with external schema management must apply `packages/server-ai/src/artifacts/drafts/migrations/20261017-artifact-drafts.sql`. Existing Artifacts require no backfill: the first edit starts at revision 0 against the current formal version. There is one current working copy per Artifact; immutable formal version history is retained. Intermediate draft revisions are concurrency markers, not a browsable version-history feature.
|
|
15
15
|
|
package/docs/artifact-types.md
CHANGED
|
@@ -95,3 +95,11 @@ Declare `definition.title` as an `I18nObject` (for example, `{ en_US: 'Shared co
|
|
|
95
95
|
Use `ArtifactsApi.readArtifactVersion({ artifactId, artifactVersionId, purpose })` to read published bytes with source authorization, active-version checks, content validation and checksum verification. `purpose: 'copy'` additionally requires `definition.collection.allowCopy: true`. Custom types default to denying copies; the built-in file type permits them. Copying creates an independent lifecycle under the destination Project's ACL, so the collecting UI must explain and confirm this boundary. Conversation snapshots remain reference-only.
|
|
96
96
|
|
|
97
97
|
The authenticated library viewer reuses the type's file, snapshot or authenticated presentation without minting a share. Existing shares are resolved by the type's `sharing.shareKey` (or `artifact-library`) and their stored URLs can be copied repeatedly. Selecting another reference version does not update the published link. Public sharing remains an explicit, separately authorized operation.
|
|
98
|
+
|
|
99
|
+
## Project working content and explicit share audiences
|
|
100
|
+
|
|
101
|
+
Types that own an application draft workflow can declare `versioning: { mode: 'draft-only' }`. Generic version uploads are rejected; publish through Artifact Drafts. `authorizeDraft` adds the working-copy policy. `assertDraftPublication` runs again under the Artifact lock immediately before an immutable version is committed, so domain review checks cannot be bypassed through the generic draft API.
|
|
102
|
+
|
|
103
|
+
`ArtifactContentRuntimeCapability` stores definition bytes in protected Artifact-owned storage. Ordinary project file listings and file tools cannot read that storage. Reads check the current source policy and require draft access unless the exact content is already referenced by a formal version. The platform validates ownership, canonical references, checksums and the 50 MB limit.
|
|
104
|
+
|
|
105
|
+
By default, Project membership and link audience are cumulative restrictions. A type may explicitly declare `sharing.projectAccess: 'link-audience'` only with authenticated presentation and organization/workspace audiences. In that case a manager's explicit share can grant access to the published definition outside Project membership. Provider authorization and any resource ACL still apply; tenant and audience membership are checked, revocation remains immediate, and the exception never applies to drafts, generic file APIs, library references, edits or data queries. It cannot enable anonymous/public sharing.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# OpenAI-compatible Embedding usage callbacks
|
|
2
|
+
|
|
3
|
+
Model plugins can use `OpenAICompatibleEmbeddings` from `@xpert-ai/plugin-sdk` instead of maintaining provider-specific metering subclasses.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { OpenAICompatibleEmbeddings, type TChatModelOptions } from '@xpert-ai/plugin-sdk'
|
|
7
|
+
|
|
8
|
+
function createEmbeddings(apiKey: string, baseURL: string, model: string, runtime?: TChatModelOptions) {
|
|
9
|
+
return new OpenAICompatibleEmbeddings({ apiKey, model, batchSize: 10, configuration: { baseURL } }, runtime)
|
|
10
|
+
}
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The adapter preserves the underlying client's vector results, request options, batching and transport retries. After a successful request, it normalizes the response's `usage.prompt_tokens` and `usage.total_tokens`, then invokes the existing `handleModelUsage` callback once for that request. Document batches receive distinct request IDs. Query embeddings use the same path.
|
|
14
|
+
|
|
15
|
+
When accounting is installed, `resolveUsagePricingSnapshot` runs before each request. Its result is forwarded unchanged with the final usage event. Accounting runs outside the transport retry loop; a callback failure propagates without repeating the provider request. A caller must not blindly retry an embedding operation after an accounting failure.
|
|
16
|
+
|
|
17
|
+
Missing, all-zero or invalid usage does not become an estimate or a fabricated provider report. The adapter itself does not calculate prices, resolve account scope or write a ledger; these remain host responsibilities. It does not also invoke the LLM-specific `handleLLMTokens` callback.
|
|
18
|
+
|
|
19
|
+
Runtime callbacks are optional for standalone use and credential validation. Native endpoints with different response contracts still need protocol-specific parsing. This adapter does not meter Tongyi's native multimodal endpoint.
|
|
20
|
+
|
|
21
|
+
Plugins consuming this export must be built and deployed with an SDK release containing it. An older SDK installation cannot supply the new class; refresh the plugin's build dependency and the host runtime together before release.
|
package/index.cjs.js
CHANGED
|
@@ -39,6 +39,7 @@ var jsTiktoken = require('js-tiktoken');
|
|
|
39
39
|
var zod = require('zod');
|
|
40
40
|
var results = require('./results.cjs.js');
|
|
41
41
|
var connector = require('./connector.cjs.js');
|
|
42
|
+
var node_path = require('node:path');
|
|
42
43
|
var _object_without_properties_loose$2 = require('./_object_without_properties_loose.cjs.js');
|
|
43
44
|
var collaborationClient = require('./collaboration-client.cjs.js');
|
|
44
45
|
var tools = require('@langchain/core/tools');
|
|
@@ -2931,7 +2932,33 @@ exports.AIModel = AIModel_1 = class AIModel {
|
|
|
2931
2932
|
}
|
|
2932
2933
|
getUsagePricingSnapshot(model, credentials, context) {
|
|
2933
2934
|
var _this_getModelSchema;
|
|
2934
|
-
|
|
2935
|
+
const pricing = (_this_getModelSchema = this.getModelSchema(model, credentials)) == null ? void 0 : _this_getModelSchema.pricing;
|
|
2936
|
+
if (this.modelType === contracts.AiModelTypeEnum.TEXT_EMBEDDING && pricing && !isModelUsagePricingConfig(pricing)) {
|
|
2937
|
+
var _pricing_tiered_pricing, _pricing_rules, _pricing_currency;
|
|
2938
|
+
// Only flat input prices can be converted without the invocation's actual token count.
|
|
2939
|
+
// Invalid or conditional prices must remain unpriced, never silently become free.
|
|
2940
|
+
const input = Number(pricing.input), unit = Number(pricing.unit);
|
|
2941
|
+
if (((_pricing_tiered_pricing = pricing.tiered_pricing) == null ? void 0 : _pricing_tiered_pricing.length) || ((_pricing_rules = pricing.rules) == null ? void 0 : _pricing_rules.length) || !Number.isFinite(input) || input < 0 || !Number.isFinite(unit) || unit <= 0 || !((_pricing_currency = pricing.currency) == null ? void 0 : _pricing_currency.trim())) {
|
|
2942
|
+
return resolveModelUsagePricingSnapshot(undefined, context);
|
|
2943
|
+
}
|
|
2944
|
+
return resolveModelUsagePricingSnapshot({
|
|
2945
|
+
type: 'usage',
|
|
2946
|
+
rules: [
|
|
2947
|
+
{
|
|
2948
|
+
id: `${model}:embedding-input`,
|
|
2949
|
+
version: 'catalog',
|
|
2950
|
+
effective_from: '1970-01-01T00:00:00.000Z',
|
|
2951
|
+
unit: 'token',
|
|
2952
|
+
token_type: 'prompt',
|
|
2953
|
+
unit_size: 1,
|
|
2954
|
+
unit_price: input * unit,
|
|
2955
|
+
currency: pricing.currency,
|
|
2956
|
+
charge_type: input === 0 ? 'free' : 'paid'
|
|
2957
|
+
}
|
|
2958
|
+
]
|
|
2959
|
+
}, context);
|
|
2960
|
+
}
|
|
2961
|
+
return resolveModelUsagePricingSnapshot(pricing, context);
|
|
2935
2962
|
}
|
|
2936
2963
|
getModelPath() {
|
|
2937
2964
|
const modelType = this.modelType.toLowerCase();
|
|
@@ -3990,6 +4017,47 @@ class Speech2TextChatModel extends chat_models.BaseChatModel {
|
|
|
3990
4017
|
}
|
|
3991
4018
|
}
|
|
3992
4019
|
|
|
4020
|
+
/** OpenAI-compatible embeddings with authoritative, per-request usage callbacks. */ class OpenAICompatibleEmbeddings extends openai.OpenAIEmbeddings {
|
|
4021
|
+
async embeddingWithRetry(request) {
|
|
4022
|
+
var _this_usageCallbacks, _this_usageCallbacks_resolveUsagePricingSnapshot, _this_usageCallbacks1, _response_usage, _response_usage1;
|
|
4023
|
+
const requestId = node_crypto.randomUUID();
|
|
4024
|
+
const context = {
|
|
4025
|
+
model: request.model,
|
|
4026
|
+
modelType: contracts.AiModelTypeEnum.TEXT_EMBEDDING,
|
|
4027
|
+
operation: contracts.AiModelTypeEnum.TEXT_EMBEDDING,
|
|
4028
|
+
modality: 'text',
|
|
4029
|
+
startedAt: new Date().toISOString()
|
|
4030
|
+
};
|
|
4031
|
+
const reportUsage = (_this_usageCallbacks = this.usageCallbacks) == null ? void 0 : _this_usageCallbacks.handleModelUsage;
|
|
4032
|
+
const pricingSnapshot = reportUsage ? await ((_this_usageCallbacks1 = this.usageCallbacks) == null ? void 0 : (_this_usageCallbacks_resolveUsagePricingSnapshot = _this_usageCallbacks1.resolveUsagePricingSnapshot) == null ? void 0 : _this_usageCallbacks_resolveUsagePricingSnapshot.call(_this_usageCallbacks1, context)) : undefined;
|
|
4033
|
+
const response = await super.embeddingWithRetry(request);
|
|
4034
|
+
const usage = normalizeTokenUsage({
|
|
4035
|
+
promptTokens: (_response_usage = response.usage) == null ? void 0 : _response_usage.prompt_tokens,
|
|
4036
|
+
completionTokens: 0,
|
|
4037
|
+
totalTokens: (_response_usage1 = response.usage) == null ? void 0 : _response_usage1.total_tokens
|
|
4038
|
+
});
|
|
4039
|
+
// Stay outside the transport retry loop: accounting failure must not repeat a billable request.
|
|
4040
|
+
if (usage && reportUsage) {
|
|
4041
|
+
await reportUsage(_extends._extends({}, context, {
|
|
4042
|
+
requestId,
|
|
4043
|
+
pricingSnapshot,
|
|
4044
|
+
recordedAt: new Date().toISOString(),
|
|
4045
|
+
metrics: [
|
|
4046
|
+
_extends._extends({
|
|
4047
|
+
unit: 'token',
|
|
4048
|
+
authority: 'provider'
|
|
4049
|
+
}, usage)
|
|
4050
|
+
]
|
|
4051
|
+
}));
|
|
4052
|
+
}
|
|
4053
|
+
return response;
|
|
4054
|
+
}
|
|
4055
|
+
constructor(input, usageCallbacks){
|
|
4056
|
+
super(input);
|
|
4057
|
+
this.usageCallbacks = usageCallbacks;
|
|
4058
|
+
}
|
|
4059
|
+
}
|
|
4060
|
+
|
|
3993
4061
|
const encodingCache = new Map();
|
|
3994
4062
|
/** Exact, model-independent text count for hard chunk limits. Treat special-token spellings as literal document text. */ function textEncoding() {
|
|
3995
4063
|
const cacheKey = 'encoding:cl100k_base';
|
|
@@ -5307,6 +5375,120 @@ console.log(JSON.stringify({ ...metrics, occurrences, changed }));
|
|
|
5307
5375
|
return `node -e '${script.replace(/'/g, "'\\''")}'`;
|
|
5308
5376
|
}
|
|
5309
5377
|
|
|
5378
|
+
const INDENTATION_SPACES = 2;
|
|
5379
|
+
/**
|
|
5380
|
+
* Node.js command template for recursive directory listing with depth control.
|
|
5381
|
+
*/ function buildListDirCommand(dirPath, displayPath, offset, limit, depth) {
|
|
5382
|
+
const pathB64 = Buffer.from(dirPath, 'utf-8').toString('base64');
|
|
5383
|
+
const displayPathB64 = Buffer.from(displayPath, 'utf-8').toString('base64');
|
|
5384
|
+
const safeOffset = Number.isFinite(offset) && offset > 0 ? Math.floor(offset) : 1;
|
|
5385
|
+
const safeLimit = Number.isFinite(limit) && limit > 0 ? Math.floor(limit) : 25;
|
|
5386
|
+
const safeDepth = Number.isFinite(depth) && depth > 0 ? Math.floor(depth) : 2;
|
|
5387
|
+
return `node -e "
|
|
5388
|
+
const fs = require('fs');
|
|
5389
|
+
const path = require('path');
|
|
5390
|
+
|
|
5391
|
+
const dirPath = Buffer.from('${pathB64}', 'base64').toString('utf-8');
|
|
5392
|
+
const displayPath = Buffer.from('${displayPathB64}', 'base64').toString('utf-8');
|
|
5393
|
+
const offset = ${safeOffset};
|
|
5394
|
+
const limit = ${safeLimit};
|
|
5395
|
+
const maxDepth = ${safeDepth};
|
|
5396
|
+
const INDENTATION_SPACES = ${INDENTATION_SPACES};
|
|
5397
|
+
|
|
5398
|
+
if (!path.isAbsolute(dirPath)) {
|
|
5399
|
+
console.error('Error: dir_path must be an absolute path');
|
|
5400
|
+
process.exit(1);
|
|
5401
|
+
}
|
|
5402
|
+
|
|
5403
|
+
if (!fs.existsSync(dirPath)) {
|
|
5404
|
+
console.error('Error: Directory not found');
|
|
5405
|
+
process.exit(1);
|
|
5406
|
+
}
|
|
5407
|
+
|
|
5408
|
+
if (!fs.statSync(dirPath).isDirectory()) {
|
|
5409
|
+
console.error('Error: Path is not a directory');
|
|
5410
|
+
process.exit(1);
|
|
5411
|
+
}
|
|
5412
|
+
|
|
5413
|
+
function collectEntries(currentPath, relativePrefix, remainingDepth, entries) {
|
|
5414
|
+
if (remainingDepth === 0) return;
|
|
5415
|
+
|
|
5416
|
+
try {
|
|
5417
|
+
const dirEntries = fs.readdirSync(currentPath, { withFileTypes: true });
|
|
5418
|
+
const sortedEntries = dirEntries
|
|
5419
|
+
.map(entry => {
|
|
5420
|
+
const fullPath = path.join(currentPath, entry.name);
|
|
5421
|
+
const relativePath = path.join(relativePrefix, entry.name);
|
|
5422
|
+
|
|
5423
|
+
let kind = 'file';
|
|
5424
|
+
if (entry.isSymbolicLink()) kind = 'symlink';
|
|
5425
|
+
else if (entry.isDirectory()) kind = 'directory';
|
|
5426
|
+
|
|
5427
|
+
return {
|
|
5428
|
+
fullPath,
|
|
5429
|
+
relativePath,
|
|
5430
|
+
kind,
|
|
5431
|
+
depth: relativePrefix.split(path.sep).filter(Boolean).length
|
|
5432
|
+
};
|
|
5433
|
+
})
|
|
5434
|
+
.sort((a, b) => a.relativePath.localeCompare(b.relativePath));
|
|
5435
|
+
|
|
5436
|
+
for (const entry of sortedEntries) {
|
|
5437
|
+
entries.push(entry);
|
|
5438
|
+
if (entry.kind === 'directory' && remainingDepth > 1) {
|
|
5439
|
+
collectEntries(entry.fullPath, entry.relativePath, remainingDepth - 1, entries);
|
|
5440
|
+
}
|
|
5441
|
+
}
|
|
5442
|
+
} catch (e) {
|
|
5443
|
+
// Skip unreadable directories
|
|
5444
|
+
}
|
|
5445
|
+
}
|
|
5446
|
+
|
|
5447
|
+
const allEntries = [];
|
|
5448
|
+
collectEntries(dirPath, '', maxDepth, allEntries);
|
|
5449
|
+
|
|
5450
|
+
if (allEntries.length === 0) {
|
|
5451
|
+
console.log('Workspace-relative directory: ' + displayPath);
|
|
5452
|
+
console.log('(Empty directory)');
|
|
5453
|
+
process.exit(0);
|
|
5454
|
+
}
|
|
5455
|
+
|
|
5456
|
+
const startIndex = offset - 1;
|
|
5457
|
+
if (startIndex >= allEntries.length) {
|
|
5458
|
+
console.error('Error: offset exceeds directory entry count');
|
|
5459
|
+
process.exit(1);
|
|
5460
|
+
}
|
|
5461
|
+
|
|
5462
|
+
const endIndex = Math.min(startIndex + limit, allEntries.length);
|
|
5463
|
+
const selectedEntries = allEntries.slice(startIndex, endIndex);
|
|
5464
|
+
|
|
5465
|
+
console.log('Workspace-relative directory: ' + displayPath);
|
|
5466
|
+
|
|
5467
|
+
for (const entry of selectedEntries) {
|
|
5468
|
+
const indent = ' '.repeat(entry.depth * INDENTATION_SPACES);
|
|
5469
|
+
let name = path.posix.join(displayPath, entry.relativePath.split(path.sep).join('/'));
|
|
5470
|
+
if (entry.kind === 'directory') name += '/';
|
|
5471
|
+
else if (entry.kind === 'symlink') name += '@';
|
|
5472
|
+
console.log(indent + name);
|
|
5473
|
+
}
|
|
5474
|
+
|
|
5475
|
+
if (endIndex < allEntries.length) {
|
|
5476
|
+
console.log('More than ' + limit + ' entries found');
|
|
5477
|
+
}
|
|
5478
|
+
"`;
|
|
5479
|
+
}
|
|
5480
|
+
|
|
5481
|
+
/** Format tool-owned paths only; file contents and backend filesystem authorization stay unchanged. */ function workspaceRelativeDisplayPath(workingDirectory, filePath) {
|
|
5482
|
+
if (!workingDirectory || !node_path.isAbsolute(workingDirectory)) {
|
|
5483
|
+
throw new Error('Sandbox working directory is not available.');
|
|
5484
|
+
}
|
|
5485
|
+
const value = node_path.relative(workingDirectory, node_path.resolve(workingDirectory, filePath));
|
|
5486
|
+
if (node_path.isAbsolute(value) || value === '..' || value.startsWith(`..${node_path.sep}`)) {
|
|
5487
|
+
throw new Error('Sandbox discovery path is outside the workspace.');
|
|
5488
|
+
}
|
|
5489
|
+
return value.split(node_path.sep).join('/') || '.';
|
|
5490
|
+
}
|
|
5491
|
+
|
|
5310
5492
|
const MAX_LINE_LENGTH = 500;
|
|
5311
5493
|
const MAX_GREP_LINE_LENGTH = 2000;
|
|
5312
5494
|
const GREP_RESULT_LIMIT = 100;
|
|
@@ -5448,112 +5630,6 @@ try {
|
|
|
5448
5630
|
}
|
|
5449
5631
|
"`;
|
|
5450
5632
|
}
|
|
5451
|
-
const INDENTATION_SPACES = 2;
|
|
5452
|
-
const MAX_ENTRY_LENGTH = 500;
|
|
5453
|
-
/**
|
|
5454
|
-
* Node.js command template for recursive directory listing with depth control.
|
|
5455
|
-
*/ function buildListDirCommand(dirPath, offset, limit, depth) {
|
|
5456
|
-
const pathB64 = utf8ToBase64(dirPath);
|
|
5457
|
-
const safeOffset = Number.isFinite(offset) && offset > 0 ? Math.floor(offset) : 1;
|
|
5458
|
-
const safeLimit = Number.isFinite(limit) && limit > 0 ? Math.floor(limit) : 25;
|
|
5459
|
-
const safeDepth = Number.isFinite(depth) && depth > 0 ? Math.floor(depth) : 2;
|
|
5460
|
-
return `node -e "
|
|
5461
|
-
const fs = require('fs');
|
|
5462
|
-
const path = require('path');
|
|
5463
|
-
|
|
5464
|
-
const dirPath = Buffer.from('${pathB64}', 'base64').toString('utf-8');
|
|
5465
|
-
const offset = ${safeOffset};
|
|
5466
|
-
const limit = ${safeLimit};
|
|
5467
|
-
const maxDepth = ${safeDepth};
|
|
5468
|
-
const INDENTATION_SPACES = ${INDENTATION_SPACES};
|
|
5469
|
-
const MAX_ENTRY_LENGTH = ${MAX_ENTRY_LENGTH};
|
|
5470
|
-
|
|
5471
|
-
if (!path.isAbsolute(dirPath)) {
|
|
5472
|
-
console.error('Error: dir_path must be an absolute path');
|
|
5473
|
-
process.exit(1);
|
|
5474
|
-
}
|
|
5475
|
-
|
|
5476
|
-
if (!fs.existsSync(dirPath)) {
|
|
5477
|
-
console.error('Error: Directory not found');
|
|
5478
|
-
process.exit(1);
|
|
5479
|
-
}
|
|
5480
|
-
|
|
5481
|
-
if (!fs.statSync(dirPath).isDirectory()) {
|
|
5482
|
-
console.error('Error: Path is not a directory');
|
|
5483
|
-
process.exit(1);
|
|
5484
|
-
}
|
|
5485
|
-
|
|
5486
|
-
function collectEntries(currentPath, relativePrefix, remainingDepth, entries) {
|
|
5487
|
-
if (remainingDepth === 0) return;
|
|
5488
|
-
|
|
5489
|
-
try {
|
|
5490
|
-
const dirEntries = fs.readdirSync(currentPath, { withFileTypes: true });
|
|
5491
|
-
const sortedEntries = dirEntries
|
|
5492
|
-
.map(entry => {
|
|
5493
|
-
const fullPath = path.join(currentPath, entry.name);
|
|
5494
|
-
const relativePath = path.join(relativePrefix, entry.name);
|
|
5495
|
-
const displayName = entry.name.length > MAX_ENTRY_LENGTH
|
|
5496
|
-
? entry.name.substring(0, MAX_ENTRY_LENGTH)
|
|
5497
|
-
: entry.name;
|
|
5498
|
-
|
|
5499
|
-
let kind = 'file';
|
|
5500
|
-
if (entry.isSymbolicLink()) kind = 'symlink';
|
|
5501
|
-
else if (entry.isDirectory()) kind = 'directory';
|
|
5502
|
-
|
|
5503
|
-
return {
|
|
5504
|
-
fullPath,
|
|
5505
|
-
relativePath,
|
|
5506
|
-
displayName,
|
|
5507
|
-
kind,
|
|
5508
|
-
depth: relativePrefix.split(path.sep).filter(Boolean).length
|
|
5509
|
-
};
|
|
5510
|
-
})
|
|
5511
|
-
.sort((a, b) => a.relativePath.localeCompare(b.relativePath));
|
|
5512
|
-
|
|
5513
|
-
for (const entry of sortedEntries) {
|
|
5514
|
-
entries.push(entry);
|
|
5515
|
-
if (entry.kind === 'directory' && remainingDepth > 1) {
|
|
5516
|
-
collectEntries(entry.fullPath, entry.relativePath, remainingDepth - 1, entries);
|
|
5517
|
-
}
|
|
5518
|
-
}
|
|
5519
|
-
} catch (e) {
|
|
5520
|
-
// Skip unreadable directories
|
|
5521
|
-
}
|
|
5522
|
-
}
|
|
5523
|
-
|
|
5524
|
-
const allEntries = [];
|
|
5525
|
-
collectEntries(dirPath, '', maxDepth, allEntries);
|
|
5526
|
-
|
|
5527
|
-
if (allEntries.length === 0) {
|
|
5528
|
-
console.log('Absolute path: ' + dirPath);
|
|
5529
|
-
console.log('(Empty directory)');
|
|
5530
|
-
process.exit(0);
|
|
5531
|
-
}
|
|
5532
|
-
|
|
5533
|
-
const startIndex = offset - 1;
|
|
5534
|
-
if (startIndex >= allEntries.length) {
|
|
5535
|
-
console.error('Error: offset exceeds directory entry count');
|
|
5536
|
-
process.exit(1);
|
|
5537
|
-
}
|
|
5538
|
-
|
|
5539
|
-
const endIndex = Math.min(startIndex + limit, allEntries.length);
|
|
5540
|
-
const selectedEntries = allEntries.slice(startIndex, endIndex);
|
|
5541
|
-
|
|
5542
|
-
console.log('Absolute path: ' + dirPath);
|
|
5543
|
-
|
|
5544
|
-
for (const entry of selectedEntries) {
|
|
5545
|
-
const indent = ' '.repeat(entry.depth * INDENTATION_SPACES);
|
|
5546
|
-
let name = entry.displayName;
|
|
5547
|
-
if (entry.kind === 'directory') name += '/';
|
|
5548
|
-
else if (entry.kind === 'symlink') name += '@';
|
|
5549
|
-
console.log(indent + name);
|
|
5550
|
-
}
|
|
5551
|
-
|
|
5552
|
-
if (endIndex < allEntries.length) {
|
|
5553
|
-
console.log('More than ' + limit + ' entries found');
|
|
5554
|
-
}
|
|
5555
|
-
"`;
|
|
5556
|
-
}
|
|
5557
5633
|
const TAB_WIDTH = 4;
|
|
5558
5634
|
const COMMENT_PREFIXES = [
|
|
5559
5635
|
'#',
|
|
@@ -5936,7 +6012,7 @@ try {
|
|
|
5936
6012
|
* @param offset - 1-indexed entry number to start from (default: 1)
|
|
5937
6013
|
* @param limit - Maximum number of entries to return (default: 25)
|
|
5938
6014
|
* @param depth - Maximum depth to traverse (default: 2)
|
|
5939
|
-
* @returns
|
|
6015
|
+
* @returns Directory tree whose entries are relative to the sandbox working directory
|
|
5940
6016
|
*/ async listDir(dirPath, offset = 1, limit = 25, depth = 2) {
|
|
5941
6017
|
if (offset < 1) {
|
|
5942
6018
|
return 'Error: offset must be a 1-indexed entry number';
|
|
@@ -5947,10 +6023,11 @@ try {
|
|
|
5947
6023
|
if (depth < 1) {
|
|
5948
6024
|
return 'Error: depth must be greater than zero';
|
|
5949
6025
|
}
|
|
5950
|
-
const
|
|
6026
|
+
const displayPath = workspaceRelativeDisplayPath(this.workingDirectory, dirPath);
|
|
6027
|
+
const command = buildListDirCommand(dirPath, displayPath, offset, limit, depth);
|
|
5951
6028
|
const result = await this.executeOperation(command, DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS);
|
|
5952
6029
|
if (result.exitCode !== 0) {
|
|
5953
|
-
return result.output || `Error: Failed to list directory '${
|
|
6030
|
+
return result.output || `Error: Failed to list directory '${displayPath}'`;
|
|
5954
6031
|
}
|
|
5955
6032
|
return result.output;
|
|
5956
6033
|
}
|
|
@@ -5999,16 +6076,19 @@ try {
|
|
|
5999
6076
|
return matches;
|
|
6000
6077
|
}
|
|
6001
6078
|
/**
|
|
6002
|
-
* Search file contents for a regex pattern, returning
|
|
6003
|
-
*/ async grep(pattern, path =
|
|
6004
|
-
const
|
|
6079
|
+
* Search file contents for a regex pattern, returning workspace-relative path labels.
|
|
6080
|
+
*/ async grep(pattern, path = this.workingDirectory, include = null) {
|
|
6081
|
+
const displayPath = workspaceRelativeDisplayPath(this.workingDirectory, path);
|
|
6082
|
+
const result = await this.grepRaw(pattern, node_path.resolve(this.workingDirectory, displayPath), include);
|
|
6005
6083
|
if (typeof result === 'string') {
|
|
6006
6084
|
return result;
|
|
6007
6085
|
}
|
|
6008
6086
|
if (result.length === 0) {
|
|
6009
6087
|
return 'No matches found';
|
|
6010
6088
|
}
|
|
6011
|
-
return formatGrepOutput(result)
|
|
6089
|
+
return formatGrepOutput(result.map((match)=>_extends._extends({}, match, {
|
|
6090
|
+
path: workspaceRelativeDisplayPath(this.workingDirectory, match.path)
|
|
6091
|
+
})));
|
|
6012
6092
|
}
|
|
6013
6093
|
/**
|
|
6014
6094
|
* Structured glob matching returning FileInfo objects.
|
|
@@ -6033,13 +6113,17 @@ try {
|
|
|
6033
6113
|
return infos;
|
|
6034
6114
|
}
|
|
6035
6115
|
/**
|
|
6036
|
-
* Find files matching a glob pattern, returning
|
|
6037
|
-
*/ async glob(pattern, path =
|
|
6038
|
-
const
|
|
6116
|
+
* Find files matching a glob pattern, returning workspace-relative paths.
|
|
6117
|
+
*/ async glob(pattern, path = this.workingDirectory) {
|
|
6118
|
+
const displayPath = workspaceRelativeDisplayPath(this.workingDirectory, path);
|
|
6119
|
+
const searchPath = node_path.resolve(this.workingDirectory, displayPath);
|
|
6120
|
+
const files = await this.globInfo(pattern, searchPath);
|
|
6039
6121
|
if (files.length === 0) {
|
|
6040
6122
|
return 'No files found';
|
|
6041
6123
|
}
|
|
6042
|
-
return formatGlobOutput(files)
|
|
6124
|
+
return formatGlobOutput(files.map((file)=>_extends._extends({}, file, {
|
|
6125
|
+
path: workspaceRelativeDisplayPath(this.workingDirectory, node_path.resolve(searchPath, file.path))
|
|
6126
|
+
})));
|
|
6043
6127
|
}
|
|
6044
6128
|
/**
|
|
6045
6129
|
* Create a new file with content.
|
|
@@ -6830,11 +6914,15 @@ exports.ArtifactPresentationRegistry = __decorate([
|
|
|
6830
6914
|
collection: v3.z.object({
|
|
6831
6915
|
allowCopy: v3.z.boolean()
|
|
6832
6916
|
}).strict().optional(),
|
|
6917
|
+
versioning: v3.z.object({
|
|
6918
|
+
mode: v3.z.literal('draft-only')
|
|
6919
|
+
}).strict().optional(),
|
|
6833
6920
|
content: v3.z.object({
|
|
6834
6921
|
mimeTypes: v3.z.array(v3.z.string().min(1)).min(1),
|
|
6835
6922
|
maxBytes: v3.z.number().int().positive()
|
|
6836
6923
|
}).strict().optional(),
|
|
6837
6924
|
sharing: v3.z.object({
|
|
6925
|
+
projectAccess: v3.z.literal('link-audience').optional(),
|
|
6838
6926
|
accessModes: v3.z.array(v3.z.enum([
|
|
6839
6927
|
'owner_only',
|
|
6840
6928
|
'workspace_all',
|
|
@@ -6860,7 +6948,13 @@ exports.ArtifactPresentationRegistry = __decorate([
|
|
|
6860
6948
|
'authenticated'
|
|
6861
6949
|
])
|
|
6862
6950
|
}).strict()
|
|
6863
|
-
}).strict()
|
|
6951
|
+
}).strict().refine((definition)=>{
|
|
6952
|
+
var _definition_sharing;
|
|
6953
|
+
return ((_definition_sharing = definition.sharing) == null ? void 0 : _definition_sharing.projectAccess) !== 'link-audience' || definition.presentation.mode === 'authenticated' && definition.sharing.accessModes.every((mode)=>[
|
|
6954
|
+
'organization_all',
|
|
6955
|
+
'workspace_all'
|
|
6956
|
+
].includes(mode));
|
|
6957
|
+
}, 'Project link audiences require authenticated organization or workspace sharing');
|
|
6864
6958
|
|
|
6865
6959
|
const artifactTypeKey = (type)=>JSON.stringify([
|
|
6866
6960
|
type.pluginName,
|
|
@@ -11304,6 +11398,7 @@ Object.defineProperty(exports, "resourceCardId", {
|
|
|
11304
11398
|
});
|
|
11305
11399
|
exports.ActorTokenRuntimeCapability = modelProvider.ActorTokenRuntimeCapability;
|
|
11306
11400
|
exports.ActorTokenRuntimeFactoryCapability = modelProvider.ActorTokenRuntimeFactoryCapability;
|
|
11401
|
+
exports.ArtifactContentRuntimeCapability = modelProvider.ArtifactContentRuntimeCapability;
|
|
11307
11402
|
exports.ArtifactDraftsRuntimeCapability = modelProvider.ArtifactDraftsRuntimeCapability;
|
|
11308
11403
|
exports.ArtifactLibraryRuntimeCapability = modelProvider.ArtifactLibraryRuntimeCapability;
|
|
11309
11404
|
exports.ArtifactsRuntimeCapability = modelProvider.ArtifactsRuntimeCapability;
|
|
@@ -11335,6 +11430,7 @@ exports.createRuntimeCapability = modelProvider.createRuntimeCapability;
|
|
|
11335
11430
|
exports.isSandboxJobRuntimeError = modelProvider.isSandboxJobRuntimeError;
|
|
11336
11431
|
exports.workspaceFileMutationMetadata = modelProvider.workspaceFileMutationMetadata;
|
|
11337
11432
|
exports.workspaceFileMutationPath = modelProvider.workspaceFileMutationPath;
|
|
11433
|
+
exports.workspaceRelativeDirectoryPathSchema = modelProvider.workspaceRelativeDirectoryPathSchema;
|
|
11338
11434
|
exports.workspaceRelativeFilePathSchema = modelProvider.workspaceRelativeFilePathSchema;
|
|
11339
11435
|
exports.DataSourceRuntimeCapability = dataWorkbench.DataSourceRuntimeCapability;
|
|
11340
11436
|
exports.analyticsBindingObjectSchema = analyticsResult.analyticsBindingObjectSchema;
|
|
@@ -11498,6 +11594,7 @@ exports.MODEL_OUTPUT_VALIDATION_ERROR_CODE = MODEL_OUTPUT_VALIDATION_ERROR_CODE;
|
|
|
11498
11594
|
exports.ModelExecutionEnvironmentCapability = ModelExecutionEnvironmentCapability;
|
|
11499
11595
|
exports.ModelOutputValidationError = ModelOutputValidationError;
|
|
11500
11596
|
exports.ORGANIZATION_METADATA_KEY = ORGANIZATION_METADATA_KEY;
|
|
11597
|
+
exports.OpenAICompatibleEmbeddings = OpenAICompatibleEmbeddings;
|
|
11501
11598
|
exports.OpenAICompatibleReranker = OpenAICompatibleReranker;
|
|
11502
11599
|
exports.PERMISSION_OPERATION_METADATA_KEY = PERMISSION_OPERATION_METADATA_KEY;
|
|
11503
11600
|
exports.PLUGIN_CONFIG_RESOLVER_TOKEN = PLUGIN_CONFIG_RESOLVER_TOKEN;
|