Skip to content

Commit 4da5af9

Browse files
authored
Merge pull request #8554 from ProcessMaker/epic/FOUR-26391
Epic/FOUR-26391: AI Data Connectors Implementation
2 parents 44db8ce + 109681a commit 4da5af9

File tree

5 files changed

+203
-0
lines changed

5 files changed

+203
-0
lines changed

config/filesystems.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@
8383
'visibility' => 'public',
8484
],
8585

86+
'data_sources' => [
87+
'driver' => 'local',
88+
'root' => storage_path('app/public/data_sources'),
89+
'url' => env('APP_URL') . '/storage/data_sources',
90+
'visibility' => 'public',
91+
],
92+
8693
'settings' => [
8794
'driver' => 'local',
8895
'root' => storage_path('app/public/setting'),

resources/js/bootstrap.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ window.ProcessesComponents = require("./processes/components");
5353
window.ScreensComponents = require("./processes/screens/components");
5454
window.ScriptsComponents = require("./processes/scripts/components");
5555
window.ProcessesCatalogueComponents = require("./processes-catalogue/components/utils");
56+
window.Utils = require("./utils");
5657

5758
window.PMDropdownSuggest = PMDropdownSuggest;
5859

resources/js/components/shared/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ import CreatePmBlockModal from "../pm-blocks/CreatePmBlockModal.vue";
4747
import TasksHome from "../../tasks/components/TasksHome.vue";
4848
import RequestsListing from "../../requests/components/RequestsListing.vue";
4949
import FilterTable from "./FilterTable.vue";
50+
import FilterableTable from "../../../jscomposition/system/table/FilterableTable.vue";
51+
import EmptyPlaceholder from "../../../jscomposition/system/placeholders/EmptyPlaceholder.vue";
52+
import LoadingPlaceholder from "../../../jscomposition/system/placeholders/LoadingPlaceholder.vue";
53+
import Pagination from "../../../jscomposition/system/table/Pagination.vue";
5054
import TasksList from '../../tasks/components/TasksList';
5155
import apiDataLoading from '../common/mixins/apiDataLoading';
5256
import datatableMixin from '../common/mixins/datatable';
@@ -113,6 +117,10 @@ export {
113117
TasksHome,
114118
RequestsListing,
115119
FilterTable,
120+
FilterableTable,
121+
EmptyPlaceholder,
122+
LoadingPlaceholder,
123+
Pagination,
116124
TasksList,
117125
apiDataLoading,
118126
datatableMixin,

resources/js/utils/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const promptSessionMixin = require("./promptSession").default;
2+
3+
module.exports = {
4+
promptSessionMixin,
5+
};
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
/**
2+
* Prompt Session Utility for ProcessMaker AI Microservice
3+
* Provides functionality to manage prompt session IDs and nonces
4+
*/
5+
6+
export default {
7+
data() {
8+
return {
9+
promptSessionId: localStorage.getItem("promptSessionId") || "",
10+
currentNonce: "",
11+
};
12+
},
13+
14+
methods: {
15+
/**
16+
* Generate a new nonce and store it in localStorage
17+
* @returns {string} The generated nonce
18+
*/
19+
getNonce() {
20+
const max = 999999999999999;
21+
const nonce = Math.floor(Math.random() * max);
22+
this.currentNonce = nonce.toString();
23+
localStorage.setItem("currentNonce", this.currentNonce);
24+
return this.currentNonce;
25+
},
26+
27+
/**
28+
* Get the current nonce from localStorage
29+
* @returns {string|null} The current nonce or null if not found
30+
*/
31+
getCurrentNonce() {
32+
return localStorage.getItem("currentNonce");
33+
},
34+
35+
/**
36+
* Get or create a prompt session ID
37+
* @returns {Promise<string>} The prompt session ID
38+
*/
39+
async getPromptSession() {
40+
const url = "/package-ai/getPromptSessionHistory";
41+
let params = {
42+
server: window.location.host,
43+
};
44+
45+
// Reset session ID if it starts with "ss" (invalid format)
46+
if (this.promptSessionId && this.promptSessionId.startsWith("ss")) {
47+
this.promptSessionId = "";
48+
}
49+
50+
// Use existing session ID if available
51+
if (this.promptSessionId && this.promptSessionId !== null && this.promptSessionId !== "") {
52+
params = { promptSessionId: this.promptSessionId };
53+
}
54+
55+
try {
56+
const response = await ProcessMaker.apiClient.post(url, params);
57+
this.promptSessionId = response.data.promptSessionId;
58+
localStorage.setItem("promptSessionId", this.promptSessionId);
59+
return this.promptSessionId;
60+
} catch (error) {
61+
const errorMsg = error.response?.data?.message || error.message;
62+
63+
if (error.response?.status === 404) {
64+
// Session not found, clear it and try again
65+
localStorage.removeItem("promptSessionId");
66+
this.promptSessionId = "";
67+
return this.getPromptSession();
68+
}
69+
// eslint-disable-next-line no-console
70+
console.error("Error getting prompt session:", errorMsg);
71+
throw error;
72+
}
73+
},
74+
75+
/**
76+
* Clear the current prompt session
77+
*/
78+
clearPromptSession() {
79+
this.promptSessionId = "";
80+
localStorage.removeItem("promptSessionId");
81+
localStorage.removeItem("currentNonce");
82+
},
83+
84+
/**
85+
* Check if a prompt session exists
86+
* @returns {boolean} True if session exists
87+
*/
88+
hasPromptSession() {
89+
return this.promptSessionId && this.promptSessionId !== "";
90+
},
91+
},
92+
};
93+
94+
/**
95+
* Standalone utility functions that can be used without Vue component
96+
*/
97+
export const promptSessionUtils = {
98+
/**
99+
* Get prompt session ID from localStorage
100+
* @returns {string} The prompt session ID
101+
*/
102+
getPromptSessionId() {
103+
return localStorage.getItem("promptSessionId") || "";
104+
},
105+
106+
/**
107+
* Set prompt session ID in localStorage
108+
* @param {string} sessionId - The session ID to store
109+
*/
110+
setPromptSessionId(sessionId) {
111+
localStorage.setItem("promptSessionId", sessionId);
112+
},
113+
114+
/**
115+
* Clear prompt session from localStorage
116+
*/
117+
clearPromptSession() {
118+
localStorage.removeItem("promptSessionId");
119+
localStorage.removeItem("currentNonce");
120+
},
121+
122+
/**
123+
* Generate a new nonce
124+
* @returns {string} The generated nonce
125+
*/
126+
generateNonce() {
127+
const max = 999999999999999;
128+
const nonce = Math.floor(Math.random() * max);
129+
const nonceString = nonce.toString();
130+
localStorage.setItem("currentNonce", nonceString);
131+
return nonceString;
132+
},
133+
134+
/**
135+
* Get current nonce from localStorage
136+
* @returns {string|null} The current nonce
137+
*/
138+
getCurrentNonce() {
139+
return localStorage.getItem("currentNonce");
140+
},
141+
142+
/**
143+
* Make API call to get prompt session (standalone version)
144+
* @returns {Promise<string>} The prompt session ID
145+
*/
146+
async getPromptSession() {
147+
const url = "/package-ai/getPromptSessionHistory";
148+
let params = {
149+
server: window.location.host,
150+
};
151+
152+
const currentSessionId = this.getPromptSessionId();
153+
154+
// Reset session ID if it starts with "ss" (invalid format)
155+
if (currentSessionId && currentSessionId.startsWith("ss")) {
156+
this.clearPromptSession();
157+
}
158+
159+
// Use existing session ID if available
160+
if (currentSessionId && currentSessionId !== "") {
161+
params = { promptSessionId: currentSessionId };
162+
}
163+
164+
try {
165+
const response = await ProcessMaker.apiClient.post(url, params);
166+
const sessionId = response.data.promptSessionId;
167+
this.setPromptSessionId(sessionId);
168+
return sessionId;
169+
} catch (error) {
170+
const errorMsg = error.response?.data?.message || error.message;
171+
172+
if (error.response?.status === 404) {
173+
// Session not found, clear it and try again
174+
this.clearPromptSession();
175+
return this.getPromptSession();
176+
}
177+
// eslint-disable-next-line no-console
178+
console.error("Error getting prompt session:", errorMsg);
179+
throw error;
180+
}
181+
},
182+
};

0 commit comments

Comments
 (0)