MCPcopy Create free account
hub / github.com/cloudflare/computer / memoryStore

Function memoryStore

packages/computer/src/tools/ai.test.ts:57–89  ·  view source on GitHub ↗
(options: {
  content?: string;
  mode?: number;
  size?: number;
  statError?: Error;
  readError?: Error;
  writeError?: Error;
  onWrite?: (path: string, content: Uint8Array, opts?: { mode?: number }) => void;
})

Source from the content-addressed store, hash-verified

55}
56
57function memoryStore(options: {
58 content?: string;
59 mode?: number;
60 size?: number;
61 statError?: Error;
62 readError?: Error;
63 writeError?: Error;
64 onWrite?: (path: string, content: Uint8Array, opts?: { mode?: number }) => void;
65}): FileStore {
66 const content = options.content ?? "";
67 return {
68 async stat() {
69 if (options.statError) throw options.statError;
70 return {
71 size: options.size ?? bytes(content).byteLength,
72 mtime: 1,
73 mode: options.mode,
74 };
75 },
76 async readAll() {
77 if (options.readError) throw options.readError;
78 return bytes(content);
79 },
80 async *readChunks() {
81 if (options.readError) throw options.readError;
82 yield bytes(content);
83 },
84 async write(path, nextContent, opts) {
85 if (options.writeError) throw options.writeError;
86 options.onWrite?.(path, nextContent, opts);
87 },
88 };
89}
90
91describe("WorkspaceFileStore", () => {
92 it("slices byte ranges while reading chunks from Workspace.fs", async () => {

Callers 1

ai.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected