Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions apps/host-cloudflare/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ export const makeCloudflareApp = async (env: CloudflareEnv) => {
const plugins = makeCloudflarePlugins(
config.secretKey,
env.ANALYTICS,
env.VECTORIZE,
config.geminiApiKey,
config.aiSearch,
config.organizationId,
);

Expand Down
20 changes: 6 additions & 14 deletions apps/host-cloudflare/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
R2Bucket,
} from "@cloudflare/workers-types";
import type { AnalyticsEngineDataset } from "@executor-js/plugin-execution-metrics/cloudflare";
import type { VectorizeIndex } from "@executor-js/plugin-semantic-search";
import type { AiSearchInstance } from "@executor-js/plugin-semantic-search";

import { isValidOrgSlug } from "@executor-js/api";
import { missingPublicOriginWarning, resolvePublicOrigin } from "@executor-js/sdk/public-origin";
Expand Down Expand Up @@ -34,15 +34,8 @@ export interface CloudflareEnv {
* bound (uncomment `analytics_engine_datasets` in wrangler.jsonc), each
* finished execution/tool call writes a data point; absent, metrics are off. */
readonly ANALYTICS?: AnalyticsEngineDataset;
/** Vectorize index binding — opt-in semantic `tools.search`. When bound (add a
* `vectorize` binding in wrangler.jsonc) the semantic-search plugin embeds
* the tool catalog and answers `tools.search` from it; absent, the engine
* keeps its built-in lexical search. */
readonly VECTORIZE?: VectorizeIndex;
/** Gemini API key (a `wrangler secret`) powering the embeddings for the
* Vectorize search. Absent → semantic search stays inert even if the index
* is bound. */
readonly GEMINI_API_KEY?: string;
/** AI Search instance binding for semantic `tools.search`. */
readonly AI_SEARCH?: AiSearchInstance;
/** MCP session Durable Object namespace — one addressable isolate per MCP
* session (the DO id IS the session id), so a session survives across the
* Worker's stateless isolates. */
Expand Down Expand Up @@ -86,9 +79,8 @@ export interface CloudflareConfig {
/** URL slug for org-prefixed console paths (`/<slug>/policies`). */
readonly organizationSlug: string;
readonly secretKey: string;
/** Gemini API key for the Vectorize search embeddings (a `wrangler secret`).
* Unset → vectorize search is inert. */
readonly geminiApiKey?: string;
/** AI Search instance binding for semantic `tools.search`. */
readonly aiSearch?: AiSearchInstance;
readonly allowLocalNetwork: boolean;
/** Explicit web base URL (`VITE_PUBLIC_SITE_URL`). Unset on a Worker with no
* static URL — the per-request origin is used instead (see RequestWebOrigin). */
Expand Down Expand Up @@ -146,7 +138,7 @@ export const loadConfig = (env: CloudflareEnv): CloudflareConfig => {
organizationName: env.SELF_HOSTED_ORG_NAME ?? "Default",
organizationSlug: resolveOrgSlug(env.SELF_HOSTED_ORG_SLUG),
secretKey,
geminiApiKey: env.GEMINI_API_KEY?.trim() || undefined,
aiSearch: env.AI_SEARCH,
allowLocalNetwork: env.ALLOW_LOCAL_NETWORK === "true",
// Pinned origin via the shared resolver. A Worker receives no PaaS platform
// vars (env: {} — there is nothing to detect), so only the explicit
Expand Down
3 changes: 2 additions & 1 deletion apps/host-cloudflare/src/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export const makeCloudflarePluginsProvider = (
config: CloudflareConfig,
): Layer.Layer<PluginsProvider> =>
Layer.succeed(PluginsProvider)({
plugins: () => makeCloudflarePlugins(config.secretKey),
plugins: () =>
makeCloudflarePlugins(config.secretKey, undefined, config.aiSearch, config.organizationId),
});

export const makeCloudflareHostConfig = (config: CloudflareConfig): Layer.Layer<HostConfig> =>
Expand Down
28 changes: 10 additions & 18 deletions apps/host-cloudflare/src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import { noopExecutionObserver } from "@executor-js/sdk";
import { serviceTokensPlugin } from "@executor-js/plugin-service-tokens/server";
import { semanticSearchHttpPlugin } from "@executor-js/plugin-semantic-search/api";
import {
makeVectorizeStore,
ToolSearchBackend,
withCloudflareLimits,
type VectorizeIndex,
makeAiSearchToolSearchBackend,
type AiSearchInstance,
} from "@executor-js/plugin-semantic-search";

// ---------------------------------------------------------------------------
Expand All @@ -39,27 +37,21 @@ import {
//
// Semantic search follows the same opt-in-by-binding shape: the plugin is
// always in the tuple (its reindex route keeps the API shape stable), but it is
// inert — the engine keeps its lexical `tools.search` — until BOTH a `vectorize`
// binding and the `GEMINI_API_KEY` secret are present. To enable: create a
// Vectorize index + add the binding in wrangler.jsonc and set the secret.
// inert until the Cloudflare AI Search binding is present.
// ---------------------------------------------------------------------------

export const makeCloudflarePlugins = (
secretKey: string,
analytics?: AnalyticsEngineDataset,
vectorize?: VectorizeIndex,
geminiApiKey?: string,
aiSearch?: AiSearchInstance,
searchNamespace?: string,
) => {
const store = vectorize ? withCloudflareLimits(makeVectorizeStore(vectorize)) : undefined;
const semanticSearchBackend =
store && geminiApiKey
? ToolSearchBackend.vector({
store,
geminiApiKey,
namespace: searchNamespace,
})
: undefined;
const semanticSearchBackend = aiSearch
? makeAiSearchToolSearchBackend({
aiSearch,
namespace: searchNamespace,
})
: undefined;
return [
openApiHttpPlugin(),
googleHttpPlugin(),
Expand Down
4 changes: 4 additions & 0 deletions apps/host-cloudflare/wrangler.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
// "analytics_engine_datasets": [
// { "binding": "ANALYTICS", "dataset": "executor_executions" },
// ],
// Cloudflare AI Search is the preferred backend for semantic `tools.search`.
// Uncomment after creating the instance, otherwise deploy will fail because
// the binding target is absent.
// "ai_search": [{ "binding": "AI_SEARCH", "instance_name": "executor-tool-search" }],
// The MCP session Durable Object: one addressable isolate per MCP session (the
// DO id IS the session id) so a session survives across the Worker's stateless
// isolates — without it, `tools/list` after `initialize` can land on a fresh
Expand Down
7 changes: 7 additions & 0 deletions packages/plugins/semantic-search/src/api/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ export const StatusResponse = Schema.Struct({
namespace: Schema.String,
indexed: Schema.Number,
lexical: Schema.NullOr(Schema.Number),
queued: Schema.optional(Schema.Number),
running: Schema.optional(Schema.Number),
completed: Schema.optional(Schema.Number),
error: Schema.optional(Schema.Number),
skipped: Schema.optional(Schema.Number),
outdated: Schema.optional(Schema.Number),
lastActivity: Schema.optional(Schema.String),
});

export type SearchResultItemType = typeof SearchResultItem.Type;
Expand Down
Loading
Loading