dsh-bailinghub 0.2.0 → 0.4.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/CHANGELOG.md +70 -0
- package/PRIVACY.md +108 -9
- package/README.md +129 -148
- package/SECURITY.md +114 -4
- package/docs/AGENT_CLIENT_CONTRACT.md +330 -23
- package/docs/COMPATIBILITY.md +75 -12
- package/docs/GETTING_STARTED.md +126 -0
- package/docs/GETTING_STARTED.zh-CN.md +113 -0
- package/docs/MIGRATION_VNEXT.md +106 -22
- package/docs/PROJECT_BOUNDARIES.md +4 -2
- package/docs/README.zh-CN.md +98 -132
- package/lib/authorizations.js +61 -0
- package/lib/conversation-archive-store.js +265 -0
- package/lib/conversation-outbox.js +230 -0
- package/lib/index.js +3 -0
- package/lib/runtime.js +1070 -64
- package/lib/session-scope-store.js +265 -0
- package/lib/session-scope.js +319 -0
- package/lib/transport.js +16 -2
- package/package.json +14 -4
package/SECURITY.md
CHANGED
|
@@ -19,15 +19,125 @@ configuration and are never model tool arguments.
|
|
|
19
19
|
|
|
20
20
|
Non-loopback HTTP is denied by default. Do not enable insecure HTTP on an untrusted network.
|
|
21
21
|
|
|
22
|
-
## Native 0.
|
|
22
|
+
## Native 0.4.0 boundary
|
|
23
23
|
|
|
24
|
-
The native 0.
|
|
24
|
+
The native 0.4.0 plugin accepts only `hubUrl`, `clientAppId`, `workspace`, and
|
|
25
25
|
`connectionName`. The generic SDK owns browser authorization, refresh, and secure credential
|
|
26
|
-
storage; business endpoints and final authorization remain Core/business-system concerns.
|
|
26
|
+
storage; business endpoints and final authorization remain Core/business-system concerns. The
|
|
27
|
+
Hub Client App owns one business authorization entry. That business page, not the plugin or model,
|
|
28
|
+
handles login, account switching, tenant selection, and the trusted `on_behalf_of` identity.
|
|
29
|
+
|
|
30
|
+
The multi-connection registry stores only public Hub/client/workspace metadata. `connectionName`
|
|
31
|
+
is a user-only local selector, not an identity claim. After browser
|
|
32
|
+
authorization, the SDK replaces an older same-binding connection only when the trusted
|
|
33
|
+
`on_behalf_of` matches; different trusted identities remain isolated. A same-alias authorization
|
|
34
|
+
for a different identity preserves the original alias and Session and assigns the new identity a
|
|
35
|
+
non-conflicting local alias. If inspection or old-Session revocation is uncertain, the new
|
|
36
|
+
connection stays authorized and explicit cleanup is required.
|
|
37
|
+
Connection add/use/remove are user slash commands, not model tools. Removing an authorized
|
|
38
|
+
connection is remote-revoke-first and keeps the local credential if revocation fails, so it cannot
|
|
39
|
+
falsely report a complete logout.
|
|
27
40
|
|
|
28
41
|
Tools are Agent/run scoped. Message ids are replaced by Core-safe hash aliases, invocation ids are
|
|
29
42
|
stable 64-character digests, and an `accepted_unknown` outcome must resume that exact invocation
|
|
30
43
|
instead of creating a replacement. Completion retries are bounded and reuse one frozen,
|
|
31
|
-
visible-only payload. Version 0.
|
|
44
|
+
visible-only payload. Version 0.4.0 installs `bailinghub-mcp-server@0.4.0` as an exact ordinary
|
|
32
45
|
dependency and resolves its `./sdk` export. It does not depend on ambient modules, an optional
|
|
33
46
|
peer, a range, a dist-tag, or a local path. Public `0.1.1` does not provide that facade.
|
|
47
|
+
|
|
48
|
+
Agent Session credentials use macOS Keychain or Windows CurrentUser DPAPI-protected files under
|
|
49
|
+
LocalAppData. Windows PowerShell or DPAPI unavailability fails closed without a plaintext fallback.
|
|
50
|
+
Linux and other POSIX hosts must explicitly enable the SDK's isolated mode-0600 file store. The
|
|
51
|
+
plugin never receives the credential value and never writes one into Cordis configuration.
|
|
52
|
+
|
|
53
|
+
## Same-system authorization selection
|
|
54
|
+
|
|
55
|
+
Version 0.4.0 lets the model select a session-local `authorization_ref` from the current
|
|
56
|
+
conversation's directory. This is a constrained per-call selector, not a connection-management
|
|
57
|
+
tool or authority to supply a Hub, route, raw connection key, credential, or business identity.
|
|
58
|
+
The host must first explicitly select fixed connection keys for this conversation through
|
|
59
|
+
`setSessionScope` or the user-only `/bailinghub scope set <connection-key>...` command. Aliases are
|
|
60
|
+
not scope keys. Unset scope and `[]` (`/bailinghub scope none`) remain ordinary chat, without
|
|
61
|
+
BailingHub tools or runs. Authorization and registry defaults cannot grant conversation scope.
|
|
62
|
+
The selected bindings must share one Hub/client/workspace; unselected bindings are excluded.
|
|
63
|
+
The adapter never implements selection by changing the SDK's global current connection.
|
|
64
|
+
|
|
65
|
+
Hosts must await successful scope persistence and confirmation before sending the first user
|
|
66
|
+
message. The first `user/message` event freezes scope, with the inbox claim as a fallback, before
|
|
67
|
+
`startTurn`; an in-flight or
|
|
68
|
+
failed selection cannot admit business work. Subsequent changes require a new conversation.
|
|
69
|
+
The full selected group is checked before business input is sent. Any missing, revoked, replaced,
|
|
70
|
+
or unreadable selected authorization pauses the whole conversation's business access. The adapter
|
|
71
|
+
must not silently adopt a default or shrink the scope to the remaining valid authorizations.
|
|
72
|
+
|
|
73
|
+
Local connection names are untrusted display data. They do not prove tenant identity, widen an
|
|
74
|
+
authorization, or replace the business system's final permission checks. The directory is a
|
|
75
|
+
binding snapshot, not a credential snapshot: expired, removed, or revoked access must fail
|
|
76
|
+
without silently selecting another authorization. New authorizations and alias changes require
|
|
77
|
+
a new conversation.
|
|
78
|
+
The host checks the fixed connection key, workspace, and original Agent Session id before
|
|
79
|
+
transport operations. An Agent Session replacement also requires a new conversation, even if
|
|
80
|
+
the local alias or connection key remains unchanged.
|
|
81
|
+
|
|
82
|
+
Matching declarations share one typed tool. Conflicting same-name descriptions, schemas, or
|
|
83
|
+
governance are not merged for execution, and a shared declaration cannot confer another identity's permissions.
|
|
84
|
+
Each invocation binds its chosen authorization, Core run, and capability revision. Recovery
|
|
85
|
+
accepts only an invocation known to this conversation and resolves its original binding; the
|
|
86
|
+
model cannot provide a replacement authorization. Changing a default connection cannot retarget
|
|
87
|
+
an existing call.
|
|
88
|
+
This invocation map lasts only for the live conversation: later turns can recover its original
|
|
89
|
+
calls, while new conversations and process restarts must reject unknown invocation ids.
|
|
90
|
+
|
|
91
|
+
Only non-secret scope metadata belongs in the scope store. Its default file store uses SHA-256 session filenames,
|
|
92
|
+
mode-0600 files and mode-0700 directories on POSIX, bounded reads, rejection of symlinks/non-regular files,
|
|
93
|
+
revision compare-and-swap, a cross-process lock, and atomic replacement. Lock timeout reports a
|
|
94
|
+
conflict without deleting another process's lock. Corrupt data and I/O failure fail closed; they
|
|
95
|
+
are never interpreted as an absent selection or a reason to use memory storage. Before validating
|
|
96
|
+
a replacement scope, the coordinator attempts to persist `needs_selection`. Failure of that first
|
|
97
|
+
write can leave the previous draft on disk. Every unlocked snapshot loaded into a new runtime is
|
|
98
|
+
therefore blocked pending explicit selection, without checking its previous SDK authorizations;
|
|
99
|
+
restart safety does not assume that the failed write replaced the old record.
|
|
100
|
+
|
|
101
|
+
The host may inject a store with the same CAS semantics; the provided memory adapter is explicitly
|
|
102
|
+
non-persistent. `restoreSessionScope` restores only a valid locked selection after verifying its
|
|
103
|
+
keys, binding, and original Agent Session ids. Unlocked drafts require explicit selection again;
|
|
104
|
+
started conversations without valid locked scope stay blocked. History containing only metadata,
|
|
105
|
+
configuration, or seed markers does not prove that a conversation started. The lifecycle check
|
|
106
|
+
requires an actual user-sourced `user/message` or `turn/start` and uses seed/observation boundaries
|
|
107
|
+
to distinguish prior history from a new first message. It restores scope only, not invocations,
|
|
108
|
+
approvals, pending completions, or task execution. A new conversation is required to change an
|
|
109
|
+
already-started scope. No token, credential, prompt, or business payload belongs in the
|
|
110
|
+
scope snapshot.
|
|
111
|
+
The trusted host owns stable, unique conversation ids and the store namespace. Scope APIs and
|
|
112
|
+
records must not be exposed as model-controlled storage or allow an untrusted caller to select
|
|
113
|
+
another conversation's id. This plugin does not secure unrelated host filesystem tools; the host
|
|
114
|
+
must enforce that access boundary.
|
|
115
|
+
|
|
116
|
+
The adapter keeps authorization-specific instructions and context labeled, and each run receives
|
|
117
|
+
only its authorization's deterministic call summary. It does not broadcast a combined final
|
|
118
|
+
answer to every run. Visible user input and context do share the local conversation boundary;
|
|
119
|
+
see [Privacy](PRIVACY.md#same-system-authorization-selection).
|
|
120
|
+
|
|
121
|
+
The independent conversation-audit extension sends visible text for the complete frozen member
|
|
122
|
+
set through an optional SDK API. A durable random archive UUID supplies correlation, not authority:
|
|
123
|
+
the SDK/Core must validate every original member before confirming or appending, and Core owns the
|
|
124
|
+
aggregate read permission. Never expose mixed free text to a reader authorized for only one member
|
|
125
|
+
by assuming it can be safely redacted. The original run id and member Session bind run links;
|
|
126
|
+
archive synchronization cannot create or resume a business action. Late links remain attached to
|
|
127
|
+
their original turn.
|
|
128
|
+
|
|
129
|
+
The separate private outbox contains plaintext visible task text and must be protected from
|
|
130
|
+
untrusted host/model filesystem tools. It has bounded reads, no-follow regular-file checks,
|
|
131
|
+
CAS/lock/atomic-write semantics, and no credential or scope-store fallback. Payloads and ids remain
|
|
132
|
+
stable on ambiguous network retries. Local I/O failure can leave an unpersisted event: available
|
|
133
|
+
DSH history is compared after reopening, and missing events produce `recovery_gap`, not a claim
|
|
134
|
+
of a complete transcript. Hosts without history must show unverified coverage. This boundary is
|
|
135
|
+
not a distributed transaction or durable business-task recovery mechanism.
|
|
136
|
+
|
|
137
|
+
Transient transport failures do not prove that an original authorization was revoked. Scope
|
|
138
|
+
get/restore and archive retry may revalidate all original members on the same runtime, while
|
|
139
|
+
keeping business access and uploads closed until validation succeeds. Concurrent callers share
|
|
140
|
+
that validation. Confirmed revocation/replacement and storage/CAS conflicts remain terminally
|
|
141
|
+
blocked, with no default or subset fallback. The gate is rechecked after asynchronous archive
|
|
142
|
+
capability discovery and outbox opening; a late result cannot erase a confirmed revocation.
|
|
143
|
+
Known local storage errors and capture gaps remain visible even while network or scope checks block upload.
|
|
@@ -1,7 +1,238 @@
|
|
|
1
1
|
# Agent Client Host Adapter Contract
|
|
2
2
|
|
|
3
|
-
Status:
|
|
4
|
-
|
|
3
|
+
Status: native Agent Client contract for `dsh-bailinghub@0.4.0`, paired with
|
|
4
|
+
`bailinghub-mcp-server@0.4.0` and recommended BailingHub Core `0.6.1` (minimum API version
|
|
5
|
+
`0.6.0`). This contract is separate from the legacy static `0.1.x` path. Version 0.3.0 supported user-managed connections but did not include
|
|
6
|
+
explicit conversation scope, multi-authorization tool selection, or the visible conversation archive.
|
|
7
|
+
|
|
8
|
+
## Same-System Authorization Selection
|
|
9
|
+
|
|
10
|
+
This increment supports multiple independently authorized identities for one public
|
|
11
|
+
`Hub + clientAppId + workspace` binding in one DSH conversation. It does not combine different
|
|
12
|
+
systems or routes, alter business capability declarations, or change Core authorization rules.
|
|
13
|
+
|
|
14
|
+
Version 0.4.0 changes the default: a new conversation with no selected scope, or an explicitly
|
|
15
|
+
empty `connectionKeys: []`, is ordinary chat. It starts no BailingHub run and exposes no BailingHub
|
|
16
|
+
business tools. Browser authorization, the registry's current connection, and the four bootstrap
|
|
17
|
+
fields do not select a conversation's scope. There is no automatic discovery-and-enable fallback.
|
|
18
|
+
|
|
19
|
+
The host explicitly selects fixed SDK connection keys before sending the first user message.
|
|
20
|
+
Exactly one selected authorization keeps the original typed arguments and result shape; two or
|
|
21
|
+
more selected authorizations use the shared envelope below. All selected keys must be authorized
|
|
22
|
+
under the same Hub/client/workspace binding. Unselected connections are never added to the scope.
|
|
23
|
+
The model receives a projected directory containing
|
|
24
|
+
session-local `authorization_ref` values, local display names, and availability, not raw connection
|
|
25
|
+
keys, credentials, Agent Session metadata,
|
|
26
|
+
or permission to supply arbitrary route or identity values. A local name is untrusted display
|
|
27
|
+
data, not proof of a tenant or store. The model must resolve ambiguous user intent before acting;
|
|
28
|
+
available authorization is not a request to act on every listed identity.
|
|
29
|
+
Labels use existing local `connectionName` metadata, not token-derived business names or a new
|
|
30
|
+
Core identity-display field. Generic aliases such as `default` and `default-2` do not establish
|
|
31
|
+
an A/B business mapping; the user must supply clear labels while the business authorization page
|
|
32
|
+
continues to determine the trusted identity.
|
|
33
|
+
|
|
34
|
+
The directory's references resolve to the explicitly selected SDK connection bindings. The first
|
|
35
|
+
`user/message` event freezes the selection, with `agent/inbox/claimed` as a fallback for drivers
|
|
36
|
+
that do not emit that event, before `startTurn`. Changing the selected keys after
|
|
37
|
+
that point requires a new conversation, including switching between ordinary chat and business
|
|
38
|
+
mode. Adding a registry authorization or changing its alias never expands an existing scope.
|
|
39
|
+
Capturing a binding does not freeze credentials or bypass refresh, expiry, revocation, or
|
|
40
|
+
downstream authorization checks.
|
|
41
|
+
Before transport operations, `status({ connectionKey })` must report the captured connection key,
|
|
42
|
+
workspace, and the original authorized Agent Session id captured during selection. If any selected
|
|
43
|
+
authorization is missing, invalid, replaced, or cannot be checked, business access for the entire
|
|
44
|
+
conversation pauses. It neither falls back to a default nor silently shrinks to the remaining
|
|
45
|
+
authorizations. A new conversation can explicitly select the still-valid subset. These inspection
|
|
46
|
+
fields stay host-side. The
|
|
47
|
+
adapter passes `connectionKey` and `workspace` as explicit SDK host metadata instead of
|
|
48
|
+
resolving a mutable alias or default.
|
|
49
|
+
|
|
50
|
+
The full selection is validated before any selected system receives the turn. For each direct
|
|
51
|
+
user turn, the adapter starts one Core run per selected authorization before
|
|
52
|
+
assembling the model request. Instructions, governance, knowledge, memory, and tool results carry
|
|
53
|
+
authorization labels. The user input is sent to each of those runs. Separate run state preserves
|
|
54
|
+
attribution; all injected context still shares the local Agent/model boundary described in
|
|
55
|
+
[Privacy](../PRIVACY.md#same-system-authorization-selection).
|
|
56
|
+
|
|
57
|
+
Business definitions with the same name, description, input schema, and governance are registered
|
|
58
|
+
once.
|
|
59
|
+
Conflicting declarations are not merged for execution. Availability remains specific to each
|
|
60
|
+
authorization, and the conversation's total active business-tool limit remains 12. In a
|
|
61
|
+
multi-authorization session, each shared definition wraps its unchanged business schema:
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"authorization_ref": "<host-issued reference from this session>",
|
|
66
|
+
"arguments": { "<business parameter>": "<value>" }
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The selector is host metadata; it is not forwarded as a business argument or new Core HTTP
|
|
71
|
+
field. A single-authorization session keeps the original unwrapped business schema.
|
|
72
|
+
`search_business_capabilities` accepts an optional `authorization_ref` using the same reference
|
|
73
|
+
boundary; omission searches all captured authorizations. Its responses update the selected
|
|
74
|
+
authorizations' capability revisions and definitions before rebuilding
|
|
75
|
+
the shared tool view. It cannot import a different binding into the conversation.
|
|
76
|
+
|
|
77
|
+
Invocation state captures the selected authorization, Core run, capability revision, tool, and
|
|
78
|
+
arguments. A replay with a different selector or payload fails closed. Recovery accepts only an
|
|
79
|
+
invocation known to this conversation and uses the original binding; it accepts no replacement
|
|
80
|
+
authorization selector. Pending approval and unknown dispatch outcomes follow the same
|
|
81
|
+
exact-invocation recovery rules as the baseline. Removing or selecting another default must not
|
|
82
|
+
retarget an existing invocation.
|
|
83
|
+
The local invocation map survives later turns of the same live conversation. It is not persisted
|
|
84
|
+
across process restarts or copied into new conversations, and unknown invocation ids fail closed.
|
|
85
|
+
This increment does not provide durable task recovery across those boundaries.
|
|
86
|
+
|
|
87
|
+
On multi-authorization completion, the adapter freezes one deterministic summary of each run's
|
|
88
|
+
own governed calls and synchronizes that run separately. It does not send the combined visible
|
|
89
|
+
assistant answer, another authorization's results, or hidden reasoning to every run. The combined
|
|
90
|
+
answer is instead eligible for the separate conversation audit below. Single-authorization completion keeps the existing visible-answer
|
|
91
|
+
behavior. Connection add/use/remove remain user-only commands, not model tools.
|
|
92
|
+
|
|
93
|
+
### Host-owned session scope API
|
|
94
|
+
|
|
95
|
+
The runtime service exposes asynchronous `getSessionScope(sessionId)`,
|
|
96
|
+
`setSessionScope(sessionId, { connectionKeys, expectedRevision? })`, and
|
|
97
|
+
`restoreSessionScope(sessionId)`. They are host APIs, never model tools. Use keys returned by the
|
|
98
|
+
SDK registry, not aliases or model-provided identity values.
|
|
99
|
+
|
|
100
|
+
Native DSH users can inspect `/bailinghub scope`, choose ordinary chat with
|
|
101
|
+
`/bailinghub scope none`, or select fixed keys with `/bailinghub scope set <connection-key>...`
|
|
102
|
+
before the first user message. Obtain keys from `/bailinghub connections list`; the scope command
|
|
103
|
+
does not accept aliases, adopt a registry default, or start a business run. These are user-only
|
|
104
|
+
commands over the same scope API.
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
const runtime = ctx.get('bailingHubAgentClient')
|
|
108
|
+
const previous = await runtime.getSessionScope(sessionId)
|
|
109
|
+
const selected = await runtime.setSessionScope(sessionId, {
|
|
110
|
+
connectionKeys: selectedConnectionKeys, // [] explicitly chooses ordinary chat
|
|
111
|
+
expectedRevision: previous.revision,
|
|
112
|
+
})
|
|
113
|
+
// Render selected.mode and selected.authorizations, then enable sending.
|
|
114
|
+
// Do not dispatch the first user message while this operation is pending or failed.
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
The returned view includes `schema`, `sessionId`, integer-or-null `revision`, `state`
|
|
118
|
+
(`unselected`, `ready`, or `needs_selection`), `locked`, `mode` (`chat`, `business`, or `blocked`),
|
|
119
|
+
and public authorization entries. `get` reads the scope; it does not grant access. A host must await
|
|
120
|
+
a successful `set`, show its returned selection, and only then send the first message. Never
|
|
121
|
+
optimistically send using an earlier scope. Before the first message, a failed replacement
|
|
122
|
+
selection leaves business access blocked; it cannot restore the previous broader selection.
|
|
123
|
+
After the scope is frozen, a change request returns `SESSION_SCOPE_LOCKED` and leaves the original
|
|
124
|
+
frozen scope unchanged. The host must open a new conversation, not treat that rejection as a
|
|
125
|
+
successful selection of the requested keys. Revision values may advance more than once
|
|
126
|
+
during selection; always use the returned value for the next compare-and-swap request.
|
|
127
|
+
|
|
128
|
+
Each returned `authorizations` entry has exactly the public host-facing fields
|
|
129
|
+
`{ authorizationRef, connectionKey, label, workspace }`. The selection accepts at most 64 unique
|
|
130
|
+
connection keys. The trusted host owns `sessionId`: it must remain stable when reopening the same
|
|
131
|
+
conversation and be unique within that store's namespace. Do not let the model or an untrusted
|
|
132
|
+
client choose another conversation's id, edit scope records, or control the storage namespace.
|
|
133
|
+
The store and its access policy belong to the host. The model sees only the projected reference,
|
|
134
|
+
label, and availability directory; raw connection keys and scope storage are not model APIs.
|
|
135
|
+
|
|
136
|
+
Reopening an existing conversation must call `restoreSessionScope` before sending. A valid
|
|
137
|
+
`locked: true` snapshot restores its original scope after the saved binding and Agent Sessions
|
|
138
|
+
are checked; it remains locked. A stored `locked: false` snapshot is only a draft, even if its
|
|
139
|
+
stored state says `ready`. Loading it into a new runtime returns `needs_selection` / `blocked`
|
|
140
|
+
without probing its previously selected SDK connections. A never-started draft remains
|
|
141
|
+
`locked: false`: the host must explicitly call `setSessionScope` again and show success before
|
|
142
|
+
sending. It must not silently reactivate the saved draft selection.
|
|
143
|
+
|
|
144
|
+
If a locked conversation is reopened offline, its business gate stays closed. A timeout,
|
|
145
|
+
connection failure, or incomplete authorization response is not proof of revocation: retry
|
|
146
|
+
`restoreSessionScope`, `getSessionScope`, or `syncSessionArchive` on the **same runtime and Session**
|
|
147
|
+
after connectivity returns. All original members must pass validation before business access or
|
|
148
|
+
archive upload resumes. Concurrent callers wait for the same in-flight whole-scope validation.
|
|
149
|
+
Retries preserve the original keys, Agent Sessions, binding, member set, and persisted scope revision.
|
|
150
|
+
Confirmed revocation, identity/binding replacement, corrupt storage, or a CAS conflict remains
|
|
151
|
+
blocked; retries never select a default, remaining subset, or replacement Session.
|
|
152
|
+
|
|
153
|
+
An old conversation without a valid snapshot stays blocked; missing or corrupt state must not
|
|
154
|
+
adopt today's registry default or discovered authorizations. Trusted history containing only
|
|
155
|
+
configuration or metadata still permits draft selection. Actual user-message or turn history
|
|
156
|
+
requires the original locked scope; changing that scope requires a new conversation. Embedded
|
|
157
|
+
hosts without the native commands or a scope-selection UI must integrate these APIs;
|
|
158
|
+
`connections use` is not a substitute.
|
|
159
|
+
|
|
160
|
+
### Scope persistence seam
|
|
161
|
+
|
|
162
|
+
`createAgentClientPlugin({ scopeStore })` accepts an explicit store with `load(sessionId)` and
|
|
163
|
+
`save(sessionId, record, expectedRevision)`. `load` returns a validated record or `null` for absence;
|
|
164
|
+
errors and corrupt records are not absence. `save` compares the stored revision atomically:
|
|
165
|
+
`null` means the record must not exist, the first revision is `1`, and each update increments it.
|
|
166
|
+
Before validating a replacement selection, the coordinator attempts to save a `needs_selection`
|
|
167
|
+
record. If that first write fails, the previous draft can remain on disk; the write is not
|
|
168
|
+
reported as successful. Restart safety also depends on the draft rule above: every loaded
|
|
169
|
+
unlocked snapshot requires explicit confirmation, so a stale saved selection never becomes
|
|
170
|
+
`ready` automatically, even when its replacement marker could not be written.
|
|
171
|
+
|
|
172
|
+
The default `createFileSessionScopeStore()` saves non-secret JSON under
|
|
173
|
+
`$DSH_HOME/plugins/dsh-bailinghub/session-scopes`, using `~/.dsh` when `DSH_HOME` is unset. Session
|
|
174
|
+
ids are hashed into filenames. On POSIX, files use mode `0600` and directories `0700`; writes use a
|
|
175
|
+
cross-process lock, compare-and-swap, and atomic replacement. Lock conflicts and storage failures
|
|
176
|
+
fail closed; the adapter never switches to an in-memory fallback. Hosts may inject another
|
|
177
|
+
durable implementation. `createMemorySessionScopeStore()` is an explicit, non-persistent option
|
|
178
|
+
for tests or hosts that deliberately accept losing scope state on restart.
|
|
179
|
+
|
|
180
|
+
The snapshot contains only the scope schema, DSH session id, revision, state/lock, public binding,
|
|
181
|
+
and selected connection keys, sanitized labels, workspace, and original Agent Session ids. It
|
|
182
|
+
contains no credentials, tokens, prompts, business arguments/results, or invocation state.
|
|
183
|
+
Restoring a scope does **not** restore an invocation, approval, pending completion, or task.
|
|
184
|
+
|
|
185
|
+
### Independent visible conversation archive
|
|
186
|
+
|
|
187
|
+
The visible archive requires SDK `0.4.0` and Core APIs introduced in `0.6.0`; the recommended
|
|
188
|
+
Core release is `0.6.1`. Earlier `0.3.0` SDK/plugin packages do not provide this contract.
|
|
189
|
+
After a nonempty scope is frozen, the adapter captures claimed user text, every durable `assistant/message` text block, turn start/end, and verified original run links. It ignores
|
|
190
|
+
`assistant/chunk`, hidden reasoning, attachments, raw provider requests, and arbitrary tool payloads.
|
|
191
|
+
The archive is one record for the complete fixed authorization set; per-authorization run summaries
|
|
192
|
+
are unchanged. It is not written into each member's memory.
|
|
193
|
+
|
|
194
|
+
The optional SDK seam is `syncConversationArchive(envelope, { members })`. `envelope` contains a
|
|
195
|
+
durable random UUID `clientArchiveId`, the same `clientConversationId` used by `startTurn`, and
|
|
196
|
+
ordered `events`. Each event has a stable UUID `event_id`, contiguous `sequence` starting at one,
|
|
197
|
+
the original `client_turn_id`, and `kind`: `turn_start`, `user_message`, `assistant_message`,
|
|
198
|
+
`run_link`, or `turn_end`. Messages contain `content`; a run link contains the original `run_id`
|
|
199
|
+
and `member_session_id`; turn end contains `completed`, `failed`, or `cancelled` status. A late
|
|
200
|
+
original run response may attach its link to an already ended turn. It never reactivates its
|
|
201
|
+
business tools, dispatches that cancelled turn's remaining members, or replaces a newer active turn.
|
|
202
|
+
The SDK receives host-only member records `{ connectionKey, workspace, expectedSessionId, label }`,
|
|
203
|
+
checks every original authorization, and owns HTTP batching and credential use. The first frozen
|
|
204
|
+
member is the writer. Neither the old hash alias nor a random archive UUID confers read/write access.
|
|
205
|
+
|
|
206
|
+
`createAgentClientPlugin({ archiveStore })` accepts an independent CAS store with `load`/`save`,
|
|
207
|
+
using the same revision semantics as the scope store but a distinct schema and directory.
|
|
208
|
+
`createFileConversationArchiveStore({ directory? })` defaults to
|
|
209
|
+
`$DSH_HOME/plugins/dsh-bailinghub/conversation-outbox`, with private file permissions, atomic writes,
|
|
210
|
+
and a 32 MiB local record bound. `createMemoryConversationArchiveStore()` is explicitly volatile.
|
|
211
|
+
Outboxes retain the frozen membership, random identity, visible events, event hashes/ids, and
|
|
212
|
+
acknowledged cursor. They contain task text; they are not credential stores. The SDK rejects a
|
|
213
|
+
message above 64,000 characters; the adapter does not silently truncate it or discard pending text.
|
|
214
|
+
Core's conversation/event quotas and the local bound can leave synchronization pending.
|
|
215
|
+
|
|
216
|
+
Host APIs `getSessionArchiveStatus(sessionId)` and `syncSessionArchive(sessionId)` and the user-only
|
|
217
|
+
`/bailinghub archive status|sync` commands expose synchronization separately from business state.
|
|
218
|
+
Persisted pending events can be retried after reopening under the original valid frozen scope,
|
|
219
|
+
without replaying `startTurn`, `invoke`, `resume`, or `completeRun`. An older SDK reports
|
|
220
|
+
`unsupported` without accessing the outbox directory; an unavailable/older Core leaves saved events
|
|
221
|
+
pending or unsupported for retry. Empty scope does not load a transport or create an archive.
|
|
222
|
+
|
|
223
|
+
Capture begins with business turns enabled under this archive contract. Previously unarchived history is not silently
|
|
224
|
+
claimed as complete. Status compares saved visible events against the available DSH `session.events`:
|
|
225
|
+
missing user/assistant text or turn boundaries report `recovery_gap` / `coverage: incomplete`, even
|
|
226
|
+
if the saved prefix is synchronized. Hosts without durable history report `coverage: unverified`.
|
|
227
|
+
This check does not reconstruct missing business run ids. Network failure leaves durable events
|
|
228
|
+
retryable; a local write failure can leave only an in-memory pending event until storage recovers.
|
|
229
|
+
While scope validation or transport availability prevents upload, a known `storage_error` or
|
|
230
|
+
`recovery_gap` remains visible with the existing unsaved-event count and coverage. An optional
|
|
231
|
+
`availability` field describes the additional upload restriction; it does not clear the local error.
|
|
232
|
+
Capability-discovery network failures report `pending`, not a fabricated local storage failure.
|
|
233
|
+
If the process ends before that write succeeds, the host-history check reports the detectable gap;
|
|
234
|
+
there is no atomic transaction between DSH's event log, this outbox, and Core. It does not promise
|
|
235
|
+
recovery of absent host history, hidden content, or durable business task execution.
|
|
5
236
|
|
|
6
237
|
## Host Configuration
|
|
7
238
|
|
|
@@ -14,9 +245,13 @@ workspace
|
|
|
14
245
|
connectionName
|
|
15
246
|
```
|
|
16
247
|
|
|
17
|
-
`hubUrl`, `clientAppId`, and `workspace` identify a public Hub-side application/workspace.
|
|
18
|
-
`connectionName`
|
|
19
|
-
|
|
248
|
+
`hubUrl`, `clientAppId`, and `workspace` identify a public Hub-side application/workspace binding.
|
|
249
|
+
`connectionName` selects a local SDK connection for connection-management commands; it does not
|
|
250
|
+
select the conversation scope. It is not an account, tenant, or
|
|
251
|
+
identity claim. The Hub Client App resolves to one stable business authorization endpoint; no
|
|
252
|
+
business endpoint, authorization endpoint, token, secret, or business credential belongs in this
|
|
253
|
+
config. The business authorization page owns sign-in, account switching, tenant selection, and
|
|
254
|
+
the trusted identity ultimately represented by `on_behalf_of`.
|
|
20
255
|
|
|
21
256
|
## Injectable Transport Seam
|
|
22
257
|
|
|
@@ -24,8 +259,13 @@ The default transport is lazily created from `bailinghub-mcp-server/sdk`. Tests
|
|
|
24
259
|
adapters may inject an object with all methods below:
|
|
25
260
|
|
|
26
261
|
```js
|
|
262
|
+
connectionsList({})
|
|
263
|
+
connectionsAdd({ connectionName, hubUrl, clientAppId, workspace })
|
|
264
|
+
connectionsUse(connectionNameOrKey)
|
|
265
|
+
connectionsRemove(connectionNameOrKey)
|
|
266
|
+
|
|
27
267
|
login({ hubUrl, clientAppId, workspace, route, connectionName })
|
|
28
|
-
status({
|
|
268
|
+
status({ connectionKey }) // conversation checks; management may use connectionName
|
|
29
269
|
logout({ connectionName })
|
|
30
270
|
workspaces({ connectionName })
|
|
31
271
|
use({ workspace, route, connectionName })
|
|
@@ -41,7 +281,7 @@ startTurn({
|
|
|
41
281
|
|
|
42
282
|
searchCapabilities({ query, limit?, runId? })
|
|
43
283
|
invoke({ invocationId, capabilityRevision, agentRunId, tool, arguments })
|
|
44
|
-
resume(invocationId, {}, { workspace,
|
|
284
|
+
resume(invocationId, {}, { workspace, connectionKey, signal? })
|
|
45
285
|
completeRun(runId, {
|
|
46
286
|
assistantMessageId,
|
|
47
287
|
content,
|
|
@@ -52,9 +292,35 @@ completeRun(runId, {
|
|
|
52
292
|
})
|
|
53
293
|
```
|
|
54
294
|
|
|
55
|
-
The adapter
|
|
56
|
-
|
|
57
|
-
|
|
295
|
+
The adapter passes host metadata (`workspace`, fixed `connectionKey`, and optional `signal`)
|
|
296
|
+
separately from the business DTO to turn/tool methods, and as the third argument to completion
|
|
297
|
+
and resume. The transport must honor that exact selection; it must never ignore it or substitute
|
|
298
|
+
a mutable alias/default. Connection-management commands may use `connectionName`. The optional
|
|
299
|
+
archive seam and its complete frozen member selection are specified above.
|
|
300
|
+
|
|
301
|
+
## Browser Identity and Local Reconciliation
|
|
302
|
+
|
|
303
|
+
`/bailinghub login` always starts from the selected Hub/client/workspace binding. The plugin does
|
|
304
|
+
not accept or derive a business URL, account id, tenant id, or identity selector. Core redirects
|
|
305
|
+
to the single authorization endpoint configured for that Client App, and the business page
|
|
306
|
+
performs any login, account switching, or tenant selection required before it approves the
|
|
307
|
+
authorization.
|
|
308
|
+
|
|
309
|
+
The SDK may stage more than one named local instance for the same public binding while browser
|
|
310
|
+
authorization is in progress. After authorization it compares the trusted Session
|
|
311
|
+
`on_behalf_of`, never the local `connectionName`:
|
|
312
|
+
|
|
313
|
+
- the same identity replaces the older local connection and revokes its old Agent Session;
|
|
314
|
+
- a different identity remains a separate named connection; when login was launched from an alias
|
|
315
|
+
already owned by the old identity, the SDK preserves that alias and Session, allocates an
|
|
316
|
+
available alias such as `default-2` to the new identity, and makes the new connection current;
|
|
317
|
+
- an uncertain identity inspection or failed old-Session revoke keeps the new Session authorized
|
|
318
|
+
and returns `cleanupRequired: true` with cleanup metadata.
|
|
319
|
+
|
|
320
|
+
The adapter reports that last result as successful authorization plus a visible warning. It tells
|
|
321
|
+
the user not to authorize again and to retry explicit cleanup with the user-only connection
|
|
322
|
+
lifecycle commands. It does not turn the result into a failed login or let the model perform
|
|
323
|
+
cleanup.
|
|
58
324
|
|
|
59
325
|
## Core HTTP Mapping
|
|
60
326
|
|
|
@@ -97,9 +363,9 @@ object-rooted input schema, and complete governance metadata (`scope`, `risk`,
|
|
|
97
363
|
Both revision fields are required lowercase 64-character SHA-256 values; shorter labels or
|
|
98
364
|
uppercase digests fail closed.
|
|
99
365
|
|
|
100
|
-
## Verified DSH
|
|
366
|
+
## Verified DSH Lifecycles
|
|
101
367
|
|
|
102
|
-
DSH `0.1.0-rc.7`
|
|
368
|
+
DSH `0.1.0-rc.7` and `0.1.1-rc.2` claim inbox messages before assembling the current step:
|
|
103
369
|
|
|
104
370
|
```text
|
|
105
371
|
agent/inbox/claimed
|
|
@@ -109,7 +375,15 @@ agent/inbox/claimed
|
|
|
109
375
|
-> model request
|
|
110
376
|
```
|
|
111
377
|
|
|
112
|
-
The adapter captures only a claimed message whose `source.kind` is `user`.
|
|
378
|
+
The adapter captures only a claimed message whose `source.kind` is `user`. The
|
|
379
|
+
first `user/message` event freezes scope; the inbox claim is a fallback if that event is absent.
|
|
380
|
+
The assembly gate permits business work only for the saved selection.
|
|
381
|
+
When inspecting attached or restored history, only `user/message` with `source.kind: 'user'` or
|
|
382
|
+
`turn/start` proves that a conversation has started. Configuration events, metadata, and
|
|
383
|
+
`session/end-seed` alone do not freeze a draft. `firstLiveSeq` is a seed-history boundary, never
|
|
384
|
+
proof of a started conversation by itself. The adapter separates the previously observed or
|
|
385
|
+
seeded prefix from new events so the current first message is not mistaken for an older turn.
|
|
386
|
+
On the authoritative
|
|
113
387
|
`system-prompt/assemble` waterfall, it calls `startTurn`, registers the returned definitions
|
|
114
388
|
through `agent.ctx.tools.register()`, and also adds their schemas to the already-sampled current
|
|
115
389
|
assembly. Later steps receive the same agent-scoped definitions from the ordinary ToolRuntime
|
|
@@ -130,10 +404,11 @@ The adapter listens to durable `session/event` values:
|
|
|
130
404
|
|
|
131
405
|
## Tool Invocation and Recovery
|
|
132
406
|
|
|
133
|
-
Every active Core tool becomes an agent-scoped DSH definition. Its
|
|
134
|
-
64-character lowercase SHA-256 digest of the session, run, DSH call id,
|
|
135
|
-
|
|
136
|
-
|
|
407
|
+
Every active Core tool becomes an agent-scoped DSH definition. Its
|
|
408
|
+
invocation id is a stable 64-character lowercase SHA-256 digest of the session, run, DSH call id,
|
|
409
|
+
and Core tool name. It
|
|
410
|
+
calls the SDK `invoke` DTO without letting the model supply the run, capability revision, route,
|
|
411
|
+
or arbitrary identity. The constrained authorization selector is described above.
|
|
137
412
|
|
|
138
413
|
An SDK error with `disposition === 'accepted_unknown'` starts recovery with the exact invocation
|
|
139
414
|
id; it never repeats the business-tool `invoke`. Likewise, `awaiting_approval`, `in_progress`, and
|
|
@@ -160,16 +435,48 @@ same bounded recovery state when known locally, and never creates a replacement
|
|
|
160
435
|
|
|
161
436
|
## Session and Completion State
|
|
162
437
|
|
|
163
|
-
Connection
|
|
164
|
-
state are isolated per DSH Agent/session.
|
|
165
|
-
|
|
438
|
+
Connection selector, workspace, conversation alias, Core run, active definitions, and completion
|
|
439
|
+
state are isolated per DSH Agent/session. Named connections for different trusted identities own
|
|
440
|
+
separate SDK credentials and Agent Sessions. Same-binding connections that resolve to the same
|
|
441
|
+
trusted identity are reconciled to one local survivor after authorization. A workspace switch
|
|
442
|
+
preserves the selected connection instance and changes connection-management defaults; it is rejected while any
|
|
443
|
+
Core run is active/completing or has an unsynchronized completion payload.
|
|
444
|
+
|
|
445
|
+
After a same-alias login resolves to a different trusted identity, the SDK-returned replacement
|
|
446
|
+
alias becomes the adapter's registry default. The retained old alias and the new alias both
|
|
447
|
+
remain visible through `connections list` and user-selectable through `connections use`; existing
|
|
448
|
+
DSH sessions remain pinned as described below.
|
|
449
|
+
|
|
450
|
+
Multi-connection add/use/remove is exposed only through the `/bailinghub connections` user
|
|
451
|
+
command. It is never registered as a model tool. Selecting a connection changes registry defaults;
|
|
452
|
+
existing states keep their captured bindings. Defaults affect connection management only;
|
|
453
|
+
the host-owned scope API alone selects the conversation's authorization directory.
|
|
454
|
+
Removing a connection is rejected while any run is active or has an unsynchronized completion. The SDK then
|
|
455
|
+
revokes only that instance's remote Agent Session before removing its local credentials and
|
|
456
|
+
registry metadata; a revoke failure preserves both. Repeating add with the same name and public
|
|
457
|
+
binding selects the existing instance; reusing a name for different public metadata fails.
|
|
458
|
+
`connectionName` remains a local user selector and never becomes a trusted identity claim.
|
|
459
|
+
|
|
460
|
+
After a successful remove, the adapter reads the registry again. A valid remaining
|
|
461
|
+
`currentConnectionKey` replaces all four public connection-management defaults, using the key itself
|
|
462
|
+
when the profile has no alias; no remaining connection sets the adapter to unconfigured. A refresh
|
|
463
|
+
failure does not change the successful remove result. It makes a removed default unavailable, but
|
|
464
|
+
does not invalidate an unchanged non-current default. Existing session state is never rewritten.
|
|
465
|
+
|
|
466
|
+
The four static adapter fields bootstrap SDK construction only. For connection management, the
|
|
467
|
+
adapter reads `connectionsList()` and adopts the public
|
|
468
|
+
metadata matching `currentConnectionKey`. Invalid, missing, or unavailable registry data leaves the
|
|
469
|
+
bootstrap defaults in place and must not remove or block unrelated host tools. The lookup is not a
|
|
470
|
+
model tool, and restoring or later selecting a default never mutates an already-created session.
|
|
471
|
+
These registry bootstrap rules do not grant business scope, even to a new
|
|
472
|
+
conversation. A failed scope load or selection never uses the bootstrap fields as a fallback.
|
|
166
473
|
|
|
167
474
|
The completion request is restricted to:
|
|
168
475
|
|
|
169
476
|
```json
|
|
170
477
|
{
|
|
171
478
|
"assistant_message_id": "stable alias",
|
|
172
|
-
"content": "visible final text",
|
|
479
|
+
"content": "visible final text for one authorization, or that run's deterministic call summary for a multi-authorization scope",
|
|
173
480
|
"status": "completed | failed | cancelled",
|
|
174
481
|
"model": "optional",
|
|
175
482
|
"runtime": "optional",
|
|
@@ -183,8 +490,8 @@ the first attempt and reused unchanged for up to three automatic attempts. A fai
|
|
|
183
490
|
remains pending in its original run; `/bailinghub sync` starts another bounded attempt batch with
|
|
184
491
|
that same id and payload.
|
|
185
492
|
|
|
186
|
-
DSH
|
|
187
|
-
`cacheWriteTokens`, and `outputTokens`) on each durable `assistant/message`. The adapter sums them
|
|
493
|
+
The verified DSH releases report disjoint camelCase buckets (`inputTokens`, `cacheReadTokens`,
|
|
494
|
+
optional `cacheWriteTokens`, and `outputTokens`) on each durable `assistant/message`. The adapter sums them
|
|
188
495
|
across model steps, exposes total input as Core `input_tokens`, cache reads as the
|
|
189
496
|
`cached_input_tokens` subset, and derives `total_tokens` without adding `reasoningTokens` a second
|
|
190
497
|
time. Unknown, non-finite, and negative metrics are discarded; only the Core public usage
|