-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenconstruct.h
More file actions
206 lines (180 loc) · 5.8 KB
/
openconstruct.h
File metadata and controls
206 lines (180 loc) · 5.8 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/**
* @file openconstruct.h
* @brief OpenConstruct C ABI Header
*
* OpenConstruct C ABI — the keystone for polyglot bindings.
* Any language that can call C functions can use OpenConstruct.
*
* This header provides the complete C interface to the OpenConstruct library.
*/
#ifndef OPENCONSTRUCT_H
#define OPENCONSTRUCT_H
#include <stddef.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Phase constants for onboarding workflow
*/
#define OC_PHASE_SELF_DECLARATION 1
#define OC_PHASE_MODULE_SELECTION 2
#define OC_PHASE_INTERFACE_SELECTION 3
#define OC_PHASE_CONNECTION_SETUP 4
#define OC_PHASE_ENVIRONMENT_GEN 5
/**
* @brief Opaque session handle
*
* Represents an active OpenConstruct onboarding session.
* Created with oc_session_start() and freed with oc_session_free().
*/
typedef struct OcSession OcSession;
/**
* @brief Opaque registry handle
*
* Represents the module registry containing available modules.
* Created with oc_registry_create() and freed with oc_registry_free().
*/
typedef struct OcRegistry OcRegistry;
/**
* @brief Module descriptor
*
* Contains metadata about a single module in the registry.
* Returned pointers are owned by the registry and should not be freed.
*/
typedef struct OcModule {
char *id; /**< Module identifier */
char *domain; /**< Module domain (e.g., "math", "plato", "agents") */
char *name; /**< Human-readable module name */
char *one_line; /**< Short description of the module */
} OcModule;
/**
* @brief Onboarding result
*
* Returned by operations that have success/failure states.
* String fields must be freed with oc_string_free().
*/
typedef struct OcResult {
bool success; /**< Whether the operation succeeded */
unsigned char phase; /**< Current phase after the operation */
char *message; /**< Human-readable result message */
char *data_json; /**< JSON data related to the operation */
} OcResult;
// ===== Registry Functions =====
/**
* @brief Create a new OpenConstruct registry with default SuperInstance modules
*
* The registry contains pre-loaded modules for various domains including
* mathematics, PLATO, and agent protocols.
*
* @return Pointer to a new OcRegistry, or NULL on failure
*/
OcRegistry *oc_registry_create(void);
/**
* @brief Free a registry and all its resources
*
* After calling this function, the registry pointer becomes invalid.
*
* @param reg Pointer to the registry to free (NULL is safe)
*/
void oc_registry_free(OcRegistry *reg);
/**
* @brief Get the number of modules in the registry
*
* @param reg Pointer to the registry (NULL returns 0)
* @return Number of modules in the registry
*/
size_t oc_registry_count(const OcRegistry *reg);
/**
* @brief Get a module by index
*
* The returned pointer is owned by the registry and must not be freed.
* Valid indices are 0 to oc_registry_count() - 1.
*
* @param reg Pointer to the registry (NULL returns NULL)
* @param index Zero-based index of the module
* @return Pointer to the module, or NULL if index is out of range
*/
const OcModule *oc_registry_get(const OcRegistry *reg, size_t index);
// ===== Session Functions =====
/**
* @brief Start a new onboarding session
*
* Creates a new session initialized to OC_PHASE_SELF_DECLARATION.
*
* @return Pointer to a new OcSession, or NULL on failure
*/
OcSession *oc_session_start(void);
/**
* @brief Free a session and all its resources
*
* After calling this function, the session pointer becomes invalid.
*
* @param session Pointer to the session to free (NULL is safe)
*/
void oc_session_free(OcSession *session);
/**
* @brief Get the current phase of a session
*
* @param session Pointer to the session (NULL returns 0)
* @return Current phase constant (OC_PHASE_*), or 0 if session is NULL
*/
unsigned char oc_session_phase(const OcSession *session);
// ===== Onboarding Functions =====
/**
* @brief Phase 1: Declare agent identity
*
* Moves the session from OC_PHASE_SELF_DECLARATION to OC_PHASE_MODULE_SELECTION.
*
* @param session Pointer to the session (NULL returns error result)
* @param name Agent name (UTF-8 string)
* @param model Agent model identifier (UTF-8 string)
* @return OcResult with success status and next phase
*/
OcResult oc_declare_agent(OcSession *session, const char *name, const char *model);
/**
* @brief Phase 2: Select modules for the agent
*
* Accepts a JSON array of module IDs (e.g., "[\"spectral-graph-core\",\"plato-room\"]").
* Moves the session from OC_PHASE_MODULE_SELECTION to OC_PHASE_INTERFACE_SELECTION.
*
* @param session Pointer to the session (NULL returns error result)
* @param module_ids_json JSON array string of module IDs to select
* @return OcResult with success status and next phase
*/
OcResult oc_select_modules(OcSession *session, const char *module_ids_json);
/**
* @brief Generate final configuration (Phase 5)
*
* Generates a JSON configuration string containing session ID, agent info,
* selected modules, interfaces, and current phase.
*
* The returned string must be freed with oc_string_free().
*
* @param session Pointer to the session (NULL returns error message)
* @return JSON configuration string, or error message on failure
*/
char *oc_generate_config(const OcSession *session);
// ===== Utility Functions =====
/**
* @brief Free a string returned by the API
*
* Use this to free any char* pointers returned by OpenConstruct functions.
* NULL is safe.
*
* @param s String pointer to free (NULL is safe)
*/
void oc_string_free(char *s);
/**
* @brief Free strings in an OcResult
*
* Frees the message and data_json fields of an OcResult.
* The result struct itself is stack-allocated and should not be freed.
*
* @param result Pointer to the OcResult to clean up
*/
void oc_result_free(OcResult *result);
#ifdef __cplusplus
}
#endif
#endif // OPENCONSTRUCT_H