@bike4mind/cli 0.2.28-feat-gpt-image-models-and-edit-tool.18724 → 0.2.28-fix-cli-eslint-errors.18724

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.
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  CurationArtifactType
4
- } from "./chunk-UL52XZ3O.js";
4
+ } from "./chunk-F3HPUK2I.js";
5
5
 
6
6
  // ../../b4m-core/packages/services/dist/src/notebookCurationService/artifactExtractor.js
7
7
  var ARTIFACT_TAG_REGEX = /<artifact\s+(.*?)>([\s\S]*?)<\/artifact>/gi;
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  BadRequestError,
4
4
  secureParameters
5
- } from "./chunk-KRXMHF4N.js";
5
+ } from "./chunk-JQOZTED2.js";
6
6
  import {
7
7
  CompletionApiUsageTransaction,
8
8
  GenericCreditDeductTransaction,
@@ -12,7 +12,7 @@ import {
12
12
  TextGenerationUsageTransaction,
13
13
  TransferCreditTransaction,
14
14
  VideoGenerationUsageTransaction
15
- } from "./chunk-UL52XZ3O.js";
15
+ } from "./chunk-F3HPUK2I.js";
16
16
 
17
17
  // ../../b4m-core/packages/services/dist/src/creditService/subtractCredits.js
18
18
  import { z } from "zod";
@@ -7,11 +7,11 @@ import {
7
7
  getSettingsMap,
8
8
  getSettingsValue,
9
9
  secureParameters
10
- } from "./chunk-KRXMHF4N.js";
10
+ } from "./chunk-JQOZTED2.js";
11
11
  import {
12
12
  KnowledgeType,
13
13
  SupportedFabFileMimeTypes
14
- } from "./chunk-UL52XZ3O.js";
14
+ } from "./chunk-F3HPUK2I.js";
15
15
 
16
16
  // ../../b4m-core/packages/services/dist/src/fabFileService/create.js
17
17
  import { z } from "zod";
@@ -29,9 +29,6 @@ var ModelBackend;
29
29
  var ImageModels;
30
30
  (function(ImageModels2) {
31
31
  ImageModels2["GPT_IMAGE_1"] = "gpt-image-1";
32
- ImageModels2["GPT_IMAGE_1_5"] = "gpt-image-1.5";
33
- ImageModels2["GPT_IMAGE_1_MINI"] = "gpt-image-1-mini";
34
- ImageModels2["DALL_E_2"] = "dall-e-2";
35
32
  ImageModels2["FLUX_PRO"] = "flux-pro";
36
33
  ImageModels2["FLUX_PRO_1_1"] = "flux-pro-1.1";
37
34
  ImageModels2["FLUX_PRO_ULTRA"] = "flux-pro-1.1-ultra";
@@ -1958,11 +1955,7 @@ var ChatCompletionCreateInputSchema = z16.object({
1958
1955
  content: z16.string()
1959
1956
  })).optional()
1960
1957
  });
1961
- var OPENAI_IMAGE_MODELS = [
1962
- ImageModels.GPT_IMAGE_1,
1963
- ImageModels.GPT_IMAGE_1_5,
1964
- ImageModels.GPT_IMAGE_1_MINI
1965
- ];
1958
+ var OPENAI_IMAGE_MODELS = [ImageModels.GPT_IMAGE_1];
1966
1959
  var ALL_IMAGE_MODELS = [
1967
1960
  ...OPENAI_IMAGE_MODELS,
1968
1961
  ...BFL_IMAGE_MODELS,
@@ -4443,9 +4436,7 @@ var GenerateImageToolCallSchema = OpenAIImageGenerationInput.extend({
4443
4436
  safety_tolerance: z25.number().optional(),
4444
4437
  prompt_upsampling: z25.boolean().optional(),
4445
4438
  output_format: z25.enum(["jpeg", "png"]).nullable().optional(),
4446
- seed: z25.number().nullable().optional(),
4447
- editModel: z25.string().optional()
4448
- // Model to use for image editing operations (separate from generation model)
4439
+ seed: z25.number().nullable().optional()
4449
4440
  }).omit({
4450
4441
  prompt: true
4451
4442
  });
@@ -15,7 +15,7 @@ import {
15
15
  dayjsConfig_default,
16
16
  extractSnippetMeta,
17
17
  settingsMap
18
- } from "./chunk-UL52XZ3O.js";
18
+ } from "./chunk-F3HPUK2I.js";
19
19
  import {
20
20
  Logger
21
21
  } from "./chunk-OCYRD7D6.js";
