@superdoc-dev/cli 0.2.0-next.78 → 0.2.0-next.79
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/dist/index.js +321 -219
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -117095,9 +117095,9 @@ var init_remark_gfm_CjV8kaUy_es = __esm(() => {
|
|
|
117095
117095
|
init_remark_gfm_z_sDF4ss_es();
|
|
117096
117096
|
});
|
|
117097
117097
|
|
|
117098
|
-
// ../../packages/superdoc/dist/chunks/src-
|
|
117099
|
-
var
|
|
117100
|
-
__export(
|
|
117098
|
+
// ../../packages/superdoc/dist/chunks/src-B8Sjis_q.es.js
|
|
117099
|
+
var exports_src_B8Sjis_q_es = {};
|
|
117100
|
+
__export(exports_src_B8Sjis_q_es, {
|
|
117101
117101
|
zt: () => defineMark,
|
|
117102
117102
|
z: () => cM,
|
|
117103
117103
|
yt: () => removeAwarenessStates,
|
|
@@ -127066,9 +127066,9 @@ function decodeTextRefPayload(encoded, stepId) {
|
|
|
127066
127066
|
throw planError("INVALID_INPUT", "invalid text ref encoding", stepId);
|
|
127067
127067
|
}
|
|
127068
127068
|
}
|
|
127069
|
-
function resolveV3TextRef(editor, index2, step3, refData
|
|
127069
|
+
function resolveV3TextRef(editor, index2, step3, refData) {
|
|
127070
127070
|
const currentRevision = getRevision(editor);
|
|
127071
|
-
if (
|
|
127071
|
+
if (refData.rev !== currentRevision)
|
|
127072
127072
|
throw planError("REVISION_MISMATCH", `Text ref is ephemeral and revision-scoped. Re-run query.match to obtain a fresh handle.ref for revision ${currentRevision}.`, step3.id, {
|
|
127073
127073
|
refRevision: refData.rev,
|
|
127074
127074
|
currentRevision,
|
|
@@ -127103,11 +127103,11 @@ function resolveV3TextRef(editor, index2, step3, refData, options) {
|
|
|
127103
127103
|
}
|
|
127104
127104
|
return [buildSpanTarget(editor, index2, step3, segments, refData.matchId)];
|
|
127105
127105
|
}
|
|
127106
|
-
function resolveTextRef(editor, index2, step3, ref$1
|
|
127106
|
+
function resolveTextRef(editor, index2, step3, ref$1) {
|
|
127107
127107
|
const payload = decodeTextRefPayload(ref$1.slice(5), step3.id);
|
|
127108
127108
|
if (!isV3Ref(payload))
|
|
127109
127109
|
throw planError("INVALID_INPUT", "only V3 text refs are supported", step3.id);
|
|
127110
|
-
return resolveV3TextRef(editor, index2, step3, payload
|
|
127110
|
+
return resolveV3TextRef(editor, index2, step3, payload);
|
|
127111
127111
|
}
|
|
127112
127112
|
function resolveBlockRef(editor, index2, step3, ref$1) {
|
|
127113
127113
|
const candidate = index2.candidates.find((c$3) => c$3.nodeId === ref$1);
|
|
@@ -127123,22 +127123,22 @@ function resolveBlockRef(editor, index2, step3, ref$1) {
|
|
|
127123
127123
|
blockPos: candidate.pos
|
|
127124
127124
|
}, candidate)];
|
|
127125
127125
|
}
|
|
127126
|
-
function dispatchRefHandler(editor, index2, step3, ref$1
|
|
127126
|
+
function dispatchRefHandler(editor, index2, step3, ref$1) {
|
|
127127
127127
|
for (const entry of REF_HANDLERS)
|
|
127128
127128
|
if (entry.prefix === "" || ref$1.startsWith(entry.prefix))
|
|
127129
|
-
return entry.handler(editor, index2, step3, ref$1
|
|
127129
|
+
return entry.handler(editor, index2, step3, ref$1);
|
|
127130
127130
|
return resolveBlockRef(editor, index2, step3, ref$1);
|
|
127131
127131
|
}
|
|
127132
|
-
function resolveRefTargets(editor, index2, step3, where
|
|
127133
|
-
return dispatchRefHandler(editor, index2, step3, where.ref
|
|
127132
|
+
function resolveRefTargets(editor, index2, step3, where) {
|
|
127133
|
+
return dispatchRefHandler(editor, index2, step3, where.ref);
|
|
127134
127134
|
}
|
|
127135
|
-
function resolveStepTargets(editor, index2, step3
|
|
127135
|
+
function resolveStepTargets(editor, index2, step3) {
|
|
127136
127136
|
const where = step3.where;
|
|
127137
127137
|
const refWhere = isRefWhere(where) ? where : undefined;
|
|
127138
127138
|
const selectWhere = isSelectWhere(where) ? where : undefined;
|
|
127139
127139
|
let targets;
|
|
127140
127140
|
if (refWhere)
|
|
127141
|
-
targets = resolveRefTargets(editor, index2, step3, refWhere
|
|
127141
|
+
targets = resolveRefTargets(editor, index2, step3, refWhere);
|
|
127142
127142
|
else if (selectWhere)
|
|
127143
127143
|
targets = resolveTextSelector(editor, index2, selectWhere.select, selectWhere.within, step3.id).addresses.map((addr) => {
|
|
127144
127144
|
const candidate = index2.candidates.find((c$3) => c$3.nodeId === addr.blockId);
|
|
@@ -127320,7 +127320,7 @@ function assertNoDuplicateBlockIds(index2) {
|
|
|
127320
127320
|
remediation: "Re-import the document or call document.repair() to assign unique identities."
|
|
127321
127321
|
});
|
|
127322
127322
|
}
|
|
127323
|
-
function compilePlan(editor, steps
|
|
127323
|
+
function compilePlan(editor, steps) {
|
|
127324
127324
|
if (steps.length > 200)
|
|
127325
127325
|
throw planError("INVALID_INPUT", `plan contains ${steps.length} steps, maximum is 200`);
|
|
127326
127326
|
const compiledRevision = getRevision(editor);
|
|
@@ -127350,7 +127350,7 @@ function compilePlan(editor, steps, options) {
|
|
|
127350
127350
|
throw planError("INVALID_INPUT", `unknown step op "${step3.op}"`, step3.id);
|
|
127351
127351
|
if (isCreateOp(step3.op))
|
|
127352
127352
|
validateCreateStepPosition(step3);
|
|
127353
|
-
const targets = resolveStepTargets(editor, index2, step3
|
|
127353
|
+
const targets = resolveStepTargets(editor, index2, step3);
|
|
127354
127354
|
if (isCreateOp(step3.op) && targets.length > 0) {
|
|
127355
127355
|
const position4 = step3.args.position ?? "after";
|
|
127356
127356
|
const anchorBlockId = resolveCreateAnchorFromTargets(targets, position4, step3.id);
|
|
@@ -128297,7 +128297,7 @@ function executeCompiledPlan(editor, compiled, options = {}) {
|
|
|
128297
128297
|
function executePlan(editor, input2) {
|
|
128298
128298
|
if (!input2.steps?.length)
|
|
128299
128299
|
throw planError("INVALID_INPUT", "plan must contain at least one step");
|
|
128300
|
-
return executeCompiledPlan(editor, compilePlan(editor, input2.steps
|
|
128300
|
+
return executeCompiledPlan(editor, compilePlan(editor, input2.steps), {
|
|
128301
128301
|
changeMode: input2.changeMode ?? "direct",
|
|
128302
128302
|
expectedRevision: input2.expectedRevision
|
|
128303
128303
|
});
|
|
@@ -131692,7 +131692,7 @@ function previewPlan(editor, input2) {
|
|
|
131692
131692
|
let currentPhase = "compile";
|
|
131693
131693
|
let evaluatedRevision = getRevision(editor);
|
|
131694
131694
|
try {
|
|
131695
|
-
const compiled = compilePlan(editor, input2.steps
|
|
131695
|
+
const compiled = compilePlan(editor, input2.steps);
|
|
131696
131696
|
evaluatedRevision = compiled.compiledRevision;
|
|
131697
131697
|
currentPhase = "execute";
|
|
131698
131698
|
const tr = editor.state.tr;
|
|
@@ -191873,7 +191873,7 @@ var Node$13 = class Node$14 {
|
|
|
191873
191873
|
trackedChanges: context.trackedChanges ?? []
|
|
191874
191874
|
});
|
|
191875
191875
|
}, _hoisted_1$6, _hoisted_2$2, _hoisted_3, _hoisted_4, ContextMenu_default, _hoisted_1$5, BasicUpload_default, _hoisted_1$4, MIN_WIDTH = 200, PPI = 96, alignment = "flex-end", Ruler_default, GenericPopover_default, _hoisted_1$3, _hoisted_2$1, RESIZE_HANDLE_WIDTH_PX = 9, RESIZE_HANDLE_HEIGHT_PX = 9, RESIZE_HANDLE_OFFSET_PX = 4, DRAG_OVERLAY_EXTENSION_PX = 1000, MIN_DRAG_OVERLAY_WIDTH_PX = 2000, THROTTLE_INTERVAL_MS = 16, MIN_RESIZE_DELTA_PX = 1, TableResizeOverlay_default, _hoisted_1$2, OVERLAY_EXPANSION_PX = 2000, RESIZE_HANDLE_SIZE_PX = 12, MOUSE_MOVE_THROTTLE_MS = 16, DIMENSION_CHANGE_THRESHOLD_PX = 1, Z_INDEX_OVERLAY = 10, Z_INDEX_HANDLE = 15, Z_INDEX_GUIDELINE = 20, ImageResizeOverlay_default, LINK_CLICK_DEBOUNCE_MS = 300, CURSOR_UPDATE_TIMEOUT_MS = 10, POPOVER_VERTICAL_OFFSET_PX = 15, LinkClickHandler_default, _hoisted_1$1, _hoisted_2, DOCX2 = "application/vnd.openxmlformats-officedocument.wordprocessingml.document", TABLE_RESIZE_HOVER_THRESHOLD = 8, TABLE_RESIZE_THROTTLE_MS = 16, SuperEditor_default, _hoisted_1, SuperInput_default, SlashMenu, Extensions;
|
|
191876
|
-
var
|
|
191876
|
+
var init_src_B8Sjis_q_es = __esm(() => {
|
|
191877
191877
|
init_rolldown_runtime_B2q5OVn9_es();
|
|
191878
191878
|
init_SuperConverter_txXmDgaI_es();
|
|
191879
191879
|
init_jszip_ChlR43oI_es();
|
|
@@ -223403,8 +223403,8 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
223403
223403
|
return isObjectLike_default(value) && hasOwnProperty$8.call(value, "callee") && !propertyIsEnumerable$1.call(value, "callee");
|
|
223404
223404
|
};
|
|
223405
223405
|
stubFalse_default = stubFalse;
|
|
223406
|
-
freeExports$2 = typeof
|
|
223407
|
-
freeModule$2 = freeExports$2 && typeof
|
|
223406
|
+
freeExports$2 = typeof exports_src_B8Sjis_q_es == "object" && exports_src_B8Sjis_q_es && !exports_src_B8Sjis_q_es.nodeType && exports_src_B8Sjis_q_es;
|
|
223407
|
+
freeModule$2 = freeExports$2 && typeof module_src_B8Sjis_q_es == "object" && module_src_B8Sjis_q_es && !module_src_B8Sjis_q_es.nodeType && module_src_B8Sjis_q_es;
|
|
223408
223408
|
Buffer$1 = freeModule$2 && freeModule$2.exports === freeExports$2 ? _root_default.Buffer : undefined;
|
|
223409
223409
|
isBuffer_default = (Buffer$1 ? Buffer$1.isBuffer : undefined) || stubFalse_default;
|
|
223410
223410
|
typedArrayTags = {};
|
|
@@ -223412,8 +223412,8 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
223412
223412
|
typedArrayTags[argsTag$1] = typedArrayTags[arrayTag$1] = typedArrayTags[arrayBufferTag$1] = typedArrayTags[boolTag$1] = typedArrayTags[dataViewTag$2] = typedArrayTags[dateTag$1] = typedArrayTags[errorTag$1] = typedArrayTags[funcTag] = typedArrayTags[mapTag$2] = typedArrayTags[numberTag$1] = typedArrayTags[objectTag$3] = typedArrayTags[regexpTag$1] = typedArrayTags[setTag$2] = typedArrayTags[stringTag$1] = typedArrayTags[weakMapTag$1] = false;
|
|
223413
223413
|
_baseIsTypedArray_default = baseIsTypedArray;
|
|
223414
223414
|
_baseUnary_default = baseUnary;
|
|
223415
|
-
freeExports$1 = typeof
|
|
223416
|
-
freeModule$1 = freeExports$1 && typeof
|
|
223415
|
+
freeExports$1 = typeof exports_src_B8Sjis_q_es == "object" && exports_src_B8Sjis_q_es && !exports_src_B8Sjis_q_es.nodeType && exports_src_B8Sjis_q_es;
|
|
223416
|
+
freeModule$1 = freeExports$1 && typeof module_src_B8Sjis_q_es == "object" && module_src_B8Sjis_q_es && !module_src_B8Sjis_q_es.nodeType && module_src_B8Sjis_q_es;
|
|
223417
223417
|
freeProcess = freeModule$1 && freeModule$1.exports === freeExports$1 && _freeGlobal_default.process;
|
|
223418
223418
|
_nodeUtil_default = function() {
|
|
223419
223419
|
try {
|
|
@@ -223518,8 +223518,8 @@ function print() { __p += __j.call(arguments, '') }
|
|
|
223518
223518
|
Stack.prototype.has = _stackHas_default;
|
|
223519
223519
|
Stack.prototype.set = _stackSet_default;
|
|
223520
223520
|
_Stack_default = Stack;
|
|
223521
|
-
freeExports = typeof
|
|
223522
|
-
freeModule = freeExports && typeof
|
|
223521
|
+
freeExports = typeof exports_src_B8Sjis_q_es == "object" && exports_src_B8Sjis_q_es && !exports_src_B8Sjis_q_es.nodeType && exports_src_B8Sjis_q_es;
|
|
223522
|
+
freeModule = freeExports && typeof module_src_B8Sjis_q_es == "object" && module_src_B8Sjis_q_es && !module_src_B8Sjis_q_es.nodeType && module_src_B8Sjis_q_es;
|
|
223523
223523
|
Buffer4 = freeModule && freeModule.exports === freeExports ? _root_default.Buffer : undefined;
|
|
223524
223524
|
allocUnsafe = Buffer4 ? Buffer4.allocUnsafe : undefined;
|
|
223525
223525
|
_cloneBuffer_default = cloneBuffer;
|
|
@@ -231599,7 +231599,7 @@ var init_zipper_DqXT7uTa_es = __esm(() => {
|
|
|
231599
231599
|
|
|
231600
231600
|
// ../../packages/superdoc/dist/super-editor.es.js
|
|
231601
231601
|
var init_super_editor_es = __esm(() => {
|
|
231602
|
-
|
|
231602
|
+
init_src_B8Sjis_q_es();
|
|
231603
231603
|
init_SuperConverter_txXmDgaI_es();
|
|
231604
231604
|
init_jszip_ChlR43oI_es();
|
|
231605
231605
|
init_xml_js_DLE8mr0n_es();
|
|
@@ -294677,10 +294677,9 @@ function decodeTextRefPayload2(encoded, stepId) {
|
|
|
294677
294677
|
throw planError2("INVALID_INPUT", "invalid text ref encoding", stepId);
|
|
294678
294678
|
}
|
|
294679
294679
|
}
|
|
294680
|
-
function resolveV3TextRef2(editor, index3, step3, refData
|
|
294680
|
+
function resolveV3TextRef2(editor, index3, step3, refData) {
|
|
294681
294681
|
const currentRevision = getRevision2(editor);
|
|
294682
|
-
|
|
294683
|
-
if (enforceRefRevision && refData.rev !== currentRevision) {
|
|
294682
|
+
if (refData.rev !== currentRevision) {
|
|
294684
294683
|
throw planError2("REVISION_MISMATCH", `Text ref is ephemeral and revision-scoped. Re-run query.match to obtain a fresh handle.ref for revision ${currentRevision}.`, step3.id, {
|
|
294685
294684
|
refRevision: refData.rev,
|
|
294686
294685
|
currentRevision,
|
|
@@ -294714,13 +294713,13 @@ function resolveV3TextRef2(editor, index3, step3, refData, options) {
|
|
|
294714
294713
|
}
|
|
294715
294714
|
return [buildSpanTarget2(editor, index3, step3, segments, refData.matchId)];
|
|
294716
294715
|
}
|
|
294717
|
-
function resolveTextRef2(editor, index3, step3, ref4
|
|
294716
|
+
function resolveTextRef2(editor, index3, step3, ref4) {
|
|
294718
294717
|
const encoded = ref4.slice(5);
|
|
294719
294718
|
const payload = decodeTextRefPayload2(encoded, step3.id);
|
|
294720
294719
|
if (!isV3Ref2(payload)) {
|
|
294721
294720
|
throw planError2("INVALID_INPUT", "only V3 text refs are supported", step3.id);
|
|
294722
294721
|
}
|
|
294723
|
-
return resolveV3TextRef2(editor, index3, step3, payload
|
|
294722
|
+
return resolveV3TextRef2(editor, index3, step3, payload);
|
|
294724
294723
|
}
|
|
294725
294724
|
function resolveBlockRef2(editor, index3, step3, ref4) {
|
|
294726
294725
|
const candidate = index3.candidates.find((c2) => c2.nodeId === ref4);
|
|
@@ -294737,24 +294736,24 @@ function resolveBlockRef2(editor, index3, step3, ref4) {
|
|
|
294737
294736
|
};
|
|
294738
294737
|
return [buildRangeTarget2(editor, step3, addr, candidate)];
|
|
294739
294738
|
}
|
|
294740
|
-
function dispatchRefHandler2(editor, index3, step3, ref4
|
|
294739
|
+
function dispatchRefHandler2(editor, index3, step3, ref4) {
|
|
294741
294740
|
for (const entry of REF_HANDLERS2) {
|
|
294742
294741
|
if (entry.prefix === "" || ref4.startsWith(entry.prefix)) {
|
|
294743
|
-
return entry.handler(editor, index3, step3, ref4
|
|
294742
|
+
return entry.handler(editor, index3, step3, ref4);
|
|
294744
294743
|
}
|
|
294745
294744
|
}
|
|
294746
294745
|
return resolveBlockRef2(editor, index3, step3, ref4);
|
|
294747
294746
|
}
|
|
294748
|
-
function resolveRefTargets2(editor, index3, step3, where
|
|
294749
|
-
return dispatchRefHandler2(editor, index3, step3, where.ref
|
|
294747
|
+
function resolveRefTargets2(editor, index3, step3, where) {
|
|
294748
|
+
return dispatchRefHandler2(editor, index3, step3, where.ref);
|
|
294750
294749
|
}
|
|
294751
|
-
function resolveStepTargets2(editor, index3, step3
|
|
294750
|
+
function resolveStepTargets2(editor, index3, step3) {
|
|
294752
294751
|
const where = step3.where;
|
|
294753
294752
|
const refWhere = isRefWhere2(where) ? where : undefined;
|
|
294754
294753
|
const selectWhere = isSelectWhere2(where) ? where : undefined;
|
|
294755
294754
|
let targets;
|
|
294756
294755
|
if (refWhere) {
|
|
294757
|
-
targets = resolveRefTargets2(editor, index3, step3, refWhere
|
|
294756
|
+
targets = resolveRefTargets2(editor, index3, step3, refWhere);
|
|
294758
294757
|
} else if (selectWhere) {
|
|
294759
294758
|
const resolved = resolveTextSelector2(editor, index3, selectWhere.select, selectWhere.within, step3.id);
|
|
294760
294759
|
targets = resolved.addresses.map((addr) => {
|
|
@@ -294948,7 +294947,7 @@ function assertNoDuplicateBlockIds2(index3) {
|
|
|
294948
294947
|
});
|
|
294949
294948
|
}
|
|
294950
294949
|
}
|
|
294951
|
-
function compilePlan2(editor, steps
|
|
294950
|
+
function compilePlan2(editor, steps) {
|
|
294952
294951
|
if (steps.length > MAX_PLAN_STEPS) {
|
|
294953
294952
|
throw planError2("INVALID_INPUT", `plan contains ${steps.length} steps, maximum is ${MAX_PLAN_STEPS}`);
|
|
294954
294953
|
}
|
|
@@ -294984,7 +294983,7 @@ function compilePlan2(editor, steps, options) {
|
|
|
294984
294983
|
if (isCreateOp2(step3.op)) {
|
|
294985
294984
|
validateCreateStepPosition2(step3);
|
|
294986
294985
|
}
|
|
294987
|
-
const targets = resolveStepTargets2(editor, index3, step3
|
|
294986
|
+
const targets = resolveStepTargets2(editor, index3, step3);
|
|
294988
294987
|
if (isCreateOp2(step3.op) && targets.length > 0) {
|
|
294989
294988
|
const position5 = step3.args.position ?? "after";
|
|
294990
294989
|
const anchorBlockId = resolveCreateAnchorFromTargets2(targets, position5, step3.id);
|
|
@@ -296014,9 +296013,7 @@ function executePlan2(editor, input2) {
|
|
|
296014
296013
|
if (!input2.steps?.length) {
|
|
296015
296014
|
throw planError2("INVALID_INPUT", "plan must contain at least one step");
|
|
296016
296015
|
}
|
|
296017
|
-
const compiled = compilePlan2(editor, input2.steps
|
|
296018
|
-
enforceRefRevision: input2.expectedRevision !== undefined
|
|
296019
|
-
});
|
|
296016
|
+
const compiled = compilePlan2(editor, input2.steps);
|
|
296020
296017
|
return executeCompiledPlan2(editor, compiled, {
|
|
296021
296018
|
changeMode: input2.changeMode ?? "direct",
|
|
296022
296019
|
expectedRevision: input2.expectedRevision
|
|
@@ -299535,9 +299532,7 @@ function previewPlan2(editor, input2) {
|
|
|
299535
299532
|
let currentPhase = "compile";
|
|
299536
299533
|
let evaluatedRevision = getRevision2(editor);
|
|
299537
299534
|
try {
|
|
299538
|
-
const compiled = compilePlan2(editor, input2.steps
|
|
299539
|
-
enforceRefRevision: input2.expectedRevision !== undefined
|
|
299540
|
-
});
|
|
299535
|
+
const compiled = compilePlan2(editor, input2.steps);
|
|
299541
299536
|
evaluatedRevision = compiled.compiledRevision;
|
|
299542
299537
|
currentPhase = "execute";
|
|
299543
299538
|
const tr = editor.state.tr;
|
|
@@ -361076,28 +361071,24 @@ async function openCollaborativeDocument(doc4, io, profile, options2 = {}) {
|
|
|
361076
361071
|
}
|
|
361077
361072
|
}
|
|
361078
361073
|
async function openSessionDocument(doc4, io, metadata, options2 = {}) {
|
|
361079
|
-
|
|
361080
|
-
|
|
361081
|
-
|
|
361082
|
-
|
|
361083
|
-
|
|
361074
|
+
const { executionMode, sessionPool, sessionId } = options2;
|
|
361075
|
+
if (executionMode === "host" && sessionPool) {
|
|
361076
|
+
const resolvedSessionId = sessionId ?? metadata.contextId;
|
|
361077
|
+
return sessionPool.acquire(resolvedSessionId, {
|
|
361078
|
+
sessionType: metadata.sessionType,
|
|
361079
|
+
workingDocPath: metadata.workingDocPath ?? doc4,
|
|
361080
|
+
metadataRevision: metadata.revision,
|
|
361081
|
+
user: metadata.user,
|
|
361082
|
+
collaboration: metadata.collaboration
|
|
361083
|
+
}, io);
|
|
361084
361084
|
}
|
|
361085
|
-
if (
|
|
361086
|
-
|
|
361087
|
-
|
|
361088
|
-
throw new CliError("COMMAND_FAILED", "Session id is required for host-mode collaboration operations.");
|
|
361085
|
+
if (metadata.sessionType === "collab") {
|
|
361086
|
+
if (!metadata.collaboration) {
|
|
361087
|
+
throw new CliError("COMMAND_FAILED", "Session is marked as collaborative but has no collaboration profile.");
|
|
361089
361088
|
}
|
|
361090
|
-
|
|
361091
|
-
contextId: sessionId,
|
|
361092
|
-
sessionType: metadata.sessionType,
|
|
361093
|
-
collaboration: metadata.collaboration,
|
|
361094
|
-
sourcePath: metadata.sourcePath,
|
|
361095
|
-
workingDocPath: metadata.workingDocPath,
|
|
361096
|
-
user: metadata.user
|
|
361097
|
-
};
|
|
361098
|
-
return options2.collabSessionPool.acquire(sessionId, doc4, metadataForPool, io);
|
|
361089
|
+
return openCollaborativeDocument(doc4, io, metadata.collaboration, { user: metadata.user });
|
|
361099
361090
|
}
|
|
361100
|
-
return
|
|
361091
|
+
return openDocument(doc4, io, { user: metadata.user });
|
|
361101
361092
|
}
|
|
361102
361093
|
async function getFileChecksum(path3) {
|
|
361103
361094
|
let bytes;
|
|
@@ -362546,16 +362537,17 @@ async function executeReadOperation(request) {
|
|
|
362546
362537
|
}
|
|
362547
362538
|
}
|
|
362548
362539
|
return withActiveContext(context.io, commandName, async ({ metadata, paths }) => {
|
|
362549
|
-
|
|
362550
|
-
|
|
362551
|
-
|
|
362552
|
-
|
|
362553
|
-
|
|
362554
|
-
|
|
362555
|
-
|
|
362556
|
-
|
|
362557
|
-
|
|
362558
|
-
const
|
|
362540
|
+
const opened = await openSessionDocument(paths.workingDocPath, context.io, metadata, {
|
|
362541
|
+
sessionId: context.sessionId ?? metadata.contextId,
|
|
362542
|
+
executionMode: context.executionMode,
|
|
362543
|
+
sessionPool: context.sessionPool
|
|
362544
|
+
});
|
|
362545
|
+
try {
|
|
362546
|
+
const result2 = invokeOperation(opened.editor, operationId, input2);
|
|
362547
|
+
const isHostMode = context.executionMode === "host" && context.sessionPool != null;
|
|
362548
|
+
if (!isHostMode && metadata.sessionType === "collab") {
|
|
362549
|
+
const synced = await syncCollaborativeSessionSnapshot(context.io, metadata, paths, opened.editor);
|
|
362550
|
+
const document5 = {
|
|
362559
362551
|
path: synced.updatedMetadata.sourcePath,
|
|
362560
362552
|
source: synced.updatedMetadata.source,
|
|
362561
362553
|
byteLength: synced.output.byteLength,
|
|
@@ -362563,16 +362555,10 @@ async function executeReadOperation(request) {
|
|
|
362563
362555
|
};
|
|
362564
362556
|
return {
|
|
362565
362557
|
command: commandName,
|
|
362566
|
-
data: buildEnvelopeData(operationId,
|
|
362567
|
-
pretty: buildPrettyOutput(operationId,
|
|
362558
|
+
data: buildEnvelopeData(operationId, document5, result2, input2),
|
|
362559
|
+
pretty: buildPrettyOutput(operationId, document5, result2)
|
|
362568
362560
|
};
|
|
362569
|
-
} finally {
|
|
362570
|
-
opened2.dispose();
|
|
362571
362561
|
}
|
|
362572
|
-
}
|
|
362573
|
-
const opened = await openDocument(paths.workingDocPath, context.io, { user: metadata.user });
|
|
362574
|
-
try {
|
|
362575
|
-
const result2 = invokeOperation(opened.editor, operationId, input2);
|
|
362576
362562
|
const document4 = {
|
|
362577
362563
|
path: metadata.sourcePath,
|
|
362578
362564
|
source: metadata.source,
|
|
@@ -362719,89 +362705,71 @@ async function executeMutationOperation(request) {
|
|
|
362719
362705
|
}
|
|
362720
362706
|
return withActiveContext(context.io, commandName, async ({ metadata, paths }) => {
|
|
362721
362707
|
assertExpectedRevision(metadata, expectedRevision);
|
|
362722
|
-
|
|
362723
|
-
|
|
362724
|
-
|
|
362725
|
-
|
|
362726
|
-
|
|
362727
|
-
|
|
362728
|
-
try {
|
|
362729
|
-
const result2 = invokeOperation2(opened2.editor, operationId, input2, invokeOptions);
|
|
362730
|
-
const synced = await syncCollaborativeSessionSnapshot(context.io, metadata, paths, opened2.editor);
|
|
362731
|
-
const document4 = {
|
|
362732
|
-
path: synced.updatedMetadata.sourcePath,
|
|
362733
|
-
source: synced.updatedMetadata.source,
|
|
362734
|
-
byteLength: synced.output.byteLength,
|
|
362735
|
-
revision: synced.updatedMetadata.revision
|
|
362736
|
-
};
|
|
362737
|
-
if (dryRun) {
|
|
362738
|
-
return {
|
|
362739
|
-
command: commandName,
|
|
362740
|
-
data: {
|
|
362741
|
-
...buildEnvelopeData2(operationId, document4, result2, { changeMode, dryRun: true }),
|
|
362742
|
-
context: { dirty: synced.updatedMetadata.dirty, revision: synced.updatedMetadata.revision },
|
|
362743
|
-
output: outPath ? { path: outPath, skippedWrite: true } : undefined
|
|
362744
|
-
},
|
|
362745
|
-
pretty: `Revision ${synced.updatedMetadata.revision}: dry run`
|
|
362746
|
-
};
|
|
362747
|
-
}
|
|
362748
|
-
const externalOutput = await exportOptionalSessionOutput(opened2.editor, outPath, force);
|
|
362749
|
-
return {
|
|
362750
|
-
command: commandName,
|
|
362751
|
-
data: buildEnvelopeData2(operationId, document4, result2, {
|
|
362752
|
-
changeMode,
|
|
362753
|
-
dryRun: false,
|
|
362754
|
-
context: { dirty: synced.updatedMetadata.dirty, revision: synced.updatedMetadata.revision },
|
|
362755
|
-
output: externalOutput
|
|
362756
|
-
}),
|
|
362757
|
-
pretty: buildPrettyOutput2(operationId, document4, result2, externalOutput?.path)
|
|
362758
|
-
};
|
|
362759
|
-
} finally {
|
|
362760
|
-
opened2.dispose();
|
|
362761
|
-
}
|
|
362762
|
-
}
|
|
362763
|
-
const opened = await openDocument(paths.workingDocPath, context.io, { user: metadata.user });
|
|
362708
|
+
const isHostMode = context.executionMode === "host" && context.sessionPool != null;
|
|
362709
|
+
const opened = await openSessionDocument(paths.workingDocPath, context.io, metadata, {
|
|
362710
|
+
sessionId: context.sessionId ?? metadata.contextId,
|
|
362711
|
+
executionMode: context.executionMode,
|
|
362712
|
+
sessionPool: context.sessionPool
|
|
362713
|
+
});
|
|
362764
362714
|
try {
|
|
362765
362715
|
const result2 = invokeOperation2(opened.editor, operationId, input2, invokeOptions);
|
|
362766
|
-
const document4 = {
|
|
362767
|
-
path: metadata.sourcePath,
|
|
362768
|
-
source: metadata.source,
|
|
362769
|
-
byteLength: opened.meta.byteLength,
|
|
362770
|
-
revision: metadata.revision
|
|
362771
|
-
};
|
|
362772
362716
|
if (dryRun) {
|
|
362717
|
+
const document5 = {
|
|
362718
|
+
path: metadata.sourcePath,
|
|
362719
|
+
source: metadata.source,
|
|
362720
|
+
byteLength: opened.meta.byteLength,
|
|
362721
|
+
revision: metadata.revision
|
|
362722
|
+
};
|
|
362773
362723
|
return {
|
|
362774
362724
|
command: commandName,
|
|
362775
362725
|
data: {
|
|
362776
|
-
...buildEnvelopeData2(operationId,
|
|
362726
|
+
...buildEnvelopeData2(operationId, document5, result2, { changeMode, dryRun: true }),
|
|
362777
362727
|
context: { dirty: metadata.dirty, revision: metadata.revision },
|
|
362778
362728
|
output: outPath ? { path: outPath, skippedWrite: true } : undefined
|
|
362779
362729
|
},
|
|
362780
362730
|
pretty: `Revision ${metadata.revision}: dry run`
|
|
362781
362731
|
};
|
|
362782
362732
|
}
|
|
362783
|
-
|
|
362733
|
+
let updatedMetadata;
|
|
362734
|
+
let byteLength3;
|
|
362735
|
+
if (isHostMode) {
|
|
362736
|
+
context.sessionPool.markDirty(metadata.contextId);
|
|
362737
|
+
updatedMetadata = markContextUpdated(context.io, metadata, {
|
|
362738
|
+
dirty: true,
|
|
362739
|
+
revision: metadata.revision + 1
|
|
362740
|
+
});
|
|
362741
|
+
await writeContextMetadata(paths, updatedMetadata);
|
|
362742
|
+
context.sessionPool.updateMetadataRevision(metadata.contextId, updatedMetadata.revision);
|
|
362743
|
+
byteLength3 = opened.meta.byteLength;
|
|
362744
|
+
} else if (metadata.sessionType === "collab") {
|
|
362745
|
+
const synced = await syncCollaborativeSessionSnapshot(context.io, metadata, paths, opened.editor);
|
|
362746
|
+
updatedMetadata = synced.updatedMetadata;
|
|
362747
|
+
byteLength3 = synced.output.byteLength;
|
|
362748
|
+
} else {
|
|
362749
|
+
const workingOutput = await exportToPath(opened.editor, paths.workingDocPath, true);
|
|
362750
|
+
updatedMetadata = markContextUpdated(context.io, metadata, {
|
|
362751
|
+
dirty: true,
|
|
362752
|
+
revision: metadata.revision + 1
|
|
362753
|
+
});
|
|
362754
|
+
await writeContextMetadata(paths, updatedMetadata);
|
|
362755
|
+
byteLength3 = workingOutput.byteLength;
|
|
362756
|
+
}
|
|
362784
362757
|
const externalOutput = await exportOptionalSessionOutput(opened.editor, outPath, force);
|
|
362785
|
-
const
|
|
362786
|
-
dirty: true,
|
|
362787
|
-
revision: metadata.revision + 1
|
|
362788
|
-
});
|
|
362789
|
-
await writeContextMetadata(paths, updatedMetadata);
|
|
362790
|
-
const updatedDocument = {
|
|
362758
|
+
const document4 = {
|
|
362791
362759
|
path: updatedMetadata.sourcePath,
|
|
362792
362760
|
source: updatedMetadata.source,
|
|
362793
|
-
byteLength:
|
|
362761
|
+
byteLength: byteLength3,
|
|
362794
362762
|
revision: updatedMetadata.revision
|
|
362795
362763
|
};
|
|
362796
362764
|
return {
|
|
362797
362765
|
command: commandName,
|
|
362798
|
-
data: buildEnvelopeData2(operationId,
|
|
362766
|
+
data: buildEnvelopeData2(operationId, document4, result2, {
|
|
362799
362767
|
changeMode,
|
|
362800
362768
|
dryRun: false,
|
|
362801
362769
|
context: { dirty: updatedMetadata.dirty, revision: updatedMetadata.revision },
|
|
362802
362770
|
output: externalOutput
|
|
362803
362771
|
}),
|
|
362804
|
-
pretty: buildPrettyOutput2(operationId,
|
|
362772
|
+
pretty: buildPrettyOutput2(operationId, document4, result2, externalOutput?.path)
|
|
362805
362773
|
};
|
|
362806
362774
|
} finally {
|
|
362807
362775
|
opened.dispose();
|
|
@@ -364925,8 +364893,8 @@ async function runClose(tokens, context) {
|
|
|
364925
364893
|
},
|
|
364926
364894
|
pretty: mode2.discard ? "Closed context (discarded unsaved changes)" : "Closed context"
|
|
364927
364895
|
};
|
|
364928
|
-
if (context.executionMode === "host" && context.
|
|
364929
|
-
await context.
|
|
364896
|
+
if (context.executionMode === "host" && context.sessionPool) {
|
|
364897
|
+
await context.sessionPool.disposeSession(effectiveMetadata.contextId, { discard: mode2.discard });
|
|
364930
364898
|
}
|
|
364931
364899
|
await clearContext(paths);
|
|
364932
364900
|
if (wasDefaultSession) {
|
|
@@ -365066,8 +365034,13 @@ async function runOpen(tokens, context) {
|
|
|
365066
365034
|
});
|
|
365067
365035
|
await writeContextMetadata(paths, metadata);
|
|
365068
365036
|
await setActiveSessionId(metadata.contextId);
|
|
365069
|
-
if (
|
|
365070
|
-
|
|
365037
|
+
if (context.executionMode === "host" && context.sessionPool) {
|
|
365038
|
+
context.sessionPool.adoptFromOpen(sessionId, opened, {
|
|
365039
|
+
sessionType: metadata.sessionType,
|
|
365040
|
+
workingDocPath: paths.workingDocPath,
|
|
365041
|
+
metadataRevision: metadata.revision,
|
|
365042
|
+
collaboration: metadata.collaboration
|
|
365043
|
+
});
|
|
365071
365044
|
adoptedToHostPool = true;
|
|
365072
365045
|
}
|
|
365073
365046
|
return {
|
|
@@ -365136,11 +365109,13 @@ async function runSave(tokens, context) {
|
|
|
365136
365109
|
const mode2 = validateSaveMode(getBooleanOption(parsed, "in-place"), getStringOption(parsed, "out"), getBooleanOption(parsed, "force"));
|
|
365137
365110
|
return withActiveContext(context.io, "save", async ({ metadata, paths }) => {
|
|
365138
365111
|
let effectiveMetadata = metadata;
|
|
365139
|
-
if (
|
|
365112
|
+
if (context.executionMode === "host" && context.sessionPool) {
|
|
365113
|
+
await context.sessionPool.checkpoint(metadata.contextId);
|
|
365114
|
+
} else if (metadata.sessionType === "collab") {
|
|
365140
365115
|
const opened = await openSessionDocument(paths.workingDocPath, context.io, metadata, {
|
|
365141
365116
|
sessionId: context.sessionId ?? metadata.contextId,
|
|
365142
365117
|
executionMode: context.executionMode,
|
|
365143
|
-
|
|
365118
|
+
sessionPool: context.sessionPool
|
|
365144
365119
|
});
|
|
365145
365120
|
try {
|
|
365146
365121
|
const synced = await syncCollaborativeSessionSnapshot(context.io, metadata, paths, opened.editor);
|
|
@@ -371563,8 +371538,8 @@ var init_uninstall = __esm(() => {
|
|
|
371563
371538
|
];
|
|
371564
371539
|
});
|
|
371565
371540
|
|
|
371566
|
-
// src/host/
|
|
371567
|
-
function
|
|
371541
|
+
// src/host/session-pool.ts
|
|
371542
|
+
function profileToFingerprint(profile) {
|
|
371568
371543
|
return JSON.stringify({
|
|
371569
371544
|
providerType: profile.providerType,
|
|
371570
371545
|
url: profile.url,
|
|
@@ -371575,90 +371550,217 @@ function profileToKey(profile) {
|
|
|
371575
371550
|
bootstrapSettlingMs: profile.bootstrapSettlingMs ?? null
|
|
371576
371551
|
});
|
|
371577
371552
|
}
|
|
371578
|
-
function
|
|
371579
|
-
|
|
371580
|
-
|
|
371581
|
-
|
|
371582
|
-
|
|
371583
|
-
|
|
371584
|
-
|
|
371585
|
-
|
|
371586
|
-
|
|
371587
|
-
|
|
371553
|
+
function createSessionLocks() {
|
|
371554
|
+
const locks = new Map;
|
|
371555
|
+
function withLock(sessionId, fn2) {
|
|
371556
|
+
const entry = locks.get(sessionId) ?? { chain: Promise.resolve() };
|
|
371557
|
+
locks.set(sessionId, entry);
|
|
371558
|
+
const result2 = entry.chain.then(fn2, fn2);
|
|
371559
|
+
entry.chain = result2.then(() => {
|
|
371560
|
+
return;
|
|
371561
|
+
}, () => {
|
|
371562
|
+
return;
|
|
371588
371563
|
});
|
|
371564
|
+
return result2;
|
|
371589
371565
|
}
|
|
371590
|
-
return {
|
|
371591
|
-
profileKey: profileToKey(metadata.collaboration),
|
|
371592
|
-
workingDocPath: metadata.workingDocPath
|
|
371593
|
-
};
|
|
371594
|
-
}
|
|
371595
|
-
function sameFingerprint(left2, right2) {
|
|
371596
|
-
return left2.profileKey === right2.profileKey && left2.workingDocPath === right2.workingDocPath;
|
|
371566
|
+
return { withLock };
|
|
371597
371567
|
}
|
|
371598
371568
|
|
|
371599
|
-
class
|
|
371600
|
-
|
|
371569
|
+
class InMemorySessionPool {
|
|
371570
|
+
sessions = new Map;
|
|
371571
|
+
sessionLocks = createSessionLocks();
|
|
371572
|
+
openLocal;
|
|
371601
371573
|
openCollaborative;
|
|
371574
|
+
exportToPathFn;
|
|
371602
371575
|
now;
|
|
371603
|
-
|
|
371604
|
-
|
|
371605
|
-
|
|
371576
|
+
createTimer;
|
|
371577
|
+
clearTimer;
|
|
371578
|
+
constructor(deps = {}) {
|
|
371579
|
+
this.openLocal = deps.openLocal ?? openDocument;
|
|
371580
|
+
this.openCollaborative = deps.openCollaborative ?? openCollaborativeDocument;
|
|
371581
|
+
this.exportToPathFn = deps.exportToPath ?? exportToPath;
|
|
371582
|
+
this.now = deps.now ?? Date.now;
|
|
371583
|
+
this.createTimer = deps.createTimer ?? setTimeout;
|
|
371584
|
+
this.clearTimer = deps.clearTimer ?? clearTimeout;
|
|
371585
|
+
}
|
|
371586
|
+
async acquire(sessionId, metadata, io) {
|
|
371587
|
+
return this.sessionLocks.withLock(sessionId, async () => {
|
|
371588
|
+
const existing = this.sessions.get(sessionId);
|
|
371589
|
+
if (existing) {
|
|
371590
|
+
if (this.isSessionValid(existing, metadata)) {
|
|
371591
|
+
existing.leased = true;
|
|
371592
|
+
existing.lastUsedAtMs = this.now();
|
|
371593
|
+
existing.io = io;
|
|
371594
|
+
return this.createLease(sessionId, existing);
|
|
371595
|
+
}
|
|
371596
|
+
await this.destroySession(existing);
|
|
371597
|
+
this.sessions.delete(sessionId);
|
|
371598
|
+
}
|
|
371599
|
+
const session = await this.openFreshSession(metadata, io);
|
|
371600
|
+
this.sessions.set(sessionId, session);
|
|
371601
|
+
return this.createLease(sessionId, session);
|
|
371602
|
+
});
|
|
371606
371603
|
}
|
|
371607
|
-
|
|
371608
|
-
const
|
|
371609
|
-
const existing = this.handles.get(sessionId);
|
|
371604
|
+
adoptFromOpen(sessionId, opened, metadata) {
|
|
371605
|
+
const existing = this.sessions.get(sessionId);
|
|
371610
371606
|
if (existing) {
|
|
371611
|
-
|
|
371612
|
-
|
|
371613
|
-
return this.createLease(existing);
|
|
371614
|
-
}
|
|
371615
|
-
await this.disposeSession(sessionId);
|
|
371607
|
+
this.clearAutosaveTimer(existing);
|
|
371608
|
+
existing.opened.dispose();
|
|
371616
371609
|
}
|
|
371617
|
-
|
|
371618
|
-
const opened = await this.openCollaborative(docPath, io, profile, { user: metadata.user });
|
|
371619
|
-
const created = {
|
|
371610
|
+
this.sessions.set(sessionId, {
|
|
371620
371611
|
opened,
|
|
371621
|
-
|
|
371622
|
-
|
|
371623
|
-
|
|
371624
|
-
|
|
371625
|
-
|
|
371626
|
-
|
|
371627
|
-
|
|
371628
|
-
|
|
371629
|
-
|
|
371630
|
-
|
|
371631
|
-
opened,
|
|
371632
|
-
fingerprint,
|
|
371633
|
-
lastUsedAtMs: this.now()
|
|
371612
|
+
sessionType: metadata.sessionType,
|
|
371613
|
+
dirty: false,
|
|
371614
|
+
leased: false,
|
|
371615
|
+
workingDocPath: metadata.workingDocPath,
|
|
371616
|
+
io: { stdout() {}, stderr() {}, readStdinBytes: async () => new Uint8Array, now: this.now },
|
|
371617
|
+
metadataRevision: metadata.metadataRevision,
|
|
371618
|
+
lastUsedAtMs: this.now(),
|
|
371619
|
+
autosaveTimer: null,
|
|
371620
|
+
collaboration: metadata.collaboration,
|
|
371621
|
+
fingerprint: metadata.collaboration ? profileToFingerprint(metadata.collaboration) : undefined
|
|
371634
371622
|
});
|
|
371635
371623
|
}
|
|
371636
|
-
async
|
|
371637
|
-
|
|
371638
|
-
|
|
371624
|
+
async checkpoint(sessionId) {
|
|
371625
|
+
return this.sessionLocks.withLock(sessionId, () => this.checkpointUnsafe(sessionId));
|
|
371626
|
+
}
|
|
371627
|
+
async checkpointAll() {
|
|
371628
|
+
const ids = Array.from(this.sessions.keys());
|
|
371629
|
+
for (const id3 of ids) {
|
|
371630
|
+
await this.checkpoint(id3);
|
|
371631
|
+
}
|
|
371632
|
+
}
|
|
371633
|
+
markDirty(sessionId) {
|
|
371634
|
+
const session = this.sessions.get(sessionId);
|
|
371635
|
+
if (!session)
|
|
371636
|
+
return;
|
|
371637
|
+
session.dirty = true;
|
|
371638
|
+
this.resetAutosaveTimer(sessionId, session);
|
|
371639
|
+
}
|
|
371640
|
+
updateMetadataRevision(sessionId, revision) {
|
|
371641
|
+
const session = this.sessions.get(sessionId);
|
|
371642
|
+
if (!session)
|
|
371639
371643
|
return;
|
|
371640
|
-
|
|
371641
|
-
|
|
371644
|
+
session.metadataRevision = revision;
|
|
371645
|
+
}
|
|
371646
|
+
isDirty(sessionId) {
|
|
371647
|
+
return this.sessions.get(sessionId)?.dirty ?? false;
|
|
371648
|
+
}
|
|
371649
|
+
async disposeSession(sessionId, options2) {
|
|
371650
|
+
return this.sessionLocks.withLock(sessionId, async () => {
|
|
371651
|
+
const session = this.sessions.get(sessionId);
|
|
371652
|
+
if (!session)
|
|
371653
|
+
return;
|
|
371654
|
+
this.clearAutosaveTimer(session);
|
|
371655
|
+
if (session.dirty && !options2?.discard) {
|
|
371656
|
+
await this.checkpointUnsafe(sessionId);
|
|
371657
|
+
}
|
|
371658
|
+
await this.destroySession(session);
|
|
371659
|
+
this.sessions.delete(sessionId);
|
|
371660
|
+
});
|
|
371642
371661
|
}
|
|
371643
371662
|
async disposeAll() {
|
|
371644
|
-
const
|
|
371645
|
-
for (const
|
|
371646
|
-
await this.disposeSession(
|
|
371663
|
+
const ids = Array.from(this.sessions.keys());
|
|
371664
|
+
for (const id3 of ids) {
|
|
371665
|
+
await this.disposeSession(id3);
|
|
371666
|
+
}
|
|
371667
|
+
}
|
|
371668
|
+
async flushPendingCheckpoints() {
|
|
371669
|
+
const ids = Array.from(this.sessions.keys());
|
|
371670
|
+
for (const id3 of ids) {
|
|
371671
|
+
const session = this.sessions.get(id3);
|
|
371672
|
+
if (session?.autosaveTimer != null) {
|
|
371673
|
+
this.clearAutosaveTimer(session);
|
|
371674
|
+
await this.checkpoint(id3);
|
|
371675
|
+
}
|
|
371647
371676
|
}
|
|
371648
371677
|
}
|
|
371649
|
-
|
|
371678
|
+
isSessionValid(session, metadata) {
|
|
371679
|
+
if (session.sessionType === "collab") {
|
|
371680
|
+
const incomingFingerprint = metadata.collaboration ? profileToFingerprint(metadata.collaboration) : undefined;
|
|
371681
|
+
return session.fingerprint === incomingFingerprint && session.workingDocPath === metadata.workingDocPath;
|
|
371682
|
+
}
|
|
371683
|
+
return session.workingDocPath === metadata.workingDocPath && session.metadataRevision === metadata.metadataRevision;
|
|
371684
|
+
}
|
|
371685
|
+
async openFreshSession(metadata, io) {
|
|
371686
|
+
const opened = metadata.sessionType === "collab" && metadata.collaboration ? await this.openCollaborative(metadata.workingDocPath, io, metadata.collaboration, {
|
|
371687
|
+
user: metadata.user
|
|
371688
|
+
}) : await this.openLocal(metadata.workingDocPath, io, { user: metadata.user });
|
|
371689
|
+
return {
|
|
371690
|
+
opened,
|
|
371691
|
+
sessionType: metadata.sessionType,
|
|
371692
|
+
dirty: false,
|
|
371693
|
+
leased: true,
|
|
371694
|
+
workingDocPath: metadata.workingDocPath,
|
|
371695
|
+
io,
|
|
371696
|
+
metadataRevision: metadata.metadataRevision,
|
|
371697
|
+
lastUsedAtMs: this.now(),
|
|
371698
|
+
autosaveTimer: null,
|
|
371699
|
+
collaboration: metadata.collaboration,
|
|
371700
|
+
fingerprint: metadata.collaboration ? profileToFingerprint(metadata.collaboration) : undefined
|
|
371701
|
+
};
|
|
371702
|
+
}
|
|
371703
|
+
createLease(sessionId, session) {
|
|
371650
371704
|
return {
|
|
371651
|
-
editor:
|
|
371652
|
-
meta:
|
|
371705
|
+
editor: session.opened.editor,
|
|
371706
|
+
meta: session.opened.meta,
|
|
371653
371707
|
dispose: () => {
|
|
371654
|
-
|
|
371708
|
+
session.leased = false;
|
|
371709
|
+
session.lastUsedAtMs = this.now();
|
|
371655
371710
|
}
|
|
371656
371711
|
};
|
|
371657
371712
|
}
|
|
371713
|
+
async checkpointUnsafe(sessionId) {
|
|
371714
|
+
const session = this.sessions.get(sessionId);
|
|
371715
|
+
if (!session?.dirty)
|
|
371716
|
+
return;
|
|
371717
|
+
if (session.sessionType === "collab") {
|
|
371718
|
+
await this.checkpointCollabSession(session);
|
|
371719
|
+
} else {
|
|
371720
|
+
await this.checkpointLocalSession(session);
|
|
371721
|
+
}
|
|
371722
|
+
session.dirty = false;
|
|
371723
|
+
this.clearAutosaveTimer(session);
|
|
371724
|
+
}
|
|
371725
|
+
async checkpointLocalSession(session) {
|
|
371726
|
+
await this.exportToPathFn(session.opened.editor, session.workingDocPath, true);
|
|
371727
|
+
}
|
|
371728
|
+
async checkpointCollabSession(session) {
|
|
371729
|
+
await this.exportToPathFn(session.opened.editor, session.workingDocPath, true);
|
|
371730
|
+
}
|
|
371731
|
+
async destroySession(session) {
|
|
371732
|
+
this.clearAutosaveTimer(session);
|
|
371733
|
+
session.opened.dispose();
|
|
371734
|
+
}
|
|
371735
|
+
resetAutosaveTimer(sessionId, session) {
|
|
371736
|
+
this.clearAutosaveTimer(session);
|
|
371737
|
+
session.autosaveTimer = this.createTimer(() => {
|
|
371738
|
+
this.onAutosaveTimerFired(sessionId).catch(() => {});
|
|
371739
|
+
}, AUTOSAVE_DEBOUNCE_MS);
|
|
371740
|
+
}
|
|
371741
|
+
clearAutosaveTimer(session) {
|
|
371742
|
+
if (session.autosaveTimer != null) {
|
|
371743
|
+
this.clearTimer(session.autosaveTimer);
|
|
371744
|
+
session.autosaveTimer = null;
|
|
371745
|
+
}
|
|
371746
|
+
}
|
|
371747
|
+
async onAutosaveTimerFired(sessionId) {
|
|
371748
|
+
await this.sessionLocks.withLock(sessionId, async () => {
|
|
371749
|
+
const session = this.sessions.get(sessionId);
|
|
371750
|
+
if (!session)
|
|
371751
|
+
return;
|
|
371752
|
+
session.autosaveTimer = null;
|
|
371753
|
+
if (session.leased) {
|
|
371754
|
+
this.resetAutosaveTimer(sessionId, session);
|
|
371755
|
+
return;
|
|
371756
|
+
}
|
|
371757
|
+
await this.checkpointUnsafe(sessionId);
|
|
371758
|
+
});
|
|
371759
|
+
}
|
|
371658
371760
|
}
|
|
371659
|
-
var
|
|
371761
|
+
var AUTOSAVE_DEBOUNCE_MS = 3000;
|
|
371762
|
+
var init_session_pool = __esm(() => {
|
|
371660
371763
|
init_document2();
|
|
371661
|
-
init_errors();
|
|
371662
371764
|
});
|
|
371663
371765
|
|
|
371664
371766
|
// src/host/invoke.ts
|
|
@@ -371725,7 +371827,7 @@ async function invokeCliFromHost(rawParams, options2 = {}) {
|
|
|
371725
371827
|
const invocation = await invokeCommand(params4.argv, {
|
|
371726
371828
|
ioOverrides: io,
|
|
371727
371829
|
executionMode: "host",
|
|
371728
|
-
|
|
371830
|
+
sessionPool: options2.sessionPool
|
|
371729
371831
|
});
|
|
371730
371832
|
if (invocation.helpText) {
|
|
371731
371833
|
return {
|
|
@@ -371822,7 +371924,7 @@ class HostServer {
|
|
|
371822
371924
|
io;
|
|
371823
371925
|
requestTimeoutMs;
|
|
371824
371926
|
maxStdinBytes;
|
|
371825
|
-
|
|
371927
|
+
sessionPool;
|
|
371826
371928
|
ownsPool;
|
|
371827
371929
|
queue = Promise.resolve();
|
|
371828
371930
|
shutdownRequested = false;
|
|
@@ -371830,11 +371932,11 @@ class HostServer {
|
|
|
371830
371932
|
this.io = options2.io;
|
|
371831
371933
|
this.requestTimeoutMs = options2.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
371832
371934
|
this.maxStdinBytes = options2.maxStdinBytes ?? DEFAULT_MAX_STDIN_BYTES;
|
|
371833
|
-
if (options2.
|
|
371834
|
-
this.
|
|
371935
|
+
if (options2.sessionPool) {
|
|
371936
|
+
this.sessionPool = options2.sessionPool;
|
|
371835
371937
|
this.ownsPool = false;
|
|
371836
371938
|
} else {
|
|
371837
|
-
this.
|
|
371939
|
+
this.sessionPool = new InMemorySessionPool;
|
|
371838
371940
|
this.ownsPool = true;
|
|
371839
371941
|
}
|
|
371840
371942
|
}
|
|
@@ -371866,7 +371968,7 @@ class HostServer {
|
|
|
371866
371968
|
}
|
|
371867
371969
|
async dispose() {
|
|
371868
371970
|
if (this.ownsPool) {
|
|
371869
|
-
await this.
|
|
371971
|
+
await this.sessionPool.disposeAll();
|
|
371870
371972
|
}
|
|
371871
371973
|
}
|
|
371872
371974
|
writeFrame(frame) {
|
|
@@ -371941,7 +372043,7 @@ class HostServer {
|
|
|
371941
372043
|
}
|
|
371942
372044
|
const outcome = await settleWithTimeout(invokeCliFromHost(request.params, {
|
|
371943
372045
|
ioNow: this.io.now,
|
|
371944
|
-
|
|
372046
|
+
sessionPool: this.sessionPool,
|
|
371945
372047
|
maxStdinBytes: this.maxStdinBytes
|
|
371946
372048
|
}), this.requestTimeoutMs);
|
|
371947
372049
|
if (outcome.kind === "timeout") {
|
|
@@ -372006,7 +372108,7 @@ var init_server = __esm(async () => {
|
|
|
372006
372108
|
init_errors();
|
|
372007
372109
|
init_guards();
|
|
372008
372110
|
init_contract2();
|
|
372009
|
-
|
|
372111
|
+
init_session_pool();
|
|
372010
372112
|
init_protocol();
|
|
372011
372113
|
await init_invoke2();
|
|
372012
372114
|
});
|
|
@@ -372118,7 +372220,7 @@ function parseInvocation(argv) {
|
|
|
372118
372220
|
const { globals, rest } = parseGlobalArgs(argv);
|
|
372119
372221
|
return { globals, rest };
|
|
372120
372222
|
}
|
|
372121
|
-
async function executeParsedInvocation(parsed, io, executionMode,
|
|
372223
|
+
async function executeParsedInvocation(parsed, io, executionMode, sessionPool) {
|
|
372122
372224
|
if (parsed.globals.help || parsed.rest.length === 0) {
|
|
372123
372225
|
return { helpText: HELP };
|
|
372124
372226
|
}
|
|
@@ -372128,7 +372230,7 @@ async function executeParsedInvocation(parsed, io, executionMode, collabSessionP
|
|
|
372128
372230
|
timeoutMs: parsed.globals.timeoutMs,
|
|
372129
372231
|
sessionId: parsed.globals.sessionId,
|
|
372130
372232
|
executionMode,
|
|
372131
|
-
|
|
372233
|
+
sessionPool
|
|
372132
372234
|
};
|
|
372133
372235
|
const execution = await executeWithTimeout(async () => {
|
|
372134
372236
|
if (MANUAL_COMMAND_KEY_SET.has(key2)) {
|
|
@@ -372159,7 +372261,7 @@ async function invokeCommand(argv, options2 = {}) {
|
|
|
372159
372261
|
const startedAt = io.now();
|
|
372160
372262
|
const { parsed, output } = await withStateDirOverride(options2.stateDir, async () => {
|
|
372161
372263
|
const parsedInvocation = parseInvocation(argv);
|
|
372162
|
-
const commandOutput = await executeParsedInvocation(parsedInvocation, io, options2.executionMode ?? "oneshot", options2.
|
|
372264
|
+
const commandOutput = await executeParsedInvocation(parsedInvocation, io, options2.executionMode ?? "oneshot", options2.sessionPool);
|
|
372163
372265
|
return { parsed: parsedInvocation, output: commandOutput };
|
|
372164
372266
|
});
|
|
372165
372267
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superdoc-dev/cli",
|
|
3
|
-
"version": "0.2.0-next.
|
|
3
|
+
"version": "0.2.0-next.79",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"superdoc": "./dist/index.js"
|
|
@@ -22,19 +22,19 @@
|
|
|
22
22
|
"typescript": "^5.9.2",
|
|
23
23
|
"@superdoc/document-api": "0.0.1",
|
|
24
24
|
"@superdoc/pm-adapter": "0.0.0",
|
|
25
|
-
"superdoc": "
|
|
26
|
-
"
|
|
25
|
+
"@superdoc/super-editor": "0.0.1",
|
|
26
|
+
"superdoc": "1.17.0"
|
|
27
27
|
},
|
|
28
28
|
"module": "src/index.ts",
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
32
|
"optionalDependencies": {
|
|
33
|
-
"@superdoc-dev/cli-darwin-arm64": "0.2.0-next.
|
|
34
|
-
"@superdoc-dev/cli-
|
|
35
|
-
"@superdoc-dev/cli-
|
|
36
|
-
"@superdoc-dev/cli-
|
|
37
|
-
"@superdoc-dev/cli-
|
|
33
|
+
"@superdoc-dev/cli-darwin-arm64": "0.2.0-next.79",
|
|
34
|
+
"@superdoc-dev/cli-darwin-x64": "0.2.0-next.79",
|
|
35
|
+
"@superdoc-dev/cli-linux-x64": "0.2.0-next.79",
|
|
36
|
+
"@superdoc-dev/cli-windows-x64": "0.2.0-next.79",
|
|
37
|
+
"@superdoc-dev/cli-linux-arm64": "0.2.0-next.79"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"dev": "bun run src/index.ts",
|