Skip to content

Canvix — Free & open-source graphic design tool. A community-built Canva alternative with a drag-and-drop editor, templates, shapes, text, images & one-click export. Works on desktop, tablet & mobile.

feat(v0.28.1): NVIDIA NIM provider support + live-model validation

Ashiq Hussain Mir688422f98a3b
diff --git a/.env.example b/.env.example
index c84ed11..30813c6 100644
--- a/.env.example
+++ b/.env.example
@@ -100,3 +100,15 @@ DATABASE_URL=postgresql://postgres.[YOUR-PROJECT-REF]:[YOUR-PASSWORD]@aws-0-eu-c
# uninstall) and plugin elements. Values:
# 1 | true | on. Default: off.
# CANVIX_PLUGINS=1
+
+# ── v0.28.1: OpenAI-compatible gateway model pins (self-hosters) ──
+# Point ZAI_BASE_URL at any OpenAI-compatible endpoint (NVIDIA NIM,
+# OpenRouter, vLLM, Ollama…) and pin per-slot model ids. DB config
+# still wins when present. Example (NVIDIA NIM, measured 2026-11):
+# ZAI_BASE_URL=https://integrate.api.nvidia.com/v1
+# ZAI_API_KEY=nvapi-…
+# ZAI_TEXT_MODEL=nvidia/nemotron-3-ultra-550b-a55b
+# ZAI_VISION_MODEL=nvidia/nemotron-3.5-super-vl-120b-a12b
+ZAI_TEXT_MODEL=
+ZAI_VISION_MODEL=
+ZAI_IMAGE_MODEL=
diff --git a/src/app/api/ai/agent/route.ts b/src/app/api/ai/agent/route.ts
index 46b328c..36d4938 100644
--- a/src/app/api/ai/agent/route.ts
+++ b/src/app/api/ai/agent/route.ts
@@ -56,6 +56,9 @@ interface RunBridge {
acks: ((ack: { ok: boolean; message?: string; design?: AgentDesignCtx }) => void)[]
/** brief validation result pushed by the client (Phase 5) */
briefResult: ((r: { satisfied: boolean; unmet: string[] } | null) => void) | null
+ /** briefResult that arrived before the loop asked (the panel answers
+ * immediately on seeing the action event) — consumed first */
+ pendingBriefResult: { satisfied: boolean; unmet: string[] } | null
/** the latest context the client pushed (after applying actions) */
latestDesign: AgentDesignCtx
/** client-abort flag (Stop button closes the stream; the route
@@ -106,6 +109,9 @@ async function __canvix_post(req: NextRequest) {
if (resolve) {
bridge.briefResult = null
resolve(body.briefResult)
+ } else if (body.briefResult) {
+ // early answer (loop not waiting yet) — queue it
+ bridge.pendingBriefResult = body.briefResult
}
}
return new Response(JSON.stringify({ ok: true }), { status: 200 })
@@ -228,6 +234,7 @@ async function __canvix_post(req: NextRequest) {
confirms: new Map(),
acks: [],
briefResult: null,
+ pendingBriefResult: null,
latestDesign: design,
aborted: false,
}
@@ -268,8 +275,14 @@ async function __canvix_post(req: NextRequest) {
setTimeout(() => resolve({ ok: true, message: 'ack timeout — assumed applied' }), 60_000)
}),
refreshedContext: () => bridge.latestDesign,
- validateBriefOnClient: () =>
- new Promise<{ satisfied: boolean; unmet: string[] } | null>((resolve) => {
+ validateBriefOnClient: async () => {
+ // consume an early answer first, then wait for a live one
+ if (bridge.pendingBriefResult) {
+ const r = bridge.pendingBriefResult
+ bridge.pendingBriefResult = null
+ return r
+ }
+ return new Promise<{ satisfied: boolean; unmet: string[] } | null>((resolve) => {
bridge.briefResult = resolve
// the client answers on the bridge; give it a generous
// window, then fall back to null (no client validation
@@ -280,7 +293,8 @@ async function __canvix_post(req: NextRequest) {
resolve(null)
}
}, 30_000)
- }),
+ })
+ },
})
} finally {
bridges.delete(runId)
diff --git a/src/lib/agent/harness.test.ts b/src/lib/agent/harness.test.ts
index a7a0550..1902c53 100644
--- a/src/lib/agent/harness.test.ts
+++ b/src/lib/agent/harness.test.ts
@@ -703,8 +703,10 @@ describe('harness · lifecycle flows (Cases A–F)', () => {
refreshedContext: () => design,
validateBriefOnClient: async () => ({ satisfied: true, unmet: [] }),
})
- // every write tool applied except the declined clear_page
- expect(result.toolCalls).toBe(valid.length - 1)
+ // every write tool applied except the declined clear_page; the
+ // validate_brief pseudo-action applies state without an ack and is
+ // not counted as a tool call (v0.28.1 live-eval fix)
+ expect(result.toolCalls).toBe(valid.length - 2)
expect(declined).toBe(true)
expect(result.summary).toBe('Sweep complete')
})
diff --git a/src/lib/agent/loop.ts b/src/lib/agent/loop.ts
index 7be3aaf..5675d28 100644
--- a/src/lib/agent/loop.ts
+++ b/src/lib/agent/loop.ts
@@ -349,6 +349,40 @@ export async function runAgentLoop(deps: LoopDeps): Promise<LoopResult> {
const args = (turn.args && typeof turn.args === 'object' && !Array.isArray(turn.args) ? turn.args : {}) as Record<string, unknown>
const result = tool.sanitize(args, toolCtx)
+ // validate_brief is a read-only pseudo-action: the client answers
+ // on the bridge (briefResult), so there is NO apply/ack round
+ // trip — awaiting one dropped the client's early answer (found by
+ // the live NIM eval: 60s ack timeout + lost validation result)
+ if (toolName === 'validate_brief' && deps.validateBriefOnClient) {
+ emit({
+ v: AGENT_PROTOCOL_VERSION,
+ type: 'action',
+ stepIndex: steps,
+ callId: `call-${steps}-${Math.random().toString(36).slice(2, 8)}`,
+ risk: 'read',
+ tool: toolName,
+ actions: result.ok ? result.actions : [],
+ })
+ const v = await deps.validateBriefOnClient()
+ steps += 1
+ markProgress()
+ if (v) {
+ const msg = v.satisfied
+ ? 'BRIEF VALIDATION PASSED — every mandatory text, color and dimension is present on the canvas. You may emit done.'
+ : `BRIEF VALIDATION FAILED — unmet requirements:\n${v.unmet.map((u) => `· ${u}`).join('\n')}\nFix these now, then re-validate.`
+ emit({ v: AGENT_PROTOCOL_VERSION, type: 'observation', stepIndex: steps - 1, message: msg })
+ messages.push({ role: 'user', content: msg })
+ if (v.satisfied) {
+ briefValidated = true
+ verification = 'Brief contract validated against the live canvas.'
+ }
+ } else {
+ emit({ v: AGENT_PROTOCOL_VERSION, type: 'observation', stepIndex: steps - 1, message: 'Brief validation unavailable on this client.' })
+ messages.push({ role: 'user', content: 'Brief validation was unavailable (no client response). Verify the required items yourself with get_page_state before finishing.' })
+ }
+ continue
+ }
+
// cycle detection: the identical call twice in a row is tolerated
// (a legitimate retry), the THIRD consecutive identical attempt
// wraps the run up BEFORE applying it — repeating the same
@@ -453,23 +487,6 @@ export async function runAgentLoop(deps: LoopDeps): Promise<LoopResult> {
continue
}
- // validate_brief: the client computed the result against real state
- if (toolName === 'validate_brief' && deps.validateBriefOnClient) {
- const v = await deps.validateBriefOnClient()
- if (v) {
- messages.push({
- role: 'user',
- content: v.satisfied
- ? 'BRIEF VALIDATION PASSED — every mandatory text, color and dimension is present on the canvas. You may emit done.'
- : `BRIEF VALIDATION FAILED — unmet requirements:\n${v.unmet.map((u) => `· ${u}`).join('\n')}\nFix these now, then re-validate.`,
- })
- if (v.satisfied) {
- briefValidated = true
- verification = 'Brief contract validated against the live canvas.'
- }
- }
- continue
- }
messages.push({ role: 'user', content: observationFor(toolName, result, true) })
diff --git a/src/lib/ai/provider.ts b/src/lib/ai/provider.ts
index e44cd96..cf5e5fc 100644
--- a/src/lib/ai/provider.ts
+++ b/src/lib/ai/provider.ts
@@ -220,8 +220,17 @@ export function pickSlot(
}
// legacy chain: the single override / env / file answers every slot,
// with the old ai.models ids still steering text/vision/image
+ // v0.28.1: env-level model ids — self-hosters pointing ZAI_BASE_URL at
+ // any OpenAI-compatible gateway (NVIDIA NIM, OpenRouter, vLLM, Ollama…)
+ // can pin per-slot models without a database. DB/models still win.
+ const envModelId =
+ slot === 'text' ? process.env.ZAI_TEXT_MODEL?.trim() :
+ slot === 'vision' ? process.env.ZAI_VISION_MODEL?.trim() :
+ slot === 'image' ? process.env.ZAI_IMAGE_MODEL?.trim() :
+ slot === 'imageEdit' ? process.env.ZAI_IMAGE_EDIT_MODEL?.trim() :
+ slot === 'video' ? process.env.ZAI_VIDEO_MODEL?.trim() : undefined
const legacyModel =
- slot === 'text' ? models.text : slot === 'vision' ? models.vision : slot === 'image' ? models.image : undefined
+ (slot === 'text' ? models.text : slot === 'vision' ? models.vision : slot === 'image' ? models.image : undefined) ?? envModelId
if (legacy) return { baseUrl: legacy.baseUrl, apiKey: legacy.apiKey, model: legacyModel, source: 'db' }
if (env.baseUrl && env.apiKey) {
return {