@smarter.sh/api 0.0.0-stage → 1.0.1
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.txt +671 -0
- package/README.md +193 -2
- package/dist/client.d.ts +146 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +178 -0
- package/dist/client.js.map +1 -0
- package/dist/core/config.d.ts +148 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +212 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/errors.d.ts +189 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +187 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/http.d.ts +207 -0
- package/dist/core/http.d.ts.map +1 -0
- package/dist/core/http.js +456 -0
- package/dist/core/http.js.map +1 -0
- package/dist/core/log.d.ts +62 -0
- package/dist/core/log.d.ts.map +1 -0
- package/dist/core/log.js +68 -0
- package/dist/core/log.js.map +1 -0
- package/dist/core/sse.d.ts +38 -0
- package/dist/core/sse.d.ts.map +1 -0
- package/dist/core/sse.js +79 -0
- package/dist/core/sse.js.map +1 -0
- package/dist/core/typing.d.ts +21 -0
- package/dist/core/typing.d.ts.map +1 -0
- package/dist/core/typing.js +13 -0
- package/dist/core/typing.js.map +1 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/models/account.d.ts +112 -0
- package/dist/models/account.d.ts.map +1 -0
- package/dist/models/account.js +55 -0
- package/dist/models/account.js.map +1 -0
- package/dist/models/base.d.ts +99 -0
- package/dist/models/base.d.ts.map +1 -0
- package/dist/models/base.js +111 -0
- package/dist/models/base.js.map +1 -0
- package/dist/models/chat.d.ts +2243 -0
- package/dist/models/chat.d.ts.map +1 -0
- package/dist/models/chat.js +451 -0
- package/dist/models/chat.js.map +1 -0
- package/dist/models/guardrail.d.ts +109 -0
- package/dist/models/guardrail.d.ts.map +1 -0
- package/dist/models/guardrail.js +68 -0
- package/dist/models/guardrail.js.map +1 -0
- package/dist/models/journal.d.ts +159 -0
- package/dist/models/journal.d.ts.map +1 -0
- package/dist/models/journal.js +115 -0
- package/dist/models/journal.js.map +1 -0
- package/dist/models/llmclient.d.ts +183 -0
- package/dist/models/llmclient.d.ts.map +1 -0
- package/dist/models/llmclient.js +105 -0
- package/dist/models/llmclient.js.map +1 -0
- package/dist/models/llmhost.d.ts +121 -0
- package/dist/models/llmhost.d.ts.map +1 -0
- package/dist/models/llmhost.js +79 -0
- package/dist/models/llmhost.js.map +1 -0
- package/dist/models/manifest.d.ts +211 -0
- package/dist/models/manifest.d.ts.map +1 -0
- package/dist/models/manifest.js +290 -0
- package/dist/models/manifest.js.map +1 -0
- package/dist/models/mcpclient.d.ts +99 -0
- package/dist/models/mcpclient.d.ts.map +1 -0
- package/dist/models/mcpclient.js +65 -0
- package/dist/models/mcpclient.js.map +1 -0
- package/dist/models/misc.d.ts +232 -0
- package/dist/models/misc.d.ts.map +1 -0
- package/dist/models/misc.js +110 -0
- package/dist/models/misc.js.map +1 -0
- package/dist/models/platform.d.ts +88 -0
- package/dist/models/platform.d.ts.map +1 -0
- package/dist/models/platform.js +35 -0
- package/dist/models/platform.js.map +1 -0
- package/dist/models/plugin.d.ts +36 -0
- package/dist/models/plugin.d.ts.map +1 -0
- package/dist/models/plugin.js +16 -0
- package/dist/models/plugin.js.map +1 -0
- package/dist/models/react.d.ts +104 -0
- package/dist/models/react.d.ts.map +1 -0
- package/dist/models/react.js +136 -0
- package/dist/models/react.js.map +1 -0
- package/dist/models/sam/account.d.ts +155 -0
- package/dist/models/sam/account.d.ts.map +1 -0
- package/dist/models/sam/account.js +7 -0
- package/dist/models/sam/account.js.map +1 -0
- package/dist/models/sam/apiconnection.d.ts +147 -0
- package/dist/models/sam/apiconnection.d.ts.map +1 -0
- package/dist/models/sam/apiconnection.js +7 -0
- package/dist/models/sam/apiconnection.js.map +1 -0
- package/dist/models/sam/apiplugin.d.ts +278 -0
- package/dist/models/sam/apiplugin.d.ts.map +1 -0
- package/dist/models/sam/apiplugin.js +7 -0
- package/dist/models/sam/apiplugin.js.map +1 -0
- package/dist/models/sam/budget.d.ts +219 -0
- package/dist/models/sam/budget.d.ts.map +1 -0
- package/dist/models/sam/budget.js +7 -0
- package/dist/models/sam/budget.js.map +1 -0
- package/dist/models/sam/customdomain.d.ts +139 -0
- package/dist/models/sam/customdomain.d.ts.map +1 -0
- package/dist/models/sam/customdomain.js +7 -0
- package/dist/models/sam/customdomain.js.map +1 -0
- package/dist/models/sam/guardrail.d.ts +222 -0
- package/dist/models/sam/guardrail.d.ts.map +1 -0
- package/dist/models/sam/guardrail.js +7 -0
- package/dist/models/sam/guardrail.js.map +1 -0
- package/dist/models/sam/imagesearchplugin.d.ts +235 -0
- package/dist/models/sam/imagesearchplugin.d.ts.map +1 -0
- package/dist/models/sam/imagesearchplugin.js +7 -0
- package/dist/models/sam/imagesearchplugin.js.map +1 -0
- package/dist/models/sam/index.d.ts +104 -0
- package/dist/models/sam/index.d.ts.map +1 -0
- package/dist/models/sam/index.js +50 -0
- package/dist/models/sam/index.js.map +1 -0
- package/dist/models/sam/llmclient.d.ts +490 -0
- package/dist/models/sam/llmclient.d.ts.map +1 -0
- package/dist/models/sam/llmclient.js +7 -0
- package/dist/models/sam/llmclient.js.map +1 -0
- package/dist/models/sam/llmhost.d.ts +429 -0
- package/dist/models/sam/llmhost.d.ts.map +1 -0
- package/dist/models/sam/llmhost.js +7 -0
- package/dist/models/sam/llmhost.js.map +1 -0
- package/dist/models/sam/llmhostcompute.d.ts +221 -0
- package/dist/models/sam/llmhostcompute.d.ts.map +1 -0
- package/dist/models/sam/llmhostcompute.js +7 -0
- package/dist/models/sam/llmhostcompute.js.map +1 -0
- package/dist/models/sam/mcpclient.d.ts +195 -0
- package/dist/models/sam/mcpclient.d.ts.map +1 -0
- package/dist/models/sam/mcpclient.js +7 -0
- package/dist/models/sam/mcpclient.js.map +1 -0
- package/dist/models/sam/orchestrator.d.ts +163 -0
- package/dist/models/sam/orchestrator.d.ts.map +1 -0
- package/dist/models/sam/orchestrator.js +7 -0
- package/dist/models/sam/orchestrator.js.map +1 -0
- package/dist/models/sam/plugin.d.ts +163 -0
- package/dist/models/sam/plugin.d.ts.map +1 -0
- package/dist/models/sam/plugin.js +7 -0
- package/dist/models/sam/plugin.js.map +1 -0
- package/dist/models/sam/prompt.d.ts +116 -0
- package/dist/models/sam/prompt.d.ts.map +1 -0
- package/dist/models/sam/prompt.js +7 -0
- package/dist/models/sam/prompt.js.map +1 -0
- package/dist/models/sam/provider.d.ts +195 -0
- package/dist/models/sam/provider.d.ts.map +1 -0
- package/dist/models/sam/provider.js +7 -0
- package/dist/models/sam/provider.js.map +1 -0
- package/dist/models/sam/proxy.d.ts +163 -0
- package/dist/models/sam/proxy.d.ts.map +1 -0
- package/dist/models/sam/proxy.js +7 -0
- package/dist/models/sam/proxy.js.map +1 -0
- package/dist/models/sam/schemas.d.ts +8 -0
- package/dist/models/sam/schemas.d.ts.map +1 -0
- package/dist/models/sam/schemas.js +6059 -0
- package/dist/models/sam/schemas.js.map +1 -0
- package/dist/models/sam/secret.d.ts +123 -0
- package/dist/models/sam/secret.d.ts.map +1 -0
- package/dist/models/sam/secret.js +7 -0
- package/dist/models/sam/secret.js.map +1 -0
- package/dist/models/sam/skillplugin.d.ts +181 -0
- package/dist/models/sam/skillplugin.d.ts.map +1 -0
- package/dist/models/sam/skillplugin.js +7 -0
- package/dist/models/sam/skillplugin.js.map +1 -0
- package/dist/models/sam/smarterauthtoken.d.ts +115 -0
- package/dist/models/sam/smarterauthtoken.d.ts.map +1 -0
- package/dist/models/sam/smarterauthtoken.js +7 -0
- package/dist/models/sam/smarterauthtoken.js.map +1 -0
- package/dist/models/sam/sqlconnection.d.ts +187 -0
- package/dist/models/sam/sqlconnection.d.ts.map +1 -0
- package/dist/models/sam/sqlconnection.js +7 -0
- package/dist/models/sam/sqlconnection.js.map +1 -0
- package/dist/models/sam/sqlplugin.d.ts +232 -0
- package/dist/models/sam/sqlplugin.d.ts.map +1 -0
- package/dist/models/sam/sqlplugin.js +7 -0
- package/dist/models/sam/sqlplugin.js.map +1 -0
- package/dist/models/sam/user.d.ts +135 -0
- package/dist/models/sam/user.d.ts.map +1 -0
- package/dist/models/sam/user.js +7 -0
- package/dist/models/sam/user.js.map +1 -0
- package/dist/models/sam/vectorsearch.d.ts +150 -0
- package/dist/models/sam/vectorsearch.d.ts.map +1 -0
- package/dist/models/sam/vectorsearch.js +7 -0
- package/dist/models/sam/vectorsearch.js.map +1 -0
- package/dist/models/sam/vectorstore.d.ts +291 -0
- package/dist/models/sam/vectorstore.d.ts.map +1 -0
- package/dist/models/sam/vectorstore.js +7 -0
- package/dist/models/sam/vectorstore.js.map +1 -0
- package/dist/models/sam/websearchplugin.d.ts +229 -0
- package/dist/models/sam/websearchplugin.d.ts.map +1 -0
- package/dist/models/sam/websearchplugin.js +7 -0
- package/dist/models/sam/websearchplugin.js.map +1 -0
- package/dist/models/vectorstore.d.ts +165 -0
- package/dist/models/vectorstore.d.ts.map +1 -0
- package/dist/models/vectorstore.js +90 -0
- package/dist/models/vectorstore.js.map +1 -0
- package/dist/resources/accounts.d.ts +107 -0
- package/dist/resources/accounts.d.ts.map +1 -0
- package/dist/resources/accounts.js +84 -0
- package/dist/resources/accounts.js.map +1 -0
- package/dist/resources/base.d.ts +127 -0
- package/dist/resources/base.d.ts.map +1 -0
- package/dist/resources/base.js +139 -0
- package/dist/resources/base.js.map +1 -0
- package/dist/resources/catalog.d.ts +209 -0
- package/dist/resources/catalog.d.ts.map +1 -0
- package/dist/resources/catalog.js +124 -0
- package/dist/resources/catalog.js.map +1 -0
- package/dist/resources/guardrails.d.ts +82 -0
- package/dist/resources/guardrails.d.ts.map +1 -0
- package/dist/resources/guardrails.js +46 -0
- package/dist/resources/guardrails.js.map +1 -0
- package/dist/resources/history.d.ts +97 -0
- package/dist/resources/history.d.ts.map +1 -0
- package/dist/resources/history.js +109 -0
- package/dist/resources/history.js.map +1 -0
- package/dist/resources/llmclients.d.ts +348 -0
- package/dist/resources/llmclients.d.ts.map +1 -0
- package/dist/resources/llmclients.js +367 -0
- package/dist/resources/llmclients.js.map +1 -0
- package/dist/resources/llmhosts.d.ts +146 -0
- package/dist/resources/llmhosts.d.ts.map +1 -0
- package/dist/resources/llmhosts.js +128 -0
- package/dist/resources/llmhosts.js.map +1 -0
- package/dist/resources/manifests.d.ts +153 -0
- package/dist/resources/manifests.d.ts.map +1 -0
- package/dist/resources/manifests.js +203 -0
- package/dist/resources/manifests.js.map +1 -0
- package/dist/resources/mcpclients.d.ts +90 -0
- package/dist/resources/mcpclients.d.ts.map +1 -0
- package/dist/resources/mcpclients.js +57 -0
- package/dist/resources/mcpclients.js.map +1 -0
- package/dist/resources/providers.d.ts +33 -0
- package/dist/resources/providers.d.ts.map +1 -0
- package/dist/resources/providers.js +39 -0
- package/dist/resources/providers.js.map +1 -0
- package/dist/resources/proxies.d.ts +61 -0
- package/dist/resources/proxies.d.ts.map +1 -0
- package/dist/resources/proxies.js +57 -0
- package/dist/resources/proxies.js.map +1 -0
- package/dist/resources/vectorstores.d.ts +194 -0
- package/dist/resources/vectorstores.d.ts.map +1 -0
- package/dist/resources/vectorstores.js +200 -0
- package/dist/resources/vectorstores.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/package.json +81 -4
package/README.md
CHANGED
|
@@ -1,3 +1,194 @@
|
|
|
1
|
-
#
|
|
1
|
+
# The Smarter Node.js SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/smarter-sh/smarter-nodejs/actions/workflows/pushMain.yml)
|
|
4
|
+
[](https://codecov.io/gh/smarter-sh/smarter-nodejs)
|
|
5
|
+
[](https://github.com/smarter-sh/smarter-nodejs/releases)
|
|
6
|
+
[](https://www.npmjs.com/package/@smarter.sh/api)
|
|
7
|
+
[](https://docs.smarter.sh/en/latest/smarter-framework/smarter-nodejs.html)
|
|
8
|
+
[](https://smarter.sh)
|
|
9
|
+
[](https://www.gnu.org/licenses/agpl-3.0)
|
|
10
|
+
[](https://join.slack.com/t/thesmarterproject/shared_invite/zt-4f0t6v46q-e2c5Of4hS4fBr_XwfQARCw)<br>
|
|
11
|
+
|
|
12
|
+
`@smarter.sh/api` is the official Node.js SDK of the
|
|
13
|
+
[Smarter platform](https://github.com/smarter-sh/smarter), written in
|
|
14
|
+
TypeScript. It is to Smarter what the `openai` package is to the OpenAI api:
|
|
15
|
+
one `npm install` gives your JavaScript or TypeScript software typed, complete
|
|
16
|
+
access to your own Smarter installation, whether it runs on your laptop or on
|
|
17
|
+
Kubernetes.
|
|
18
|
+
|
|
19
|
+
Use it to build custom software that is tightly integrated with your Smarter
|
|
20
|
+
resources and functionality, without customizing or forking the Smarter
|
|
21
|
+
backend: a web back end that chats with your LLMClients, a CI job that applies
|
|
22
|
+
your manifests, a serverless function that loads documents into a vectorstore,
|
|
23
|
+
or a service that calls your MCP servers' tools.
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { Smarter } from "@smarter.sh/api";
|
|
27
|
+
|
|
28
|
+
const client = new Smarter(); // SMARTER_API_KEY, or the smarter cli's ~/.smarter/config.yaml
|
|
29
|
+
|
|
30
|
+
const llmclient = await client.llmClients.find("customer_support");
|
|
31
|
+
const response = await client.llmClients.prompt(llmclient.id, "Where is my order #1234?");
|
|
32
|
+
console.log(response.text);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
It has the same features as the [Smarter Python SDK](https://github.com/smarter-sh/smarter-python),
|
|
36
|
+
which is the reference implementation of every Smarter SDK, with the same
|
|
37
|
+
resources, verbs and errors, in idiomatic TypeScript.
|
|
38
|
+
|
|
39
|
+
## Smarter Node.js SDK or Smarter CLI?
|
|
40
|
+
|
|
41
|
+
Both manage the same resources through the same api. The difference is how
|
|
42
|
+
you use them:
|
|
43
|
+
|
|
44
|
+
| [smarter-nodejs](https://github.com/smarter-sh/smarter-nodejs) (this package) | [smarter-cli](https://github.com/smarter-sh/smarter-cli) |
|
|
45
|
+
| ----------------------------------------------------------------------------- | -------------------------------------------------------- |
|
|
46
|
+
| A library that you **import** into your own software. | A program that you **install** on your computer. |
|
|
47
|
+
| `await client.manifests.apply("guardrail.yaml")` | `smarter apply -f guardrail.yaml` |
|
|
48
|
+
| Returns typed, validated objects, and throws typed errors. | Prints JSON or YAML in a terminal window. |
|
|
49
|
+
| For applications, services, serverless functions, tests and automation. | For people at a keyboard, and shell scripts. |
|
|
50
|
+
|
|
51
|
+
The SDK reads the cli's configuration file, so if you have run
|
|
52
|
+
`smarter configure`, the SDK needs no other setup.
|
|
53
|
+
|
|
54
|
+
## At a Glance
|
|
55
|
+
|
|
56
|
+
- **Every resource kind**, through the same manifest api as the cli:
|
|
57
|
+
`apply`, `validate`, `get`, `describe`, `delete`, `deploy`, `undeploy` and
|
|
58
|
+
`logs`, for LLMClients, Plugins, Guardrails, MCPClients, Vectorstores,
|
|
59
|
+
LLMHosts, Secrets, Custom Domains, Accounts, Users, and every other kind.
|
|
60
|
+
- **Prompts and conversations**: prompt an LLMClient, hold a multi-turn chat
|
|
61
|
+
that keeps its session, and stream a prompt's progress (its LLM requests,
|
|
62
|
+
tool calls and MCP calls) as it runs, with `for await`.
|
|
63
|
+
- **Resource actions**: evaluate a Guardrail, call an MCP server's tools, add
|
|
64
|
+
documents to and search a vectorstore, plan and deploy an LLMHost, discover
|
|
65
|
+
open-weight models, and call an LLM provider through a Proxy.
|
|
66
|
+
- **The platform's own models**: a TypeScript type of every
|
|
67
|
+
[SAM manifest](https://docs.smarter.sh/en/latest/smarter-framework/smarter-manifests.html)
|
|
68
|
+
kind (e.g. `SAMLLMClient`), generated from the platform's JSON Schemas, and
|
|
69
|
+
Zod schemas of the Smarter Chat api contract (e.g. `PromptChatApiConfig`),
|
|
70
|
+
the Smarter Journal contract and every REST response, kept in step with the
|
|
71
|
+
platform by tests.
|
|
72
|
+
- **Production behavior**: retries with backoff, timeouts and cancellation
|
|
73
|
+
(`AbortSignal`), typed errors, logging that never prints your api key, ES
|
|
74
|
+
modules that CommonJS can `require()`, and no HTTP dependency.
|
|
75
|
+
|
|
76
|
+
## Quickstart
|
|
77
|
+
|
|
78
|
+
```console
|
|
79
|
+
npm install @smarter.sh/api
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Point the SDK at your platform with environment variables, or pass them as
|
|
83
|
+
options to `new Smarter({...})`:
|
|
84
|
+
|
|
85
|
+
```console
|
|
86
|
+
export SMARTER_API_KEY="your 64-character Smarter api key"
|
|
87
|
+
export SMARTER_BASE_URL="https://platform.example.com" # or http://localhost:9357
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Manifests
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import { Smarter } from "@smarter.sh/api";
|
|
94
|
+
|
|
95
|
+
const client = new Smarter();
|
|
96
|
+
|
|
97
|
+
await client.manifests.apply("pii-redactor.yaml"); // create or update
|
|
98
|
+
const manifest = await client.guardrails.describe("pii_redactor"); // read it back
|
|
99
|
+
const guardrail = manifest.toSam("Guardrail"); // as a typed SAMGuardrail
|
|
100
|
+
console.log(guardrail.spec.config.action);
|
|
101
|
+
await client.guardrails.delete("pii_redactor");
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Chat
|
|
105
|
+
|
|
106
|
+
```ts
|
|
107
|
+
const chat = await client.llmClients.chat(llmclient.id);
|
|
108
|
+
console.log((await chat.send("What is 2 to the 10th power?")).text);
|
|
109
|
+
console.log((await chat.send("And divided by 4?")).text);
|
|
110
|
+
|
|
111
|
+
const stream = chat.stream("Now take its square root.");
|
|
112
|
+
for await (const event of stream) {
|
|
113
|
+
console.log("...", event.message); // e.g. "Calling tool calculator"
|
|
114
|
+
}
|
|
115
|
+
console.log(stream.response.text);
|
|
116
|
+
|
|
117
|
+
// The chat configuration has what a chat needs. verbose adds the LLMClient's plugins and
|
|
118
|
+
// extensions, the session's tool calls and the complete meta_data.
|
|
119
|
+
const config = await client.llmClients.config(llmclient.id, { verbose: true });
|
|
120
|
+
console.log(config.plugins.plugins.map((plugin) => plugin.plugin_meta.name));
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Errors
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { NotFoundError, SmarterError } from "@smarter.sh/api";
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
await client.manifests.describe("LLMClient", "no_such_client");
|
|
130
|
+
} catch (err) {
|
|
131
|
+
if (err instanceof NotFoundError) console.log(err.statusCode, err.message, err.errorClass);
|
|
132
|
+
else if (err instanceof SmarterError) console.log("something else went wrong:", err);
|
|
133
|
+
else throw err;
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Documentation
|
|
138
|
+
|
|
139
|
+
Read the Docs: [The Smarter Node.js SDK](https://docs.smarter.sh/en/latest/smarter-framework/smarter-nodejs.html)
|
|
140
|
+
on [docs.smarter.sh](https://docs.smarter.sh/). The design decisions are
|
|
141
|
+
recorded in [doc/adr/](./doc/adr/).
|
|
142
|
+
|
|
143
|
+
## Requirements
|
|
144
|
+
|
|
145
|
+
Node.js 22 or later, and a Smarter platform to connect to. See the
|
|
146
|
+
[Quick Start Guide](https://docs.smarter.sh/en/latest/smarter-platform/installation/quick-start.html)
|
|
147
|
+
to run one on your laptop.
|
|
148
|
+
|
|
149
|
+
## Development
|
|
150
|
+
|
|
151
|
+
```console
|
|
152
|
+
make init # the dependencies, and the pre-commit hooks
|
|
153
|
+
make test # the unit tests, which never reach a platform
|
|
154
|
+
make coverage # the unit tests, with a coverage report
|
|
155
|
+
SMARTER_BASE_URL=http://localhost:9357 SMARTER_API_KEY=... make test-live
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
If your shell sets `NODE_ENV=production`, npm skips the development
|
|
159
|
+
dependencies: `make init` installs them anyway.
|
|
160
|
+
|
|
161
|
+
`make init` also creates a Python virtual environment in `venv/` with
|
|
162
|
+
[pre-commit](https://pre-commit.com/) (Python 3.14), and installs the
|
|
163
|
+
pre-commit and commit-msg hooks, which lint each commit and check its message.
|
|
164
|
+
`make python-init` does only that part.
|
|
165
|
+
|
|
166
|
+
### Versions and releases
|
|
167
|
+
|
|
168
|
+
Commit messages are [conventional commits](https://www.conventionalcommits.org/), and
|
|
169
|
+
[semantic-release](https://semantic-release.gitbook.io/) versions the package from them, as it does
|
|
170
|
+
[Smarter Chat](https://github.com/smarter-sh/smarter-chat). On each push to `main`, and to `alpha` and
|
|
171
|
+
`beta` (prereleases, e.g. `1.0.0-alpha.1`), `.github/workflows/pushMain.yml` runs the tests and the
|
|
172
|
+
build, and if they pass, determines the next version, writes it to `package.json` and `src/version.ts`,
|
|
173
|
+
adds the release notes to `CHANGELOG.md`, tags the commit and creates a GitHub release. It then builds
|
|
174
|
+
the tag and publishes it to npm as [@smarter.sh/api](https://www.npmjs.com/package/@smarter.sh/api),
|
|
175
|
+
with npm's trusted publishing and a provenance statement: a release from `main` with the `latest`
|
|
176
|
+
dist-tag, and a prerelease with `alpha` or `beta`. A release on `main` is then merged back into
|
|
177
|
+
`alpha`. `feat` commits are minor releases, `fix` and `perf` commits are patches, and a
|
|
178
|
+
`BREAKING CHANGE:` footer is a major release. See `release.config.js`.
|
|
179
|
+
|
|
180
|
+
`make release` publishes by hand, from `main`, with an npm token that may publish to the
|
|
181
|
+
`@smarter.sh` scope (in `.npmrc`, which is gitignored, or `~/.npmrc`). It is needed only if the
|
|
182
|
+
workflow can't publish.
|
|
183
|
+
|
|
184
|
+
The agent skills in [skills/](./skills/) describe how this repository is
|
|
185
|
+
developed, tested and documented, for people and for AI coding agents.
|
|
186
|
+
|
|
187
|
+
## Support
|
|
188
|
+
|
|
189
|
+
Please report bugs to the [GitHub Issues Page](https://github.com/smarter-sh/smarter-nodejs/issues)
|
|
190
|
+
for this project.
|
|
191
|
+
|
|
192
|
+
## Contributing
|
|
193
|
+
|
|
194
|
+
Please see [CONTRIBUTING](./.github/CONTRIBUTING.md).
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Smarter client.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { Smarter } from "@smarter.sh/api";
|
|
7
|
+
*
|
|
8
|
+
* const client = new Smarter(); // SMARTER_API_KEY, or ~/.smarter/config.yaml
|
|
9
|
+
* console.log((await client.whoami()).user.username);
|
|
10
|
+
*
|
|
11
|
+
* const response = await client.llmClients.prompt(5, "What is 17 times 23?");
|
|
12
|
+
* console.log(response.text);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
import { inspect } from "node:util";
|
|
16
|
+
import { type ClientConfig, type ConfigOptions } from "./core/config.ts";
|
|
17
|
+
import { SmarterHttpClient, type Fetch, type RequestOptions } from "./core/http.ts";
|
|
18
|
+
import { type SmarterLogger, type SmarterLogLevel } from "./core/log.ts";
|
|
19
|
+
import { KindInfo } from "./models/manifest.ts";
|
|
20
|
+
import { PlatformStatus, PlatformVersion, WhoAmI } from "./models/platform.ts";
|
|
21
|
+
import { Accounts } from "./resources/accounts.ts";
|
|
22
|
+
import { Orchestrators, Plugins, Secrets, Vectorsearches } from "./resources/catalog.ts";
|
|
23
|
+
import { Guardrails } from "./resources/guardrails.ts";
|
|
24
|
+
import { Journal, PromptHistory } from "./resources/history.ts";
|
|
25
|
+
import { LLMClients } from "./resources/llmclients.ts";
|
|
26
|
+
import { LLMHosts } from "./resources/llmhosts.ts";
|
|
27
|
+
import { Manifests } from "./resources/manifests.ts";
|
|
28
|
+
import { MCPClients } from "./resources/mcpclients.ts";
|
|
29
|
+
import { Providers } from "./resources/providers.ts";
|
|
30
|
+
import { Proxies } from "./resources/proxies.ts";
|
|
31
|
+
import { Vectorstores } from "./resources/vectorstores.ts";
|
|
32
|
+
/** The options of a {@link Smarter} client. Every option is optional: see `src/core/config.ts` for where each is looked up. */
|
|
33
|
+
export interface SmarterOptions extends ConfigOptions {
|
|
34
|
+
/** Headers to add to every request. */
|
|
35
|
+
defaultHeaders?: Record<string, string> | undefined;
|
|
36
|
+
/** The `fetch` to send requests with, e.g. one with a proxy agent. The global `fetch` by default. */
|
|
37
|
+
fetch?: Fetch | undefined;
|
|
38
|
+
/** Where to log: `console`, or any logger with `debug`, `info`, `warn` and `error` methods. */
|
|
39
|
+
logger?: SmarterLogger | undefined;
|
|
40
|
+
/** How much to log, instead of `SMARTER_LOG`. Nothing is logged by default. */
|
|
41
|
+
logLevel?: SmarterLogLevel | undefined;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A client of a Smarter platform's api.
|
|
45
|
+
*
|
|
46
|
+
* The client's properties group the api's operations:
|
|
47
|
+
*
|
|
48
|
+
* - {@link Smarter.manifests}: apply, validate, get, describe, delete, deploy, undeploy and logs, for any kind
|
|
49
|
+
* - {@link Smarter.llmClients}: LLMClients, and prompting and chatting with them
|
|
50
|
+
* - {@link Smarter.guardrails}, {@link Smarter.mcpClients}, {@link Smarter.vectorstores},
|
|
51
|
+
* {@link Smarter.llmHosts}, {@link Smarter.secrets}, {@link Smarter.plugins},
|
|
52
|
+
* {@link Smarter.orchestrators}, {@link Smarter.vectorsearches}
|
|
53
|
+
* - {@link Smarter.accounts} (and `accounts.users`, `accounts.contacts` and `accounts.userProfiles`)
|
|
54
|
+
* - {@link Smarter.history}, {@link Smarter.journal}, {@link Smarter.providers}, {@link Smarter.proxies}
|
|
55
|
+
* - {@link Smarter.whoami}, {@link Smarter.version}, {@link Smarter.status} and {@link Smarter.kinds}
|
|
56
|
+
*
|
|
57
|
+
* A client holds no open connections of its own: there is nothing to close.
|
|
58
|
+
*/
|
|
59
|
+
export declare class Smarter {
|
|
60
|
+
#private;
|
|
61
|
+
/** The client's resolved configuration, without its api key. */
|
|
62
|
+
readonly config: Omit<ClientConfig, "apiKey">;
|
|
63
|
+
/** The http transport, for endpoints that the SDK does not wrap. */
|
|
64
|
+
readonly http: SmarterHttpClient;
|
|
65
|
+
/** The manifest api, for any resource kind. */
|
|
66
|
+
readonly manifests: Manifests;
|
|
67
|
+
/** LLMClients. */
|
|
68
|
+
readonly llmClients: LLMClients;
|
|
69
|
+
/** Guardrails. */
|
|
70
|
+
readonly guardrails: Guardrails;
|
|
71
|
+
/** MCPClients. */
|
|
72
|
+
readonly mcpClients: MCPClients;
|
|
73
|
+
/** Vectorstores. */
|
|
74
|
+
readonly vectorstores: Vectorstores;
|
|
75
|
+
/** LLMHosts. */
|
|
76
|
+
readonly llmHosts: LLMHosts;
|
|
77
|
+
/** Secrets. */
|
|
78
|
+
readonly secrets: Secrets;
|
|
79
|
+
/** Plugins. */
|
|
80
|
+
readonly plugins: Plugins;
|
|
81
|
+
/** Orchestrators. */
|
|
82
|
+
readonly orchestrators: Orchestrators;
|
|
83
|
+
/** Vectorsearches. */
|
|
84
|
+
readonly vectorsearches: Vectorsearches;
|
|
85
|
+
/** Accounts, and their users and contacts. */
|
|
86
|
+
readonly accounts: Accounts;
|
|
87
|
+
/** The history of chat sessions, tool calls and plugin uses. */
|
|
88
|
+
readonly history: PromptHistory;
|
|
89
|
+
/** The Smarter Journal. Superusers only. */
|
|
90
|
+
readonly journal: Journal;
|
|
91
|
+
/** LLM providers and their models. */
|
|
92
|
+
readonly providers: Providers;
|
|
93
|
+
/** Proxies to LLM providers' own apis. */
|
|
94
|
+
readonly proxies: Proxies;
|
|
95
|
+
/**
|
|
96
|
+
* @param options - The api key, base url, environment, timeout (seconds), retries, headers, `fetch` and logging.
|
|
97
|
+
* @throws {@link SmarterConfigurationError} If no api key is found, or an option or environment variable is invalid.
|
|
98
|
+
*/
|
|
99
|
+
constructor(options?: SmarterOptions);
|
|
100
|
+
/** The api key, e.g. to use a proxy with a provider's own SDK. */
|
|
101
|
+
get apiKey(): string;
|
|
102
|
+
/** The api's base url, e.g. `https://platform.smarter.sh/api/v1/`. */
|
|
103
|
+
get baseUrl(): string;
|
|
104
|
+
/**
|
|
105
|
+
* The owner of the api key: the user, their account, and the platform's environment.
|
|
106
|
+
*
|
|
107
|
+
* @param options - Per-request options.
|
|
108
|
+
* @returns The owner.
|
|
109
|
+
*/
|
|
110
|
+
whoami(options?: RequestOptions): Promise<WhoAmI>;
|
|
111
|
+
/**
|
|
112
|
+
* The platform's version, and the versions of its main Python packages.
|
|
113
|
+
*
|
|
114
|
+
* @param options - Per-request options.
|
|
115
|
+
* @returns The versions.
|
|
116
|
+
*/
|
|
117
|
+
version(options?: RequestOptions): Promise<PlatformVersion>;
|
|
118
|
+
/**
|
|
119
|
+
* The state of the platform's infrastructure and compute.
|
|
120
|
+
*
|
|
121
|
+
* @param options - Per-request options.
|
|
122
|
+
* @returns The status.
|
|
123
|
+
*/
|
|
124
|
+
status(options?: RequestOptions): Promise<PlatformStatus>;
|
|
125
|
+
/**
|
|
126
|
+
* The resource kinds that the platform supports, and which of them can be deployed.
|
|
127
|
+
*
|
|
128
|
+
* @param options - Per-request options.
|
|
129
|
+
* @returns The kinds.
|
|
130
|
+
*/
|
|
131
|
+
kinds(options?: RequestOptions): Promise<KindInfo[]>;
|
|
132
|
+
/**
|
|
133
|
+
* The client as JSON, with its api key masked.
|
|
134
|
+
*
|
|
135
|
+
* @returns The base url and the masked api key.
|
|
136
|
+
*/
|
|
137
|
+
toJSON(): {
|
|
138
|
+
baseUrl: string;
|
|
139
|
+
apiKey: string;
|
|
140
|
+
};
|
|
141
|
+
/** @returns e.g. `Smarter(baseUrl="https://platform.smarter.sh/api/v1/", apiKey="****5150")`. */
|
|
142
|
+
toString(): string;
|
|
143
|
+
/** How `console.log` and `util.inspect` show the client: without its api key. */
|
|
144
|
+
[inspect.custom](): string;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;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AE1B;;;OAGG;gBACS,OAAO,GAAE,cAAmB;IA2BxC,kEAAkE;IAClE,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,sEAAsE;IACtE,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED;;;;;OAKG;IACG,MAAM,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;IAIvD;;;;;OAKG;IACG,OAAO,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;IAIjE;;;;;OAKG;IACG,MAAM,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;IAI/D;;;;;OAKG;IACG,KAAK,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAc1D;;;;OAIG;IACH,MAAM,IAAI;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE;IAI7C,iGAAiG;IACjG,QAAQ,IAAI,MAAM;IAIlB,iFAAiF;IACjF,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM;CAG3B"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Smarter client.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { Smarter } from "@smarter.sh/api";
|
|
7
|
+
*
|
|
8
|
+
* const client = new Smarter(); // SMARTER_API_KEY, or ~/.smarter/config.yaml
|
|
9
|
+
* console.log((await client.whoami()).user.username);
|
|
10
|
+
*
|
|
11
|
+
* const response = await client.llmClients.prompt(5, "What is 17 times 23?");
|
|
12
|
+
* console.log(response.text);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
import { inspect } from "node:util";
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
import { readSettings, resolveClientConfig } from "./core/config.js";
|
|
18
|
+
import { SmarterHttpClient } from "./core/http.js";
|
|
19
|
+
import { makeLogger, maskSecret } from "./core/log.js";
|
|
20
|
+
import { SAMJournalApiEnvelope } from "./models/journal.js";
|
|
21
|
+
import { KindInfo } from "./models/manifest.js";
|
|
22
|
+
import { PlatformStatus, PlatformVersion, WhoAmI } from "./models/platform.js";
|
|
23
|
+
import { Accounts } from "./resources/accounts.js";
|
|
24
|
+
import { Orchestrators, Plugins, Secrets, Vectorsearches } from "./resources/catalog.js";
|
|
25
|
+
import { Guardrails } from "./resources/guardrails.js";
|
|
26
|
+
import { Journal, PromptHistory } from "./resources/history.js";
|
|
27
|
+
import { LLMClients } from "./resources/llmclients.js";
|
|
28
|
+
import { LLMHosts } from "./resources/llmhosts.js";
|
|
29
|
+
import { Manifests } from "./resources/manifests.js";
|
|
30
|
+
import { MCPClients } from "./resources/mcpclients.js";
|
|
31
|
+
import { Providers } from "./resources/providers.js";
|
|
32
|
+
import { Proxies } from "./resources/proxies.js";
|
|
33
|
+
import { Vectorstores } from "./resources/vectorstores.js";
|
|
34
|
+
/**
|
|
35
|
+
* A client of a Smarter platform's api.
|
|
36
|
+
*
|
|
37
|
+
* The client's properties group the api's operations:
|
|
38
|
+
*
|
|
39
|
+
* - {@link Smarter.manifests}: apply, validate, get, describe, delete, deploy, undeploy and logs, for any kind
|
|
40
|
+
* - {@link Smarter.llmClients}: LLMClients, and prompting and chatting with them
|
|
41
|
+
* - {@link Smarter.guardrails}, {@link Smarter.mcpClients}, {@link Smarter.vectorstores},
|
|
42
|
+
* {@link Smarter.llmHosts}, {@link Smarter.secrets}, {@link Smarter.plugins},
|
|
43
|
+
* {@link Smarter.orchestrators}, {@link Smarter.vectorsearches}
|
|
44
|
+
* - {@link Smarter.accounts} (and `accounts.users`, `accounts.contacts` and `accounts.userProfiles`)
|
|
45
|
+
* - {@link Smarter.history}, {@link Smarter.journal}, {@link Smarter.providers}, {@link Smarter.proxies}
|
|
46
|
+
* - {@link Smarter.whoami}, {@link Smarter.version}, {@link Smarter.status} and {@link Smarter.kinds}
|
|
47
|
+
*
|
|
48
|
+
* A client holds no open connections of its own: there is nothing to close.
|
|
49
|
+
*/
|
|
50
|
+
export class Smarter {
|
|
51
|
+
/** The client's resolved configuration, without its api key. */
|
|
52
|
+
config;
|
|
53
|
+
/** The http transport, for endpoints that the SDK does not wrap. */
|
|
54
|
+
http;
|
|
55
|
+
#apiKey;
|
|
56
|
+
/** The manifest api, for any resource kind. */
|
|
57
|
+
manifests;
|
|
58
|
+
/** LLMClients. */
|
|
59
|
+
llmClients;
|
|
60
|
+
/** Guardrails. */
|
|
61
|
+
guardrails;
|
|
62
|
+
/** MCPClients. */
|
|
63
|
+
mcpClients;
|
|
64
|
+
/** Vectorstores. */
|
|
65
|
+
vectorstores;
|
|
66
|
+
/** LLMHosts. */
|
|
67
|
+
llmHosts;
|
|
68
|
+
/** Secrets. */
|
|
69
|
+
secrets;
|
|
70
|
+
/** Plugins. */
|
|
71
|
+
plugins;
|
|
72
|
+
/** Orchestrators. */
|
|
73
|
+
orchestrators;
|
|
74
|
+
/** Vectorsearches. */
|
|
75
|
+
vectorsearches;
|
|
76
|
+
/** Accounts, and their users and contacts. */
|
|
77
|
+
accounts;
|
|
78
|
+
/** The history of chat sessions, tool calls and plugin uses. */
|
|
79
|
+
history;
|
|
80
|
+
/** The Smarter Journal. Superusers only. */
|
|
81
|
+
journal;
|
|
82
|
+
/** LLM providers and their models. */
|
|
83
|
+
providers;
|
|
84
|
+
/** Proxies to LLM providers' own apis. */
|
|
85
|
+
proxies;
|
|
86
|
+
/**
|
|
87
|
+
* @param options - The api key, base url, environment, timeout (seconds), retries, headers, `fetch` and logging.
|
|
88
|
+
* @throws {@link SmarterConfigurationError} If no api key is found, or an option or environment variable is invalid.
|
|
89
|
+
*/
|
|
90
|
+
constructor(options = {}) {
|
|
91
|
+
const settings = readSettings();
|
|
92
|
+
const logger = makeLogger(options.logLevel ?? settings.log, options.logger);
|
|
93
|
+
const { apiKey, ...config } = resolveClientConfig(options, settings, logger);
|
|
94
|
+
this.#apiKey = apiKey;
|
|
95
|
+
this.config = config;
|
|
96
|
+
this.http = new SmarterHttpClient({ apiKey, ...config }, { defaultHeaders: options.defaultHeaders, fetch: options.fetch, logger });
|
|
97
|
+
this.manifests = new Manifests(this);
|
|
98
|
+
this.llmClients = new LLMClients(this);
|
|
99
|
+
this.guardrails = new Guardrails(this);
|
|
100
|
+
this.mcpClients = new MCPClients(this);
|
|
101
|
+
this.vectorstores = new Vectorstores(this);
|
|
102
|
+
this.llmHosts = new LLMHosts(this);
|
|
103
|
+
this.secrets = new Secrets(this);
|
|
104
|
+
this.plugins = new Plugins(this);
|
|
105
|
+
this.orchestrators = new Orchestrators(this);
|
|
106
|
+
this.vectorsearches = new Vectorsearches(this);
|
|
107
|
+
this.accounts = new Accounts(this);
|
|
108
|
+
this.history = new PromptHistory(this);
|
|
109
|
+
this.journal = new Journal(this);
|
|
110
|
+
this.providers = new Providers(this);
|
|
111
|
+
this.proxies = new Proxies(this);
|
|
112
|
+
}
|
|
113
|
+
/** The api key, e.g. to use a proxy with a provider's own SDK. */
|
|
114
|
+
get apiKey() {
|
|
115
|
+
return this.#apiKey;
|
|
116
|
+
}
|
|
117
|
+
/** The api's base url, e.g. `https://platform.smarter.sh/api/v1/`. */
|
|
118
|
+
get baseUrl() {
|
|
119
|
+
return this.config.baseUrl;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The owner of the api key: the user, their account, and the platform's environment.
|
|
123
|
+
*
|
|
124
|
+
* @param options - Per-request options.
|
|
125
|
+
* @returns The owner.
|
|
126
|
+
*/
|
|
127
|
+
async whoami(options) {
|
|
128
|
+
return this.#cliData("whoami/", WhoAmI, options);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The platform's version, and the versions of its main Python packages.
|
|
132
|
+
*
|
|
133
|
+
* @param options - Per-request options.
|
|
134
|
+
* @returns The versions.
|
|
135
|
+
*/
|
|
136
|
+
async version(options) {
|
|
137
|
+
return this.#cliData("version/", PlatformVersion, options);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The state of the platform's infrastructure and compute.
|
|
141
|
+
*
|
|
142
|
+
* @param options - Per-request options.
|
|
143
|
+
* @returns The status.
|
|
144
|
+
*/
|
|
145
|
+
async status(options) {
|
|
146
|
+
return this.#cliData("status/", PlatformStatus, options);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The resource kinds that the platform supports, and which of them can be deployed.
|
|
150
|
+
*
|
|
151
|
+
* @param options - Per-request options.
|
|
152
|
+
* @returns The kinds.
|
|
153
|
+
*/
|
|
154
|
+
async kinds(options) {
|
|
155
|
+
return this.#cliData("resources/", z.array(KindInfo), options);
|
|
156
|
+
}
|
|
157
|
+
async #cliData(path, schema, options) {
|
|
158
|
+
const response = await this.http.request("POST", `cli/${path}`, SAMJournalApiEnvelope.extend({ data: schema }), options);
|
|
159
|
+
return response.data;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* The client as JSON, with its api key masked.
|
|
163
|
+
*
|
|
164
|
+
* @returns The base url and the masked api key.
|
|
165
|
+
*/
|
|
166
|
+
toJSON() {
|
|
167
|
+
return { baseUrl: this.baseUrl, apiKey: maskSecret(this.#apiKey) };
|
|
168
|
+
}
|
|
169
|
+
/** @returns e.g. `Smarter(baseUrl="https://platform.smarter.sh/api/v1/", apiKey="****5150")`. */
|
|
170
|
+
toString() {
|
|
171
|
+
return `Smarter(baseUrl=${JSON.stringify(this.baseUrl)}, apiKey=${JSON.stringify(maskSecret(this.#apiKey))})`;
|
|
172
|
+
}
|
|
173
|
+
/** How `console.log` and `util.inspect` show the client: without its api key. */
|
|
174
|
+
[inspect.custom]() {
|
|
175
|
+
return this.toString();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AA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