@agent-commons/sdk 0.4.0 → 0.5.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Agent Commons
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,230 @@
1
+ # `@agent-commons/sdk`
2
+
3
+ The official TypeScript SDK for Agent Commons. Build and run agents, stream
4
+ responses, manage tools and workflows, work with persistent agent computers,
5
+ and access the wider Agent Commons platform through one typed client.
6
+
7
+ - TypeScript-first with bundled declarations
8
+ - ESM and CommonJS builds
9
+ - Node.js 18+, modern browsers, and edge runtimes
10
+ - Streaming agent, task, workflow, and A2A events
11
+ - No runtime dependencies
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install @agent-commons/sdk
17
+ ```
18
+
19
+ ```bash
20
+ pnpm add @agent-commons/sdk
21
+ ```
22
+
23
+ ## Get a developer API key
24
+
25
+ Create a project-scoped key in **Agent Commons → Settings → Developer API
26
+ keys**. Choose the project, scopes, and expiration, then copy the `csk_*` key
27
+ when it is shown.
28
+
29
+ Keep keys on the server. Do not embed them in browser bundles, mobile apps, or
30
+ source control.
31
+
32
+ ## Quick start
33
+
34
+ ```ts
35
+ import { CommonsClient } from "@agent-commons/sdk";
36
+
37
+ const commons = new CommonsClient({
38
+ apiKey: process.env.AGENT_COMMONS_API_KEY,
39
+ });
40
+
41
+ const { data: agent } = await commons.agents.create({
42
+ name: "Research assistant",
43
+ instructions: "Research carefully and cite your sources.",
44
+ modelProvider: "openai",
45
+ modelId: "gpt-5.4-mini",
46
+ });
47
+
48
+ const result = await commons.run.once({
49
+ agentId: agent.agentId,
50
+ messages: [{ role: "user", content: "Summarize the latest session." }],
51
+ });
52
+
53
+ console.log(result);
54
+ ```
55
+
56
+ `baseUrl` defaults to `https://api.agentcommons.io`.
57
+
58
+ ## Stream a run
59
+
60
+ ```ts
61
+ for await (const event of commons.agents.stream({
62
+ agentId: "agt_...",
63
+ messages: [{ role: "user", content: "Draft a launch plan." }],
64
+ })) {
65
+ if (event.type === "token") {
66
+ process.stdout.write(event.content ?? "");
67
+ }
68
+
69
+ if (event.type === "final") {
70
+ console.log("\nDone");
71
+ }
72
+ }
73
+ ```
74
+
75
+ Streaming is implemented with async generators and works anywhere the Fetch
76
+ API and readable response streams are available.
77
+
78
+ ## Core resources
79
+
80
+ The client groups methods by platform resource:
81
+
82
+ | Namespace | Capabilities |
83
+ | --- | --- |
84
+ | `agents` | Agents, runtimes, autonomy, tools, knowledge, computers |
85
+ | `sessions` | Create, list, inspect, rename, and delete sessions |
86
+ | `tasks` | Tasks, scheduling, execution, cancellation, streaming |
87
+ | `workflows` | Build, fork, run, approve, stream, and expose webhooks |
88
+ | `tools`, `toolKeys`, `toolPermissions` | Tools, encrypted credentials, access |
89
+ | `mcp`, `skills`, `memory` | MCP servers, reusable skills, agent memory |
90
+ | `files`, `library` | Multipart uploads, content, metadata, grants, share links |
91
+ | `projects` | Agent-created code projects, previews, computer and GitHub export |
92
+ | `spaces` | Collaborative spaces, members, messages, and RTC tickets |
93
+ | `oauth` | Connected accounts and provider authorization |
94
+ | `wallets`, `credits`, `billing` | Wallets, x402, credits, plans, invoices |
95
+ | `activity`, `logs`, `usage` | Activity, observability, tokens, and cost |
96
+ | `a2a` | Agent-to-Agent cards, tasks, cancellation, and streaming |
97
+ | `developer` | Developer projects and project-scoped API keys |
98
+
99
+ Every namespace is available from the same client:
100
+
101
+ ```ts
102
+ const [{ data: agents }, { data: library }, { data: projects }] =
103
+ await Promise.all([
104
+ commons.agents.list(),
105
+ commons.library.list({ favorite: true, limit: 20 }),
106
+ commons.projects.list("agt_..."),
107
+ ]);
108
+ ```
109
+
110
+ ## Files and library
111
+
112
+ ```ts
113
+ const { data: uploaded } = await commons.files.upload(
114
+ [{ data: new Blob(["hello"]), name: "hello.txt" }],
115
+ { agentId: "agt_...", storageProvider: "s3" },
116
+ );
117
+
118
+ const { data: content } = await commons.files.content(uploaded[0].fileId, {
119
+ maxChars: 20_000,
120
+ includeDownloadUrl: true,
121
+ });
122
+ ```
123
+
124
+ ## Persistent agent computers
125
+
126
+ ```ts
127
+ await commons.agents.updateComputerConfig("agt_...", {
128
+ enabled: true,
129
+ resourceProfile: "standard",
130
+ });
131
+
132
+ await commons.agents.wakeComputer("agt_...");
133
+
134
+ const { data: execution } = await commons.agents.execComputer("agt_...", {
135
+ command: "pnpm test",
136
+ cwd: "/workspace",
137
+ });
138
+ ```
139
+
140
+ ## Connected accounts
141
+
142
+ ```ts
143
+ const { providers } = await commons.oauth.listProviders();
144
+
145
+ const authorization = await commons.oauth.connect({
146
+ providerKey: providers[0].providerKey,
147
+ });
148
+
149
+ console.log(authorization.authorizationUrl);
150
+ ```
151
+
152
+ ## Manage developer projects and API keys
153
+
154
+ Interactive users should normally manage keys in Settings or with the Agent
155
+ Commons CLI. Authenticated developer tooling can use the same identity API:
156
+
157
+ ```ts
158
+ const account = new CommonsClient({
159
+ identityUrl: "https://auth.agentcommons.io",
160
+ identityToken: process.env.COMMONS_ACCOUNT_TOKEN,
161
+ });
162
+
163
+ const { data: projects } = await account.developer.listProjects();
164
+
165
+ const { data: created } = await account.developer.createApiKey(projects[0].id, {
166
+ name: "CI deployment",
167
+ scopes: ["agents:read", "agents:run"],
168
+ });
169
+
170
+ console.log(created.key); // Shown once
171
+ ```
172
+
173
+ The `apiKeys` namespace remains available for legacy per-principal `sk-ac-*`
174
+ keys. New integrations should use project-scoped `csk_*` keys.
175
+
176
+ ## Configuration
177
+
178
+ ```ts
179
+ const commons = new CommonsClient({
180
+ baseUrl: "https://api.agentcommons.io",
181
+ apiKey: process.env.AGENT_COMMONS_API_KEY,
182
+ initiator: "usr_...", // Optional delegation context
183
+ fetch: customFetch, // Optional Fetch-compatible implementation
184
+ });
185
+ ```
186
+
187
+ | Option | Description |
188
+ | --- | --- |
189
+ | `baseUrl` | Agent Commons API origin |
190
+ | `apiKey` | Project API key or Commons access token |
191
+ | `initiator` | Optional delegated principal ID |
192
+ | `identityUrl` | Commons Identity origin for `developer` methods |
193
+ | `identityToken` | Account session/OAuth token for `developer` methods |
194
+ | `fetch` | Custom Fetch-compatible implementation |
195
+
196
+ ## Errors
197
+
198
+ Non-successful responses throw `CommonsError`.
199
+
200
+ ```ts
201
+ import { CommonsError } from "@agent-commons/sdk";
202
+
203
+ try {
204
+ await commons.agents.get("missing");
205
+ } catch (error) {
206
+ if (error instanceof CommonsError) {
207
+ console.error(error.status, error.message, error.data);
208
+ }
209
+ }
210
+ ```
211
+
212
+ ## Security
213
+
214
+ - Use a separate developer project for each environment.
215
+ - Grant the smallest useful scope set.
216
+ - Prefer expiring keys for CI, previews, and temporary integrations.
217
+ - Revoke a key immediately if it may have been exposed.
218
+ - Use OAuth connections for third-party accounts; do not pass provider tokens
219
+ through your application.
220
+
221
+ ## Links
222
+
223
+ - [Documentation](https://docs.agentcommons.io)
224
+ - [Agent Commons](https://www.agentcommons.io)
225
+ - [GitHub](https://github.com/Arttribute/agent-commons)
226
+ - [Issues](https://github.com/Arttribute/agent-commons/issues)
227
+
228
+ ## License
229
+
230
+ MIT