@asaidimu/utils-workspace 3.1.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.mts CHANGED
@@ -165,12 +165,12 @@ interface DocumentBlock {
165
165
  }
166
166
  /** Represents a structured proposal to create or modify a task. */
167
167
  interface TaskProposalBlock {
168
- id: UUID;
169
- taskId?: UUID;
168
+ id?: UUID;
169
+ ref?: string;
170
170
  type: 'task:proposal';
171
171
  title: string;
172
172
  steps: {
173
- id?: UUID;
173
+ ref?: string;
174
174
  text: string;
175
175
  status: 'todo' | 'done';
176
176
  }[];
@@ -362,13 +362,14 @@ interface SessionMeta {
362
362
  type TaskStatus = 'todo' | 'active' | 'done' | 'blocked' | 'defered';
363
363
  /** A single item within a Task's checklist. */
364
364
  interface TaskStep {
365
- id: UUID;
365
+ ref: string;
366
366
  text: string;
367
367
  completed?: Timestamp;
368
368
  }
369
369
  /** A high-level objective with nested steps, used for tracking AI progress. */
370
370
  interface Task {
371
371
  id: UUID;
372
+ ref?: string;
372
373
  title: string;
373
374
  description?: string;
374
375
  status: TaskStatus;
@@ -402,6 +403,8 @@ interface ContextSummary {
402
403
  }
403
404
  interface TaskSummary {
404
405
  id: UUID;
406
+ ref?: string;
407
+ description: string;
405
408
  title: string;
406
409
  status: TaskStatus;
407
410
  steps: {
@@ -540,15 +543,18 @@ interface DeleteContext extends BaseCommand {
540
543
  key: string;
541
544
  };
542
545
  }
546
+ type TaskRef = UUID | string;
543
547
  interface AddTask extends BaseCommand {
544
548
  type: 'task:add';
545
549
  payload: Task;
546
550
  }
547
551
  interface UpdateTask extends BaseCommand {
548
552
  type: 'task:update';
549
- payload: Partial<Task> & {
553
+ payload: Partial<Task> & ({
550
554
  id: UUID;
551
- };
555
+ } | {
556
+ ref: string;
557
+ });
552
558
  }
553
559
  interface DeleteTask extends BaseCommand {
554
560
  type: 'task:delete';
@@ -851,11 +857,11 @@ interface LLMAdapter<TRequest, TRequestParams, TResponse> {
851
857
  /**
852
858
  * Maps the vendor-specific response back to an internal `Turn`.
853
859
  * * @param params - The raw response received from the model API.
854
- * @returns A standardized Turn object for the workspace transcript.
860
+ * @returns A Result containing standardized Turn object or an error.
855
861
  */
856
862
  parse(params: {
857
863
  response: TResponse;
858
- }): Turn;
864
+ }): Result<Turn, WorkspaceError>;
859
865
  }
860
866
 
861
867
  /**
@@ -1296,8 +1302,8 @@ type CollectionName = typeof COLLECTIONS[keyof typeof COLLECTIONS];
1296
1302
 
1297
1303
  declare function del<T>(): T;
1298
1304
  declare const merge: <T extends object>(original: T, changes: DeepPartial<T> | symbol) => T;
1299
- declare function ok<T>(value: T): Result<T, never>;
1300
- declare function err<E = WorkspaceError>(error: E): Result<never, E>;
1305
+ declare function success<T>(value: T): Result<T, never>;
1306
+ declare function error<E = WorkspaceError>(error: E): Result<never, E>;
1301
1307
  declare function omitNullUndefined<T extends Record<string, any>>(obj: T): Partial<T>;
1302
1308
  declare function createProjectWorkspace<ProjectMetadata extends Record<string, any> = Record<string, any>>({ project, language }: {
1303
1309
  language: string;
@@ -1320,6 +1326,27 @@ declare const createEmptyRole: (name: string, label: string) => Role;
1320
1326
  */
1321
1327
  declare function bufferToBase64(data: ArrayBuffer | Uint8Array | number[]): string;
1322
1328
 
1329
+ /**
1330
+ * Short, deterministic hash of a string (4 chars in base36).
1331
+ * Suitable for AI-friendly reference tokens.
1332
+ */
1333
+ declare function shortHash(s: string, length?: number): string;
1334
+ /**
1335
+ * Generates a short, memorable reference for a task.
1336
+ * - Returns the proposal's own `ref` if provided.
1337
+ * - Otherwise returns a 4‑character hash of the proposal's `id` or `title`.
1338
+ */
1339
+ declare function generateTaskRef(proposal: TaskProposalBlock): string;
1340
+ /**
1341
+ * Generates a short step reference.
1342
+ * - Returns the step's own `ref` if provided.
1343
+ * - Otherwise returns `${taskRef}_${index+1}` (e.g., "a3f9_2").
1344
+ *
1345
+ * The underscore separator avoids confusion with colons, slashes, or
1346
+ * numeric suffixes that could be misinterpreted by LLMs.
1347
+ */
1348
+ declare function generateTaskStepRef(index: number, proposal: TaskProposalBlock): string;
1349
+
1323
1350
  /**
1324
1351
  * Persistence contract for binary blob content and blob registry records.
1325
1352
  *
@@ -1644,8 +1671,8 @@ declare class TurnBuilder {
1644
1671
  addTaskProposal(title: string, steps: {
1645
1672
  text: string;
1646
1673
  status?: 'todo' | 'done';
1647
- id?: UUID;
1648
- }[], action?: 'create' | 'update' | 'complete', taskId?: UUID): TurnBuilder;
1674
+ ref?: string;
1675
+ }[], action?: 'create' | 'update' | 'complete', id?: string): TurnBuilder;
1649
1676
  addBlock(block: ContentBlock): TurnBuilder;
1650
1677
  deleteBlock(blockId: UUID): TurnBuilder;
1651
1678
  editTextBlock(blockId: UUID, newText: string): TurnBuilder;
@@ -1760,9 +1787,6 @@ declare class Session {
1760
1787
  * @returns A patch to merge into the workspace state.
1761
1788
  */
1762
1789
  unsetTask(workspace: Workspace): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
1763
- createTask(workspace: Workspace, title: string, description: string | undefined, steps: {
1764
- text: string;
1765
- }[], topics: string[]): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
1766
1790
  /**
1767
1791
  * Creates a new session as a fork (copy) of this one.
1768
1792
  * @param workspace Current workspace state.
@@ -2030,7 +2054,7 @@ declare class GoogleGenAIAdapter implements LLMAdapter<{
2030
2054
  */
2031
2055
  parse({ response }: {
2032
2056
  response: GenerateContentResponse;
2033
- }): Turn;
2057
+ }): Result<Turn, WorkspaceError>;
2034
2058
  }
