@pstdio/sdk 0.23.0 → 0.24.1

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.
@@ -186,6 +186,7 @@ declare const sessionSchema: z.ZodObject<{
186
186
  cwd: z.ZodNullable<z.ZodString>;
187
187
  params_json: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodBoolean]>>>;
188
188
  anchors_json: z.ZodArray<z.ZodObject<{
189
+ shorthand: z.ZodOptional<z.ZodString>;
189
190
  type: z.ZodString;
190
191
  id: z.ZodString;
191
192
  projectId: z.ZodOptional<z.ZodString>;
@@ -213,6 +214,7 @@ declare const sessionStatusSchema: z.ZodEnum<{
213
214
  export declare type Settings = z.infer<typeof settingsSchema>;
214
215
 
215
216
  declare const settingsSchema: z.ZodObject<{
217
+ notifications_enabled: z.ZodBoolean;
216
218
  max_concurrent_sessions: z.ZodNullable<z.ZodNumber>;
217
219
  }, z.core.$strip>;
218
220
 
@@ -354,6 +356,7 @@ declare const workspaceListItemSchema: z.ZodObject<{
354
356
  workspace_shorthand: z.ZodString;
355
357
  startup_log_file_id: z.ZodNullable<z.ZodString>;
356
358
  anchors_json: z.ZodArray<z.ZodObject<{
359
+ shorthand: z.ZodOptional<z.ZodString>;
357
360
  type: z.ZodString;
358
361
  id: z.ZodString;
359
362
  projectId: z.ZodOptional<z.ZodString>;
@@ -406,6 +409,7 @@ declare const workspaceSchema: z.ZodObject<{
406
409
  workspace_shorthand: z.ZodString;
407
410
  startup_log_file_id: z.ZodNullable<z.ZodString>;
408
411
  anchors_json: z.ZodArray<z.ZodObject<{
412
+ shorthand: z.ZodOptional<z.ZodString>;
409
413
  type: z.ZodString;
410
414
  id: z.ZodString;
411
415
  projectId: z.ZodOptional<z.ZodString>;
@@ -0,0 +1,207 @@
1
+ // src/testing/memory-resources.ts
2
+ var createMemoryResources = (prefixes, sequences = new Map) => ({
3
+ allocate: async ({ kind }) => {
4
+ const prefix = prefixes[kind];
5
+ if (!prefix)
6
+ throw new Error(`Undeclared resource kind: ${kind}`);
7
+ const next = (sequences.get(kind) ?? 0) + 1;
8
+ sequences.set(kind, next);
9
+ return { id: crypto.randomUUID(), shorthand: `${prefix}-${next}` };
10
+ }
11
+ });
12
+
13
+ // src/testing/command-context.ts
14
+ var sequencesByStorage = new WeakMap;
15
+ var paramsByContext = new WeakMap;
16
+ var makeCommandContext = (input) => {
17
+ const { storage, params, projectId = "proj-1", overrides } = input;
18
+ let sequences = sequencesByStorage.get(storage);
19
+ if (!sequences) {
20
+ sequences = new Map;
21
+ sequencesByStorage.set(storage, sequences);
22
+ }
23
+ const resources = createMemoryResources(input.resourcePrefixes ?? {}, sequences);
24
+ const context = {
25
+ extensionId: "test.extension",
26
+ name: "test-extension",
27
+ projectId,
28
+ project: { id: projectId, name: "Test Project", shorthand: "T" },
29
+ storage,
30
+ resources,
31
+ invocation: { params },
32
+ events: { emit: async () => ({ delivered: 0 }) },
33
+ notify: { action: async () => ({}), dismiss: async () => [], resolve: async () => [], toast: async () => {} },
34
+ workspaces: { list: async () => [], get: async () => null, getByShorthand: async () => null },
35
+ sessions: { list: async () => [], listByWorkspace: async () => [], addAnchors: async () => {} },
36
+ ...overrides
37
+ };
38
+ paramsByContext.set(context, params);
39
+ return context;
40
+ };
41
+ var commandParamsFor = (context) => paramsByContext.get(context);
42
+ var makeCommandArgs = (input) => [makeCommandContext(input), input.params];
43
+ // src/testing/memory-repo-files.ts
44
+ var createMemoryRepoFiles = () => {
45
+ const files = new Map;
46
+ const encoder = new TextEncoder;
47
+ const decoder = new TextDecoder;
48
+ return {
49
+ files,
50
+ exists: async (path) => files.has(path) || [...files.keys()].some((file) => file.startsWith(`${path}/`)),
51
+ readText: async (path) => {
52
+ const value = files.get(path);
53
+ if (value === undefined)
54
+ throw new Error(`File not found: ${path}`);
55
+ return decoder.decode(value);
56
+ },
57
+ writeText: async (path, value) => {
58
+ files.set(path, encoder.encode(value));
59
+ },
60
+ readBytes: async (path) => {
61
+ const value = files.get(path);
62
+ if (value === undefined)
63
+ throw new Error(`File not found: ${path}`);
64
+ return value;
65
+ },
66
+ writeBytes: async (path, value) => {
67
+ files.set(path, value);
68
+ },
69
+ list: async (pattern) => {
70
+ const prefix = pattern ? pattern.replace(/\*+.*/, "") : "";
71
+ return [...files.keys()].filter((path) => path.startsWith(prefix)).sort().map((path) => ({ path }));
72
+ },
73
+ listDirs: async () => [],
74
+ delete: async (path) => {
75
+ const matches = [...files.keys()].filter((file) => file === path || file.startsWith(`${path}/`));
76
+ if (matches.length === 0)
77
+ throw Object.assign(new Error(`ENOENT: ${path}`), { code: "ENOENT" });
78
+ for (const file of matches)
79
+ files.delete(file);
80
+ }
81
+ };
82
+ };
83
+ // src/testing/memory-storage.ts
84
+ var createMemoryStorage = () => {
85
+ const kv = new Map;
86
+ const collections = new Map;
87
+ const blobStores = new Map;
88
+ const collectionStore = (name) => {
89
+ const existing = collections.get(name);
90
+ if (existing)
91
+ return existing;
92
+ const created = new Map;
93
+ collections.set(name, created);
94
+ return created;
95
+ };
96
+ const blobStore = (name) => {
97
+ const existing = blobStores.get(name);
98
+ if (existing)
99
+ return existing;
100
+ const created = new Map;
101
+ blobStores.set(name, created);
102
+ return created;
103
+ };
104
+ const blobsApi = (name) => {
105
+ const store = blobStore(name);
106
+ return {
107
+ async put(input) {
108
+ const id = crypto.randomUUID();
109
+ const data = input.data instanceof Uint8Array ? input.data : new Uint8Array(input.data);
110
+ const ref = {
111
+ id,
112
+ name: input.name,
113
+ mimeType: input.mimeType ?? null,
114
+ size: data.byteLength,
115
+ hash: null,
116
+ url: `memory://${id}`,
117
+ createdAt: new Date().toISOString(),
118
+ updatedAt: new Date().toISOString()
119
+ };
120
+ store.set(id, { ...ref, data });
121
+ return ref;
122
+ },
123
+ async get(id) {
124
+ const stored = store.get(id);
125
+ if (!stored)
126
+ return;
127
+ const { data: _data, ...ref } = stored;
128
+ return ref;
129
+ },
130
+ async getBytes(id) {
131
+ const stored = store.get(id);
132
+ if (!stored)
133
+ throw new Error(`File not found: ${id}`);
134
+ return stored.data;
135
+ },
136
+ async list() {
137
+ return [...store.values()].map(({ data: _data, ...ref }) => ref);
138
+ },
139
+ async delete(id) {
140
+ store.delete(id);
141
+ },
142
+ urlFor(id) {
143
+ return `memory://${id}`;
144
+ }
145
+ };
146
+ };
147
+ const api = {
148
+ files: blobsApi("project"),
149
+ scope(_scope) {
150
+ return api;
151
+ },
152
+ async get(key) {
153
+ return kv.get(key);
154
+ },
155
+ async set(key, value) {
156
+ kv.set(key, value);
157
+ },
158
+ async delete(key) {
159
+ kv.delete(key);
160
+ },
161
+ collection(name) {
162
+ const store = collectionStore(name);
163
+ return {
164
+ async get(id) {
165
+ return store.get(id);
166
+ },
167
+ async list() {
168
+ return [...store.values()];
169
+ },
170
+ async put(id, value) {
171
+ store.set(id, value);
172
+ },
173
+ async createIfAbsent(id, value) {
174
+ if (store.has(id))
175
+ return false;
176
+ store.set(id, value);
177
+ return true;
178
+ },
179
+ async deleteIfValue(id, value) {
180
+ if (store.get(id) !== value && JSON.stringify(store.get(id)) !== JSON.stringify(value))
181
+ return false;
182
+ return store.delete(id);
183
+ },
184
+ async create(value) {
185
+ const id = crypto.randomUUID();
186
+ store.set(id, value);
187
+ return { ...typeof value === "object" && value !== null ? value : {}, id };
188
+ },
189
+ async delete(id) {
190
+ store.delete(id);
191
+ },
192
+ attachments(itemId) {
193
+ return blobsApi(`${name}:${itemId}`);
194
+ }
195
+ };
196
+ }
197
+ };
198
+ return api;
199
+ };
200
+ export {
201
+ commandParamsFor,
202
+ createMemoryRepoFiles,
203
+ createMemoryResources,
204
+ createMemoryStorage,
205
+ makeCommandArgs,
206
+ makeCommandContext
207
+ };