@asaidimu/utils-workspace 6.5.4 → 6.5.6

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/index.d.mts CHANGED
@@ -2690,10 +2690,17 @@ declare class Session {
2690
2690
  private tree;
2691
2691
  private unsubscribe?;
2692
2692
  private constructor();
2693
+ /**
2694
+ * Factory method to create a new Session instance.
2695
+ * @param sessionId - Unique identifier for the session.
2696
+ * @param manager - Workspace manager for dispatching commands.
2697
+ * @param processor - Turn processor for handling tool calls.
2698
+ * @returns A fully initialised Session.
2699
+ */
2693
2700
  static create(sessionId: UUID, manager: WorkspaceManager, processor: TurnProcessor): Promise<Session>;
2694
2701
  /**
2695
- * Synchronizes the session's in-memory state with the persistent stores.
2696
- * Useful after a workspace-wide sync or if state becomes stale.
2702
+ * Synchronises the session's inmemory state with the persistent stores.
2703
+ * Useful after a workspacewide sync or if state becomes stale.
2697
2704
  */
2698
2705
  sync(): Promise<void>;
2699
2706
  /**
@@ -2702,57 +2709,163 @@ declare class Session {
2702
2709
  close(): void;
2703
2710
  private _setRole;
2704
2711
  private _setPreference;
2712
+ /** Returns the session’s unique identifier. */
2705
2713
  id(): UUID;
2706
2714
  private ws;
2715
+ /** Returns the session metadata from the workspace index. */
2707
2716
  meta(): SessionMetadata | undefined;
2717
+ /** Returns the session’s label (display name). */
2708
2718
  label(): string | undefined;
2719
+ /** Returns the session’s current Role object. */
2709
2720
  role(): Role | undefined;
2721
+ /** Returns the list of topic strings associated with the session. */
2710
2722
  topics(): string[];
2723
+ /** Returns the list of preferences active for this session. */
2711
2724
  preferences(): Preference[];
2725
+ /** Returns the current head (last turn) of the session, or null if empty. */
2712
2726
  head(): TurnRef | null;
2727
+ /** Returns the active chain of turns as an array of TurnNode. */
2713
2728
  turns(): TurnNode[];
2729
+ /**
2730
+ * Returns all sibling turns of a given turn (other children of the same parent).
2731
+ * @param turnId - ID of the turn.
2732
+ */
2714
2733
  siblings(turnId: UUID): Promise<TurnNode[]>;
2734
+ /**
2735
+ * Returns branching information for a turn (versions, navigation).
2736
+ * @param turnId - ID of the turn.
2737
+ */
2715
2738
  branchInfo(turnId: UUID): Promise<BranchInfo>;
2739
+ /**
2740
+ * Retrieves a TurnNode by its ID.
2741
+ * @param turnId - ID of the turn.
2742
+ */
2716
2743
  getTurn(turnId: UUID): Promise<TurnNode | undefined>;
2744
+ /**
2745
+ * Changes the session’s display label.
2746
+ * @param newLabel - New label for the session.
2747
+ */
2717
2748
  rename(newLabel: string): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2749
+ /**
2750
+ * Replaces the session’s topic list.
2751
+ * @param topics - New array of topic strings.
2752
+ */
2718
2753
  setTopics(topics: string[]): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2719
2754
  /**
2720
- * Updates the session's model identifier.
2755
+ * Updates the sessions model identifier (e.g., "gpt-4").
2756
+ * @param model - New model string.
2721
2757
  */
2722
2758
  setModel(model: string): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2723
2759
  /**
2724
- * Merges the provided metadata into the session's current metadata.
2760
+ * Merges arbitrary metadata into the sessions metadata object.
2761
+ * @param metadata - Key‑value pairs to merge.
2725
2762
  */
2726
2763
  updateMetadata(metadata: Record<string, any>): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2764
+ /**
2765
+ * Adds topics to the session (does not replace existing ones).
2766
+ * @param topics - Topics to add.
2767
+ */
2727
2768
  addTopics(topics: string[]): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2769
+ /**
2770
+ * Replaces the session’s preference list with the given IDs.
2771
+ * @param preferenceIds - Array of preference UUIDs.
2772
+ */
2728
2773
  setPreferences(preferenceIds: UUID[]): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2774
+ /**
2775
+ * Creates a new session as a fork of this one.
2776
+ * @param newSessionId - ID for the new session.
2777
+ * @param label - Label for the new session.
2778
+ * @param role - Optional role ID (defaults to current role).
2779
+ * @param topics - Optional topics (defaults to current topics).
2780
+ */
2729
2781
  fork(newSessionId: UUID, label: string, role?: string, topics?: string[]): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2782
+ /**
2783
+ * Dispatches a raw command to the workspace manager.
2784
+ * @param command - BaseCommand to dispatch.
2785
+ */
2730
2786
  dispatch(command: BaseCommand): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2787
+ /**
2788
+ * Switches the session to a different role.
2789
+ * @param newRole - ID of the new role (or EMPTY_SYSTEM_ROLE).
2790
+ */
2731
2791
  switchRole(newRole: string): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2792
+ /**
2793
+ * Adds a turn to the session. The turn’s parent, version, role, and model
2794
+ * are automatically filled if missing.
2795
+ * @param turn - The turn to add (may be incomplete).
2796
+ * @returns Result with the workspace patch and updates the in‑memory tree.
2797
+ */
2732
2798
  addTurn(turn: Turn): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2799
+ /**
2800
+ * Records a user turn (alias for addTurn).
2801
+ * @param turn - The user turn.
2802
+ */
2733
2803
  recordUserTurn(turn: Turn): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2804
+ /**
2805
+ * Records an assistant turn, processes any tool calls, and optionally records denial turns.
2806
+ * @param turn - The assistant turn (may contain tool calls).
2807
+ * @param recordDenial - If true, adds a user turn explaining denied tool calls.
2808
+ * @returns Result with the merged workspace patches.
2809
+ */
2734
2810
  recordAssistantTurn(turn: Turn, recordDenial?: boolean): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2735
2811
  private buildDenialTurn;
2736
2812
  private describeCommand;
2813
+ /**
2814
+ * Edits an existing turn, creating a new version. The session head is moved to this new version.
2815
+ * @param turnId - ID of the turn to edit.
2816
+ * @param newBlocks - New content blocks for the turn.
2817
+ * @param roleSnapshot - Optional role to associate (defaults to current active version's role).
2818
+ * @param modelSnapshot - Optional model to associate (defaults to current active version's model).
2819
+ */
2737
2820
  editTurn(turnId: UUID, newBlocks: ContentBlock[], roleSnapshot?: string, modelSnapshot?: string): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2821
+ /**
2822
+ * Adds a branch turn (a turn that shares a parent with an existing turn).
2823
+ * @param turn - The turn to branch (must have parent set).
2824
+ */
2738
2825
  branch(turn: Turn): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2826
+ /**
2827
+ * Deletes a specific version of a turn and optionally updates the session head.
2828
+ * @param turnId - ID of the turn.
2829
+ * @param version - Version number to delete.
2830
+ * @param newHead - New head reference after deletion (or null to keep current head if still valid).
2831
+ */
2739
2832
  deleteTurn(turnId: UUID, version: number, newHead: TurnRef | null): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2740
2833
  /**
2741
- * Updates the status of a specific turn using the Result pattern.
2834
+ * Updates the status (success/unsuccessful) of a specific turn version.
2835
+ * @param turnId - ID of the turn.
2836
+ * @param version - Version number of the turn to update.
2837
+ * @param status - Result indicating success or failure.
2838
+ */
2839
+ updateTurnStatus(turnId: UUID, version: number, status: Result<undefined, WorkspaceError>): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2840
+ /**
2841
+ * Switches to the previous version of a turn (if available).
2842
+ * @param turnId - ID of the turn.
2742
2843
  */
2743
- updateTurnStatus(turnId: UUID, status: Result<undefined, WorkspaceError>): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2744
2844
  switchVersionLeft(turnId: UUID): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2845
+ /**
2846
+ * Switches to the next version of a turn (if available).
2847
+ * @param turnId - ID of the turn.
2848
+ */
2745
2849
  switchVersionRight(turnId: UUID): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2746
2850
  private switchVersion;
2747
2851
  /**
2748
- * Assembles a SessionSnapshot for PromptBuilder.
2749
- * * @param target - Optional target for the snapshot.
2750
- * If a UUID is provided, it snapshots the history ending at that turn.
2751
- * If a Turn object is provided, it snapshots a "potential" state where
2752
- * this turn is appended to its parent (or current head) without committing it.
2852
+ * Assembles a SessionSnapshot for the PromptBuilder.
2853
+ * @param target - Optional target:
2854
+ * - If a UUID is provided, snapshots history ending at that turn.
2855
+ * - If a Turn object is provided, snapshots a "potential" state where
2856
+ * this turn is appended to its parent (or current head) without committing it.
2753
2857
  */
2754
2858
  snapshot(target?: UUID | Turn): Promise<SessionSnapshot | undefined>;
2859
+ /**
2860
+ * Rebuilds the in‑memory TurnTree.
2861
+ * @param headOverride - If provided, use this as the session head instead of reading from the store.
2862
+ * This avoids stale reads after mutations that change the head.
2863
+ */
2755
2864
  private refreshTurnTree;
2865
+ /**
2866
+ * Finds the deepest descendant (tip) of a given turn version.
2867
+ * Used when switching versions to determine the new session head.
2868
+ */
2756
2869
  private findSubtreeTip;
2757
2870
  }
