@artenx/dshb 0.1.53 → 0.1.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/README.md +22 -7
  2. package/lib/auth/decorate-webserver.js +4 -4
  3. package/lib/auth/decorate-webserver.js.map +1 -1
  4. package/lib/auth/gate.d.ts +11 -3
  5. package/lib/auth/gate.js +14 -2
  6. package/lib/auth/gate.js.map +1 -1
  7. package/lib/auth/index.js +22 -3
  8. package/lib/auth/index.js.map +1 -1
  9. package/lib/auth/webserver.js +4 -4
  10. package/lib/auth/webserver.js.map +1 -1
  11. package/lib/{catalog-BPkswHoz.js → catalog-B6Qvy7bH.js} +8 -4
  12. package/lib/catalog-B6Qvy7bH.js.map +1 -0
  13. package/lib/client.js +421 -29
  14. package/lib/client.js.map +1 -1
  15. package/lib/core/index.js +132 -202
  16. package/lib/core/index.js.map +1 -1
  17. package/lib/core/node-registry.js +1 -1
  18. package/lib/core/routes.d.ts +1 -1
  19. package/lib/core/sync/coordinator.d.ts +5 -5
  20. package/lib/core/sync/coordinator.js +1 -1
  21. package/lib/core/sync/host-key.d.ts +1 -1
  22. package/lib/core/sync/internal-routes.d.ts +3 -3
  23. package/lib/core/sync/internal-routes.js +52 -2
  24. package/lib/core/sync/internal-routes.js.map +1 -1
  25. package/lib/core/sync/model.d.ts +1 -1
  26. package/lib/core/sync/model.js.map +1 -1
  27. package/lib/core/sync/node-sync.d.ts +1 -1
  28. package/lib/core/sync/offline-archive.d.ts +4 -4
  29. package/lib/core/sync/offline-archive.js +2 -2
  30. package/lib/core/sync/offline-routes.js +1 -1
  31. package/lib/core/sync/peer-manager.d.ts +2 -2
  32. package/lib/core/sync/routes.d.ts +9 -4
  33. package/lib/core/sync/routes.js +31 -4
  34. package/lib/core/sync/routes.js.map +1 -1
  35. package/lib/core/sync/session-journal.d.ts +1 -1
  36. package/lib/core/sync/session-open-routes.d.ts +32 -0
  37. package/lib/core/sync/session-open-routes.js +239 -0
  38. package/lib/core/sync/session-open-routes.js.map +1 -0
  39. package/lib/core/sync/session-routes.d.ts +1 -1
  40. package/lib/core/sync/session-routes.js +1 -1
  41. package/lib/core/sync/session-sync.d.ts +1 -1
  42. package/lib/core/sync/session-sync.js +1 -1
  43. package/lib/core/sync/ssh-transport.d.ts +1 -1
  44. package/lib/core/sync/ssh-transport.js +44 -1
  45. package/lib/core/sync/ssh-transport.js.map +1 -1
  46. package/lib/core/sync/stores.d.ts +1 -1
  47. package/lib/core/workspace-instruction-context.d.ts +1 -1
  48. package/lib/core/workspace-instructions.js +9 -1
  49. package/lib/core/workspace-instructions.js.map +1 -1
  50. package/lib/core/workspaces.d.ts +1 -1
  51. package/lib/{host-key-hIj6EY1x.d.ts → host-key-kbG50cnS.d.ts} +2 -2
  52. package/lib/{index-VF8bcBeX.d.ts → index-D6KDknUV.d.ts} +3 -309
  53. package/lib/{model-ByASrkzO.d.ts → model-zRfOihS3.d.ts} +4 -1
  54. package/lib/{node-sync-Cv1Amudy.d.ts → node-sync-Ba4yARei.d.ts} +3 -3
  55. package/lib/relay-auth-CtwES4Xn.js +240 -0
  56. package/lib/relay-auth-CtwES4Xn.js.map +1 -0
  57. package/lib/{session-journal-BnpGWLo2.d.ts → session-journal-BKjaO_1l.d.ts} +2 -2
  58. package/lib/{session-sync-Bn5ZXU8H.d.ts → session-sync-B5MCI0TW.d.ts} +31 -8
  59. package/lib/{session-sync-Dwz4dp4U.js → session-sync-Bsv3Qnof.js} +156 -96
  60. package/lib/session-sync-Bsv3Qnof.js.map +1 -0
  61. package/lib/{ssh-transport-CcGpOVy5.d.ts → ssh-transport-Uii7j8la.d.ts} +14 -5
  62. package/lib/{stores-BfruQqD-.d.ts → stores-DnyrIi4h.d.ts} +2 -2
  63. package/package.json +6 -2
  64. package/lib/catalog-BPkswHoz.js.map +0 -1
  65. package/lib/session-sync-Dwz4dp4U.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"workspace-instructions.js","names":[],"sources":["../../src/core/workspace-instructions.ts"],"sourcesContent":["import { createHash } from 'node:crypto'\nimport { chmodSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'\nimport { homedir } from 'node:os'\nimport { join } from 'node:path'\n\nexport const INSTRUCTION_MAX_BYTES = 32768\n\nexport interface WorkspaceInstructionRecord {\n workspaceId: string\n text: string\n revision: number\n digest: string\n createdAt: string\n updatedAt: string\n}\n\nexport interface SessionInstructionSnapshot {\n sessionId: string\n workspaceId?: string\n workspaceRevision?: number\n digest?: string\n text: string\n capturedAt: string\n inheritedFromSessionId?: string\n}\n\nexport class InstructionConflictError extends Error {\n readonly expected: number\n readonly actual: number\n constructor(expected: number, actual: number) {\n super(`revision conflict: expected ${expected}, current ${actual}`)\n this.name = 'InstructionConflictError'\n this.expected = expected\n this.actual = actual\n }\n}\n\nexport class InstructionSizeError extends Error {\n readonly bytes: number\n constructor(bytes: number) {\n super(`instruction exceeds ${INSTRUCTION_MAX_BYTES} bytes (got ${bytes})`)\n this.name = 'InstructionSizeError'\n this.bytes = bytes\n }\n}\n\nfunction dshHome(): string {\n return process.env.DSH_HOME ?? join(homedir(), '.dsh')\n}\n\nfunction utf8Bytes(text: string): number {\n return Buffer.byteLength(text, 'utf8')\n}\n\nfunction computeDigest(text: string): string {\n return createHash('sha256').update(text, 'utf8').digest('hex')\n}\n\ninterface WorkspaceStoreData {\n records: Record<string, WorkspaceInstructionRecord>\n}\n\ninterface SnapshotStoreData {\n records: Record<string, SessionInstructionSnapshot>\n}\n\nexport class WorkspaceInstructionStore {\n private data: WorkspaceStoreData = { records: {} }\n private loaded = false\n private readonly home: string | undefined\n\n constructor(home?: string) {\n this.home = home\n }\n\n private file(): string {\n return join(this.home ?? dshHome(), 'dshb', 'workspace-instructions.json')\n }\n\n private load(): void {\n if (this.loaded) return\n this.loaded = true\n try {\n const raw = readFileSync(this.file(), 'utf8')\n this.data = JSON.parse(raw) as WorkspaceStoreData\n if (!this.data.records || typeof this.data.records !== 'object') {\n this.data = { records: {} }\n }\n } catch {\n this.data = { records: {} }\n }\n }\n\n private save(): void {\n this.load()\n const file = this.file()\n mkdirSync(join(file, '..'), { recursive: true, mode: 0o700 })\n const tmp = `${file}.${process.pid}.tmp`\n writeFileSync(tmp, JSON.stringify(this.data, null, 2), { mode: 0o600 })\n renameSync(tmp, file)\n chmodSync(file, 0o600)\n }\n\n get(workspaceId: string): WorkspaceInstructionRecord | undefined {\n this.load()\n const r = this.data.records[workspaceId]\n return r ? { ...r } : undefined\n }\n\n update(input: {\n workspaceId: string\n text: string\n expectedRevision: number\n }): WorkspaceInstructionRecord {\n this.load()\n const bytes = utf8Bytes(input.text)\n if (bytes > INSTRUCTION_MAX_BYTES) throw new InstructionSizeError(bytes)\n const existing = this.data.records[input.workspaceId]\n if (existing && existing.revision !== input.expectedRevision) {\n throw new InstructionConflictError(input.expectedRevision, existing.revision)\n }\n const now = new Date().toISOString()\n const record: WorkspaceInstructionRecord = {\n workspaceId: input.workspaceId,\n text: input.text,\n revision: (existing?.revision ?? 0) + 1,\n digest: computeDigest(input.text),\n createdAt: existing?.createdAt ?? now,\n updatedAt: now,\n }\n this.data.records[input.workspaceId] = record\n this.save()\n return { ...record }\n }\n\n clear(workspaceId: string, expectedRevision: number): void {\n this.load()\n const existing = this.data.records[workspaceId]\n if (existing && existing.revision !== expectedRevision) {\n throw new InstructionConflictError(expectedRevision, existing.revision)\n }\n if (!existing) return\n delete this.data.records[workspaceId]\n this.save()\n }\n\n /**\n * 同步导入采纳:以对端快照的修订恢复工作区指令。\n * 本地缺失或本地修订更低(对端编辑过)时采纳;本地同版或更新时保留本地。\n * revision 直接采用对端计数,使两端的指令修订序列保持同一根。\n */\n restoreWorkspace(input: { workspaceId: string; text: string; revision: number; capturedAt?: string }): WorkspaceInstructionRecord | undefined {\n this.load()\n if (utf8Bytes(input.text) > INSTRUCTION_MAX_BYTES) throw new InstructionSizeError(utf8Bytes(input.text))\n const existing = this.data.records[input.workspaceId]\n if (existing && existing.revision >= input.revision) return { ...existing }\n const now = new Date().toISOString()\n const record: WorkspaceInstructionRecord = {\n workspaceId: input.workspaceId,\n text: input.text,\n revision: input.revision,\n digest: computeDigest(input.text),\n createdAt: existing?.createdAt ?? (input.capturedAt ?? now),\n updatedAt: now,\n }\n this.data.records[input.workspaceId] = record\n this.save()\n return { ...record }\n }\n\n removeByWorkspace(workspaceId: string): void {\n this.load()\n if (!this.data.records[workspaceId]) return\n delete this.data.records[workspaceId]\n this.save()\n }\n}\n\nexport class SessionInstructionSnapshotStore {\n private data: SnapshotStoreData = { records: {} }\n private loaded = false\n\n private file(): string {\n return join(dshHome(), 'dshb', 'session-instruction-snapshots.json')\n }\n\n private load(): void {\n if (this.loaded) return\n this.loaded = true\n try {\n const raw = readFileSync(this.file(), 'utf8')\n this.data = JSON.parse(raw) as SnapshotStoreData\n if (!this.data.records || typeof this.data.records !== 'object') {\n this.data = { records: {} }\n }\n } catch {\n this.data = { records: {} }\n }\n }\n\n private save(): void {\n this.load()\n const file = this.file()\n mkdirSync(join(file, '..'), { recursive: true, mode: 0o700 })\n const tmp = `${file}.${process.pid}.tmp`\n writeFileSync(tmp, JSON.stringify(this.data, null, 2), { mode: 0o600 })\n renameSync(tmp, file)\n chmodSync(file, 0o600)\n }\n\n get(sessionId: string): SessionInstructionSnapshot | undefined {\n this.load()\n const r = this.data.records[sessionId]\n return r ? { ...r } : undefined\n }\n\n createIfAbsent(\n sessionId: string,\n source:\n | { kind: 'workspace'; record: WorkspaceInstructionRecord; workspaceId: string }\n | { kind: 'empty'; workspaceId?: string }\n | { kind: 'inherit'; parentSnapshot: SessionInstructionSnapshot },\n ): SessionInstructionSnapshot {\n this.load()\n const existing = this.data.records[sessionId]\n if (existing) return { ...existing }\n let snapshot: SessionInstructionSnapshot\n const now = new Date().toISOString()\n if (source.kind === 'workspace') {\n snapshot = {\n sessionId,\n workspaceId: source.workspaceId,\n workspaceRevision: source.record.revision,\n digest: source.record.digest,\n text: source.record.text,\n capturedAt: now,\n }\n } else if (source.kind === 'inherit') {\n const parent = source.parentSnapshot\n snapshot = {\n sessionId,\n workspaceId: parent.workspaceId,\n workspaceRevision: parent.workspaceRevision,\n digest: parent.digest,\n text: parent.text,\n capturedAt: now,\n inheritedFromSessionId: parent.sessionId,\n }\n } else {\n snapshot = {\n sessionId,\n workspaceId: source.workspaceId,\n text: '',\n capturedAt: now,\n }\n }\n this.data.records[sessionId] = snapshot\n this.save()\n return { ...snapshot }\n }\n\n restore(snapshot: SessionInstructionSnapshot): SessionInstructionSnapshot {\n this.load()\n if (utf8Bytes(snapshot.text) > INSTRUCTION_MAX_BYTES) throw new InstructionSizeError(utf8Bytes(snapshot.text))\n if (snapshot.digest !== undefined && snapshot.digest !== computeDigest(snapshot.text)) {\n throw new Error('session instruction snapshot digest mismatch')\n }\n const existing = this.data.records[snapshot.sessionId]\n if (existing) {\n if (JSON.stringify(existing) !== JSON.stringify(snapshot)) throw new Error('session instruction snapshot already differs')\n return { ...existing }\n }\n this.data.records[snapshot.sessionId] = { ...snapshot }\n this.save()\n return { ...snapshot }\n }\n\n /**\n * 同步导入采纳:以对端快照的修订恢复工作区指令。\n * 本地缺失或本地修订更低(对端编辑过)时采纳;本地同版或更新时保留本地。\n * revision 直接采用对端计数,使两端的指令修订序列保持同一根。\n */\n remove(sessionId: string): void {\n this.load()\n if (!this.data.records[sessionId]) return\n delete this.data.records[sessionId]\n this.save()\n }\n}\n\nlet sharedWorkspaceStore: WorkspaceInstructionStore | null = null\nlet sharedSnapshotStore: SessionInstructionSnapshotStore | null = null\n\nexport function sharedWorkspaceInstructionStore(): WorkspaceInstructionStore {\n if (!sharedWorkspaceStore) sharedWorkspaceStore = new WorkspaceInstructionStore()\n return sharedWorkspaceStore\n}\n\nexport function sharedSessionInstructionSnapshotStore(): SessionInstructionSnapshotStore {\n if (!sharedSnapshotStore) sharedSnapshotStore = new SessionInstructionSnapshotStore()\n return sharedSnapshotStore\n}\n"],"mappings":";;;;;AAKA,MAAa,wBAAwB;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IAAI,KAAK,UAAU,QAAQ,MAAM,KAAK,UAAU,QAAQ,GAAG,MAAM,IAAI,MAAM,8CAA8C;GACzH,OAAO,EAAE,GAAG,SAAS;EACvB;EACA,KAAK,KAAK,QAAQ,SAAS,aAAa,EAAE,GAAG,SAAS;EACtD,KAAK,KAAK;EACV,OAAO,EAAE,GAAG,SAAS;CACvB;;;;;;CAOA,OAAO,WAAyB;EAC9B,KAAK,KAAK;EACV,IAAI,CAAC,KAAK,KAAK,QAAQ,YAAY;EACnC,OAAO,KAAK,KAAK,QAAQ;EACzB,KAAK,KAAK;CACZ;AACF;AAEA,IAAI,uBAAyD;AAC7D,IAAI,sBAA8D;AAElE,SAAgB,kCAA6D;CAC3E,IAAI,CAAC,sBAAsB,uBAAuB,IAAI,0BAA0B;CAChF,OAAO;AACT;AAEA,SAAgB,wCAAyE;CACvF,IAAI,CAAC,qBAAqB,sBAAsB,IAAI,gCAAgC;CACpF,OAAO;AACT"}
