Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

Merge remote-tracking branch 'origin/dev' into feat/live-entity-change-stream

Josué39d2fe17195a
diff --cc control-api/package-lock.json
index b8901b3f7,9c880649c..641cde629
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@@ -1,12 -1,12 +1,12 @@@
{
"name": "clerum-control-api",
- "version": "0.1.690",
- "version": "0.1.681",
++ "version": "0.1.691",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.690",
- "version": "0.1.681",
++ "version": "0.1.691",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",
diff --cc control-api/package.json
index 52f72d6a5,2e64e8220..392a3831e
--- a/control-api/package.json
+++ b/control-api/package.json
@@@ -1,6 -1,6 +1,6 @@@
{
"name": "clerum-control-api",
- "version": "0.1.690",
- "version": "0.1.681",
++ "version": "0.1.691",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --cc control-ui/package-lock.json
index 6782cebb0,6cf07b947..b5634104e
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@@ -1,12 -1,12 +1,12 @@@
{
"name": "clerum-control-ui",
- "version": "0.1.688",
- "version": "0.1.663",
++ "version": "0.1.689",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.688",
- "version": "0.1.663",
++ "version": "0.1.689",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/frontend-components": "file:../packages/frontend-components",
diff --cc control-ui/package.json
index b69adedab,42dfc7727..aca63cc6c
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@@ -1,6 -1,6 +1,6 @@@
{
"name": "clerum-control-ui",
- "version": "0.1.688",
- "version": "0.1.663",
++ "version": "0.1.689",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",
diff --cc desktop-app/src/appService.ts
index 455a9bbb6,850b24632..e6c0c0d1c
--- a/desktop-app/src/appService.ts
+++ b/desktop-app/src/appService.ts
@@@ -1183,8 -1182,8 +1216,9 @@@ export class AppService
let activeToken = originalToken
const shouldSwitch = originalTeamId !== targetTeamId
const shouldRestore = Boolean(originalTeamId && shouldSwitch)
+ let restoredOriginalTeam = false
const releaseTransientHop = shouldSwitch ? this.enterGfsTransientTeamHop() : undefined
+ if (shouldRestore) this.chatStoreHomeTeamId = originalTeamId
try {
if (shouldSwitch) {
@@@ -1209,12 -1207,27 +1243,31 @@@
)
}
}
+ if (restoredOriginalTeam && this.sessionToken) {
+ this.updateEntityChangeSessionToken(this.sessionToken)
+ this.restartEntityChangeStreamForSessionReplacement()
+ }
}
} finally {
+ if (shouldRestore) {
+ this.chatStoreHomeTeamId = null
+ // A failed switch back leaves the session on the hop team while the
+ // store is still bound to the pinned home team. Rebind so the store
+ // scope and the delete-fence authority (both derived from
+ // chatStoreTeamId) agree again. A rebind failure is logged and never
+ // replaces the error of the operation or of the failed restore.
+ const sessionUserId = this.me?.id
+ if (sessionUserId && this.me?.teamId !== originalTeamId) {
+ try {
+ await this.bindCurrentChatStore(sessionUserId)
+ } catch (rebindError) {
+ console.error(
+ '[AppService] Failed to rebind the chat store after a failed team restore:',
+ rebindError
+ )
+ }
+ }
+ }
releaseTransientHop?.()
}
} finally {
@@@ -1503,46 -1537,49 +1580,51 @@@
token: string
me: SessionMe
}): Promise<SessionState> {
- const previousToken = this.sessionToken
- const previousMe = this.me
- const previousGeneration = this.sessionGeneration
- const hadAuthenticatedScope = Boolean(previousToken && previousMe)
- if (hadAuthenticatedScope) {
- try {
- await this.suspendDesktopGfsUploadsForAuthBoundary()
- } catch (error) {
+ const releasePrewarm = this.beginPrewarmAuthTransition()
+ try {
+ const previousToken = this.sessionToken
+ const previousMe = this.me
+ const previousGeneration = this.sessionGeneration
+ const hadAuthenticatedScope = Boolean(previousToken && previousMe)
+ if (hadAuthenticatedScope) {
+ try {
+ await this.suspendDesktopGfsUploadsForAuthBoundary()
+ } catch (error) {
+ if (
+ this.sessionGeneration === previousGeneration &&
+ this.sessionToken === previousToken &&
+ this.me === previousMe
+ ) {
+ this.activateGfsAuthScope()
+ }
+ throw error
+ }
if (
- this.sessionGeneration === previousGeneration &&
- this.sessionToken === previousToken &&
- this.me === previousMe
+ this.sessionGeneration !== previousGeneration ||
+ this.sessionToken !== previousToken ||
+ this.me !== previousMe
) {
- this.activateGfsAuthScope()
+ throw new Error('stale_auth_epoch: authenticated scope changed during login replacement')
}
- throw error
- }
- if (
- this.sessionGeneration !== previousGeneration ||
- this.sessionToken !== previousToken ||
- this.me !== previousMe
- ) {
- throw new Error('stale_auth_epoch: authenticated scope changed during login replacement')
}
+ this.logoutInProgress = false
+ this.sessionGeneration += 1
+ this.sessionToken = result.token
+ this.me = result.me
++ this.updateEntityChangeSessionToken(result.token)
++ this.restartEntityChangeStreamForSessionReplacement()
+ await this.bindCurrentChatStore(result.me.id)
+ this.accessCatalog = null
+ this.teamDirectoryCache = null
+ this.workflowApprovalTeamById.clear()
+ this.workflowTeamByKey.clear()
+ this.rpcTokenManager.clear()
+ await this.tokenStore.setSessionToken(result.token, getActiveEnvKey())
+ this.activateGfsAuthScope()
+ return { authenticated: true, me: result.me }
+ } finally {
+ releasePrewarm()
}
- this.logoutInProgress = false
- this.sessionGeneration += 1
- this.sessionToken = result.token
- this.me = result.me
- this.updateEntityChangeSessionToken(result.token)
- this.restartEntityChangeStreamForSessionReplacement()
- await this.bindCurrentChatStore(result.me.id)
- this.accessCatalog = null
- this.teamDirectoryCache = null
- this.workflowApprovalTeamById.clear()
- this.workflowTeamByKey.clear()
- this.rpcTokenManager.clear()
- await this.tokenStore.setSessionToken(result.token, getActiveEnvKey())
- this.activateGfsAuthScope()
- return { authenticated: true, me: result.me }
}
private async completePasswordLogin(email: string, password: string): Promise<SessionState> {
diff --cc desktop-app/src/authClient.ts
index 44e078c66,ec20e13ed..3bab266ff
--- a/desktop-app/src/authClient.ts
+++ b/desktop-app/src/authClient.ts
@@@ -561,81 -508,6 +562,81 @@@ export class AuthClient
if (trailing) processChunk(trailing)
}
+ async openEntityChangeStream(
+ sessionToken: string,
+ cursor: string | null,
+ onEvent: (event: EntityChangeStreamEvent) => void,
+ signal: AbortSignal
+ ): Promise<void> {
+ const streamUrl = new URL(url('/api/v1/entity-changes/stream'))
+ if (cursor) streamUrl.searchParams.set('cursor', cursor)
+ const response = await fetch(streamUrl, {
+ method: 'GET',
+ headers: {
+ accept: 'application/x-ndjson',
+ authorization: `Bearer ${sessionToken}`,
+ },
+ signal,
+ })
+ if (!response.ok) {
+ const body = await readErrorBody(response)
+ throw new ApiError(
- `Entity change stream failed (${response.status}): ${body || response.statusText}`,
++ `Entity change stream failed (${response.status}): ${boundedErrorExcerpt(body) || response.statusText}`,
+ response.status,
+ body,
+ response.headers.get('retry-after')
+ )
+ }
+ if (!response.body) throw new Error('Entity change stream missing response body')
+
+ onEvent({ type: 'open' })
+ const reader = response.body.getReader()
+ const decoder = new TextDecoder()
+ let buffer = ''
+ const processFrame = (rawLine: string) => {
+ if (!rawLine.trim()) return
+ let decoded: unknown
+ try {
+ decoded = JSON.parse(rawLine) as unknown
+ } catch {
+ throw new Error('Entity change stream contained invalid JSON')
+ }
+ const frame = parseEntityChangeStreamFrame(decoded)
+ if (!frame) return
+ onEvent(frame)
+ }
+ const processChunk = (chunk: string) => {
+ buffer += chunk
+ if (buffer.length > 16 * 1024 && !buffer.includes('\n')) {
+ throw new Error('Entity change stream frame exceeded the size limit')
+ }
+ while (true) {
+ const newline = buffer.indexOf('\n')
+ if (newline === -1) break
+ const line = buffer.slice(0, newline)
+ buffer = buffer.slice(newline + 1)
+ if (line.length > 16 * 1024)
+ throw new Error('Entity change stream frame exceeded the size limit')
+ processFrame(line)
+ }
+ }
+
+ try {
+ while (true) {
+ const { done, value } = await reader.read()
+ if (done) break
+ processChunk(decoder.decode(value, { stream: true }))
+ }
+ processChunk(decoder.decode())
+ if (buffer.trim()) processFrame(buffer)
+ } catch (error) {
+ await reader.cancel().catch(() => undefined)
+ throw error
+ } finally {
+ reader.releaseLock()
+ }
+ }
+
async listWorkflows(sessionToken: string): Promise<WorkflowRecipeListResult> {
return requestJson<WorkflowRecipeListResult>('GET', url('/api/v1/workflows'), {
token: sessionToken,
diff --cc desktop-app/src/ipc.ts
index 57a72c40f,436abdaa3..9d935c6bf
--- a/desktop-app/src/ipc.ts
+++ b/desktop-app/src/ipc.ts
@@@ -23,8 -27,9 +27,10 @@@ import
PLUGIN_SDK_REQUEST_CHANNEL,
} from './pluginSdkProtocol.js'
import {
+ type ChatAuthorityScope,
+ type ChatDeleteFence,
DesktopRuntimeConfig,
+ EntityChangeStreamEvent,
HostActivityStreamEvent,
HostMessageRequest,
HostStatusStreamEvent,
diff --cc external-rest-api/src/releaseManifest.ts
index eb08f45a2,f159b47b7..c28c48b3b
--- a/external-rest-api/src/releaseManifest.ts
+++ b/external-rest-api/src/releaseManifest.ts
@@@ -8,8 -8,8 +8,8 @@@ export type ReleaseManifest =
export const releaseManifest: ReleaseManifest = {
releaseId: 'v0.10.0',
- externalRestApiVersion: '0.1.85',
+ externalRestApiVersion: '0.1.91',
- rpcProxyVersion: '0.1.94',
+ rpcProxyVersion: '0.1.111',
desktopVersion: '0.10.0',
minimumDesktopVersion: '0.1.252',
}