@pstdio/sdk 0.24.1 → 0.35.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/README.md +29 -0
- package/dist/api/index.js +352 -50
- package/dist/api.d.ts +15 -3786
- package/dist/client/index.js +21 -5
- package/dist/client.d.ts +3 -1727
- package/dist/data.d.ts +27 -47
- package/dist/extensions/index.js +288 -2
- package/dist/extensions-react.d.ts +18 -23
- package/dist/extensions.d.ts +3 -3920
- package/dist/hooks.d.ts +95 -1788
- package/dist/index-Cm5A8d4m.d.ts +261 -0
- package/dist/index-iez3LrOK.d.ts +7 -0
- package/dist/index-x7CdJPRb.d.ts +7965 -0
- package/dist/prompts.d.ts +4 -3
- package/dist/resources/index.js +352 -50
- package/dist/resources.d.ts +4 -426
- package/dist/sessions-DcxmP7uF.d.ts +2 -0
- package/dist/skills-DcxmP7uF.d.ts +2 -0
- package/dist/testing/index.js +27 -2
- package/dist/testing.d.ts +27 -910
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -63,3 +63,32 @@ The host delivers only events matching the view's project. Projectless events re
|
|
|
63
63
|
Development and installed consumers both load built SDK entries. Repository development builds this package before starting the source CLI. Builds stage release files under `.publish` through the shared release script. Package verification installs those same staged artifacts into a temporary directory outside the monorepo and checks every entry point.
|
|
64
64
|
|
|
65
65
|
Host authors should use the [workbench guide](https://github.com/pufflyai/prompt-studio/blob/main/packages/pstdio-workbench/README.md). Extension authors should use this SDK and public UI packages.
|
|
66
|
+
|
|
67
|
+
## Workspace contract release bridge
|
|
68
|
+
|
|
69
|
+
The alpha.10 host now provides workspace APIs alongside its existing repository APIs.
|
|
70
|
+
Use `ctx.projectFiles` for the project's default workspace and `ctx.workspaceFiles`
|
|
71
|
+
for the invocation's working files. Project file operations check the current workspace
|
|
72
|
+
readiness and file capabilities. Remote workspaces never fall back to local files.
|
|
73
|
+
|
|
74
|
+
`ctx.workspaces.getDefault()` returns the project workspace.
|
|
75
|
+
`ctx.workspaces.listProviders()` returns available providers, their optional `icon`, and their parameters.
|
|
76
|
+
Render these declared parameters after the user selects a workspace type. The Git
|
|
77
|
+
provider supplies a **Base branch** selection; cloud providers supply their own fields.
|
|
78
|
+
Local setup failures reject creation with the saved workspace ID and setup error.
|
|
79
|
+
The workspace remains available for diagnosis and retry.
|
|
80
|
+
Workspace context records expose `root_path` for a local directory and retain
|
|
81
|
+
`worktree_path` during this release bridge.
|
|
82
|
+
|
|
83
|
+
The SDK client exposes `client.workspaces.listProviders(projectId)` and
|
|
84
|
+
`client.filesystem.createDirectory({ parent_path, name })`.
|
|
85
|
+
Directory creation accepts one child name under an existing parent.
|
|
86
|
+
|
|
87
|
+
Webviews can set `workspaceId` in `createWebviewClient(host, { workspaceId })`
|
|
88
|
+
to run commands in that workspace. The host validates project ownership.
|
|
89
|
+
|
|
90
|
+
Extensions that work with both host contracts can declare the exact versions
|
|
91
|
+
`1.0.0-alpha.10 || 1.0.0-alpha.11` in `engines.pstdio`.
|
|
92
|
+
General version ranges and wildcards remain unsupported.
|
|
93
|
+
This declaration requires the bridge host; older alpha.10 hosts accept only one version.
|
|
94
|
+
See [the staged release ADR](../../.pstdio/docs/adrs/0030-temporary-workspace-contract-release-bridge.md).
|
package/dist/api/index.js
CHANGED
|
@@ -5229,7 +5229,19 @@ var listExtensionConnectionsResponseSchema = object({
|
|
|
5229
5229
|
connections: array(extensionConnectionRecordSchema)
|
|
5230
5230
|
});
|
|
5231
5231
|
|
|
5232
|
-
// ../pstdio-api-contracts/src/
|
|
5232
|
+
// ../pstdio-api-contracts/src/extension-kernel/navigation-href.ts
|
|
5233
|
+
var isNavigationHref = (href) => {
|
|
5234
|
+
if (typeof href !== "string")
|
|
5235
|
+
return false;
|
|
5236
|
+
try {
|
|
5237
|
+
const { protocol } = new URL(href);
|
|
5238
|
+
return protocol === "https:" || protocol === "http:";
|
|
5239
|
+
} catch {
|
|
5240
|
+
return false;
|
|
5241
|
+
}
|
|
5242
|
+
};
|
|
5243
|
+
|
|
5244
|
+
// ../pstdio-api-contracts/src/extensions/resource-ref.ts
|
|
5233
5245
|
var extensionResourceRefSchema = object({
|
|
5234
5246
|
shorthand: string2().optional(),
|
|
5235
5247
|
type: string2(),
|
|
@@ -5240,6 +5252,54 @@ var extensionResourceRefSchema = object({
|
|
|
5240
5252
|
extensionId: string2().optional(),
|
|
5241
5253
|
metadata: serializableJsonObjectSchema.optional()
|
|
5242
5254
|
});
|
|
5255
|
+
|
|
5256
|
+
// ../pstdio-api-contracts/src/extensions/workbench-refs-metadata.ts
|
|
5257
|
+
var contributionRefSchema = (kind) => object({ extensionId: string2(), kind: literal(kind), id: string2() });
|
|
5258
|
+
var pageRefSchema = contributionRefSchema("page");
|
|
5259
|
+
var placementRefSchema = contributionRefSchema("placement");
|
|
5260
|
+
var modeRefSchema = contributionRefSchema("mode");
|
|
5261
|
+
var viewRefSchema = contributionRefSchema("view");
|
|
5262
|
+
var resourceKindRefSchema = contributionRefSchema("resource-kind");
|
|
5263
|
+
var pageSlotRefSchema = object({
|
|
5264
|
+
kind: literal("page-slot"),
|
|
5265
|
+
page: pageRefSchema,
|
|
5266
|
+
id: string2()
|
|
5267
|
+
});
|
|
5268
|
+
var panelRefSchema = union([placementRefSchema, pageSlotRefSchema]);
|
|
5269
|
+
var commandTargetSchema = object({
|
|
5270
|
+
command: contributionRefSchema("command"),
|
|
5271
|
+
params: serializableJsonObjectSchema.optional()
|
|
5272
|
+
});
|
|
5273
|
+
|
|
5274
|
+
// ../pstdio-api-contracts/src/extensions/navigation-target-metadata.ts
|
|
5275
|
+
var sectionSchema = object({
|
|
5276
|
+
anchors: array(object({ id: string2(), heading: string2(), occurrence: number2().int().nonnegative().optional() }))
|
|
5277
|
+
});
|
|
5278
|
+
var pageTargetSchema = lazy(() => object({
|
|
5279
|
+
kind: literal("page"),
|
|
5280
|
+
page: pageRefSchema,
|
|
5281
|
+
resource: extensionResourceRefSchema.optional(),
|
|
5282
|
+
open: _enum(["preview", "pin"]).optional(),
|
|
5283
|
+
section: sectionSchema.optional(),
|
|
5284
|
+
parent: pageTargetSchema.optional()
|
|
5285
|
+
})).meta({ id: "WorkbenchMetadataPageTarget" });
|
|
5286
|
+
var navigationOperationSchema = union([
|
|
5287
|
+
pageTargetSchema,
|
|
5288
|
+
object({
|
|
5289
|
+
kind: literal("panel"),
|
|
5290
|
+
panel: panelRefSchema,
|
|
5291
|
+
resource: extensionResourceRefSchema.optional(),
|
|
5292
|
+
open: _enum(["preview", "pin"]).optional()
|
|
5293
|
+
})
|
|
5294
|
+
]);
|
|
5295
|
+
var navigationTargetSchema = union([
|
|
5296
|
+
navigationOperationSchema,
|
|
5297
|
+
object({ kind: literal("command"), target: commandTargetSchema }),
|
|
5298
|
+
object({ kind: literal("href"), href: string2().refine(isNavigationHref, "Expected an HTTP or HTTPS URL") }),
|
|
5299
|
+
object({ kind: literal("compound"), targets: array(navigationOperationSchema).min(1) })
|
|
5300
|
+
]);
|
|
5301
|
+
|
|
5302
|
+
// ../pstdio-api-contracts/src/extensions/execute.ts
|
|
5243
5303
|
var extensionRepoContextSchema = object({
|
|
5244
5304
|
projectId: string2(),
|
|
5245
5305
|
repoId: string2(),
|
|
@@ -5309,10 +5369,12 @@ var commandDiagnosticSchema = object({
|
|
|
5309
5369
|
commandId: string2().optional(),
|
|
5310
5370
|
metadata: jsonObjectSchema.optional()
|
|
5311
5371
|
});
|
|
5372
|
+
var responseNavigationTargetSchema = navigationTargetSchema;
|
|
5312
5373
|
var commandOutcomeSchema = object({
|
|
5313
5374
|
ok: boolean2(),
|
|
5314
5375
|
status: _enum(["success", "rejected", "error"]),
|
|
5315
5376
|
value: unknown().optional(),
|
|
5377
|
+
navigationRequests: array(responseNavigationTargetSchema).optional(),
|
|
5316
5378
|
code: string2().optional(),
|
|
5317
5379
|
reason: string2().optional(),
|
|
5318
5380
|
data: jsonObjectSchema.optional(),
|
|
@@ -5682,52 +5744,6 @@ var extensionCommandPaletteResourceRecordSchema = object({
|
|
|
5682
5744
|
refreshEventIds: array(string2().min(1)).optional()
|
|
5683
5745
|
});
|
|
5684
5746
|
|
|
5685
|
-
// ../pstdio-api-contracts/src/extensions/workbench-refs-metadata.ts
|
|
5686
|
-
var contributionRefSchema = (kind) => object({ extensionId: string2(), kind: literal(kind), id: string2() });
|
|
5687
|
-
var pageRefSchema = contributionRefSchema("page");
|
|
5688
|
-
var placementRefSchema = contributionRefSchema("placement");
|
|
5689
|
-
var modeRefSchema = contributionRefSchema("mode");
|
|
5690
|
-
var viewRefSchema = contributionRefSchema("view");
|
|
5691
|
-
var resourceKindRefSchema = contributionRefSchema("resource-kind");
|
|
5692
|
-
var pageSlotRefSchema = object({
|
|
5693
|
-
kind: literal("page-slot"),
|
|
5694
|
-
page: pageRefSchema,
|
|
5695
|
-
id: string2()
|
|
5696
|
-
});
|
|
5697
|
-
var panelRefSchema = union([placementRefSchema, pageSlotRefSchema]);
|
|
5698
|
-
var commandTargetSchema = object({
|
|
5699
|
-
command: contributionRefSchema("command"),
|
|
5700
|
-
params: serializableJsonObjectSchema.optional()
|
|
5701
|
-
});
|
|
5702
|
-
|
|
5703
|
-
// ../pstdio-api-contracts/src/extensions/navigation-target-metadata.ts
|
|
5704
|
-
var sectionSchema = object({
|
|
5705
|
-
anchors: array(object({ id: string2(), heading: string2(), occurrence: number2().int().nonnegative().optional() }))
|
|
5706
|
-
});
|
|
5707
|
-
var pageTargetSchema = lazy(() => object({
|
|
5708
|
-
kind: literal("page"),
|
|
5709
|
-
page: pageRefSchema,
|
|
5710
|
-
resource: extensionResourceRefSchema.optional(),
|
|
5711
|
-
open: _enum(["preview", "pin"]).optional(),
|
|
5712
|
-
section: sectionSchema.optional(),
|
|
5713
|
-
parent: pageTargetSchema.optional()
|
|
5714
|
-
})).meta({ id: "WorkbenchMetadataPageTarget" });
|
|
5715
|
-
var navigationOperationSchema = union([
|
|
5716
|
-
pageTargetSchema,
|
|
5717
|
-
object({
|
|
5718
|
-
kind: literal("panel"),
|
|
5719
|
-
panel: panelRefSchema,
|
|
5720
|
-
resource: extensionResourceRefSchema.optional(),
|
|
5721
|
-
open: _enum(["preview", "pin"]).optional()
|
|
5722
|
-
})
|
|
5723
|
-
]);
|
|
5724
|
-
var navigationTargetSchema = union([
|
|
5725
|
-
navigationOperationSchema,
|
|
5726
|
-
object({ kind: literal("command"), target: commandTargetSchema }),
|
|
5727
|
-
object({ kind: literal("href"), href: string2() }),
|
|
5728
|
-
object({ kind: literal("compound"), targets: array(navigationOperationSchema).min(1) })
|
|
5729
|
-
]);
|
|
5730
|
-
|
|
5731
5747
|
// ../pstdio-api-contracts/src/extensions/keybindings.ts
|
|
5732
5748
|
var parsedKeybindingChordSchema = object({
|
|
5733
5749
|
key: string2(),
|
|
@@ -6292,6 +6308,10 @@ var automationRunEventSchema = object({
|
|
|
6292
6308
|
createdAt: string2()
|
|
6293
6309
|
});
|
|
6294
6310
|
var listAutomationRunEventsResponseSchema = object({ events: array(automationRunEventSchema) });
|
|
6311
|
+
// ../pstdio-api-contracts/src/extension-kernel/api-versions.ts
|
|
6312
|
+
var numericIdentifier = "(?:0|[1-9]\\d*)";
|
|
6313
|
+
var prereleaseIdentifier = `(?:${numericIdentifier}|\\d*[A-Za-z-][0-9A-Za-z-]*)`;
|
|
6314
|
+
var exactVersion = new RegExp(`^${numericIdentifier}\\.${numericIdentifier}\\.${numericIdentifier}(?:-${prereleaseIdentifier}(?:\\.${prereleaseIdentifier})*)?(?:\\+[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*)?$`);
|
|
6295
6315
|
// ../pstdio-api-contracts/src/extension-kernel/builtin-refs.ts
|
|
6296
6316
|
var hostRef = (kind, id) => ({ extensionId: "pstdio", kind, id });
|
|
6297
6317
|
var workbenchModes = {
|
|
@@ -6423,6 +6443,11 @@ var workspaceSlots = {
|
|
|
6423
6443
|
var projectEvents = {
|
|
6424
6444
|
opened: hostEventRef("project.opened")
|
|
6425
6445
|
};
|
|
6446
|
+
var viewDataEvents = {
|
|
6447
|
+
sessionsChanged: hostEventRef("view.sessions.changed"),
|
|
6448
|
+
workspacesChanged: hostEventRef("view.workspaces.changed"),
|
|
6449
|
+
repositoriesChanged: hostEventRef("view.repositories.changed")
|
|
6450
|
+
};
|
|
6426
6451
|
var sessionEvents = {
|
|
6427
6452
|
started: hostEventRef("session.started"),
|
|
6428
6453
|
resumed: hostEventRef("session.resumed"),
|
|
@@ -6453,6 +6478,86 @@ var l10n = (key, defaultValue) => ({
|
|
|
6453
6478
|
...defaultValue === undefined ? {} : { default: defaultValue }
|
|
6454
6479
|
});
|
|
6455
6480
|
var isLocalizedString = (value) => typeof value === "object" && value !== null && ("$l10n" in value) && typeof value.$l10n === "string";
|
|
6481
|
+
// ../pstdio-api-contracts/src/extension-kernel/navigation.ts
|
|
6482
|
+
var isRecord = (value) => Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
6483
|
+
var isContributionRef = (value, kind) => isRecord(value) && value.kind === kind && typeof value.id === "string";
|
|
6484
|
+
var isResource = (value) => isRecord(value) && typeof value.type === "string" && typeof value.id === "string";
|
|
6485
|
+
var isOpenIntent = (value) => value === undefined || value === "preview" || value === "pin";
|
|
6486
|
+
var isPageTarget = (value, ancestors = new Set) => {
|
|
6487
|
+
if (!isRecord(value) || value.kind !== "page" || !isContributionRef(value.page, "page"))
|
|
6488
|
+
return false;
|
|
6489
|
+
if (ancestors.has(value))
|
|
6490
|
+
return false;
|
|
6491
|
+
if (value.resource !== undefined && !isResource(value.resource))
|
|
6492
|
+
return false;
|
|
6493
|
+
if (value.section !== undefined && !isRecord(value.section))
|
|
6494
|
+
return false;
|
|
6495
|
+
if (!isOpenIntent(value.open))
|
|
6496
|
+
return false;
|
|
6497
|
+
if (value.parent === undefined)
|
|
6498
|
+
return true;
|
|
6499
|
+
const next = new Set(ancestors);
|
|
6500
|
+
next.add(value);
|
|
6501
|
+
return isPageTarget(value.parent, next);
|
|
6502
|
+
};
|
|
6503
|
+
var isPanelTarget = (value) => {
|
|
6504
|
+
if (!isRecord(value) || value.kind !== "panel" || !isRecord(value.panel))
|
|
6505
|
+
return false;
|
|
6506
|
+
const panel = value.panel;
|
|
6507
|
+
const validPanel = isContributionRef(panel, "placement") || panel.kind === "page-slot" && isContributionRef(panel.page, "page") && typeof panel.id === "string";
|
|
6508
|
+
return validPanel && (value.resource === undefined || isResource(value.resource)) && isOpenIntent(value.open);
|
|
6509
|
+
};
|
|
6510
|
+
var isItemTarget = (value) => {
|
|
6511
|
+
if (!isRecord(value))
|
|
6512
|
+
return false;
|
|
6513
|
+
if (value.kind === "page")
|
|
6514
|
+
return isPageTarget(value);
|
|
6515
|
+
if (value.kind === "panel")
|
|
6516
|
+
return isPanelTarget(value);
|
|
6517
|
+
if (value.kind === "href")
|
|
6518
|
+
return isNavigationHref(value.href);
|
|
6519
|
+
return value.kind === "command" && isRecord(value.target) && isContributionRef(value.target.command, "command") && (value.target.params === undefined || isRecord(value.target.params));
|
|
6520
|
+
};
|
|
6521
|
+
var isNavigationTarget = (value) => {
|
|
6522
|
+
if (isItemTarget(value))
|
|
6523
|
+
return true;
|
|
6524
|
+
if (!isRecord(value) || value.kind !== "compound" || !Array.isArray(value.targets) || value.targets.length === 0) {
|
|
6525
|
+
return false;
|
|
6526
|
+
}
|
|
6527
|
+
return value.targets.every((target) => isPageTarget(target) || isPanelTarget(target));
|
|
6528
|
+
};
|
|
6529
|
+
var withExtensionOwner = (ref, extensionId) => ref.extensionId !== undefined || extensionId === undefined ? ref : { ...ref, extensionId };
|
|
6530
|
+
var toPageTarget = (target, extensionId, projectId) => ({
|
|
6531
|
+
...target,
|
|
6532
|
+
page: withExtensionOwner(target.page, extensionId),
|
|
6533
|
+
...target.resource ? { resource: qualifyResource(target.resource, extensionId, projectId) } : {},
|
|
6534
|
+
...target.parent ? { parent: toPageTarget(target.parent, extensionId, projectId) } : {}
|
|
6535
|
+
});
|
|
6536
|
+
var qualifyResource = (resource, extensionId, projectId) => ({
|
|
6537
|
+
...resource,
|
|
6538
|
+
extensionId: resource.extensionId ?? extensionId,
|
|
6539
|
+
projectId: resource.projectId ?? projectId
|
|
6540
|
+
});
|
|
6541
|
+
var qualifyNavigationTarget = (target, extensionId, projectId) => {
|
|
6542
|
+
if (!isNavigationTarget(target))
|
|
6543
|
+
throw new Error("Invalid navigation target.");
|
|
6544
|
+
if (target.kind === "page")
|
|
6545
|
+
return toPageTarget(target, extensionId, projectId);
|
|
6546
|
+
if (target.kind === "panel")
|
|
6547
|
+
return {
|
|
6548
|
+
...target,
|
|
6549
|
+
panel: target.panel.kind === "page-slot" ? { ...target.panel, page: withExtensionOwner(target.panel.page, extensionId) } : withExtensionOwner(target.panel, extensionId),
|
|
6550
|
+
...target.resource ? { resource: qualifyResource(target.resource, extensionId, projectId) } : {}
|
|
6551
|
+
};
|
|
6552
|
+
if (target.kind === "command")
|
|
6553
|
+
return { ...target, target: { ...target.target, command: withExtensionOwner(target.target.command, extensionId) } };
|
|
6554
|
+
if (target.kind === "href")
|
|
6555
|
+
return target;
|
|
6556
|
+
return {
|
|
6557
|
+
...target,
|
|
6558
|
+
targets: target.targets.map((item) => qualifyNavigationTarget(item, extensionId, projectId))
|
|
6559
|
+
};
|
|
6560
|
+
};
|
|
6456
6561
|
// ../pstdio-api-contracts/src/extension-kernel/package-asset.ts
|
|
6457
6562
|
var packageAsset = (path, baseUrl) => ({
|
|
6458
6563
|
kind: "package-asset",
|
|
@@ -6502,6 +6607,179 @@ var fileRecordSchema = object({
|
|
|
6502
6607
|
created_at: string2(),
|
|
6503
6608
|
updated_at: string2()
|
|
6504
6609
|
});
|
|
6610
|
+
// ../pstdio-api-contracts/src/history-turn-evidence.ts
|
|
6611
|
+
var historyTurnEvidence = (known, native, prompt, body) => {
|
|
6612
|
+
const signatures = (turn) => JSON.stringify([prompt(turn), body(turn)]);
|
|
6613
|
+
if (known.length === native.length && known.every((turn, index) => signatures(turn) === signatures(native[index]))) {
|
|
6614
|
+
return signatures;
|
|
6615
|
+
}
|
|
6616
|
+
const tokens = (turns) => {
|
|
6617
|
+
const positions = new Map;
|
|
6618
|
+
turns.forEach((turn, index) => {
|
|
6619
|
+
for (const value of new Set(body(turn))) {
|
|
6620
|
+
const token = JSON.stringify([prompt(turn), value]);
|
|
6621
|
+
positions.set(token, positions.has(token) ? -1 : index);
|
|
6622
|
+
}
|
|
6623
|
+
});
|
|
6624
|
+
return positions;
|
|
6625
|
+
};
|
|
6626
|
+
const left = tokens(known);
|
|
6627
|
+
const right = tokens(native);
|
|
6628
|
+
const matches = new Map;
|
|
6629
|
+
const reverse = new Map;
|
|
6630
|
+
for (const [token, index] of left) {
|
|
6631
|
+
const other = right.get(token);
|
|
6632
|
+
if (index < 0 || other === undefined || other < 0)
|
|
6633
|
+
continue;
|
|
6634
|
+
const targets = matches.get(index) ?? new Set;
|
|
6635
|
+
targets.add(other);
|
|
6636
|
+
matches.set(index, targets);
|
|
6637
|
+
const sources = reverse.get(other) ?? new Set;
|
|
6638
|
+
sources.add(index);
|
|
6639
|
+
reverse.set(other, sources);
|
|
6640
|
+
}
|
|
6641
|
+
const keys = new Map;
|
|
6642
|
+
known.forEach((turn, index) => {
|
|
6643
|
+
keys.set(turn, `known:${index}`);
|
|
6644
|
+
});
|
|
6645
|
+
native.forEach((turn, index) => {
|
|
6646
|
+
keys.set(turn, `native:${index}`);
|
|
6647
|
+
});
|
|
6648
|
+
for (const [index, targets] of matches) {
|
|
6649
|
+
if (targets.size !== 1)
|
|
6650
|
+
continue;
|
|
6651
|
+
const other = [...targets][0];
|
|
6652
|
+
if (reverse.get(other)?.size !== 1)
|
|
6653
|
+
continue;
|
|
6654
|
+
const key = `pair:${index}:${other}`;
|
|
6655
|
+
keys.set(known[index], key);
|
|
6656
|
+
keys.set(native[other], key);
|
|
6657
|
+
}
|
|
6658
|
+
return (turn) => keys.get(turn);
|
|
6659
|
+
};
|
|
6660
|
+
|
|
6661
|
+
// ../pstdio-api-contracts/src/history-reconciliation.ts
|
|
6662
|
+
class HistoryConflict extends Error {
|
|
6663
|
+
}
|
|
6664
|
+
var submittedPrompt = (message) => message.parts.filter((part) => part.type === "text").map((part) => part.text).join(`
|
|
6665
|
+
`).replace(/\n\n<session-attachments>[\s\S]*<\/session-attachments>\s*$/, "").trim();
|
|
6666
|
+
var historyValueKey = (value) => JSON.stringify(value, (_key, item) => {
|
|
6667
|
+
if (!item || typeof item !== "object" || Array.isArray(item))
|
|
6668
|
+
return item;
|
|
6669
|
+
return Object.fromEntries(Object.entries(item).sort(([a], [b]) => a.localeCompare(b)));
|
|
6670
|
+
});
|
|
6671
|
+
var historyMessageKey = (message) => historyValueKey([message.role, message.parts]);
|
|
6672
|
+
var positions = (items, key) => {
|
|
6673
|
+
const result = new Map;
|
|
6674
|
+
items.forEach((item, index) => {
|
|
6675
|
+
const value = key(item);
|
|
6676
|
+
const indices = result.get(value) ?? [];
|
|
6677
|
+
indices.push(index);
|
|
6678
|
+
result.set(value, indices);
|
|
6679
|
+
});
|
|
6680
|
+
return result;
|
|
6681
|
+
};
|
|
6682
|
+
var mergeOrderedHistory = (known, native, key, merge, refineKey) => {
|
|
6683
|
+
if (!known.length)
|
|
6684
|
+
return native;
|
|
6685
|
+
if (!native.length)
|
|
6686
|
+
return known;
|
|
6687
|
+
const knownPositions = positions(known, key);
|
|
6688
|
+
const nativePositions = positions(native, key);
|
|
6689
|
+
const anchors = [];
|
|
6690
|
+
for (const [value, indices] of knownPositions) {
|
|
6691
|
+
const other = nativePositions.get(value);
|
|
6692
|
+
if (indices.length === 1 && other?.length === 1)
|
|
6693
|
+
anchors.push([indices[0], other[0]]);
|
|
6694
|
+
}
|
|
6695
|
+
if (!anchors.length) {
|
|
6696
|
+
if (refineKey) {
|
|
6697
|
+
const refined = mergeOrderedHistory(known, native, refineKey(known, native), merge);
|
|
6698
|
+
return refined;
|
|
6699
|
+
}
|
|
6700
|
+
if (known.length === native.length && known.every((item, index) => key(item) === key(native[index]))) {
|
|
6701
|
+
return known.map((item, index) => merge(item, native[index]));
|
|
6702
|
+
}
|
|
6703
|
+
throw new HistoryConflict("ambiguous_interval");
|
|
6704
|
+
}
|
|
6705
|
+
let left = 0;
|
|
6706
|
+
let right = 0;
|
|
6707
|
+
const result = [];
|
|
6708
|
+
for (const [a, b] of anchors) {
|
|
6709
|
+
if (b < right)
|
|
6710
|
+
throw new HistoryConflict("conflicting_order");
|
|
6711
|
+
result.push(...mergeOrderedHistory(known.slice(left, a), native.slice(right, b), key, merge, refineKey));
|
|
6712
|
+
result.push(merge(known[a], native[b]));
|
|
6713
|
+
left = a + 1;
|
|
6714
|
+
right = b + 1;
|
|
6715
|
+
}
|
|
6716
|
+
result.push(...mergeOrderedHistory(known.slice(left), native.slice(right), key, merge, refineKey));
|
|
6717
|
+
return result;
|
|
6718
|
+
};
|
|
6719
|
+
var splitHistoryTurns = (messages) => {
|
|
6720
|
+
const turns = [];
|
|
6721
|
+
for (const message of messages) {
|
|
6722
|
+
if (message.role === "user" || !turns.length)
|
|
6723
|
+
turns.push([]);
|
|
6724
|
+
turns[turns.length - 1].push(message);
|
|
6725
|
+
}
|
|
6726
|
+
return turns;
|
|
6727
|
+
};
|
|
6728
|
+
var mergeHistoryMetadata = (known, native) => {
|
|
6729
|
+
const files = native.parts.filter((part) => part.type === "file");
|
|
6730
|
+
const fileKeys = new Set(files.map((part) => part.fileId ?? part.url));
|
|
6731
|
+
const missing = known.parts.filter((part) => part.type === "file" && !fileKeys.has(part.fileId ?? part.url));
|
|
6732
|
+
const parts = native.role === "user" ? [...known.parts.filter((part) => part.type === "text"), ...native.parts.filter((part) => part.type !== "text")] : native.parts;
|
|
6733
|
+
return { ...known, ...native, parts: [...parts, ...missing] };
|
|
6734
|
+
};
|
|
6735
|
+
var isUsage = (message) => message.role === "system" && message.parts.length > 0 && message.parts.every((part) => part.type === "token_usage");
|
|
6736
|
+
var combineTextRuns = (messages) => {
|
|
6737
|
+
const runs = [];
|
|
6738
|
+
for (const message of messages) {
|
|
6739
|
+
const previous = runs.at(-1);
|
|
6740
|
+
const part = message.parts[0];
|
|
6741
|
+
const previousPart = previous?.parts[0];
|
|
6742
|
+
if (previous && message.role === previous.role && message.parts.length === 1 && previous.parts.length === 1 && (part.type === "text" || part.type === "reasoning") && previousPart?.type === part.type) {
|
|
6743
|
+
runs[runs.length - 1] = { ...previous, parts: [{ ...part, text: previousPart.text + part.text }] };
|
|
6744
|
+
} else
|
|
6745
|
+
runs.push(message);
|
|
6746
|
+
}
|
|
6747
|
+
return runs;
|
|
6748
|
+
};
|
|
6749
|
+
var reconcileMessageHistory = (input, projection = {}) => {
|
|
6750
|
+
const key = projection.key ?? historyMessageKey;
|
|
6751
|
+
const merge = projection.merge ?? mergeHistoryMetadata;
|
|
6752
|
+
const generated = projection.isGenerated ?? isUsage;
|
|
6753
|
+
const mergeTurn = (known, native) => {
|
|
6754
|
+
const startsWithUser = known[0]?.role === "user" && native[0]?.role === "user";
|
|
6755
|
+
const body = (turn) => combineTextRuns(turn.slice(startsWithUser ? 1 : 0).filter((message) => !generated(message)));
|
|
6756
|
+
const messages = mergeOrderedHistory(body(known), body(native), key, merge);
|
|
6757
|
+
const metadata = [...native.filter(generated)];
|
|
6758
|
+
const counts = new Map;
|
|
6759
|
+
metadata.forEach((message) => {
|
|
6760
|
+
counts.set(historyMessageKey(message), (counts.get(historyMessageKey(message)) ?? 0) + 1);
|
|
6761
|
+
});
|
|
6762
|
+
for (const message of known.filter(generated)) {
|
|
6763
|
+
const value = historyMessageKey(message);
|
|
6764
|
+
const remaining = counts.get(value) ?? 0;
|
|
6765
|
+
if (remaining)
|
|
6766
|
+
counts.set(value, remaining - 1);
|
|
6767
|
+
else
|
|
6768
|
+
metadata.push(message);
|
|
6769
|
+
}
|
|
6770
|
+
return [...startsWithUser ? [mergeHistoryMetadata(known[0], native[0])] : [], ...messages, ...metadata];
|
|
6771
|
+
};
|
|
6772
|
+
try {
|
|
6773
|
+
const prompt = (turn) => turn[0]?.role === "user" ? `user:${submittedPrompt(turn[0])}` : "prefix";
|
|
6774
|
+
const turns = mergeOrderedHistory(splitHistoryTurns(input.knownMessages), splitHistoryTurns(input.nativeMessages), prompt, mergeTurn, (known, native) => historyTurnEvidence(known, native, prompt, (turn) => combineTextRuns(turn.slice(1).filter((message) => !generated(message))).map(key)));
|
|
6775
|
+
const messages = turns.flat().map((message, index) => message.index === undefined ? message : { ...message, index });
|
|
6776
|
+
return { kind: "recovered", messages };
|
|
6777
|
+
} catch (error) {
|
|
6778
|
+
if (error instanceof HistoryConflict)
|
|
6779
|
+
return { kind: "conflict", category: error.message };
|
|
6780
|
+
throw error;
|
|
6781
|
+
}
|
|
6782
|
+
};
|
|
6505
6783
|
// ../pstdio-api-contracts/src/projects.ts
|
|
6506
6784
|
var extensionSetupWarningSchema = object({
|
|
6507
6785
|
code: literal("extension_setup_failed"),
|
|
@@ -6767,9 +7045,21 @@ var followUpDecisionSchema = union([
|
|
|
6767
7045
|
var followUpResponseSchema = sessionSchema.extend({
|
|
6768
7046
|
follow_up: followUpDecisionSchema
|
|
6769
7047
|
});
|
|
7048
|
+
var sessionHistoryIssueSchema = object({
|
|
7049
|
+
code: _enum(["reconciliation_conflict", "checkpoint_unreadable", "native_unavailable"]),
|
|
7050
|
+
category: string2()
|
|
7051
|
+
});
|
|
7052
|
+
var sessionQueuedMessagesResponseSchema = object({ messages: array(sessionMessageSchema) });
|
|
7053
|
+
var sessionConversationSourcesSchema = object({
|
|
7054
|
+
checkpoint: array(sessionMessageSchema).nullable(),
|
|
7055
|
+
native: array(sessionMessageSchema).nullable(),
|
|
7056
|
+
checkpointError: string2().nullable(),
|
|
7057
|
+
nativeError: string2().nullable()
|
|
7058
|
+
});
|
|
6770
7059
|
var sessionConversationResponseSchema = object({
|
|
7060
|
+
historyIssue: sessionHistoryIssueSchema.optional(),
|
|
6771
7061
|
session: sessionSchema,
|
|
6772
|
-
messages: array(
|
|
7062
|
+
messages: array(sessionMessageSchema)
|
|
6773
7063
|
});
|
|
6774
7064
|
var resolveSessionIdInputSchema = object({
|
|
6775
7065
|
agent: string2(),
|
|
@@ -6863,6 +7153,9 @@ var workspaceProviderErrorSchema = object({
|
|
|
6863
7153
|
retryable: boolean2(),
|
|
6864
7154
|
occurred_at: string2()
|
|
6865
7155
|
});
|
|
7156
|
+
var workspaceAnchorSchema = extensionResourceRefSchema.extend({
|
|
7157
|
+
role: _enum(["primary", "context", "source", "result"]).optional()
|
|
7158
|
+
});
|
|
6866
7159
|
var workspaceSchema = object({
|
|
6867
7160
|
id: string2(),
|
|
6868
7161
|
project_id: string2(),
|
|
@@ -6883,7 +7176,7 @@ var workspaceSchema = object({
|
|
|
6883
7176
|
archived: boolean2(),
|
|
6884
7177
|
workspace_shorthand: string2(),
|
|
6885
7178
|
startup_log_file_id: string2().nullable(),
|
|
6886
|
-
anchors_json: array(
|
|
7179
|
+
anchors_json: array(workspaceAnchorSchema),
|
|
6887
7180
|
created_at: string2(),
|
|
6888
7181
|
updated_at: string2(),
|
|
6889
7182
|
deleted_at: string2().nullable()
|
|
@@ -6893,7 +7186,9 @@ var createWorkspaceInputSchema = object({
|
|
|
6893
7186
|
provider_id: string2().optional(),
|
|
6894
7187
|
params: jsonObjectSchema.optional(),
|
|
6895
7188
|
repo_id: string2().optional(),
|
|
6896
|
-
base: string2().optional()
|
|
7189
|
+
base: string2().optional(),
|
|
7190
|
+
anchors: array(workspaceAnchorSchema).optional(),
|
|
7191
|
+
shorthand_base: string2().trim().min(1).optional()
|
|
6897
7192
|
});
|
|
6898
7193
|
var renameWorkspaceInputSchema = object({
|
|
6899
7194
|
name: string2().trim().min(1, "Workspace name is required").max(120, "Workspace name must be 120 characters or less")
|
|
@@ -6936,6 +7231,13 @@ var listWorkspaceFilesInputSchema = object({
|
|
|
6936
7231
|
query: string2().optional(),
|
|
6937
7232
|
limit: number2().int().positive().max(500).optional()
|
|
6938
7233
|
});
|
|
7234
|
+
var workspaceProviderDescriptorSchema = object({
|
|
7235
|
+
id: string2(),
|
|
7236
|
+
label: localizableStringSchema,
|
|
7237
|
+
icon: string2().optional(),
|
|
7238
|
+
description: localizableStringSchema.optional(),
|
|
7239
|
+
params: extensionParamObjectSchema
|
|
7240
|
+
});
|
|
6939
7241
|
export {
|
|
6940
7242
|
sessionAttachmentMimeTypesByExtension
|
|
6941
7243
|
};
|