2035
2059
 
2036
- export { type AddContext, type AddPreference, type AddRole, type AddSessionTopics, type AddTask, type AddTurn, type AuthRequest, type BackendError, type BaseCommand, type BlobCommand, type BlobError, type BlobMediaType, type BlobRecord, type BlobRef, type BlobStorage, BlobStore, type BlobStoreConfig, type BranchInfo, type BranchTurn, COLLECTIONS, type CallTool, type CollectionName, type Command, type ContentBlock, ContentStore, type Context, type ContextContent, type ContextSummary, type CreateSession, type CreateWorkspace, DefaultTurnProcessor, type DeleteContext, type DeletePreference, type DeleteRole, type DeleteSession, type DeleteTask, type DeleteTurn, type DocumentBlock, type DocumentMediaType, type DuplicateKeyError, EMPTY_SYSTEM_ROLE, type EditTurn, type EffectiveSession, type ForkSession, GoogleGenAIAdapter, type ImageBlock, type ImageMediaType, type Index, type IndexedDBBlobConfig, IndexedDBBlobStorage, type InvalidCommandError, type LLMAdapter, MemoryBlobStorage, type NotFoundError, type OpenResult, type OverrideSessionPreferences, type PermissionDeniedError, type PermissionGuard, type Preference, type PreferenceConflict, type PreferenceSummary, type Project, type Prompt, PromptBuilder, type PurgeBlob, type RecordBlobRemoteId, type RegisterBlob, type ReleaseBlob, type ResolvedBlob, type Result, type RetainBlob, type Role, type RoleSummary, type RoleTransitionBlock, type SHA256, type SaveTurn, Session, SessionManager, type SessionManagerConfig, type SessionMeta, type Settings, type Summarizer, type SummaryBlock, type SwitchRole, type Task, type TaskProposalBlock, type TaskStatus, type TaskStep, type TaskSummary, type TextBlock, type ThinkingBlock, type Timestamp, type TokenBudget, type ToolCall, type ToolRegistry, type ToolResultBlock, type ToolSummary, type ToolUseBlock, type TopicIndex, type Turn, type TurnActor, TurnBuilder, type TurnNode, type TurnProcessor, type TurnRef, TurnTree, type URI, type UUID, type UpdateContext, type UpdatePreference, type UpdateRole, type UpdateSession, type UpdateTask, type Workspace, type WorkspaceBundle, type WorkspaceDatabase, type WorkspaceError, type WorkspaceEvents, WorkspaceManager, bufferToBase64, computeSHA256, createEmptyRole, createProjectWorkspace, createSimpleWorkspace, createWorkspaceDatabase, del, err, extractBlobRecord, extractBlobRef, merge, ok, omitNullUndefined };
2060
+ export { type AddContext, type AddPreference, type AddRole, type AddSessionTopics, type AddTask, type AddTurn, type AuthRequest, type BackendError, type BaseCommand, type BlobCommand, type BlobError, type BlobMediaType, type BlobRecord, type BlobRef, type BlobStorage, BlobStore, type BlobStoreConfig, type BranchInfo, type BranchTurn, COLLECTIONS, type CallTool, type CollectionName, type Command, type ContentBlock, ContentStore, type Context, type ContextContent, type ContextSummary, type CreateSession, type CreateWorkspace, DefaultTurnProcessor, type DeleteContext, type DeletePreference, type DeleteRole, type DeleteSession, type DeleteTask, type DeleteTurn, type DocumentBlock, type DocumentMediaType, type DuplicateKeyError, EMPTY_SYSTEM_ROLE, type EditTurn, type EffectiveSession, type ForkSession, GoogleGenAIAdapter, type ImageBlock, type ImageMediaType, type Index, type IndexedDBBlobConfig, IndexedDBBlobStorage, type InvalidCommandError, type LLMAdapter, MemoryBlobStorage, type NotFoundError, type OpenResult, type OverrideSessionPreferences, type PermissionDeniedError, type PermissionGuard, type Preference, type PreferenceConflict, type PreferenceSummary, type Project, type Prompt, PromptBuilder, type PurgeBlob, type RecordBlobRemoteId, type RegisterBlob, type ReleaseBlob, type ResolvedBlob, type Result, type RetainBlob, type Role, type RoleSummary, type RoleTransitionBlock, type SHA256, type SaveTurn, Session, SessionManager, type SessionManagerConfig, type SessionMeta, type Settings, type Summarizer, type SummaryBlock, type SwitchRole, type Task, type TaskProposalBlock, type TaskRef, type TaskStatus, type TaskStep, type TaskSummary, type TextBlock, type ThinkingBlock, type Timestamp, type TokenBudget, type ToolCall, type ToolRegistry, type ToolResultBlock, type ToolSummary, type ToolUseBlock, type TopicIndex, type Turn, type TurnActor, TurnBuilder, type TurnNode, type TurnProcessor, type TurnRef, TurnTree, type URI, type UUID, type UpdateContext, type UpdatePreference, type UpdateRole, type UpdateSession, type UpdateTask, type Workspace, type WorkspaceBundle, type WorkspaceDatabase, type WorkspaceError, type WorkspaceEvents, WorkspaceManager, bufferToBase64, computeSHA256, createEmptyRole, createProjectWorkspace, createSimpleWorkspace, createWorkspaceDatabase, del, error, extractBlobRecord, extractBlobRef, generateTaskRef, generateTaskStepRef, merge, omitNullUndefined, shortHash, success };
package/index.d.ts CHANGED
@@ -165,12 +165,12 @@ interface DocumentBlock {
165
165
  }
166
166
  /** Represents a structured proposal to create or modify a task. */
167
167
  interface TaskProposalBlock {
168
- id: UUID;
169
- taskId?: UUID;
168
+ id?: UUID;
169
+ ref?: string;
170
170
  type: 'task:proposal';
171
171
  title: string;
172
172
  steps: {
173
- id?: UUID;
173
+ ref?: string;
174
174
  text: string;
175
175
  status: 'todo' | 'done';
176
176
  }[];
@@ -362,13 +362,14 @@ interface SessionMeta {
362
362
  type TaskStatus = 'todo' | 'active' | 'done' | 'blocked' | 'defered';
363
363
  /** A single item within a Task's checklist. */
364
364
  interface TaskStep {
365
- id: UUID;
365
+ ref: string;
366
366
  text: string;
367
367
  completed?: Timestamp;
368
368
  }
369
369
  /** A high-level objective with nested steps, used for tracking AI progress. */
370
370
  interface Task {
371
371
  id: UUID;
372
+ ref?: string;
372
373
  title: string;
373
374
  description?: string;
374
375
  status: TaskStatus;
@@ -402,6 +403,8 @@ interface ContextSummary {
402
403
  }
403
404
  interface TaskSummary {
404
405
  id: UUID;
406
+ ref?: string;
407
+ description: string;
405
408
  title: string;
406
409
  status: TaskStatus;
407
410
  steps: {
@@ -540,15 +543,18 @@ interface DeleteContext extends BaseCommand {
540
543
  key: string;
541
544
  };
542
545
  }
546
+ type TaskRef = UUID | string;
543
547
  interface AddTask extends BaseCommand {
544
548
  type: 'task:add';
545
549
  payload: Task;
546
550
  }
547
551
  interface UpdateTask extends BaseCommand {
548
552
  type: 'task:update';
549
- payload: Partial<Task> & {
553
+ payload: Partial<Task> & ({
550
554
  id: UUID;
551
- };
555
+ } | {
556
+ ref: string;
557
+ });
552
558
  }
553
559
  interface DeleteTask extends BaseCommand {
554
560
  type: 'task:delete';
@@ -851,11 +857,11 @@ interface LLMAdapter<TRequest, TRequestParams, TResponse> {
851
857
  /**
852
858
  * Maps the vendor-specific response back to an internal `Turn`.
853
859
  * * @param params - The raw response received from the model API.
854
- * @returns A standardized Turn object for the workspace transcript.
860
+ * @returns A Result containing standardized Turn object or an error.
855
861
  */
856
862
  parse(params: {
857
863
  response: TResponse;
858
- }): Turn;
864
+ }): Result<Turn, WorkspaceError>;
859
865
  }
860
866
 
861
867
  /**
@@ -1296,8 +1302,8 @@ type CollectionName = typeof COLLECTIONS[keyof typeof COLLECTIONS];
1296
1302
 
1297
1303
  declare function del<T>(): T;
1298
1304
  declare const merge: <T extends object>(original: T, changes: DeepPartial<T> | symbol) => T;
1299
- declare function ok<T>(value: T): Result<T, never>;
1300
- declare function err<E = WorkspaceError>(error: E): Result<never, E>;
1305
+ declare function success<T>(value: T): Result<T, never>;
1306
+ declare function error<E = WorkspaceError>(error: E): Result<never, E>;
1301
1307
  declare function omitNullUndefined<T extends Record<string, any>>(obj: T): Partial<T>;
1302
1308
  declare function createProjectWorkspace<ProjectMetadata extends Record<string, any> = Record<string, any>>({ project, language }: {
1303
1309
  language: string;
@@ -1320,6 +1326,27 @@ declare const createEmptyRole: (name: string, label: string) => Role;
1320
1326
  */
1321
1327
  declare function bufferToBase64(data: ArrayBuffer | Uint8Array | number[]): string;
1322
1328
 
1329
+ /**
1330
+ * Short, deterministic hash of a string (4 chars in base36).
1331
+ * Suitable for AI-friendly reference tokens.
1332
+ */
1333
+ declare function shortHash(s: string, length?: number): string;
1334
+ /**
1335
+ * Generates a short, memorable reference for a task.
1336
+ * - Returns the proposal's own `ref` if provided.
1337
+ * - Otherwise returns a 4‑character hash of the proposal's `id` or `title`.
1338
+ */
1339
+ declare function generateTaskRef(proposal: TaskProposalBlock): string;
1340
+ /**
1341
+ * Generates a short step reference.
1342
+ * - Returns the step's own `ref` if provided.
1343
+ * - Otherwise returns `${taskRef}_${index+1}` (e.g., "a3f9_2").
1344
+ *
1345
+ * The underscore separator avoids confusion with colons, slashes, or
1346
+ * numeric suffixes that could be misinterpreted by LLMs.
1347
+ */
1348
+ declare function generateTaskStepRef(index: number, proposal: TaskProposalBlock): string;
1349
+
1323
1350
  /**
1324
1351
  * Persistence contract for binary blob content and blob registry records.
1325
1352
  *
@@ -1644,8 +1671,8 @@ declare class TurnBuilder {
1644
1671
  addTaskProposal(title: string, steps: {
1645
1672
  text: string;
1646
1673
  status?: 'todo' | 'done';
1647
- id?: UUID;
1648
- }[], action?: 'create' | 'update' | 'complete', taskId?: UUID): TurnBuilder;
1674
+ ref?: string;
1675
+ }[], action?: 'create' | 'update' | 'complete', id?: string): TurnBuilder;
1649
1676
  addBlock(block: ContentBlock): TurnBuilder;
1650
1677
  deleteBlock(blockId: UUID): TurnBuilder;
1651
1678
  editTextBlock(blockId: UUID, newText: string): TurnBuilder;
@@ -1760,9 +1787,6 @@ declare class Session {
1760
1787
  * @returns A patch to merge into the workspace state.
1761
1788
  */
1762
1789
  unsetTask(workspace: Workspace): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
1763
- createTask(workspace: Workspace, title: string, description: string | undefined, steps: {
1764
- text: string;
1765
- }[], topics: string[]): Promise<Result<DeepPartial<Workspace>, WorkspaceError>>;
1766
1790
  /**
1767
1791
  * Creates a new session as a fork (copy) of this one.
1768
1792
  * @param workspace Current workspace state.
@@ -2030,7 +2054,7 @@ declare class GoogleGenAIAdapter implements LLMAdapter<{
2030
2054
  */
2031
2055
  parse({ response }: {
2032
2056
  response: GenerateContentResponse;
2033
- }): Turn;
2057
+ }): Result<Turn, WorkspaceError>;
2034
2058
  }
