@egdesk/next-api-plugin 1.4.2 → 1.4.3

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.
@@ -766,6 +766,200 @@ export async function runBrowserRecording(
766
766
  ...options
767
767
  });
768
768
  }
769
+
770
+ // ==========================================
771
+ // AI CENTER (workflows, entities, relations, tags)
772
+ // ==========================================
773
+
774
+ /**
775
+ * Call EGDesk AI Center MCP tool (workflows, Neuron Layer entities/relations/tags).
776
+ *
777
+ * - Server: \`POST {apiUrl}/ai-center/tools/call\`
778
+ * - Client: \`POST /__ai_center_proxy\` (see proxy.ts / middleware)
779
+ */
780
+ export async function callAICenterTool(
781
+ toolName: string,
782
+ args: Record<string, any> = {}
783
+ ): Promise<any> {
784
+ const body = JSON.stringify({ tool: toolName, arguments: args });
785
+ const headers: Record<string, string> = {
786
+ 'Content-Type': 'application/json'
787
+ };
788
+
789
+ const isServer = typeof window === 'undefined';
790
+
791
+ let response: Response;
792
+ if (isServer) {
793
+ const apiUrl =
794
+ (typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
795
+ EGDESK_CONFIG.apiUrl;
796
+ const apiKey =
797
+ (typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_KEY) ||
798
+ EGDESK_CONFIG.apiKey;
799
+ if (apiKey) {
800
+ headers['X-Api-Key'] = apiKey;
801
+ }
802
+ response = await fetch(\`\${apiUrl}/ai-center/tools/call\`, {
803
+ method: 'POST',
804
+ headers,
805
+ body
806
+ });
807
+ } else {
808
+ response = await fetch('/__ai_center_proxy', {
809
+ method: 'POST',
810
+ headers,
811
+ body
812
+ });
813
+ }
814
+
815
+ return parseEgdeskMcpToolResponse(response);
816
+ }
817
+
818
+ // ── Workflows ────────────────────────────────────────────────────────────────
819
+
820
+ /** List all AI workflows */
821
+ export async function listWorkflows() {
822
+ return callAICenterTool('ai_center_list_workflows', {});
823
+ }
824
+
825
+ /** Get a single workflow by ID (includes action steps) */
826
+ export async function getWorkflow(id: string) {
827
+ return callAICenterTool('ai_center_get_workflow', { id });
828
+ }
829
+
830
+ /** Create a new AI workflow */
831
+ export async function createWorkflow(data: {
832
+ label: string;
833
+ inputTypes: string[];
834
+ hints: string[];
835
+ outputTables: string[];
836
+ actions: Array<{ actionId: string; params?: Record<string, string> }>;
837
+ status?: 'active' | 'suggested' | 'draft';
838
+ suggestedBy?: string;
839
+ }) {
840
+ return callAICenterTool('ai_center_create_workflow', data);
841
+ }
842
+
843
+ /** Update metadata fields of an existing workflow */
844
+ export async function updateWorkflow(
845
+ id: string,
846
+ data: {
847
+ label?: string;
848
+ status?: 'active' | 'suggested' | 'draft';
849
+ inputTypes?: string[];
850
+ hints?: string[];
851
+ outputTables?: string[];
852
+ }
853
+ ) {
854
+ return callAICenterTool('ai_center_update_workflow', { id, ...data });
855
+ }
856
+
857
+ /** Change the status of a workflow */
858
+ export async function updateWorkflowStatus(
859
+ id: string,
860
+ status: 'active' | 'suggested' | 'draft'
861
+ ) {
862
+ return callAICenterTool('ai_center_update_workflow_status', { id, status });
863
+ }
864
+
865
+ /** Delete a workflow and all its action steps */
866
+ export async function deleteWorkflow(id: string) {
867
+ return callAICenterTool('ai_center_delete_workflow', { id });
868
+ }
869
+
870
+ // ── Workflow actions ──────────────────────────────────────────────────────────
871
+
872
+ /** Append or insert an action step into a workflow */
873
+ export async function addWorkflowAction(
874
+ workflowId: string,
875
+ actionId: string,
876
+ params: Record<string, string>,
877
+ position: number = 0
878
+ ) {
879
+ return callAICenterTool('ai_center_add_workflow_action', { workflowId, actionId, params, position });
880
+ }
881
+
882
+ /** Remove a single action step from a workflow by its row ID */
883
+ export async function removeWorkflowAction(rowId: string) {
884
+ return callAICenterTool('ai_center_remove_workflow_action', { rowId });
885
+ }
886
+
887
+ // ── Entities ──────────────────────────────────────────────────────────────────
888
+
889
+ /** List all Neuron Layer entities, optionally filtered by type */
890
+ export async function listEntities(types?: string[]) {
891
+ return callAICenterTool('ai_center_list_entities', types ? { types } : {});
892
+ }
893
+
894
+ /** Create a new entity in the Neuron Layer */
895
+ export async function createEntity(data: {
896
+ type: string;
897
+ name: string;
898
+ source: 'ai' | 'human';
899
+ id?: string;
900
+ raw?: string;
901
+ confidence?: number;
902
+ }) {
903
+ return callAICenterTool('ai_center_create_entity', data);
904
+ }
905
+
906
+ /** Delete an entity from the Neuron Layer */
907
+ export async function deleteEntity(id: string) {
908
+ return callAICenterTool('ai_center_delete_entity', { id });
909
+ }
910
+
911
+ // ── Relations ─────────────────────────────────────────────────────────────────
912
+
913
+ /** List all relations, optionally filtered by source entity ID */
914
+ export async function listRelations(fromId?: string) {
915
+ return callAICenterTool('ai_center_list_relations', fromId ? { fromId } : {});
916
+ }
917
+
918
+ /** Create a relation edge between two entities */
919
+ export async function createRelation(data: {
920
+ from_type: string;
921
+ from_id: string;
922
+ to_type: string;
923
+ to_id: string;
924
+ relation: string;
925
+ source: 'ai' | 'human';
926
+ id?: string;
927
+ confidence?: number;
928
+ }) {
929
+ return callAICenterTool('ai_center_create_relation', data);
930
+ }
931
+
932
+ /** Delete a relation edge by ID */
933
+ export async function deleteRelation(id: string) {
934
+ return callAICenterTool('ai_center_delete_relation', { id });
935
+ }
936
+
937
+ // ── Tags ──────────────────────────────────────────────────────────────────────
938
+
939
+ /** List all tags, optionally filtered by entity ID */
940
+ export async function listTags(entityId?: string) {
941
+ return callAICenterTool('ai_center_list_tags', entityId ? { entityId } : {});
942
+ }
943
+
944
+ /** Create a tag/property on an entity or document */
945
+ export async function createTag(data: {
946
+ doc_type: string;
947
+ doc_id: string;
948
+ namespace: string;
949
+ value: string;
950
+ source: 'ai' | 'human';
951
+ id?: string;
952
+ doc_ref?: string;
953
+ entity_id?: string;
954
+ confidence?: number;
955
+ }) {
956
+ return callAICenterTool('ai_center_create_tag', data);
957
+ }
958
+
959
+ /** Delete a tag by ID */
960
+ export async function deleteTag(id: string) {
961
+ return callAICenterTool('ai_center_delete_tag', { id });
962
+ }
769
963
  `;
770
964
  fs.writeFileSync(helperPath, helperContent.replace(/\r?\n/g, os.EOL), 'utf-8');
771
965
  console.log(`✅ Generated ${helperPath}`);
@@ -75,7 +75,7 @@ import type { NextRequest } from 'next/server';
75
75
  /**
76
76
  * EGDesk Database Proxy (Next.js 16+)
77
77
  *
78
- * Intercepts __user_data_proxy, __browser_recording_proxy, and __internal_knowledge_proxy requests
78
+ * Intercepts __user_data_proxy, __browser_recording_proxy, __internal_knowledge_proxy, and __ai_center_proxy requests
79
79
  * and forwards them to the EGDesk MCP HTTP server. This avoids CORS in local and tunneled environments.
80
80
  *
81
81
  * Generated by @egdesk/next-api-plugin
@@ -182,6 +182,38 @@ export async function proxy(request: NextRequest) {
182
182
  }
183
183
  }
184
184
 
185
+ if (pathname.includes('__ai_center_proxy')) {
186
+ try {
187
+ const body = await request.text();
188
+
189
+ const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
190
+ const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
191
+
192
+ const headers: HeadersInit = {
193
+ 'Content-Type': 'application/json',
194
+ };
195
+
196
+ if (apiKey) {
197
+ headers['X-Api-Key'] = apiKey;
198
+ }
199
+
200
+ const response = await fetch(\`\${apiUrl}/ai-center/tools/call\`, {
201
+ method: 'POST',
202
+ headers,
203
+ body,
204
+ });
205
+
206
+ const result = await response.json();
207
+
208
+ return NextResponse.json(result, { status: response.status });
209
+ } catch (error: any) {
210
+ return NextResponse.json(
211
+ { error: 'Proxy error', message: error.message },
212
+ { status: 500 }
213
+ );
214
+ }
215
+ }
216
+
185
217
  // Continue to next proxy or route
186
218
  return NextResponse.next();
187
219
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@egdesk/next-api-plugin",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "Next.js plugin for EGDesk database proxy integration",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -733,6 +733,200 @@ export async function runBrowserRecording(
733
733
  ...options
734
734
  });
735
735
  }
736
+
737
+ // ==========================================
738
+ // AI CENTER (workflows, entities, relations, tags)
739
+ // ==========================================
740
+
741
+ /**
742
+ * Call EGDesk AI Center MCP tool (workflows, Neuron Layer entities/relations/tags).
743
+ *
744
+ * - Server: \`POST {apiUrl}/ai-center/tools/call\`
745
+ * - Client: \`POST /__ai_center_proxy\` (see proxy.ts / middleware)
746
+ */
747
+ export async function callAICenterTool(
748
+ toolName: string,
749
+ args: Record<string, any> = {}
750
+ ): Promise<any> {
751
+ const body = JSON.stringify({ tool: toolName, arguments: args });
752
+ const headers: Record<string, string> = {
753
+ 'Content-Type': 'application/json'
754
+ };
755
+
756
+ const isServer = typeof window === 'undefined';
757
+
758
+ let response: Response;
759
+ if (isServer) {
760
+ const apiUrl =
761
+ (typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_URL) ||
762
+ EGDESK_CONFIG.apiUrl;
763
+ const apiKey =
764
+ (typeof process !== 'undefined' && process.env?.NEXT_PUBLIC_EGDESK_API_KEY) ||
765
+ EGDESK_CONFIG.apiKey;
766
+ if (apiKey) {
767
+ headers['X-Api-Key'] = apiKey;
768
+ }
769
+ response = await fetch(\`\${apiUrl}/ai-center/tools/call\`, {
770
+ method: 'POST',
771
+ headers,
772
+ body
773
+ });
774
+ } else {
775
+ response = await fetch('/__ai_center_proxy', {
776
+ method: 'POST',
777
+ headers,
778
+ body
779
+ });
780
+ }
781
+
782
+ return parseEgdeskMcpToolResponse(response);
783
+ }
784
+
785
+ // ── Workflows ────────────────────────────────────────────────────────────────
786
+
787
+ /** List all AI workflows */
788
+ export async function listWorkflows() {
789
+ return callAICenterTool('ai_center_list_workflows', {});
790
+ }
791
+
792
+ /** Get a single workflow by ID (includes action steps) */
793
+ export async function getWorkflow(id: string) {
794
+ return callAICenterTool('ai_center_get_workflow', { id });
795
+ }
796
+
797
+ /** Create a new AI workflow */
798
+ export async function createWorkflow(data: {
799
+ label: string;
800
+ inputTypes: string[];
801
+ hints: string[];
802
+ outputTables: string[];
803
+ actions: Array<{ actionId: string; params?: Record<string, string> }>;
804
+ status?: 'active' | 'suggested' | 'draft';
805
+ suggestedBy?: string;
806
+ }) {
807
+ return callAICenterTool('ai_center_create_workflow', data);
808
+ }
809
+
810
+ /** Update metadata fields of an existing workflow */
811
+ export async function updateWorkflow(
812
+ id: string,
813
+ data: {
814
+ label?: string;
815
+ status?: 'active' | 'suggested' | 'draft';
816
+ inputTypes?: string[];
817
+ hints?: string[];
818
+ outputTables?: string[];
819
+ }
820
+ ) {
821
+ return callAICenterTool('ai_center_update_workflow', { id, ...data });
822
+ }
823
+
824
+ /** Change the status of a workflow */
825
+ export async function updateWorkflowStatus(
826
+ id: string,
827
+ status: 'active' | 'suggested' | 'draft'
828
+ ) {
829
+ return callAICenterTool('ai_center_update_workflow_status', { id, status });
830
+ }
831
+
832
+ /** Delete a workflow and all its action steps */
833
+ export async function deleteWorkflow(id: string) {
834
+ return callAICenterTool('ai_center_delete_workflow', { id });
835
+ }
836
+
837
+ // ── Workflow actions ──────────────────────────────────────────────────────────
838
+
839
+ /** Append or insert an action step into a workflow */
840
+ export async function addWorkflowAction(
841
+ workflowId: string,
842
+ actionId: string,
843
+ params: Record<string, string>,
844
+ position: number = 0
845
+ ) {
846
+ return callAICenterTool('ai_center_add_workflow_action', { workflowId, actionId, params, position });
847
+ }
848
+
849
+ /** Remove a single action step from a workflow by its row ID */
850
+ export async function removeWorkflowAction(rowId: string) {
851
+ return callAICenterTool('ai_center_remove_workflow_action', { rowId });
852
+ }
853
+
854
+ // ── Entities ──────────────────────────────────────────────────────────────────
855
+
856
+ /** List all Neuron Layer entities, optionally filtered by type */
857
+ export async function listEntities(types?: string[]) {
858
+ return callAICenterTool('ai_center_list_entities', types ? { types } : {});
859
+ }
860
+
861
+ /** Create a new entity in the Neuron Layer */
862
+ export async function createEntity(data: {
863
+ type: string;
864
+ name: string;
865
+ source: 'ai' | 'human';
866
+ id?: string;
867
+ raw?: string;
868
+ confidence?: number;
869
+ }) {
870
+ return callAICenterTool('ai_center_create_entity', data);
871
+ }
872
+
873
+ /** Delete an entity from the Neuron Layer */
874
+ export async function deleteEntity(id: string) {
875
+ return callAICenterTool('ai_center_delete_entity', { id });
876
+ }
877
+
878
+ // ── Relations ─────────────────────────────────────────────────────────────────
879
+
880
+ /** List all relations, optionally filtered by source entity ID */
881
+ export async function listRelations(fromId?: string) {
882
+ return callAICenterTool('ai_center_list_relations', fromId ? { fromId } : {});
883
+ }
884
+
885
+ /** Create a relation edge between two entities */
886
+ export async function createRelation(data: {
887
+ from_type: string;
888
+ from_id: string;
889
+ to_type: string;
890
+ to_id: string;
891
+ relation: string;
892
+ source: 'ai' | 'human';
893
+ id?: string;
894
+ confidence?: number;
895
+ }) {
896
+ return callAICenterTool('ai_center_create_relation', data);
897
+ }
898
+
899
+ /** Delete a relation edge by ID */
900
+ export async function deleteRelation(id: string) {
901
+ return callAICenterTool('ai_center_delete_relation', { id });
902
+ }
903
+
904
+ // ── Tags ──────────────────────────────────────────────────────────────────────
905
+
906
+ /** List all tags, optionally filtered by entity ID */
907
+ export async function listTags(entityId?: string) {
908
+ return callAICenterTool('ai_center_list_tags', entityId ? { entityId } : {});
909
+ }
910
+
911
+ /** Create a tag/property on an entity or document */
912
+ export async function createTag(data: {
913
+ doc_type: string;
914
+ doc_id: string;
915
+ namespace: string;
916
+ value: string;
917
+ source: 'ai' | 'human';
918
+ id?: string;
919
+ doc_ref?: string;
920
+ entity_id?: string;
921
+ confidence?: number;
922
+ }) {
923
+ return callAICenterTool('ai_center_create_tag', data);
924
+ }
925
+
926
+ /** Delete a tag by ID */
927
+ export async function deleteTag(id: string) {
928
+ return callAICenterTool('ai_center_delete_tag', { id });
929
+ }
736
930
  `;
737
931
 
738
932
  fs.writeFileSync(helperPath, helperContent.replace(/\r?\n/g, os.EOL), 'utf-8');
@@ -45,7 +45,7 @@ import type { NextRequest } from 'next/server';
45
45
  /**
46
46
  * EGDesk Database Proxy (Next.js 16+)
47
47
  *
48
- * Intercepts __user_data_proxy, __browser_recording_proxy, and __internal_knowledge_proxy requests
48
+ * Intercepts __user_data_proxy, __browser_recording_proxy, __internal_knowledge_proxy, and __ai_center_proxy requests
49
49
  * and forwards them to the EGDesk MCP HTTP server. This avoids CORS in local and tunneled environments.
50
50
  *
51
51
  * Generated by @egdesk/next-api-plugin
@@ -152,6 +152,38 @@ export async function proxy(request: NextRequest) {
152
152
  }
153
153
  }
154
154
 
155
+ if (pathname.includes('__ai_center_proxy')) {
156
+ try {
157
+ const body = await request.text();
158
+
159
+ const apiKey = process.env.NEXT_PUBLIC_EGDESK_API_KEY;
160
+ const apiUrl = process.env.NEXT_PUBLIC_EGDESK_API_URL || 'http://localhost:8080';
161
+
162
+ const headers: HeadersInit = {
163
+ 'Content-Type': 'application/json',
164
+ };
165
+
166
+ if (apiKey) {
167
+ headers['X-Api-Key'] = apiKey;
168
+ }
169
+
170
+ const response = await fetch(\`\${apiUrl}/ai-center/tools/call\`, {
171
+ method: 'POST',
172
+ headers,
173
+ body,
174
+ });
175
+
176
+ const result = await response.json();
177
+
178
+ return NextResponse.json(result, { status: response.status });
179
+ } catch (error: any) {
180
+ return NextResponse.json(
181
+ { error: 'Proxy error', message: error.message },
182
+ { status: 500 }
183
+ );
184
+ }
185
+ }
186
+
155
187
  // Continue to next proxy or route
156
188
  return NextResponse.next();
157
189
  }