@tano.page/protocol 0.13.0 → 0.15.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.
@@ -1,6 +1,7 @@
1
1
  import type { WorkspaceObject } from './objects';
2
2
  import { isShortId } from './short-id';
3
3
  import { validEventTime } from './object-types';
4
+ import { isDoneStatus } from './plan-item';
4
5
 
5
6
  export interface TaskReview {
6
7
  version: 1;
@@ -35,15 +36,23 @@ export function parseTaskReview(value: unknown): TaskReview {
35
36
  export function taskReview(object: Pick<WorkspaceObject, 'properties'>): TaskReview | null {
36
37
  return object.properties.deliveryReview === undefined ? null : parseTaskReview(object.properties.deliveryReview);
37
38
  }
39
+ function syncedReviewStatus(object: WorkspaceObject, completed: boolean) {
40
+ const current = typeof object.properties.status === 'string' ? object.properties.status.trim() : '';
41
+ if (!current) return object.type === 'task' ? { status: completed ? 'done' : 'todo' } : {};
42
+ const chinese = ['待处理', '进行中', '已阻塞', '已完成'].includes(current);
43
+ if (completed) return { status: chinese ? '已完成' : 'done' };
44
+ if (isDoneStatus(current)) return { status: chinese ? '待处理' : 'todo' };
45
+ return object.type === 'task' ? { status: 'todo' } : {};
46
+ }
38
47
  export function submitTaskReview(object: WorkspaceObject, input: Omit<TaskReview, 'version' | 'state' | 'decidedAt' | 'comment'>): WorkspaceObject {
39
48
  const review = parseTaskReview({ ...input, version: 1, state: 'pending' });
40
49
  return { ...object, properties: { ...object.properties, completed: false,
41
- ...(object.type === 'task' ? { status: 'todo' } : {}), deliveryReview: review } };
50
+ ...syncedReviewStatus(object, false), deliveryReview: review } };
42
51
  }
43
52
  export function decideTaskReview(object: WorkspaceObject, decision: 'approved' | 'changes-requested', comment: string, now = new Date().toISOString()): WorkspaceObject {
44
53
  const previous = taskReview(object);
45
54
  if (!previous || previous.state !== 'pending') throw new Error('此交付没有待处理的审阅请求');
46
55
  const review = parseTaskReview({ ...previous, state: decision, decidedAt: now, ...(comment.trim() ? { comment: comment.trim() } : {}) });
47
56
  return { ...object, properties: { ...object.properties, completed: decision === 'approved',
48
- ...(object.type === 'task' ? { status: decision === 'approved' ? 'done' : 'todo' } : {}), deliveryReview: review } };
57
+ ...syncedReviewStatus(object, decision === 'approved'), deliveryReview: review } };
49
58
  }
