minimal-forge-work-pack-sync 0.1.33 → 0.1.34

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.
Files changed (2) hide show
  1. package/dist/index.js +52 -4
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -7551,7 +7551,7 @@ var DEFAULT_DEBUG_TRACE_LIMITS = {
7551
7551
  };
7552
7552
 
7553
7553
  // packages/shared/src/contracts/settings.ts
7554
- var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.33";
7554
+ var WORK_PACK_SYNC_PLUGIN_VERSION = "0.1.34";
7555
7555
  var WORK_PACK_SYNC_PLUGIN_PACKAGE = `minimal-forge-work-pack-sync@${WORK_PACK_SYNC_PLUGIN_VERSION}`;
7556
7556
  var WORK_PACK_SYNC_PLUGIN_FILENAME = `minimal-forge-work-pack-sync-${WORK_PACK_SYNC_PLUGIN_VERSION}.tgz`;
7557
7557
  var FIRECRAWL_KEYLESS_MCP_NAME = "firecrawl";
@@ -7688,7 +7688,7 @@ async function probeHealth(url2, route, headers, healthyField, source) {
7688
7688
  }
7689
7689
 
7690
7690
  // packages/cli/src/workPackSyncPlugin.ts
7691
- import { createHash as createHash5 } from "node:crypto";
7691
+ import { createHash as createHash5, randomUUID as randomUUID2 } from "node:crypto";
7692
7692
  import { pathToFileURL } from "node:url";
7693
7693
 
7694
7694
  // packages/cli/src/skillUsageReporter.ts
@@ -25168,7 +25168,7 @@ function isRecord(value) {
25168
25168
  }
25169
25169
 
25170
25170
  // packages/cli/src/workPackSyncPlugin.ts
25171
- var PLUGIN_VERSION = "0.1.33";
25171
+ var PLUGIN_VERSION = "0.1.34";
25172
25172
  var FORGE_DECISION_TIMEOUT_MS = 11e4;
25173
25173
  var STATUS_FILENAME = "work-pack-startup-status.json";
25174
25174
  var activeSync = /* @__PURE__ */ new Map();
@@ -25229,12 +25229,60 @@ var ForgeWorkPackSyncServer = async (_input, options) => {
25229
25229
  forge_decide_run: createForgeDecisionRunTool(forgeBaseUrl, state.decisionBaseUrl, state.paths),
25230
25230
  forge_decide: createForgeDecisionTool(forgeBaseUrl, state.decisionBaseUrl, state.paths),
25231
25231
  forge_generate_codebook: createForgeCodebookTool(forgeBaseUrl, state.decisionBaseUrl, state.paths),
25232
- forge_feedback: createForgeFeedbackTool(forgeBaseUrl, state.paths)
25232
+ forge_feedback: createForgeFeedbackTool(forgeBaseUrl, state.paths),
25233
+ forge_image: createForgeImageTool(forgeBaseUrl, state.decisionBaseUrl, state.paths)
25233
25234
  }
25234
25235
  };
25235
25236
  };
25236
25237
  var ForgeDecisionRejectedError = class extends Error {
25237
25238
  };
25239
+ function createForgeImageTool(forgeBaseUrl, gatewayBaseUrl, paths) {
25240
+ return tool({
25241
+ description: "Cria ou edita uma imagem a pedido da pessoa. Usa uma \xFAnica chamada por imagem; cada revis\xE3o consome outra das 30 imagens mensais. Guarda o PNG na pasta de trabalho e devolve o caminho para visualiza\xE7\xE3o. N\xE3o fa\xE7as revis\xF5es autom\xE1ticas.",
25242
+ args: {
25243
+ prompt: tool.schema.string().min(1).max(8e3).describe("Descri\xE7\xE3o da imagem ou altera\xE7\xE3o pedida"),
25244
+ referencePath: tool.schema.string().optional().describe("Caminho expl\xEDcito de uma imagem PNG, JPEG ou WebP a editar")
25245
+ },
25246
+ async execute(args, context) {
25247
+ const requestId = randomUUID2();
25248
+ let referenceDataUrl;
25249
+ if (args.referencePath) {
25250
+ const bytes = await readFile4(args.referencePath);
25251
+ if (bytes.byteLength > 25e5) throw new Error("A imagem de refer\xEAncia \xE9 demasiado grande. Reduza-a antes de tentar novamente.");
25252
+ const mime = bytes.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10])) ? "image/png" : bytes.subarray(0, 3).equals(Buffer.from([255, 216, 255])) ? "image/jpeg" : bytes.subarray(0, 4).toString() === "RIFF" && bytes.subarray(8, 12).toString() === "WEBP" ? "image/webp" : void 0;
25253
+ if (!mime) throw new Error("A refer\xEAncia tem de ser PNG, JPEG ou WebP.");
25254
+ referenceDataUrl = `data:${mime};base64,${bytes.toString("base64")}`;
25255
+ }
25256
+ const credentials = await readWellKnownForgeCredentials(paths.opencodeAuthPath, forgeBaseUrl);
25257
+ let response;
25258
+ try {
25259
+ response = await fetch(`${gatewayBaseUrl}/v1/images`, {
25260
+ method: "POST",
25261
+ redirect: "error",
25262
+ headers: { authorization: `Bearer ${credentials.forgeApiKey}`, "content-type": "application/json" },
25263
+ body: JSON.stringify({ requestId, prompt: args.prompt, referenceDataUrl }),
25264
+ signal: AbortSignal.any([context.abort, AbortSignal.timeout(15e4)])
25265
+ });
25266
+ } catch {
25267
+ throw new Error(`O resultado da imagem \xE9 incerto. N\xE3o repita automaticamente. Refer\xEAncia: ${requestId}`);
25268
+ }
25269
+ const body = await response.json();
25270
+ if (!response.ok) throw new Error(`${body.error?.message ?? "A gera\xE7\xE3o falhou"} Refer\xEAncia: ${requestId}`);
25271
+ if (body.media_type !== "image/png" || !body.b64_json) throw new Error(`O resultado da imagem \xE9 incerto. Refer\xEAncia: ${requestId}`);
25272
+ const image = Buffer.from(body.b64_json, "base64");
25273
+ if (image.byteLength > 8 * 1024 * 1024 || !image.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]))) {
25274
+ throw new Error(`O PNG recebido \xE9 inv\xE1lido. Refer\xEAncia: ${requestId}`);
25275
+ }
25276
+ const destination = path6.join(context.directory, `forge-image-${requestId}.png`);
25277
+ await writeFile4(destination, image, { flag: "wx" });
25278
+ const reset = body.quota && new Intl.DateTimeFormat("pt-PT", { dateStyle: "long", timeZone: "Europe/Lisbon" }).format(new Date(body.quota.resetsAt));
25279
+ const remaining = body.quota ? ` Restam ${body.quota.remaining} imagens at\xE9 ${reset}.` : "";
25280
+ return `Imagem guardada em ${destination}.${remaining}
25281
+
25282
+ ![Imagem gerada](${destination})`;
25283
+ }
25284
+ });
25285
+ }
25238
25286
  function createForgeDecisionTool(forgeBaseUrl, decisionBaseUrl, paths, responseDirectory) {
25239
25287
  const question = tool.schema.discriminatedUnion("type", [
25240
25288
  tool.schema.object({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minimal-forge-work-pack-sync",
3
- "version": "0.1.33",
3
+ "version": "0.1.34",
4
4
  "description": "Minimal Forge Work Pack startup synchronization for OpenCode and OpenWork.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {