refactor: split repo into docs/ mockup/ app/
- move static mockups from resource/ui to mockup/ - move React app scaffold from resource/ui to app/ - move prome.md + images to docs/ - drop empty resource/jsonfile and resource/ - add root .gitignore - rewrite README for new layout - fix paths in mockup/index.html (resource/ui -> mockup, docs/prome.md)
This commit is contained in:
1 parent
8e87e47017
commit
92a2adad6a
133 files changed
+23416
-50
No files matched your search
@@ -0,0 +1,119 @@
|
||||
import type {
|
||||
AgentLoopFinalResponseGuardContext,
|
||||
AgentLoopFinalResponseGuardResult,
|
||||
} from "@agent-native/core/server";
|
||||
|
||||
const DOMAIN_OPERATION_PATTERN =
|
||||
/\b(create|add|make|build|update|edit|delete|remove|list|show|open|save|publish|submit|send|export|import)\b/i;
|
||||
|
||||
const EXPLICIT_EXTEND_APP_PATTERN =
|
||||
/\b(extend (this |the )?app|add (a |the )?(feature|capability|page|route|screen|action|ui)|scaffold|implement (a |the )?(feature|app)|wire up|build (this |the )?app|new action|create (a |an )?action|agent-native|defineAction)\b/i;
|
||||
|
||||
const SOURCE_HANDOFF_PATTERN =
|
||||
/\b(actions\/|app\/|server\/|drizzle\/|schema\.ts|\.tsx|source code|source files?|edit the (file|code)|I'll (create|add|update|modify|write)|I will (create|add|update|modify|write)|let me (create|add|update|modify|write)|pnpm action)\b/i;
|
||||
|
||||
const APP_ACTION_PREFIXES = [
|
||||
"create-",
|
||||
"update-",
|
||||
"delete-",
|
||||
"list-",
|
||||
"get-",
|
||||
"add-",
|
||||
"remove-",
|
||||
"export-",
|
||||
"import-",
|
||||
"patch-",
|
||||
"search-",
|
||||
"preview-",
|
||||
"navigate",
|
||||
"view-screen",
|
||||
] as const;
|
||||
|
||||
const RETRY_MESSAGE =
|
||||
"The user asked to operate on app data or domain objects. Before editing source or proposing a code change, call tool-search with a specific query for their request, then call the matching registered app action if one exists. Only extend source when no registered action can complete the request.";
|
||||
|
||||
function latestUserText(
|
||||
messages: AgentLoopFinalResponseGuardContext["messages"],
|
||||
): string {
|
||||
for (let index = messages.length - 1; index >= 0; index -= 1) {
|
||||
const message = messages[index];
|
||||
if (message?.role !== "user") continue;
|
||||
const content = message.content;
|
||||
if (typeof content === "string") return content;
|
||||
if (!Array.isArray(content)) continue;
|
||||
return content
|
||||
.filter(
|
||||
(part): part is { type: "text"; text: string } =>
|
||||
!!part &&
|
||||
typeof part === "object" &&
|
||||
(part as { type?: string }).type === "text" &&
|
||||
typeof (part as { text?: string }).text === "string",
|
||||
)
|
||||
.map((part) => part.text)
|
||||
.join("\n");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
function looksLikeDomainOperationRequest(text: string): boolean {
|
||||
const trimmed = text.trim();
|
||||
if (!trimmed || EXPLICIT_EXTEND_APP_PATTERN.test(trimmed)) return false;
|
||||
return DOMAIN_OPERATION_PATTERN.test(trimmed);
|
||||
}
|
||||
|
||||
function calledToolSearch(
|
||||
toolCalls: AgentLoopFinalResponseGuardContext["toolCalls"],
|
||||
): boolean {
|
||||
return toolCalls.some((call) => call.name === "tool-search");
|
||||
}
|
||||
|
||||
function calledAppFacingTool(
|
||||
toolCalls: AgentLoopFinalResponseGuardContext["toolCalls"],
|
||||
): boolean {
|
||||
return toolCalls.some((call) => {
|
||||
if (APP_ACTION_PREFIXES.some((prefix) => call.name.startsWith(prefix))) {
|
||||
return true;
|
||||
}
|
||||
if (call.name !== "bash") return false;
|
||||
const command = String(
|
||||
(call.input as { command?: string } | undefined)?.command ?? "",
|
||||
);
|
||||
return /\bpnpm action\b/.test(command);
|
||||
});
|
||||
}
|
||||
|
||||
function usedSourceEditTools(
|
||||
toolCalls: AgentLoopFinalResponseGuardContext["toolCalls"],
|
||||
): boolean {
|
||||
return toolCalls.some((call) =>
|
||||
["bash", "read", "edit", "write", "grep"].includes(call.name),
|
||||
);
|
||||
}
|
||||
|
||||
function proposesSourceHandoff(text: string): boolean {
|
||||
return SOURCE_HANDOFF_PATTERN.test(text);
|
||||
}
|
||||
|
||||
export function appOperationFinalResponseGuard(
|
||||
context: AgentLoopFinalResponseGuardContext,
|
||||
): AgentLoopFinalResponseGuardResult | null {
|
||||
if (context.executionMode === "plan") return null;
|
||||
|
||||
const requestText = context.requestText ?? latestUserText(context.messages);
|
||||
if (!looksLikeDomainOperationRequest(requestText)) return null;
|
||||
if (calledToolSearch(context.toolCalls)) return null;
|
||||
if (calledAppFacingTool(context.toolCalls)) return null;
|
||||
|
||||
if (
|
||||
!proposesSourceHandoff(context.text) &&
|
||||
!usedSourceEditTools(context.toolCalls)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
retryMessage: RETRY_MESSAGE,
|
||||
expandToolSurface: true,
|
||||
maxRetries: 1,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// App data layer — the DB client lives here.
|
||||
//
|
||||
// This starter ships without any tables, so the wiring is stubbed out. `getDb()`
|
||||
// returns a Drizzle client bound to the app's `schema`. Enable it when you add
|
||||
// your first table (see `drizzle/START_HERE.md`):
|
||||
//
|
||||
// 1. Define tables in `drizzle/schema.ts`.
|
||||
// 2. Uncomment the lines below, run `pnpm db:generate`, then `pnpm db:migrate`
|
||||
// to apply the new migration. (drizzle-orm, drizzle-kit, drizzle.config.ts,
|
||||
// and the db:generate/db:migrate scripts already ship.)
|
||||
//
|
||||
// import { createGetDb } from "@agent-native/core/db";
|
||||
// import { registerShareableResource } from "@agent-native/core/sharing";
|
||||
// import * as schema from "../drizzle/schema";
|
||||
//
|
||||
// export const getDb = createGetDb(schema);
|
||||
// export { schema };
|
||||
//
|
||||
// // Lets accessFilter/assertAccess and the share actions resolve "note" rows.
|
||||
// registerShareableResource({
|
||||
// type: "note",
|
||||
// resourceTable: schema.notes,
|
||||
// sharesTable: schema.noteShares,
|
||||
// displayName: "Note",
|
||||
// titleColumn: "title",
|
||||
// getResourcePath: (note) => `/notes/${note.id}`,
|
||||
// getDb,
|
||||
// });
|
||||
|
||||
export {};
|
||||
@@ -0,0 +1,31 @@
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import {
|
||||
loadTemplateMcpConformance,
|
||||
providerSchemaViolations,
|
||||
templateMcpCatalogModes,
|
||||
type TemplateMcpConformance,
|
||||
} from "@agent-native/core/testing";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
|
||||
const projectRoot = fileURLToPath(new URL("..", import.meta.url));
|
||||
|
||||
describe("Chat MCP catalogs", () => {
|
||||
let template: TemplateMcpConformance;
|
||||
|
||||
beforeAll(async () => {
|
||||
template = await loadTemplateMcpConformance(projectRoot);
|
||||
}, 180_000);
|
||||
|
||||
it.each(templateMcpCatalogModes(projectRoot))(
|
||||
"advertises only schemas that pass every pinned provider rule in the %s catalog",
|
||||
async (mode) => {
|
||||
const tools = await template.listCatalog(mode);
|
||||
expect(tools.length).toBeGreaterThan(0);
|
||||
expect(tools.flatMap((tool) => providerSchemaViolations(tool))).toEqual(
|
||||
[],
|
||||
);
|
||||
},
|
||||
60_000,
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,6 @@
|
||||
import { runAuthGuard } from "@agent-native/core/server";
|
||||
import { defineEventHandler } from "h3";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
return runAuthGuard(event);
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
import { getOrgContext } from "@agent-native/core/org";
|
||||
import {
|
||||
createAgentChatPlugin,
|
||||
loadActionsFromStaticRegistry,
|
||||
} from "@agent-native/core/server";
|
||||
|
||||
import actionsRegistry from "../../.generated/actions-registry.js";
|
||||
import { appOperationFinalResponseGuard } from "../agent/app-operation-guard.js";
|
||||
|
||||
export default createAgentChatPlugin({
|
||||
appId: "app",
|
||||
actions: loadActionsFromStaticRegistry(actionsRegistry),
|
||||
mcp: { connectorCatalog: [] },
|
||||
nativeActionsInDev: true,
|
||||
finalResponseGuard: appOperationFinalResponseGuard,
|
||||
resolveOrgId: async (event) => (await getOrgContext(event)).orgId,
|
||||
systemPrompt: `You are this app's agent. Help the user inspect, explain, and extend the app.
|
||||
|
||||
Use actions as the source of truth. Inspect the current screen when context matters. Treat requests to create, add, build, update, delete, or otherwise operate on the app's domain objects as app operations, not source-code changes. Call the matching app action directly. If an expected action is not loaded, use tool-search before considering a source-code handoff. Only hand off a request as a code change when it changes the app's capabilities, UI, or behavior and no registered action can complete it.
|
||||
|
||||
When asked to extend the app, keep the change small and agent-native: add or update actions, put real product UI on the page, and keep application state and navigation visible to the agent.
|
||||
|
||||
Do not add i18n catalogs or changelog/What's New surfaces unless the user explicitly asks.`,
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
import { defineAppConfig } from "@agent-native/core/server";
|
||||
|
||||
export default defineAppConfig({
|
||||
app: {
|
||||
// This name appears in transactional emails. Change it to your product name.
|
||||
name: "App",
|
||||
// The source template keeps a renamed app from inheriting first-party email branding.
|
||||
sourceTemplate: "builder-code-starter",
|
||||
// Keep the template's authenticated entry explicit after renaming the app.
|
||||
homePath: "/home",
|
||||
// Optional: use your own absolute HTTPS logo URL in transactional emails.
|
||||
// logoUrl: "https://example.com/logo.png",
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
import { createAuthPlugin } from "@agent-native/core/server";
|
||||
|
||||
// Email/password auth with optional Google OAuth (enabled automatically when
|
||||
// GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET are set). No marketing copy — a
|
||||
// blank app defines its own brand on the login page when it needs one by setting loginHtml in this config.
|
||||
export default createAuthPlugin({
|
||||
rootAuth: false, // auth is not serverd on / by default
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
import { defineAppConfig } from "@agent-native/core/server";
|
||||
|
||||
// Refuse opt-in default plugins so a blank app doesn't boot Slack/Telegram/etc
|
||||
// integration routes, Sentry error tracking, the PTY terminal, or agent
|
||||
// long-term memory. `plugins.disabled` is read from getAppConfig() (this `app`
|
||||
// layer), which is why it must live here and not in agent-native.json.
|
||||
// Never disable agent-chat/auth/core-routes — they carry most of the app.
|
||||
export default defineAppConfig({
|
||||
plugins: {
|
||||
disabled: ["integrations", "observational-memory", "sentry", "terminal"],
|
||||
},
|
||||
app: {
|
||||
homePath: "/",
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,6 @@
|
||||
import { defineNitroPlugin } from "@agent-native/core/server";
|
||||
import { startAgentNativeOtel } from "@agent-native/otel";
|
||||
|
||||
export default defineNitroPlugin(() => {
|
||||
startAgentNativeOtel();
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
import { createH3SSRHandler } from "@agent-native/core/server/ssr-handler";
|
||||
|
||||
export default createH3SSRHandler(
|
||||
() => import("virtual:react-router/server-build"),
|
||||
);
|
||||
@@ -0,0 +1,2 @@
|
||||
// Nitro's [...page] catch-all doesn't match "/", and this starter serves its home page at "/".
|
||||
export { default } from "./[...page].get.js";
|
||||
Reference in new issue
Block a user