| 599 | // even if the parent hibernates and comes back between calls. |
| 600 | |
| 601 | class SharedWorkspace implements WorkspaceFsLike { |
| 602 | #stubPromise?: Promise<DurableObjectStub<AssistantDirectory>>; |
| 603 | |
| 604 | constructor(private child: Pick<MyAssistant, "parentAgent">) {} |
| 605 | |
| 606 | private parent(): Promise<DurableObjectStub<AssistantDirectory>> { |
| 607 | this.#stubPromise ??= this.child.parentAgent(AssistantDirectory); |
| 608 | return this.#stubPromise; |
| 609 | } |
| 610 | |
| 611 | async readFile(path: string) { |
| 612 | return (await this.parent()).readFile(path); |
| 613 | } |
| 614 | |
| 615 | async readFileBytes(path: string) { |
| 616 | return (await this.parent()).readFileBytes(path); |
| 617 | } |
| 618 | |
| 619 | async writeFile( |
| 620 | path: string, |
| 621 | content: string, |
| 622 | mimeType?: Parameters<Workspace["writeFile"]>[2] |
| 623 | ) { |
| 624 | return (await this.parent()).writeFile(path, content, mimeType); |
| 625 | } |
| 626 | |
| 627 | async writeFileBytes( |
| 628 | path: string, |
| 629 | content: Parameters<Workspace["writeFileBytes"]>[1], |
| 630 | mimeType?: Parameters<Workspace["writeFileBytes"]>[2] |
| 631 | ) { |
| 632 | return (await this.parent()).writeFileBytes(path, content, mimeType); |
| 633 | } |
| 634 | |
| 635 | async appendFile( |
| 636 | path: string, |
| 637 | content: string, |
| 638 | mimeType?: Parameters<Workspace["appendFile"]>[2] |
| 639 | ) { |
| 640 | return (await this.parent()).appendFile(path, content, mimeType); |
| 641 | } |
| 642 | |
| 643 | async exists(path: string) { |
| 644 | return (await this.parent()).exists(path); |
| 645 | } |
| 646 | |
| 647 | async readDir(path?: string, opts?: Parameters<Workspace["readDir"]>[1]) { |
| 648 | return (await this.parent()).readDir(path ?? "/", opts); |
| 649 | } |
| 650 | |
| 651 | async rm(path: string, opts?: Parameters<Workspace["rm"]>[1]) { |
| 652 | return (await this.parent()).rm(path, opts); |
| 653 | } |
| 654 | |
| 655 | async glob(pattern: string) { |
| 656 | return (await this.parent()).glob(pattern); |
| 657 | } |
| 658 |
nothing calls this directly
no outgoing calls
no test coverage detected