2035
2059
 
2036
- export { type AddContext, type AddPreference, type AddRole, type AddSessionTopics, type AddTask, type AddTurn, type AuthRequest, type BackendError, type BaseCommand, type BlobCommand, type BlobError, type BlobMediaType, type BlobRecord, type BlobRef, type BlobStorage, BlobStore, type BlobStoreConfig, type BranchInfo, type BranchTurn, COLLECTIONS, type CallTool, type CollectionName, type Command, type ContentBlock, ContentStore, type Context, type ContextContent, type ContextSummary, type CreateSession, type CreateWorkspace, DefaultTurnProcessor, type DeleteContext, type DeletePreference, type DeleteRole, type DeleteSession, type DeleteTask, type DeleteTurn, type DocumentBlock, type DocumentMediaType, type DuplicateKeyError, EMPTY_SYSTEM_ROLE, type EditTurn, type EffectiveSession, type ForkSession, GoogleGenAIAdapter, type ImageBlock, type ImageMediaType, type Index, type IndexedDBBlobConfig, IndexedDBBlobStorage, type InvalidCommandError, type LLMAdapter, MemoryBlobStorage, type NotFoundError, type OpenResult, type OverrideSessionPreferences, type PermissionDeniedError, type PermissionGuard, type Preference, type PreferenceConflict, type PreferenceSummary, type Project, type Prompt, PromptBuilder, type PurgeBlob, type RecordBlobRemoteId, type RegisterBlob, type ReleaseBlob, type ResolvedBlob, type Result, type RetainBlob, type Role, type RoleSummary, type RoleTransitionBlock, type SHA256, type SaveTurn, Session, SessionManager, type SessionManagerConfig, type SessionMeta, type Settings, type Summarizer, type SummaryBlock, type SwitchRole, type Task, type TaskProposalBlock, type TaskStatus, type TaskStep, type TaskSummary, type TextBlock, type ThinkingBlock, type Timestamp, type TokenBudget, type ToolCall, type ToolRegistry, type ToolResultBlock, type ToolSummary, type ToolUseBlock, type TopicIndex, type Turn, type TurnActor, TurnBuilder, type TurnNode, type TurnProcessor, type TurnRef, TurnTree, type URI, type UUID, type UpdateContext, type UpdatePreference, type UpdateRole, type UpdateSession, type UpdateTask, type Workspace, type WorkspaceBundle, type WorkspaceDatabase, type WorkspaceError, type WorkspaceEvents, WorkspaceManager, bufferToBase64, computeSHA256, createEmptyRole, createProjectWorkspace, createSimpleWorkspace, createWorkspaceDatabase, del, err, extractBlobRecord, extractBlobRef, merge, ok, omitNullUndefined };
2060
+ export { type AddContext, type AddPreference, type AddRole, type AddSessionTopics, type AddTask, type AddTurn, type AuthRequest, type BackendError, type BaseCommand, type BlobCommand, type BlobError, type BlobMediaType, type BlobRecord, type BlobRef, type BlobStorage, BlobStore, type BlobStoreConfig, type BranchInfo, type BranchTurn, COLLECTIONS, type CallTool, type CollectionName, type Command, type ContentBlock, ContentStore, type Context, type ContextContent, type ContextSummary, type CreateSession, type CreateWorkspace, DefaultTurnProcessor, type DeleteContext, type DeletePreference, type DeleteRole, type DeleteSession, type DeleteTask, type DeleteTurn, type DocumentBlock, type DocumentMediaType, type DuplicateKeyError, EMPTY_SYSTEM_ROLE, type EditTurn, type EffectiveSession, type ForkSession, GoogleGenAIAdapter, type ImageBlock, type ImageMediaType, type Index, type IndexedDBBlobConfig, IndexedDBBlobStorage, type InvalidCommandError, type LLMAdapter, MemoryBlobStorage, type NotFoundError, type OpenResult, type OverrideSessionPreferences, type PermissionDeniedError, type PermissionGuard, type Preference, type PreferenceConflict, type PreferenceSummary, type Project, type Prompt, PromptBuilder, type PurgeBlob, type RecordBlobRemoteId, type RegisterBlob, type ReleaseBlob, type ResolvedBlob, type Result, type RetainBlob, type Role, type RoleSummary, type RoleTransitionBlock, type SHA256, type SaveTurn, Session, SessionManager, type SessionManagerConfig, type SessionMeta, type Settings, type Summarizer, type SummaryBlock, type SwitchRole, type Task, type TaskProposalBlock, type TaskRef, type TaskStatus, type TaskStep, type TaskSummary, type TextBlock, type ThinkingBlock, type Timestamp, type TokenBudget, type ToolCall, type ToolRegistry, type ToolResultBlock, type ToolSummary, type ToolUseBlock, type TopicIndex, type Turn, type TurnActor, TurnBuilder, type TurnNode, type TurnProcessor, type TurnRef, TurnTree, type URI, type UUID, type UpdateContext, type UpdatePreference, type UpdateRole, type UpdateSession, type UpdateTask, type Workspace, type WorkspaceBundle, type WorkspaceDatabase, type WorkspaceError, type WorkspaceEvents, WorkspaceManager, bufferToBase64, computeSHA256, createEmptyRole, createProjectWorkspace, createSimpleWorkspace, createWorkspaceDatabase, del, error, extractBlobRecord, extractBlobRef, generateTaskRef, generateTaskStepRef, merge, omitNullUndefined, shortHash, success };