@getmodus/sdk 0.2.0 → 0.2.2

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/CHANGELOG.md CHANGED
@@ -1,8 +1,19 @@
1
1
  # Changelog
2
2
 
3
- **Current npm release:** [`0.2.0`](https://www.npmjs.com/package/@getmodus/sdk/v/0.2.0).
3
+ **Current npm release:** [`0.2.2`](https://www.npmjs.com/package/@getmodus/sdk/v/0.2.2).
4
4
 
5
5
 
6
+ ## [Unreleased]
7
+
8
+ ## [0.2.2] — 2026-07-20
9
+
10
+ ## [0.2.1] — 2026-07-20
11
+
12
+ ### Changed
13
+
14
+ - Public README brought to parity with the Python SDK guide (product framing, auth, Modus vs scopes, chat/stream/context, management, pagination, errors).
15
+ - Added `assets/modus-logo.png` / `.svg` for GitHub mirror and package docs.
16
+
6
17
  ## [0.2.0] — 2026-07-20
7
18
 
8
19
  ### Added
@@ -26,8 +37,6 @@
26
37
 
27
38
  - Legacy **`client.skills` / `client.agents`** and **`mgmt.skills` / `mgmt.agents`** accessors — use `scopes` / `workflows`.
28
39
 
29
- ## [Unreleased]
30
-
31
40
  ## [0.1.0] — 2026-07-20
32
41
 
33
42
  ### Added
package/README.md CHANGED
@@ -1,79 +1,226 @@
1
- # @getmodus/sdk
1
+ <p align="center">
2
+ <img
3
+ src="https://raw.githubusercontent.com/modus-data/modus-sdk-typescript/main/assets/modus-logo.png"
4
+ alt="Modus"
5
+ width="280"
6
+ />
7
+ </p>
2
8
 
3
- Official TypeScript client for Modus (pre-release).
9
+ # Modus TypeScript SDK
10
+
11
+ [![npm](https://img.shields.io/npm/v/@getmodus/sdk)](https://www.npmjs.com/package/@getmodus/sdk)
12
+ [![Node.js](https://img.shields.io/node/v/@getmodus/sdk)](https://www.npmjs.com/package/@getmodus/sdk)
13
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
14
+
15
+ Official TypeScript / JavaScript client for Modus — your organization's context layer for AI.
4
16
 
5
17
  **Runtime:** Node.js 18+. Ships **ESM** and **CommonJS**. Not intended for browsers or edge runtimes (uses Node APIs such as `process.env`).
6
18
 
7
- ## Install (coming soon)
19
+ ## What is Modus?
20
+
21
+ Modus is your organization's context layer: it connects assistants to curated knowledge about your data, systems, and workflows so answers use org-specific context instead of generic guesses.
22
+
23
+ - **Modus** — your org-wide assistant (same capability as the Modus home page)
24
+ - **Scopes** — published assistants you chat with, each with its own context and tools
25
+ - **Workflows** — automations that run on a schedule or trigger
26
+ - **Context items** — curated knowledge Modus composes at runtime when answering
27
+
28
+ ## Two clients in one package
29
+
30
+ **`Modus`** is what most people need. Use it to chat with Modus, run scopes, browse context, and inspect workflow runs — the same things you do in the Modus app day to day.
31
+
32
+ **`ModusManagement`** (`@getmodus/sdk/management`) is for org setup: create, update, and deploy scopes, workflows, and context — the CRUD operations you would use in the Modus UI as an admin.
33
+
34
+ If you are getting started, use `Modus` only. Reach for `ModusManagement` when you are automating configuration.
35
+
36
+ ## Installation
8
37
 
9
38
  ```bash
10
- npm install @getmodus/sdk@beta
39
+ npm install @getmodus/sdk
11
40
  ```
12
41
 
13
- ## Usage
14
-
15
- ### ESM (`import`)
42
+ ## Getting started
16
43
 
17
44
  ```ts
18
45
  import { Modus } from '@getmodus/sdk'
19
- import { ModusManagement } from '@getmodus/sdk/management'
20
46
 
21
- const client = new Modus({ apiKey: process.env.MODUS_API_KEY })
22
- const mgmt = new ModusManagement({ apiKey: process.env.MODUS_API_KEY })
47
+ // Reads MODUS_API_KEY from the environment, or pass apiKey explicitly
48
+ const client = new Modus()
49
+
50
+ for await (const scope of (await client.scopes.list()).autoPagingIter()) {
51
+ console.log(scope.name, scope.status)
52
+ }
53
+
54
+ const scope = await client.scopes.get('revenue-analysis')
55
+ console.log(scope.name, scope.description)
23
56
 
24
- const scopes = await client.scopes.list()
25
- const draft = await mgmt.scopes.create({ name: 'Analyst', model: 'claude-sonnet-5' })
57
+ for await (const item of (await client.context.items.list()).autoPagingIter()) {
58
+ console.log(item.uid, item.contextType, item.description ?? item.uid)
59
+ }
26
60
  ```
27
61
 
28
62
  ### CommonJS (`require`)
29
63
 
30
64
  ```js
31
65
  const { Modus } = require('@getmodus/sdk')
32
- const { ModusManagement } = require('@getmodus/sdk/management')
33
-
34
66
  const client = new Modus({ apiKey: process.env.MODUS_API_KEY })
35
67
  ```
36
68
 
37
- ## Examples
38
-
39
- Runnable scripts (mirrored to the public GitHub repo):
69
+ ## Authentication
40
70
 
41
- - `examples/scripts/quickstart.ts` list scopes and context (`Modus`)
42
- - `examples/scripts/modus_chat.ts` — buffered and streaming Modus chat, context compose, conversations
43
- - `examples/scripts/chat.ts` — buffered scope chat with thread follow-up
44
- - `examples/scripts/manage_skill.ts` — create and deploy a scope (`ModusManagement`, `--write` optional)
71
+ Create an API token in the Modus app (**Settings → API Tokens** on your Modus home page). Prefer an environment variable over hardcoding keys in source:
45
72
 
46
73
  ```bash
47
74
  export MODUS_API_KEY=modus_xxx
48
- npx tsx examples/scripts/quickstart.ts
49
75
  ```
50
76
 
51
- From the Modus monorepo (after build):
77
+ ```ts
78
+ const client = new Modus({ apiKey: 'modus_xxx' })
79
+ ```
52
80
 
53
- ```bash
54
- pnpm nx run modus-sdk-typescript:build
55
- MODUS_API_KEY=modus_xxx node --import tsx distribution/clients/typescript/modus-sdk/examples/scripts/quickstart.ts
81
+ ## Using Modus
82
+
83
+ ### Modus vs scopes
84
+
85
+ | Surface | SDK | Use when |
86
+ |---------|-----|----------|
87
+ | **Modus** (org-wide) | `client.modus.*` | Full-environment assistant — same as the Modus home page |
88
+ | **Scope** | `client.scopes.*` | A specific published scope and its configured context/tools |
89
+
90
+ Use `client.modus.chat()` for native Modus — not a scope-id shortcut.
91
+
92
+ ### Org-wide Modus assistant
93
+
94
+ ```ts
95
+ const MODEL = 'claude-sonnet-5'
96
+
97
+ const result = await client.modus.chat('What were our top revenue drivers last quarter?', {
98
+ model: MODEL,
99
+ })
100
+ console.log(result.content, result.threadId)
101
+
102
+ const followUp = await client.modus.chat('Break that down by region.', {
103
+ model: MODEL,
104
+ threadId: result.threadId,
105
+ })
106
+ console.log(followUp.content)
107
+
108
+ const stream = client.modus.chatStream('Summarize this week', { model: MODEL })
109
+ for await (const chunk of stream.textStream()) {
110
+ process.stdout.write(chunk)
111
+ }
112
+
113
+ const ctx = await client.modus.getContext('What tables describe customer churn?', { limit: 10 })
114
+ console.log(ctx.originalCount, ctx.sessionId)
115
+
116
+ for await (const row of (
117
+ await client.modus.conversations.list({ kind: 'modus', pageSize: 10 })
118
+ ).autoPagingIter()) {
119
+ console.log(row.threadId, row.firstMessage)
120
+ }
56
121
  ```
57
122
 
58
- ## Development
123
+ ### Scopes
59
124
 
60
- From the Modus monorepo root:
125
+ ```ts
126
+ const MODEL = 'claude-sonnet-5'
61
127
 
62
- ```bash
63
- pnpm nx run modus-sdk-typescript:generate
64
- pnpm nx run modus-sdk-typescript:build
65
- pnpm nx run modus-sdk-typescript:test
128
+ const result = await client.scopes.chat(scopeId, 'Hello', { model: MODEL })
129
+ console.log(result.content, result.threadId)
130
+
131
+ const stream = client.scopes.chatStream(scopeId, 'Hi', { model: MODEL })
132
+ for await (const chunk of stream.textStream()) {
133
+ process.stdout.write(chunk)
134
+ }
66
135
  ```
67
136
 
68
- See [`../dev-examples/`](../dev-examples/) for additional runnable scripts (monorepo only).
137
+ ### Context
69
138
 
70
- ```bash
71
- # Batch smoke (from repo root; uses .env for MODUS_API_KEY / MODUS_BASE_URL)
72
- bash distribution/clients/typescript/dev-examples/run_all.sh
73
- bash distribution/clients/typescript/dev-examples/run_all.sh --write
74
- bash distribution/clients/typescript/dev-examples/run_all.sh --chat # LLM credits; needs healthy agent backend
139
+ ```ts
140
+ for await (const item of (await client.context.items.list()).autoPagingIter()) {
141
+ console.log(item.uid, item.description ?? item.uid)
142
+ }
75
143
  ```
76
144
 
77
- Shipped `chat.ts` accepts optional `MODUS_SCOPE_ID` to pick the scope. Chat may return `INTERNAL_ERROR` when the target environment's agent runtime is down — that is not an SDK bug.
145
+ ### Workflows
146
+
147
+ ```ts
148
+ const workflow = await client.workflows.get(workflowId)
149
+ for await (const run of (await client.workflows.runs.list(workflowId, { pageSize: 20 })).autoPagingIter()) {
150
+ console.log(run.id, run.status)
151
+ }
152
+ ```
153
+
154
+ Workflow chat is not on the public PAT surface. Use `client.modus.chat()` for org-wide conversation or `client.scopes.chat()` for a published scope.
155
+
156
+ ## Managing your org
157
+
158
+ ```ts
159
+ import { ModusManagement } from '@getmodus/sdk/management'
160
+
161
+ const mgmt = new ModusManagement() // reads MODUS_API_KEY
162
+ const scope = await mgmt.scopes.create({ name: 'Analyst', model: 'claude-sonnet-5' })
163
+ await mgmt.scopes.deploy(scope.id)
164
+
165
+ // Create returns contextItemId (also available as .uid); list/get use .uid
166
+ const note = await mgmt.context.createNote('Title', 'Body')
167
+ console.log(note.contextItemId, note.uid) // same UUID
168
+ ```
169
+
170
+ Requires a token with write access to scopes and workflows (same as the Modus UI).
171
+
172
+ ## Pagination
173
+
174
+ List endpoints return a `Page<T>`. Iterate the current page, or use `.autoPagingIter()` for all pages:
175
+
176
+ ```ts
177
+ for await (const scope of (await client.scopes.list()).autoPagingIter()) {
178
+ console.log(scope.name)
179
+ }
180
+ ```
181
+
182
+ `client.modus.conversations.list()` accepts `kind: 'modus' | 'skills' | 'all'` (default `'all'`).
183
+
184
+ ## Error handling
185
+
186
+ ```ts
187
+ import {
188
+ Modus,
189
+ NotFoundError,
190
+ AuthenticationError,
191
+ RateLimitError,
192
+ ModusError,
193
+ } from '@getmodus/sdk'
194
+
195
+ try {
196
+ await client.scopes.get(999)
197
+ } catch (e) {
198
+ if (e instanceof NotFoundError) {
199
+ console.log('Scope not found')
200
+ } else if (e instanceof AuthenticationError) {
201
+ console.log('Check your MODUS_API_KEY')
202
+ } else if (e instanceof RateLimitError) {
203
+ console.log(`Rate limited. Retry after ${e.retryAfter}s`)
204
+ } else if (e instanceof ModusError) {
205
+ console.log(`API error ${e.statusCode}: ${e.message}`)
206
+ } else {
207
+ throw e
208
+ }
209
+ }
210
+ ```
211
+
212
+ ## Examples
213
+
214
+ Runnable scripts ship in this repository:
215
+
216
+ - `examples/scripts/quickstart.ts` — list scopes and context (`Modus`)
217
+ - `examples/scripts/modus_chat.ts` — buffered and streaming Modus chat, context compose, conversations
218
+ - `examples/scripts/chat.ts` — buffered scope chat with thread follow-up
219
+ - `examples/scripts/manage_skill.ts` — create and deploy a scope (`ModusManagement`, `--write` optional)
220
+
221
+ ```bash
222
+ export MODUS_API_KEY=modus_xxx
223
+ npx tsx examples/scripts/quickstart.ts
224
+ ```
78
225
 
79
226
  See [CHANGELOG.md](./CHANGELOG.md) for release history.
Binary file
@@ -0,0 +1,13 @@
1
+ <svg width="285" height="61" viewBox="0 0 285 61" fill="none" color="#3262FF" xmlns="http://www.w3.org/2000/svg">
2
+ <g clip-path="url(#clip0_286_163)">
3
+ <path d="M55.2983 42.8834C54.751 42.8368 54.2105 42.808 53.6606 42.7975C43.9042 42.4159 33.1793 49.1184 31.4067 59.7994C31.3068 60.3796 31.2328 60.9615 31.186 61.5553H24.4956C24.4488 60.9615 24.3748 60.3796 24.2749 59.7994C22.5023 49.1183 11.7775 42.4158 2.021 42.7975C1.4711 42.808 0.930604 42.8368 0.383301 42.8834V33.9069C1.12817 33.9537 1.85781 34.0252 2.59521 34.1207C15.2942 35.53 26.8692 45.713 27.8403 58.0631C28.8114 45.7131 40.3875 35.5301 53.0864 34.1207C53.8238 34.0252 54.5535 33.9537 55.2983 33.9069V42.8834Z" fill="currentColor"/>
4
+ <path d="M55.301 18.2284C54.7538 18.2751 54.2131 18.3038 53.6633 18.3143C43.9068 18.696 33.182 11.9935 31.4094 1.31238C31.3095 0.732203 31.2355 0.15036 31.1887 -0.443481H24.4983C24.4515 0.150316 24.3775 0.732243 24.2776 1.31238C22.505 11.9934 11.7802 18.6959 2.02368 18.3143C1.47379 18.3038 0.933275 18.2751 0.385986 18.2284V27.205C1.13082 27.1581 1.86052 27.0867 2.5979 26.9911C15.2955 25.5819 26.8698 15.4008 27.843 3.05261C28.8162 15.4009 40.3914 25.582 53.0891 26.9911C53.8264 27.0866 54.5562 27.1581 55.301 27.205V18.2284Z" fill="currentColor"/>
5
+ <path d="M27.8416 15.1049C27.8416 15.1049 29.1317 23.1704 32.1291 26.1678C35.1265 29.1651 43.192 30.4553 43.192 30.4553C43.192 30.4553 35.1265 31.7455 32.1291 34.7428C29.1317 37.7402 27.8416 45.8057 27.8416 45.8057C27.8416 45.8057 26.5514 37.7402 23.554 34.7428C20.5567 31.7455 12.4911 30.4553 12.4911 30.4553C12.4911 30.4553 20.5567 29.1651 23.554 26.1678C26.5514 23.1704 27.8416 15.1049 27.8416 15.1049Z" fill="currentColor"/>
6
+ <path d="M69.9199 53.5372V18.4094H76.2005V22.7183C78.2454 19.0667 81.4587 17.387 85.7675 17.387C90.5876 17.387 94.1661 19.724 95.8458 23.6677C98.1097 19.4319 101.761 17.387 106.362 17.387C114.469 17.387 118.924 22.2801 118.924 31.0438V53.5372H111.913V31.4089C111.913 26.5159 109.576 23.8137 105.121 23.8137C100.958 23.8137 97.9637 27.0271 97.9637 31.628V53.5372H90.8797V31.4089C90.8797 26.5159 88.5427 23.8137 84.2339 23.8137C79.9981 23.8137 77.0039 27.0271 77.0039 31.628V53.5372H69.9199ZM145.316 54.5597C134.653 54.5597 127.204 47.1105 127.204 35.9368C127.204 24.8361 134.653 17.387 145.316 17.387C156.051 17.387 163.427 24.8361 163.427 35.9368C163.427 47.1105 156.051 54.5597 145.316 54.5597ZM134.507 35.9368C134.507 43.2399 138.889 48.133 145.316 48.133C151.815 48.133 156.124 43.2399 156.124 35.9368C156.124 28.7068 151.815 23.8137 145.316 23.8137C138.889 23.8137 134.507 28.7068 134.507 35.9368ZM186.865 54.5597C176.86 54.5597 169.995 47.1105 169.995 35.9368C169.995 24.8361 176.86 17.387 186.865 17.387C191.978 17.387 196.14 19.2858 198.331 22.7183V2.41571H205.342V53.5372H199.062V48.6442C196.725 52.3687 192.343 54.5597 186.865 54.5597ZM177.298 35.9368C177.298 43.2399 181.607 48.133 187.961 48.133C194.315 48.133 198.477 43.2399 198.477 35.9368C198.477 28.7068 194.315 23.8137 187.961 23.8137C181.607 23.8137 177.298 28.7068 177.298 35.9368ZM229.692 54.5597C221.148 54.5597 215.89 49.3014 215.89 39.5884V18.4094H222.974V38.9311C222.974 45.2117 225.895 48.133 231.007 48.133C236.338 48.133 239.771 44.3354 239.771 38.712V18.4094H246.855V53.5372H240.574V49.5205C238.237 52.953 234.22 54.5597 229.692 54.5597ZM270.113 54.5597C260.619 54.5597 254.996 50.7621 254.631 43.532H261.934C262.299 47.0375 265.147 48.7902 270.259 48.7902C274.933 48.7902 277.781 46.8184 277.781 43.605C277.781 40.9759 275.81 39.4423 272.158 39.0771L266.535 38.4929C259.962 37.8356 255.799 34.1841 255.799 28.3416C255.799 21.6228 261.422 17.387 270.04 17.387C278.804 17.387 284.208 21.0385 284.646 28.1956H277.562C277.343 24.8361 274.568 23.1564 269.967 23.1564C265.585 23.1564 262.81 24.9822 262.81 27.9765C262.81 30.5325 264.709 31.9201 268.799 32.4313L274.495 33.0886C281.141 33.8189 284.938 37.5435 284.938 43.3129C284.938 50.1778 279.169 54.5597 270.113 54.5597Z" fill="currentColor"/>
7
+ </g>
8
+ <defs>
9
+ <clipPath id="clip0_286_163">
10
+ <rect width="285" height="61" fill="currentColor"/>
11
+ </clipPath>
12
+ </defs>
13
+ </svg>