@frockbot/plugin-subagents 0.0.0 → 0.1.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/frockbot.json +33 -0
- package/package.json +38 -6
- package/src/agent.test.ts +480 -0
- package/src/agent.ts +1078 -0
- package/src/backend.ts +193 -0
- package/src/index.ts +8 -0
- package/src/manifest.ts +3 -0
- package/src/models.test.ts +175 -0
- package/src/models.ts +185 -0
- package/src/quota.test.ts +82 -0
- package/src/quota.ts +222 -0
- package/src/records.test.ts +245 -0
- package/src/records.ts +649 -0
- package/src/roles.test.ts +60 -0
- package/src/roles.ts +76 -0
- package/src/shared.ts +232 -0
- package/src/storage-keys.ts +148 -0
- package/src/store.test.ts +500 -0
- package/src/store.ts +695 -0
- package/src/testing.ts +58 -0
- package/tsconfig.json +15 -0
- package/README.md +0 -3
package/src/testing.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// An in-memory storage seam, for tests and for any host that needs the Durable
|
|
2
|
+
// Object's storage contract without a Durable Object: a sorted key space,
|
|
3
|
+
// exact-key reads, and a transaction that rolls back.
|
|
4
|
+
import type { TaskStorageV1, TaskStorageWritesV1 } from "./store.js";
|
|
5
|
+
import type { SubagentSlotTransaction } from "./quota.js";
|
|
6
|
+
|
|
7
|
+
export interface MemorySubagentStorageV1 extends TaskStorageV1 {
|
|
8
|
+
/** Every key currently held, sorted. Useful for asserting trimming. */
|
|
9
|
+
keys(): string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function reads(map: Map<string, unknown>): TaskStorageWritesV1 {
|
|
13
|
+
return {
|
|
14
|
+
get<T>(key: string): Promise<T | undefined> {
|
|
15
|
+
return Promise.resolve(map.get(key) as T | undefined);
|
|
16
|
+
},
|
|
17
|
+
list<T>(options: {
|
|
18
|
+
prefix: string;
|
|
19
|
+
limit?: number;
|
|
20
|
+
}): Promise<Map<string, T>> {
|
|
21
|
+
const entries = [...map.entries()]
|
|
22
|
+
.filter(([key]) => key.startsWith(options.prefix))
|
|
23
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
24
|
+
.slice(0, options.limit ?? Number.POSITIVE_INFINITY);
|
|
25
|
+
return Promise.resolve(new Map(entries as Array<[string, T]>));
|
|
26
|
+
},
|
|
27
|
+
put(key: string, value: unknown): Promise<void> {
|
|
28
|
+
map.set(key, structuredClone(value));
|
|
29
|
+
return Promise.resolve();
|
|
30
|
+
},
|
|
31
|
+
delete(key: string): Promise<boolean> {
|
|
32
|
+
return Promise.resolve(map.delete(key));
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function createMemorySubagentStorageV1(): MemorySubagentStorageV1 {
|
|
38
|
+
const map = new Map<string, unknown>();
|
|
39
|
+
const base = reads(map);
|
|
40
|
+
return {
|
|
41
|
+
...base,
|
|
42
|
+
keys: () => [...map.keys()].sort(),
|
|
43
|
+
async transaction<T>(
|
|
44
|
+
closure: (
|
|
45
|
+
transaction: TaskStorageWritesV1 & SubagentSlotTransaction,
|
|
46
|
+
) => Promise<T>,
|
|
47
|
+
): Promise<T> {
|
|
48
|
+
const snapshot = new Map(map);
|
|
49
|
+
try {
|
|
50
|
+
return await closure(base);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
map.clear();
|
|
53
|
+
for (const [key, value] of snapshot) map.set(key, value);
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
} satisfies MemorySubagentStorageV1;
|
|
58
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2023",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Bundler",
|
|
6
|
+
"allowImportingTsExtensions": true,
|
|
7
|
+
"resolveJsonModule": true,
|
|
8
|
+
"strict": true,
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"lib": ["ES2023", "DOM"],
|
|
12
|
+
"types": ["bun"]
|
|
13
|
+
},
|
|
14
|
+
"include": ["src/**/*.ts"]
|
|
15
|
+
}
|
package/README.md
DELETED