@ggui-ai/ui-gen 0.9.0 → 0.10.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.
- package/dist/adapters/generation-dispatch.d.ts +9 -2
- package/dist/adapters/generation-dispatch.js +547 -85
- package/dist/adapters/generation-dispatch.js.map +1 -1
- package/dist/adapters/index.js +28 -11
- package/dist/adapters/index.js.map +1 -1
- package/dist/advanced/index.d.ts +5 -3
- package/dist/advanced/index.js +563 -92
- package/dist/advanced/index.js.map +1 -1
- package/dist/blueprint-validator.js +109 -3
- package/dist/blueprint-validator.js.map +1 -1
- package/dist/boilerplate.js +14 -2
- package/dist/boilerplate.js.map +1 -1
- package/dist/check/index.d.ts +1 -1
- package/dist/check/index.js +11 -1
- package/dist/check/index.js.map +1 -1
- package/dist/{create-ui-generator-B9kV4U9h.d.ts → create-ui-generator-CF0EL0Li.d.ts} +13 -1
- package/dist/{dispatch-Deo9qzrG.d.ts → dispatch-D75M-OfZ.d.ts} +1 -1
- package/dist/evaluation/axis-checks/index.d.ts +3 -3
- package/dist/evaluation/axis-checks/index.js +101 -0
- package/dist/evaluation/axis-checks/index.js.map +1 -1
- package/dist/evaluation/axis-checks/registry.d.ts +1 -1
- package/dist/evaluation/axis-checks/registry.js +101 -0
- package/dist/evaluation/axis-checks/registry.js.map +1 -1
- package/dist/evaluation/index.d.ts +46 -3
- package/dist/evaluation/index.js +358 -17
- package/dist/evaluation/index.js.map +1 -1
- package/dist/harness/check/runtime-render/index.d.ts +2 -2
- package/dist/harness/check/runtime-render/index.js +110 -3
- package/dist/harness/check/runtime-render/index.js.map +1 -1
- package/dist/harness/index.d.ts +2 -2
- package/dist/harness/index.js +263 -18
- package/dist/harness/index.js.map +1 -1
- package/dist/harness/llm-trace-sink.d.ts +1 -1
- package/dist/harness/llm-trace-sink.js.map +1 -1
- package/dist/harness/prompts.js +17 -3
- package/dist/harness/prompts.js.map +1 -1
- package/dist/harness/result-types.d.ts +1 -1
- package/dist/harness/runtime.d.ts +9 -2
- package/dist/harness/runtime.js +20 -6
- package/dist/harness/runtime.js.map +1 -1
- package/dist/harness/types-public.d.ts +1 -1
- package/dist/harness/types-public.js +14 -2
- package/dist/harness/types-public.js.map +1 -1
- package/dist/harness/validator-trace-sink.d.ts +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +563 -92
- package/dist/index.js.map +1 -1
- package/dist/{llm-router-1TyI0_TV.d.ts → llm-router-BEVtbAb9.d.ts} +61 -4
- package/dist/patch.d.ts +1 -1
- package/dist/provider-adapter.d.ts +16 -6
- package/dist/provider-adapter.js.map +1 -1
- package/dist/providers/index.d.ts +19 -6
- package/dist/providers/index.js.map +1 -1
- package/dist/{render-check-CNZjHD5g.d.ts → render-check-BNYGVDJd.d.ts} +1 -1
- package/dist/{types-public-C36k1q6s.d.ts → types-public-DIpjC-OA.d.ts} +1 -1
- package/dist/workflows.d.ts +1 -1
- package/package.json +12 -12
- package/src/adapters/generation-dispatch.ts +9 -0
- package/src/adapters/openrouter/client.ts +2 -2
- package/src/adapters/openrouter/types.ts +10 -0
- package/src/boilerplate/generate.ts +10 -2
- package/src/boilerplate/json-schema-ts.ts +22 -2
- package/src/boilerplate/system-prompt.ts +1 -0
- package/src/compile.ts +1 -1
- package/src/contract-context.ts +10 -2
- package/src/create-ui-generator.ts +14 -0
- package/src/design-system-docs.ts +6 -4
- package/src/evaluation/axis-checks/checks/state-ui-affordance.ts +162 -0
- package/src/evaluation/axis-checks/registry.ts +2 -0
- package/src/evaluation/index.ts +11 -0
- package/src/evaluation/llm-evaluator.ts +14 -1
- package/src/evaluation/visual-evaluator.ts +44 -65
- package/src/harness/check/runtime-render/adapter.ts +18 -0
- package/src/harness/check/runtime-render/index.ts +8 -0
- package/src/harness/check/runtime-render/prepare-mockup.ts +14 -0
- package/src/harness/check/runtime-render/production-act-shim.ts +158 -0
- package/src/harness/check/runtime-render/render-check.ts +72 -1
- package/src/harness/coding/run-eval-round.ts +61 -5
- package/src/harness/index.ts +1 -1
- package/src/harness/llm-router.ts +397 -18
- package/src/harness/llm-trace-sink.ts +2 -1
- package/src/harness/runtime.ts +7 -0
- package/src/index.ts +5 -5
- package/src/provider-adapter.ts +16 -6
- package/src/providers/bedrock.ts +5 -4
- package/src/providers/index.ts +16 -4
- package/src/tools/render-check.ts +19 -7
package/dist/advanced/index.js
CHANGED
|
@@ -1154,14 +1154,16 @@ var OpenRouterError;
|
|
|
1154
1154
|
var init_types = __esm({
|
|
1155
1155
|
"src/adapters/openrouter/types.ts"() {
|
|
1156
1156
|
OpenRouterError = class extends Error {
|
|
1157
|
-
constructor(message, status, code) {
|
|
1157
|
+
constructor(message, status, code, headers) {
|
|
1158
1158
|
super(message);
|
|
1159
1159
|
this.status = status;
|
|
1160
1160
|
this.code = code;
|
|
1161
|
+
this.headers = headers;
|
|
1161
1162
|
this.name = "OpenRouterError";
|
|
1162
1163
|
}
|
|
1163
1164
|
status;
|
|
1164
1165
|
code;
|
|
1166
|
+
headers;
|
|
1165
1167
|
get isTransient() {
|
|
1166
1168
|
return this.status === 408 || this.status === 429 || this.status === 502 || this.status === 503;
|
|
1167
1169
|
}
|
|
@@ -1206,7 +1208,7 @@ var init_client2 = __esm({
|
|
|
1206
1208
|
if (!response.ok) {
|
|
1207
1209
|
const errorBody = await response.json().catch(() => ({ error: { message: response.statusText } }));
|
|
1208
1210
|
const message = errorBody.error?.message ?? response.statusText;
|
|
1209
|
-
throw new OpenRouterError(message, response.status);
|
|
1211
|
+
throw new OpenRouterError(message, response.status, void 0, response.headers);
|
|
1210
1212
|
}
|
|
1211
1213
|
return response.json();
|
|
1212
1214
|
}
|
|
@@ -1224,7 +1226,7 @@ var init_client2 = __esm({
|
|
|
1224
1226
|
if (!response.ok) {
|
|
1225
1227
|
const errorBody = await response.json().catch(() => ({ error: { message: response.statusText } }));
|
|
1226
1228
|
const message = errorBody.error?.message ?? response.statusText;
|
|
1227
|
-
throw new OpenRouterError(message, response.status);
|
|
1229
|
+
throw new OpenRouterError(message, response.status, void 0, response.headers);
|
|
1228
1230
|
}
|
|
1229
1231
|
if (!response.body) {
|
|
1230
1232
|
throw new OpenRouterError("No response body for streaming request", 500);
|
|
@@ -2077,6 +2079,15 @@ function jsonSchemaTypeToTs(schema) {
|
|
|
2077
2079
|
if (schema.enum?.length) {
|
|
2078
2080
|
return schema.enum.map((v) => typeof v === "string" ? `'${v}'` : String(v)).join(" | ");
|
|
2079
2081
|
}
|
|
2082
|
+
if (Array.isArray(schema.type)) {
|
|
2083
|
+
const { nullable: _nullable, ...rest } = schema;
|
|
2084
|
+
const members = [...new Set(schema.type)].map(
|
|
2085
|
+
(member) => jsonSchemaTypeToTs({ ...rest, type: member })
|
|
2086
|
+
);
|
|
2087
|
+
const unique = [...new Set(members)];
|
|
2088
|
+
if (schema.nullable && !unique.includes("null")) unique.push("null");
|
|
2089
|
+
return unique.join(" | ");
|
|
2090
|
+
}
|
|
2080
2091
|
let result;
|
|
2081
2092
|
switch (schema.type) {
|
|
2082
2093
|
case "string":
|
|
@@ -2094,7 +2105,8 @@ function jsonSchemaTypeToTs(schema) {
|
|
|
2094
2105
|
case "array": {
|
|
2095
2106
|
if (schema.items) {
|
|
2096
2107
|
const itemType = jsonSchemaTypeToTs(schema.items);
|
|
2097
|
-
|
|
2108
|
+
const itemsDeclareObject = Array.isArray(schema.items.type) ? schema.items.type.includes("object") : schema.items.type === "object";
|
|
2109
|
+
result = itemsDeclareObject && schema.items.properties ? `Array<${itemType}>` : itemType.includes("|") ? `(${itemType})[]` : `${itemType}[]`;
|
|
2098
2110
|
} else {
|
|
2099
2111
|
result = "unknown[]";
|
|
2100
2112
|
}
|
|
@@ -4112,6 +4124,29 @@ function errorSummary(e) {
|
|
|
4112
4124
|
}
|
|
4113
4125
|
return `${e.constructor.name}${status}${code}: ${e.message.slice(0, 120)}${body}`;
|
|
4114
4126
|
}
|
|
4127
|
+
function isRateLimited(e) {
|
|
4128
|
+
if (!(e instanceof Error) || !("status" in e)) return false;
|
|
4129
|
+
return e.status === 429;
|
|
4130
|
+
}
|
|
4131
|
+
function extractStatus(e) {
|
|
4132
|
+
if (!(e instanceof Error) || !("status" in e)) return void 0;
|
|
4133
|
+
const status = e.status;
|
|
4134
|
+
return typeof status === "number" ? status : void 0;
|
|
4135
|
+
}
|
|
4136
|
+
function extractRetryAfterSec(e) {
|
|
4137
|
+
if (!(e instanceof Error) || !("headers" in e)) return void 0;
|
|
4138
|
+
const headers = e.headers;
|
|
4139
|
+
if (headers === null || typeof headers !== "object" || !("get" in headers) || typeof headers.get !== "function") {
|
|
4140
|
+
return void 0;
|
|
4141
|
+
}
|
|
4142
|
+
const raw = headers.get("retry-after");
|
|
4143
|
+
if (raw === null) return void 0;
|
|
4144
|
+
const parsed = Number(raw);
|
|
4145
|
+
return Number.isFinite(parsed) && parsed >= 0 ? Math.floor(parsed) : void 0;
|
|
4146
|
+
}
|
|
4147
|
+
function sleep(ms) {
|
|
4148
|
+
return new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
4149
|
+
}
|
|
4115
4150
|
function interactionText(interaction) {
|
|
4116
4151
|
let text = "";
|
|
4117
4152
|
for (const step of interaction.steps ?? []) {
|
|
@@ -4136,24 +4171,38 @@ function toUserInputStep(text) {
|
|
|
4136
4171
|
function createAgent(providerOrConfig) {
|
|
4137
4172
|
const provider = typeof providerOrConfig === "string" ? providerOrConfig : providerOrConfig.provider;
|
|
4138
4173
|
const routeOverride = typeof providerOrConfig === "string" ? void 0 : providerOrConfig.routeOverride;
|
|
4174
|
+
const onRetry = typeof providerOrConfig === "string" ? void 0 : providerOrConfig.onRetry;
|
|
4139
4175
|
switch (provider) {
|
|
4140
4176
|
case "anthropic":
|
|
4141
|
-
return new AnthropicAgent(routeOverride);
|
|
4177
|
+
return new AnthropicAgent(routeOverride, onRetry);
|
|
4142
4178
|
case "openai":
|
|
4143
|
-
return new OpenAIAgent(routeOverride);
|
|
4179
|
+
return new OpenAIAgent(routeOverride, onRetry);
|
|
4144
4180
|
case "google":
|
|
4145
|
-
return new GoogleAgent(routeOverride);
|
|
4181
|
+
return new GoogleAgent(routeOverride, onRetry);
|
|
4146
4182
|
case "openrouter":
|
|
4147
|
-
return new OpenRouterAgent(routeOverride);
|
|
4183
|
+
return new OpenRouterAgent(routeOverride, onRetry);
|
|
4148
4184
|
}
|
|
4149
4185
|
}
|
|
4150
|
-
|
|
4186
|
+
function createVisionAgent(config) {
|
|
4187
|
+
switch (config.provider) {
|
|
4188
|
+
case "anthropic":
|
|
4189
|
+
return new AnthropicAgent(config.routeOverride, config.onRetry);
|
|
4190
|
+
case "google":
|
|
4191
|
+
return new GoogleAgent(config.routeOverride, config.onRetry);
|
|
4192
|
+
}
|
|
4193
|
+
}
|
|
4194
|
+
var MAX_RETRY_ATTEMPTS, RETRY_AFTER_CAP_SEC, DEFAULT_BACKOFF_BASE_MS, DEFAULT_BACKOFF_MAX_MS, MAX_TOTAL_RETRY_DELAY_MS, LLMAgent, AnthropicAgent, OpenAIAgent, GoogleAgent, OpenRouterAgent;
|
|
4151
4195
|
var init_llm_router = __esm({
|
|
4152
4196
|
"src/harness/llm-router.ts"() {
|
|
4153
4197
|
init_client();
|
|
4154
4198
|
init_provider_router();
|
|
4155
4199
|
init_tool_bridge();
|
|
4156
4200
|
init_llm_trace_sink();
|
|
4201
|
+
MAX_RETRY_ATTEMPTS = 2;
|
|
4202
|
+
RETRY_AFTER_CAP_SEC = 15;
|
|
4203
|
+
DEFAULT_BACKOFF_BASE_MS = 1e3;
|
|
4204
|
+
DEFAULT_BACKOFF_MAX_MS = 8e3;
|
|
4205
|
+
MAX_TOTAL_RETRY_DELAY_MS = 2e4;
|
|
4157
4206
|
LLMAgent = class {
|
|
4158
4207
|
client = null;
|
|
4159
4208
|
// ── Session state for server-side chaining ──────────────
|
|
@@ -4168,8 +4217,11 @@ var init_llm_router = __esm({
|
|
|
4168
4217
|
* back to `process.env` exactly as before.
|
|
4169
4218
|
*/
|
|
4170
4219
|
routeOverride;
|
|
4171
|
-
|
|
4220
|
+
/** See `AgentConfig.onRetry` (#489). Absent is a no-op. */
|
|
4221
|
+
onRetry;
|
|
4222
|
+
constructor(routeOverride, onRetry) {
|
|
4172
4223
|
this.routeOverride = routeOverride;
|
|
4224
|
+
this.onRetry = onRetry;
|
|
4173
4225
|
}
|
|
4174
4226
|
async getClient() {
|
|
4175
4227
|
if (!this.client) {
|
|
@@ -4204,17 +4256,83 @@ var init_llm_router = __esm({
|
|
|
4204
4256
|
async sendToolResult(_results) {
|
|
4205
4257
|
}
|
|
4206
4258
|
/**
|
|
4207
|
-
* Execute an API call
|
|
4208
|
-
*
|
|
4259
|
+
* Execute an API call, retrying once or twice on HTTP 429
|
|
4260
|
+
* (rate-limited) before giving up (#489).
|
|
4261
|
+
*
|
|
4262
|
+
* Policy: on a 429, honor the provider's `Retry-After` header when
|
|
4263
|
+
* present (capped at `RETRY_AFTER_CAP_SEC` — a provider asking for a
|
|
4264
|
+
* longer wait is treated as "don't retry", not "wait longer": making
|
|
4265
|
+
* the caller sit through 15+ more seconds on a single failed call is
|
|
4266
|
+
* a bad experience regardless of what's driving the request);
|
|
4267
|
+
* otherwise fall back to exponential backoff with jitter, capped at
|
|
4268
|
+
* `DEFAULT_BACKOFF_MAX_MS` per attempt. Stops after
|
|
4269
|
+
* `MAX_RETRY_ATTEMPTS` retries OR once the cumulative delay would
|
|
4270
|
+
* exceed `MAX_TOTAL_RETRY_DELAY_MS`, whichever comes first. Any
|
|
4271
|
+
* non-429 error, or a 429 with no attempts left, is logged and
|
|
4272
|
+
* re-thrown immediately — unchanged from the pre-#489 behavior.
|
|
4273
|
+
*
|
|
4274
|
+
* **Budget scope (final-review correction):** `MAX_TOTAL_RETRY_DELAY_MS`
|
|
4275
|
+
* bounds a single `apiCall()` invocation, not a whole generation. A
|
|
4276
|
+
* generation issues many sequential `apiCall()` calls (coding turns,
|
|
4277
|
+
* tool-result round-trips, eval rounds); under sustained throttling
|
|
4278
|
+
* each one can independently add up to `MAX_TOTAL_RETRY_DELAY_MS`, so
|
|
4279
|
+
* a generation with k rate-limited calls can add up to roughly `k *
|
|
4280
|
+
* MAX_TOTAL_RETRY_DELAY_MS` to how long it holds its caller's
|
|
4281
|
+
* resources (e.g. the caller's concurrency slot) — not a flat 20s
|
|
4282
|
+
* ceiling. No shared per-generation budget is threaded here by
|
|
4283
|
+
* design (accepted ruling, not an oversight): the caller's own
|
|
4284
|
+
* queue/admission backstop is what bounds how long other
|
|
4285
|
+
* queued work waits, independent of any one generation's retry
|
|
4286
|
+
* total.
|
|
4209
4287
|
*/
|
|
4210
4288
|
async apiCall(fn) {
|
|
4211
4289
|
const start = Date.now();
|
|
4212
|
-
|
|
4213
|
-
|
|
4214
|
-
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4290
|
+
let totalDelayMs = 0;
|
|
4291
|
+
for (let attempt = 0; ; attempt++) {
|
|
4292
|
+
try {
|
|
4293
|
+
return await fn();
|
|
4294
|
+
} catch (e) {
|
|
4295
|
+
const ms = Date.now() - start;
|
|
4296
|
+
if (attempt >= MAX_RETRY_ATTEMPTS || !isRateLimited(e)) {
|
|
4297
|
+
console.error(`[${this.provider}] API error after ${ms}ms: ${errorSummary(e)}`);
|
|
4298
|
+
throw e;
|
|
4299
|
+
}
|
|
4300
|
+
const retryAfterSec = extractRetryAfterSec(e);
|
|
4301
|
+
if (retryAfterSec !== void 0 && retryAfterSec > RETRY_AFTER_CAP_SEC) {
|
|
4302
|
+
console.error(
|
|
4303
|
+
`[${this.provider}] API error after ${ms}ms (retry-after ${retryAfterSec}s exceeds ${RETRY_AFTER_CAP_SEC}s cap, not retrying): ${errorSummary(e)}`
|
|
4304
|
+
);
|
|
4305
|
+
throw e;
|
|
4306
|
+
}
|
|
4307
|
+
const delayMs = retryAfterSec !== void 0 ? retryAfterSec * 1e3 : Math.min(DEFAULT_BACKOFF_BASE_MS * 2 ** attempt, DEFAULT_BACKOFF_MAX_MS) + Math.floor(Math.random() * 250);
|
|
4308
|
+
if (totalDelayMs + delayMs > MAX_TOTAL_RETRY_DELAY_MS) {
|
|
4309
|
+
console.error(
|
|
4310
|
+
`[${this.provider}] API error after ${ms}ms (retry budget exhausted, not retrying): ${errorSummary(e)}`
|
|
4311
|
+
);
|
|
4312
|
+
throw e;
|
|
4313
|
+
}
|
|
4314
|
+
totalDelayMs += delayMs;
|
|
4315
|
+
const info = {
|
|
4316
|
+
provider: this.provider,
|
|
4317
|
+
attempt: attempt + 1,
|
|
4318
|
+
maxAttempts: MAX_RETRY_ATTEMPTS,
|
|
4319
|
+
status: extractStatus(e),
|
|
4320
|
+
retryAfterSec,
|
|
4321
|
+
delayMs,
|
|
4322
|
+
message: errorSummary(e)
|
|
4323
|
+
};
|
|
4324
|
+
console.warn(
|
|
4325
|
+
`[${this.provider}] rate-limited (attempt ${info.attempt}/${info.maxAttempts}), retrying in ${delayMs}ms`
|
|
4326
|
+
);
|
|
4327
|
+
try {
|
|
4328
|
+
this.onRetry?.(info);
|
|
4329
|
+
} catch (observerError) {
|
|
4330
|
+
console.warn(
|
|
4331
|
+
`[${this.provider}] onRetry observer threw (ignored, retry proceeds): ${errorSummary(observerError)}`
|
|
4332
|
+
);
|
|
4333
|
+
}
|
|
4334
|
+
await sleep(delayMs);
|
|
4335
|
+
}
|
|
4218
4336
|
}
|
|
4219
4337
|
}
|
|
4220
4338
|
};
|
|
@@ -4307,6 +4425,73 @@ var init_llm_router = __esm({
|
|
|
4307
4425
|
throw e;
|
|
4308
4426
|
}
|
|
4309
4427
|
}
|
|
4428
|
+
async callVision(model, systemPrompt, userPrompt, image, maxTokens) {
|
|
4429
|
+
const client = await this.getClient();
|
|
4430
|
+
const traceId = newLlmTraceId();
|
|
4431
|
+
const startedAt = Date.now();
|
|
4432
|
+
const resolvedModel = this.resolveModel(model);
|
|
4433
|
+
const imageBlock = {
|
|
4434
|
+
type: "image",
|
|
4435
|
+
source: {
|
|
4436
|
+
type: "base64",
|
|
4437
|
+
media_type: image.mediaType,
|
|
4438
|
+
data: image.base64
|
|
4439
|
+
}
|
|
4440
|
+
};
|
|
4441
|
+
try {
|
|
4442
|
+
const response = await this.apiCall(
|
|
4443
|
+
() => client.messages.create({
|
|
4444
|
+
model: resolvedModel,
|
|
4445
|
+
max_tokens: maxTokens ?? 1500,
|
|
4446
|
+
system: systemPrompt,
|
|
4447
|
+
messages: [
|
|
4448
|
+
{
|
|
4449
|
+
role: "user",
|
|
4450
|
+
content: [imageBlock, { type: "text", text: userPrompt }]
|
|
4451
|
+
}
|
|
4452
|
+
]
|
|
4453
|
+
})
|
|
4454
|
+
);
|
|
4455
|
+
const text = response.content.filter((block) => block.type === "text").map((block) => block.text).join("");
|
|
4456
|
+
const endedAt = Date.now();
|
|
4457
|
+
emitLlmTraceEvent({
|
|
4458
|
+
id: traceId,
|
|
4459
|
+
at: startedAt,
|
|
4460
|
+
endedAt,
|
|
4461
|
+
durationMs: endedAt - startedAt,
|
|
4462
|
+
provider: "anthropic",
|
|
4463
|
+
model: resolvedModel,
|
|
4464
|
+
kind: "callVision",
|
|
4465
|
+
systemPrompt,
|
|
4466
|
+
userPrompt,
|
|
4467
|
+
result: {
|
|
4468
|
+
inputTokens: response.usage.input_tokens,
|
|
4469
|
+
outputTokens: response.usage.output_tokens,
|
|
4470
|
+
text
|
|
4471
|
+
}
|
|
4472
|
+
});
|
|
4473
|
+
return {
|
|
4474
|
+
text,
|
|
4475
|
+
inputTokens: response.usage.input_tokens,
|
|
4476
|
+
outputTokens: response.usage.output_tokens
|
|
4477
|
+
};
|
|
4478
|
+
} catch (e) {
|
|
4479
|
+
const endedAt = Date.now();
|
|
4480
|
+
emitLlmTraceEvent({
|
|
4481
|
+
id: traceId,
|
|
4482
|
+
at: startedAt,
|
|
4483
|
+
endedAt,
|
|
4484
|
+
durationMs: endedAt - startedAt,
|
|
4485
|
+
provider: "anthropic",
|
|
4486
|
+
model: resolvedModel,
|
|
4487
|
+
kind: "callVision",
|
|
4488
|
+
systemPrompt,
|
|
4489
|
+
userPrompt,
|
|
4490
|
+
error: { message: e instanceof Error ? e.message : String(e) }
|
|
4491
|
+
});
|
|
4492
|
+
throw e;
|
|
4493
|
+
}
|
|
4494
|
+
}
|
|
4310
4495
|
async callTools(model, systemPrompt, userPrompt, tools, toolChoice = "required", _scopedTools) {
|
|
4311
4496
|
const client = await this.getClient();
|
|
4312
4497
|
const traceId = newLlmTraceId();
|
|
@@ -4681,6 +4866,72 @@ var init_llm_router = __esm({
|
|
|
4681
4866
|
outputTokens: interaction.usage?.total_output_tokens ?? 0
|
|
4682
4867
|
};
|
|
4683
4868
|
}
|
|
4869
|
+
async callVision(model, systemPrompt, userPrompt, image, maxTokens) {
|
|
4870
|
+
const client = await this.getClient();
|
|
4871
|
+
const traceId = newLlmTraceId();
|
|
4872
|
+
const startedAt = Date.now();
|
|
4873
|
+
const resolvedModel = this.resolveModel(model);
|
|
4874
|
+
try {
|
|
4875
|
+
const response = await this.apiCall(
|
|
4876
|
+
() => client.models.generateContent({
|
|
4877
|
+
model: resolvedModel,
|
|
4878
|
+
contents: [
|
|
4879
|
+
{
|
|
4880
|
+
role: "user",
|
|
4881
|
+
parts: [
|
|
4882
|
+
{ inlineData: { mimeType: image.mediaType, data: image.base64 } },
|
|
4883
|
+
{ text: userPrompt }
|
|
4884
|
+
]
|
|
4885
|
+
}
|
|
4886
|
+
],
|
|
4887
|
+
config: {
|
|
4888
|
+
systemInstruction: systemPrompt,
|
|
4889
|
+
...maxTokens ? { maxOutputTokens: maxTokens } : {}
|
|
4890
|
+
}
|
|
4891
|
+
})
|
|
4892
|
+
);
|
|
4893
|
+
const text = response.candidates?.[0]?.content?.parts?.map((p) => p.text || "").join("") || "";
|
|
4894
|
+
const usage = response.usageMetadata;
|
|
4895
|
+
const result = {
|
|
4896
|
+
text,
|
|
4897
|
+
inputTokens: usage?.promptTokenCount ?? 0,
|
|
4898
|
+
outputTokens: usage?.candidatesTokenCount ?? 0
|
|
4899
|
+
};
|
|
4900
|
+
const endedAt = Date.now();
|
|
4901
|
+
emitLlmTraceEvent({
|
|
4902
|
+
id: traceId,
|
|
4903
|
+
at: startedAt,
|
|
4904
|
+
endedAt,
|
|
4905
|
+
durationMs: endedAt - startedAt,
|
|
4906
|
+
provider: "google",
|
|
4907
|
+
model: resolvedModel,
|
|
4908
|
+
kind: "callVision",
|
|
4909
|
+
systemPrompt,
|
|
4910
|
+
userPrompt,
|
|
4911
|
+
result: {
|
|
4912
|
+
inputTokens: result.inputTokens,
|
|
4913
|
+
outputTokens: result.outputTokens,
|
|
4914
|
+
text
|
|
4915
|
+
}
|
|
4916
|
+
});
|
|
4917
|
+
return result;
|
|
4918
|
+
} catch (e) {
|
|
4919
|
+
const endedAt = Date.now();
|
|
4920
|
+
emitLlmTraceEvent({
|
|
4921
|
+
id: traceId,
|
|
4922
|
+
at: startedAt,
|
|
4923
|
+
endedAt,
|
|
4924
|
+
durationMs: endedAt - startedAt,
|
|
4925
|
+
provider: "google",
|
|
4926
|
+
model: resolvedModel,
|
|
4927
|
+
kind: "callVision",
|
|
4928
|
+
systemPrompt,
|
|
4929
|
+
userPrompt,
|
|
4930
|
+
error: { message: e instanceof Error ? e.message : String(e) }
|
|
4931
|
+
});
|
|
4932
|
+
throw e;
|
|
4933
|
+
}
|
|
4934
|
+
}
|
|
4684
4935
|
async callTools(model, systemPrompt, userPrompt, tools, _toolChoice = "required", scopedTools) {
|
|
4685
4936
|
const client = await this.getClient();
|
|
4686
4937
|
const interactionTools = tools.map((t) => ({
|
|
@@ -6025,7 +6276,11 @@ async function runLLMEvaluation(context, config, preWarmedContext) {
|
|
|
6025
6276
|
designSystemSummary: context.designContext
|
|
6026
6277
|
});
|
|
6027
6278
|
const numberedSource = context.sourceCode.split("\n").map((line, i) => `${String(i + 1).padStart(4)} | ${line}`).join("\n");
|
|
6028
|
-
const agent = createAgent({
|
|
6279
|
+
const agent = createAgent({
|
|
6280
|
+
provider: routerProvider,
|
|
6281
|
+
routeOverride: config.routeOverride,
|
|
6282
|
+
onRetry: config.onRetry
|
|
6283
|
+
});
|
|
6029
6284
|
const evalStart = Date.now();
|
|
6030
6285
|
const totalCriteriaCount = TIER_1_CRITERIA.length + TIER_2_CRITERIA.length;
|
|
6031
6286
|
const results = await Promise.all([
|
|
@@ -9393,6 +9648,7 @@ var visual_evaluator_exports = {};
|
|
|
9393
9648
|
__export(visual_evaluator_exports, {
|
|
9394
9649
|
buildRenderHTML: () => buildRenderHTML,
|
|
9395
9650
|
bundleForRendering: () => bundleForRendering,
|
|
9651
|
+
callMultimodalLLM: () => callMultimodalLLM,
|
|
9396
9652
|
runVisualEval: () => runVisualEval,
|
|
9397
9653
|
runVisualEvaluation: () => runVisualEvaluation
|
|
9398
9654
|
});
|
|
@@ -9517,63 +9773,23 @@ async function captureScreenshot(html, viewport = { width: 1280, height: 800 })
|
|
|
9517
9773
|
return null;
|
|
9518
9774
|
}
|
|
9519
9775
|
}
|
|
9520
|
-
async function callMultimodalLLM(
|
|
9776
|
+
async function callMultimodalLLM(config, model, prompt, screenshot, originalPrompt) {
|
|
9521
9777
|
const userPrompt = `## Original Request
|
|
9522
9778
|
${originalPrompt}
|
|
9523
9779
|
|
|
9524
9780
|
Evaluate the screenshot of the generated component.`;
|
|
9525
|
-
|
|
9526
|
-
|
|
9527
|
-
|
|
9528
|
-
|
|
9529
|
-
baseURL: "https://api.anthropic.com"
|
|
9530
|
-
});
|
|
9531
|
-
const response2 = await client2.messages.create({
|
|
9532
|
-
model: model.startsWith("anthropic/") ? model.slice(10) : model,
|
|
9533
|
-
max_tokens: 1500,
|
|
9534
|
-
system: prompt,
|
|
9535
|
-
messages: [{
|
|
9536
|
-
role: "user",
|
|
9537
|
-
content: [
|
|
9538
|
-
{
|
|
9539
|
-
type: "image",
|
|
9540
|
-
source: {
|
|
9541
|
-
type: "base64",
|
|
9542
|
-
media_type: "image/png",
|
|
9543
|
-
data: screenshot.toString("base64")
|
|
9544
|
-
}
|
|
9545
|
-
},
|
|
9546
|
-
{ type: "text", text: userPrompt }
|
|
9547
|
-
]
|
|
9548
|
-
}]
|
|
9549
|
-
});
|
|
9550
|
-
return {
|
|
9551
|
-
text: response2.content.filter((b) => b.type === "text").map((b) => b.text).join(""),
|
|
9552
|
-
inputTokens: response2.usage.input_tokens,
|
|
9553
|
-
outputTokens: response2.usage.output_tokens
|
|
9554
|
-
};
|
|
9555
|
-
}
|
|
9556
|
-
const { GoogleGenAI } = await import('@google/genai');
|
|
9557
|
-
const client = new GoogleGenAI({
|
|
9558
|
-
apiKey: process.env.GEMINI_API_KEY || process.env.GOOGLE_API_KEY
|
|
9781
|
+
const agent = createVisionAgent({
|
|
9782
|
+
provider: config.provider === "claude" ? "anthropic" : config.provider,
|
|
9783
|
+
routeOverride: config.routeOverride,
|
|
9784
|
+
onRetry: config.onRetry
|
|
9559
9785
|
});
|
|
9560
|
-
|
|
9561
|
-
model
|
|
9562
|
-
|
|
9563
|
-
|
|
9564
|
-
|
|
9565
|
-
|
|
9566
|
-
|
|
9567
|
-
]
|
|
9568
|
-
}],
|
|
9569
|
-
config: { systemInstruction: prompt }
|
|
9570
|
-
});
|
|
9571
|
-
const usage = response.usageMetadata;
|
|
9572
|
-
return {
|
|
9573
|
-
text: response.candidates?.[0]?.content?.parts?.map((p) => p.text || "").join("") || "",
|
|
9574
|
-
inputTokens: usage?.promptTokenCount ?? 0,
|
|
9575
|
-
outputTokens: usage?.candidatesTokenCount ?? 0
|
|
9576
|
-
};
|
|
9786
|
+
return agent.callVision(
|
|
9787
|
+
model,
|
|
9788
|
+
prompt,
|
|
9789
|
+
userPrompt,
|
|
9790
|
+
{ mediaType: "image/png", base64: screenshot.toString("base64") },
|
|
9791
|
+
1500
|
|
9792
|
+
);
|
|
9577
9793
|
}
|
|
9578
9794
|
async function runVisualEvaluation(context, config) {
|
|
9579
9795
|
const startTime = Date.now();
|
|
@@ -9591,7 +9807,7 @@ async function runVisualEvaluation(context, config) {
|
|
|
9591
9807
|
console.log(`[visual-eval] screenshot: ${screenshot.length}B (${Date.now() - startTime}ms)`);
|
|
9592
9808
|
const model = config.model ?? getDefaultVisualModel(config.provider);
|
|
9593
9809
|
const response = await callMultimodalLLM(
|
|
9594
|
-
config
|
|
9810
|
+
config,
|
|
9595
9811
|
model,
|
|
9596
9812
|
VISUAL_EVAL_PROMPT,
|
|
9597
9813
|
screenshot,
|
|
@@ -9665,6 +9881,7 @@ async function runVisualEval(context, config) {
|
|
|
9665
9881
|
var VISUAL_EVAL_PROMPT;
|
|
9666
9882
|
var init_visual_evaluator = __esm({
|
|
9667
9883
|
"src/evaluation/visual-evaluator.ts"() {
|
|
9884
|
+
init_llm_router();
|
|
9668
9885
|
VISUAL_EVAL_PROMPT = `You are a visual quality evaluator for ggui \u2014 a platform where AI agents generate React UI components on demand.
|
|
9669
9886
|
|
|
9670
9887
|
## Context
|
|
@@ -10127,10 +10344,12 @@ These tokens adapt automatically to any theme (light, dark, branded). **ALWAYS u
|
|
|
10127
10344
|
- Borders/dividers \u2192 \`var(--ggui-color-outline)\` or \`var(--ggui-color-outlineVariant)\`
|
|
10128
10345
|
|
|
10129
10346
|
### State Colors
|
|
10130
|
-
|
|
10131
|
-
- var(--ggui-color-
|
|
10132
|
-
- var(--ggui-color-
|
|
10133
|
-
- var(--ggui-color-
|
|
10347
|
+
Semantic families ship as SCALES; the \`500\` stop is the role color (per-mode brightness), \`50\` the tint, \`800\` the on-tint text:
|
|
10348
|
+
- var(--ggui-color-success-500) \u2014 success states (tint bg: success-50, text on tint: success-800)
|
|
10349
|
+
- var(--ggui-color-warning-500) \u2014 warning states (warning-50 / warning-800)
|
|
10350
|
+
- var(--ggui-color-error-500) \u2014 error states, destructive actions (error-50 / error-800)
|
|
10351
|
+
- var(--ggui-color-info-500) \u2014 informational (info-50 / info-800)
|
|
10352
|
+
Prefer the primitives' \`tone="success|warning|error|info"\` prop over hand-written vars \u2014 it resolves to the same stops.
|
|
10134
10353
|
|
|
10135
10354
|
### IMPORTANT: Color Rules
|
|
10136
10355
|
- **NEVER** use hardcoded hex colors. ONLY use var(--ggui-color-*) tokens.
|
|
@@ -10430,16 +10649,19 @@ function generateSampleProps(spec) {
|
|
|
10430
10649
|
return props;
|
|
10431
10650
|
}
|
|
10432
10651
|
function synthesizeFromSchema(schema) {
|
|
10433
|
-
|
|
10652
|
+
const declared = Array.isArray(schema.type) ? schema.type.find((t) => t !== "null") : schema.type;
|
|
10653
|
+
switch (declared) {
|
|
10434
10654
|
case "string":
|
|
10435
10655
|
return "sample";
|
|
10436
10656
|
case "number":
|
|
10657
|
+
case "integer":
|
|
10437
10658
|
return 0;
|
|
10438
10659
|
case "boolean":
|
|
10439
10660
|
return false;
|
|
10661
|
+
case "null":
|
|
10662
|
+
return null;
|
|
10440
10663
|
case "array": {
|
|
10441
|
-
|
|
10442
|
-
if (itemSchema) return [synthesizeFromSchema(itemSchema) ?? null];
|
|
10664
|
+
if (schema.items) return [synthesizeFromSchema(schema.items) ?? null];
|
|
10443
10665
|
return [];
|
|
10444
10666
|
}
|
|
10445
10667
|
case "object": {
|
|
@@ -12362,13 +12584,14 @@ function generateBoilerplate(_userPrompt, contract, shellType, screen, composedS
|
|
|
12362
12584
|
const propsFields = [];
|
|
12363
12585
|
const propsProperties = contract?.propsSpec?.properties ?? {};
|
|
12364
12586
|
for (const [key, entry] of Object.entries(propsProperties)) {
|
|
12365
|
-
const required = entry.required
|
|
12587
|
+
const required = entry.required === true;
|
|
12366
12588
|
const nullable = entry.schema.nullable === true;
|
|
12367
12589
|
const tsType = jsonSchemaTypeToTs(entry.schema);
|
|
12368
12590
|
const fullType = nullable ? `${tsType} | null` : tsType;
|
|
12369
12591
|
const parts = [];
|
|
12370
12592
|
if (entry.description) parts.push(entry.description);
|
|
12371
12593
|
if (entry.default !== void 0) parts.push(`(default: ${JSON.stringify(entry.default)})`);
|
|
12594
|
+
if (!required) parts.push("(optional \u2014 the agent may omit it; guard or fall back)");
|
|
12372
12595
|
const desc = parts.length > 0 ? ` // ${parts.join(" ")}` : "";
|
|
12373
12596
|
propsFields.push(` ${key}${required ? "" : "?"}: ${fullType};${desc}`);
|
|
12374
12597
|
}
|
|
@@ -12927,6 +13150,7 @@ A \`DataContract\` declares everything a GguiSession exchanges with the outside
|
|
|
12927
13150
|
|
|
12928
13151
|
Props arrive at mount and may be partial on first render; later prop changes reach the SAME mounted component via \`ggui_amend\` (in-place repaint) on the live channel. Stream channels start empty and fill over time. Context slots start at their declared default (often \`null\`). **Never assume a field exists before you read it.**
|
|
12929
13152
|
|
|
13153
|
+
- **Optional contract props**: a \`Props\` field marked \`?\` in the boilerplate may be omitted by the agent ENTIRELY \u2014 the wire gate only enforces \`required: true\` entries, and the harness verifies your component with those props stripped. Guard them (\`?? default\`, \`?.\`, or an empty-state branch) from the FIRST render.
|
|
12930
13154
|
- **Array iteration**: always default to \`[]\` before \`.map\`/\`.filter\`/\`.length\`. Use \`(props.items ?? []).map(...)\` not \`props.items.map(...)\`. Same for stream.all, stream.latest, etc.
|
|
12931
13155
|
- **Object access**: optional-chain through nested fields. \`props.user?.name ?? 'Anonymous'\` not \`props.user.name\`.
|
|
12932
13156
|
- **Number ops**: default before arithmetic. \`(props.count ?? 0) + 1\` not \`props.count + 1\`.
|
|
@@ -14339,6 +14563,106 @@ var STATE_MERGE_CHECKS = [
|
|
|
14339
14563
|
}
|
|
14340
14564
|
];
|
|
14341
14565
|
|
|
14566
|
+
// src/evaluation/axis-checks/checks/state-ui-affordance.ts
|
|
14567
|
+
var STATE_ARIA_OR_ROLE = /aria-(checked|pressed|selected|expanded|current)\s*=|role\s*=/;
|
|
14568
|
+
var STATE_PRIMITIVE_IN_SUBTREE = /<(Checkbox|Toggle|Tabs|Accordion)[\s/>]/;
|
|
14569
|
+
var SEMANTIC_PRIMITIVES = /* @__PURE__ */ new Set(["Button", "Checkbox", "Toggle", "Link", "MenuItem"]);
|
|
14570
|
+
function collectSetters(src) {
|
|
14571
|
+
const setters = /* @__PURE__ */ new Set();
|
|
14572
|
+
for (const m of src.matchAll(/const\s*\[\s*\w+\s*,\s*(set\w+)\s*\]\s*=\s*useState/g)) {
|
|
14573
|
+
setters.add(m[1]);
|
|
14574
|
+
}
|
|
14575
|
+
return setters;
|
|
14576
|
+
}
|
|
14577
|
+
function collectHandlers(src, setters) {
|
|
14578
|
+
const handlers = /* @__PURE__ */ new Set();
|
|
14579
|
+
for (const m of src.matchAll(/const\s+(\w+)\s*=\s*(?:\([^)]*\)|\w+)\s*=>\s*\{?/g)) {
|
|
14580
|
+
const body = src.slice(m.index + m[0].length, m.index + m[0].length + 400);
|
|
14581
|
+
for (const s of setters) {
|
|
14582
|
+
if (body.includes(s)) {
|
|
14583
|
+
handlers.add(m[1]);
|
|
14584
|
+
break;
|
|
14585
|
+
}
|
|
14586
|
+
}
|
|
14587
|
+
}
|
|
14588
|
+
return handlers;
|
|
14589
|
+
}
|
|
14590
|
+
function attrBlock(src, start) {
|
|
14591
|
+
let depth = 0;
|
|
14592
|
+
for (let i = start; i < src.length; i++) {
|
|
14593
|
+
const c = src[i];
|
|
14594
|
+
if (c === "{") depth++;
|
|
14595
|
+
else if (c === "}") depth--;
|
|
14596
|
+
else if (c === ">" && depth === 0) return { block: src.slice(start, i), end: i };
|
|
14597
|
+
}
|
|
14598
|
+
return { block: src.slice(start, start + 900), end: start + 900 };
|
|
14599
|
+
}
|
|
14600
|
+
function onClickValue(block) {
|
|
14601
|
+
const m = block.match(/onClick\s*=\s*\{/);
|
|
14602
|
+
if (!m || m.index === void 0) return null;
|
|
14603
|
+
const open = m.index + m[0].length - 1;
|
|
14604
|
+
let depth = 0;
|
|
14605
|
+
for (let i = open; i < block.length; i++) {
|
|
14606
|
+
if (block[i] === "{") depth++;
|
|
14607
|
+
else if (block[i] === "}") {
|
|
14608
|
+
depth--;
|
|
14609
|
+
if (depth === 0) return block.slice(open + 1, i);
|
|
14610
|
+
}
|
|
14611
|
+
}
|
|
14612
|
+
return block.slice(open + 1);
|
|
14613
|
+
}
|
|
14614
|
+
function subtree(src, pos, tag) {
|
|
14615
|
+
const close = src.indexOf(`</${tag}>`, pos);
|
|
14616
|
+
return src.slice(pos, close === -1 ? pos + 700 : close);
|
|
14617
|
+
}
|
|
14618
|
+
function runStateAriaPresent(input) {
|
|
14619
|
+
if (input.compiledCode === null) return [];
|
|
14620
|
+
const src = input.sourceCode;
|
|
14621
|
+
const setters = collectSetters(src);
|
|
14622
|
+
const handlers = collectHandlers(src, setters);
|
|
14623
|
+
const issues = [];
|
|
14624
|
+
const flaggedLines = /* @__PURE__ */ new Set();
|
|
14625
|
+
const localComponents = /* @__PURE__ */ new Set();
|
|
14626
|
+
for (const m of src.matchAll(/(?:function\s+([A-Z]\w*)\s*\(|const\s+([A-Z]\w*)\s*=)/g)) {
|
|
14627
|
+
localComponents.add(m[1] ?? m[2]);
|
|
14628
|
+
}
|
|
14629
|
+
for (const m of src.matchAll(/<([A-Za-z][A-Za-z0-9]*)\b/g)) {
|
|
14630
|
+
const tag = m[1];
|
|
14631
|
+
if (m.index === void 0) continue;
|
|
14632
|
+
if (localComponents.has(tag)) continue;
|
|
14633
|
+
const { block, end } = attrBlock(src, m.index + m[0].length);
|
|
14634
|
+
const clickValue = onClickValue(block);
|
|
14635
|
+
if (clickValue === null) continue;
|
|
14636
|
+
const mutatesAffordance = [...setters].some((s) => clickValue.includes(s)) || [...handlers].some((h) => new RegExp(`\\b${h}\\b`).test(clickValue)) || // Extracted-subcomponent shape: the toggle handler arrives as an
|
|
14637
|
+
// `on[A-Z]…` callback prop and is invoked from onClick — inside a
|
|
14638
|
+
// ui-affordance component that IS the affordance mutation.
|
|
14639
|
+
/\bon[A-Z]\w*\b/.test(clickValue);
|
|
14640
|
+
if (!mutatesAffordance) continue;
|
|
14641
|
+
if (SEMANTIC_PRIMITIVES.has(tag)) continue;
|
|
14642
|
+
if (STATE_ARIA_OR_ROLE.test(block)) continue;
|
|
14643
|
+
if (STATE_PRIMITIVE_IN_SUBTREE.test(subtree(src, end, tag))) continue;
|
|
14644
|
+
const line = src.slice(0, m.index).split("\n").length;
|
|
14645
|
+
if (flaggedLines.has(line)) continue;
|
|
14646
|
+
flaggedLines.add(line);
|
|
14647
|
+
issues.push(
|
|
14648
|
+
mkIssue(
|
|
14649
|
+
"state.ui_affordance.state_aria_present",
|
|
14650
|
+
`Line ${line}: <${tag}> toggles the UI affordance from its onClick but exposes no state ARIA \u2014 its checked/selected/expanded state is invisible to assistive technology (styling is the only carrier).`,
|
|
14651
|
+
`Add the matching state attribute to the SAME element that carries the onClick: \`role="checkbox"\` + \`aria-checked={\u2026}\` for a toggle row, \`aria-pressed\` for a toggle button, \`aria-selected\` for a selection, \`aria-expanded\` for an open/close affordance \u2014 or replace the hand-rolled control with the state-carrying primitive (Checkbox / Toggle / Tabs / Accordion). \`as={Clickable}\` adds button + keyboard semantics but NOT state.`
|
|
14652
|
+
)
|
|
14653
|
+
);
|
|
14654
|
+
}
|
|
14655
|
+
return issues;
|
|
14656
|
+
}
|
|
14657
|
+
var STATE_UI_AFFORDANCE_CHECKS = [
|
|
14658
|
+
{
|
|
14659
|
+
id: "state.ui_affordance.state_aria_present",
|
|
14660
|
+
axis: "state",
|
|
14661
|
+
values: ["ui-affordance"],
|
|
14662
|
+
run: runStateAriaPresent
|
|
14663
|
+
}
|
|
14664
|
+
];
|
|
14665
|
+
|
|
14342
14666
|
// src/evaluation/axis-checks/checks/realtime.ts
|
|
14343
14667
|
var REALTIME_ACTIVE = ["merge", "append", "status", "presence", "mixed"];
|
|
14344
14668
|
function runStreamHandlerPerEvent(input) {
|
|
@@ -15028,6 +15352,7 @@ var EXTRA_CHECKS = [
|
|
|
15028
15352
|
var REGISTRY = [
|
|
15029
15353
|
...UNIVERSAL_CHECKS,
|
|
15030
15354
|
...STATE_MERGE_CHECKS,
|
|
15355
|
+
...STATE_UI_AFFORDANCE_CHECKS,
|
|
15031
15356
|
...REALTIME_CHECKS,
|
|
15032
15357
|
...WRITES_CHECKS,
|
|
15033
15358
|
...STATE_PAYLOAD_CHECKS,
|
|
@@ -15198,8 +15523,8 @@ ${cjsResult.code}
|
|
|
15198
15523
|
// src/harness/check/runtime-render/load-component.ts
|
|
15199
15524
|
async function loadComponent(input) {
|
|
15200
15525
|
const { sourceCode, moduleResolutions = {} } = input;
|
|
15201
|
-
const { createRequire:
|
|
15202
|
-
const require_ =
|
|
15526
|
+
const { createRequire: createRequire4 } = await import('module');
|
|
15527
|
+
const require_ = createRequire4(import.meta.url);
|
|
15203
15528
|
const sandboxRequire = (id) => {
|
|
15204
15529
|
if (id in moduleResolutions) return moduleResolutions[id];
|
|
15205
15530
|
if (id === "react/jsx-runtime" || id === "react/jsx-dev-runtime") {
|
|
@@ -15455,6 +15780,47 @@ function wrapDetection(kind, jsx, native, custom) {
|
|
|
15455
15780
|
function dedupe(arr) {
|
|
15456
15781
|
return Array.from(new Set(arr));
|
|
15457
15782
|
}
|
|
15783
|
+
var installed = false;
|
|
15784
|
+
function installProductionActShim() {
|
|
15785
|
+
if (installed) return;
|
|
15786
|
+
installed = true;
|
|
15787
|
+
const require_ = createRequire(import.meta.url);
|
|
15788
|
+
let reactCjs;
|
|
15789
|
+
try {
|
|
15790
|
+
reactCjs = require_("react");
|
|
15791
|
+
} catch {
|
|
15792
|
+
return;
|
|
15793
|
+
}
|
|
15794
|
+
if (typeof reactCjs.act === "function") {
|
|
15795
|
+
return;
|
|
15796
|
+
}
|
|
15797
|
+
try {
|
|
15798
|
+
const testUtils = require_("react-dom/test-utils");
|
|
15799
|
+
const reactDom = require_("react-dom");
|
|
15800
|
+
testUtils.act = createFlushSyncAct(reactDom.flushSync);
|
|
15801
|
+
} catch {
|
|
15802
|
+
}
|
|
15803
|
+
}
|
|
15804
|
+
function createFlushSyncAct(flushSync) {
|
|
15805
|
+
return (callback) => {
|
|
15806
|
+
let callbackResult;
|
|
15807
|
+
flushSync(() => {
|
|
15808
|
+
callbackResult = callback();
|
|
15809
|
+
});
|
|
15810
|
+
if (isThenable(callbackResult)) {
|
|
15811
|
+
const pending = callbackResult;
|
|
15812
|
+
return new Promise((resolve3, reject) => {
|
|
15813
|
+
pending.then(() => resolve3(), reject);
|
|
15814
|
+
});
|
|
15815
|
+
}
|
|
15816
|
+
return new Promise((resolve3) => {
|
|
15817
|
+
queueMicrotask(resolve3);
|
|
15818
|
+
});
|
|
15819
|
+
};
|
|
15820
|
+
}
|
|
15821
|
+
function isThenable(value) {
|
|
15822
|
+
return typeof value === "object" && value !== null && typeof value.then === "function";
|
|
15823
|
+
}
|
|
15458
15824
|
|
|
15459
15825
|
// src/internal/open-record.ts
|
|
15460
15826
|
function openRecord(o) {
|
|
@@ -15572,6 +15938,7 @@ async function runRenderCheck(input) {
|
|
|
15572
15938
|
const probe = createProbe();
|
|
15573
15939
|
const wireConfig = createProbeWireConfig(probe);
|
|
15574
15940
|
uninstallSpy = probe.installPostMessageSpy();
|
|
15941
|
+
installProductionActShim();
|
|
15575
15942
|
const { render, cleanup } = await import('@testing-library/react');
|
|
15576
15943
|
const userEventModule = await import('@testing-library/user-event');
|
|
15577
15944
|
const userEvent = userEventModule.default ?? userEventModule;
|
|
@@ -15727,6 +16094,50 @@ async function runRenderCheck(input) {
|
|
|
15727
16094
|
if (issue) issues.push(issue);
|
|
15728
16095
|
}
|
|
15729
16096
|
}
|
|
16097
|
+
const declaredProps = input.contract?.propsSpec?.properties;
|
|
16098
|
+
if (declaredProps) {
|
|
16099
|
+
const optionalFilled = Object.entries(declaredProps).filter(
|
|
16100
|
+
([name, entry]) => entry.required !== true && input.mockupProps[name] !== void 0
|
|
16101
|
+
).map(([name]) => name);
|
|
16102
|
+
if (optionalFilled.length > 0) {
|
|
16103
|
+
const requiredOnlyProps = { ...input.mockupProps };
|
|
16104
|
+
for (const name of optionalFilled) delete requiredOnlyProps[name];
|
|
16105
|
+
const omitBoundaryRef = {};
|
|
16106
|
+
class OmitErrorBoundary extends React.Component {
|
|
16107
|
+
state = { caught: false };
|
|
16108
|
+
static getDerivedStateFromError() {
|
|
16109
|
+
return { caught: true };
|
|
16110
|
+
}
|
|
16111
|
+
componentDidCatch(error) {
|
|
16112
|
+
omitBoundaryRef.error ??= error;
|
|
16113
|
+
}
|
|
16114
|
+
render() {
|
|
16115
|
+
if (this.state.caught) return null;
|
|
16116
|
+
return this.props.children;
|
|
16117
|
+
}
|
|
16118
|
+
}
|
|
16119
|
+
try {
|
|
16120
|
+
render(
|
|
16121
|
+
React.createElement(GguiWireProvider, {
|
|
16122
|
+
config: wireConfig,
|
|
16123
|
+
children: React.createElement(OmitErrorBoundary, {
|
|
16124
|
+
children: React.createElement(Component, requiredOnlyProps)
|
|
16125
|
+
})
|
|
16126
|
+
})
|
|
16127
|
+
);
|
|
16128
|
+
} catch (e) {
|
|
16129
|
+
omitBoundaryRef.error ??= e instanceof Error ? e : new Error(String(e));
|
|
16130
|
+
}
|
|
16131
|
+
if (omitBoundaryRef.error) {
|
|
16132
|
+
issues.push({
|
|
16133
|
+
check: "optional-props-omitted",
|
|
16134
|
+
outcome: "failed",
|
|
16135
|
+
subject: optionalFilled.join(", "),
|
|
16136
|
+
reason: `Render crashed when the optional prop(s) ${optionalFilled.map((n) => `'${n}'`).join(", ")} were omitted: ${omitBoundaryRef.error.message}. The contract marks them optional (no \`required: true\`), so a legitimate render may leave them out.`
|
|
16137
|
+
});
|
|
16138
|
+
}
|
|
16139
|
+
}
|
|
16140
|
+
}
|
|
15730
16141
|
} finally {
|
|
15731
16142
|
cleanup();
|
|
15732
16143
|
}
|
|
@@ -16298,6 +16709,15 @@ function synthesizeFromSchema2(schema, hint, warnings, depth) {
|
|
|
16298
16709
|
if (schema.anyOf && schema.anyOf.length > 0) {
|
|
16299
16710
|
return synthesizeFromSchema2(schema.anyOf[0], hint, warnings, depth + 1);
|
|
16300
16711
|
}
|
|
16712
|
+
if (Array.isArray(schema.type)) {
|
|
16713
|
+
const primary = schema.type.find((t) => t !== "null") ?? "null";
|
|
16714
|
+
return synthesizeFromSchema2(
|
|
16715
|
+
{ ...schema, type: primary },
|
|
16716
|
+
hint,
|
|
16717
|
+
warnings,
|
|
16718
|
+
depth + 1
|
|
16719
|
+
);
|
|
16720
|
+
}
|
|
16301
16721
|
switch (schema.type) {
|
|
16302
16722
|
case "string": {
|
|
16303
16723
|
switch (schema.format) {
|
|
@@ -16468,6 +16888,16 @@ function toEvalIssue(issue) {
|
|
|
16468
16888
|
description: `Component crashed at runtime: ${issue.reason}`,
|
|
16469
16889
|
fix: classifyRenderCrashFix(issue.reason)
|
|
16470
16890
|
};
|
|
16891
|
+
case "optional-props-omitted":
|
|
16892
|
+
return {
|
|
16893
|
+
tier: 0,
|
|
16894
|
+
result,
|
|
16895
|
+
category: "crash",
|
|
16896
|
+
subcategory,
|
|
16897
|
+
severity: "critical",
|
|
16898
|
+
description: `Component crashed when optional props were omitted: ${issue.reason}`,
|
|
16899
|
+
fix: `Guard every optional prop before member access (props.${subject.split(",")[0]?.trim() ?? "x"}?.map(...), a default via destructuring, or an early empty-state return). Optional props (no \`required: true\` in the contract) may be absent at runtime even though the harness fills them.`
|
|
16900
|
+
};
|
|
16471
16901
|
case "action-wiring": {
|
|
16472
16902
|
const fix = issue.outcome === "unverified" ? `Source shows the action callback flowing into a non-native or custom-component prop. If wiring is intentional (e.g., Dropdown.onChange, drag-drop), this warn is informational \u2014 manual/browser verification is required to confirm. Otherwise wire to a native onClick={() => ${subject}(payload)} on <button> or design-system <Button>.` : `Wire ${subject}() to a native event prop. Common fix: <Button onClick={() => ${subject}(payload)}>Label</Button>. Source-AST analysis didn't find this wiring in your JSX.`;
|
|
16473
16903
|
return {
|
|
@@ -16514,6 +16944,7 @@ async function warmupRuntimeRenderProbe() {
|
|
|
16514
16944
|
missing += 1;
|
|
16515
16945
|
}
|
|
16516
16946
|
};
|
|
16947
|
+
installProductionActShim();
|
|
16517
16948
|
await Promise.all([
|
|
16518
16949
|
tryLoad("happy-dom"),
|
|
16519
16950
|
tryLoad("@testing-library/react"),
|
|
@@ -17590,6 +18021,14 @@ function mapProviderForEvaluator(provider) {
|
|
|
17590
18021
|
|
|
17591
18022
|
// src/harness/coding/run-eval-round.ts
|
|
17592
18023
|
var MAX_FEEDBACK_ISSUES = 3;
|
|
18024
|
+
function selectActionableFeedback(issues) {
|
|
18025
|
+
const pool = issues.filter((i) => i.result === "fail" || i.result === "warn");
|
|
18026
|
+
const reserved = pool.find((i) => i.tier === 0 && i.result === "fail");
|
|
18027
|
+
return [
|
|
18028
|
+
...reserved ? [reserved] : [],
|
|
18029
|
+
...pool.filter((i) => i !== reserved).sort((a, b) => (a.result === "fail" ? 0 : 1) - (b.result === "fail" ? 0 : 1))
|
|
18030
|
+
].slice(0, MAX_FEEDBACK_ISSUES);
|
|
18031
|
+
}
|
|
17593
18032
|
function fingerprintFail(issue) {
|
|
17594
18033
|
const cat = issue.category ?? "";
|
|
17595
18034
|
const sub = issue.subcategory ?? "";
|
|
@@ -17764,7 +18203,14 @@ async function runEvalRound(ctx, input) {
|
|
|
17764
18203
|
// back to `process.env` either (the eval calls run
|
|
17765
18204
|
// inside the same concurrent generation, so the race is
|
|
17766
18205
|
// real here too, not just on the coding turn).
|
|
17767
|
-
routeOverride: evaluationAgent.routeOverride
|
|
18206
|
+
routeOverride: evaluationAgent.routeOverride,
|
|
18207
|
+
// #489 — thread the same provider-429-retry observer.
|
|
18208
|
+
// Without this, a rate-limited retry inside the
|
|
18209
|
+
// evaluation agent's apiCall() happens (the base-class
|
|
18210
|
+
// retry loop is unconditional) but never reaches the
|
|
18211
|
+
// caller, silently missing the host application's
|
|
18212
|
+
// structured log.
|
|
18213
|
+
onRetry: evaluationAgent.onRetry
|
|
17768
18214
|
},
|
|
17769
18215
|
preWarmedContext
|
|
17770
18216
|
) : null,
|
|
@@ -17775,7 +18221,15 @@ async function runEvalRound(ctx, input) {
|
|
|
17775
18221
|
model: visualEvalAgent.model,
|
|
17776
18222
|
passThreshold: visualThreshold,
|
|
17777
18223
|
sampleProps: visualEvaluation?.sampleProps,
|
|
17778
|
-
viewport: visualEvaluation?.viewport
|
|
18224
|
+
viewport: visualEvaluation?.viewport,
|
|
18225
|
+
// #484/#489 — same threading as the LLM-eval leg above:
|
|
18226
|
+
// the visual eval's multimodal call runs inside the same
|
|
18227
|
+
// concurrent generation, so it needs the same routing
|
|
18228
|
+
// override (never fall back to `process.env`) and the
|
|
18229
|
+
// same provider-429-retry observer (retries reach the
|
|
18230
|
+
// host application's structured log).
|
|
18231
|
+
routeOverride: visualEvalAgent.routeOverride,
|
|
18232
|
+
onRetry: visualEvalAgent.onRetry
|
|
17779
18233
|
}
|
|
17780
18234
|
) : null
|
|
17781
18235
|
]);
|
|
@@ -17994,7 +18448,7 @@ async function runEvalRound(ctx, input) {
|
|
|
17994
18448
|
lastDiffFailed: false
|
|
17995
18449
|
};
|
|
17996
18450
|
}
|
|
17997
|
-
const allActionable = evalResult.issues
|
|
18451
|
+
const allActionable = selectActionableFeedback(evalResult.issues);
|
|
17998
18452
|
const issueLines = allActionable.map((issue) => {
|
|
17999
18453
|
const tag = issue.result === "fail" ? "FAIL" : "WARN";
|
|
18000
18454
|
return `[${tag}] ${issue.category}${issue.subcategory ? "/" + issue.subcategory : ""}: ${issue.description}
|
|
@@ -18009,7 +18463,16 @@ async function runEvalRound(ctx, input) {
|
|
|
18009
18463
|
evalResult,
|
|
18010
18464
|
evalRoundsUsed,
|
|
18011
18465
|
prevModeSubcats: updatedPrevModeSubcats,
|
|
18012
|
-
|
|
18466
|
+
// DELIVERED fails only (Exp 54 P1 addendum, proposal 2): the
|
|
18467
|
+
// stuck detector's premise is "the LLM saw these and did not
|
|
18468
|
+
// resolve them" — recording fails that the MAX_FEEDBACK_ISSUES
|
|
18469
|
+
// cap cut from the feedback turns truncation into a premature
|
|
18470
|
+
// stuck-exit (the model never saw the issue it is blamed for
|
|
18471
|
+
// not fixing). An undelivered fail recurring next round now
|
|
18472
|
+
// reads as NEW, gets delivered, and earns its fix round.
|
|
18473
|
+
prevFailFingerprints: new Set(
|
|
18474
|
+
allActionable.filter((i) => i.result === "fail").map(fingerprintFail)
|
|
18475
|
+
),
|
|
18013
18476
|
preWarmedContext,
|
|
18014
18477
|
evalTokens,
|
|
18015
18478
|
evalLlmMs,
|
|
@@ -18504,12 +18967,14 @@ async function dispatchGeneration(params) {
|
|
|
18504
18967
|
const codingAgent = {
|
|
18505
18968
|
provider: routerProvider,
|
|
18506
18969
|
model: resolvedModel,
|
|
18507
|
-
routeOverride: params.routeOverride
|
|
18970
|
+
routeOverride: params.routeOverride,
|
|
18971
|
+
onRetry: params.onRetry
|
|
18508
18972
|
};
|
|
18509
18973
|
const evaluationAgent = params.models?.evaluation ? {
|
|
18510
18974
|
provider: routerProvider,
|
|
18511
18975
|
model: params.models.evaluation,
|
|
18512
|
-
routeOverride: params.routeOverride
|
|
18976
|
+
routeOverride: params.routeOverride,
|
|
18977
|
+
onRetry: params.onRetry
|
|
18513
18978
|
} : void 0;
|
|
18514
18979
|
const effectiveContract = params.contract;
|
|
18515
18980
|
const sessionParams = {
|
|
@@ -18870,11 +19335,15 @@ ${JSON.stringify(clientCapabilities, null, 2)}
|
|
|
18870
19335
|
const uiRequirements = [];
|
|
18871
19336
|
if (contract.propsSpec?.properties) {
|
|
18872
19337
|
for (const [name, entry] of Object.entries(contract.propsSpec.properties)) {
|
|
18873
|
-
const required = entry.required;
|
|
18874
|
-
if (required
|
|
19338
|
+
const required = entry.required === true;
|
|
19339
|
+
if (required) {
|
|
18875
19340
|
uiRequirements.push(
|
|
18876
19341
|
`- **Required prop \`${name}\`** must appear somewhere in rendered DOM (display the value, or use it to drive a label/aria/key).`
|
|
18877
19342
|
);
|
|
19343
|
+
} else {
|
|
19344
|
+
uiRequirements.push(
|
|
19345
|
+
`- **Optional prop \`${name}\`** may be ABSENT at runtime \u2014 the component must render without it (guard the access or apply its default) and must display it when it IS provided.`
|
|
19346
|
+
);
|
|
18878
19347
|
}
|
|
18879
19348
|
}
|
|
18880
19349
|
}
|
|
@@ -18958,7 +19427,8 @@ function createUiGenerator(options = {}) {
|
|
|
18958
19427
|
maxEvalRounds,
|
|
18959
19428
|
qualityConfig,
|
|
18960
19429
|
gadgetCatalog,
|
|
18961
|
-
disableEnvMutation = false
|
|
19430
|
+
disableEnvMutation = false,
|
|
19431
|
+
onRetry
|
|
18962
19432
|
} = options;
|
|
18963
19433
|
const identity = resolveIdentity(options);
|
|
18964
19434
|
return {
|
|
@@ -19036,7 +19506,8 @@ function createUiGenerator(options = {}) {
|
|
|
19036
19506
|
// `dispatchGeneration`.
|
|
19037
19507
|
...input.gadgetTypes !== void 0 ? { gadgetTypes: input.gadgetTypes } : {},
|
|
19038
19508
|
enableRuntimeRender,
|
|
19039
|
-
...routeOverride !== void 0 ? { routeOverride } : {}
|
|
19509
|
+
...routeOverride !== void 0 ? { routeOverride } : {},
|
|
19510
|
+
...onRetry !== void 0 ? { onRetry } : {}
|
|
19040
19511
|
});
|
|
19041
19512
|
const metadata = {
|
|
19042
19513
|
provider: input.llm.provider,
|