@stigmer/cli 3.41.0 → 3.41.1-dev.20261003094357.g39d6aa748646
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/commands/config/context.js +3 -3
- package/commands/config/context.js.map +1 -1
- package/commands/resume.d.ts.map +1 -1
- package/commands/resume.js +12 -13
- package/commands/resume.js.map +1 -1
- package/commands/run.js +2 -2
- package/commands/run.js.map +1 -1
- package/config/config.d.ts +1 -1
- package/config/config.d.ts.map +1 -1
- package/config/keys.js +3 -3
- package/config/keys.js.map +1 -1
- package/config/resolve.d.ts +1 -1
- package/config/resolve.js +5 -5
- package/config/resolve.js.map +1 -1
- package/local/artifact.d.ts +28 -6
- package/local/artifact.d.ts.map +1 -1
- package/local/artifact.js +88 -13
- package/local/artifact.js.map +1 -1
- package/local/bootstrap.js +1 -1
- package/local/bootstrap.js.map +1 -1
- package/local/daemon/components.js +1 -1
- package/local/daemon/components.js.map +1 -1
- package/local/net/tcp.js +1 -1
- package/local/net/tcp.js.map +1 -1
- package/local/temporal/download.d.ts +12 -2
- package/local/temporal/download.d.ts.map +1 -1
- package/local/temporal/download.js +6 -2
- package/local/temporal/download.js.map +1 -1
- package/package.json +7 -7
- package/resources/run/prepare.d.ts +1 -1
- package/resources/run/prepare.js +4 -4
- package/resources/run/prepare.js.map +1 -1
- package/resources/run/resume.d.ts +0 -1
- package/resources/run/resume.d.ts.map +1 -1
- package/resources/run/resume.js +7 -4
- package/resources/run/resume.js.map +1 -1
- package/resources/run/workflow-stream.d.ts +9 -0
- package/resources/run/workflow-stream.d.ts.map +1 -1
- package/resources/run/workflow-stream.js +24 -4
- package/resources/run/workflow-stream.js.map +1 -1
- package/resources/stream/headless.d.ts +16 -0
- package/resources/stream/headless.d.ts.map +1 -1
- package/resources/stream/headless.js +33 -5
- package/resources/stream/headless.js.map +1 -1
- package/resources/usage.d.ts +2 -2
- package/resources/usage.d.ts.map +1 -1
- package/resources/usage.js +4 -4
- package/resources/usage.js.map +1 -1
- package/src/commands/config/context.ts +3 -3
- package/src/commands/resume.ts +11 -17
- package/src/commands/run.ts +2 -2
- package/src/config/config.ts +1 -1
- package/src/config/keys.ts +3 -3
- package/src/config/resolve.ts +5 -5
- package/src/local/artifact.ts +120 -15
- package/src/local/bootstrap.ts +1 -1
- package/src/local/daemon/components.ts +1 -1
- package/src/local/net/tcp.ts +1 -1
- package/src/local/temporal/download.ts +14 -4
- package/src/resources/run/prepare.ts +4 -4
- package/src/resources/run/resume.ts +7 -4
- package/src/resources/run/workflow-stream.ts +23 -3
- package/src/resources/stream/headless.ts +31 -4
- package/src/resources/usage.ts +4 -4
|
@@ -31,6 +31,12 @@ export interface HeadlessRenderer {
|
|
|
31
31
|
resolveApproval(event: ApprovalNeededEvent): ApprovalAction;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* How long the driver keeps reading after the terminal snapshot, for the
|
|
36
|
+
* server to end the subscription, before it cancels the call itself.
|
|
37
|
+
*/
|
|
38
|
+
export const SUBSCRIPTION_DRAIN_GRACE_MS = 2_000;
|
|
39
|
+
|
|
34
40
|
/** The terminal outcome of a headless stream. */
|
|
35
41
|
export interface HeadlessResult {
|
|
36
42
|
readonly phase: string;
|
|
@@ -52,20 +58,41 @@ export interface HeadlessStreamDeps {
|
|
|
52
58
|
* Drive the stream to a terminal phase and return the outcome. Aborting (Ctrl-C)
|
|
53
59
|
* resolves cleanly with an empty result; a dropped stream renders a stream_error
|
|
54
60
|
* and returns its message.
|
|
61
|
+
*
|
|
62
|
+
* The subscription never outlives the drive (#1522). After the terminal
|
|
63
|
+
* snapshot the driver keeps reading, ignoring what follows, until the server
|
|
64
|
+
* ends the subscription, which it does on a terminal phase: an HTTP/2 stream
|
|
65
|
+
* whose unread frames are left in its buffer is never destroyed, and an open
|
|
66
|
+
* stream holds the session, and with it the process, alive after the run has
|
|
67
|
+
* finished. Leaving the loop early, or aborting the call once the server has
|
|
68
|
+
* already closed its side, does not release it. A server that does not end the
|
|
69
|
+
* stream within SUBSCRIPTION_DRAIN_GRACE_MS is cancelled, and the subscription
|
|
70
|
+
* is subscribed with a signal of the driver's own (joined to the caller's),
|
|
71
|
+
* aborted on every way out.
|
|
55
72
|
*/
|
|
56
73
|
export async function runHeadlessStream(deps: HeadlessStreamDeps): Promise<HeadlessResult> {
|
|
57
74
|
const differ = new SnapshotDiffer();
|
|
75
|
+
const subscription = new AbortController();
|
|
76
|
+
let outcome: HeadlessResult | undefined;
|
|
77
|
+
let grace: ReturnType<typeof setTimeout> | undefined;
|
|
58
78
|
try {
|
|
59
|
-
for await (const snapshot of deps.subscribe(deps.signal)) {
|
|
60
|
-
|
|
61
|
-
|
|
79
|
+
for await (const snapshot of deps.subscribe(AbortSignal.any([deps.signal, subscription.signal]))) {
|
|
80
|
+
if (outcome !== undefined) continue;
|
|
81
|
+
outcome = await drainSnapshot(differ.next(snapshot), deps);
|
|
82
|
+
if (outcome !== undefined) {
|
|
83
|
+
grace = setTimeout(() => subscription.abort(), SUBSCRIPTION_DRAIN_GRACE_MS);
|
|
84
|
+
}
|
|
62
85
|
}
|
|
63
|
-
return { phase: "", error: "" };
|
|
86
|
+
return outcome ?? { phase: "", error: "" };
|
|
64
87
|
} catch (err) {
|
|
88
|
+
if (outcome !== undefined) return outcome;
|
|
65
89
|
if (deps.signal.aborted) return { phase: "", error: "" };
|
|
66
90
|
const message = classifyStreamError(err, deps.sessionId);
|
|
67
91
|
deps.renderer.render({ kind: "streamError", error: message });
|
|
68
92
|
return { phase: "", error: message };
|
|
93
|
+
} finally {
|
|
94
|
+
clearTimeout(grace);
|
|
95
|
+
subscription.abort();
|
|
69
96
|
}
|
|
70
97
|
}
|
|
71
98
|
|
package/src/resources/usage.ts
CHANGED
|
@@ -41,21 +41,21 @@ export async function getSessionUsageReport(client: Stigmer, sessionId: string):
|
|
|
41
41
|
export async function getAgentUsageReport(
|
|
42
42
|
client: Stigmer,
|
|
43
43
|
agentId: string,
|
|
44
|
-
|
|
44
|
+
org: string,
|
|
45
45
|
range: DateRange,
|
|
46
46
|
): Promise<GetAgentUsageReportOutput> {
|
|
47
47
|
return client.agentExecution.getAgentUsageReport(
|
|
48
|
-
create(GetAgentUsageReportInputSchema, { agentId,
|
|
48
|
+
create(GetAgentUsageReportInputSchema, { agentId, org, fromDate: range.from, toDate: range.to }),
|
|
49
49
|
);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
export async function getOrgUsageReport(
|
|
53
53
|
client: Stigmer,
|
|
54
|
-
|
|
54
|
+
org: string,
|
|
55
55
|
range: DateRange,
|
|
56
56
|
): Promise<GetOrgUsageReportOutput> {
|
|
57
57
|
return client.agentExecution.getOrgUsageReport(
|
|
58
|
-
create(GetOrgUsageReportInputSchema, {
|
|
58
|
+
create(GetOrgUsageReportInputSchema, { org, fromDate: range.from, toDate: range.to }),
|
|
59
59
|
);
|
|
60
60
|
}
|
|
61
61
|
|