Skip to content

Commit d1c2fe1

Browse files
Merge pull request #36 from dreamer-coding/main
2 parents b0089c9 + 1d0a4d7 commit d1c2fe1

File tree

17 files changed

+3788
-1505
lines changed

17 files changed

+3788
-1505
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ To get started with Jellyfish, ensure you have the following installed:
4848
# ======================
4949
[wrap-git]
5050
url = https://github.com/fossillogic/fossil-jellyfish.git
51-
revision = v0.1.2
51+
revision = v0.1.3
5252

5353
[provide]
5454
fossil-jellyfish = fossil_fish_dep

code/logic/fossil/ai/framework.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define FOSSIL_JELLYFISH_AI_FRAMEWORK_H
1616

1717
#include "jellyfish.h"
18-
#include "iochat.h"
1918
#include "language.h"
19+
#include "iochat.h"
2020

2121
#endif /* FOSSIL_JELLYFISH_AI_FRAMEWORK_H */

code/logic/fossil/ai/iochat.h

Lines changed: 135 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern "C"
3333
* @param context_name Optional name for the context/session.
3434
* @return 0 on success, non-zero on failure.
3535
*/
36-
int fossil_io_chat_start(const char *context_name, fossil_jellyfish_chain *chain);
36+
int fossil_io_chat_start(const char *context_name, fossil_jellyfish_chain_t *chain);
3737

3838
/**
3939
* @brief Processes a user input and generates a chatbot response.
@@ -46,7 +46,7 @@ int fossil_io_chat_start(const char *context_name, fossil_jellyfish_chain *chain
4646
* @param size Size of output buffer.
4747
* @return 0 if response found, -1 if unknown.
4848
*/
49-
int fossil_io_chat_respond(fossil_jellyfish_chain *chain, const char *input, char *output, size_t size);
49+
int fossil_io_chat_respond(fossil_jellyfish_chain_t *chain, const char *input, char *output, size_t size);
5050

5151
/**
5252
* @brief Ends the current conversation session and performs cleanup.
@@ -55,7 +55,7 @@ int fossil_io_chat_respond(fossil_jellyfish_chain *chain, const char *input, cha
5555
*
5656
* @return 0 on success.
5757
*/
58-
int fossil_io_chat_end(fossil_jellyfish_chain *chain);
58+
int fossil_io_chat_end(fossil_jellyfish_chain_t *chain);
5959

6060
/**
6161
* @brief Injects a system message into the chain (e.g. "Hello", "System Ready").
@@ -66,7 +66,7 @@ int fossil_io_chat_end(fossil_jellyfish_chain *chain);
6666
* @param message System-level message.
6767
* @return 0 on success.
6868
*/
69-
int fossil_io_chat_inject_system_message(fossil_jellyfish_chain *chain, const char *message);
69+
int fossil_io_chat_inject_system_message(fossil_jellyfish_chain_t *chain, const char *message);
7070

7171
/**
7272
* @brief Appends a chatbot-generated response to the chain memory.
@@ -78,15 +78,15 @@ int fossil_io_chat_inject_system_message(fossil_jellyfish_chain *chain, const ch
7878
* @param output Chatbot response to learn.
7979
* @return 0 on success.
8080
*/
81-
int fossil_io_chat_learn_response(fossil_jellyfish_chain *chain, const char *input, const char *output);
81+
int fossil_io_chat_learn_response(fossil_jellyfish_chain_t *chain, const char *input, const char *output);
8282

8383
/**
8484
* @brief Returns the number of conversational turns remembered.
8585
*
8686
* @param chain Jellyfish chain.
8787
* @return Number of user-input/output pairs.
8888
*/
89-
int fossil_io_chat_turn_count(const fossil_jellyfish_chain *chain);
89+
int fossil_io_chat_turn_count(const fossil_jellyfish_chain_t *chain);
9090

9191
/**
9292
* @brief Summarizes the session into a concise text form.
@@ -98,7 +98,7 @@ int fossil_io_chat_turn_count(const fossil_jellyfish_chain *chain);
9898
* @param size Size of the output buffer.
9999
* @return 0 on success, -1 if summary couldn't be generated.
100100
*/
101-
int fossil_io_chat_summarize_session(const fossil_jellyfish_chain *chain, char *summary, size_t size);
101+
int fossil_io_chat_summarize_session(const fossil_jellyfish_chain_t *chain, char *summary, size_t size);
102102

103103
/**
104104
* @brief Filters the most recent N turns into a temporary sub-chain.
@@ -110,7 +110,7 @@ int fossil_io_chat_summarize_session(const fossil_jellyfish_chain *chain, char *
110110
* @param turn_count Number of recent user turns to include.
111111
* @return 0 on success.
112112
*/
113-
int fossil_io_chat_filter_recent(const fossil_jellyfish_chain *chain, fossil_jellyfish_chain *out_chain, int turn_count);
113+
int fossil_io_chat_filter_recent(const fossil_jellyfish_chain_t *chain, fossil_jellyfish_chain_t *out_chain, int turn_count);
114114

115115
/**
116116
* @brief Exports the current conversation history to a text file.
@@ -119,7 +119,7 @@ int fossil_io_chat_filter_recent(const fossil_jellyfish_chain *chain, fossil_jel
119119
* @param filepath Destination path for output.
120120
* @return 0 on success, -1 on error.
121121
*/
122-
int fossil_io_chat_export_history(const fossil_jellyfish_chain *chain, const char *filepath);
122+
int fossil_io_chat_export_history(const fossil_jellyfish_chain_t *chain, const char *filepath);
123123

