@agent-os-lab/agent-game-sdk 0.1.2 → 0.1.3
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 +7 -5
- package/USAGE.md +303 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Embeddable agent game views and runtime clients.
|
|
4
4
|
|
|
5
|
+
For the full integration guide, see [USAGE.md](./USAGE.md).
|
|
6
|
+
|
|
5
7
|
## Office View
|
|
6
8
|
|
|
7
9
|
Framework-neutral mount API:
|
|
8
10
|
|
|
9
11
|
```ts
|
|
10
|
-
import { AgentGameRuntimeBrowserClient } from "agent-game-sdk";
|
|
11
|
-
import { mountAgentGameOffice } from "agent-game-sdk/office";
|
|
12
|
+
import { AgentGameRuntimeBrowserClient } from "@agent-os-lab/agent-game-sdk";
|
|
13
|
+
import { mountAgentGameOffice } from "@agent-os-lab/agent-game-sdk/office";
|
|
12
14
|
|
|
13
15
|
const client = new AgentGameRuntimeBrowserClient({
|
|
14
16
|
baseUrl: "",
|
|
@@ -31,8 +33,8 @@ view.destroy();
|
|
|
31
33
|
React wrapper:
|
|
32
34
|
|
|
33
35
|
```tsx
|
|
34
|
-
import { AgentGameRuntimeBrowserClient } from "agent-game-sdk";
|
|
35
|
-
import { AgentGameOfficeView } from "agent-game-sdk/office/react";
|
|
36
|
+
import { AgentGameRuntimeBrowserClient } from "@agent-os-lab/agent-game-sdk";
|
|
37
|
+
import { AgentGameOfficeView } from "@agent-os-lab/agent-game-sdk/office/react";
|
|
36
38
|
|
|
37
39
|
const client = new AgentGameRuntimeBrowserClient({
|
|
38
40
|
baseUrl: "",
|
|
@@ -54,7 +56,7 @@ export function Office() {
|
|
|
54
56
|
Browser clients should call an application BFF endpoint. Keep the AgentOS service API key on the server; the SDK server client forwards it to Agent Game Runtime:
|
|
55
57
|
|
|
56
58
|
```ts
|
|
57
|
-
import { AgentGameRuntimeServerClient } from "agent-game-sdk";
|
|
59
|
+
import { AgentGameRuntimeServerClient } from "@agent-os-lab/agent-game-sdk";
|
|
58
60
|
|
|
59
61
|
const client = new AgentGameRuntimeServerClient({
|
|
60
62
|
baseUrl: process.env.AGENT_GAME_RUNTIME_BASE_URL!,
|
package/USAGE.md
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
# Agent Game SDK Usage Guide
|
|
2
|
+
|
|
3
|
+
This document describes how to use `@agent-os-lab/agent-game-sdk` from browser-facing applications and trusted backend services.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`@agent-os-lab/agent-game-sdk` provides embeddable agent game views and a browser-safe client for Agent Game Runtime presence streams.
|
|
8
|
+
|
|
9
|
+
Use it when another application needs to render an AgentOS office view, subscribe to live agent presence, or bridge a trusted backend API key into short-lived runtime tokens for browser clients.
|
|
10
|
+
|
|
11
|
+
The SDK is intentionally split by responsibility:
|
|
12
|
+
|
|
13
|
+
- Runtime clients handle token creation and WebSocket subscription.
|
|
14
|
+
- Office view APIs mount a framework-neutral 3D office view into a DOM container.
|
|
15
|
+
- React APIs wrap the same office view for React applications.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @agent-os-lab/agent-game-sdk
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Runtime requirements:
|
|
24
|
+
|
|
25
|
+
- A modern browser runtime with `fetch`, `Headers`, `Response`, and `WebSocket` for frontend usage.
|
|
26
|
+
- A trusted backend runtime with `fetch` for runtime token proxy endpoints.
|
|
27
|
+
- React 19+ and React DOM 19+ only when using `@agent-os-lab/agent-game-sdk/office/react`.
|
|
28
|
+
|
|
29
|
+
## Entry Points
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import {
|
|
33
|
+
AgentGameRuntimeBrowserClient,
|
|
34
|
+
AgentGameRuntimeServerClient,
|
|
35
|
+
} from "@agent-os-lab/agent-game-sdk";
|
|
36
|
+
import { mountAgentGameOffice } from "@agent-os-lab/agent-game-sdk/office";
|
|
37
|
+
import { AgentGameOfficeView } from "@agent-os-lab/agent-game-sdk/office/react";
|
|
38
|
+
import type { AgentPresence } from "@agent-os-lab/agent-game-sdk/office";
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Available entry points:
|
|
42
|
+
|
|
43
|
+
- `@agent-os-lab/agent-game-sdk`: runtime clients and office exports.
|
|
44
|
+
- `@agent-os-lab/agent-game-sdk/office`: framework-neutral office view APIs and office types.
|
|
45
|
+
- `@agent-os-lab/agent-game-sdk/office/react`: React office view component.
|
|
46
|
+
|
|
47
|
+
Do not import files from `src/` in application code. Use the published entry points above.
|
|
48
|
+
|
|
49
|
+
## Authentication Model
|
|
50
|
+
|
|
51
|
+
Use `AgentGameRuntimeServerClient` only in trusted backend code. It sends the AgentOS service API key as a bearer token to Agent Game Runtime and returns a short-lived runtime token response.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { AgentGameRuntimeServerClient } from "@agent-os-lab/agent-game-sdk";
|
|
55
|
+
|
|
56
|
+
const serverClient = new AgentGameRuntimeServerClient({
|
|
57
|
+
baseUrl: process.env.AGENT_GAME_RUNTIME_BASE_URL!,
|
|
58
|
+
apiKey: process.env.AGENTOS_API_KEY!,
|
|
59
|
+
requestId: () => crypto.randomUUID(),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export async function GET() {
|
|
63
|
+
return Response.json(await serverClient.createRuntimeToken());
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Do not expose `AGENTOS_API_KEY` or any AgentOS service API key to browser code.
|
|
68
|
+
|
|
69
|
+
Use `AgentGameRuntimeBrowserClient` in the frontend against a same-origin BFF/proxy endpoint that returns `GameRuntimeTokenResponse`.
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
import { AgentGameRuntimeBrowserClient } from "@agent-os-lab/agent-game-sdk";
|
|
73
|
+
|
|
74
|
+
const browserClient = new AgentGameRuntimeBrowserClient({
|
|
75
|
+
baseUrl: "",
|
|
76
|
+
tokenPath: "/api/agent-game-runtime-token",
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
If your application backend expects an application-scoped browser token, provide `accessToken`. This token is for your BFF/proxy, not for Agent Game Runtime directly.
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
const browserClient = new AgentGameRuntimeBrowserClient({
|
|
84
|
+
baseUrl: "",
|
|
85
|
+
tokenPath: "/api/agent-game-runtime-token",
|
|
86
|
+
accessToken: async () => getScopedApplicationToken(),
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
The browser client strips caller-provided `authorization`, `x-hermes-tenant-id`, and `x-agentos-tenant-id` headers. Only the `accessToken` option may set a browser bearer token.
|
|
91
|
+
|
|
92
|
+
## Runtime Subscription
|
|
93
|
+
|
|
94
|
+
Use `subscribe` when the application wants direct access to live runtime messages instead of using the office view.
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
const subscription = await browserClient.subscribe({
|
|
98
|
+
onSnapshot: (message) => {
|
|
99
|
+
console.log("snapshot", message.agents);
|
|
100
|
+
},
|
|
101
|
+
onPatch: (message) => {
|
|
102
|
+
console.log("patch", message.agents);
|
|
103
|
+
},
|
|
104
|
+
onError: (error) => {
|
|
105
|
+
console.error("runtime stream error", error);
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
subscription.close();
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Runtime messages are either:
|
|
113
|
+
|
|
114
|
+
- `snapshot`: full current presence list for the tenant.
|
|
115
|
+
- `patch`: changed agent presence records.
|
|
116
|
+
|
|
117
|
+
Use `mergeAgentPresence` when maintaining your own local presence array from snapshots and patches.
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
import { mergeAgentPresence } from "@agent-os-lab/agent-game-sdk";
|
|
121
|
+
|
|
122
|
+
let agents = [];
|
|
123
|
+
|
|
124
|
+
await browserClient.subscribe({
|
|
125
|
+
onSnapshot: (message) => {
|
|
126
|
+
agents = message.agents;
|
|
127
|
+
},
|
|
128
|
+
onPatch: (message) => {
|
|
129
|
+
agents = mergeAgentPresence(agents, message.agents);
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Office View
|
|
135
|
+
|
|
136
|
+
Use `mountAgentGameOffice` for framework-neutral embedding.
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
import { AgentGameRuntimeBrowserClient } from "@agent-os-lab/agent-game-sdk";
|
|
140
|
+
import { mountAgentGameOffice } from "@agent-os-lab/agent-game-sdk/office";
|
|
141
|
+
|
|
142
|
+
const client = new AgentGameRuntimeBrowserClient({
|
|
143
|
+
baseUrl: "",
|
|
144
|
+
tokenPath: "/api/agent-game-runtime-token",
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const view = await mountAgentGameOffice(container, {
|
|
148
|
+
renderer: "three",
|
|
149
|
+
source: {
|
|
150
|
+
type: "runtime",
|
|
151
|
+
client,
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
view.focusAgent("agent-1");
|
|
156
|
+
view.destroy();
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
`renderer: "three"` is the built-in renderer and the default renderer. The container must have a stable size; the React wrapper supplies a default `minHeight`, but framework-neutral callers should size the container in CSS.
|
|
160
|
+
|
|
161
|
+
## React Office View
|
|
162
|
+
|
|
163
|
+
Use `AgentGameOfficeView` when embedding the office view in a React application.
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
import { AgentGameRuntimeBrowserClient } from "@agent-os-lab/agent-game-sdk";
|
|
167
|
+
import { AgentGameOfficeView } from "@agent-os-lab/agent-game-sdk/office/react";
|
|
168
|
+
|
|
169
|
+
const client = new AgentGameRuntimeBrowserClient({
|
|
170
|
+
baseUrl: "",
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
export function Office() {
|
|
174
|
+
return (
|
|
175
|
+
<AgentGameOfficeView
|
|
176
|
+
renderer="three"
|
|
177
|
+
source={{ type: "runtime", client }}
|
|
178
|
+
focusedAgentId="agent-1"
|
|
179
|
+
style={{ height: 640 }}
|
|
180
|
+
/>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Keep `source` object identity stable across renders when possible. Recreating `source` every render can remount the view because the React wrapper treats `options.source` as an effect dependency.
|
|
186
|
+
|
|
187
|
+
## Snapshot Source
|
|
188
|
+
|
|
189
|
+
Use `source.type: "snapshot"` for demos, tests, static previews, or applications that already have agent presence data.
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
import { mountAgentGameOffice, type AgentPresence } from "@agent-os-lab/agent-game-sdk/office";
|
|
193
|
+
|
|
194
|
+
const agents: AgentPresence[] = [
|
|
195
|
+
{
|
|
196
|
+
tenantId: "tenant-demo",
|
|
197
|
+
agentId: "agent-1",
|
|
198
|
+
displayName: "Research Agent",
|
|
199
|
+
status: "working",
|
|
200
|
+
statusSource: "simulation",
|
|
201
|
+
activity: {
|
|
202
|
+
kind: "running",
|
|
203
|
+
summary: "Reading customer notes",
|
|
204
|
+
updatedAt: new Date().toISOString(),
|
|
205
|
+
},
|
|
206
|
+
updatedAt: new Date().toISOString(),
|
|
207
|
+
},
|
|
208
|
+
];
|
|
209
|
+
|
|
210
|
+
const view = await mountAgentGameOffice(container, {
|
|
211
|
+
source: {
|
|
212
|
+
type: "snapshot",
|
|
213
|
+
agents,
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
view.updateAgents([
|
|
218
|
+
{
|
|
219
|
+
...agents[0],
|
|
220
|
+
status: "meeting",
|
|
221
|
+
updatedAt: new Date().toISOString(),
|
|
222
|
+
},
|
|
223
|
+
]);
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
`updateAgents` only mutates SDK-managed snapshot sources. Runtime and custom sources own their own updates.
|
|
227
|
+
|
|
228
|
+
## Custom Source
|
|
229
|
+
|
|
230
|
+
Use `source.type: "custom"` when another state manager already projects runtime state into office snapshots.
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
import type {
|
|
234
|
+
AgentGameOfficeSnapshot,
|
|
235
|
+
AgentGameOfficeSource,
|
|
236
|
+
} from "@agent-os-lab/agent-game-sdk/office";
|
|
237
|
+
|
|
238
|
+
const source: AgentGameOfficeSource = {
|
|
239
|
+
subscribe(listener: (snapshot: AgentGameOfficeSnapshot) => void) {
|
|
240
|
+
const unsubscribe = store.subscribe(() => {
|
|
241
|
+
listener(store.getState().officeSnapshot);
|
|
242
|
+
});
|
|
243
|
+
listener(store.getState().officeSnapshot);
|
|
244
|
+
return unsubscribe;
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
await mountAgentGameOffice(container, {
|
|
249
|
+
source: {
|
|
250
|
+
type: "custom",
|
|
251
|
+
source,
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Agent Presence Shape
|
|
257
|
+
|
|
258
|
+
Office rendering is driven by `AgentPresence`.
|
|
259
|
+
|
|
260
|
+
Important fields:
|
|
261
|
+
|
|
262
|
+
- `tenantId`: tenant that owns the presence record.
|
|
263
|
+
- `agentId`: stable agent identifier.
|
|
264
|
+
- `displayName`: label shown in the office view.
|
|
265
|
+
- `status`: one of `working`, `thinking`, `meeting`, `resting`, `entertaining`, `idle`, or `offline`.
|
|
266
|
+
- `statusSource`: `runtime`, `simulation`, or `system`.
|
|
267
|
+
- `activity`: optional visible activity summary and preview.
|
|
268
|
+
- `updatedAt`: ISO timestamp for the latest presence update.
|
|
269
|
+
- `expiresAt`: optional ISO timestamp after which the presence should be considered stale by the producer.
|
|
270
|
+
|
|
271
|
+
## Local Demo
|
|
272
|
+
|
|
273
|
+
Run the SDK office view demo from `agent-game-sdk`:
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
AGENT_GAME_RUNTIME_BASE_URL=http://localhost:3107 AGENTOS_API_KEY=... bun run demo
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
Open `http://localhost:7357`.
|
|
280
|
+
|
|
281
|
+
Set `PORT=7358` or another value to change the port.
|
|
282
|
+
|
|
283
|
+
## Publish
|
|
284
|
+
|
|
285
|
+
Publishing is controlled from the SDK package directory. The script bumps the package version, builds the package, runs `npm pack --dry-run`, and then publishes to npm:
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
bun run sdk:publish
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
The default release is patch. Use `--minor` or `--major` when needed:
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
bun run sdk:publish -- --minor
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
Use `--dry-run` to validate the next version and package contents without publishing. The script restores the previous version after a dry run.
|
|
298
|
+
|
|
299
|
+
If npm requires two-factor authentication, pass the one-time password with `--otp`:
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
bun run sdk:publish -- --otp 123456
|
|
303
|
+
```
|