@pluno/product-agent-web 0.1.229 → 0.1.232
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/dist/adapters/web/backendHttp.d.ts +16 -2
- package/dist/adapters/web/backendTransport.d.ts +3 -0
- package/dist/adapters/web/conversationAdapters.d.ts +59 -0
- package/dist/adapters/web/conversationCheckpoint.d.ts +16 -0
- package/dist/adapters/web/conversationInteractionAdapter.d.ts +11 -0
- package/dist/adapters/web/conversationPresentation.d.ts +4 -0
- package/dist/adapters/web/directoryAdapters.d.ts +2 -2
- package/dist/adapters/web/socketIOTransport.d.ts +4 -0
- package/dist/chatPresentation.d.ts +7 -0
- package/dist/core/conversation/contracts.d.ts +181 -1
- package/dist/core/conversation/delivery.d.ts +22 -0
- package/dist/core/conversation/deliveryContracts.d.ts +100 -0
- package/dist/core/conversation/display.d.ts +134 -0
- package/dist/core/conversation/reducer.d.ts +8 -0
- package/dist/core/conversation/selectors.d.ts +59 -0
- package/dist/core/conversation/state.d.ts +6 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/model-selection/commands.d.ts +1 -1
- package/dist/displayedErrors.d.ts +1 -1
- package/dist/entrySurface.d.ts +2 -0
- package/dist/index.d.ts +51 -117
- package/dist/interactionManager.d.ts +3 -0
- package/dist/interruptState.d.ts +1 -1
- package/dist/operationTiming.d.ts +21 -0
- package/dist/product-agent-runtime.cjs +1 -1
- package/dist/product-agent-runtime.js +578 -375
- package/dist/product-agent-sdk.js +4195 -4637
- package/dist/product-agent-widget.js +8748 -9160
- package/dist/protocolTrace.d.ts +3 -0
- package/dist/public/operationRoutes.d.ts +2 -0
- package/dist/renderDiagnostics.d.ts +31 -0
- package/dist/responseDiagnostics.d.ts +1 -0
- package/dist/runtime/composition.d.ts +13 -5
- package/dist/runtime/modelSelection.d.ts +1 -1
- package/dist/runtime.d.ts +2 -2
- package/dist/runtimeClient.d.ts +20 -6
- package/dist/runtimeState.d.ts +15 -0
- package/dist/shareCard.d.ts +1 -0
- package/dist/uiFlightRecorder.d.ts +4 -1
- package/dist/uiInvariants.d.ts +2 -0
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { createOperationTimer } from "../../operationTiming";
|
|
2
|
+
import { ProductAgentSocketError, type ProductAgentSocketAuth } from './socketIOTransport';
|
|
2
3
|
export declare class ProductAgentHttpTransport {
|
|
3
4
|
private readonly options;
|
|
4
5
|
private readonly requests;
|
|
@@ -6,7 +7,20 @@ export declare class ProductAgentHttpTransport {
|
|
|
6
7
|
constructor(options: {
|
|
7
8
|
backendUrl: string;
|
|
8
9
|
auth: ProductAgentSocketAuth;
|
|
10
|
+
authority?: () => string;
|
|
11
|
+
authenticationFailure?: () => ProductAgentSocketError | null;
|
|
12
|
+
pendingAuthentication?: () => Promise<void> | null;
|
|
13
|
+
recoverAuthentication?: (token: string, error: ProductAgentSocketError, retryAllowed: boolean) => Promise<void>;
|
|
14
|
+
executorConnection?: () => string | null;
|
|
15
|
+
restoreExecutor?: (connectionId: string) => Promise<void>;
|
|
9
16
|
});
|
|
10
17
|
dispose(): void;
|
|
11
|
-
|
|
18
|
+
resolveUrl(path: string): URL;
|
|
19
|
+
request<T = unknown>(path: string, params?: Record<string, unknown>, body?: unknown, method?: string, namespace?: 'runtime' | 'extension' | 'embed' | 'conversations', recovery?: {
|
|
20
|
+
readOnly?: boolean;
|
|
21
|
+
timing?: ReturnType<typeof createOperationTimer>;
|
|
22
|
+
skipAuthentication?: boolean;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
}): Promise<T>;
|
|
25
|
+
private requestOnce;
|
|
12
26
|
}
|
|
@@ -10,6 +10,7 @@ type Options = {
|
|
|
10
10
|
currentSession: (page?: Record<string, any>) => string | null;
|
|
11
11
|
contextKey?: (event: WireEvent) => string;
|
|
12
12
|
sessionReferences: () => readonly string[];
|
|
13
|
+
displaySchema?: "legacy" | "canonical";
|
|
13
14
|
entrySurface?: string;
|
|
14
15
|
};
|
|
15
16
|
export declare class ProductAgentBackendTransport extends EventTarget {
|
|
@@ -40,6 +41,8 @@ export declare class ProductAgentBackendTransport extends EventTarget {
|
|
|
40
41
|
initialReadinessExpired: boolean;
|
|
41
42
|
constructor(options: Options);
|
|
42
43
|
get directoryRooms(): Pick<ProductAgentSocketIOTransport, 'retain' | 'release'>;
|
|
44
|
+
get connectionId(): string | null;
|
|
45
|
+
restoreExecutor(connectionId: string): Promise<void>;
|
|
43
46
|
get connectionAttempt(): import("./socketIOTransport").ProductAgentConnectionAttempt | null;
|
|
44
47
|
retryReadiness(): void;
|
|
45
48
|
private startInitialReadinessBudget;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type OperationTiming } from "../../operationTiming";
|
|
2
|
+
import type { ProductAgentPrepareAttachmentUploadInput, ProductAgentAttachmentUpload } from "../../index";
|
|
3
|
+
import type { PAConversationPorts, PAConversationSnapshotLane } from "../../core/conversation/contracts";
|
|
4
|
+
import type { PAUploadedAttachment, PAConversationDeliveryCheckpoint, PAConversationWireCommand } from "../../core/conversation/deliveryContracts";
|
|
5
|
+
import type { PAConversationDisplayEvent } from "../../core/conversation/display";
|
|
6
|
+
import type { PADirectoryAuthority } from "../../core/session-directory/contracts";
|
|
7
|
+
import type { PASessionId } from "../../core/kernel/state";
|
|
8
|
+
import type { PAClientRuntime } from "../../runtime/composition";
|
|
9
|
+
import { ProductAgentHttpTransport } from "./backendHttp";
|
|
10
|
+
import type { ProductAgentSocketIOTransport } from "./socketIOTransport";
|
|
11
|
+
type Boundary = {
|
|
12
|
+
authority: PADirectoryAuthority;
|
|
13
|
+
runtime: () => PAClientRuntime;
|
|
14
|
+
isCurrent?: () => boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare function createConversationPorts(options: Boundary & {
|
|
17
|
+
http: ProductAgentHttpTransport;
|
|
18
|
+
connectionId: () => string | null;
|
|
19
|
+
readAttachment: (sourceId: string) => Promise<Blob>;
|
|
20
|
+
saveDelivery: (checkpoint: PAConversationDeliveryCheckpoint) => Promise<void>;
|
|
21
|
+
onError?: (error: unknown) => void;
|
|
22
|
+
onCommand?: (command: PAConversationWireCommand) => void;
|
|
23
|
+
onTiming?: (timing: OperationTiming) => void;
|
|
24
|
+
now: () => number;
|
|
25
|
+
onUploaded?: (sourceId: string, sessionId: string, attachment: PAUploadedAttachment) => Promise<void>;
|
|
26
|
+
prepareUpload?: (input: ProductAgentPrepareAttachmentUploadInput) => Promise<ProductAgentAttachmentUpload>;
|
|
27
|
+
persistUpload?: (input: ProductAgentPrepareAttachmentUploadInput, bytes: File) => Promise<Pick<ProductAgentAttachmentUpload, "sessionId" | "attachment">>;
|
|
28
|
+
}): Omit<PAConversationPorts, "conversation.interactions">;
|
|
29
|
+
export declare class ProductAgentConversationObservationAdapter {
|
|
30
|
+
private readonly options;
|
|
31
|
+
private readonly observations;
|
|
32
|
+
private readonly waiters;
|
|
33
|
+
private readonly unsubscribe;
|
|
34
|
+
private readonly unsubscribeDispose;
|
|
35
|
+
private disposed;
|
|
36
|
+
private readonly owner;
|
|
37
|
+
private readonly deliveryRecovery;
|
|
38
|
+
constructor(options: Boundary & {
|
|
39
|
+
socket: Pick<ProductAgentSocketIOTransport, "retain" | "release">;
|
|
40
|
+
nextRequestId: () => string;
|
|
41
|
+
now: () => number;
|
|
42
|
+
wakeup: {
|
|
43
|
+
start: () => void;
|
|
44
|
+
stop: () => void;
|
|
45
|
+
};
|
|
46
|
+
onError: (error: unknown) => void;
|
|
47
|
+
enabled?: () => boolean;
|
|
48
|
+
});
|
|
49
|
+
private reconcile;
|
|
50
|
+
refresh(sessionId: PASessionId, lane?: PAConversationSnapshotLane): Promise<void>;
|
|
51
|
+
receive(event: PAConversationDisplayEvent): void;
|
|
52
|
+
wake(): void;
|
|
53
|
+
private report;
|
|
54
|
+
private hasUncertainDelivery;
|
|
55
|
+
private hasRunningDelivery;
|
|
56
|
+
private waitForDelivery;
|
|
57
|
+
dispose(): void;
|
|
58
|
+
}
|
|
59
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PAConversationState, PAOwnedSubmission } from "../../core/conversation/contracts";
|
|
2
|
+
import type { PAConversationDeliveryCheckpoint, PAConversationWireCommand } from "../../core/conversation/deliveryContracts";
|
|
3
|
+
import type { PAClientScopeId, PAConversationScopeId, PASessionId, PAViewId } from "../../core/kernel/state";
|
|
4
|
+
import type { PAProductAgentModel } from "../../core/model-selection/contracts";
|
|
5
|
+
export declare function importLegacyConversationSubmissions(state: PAConversationState, inputs: readonly Readonly<{
|
|
6
|
+
command: PAConversationWireCommand;
|
|
7
|
+
requestedModel: PAProductAgentModel | null;
|
|
8
|
+
clientScopeId: PAClientScopeId;
|
|
9
|
+
conversationScopeId: PAConversationScopeId;
|
|
10
|
+
viewId: PAViewId;
|
|
11
|
+
sessionId: PASessionId | null;
|
|
12
|
+
entrySurface: PAOwnedSubmission["entrySurface"];
|
|
13
|
+
submittedAt: number;
|
|
14
|
+
}>[]): PAConversationDeliveryCheckpoint;
|
|
15
|
+
export declare function readConversationStorage(key: string): string | null;
|
|
16
|
+
export declare function rememberConversationAuthority(clientId: string, authorityId: string): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PAConversationPorts } from "../../core/conversation/contracts";
|
|
2
|
+
import type { PADirectoryAuthority } from "../../core/session-directory/contracts";
|
|
3
|
+
import type { ProductAgentInteractionManager } from "../../interactionManager";
|
|
4
|
+
import type { PAClientRuntime } from "../../runtime/composition";
|
|
5
|
+
export declare function createConversationInteractionPort(options: {
|
|
6
|
+
authority: PADirectoryAuthority;
|
|
7
|
+
runtime: () => PAClientRuntime;
|
|
8
|
+
manager: ProductAgentInteractionManager;
|
|
9
|
+
invalidateAuth: (requestId: string) => void;
|
|
10
|
+
notify: () => void;
|
|
11
|
+
}): PAConversationPorts["conversation.interactions"];
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ProductAgentState } from "../../index";
|
|
2
|
+
import type { PAConversationProjection, PAConversationRecord } from "../../core/conversation/contracts";
|
|
3
|
+
export type PAConversationPresentation = Pick<ProductAgentState, "historyPreparation" | "selectionKey" | "isDraftSession" | "sessionId" | "messages" | "removedItems" | "activeScheduledFollowUps" | "isLoadingSession" | "assistantDraft" | "assistantDraftItemId" | "assistantDraftPhase" | "assistantDraftRespondsToUserMessageId" | "assistantDraftRunId" | "activeResponseUserMessageId" | "pendingMessageStatus" | "turnPhase" | "isThinking" | "taskStatus" | "lastError" | "lastErrorCode" | "lastErrorSecuritySettingsUrl"> & Required<Pick<ProductAgentState, "segments" | "activity" | "receipts">>;
|
|
4
|
+
export declare function projectConversationPresentation(projection: PAConversationProjection, query: PAConversationRecord["queries"]["current"] | undefined, backendUrl: string): PAConversationPresentation;
|
|
@@ -52,8 +52,8 @@ export declare class ProductAgentDirectoryObservationAdapter {
|
|
|
52
52
|
runtime: PAClientRuntime;
|
|
53
53
|
authority: PADirectoryAuthority;
|
|
54
54
|
http: ProductAgentHttpTransport;
|
|
55
|
-
socket
|
|
56
|
-
recovery
|
|
55
|
+
socket?: Pick<ProductAgentSocketIOTransport, 'retain' | 'release'>;
|
|
56
|
+
recovery?: (sessionId: string) => PADirectoryRecoveryHandles;
|
|
57
57
|
isActiveTurn: (sessionId: string) => boolean;
|
|
58
58
|
nextRequestId: () => string;
|
|
59
59
|
onError: (error: unknown) => void;
|
|
@@ -34,6 +34,7 @@ type Options = {
|
|
|
34
34
|
onError: (error: ProductAgentSocketError) => void;
|
|
35
35
|
requestTimeoutMs?: number;
|
|
36
36
|
reconnect?: boolean;
|
|
37
|
+
displaySchema?: "legacy" | "canonical";
|
|
37
38
|
bootstrapRequired?: boolean;
|
|
38
39
|
onAttempt?: (attempt: ProductAgentConnectionAttempt) => void;
|
|
39
40
|
};
|
|
@@ -61,12 +62,15 @@ export declare class ProductAgentSocketIOTransport {
|
|
|
61
62
|
private operations;
|
|
62
63
|
private queuedOperations;
|
|
63
64
|
private uploadingResult;
|
|
65
|
+
private executorRecovery;
|
|
64
66
|
private admissionTimer;
|
|
65
67
|
private readinessTimer;
|
|
66
68
|
private attemptCount;
|
|
67
69
|
private attempt;
|
|
68
70
|
constructor(options: Options);
|
|
69
71
|
connect(): void;
|
|
72
|
+
get connectionId(): string | null;
|
|
73
|
+
restoreExecutor(connectionId: string): Promise<void>;
|
|
70
74
|
replaceCredentials(auth: ProductAgentSocketAuth, authorityChanged: boolean): void;
|
|
71
75
|
suspend(): void;
|
|
72
76
|
disconnect(): void;
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
export declare const EMPTY_CONVERSATION_MESSAGE = "Looks like no message is sent yet";
|
|
2
2
|
export declare function getChatErrorPlacement(code: string | null | undefined): "bottom_notice" | "conversation";
|
|
3
|
+
export declare function getConversationFeedback(state: {
|
|
4
|
+
lastError?: string | null;
|
|
5
|
+
lastErrorCode?: string | null;
|
|
6
|
+
}): {
|
|
7
|
+
showProgress: boolean;
|
|
8
|
+
actions: readonly ("retry_history" | "retry_message" | "new_chat")[];
|
|
9
|
+
};
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
import type { PAClientScopeId, PARequestId, PASessionId, PAViewId } from "../kernel/state";
|
|
1
|
+
import type { PAClientScopeId, PAConversationScopeId, PARequestId, PAEffectId, PASessionId, PAViewId } from "../kernel/state";
|
|
2
2
|
import type { PAJsonObject } from "../protocol/json";
|
|
3
|
+
import type { PAEffectHandlers } from "../kernel/effects";
|
|
4
|
+
import type { PAQueryState } from "../kernel/state";
|
|
5
|
+
import type { PADirectoryAuthority } from "../session-directory/contracts";
|
|
6
|
+
import type { PAProductAgentModel } from "../model-selection/contracts";
|
|
7
|
+
import type { PATransportedError } from "../protocol/errors";
|
|
8
|
+
import type { PAConversationInteractionSource, PAConversationFollowUp, PAConversationDisplayEvent, PADisplayItem, PADisplaySnapshot, PAEntrySurface, PAExecutionState, PAInvocation, PAStreamLifecycle } from "./display";
|
|
9
|
+
import type { PAConversationDelivery, PAConversationDeliveryCommand, PAConversationDeliveryEffects, PAConversationOperation, PAUploadedAttachment } from "./deliveryContracts";
|
|
3
10
|
export type PAAttachmentSource = Readonly<{
|
|
4
11
|
sourceId: string;
|
|
5
12
|
name: string;
|
|
6
13
|
mimeType: string;
|
|
7
14
|
sizeBytes: number;
|
|
15
|
+
uploaded?: PAUploadedAttachment;
|
|
8
16
|
}>;
|
|
9
17
|
export type PARendererComposerSubmission = Readonly<{
|
|
10
18
|
viewId: PAViewId;
|
|
@@ -19,3 +27,175 @@ export type PASubmissionReceipt = Readonly<{
|
|
|
19
27
|
sessionId: PASessionId;
|
|
20
28
|
acceptedRendererRevision: number;
|
|
21
29
|
}>;
|
|
30
|
+
export type PAConversationSubmissionInput = Readonly<{
|
|
31
|
+
userMessageId: string;
|
|
32
|
+
requestId: PARequestId;
|
|
33
|
+
clientScopeId: PAClientScopeId;
|
|
34
|
+
conversationScopeId: PAConversationScopeId;
|
|
35
|
+
viewId: PAViewId;
|
|
36
|
+
rendererRevision: number;
|
|
37
|
+
content: string;
|
|
38
|
+
attachments: readonly PAAttachmentSource[];
|
|
39
|
+
context: PAJsonObject;
|
|
40
|
+
invocation: PAInvocation;
|
|
41
|
+
entrySurface: PAEntrySurface;
|
|
42
|
+
submittedAt: number;
|
|
43
|
+
}>;
|
|
44
|
+
export type PAOwnedSubmission = PAConversationSubmissionInput & Readonly<{
|
|
45
|
+
contextPreparation?: Readonly<{
|
|
46
|
+
pageContent: string;
|
|
47
|
+
sessionTabs: readonly PAJsonObject[];
|
|
48
|
+
}> | null;
|
|
49
|
+
requestedModel: PAProductAgentModel | null;
|
|
50
|
+
sessionId: PASessionId | null;
|
|
51
|
+
delivery: "staged" | "sending" | "uncertain" | "accepted" | "failed";
|
|
52
|
+
cancelled: boolean;
|
|
53
|
+
executionVersion: number | null;
|
|
54
|
+
error: PATransportedError | null;
|
|
55
|
+
}>;
|
|
56
|
+
export type PAConversationSnapshotLane = "current" | "history";
|
|
57
|
+
export type PAConversationSnapshotRequest = PADirectoryAuthority & Readonly<{
|
|
58
|
+
retryPreparation?: boolean;
|
|
59
|
+
sessionId: PASessionId;
|
|
60
|
+
requestId: PARequestId;
|
|
61
|
+
lane: PAConversationSnapshotLane;
|
|
62
|
+
before: string | null;
|
|
63
|
+
refreshItemIds: readonly string[];
|
|
64
|
+
}>;
|
|
65
|
+
export type PAConversationInteractionHandoff = PADirectoryAuthority & Readonly<{
|
|
66
|
+
sessionId: PASessionId;
|
|
67
|
+
sources: readonly PAConversationInteractionSource[];
|
|
68
|
+
}>;
|
|
69
|
+
export type PAConversationEffects = PAConversationDeliveryEffects & {
|
|
70
|
+
"conversation.interactions": {
|
|
71
|
+
input: PAConversationInteractionHandoff;
|
|
72
|
+
output: null;
|
|
73
|
+
};
|
|
74
|
+
"conversation.snapshot": {
|
|
75
|
+
input: PAConversationSnapshotRequest;
|
|
76
|
+
output: Readonly<{
|
|
77
|
+
snapshot: PADisplaySnapshot;
|
|
78
|
+
updatedAt: number;
|
|
79
|
+
}>;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
export type PAConversationPorts = PAEffectHandlers<PAConversationEffects>;
|
|
83
|
+
export type PAConversationRecord = Readonly<{
|
|
84
|
+
preparation?: "pending" | "busy" | null;
|
|
85
|
+
sessionId: PASessionId;
|
|
86
|
+
items: Readonly<Record<string, PADisplayItem>>;
|
|
87
|
+
streams: Readonly<Record<string, PAStreamLifecycle>>;
|
|
88
|
+
removedItems: Readonly<Record<string, string>>;
|
|
89
|
+
execution: PAExecutionState | null;
|
|
90
|
+
executionByUserMessage: Readonly<Record<string, Pick<PAExecutionState, "version" | "phase">>>;
|
|
91
|
+
followUps: readonly PAConversationFollowUp[];
|
|
92
|
+
followUpsVersion: number;
|
|
93
|
+
queries: Readonly<Record<PAConversationSnapshotLane, PAQueryState<string, readonly string[]>>>;
|
|
94
|
+
}>;
|
|
95
|
+
export type PAConversationStopReason = "user_requested" | "new_chat" | "session_switch" | "task_tab_closed" | "flow_reset" | "delegated_task_cancelled" | "sdk_session_reset" | "security_policy_changed";
|
|
96
|
+
export type PAConversationStop = Readonly<{
|
|
97
|
+
requestId: PARequestId;
|
|
98
|
+
userMessageIds: readonly string[];
|
|
99
|
+
executionVersion: number;
|
|
100
|
+
reason?: PAConversationStopReason;
|
|
101
|
+
}>;
|
|
102
|
+
export type PAConversationState = PADirectoryAuthority & Readonly<{
|
|
103
|
+
sessions: Readonly<Record<string, PAConversationRecord>>;
|
|
104
|
+
proactiveQuestions: Readonly<Record<string, Readonly<{
|
|
105
|
+
id: string;
|
|
106
|
+
content: string;
|
|
107
|
+
}>>>;
|
|
108
|
+
submissions: Readonly<Record<string, PAOwnedSubmission>>;
|
|
109
|
+
submissionOrder: readonly string[];
|
|
110
|
+
stops: Readonly<Record<string, PAConversationStop>>;
|
|
111
|
+
requests: Readonly<Record<string, PAConversationSnapshotRequest & Readonly<{
|
|
112
|
+
acceptedUserMessageIds: readonly string[];
|
|
113
|
+
}>>>;
|
|
114
|
+
requestSequence: number;
|
|
115
|
+
deliveries: Readonly<Record<string, PAConversationDelivery>>;
|
|
116
|
+
effectsEnabled: boolean;
|
|
117
|
+
checkpointEffectId: PAEffectId | null;
|
|
118
|
+
checkpointError: PATransportedError | null;
|
|
119
|
+
operations: Readonly<Record<string, PAConversationOperation>>;
|
|
120
|
+
}>;
|
|
121
|
+
export type PAConversationCommand = PAConversationDeliveryCommand | PADirectoryAuthority & ((PAConversationSubmissionInput & Readonly<{
|
|
122
|
+
type: "conversation.submission_stage";
|
|
123
|
+
prepareContext?: boolean;
|
|
124
|
+
}>) | Readonly<{
|
|
125
|
+
type: "conversation.context_prepared";
|
|
126
|
+
userMessageId: string;
|
|
127
|
+
pageContent: string;
|
|
128
|
+
sessionTabs: readonly PAJsonObject[];
|
|
129
|
+
}> | Readonly<{
|
|
130
|
+
type: "conversation.proactive_edit";
|
|
131
|
+
conversationScopeId: PAConversationScopeId;
|
|
132
|
+
id: string;
|
|
133
|
+
content: string;
|
|
134
|
+
}> | Readonly<{
|
|
135
|
+
type: "conversation.stop";
|
|
136
|
+
clientScopeId: PAClientScopeId;
|
|
137
|
+
conversationScopeId: PAConversationScopeId;
|
|
138
|
+
requestId: PARequestId;
|
|
139
|
+
reason?: PAConversationStopReason;
|
|
140
|
+
userMessageIds?: readonly string[];
|
|
141
|
+
}> | Readonly<{
|
|
142
|
+
type: "conversation.observation_released";
|
|
143
|
+
sessionId: PASessionId;
|
|
144
|
+
}> | Readonly<{
|
|
145
|
+
type: "conversation.snapshot";
|
|
146
|
+
sessionId: PASessionId;
|
|
147
|
+
requestId: PARequestId;
|
|
148
|
+
lane: PAConversationSnapshotLane;
|
|
149
|
+
}>);
|
|
150
|
+
export type PAConversationEvent = PADirectoryAuthority & (Readonly<{
|
|
151
|
+
type: "conversation.submission_accepted";
|
|
152
|
+
userMessageId: string;
|
|
153
|
+
sessionId: PASessionId;
|
|
154
|
+
}> | Readonly<{
|
|
155
|
+
type: "conversation.submission_delivery";
|
|
156
|
+
userMessageId: string;
|
|
157
|
+
requestId: PARequestId;
|
|
158
|
+
delivery: "sending" | "uncertain" | "failed";
|
|
159
|
+
error: PATransportedError | null;
|
|
160
|
+
}> | Readonly<{
|
|
161
|
+
type: "conversation.display_received";
|
|
162
|
+
event: PAConversationDisplayEvent;
|
|
163
|
+
}>);
|
|
164
|
+
export type PAConversationSegment = Readonly<{
|
|
165
|
+
id: string;
|
|
166
|
+
userMessageId: string | null;
|
|
167
|
+
activityIds: readonly string[];
|
|
168
|
+
outcomeIds: readonly string[];
|
|
169
|
+
collapsed: boolean;
|
|
170
|
+
}>;
|
|
171
|
+
export type PAConversationProjection = Readonly<{
|
|
172
|
+
preparation?: "pending" | "busy" | null;
|
|
173
|
+
selectionKey?: string;
|
|
174
|
+
isDraftSession: boolean;
|
|
175
|
+
proactiveQuestion: Readonly<{
|
|
176
|
+
id: string;
|
|
177
|
+
content: string;
|
|
178
|
+
}> | null;
|
|
179
|
+
followUps: readonly PAConversationFollowUp[];
|
|
180
|
+
sessionId: PASessionId | null;
|
|
181
|
+
submissions: readonly PAOwnedSubmission[];
|
|
182
|
+
deliveries: Readonly<Record<string, PAConversationDelivery>>;
|
|
183
|
+
items: readonly PADisplayItem[];
|
|
184
|
+
optimistic: readonly PAOwnedSubmission[];
|
|
185
|
+
removedItems: Readonly<Record<string, string>>;
|
|
186
|
+
streamStates: Readonly<Record<string, PAStreamLifecycle["state"] | "awaiting_content">>;
|
|
187
|
+
stop: (PAConversationStop & Readonly<{
|
|
188
|
+
pending: boolean;
|
|
189
|
+
}>) | null;
|
|
190
|
+
segments: readonly PAConversationSegment[];
|
|
191
|
+
activity: Readonly<{
|
|
192
|
+
phase: PAExecutionState["phase"] | "submitting" | "awaiting_execution";
|
|
193
|
+
activeItemId: string | null;
|
|
194
|
+
userMessageId?: string | null;
|
|
195
|
+
}>;
|
|
196
|
+
receipts: readonly Readonly<{
|
|
197
|
+
viewId: PAViewId;
|
|
198
|
+
userMessageId: string;
|
|
199
|
+
acceptedRendererRevision: number;
|
|
200
|
+
}>[];
|
|
201
|
+
}>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PAEffect, PAEffectResultEvent } from "../kernel/effects";
|
|
2
|
+
import type { PAModelSelectionState } from "../model-selection/state";
|
|
3
|
+
import type { PADirectoryState } from "../session-directory/contracts";
|
|
4
|
+
import type { PAConversationCommand, PAConversationEffects, PAConversationEvent, PAConversationState } from "./contracts";
|
|
5
|
+
import type { PAConversationDeliveryCheckpoint, PAConversationOperation } from "./deliveryContracts";
|
|
6
|
+
type Input = PAConversationCommand | PAConversationEvent | PAEffectResultEvent<PAConversationEffects>;
|
|
7
|
+
export declare function conversationDeliveryCheckpoint(state: PAConversationState, directory: PADirectoryState): PAConversationDeliveryCheckpoint;
|
|
8
|
+
export declare function canAutomaticallyReplayOperation(op: PAConversationOperation): boolean;
|
|
9
|
+
export declare function needsConversationDeliveryRecovery(state: PAConversationState, id: string): boolean;
|
|
10
|
+
export declare function checkpointConversationChange(previous: PAConversationState, state: PAConversationState, directory: PADirectoryState, retry?: boolean): {
|
|
11
|
+
state: PAConversationState;
|
|
12
|
+
effects: PAEffect<PAConversationEffects>[];
|
|
13
|
+
};
|
|
14
|
+
export declare function scheduleConversationDelivery(state: PAConversationState): {
|
|
15
|
+
state: PAConversationState;
|
|
16
|
+
effects: PAEffect<PAConversationEffects>[];
|
|
17
|
+
};
|
|
18
|
+
export declare function reduceConversationWithDelivery(state: PAConversationState, input: Input, directory: PADirectoryState, models: PAModelSelectionState): {
|
|
19
|
+
state: PAConversationState;
|
|
20
|
+
effects: PAEffect<PAConversationEffects>[];
|
|
21
|
+
};
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { PAConversationScopeId, PAEffectId, PARequestId, PASessionId } from "../kernel/state";
|
|
2
|
+
import type { PAJsonObject, PAJsonValue } from "../protocol/json";
|
|
3
|
+
import type { PATransportedError } from "../protocol/errors";
|
|
4
|
+
import type { PADirectoryAuthority } from "../session-directory/contracts";
|
|
5
|
+
import type { PAAttachmentSource, PAOwnedSubmission, PAConversationState } from "./contracts";
|
|
6
|
+
export type PAUploadedAttachment = Readonly<{
|
|
7
|
+
id: string | null;
|
|
8
|
+
name: string;
|
|
9
|
+
mime_type: string;
|
|
10
|
+
size_bytes: number;
|
|
11
|
+
storage_key?: string | null;
|
|
12
|
+
sandbox_path?: string | null;
|
|
13
|
+
file_url?: string | null;
|
|
14
|
+
}>;
|
|
15
|
+
export type PAConversationWireCommand = Readonly<{
|
|
16
|
+
request_id: string;
|
|
17
|
+
type: "chat.user_message" | "chat.retry_last_user_message" | "run.stop" | "attachment.upload_completed" | "runtime.warmup" | "session.reset";
|
|
18
|
+
payload: PAJsonObject;
|
|
19
|
+
}>;
|
|
20
|
+
export type PAConversationDelivery = Readonly<{
|
|
21
|
+
phase: "waiting" | "running" | "uncertain" | "paused" | "failed" | "done";
|
|
22
|
+
recoveryDeadline: number | null;
|
|
23
|
+
step: "upload" | "complete" | "send" | "receipt" | null;
|
|
24
|
+
effectId: PAEffectId | null;
|
|
25
|
+
uploads: readonly PAUploadedAttachment[];
|
|
26
|
+
completedUploads: number;
|
|
27
|
+
command: PAConversationWireCommand | null;
|
|
28
|
+
}>;
|
|
29
|
+
export type PAConversationOperationCommand = PAConversationWireCommand | Readonly<{
|
|
30
|
+
request_id: string;
|
|
31
|
+
type: "attachment.prepare";
|
|
32
|
+
payload: PAJsonObject;
|
|
33
|
+
}>;
|
|
34
|
+
export type PAConversationOperation = Readonly<{
|
|
35
|
+
conversationScopeId: PAConversationScopeId | null;
|
|
36
|
+
command: PAConversationOperationCommand;
|
|
37
|
+
phase: "waiting" | "running" | "uncertain" | "failed" | "done";
|
|
38
|
+
effectId: PAEffectId | null;
|
|
39
|
+
result: PAJsonValue;
|
|
40
|
+
error: PATransportedError | null;
|
|
41
|
+
}>;
|
|
42
|
+
export type PAConversationDeliveryEffects = {
|
|
43
|
+
"conversation.checkpoint": {
|
|
44
|
+
input: PADirectoryAuthority & Readonly<{
|
|
45
|
+
checkpoint: PAConversationDeliveryCheckpoint;
|
|
46
|
+
}>;
|
|
47
|
+
output: null;
|
|
48
|
+
};
|
|
49
|
+
"conversation.receipt": {
|
|
50
|
+
input: PADirectoryAuthority & Readonly<{
|
|
51
|
+
userMessageId: string;
|
|
52
|
+
sessionId: PASessionId | null;
|
|
53
|
+
}>;
|
|
54
|
+
output: Readonly<{
|
|
55
|
+
sessionId: PASessionId;
|
|
56
|
+
clientMessageId: string;
|
|
57
|
+
}> | null;
|
|
58
|
+
};
|
|
59
|
+
"conversation.upload": {
|
|
60
|
+
input: PADirectoryAuthority & Readonly<{
|
|
61
|
+
submission: Pick<PAOwnedSubmission, "userMessageId" | "conversationScopeId" | "sessionId" | "context" | "requestedModel" | "entrySurface">;
|
|
62
|
+
source: PAAttachmentSource;
|
|
63
|
+
preparationId?: string;
|
|
64
|
+
}>;
|
|
65
|
+
output: Readonly<{
|
|
66
|
+
sessionId: PASessionId;
|
|
67
|
+
attachment: PAUploadedAttachment;
|
|
68
|
+
}>;
|
|
69
|
+
};
|
|
70
|
+
"conversation.command": {
|
|
71
|
+
input: PADirectoryAuthority & Readonly<{
|
|
72
|
+
command: PAConversationWireCommand;
|
|
73
|
+
}>;
|
|
74
|
+
output: PAJsonValue;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
export type PAConversationDeliveryCommand = PADirectoryAuthority & (Readonly<{
|
|
78
|
+
type: "conversation.enable_effects";
|
|
79
|
+
}> | Readonly<{
|
|
80
|
+
type: "conversation.recover";
|
|
81
|
+
now: number;
|
|
82
|
+
}> | Readonly<{
|
|
83
|
+
type: "conversation.restore_delivery";
|
|
84
|
+
checkpoint: PAConversationDeliveryCheckpoint;
|
|
85
|
+
}> | Readonly<{
|
|
86
|
+
type: "conversation.submit";
|
|
87
|
+
userMessageId: string;
|
|
88
|
+
now: number;
|
|
89
|
+
manualRetry?: true;
|
|
90
|
+
}> | Readonly<{
|
|
91
|
+
type: "conversation.operation";
|
|
92
|
+
command: PAConversationOperationCommand;
|
|
93
|
+
conversationScopeId?: PAConversationScopeId;
|
|
94
|
+
}> | Readonly<{
|
|
95
|
+
type: "conversation.retry_operation";
|
|
96
|
+
requestId: PARequestId;
|
|
97
|
+
}>);
|
|
98
|
+
export type PAConversationDeliveryCheckpoint = Readonly<{
|
|
99
|
+
schema: 1;
|
|
100
|
+
}> & Pick<PAConversationState, "authorityId" | "submissions" | "submissionOrder" | "deliveries" | "operations" | "stops" | "requestSequence">;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
export type PAInvocation = "user" | "automation" | "scheduled_continuation" | "private_continuation";
|
|
2
|
+
export type PAEntrySurface = "extension_sidepanel" | "extension_widget" | "main_web_chat" | "whatsapp" | "automation" | "mcp" | "embedded_widget" | "embedded_custom_ui";
|
|
3
|
+
export type PADisplayAttachment = Readonly<{
|
|
4
|
+
id: string | null;
|
|
5
|
+
name: string;
|
|
6
|
+
mime_type: string;
|
|
7
|
+
size_bytes: number;
|
|
8
|
+
file_url: string | null;
|
|
9
|
+
}>;
|
|
10
|
+
type PAItemShell = Readonly<{
|
|
11
|
+
id: string;
|
|
12
|
+
conversation_id: string;
|
|
13
|
+
created_at: string;
|
|
14
|
+
updated_at: string;
|
|
15
|
+
}>;
|
|
16
|
+
type PAStreamContent = Readonly<{
|
|
17
|
+
content: string;
|
|
18
|
+
revision: number;
|
|
19
|
+
}>;
|
|
20
|
+
export type PADisplayItem = PAItemShell & (Readonly<{
|
|
21
|
+
type: "user_message";
|
|
22
|
+
data: Readonly<{
|
|
23
|
+
content: string;
|
|
24
|
+
attachments: readonly PADisplayAttachment[];
|
|
25
|
+
invocation: PAInvocation;
|
|
26
|
+
entry_surface: PAEntrySurface;
|
|
27
|
+
}>;
|
|
28
|
+
}> | Readonly<{
|
|
29
|
+
type: "commentary" | "tool_summary";
|
|
30
|
+
data: PAStreamContent;
|
|
31
|
+
}> | Readonly<{
|
|
32
|
+
type: "final_response";
|
|
33
|
+
data: PAStreamContent & Readonly<{
|
|
34
|
+
attachments: readonly PADisplayAttachment[];
|
|
35
|
+
}>;
|
|
36
|
+
}> | Readonly<{
|
|
37
|
+
type: "error";
|
|
38
|
+
data: Readonly<{
|
|
39
|
+
code: string;
|
|
40
|
+
message: string;
|
|
41
|
+
security_settings_url?: string | null;
|
|
42
|
+
}>;
|
|
43
|
+
}> | Readonly<{
|
|
44
|
+
type: "stopped";
|
|
45
|
+
data: Readonly<{
|
|
46
|
+
message: string;
|
|
47
|
+
}>;
|
|
48
|
+
}>);
|
|
49
|
+
export type PAStreamLifecycle = Readonly<{
|
|
50
|
+
item_id: string;
|
|
51
|
+
revision: number;
|
|
52
|
+
state: "open" | "finished" | "stopped" | "failed";
|
|
53
|
+
}>;
|
|
54
|
+
export type PAItemRemoval = Readonly<{
|
|
55
|
+
type: "conversation.item.removed";
|
|
56
|
+
conversation_id: string;
|
|
57
|
+
item_id: string;
|
|
58
|
+
replacement_item_id: string;
|
|
59
|
+
}>;
|
|
60
|
+
export type PAExecutionState = Readonly<{
|
|
61
|
+
conversation_id: string;
|
|
62
|
+
version: number;
|
|
63
|
+
phase: "idle" | "queued" | "thinking" | "steering" | "stopping" | "completed" | "stopped" | "failed";
|
|
64
|
+
user_message_ids: readonly string[];
|
|
65
|
+
execution_message_ids?: readonly string[];
|
|
66
|
+
}>;
|
|
67
|
+
export declare function executionMessageIds(execution: PAExecutionState | null | undefined): readonly string[];
|
|
68
|
+
export type PAConversationInteractionSource = Readonly<{
|
|
69
|
+
id: string;
|
|
70
|
+
conversation_id: string;
|
|
71
|
+
version: number;
|
|
72
|
+
lifecycle: "pending" | "completed" | "cancelled" | "expired";
|
|
73
|
+
user_message_id: string | null;
|
|
74
|
+
scope: "conversation";
|
|
75
|
+
invocation: PAInvocation | null;
|
|
76
|
+
entry_surface: PAEntrySurface | null;
|
|
77
|
+
payload: Readonly<{
|
|
78
|
+
kind: "sharing";
|
|
79
|
+
eligible: boolean;
|
|
80
|
+
variant: "social" | "referral";
|
|
81
|
+
wait_for_terminal: boolean;
|
|
82
|
+
decision_scope: "client";
|
|
83
|
+
}> | Readonly<{
|
|
84
|
+
kind: "integration_auth";
|
|
85
|
+
request_id: string;
|
|
86
|
+
app_slug: string;
|
|
87
|
+
app_name: string;
|
|
88
|
+
app_logo: string | null;
|
|
89
|
+
expires_at: string;
|
|
90
|
+
}> | Readonly<{
|
|
91
|
+
kind: "personal_channel";
|
|
92
|
+
request_id: string;
|
|
93
|
+
channel: "whatsapp";
|
|
94
|
+
management_url: string;
|
|
95
|
+
}>;
|
|
96
|
+
}>;
|
|
97
|
+
export type PAConversationFollowUp = Readonly<{
|
|
98
|
+
task_id: string;
|
|
99
|
+
due_at: string;
|
|
100
|
+
}>;
|
|
101
|
+
export type PADisplaySnapshot = Readonly<{
|
|
102
|
+
conversation_id: string;
|
|
103
|
+
items: readonly PADisplayItem[];
|
|
104
|
+
removed_items: readonly PAItemRemoval[];
|
|
105
|
+
streams: readonly PAStreamLifecycle[];
|
|
106
|
+
execution: PAExecutionState;
|
|
107
|
+
interactions: readonly PAConversationInteractionSource[];
|
|
108
|
+
follow_ups: readonly PAConversationFollowUp[];
|
|
109
|
+
follow_ups_version: number;
|
|
110
|
+
next_cursor: string | null;
|
|
111
|
+
projection_ready: boolean;
|
|
112
|
+
preparation?: "pending" | "busy" | "failed" | "disabled" | null;
|
|
113
|
+
}>;
|
|
114
|
+
export type PAConversationDisplayEvent = Readonly<{
|
|
115
|
+
type: "conversation.interaction.updated";
|
|
116
|
+
interaction: PAConversationInteractionSource;
|
|
117
|
+
}> | Readonly<{
|
|
118
|
+
type: "conversation.follow_ups.updated";
|
|
119
|
+
conversation_id: string;
|
|
120
|
+
version: number;
|
|
121
|
+
follow_ups: readonly PAConversationFollowUp[];
|
|
122
|
+
}> | Readonly<{
|
|
123
|
+
type: "conversation.item.updated";
|
|
124
|
+
item: PADisplayItem;
|
|
125
|
+
}> | PAItemRemoval | (PAStreamLifecycle & Readonly<{
|
|
126
|
+
type: "conversation.item.stream_finished";
|
|
127
|
+
conversation_id: string;
|
|
128
|
+
}>) | Readonly<{
|
|
129
|
+
type: "conversation.execution.updated";
|
|
130
|
+
execution: PAExecutionState;
|
|
131
|
+
}>;
|
|
132
|
+
export declare function displayTimestampKey(value: string): string;
|
|
133
|
+
export declare function displayRevision(item: PADisplayItem): number | null;
|
|
134
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PAEffectResultEvent } from "../kernel/effects";
|
|
2
|
+
import type { PAReduction } from "../kernel/reducer";
|
|
3
|
+
import type { PAModelSelectionState } from "../model-selection/state";
|
|
4
|
+
import type { PADirectoryState } from "../session-directory/contracts";
|
|
5
|
+
import type { PAConversationCommand, PAConversationEffects, PAConversationEvent, PAConversationState, PAOwnedSubmission } from "./contracts";
|
|
6
|
+
export declare function submissionHasLocalPresence(submission: PAOwnedSubmission, directory: PADirectoryState): boolean;
|
|
7
|
+
export declare function synchronizeConversationDirectory(state: PAConversationState, directory: PADirectoryState): PAConversationState;
|
|
8
|
+
export declare function reduceConversation(state: PAConversationState, input: PAConversationCommand | PAConversationEvent | PAEffectResultEvent<PAConversationEffects>, directory: PADirectoryState, models: PAModelSelectionState): PAReduction<PAConversationState, PAConversationEffects>;
|