Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions packages/workshop-backend/src/overseer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2554,14 +2554,15 @@ class OverseerImpl implements AgentHooks {
: Promise<GadgetExportFormat[]> {
this.checkChatExistsAndMaterializeDrafts(chatId);
let resolved = await this.#resolveGadgetExportFormats(gadgetId, chatId);
resolved.gadget[Symbol.dispose]();
resolved.gadget?.[Symbol.dispose]();
return resolved.formats;
}

async exportGadget(gadgetId: WorkpieceId, formatId: string, chatId?: number)
: Promise<ReadableStream<Uint8Array>> {
this.checkChatExistsAndMaterializeDrafts(chatId);
let {formats, handler, gadget} = await this.#resolveGadgetExportFormats(gadgetId, chatId);
if (!gadget) throw new Error("The Gadget server stub is unavailable.");
using exportGadget = gadget;
let format = formats.find(candidate => candidate.id === formatId);
if (!format) throw new Error(`This Gadget does not support export format: ${formatId}`);
Expand Down Expand Up @@ -2590,8 +2591,17 @@ class OverseerImpl implements AgentHooks {
async #resolveGadgetExportFormats(gadgetId: WorkpieceId, chatId?: number): Promise<{
formats: GadgetExportFormat[];
handler: Fetcher<GadgetExportEntrypoint> | null;
gadget: NativeRpcStub<any>;
gadget: NativeRpcStub<any> | null;
}> {
let {ydoc} = this.buildYDoc("current");
Comment thread
maxwellpeterson marked this conversation as resolved.
if (chatId !== undefined) {
this.getProposedChanges(chatId).forEach(({update}) => {
if (update !== undefined) Y.applyUpdateV2(ydoc, update);
});
}
let files = ydoc.getMap<Y.Text>(this.gadgetRootName(gadgetId));
if (!files.has("server.js")) return {formats: [], handler: null, gadget: null};
Comment thread
maxwellpeterson marked this conversation as resolved.

let handler = this.loadGadgetWorker(gadgetId, chatId)
.getEntrypoint<GadgetExportEntrypoint>(GADGET_EXPORT_ENTRYPOINT);
// getGadgetFacet() wraps this native stub for Cap'n Web's type system, but this path invokes
Expand All @@ -2600,7 +2610,11 @@ class OverseerImpl implements AgentHooks {
try {
let formats = await readCustomExportFormats(handler, gadget);
return formats === null
? {formats: defaultExportFormats(), handler: null, gadget}
? {
formats: files.has("client.js") ? defaultExportFormats() : [],
handler: null,
gadget,
}
: {formats, handler, gadget};
} catch (error) {
gadget[Symbol.dispose]();
Expand Down
Loading