@wireweave/sdk 0.1.0-beta.0 → 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/README.md +92 -0
- package/dist/index.js +393 -421
- package/dist/index.js.map +1 -1
- package/package.json +23 -23
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# @wireweave/sdk
|
|
2
|
+
|
|
3
|
+
The platform client for Wireweave — a typed HTTP client, token-based auth, and an in-process local tool runner, all behind a single `dispatch()` entry point.
|
|
4
|
+
|
|
5
|
+
## What it does
|
|
6
|
+
|
|
7
|
+
`@wireweave/sdk` is the contract owner shared by the Wireweave CLI, MCP server, and skill packages. It exposes one tool-dispatch surface that routes each call to the right place:
|
|
8
|
+
|
|
9
|
+
- **Local tools** run in-process via `@wireweave/core`, `@wireweave/ux-rules`, and `@wireweave/language-data`. No network call, no API key required.
|
|
10
|
+
- **Remote tools** are proxied to the Wireweave API server (`api-server`) over HTTP. These require an API key (cloud project/wireframe storage, account & billing, hosted reference content such as the grammar and LLM guide).
|
|
11
|
+
|
|
12
|
+
The list of local tools and the endpoint map for remote tools are generated from the api-server contract (`src/generated/`), so consumers never hand-maintain routing.
|
|
13
|
+
|
|
14
|
+
Local dispatch tools:
|
|
15
|
+
|
|
16
|
+
`wireweave_parse` · `wireweave_validate` · `wireweave_render_html_code` · `wireweave_validate_ux` · `wireweave_diff` · `wireweave_analyze` · `wireweave_list_components` · `wireweave_export_json` · `wireweave_export_figma`
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @wireweave/sdk
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Requires Node.js 20+.
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { dispatch, toolEndpoints, type ApiConfig } from '@wireweave/sdk'
|
|
30
|
+
|
|
31
|
+
const apiConfig: ApiConfig = {
|
|
32
|
+
apiUrl: 'https://api.wireweave.org',
|
|
33
|
+
apiKey: process.env.WIREWEAVE_API_KEY ?? '', // empty is fine for local tools
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Local tool — runs in-process, no network, no key needed.
|
|
37
|
+
const parsed = await dispatch(
|
|
38
|
+
'wireweave_parse',
|
|
39
|
+
{ source: 'Page "Home"' },
|
|
40
|
+
{ apiConfig, endpoints: toolEndpoints },
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
// Remote tool — proxied to api-server, requires a valid apiKey.
|
|
44
|
+
const saved = await dispatch(
|
|
45
|
+
'wireweave_cloud_save_wireframe',
|
|
46
|
+
{ name: 'Home', source },
|
|
47
|
+
{ apiConfig, endpoints: toolEndpoints },
|
|
48
|
+
)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Run a local tool directly, bypassing dispatch:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { localDispatch, isLocalDispatchTool } from '@wireweave/sdk'
|
|
55
|
+
|
|
56
|
+
if (isLocalDispatchTool('wireweave_diff')) {
|
|
57
|
+
const result = localDispatch('wireweave_diff', { oldSource, newSource })
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Authentication helpers persist a token at `~/.wireweave/config.json` (`0600`):
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { saveToken, loadToken, verifyToken, clearToken } from '@wireweave/sdk'
|
|
65
|
+
|
|
66
|
+
const check = await verifyToken(token, 'https://api.wireweave.org', '/verify')
|
|
67
|
+
if (check.valid) await saveToken({ token })
|
|
68
|
+
|
|
69
|
+
const stored = await loadToken() // { token, apiUrl? } | null
|
|
70
|
+
await clearToken()
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## API
|
|
74
|
+
|
|
75
|
+
| Export | Description |
|
|
76
|
+
| -------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
77
|
+
| `dispatch(name, args, options)` | Single entry point. Routes local tools to `localDispatch`, remote tools to `callApi`. |
|
|
78
|
+
| `localDispatch(name, args)` | Runs a local tool in-process (parse, validate, render, diff, analyze, export, etc.). |
|
|
79
|
+
| `isLocalDispatchTool(name)` | `true` if the tool is dispatched locally. |
|
|
80
|
+
| `LOCAL_DISPATCH_TOOL_NAMES` | `ReadonlySet<string>` of local tool names. |
|
|
81
|
+
| `callApi(config, endpoint, args, fetchFn?)` | Low-level HTTP call to an api-server endpoint. |
|
|
82
|
+
| `buildRequest(config, endpoint, args?)` | Builds the URL and `RequestInit` for an endpoint (path params, query, body). |
|
|
83
|
+
| `extractCreditInfo(headers)` / `parseErrorMessage(status, body)` | Credit-header parsing and HTTP-status-to-message mapping. |
|
|
84
|
+
| `loadToken` / `saveToken` / `clearToken` / `verifyToken` / `getConfigPath` | Token persistence and verification. |
|
|
85
|
+
| `tools` / `toolEndpoints` | Generated tool definitions and the remote endpoint map (api-server contract). |
|
|
86
|
+
| Types | `ApiConfig`, `ApiResult`, `ApiErrorBody`, `HttpMethod`, `ToolEndpoint`, `CreditInfo`, `LocalToolResult`, `LocalToolContentBlock`, `DispatchOptions`, `AuthOptions`, `StoredConfig`, `VerifyTokenResult` |
|
|
87
|
+
|
|
88
|
+
Part of the [Wireweave monorepo](https://github.com/wireweave/wireweave).
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT
|