@auvira.ai/sdk 0.6.1 → 0.6.3
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.
- package/README.md +34 -3
- package/dist/agent/events.d.ts +16 -1
- package/dist/agent/events.d.ts.map +1 -1
- package/dist/agent/events.js.map +1 -1
- package/dist/agent/hostTools.d.ts +4 -0
- package/dist/agent/hostTools.d.ts.map +1 -1
- package/dist/agent/hostTools.js +8 -0
- package/dist/agent/hostTools.js.map +1 -1
- package/dist/agent/tools/toolConcurrency.d.ts +55 -0
- package/dist/agent/tools/toolConcurrency.d.ts.map +1 -0
- package/dist/agent/tools/toolConcurrency.js +136 -0
- package/dist/agent/tools/toolConcurrency.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/providers/agentic/agentLoop.d.ts.map +1 -1
- package/dist/providers/agentic/agentLoop.js +165 -49
- package/dist/providers/agentic/agentLoop.js.map +1 -1
- package/dist/runner/jobTypes.d.ts +1 -1
- package/dist/runner/jobTypes.d.ts.map +1 -1
- package/dist/runner/mapStreamEvents.d.ts.map +1 -1
- package/dist/runner/mapStreamEvents.js +22 -0
- package/dist/runner/mapStreamEvents.js.map +1 -1
- package/dist/util/apiThrottle.d.ts +5 -1
- package/dist/util/apiThrottle.d.ts.map +1 -1
- package/dist/util/apiThrottle.js +12 -44
- package/dist/util/apiThrottle.js.map +1 -1
- package/dist/util/minimaxImageClient.d.ts.map +1 -1
- package/dist/util/minimaxImageClient.js +3 -2
- package/dist/util/minimaxImageClient.js.map +1 -1
- package/dist/util/modelCallQueue.d.ts +38 -0
- package/dist/util/modelCallQueue.d.ts.map +1 -0
- package/dist/util/modelCallQueue.js +88 -0
- package/dist/util/modelCallQueue.js.map +1 -0
- package/docs/host-integration-image-placement.md +88 -0
- package/docs/sandbox-runner.md +6 -1
- package/package.json +3 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { sniffImageMime } from "../agent/tools/assetPathValidation.js";
|
|
3
3
|
import { postJsonWithRetry } from "./modelApiClient.js";
|
|
4
|
+
import { getGlobalModelCallQueue } from "./modelCallQueue.js";
|
|
4
5
|
const GLOBAL_IMAGE_BASE = "https://api.minimax.io/v1";
|
|
5
6
|
const CN_IMAGE_BASE = "https://api.minimaxi.com/v1";
|
|
6
7
|
/** Returns true when image generation is enabled (`AUVIRA_IMAGE_GEN_ENABLED=true`). */
|
|
@@ -73,7 +74,7 @@ async function callImageGeneration(input) {
|
|
|
73
74
|
if (input.subjectReference?.length) {
|
|
74
75
|
body.subject_reference = input.subjectReference;
|
|
75
76
|
}
|
|
76
|
-
const result = await postJsonWithRetry({
|
|
77
|
+
const result = await getGlobalModelCallQueue().run("image_generation", () => postJsonWithRetry({
|
|
77
78
|
url: `${baseUrl}/image_generation`,
|
|
78
79
|
headers: {
|
|
79
80
|
Authorization: `Bearer ${input.apiKey}`,
|
|
@@ -82,7 +83,7 @@ async function callImageGeneration(input) {
|
|
|
82
83
|
body,
|
|
83
84
|
timeoutMs: input.timeoutMs ?? 120_000,
|
|
84
85
|
signal: input.signal,
|
|
85
|
-
}, 0);
|
|
86
|
+
}, 0));
|
|
86
87
|
if (!result.ok || !result.data) {
|
|
87
88
|
const rateLimit = result.rateLimit;
|
|
88
89
|
throw new Error(rateLimit?.message ?? result.errorMessage ?? "Image generation request failed");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"minimaxImageClient.js","sourceRoot":"","sources":["../../src/util/minimaxImageClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAsB,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"minimaxImageClient.js","sourceRoot":"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W,IAAI,CAAC,CAAC;IAC3D,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,IAAI,SAAS,CAAC;IACjE,IAAI,UAAU,KAAK,CAAC,EAAE,CAAC;QACrB,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;YACxB,MAAM,IAAI,GAAkB;gBAC1B,aAAa,EAAE,IAAI;gBACnB,kBAAkB,EAAE,UAAU;gBAC9B,OAAO,EAAE,SAAS;gBAClB,OAAO,EAAE,EAAE;aACZ,CAAC;YACF,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,gBAAgB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,EAAE;gBACtE,SAAS,EAAE,IAAI;aAChB,CAAC,CAAC;QACL,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC;IAChD,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC1C,MAAM,QAAQ,GAAG,cAAc,CAAC,MAAM,CAAC,IAAI,WAAW,CAAC;IACvD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export interface ModelCallQueueOptions {
|
|
2
|
+
maxConcurrent?: number;
|
|
3
|
+
cooldownMs?: number;
|
|
4
|
+
}
|
|
5
|
+
/** Reads max concurrent API slots from env (primary + legacy aliases). Default 3. */
|
|
6
|
+
export declare function getApiMaxConcurrent(): number;
|
|
7
|
+
/** Reads API cooldown ms from env (primary + legacy aliases). Default 0. */
|
|
8
|
+
export declare function getApiCooldownMs(): number;
|
|
9
|
+
/** Global queue for all external model-like API calls (chat, evaluator, image, judges). */
|
|
10
|
+
export declare class ModelCallQueue {
|
|
11
|
+
private activeCalls;
|
|
12
|
+
private readonly waitQueue;
|
|
13
|
+
private readonly maxConcurrent;
|
|
14
|
+
private readonly cooldownMs;
|
|
15
|
+
constructor(options?: ModelCallQueueOptions);
|
|
16
|
+
/** Acquires a queue slot and returns fn result. Use when queue wait time is not needed. */
|
|
17
|
+
run<T>(label: string, fn: () => Promise<T>): Promise<T>;
|
|
18
|
+
/**
|
|
19
|
+
* Acquires a slot, measures wait time, invokes fn(queueWaitMs), returns result + wait.
|
|
20
|
+
* queueWaitMs is measured after slot acquire and before fn runs.
|
|
21
|
+
*/
|
|
22
|
+
runWithMetrics<T>(label: string, fn: (queueWaitMs: number) => Promise<T>): Promise<{
|
|
23
|
+
value: T;
|
|
24
|
+
queueWaitMs: number;
|
|
25
|
+
}>;
|
|
26
|
+
/** Returns current queue settings for diagnostics. */
|
|
27
|
+
getConfig(): {
|
|
28
|
+
maxConcurrent: number;
|
|
29
|
+
cooldownMs: number;
|
|
30
|
+
activeCalls: number;
|
|
31
|
+
queuedCalls: number;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** Shared queue for all external model-like API calls in this process. */
|
|
35
|
+
export declare function getGlobalModelCallQueue(): ModelCallQueue;
|
|
36
|
+
/** Resets the global queue (tests only). */
|
|
37
|
+
export declare function resetGlobalModelCallQueue(): void;
|
|
38
|
+
//# sourceMappingURL=modelCallQueue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modelCallQueue.d.ts","sourceRoot":"","sources":["../../src/util/modelCallQueue.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IACpC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAMD,qFAAqF;AACrF,wBAAgB,mBAAmB,IAAI,MAAM,CAQ5C;AAED,4EAA4E;AAC5E,wBAAgB,gBAAgB,IAAI,MAAM,CAQzC;AAED,2FAA2F;AAC3F,qBAAa,cAAc;IACzB,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAyB;IACnD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAExB,OAAO,GAAE,qBAA0B;IAK/C,2FAA2F;IACrF,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAK7D;;;OAGG;IACG,cAAc,CAAC,CAAC,EACpB,KAAK,EAAE,MAAM,EACb,EAAE,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GACtC,OAAO,CAAC;QAAE,KAAK,EAAE,CAAC,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IA+B7C,sDAAsD;IACtD,SAAS,IAAI;QACX,aAAa,EAAE,MAAM,CAAC;QACtB,UAAU,EAAE,MAAM,CAAC;QACnB,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC;KACrB;CAQF;AAID,0EAA0E;AAC1E,wBAAgB,uBAAuB,IAAI,cAAc,CAKxD;AAED,4CAA4C;AAC5C,wBAAgB,yBAAyB,IAAI,IAAI,CAEhD"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
function sleep(ms) {
|
|
2
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
3
|
+
}
|
|
4
|
+
/** Reads max concurrent API slots from env (primary + legacy aliases). Default 3. */
|
|
5
|
+
export function getApiMaxConcurrent() {
|
|
6
|
+
const raw = process.env.AUVIRA_API_MAX_CONCURRENT?.trim() ??
|
|
7
|
+
process.env.AUVIRA_MODEL_MAX_CONCURRENT?.trim() ??
|
|
8
|
+
process.env.CUSTOM_MODEL_MAX_CONCURRENT?.trim() ??
|
|
9
|
+
"3";
|
|
10
|
+
const parsed = Number(raw);
|
|
11
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : 3;
|
|
12
|
+
}
|
|
13
|
+
/** Reads API cooldown ms from env (primary + legacy aliases). Default 0. */
|
|
14
|
+
export function getApiCooldownMs() {
|
|
15
|
+
const raw = process.env.AUVIRA_API_COOLDOWN_MS?.trim() ??
|
|
16
|
+
process.env.AUVIRA_MODEL_API_COOLDOWN_MS?.trim() ??
|
|
17
|
+
process.env.CUSTOM_MODEL_API_COOLDOWN_MS?.trim() ??
|
|
18
|
+
"0";
|
|
19
|
+
const parsed = Number(raw);
|
|
20
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : 0;
|
|
21
|
+
}
|
|
22
|
+
/** Global queue for all external model-like API calls (chat, evaluator, image, judges). */
|
|
23
|
+
export class ModelCallQueue {
|
|
24
|
+
activeCalls = 0;
|
|
25
|
+
waitQueue = [];
|
|
26
|
+
maxConcurrent;
|
|
27
|
+
cooldownMs;
|
|
28
|
+
constructor(options = {}) {
|
|
29
|
+
this.maxConcurrent = options.maxConcurrent ?? getApiMaxConcurrent();
|
|
30
|
+
this.cooldownMs = options.cooldownMs ?? getApiCooldownMs();
|
|
31
|
+
}
|
|
32
|
+
/** Acquires a queue slot and returns fn result. Use when queue wait time is not needed. */
|
|
33
|
+
async run(label, fn) {
|
|
34
|
+
const { value } = await this.runWithMetrics(label, async () => fn());
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Acquires a slot, measures wait time, invokes fn(queueWaitMs), returns result + wait.
|
|
39
|
+
* queueWaitMs is measured after slot acquire and before fn runs.
|
|
40
|
+
*/
|
|
41
|
+
async runWithMetrics(label, fn) {
|
|
42
|
+
const queueStartedAt = Date.now();
|
|
43
|
+
while (this.activeCalls >= this.maxConcurrent) {
|
|
44
|
+
await new Promise((resolve) => this.waitQueue.push(resolve));
|
|
45
|
+
}
|
|
46
|
+
const queueWaitMs = Date.now() - queueStartedAt;
|
|
47
|
+
if (queueWaitMs > 1000) {
|
|
48
|
+
console.warn(`[auvira-agent] Waiting for API slot (${label}, ${queueWaitMs}ms, active=${this.activeCalls}/${this.maxConcurrent}).`);
|
|
49
|
+
}
|
|
50
|
+
this.activeCalls += 1;
|
|
51
|
+
try {
|
|
52
|
+
const value = await fn(queueWaitMs);
|
|
53
|
+
return { value, queueWaitMs };
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
this.activeCalls -= 1;
|
|
57
|
+
const next = this.waitQueue.shift();
|
|
58
|
+
if (next) {
|
|
59
|
+
next();
|
|
60
|
+
}
|
|
61
|
+
if (this.cooldownMs > 0) {
|
|
62
|
+
await sleep(this.cooldownMs);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** Returns current queue settings for diagnostics. */
|
|
67
|
+
getConfig() {
|
|
68
|
+
return {
|
|
69
|
+
maxConcurrent: this.maxConcurrent,
|
|
70
|
+
cooldownMs: this.cooldownMs,
|
|
71
|
+
activeCalls: this.activeCalls,
|
|
72
|
+
queuedCalls: this.waitQueue.length,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
let globalQueue;
|
|
77
|
+
/** Shared queue for all external model-like API calls in this process. */
|
|
78
|
+
export function getGlobalModelCallQueue() {
|
|
79
|
+
if (!globalQueue) {
|
|
80
|
+
globalQueue = new ModelCallQueue();
|
|
81
|
+
}
|
|
82
|
+
return globalQueue;
|
|
83
|
+
}
|
|
84
|
+
/** Resets the global queue (tests only). */
|
|
85
|
+
export function resetGlobalModelCallQueue() {
|
|
86
|
+
globalQueue = undefined;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=modelCallQueue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modelC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,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;YACpC,IAAI,IAAI,EAAE,CAAC;gBACT,IAAI,EAAE,CAAC;YACT,CAAC;YAED,IAAI,IAAI,CAAC,UAAU,GAAG,CAAC,EAAE,CAAC;gBACxB,MAAM,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;IACH,CAAC;IAED,sDAAsD;IACtD,SAAS;QAMP,OAAO;YACL,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM;SACnC,CAAC;IACJ,CAAC;CACF;AAED,IAAI,WAAuC,CAAC;AAE5C,0EAA0E;AAC1E,MAAM,UAAU,uBAAuB;IACrC,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,WAAW,GAAG,IAAI,cAAc,EAAE,CAAC;IACrC,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,4CAA4C;AAC5C,MAAM,UAAU,yBAAyB;IACvC,WAAW,GAAG,SAAS,CAAC;AAC1B,CAAC"}
|
|
@@ -15,6 +15,94 @@ This guide maps the generic image-placement architecture to **SDK APIs (v0.6+)**
|
|
|
15
15
|
| Vision bytes for model | Optional | `images[]` on send payload |
|
|
16
16
|
| Serializable multi-file completion | Configures | `completion.rules` |
|
|
17
17
|
| Built-in `get_attachment_urls` | Can override | Shipped generic tool |
|
|
18
|
+
| `classifyImageEditMode` / `runImageEditPipeline` | Yes — runs **before** `Agent.send` | No |
|
|
19
|
+
| Deterministic image applier + embedding verify/retry | Yes | No |
|
|
20
|
+
| Plan → Apply → Polish routing by intent | Yes | Speed + completion only |
|
|
21
|
+
|
|
22
|
+
## Plan → Apply → Polish (host-owned pipeline)
|
|
23
|
+
|
|
24
|
+
For fast image edits, the **host orchestrator runs before `Agent.send`**. It classifies intent, applies images deterministically when possible, and calls the SDK agent only for polish or full creative work. The SDK stays generic — it does not know `siteConfig`, placement targets, or applier logic.
|
|
25
|
+
|
|
26
|
+
```mermaid
|
|
27
|
+
flowchart TD
|
|
28
|
+
hostOrch[Host orchestrator before Agent.send]
|
|
29
|
+
direct[direct_embed]
|
|
30
|
+
plan[placement_plan]
|
|
31
|
+
style[embed_then_style]
|
|
32
|
+
creative[full_creative]
|
|
33
|
+
|
|
34
|
+
hostOrch --> direct
|
|
35
|
+
hostOrch --> plan
|
|
36
|
+
hostOrch --> style
|
|
37
|
+
hostOrch --> creative
|
|
38
|
+
|
|
39
|
+
direct --> hostApply1[Host deterministic applier]
|
|
40
|
+
plan --> hostPlan[Host JSON plan call]
|
|
41
|
+
hostPlan --> hostApply2[Host deterministic applier]
|
|
42
|
+
style --> hostApply3[Host deterministic applier]
|
|
43
|
+
style --> sdkPolish[SDK agent polish pass]
|
|
44
|
+
creative --> sdkAgent[SDK full agentic loop]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
| Mode | Host responsibility | SDK involvement |
|
|
48
|
+
| --- | --- | --- |
|
|
49
|
+
| **`direct_embed`** | Deterministic applier; **0 agent tools**; usually **no `Agent.send`** | Attachments / completion types only if a follow-up turn is needed |
|
|
50
|
+
| **`placement_plan`** | One JSON planning call (host LLM + schema); deterministic applier; **no SDK agentic file tools** | Not required for planning (host may use its own LLM client) |
|
|
51
|
+
| **`embed_then_style`** | Deterministic apply first (image URL already wired) | Short polish/style `Agent.send`; `completion.rules` must keep the wired URL present |
|
|
52
|
+
| **`full_creative`** | Classify + optional pre-context | Full agentic loop; v0.6.2 parallel read batches speed discovery |
|
|
53
|
+
|
|
54
|
+
**SDK owns:** attachments, host tools, completion rules, agentic loop, API queue, parallel read-only tools.
|
|
55
|
+
|
|
56
|
+
**Host owns:** image classification, placement mapping, deterministic applying, embedding verification, retry logic.
|
|
57
|
+
|
|
58
|
+
### Example: `embed_then_style` polish pass
|
|
59
|
+
|
|
60
|
+
After the host applies the image (no agent file tools), call the SDK for animation/style only. Most consumers wire hero URLs in `siteConfig.ts`; some use `page.tsx` or a component — tune `pathPattern` to your repo.
|
|
61
|
+
|
|
62
|
+
**Recommended:** inject the exact URL the host just wired — strongest gate for the polish pass:
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
const uploadedImagePublicUrl = attachments[0].publicUrl; // e.g. "/uploads/hero-abc.png"
|
|
66
|
+
|
|
67
|
+
function escapeRegex(value: string): string {
|
|
68
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
await agent.send(
|
|
72
|
+
{
|
|
73
|
+
text: styleOnWiredBaselinePrompt, // host-owned
|
|
74
|
+
attachments, // already wired by host applier
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
completion: {
|
|
78
|
+
mode: "multi_file_required",
|
|
79
|
+
multiStep: { minToolCalls: 1, maxExtraTurnsAfterStyleOnly: 2 },
|
|
80
|
+
rules: {
|
|
81
|
+
requiredContent: [
|
|
82
|
+
{
|
|
83
|
+
// siteConfig.ts is the common case; extend for inline page/component wiring
|
|
84
|
+
pathPattern: "(siteConfig\\.ts|page\\.tsx|.*components/.*\\.(tsx|ts))",
|
|
85
|
+
contentPattern: escapeRegex(uploadedImagePublicUrl),
|
|
86
|
+
nudge: `Keep the wired image URL ${uploadedImagePublicUrl}; add animation/style only.`,
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Alternative** (prefix-only, when `/uploads/` or `/assets/` is enough):
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
contentPattern: 'backgroundImageUrl\\s*:\\s*["\']/(uploads|assets)/',
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
For **`full_creative`**, use the normal agentic path with tuned `completion.rules`. v0.6.2 parallel read tools (`grep`, `read`, `glob`, etc.) reduce discovery latency when the model batches exploration.
|
|
102
|
+
|
|
103
|
+
**Not in SDK:** `classifyImageEditMode`, `runImageEditPipeline`, `ImagePlacementTarget`, `applyImageToConfig`, embedding verification, or gallery `ImagePlacementPlan` replacement — implement these in the consumer repo.
|
|
104
|
+
|
|
105
|
+
**Optional later:** a generic `planOnly` send mode (single structured JSON call, no tool loop) if the host wants to drop duplicated planner LLM client code. Defer until the consumer pipeline proves that need.
|
|
18
106
|
|
|
19
107
|
## Layer 1 — Attachments vs vision images
|
|
20
108
|
|
package/docs/sandbox-runner.md
CHANGED
|
@@ -75,6 +75,9 @@ auvira-sdk-run --job <editJobId>
|
|
|
75
75
|
| `AUVIRA_IMAGE_GEN_MAX_PER_RUN` | No | Max image generations per run (default `2`) |
|
|
76
76
|
| `AUVIRA_IMAGE_BASE_URL` | No | Override image API base (default global `api.minimax.io/v1` or CN from chat host) |
|
|
77
77
|
| `AUVIRA_IMAGE_MODEL` | No | Image model id (default `image-01`) |
|
|
78
|
+
| `AUVIRA_PARALLEL_READ_TOOLS` | No | Parallelize read-only tool batches (default `true`) |
|
|
79
|
+
| `AUVIRA_MAX_PARALLEL_READ_TOOLS` | No | Max concurrent read tools per batch (default `8`) |
|
|
80
|
+
| `AUVIRA_API_MAX_CONCURRENT` | No | Global in-flight limit for external API calls — chat, evaluator, image gen (default `3`; aliases: `AUVIRA_MODEL_MAX_CONCURRENT`, `CUSTOM_MODEL_MAX_CONCURRENT`) |
|
|
78
81
|
|
|
79
82
|
`CUSTOM_MODEL_API_KEY` is read from the environment only — never from `job.json`.
|
|
80
83
|
|
|
@@ -134,7 +137,9 @@ auvira-sdk-run --job <editJobId>
|
|
|
134
137
|
- `hostTools` are **not** supported in `job.json` v1 — register them in-process via `Agent.create` / `Agent.send`.
|
|
135
138
|
- `model.apiKey` is rejected by the validator.
|
|
136
139
|
|
|
137
|
-
See [host-integration-image-placement.md](./host-integration-image-placement.md) for the full SDK vs website-repo split.
|
|
140
|
+
See [host-integration-image-placement.md](./host-integration-image-placement.md) for the full SDK vs website-repo split, including the **Plan → Apply → Polish** host pipeline (`direct_embed`, `placement_plan`, `embed_then_style`, `full_creative`).
|
|
141
|
+
|
|
142
|
+
For image edits routed by the host orchestrator: Cases 1–3 (deterministic apply / plan-then-apply) typically **do not** spawn a sandbox job or call `Agent.send`. Case 4 (`full_creative`) uses this runner; v0.6.2 parallel read tools and `AUVIRA_API_MAX_CONCURRENT` apply inside the VM the same as in-process runs.
|
|
138
143
|
|
|
139
144
|
## Result (`SandboxAuviraJobResult`)
|
|
140
145
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auvira.ai/sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"description": "Cursor-SDK-compatible visual coding agent with custom model support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -42,13 +42,14 @@
|
|
|
42
42
|
"test:flex": "node --env-file=.env ./node_modules/vitest/vitest.mjs run src/__tests__/flex",
|
|
43
43
|
"test:flex:unit": "node --env-file=.env ./node_modules/vitest/vitest.mjs run src/__tests__/flex --exclude 'src/__tests__/flex/real-*.e2e.test.ts'",
|
|
44
44
|
"test:real": "node --env-file=.env ./node_modules/vitest/vitest.mjs run src/__tests__/real src/__tests__/flex/real-*.e2e.test.ts src/__tests__/runner/run-cli.real.e2e.test.ts",
|
|
45
|
+
"test:real:smoke": "node --env-file=.env ./node_modules/vitest/vitest.mjs run src/__tests__/real/minimax-api.test.ts src/__tests__/real/agent-run-stream.e2e.test.ts src/__tests__/real/agent-parallel-read-tools.e2e.test.ts",
|
|
45
46
|
"test:runner": "node --env-file=.env ./node_modules/vitest/vitest.mjs run src/__tests__/runner --exclude 'src/__tests__/runner/**/*.real.e2e.test.ts'",
|
|
46
47
|
"test:runner:real": "node --env-file=.env ./node_modules/vitest/vitest.mjs run src/__tests__/runner/run-cli.real.e2e.test.ts src/__tests__/runner/run-cli-vibe-consumer.real.e2e.test.ts",
|
|
47
48
|
"test:runner:asset": "AUVIRA_REAL_ASSET_E2E=true node --env-file=.env ./node_modules/vitest/vitest.mjs run src/__tests__/runner/run-cli-asset.real.e2e.test.ts",
|
|
48
49
|
"test:runner:image-gen": "AUVIRA_REAL_IMAGE_GEN_E2E=true AUVIRA_IMAGE_GEN_ENABLED=true node --env-file=.env ./node_modules/vitest/vitest.mjs run src/__tests__/runner/run-cli-generate-image.real.e2e.test.ts",
|
|
49
50
|
"test:real:image-api": "AUVIRA_REAL_IMAGE_API=true AUVIRA_IMAGE_GEN_ENABLED=true node --env-file=.env ./node_modules/vitest/vitest.mjs run src/__tests__/real/minimax-image-api.real.test.ts",
|
|
50
51
|
"test:real:multi-image": "AUVIRA_REAL_MULTI_IMAGE_E2E=true node --env-file=.env ./node_modules/vitest/vitest.mjs run src/__tests__/real/agent-multi-image.e2e.test.ts src/__tests__/runner/run-cli-multi-image.real.e2e.test.ts",
|
|
51
|
-
"test:real:attachment-placement": "AUVIRA_REAL_ATTACHMENT_E2E=true node --env-file=.env ./node_modules/vitest/vitest.mjs run src/__tests__/real/agent-attachment-placement.e2e.test.ts src/__tests__/runner/run-cli-attachment-placement.real.e2e.test.ts",
|
|
52
|
+
"test:real:attachment-placement": "AUVIRA_REAL_ATTACHMENT_E2E=true node --env-file=.env ./node_modules/vitest/vitest.mjs run src/__tests__/real/agent-attachment-placement.e2e.test.ts src/__tests__/real/agent-attachment-animation.e2e.test.ts src/__tests__/runner/run-cli-attachment-placement.real.e2e.test.ts",
|
|
52
53
|
"test:runner:vibe": "node --env-file=.env ./node_modules/vitest/vitest.mjs run src/__tests__/runner/run-cli-vibe-consumer.real.e2e.test.ts"
|
|
53
54
|
},
|
|
54
55
|
"keywords": [
|