feat(cli): session continue-stream + NDJSON init MessageID
Adds `weknora session continue-stream <session-id> --message <id>` for
re-attaching to an in-progress or already-completed SSE event buffer.
Server semantics (replay-from-0 + tail):
- Every connection replays the full stored event log from index 0,
then tails any new events. NOT cursor-from-disconnect. Agents that
already consumed events on the original stream MUST dedupe by
message_id + event hash to avoid double-processing.
- Buffer TTL: redis mode 1h hardcoded; memory mode = process lifetime.
After expiry the CLI surfaces local.sse_stream_aborted.
Output is NDJSON: one CLI-injected init line carrying
{session_id, message_id, profile} at stream head, then raw SDK
StreamResponse events verbatim. The init line lets agents thread the
resume to the original message in their dedupe table before the first
SDK frame arrives — output.InitEvent gains an omitempty MessageID field
for this purpose; non-resume init events stay unchanged.
The command always emits NDJSON regardless of --format — there is no
human-text use case for raw event-log replay (operator scenarios are
incident response / debugging). --dry-run is excluded for the same
reason streaming commands always are: a buffered plan makes no sense
for an event stream.
This commit is contained in:
@@ -13,6 +13,11 @@ import (
|
||||
type InitEvent struct {
|
||||
Type string `json:"type"`
|
||||
SessionID string `json:"session_id"`
|
||||
// MessageID anchors a resumed stream (`session continue-stream`) to the
|
||||
// specific assistant message whose event buffer is being replayed. Empty
|
||||
// for fresh streams (chat / session ask) where the message id is only
|
||||
// known after the SDK emits its first agent_query frame.
|
||||
MessageID string `json:"message_id,omitempty"`
|
||||
AgentID string `json:"agent_id,omitempty"`
|
||||
KBID string `json:"kb_id,omitempty"`
|
||||
RequestID string `json:"request_id,omitempty"`
|
||||
|
||||
@@ -40,7 +40,7 @@ func TestEmitInit_OmitsEmptyOptionalFields(t *testing.T) {
|
||||
t.Fatalf("EmitInit: %v", err)
|
||||
}
|
||||
line := buf.String()
|
||||
for _, field := range []string{"kb_id", "agent_id", "model", "profile", "request_id"} {
|
||||
for _, field := range []string{"kb_id", "agent_id", "model", "profile", "request_id", "message_id"} {
|
||||
if strings.Contains(line, `"`+field+`"`) {
|
||||
t.Errorf("optional field %q should be omitted when empty, got: %s", field, line)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user