@tangle-network/agent-app 0.43.72 → 0.43.73
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.
|
@@ -222,24 +222,31 @@ declare function assistantRowIdForTurn(turnKey: string): string;
|
|
|
222
222
|
* no router import. Auth/access is one injected `authorize` seam, composable
|
|
223
223
|
* with `/app-auth` guards but not coupled to them.
|
|
224
224
|
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
225
|
+
* Optional product seams let a complex turn-orchestrator compose the vertical
|
|
226
|
+
* instead of hand-rolling a generator — each omittable to the exact behavior
|
|
227
|
+
* above: `turnLock` (single-flight acquire/release around the turn),
|
|
228
228
|
* `contextGate` (pre-producer domain-readiness short-circuit), `beforeTurn`
|
|
229
229
|
* (observe + augment the producer input), `lifecycle` (deterministic
|
|
230
230
|
* start/complete/error telemetry), `heartbeat` (keepalive during silent
|
|
231
|
-
* producer waits),
|
|
232
|
-
* `
|
|
233
|
-
*
|
|
231
|
+
* producer waits), and `onRawEvent` (the raw producer events, for telemetry) —
|
|
232
|
+
* plus the `authorize` result's `insertUserMessage` flag (suppress the user row
|
|
233
|
+
* for a product-dispatched turn). `handleChatTurn` stays the engine — the seams
|
|
234
|
+
* only wrap its input, its producer stream, and its settle.
|
|
234
235
|
*
|
|
235
|
-
* Seam stability:
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
236
|
+
* Seam stability: all of the above are STABLE and safe to depend on. They
|
|
237
|
+
* graduated in #227 against the bar this package holds itself to — a seam is
|
|
238
|
+
* provisional until two INDEPENDENT consumers exercise it, because one
|
|
239
|
+
* consumer's shape is indistinguishable from that consumer's assumptions.
|
|
240
|
+
* `turnLock` cleared it with `/turn-stream`'s shared DO adapter (#221);
|
|
241
|
+
* `contextGate`, `beforeTurn`, `onRawEvent` and `insertUserMessage` each
|
|
242
|
+
* cleared it with two product verticals reading them differently — and the
|
|
243
|
+
* review found no leaked assumptions to fix, only `ChatRouteEvent` to export.
|
|
244
|
+
*
|
|
245
|
+
* They stay FLAT top-level options (not grouped under a `hooks` object): that
|
|
246
|
+
* grouping would break every shipped consumer's call for no mechanism gain, and
|
|
247
|
+
* this package's exports are additive-only. For the same reason `onRawEvent`
|
|
248
|
+
* keeps its two-argument `(event, context)` signature rather than being
|
|
249
|
+
* normalized to the single-args shape the other seams take.
|
|
243
250
|
*/
|
|
244
251
|
|
|
245
252
|
/** Usage receipt persisted onto the assistant message (the flattened
|
|
@@ -338,7 +345,14 @@ type ChatTurnAuthorization<TContext> = {
|
|
|
338
345
|
* never overrides — the engine's retry-dedup: `authorize` runs before
|
|
339
346
|
* turn identity is resolved, so it cannot tell a retry from a fresh turn;
|
|
340
347
|
* a turn already deduped stays deduped. Omit / `true` → today's behavior.
|
|
341
|
-
*
|
|
348
|
+
*
|
|
349
|
+
* Settled shape (#227). The validated case in both consumers is the same:
|
|
350
|
+
* a durable plan-approval follow-up re-entering an execution the decision
|
|
351
|
+
* route already enqueued — a decision, not a typed message, so it must
|
|
352
|
+
* not surface a user bubble. Suppressing the insert also propagates:
|
|
353
|
+
* `ChatTurnProduceArgs.userMessageId` is `null` for the rest of the turn
|
|
354
|
+
* when there is no row to reuse, so a seam anchoring to the user row must
|
|
355
|
+
* handle that arm rather than assume a string. */
|
|
342
356
|
insertUserMessage?: boolean;
|
|
343
357
|
} | {
|
|
344
358
|
ok: false;
|
|
@@ -385,7 +399,12 @@ interface ChatTurnProduceArgs<TContext> {
|
|
|
385
399
|
userMessageId?: string | null;
|
|
386
400
|
}
|
|
387
401
|
/** One event as it crosses the route: the producer's own vocabulary, or an
|
|
388
|
-
* injected keepalive. Same shape the engine forwards verbatim.
|
|
402
|
+
* injected keepalive. Same shape the engine forwards verbatim.
|
|
403
|
+
*
|
|
404
|
+
* Public because it IS the vocabulary of two seams — `onRawEvent`'s parameter
|
|
405
|
+
* and `heartbeat.event`'s return. Exported so a product can declare a
|
|
406
|
+
* standalone handler (`function onRawEvent(e: ChatRouteEvent, ctx: T)`) rather
|
|
407
|
+
* than depending on contextual typing from an inline object literal. */
|
|
389
408
|
type ChatRouteEvent = {
|
|
390
409
|
type: string;
|
|
391
410
|
data?: Record<string, unknown>;
|
|
@@ -532,11 +551,34 @@ interface CreateChatTurnRoutesOptions<TContext = void> {
|
|
|
532
551
|
/** Pre-turn readiness gate that can short-circuit with a product `Response`
|
|
533
552
|
* before the producer runs (the user row is already persisted). Runs after
|
|
534
553
|
* `turnLock.acquire`, before `beforeTurn`. Omit → always proceed.
|
|
535
|
-
*
|
|
554
|
+
*
|
|
555
|
+
* Settled shape (#227). What a consumer may depend on:
|
|
556
|
+
* - `args.userMessageId` is RESOLVED here — a string, or `null` when the
|
|
557
|
+
* insert was suppressed with nothing to reuse. (`turnLock.acquire` is the
|
|
558
|
+
* only seam that sees it `undefined`.)
|
|
559
|
+
* - `{proceed:false}` releases the lock and returns the product's `Response`
|
|
560
|
+
* verbatim: `beforeTurn` and `produce` never run, no assistant row is
|
|
561
|
+
* written, and the user row already inserted is KEPT — a real user turn
|
|
562
|
+
* whose assistant side is the gate's own response.
|
|
563
|
+
* - Always returning `{proceed:true}` is supported, not a misuse: the seam
|
|
564
|
+
* doubles as the one place that runs after the user row exists and before
|
|
565
|
+
* the producer, which is where per-turn analytics and readiness
|
|
566
|
+
* precomputation belong. A gate that never gates is a valid consumer. */
|
|
536
567
|
contextGate?(args: ChatTurnProduceArgs<TContext>): ChatTurnGateResult | Promise<ChatTurnGateResult>;
|
|
537
568
|
/** Observe the assembled producer input and optionally augment it (rewrite
|
|
538
569
|
* the prompt / prior messages) before the producer runs. Omit → no change.
|
|
539
|
-
*
|
|
570
|
+
*
|
|
571
|
+
* Settled shape (#227). BOTH return arms are contract:
|
|
572
|
+
* - a `ChatTurnInputPatch` shallow-merges over the route-assembled args, so
|
|
573
|
+
* an omitted field keeps the route's value;
|
|
574
|
+
* - `void` means "no patch" — and mutating `args.context` in place is the
|
|
575
|
+
* supported way to thread request-scoped state forward to `produce` /
|
|
576
|
+
* `lifecycle` / `onTurnComplete`, which all receive the same object.
|
|
577
|
+
*
|
|
578
|
+
* A throw propagates (the turn fails with the lock released). It runs BEFORE
|
|
579
|
+
* `lifecycle.onTurnStart`, so a throw here fires no terminal lifecycle hook —
|
|
580
|
+
* the span never opened. Telemetry for a failure in this seam belongs in the
|
|
581
|
+
* seam, not in `lifecycle`. */
|
|
540
582
|
beforeTurn?(args: ChatTurnProduceArgs<TContext>): ChatTurnInputPatch | void | Promise<ChatTurnInputPatch | void>;
|
|
541
583
|
/** Deterministic run telemetry (start / complete / error) with identity and
|
|
542
584
|
* timing. Omit → no telemetry. */
|
|
@@ -547,7 +589,18 @@ interface CreateChatTurnRoutesOptions<TContext = void> {
|
|
|
547
589
|
* before any heartbeat injection (the raw sidecar-producer events, for
|
|
548
590
|
* telemetry). Never alters the stream; errors are swallowed. Distinct from
|
|
549
591
|
* `onEvent`, which sees the engine-framed stream incl. lifecycle envelopes.
|
|
550
|
-
*
|
|
592
|
+
*
|
|
593
|
+
* Settled shape (#227). What a consumer may depend on:
|
|
594
|
+
* - it sees EXACTLY the producer's own events — no engine lifecycle
|
|
595
|
+
* envelopes, and no injected keepalives (`heartbeat` wraps the stream
|
|
596
|
+
* downstream of this tap, so a synthetic event never reaches a trace);
|
|
597
|
+
* - a throw is caught and logged, never surfaced: a broken telemetry sink
|
|
598
|
+
* cannot fail a turn or truncate the client's stream;
|
|
599
|
+
* - it is an OBSERVER — the return value is ignored, and the event object
|
|
600
|
+
* continues downstream. Mutating it mutates the stream; don't.
|
|
601
|
+
*
|
|
602
|
+
* Takes `(event, context)` rather than one args object, matching both
|
|
603
|
+
* shipped consumers; see the module header on why it stays that way. */
|
|
551
604
|
onRawEvent?(event: ChatRouteEvent, context: TContext): void | Promise<void>;
|
|
552
605
|
/** Pre-persist transform of the final text (e.g. `/redact`'s `redactPII`).
|
|
553
606
|
* Live stream is never altered. */
|
|
@@ -1557,4 +1610,4 @@ interface PromoteAgentFilePartOptions {
|
|
|
1557
1610
|
/** Promote a part of an agent file with optional byte limits and MIME type detection */
|
|
1558
1611
|
declare function promoteAgentFilePart(options: PromoteAgentFilePartOptions): Promise<PromoteFilePartResult>;
|
|
1559
1612
|
|
|
1560
|
-
export { type AssistantDraftSnapshot, type AssistantDraftStore, type AssistantDraftWriter, type AssistantDraftWriterOptions, type AssistantRowValues, type AttachmentPathArgs, type AttachmentPathCheck, type AttachmentReadResult, type AttachmentUploadAuthorization, type AttachmentWriteResult, type BuildDispatchPartsInput, ChatAttachmentKind, type ChatRouteDurableProjection, type ChatRouteDurableProjectionLogger, type ChatTurnAuthorization, type ChatTurnAuthorizeArgs, type ChatTurnCompleteInput, ChatTurnFilePartInput, type ChatTurnGateResult, type ChatTurnHeartbeat, type ChatTurnInputPatch, type ChatTurnLifecycle, type ChatTurnLifecycleComplete, type ChatTurnLifecycleError, type ChatTurnLifecycleStart, type ChatTurnLock, type ChatTurnLockResult, type ChatTurnMessageStore, type ChatTurnModelFailover, ChatTurnPartInput, type ChatTurnProduceArgs, ChatTurnRequestPayload, type ChatTurnRouteProducer, type ChatTurnRoutes, type ChatTurnUsage, type CreateAttachmentUploadRouteOptions, type CreateChatTurnRoutesOptions, type CreateUploadRouteOptions, type DetachedTurnFinal, type DetachedTurnOptions, type DetachedTurnParts, type DetachedTurnResult, type DispatchPartsOutcome, type DraftPersistenceTuning, type DraftStoredMessage, type FilePartPromotionOutcome, type ModelFailoverStreamHandle, type ModelFailoverStreamOptions, type ModelFallbackInfo, type OpenModelStream, PROMOTE_MAX_FILE_BYTES, type PromoteAgentFilePartOptions, type PromoteFilePartResult, PromptInputPart, type RawAgentFilePart, type ReadAttachmentFn, type ReadSandboxMentionFn, type ResolveChatAttachmentsOptions, type ResolveChatAttachmentsResult, type SandboxChatProducerOptions, type SandboxUploadSink, UPLOAD_INLINE_MAX_BYTES, UPLOAD_MAX_FILE_BYTES, type UploadAuthorization, type UploadedChatFile, type WriteAttachmentFn, assistantRowIdForTurn, buildDispatchParts, bytesToBase64, classifyTerminalFailure, createAssistantDraftWriter, createAttachmentUploadRoute, createChatTurnRoutes, createSandboxChatProducer, createUploadRoute, defaultValidateAttachmentPath, isCommittingSandboxEvent, isDraftContentEvent, promoteAgentFilePart, resolveChatAttachments, rowIdOf, runDetachedTurn, sanitizeUploadFilename, sniffMimeFromName, storeSupportsDraftPersistence, streamWithModelFailover, withDurableChatProjection };
|
|
1613
|
+
export { type AssistantDraftSnapshot, type AssistantDraftStore, type AssistantDraftWriter, type AssistantDraftWriterOptions, type AssistantRowValues, type AttachmentPathArgs, type AttachmentPathCheck, type AttachmentReadResult, type AttachmentUploadAuthorization, type AttachmentWriteResult, type BuildDispatchPartsInput, ChatAttachmentKind, type ChatRouteDurableProjection, type ChatRouteDurableProjectionLogger, type ChatRouteEvent, type ChatTurnAuthorization, type ChatTurnAuthorizeArgs, type ChatTurnCompleteInput, ChatTurnFilePartInput, type ChatTurnGateResult, type ChatTurnHeartbeat, type ChatTurnInputPatch, type ChatTurnLifecycle, type ChatTurnLifecycleComplete, type ChatTurnLifecycleError, type ChatTurnLifecycleStart, type ChatTurnLock, type ChatTurnLockResult, type ChatTurnMessageStore, type ChatTurnModelFailover, ChatTurnPartInput, type ChatTurnProduceArgs, ChatTurnRequestPayload, type ChatTurnRouteProducer, type ChatTurnRoutes, type ChatTurnUsage, type CreateAttachmentUploadRouteOptions, type CreateChatTurnRoutesOptions, type CreateUploadRouteOptions, type DetachedTurnFinal, type DetachedTurnOptions, type DetachedTurnParts, type DetachedTurnResult, type DispatchPartsOutcome, type DraftPersistenceTuning, type DraftStoredMessage, type FilePartPromotionOutcome, type ModelFailoverStreamHandle, type ModelFailoverStreamOptions, type ModelFallbackInfo, type OpenModelStream, PROMOTE_MAX_FILE_BYTES, type PromoteAgentFilePartOptions, type PromoteFilePartResult, PromptInputPart, type RawAgentFilePart, type ReadAttachmentFn, type ReadSandboxMentionFn, type ResolveChatAttachmentsOptions, type ResolveChatAttachmentsResult, type SandboxChatProducerOptions, type SandboxUploadSink, UPLOAD_INLINE_MAX_BYTES, UPLOAD_MAX_FILE_BYTES, type UploadAuthorization, type UploadedChatFile, type WriteAttachmentFn, assistantRowIdForTurn, buildDispatchParts, bytesToBase64, classifyTerminalFailure, createAssistantDraftWriter, createAttachmentUploadRoute, createChatTurnRoutes, createSandboxChatProducer, createUploadRoute, defaultValidateAttachmentPath, isCommittingSandboxEvent, isDraftContentEvent, promoteAgentFilePart, resolveChatAttachments, rowIdOf, runDetachedTurn, sanitizeUploadFilename, sniffMimeFromName, storeSupportsDraftPersistence, streamWithModelFailover, withDurableChatProjection };
|