getaiapi 1.1.0 → 1.2.0

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.
@@ -33438,9 +33438,11 @@ var registry_default = [
33438
33438
  prompt: "prompt",
33439
33439
  negative_prompt: "negative_prompt",
33440
33440
  image: "image",
33441
+ image_tail: "image_tail",
33441
33442
  duration: "duration",
33442
33443
  size: "aspect_ratio",
33443
- guidance: "cfg_scale"
33444
+ voice_list: "voice_list",
33445
+ sound: "sound"
33444
33446
  },
33445
33447
  defaults: {
33446
33448
  model_name: "kling-v2-6",
@@ -33458,14 +33460,13 @@ var registry_default = [
33458
33460
  endpoint: "fal-ai/kling-video/v2.6/pro/image-to-video",
33459
33461
  auth_env: "FAL_KEY",
33460
33462
  param_map: {
33461
- image: "image_url",
33463
+ image: "start_image_url",
33464
+ image_tail: "end_image_url",
33462
33465
  prompt: "prompt",
33463
33466
  negative_prompt: "negative_prompt",
33464
- seed: "seed",
33465
- guidance: "guidance_scale",
33466
- steps: "num_inference_steps",
33467
- format: "output_format",
33468
- safety: "enable_safety_checker"
33467
+ duration: "duration",
33468
+ voice_ids: "voice_ids",
33469
+ generate_audio: "generate_audio"
33469
33470
  },
33470
33471
  output_map: {
33471
33472
  type: "video",
@@ -73258,6 +73259,78 @@ var AuthManager = class {
73258
73259
  }
73259
73260
  };
73260
73261
 
73262
+ // src/fetch.ts
73263
+ var DEFAULT_TIMEOUT_MS = 3e4;
73264
+ var SENSITIVE_HEADER = /auth|key|token|secret|bearer/i;
73265
+ var config = {
73266
+ timeoutMs: DEFAULT_TIMEOUT_MS,
73267
+ logging: false,
73268
+ logger: (entry) => console.debug(JSON.stringify(entry))
73269
+ };
73270
+ function configureFetch(options) {
73271
+ if (options.timeoutMs !== void 0) config.timeoutMs = options.timeoutMs;
73272
+ if (options.logging !== void 0) config.logging = options.logging;
73273
+ if (options.logger) config.logger = options.logger;
73274
+ }
73275
+ function redactHeaders(headers) {
73276
+ if (!headers) return void 0;
73277
+ const entries = headers instanceof Headers ? Array.from(headers.entries()) : Array.isArray(headers) ? headers : Object.entries(headers);
73278
+ const result = {};
73279
+ for (const [key, value] of entries) {
73280
+ result[key] = SENSITIVE_HEADER.test(key) ? "[REDACTED]" : value;
73281
+ }
73282
+ return result;
73283
+ }
73284
+ function bodySize(body) {
73285
+ if (typeof body === "string") return body.length;
73286
+ if (body instanceof ArrayBuffer) return body.byteLength;
73287
+ if (body instanceof Uint8Array) return body.byteLength;
73288
+ return void 0;
73289
+ }
73290
+ async function fetchWithTimeout(url, init) {
73291
+ const finalInit = { ...init };
73292
+ if (!finalInit.signal) {
73293
+ finalInit.signal = AbortSignal.timeout(config.timeoutMs);
73294
+ }
73295
+ const method = (finalInit.method ?? "GET").toUpperCase();
73296
+ const start = Date.now();
73297
+ if (config.logging) {
73298
+ config.logger({
73299
+ kind: "request",
73300
+ method,
73301
+ url,
73302
+ bodyBytes: bodySize(finalInit.body),
73303
+ headers: redactHeaders(finalInit.headers)
73304
+ });
73305
+ }
73306
+ try {
73307
+ const response = await fetch(url, finalInit);
73308
+ if (config.logging) {
73309
+ const contentLength = response.headers.get("content-length");
73310
+ config.logger({
73311
+ kind: "response",
73312
+ method,
73313
+ url,
73314
+ status: response.status,
73315
+ durationMs: Date.now() - start,
73316
+ responseBytes: contentLength ? parseInt(contentLength, 10) : void 0
73317
+ });
73318
+ }
73319
+ return response;
73320
+ } catch (err) {
73321
+ if (config.logging) {
73322
+ config.logger({
73323
+ kind: "error",
73324
+ method,
73325
+ url,
73326
+ durationMs: Date.now() - start,
73327
+ error: err instanceof Error ? err.message : String(err)
73328
+ });
73329
+ }
73330
+ throw err;
73331
+ }
73332
+ }
73333
+
73261
73334
  // src/adapters/kling.ts
73262
73335
  import { createHmac } from "crypto";
73263
73336
  var API_BASE = "https://api-singapore.klingai.com";
@@ -73329,7 +73402,7 @@ var klingAdapter = {
73329
73402
  name: "kling",
73330
73403
  async submit(endpoint, params, auth) {
73331
73404
  const url = `${API_BASE}/${endpoint}`;
73332
- const response = await fetch(url, {
73405
+ const response = await fetchWithTimeout(url, {
73333
73406
  method: "POST",
73334
73407
  headers: getAuthHeaders(auth),
73335
73408
  body: JSON.stringify(cleanParams(params))
@@ -73347,7 +73420,7 @@ var klingAdapter = {
73347
73420
  throw new ProviderError("kling", "unknown", 400, "endpoint is required for polling");
73348
73421
  }
73349
73422
  const url = `${API_BASE}/${endpoint}/${taskId}`;
73350
- const response = await fetch(url, {
73423
+ const response = await fetchWithTimeout(url, {
73351
73424
  headers: getAuthHeaders(auth)
73352
73425
  });
73353
73426
  await handleHttpErrors(response, endpoint);
@@ -73528,9 +73601,9 @@ function parseExpiresIn(value) {
73528
73601
  }
73529
73602
  return parsed;
73530
73603
  }
73531
- function configureStorage(config) {
73532
- if (config) {
73533
- storageConfig = config;
73604
+ function configureStorage(config2) {
73605
+ if (config2) {
73606
+ storageConfig = config2;
73534
73607
  return;
73535
73608
  }
73536
73609
  const accountId = process.env.R2_ACCOUNT_ID;
@@ -73563,15 +73636,15 @@ function getConfig() {
73563
73636
  }
73564
73637
  return storageConfig;
73565
73638
  }
73566
- function buildR2Url(config, key) {
73567
- return `https://${config.accountId}.r2.cloudflarestorage.com/${config.bucketName}/${key}`;
73639
+ function buildR2Url(config2, key) {
73640
+ return `https://${config2.accountId}.r2.cloudflarestorage.com/${config2.bucketName}/${key}`;
73568
73641
  }
73569
- function buildPublicUrl(config, key) {
73570
- if (config.publicUrlBase) {
73571
- const base = config.publicUrlBase.replace(/\/$/, "");
73642
+ function buildPublicUrl(config2, key) {
73643
+ if (config2.publicUrlBase) {
73644
+ const base = config2.publicUrlBase.replace(/\/$/, "");
73572
73645
  return `${base}/${key}`;
73573
73646
  }
73574
- return buildR2Url(config, key);
73647
+ return buildR2Url(config2, key);
73575
73648
  }
73576
73649
  function detectContentType(input) {
73577
73650
  if (input instanceof File) return input.type || "application/octet-stream";
@@ -73585,7 +73658,7 @@ async function toBuffer(input) {
73585
73658
  return Buffer.from(input);
73586
73659
  }
73587
73660
  async function uploadAsset(input, options) {
73588
- const config = getConfig();
73661
+ const config2 = getConfig();
73589
73662
  const buffer = await toBuffer(input);
73590
73663
  const maxBytes = options?.maxBytes ?? DEFAULT_MAX_BYTES;
73591
73664
  if (buffer.length > maxBytes) {
@@ -73597,15 +73670,15 @@ async function uploadAsset(input, options) {
73597
73670
  const contentType = options?.contentType ?? detectContentType(input);
73598
73671
  const prefix = options?.prefix ? `${options.prefix.replace(/\/$/, "")}/` : "";
73599
73672
  const key = options?.key ?? `${prefix}${randomUUID()}`;
73600
- const r2Url = buildR2Url(config, key);
73673
+ const r2Url = buildR2Url(config2, key);
73601
73674
  const signed = signS3Request(
73602
73675
  "PUT",
73603
73676
  r2Url,
73604
73677
  { "Content-Type": contentType, "Content-Length": String(buffer.length) },
73605
73678
  buffer,
73606
73679
  {
73607
- accessKeyId: config.accessKeyId,
73608
- secretAccessKey: config.secretAccessKey
73680
+ accessKeyId: config2.accessKeyId,
73681
+ secretAccessKey: config2.secretAccessKey
73609
73682
  }
73610
73683
  );
73611
73684
  const response = await fetch(signed.url, {
@@ -73617,7 +73690,7 @@ async function uploadAsset(input, options) {
73617
73690
  const body = await response.text().catch(() => "");
73618
73691
  throw new StorageError("upload", `R2 returned ${response.status}: ${body}`, response.status);
73619
73692
  }
73620
- const url = config.mode === "presigned" ? validatedPresign(config, key) : buildPublicUrl(config, key);
73693
+ const url = config2.mode === "presigned" ? validatedPresign(config2, key) : buildPublicUrl(config2, key);
73621
73694
  return {
73622
73695
  url,
73623
73696
  key,
@@ -73625,34 +73698,34 @@ async function uploadAsset(input, options) {
73625
73698
  content_type: contentType
73626
73699
  };
73627
73700
  }
73628
- function validatedPresign(config, key, expiresIn) {
73629
- const ttl = expiresIn ?? config.presignExpiresIn ?? 3600;
73701
+ function validatedPresign(config2, key, expiresIn) {
73702
+ const ttl = expiresIn ?? config2.presignExpiresIn ?? 3600;
73630
73703
  if (ttl > MAX_PRESIGN_EXPIRES) {
73631
73704
  throw new StorageError(
73632
73705
  "config",
73633
73706
  `Presign expiry ${ttl}s exceeds maximum of ${MAX_PRESIGN_EXPIRES}s (7 days).`
73634
73707
  );
73635
73708
  }
73636
- return presignS3Url(buildR2Url(config, key), {
73637
- accessKeyId: config.accessKeyId,
73638
- secretAccessKey: config.secretAccessKey
73709
+ return presignS3Url(buildR2Url(config2, key), {
73710
+ accessKeyId: config2.accessKeyId,
73711
+ secretAccessKey: config2.secretAccessKey
73639
73712
  }, { expiresIn: ttl });
73640
73713
  }
73641
73714
  function presignAsset(key, options) {
73642
- const config = getConfig();
73643
- return validatedPresign(config, key, options?.expiresIn);
73715
+ const config2 = getConfig();
73716
+ return validatedPresign(config2, key, options?.expiresIn);
73644
73717
  }
73645
73718
  async function deleteAsset(key) {
73646
- const config = getConfig();
73647
- const r2Url = buildR2Url(config, key);
73719
+ const config2 = getConfig();
73720
+ const r2Url = buildR2Url(config2, key);
73648
73721
  const signed = signS3Request(
73649
73722
  "DELETE",
73650
73723
  r2Url,
73651
73724
  {},
73652
73725
  null,
73653
73726
  {
73654
- accessKeyId: config.accessKeyId,
73655
- secretAccessKey: config.secretAccessKey
73727
+ accessKeyId: config2.accessKeyId,
73728
+ secretAccessKey: config2.secretAccessKey
73656
73729
  }
73657
73730
  );
73658
73731
  const response = await fetch(signed.url, {
@@ -73726,9 +73799,9 @@ async function processRecord(obj, shouldReupload, maxBytes) {
73726
73799
  return result;
73727
73800
  }
73728
73801
  async function processParamsForUpload(params, options) {
73729
- const config = getStorageConfig();
73730
- if (!config) return params;
73731
- const shouldReupload = options?.reupload || config.autoUpload || false;
73802
+ const config2 = getStorageConfig();
73803
+ if (!config2) return params;
73804
+ const shouldReupload = options?.reupload || config2.autoUpload || false;
73732
73805
  const maxBytes = options?.maxBytes ?? DEFAULT_MAX_BYTES;
73733
73806
  return processRecord(params, shouldReupload, maxBytes);
73734
73807
  }
@@ -73772,7 +73845,7 @@ var falAiAdapter = {
73772
73845
  name: "fal-ai",
73773
73846
  async submit(endpoint, params, auth) {
73774
73847
  const url = `${BASE_URL}/${endpoint}`;
73775
- const response = await fetch(url, {
73848
+ const response = await fetchWithTimeout(url, {
73776
73849
  method: "POST",
73777
73850
  headers: authHeaders(auth),
73778
73851
  body: JSON.stringify(params)
@@ -73790,7 +73863,7 @@ var falAiAdapter = {
73790
73863
  }
73791
73864
  const baseEndpoint = getBaseEndpoint(endpoint);
73792
73865
  const statusUrl = `${BASE_URL}/${baseEndpoint}/requests/${taskId}/status`;
73793
- const statusResponse = await fetch(statusUrl, {
73866
+ const statusResponse = await fetchWithTimeout(statusUrl, {
73794
73867
  headers: { Authorization: `Key ${auth}` }
73795
73868
  });
73796
73869
  await handleHttpErrors2(statusResponse, endpoint);
@@ -73809,7 +73882,7 @@ var falAiAdapter = {
73809
73882
  };
73810
73883
  }
73811
73884
  const resultUrl = `${BASE_URL}/${baseEndpoint}/requests/${taskId}`;
73812
- const resultResponse = await fetch(resultUrl, {
73885
+ const resultResponse = await fetchWithTimeout(resultUrl, {
73813
73886
  headers: { Authorization: `Key ${auth}` }
73814
73887
  });
73815
73888
  await handleHttpErrors2(resultResponse, endpoint);
@@ -73947,7 +74020,7 @@ async function fetchLatestVersion(endpoint, auth) {
73947
74020
  const cached = versionCache.get(endpoint);
73948
74021
  if (cached) return cached;
73949
74022
  const url = `${BASE_URL2}/models/${endpoint}`;
73950
- const response = await fetch(url, {
74023
+ const response = await fetchWithTimeout(url, {
73951
74024
  headers: { Authorization: `Bearer ${auth}` }
73952
74025
  });
73953
74026
  await handleHttpErrors3(response, endpoint);
@@ -73960,7 +74033,7 @@ async function fetchLatestVersion(endpoint, auth) {
73960
74033
  }
73961
74034
  async function submitWithVersion(endpoint, params, auth) {
73962
74035
  const version = await fetchLatestVersion(endpoint, auth);
73963
- const response = await fetch(`${BASE_URL2}/predictions`, {
74036
+ const response = await fetchWithTimeout(`${BASE_URL2}/predictions`, {
73964
74037
  method: "POST",
73965
74038
  headers: authHeaders2(auth),
73966
74039
  body: JSON.stringify({ version, input: params })
@@ -73976,7 +74049,7 @@ var replicateAdapter = {
73976
74049
  return submitWithVersion(endpoint, params, auth);
73977
74050
  }
73978
74051
  const modelsUrl = `${BASE_URL2}/models/${endpoint}/predictions`;
73979
- const response = await fetch(modelsUrl, {
74052
+ const response = await fetchWithTimeout(modelsUrl, {
73980
74053
  method: "POST",
73981
74054
  headers: authHeaders2(auth),
73982
74055
  body: JSON.stringify({ input: params })
@@ -73991,7 +74064,7 @@ var replicateAdapter = {
73991
74064
  },
73992
74065
  async poll(taskId, auth) {
73993
74066
  const url = `${BASE_URL2}/predictions/${taskId}`;
73994
- const response = await fetch(url, {
74067
+ const response = await fetchWithTimeout(url, {
73995
74068
  headers: { Authorization: `Bearer ${auth}` }
73996
74069
  });
73997
74070
  await handleHttpErrors3(response, taskId);
@@ -74078,7 +74151,7 @@ var wavespeedAdapter = {
74078
74151
  name: "wavespeed",
74079
74152
  async submit(endpoint, params, auth) {
74080
74153
  const url = `${BASE_URL3}/${endpoint}`;
74081
- const response = await fetch(url, {
74154
+ const response = await fetchWithTimeout(url, {
74082
74155
  method: "POST",
74083
74156
  headers: authHeaders3(auth),
74084
74157
  body: JSON.stringify(params)
@@ -74092,7 +74165,7 @@ var wavespeedAdapter = {
74092
74165
  },
74093
74166
  async poll(taskId, auth) {
74094
74167
  const url = `${BASE_URL3}/predictions/${taskId}/result`;
74095
- const response = await fetch(url, {
74168
+ const response = await fetchWithTimeout(url, {
74096
74169
  headers: { Authorization: `Bearer ${auth}` }
74097
74170
  });
74098
74171
  await handleHttpErrors4(response, `predictions/${taskId}/result`);
@@ -74175,7 +74248,7 @@ var openRouterAdapter = {
74175
74248
  if (max_tokens !== void 0) body.max_tokens = max_tokens;
74176
74249
  if (top_p !== void 0) body.top_p = top_p;
74177
74250
  const url = `${BASE_URL4}/chat/completions`;
74178
- const response = await fetch(url, {
74251
+ const response = await fetchWithTimeout(url, {
74179
74252
  method: "POST",
74180
74253
  headers: authHeaders4(auth),
74181
74254
  body: JSON.stringify(body)
@@ -74282,7 +74355,7 @@ var adapters = {
74282
74355
  "openrouter": openRouterAdapter,
74283
74356
  "kling": klingAdapter
74284
74357
  };
74285
- var DEFAULT_TIMEOUT_MS = 12e4;
74358
+ var DEFAULT_TIMEOUT_MS2 = 12e4;
74286
74359
  async function _prepare(request) {
74287
74360
  if (!request.model) throw new ValidationError("model", "model is required");
74288
74361
  const auth = new AuthManager();
@@ -74316,7 +74389,7 @@ async function _prepare(request) {
74316
74389
  }
74317
74390
  async function submit(request) {
74318
74391
  const { binding, adapter, apiKey, finalParams, model } = await _prepare(request);
74319
- const timeoutMs = request.options?.timeout ?? DEFAULT_TIMEOUT_MS;
74392
+ const timeoutMs = request.options?.timeout ?? DEFAULT_TIMEOUT_MS2;
74320
74393
  const submitted = await withRetry(
74321
74394
  () => adapter.submit(binding.endpoint, finalParams, apiKey),
74322
74395
  { timeoutMs, provider: binding.provider, model: model.canonical_name }
@@ -74386,7 +74459,7 @@ async function submitAndPoll(request) {
74386
74459
  async function generate(request) {
74387
74460
  const startTime = Date.now();
74388
74461
  const { binding, adapter, apiKey, finalParams, model } = await _prepare(request);
74389
- const timeoutMs = request.options?.timeout ?? DEFAULT_TIMEOUT_MS;
74462
+ const timeoutMs = request.options?.timeout ?? DEFAULT_TIMEOUT_MS2;
74390
74463
  const submitted = await withRetry(
74391
74464
  () => adapter.submit(binding.endpoint, finalParams, apiKey),
74392
74465
  { timeoutMs, provider: binding.provider, model: model.canonical_name }
@@ -74478,6 +74551,7 @@ export {
74478
74551
  RateLimitError,
74479
74552
  StorageError,
74480
74553
  configureAuth,
74554
+ configureFetch,
74481
74555
  klingAdapter,
74482
74556
  configureStorage,
74483
74557
  uploadAsset,
@@ -74490,4 +74564,4 @@ export {
74490
74564
  listModels,
74491
74565
  deriveCategory
74492
74566
  };
74493
- //# sourceMappingURL=chunk-3V2PDK26.js.map
74567
+ //# sourceMappingURL=chunk-QVQQFPOY.js.map