reasoninglayer 0.2.1

Rust client SDK for the Reasoning Layer API
Documentation
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
//! Utilities DTOs (relational arithmetic, math functions, bitwise/modular ops, string ops, copy).

use serde::{Deserialize, Serialize};

// ─── Arithmetic ─────────────────────────────────────────────────────────────

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ArithValueDto {
    Integer { value: i64 },
    Real { value: f64 },
    TermRef { term_id: String },
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct RelationalArithRequest {
    pub session_id: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub arg1: Option<ArithValueDto>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub arg2: Option<ArithValueDto>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub arg3: Option<ArithValueDto>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "status", rename_all = "snake_case")]
pub enum RelationalArithResponse {
    Success {
        result: ArithValueDto,
        computed_arg: u64,
    },
    Residuate1 {
        term_id: String,
    },
    Residuate2 {
        term1_id: String,
        term2_id: String,
    },
    Residuate3 {
        term1_id: String,
        term2_id: String,
        term3_id: String,
    },
    Curry {
        missing_count: u64,
    },
    Fail {
        reason: String,
    },
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum MathFunctionType {
    Sqrt,
    Pow,
    Sin,
    Cos,
    Tan,
    Asin,
    Acos,
    Atan,
    Atan2,
    Sinh,
    Cosh,
    Tanh,
    Asinh,
    Acosh,
    Atanh,
    Exp,
    Log,
    Log10,
    Floor,
    Ceiling,
    Round,
    Truncate,
    Abs,
    Sign,
    Pi,
    E,
    DegToRad,
    RadToDeg,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MathFunctionRequest {
    pub session_id: String,
    pub function: MathFunctionType,
    pub args: Vec<Option<f64>>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum MathResultDto {
    Integer { value: i64 },
    Real { value: f64 },
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "status", rename_all = "snake_case")]
pub enum MathFunctionResponse {
    Success { result: MathResultDto },
    Residuate { term_ids: Vec<String> },
    DomainError { message: String },
    Fail,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum BitwiseOperationType {
    And,
    Or,
    Xor,
    Not,
    LeftShift,
    RightShift,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BitwiseRequest {
    pub session_id: String,
    pub operation: BitwiseOperationType,
    pub args: Vec<Option<i64>>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "status", rename_all = "snake_case")]
pub enum BitwiseResponse {
    Success { result: i64 },
    Residuate { term_ids: Vec<String> },
    Fail { reason: String },
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ModularOperationType {
    Mod,
    Gcd,
    Lcm,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ModularArithRequest {
    pub operation: ModularOperationType,
    pub arg1: i64,
    pub arg2: i64,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ModularArithResponse {
    pub result: i64,
}

// ─── String operations ──────────────────────────────────────────────────────

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StringConcatRequest {
    pub string1: String,
    pub string2: String,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct StringConcatResponse {
    pub result: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StringLengthRequest {
    pub string_value: String,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct StringLengthResponse {
    pub length: i64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SubstringRequest {
    pub string_value: String,
    pub start: u64,
    pub length: u64,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct SubstringResponse {
    pub result: String,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum StringOperationType {
    ToUpper,
    ToLower,
    Trim,
    TrimStart,
    TrimEnd,
    Reverse,
    CharAt,
    IndexOf,
    Replace,
    Split,
    Contains,
    StartsWith,
    EndsWith,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct StringOpParams {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub index: Option<u64>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub search: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub replacement: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub delimiter: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StringOpRequest {
    pub operation: StringOperationType,
    pub string_value: String,
    #[serde(default)]
    pub params: StringOpParams,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum StringOpResponse {
    String { result: String },
    Char { result: char },
    Integer { result: i64 },
    Boolean { result: bool },
    Strings { result: Vec<String> },
    NotFound,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StringCompareRequest {
    pub string1: String,
    pub string2: String,
    #[serde(default)]
    pub ignore_case: bool,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct StringCompareResponse {
    pub ordering: i32,
    pub are_equal: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum NumberValueDto {
    Integer { value: i64 },
    Real { value: f64 },
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct NumberFormatDto {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub precision: Option<u64>,
    #[serde(default)]
    pub scientific: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NumberToStringRequest {
    pub value: NumberValueDto,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub format: Option<NumberFormatDto>,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct NumberToStringResponse {
    pub result: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AscRequest {
    pub character: char,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct AscResponse {
    pub code: i64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChrRequest {
    pub code: i64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "status", rename_all = "snake_case")]
pub enum ChrResponse {
    Success { character: char },
    InvalidCode { code: i64 },
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum StringCompareOperator {
    Lt,
    Gt,
    Le,
    Ge,
    Eq,
    Ne,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StringComparePredicateRequest {
    pub string1: String,
    pub string2: String,
    pub operator: StringCompareOperator,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct StringComparePredicateResponse {
    pub success: bool,
    pub operator: Option<StringCompareOperator>,
    pub explanation: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchStringCompareRequest {
    pub comparisons: Vec<StringComparePredicateRequest>,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct BatchStringCompareResponse {
    #[serde(default)]
    pub results: Vec<StringComparePredicateResponse>,
    pub all_succeeded: bool,
}

// ─── Copy operations ────────────────────────────────────────────────────────

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum CopyModeDto {
    Exact,
    Quote,
    Eval,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CopyTermRequest {
    pub session_id: String,
    pub term_id: String,
    pub copy_mode: CopyModeDto,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct CopyTermResponse {
    pub original_term_id: String,
    pub copied_term_id: String,
    pub copy_mode: Option<CopyModeDto>,
    #[serde(default)]
    pub copied_features: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SingleCopyRequest {
    pub term_id: String,
    pub copy_mode: CopyModeDto,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BatchCopyRequest {
    pub session_id: String,
    pub copies: Vec<SingleCopyRequest>,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct CopyResultDto {
    pub original_term_id: String,
    pub copied_term_id: String,
    pub success: bool,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub error: Option<String>,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct BatchCopyResponse {
    #[serde(default)]
    pub copies: Vec<CopyResultDto>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DeepCopyRequest {
    pub session_id: String,
    pub term_id: String,
    pub copy_mode: CopyModeDto,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub max_depth: Option<u64>,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct TermTranslationDto {
    pub original_id: String,
    pub copied_id: String,
}

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct DeepCopyResponse {
    pub original_term_id: String,
    pub copied_term_id: String,
    pub copy_mode: Option<CopyModeDto>,
    pub terms_copied: u64,
    pub cycles_detected: bool,
    #[serde(default)]
    pub translation_table: Vec<TermTranslationDto>,
}