@meistrari/agent-core 0.1.11 → 0.1.13
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meistrari/agent-core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.13",
|
|
5
5
|
"packageManager": "bun@1.3.12",
|
|
6
6
|
"description": "Shared contracts and runtime modules for Tela coding-agent sandboxes: agent protocol, supervisor wire protocol, resident supervisor, worker runtime client, and Claude/Codex harness adapters.",
|
|
7
7
|
"license": "UNLICENSED",
|
|
@@ -19,6 +19,7 @@ export class ModelRebindingRun implements AgentRun {
|
|
|
19
19
|
private workspacePrepared = false
|
|
20
20
|
private workspaceChanging = false
|
|
21
21
|
private readonly lifetime = new AbortController()
|
|
22
|
+
private readonly controls = new Set<Promise<unknown>>()
|
|
22
23
|
|
|
23
24
|
constructor(run: AgentRun, private readonly reopen: (model: string, signal: AbortSignal) => Promise<AgentRun>, private readonly rootAdded?: (root: string) => void) {
|
|
24
25
|
this.run = run
|
|
@@ -41,11 +42,11 @@ export class ModelRebindingRun implements AgentRun {
|
|
|
41
42
|
})
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
respondUserInput: AgentRun['respondUserInput'] = async (command, options) => await this.run.respondUserInput(command, options)
|
|
45
|
-
interrupt: AgentRun['interrupt'] = async (command, options) => await this.run.interrupt(command, options)
|
|
45
|
+
respondUserInput: AgentRun['respondUserInput'] = async (command, options) => await this.withControl(signal => this.run.respondUserInput(command, { ...options, signal }), options)
|
|
46
|
+
interrupt: AgentRun['interrupt'] = async (command, options) => await this.withControl(signal => this.run.interrupt(command, { ...options, signal }), options)
|
|
46
47
|
|
|
47
48
|
async sendPrompt(command: SendPromptCommand, options: AgentOperationOptions = {}): Promise<AgentPromptAcceptance> {
|
|
48
|
-
if (this.dispatching || this.workspaceChanging)
|
|
49
|
+
if (this.dispatching || this.workspaceChanging || this.controls.size)
|
|
49
50
|
throw new AgentPromptDeferredError({ message: 'A prompt admission is already in progress.' })
|
|
50
51
|
const task = this.dispatchPrompt(command, options)
|
|
51
52
|
this.dispatching = task
|
|
@@ -112,6 +113,7 @@ export class ModelRebindingRun implements AgentRun {
|
|
|
112
113
|
throw new AgentRunStateError({ message: 'Stop does not target the bound run.' })
|
|
113
114
|
this.stopped = true
|
|
114
115
|
this.lifetime.abort()
|
|
116
|
+
await Promise.allSettled([...this.controls])
|
|
115
117
|
await this.run.stop(command, options)
|
|
116
118
|
await this.dispatching?.catch(() => undefined)
|
|
117
119
|
await this.pump
|
|
@@ -122,6 +124,23 @@ export class ModelRebindingRun implements AgentRun {
|
|
|
122
124
|
return { provider: this.metadata.provider, sessionId: this.metadata.sessionId, providerSessionId: this.metadata.providerSessionId }
|
|
123
125
|
}
|
|
124
126
|
|
|
127
|
+
private async withControl<T>(operation: (signal: AbortSignal) => Promise<T>, options: AgentOperationOptions = {}): Promise<T> {
|
|
128
|
+
if (this.stopped)
|
|
129
|
+
throw new AgentRunStateError({ message: 'The run stopped.' })
|
|
130
|
+
if (this.changing || this.needsRebind)
|
|
131
|
+
throw new AgentPromptDeferredError({ message: 'The provider model is being rebound.' })
|
|
132
|
+
const signal = AbortSignal.any([this.lifetime.signal, ...(options.signal ? [options.signal] : [])])
|
|
133
|
+
const task = Promise.resolve().then(async () => {
|
|
134
|
+
signal.throwIfAborted()
|
|
135
|
+
return await operation(signal)
|
|
136
|
+
})
|
|
137
|
+
this.controls.add(task)
|
|
138
|
+
try {
|
|
139
|
+
return await task
|
|
140
|
+
}
|
|
141
|
+
finally { this.controls.delete(task) }
|
|
142
|
+
}
|
|
143
|
+
|
|
125
144
|
private async withWorkspaceChange(operation: () => Promise<void>): Promise<void> {
|
|
126
145
|
if (this.stopped)
|
|
127
146
|
throw new AgentRunStateError({ message: 'The run stopped.' })
|
package/src/provenance.gen.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Generated by scripts/write-provenance.ts. Do not edit by hand.
|
|
2
2
|
export const generatedProvenance = {
|
|
3
|
-
version: "0.1.
|
|
4
|
-
sha: "
|
|
5
|
-
buildTime: "2026-09-
|
|
3
|
+
version: "0.1.13",
|
|
4
|
+
sha: "4f60fec6595bb447bfb1d307118a4a60264045a6",
|
|
5
|
+
buildTime: "2026-09-14T20:08:24.556Z",
|
|
6
6
|
} as const
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer'
|
|
2
|
+
|
|
3
|
+
/** Connection-local best effort only; never persisted or acknowledged as durable. */
|
|
4
|
+
export class EphemeralFrameBuffer {
|
|
5
|
+
private readonly frames: { value: string, bytes: number, barrier: number, expires: number }[] = []
|
|
6
|
+
private bytes = 0
|
|
7
|
+
|
|
8
|
+
constructor(private readonly options = { maxFrames: 2048, maxBytes: 1024 * 1024, ttlMs: 10_000, now: Date.now }) {}
|
|
9
|
+
|
|
10
|
+
enqueue(value: string, barrier: number): void {
|
|
11
|
+
this.expire()
|
|
12
|
+
const bytes = Buffer.byteLength(value)
|
|
13
|
+
if (this.frames.length >= this.options.maxFrames || this.bytes + bytes > this.options.maxBytes)
|
|
14
|
+
return
|
|
15
|
+
this.frames.push({ value, bytes, barrier, expires: this.options.now() + this.options.ttlMs })
|
|
16
|
+
this.bytes += bytes
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
flush(ackFloor: number, send: (value: string) => number): void {
|
|
20
|
+
this.expire()
|
|
21
|
+
while (this.frames.length > 0) {
|
|
22
|
+
const frame = this.frames[0]!
|
|
23
|
+
if (frame.barrier > ackFloor || send(frame.value) < 0)
|
|
24
|
+
return
|
|
25
|
+
this.bytes -= frame.bytes
|
|
26
|
+
this.frames.shift()
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
clear(): void {
|
|
31
|
+
this.frames.length = 0
|
|
32
|
+
this.bytes = 0
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private expire(): void {
|
|
36
|
+
while (this.frames[0] && this.frames[0].expires <= this.options.now())
|
|
37
|
+
this.bytes -= this.frames.shift()!.bytes
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -11,6 +11,7 @@ import { durabilityOf } from '../supervisor-protocol/durability'
|
|
|
11
11
|
import { wireEventBodySchema } from '../supervisor-protocol/event-body'
|
|
12
12
|
import { maxDurableEventBytes, maxEphemeralDeltaBytes } from '../supervisor-protocol/payload-overflow'
|
|
13
13
|
import { decodeControlPlaneFrame, encodeWireFrame } from '../supervisor-protocol/wire-codec'
|
|
14
|
+
import { EphemeralFrameBuffer } from './ephemeral-frame-buffer'
|
|
14
15
|
import { SupervisorRpcClient } from './rpc-client'
|
|
15
16
|
|
|
16
17
|
export interface ResidentSupervisorSocket {
|
|
@@ -36,6 +37,7 @@ export class SupervisorRuntimeHandler implements RuntimeConnectionHandler {
|
|
|
36
37
|
private eventAckFloor = 0
|
|
37
38
|
private stopped = false
|
|
38
39
|
private readonly retainedFrames: string[] = []
|
|
40
|
+
private readonly ephemeralFrames = new EphemeralFrameBuffer()
|
|
39
41
|
private readonly heartbeatTimer: ReturnType<typeof setInterval>
|
|
40
42
|
|
|
41
43
|
constructor(private readonly dependencies: {
|
|
@@ -67,6 +69,7 @@ export class SupervisorRuntimeHandler implements RuntimeConnectionHandler {
|
|
|
67
69
|
this.socket = input.socket
|
|
68
70
|
this.eventAckFloor = input.eventAckFloor
|
|
69
71
|
this.retainedFrames.length = 0
|
|
72
|
+
this.ephemeralFrames.clear()
|
|
70
73
|
if (previous && previous !== input.socket)
|
|
71
74
|
previous.close(1008, 'Connection generation was superseded.')
|
|
72
75
|
this.rpc.attach(frame => this.sendRetained(frame))
|
|
@@ -107,6 +110,7 @@ export class SupervisorRuntimeHandler implements RuntimeConnectionHandler {
|
|
|
107
110
|
return
|
|
108
111
|
}
|
|
109
112
|
this.eventAckFloor = Math.max(this.eventAckFloor, frame.highWaterMark)
|
|
113
|
+
this.flushEphemeral()
|
|
110
114
|
return
|
|
111
115
|
}
|
|
112
116
|
if (frame.kind === 'rpc.response') {
|
|
@@ -121,6 +125,7 @@ export class SupervisorRuntimeHandler implements RuntimeConnectionHandler {
|
|
|
121
125
|
return
|
|
122
126
|
this.socket = undefined
|
|
123
127
|
this.retainedFrames.length = 0
|
|
128
|
+
this.ephemeralFrames.clear()
|
|
124
129
|
this.rpc.detach()
|
|
125
130
|
}
|
|
126
131
|
|
|
@@ -128,6 +133,7 @@ export class SupervisorRuntimeHandler implements RuntimeConnectionHandler {
|
|
|
128
133
|
if (this.socket !== socket)
|
|
129
134
|
return
|
|
130
135
|
this.flushRetained()
|
|
136
|
+
this.flushEphemeral()
|
|
131
137
|
}
|
|
132
138
|
|
|
133
139
|
async refreshSecrets(input: {
|
|
@@ -154,6 +160,7 @@ export class SupervisorRuntimeHandler implements RuntimeConnectionHandler {
|
|
|
154
160
|
this.rpc.stop()
|
|
155
161
|
this.socket?.close(1001, 'Supervisor runtime stopped.')
|
|
156
162
|
this.socket = undefined
|
|
163
|
+
this.ephemeralFrames.clear()
|
|
157
164
|
await this.processing.catch(() => undefined)
|
|
158
165
|
}
|
|
159
166
|
|
|
@@ -269,14 +276,20 @@ export class SupervisorRuntimeHandler implements RuntimeConnectionHandler {
|
|
|
269
276
|
private sendEvent(event: EventEnvelope): void {
|
|
270
277
|
const frame = encodeWireFrame(event)
|
|
271
278
|
if (event.delivery_semantics === 'ephemeral') {
|
|
272
|
-
if (this.
|
|
279
|
+
if (!this.socket)
|
|
273
280
|
return
|
|
274
|
-
this.
|
|
281
|
+
this.ephemeralFrames.enqueue(frame, this.dependencies.store.localEventMax())
|
|
282
|
+
this.flushEphemeral()
|
|
275
283
|
return
|
|
276
284
|
}
|
|
277
285
|
this.sendRetained(frame)
|
|
278
286
|
}
|
|
279
287
|
|
|
288
|
+
private flushEphemeral(): void {
|
|
289
|
+
if (this.socket && this.retainedFrames.length === 0)
|
|
290
|
+
this.ephemeralFrames.flush(this.eventAckFloor, frame => this.socket!.send(frame))
|
|
291
|
+
}
|
|
292
|
+
|
|
280
293
|
private sendRetained(frame: string): void {
|
|
281
294
|
const socket = this.socket
|
|
282
295
|
if (!socket)
|