-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy paththread_service.hpp
More file actions
96 lines (81 loc) · 3.48 KB
/
Copy paththread_service.hpp
File metadata and controls
96 lines (81 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#pragma once
#include "session_client.hpp"
#include <atomic>
#include <cstddef>
#include <cstdint>
#include <functional>
#include <string>
#include <vector>
#include <nlohmann/json.hpp>
namespace acecode {
class SessionManager;
class SessionRegistry;
struct ThreadScope {
std::string cwd;
std::string caller_thread_id;
SessionManager* caller_manager = nullptr;
};
struct ThreadWaitTarget {
std::string thread_id;
std::uint64_t after_cursor = 0;
};
struct ThreadServiceResult {
bool success = false;
nlohmann::json value = nlohmann::json::object();
std::string error;
// Runtime-only control used by delete_thread self-deletion. The tool layer
// forwards these fields to ToolResult; they are never written as JSON.
bool terminate_caller_after_turn = false;
std::function<void()> post_turn_action;
static ThreadServiceResult ok(
nlohmann::json value = nlohmann::json::object());
static ThreadServiceResult fail(std::string error);
};
// In-process thread domain service shared by model tools and host surfaces.
// It resolves persistent and active sessions in the calling workspace and
// never loops back through ACECode's HTTP API.
class ThreadService {
public:
struct Deps {
SessionRegistry* registry = nullptr;
SessionClient* client = nullptr;
};
explicit ThreadService(Deps deps);
ThreadServiceResult list(const ThreadScope& scope,
std::size_t limit = 20) const;
ThreadServiceResult read(const ThreadScope& scope,
const std::string& thread_id,
const std::string& cursor = {},
std::size_t turn_limit = 8,
bool include_outputs = false,
std::size_t max_chars_per_item = 2000) const;
ThreadServiceResult wait(const ThreadScope& scope,
const std::vector<ThreadWaitTarget>& targets,
int timeout_ms,
const std::atomic<bool>* abort_flag = nullptr) const;
ThreadServiceResult create(const ThreadScope& scope,
const std::string& prompt,
const std::string& title = {},
const std::string& model_name = {}) const;
ThreadServiceResult fork(const ThreadScope& scope,
const std::string& thread_id = {}) const;
ThreadServiceResult send(const ThreadScope& scope,
const std::string& thread_id,
const std::string& prompt) const;
ThreadServiceResult set_title(const ThreadScope& scope,
const std::string& thread_id,
const std::string& title) const;
ThreadServiceResult set_pinned(const ThreadScope& scope,
const std::string& thread_id,
bool pinned) const;
ThreadServiceResult set_archived(const ThreadScope& scope,
const std::string& thread_id,
bool archived) const;
ThreadServiceResult delete_thread(const ThreadScope& scope,
const std::string& thread_id) const;
ThreadServiceResult repair(const ThreadScope& scope,
const std::string& thread_id) const;
private:
Deps deps_;
};
} // namespace acecode