1
+ {"version":3,"file":"workspace-instructions.js","names":[],"sources":["../../src/core/workspace-instructions.ts"],"sourcesContent":["import { createHash } from 'node:crypto'\nimport { chmodSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'\nimport { homedir } from 'node:os'\nimport { join } from 'node:path'\n\nexport const INSTRUCTION_MAX_BYTES = 32768\n\nexport interface WorkspaceInstructionRecord {\n workspaceId: string\n text: string\n revision: number\n digest: string\n createdAt: string\n updatedAt: string\n}\n\nexport interface SessionInstructionSnapshot {\n sessionId: string\n workspaceId?: string\n workspaceRevision?: number\n digest?: string\n text: string\n capturedAt: string\n inheritedFromSessionId?: string\n}\n\nexport class InstructionConflictError extends Error {\n readonly expected: number\n readonly actual: number\n constructor(expected: number, actual: number) {\n super(`revision conflict: expected ${expected}, current ${actual}`)\n this.name = 'InstructionConflictError'\n this.expected = expected\n this.actual = actual\n }\n}\n\nexport class InstructionSizeError extends Error {\n readonly bytes: number\n constructor(bytes: number) {\n super(`instruction exceeds ${INSTRUCTION_MAX_BYTES} bytes (got ${bytes})`)\n this.name = 'InstructionSizeError'\n this.bytes = bytes\n }\n}\n\nfunction dshHome(): string {\n return process.env.DSH_HOME ?? join(homedir(), '.dsh')\n}\n\nfunction utf8Bytes(text: string): number {\n return Buffer.byteLength(text, 'utf8')\n}\n\nfunction computeDigest(text: string): string {\n return createHash('sha256').update(text, 'utf8').digest('hex')\n}\n\ninterface WorkspaceStoreData {\n records: Record<string, WorkspaceInstructionRecord>\n}\n\ninterface SnapshotStoreData {\n records: Record<string, SessionInstructionSnapshot>\n}\n\nexport class WorkspaceInstructionStore {\n private data: WorkspaceStoreData = { records: {} }\n private loaded = false\n private readonly home: string | undefined\n\n constructor(home?: string) {\n this.home = home\n }\n\n private file(): string {\n return join(this.home ?? dshHome(), 'dshb', 'workspace-instructions.json')\n }\n\n private load(): void {\n if (this.loaded) return\n this.loaded = true\n try {\n const raw = readFileSync(this.file(), 'utf8')\n this.data = JSON.parse(raw) as WorkspaceStoreData\n if (!this.data.records || typeof this.data.records !== 'object') {\n this.data = { records: {} }\n }\n } catch {\n this.data = { records: {} }\n }\n }\n\n private save(): void {\n this.load()\n const file = this.file()\n mkdirSync(join(file, '..'), { recursive: true, mode: 0o700 })\n const tmp = `${file}.${process.pid}.tmp`\n writeFileSync(tmp, JSON.stringify(this.data, null, 2), { mode: 0o600 })\n renameSync(tmp, file)\n chmodSync(file, 0o600)\n }\n\n get(workspaceId: string): WorkspaceInstructionRecord | undefined {\n this.load()\n const r = this.data.records[workspaceId]\n return r ? { ...r } : undefined\n }\n\n update(input: {\n workspaceId: string\n text: string\n expectedRevision: number\n }): WorkspaceInstructionRecord {\n this.load()\n const bytes = utf8Bytes(input.text)\n if (bytes > INSTRUCTION_MAX_BYTES) throw new InstructionSizeError(bytes)\n const existing = this.data.records[input.workspaceId]\n if (existing && existing.revision !== input.expectedRevision) {\n throw new InstructionConflictError(input.expectedRevision, existing.revision)\n }\n const now = new Date().toISOString()\n const record: WorkspaceInstructionRecord = {\n workspaceId: input.workspaceId,\n text: input.text,\n revision: (existing?.revision ?? 0) + 1,\n digest: computeDigest(input.text),\n createdAt: existing?.createdAt ?? now,\n updatedAt: now,\n }\n this.data.records[input.workspaceId] = record\n this.save()\n return { ...record }\n }\n\n clear(workspaceId: string, expectedRevision: number): void {\n this.load()\n const existing = this.data.records[workspaceId]\n if (existing && existing.revision !== expectedRevision) {\n throw new InstructionConflictError(expectedRevision, existing.revision)\n }\n if (!existing) return\n delete this.data.records[workspaceId]\n this.save()\n }\n\n /**\n * 同步导入采纳:以对端快照的修订恢复工作区指令。\n * 本地缺失或本地修订更低(对端编辑过)时采纳;本地同版或更新时保留本地。\n * revision 直接采用对端计数,使两端的指令修订序列保持同一根。\n */\n restoreWorkspace(input: { workspaceId: string; text: string; revision: number; capturedAt?: string }): WorkspaceInstructionRecord | undefined {\n this.load()\n if (utf8Bytes(input.text) > INSTRUCTION_MAX_BYTES) throw new InstructionSizeError(utf8Bytes(input.text))\n const existing = this.data.records[input.workspaceId]\n if (existing && existing.revision >= input.revision) return { ...existing }\n const now = new Date().toISOString()\n const record: WorkspaceInstructionRecord = {\n workspaceId: input.workspaceId,\n text: input.text,\n revision: input.revision,\n digest: computeDigest(input.text),\n createdAt: existing?.createdAt ?? (input.capturedAt ?? now),\n updatedAt: now,\n }\n this.data.records[input.workspaceId] = record\n this.save()\n return { ...record }\n }\n\n removeByWorkspace(workspaceId: string): void {\n this.load()\n if (!this.data.records[workspaceId]) return\n delete this.data.records[workspaceId]\n this.save()\n }\n}\n\nexport class SessionInstructionSnapshotStore {\n private data: SnapshotStoreData = { records: {} }\n private loaded = false\n\n private file(): string {\n return join(dshHome(), 'dshb', 'session-instruction-snapshots.json')\n }\n\n private load(): void {\n if (this.loaded) return\n this.loaded = true\n try {\n const raw = readFileSync(this.file(), 'utf8')\n this.data = JSON.parse(raw) as SnapshotStoreData\n if (!this.data.records || typeof this.data.records !== 'object') {\n this.data = { records: {} }\n }\n } catch {\n this.data = { records: {} }\n }\n }\n\n private save(): void {\n this.load()\n const file = this.file()\n mkdirSync(join(file, '..'), { recursive: true, mode: 0o700 })\n const tmp = `${file}.${process.pid}.tmp`\n writeFileSync(tmp, JSON.stringify(this.data, null, 2), { mode: 0o600 })\n renameSync(tmp, file)\n chmodSync(file, 0o600)\n }\n\n get(sessionId: string): SessionInstructionSnapshot | undefined {\n this.load()\n const r = this.data.records[sessionId]\n return r ? { ...r } : undefined\n }\n\n createIfAbsent(\n sessionId: string,\n source:\n | { kind: 'workspace'; record: WorkspaceInstructionRecord; workspaceId: string }\n | { kind: 'empty'; workspaceId?: string }\n | { kind: 'inherit'; parentSnapshot: SessionInstructionSnapshot },\n ): SessionInstructionSnapshot {\n this.load()\n const existing = this.data.records[sessionId]\n if (existing) return { ...existing }\n let snapshot: SessionInstructionSnapshot\n const now = new Date().toISOString()\n if (source.kind === 'workspace') {\n snapshot = {\n sessionId,\n workspaceId: source.workspaceId,\n workspaceRevision: source.record.revision,\n digest: source.record.digest,\n text: source.record.text,\n capturedAt: now,\n }\n } else if (source.kind === 'inherit') {\n const parent = source.parentSnapshot\n snapshot = {\n sessionId,\n workspaceId: parent.workspaceId,\n workspaceRevision: parent.workspaceRevision,\n digest: parent.digest,\n text: parent.text,\n capturedAt: now,\n inheritedFromSessionId: parent.sessionId,\n }\n } else {\n snapshot = {\n sessionId,\n workspaceId: source.workspaceId,\n text: '',\n capturedAt: now,\n }\n }\n this.data.records[sessionId] = snapshot\n this.save()\n return { ...snapshot }\n }\n\n restore(snapshot: SessionInstructionSnapshot): SessionInstructionSnapshot {\n this.load()\n if (utf8Bytes(snapshot.text) > INSTRUCTION_MAX_BYTES) throw new InstructionSizeError(utf8Bytes(snapshot.text))\n if (snapshot.digest !== undefined && snapshot.digest !== computeDigest(snapshot.text)) {\n throw new Error('session instruction snapshot digest mismatch')\n }\n const existing = this.data.records[snapshot.sessionId]\n if (existing) {\n // 工作区注册表可能在两次导入间被重建(ID 变化、路径不变);按指令内容与捕获时间\n // 判等,workspaceId 以本次快照为准更新,避免把注册表重建误判为指令冲突。\n if (existing.text !== snapshot.text || existing.capturedAt !== snapshot.capturedAt ||\n (existing.digest ?? undefined) !== (snapshot.digest ?? undefined) ||\n (existing.workspaceRevision ?? undefined) !== (snapshot.workspaceRevision ?? undefined)) {\n throw new Error('session instruction snapshot already differs')\n }\n if (existing.workspaceId !== snapshot.workspaceId) {\n this.data.records[snapshot.sessionId] = { ...existing, workspaceId: snapshot.workspaceId }\n this.save()\n return { ...this.data.records[snapshot.sessionId]! }\n }\n return { ...existing }\n }\n this.data.records[snapshot.sessionId] = { ...snapshot }\n this.save()\n return { ...snapshot }\n }\n\n /**\n * 同步导入采纳:以对端快照的修订恢复工作区指令。\n * 本地缺失或本地修订更低(对端编辑过)时采纳;本地同版或更新时保留本地。\n * revision 直接采用对端计数,使两端的指令修订序列保持同一根。\n */\n remove(sessionId: string): void {\n this.load()\n if (!this.data.records[sessionId]) return\n delete this.data.records[sessionId]\n this.save()\n }\n}\n\nlet sharedWorkspaceStore: WorkspaceInstructionStore | null = null\nlet sharedSnapshotStore: SessionInstructionSnapshotStore | null = null\n\nexport function sharedWorkspaceInstructionStore(): WorkspaceInstructionStore {\n if (!sharedWorkspaceStore) sharedWorkspaceStore = new WorkspaceInstructionStore()\n return sharedWorkspaceStore\n}\n\nexport function sharedSessionInstructionSnapshotStore(): SessionInstructionSnapshotStore {\n if (!sharedSnapshotStore) sharedSnapshotStore = new SessionInstructionSnapshotStore()\n return sharedSnapshotStore\n}\n"],"mappings":";;;;;AAKA,MAAa,wBAAwB;AAqBrC,IAAa,2BAAb,cAA8C,MAAM;CAClD;CACA;CACA,YAAY,UAAkB,QAAgB;EAC5C,MAAM,+BAA+B,SAAS,YAAY,QAAQ;EAClE,KAAK,OAAO;EACZ,KAAK,WAAW;EAChB,KAAK,SAAS;CAChB;AACF;AAEA,IAAa,uBAAb,cAA0C,MAAM;CAC9C;CACA,YAAY,OAAe;EACzB,MAAM,uBAAuB,sBAAsB,cAAc,MAAM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AG;KAAU,aAAa,SAAS;IAAY;IACzF,KAAK,KAAK;IACV,OAAO,EAAE,GAAG,KAAK,KAAK,QAAQ,SAAS,WAAY;GACrD;GACA,OAAO,EAAE,GAAG,SAAS;EACvB;EACA,KAAK,KAAK,QAAQ,SAAS,aAAa,EAAE,GAAG,SAAS;EACtD,KAAK,KAAK;EACV,OAAO,EAAE,GAAG,SAAS;CACvB;;;;;;CAOA,OAAO,WAAyB;EAC9B,KAAK,KAAK;EACV,IAAI,CAAC,KAAK,KAAK,QAAQ,YAAY;EACnC,OAAO,KAAK,KAAK,QAAQ;EACzB,KAAK,KAAK;CACZ;AACF;AAEA,IAAI,uBAAyD;AAC7D,IAAI,sBAA8D;AAElE,SAAgB,kCAA6D;CAC3E,IAAI,CAAC,sBAAsB,uBAAuB,IAAI,0BAA0B;CAChF,OAAO;AACT;AAEA,SAAgB,wCAAyE;CACvF,IAAI,CAAC,qBAAqB,sBAAsB,IAAI,gCAAgC;CACpF,OAAO;AACT"}
@@ -1,6 +1,6 @@
1
1
  import { o as NodeRegistry } from "../node-registry-BTnnM5-k.js";
