@almadar/integrations 2.34.0 → 2.36.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.
@@ -1,5 +1,5 @@
1
1
  import { g as IntegrationParams, I as IntegrationCallContext, d as IntegrationFactory } from '../BaseIntegration-BYlbMFlf.js';
2
- import { o as IntegrationName, m as IntegrationActionName, n as IntegrationContracts, e as CredentialStore } from '../store-DaPuMedl.js';
2
+ import { o as IntegrationName, m as IntegrationActionName, n as IntegrationContracts, e as CredentialStore } from '../store-OiFX0Tkn.js';
3
3
  import '@almadar/core';
4
4
 
5
5
  /**
@@ -162,7 +162,8 @@ var serviceCredentials = {
162
162
  ],
163
163
  rigger: [
164
164
  { envVar: "RIGGER_BASE_URL", required: false, description: "Local rigger service base URL (default http://127.0.0.1:8181)" },
165
- { envVar: "RIGGER_TIMEOUT_MS", required: false, description: "Per-request timeout (ms)" }
165
+ { envVar: "RIGGER_TIMEOUT_MS", required: false, description: "Per-request timeout (ms)" },
166
+ { envVar: "RIGGER_GENERATE_TIMEOUT_MS", required: false, description: "Timeout (ms) for the 'generate' action; a local z-image-turbo run takes ~60-90 s and a kontext edit at 1024px several minutes (default 600000)" }
166
167
  ]
167
168
  };
168
169
  function allCredentialEnvVars() {
@@ -5347,11 +5348,36 @@ registerIntegration("arxiv", ArxivIntegration);
5347
5348
  // src/integrations/rigger/index.ts
5348
5349
  var DEFAULT_BASE_URL = "http://127.0.0.1:8181";
5349
5350
  var DEFAULT_TIMEOUT_MS5 = 3e4;
5351
+ var DEFAULT_GENERATE_TIMEOUT_MS = 6e5;
5352
+ var GENERATE_MODELS = ["z-image-turbo", "kontext"];
5353
+ function generateParamErrors(params) {
5354
+ const errors = [];
5355
+ const model = params.model;
5356
+ if (typeof model !== "string" || !GENERATE_MODELS.includes(model)) {
5357
+ errors.push(`model must be one of ${GENERATE_MODELS.join(", ")}`);
5358
+ }
5359
+ if (model === "kontext" && (typeof params.sourcePath !== "string" || params.sourcePath === "")) {
5360
+ errors.push("sourcePath is required when model is kontext");
5361
+ }
5362
+ return errors;
5363
+ }
5364
+ async function riggerError(path, response) {
5365
+ let detail = "";
5366
+ try {
5367
+ const body = await response.json();
5368
+ if (typeof body.detail === "string") detail = body.detail;
5369
+ else if (body.detail !== void 0) detail = JSON.stringify(body.detail);
5370
+ } catch {
5371
+ detail = "";
5372
+ }
5373
+ return new Error(`Rigger ${path} returned ${response.status}${detail ? `: ${detail}` : ""}`);
5374
+ }
5350
5375
  var RiggerIntegration = class extends BaseIntegration {
5351
5376
  constructor(config) {
5352
5377
  super(config);
5353
5378
  this.baseUrl = config.env.RIGGER_BASE_URL || DEFAULT_BASE_URL;
5354
5379
  this.timeoutMs = Number(config.env.RIGGER_TIMEOUT_MS) || DEFAULT_TIMEOUT_MS5;
5380
+ this.generateTimeoutMs = Number(config.env.RIGGER_GENERATE_TIMEOUT_MS) || DEFAULT_GENERATE_TIMEOUT_MS;
5355
5381
  this.logger.info("Rigger integration initialized", { baseUrl: this.baseUrl });
5356
5382
  }
5357
5383
  async execute(action, params) {
@@ -5368,6 +5394,21 @@ var RiggerIntegration = class extends BaseIntegration {
5368
5394
  metadata: this.createMetadata(action, 0)
5369
5395
  };
5370
5396
  }
5397
+ if (action === "generate") {
5398
+ const invalid = generateParamErrors(params);
5399
+ if (invalid.length > 0) {
5400
+ return {
5401
+ success: false,
5402
+ error: {
5403
+ name: "IntegrationError",
5404
+ message: "Validation failed",
5405
+ code: "VALIDATION_ERROR",
5406
+ details: invalid
5407
+ },
5408
+ metadata: this.createMetadata(action, 0)
5409
+ };
5410
+ }
5411
+ }
5371
5412
  const startTime = Date.now();
5372
5413
  try {
5373
5414
  let data;
@@ -5381,6 +5422,27 @@ var RiggerIntegration = class extends BaseIntegration {
5381
5422
  case "render":
5382
5423
  data = await this.executeWithRetry(() => this.render(params));
5383
5424
  break;
5425
+ case "listPresets":
5426
+ data = await this.executeWithRetry(() => this.listPresets());
5427
+ break;
5428
+ case "loadRig":
5429
+ data = await this.executeWithRetry(() => this.loadRig(params));
5430
+ break;
5431
+ case "saveRig":
5432
+ data = await this.executeWithRetry(() => this.saveRig(params));
5433
+ break;
5434
+ case "ownership":
5435
+ data = await this.executeWithRetry(() => this.ownership(params));
5436
+ break;
5437
+ case "buildLayers":
5438
+ data = await this.executeWithRetry(() => this.buildLayers(params));
5439
+ break;
5440
+ case "pose":
5441
+ data = await this.executeWithRetry(() => this.pose(params));
5442
+ break;
5443
+ case "generate":
5444
+ data = await this.executeWithRetry(() => this.generate(params));
5445
+ break;
5384
5446
  default:
5385
5447
  throw new UnknownActionError(this.config.name, action);
5386
5448
  }
@@ -5408,22 +5470,109 @@ var RiggerIntegration = class extends BaseIntegration {
5408
5470
  signal: AbortSignal.timeout(this.timeoutMs)
5409
5471
  });
5410
5472
  if (!response.ok) {
5411
- throw new Error(`Rigger /mesh/build returned ${response.status}`);
5473
+ throw await riggerError("/mesh/build", response);
5412
5474
  }
5413
5475
  return await response.json();
5414
5476
  }
5415
5477
  async render(params) {
5416
- const { imagePath, rig, preset, outDir } = params;
5478
+ const { imagePath, rig, preset, outDir, mode, supersample } = params;
5417
5479
  const response = await fetch(`${this.baseUrl}/render`, {
5418
5480
  method: "POST",
5419
5481
  headers: { "Content-Type": "application/json" },
5420
- body: JSON.stringify({ imagePath, rig, preset, outDir }),
5482
+ body: JSON.stringify({ imagePath, rig, preset, outDir, mode, supersample }),
5421
5483
  signal: AbortSignal.timeout(this.timeoutMs)
5422
5484
  });
5423
5485
  if (!response.ok) {
5424
- throw new Error(`Rigger /render returned ${response.status}`);
5486
+ throw await riggerError("/render", response);
5425
5487
  }
5426
- return response.json();
5488
+ return await response.json();
5489
+ }
5490
+ async listPresets() {
5491
+ const response = await fetch(`${this.baseUrl}/presets`, {
5492
+ signal: AbortSignal.timeout(this.timeoutMs)
5493
+ });
5494
+ if (!response.ok) {
5495
+ throw await riggerError("/presets", response);
5496
+ }
5497
+ return await response.json();
5498
+ }
5499
+ async loadRig(params) {
5500
+ const { rigPath } = params;
5501
+ const response = await fetch(`${this.baseUrl}/rig/load`, {
5502
+ method: "POST",
5503
+ headers: { "Content-Type": "application/json" },
5504
+ body: JSON.stringify({ rigPath }),
5505
+ signal: AbortSignal.timeout(this.timeoutMs)
5506
+ });
5507
+ if (!response.ok) {
5508
+ throw await riggerError("/rig/load", response);
5509
+ }
5510
+ return await response.json();
5511
+ }
5512
+ async saveRig(params) {
5513
+ const { rigPath, rig } = params;
5514
+ const response = await fetch(`${this.baseUrl}/rig/save`, {
5515
+ method: "POST",
5516
+ headers: { "Content-Type": "application/json" },
5517
+ body: JSON.stringify({ rigPath, rig }),
5518
+ signal: AbortSignal.timeout(this.timeoutMs)
5519
+ });
5520
+ if (!response.ok) {
5521
+ throw await riggerError("/rig/save", response);
5522
+ }
5523
+ return await response.json();
5524
+ }
5525
+ async ownership(params) {
5526
+ const { imagePath, rig, outPath } = params;
5527
+ const response = await fetch(`${this.baseUrl}/ownership`, {
5528
+ method: "POST",
5529
+ headers: { "Content-Type": "application/json" },
5530
+ body: JSON.stringify({ imagePath, rig, outPath }),
5531
+ signal: AbortSignal.timeout(this.timeoutMs)
5532
+ });
5533
+ if (!response.ok) {
5534
+ throw await riggerError("/ownership", response);
5535
+ }
5536
+ return await response.json();
5537
+ }
5538
+ async buildLayers(params) {
5539
+ const { imagePath, rig, outDir } = params;
5540
+ const response = await fetch(`${this.baseUrl}/layers`, {
5541
+ method: "POST",
5542
+ headers: { "Content-Type": "application/json" },
5543
+ body: JSON.stringify({ imagePath, rig, outDir }),
5544
+ signal: AbortSignal.timeout(this.timeoutMs)
5545
+ });
5546
+ if (!response.ok) {
5547
+ throw await riggerError("/layers", response);
5548
+ }
5549
+ return await response.json();
5550
+ }
5551
+ async pose(params) {
5552
+ const { imagePath, rig, roles, preset, overrides } = params;
5553
+ const response = await fetch(`${this.baseUrl}/pose`, {
5554
+ method: "POST",
5555
+ headers: { "Content-Type": "application/json" },
5556
+ body: JSON.stringify({ imagePath, rig, roles, preset, overrides }),
5557
+ signal: AbortSignal.timeout(this.timeoutMs)
5558
+ });
5559
+ if (!response.ok) {
5560
+ throw await riggerError("/pose", response);
5561
+ }
5562
+ return await response.json();
5563
+ }
5564
+ async generate(params) {
5565
+ const { model, prompt, seed, size, steps, sourcePath, outDir } = params;
5566
+ const response = await fetch(`${this.baseUrl}/generate`, {
5567
+ method: "POST",
5568
+ headers: { "Content-Type": "application/json" },
5569
+ body: JSON.stringify({ model, prompt, seed, size, steps, sourcePath, outDir }),
5570
+ signal: AbortSignal.timeout(this.generateTimeoutMs)
5571
+ });
5572
+ if (!response.ok) {
5573
+ throw await riggerError("/generate", response);
5574
+ }
5575
+ return await response.json();
5427
5576
  }
5428
5577
  };
5429
5578
  registerIntegration("rigger", RiggerIntegration);
@@ -5487,28 +5636,41 @@ function createCallServiceHandler(factory) {
5487
5636
  }
5488
5637
 
5489
5638
  // src/runtime/RuntimeIntegrationManager.ts
5490
- function generateMockFromShape(shape) {
5491
- const data = {};
5492
- for (const [key, type] of Object.entries(shape)) {
5493
- switch (type) {
5639
+ function mockValueForDescriptor(key, descriptor) {
5640
+ if (typeof descriptor === "string") {
5641
+ if (descriptor.endsWith("[]")) return [];
5642
+ switch (descriptor) {
5494
5643
  case "string":
5495
- data[key] = `mock_${key}`;
5496
- break;
5644
+ return `mock_${key}`;
5497
5645
  case "number":
5498
- data[key] = 42;
5499
- break;
5646
+ return 42;
5500
5647
  case "boolean":
5501
- data[key] = true;
5502
- break;
5648
+ return true;
5503
5649
  case "object":
5504
- data[key] = {};
5505
- break;
5506
- case "string[]":
5507
- data[key] = [];
5508
- break;
5650
+ return {};
5509
5651
  default:
5510
- data[key] = `mock_${key}`;
5652
+ return `mock_${key}`;
5653
+ }
5654
+ }
5655
+ if (descriptor.type === "array") {
5656
+ return descriptor.items ? [mockValueForDescriptor(`${key}Item`, descriptor.items)] : [];
5657
+ }
5658
+ if (descriptor.properties) {
5659
+ const obj = {};
5660
+ for (const [propKey, propDescriptor] of Object.entries(descriptor.properties)) {
5661
+ obj[propKey] = mockValueForDescriptor(propKey, propDescriptor);
5511
5662
  }
5663
+ return obj;
5664
+ }
5665
+ if (descriptor.mapValue) {
5666
+ return { sample: mockValueForDescriptor("sample", descriptor.mapValue) };
5667
+ }
5668
+ return {};
5669
+ }
5670
+ function generateMockFromShape(shape) {
5671
+ const data = {};
5672
+ for (const [key, descriptor] of Object.entries(shape)) {
5673
+ data[key] = mockValueForDescriptor(key, descriptor);
5512
5674
  }
5513
5675
  return data;
5514
5676
  }