@xpert-ai/plugin-sdk 3.37.0 → 3.38.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 +1 -1
- package/artifact-document.esm.js +1 -1
- package/docs/README.md +87 -0
- package/docs/artifact-documents.md +1 -1
- package/index.cjs.js +345 -102
- package/index.esm.js +338 -104
- package/model-provider.cjs.js +3 -0
- package/model-provider.esm.js +3 -1
- package/package.json +2 -2
- package/src/index.d.ts +1 -0
- package/src/lib/artifact-document/host.d.ts +2 -0
- package/src/lib/core/index.d.ts +2 -0
- package/src/lib/core/named-provider.registry.d.ts +9 -0
- package/src/lib/core/provider-registration.d.ts +9 -0
- package/src/lib/project-pipeline/adapters.d.ts +3 -2
- package/src/lib/rag/capability/knowledgebase-documents.d.ts +9 -0
- package/src/lib/runtime/capabilities/conversation.d.ts +8 -0
- package/src/lib/runtime/capabilities/index.d.ts +1 -0
- package/src/lib/sandbox/file-edit-command.d.ts +2 -1
- package/src/lib/sandbox/file-edits.d.ts +1 -0
- package/src/lib/sandbox/protocol.d.ts +7 -1
- package/src/lib/strategy.d.ts +8 -2
- package/src/lib/widgets/index.d.ts +2 -0
- package/src/lib/widgets/message-widget-provider/index.d.ts +3 -0
- package/src/lib/widgets/message-widget-provider/provider.decorator.d.ts +2 -0
- package/src/lib/widgets/message-widget-provider/provider.registry.d.ts +7 -0
- package/src/lib/widgets/message-widget-provider/types.d.ts +16 -0
- package/src/lib/widgets/widget-action/action.decorator.d.ts +2 -0
- package/src/lib/widgets/widget-action/action.registry.d.ts +8 -0
- package/src/lib/widgets/widget-action/index.d.ts +3 -0
- package/src/lib/widgets/widget-action/types.d.ts +19 -0
package/index.cjs.js
CHANGED
|
@@ -516,9 +516,15 @@ exports.StrategyBus = __decorate([
|
|
|
516
516
|
|
|
517
517
|
class BaseStrategyRegistry {
|
|
518
518
|
onModuleInit() {
|
|
519
|
-
|
|
519
|
+
var _this_strategySubscription;
|
|
520
|
+
(_this_strategySubscription = this.strategySubscription) == null ? void 0 : _this_strategySubscription.unsubscribe();
|
|
521
|
+
this.strategySubscription = this.bus.events$.pipe(rxjs.filter((event)=>!event.strategyType || event.strategyType === this.strategyKey)).subscribe((evt)=>{
|
|
520
522
|
if (evt.type === 'UPSERT') {
|
|
521
|
-
|
|
523
|
+
try {
|
|
524
|
+
this.upsert(evt.entry.instance);
|
|
525
|
+
} catch (error) {
|
|
526
|
+
this.onRegistrationError(error);
|
|
527
|
+
}
|
|
522
528
|
} else if (evt.type === 'REMOVE') {
|
|
523
529
|
this.remove(evt.orgId, evt.pluginName);
|
|
524
530
|
}
|
|
@@ -530,6 +536,14 @@ class BaseStrategyRegistry {
|
|
|
530
536
|
this.upsert(instance);
|
|
531
537
|
}
|
|
532
538
|
}
|
|
539
|
+
onModuleDestroy() {
|
|
540
|
+
var _this_strategySubscription;
|
|
541
|
+
(_this_strategySubscription = this.strategySubscription) == null ? void 0 : _this_strategySubscription.unsubscribe();
|
|
542
|
+
this.strategySubscription = undefined;
|
|
543
|
+
}
|
|
544
|
+
/** Policy for rejected registrations delivered by the lifecycle bus. */ onRegistrationError(error) {
|
|
545
|
+
throw error;
|
|
546
|
+
}
|
|
533
547
|
upsert(instance) {
|
|
534
548
|
const target = resolveStrategyMetadataTarget(instance);
|
|
535
549
|
if (!target) {
|
|
@@ -638,6 +652,14 @@ class BaseStrategyRegistry {
|
|
|
638
652
|
}
|
|
639
653
|
return scopeKeys;
|
|
640
654
|
}
|
|
655
|
+
/** Resolves a registered name in the effective scope, without requiring a match. */ findByName(type, organizationId) {
|
|
656
|
+
for (const scopeKey of this.resolveStrategyScopeKeys(organizationId)){
|
|
657
|
+
var _this_strategies_get;
|
|
658
|
+
const strategy = (_this_strategies_get = this.strategies.get(scopeKey)) == null ? void 0 : _this_strategies_get.get(type);
|
|
659
|
+
if (strategy) return strategy;
|
|
660
|
+
}
|
|
661
|
+
return undefined;
|
|
662
|
+
}
|
|
641
663
|
/**
|
|
642
664
|
* Get strategy by type from the given organization including global strategies as fallback.
|
|
643
665
|
*
|
|
@@ -645,11 +667,7 @@ class BaseStrategyRegistry {
|
|
|
645
667
|
* @param organizationId
|
|
646
668
|
* @returns
|
|
647
669
|
*/ get(type, organizationId) {
|
|
648
|
-
|
|
649
|
-
const strategy = this.resolveStrategyScopeKeys(organizationId).map((scopeKey)=>{
|
|
650
|
-
var _this_strategies_get;
|
|
651
|
-
return (_this_strategies_get = this.strategies.get(scopeKey)) == null ? void 0 : _this_strategies_get.get(type);
|
|
652
|
-
}).find((item)=>!!item);
|
|
670
|
+
const strategy = this.findByName(type, organizationId);
|
|
653
671
|
if (!strategy) {
|
|
654
672
|
throw new Error(`No strategy found for type '${type}' for strategy '${this.strategyKey}'`);
|
|
655
673
|
}
|
|
@@ -837,6 +855,117 @@ exports.ResourceCardProviderRegistry = ResourceCardProviderRegistry_1 = __decora
|
|
|
837
855
|
])
|
|
838
856
|
], exports.ResourceCardProviderRegistry);
|
|
839
857
|
|
|
858
|
+
const kindPrefix = 'xpert:provider-registration:';
|
|
859
|
+
/** Declares a plugin-owned strategy category with a stable metadata key across SDK copies. */ function definePluginRegistration(metadataKey, kind = metadataKey) {
|
|
860
|
+
if (!metadataKey || metadataKey.trim() !== metadataKey || metadataKey === STRATEGY_META_KEY || metadataKey.startsWith(kindPrefix)) throw new Error('Invalid provider registration metadata key');
|
|
861
|
+
if (!kind || kind.trim() !== kind) throw new Error('A provider registration requires an exact category');
|
|
862
|
+
return (name)=>{
|
|
863
|
+
if (!name || name.trim() !== name) throw new Error('A provider registration requires an exact name');
|
|
864
|
+
return common.applyDecorators(common.Injectable(), common.SetMetadata(STRATEGY_META_KEY, metadataKey), common.SetMetadata(metadataKey, name), common.SetMetadata(kindPrefix + metadataKey, kind));
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
function assertPluginRegistrationOwner(name, pluginName) {
|
|
868
|
+
const separator = name.indexOf(':');
|
|
869
|
+
const owner = separator < 0 ? undefined : name.slice(0, separator);
|
|
870
|
+
const localName = name.slice(separator + 1);
|
|
871
|
+
if (owner !== pluginName || name.trim() !== name || !/^[a-zA-Z0-9_-]+(?:\.[a-zA-Z0-9_-]+)*$/.test(localName)) throw new Error(`Registration '${name}' does not belong to ${pluginName != null ? pluginName : 'the platform'}`);
|
|
872
|
+
}
|
|
873
|
+
function readPluginProviderRegistrations(target, pluginName) {
|
|
874
|
+
const claims = [];
|
|
875
|
+
for (const key of Reflect.getMetadataKeys(target)){
|
|
876
|
+
if (typeof key !== 'string' || !key.startsWith(kindPrefix)) continue;
|
|
877
|
+
const metadataKey = key.slice(kindPrefix.length);
|
|
878
|
+
const kind = Reflect.getMetadata(key, target);
|
|
879
|
+
if (typeof kind !== 'string' || !kind.trim() || kind.trim() !== kind) throw new Error(`Invalid provider registration category for '${metadataKey}'`);
|
|
880
|
+
const name = Reflect.getMetadata(metadataKey, target);
|
|
881
|
+
if (typeof name !== 'string') throw new Error(`Invalid ${kind} registration name`);
|
|
882
|
+
assertPluginRegistrationOwner(name, pluginName);
|
|
883
|
+
claims.push({
|
|
884
|
+
kind,
|
|
885
|
+
key: name
|
|
886
|
+
});
|
|
887
|
+
}
|
|
888
|
+
return claims;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
const MESSAGE_WIDGET_PROVIDER = 'XPERT_MESSAGE_WIDGET_PROVIDER';
|
|
892
|
+
const MessageWidgetProvider = definePluginRegistration(MESSAGE_WIDGET_PROVIDER, 'widget provider');
|
|
893
|
+
|
|
894
|
+
/** Opt-in registry for validated, owner-qualified providers that cannot replace a different live instance. */ class NamedProviderRegistry extends BaseStrategyRegistry {
|
|
895
|
+
upsert(instance) {
|
|
896
|
+
const target = resolveStrategyMetadataTarget(instance);
|
|
897
|
+
const name = target && this.reflector.get(this.strategyKey, target);
|
|
898
|
+
if (name == null) return;
|
|
899
|
+
if (typeof name !== 'string' || !name) throw new Error(`Invalid ${this.strategyKey} registration name`);
|
|
900
|
+
if (!instance || typeof instance !== 'object' || !this.isProvider(instance)) throw new Error(`Invalid ${this.strategyKey} provider '${name}'`);
|
|
901
|
+
this.register(name, instance, this.getSource(instance));
|
|
902
|
+
}
|
|
903
|
+
assertCanRegister(name, instance, source) {
|
|
904
|
+
var _this_strategies_get;
|
|
905
|
+
assertPluginRegistrationOwner(name, source.kind === 'plugin' ? source.pluginName : undefined);
|
|
906
|
+
const current = (_this_strategies_get = this.strategies.get(source.scopeKey)) == null ? void 0 : _this_strategies_get.get(name);
|
|
907
|
+
if (current && current !== instance) throw new Error(`Provider '${name}' is already registered in this scope`);
|
|
908
|
+
super.assertCanRegister(name, instance, source);
|
|
909
|
+
}
|
|
910
|
+
onRegistrationError(error) {
|
|
911
|
+
this.providerLogger.warn(error instanceof Error ? error.message : 'Invalid provider registration');
|
|
912
|
+
}
|
|
913
|
+
constructor(...args){
|
|
914
|
+
super(...args);
|
|
915
|
+
this.providerLogger = new common.Logger(this.constructor.name);
|
|
916
|
+
}
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
exports.MessageWidgetProviderRegistry = class MessageWidgetProviderRegistry extends NamedProviderRegistry {
|
|
920
|
+
isProvider(instance) {
|
|
921
|
+
return 'resolve' in instance && typeof instance.resolve === 'function';
|
|
922
|
+
}
|
|
923
|
+
constructor(discovery, reflector){
|
|
924
|
+
super(MESSAGE_WIDGET_PROVIDER, discovery, reflector);
|
|
925
|
+
}
|
|
926
|
+
};
|
|
927
|
+
exports.MessageWidgetProviderRegistry = __decorate([
|
|
928
|
+
common.Injectable(),
|
|
929
|
+
__metadata("design:paramtypes", [
|
|
930
|
+
core.DiscoveryService,
|
|
931
|
+
core.Reflector
|
|
932
|
+
])
|
|
933
|
+
], exports.MessageWidgetProviderRegistry);
|
|
934
|
+
|
|
935
|
+
const WIDGET_ACTION_PROVIDER = 'XPERT_WIDGET_ACTION_PROVIDER';
|
|
936
|
+
const WidgetActionProvider = definePluginRegistration(WIDGET_ACTION_PROVIDER, 'widget action provider');
|
|
937
|
+
|
|
938
|
+
const localActionName = /^[a-zA-Z0-9_-]+$/;
|
|
939
|
+
exports.WidgetActionProviderRegistry = class WidgetActionProviderRegistry extends NamedProviderRegistry {
|
|
940
|
+
isProvider(instance) {
|
|
941
|
+
if (!('actions' in instance) || !instance.actions || typeof instance.actions !== 'object' || Array.isArray(instance.actions)) return false;
|
|
942
|
+
const entries = Object.entries(instance.actions);
|
|
943
|
+
return entries.length > 0 && entries.every(([name, handler])=>localActionName.test(name) && isActionHandler(handler));
|
|
944
|
+
}
|
|
945
|
+
resolve(action) {
|
|
946
|
+
const separator = action.lastIndexOf('.');
|
|
947
|
+
if (separator < 1) return undefined;
|
|
948
|
+
const name = action.slice(separator + 1);
|
|
949
|
+
if (!localActionName.test(name)) return undefined;
|
|
950
|
+
const provider = this.findByName(action.slice(0, separator));
|
|
951
|
+
if (!provider || !Object.prototype.hasOwnProperty.call(provider.actions, name)) return undefined;
|
|
952
|
+
return provider.actions[name];
|
|
953
|
+
}
|
|
954
|
+
constructor(discovery, reflector){
|
|
955
|
+
super(WIDGET_ACTION_PROVIDER, discovery, reflector);
|
|
956
|
+
}
|
|
957
|
+
};
|
|
958
|
+
exports.WidgetActionProviderRegistry = __decorate([
|
|
959
|
+
common.Injectable(),
|
|
960
|
+
__metadata("design:paramtypes", [
|
|
961
|
+
core.DiscoveryService,
|
|
962
|
+
core.Reflector
|
|
963
|
+
])
|
|
964
|
+
], exports.WidgetActionProviderRegistry);
|
|
965
|
+
function isActionHandler(value) {
|
|
966
|
+
return !!value && typeof value === 'object' && 'execute' in value && typeof value.execute === 'function' && (!('widgetSource' in value) || value.widgetSource === undefined || value.widgetSource === 'message' || value.widgetSource === 'receipt');
|
|
967
|
+
}
|
|
968
|
+
|
|
840
969
|
function createPluginLogger(scope, baseMeta = {}) {
|
|
841
970
|
const nestLogger = new common.Logger(scope);
|
|
842
971
|
const wrap = (level, msg, meta)=>{
|
|
@@ -5224,6 +5353,105 @@ function resolveSandboxBackend(sandbox) {
|
|
|
5224
5353
|
return isSandboxBackend(candidate) ? candidate : null;
|
|
5225
5354
|
}
|
|
5226
5355
|
|
|
5356
|
+
// Embedded in the existing sandbox Node process; no Git, subprocess, or temporary files.
|
|
5357
|
+
const FILE_EDIT_DIFF_SCRIPT = String.raw`
|
|
5358
|
+
function inspectLineDiff(before, after) {
|
|
5359
|
+
if (before === after) return { diff: { removed: 0, added: 0 } };
|
|
5360
|
+
// Include line terminators so a missing final newline is an actual line change.
|
|
5361
|
+
const oldLines = before.match(/[^\n]*\n|[^\n]+$/g) || [];
|
|
5362
|
+
const newLines = after.match(/[^\n]*\n|[^\n]+$/g) || [];
|
|
5363
|
+
let start = 0, oldEnd = oldLines.length, newEnd = newLines.length;
|
|
5364
|
+
while (start < oldEnd && start < newEnd && oldLines[start] === newLines[start]) start++;
|
|
5365
|
+
while (oldEnd > start && newEnd > start && oldLines[oldEnd - 1] === newLines[newEnd - 1]) {
|
|
5366
|
+
oldEnd--;
|
|
5367
|
+
newEnd--;
|
|
5368
|
+
}
|
|
5369
|
+
const removed = oldEnd - start, added = newEnd - start;
|
|
5370
|
+
if (!removed || !added) return { diff: { removed, added } };
|
|
5371
|
+
|
|
5372
|
+
// Myers shortest edit distance needs only a frontier when reporting counts, not a patch.
|
|
5373
|
+
// Bound the optional quadratic search on broad rewrites; never limit the edit itself.
|
|
5374
|
+
const maxDistance = Math.min(removed + added, 2000);
|
|
5375
|
+
const offset = maxDistance + 1;
|
|
5376
|
+
const frontier = new Int32Array(2 * maxDistance + 3);
|
|
5377
|
+
let work = 0;
|
|
5378
|
+
for (let distance = 0; distance <= maxDistance; distance++) {
|
|
5379
|
+
for (let diagonal = -distance; diagonal <= distance; diagonal += 2) {
|
|
5380
|
+
if (++work > 1000000) return { diffUnavailable: 'comparison_budget_exceeded' };
|
|
5381
|
+
const index = offset + diagonal;
|
|
5382
|
+
let x = diagonal === -distance || (diagonal !== distance && frontier[index - 1] < frontier[index + 1])
|
|
5383
|
+
? frontier[index + 1]
|
|
5384
|
+
: frontier[index - 1] + 1;
|
|
5385
|
+
let y = x - diagonal;
|
|
5386
|
+
while (x < removed && y < added && oldLines[start + x] === newLines[start + y]) {
|
|
5387
|
+
if (++work > 1000000) return { diffUnavailable: 'comparison_budget_exceeded' };
|
|
5388
|
+
x++;
|
|
5389
|
+
y++;
|
|
5390
|
+
}
|
|
5391
|
+
if (x >= removed && y >= added) {
|
|
5392
|
+
return { diff: { removed: (distance + removed - added) / 2, added: (distance + added - removed) / 2 } };
|
|
5393
|
+
}
|
|
5394
|
+
frontier[index] = x;
|
|
5395
|
+
}
|
|
5396
|
+
}
|
|
5397
|
+
return { diffUnavailable: 'comparison_budget_exceeded' };
|
|
5398
|
+
}
|
|
5399
|
+
`;
|
|
5400
|
+
|
|
5401
|
+
// The same comparison runs for single and grouped edits. Only values encoded as
|
|
5402
|
+
// JSON/base64 enter the shell, never literal paths or replacement strings.
|
|
5403
|
+
function command(filePath, edits, batch) {
|
|
5404
|
+
const encoded = Buffer.from(JSON.stringify({
|
|
5405
|
+
filePath,
|
|
5406
|
+
edits,
|
|
5407
|
+
batch
|
|
5408
|
+
})).toString('base64');
|
|
5409
|
+
const script = `
|
|
5410
|
+
const fs = require('node:fs');
|
|
5411
|
+
const input = JSON.parse(Buffer.from('${encoded}', 'base64').toString('utf8'));
|
|
5412
|
+
const lines = text => text.length ? text.split('\\n').length - Number(text.endsWith('\\n')) : 0;
|
|
5413
|
+
${FILE_EDIT_DIFF_SCRIPT}
|
|
5414
|
+
let source;
|
|
5415
|
+
try { source = fs.readFileSync(input.filePath, 'utf8'); } catch {}
|
|
5416
|
+
let content = source;
|
|
5417
|
+
const steps = [];
|
|
5418
|
+
for (const edit of input.edits) {
|
|
5419
|
+
const metrics = { oldLines: lines(edit.oldString), newLines: lines(edit.newString) };
|
|
5420
|
+
const parts = content === undefined ? [] : content.split(edit.oldString);
|
|
5421
|
+
const count = parts.length - 1;
|
|
5422
|
+
const code = content === undefined ? 3 : count === 0 ? 1 : count > 1 && !edit.replaceAll ? 2 : 0;
|
|
5423
|
+
if (code) {
|
|
5424
|
+
steps.push({ code, metrics: { ...metrics, occurrences: 0, changed: false, diff: { removed: 0, added: 0 } } });
|
|
5425
|
+
break;
|
|
5426
|
+
}
|
|
5427
|
+
const after = parts.join(edit.newString);
|
|
5428
|
+
try { Object.assign(metrics, inspectLineDiff(content, after)); } catch { metrics.diffUnavailable = 'diff_unavailable'; }
|
|
5429
|
+
// A direct SDK edit of empty search text in an empty file historically reports one no-op.
|
|
5430
|
+
const occurrences = input.batch && count < 0 ? 1 : count;
|
|
5431
|
+
steps.push({ code, metrics: { ...metrics, occurrences, changed: content !== after } });
|
|
5432
|
+
content = after;
|
|
5433
|
+
}
|
|
5434
|
+
// A logical mismatch commits its valid prefix. An I/O failure must never emit
|
|
5435
|
+
// a successful receipt (or cause the host to replay a possibly committed edit).
|
|
5436
|
+
if (source !== content) fs.writeFileSync(input.filePath, content, 'utf8');
|
|
5437
|
+
if (input.batch) console.log(JSON.stringify(steps));
|
|
5438
|
+
else { console.log(JSON.stringify(steps[0].metrics)); process.exitCode = steps[0].code; }
|
|
5439
|
+
`;
|
|
5440
|
+
return `node -e '${script.replace(/'/g, "'\\''")}'`;
|
|
5441
|
+
}
|
|
5442
|
+
function buildEditCommand(filePath, oldString, newString, replaceAll) {
|
|
5443
|
+
return command(filePath, [
|
|
5444
|
+
{
|
|
5445
|
+
oldString,
|
|
5446
|
+
newString,
|
|
5447
|
+
replaceAll
|
|
5448
|
+
}
|
|
5449
|
+
], false);
|
|
5450
|
+
}
|
|
5451
|
+
function buildBatchEditCommand(filePath, edits) {
|
|
5452
|
+
return command(filePath, edits, true);
|
|
5453
|
+
}
|
|
5454
|
+
|
|
5227
5455
|
const editMetricsSchema = v3.z.object({
|
|
5228
5456
|
occurrences: v3.z.number().int().nonnegative(),
|
|
5229
5457
|
oldLines: v3.z.number().int().nonnegative(),
|
|
@@ -5283,121 +5511,124 @@ function editCommandResult(filePath, result) {
|
|
|
5283
5511
|
};
|
|
5284
5512
|
}
|
|
5285
5513
|
}
|
|
5286
|
-
|
|
5287
|
-
const
|
|
5288
|
-
if (!
|
|
5514
|
+
function sequenceResult(path, results) {
|
|
5515
|
+
const count = results.length;
|
|
5516
|
+
if (!count) return {
|
|
5289
5517
|
error: 'No edits provided',
|
|
5290
5518
|
progress: {
|
|
5291
5519
|
mode: 'sequential',
|
|
5292
5520
|
appliedEdits: 0
|
|
5293
5521
|
}
|
|
5294
5522
|
};
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
|
|
5299
|
-
error: `Multi-edit failed at edit ${results.length}: ${result.error}`,
|
|
5300
|
-
path: filePath,
|
|
5523
|
+
const last = results[count - 1];
|
|
5524
|
+
if (last.error) {
|
|
5525
|
+
return {
|
|
5526
|
+
path,
|
|
5301
5527
|
filesUpdate: null,
|
|
5302
5528
|
results,
|
|
5529
|
+
error: `Multi-edit failed at edit ${count}: ${last.error}`,
|
|
5303
5530
|
progress: {
|
|
5304
5531
|
mode: 'sequential',
|
|
5305
|
-
appliedEdits:
|
|
5306
|
-
failedEdit:
|
|
5532
|
+
appliedEdits: count - 1,
|
|
5533
|
+
failedEdit: count
|
|
5307
5534
|
}
|
|
5308
5535
|
};
|
|
5309
5536
|
}
|
|
5310
5537
|
return {
|
|
5311
|
-
path
|
|
5538
|
+
path,
|
|
5312
5539
|
filesUpdate: null,
|
|
5313
5540
|
results,
|
|
5314
5541
|
progress: {
|
|
5315
5542
|
mode: 'sequential',
|
|
5316
|
-
appliedEdits:
|
|
5543
|
+
appliedEdits: count
|
|
5317
5544
|
}
|
|
5318
5545
|
};
|
|
5319
5546
|
}
|
|
5320
|
-
|
|
5321
|
-
|
|
5322
|
-
const
|
|
5323
|
-
|
|
5324
|
-
|
|
5325
|
-
|
|
5326
|
-
|
|
5327
|
-
|
|
5328
|
-
|
|
5329
|
-
|
|
5330
|
-
|
|
5331
|
-
|
|
5332
|
-
|
|
5333
|
-
|
|
5334
|
-
|
|
5335
|
-
|
|
5336
|
-
|
|
5337
|
-
|
|
5338
|
-
|
|
5339
|
-
|
|
5340
|
-
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
for (let diagonal = -distance; diagonal <= distance; diagonal += 2) {
|
|
5345
|
-
if (++work > 1000000) return { diffUnavailable: 'comparison_budget_exceeded' };
|
|
5346
|
-
const index = offset + diagonal;
|
|
5347
|
-
let x = diagonal === -distance || (diagonal !== distance && frontier[index - 1] < frontier[index + 1])
|
|
5348
|
-
? frontier[index + 1]
|
|
5349
|
-
: frontier[index - 1] + 1;
|
|
5350
|
-
let y = x - diagonal;
|
|
5351
|
-
while (x < removed && y < added && oldLines[start + x] === newLines[start + y]) {
|
|
5352
|
-
if (++work > 1000000) return { diffUnavailable: 'comparison_budget_exceeded' };
|
|
5353
|
-
x++;
|
|
5354
|
-
y++;
|
|
5355
|
-
}
|
|
5356
|
-
if (x >= removed && y >= added) {
|
|
5357
|
-
return { diff: { removed: (distance + removed - added) / 2, added: (distance + added - removed) / 2 } };
|
|
5358
|
-
}
|
|
5359
|
-
frontier[index] = x;
|
|
5547
|
+
/** Stops on failure; never promises rollback or silently reapplies completed edits. */ async function sequentialFileEdits(filePath, edits, apply) {
|
|
5548
|
+
const results = [];
|
|
5549
|
+
for (const edit of edits != null ? edits : []){
|
|
5550
|
+
const result = await apply(edit);
|
|
5551
|
+
results.push(result);
|
|
5552
|
+
if (result.error) break;
|
|
5553
|
+
}
|
|
5554
|
+
return sequenceResult(filePath, results);
|
|
5555
|
+
}
|
|
5556
|
+
const batchReceiptSchema = v3.z.array(v3.z.object({
|
|
5557
|
+
code: v3.z.union([
|
|
5558
|
+
v3.z.literal(0),
|
|
5559
|
+
v3.z.literal(1),
|
|
5560
|
+
v3.z.literal(2),
|
|
5561
|
+
v3.z.literal(3)
|
|
5562
|
+
]),
|
|
5563
|
+
metrics: editMetricsSchema
|
|
5564
|
+
}));
|
|
5565
|
+
function batchSteps(output, count) {
|
|
5566
|
+
let raw;
|
|
5567
|
+
try {
|
|
5568
|
+
raw = JSON.parse(output);
|
|
5569
|
+
} catch (e) {
|
|
5570
|
+
return undefined;
|
|
5360
5571
|
}
|
|
5361
|
-
|
|
5362
|
-
|
|
5363
|
-
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5368
|
-
|
|
5369
|
-
|
|
5370
|
-
|
|
5371
|
-
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
|
|
5375
|
-
|
|
5376
|
-
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
|
|
5380
|
-
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
|
|
5391
|
-
|
|
5392
|
-
|
|
5393
|
-
|
|
5394
|
-
|
|
5395
|
-
|
|
5396
|
-
|
|
5397
|
-
}
|
|
5398
|
-
|
|
5399
|
-
|
|
5400
|
-
|
|
5572
|
+
const parsed = batchReceiptSchema.safeParse(raw);
|
|
5573
|
+
if (!parsed.success) return undefined;
|
|
5574
|
+
const steps = parsed.data;
|
|
5575
|
+
const failure = steps.findIndex((step)=>step.code !== 0);
|
|
5576
|
+
if (!steps.length || steps.length > count) return undefined;
|
|
5577
|
+
if (steps.some(({ code, metrics })=>code === 0 ? metrics.occurrences === 0 : metrics.changed || metrics.occurrences !== 0)) return undefined;
|
|
5578
|
+
if (failure < 0 ? steps.length !== count : failure !== steps.length - 1) return undefined;
|
|
5579
|
+
return steps;
|
|
5580
|
+
}
|
|
5581
|
+
/** Keep the encoded shell argument bounded. An oversized edit runs alone. */ function batchEnd(path, edits, start) {
|
|
5582
|
+
let bytes = Buffer.byteLength(JSON.stringify(path));
|
|
5583
|
+
let end = start;
|
|
5584
|
+
while(end < edits.length && end - start < 32){
|
|
5585
|
+
bytes += Buffer.byteLength(JSON.stringify(edits[end])) + 1;
|
|
5586
|
+
if (bytes > 64 * 1024) break;
|
|
5587
|
+
end++;
|
|
5588
|
+
}
|
|
5589
|
+
return Math.max(start + 1, end);
|
|
5590
|
+
}
|
|
5591
|
+
async function groupedFileEdits(path, edits, execute) {
|
|
5592
|
+
const results = [];
|
|
5593
|
+
var _edits_length;
|
|
5594
|
+
while(results.length < ((_edits_length = edits == null ? void 0 : edits.length) != null ? _edits_length : 0)){
|
|
5595
|
+
const start = results.length;
|
|
5596
|
+
const end = batchEnd(path, edits, start);
|
|
5597
|
+
const unconfirmed = (reason)=>({
|
|
5598
|
+
path,
|
|
5599
|
+
filesUpdate: null,
|
|
5600
|
+
results,
|
|
5601
|
+
error: `Sandbox multi-edit: ${reason}. Read the current file before retrying edits ${start + 1}–${end}.`,
|
|
5602
|
+
progress: {
|
|
5603
|
+
mode: 'sequential',
|
|
5604
|
+
appliedEdits: start,
|
|
5605
|
+
unconfirmedEdits: {
|
|
5606
|
+
from: start + 1,
|
|
5607
|
+
to: end
|
|
5608
|
+
}
|
|
5609
|
+
}
|
|
5610
|
+
});
|
|
5611
|
+
const command = buildBatchEditCommand(path, edits.slice(start, end));
|
|
5612
|
+
let response;
|
|
5613
|
+
try {
|
|
5614
|
+
response = await execute(command);
|
|
5615
|
+
} catch (e) {
|
|
5616
|
+
return unconfirmed('execution receipt unavailable');
|
|
5617
|
+
}
|
|
5618
|
+
if (response.timedOut) return unconfirmed('execution timed out');
|
|
5619
|
+
if (response.terminationReason) return unconfirmed(`execution terminated (${response.terminationReason})`);
|
|
5620
|
+
if (response.exitCode !== 0) return unconfirmed('execution did not exit successfully');
|
|
5621
|
+
if (response.truncated) return unconfirmed('truncated execution receipt');
|
|
5622
|
+
const steps = batchSteps(response.output, end - start);
|
|
5623
|
+
if (!steps) return unconfirmed('invalid execution receipt');
|
|
5624
|
+
for (const step of steps){
|
|
5625
|
+
results.push(editCommandResult(path, {
|
|
5626
|
+
output: JSON.stringify(step.metrics),
|
|
5627
|
+
exitCode: step.code}));
|
|
5628
|
+
}
|
|
5629
|
+
if (results[results.length - 1].error) break;
|
|
5630
|
+
}
|
|
5631
|
+
return sequenceResult(path, results);
|
|
5401
5632
|
}
|
|
5402
5633
|
|
|
5403
5634
|
const INDENTATION_SPACES = 2;
|
|
@@ -6226,10 +6457,13 @@ try {
|
|
|
6226
6457
|
return editCommandResult(filePath, result);
|
|
6227
6458
|
}
|
|
6228
6459
|
/** Earlier successful edits remain persisted if a later edit fails. */ multiEdit(filePath, edits) {
|
|
6229
|
-
|
|
6460
|
+
const single = (edit)=>{
|
|
6230
6461
|
var _edit_replaceAll;
|
|
6231
6462
|
return this.edit(filePath, edit.oldString, edit.newString, (_edit_replaceAll = edit.replaceAll) != null ? _edit_replaceAll : false);
|
|
6232
|
-
}
|
|
6463
|
+
};
|
|
6464
|
+
// Backends with their own edit storage/authorization semantics retain that implementation.
|
|
6465
|
+
if (this.edit !== BaseSandbox.prototype.edit) return sequentialFileEdits(filePath, edits, single);
|
|
6466
|
+
return groupedFileEdits(filePath, edits, (command)=>this.executeOperation(command, DEFAULT_SANDBOX_FILE_OPERATION_EXECUTION_OPTIONS));
|
|
6233
6467
|
}
|
|
6234
6468
|
}
|
|
6235
6469
|
|
|
@@ -11675,6 +11909,7 @@ exports.AssistantMiddlewareAccessRuntimeCapability = modelProvider.AssistantMidd
|
|
|
11675
11909
|
exports.BaseTool = modelProvider.BaseTool;
|
|
11676
11910
|
exports.BaseToolset = modelProvider.BaseToolset;
|
|
11677
11911
|
exports.BuiltinToolset = modelProvider.BuiltinToolset;
|
|
11912
|
+
exports.ConversationRuntimeCapability = modelProvider.ConversationRuntimeCapability;
|
|
11678
11913
|
exports.DefaultAgentMiddlewareRuntimeCapabilityRegistry = modelProvider.DefaultRuntimeCapabilityRegistry;
|
|
11679
11914
|
exports.DefaultRuntimeCapabilityRegistry = modelProvider.DefaultRuntimeCapabilityRegistry;
|
|
11680
11915
|
exports.McpClientRuntimeCapability = modelProvider.McpClientRuntimeCapability;
|
|
@@ -11869,9 +12104,12 @@ exports.MANAGED_CONNECTION_REGISTRY_TOKEN = MANAGED_CONNECTION_REGISTRY_TOKEN;
|
|
|
11869
12104
|
exports.MANAGED_QUEUE_HANDLER_REGISTRY_TOKEN = MANAGED_QUEUE_HANDLER_REGISTRY_TOKEN;
|
|
11870
12105
|
exports.MANAGED_QUEUE_SERVICE_TOKEN = MANAGED_QUEUE_SERVICE_TOKEN;
|
|
11871
12106
|
exports.MCP_CAPABILITY_CHANGE_EVENT_TYPES = MCP_CAPABILITY_CHANGE_EVENT_TYPES;
|
|
12107
|
+
exports.MESSAGE_WIDGET_PROVIDER = MESSAGE_WIDGET_PROVIDER;
|
|
11872
12108
|
exports.MODEL_OUTPUT_VALIDATION_ERROR_CODE = MODEL_OUTPUT_VALIDATION_ERROR_CODE;
|
|
12109
|
+
exports.MessageWidgetProvider = MessageWidgetProvider;
|
|
11873
12110
|
exports.ModelExecutionEnvironmentCapability = ModelExecutionEnvironmentCapability;
|
|
11874
12111
|
exports.ModelOutputValidationError = ModelOutputValidationError;
|
|
12112
|
+
exports.NamedProviderRegistry = NamedProviderRegistry;
|
|
11875
12113
|
exports.ORGANIZATION_METADATA_KEY = ORGANIZATION_METADATA_KEY;
|
|
11876
12114
|
exports.OpenAICompatibleEmbeddings = OpenAICompatibleEmbeddings;
|
|
11877
12115
|
exports.OpenAICompatibleReranker = OpenAICompatibleReranker;
|
|
@@ -11959,8 +12197,10 @@ exports.VectorStoreStrategy = VectorStoreStrategy;
|
|
|
11959
12197
|
exports.VideoGenerationModel = VideoGenerationModel;
|
|
11960
12198
|
exports.ViewExtensionProvider = ViewExtensionProvider;
|
|
11961
12199
|
exports.ViewMiddlewareRuntimeCapability = ViewMiddlewareRuntimeCapability;
|
|
12200
|
+
exports.WIDGET_ACTION_PROVIDER = WIDGET_ACTION_PROVIDER;
|
|
11962
12201
|
exports.WORKFLOW_NODE_STRATEGY = WORKFLOW_NODE_STRATEGY;
|
|
11963
12202
|
exports.WORKFLOW_TRIGGER_STRATEGY = WORKFLOW_TRIGGER_STRATEGY;
|
|
12203
|
+
exports.WidgetActionProvider = WidgetActionProvider;
|
|
11964
12204
|
exports.WorkbenchDecisionCapability = WorkbenchDecisionCapability;
|
|
11965
12205
|
exports.WorkflowNodeStrategy = WorkflowNodeStrategy;
|
|
11966
12206
|
exports.WorkflowTriggerStrategy = WorkflowTriggerStrategy;
|
|
@@ -11994,6 +12234,7 @@ exports.applyModelConfiguration = applyModelConfiguration;
|
|
|
11994
12234
|
exports.applyModelContextSize = applyModelContextSize;
|
|
11995
12235
|
exports.artifactPresentationKey = artifactPresentationKey;
|
|
11996
12236
|
exports.artifactTypeKey = artifactTypeKey;
|
|
12237
|
+
exports.assertPluginRegistrationOwner = assertPluginRegistrationOwner;
|
|
11997
12238
|
exports.assertXpertToolProviderClaims = assertXpertToolProviderClaims;
|
|
11998
12239
|
exports.buildSandboxTimeoutMessage = buildSandboxTimeoutMessage;
|
|
11999
12240
|
exports.calcTokenUsage = calcTokenUsage;
|
|
@@ -12014,6 +12255,7 @@ exports.defineMcpCapabilities = defineMcpCapabilities;
|
|
|
12014
12255
|
exports.defineMcpPrompt = defineMcpPrompt;
|
|
12015
12256
|
exports.defineMcpResource = defineMcpResource;
|
|
12016
12257
|
exports.defineMcpResourceTemplate = defineMcpResourceTemplate;
|
|
12258
|
+
exports.definePluginRegistration = definePluginRegistration;
|
|
12017
12259
|
exports.defineXpertTool = defineXpertTool;
|
|
12018
12260
|
exports.derivePluginArtifactNamespace = derivePluginArtifactNamespace;
|
|
12019
12261
|
exports.describeXpertToolProvider = describeXpertToolProvider;
|
|
@@ -12065,6 +12307,7 @@ exports.prepareToolResult = prepareToolResult;
|
|
|
12065
12307
|
exports.processAsyncAIGCManagedJob = processAsyncAIGCManagedJob;
|
|
12066
12308
|
exports.projectPipelineInvocationScopeSchema = projectPipelineInvocationScopeSchema;
|
|
12067
12309
|
exports.readAnalyticsProviderDiagnostic = readAnalyticsProviderDiagnostic;
|
|
12310
|
+
exports.readPluginProviderRegistrations = readPluginProviderRegistrations;
|
|
12068
12311
|
exports.renderRemoteModuleIframeHtml = renderRemoteModuleIframeHtml;
|
|
12069
12312
|
exports.renderRemoteReactIframeHtml = renderRemoteReactIframeHtml;
|
|
12070
12313
|
exports.renderRemoteVueIframeHtml = renderRemoteVueIframeHtml;
|