package/src/types.ts ADDED
@@ -0,0 +1,166 @@
1
+ export interface FileEntry {
2
+ id: string;
3
+ path: string;
4
+ name: string;
5
+ kind: 'file' | 'directory';
6
+ size: number;
7
+ modified: number;
8
+ /** Content hash supplied by the authority when available, never inferred from mtime. */
9
+ contentHash?: string;
10
+ readOnly?: boolean;
11
+ /** Local draft; the authority has not yet confirmed creation. */
12
+ pendingCreation?: boolean;
13
+ }
14
+
15
+ export interface Workspace {
16
+ id: string;
17
+ name: string;
18
+ path: string;
19
+ files: FileEntry[];
20
+ readOnly?: boolean;
21
+ /** Transient creation result; omitted on subsequent opens and refreshes. */
22
+ newlyCreated?: boolean;
23
+ /** Local metadata was deleted; this open initialized a new workspace identity. */
24
+ reinitialized?: boolean;
25
+ /** True only when the current user may delete this workspace. */
26
+ canDelete?: boolean;
27
+ /** Supplied by the authority owning workspace membership, never by portable files. */
28
+ canManagePlugins?: boolean;
29
+ /** Supplied by the authority; content editing alone does not grant settings access. */
30
+ canManageSettings?: boolean;
31
+ }
32
+
33
+ export class WorkspaceAccessRevokedError extends Error {
34
+ constructor() {
35
+ super('你已失去此工作区的访问权限');
36
+ this.name = 'WorkspaceAccessRevokedError';
37
+ }
38
+ }
39
+
40
+ export interface FileSnapshot {
41
+ content: string;
42
+ hash: string;
43
+ modified: number;
44
+ }
45
+
46
+ export type WriteResult =
47
+ | { status: 'saved'; snapshot: FileSnapshot }
48
+ | { status: 'conflict'; snapshot: FileSnapshot }
49
+ | { status: 'missing' };
50
+
51
+ /** Compare identity and content at the filesystem boundary before moving/deleting a document. */
52
+ export interface FileChangeRequest {
53
+ workspaceId: string;
54
+ fileId: string;
55
+ path: string;
56
+ expectedHash: string;
57
+ /** Omitted for deletion. Saved returns the source snapshot, including for deletion. */
58
+ destination?: string;
59
+ }
60
+
61
+ export interface WorkspaceAdapter {
62
+ readonly mode: 'desktop' | 'demo' | 'web';
63
+ reserveObjectId?(occupied: string[]): Promise<string>;
64
+ /** Reserve an externally proposed, never-used object or table ID before exclusive creation. */
65
+ createAgentRecord?(path: string, content: string): Promise<void>;
66
+ /** Select a folder without opening it or changing the active workspace; null cancels. */
67
+ selectWorkspacePath?(): Promise<string | null>;
68
+ open(path?: string): Promise<Workspace | null>;
69
+ close?(workspaceId: string): Promise<void>;
70
+ createWorkspace?(name: string): Promise<Workspace>;
71
+ deleteWorkspace?(workspaceId: string): Promise<void>;
72
+ recent?(): Promise<RecentWorkspace[]>;
73
+ loadSession?(workspaceId: string): Promise<WorkspaceSession | null>;
74
+ saveSession?(workspaceId: string, session: WorkspaceSession): Promise<void>;
75
+ refresh(): Promise<Workspace>;
76
+ search?(workspaceId: string, query: string, signal?: AbortSignal): Promise<SearchHit[]>;
77
+ read(path: string): Promise<FileSnapshot>;
78
+ /** Optional version-checked, synchronous cache. Never returns speculative content. */
79
+ readCached?(path: string): FileSnapshot | undefined;
80
+ /** Best-effort read ahead; implementations bound speculative network work. */
81
+ prefetch?(path: string): Promise<void>;
82
+ write(path: string, content: string, expectedHash: string): Promise<WriteResult>;
83
+ /** May return the workspace including the confirmed creation to avoid a redundant refresh. */
84
+ create(path: string, content: string): Promise<void | Workspace>;
85
+ /** Persist a recoverable local draft without waiting for the remote authority. */
86
+ stageCreate?(path: string, content: string): Promise<{ workspace: Workspace; file: FileEntry }>;
87
+ /** Confirm the staged request, reusing its durable identity and idempotency key on retry. */
88
+ commitCreate?(id: string): Promise<{ file: FileEntry; snapshot: FileSnapshot }>;
89
+ createFolder(path: string): Promise<void>;
90
+ /** Must reject nonempty directories, including hidden/unindexed entries; never recurse. */
91
+ removeEmptyFolder?(workspaceId: string, path: string): Promise<void>;
92
+ rename(from: string, to: string): Promise<void>;
93
+ move(from: string, to: string, kind: FileEntry['kind']): Promise<void>;
94
+ duplicate?(workspaceId: string, path: string): Promise<string>;
95
+ remove(path: string): Promise<void>;
96
+ changeFile?(request: FileChangeRequest): Promise<WriteResult>;
97
+ /** Object-only compare-and-delete. Keeps the assistant file boundary unchanged. */
98
+ removeObjectFile?(request: FileChangeRequest): Promise<WriteResult>;
99
+ reveal(): Promise<void>;
100
+ watch(callback: () => void): Promise<() => void>;
101
+ }
102
+
103
+ export interface SearchHit {
104
+ id: string;
105
+ path: string;
106
+ excerpt: string;
107
+ }
108
+
109
+ export interface RecentWorkspace {
110
+ id: string;
111
+ name: string;
112
+ path: string;
113
+ openedAt: number;
114
+ /** Owner display label supplied by the storage adapter, when available. */
115
+ owner?: string;
116
+ /** Stable owner identity used by workspace dashboard filters. */
117
+ ownerUserId?: string;
118
+ /** Display identity for a cloud workspace owner, when the server provides it. */
119
+ ownerProfile?: { userId: string; name: string; avatar?: string };
120
+ /** Workspace creation time in milliseconds; absent for legacy workspaces. */
121
+ createdAt?: number | null;
122
+ /** Optional user selection state supplied by a storage adapter. */
123
+ favorite?: boolean;
124
+ /** Whether this workspace was explicitly shared with the current user. */
125
+ shared?: boolean;
126
+ icon?: string;
127
+ }
128
+
129
+ export interface SessionDocument {
130
+ id: string;
131
+ path: string;
132
+ draft?: { content: string; base: FileSnapshot };
133
+ }
134
+
135
+ export interface WorkspaceSession {
136
+ version: 1;
137
+ activeId: string;
138
+ documents: SessionDocument[];
139
+ tabs?: string[];
140
+ layout?: WorkspaceLayout;
141
+ dataTables?: {
142
+ id: string;
143
+ fileId?: string;
144
+ path?: string;
145
+ content: string;
146
+ base: FileSnapshot;
147
+ }[];
148
+ }
149
+
150
+ export interface WorkspacePane {
151
+ kind: 'pane';
152
+ id: string;
153
+ tabs: string[];
154
+ activeId: string;
155
+ }
156
+
157
+ export interface WorkspaceSplit {
158
+ kind: 'split';
159
+ id: string;
160
+ axis: 'horizontal' | 'vertical';
161
+ ratio: number;
162
+ first: WorkspaceLayout;
163
+ second: WorkspaceLayout;
164
+ }
165
+
166
+ export type WorkspaceLayout = WorkspacePane | WorkspaceSplit;
@@ -1,4 +1,5 @@
1
- import type { WorkspaceObject, WorkspaceRelation, ReferenceIdentity } from './index';
1
+ import type { ReferenceIdentity, WorkspaceObject } from './objects';
2
+ import type { WorkspaceRelation } from './relations';
2
3
  import { validObjectType } from './object-types';
3
4
  import { referenceKey } from './relations';
4
5
 
@@ -13,7 +14,7 @@ export interface ObjectViewQuery {
13
14
  /** Optional relationship query. The endpoint remains an ID, never a copied record. */
14
15
  relatedTo?: ReferenceIdentity;
15
16
  }
16
- export const defaultObjectViewQuery = (): ObjectViewQuery => ({ layout: 'table', types: ['task', 'project', 'experiment'], includeArchived: false,
17
+ export const defaultObjectViewQuery = (): ObjectViewQuery => ({ layout: 'table', types: [], includeArchived: false,
17
18
  filters: [], sort: { field: 'name', direction: 'asc' }, groupBy: 'property:status' });
18
19
  export function validateObjectViewQuery(query: ObjectViewQuery) {
19
20
  const field = (value: unknown) => typeof value === 'string' && /^(name|type|description|archived|property:[\s\S]{1,100})$/.test(value);
@@ -1,4 +1,4 @@
1
- import type { FileEntry } from './index';
1
+ import type { FileEntry } from './types';
2
2
  import type { ReferenceIdentity } from './objects';
3
3
  import { isShortId } from './short-id';
4
4
  import { validObjectType } from './object-types';