2758
2871
 
@@ -2865,7 +2978,7 @@ declare class TurnTree {
2865
2978
  private readonly nodes;
2866
2979
  private readonly _head;
2867
2980
  private constructor();
2868
- static build(sessionId: UUID, repository: TurnRepository): Promise<TurnTree>;
2981
+ static build(sessionId: UUID, repository: TurnRepository, headOverride?: TurnRef | null): Promise<TurnTree>;
2869
2982
  head(): TurnRef | null;
2870
2983
  chain(): TurnNode[];
2871
2984
  /**
package/index.d.ts CHANGED
@@ -2690,10 +2690,17 @@ declare class Session {
2690
2690
  private tree;
2691
2691
  private unsubscribe?;
2692
2692
  private constructor();
2693
+ /**
2694
+ * Factory method to create a new Session instance.
2695
+ * @param sessionId - Unique identifier for the session.
2696
+ * @param manager - Workspace manager for dispatching commands.
2697
+ * @param processor - Turn processor for handling tool calls.
2698
+ * @returns A fully initialised Session.
2699
+ */
2693
2700
  static create(sessionId: UUID, manager: WorkspaceManager, processor: TurnProcessor): Promise<Session>;
2694
2701
  /**
2695
- * Synchronizes the session's in-memory state with the persistent stores.
2696
- * Useful after a workspace-wide sync or if state becomes stale.
2702
+ * Synchronises the session's inmemory state with the persistent stores.
2703
+ * Useful after a workspacewide sync or if state becomes stale.
2697
2704
  */
2698
2705
  sync(): Promise<void>;
2699
2706
  /**
@@ -2702,57 +2709,163 @@ declare class Session {
2702
2709
  close(): void;
2703
2710
  private _setRole;
2704
2711
  private _setPreference;
2712
+ /** Returns the session’s unique identifier. */
2705
2713
  id(): UUID;
2706
2714
  private ws;
2715
+ /** Returns the session metadata from the workspace index. */
2707
2716
  meta(): SessionMetadata | undefined;
2717
+ /** Returns the session’s label (display name). */
2708
2718
  label(): string | undefined;
2719
+ /** Returns the session’s current Role object. */
2709
2720
  role(): Role | undefined;
2721
+ /** Returns the list of topic strings associated with the session. */
2710
2722
  topics(): string[];
2723
+ /** Returns the list of preferences active for this session. */
2711
2724
  preferences(): Preference[];
2725
+ /** Returns the current head (last turn) of the session, or null if empty. */
2712
2726
  head(): TurnRef | null;
2727
+ /** Returns the active chain of turns as an array of TurnNode. */
2713
2728
  turns(): TurnNode[];
2729
+ /**
2730
+ * Returns all sibling turns of a given turn (other children of the same parent).
2731
+ * @param turnId - ID of the turn.
2732
+ */
2714
2733
  siblings(turnId: UUID): Promise<TurnNode[]>;
2734
+ /**
2735
+ * Returns branching information for a turn (versions, navigation).
2736
+ * @param turnId - ID of the turn.
2737
+ */
2715
2738
  branchInfo(turnId: UUID): Promise<BranchInfo>;
2739
+ /**
2740
+ * Retrieves a TurnNode by its ID.
2741
+ * @param turnId - ID of the turn.
2742
+ */
2716
2743
  getTurn(turnId: UUID): Promise<TurnNode | undefined>;
2744
+ /**
2745
+ * Changes the session’s display label.
2746
+ * @param newLabel - New label for the session.
2747
+ */
2717
2748
  rename(newLabel: string): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2749
+ /**
2750
+ * Replaces the session’s topic list.
2751
+ * @param topics - New array of topic strings.
2752
+ */
2718
2753
  setTopics(topics: string[]): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2719
2754
  /**
2720
- * Updates the session's model identifier.
2755
+ * Updates the sessions model identifier (e.g., "gpt-4").
2756
+ * @param model - New model string.
2721
2757
  */
2722
2758
  setModel(model: string): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2723
2759
  /**
2724
- * Merges the provided metadata into the session's current metadata.
2760
+ * Merges arbitrary metadata into the sessions metadata object.
2761
+ * @param metadata - Key‑value pairs to merge.
2725
2762
  */
2726
2763
  updateMetadata(metadata: Record<string, any>): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2764
+ /**
2765
+ * Adds topics to the session (does not replace existing ones).
2766
+ * @param topics - Topics to add.
2767
+ */
2727
2768
  addTopics(topics: string[]): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2769
+ /**
2770
+ * Replaces the session’s preference list with the given IDs.
2771
+ * @param preferenceIds - Array of preference UUIDs.
2772
+ */
2728
2773
  setPreferences(preferenceIds: UUID[]): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2774
+ /**
2775
+ * Creates a new session as a fork of this one.
2776
+ * @param newSessionId - ID for the new session.
2777
+ * @param label - Label for the new session.
2778
+ * @param role - Optional role ID (defaults to current role).
2779
+ * @param topics - Optional topics (defaults to current topics).
2780
+ */
2729
2781
  fork(newSessionId: UUID, label: string, role?: string, topics?: string[]): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2782
+ /**
2783
+ * Dispatches a raw command to the workspace manager.
2784
+ * @param command - BaseCommand to dispatch.
2785
+ */
2730
2786
  dispatch(command: BaseCommand): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2787
+ /**
2788
+ * Switches the session to a different role.
2789
+ * @param newRole - ID of the new role (or EMPTY_SYSTEM_ROLE).
2790
+ */
2731
2791
  switchRole(newRole: string): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2792
+ /**
2793
+ * Adds a turn to the session. The turn’s parent, version, role, and model
2794
+ * are automatically filled if missing.
2795
+ * @param turn - The turn to add (may be incomplete).
2796
+ * @returns Result with the workspace patch and updates the in‑memory tree.
2797
+ */
2732
2798
  addTurn(turn: Turn): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2799
+ /**
2800
+ * Records a user turn (alias for addTurn).
2801
+ * @param turn - The user turn.
2802
+ */
2733
2803
  recordUserTurn(turn: Turn): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2804
+ /**
2805
+ * Records an assistant turn, processes any tool calls, and optionally records denial turns.
2806
+ * @param turn - The assistant turn (may contain tool calls).
2807
+ * @param recordDenial - If true, adds a user turn explaining denied tool calls.
2808
+ * @returns Result with the merged workspace patches.
2809
+ */
2734
2810
  recordAssistantTurn(turn: Turn, recordDenial?: boolean): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2735
2811
  private buildDenialTurn;
2736
2812
  private describeCommand;
2813
+ /**
2814
+ * Edits an existing turn, creating a new version. The session head is moved to this new version.
2815
+ * @param turnId - ID of the turn to edit.
2816
+ * @param newBlocks - New content blocks for the turn.
2817
+ * @param roleSnapshot - Optional role to associate (defaults to current active version's role).
2818
+ * @param modelSnapshot - Optional model to associate (defaults to current active version's model).
2819
+ */
2737
2820
  editTurn(turnId: UUID, newBlocks: ContentBlock[], roleSnapshot?: string, modelSnapshot?: string): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2821
+ /**
2822
+ * Adds a branch turn (a turn that shares a parent with an existing turn).
2823
+ * @param turn - The turn to branch (must have parent set).
2824
+ */
2738
2825
  branch(turn: Turn): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2826
+ /**
2827
+ * Deletes a specific version of a turn and optionally updates the session head.
2828
+ * @param turnId - ID of the turn.
2829
+ * @param version - Version number to delete.
2830
+ * @param newHead - New head reference after deletion (or null to keep current head if still valid).
2831
+ */
2739
2832
  deleteTurn(turnId: UUID, version: number, newHead: TurnRef | null): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2740
2833
  /**
2741
- * Updates the status of a specific turn using the Result pattern.
2834
+ * Updates the status (success/unsuccessful) of a specific turn version.
2835
+ * @param turnId - ID of the turn.
2836
+ * @param version - Version number of the turn to update.
2837
+ * @param status - Result indicating success or failure.
2838
+ */
2839
+ updateTurnStatus(turnId: UUID, version: number, status: Result<undefined, WorkspaceError>): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2840
+ /**
2841
+ * Switches to the previous version of a turn (if available).
2842
+ * @param turnId - ID of the turn.
2742
2843
  */
2743
- updateTurnStatus(turnId: UUID, status: Result<undefined, WorkspaceError>): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2744
2844
  switchVersionLeft(turnId: UUID): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2845
+ /**
2846
+ * Switches to the next version of a turn (if available).
2847
+ * @param turnId - ID of the turn.
2848
+ */
2745
2849
  switchVersionRight(turnId: UUID): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
2746
2850
  private switchVersion;
2747
2851
  /**
2748
- * Assembles a SessionSnapshot for PromptBuilder.
2749
- * * @param target - Optional target for the snapshot.
2750
- * If a UUID is provided, it snapshots the history ending at that turn.
2751
- * If a Turn object is provided, it snapshots a "potential" state where
2752
- * this turn is appended to its parent (or current head) without committing it.
2852
+ * Assembles a SessionSnapshot for the PromptBuilder.
2853
+ * @param target - Optional target:
2854
+ * - If a UUID is provided, snapshots history ending at that turn.
2855
+ * - If a Turn object is provided, snapshots a "potential" state where
2856
+ * this turn is appended to its parent (or current head) without committing it.
2753
2857
  */
2754
2858
  snapshot(target?: UUID | Turn): Promise<SessionSnapshot | undefined>;
2859
+ /**
2860
+ * Rebuilds the in‑memory TurnTree.
2861
+ * @param headOverride - If provided, use this as the session head instead of reading from the store.
2862
+ * This avoids stale reads after mutations that change the head.
2863
+ */
2755
2864
  private refreshTurnTree;
2865
+ /**
2866
+ * Finds the deepest descendant (tip) of a given turn version.
2867
+ * Used when switching versions to determine the new session head.
2868
+ */
2756
2869
  private findSubtreeTip;
2757
2870
  }
2758
2871
 
@@ -2865,7 +2978,7 @@ declare class TurnTree {
2865
2978
  private readonly nodes;
2866
2979
  private readonly _head;
2867
2980
  private constructor();
2868
- static build(sessionId: UUID, repository: TurnRepository): Promise<TurnTree>;
2981
+ static build(sessionId: UUID, repository: TurnRepository, headOverride?: TurnRef | null): Promise<TurnTree>;
2869
2982
  head(): TurnRef | null;
2870
2983
  chain(): TurnNode[];
2871
2984
  /**