t3code-cli 0.14.1 → 0.15.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/README.md +37 -1
- package/dist/application.d.ts +2 -2
- package/dist/application.js +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.js +1 -1
- package/dist/bin.js +1305 -424
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +1 -1
- package/dist/client-runtime/authorization.d.ts +1 -1
- package/dist/client-runtime/authorization.js +1 -1
- package/dist/client-runtime/connection.d.ts +1 -1
- package/dist/client-runtime/connection.js +1 -1
- package/dist/client-runtime/environment.d.ts +7 -1
- package/dist/client-runtime/environment.js +1 -1
- package/dist/client-runtime/errors.js +1 -1
- package/dist/client-runtime/operations/projects.d.ts +2 -2
- package/dist/client-runtime/operations/projects.js +2 -2
- package/dist/client-runtime/operations.d.ts +2 -2
- package/dist/client-runtime/operations.js +2 -2
- package/dist/client-runtime/platform.d.ts +1 -1
- package/dist/client-runtime/platform.js +1 -1
- package/dist/client-runtime/relay.d.ts +13 -2
- package/dist/client-runtime/relay.js +12 -2
- package/dist/client-runtime/rpc.d.ts +2 -2
- package/dist/client-runtime/rpc.js +2 -2
- package/dist/client-runtime/state/assets.d.ts +17 -11
- package/dist/client-runtime/state/assets.js +1 -1
- package/dist/client-runtime/state/auth.d.ts +1 -1
- package/dist/client-runtime/state/auth.js +1 -1
- package/dist/client-runtime/state/connections.js +1 -1
- package/dist/client-runtime/state/entities.d.ts +1 -1
- package/dist/client-runtime/state/entities.js +1 -1
- package/dist/client-runtime/state/filesystem.d.ts +1 -1
- package/dist/client-runtime/state/filesystem.js +1 -1
- package/dist/client-runtime/state/git.d.ts +6 -5
- package/dist/client-runtime/state/git.js +1 -1
- package/dist/client-runtime/state/models.d.ts +1 -1
- package/dist/client-runtime/state/models.js +1 -1
- package/dist/client-runtime/state/orchestration.d.ts +42 -2
- package/dist/client-runtime/state/orchestration.js +13 -1
- package/dist/client-runtime/state/presentation.d.ts +15 -3
- package/dist/client-runtime/state/presentation.js +1 -1
- package/dist/client-runtime/state/preview.d.ts +58 -48
- package/dist/client-runtime/state/preview.js +3 -2
- package/dist/client-runtime/state/project-grouping.d.ts +26 -2
- package/dist/client-runtime/state/project-grouping.js +83 -3
- package/dist/client-runtime/state/projects.d.ts +24 -18
- package/dist/client-runtime/state/projects.js +1 -1
- package/dist/client-runtime/state/pull-requests.d.ts +478 -0
- package/dist/client-runtime/state/pull-requests.js +172 -0
- package/dist/client-runtime/state/relay.d.ts +1 -1
- package/dist/client-runtime/state/relay.js +1 -1
- package/dist/client-runtime/state/review.d.ts +16 -1
- package/dist/client-runtime/state/review.js +27 -6
- package/dist/client-runtime/state/runtime.d.ts +2 -2
- package/dist/client-runtime/state/runtime.js +2 -2
- package/dist/client-runtime/state/server.d.ts +311 -172
- package/dist/client-runtime/state/server.js +192 -16
- package/dist/client-runtime/state/session.d.ts +77 -7
- package/dist/client-runtime/state/session.js +32 -3
- package/dist/client-runtime/state/shell.d.ts +47 -7
- package/dist/client-runtime/state/shell.js +1 -1
- package/dist/client-runtime/state/source-control.d.ts +2 -2
- package/dist/client-runtime/state/source-control.js +1 -1
- package/dist/client-runtime/state/subagentRuntime.d.ts +145 -0
- package/dist/client-runtime/state/subagentRuntime.js +521 -0
- package/dist/client-runtime/state/terminal.d.ts +17 -17
- package/dist/client-runtime/state/terminal.js +1 -1
- package/dist/client-runtime/state/thread-search.d.ts +23 -0
- package/dist/client-runtime/state/thread-search.js +38 -0
- package/dist/client-runtime/state/thread-settled.d.ts +32 -4
- package/dist/client-runtime/state/thread-settled.js +2 -157
- package/dist/client-runtime/state/thread-sort.d.ts +59 -2
- package/dist/client-runtime/state/thread-sort.js +128 -2
- package/dist/client-runtime/state/threads.d.ts +115 -3
- package/dist/client-runtime/state/threads.js +309 -28
- package/dist/client-runtime/state/vcs.d.ts +14 -14
- package/dist/client-runtime/state/vcs.js +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js +1 -1
- package/dist/connection.d.ts +1 -1
- package/dist/connection.js +1 -1
- package/dist/contracts.d.ts +1 -1
- package/dist/contracts.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +1 -1
- package/dist/orchestration.d.ts +155 -6
- package/dist/orchestration.js +2 -2
- package/dist/preview.d.ts +1 -1
- package/dist/preview.js +1 -1
- package/dist/rpc.d.ts +887 -360
- package/dist/rpc.js +1 -1
- package/dist/runtime.d.ts +1 -1
- package/dist/runtime.js +1 -1
- package/dist/shared/DrainableWorker.js +1 -1
- package/dist/shared/KeyedCoalescingWorker.js +1 -1
- package/dist/shared/Net.d.ts +6 -0
- package/dist/shared/Net.js +2 -1
- package/dist/shared/advertisedEndpoint.d.ts +1 -1
- package/dist/shared/advertisedEndpoint.js +1 -1
- package/dist/shared/agentAwareness.d.ts +1 -1
- package/dist/shared/backgroundActivitySettings.d.ts +1 -1
- package/dist/shared/composerInlineTokens.js +1 -1
- package/dist/shared/connectAuth.d.ts +23 -4
- package/dist/shared/connectAuth.js +40 -7
- package/dist/shared/devHome.js +1 -1
- package/dist/shared/dpop.js +1 -1
- package/dist/shared/git.d.ts +1 -1
- package/dist/shared/httpObservability.js +1 -1
- package/dist/shared/httpReadiness.js +1 -1
- package/dist/shared/keybindings.d.ts +2 -2
- package/dist/shared/keybindings.js +15 -1
- package/dist/shared/model.d.ts +1 -1
- package/dist/shared/oauthScope.js +1 -1
- package/dist/shared/observability.d.ts +8 -1
- package/dist/shared/observability.js +49 -5
- package/dist/shared/path.js +1 -1
- package/dist/shared/preview.js +1 -1
- package/dist/shared/previewViewport.d.ts +1 -1
- package/dist/shared/previewViewport.js +1 -1
- package/dist/shared/projectFavicon.d.ts +2 -1
- package/dist/shared/projectFavicon.js +13 -1
- package/dist/shared/projectScripts.d.ts +1 -1
- package/dist/shared/relayAuth.js +1 -1
- package/dist/shared/relayClient.d.ts +1 -1
- package/dist/shared/relayClient.js +1 -1
- package/dist/shared/relayJwt.js +1 -1
- package/dist/shared/relayTracing.js +1 -1
- package/dist/shared/relayUrl.js +1 -1
- package/dist/shared/remote.js +1 -1
- package/dist/shared/schemaYaml.js +3 -3
- package/dist/shared/semver.js +1 -1
- package/dist/shared/serverSettings.d.ts +1 -1
- package/dist/shared/serverSettings.js +1 -1
- package/dist/shared/shell.d.ts +6 -1
- package/dist/shared/shell.js +42 -4
- package/dist/shared/sourceControl.d.ts +1 -1
- package/dist/shared/t3ProjectFile.d.ts +9 -1
- package/dist/shared/t3ProjectFile.js +12 -2
- package/dist/shared/terminalLabels.d.ts +1 -1
- package/dist/shared/threadEnvMode.d.ts +29 -0
- package/dist/shared/threadEnvMode.js +24 -0
- package/dist/shared/toolActivity.d.ts +1 -1
- package/dist/shared/usageFormat.d.ts +34 -0
- package/dist/shared/usageFormat.js +176 -0
- package/dist/shared/usageMerge.d.ts +78 -0
- package/dist/shared/usageMerge.js +241 -0
- package/dist/shared.d.ts +8268 -1372
- package/dist/shared.js +22185 -19774
- package/dist/t3tools.d.ts +2 -2
- package/dist/t3tools.js +2 -2
- package/package.json +5 -5
- package/src/application/error.ts +2 -2
- package/src/application/index.ts +2 -0
- package/src/application/service.ts +43 -5
- package/src/application/thread-commands.ts +78 -0
- package/src/application/threads.ts +156 -17
- package/src/cli/app.ts +4 -0
- package/src/cli/ask-lifecycle.ts +331 -0
- package/src/cli/ask.ts +390 -0
- package/src/cli/error.ts +70 -0
- package/src/cli/format/thread.ts +49 -7
- package/src/cli/search.ts +48 -0
- package/src/cli/thread.ts +12 -0
- package/src/cli/threads/messages.ts +33 -3
- package/src/cli/threads/pin.ts +46 -0
- package/src/cli/threads/send.ts +5 -1
- package/src/cli/threads/settle.ts +46 -0
- package/src/cli/threads/snooze.ts +117 -0
- package/src/cli/threads/start.ts +6 -1
- package/src/cli/threads/unpin.ts +48 -0
- package/src/cli/threads/unsettle.ts +48 -0
- package/src/cli/threads/unsnooze.ts +48 -0
- package/src/config/persist/schema.ts +1 -1
- package/src/connection/prepared.ts +12 -2
- package/src/orchestration/error.ts +10 -0
- package/src/orchestration/index.ts +1 -0
- package/src/orchestration/layer.ts +78 -0
- package/src/orchestration/service.ts +16 -3
- package/src/rpc/error.ts +2 -0
- package/src/rpc/operation.ts +2 -0
- package/src/rpc/ws-group.ts +3 -0
- package/src/runtime/layer.ts +9 -4
|
@@ -1,5 +1,97 @@
|
|
|
1
|
-
import { $
|
|
1
|
+
import { $A as runHead, $j as ignore, Aj as andThen, By as changes, CM as sync, DD as set, DN as seconds, Dr as followStreamInEnvironment, ED as make$2, EM as timeoutOption, EN as minutes, GM as hasInterruptsOnly, GN as none, Gj as flatMap, HN as isSome, Ha as safeErrorLogAttributes, Hj as exit, Hy as make$1, Ia as EnvironmentRegistry, JM as squash, KM as isFailReason, KN as some, Ka as EnvironmentCacheStore, Kj as fn, Kr as make, LA as filter, Lk as String, Mj as as, NA as debounce, NM as void_, Nj as asVoid, Nk as Literals, OD as update, Oj as addFinalizer, PN as flatten, Pr as scheduleAtomCommandEffect, QA as runForEach, Qj as gen, RA as filterMap, RN as getOrNull, Ra as EnvironmentSupervisor, SN as succeed$1, Sr as createRuntimeCommand, TD as get$1, UN as map, Uj as fail, Uy as set$1, VA as fromQueue, VN as isNone, Vy as get, WA as mapAccum, WN as match, Wj as failCause, Wr as family, Xj as forkChild, Xk as optional, Yr as withLabel, Zj as forkScoped, _r as createEnvironmentRpcCommand, ai as isRpcClientError, bM as sleep, bj as sliding, br as createEnvironmentRpcSubscriptionAtomFamily, cM as onExit, cN as isFailure, ci as subscribe, ei as value, gj as offer, jj as annotateLogs, lN as isSuccess, lc as WS_METHODS, mr as createAtomCommandScheduler, nM as logWarning, oi as request, qN as toArray, qr as setIdleTTL, rM as map$1, si as runStream, sj as unwrap, vN as failVoid, vr as createEnvironmentRpcQueryAtomFamily, xM as succeed, zj as catch_, zk as TaggedErrorClass } from "../../shared.js";
|
|
2
2
|
//#region upstream-t3code/packages/client-runtime/src/state/server.ts
|
|
3
|
+
const IDLE_SERVER_UPDATE_STATE = { status: "idle" };
|
|
4
|
+
const EMPTY_SERVER_UPDATE_STATE_ATOM = make(IDLE_SERVER_UPDATE_STATE).pipe(withLabel("environment-data:server:update-state:empty"));
|
|
5
|
+
const serverUpdateStateAtom = family((environmentId) => make(IDLE_SERVER_UPDATE_STATE).pipe(withLabel(`environment-data:server:update-state:${environmentId}`)));
|
|
6
|
+
var ServerUpdateResumeTimeoutError = class extends TaggedErrorClass()("ServerUpdateResumeTimeoutError", {
|
|
7
|
+
environmentId: String,
|
|
8
|
+
targetVersion: String
|
|
9
|
+
}) {
|
|
10
|
+
get message() {
|
|
11
|
+
return `The server did not resume on t3@${this.targetVersion}.`;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var ServerUpdateProgressIncompleteError = class extends TaggedErrorClass()("ServerUpdateProgressIncompleteError", { targetVersion: String }) {
|
|
15
|
+
get message() {
|
|
16
|
+
return `The t3@${this.targetVersion} update ended before the server accepted the restart.`;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var ServerUpdateTerminalError = class extends TaggedErrorClass()("ServerUpdateTerminalError", {
|
|
20
|
+
targetVersion: String,
|
|
21
|
+
status: Literals([
|
|
22
|
+
"committed",
|
|
23
|
+
"rolled-back",
|
|
24
|
+
"failed"
|
|
25
|
+
]),
|
|
26
|
+
reason: optional(String)
|
|
27
|
+
}) {
|
|
28
|
+
get message() {
|
|
29
|
+
return this.reason ?? `The t3@${this.targetVersion} update ${this.status}.`;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const SERVER_UPDATE_RESUME_TIMEOUT = minutes(4);
|
|
33
|
+
function matchesServerUpdateReadyEvent(result, event) {
|
|
34
|
+
return result.updateId === void 0 ? event.payload.environment.serverVersion === result.targetVersion : event.payload.updateOutcome?.id === result.updateId;
|
|
35
|
+
}
|
|
36
|
+
function validateServerUpdateReadyEvent(result, event) {
|
|
37
|
+
if (result.updateId === void 0) return void_;
|
|
38
|
+
const outcome = event.payload.updateOutcome;
|
|
39
|
+
if (outcome?.id === result.updateId && outcome.status === "committed" && outcome.targetVersion === result.targetVersion && event.payload.environment.serverVersion === result.targetVersion) return void_;
|
|
40
|
+
return fail(new ServerUpdateTerminalError({
|
|
41
|
+
targetVersion: result.targetVersion,
|
|
42
|
+
status: outcome?.status ?? "failed",
|
|
43
|
+
reason: outcome?.reason ?? "The service launcher resumed without committing the requested server version."
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Keeps reconnect attempts ~1s apart for the whole update restart.
|
|
48
|
+
*
|
|
49
|
+
* A restart takes the server down for ~15 seconds, but the supervisor's normal
|
|
50
|
+
* backoff ladder (1/2/4/8/16s) assumes an unexpected failure and lands attempts
|
|
51
|
+
* at ~3, 5, 9, 17 and 33 seconds — so a 15-second restart is observed as a
|
|
52
|
+
* 33-second "Resuming". Nudging on every backoff entry (not just the first)
|
|
53
|
+
* holds the retry cadence flat until the server answers again. The sleep before
|
|
54
|
+
* each nudge is the pacer: a connection that fails instantly re-enters backoff
|
|
55
|
+
* immediately and would otherwise spin a tight retry loop.
|
|
56
|
+
*
|
|
57
|
+
* Callers fork this as a child of the update command so it is interrupted as
|
|
58
|
+
* soon as the update settles, whether it succeeds, fails, or times out.
|
|
59
|
+
*/
|
|
60
|
+
function nudgeReconnectDuringUpdateRestart(input) {
|
|
61
|
+
return input.stateChanges.pipe(filter((state) => state.phase === "backoff"), runForEach(() => sleep(input.interval ?? seconds(1)).pipe(andThen(input.retryNow))), timeoutOption(SERVER_UPDATE_RESUME_TIMEOUT), ignore);
|
|
62
|
+
}
|
|
63
|
+
function serverUpdateStateForProgressEvent(fromVersion, targetVersion, event) {
|
|
64
|
+
return {
|
|
65
|
+
status: "running",
|
|
66
|
+
stage: event.type === "complete" ? "resuming" : event.stage,
|
|
67
|
+
fromVersion,
|
|
68
|
+
targetVersion
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function serverUpdateStateForServerVersion(state, serverVersion) {
|
|
72
|
+
return state.status === "idle" || state.status === "running" || serverVersion === null || state.fromVersion === serverVersion ? state : IDLE_SERVER_UPDATE_STATE;
|
|
73
|
+
}
|
|
74
|
+
function serverUpdateFailureMessage(error) {
|
|
75
|
+
return error instanceof Error ? error.message : "Server update failed.";
|
|
76
|
+
}
|
|
77
|
+
function isRpcSocketError(error) {
|
|
78
|
+
if (!isRpcClientError(error)) return false;
|
|
79
|
+
switch (error.reason._tag) {
|
|
80
|
+
case "SocketReadError":
|
|
81
|
+
case "SocketWriteError":
|
|
82
|
+
case "SocketCloseError": return true;
|
|
83
|
+
default: return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function isLegacyUpdateHandoffLoss(cause) {
|
|
87
|
+
if (hasInterruptsOnly(cause)) return true;
|
|
88
|
+
return cause.reasons.length > 0 && cause.reasons.every((reason) => isFailReason(reason) && isRpcSocketError(reason.error));
|
|
89
|
+
}
|
|
90
|
+
function resolveServerUpdateProgressResult(targetVersion, terminal, streamExit) {
|
|
91
|
+
if (isSome(terminal) && (isSuccess(streamExit) || isLegacyUpdateHandoffLoss(streamExit.cause))) return succeed(terminal.value);
|
|
92
|
+
if (isFailure(streamExit)) return failCause(streamExit.cause);
|
|
93
|
+
return fail(new ServerUpdateProgressIncompleteError({ targetVersion }));
|
|
94
|
+
}
|
|
3
95
|
function applyServerConfigProjection(current, event) {
|
|
4
96
|
switch (event.type) {
|
|
5
97
|
case "snapshot": return some({
|
|
@@ -52,7 +144,7 @@ const makeEnvironmentServerConfigState = fn("EnvironmentServerConfigState.make")
|
|
|
52
144
|
const supervisor = yield* EnvironmentSupervisor;
|
|
53
145
|
const cache = yield* EnvironmentCacheStore;
|
|
54
146
|
const environmentId = supervisor.target.environmentId;
|
|
55
|
-
const state = yield* make(map(yield* cache.loadServerConfig(environmentId).pipe(catch_((error) => logWarning("Could not load cached server configuration.").pipe(annotateLogs({
|
|
147
|
+
const state = yield* make$1(map(yield* cache.loadServerConfig(environmentId).pipe(catch_((error) => logWarning("Could not load cached server configuration.").pipe(annotateLogs({
|
|
56
148
|
environmentId,
|
|
57
149
|
...safeErrorLogAttributes(error)
|
|
58
150
|
}), as(none())))), (config) => ({
|
|
@@ -61,7 +153,7 @@ const makeEnvironmentServerConfigState = fn("EnvironmentServerConfigState.make")
|
|
|
61
153
|
source: "cache"
|
|
62
154
|
})));
|
|
63
155
|
const persistence = yield* sliding(1);
|
|
64
|
-
const pendingPersistence = yield* make$
|
|
156
|
+
const pendingPersistence = yield* make$2(none());
|
|
65
157
|
const persist = fn("EnvironmentServerConfigState.persist")(function* (config) {
|
|
66
158
|
return yield* cache.saveServerConfig(environmentId, config).pipe(as(true), catch_((error) => logWarning("Could not persist cached server configuration.").pipe(annotateLogs({
|
|
67
159
|
environmentId,
|
|
@@ -89,7 +181,7 @@ const makeEnvironmentServerConfigState = fn("EnvironmentServerConfigState.make")
|
|
|
89
181
|
function serverConfigStateChanges(environmentId) {
|
|
90
182
|
return followStreamInEnvironment(environmentId, unwrap(makeEnvironmentServerConfigState().pipe(map$1((state) => changes(state).pipe(filterMap((projection) => match(projection, {
|
|
91
183
|
onNone: () => failVoid,
|
|
92
|
-
onSome: (value) => succeed(value)
|
|
184
|
+
onSome: (value) => succeed$1(value)
|
|
93
185
|
})))))));
|
|
94
186
|
}
|
|
95
187
|
function projectServerWelcome(current, event) {
|
|
@@ -98,31 +190,115 @@ function projectServerWelcome(current, event) {
|
|
|
98
190
|
return [some(welcome), [welcome]];
|
|
99
191
|
}
|
|
100
192
|
function resolveServerConfigValue(projection, initialConfig) {
|
|
101
|
-
if (projection?.source === "live") return projection.config;
|
|
193
|
+
if (projection?.source === "live" && (initialConfig === null || projection.config.environment.serverVersion === initialConfig.environment.serverVersion)) return projection.config;
|
|
102
194
|
return initialConfig ?? projection?.config ?? null;
|
|
103
195
|
}
|
|
104
196
|
function createServerEnvironmentAtoms(runtime, options) {
|
|
105
197
|
const configScheduler = createAtomCommandScheduler();
|
|
198
|
+
const updateScheduler = createAtomCommandScheduler();
|
|
106
199
|
const configConcurrency = {
|
|
107
200
|
mode: "serial",
|
|
108
201
|
key: ({ environmentId }) => environmentId
|
|
109
202
|
};
|
|
110
203
|
const configProjectionFamily = family((environmentId) => runtime.atom(serverConfigStateChanges(environmentId)).pipe(setIdleTTL(5 * 6e4), withLabel(`environment-data:server:config-projection:${environmentId}`)));
|
|
111
204
|
const configProjection = (target) => configProjectionFamily(target.environmentId);
|
|
112
|
-
const emptyConfigAtom = make
|
|
205
|
+
const emptyConfigAtom = make(null).pipe(withLabel("environment-data:server:config:empty"));
|
|
113
206
|
const configValueAtom = family((environmentId) => {
|
|
114
207
|
if (environmentId === null) return emptyConfigAtom;
|
|
115
|
-
return make
|
|
208
|
+
return make((get) => {
|
|
116
209
|
return resolveServerConfigValue(getOrNull(value(get(configProjection({
|
|
117
210
|
environmentId,
|
|
118
211
|
input: {}
|
|
119
212
|
})))), get(options.initialConfigValueAtom(environmentId)));
|
|
120
213
|
}).pipe(withLabel(`environment-data:server:config:${environmentId}`));
|
|
121
214
|
});
|
|
215
|
+
const updateStateValueAtom = family((environmentId) => make((get) => serverUpdateStateForServerVersion(get(serverUpdateStateAtom(environmentId)), get(configValueAtom(environmentId))?.environment.serverVersion ?? null)).pipe(withLabel(`environment-data:server:update-state-value:${environmentId}`)));
|
|
216
|
+
const updateStateAtom = (environmentId) => environmentId === null ? EMPTY_SERVER_UPDATE_STATE_ATOM : updateStateValueAtom(environmentId);
|
|
217
|
+
const updateServer = createRuntimeCommand(runtime, {
|
|
218
|
+
label: "environment-data:server:update-server",
|
|
219
|
+
scheduler: updateScheduler,
|
|
220
|
+
concurrency: configConcurrency,
|
|
221
|
+
execute: (target, atomRegistry) => {
|
|
222
|
+
const stateAtom = serverUpdateStateAtom(target.environmentId);
|
|
223
|
+
const targetVersion = target.input.targetVersion;
|
|
224
|
+
let fromVersion = atomRegistry.get(configValueAtom(target.environmentId))?.environment.serverVersion ?? targetVersion;
|
|
225
|
+
let currentStage = "downloading";
|
|
226
|
+
atomRegistry.set(stateAtom, {
|
|
227
|
+
status: "running",
|
|
228
|
+
stage: currentStage,
|
|
229
|
+
fromVersion,
|
|
230
|
+
targetVersion
|
|
231
|
+
});
|
|
232
|
+
return gen(function* () {
|
|
233
|
+
const environmentRegistry = yield* EnvironmentRegistry;
|
|
234
|
+
const result = yield* scheduleAtomCommandEffect(atomRegistry, configScheduler, configConcurrency, target, gen(function* () {
|
|
235
|
+
const currentConfig = atomRegistry.get(configValueAtom(target.environmentId));
|
|
236
|
+
fromVersion = currentConfig?.environment.serverVersion ?? targetVersion;
|
|
237
|
+
atomRegistry.set(stateAtom, {
|
|
238
|
+
status: "running",
|
|
239
|
+
stage: currentStage,
|
|
240
|
+
fromVersion,
|
|
241
|
+
targetVersion
|
|
242
|
+
});
|
|
243
|
+
const updateResult = currentConfig?.environment.capabilities.serverSelfUpdateProgress === true ? yield* gen(function* () {
|
|
244
|
+
const terminal = yield* make$2(none());
|
|
245
|
+
const streamExit = yield* environmentRegistry.runStream(target.environmentId, runStream(WS_METHODS.serverUpdateServerWithProgress, target.input)).pipe(runForEach((event) => sync(() => {
|
|
246
|
+
currentStage = event.type === "complete" ? "resuming" : event.stage;
|
|
247
|
+
atomRegistry.set(stateAtom, serverUpdateStateForProgressEvent(fromVersion, targetVersion, event));
|
|
248
|
+
}).pipe(andThen(event.type === "complete" ? set(terminal, some(event.result)) : void_))), exit);
|
|
249
|
+
return yield* resolveServerUpdateProgressResult(targetVersion, yield* get$1(terminal), streamExit);
|
|
250
|
+
}) : yield* gen(function* () {
|
|
251
|
+
const selfUpdateMethod = currentConfig?.environment.capabilities.serverSelfUpdate;
|
|
252
|
+
const exit$1 = yield* environmentRegistry.run(target.environmentId, request(WS_METHODS.serverUpdateServer, target.input)).pipe(exit);
|
|
253
|
+
if (isSuccess(exit$1)) return exit$1.value;
|
|
254
|
+
if ((selfUpdateMethod === "boot-service" || selfUpdateMethod === "respawn") && isLegacyUpdateHandoffLoss(exit$1.cause)) return {
|
|
255
|
+
targetVersion,
|
|
256
|
+
method: selfUpdateMethod
|
|
257
|
+
};
|
|
258
|
+
return yield* failCause(exit$1.cause);
|
|
259
|
+
});
|
|
260
|
+
currentStage = "resuming";
|
|
261
|
+
atomRegistry.set(stateAtom, {
|
|
262
|
+
status: "running",
|
|
263
|
+
stage: currentStage,
|
|
264
|
+
fromVersion,
|
|
265
|
+
targetVersion
|
|
266
|
+
});
|
|
267
|
+
return updateResult;
|
|
268
|
+
}));
|
|
269
|
+
yield* nudgeReconnectDuringUpdateRestart({
|
|
270
|
+
stateChanges: environmentRegistry.stateChanges(target.environmentId),
|
|
271
|
+
retryNow: environmentRegistry.retryNow(target.environmentId)
|
|
272
|
+
}).pipe(forkChild);
|
|
273
|
+
const resumed = yield* environmentRegistry.followStream(target.environmentId, subscribe(WS_METHODS.subscribeServerLifecycle, {})).pipe(filter((event) => event.type === "ready" && matchesServerUpdateReadyEvent(result, event)), runHead, timeoutOption(SERVER_UPDATE_RESUME_TIMEOUT), map$1(flatten));
|
|
274
|
+
if (isNone(resumed)) return yield* new ServerUpdateResumeTimeoutError({
|
|
275
|
+
environmentId: target.environmentId,
|
|
276
|
+
targetVersion
|
|
277
|
+
});
|
|
278
|
+
yield* validateServerUpdateReadyEvent(result, resumed.value);
|
|
279
|
+
atomRegistry.set(stateAtom, IDLE_SERVER_UPDATE_STATE);
|
|
280
|
+
return result;
|
|
281
|
+
}).pipe(onExit((exit) => sync(() => {
|
|
282
|
+
if (isSuccess(exit)) return;
|
|
283
|
+
if (hasInterruptsOnly(exit.cause)) {
|
|
284
|
+
atomRegistry.set(stateAtom, IDLE_SERVER_UPDATE_STATE);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
atomRegistry.set(stateAtom, {
|
|
288
|
+
status: "failed",
|
|
289
|
+
stage: currentStage,
|
|
290
|
+
fromVersion,
|
|
291
|
+
targetVersion,
|
|
292
|
+
message: serverUpdateFailureMessage(squash(exit.cause))
|
|
293
|
+
});
|
|
294
|
+
})));
|
|
295
|
+
}
|
|
296
|
+
});
|
|
122
297
|
return {
|
|
123
298
|
configValueAtom,
|
|
124
|
-
|
|
125
|
-
|
|
299
|
+
updateStateAtom,
|
|
300
|
+
settingsValueAtom: family((environmentId) => make((get) => get(configValueAtom(environmentId))?.settings ?? null).pipe(withLabel(`environment-data:server:settings:${environmentId}`))),
|
|
301
|
+
providersValueAtom: family((environmentId) => make((get) => get(configValueAtom(environmentId))?.providers ?? null).pipe(withLabel(`environment-data:server:providers:${environmentId}`))),
|
|
126
302
|
traceDiagnostics: createEnvironmentRpcQueryAtomFamily(runtime, {
|
|
127
303
|
label: "environment-data:server:trace-diagnostics",
|
|
128
304
|
tag: WS_METHODS.serverGetTraceDiagnostics
|
|
@@ -145,6 +321,11 @@ function createServerEnvironmentAtoms(runtime, options) {
|
|
|
145
321
|
tag: WS_METHODS.serverGetResourceTelemetryHistory,
|
|
146
322
|
staleTimeMs: 5e3
|
|
147
323
|
}),
|
|
324
|
+
usageSummary: createEnvironmentRpcQueryAtomFamily(runtime, {
|
|
325
|
+
label: "environment-data:server:usage-summary",
|
|
326
|
+
tag: WS_METHODS.serverGetUsageSummary,
|
|
327
|
+
staleTimeMs: 6e4
|
|
328
|
+
}),
|
|
148
329
|
configProjection,
|
|
149
330
|
welcome: createEnvironmentRpcSubscriptionAtomFamily(runtime, {
|
|
150
331
|
label: "environment-data:server:welcome",
|
|
@@ -165,12 +346,7 @@ function createServerEnvironmentAtoms(runtime, options) {
|
|
|
165
346
|
scheduler: configScheduler,
|
|
166
347
|
concurrency: configConcurrency
|
|
167
348
|
}),
|
|
168
|
-
updateServer
|
|
169
|
-
label: "environment-data:server:update-server",
|
|
170
|
-
tag: WS_METHODS.serverUpdateServer,
|
|
171
|
-
scheduler: configScheduler,
|
|
172
|
-
concurrency: configConcurrency
|
|
173
|
-
}),
|
|
349
|
+
updateServer,
|
|
174
350
|
upsertKeybinding: createEnvironmentRpcCommand(runtime, {
|
|
175
351
|
label: "environment-data:server:upsert-keybinding",
|
|
176
352
|
tag: WS_METHODS.serverUpsertKeybinding,
|
|
@@ -204,4 +380,4 @@ function createServerEnvironmentAtoms(runtime, options) {
|
|
|
204
380
|
};
|
|
205
381
|
}
|
|
206
382
|
//#endregion
|
|
207
|
-
export { applyServerConfigProjection, createServerEnvironmentAtoms, makeEnvironmentServerConfigState, projectServerConfig, projectServerWelcome, resolveServerConfigValue, serverConfigStateChanges };
|
|
383
|
+
export { ServerUpdateProgressIncompleteError, ServerUpdateResumeTimeoutError, ServerUpdateTerminalError, applyServerConfigProjection, createServerEnvironmentAtoms, isLegacyUpdateHandoffLoss, makeEnvironmentServerConfigState, matchesServerUpdateReadyEvent, nudgeReconnectDuringUpdateRestart, projectServerConfig, projectServerWelcome, resolveServerConfigValue, resolveServerUpdateProgressResult, serverConfigStateChanges, serverUpdateStateForProgressEvent, serverUpdateStateForServerVersion, validateServerUpdateReadyEvent };
|
|
@@ -1,10 +1,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Id as KeybindingWhenNode, Oa as EnvironmentRegistry, Su as ServerConfig, ms as PreparedConnection, no as RemoteEnvironmentRequestError, wo as ManagedRelayDpopSigner } from "../../shared.js";
|
|
2
2
|
import * as Effect from "effect/Effect";
|
|
3
3
|
import * as Option from "effect/Option";
|
|
4
|
+
import { HttpClient } from "effect/unstable/http";
|
|
4
5
|
import { AsyncResult, Atom } from "effect/unstable/reactivity";
|
|
5
6
|
//#region upstream-t3code/packages/client-runtime/src/state/session.d.ts
|
|
6
7
|
declare function initialConfigOption<E>(initialConfig: Effect.Effect<ServerConfig, E>): Effect.Effect<Option.Option<ServerConfig>>;
|
|
7
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Read the granted scopes of this client's session on one environment via its
|
|
10
|
+
* `/api/auth/session` endpoint, authenticated with whatever credential the
|
|
11
|
+
* connection was prepared with (cookie, bearer, or DPoP).
|
|
12
|
+
*/
|
|
13
|
+
declare const fetchEnvironmentSessionState: (input: {
|
|
14
|
+
readonly prepared: PreparedConnection;
|
|
15
|
+
readonly signer: Option.Option<ManagedRelayDpopSigner["Service"]>;
|
|
16
|
+
readonly timeoutMs?: number;
|
|
17
|
+
}) => Effect.Effect<{
|
|
18
|
+
readonly authenticated: boolean;
|
|
19
|
+
readonly auth: {
|
|
20
|
+
readonly policy: "desktop-managed-local" | "loopback-browser" | "remote-reachable" | "unsafe-no-auth";
|
|
21
|
+
readonly bootstrapMethods: readonly ("desktop-bootstrap" | "one-time-token")[];
|
|
22
|
+
readonly sessionMethods: readonly ("bearer-access-token" | "browser-session-cookie" | "dpop-access-token")[];
|
|
23
|
+
readonly sessionCookieName: string;
|
|
24
|
+
};
|
|
25
|
+
readonly scopes?: readonly ("access:read" | "access:write" | "orchestration:operate" | "orchestration:read" | "relay:read" | "relay:write" | "review:write" | "terminal:operate")[];
|
|
26
|
+
readonly sessionMethod?: "bearer-access-token" | "browser-session-cookie" | "dpop-access-token";
|
|
27
|
+
readonly expiresAt?: import("effect/DateTime").Utc;
|
|
28
|
+
}, RemoteEnvironmentRequestError, HttpClient.HttpClient>;
|
|
29
|
+
declare function createEnvironmentSessionAtoms<R, E>(runtime: Atom.AtomRuntime<EnvironmentRegistry | HttpClient.HttpClient | R, E>): {
|
|
8
30
|
initialConfigAtom: (arg: string & import("effect/Brand").Brand<"EnvironmentId">) => Atom.Atom<AsyncResult.AsyncResult<Option.Option<{
|
|
9
31
|
readonly environment: {
|
|
10
32
|
readonly environmentId: string & import("effect/Brand").Brand<"EnvironmentId">;
|
|
@@ -17,9 +39,15 @@ declare function createEnvironmentSessionAtoms<R, E>(runtime: Atom.AtomRuntime<E
|
|
|
17
39
|
readonly capabilities: {
|
|
18
40
|
readonly repositoryIdentity: boolean;
|
|
19
41
|
readonly connectionProbe?: boolean;
|
|
42
|
+
readonly pullRequests?: boolean;
|
|
20
43
|
readonly threadSettlement?: boolean;
|
|
21
44
|
readonly threadSnooze?: boolean;
|
|
45
|
+
readonly threadPinning?: boolean;
|
|
46
|
+
readonly threadPinReorder?: boolean;
|
|
47
|
+
readonly threadTitleRegeneration?: boolean;
|
|
22
48
|
readonly serverSelfUpdate?: "boot-service" | "desktop-managed" | "respawn";
|
|
49
|
+
readonly serverSelfUpdateProgress?: boolean;
|
|
50
|
+
readonly agentActivityPublishing?: boolean;
|
|
23
51
|
};
|
|
24
52
|
};
|
|
25
53
|
readonly auth: {
|
|
@@ -31,7 +59,7 @@ declare function createEnvironmentSessionAtoms<R, E>(runtime: Atom.AtomRuntime<E
|
|
|
31
59
|
readonly cwd: string;
|
|
32
60
|
readonly keybindingsConfigPath: string;
|
|
33
61
|
readonly keybindings: readonly {
|
|
34
|
-
readonly command: "chat.new" | "chat.newLocal" | "commandPalette.toggle" | "composer.stash" | "diff.toggle" | "editor.openFavorite" | "modelPicker.jump.1" | "modelPicker.jump.2" | "modelPicker.jump.3" | "modelPicker.jump.4" | "modelPicker.jump.5" | "modelPicker.jump.6" | "modelPicker.jump.7" | "modelPicker.jump.8" | "modelPicker.jump.9" | "modelPicker.toggle" | "preview.focusUrl" | "preview.refresh" | "preview.resetZoom" | "preview.toggle" | "preview.zoomIn" | "preview.zoomOut" | "rightPanel.toggle" | "sidebar.toggle" | "terminal.close" | "terminal.new" | "terminal.split" | "terminal.splitVertical" | "terminal.toggle" | "thread.jump.1" | "thread.jump.2" | "thread.jump.3" | "thread.jump.4" | "thread.jump.5" | "thread.jump.6" | "thread.jump.7" | "thread.jump.8" | "thread.jump.9" | "thread.next" | "thread.previous" | `script.${string}.run`;
|
|
62
|
+
readonly command: "chat.new" | "chat.newLocal" | "commandPalette.toggle" | "composer.stash" | "diff.toggle" | "editor.openFavorite" | "filePicker.toggle" | "modelPicker.jump.1" | "modelPicker.jump.2" | "modelPicker.jump.3" | "modelPicker.jump.4" | "modelPicker.jump.5" | "modelPicker.jump.6" | "modelPicker.jump.7" | "modelPicker.jump.8" | "modelPicker.jump.9" | "modelPicker.toggle" | "preview.focusUrl" | "preview.refresh" | "preview.resetZoom" | "preview.toggle" | "preview.zoomIn" | "preview.zoomOut" | "projectSearch.toggle" | "rightPanel.toggle" | "sidebar.toggle" | "terminal.close" | "terminal.new" | "terminal.split" | "terminal.splitVertical" | "terminal.toggle" | "themeEditor.toggle" | "thread.jump.1" | "thread.jump.2" | "thread.jump.3" | "thread.jump.4" | "thread.jump.5" | "thread.jump.6" | "thread.jump.7" | "thread.jump.8" | "thread.jump.9" | "thread.next" | "thread.previous" | `script.${string}.run`;
|
|
35
63
|
readonly shortcut: {
|
|
36
64
|
readonly key: string;
|
|
37
65
|
readonly metaKey: boolean;
|
|
@@ -96,6 +124,7 @@ declare function createEnvironmentSessionAtoms<R, E>(runtime: Atom.AtomRuntime<E
|
|
|
96
124
|
readonly subProvider?: string | undefined;
|
|
97
125
|
readonly isCustom: boolean;
|
|
98
126
|
readonly isDefault?: boolean | undefined;
|
|
127
|
+
readonly isLegacy?: boolean | undefined;
|
|
99
128
|
readonly capabilities: {
|
|
100
129
|
readonly optionDescriptors?: readonly ({
|
|
101
130
|
readonly id: string;
|
|
@@ -153,6 +182,10 @@ declare function createEnvironmentSessionAtoms<R, E>(runtime: Atom.AtomRuntime<E
|
|
|
153
182
|
};
|
|
154
183
|
}[];
|
|
155
184
|
readonly availableEditors: readonly ("antigravity" | "aqua" | "clion" | "cursor" | "datagrip" | "dataspell" | "file-manager" | "goland" | "idea" | "kiro" | "phpstorm" | "pycharm" | "rider" | "rubymine" | "rustrover" | "trae" | "vscode" | "vscode-insiders" | "vscodium" | "webstorm" | "zed")[];
|
|
185
|
+
readonly remoteOpenTargets?: readonly {
|
|
186
|
+
readonly kind: "mdns" | "tailscale";
|
|
187
|
+
readonly host: string;
|
|
188
|
+
}[];
|
|
156
189
|
readonly observability: {
|
|
157
190
|
readonly logsDirectoryPath: string;
|
|
158
191
|
readonly localTracingEnabled: boolean;
|
|
@@ -162,7 +195,7 @@ declare function createEnvironmentSessionAtoms<R, E>(runtime: Atom.AtomRuntime<E
|
|
|
162
195
|
readonly otlpMetricsEnabled: boolean;
|
|
163
196
|
};
|
|
164
197
|
readonly settings: {
|
|
165
|
-
readonly
|
|
198
|
+
readonly enableLegacyTokenStreaming: boolean;
|
|
166
199
|
readonly enableProviderUpdateChecks: boolean;
|
|
167
200
|
readonly backgroundActivity: {
|
|
168
201
|
readonly schemaVersion: 1;
|
|
@@ -264,6 +297,7 @@ declare function createEnvironmentSessionAtoms<R, E>(runtime: Atom.AtomRuntime<E
|
|
|
264
297
|
};
|
|
265
298
|
readonly shellResumeCompletionMarker?: boolean;
|
|
266
299
|
readonly threadResumeCompletionMarker?: boolean;
|
|
300
|
+
readonly threadSnapshotPagination?: boolean;
|
|
267
301
|
}>, E | import("effect/Cause").NoSuchElementError>>;
|
|
268
302
|
initialConfigValueAtom: (arg: string & import("effect/Brand").Brand<"EnvironmentId">) => Atom.Atom<{
|
|
269
303
|
readonly environment: {
|
|
@@ -277,9 +311,15 @@ declare function createEnvironmentSessionAtoms<R, E>(runtime: Atom.AtomRuntime<E
|
|
|
277
311
|
readonly capabilities: {
|
|
278
312
|
readonly repositoryIdentity: boolean;
|
|
279
313
|
readonly connectionProbe?: boolean;
|
|
314
|
+
readonly pullRequests?: boolean;
|
|
280
315
|
readonly threadSettlement?: boolean;
|
|
281
316
|
readonly threadSnooze?: boolean;
|
|
317
|
+
readonly threadPinning?: boolean;
|
|
318
|
+
readonly threadPinReorder?: boolean;
|
|
319
|
+
readonly threadTitleRegeneration?: boolean;
|
|
282
320
|
readonly serverSelfUpdate?: "boot-service" | "desktop-managed" | "respawn";
|
|
321
|
+
readonly serverSelfUpdateProgress?: boolean;
|
|
322
|
+
readonly agentActivityPublishing?: boolean;
|
|
283
323
|
};
|
|
284
324
|
};
|
|
285
325
|
readonly auth: {
|
|
@@ -291,7 +331,7 @@ declare function createEnvironmentSessionAtoms<R, E>(runtime: Atom.AtomRuntime<E
|
|
|
291
331
|
readonly cwd: string;
|
|
292
332
|
readonly keybindingsConfigPath: string;
|
|
293
333
|
readonly keybindings: readonly {
|
|
294
|
-
readonly command: "chat.new" | "chat.newLocal" | "commandPalette.toggle" | "composer.stash" | "diff.toggle" | "editor.openFavorite" | "modelPicker.jump.1" | "modelPicker.jump.2" | "modelPicker.jump.3" | "modelPicker.jump.4" | "modelPicker.jump.5" | "modelPicker.jump.6" | "modelPicker.jump.7" | "modelPicker.jump.8" | "modelPicker.jump.9" | "modelPicker.toggle" | "preview.focusUrl" | "preview.refresh" | "preview.resetZoom" | "preview.toggle" | "preview.zoomIn" | "preview.zoomOut" | "rightPanel.toggle" | "sidebar.toggle" | "terminal.close" | "terminal.new" | "terminal.split" | "terminal.splitVertical" | "terminal.toggle" | "thread.jump.1" | "thread.jump.2" | "thread.jump.3" | "thread.jump.4" | "thread.jump.5" | "thread.jump.6" | "thread.jump.7" | "thread.jump.8" | "thread.jump.9" | "thread.next" | "thread.previous" | `script.${string}.run`;
|
|
334
|
+
readonly command: "chat.new" | "chat.newLocal" | "commandPalette.toggle" | "composer.stash" | "diff.toggle" | "editor.openFavorite" | "filePicker.toggle" | "modelPicker.jump.1" | "modelPicker.jump.2" | "modelPicker.jump.3" | "modelPicker.jump.4" | "modelPicker.jump.5" | "modelPicker.jump.6" | "modelPicker.jump.7" | "modelPicker.jump.8" | "modelPicker.jump.9" | "modelPicker.toggle" | "preview.focusUrl" | "preview.refresh" | "preview.resetZoom" | "preview.toggle" | "preview.zoomIn" | "preview.zoomOut" | "projectSearch.toggle" | "rightPanel.toggle" | "sidebar.toggle" | "terminal.close" | "terminal.new" | "terminal.split" | "terminal.splitVertical" | "terminal.toggle" | "themeEditor.toggle" | "thread.jump.1" | "thread.jump.2" | "thread.jump.3" | "thread.jump.4" | "thread.jump.5" | "thread.jump.6" | "thread.jump.7" | "thread.jump.8" | "thread.jump.9" | "thread.next" | "thread.previous" | `script.${string}.run`;
|
|
295
335
|
readonly shortcut: {
|
|
296
336
|
readonly key: string;
|
|
297
337
|
readonly metaKey: boolean;
|
|
@@ -356,6 +396,7 @@ declare function createEnvironmentSessionAtoms<R, E>(runtime: Atom.AtomRuntime<E
|
|
|
356
396
|
readonly subProvider?: string | undefined;
|
|
357
397
|
readonly isCustom: boolean;
|
|
358
398
|
readonly isDefault?: boolean | undefined;
|
|
399
|
+
readonly isLegacy?: boolean | undefined;
|
|
359
400
|
readonly capabilities: {
|
|
360
401
|
readonly optionDescriptors?: readonly ({
|
|
361
402
|
readonly id: string;
|
|
@@ -413,6 +454,10 @@ declare function createEnvironmentSessionAtoms<R, E>(runtime: Atom.AtomRuntime<E
|
|
|
413
454
|
};
|
|
414
455
|
}[];
|
|
415
456
|
readonly availableEditors: readonly ("antigravity" | "aqua" | "clion" | "cursor" | "datagrip" | "dataspell" | "file-manager" | "goland" | "idea" | "kiro" | "phpstorm" | "pycharm" | "rider" | "rubymine" | "rustrover" | "trae" | "vscode" | "vscode-insiders" | "vscodium" | "webstorm" | "zed")[];
|
|
457
|
+
readonly remoteOpenTargets?: readonly {
|
|
458
|
+
readonly kind: "mdns" | "tailscale";
|
|
459
|
+
readonly host: string;
|
|
460
|
+
}[];
|
|
416
461
|
readonly observability: {
|
|
417
462
|
readonly logsDirectoryPath: string;
|
|
418
463
|
readonly localTracingEnabled: boolean;
|
|
@@ -422,7 +467,7 @@ declare function createEnvironmentSessionAtoms<R, E>(runtime: Atom.AtomRuntime<E
|
|
|
422
467
|
readonly otlpMetricsEnabled: boolean;
|
|
423
468
|
};
|
|
424
469
|
readonly settings: {
|
|
425
|
-
readonly
|
|
470
|
+
readonly enableLegacyTokenStreaming: boolean;
|
|
426
471
|
readonly enableProviderUpdateChecks: boolean;
|
|
427
472
|
readonly backgroundActivity: {
|
|
428
473
|
readonly schemaVersion: 1;
|
|
@@ -524,9 +569,34 @@ declare function createEnvironmentSessionAtoms<R, E>(runtime: Atom.AtomRuntime<E
|
|
|
524
569
|
};
|
|
525
570
|
readonly shellResumeCompletionMarker?: boolean;
|
|
526
571
|
readonly threadResumeCompletionMarker?: boolean;
|
|
572
|
+
readonly threadSnapshotPagination?: boolean;
|
|
527
573
|
} | null>;
|
|
528
574
|
preparedConnectionAtom: (arg: string & import("effect/Brand").Brand<"EnvironmentId">) => Atom.Atom<AsyncResult.AsyncResult<Option.Option<PreparedConnection>, E | import("effect/Cause").NoSuchElementError>>;
|
|
529
575
|
preparedConnectionValueAtom: (arg: string & import("effect/Brand").Brand<"EnvironmentId">) => Atom.Atom<Option.Option<PreparedConnection>>;
|
|
576
|
+
sessionStateAtom: (arg: string & import("effect/Brand").Brand<"EnvironmentId">) => Atom.Atom<AsyncResult.AsyncResult<{
|
|
577
|
+
readonly authenticated: boolean;
|
|
578
|
+
readonly auth: {
|
|
579
|
+
readonly policy: "desktop-managed-local" | "loopback-browser" | "remote-reachable" | "unsafe-no-auth";
|
|
580
|
+
readonly bootstrapMethods: readonly ("desktop-bootstrap" | "one-time-token")[];
|
|
581
|
+
readonly sessionMethods: readonly ("bearer-access-token" | "browser-session-cookie" | "dpop-access-token")[];
|
|
582
|
+
readonly sessionCookieName: string;
|
|
583
|
+
};
|
|
584
|
+
readonly scopes?: readonly ("access:read" | "access:write" | "orchestration:operate" | "orchestration:read" | "relay:read" | "relay:write" | "review:write" | "terminal:operate")[];
|
|
585
|
+
readonly sessionMethod?: "bearer-access-token" | "browser-session-cookie" | "dpop-access-token";
|
|
586
|
+
readonly expiresAt?: import("effect/DateTime").Utc;
|
|
587
|
+
}, E | RemoteEnvironmentRequestError>>;
|
|
588
|
+
sessionStateValueAtom: (arg: string & import("effect/Brand").Brand<"EnvironmentId">) => Atom.Atom<{
|
|
589
|
+
readonly authenticated: boolean;
|
|
590
|
+
readonly auth: {
|
|
591
|
+
readonly policy: "desktop-managed-local" | "loopback-browser" | "remote-reachable" | "unsafe-no-auth";
|
|
592
|
+
readonly bootstrapMethods: readonly ("desktop-bootstrap" | "one-time-token")[];
|
|
593
|
+
readonly sessionMethods: readonly ("bearer-access-token" | "browser-session-cookie" | "dpop-access-token")[];
|
|
594
|
+
readonly sessionCookieName: string;
|
|
595
|
+
};
|
|
596
|
+
readonly scopes?: readonly ("access:read" | "access:write" | "orchestration:operate" | "orchestration:read" | "relay:read" | "relay:write" | "review:write" | "terminal:operate")[];
|
|
597
|
+
readonly sessionMethod?: "bearer-access-token" | "browser-session-cookie" | "dpop-access-token";
|
|
598
|
+
readonly expiresAt?: import("effect/DateTime").Utc;
|
|
599
|
+
} | null>;
|
|
530
600
|
};
|
|
531
601
|
//#endregion
|
|
532
|
-
export { createEnvironmentSessionAtoms, initialConfigOption };
|
|
602
|
+
export { createEnvironmentSessionAtoms, fetchEnvironmentSessionState, initialConfigOption };
|
|
@@ -1,8 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { By as changes, Dr as followStreamInEnvironment, GA as mapEffect, GN as none, Ha as safeErrorLogAttributes, Ho as makeEnvironmentHttpApiClient, Hr as buildEnvironmentAuthHeaders, Jr as swr, KN as some, Kj as fn, Ko as environmentEndpointUrl, Kr as make, LN as getOrElse, Mj as as, Qj as gen, RN as getOrNull, Ra as EnvironmentSupervisor, Ur as withEnvironmentCredentials, Vo as executeEnvironmentHttpRequest, WN as match, Wr as family, Yr as withLabel, ei as value, jj as annotateLogs, nM as logWarning, qr as setIdleTTL, rM as map, ro as ManagedRelayDpopSigner, sM as never, sj as unwrap, xM as succeed, yM as serviceOption, zj as catch_ } from "../../shared.js";
|
|
2
2
|
//#region upstream-t3code/packages/client-runtime/src/state/session.ts
|
|
3
3
|
function initialConfigOption(initialConfig) {
|
|
4
4
|
return initialConfig.pipe(map(some), catch_((error) => logWarning("Could not load the initial environment configuration.").pipe(annotateLogs({ ...safeErrorLogAttributes(error) }), as(none()))));
|
|
5
5
|
}
|
|
6
|
+
const DEFAULT_SESSION_STATE_TIMEOUT_MS = 6e3;
|
|
7
|
+
/**
|
|
8
|
+
* Read the granted scopes of this client's session on one environment via its
|
|
9
|
+
* `/api/auth/session` endpoint, authenticated with whatever credential the
|
|
10
|
+
* connection was prepared with (cookie, bearer, or DPoP).
|
|
11
|
+
*/
|
|
12
|
+
const fetchEnvironmentSessionState = fn("clientRuntime.state.fetchEnvironmentSessionState")(function* (input) {
|
|
13
|
+
const requestUrl = environmentEndpointUrl(input.prepared.httpBaseUrl, "/api/auth/session");
|
|
14
|
+
const client = yield* makeEnvironmentHttpApiClient(input.prepared.httpBaseUrl);
|
|
15
|
+
const headers = yield* buildEnvironmentAuthHeaders(input.prepared.httpAuthorization, "GET", requestUrl, input.signer);
|
|
16
|
+
return yield* executeEnvironmentHttpRequest(requestUrl, input.timeoutMs ?? DEFAULT_SESSION_STATE_TIMEOUT_MS, withEnvironmentCredentials(input.prepared.httpAuthorization, client.auth.session({ headers })));
|
|
17
|
+
});
|
|
6
18
|
function createEnvironmentSessionAtoms(runtime) {
|
|
7
19
|
const initialConfigAtom = family((environmentId) => runtime.atom(followStreamInEnvironment(environmentId, unwrap(EnvironmentSupervisor.pipe(map((supervisor) => changes(supervisor.session).pipe(mapEffect(match({
|
|
8
20
|
onNone: () => succeed(none()),
|
|
@@ -10,12 +22,29 @@ function createEnvironmentSessionAtoms(runtime) {
|
|
|
10
22
|
}))))))), { initialValue: none() }));
|
|
11
23
|
const initialConfigValueAtom = family((environmentId) => make((get) => getOrNull(getOrElse(value(get(initialConfigAtom(environmentId))), () => none()))).pipe(withLabel(`environment-config-value:${environmentId}`)));
|
|
12
24
|
const preparedConnectionAtom = family((environmentId) => runtime.atom(followStreamInEnvironment(environmentId, unwrap(EnvironmentSupervisor.pipe(map((supervisor) => changes(supervisor.prepared))))), { initialValue: none() }));
|
|
25
|
+
const preparedConnectionValueAtom = family((environmentId) => make((get) => getOrElse(value(get(preparedConnectionAtom(environmentId))), () => none())).pipe(withLabel(`environment-prepared-connection:${environmentId}`)));
|
|
26
|
+
const sessionStateAtom = family((environmentId) => runtime.atom((get) => {
|
|
27
|
+
const prepared = getOrNull(get(preparedConnectionValueAtom(environmentId)));
|
|
28
|
+
if (prepared === null) return never;
|
|
29
|
+
return gen(function* () {
|
|
30
|
+
const signer = yield* serviceOption(ManagedRelayDpopSigner);
|
|
31
|
+
return yield* fetchEnvironmentSessionState({
|
|
32
|
+
prepared,
|
|
33
|
+
signer
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}).pipe(swr({
|
|
37
|
+
staleTime: 3e4,
|
|
38
|
+
revalidateOnMount: true
|
|
39
|
+
}), setIdleTTL(5 * 6e4), withLabel(`environment-session-state:${environmentId}`)));
|
|
13
40
|
return {
|
|
14
41
|
initialConfigAtom,
|
|
15
42
|
initialConfigValueAtom,
|
|
16
43
|
preparedConnectionAtom,
|
|
17
|
-
preparedConnectionValueAtom
|
|
44
|
+
preparedConnectionValueAtom,
|
|
45
|
+
sessionStateAtom,
|
|
46
|
+
sessionStateValueAtom: family((environmentId) => make((get) => getOrNull(value(get(sessionStateAtom(environmentId)))) ?? null).pipe(withLabel(`environment-session-state-value:${environmentId}`)))
|
|
18
47
|
};
|
|
19
48
|
}
|
|
20
49
|
//#endregion
|
|
21
|
-
export { createEnvironmentSessionAtoms, initialConfigOption };
|
|
50
|
+
export { createEnvironmentSessionAtoms, fetchEnvironmentSessionState, initialConfigOption };
|