mirror of
https://github.com/kennethnym/aris.git
synced 2026-06-13 11:01:18 +01:00
Compare commits
1 Commits
master
...
feat/mcp-p
| Author | SHA1 | Date | |
|---|---|---|---|
|
6e17050cdf
|
@@ -66,20 +66,6 @@ export function SourceConfigPanel({ source, onUpdate }: SourceConfigPanelProps)
|
|||||||
return creds
|
return creds
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasUserConfigFields(): boolean {
|
|
||||||
return Object.values(source.fields).some((field) => !isCredentialField(field))
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildReplaceBody(enabledValue: boolean): Parameters<typeof replaceSource>[1] {
|
|
||||||
const body: Parameters<typeof replaceSource>[1] = { enabled: enabledValue }
|
|
||||||
|
|
||||||
if (hasUserConfigFields()) {
|
|
||||||
body.config = getUserConfig()
|
|
||||||
}
|
|
||||||
|
|
||||||
return body
|
|
||||||
}
|
|
||||||
|
|
||||||
function invalidate() {
|
function invalidate() {
|
||||||
queryClient.invalidateQueries({ queryKey: ["sourceConfig", source.id] })
|
queryClient.invalidateQueries({ queryKey: ["sourceConfig", source.id] })
|
||||||
queryClient.invalidateQueries({ queryKey: ["configs"] })
|
queryClient.invalidateQueries({ queryKey: ["configs"] })
|
||||||
@@ -93,7 +79,10 @@ export function SourceConfigPanel({ source, onUpdate }: SourceConfigPanelProps)
|
|||||||
(v) => typeof v === "string" && v.length > 0,
|
(v) => typeof v === "string" && v.length > 0,
|
||||||
)
|
)
|
||||||
|
|
||||||
const body = buildReplaceBody(enabled)
|
const body: Parameters<typeof replaceSource>[1] = {
|
||||||
|
enabled,
|
||||||
|
config: getUserConfig(),
|
||||||
|
}
|
||||||
if (hasCredentials && source.perUserCredentials) {
|
if (hasCredentials && source.perUserCredentials) {
|
||||||
body.credentials = credentialFields
|
body.credentials = credentialFields
|
||||||
}
|
}
|
||||||
@@ -115,7 +104,8 @@ export function SourceConfigPanel({ source, onUpdate }: SourceConfigPanelProps)
|
|||||||
})
|
})
|
||||||
|
|
||||||
const toggleMutation = useMutation({
|
const toggleMutation = useMutation({
|
||||||
mutationFn: (checked: boolean) => replaceSource(source.id, buildReplaceBody(checked)),
|
mutationFn: (checked: boolean) =>
|
||||||
|
replaceSource(source.id, { enabled: checked, config: getUserConfig() }),
|
||||||
onSuccess(_data, checked) {
|
onSuccess(_data, checked) {
|
||||||
invalidate()
|
invalidate()
|
||||||
toast.success(`Source ${checked ? "enabled" : "disabled"}`)
|
toast.success(`Source ${checked ? "enabled" : "disabled"}`)
|
||||||
@@ -126,7 +116,7 @@ export function SourceConfigPanel({ source, onUpdate }: SourceConfigPanelProps)
|
|||||||
})
|
})
|
||||||
|
|
||||||
const deleteMutation = useMutation({
|
const deleteMutation = useMutation({
|
||||||
mutationFn: () => replaceSource(source.id, buildReplaceBody(false)),
|
mutationFn: () => replaceSource(source.id, { enabled: false, config: {} }),
|
||||||
onSuccess() {
|
onSuccess() {
|
||||||
setDirty({})
|
setDirty({})
|
||||||
invalidate()
|
invalidate()
|
||||||
|
|||||||
@@ -151,18 +151,6 @@ const sourceDefinitions: SourceDefinition[] = [
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
id: "freya.web-search",
|
|
||||||
name: "Web Search",
|
|
||||||
description: "Exa web search action. Requires EXA_API_KEY on the backend.",
|
|
||||||
fields: {},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "freya.google-maps",
|
|
||||||
name: "Google Maps",
|
|
||||||
description: "Google Maps Grounding Lite MCP tools for places, weather, routes, and Place IDs.",
|
|
||||||
fields: {},
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
|
|
||||||
export function fetchSources(): Promise<SourceDefinition[]> {
|
export function fetchSources(): Promise<SourceDefinition[]> {
|
||||||
@@ -186,7 +174,7 @@ export async function fetchConfigs(): Promise<SourceConfig[]> {
|
|||||||
|
|
||||||
export async function replaceSource(
|
export async function replaceSource(
|
||||||
sourceId: string,
|
sourceId: string,
|
||||||
body: { enabled: boolean; config?: unknown; credentials?: Record<string, unknown> },
|
body: { enabled: boolean; config: unknown; credentials?: Record<string, unknown> },
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const res = await fetch(`${serverBase()}/sources/${sourceId}`, {
|
const res = await fetch(`${serverBase()}/sources/${sourceId}`, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import {
|
|||||||
Loader2,
|
Loader2,
|
||||||
TrainFront,
|
TrainFront,
|
||||||
LogOut,
|
LogOut,
|
||||||
Map as MapIcon,
|
|
||||||
MapPin,
|
MapPin,
|
||||||
Rss,
|
Rss,
|
||||||
Server,
|
Server,
|
||||||
@@ -50,7 +49,6 @@ const SOURCE_ICONS: Record<string, React.ComponentType<{ className?: string }>>
|
|||||||
"freya.weather": CloudSun,
|
"freya.weather": CloudSun,
|
||||||
"freya.caldav": CalendarDays,
|
"freya.caldav": CalendarDays,
|
||||||
"freya.google-calendar": Calendar,
|
"freya.google-calendar": Calendar,
|
||||||
"freya.google-maps": MapIcon,
|
|
||||||
"freya.tfl": TrainFront,
|
"freya.tfl": TrainFront,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,11 +18,9 @@
|
|||||||
"@freya/core": "workspace:*",
|
"@freya/core": "workspace:*",
|
||||||
"@freya/source-caldav": "workspace:*",
|
"@freya/source-caldav": "workspace:*",
|
||||||
"@freya/source-google-calendar": "workspace:*",
|
"@freya/source-google-calendar": "workspace:*",
|
||||||
"@freya/source-google-maps": "workspace:*",
|
|
||||||
"@freya/source-location": "workspace:*",
|
"@freya/source-location": "workspace:*",
|
||||||
"@freya/source-tfl": "workspace:*",
|
"@freya/source-tfl": "workspace:*",
|
||||||
"@freya/source-weatherkit": "workspace:*",
|
"@freya/source-weatherkit": "workspace:*",
|
||||||
"@freya/source-web-search": "workspace:*",
|
|
||||||
"@openrouter/sdk": "^0.9.11",
|
"@openrouter/sdk": "^0.9.11",
|
||||||
"arktype": "^2.1.29",
|
"arktype": "^2.1.29",
|
||||||
"better-auth": "^1",
|
"better-auth": "^1",
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
import type { GoogleMapsSourceOptions } from "@freya/source-google-maps"
|
|
||||||
|
|
||||||
import { describe, expect, test } from "bun:test"
|
|
||||||
|
|
||||||
import { GoogleMapsSourceProvider } from "./provider.ts"
|
|
||||||
|
|
||||||
type McpClient = NonNullable<GoogleMapsSourceOptions["client"]>
|
|
||||||
|
|
||||||
class MockMcpClient implements McpClient {
|
|
||||||
async listTools(): ReturnType<McpClient["listTools"]> {
|
|
||||||
return { tools: [] }
|
|
||||||
}
|
|
||||||
|
|
||||||
async readResource(
|
|
||||||
_params: Parameters<McpClient["readResource"]>[0],
|
|
||||||
): ReturnType<McpClient["readResource"]> {
|
|
||||||
throw new Error("unexpected resource read")
|
|
||||||
}
|
|
||||||
|
|
||||||
async callTool(_params: Parameters<McpClient["callTool"]>[0]): ReturnType<McpClient["callTool"]> {
|
|
||||||
return { structuredContent: {} }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("GoogleMapsSourceProvider", () => {
|
|
||||||
test("sourceId is freya.google-maps", () => {
|
|
||||||
const provider = new GoogleMapsSourceProvider({ apiKey: "key" })
|
|
||||||
expect(provider.sourceId).toBe("freya.google-maps")
|
|
||||||
})
|
|
||||||
|
|
||||||
test("throws when service API key is empty", () => {
|
|
||||||
expect(() => new GoogleMapsSourceProvider({ apiKey: "" })).toThrow(
|
|
||||||
"Google Maps MCP API key must be configured",
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("returns source with service API key", async () => {
|
|
||||||
const provider = new GoogleMapsSourceProvider({ apiKey: "key" })
|
|
||||||
|
|
||||||
const source = await provider.feedSourceForUser("user-1", {}, null)
|
|
||||||
|
|
||||||
expect(source.id).toBe("freya.google-maps")
|
|
||||||
})
|
|
||||||
|
|
||||||
test("allows injected test client with service API key", async () => {
|
|
||||||
const provider = new GoogleMapsSourceProvider({
|
|
||||||
apiKey: "key",
|
|
||||||
client: new MockMcpClient(),
|
|
||||||
})
|
|
||||||
|
|
||||||
const source = await provider.feedSourceForUser("user-1", {}, null)
|
|
||||||
|
|
||||||
expect(source.id).toBe("freya.google-maps")
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
import { GoogleMapsSource, type GoogleMapsSourceOptions } from "@freya/source-google-maps"
|
|
||||||
|
|
||||||
import type { FeedSourceProvider } from "../session/feed-source-provider.ts"
|
|
||||||
|
|
||||||
export interface GoogleMapsSourceProviderOptions {
|
|
||||||
readonly apiKey: string
|
|
||||||
readonly client?: GoogleMapsSourceOptions["client"]
|
|
||||||
}
|
|
||||||
|
|
||||||
export class GoogleMapsSourceProvider implements FeedSourceProvider {
|
|
||||||
readonly sourceId = "freya.google-maps"
|
|
||||||
|
|
||||||
private readonly apiKey: string
|
|
||||||
private readonly client: GoogleMapsSourceProviderOptions["client"]
|
|
||||||
|
|
||||||
constructor(options: GoogleMapsSourceProviderOptions) {
|
|
||||||
if (!nonEmptyString(options.apiKey)) {
|
|
||||||
throw new Error("Google Maps MCP API key must be configured")
|
|
||||||
}
|
|
||||||
|
|
||||||
this.apiKey = options.apiKey
|
|
||||||
this.client = options.client
|
|
||||||
}
|
|
||||||
|
|
||||||
async feedSourceForUser(
|
|
||||||
_userId: string,
|
|
||||||
_config: unknown,
|
|
||||||
_credentials: unknown,
|
|
||||||
): Promise<GoogleMapsSource> {
|
|
||||||
return new GoogleMapsSource({
|
|
||||||
apiKey: this.apiKey,
|
|
||||||
client: this.client,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function nonEmptyString(value: string): boolean {
|
|
||||||
return typeof value === "string" && value.trim().length > 0
|
|
||||||
}
|
|
||||||
@@ -11,7 +11,6 @@ import { createDatabase } from "./db/index.ts"
|
|||||||
import { registerFeedHttpHandlers } from "./engine/http.ts"
|
import { registerFeedHttpHandlers } from "./engine/http.ts"
|
||||||
import { createFeedEnhancer } from "./enhancement/enhance-feed.ts"
|
import { createFeedEnhancer } from "./enhancement/enhance-feed.ts"
|
||||||
import { createLlmClient } from "./enhancement/llm-client.ts"
|
import { createLlmClient } from "./enhancement/llm-client.ts"
|
||||||
import { GoogleMapsSourceProvider } from "./google-maps/provider.ts"
|
|
||||||
import { CredentialEncryptor } from "./lib/crypto.ts"
|
import { CredentialEncryptor } from "./lib/crypto.ts"
|
||||||
import { registerLocationHttpHandlers } from "./location/http.ts"
|
import { registerLocationHttpHandlers } from "./location/http.ts"
|
||||||
import { LocationSourceProvider } from "./location/provider.ts"
|
import { LocationSourceProvider } from "./location/provider.ts"
|
||||||
@@ -19,7 +18,6 @@ import { UserSessionManager } from "./session/index.ts"
|
|||||||
import { registerSourcesHttpHandlers } from "./sources/http.ts"
|
import { registerSourcesHttpHandlers } from "./sources/http.ts"
|
||||||
import { TflSourceProvider } from "./tfl/provider.ts"
|
import { TflSourceProvider } from "./tfl/provider.ts"
|
||||||
import { WeatherSourceProvider } from "./weather/provider.ts"
|
import { WeatherSourceProvider } from "./weather/provider.ts"
|
||||||
import { WebSearchSourceProvider } from "./web-search/provider.ts"
|
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
const { db, close: closeDb } = createDatabase(process.env.DATABASE_URL!)
|
const { db, close: closeDb } = createDatabase(process.env.DATABASE_URL!)
|
||||||
@@ -48,11 +46,6 @@ function main() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const googleMapsApiKey = process.env.GOOGLE_MAPS_API_KEY ?? process.env.GOOGLE_MAPS_MCP_API_KEY
|
|
||||||
if (!googleMapsApiKey) {
|
|
||||||
throw new Error("GOOGLE_MAPS_API_KEY or GOOGLE_MAPS_MCP_API_KEY must be set")
|
|
||||||
}
|
|
||||||
|
|
||||||
const sessionManager = new UserSessionManager({
|
const sessionManager = new UserSessionManager({
|
||||||
db,
|
db,
|
||||||
providers: [
|
providers: [
|
||||||
@@ -67,10 +60,6 @@ function main() {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
new TflSourceProvider({ apiKey: process.env.TFL_API_KEY! }),
|
new TflSourceProvider({ apiKey: process.env.TFL_API_KEY! }),
|
||||||
new WebSearchSourceProvider({ apiKey: process.env.EXA_API_KEY }),
|
|
||||||
new GoogleMapsSourceProvider({
|
|
||||||
apiKey: googleMapsApiKey,
|
|
||||||
}),
|
|
||||||
],
|
],
|
||||||
feedEnhancer,
|
feedEnhancer,
|
||||||
credentialEncryptor,
|
credentialEncryptor,
|
||||||
|
|||||||
@@ -186,18 +186,6 @@ function put(app: Hono, sourceId: string, body: unknown) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function listActions(app: Hono, sourceId: string) {
|
|
||||||
return app.request(`/api/sources/${sourceId}/actions`, { method: "GET" })
|
|
||||||
}
|
|
||||||
|
|
||||||
function executeAction(app: Hono, sourceId: string, actionId: string, body: unknown) {
|
|
||||||
return app.request(`/api/sources/${sourceId}/actions/${actionId}`, {
|
|
||||||
method: "POST",
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify(body),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Tests
|
// Tests
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -793,168 +781,6 @@ describe("PUT /api/sources/:sourceId", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("GET /api/sources/:sourceId/actions", () => {
|
|
||||||
test("returns 401 without auth", async () => {
|
|
||||||
activeStore = createInMemoryStore()
|
|
||||||
const { app } = createApp([createStubProvider("freya.location")])
|
|
||||||
|
|
||||||
const res = await listActions(app, "freya.location")
|
|
||||||
|
|
||||||
expect(res.status).toBe(401)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("returns 404 for source that is not enabled in the user session", async () => {
|
|
||||||
activeStore = createInMemoryStore()
|
|
||||||
const { app } = createApp([createStubProvider("freya.location")], MOCK_USER_ID)
|
|
||||||
|
|
||||||
const res = await listActions(app, "freya.location")
|
|
||||||
|
|
||||||
expect(res.status).toBe(404)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("returns serializable action definitions", async () => {
|
|
||||||
activeStore = createInMemoryStore()
|
|
||||||
activeStore.seed(MOCK_USER_ID, "test.actions")
|
|
||||||
const provider: FeedSourceProvider = {
|
|
||||||
sourceId: "test.actions",
|
|
||||||
async feedSourceForUser() {
|
|
||||||
return {
|
|
||||||
id: "test.actions",
|
|
||||||
async listActions() {
|
|
||||||
return {
|
|
||||||
search: {
|
|
||||||
id: "search",
|
|
||||||
description: "Search something",
|
|
||||||
input: tflConfig,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async executeAction() {
|
|
||||||
return undefined
|
|
||||||
},
|
|
||||||
async fetchContext() {
|
|
||||||
return null
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
const { app } = createApp([provider], MOCK_USER_ID)
|
|
||||||
|
|
||||||
const res = await listActions(app, "test.actions")
|
|
||||||
|
|
||||||
expect(res.status).toBe(200)
|
|
||||||
const body = (await res.json()) as {
|
|
||||||
actions: Record<string, { id: string; description?: string; input?: unknown }>
|
|
||||||
}
|
|
||||||
expect(body.actions.search).toEqual({
|
|
||||||
id: "search",
|
|
||||||
description: "Search something",
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("POST /api/sources/:sourceId/actions/:actionId", () => {
|
|
||||||
test("returns 401 without auth", async () => {
|
|
||||||
activeStore = createInMemoryStore()
|
|
||||||
const { app } = createApp([createStubProvider("freya.location")])
|
|
||||||
|
|
||||||
const res = await executeAction(app, "freya.location", "update-location", {})
|
|
||||||
|
|
||||||
expect(res.status).toBe(401)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("executes source action with request body as params", async () => {
|
|
||||||
activeStore = createInMemoryStore()
|
|
||||||
activeStore.seed(MOCK_USER_ID, "test.actions")
|
|
||||||
let receivedParams: unknown
|
|
||||||
const provider: FeedSourceProvider = {
|
|
||||||
sourceId: "test.actions",
|
|
||||||
async feedSourceForUser() {
|
|
||||||
return {
|
|
||||||
id: "test.actions",
|
|
||||||
async listActions() {
|
|
||||||
return {
|
|
||||||
search: { id: "search", description: "Search something" },
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async executeAction(_actionId: string, params: unknown) {
|
|
||||||
receivedParams = params
|
|
||||||
return { ok: true, count: 2 }
|
|
||||||
},
|
|
||||||
async fetchContext() {
|
|
||||||
return null
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
const { app } = createApp([provider], MOCK_USER_ID)
|
|
||||||
|
|
||||||
const res = await executeAction(app, "test.actions", "search", { query: "exa" })
|
|
||||||
|
|
||||||
expect(res.status).toBe(200)
|
|
||||||
expect(receivedParams).toEqual({ query: "exa" })
|
|
||||||
const body = (await res.json()) as { result: unknown }
|
|
||||||
expect(body.result).toEqual({ ok: true, count: 2 })
|
|
||||||
})
|
|
||||||
|
|
||||||
test("returns 404 for unknown action", async () => {
|
|
||||||
activeStore = createInMemoryStore()
|
|
||||||
activeStore.seed(MOCK_USER_ID, "freya.location")
|
|
||||||
const { app } = createApp([createStubProvider("freya.location")], MOCK_USER_ID)
|
|
||||||
|
|
||||||
const res = await executeAction(app, "freya.location", "missing", {})
|
|
||||||
|
|
||||||
expect(res.status).toBe(404)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("returns 400 for invalid JSON", async () => {
|
|
||||||
activeStore = createInMemoryStore()
|
|
||||||
activeStore.seed(MOCK_USER_ID, "freya.location")
|
|
||||||
const { app } = createApp([createStubProvider("freya.location")], MOCK_USER_ID)
|
|
||||||
|
|
||||||
const res = await app.request("/api/sources/freya.location/actions/search", {
|
|
||||||
method: "POST",
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
body: "not-json",
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(res.status).toBe(400)
|
|
||||||
const body = (await res.json()) as { error: string }
|
|
||||||
expect(body.error).toBe("Invalid JSON")
|
|
||||||
})
|
|
||||||
|
|
||||||
test("returns 400 when source rejects params", async () => {
|
|
||||||
activeStore = createInMemoryStore()
|
|
||||||
activeStore.seed(MOCK_USER_ID, "test.actions")
|
|
||||||
const provider: FeedSourceProvider = {
|
|
||||||
sourceId: "test.actions",
|
|
||||||
async feedSourceForUser() {
|
|
||||||
return {
|
|
||||||
id: "test.actions",
|
|
||||||
async listActions() {
|
|
||||||
return {
|
|
||||||
search: { id: "search" },
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async executeAction() {
|
|
||||||
throw new Error("query must not be empty")
|
|
||||||
},
|
|
||||||
async fetchContext() {
|
|
||||||
return null
|
|
||||||
},
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
const { app } = createApp([provider], MOCK_USER_ID)
|
|
||||||
|
|
||||||
const res = await executeAction(app, "test.actions", "search", { query: "" })
|
|
||||||
|
|
||||||
expect(res.status).toBe(400)
|
|
||||||
const body = (await res.json()) as { error: string }
|
|
||||||
expect(body.error).toBe("query must not be empty")
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe("PUT /api/sources/:sourceId/credentials", () => {
|
describe("PUT /api/sources/:sourceId/credentials", () => {
|
||||||
test("returns 401 without auth", async () => {
|
test("returns 401 without auth", async () => {
|
||||||
activeStore = createInMemoryStore()
|
activeStore = createInMemoryStore()
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import type { ActionDefinition } from "@freya/core"
|
|
||||||
import type { Context, Hono } from "hono"
|
import type { Context, Hono } from "hono"
|
||||||
|
|
||||||
import { type } from "arktype"
|
import { type } from "arktype"
|
||||||
@@ -56,13 +55,6 @@ export function registerSourcesHttpHandlers(
|
|||||||
app.get("/api/sources/:sourceId", inject, authSessionMiddleware, handleGetSource)
|
app.get("/api/sources/:sourceId", inject, authSessionMiddleware, handleGetSource)
|
||||||
app.patch("/api/sources/:sourceId", inject, authSessionMiddleware, handleUpdateSource)
|
app.patch("/api/sources/:sourceId", inject, authSessionMiddleware, handleUpdateSource)
|
||||||
app.put("/api/sources/:sourceId", inject, authSessionMiddleware, handleReplaceSource)
|
app.put("/api/sources/:sourceId", inject, authSessionMiddleware, handleReplaceSource)
|
||||||
app.get("/api/sources/:sourceId/actions", inject, authSessionMiddleware, handleListActions)
|
|
||||||
app.post(
|
|
||||||
"/api/sources/:sourceId/actions/:actionId",
|
|
||||||
inject,
|
|
||||||
authSessionMiddleware,
|
|
||||||
handleExecuteAction,
|
|
||||||
)
|
|
||||||
app.put(
|
app.put(
|
||||||
"/api/sources/:sourceId/credentials",
|
"/api/sources/:sourceId/credentials",
|
||||||
inject,
|
inject,
|
||||||
@@ -197,71 +189,6 @@ async function handleReplaceSource(c: Context<Env>) {
|
|||||||
return c.body(null, 204)
|
return c.body(null, 204)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleListActions(c: Context<Env>) {
|
|
||||||
const sourceId = c.req.param("sourceId")
|
|
||||||
if (!sourceId) {
|
|
||||||
return c.body(null, 404)
|
|
||||||
}
|
|
||||||
|
|
||||||
const user = c.get("user")!
|
|
||||||
const sessionManager = c.get("sessionManager")
|
|
||||||
|
|
||||||
let session
|
|
||||||
try {
|
|
||||||
session = await sessionManager.getOrCreate(user.id)
|
|
||||||
} catch (err) {
|
|
||||||
console.error("[handleListActions] Failed to create session:", err)
|
|
||||||
return c.json({ error: "Service unavailable" }, 503)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const actions = await session.engine.listActions(sourceId)
|
|
||||||
return c.json({ actions: serializeActions(actions) })
|
|
||||||
} catch (err) {
|
|
||||||
if (isActionNotFoundError(err)) {
|
|
||||||
return c.json({ error: err.message }, 404)
|
|
||||||
}
|
|
||||||
console.error(`[handleListActions] Failed to list actions for "${sourceId}":`, err)
|
|
||||||
return c.json({ error: "Failed to list actions" }, 500)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleExecuteAction(c: Context<Env>) {
|
|
||||||
const sourceId = c.req.param("sourceId")
|
|
||||||
const actionId = c.req.param("actionId")
|
|
||||||
if (!sourceId || !actionId) {
|
|
||||||
return c.body(null, 404)
|
|
||||||
}
|
|
||||||
|
|
||||||
let params: unknown
|
|
||||||
try {
|
|
||||||
params = await c.req.json()
|
|
||||||
} catch {
|
|
||||||
return c.json({ error: "Invalid JSON" }, 400)
|
|
||||||
}
|
|
||||||
|
|
||||||
const user = c.get("user")!
|
|
||||||
const sessionManager = c.get("sessionManager")
|
|
||||||
|
|
||||||
let session
|
|
||||||
try {
|
|
||||||
session = await sessionManager.getOrCreate(user.id)
|
|
||||||
} catch (err) {
|
|
||||||
console.error("[handleExecuteAction] Failed to create session:", err)
|
|
||||||
return c.json({ error: "Service unavailable" }, 503)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result = await session.engine.executeAction(sourceId, actionId, params)
|
|
||||||
return c.json({ result })
|
|
||||||
} catch (err) {
|
|
||||||
if (isActionNotFoundError(err)) {
|
|
||||||
return c.json({ error: err.message }, 404)
|
|
||||||
}
|
|
||||||
return c.json({ error: err instanceof Error ? err.message : String(err) }, 400)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleUpdateCredentials(c: Context<Env>) {
|
async function handleUpdateCredentials(c: Context<Env>) {
|
||||||
const sourceId = c.req.param("sourceId")
|
const sourceId = c.req.param("sourceId")
|
||||||
if (!sourceId) {
|
if (!sourceId) {
|
||||||
@@ -301,21 +228,3 @@ async function handleUpdateCredentials(c: Context<Env>) {
|
|||||||
|
|
||||||
return c.body(null, 204)
|
return c.body(null, 204)
|
||||||
}
|
}
|
||||||
|
|
||||||
function serializeActions(actions: Record<string, ActionDefinition>) {
|
|
||||||
const serialized: Record<string, { id: string; description?: string }> = {}
|
|
||||||
for (const [key, action] of Object.entries(actions)) {
|
|
||||||
serialized[key] = {
|
|
||||||
id: action.id,
|
|
||||||
...(action.description ? { description: action.description } : {}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return serialized
|
|
||||||
}
|
|
||||||
|
|
||||||
function isActionNotFoundError(err: unknown): err is Error {
|
|
||||||
if (!(err instanceof Error)) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return err.message.startsWith("Source not found:") || err.message.startsWith("Action ")
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,30 +0,0 @@
|
|||||||
import { WebSearchSource, type WebSearchClient } from "@freya/source-web-search"
|
|
||||||
|
|
||||||
import type { FeedSourceProvider } from "../session/feed-source-provider.ts"
|
|
||||||
|
|
||||||
export type WebSearchSourceProviderOptions =
|
|
||||||
| { apiKey: string | undefined; client?: never }
|
|
||||||
| { apiKey?: never; client: WebSearchClient }
|
|
||||||
|
|
||||||
export class WebSearchSourceProvider implements FeedSourceProvider {
|
|
||||||
readonly sourceId = "freya.web-search"
|
|
||||||
|
|
||||||
private readonly apiKey: string | undefined
|
|
||||||
private readonly client: WebSearchClient | undefined
|
|
||||||
|
|
||||||
constructor(options: WebSearchSourceProviderOptions) {
|
|
||||||
this.apiKey = "apiKey" in options ? options.apiKey : undefined
|
|
||||||
this.client = "client" in options ? options.client : undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
async feedSourceForUser(
|
|
||||||
_userId: string,
|
|
||||||
_config: unknown,
|
|
||||||
_credentials: unknown,
|
|
||||||
): Promise<WebSearchSource> {
|
|
||||||
return new WebSearchSource({
|
|
||||||
apiKey: this.apiKey,
|
|
||||||
client: this.client,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
80
bun.lock
80
bun.lock
@@ -53,11 +53,9 @@
|
|||||||
"@freya/core": "workspace:*",
|
"@freya/core": "workspace:*",
|
||||||
"@freya/source-caldav": "workspace:*",
|
"@freya/source-caldav": "workspace:*",
|
||||||
"@freya/source-google-calendar": "workspace:*",
|
"@freya/source-google-calendar": "workspace:*",
|
||||||
"@freya/source-google-maps": "workspace:*",
|
|
||||||
"@freya/source-location": "workspace:*",
|
"@freya/source-location": "workspace:*",
|
||||||
"@freya/source-tfl": "workspace:*",
|
"@freya/source-tfl": "workspace:*",
|
||||||
"@freya/source-weatherkit": "workspace:*",
|
"@freya/source-weatherkit": "workspace:*",
|
||||||
"@freya/source-web-search": "workspace:*",
|
|
||||||
"@openrouter/sdk": "^0.9.11",
|
"@openrouter/sdk": "^0.9.11",
|
||||||
"arktype": "^2.1.29",
|
"arktype": "^2.1.29",
|
||||||
"better-auth": "^1",
|
"better-auth": "^1",
|
||||||
@@ -194,14 +192,6 @@
|
|||||||
"arktype": "^2.1.0",
|
"arktype": "^2.1.0",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"packages/freya-source-google-maps": {
|
|
||||||
"name": "@freya/source-google-maps",
|
|
||||||
"version": "0.0.0",
|
|
||||||
"dependencies": {
|
|
||||||
"@freya/source-mcp": "workspace:*",
|
|
||||||
"arktype": "^2.1.0",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"packages/freya-source-location": {
|
"packages/freya-source-location": {
|
||||||
"name": "@freya/source-location",
|
"name": "@freya/source-location",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
@@ -241,18 +231,30 @@
|
|||||||
"arktype": "^2.1.0",
|
"arktype": "^2.1.0",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"packages/freya-source-web-search": {
|
|
||||||
"name": "@freya/source-web-search",
|
|
||||||
"version": "0.0.0",
|
|
||||||
"dependencies": {
|
|
||||||
"@freya/core": "workspace:*",
|
|
||||||
"arktype": "^2.1.0",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
"packages": {
|
"packages": {
|
||||||
"@0no-co/graphql.web": ["@0no-co/graphql.web@1.2.0", "", { "peerDependencies": { "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" }, "optionalPeers": ["graphql"] }, "sha512-/1iHy9TTr63gE1YcR5idjx8UREz1s0kFhydf3bBLCXyqjhkIc6igAzTOx3zPifCwFR87tsh/4Pa9cNts6d2otw=="],
|
"@0no-co/graphql.web": ["@0no-co/graphql.web@1.2.0", "", { "peerDependencies": { "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" }, "optionalPeers": ["graphql"] }, "sha512-/1iHy9TTr63gE1YcR5idjx8UREz1s0kFhydf3bBLCXyqjhkIc6igAzTOx3zPifCwFR87tsh/4Pa9cNts6d2otw=="],
|
||||||
|
|
||||||
|
"@freya/backend": ["@freya/backend@workspace:apps/freya-backend"],
|
||||||
|
|
||||||
|
"@freya/components": ["@freya/components@workspace:packages/freya-components"],
|
||||||
|
|
||||||
|
"@freya/core": ["@freya/core@workspace:packages/freya-core"],
|
||||||
|
|
||||||
|
"@freya/feed-enhancers": ["@freya/feed-enhancers@workspace:packages/freya-feed-enhancers"],
|
||||||
|
|
||||||
|
"@freya/source-caldav": ["@freya/source-caldav@workspace:packages/freya-source-caldav"],
|
||||||
|
|
||||||
|
"@freya/source-google-calendar": ["@freya/source-google-calendar@workspace:packages/freya-source-google-calendar"],
|
||||||
|
|
||||||
|
"@freya/source-location": ["@freya/source-location@workspace:packages/freya-source-location"],
|
||||||
|
|
||||||
|
"@freya/source-mcp": ["@freya/source-mcp@workspace:packages/freya-source-mcp"],
|
||||||
|
|
||||||
|
"@freya/source-tfl": ["@freya/source-tfl@workspace:packages/freya-source-tfl"],
|
||||||
|
|
||||||
|
"@freya/source-weatherkit": ["@freya/source-weatherkit@workspace:packages/freya-source-weatherkit"],
|
||||||
|
|
||||||
"@alloc/quick-lru": ["@alloc/quick-lru@5.2.0", "", {}, "sha512-UrcABB+4bUrFABwbluTIBErXwvbsU/V7TZWfmbgJfbkwiBuziS9gxdODUyuiecfdGQ85jglMW6juS3+z5TsKLw=="],
|
"@alloc/quick-lru": ["@alloc/quick-lru@5.2.0", "", {}, "sha512-UrcABB+4bUrFABwbluTIBErXwvbsU/V7TZWfmbgJfbkwiBuziS9gxdODUyuiecfdGQ85jglMW6juS3+z5TsKLw=="],
|
||||||
|
|
||||||
"@ark/schema": ["@ark/schema@0.56.0", "", { "dependencies": { "@ark/util": "0.56.0" } }, "sha512-ECg3hox/6Z/nLajxXqNhgPtNdHWC9zNsDyskwO28WinoFEnWow4IsERNz9AnXRhTZJnYIlAJ4uGn3nlLk65vZA=="],
|
"@ark/schema": ["@ark/schema@0.56.0", "", { "dependencies": { "@ark/util": "0.56.0" } }, "sha512-ECg3hox/6Z/nLajxXqNhgPtNdHWC9zNsDyskwO28WinoFEnWow4IsERNz9AnXRhTZJnYIlAJ4uGn3nlLk65vZA=="],
|
||||||
@@ -669,28 +671,6 @@
|
|||||||
|
|
||||||
"@formatjs/intl-localematcher": ["@formatjs/intl-localematcher@0.6.2", "", { "dependencies": { "tslib": "^2.8.0" } }, "sha512-XOMO2Hupl0wdd172Y06h6kLpBz6Dv+J4okPLl4LPtzbr8f66WbIoy4ev98EBuZ6ZK4h5ydTN6XneT4QVpD7cdA=="],
|
"@formatjs/intl-localematcher": ["@formatjs/intl-localematcher@0.6.2", "", { "dependencies": { "tslib": "^2.8.0" } }, "sha512-XOMO2Hupl0wdd172Y06h6kLpBz6Dv+J4okPLl4LPtzbr8f66WbIoy4ev98EBuZ6ZK4h5ydTN6XneT4QVpD7cdA=="],
|
||||||
|
|
||||||
"@freya/backend": ["@freya/backend@workspace:apps/freya-backend"],
|
|
||||||
|
|
||||||
"@freya/components": ["@freya/components@workspace:packages/freya-components"],
|
|
||||||
|
|
||||||
"@freya/core": ["@freya/core@workspace:packages/freya-core"],
|
|
||||||
|
|
||||||
"@freya/feed-enhancers": ["@freya/feed-enhancers@workspace:packages/freya-feed-enhancers"],
|
|
||||||
|
|
||||||
"@freya/source-caldav": ["@freya/source-caldav@workspace:packages/freya-source-caldav"],
|
|
||||||
|
|
||||||
"@freya/source-google-calendar": ["@freya/source-google-calendar@workspace:packages/freya-source-google-calendar"],
|
|
||||||
|
|
||||||
"@freya/source-google-maps": ["@freya/source-google-maps@workspace:packages/freya-source-google-maps"],
|
|
||||||
|
|
||||||
"@freya/source-location": ["@freya/source-location@workspace:packages/freya-source-location"],
|
|
||||||
|
|
||||||
"@freya/source-tfl": ["@freya/source-tfl@workspace:packages/freya-source-tfl"],
|
|
||||||
|
|
||||||
"@freya/source-weatherkit": ["@freya/source-weatherkit@workspace:packages/freya-source-weatherkit"],
|
|
||||||
|
|
||||||
"@freya/source-web-search": ["@freya/source-web-search@workspace:packages/freya-source-web-search"],
|
|
||||||
|
|
||||||
"@hapi/hoek": ["@hapi/hoek@9.3.0", "", {}, "sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ=="],
|
"@hapi/hoek": ["@hapi/hoek@9.3.0", "", {}, "sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ=="],
|
||||||
|
|
||||||
"@hapi/topo": ["@hapi/topo@5.1.0", "", { "dependencies": { "@hapi/hoek": "^9.0.0" } }, "sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg=="],
|
"@hapi/topo": ["@hapi/topo@5.1.0", "", { "dependencies": { "@hapi/hoek": "^9.0.0" } }, "sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg=="],
|
||||||
@@ -1559,6 +1539,8 @@
|
|||||||
|
|
||||||
"admin-dashboard": ["admin-dashboard@workspace:apps/admin-dashboard"],
|
"admin-dashboard": ["admin-dashboard@workspace:apps/admin-dashboard"],
|
||||||
|
|
||||||
|
"freya-client": ["freya-client@workspace:apps/freya-client"],
|
||||||
|
|
||||||
"agent-base": ["agent-base@7.1.4", "", {}, "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ=="],
|
"agent-base": ["agent-base@7.1.4", "", {}, "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ=="],
|
||||||
|
|
||||||
"ajv": ["ajv@8.11.0", "", { "dependencies": { "fast-deep-equal": "^3.1.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2", "uri-js": "^4.2.2" } }, "sha512-wGgprdCvMalC0BztXvitD2hC04YffAvtsUn93JbGXYLAtCUO4xd17mCCZQxUOItiBwZvJScWo8NIvQMQ71rdpg=="],
|
"ajv": ["ajv@8.11.0", "", { "dependencies": { "fast-deep-equal": "^3.1.1", "json-schema-traverse": "^1.0.0", "require-from-string": "^2.0.2", "uri-js": "^4.2.2" } }, "sha512-wGgprdCvMalC0BztXvitD2hC04YffAvtsUn93JbGXYLAtCUO4xd17mCCZQxUOItiBwZvJScWo8NIvQMQ71rdpg=="],
|
||||||
@@ -2195,8 +2177,6 @@
|
|||||||
|
|
||||||
"fresh": ["fresh@0.5.2", "", {}, "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q=="],
|
"fresh": ["fresh@0.5.2", "", {}, "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q=="],
|
||||||
|
|
||||||
"freya-client": ["freya-client@workspace:apps/freya-client"],
|
|
||||||
|
|
||||||
"fs-extra": ["fs-extra@11.3.4", "", { "dependencies": { "graceful-fs": "^4.2.0", "jsonfile": "^6.0.1", "universalify": "^2.0.0" } }, "sha512-CTXd6rk/M3/ULNQj8FBqBWHYBVYybQ3VPBw0xGKFe3tuH7ytT6ACnvzpIQ3UZtB8yvUKC2cXn1a+x+5EVQLovA=="],
|
"fs-extra": ["fs-extra@11.3.4", "", { "dependencies": { "graceful-fs": "^4.2.0", "jsonfile": "^6.0.1", "universalify": "^2.0.0" } }, "sha512-CTXd6rk/M3/ULNQj8FBqBWHYBVYybQ3VPBw0xGKFe3tuH7ytT6ACnvzpIQ3UZtB8yvUKC2cXn1a+x+5EVQLovA=="],
|
||||||
|
|
||||||
"fs.realpath": ["fs.realpath@1.0.0", "", {}, "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw=="],
|
"fs.realpath": ["fs.realpath@1.0.0", "", {}, "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw=="],
|
||||||
@@ -3951,6 +3931,12 @@
|
|||||||
|
|
||||||
"accepts/negotiator": ["negotiator@0.6.3", "", {}, "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg=="],
|
"accepts/negotiator": ["negotiator@0.6.3", "", {}, "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg=="],
|
||||||
|
|
||||||
|
"freya-client/@types/react": ["@types/react@19.1.17", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-Qec1E3mhALmaspIrhWt9jkQMNdw6bReVu64mjvhbhq2NFPftLPVr+l1SZgmw/66WwBNpDh7ao5AT6gF5v41PFA=="],
|
||||||
|
|
||||||
|
"freya-client/react": ["react@19.1.0", "", {}, "sha512-FS+XFBNvn3GTAWq26joslQgWNoFu08F4kl0J4CgdNKADkdSGXQyTCnKteIAJy96Br6YbpEU1LSzV5dYtjMkMDg=="],
|
||||||
|
|
||||||
|
"freya-client/react-dom": ["react-dom@19.1.0", "", { "dependencies": { "scheduler": "^0.26.0" }, "peerDependencies": { "react": "^19.1.0" } }, "sha512-Xs1hdnE+DyKgeHJeJznQmYMIBG3TKIHJJT95Q58nHLSrElKlGQqDTR2HQ9fx5CN/Gk6Vh/kupBTDLU11/nDk/g=="],
|
||||||
|
|
||||||
"ansi-escapes/type-fest": ["type-fest@0.21.3", "", {}, "sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w=="],
|
"ansi-escapes/type-fest": ["type-fest@0.21.3", "", {}, "sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w=="],
|
||||||
|
|
||||||
"anymatch/picomatch": ["picomatch@2.3.1", "", {}, "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA=="],
|
"anymatch/picomatch": ["picomatch@2.3.1", "", {}, "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA=="],
|
||||||
@@ -4093,12 +4079,6 @@
|
|||||||
|
|
||||||
"framer-motion/tslib": ["tslib@2.8.1", "", {}, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="],
|
"framer-motion/tslib": ["tslib@2.8.1", "", {}, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="],
|
||||||
|
|
||||||
"freya-client/@types/react": ["@types/react@19.1.17", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-Qec1E3mhALmaspIrhWt9jkQMNdw6bReVu64mjvhbhq2NFPftLPVr+l1SZgmw/66WwBNpDh7ao5AT6gF5v41PFA=="],
|
|
||||||
|
|
||||||
"freya-client/react": ["react@19.1.0", "", {}, "sha512-FS+XFBNvn3GTAWq26joslQgWNoFu08F4kl0J4CgdNKADkdSGXQyTCnKteIAJy96Br6YbpEU1LSzV5dYtjMkMDg=="],
|
|
||||||
|
|
||||||
"freya-client/react-dom": ["react-dom@19.1.0", "", { "dependencies": { "scheduler": "^0.26.0" }, "peerDependencies": { "react": "^19.1.0" } }, "sha512-Xs1hdnE+DyKgeHJeJznQmYMIBG3TKIHJJT95Q58nHLSrElKlGQqDTR2HQ9fx5CN/Gk6Vh/kupBTDLU11/nDk/g=="],
|
|
||||||
|
|
||||||
"giget/pathe": ["pathe@2.0.3", "", {}, "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w=="],
|
"giget/pathe": ["pathe@2.0.3", "", {}, "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w=="],
|
||||||
|
|
||||||
"glob/minimatch": ["minimatch@3.1.5", "", { "dependencies": { "brace-expansion": "^1.1.7" } }, "sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w=="],
|
"glob/minimatch": ["minimatch@3.1.5", "", { "dependencies": { "brace-expansion": "^1.1.7" } }, "sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w=="],
|
||||||
@@ -4589,6 +4569,8 @@
|
|||||||
|
|
||||||
"@typescript-eslint/typescript-estree/minimatch/brace-expansion": ["brace-expansion@5.0.4", "", { "dependencies": { "balanced-match": "^4.0.2" } }, "sha512-h+DEnpVvxmfVefa4jFbCf5HdH5YMDXRsmKflpf1pILZWRFlTbJpxeU55nJl4Smt5HQaGzg1o6RHFPJaOqnmBDg=="],
|
"@typescript-eslint/typescript-estree/minimatch/brace-expansion": ["brace-expansion@5.0.4", "", { "dependencies": { "balanced-match": "^4.0.2" } }, "sha512-h+DEnpVvxmfVefa4jFbCf5HdH5YMDXRsmKflpf1pILZWRFlTbJpxeU55nJl4Smt5HQaGzg1o6RHFPJaOqnmBDg=="],
|
||||||
|
|
||||||
|
"freya-client/react-dom/scheduler": ["scheduler@0.26.0", "", {}, "sha512-NlHwttCI/l5gCPR3D1nNXtWABUmBwvZpEQiD4IXSbIDq8BzLIK/7Ir5gTFSGZDUu37K5cMNp0hFtzO38sC7gWA=="],
|
||||||
|
|
||||||
"better-opn/open/define-lazy-prop": ["define-lazy-prop@2.0.0", "", {}, "sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og=="],
|
"better-opn/open/define-lazy-prop": ["define-lazy-prop@2.0.0", "", {}, "sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og=="],
|
||||||
|
|
||||||
"better-opn/open/is-docker": ["is-docker@2.2.1", "", { "bin": { "is-docker": "cli.js" } }, "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ=="],
|
"better-opn/open/is-docker": ["is-docker@2.2.1", "", { "bin": { "is-docker": "cli.js" } }, "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ=="],
|
||||||
@@ -4723,8 +4705,6 @@
|
|||||||
|
|
||||||
"finalhandler/debug/ms": ["ms@2.0.0", "", {}, "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="],
|
"finalhandler/debug/ms": ["ms@2.0.0", "", {}, "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A=="],
|
||||||
|
|
||||||
"freya-client/react-dom/scheduler": ["scheduler@0.26.0", "", {}, "sha512-NlHwttCI/l5gCPR3D1nNXtWABUmBwvZpEQiD4IXSbIDq8BzLIK/7Ir5gTFSGZDUu37K5cMNp0hFtzO38sC7gWA=="],
|
|
||||||
|
|
||||||
"glob/minimatch/brace-expansion": ["brace-expansion@1.1.12", "", { "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" } }, "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg=="],
|
"glob/minimatch/brace-expansion": ["brace-expansion@1.1.12", "", { "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" } }, "sha512-9T9UjW3r0UW5c1Q7GTwllptXwhvYmEzFhzMfZ9H7FQWt+uZePjZPjBP/W1ZEyZ1twGWom5/56TF4lPcqjnDHcg=="],
|
||||||
|
|
||||||
"globby/fast-glob/glob-parent": ["glob-parent@5.1.2", "", { "dependencies": { "is-glob": "^4.0.1" } }, "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow=="],
|
"globby/fast-glob/glob-parent": ["glob-parent@5.1.2", "", { "dependencies": { "is-glob": "^4.0.1" } }, "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow=="],
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@freya/source-google-maps",
|
|
||||||
"version": "0.0.0",
|
|
||||||
"type": "module",
|
|
||||||
"main": "src/index.ts",
|
|
||||||
"types": "src/index.ts",
|
|
||||||
"scripts": {
|
|
||||||
"test": "bun test src/"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@freya/source-mcp": "workspace:*",
|
|
||||||
"arktype": "^2.1.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,135 +0,0 @@
|
|||||||
import type {
|
|
||||||
McpCallToolParams,
|
|
||||||
McpCallToolResult,
|
|
||||||
McpClient,
|
|
||||||
McpListToolsResult,
|
|
||||||
McpReadResourceParams,
|
|
||||||
McpReadResourceResult,
|
|
||||||
} from "@freya/source-mcp"
|
|
||||||
|
|
||||||
import { describe, expect, test } from "bun:test"
|
|
||||||
|
|
||||||
import { GoogleMapsAction, GoogleMapsSource, GoogleMapsSourceId, GoogleMapsTool } from "./index"
|
|
||||||
|
|
||||||
class MockMcpClient implements McpClient {
|
|
||||||
readonly calls: McpCallToolParams[] = []
|
|
||||||
|
|
||||||
async listTools(): Promise<McpListToolsResult> {
|
|
||||||
return {
|
|
||||||
tools: Object.values(GoogleMapsTool).map((name) => ({
|
|
||||||
name,
|
|
||||||
description: `${name} description`,
|
|
||||||
})),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async readResource(_params: McpReadResourceParams): Promise<McpReadResourceResult> {
|
|
||||||
throw new Error("unexpected resource read")
|
|
||||||
}
|
|
||||||
|
|
||||||
async callTool(params: McpCallToolParams): Promise<McpCallToolResult> {
|
|
||||||
this.calls.push(params)
|
|
||||||
return {
|
|
||||||
structuredContent: {
|
|
||||||
tool: params.name,
|
|
||||||
arguments: params.arguments ?? {},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("GoogleMapsSource", () => {
|
|
||||||
test("uses the Google Maps source id", () => {
|
|
||||||
const source = new GoogleMapsSource({ client: new MockMcpClient() })
|
|
||||||
expect(source.id).toBe(GoogleMapsSourceId)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("exposes documented Google Maps MCP tools as actions", async () => {
|
|
||||||
const source = new GoogleMapsSource({ client: new MockMcpClient() })
|
|
||||||
|
|
||||||
const actions = await source.listActions()
|
|
||||||
|
|
||||||
expect(Object.keys(actions).sort()).toEqual(Object.values(GoogleMapsAction).sort())
|
|
||||||
expect(actions[GoogleMapsAction.SearchPlaces]!.id).toBe(GoogleMapsAction.SearchPlaces)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("maps action execution to the underlying MCP tool", async () => {
|
|
||||||
const client = new MockMcpClient()
|
|
||||||
const source = new GoogleMapsSource({ client })
|
|
||||||
|
|
||||||
const result = await source.executeAction(GoogleMapsAction.SearchPlaces, {
|
|
||||||
textQuery: "coffee shops near Golden Gate Park",
|
|
||||||
regionCode: "US",
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(client.calls).toEqual([
|
|
||||||
{
|
|
||||||
name: GoogleMapsTool.SearchPlaces,
|
|
||||||
arguments: {
|
|
||||||
textQuery: "coffee shops near Golden Gate Park",
|
|
||||||
regionCode: "US",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
])
|
|
||||||
expect(result).toEqual({
|
|
||||||
tool: GoogleMapsTool.SearchPlaces,
|
|
||||||
arguments: {
|
|
||||||
textQuery: "coffee shops near Golden Gate Park",
|
|
||||||
regionCode: "US",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
test("validates action input before calling the MCP tool", async () => {
|
|
||||||
const client = new MockMcpClient()
|
|
||||||
const source = new GoogleMapsSource({ client })
|
|
||||||
|
|
||||||
await expectRejectsWithMessage(
|
|
||||||
source.executeAction(GoogleMapsAction.SearchPlaces, {}),
|
|
||||||
"textQuery must be a string",
|
|
||||||
)
|
|
||||||
expect(client.calls).toEqual([])
|
|
||||||
})
|
|
||||||
|
|
||||||
test("validates resolve names query objects", async () => {
|
|
||||||
const client = new MockMcpClient()
|
|
||||||
const source = new GoogleMapsSource({ client })
|
|
||||||
|
|
||||||
await expectRejectsWithMessage(
|
|
||||||
source.executeAction(GoogleMapsAction.ResolveNames, { queries: [{}] }),
|
|
||||||
"queries[0].text must be a string",
|
|
||||||
)
|
|
||||||
expect(client.calls).toEqual([])
|
|
||||||
})
|
|
||||||
|
|
||||||
test("does not produce feed items or context by default", async () => {
|
|
||||||
const source = new GoogleMapsSource({ client: new MockMcpClient() })
|
|
||||||
|
|
||||||
const contextEntries = await source.fetchContext(undefined as never)
|
|
||||||
const items = await source.fetchItems(undefined as never)
|
|
||||||
|
|
||||||
expect(contextEntries).toBeNull()
|
|
||||||
expect(items).toEqual([])
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
async function expectRejectsWithMessage(
|
|
||||||
promise: Promise<unknown>,
|
|
||||||
expectedMessage: string,
|
|
||||||
): Promise<void> {
|
|
||||||
try {
|
|
||||||
await promise
|
|
||||||
} catch (err) {
|
|
||||||
expect(errorMessage(err)).toContain(expectedMessage)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error(`Expected promise to reject with "${expectedMessage}"`)
|
|
||||||
}
|
|
||||||
|
|
||||||
function errorMessage(err: unknown): string {
|
|
||||||
if (err instanceof Error) {
|
|
||||||
return err.message
|
|
||||||
}
|
|
||||||
return String(err)
|
|
||||||
}
|
|
||||||
@@ -1,151 +0,0 @@
|
|||||||
import {
|
|
||||||
McpSource,
|
|
||||||
type McpActionMapping,
|
|
||||||
type McpClient,
|
|
||||||
type McpHttpHeaders,
|
|
||||||
type McpSourceOptions,
|
|
||||||
} from "@freya/source-mcp"
|
|
||||||
|
|
||||||
import {
|
|
||||||
ComputeRoutesInput,
|
|
||||||
LookupWeatherInput,
|
|
||||||
ResolveMapsUrlsInput,
|
|
||||||
ResolveNamesInput,
|
|
||||||
SearchPlacesInput,
|
|
||||||
} from "./schemas"
|
|
||||||
|
|
||||||
export type GoogleMapsApiKey = string | (() => Promise<string>)
|
|
||||||
|
|
||||||
export interface GoogleMapsSourceOptions {
|
|
||||||
readonly endpoint?: string | URL
|
|
||||||
readonly apiKey?: GoogleMapsApiKey
|
|
||||||
readonly timeoutMs?: number
|
|
||||||
readonly headers?: McpHttpHeaders | (() => Promise<McpHttpHeaders>)
|
|
||||||
readonly requestInit?: RequestInit
|
|
||||||
readonly transportOptions?: McpSourceOptions["transportOptions"]
|
|
||||||
readonly client?: McpClient
|
|
||||||
readonly clientFactory?: McpSourceOptions["clientFactory"]
|
|
||||||
}
|
|
||||||
|
|
||||||
export const GoogleMapsSourceId = "freya.google-maps"
|
|
||||||
|
|
||||||
export const GoogleMapsMcpEndpoint = "https://mapstools.googleapis.com/mcp"
|
|
||||||
|
|
||||||
export const GoogleMapsAction = {
|
|
||||||
SearchPlaces: "search-places",
|
|
||||||
LookupWeather: "lookup-weather",
|
|
||||||
ComputeRoutes: "compute-routes",
|
|
||||||
ResolveNames: "resolve-names",
|
|
||||||
ResolveMapsUrls: "resolve-maps-urls",
|
|
||||||
} as const
|
|
||||||
|
|
||||||
export type GoogleMapsAction = (typeof GoogleMapsAction)[keyof typeof GoogleMapsAction]
|
|
||||||
|
|
||||||
export const GoogleMapsTool = {
|
|
||||||
SearchPlaces: "search_places",
|
|
||||||
LookupWeather: "lookup_weather",
|
|
||||||
ComputeRoutes: "compute_routes",
|
|
||||||
ResolveNames: "resolve_names",
|
|
||||||
ResolveMapsUrls: "resolve_maps_urls",
|
|
||||||
} as const
|
|
||||||
|
|
||||||
export type GoogleMapsTool = (typeof GoogleMapsTool)[keyof typeof GoogleMapsTool]
|
|
||||||
|
|
||||||
const GoogleMapsActions = {
|
|
||||||
[GoogleMapsAction.SearchPlaces]: {
|
|
||||||
tool: GoogleMapsTool.SearchPlaces,
|
|
||||||
description:
|
|
||||||
"Find places, businesses, addresses, locations, and points of interest with Google Maps.",
|
|
||||||
input: SearchPlacesInput,
|
|
||||||
},
|
|
||||||
[GoogleMapsAction.LookupWeather]: {
|
|
||||||
tool: GoogleMapsTool.LookupWeather,
|
|
||||||
description: "Retrieve current conditions and weather forecasts through Google Maps.",
|
|
||||||
input: LookupWeatherInput,
|
|
||||||
},
|
|
||||||
[GoogleMapsAction.ComputeRoutes]: {
|
|
||||||
tool: GoogleMapsTool.ComputeRoutes,
|
|
||||||
description: "Compute a Google Maps route between an origin and destination.",
|
|
||||||
input: ComputeRoutesInput,
|
|
||||||
},
|
|
||||||
[GoogleMapsAction.ResolveNames]: {
|
|
||||||
tool: GoogleMapsTool.ResolveNames,
|
|
||||||
description: "Resolve specific place names or addresses into Google Maps Place IDs.",
|
|
||||||
input: ResolveNamesInput,
|
|
||||||
},
|
|
||||||
[GoogleMapsAction.ResolveMapsUrls]: {
|
|
||||||
tool: GoogleMapsTool.ResolveMapsUrls,
|
|
||||||
description: "Resolve Google Maps URLs into canonical Google Maps Place IDs.",
|
|
||||||
input: ResolveMapsUrlsInput,
|
|
||||||
},
|
|
||||||
} as const satisfies Record<GoogleMapsAction, McpActionMapping>
|
|
||||||
|
|
||||||
export class GoogleMapsSource extends McpSource {
|
|
||||||
constructor(options: GoogleMapsSourceOptions = {}) {
|
|
||||||
super({
|
|
||||||
id: GoogleMapsSourceId,
|
|
||||||
url: options.endpoint ?? GoogleMapsMcpEndpoint,
|
|
||||||
clientName: "freya-source-google-maps",
|
|
||||||
clientVersion: "0.0.0",
|
|
||||||
timeoutMs: options.timeoutMs,
|
|
||||||
headers: createGoogleMapsHeaders({
|
|
||||||
headers: options.headers,
|
|
||||||
apiKey: options.apiKey,
|
|
||||||
}),
|
|
||||||
requestInit: options.requestInit,
|
|
||||||
transportOptions: options.transportOptions,
|
|
||||||
client: options.client,
|
|
||||||
clientFactory: options.clientFactory,
|
|
||||||
actions: GoogleMapsActions,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface GoogleMapsHeaderOptions {
|
|
||||||
readonly headers: McpHttpHeaders | (() => Promise<McpHttpHeaders>) | undefined
|
|
||||||
readonly apiKey: GoogleMapsApiKey | undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
function createGoogleMapsHeaders({
|
|
||||||
headers,
|
|
||||||
apiKey,
|
|
||||||
}: GoogleMapsHeaderOptions): McpHttpHeaders | (() => Promise<McpHttpHeaders>) | undefined {
|
|
||||||
if (!apiKey) {
|
|
||||||
return headers
|
|
||||||
}
|
|
||||||
|
|
||||||
return async () => {
|
|
||||||
const merged = new Headers()
|
|
||||||
const resolvedHeaders = typeof headers === "function" ? await headers() : headers
|
|
||||||
if (resolvedHeaders) {
|
|
||||||
applyHeaders(merged, resolvedHeaders)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (apiKey) {
|
|
||||||
const resolvedApiKey = typeof apiKey === "function" ? await apiKey() : apiKey
|
|
||||||
merged.set("x-goog-api-key", resolvedApiKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
return merged
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function applyHeaders(target: Headers, headers: McpHttpHeaders): void {
|
|
||||||
if (headers instanceof Headers) {
|
|
||||||
headers.forEach((value, key) => {
|
|
||||||
target.set(key, value)
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Array.isArray(headers)) {
|
|
||||||
for (const [key, value] of headers) {
|
|
||||||
target.set(key, value)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(headers)) {
|
|
||||||
target.set(key, value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
export {
|
|
||||||
GoogleMapsAction,
|
|
||||||
GoogleMapsMcpEndpoint,
|
|
||||||
GoogleMapsSource,
|
|
||||||
GoogleMapsSourceId,
|
|
||||||
GoogleMapsTool,
|
|
||||||
type GoogleMapsApiKey,
|
|
||||||
type GoogleMapsSourceOptions,
|
|
||||||
} from "./google-maps-source"
|
|
||||||
|
|
||||||
export {
|
|
||||||
ComputeRoutesInput,
|
|
||||||
LookupWeatherInput,
|
|
||||||
ResolveMapsUrlsInput,
|
|
||||||
ResolveNamesInput,
|
|
||||||
SearchPlacesInput,
|
|
||||||
} from "./schemas"
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
import { type } from "arktype"
|
|
||||||
|
|
||||||
const ResolveNameQuery = type({
|
|
||||||
"+": "reject",
|
|
||||||
text: "string",
|
|
||||||
})
|
|
||||||
|
|
||||||
export const SearchPlacesInput = type({
|
|
||||||
"+": "reject",
|
|
||||||
textQuery: "string",
|
|
||||||
"locationBias?": "unknown",
|
|
||||||
"languageCode?": "string",
|
|
||||||
"regionCode?": "string",
|
|
||||||
})
|
|
||||||
|
|
||||||
export const LookupWeatherInput = type({
|
|
||||||
"+": "reject",
|
|
||||||
location: "unknown",
|
|
||||||
"date?": "unknown",
|
|
||||||
"hour?": "number",
|
|
||||||
"unitsSystem?": "'UNITS_SYSTEM_UNSPECIFIED' | 'METRIC' | 'IMPERIAL'",
|
|
||||||
})
|
|
||||||
|
|
||||||
export const ComputeRoutesInput = type({
|
|
||||||
"+": "reject",
|
|
||||||
origin: "unknown",
|
|
||||||
destination: "unknown",
|
|
||||||
"travelMode?": "'ROUTE_TRAVEL_MODE_UNSPECIFIED' | 'DRIVE' | 'WALK'",
|
|
||||||
})
|
|
||||||
|
|
||||||
export const ResolveNamesInput = type({
|
|
||||||
"+": "reject",
|
|
||||||
queries: ResolveNameQuery.array(),
|
|
||||||
"locationBias?": "unknown",
|
|
||||||
"regionCode?": "string",
|
|
||||||
})
|
|
||||||
|
|
||||||
export const ResolveMapsUrlsInput = type({
|
|
||||||
"+": "reject",
|
|
||||||
urls: "string[]",
|
|
||||||
})
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "../../tsconfig.json",
|
|
||||||
"include": ["src"]
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@freya/source-web-search",
|
|
||||||
"version": "0.0.0",
|
|
||||||
"type": "module",
|
|
||||||
"main": "src/index.ts",
|
|
||||||
"types": "src/index.ts",
|
|
||||||
"scripts": {
|
|
||||||
"test": "bun test ."
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@freya/core": "workspace:*",
|
|
||||||
"arktype": "^2.1.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
import { describe, expect, test } from "bun:test"
|
|
||||||
|
|
||||||
import { ExaSearchClient } from "./exa-client.ts"
|
|
||||||
|
|
||||||
describe("ExaSearchClient", () => {
|
|
||||||
test("maps request and response", async () => {
|
|
||||||
const originalFetch = globalThis.fetch
|
|
||||||
let requestUrl = ""
|
|
||||||
let requestHeaders: Headers
|
|
||||||
let requestBody: unknown
|
|
||||||
|
|
||||||
globalThis.fetch = (async (
|
|
||||||
input: Parameters<typeof fetch>[0],
|
|
||||||
init?: Parameters<typeof fetch>[1],
|
|
||||||
) => {
|
|
||||||
requestUrl = String(input)
|
|
||||||
requestHeaders = new Headers(init?.headers)
|
|
||||||
requestBody = JSON.parse(String(init?.body))
|
|
||||||
|
|
||||||
return new Response(
|
|
||||||
JSON.stringify({
|
|
||||||
requestId: "exa-request-1",
|
|
||||||
results: [
|
|
||||||
{
|
|
||||||
id: "result-1",
|
|
||||||
url: "https://example.com",
|
|
||||||
title: "Example",
|
|
||||||
publishedDate: "2026-01-01T00:00:00.000Z",
|
|
||||||
author: "Author",
|
|
||||||
image: "https://example.com/image.png",
|
|
||||||
favicon: "https://example.com/favicon.ico",
|
|
||||||
highlights: ["A useful passage"],
|
|
||||||
highlightScores: [0.7],
|
|
||||||
summary: "Summary",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
{ status: 200 },
|
|
||||||
)
|
|
||||||
}) as unknown as typeof fetch
|
|
||||||
|
|
||||||
try {
|
|
||||||
const client = new ExaSearchClient("api-key", "https://api.example.test")
|
|
||||||
const result = await client.search({
|
|
||||||
query: "test query",
|
|
||||||
numResults: 3,
|
|
||||||
includeDomains: ["example.com"],
|
|
||||||
highlights: false,
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(requestUrl).toBe("https://api.example.test/search")
|
|
||||||
expect(requestHeaders!.get("x-api-key")).toBe("api-key")
|
|
||||||
expect(requestBody).toEqual({
|
|
||||||
query: "test query",
|
|
||||||
numResults: 3,
|
|
||||||
includeDomains: ["example.com"],
|
|
||||||
contents: { highlights: false },
|
|
||||||
})
|
|
||||||
expect(result).toEqual({
|
|
||||||
query: "test query",
|
|
||||||
requestId: "exa-request-1",
|
|
||||||
results: [
|
|
||||||
{
|
|
||||||
id: "result-1",
|
|
||||||
url: "https://example.com",
|
|
||||||
title: "Example",
|
|
||||||
publishedDate: "2026-01-01T00:00:00.000Z",
|
|
||||||
author: "Author",
|
|
||||||
image: "https://example.com/image.png",
|
|
||||||
favicon: "https://example.com/favicon.ico",
|
|
||||||
text: null,
|
|
||||||
highlights: ["A useful passage"],
|
|
||||||
highlightScores: [0.7],
|
|
||||||
summary: "Summary",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
|
||||||
} finally {
|
|
||||||
globalThis.fetch = originalFetch
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
test("throws on non-ok response", async () => {
|
|
||||||
const originalFetch = globalThis.fetch
|
|
||||||
globalThis.fetch = (async () =>
|
|
||||||
new Response("nope", { status: 401, statusText: "Unauthorized" })) as unknown as typeof fetch
|
|
||||||
|
|
||||||
try {
|
|
||||||
const client = new ExaSearchClient("bad-key")
|
|
||||||
await expect(client.search({ query: "test" })).rejects.toThrow(
|
|
||||||
"Exa API error: 401 Unauthorized",
|
|
||||||
)
|
|
||||||
} finally {
|
|
||||||
globalThis.fetch = originalFetch
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
import { type } from "arktype"
|
|
||||||
|
|
||||||
import type {
|
|
||||||
WebSearchClient,
|
|
||||||
WebSearchRequest,
|
|
||||||
WebSearchResponse,
|
|
||||||
WebSearchResult,
|
|
||||||
} from "./types.ts"
|
|
||||||
|
|
||||||
const EXA_API_BASE = "https://api.exa.ai"
|
|
||||||
const DEFAULT_NUM_RESULTS = 10
|
|
||||||
|
|
||||||
const ExaSearchResult = type({
|
|
||||||
id: "string",
|
|
||||||
url: "string",
|
|
||||||
"title?": "string | null",
|
|
||||||
"publishedDate?": "string | null",
|
|
||||||
"author?": "string | null",
|
|
||||||
"image?": "string | null",
|
|
||||||
"favicon?": "string | null",
|
|
||||||
"text?": "string | null",
|
|
||||||
"highlights?": "string[]",
|
|
||||||
"highlightScores?": "number[]",
|
|
||||||
"summary?": "string | null",
|
|
||||||
})
|
|
||||||
|
|
||||||
const ExaSearchResponse = type({
|
|
||||||
results: ExaSearchResult.array(),
|
|
||||||
"requestId?": "string",
|
|
||||||
})
|
|
||||||
|
|
||||||
interface ExaSearchBody {
|
|
||||||
query: string
|
|
||||||
numResults?: number
|
|
||||||
includeDomains?: string[]
|
|
||||||
excludeDomains?: string[]
|
|
||||||
startCrawlDate?: string
|
|
||||||
endCrawlDate?: string
|
|
||||||
startPublishedDate?: string
|
|
||||||
endPublishedDate?: string
|
|
||||||
type?: WebSearchRequest["type"]
|
|
||||||
category?: string
|
|
||||||
userLocation?: string
|
|
||||||
moderation?: boolean
|
|
||||||
contents: {
|
|
||||||
highlights: boolean
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ExaSearchClient implements WebSearchClient {
|
|
||||||
private readonly apiKey: string
|
|
||||||
private readonly baseUrl: string
|
|
||||||
|
|
||||||
constructor(apiKey: string, baseUrl = EXA_API_BASE) {
|
|
||||||
this.apiKey = apiKey
|
|
||||||
this.baseUrl = baseUrl
|
|
||||||
}
|
|
||||||
|
|
||||||
async search(request: WebSearchRequest): Promise<WebSearchResponse> {
|
|
||||||
const response = await fetch(new URL("/search", this.baseUrl), {
|
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"x-api-key": this.apiKey,
|
|
||||||
},
|
|
||||||
body: JSON.stringify(toExaSearchBody(request)),
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`Exa API error: ${response.status} ${response.statusText}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.json()
|
|
||||||
const parsed = ExaSearchResponse(data)
|
|
||||||
if (parsed instanceof type.errors) {
|
|
||||||
throw new Error(`Invalid Exa API response: ${parsed.summary}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
query: request.query,
|
|
||||||
requestId: parsed.requestId ?? null,
|
|
||||||
results: parsed.results.map(toWebSearchResult),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function toExaSearchBody(request: WebSearchRequest): ExaSearchBody {
|
|
||||||
const body: ExaSearchBody = {
|
|
||||||
query: request.query,
|
|
||||||
numResults: request.numResults ?? DEFAULT_NUM_RESULTS,
|
|
||||||
contents: {
|
|
||||||
highlights: request.highlights ?? true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
if (request.includeDomains) body.includeDomains = request.includeDomains
|
|
||||||
if (request.excludeDomains) body.excludeDomains = request.excludeDomains
|
|
||||||
if (request.startCrawlDate) body.startCrawlDate = request.startCrawlDate
|
|
||||||
if (request.endCrawlDate) body.endCrawlDate = request.endCrawlDate
|
|
||||||
if (request.startPublishedDate) body.startPublishedDate = request.startPublishedDate
|
|
||||||
if (request.endPublishedDate) body.endPublishedDate = request.endPublishedDate
|
|
||||||
if (request.type) body.type = request.type
|
|
||||||
if (request.category) body.category = request.category
|
|
||||||
if (request.userLocation) body.userLocation = request.userLocation
|
|
||||||
if (request.moderation !== undefined) body.moderation = request.moderation
|
|
||||||
|
|
||||||
return body
|
|
||||||
}
|
|
||||||
|
|
||||||
function toWebSearchResult(result: typeof ExaSearchResult.infer): WebSearchResult {
|
|
||||||
return {
|
|
||||||
id: result.id,
|
|
||||||
url: result.url,
|
|
||||||
title: result.title ?? null,
|
|
||||||
publishedDate: result.publishedDate ?? null,
|
|
||||||
author: result.author ?? null,
|
|
||||||
image: result.image ?? null,
|
|
||||||
favicon: result.favicon ?? null,
|
|
||||||
text: result.text ?? null,
|
|
||||||
highlights: result.highlights ?? [],
|
|
||||||
highlightScores: result.highlightScores ?? [],
|
|
||||||
summary: result.summary ?? null,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
export { ExaSearchClient } from "./exa-client.ts"
|
|
||||||
export { WebSearchSource } from "./web-search-source.ts"
|
|
||||||
export {
|
|
||||||
WebSearchAction,
|
|
||||||
WebSearchType,
|
|
||||||
type WebSearchClient,
|
|
||||||
type WebSearchRequest,
|
|
||||||
type WebSearchResponse,
|
|
||||||
type WebSearchResult,
|
|
||||||
type WebSearchSourceOptions,
|
|
||||||
} from "./types.ts"
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
export const WebSearchAction = {
|
|
||||||
Search: "search",
|
|
||||||
} as const
|
|
||||||
|
|
||||||
export type WebSearchAction = (typeof WebSearchAction)[keyof typeof WebSearchAction]
|
|
||||||
|
|
||||||
export const WebSearchType = {
|
|
||||||
Instant: "instant",
|
|
||||||
Fast: "fast",
|
|
||||||
Auto: "auto",
|
|
||||||
DeepLite: "deep-lite",
|
|
||||||
Deep: "deep",
|
|
||||||
DeepReasoning: "deep-reasoning",
|
|
||||||
} as const
|
|
||||||
|
|
||||||
export type WebSearchType = (typeof WebSearchType)[keyof typeof WebSearchType]
|
|
||||||
|
|
||||||
export interface WebSearchRequest {
|
|
||||||
query: string
|
|
||||||
numResults?: number
|
|
||||||
includeDomains?: string[]
|
|
||||||
excludeDomains?: string[]
|
|
||||||
startCrawlDate?: string
|
|
||||||
endCrawlDate?: string
|
|
||||||
startPublishedDate?: string
|
|
||||||
endPublishedDate?: string
|
|
||||||
type?: WebSearchType
|
|
||||||
category?: string
|
|
||||||
userLocation?: string
|
|
||||||
moderation?: boolean
|
|
||||||
highlights?: boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface WebSearchResult extends Record<string, unknown> {
|
|
||||||
id: string
|
|
||||||
url: string
|
|
||||||
title: string | null
|
|
||||||
publishedDate: string | null
|
|
||||||
author: string | null
|
|
||||||
image: string | null
|
|
||||||
favicon: string | null
|
|
||||||
text: string | null
|
|
||||||
highlights: string[]
|
|
||||||
highlightScores: number[]
|
|
||||||
summary: string | null
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface WebSearchResponse extends Record<string, unknown> {
|
|
||||||
query: string
|
|
||||||
requestId: string | null
|
|
||||||
results: WebSearchResult[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface WebSearchClient {
|
|
||||||
search(request: WebSearchRequest): Promise<WebSearchResponse>
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface WebSearchSourceOptions {
|
|
||||||
apiKey?: string
|
|
||||||
client?: WebSearchClient
|
|
||||||
}
|
|
||||||
@@ -1,123 +0,0 @@
|
|||||||
import { Context } from "@freya/core"
|
|
||||||
import { describe, expect, test } from "bun:test"
|
|
||||||
|
|
||||||
import type { WebSearchClient, WebSearchRequest, WebSearchResponse } from "./types.ts"
|
|
||||||
|
|
||||||
import { WebSearchAction } from "./types.ts"
|
|
||||||
import { WebSearchSource } from "./web-search-source.ts"
|
|
||||||
|
|
||||||
class RecordingSearchClient implements WebSearchClient {
|
|
||||||
requests: WebSearchRequest[] = []
|
|
||||||
|
|
||||||
async search(request: WebSearchRequest): Promise<WebSearchResponse> {
|
|
||||||
this.requests.push(request)
|
|
||||||
return {
|
|
||||||
query: request.query,
|
|
||||||
requestId: "request-1",
|
|
||||||
results: [
|
|
||||||
{
|
|
||||||
id: "https://example.com/a",
|
|
||||||
url: "https://example.com/a",
|
|
||||||
title: "Example result",
|
|
||||||
publishedDate: "2026-01-01T00:00:00.000Z",
|
|
||||||
author: "Example Author",
|
|
||||||
image: null,
|
|
||||||
favicon: "https://example.com/favicon.ico",
|
|
||||||
text: null,
|
|
||||||
highlights: ["Relevant excerpt"],
|
|
||||||
highlightScores: [0.8],
|
|
||||||
summary: null,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
describe("WebSearchSource", () => {
|
|
||||||
test("has correct id", () => {
|
|
||||||
const source = new WebSearchSource({ client: new RecordingSearchClient() })
|
|
||||||
|
|
||||||
expect(source.id).toBe("freya.web-search")
|
|
||||||
})
|
|
||||||
|
|
||||||
test("does not provide context or feed items", async () => {
|
|
||||||
const source = new WebSearchSource({ client: new RecordingSearchClient() })
|
|
||||||
|
|
||||||
expect("fetchItems" in source).toBe(false)
|
|
||||||
expect(await source.fetchContext(new Context())).toBeNull()
|
|
||||||
})
|
|
||||||
|
|
||||||
test("lists search action", async () => {
|
|
||||||
const source = new WebSearchSource({ client: new RecordingSearchClient() })
|
|
||||||
const actions = await source.listActions()
|
|
||||||
|
|
||||||
expect(actions[WebSearchAction.Search]).toBeDefined()
|
|
||||||
expect(actions[WebSearchAction.Search]!.id).toBe(WebSearchAction.Search)
|
|
||||||
expect(actions[WebSearchAction.Search]!.input).toBeDefined()
|
|
||||||
})
|
|
||||||
|
|
||||||
test("executes search action with normalized params", async () => {
|
|
||||||
const client = new RecordingSearchClient()
|
|
||||||
const source = new WebSearchSource({ client })
|
|
||||||
|
|
||||||
const result = await source.executeAction(WebSearchAction.Search, {
|
|
||||||
query: " latest personal assistant research ",
|
|
||||||
includeDomains: ["exa.ai"],
|
|
||||||
type: "fast",
|
|
||||||
userLocation: "gb",
|
|
||||||
moderation: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(result.requestId).toBe("request-1")
|
|
||||||
expect(result.results).toHaveLength(1)
|
|
||||||
expect(client.requests).toEqual([
|
|
||||||
{
|
|
||||||
query: "latest personal assistant research",
|
|
||||||
numResults: 10,
|
|
||||||
includeDomains: ["exa.ai"],
|
|
||||||
type: "fast",
|
|
||||||
userLocation: "GB",
|
|
||||||
moderation: true,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
test("allows per-call numResults override", async () => {
|
|
||||||
const client = new RecordingSearchClient()
|
|
||||||
const source = new WebSearchSource({ client })
|
|
||||||
|
|
||||||
await source.executeAction(WebSearchAction.Search, {
|
|
||||||
query: "freya",
|
|
||||||
numResults: 2,
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(client.requests[0]!.numResults).toBe(2)
|
|
||||||
})
|
|
||||||
|
|
||||||
test("throws for invalid action", async () => {
|
|
||||||
const source = new WebSearchSource({ client: new RecordingSearchClient() })
|
|
||||||
|
|
||||||
await expect(source.executeAction("missing", {})).rejects.toThrow("Unknown action")
|
|
||||||
})
|
|
||||||
|
|
||||||
test("throws for invalid search params", async () => {
|
|
||||||
const source = new WebSearchSource({ client: new RecordingSearchClient() })
|
|
||||||
|
|
||||||
await expect(
|
|
||||||
source.executeAction(WebSearchAction.Search, {
|
|
||||||
query: "",
|
|
||||||
}),
|
|
||||||
).rejects.toThrow("query must not be empty")
|
|
||||||
|
|
||||||
await expect(
|
|
||||||
source.executeAction(WebSearchAction.Search, {
|
|
||||||
query: "x",
|
|
||||||
numResults: 101,
|
|
||||||
}),
|
|
||||||
).rejects.toThrow("numResults must be an integer")
|
|
||||||
})
|
|
||||||
|
|
||||||
test("throws if neither client nor apiKey is provided", () => {
|
|
||||||
expect(() => new WebSearchSource({})).toThrow("Either client or apiKey must be provided")
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
import type { ActionDefinition, Context, ContextEntry, FeedSource } from "@freya/core"
|
|
||||||
|
|
||||||
import { UnknownActionError } from "@freya/core"
|
|
||||||
import { type } from "arktype"
|
|
||||||
|
|
||||||
import type {
|
|
||||||
WebSearchClient,
|
|
||||||
WebSearchRequest,
|
|
||||||
WebSearchResponse,
|
|
||||||
WebSearchSourceOptions,
|
|
||||||
} from "./types.ts"
|
|
||||||
|
|
||||||
import { ExaSearchClient } from "./exa-client.ts"
|
|
||||||
import { WebSearchAction, WebSearchType } from "./types.ts"
|
|
||||||
|
|
||||||
const DEFAULT_NUM_RESULTS = 10
|
|
||||||
const MIN_NUM_RESULTS = 1
|
|
||||||
const MAX_NUM_RESULTS = 100
|
|
||||||
|
|
||||||
const SearchInput = type({
|
|
||||||
"+": "reject",
|
|
||||||
query: "string",
|
|
||||||
"numResults?": "number",
|
|
||||||
"includeDomains?": "string[]",
|
|
||||||
"excludeDomains?": "string[]",
|
|
||||||
"startCrawlDate?": "string.date.iso",
|
|
||||||
"endCrawlDate?": "string.date.iso",
|
|
||||||
"startPublishedDate?": "string.date.iso",
|
|
||||||
"endPublishedDate?": "string.date.iso",
|
|
||||||
"type?": "'instant' | 'fast' | 'auto' | 'deep-lite' | 'deep' | 'deep-reasoning'",
|
|
||||||
"category?": "string",
|
|
||||||
"userLocation?": "string",
|
|
||||||
"moderation?": "boolean",
|
|
||||||
"highlights?": "boolean",
|
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Action-only FeedSource for web search through Exa.
|
|
||||||
*
|
|
||||||
* It intentionally does not produce feed items. Consumers call the `search`
|
|
||||||
* action and receive structured web results.
|
|
||||||
*/
|
|
||||||
export class WebSearchSource implements FeedSource {
|
|
||||||
readonly id = "freya.web-search"
|
|
||||||
|
|
||||||
private readonly client: WebSearchClient
|
|
||||||
|
|
||||||
constructor(options: WebSearchSourceOptions) {
|
|
||||||
if (!options.client && !options.apiKey) {
|
|
||||||
throw new Error("Either client or apiKey must be provided")
|
|
||||||
}
|
|
||||||
this.client = options.client ?? new ExaSearchClient(options.apiKey!)
|
|
||||||
}
|
|
||||||
|
|
||||||
async listActions(): Promise<Record<string, ActionDefinition>> {
|
|
||||||
return {
|
|
||||||
[WebSearchAction.Search]: {
|
|
||||||
id: WebSearchAction.Search,
|
|
||||||
description: "Search the web and return structured results",
|
|
||||||
input: SearchInput,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async executeAction(actionId: string, params: unknown): Promise<WebSearchResponse> {
|
|
||||||
switch (actionId) {
|
|
||||||
case WebSearchAction.Search:
|
|
||||||
return this.client.search(this.parseSearchInput(params))
|
|
||||||
default:
|
|
||||||
throw new UnknownActionError(actionId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fetchContext(_context: Context): Promise<readonly ContextEntry[] | null> {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
private parseSearchInput(params: unknown): WebSearchRequest {
|
|
||||||
const parsed = SearchInput(params)
|
|
||||||
if (parsed instanceof type.errors) {
|
|
||||||
throw new Error(parsed.summary)
|
|
||||||
}
|
|
||||||
|
|
||||||
const query = parsed.query.trim()
|
|
||||||
if (!query) {
|
|
||||||
throw new Error("query must not be empty")
|
|
||||||
}
|
|
||||||
|
|
||||||
const numResults = parsed.numResults ?? DEFAULT_NUM_RESULTS
|
|
||||||
if (
|
|
||||||
!Number.isInteger(numResults) ||
|
|
||||||
numResults < MIN_NUM_RESULTS ||
|
|
||||||
numResults > MAX_NUM_RESULTS
|
|
||||||
) {
|
|
||||||
throw new Error(`numResults must be an integer from ${MIN_NUM_RESULTS} to ${MAX_NUM_RESULTS}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parsed.userLocation && !/^[A-Za-z]{2}$/.test(parsed.userLocation)) {
|
|
||||||
throw new Error("userLocation must be a two-letter ISO country code")
|
|
||||||
}
|
|
||||||
|
|
||||||
const request: WebSearchRequest = {
|
|
||||||
query,
|
|
||||||
numResults,
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parsed.includeDomains) request.includeDomains = parsed.includeDomains
|
|
||||||
if (parsed.excludeDomains) request.excludeDomains = parsed.excludeDomains
|
|
||||||
if (parsed.startCrawlDate) request.startCrawlDate = parsed.startCrawlDate
|
|
||||||
if (parsed.endCrawlDate) request.endCrawlDate = parsed.endCrawlDate
|
|
||||||
if (parsed.startPublishedDate) request.startPublishedDate = parsed.startPublishedDate
|
|
||||||
if (parsed.endPublishedDate) request.endPublishedDate = parsed.endPublishedDate
|
|
||||||
if (parsed.type) request.type = parsed.type as WebSearchType
|
|
||||||
if (parsed.category) request.category = parsed.category
|
|
||||||
if (parsed.userLocation) request.userLocation = parsed.userLocation.toUpperCase()
|
|
||||||
if (parsed.moderation !== undefined) request.moderation = parsed.moderation
|
|
||||||
if (parsed.highlights !== undefined) request.highlights = parsed.highlights
|
|
||||||
|
|
||||||
return request
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user