@egdesk/next-api-plugin 1.5.199 → 1.5.201

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.
@@ -33,5 +33,5 @@ export interface GenerateHelpersOptions {
33
33
  apiKeyNames?: string[];
34
34
  }
35
35
  /** Bump when generated helper/middleware behavior changes; EGDesk regenerates stale projects. */
36
- export declare const EGDESK_HELPERS_GENERATION_VERSION = "6";
36
+ export declare const EGDESK_HELPERS_GENERATION_VERSION = "7";
37
37
  export declare function generateHelpers(projectPath: string, options?: GenerateHelpersOptions): void;
@@ -134,7 +134,7 @@ function ensureSchemaFile(projectPath, tables) {
134
134
  };
135
135
  }
136
136
  /** Bump when generated helper/middleware behavior changes; EGDesk regenerates stale projects. */
137
- exports.EGDESK_HELPERS_GENERATION_VERSION = '6';
137
+ exports.EGDESK_HELPERS_GENERATION_VERSION = '7';
138
138
  function generateHelpers(projectPath, options = {}) {
139
139
  const helperPath = path.join(projectPath, 'egdesk-helpers.ts');
140
140
  const helperContent = `/**
@@ -144,7 +144,7 @@ function generateHelpers(projectPath, options = {}) {
144
144
  *
145
145
  * Type-safe helpers for EGDesk user data, Google Workspace (Sheets / Drive / Docs / Slides MCP + sync, Gmail, Apps Script),
146
146
  * FinanceHub (banks, cards, Hometax, promissory notes),
147
- * internal knowledge / business identity / company research (MCP), company research docs (cited tool-result blocks), Korean law (MCP), Bizinfo grants (MCP), NPS workplace headcount (MCP), and browser recorder replay / live browse.
147
+ * internal knowledge / business identity / company research (MCP), company research docs (cited tool-result blocks), Relate graph memory (MCP), Korean law (MCP), Bizinfo grants (MCP), NPS workplace headcount (MCP), and browser recorder replay / live browse.
148
148
  * Works in both client and server components.
149
149
  *
150
150
  * Generated by @egdesk/next-api-plugin — do not edit by hand.
@@ -4970,6 +4970,151 @@ export async function syncAppsScript(options: {
4970
4970
  });
4971
4971
  }
4972
4972
 
4973
+ // ==========================================
4974
+ // Relate (MCP) — graph memory / episodes / facts
4975
+ // ==========================================
4976
+
4977
+ /**
4978
+ * Call EGDesk Relate MCP tool (per-project graph: search, read-only Cypher, episode ingest).
4979
+ *
4980
+ * - Server: \`POST {apiUrl}/relate/tools/call\`
4981
+ * - Client: \`POST /__relate_proxy\` (see proxy.ts / middleware)
4982
+ * - Tools: \`relate_graph\`, \`relate_query\`, \`relate_ingest\` (enable Relate in EGDesk MCP settings)
4983
+ */
4984
+ export async function callRelateTool(
4985
+ toolName: 'relate_graph' | 'relate_query' | 'relate_ingest',
4986
+ args: Record<string, any> = {}
4987
+ ): Promise<any> {
4988
+ const body = JSON.stringify({ tool: toolName, arguments: args });
4989
+
4990
+ const isServer = typeof window === 'undefined';
4991
+
4992
+ let response: Response;
4993
+ if (isServer) {
4994
+ const apiUrl = resolveServerEgdeskApiUrl();
4995
+ response = await fetch(\`\${apiUrl}/relate/tools/call\`, {
4996
+ method: 'POST',
4997
+ headers: buildServerEgdeskHeaders(),
4998
+ body,
4999
+ });
5000
+ } else {
5001
+ response = await apiFetch('/__relate_proxy', {
5002
+ method: 'POST',
5003
+ headers: { 'Content-Type': 'application/json' },
5004
+ body,
5005
+ });
5006
+ }
5007
+
5008
+ return parseEgdeskMcpToolResponse(response);
5009
+ }
5010
+
5011
+ /** Relate graph project status (enabled, queue, counts). */
5012
+ export async function getRelateStatus(projectId?: string) {
5013
+ return callRelateTool('relate_graph', {
5014
+ action: 'status',
5015
+ ...(projectId ? { project_id: projectId } : {}),
5016
+ });
5017
+ }
5018
+
5019
+ /** Hybrid / lexical / vector search over entities, facts, and episodes. */
5020
+ export async function searchRelateGraph(
5021
+ query: string,
5022
+ options: {
5023
+ projectId?: string;
5024
+ limit?: number;
5025
+ mode?: 'hybrid' | 'lexical' | 'vector';
5026
+ } = {}
5027
+ ) {
5028
+ return callRelateTool('relate_graph', {
5029
+ action: 'search',
5030
+ query,
5031
+ ...(options.projectId ? { project_id: options.projectId } : {}),
5032
+ ...(options.limit !== undefined ? { limit: options.limit } : {}),
5033
+ ...(options.mode ? { mode: options.mode } : {}),
5034
+ });
5035
+ }
5036
+
5037
+ export async function getRelateCurrentFacts(entityId: string, projectId?: string) {
5038
+ return callRelateTool('relate_graph', {
5039
+ action: 'current_facts',
5040
+ entity_id: entityId,
5041
+ ...(projectId ? { project_id: projectId } : {}),
5042
+ });
5043
+ }
5044
+
5045
+ export async function getRelateFactHistory(
5046
+ entityId: string,
5047
+ factKey: string,
5048
+ projectId?: string
5049
+ ) {
5050
+ return callRelateTool('relate_graph', {
5051
+ action: 'fact_history',
5052
+ entity_id: entityId,
5053
+ fact_key: factKey,
5054
+ ...(projectId ? { project_id: projectId } : {}),
5055
+ });
5056
+ }
5057
+
5058
+ export async function getRelateEpisode(episodeId: string, projectId?: string) {
5059
+ return callRelateTool('relate_graph', {
5060
+ action: 'episode',
5061
+ episode_id: episodeId,
5062
+ ...(projectId ? { project_id: projectId } : {}),
5063
+ });
5064
+ }
5065
+
5066
+ /** Read-only Cypher against the project graph (row cap enforced server-side). */
5067
+ export async function queryRelateGraph(
5068
+ cypher: string,
5069
+ options: { params?: Record<string, any>; projectId?: string } = {}
5070
+ ) {
5071
+ return callRelateTool('relate_query', {
5072
+ cypher,
5073
+ ...(options.params ? { params: options.params } : {}),
5074
+ ...(options.projectId ? { project_id: options.projectId } : {}),
5075
+ });
5076
+ }
5077
+
5078
+ export async function addRelateEpisode(options: {
5079
+ text: string;
5080
+ kind?: 'call' | 'chat' | 'meeting' | 'note';
5081
+ sourceRef?: string;
5082
+ occurredAt?: string;
5083
+ participants?: string[];
5084
+ projectId?: string;
5085
+ confirmed?: boolean;
5086
+ }) {
5087
+ return callRelateTool('relate_ingest', {
5088
+ action: 'add_episode',
5089
+ text: options.text,
5090
+ ...(options.kind ? { kind: options.kind } : {}),
5091
+ ...(options.sourceRef ? { source_ref: options.sourceRef } : {}),
5092
+ ...(options.occurredAt ? { occurred_at: options.occurredAt } : {}),
5093
+ ...(options.participants ? { participants: options.participants } : {}),
5094
+ ...(options.projectId ? { project_id: options.projectId } : {}),
5095
+ ...(options.confirmed ? { confirmed: true } : {}),
5096
+ });
5097
+ }
5098
+
5099
+ export async function reextractRelateEpisode(
5100
+ episodeId: string,
5101
+ options: { projectId?: string; confirmed?: boolean } = {}
5102
+ ) {
5103
+ return callRelateTool('relate_ingest', {
5104
+ action: 'reextract',
5105
+ episode_id: episodeId,
5106
+ ...(options.projectId ? { project_id: options.projectId } : {}),
5107
+ ...(options.confirmed ? { confirmed: true } : {}),
5108
+ });
5109
+ }
5110
+
5111
+ export async function getRelateIngestStatus(projectId?: string) {
5112
+ return callRelateTool('relate_ingest', {
5113
+ action: 'status',
5114
+ ...(projectId ? { project_id: projectId } : {}),
5115
+ });
5116
+ }
5117
+
4973
5118
  // ==========================================
4974
5119
  // Knowledge Wiki (MCP) — Obsidian + wikiHow
4975
5120
  // ==========================================
@@ -11,6 +11,8 @@ const node_test_1 = __importDefault(require("node:test"));
11
11
  const typescript_1 = __importDefault(require("typescript"));
12
12
  const node_vm_1 = __importDefault(require("node:vm"));
13
13
  const generate_helpers_1 = require("./generate-helpers");
14
+ const generate_middleware_1 = require("./generate-middleware");
15
+ const generate_proxy_1 = require("./generate-proxy");
14
16
  function loadGeneratedHelpersModule() {
15
17
  const tmpDir = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'egdesk-helpers-test-'));
16
18
  try {
@@ -72,10 +74,44 @@ function loadGeneratedHelpersModule() {
72
74
  node_fs_1.default.rmSync(tmpDir, { recursive: true, force: true });
73
75
  }
74
76
  }
75
- (0, node_test_1.default)('EGDESK_HELPERS_GENERATION_VERSION is 6', () => {
77
+ (0, node_test_1.default)('EGDESK_HELPERS_GENERATION_VERSION is 7', () => {
76
78
  const { helpers } = loadGeneratedHelpersModule();
77
- strict_1.default.equal(generate_helpers_1.EGDESK_HELPERS_GENERATION_VERSION, '6');
78
- strict_1.default.equal(helpers.EGDESK_HELPERS_GENERATION_VERSION, '6');
79
+ strict_1.default.equal(generate_helpers_1.EGDESK_HELPERS_GENERATION_VERSION, '7');
80
+ strict_1.default.equal(helpers.EGDESK_HELPERS_GENERATION_VERSION, '7');
81
+ });
82
+ (0, node_test_1.default)('searchRelateGraph calls relate MCP with search action', async () => {
83
+ const { helpers, calls } = loadGeneratedHelpersModule();
84
+ await helpers.searchRelateGraph('acme contract', { mode: 'hybrid', limit: 5 });
85
+ strict_1.default.equal(calls.length, 1);
86
+ strict_1.default.equal(calls[0].url, 'http://localhost:8080/relate/tools/call');
87
+ const body = JSON.parse(String(calls[0].options.body));
88
+ strict_1.default.equal(body.tool, 'relate_graph');
89
+ strict_1.default.deepEqual(body.arguments, {
90
+ action: 'search',
91
+ query: 'acme contract',
92
+ limit: 5,
93
+ mode: 'hybrid',
94
+ });
95
+ });
96
+ (0, node_test_1.default)('generateProxy and generateMiddleware both wire __relate_proxy with X-EGDesk-Project-Id', () => {
97
+ const proxyDir = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'egdesk-proxy-relate-'));
98
+ const mwDir = node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), 'egdesk-mw-relate-'));
99
+ try {
100
+ (0, generate_proxy_1.generateProxy)(proxyDir);
101
+ const proxySource = node_fs_1.default.readFileSync(node_path_1.default.join(proxyDir, 'proxy.ts'), 'utf-8');
102
+ strict_1.default.match(proxySource, /pathname\.includes\('__relate_proxy'\)/);
103
+ strict_1.default.match(proxySource, /\/relate\/tools\/call/);
104
+ strict_1.default.match(proxySource, /X-EGDesk-Project-Id/);
105
+ (0, generate_middleware_1.generateMiddleware)(mwDir);
106
+ const mwSource = node_fs_1.default.readFileSync(node_path_1.default.join(mwDir, 'middleware.ts'), 'utf-8');
107
+ strict_1.default.match(mwSource, /pathname\.includes\('__relate_proxy'\)/);
108
+ strict_1.default.match(mwSource, /\/relate\/tools\/call/);
109
+ strict_1.default.match(mwSource, /X-EGDesk-Project-Id/);
110
+ }
111
+ finally {
112
+ node_fs_1.default.rmSync(proxyDir, { recursive: true, force: true });
113
+ node_fs_1.default.rmSync(mwDir, { recursive: true, force: true });
114
+ }
79
115
  });
80
116
  (0, node_test_1.default)('queryTable normalizes where fallback and coerces primitive values to strings', async () => {
81
117
  const { helpers, calls } = loadGeneratedHelpersModule();
@@ -74,7 +74,7 @@ import type { NextRequest } from 'next/server';
74
74
  /**
75
75
  * EGDesk Database Proxy Middleware
76
76
  *
77
- * Intercepts __user_data_proxy, __browser_recording_proxy, __business_identity_proxy, __company_research_proxy, __kakao_proxy, __drive_proxy, __sheets_proxy, __docs_proxy, __slides_proxy, __egdesk_http_proxy, __gmail_proxy, __apps_script_proxy, __visitor_auth_proxy, and __visitor_google_proxy requests
77
+ * Intercepts __user_data_proxy, __browser_recording_proxy, __business_identity_proxy, __company_research_proxy, __kakao_proxy, __relate_proxy, __drive_proxy, __sheets_proxy, __docs_proxy, __slides_proxy, __egdesk_http_proxy, __gmail_proxy, __apps_script_proxy, __visitor_auth_proxy, and __visitor_google_proxy requests
78
78
  *
79
79
  * POLICY (workspace-oauth-byo-multi-HANDOFF-README.md §6.9): Never codegen app/api/workspace-oauth/*
80
80
  * or browser proxies to POST /workspace-oauth/tools/call — operator BYO config is not a visitor API.
@@ -313,6 +313,40 @@ export async function middleware(request: NextRequest) {
313
313
  }
314
314
  }
315
315
 
316
+ if (pathname.includes('__relate_proxy')) {
317
+ try {
318
+ const body = await request.text();
319
+
320
+ const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
321
+ const projectId = process.env.NEXT_PUBLIC_EGDESK_PROJECT_ID;
322
+ const egdeskEnv = process.env.NEXT_PUBLIC_EGDESK_ENV;
323
+ const apiUrl = resolveEgdeskMcpApiUrl();
324
+
325
+ const headers: Record<string, string> = {
326
+ 'Content-Type': 'application/json',
327
+ };
328
+
329
+ if (apiKey) headers['X-Api-Key'] = apiKey;
330
+ if (projectId) headers['X-EGDesk-Project-Id'] = projectId;
331
+ if (egdeskEnv) headers['X-EGDesk-Env'] = egdeskEnv;
332
+
333
+ const response = await fetch(\`\${apiUrl}/relate/tools/call\`, {
334
+ method: 'POST',
335
+ headers,
336
+ body,
337
+ });
338
+
339
+ const result = await response.json();
340
+
341
+ return NextResponse.json(result, { status: response.status });
342
+ } catch (error: any) {
343
+ return NextResponse.json(
344
+ { error: 'Proxy error', message: error.message },
345
+ { status: 500 }
346
+ );
347
+ }
348
+ }
349
+
316
350
  if (pathname.includes('__kakao_proxy')) {
317
351
  try {
318
352
  const body = await request.text();
@@ -76,7 +76,7 @@ import type { NextRequest } from 'next/server';
76
76
  /**
77
77
  * EGDesk Database Proxy (Next.js 16+)
78
78
  *
79
- * Intercepts __user_data_proxy, __browser_recording_proxy, __business_identity_proxy, __company_research_proxy, __ai_center_proxy, __korean_law_proxy, __bizinfo_proxy, __nps_proxy, __seo_proxy, __hosting_coding_proxy, __local_agent_proxy, __pageindex_proxy, __drive_proxy, __sheets_proxy, __docs_proxy, __slides_proxy, __egdesk_http_proxy, __gmail_proxy, __apps_script_proxy, __knowledge_wiki_proxy, __egdesk_config_proxy, __ai_caller_proxy, __kakao_proxy, __phone_proxy, __instagram_proxy, __financehub_proxy, __blog_proxy, __youtube_proxy, __visitor_auth_proxy, and __visitor_google_proxy requests
79
+ * Intercepts __user_data_proxy, __browser_recording_proxy, __business_identity_proxy, __company_research_proxy, __ai_center_proxy, __korean_law_proxy, __bizinfo_proxy, __nps_proxy, __seo_proxy, __hosting_coding_proxy, __local_agent_proxy, __pageindex_proxy, __drive_proxy, __sheets_proxy, __docs_proxy, __slides_proxy, __egdesk_http_proxy, __gmail_proxy, __apps_script_proxy, __knowledge_wiki_proxy, __relate_proxy, __egdesk_config_proxy, __ai_caller_proxy, __kakao_proxy, __phone_proxy, __instagram_proxy, __financehub_proxy, __blog_proxy, __youtube_proxy, __visitor_auth_proxy, and __visitor_google_proxy requests
80
80
  *
81
81
  * POLICY (workspace-oauth-byo-multi-HANDOFF-README.md §6.9): Never codegen app/api/workspace-oauth/*
82
82
  * or browser proxies to POST /workspace-oauth/tools/call — operator BYO config is not a visitor API.
@@ -678,6 +678,28 @@ export async function proxy(request: NextRequest) {
678
678
  }
679
679
  }
680
680
 
681
+ if (pathname.includes('__relate_proxy')) {
682
+ try {
683
+ const body = await request.text();
684
+ const apiUrl = resolveEgdeskMcpApiUrl();
685
+
686
+ const response = await fetch(\`\${apiUrl}/relate/tools/call\`, {
687
+ method: 'POST',
688
+ headers: buildEgdeskHeaders(),
689
+ body,
690
+ });
691
+
692
+ const result = await response.json();
693
+
694
+ return NextResponse.json(result, { status: response.status });
695
+ } catch (error: any) {
696
+ return NextResponse.json(
697
+ { error: 'Proxy error', message: error.message },
698
+ { status: 500 }
699
+ );
700
+ }
701
+ }
702
+
681
703
  if (pathname.includes('__kakao_proxy')) {
682
704
  try {
683
705
  const body = await request.text();
@@ -912,7 +934,7 @@ export const config = {
912
934
  matcher: [
913
935
  /*
914
936
  * Match all paths except static assets
915
- * The proxy function filters for __user_data_proxy / __browser_recording_proxy / __business_identity_proxy / __company_research_proxy / __ai_center_proxy / __korean_law_proxy / __bizinfo_proxy / __nps_proxy / __seo_proxy / __hosting_coding_proxy / __local_agent_proxy / __pageindex_proxy / __drive_proxy / __sheets_proxy / __docs_proxy / __slides_proxy / __egdesk_http_proxy / __gmail_proxy / __apps_script_proxy / __knowledge_wiki_proxy / __egdesk_config_proxy / __ai_caller_proxy / __kakao_proxy / __phone_proxy / __instagram_proxy / __financehub_proxy / __blog_proxy / __youtube_proxy / __visitor_auth_proxy / __visitor_google_proxy
937
+ * The proxy function filters for __user_data_proxy / __browser_recording_proxy / __business_identity_proxy / __company_research_proxy / __ai_center_proxy / __korean_law_proxy / __bizinfo_proxy / __nps_proxy / __seo_proxy / __hosting_coding_proxy / __local_agent_proxy / __pageindex_proxy / __drive_proxy / __sheets_proxy / __docs_proxy / __slides_proxy / __egdesk_http_proxy / __gmail_proxy / __apps_script_proxy / __knowledge_wiki_proxy / __relate_proxy / __egdesk_config_proxy / __ai_caller_proxy / __kakao_proxy / __phone_proxy / __instagram_proxy / __financehub_proxy / __blog_proxy / __youtube_proxy / __visitor_auth_proxy / __visitor_google_proxy
916
938
  */
917
939
  '/:path*',
918
940
  ],
package/dist/index.d.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  * The minimum EGDesk app version this plugin version is compatible with.
9
9
  * The app checks this at setup time and warns on mismatch.
10
10
  */
11
- export declare const COMPATIBLE_APP_VERSION = "1.4.220";
11
+ export declare const COMPATIBLE_APP_VERSION = "1.4.222";
12
12
  export interface SetupOptions {
13
13
  egdeskUrl?: string;
14
14
  /** Production EGDesk server URL — written to .env.production.local. Falls back to egdeskUrl. */
package/dist/index.js CHANGED
@@ -46,7 +46,7 @@ exports.setupNextApiPlugin = setupNextApiPlugin;
46
46
  * The minimum EGDesk app version this plugin version is compatible with.
47
47
  * The app checks this at setup time and warns on mismatch.
48
48
  */
49
- exports.COMPATIBLE_APP_VERSION = '1.4.220';
49
+ exports.COMPATIBLE_APP_VERSION = '1.4.222';
50
50
  const fs = __importStar(require("fs"));
51
51
  const path = __importStar(require("path"));
52
52
  const setup_userdata_1 = require("./setup-userdata");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egdesk/next-api-plugin",
3
- "version": "1.5.199",
3
+ "version": "1.5.201",
4
4
  "description": "Next.js plugin for EGDesk database proxy integration",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",