@@ -6425,36 +6425,6 @@ var OpenAIBackend = class {
6425
6425
  description: "OpenAI GPT-Image-1 - Advanced multimodal image generation with text integration, supporting up to 2048x2048 resolution and image editing capabilities.",
6426
6426
  rank: 10
6427
6427
  },
6428
- {
6429
- id: ImageModels.GPT_IMAGE_1_5,
6430
- type: "image",
6431
- name: "GPT-Image-1.5",
6432
- backend: ModelBackend.OpenAI,
6433
- contextWindow: 1e4,
6434
- supportsImageVariation: true,
6435
- max_tokens: 1e4,
6436
- pricing: {
6437
- 1: { input: 8 / 1e6, output: 32 / 1e6 }
6438
- // $8 / 1M Input tokens, $32 / 1M Output tokens (same as GPT-Image-1)
6439
- },
6440
- description: "OpenAI GPT-Image-1.5 - Enhanced version of GPT-Image-1 with improved image generation quality and text integration, supporting up to 2048x2048 resolution and image editing capabilities.",
6441
- rank: 9
6442
- },
6443
- {
6444
- id: ImageModels.GPT_IMAGE_1_MINI,
6445
- type: "image",
6446
- name: "GPT-Image-1 Mini",
6447
- backend: ModelBackend.OpenAI,
6448
- contextWindow: 1e4,
6449
- supportsImageVariation: true,
6450
- max_tokens: 1e4,
6451
- pricing: {
6452
- 1: { input: 4 / 1e6, output: 16 / 1e6 }
6453
- // Lower pricing for mini variant
6454
- },
6455
- description: "OpenAI GPT-Image-1 Mini - Faster, cost-effective version of GPT-Image-1 with good quality image generation and text integration, supporting up to 2048x2048 resolution and image editing capabilities.",
6456
- rank: 11
6457
- },
6458
6428
  // OpenAI Speech-to-Text Models
