@anureo/adapter-pi 0.0.0-stage → 0.3.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/LICENSE +201 -0
- package/README.md +119 -2
- package/package.json +64 -4
- package/protocol/1.5.2/run.json +792 -0
- package/src/adapter.d.ts +212 -0
- package/src/adapter.js +730 -0
- package/src/catalog.d.ts +17 -0
- package/src/catalog.js +23 -0
- package/src/host.d.ts +257 -0
- package/src/host.js +361 -0
- package/src/index.d.ts +8 -0
- package/src/index.js +6 -0
- package/src/mapping.d.ts +104 -0
- package/src/mapping.js +324 -0
- package/src/options.d.ts +20 -0
- package/src/options.js +0 -0
- package/src/profile.d.ts +28 -0
- package/src/profile.js +43 -0
package/src/adapter.d.ts
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { type AhpRequestMap, type AhpResultMap, type Capabilities, type InitializeParams, type InitializeResult, type SessionBinding, type SessionOpenParams } from '@anureo/protocol';
|
|
2
|
+
import { type BackendSession, type HarnessAdapter, type SessionEventSink, type SessionMethod, type StructuredOutputToolPort } from '@anureo/sdk';
|
|
3
|
+
import { type PiHostFactory, type PiSessionHost } from "./host.js";
|
|
4
|
+
import { type Redactor } from "./mapping.js";
|
|
5
|
+
import type { PiAdapterOptions } from "./options.js";
|
|
6
|
+
import { type PiProfile } from "./profile.js";
|
|
7
|
+
/** Connect an SDK client to Pi. Hosts open on session admission. Await client disposal to release them. */
|
|
8
|
+
export declare function createPiAdapter(options?: PiAdapterOptions): PiAdapter;
|
|
9
|
+
/**
|
|
10
|
+
* Connect createClient to Pi hosts. Applications normally use createPiAdapter and await client
|
|
11
|
+
* disposal. Direct adapter consumers must await disposal of the adapter and its tracked sessions.
|
|
12
|
+
*/
|
|
13
|
+
export declare class PiAdapter implements HarnessAdapter {
|
|
14
|
+
/** Capture the version, host factory and redactor without I/O. Omitting the version selects the baseline profile. */
|
|
15
|
+
constructor(options?: PiAdapterOptions);
|
|
16
|
+
/** Requested persistence, defaulting to true. Hosts persist only when the version profile supports resume. */
|
|
17
|
+
get persist(): boolean;
|
|
18
|
+
/** Native capability set for negotiation; the SDK may add structured output when a host exposes its tool port. */
|
|
19
|
+
get capabilities(): Capabilities;
|
|
20
|
+
/**
|
|
21
|
+
* Negotiate protocol v1 without opening Pi. Return runtime info and native capabilities for
|
|
22
|
+
* Client.initialize through the output wrapper. Invalid or incompatible requests and disposed
|
|
23
|
+
* adapters reject.
|
|
24
|
+
*/
|
|
25
|
+
initialize(params: InitializeParams): Promise<InitializeResult>;
|
|
26
|
+
/**
|
|
27
|
+
* Acquire an owned backend for OutputSession.open with host observation registered. A disposed
|
|
28
|
+
* adapter, non-Pi binding or nonempty MCP server list rejects before acquisition. If open fails
|
|
29
|
+
* after construction, attempt backend disposal before rethrowing the setup failure. The output
|
|
30
|
+
* wrapper owns disposal of the returned backend.
|
|
31
|
+
*/
|
|
32
|
+
openSession(params: SessionOpenParams, sink: SessionEventSink): Promise<BackendSession>;
|
|
33
|
+
/** Attempt release of all tracked sessions concurrently. Reject the first failure in tracking order after all attempts settle. Later calls are no-ops. */
|
|
34
|
+
dispose(): Promise<void>;
|
|
35
|
+
/** Supply the host factory to PiBackendSession.open. The acquiring backend owns each returned host. */
|
|
36
|
+
hostFactory(): PiHostFactory;
|
|
37
|
+
/** PiBackendSession.dispose removes itself after release. Turn mappings remain available for resume and fork. */
|
|
38
|
+
forget(session: PiBackendSession): void;
|
|
39
|
+
/** Find a tracked source for PiBackendSession.forkHost to borrow. The source backend retains disposal ownership. */
|
|
40
|
+
liveHost(nativeId: string): PiSessionHost | undefined;
|
|
41
|
+
/** Original option object retained by reference; host paths/history limits are read when used. */
|
|
42
|
+
readonly options: PiAdapterOptions;
|
|
43
|
+
/** Version profile selected at construction. Persistence policy also affects advertised capabilities. */
|
|
44
|
+
readonly profile: PiProfile;
|
|
45
|
+
private readonly sessions;
|
|
46
|
+
/** Shared maps keyed by Pi session ID, then native user entry ID, to retain SDK turn IDs across resume and fork. */
|
|
47
|
+
readonly turnMaps: Map<string, Map<string, string>>;
|
|
48
|
+
/** Content redactor shared by backends, captured from the constructor options. */
|
|
49
|
+
readonly redact: Redactor;
|
|
50
|
+
private readonly factory;
|
|
51
|
+
private disposed;
|
|
52
|
+
private version;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Observe and control one Pi session through the SDK backend port. OutputSession adopts the
|
|
56
|
+
* backend returned by PiAdapter.openSession and owns disposal. Input receipts acknowledge native
|
|
57
|
+
* admission. Sink events carry later execution and settlement.
|
|
58
|
+
*/
|
|
59
|
+
export declare class PiBackendSession implements BackendSession {
|
|
60
|
+
private readonly adapter;
|
|
61
|
+
private readonly params;
|
|
62
|
+
private readonly sink;
|
|
63
|
+
/**
|
|
64
|
+
* Prepare one backend without acquiring a host. PiAdapter.openSession supplies the request and sink.
|
|
65
|
+
* Unknown config options throw CAPABILITY_UNSUPPORTED and invalid schema values throw
|
|
66
|
+
* INVALID_PARAMS. Await open before dispatching requests and dispose after use or failed open.
|
|
67
|
+
*/
|
|
68
|
+
constructor(adapter: PiAdapter, params: SessionOpenParams, sink: SessionEventSink);
|
|
69
|
+
/**
|
|
70
|
+
* Expose direct tool registration when the acquired host supports it. OutputSession supplies the
|
|
71
|
+
* definition and its validation callback before dispatch. It passes undefined on terminal,
|
|
72
|
+
* definite rejection of an unbound submission or release. Host registration failures propagate
|
|
73
|
+
* to the wrapper, which owns candidate validation and publication.
|
|
74
|
+
*/
|
|
75
|
+
get structuredOutputTool(): StructuredOutputToolPort | undefined;
|
|
76
|
+
/** Pi session ID after open, or the requested native reference before acquisition. A missing reference returns an empty string. */
|
|
77
|
+
get nativeId(): string;
|
|
78
|
+
/**
|
|
79
|
+
* PiAdapter.openSession calls once before returning this backend. Acquire and bind the host,
|
|
80
|
+
* retain pre-run entries and subscribe in that order so new user entries can identify live turns.
|
|
81
|
+
* Acquisition failures use sdkError with PI_SESSION_OPEN_FAILED as fallback. The adapter owns
|
|
82
|
+
* disposal if binding or subscription setup fails after acquisition.
|
|
83
|
+
*/
|
|
84
|
+
open(): Promise<void>;
|
|
85
|
+
/**
|
|
86
|
+
* Dispatch an SDK-validated request from OutputSession.execute after open. Submission resolves
|
|
87
|
+
* on native admission, interrupt after abort and compact after native compaction. Sink events
|
|
88
|
+
* independently report execution completion. Unsupported requests, closed sessions and native
|
|
89
|
+
* failures reject. Close awaits disposal and reports execution stop as unconfirmed.
|
|
90
|
+
*/
|
|
91
|
+
execute<M extends SessionMethod>(method: M, params: AhpRequestMap[M]): Promise<AhpResultMap[M]>;
|
|
92
|
+
/**
|
|
93
|
+
* Share one cleanup attempt across callers. Stop admission, unsubscribe and discard pending
|
|
94
|
+
* inputs before best-effort abort and awaited host disposal. Host disposal failure rejects the
|
|
95
|
+
* shared promise and leaves adapter tracking intact; cleanup does not await event-tail drainage.
|
|
96
|
+
*/
|
|
97
|
+
dispose(): Promise<void>;
|
|
98
|
+
/** Acquired by open; backend disposal owns its release, including partially completed setup. */
|
|
99
|
+
host: PiSessionHost;
|
|
100
|
+
/** Requested SDK identity, with the native reference replaced after acquisition. */
|
|
101
|
+
binding: SessionBinding;
|
|
102
|
+
/** Native capabilities captured for attachment; direct output support is projected by the SDK wrapper. */
|
|
103
|
+
readonly capabilities: Capabilities;
|
|
104
|
+
private readonly redact;
|
|
105
|
+
private unsubscribe?;
|
|
106
|
+
private active?;
|
|
107
|
+
private pending;
|
|
108
|
+
private closed;
|
|
109
|
+
private release?;
|
|
110
|
+
private config;
|
|
111
|
+
private model?;
|
|
112
|
+
private capabilityRevision;
|
|
113
|
+
private title?;
|
|
114
|
+
private tail;
|
|
115
|
+
private turns;
|
|
116
|
+
private snapshots;
|
|
117
|
+
private compactions;
|
|
118
|
+
/** Entry ids that existed before the current run, so the run's own user entry can be told apart. */
|
|
119
|
+
private known;
|
|
120
|
+
/** Snapshot entry ids at open/turn completion so the next run can associate its first new user entry. */
|
|
121
|
+
private markKnown;
|
|
122
|
+
/** Build host options before native-open error wrapping, preserving validation failures as parameter errors. */
|
|
123
|
+
private hostOptions;
|
|
124
|
+
/** Acquire a new, resumed or forked host; open publishes its binding only after acquisition succeeds. */
|
|
125
|
+
private acquireHost;
|
|
126
|
+
/** Resolve config before the open request's permission mode; omission keeps native host defaults. */
|
|
127
|
+
private permissionMode;
|
|
128
|
+
/**
|
|
129
|
+
* Fork from a tracked source or a temporary resumed host. Copy the SDK turn IDs retained by
|
|
130
|
+
* the branch so open can register them for the new session. Always attempt to dispose the
|
|
131
|
+
* temporary source and suppress that cleanup failure. The live source remains borrowed.
|
|
132
|
+
*/
|
|
133
|
+
private forkHost;
|
|
134
|
+
/**
|
|
135
|
+
* The listener registered by open appends events here without blocking Pi. Await each handler in
|
|
136
|
+
* arrival order and skip queued work after close. Report mapping or publication failures through
|
|
137
|
+
* OutputSession's forwarding sink, which delegates observation failure to Session.fail. Disposal
|
|
138
|
+
* unsubscribes and leaves any in-flight handler to finish independently.
|
|
139
|
+
*/
|
|
140
|
+
private enqueue;
|
|
141
|
+
/** Return detached binding and config for config receipts and post-terminal state. Capabilities remain shared. */
|
|
142
|
+
private snapshot;
|
|
143
|
+
/** Publish a new turn before binding pending inputs; retries/continuations reuse the active turn until settlement. */
|
|
144
|
+
private beginTurn;
|
|
145
|
+
/**
|
|
146
|
+
* Route serialized host callbacks to the sink or turn state. Wait for settlement across native
|
|
147
|
+
* retries and continuations. A run error can end the turn early, and source loss fails observation.
|
|
148
|
+
*/
|
|
149
|
+
private handle;
|
|
150
|
+
/** Start tool items only at execution, when Pi has finalized the name and arguments. */
|
|
151
|
+
private startTool;
|
|
152
|
+
/** Ignore updates without a running turn's matching tool item; publish redacted output deltas otherwise. */
|
|
153
|
+
private updateTool;
|
|
154
|
+
/** Complete only tool items already observed in the active turn. */
|
|
155
|
+
private endTool;
|
|
156
|
+
/** Outside a turn, report compaction as a notice because item events require a turn scope. */
|
|
157
|
+
private startCompaction;
|
|
158
|
+
/** Match the latest compaction item inside a turn, or publish an unscoped completion/failure notice. */
|
|
159
|
+
private endCompaction;
|
|
160
|
+
/** Native settlement completes the active turn, or rejects inputs that never acquired an execution. */
|
|
161
|
+
private settle;
|
|
162
|
+
/** Address the same assistant content block in both streaming updates and the final message. */
|
|
163
|
+
private itemId;
|
|
164
|
+
/**
|
|
165
|
+
* Accumulate streamed text and reasoning using stable item IDs. Text completion waits for
|
|
166
|
+
* message_end to select its phase. Tool items start at execution, when arguments are final.
|
|
167
|
+
*/
|
|
168
|
+
private messageUpdate;
|
|
169
|
+
/**
|
|
170
|
+
* Associate the first new user entry with this turn. For assistant messages, retain usage and
|
|
171
|
+
* errors and publish completed text blocks with their final or commentary phase. Successful
|
|
172
|
+
* assistant continuations clear earlier attempt failures.
|
|
173
|
+
*/
|
|
174
|
+
private messageEnd;
|
|
175
|
+
/**
|
|
176
|
+
* On the first user message end, record the new Pi entry so history and fork can resolve the
|
|
177
|
+
* SDK turn ID. Further user messages may belong to queued continuations of the same turn.
|
|
178
|
+
*/
|
|
179
|
+
private recordTurnStart;
|
|
180
|
+
/**
|
|
181
|
+
* Complete unfinished tool items, then publish usage, the terminal and ready state in order.
|
|
182
|
+
* Native interruption takes precedence over a recorded failure. Clear active state before terminal
|
|
183
|
+
* publication so the emitted snapshot is ready; publication failures flow to enqueue's sink failure.
|
|
184
|
+
*/
|
|
185
|
+
private finishTurn;
|
|
186
|
+
/**
|
|
187
|
+
* Convert input before native admission. Reserve idle input before prompt can emit events. Other
|
|
188
|
+
* inputs use followUp or steer, then join an active turn if present or wait for a binding event.
|
|
189
|
+
* Extension handling returns acceptance without a turn. Native failures use PI_SUBMIT_FAILED
|
|
190
|
+
* as a fallback code. OutputSession prepares schema-bearing input before dispatch.
|
|
191
|
+
*/
|
|
192
|
+
private submit;
|
|
193
|
+
/**
|
|
194
|
+
* Check the patch before applying model, thinking and tools in order, then publish and return
|
|
195
|
+
* the new state. PI_CONFIG_FAILED is the fallback for host mutations with an unknown outcome.
|
|
196
|
+
* Earlier mutations can survive later failures. The config and revision commit after all host
|
|
197
|
+
* mutations succeed, before publication.
|
|
198
|
+
*/
|
|
199
|
+
private setConfig;
|
|
200
|
+
/**
|
|
201
|
+
* Return the validated model and thinking level for setConfig to apply, or throw INVALID_PARAMS.
|
|
202
|
+
* A requested model governs the allowed thinking levels, with the host's active levels as fallback.
|
|
203
|
+
*/
|
|
204
|
+
private validateModelConfig;
|
|
205
|
+
/**
|
|
206
|
+
* Return detached item pages from redacted active-branch history. Reuse snapshotToken with
|
|
207
|
+
* nextCursor to keep paging over the same snapshot. New reads retain the configured history
|
|
208
|
+
* suffix, keep up to eight snapshots and evict the oldest first. Pages default to 200 items,
|
|
209
|
+
* capped at 1000. Invalid offsets reject CURSOR_INVALID and unavailable tokens reject CURSOR_EXPIRED.
|
|
210
|
+
*/
|
|
211
|
+
private readHistory;
|
|
212
|
+
}
|