124124
/**
125125
* @brief Imports a context file and loads it into the chain.
@@ -130,7 +130,7 @@ int fossil_io_chat_export_history(const fossil_jellyfish_chain *chain, const cha
130130
* @param filepath Source path of saved context.
131131
* @return 0 on success, -1 if parsing fails.
132132
*/
133-
int fossil_io_chat_import_context(fossil_jellyfish_chain *chain, const char *filepath);
133+
int fossil_io_chat_import_context(fossil_jellyfish_chain_t *chain, const char *filepath);
134134

135135
#ifdef __cplusplus
136136
}
@@ -142,7 +142,132 @@ namespace fossil {
142142

143143
namespace ai {
144144

145+
class IOChat {
146+
public:
147+
/**
148+
* @brief Starts a new conversation session.
149+
*
150+
* Initializes a context for handling multi-turn dialogue.
151+
*
152+
* @param context_name Optional name for the context/session.
153+
* @return 0 on success, non-zero on failure.
154+
*/
155+
static int start(const char *context_name, fossil_jellyfish_chain_t *chain) {
156+
return fossil_io_chat_start(context_name, chain);
157+
}
145158

159+
/**
160+
* @brief Processes a user input and generates a chatbot response.
161+
*
162+
* Leverages the Jellyfish memory chain to reason about the input.
163+
*
164+
* @param input User input string.
165+
* @param output Output buffer to receive response.
166+
* @param size Size of output buffer.
167+
* @return 0 if response found, -1 if unknown.
168+
*/
169+
static int respond(fossil_jellyfish_chain_t *chain, const char *input, char *output, size_t size) {
170+
return fossil_io_chat_respond(chain, input, output, size);
171+
}
172+
173+
/**
174+
* @brief Ends the current conversation session and performs cleanup.
175+
*
176+
* Frees temporary memory, flushes session logs, or persists updates.
177+
*
178+
* @return 0 on success.
179+
*/
180+
static int end(fossil_jellyfish_chain_t *chain) {
181+
return fossil_io_chat_end(chain);
182+
}
183+
184+
/**
185+
* @brief Injects a system message into the chain (e.g. "Hello", "System Ready").
186+
*
187+
* System messages are logged as immutable memory blocks with device signature.
188+
*
189+
* @param message System-level message.
190+
* @return 0 on success.
191+
*/
192+
static int inject_system_message(fossil_jellyfish_chain_t *chain, const char *message) {
193+
return fossil_io_chat_inject_system_message(chain, message);
194+
}
195+
196+
/**
197+
* @brief Learns a new response based on user input and chatbot output.
198+
*
199+
* Updates the Jellyfish memory chain with the new information.
200+
*
201+
* @param input User input string.
202+
* @param output Chatbot output string.
203+
* @return 0 on success, -1 on error.
204+
*/
205+
static int learn_response(fossil_jellyfish_chain_t *chain, const char *input, const char *output) {
206+
return fossil_io_chat_learn_response(chain, input, output);
207+
}
208+
209+
/**
210+
* @brief Returns the number of conversational turns remembered.
211+
*
212+
* @param chain Jellyfish chain.
213+
* @return Number of user-input/output pairs.
214+
*/
215+
static int turn_count(const fossil_jellyfish_chain_t *chain) {
216+
return fossil_io_chat_turn_count(chain);
217+
}
218+
219+
/**
220+
* @brief Summarizes the session into a concise text form.
221+
*
222+
* This scans the chat blocks and returns a summary paragraph based on user turns.
223+
*
224+
* @param chain Jellyfish chain to summarize.
225+
* @param summary Output buffer to store summary.
226+
* @param size Size of the output buffer.
227+
* @return 0 on success, -1 if summary couldn't be generated.
228+
*/
229+
static int summarize_session(const fossil_jellyfish_chain_t *chain, char *summary, size_t size) {
230+
return fossil_io_chat_summarize_session(chain, summary, size);
231+
}
232+
233+
/**
234+
* @brief Filters the most recent N turns into a temporary sub-chain.
235+
*
236+
* Useful for generating context-limited decisions.
237+
*
238+
* @param chain Original chat chain.
239+
* @param out_chain Output chain filled with most recent turns.
240+
* @param turn_count Number of recent user turns to include.
241+
* @return 0 on success.
242+
*/
243+
static int filter_recent(const fossil_jellyfish_chain_t *chain, fossil_jellyfish_chain_t *out_chain, int turn_count) {
244+
return fossil_io_chat_filter_recent(chain, out_chain, turn_count);
245+
}
246+
247+
/**
248+
* @brief Exports the current conversation history to a text file.
249+
*
250+
* @param chain Jellyfish chain to serialize.
251+
* @param filepath Destination path for output.
252+
* @return 0 on success, -1 on error.
253+
*/
254+
static int export_history(const fossil_jellyfish_chain_t *chain, const char *filepath) {
255+
return fossil_io_chat_export_history(chain, filepath);
256+
}
257+
258+
/**
259+
* @brief Imports a context file and loads it into the chain.
260+
*
261+
* Useful for bootstrapping or restoring previous sessions.
262+
*
263+
* @param chain Destination Jellyfish chain.
264+
* @param filepath Source path of saved context.
265+
* @return 0 on success, -1 if parsing fails.
266+
*/
267+
static int import_context(fossil_jellyfish_chain_t *chain, const char *filepath) {
268+
return fossil_io_chat_import_context(chain, filepath);
269+
}
270+
};
146271

147272
} // namespace ai
148273

0 commit comments

Comments
 (0)