@ggui-ai/ui-gen 0.28.0 → 0.29.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/{adapter-h4_V69LI.d.ts → adapter-DLQ-5COm.d.ts} +1 -1
- package/dist/adapters/base.js +2 -27
- package/dist/adapters/base.js.map +1 -1
- package/dist/adapters/generation-dispatch.d.ts +14 -6
- package/dist/adapters/generation-dispatch.js +40 -19260
- package/dist/adapters/generation-dispatch.js.map +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/index.js +25 -3561
- package/dist/adapters/index.js.map +1 -1
- package/dist/adapters/types.js +2 -9
- package/dist/adapters/types.js.map +1 -1
- package/dist/advanced/index.d.ts +13 -12
- package/dist/advanced/index.js +63 -21954
- package/dist/advanced/index.js.map +1 -1
- package/dist/{bank-Ctdp3FUA.d.ts → bank-LWaiAtaA.d.ts} +1 -1
- package/dist/blueprint-validator.js +6 -2301
- package/dist/blueprint-validator.js.map +1 -1
- package/dist/boilerplate.d.ts +3 -2
- package/dist/boilerplate.js +6 -1867
- package/dist/boilerplate.js.map +1 -1
- package/dist/check/index.d.ts +3 -2
- package/dist/check/index.js +6 -1923
- package/dist/check/index.js.map +1 -1
- package/dist/chunk-33B3BAWS.js +24 -0
- package/dist/chunk-33B3BAWS.js.map +1 -0
- package/dist/chunk-3HSGA6NI.js +591 -0
- package/dist/chunk-3HSGA6NI.js.map +1 -0
- package/dist/chunk-3NNNGNTO.js +1707 -0
- package/dist/chunk-3NNNGNTO.js.map +1 -0
- package/dist/chunk-3T2HMTON.js +79 -0
- package/dist/chunk-3T2HMTON.js.map +1 -0
- package/dist/chunk-3ZSSDV3L.js +123 -0
- package/dist/chunk-3ZSSDV3L.js.map +1 -0
- package/dist/chunk-4MBR5GA3.js +99 -0
- package/dist/chunk-4MBR5GA3.js.map +1 -0
- package/dist/chunk-56NJFD55.js +337 -0
- package/dist/chunk-56NJFD55.js.map +1 -0
- package/dist/chunk-5AGTY555.js +26 -0
- package/dist/chunk-5AGTY555.js.map +1 -0
- package/dist/chunk-5EJM7EGY.js +115 -0
- package/dist/chunk-5EJM7EGY.js.map +1 -0
- package/dist/chunk-5KXCQLLR.js +529 -0
- package/dist/chunk-5KXCQLLR.js.map +1 -0
- package/dist/chunk-5VBXHVEH.js +171 -0
- package/dist/chunk-5VBXHVEH.js.map +1 -0
- package/dist/chunk-6KDDEING.js +515 -0
- package/dist/chunk-6KDDEING.js.map +1 -0
- package/dist/chunk-6VDRWAP6.js +123 -0
- package/dist/chunk-6VDRWAP6.js.map +1 -0
- package/dist/chunk-732IBFEJ.js +2400 -0
- package/dist/chunk-732IBFEJ.js.map +1 -0
- package/dist/chunk-73AURS3I.js +46 -0
- package/dist/chunk-73AURS3I.js.map +1 -0
- package/dist/chunk-77H5SKLX.js +8 -0
- package/dist/chunk-77H5SKLX.js.map +1 -0
- package/dist/chunk-7QE3AHLE.js +35 -0
- package/dist/chunk-7QE3AHLE.js.map +1 -0
- package/dist/chunk-A375NNWN.js +11 -0
- package/dist/chunk-A375NNWN.js.map +1 -0
- package/dist/chunk-AOU33EFS.js +140 -0
- package/dist/chunk-AOU33EFS.js.map +1 -0
- package/dist/chunk-BA4QYA6E.js +461 -0
- package/dist/chunk-BA4QYA6E.js.map +1 -0
- package/dist/chunk-DBP764GL.js +3 -0
- package/dist/chunk-DBP764GL.js.map +1 -0
- package/dist/chunk-DUU3ZJDQ.js +41 -0
- package/dist/chunk-DUU3ZJDQ.js.map +1 -0
- package/dist/chunk-DXKRBXNU.js +30 -0
- package/dist/chunk-DXKRBXNU.js.map +1 -0
- package/dist/chunk-FB7OEEAH.js +1467 -0
- package/dist/chunk-FB7OEEAH.js.map +1 -0
- package/dist/chunk-FLRNMZV2.js +18 -0
- package/dist/chunk-FLRNMZV2.js.map +1 -0
- package/dist/chunk-FWJIMKFZ.js +2032 -0
- package/dist/chunk-FWJIMKFZ.js.map +1 -0
- package/dist/chunk-FXRHWYIQ.js +163 -0
- package/dist/chunk-FXRHWYIQ.js.map +1 -0
- package/dist/chunk-G3PMV62Z.js +33 -0
- package/dist/chunk-G3PMV62Z.js.map +1 -0
- package/dist/chunk-GAJI7Y3P.js +13 -0
- package/dist/chunk-GAJI7Y3P.js.map +1 -0
- package/dist/chunk-GYINWMPR.js +2052 -0
- package/dist/chunk-GYINWMPR.js.map +1 -0
- package/dist/chunk-HD6ABIK7.js +484 -0
- package/dist/chunk-HD6ABIK7.js.map +1 -0
- package/dist/chunk-HDQVHYO6.js +100 -0
- package/dist/chunk-HDQVHYO6.js.map +1 -0
- package/dist/chunk-IHUT3SIW.js +7 -0
- package/dist/chunk-IHUT3SIW.js.map +1 -0
- package/dist/chunk-JDH5EGNZ.js +126 -0
- package/dist/chunk-JDH5EGNZ.js.map +1 -0
- package/dist/chunk-JMD4RGSV.js +37 -0
- package/dist/chunk-JMD4RGSV.js.map +1 -0
- package/dist/chunk-KJWGZL5B.js +33 -0
- package/dist/chunk-KJWGZL5B.js.map +1 -0
- package/dist/chunk-MKMDQFZ7.js +86 -0
- package/dist/chunk-MKMDQFZ7.js.map +1 -0
- package/dist/chunk-NF6JUZWF.js +85 -0
- package/dist/chunk-NF6JUZWF.js.map +1 -0
- package/dist/chunk-O2YC6XDC.js +1933 -0
- package/dist/chunk-O2YC6XDC.js.map +1 -0
- package/dist/chunk-OVLH5ICV.js +29 -0
- package/dist/chunk-OVLH5ICV.js.map +1 -0
- package/dist/chunk-PBOYHGSD.js +106 -0
- package/dist/chunk-PBOYHGSD.js.map +1 -0
- package/dist/chunk-PJFH7QWA.js +81 -0
- package/dist/chunk-PJFH7QWA.js.map +1 -0
- package/dist/chunk-PUH4CXGZ.js +284 -0
- package/dist/chunk-PUH4CXGZ.js.map +1 -0
- package/dist/chunk-QLXXPGTV.js +18 -0
- package/dist/chunk-QLXXPGTV.js.map +1 -0
- package/dist/chunk-R5GIGPW2.js +2845 -0
- package/dist/chunk-R5GIGPW2.js.map +1 -0
- package/dist/chunk-RH4IUSTO.js +83 -0
- package/dist/chunk-RH4IUSTO.js.map +1 -0
- package/dist/chunk-S2GVXKKY.js +153 -0
- package/dist/chunk-S2GVXKKY.js.map +1 -0
- package/dist/chunk-TVHGKFJS.js +58 -0
- package/dist/chunk-TVHGKFJS.js.map +1 -0
- package/dist/chunk-U7GALWLG.js +66 -0
- package/dist/chunk-U7GALWLG.js.map +1 -0
- package/dist/chunk-VTC263LT.js +256 -0
- package/dist/chunk-VTC263LT.js.map +1 -0
- package/dist/chunk-WEOXFEVE.js +739 -0
- package/dist/chunk-WEOXFEVE.js.map +1 -0
- package/dist/chunk-WYHP46LT.js +28 -0
- package/dist/chunk-WYHP46LT.js.map +1 -0
- package/dist/chunk-XGLO5LGG.js +274 -0
- package/dist/chunk-XGLO5LGG.js.map +1 -0
- package/dist/chunk-XRBCRKA2.js +29 -0
- package/dist/chunk-XRBCRKA2.js.map +1 -0
- package/dist/chunk-XW7ADFFV.js +340 -0
- package/dist/chunk-XW7ADFFV.js.map +1 -0
- package/dist/chunk-YIQ42IUX.js +34 -0
- package/dist/chunk-YIQ42IUX.js.map +1 -0
- package/dist/chunk-YJZTUY7B.js +101 -0
- package/dist/chunk-YJZTUY7B.js.map +1 -0
- package/dist/chunk-Z3CXME3K.js +107 -0
- package/dist/chunk-Z3CXME3K.js.map +1 -0
- package/dist/classifier/index.js +2 -527
- package/dist/classifier/index.js.map +1 -1
- package/dist/client-JBPCXU7W.js +4 -0
- package/dist/client-JBPCXU7W.js.map +1 -0
- package/dist/compose.js +3 -367
- package/dist/compose.js.map +1 -1
- package/dist/cost-tracker-HHGQ4FTW.js +67 -0
- package/dist/cost-tracker-HHGQ4FTW.js.map +1 -0
- package/dist/{create-ui-generator-BrZHF0cf.d.ts → create-ui-generator-BY-WeaPi.d.ts} +3 -3
- package/dist/{design-mode-DGWN_Gkm.d.ts → design-mode-XyOQmzE0.d.ts} +4 -3
- package/dist/{dispatch-B07TI30d.d.ts → dispatch-8LzTddKw.d.ts} +3 -2
- package/dist/dist-UALN6ZVB.js +543 -0
- package/dist/dist-UALN6ZVB.js.map +1 -0
- package/dist/dupe-break-X6K7QFIS.js +4 -0
- package/dist/dupe-break-X6K7QFIS.js.map +1 -0
- package/dist/evaluation/axis-checks/index.d.ts +5 -4
- package/dist/evaluation/axis-checks/index.js +6 -1914
- package/dist/evaluation/axis-checks/index.js.map +1 -1
- package/dist/evaluation/axis-checks/registry.d.ts +3 -2
- package/dist/evaluation/axis-checks/registry.js +3 -1844
- package/dist/evaluation/axis-checks/registry.js.map +1 -1
- package/dist/evaluation/index.d.ts +49 -132
- package/dist/evaluation/index.js +302 -6466
- package/dist/evaluation/index.js.map +1 -1
- package/dist/evaluation/types.d.ts +3 -2
- package/dist/evaluation/types.js +2 -5
- package/dist/evaluation/types.js.map +1 -1
- package/dist/fragments/index.js +2 -338
- package/dist/fragments/index.js.map +1 -1
- package/dist/{generate-tSO_shQ0.d.ts → generate-DQ4ci90s.d.ts} +1 -1
- package/dist/harness/check/runtime-render/index.d.ts +35 -15
- package/dist/harness/check/runtime-render/index.js +6 -2390
- package/dist/harness/check/runtime-render/index.js.map +1 -1
- package/dist/harness/check/runtime-render/render-check-worker.js +4 -1739
- package/dist/harness/check/runtime-render/render-check-worker.js.map +1 -1
- package/dist/harness/index.d.ts +3 -2
- package/dist/harness/index.js +23 -5126
- package/dist/harness/index.js.map +1 -1
- package/dist/harness/llm-trace-sink.js +2 -24
- package/dist/harness/llm-trace-sink.js.map +1 -1
- package/dist/harness/prompts.d.ts +2 -2
- package/dist/harness/prompts.js +8 -324
- package/dist/harness/prompts.js.map +1 -1
- package/dist/harness/result-types.d.ts +6 -5
- package/dist/harness/result-types.js +2 -0
- package/dist/harness/result-types.js.map +1 -1
- package/dist/harness/runtime.d.ts +22 -5
- package/dist/harness/runtime.js +10 -2313
- package/dist/harness/runtime.js.map +1 -1
- package/dist/harness/types-public.d.ts +3 -2
- package/dist/harness/types-public.js +16 -2954
- package/dist/harness/types-public.js.map +1 -1
- package/dist/harness/validator-trace-sink.d.ts +3 -2
- package/dist/harness/validator-trace-sink.js +2 -26
- package/dist/harness/validator-trace-sink.js.map +1 -1
- package/dist/hash.js +2 -39
- package/dist/hash.js.map +1 -1
- package/dist/hashline-5OKREIRM.js +4 -0
- package/dist/hashline-5OKREIRM.js.map +1 -0
- package/dist/index.d.ts +50 -11
- package/dist/index.js +57 -22015
- package/dist/index.js.map +1 -1
- package/dist/llm-evaluator-PN3WFCS4.js +653 -0
- package/dist/llm-evaluator-PN3WFCS4.js.map +1 -0
- package/dist/magic-string.es-2NZTC4GZ.js +1307 -0
- package/dist/magic-string.es-2NZTC4GZ.js.map +1 -0
- package/dist/patch.d.ts +3 -2
- package/dist/patch.js +2 -56
- package/dist/patch.js.map +1 -1
- package/dist/policy-VCYKGSAC.js +5 -0
- package/dist/policy-VCYKGSAC.js.map +1 -0
- package/dist/policy.js +2 -35
- package/dist/policy.js.map +1 -1
- package/dist/primitive-index-2OF6F4TZ.js +131 -0
- package/dist/primitive-index-2OF6F4TZ.js.map +1 -0
- package/dist/primitive-slice-WTMBLYFJ.js +235 -0
- package/dist/primitive-slice-WTMBLYFJ.js.map +1 -0
- package/dist/{prompts-BhNUuRoZ.d.ts → prompts-CLZGywMP.d.ts} +1 -1
- package/dist/provider-adapter-contract.js +10407 -14204
- package/dist/provider-adapter-contract.js.map +1 -1
- package/dist/provider-adapter.js +2 -44
- package/dist/provider-adapter.js.map +1 -1
- package/dist/providers/index.d.ts +89 -1
- package/dist/providers/index.js +115 -44
- package/dist/providers/index.js.map +1 -1
- package/dist/raw-C6KBH5I3.js +141 -0
- package/dist/raw-C6KBH5I3.js.map +1 -0
- package/dist/raw-FXSBXQTZ.js +7 -0
- package/dist/raw-FXSBXQTZ.js.map +1 -0
- package/dist/raw-MURDUPGK.js +8 -0
- package/dist/raw-MURDUPGK.js.map +1 -0
- package/dist/raw-T3GW3UVX.js +8 -0
- package/dist/raw-T3GW3UVX.js.map +1 -0
- package/dist/render-check-host-ZNIS6BJ5.js +5 -0
- package/dist/render-check-host-ZNIS6BJ5.js.map +1 -0
- package/dist/sdk-4JNSDNSR.js +6 -0
- package/dist/sdk-4JNSDNSR.js.map +1 -0
- package/dist/sdk-DIVJMHCX.js +7 -0
- package/dist/sdk-DIVJMHCX.js.map +1 -0
- package/dist/sdk-QRJOCRTS.js +7 -0
- package/dist/sdk-QRJOCRTS.js.map +1 -0
- package/dist/tag-balance-CTHCTRJ7.js +123 -0
- package/dist/tag-balance-CTHCTRJ7.js.map +1 -0
- package/dist/tools/get-primitives-ts.d.ts +1 -1
- package/dist/tools/get-primitives-ts.js +3 -1
- package/dist/tools/get-primitives-ts.js.map +1 -1
- package/dist/tools/render-check-worker.js +3 -40
- package/dist/tools/render-check-worker.js.map +1 -1
- package/dist/{types-public-h8IMnYuh.d.ts → types-public-hYlrerZh.d.ts} +35 -2
- package/dist/validation/index.d.ts +2 -2
- package/dist/validation/index.js +3 -498
- package/dist/validation/index.js.map +1 -1
- package/dist/{visual-evaluator-C2strxqD.d.ts → visual-evaluator-KskajxD5.d.ts} +14 -4
- package/dist/visual-evaluator-TGEXYQTP.js +12 -0
- package/dist/visual-evaluator-TGEXYQTP.js.map +1 -0
- package/dist/workflows.d.ts +3 -2
- package/dist/workflows.js +2 -151
- package/dist/workflows.js.map +1 -1
- package/package.json +20 -16
- package/src/adapters/claude/sdk.ts +4 -2
- package/src/adapters/claude/tool-bridge.ts +2 -1
- package/src/adapters/generation-dispatch.ts +9 -0
- package/src/adapters/openai/raw.ts +4 -0
- package/src/adapters/openai/sdk.ts +6 -1
- package/src/adapters/openai/tokens.ts +21 -7
- package/src/adapters/tool-bridge.ts +1 -1
- package/src/adapters/tools.ts +1 -1
- package/src/advanced/feedback.ts +1 -2
- package/src/advanced/generator.ts +4 -3
- package/src/boilerplate/free-design-prompt.ts +7 -0
- package/src/boilerplate/generate.ts +18 -5
- package/src/boilerplate/hard-sections.ts +8 -3
- package/src/boilerplate/react-hooks.ts +56 -0
- package/src/boilerplate/system-prompt.ts +12 -3
- package/src/check/run-tier0.ts +233 -8
- package/src/check/type-checker.ts +128 -16
- package/src/coding-agent/tools.ts +26 -3
- package/src/design-mode.ts +4 -9
- package/src/evaluation/axis-checks/checks/state-merge.ts +2 -4
- package/src/evaluation/axis-checks/checks/state-payload.ts +1 -28
- package/src/evaluation/axis-checks/checks/tint.ts +197 -0
- package/src/evaluation/axis-checks/helpers.ts +121 -0
- package/src/evaluation/axis-checks/registry.ts +2 -0
- package/src/evaluation/criteria/__fixtures__/edge-v2-draw2.json +4629 -0
- package/src/evaluation/criteria/bank.ts +1 -1
- package/src/evaluation/criteria/edge-instruments.ts +14 -0
- package/src/evaluation/criteria/edge-probe-v2.ts +352 -0
- package/src/evaluation/criteria/edge-v2.ts +242 -0
- package/src/evaluation/criteria/resolve.ts +24 -5
- package/src/evaluation/index.ts +3 -5
- package/src/evaluation/mcp-server.ts +0 -50
- package/src/evaluation/types-public.ts +6 -1
- package/src/evaluation/visual-evaluator.ts +161 -30
- package/src/harness/check/runtime-render/index.ts +28 -4
- package/src/harness/check/runtime-render/render-check.ts +20 -21
- package/src/harness/claude-agent-sdk-loader.ts +93 -0
- package/src/harness/claude-code-login-query.ts +1 -1
- package/src/harness/coding/generate-task-runner.ts +1 -0
- package/src/harness/coding/run-coding-turn.ts +3 -0
- package/src/harness/coding/run-eval-round.ts +9 -0
- package/src/harness/llm-router.ts +50 -2
- package/src/harness/runtime.ts +17 -0
- package/src/index.ts +9 -0
- package/src/providers/anthropic-tool-call.ts +263 -0
- package/src/providers/index.ts +13 -0
- package/src/tools/get-primitives-ts.ts +1 -1
- package/src/tools/render-check.ts +4 -4
- package/src/validation/primitives.ts +2 -1
- package/src/evaluation/loop.ts +0 -218
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/provider-adapter.ts
|
|
2
|
+
function makeProviderError(args) {
|
|
3
|
+
const out = {
|
|
4
|
+
kind: args.kind,
|
|
5
|
+
provider: args.provider,
|
|
6
|
+
message: args.message,
|
|
7
|
+
...args.status !== void 0 ? { status: args.status } : {},
|
|
8
|
+
...args.retryAfterSec !== void 0 ? { retryAfterSec: args.retryAfterSec } : {}
|
|
9
|
+
};
|
|
10
|
+
return out;
|
|
11
|
+
}
|
|
12
|
+
function statusToErrorKind(status) {
|
|
13
|
+
if (status === 401) return "unauthorized";
|
|
14
|
+
if (status === 403) return "forbidden";
|
|
15
|
+
if (status === 429) return "rate-limited";
|
|
16
|
+
if (status >= 500 && status < 600) return "server-error";
|
|
17
|
+
if (status >= 400 && status < 500) return "client-error";
|
|
18
|
+
return "unknown";
|
|
19
|
+
}
|
|
20
|
+
function defaultValidateConfig(provider, request) {
|
|
21
|
+
if (!request.apiKey || request.apiKey.length === 0) {
|
|
22
|
+
return {
|
|
23
|
+
ok: false,
|
|
24
|
+
error: makeProviderError({
|
|
25
|
+
kind: "no-credentials",
|
|
26
|
+
provider,
|
|
27
|
+
message: `${provider}: no API key supplied`
|
|
28
|
+
})
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (!request.route?.model || request.route.model.length === 0) {
|
|
32
|
+
return {
|
|
33
|
+
ok: false,
|
|
34
|
+
error: makeProviderError({
|
|
35
|
+
kind: "client-error",
|
|
36
|
+
provider,
|
|
37
|
+
message: `${provider}: model id is required`
|
|
38
|
+
})
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return { ok: true };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { defaultValidateConfig, makeProviderError, statusToErrorKind };
|
|
45
|
+
//# sourceMappingURL=chunk-73AURS3I.js.map
|
|
46
|
+
//# sourceMappingURL=chunk-73AURS3I.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/provider-adapter.ts"],"names":[],"mappings":";AA+PO,SAAS,kBAAkB,IAAA,EAMhB;AAChB,EAAA,MAAM,GAAA,GAAqB;AAAA,IACzB,MAAM,IAAA,CAAK,IAAA;AAAA,IACX,UAAU,IA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A;AAAA,QACA,OAAA,EAAS,GAAG,QAAQ,CAAA,sBAAA;AAAA,OACrB;AAAA,KACH;AAAA,EACF;AACA,EAAA,OAAO,EAAE,IAAI,IAAA,EAAK;AACpB","file":"chunk-73AURS3I.js","sourcesContent":["/**\n * Provider adapter contract — the narrow surface every concrete LLM\n * provider client (Anthropic, Google, OpenAI, OpenRouter, Bedrock)\n * implements.\n *\n * **Real role:** a provider-agnostic one-shot LLM caller for\n * lightweight callers that need a single `complete()` round-trip — NOT\n * a generation harness. The primary consumer is the negotiator's LLM\n * seam (`@ggui-ai/mcp-server`'s `llm-backed-negotiator.ts`, via\n * {@link selectAdapter} from `./providers/index.js`); other lightweight\n * one-shot callers use it the same way. It is explicitly NOT part of\n * the generation dispatch path: `createUiGenerator()` accepts no\n * adapter option, and generation-call 429 retry/backoff lives entirely\n * in `harness/llm-router.ts`'s `apiCall()` — a separate retry story for\n * a separate call shape (an agentic SDK loop, not a single completion).\n *\n * The contract is deliberately defined independently of concrete\n * adapters so:\n *\n * - Adapter implementations can be written against a stable surface —\n * every concrete adapter MUST pass\n * {@link providerAdapterContract} or it isn't a `ProviderAdapter`.\n * - Downstream one-shot callers build against ONE structured failure\n * shape ({@link ProviderError}) instead of inventing per-provider\n * error UX.\n * - The negotiator + cache layers can branch on\n * `error.kind === 'rate-limited'` etc. without parsing strings.\n *\n * **Scope:**\n *\n * - Defines the interface, the response shape, the error shape,\n * and a contract test runner that asserts every adapter\n * satisfies the seam.\n * - Does NOT call any LLM. The contract is structural; this\n * package's own tests exercise the runner against a deterministic\n * fixture adapter (`provider-adapter-mock.test-util.ts`).\n *\n * **Design choices, locked:**\n *\n * - One discriminated `ProviderError.kind` union, not per-provider\n * subclasses. Every provider's raw error funnels through\n * `mapError` into one of these kinds. Callers branch on `kind`.\n * - Every error carries `provider` + `message`; transport-shaped\n * errors carry `status`; backoff-shaped errors carry\n * `retryAfterSec`. Optional fields don't appear when they don't\n * apply (no `status: undefined` noise in serialized logs).\n * - `validateConfig` is synchronous + does NO I/O. It catches the\n * \"operator never configured the provider\" case (missing key,\n * malformed model id) before we attempt a network call.\n * - `complete` is the single-completion seam. Streaming, tool\n * calling, function calling, and harness retry land in higher\n * layers — adapters stay narrow.\n */\nimport type { LlmProvider, LlmRoute } from '@ggui-ai/protocol';\n\n/**\n * One LLM completion request as the adapter sees it. Plain data so\n * tests can construct it without DI.\n *\n * `route` is a discriminated `LlmRoute` — `(provider, model)` typed\n * together so the model id is structurally constrained to its\n * provider's namespace (per the `MODELS` registry in\n * `@ggui-ai/protocol/types/llm-route`). This makes the #22 / #42 bug\n * class — passing a LiteLLM-prefixed `'anthropic/claude-haiku-4-5'`\n * where Anthropic expected the wire id `'claude-haiku-4-5-20251001'` —\n * a compile error at every adapter call site. The adapter reads the\n * wire-canonical string off `request.route.model` and passes it\n * verbatim to the provider SDK; no transformation step exists to\n * forget.\n */\nexport interface ProviderRequest {\n /** API key. Resolved upstream by `@ggui-ai/cli/byok-resolver`. */\n readonly apiKey: string;\n /**\n * Discriminated `(provider, model)` route. `route.model` is the\n * wire-canonical id the provider's API expects — adapters pass it\n * verbatim with no stripping or remapping.\n */\n readonly route: LlmRoute;\n /** System prompt text. Adapter wires it into the provider's slot. */\n readonly systemPrompt: string;\n /** User prompt text. */\n readonly userPrompt: string;\n /**\n * Optional cap on output tokens. Adapters MUST honor when the\n * provider supports it; when absent, adapters use the provider\n * default.\n */\n readonly maxTokens?: number;\n /**\n * Optional cancellation. Adapters MUST forward into the provider\n * SDK's abort surface and reject with `ProviderError{kind:'aborted'}`\n * when fired.\n */\n readonly signal?: AbortSignal;\n}\n\n/**\n * Successful provider response, normalized.\n *\n * Tool-calling output, multi-turn dialogue, structured-output\n * coercion all land in higher layers — this contract intentionally\n * stays narrow: text + usage + finish reason. The harness layer\n * composes adapters into multi-turn loops.\n */\nexport interface ProviderResponse {\n /** The completion text returned by the provider. */\n readonly text: string;\n /** Token usage, per-call. Required — adapters synthesize 0 if the\n * provider didn't report it (and document that in their adapter). */\n readonly usage: {\n readonly inputTokens: number;\n readonly outputTokens: number;\n };\n /**\n * Why the model stopped. Mapped through a normalized union so\n * callers don't have to know each provider's vocabulary.\n *\n * - `'stop'` model emitted EOS / stop sequence\n * - `'length'` hit `maxTokens` or provider context limit\n * - `'content-filter'` provider safety filter intervened\n * - `'other'` anything else (provider-specific reason)\n */\n readonly finishReason: 'stop' | 'length' | 'content-filter' | 'other';\n}\n\n/**\n * The structured failure contract. Every concrete adapter's\n * `mapError` MUST funnel raw provider errors into this shape so\n * downstream code branches on `kind`, not on string parsing.\n *\n * Discriminator + optional carriers:\n *\n * - `'no-credentials'` — no key supplied (pre-flight failure;\n * usually surfaced by `validateConfig`,\n * not `mapError`).\n * - `'unauthorized'` — provider returned 401. Key invalid /\n * revoked / wrong type.\n * - `'forbidden'` — provider returned 403. Quota exhausted,\n * org-level block, model not allowed for\n * this key. (Distinct from 401 because\n * \"rotate the key\" doesn't help.)\n * - `'rate-limited'` — provider returned 429. Carries\n * `retryAfterSec` when the provider\n * advertised one (`Retry-After` header).\n * - `'server-error'` — provider returned 5xx. Retryable.\n * - `'client-error'` — provider returned other 4xx. Usually\n * non-retryable (bad model id, malformed\n * request).\n * - `'network'` — TCP-level failure, DNS, EAI_AGAIN, etc.\n * No `status`. Retryable.\n * - `'invalid-response'` — provider returned 2xx with a body the\n * adapter couldn't parse. Bug in the\n * adapter or in the provider; treat as\n * non-retryable.\n * - `'aborted'` — caller aborted via `signal`.\n * - `'unknown'` — last-resort bucket. Adapters that hit\n * this should be patched to map the\n * specific case explicitly.\n */\nexport type ProviderErrorKind =\n | 'no-credentials'\n | 'unauthorized'\n | 'forbidden'\n | 'rate-limited'\n | 'server-error'\n | 'client-error'\n | 'network'\n | 'invalid-response'\n | 'aborted'\n | 'unknown';\n\nexport interface ProviderError {\n readonly kind: ProviderErrorKind;\n readonly provider: LlmProvider;\n /** Human-readable message. Safe to log; should not contain key\n * material — adapters MUST scrub before placing here. */\n readonly message: string;\n /** HTTP status when transport-shaped. Absent for pre-flight,\n * network, aborted, invalid-response. */\n readonly status?: number;\n /**\n * Seconds to wait before retrying. Set ONLY for `'rate-limited'`\n * when the provider advertised a `Retry-After` header. Higher-level\n * retry policy uses this when present; falls back to its own\n * exponential backoff when absent.\n */\n readonly retryAfterSec?: number;\n}\n\n/**\n * Pre-flight config validation. Synchronous, no I/O. Catches:\n *\n * - missing or empty API key → no-credentials\n * - missing or empty model id → client-error\n *\n * Adapters MAY widen the check with provider-specific rules\n * (e.g. \"openrouter model id MUST contain a `/`\"). Failures\n * surface through the same {@link ProviderError} so callers branch\n * on one union.\n */\nexport type ProviderValidation =\n | { readonly ok: true }\n | { readonly ok: false; readonly error: ProviderError };\n\n/**\n * The contract every provider client implements.\n */\nexport interface ProviderAdapter {\n /** Provider this adapter speaks to. Stable identifier; lets the\n * caller route a `ProviderRequest` to the right adapter. */\n readonly provider: LlmProvider;\n /**\n * Pre-flight check. MUST return synchronously and MUST NOT touch\n * the network. Returns `{ok: true}` when the request is at least\n * structurally valid; returns `{ok: false, error}` otherwise.\n */\n validateConfig(request: Pick<ProviderRequest, 'apiKey' | 'route'>): ProviderValidation;\n /**\n * Single-completion call. Resolves with `{ok: true, response}` on\n * success or `{ok: false, error}` on any failure (network,\n * provider 4xx/5xx, abort). Implementations MUST:\n *\n * 1. Funnel every raw provider error through `mapError`.\n * 2. NOT throw. The result discriminator IS the error path.\n * 3. Forward `request.signal` into the provider SDK's abort\n * mechanism + return `kind:'aborted'` when fired.\n */\n complete(request: ProviderRequest): Promise<ProviderResult>;\n /**\n * Map an arbitrary thrown / rejected value into a\n * {@link ProviderError}. Exposed (not just internal) so test\n * harnesses + retry policies can normalize errors without going\n * through `complete`.\n *\n * MUST NEVER throw — `mapError(unknown)` is the safety net.\n */\n mapError(raw: unknown): ProviderError;\n}\n\n/**\n * Discriminated result of a `complete` call. Mirrors `validateConfig`\n * so callers never have to handle thrown errors from this seam.\n */\nexport type ProviderResult =\n | { readonly ok: true; readonly response: ProviderResponse }\n | { readonly ok: false; readonly error: ProviderError };\n\n// ─── Helpers concrete adapters compose with ────────────────────────\n\n/**\n * Build a `ProviderError` of the supplied kind. Centralized so\n * concrete adapters don't drift on field shape. Provider-aware so\n * callers don't have to thread it through.\n */\nexport function makeProviderError(args: {\n readonly kind: ProviderErrorKind;\n readonly provider: LlmProvider;\n readonly message: string;\n readonly status?: number;\n readonly retryAfterSec?: number;\n}): ProviderError {\n const out: ProviderError = {\n kind: args.kind,\n provider: args.provider,\n message: args.message,\n ...(args.status !== undefined ? { status: args.status } : {}),\n ...(args.retryAfterSec !== undefined\n ? { retryAfterSec: args.retryAfterSec }\n : {}),\n };\n return out;\n}\n\n/**\n * Map an HTTP status code to the canonical error kind. Adapters\n * call this from `mapError` after they've classified the failure as\n * \"the provider returned a status we understand\". Network / abort /\n * pre-flight live outside this mapping.\n */\nexport function statusToErrorKind(status: number): ProviderErrorKind {\n if (status === 401) return 'unauthorized';\n if (status === 403) return 'forbidden';\n if (status === 429) return 'rate-limited';\n if (status >= 500 && status < 600) return 'server-error';\n if (status >= 400 && status < 500) return 'client-error';\n return 'unknown';\n}\n\n/**\n * Default `validateConfig` implementation. Concrete adapters\n * compose this and add their own provider-specific checks on top.\n *\n * Catches the two universal failures: missing key + missing model.\n * Returns `{ok: true}` when both are present.\n *\n * The model-id check is defense-in-depth — typed `LlmRoute` callers\n * cannot construct a route with an empty model string, but the\n * adapter still validates at runtime in case the request crossed an\n * untyped JSON boundary (e.g. deserialized from a wire format).\n */\nexport function defaultValidateConfig(\n provider: LlmProvider,\n request: Pick<ProviderRequest, 'apiKey' | 'route'>,\n): ProviderValidation {\n if (!request.apiKey || request.apiKey.length === 0) {\n return {\n ok: false,\n error: makeProviderError({\n kind: 'no-credentials',\n provider,\n message: `${provider}: no API key supplied`,\n }),\n };\n }\n if (!request.route?.model || request.route.model.length === 0) {\n return {\n ok: false,\n error: makeProviderError({\n kind: 'client-error',\n provider,\n message: `${provider}: model id is required`,\n }),\n };\n }\n return { ok: true };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/harness/hash.ts"],"names":[],"mappings":";AAqBO,SAAS,YAAY,CAAA,EAAoB;AAC9C,EAAA,OAAO,CAAA,CAAE,EAAA;AACX","file":"chunk-77H5SKLX.js","sourcesContent":["// Harness-level hash helpers. The three Harness-type-free helpers\n// (`hashClassification`, `computeHarnessId`, `computeHarnessName`) live\n// in `@ggui-ai/ui-gen/hash`; this file re-exports them so `./hash.js`\n// imports within the harness module keep working.\n//\n// `hashHarness` lives here because it reads the `Harness` type.\n\nimport type { Harness } from \"./types-public.js\";\n\nexport {\n hashClassification,\n computeHarnessId,\n computeHarnessName,\n} from \"../hash.js\";\n\n/**\n * Fingerprint a materialized Harness. `h.id` is already a deterministic\n * hash of the load-bearing construction inputs (classification +\n * leg versions + fragments + overrides), so equality of `hashHarness(a)`\n * and `hashHarness(b)` is equivalent to equality of `a.id` and `b.id`.\n */\nexport function hashHarness(h: Harness): string {\n return h.id;\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as z from 'zod';
|
|
2
|
+
|
|
3
|
+
// src/adapters/tool-bridge.ts
|
|
4
|
+
function zodToJsonSchema(schema) {
|
|
5
|
+
return z.toJSONSchema(schema);
|
|
6
|
+
}
|
|
7
|
+
function toolArgsToJsonObject(args) {
|
|
8
|
+
const out = {};
|
|
9
|
+
for (const [key, value] of Object.entries(args)) {
|
|
10
|
+
out[key] = value === void 0 ? void 0 : toJsonValue(value, key);
|
|
11
|
+
}
|
|
12
|
+
return out;
|
|
13
|
+
}
|
|
14
|
+
function toJsonValue(value, path) {
|
|
15
|
+
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
if (Array.isArray(value)) {
|
|
19
|
+
return value.map((item, i) => toJsonValue(item, `${path}[${i}]`));
|
|
20
|
+
}
|
|
21
|
+
if (typeof value === "object") {
|
|
22
|
+
const out = {};
|
|
23
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
24
|
+
out[key] = entry === void 0 ? void 0 : toJsonValue(entry, `${path}.${key}`);
|
|
25
|
+
}
|
|
26
|
+
return out;
|
|
27
|
+
}
|
|
28
|
+
throw new Error(
|
|
29
|
+
`Tool-call arguments contain a non-JSON value at '${path}' (${typeof value})`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { toolArgsToJsonObject, zodToJsonSchema };
|
|
34
|
+
//# sourceMappingURL=chunk-7QE3AHLE.js.map
|
|
35
|
+
//# sourceMappingURL=chunk-7QE3AHLE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/adapters/tool-bridge.ts"],"names":[],"mappings":";;;AAaO,SAAS,gBAAgB,MAAA,EAA+B;AAC7D,EAAA,OAAS,eAAa,MAAM,CAAA;AAC9B;AAUO,SAAS,qBAAqB,IAAA,EAA8C;AACjF,EAAA,MAAM,MAAkB,EAAC;AACzB,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,IAAI,CAAA,EAAG;AAG/C,IAAA,GAAA,CAAI,GAAG,CAAA,GAAI,KAAA,KAAU,SAAY,MAAA,GAAY,WAAA,CAAY,OAAO,GAAG,CAAA;AAAA,EACrE;AACA,EAAA,OAAO,GAAA;AACT;AAEA,SAAS,WAAA,CAAY,OAAgB,IAAA,EAAyB;AAC5D,EAAA,IACE,KAAA,KAAU,IAAA,IACV,OAAO,KAAA,KAAU,QAAA,IACjB,OAAO,KAAA,KAAU,QAAA,IACjB,OAAO,KAAA,KAAU,SAAA,EACjB;AACA,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACxB,IAAA,OAAO,KAAA,CAAM,GAAA,CAAI,CAAC,IAAA,EAAM,CAAA,KAAM,WAAA,CAAY,IAAA,EAAM,CAAA,EAAG,IAAI,CAAA,CAAA,EAAI,CAAC,CAAA,CAAA,CAAG,CAAC,CAAA;AAAA,EAClE;AACA,EAAA,IAAI,OAAO,UAAU,QAAA,EAAU;AAC7B,IAAA,MAAM,MAAkB,EAAC;AACzB,IAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,EAAG;AAChD,MAAA,GAAA,CAAI,GAAG,CAAA,GAAI,KAAA,KAAU,MAAA,GAAY,MAAA,GAAY,WAAA,CAAY,KAAA,EAAO,CAAA,EAAG,IAAI,CAAA,CAAA,EAAI,GAAG,CAAA,CAAE,CAAA;AAAA,IAClF;AACA,IAAA,OAAO,GAAA;AAAA,EACT;AACA,EAAA,MAAM,IAAI,KAAA;AAAA,IACR,CAAA,iDAAA,EAAoD,IAAI,CAAA,GAAA,EAAM,OAAO,KAAK,CAAA,CAAA;AAAA,GAC5E;AACF","file":"chunk-7QE3AHLE.js","sourcesContent":["// packages/ui-gen/src/adapters/tool-bridge.ts\n//\n// Bridges between SDK tool wire formats and ggui's JSON types:\n// Zod → JSON Schema for tool declarations, and validated narrowing of\n// decoded tool-call arguments to `JsonObject`.\n\nimport * as z from 'zod';\nimport type { JsonObject, JsonValue } from '@ggui-ai/protocol';\n\n/**\n * Convert a Zod object schema to JSON Schema.\n * Uses Zod v4's built-in toJSONSchema() function.\n */\nexport function zodToJsonSchema(schema: z.ZodType): JsonObject {\n return z.toJSONSchema(schema) as JsonObject;\n}\n\n/**\n * Validate that a decoded tool-call `arguments` object is plain JSON data\n * and narrow it to {@link JsonObject}. Provider SDKs type tool-call\n * arguments as `{ [key: string]: unknown }`; values decoded from a JSON\n * wire payload are JSON by construction, so a failure here means the SDK\n * handed us something that never came from JSON — a bug worth surfacing,\n * not erasing with a cast.\n */\nexport function toolArgsToJsonObject(args: { [key: string]: unknown }): JsonObject {\n const out: JsonObject = {};\n for (const [key, value] of Object.entries(args)) {\n // `JsonObject` keys admit `undefined` (TS optional properties);\n // JSON.stringify omits them, so pass-through is JSON-safe.\n out[key] = value === undefined ? undefined : toJsonValue(value, key);\n }\n return out;\n}\n\nfunction toJsonValue(value: unknown, path: string): JsonValue {\n if (\n value === null ||\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean'\n ) {\n return value;\n }\n if (Array.isArray(value)) {\n return value.map((item, i) => toJsonValue(item, `${path}[${i}]`));\n }\n if (typeof value === 'object') {\n const out: JsonObject = {};\n for (const [key, entry] of Object.entries(value)) {\n out[key] = entry === undefined ? undefined : toJsonValue(entry, `${path}.${key}`);\n }\n return out;\n }\n throw new Error(\n `Tool-call arguments contain a non-JSON value at '${path}' (${typeof value})`,\n );\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/adapters/types.ts
|
|
2
|
+
var PROVIDER_DISPLAY_NAMES = {
|
|
3
|
+
claude: "Anthropic Claude",
|
|
4
|
+
openai: "OpenAI",
|
|
5
|
+
google: "Google Gemini",
|
|
6
|
+
openrouter: "OpenRouter"
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export { PROVIDER_DISPLAY_NAMES };
|
|
10
|
+
//# sourceMappingURL=chunk-A375NNWN.js.map
|
|
11
|
+
//# sourceMappingURL=chunk-A375NNWN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/adapters/types.ts"],"names":[],"mappings":";AAcO,IAAM,sBAAA,GAAuD;AAAA,EAClE,MAAA,EAAQ,kBAAA;AAAA,EACR,MAAA,EAAQ,QAAA;AAAA,EACR,MAAA,EAAQ,eAAA;AAAA,EACR,UAAA,EAAY;AACd","file":"chunk-A375NNWN.js","sourcesContent":["// packages/ui-gen/src/adapters/types.ts\n//\n// Production adapter types — used by both Lambda generation and benchmarks.\n\nimport type { z } from 'zod';\nimport type { JsonObject } from '@ggui-ai/protocol';\n\n// =============================================================================\n// Provider & Mode\n// =============================================================================\n\nexport type ProviderName = 'claude' | 'openai' | 'google' | 'openrouter';\nexport type AdapterMode = 'raw' | 'sdk' | 'multi-agent';\n\nexport const PROVIDER_DISPLAY_NAMES: Record<ProviderName, string> = {\n claude: 'Anthropic Claude',\n openai: 'OpenAI',\n google: 'Google Gemini',\n openrouter: 'OpenRouter',\n};\n\n// =============================================================================\n// Tool Definition (SDK-agnostic)\n// =============================================================================\n\nexport interface ToolResultContent {\n type: 'text';\n text: string;\n}\n\nexport interface ToolResult {\n content: ToolResultContent[];\n isError?: boolean;\n}\n\n/**\n * SDK-agnostic tool definition.\n * Each adapter converts these to its native tool format.\n */\nexport interface ToolDefinition {\n /** Tool name (e.g., 'compile_component') */\n name: string;\n /** Tool description for the LLM */\n description: string;\n /** Zod schema for input parameters (always an object schema — tools take named args) */\n inputSchema: z.ZodObject<z.ZodRawShape>;\n /** Handler function — same signature regardless of SDK */\n handler: (args: JsonObject) => Promise<ToolResult>;\n}\n\n// =============================================================================\n// Adapter Result\n// =============================================================================\n\n/**\n * Result returned by any adapter's generate() method.\n *\n * Core fields are populated by all adapters. Extended fields are\n * populated by adapters that support richer output (e.g., Claude SDK).\n */\nexport interface AdapterResult {\n /** Final compiled JavaScript component code */\n compiledCode: string;\n /** TSX source code (captured from compile_component input) */\n sourceCode?: string;\n /** Token usage breakdown */\n tokens: {\n input: number;\n output: number;\n total: number;\n };\n /** Wall-clock generation time in ms */\n generationTimeMs: number;\n /** Total number of LLM API calls across all phases */\n turnsUsed: number;\n /** Number of harness iterations (Plan→Code→Evaluate→Regen cycles). 1 = single pass. */\n iterations?: number;\n /** Raw cost from SDK if available */\n rawCostUsd?: number;\n\n // ── Extended fields (production use) ───────────────────────────────\n\n /** Data spec for ggui_emit — describes what data the component accepts */\n stream?: JsonObject;\n /** LLM-generated metadata annotation for blueprint indexing */\n generatorMeta?: { category: string; description: string };\n /** Names of subagents invoked during generation */\n subagentsUsed?: string[];\n /** Tokens written to prompt cache (Claude-specific) */\n cacheCreationTokens?: number;\n /** Tokens read from prompt cache (Claude / OpenRouter / OpenAI). */\n cacheReadTokens?: number;\n /** SDK session ID for evaluation loop resume (Claude SDK-specific) */\n sdkSessionId?: string;\n}\n"]}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { createCapture, captureMarkers, captureSourceCode, captureCompiledCode, extractCodeFromText, compileLastResort } from './chunk-YJZTUY7B.js';
|
|
2
|
+
import { GeneratorAdapter, hasCredentials } from './chunk-XRBCRKA2.js';
|
|
3
|
+
import { splitOpenAiUsage } from './chunk-OVLH5ICV.js';
|
|
4
|
+
import { zodToJsonSchema } from './chunk-7QE3AHLE.js';
|
|
5
|
+
|
|
6
|
+
// src/adapters/openai/raw.ts
|
|
7
|
+
async function loadOpenAI() {
|
|
8
|
+
return import('openai');
|
|
9
|
+
}
|
|
10
|
+
var OpenAiRawAdapter = class extends GeneratorAdapter {
|
|
11
|
+
provider = "openai";
|
|
12
|
+
mode = "raw";
|
|
13
|
+
displayName = "OpenAI (Raw API)";
|
|
14
|
+
client = null;
|
|
15
|
+
constructor(config = {}) {
|
|
16
|
+
super(config);
|
|
17
|
+
}
|
|
18
|
+
isAvailable() {
|
|
19
|
+
return hasCredentials(this.config, "OPENAI_API_KEY");
|
|
20
|
+
}
|
|
21
|
+
async generate(params) {
|
|
22
|
+
const startTime = Date.now();
|
|
23
|
+
if (!this.client) {
|
|
24
|
+
const { default: OpenAIClient } = await loadOpenAI();
|
|
25
|
+
this.client = new OpenAIClient({
|
|
26
|
+
apiKey: this.config.apiKey || process.env.OPENAI_API_KEY
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const tools = params.tools.map(toResponsesTool);
|
|
30
|
+
const capture = createCapture();
|
|
31
|
+
let totalInputTokens = 0;
|
|
32
|
+
let totalOutputTokens = 0;
|
|
33
|
+
let totalCachedInputTokens = 0;
|
|
34
|
+
let totalCacheWriteTokens = 0;
|
|
35
|
+
let turnsUsed = 0;
|
|
36
|
+
let allTextOutput = "";
|
|
37
|
+
let response = await this.client.responses.create({
|
|
38
|
+
model: params.model,
|
|
39
|
+
instructions: params.systemPrompt,
|
|
40
|
+
input: [{ role: "user", content: params.userPrompt }],
|
|
41
|
+
tools,
|
|
42
|
+
store: true
|
|
43
|
+
// Required for previous_response_id to work on subsequent turns
|
|
44
|
+
});
|
|
45
|
+
for (let turn = 0; turn < params.maxTurns; turn++) {
|
|
46
|
+
turnsUsed = turn + 1;
|
|
47
|
+
if (response.usage) {
|
|
48
|
+
totalInputTokens += response.usage.input_tokens ?? 0;
|
|
49
|
+
totalOutputTokens += response.usage.output_tokens ?? 0;
|
|
50
|
+
totalCachedInputTokens += response.usage.input_tokens_details?.cached_tokens ?? 0;
|
|
51
|
+
totalCacheWriteTokens += response.usage.input_tokens_details?.cache_write_tokens ?? 0;
|
|
52
|
+
}
|
|
53
|
+
const output = response.output ?? [];
|
|
54
|
+
const functionCalls = output.filter(
|
|
55
|
+
(item) => item.type === "function_call"
|
|
56
|
+
);
|
|
57
|
+
for (const item of output) {
|
|
58
|
+
if (item.type === "message" && "content" in item && item.content) {
|
|
59
|
+
for (const part of item.content) {
|
|
60
|
+
if (part.type === "output_text" && part.text) {
|
|
61
|
+
allTextOutput += part.text + "\n";
|
|
62
|
+
captureMarkers(capture, part.text);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (functionCalls.length === 0) break;
|
|
68
|
+
const nextInput = [];
|
|
69
|
+
for (const fc of functionCalls) {
|
|
70
|
+
const toolDef = params.tools.find((t) => t.name === fc.name);
|
|
71
|
+
if (!toolDef) {
|
|
72
|
+
nextInput.push({
|
|
73
|
+
type: "function_call_output",
|
|
74
|
+
call_id: fc.call_id,
|
|
75
|
+
output: JSON.stringify({ error: `Tool '${fc.name}' not found` })
|
|
76
|
+
});
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
let args = {};
|
|
80
|
+
try {
|
|
81
|
+
args = JSON.parse(fc.arguments || "{}");
|
|
82
|
+
} catch {
|
|
83
|
+
}
|
|
84
|
+
captureSourceCode(capture, fc.name, args);
|
|
85
|
+
const result = await toolDef.handler(args);
|
|
86
|
+
captureCompiledCode(capture, fc.name, result);
|
|
87
|
+
nextInput.push({
|
|
88
|
+
type: "function_call_output",
|
|
89
|
+
call_id: fc.call_id,
|
|
90
|
+
output: result.content[0]?.text ?? ""
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
response = await this.client.responses.create({
|
|
94
|
+
model: params.model,
|
|
95
|
+
instructions: params.systemPrompt,
|
|
96
|
+
input: nextInput,
|
|
97
|
+
tools,
|
|
98
|
+
previous_response_id: response.id,
|
|
99
|
+
store: true
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (!capture.compiledCode && allTextOutput) {
|
|
103
|
+
captureMarkers(capture, allTextOutput);
|
|
104
|
+
await extractCodeFromText(allTextOutput, params.tools, capture);
|
|
105
|
+
}
|
|
106
|
+
if (!capture.compiledCode) {
|
|
107
|
+
await compileLastResort(capture, allTextOutput);
|
|
108
|
+
}
|
|
109
|
+
if (!capture.compiledCode) {
|
|
110
|
+
throw new Error("OpenAI raw adapter: no compiled code produced after all turns");
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
compiledCode: capture.compiledCode,
|
|
114
|
+
sourceCode: capture.sourceCode,
|
|
115
|
+
stream: capture.stream,
|
|
116
|
+
generatorMeta: capture.generatorMeta,
|
|
117
|
+
...splitOpenAiUsage(
|
|
118
|
+
totalInputTokens,
|
|
119
|
+
totalOutputTokens,
|
|
120
|
+
totalCachedInputTokens,
|
|
121
|
+
totalCacheWriteTokens
|
|
122
|
+
),
|
|
123
|
+
generationTimeMs: Date.now() - startTime,
|
|
124
|
+
turnsUsed
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
function toResponsesTool(def) {
|
|
129
|
+
return {
|
|
130
|
+
type: "function",
|
|
131
|
+
name: def.name,
|
|
132
|
+
description: def.description,
|
|
133
|
+
parameters: zodToJsonSchema(def.inputSchema),
|
|
134
|
+
strict: false
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export { OpenAiRawAdapter };
|
|
139
|
+
//# sourceMappingURL=chunk-AOU33EFS.js.map
|
|
140
|
+
//# sourceMappingURL=chunk-AOU33EFS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/adapters/openai/raw.ts"],"names":[],"mappings":";;;;;;AAwBA,eAAe,UAAA,GAA+C;AAC5D,EAAA,OAAO,OAAO,QAAQ,CAAA;AACxB;AAEO,IAAM,gBAAA,GAAN,cAA+B,gBAAA,CAAiB;AAAA,EAC5C,QAAA,GAAyB,QAAA;AAAA,EACzB,IAAA,GAAoB,KAAA;AAAA,EACpB,WAAA,GAAc,kBAAA;AAAA,EAEf,MAAA,GAAwB,IAAA;AAAA,EAEhC,WAAA,CAAY,MAAA,GAAwB,EAAC,EAAG;AACtC,IAAA,KAAA,CAAM,MAAM,CAAA;AAAA,EACd;AAAA,EAEA,WAAA,GAAuB;AACrB,IAAA,OAAO,cAAA,CAAe,IAAA,CAAK,MAAA,EAAQ,gBAAgB,CAAA;AAAA,EACrD;AAAA,EAEA,MAAM,SAAS,MAAA,EAAgD;AAC7D,IAAA,MAAM,SAAA,GAAY,KAAK,GAAA,EAAI;AAE3B,IAAA,IAAI,CAAC,KAAK,MAAA,EAAQ;AAChB,MAAA,MAAM,EAAE,OAAA,EAAS,YAAA,EAAa,GAAI,MAAM,UAAA,EAAW;AACnD,MAAA,IAAA,CAAK,MAAA,GAAS,IAAI,YAAA,CAAa;AAAA,QAC7B,MAAA,EAAQ,IAAA,CAAK,MAAA,CAAO,MAAA,IAAU,QAAQ,GAAA,CAAI;AAAA,OAC3C,CAAA;AAAA,IACH;AAEA,IAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,KAAA,CAAM,GAAA,CAAI,eAAe,CAAA;AAC9C,IAAA,MAAM,UAAU,aAAA,E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AAAA,QACA,sBAAA;AAAA,QACA;AAAA,OACF;AAAA,MACA,gBAAA,EAAkB,IAAA,CAAK,GAAA,EAAI,GAAI,SAAA;AAAA,MAC/B;AAAA,KACF;AAAA,EACF;AACF;AAKA,SAAS,gBAAgB,GAAA,EAAuH;AAC9I,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,UAAA;AAAA,IACN,MAAM,GAAA,CAAI,IAAA;AAAA,IACV,aAAa,GAAA,CAAI,WAAA;AAAA,IACjB,UAAA,EAAY,eAAA,CAAgB,GAAA,CAAI,WAAW,CAAA;AAAA,IAC3C,MAAA,EAAQ;AAAA,GACV;AACF","file":"chunk-AOU33EFS.js","sourcesContent":["// packages/ui-gen/src/adapters/openai/raw.ts\n//\n// OpenAI adapter using the raw OpenAI SDK (openai).\n// Uses the Responses API (responses.create) with previous_response_id\n// for multi-turn tool-calling loops.\n\nimport type OpenAI from 'openai';\nimport type { Responses } from 'openai/resources/responses/responses';\nimport { GeneratorAdapter, hasCredentials } from '../base';\nimport type { AdapterConfig, GenerateParams } from '../base';\nimport type { AdapterResult, ToolDefinition, ProviderName, AdapterMode } from '../types';\nimport { zodToJsonSchema } from '../tool-bridge';\nimport { splitOpenAiUsage } from './tokens';\nimport {\n createCapture,\n captureSourceCode,\n captureCompiledCode,\n captureMarkers,\n extractCodeFromText,\n compileLastResort,\n} from '../extract-code';\nimport type { JsonObject } from '@ggui-ai/protocol';\n\n/** Lazy-load the OpenAI SDK to avoid top-level import crashes in Lambda bundles. */\nasync function loadOpenAI(): Promise<typeof import('openai')> {\n return import('openai');\n}\n\nexport class OpenAiRawAdapter extends GeneratorAdapter {\n readonly provider: ProviderName = 'openai';\n readonly mode: AdapterMode = 'raw';\n readonly displayName = 'OpenAI (Raw API)';\n\n private client: OpenAI | null = null;\n\n constructor(config: AdapterConfig = {}) {\n super(config);\n }\n\n isAvailable(): boolean {\n return hasCredentials(this.config, 'OPENAI_API_KEY');\n }\n\n async generate(params: GenerateParams): Promise<AdapterResult> {\n const startTime = Date.now();\n\n if (!this.client) {\n const { default: OpenAIClient } = await loadOpenAI();\n this.client = new OpenAIClient({\n apiKey: this.config.apiKey || process.env.OPENAI_API_KEY,\n });\n }\n\n const tools = params.tools.map(toResponsesTool);\n const capture = createCapture();\n let totalInputTokens = 0;\n let totalOutputTokens = 0;\n // OpenAI's input token count INCLUDES cached tokens; track the cached\n // subset so tokens.input reports NON-cached input (ggui#1186).\n let totalCachedInputTokens = 0;\n let totalCacheWriteTokens = 0;\n let turnsUsed = 0;\n let allTextOutput = '';\n\n // First request — user prompt + instructions\n let response: Responses.Response = await this.client.responses.create({\n model: params.model,\n instructions: params.systemPrompt,\n input: [{ role: 'user', content: params.userPrompt }],\n tools,\n store: true, // Required for previous_response_id to work on subsequent turns\n });\n\n // Agentic loop\n for (let turn = 0; turn < params.maxTurns; turn++) {\n turnsUsed = turn + 1;\n\n // Track tokens\n if (response.usage) {\n totalInputTokens += response.usage.input_tokens ?? 0;\n totalOutputTokens += response.usage.output_tokens ?? 0;\n totalCachedInputTokens +=\n response.usage.input_tokens_details?.cached_tokens ?? 0;\n totalCacheWriteTokens +=\n response.usage.input_tokens_details?.cache_write_tokens ?? 0;\n }\n\n // Process output items\n const output = response.output ?? [];\n const functionCalls = output.filter(\n (item): item is Responses.ResponseFunctionToolCall => item.type === 'function_call',\n );\n\n // Collect text output for markers and code extraction fallback\n for (const item of output) {\n if (item.type === 'message' && 'content' in item && item.content) {\n for (const part of item.content) {\n if (part.type === 'output_text' && part.text) {\n allTextOutput += part.text + '\\n';\n captureMarkers(capture, part.text);\n }\n }\n }\n }\n\n if (functionCalls.length === 0) break;\n\n // Only send function_call_output items — previous_response_id carries context\n const nextInput: Responses.ResponseInputItem.FunctionCallOutput[] = [];\n\n for (const fc of functionCalls) {\n const toolDef = params.tools.find((t) => t.name === fc.name);\n if (!toolDef) {\n nextInput.push({\n type: 'function_call_output',\n call_id: fc.call_id,\n output: JSON.stringify({ error: `Tool '${fc.name}' not found` }),\n });\n continue;\n }\n\n let args: JsonObject = {};\n try { args = JSON.parse(fc.arguments || '{}') as JsonObject; } catch { /* empty */ }\n\n captureSourceCode(capture, fc.name, args);\n\n const result = await toolDef.handler(args);\n captureCompiledCode(capture, fc.name, result);\n\n nextInput.push({\n type: 'function_call_output',\n call_id: fc.call_id,\n output: result.content[0]?.text ?? '',\n });\n }\n\n // Next turn — use previous_response_id for context continuity\n response = await this.client.responses.create({\n model: params.model,\n instructions: params.systemPrompt,\n input: nextInput,\n tools,\n previous_response_id: response.id,\n store: true,\n });\n }\n\n // Fallback: extract code from text output if no tool produced compiled code\n if (!capture.compiledCode && allTextOutput) {\n captureMarkers(capture, allTextOutput);\n await extractCodeFromText(allTextOutput, params.tools, capture);\n }\n\n // Last resort: compile sourceCode directly with esbuild, bypassing self-checks\n if (!capture.compiledCode) {\n await compileLastResort(capture, allTextOutput);\n }\n\n if (!capture.compiledCode) {\n throw new Error('OpenAI raw adapter: no compiled code produced after all turns');\n }\n\n return {\n compiledCode: capture.compiledCode,\n sourceCode: capture.sourceCode,\n stream: capture.stream,\n generatorMeta: capture.generatorMeta,\n ...splitOpenAiUsage(\n totalInputTokens,\n totalOutputTokens,\n totalCachedInputTokens,\n totalCacheWriteTokens,\n ),\n generationTimeMs: Date.now() - startTime,\n turnsUsed,\n };\n }\n}\n\n/**\n * Convert a ToolDefinition to OpenAI Responses API FunctionTool format.\n */\nfunction toResponsesTool(def: ToolDefinition): { type: 'function'; name: string; description: string; parameters: JsonObject; strict: boolean } {\n return {\n type: 'function',\n name: def.name,\n description: def.description,\n parameters: zodToJsonSchema(def.inputSchema) as JsonObject,\n strict: false,\n };\n}\n"]}
|