6459
6429
  {
6460
6430
  id: SpeechToTextModels.WHISPER_1,
@@ -9925,9 +9895,6 @@ async function invokeImageProcessor(imageBuffer, lambdaFunctionName, maxSizeMB =
9925
9895
  throw new Error("ImageProcessor Lambda returned no payload");
9926
9896
  }
9927
9897
  const result = JSON.parse(Buffer.from(response.Payload).toString());
9928
- if (!result.processedBuffer) {
9929
- throw new Error(`ImageProcessor Lambda returned invalid response - missing processedBuffer. Response: ${JSON.stringify(result)}`);
9930
- }
9931
9898
  console.log(`[ImageProcessorUtils] Image processed successfully:`, {
9932
9899
  outputSizeMB: result.sizeMB,
9933
9900
  isPng: result.isPng
@@ -9965,28 +9932,24 @@ async function downloadImageAsBuffer(imageUrl) {
9965
9932
 
9966
9933
  // ../../b4m-core/packages/utils/dist/src/imageGeneration/OpenAIImageService.js
9967
9934
  var OpenAIImageService = class extends AIImageService {
9968
- // Helper to check if a model is a GPT Image model
9969
- isGPTImageModel(model) {
9970
- return model === ImageModels.GPT_IMAGE_1 || model === ImageModels.GPT_IMAGE_1_5 || model === ImageModels.GPT_IMAGE_1_MINI;
9971
- }
9972
9935
  async generate(prompt, options) {
9973
9936
  const openai = new OpenAI5({ apiKey: this.apiKey });
9974
9937
  Logger.log("Generating image... with these params: ", options);
9975
9938
  try {
9976
9939
  const { safety_tolerance, prompt_upsampling, seed: bflSeed, output_format, imagePrompt, stream, ...openaiOptions } = options;
9977
9940
  const parameterWarnings = [];
9978
- if (this.isGPTImageModel(options.model)) {
9979
- const modelName = options.model || ImageModels.GPT_IMAGE_1_5;
9980
- openaiOptions.model = modelName;
9941
+ if (options.model === ImageModels.GPT_IMAGE_1) {
9942
+ console.log("[DEBUG] GPT-Image-1 parameter validation and sanitization...");
9943
+ openaiOptions.model = "gpt-image-1";
9981
9944
  if (openaiOptions.style) {
9982
- parameterWarnings.push(`Style parameter ('${openaiOptions.style}') is not supported by ${modelName} and was removed`);
9945
+ parameterWarnings.push(`Style parameter ('${openaiOptions.style}') is not supported by GPT-Image-1 and was removed`);
9983
9946
  delete openaiOptions.style;
9984
9947
  }
9985
9948
  if (openaiOptions.response_format) {
9986
9949
  delete openaiOptions.response_format;
9987
9950
  }
9988
9951
  if (openaiOptions.quality) {
9989
- parameterWarnings.push(`Quality parameter ('${openaiOptions.quality}') is not supported by ${modelName} text-to-image generation and was removed`);
9952
+ parameterWarnings.push(`Quality parameter ('${openaiOptions.quality}') is not supported by GPT-Image-1 text-to-image generation and was removed`);
9990
9953
  delete openaiOptions.quality;
9991
9954
  }
9992
9955
  const validGPTSizes = ["1024x1024", "1536x1024", "1024x1536"];
@@ -9994,7 +9957,7 @@ var OpenAIImageService = class extends AIImageService {
9994
9957
  if (!validGPTSizes.includes(openaiOptions.size)) {
9995
9958
  const originalSize = openaiOptions.size;
9996
9959
  openaiOptions.size = "1024x1024";
9997
- parameterWarnings.push(`Size '${originalSize}' is not supported by ${modelName}, changed to '1024x1024'`);
9960
+ parameterWarnings.push(`Size '${originalSize}' is not supported by GPT-Image-1, changed to '1024x1024'`);
9998
9961
  }
9999
9962
  } else {
10000
9963
  openaiOptions.size = "1024x1024";
@@ -10002,10 +9965,10 @@ var OpenAIImageService = class extends AIImageService {
10002
9965
  if ("width" in openaiOptions || "height" in openaiOptions) {
10003
9966
  delete openaiOptions.width;
10004
9967
  delete openaiOptions.height;
10005
- parameterWarnings.push(`Custom width/height not supported by ${modelName}, using standard sizes`);
9968
+ parameterWarnings.push("Custom width/height not supported by GPT-Image-1, using standard sizes");
10006
9969
  }
10007
9970
  if (parameterWarnings.length > 0) {
10008
- console.log(`[DEBUG] \u26A0\uFE0F ${modelName} parameter adjustments:`, parameterWarnings);
9971
+ console.log("[DEBUG] \u26A0\uFE0F GPT-Image-1 parameter adjustments:", parameterWarnings);
10009
9972
  }
10010
9973
  } else {
10011
9974
  openaiOptions.response_format = "url";
@@ -10024,37 +9987,99 @@ var OpenAIImageService = class extends AIImageService {
10024
9987
  if (bflSeed !== null && bflSeed !== void 0) {
10025
9988
  openaiOptions.seed = bflSeed;
10026
9989
  }
9990
+ console.log("[DEBUG] OpenAI Image generation sanitized params:", {
9991
+ model: options.model,
9992
+ prompt: prompt.substring(0, 100) + "...",
9993
+ finalOptions: openaiOptions,
9994
+ adjustments: parameterWarnings.length > 0 ? parameterWarnings : "No adjustments needed"
9995
+ });
10027
9996
  let images = [];
10028
- let result;
10029
- if (imagePrompt) {
10030
- const imageBuffer = await downloadImageAsBuffer(imagePrompt);
10031
- if (!this.imageProcessorLambdaName) {
10032
- throw new Error("ImageProcessor Lambda name is required for image processing. Please provide it when creating the image service.");
10033
- }
10034
- const pngBuffer = await invokeImageProcessor(imageBuffer, this.imageProcessorLambdaName, 4);
10035
- const imageFile = new File([pngBuffer], "image.png", { type: "image/png" });
10036
- if (this.isGPTImageModel(options.model)) {
10037
- const editModel = options.model || ImageModels.GPT_IMAGE_1_5;
10038
- result = await openai.images.edit({
10039
- model: editModel,
10040
- image: [imageFile],
10041
- prompt
9997
+ if (false) {
9998
+ } else {
9999
+ let result;
10000
+ if (imagePrompt) {
10001
+ console.log("RUNNING IMAGE-TO-IMAGE for ", imagePrompt);
10002
+ const imageBuffer = await downloadImageAsBuffer(imagePrompt);
10003
+ if (!this.imageProcessorLambdaName) {
10004
+ throw new Error("ImageProcessor Lambda name is required for image processing. Please provide it when creating the image service.");
10005
+ }
10006
+ const pngBuffer = await invokeImageProcessor(imageBuffer, this.imageProcessorLambdaName, 4);
10007
+ console.log(`[DEBUG] Image prepared for image-to-image:`, {
10008
+ originalUrl: imagePrompt.substring(0, 100) + "...",
10009
+ pngSizeMB: (pngBuffer.length / (1024 * 1024)).toFixed(2),
10010
+ bufferLength: pngBuffer.length
10042
10011
  });
10012
+ const imageFile = new File([pngBuffer], "image.png", { type: "image/png" });
10013
+ if (options.model === ImageModels.GPT_IMAGE_1) {
10014
+ console.log("[DEBUG] Using GPT-Image-1 edit endpoint for image-to-image generation");
10015
+ const { style, quality, size, ...editOptions } = openaiOptions;
10016
+ let editSize;
10017
+ const validEditSizes = [
10018
+ "auto",
10019
+ "1024x1024",
10020
+ "1536x1024",
10021
+ "1024x1536",
10022
+ "256x256",
10023
+ "512x512"
10024
+ ];
10025
+ if (size && validEditSizes.includes(size)) {
10026
+ editSize = size;
10027
+ } else if (size) {
10028
+ console.log(`[DEBUG] Size '${size}' not supported by edit endpoint, using '1024x1024'`);
10029
+ editSize = "1024x1024";
10030
+ }
10031
+ result = await openai.images.edit({
10032
+ ...editOptions,
10033
+ image: imageFile,
10034
+ prompt,
10035
+ model: "gpt-image-1",
10036
+ ...editSize && { size: editSize }
10037
+ });
10038
+ console.log("[DEBUG] GPT-Image-1 edit result:", {
10039
+ success: !!result,
10040
+ dataLength: result?.data?.length,
10041
+ hasUrl: !!result?.data?.[0]?.url,
10042
+ hasB64: !!result?.data?.[0]?.b64_json
10043
+ });
10044
+ } else {
10045
+ console.log("[DEBUG] Using DALL-E 2 variation endpoint");
10046
+ const { style, quality, model, ...opts } = openaiOptions;
10047
+ result = await openai.images.createVariation({
10048
+ ...opts,
10049
+ image: imageFile,
10050
+ size: ["256x256", "512x512", "1024x1024"].find((s) => s === openaiOptions.size)
10051
+ });
10052
+ console.log("[DEBUG] Variation result:", {
10053
+ success: !!result,
10054
+ dataLength: result?.data?.length,
10055
+ hasUrl: !!result?.data?.[0]?.url
10056
+ });
10057
+ }
10043
10058
  } else {
10044
- const { style, quality, model, ...opts } = openaiOptions;
10045
- result = await openai.images.createVariation({
10046
- ...opts,
10047
- image: imageFile,
10048
- size: ["256x256", "512x512", "1024x1024"].find((s) => s === openaiOptions.size)
10059
+ console.log("RUNNING GENERATE");
10060
+ result = await openai.images.generate({
10061
+ prompt,
10062
+ ...openaiOptions
10063
+ });
10064
+ console.log("[DEBUG] OpenAI raw response:", {
10065
+ model: options.model,
10066
+ resultData: result?.data,
10067
+ firstImage: result?.data?.[0],
10068
+ firstImageKeys: result?.data?.[0] ? Object.keys(result.data[0]) : "No first image"
10069
+ });
10070
+ console.log("[DEBUG] OpenAI Image generation response:", {
10071
+ model: options.model,
10072
+ responseData: result?.data?.length ? `${result.data.length} images generated` : "No images",
10073
+ firstUrl: result?.data?.[0]?.url ? "URL received" : "No URL"
10049
10074
  });
10050
10075
  }
10051
- } else {
10052
- result = await openai.images.generate({
10053
- prompt,
10054
- ...openaiOptions
10055
- });
10076
+ images = this.imageResponseToUrl(result);
10056
10077
  }
10057
- images = this.imageResponseToUrl(result);
10078
+ console.log("[DEBUG] OpenAI Image generation completed:", {
10079
+ model: options.model,
10080
+ imageCount: images.length,
10081
+ hasUrls: images.every((url) => url && url.startsWith("http"))
10082
+ });
10058
10083
  return images;
10059
10084
  } catch (error) {
10060
10085
  console.error("[DEBUG] Error in OpenAI image generation:", {
@@ -10097,7 +10122,7 @@ Tip: Consider using alternative models like Flux Pro that may have different con
10097
10122
  throw new Error(`Image response contains neither url nor b64_json: ${JSON.stringify(Object.keys(imageData))}`);
10098
10123
  });
10099
10124
  }
10100
- async edit(image, prompt, { mask = null, model = ImageModels.GPT_IMAGE_1_5, n = 1, size, response_format = "url", user }) {
10125
+ async edit(image, prompt, { mask = null, model = ImageModels.GPT_IMAGE_1, n = 1, size, response_format = "url", user }) {
10101
10126
  try {
10102
10127
  const openai = new OpenAI5({ apiKey: this.apiKey });
10103
10128
  const cleanImageBase64 = image.replace(/^data:image\/(png|jpeg|jpg);base64,/, "");
@@ -10117,35 +10142,35 @@ Tip: Consider using alternative models like Flux Pro that may have different con
10117
10142
  const pngMaskBuffer = await invokeImageProcessor(maskBuffer, this.imageProcessorLambdaName, 4);
10118
10143
  maskFile = new File([pngMaskBuffer], "mask.png", { type: "image/png" });
10119
10144
  }
10120
- let editModel = model;
10121
- if (!this.isGPTImageModel(model) && model !== ImageModels.DALL_E_2) {
10122
- console.log(`[DEBUG] \u26A0\uFE0F Edit endpoint doesn't support ${model}, defaulting to gpt-image-1.5`);
10123
- editModel = ImageModels.GPT_IMAGE_1_5;
10124
- }
10125
- const response = await openai.images.edit(this.isGPTImageModel(editModel) ? {
10126
- model: editModel,
10127
- image: [imageFile],
10128
- prompt
10129
- } : {
10130
- model: editModel,
10131
- image: imageFile,
10145
+ console.log("[DEBUG] OpenAI Image edit request:", {
10132
10146
  prompt,
10147
+ size,
10148
+ imageFile,
10149
+ maskFile,
10150
+ n,
10151
+ response_format,
10152
+ user
10153
+ });
10154
+ const response = await openai.images.edit({
10155
+ prompt,
10156
+ image: imageFile,
10133
10157
  mask: maskFile,
10134
10158
  n,
10135
10159
  size,
10136
10160
  response_format,
10137
10161
  user
10138
10162
  });
10163
+ console.log("[DEBUG] OpenAI Image edit response:", {
10164
+ data: response
10165
+ });
10139
10166
  if (response.data && response.data.length > 0) {
10140
10167
  const result = response.data[0];
10141
- const dataUrl = result.b64_json ? `data:image/png;base64,${result.b64_json}` : result.url;
10142
- if (!dataUrl) {
10143
- throw new Error(`Image response contains neither url nor b64_json: ${JSON.stringify(Object.keys(result))}`);
10144
- }
10168
+ const dataUrl = response_format === "b64_json" ? result.b64_json : result.url;
10145
10169
  return { type: "success", dataUrl };
10146
10170
  }
10147
10171
  throw new Error("No image was generated");
10148
10172
  } catch (error) {
10173
+ console.error("[DEBUG] Error in OpenAI image edit:", error);
10149
10174
  if (error instanceof OpenAI5.APIError) {
10150
10175
  console.error("[DEBUG] OpenAI API error details:", {
10151
10176
  status: error.status,
@@ -10179,8 +10204,8 @@ import axios3 from "axios";
10179
10204
  var BFLImageService = class extends AIImageService {
10180
10205
  baseUrl = "https://api.bfl.ai/v1";
10181
10206
  static failedRequests = {};
10182
- constructor(apiKey, logger, imageProcessorLambdaName) {
10183
- super(apiKey, logger, imageProcessorLambdaName);
10207
+ constructor(apiKey, logger) {
10208
+ super(apiKey, logger);
10184
10209
  }
10185
10210
  async generate(prompt, { n = 1, user = "user", model = ImageModels.FLUX_PRO_1_1, safety_tolerance = 0.5, prompt_upsampling = false, seed = null, output_format = "png", width = 1024, height = 768, aspect_ratio = "16:9", image_prompt, ...modelSpecificOptions }) {
10186
10211
  try {
@@ -10575,8 +10600,8 @@ import { GoogleGenAI as GoogleGenAI2 } from "@google/genai";
10575
10600
  import { v4 as uuidv42 } from "uuid";
10576
10601
  var GeminiImageService = class extends AIImageService {
10577
10602
  genAI;
10578
- constructor(apiKey, logger, imageProcessorLambdaName) {
10579
- super(apiKey, logger, imageProcessorLambdaName);
10603
+ constructor(apiKey, logger) {
10604
+ super(apiKey, logger);
10580
10605
  this.genAI = new GoogleGenAI2({ apiKey });
10581
10606
  }
10582
10607
  async generate(prompt, options) {
@@ -6,12 +6,12 @@ import {
6
6
  getSettingsByNames,
7
7
  obfuscateApiKey,
8
8
  secureParameters
9
- } from "./chunk-KRXMHF4N.js";
9
+ } from "./chunk-JQOZTED2.js";
10
10
  import {
11
11
  ApiKeyType,
12
12
  MementoTier,
13
13
  isSupportedEmbeddingModel
14
- } from "./chunk-UL52XZ3O.js";
14
+ } from "./chunk-F3HPUK2I.js";
15
15
 
16
16
  // ../../b4m-core/packages/services/dist/src/apiKeyService/get.js
17
17
  import { z } from "zod";
@@ -2,9 +2,9 @@
2
2
  import {
3
3
  createFabFile,
4
4
  createFabFileSchema
5
- } from "./chunk-533FZUGS.js";
6
- import "./chunk-KRXMHF4N.js";
7
- import "./chunk-UL52XZ3O.js";
5
+ } from "./chunk-5ZYPV3TT.js";
6
+ import "./chunk-JQOZTED2.js";
7
+ import "./chunk-F3HPUK2I.js";
8
8
  import "./chunk-OCYRD7D6.js";
9
9
  export {
10
10
  createFabFile,