ciyidogan commited on
Commit
78a2bad
·
verified ·
1 Parent(s): 1636ae6

Update static/js/project.js

Browse files
Files changed (1) hide show
  1. static/js/project.js +63 -0
static/js/project.js CHANGED
@@ -76,6 +76,69 @@ function removeIntent(name) {
76
  });
77
  }
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  function saveProject() {
80
  alert('Save logic will be implemented here.');
81
  }
 
76
  });
77
  }
78
 
79
+ function editIntent(name) {
80
+ const project = document.getElementById('project-select').value;
81
+
82
+ apiGet(`/project/${project}/latest`)
83
+ .then(data => {
84
+ const intent = data.intents.find(i => i.name === name);
85
+ if (!intent) {
86
+ alert('Intent not found.');
87
+ return;
88
+ }
89
+
90
+ document.getElementById('intent-project-name').value = project;
91
+ document.getElementById('intent-name').value = intent.name;
92
+ document.getElementById('intent-action').value = intent.action || '';
93
+ document.getElementById('intent-fallback').value = intent.fallback_error_message || '';
94
+ document.getElementById('intent-prompt').value = intent.humanization_prompt || '';
95
+ document.getElementById('intent-examples').value = (intent.examples || []).join(', ');
96
+ document.getElementById('intent-parameters').value = JSON.stringify(intent.parameters || [], null, 2);
97
+
98
+ $('#intentModal').modal('show');
99
+ })
100
+ .catch(err => console.error(err));
101
+ }
102
+
103
+ function saveIntent() {
104
+ const project = document.getElementById('intent-project-name').value;
105
+ const name = document.getElementById('intent-name').value;
106
+ const action = document.getElementById('intent-action').value;
107
+ const fallback = document.getElementById('intent-fallback').value;
108
+ const prompt = document.getElementById('intent-prompt').value;
109
+ const examples = document.getElementById('intent-examples').value.split(',').map(e => e.trim());
110
+ let parameters = [];
111
+ try {
112
+ parameters = JSON.parse(document.getElementById('intent-parameters').value);
113
+ } catch (e) {
114
+ alert('Invalid JSON in parameters.');
115
+ return;
116
+ }
117
+
118
+ const intentData = {
119
+ action: action,
120
+ fallback_error_message: fallback,
121
+ humanization_prompt: prompt,
122
+ examples: examples,
123
+ parameters: parameters
124
+ };
125
+
126
+ apiPost('/project/update_intent', {
127
+ project_name: project,
128
+ intent_name: name,
129
+ intent_data: intentData
130
+ })
131
+ .then(data => {
132
+ showResult('project-result', data);
133
+ $('#intentModal').modal('hide');
134
+ loadProjectDetails();
135
+ })
136
+ .catch(err => {
137
+ console.error(err);
138
+ alert('Failed to save intent.');
139
+ });
140
+ }
141
+
142
  function saveProject() {
143
  alert('Save logic will be implemented here.');
144
  }