@assistant-ui/react-statewire 0.4.2 → 0.4.4
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/AssistantTransportThread.d.ts +190 -4
- package/dist/AssistantTransportThread.d.ts.map +1 -1
- package/dist/AssistantTransportThread.js.map +1 -1
- package/dist/StatewireThread.d.ts +6 -2
- package/dist/StatewireThread.d.ts.map +1 -1
- package/dist/StatewireThread.js +2 -1
- package/dist/StatewireThread.js.map +1 -1
- package/dist/hooks.d.ts +4 -2
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js.map +1 -1
- package/dist/host.d.ts +5 -5
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +1 -36
- package/dist/inputRequests.d.ts +4 -4
- package/dist/inputRequests.d.ts.map +1 -1
- package/dist/inputRequests.js.map +1 -1
- package/dist/runCommands.d.ts +6 -6
- package/dist/runCommands.d.ts.map +1 -1
- package/dist/runCommands.js.map +1 -1
- package/package.json +1 -1
- package/src/AssistantTransportThread.ts +258 -14
- package/src/StatewireThread.test.tsx +41 -2
- package/src/StatewireThread.ts +16 -4
- package/src/__tests__/testHelpers.tsx +11 -17
- package/src/athena.e2e.test.tsx +15 -19
- package/src/hooks.ts +7 -2
- package/src/host.ts +11 -13
- package/src/index.ts +1 -36
- package/src/inputRequests.ts +8 -6
- package/src/legacy-diff.test.tsx +4 -7
- package/src/runCommands.ts +14 -16
- package/src/transport.test.tsx +12 -16
- package/dist/index.d.ts.map +0 -1
- package/dist/types.d.ts +0 -189
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -0
- package/src/types.ts +0 -255
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;kBAUiB;OACH,QAAQ,KAAK,0BAAgC;OAC7C,UAAU;OACV,WAAW;OACX,QAAQ;OACR,qBAAqB;OACrB,eAAe,KAAK,iCAAuC;OAC3D,aAAa;OACb,oBAAoB;OACpB,kBAAkB;OAClB,oBAAoB;OACpB,iBAAiB;OACjB,qBAAqB;OACrB,mBAAmB;OACnB,kBAAkB;OAClB,eAAe;OACf,uBAAuB;OACvB,2BAA2B;OAC3B,qBAAqB;OACrB,oBAAoB;OACpB,gBAAgB;OAChB,wBAAwB;OACxB,4BAA4B;OAC5B,iBAAiB;OACjB,eAAe;OACf,eAAe;OACf,0BAA0B;OAC1B,WAAW;OACX,WAAW;OACX,eAAe"}
|
package/dist/types.d.ts
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { Assistant } from "@assistant-ui/react";
|
|
2
|
-
import { AttachmentAdapter, LanguageModelConfig, LanguageModelV1CallSettings, ThreadMessage, ToolExecutionStatus } from "@assistant-ui/core";
|
|
3
|
-
import { ReadonlyJSONValue } from "assistant-stream/utils";
|
|
4
|
-
//#region src/types.d.ts
|
|
5
|
-
type UserCommands = Assistant.Commands[keyof Assistant.Commands];
|
|
6
|
-
type UserExternalState = keyof Assistant.ExternalState extends never ? Record<string, unknown> : Assistant.ExternalState[keyof Assistant.ExternalState];
|
|
7
|
-
type TextPart = {
|
|
8
|
-
readonly type: "text";
|
|
9
|
-
readonly text: string;
|
|
10
|
-
};
|
|
11
|
-
type FilePart = {
|
|
12
|
-
readonly type: "file";
|
|
13
|
-
readonly mediaType: string;
|
|
14
|
-
readonly url: string;
|
|
15
|
-
readonly filename?: string;
|
|
16
|
-
};
|
|
17
|
-
type RunUserMessage = {
|
|
18
|
-
readonly id: string;
|
|
19
|
-
readonly role: "user";
|
|
20
|
-
readonly parts: readonly (TextPart | FilePart)[];
|
|
21
|
-
readonly metadata?: Record<string, unknown>;
|
|
22
|
-
};
|
|
23
|
-
/** Queue placement fields, flat on the command. Absent is load-bearing: it means default placement; `null` names a queue boundary. */
|
|
24
|
-
type RunPlacement = {
|
|
25
|
-
readonly insertAfter?: string | null;
|
|
26
|
-
readonly insertBefore?: string | null;
|
|
27
|
-
};
|
|
28
|
-
type RunEnqueueCommand = {
|
|
29
|
-
readonly type: "run/enqueue";
|
|
30
|
-
} & ({
|
|
31
|
-
readonly message: RunUserMessage;
|
|
32
|
-
/** Branch anchor: the newest message the client knows on its intended branch, null asserting an empty thread. Required on adds; optional on edits of queued items. */
|
|
33
|
-
readonly anchorMessageId?: string | null;
|
|
34
|
-
} | {
|
|
35
|
-
readonly messageId: string;
|
|
36
|
-
}) & RunPlacement;
|
|
37
|
-
type RunSteerCommand = {
|
|
38
|
-
readonly type: "run/steer";
|
|
39
|
-
} & ({
|
|
40
|
-
readonly message: RunUserMessage;
|
|
41
|
-
/** Branch anchor: the newest message the client knows on its intended branch, null asserting an empty thread. Required on adds; optional on edits of queued items. */
|
|
42
|
-
readonly anchorMessageId?: string | null;
|
|
43
|
-
} | {
|
|
44
|
-
readonly messageId: string;
|
|
45
|
-
}) & RunPlacement;
|
|
46
|
-
type RunDequeueCommand = {
|
|
47
|
-
readonly type: "run/dequeue";
|
|
48
|
-
readonly messageId: string;
|
|
49
|
-
};
|
|
50
|
-
type RunEditCommand = {
|
|
51
|
-
readonly type: "run/edit";
|
|
52
|
-
readonly message: RunUserMessage;
|
|
53
|
-
readonly sourceId: string;
|
|
54
|
-
};
|
|
55
|
-
type RunContinueCommand = {
|
|
56
|
-
readonly type: "run/continue";
|
|
57
|
-
};
|
|
58
|
-
type ToolCallInputRequest = {
|
|
59
|
-
readonly type: "tool-call";
|
|
60
|
-
readonly id: string;
|
|
61
|
-
readonly toolCallId: string;
|
|
62
|
-
};
|
|
63
|
-
type ToolApprovalInputRequest = {
|
|
64
|
-
readonly type: "tool-approval";
|
|
65
|
-
readonly id: string;
|
|
66
|
-
readonly toolCallId: string;
|
|
67
|
-
};
|
|
68
|
-
type CustomInputRequest = {
|
|
69
|
-
readonly type: string;
|
|
70
|
-
readonly id: string;
|
|
71
|
-
readonly [key: string]: ReadonlyJSONValue | undefined;
|
|
72
|
-
};
|
|
73
|
-
/** A host request parking the run until answered; open union for custom types. */
|
|
74
|
-
type InputRequest = ToolCallInputRequest | ToolApprovalInputRequest | CustomInputRequest;
|
|
75
|
-
type ToolCallInputResponse = {
|
|
76
|
-
readonly output: ReadonlyJSONValue;
|
|
77
|
-
/** Default false; when true, `output` carries the error payload. */
|
|
78
|
-
readonly isError?: boolean;
|
|
79
|
-
readonly artifact?: ReadonlyJSONValue;
|
|
80
|
-
};
|
|
81
|
-
type ToolApprovalInputResponse = {
|
|
82
|
-
readonly decision: "approve" | "reject" | "edit" | "respond";
|
|
83
|
-
readonly editedArgs?: ReadonlyJSONValue;
|
|
84
|
-
readonly message?: string;
|
|
85
|
-
};
|
|
86
|
-
type InputResponse = ReadonlyJSONValue;
|
|
87
|
-
type RunInputCommand = {
|
|
88
|
-
readonly type: "run/input";
|
|
89
|
-
readonly requestId: string;
|
|
90
|
-
readonly response: InputResponse;
|
|
91
|
-
};
|
|
92
|
-
/** An input request projected out of the host state with its response echo. */
|
|
93
|
-
type InputRequestState = InputRequest & {
|
|
94
|
-
readonly response: InputResponse | null;
|
|
95
|
-
};
|
|
96
|
-
type RunReloadCommand = {
|
|
97
|
-
readonly type: "run/reload";
|
|
98
|
-
readonly sourceId: string;
|
|
99
|
-
};
|
|
100
|
-
type RunCommand = RunEnqueueCommand | RunSteerCommand | RunDequeueCommand | RunEditCommand | RunContinueCommand | RunReloadCommand | RunInputCommand;
|
|
101
|
-
type AssistantTransportCommand = RunCommand | UserCommands;
|
|
102
|
-
/** A queued message projected out of the host state, wire shape. */
|
|
103
|
-
type RunQueueItem = {
|
|
104
|
-
readonly id: string;
|
|
105
|
-
readonly parts: readonly (TextPart | FilePart)[];
|
|
106
|
-
};
|
|
107
|
-
type AssistantTransportState = {
|
|
108
|
-
readonly messages: readonly ThreadMessage[];
|
|
109
|
-
readonly state?: ReadonlyJSONValue;
|
|
110
|
-
readonly isRunning: boolean;
|
|
111
|
-
/**
|
|
112
|
-
* The host's regular queue lane projected out of the state. Returning it
|
|
113
|
-
* (even empty) turns on the server-side queue: sends become `run/enqueue`
|
|
114
|
-
* / `run/steer` commands and item controls send the `run/*` queue
|
|
115
|
-
* commands. Presence must be stable across conversions and excludes the
|
|
116
|
-
* client-local `capabilities.queue` buffer.
|
|
117
|
-
*/
|
|
118
|
-
readonly queue?: readonly RunQueueItem[];
|
|
119
|
-
/** The host's steer lane; requires `queue`. Absent means empty. */
|
|
120
|
-
readonly steerQueue?: readonly RunQueueItem[];
|
|
121
|
-
/**
|
|
122
|
-
* The host's parked input requests projected out of the state. Returning it
|
|
123
|
-
* (even empty) routes tool results and approvals with a matching pending
|
|
124
|
-
* request through `run/input`. Presence must be stable across conversions.
|
|
125
|
-
*/
|
|
126
|
-
readonly inputRequests?: readonly InputRequestState[];
|
|
127
|
-
};
|
|
128
|
-
type AssistantTransportConnectionMetadata = {
|
|
129
|
-
pendingCommands: AssistantTransportCommand[];
|
|
130
|
-
isSending: boolean;
|
|
131
|
-
toolStatuses: Record<string, ToolExecutionStatus>;
|
|
132
|
-
};
|
|
133
|
-
type AssistantTransportStateConverter<T> = (state: T, connectionMetadata: AssistantTransportConnectionMetadata) => AssistantTransportState;
|
|
134
|
-
type HeadersValue = Record<string, string> | Headers;
|
|
135
|
-
type AssistantTransportProtocol = "data-stream" | "assistant-transport";
|
|
136
|
-
type SendCommandsRequestBody = {
|
|
137
|
-
commands: AssistantTransportCommand[];
|
|
138
|
-
state: unknown;
|
|
139
|
-
system: string | undefined;
|
|
140
|
-
tools: Record<string, unknown> | undefined;
|
|
141
|
-
callSettings: LanguageModelV1CallSettings | undefined;
|
|
142
|
-
config: LanguageModelConfig | undefined;
|
|
143
|
-
threadId: string | null;
|
|
144
|
-
parentId?: string | null;
|
|
145
|
-
[key: string]: unknown;
|
|
146
|
-
};
|
|
147
|
-
type AssistantTransportOptions<T> = {
|
|
148
|
-
initialState: T;
|
|
149
|
-
converter: AssistantTransportStateConverter<T>;
|
|
150
|
-
api: string;
|
|
151
|
-
resumeApi?: string | undefined;
|
|
152
|
-
protocol?: AssistantTransportProtocol | undefined;
|
|
153
|
-
headers: HeadersValue | (() => Promise<HeadersValue>);
|
|
154
|
-
body?: object | (() => Promise<object | undefined>) | undefined;
|
|
155
|
-
/** Transform the fully assembled request body before it is sent. */
|
|
156
|
-
prepareSendCommandsRequest?: ((body: SendCommandsRequestBody) => Record<string, unknown> | Promise<Record<string, unknown>>) | undefined;
|
|
157
|
-
onResponse?: ((response: Response) => void) | undefined;
|
|
158
|
-
onFinish?: (() => void) | undefined;
|
|
159
|
-
onError?: ((error: Error, params: {
|
|
160
|
-
commands: AssistantTransportCommand[];
|
|
161
|
-
updateState: (updater: (state: T) => T) => void;
|
|
162
|
-
}) => void | Promise<void>) | undefined;
|
|
163
|
-
/**
|
|
164
|
-
* Called when commands are cancelled. After an error, queued commands are
|
|
165
|
-
* cancelled once `onError` settles; `error` then carries the cause.
|
|
166
|
-
*/
|
|
167
|
-
onCancel?: ((params: {
|
|
168
|
-
commands: AssistantTransportCommand[];
|
|
169
|
-
updateState: (updater: (state: T) => T) => void;
|
|
170
|
-
error?: Error;
|
|
171
|
-
}) => void) | undefined;
|
|
172
|
-
capabilities?: {
|
|
173
|
-
edit?: boolean | undefined;
|
|
174
|
-
/**
|
|
175
|
-
* Buffer messages sent during a run in an in-memory queue and dispatch
|
|
176
|
-
* them once the run settles. Steering interrupts the active run.
|
|
177
|
-
* Mutually exclusive with the converter's `queue` projection.
|
|
178
|
-
*/
|
|
179
|
-
queue?: boolean | undefined;
|
|
180
|
-
/** The host supports `run/continue` (a continue affordance on aborted runs). */
|
|
181
|
-
continue?: boolean | undefined;
|
|
182
|
-
} | undefined;
|
|
183
|
-
adapters?: {
|
|
184
|
-
attachments?: AttachmentAdapter | undefined;
|
|
185
|
-
} | undefined;
|
|
186
|
-
};
|
|
187
|
-
//#endregion
|
|
188
|
-
export { AssistantTransportCommand, AssistantTransportConnectionMetadata, AssistantTransportOptions, AssistantTransportProtocol, AssistantTransportState, AssistantTransportStateConverter, CustomInputRequest, FilePart, HeadersValue, InputRequest, InputRequestState, InputResponse, RunCommand, RunContinueCommand, RunDequeueCommand, RunEditCommand, RunEnqueueCommand, RunInputCommand, RunPlacement, RunQueueItem, RunReloadCommand, RunSteerCommand, RunUserMessage, SendCommandsRequestBody, TextPart, ToolApprovalInputRequest, ToolApprovalInputResponse, ToolCallInputRequest, ToolCallInputResponse, UserCommands, UserExternalState };
|
|
189
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;;KAUY,eAAe,UAAU,eAAe,UAAU;KAClD,0BAA0B,UAAU,8BAC5C,0BACA,UAAU,oBAAoB,UAAU;KAEhC;WACD;WACA;;KAGC;WACD;WACA;WACA;WACA;;KAGC;WACD;WACA;WACA,iBAAiB,WAAW;WAC5B,WAAW;;;KAIV;WACD;WACA;;KAGC;WACD;;WAGI,SAAS;;WAET;;WAEA;KAEb;KAEU;WACD;;WAGI,SAAS;;WAET;;WAEA;KAEb;KAEU;WACD;WACA;;KAGC;WACD;WACA,SAAS;WACT;;KAGC;WACD;;KAGC;WACD;WACA;WACA;;KAGC;WACD;WACA;WACA;;KAGC;WACD;WACA;YACC,cAAc;;;KAId,eACR,uBACA,2BACA;KAEQ;WACD,QAAQ;;WAER;WACA,WAAW;;KAGV;WACD;WACA,aAAa;WACb;;KAGC,gBAAgB;KAEhB;WACD;WACA;WACA,UAAU;;;KAIT,oBAAoB;WACrB,UAAU;;KAGT;WACD;WACA;;KAGC,aACR,oBACA,kBACA,oBACA,iBACA,qBACA,mBACA;KAEQ,4BAA4B,aAAa;;KAGzC;WACD;WACA,iBAAiB,WAAW;;KAG3B;WACD,mBAAmB;WACnB,QAAQ;WACR;;;;;;;;WAQA,iBAAiB;;WAEjB,sBAAsB;;;;;;WAMtB,yBAAyB;;KAGxB;EACV,iBAAiB;EACjB;EACA,cAAc,eAAe;;KAGnB,iCAAiC,MAC3C,OAAO,GACP,oBAAoB,yCACjB;KAEO,eAAe,yBAAyB;KAExC;KAEA;EACV,UAAU;EACV;EACA;EACA,OAAO;EACP,cAAc;EACd,QAAQ;EACR;EACA;GACC;;KAGS,0BAA0B;EACpC,cAAc;EACd,WAAW,iCAAiC;EAC5C;EACA;EACA,WAAW;EACX,SAAS,sBAAsB,QAAQ;EACvC,uBAAuB;;EAEvB,+BAEM,MAAM,4BACH,0BAA0B,QAAQ;EAE3C,eAAe,UAAU;EACzB;EACA,YAEM,OAAO,OACP;IACE,UAAU;IACV,cAAc,UAAU,OAAO,MAAM;eAE7B;;;;;EAMhB,aACM;IACA,UAAU;IACV,cAAc,UAAU,OAAO,MAAM;IACrC,QAAQ;;EAGd;IAEM;;;;;;IAMA;;IAEA;;EAGN;IAEM,cAAc"}
|
package/dist/types.js
DELETED
|
File without changes
|
package/src/types.ts
DELETED
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
import type { ReadonlyJSONValue } from "assistant-stream/utils";
|
|
2
|
-
import type {
|
|
3
|
-
AttachmentAdapter,
|
|
4
|
-
ThreadMessage,
|
|
5
|
-
ToolExecutionStatus,
|
|
6
|
-
LanguageModelV1CallSettings,
|
|
7
|
-
LanguageModelConfig,
|
|
8
|
-
} from "@assistant-ui/core";
|
|
9
|
-
import type { Assistant } from "@assistant-ui/react";
|
|
10
|
-
|
|
11
|
-
export type UserCommands = Assistant.Commands[keyof Assistant.Commands];
|
|
12
|
-
export type UserExternalState = keyof Assistant.ExternalState extends never
|
|
13
|
-
? Record<string, unknown>
|
|
14
|
-
: Assistant.ExternalState[keyof Assistant.ExternalState];
|
|
15
|
-
|
|
16
|
-
export type TextPart = {
|
|
17
|
-
readonly type: "text";
|
|
18
|
-
readonly text: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type FilePart = {
|
|
22
|
-
readonly type: "file";
|
|
23
|
-
readonly mediaType: string;
|
|
24
|
-
readonly url: string;
|
|
25
|
-
readonly filename?: string;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export type RunUserMessage = {
|
|
29
|
-
readonly id: string;
|
|
30
|
-
readonly role: "user";
|
|
31
|
-
readonly parts: readonly (TextPart | FilePart)[];
|
|
32
|
-
readonly metadata?: Record<string, unknown>;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
/** Queue placement fields, flat on the command. Absent is load-bearing: it means default placement; `null` names a queue boundary. */
|
|
36
|
-
export type RunPlacement = {
|
|
37
|
-
readonly insertAfter?: string | null;
|
|
38
|
-
readonly insertBefore?: string | null;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export type RunEnqueueCommand = {
|
|
42
|
-
readonly type: "run/enqueue";
|
|
43
|
-
} & (
|
|
44
|
-
| {
|
|
45
|
-
readonly message: RunUserMessage;
|
|
46
|
-
/** Branch anchor: the newest message the client knows on its intended branch, null asserting an empty thread. Required on adds; optional on edits of queued items. */
|
|
47
|
-
readonly anchorMessageId?: string | null;
|
|
48
|
-
}
|
|
49
|
-
| { readonly messageId: string }
|
|
50
|
-
) &
|
|
51
|
-
RunPlacement;
|
|
52
|
-
|
|
53
|
-
export type RunSteerCommand = {
|
|
54
|
-
readonly type: "run/steer";
|
|
55
|
-
} & (
|
|
56
|
-
| {
|
|
57
|
-
readonly message: RunUserMessage;
|
|
58
|
-
/** Branch anchor: the newest message the client knows on its intended branch, null asserting an empty thread. Required on adds; optional on edits of queued items. */
|
|
59
|
-
readonly anchorMessageId?: string | null;
|
|
60
|
-
}
|
|
61
|
-
| { readonly messageId: string }
|
|
62
|
-
) &
|
|
63
|
-
RunPlacement;
|
|
64
|
-
|
|
65
|
-
export type RunDequeueCommand = {
|
|
66
|
-
readonly type: "run/dequeue";
|
|
67
|
-
readonly messageId: string;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export type RunEditCommand = {
|
|
71
|
-
readonly type: "run/edit";
|
|
72
|
-
readonly message: RunUserMessage;
|
|
73
|
-
readonly sourceId: string;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export type RunContinueCommand = {
|
|
77
|
-
readonly type: "run/continue";
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export type ToolCallInputRequest = {
|
|
81
|
-
readonly type: "tool-call";
|
|
82
|
-
readonly id: string;
|
|
83
|
-
readonly toolCallId: string;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export type ToolApprovalInputRequest = {
|
|
87
|
-
readonly type: "tool-approval";
|
|
88
|
-
readonly id: string;
|
|
89
|
-
readonly toolCallId: string;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
export type CustomInputRequest = {
|
|
93
|
-
readonly type: string;
|
|
94
|
-
readonly id: string;
|
|
95
|
-
readonly [key: string]: ReadonlyJSONValue | undefined;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
/** A host request parking the run until answered; open union for custom types. */
|
|
99
|
-
export type InputRequest =
|
|
100
|
-
| ToolCallInputRequest
|
|
101
|
-
| ToolApprovalInputRequest
|
|
102
|
-
| CustomInputRequest;
|
|
103
|
-
|
|
104
|
-
export type ToolCallInputResponse = {
|
|
105
|
-
readonly output: ReadonlyJSONValue;
|
|
106
|
-
/** Default false; when true, `output` carries the error payload. */
|
|
107
|
-
readonly isError?: boolean;
|
|
108
|
-
readonly artifact?: ReadonlyJSONValue;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
export type ToolApprovalInputResponse = {
|
|
112
|
-
readonly decision: "approve" | "reject" | "edit" | "respond";
|
|
113
|
-
readonly editedArgs?: ReadonlyJSONValue;
|
|
114
|
-
readonly message?: string;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
export type InputResponse = ReadonlyJSONValue;
|
|
118
|
-
|
|
119
|
-
export type RunInputCommand = {
|
|
120
|
-
readonly type: "run/input";
|
|
121
|
-
readonly requestId: string;
|
|
122
|
-
readonly response: InputResponse;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
/** An input request projected out of the host state with its response echo. */
|
|
126
|
-
export type InputRequestState = InputRequest & {
|
|
127
|
-
readonly response: InputResponse | null;
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
export type RunReloadCommand = {
|
|
131
|
-
readonly type: "run/reload";
|
|
132
|
-
readonly sourceId: string;
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
export type RunCommand =
|
|
136
|
-
| RunEnqueueCommand
|
|
137
|
-
| RunSteerCommand
|
|
138
|
-
| RunDequeueCommand
|
|
139
|
-
| RunEditCommand
|
|
140
|
-
| RunContinueCommand
|
|
141
|
-
| RunReloadCommand
|
|
142
|
-
| RunInputCommand;
|
|
143
|
-
|
|
144
|
-
export type AssistantTransportCommand = RunCommand | UserCommands;
|
|
145
|
-
|
|
146
|
-
/** A queued message projected out of the host state, wire shape. */
|
|
147
|
-
export type RunQueueItem = {
|
|
148
|
-
readonly id: string;
|
|
149
|
-
readonly parts: readonly (TextPart | FilePart)[];
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
export type AssistantTransportState = {
|
|
153
|
-
readonly messages: readonly ThreadMessage[];
|
|
154
|
-
readonly state?: ReadonlyJSONValue;
|
|
155
|
-
readonly isRunning: boolean;
|
|
156
|
-
/**
|
|
157
|
-
* The host's regular queue lane projected out of the state. Returning it
|
|
158
|
-
* (even empty) turns on the server-side queue: sends become `run/enqueue`
|
|
159
|
-
* / `run/steer` commands and item controls send the `run/*` queue
|
|
160
|
-
* commands. Presence must be stable across conversions and excludes the
|
|
161
|
-
* client-local `capabilities.queue` buffer.
|
|
162
|
-
*/
|
|
163
|
-
readonly queue?: readonly RunQueueItem[];
|
|
164
|
-
/** The host's steer lane; requires `queue`. Absent means empty. */
|
|
165
|
-
readonly steerQueue?: readonly RunQueueItem[];
|
|
166
|
-
/**
|
|
167
|
-
* The host's parked input requests projected out of the state. Returning it
|
|
168
|
-
* (even empty) routes tool results and approvals with a matching pending
|
|
169
|
-
* request through `run/input`. Presence must be stable across conversions.
|
|
170
|
-
*/
|
|
171
|
-
readonly inputRequests?: readonly InputRequestState[];
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
export type AssistantTransportConnectionMetadata = {
|
|
175
|
-
pendingCommands: AssistantTransportCommand[];
|
|
176
|
-
isSending: boolean;
|
|
177
|
-
toolStatuses: Record<string, ToolExecutionStatus>;
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
export type AssistantTransportStateConverter<T> = (
|
|
181
|
-
state: T,
|
|
182
|
-
connectionMetadata: AssistantTransportConnectionMetadata,
|
|
183
|
-
) => AssistantTransportState;
|
|
184
|
-
|
|
185
|
-
export type HeadersValue = Record<string, string> | Headers;
|
|
186
|
-
|
|
187
|
-
export type AssistantTransportProtocol = "data-stream" | "assistant-transport";
|
|
188
|
-
|
|
189
|
-
export type SendCommandsRequestBody = {
|
|
190
|
-
commands: AssistantTransportCommand[];
|
|
191
|
-
state: unknown;
|
|
192
|
-
system: string | undefined;
|
|
193
|
-
tools: Record<string, unknown> | undefined;
|
|
194
|
-
callSettings: LanguageModelV1CallSettings | undefined;
|
|
195
|
-
config: LanguageModelConfig | undefined;
|
|
196
|
-
threadId: string | null;
|
|
197
|
-
parentId?: string | null;
|
|
198
|
-
[key: string]: unknown;
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
export type AssistantTransportOptions<T> = {
|
|
202
|
-
initialState: T;
|
|
203
|
-
converter: AssistantTransportStateConverter<T>;
|
|
204
|
-
api: string;
|
|
205
|
-
resumeApi?: string | undefined;
|
|
206
|
-
protocol?: AssistantTransportProtocol | undefined;
|
|
207
|
-
headers: HeadersValue | (() => Promise<HeadersValue>);
|
|
208
|
-
body?: object | (() => Promise<object | undefined>) | undefined;
|
|
209
|
-
/** Transform the fully assembled request body before it is sent. */
|
|
210
|
-
prepareSendCommandsRequest?:
|
|
211
|
-
| ((
|
|
212
|
-
body: SendCommandsRequestBody,
|
|
213
|
-
) => Record<string, unknown> | Promise<Record<string, unknown>>)
|
|
214
|
-
| undefined;
|
|
215
|
-
onResponse?: ((response: Response) => void) | undefined;
|
|
216
|
-
onFinish?: (() => void) | undefined;
|
|
217
|
-
onError?:
|
|
218
|
-
| ((
|
|
219
|
-
error: Error,
|
|
220
|
-
params: {
|
|
221
|
-
commands: AssistantTransportCommand[];
|
|
222
|
-
updateState: (updater: (state: T) => T) => void;
|
|
223
|
-
},
|
|
224
|
-
) => void | Promise<void>)
|
|
225
|
-
| undefined;
|
|
226
|
-
/**
|
|
227
|
-
* Called when commands are cancelled. After an error, queued commands are
|
|
228
|
-
* cancelled once `onError` settles; `error` then carries the cause.
|
|
229
|
-
*/
|
|
230
|
-
onCancel?:
|
|
231
|
-
| ((params: {
|
|
232
|
-
commands: AssistantTransportCommand[];
|
|
233
|
-
updateState: (updater: (state: T) => T) => void;
|
|
234
|
-
error?: Error;
|
|
235
|
-
}) => void)
|
|
236
|
-
| undefined;
|
|
237
|
-
capabilities?:
|
|
238
|
-
| {
|
|
239
|
-
edit?: boolean | undefined;
|
|
240
|
-
/**
|
|
241
|
-
* Buffer messages sent during a run in an in-memory queue and dispatch
|
|
242
|
-
* them once the run settles. Steering interrupts the active run.
|
|
243
|
-
* Mutually exclusive with the converter's `queue` projection.
|
|
244
|
-
*/
|
|
245
|
-
queue?: boolean | undefined;
|
|
246
|
-
/** The host supports `run/continue` (a continue affordance on aborted runs). */
|
|
247
|
-
continue?: boolean | undefined;
|
|
248
|
-
}
|
|
249
|
-
| undefined;
|
|
250
|
-
adapters?:
|
|
251
|
-
| {
|
|
252
|
-
attachments?: AttachmentAdapter | undefined;
|
|
253
|
-
}
|
|
254
|
-
| undefined;
|
|
255
|
-
};
|