@agent-assistant/surfaces 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.
Files changed (2) hide show
  1. package/README.md +175 -0
  2. package/package.json +33 -0
package/README.md ADDED
@@ -0,0 +1,175 @@
1
+ # `@agent-assistant/surfaces`
2
+
3
+ `@agent-assistant/surfaces` provides the assistant-facing surface layer for Agent Assistant SDK. It owns surface registration, inbound normalization, outbound dispatch, formatting hooks, and multi-surface fanout. It does not implement transport protocols or product-specific surface logic.
4
+
5
+ ## Responsibilities
6
+
7
+ - register and track `SurfaceConnection` records
8
+ - expose a single registry that satisfies the inbound and outbound adapter contracts used by `@agent-assistant/core`
9
+ - normalize raw inbound payloads into the structural `InboundMessage` shape core expects
10
+ - dispatch outbound events to one surface or fan them out across session-attached surfaces
11
+ - apply optional per-surface formatting hooks before delivery
12
+
13
+ ## Non-Goals
14
+
15
+ - transport implementation such as HTTP, WebSocket, Slack Events, or desktop IPC
16
+ - authentication, webhook verification, or provider SDK concerns
17
+ - product-specific formatting conventions or UI behavior
18
+ - buffering, retries, or offline queueing
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ npm install @agent-assistant/surfaces
24
+ ```
25
+
26
+ ## Core Concepts
27
+
28
+ `SurfaceConnection` describes one registered surface, including its adapter, capabilities, and current state.
29
+
30
+ `SurfaceAdapter` is implemented by product code or a transport-facing package. The adapter is responsible only for connection state callbacks and final payload delivery.
31
+
32
+ `createSurfaceRegistry()` returns one object that acts as:
33
+
34
+ - the surface registry
35
+ - the core inbound adapter
36
+ - the core outbound adapter
37
+
38
+ That lets products wire one registry instance into the runtime and the relay-facing transport layer.
39
+
40
+ ## Usage
41
+
42
+ ```ts
43
+ import { createAssistant } from '@agent-assistant/core';
44
+ import { createSurfaceRegistry } from '@agent-assistant/surfaces';
45
+
46
+ const surfaces = createSurfaceRegistry();
47
+
48
+ const runtime = createAssistant(
49
+ {
50
+ id: 'assistant-1',
51
+ name: 'Assistant',
52
+ capabilities: {
53
+ chat: async (message, context) => {
54
+ await context.runtime.emit({
55
+ surfaceId: message.surfaceId,
56
+ text: `echo:${message.text}`,
57
+ });
58
+ },
59
+ },
60
+ },
61
+ {
62
+ inbound: surfaces,
63
+ outbound: surfaces,
64
+ },
65
+ );
66
+ ```
67
+
68
+ ## Registering A Surface
69
+
70
+ ```ts
71
+ surfaces.register({
72
+ id: 'web-primary',
73
+ type: 'web',
74
+ state: 'registered',
75
+ capabilities: {
76
+ markdown: true,
77
+ richBlocks: false,
78
+ attachments: false,
79
+ streaming: false,
80
+ maxResponseLength: 0,
81
+ },
82
+ adapter: {
83
+ async send(payload) {
84
+ // Deliver payload to your transport layer.
85
+ },
86
+ onConnect(callback) {
87
+ // Store and call when the transport becomes active.
88
+ },
89
+ onDisconnect(callback) {
90
+ // Store and call when the transport becomes inactive.
91
+ },
92
+ },
93
+ });
94
+ ```
95
+
96
+ When the adapter reports connect or disconnect events, the registry updates `connection.state` in place.
97
+
98
+ ## Inbound Flow
99
+
100
+ Relay-facing code pushes raw events into the registry:
101
+
102
+ ```ts
103
+ surfaces.receiveRaw('web-primary', {
104
+ messageId: 'msg-1',
105
+ userId: 'user-1',
106
+ text: 'hello',
107
+ capability: 'chat',
108
+ });
109
+ ```
110
+
111
+ Default normalization extracts:
112
+
113
+ - `id` from `messageId` or `id`, otherwise a generated UUID
114
+ - `sessionId` from `sessionId` or `session.id`
115
+ - `userId` from `userId`, `user.id`, or `user` when it is a string
116
+ - `workspaceId` from `workspaceId` or `workspace.id`
117
+ - `text` from `text`, `content`, or `body`
118
+ - `receivedAt` from `timestamp` or `receivedAt`, otherwise the current time
119
+ - `capability` from `capability` or `type`, otherwise `'chat'`
120
+
121
+ If `userId` is missing, the message is dropped and an error is logged. If text is missing, an empty string is used and a warning is logged.
122
+
123
+ Products with non-standard relay payloads can replace the default normalization logic with `normalizationHook`.
124
+
125
+ ## Outbound Delivery
126
+
127
+ Targeted delivery uses `send(event)` and requires `event.surfaceId`.
128
+
129
+ ```ts
130
+ await surfaces.send({
131
+ surfaceId: 'web-primary',
132
+ text: 'Hello from the assistant',
133
+ });
134
+ ```
135
+
136
+ If a connection has a `formatHook`, the hook receives the outbound event and the surface capabilities and can return any surface-specific formatted structure. Without a hook, the adapter receives `event.text` as the formatted output.
137
+
138
+ Adapter failures are wrapped in `SurfaceDeliveryError`.
139
+
140
+ ## Fanout
141
+
142
+ When core resolves a session into a set of attached surface IDs, the registry can deliver to all of them:
143
+
144
+ ```ts
145
+ const result = await surfaces.fanout(
146
+ {
147
+ sessionId: 'session-1',
148
+ text: 'This reaches every attached surface',
149
+ },
150
+ ['web-primary', 'desktop-1'],
151
+ );
152
+ ```
153
+
154
+ Fanout behavior:
155
+
156
+ - sends concurrently by default
157
+ - skips unknown surfaces
158
+ - skips inactive surfaces by default
159
+ - can continue collecting failures or abort on the first failure
160
+ - returns a `FanoutResult` with per-surface outcomes
161
+
162
+ Default fanout behavior can be configured with `defaultFanoutPolicy`.
163
+
164
+ ## Package Boundary
165
+
166
+ This package is TypeScript-first, runtime-light, and has no cloud assumptions. It does not depend on specific transport stacks, does not import session logic at runtime, and does not contain relay transport implementations.
167
+
168
+ ## Development
169
+
170
+ ```bash
171
+ npm test
172
+ npm run build
173
+ ```
174
+
175
+ SURFACES_PACKAGE_IMPLEMENTED
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@agent-assistant/surfaces",
3
+ "version": "0.1.0",
4
+ "description": "Surface connection registry, inbound normalization, and outbound dispatch for Agent Assistant SDK",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc -p tsconfig.json",
19
+ "test": "vitest run",
20
+ "test:watch": "vitest"
21
+ },
22
+ "devDependencies": {
23
+ "typescript": "^5.9.3",
24
+ "vitest": "^3.2.4"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/AgentWorkforce/agent-assistant"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public"
32
+ }
33
+ }