@skyphusion/create-prism 1.2.0 → 1.3.1

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.
@@ -54,6 +54,18 @@ bucket_name = "skyphusion-llm"
54
54
  binding = "VEC"
55
55
  index_name = "skyphusion-llm-vec"
56
56
 
57
+ # Opt-in web search. Service binding to the skyphusion-search Worker,
58
+ # named entrypoint SearchEntrypoint, method search(question). Source
59
+ # repo skyphusion-labs/search-mcp. This is not POST /ask: that route
60
+ # checks Origin and Turnstile. Self-hosters who do not run that worker
61
+ # delete this block: wrangler deploy fails when the named service does
62
+ # not exist. With the binding absent, that source reports status
63
+ # "absent" and Wikipedia still runs.
64
+ [[services]]
65
+ binding = "SEARCH"
66
+ service = "skyphusion-search"
67
+ entrypoint = "SearchEntrypoint"
68
+
57
69
  # Static frontend (HTML, CSS, JS).
58
70
  [assets]
59
71
  directory = "./public"
@@ -195,12 +207,5 @@ enabled = true
195
207
  # CF_AIG_TOKEN (required for Anthropic, xAI, OpenAI chat, Google, and proxied
196
208
  # image/video/music on Unified Billing when using worker-level
197
209
  # credentials; optional in public demo mode where users supply
198
- # their own token via /api/prefs; v0.93.0+),
199
- # SEARXNG_URL (optional, v0.166.0; base URL of a self-hosted SearXNG instance
200
- # for the opt-in web-search source, e.g. https://search.skyphusion.org.
201
- # May be a plain [vars] entry instead of a secret. Skipped when
202
- # unset; Wikipedia still runs keyless),
203
- # SEARXNG_ACCESS_CLIENT_ID / SEARXNG_ACCESS_CLIENT_SECRET (optional, v0.166.0;
204
- # Cloudflare Access service-token halves for a gated SearXNG
205
- # instance. Sent as CF-Access-Client-Id / CF-Access-Client-Secret
206
- # only when BOTH are set; leave unset for an un-gated instance).
210
+ # their own token via /api/prefs; v0.93.0+).
211
+ # Web search uses the SEARCH service binding above. It does not take a secret.
@@ -1,75 +0,0 @@
1
- // SearXNG web retrieval (v0.166.0).
2
- //
3
- // Self-hosted metasearch source, slotted in beside the keyless Wikipedia
4
- // retriever (replacing the retired Tavily + Brave SaaS sources, prism#93).
5
- // Requests the JSON API: GET {SEARXNG_URL}/search?q=...&format=json.
6
- //
7
- // When the instance is gated by Cloudflare Access (our deploy at
8
- // search.skyphusion.org is), a per-function Access service token is sent as
9
- // the standard CF-Access-Client-Id / CF-Access-Client-Secret headers. A
10
- // self-hoster running an un-gated instance sets neither, and no Access headers
11
- // are sent.
12
-
13
- export interface SearxngHit {
14
- title: string;
15
- url: string;
16
- snippet: string;
17
- }
18
-
19
- // Pure parser for the SearXNG JSON response. The relevant shape is
20
- // { results: [ { url, title, content }, ... ] }; other top-level keys
21
- // (query, number_of_results, suggestions, ...) are ignored. Rows missing a
22
- // url or title are dropped; content is the snippet (may be absent).
23
- export function mapSearxngResults(data: unknown, maxResults: number): SearxngHit[] {
24
- const root = data as {
25
- results?: Array<{ title?: string; url?: string; content?: string }>;
26
- };
27
- const items = root.results ?? [];
28
- return items
29
- .filter((r) => r.url && r.title)
30
- .slice(0, maxResults)
31
- .map((r) => ({
32
- title: r.title!,
33
- url: r.url!,
34
- snippet: normalizeSearxngSnippet(r.content ?? ""),
35
- }));
36
- }
37
-
38
- function normalizeSearxngSnippet(text: string): string {
39
- return text.replace(/\s+/g, " ").trim();
40
- }
41
-
42
- export async function searchSearxngWeb(
43
- baseUrl: string,
44
- query: string,
45
- opts: {
46
- maxResults: number;
47
- timeoutMs: number;
48
- accessClientId?: string;
49
- accessClientSecret?: string;
50
- },
51
- ): Promise<SearxngHit[]> {
52
- // baseUrl may or may not carry a trailing slash; URL() with an absolute
53
- // "/search" path normalizes either way.
54
- const url = new URL("/search", baseUrl);
55
- url.searchParams.set("q", query);
56
- url.searchParams.set("format", "json");
57
-
58
- const headers: Record<string, string> = { Accept: "application/json" };
59
- // Access service-token headers are sent ONLY when both halves are set, so an
60
- // un-gated self-hosted instance is reached with no headers.
61
- if (opts.accessClientId && opts.accessClientSecret) {
62
- headers["CF-Access-Client-Id"] = opts.accessClientId;
63
- headers["CF-Access-Client-Secret"] = opts.accessClientSecret;
64
- }
65
-
66
- const resp = await fetch(url.toString(), {
67
- headers,
68
- signal: AbortSignal.timeout(opts.timeoutMs),
69
- });
70
- if (!resp.ok) {
71
- throw new Error(`SearXNG ${resp.status}: ${(await resp.text()).slice(0, 200)}`);
72
- }
73
- const data: unknown = await resp.json();
74
- return mapSearxngResults(data, opts.maxResults);
75
- }
@@ -1,51 +0,0 @@
1
- import { describe, it, expect } from "vitest";
2
- import { mapSearxngResults } from "../src/searxng";
3
-
4
- describe("mapSearxngResults", () => {
5
- it("maps results into title/url/snippet hits", () => {
6
- const data = {
7
- query: "cloudflare workers",
8
- number_of_results: 2,
9
- results: [
10
- { title: "Example", url: "https://example.com/a", content: "First hit." },
11
- { title: "Other", url: "https://example.com/b", content: "Second hit." },
12
- ],
13
- };
14
- expect(mapSearxngResults(data, 5)).toEqual([
15
- { title: "Example", url: "https://example.com/a", snippet: "First hit." },
16
- { title: "Other", url: "https://example.com/b", snippet: "Second hit." },
17
- ]);
18
- });
19
-
20
- it("drops rows missing title or url and respects maxResults", () => {
21
- const data = {
22
- results: [
23
- { title: "Keep", url: "https://example.com/keep", content: "ok" },
24
- { title: "No URL", content: "skip" },
25
- { url: "https://example.com/no-title", content: "skip" },
26
- { title: "Third", url: "https://example.com/third", content: "ok" },
27
- ],
28
- };
29
- expect(mapSearxngResults(data, 1)).toEqual([
30
- { title: "Keep", url: "https://example.com/keep", snippet: "ok" },
31
- ]);
32
- });
33
-
34
- it("collapses whitespace in snippets and tolerates a missing content field", () => {
35
- const data = {
36
- results: [
37
- { title: "Spacey", url: "https://example.com/s", content: " multi line\n\ttext " },
38
- { title: "NoContent", url: "https://example.com/n" },
39
- ],
40
- };
41
- expect(mapSearxngResults(data, 5)).toEqual([
42
- { title: "Spacey", url: "https://example.com/s", snippet: "multi line text" },
43
- { title: "NoContent", url: "https://example.com/n", snippet: "" },
44
- ]);
45
- });
46
-
47
- it("returns an empty array when results is missing", () => {
48
- expect(mapSearxngResults({}, 5)).toEqual([]);
49
- expect(mapSearxngResults({ results: [] }, 5)).toEqual([]);
50
- });
51
- });