@frankieai/core 0.1.2 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -307,10 +307,12 @@ function truncate(value, max) {
307
307
  // src/install.ts
308
308
  function planHostedInstall(input) {
309
309
  const { files, workspace } = input;
310
- const layouts = Object.keys(files).filter((p) => /(?:^|\/)(?:src\/)?app\/layout\.tsx$/.test(p));
311
- const layoutPath = layouts.find((p) => /apps\/(dashboard|web)\//.test(p)) ?? layouts[0];
312
- if (!layoutPath) throw new Error("Automatic installation supports Next.js App Router. No app/layout.tsx was found.");
313
- const appRoot = layoutPath.slice(0, -"layout.tsx".length);
310
+ const layouts = Object.keys(files).filter((p) => /(?:^|\/)(?:src\/)?app(?:\/\([^/]+\))?\/layout\.tsx$/.test(p));
311
+ const rootLayoutPath = layouts.find((p) => !/(?:^|\/)app\/\([^/]+\)\/layout\.tsx$/.test(p)) ?? layouts[0];
312
+ if (!rootLayoutPath) throw new Error("Automatic installation supports Next.js App Router. No app/layout.tsx was found.");
313
+ const layoutPath = layouts.find((p) => /(?:^|\/)app\/\((?:dashboard|authenticated|protected|app)\)\/layout\.tsx$/.test(p)) ?? rootLayoutPath;
314
+ const appRoot = rootLayoutPath.slice(0, -"layout.tsx".length);
315
+ const integrationAppRoot = layoutPath.slice(0, -"layout.tsx".length);
314
316
  const root = appRoot.replace(/(?:src\/)?app\/$/, "");
315
317
  const pkgPath = root + "package.json";
316
318
  const pkg = JSON.parse(files[pkgPath] ?? "{}");
@@ -325,7 +327,7 @@ function planHostedInstall(input) {
325
327
  const tokenPath = appRoot + "api/frankie/token/route.ts";
326
328
  const needsAuthSetup = !workspace.allowAnonymous && !files[tokenPath] && !firebase && !authJs;
327
329
  if (needsAuthSetup) notes.push("Connect getCurrentUser in the generated token endpoint to your server session. It rejects requests until configured.");
328
- pkg.dependencies = { ...pkg.dependencies, "@frankieai/react": pkg.dependencies["@frankieai/react"] ?? "^0.1.4", ...!workspace.allowAnonymous ? { jose: pkg.dependencies.jose ?? "^6.0.11" } : {} };
330
+ pkg.dependencies = { ...pkg.dependencies, "@frankieai/react": pkg.dependencies["@frankieai/react"] ?? "^0.1.5", ...!workspace.allowAnonymous ? { jose: pkg.dependencies.jose ?? "^6.0.11" } : {} };
329
331
  out.set(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
330
332
  const authProp = workspace.allowAnonymous ? "" : " getUserToken={getUserToken}";
331
333
  const shared = `import { FrankieProvider, FrankieWidget, FrankieChatPage } from "@frankieai/react";
@@ -344,8 +346,8 @@ async function getUserToken() {
344
346
  if (previous.workspaceId === workspace.id && ["/chat", "/frankie/chat"].includes(previous.chatPath)) priorChat = previous.chatPath;
345
347
  } catch {
346
348
  }
347
- const chatPath = priorChat ?? (files[appRoot + "chat/page.tsx"] ? "/frankie/chat" : "/chat");
348
- if (!priorChat && files[appRoot + chatPath.slice(1) + "/page.tsx"]) throw new Error("Both /chat and /frankie/chat already exist. Choose a chat route manually.");
349
+ const chatPath = priorChat ?? (files[integrationAppRoot + "chat/page.tsx"] ? "/frankie/chat" : "/chat");
350
+ if (!priorChat && files[integrationAppRoot + chatPath.slice(1) + "/page.tsx"]) throw new Error("Both /chat and /frankie/chat already exist. Choose a chat route manually.");
349
351
  out.set(root + "frankie.install.json", JSON.stringify({ workspaceId: workspace.id, chatPath }, null, 2) + "\n");
350
352
  if (chatPath !== "/chat") notes.push("Existing /chat preserved. Frankie chat is available at /frankie/chat.");
351
353
  const mount = `"use client";
@@ -364,17 +366,24 @@ export function WorkspaceChatPage() {
364
366
  }
365
367
  `;
366
368
  const moduleName = existingMount ? "FrankieSetupChat" : "FrankieWidgetMount";
367
- out.set(appRoot + "frankie/" + moduleName + ".tsx", mount);
369
+ out.set(integrationAppRoot + "frankie/" + moduleName + ".tsx", mount);
368
370
  if (!existingMount) {
369
371
  const layout = files[layoutPath];
370
- if (!layout.includes("</body>")) throw new Error("The layout has no closing body. This custom layout needs manual widget placement.");
371
372
  const importLine = `import { FrankieWidgetMount } from "./frankie/FrankieWidgetMount";
372
373
  `;
373
374
  const withImport = /^["']use client["'];/.test(layout) ? layout.replace(/^(['"]use client['"];)/, "$1\n" + importLine) : importLine + layout;
374
- out.set(layoutPath, withImport.replace("</body>", " <FrankieWidgetMount />\n</body>"));
375
+ if (withImport.includes("</body>")) {
376
+ out.set(layoutPath, withImport.replace("</body>", " <FrankieWidgetMount />\n</body>"));
377
+ } else if (withImport.includes("</main>")) {
378
+ out.set(layoutPath, withImport.replace("</main>", " <FrankieWidgetMount />\n</main>"));
379
+ } else if (withImport.includes("{children}")) {
380
+ out.set(layoutPath, withImport.replace("{children}", "{children}<FrankieWidgetMount />"));
381
+ } else {
382
+ throw new Error("The selected layout has no safe widget mount point. Add FrankieWidgetMount manually.");
383
+ }
375
384
  }
376
385
  const pageImport = chatPath === "/chat" ? "../frankie/" : "../../frankie/";
377
- out.set(appRoot + chatPath.slice(1) + "/page.tsx", `import { WorkspaceChatPage } from "${pageImport}${moduleName}";
386
+ out.set(integrationAppRoot + chatPath.slice(1) + "/page.tsx", `import { WorkspaceChatPage } from "${pageImport}${moduleName}";
378
387
  export default WorkspaceChatPage;
379
388
  `);
380
389
  if (!workspace.allowAnonymous && !files[tokenPath]) {
@@ -432,7 +441,7 @@ export async function POST() {
432
441
  if (nextRoute) {
433
442
  const path = nextRoute[1].replace(/\/\([^/]+\)/g, "").replace(/\[([^\]]+)\]/g, "{$1}");
434
443
  if (path.includes("...") || /\/(?:auth|frankie)(?:\/|$)/.test(path)) continue;
435
- for (const method of ["GET", "POST", "PUT", "PATCH", "DELETE"]) {
444
+ for (const method of ["GET"]) {
436
445
  if (new RegExp("export\\s+(?:(?:async\\s+)?function\\s+" + method + "\\b|(?:const|let)\\s+" + method + "\\s*=)").test(content))
437
446
  addInstallOperation(paths, method, path, file);
438
447
  }
@@ -441,12 +450,14 @@ export async function POST() {
441
450
  addInstallOperation(paths, match[1].toUpperCase(), match[2].replace(/:([A-Za-z0-9_]+)/g, "{$1}"), file);
442
451
  }
443
452
  }
444
- doc ??= { openapi: "3.0.3", info: { title: workspace.name + " API", version: "1.0.0", description: "Generated route inventory. Review prefixes, schemas and authorization before enabling tools." }, servers: [{ url: input.apiBaseUrl ?? "/" }], paths };
453
+ doc ??= { openapi: "3.0.3", info: { title: workspace.name + " API", version: "1.0.0", description: "Read-only generated route inventory. Review schemas, authorization, and the deployed origin before enabling tools." }, paths };
445
454
  const specPath = root + "public/frankie.openapi.json";
446
455
  const operationCount = Object.values(doc.paths).reduce((n, item) => n + Object.keys(item).filter((m) => /^(get|post|put|patch|delete)$/.test(m)).length, 0);
447
456
  out.set(specPath, JSON.stringify(doc, null, 2) + "\n");
448
457
  if (!operationCount) notes.push("No supported API routes detected. The OpenAPI draft has no operations; add the real schema before connecting tools.");
449
- notes.push("Review generated schemas and route mount prefixes before enabling operations.");
458
+ notes.push("Generated OpenAPI is read-only (GET only). Add write operations only to a reviewed, user-authorized schema.");
459
+ notes.push("Verify the public spec URL is reachable without dashboard authentication before connecting it.");
460
+ notes.push("The token endpoint issues a signed user JWT, but your product API must validate it and enforce user/resource permissions before exposing tools.");
450
461
  const envPath = root + ".env.example";
451
462
  const env = (files[envPath] ?? "").replace(/^NEXT_PUBLIC_FRANKIE_KEY=.*\n?/gm, "").replace(/^FRANKIE_JWT_SECRET=.*\n?/gm, "").trimEnd();
452
463
  out.set(envPath, env + "\nNEXT_PUBLIC_FRANKIE_KEY=" + workspace.publishableKey + "\n" + (workspace.allowAnonymous ? "" : "# Server only: use the secret from this workspace. Never commit its value.\nFRANKIE_JWT_SECRET=\n"));
@@ -455,11 +466,12 @@ export async function POST() {
455
466
  Workspace: ${workspace.name}
456
467
 
457
468
  1. Add NEXT_PUBLIC_FRANKIE_KEY from .env.example to the frontend deployment.
458
- ${workspace.allowAnonymous ? "" : "2. Add FRANKIE_JWT_SECRET from this workspace to the server hosting /api/frankie/token. Never commit the value.\n"}3. Install dependencies, update the lockfile, review and deploy the PR.
459
- 4. Open ${chatPath}. The generated floating widget hides on this chat page.
460
- 5. Connect https://YOUR_APP/frankie.openapi.json in Frankie \u2192 Tools & MCP. Choose Direct OpenAPI or OpenAPI + hosted MCP and select allowed operations.
461
- 6. Forwarding sends the Frankie-signed JWT. Your API must verify it and enforce user/resource permissions. It is not automatically interchangeable with a Firebase or OAuth access token.
462
- 7. Review conversations in Workspace \u2192 Chat sessions.
469
+ ${workspace.allowAnonymous ? "" : "2. Add FRANKIE_JWT_SECRET from this workspace to the server hosting /api/frankie/token. Never commit the value.\n"}3. Run your package manager and commit the updated lockfile (for pnpm: pnpm install --lockfile-only). The remote GitHub installer cannot safely synthesize a lockfile.
470
+ 4. Confirm https://YOUR_APP/frankie.openapi.json is public. If your Next.js middleware protects all paths, explicitly bypass /frankie.openapi.json before connecting it.
471
+ 5. Open ${chatPath}. It is created inside the detected authenticated dashboard group when one exists; add its link to the host sidebar during review.
472
+ 6. Connect https://YOUR_APP/frankie.openapi.json in Frankie \u2192 Tools & MCP. The generated document contains only read-only GET operations.
473
+ 7. Forwarding sends the Frankie-signed JWT. Your API must validate it and enforce user/resource permissions. It is not automatically interchangeable with a Firebase or OAuth access token.
474
+ 8. Add NEXT_PUBLIC_FRANKIE_KEY to every frontend deployment environment (Preview and Production). ${workspace.allowAnonymous ? "" : "Add FRANKIE_JWT_SECRET only to the server environment running /api/frankie/token; never expose it to the browser.\n"}9. Review conversations in Workspace \u2192 Chat sessions.
463
475
 
464
476
  ## Remaining setup
465
477
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/config.ts","../src/tools.ts","../src/install.ts"],"sourcesContent":["export * from \"./config.js\";\nexport * from \"./protocol.js\";\nexport * from \"./tools.js\";\n\nexport * from \"./install.js\";\n","import { z } from \"zod\";\n\n/**\n * Tenant configuration. One config == one embedded agent. Everything a\n * customer needs to change to make Frankie theirs lives here, so the code\n * itself stays generic.\n */\n\nexport const widgetThemeSchema = z\n .object({\n primary: z.string().optional(),\n primaryForeground: z.string().optional(),\n background: z.string().optional(),\n foreground: z.string().optional(),\n muted: z.string().optional(),\n border: z.string().optional(),\n radius: z.string().optional(),\n fontFamily: z.string().optional(),\n mode: z.enum([\"light\", \"dark\", \"system\"]).default(\"system\"),\n })\n .prefault({});\n\nexport const thinkingLevelSchema = z.enum([\"minimal\", \"low\", \"medium\", \"high\", \"xhigh\", \"max\"]);\n\nexport const modelConfigSchema = z.object({\n /**\n * Any provider the model layer knows about. `fireworks` is the default;\n * `anthropic`, `openai`, `google`, `groq`, `together`, `openrouter` and\n * ~30 others resolve too, which is what makes the model a config choice.\n */\n provider: z.string().min(1).default(\"fireworks\"),\n /**\n * Model id within that provider. The default is Kimi K2.7 on Fireworks,\n * which serves a native Anthropic-Messages endpoint and a 262K window.\n */\n model: z.string().default(\"accounts/fireworks/models/kimi-k2p7-code\"),\n /** Env var holding the provider key. Never put the key in config itself. */\n apiKeyEnv: z.string().default(\"FIREWORKS_API_KEY\"),\n /** Override the provider's base URL (self-hosted gateways, tests). */\n baseUrl: z.string().url().optional(),\n maxTokens: z.number().int().positive().max(200_000).default(8192),\n temperature: z.number().min(0).max(2).default(0.6),\n /**\n * Reasoning depth. Lowest by default: an onboarding widget is latency-\n * sensitive and its questions rarely need deliberation.\n */\n thinkingLevel: thinkingLevelSchema.default(\"minimal\"),\n /** Forward the model's reasoning stream to the client as thinking deltas. */\n streamReasoning: z.boolean().default(false),\n});\n\n/** One selectable model in the (optional) end-user model picker. */\nexport const modelChoiceSchema = z.object({\n /** Provider model id, e.g. \"accounts/fireworks/models/kimi-k2p7-code\". */\n id: z.string().min(1),\n /** Shown in the picker, e.g. \"Fast\" or \"Smart\". */\n label: z.string().min(1),\n /** Defaults to the workspace's default provider when omitted. */\n provider: z.string().optional(),\n});\n\n/**\n * Optional, opt-in chat capabilities the SDK consumer turns on per workspace.\n * Everything here is OFF by default: an embedded agent only gets a wider surface\n * when the customer deliberately enables it.\n */\nexport const featuresConfigSchema = z\n .object({\n /** Let end users attach files. Images go to a vision model; docs are read as text. */\n attachments: z\n .object({\n enabled: z.boolean().default(false),\n /** Accepted MIME patterns, e.g. \"image/*\", \"text/*\", \"application/json\". */\n accept: z.array(z.string()).default([\"image/*\", \"text/*\", \"application/json\"]),\n maxMb: z.number().positive().max(25).default(10),\n maxCount: z.number().int().positive().max(10).default(4),\n })\n .prefault({}),\n /** Let end users choose the model, from a curated list you control. */\n modelPicker: z\n .object({\n enabled: z.boolean().default(false),\n /** The models offered to end users. The workspace default is always allowed. */\n models: z.array(modelChoiceSchema).default([]),\n })\n .prefault({}),\n /**\n * Platform onboarding: give the agent built-in tools to create and list the\n * signed-in user's own Frankie workspaces. Only for a workspace that *is* the\n * Frankie onboarding assistant — a normal customer never turns this on.\n */\n workspaceAdmin: z.boolean().default(false),\n })\n .prefault({});\n\nexport const mcpServerSchema = z.object({\n name: z\n .string()\n .min(1)\n .regex(/^[a-z0-9][a-z0-9_-]*$/i, \"MCP server names must be alphanumeric with - or _\"),\n enabled: z.boolean().default(true),\n /** Explicit tool selection. Omitted keeps legacy all-tools behavior; [] disables all. */\n selectedTools: z.array(z.string().min(1)).optional(),\n discoveredTools: z.array(z.object({ name: z.string(), description: z.string().optional() })).default([]),\n /** `http` covers streamable HTTP; `sse` is the legacy transport. */\n transport: z.enum([\"http\", \"sse\"]).default(\"http\"),\n url: z.string().url(),\n /** Static headers, e.g. a service token for the company's own MCP server. */\n headers: z.record(z.string(), z.string()).default({}),\n /**\n * When set, the verified end-user JWT is forwarded to the MCP server in this\n * header so the company's tools can act as that user. Use with care: only\n * enable it for MCP servers you control.\n */\n forwardUserTokenAs: z.string().optional(),\n /** Extra claims from the user token to forward as `x-frankie-<claim>`. */\n forwardUserClaims: z.array(z.string()).default([]),\n});\n\n/**\n * An HTTP API described by an OpenAPI document, turned into tools directly.\n *\n * This is the \"no MCP server to write\" path: point Frankie at a spec, name the\n * operations the agent may use, and it builds the tools at startup.\n */\nexport const apiCapabilitySchema = z.object({\n operationId: z.string().min(1),\n method: z.enum([\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\"]),\n path: z.string().min(1),\n summary: z.string().optional(),\n});\n\nexport const apiSourceSchema = z.object({\n name: z\n .string()\n .min(1)\n .regex(/^[a-z0-9][a-z0-9_-]*$/i, \"API source names must be alphanumeric with - or _\"),\n /** URL or local path to an OpenAPI 3.x document (JSON or YAML). */\n spec: z.string().min(1),\n /** Overrides the spec's own `servers[0].url`. Required if the spec has none. */\n baseUrl: z.string().url().optional(),\n /**\n * Operation ids the agent may call. Empty means \"every operation that passes\n * the other filters\" — fine for a small internal API, risky for a large one.\n */\n operations: z.array(z.string()).default([]),\n /**\n * Path globs to include, e.g. `/projects/**`. Empty means all paths.\n */\n includePaths: z.array(z.string()).default([]),\n /**\n * HTTP methods the agent may use. Read-only by default: an onboarding agent\n * wired to a whole API should not be able to DELETE on its first day. Widen\n * deliberately, per API.\n */\n methods: z.array(z.enum([\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\"])).default([\"GET\"]),\n enabled: z.boolean().default(true),\n /** Explicit operation selection, independent of the discovered inventory. */\n selectedTools: z.array(z.string().min(1)).optional(),\n /** Whether these approved API tools are also served by the workspace MCP. */\n exposeAsMcp: z.boolean().default(true),\n /** A read-only inventory derived from the source for the dashboard. */\n capabilities: z.array(apiCapabilitySchema).default([]),\n /** Static headers, e.g. a service token. */\n headers: z.record(z.string(), z.string()).default({}),\n /**\n * When set, the verified end-user JWT is forwarded in this header, so your\n * API authorises the call exactly as it would any other request from them.\n */\n forwardUserTokenAs: z.string().optional(),\n /** Extra claims from the user token to forward as `x-frankie-<claim>`. */\n forwardUserClaims: z.array(z.string()).default([]),\n /** Per-call timeout. */\n timeoutMs: z.number().int().positive().default(30_000),\n /** Response bodies longer than this are truncated before the model sees them. */\n maxResponseChars: z.number().int().positive().default(8_000),\n});\n\nexport const toolPolicySchema = z.object({\n /**\n * Tool names the agent may call without asking. MCP tools are named\n * `mcp__<server>__<tool>` and generated API tools `api__<name>__<operation>`;\n * naming the prefix alone (`mcp__acme`, `api__acme`) allows all of them.\n */\n allow: z.array(z.string()).default([]),\n /** Explicit denials; evaluated before `allow`. */\n deny: z.array(z.string()).default([]),\n /**\n * Deny anything not in `allow`. On by default — an onboarding agent living\n * on a public marketing page should not have an open tool surface.\n */\n denyByDefault: z.boolean().default(true),\n});\n\nexport const agentConfigSchema = z.object({\n /** Prepended to the runtime's own operating instructions. */\n systemPrompt: z.string().default(\"\"),\n /** First message the widget shows before the user types anything. */\n greeting: z.string().default(\"Hi! I can walk you through getting set up. What are you trying to do?\"),\n suggestedPrompts: z.array(z.string()).max(6).default([]),\n maxTurns: z.number().int().positive().max(50).default(12),\n /** Hard stop on estimated spend per session. */\n maxBudgetUsd: z.number().positive().optional(),\n tools: toolPolicySchema.prefault({}),\n /** Show tool activity in the transcript. */\n showToolActivity: z.boolean().default(true),\n});\n\nexport const authConfigSchema = z.object({\n /**\n * Safe to ship in client bundles. Identifies the tenant; it authorises\n * nothing on its own — the origin allowlist and the user token do that.\n */\n publishableKey: z.string().min(8),\n /** Exact origins allowed to open sessions, e.g. `https://app.acme.com`. */\n allowedOrigins: z.array(z.string()).default([]),\n /** Let visitors chat without a host-signed token (marketing pages). */\n allowAnonymous: z.boolean().default(false),\n /** Env var holding the HS256 secret the host signs user tokens with. */\n jwtSecretEnv: z.string().default(\"FRANKIE_JWT_SECRET\"),\n /** Verify against a JWKS endpoint instead of a shared secret (RS/ES256). */\n jwksUrl: z.string().url().optional(),\n jwtIssuer: z.string().optional(),\n jwtAudience: z.string().optional(),\n /** How long an issued session token is good for. */\n sessionTtlSeconds: z.number().int().positive().default(60 * 60),\n /** Env var holding the secret used to sign Frankie's own session tokens. */\n sessionSecretEnv: z.string().default(\"FRANKIE_SESSION_SECRET\"),\n});\n\nexport const limitsConfigSchema = z.object({\n /** Messages per session per window. */\n messagesPerWindow: z.number().int().positive().default(30),\n windowSeconds: z.number().int().positive().default(15 * 60),\n /** Sessions a single IP may open per window. */\n sessionsPerIpPerWindow: z.number().int().positive().default(20),\n /** Longest a single turn may run before it is aborted. */\n turnTimeoutMs: z.number().int().positive().default(120_000),\n});\n\nexport const brandingConfigSchema = z.object({\n name: z.string().default(\"Assistant\"),\n tagline: z.string().optional(),\n avatarUrl: z.string().url().optional(),\n launcherLabel: z.string().default(\"Need a hand?\"),\n});\n\nexport const frankieConfigSchema = z.object({\n tenantId: z.string().min(1),\n branding: brandingConfigSchema.prefault({}),\n theme: widgetThemeSchema,\n model: modelConfigSchema.prefault({}),\n agent: agentConfigSchema.prefault({}),\n auth: authConfigSchema,\n mcpServers: z.array(mcpServerSchema).default([]),\n /** APIs turned into tools from their OpenAPI document. */\n apis: z.array(apiSourceSchema).default([]),\n limits: limitsConfigSchema.prefault({}),\n /** Opt-in end-user chat capabilities (attachments, model picker). */\n features: featuresConfigSchema,\n});\n\nexport type ThinkingLevel = z.infer<typeof thinkingLevelSchema>;\nexport type WidgetThemeConfig = z.infer<typeof widgetThemeSchema>;\nexport type ModelChoice = z.infer<typeof modelChoiceSchema>;\nexport type FeaturesConfig = z.infer<typeof featuresConfigSchema>;\nexport type ModelConfig = z.infer<typeof modelConfigSchema>;\nexport type McpServerConfig = z.infer<typeof mcpServerSchema>;\nexport type ApiCapability = z.infer<typeof apiCapabilitySchema>;\nexport type ApiSourceConfig = z.infer<typeof apiSourceSchema>;\nexport type ToolPolicy = z.infer<typeof toolPolicySchema>;\nexport type AgentConfig = z.infer<typeof agentConfigSchema>;\nexport type AuthConfig = z.infer<typeof authConfigSchema>;\nexport type LimitsConfig = z.infer<typeof limitsConfigSchema>;\nexport type BrandingConfig = z.infer<typeof brandingConfigSchema>;\nexport type FrankieConfig = z.infer<typeof frankieConfigSchema>;\nexport type FrankieConfigInput = z.input<typeof frankieConfigSchema>;\n\nexport function parseFrankieConfig(input: unknown): FrankieConfig {\n return frankieConfigSchema.parse(input);\n}\n\n/** Helper for `frankie.config.ts` files — gives editors full completion. */\nexport function defineFrankieConfig(config: FrankieConfigInput): FrankieConfigInput {\n return config;\n}\n","import type { ToolPolicy } from \"./config.js\";\n\nexport interface ToolDecision {\n allowed: boolean;\n reason: string;\n}\n\n/**\n * Decide whether the agent may run a tool.\n *\n * Patterns are matched exactly, or as a prefix when they end in `*`. MCP tools\n * arrive as `mcp__<server>__<tool>`, so listing `mcp__acme` (no trailing star)\n * also allows every tool on the `acme` server.\n */\nexport function evaluateToolPolicy(toolName: string, policy: ToolPolicy): ToolDecision {\n if (matchesAny(toolName, policy.deny)) {\n return { allowed: false, reason: `\"${toolName}\" is on the deny list for this agent.` };\n }\n if (matchesAny(toolName, policy.allow)) {\n return { allowed: true, reason: \"allowed by policy\" };\n }\n if (policy.denyByDefault) {\n return { allowed: false, reason: `\"${toolName}\" is not in this agent's allow list.` };\n }\n return { allowed: true, reason: \"no policy match; default allow\" };\n}\n\nfunction matchesAny(toolName: string, patterns: readonly string[]): boolean {\n return patterns.some((pattern) => matches(toolName, pattern));\n}\n\nfunction matches(toolName: string, pattern: string): boolean {\n if (pattern === \"*\") return true;\n if (pattern.endsWith(\"*\")) return toolName.startsWith(pattern.slice(0, -1));\n if (toolName === pattern) return true;\n // `mcp__acme` covers `mcp__acme__create_workspace`.\n return toolName.startsWith(`${pattern}__`);\n}\n\n/** A short human label for a tool call, for the \"Frankie is …\" line in the UI. */\nexport function describeTool(toolName: string, input: unknown): string {\n const mcp = /^mcp__([^_]+(?:_[^_]+)*)__(.+)$/.exec(toolName);\n if (mcp) {\n const [, server, tool] = mcp;\n return `${humanise(tool ?? toolName)} · ${server}`;\n }\n const inputRecord = typeof input === \"object\" && input !== null ? (input as Record<string, unknown>) : {};\n const hint = inputRecord[\"path\"] ?? inputRecord[\"url\"] ?? inputRecord[\"query\"] ?? inputRecord[\"command\"];\n return typeof hint === \"string\" ? `${humanise(toolName)}: ${truncate(hint, 60)}` : humanise(toolName);\n}\n\nfunction humanise(name: string): string {\n return name\n .replace(/[_-]+/g, \" \")\n .replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n .replace(/\\b\\w/g, (c) => c.toUpperCase())\n .trim();\n}\n\nfunction truncate(value: string, max: number): string {\n return value.length <= max ? value : `${value.slice(0, max - 1)}…`;\n}\n","/** One installation plan for GitHub and the local CLI. Never includes credentials. */\nexport interface InstallProject {\n files: Record<string, string>;\n workspace: { id: string; name: string; publishableKey: string; allowAnonymous: boolean };\n apiBaseUrl?: string;\n}\nexport interface InstallPlan {\n files: Array<{ path: string; content: string }>; root: string; chatPath: string; specPath: string;\n operationCount: number; needsAuthSetup: boolean; notes: string[];\n}\ntype ApiDocument = { paths: Record<string, Record<string, unknown>>; [key: string]: unknown };\nexport function planHostedInstall(input: InstallProject): InstallPlan {\n const { files, workspace } = input;\n const layouts = Object.keys(files).filter((p) => /(?:^|\\/)(?:src\\/)?app\\/layout\\.tsx$/.test(p));\n const layoutPath = layouts.find((p) => /apps\\/(dashboard|web)\\//.test(p)) ?? layouts[0];\n if (!layoutPath) throw new Error(\"Automatic installation supports Next.js App Router. No app/layout.tsx was found.\");\n const appRoot = layoutPath.slice(0, -\"layout.tsx\".length);\n const root = appRoot.replace(/(?:src\\/)?app\\/$/, \"\");\n const pkgPath = root + \"package.json\";\n const pkg = JSON.parse(files[pkgPath] ?? \"{}\");\n if (!pkg.dependencies?.next) throw new Error(\"The selected app must have Next.js in dependencies.\");\n const out = new Map<string, string>();\n const notes: string[] = [];\n const existingMount = files[layoutPath]!.includes(\"FrankieWidgetMount\");\n const sourceRoot = appRoot.endsWith(\"src/app/\") ? root + \"src/\" : root;\n const firebase = Boolean(files[sourceRoot + \"lib/firebase-admin.ts\"]?.includes(\"getAdminAuth\") && files[sourceRoot + \"lib/session.ts\"]?.includes(\"SESSION_COOKIE\"));\n const authFile = files[sourceRoot + \"auth.ts\"];\n const authJs = Boolean(authFile?.includes(\"NextAuth\") && /export\\s+(?:const|let)\\s*\\{[^}]*\\bauth\\b/.test(authFile ?? \"\"));\n const tokenPath = appRoot + \"api/frankie/token/route.ts\";\n const needsAuthSetup = !workspace.allowAnonymous && !files[tokenPath] && !firebase && !authJs;\n if (needsAuthSetup) notes.push(\"Connect getCurrentUser in the generated token endpoint to your server session. It rejects requests until configured.\");\n pkg.dependencies = { ...pkg.dependencies, \"@frankieai/react\": pkg.dependencies[\"@frankieai/react\"] ?? \"^0.1.4\", ...(!workspace.allowAnonymous ? { jose: pkg.dependencies.jose ?? \"^6.0.11\" } : {}) };\n out.set(pkgPath, JSON.stringify(pkg, null, 2) + \"\\n\");\n const authProp = workspace.allowAnonymous ? \"\" : \" getUserToken={getUserToken}\";\n const shared = `import { FrankieProvider, FrankieWidget, FrankieChatPage } from \"@frankieai/react\";\\nimport \"@frankieai/react/styles.css\";\\n`;\n const getToken = workspace.allowAnonymous ? \"\" : `\nasync function getUserToken() {\n const response = await fetch(\"/api/frankie/token\", { method: \"POST\", credentials: \"same-origin\" });\n if (!response.ok) return undefined;\n return ((await response.json()) as { token?: string }).token;\n}\n`;\n let priorChat: string | undefined;\n try { const previous = JSON.parse(files[root + \"frankie.install.json\"] ?? \"{}\"); if (previous.workspaceId === workspace.id && [\"/chat\", \"/frankie/chat\"].includes(previous.chatPath)) priorChat = previous.chatPath; } catch {}\n const chatPath = priorChat ?? (files[appRoot + \"chat/page.tsx\"] ? \"/frankie/chat\" : \"/chat\");\n if (!priorChat && files[appRoot + chatPath.slice(1) + \"/page.tsx\"]) throw new Error(\"Both /chat and /frankie/chat already exist. Choose a chat route manually.\");\n out.set(root + \"frankie.install.json\", JSON.stringify({ workspaceId: workspace.id, chatPath }, null, 2) + \"\\n\");\n if (chatPath !== \"/chat\") notes.push(\"Existing /chat preserved. Frankie chat is available at /frankie/chat.\");\n const mount = `\"use client\";\\nimport { usePathname } from \"next/navigation\";\\n${shared}${getToken}\nexport function FrankieWidgetMount() {\n const pathname = usePathname();\n const key = process.env.NEXT_PUBLIC_FRANKIE_KEY;\n if (!key || pathname === ${JSON.stringify(chatPath)}) return null;\n return <FrankieProvider publishableKey={key}${authProp}><FrankieWidget /></FrankieProvider>;\n}\nexport function WorkspaceChatPage() {\n const key = process.env.NEXT_PUBLIC_FRANKIE_KEY;\n if (!key) return <p>Chat is not configured. Set NEXT_PUBLIC_FRANKIE_KEY in your deployment.</p>;\n return <FrankieChatPage publishableKey={key}${authProp} />;\n}\n`;\n const moduleName = existingMount ? \"FrankieSetupChat\" : \"FrankieWidgetMount\";\n out.set(appRoot + \"frankie/\" + moduleName + \".tsx\", mount);\n if (!existingMount) {\n const layout = files[layoutPath]!;\n if (!layout.includes(\"</body>\")) throw new Error(\"The layout has no closing body. This custom layout needs manual widget placement.\");\n const importLine = `import { FrankieWidgetMount } from \"./frankie/FrankieWidgetMount\";\\n`;\n const withImport = /^[\"']use client[\"'];/.test(layout) ? layout.replace(/^(['\"]use client['\"];)/, \"$1\\n\" + importLine) : importLine + layout;\n out.set(layoutPath, withImport.replace(\"</body>\", \" <FrankieWidgetMount />\\n</body>\"));\n }\n const pageImport = chatPath === \"/chat\" ? \"../frankie/\" : \"../../frankie/\";\n out.set(appRoot + chatPath.slice(1) + \"/page.tsx\", `import { WorkspaceChatPage } from \"${pageImport}${moduleName}\";\\nexport default WorkspaceChatPage;\\n`);\n if (!workspace.allowAnonymous && !files[tokenPath]) {\n const lookup = firebase\n ? `import { cookies } from \"next/headers\";\\nimport { getAdminAuth } from \"@/lib/firebase-admin\";\\nimport { SESSION_COOKIE } from \"@/lib/session\";\\nasync function getCurrentUser() {\\n const cookie = (await cookies()).get(SESSION_COOKIE)?.value;\\n if (!cookie) return null;\\n const user = await getAdminAuth().verifySessionCookie(cookie, true);\\n return { id: user.uid, name: user.name, email: user.email };\\n}\\n`\n : authJs ? `import { auth } from \"@/auth\";\\nasync function getCurrentUser() {\\n const session = await auth();\\n const user = session?.user as { id?: string; name?: string | null; email?: string | null } | undefined;\\n return user?.id ? user : null;\\n}\\n`\n : `// Replace with your app's verified server session lookup.\\nasync function getCurrentUser(): Promise<{ id: string; name?: string; email?: string } | null> { return null; }\\n`;\n out.set(tokenPath, `import { SignJWT } from \"jose\";\\nimport { NextResponse } from \"next/server\";\\n${lookup}\nexport async function POST() {\n const secret = process.env.FRANKIE_JWT_SECRET;\n if (!secret) return NextResponse.json({ error: \"Chat secret not configured\" }, { status: 503 });\n try {\n const user = await getCurrentUser();\n if (!user?.id) return NextResponse.json({ error: \"Sign in required\" }, { status: 401 });\n const token = await new SignJWT({ name: user.name, email: user.email })\n .setProtectedHeader({ alg: \"HS256\" }).setSubject(user.id).setIssuedAt()\n .setExpirationTime(\"5m\").sign(new TextEncoder().encode(secret));\n return NextResponse.json({ token }, { headers: { \"Cache-Control\": \"no-store\" } });\n } catch { return NextResponse.json({ error: \"Sign in required\" }, { status: 401 }); }\n}\n`);\n }\n let doc: ApiDocument | undefined;\n for (const [path, content] of Object.entries(files)) {\n if (!/(?:openapi|swagger)[^/]*\\.json$/i.test(path)) continue;\n try { const parsed = JSON.parse(content); if (parsed.openapi && parsed.paths) { doc = parsed; break; } } catch {}\n }\n const paths: Record<string, Record<string, unknown>> = {};\n if (!doc) for (const [file, content] of Object.entries(files)) {\n if (/\\.(test|spec)\\.[tj]sx?$/.test(file)) continue;\n const nextRoute = file.match(/(?:^|\\/)app(\\/.*)\\/route\\.[tj]s$/);\n if (nextRoute) {\n const path = nextRoute[1]!.replace(/\\/\\([^/]+\\)/g, \"\").replace(/\\[([^\\]]+)\\]/g, \"{$1}\");\n if (path.includes(\"...\") || /\\/(?:auth|frankie)(?:\\/|$)/.test(path)) continue;\n for (const method of [\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\"]) {\n if (new RegExp(\"export\\\\s+(?:(?:async\\\\s+)?function\\\\s+\" + method + \"\\\\b|(?:const|let)\\\\s+\" + method + \"\\\\s*=)\").test(content))\n addInstallOperation(paths, method, path, file);\n }\n } else if (/\\.[tj]s$/.test(file) && /(?:routes?|api)\\//.test(file)) {\n for (const match of content.matchAll(/\\b(?:app|router|fastify)\\.(get|post|put|patch|delete)(?:\\s*<[^;]{1,1600}?>)?\\s*\\(\\s*[\"']([^\"']+)[\"']/g))\n addInstallOperation(paths, match[1]!.toUpperCase(), match[2]!.replace(/:([A-Za-z0-9_]+)/g, \"{$1}\"), file);\n }\n }\n doc ??= { openapi: \"3.0.3\", info: { title: workspace.name + \" API\", version: \"1.0.0\", description: \"Generated route inventory. Review prefixes, schemas and authorization before enabling tools.\" }, servers: [{ url: input.apiBaseUrl ?? \"/\" }], paths };\n const specPath = root + \"public/frankie.openapi.json\";\n const operationCount = Object.values(doc.paths).reduce((n, item) => n + Object.keys(item).filter((m) => /^(get|post|put|patch|delete)$/.test(m)).length, 0);\n out.set(specPath, JSON.stringify(doc, null, 2) + \"\\n\");\n if (!operationCount) notes.push(\"No supported API routes detected. The OpenAPI draft has no operations; add the real schema before connecting tools.\");\n notes.push(\"Review generated schemas and route mount prefixes before enabling operations.\");\n const envPath = root + \".env.example\";\n const env = (files[envPath] ?? \"\").replace(/^NEXT_PUBLIC_FRANKIE_KEY=.*\\n?/gm, \"\").replace(/^FRANKIE_JWT_SECRET=.*\\n?/gm, \"\").trimEnd();\n out.set(envPath, env + \"\\nNEXT_PUBLIC_FRANKIE_KEY=\" + workspace.publishableKey + \"\\n\" + (workspace.allowAnonymous ? \"\" : \"# Server only: use the secret from this workspace. Never commit its value.\\nFRANKIE_JWT_SECRET=\\n\"));\n out.set(root + \"FRANKIE_SETUP.md\", `# Frankie setup\\n\\nWorkspace: ${workspace.name}\\n\\n1. Add NEXT_PUBLIC_FRANKIE_KEY from .env.example to the frontend deployment.\\n${workspace.allowAnonymous ? \"\" : \"2. Add FRANKIE_JWT_SECRET from this workspace to the server hosting /api/frankie/token. Never commit the value.\\n\"}3. Install dependencies, update the lockfile, review and deploy the PR.\\n4. Open ${chatPath}. The generated floating widget hides on this chat page.\\n5. Connect https://YOUR_APP/frankie.openapi.json in Frankie → Tools & MCP. Choose Direct OpenAPI or OpenAPI + hosted MCP and select allowed operations.\\n6. Forwarding sends the Frankie-signed JWT. Your API must verify it and enforce user/resource permissions. It is not automatically interchangeable with a Firebase or OAuth access token.\\n7. Review conversations in Workspace → Chat sessions.\\n\\n## Remaining setup\\n\\n${notes.map((n) => \"- \" + n).join(\"\\n\")}\\n`);\n return { files: [...out].map(([path, content]) => ({ path, content })), root, chatPath, specPath, operationCount, needsAuthSetup, notes };\n}\nfunction addInstallOperation(paths: Record<string, Record<string, unknown>>, method: string, path: string, file: string) {\n if (path.includes(\"*\") || !path.startsWith(\"/\")) return;\n (paths[path] ??= {})[method.toLowerCase()] = {\n operationId: (method.toLowerCase() + \"_\" + path).replace(/[^a-zA-Z0-9_]+/g, \"_\"),\n summary: method + \" \" + path, description: \"Detected in \" + file + \". Review schemas before enabling.\",\n parameters: [...path.matchAll(/\\{([^}]+)\\}/g)].map((m) => ({ name: m[1], in: \"path\", required: true, schema: { type: \"string\" } })),\n responses: { \"200\": { description: \"Successful response\" } }, \"x-frankie-review-required\": true,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAkB;AAQX,IAAM,oBAAoB,aAC9B,OAAO;AAAA,EACN,SAAS,aAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,mBAAmB,aAAE,OAAO,EAAE,SAAS;AAAA,EACvC,YAAY,aAAE,OAAO,EAAE,SAAS;AAAA,EAChC,YAAY,aAAE,OAAO,EAAE,SAAS;AAAA,EAChC,OAAO,aAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,QAAQ,aAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,QAAQ,aAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,YAAY,aAAE,OAAO,EAAE,SAAS;AAAA,EAChC,MAAM,aAAE,KAAK,CAAC,SAAS,QAAQ,QAAQ,CAAC,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;AAAA,IAC3C,cAAc,OAAO,YAAY,IAAI,MAAM,MAAM,QAAQ,mBAAmB,GAAG;AAAA,IAC/E,SAAS,SAAS,MAAM;AAAA,IAAM,aAAa,iBAAiB,OAAO;AAAA,IACnE,YAAY,CAAC,GAAG,KAAK,SAAS,cAAc,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI,QAAQ,UAAU,MAAM,QAAQ,EAAE,MAAM,SAAS,EAAE,EAAE;AAAA,IAClI,WAAW,EAAE,OAAO,EAAE,aAAa,sBAAsB,EAAE;AAAA,IAAG,6BAA6B;AAAA,EAC7F;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/config.ts","../src/tools.ts","../src/install.ts"],"sourcesContent":["export * from \"./config.js\";\nexport * from \"./protocol.js\";\nexport * from \"./tools.js\";\n\nexport * from \"./install.js\";\n","import { z } from \"zod\";\n\n/**\n * Tenant configuration. One config == one embedded agent. Everything a\n * customer needs to change to make Frankie theirs lives here, so the code\n * itself stays generic.\n */\n\nexport const widgetThemeSchema = z\n .object({\n primary: z.string().optional(),\n primaryForeground: z.string().optional(),\n background: z.string().optional(),\n foreground: z.string().optional(),\n muted: z.string().optional(),\n border: z.string().optional(),\n radius: z.string().optional(),\n fontFamily: z.string().optional(),\n mode: z.enum([\"light\", \"dark\", \"system\"]).default(\"system\"),\n })\n .prefault({});\n\nexport const thinkingLevelSchema = z.enum([\"minimal\", \"low\", \"medium\", \"high\", \"xhigh\", \"max\"]);\n\nexport const modelConfigSchema = z.object({\n /**\n * Any provider the model layer knows about. `fireworks` is the default;\n * `anthropic`, `openai`, `google`, `groq`, `together`, `openrouter` and\n * ~30 others resolve too, which is what makes the model a config choice.\n */\n provider: z.string().min(1).default(\"fireworks\"),\n /**\n * Model id within that provider. The default is Kimi K2.7 on Fireworks,\n * which serves a native Anthropic-Messages endpoint and a 262K window.\n */\n model: z.string().default(\"accounts/fireworks/models/kimi-k2p7-code\"),\n /** Env var holding the provider key. Never put the key in config itself. */\n apiKeyEnv: z.string().default(\"FIREWORKS_API_KEY\"),\n /** Override the provider's base URL (self-hosted gateways, tests). */\n baseUrl: z.string().url().optional(),\n maxTokens: z.number().int().positive().max(200_000).default(8192),\n temperature: z.number().min(0).max(2).default(0.6),\n /**\n * Reasoning depth. Lowest by default: an onboarding widget is latency-\n * sensitive and its questions rarely need deliberation.\n */\n thinkingLevel: thinkingLevelSchema.default(\"minimal\"),\n /** Forward the model's reasoning stream to the client as thinking deltas. */\n streamReasoning: z.boolean().default(false),\n});\n\n/** One selectable model in the (optional) end-user model picker. */\nexport const modelChoiceSchema = z.object({\n /** Provider model id, e.g. \"accounts/fireworks/models/kimi-k2p7-code\". */\n id: z.string().min(1),\n /** Shown in the picker, e.g. \"Fast\" or \"Smart\". */\n label: z.string().min(1),\n /** Defaults to the workspace's default provider when omitted. */\n provider: z.string().optional(),\n});\n\n/**\n * Optional, opt-in chat capabilities the SDK consumer turns on per workspace.\n * Everything here is OFF by default: an embedded agent only gets a wider surface\n * when the customer deliberately enables it.\n */\nexport const featuresConfigSchema = z\n .object({\n /** Let end users attach files. Images go to a vision model; docs are read as text. */\n attachments: z\n .object({\n enabled: z.boolean().default(false),\n /** Accepted MIME patterns, e.g. \"image/*\", \"text/*\", \"application/json\". */\n accept: z.array(z.string()).default([\"image/*\", \"text/*\", \"application/json\"]),\n maxMb: z.number().positive().max(25).default(10),\n maxCount: z.number().int().positive().max(10).default(4),\n })\n .prefault({}),\n /** Let end users choose the model, from a curated list you control. */\n modelPicker: z\n .object({\n enabled: z.boolean().default(false),\n /** The models offered to end users. The workspace default is always allowed. */\n models: z.array(modelChoiceSchema).default([]),\n })\n .prefault({}),\n /**\n * Platform onboarding: give the agent built-in tools to create and list the\n * signed-in user's own Frankie workspaces. Only for a workspace that *is* the\n * Frankie onboarding assistant — a normal customer never turns this on.\n */\n workspaceAdmin: z.boolean().default(false),\n })\n .prefault({});\n\nexport const mcpServerSchema = z.object({\n name: z\n .string()\n .min(1)\n .regex(/^[a-z0-9][a-z0-9_-]*$/i, \"MCP server names must be alphanumeric with - or _\"),\n enabled: z.boolean().default(true),\n /** Explicit tool selection. Omitted keeps legacy all-tools behavior; [] disables all. */\n selectedTools: z.array(z.string().min(1)).optional(),\n discoveredTools: z.array(z.object({ name: z.string(), description: z.string().optional() })).default([]),\n /** `http` covers streamable HTTP; `sse` is the legacy transport. */\n transport: z.enum([\"http\", \"sse\"]).default(\"http\"),\n url: z.string().url(),\n /** Static headers, e.g. a service token for the company's own MCP server. */\n headers: z.record(z.string(), z.string()).default({}),\n /**\n * When set, the verified end-user JWT is forwarded to the MCP server in this\n * header so the company's tools can act as that user. Use with care: only\n * enable it for MCP servers you control.\n */\n forwardUserTokenAs: z.string().optional(),\n /** Extra claims from the user token to forward as `x-frankie-<claim>`. */\n forwardUserClaims: z.array(z.string()).default([]),\n});\n\n/**\n * An HTTP API described by an OpenAPI document, turned into tools directly.\n *\n * This is the \"no MCP server to write\" path: point Frankie at a spec, name the\n * operations the agent may use, and it builds the tools at startup.\n */\nexport const apiCapabilitySchema = z.object({\n operationId: z.string().min(1),\n method: z.enum([\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\"]),\n path: z.string().min(1),\n summary: z.string().optional(),\n});\n\nexport const apiSourceSchema = z.object({\n name: z\n .string()\n .min(1)\n .regex(/^[a-z0-9][a-z0-9_-]*$/i, \"API source names must be alphanumeric with - or _\"),\n /** URL or local path to an OpenAPI 3.x document (JSON or YAML). */\n spec: z.string().min(1),\n /** Overrides the spec's own `servers[0].url`. Required if the spec has none. */\n baseUrl: z.string().url().optional(),\n /**\n * Operation ids the agent may call. Empty means \"every operation that passes\n * the other filters\" — fine for a small internal API, risky for a large one.\n */\n operations: z.array(z.string()).default([]),\n /**\n * Path globs to include, e.g. `/projects/**`. Empty means all paths.\n */\n includePaths: z.array(z.string()).default([]),\n /**\n * HTTP methods the agent may use. Read-only by default: an onboarding agent\n * wired to a whole API should not be able to DELETE on its first day. Widen\n * deliberately, per API.\n */\n methods: z.array(z.enum([\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\"])).default([\"GET\"]),\n enabled: z.boolean().default(true),\n /** Explicit operation selection, independent of the discovered inventory. */\n selectedTools: z.array(z.string().min(1)).optional(),\n /** Whether these approved API tools are also served by the workspace MCP. */\n exposeAsMcp: z.boolean().default(true),\n /** A read-only inventory derived from the source for the dashboard. */\n capabilities: z.array(apiCapabilitySchema).default([]),\n /** Static headers, e.g. a service token. */\n headers: z.record(z.string(), z.string()).default({}),\n /**\n * When set, the verified end-user JWT is forwarded in this header, so your\n * API authorises the call exactly as it would any other request from them.\n */\n forwardUserTokenAs: z.string().optional(),\n /** Extra claims from the user token to forward as `x-frankie-<claim>`. */\n forwardUserClaims: z.array(z.string()).default([]),\n /** Per-call timeout. */\n timeoutMs: z.number().int().positive().default(30_000),\n /** Response bodies longer than this are truncated before the model sees them. */\n maxResponseChars: z.number().int().positive().default(8_000),\n});\n\nexport const toolPolicySchema = z.object({\n /**\n * Tool names the agent may call without asking. MCP tools are named\n * `mcp__<server>__<tool>` and generated API tools `api__<name>__<operation>`;\n * naming the prefix alone (`mcp__acme`, `api__acme`) allows all of them.\n */\n allow: z.array(z.string()).default([]),\n /** Explicit denials; evaluated before `allow`. */\n deny: z.array(z.string()).default([]),\n /**\n * Deny anything not in `allow`. On by default — an onboarding agent living\n * on a public marketing page should not have an open tool surface.\n */\n denyByDefault: z.boolean().default(true),\n});\n\nexport const agentConfigSchema = z.object({\n /** Prepended to the runtime's own operating instructions. */\n systemPrompt: z.string().default(\"\"),\n /** First message the widget shows before the user types anything. */\n greeting: z.string().default(\"Hi! I can walk you through getting set up. What are you trying to do?\"),\n suggestedPrompts: z.array(z.string()).max(6).default([]),\n maxTurns: z.number().int().positive().max(50).default(12),\n /** Hard stop on estimated spend per session. */\n maxBudgetUsd: z.number().positive().optional(),\n tools: toolPolicySchema.prefault({}),\n /** Show tool activity in the transcript. */\n showToolActivity: z.boolean().default(true),\n});\n\nexport const authConfigSchema = z.object({\n /**\n * Safe to ship in client bundles. Identifies the tenant; it authorises\n * nothing on its own — the origin allowlist and the user token do that.\n */\n publishableKey: z.string().min(8),\n /** Exact origins allowed to open sessions, e.g. `https://app.acme.com`. */\n allowedOrigins: z.array(z.string()).default([]),\n /** Let visitors chat without a host-signed token (marketing pages). */\n allowAnonymous: z.boolean().default(false),\n /** Env var holding the HS256 secret the host signs user tokens with. */\n jwtSecretEnv: z.string().default(\"FRANKIE_JWT_SECRET\"),\n /** Verify against a JWKS endpoint instead of a shared secret (RS/ES256). */\n jwksUrl: z.string().url().optional(),\n jwtIssuer: z.string().optional(),\n jwtAudience: z.string().optional(),\n /** How long an issued session token is good for. */\n sessionTtlSeconds: z.number().int().positive().default(60 * 60),\n /** Env var holding the secret used to sign Frankie's own session tokens. */\n sessionSecretEnv: z.string().default(\"FRANKIE_SESSION_SECRET\"),\n});\n\nexport const limitsConfigSchema = z.object({\n /** Messages per session per window. */\n messagesPerWindow: z.number().int().positive().default(30),\n windowSeconds: z.number().int().positive().default(15 * 60),\n /** Sessions a single IP may open per window. */\n sessionsPerIpPerWindow: z.number().int().positive().default(20),\n /** Longest a single turn may run before it is aborted. */\n turnTimeoutMs: z.number().int().positive().default(120_000),\n});\n\nexport const brandingConfigSchema = z.object({\n name: z.string().default(\"Assistant\"),\n tagline: z.string().optional(),\n avatarUrl: z.string().url().optional(),\n launcherLabel: z.string().default(\"Need a hand?\"),\n});\n\nexport const frankieConfigSchema = z.object({\n tenantId: z.string().min(1),\n branding: brandingConfigSchema.prefault({}),\n theme: widgetThemeSchema,\n model: modelConfigSchema.prefault({}),\n agent: agentConfigSchema.prefault({}),\n auth: authConfigSchema,\n mcpServers: z.array(mcpServerSchema).default([]),\n /** APIs turned into tools from their OpenAPI document. */\n apis: z.array(apiSourceSchema).default([]),\n limits: limitsConfigSchema.prefault({}),\n /** Opt-in end-user chat capabilities (attachments, model picker). */\n features: featuresConfigSchema,\n});\n\nexport type ThinkingLevel = z.infer<typeof thinkingLevelSchema>;\nexport type WidgetThemeConfig = z.infer<typeof widgetThemeSchema>;\nexport type ModelChoice = z.infer<typeof modelChoiceSchema>;\nexport type FeaturesConfig = z.infer<typeof featuresConfigSchema>;\nexport type ModelConfig = z.infer<typeof modelConfigSchema>;\nexport type McpServerConfig = z.infer<typeof mcpServerSchema>;\nexport type ApiCapability = z.infer<typeof apiCapabilitySchema>;\nexport type ApiSourceConfig = z.infer<typeof apiSourceSchema>;\nexport type ToolPolicy = z.infer<typeof toolPolicySchema>;\nexport type AgentConfig = z.infer<typeof agentConfigSchema>;\nexport type AuthConfig = z.infer<typeof authConfigSchema>;\nexport type LimitsConfig = z.infer<typeof limitsConfigSchema>;\nexport type BrandingConfig = z.infer<typeof brandingConfigSchema>;\nexport type FrankieConfig = z.infer<typeof frankieConfigSchema>;\nexport type FrankieConfigInput = z.input<typeof frankieConfigSchema>;\n\nexport function parseFrankieConfig(input: unknown): FrankieConfig {\n return frankieConfigSchema.parse(input);\n}\n\n/** Helper for `frankie.config.ts` files — gives editors full completion. */\nexport function defineFrankieConfig(config: FrankieConfigInput): FrankieConfigInput {\n return config;\n}\n","import type { ToolPolicy } from \"./config.js\";\n\nexport interface ToolDecision {\n allowed: boolean;\n reason: string;\n}\n\n/**\n * Decide whether the agent may run a tool.\n *\n * Patterns are matched exactly, or as a prefix when they end in `*`. MCP tools\n * arrive as `mcp__<server>__<tool>`, so listing `mcp__acme` (no trailing star)\n * also allows every tool on the `acme` server.\n */\nexport function evaluateToolPolicy(toolName: string, policy: ToolPolicy): ToolDecision {\n if (matchesAny(toolName, policy.deny)) {\n return { allowed: false, reason: `\"${toolName}\" is on the deny list for this agent.` };\n }\n if (matchesAny(toolName, policy.allow)) {\n return { allowed: true, reason: \"allowed by policy\" };\n }\n if (policy.denyByDefault) {\n return { allowed: false, reason: `\"${toolName}\" is not in this agent's allow list.` };\n }\n return { allowed: true, reason: \"no policy match; default allow\" };\n}\n\nfunction matchesAny(toolName: string, patterns: readonly string[]): boolean {\n return patterns.some((pattern) => matches(toolName, pattern));\n}\n\nfunction matches(toolName: string, pattern: string): boolean {\n if (pattern === \"*\") return true;\n if (pattern.endsWith(\"*\")) return toolName.startsWith(pattern.slice(0, -1));\n if (toolName === pattern) return true;\n // `mcp__acme` covers `mcp__acme__create_workspace`.\n return toolName.startsWith(`${pattern}__`);\n}\n\n/** A short human label for a tool call, for the \"Frankie is …\" line in the UI. */\nexport function describeTool(toolName: string, input: unknown): string {\n const mcp = /^mcp__([^_]+(?:_[^_]+)*)__(.+)$/.exec(toolName);\n if (mcp) {\n const [, server, tool] = mcp;\n return `${humanise(tool ?? toolName)} · ${server}`;\n }\n const inputRecord = typeof input === \"object\" && input !== null ? (input as Record<string, unknown>) : {};\n const hint = inputRecord[\"path\"] ?? inputRecord[\"url\"] ?? inputRecord[\"query\"] ?? inputRecord[\"command\"];\n return typeof hint === \"string\" ? `${humanise(toolName)}: ${truncate(hint, 60)}` : humanise(toolName);\n}\n\nfunction humanise(name: string): string {\n return name\n .replace(/[_-]+/g, \" \")\n .replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n .replace(/\\b\\w/g, (c) => c.toUpperCase())\n .trim();\n}\n\nfunction truncate(value: string, max: number): string {\n return value.length <= max ? value : `${value.slice(0, max - 1)}…`;\n}\n","/** One installation plan for GitHub and the local CLI. Never includes credentials. */\nexport interface InstallProject {\n files: Record<string, string>;\n workspace: { id: string; name: string; publishableKey: string; allowAnonymous: boolean };\n apiBaseUrl?: string;\n}\nexport interface InstallPlan {\n files: Array<{ path: string; content: string }>; root: string; chatPath: string; specPath: string;\n operationCount: number; needsAuthSetup: boolean; notes: string[];\n}\ntype ApiDocument = { paths: Record<string, Record<string, unknown>>; [key: string]: unknown };\nexport function planHostedInstall(input: InstallProject): InstallPlan {\n const { files, workspace } = input;\n const layouts = Object.keys(files).filter((p) => /(?:^|\\/)(?:src\\/)?app(?:\\/\\([^/]+\\))?\\/layout\\.tsx$/.test(p));\n const rootLayoutPath = layouts.find((p) => !/(?:^|\\/)app\\/\\([^/]+\\)\\/layout\\.tsx$/.test(p)) ?? layouts[0];\n if (!rootLayoutPath) throw new Error(\"Automatic installation supports Next.js App Router. No app/layout.tsx was found.\");\n // Prefer an existing authenticated/dashboard route group for the chat page and\n // floating widget; route groups do not change the URL, but preserve its layout,\n // session gate, and sidebar.\n const layoutPath = layouts.find((p) => /(?:^|\\/)app\\/\\((?:dashboard|authenticated|protected|app)\\)\\/layout\\.tsx$/.test(p)) ?? rootLayoutPath;\n const appRoot = rootLayoutPath.slice(0, -\"layout.tsx\".length);\n const integrationAppRoot = layoutPath.slice(0, -\"layout.tsx\".length);\n const root = appRoot.replace(/(?:src\\/)?app\\/$/, \"\");\n const pkgPath = root + \"package.json\";\n const pkg = JSON.parse(files[pkgPath] ?? \"{}\");\n if (!pkg.dependencies?.next) throw new Error(\"The selected app must have Next.js in dependencies.\");\n const out = new Map<string, string>();\n const notes: string[] = [];\n const existingMount = files[layoutPath]!.includes(\"FrankieWidgetMount\");\n const sourceRoot = appRoot.endsWith(\"src/app/\") ? root + \"src/\" : root;\n const firebase = Boolean(files[sourceRoot + \"lib/firebase-admin.ts\"]?.includes(\"getAdminAuth\") && files[sourceRoot + \"lib/session.ts\"]?.includes(\"SESSION_COOKIE\"));\n const authFile = files[sourceRoot + \"auth.ts\"];\n const authJs = Boolean(authFile?.includes(\"NextAuth\") && /export\\s+(?:const|let)\\s*\\{[^}]*\\bauth\\b/.test(authFile ?? \"\"));\n const tokenPath = appRoot + \"api/frankie/token/route.ts\";\n const needsAuthSetup = !workspace.allowAnonymous && !files[tokenPath] && !firebase && !authJs;\n if (needsAuthSetup) notes.push(\"Connect getCurrentUser in the generated token endpoint to your server session. It rejects requests until configured.\");\n pkg.dependencies = { ...pkg.dependencies, \"@frankieai/react\": pkg.dependencies[\"@frankieai/react\"] ?? \"^0.1.5\", ...(!workspace.allowAnonymous ? { jose: pkg.dependencies.jose ?? \"^6.0.11\" } : {}) };\n out.set(pkgPath, JSON.stringify(pkg, null, 2) + \"\\n\");\n const authProp = workspace.allowAnonymous ? \"\" : \" getUserToken={getUserToken}\";\n // The distributed stylesheet omits Preflight and scopes every rule to .frankie-root,\n // so the full-page chat is polished without changing the host dashboard.\n const shared = `import { FrankieProvider, FrankieWidget, FrankieChatPage } from \"@frankieai/react\";\\nimport \"@frankieai/react/styles.css\";\\n`;\n const getToken = workspace.allowAnonymous ? \"\" : `\nasync function getUserToken() {\n const response = await fetch(\"/api/frankie/token\", { method: \"POST\", credentials: \"same-origin\" });\n if (!response.ok) return undefined;\n return ((await response.json()) as { token?: string }).token;\n}\n`;\n let priorChat: string | undefined;\n try { const previous = JSON.parse(files[root + \"frankie.install.json\"] ?? \"{}\"); if (previous.workspaceId === workspace.id && [\"/chat\", \"/frankie/chat\"].includes(previous.chatPath)) priorChat = previous.chatPath; } catch {}\n const chatPath = priorChat ?? (files[integrationAppRoot + \"chat/page.tsx\"] ? \"/frankie/chat\" : \"/chat\");\n if (!priorChat && files[integrationAppRoot + chatPath.slice(1) + \"/page.tsx\"]) throw new Error(\"Both /chat and /frankie/chat already exist. Choose a chat route manually.\");\n out.set(root + \"frankie.install.json\", JSON.stringify({ workspaceId: workspace.id, chatPath }, null, 2) + \"\\n\");\n if (chatPath !== \"/chat\") notes.push(\"Existing /chat preserved. Frankie chat is available at /frankie/chat.\");\n const mount = `\"use client\";\\nimport { usePathname } from \"next/navigation\";\\n${shared}${getToken}\nexport function FrankieWidgetMount() {\n const pathname = usePathname();\n const key = process.env.NEXT_PUBLIC_FRANKIE_KEY;\n if (!key || pathname === ${JSON.stringify(chatPath)}) return null;\n return <FrankieProvider publishableKey={key}${authProp}><FrankieWidget /></FrankieProvider>;\n}\nexport function WorkspaceChatPage() {\n const key = process.env.NEXT_PUBLIC_FRANKIE_KEY;\n if (!key) return <p>Chat is not configured. Set NEXT_PUBLIC_FRANKIE_KEY in your deployment.</p>;\n return <FrankieChatPage publishableKey={key}${authProp} />;\n}\n`;\n const moduleName = existingMount ? \"FrankieSetupChat\" : \"FrankieWidgetMount\";\n out.set(integrationAppRoot + \"frankie/\" + moduleName + \".tsx\", mount);\n if (!existingMount) {\n const layout = files[layoutPath]!;\n const importLine = `import { FrankieWidgetMount } from \"./frankie/FrankieWidgetMount\";\\n`;\n const withImport = /^[\"']use client[\"'];/.test(layout) ? layout.replace(/^(['\"]use client['\"];)/, \"$1\\n\" + importLine) : importLine + layout;\n if (withImport.includes(\"</body>\")) {\n out.set(layoutPath, withImport.replace(\"</body>\", \" <FrankieWidgetMount />\\n</body>\"));\n } else if (withImport.includes(\"</main>\")) {\n out.set(layoutPath, withImport.replace(\"</main>\", \" <FrankieWidgetMount />\\n</main>\"));\n } else if (withImport.includes(\"{children}\")) {\n out.set(layoutPath, withImport.replace(\"{children}\", \"{children}<FrankieWidgetMount />\"));\n } else {\n throw new Error(\"The selected layout has no safe widget mount point. Add FrankieWidgetMount manually.\");\n }\n }\n const pageImport = chatPath === \"/chat\" ? \"../frankie/\" : \"../../frankie/\";\n out.set(integrationAppRoot + chatPath.slice(1) + \"/page.tsx\", `import { WorkspaceChatPage } from \"${pageImport}${moduleName}\";\\nexport default WorkspaceChatPage;\\n`);\n if (!workspace.allowAnonymous && !files[tokenPath]) {\n const lookup = firebase\n ? `import { cookies } from \"next/headers\";\\nimport { getAdminAuth } from \"@/lib/firebase-admin\";\\nimport { SESSION_COOKIE } from \"@/lib/session\";\\nasync function getCurrentUser() {\\n const cookie = (await cookies()).get(SESSION_COOKIE)?.value;\\n if (!cookie) return null;\\n const user = await getAdminAuth().verifySessionCookie(cookie, true);\\n return { id: user.uid, name: user.name, email: user.email };\\n}\\n`\n : authJs ? `import { auth } from \"@/auth\";\\nasync function getCurrentUser() {\\n const session = await auth();\\n const user = session?.user as { id?: string; name?: string | null; email?: string | null } | undefined;\\n return user?.id ? user : null;\\n}\\n`\n : `// Replace with your app's verified server session lookup.\\nasync function getCurrentUser(): Promise<{ id: string; name?: string; email?: string } | null> { return null; }\\n`;\n out.set(tokenPath, `import { SignJWT } from \"jose\";\\nimport { NextResponse } from \"next/server\";\\n${lookup}\nexport async function POST() {\n const secret = process.env.FRANKIE_JWT_SECRET;\n if (!secret) return NextResponse.json({ error: \"Chat secret not configured\" }, { status: 503 });\n try {\n const user = await getCurrentUser();\n if (!user?.id) return NextResponse.json({ error: \"Sign in required\" }, { status: 401 });\n const token = await new SignJWT({ name: user.name, email: user.email })\n .setProtectedHeader({ alg: \"HS256\" }).setSubject(user.id).setIssuedAt()\n .setExpirationTime(\"5m\").sign(new TextEncoder().encode(secret));\n return NextResponse.json({ token }, { headers: { \"Cache-Control\": \"no-store\" } });\n } catch { return NextResponse.json({ error: \"Sign in required\" }, { status: 401 }); }\n}\n`);\n }\n let doc: ApiDocument | undefined;\n for (const [path, content] of Object.entries(files)) {\n if (!/(?:openapi|swagger)[^/]*\\.json$/i.test(path)) continue;\n try { const parsed = JSON.parse(content); if (parsed.openapi && parsed.paths) { doc = parsed; break; } } catch {}\n }\n const paths: Record<string, Record<string, unknown>> = {};\n if (!doc) for (const [file, content] of Object.entries(files)) {\n if (/\\.(test|spec)\\.[tj]sx?$/.test(file)) continue;\n const nextRoute = file.match(/(?:^|\\/)app(\\/.*)\\/route\\.[tj]s$/);\n if (nextRoute) {\n const path = nextRoute[1]!.replace(/\\/\\([^/]+\\)/g, \"\").replace(/\\[([^\\]]+)\\]/g, \"{$1}\");\n if (path.includes(\"...\") || /\\/(?:auth|frankie)(?:\\/|$)/.test(path)) continue;\n // Generated tool inventories are read-only. Writes require an explicit, reviewed schema.\n for (const method of [\"GET\"]) {\n if (new RegExp(\"export\\\\s+(?:(?:async\\\\s+)?function\\\\s+\" + method + \"\\\\b|(?:const|let)\\\\s+\" + method + \"\\\\s*=)\").test(content))\n addInstallOperation(paths, method, path, file);\n }\n } else if (/\\.[tj]s$/.test(file) && /(?:routes?|api)\\//.test(file)) {\n for (const match of content.matchAll(/\\b(?:app|router|fastify)\\.(get|post|put|patch|delete)(?:\\s*<[^;]{1,1600}?>)?\\s*\\(\\s*[\"']([^\"']+)[\"']/g))\n addInstallOperation(paths, match[1]!.toUpperCase(), match[2]!.replace(/:([A-Za-z0-9_]+)/g, \"{$1}\"), file);\n }\n }\n doc ??= { openapi: \"3.0.3\", info: { title: workspace.name + \" API\", version: \"1.0.0\", description: \"Read-only generated route inventory. Review schemas, authorization, and the deployed origin before enabling tools.\" }, paths };\n const specPath = root + \"public/frankie.openapi.json\";\n const operationCount = Object.values(doc.paths).reduce((n, item) => n + Object.keys(item).filter((m) => /^(get|post|put|patch|delete)$/.test(m)).length, 0);\n out.set(specPath, JSON.stringify(doc, null, 2) + \"\\n\");\n if (!operationCount) notes.push(\"No supported API routes detected. The OpenAPI draft has no operations; add the real schema before connecting tools.\");\n notes.push(\"Generated OpenAPI is read-only (GET only). Add write operations only to a reviewed, user-authorized schema.\");\n notes.push(\"Verify the public spec URL is reachable without dashboard authentication before connecting it.\");\n notes.push(\"The token endpoint issues a signed user JWT, but your product API must validate it and enforce user/resource permissions before exposing tools.\");\n const envPath = root + \".env.example\";\n const env = (files[envPath] ?? \"\").replace(/^NEXT_PUBLIC_FRANKIE_KEY=.*\\n?/gm, \"\").replace(/^FRANKIE_JWT_SECRET=.*\\n?/gm, \"\").trimEnd();\n out.set(envPath, env + \"\\nNEXT_PUBLIC_FRANKIE_KEY=\" + workspace.publishableKey + \"\\n\" + (workspace.allowAnonymous ? \"\" : \"# Server only: use the secret from this workspace. Never commit its value.\\nFRANKIE_JWT_SECRET=\\n\"));\n out.set(root + \"FRANKIE_SETUP.md\", `# Frankie setup\\n\\nWorkspace: ${workspace.name}\\n\\n1. Add NEXT_PUBLIC_FRANKIE_KEY from .env.example to the frontend deployment.\\n${workspace.allowAnonymous ? \"\" : \"2. Add FRANKIE_JWT_SECRET from this workspace to the server hosting /api/frankie/token. Never commit the value.\\n\"}3. Run your package manager and commit the updated lockfile (for pnpm: pnpm install --lockfile-only). The remote GitHub installer cannot safely synthesize a lockfile.\\n4. Confirm https://YOUR_APP/frankie.openapi.json is public. If your Next.js middleware protects all paths, explicitly bypass /frankie.openapi.json before connecting it.\\n5. Open ${chatPath}. It is created inside the detected authenticated dashboard group when one exists; add its link to the host sidebar during review.\\n6. Connect https://YOUR_APP/frankie.openapi.json in Frankie → Tools & MCP. The generated document contains only read-only GET operations.\\n7. Forwarding sends the Frankie-signed JWT. Your API must validate it and enforce user/resource permissions. It is not automatically interchangeable with a Firebase or OAuth access token.\\n8. Add NEXT_PUBLIC_FRANKIE_KEY to every frontend deployment environment (Preview and Production). ${workspace.allowAnonymous ? \"\" : \"Add FRANKIE_JWT_SECRET only to the server environment running /api/frankie/token; never expose it to the browser.\\n\"}9. Review conversations in Workspace → Chat sessions.\\n\\n## Remaining setup\\n\\n${notes.map((n) => \"- \" + n).join(\"\\n\")}\\n`);\n return { files: [...out].map(([path, content]) => ({ path, content })), root, chatPath, specPath, operationCount, needsAuthSetup, notes };\n}\nfunction addInstallOperation(paths: Record<string, Record<string, unknown>>, method: string, path: string, file: string) {\n if (path.includes(\"*\") || !path.startsWith(\"/\")) return;\n (paths[path] ??= {})[method.toLowerCase()] = {\n operationId: (method.toLowerCase() + \"_\" + path).replace(/[^a-zA-Z0-9_]+/g, \"_\"),\n summary: method + \" \" + path, description: \"Detected in \" + file + \". Review schemas before enabling.\",\n parameters: [...path.matchAll(/\\{([^}]+)\\}/g)].map((m) => ({ name: m[1], in: \"path\", required: true, schema: { type: \"string\" } })),\n responses: { \"200\": { description: \"Successful response\" } }, \"x-frankie-review-required\": true,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,iBAAkB;AAQX,IAAM,oBAAoB,aAC9B,OAAO;AAAA,EACN,SAAS,aAAE,OAA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function truncate(value, max) {
263
263
  // src/install.ts
264
264
  function planHostedInstall(input) {
265
265
  const { files, workspace } = input;
266
- const layouts = Object.keys(files).filter((p) => /(?:^|\/)(?:src\/)?app\/layout\.tsx$/.test(p));
267
- const layoutPath = layouts.find((p) => /apps\/(dashboard|web)\//.test(p)) ?? layouts[0];
268
- if (!layoutPath) throw new Error("Automatic installation supports Next.js App Router. No app/layout.tsx was found.");
269
- const appRoot = layoutPath.slice(0, -"layout.tsx".length);
266
+ const layouts = Object.keys(files).filter((p) => /(?:^|\/)(?:src\/)?app(?:\/\([^/]+\))?\/layout\.tsx$/.test(p));
267
+ const rootLayoutPath = layouts.find((p) => !/(?:^|\/)app\/\([^/]+\)\/layout\.tsx$/.test(p)) ?? layouts[0];
268
+ if (!rootLayoutPath) throw new Error("Automatic installation supports Next.js App Router. No app/layout.tsx was found.");
269
+ const layoutPath = layouts.find((p) => /(?:^|\/)app\/\((?:dashboard|authenticated|protected|app)\)\/layout\.tsx$/.test(p)) ?? rootLayoutPath;
270
+ const appRoot = rootLayoutPath.slice(0, -"layout.tsx".length);
271
+ const integrationAppRoot = layoutPath.slice(0, -"layout.tsx".length);
270
272
  const root = appRoot.replace(/(?:src\/)?app\/$/, "");
271
273
  const pkgPath = root + "package.json";
272
274
  const pkg = JSON.parse(files[pkgPath] ?? "{}");
@@ -281,7 +283,7 @@ function planHostedInstall(input) {
281
283
  const tokenPath = appRoot + "api/frankie/token/route.ts";
282
284
  const needsAuthSetup = !workspace.allowAnonymous && !files[tokenPath] && !firebase && !authJs;
283
285
  if (needsAuthSetup) notes.push("Connect getCurrentUser in the generated token endpoint to your server session. It rejects requests until configured.");
284
- pkg.dependencies = { ...pkg.dependencies, "@frankieai/react": pkg.dependencies["@frankieai/react"] ?? "^0.1.4", ...!workspace.allowAnonymous ? { jose: pkg.dependencies.jose ?? "^6.0.11" } : {} };
286
+ pkg.dependencies = { ...pkg.dependencies, "@frankieai/react": pkg.dependencies["@frankieai/react"] ?? "^0.1.5", ...!workspace.allowAnonymous ? { jose: pkg.dependencies.jose ?? "^6.0.11" } : {} };
285
287
  out.set(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
286
288
  const authProp = workspace.allowAnonymous ? "" : " getUserToken={getUserToken}";
287
289
  const shared = `import { FrankieProvider, FrankieWidget, FrankieChatPage } from "@frankieai/react";
@@ -300,8 +302,8 @@ async function getUserToken() {
300
302
  if (previous.workspaceId === workspace.id && ["/chat", "/frankie/chat"].includes(previous.chatPath)) priorChat = previous.chatPath;
301
303
  } catch {
302
304
  }
303
- const chatPath = priorChat ?? (files[appRoot + "chat/page.tsx"] ? "/frankie/chat" : "/chat");
304
- if (!priorChat && files[appRoot + chatPath.slice(1) + "/page.tsx"]) throw new Error("Both /chat and /frankie/chat already exist. Choose a chat route manually.");
305
+ const chatPath = priorChat ?? (files[integrationAppRoot + "chat/page.tsx"] ? "/frankie/chat" : "/chat");
306
+ if (!priorChat && files[integrationAppRoot + chatPath.slice(1) + "/page.tsx"]) throw new Error("Both /chat and /frankie/chat already exist. Choose a chat route manually.");
305
307
  out.set(root + "frankie.install.json", JSON.stringify({ workspaceId: workspace.id, chatPath }, null, 2) + "\n");
306
308
  if (chatPath !== "/chat") notes.push("Existing /chat preserved. Frankie chat is available at /frankie/chat.");
307
309
  const mount = `"use client";
@@ -320,17 +322,24 @@ export function WorkspaceChatPage() {
320
322
  }
321
323
  `;
322
324
  const moduleName = existingMount ? "FrankieSetupChat" : "FrankieWidgetMount";
323
- out.set(appRoot + "frankie/" + moduleName + ".tsx", mount);
325
+ out.set(integrationAppRoot + "frankie/" + moduleName + ".tsx", mount);
324
326
  if (!existingMount) {
325
327
  const layout = files[layoutPath];
326
- if (!layout.includes("</body>")) throw new Error("The layout has no closing body. This custom layout needs manual widget placement.");
327
328
  const importLine = `import { FrankieWidgetMount } from "./frankie/FrankieWidgetMount";
328
329
  `;
329
330
  const withImport = /^["']use client["'];/.test(layout) ? layout.replace(/^(['"]use client['"];)/, "$1\n" + importLine) : importLine + layout;
330
- out.set(layoutPath, withImport.replace("</body>", " <FrankieWidgetMount />\n</body>"));
331
+ if (withImport.includes("</body>")) {
332
+ out.set(layoutPath, withImport.replace("</body>", " <FrankieWidgetMount />\n</body>"));
333
+ } else if (withImport.includes("</main>")) {
334
+ out.set(layoutPath, withImport.replace("</main>", " <FrankieWidgetMount />\n</main>"));
335
+ } else if (withImport.includes("{children}")) {
336
+ out.set(layoutPath, withImport.replace("{children}", "{children}<FrankieWidgetMount />"));
337
+ } else {
338
+ throw new Error("The selected layout has no safe widget mount point. Add FrankieWidgetMount manually.");
339
+ }
331
340
  }
332
341
  const pageImport = chatPath === "/chat" ? "../frankie/" : "../../frankie/";
333
- out.set(appRoot + chatPath.slice(1) + "/page.tsx", `import { WorkspaceChatPage } from "${pageImport}${moduleName}";
342
+ out.set(integrationAppRoot + chatPath.slice(1) + "/page.tsx", `import { WorkspaceChatPage } from "${pageImport}${moduleName}";
334
343
  export default WorkspaceChatPage;
335
344
  `);
336
345
  if (!workspace.allowAnonymous && !files[tokenPath]) {
@@ -388,7 +397,7 @@ export async function POST() {
388
397
  if (nextRoute) {
389
398
  const path = nextRoute[1].replace(/\/\([^/]+\)/g, "").replace(/\[([^\]]+)\]/g, "{$1}");
390
399
  if (path.includes("...") || /\/(?:auth|frankie)(?:\/|$)/.test(path)) continue;
391
- for (const method of ["GET", "POST", "PUT", "PATCH", "DELETE"]) {
400
+ for (const method of ["GET"]) {
392
401
  if (new RegExp("export\\s+(?:(?:async\\s+)?function\\s+" + method + "\\b|(?:const|let)\\s+" + method + "\\s*=)").test(content))
393
402
  addInstallOperation(paths, method, path, file);
394
403
  }
@@ -397,12 +406,14 @@ export async function POST() {
397
406
  addInstallOperation(paths, match[1].toUpperCase(), match[2].replace(/:([A-Za-z0-9_]+)/g, "{$1}"), file);
398
407
  }
399
408
  }
400
- doc ??= { openapi: "3.0.3", info: { title: workspace.name + " API", version: "1.0.0", description: "Generated route inventory. Review prefixes, schemas and authorization before enabling tools." }, servers: [{ url: input.apiBaseUrl ?? "/" }], paths };
409
+ doc ??= { openapi: "3.0.3", info: { title: workspace.name + " API", version: "1.0.0", description: "Read-only generated route inventory. Review schemas, authorization, and the deployed origin before enabling tools." }, paths };
401
410
  const specPath = root + "public/frankie.openapi.json";
402
411
  const operationCount = Object.values(doc.paths).reduce((n, item) => n + Object.keys(item).filter((m) => /^(get|post|put|patch|delete)$/.test(m)).length, 0);
403
412
  out.set(specPath, JSON.stringify(doc, null, 2) + "\n");
404
413
  if (!operationCount) notes.push("No supported API routes detected. The OpenAPI draft has no operations; add the real schema before connecting tools.");
405
- notes.push("Review generated schemas and route mount prefixes before enabling operations.");
414
+ notes.push("Generated OpenAPI is read-only (GET only). Add write operations only to a reviewed, user-authorized schema.");
415
+ notes.push("Verify the public spec URL is reachable without dashboard authentication before connecting it.");
416
+ notes.push("The token endpoint issues a signed user JWT, but your product API must validate it and enforce user/resource permissions before exposing tools.");
406
417
  const envPath = root + ".env.example";
407
418
  const env = (files[envPath] ?? "").replace(/^NEXT_PUBLIC_FRANKIE_KEY=.*\n?/gm, "").replace(/^FRANKIE_JWT_SECRET=.*\n?/gm, "").trimEnd();
408
419
  out.set(envPath, env + "\nNEXT_PUBLIC_FRANKIE_KEY=" + workspace.publishableKey + "\n" + (workspace.allowAnonymous ? "" : "# Server only: use the secret from this workspace. Never commit its value.\nFRANKIE_JWT_SECRET=\n"));
@@ -411,11 +422,12 @@ export async function POST() {
411
422
  Workspace: ${workspace.name}
412
423
 
413
424
  1. Add NEXT_PUBLIC_FRANKIE_KEY from .env.example to the frontend deployment.
414
- ${workspace.allowAnonymous ? "" : "2. Add FRANKIE_JWT_SECRET from this workspace to the server hosting /api/frankie/token. Never commit the value.\n"}3. Install dependencies, update the lockfile, review and deploy the PR.
415
- 4. Open ${chatPath}. The generated floating widget hides on this chat page.
416
- 5. Connect https://YOUR_APP/frankie.openapi.json in Frankie \u2192 Tools & MCP. Choose Direct OpenAPI or OpenAPI + hosted MCP and select allowed operations.
417
- 6. Forwarding sends the Frankie-signed JWT. Your API must verify it and enforce user/resource permissions. It is not automatically interchangeable with a Firebase or OAuth access token.
418
- 7. Review conversations in Workspace \u2192 Chat sessions.
425
+ ${workspace.allowAnonymous ? "" : "2. Add FRANKIE_JWT_SECRET from this workspace to the server hosting /api/frankie/token. Never commit the value.\n"}3. Run your package manager and commit the updated lockfile (for pnpm: pnpm install --lockfile-only). The remote GitHub installer cannot safely synthesize a lockfile.
426
+ 4. Confirm https://YOUR_APP/frankie.openapi.json is public. If your Next.js middleware protects all paths, explicitly bypass /frankie.openapi.json before connecting it.
427
+ 5. Open ${chatPath}. It is created inside the detected authenticated dashboard group when one exists; add its link to the host sidebar during review.
428
+ 6. Connect https://YOUR_APP/frankie.openapi.json in Frankie \u2192 Tools & MCP. The generated document contains only read-only GET operations.
429
+ 7. Forwarding sends the Frankie-signed JWT. Your API must validate it and enforce user/resource permissions. It is not automatically interchangeable with a Firebase or OAuth access token.
430
+ 8. Add NEXT_PUBLIC_FRANKIE_KEY to every frontend deployment environment (Preview and Production). ${workspace.allowAnonymous ? "" : "Add FRANKIE_JWT_SECRET only to the server environment running /api/frankie/token; never expose it to the browser.\n"}9. Review conversations in Workspace \u2192 Chat sessions.
419
431
 
420
432
  ## Remaining setup
421
433
 
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/config.ts","../src/tools.ts","../src/install.ts"],"sourcesContent":["import { z } from \"zod\";\n\n/**\n * Tenant configuration. One config == one embedded agent. Everything a\n * customer needs to change to make Frankie theirs lives here, so the code\n * itself stays generic.\n */\n\nexport const widgetThemeSchema = z\n .object({\n primary: z.string().optional(),\n primaryForeground: z.string().optional(),\n background: z.string().optional(),\n foreground: z.string().optional(),\n muted: z.string().optional(),\n border: z.string().optional(),\n radius: z.string().optional(),\n fontFamily: z.string().optional(),\n mode: z.enum([\"light\", \"dark\", \"system\"]).default(\"system\"),\n })\n .prefault({});\n\nexport const thinkingLevelSchema = z.enum([\"minimal\", \"low\", \"medium\", \"high\", \"xhigh\", \"max\"]);\n\nexport const modelConfigSchema = z.object({\n /**\n * Any provider the model layer knows about. `fireworks` is the default;\n * `anthropic`, `openai`, `google`, `groq`, `together`, `openrouter` and\n * ~30 others resolve too, which is what makes the model a config choice.\n */\n provider: z.string().min(1).default(\"fireworks\"),\n /**\n * Model id within that provider. The default is Kimi K2.7 on Fireworks,\n * which serves a native Anthropic-Messages endpoint and a 262K window.\n */\n model: z.string().default(\"accounts/fireworks/models/kimi-k2p7-code\"),\n /** Env var holding the provider key. Never put the key in config itself. */\n apiKeyEnv: z.string().default(\"FIREWORKS_API_KEY\"),\n /** Override the provider's base URL (self-hosted gateways, tests). */\n baseUrl: z.string().url().optional(),\n maxTokens: z.number().int().positive().max(200_000).default(8192),\n temperature: z.number().min(0).max(2).default(0.6),\n /**\n * Reasoning depth. Lowest by default: an onboarding widget is latency-\n * sensitive and its questions rarely need deliberation.\n */\n thinkingLevel: thinkingLevelSchema.default(\"minimal\"),\n /** Forward the model's reasoning stream to the client as thinking deltas. */\n streamReasoning: z.boolean().default(false),\n});\n\n/** One selectable model in the (optional) end-user model picker. */\nexport const modelChoiceSchema = z.object({\n /** Provider model id, e.g. \"accounts/fireworks/models/kimi-k2p7-code\". */\n id: z.string().min(1),\n /** Shown in the picker, e.g. \"Fast\" or \"Smart\". */\n label: z.string().min(1),\n /** Defaults to the workspace's default provider when omitted. */\n provider: z.string().optional(),\n});\n\n/**\n * Optional, opt-in chat capabilities the SDK consumer turns on per workspace.\n * Everything here is OFF by default: an embedded agent only gets a wider surface\n * when the customer deliberately enables it.\n */\nexport const featuresConfigSchema = z\n .object({\n /** Let end users attach files. Images go to a vision model; docs are read as text. */\n attachments: z\n .object({\n enabled: z.boolean().default(false),\n /** Accepted MIME patterns, e.g. \"image/*\", \"text/*\", \"application/json\". */\n accept: z.array(z.string()).default([\"image/*\", \"text/*\", \"application/json\"]),\n maxMb: z.number().positive().max(25).default(10),\n maxCount: z.number().int().positive().max(10).default(4),\n })\n .prefault({}),\n /** Let end users choose the model, from a curated list you control. */\n modelPicker: z\n .object({\n enabled: z.boolean().default(false),\n /** The models offered to end users. The workspace default is always allowed. */\n models: z.array(modelChoiceSchema).default([]),\n })\n .prefault({}),\n /**\n * Platform onboarding: give the agent built-in tools to create and list the\n * signed-in user's own Frankie workspaces. Only for a workspace that *is* the\n * Frankie onboarding assistant — a normal customer never turns this on.\n */\n workspaceAdmin: z.boolean().default(false),\n })\n .prefault({});\n\nexport const mcpServerSchema = z.object({\n name: z\n .string()\n .min(1)\n .regex(/^[a-z0-9][a-z0-9_-]*$/i, \"MCP server names must be alphanumeric with - or _\"),\n enabled: z.boolean().default(true),\n /** Explicit tool selection. Omitted keeps legacy all-tools behavior; [] disables all. */\n selectedTools: z.array(z.string().min(1)).optional(),\n discoveredTools: z.array(z.object({ name: z.string(), description: z.string().optional() })).default([]),\n /** `http` covers streamable HTTP; `sse` is the legacy transport. */\n transport: z.enum([\"http\", \"sse\"]).default(\"http\"),\n url: z.string().url(),\n /** Static headers, e.g. a service token for the company's own MCP server. */\n headers: z.record(z.string(), z.string()).default({}),\n /**\n * When set, the verified end-user JWT is forwarded to the MCP server in this\n * header so the company's tools can act as that user. Use with care: only\n * enable it for MCP servers you control.\n */\n forwardUserTokenAs: z.string().optional(),\n /** Extra claims from the user token to forward as `x-frankie-<claim>`. */\n forwardUserClaims: z.array(z.string()).default([]),\n});\n\n/**\n * An HTTP API described by an OpenAPI document, turned into tools directly.\n *\n * This is the \"no MCP server to write\" path: point Frankie at a spec, name the\n * operations the agent may use, and it builds the tools at startup.\n */\nexport const apiCapabilitySchema = z.object({\n operationId: z.string().min(1),\n method: z.enum([\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\"]),\n path: z.string().min(1),\n summary: z.string().optional(),\n});\n\nexport const apiSourceSchema = z.object({\n name: z\n .string()\n .min(1)\n .regex(/^[a-z0-9][a-z0-9_-]*$/i, \"API source names must be alphanumeric with - or _\"),\n /** URL or local path to an OpenAPI 3.x document (JSON or YAML). */\n spec: z.string().min(1),\n /** Overrides the spec's own `servers[0].url`. Required if the spec has none. */\n baseUrl: z.string().url().optional(),\n /**\n * Operation ids the agent may call. Empty means \"every operation that passes\n * the other filters\" — fine for a small internal API, risky for a large one.\n */\n operations: z.array(z.string()).default([]),\n /**\n * Path globs to include, e.g. `/projects/**`. Empty means all paths.\n */\n includePaths: z.array(z.string()).default([]),\n /**\n * HTTP methods the agent may use. Read-only by default: an onboarding agent\n * wired to a whole API should not be able to DELETE on its first day. Widen\n * deliberately, per API.\n */\n methods: z.array(z.enum([\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\"])).default([\"GET\"]),\n enabled: z.boolean().default(true),\n /** Explicit operation selection, independent of the discovered inventory. */\n selectedTools: z.array(z.string().min(1)).optional(),\n /** Whether these approved API tools are also served by the workspace MCP. */\n exposeAsMcp: z.boolean().default(true),\n /** A read-only inventory derived from the source for the dashboard. */\n capabilities: z.array(apiCapabilitySchema).default([]),\n /** Static headers, e.g. a service token. */\n headers: z.record(z.string(), z.string()).default({}),\n /**\n * When set, the verified end-user JWT is forwarded in this header, so your\n * API authorises the call exactly as it would any other request from them.\n */\n forwardUserTokenAs: z.string().optional(),\n /** Extra claims from the user token to forward as `x-frankie-<claim>`. */\n forwardUserClaims: z.array(z.string()).default([]),\n /** Per-call timeout. */\n timeoutMs: z.number().int().positive().default(30_000),\n /** Response bodies longer than this are truncated before the model sees them. */\n maxResponseChars: z.number().int().positive().default(8_000),\n});\n\nexport const toolPolicySchema = z.object({\n /**\n * Tool names the agent may call without asking. MCP tools are named\n * `mcp__<server>__<tool>` and generated API tools `api__<name>__<operation>`;\n * naming the prefix alone (`mcp__acme`, `api__acme`) allows all of them.\n */\n allow: z.array(z.string()).default([]),\n /** Explicit denials; evaluated before `allow`. */\n deny: z.array(z.string()).default([]),\n /**\n * Deny anything not in `allow`. On by default — an onboarding agent living\n * on a public marketing page should not have an open tool surface.\n */\n denyByDefault: z.boolean().default(true),\n});\n\nexport const agentConfigSchema = z.object({\n /** Prepended to the runtime's own operating instructions. */\n systemPrompt: z.string().default(\"\"),\n /** First message the widget shows before the user types anything. */\n greeting: z.string().default(\"Hi! I can walk you through getting set up. What are you trying to do?\"),\n suggestedPrompts: z.array(z.string()).max(6).default([]),\n maxTurns: z.number().int().positive().max(50).default(12),\n /** Hard stop on estimated spend per session. */\n maxBudgetUsd: z.number().positive().optional(),\n tools: toolPolicySchema.prefault({}),\n /** Show tool activity in the transcript. */\n showToolActivity: z.boolean().default(true),\n});\n\nexport const authConfigSchema = z.object({\n /**\n * Safe to ship in client bundles. Identifies the tenant; it authorises\n * nothing on its own — the origin allowlist and the user token do that.\n */\n publishableKey: z.string().min(8),\n /** Exact origins allowed to open sessions, e.g. `https://app.acme.com`. */\n allowedOrigins: z.array(z.string()).default([]),\n /** Let visitors chat without a host-signed token (marketing pages). */\n allowAnonymous: z.boolean().default(false),\n /** Env var holding the HS256 secret the host signs user tokens with. */\n jwtSecretEnv: z.string().default(\"FRANKIE_JWT_SECRET\"),\n /** Verify against a JWKS endpoint instead of a shared secret (RS/ES256). */\n jwksUrl: z.string().url().optional(),\n jwtIssuer: z.string().optional(),\n jwtAudience: z.string().optional(),\n /** How long an issued session token is good for. */\n sessionTtlSeconds: z.number().int().positive().default(60 * 60),\n /** Env var holding the secret used to sign Frankie's own session tokens. */\n sessionSecretEnv: z.string().default(\"FRANKIE_SESSION_SECRET\"),\n});\n\nexport const limitsConfigSchema = z.object({\n /** Messages per session per window. */\n messagesPerWindow: z.number().int().positive().default(30),\n windowSeconds: z.number().int().positive().default(15 * 60),\n /** Sessions a single IP may open per window. */\n sessionsPerIpPerWindow: z.number().int().positive().default(20),\n /** Longest a single turn may run before it is aborted. */\n turnTimeoutMs: z.number().int().positive().default(120_000),\n});\n\nexport const brandingConfigSchema = z.object({\n name: z.string().default(\"Assistant\"),\n tagline: z.string().optional(),\n avatarUrl: z.string().url().optional(),\n launcherLabel: z.string().default(\"Need a hand?\"),\n});\n\nexport const frankieConfigSchema = z.object({\n tenantId: z.string().min(1),\n branding: brandingConfigSchema.prefault({}),\n theme: widgetThemeSchema,\n model: modelConfigSchema.prefault({}),\n agent: agentConfigSchema.prefault({}),\n auth: authConfigSchema,\n mcpServers: z.array(mcpServerSchema).default([]),\n /** APIs turned into tools from their OpenAPI document. */\n apis: z.array(apiSourceSchema).default([]),\n limits: limitsConfigSchema.prefault({}),\n /** Opt-in end-user chat capabilities (attachments, model picker). */\n features: featuresConfigSchema,\n});\n\nexport type ThinkingLevel = z.infer<typeof thinkingLevelSchema>;\nexport type WidgetThemeConfig = z.infer<typeof widgetThemeSchema>;\nexport type ModelChoice = z.infer<typeof modelChoiceSchema>;\nexport type FeaturesConfig = z.infer<typeof featuresConfigSchema>;\nexport type ModelConfig = z.infer<typeof modelConfigSchema>;\nexport type McpServerConfig = z.infer<typeof mcpServerSchema>;\nexport type ApiCapability = z.infer<typeof apiCapabilitySchema>;\nexport type ApiSourceConfig = z.infer<typeof apiSourceSchema>;\nexport type ToolPolicy = z.infer<typeof toolPolicySchema>;\nexport type AgentConfig = z.infer<typeof agentConfigSchema>;\nexport type AuthConfig = z.infer<typeof authConfigSchema>;\nexport type LimitsConfig = z.infer<typeof limitsConfigSchema>;\nexport type BrandingConfig = z.infer<typeof brandingConfigSchema>;\nexport type FrankieConfig = z.infer<typeof frankieConfigSchema>;\nexport type FrankieConfigInput = z.input<typeof frankieConfigSchema>;\n\nexport function parseFrankieConfig(input: unknown): FrankieConfig {\n return frankieConfigSchema.parse(input);\n}\n\n/** Helper for `frankie.config.ts` files — gives editors full completion. */\nexport function defineFrankieConfig(config: FrankieConfigInput): FrankieConfigInput {\n return config;\n}\n","import type { ToolPolicy } from \"./config.js\";\n\nexport interface ToolDecision {\n allowed: boolean;\n reason: string;\n}\n\n/**\n * Decide whether the agent may run a tool.\n *\n * Patterns are matched exactly, or as a prefix when they end in `*`. MCP tools\n * arrive as `mcp__<server>__<tool>`, so listing `mcp__acme` (no trailing star)\n * also allows every tool on the `acme` server.\n */\nexport function evaluateToolPolicy(toolName: string, policy: ToolPolicy): ToolDecision {\n if (matchesAny(toolName, policy.deny)) {\n return { allowed: false, reason: `\"${toolName}\" is on the deny list for this agent.` };\n }\n if (matchesAny(toolName, policy.allow)) {\n return { allowed: true, reason: \"allowed by policy\" };\n }\n if (policy.denyByDefault) {\n return { allowed: false, reason: `\"${toolName}\" is not in this agent's allow list.` };\n }\n return { allowed: true, reason: \"no policy match; default allow\" };\n}\n\nfunction matchesAny(toolName: string, patterns: readonly string[]): boolean {\n return patterns.some((pattern) => matches(toolName, pattern));\n}\n\nfunction matches(toolName: string, pattern: string): boolean {\n if (pattern === \"*\") return true;\n if (pattern.endsWith(\"*\")) return toolName.startsWith(pattern.slice(0, -1));\n if (toolName === pattern) return true;\n // `mcp__acme` covers `mcp__acme__create_workspace`.\n return toolName.startsWith(`${pattern}__`);\n}\n\n/** A short human label for a tool call, for the \"Frankie is …\" line in the UI. */\nexport function describeTool(toolName: string, input: unknown): string {\n const mcp = /^mcp__([^_]+(?:_[^_]+)*)__(.+)$/.exec(toolName);\n if (mcp) {\n const [, server, tool] = mcp;\n return `${humanise(tool ?? toolName)} · ${server}`;\n }\n const inputRecord = typeof input === \"object\" && input !== null ? (input as Record<string, unknown>) : {};\n const hint = inputRecord[\"path\"] ?? inputRecord[\"url\"] ?? inputRecord[\"query\"] ?? inputRecord[\"command\"];\n return typeof hint === \"string\" ? `${humanise(toolName)}: ${truncate(hint, 60)}` : humanise(toolName);\n}\n\nfunction humanise(name: string): string {\n return name\n .replace(/[_-]+/g, \" \")\n .replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n .replace(/\\b\\w/g, (c) => c.toUpperCase())\n .trim();\n}\n\nfunction truncate(value: string, max: number): string {\n return value.length <= max ? value : `${value.slice(0, max - 1)}…`;\n}\n","/** One installation plan for GitHub and the local CLI. Never includes credentials. */\nexport interface InstallProject {\n files: Record<string, string>;\n workspace: { id: string; name: string; publishableKey: string; allowAnonymous: boolean };\n apiBaseUrl?: string;\n}\nexport interface InstallPlan {\n files: Array<{ path: string; content: string }>; root: string; chatPath: string; specPath: string;\n operationCount: number; needsAuthSetup: boolean; notes: string[];\n}\ntype ApiDocument = { paths: Record<string, Record<string, unknown>>; [key: string]: unknown };\nexport function planHostedInstall(input: InstallProject): InstallPlan {\n const { files, workspace } = input;\n const layouts = Object.keys(files).filter((p) => /(?:^|\\/)(?:src\\/)?app\\/layout\\.tsx$/.test(p));\n const layoutPath = layouts.find((p) => /apps\\/(dashboard|web)\\//.test(p)) ?? layouts[0];\n if (!layoutPath) throw new Error(\"Automatic installation supports Next.js App Router. No app/layout.tsx was found.\");\n const appRoot = layoutPath.slice(0, -\"layout.tsx\".length);\n const root = appRoot.replace(/(?:src\\/)?app\\/$/, \"\");\n const pkgPath = root + \"package.json\";\n const pkg = JSON.parse(files[pkgPath] ?? \"{}\");\n if (!pkg.dependencies?.next) throw new Error(\"The selected app must have Next.js in dependencies.\");\n const out = new Map<string, string>();\n const notes: string[] = [];\n const existingMount = files[layoutPath]!.includes(\"FrankieWidgetMount\");\n const sourceRoot = appRoot.endsWith(\"src/app/\") ? root + \"src/\" : root;\n const firebase = Boolean(files[sourceRoot + \"lib/firebase-admin.ts\"]?.includes(\"getAdminAuth\") && files[sourceRoot + \"lib/session.ts\"]?.includes(\"SESSION_COOKIE\"));\n const authFile = files[sourceRoot + \"auth.ts\"];\n const authJs = Boolean(authFile?.includes(\"NextAuth\") && /export\\s+(?:const|let)\\s*\\{[^}]*\\bauth\\b/.test(authFile ?? \"\"));\n const tokenPath = appRoot + \"api/frankie/token/route.ts\";\n const needsAuthSetup = !workspace.allowAnonymous && !files[tokenPath] && !firebase && !authJs;\n if (needsAuthSetup) notes.push(\"Connect getCurrentUser in the generated token endpoint to your server session. It rejects requests until configured.\");\n pkg.dependencies = { ...pkg.dependencies, \"@frankieai/react\": pkg.dependencies[\"@frankieai/react\"] ?? \"^0.1.4\", ...(!workspace.allowAnonymous ? { jose: pkg.dependencies.jose ?? \"^6.0.11\" } : {}) };\n out.set(pkgPath, JSON.stringify(pkg, null, 2) + \"\\n\");\n const authProp = workspace.allowAnonymous ? \"\" : \" getUserToken={getUserToken}\";\n const shared = `import { FrankieProvider, FrankieWidget, FrankieChatPage } from \"@frankieai/react\";\\nimport \"@frankieai/react/styles.css\";\\n`;\n const getToken = workspace.allowAnonymous ? \"\" : `\nasync function getUserToken() {\n const response = await fetch(\"/api/frankie/token\", { method: \"POST\", credentials: \"same-origin\" });\n if (!response.ok) return undefined;\n return ((await response.json()) as { token?: string }).token;\n}\n`;\n let priorChat: string | undefined;\n try { const previous = JSON.parse(files[root + \"frankie.install.json\"] ?? \"{}\"); if (previous.workspaceId === workspace.id && [\"/chat\", \"/frankie/chat\"].includes(previous.chatPath)) priorChat = previous.chatPath; } catch {}\n const chatPath = priorChat ?? (files[appRoot + \"chat/page.tsx\"] ? \"/frankie/chat\" : \"/chat\");\n if (!priorChat && files[appRoot + chatPath.slice(1) + \"/page.tsx\"]) throw new Error(\"Both /chat and /frankie/chat already exist. Choose a chat route manually.\");\n out.set(root + \"frankie.install.json\", JSON.stringify({ workspaceId: workspace.id, chatPath }, null, 2) + \"\\n\");\n if (chatPath !== \"/chat\") notes.push(\"Existing /chat preserved. Frankie chat is available at /frankie/chat.\");\n const mount = `\"use client\";\\nimport { usePathname } from \"next/navigation\";\\n${shared}${getToken}\nexport function FrankieWidgetMount() {\n const pathname = usePathname();\n const key = process.env.NEXT_PUBLIC_FRANKIE_KEY;\n if (!key || pathname === ${JSON.stringify(chatPath)}) return null;\n return <FrankieProvider publishableKey={key}${authProp}><FrankieWidget /></FrankieProvider>;\n}\nexport function WorkspaceChatPage() {\n const key = process.env.NEXT_PUBLIC_FRANKIE_KEY;\n if (!key) return <p>Chat is not configured. Set NEXT_PUBLIC_FRANKIE_KEY in your deployment.</p>;\n return <FrankieChatPage publishableKey={key}${authProp} />;\n}\n`;\n const moduleName = existingMount ? \"FrankieSetupChat\" : \"FrankieWidgetMount\";\n out.set(appRoot + \"frankie/\" + moduleName + \".tsx\", mount);\n if (!existingMount) {\n const layout = files[layoutPath]!;\n if (!layout.includes(\"</body>\")) throw new Error(\"The layout has no closing body. This custom layout needs manual widget placement.\");\n const importLine = `import { FrankieWidgetMount } from \"./frankie/FrankieWidgetMount\";\\n`;\n const withImport = /^[\"']use client[\"'];/.test(layout) ? layout.replace(/^(['\"]use client['\"];)/, \"$1\\n\" + importLine) : importLine + layout;\n out.set(layoutPath, withImport.replace(\"</body>\", \" <FrankieWidgetMount />\\n</body>\"));\n }\n const pageImport = chatPath === \"/chat\" ? \"../frankie/\" : \"../../frankie/\";\n out.set(appRoot + chatPath.slice(1) + \"/page.tsx\", `import { WorkspaceChatPage } from \"${pageImport}${moduleName}\";\\nexport default WorkspaceChatPage;\\n`);\n if (!workspace.allowAnonymous && !files[tokenPath]) {\n const lookup = firebase\n ? `import { cookies } from \"next/headers\";\\nimport { getAdminAuth } from \"@/lib/firebase-admin\";\\nimport { SESSION_COOKIE } from \"@/lib/session\";\\nasync function getCurrentUser() {\\n const cookie = (await cookies()).get(SESSION_COOKIE)?.value;\\n if (!cookie) return null;\\n const user = await getAdminAuth().verifySessionCookie(cookie, true);\\n return { id: user.uid, name: user.name, email: user.email };\\n}\\n`\n : authJs ? `import { auth } from \"@/auth\";\\nasync function getCurrentUser() {\\n const session = await auth();\\n const user = session?.user as { id?: string; name?: string | null; email?: string | null } | undefined;\\n return user?.id ? user : null;\\n}\\n`\n : `// Replace with your app's verified server session lookup.\\nasync function getCurrentUser(): Promise<{ id: string; name?: string; email?: string } | null> { return null; }\\n`;\n out.set(tokenPath, `import { SignJWT } from \"jose\";\\nimport { NextResponse } from \"next/server\";\\n${lookup}\nexport async function POST() {\n const secret = process.env.FRANKIE_JWT_SECRET;\n if (!secret) return NextResponse.json({ error: \"Chat secret not configured\" }, { status: 503 });\n try {\n const user = await getCurrentUser();\n if (!user?.id) return NextResponse.json({ error: \"Sign in required\" }, { status: 401 });\n const token = await new SignJWT({ name: user.name, email: user.email })\n .setProtectedHeader({ alg: \"HS256\" }).setSubject(user.id).setIssuedAt()\n .setExpirationTime(\"5m\").sign(new TextEncoder().encode(secret));\n return NextResponse.json({ token }, { headers: { \"Cache-Control\": \"no-store\" } });\n } catch { return NextResponse.json({ error: \"Sign in required\" }, { status: 401 }); }\n}\n`);\n }\n let doc: ApiDocument | undefined;\n for (const [path, content] of Object.entries(files)) {\n if (!/(?:openapi|swagger)[^/]*\\.json$/i.test(path)) continue;\n try { const parsed = JSON.parse(content); if (parsed.openapi && parsed.paths) { doc = parsed; break; } } catch {}\n }\n const paths: Record<string, Record<string, unknown>> = {};\n if (!doc) for (const [file, content] of Object.entries(files)) {\n if (/\\.(test|spec)\\.[tj]sx?$/.test(file)) continue;\n const nextRoute = file.match(/(?:^|\\/)app(\\/.*)\\/route\\.[tj]s$/);\n if (nextRoute) {\n const path = nextRoute[1]!.replace(/\\/\\([^/]+\\)/g, \"\").replace(/\\[([^\\]]+)\\]/g, \"{$1}\");\n if (path.includes(\"...\") || /\\/(?:auth|frankie)(?:\\/|$)/.test(path)) continue;\n for (const method of [\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\"]) {\n if (new RegExp(\"export\\\\s+(?:(?:async\\\\s+)?function\\\\s+\" + method + \"\\\\b|(?:const|let)\\\\s+\" + method + \"\\\\s*=)\").test(content))\n addInstallOperation(paths, method, path, file);\n }\n } else if (/\\.[tj]s$/.test(file) && /(?:routes?|api)\\//.test(file)) {\n for (const match of content.matchAll(/\\b(?:app|router|fastify)\\.(get|post|put|patch|delete)(?:\\s*<[^;]{1,1600}?>)?\\s*\\(\\s*[\"']([^\"']+)[\"']/g))\n addInstallOperation(paths, match[1]!.toUpperCase(), match[2]!.replace(/:([A-Za-z0-9_]+)/g, \"{$1}\"), file);\n }\n }\n doc ??= { openapi: \"3.0.3\", info: { title: workspace.name + \" API\", version: \"1.0.0\", description: \"Generated route inventory. Review prefixes, schemas and authorization before enabling tools.\" }, servers: [{ url: input.apiBaseUrl ?? \"/\" }], paths };\n const specPath = root + \"public/frankie.openapi.json\";\n const operationCount = Object.values(doc.paths).reduce((n, item) => n + Object.keys(item).filter((m) => /^(get|post|put|patch|delete)$/.test(m)).length, 0);\n out.set(specPath, JSON.stringify(doc, null, 2) + \"\\n\");\n if (!operationCount) notes.push(\"No supported API routes detected. The OpenAPI draft has no operations; add the real schema before connecting tools.\");\n notes.push(\"Review generated schemas and route mount prefixes before enabling operations.\");\n const envPath = root + \".env.example\";\n const env = (files[envPath] ?? \"\").replace(/^NEXT_PUBLIC_FRANKIE_KEY=.*\\n?/gm, \"\").replace(/^FRANKIE_JWT_SECRET=.*\\n?/gm, \"\").trimEnd();\n out.set(envPath, env + \"\\nNEXT_PUBLIC_FRANKIE_KEY=\" + workspace.publishableKey + \"\\n\" + (workspace.allowAnonymous ? \"\" : \"# Server only: use the secret from this workspace. Never commit its value.\\nFRANKIE_JWT_SECRET=\\n\"));\n out.set(root + \"FRANKIE_SETUP.md\", `# Frankie setup\\n\\nWorkspace: ${workspace.name}\\n\\n1. Add NEXT_PUBLIC_FRANKIE_KEY from .env.example to the frontend deployment.\\n${workspace.allowAnonymous ? \"\" : \"2. Add FRANKIE_JWT_SECRET from this workspace to the server hosting /api/frankie/token. Never commit the value.\\n\"}3. Install dependencies, update the lockfile, review and deploy the PR.\\n4. Open ${chatPath}. The generated floating widget hides on this chat page.\\n5. Connect https://YOUR_APP/frankie.openapi.json in Frankie → Tools & MCP. Choose Direct OpenAPI or OpenAPI + hosted MCP and select allowed operations.\\n6. Forwarding sends the Frankie-signed JWT. Your API must verify it and enforce user/resource permissions. It is not automatically interchangeable with a Firebase or OAuth access token.\\n7. Review conversations in Workspace → Chat sessions.\\n\\n## Remaining setup\\n\\n${notes.map((n) => \"- \" + n).join(\"\\n\")}\\n`);\n return { files: [...out].map(([path, content]) => ({ path, content })), root, chatPath, specPath, operationCount, needsAuthSetup, notes };\n}\nfunction addInstallOperation(paths: Record<string, Record<string, unknown>>, method: string, path: string, file: string) {\n if (path.includes(\"*\") || !path.startsWith(\"/\")) return;\n (paths[path] ??= {})[method.toLowerCase()] = {\n operationId: (method.toLowerCase() + \"_\" + path).replace(/[^a-zA-Z0-9_]+/g, \"_\"),\n summary: method + \" \" + path, description: \"Detected in \" + file + \". Review schemas before enabling.\",\n parameters: [...path.matchAll(/\\{([^}]+)\\}/g)].map((m) => ({ name: m[1], in: \"path\", required: true, schema: { type: \"string\" } })),\n responses: { \"200\": { description: \"Successful response\" } }, \"x-frankie-review-required\": true,\n };\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAQX,IAAM,oBAAoB,EAC9B,OAAO;AAAA,EACN,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,mBAAmB,EAAE,OAAO,EAAE,SAAS;AAAA,EACvC,YAAY,EAAE,OAAO,EAAE,SAAS;AAAA,EAChC,YAAY,EAAE,OAAO,EAAE,SAAS;AAAA,EAChC,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,QAAQ,EAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,QAAQ,EAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,YAAY,EAAE,OAAO,EAAE,SAAS;AAAA,EAChC,MAAM,EAAE,KAAK,CAAC,SAAS,QAAQ,QAAQ,CAAC,EAAE,QAAQ,QAAQ;AAC5D,CAAC,EACA,SAAS,CAAC,CAAC;AAEP,IAAM,sBAAsB,EAAE,KAAK,CAAC,WAAW,OAAO,UAAU,QAAQ,SAAS,KAAK,CAAC;AAEvF,IAAM,oBAAoB,EAAE,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMxC,UAAU,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,QAAQ,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA,EAK/C,OAAO,EAAE,OAAO,EAAE,QAAQ,0CAA0C;AAAA;AAAA,EAEpE,WAAW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AG,6BAA6B;AAAA,EAC7F;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/config.ts","../src/tools.ts","../src/install.ts"],"sourcesContent":["import { z } from \"zod\";\n\n/**\n * Tenant configuration. One config == one embedded agent. Everything a\n * customer needs to change to make Frankie theirs lives here, so the code\n * itself stays generic.\n */\n\nexport const widgetThemeSchema = z\n .object({\n primary: z.string().optional(),\n primaryForeground: z.string().optional(),\n background: z.string().optional(),\n foreground: z.string().optional(),\n muted: z.string().optional(),\n border: z.string().optional(),\n radius: z.string().optional(),\n fontFamily: z.string().optional(),\n mode: z.enum([\"light\", \"dark\", \"system\"]).default(\"system\"),\n })\n .prefault({});\n\nexport const thinkingLevelSchema = z.enum([\"minimal\", \"low\", \"medium\", \"high\", \"xhigh\", \"max\"]);\n\nexport const modelConfigSchema = z.object({\n /**\n * Any provider the model layer knows about. `fireworks` is the default;\n * `anthropic`, `openai`, `google`, `groq`, `together`, `openrouter` and\n * ~30 others resolve too, which is what makes the model a config choice.\n */\n provider: z.string().min(1).default(\"fireworks\"),\n /**\n * Model id within that provider. The default is Kimi K2.7 on Fireworks,\n * which serves a native Anthropic-Messages endpoint and a 262K window.\n */\n model: z.string().default(\"accounts/fireworks/models/kimi-k2p7-code\"),\n /** Env var holding the provider key. Never put the key in config itself. */\n apiKeyEnv: z.string().default(\"FIREWORKS_API_KEY\"),\n /** Override the provider's base URL (self-hosted gateways, tests). */\n baseUrl: z.string().url().optional(),\n maxTokens: z.number().int().positive().max(200_000).default(8192),\n temperature: z.number().min(0).max(2).default(0.6),\n /**\n * Reasoning depth. Lowest by default: an onboarding widget is latency-\n * sensitive and its questions rarely need deliberation.\n */\n thinkingLevel: thinkingLevelSchema.default(\"minimal\"),\n /** Forward the model's reasoning stream to the client as thinking deltas. */\n streamReasoning: z.boolean().default(false),\n});\n\n/** One selectable model in the (optional) end-user model picker. */\nexport const modelChoiceSchema = z.object({\n /** Provider model id, e.g. \"accounts/fireworks/models/kimi-k2p7-code\". */\n id: z.string().min(1),\n /** Shown in the picker, e.g. \"Fast\" or \"Smart\". */\n label: z.string().min(1),\n /** Defaults to the workspace's default provider when omitted. */\n provider: z.string().optional(),\n});\n\n/**\n * Optional, opt-in chat capabilities the SDK consumer turns on per workspace.\n * Everything here is OFF by default: an embedded agent only gets a wider surface\n * when the customer deliberately enables it.\n */\nexport const featuresConfigSchema = z\n .object({\n /** Let end users attach files. Images go to a vision model; docs are read as text. */\n attachments: z\n .object({\n enabled: z.boolean().default(false),\n /** Accepted MIME patterns, e.g. \"image/*\", \"text/*\", \"application/json\". */\n accept: z.array(z.string()).default([\"image/*\", \"text/*\", \"application/json\"]),\n maxMb: z.number().positive().max(25).default(10),\n maxCount: z.number().int().positive().max(10).default(4),\n })\n .prefault({}),\n /** Let end users choose the model, from a curated list you control. */\n modelPicker: z\n .object({\n enabled: z.boolean().default(false),\n /** The models offered to end users. The workspace default is always allowed. */\n models: z.array(modelChoiceSchema).default([]),\n })\n .prefault({}),\n /**\n * Platform onboarding: give the agent built-in tools to create and list the\n * signed-in user's own Frankie workspaces. Only for a workspace that *is* the\n * Frankie onboarding assistant — a normal customer never turns this on.\n */\n workspaceAdmin: z.boolean().default(false),\n })\n .prefault({});\n\nexport const mcpServerSchema = z.object({\n name: z\n .string()\n .min(1)\n .regex(/^[a-z0-9][a-z0-9_-]*$/i, \"MCP server names must be alphanumeric with - or _\"),\n enabled: z.boolean().default(true),\n /** Explicit tool selection. Omitted keeps legacy all-tools behavior; [] disables all. */\n selectedTools: z.array(z.string().min(1)).optional(),\n discoveredTools: z.array(z.object({ name: z.string(), description: z.string().optional() })).default([]),\n /** `http` covers streamable HTTP; `sse` is the legacy transport. */\n transport: z.enum([\"http\", \"sse\"]).default(\"http\"),\n url: z.string().url(),\n /** Static headers, e.g. a service token for the company's own MCP server. */\n headers: z.record(z.string(), z.string()).default({}),\n /**\n * When set, the verified end-user JWT is forwarded to the MCP server in this\n * header so the company's tools can act as that user. Use with care: only\n * enable it for MCP servers you control.\n */\n forwardUserTokenAs: z.string().optional(),\n /** Extra claims from the user token to forward as `x-frankie-<claim>`. */\n forwardUserClaims: z.array(z.string()).default([]),\n});\n\n/**\n * An HTTP API described by an OpenAPI document, turned into tools directly.\n *\n * This is the \"no MCP server to write\" path: point Frankie at a spec, name the\n * operations the agent may use, and it builds the tools at startup.\n */\nexport const apiCapabilitySchema = z.object({\n operationId: z.string().min(1),\n method: z.enum([\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\"]),\n path: z.string().min(1),\n summary: z.string().optional(),\n});\n\nexport const apiSourceSchema = z.object({\n name: z\n .string()\n .min(1)\n .regex(/^[a-z0-9][a-z0-9_-]*$/i, \"API source names must be alphanumeric with - or _\"),\n /** URL or local path to an OpenAPI 3.x document (JSON or YAML). */\n spec: z.string().min(1),\n /** Overrides the spec's own `servers[0].url`. Required if the spec has none. */\n baseUrl: z.string().url().optional(),\n /**\n * Operation ids the agent may call. Empty means \"every operation that passes\n * the other filters\" — fine for a small internal API, risky for a large one.\n */\n operations: z.array(z.string()).default([]),\n /**\n * Path globs to include, e.g. `/projects/**`. Empty means all paths.\n */\n includePaths: z.array(z.string()).default([]),\n /**\n * HTTP methods the agent may use. Read-only by default: an onboarding agent\n * wired to a whole API should not be able to DELETE on its first day. Widen\n * deliberately, per API.\n */\n methods: z.array(z.enum([\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\"])).default([\"GET\"]),\n enabled: z.boolean().default(true),\n /** Explicit operation selection, independent of the discovered inventory. */\n selectedTools: z.array(z.string().min(1)).optional(),\n /** Whether these approved API tools are also served by the workspace MCP. */\n exposeAsMcp: z.boolean().default(true),\n /** A read-only inventory derived from the source for the dashboard. */\n capabilities: z.array(apiCapabilitySchema).default([]),\n /** Static headers, e.g. a service token. */\n headers: z.record(z.string(), z.string()).default({}),\n /**\n * When set, the verified end-user JWT is forwarded in this header, so your\n * API authorises the call exactly as it would any other request from them.\n */\n forwardUserTokenAs: z.string().optional(),\n /** Extra claims from the user token to forward as `x-frankie-<claim>`. */\n forwardUserClaims: z.array(z.string()).default([]),\n /** Per-call timeout. */\n timeoutMs: z.number().int().positive().default(30_000),\n /** Response bodies longer than this are truncated before the model sees them. */\n maxResponseChars: z.number().int().positive().default(8_000),\n});\n\nexport const toolPolicySchema = z.object({\n /**\n * Tool names the agent may call without asking. MCP tools are named\n * `mcp__<server>__<tool>` and generated API tools `api__<name>__<operation>`;\n * naming the prefix alone (`mcp__acme`, `api__acme`) allows all of them.\n */\n allow: z.array(z.string()).default([]),\n /** Explicit denials; evaluated before `allow`. */\n deny: z.array(z.string()).default([]),\n /**\n * Deny anything not in `allow`. On by default — an onboarding agent living\n * on a public marketing page should not have an open tool surface.\n */\n denyByDefault: z.boolean().default(true),\n});\n\nexport const agentConfigSchema = z.object({\n /** Prepended to the runtime's own operating instructions. */\n systemPrompt: z.string().default(\"\"),\n /** First message the widget shows before the user types anything. */\n greeting: z.string().default(\"Hi! I can walk you through getting set up. What are you trying to do?\"),\n suggestedPrompts: z.array(z.string()).max(6).default([]),\n maxTurns: z.number().int().positive().max(50).default(12),\n /** Hard stop on estimated spend per session. */\n maxBudgetUsd: z.number().positive().optional(),\n tools: toolPolicySchema.prefault({}),\n /** Show tool activity in the transcript. */\n showToolActivity: z.boolean().default(true),\n});\n\nexport const authConfigSchema = z.object({\n /**\n * Safe to ship in client bundles. Identifies the tenant; it authorises\n * nothing on its own — the origin allowlist and the user token do that.\n */\n publishableKey: z.string().min(8),\n /** Exact origins allowed to open sessions, e.g. `https://app.acme.com`. */\n allowedOrigins: z.array(z.string()).default([]),\n /** Let visitors chat without a host-signed token (marketing pages). */\n allowAnonymous: z.boolean().default(false),\n /** Env var holding the HS256 secret the host signs user tokens with. */\n jwtSecretEnv: z.string().default(\"FRANKIE_JWT_SECRET\"),\n /** Verify against a JWKS endpoint instead of a shared secret (RS/ES256). */\n jwksUrl: z.string().url().optional(),\n jwtIssuer: z.string().optional(),\n jwtAudience: z.string().optional(),\n /** How long an issued session token is good for. */\n sessionTtlSeconds: z.number().int().positive().default(60 * 60),\n /** Env var holding the secret used to sign Frankie's own session tokens. */\n sessionSecretEnv: z.string().default(\"FRANKIE_SESSION_SECRET\"),\n});\n\nexport const limitsConfigSchema = z.object({\n /** Messages per session per window. */\n messagesPerWindow: z.number().int().positive().default(30),\n windowSeconds: z.number().int().positive().default(15 * 60),\n /** Sessions a single IP may open per window. */\n sessionsPerIpPerWindow: z.number().int().positive().default(20),\n /** Longest a single turn may run before it is aborted. */\n turnTimeoutMs: z.number().int().positive().default(120_000),\n});\n\nexport const brandingConfigSchema = z.object({\n name: z.string().default(\"Assistant\"),\n tagline: z.string().optional(),\n avatarUrl: z.string().url().optional(),\n launcherLabel: z.string().default(\"Need a hand?\"),\n});\n\nexport const frankieConfigSchema = z.object({\n tenantId: z.string().min(1),\n branding: brandingConfigSchema.prefault({}),\n theme: widgetThemeSchema,\n model: modelConfigSchema.prefault({}),\n agent: agentConfigSchema.prefault({}),\n auth: authConfigSchema,\n mcpServers: z.array(mcpServerSchema).default([]),\n /** APIs turned into tools from their OpenAPI document. */\n apis: z.array(apiSourceSchema).default([]),\n limits: limitsConfigSchema.prefault({}),\n /** Opt-in end-user chat capabilities (attachments, model picker). */\n features: featuresConfigSchema,\n});\n\nexport type ThinkingLevel = z.infer<typeof thinkingLevelSchema>;\nexport type WidgetThemeConfig = z.infer<typeof widgetThemeSchema>;\nexport type ModelChoice = z.infer<typeof modelChoiceSchema>;\nexport type FeaturesConfig = z.infer<typeof featuresConfigSchema>;\nexport type ModelConfig = z.infer<typeof modelConfigSchema>;\nexport type McpServerConfig = z.infer<typeof mcpServerSchema>;\nexport type ApiCapability = z.infer<typeof apiCapabilitySchema>;\nexport type ApiSourceConfig = z.infer<typeof apiSourceSchema>;\nexport type ToolPolicy = z.infer<typeof toolPolicySchema>;\nexport type AgentConfig = z.infer<typeof agentConfigSchema>;\nexport type AuthConfig = z.infer<typeof authConfigSchema>;\nexport type LimitsConfig = z.infer<typeof limitsConfigSchema>;\nexport type BrandingConfig = z.infer<typeof brandingConfigSchema>;\nexport type FrankieConfig = z.infer<typeof frankieConfigSchema>;\nexport type FrankieConfigInput = z.input<typeof frankieConfigSchema>;\n\nexport function parseFrankieConfig(input: unknown): FrankieConfig {\n return frankieConfigSchema.parse(input);\n}\n\n/** Helper for `frankie.config.ts` files — gives editors full completion. */\nexport function defineFrankieConfig(config: FrankieConfigInput): FrankieConfigInput {\n return config;\n}\n","import type { ToolPolicy } from \"./config.js\";\n\nexport interface ToolDecision {\n allowed: boolean;\n reason: string;\n}\n\n/**\n * Decide whether the agent may run a tool.\n *\n * Patterns are matched exactly, or as a prefix when they end in `*`. MCP tools\n * arrive as `mcp__<server>__<tool>`, so listing `mcp__acme` (no trailing star)\n * also allows every tool on the `acme` server.\n */\nexport function evaluateToolPolicy(toolName: string, policy: ToolPolicy): ToolDecision {\n if (matchesAny(toolName, policy.deny)) {\n return { allowed: false, reason: `\"${toolName}\" is on the deny list for this agent.` };\n }\n if (matchesAny(toolName, policy.allow)) {\n return { allowed: true, reason: \"allowed by policy\" };\n }\n if (policy.denyByDefault) {\n return { allowed: false, reason: `\"${toolName}\" is not in this agent's allow list.` };\n }\n return { allowed: true, reason: \"no policy match; default allow\" };\n}\n\nfunction matchesAny(toolName: string, patterns: readonly string[]): boolean {\n return patterns.some((pattern) => matches(toolName, pattern));\n}\n\nfunction matches(toolName: string, pattern: string): boolean {\n if (pattern === \"*\") return true;\n if (pattern.endsWith(\"*\")) return toolName.startsWith(pattern.slice(0, -1));\n if (toolName === pattern) return true;\n // `mcp__acme` covers `mcp__acme__create_workspace`.\n return toolName.startsWith(`${pattern}__`);\n}\n\n/** A short human label for a tool call, for the \"Frankie is …\" line in the UI. */\nexport function describeTool(toolName: string, input: unknown): string {\n const mcp = /^mcp__([^_]+(?:_[^_]+)*)__(.+)$/.exec(toolName);\n if (mcp) {\n const [, server, tool] = mcp;\n return `${humanise(tool ?? toolName)} · ${server}`;\n }\n const inputRecord = typeof input === \"object\" && input !== null ? (input as Record<string, unknown>) : {};\n const hint = inputRecord[\"path\"] ?? inputRecord[\"url\"] ?? inputRecord[\"query\"] ?? inputRecord[\"command\"];\n return typeof hint === \"string\" ? `${humanise(toolName)}: ${truncate(hint, 60)}` : humanise(toolName);\n}\n\nfunction humanise(name: string): string {\n return name\n .replace(/[_-]+/g, \" \")\n .replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n .replace(/\\b\\w/g, (c) => c.toUpperCase())\n .trim();\n}\n\nfunction truncate(value: string, max: number): string {\n return value.length <= max ? value : `${value.slice(0, max - 1)}…`;\n}\n","/** One installation plan for GitHub and the local CLI. Never includes credentials. */\nexport interface InstallProject {\n files: Record<string, string>;\n workspace: { id: string; name: string; publishableKey: string; allowAnonymous: boolean };\n apiBaseUrl?: string;\n}\nexport interface InstallPlan {\n files: Array<{ path: string; content: string }>; root: string; chatPath: string; specPath: string;\n operationCount: number; needsAuthSetup: boolean; notes: string[];\n}\ntype ApiDocument = { paths: Record<string, Record<string, unknown>>; [key: string]: unknown };\nexport function planHostedInstall(input: InstallProject): InstallPlan {\n const { files, workspace } = input;\n const layouts = Object.keys(files).filter((p) => /(?:^|\\/)(?:src\\/)?app(?:\\/\\([^/]+\\))?\\/layout\\.tsx$/.test(p));\n const rootLayoutPath = layouts.find((p) => !/(?:^|\\/)app\\/\\([^/]+\\)\\/layout\\.tsx$/.test(p)) ?? layouts[0];\n if (!rootLayoutPath) throw new Error(\"Automatic installation supports Next.js App Router. No app/layout.tsx was found.\");\n // Prefer an existing authenticated/dashboard route group for the chat page and\n // floating widget; route groups do not change the URL, but preserve its layout,\n // session gate, and sidebar.\n const layoutPath = layouts.find((p) => /(?:^|\\/)app\\/\\((?:dashboard|authenticated|protected|app)\\)\\/layout\\.tsx$/.test(p)) ?? rootLayoutPath;\n const appRoot = rootLayoutPath.slice(0, -\"layout.tsx\".length);\n const integrationAppRoot = layoutPath.slice(0, -\"layout.tsx\".length);\n const root = appRoot.replace(/(?:src\\/)?app\\/$/, \"\");\n const pkgPath = root + \"package.json\";\n const pkg = JSON.parse(files[pkgPath] ?? \"{}\");\n if (!pkg.dependencies?.next) throw new Error(\"The selected app must have Next.js in dependencies.\");\n const out = new Map<string, string>();\n const notes: string[] = [];\n const existingMount = files[layoutPath]!.includes(\"FrankieWidgetMount\");\n const sourceRoot = appRoot.endsWith(\"src/app/\") ? root + \"src/\" : root;\n const firebase = Boolean(files[sourceRoot + \"lib/firebase-admin.ts\"]?.includes(\"getAdminAuth\") && files[sourceRoot + \"lib/session.ts\"]?.includes(\"SESSION_COOKIE\"));\n const authFile = files[sourceRoot + \"auth.ts\"];\n const authJs = Boolean(authFile?.includes(\"NextAuth\") && /export\\s+(?:const|let)\\s*\\{[^}]*\\bauth\\b/.test(authFile ?? \"\"));\n const tokenPath = appRoot + \"api/frankie/token/route.ts\";\n const needsAuthSetup = !workspace.allowAnonymous && !files[tokenPath] && !firebase && !authJs;\n if (needsAuthSetup) notes.push(\"Connect getCurrentUser in the generated token endpoint to your server session. It rejects requests until configured.\");\n pkg.dependencies = { ...pkg.dependencies, \"@frankieai/react\": pkg.dependencies[\"@frankieai/react\"] ?? \"^0.1.5\", ...(!workspace.allowAnonymous ? { jose: pkg.dependencies.jose ?? \"^6.0.11\" } : {}) };\n out.set(pkgPath, JSON.stringify(pkg, null, 2) + \"\\n\");\n const authProp = workspace.allowAnonymous ? \"\" : \" getUserToken={getUserToken}\";\n // The distributed stylesheet omits Preflight and scopes every rule to .frankie-root,\n // so the full-page chat is polished without changing the host dashboard.\n const shared = `import { FrankieProvider, FrankieWidget, FrankieChatPage } from \"@frankieai/react\";\\nimport \"@frankieai/react/styles.css\";\\n`;\n const getToken = workspace.allowAnonymous ? \"\" : `\nasync function getUserToken() {\n const response = await fetch(\"/api/frankie/token\", { method: \"POST\", credentials: \"same-origin\" });\n if (!response.ok) return undefined;\n return ((await response.json()) as { token?: string }).token;\n}\n`;\n let priorChat: string | undefined;\n try { const previous = JSON.parse(files[root + \"frankie.install.json\"] ?? \"{}\"); if (previous.workspaceId === workspace.id && [\"/chat\", \"/frankie/chat\"].includes(previous.chatPath)) priorChat = previous.chatPath; } catch {}\n const chatPath = priorChat ?? (files[integrationAppRoot + \"chat/page.tsx\"] ? \"/frankie/chat\" : \"/chat\");\n if (!priorChat && files[integrationAppRoot + chatPath.slice(1) + \"/page.tsx\"]) throw new Error(\"Both /chat and /frankie/chat already exist. Choose a chat route manually.\");\n out.set(root + \"frankie.install.json\", JSON.stringify({ workspaceId: workspace.id, chatPath }, null, 2) + \"\\n\");\n if (chatPath !== \"/chat\") notes.push(\"Existing /chat preserved. Frankie chat is available at /frankie/chat.\");\n const mount = `\"use client\";\\nimport { usePathname } from \"next/navigation\";\\n${shared}${getToken}\nexport function FrankieWidgetMount() {\n const pathname = usePathname();\n const key = process.env.NEXT_PUBLIC_FRANKIE_KEY;\n if (!key || pathname === ${JSON.stringify(chatPath)}) return null;\n return <FrankieProvider publishableKey={key}${authProp}><FrankieWidget /></FrankieProvider>;\n}\nexport function WorkspaceChatPage() {\n const key = process.env.NEXT_PUBLIC_FRANKIE_KEY;\n if (!key) return <p>Chat is not configured. Set NEXT_PUBLIC_FRANKIE_KEY in your deployment.</p>;\n return <FrankieChatPage publishableKey={key}${authProp} />;\n}\n`;\n const moduleName = existingMount ? \"FrankieSetupChat\" : \"FrankieWidgetMount\";\n out.set(integrationAppRoot + \"frankie/\" + moduleName + \".tsx\", mount);\n if (!existingMount) {\n const layout = files[layoutPath]!;\n const importLine = `import { FrankieWidgetMount } from \"./frankie/FrankieWidgetMount\";\\n`;\n const withImport = /^[\"']use client[\"'];/.test(layout) ? layout.replace(/^(['\"]use client['\"];)/, \"$1\\n\" + importLine) : importLine + layout;\n if (withImport.includes(\"</body>\")) {\n out.set(layoutPath, withImport.replace(\"</body>\", \" <FrankieWidgetMount />\\n</body>\"));\n } else if (withImport.includes(\"</main>\")) {\n out.set(layoutPath, withImport.replace(\"</main>\", \" <FrankieWidgetMount />\\n</main>\"));\n } else if (withImport.includes(\"{children}\")) {\n out.set(layoutPath, withImport.replace(\"{children}\", \"{children}<FrankieWidgetMount />\"));\n } else {\n throw new Error(\"The selected layout has no safe widget mount point. Add FrankieWidgetMount manually.\");\n }\n }\n const pageImport = chatPath === \"/chat\" ? \"../frankie/\" : \"../../frankie/\";\n out.set(integrationAppRoot + chatPath.slice(1) + \"/page.tsx\", `import { WorkspaceChatPage } from \"${pageImport}${moduleName}\";\\nexport default WorkspaceChatPage;\\n`);\n if (!workspace.allowAnonymous && !files[tokenPath]) {\n const lookup = firebase\n ? `import { cookies } from \"next/headers\";\\nimport { getAdminAuth } from \"@/lib/firebase-admin\";\\nimport { SESSION_COOKIE } from \"@/lib/session\";\\nasync function getCurrentUser() {\\n const cookie = (await cookies()).get(SESSION_COOKIE)?.value;\\n if (!cookie) return null;\\n const user = await getAdminAuth().verifySessionCookie(cookie, true);\\n return { id: user.uid, name: user.name, email: user.email };\\n}\\n`\n : authJs ? `import { auth } from \"@/auth\";\\nasync function getCurrentUser() {\\n const session = await auth();\\n const user = session?.user as { id?: string; name?: string | null; email?: string | null } | undefined;\\n return user?.id ? user : null;\\n}\\n`\n : `// Replace with your app's verified server session lookup.\\nasync function getCurrentUser(): Promise<{ id: string; name?: string; email?: string } | null> { return null; }\\n`;\n out.set(tokenPath, `import { SignJWT } from \"jose\";\\nimport { NextResponse } from \"next/server\";\\n${lookup}\nexport async function POST() {\n const secret = process.env.FRANKIE_JWT_SECRET;\n if (!secret) return NextResponse.json({ error: \"Chat secret not configured\" }, { status: 503 });\n try {\n const user = await getCurrentUser();\n if (!user?.id) return NextResponse.json({ error: \"Sign in required\" }, { status: 401 });\n const token = await new SignJWT({ name: user.name, email: user.email })\n .setProtectedHeader({ alg: \"HS256\" }).setSubject(user.id).setIssuedAt()\n .setExpirationTime(\"5m\").sign(new TextEncoder().encode(secret));\n return NextResponse.json({ token }, { headers: { \"Cache-Control\": \"no-store\" } });\n } catch { return NextResponse.json({ error: \"Sign in required\" }, { status: 401 }); }\n}\n`);\n }\n let doc: ApiDocument | undefined;\n for (const [path, content] of Object.entries(files)) {\n if (!/(?:openapi|swagger)[^/]*\\.json$/i.test(path)) continue;\n try { const parsed = JSON.parse(content); if (parsed.openapi && parsed.paths) { doc = parsed; break; } } catch {}\n }\n const paths: Record<string, Record<string, unknown>> = {};\n if (!doc) for (const [file, content] of Object.entries(files)) {\n if (/\\.(test|spec)\\.[tj]sx?$/.test(file)) continue;\n const nextRoute = file.match(/(?:^|\\/)app(\\/.*)\\/route\\.[tj]s$/);\n if (nextRoute) {\n const path = nextRoute[1]!.replace(/\\/\\([^/]+\\)/g, \"\").replace(/\\[([^\\]]+)\\]/g, \"{$1}\");\n if (path.includes(\"...\") || /\\/(?:auth|frankie)(?:\\/|$)/.test(path)) continue;\n // Generated tool inventories are read-only. Writes require an explicit, reviewed schema.\n for (const method of [\"GET\"]) {\n if (new RegExp(\"export\\\\s+(?:(?:async\\\\s+)?function\\\\s+\" + method + \"\\\\b|(?:const|let)\\\\s+\" + method + \"\\\\s*=)\").test(content))\n addInstallOperation(paths, method, path, file);\n }\n } else if (/\\.[tj]s$/.test(file) && /(?:routes?|api)\\//.test(file)) {\n for (const match of content.matchAll(/\\b(?:app|router|fastify)\\.(get|post|put|patch|delete)(?:\\s*<[^;]{1,1600}?>)?\\s*\\(\\s*[\"']([^\"']+)[\"']/g))\n addInstallOperation(paths, match[1]!.toUpperCase(), match[2]!.replace(/:([A-Za-z0-9_]+)/g, \"{$1}\"), file);\n }\n }\n doc ??= { openapi: \"3.0.3\", info: { title: workspace.name + \" API\", version: \"1.0.0\", description: \"Read-only generated route inventory. Review schemas, authorization, and the deployed origin before enabling tools.\" }, paths };\n const specPath = root + \"public/frankie.openapi.json\";\n const operationCount = Object.values(doc.paths).reduce((n, item) => n + Object.keys(item).filter((m) => /^(get|post|put|patch|delete)$/.test(m)).length, 0);\n out.set(specPath, JSON.stringify(doc, null, 2) + \"\\n\");\n if (!operationCount) notes.push(\"No supported API routes detected. The OpenAPI draft has no operations; add the real schema before connecting tools.\");\n notes.push(\"Generated OpenAPI is read-only (GET only). Add write operations only to a reviewed, user-authorized schema.\");\n notes.push(\"Verify the public spec URL is reachable without dashboard authentication before connecting it.\");\n notes.push(\"The token endpoint issues a signed user JWT, but your product API must validate it and enforce user/resource permissions before exposing tools.\");\n const envPath = root + \".env.example\";\n const env = (files[envPath] ?? \"\").replace(/^NEXT_PUBLIC_FRANKIE_KEY=.*\\n?/gm, \"\").replace(/^FRANKIE_JWT_SECRET=.*\\n?/gm, \"\").trimEnd();\n out.set(envPath, env + \"\\nNEXT_PUBLIC_FRANKIE_KEY=\" + workspace.publishableKey + \"\\n\" + (workspace.allowAnonymous ? \"\" : \"# Server only: use the secret from this workspace. Never commit its value.\\nFRANKIE_JWT_SECRET=\\n\"));\n out.set(root + \"FRANKIE_SETUP.md\", `# Frankie setup\\n\\nWorkspace: ${workspace.name}\\n\\n1. Add NEXT_PUBLIC_FRANKIE_KEY from .env.example to the frontend deployment.\\n${workspace.allowAnonymous ? \"\" : \"2. Add FRANKIE_JWT_SECRET from this workspace to the server hosting /api/frankie/token. Never commit the value.\\n\"}3. Run your package manager and commit the updated lockfile (for pnpm: pnpm install --lockfile-only). The remote GitHub installer cannot safely synthesize a lockfile.\\n4. Confirm https://YOUR_APP/frankie.openapi.json is public. If your Next.js middleware protects all paths, explicitly bypass /frankie.openapi.json before connecting it.\\n5. Open ${chatPath}. It is created inside the detected authenticated dashboard group when one exists; add its link to the host sidebar during review.\\n6. Connect https://YOUR_APP/frankie.openapi.json in Frankie → Tools & MCP. The generated document contains only read-only GET operations.\\n7. Forwarding sends the Frankie-signed JWT. Your API must validate it and enforce user/resource permissions. It is not automatically interchangeable with a Firebase or OAuth access token.\\n8. Add NEXT_PUBLIC_FRANKIE_KEY to every frontend deployment environment (Preview and Production). ${workspace.allowAnonymous ? \"\" : \"Add FRANKIE_JWT_SECRET only to the server environment running /api/frankie/token; never expose it to the browser.\\n\"}9. Review conversations in Workspace → Chat sessions.\\n\\n## Remaining setup\\n\\n${notes.map((n) => \"- \" + n).join(\"\\n\")}\\n`);\n return { files: [...out].map(([path, content]) => ({ path, content })), root, chatPath, specPath, operationCount, needsAuthSetup, notes };\n}\nfunction addInstallOperation(paths: Record<string, Record<string, unknown>>, method: string, path: string, file: string) {\n if (path.includes(\"*\") || !path.startsWith(\"/\")) return;\n (paths[path] ??= {})[method.toLowerCase()] = {\n operationId: (method.toLowerCase() + \"_\" + path).replace(/[^a-zA-Z0-9_]+/g, \"_\"),\n summary: method + \" \" + path, description: \"Detected in \" + file + \". Review schemas before enabling.\",\n parameters: [...path.matchAll(/\\{([^}]+)\\}/g)].map((m) => ({ name: m[1], in: \"path\", required: true, schema: { type: \"string\" } })),\n responses: { \"200\": { description: \"Successful response\" } }, \"x-frankie-review-required\": true,\n };\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAQX,IAAM,oBAAoB,EAC9B,OAAO;AAAA,EACN,SAAS,EAAE,OAAO,EAAE,SAAS;AAAA,EAC7B,mBAAmB,EAAE,OAAO,EAAE,SAAS;AAAA,EACvC,YAAY,EAAE,OAAO,EAAE,SAAS;AAAA,EAChC,YAAY,EAAE,OAAO,EAAE,SAAS;AAAA,EAChC,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,QAAQ,EAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,QAAQ,EAAE,OAAO,EAAE,SAAS;AAAA,EAC5B,YAAY,EAAE,OAAO,EAAE,SAAS;AAAA,EAChC,MAAM,EAAE,KAAK,CAAC,SAAS,QAAQ,QAAQ,CAAC,EAAE,QAAQ,QAAQ;AAC5D,CAAC,EACA,SAAS,CAAC,CAAC;AAEP,IAAM,sBAAsB,EAAE,KAAK,CAAC,WAAW,OAAO,UAAU,QAAQ,SAAS,KAAK,CAAC;AAEvF,IAAM,oBAAoB,EAAE,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMxC,UAAU,EAAE,OAAO,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AAS,oBAAoB,OAAgD,QAAgB,MAAc,MAAc;AACvH,MAAI,KAAK,SAAS,GAAG,KAAK,CAAC,KAAK,WAAW,GAAG,EAAG;AACjD,GAAC,MAAM,IAAI,MAAM,CAAC,GAAG,OAAO,YAAY,CAAC,IAAI;AAAA,IAC3C,cAAc,OAAO,YAAY,IAAI,MAAM,MAAM,QAAQ,mBAAmB,GAAG;AAAA,IAC/E,SAAS,SAAS,MAAM;AAAA,IAAM,aAAa,iBAAiB,OAAO;AAAA,IACnE,YAAY,CAAC,GAAG,KAAK,SAAS,cAAc,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,GAAG,IAAI,QAAQ,UAAU,MAAM,QAAQ,EAAE,MAAM,SAAS,EAAE,EAAE;AAAA,IAClI,WAAW,EAAE,OAAO,EAAE,aAAa,sBAAsB,EAAE;AAAA,IAAG,6BAA6B;AAAA,EAC7F;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frankieai/core",
3
- "version": "0.1.2",
3
+ "version": "0.1.5",
4
4
  "description": "Shared config schema and wire protocol for Frankie.",
5
5
  "license": "MIT",
6
6
  "type": "module",