feat(session)!: embed assistant streams in format v2
This commit is contained in:
1 parent
0bb7bba015
commit
f99b06eaed
387 files changed
+9491
-4625
No files matched your search
@@ -1,18 +1,33 @@
|
||||
/** Observable contiguous Session event window consumed by domain assemblers. */
|
||||
import { notifySubscribers, type ObservableSnapshot } from '@deepseek-ai/dsh-client-store'
|
||||
import type { LlmAttemptId, StreamChunk } from '@deepseek-ai/dsh-llm'
|
||||
import type { SessionEvent } from '@deepseek-ai/dsh-session/types'
|
||||
import type { ChunkRowEvent } from '../../types.ts'
|
||||
|
||||
/** Standard Session event or compact historical Assistant run. */
|
||||
export type SessionEventLike = SessionEvent | ChunkRowEvent
|
||||
/** Client-only live chunk presentation; `seq` orders the transient row between durable Session seqs. */
|
||||
export interface AssistantLiveChunkEvent {
|
||||
readonly type: 'assistant/live-chunk'
|
||||
readonly seq: number
|
||||
readonly time: number
|
||||
readonly data: {
|
||||
readonly attemptId: LlmAttemptId
|
||||
readonly turn: number
|
||||
readonly step: number
|
||||
readonly chunk: StreamChunk
|
||||
}
|
||||
}
|
||||
|
||||
/** Current durable Session event or one client-only live chunk presentation. */
|
||||
export type SessionEventLike = SessionEvent | AssistantLiveChunkEvent
|
||||
|
||||
/** Client history entry retaining its coarse transport discriminator. */
|
||||
export type SessionEventLikeEntry =
|
||||
| { readonly type: 'event'; readonly event: SessionEvent }
|
||||
| { readonly type: 'chunks'; readonly event: ChunkRowEvent }
|
||||
| { readonly type: 'transient'; readonly event: AssistantLiveChunkEvent }
|
||||
|
||||
/** Scalar live entry accepted by append-only Client paths. */
|
||||
export type SessionLiveEventEntry = Extract<SessionEventLikeEntry, { readonly type: 'event' }>
|
||||
/** Client-only Assistant frame admitted outside durable cursor algebra. */
|
||||
export type SessionTransientEventEntry = Extract<SessionEventLikeEntry, { readonly type: 'transient' }>
|
||||
|
||||
interface EventWindowLeaf {
|
||||
readonly kind: 'leaf'
|
||||
@@ -78,7 +93,7 @@ function windowSnapshot(
|
||||
export type SessionEventChange =
|
||||
| { readonly kind: 'replace'; readonly entries: readonly SessionEventLikeEntry[] }
|
||||
| { readonly kind: 'prepend'; readonly entries: readonly SessionEventLikeEntry[] }
|
||||
| { readonly kind: 'append'; readonly entries: readonly SessionLiveEventEntry[] }
|
||||
| { readonly kind: 'append'; readonly entries: readonly SessionEventLikeEntry[] }
|
||||
|
||||
/** Current contiguous event window and its latest synchronous delta. */
|
||||
export interface SessionEventWindow {
|
||||
@@ -139,7 +154,7 @@ export class MutableSessionEventSource implements SessionEventSource {
|
||||
* Append one contiguous live entry.
|
||||
* @param entry - live tail entry.
|
||||
*/
|
||||
append(entry: SessionLiveEventEntry): void {
|
||||
append(entry: SessionEventLikeEntry): void {
|
||||
const entries = [entry]
|
||||
this.window = concat(this.window, leaf(entries))
|
||||
this.publish(this.snapshot.hasMore, {
|
||||
|
||||
Reference in new issue
Block a user