@sealant/sdk-next 0.40.0-next.966 → 0.40.0-next.967
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/dist/facade/context.d.ts +18 -0
- package/dist/facade/context.js +11 -0
- package/dist/facade/record.js +8 -5
- package/dist/facade/run.js +5 -4
- package/dist/facade/session.js +11 -6
- package/package.json +3 -3
package/dist/facade/context.d.ts
CHANGED
|
@@ -14,5 +14,23 @@ export declare const captureTrace: (ctx: SdkContext) => CallerTrace | undefined;
|
|
|
14
14
|
* `await`s (a polling loop), so each continues the trace the call started in.
|
|
15
15
|
*/
|
|
16
16
|
export declare const bindRun: (ctx: SdkContext) => (<A, E>(effect: Effect.Effect<A, E, SdkServices>) => Promise<A>);
|
|
17
|
+
/**
|
|
18
|
+
* The calls of a loop that polls until something ends (a run, a session's output), which may last
|
|
19
|
+
* as long as an agent does. Only the calls the loop makes in the caller's name join the caller's
|
|
20
|
+
* trace (a first read, a final drain, what is read once it ended); the polls between join none.
|
|
21
|
+
*/
|
|
22
|
+
export interface Polling {
|
|
23
|
+
/** The caller's trace, for a request the loop makes outside the runtime (its SSE stream). */
|
|
24
|
+
readonly trace: CallerTrace | undefined;
|
|
25
|
+
/** A call in the caller's trace: a read the caller is waiting on, not a poll. */
|
|
26
|
+
readonly run: <A, E>(effect: Effect.Effect<A, E, SdkServices>) => Promise<A>;
|
|
27
|
+
/**
|
|
28
|
+
* A poll, in no trace: its request starts a short trace of its own on the server, rather than
|
|
29
|
+
* growing the caller's trace by a few spans every half second for as long as the loop runs.
|
|
30
|
+
*/
|
|
31
|
+
readonly poll: <A, E>(effect: Effect.Effect<A, E, SdkServices>) => Promise<A>;
|
|
32
|
+
}
|
|
33
|
+
/** {@link Polling} bound to the caller's trace captured now. */
|
|
34
|
+
export declare const bindPolling: (ctx: SdkContext) => Polling;
|
|
17
35
|
/** An AsyncIterable whose iteration rejects — for surface that is typed now but not yet implemented. */
|
|
18
36
|
export declare const notImplementedAsyncIterable: <A>(operation: string, error: Error) => AsyncIterable<A>;
|
package/dist/facade/context.js
CHANGED
|
@@ -9,6 +9,17 @@ export const bindRun = (ctx) => {
|
|
|
9
9
|
const trace = captureTrace(ctx);
|
|
10
10
|
return (effect) => ctx.runtime.run(effect, trace);
|
|
11
11
|
};
|
|
12
|
+
/** A trace that continues nothing: the call makes no spans and its request carries no trace header. */
|
|
13
|
+
const NO_TRACE = { parent: undefined, tracer: undefined, tracestate: undefined };
|
|
14
|
+
/** {@link Polling} bound to the caller's trace captured now. */
|
|
15
|
+
export const bindPolling = (ctx) => {
|
|
16
|
+
const trace = captureTrace(ctx);
|
|
17
|
+
return {
|
|
18
|
+
trace,
|
|
19
|
+
run: (effect) => ctx.runtime.run(effect, trace),
|
|
20
|
+
poll: (effect) => ctx.runtime.run(effect, NO_TRACE),
|
|
21
|
+
};
|
|
22
|
+
};
|
|
12
23
|
/** An AsyncIterable whose iteration rejects — for surface that is typed now but not yet implemented. */
|
|
13
24
|
export const notImplementedAsyncIterable = (operation, error) => ({
|
|
14
25
|
[Symbol.asyncIterator]() {
|
package/dist/facade/record.js
CHANGED
|
@@ -9,7 +9,7 @@ import { decodeRecordEventPayload, } from "@sealant/api-contracts";
|
|
|
9
9
|
import { getRunLossOp, getRunOp, getRunScrollbackOp, getRunTimelineOp, } from "../effect/operations.js";
|
|
10
10
|
import { SealantNotImplementedError } from "../errors.js";
|
|
11
11
|
import { elapsed } from "../internal/clock.js";
|
|
12
|
-
import {
|
|
12
|
+
import { bindPolling } from "./context.js";
|
|
13
13
|
// Live `stream()` is poll-backed for now: it tails the timeline endpoint until the run is terminal.
|
|
14
14
|
// The transport swaps to SSE over Postgres LISTEN/NOTIFY in Stage 5 behind this same signature.
|
|
15
15
|
const TERMINAL_RUN_STATUSES = new Set(["completed", "failed", "cancelled"]);
|
|
@@ -186,12 +186,14 @@ export const makeRunRecord = (ctx, runId) => {
|
|
|
186
186
|
transcript: async () => renderTranscript(reconstructCommands(await fetchTimeline())),
|
|
187
187
|
stream: (options) => {
|
|
188
188
|
// Captured when stream() is called: the generator's body first runs on the first next().
|
|
189
|
-
|
|
189
|
+
// The first read and the final drain join the caller's trace; the polls between are their own.
|
|
190
|
+
const polling = bindPolling(ctx);
|
|
190
191
|
async function* iterate() {
|
|
191
192
|
let from = options?.from;
|
|
192
193
|
const deadline = elapsed() + STREAM_TIMEOUT_MS;
|
|
194
|
+
let call = polling.run;
|
|
193
195
|
for (;;) {
|
|
194
|
-
const wire = await
|
|
196
|
+
const wire = await call(getRunTimelineOp(runId, {
|
|
195
197
|
ownerUserId: ctx.config.hostLocal.ownerUserId,
|
|
196
198
|
...(from === undefined ? {} : { fromSequence: from.toString() }),
|
|
197
199
|
}));
|
|
@@ -202,9 +204,10 @@ export const makeRunRecord = (ctx, runId) => {
|
|
|
202
204
|
}
|
|
203
205
|
// Stop once the run is terminal — with one final drain to catch entries written between the
|
|
204
206
|
// last timeline fetch and the status check.
|
|
205
|
-
const run = await
|
|
207
|
+
const run = await call(getRunOp(runId, ctx.config.hostLocal.ownerUserId));
|
|
208
|
+
call = polling.poll;
|
|
206
209
|
if (TERMINAL_RUN_STATUSES.has(run.status)) {
|
|
207
|
-
const tail = await
|
|
210
|
+
const tail = await polling.run(getRunTimelineOp(runId, {
|
|
208
211
|
ownerUserId: ctx.config.hostLocal.ownerUserId,
|
|
209
212
|
...(from === undefined ? {} : { fromSequence: from.toString() }),
|
|
210
213
|
}));
|
package/dist/facade/run.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getRunChangesOp, getRunOp } from "../effect/operations.js";
|
|
2
2
|
import { SealantError, SealantNotImplementedError } from "../errors.js";
|
|
3
3
|
import { elapsed } from "../internal/clock.js";
|
|
4
|
-
import {
|
|
4
|
+
import { bindPolling } from "./context.js";
|
|
5
5
|
import { makeRunRecord } from "./record.js";
|
|
6
6
|
/** Maps the wire changes shape to the facade data (shared with the run-harness execution path). */
|
|
7
7
|
export const toRunChangesData = (wire) => ({
|
|
@@ -47,8 +47,9 @@ export const makeRun = (ctx, init) => {
|
|
|
47
47
|
artifacts: emptyArtifacts,
|
|
48
48
|
record: makeRunRecord(ctx, runId),
|
|
49
49
|
wait: async () => {
|
|
50
|
-
//
|
|
51
|
-
|
|
50
|
+
// The polls are their own short traces; what wait() reads once the run is terminal joins
|
|
51
|
+
// the trace it was called in.
|
|
52
|
+
const { run, poll } = bindPolling(ctx);
|
|
52
53
|
let current = init.wire;
|
|
53
54
|
const deadline = elapsed() + WAIT_TIMEOUT_MS;
|
|
54
55
|
while (!TERMINAL_STATUSES.has(current.status)) {
|
|
@@ -58,7 +59,7 @@ export const makeRun = (ctx, init) => {
|
|
|
58
59
|
});
|
|
59
60
|
}
|
|
60
61
|
await delay(WAIT_POLL_INTERVAL_MS);
|
|
61
|
-
current = await
|
|
62
|
+
current = await poll(getRunOp(runId, ctx.config.hostLocal.ownerUserId));
|
|
62
63
|
}
|
|
63
64
|
// Settle the changes: a handle from `harness.start()` or `runs.get()` has none captured yet,
|
|
64
65
|
// so read the server-side capture now that the run is terminal.
|
package/dist/facade/session.js
CHANGED
|
@@ -4,7 +4,7 @@ import { traceHeaders } from "../effect/trace.js";
|
|
|
4
4
|
import { SealantBudgetExceededError } from "../errors.js";
|
|
5
5
|
import { resolveRequestPriority } from "../internal/config.js";
|
|
6
6
|
import { toSealantError } from "../internal/map-error.js";
|
|
7
|
-
import {
|
|
7
|
+
import { bindPolling } from "./context.js";
|
|
8
8
|
/**
|
|
9
9
|
* Open the held-WebSocket terminal attachment (the data plane). One socket:
|
|
10
10
|
* binary frames are PTY bytes in both directions, text frames are control
|
|
@@ -189,16 +189,20 @@ async function* streamOverSse(ctx, sessionId, from, signal, priority, trace) {
|
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
/** Poll-backed fallback: page the range endpoint until the session settles. */
|
|
192
|
-
async function* streamByPolling(ctx, sessionId, from, signal,
|
|
192
|
+
async function* streamByPolling(ctx, sessionId, from, signal, polling) {
|
|
193
193
|
let cursor = from;
|
|
194
|
+
// The first page continues the caller's trace; every later one is a poll of its own, so a
|
|
195
|
+
// session's output read this way never holds one trace open for the agent's whole life.
|
|
196
|
+
let call = polling.run;
|
|
194
197
|
for (;;) {
|
|
195
198
|
if (signal?.aborted === true) {
|
|
196
199
|
return;
|
|
197
200
|
}
|
|
198
|
-
const page = await
|
|
201
|
+
const page = await call(getSessionOutputOp(sessionId, {
|
|
199
202
|
ownerUserId: ctx.config.hostLocal.ownerUserId,
|
|
200
203
|
from: cursor.toString(),
|
|
201
|
-
})
|
|
204
|
+
}));
|
|
205
|
+
call = polling.poll;
|
|
202
206
|
for (const chunk of page.chunks) {
|
|
203
207
|
yield { sequence: BigInt(chunk.sequence), data: decodeBase64(chunk.dataBase64) };
|
|
204
208
|
}
|
|
@@ -229,7 +233,8 @@ export const makeInteractiveSession = (ctx, wire) => {
|
|
|
229
233
|
const from = options?.from ?? 0n;
|
|
230
234
|
const signal = options?.signal;
|
|
231
235
|
// Captured when output() is called: the generator's body first runs on the first next().
|
|
232
|
-
const
|
|
236
|
+
const polling = bindPolling(ctx);
|
|
237
|
+
const trace = polling.trace;
|
|
233
238
|
async function* iterate() {
|
|
234
239
|
let cursor = from;
|
|
235
240
|
const priority = resolveRequestPriority(ctx.config.requestPriority);
|
|
@@ -250,7 +255,7 @@ export const makeInteractiveSession = (ctx, wire) => {
|
|
|
250
255
|
// from the cursor; the sequence keying makes the switch seamless.
|
|
251
256
|
void error;
|
|
252
257
|
}
|
|
253
|
-
yield* streamByPolling(ctx, sessionId, cursor, signal,
|
|
258
|
+
yield* streamByPolling(ctx, sessionId, cursor, signal, polling);
|
|
254
259
|
}
|
|
255
260
|
return iterate();
|
|
256
261
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sealant/sdk-next",
|
|
3
|
-
"version": "0.40.0-next.
|
|
3
|
+
"version": "0.40.0-next.967",
|
|
4
4
|
"description": "The fluent public SDK for Sealant — create a workspace, run a harness, replay the record.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"node": ">=20"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@sealant/api-contracts": "npm:@sealant/api-contracts-next@0.40.0-next.
|
|
29
|
+
"@sealant/api-contracts": "npm:@sealant/api-contracts-next@0.40.0-next.967"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"effect": "^4.0.5"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "e14bfdd3f73f866926b07ba8a57d0066c0d4afad",
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
}
|