2
2
  import { r as WorkspaceBindingsStore } from "../workspace-bindings-CsB0TIJB.js";
3
- import { s as SyncNodeService } from "../node-sync-Cv1Amudy.js";
3
+ import { s as SyncNodeService } from "../node-sync-Ba4yARei.js";
4
4
  import { Context } from "@deepseek-ai/cordis";
5
5
  //#region src/core/workspaces.d.ts
6
6
  declare function registerWorkspaceRoutes(ctx: Context, registry: NodeRegistry, bindings: WorkspaceBindingsStore, syncNodes?: SyncNodeService): void;
@@ -1,4 +1,4 @@
1
- import { u as SyncPeer } from "./model-ByASrkzO.js";
1
+ import { u as SyncPeer } from "./model-zRfOihS3.js";
2
2
  //#region src/core/sync/host-key.d.ts
3
3
  type SyncHostKeyDecision = 'trusted' | 'untrusted' | 'changed';
4
4
  declare class SyncHostKeyChallengeError extends Error {
@@ -27,4 +27,4 @@ declare class SyncHostKeyChallenges {
27
27
  }
28
28
  //#endregion
29
29
  export { inspectSyncHostKey as a, SyncHostKeyDecision as i, SyncHostKeyChallengeExpiredError as n, isOpenSshFingerprint as o, SyncHostKeyChallenges as r, opensshFingerprintFromSha256Hex as s, SyncHostKeyChallengeError as t };
30
- //# sourceMappingURL=host-key-hIj6EY1x.d.ts.map
30
+ //# sourceMappingURL=host-key-kbG50cnS.d.ts.map
@@ -1,4 +1,5 @@
1
1
  import { Context, Service } from "@deepseek-ai/cordis";
2
+ import { FileAttachmentRef, ImageAttachmentRef, ImageRequestTarget } from "@deepseek-ai/dsh-attachment";
2
3
  //#region ../../node_modules/@deepseek-ai/dsh-brand/lib/types/index.d.ts
3
4
  /**
4
5
  * Duplicate-install-safe nominal primitive helpers.
@@ -561,313 +562,6 @@ declare abstract class TypertRemoteService<out T = never> extends Service<T> {
561
562
  protected constructor(ctx: Context, serviceKey: string, options?: TypertGatewayBindingOptions);
562
563
  }
563
564
  //#endregion
564
- //#region ../../node_modules/@deepseek-ai/dsh-attachment/lib/types/error.d.ts
565
- declare const ATTACHMENT_ERROR_CODES: readonly ["TOO_MANY_IMAGES", "IMAGES_TOO_LARGE", "UNSUPPORTED_IMAGE_TYPE", "INVALID_IMAGE_BASE64", "INVALID_IMAGE", "IMAGE_TYPE_MISMATCH", "IMAGE_TOO_LARGE", "IMAGE_TOO_MANY_PIXELS", "IMAGE_DIMENSION_TOO_LARGE", "INVALID_FILE_BASE64", "INVALID_ATTACHMENT_REF", "ATTACHMENT_CORRUPT", "ATTACHMENT_WRITE_FAILED", "ATTACHMENT_NOT_FOUND", "ATTACHMENT_READ_FAILED", "ATTACHMENT_PROJECTION_UNSUPPORTED", "ATTACHMENT_FILES_UNSUPPORTED"];
566
- /** Stable attachment failure codes used for protocol error routing. */
567
- type AttachmentErrorCode = typeof ATTACHMENT_ERROR_CODES[number];
568
- /**
569
- * Stable failures suitable for host RPC error mapping.
570
- *
571
- * Deliberately re-implements the `HarnessError` shape instead of extending it:
572
- * the base lives in `@deepseek-ai/dsh-llm`, which itself depends on this
573
- * package (`ImageBlock` references `ImageAttachmentRef`), so sharing the base
574
- * would create a dependency cycle. Consumers route on `code`, never on the
575
- * prototype chain, so the shapes stay interchangeable at the wire boundary.
576
- */
577
- declare class AttachmentError extends Error {
578
- /** Stable machine-routing failure code. */
579
- readonly code: AttachmentErrorCode;
580
- /**
581
- * @param message - human-readable failure description without raw bytes or host paths.
582
- * @param code - stable machine-routing code.
583
- * @param options - optional chained cause.
584
- */
585
- constructor(message: string, code: AttachmentErrorCode, options?: ErrorOptions);
586
- }
587
- //#endregion
588
- //#region ../../node_modules/@deepseek-ai/dsh-attachment/lib/types/brand.d.ts
589
- /** Opaque content-addressed identifier for one immutable attachment object. */
590
- type AttachmentId = Branded<'AttachmentId'>;
591
- /**
592
- * Brand a validated storage identifier.
593
- * @param value - backend-produced opaque identifier.
594
- * @returns the branded identifier.
595
- */
596
- declare function AttachmentId(value: string): AttachmentId;
597
- /** Opaque deterministic identity for one request-image transformation. */
598
- type ImageVariantId = Branded<'ImageVariantId'>;
599
- /**
600
- * Brand a validated request-image transformation identifier.
601
- * @param value - attachment-provider-produced opaque identifier.
602
- * @returns the branded identifier.
603
- */
604
- declare function ImageVariantId(value: string): ImageVariantId;
605
- //#endregion
606
- //#region ../../node_modules/@deepseek-ai/dsh-attachment/lib/types/types.d.ts
607
- /** Raster image formats accepted by the version-one attachment path. */
608
- type ImageMediaType = 'image/png' | 'image/jpeg' | 'image/webp' | 'image/gif';
609
- /** Durable, serializable reference to one immutable normalized image. */
610
- interface ImageAttachmentRef {
611
- /** Opaque storage identifier; never a filesystem path or bearer URL. */
612
- attachmentId: AttachmentId;
613
- /** Media type verified from the stored bytes. */
614
- mediaType: ImageMediaType;
615
- /** Exact encoded byte length. */
616
- bytes: number;
617
- /** Intrinsic encoded width in pixels. */
618
- width: number;
619
- /** Intrinsic encoded height in pixels. */
620
- height: number;
621
- /** Optional display name stripped of local path information. */
622
- name?: string;
623
- /**
624
- * Input dimensions after applying EXIF orientation and before normalization
625
- * scaling. Present only when normalization reduced the image.
626
- */
627
- originalDimensions?: {
628
- width: number;
629
- height: number;
630
- };
631
- }
632
- /**
633
- * Durable, serializable reference to one verbatim stored file. Files are
634
- * stored byte-for-byte with no normalization; `attachmentId` is the sha256
635
- * digest of exactly those bytes.
636
- */
637
- interface FileAttachmentRef {
638
- /** Opaque content-addressed storage identifier; never a filesystem path or bearer URL. */
639
- attachmentId: AttachmentId;
640
- /** Sanitized display filename, also the stored object's leaf name. */
641
- name: string;
642
- /** Exact byte length. */
643
- bytes: number;
644
- }
645
- /** Base64-encoded file upload accompanying one wire request. */
646
- interface EncodedFileAttachment {
647
- /** Canonical base64 encoding of the file bytes. */
648
- data: string;
649
- /** Optional display name; it is never interpreted as a path. */
650
- name?: string;
651
- }
652
- /** Request to durably commit one file verbatim. */
653
- interface SaveFileAttachment {
654
- data: Uint8Array;
655
- /** Optional browser/provider display name; it is never interpreted as a path. */
656
- name?: string;
657
- }
658
- /** Request to durably commit one file from bounded byte chunks. */
659
- interface SaveFileStreamAttachment {
660
- /** Exact file bytes in order; providers must not retain the complete sequence in memory. */
661
- data: AsyncIterable<Uint8Array>;
662
- /** Optional cancellation for source reads and storage writes. */
663
- signal?: AbortSignal;
664
- /** Optional browser/provider display name; it is never interpreted as a path. */
665
- name?: string;
666
- }
667
- /** Deployment-resolved limits used by upload admission and request buffering. */
668
- interface ImageAttachmentLimits {
669
- maxImageBytes: number;
670
- maxImagesPerMessage: number;
671
- maxMessageImageBytes: number;
672
- maxImagePixels: number;
673
- /** Maximum intrinsic width and maximum intrinsic height in pixels for one image. */
674
- maxImageDimension: number;
675
- mediaTypes: readonly ImageMediaType[];
676
- }
677
- /**
678
- * Browser-submitted prompt content accepted by Host prompt endpoints; the
679
- * accepting Host promotes image parts to durable references through
680
- * `ctx.attachments.admitPromptContent()` before any message is created, so a wire caller can
681
- * never cite an attachment it did not upload.
682
- */
683
- type PromptContentPart = {
684
- readonly type: 'text';
685
- readonly text: string;
686
- } | {
687
- readonly type: 'image';
688
- readonly mediaType: ImageMediaType;
689
- readonly data: string;
690
- readonly name?: string;
691
- };
692
- /** Host prompt content whose file receipts are resolved and whose image bytes await admission. */
693
- type AttachmentAdmissionPart = PromptContentPart | {
694
- readonly type: 'file';
695
- readonly attachment: FileAttachmentRef;
696
- };
697
- /** Host-admitted prompt content with every attachment represented by its durable reference. */
698
- type AdmittedPromptContentPart = {
699
- readonly type: 'text';
700
- readonly text: string;
701
- } | {
702
- readonly type: 'image';
703
- readonly attachment: ImageAttachmentRef;
704
- } | {
705
- readonly type: 'file';
706
- readonly attachment: FileAttachmentRef;
707
- };
708
- /** Request to validate and durably commit one image. */
709
- interface SaveImageAttachment {
710
- data: Uint8Array;
711
- /** Caller-declared media type, checked against fully decoded bytes. */
712
- mediaType: ImageMediaType;
713
- /** Optional browser/provider display name; it is never interpreted as a path. */
714
- name?: string;
715
- }
716
- /** Stored image bytes returned after reference and digest verification. */
717
- interface StoredImageAttachment {
718
- ref: ImageAttachmentRef;
719
- data: Uint8Array;
720
- }
721
- /** Deterministic request-image target selected by one exact model route for one attachment. */
722
- interface ImageRequestTarget {
723
- /** Target width in pixels; a target above the source keeps the source width. */
724
- width: number;
725
- /** Target height in pixels; a target above the source keeps the source height. */
726
- height: number;
727
- /** Encoded-byte target before base64 expansion or Files API upload; the smallest quality-ladder output is kept when no quality fits. */
728
- maxBytes: number;
729
- }
730
- /** Cached request version derived from one provider-independent normalized attachment. */
731
- interface RequestImageAttachment {
732
- /** Cache and upload-index key over the attachment id, policy, and fixed encoder parameters. */
733
- variantId: ImageVariantId;
734
- /** Durable normalized attachment from which this request version was derived. */
735
- attachment: ImageAttachmentRef;
736
- /** Encoded request bytes. */
737
- data: Uint8Array;
738
- mediaType: ImageMediaType;
739
- bytes: number;
740
- width: number;
741
- height: number;
742
- /** Provider-compatible sample depth proven after request encoding. */
743
- depth: 'uchar';
744
- /** Provider-compatible color space proven after request encoding. */
745
- space: 'srgb';
746
- /** Whether the encoded request version retains an alpha channel. */
747
- hasAlpha: boolean;
748
- }
749
- //#endregion
750
- //#region ../../node_modules/@deepseek-ai/dsh-attachment/lib/types/index.d.ts
751
- declare module '@deepseek-ai/cordis' {
752
- interface Context {
753
- attachments: AttachmentStore;
754
- }
755
- }
756
- /** Immutable binary attachment service. Implementations validate bytes before publishing a reference. */
757
- declare abstract class AttachmentStore extends Service {
758
- constructor(ctx: Context);
759
- /** Deployment-resolved image policy used by authoritative and fast-path validation. */
760
- abstract readonly imageLimits: ImageAttachmentLimits;
761
- /**
762
- * Validate one image without persisting it.
763
- * Batch callers validate every member before saving any member.
764
- * @param input - encoded bytes, declared media type, and optional display name.
765
- * @returns completion after the encoded raster has been fully decoded.
766
- */
767
- abstract validateImage(input: SaveImageAttachment): Promise<void>;
768
- /**
769
- * Validate one ordered image batch before committing any member.
770
- * Validation failures start no writes; storage failures return no partial
771
- * references, although already published content-addressed objects may stay
772
- * unreachable until a future retention policy collects them.
773
- * @param inputs - encoded images in their owning message order.
774
- * @returns durable references in the exact input order.
775
- */
776
- protected validateImageBatch(inputs: readonly SaveImageAttachment[]): void;
777
- /**
778
- * Validate and durably commit one ordered image batch.
779
- * @param inputs - encoded images in owning-message order.
780
- * @returns durable normalized attachment references in the same order after every member succeeds.
781
- */
782
- saveImages(inputs: readonly SaveImageAttachment[]): Promise<readonly ImageAttachmentRef[]>;
783
- /**
784
- * Admit one Host prompt and replace each uploaded image with its durable reference.
785
- * Text and durable file references pass through unchanged. A prompt without image parts performs no storage operation.
786
- * @param content - prompt parts in message order after file receipt resolution.
787
- * @returns admitted prompt parts in the same order as `content`.
788
- * @throws AttachmentError when the image batch is refused.
789
- */
790
- admitPromptContent(content: readonly AttachmentAdmissionPart[]): Promise<AdmittedPromptContentPart[]>;
791
- /**
792
- * Decode and durably commit one canonical base64 file upload.
793
- * @param input - canonical base64 bytes and optional display name.
794
- * @returns the durable content-addressed file reference.
795
- * @throws AttachmentError when the encoding or storage operation is refused.
796
- */
797
- admitEncodedFile(input: EncodedFileAttachment): Promise<FileAttachmentRef>;
798
- /**
799
- * Identify a failure emitted by this attachment capability by its stable code.
800
- * @param error - value caught from an attachment operation.
801
- * @returns whether the value is an attachment failure.
802
- */
803
- isAttachmentError(error: unknown): error is AttachmentError;
804
- /**
805
- * Validate and durably commit one image before its owning session event is appended.
806
- * The returned reference describes the persisted normalized image. When
807
- * normalization reduces the raster, its `originalDimensions` records the
808
- * orientation-applied input dimensions.
809
- * @param input - encoded bytes, declared media type, and optional display name.
810
- * @returns the durable content-addressed normalized image reference.
811
- */
812
- abstract saveImage(input: SaveImageAttachment): Promise<ImageAttachmentRef>;
813
- /**
814
- * Read one image and verify that bytes still match the recorded reference.
815
- * @param ref - durable reference from the session log.
816
- * @param signal - optional cancellation for backend read and verification work.
817
- * @returns the verified bytes and normalized attachment reference.
818
- * @throws the signal reason when aborted, or a storage error when verification fails.
819
- */
820
- abstract readImage(ref: ImageAttachmentRef, signal?: AbortSignal): Promise<StoredImageAttachment>;
821
- /**
822
- * Locate the provider-owned normalized object in the harness host filesystem.
823
- * @param ref - durable normalized attachment reference.
824
- * @returns an absolute host path, or undefined when this backend is not host-file-backed.
825
- * @throws an AttachmentError when the durable reference is invalid.
826
- */
827
- imageHostPath(ref: ImageAttachmentRef): string | undefined;
828
- /**
829
- * Durably commit one file byte-for-byte before its owning session event is
830
- * appended. Files carry no admission limits: any byte content and length is
831
- * accepted, and the stored object is the exact submitted bytes. Backends
832
- * without verbatim file storage keep this default rejection.
833
- * @param input - exact bytes and optional display name.
834
- * @returns the durable content-addressed file reference.
835
- */
836
- saveFile(input: SaveFileAttachment): Promise<FileAttachmentRef>;
837
- /**
838
- * Durably commit one file byte-for-byte from bounded chunks. Providers must
839
- * apply backpressure and must not collect the complete file in memory.
840
- * Backends without streamed verbatim storage keep this default rejection.
841
- * @param input - ordered exact bytes, optional cancellation, and display name.
842
- * @returns the durable content-addressed file reference.
843
- */
844
- saveFileStream(input: SaveFileStreamAttachment): Promise<FileAttachmentRef>;
845
- /**
846
- * Read and verify one verbatim stored file as bounded chunks. Providers must
847
- * not collect the complete file in memory. Backends without verbatim file
848
- * reads keep this default rejection.
849
- * @param ref - durable reference from the session log.
850
- * @param signal - optional cancellation for backend reads and verification work.
851
- * @returns exact file bytes in order; integrity failures reject the iteration.
852
- */
853
- readFileStream(ref: FileAttachmentRef, signal?: AbortSignal): AsyncIterable<Uint8Array>;
854
- /**
855
- * Locate the verbatim stored file object in the harness host filesystem.
856
- * @param ref - durable file reference.
857
- * @returns an absolute host path, or undefined when this backend is not host-file-backed.
858
- * @throws an AttachmentError when the durable reference is invalid.
859
- */
860
- fileHostPath(ref: FileAttachmentRef): string | undefined;
861
- /**
862
- * Generate or read one deterministic model-request version from the stored normalized image.
863
- * @param ref - durable provider-independent normalized attachment reference.
864
- * @param target - route-chosen dimensions and byte target; an unmet byte target yields the smallest ladder output.
865
- * @param signal - optional cancellation.
866
- * @returns request bytes and the cache/upload identity covering every transform input.
867
- */
868
- readImageRequest(ref: ImageAttachmentRef, target: ImageRequestTarget, signal?: AbortSignal): Promise<RequestImageAttachment>;
869
- }
870
- //#endregion
871
565
  //#region ../../node_modules/@deepseek-ai/dsh-llm/lib/types/brand.d.ts
872
566
  /** Stable identity carried by one message across inbox, log, and model-request boundaries. */
873
567
  type MessageId = Branded<'MessageId'>;
@@ -2289,5 +1983,5 @@ declare class LlmRuntime extends TypertRemoteService {
2289
1983
  private streamWithRegistration;
2290
1984
  }
2291
1985
  //#endregion
2292
- export { BrandedNumber as S, FileAttachmentRef as _, SystemPromptUpdate as a, TypertResource as b, ToolSchema as c, Message as d, SystemMessage as f, ToolCallId as g, createUserMessage as h, LlmFailure as i, AssistantMessage as l, UserMessage as m, LlmCallConfig as n, TokenUsage as o, ToolResultMessage as p, LlmCallConfigAdapterDefaults as r, ToolHistory as s, AssistantStreamRecord as t, DeveloperMessage as u, ImageAttachmentRef as v, Branded as x, TypertLookup as y };
2293
- //# sourceMappingURL=index-VF8bcBeX.d.ts.map
1986
+ export { TypertLookup as _, SystemPromptUpdate as a, BrandedNumber as b, ToolSchema as c, Message as d, SystemMessage as f, ToolCallId as g, createUserMessage as h, LlmFailure as i, AssistantMessage as l, UserMessage as m, LlmCallConfig as n, TokenUsage as o, ToolResultMessage as p, LlmCallConfigAdapterDefaults as r, ToolHistory as s, AssistantStreamRecord as t, DeveloperMessage as u, TypertResource as v, Branded as y };
1987
+ //# sourceMappingURL=index-D6KDknUV.d.ts.map
@@ -62,6 +62,9 @@ interface SyncCatalogSession {
62
62
  sizeBytes?: number;
63
63
  branchId?: string;
64
64
  deleted?: boolean;
65
+ archived?: boolean;
66
+ /** 空壳会话(无任何用户消息):远端 UI 不显示,目录消费方也应过滤。 */
67
+ blank?: boolean;
65
68
  }
66
69
  interface SyncCatalog {
67
70
  protocolVersion: 1;
@@ -171,4 +174,4 @@ declare function isRecord(value: unknown): value is Record<string, unknown>;
171
174
  declare function isNonNegativeSafeInteger(value: unknown): value is number;
172
175
  //#endregion
173
176
  export { parseSyncPeer as C, syncWorkspaceKey as D, syncRecordKey as E, isRecord as S, parseSyncSelection as T, SyncSessionArchive as _, SyncDirection as a, SyncWorkspaceOrigin as b, SyncMode as c, SyncPeerDraft as d, SyncPeerProgress as f, SyncSelection as g, SyncSchedule as h, SyncCatalogWorkspace as i, SyncOrigin as l, SyncRecordMetadata as m, SyncCatalogNode as n, SyncEntityKind as o, SyncProvenance as p, SyncCatalogSession as r, SyncImportMethod as s, SyncCatalog as t, SyncPeer as u, SyncState as v, parseSyncPeerDraft as w, isNonNegativeSafeInteger as x, SyncWorkspaceMapping as y };
174
- //# sourceMappingURL=model-ByASrkzO.d.ts.map
177
+ //# sourceMappingURL=model-zRfOihS3.d.ts.map
@@ -1,7 +1,7 @@
1
1
  import { c as NodeSsh, o as NodeRegistry, r as NodeDocker, s as NodeSecrets } from "./node-registry-BTnnM5-k.js";
2
2
  import { r as WorkspaceBindingsStore } from "./workspace-bindings-CsB0TIJB.js";
3
- import { m as SyncRecordMetadata, s as SyncImportMethod } from "./model-ByASrkzO.js";
4
- import { n as SyncStateStore } from "./stores-BfruQqD-.js";
3
+ import { m as SyncRecordMetadata, s as SyncImportMethod } from "./model-zRfOihS3.js";
4
+ import { n as SyncStateStore } from "./stores-DnyrIi4h.js";
5
5
  //#region src/core/sync/node-sync.d.ts
6
6
  interface SyncNodeProfile {
7
7
  name: string;
@@ -86,4 +86,4 @@ declare class SyncNodeService {
86
86
  }
87
87
  //#endregion
88
88
  export { SyncNodeManifestError as a, SyncNodeView as c, SyncNodeManifest as i, SyncNodeEntry as n, SyncNodeProfile as o, SyncNodeInUseError as r, SyncNodeService as s, SyncNodeApplyResult as t };
89
- //# sourceMappingURL=node-sync-Cv1Amudy.d.ts.map
89
+ //# sourceMappingURL=node-sync-Ba4yARei.d.ts.map