@skyphusion/create-prism 0.1.0 → 1.0.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/README.md +5 -3
- package/index.js +4 -2
- package/package.json +1 -1
- package/template/CONTRIBUTING.md +6 -2
- package/template/README.md +227 -48
- package/template/docs/legal/README.md +1 -0
- package/template/migrations/0002_auth_public_mode.sql +32 -0
- package/template/migrations/0003_conversation_compact.sql +24 -0
- package/template/package.json +6 -6
- package/template/public/app.js +128 -19
- package/template/public/index.html +50 -4
- package/template/public/styles.css +16 -2
- package/template/schema.sql +17 -0
- package/template/src/auth-kdf.ts +7 -4
- package/template/src/auth.ts +11 -2
- package/template/src/control-plane.ts +254 -0
- package/template/src/conversation-context.ts +126 -0
- package/template/src/env.ts +15 -0
- package/template/src/gateway-credentials.ts +23 -4
- package/template/src/health-schema.ts +4 -0
- package/template/src/index.ts +73 -3982
- package/template/src/longrun-params.ts +4 -2
- package/template/src/models.ts +65 -19
- package/template/src/output-extract.ts +58 -8
- package/template/src/parsers/openai-sse.ts +43 -14
- package/template/src/providers/anthropic.ts +105 -0
- package/template/src/providers/openai-image.ts +66 -0
- package/template/src/providers/openai.ts +79 -13
- package/template/src/providers/xai.ts +91 -0
- package/template/src/proxied-image-params.ts +29 -16
- package/template/src/routes/artifacts.ts +51 -0
- package/template/src/routes/chat.ts +1682 -0
- package/template/src/routes/conversations.ts +494 -0
- package/template/src/routes/documents.ts +262 -0
- package/template/src/routes/health.ts +105 -0
- package/template/src/routes/history.ts +92 -0
- package/template/src/routes/prefs.ts +95 -0
- package/template/src/routes/projects.ts +574 -0
- package/template/src/routes/rag.ts +657 -0
- package/template/src/routes/shared.ts +226 -0
- package/template/src/routes/workflow.ts +304 -0
- package/template/src/stt-session.ts +1 -1
- package/template/src/user-prefs.ts +10 -0
- package/template/src/zip.ts +7 -0
- package/template/tests/anthropic-binding.test.ts +181 -0
- package/template/tests/control-plane.test.ts +112 -0
- package/template/tests/conversation-compact.test.ts +103 -0
- package/template/tests/gateway-credentials.test.ts +37 -0
- package/template/tests/longrun-params.test.ts +19 -0
- package/template/tests/openai-image.test.ts +47 -0
- package/template/tests/openai-responses.test.ts +78 -0
- package/template/tests/openai-sse.test.ts +28 -0
- package/template/tests/output-extract.test.ts +75 -1
- package/template/tests/proxied-image-params.test.ts +16 -7
- package/template/tests/sprint1-catalog.test.ts +27 -0
- package/template/tests/sprint2-catalog.test.ts +51 -0
- package/template/tests/sprint3-catalog.test.ts +29 -0
- package/template/tests/xai-binding.test.ts +127 -0
- package/template/tests-integration/worker.test.ts +9 -2
- package/template/wrangler.example.toml +19 -7
|
@@ -7,7 +7,13 @@
|
|
|
7
7
|
// the rest are regression coverage for the shapes that already shipped.
|
|
8
8
|
|
|
9
9
|
import { describe, it, expect } from "vitest";
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
extractOutput,
|
|
12
|
+
extractUsage,
|
|
13
|
+
detectProviderFailure,
|
|
14
|
+
extractProxiedImageUrl,
|
|
15
|
+
extractProxiedImageAsset,
|
|
16
|
+
} from "../src/output-extract";
|
|
11
17
|
|
|
12
18
|
describe("extractOutput", () => {
|
|
13
19
|
it("returns a bare string unchanged", () => {
|
|
@@ -122,6 +128,23 @@ describe("detectProviderFailure", () => {
|
|
|
122
128
|
expect(detectProviderFailure({ state: "Failed" })).toBe('provider returned state "Failed"');
|
|
123
129
|
});
|
|
124
130
|
|
|
131
|
+
it("flags OpenAI Responses API failed/incomplete status (v0.173.0)", () => {
|
|
132
|
+
expect(detectProviderFailure({
|
|
133
|
+
object: "response",
|
|
134
|
+
status: "failed",
|
|
135
|
+
error: { message: "upstream unavailable" },
|
|
136
|
+
})).toBe("upstream unavailable");
|
|
137
|
+
expect(detectProviderFailure({
|
|
138
|
+
object: "response",
|
|
139
|
+
status: "incomplete",
|
|
140
|
+
})).toBe('provider returned status "incomplete"');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("does not flag a completed Responses object", () => {
|
|
144
|
+
expect(detectProviderFailure({ object: "response", status: "completed", output: [] })).toBeNull();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
|
|
125
148
|
it("treats any non-Completed state as a failure", () => {
|
|
126
149
|
expect(detectProviderFailure({ state: "Cancelled" })).toBe('provider returned state "Cancelled"');
|
|
127
150
|
});
|
|
@@ -158,9 +181,24 @@ describe("extractProxiedImageUrl", () => {
|
|
|
158
181
|
expect(extractProxiedImageUrl(r)).toBe("https://r2.dev/wrapped.png");
|
|
159
182
|
});
|
|
160
183
|
|
|
184
|
+
it("reads Seedream-style result.images[] and takes the first URL (v0.171.0)", () => {
|
|
185
|
+
const r = {
|
|
186
|
+
state: "Completed",
|
|
187
|
+
result: { images: ["https://r2.dev/seedream-0.jpeg", "https://r2.dev/seedream-1.jpeg"] },
|
|
188
|
+
};
|
|
189
|
+
expect(extractProxiedImageUrl(r)).toBe("https://r2.dev/seedream-0.jpeg");
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("reads bare { images } when no result wrapper is present", () => {
|
|
193
|
+
expect(extractProxiedImageUrl({ images: ["https://r2.dev/bare-arr.png"] })).toBe(
|
|
194
|
+
"https://r2.dev/bare-arr.png",
|
|
195
|
+
);
|
|
196
|
+
});
|
|
197
|
+
|
|
161
198
|
it("returns null when no image url is present", () => {
|
|
162
199
|
expect(extractProxiedImageUrl({ state: "Completed", result: {} })).toBeNull();
|
|
163
200
|
expect(extractProxiedImageUrl({ choices: [] })).toBeNull();
|
|
201
|
+
expect(extractProxiedImageUrl({ result: { images: [] } })).toBeNull();
|
|
164
202
|
});
|
|
165
203
|
|
|
166
204
|
it("does not throw on null / undefined / string", () => {
|
|
@@ -168,4 +206,40 @@ describe("extractProxiedImageUrl", () => {
|
|
|
168
206
|
expect(extractProxiedImageUrl(undefined)).toBeNull();
|
|
169
207
|
expect(extractProxiedImageUrl("nope")).toBeNull();
|
|
170
208
|
});
|
|
209
|
+
|
|
210
|
+
it("extractProxiedImageUrl ignores raw base64 (not a URL)", () => {
|
|
211
|
+
expect(extractProxiedImageUrl({ result: { image: "iVBORw0KGgo=" } })).toBeNull();
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
describe("extractProxiedImageAsset", () => {
|
|
216
|
+
it("classifies https URLs as kind url", () => {
|
|
217
|
+
expect(extractProxiedImageAsset({
|
|
218
|
+
state: "Completed",
|
|
219
|
+
result: { image: "https://r2.dev/out.png" },
|
|
220
|
+
})).toEqual({ kind: "url", url: "https://r2.dev/out.png" });
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it("classifies raw base64 as kind b64 (Grok Imagine b64_json)", () => {
|
|
224
|
+
expect(extractProxiedImageAsset({
|
|
225
|
+
state: "Completed",
|
|
226
|
+
result: { image: "iVBORw0KGgoAAAANSUhEUg==" },
|
|
227
|
+
})).toEqual({
|
|
228
|
+
kind: "b64",
|
|
229
|
+
mime: "image/png",
|
|
230
|
+
base64: "iVBORw0KGgoAAAANSUhEUg==",
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("parses data: URIs into mime + base64", () => {
|
|
235
|
+
expect(extractProxiedImageAsset({
|
|
236
|
+
result: { image: "data:image/webp;base64,UklGRg==" },
|
|
237
|
+
})).toEqual({ kind: "b64", mime: "image/webp", base64: "UklGRg==" });
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it("takes the first Seedream images[] URL", () => {
|
|
241
|
+
expect(extractProxiedImageAsset({
|
|
242
|
+
result: { images: ["https://cdn.example/a.jpeg", "https://cdn.example/b.jpeg"] },
|
|
243
|
+
})).toEqual({ kind: "url", url: "https://cdn.example/a.jpeg" });
|
|
244
|
+
});
|
|
171
245
|
});
|
|
@@ -26,18 +26,27 @@ describe("buildProxiedImageParams", () => {
|
|
|
26
26
|
expect("output_format" in params).toBe(false);
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
it("recraft (recraftv4) sends
|
|
29
|
+
it("recraft (recraftv4*) sends bare prompt (no style/size; V4.1 Pro rejects 1024x1024)", () => {
|
|
30
30
|
const params = buildProxiedImageParams("recraft", "a logo");
|
|
31
|
-
expect(params).toEqual({
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
style: "digital_illustration",
|
|
35
|
-
});
|
|
31
|
+
expect(params).toEqual({ prompt: "a logo" });
|
|
32
|
+
expect("style" in params).toBe(false);
|
|
33
|
+
expect("size" in params).toBe(false);
|
|
36
34
|
expect("background" in params).toBe(false);
|
|
37
35
|
});
|
|
38
36
|
|
|
37
|
+
it("xai (grok-imagine-*) requests b64_json (Unified Billing ZDR/URL ban, v0.173.0)", () => {
|
|
38
|
+
expect(buildProxiedImageParams("xai", "a puppy")).toEqual({
|
|
39
|
+
prompt: "a puppy",
|
|
40
|
+
response_format: "b64_json",
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("bytedance (seedream-5-pro) sends bare prompt only (v0.171.0)", () => {
|
|
45
|
+
expect(buildProxiedImageParams("bytedance", "a watch")).toEqual({ prompt: "a watch" });
|
|
46
|
+
});
|
|
47
|
+
|
|
39
48
|
it("never leaks the @cf request shape for any proxied provider", () => {
|
|
40
|
-
for (const p of ["google", "openai", "recraft"] as const) {
|
|
49
|
+
for (const p of ["google", "openai", "recraft", "xai", "bytedance"] as const) {
|
|
41
50
|
const params = buildProxiedImageParams(p, "x");
|
|
42
51
|
for (const forbidden of ["width", "height", "steps", "negative_prompt"]) {
|
|
43
52
|
expect(forbidden in params).toBe(false);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Catalog pins for the v0.170.0 Sprint 1 model adds (read-only audit follow-up).
|
|
2
|
+
|
|
3
|
+
import { describe, it, expect } from "vitest";
|
|
4
|
+
import { MODELS } from "../src/models";
|
|
5
|
+
|
|
6
|
+
describe("v0.170.0 sprint 1 catalog entries", () => {
|
|
7
|
+
it("adds Gemini 3.6 Flash on the google dispatcher (text-only caps)", () => {
|
|
8
|
+
const m = MODELS.find((x) => x.id === "google/gemini-3.6-flash");
|
|
9
|
+
expect(m).toBeDefined();
|
|
10
|
+
expect(m?.provider).toBe("google");
|
|
11
|
+
expect(m?.type).toBe("chat");
|
|
12
|
+
expect(m?.streaming).toBe(true);
|
|
13
|
+
expect(m?.capabilities).toEqual([]);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("adds Seedance 2.0 Mini as bytedance video with image-input", () => {
|
|
17
|
+
const m = MODELS.find((x) => x.id === "bytedance/seedance-2.0-mini");
|
|
18
|
+
expect(m).toBeDefined();
|
|
19
|
+
expect(m?.provider).toBe("bytedance");
|
|
20
|
+
expect(m?.type).toBe("video");
|
|
21
|
+
expect(m?.capabilities).toContain("image-input");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("does not re-introduce blocked grok-build-0.1", () => {
|
|
25
|
+
expect(MODELS.find((x) => x.id === "xai/grok-build-0.1")).toBeUndefined();
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Catalog pins for the v0.171.0 Sprint 2 model adds.
|
|
2
|
+
|
|
3
|
+
import { describe, it, expect } from "vitest";
|
|
4
|
+
import { MODELS } from "../src/models";
|
|
5
|
+
import { readFileSync } from "node:fs";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
|
|
9
|
+
const chatSrc = readFileSync(
|
|
10
|
+
join(dirname(fileURLToPath(import.meta.url)), "../src/routes/chat.ts"),
|
|
11
|
+
"utf8",
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
describe("v0.171.0 sprint 2 catalog entries", () => {
|
|
15
|
+
it("adds Kimi K3 as moonshotai chat with streaming (OpenAI-compat path)", () => {
|
|
16
|
+
const m = MODELS.find((x) => x.id === "moonshotai/kimi-k3");
|
|
17
|
+
expect(m).toBeDefined();
|
|
18
|
+
expect(m?.provider).toBe("moonshotai");
|
|
19
|
+
expect(m?.type).toBe("chat");
|
|
20
|
+
expect(m?.streaming).toBe(true);
|
|
21
|
+
// Multimodal-in unsmoked; attach affordance stays off (OpenAI convention).
|
|
22
|
+
expect(m?.capabilities).toEqual([]);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Adversarial audit medium finding: stream allowlist must include moonshotai
|
|
26
|
+
// or handleChatStream 501s before runChatStream can route to callOpenAIStream.
|
|
27
|
+
it("handleChatStream allowlist includes moonshotai (no 501 before dispatch)", () => {
|
|
28
|
+
expect(chatSrc).toMatch(/model\.provider !== "moonshotai"/);
|
|
29
|
+
expect(chatSrc).toMatch(/provider === "openai" \|\| model\.provider === "moonshotai"/);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("adds Grok Imagine Image as xai image", () => {
|
|
33
|
+
const m = MODELS.find((x) => x.id === "xai/grok-imagine-image");
|
|
34
|
+
expect(m).toBeDefined();
|
|
35
|
+
expect(m?.provider).toBe("xai");
|
|
36
|
+
expect(m?.type).toBe("image");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("adds Seedream 5 Pro as bytedance image", () => {
|
|
40
|
+
const m = MODELS.find((x) => x.id === "bytedance/seedream-5-pro");
|
|
41
|
+
expect(m).toBeDefined();
|
|
42
|
+
expect(m?.provider).toBe("bytedance");
|
|
43
|
+
expect(m?.type).toBe("image");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("keeps Workers AI Kimi K2.x distinct from third-party K3", () => {
|
|
47
|
+
expect(MODELS.find((x) => x.id === "@cf/moonshotai/kimi-k2.6")).toBeDefined();
|
|
48
|
+
expect(MODELS.find((x) => x.id === "@cf/moonshotai/kimi-k2.7-code")).toBeDefined();
|
|
49
|
+
expect(MODELS.find((x) => x.id === "moonshotai/kimi-k3")).toBeDefined();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Catalog pins for the v0.172.0 Sprint 3 image-sibling adds (data-only).
|
|
2
|
+
|
|
3
|
+
import { describe, it, expect } from "vitest";
|
|
4
|
+
import { MODELS } from "../src/models";
|
|
5
|
+
|
|
6
|
+
describe("v0.172.0 sprint 3 catalog entries", () => {
|
|
7
|
+
const cases: Array<{ id: string; provider: string }> = [
|
|
8
|
+
{ id: "google/nano-banana-2-lite", provider: "google" },
|
|
9
|
+
{ id: "recraft/recraftv4-1", provider: "recraft" },
|
|
10
|
+
{ id: "xai/grok-imagine-image-quality", provider: "xai" },
|
|
11
|
+
{ id: "bytedance/seedream-5-lite", provider: "bytedance" },
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
for (const c of cases) {
|
|
15
|
+
it(`adds ${c.id} as ${c.provider} image`, () => {
|
|
16
|
+
const m = MODELS.find((x) => x.id === c.id);
|
|
17
|
+
expect(m).toBeDefined();
|
|
18
|
+
expect(m?.provider).toBe(c.provider);
|
|
19
|
+
expect(m?.type).toBe("image");
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
it("keeps pro/base siblings alongside the new tier rows", () => {
|
|
24
|
+
expect(MODELS.find((x) => x.id === "google/nano-banana-2")).toBeDefined();
|
|
25
|
+
expect(MODELS.find((x) => x.id === "recraft/recraftv4-1-pro")).toBeDefined();
|
|
26
|
+
expect(MODELS.find((x) => x.id === "xai/grok-imagine-image")).toBeDefined();
|
|
27
|
+
expect(MODELS.find((x) => x.id === "bytedance/seedream-5-pro")).toBeDefined();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// Tests for the v0.170.0 binding dispatch in src/providers/xai.ts.
|
|
2
|
+
//
|
|
3
|
+
// xai/grok-4.5 is flagged binding: true, so callXai / callXaiStream route
|
|
4
|
+
// through env.AI.run (Unified Billing catalog) instead of the legacy AI Gateway
|
|
5
|
+
// grok provider fetch. Mirrors tests/anthropic-binding.test.ts.
|
|
6
|
+
|
|
7
|
+
import { describe, it, expect } from "vitest";
|
|
8
|
+
import type { AiContext } from "../src/ai-binding";
|
|
9
|
+
import type { ModelEntry } from "../src/models";
|
|
10
|
+
import { MODELS } from "../src/models";
|
|
11
|
+
import { callXai, callXaiStream } from "../src/providers/xai";
|
|
12
|
+
import type { ProviderStreamEvent } from "../src/parsers/types";
|
|
13
|
+
|
|
14
|
+
const grok45: ModelEntry = {
|
|
15
|
+
id: "xai/grok-4.5",
|
|
16
|
+
label: "Grok 4.5 (xAI)",
|
|
17
|
+
group: "Chat · xAI",
|
|
18
|
+
type: "chat",
|
|
19
|
+
capabilities: ["vision"],
|
|
20
|
+
provider: "xai",
|
|
21
|
+
streaming: true,
|
|
22
|
+
binding: true,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type RunCall = { model: string; params: Record<string, unknown>; opts: unknown };
|
|
26
|
+
|
|
27
|
+
function fakeCtx(runImpl: (model: string, params: unknown, opts: unknown) => Promise<unknown>): { ctx: AiContext; calls: RunCall[] } {
|
|
28
|
+
const calls: RunCall[] = [];
|
|
29
|
+
const env = {
|
|
30
|
+
AI: {
|
|
31
|
+
run: (model: string, params: unknown, opts: unknown) => {
|
|
32
|
+
calls.push({ model, params: params as Record<string, unknown>, opts });
|
|
33
|
+
return runImpl(model, params, opts);
|
|
34
|
+
},
|
|
35
|
+
aiGatewayLogId: "log-xai-123",
|
|
36
|
+
},
|
|
37
|
+
} as unknown as AiContext["env"];
|
|
38
|
+
const ctx = { env, gateway: { gatewayId: "skyphusion-llm", cfAigToken: "tok" } } as unknown as AiContext;
|
|
39
|
+
return { ctx, calls };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function sseStream(frames: unknown[], chunkSize = 11): ReadableStream<Uint8Array> {
|
|
43
|
+
const text = frames.map((f) => "data: " + JSON.stringify(f) + "\n\n").join("") + "data: [DONE]\n\n";
|
|
44
|
+
const bytes = new TextEncoder().encode(text);
|
|
45
|
+
let i = 0;
|
|
46
|
+
return new ReadableStream<Uint8Array>({
|
|
47
|
+
pull(controller) {
|
|
48
|
+
if (i >= bytes.length) { controller.close(); return; }
|
|
49
|
+
const end = Math.min(i + chunkSize, bytes.length);
|
|
50
|
+
controller.enqueue(bytes.slice(i, end));
|
|
51
|
+
i = end;
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const userMessages = [{ role: "user", content: "hi" }];
|
|
57
|
+
|
|
58
|
+
describe("catalog", () => {
|
|
59
|
+
it("has grok-4.5 flagged binding: true, provider xai, streaming, vision", () => {
|
|
60
|
+
const m = MODELS.find((x) => x.id === "xai/grok-4.5");
|
|
61
|
+
expect(m).toBeDefined();
|
|
62
|
+
expect(m?.binding).toBe(true);
|
|
63
|
+
expect(m?.provider).toBe("xai");
|
|
64
|
+
expect(m?.streaming).toBe(true);
|
|
65
|
+
expect(m?.capabilities).toContain("vision");
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe("callXai binding dispatch (non-stream)", () => {
|
|
70
|
+
const completion = {
|
|
71
|
+
id: "chatcmpl-test",
|
|
72
|
+
object: "chat.completion",
|
|
73
|
+
choices: [{ message: { role: "assistant", content: "hello" }, finish_reason: "stop" }],
|
|
74
|
+
usage: { prompt_tokens: 3, completion_tokens: 1, total_tokens: 4 },
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
it("calls env.AI.run with the full catalog id and Chat Completions body", async () => {
|
|
78
|
+
const { ctx, calls } = fakeCtx(async () => completion);
|
|
79
|
+
const { raw, logId } = await callXai(ctx, grok45, userMessages);
|
|
80
|
+
|
|
81
|
+
expect(raw).toBe(completion);
|
|
82
|
+
expect(logId).toBe("log-xai-123");
|
|
83
|
+
expect(calls).toHaveLength(1);
|
|
84
|
+
expect(calls[0].model).toBe("xai/grok-4.5");
|
|
85
|
+
expect(calls[0].opts).toEqual({ gateway: { id: "skyphusion-llm" } });
|
|
86
|
+
|
|
87
|
+
const p = calls[0].params;
|
|
88
|
+
expect(p.messages).toEqual(userMessages);
|
|
89
|
+
expect(p.max_completion_tokens).toBe(4096);
|
|
90
|
+
expect(p.stream).toBeUndefined();
|
|
91
|
+
// Binding path does not strip the xai/ prefix into a separate model field.
|
|
92
|
+
expect(p.model).toBeUndefined();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("a non-binding xai model does NOT take the binding path", async () => {
|
|
96
|
+
const { ctx, calls } = fakeCtx(async () => completion);
|
|
97
|
+
const legacy: ModelEntry = { ...grok45, id: "xai/grok-4.3", binding: undefined };
|
|
98
|
+
await expect(callXai(ctx, legacy, userMessages)).rejects.toThrow();
|
|
99
|
+
expect(calls).toHaveLength(0);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe("callXaiStream binding dispatch", () => {
|
|
104
|
+
it("streams OpenAI-compatible SSE through interpretXaiSSEFrame", async () => {
|
|
105
|
+
const frames = [
|
|
106
|
+
{ choices: [{ delta: { content: "Hel" } }] },
|
|
107
|
+
{ choices: [{ delta: { content: "lo" } }] },
|
|
108
|
+
{ choices: [], usage: { prompt_tokens: 2, completion_tokens: 2, total_tokens: 4 } },
|
|
109
|
+
];
|
|
110
|
+
const { ctx, calls } = fakeCtx(async () => sseStream(frames));
|
|
111
|
+
const ac = new AbortController();
|
|
112
|
+
const events: ProviderStreamEvent[] = [];
|
|
113
|
+
for await (const e of callXaiStream(ctx, grok45, userMessages, ac.signal)) {
|
|
114
|
+
events.push(e);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
expect(calls).toHaveLength(1);
|
|
118
|
+
expect(calls[0].model).toBe("xai/grok-4.5");
|
|
119
|
+
expect(calls[0].params.stream).toBe(true);
|
|
120
|
+
expect(calls[0].params.stream_options).toEqual({ include_usage: true });
|
|
121
|
+
expect(events).toEqual([
|
|
122
|
+
{ type: "text", text: "Hel" },
|
|
123
|
+
{ type: "text", text: "lo" },
|
|
124
|
+
{ type: "usage", in_: 2, out_: 2 },
|
|
125
|
+
]);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -143,6 +143,10 @@ describe("routing + 404 fallthrough", () => {
|
|
|
143
143
|
});
|
|
144
144
|
|
|
145
145
|
describe("getUserEmail header / anonymous fallback (src/index.ts:204)", () => {
|
|
146
|
+
beforeEach(() => {
|
|
147
|
+
(env as unknown as { ACCESS_ALLOW_ANONYMOUS?: string }).ACCESS_ALLOW_ANONYMOUS = "1";
|
|
148
|
+
});
|
|
149
|
+
|
|
146
150
|
it("falls back to anonymous when the Access header is absent", async () => {
|
|
147
151
|
const res = await req("/api/models");
|
|
148
152
|
const body = (await res.json()) as { user: string };
|
|
@@ -292,8 +296,11 @@ describe("gateway 412 refusal path", () => {
|
|
|
292
296
|
body: { model: WORKERS_AI_CHAT, user_input: "hi" },
|
|
293
297
|
});
|
|
294
298
|
expect(res.status).toBe(412);
|
|
295
|
-
const body = (await res.json()) as { error: string };
|
|
296
|
-
|
|
299
|
+
const body = (await res.json()) as { error: string; code?: string };
|
|
300
|
+
// Copy mentions both BYOK gateway and control-plane pcp_ (v0.175.3).
|
|
301
|
+
expect(body.code).toBe("gateway_not_configured");
|
|
302
|
+
expect(body.error).toContain("Inference not configured");
|
|
303
|
+
expect(body.error).toMatch(/pcp_/);
|
|
297
304
|
});
|
|
298
305
|
|
|
299
306
|
it("positive control: once a gateway id is set, the 412 gate no longer fires", async () => {
|
|
@@ -2,11 +2,13 @@ name = "skyphusion-llm"
|
|
|
2
2
|
main = "src/index.ts"
|
|
3
3
|
compatibility_date = "2026-05-01"
|
|
4
4
|
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
5
|
+
# Live play.skyphusion.org runs AUTH_MODE=public (first-party signup; CF Access
|
|
6
|
+
# is NOT used on play). Private self-hosts typically use AUTH_MODE=access with
|
|
7
|
+
# Access on a custom domain. Either way, keep workers_dev = false so the
|
|
8
|
+
# *.workers.dev URL is not an ungated alternate surface. NOTE: this is the
|
|
9
|
+
# committed TEMPLATE; the live worker deploys from the per-deployer
|
|
10
|
+
# wrangler.toml (gitignored), so set it there too and redeploy
|
|
11
|
+
# (defense-in-depth; fleet-chezmoi#46).
|
|
10
12
|
workers_dev = false
|
|
11
13
|
|
|
12
14
|
# No scheduled tasks. The render-notify sweep that used a `*/3` cron (resolving
|
|
@@ -124,6 +126,12 @@ enabled = true
|
|
|
124
126
|
# gateway fallback stays available. This is the default (back-compat).
|
|
125
127
|
# [vars]
|
|
126
128
|
# AUTH_MODE = "public"
|
|
129
|
+
# Control plane (v0.175.0): optional metered chat via prism-control-plane.
|
|
130
|
+
# Users store only a pcp_ key in prefs; origin is NOT user-set (SSRF).
|
|
131
|
+
# Default allowlisted host is play-proxy.skyphusion.org. Do NOT add another
|
|
132
|
+
# commented vars header (CI uncomments every "# [vars]" line and TOML breaks).
|
|
133
|
+
# CONTROL_PLANE_URL = "https://play-proxy.skyphusion.org"
|
|
134
|
+
# CONTROL_PLANE_ALLOW_LOCALHOST = "true"
|
|
127
135
|
|
|
128
136
|
# Note: GATEWAY_ID is set as a worker secret rather than a var in this file
|
|
129
137
|
# (v0.12.0+). This keeps deployer-specific values out of the committed template.
|
|
@@ -132,11 +140,15 @@ enabled = true
|
|
|
132
140
|
# For local development, also add it to .dev.vars:
|
|
133
141
|
# GATEWAY_ID=your-gateway-slug
|
|
134
142
|
#
|
|
135
|
-
# Public
|
|
143
|
+
# Public mode (v0.167.0+): omit GATEWAY_ID and CF_AIG_TOKEN on the worker.
|
|
136
144
|
# Each visitor stores their own gateway slug + token via Account > AI Gateway
|
|
137
|
-
# (/api/prefs in D1 user_prefs).
|
|
145
|
+
# (/api/prefs in D1 user_prefs). No Cloudflare Access needed when AUTH_MODE=public.
|
|
138
146
|
#
|
|
139
147
|
# Other worker secrets (also set via `npx wrangler secret put <NAME>`):
|
|
148
|
+
# OPENAI_API_KEY (optional sole BYOK carve-out, v0.174.0): when set,
|
|
149
|
+
# openai/gpt-image-* call api.openai.com directly for transparent PNG
|
|
150
|
+
# (background + output_format). When unset, those models stay on Unified
|
|
151
|
+
# Billing and render opaque. No other provider reads a deployer key.
|
|
140
152
|
# CF_AIG_TOKEN (required for Anthropic, xAI, OpenAI chat, Google, and proxied
|
|
141
153
|
# image/video/music on Unified Billing when using worker-level
|
|
142
154
|
# credentials; optional in public demo mode where users supply
|