@shaxpir/duiduidui-models 1.26.0 → 1.26.2

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.
@@ -174,13 +174,24 @@ class Workspace extends Content_1.Content {
174
174
  async acquireSessionForUtcTime(utcTime) {
175
175
  this.checkDisposed("Workspace.acquireSessionForUtcTime");
176
176
  const shareSync = repo_1.ShareSyncFactory.get();
177
+ // First, try direct ref match — if the utcTime exactly matches a
178
+ // session's created_at, we can acquire by ref without range checking.
177
179
  for (let i = 0, len = this.sessions.length; i < len; i++) {
178
180
  const sessionCreatedAt = this.sessions.get(i);
179
- if (shaxpir_common_1.Time.isDateTimeBefore(sessionCreatedAt.utc_time, utcTime)) {
181
+ if (sessionCreatedAt.utc_time === utcTime) {
182
+ const sessionRef = Session_1.Session.makeSessionRef(this.owner, sessionCreatedAt);
183
+ return await shareSync.acquire(ContentKind_1.ContentKind.SESSION, sessionRef);
184
+ }
185
+ }
186
+ // Fall back to range match — find the session that contains utcTime
187
+ // (created_at <= utcTime <= updated_at).
188
+ for (let i = 0, len = this.sessions.length; i < len; i++) {
189
+ const sessionCreatedAt = this.sessions.get(i);
190
+ if (!shaxpir_common_1.Time.isDateTimeAfter(sessionCreatedAt.utc_time, utcTime)) {
180
191
  const sessionRef = Session_1.Session.makeSessionRef(this.owner, sessionCreatedAt);
181
192
  const session = await shareSync.acquire(ContentKind_1.ContentKind.SESSION, sessionRef);
182
193
  const sessionUpdatedAt = session.updatedAt;
183
- if (shaxpir_common_1.Time.isDateTimeAfter(sessionUpdatedAt.utc_time, utcTime)) {
194
+ if (!shaxpir_common_1.Time.isDateTimeBefore(sessionUpdatedAt.utc_time, utcTime)) {
184
195
  return session;
185
196
  }
186
197
  else {
@@ -0,0 +1,68 @@
1
+ import { CompactDate } from '@shaxpir/shaxpir-common';
2
+ declare enum VersionTagBrand {
3
+ }
4
+ /**
5
+ * A date-based version identifier in YYYYMMDDx format, where x is a
6
+ * lowercase letter (a-z) allowing multiple versions per day.
7
+ *
8
+ * Used for:
9
+ * - System prompt versions (e.g., "20260321e")
10
+ * - Tool definition versions (e.g., "20260321e")
11
+ * - Built-in database releases (e.g., "20260316a")
12
+ *
13
+ * Examples: "20260321a", "20260321b", "20250118a"
14
+ *
15
+ * Version tags sort lexicographically in chronological order.
16
+ */
17
+ export type VersionTag = string & VersionTagBrand;
18
+ export declare class VersionTagModel {
19
+ private static readonly PATTERN;
20
+ /**
21
+ * Validate and create a branded VersionTag from a string.
22
+ * Returns null if the format is invalid.
23
+ */
24
+ static from(value: string): VersionTag | null;
25
+ /**
26
+ * Validate and create a branded VersionTag from a string.
27
+ * Throws if the format is invalid.
28
+ */
29
+ static fromOrThrow(value: string): VersionTag;
30
+ /**
31
+ * Validate YYYYMMDDx format (where x is a lowercase letter a-z).
32
+ */
33
+ static isValid(value: string): boolean;
34
+ /**
35
+ * Compare two version tags.
36
+ * Returns: negative if a < b, 0 if equal, positive if a > b.
37
+ */
38
+ static compare(a: VersionTag, b: VersionTag): number;
39
+ /**
40
+ * Returns true if a comes before b chronologically.
41
+ */
42
+ static isBefore(a: VersionTag, b: VersionTag): boolean;
43
+ /**
44
+ * Returns true if a comes after b chronologically.
45
+ */
46
+ static isAfter(a: VersionTag, b: VersionTag): boolean;
47
+ /**
48
+ * Extract the date portion as a CompactDate (YYYYMMDD).
49
+ * Example: "20260321e" → "20260321"
50
+ */
51
+ static date(tag: VersionTag): CompactDate;
52
+ /**
53
+ * Extract the letter suffix.
54
+ * Example: "20260321e" → "e"
55
+ */
56
+ static letter(tag: VersionTag): string;
57
+ /**
58
+ * Generate the next version tag in sequence for the same day.
59
+ * Example: "20260321a" → "20260321b"
60
+ * Returns null if already at 'z'.
61
+ */
62
+ static next(tag: VersionTag): VersionTag | null;
63
+ /**
64
+ * Check if two version tags share the same date.
65
+ */
66
+ static isSameDay(a: VersionTag, b: VersionTag): boolean;
67
+ }
68
+ export {};
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VersionTagModel = void 0;
4
+ var VersionTagBrand;
5
+ (function (VersionTagBrand) {
6
+ })(VersionTagBrand || (VersionTagBrand = {}));
7
+ class VersionTagModel {
8
+ /**
9
+ * Validate and create a branded VersionTag from a string.
10
+ * Returns null if the format is invalid.
11
+ */
12
+ static from(value) {
13
+ if (!VersionTagModel.isValid(value))
14
+ return null;
15
+ return value;
16
+ }
17
+ /**
18
+ * Validate and create a branded VersionTag from a string.
19
+ * Throws if the format is invalid.
20
+ */
21
+ static fromOrThrow(value) {
22
+ if (!VersionTagModel.isValid(value)) {
23
+ throw new Error(`Invalid VersionTag format: "${value}". Expected YYYYMMDDx (e.g., "20260321a")`);
24
+ }
25
+ return value;
26
+ }
27
+ /**
28
+ * Validate YYYYMMDDx format (where x is a lowercase letter a-z).
29
+ */
30
+ static isValid(value) {
31
+ return VersionTagModel.PATTERN.test(value);
32
+ }
33
+ /**
34
+ * Compare two version tags.
35
+ * Returns: negative if a < b, 0 if equal, positive if a > b.
36
+ */
37
+ static compare(a, b) {
38
+ return a.localeCompare(b);
39
+ }
40
+ /**
41
+ * Returns true if a comes before b chronologically.
42
+ */
43
+ static isBefore(a, b) {
44
+ return VersionTagModel.compare(a, b) < 0;
45
+ }
46
+ /**
47
+ * Returns true if a comes after b chronologically.
48
+ */
49
+ static isAfter(a, b) {
50
+ return VersionTagModel.compare(a, b) > 0;
51
+ }
52
+ /**
53
+ * Extract the date portion as a CompactDate (YYYYMMDD).
54
+ * Example: "20260321e" → "20260321"
55
+ */
56
+ static date(tag) {
57
+ return tag.substring(0, 8);
58
+ }
59
+ /**
60
+ * Extract the letter suffix.
61
+ * Example: "20260321e" → "e"
62
+ */
63
+ static letter(tag) {
64
+ return tag.charAt(8);
65
+ }
66
+ /**
67
+ * Generate the next version tag in sequence for the same day.
68
+ * Example: "20260321a" → "20260321b"
69
+ * Returns null if already at 'z'.
70
+ */
71
+ static next(tag) {
72
+ const letter = VersionTagModel.letter(tag);
73
+ if (letter === 'z')
74
+ return null;
75
+ const nextLetter = String.fromCharCode(letter.charCodeAt(0) + 1);
76
+ return (tag.substring(0, 8) + nextLetter);
77
+ }
78
+ /**
79
+ * Check if two version tags share the same date.
80
+ */
81
+ static isSameDay(a, b) {
82
+ return a.substring(0, 8) === b.substring(0, 8);
83
+ }
84
+ }
85
+ exports.VersionTagModel = VersionTagModel;
86
+ VersionTagModel.PATTERN = /^\d{8}[a-z]$/;
@@ -8,3 +8,4 @@ export * from './PinyinValidator';
8
8
  export * from './SearchPreprocessor';
9
9
  export * from './SearchTokenizer';
10
10
  export * from './SenseRankEncoder';
11
+ export * from './VersionTag';
@@ -25,3 +25,4 @@ __exportStar(require("./PinyinValidator"), exports);
25
25
  __exportStar(require("./SearchPreprocessor"), exports);
26
26
  __exportStar(require("./SearchTokenizer"), exports);
27
27
  __exportStar(require("./SenseRankEncoder"), exports);
28
+ __exportStar(require("./VersionTag"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaxpir/duiduidui-models",
3
- "version": "1.26.0",
3
+ "version": "1.26.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/shaxpir/duiduidui-models"
@@ -18,7 +18,7 @@
18
18
  "dependencies": {
19
19
  "@shaxpir/duiduidui-models": "^1.10.3",
20
20
  "@shaxpir/sharedb": "^6.0.6",
21
- "@shaxpir/shaxpir-common": "^1.4.1",
21
+ "@shaxpir/shaxpir-common": "^1.4.2",
22
22
  "ot-json1": "1.0.1",
23
23
  "ot-text-unicode": "4.0.0",
24
24
  "reconnecting-websocket": "4.4.0"