hci-atrium 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 +21 -0
- package/README.md +182 -0
- package/dist/atrium.d.ts +522 -0
- package/dist/atrium.d.ts.map +1 -0
- package/dist/atrium.js +806 -0
- package/dist/atrium.js.map +1 -0
- package/dist/auth.d.ts +85 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +369 -0
- package/dist/auth.js.map +1 -0
- package/dist/by.d.ts +84 -0
- package/dist/by.d.ts.map +1 -0
- package/dist/by.js +87 -0
- package/dist/by.js.map +1 -0
- package/dist/decider.d.ts +40 -0
- package/dist/decider.d.ts.map +1 -0
- package/dist/decider.js +76 -0
- package/dist/decider.js.map +1 -0
- package/dist/discovery.d.ts +15 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +38 -0
- package/dist/discovery.js.map +1 -0
- package/dist/env.d.ts +11 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +28 -0
- package/dist/env.js.map +1 -0
- package/dist/errors.d.ts +67 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +86 -0
- package/dist/errors.js.map +1 -0
- package/dist/files.d.ts +7 -0
- package/dist/files.d.ts.map +1 -0
- package/dist/files.js +2 -0
- package/dist/files.js.map +1 -0
- package/dist/http.d.ts +11 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +21 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/models.d.ts +456 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +487 -0
- package/dist/models.js.map +1 -0
- package/dist/pkce.d.ts +16 -0
- package/dist/pkce.d.ts.map +1 -0
- package/dist/pkce.js +40 -0
- package/dist/pkce.js.map +1 -0
- package/dist/react/index.d.ts +37 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +89 -0
- package/dist/react/index.js.map +1 -0
- package/dist/rooms/armed-set.d.ts +33 -0
- package/dist/rooms/armed-set.d.ts.map +1 -0
- package/dist/rooms/armed-set.js +65 -0
- package/dist/rooms/armed-set.js.map +1 -0
- package/dist/rooms/brokers.d.ts +62 -0
- package/dist/rooms/brokers.d.ts.map +1 -0
- package/dist/rooms/brokers.js +109 -0
- package/dist/rooms/brokers.js.map +1 -0
- package/dist/rooms/codec.d.ts +100 -0
- package/dist/rooms/codec.d.ts.map +1 -0
- package/dist/rooms/codec.js +101 -0
- package/dist/rooms/codec.js.map +1 -0
- package/dist/rooms/index.d.ts +40 -0
- package/dist/rooms/index.d.ts.map +1 -0
- package/dist/rooms/index.js +45 -0
- package/dist/rooms/index.js.map +1 -0
- package/dist/rooms/offer-capture.d.ts +96 -0
- package/dist/rooms/offer-capture.d.ts.map +1 -0
- package/dist/rooms/offer-capture.js +338 -0
- package/dist/rooms/offer-capture.js.map +1 -0
- package/dist/rooms/offer-transcription.d.ts +63 -0
- package/dist/rooms/offer-transcription.d.ts.map +1 -0
- package/dist/rooms/offer-transcription.js +231 -0
- package/dist/rooms/offer-transcription.js.map +1 -0
- package/dist/rooms/participant.d.ts +35 -0
- package/dist/rooms/participant.d.ts.map +1 -0
- package/dist/rooms/participant.js +53 -0
- package/dist/rooms/participant.js.map +1 -0
- package/dist/rooms/recorder.d.ts +74 -0
- package/dist/rooms/recorder.d.ts.map +1 -0
- package/dist/rooms/recorder.js +157 -0
- package/dist/rooms/recorder.js.map +1 -0
- package/dist/rooms/room.d.ts +542 -0
- package/dist/rooms/room.d.ts.map +1 -0
- package/dist/rooms/room.js +1357 -0
- package/dist/rooms/room.js.map +1 -0
- package/dist/rooms/snippet.d.ts +48 -0
- package/dist/rooms/snippet.d.ts.map +1 -0
- package/dist/rooms/snippet.js +70 -0
- package/dist/rooms/snippet.js.map +1 -0
- package/dist/rooms/sse.d.ts +102 -0
- package/dist/rooms/sse.d.ts.map +1 -0
- package/dist/rooms/sse.js +347 -0
- package/dist/rooms/sse.js.map +1 -0
- package/dist/rooms/standing-source.d.ts +190 -0
- package/dist/rooms/standing-source.d.ts.map +1 -0
- package/dist/rooms/standing-source.js +431 -0
- package/dist/rooms/standing-source.js.map +1 -0
- package/dist/rooms/transcriber.d.ts +81 -0
- package/dist/rooms/transcriber.d.ts.map +1 -0
- package/dist/rooms/transcriber.js +111 -0
- package/dist/rooms/transcriber.js.map +1 -0
- package/dist/rooms/transport-shared.d.ts +28 -0
- package/dist/rooms/transport-shared.d.ts.map +1 -0
- package/dist/rooms/transport-shared.js +42 -0
- package/dist/rooms/transport-shared.js.map +1 -0
- package/dist/rooms/transport.d.ts +161 -0
- package/dist/rooms/transport.d.ts.map +1 -0
- package/dist/rooms/transport.js +258 -0
- package/dist/rooms/transport.js.map +1 -0
- package/dist/shaping/assets.d.ts +42 -0
- package/dist/shaping/assets.d.ts.map +1 -0
- package/dist/shaping/assets.js +77 -0
- package/dist/shaping/assets.js.map +1 -0
- package/dist/shaping/chat.d.ts +39 -0
- package/dist/shaping/chat.d.ts.map +1 -0
- package/dist/shaping/chat.js +62 -0
- package/dist/shaping/chat.js.map +1 -0
- package/dist/shaping/index.d.ts +14 -0
- package/dist/shaping/index.d.ts.map +1 -0
- package/dist/shaping/index.js +13 -0
- package/dist/shaping/index.js.map +1 -0
- package/dist/shaping/library.d.ts +84 -0
- package/dist/shaping/library.d.ts.map +1 -0
- package/dist/shaping/library.js +288 -0
- package/dist/shaping/library.js.map +1 -0
- package/dist/shaping/request.d.ts +47 -0
- package/dist/shaping/request.d.ts.map +1 -0
- package/dist/shaping/request.js +25 -0
- package/dist/shaping/request.js.map +1 -0
- package/dist/shaping/rooms.d.ts +128 -0
- package/dist/shaping/rooms.d.ts.map +1 -0
- package/dist/shaping/rooms.js +330 -0
- package/dist/shaping/rooms.js.map +1 -0
- package/dist/shaping/sources.d.ts +29 -0
- package/dist/shaping/sources.d.ts.map +1 -0
- package/dist/shaping/sources.js +51 -0
- package/dist/shaping/sources.js.map +1 -0
- package/dist/shaping/structured.d.ts +47 -0
- package/dist/shaping/structured.d.ts.map +1 -0
- package/dist/shaping/structured.js +115 -0
- package/dist/shaping/structured.js.map +1 -0
- package/dist/storage.d.ts +36 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +86 -0
- package/dist/storage.js.map +1 -0
- package/dist/transcribe-stream.d.ts +81 -0
- package/dist/transcribe-stream.d.ts.map +1 -0
- package/dist/transcribe-stream.js +253 -0
- package/dist/transcribe-stream.js.map +1 -0
- package/dist/transcribe.d.ts +57 -0
- package/dist/transcribe.d.ts.map +1 -0
- package/dist/transcribe.js +267 -0
- package/dist/transcribe.js.map +1 -0
- package/dist/types.d.ts +20 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Anders Petruschke
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# hci-atrium
|
|
2
|
+
|
|
3
|
+
The TypeScript client for Atrium. Its flagship module is **"Sign in with
|
|
4
|
+
Atrium"** — OAuth 2.0 Authorization Code + PKCE against your Atrium instance — plus an
|
|
5
|
+
authenticated `fetch` that every future SDK module builds on. React bindings ship in the same
|
|
6
|
+
package under the `hci-atrium/react` subpath.
|
|
7
|
+
|
|
8
|
+
- **Zero runtime dependencies** (PKCE uses the platform's WebCrypto).
|
|
9
|
+
- **ESM + TypeScript strict.** Plain `tsc` build, no bundler required.
|
|
10
|
+
- **SSR/import-safe** — importing the package on a server never throws; browser APIs are touched
|
|
11
|
+
only at call time.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
pnpm add hci-atrium
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or `npm install hci-atrium`.
|
|
20
|
+
|
|
21
|
+
## Register an app
|
|
22
|
+
|
|
23
|
+
An app is registered on an Atrium **project**, next to its API keys (Capabilities → Apps). You
|
|
24
|
+
give it a display name and the redirect URIs it will use (your app's https origins, plus loopback
|
|
25
|
+
for local dev) and get back a public **`client_id`**. There is **no client secret** — these are
|
|
26
|
+
public clients and PKCE is the proof. Only **project members** can sign in, checked live on every
|
|
27
|
+
request, so removing a member ends their app sessions immediately.
|
|
28
|
+
|
|
29
|
+
## Quickstart (React)
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import { Atrium } from "hci-atrium"
|
|
33
|
+
import { AtriumProvider, RequireSignIn, useUser } from "hci-atrium/react"
|
|
34
|
+
|
|
35
|
+
const atrium = new Atrium({
|
|
36
|
+
baseUrl: "https://atrium.example.edu",
|
|
37
|
+
clientId: "your-registered-client-id",
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
function App() {
|
|
41
|
+
return (
|
|
42
|
+
<AtriumProvider atrium={atrium}>
|
|
43
|
+
<RequireSignIn>
|
|
44
|
+
<Dashboard />
|
|
45
|
+
</RequireSignIn>
|
|
46
|
+
</AtriumProvider>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function Dashboard() {
|
|
51
|
+
const user = useUser() // undefined while loading, null when signed out, else the user
|
|
52
|
+
return <p>Signed in as {user?.email}</p>
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`<RequireSignIn>` renders its children once the user is signed in and a minimal "Sign in with
|
|
57
|
+
Atrium" button otherwise (pass `fallback` for your own landing page). The callback that Atrium
|
|
58
|
+
redirects back to is handled automatically — no route or effect to wire up.
|
|
59
|
+
|
|
60
|
+
## Core API (no framework)
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
const atrium = new Atrium({ baseUrl, clientId })
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
| Member | Description |
|
|
67
|
+
| --- | --- |
|
|
68
|
+
| `new Atrium({ baseUrl, clientId })` | Args take precedence over the `ATRIUM_BASE_URL` / `ATRIUM_CLIENT_ID` env vars. `baseUrl` is required. |
|
|
69
|
+
| `atrium.auth.signIn(opts?)` | Full-page redirect PKCE sign-in. `opts.redirectUri` overrides the default (current origin + path); `opts.scope` sets the OAuth scope. Called while signed in, it re-authenticates. |
|
|
70
|
+
| `atrium.auth.user` | The signed-in user (`{ id, email, … }`) or `null`. |
|
|
71
|
+
| `atrium.auth.signOut()` | Revokes the refresh token, clears storage, and emits a change. |
|
|
72
|
+
| `atrium.auth.onChange(cb)` | Subscribe to user changes; returns an unsubscribe function. |
|
|
73
|
+
| `atrium.auth.onError(cb)` | Subscribe to auth errors (state mismatch, token exchange, refresh). |
|
|
74
|
+
| `atrium.auth.ready()` | Resolves once initial callback handling / session resume settles. |
|
|
75
|
+
| `atrium.fetch(path, init?)` | `fetch` against the instance with the bearer token attached, silent refresh, and a one-shot 401 retry. Relative paths resolve against `baseUrl`. |
|
|
76
|
+
|
|
77
|
+
### How it behaves
|
|
78
|
+
|
|
79
|
+
- **Callback handled automatically.** On construction (browser only) the SDK detects `?code&state`
|
|
80
|
+
on the current URL, validates `state`, exchanges the code + PKCE verifier at the token endpoint,
|
|
81
|
+
stores the tokens, strips the params via `history.replaceState`, loads `/v1/users/me`, and emits a
|
|
82
|
+
change. Failures (state mismatch, exchange error, or `?error=` from a denied sign-in) surface via
|
|
83
|
+
`onError`, never silently.
|
|
84
|
+
- **Endpoints are discovered** from `{baseUrl}/.well-known/oauth-authorization-server` (RFC 8414),
|
|
85
|
+
falling back to the conventional `/oauth/*` paths, and cached.
|
|
86
|
+
- **Tokens live in `localStorage`**, namespaced by `baseUrl` + `clientId`, so multiple `Atrium`
|
|
87
|
+
instances never collide. The PKCE verifier + state live in `sessionStorage` across the redirect.
|
|
88
|
+
- **Refresh is silent and single-flight**: proactive when the access token nears expiry, reactive
|
|
89
|
+
(retry once) on a 401, and concurrent callers share one refresh. If refresh fails, the SDK drops
|
|
90
|
+
to a signed-out state and emits a change.
|
|
91
|
+
|
|
92
|
+
## Phase-1 surface
|
|
93
|
+
|
|
94
|
+
Beyond auth, the client exposes the library / assets / sources / sessions / rooms namespaces plus
|
|
95
|
+
`chat` and `embed`. Every method takes an **options object** with `filters` kept nested
|
|
96
|
+
(`search("rain", { modality, filters: { … } })`); names are **camelCase**, translated to the wire's
|
|
97
|
+
snake_case in one place (the shaping layer). Authenticate with an OAuth `clientId` **or** an
|
|
98
|
+
`apiKey` — the latter works in the browser too (a one-time console note points at PKCE for hosted
|
|
99
|
+
apps).
|
|
100
|
+
|
|
101
|
+
| Member | Description |
|
|
102
|
+
| --- | --- |
|
|
103
|
+
| `library.search(query?, opts?)` | Semantic search — text, `like` (an asset/hit/id), `image`/`audio`/`video`, or `vector`. `matchBy` (weighted map), tag facets, and the long tail ride `filters`. |
|
|
104
|
+
| `library.searchByExamples(positives, opts?)` | Mood-board search over a set of example assets (`method` defaults to `"cav"`). Seeds are `Asset` or `by.asset(id)`. |
|
|
105
|
+
| `library.compare(a, b, opts?)` | Similarity of two operands (`Asset` / text / `by.*`), raw + calibrated. `opts.space` forces the embedding space. |
|
|
106
|
+
| `library.enrich(query, opts)` | Pull external candidates into the library; `opts.preview` is a dry-run. Returns the raw payload. |
|
|
107
|
+
| `assets.list(opts?)` / `assets.get(id, opts?)` / `assets.upload(file, opts?)` | Browse, fetch, and upload assets. `file` is a `Blob`/`File` or a URL string. |
|
|
108
|
+
| `sources.list()` / `sources.search(query, opts?)` / `sources.import(opts)` | External-provider gateway — read-only fan-out search, then import a `Candidate`. |
|
|
109
|
+
| `sessions.start(opts?)` / `sessions.resume(id)` / `sessions.event(id, type, opts?)` | Durable, append-only session logs. |
|
|
110
|
+
| `rooms.open(opts?)` / `rooms.get(id)` / `rooms.list()` / `rooms.join(code)` | Live [`Room`](#live-rooms) handles — `open`/`get`/`list` are authenticated, `join(code)` is a loginless participant. |
|
|
111
|
+
| `chat(messages, opts?)` | Chat completion. Pass `responseFormat` a **Zod** schema for validated structured output (Zod is an optional peer dep). |
|
|
112
|
+
| `embed(opts)` | Embed exactly one of `text` / `image` / `audio` / `video` into a vector; `model` is required. |
|
|
113
|
+
| `transcribe(audio, opts?)` | Speech-to-text over a multipart audio upload; `opts.verbose` fills `.language` / `.duration` / `.segments`. |
|
|
114
|
+
| `by.*` | Operand grammar for `searchByExamples` / `compare`: `by.asset` / `by.text` / `by.file` / `by.concept`, and `by.vector([…])` — the only way to pass a raw vector. |
|
|
115
|
+
| `Decider({ margin, dwell })` | N-way hysteresis winner-selection over a live score stream — `update(scores)` returns a new winner only on a real switch. |
|
|
116
|
+
| `close()` / `await using` | Aborts in-flight requests; `AbortSignal` is accepted per call via `opts.signal`. |
|
|
117
|
+
|
|
118
|
+
### Live rooms
|
|
119
|
+
|
|
120
|
+
A `Room` is pure live transport over one WebSocket — text signals *and* the ephemeral binary
|
|
121
|
+
audio-analysis stream. `room.on(type, handler)` registers a handler (its return value auto-replies to
|
|
122
|
+
a matching `room.request(...)`); `room.send(type, payload, { to })` fans out; player controls
|
|
123
|
+
(`play` / `configureLayers` / `clearLayer` / `clearAll` / `setLayerEffects` / `queryLayers` /
|
|
124
|
+
`watchLayers` / `playerUrl`) drive the hosted Player; `room.audioSignals(cb)` decodes the
|
|
125
|
+
loudness/spectrum/beat stream. `connect()` opens the socket (every wire method calls it for you);
|
|
126
|
+
`close()` / `await using` / a passed `AbortSignal` tears it down.
|
|
127
|
+
|
|
128
|
+
Not yet ported (environment- or broker-bound, tracked as parity exceptions): `record(into=session)`
|
|
129
|
+
host bridging, and `audioVectors` / `audioScores` (the embed/chat-broker protocol). Audio-signal
|
|
130
|
+
*consumption* is complete. In Node <22 pass a `WebSocketCtor` (e.g. from `ws`); browsers and Node ≥22
|
|
131
|
+
use the global.
|
|
132
|
+
|
|
133
|
+
Errors derive from `AtriumError`: HTTP failures are `APIError` (401/403 → `AuthError`, 429/5xx →
|
|
134
|
+
`TransientAuthError`), and caller mistakes (mutually-exclusive inputs, unsupported filters) are
|
|
135
|
+
`InvalidArgumentError`.
|
|
136
|
+
|
|
137
|
+
## Quickstart (search + play)
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
import { Atrium } from "hci-atrium"
|
|
141
|
+
|
|
142
|
+
const atrium = new Atrium({ baseUrl: "https://atrium.example.edu", apiKey: "atr_…" })
|
|
143
|
+
const [hit] = await atrium.library.search("distant thunder", { modality: "audio" })
|
|
144
|
+
if (hit) new Audio(hit.asset.contentUrl).play() // public, no-auth, cache-friendly URL
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Quickstart (join a room, react to a signal)
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
import { joinRoom, Decider } from "hci-atrium"
|
|
151
|
+
|
|
152
|
+
// Loginless: a participant joins by connect code (no account, no client).
|
|
153
|
+
await using room = await joinRoom("ABC12345", { baseUrl: "https://atrium.example.edu" })
|
|
154
|
+
|
|
155
|
+
// React to what peers broadcast; a returned value auto-replies to a request().
|
|
156
|
+
room.on("scene.change", (e) => console.log("scene →", e.payload.name))
|
|
157
|
+
|
|
158
|
+
// Consume the live audio-analysis stream and switch mood beds with hysteresis.
|
|
159
|
+
const mood = new Decider({ margin: 0.15, dwell: 2 })
|
|
160
|
+
room.audioSignals((sig) => {
|
|
161
|
+
if (sig.kind !== "frame") return
|
|
162
|
+
const winner = mood.update({ calm: 1 - sig.frame.level, intense: sig.frame.level })
|
|
163
|
+
if (winner) room.send("mood", { winner })
|
|
164
|
+
})
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Honest caveat: the guard is UX, not secrecy
|
|
168
|
+
|
|
169
|
+
For a static single-page app the client-side guard is **user experience, not a security boundary**
|
|
170
|
+
— the bundle is public and anyone can read it. What's actually protected is **every Atrium call**:
|
|
171
|
+
the token carries the app's project-scoped access, membership is verified live on the server, and no
|
|
172
|
+
app token can reach a project's management surface. Put secrets in an Atrium session or a
|
|
173
|
+
server-side API key, never in the app bundle.
|
|
174
|
+
|
|
175
|
+
## Development
|
|
176
|
+
|
|
177
|
+
```sh
|
|
178
|
+
pnpm install
|
|
179
|
+
pnpm build # tsc → dist/ (.js + .d.ts)
|
|
180
|
+
pnpm test # vitest (mocked fetch, no live server)
|
|
181
|
+
pnpm lint # biome check
|
|
182
|
+
```
|