thinkthen 0.1.2-aarch64-linux → 0.2.0-aarch64-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. checksums.yaml +4 -4
  2. data/API.md +40 -0
  3. data/LICENSE +21 -0
  4. data/README.md +562 -0
  5. data/THIRD-PARTY-NOTICES/anstream-1.0.0/LICENSE-APACHE +202 -0
  6. data/THIRD-PARTY-NOTICES/anstream-1.0.0/LICENSE-MIT +19 -0
  7. data/THIRD-PARTY-NOTICES/anstyle-1.0.14/LICENSE-APACHE +202 -0
  8. data/THIRD-PARTY-NOTICES/anstyle-1.0.14/LICENSE-MIT +19 -0
  9. data/THIRD-PARTY-NOTICES/anstyle-parse-1.0.0/LICENSE-APACHE +202 -0
  10. data/THIRD-PARTY-NOTICES/anstyle-parse-1.0.0/LICENSE-MIT +19 -0
  11. data/THIRD-PARTY-NOTICES/anstyle-query-1.1.5/LICENSE-APACHE +202 -0
  12. data/THIRD-PARTY-NOTICES/anstyle-query-1.1.5/LICENSE-MIT +19 -0
  13. data/THIRD-PARTY-NOTICES/base64-0.23.1/LICENSE-APACHE +201 -0
  14. data/THIRD-PARTY-NOTICES/base64-0.23.1/LICENSE-MIT +21 -0
  15. data/THIRD-PARTY-NOTICES/bitflags-2.13.2/LICENSE-APACHE +201 -0
  16. data/THIRD-PARTY-NOTICES/bitflags-2.13.2/LICENSE-MIT +25 -0
  17. data/THIRD-PARTY-NOTICES/block-buffer-0.10.4/LICENSE-APACHE +201 -0
  18. data/THIRD-PARTY-NOTICES/block-buffer-0.10.4/LICENSE-MIT +25 -0
  19. data/THIRD-PARTY-NOTICES/bytes-1.12.1/LICENSE +25 -0
  20. data/THIRD-PARTY-NOTICES/cfg-if-1.0.5/LICENSE-APACHE +201 -0
  21. data/THIRD-PARTY-NOTICES/cfg-if-1.0.5/LICENSE-MIT +25 -0
  22. data/THIRD-PARTY-NOTICES/clap-4.6.7/LICENSE-APACHE +202 -0
  23. data/THIRD-PARTY-NOTICES/clap-4.6.7/LICENSE-MIT +19 -0
  24. data/THIRD-PARTY-NOTICES/clap_builder-4.6.7/LICENSE-APACHE +202 -0
  25. data/THIRD-PARTY-NOTICES/clap_builder-4.6.7/LICENSE-MIT +19 -0
  26. data/THIRD-PARTY-NOTICES/clap_complete-4.6.11/LICENSE-APACHE +202 -0
  27. data/THIRD-PARTY-NOTICES/clap_complete-4.6.11/LICENSE-MIT +19 -0
  28. data/THIRD-PARTY-NOTICES/clap_lex-1.1.1/LICENSE-APACHE +202 -0
  29. data/THIRD-PARTY-NOTICES/clap_lex-1.1.1/LICENSE-MIT +19 -0
  30. data/THIRD-PARTY-NOTICES/clap_mangen-0.2.33/LICENSE-APACHE +202 -0
  31. data/THIRD-PARTY-NOTICES/clap_mangen-0.2.33/LICENSE-MIT +19 -0
  32. data/THIRD-PARTY-NOTICES/colorchoice-1.0.5/LICENSE-APACHE +202 -0
  33. data/THIRD-PARTY-NOTICES/colorchoice-1.0.5/LICENSE-MIT +19 -0
  34. data/THIRD-PARTY-NOTICES/command-group-5.0.1/COPYRIGHT +29 -0
  35. data/THIRD-PARTY-NOTICES/command-group-5.0.1/LICENSE-APACHE +176 -0
  36. data/THIRD-PARTY-NOTICES/command-group-5.0.1/LICENSE-MIT +23 -0
  37. data/THIRD-PARTY-NOTICES/cpufeatures-0.2.17/LICENSE-APACHE +201 -0
  38. data/THIRD-PARTY-NOTICES/cpufeatures-0.2.17/LICENSE-MIT +25 -0
  39. data/THIRD-PARTY-NOTICES/crc32fast-1.5.3/LICENSE-APACHE +202 -0
  40. data/THIRD-PARTY-NOTICES/crc32fast-1.5.3/LICENSE-MIT +21 -0
  41. data/THIRD-PARTY-NOTICES/crypto-common-0.1.7/LICENSE-APACHE +201 -0
  42. data/THIRD-PARTY-NOTICES/crypto-common-0.1.7/LICENSE-MIT +25 -0
  43. data/THIRD-PARTY-NOTICES/ctrlc-3.5.2/LICENSE-APACHE +201 -0
  44. data/THIRD-PARTY-NOTICES/ctrlc-3.5.2/LICENSE-MIT +23 -0
  45. data/THIRD-PARTY-NOTICES/digest-0.10.7/LICENSE-APACHE +201 -0
  46. data/THIRD-PARTY-NOTICES/digest-0.10.7/LICENSE-MIT +25 -0
  47. data/THIRD-PARTY-NOTICES/dyn-clone-1.0.20/LICENSE-APACHE +176 -0
  48. data/THIRD-PARTY-NOTICES/dyn-clone-1.0.20/LICENSE-MIT +23 -0
  49. data/THIRD-PARTY-NOTICES/equivalent-1.0.3/LICENSE-APACHE +201 -0
  50. data/THIRD-PARTY-NOTICES/equivalent-1.0.3/LICENSE-MIT +25 -0
  51. data/THIRD-PARTY-NOTICES/fastrand-2.5.0/LICENSE-APACHE +201 -0
  52. data/THIRD-PARTY-NOTICES/fastrand-2.5.0/LICENSE-MIT +23 -0
  53. data/THIRD-PARTY-NOTICES/flate2-1.1.10/LICENSE-APACHE +201 -0
  54. data/THIRD-PARTY-NOTICES/flate2-1.1.10/LICENSE-MIT +25 -0
  55. data/THIRD-PARTY-NOTICES/generic-array-0.14.7/LICENSE +21 -0
  56. data/THIRD-PARTY-NOTICES/getrandom-0.2.17/LICENSE-APACHE +201 -0
  57. data/THIRD-PARTY-NOTICES/getrandom-0.2.17/LICENSE-MIT +26 -0
  58. data/THIRD-PARTY-NOTICES/getrandom-0.3.4/LICENSE-APACHE +201 -0
  59. data/THIRD-PARTY-NOTICES/getrandom-0.3.4/LICENSE-MIT +26 -0
  60. data/THIRD-PARTY-NOTICES/getrandom-0.4.3/LICENSE-APACHE +201 -0
  61. data/THIRD-PARTY-NOTICES/getrandom-0.4.3/LICENSE-MIT +26 -0
  62. data/THIRD-PARTY-NOTICES/hashbrown-0.17.1/LICENSE-APACHE +201 -0
  63. data/THIRD-PARTY-NOTICES/hashbrown-0.17.1/LICENSE-MIT +25 -0
  64. data/THIRD-PARTY-NOTICES/http-1.5.0/LICENSE-APACHE +201 -0
  65. data/THIRD-PARTY-NOTICES/http-1.5.0/LICENSE-MIT +25 -0
  66. data/THIRD-PARTY-NOTICES/httparse-1.10.1/LICENSE-APACHE +201 -0
  67. data/THIRD-PARTY-NOTICES/httparse-1.10.1/LICENSE-MIT +20 -0
  68. data/THIRD-PARTY-NOTICES/httpdate-1.0.3/LICENSE-APACHE +201 -0
  69. data/THIRD-PARTY-NOTICES/httpdate-1.0.3/LICENSE-MIT +19 -0
  70. data/THIRD-PARTY-NOTICES/index.json +633 -0
  71. data/THIRD-PARTY-NOTICES/indexmap-2.14.2/LICENSE-APACHE +201 -0
  72. data/THIRD-PARTY-NOTICES/indexmap-2.14.2/LICENSE-MIT +25 -0
  73. data/THIRD-PARTY-NOTICES/is_terminal_polyfill-1.70.2/LICENSE-APACHE +202 -0
  74. data/THIRD-PARTY-NOTICES/is_terminal_polyfill-1.70.2/LICENSE-MIT +19 -0
  75. data/THIRD-PARTY-NOTICES/itoa-1.0.18/LICENSE-APACHE +176 -0
  76. data/THIRD-PARTY-NOTICES/itoa-1.0.18/LICENSE-MIT +23 -0
  77. data/THIRD-PARTY-NOTICES/libc-0.2.190/LICENSE-APACHE +176 -0
  78. data/THIRD-PARTY-NOTICES/libc-0.2.190/LICENSE-MIT +25 -0
  79. data/THIRD-PARTY-NOTICES/linux-raw-sys-0.12.1/COPYRIGHT +29 -0
  80. data/THIRD-PARTY-NOTICES/linux-raw-sys-0.12.1/LICENSE-APACHE +201 -0
  81. data/THIRD-PARTY-NOTICES/linux-raw-sys-0.12.1/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  82. data/THIRD-PARTY-NOTICES/linux-raw-sys-0.12.1/LICENSE-MIT +23 -0
  83. data/THIRD-PARTY-NOTICES/log-0.4.34/LICENSE-APACHE +201 -0
  84. data/THIRD-PARTY-NOTICES/log-0.4.34/LICENSE-MIT +25 -0
  85. data/THIRD-PARTY-NOTICES/memchr-2.8.3/COPYING +3 -0
  86. data/THIRD-PARTY-NOTICES/memchr-2.8.3/LICENSE-MIT +21 -0
  87. data/THIRD-PARTY-NOTICES/nix-0.27.1/LICENSE +21 -0
  88. data/THIRD-PARTY-NOTICES/nix-0.31.3/LICENSE +21 -0
  89. data/THIRD-PARTY-NOTICES/once_cell-1.21.4/LICENSE-APACHE +201 -0
  90. data/THIRD-PARTY-NOTICES/once_cell-1.21.4/LICENSE-MIT +23 -0
  91. data/THIRD-PARTY-NOTICES/openssl-probe-0.2.1/LICENSE-APACHE +201 -0
  92. data/THIRD-PARTY-NOTICES/openssl-probe-0.2.1/LICENSE-MIT +25 -0
  93. data/THIRD-PARTY-NOTICES/percent-encoding-2.3.2/LICENSE-APACHE +201 -0
  94. data/THIRD-PARTY-NOTICES/percent-encoding-2.3.2/LICENSE-MIT +25 -0
  95. data/THIRD-PARTY-NOTICES/quick-xml-0.41.0/LICENSE-MIT.md +23 -0
  96. data/THIRD-PARTY-NOTICES/ref-cast-1.0.27/LICENSE-APACHE +176 -0
  97. data/THIRD-PARTY-NOTICES/ref-cast-1.0.27/LICENSE-MIT +23 -0
  98. data/THIRD-PARTY-NOTICES/ring-0.17.14/LICENSE +9 -0
  99. data/THIRD-PARTY-NOTICES/ring-0.17.14/LICENSE-BoringSSL +272 -0
  100. data/THIRD-PARTY-NOTICES/ring-0.17.14/LICENSE-other-bits +13 -0
  101. data/THIRD-PARTY-NOTICES/ring-0.17.14/src/polyfill/once_cell/LICENSE-APACHE +201 -0
  102. data/THIRD-PARTY-NOTICES/ring-0.17.14/src/polyfill/once_cell/LICENSE-MIT +23 -0
  103. data/THIRD-PARTY-NOTICES/ring-0.17.14/third_party/fiat/LICENSE +15 -0
  104. data/THIRD-PARTY-NOTICES/roff-1.1.1/LICENSE-APACHE +202 -0
  105. data/THIRD-PARTY-NOTICES/roff-1.1.1/LICENSE-MIT +19 -0
  106. data/THIRD-PARTY-NOTICES/rustix-1.1.5/COPYRIGHT +29 -0
  107. data/THIRD-PARTY-NOTICES/rustix-1.1.5/LICENSE-APACHE +201 -0
  108. data/THIRD-PARTY-NOTICES/rustix-1.1.5/LICENSE-Apache-2.0_WITH_LLVM-exception +220 -0
  109. data/THIRD-PARTY-NOTICES/rustix-1.1.5/LICENSE-MIT +23 -0
  110. data/THIRD-PARTY-NOTICES/rustls-0.23.46/LICENSE-APACHE +201 -0
  111. data/THIRD-PARTY-NOTICES/rustls-0.23.46/LICENSE-ISC +15 -0
  112. data/THIRD-PARTY-NOTICES/rustls-0.23.46/LICENSE-MIT +25 -0
  113. data/THIRD-PARTY-NOTICES/rustls-native-certs-0.8.5/LICENSE +10 -0
  114. data/THIRD-PARTY-NOTICES/rustls-native-certs-0.8.5/LICENSE-APACHE +201 -0
  115. data/THIRD-PARTY-NOTICES/rustls-native-certs-0.8.5/LICENSE-ISC +15 -0
  116. data/THIRD-PARTY-NOTICES/rustls-native-certs-0.8.5/LICENSE-MIT +25 -0
  117. data/THIRD-PARTY-NOTICES/rustls-pki-types-1.15.1/LICENSE-APACHE +201 -0
  118. data/THIRD-PARTY-NOTICES/rustls-pki-types-1.15.1/LICENSE-MIT +25 -0
  119. data/THIRD-PARTY-NOTICES/rustls-platform-verifier-0.7.1/LICENSE-APACHE +201 -0
  120. data/THIRD-PARTY-NOTICES/rustls-platform-verifier-0.7.1/LICENSE-MIT +21 -0
  121. data/THIRD-PARTY-NOTICES/rustls-webpki-0.103.16/LICENSE +19 -0
  122. data/THIRD-PARTY-NOTICES/schemars-1.2.3/LICENSE +21 -0
  123. data/THIRD-PARTY-NOTICES/serde-1.0.229/LICENSE-APACHE +176 -0
  124. data/THIRD-PARTY-NOTICES/serde-1.0.229/LICENSE-MIT +23 -0
  125. data/THIRD-PARTY-NOTICES/serde_core-1.0.229/LICENSE-APACHE +176 -0
  126. data/THIRD-PARTY-NOTICES/serde_core-1.0.229/LICENSE-MIT +23 -0
  127. data/THIRD-PARTY-NOTICES/serde_json-1.0.151/LICENSE-APACHE +176 -0
  128. data/THIRD-PARTY-NOTICES/serde_json-1.0.151/LICENSE-MIT +23 -0
  129. data/THIRD-PARTY-NOTICES/sha2-0.10.9/LICENSE-APACHE +201 -0
  130. data/THIRD-PARTY-NOTICES/sha2-0.10.9/LICENSE-MIT +27 -0
  131. data/THIRD-PARTY-NOTICES/strsim-0.11.1/LICENSE +23 -0
  132. data/THIRD-PARTY-NOTICES/subtle-2.6.1/LICENSE +29 -0
  133. data/THIRD-PARTY-NOTICES/tempfile-3.23.0/LICENSE-APACHE +201 -0
  134. data/THIRD-PARTY-NOTICES/tempfile-3.23.0/LICENSE-MIT +25 -0
  135. data/THIRD-PARTY-NOTICES/thiserror-2.0.21/LICENSE-APACHE +176 -0
  136. data/THIRD-PARTY-NOTICES/thiserror-2.0.21/LICENSE-MIT +23 -0
  137. data/THIRD-PARTY-NOTICES/tinyvec-1.13.3/LICENSE-APACHE.md +202 -0
  138. data/THIRD-PARTY-NOTICES/tinyvec-1.13.3/LICENSE-MIT.md +5 -0
  139. data/THIRD-PARTY-NOTICES/tinyvec-1.13.3/LICENSE-ZLIB.md +11 -0
  140. data/THIRD-PARTY-NOTICES/typed-path-0.13.0/LICENSE-APACHE +176 -0
  141. data/THIRD-PARTY-NOTICES/typed-path-0.13.0/LICENSE-MIT +23 -0
  142. data/THIRD-PARTY-NOTICES/typenum-1.20.1/LICENSE +1 -0
  143. data/THIRD-PARTY-NOTICES/typenum-1.20.1/LICENSE-APACHE +201 -0
  144. data/THIRD-PARTY-NOTICES/typenum-1.20.1/LICENSE-MIT +21 -0
  145. data/THIRD-PARTY-NOTICES/unicode-general-category-1.1.0/LICENSE +201 -0
  146. data/THIRD-PARTY-NOTICES/unicode-normalization-0.1.26/COPYRIGHT +7 -0
  147. data/THIRD-PARTY-NOTICES/unicode-normalization-0.1.26/LICENSE-APACHE +201 -0
  148. data/THIRD-PARTY-NOTICES/unicode-normalization-0.1.26/LICENSE-MIT +25 -0
  149. data/THIRD-PARTY-NOTICES/unicode-normalization-0.1.26/LICENSE-UNICODE +39 -0
  150. data/THIRD-PARTY-NOTICES/untrusted-0.9.0/LICENSE.txt +13 -0
  151. data/THIRD-PARTY-NOTICES/ureq-3.4.2/LICENSE-APACHE +201 -0
  152. data/THIRD-PARTY-NOTICES/ureq-3.4.2/LICENSE-MIT +21 -0
  153. data/THIRD-PARTY-NOTICES/ureq-proto-0.6.4/LICENSE-APACHE.txt +202 -0
  154. data/THIRD-PARTY-NOTICES/ureq-proto-0.6.4/LICENSE-MIT.txt +7 -0
  155. data/THIRD-PARTY-NOTICES/utf8-zero-0.8.1/LICENSE-APACHE +176 -0
  156. data/THIRD-PARTY-NOTICES/utf8-zero-0.8.1/LICENSE-MIT +23 -0
  157. data/THIRD-PARTY-NOTICES/utf8parse-0.2.2/LICENSE-APACHE +176 -0
  158. data/THIRD-PARTY-NOTICES/utf8parse-0.2.2/LICENSE-MIT +25 -0
  159. data/THIRD-PARTY-NOTICES/zeroize-1.9.0/LICENSE-APACHE +202 -0
  160. data/THIRD-PARTY-NOTICES/zeroize-1.9.0/LICENSE-MIT +25 -0
  161. data/THIRD-PARTY-NOTICES/zip-9.1.2/LICENSE +21 -0
  162. data/THIRD-PARTY-NOTICES/zlib-rs-0.6.8/LICENSE +19 -0
  163. data/THIRD-PARTY-NOTICES/zmij-1.0.23/LICENSE-MIT +23 -0
  164. data/lib/thinkthen/call_owner.rb +68 -0
  165. data/lib/thinkthen/client.rb +293 -0
  166. data/lib/thinkthen/configuration.rb +76 -0
  167. data/lib/thinkthen/contract.rb +89 -0
  168. data/lib/thinkthen/libthinkthen_ffi.so +0 -0
  169. data/lib/thinkthen/native.rb +350 -0
  170. data/lib/thinkthen/native_allocator.rb +35 -0
  171. data/lib/thinkthen/native_reader.rb +87 -0
  172. data/lib/thinkthen/questions.rb +184 -0
  173. data/lib/thinkthen/row.rb +173 -0
  174. data/lib/thinkthen/rows.rb +199 -0
  175. data/lib/thinkthen/values.rb +111 -0
  176. data/lib/thinkthen/version.rb +3 -1
  177. data/lib/thinkthen.rb +79 -699
  178. data/sig/error_codes.rbs +3 -0
  179. data/sig/internal.rbs +277 -0
  180. data/sig/thinkthen.rbs +440 -0
  181. metadata +207 -13
  182. data/lib/thinkthen/thinkthen.so +0 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,25 @@
