@agent-assistant/sessions 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 +118 -0
  2. package/package.json +33 -0
package/README.md ADDED
@@ -0,0 +1,118 @@
1
+ # `@agent-assistant/sessions`
2
+
3
+ `@agent-assistant/sessions` owns assistant session continuity across surfaces and time. It provides spec-aligned session types, a session store factory, an in-memory adapter for local use and tests, and a small affinity helper for lookup-or-create flows.
4
+
5
+ ## Scope
6
+
7
+ This package owns:
8
+
9
+ - session identity and lifecycle state
10
+ - surface attachment and detachment
11
+ - stale-session suspension and explicit expiry
12
+ - metadata updates
13
+ - affinity-based session reuse helpers
14
+
15
+ This package does not own:
16
+
17
+ - memory retrieval or storage
18
+ - routing policy decisions
19
+ - surface protocol implementations
20
+ - cloud storage implementations
21
+ - product-specific rules
22
+
23
+ ## Install Shape
24
+
25
+ The package is TypeScript-first and builds to `dist/`.
26
+
27
+ ```ts
28
+ import {
29
+ InMemorySessionStoreAdapter,
30
+ createSessionStore,
31
+ defaultAffinityResolver,
32
+ resolveSession,
33
+ } from '@agent-assistant/sessions';
34
+ ```
35
+
36
+ ## Core API
37
+
38
+ ### `createSessionStore(config)`
39
+
40
+ Creates a `SessionStore` from an injected `SessionStoreAdapter`.
41
+
42
+ Supported operations:
43
+
44
+ - `create`
45
+ - `get`
46
+ - `find`
47
+ - `touch`
48
+ - `attachSurface`
49
+ - `detachSurface`
50
+ - `expire`
51
+ - `sweepStale`
52
+ - `updateMetadata`
53
+
54
+ Default TTL is one hour if `defaultTtlMs` is not provided.
55
+
56
+ ### `InMemorySessionStoreAdapter`
57
+
58
+ Local adapter backed by an in-memory `Map`. It deep-clones reads and writes so callers cannot mutate stored session state accidentally. This is the default adapter to use for tests and isolated local execution.
59
+
60
+ ### `defaultAffinityResolver(store)`
61
+
62
+ Returns an `AffinityResolver` that prefers the most recently active or suspended session for a user, and prefers a matching attached surface when one is provided.
63
+
64
+ ### `resolveSession(message, store, resolver)`
65
+
66
+ Looks up an existing session through an affinity resolver and touches it when found. If no session is resolved, it creates a new one using the inbound `userId`, optional `workspaceId`, and `surfaceId`.
67
+
68
+ ## Example
69
+
70
+ ```ts
71
+ import {
72
+ InMemorySessionStoreAdapter,
73
+ createSessionStore,
74
+ defaultAffinityResolver,
75
+ resolveSession,
76
+ } from '@agent-assistant/sessions';
77
+
78
+ const store = createSessionStore({
79
+ adapter: new InMemorySessionStoreAdapter(),
80
+ defaultTtlMs: 30 * 60 * 1000,
81
+ });
82
+
83
+ const resolver = defaultAffinityResolver(store);
84
+
85
+ const session = await resolveSession(
86
+ {
87
+ userId: 'user-123',
88
+ workspaceId: 'workspace-456',
89
+ surfaceId: 'web-thread-1',
90
+ },
91
+ store,
92
+ resolver,
93
+ );
94
+
95
+ await store.attachSurface(session.id, 'slack-dm-99');
96
+ await store.updateMetadata(session.id, { locale: 'en-US' });
97
+ ```
98
+
99
+ ## Core Integration
100
+
101
+ The store returned by `createSessionStore` is structurally compatible with core runtime registration:
102
+
103
+ ```ts
104
+ runtime.register('sessions', store);
105
+ ```
106
+
107
+ Core can then use `store.get(sessionId)` during emit and session lookup flows because returned sessions include `attachedSurfaces`.
108
+
109
+ ## Development
110
+
111
+ Run inside `packages/sessions`:
112
+
113
+ ```sh
114
+ npm test
115
+ npm run build
116
+ ```
117
+
118
+ SESSIONS_PACKAGE_IMPLEMENTED
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "@agent-assistant/sessions",
3
+ "version": "0.1.0",
4
+ "description": "Session lifecycle, storage, and affinity 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
+ }