@agent-play/sdk 3.0.1 → 3.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 +1 -0
- package/dist/.root +1 -0
- package/dist/browser-C8UKcztD.d.ts +341 -0
- package/dist/browser.d.ts +1 -0
- package/dist/browser.js +23 -0
- package/dist/browser.js.map +1 -0
- package/dist/chunk-G2WV7OYM.js +260 -0
- package/dist/chunk-G2WV7OYM.js.map +1 -0
- package/dist/index.d.ts +122 -307
- package/dist/index.js +729 -251
- package/dist/index.js.map +1 -1
- package/examples/01-remote-web-ui-langchain.ts +77 -16
- package/examples/02-remote-two-players-langchain.ts +57 -20
- package/examples/README.md +6 -4
- package/package.json +10 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,251 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type WorldInteractionRole = "user" | "assistant" | "tool";
|
|
6
|
-
/**
|
|
7
|
-
* Payload for {@link import("./lib/remote-play-world.js").RemotePlayWorld.recordInteraction}.
|
|
8
|
-
*
|
|
9
|
-
* @property playerId - Player id returned from `addPlayer`.
|
|
10
|
-
* @property role - Who "spoke" the line.
|
|
11
|
-
* @property text - Plain text; may be truncated for display server-side.
|
|
12
|
-
*/
|
|
13
|
-
type RecordInteractionInput = {
|
|
14
|
-
playerId: string;
|
|
15
|
-
role: WorldInteractionRole;
|
|
16
|
-
text: string;
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Metadata for a tool whose name starts with `assist_`, shown as assist actions on the watch UI.
|
|
20
|
-
*
|
|
21
|
-
* @property parameters - Derived from Zod object `schema` when present; placeholder hints otherwise.
|
|
22
|
-
*/
|
|
23
|
-
type AssistToolSpec = {
|
|
24
|
-
name: string;
|
|
25
|
-
description: string;
|
|
26
|
-
parameters: Record<string, unknown>;
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Serializable shape returned by {@link import("./platforms/langchain.js").langchainRegistration} for `addPlayer`.
|
|
30
|
-
*
|
|
31
|
-
* @property type - Always `"langchain"` for this adapter.
|
|
32
|
-
* @property toolNames - All tool names from the agent (must include `chat_tool`).
|
|
33
|
-
* @property assistTools - Subset of tools with `assist_` prefix, for UI buttons.
|
|
34
|
-
*/
|
|
35
|
-
type LangChainAgentRegistration = {
|
|
36
|
-
type: "langchain";
|
|
37
|
-
toolNames: string[];
|
|
38
|
-
assistTools?: AssistToolSpec[];
|
|
39
|
-
};
|
|
40
|
-
/** Minimal player identity in the SDK (without preview URL). */
|
|
41
|
-
type PlayAgentInformation = {
|
|
42
|
-
id: string;
|
|
43
|
-
name: string;
|
|
44
|
-
sid: string;
|
|
45
|
-
createdAt: Date;
|
|
46
|
-
updatedAt: Date;
|
|
47
|
-
};
|
|
48
|
-
/** Input fields for `addPlayer` before `agent` is attached. */
|
|
49
|
-
type PlatformAgentInformation = {
|
|
50
|
-
name: string;
|
|
51
|
-
type: string;
|
|
52
|
-
version?: string;
|
|
53
|
-
createdAt?: Date;
|
|
54
|
-
updatedAt?: Date;
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* Register a player (agent) in the world.
|
|
58
|
-
*
|
|
59
|
-
* Use **`langchainRegistration(agent)`** for `agent` (requires a **`chat_tool`** tool; `assist_*`
|
|
60
|
-
* tools are indexed for the watch UI).
|
|
61
|
-
*
|
|
62
|
-
* **`agentId`** is required: use an id from **`agent-play create`** when the server uses a repository
|
|
63
|
-
* (with **`apiKey`** from **`RemotePlayWorld`**), or any stable string for local dev without Redis.
|
|
64
|
-
*/
|
|
65
|
-
type AddPlayerInput = PlatformAgentInformation & {
|
|
66
|
-
/** Registration from {@link import("./platforms/langchain.js").langchainRegistration}. */
|
|
67
|
-
agent: LangChainAgentRegistration;
|
|
68
|
-
/** Registered agent id (or session-local id without Redis). */
|
|
69
|
-
agentId: string;
|
|
70
|
-
};
|
|
71
|
-
/** Zone counter event surfaced on snapshots and signals. */
|
|
72
|
-
type ZoneEventInfo = {
|
|
73
|
-
zoneCount: number;
|
|
74
|
-
flagged?: boolean;
|
|
75
|
-
at: string;
|
|
76
|
-
};
|
|
77
|
-
/** Yield counter event surfaced on snapshots and signals. */
|
|
78
|
-
type YieldEventInfo = {
|
|
79
|
-
yieldCount: number;
|
|
80
|
-
at: string;
|
|
81
|
-
};
|
|
82
|
-
/** Repository-backed summary returned with `addPlayer` when the agent is (or maps to) a stored registration. */
|
|
83
|
-
type RegisteredAgentSummary = {
|
|
84
|
-
agentId: string;
|
|
85
|
-
name: string;
|
|
86
|
-
toolNames: string[];
|
|
87
|
-
zoneCount: number;
|
|
88
|
-
yieldCount: number;
|
|
89
|
-
flagged: boolean;
|
|
90
|
-
};
|
|
91
|
-
/** Result of `addPlayer` including watch URL and registered-agent metadata from the server. */
|
|
92
|
-
type RegisteredPlayer = PlayAgentInformation & {
|
|
93
|
-
previewUrl: string;
|
|
94
|
-
registeredAgent: RegisteredAgentSummary;
|
|
95
|
-
};
|
|
96
|
-
/** First step of a journey: user message origin. */
|
|
97
|
-
type OriginJourneyStep = {
|
|
98
|
-
type: "origin";
|
|
99
|
-
content: string;
|
|
100
|
-
messageId: string;
|
|
101
|
-
};
|
|
102
|
-
/** Middle step: tool invocation on the map. */
|
|
103
|
-
type StructureJourneyStep = {
|
|
104
|
-
type: "structure";
|
|
105
|
-
toolName: string;
|
|
106
|
-
toolCallId: string;
|
|
107
|
-
args: Record<string, unknown>;
|
|
108
|
-
result?: string;
|
|
109
|
-
};
|
|
110
|
-
/** Final step: assistant reply. */
|
|
111
|
-
type DestinationJourneyStep = {
|
|
112
|
-
type: "destination";
|
|
113
|
-
content: string;
|
|
114
|
-
messageId: string;
|
|
115
|
-
};
|
|
116
|
-
/** Union of journey step shapes. */
|
|
117
|
-
type JourneyStep = OriginJourneyStep | StructureJourneyStep | DestinationJourneyStep;
|
|
118
|
-
/**
|
|
119
|
-
* Ordered journey with timestamps; sent to the server via `recordJourney`.
|
|
120
|
-
*
|
|
121
|
-
* @property steps - Ordered path from origin through tool steps to destination.
|
|
122
|
-
* @property startedAt, completedAt - Wall times for the run (client or server).
|
|
123
|
-
*/
|
|
124
|
-
type Journey = {
|
|
125
|
-
steps: JourneyStep[];
|
|
126
|
-
startedAt: Date;
|
|
127
|
-
completedAt: Date;
|
|
128
|
-
};
|
|
129
|
-
/** Journey step after server assigns coordinates (and optional structure id). */
|
|
130
|
-
type PositionedStep = JourneyStep & {
|
|
131
|
-
x?: number;
|
|
132
|
-
y?: number;
|
|
133
|
-
structureId?: string;
|
|
134
|
-
};
|
|
135
|
-
type AgentPlayWorldMapBounds = {
|
|
136
|
-
minX: number;
|
|
137
|
-
minY: number;
|
|
138
|
-
maxX: number;
|
|
139
|
-
maxY: number;
|
|
140
|
-
};
|
|
141
|
-
/**
|
|
142
|
-
* One agent on the world map. Coordinates are grid positions; the server enforces unique `(x,y)` per occupant.
|
|
143
|
-
*/
|
|
144
|
-
type AgentPlayWorldMapAgentOccupant = {
|
|
145
|
-
kind: "agent";
|
|
146
|
-
agentId: string;
|
|
147
|
-
name: string;
|
|
148
|
-
x: number;
|
|
149
|
-
y: number;
|
|
150
|
-
/**
|
|
151
|
-
* Integration label from addPlayer `type` (e.g. `langchain`). Populated from the snapshot field `platform`. The legacy wire field `agentType` is deprecated and accepted only for backward compatibility when parsing JSON.
|
|
152
|
-
*/
|
|
153
|
-
platform?: string;
|
|
154
|
-
toolNames?: string[];
|
|
155
|
-
assistToolNames?: string[];
|
|
156
|
-
assistTools?: AssistToolSpec[];
|
|
157
|
-
hasChatTool?: boolean;
|
|
158
|
-
stationary?: boolean;
|
|
159
|
-
lastUpdate?: unknown;
|
|
160
|
-
recentInteractions?: Array<{
|
|
161
|
-
role: WorldInteractionRole;
|
|
162
|
-
text: string;
|
|
163
|
-
at: string;
|
|
164
|
-
seq: number;
|
|
165
|
-
}>;
|
|
166
|
-
zoneCount?: number;
|
|
167
|
-
yieldCount?: number;
|
|
168
|
-
flagged?: boolean;
|
|
169
|
-
onZone?: ZoneEventInfo;
|
|
170
|
-
onYield?: YieldEventInfo;
|
|
171
|
-
};
|
|
172
|
-
/** MCP server shown as a separate map occupant (distinct from LangChain agents). */
|
|
173
|
-
type AgentPlayWorldMapMcpOccupant = {
|
|
174
|
-
kind: "mcp";
|
|
175
|
-
id: string;
|
|
176
|
-
name: string;
|
|
177
|
-
x: number;
|
|
178
|
-
y: number;
|
|
179
|
-
url?: string;
|
|
180
|
-
};
|
|
181
|
-
/** Spatial index: axis-aligned bounds plus every agent and MCP registration placed on the grid. */
|
|
182
|
-
type AgentPlayWorldMap = {
|
|
183
|
-
bounds: AgentPlayWorldMapBounds;
|
|
184
|
-
occupants: (AgentPlayWorldMapAgentOccupant | AgentPlayWorldMapMcpOccupant)[];
|
|
185
|
-
};
|
|
186
|
-
/**
|
|
187
|
-
* Session snapshot from {@link import("./lib/remote-play-world.js").RemotePlayWorld.getWorldSnapshot}.
|
|
188
|
-
* Agents and MCP servers appear only under **`worldMap.occupants`** (no separate `players` list).
|
|
189
|
-
*/
|
|
190
|
-
type AgentPlaySnapshot = {
|
|
191
|
-
sid: string;
|
|
192
|
-
worldMap: AgentPlayWorldMap;
|
|
193
|
-
mcpServers?: Array<{
|
|
194
|
-
id: string;
|
|
195
|
-
name: string;
|
|
196
|
-
url?: string;
|
|
197
|
-
}>;
|
|
198
|
-
};
|
|
199
|
-
type PlayerChainNotifyNodeRef = {
|
|
200
|
-
stableKey: string;
|
|
201
|
-
leafIndex: number;
|
|
202
|
-
removed?: boolean;
|
|
203
|
-
updatedAt?: string;
|
|
204
|
-
};
|
|
205
|
-
type PlayerChainFanoutNotify = {
|
|
206
|
-
updatedAt: string;
|
|
207
|
-
nodes: PlayerChainNotifyNodeRef[];
|
|
208
|
-
};
|
|
209
|
-
type PlayerChainGenesisStableKey = "__genesis__";
|
|
210
|
-
type PlayerChainHeaderStableKey = "__header__";
|
|
211
|
-
type PlayerChainGenesisNode = {
|
|
212
|
-
kind: "genesis";
|
|
213
|
-
stableKey: PlayerChainGenesisStableKey;
|
|
214
|
-
text: string;
|
|
215
|
-
};
|
|
216
|
-
type PlayerChainHeaderNode = {
|
|
217
|
-
kind: "header";
|
|
218
|
-
stableKey: PlayerChainHeaderStableKey;
|
|
219
|
-
sid: string;
|
|
220
|
-
bounds: AgentPlayWorldMapBounds;
|
|
221
|
-
};
|
|
222
|
-
type PlayerChainOccupantRemovedNode = {
|
|
223
|
-
kind: "occupant";
|
|
224
|
-
stableKey: string;
|
|
225
|
-
removed: true;
|
|
226
|
-
};
|
|
227
|
-
type PlayerChainOccupantPresentNode = {
|
|
228
|
-
kind: "occupant";
|
|
229
|
-
stableKey: string;
|
|
230
|
-
removed: false;
|
|
231
|
-
occupant: AgentPlayWorldMapAgentOccupant | AgentPlayWorldMapMcpOccupant;
|
|
232
|
-
};
|
|
233
|
-
type PlayerChainNodeResponse = PlayerChainGenesisNode | PlayerChainHeaderNode | PlayerChainOccupantRemovedNode | PlayerChainOccupantPresentNode;
|
|
234
|
-
/** Full journey + path update (SSE `world:journey`); coordinates are embedded in `path` steps. */
|
|
235
|
-
type WorldJourneyUpdate = {
|
|
236
|
-
playerId: string;
|
|
237
|
-
journey: Journey;
|
|
238
|
-
path: PositionedStep[];
|
|
239
|
-
};
|
|
1
|
+
import { W as WorldInteractionRole, L as LangChainAgentRegistration, A as AgentPlaySnapshot, P as PlayerChainNodeResponse, a as AddAgentInput, R as RegisteredPlayer, b as AddPlayerInput, c as RecordInteractionInput, J as Journey } from './browser-C8UKcztD.js';
|
|
2
|
+
export { d as AgentPlayWorldMap, e as AgentPlayWorldMapAgentOccupant, f as AgentPlayWorldMapBounds, g as AgentPlayWorldMapMcpOccupant, h as AssistToolFieldType, i as AssistToolParameterSpec, j as AssistToolSpec, D as DestinationJourneyStep, k as JourneyStep, O as OriginJourneyStep, l as PLAYER_CHAIN_GENESIS_STABLE_KEY, m as PLAYER_CHAIN_HEADER_STABLE_KEY, n as PlatformAgentInformation, o as PlayAgentInformation, p as PlayerChainFanoutNotify, q as PlayerChainGenesisNode, r as PlayerChainHeaderNode, s as PlayerChainNotifyNodeRef, t as PlayerChainOccupantPresentNode, u as PlayerChainOccupantRemovedNode, v as PositionedStep, w as RegisteredAgentSummary, S as StructureJourneyStep, x as WorldBounds, y as WorldJourneyUpdate, Y as YieldEventInfo, Z as ZoneEventInfo, z as boundsContain, B as clampWorldPosition, C as mergeSnapshotWithPlayerChainNode, E as parsePlayerChainFanoutNotify, F as parsePlayerChainFanoutNotifyFromSsePayload, G as parsePlayerChainNodeRpcBody, H as sortNodeRefsForSerializedFetch } from './browser-C8UKcztD.js';
|
|
3
|
+
import { WorldIntercomEventPayload, IntercomResponsePayload } from '@agent-play/intercom';
|
|
4
|
+
export { AgentPlayAgentNodeEntry, AgentPlayCredentialsFile, loadAgentPlayCredentialsFileFromPath, loadAgentPlayCredentialsFileFromPathSync, loadRootKey, nodeCredentialsMaterialFromHumanPassphrase, parseAgentPlayCredentialsJson, resolveAgentPlayCredentialsPath } from '@agent-play/node-tools';
|
|
240
5
|
|
|
241
6
|
/**
|
|
242
7
|
* String constants and payload shapes for SSE and in-process world events.
|
|
243
8
|
*
|
|
244
9
|
* @remarks **Emitters:** server `PlayWorld` and Redis fanout. **Consumers:** watch UI `EventSource`,
|
|
245
10
|
* integration tests, and any host that forwards `POST` events.
|
|
11
|
+
*
|
|
12
|
+
* **Session vs world:** names prefixed with **`session:`** concern the HTTP/SDK session (`sid`) and
|
|
13
|
+
* transport; names prefixed with **`world:`** concern occupants, chat, and map-visible state.
|
|
246
14
|
*/
|
|
247
15
|
|
|
248
|
-
/**
|
|
16
|
+
/** After `RemotePlayWorld.connect()` assigns a `sid` (and optional detail such as `sid`). */
|
|
17
|
+
declare const SESSION_CONNECTED_EVENT = "session:connected";
|
|
18
|
+
/** RPC or transport rejected the session (e.g. 401/403); optional `detail.status`. */
|
|
19
|
+
declare const SESSION_INVALID_EVENT = "session:invalid";
|
|
20
|
+
/** After `RemotePlayWorld.close()` completes teardown. */
|
|
21
|
+
declare const SESSION_CLOSED_EVENT = "session:closed";
|
|
22
|
+
/** SSE subscription opened (optional; emitted when wired). */
|
|
23
|
+
declare const SESSION_SSE_OPEN_EVENT = "session:sse_open";
|
|
24
|
+
/** SSE subscription error (optional; emitted when wired). */
|
|
25
|
+
declare const SESSION_SSE_ERROR_EVENT = "session:sse_error";
|
|
26
|
+
type RemotePlayWorldSessionEvent = {
|
|
27
|
+
name: string;
|
|
28
|
+
detail?: Record<string, unknown>;
|
|
29
|
+
};
|
|
30
|
+
/** Fired when `addAgent` / `addPlayer` completes; payload includes snapshot row for the new player. */
|
|
249
31
|
declare const PLAYER_ADDED_EVENT = "world:player_added";
|
|
250
32
|
/** Fired for each new chat/interaction line. */
|
|
251
33
|
declare const WORLD_INTERACTION_EVENT = "world:interaction";
|
|
@@ -278,49 +60,6 @@ type WorldInteractionPayload = {
|
|
|
278
60
|
seq: number;
|
|
279
61
|
};
|
|
280
62
|
|
|
281
|
-
/**
|
|
282
|
-
* Axis-aligned rectangle in world coordinates (grid units). Used by the server to clamp paths
|
|
283
|
-
* and by the watch UI to clamp joystick-driven movement.
|
|
284
|
-
*
|
|
285
|
-
* @remarks **Consumers:** {@link clampWorldPosition}, {@link boundsContain}; server `PlayWorld` and
|
|
286
|
-
* play-ui canvas both import these helpers from `@agent-play/sdk`.
|
|
287
|
-
*/
|
|
288
|
-
type WorldBounds = {
|
|
289
|
-
/** Inclusive minimum X. */
|
|
290
|
-
minX: number;
|
|
291
|
-
/** Inclusive minimum Y. */
|
|
292
|
-
minY: number;
|
|
293
|
-
/** Inclusive maximum X. */
|
|
294
|
-
maxX: number;
|
|
295
|
-
/** Inclusive maximum Y. */
|
|
296
|
-
maxY: number;
|
|
297
|
-
};
|
|
298
|
-
/**
|
|
299
|
-
* Clamps a point to lie inside `bounds` along both axes.
|
|
300
|
-
*
|
|
301
|
-
* @param p - Position with `x` and `y` in world units.
|
|
302
|
-
* @param bounds - Valid rectangle (`min` ≤ `max` per axis).
|
|
303
|
-
* @returns Same point if inside, otherwise clamped to the nearest edge.
|
|
304
|
-
*
|
|
305
|
-
* @remarks **Callers:** server `PlayWorld` path enrichment; play-ui joystick and preview. **Callees:** `Math.min/Math.max`.
|
|
306
|
-
*/
|
|
307
|
-
declare function clampWorldPosition(p: {
|
|
308
|
-
x: number;
|
|
309
|
-
y: number;
|
|
310
|
-
}, bounds: WorldBounds): {
|
|
311
|
-
x: number;
|
|
312
|
-
y: number;
|
|
313
|
-
};
|
|
314
|
-
/**
|
|
315
|
-
* @returns Whether `p` lies inside or on the border of `bounds`.
|
|
316
|
-
*
|
|
317
|
-
* @remarks **Callers:** optional UI checks. **Callees:** none.
|
|
318
|
-
*/
|
|
319
|
-
declare function boundsContain(bounds: WorldBounds, p: {
|
|
320
|
-
x: number;
|
|
321
|
-
y: number;
|
|
322
|
-
}): boolean;
|
|
323
|
-
|
|
324
63
|
/**
|
|
325
64
|
* Optional structured `console.debug` for SDK internals; gated by {@link configureAgentPlayDebug} or `AGENT_PLAY_DEBUG=1`.
|
|
326
65
|
*/
|
|
@@ -331,7 +70,7 @@ type DebugConfigure = {
|
|
|
331
70
|
/**
|
|
332
71
|
* Sets whether SDK debug logging is enabled regardless of `AGENT_PLAY_DEBUG`.
|
|
333
72
|
*
|
|
334
|
-
* @param opts
|
|
73
|
+
* @param opts - Optional `{ debug }`: `true` / `false` forces logging; omit `debug` to clear override.
|
|
335
74
|
*
|
|
336
75
|
* @remarks **Callers:** tests and user code. **Callees:** none.
|
|
337
76
|
*/
|
|
@@ -353,51 +92,116 @@ declare function isAgentPlayDebugEnabled(): boolean;
|
|
|
353
92
|
*
|
|
354
93
|
* @param scope - Short label (e.g. `"langchain"`).
|
|
355
94
|
* @param message - Human-readable message.
|
|
356
|
-
* @param detail - Optional object serialized by
|
|
95
|
+
* @param detail - Optional object serialized by the internal truncation helper (see source).
|
|
357
96
|
*
|
|
358
|
-
* @remarks **Callers:** {@link langchainRegistration} and other SDK modules. **Callees:** {@link isAgentPlayDebugEnabled}
|
|
97
|
+
* @remarks **Callers:** {@link langchainRegistration} and other SDK modules. **Callees:** {@link isAgentPlayDebugEnabled} and the internal serializer.
|
|
359
98
|
*/
|
|
360
99
|
declare function agentPlayDebug(scope: string, message: string, detail?: unknown): void;
|
|
361
100
|
|
|
362
101
|
/**
|
|
363
102
|
* Validates a LangChain-style agent exposes tools (including required `chat_tool`) and returns
|
|
364
|
-
* a {@link LangChainAgentRegistration} for `
|
|
103
|
+
* a {@link LangChainAgentRegistration} for `RemotePlayWorld.addAgent`.
|
|
365
104
|
*
|
|
366
105
|
* @param agent - Return value from `createAgent` (or equivalent) with a `tools` array.
|
|
367
106
|
* @throws Error if tools are missing or `chat_tool` is not present.
|
|
368
107
|
*
|
|
369
|
-
* @remarks **Callers:** user code before `RemotePlayWorld.
|
|
370
|
-
* {@link formatMissingAgentToolsError}, {@link formatMissingChatToolError}, {@link describeTool}, {@link agentPlayDebug}.
|
|
108
|
+
* @remarks **Callers:** user code before `RemotePlayWorld.addAgent`. **Callees:** internal validation helpers and {@link agentPlayDebug}.
|
|
371
109
|
*/
|
|
372
110
|
declare function langchainRegistration(agent: unknown): LangChainAgentRegistration;
|
|
373
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Root key (from `.root`) plus **human** passphrase as stored in **`~/.agent-play/credentials.json`**
|
|
114
|
+
* after **`agent-play create-main-node`**. Material for node id and wire auth is
|
|
115
|
+
* **`nodeCredentialsMaterialFromHumanPassphrase(passw)`** (SHA-256 hex; same as CLI **`hashNodePassword`**).
|
|
116
|
+
*/
|
|
117
|
+
type RemotePlayWorldNodeCredentials = {
|
|
118
|
+
rootKey: string;
|
|
119
|
+
passw: string;
|
|
120
|
+
};
|
|
121
|
+
type RemotePlayWorldLogging = "off" | "on";
|
|
374
122
|
type RemotePlayWorldOptions = {
|
|
375
|
-
baseUrl
|
|
376
|
-
|
|
377
|
-
|
|
123
|
+
baseUrl?: string;
|
|
124
|
+
/**
|
|
125
|
+
* `rootKey` from `.root` and **`passw`** human phrase from **`credentials.json`** (see **`loadAgentPlayCredentialsFileFromPathSync`** in **@agent-play/node-tools**).
|
|
126
|
+
*/
|
|
127
|
+
nodeCredentials?: RemotePlayWorldNodeCredentials;
|
|
128
|
+
/** Called for session lifecycle events (`session:connected`, `session:closed`; see `world-events`). */
|
|
129
|
+
onSessionEvent?: (event: RemotePlayWorldSessionEvent) => void;
|
|
130
|
+
/**
|
|
131
|
+
* When **`"on"`**, prints **`console.info`** lines for session events, SSE messages, intercom command matching/skips, and **`sendIntercomResponse`** payloads (for request tracing). Default **`"off"`**.
|
|
132
|
+
*/
|
|
133
|
+
logging?: RemotePlayWorldLogging;
|
|
134
|
+
};
|
|
135
|
+
/** Options for {@link RemotePlayWorld.connect}. */
|
|
136
|
+
type RemotePlayWorldConnectOptions = {
|
|
137
|
+
/**
|
|
138
|
+
* Parent **main** node id. When set, `connect` runs `POST /api/nodes/validate` first, then `GET /api/agent-play/session`.
|
|
139
|
+
* When omitted, only `GET /api/agent-play/session` runs.
|
|
140
|
+
*/
|
|
141
|
+
mainNodeId?: string;
|
|
378
142
|
};
|
|
379
143
|
type RemotePlayWorldHold = {
|
|
380
144
|
for: (seconds: number) => Promise<void>;
|
|
381
145
|
};
|
|
146
|
+
type IntercomToolExecutor = (input: {
|
|
147
|
+
toolName: string;
|
|
148
|
+
args: Record<string, unknown>;
|
|
149
|
+
}) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
150
|
+
type SubscribeIntercomChatAgents = {
|
|
151
|
+
/**
|
|
152
|
+
* Same LangChain agent instances passed to **`langchainRegistration`** (e.g. **`createAgent`** return values).
|
|
153
|
+
* For **`kind: chat`**, **`invoke({ messages: [HumanMessage(text)] })`** is called with **`.call(agent, input)`** (no wrapping).
|
|
154
|
+
*/
|
|
155
|
+
chatAgentsByPlayerId?: ReadonlyMap<string, unknown>;
|
|
156
|
+
};
|
|
157
|
+
type SubscribeIntercomCommandsOptions = ({
|
|
158
|
+
playerId: string;
|
|
159
|
+
executeTool: IntercomToolExecutor;
|
|
160
|
+
} & SubscribeIntercomChatAgents) | ({
|
|
161
|
+
playerIds: readonly string[];
|
|
162
|
+
executeTool: IntercomToolExecutor;
|
|
163
|
+
} & SubscribeIntercomChatAgents);
|
|
382
164
|
/**
|
|
383
165
|
* HTTP client for the Agent Play web UI: session, snapshot RPC, mutating RPC with `sid`, and optional SSE subscription.
|
|
384
166
|
*
|
|
167
|
+
* Authenticates like the CLI: **`x-node-id`** (derived node id) and **`x-node-passw`** (hashed passphrase material) on every request.
|
|
168
|
+
*
|
|
169
|
+
* Register automation agents with {@link RemotePlayWorld.addAgent} (`nodeId` is the agent node id; the server stores it as `agentId`).
|
|
170
|
+
*
|
|
385
171
|
* Incremental updates: {@link RemotePlayWorld.subscribeWorldState} listens for **`playerChainNotify`** in SSE `data`, then fetches each changed leaf via {@link RemotePlayWorld.getPlayerChainNode} and merges with {@link mergeSnapshotWithPlayerChainNode}.
|
|
172
|
+
*
|
|
173
|
+
* Human→agent intercom (Assist/Chat from the watch UI) is delivered as SSE **`world:intercom`** payloads with status **`forwarded`**. Call {@link RemotePlayWorld.subscribeIntercomCommands} with **`playerId`** or **`playerIds`** (one SSE stream; routes **`forwarded`** commands by **`toPlayerId`**) so your process runs tools and posts **`intercomResponse`** via {@link RemotePlayWorld.sendIntercomResponse} (the subscription does this when **`executeTool`** resolves).
|
|
174
|
+
*
|
|
175
|
+
* Set **`logging: "on"`** to trace **`forwarded`** commands for subscribed ids and **`sendIntercomResponse`** HTTP results.
|
|
386
176
|
*/
|
|
387
177
|
declare class RemotePlayWorld {
|
|
388
178
|
private readonly apiBase;
|
|
389
|
-
private readonly
|
|
390
|
-
|
|
179
|
+
private readonly rootKey;
|
|
180
|
+
/** Node id derived from hashed passphrase material + root (main or agent node id). */
|
|
181
|
+
private readonly derivedNodeId;
|
|
182
|
+
/** Hex password material (`hashNodePassword` on normalized human phrase); sent as `password` for repository addAgent. */
|
|
183
|
+
private readonly password;
|
|
184
|
+
private readonly onSessionEvent;
|
|
185
|
+
private readonly transportLog;
|
|
391
186
|
private sid;
|
|
392
187
|
private closed;
|
|
393
188
|
private readonly closeListeners;
|
|
394
|
-
|
|
189
|
+
private readonly playerConnectionInfo;
|
|
190
|
+
constructor(options?: RemotePlayWorldOptions);
|
|
191
|
+
private logTransport;
|
|
192
|
+
private truncateForLog;
|
|
193
|
+
private emitSessionEvent;
|
|
395
194
|
onClose(handler: () => void): () => void;
|
|
396
195
|
hold(): RemotePlayWorldHold;
|
|
397
196
|
private authHeaders;
|
|
398
197
|
private jsonHeaders;
|
|
399
198
|
private mergeAuthFetch;
|
|
400
|
-
|
|
199
|
+
private validateNodeIdentity;
|
|
200
|
+
/**
|
|
201
|
+
* Establishes the HTTP session via `GET /api/agent-play/session`. With {@link RemotePlayWorldConnectOptions.mainNodeId},
|
|
202
|
+
* validates node identity with `POST /api/nodes/validate` first.
|
|
203
|
+
*/
|
|
204
|
+
connect(options?: RemotePlayWorldConnectOptions): Promise<void>;
|
|
401
205
|
close(): Promise<void>;
|
|
402
206
|
getSessionId(): string;
|
|
403
207
|
getPreviewUrl(): string;
|
|
@@ -412,30 +216,41 @@ declare class RemotePlayWorld {
|
|
|
412
216
|
subscribeWorldState(callbacks: {
|
|
413
217
|
onSnapshot: (snapshot: AgentPlaySnapshot) => void;
|
|
414
218
|
onError?: (err: Error) => void;
|
|
219
|
+
onIntercomEvent?: (payload: WorldIntercomEventPayload) => void;
|
|
415
220
|
}): {
|
|
416
221
|
close: () => void;
|
|
417
222
|
};
|
|
223
|
+
/**
|
|
224
|
+
* Registers an automation agent using **agent node id** (`nodeId`), sent to the server as `agentId`.
|
|
225
|
+
*/
|
|
226
|
+
addAgent(input: AddAgentInput): Promise<RegisteredPlayer>;
|
|
227
|
+
/**
|
|
228
|
+
* @deprecated Use {@link addAgent} with `nodeId` (agent node id) for integrations and automation.
|
|
229
|
+
*/
|
|
418
230
|
addPlayer(input: AddPlayerInput): Promise<RegisteredPlayer>;
|
|
419
231
|
recordInteraction(input: RecordInteractionInput): Promise<void>;
|
|
420
232
|
recordJourney(playerId: string, journey: Journey): Promise<void>;
|
|
233
|
+
sendIntercomResponse(payload: IntercomResponsePayload): Promise<void>;
|
|
234
|
+
/**
|
|
235
|
+
* Subscribes to the session SSE stream and handles **`forwarded`** intercom commands whose **`toPlayerId`** is in **`playerId`** or **`playerIds`**, invoking **`executeTool`** and posting **`intercomResponse`** (**`completed`** / **`failed`**).
|
|
236
|
+
* Uses a **single** SSE connection when **`playerIds`** lists multiple automation agents (recommended for several agents in one process).
|
|
237
|
+
* Not invoked automatically by {@link RemotePlayWorld.addAgent}.
|
|
238
|
+
*/
|
|
239
|
+
subscribeIntercomCommands(options: SubscribeIntercomCommandsOptions): {
|
|
240
|
+
close: () => void;
|
|
241
|
+
};
|
|
421
242
|
registerMcp(options: {
|
|
422
243
|
name: string;
|
|
423
244
|
url?: string;
|
|
424
245
|
}): Promise<string>;
|
|
425
246
|
private rpc;
|
|
247
|
+
private heartbeatPlayerConnection;
|
|
248
|
+
private disconnectPlayerConnection;
|
|
426
249
|
}
|
|
427
250
|
|
|
428
251
|
/**
|
|
429
|
-
*
|
|
252
|
+
* Maps a LangChain agent **`invoke`** result to a plain object suitable for **`intercomResponse`** **`result`**.
|
|
430
253
|
*/
|
|
254
|
+
declare function intercomResultRecordFromLangChainInvokeOutput(output: unknown): Record<string, unknown>;
|
|
431
255
|
|
|
432
|
-
|
|
433
|
-
declare function parsePlayerChainFanoutNotify(raw: unknown): PlayerChainFanoutNotify | undefined;
|
|
434
|
-
declare function parsePlayerChainFanoutNotifyFromSsePayload(sseData: unknown): PlayerChainFanoutNotify | undefined;
|
|
435
|
-
declare function parsePlayerChainNodeRpcBody(json: unknown): PlayerChainNodeResponse;
|
|
436
|
-
declare function mergeSnapshotWithPlayerChainNode(snapshot: AgentPlaySnapshot, node: PlayerChainNodeResponse): AgentPlaySnapshot;
|
|
437
|
-
|
|
438
|
-
declare const PLAYER_CHAIN_GENESIS_STABLE_KEY: "__genesis__";
|
|
439
|
-
declare const PLAYER_CHAIN_HEADER_STABLE_KEY: "__header__";
|
|
440
|
-
|
|
441
|
-
export { type AddPlayerInput, type AgentPlaySnapshot, type AgentPlayWorldMap, type AgentPlayWorldMapAgentOccupant, type AgentPlayWorldMapBounds, type AgentPlayWorldMapMcpOccupant, type AssistToolSpec, type DestinationJourneyStep, type Journey, type JourneyStep, type LangChainAgentRegistration, type OriginJourneyStep, PLAYER_ADDED_EVENT, PLAYER_CHAIN_GENESIS_STABLE_KEY, PLAYER_CHAIN_HEADER_STABLE_KEY, type PlatformAgentInformation, type PlayAgentInformation, type PlayerChainFanoutNotify, type PlayerChainGenesisNode, type PlayerChainHeaderNode, type PlayerChainNodeResponse, type PlayerChainNotifyNodeRef, type PlayerChainOccupantPresentNode, type PlayerChainOccupantRemovedNode, type PositionedStep, type RecordInteractionInput, type RegisteredAgentSummary, type RegisteredPlayer, RemotePlayWorld, type RemotePlayWorldHold, type RemotePlayWorldOptions, type StructureJourneyStep, WORLD_AGENT_SIGNAL_EVENT, WORLD_INTERACTION_EVENT, WORLD_JOURNEY_EVENT, type WorldAgentSignalPayload, type WorldBounds, type WorldInteractionPayload, type WorldInteractionRole, type WorldJourneyUpdate, type YieldEventInfo, type ZoneEventInfo, agentPlayDebug, boundsContain, clampWorldPosition, configureAgentPlayDebug, isAgentPlayDebugEnabled, langchainRegistration, mergeSnapshotWithPlayerChainNode, parsePlayerChainFanoutNotify, parsePlayerChainFanoutNotifyFromSsePayload, parsePlayerChainNodeRpcBody, resetAgentPlayDebug, sortNodeRefsForSerializedFetch };
|
|
256
|
+
export { AddAgentInput, AddPlayerInput, AgentPlaySnapshot, type IntercomToolExecutor, Journey, LangChainAgentRegistration, PLAYER_ADDED_EVENT, PlayerChainNodeResponse, RecordInteractionInput, RegisteredPlayer, RemotePlayWorld, type RemotePlayWorldConnectOptions, type RemotePlayWorldHold, type RemotePlayWorldLogging, type RemotePlayWorldNodeCredentials, type RemotePlayWorldOptions, type RemotePlayWorldSessionEvent, SESSION_CLOSED_EVENT, SESSION_CONNECTED_EVENT, SESSION_INVALID_EVENT, SESSION_SSE_ERROR_EVENT, SESSION_SSE_OPEN_EVENT, type SubscribeIntercomCommandsOptions, WORLD_AGENT_SIGNAL_EVENT, WORLD_INTERACTION_EVENT, WORLD_JOURNEY_EVENT, type WorldAgentSignalPayload, type WorldInteractionPayload, WorldInteractionRole, agentPlayDebug, configureAgentPlayDebug, intercomResultRecordFromLangChainInvokeOutput, isAgentPlayDebugEnabled, langchainRegistration, resetAgentPlayDebug };
|