mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-31 19:45:15 +02:00
feat: updated agent harness
This commit is contained in:
parent
9ec9b64348
commit
31a372bb84
139 changed files with 12583 additions and 1111 deletions
64
surfsense_web/lib/apis/agent-actions-api.service.ts
Normal file
64
surfsense_web/lib/apis/agent-actions-api.service.ts
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import { z } from "zod";
|
||||
import { baseApiService } from "./base-api.service";
|
||||
|
||||
const AgentActionReadSchema = z.object({
|
||||
id: z.number(),
|
||||
thread_id: z.number(),
|
||||
user_id: z.string().nullable(),
|
||||
search_space_id: z.number(),
|
||||
tool_name: z.string(),
|
||||
args: z.record(z.string(), z.unknown()).nullable(),
|
||||
result_id: z.string().nullable(),
|
||||
reversible: z.boolean(),
|
||||
reverse_descriptor: z.record(z.string(), z.unknown()).nullable(),
|
||||
error: z.record(z.string(), z.unknown()).nullable(),
|
||||
reverse_of: z.number().nullable(),
|
||||
reverted_by_action_id: z.number().nullable(),
|
||||
is_revert_action: z.boolean(),
|
||||
created_at: z.string(),
|
||||
});
|
||||
|
||||
export type AgentAction = z.infer<typeof AgentActionReadSchema>;
|
||||
|
||||
const AgentActionListResponseSchema = z.object({
|
||||
items: z.array(AgentActionReadSchema),
|
||||
total: z.number(),
|
||||
page: z.number(),
|
||||
page_size: z.number(),
|
||||
has_more: z.boolean(),
|
||||
});
|
||||
|
||||
export type AgentActionListResponse = z.infer<typeof AgentActionListResponseSchema>;
|
||||
|
||||
const RevertResponseSchema = z.object({
|
||||
status: z.literal("ok"),
|
||||
message: z.string(),
|
||||
new_action_id: z.number().nullable().optional(),
|
||||
});
|
||||
|
||||
export type RevertResponse = z.infer<typeof RevertResponseSchema>;
|
||||
|
||||
class AgentActionsApiService {
|
||||
listForThread = async (
|
||||
threadId: number,
|
||||
opts: { page?: number; pageSize?: number } = {}
|
||||
): Promise<AgentActionListResponse> => {
|
||||
const params = new URLSearchParams();
|
||||
params.set("page", String(opts.page ?? 0));
|
||||
params.set("page_size", String(opts.pageSize ?? 50));
|
||||
return baseApiService.get(
|
||||
`/api/v1/threads/${threadId}/actions?${params.toString()}`,
|
||||
AgentActionListResponseSchema
|
||||
);
|
||||
};
|
||||
|
||||
revert = async (threadId: number, actionId: number): Promise<RevertResponse> => {
|
||||
return baseApiService.post(
|
||||
`/api/v1/threads/${threadId}/revert/${actionId}`,
|
||||
RevertResponseSchema,
|
||||
{ body: {} }
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export const agentActionsApiService = new AgentActionsApiService();
|
||||
40
surfsense_web/lib/apis/agent-flags-api.service.ts
Normal file
40
surfsense_web/lib/apis/agent-flags-api.service.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { z } from "zod";
|
||||
import { baseApiService } from "./base-api.service";
|
||||
|
||||
const AgentFeatureFlagsSchema = z.object({
|
||||
disable_new_agent_stack: z.boolean(),
|
||||
|
||||
enable_context_editing: z.boolean(),
|
||||
enable_compaction_v2: z.boolean(),
|
||||
enable_retry_after: z.boolean(),
|
||||
enable_model_fallback: z.boolean(),
|
||||
enable_model_call_limit: z.boolean(),
|
||||
enable_tool_call_limit: z.boolean(),
|
||||
enable_tool_call_repair: z.boolean(),
|
||||
enable_doom_loop: z.boolean(),
|
||||
|
||||
enable_permission: z.boolean(),
|
||||
enable_busy_mutex: z.boolean(),
|
||||
enable_llm_tool_selector: z.boolean(),
|
||||
|
||||
enable_skills: z.boolean(),
|
||||
enable_specialized_subagents: z.boolean(),
|
||||
enable_kb_planner_runnable: z.boolean(),
|
||||
|
||||
enable_action_log: z.boolean(),
|
||||
enable_revert_route: z.boolean(),
|
||||
|
||||
enable_plugin_loader: z.boolean(),
|
||||
|
||||
enable_otel: z.boolean(),
|
||||
});
|
||||
|
||||
export type AgentFeatureFlags = z.infer<typeof AgentFeatureFlagsSchema>;
|
||||
|
||||
class AgentFlagsApiService {
|
||||
get = async (): Promise<AgentFeatureFlags> => {
|
||||
return baseApiService.get(`/api/v1/agent/flags`, AgentFeatureFlagsSchema);
|
||||
};
|
||||
}
|
||||
|
||||
export const agentFlagsApiService = new AgentFlagsApiService();
|
||||
90
surfsense_web/lib/apis/agent-permissions-api.service.ts
Normal file
90
surfsense_web/lib/apis/agent-permissions-api.service.ts
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
import { z } from "zod";
|
||||
import { ValidationError } from "@/lib/error";
|
||||
import { baseApiService } from "./base-api.service";
|
||||
|
||||
const ActionEnum = z.enum(["allow", "deny", "ask"]);
|
||||
export type AgentPermissionAction = z.infer<typeof ActionEnum>;
|
||||
|
||||
const AgentPermissionRuleSchema = z.object({
|
||||
id: z.number(),
|
||||
search_space_id: z.number(),
|
||||
user_id: z.string().nullable(),
|
||||
thread_id: z.number().nullable(),
|
||||
permission: z.string(),
|
||||
pattern: z.string(),
|
||||
action: ActionEnum,
|
||||
created_at: z.string(),
|
||||
});
|
||||
|
||||
export type AgentPermissionRule = z.infer<typeof AgentPermissionRuleSchema>;
|
||||
|
||||
const AgentPermissionRuleListSchema = z.array(AgentPermissionRuleSchema);
|
||||
|
||||
const AgentPermissionRuleCreateSchema = z.object({
|
||||
permission: z
|
||||
.string()
|
||||
.min(1, "Permission is required")
|
||||
.max(255)
|
||||
.regex(/^[a-zA-Z0-9_:.\-*]+$/, "Use letters, digits, '.', '_', ':', '-', or '*' wildcards."),
|
||||
pattern: z.string().min(1).max(255).default("*"),
|
||||
action: ActionEnum,
|
||||
user_id: z.string().nullable().optional(),
|
||||
thread_id: z.number().nullable().optional(),
|
||||
});
|
||||
|
||||
export type AgentPermissionRuleCreate = z.infer<typeof AgentPermissionRuleCreateSchema>;
|
||||
|
||||
const AgentPermissionRuleUpdateSchema = z.object({
|
||||
pattern: z.string().min(1).max(255).optional(),
|
||||
action: ActionEnum.optional(),
|
||||
});
|
||||
|
||||
export type AgentPermissionRuleUpdate = z.infer<typeof AgentPermissionRuleUpdateSchema>;
|
||||
|
||||
class AgentPermissionsApiService {
|
||||
list = async (searchSpaceId: number): Promise<AgentPermissionRule[]> => {
|
||||
return baseApiService.get(
|
||||
`/api/v1/searchspaces/${searchSpaceId}/agent/permissions/rules`,
|
||||
AgentPermissionRuleListSchema
|
||||
);
|
||||
};
|
||||
|
||||
create = async (
|
||||
searchSpaceId: number,
|
||||
payload: AgentPermissionRuleCreate
|
||||
): Promise<AgentPermissionRule> => {
|
||||
const parsed = AgentPermissionRuleCreateSchema.safeParse(payload);
|
||||
if (!parsed.success) {
|
||||
throw new ValidationError(parsed.error.issues.map((i) => i.message).join(", "));
|
||||
}
|
||||
return baseApiService.post(
|
||||
`/api/v1/searchspaces/${searchSpaceId}/agent/permissions/rules`,
|
||||
AgentPermissionRuleSchema,
|
||||
{ body: parsed.data }
|
||||
);
|
||||
};
|
||||
|
||||
update = async (
|
||||
searchSpaceId: number,
|
||||
ruleId: number,
|
||||
payload: AgentPermissionRuleUpdate
|
||||
): Promise<AgentPermissionRule> => {
|
||||
const parsed = AgentPermissionRuleUpdateSchema.safeParse(payload);
|
||||
if (!parsed.success) {
|
||||
throw new ValidationError(parsed.error.issues.map((i) => i.message).join(", "));
|
||||
}
|
||||
return baseApiService.patch(
|
||||
`/api/v1/searchspaces/${searchSpaceId}/agent/permissions/rules/${ruleId}`,
|
||||
AgentPermissionRuleSchema,
|
||||
{ body: parsed.data }
|
||||
);
|
||||
};
|
||||
|
||||
remove = async (searchSpaceId: number, ruleId: number): Promise<void> => {
|
||||
await baseApiService.delete(
|
||||
`/api/v1/searchspaces/${searchSpaceId}/agent/permissions/rules/${ruleId}`
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export const agentPermissionsApiService = new AgentPermissionsApiService();
|
||||
Loading…
Add table
Add a link
Reference in a new issue