Skip to content

Commit dc8faac

Browse files
author
Jicheng Lu
committed
add code script page
1 parent 49c0ac5 commit dc8faac

8 files changed

Lines changed: 507 additions & 3 deletions

File tree

src/lib/helpers/enums.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ const agentType = {
7777
};
7878
export const AgentType = Object.freeze(agentType);
7979

80+
const agentCodeScriptType = {
81+
Src: 'src',
82+
Test: 'test'
83+
};
84+
export const AgentCodeScriptType = Object.freeze(agentCodeScriptType);
85+
8086
const routingMode = {
8187
Eager: "eager",
8288
Lazy: "lazy"

src/lib/helpers/http.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ function skipLoader(config) {
7474
new RegExp('http(s*)://(.*?)/knowledge/vector/(.*?)/create', 'g'),
7575
new RegExp('http(s*)://(.*?)/knowledge/document/(.*?)/page', 'g'),
7676
new RegExp('http(s*)://(.*?)/users', 'g'),
77-
new RegExp('http(s*)://(.*?)/instruct/chat-completion', 'g')
77+
new RegExp('http(s*)://(.*?)/instruct/chat-completion', 'g'),
78+
new RegExp('http(s*)://(.*?)/agent/(.*?)/code-scripts', 'g')
7879
];
7980

8081
/** @type {RegExp[]} */

src/lib/helpers/types/agentTypes.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,34 @@
109109
* @property {string} [direct_agent_id] - Run task directly in this agent.
110110
*/
111111

112+
/**
113+
* @typedef {Object} AgentCodeScriptFilter
114+
* @property {string[]?} [scriptNames]
115+
* @property {string[]?} [scriptTypes]
116+
*/
117+
118+
119+
/**
120+
* @typedef {Object} AgentCodeScriptViewModel
121+
* @property {string?} [uid]
122+
* @property {string} name
123+
* @property {string} content
124+
* @property {string} script_type
125+
*/
126+
127+
/**
128+
* @typedef {Object} AgentCodeScriptUpdateOptions
129+
* @property {boolean?} [delete_if_not_included]
130+
* @property {boolean?} [is_upsert]
131+
*/
132+
133+
/**
134+
* @typedef {Object} AgentCodeScriptUpdateModel
135+
* @property {AgentCodeScriptViewModel[]?} [code_scripts]
136+
* @property {AgentCodeScriptUpdateOptions?} [options]
137+
*/
138+
139+
112140
/**
113141
* @typedef {Object} ChannelInstruction
114142
* @property {string} [uid]

src/lib/services/agent-service.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { endpoints } from '$lib/services/api-endpoints.js';
22
import axios from 'axios';
3+
import qs from 'qs';
34

45
/**
56
* Get agent settings
@@ -121,3 +122,35 @@ export async function getAgentLabels() {
121122
const response = await axios.get(url);
122123
return response.data;
123124
}
125+
126+
127+
/**
128+
* Get agent code scripts
129+
* @param {string} agentId
130+
* @param {import('$agentTypes').AgentCodeScriptFilter?} filter
131+
* @returns {Promise<import('$agentTypes').AgentCodeScriptViewModel[]>}
132+
*/
133+
export async function getAgentCodeScripts(agentId, filter = null) {
134+
const url = endpoints.agentCodeScriptListUrl.replace("{agentId}", agentId);
135+
const response = await axios.get(url, {
136+
params: {
137+
...filter
138+
},
139+
paramsSerializer: (params) => qs.stringify(params, { encode: false, allowDots: true, arrayFormat: "indices" })
140+
});
141+
return response.data;
142+
}
143+
144+
/**
145+
* Update agent code scripts
146+
* @param {string} agentId
147+
* @param {import('$agentTypes').AgentCodeScriptUpdateModel} update
148+
* @returns {Promise<boolean>}
149+
*/
150+
export async function updateAgentCodeScripts(agentId, update) {
151+
const url = endpoints.agentCodeScriptUpdateUrl.replace("{agentId}", agentId);
152+
const response = await axios.post(url, {
153+
...update
154+
});
155+
return response.data;
156+
}

src/lib/services/api-endpoints.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export const endpoints = {
3737
agentUtilityOptionsUrl: `${host}/agent/utility/options`,
3838
agentRuleOptionsUrl: `${host}/rule/triggers`,
3939
agentLabelsUrl: `${host}/agent/labels`,
40+
41+
// agent code script:
42+
agentCodeScriptListUrl: `${host}/agent/{agentId}/code-scripts`,
43+
agentCodeScriptUpdateUrl: `${host}/agent/{agentId}/code-scripts`,
4044

4145
// agent task
4246
agentTaskListUrl: `${host}/agent/tasks`,

0 commit comments

Comments
 (0)