@cerebro-labs/agentnava-sdk 0.26.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.
Files changed (67) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +12 -0
  3. package/README.md +230 -0
  4. package/agent.d.ts +285 -0
  5. package/agent.js +394 -0
  6. package/agent.js.map +1 -0
  7. package/attach.d.ts +49 -0
  8. package/attach.js +115 -0
  9. package/attach.js.map +1 -0
  10. package/connection-status.d.ts +28 -0
  11. package/connection-status.js +61 -0
  12. package/connection-status.js.map +1 -0
  13. package/connection.d.ts +89 -0
  14. package/connection.js +143 -0
  15. package/connection.js.map +1 -0
  16. package/conversation.d.ts +177 -0
  17. package/conversation.js +348 -0
  18. package/conversation.js.map +1 -0
  19. package/end-user.d.ts +159 -0
  20. package/end-user.js +209 -0
  21. package/end-user.js.map +1 -0
  22. package/errors.d.ts +43 -0
  23. package/errors.js +55 -0
  24. package/errors.js.map +1 -0
  25. package/http.d.ts +32 -0
  26. package/http.js +192 -0
  27. package/http.js.map +1 -0
  28. package/import-tools.d.ts +282 -0
  29. package/import-tools.js +686 -0
  30. package/import-tools.js.map +1 -0
  31. package/index.d.ts +16 -0
  32. package/index.js +38 -0
  33. package/index.js.map +1 -0
  34. package/knowledge-base.d.ts +165 -0
  35. package/knowledge-base.js +274 -0
  36. package/knowledge-base.js.map +1 -0
  37. package/load-agent-dir.d.ts +17 -0
  38. package/load-agent-dir.js +192 -0
  39. package/load-agent-dir.js.map +1 -0
  40. package/package.json +32 -0
  41. package/project.d.ts +94 -0
  42. package/project.js +155 -0
  43. package/project.js.map +1 -0
  44. package/secret.d.ts +45 -0
  45. package/secret.js +69 -0
  46. package/secret.js.map +1 -0
  47. package/templates-inline.d.ts +2 -0
  48. package/templates-inline.js +16 -0
  49. package/templates-inline.js.map +1 -0
  50. package/templates.d.ts +16 -0
  51. package/templates.js +32 -0
  52. package/templates.js.map +1 -0
  53. package/turn.d.ts +11 -0
  54. package/turn.js +244 -0
  55. package/turn.js.map +1 -0
  56. package/types.d.ts +485 -0
  57. package/types.js +4 -0
  58. package/types.js.map +1 -0
  59. package/version.d.ts +1 -0
  60. package/version.js +5 -0
  61. package/version.js.map +1 -0
  62. package/workflows.d.ts +36 -0
  63. package/workflows.js +101 -0
  64. package/workflows.js.map +1 -0
  65. package/workspace.d.ts +290 -0
  66. package/workspace.js +390 -0
  67. package/workspace.js.map +1 -0
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/NOTICE ADDED
@@ -0,0 +1,12 @@
1
+ AgentNava SDK
2
+ Copyright 2026 Cerebro Labs, Inc.
3
+
4
+ This product includes software developed at Cerebro Labs, Inc.
5
+ (https://agentnava.com).
6
+
7
+ This NOTICE file is required by Section 4(d) of the Apache License 2.0 and
8
+ must be carried in any redistribution of this software.
9
+
10
+ "AgentNava" and "Cerebro Labs" are trademarks of Cerebro Labs, Inc. Section 6
11
+ of the License grants no rights to use them: the code is free, the names are
12
+ not.
package/README.md ADDED
@@ -0,0 +1,230 @@
1
+ # @cerebro-labs/agentnava-sdk
2
+
3
+ Configure an agent, start a conversation, work with it.
4
+
5
+ ```bash
6
+ npm install @cerebro-labs/agentnava-sdk
7
+ ```
8
+
9
+ Node 18 or later, or Bun, or any runtime with `fetch`. Both `import` and
10
+ `require` work, and TypeScript types ship with it.
11
+
12
+ ```ts
13
+ import { AgentNava } from '@cerebro-labs/agentnava-sdk';
14
+
15
+ const ws = AgentNava.getWorkspace(); // reads AGENTNAVA_API_KEY
16
+
17
+ const agent = await ws.agents.create({
18
+ name: 'Refund checker',
19
+ instructions: 'Decide whether a late delivery qualifies for a refund.',
20
+ });
21
+
22
+ const conversation = await agent.start();
23
+ console.log(await conversation.ask('Order 4471 arrived nine days late.'));
24
+ ```
25
+
26
+ The full reference is at https://docs.agentnava.com. (It used to point here at a
27
+ file path inside our own repository, which nobody who installs this package
28
+ has.) This README covers
29
+ only the things that are easy to get wrong.
30
+
31
+ ## Connecting an account, end to end
32
+
33
+ `authorize()` gives you a URL for your user to visit. `waitUntilReady()` tells
34
+ you when they are done, so you do not have to write a polling loop or work out
35
+ which field to believe.
36
+
37
+ ```ts
38
+ const { url } = await conversation.authorize('gmail');
39
+ showToUser(url); // popup, redirect, QR code, your choice
40
+ await conversation.waitUntilReady(); // resolves once nothing required is outstanding
41
+ ```
42
+
43
+ How you show the URL is yours: this SDK authenticates with an API key, so it
44
+ runs on your server, and the browser half is your application's.
45
+
46
+ An OPTIONAL requirement does not hold the wait up, for the same reason it does
47
+ not make `ready` false: the conversation genuinely works without it.
48
+
49
+ On timeout it throws `conversation_not_ready` and the message names what is
50
+ still missing, e.g. `still waiting on: connection gmail`. It is safe to call
51
+ again; someone who has not finished signing in may just need longer.
52
+
53
+ ```ts
54
+ await conversation.waitUntilReady({ timeoutMs: 120_000, intervalMs: 2_000, signal });
55
+ ```
56
+
57
+ ## 0.2.0 is a breaking change. Upgrade from 0.1.1, do not stay on it.
58
+
59
+ "session" is gone from everything you touch. It survives only in our storage,
60
+ which you never see.
61
+
62
+ | 0.1.1 | 0.2.0 |
63
+ |---|---|
64
+ | `GET /v1/sessions` | `GET /v1/conversations` (the old path now 404s) |
65
+ | `ConnectionStatus.sessionId` | `ConnectionStatus.conversationId` |
66
+ | `conversation.authorize()` sent `sessionId` | sends `conversationId` |
67
+ | `scope: 'session'` came back from the API | `scope: 'conversation'`, the value the type always declared |
68
+
69
+ **0.1.1 stops working** once these reach production, because the API reads only
70
+ the new field names. There is no compatibility shim: this package is private and
71
+ pre-launch, so the old spellings were removed rather than deprecated.
72
+
73
+ If you are on 0.1.1 the change is mechanical: rename `sessionId` to
74
+ `conversationId` wherever you read it or pass it. Nothing else about the shape
75
+ moved.
76
+
77
+
78
+ ## Holding an object is free
79
+
80
+ `ws.agent(id)`, `ws.conversation(id)` and `ws.project(id)` make **no network
81
+ call**. You get something you can call methods on, and the first request happens
82
+ when you call one.
83
+
84
+ Store the `id`, not the object. A returned object is a handle, not JSON.
85
+
86
+ ## Asking: one method, two shapes
87
+
88
+ ```ts
89
+ const reply = await conversation.ask('...'); // just the answer
90
+ ```
91
+
92
+ ```ts
93
+ for await (const e of conversation.ask('...')) { // as it happens
94
+ if (e.type === 'text') append(e.text);
95
+ if (e.type === 'done') save(e.reply);
96
+ }
97
+ ```
98
+
99
+ **The message is sent when you call `ask`**, not when you await or iterate it.
100
+ Calling `ask` twice asks twice.
101
+
102
+ You may await the same turn more than once; it is a promise, and you get the same
103
+ answer. You may not iterate it twice, or mix the two, because the events are a
104
+ live stream rather than a stored list and the second consumer would receive
105
+ nothing at all. That throws instead.
106
+
107
+ **The turn is not your request.** It runs on our side, so a dropped connection
108
+ does not cancel it. Read the answer back with `conversation.messages()` rather
109
+ than asking again.
110
+
111
+ ## Changing an agent publishes a version
112
+
113
+ There is no separate save. `agent.update()`, `setWorkflow`, `removeWorkflow` and
114
+ `setTriggers` each publish a new version.
115
+
116
+ **Send only what changes.** Everything you do not send is inherited from the
117
+ current version. That is what makes changing one field safe, and it is not a
118
+ convenience: a caller that rebuilds and resends a whole configuration drops
119
+ whatever it forgot, which has caused four separate data-loss bugs in this
120
+ codebase.
121
+
122
+ ```ts
123
+ await agent.update({ instructions: 'Be brief.' }); // keeps everything else
124
+ ```
125
+
126
+ ## A conversation pins its version
127
+
128
+ It pins the agent's version when it starts and keeps it. Publishing afterwards
129
+ does not move a conversation that is already open.
130
+
131
+ Knowledge is the exception, and deliberately so: it is read **by reference**, so
132
+ replacing a knowledge file changes what open conversations see on their next
133
+ turn. A price list you could not correct without republishing the agent would be
134
+ useless.
135
+
136
+ ## Two drives
137
+
138
+ | | The agent sees | Belongs to | You write | The agent writes |
139
+ |---|---|---|---|---|
140
+ | Knowledge | `/knowledge` | the agent | yes | no |
141
+ | Conversation | `/workspace` | one conversation | yes | yes |
142
+
143
+ An application stages material by writing it in before asking about it:
144
+
145
+ ```ts
146
+ await conversation.writeFile('/input/contract.pdf', bytes);
147
+ await conversation.ask('What are the payment terms?');
148
+ ```
149
+
150
+ Anywhere under the root works. `input/` is a convention here and nothing
151
+ enforces it, because the agent and your application share one namespace.
152
+
153
+ ## Credentials have two tiers, and they do not substitute
154
+
155
+ `fixed` is set once on the agent and used by every conversation. `conversation`
156
+ is supplied per conversation, so each user brings their own account.
157
+
158
+ An account connected on the agent does **not** satisfy a declaration scoped
159
+ `conversation`, and a conversation cannot supply a `fixed` one. Check
160
+ `conversation.ready` and `conversation.requires` to see what is outstanding.
161
+
162
+ ## Drafting tools from an API you already describe
163
+
164
+ `importTools` turns an OpenAPI document, a Postman collection or a working curl
165
+ command into draft `httpTools`, so nobody hand-writes one declaration per
166
+ endpoint.
167
+
168
+ ```ts
169
+ import { importTools } from '@cerebro-labs/agentnava-sdk';
170
+
171
+ const draft = importTools({ openapi }, { include: (c) => !c.url.includes('/admin/') });
172
+ await ws.agents.create({ id: 'support', instructions, httpTools: draft.tools });
173
+ ```
174
+
175
+ It runs entirely on your machine. Nothing about the source is sent to
176
+ AgentNava, which matters because these files routinely contain a live token:
177
+ any credential found is replaced with a `{{secrets.NAME}}` placeholder and
178
+ listed in `draft.secrets`, with no value carried across. Each drafted tool also
179
+ declares the secrets it uses in its own `secrets` field, which is what lets the
180
+ runtime load them for the turn.
181
+
182
+ They are drafts. `draft.warnings` names what a human still has to decide, and
183
+ the big one is `description-missing`: none of the three formats contains the
184
+ sentence a model reads to pick a tool, and a bad description does not fail, it
185
+ makes the agent call the wrong thing.
186
+
187
+ ## Errors
188
+
189
+ Every failure throws `AgentNavaError`.
190
+
191
+ ```ts
192
+ catch (err) {
193
+ if (err instanceof AgentNavaError) {
194
+ err.code; // 'agent_not_found', branch on THIS
195
+ err.status; // 404
196
+ err.retryable; // 5xx, 429, and network failures
197
+ err.retryAfter; // seconds, on a 429
198
+ }
199
+ }
200
+ ```
201
+
202
+ Branch on `code`, not on `message`. Codes are stable; messages are written for a
203
+ person reading a log.
204
+
205
+ `retryable` is the only thing worth automating on: a 400 will fail identically
206
+ forever, and a 404 will not become found.
207
+
208
+ 404 covers both "no such thing" and "not yours", so a caller probing ids cannot
209
+ tell another customer's agent from one that never existed. There is no 403.
210
+
211
+ ## Configuration
212
+
213
+ ```ts
214
+ AgentNava.getWorkspace(); // AGENTNAVA_API_KEY
215
+ AgentNava.getWorkspace({ apiKey, baseURL, timeout });
216
+ AgentNava.getWorkspace({ fetch: myFetch }); // a proxy, or a test
217
+ ```
218
+
219
+ Runs anywhere `fetch` exists: Node, Bun, Deno, Cloudflare Workers, the browser.
220
+ `loadWorkflows` is the one exception; it reads a directory off disk and so needs
221
+ Node or Bun.
222
+
223
+ ## Licence
224
+
225
+ Apache License 2.0. See `LICENSE`, and `NOTICE` for the attribution that
226
+ section 4(d) asks you to carry along.
227
+
228
+ Free to use, modify and redistribute, including commercially, with an
229
+ explicit patent grant. Section 6 grants no rights to the names: "AgentNava"
230
+ and "Cerebro Labs" remain trademarks of Cerebro Labs, Inc.