@harny/sdk 0.0.1-alpha.1 → 0.1.0
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.
- package/LICENSE +202 -0
- package/README.md +54 -42
- package/dist/cjs/agent/adapters.d.ts +167 -0
- package/dist/cjs/agent/adapters.js +557 -0
- package/dist/cjs/agent/adapters.js.map +1 -0
- package/dist/cjs/agent/hooks.d.ts +52 -0
- package/dist/cjs/agent/hooks.js +41 -0
- package/dist/cjs/agent/hooks.js.map +1 -0
- package/dist/cjs/agent/index.d.ts +34 -0
- package/dist/cjs/agent/index.js +62 -0
- package/dist/cjs/agent/index.js.map +1 -0
- package/dist/cjs/agent/loop.d.ts +401 -0
- package/dist/cjs/agent/loop.js +1252 -0
- package/dist/cjs/agent/loop.js.map +1 -0
- package/dist/cjs/agent/roster.d.ts +62 -0
- package/dist/cjs/agent/roster.js +149 -0
- package/dist/cjs/agent/roster.js.map +1 -0
- package/dist/cjs/agent/session.d.ts +106 -0
- package/dist/cjs/agent/session.js +261 -0
- package/dist/cjs/agent/session.js.map +1 -0
- package/dist/cjs/agent/spend.d.ts +39 -0
- package/dist/cjs/agent/spend.js +70 -0
- package/dist/cjs/agent/spend.js.map +1 -0
- package/dist/cjs/agent/tools.d.ts +83 -0
- package/dist/cjs/agent/tools.js +212 -0
- package/dist/cjs/agent/tools.js.map +1 -0
- package/dist/cjs/agent/tracing.d.ts +72 -0
- package/dist/cjs/agent/tracing.js +128 -0
- package/dist/cjs/agent/tracing.js.map +1 -0
- package/dist/cjs/agent/util.d.ts +60 -0
- package/dist/cjs/agent/util.js +188 -0
- package/dist/cjs/agent/util.js.map +1 -0
- package/dist/cjs/conflictQuestion.d.ts +137 -0
- package/dist/cjs/conflictQuestion.js +356 -0
- package/dist/cjs/conflictQuestion.js.map +1 -0
- package/dist/cjs/index.d.ts +950 -0
- package/dist/cjs/index.js +1118 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/memoryV1.d.ts +121 -0
- package/dist/cjs/memoryV1.js +132 -0
- package/dist/cjs/memoryV1.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/agent/adapters.d.ts +167 -0
- package/dist/esm/agent/adapters.js +543 -0
- package/dist/esm/agent/adapters.js.map +1 -0
- package/dist/esm/agent/hooks.d.ts +52 -0
- package/dist/esm/agent/hooks.js +36 -0
- package/dist/esm/agent/hooks.js.map +1 -0
- package/dist/esm/agent/index.d.ts +34 -0
- package/dist/esm/agent/index.js +28 -0
- package/dist/esm/agent/index.js.map +1 -0
- package/dist/esm/agent/loop.d.ts +401 -0
- package/dist/esm/agent/loop.js +1243 -0
- package/dist/esm/agent/loop.js.map +1 -0
- package/dist/esm/agent/roster.d.ts +62 -0
- package/dist/esm/agent/roster.js +143 -0
- package/dist/esm/agent/roster.js.map +1 -0
- package/dist/esm/agent/session.d.ts +106 -0
- package/dist/esm/agent/session.js +221 -0
- package/dist/esm/agent/session.js.map +1 -0
- package/dist/esm/agent/spend.d.ts +39 -0
- package/dist/esm/agent/spend.js +65 -0
- package/dist/esm/agent/spend.js.map +1 -0
- package/dist/esm/agent/tools.d.ts +83 -0
- package/dist/esm/agent/tools.js +205 -0
- package/dist/esm/agent/tools.js.map +1 -0
- package/dist/esm/agent/tracing.d.ts +72 -0
- package/dist/esm/agent/tracing.js +119 -0
- package/dist/esm/agent/tracing.js.map +1 -0
- package/dist/esm/agent/util.d.ts +60 -0
- package/dist/esm/agent/util.js +168 -0
- package/dist/esm/agent/util.js.map +1 -0
- package/dist/esm/conflictQuestion.d.ts +137 -0
- package/dist/esm/conflictQuestion.js +346 -0
- package/dist/esm/conflictQuestion.js.map +1 -0
- package/dist/esm/index.d.ts +950 -0
- package/dist/esm/index.js +1066 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/memoryV1.d.ts +121 -0
- package/dist/esm/memoryV1.js +124 -0
- package/dist/esm/memoryV1.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/package.json +41 -15
- package/index.js +0 -270
package/LICENSE
ADDED
|
@@ -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.
|
package/README.md
CHANGED
|
@@ -1,63 +1,75 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Harny TypeScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Harny gives each person your app's AI serves a private memory that keeps up when facts change. This package is the TypeScript client for Node: ingest timestamped text, check its status, delete it when required, and recall current facts with evidence.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
#1 on BEAM at 128K tokens, the public benchmark for long-term memory in agents. [Results and methodology](https://harny.ai/benchmarks)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Documentation: [Quickstart](https://harny.ai/docs/memory-api/quickstart) · [Memory API overview](https://harny.ai/docs/memory-api/overview)
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```
|
|
8
12
|
npm install @harny/sdk
|
|
9
13
|
```
|
|
10
14
|
|
|
11
|
-
|
|
15
|
+
Requires Node.js 20+.
|
|
16
|
+
|
|
17
|
+
## Key
|
|
12
18
|
|
|
13
|
-
|
|
14
|
-
const harny = require("@harny/sdk");
|
|
19
|
+
Sign up at [console.harny.ai](https://console.harny.ai/signup) and create an app key. Keep it on the server as `HARNY_API_KEY` and pass it to the client as `apiKey`.
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
const result = harny.vibeCheck();
|
|
18
|
-
harny.print(result);
|
|
21
|
+
## Quickstart
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
prompt: "Explain quantum computing using interpretive dance metaphors",
|
|
23
|
-
reasoning: "Let me think step by step about how qubits are like dancers...",
|
|
24
|
-
result: "Imagine each qubit as a dancer spinning in superposition..."
|
|
25
|
-
});
|
|
23
|
+
```typescript
|
|
24
|
+
import { HarnyClient } from "@harny/sdk";
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
const harny = new HarnyClient({ apiKey: process.env.HARNY_API_KEY });
|
|
27
|
+
await harny.provisionUser("demo-user", "demo@example.com"); // add each person once; repeating it is safe
|
|
28
|
+
const receipt = await harny.ingestDataPoint(
|
|
29
|
+
{ content: "Budget for the Acme pilot moved to 40k.", timestamp: "2026-07-28T16:00:00Z" },
|
|
30
|
+
{ user: "demo-user" },
|
|
31
|
+
);
|
|
32
|
+
await harny.waitForIngestion(receipt.ingestionId, { user: "demo-user" });
|
|
33
|
+
const page = await harny.recall("What is the Acme pilot budget?", { user: "demo-user" });
|
|
34
|
+
console.log(page.results[0].content);
|
|
30
35
|
```
|
|
31
36
|
|
|
32
|
-
|
|
37
|
+
`user` names the person; each recall returns that person's memory and nothing from anyone else's.
|
|
33
38
|
|
|
34
|
-
|
|
39
|
+
## Methods
|
|
35
40
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
- `ingestDataPoint(point, { user?, idempotencyKey? })` — send one fact with the time it happened: `{ content, id?, label?, timestamp?, metadata?, audience? }`. Returns `{ ingestionId, sourceId, status }`. The same `id` with changed content replaces the old memory.
|
|
42
|
+
- `ingestBatch(items, { user?, idempotencyKey? })` — send 1 to 1,000 facts at once.
|
|
43
|
+
- `getIngestion(id, { user? })` / `waitForIngestion(id, { user?, timeoutMs?, pollMs? })` — `processing`, `completed` or `failed`. `nothingNew` is true when the send added nothing new.
|
|
44
|
+
- `recall(query, { user?, level?, maxTokens?, limit?, sort?, queryTimestamp?, occurredFrom?, occurredTo? })` — ranked, dated facts for a question. `level` is `low`, `medium`, `high` or `extra-high`; `maxTokens` sets a ceiling instead. The response carries `results`, `asOf` and `usedEvidenceTokens`.
|
|
45
|
+
- `deleteDataPoint(sourceId)`, `deleteDataPoints(ids)`, `deleteIngestion(id)` — remove a fact, or a whole send, and the memories that rest only on it.
|
|
46
|
+
- `getUsage()` — this month's usage for the app.
|
|
41
47
|
|
|
42
|
-
|
|
48
|
+
For agents, the client also has `provisionUser`, `assembleContext` and an `Agent` loop. See the [agent harness overview](https://harny.ai/docs/agent-harness/overview).
|
|
49
|
+
|
|
50
|
+
## Errors
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { HarnyError } from "@harny/sdk";
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
await harny.recall("What is the Acme pilot budget?", { user: "demo-user" });
|
|
57
|
+
} catch (err) {
|
|
58
|
+
if (err instanceof HarnyError) {
|
|
59
|
+
console.log(err.statusCode, err.errorCode, err.recoveryHint, err.retryAfterS);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
43
63
|
|
|
44
|
-
|
|
45
|
-
|-------|---------|
|
|
46
|
-
| 1–15 | Completely Unharny |
|
|
47
|
-
| 16–25 | Mildly Stale |
|
|
48
|
-
| 26–35 | Room Temperature |
|
|
49
|
-
| 36–45 | Slightly Prompted |
|
|
50
|
-
| 46–55 | Moderately Harny |
|
|
51
|
-
| 56–65 | Respectably Harny |
|
|
52
|
-
| 66–75 | Dangerously Harny |
|
|
53
|
-
| 76–85 | Weapons-Grade Harny |
|
|
54
|
-
| 86–95 | Catastrophically Harny |
|
|
55
|
-
| 96–100 | Beyond Harny — Transcendent |
|
|
64
|
+
`statusCode` is 0 when nothing reached Harny (timeout or network); every other value is the HTTP status.
|
|
56
65
|
|
|
57
|
-
##
|
|
66
|
+
## Where next
|
|
58
67
|
|
|
59
|
-
- [
|
|
68
|
+
- [Quickstart](https://harny.ai/docs/memory-api/quickstart) in cURL, Python and TypeScript
|
|
69
|
+
- [Memory API overview](https://harny.ai/docs/memory-api/overview)
|
|
70
|
+
- [MCP server](https://harny.ai/docs/mcp/overview) for Claude, Cursor, VS Code and other MCP clients
|
|
71
|
+
- [support@harny.ai](mailto:support@harny.ai)
|
|
60
72
|
|
|
61
73
|
## License
|
|
62
74
|
|
|
63
|
-
|
|
75
|
+
Apache-2.0.
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model adapters: three wire styles, configured entirely from a roster entry.
|
|
3
|
+
*
|
|
4
|
+
* The loop speaks one neutral shape (messages, tool specs, tool calls). An
|
|
5
|
+
* adapter translates it to one wire style and back:
|
|
6
|
+
*
|
|
7
|
+
* - `chat_completions`: the widely shared chat-completions request shape.
|
|
8
|
+
* - `messages`: the messages request shape with content blocks.
|
|
9
|
+
* - `generate_content`: the generate-content shape with function declarations.
|
|
10
|
+
*
|
|
11
|
+
* Which provider speaks which style, the base URL, the auth header, any fixed
|
|
12
|
+
* headers and any extra request-body fields (a pin to one host on a provider
|
|
13
|
+
* that routes to many) all come from the roster entry, so no provider or model
|
|
14
|
+
* name is written here and a new provider on an existing style is a roster edit.
|
|
15
|
+
*
|
|
16
|
+
* Within one run, the model's own assistant turns are replayed in the native
|
|
17
|
+
* form the provider returned (some providers require their reasoning or
|
|
18
|
+
* signature fields back on the next call), with one repair: a tool call whose
|
|
19
|
+
* arguments are not a JSON object is replayed with `{}` (the loop has already
|
|
20
|
+
* answered it as invalid), because some hosts refuse the whole request
|
|
21
|
+
* otherwise. Across runs the session store keeps plain text and action notes
|
|
22
|
+
* only, so a conversation survives a change of preset or provider.
|
|
23
|
+
*
|
|
24
|
+
* A model that thinks before it answers (`thinking_always_on` in its roster
|
|
25
|
+
* entry; the agent never switches thinking off) spends part of the answer
|
|
26
|
+
* limit thinking. Its adapter gives every call at least the entry's
|
|
27
|
+
* `answer_room_tokens`; only the tokens the model uses are billed, and the
|
|
28
|
+
* thinking itself is never capped. A turn the provider stopped at the limit,
|
|
29
|
+
* or before it finished for another documented reason, is marked `cutOff`.
|
|
30
|
+
*/
|
|
31
|
+
import type { ResolvedModel } from "./roster.js";
|
|
32
|
+
export interface ToolSpec {
|
|
33
|
+
readonly name: string;
|
|
34
|
+
readonly description: string;
|
|
35
|
+
readonly parameters: Record<string, unknown>;
|
|
36
|
+
}
|
|
37
|
+
export interface ToolCall {
|
|
38
|
+
readonly id: string;
|
|
39
|
+
readonly name: string;
|
|
40
|
+
/** `null` when the model's arguments were not a JSON object (see `parseError`). */
|
|
41
|
+
readonly arguments: Record<string, unknown> | null;
|
|
42
|
+
readonly parseError?: string | null;
|
|
43
|
+
}
|
|
44
|
+
export interface ToolResult {
|
|
45
|
+
readonly callId: string;
|
|
46
|
+
readonly name: string;
|
|
47
|
+
readonly content: string;
|
|
48
|
+
readonly isError?: boolean;
|
|
49
|
+
}
|
|
50
|
+
export declare class Usage {
|
|
51
|
+
inputTokens: number;
|
|
52
|
+
outputTokens: number;
|
|
53
|
+
constructor(inputTokens?: number, outputTokens?: number);
|
|
54
|
+
get totalTokens(): number;
|
|
55
|
+
add(other: Usage): void;
|
|
56
|
+
}
|
|
57
|
+
export type MessageRole = "user" | "assistant" | "tool_results";
|
|
58
|
+
/**
|
|
59
|
+
* One neutral message. `native` holds a provider's own assistant turn.
|
|
60
|
+
*
|
|
61
|
+
* A `tool_results` message may carry `text`: the loop's own words to the model
|
|
62
|
+
* after the results (the closing turn at the step limit), sent in the same
|
|
63
|
+
* turn as the results so user and model turns keep alternating.
|
|
64
|
+
*/
|
|
65
|
+
export declare class Message {
|
|
66
|
+
readonly role: MessageRole;
|
|
67
|
+
readonly text: string;
|
|
68
|
+
readonly toolCalls: ToolCall[];
|
|
69
|
+
readonly results: ToolResult[];
|
|
70
|
+
readonly native: unknown;
|
|
71
|
+
readonly nativeStyle: string | null;
|
|
72
|
+
constructor(init: {
|
|
73
|
+
role: MessageRole;
|
|
74
|
+
text?: string;
|
|
75
|
+
toolCalls?: ToolCall[];
|
|
76
|
+
results?: ToolResult[];
|
|
77
|
+
native?: unknown;
|
|
78
|
+
nativeStyle?: string | null;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
export declare class ModelTurn {
|
|
82
|
+
readonly text: string;
|
|
83
|
+
readonly toolCalls: ToolCall[];
|
|
84
|
+
readonly usage: Usage;
|
|
85
|
+
readonly stop: string;
|
|
86
|
+
readonly native: unknown;
|
|
87
|
+
constructor(text: string, toolCalls: ToolCall[], usage: Usage, stop: string, native?: unknown);
|
|
88
|
+
/** The provider stopped this turn before it finished: text and tool calls may be incomplete. */
|
|
89
|
+
get cutOff(): boolean;
|
|
90
|
+
/** Stopped at the answer limit (the common case of `cutOff`). */
|
|
91
|
+
get atAnswerLimit(): boolean;
|
|
92
|
+
}
|
|
93
|
+
/** The model provider refused or failed the call (after retries). */
|
|
94
|
+
export declare class ModelProviderError extends Error {
|
|
95
|
+
readonly statusCode: number | null;
|
|
96
|
+
constructor(message: string, statusCode?: number | null);
|
|
97
|
+
}
|
|
98
|
+
export interface CompleteRequest {
|
|
99
|
+
system: string;
|
|
100
|
+
messages: Message[];
|
|
101
|
+
tools: ToolSpec[];
|
|
102
|
+
maxOutputTokens: number;
|
|
103
|
+
/** Aborts the call (the run's time ran out). */
|
|
104
|
+
signal?: AbortSignal | null;
|
|
105
|
+
}
|
|
106
|
+
export interface ModelAdapter {
|
|
107
|
+
readonly provider: string;
|
|
108
|
+
readonly model: string;
|
|
109
|
+
readonly style: string;
|
|
110
|
+
complete(request: CompleteRequest): Promise<ModelTurn>;
|
|
111
|
+
}
|
|
112
|
+
export interface AdapterOptions {
|
|
113
|
+
/** A `fetch` to use instead of the global one (tests, proxies). */
|
|
114
|
+
fetch?: typeof fetch;
|
|
115
|
+
/** Per-call timeout. Default 60 seconds. */
|
|
116
|
+
timeoutMs?: number;
|
|
117
|
+
}
|
|
118
|
+
declare abstract class HttpAdapter implements ModelAdapter {
|
|
119
|
+
abstract readonly style: string;
|
|
120
|
+
readonly provider: string;
|
|
121
|
+
readonly model: string;
|
|
122
|
+
/** The answer limit a model that always thinks gets at least (`null`: no floor). */
|
|
123
|
+
readonly answerRoomTokens: number | null;
|
|
124
|
+
protected readonly base: string;
|
|
125
|
+
private readonly auth;
|
|
126
|
+
private readonly fixedHeaders;
|
|
127
|
+
protected readonly maxTokensParam: string;
|
|
128
|
+
private readonly extraBody;
|
|
129
|
+
private readonly fetchImpl;
|
|
130
|
+
private readonly timeoutMs;
|
|
131
|
+
constructor(resolved: ResolvedModel, options?: AdapterOptions);
|
|
132
|
+
/** The caller's limit, raised to the roster's answer room for a model that always thinks. */
|
|
133
|
+
protected answerLimit(requested: number): number;
|
|
134
|
+
/** The roster entry's extra fields, added where the adapter set nothing. */
|
|
135
|
+
protected withExtra(body: Record<string, unknown>): Record<string, unknown>;
|
|
136
|
+
private headers;
|
|
137
|
+
protected post(url: string, body: Record<string, unknown>, signal?: AbortSignal | null): Promise<Record<string, unknown>>;
|
|
138
|
+
abstract complete(request: CompleteRequest): Promise<ModelTurn>;
|
|
139
|
+
}
|
|
140
|
+
/** `[arguments, error]`: an object, or `null` with the reason it is not one. */
|
|
141
|
+
export declare function parseArguments(raw: unknown): [Record<string, unknown> | null, string | null];
|
|
142
|
+
/**
|
|
143
|
+
* The model's own turn, safe to send back: a tool call whose arguments are not
|
|
144
|
+
* a JSON object is replayed with `{}`. Valid arguments go back byte for byte;
|
|
145
|
+
* the stored turn is never changed.
|
|
146
|
+
*/
|
|
147
|
+
export declare function replayable(native: unknown): unknown;
|
|
148
|
+
export declare class ChatCompletionsAdapter extends HttpAdapter {
|
|
149
|
+
readonly style = "chat_completions";
|
|
150
|
+
private wireMessages;
|
|
151
|
+
complete(request: CompleteRequest): Promise<ModelTurn>;
|
|
152
|
+
}
|
|
153
|
+
export declare class MessagesAdapter extends HttpAdapter {
|
|
154
|
+
readonly style = "messages";
|
|
155
|
+
private wireMessages;
|
|
156
|
+
complete(request: CompleteRequest): Promise<ModelTurn>;
|
|
157
|
+
}
|
|
158
|
+
/** Reduce a JSON schema to the subset function declarations accept. */
|
|
159
|
+
export declare function declarationSchema(schema: unknown): unknown;
|
|
160
|
+
export declare class GenerateContentAdapter extends HttpAdapter {
|
|
161
|
+
readonly style = "generate_content";
|
|
162
|
+
private wireContents;
|
|
163
|
+
complete(request: CompleteRequest): Promise<ModelTurn>;
|
|
164
|
+
}
|
|
165
|
+
/** The adapter for a resolved roster entry's wire style. */
|
|
166
|
+
export declare function buildAdapter(resolved: ResolvedModel, options?: AdapterOptions): ModelAdapter;
|
|
167
|
+
export {};
|