1
+ Copyright (c) 2018-2026 The RustCrypto Project Developers
2
+
3
+ Permission is hereby granted, free of charge, to any
4
+ person obtaining a copy of this software and associated
5
+ documentation files (the "Software"), to deal in the
6
+ Software without restriction, including without
7
+ limitation the rights to use, copy, modify, merge,
8
+ publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software
10
+ is furnished to do so, subject to the following
11
+ conditions:
12
+
13
+ The above copyright notice and this permission notice
14
+ shall be included in all copies or substantial portions
15
+ of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
18
+ ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
19
+ TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
20
+ PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
21
+ SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
24
+ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25
+ DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Mathijs van de Nes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,19 @@
1
+ (C) 2024 Trifecta Tech Foundation
2
+
3
+ This software is provided 'as-is', without any express or implied
4
+ warranty. In no event will the authors be held liable for any damages
5
+ arising from the use of this software.
6
+
7
+ Permission is granted to anyone to use this software for any purpose,
8
+ including commercial applications, and to alter it and redistribute it
9
+ freely, subject to the following restrictions:
10
+
11
+ 1. The origin of this software must not be misrepresented; you must not
12
+ claim that you wrote the original software. If you use this software
13
+ in a product, an acknowledgment in the product documentation would be
14
+ appreciated but is not required.
15
+
16
+ 2. Altered source versions must be plainly marked as such, and must not be
17
+ misrepresented as being the original software.
18
+
19
+ 3. This notice may not be removed or altered from any source distribution.
@@ -0,0 +1,23 @@
1
+ Permission is hereby granted, free of charge, to any
2
+ person obtaining a copy of this software and associated
3
+ documentation files (the "Software"), to deal in the
4
+ Software without restriction, including without
5
+ limitation the rights to use, copy, modify, merge,
6
+ publish, distribute, sublicense, and/or sell copies of
7
+ the Software, and to permit persons to whom the Software
8
+ is furnished to do so, subject to the following
9
+ conditions:
10
+
11
+ The above copyright notice and this permission notice
12
+ shall be included in all copies or substantial portions
13
+ of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
16
+ ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17
+ TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
18
+ PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
19
+ SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
22
+ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
+ DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ThinkThen
4
+ # The owner pins a call across every FFI operation. Only cancellation may
5
+ # enter concurrently; close waits for an active host operation before free.
6
+ class CallOwner
7
+ def initialize(pointer)
8
+ @pid = Process.pid
9
+ @pointer = Native::CallPointer.new(pointer)
10
+ @mutex = Mutex.new
11
+ @idle = ConditionVariable.new
12
+ @active = false
13
+ @closing = false
14
+ end
15
+
16
+ def use
17
+ check_process
18
+ @mutex.synchronize do
19
+ raise UsageError.new("call is closed", code: :"usage.closed") if @closing || !@pointer
20
+ raise ThreadError, "call already has an active driver" if @active
21
+ @active = true
22
+ end
23
+ begin
24
+ yield @pointer
25
+ ensure
26
+ @mutex.synchronize do
27
+ @active = false
28
+ @idle.broadcast
29
+ end
30
+ end
31
+ end
32
+
33
+ def cancel
34
+ check_process
35
+ @mutex.synchronize { Native.thinkthen_call_cancel(@pointer) if @pointer }
36
+ nil
37
+ end
38
+
39
+ def close
40
+ check_process
41
+ Thread.handle_interrupt(Object => :never) do
42
+ @mutex.synchronize do
43
+ return if !@pointer
44
+ @closing = true
45
+ Native.thinkthen_call_cancel(@pointer)
46
+ @idle.wait(@mutex) while @active
47
+ return unless @pointer
48
+ @pointer.free
49
+ @pointer = nil
50
+ end
51
+ end
52
+ nil
53
+ end
54
+
55
+ private
56
+
57
+ def check_process
58
+ raise IOError, "call belongs to another process; create a client after fork" unless @pid == Process.pid
59
+ end
60
+
61
+ public
62
+
63
+ def closed?
64
+ @mutex.synchronize { !@pointer }
65
+ end
66
+ end
67
+ private_constant :CallOwner
68
+ end
@@ -0,0 +1,293 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ThinkThen
4
+ class Client
5
+ # Open a client. A block closes it reliably and returns the block result.
6
+ def self.open(**settings)
7
+ client = new(**settings)
8
+ return client unless block_given?
9
+ begin
10
+ yield client
11
+ ensure
12
+ client.close
13
+ end
14
+ end
15
+ # Open the native engine with optional backend settings and a RetryPolicy policy.
16
+ def initialize(backend: nil, model: nil, url: nil, api_key: nil, batch: nil, max_requests: nil, retry: nil)
17
+ @mutex, @streams = Mutex.new, []
18
+ @pid = Process.pid
19
+ ThinkThen.send(:native)
20
+ key = api_key.nil? || api_key.is_a?(RedactedKey) ? api_key : RedactedKey.new(api_key)
21
+ @api_key = key
22
+ policy = binding.local_variable_get(:retry)
23
+ raise UsageError.new("retry must be a RetryPolicy", code: :"usage.settings") unless policy.nil? || policy.is_a?(RetryPolicy)
24
+ raise UsageError.new("backend must be a Symbol", code: :"usage.backend") unless backend.nil? || backend.is_a?(Symbol)
25
+ raw_settings = {backend: backend, model: model, url: url, batch: batch, max_requests: max_requests, retry: policy&.to_h}.reject { |_, value| value.nil? }
26
+ output = FFI::MemoryPointer.new(:pointer)
27
+ Native.bytes(Native.context_dump(raw_settings, :settings)) do |bytes, length|
28
+ Native.checked { |error| Native.thinkthen_settings_from_json(bytes, length, output, error) }
29
+ end
30
+ settings = Native::SettingsPointer.new(output.read_pointer)
31
+ key&.send(:copy_to, settings)
32
+ Thread.handle_interrupt(Object => :never) do
33
+ output = FFI::MemoryPointer.new(:pointer)
34
+ Native.checked { |error| Native.thinkthen_client_open(settings, output, error) }
35
+ @pointer = Native::ClientPointer.new(output.read_pointer)
36
+ end
37
+ ensure
38
+ settings&.free
39
+ end
40
+ # The redacted key wrapper; its display never reveals the key.
41
+ attr_reader :api_key
42
+ def inspect = "#<ThinkThen::Client closed=#{closed?}>"
43
+ alias to_s inspect
44
+ # Close active calls and release this client. Repeated close calls are safe.
45
+ def close
46
+ check_process
47
+ streams = @mutex.synchronize do
48
+ @closed = true
49
+ @streams.filter_map { |reference| reference.__getobj__ if reference.weakref_alive? }
50
+ end
51
+ streams.each(&:close)
52
+ Thread.handle_interrupt(Object => :never) do
53
+ @mutex.synchronize do
54
+ if @pointer
55
+ @usage = Native.usage(@pointer, settled: true)
56
+ @pointer.free
57
+ @pointer = nil
58
+ end
59
+ end
60
+ end
61
+ nil
62
+ end
63
+ # Cumulative usage; after close returns the copied settled snapshot.
64
+ def usage
65
+ check_process
66
+ @mutex.synchronize { @pointer ? Native.usage(@pointer) : @usage }
67
+ end
68
+ # Whether this client has released its native engine.
69
+ def closed? = @mutex.synchronize { @closed || !@pointer }
70
+ # Return a boolean answer row with its probability. A collection belongs in decide_each.
71
+ def decide(question, record, threshold: UNSET, field: UNSET, name: nil, cancel: nil, yes_means: UNSET, no_means: UNSET)
72
+ question = build_question(:decide, question, {yes_means: yes_means, no_means: no_means, threshold: threshold, field: field})
73
+ stream = open_rows(question, single_record(record, :decide), name, cancel)
74
+ single_result(stream)
75
+ end
76
+ # Yield one decide row per input. Without a block, return a closable Rows enumerator.
77
+ def decide_each(question, records, threshold: UNSET, field: UNSET, name: nil, cancel: nil, yes_means: UNSET, no_means: UNSET, &block)
78
+ question = build_question(:decide, question, {yes_means: yes_means, no_means: no_means, threshold: threshold, field: field})
79
+ stream = open_rows(question, records, name, cancel)
80
+ return stream unless block
81
+ stream.each(&block)
82
+ nil
83
+ end
84
+ # Return the selected label and its distribution. A collection belongs in choose_each.
85
+ def choose(question, record, choices: UNSET, threshold: UNSET, field: UNSET, name: nil, cancel: nil, descriptions: UNSET)
86
+ question = build_question(:choose, question, {descriptions: descriptions, choices: choices, threshold: threshold, field: field})
87
+ stream = open_rows(question, single_record(record, :choose), name, cancel)
88
+ single_result(stream)
89
+ end
90
+ # Yield one choose row per input. Without a block, return a closable Rows enumerator.
91
+ def choose_each(question, records, choices: UNSET, threshold: UNSET, field: UNSET, name: nil, cancel: nil, descriptions: UNSET, &block)
92
+ question = build_question(:choose, question, {descriptions: descriptions, choices: choices, threshold: threshold, field: field})
93
+ stream = open_rows(question, records, name, cancel)
94
+ return stream unless block
95
+ stream.each(&block)
96
+ nil
97
+ end
98
+ # Return the matching labels and their probabilities. A collection belongs in tag_each.
99
+ def tag(question, record, labels: UNSET, threshold: UNSET, field: UNSET, name: nil, cancel: nil, descriptions: UNSET)
100
+ question = build_question(:tag, question, {descriptions: descriptions, labels: labels, threshold: threshold, field: field})
101
+ stream = open_rows(question, single_record(record, :tag), name, cancel)
102
+ single_result(stream)
103
+ end
104
+ # Yield one tag row per input. Without a block, return a closable Rows enumerator.
105
+ def tag_each(question, records, labels: UNSET, threshold: UNSET, field: UNSET, name: nil, cancel: nil, descriptions: UNSET, &block)
106
+ question = build_question(:tag, question, {descriptions: descriptions, labels: labels, threshold: threshold, field: field})
107
+ stream = open_rows(question, records, name, cancel)
108
+ return stream unless block
109
+ stream.each(&block)
110
+ nil
111
+ end
112
+ # Return a normalized score and its level probabilities. A collection belongs in score_each.
113
+ def score(question, record, levels: UNSET, field: UNSET, name: nil, cancel: nil, descriptions: UNSET)
114
+ question = build_question(:score, question, {descriptions: descriptions, levels: levels, field: field})
115
+ stream = open_rows(question, single_record(record, :score), name, cancel)
116
+ single_result(stream)
117
+ end
118
+ # Yield one score row per input. Without a block, return a closable Rows enumerator.
119
+ def score_each(question, records, levels: UNSET, field: UNSET, name: nil, cancel: nil, descriptions: UNSET, &block)
120
+ question = build_question(:score, question, {descriptions: descriptions, levels: levels, field: field})
121
+ stream = open_rows(question, records, name, cancel)
122
+ return stream unless block
123
+ stream.each(&block)
124
+ nil
125
+ end
126
+ # Yield only the original kept records, then raise once with failed results.
127
+ def filter(question, records, threshold: UNSET, field: UNSET, name: nil, cancel: nil, yes_means: UNSET, no_means: UNSET, &block)
128
+ question = build_question(:filter, question, {yes_means: yes_means, no_means: no_means, threshold: threshold, field: field})
129
+ stream = open_rows(question, records, name, cancel)
130
+ delivered = Enumerator.new do |output|
131
+ # @type var failed: Array[Result]
132
+ failed = []
133
+ begin
134
+ stream.each do |row|
135
+ if row.failed?
136
+ failed << row
137
+ elsif row.answer
138
+ output << row.item
139
+ end
140
+ end
141
+ unless failed.empty?
142
+ # Collected native failed outcomes always carry their error.
143
+ # @type var error: untyped
144
+ error = failed.first.error
145
+ raise FailedError.new(error.message, code: error.code, http_status: error.http_status, rows: failed)
146
+ end
147
+ ensure
148
+ stream.close
149
+ end
150
+ end
151
+ return delivered unless block
152
+ delivered.each(&block)
153
+ nil
154
+ end
155
+ # Yield ranked results, failed records last, retaining each caller-owned item.
156
+ def rank(question, records, levels: UNSET, top: UNSET, field: UNSET, name: nil, cancel: nil, descriptions: UNSET, &block)
157
+ question = build_question(:rank, question, {descriptions: descriptions, levels: levels, top: top, field: field})
158
+ stream = open_rows(question, records, name, cancel)
159
+ return stream unless block
160
+ stream.each(&block)
161
+ nil
162
+ end
163
+ # Return the matched span, or an answered nil when no span matches. A collection belongs in find_each.
164
+ def find(question, record, threshold: UNSET, field: UNSET, name: nil, cancel: nil)
165
+ question = build_question(:find, question, {threshold: threshold, field: field})
166
+ stream = open_rows(question, single_record(record, :find), name, cancel)
167
+ single_result(stream)
168
+ end
169
+ # Yield one find row per input. Without a block, return a closable Rows enumerator.
170
+ def find_each(question, records, threshold: UNSET, field: UNSET, name: nil, cancel: nil, &block)
171
+ question = build_question(:find, question, {threshold: threshold, field: field})
172
+ stream = open_rows(question, records, name, cancel)
173
+ return stream unless block
174
+ stream.each(&block)
175
+ nil
176
+ end
177
+ # Return recognized names with character offsets and probabilities. A collection belongs in recognize_each.
178
+ def recognize(record, kinds: UNSET, threshold: UNSET, field: UNSET, name: nil, cancel: nil)
179
+ question = build_question(:recognize, nil, {kinds: kinds, threshold: threshold, field: field})
180
+ stream = open_rows(question, single_record(record, :recognize), name, cancel)
181
+ single_result(stream)
182
+ end
183
+ def recognize_each(records, kinds: UNSET, threshold: UNSET, field: UNSET, name: nil, cancel: nil, &block)
184
+ question = build_question(:recognize, nil, {kinds: kinds, threshold: threshold, field: field})
185
+ stream = open_rows(question, records, name, cancel)
186
+ return stream unless block
187
+ stream.each(&block)
188
+ nil
189
+ end
190
+ def relate(record, rules: UNSET, threshold: UNSET, field: UNSET, name: nil, cancel: nil)
191
+ question = build_question(:relate, nil, {rules: rules, threshold: threshold, field: field})
192
+ stream = open_rows(question, single_record(record, :relate), name, cancel)
193
+ single_result(stream)
194
+ end
195
+ def relate_each(records, rules: UNSET, threshold: UNSET, field: UNSET, name: nil, cancel: nil, &block)
196
+ question = build_question(:relate, nil, {rules: rules, threshold: threshold, field: field})
197
+ stream = open_rows(question, records, name, cancel)
198
+ return stream unless block
199
+ stream.each(&block)
200
+ nil
201
+ end
202
+ # Return named child answer rows for the supplied questions. A collection belongs in annotate_each.
203
+ def annotate(question, record, field: UNSET, name: nil, cancel: nil)
204
+ question = build_question(:annotate, question, {field: field})
205
+ stream = open_rows(question, single_record(record, :annotate), name, cancel)
206
+ single_result(stream)
207
+ end
208
+ # Yield one annotate row per input. Without a block, return a closable Rows enumerator.
209
+ def annotate_each(question, records, field: UNSET, name: nil, cancel: nil, &block)
210
+ question = build_question(:annotate, question, {field: field})
211
+ stream = open_rows(question, records, name, cancel)
212
+ return stream unless block
213
+ stream.each(&block)
214
+ nil
215
+ end
216
+ private
217
+ def single_result(stream)
218
+ row = stream.next
219
+ if row.failed?
220
+ error = row.error
221
+ raise FailedError.new(error.message, code: error.code, http_status: error.http_status, rows: [row])
222
+ end
223
+ row
224
+ ensure
225
+ stream.close
226
+ end
227
+ def single_record(record, function)
228
+ if record.is_a?(Array) || record.respond_to?(:each) && !record.is_a?(Hash) && !record.is_a?(String) && !record.respond_to?(:to_h)
229
+ raise UsageError.new("a single call does not accept a collection; use #{function}_each", code: :"usage.argument")
230
+ end
231
+ [record]
232
+ end
233
+ def check_process
234
+ raise IOError, "client belongs to another process; create a client after fork" unless @pid == Process.pid
235
+ end
236
+ def build_question(function, question, options)
237
+ check_process
238
+ # @type var klass: untyped
239
+ klass = ThinkThen.const_get("#{function.to_s.capitalize}Question")
240
+ # @type var options: Hash[Symbol, untyped]
241
+ options = options.reject { |_, value| value.equal?(UNSET) }
242
+ if question.is_a?(Question)
243
+ raise UsageError.new("question does not match function", code: :"usage.argument") unless question.is_a?(klass)
244
+ raise UsageError.new("saved question owns its options", code: :"usage.argument") unless options.empty?
245
+ question
246
+ elsif function == :annotate
247
+ klass.new(question, **options)
248
+ elsif [:recognize, :relate].include?(function)
249
+ klass.new(**options)
250
+ else
251
+ klass.new(question, **options)
252
+ end
253
+ end
254
+ def open_rows(question, records, name, cancel)
255
+ raise UsageError.new("records must be an Enumerable; use the single-record method for text", code: :"usage.argument") unless records.respond_to?(:each) && !records.is_a?(Hash)
256
+ raise UsageError.new("name must be a String", code: :"usage.name") unless name.nil? || name.is_a?(String)
257
+ raise UsageError.new("cancel must be a Cancel", code: :"usage.argument") unless cancel.nil? || cancel.is_a?(Cancel)
258
+ request = Native.context_dump({question: question.value, **(name.nil? ? {} : {name: name})}, :question)
259
+ stream = Rows.new(self, request, records, cancel, question)
260
+ @mutex.synchronize do
261
+ raise UsageError.new("client is closed", code: :"usage.closed") if @closed || !@pointer
262
+ @streams.reject! { |reference| !reference.weakref_alive? }
263
+ @streams << WeakRef.new(stream)
264
+ end
265
+ stream
266
+ rescue Exception
267
+ stream&.close
268
+ raise
269
+ end
270
+ def admit(request, records = nil)
271
+ @mutex.synchronize do
272
+ raise UsageError.new("client is closed", code: :"usage.closed") if @closed || !@pointer
273
+ Native.bytes(request) do |bytes, length|
274
+ output = FFI::MemoryPointer.new(:pointer)
275
+ if records
276
+ Native.records(records) do |input, count|
277
+ Native.checked do |error|
278
+ Native.thinkthen_call_open_records_json(@pointer, bytes, length, input, count, Native::RecordInput.size,
279
+ NativeContract::OFFSET_NAMES.key("code_points"), output, error)
280
+ end
281
+ end
282
+ else
283
+ Native.checked do |error|
284
+ Native.thinkthen_call_open_json(@pointer, bytes, length, NativeContract::OFFSET_NAMES.key("code_points"), output, error)
285
+ end
286
+ end
287
+ output.read_pointer
288
+ end
289
+ end
290
+ end
291
+ def forget(stream) = @mutex.synchronize { @streams.reject! { |reference| !reference.weakref_alive? || reference.__getobj__.equal?(stream) } }
292
+ end
293
+ end