@sparkelf/dsh-plus 0.2.9-alpha.92 → 0.2.9-alpha.94

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.
@@ -1,379 +0,0 @@
1
- diff --git a/packages/api/session-controller/src/client/contract/session.ts b/packages/api/session-controller/src/client/contract/session.ts
2
- index ce060ec4..ea3ce4b6 100644
3
- --- a/packages/api/session-controller/src/client/contract/session.ts
4
- +++ b/packages/api/session-controller/src/client/contract/session.ts
5
- @@ -12,7 +12,7 @@ import type { MessageId } from '@deepseek-ai/dsh-llm/brand'
6
- import type { SessionId, SessionSeq } from '@deepseek-ai/dsh-session/types'
7
- import type { RemoteResult } from '@deepseek-ai/dsh-typert-protocol'
8
- import type { ObservableSnapshot } from '@deepseek-ai/dsh-client-store'
9
- -import type { PromptContentPart, QueueAction, SessionRequestId } from '../../types.ts'
10
- +import type { PromptContentPart, QueueAction, SessionMentionRef, SessionRequestId } from '../../types.ts'
11
- import type { PendingSubmissionAttachment, SessionSnapshot } from './snapshot.ts'
12
-
13
- /**
14
- @@ -100,6 +100,7 @@ export interface ISession {
15
- mode: 'queue' | 'steer',
16
- signal?: AbortSignal,
17
- requestId?: SessionRequestId,
18
- + mentions?: readonly SessionMentionRef[],
19
- ): Promise<RemoteResult<{ accepted: true }>>
20
- /**
21
- * Resolve one stored image using this Session's gateway permission scope.
22
- diff --git a/packages/api/session-controller/src/client/index.ts b/packages/api/session-controller/src/client/index.ts
23
- index b9600f36..d48cb924 100644
24
- --- a/packages/api/session-controller/src/client/index.ts
25
- +++ b/packages/api/session-controller/src/client/index.ts
26
- @@ -28,6 +28,7 @@ export { createScope, scopeOf } from './scope.ts'
27
- export type { AgentContext, AgentScopeHandle } from './scope.ts'
28
- export { SessionCreateError, SessionForkError } from './sessions/service.ts'
29
- export type { SessionBinding, SessionListState, SessionSummary } from './sessions/service.ts'
30
- +export type { SessionMentionRef } from '../types.ts'
31
- export type {
32
- SessionListPhase,
33
- SessionListSnapshot,
34
- diff --git a/packages/api/session-controller/src/client/sessions/session.ts b/packages/api/session-controller/src/client/sessions/session.ts
35
- index 60194de5..67459761 100644
36
- --- a/packages/api/session-controller/src/client/sessions/session.ts
37
- +++ b/packages/api/session-controller/src/client/sessions/session.ts
38
- @@ -17,6 +17,7 @@ import type {
39
- SessionAssistantStreamBaseline,
40
- SessionProjectionBaseline,
41
- SessionRequestId,
42
- + SessionMentionRef,
43
- } from '../../types.ts'
44
- import type {
45
- BeginSubmissionInput, PendingSubmissionRetirement, SessionFace, SubmissionHandle,
46
- @@ -272,6 +273,7 @@ export class Session implements SessionFace {
47
- mode: 'queue' | 'steer',
48
- signal?: AbortSignal,
49
- requestId?: SessionRequestId,
50
- + mentions?: readonly SessionMentionRef[],
51
- ): Promise<RemoteResult<{ accepted: true }>> {
52
- this.promptError = null
53
- this.lastAgentError = null
54
- @@ -287,6 +289,7 @@ export class Session implements SessionFace {
55
- mode,
56
- content,
57
- clientTimeZone,
58
- + ...(mentions === undefined || mentions.length === 0 ? {} : { mentions }),
59
- }, signal)
60
- } else if (content.some(part => part.type === 'file')) {
61
- result = {
62
- diff --git a/packages/api/session-controller/src/index.ts b/packages/api/session-controller/src/index.ts
63
- index 6303340c..a6c253ee 100644
64
- --- a/packages/api/session-controller/src/index.ts
65
- +++ b/packages/api/session-controller/src/index.ts
66
- @@ -487,6 +487,9 @@ export class SessionController extends TypertRemoteService {
67
- rpcId: request.requestId,
68
- ...(clientTimeZone === undefined ? {} : { clientTimeZone }),
69
- ...(principal === undefined ? {} : { principal }),
70
- + // Structured mentions ride the durable source, not the model content: a host plugin that
71
- + // routes on identity reads them here, and the model only sees the text.
72
- + ...(request.mentions === undefined || request.mentions.length === 0 ? {} : { mentions: request.mentions }),
73
- }
74
- return this.commands.prompt(request, source)
75
- }
76
- diff --git a/packages/api/session-controller/src/types.ts b/packages/api/session-controller/src/types.ts
77
- index 49cd7c0f..12257027 100644
78
- --- a/packages/api/session-controller/src/types.ts
79
- +++ b/packages/api/session-controller/src/types.ts
80
- @@ -320,6 +320,23 @@ export interface SessionForkValue {
81
- readonly sessionId: SessionId
82
- }
83
-
84
- +/**
85
- + * One structured mention a client declared when composing a prompt.
86
- + *
87
- + * The composer's `@` menu renders a chip per source, and a source opts in by inserting with
88
- + * `appearance: 'mention'`; the reference travels here as identity plus the label the user saw, so
89
- + * a host plugin can route it without parsing the prompt text. Never part of the model input: the
90
- + * text already names the item.
91
- + */
92
- +export interface SessionMentionRef {
93
- + /** Trigger source that produced the chip (e.g. a roster source). */
94
- + readonly sourceId: string
95
- + /** Source-scoped identity of the picked item. */
96
- + readonly itemId: string
97
- + /** Display label the user picked, for diagnostics and dedupe. */
98
- + readonly displayName: string
99
- +}
100
- +
101
- /** Session prompt request. */
102
- export interface SessionPromptRequest {
103
- /** Client-minted identity persisted on the accepted inbox input, including empty continuation. */
104
- @@ -328,6 +345,8 @@ export interface SessionPromptRequest {
105
- readonly mode: 'queue' | 'steer'
106
- /** Non-whitespace text or attachments; an empty array continues an eligible failed idle Session. */
107
- readonly content: readonly PromptContentPart[]
108
- + /** Structured mentions the composer declared, in document order. Absent when it carried none. */
109
- + readonly mentions?: readonly SessionMentionRef[]
110
- readonly clientTimeZone?: string
111
- }
112
-
113
- @@ -397,7 +416,13 @@ declare module '@deepseek-ai/dsh-llm' {
114
- * caller that submitted the prompt. `principal` is written only for a
115
- * caller other than the owner, so an absent `principal` means the owner.
116
- */
117
- - 'user-rpc': { kind: 'user'; rpcId: SessionRequestId; clientTimeZone?: string; principal?: Principal }
118
- + 'user-rpc': {
119
- + kind: 'user'
120
- + rpcId: SessionRequestId
121
- + clientTimeZone?: string
122
- + principal?: Principal
123
- + mentions?: readonly SessionMentionRef[]
124
- + }
125
- /** Empty retry user message with browser prompt correlation and caller metadata. */
126
- 'retry-rpc': { kind: 'retry'; rpcId: SessionRequestId; clientTimeZone?: string; principal?: Principal }
127
- }
128
- diff --git a/packages/client/ui-conversation/src/client/contract/draft-editor.ts b/packages/client/ui-conversation/src/client/contract/draft-editor.ts
129
- index 86592a82..3ee5ea16 100644
130
- --- a/packages/client/ui-conversation/src/client/contract/draft-editor.ts
131
- +++ b/packages/client/ui-conversation/src/client/contract/draft-editor.ts
132
- @@ -16,7 +16,12 @@ export interface ReferenceInsert {
133
- readonly source: string
134
- readonly ref: string
135
- readonly label: string
136
- - readonly appearance?: 'session' | 'file' | 'folder'
137
- + /**
138
- + * Row glyph, and the submit-time declaration hook: `'mention'` marks a reference a host plugin
139
- + * must receive as structured identity (`source`/`ref`) rather than re-parse out of the text.
140
- + * Every other value is display-only.
141
- + */
142
- + readonly appearance?: 'session' | 'file' | 'folder' | 'resource' | 'mention'
143
- readonly clipboardText: string
144
- }
145
-
146
- diff --git a/packages/client/ui-conversation/src/client/input/facade.ts b/packages/client/ui-conversation/src/client/input/facade.ts
147
- index 1fd208b6..a0155622 100644
148
- --- a/packages/client/ui-conversation/src/client/input/facade.ts
149
- +++ b/packages/client/ui-conversation/src/client/input/facade.ts
150
- @@ -21,8 +21,10 @@ import type {
151
- SessionInput, SubmitAttempt, SubmitAttachment, SubmitOutcome,
152
- } from '../contract/input.ts'
153
- import type {
154
- - ArbitrateKey, ArbitrateOutcome, ComposerKeyboard, DraftInput, DraftSnapshot, ReferenceInsert, TokenSpan,
155
- + ArbitrateKey, ArbitrateOutcome, ComposerKeyboard, DraftInput, DraftSnapshot, Occurrence,
156
- + ReferenceInsert, TokenSpan,
157
- } from '../contract/draft-editor.ts'
158
- +import type { SessionMentionRef } from '@deepseek-ai/dsh-api-session-controller/client'
159
- import type { InputSubmitMode, MessageSubmission, MessageSubmissionState } from '../contract/composer-submission.ts'
160
- import { serializeDraftPrompt } from './prompt.ts'
161
- import { SubmitMachine } from './machine.ts'
162
- @@ -70,6 +72,7 @@ export interface SessionInputDeps {
163
- mode: InputSubmitMode,
164
- signal: AbortSignal,
165
- accept: () => void,
166
- + mentions?: readonly SessionMentionRef[],
167
- ): Promise<SubmitOutcome>
168
- /** Live Session and composer-block policy for transcript insertion. */
169
- quoteInsertionAllowed?: () => boolean
170
- @@ -135,6 +138,29 @@ const EMPTY_LEXICON: ReadonlyMap<'/' | '@', readonly string[]> = new Map()
171
- * setDraft/submit + the published InputState store, over a shell-owned
172
- * Lexical editor.
173
- */
174
- +/**
175
- + * Structured mentions declared by one draft, in document order.
176
- + *
177
- + * Only `appearance: 'mention'` chips qualify: a source opts in when it inserts through
178
- + * `PickOutcome.insert`, and the host plugin that owns the roster reads the ids instead of parsing
179
- + * `@name` out of the text (which would misread a code sample and let any message smuggle itself
180
- + * into a routing decision). The same item picked twice is one mention.
181
- + * @param occurrences - chip occurrences projected from the editor.
182
- + * @returns `{sourceId, itemId, displayName}` records, or undefined when the draft declared none.
183
- + */
184
- +export const collectMentions = (occurrences: readonly Occurrence[]): readonly SessionMentionRef[] | undefined => {
185
- + const seen = new Set<string>()
186
- + const mentions: SessionMentionRef[] = []
187
- + for (const occurrence of occurrences) {
188
- + if (occurrence.appearance !== 'mention') continue
189
- + const key = occurrence.source + '\u0000' + occurrence.ref
190
- + if (seen.has(key)) continue
191
- + seen.add(key)
192
- + mentions.push({ sourceId: occurrence.source, itemId: occurrence.ref, displayName: occurrence.label })
193
- + }
194
- + return mentions.length === 0 ? undefined : mentions
195
- +}
196
- +
197
- export class SessionInputShell implements SessionInput {
198
- /** Published editor projection + submit-plane state + queue overlay (the InputZone currency source). */
199
- readonly state: SnapshotStore<InputState>
200
- @@ -742,7 +768,10 @@ export class SessionInputShell implements SessionInput {
201
- this.settleSink(attempt, Promise.resolve({ kind: 'success' }))
202
- return
203
- }
204
- - this.settleSink(attempt, this.deps.defaultSink(text, attachmentIds, mode, attempt.signal, () => { this.acceptSink(attempt) }))
205
- + const mentions = collectMentions(attempt.occurrences)
206
- + this.settleSink(attempt, mentions === undefined
207
- + ? this.deps.defaultSink(text, attachmentIds, mode, attempt.signal, () => { this.acceptSink(attempt) })
208
- + : this.deps.defaultSink(text, attachmentIds, mode, attempt.signal, () => { this.acceptSink(attempt) }, mentions))
209
- }
210
- if (!(prompt instanceof Promise)) { send(prompt); return }
211
- void prompt.then(send, (error: unknown) => { this.failSink(attempt, error) })
212
- diff --git a/packages/client/ui-conversation/src/client/input/hub.ts b/packages/client/ui-conversation/src/client/input/hub.ts
213
- index f6e9ce41..7f4354b0 100644
214
- --- a/packages/client/ui-conversation/src/client/input/hub.ts
215
- +++ b/packages/client/ui-conversation/src/client/input/hub.ts
216
- @@ -12,6 +12,7 @@ import type {
217
- ISessions, SessionBinding, SessionFace,
218
- } from '@deepseek-ai/dsh-api-session-controller/client'
219
- import type { SessionId, SessionSeq } from '@deepseek-ai/dsh-session/types'
220
- +import type { SessionMentionRef } from '@deepseek-ai/dsh-api-session-controller/client'
221
- import type { TranslateNS } from '@deepseek-ai/dsh-client-locale/client'
222
- import type { InboxState } from '@deepseek-ai/dsh-agent/types'
223
- import type { ModelSelectionProjection } from '@deepseek-ai/dsh-agent/types'
224
- @@ -49,6 +50,7 @@ interface ConversationAttachmentFace {
225
- mode: InputSubmitMode,
226
- signal?: AbortSignal,
227
- accept?: () => void,
228
- + mentions?: readonly SessionMentionRef[],
229
- ): Promise<SubmitOutcome>
230
- serializeDraftAttachments(attachmentIds: readonly DraftAttachmentId[]): Promise<DraftAttachmentSerializationResult>
231
- releaseDraftAttachment(id: DraftAttachmentId): void
232
- @@ -125,7 +127,7 @@ export class InputHub implements SessionInputResolver {
233
- inputTriggers: () => this.controller(actx),
234
- popup: () => this.popup(actx),
235
- inbox: session.projections.faceOf('inbox') as ObservableSnapshot<InboxState | undefined>,
236
- - defaultSink: (text, attachmentIds, mode, signal, accept) => this.sink(session, text, attachmentIds, mode, signal, accept),
237
- + defaultSink: (text, attachmentIds, mode, signal, accept, mentions) => this.sink(session, text, attachmentIds, mode, signal, accept, mentions),
238
- quoteRemoveLabel: () => this.t('quote.remove'),
239
- quoteInsertionAllowed: () => {
240
- const state = session.getSnapshot()
241
- @@ -273,11 +275,15 @@ export class InputHub implements SessionInputResolver {
242
- mode: InputSubmitMode,
243
- signal: AbortSignal,
244
- accept: () => void,
245
- + mentions?: readonly SessionMentionRef[],
246
- ): Promise<SubmitOutcome> {
247
- if (text === '' && attachmentIds.length === 0) {
248
- return session.prompt([], mode, signal).then(result => result.ok ? { kind: 'success' } : { kind: 'error' })
249
- }
250
- - return this.conversation().sendSession(session, text, attachmentIds, mode, signal, accept)
251
- + // A draft that declared mentions takes one extra argument; the ordinary send keeps its shape.
252
- + return mentions === undefined || mentions.length === 0
253
- + ? this.conversation().sendSession(session, text, attachmentIds, mode, signal, accept)
254
- + : this.conversation().sendSession(session, text, attachmentIds, mode, signal, accept, mentions)
255
- }
256
-
257
- /**
258
- diff --git a/packages/client/ui-conversation/src/client/service.ts b/packages/client/ui-conversation/src/client/service.ts
259
- index af19eb77..4ae2286d 100644
260
- --- a/packages/client/ui-conversation/src/client/service.ts
261
- +++ b/packages/client/ui-conversation/src/client/service.ts
262
- @@ -9,6 +9,7 @@
263
- */
264
- import { Service } from '@deepseek-ai/cordis'
265
- import type { Context } from '@deepseek-ai/cordis'
266
- +import type { SessionMentionRef } from '@deepseek-ai/dsh-api-session-controller/client'
267
- import { randomUUID } from '@deepseek-ai/dsh-util-crypto'
268
- // Type-only imports: a plugin-to-plugin value import is a bundle purity
269
- // error, so scope resolution goes through the sessions service (scopeOf
270
- @@ -238,6 +239,7 @@ export class ConversationController extends Service implements IConversation {
271
- mode: InputSubmitMode,
272
- signal?: AbortSignal,
273
- accept?: () => void,
274
- + mentions?: readonly SessionMentionRef[],
275
- ): Promise<SubmitOutcome> {
276
- const attachments = this.resolveDraftAttachments(attachmentIds)
277
- if (attachments.length !== attachmentIds.length) {
278
- @@ -306,7 +308,12 @@ export class ConversationController extends Service implements IConversation {
279
- }
280
- // An Inbox row can show the acceptance before the receipt; a receipt that fails afterwards changes
281
- // nothing here because the Host already holds the message.
282
- - const result = await Promise.race([session.prompt(content, mode, signal, submission.requestId), acceptance.promise])
283
- + // Only a draft that declared mentions takes the extra argument, so the ordinary send keeps the
284
- + // four-argument prompt every caller and test double already knows.
285
- + const prompting = mentions === undefined || mentions.length === 0
286
- + ? session.prompt(content, mode, signal, submission.requestId)
287
- + : session.prompt(content, mode, signal, submission.requestId, mentions)
288
- + const result = await Promise.race([prompting, acceptance.promise])
289
- if (result !== undefined && !result.ok) return { kind: 'error' }
290
- ownership.accepted = true
291
- // An accepted prompt whose echo already retired unobserved, as when its queue entry was removed.
292
- diff --git a/packages/client/ui-conversation/tests/mentions.client.spec.ts b/packages/client/ui-conversation/tests/mentions.client.spec.ts
293
- new file mode 100644
294
- index 00000000..7439cbff
295
- --- /dev/null
296
- +++ b/packages/client/ui-conversation/tests/mentions.client.spec.ts
297
- @@ -0,0 +1,45 @@
298
- +import { describe, expect, it } from 'vitest'
299
- +import type { Occurrence } from '../src/client/contract/draft-editor.ts'
300
- +import { collectMentions } from '../src/client/input/facade.ts'
301
- +
302
- +/** One projected chip occurrence; only the fields the collector reads are interesting. */
303
- +const occurrence = (patch: Partial<Occurrence> & Pick<Occurrence, 'source' | 'ref'>): Occurrence => ({
304
- + occurrenceId: 1,
305
- + offset: 0,
306
- + length: 4,
307
- + label: 'label',
308
- + clipboardText: '@label',
309
- + ...patch,
310
- +})
311
- +
312
- +describe('collecting declared mentions', () => {
313
- + it('takes mention chips only, in document order', () => {
314
- + const mentions = collectMentions([
315
- + occurrence({ source: 'reference', ref: 'src/a.ts', appearance: 'file', label: 'a.ts' }),
316
- + occurrence({ source: 'roster', ref: 'u-1', appearance: 'mention', label: '张三' }),
317
- + occurrence({ source: 'roster', ref: 'u-2', appearance: 'mention', label: '李四' }),
318
- + ])
319
- +
320
- + // A file chip is a reference the model reads, not an identity a host plugin routes on.
321
- + expect(mentions).toEqual([
322
- + { sourceId: 'roster', itemId: 'u-1', displayName: '张三' },
323
- + { sourceId: 'roster', itemId: 'u-2', displayName: '李四' },
324
- + ])
325
- + })
326
- +
327
- + it('reports one mention when the same item is picked twice', () => {
328
- + const mentions = collectMentions([
329
- + occurrence({ source: 'roster', ref: 'u-1', appearance: 'mention', label: '张三' }),
330
- + occurrence({ source: 'roster', ref: 'u-1', appearance: 'mention', label: '张三' }),
331
- + ])
332
- +
333
- + expect(mentions).toEqual([{ sourceId: 'roster', itemId: 'u-1', displayName: '张三' }])
334
- + })
335
- +
336
- + it('answers undefined for a draft that declared none', () => {
337
- + // Undefined, not an empty array: the sink keeps its original argument shape, so callers and
338
- + // test doubles that never saw a mention stay unchanged.
339
- + expect(collectMentions([])).toBeUndefined()
340
- + expect(collectMentions([occurrence({ source: 'reference', ref: 'x', appearance: 'session' })])).toBeUndefined()
341
- + })
342
- +})
343
-
344
- diff --git a/packages/client/ui-primitives/src/ReferenceIcon.tsx b/packages/client/ui-primitives/src/ReferenceIcon.tsx
345
- index ca566c40..7fd75f96 100644
346
- --- a/packages/client/ui-primitives/src/ReferenceIcon.tsx
347
- +++ b/packages/client/ui-primitives/src/ReferenceIcon.tsx
348
- @@ -1,12 +1,12 @@
349
- import type { ReactNode } from 'react'
350
- -import { ICON_MEDIUM_STROKE, ICON_REGULAR_STROKE } from './icons/index.tsx'
351
- +import { ICON_MEDIUM_STROKE, ICON_REGULAR_STROKE, IconUserOutlineRegular } from './icons/index.tsx'
352
- import type { IconProps } from './icons/props.ts'
353
- import {
354
- BrowseOutlineArtwork, ChatLinesOutlineArtwork, FolderCloseArtwork,
355
- } from './icons/shared-artwork.tsx'
356
-
357
- /** Reference domains with distinct composer and transcript glyphs. */
358
- -export type ReferenceIconKind = 'session' | 'file' | 'folder'
359
- +export type ReferenceIconKind = 'session' | 'file' | 'folder' | 'resource' | 'mention'
360
-
361
- /** Props shared by inline reference glyphs. */
362
- export interface ReferenceIconProps extends IconProps {
363
- @@ -25,8 +25,16 @@ interface WeightedReferenceIconProps extends ReferenceIconProps {
364
- function ReferenceIconArtwork({ kind, size = 16, className, strokeWidth }: WeightedReferenceIconProps): ReactNode {
365
- switch (kind) {
366
- case 'session': return <ChatLinesOutlineArtwork size={size} className={className} strokeWidth={strokeWidth} />
367
- + case 'mention': return <IconUserOutlineRegular size={size} className={className} />
368
- case 'file': return <BrowseOutlineArtwork size={size} className={className} strokeWidth={strokeWidth} />
369
- case 'folder': return <FolderCloseArtwork size={size} className={className} strokeWidth={strokeWidth} />
370
- + case 'resource': return (
371
- + <svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={strokeWidth} strokeLinecap="round" strokeLinejoin="round" className={className} aria-hidden>
372
- + <path d="M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z" />
373
- + <path d="m3.3 7 8.7 5 8.7-5" />
374
- + <path d="M12 22V12" />
375
- + </svg>
376
- + )
377
- }
378
- }
379
-
@@ -1,92 +0,0 @@
1
- diff --git a/packages/core/session/src/index.ts b/packages/core/session/src/index.ts
2
- index ea6c337f..82d57f11 100644
3
- --- a/packages/core/session/src/index.ts
4
- +++ b/packages/core/session/src/index.ts
5
- @@ -15,7 +15,7 @@ import type { Scoped } from '@deepseek-ai/dsh-scope'
6
- import type { Message } from '@deepseek-ai/dsh-llm'
7
- import { SESSION_FORMAT_VERSION, SessionLogOffset, SessionSeq } from './types.ts'
8
- import type { TypertLookup } from '@deepseek-ai/dsh-typert-protocol'
9
- -import type { CreateSessionOptions, EpochHeader, PluginRecord, PluginRecordMap, PluginRecordType, PrepareSessionOptions, RequestContext, SessionEvent, SessionEventInput, SessionEventMap, SessionEventType, SessionHeader, SessionId, SessionSeedEventState, SurfaceIntent, SurfaceEventType } from './types.ts'
10
- +import type { CreateSessionOptions, EpochHeader, PluginRecord, PluginRecordMap, PluginRecordType, PrepareSessionOptions, RequestContext, SessionEvent, SessionEventInput, SessionEventMap, SessionEventType, SessionHeader, SessionId, SessionSeedEventState, SurfaceIntent, EnvelopeIntent, SurfaceEventType } from './types.ts'
11
- import { SurfaceManager, validateSessionEventData, validateSurfaceMetadata } from './surface.ts'
12
- import type { SessionSurface, SessionMessageProjection } from './surface.ts'
13
- import { foldRequestHeader } from './request-header.ts'
14
- @@ -521,11 +521,14 @@ export function pluginRecordOf(event: SessionEvent): PluginRecord | undefined {
15
- function snapshotAppend(
16
- type: SessionEventType,
17
- data: SessionEventMap[SessionEventType] | undefined,
18
- - opts: SurfaceIntent | undefined,
19
- + opts: SurfaceIntent | EnvelopeIntent | undefined,
20
- subject: string,
21
- ) {
22
- - const surfaceOp = opts?.surfaceOp
23
- - const sourceEventSeqs = opts?.sourceEventSeqs
24
- + // A surface event's option object is a `SurfaceIntent`; a log-only event's is an
25
- + // `EnvelopeIntent`. The two never share a field, so one object serves both.
26
- + const intent = opts as (SurfaceIntent & EnvelopeIntent) | undefined
27
- + const surfaceOp = intent?.surfaceOp
28
- + const sourceEventSeqs = intent?.sourceEventSeqs
29
- const dataSnapshot = snapshotJsonValue(data)
30
- if (dataSnapshot === undefined) throw new Error(`${subject} carries non-JSON-serializable data`)
31
- const surface = snapshotJsonValue({
32
- @@ -533,13 +536,19 @@ function snapshotAppend(
33
- ...surfaceOp === undefined ? {} : { surfaceOp },
34
- })
35
- if (surface === undefined) throw new Error(`${subject} carries non-JSON-serializable surface metadata`)
36
- - return { type, data: dataSnapshot, surface }
37
- + return { type, data: dataSnapshot, surface, ignorable: intent?.ignorable === true }
38
- }
39
-
40
- /** Construct and validate one live event from detached inputs. */
41
- function createAppendEvent(snapshot: ReturnType<typeof snapshotAppend>, seq: SessionSeq): SessionEvent {
42
- - const { type, data, surface } = snapshot
43
- - const event = deepFreeze({ type, seq, time: Date.now(), data, ...surface } as SessionEvent)
44
- + const { type, data, surface, ignorable } = snapshot
45
- + // A log-only producer declares that a reader without its event type may skip the record.
46
- + // Only `true` is admitted: the field's absence means required, and an explicit falsy value
47
- + // would be indistinguishable from a producer that meant the opposite.
48
- + const event = deepFreeze({
49
- + type, seq, time: Date.now(), data, ...surface,
50
- + ...ignorable ? { ignorable: true } : {},
51
- + } as SessionEvent)
52
- validateSessionEventData(event, `session event "${type}" at seq ${seq}`)
53
- return event
54
- }
55
- @@ -853,12 +862,12 @@ export class Session {
56
- append<T extends SessionEventType>(
57
- type: T,
58
- data: SessionEventMap[T],
59
- - ...opts: T extends SurfaceEventType ? [opts: SurfaceIntent<T>] : []
60
- + ...opts: T extends SurfaceEventType ? [opts: SurfaceIntent<T>] : [opts?: EnvelopeIntent]
61
- ): SessionEvent<T>
62
- append(
63
- type: SessionEventType | readonly SessionEventInput[],
64
- data?: SessionEventMap[SessionEventType],
65
- - ...opts: [opts?: SurfaceIntent]
66
- + ...opts: [opts?: SurfaceIntent | EnvelopeIntent]
67
- ): SessionEvent | readonly SessionEvent[] {
68
- if (typeof type !== 'string') return this.#appendEvents(type)
69
- this.publicationEntry()
70
- diff --git a/packages/core/session/src/types.ts b/packages/core/session/src/types.ts
71
- index 0cf13c86..0f350a41 100644
72
- --- a/packages/core/session/src/types.ts
73
- +++ b/packages/core/session/src/types.ts
74
- @@ -490,6 +490,18 @@ export type SessionEventInput = {
75
- [K in SessionEventType]: readonly [type: K, data: SessionEventMap[K], ...opts: K extends SurfaceEventType ? [opts: SurfaceIntent<K>] : []]
76
- }[SessionEventType]
77
-
78
- +/**
79
- + * Envelope markers a log-only event may declare at {@link Session.append}.
80
- + *
81
- + * `ignorable` lets a reader that does not know the event type skip it instead of refusing the
82
- + * whole log. Only a producer whose record cannot affect reconstruction may set it, so it is
83
- + * opt-in per append rather than a property of the event type.
84
- + */
85
- +export type EnvelopeIntent = {
86
- + /** Marks an event a reader may skip when it does not recognize the type. */
87
- + ignorable?: true
88
- +}
89
- +
90
- /**
91
- * One immutable entry in the session log.
92
- *