cwist
Modern C web framework with libttak runtime
Loading...
Searching...
No Matches
json_heal.h
Go to the documentation of this file.
1#ifndef __CWIST_JSON_HEAL_H__
2#define __CWIST_JSON_HEAL_H__
3
31#include <stdbool.h>
32#include <stddef.h>
33#include <cjson/cJSON.h>
34
35/* -------------------------------------------------------------------------
36 * Schema descriptor (shared with zod.h)
37 * ---------------------------------------------------------------------- */
38
48
49#define CWIST_SCHEMA_MAX_ALIASES 8
50
64
70
71/* -------------------------------------------------------------------------
72 * L3 SLLM callback
73 * ---------------------------------------------------------------------- */
74
89typedef char *(*cwist_sllm_heal_fn)(const char *broken_json, const cwist_schema_t *schema,
90 void *userdata);
91
92/* -------------------------------------------------------------------------
93 * Healing configuration
94 * ---------------------------------------------------------------------- */
95
103
104/* -------------------------------------------------------------------------
105 * Result
106 * ---------------------------------------------------------------------- */
107
108#define CWIST_HEAL_LOG_MAX 512
109
118
119/* -------------------------------------------------------------------------
120 * Public API
121 * ---------------------------------------------------------------------- */
122
135cwist_heal_result_t cwist_json_heal(const char *input, const cwist_heal_config_t *cfg);
136
149int cwist_json_schema_align(cJSON *obj, const cwist_schema_t *schema, char *log, size_t log_sz);
150
155
156#endif /* __CWIST_JSON_HEAL_H__ */
int cwist_json_schema_align(cJSON *obj, const cwist_schema_t *schema, char *log, size_t log_sz)
Apply L2 schema alignment to an already-parsed cJSON object in place.
Definition json_heal.c:358
struct cwist_heal_config cwist_heal_config_t
Configuration passed to cwist_json_heal().
struct cwist_schema cwist_schema_t
A complete schema: array of field descriptors + count.
cwist_field_type_t
Expected value type for a schema field.
Definition json_heal.h:40
@ CWIST_FIELD_INT
Definition json_heal.h:42
@ CWIST_FIELD_BOOL
Definition json_heal.h:44
@ CWIST_FIELD_FLOAT
Definition json_heal.h:43
@ CWIST_FIELD_OBJECT
Definition json_heal.h:45
@ CWIST_FIELD_ARRAY
Definition json_heal.h:46
@ CWIST_FIELD_STRING
Definition json_heal.h:41
#define CWIST_HEAL_LOG_MAX
Definition json_heal.h:108
struct cwist_schema_field cwist_schema_field_t
Single field descriptor used by both the healer and the Zod validator.
#define CWIST_SCHEMA_MAX_ALIASES
Definition json_heal.h:49
struct cwist_heal_result cwist_heal_result_t
Result of a healing attempt.
void cwist_heal_result_free(cwist_heal_result_t *r)
Free resources owned by a cwist_heal_result_t.
Definition json_heal.c:584
char *(* cwist_sllm_heal_fn)(const char *broken_json, const cwist_schema_t *schema, void *userdata)
Optional deep-recovery callback (e.g. backed by an LLM).
Definition json_heal.h:89
cwist_heal_result_t cwist_json_heal(const char *input, const cwist_heal_config_t *cfg)
Attempt to heal a potentially broken JSON string.
Definition json_heal.c:509
Configuration passed to cwist_json_heal().
Definition json_heal.h:97
void * sllm_userdata
Passed verbatim to sllm_fn.
Definition json_heal.h:101
const cwist_schema_t * schema
Schema for L2 alignment (may be NULL).
Definition json_heal.h:99
double threshold
Min confidence (0.0–1.0) to accept recovery. Default: 0.8.
Definition json_heal.h:98
cwist_sllm_heal_fn sllm_fn
Optional L3 deep-recovery callback.
Definition json_heal.h:100
Result of a healing attempt.
Definition json_heal.h:111
char * json
Healed JSON string (free with cwist_heal_result_free). NULL on failure.
Definition json_heal.h:112
bool healed
True if any modification was made.
Definition json_heal.h:113
double confidence
Estimated confidence in the recovery (0.0–1.0).
Definition json_heal.h:115
int level
Recovery level reached: 0=none, 1=L1, 2=L2, 3=L3.
Definition json_heal.h:114
char log[CWIST_HEAL_LOG_MAX]
Human-readable description of changes made.
Definition json_heal.h:116
Single field descriptor used by both the healer and the Zod validator.
Definition json_heal.h:58
bool required
Must be present?
Definition json_heal.h:62
const char * name
Canonical field name.
Definition json_heal.h:59
const char * aliases[CWIST_SCHEMA_MAX_ALIASES]
Alternative names (NULL-terminated).
Definition json_heal.h:60
cwist_field_type_t type
Expected value type.
Definition json_heal.h:61
A complete schema: array of field descriptors + count.
Definition json_heal.h:66
int field_count
Definition json_heal.h:68
const cwist_schema_field_t * fields
Definition json_heal.h:67