Skip to content

Commit e3b2ef0

Browse files
committed
Format SDK files and update ui package.json
Apply code-style and formatting changes across the UI SDK: reflow multi-line objects, add trailing commas, fix function parameter comma placements, and tidy imports/exports (notably reordering/aggregating schema exports in packages/sdk/src/index.ts). Update ui/package.json to set "private": true and change the prettier script to use project ignore paths. All changes are non-functional and mostly affect tests and formatting.
1 parent 73ca1ec commit e3b2ef0

20 files changed

Lines changed: 793 additions & 364 deletions

ui/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"type": "module",
3+
"private": true,
34
"scripts": {
45
"build": "pnpm type-check && pnpm build-only",
56
"build-only": "pnpm -C packages/sdk run build && rsbuild build",
67
"dev": "rsbuild build --watch --env-mode=development",
78
"lint:oxlint": "oxlint . --fix -D correctness --ignore-path ../.gitignore",
89
"lint:eslint": "eslint . --fix",
910
"lint": "run-s lint:*",
10-
"prettier": "prettier --write src/",
11+
"prettier": "prettier . --write --ignore-path ../.gitignore --ignore-path ./.prettierignore",
1112
"test:unit": "rstest run",
1213
"type-check": "vue-tsc --build"
1314
},

ui/packages/sdk/src/chat.ts

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import type {
1616
DataPart,
1717
FilePart,
1818
IdGenerator,
19-
ToolPart,
2019
ToolApprovalResponseInput,
2120
ToolOutputInput,
2221
ToolOutputSuccessInput,
22+
ToolPart,
2323
UIMessage,
2424
UIMessageChunk,
2525
UIMessageStreamTerminal,
@@ -137,7 +137,10 @@ export class Chat<METADATA = unknown> {
137137
}
138138
}
139139

140-
async sendMessage(message?: SendMessageInput<METADATA>, options?: ChatRequestOptions): Promise<void> {
140+
async sendMessage(
141+
message?: SendMessageInput<METADATA>,
142+
options?: ChatRequestOptions,
143+
): Promise<void> {
141144
if (message) {
142145
this.applyUserMessage(message)
143146
}
@@ -164,7 +167,12 @@ export class Chat<METADATA = unknown> {
164167

165168
const keepUntil = messages[index].role === 'assistant' ? index : index + 1
166169
this.setMessages(messages.slice(0, keepUntil))
167-
await this.makeRequest({ trigger: 'regenerate-message', messageId, options, requestMessages: messages })
170+
await this.makeRequest({
171+
trigger: 'regenerate-message',
172+
messageId,
173+
options,
174+
requestMessages: messages,
175+
})
168176
}
169177

170178
stop(): void {
@@ -178,7 +186,12 @@ export class Chat<METADATA = unknown> {
178186
}
179187
return assistant.parts
180188
.filter(isToolPart)
181-
.every((part) => part.state === 'output-available' || part.state === 'output-error' || part.state === 'output-denied')
189+
.every(
190+
(part) =>
191+
part.state === 'output-available' ||
192+
part.state === 'output-error' ||
193+
part.state === 'output-denied',
194+
)
182195
}
183196

184197
private async appendToolOutputSuccess(
@@ -188,11 +201,11 @@ export class Chat<METADATA = unknown> {
188201
result: unknown
189202
providerMetadata?: Record<string, unknown>
190203
},
191-
options?: ChatRequestOptions
204+
options?: ChatRequestOptions,
192205
): Promise<void> {
193206
const tool = this.resolveToolCall(input.toolCallId, input.toolName)
194207
this.updateLastAssistant((message) =>
195-
withToolOutput(message, { ...input, toolName: tool.toolName })
208+
withToolOutput(message, { ...input, toolName: tool.toolName }),
196209
)
197210
await this.maybeSendAutomatically(options)
198211
}
@@ -204,11 +217,11 @@ export class Chat<METADATA = unknown> {
204217
errorText: string
205218
providerMetadata?: Record<string, unknown>
206219
},
207-
options?: ChatRequestOptions
220+
options?: ChatRequestOptions,
208221
): Promise<void> {
209222
const tool = this.resolveToolCall(input.toolCallId, input.toolName)
210223
this.updateLastAssistant((message) =>
211-
withToolError(message, { ...input, toolName: tool.toolName })
224+
withToolError(message, { ...input, toolName: tool.toolName }),
212225
)
213226
await this.maybeSendAutomatically(options)
214227
}
@@ -223,7 +236,7 @@ export class Chat<METADATA = unknown> {
223236
errorText: input.errorText,
224237
providerMetadata: input.providerMetadata,
225238
},
226-
options
239+
options,
227240
)
228241
return
229242
}
@@ -235,20 +248,20 @@ export class Chat<METADATA = unknown> {
235248
result: outputInput.output ?? outputInput.result,
236249
providerMetadata: outputInput.providerMetadata,
237250
},
238-
options
251+
options,
239252
)
240253
}
241254

242255
async rejectToolCall(
243256
input: Omit<ToolApprovalResponseInput, 'approved'> & { approved?: false },
244-
options?: ChatRequestOptions
257+
options?: ChatRequestOptions,
245258
): Promise<void> {
246259
await this.addToolApprovalResponse({ ...input, approved: false }, options)
247260
}
248261

249262
async addToolApprovalResponse(
250263
input: ToolApprovalResponseInput,
251-
options?: ChatRequestOptions
264+
options?: ChatRequestOptions,
252265
): Promise<void> {
253266
const approval =
254267
input.id || input.approvalId
@@ -267,7 +280,7 @@ export class Chat<METADATA = unknown> {
267280
approved: input.approved,
268281
reason: input.reason,
269282
providerMetadata: input.providerMetadata,
270-
})
283+
}),
271284
)
272285
await this.maybeSendAutomatically(options)
273286
}
@@ -289,10 +302,7 @@ export class Chat<METADATA = unknown> {
289302
if (messages[index].role !== 'user') {
290303
throw new Error(`message with id ${message.messageId} is not a user message`)
291304
}
292-
this.setMessages([
293-
...messages.slice(0, index),
294-
{ ...nextMessage, id: message.messageId },
295-
])
305+
this.setMessages([...messages.slice(0, index), { ...nextMessage, id: message.messageId }])
296306
return
297307
}
298308

@@ -352,7 +362,12 @@ export class Chat<METADATA = unknown> {
352362
}),
353363
})
354364

355-
if (this.status === 'ready' && !outcome.isError && allowAutoSubmit && (await this.shouldSendAutomatically())) {
365+
if (
366+
this.status === 'ready' &&
367+
!outcome.isError &&
368+
allowAutoSubmit &&
369+
(await this.shouldSendAutomatically())
370+
) {
356371
await this.makeRequest({
357372
trigger: 'submit-message',
358373
messageId: this.messages[this.messages.length - 1]?.id,
@@ -433,7 +448,7 @@ export class Chat<METADATA = unknown> {
433448

434449
private applyAssistantChunk(
435450
reducer: ReturnType<typeof createUIMessageReducer<METADATA>>,
436-
chunk: UIMessageChunk
451+
chunk: UIMessageChunk,
437452
) {
438453
applyUIMessageChunk(reducer, chunk)
439454
if (isDataChunk(chunk)) {
@@ -579,7 +594,7 @@ function findLastIndex<T>(items: T[], predicate: (item: T) => boolean): number {
579594

580595
function findLastToolPart<METADATA>(
581596
messages: UIMessage<METADATA>[],
582-
toolCallId: string
597+
toolCallId: string,
583598
): { toolName: string } | undefined {
584599
for (let messageIndex = messages.length - 1; messageIndex >= 0; messageIndex -= 1) {
585600
const message = messages[messageIndex]
@@ -598,7 +613,7 @@ function findLastToolPart<METADATA>(
598613

599614
function findLastApprovalRequest<METADATA>(
600615
messages: UIMessage<METADATA>[],
601-
approvalId: string
616+
approvalId: string,
602617
): ToolPart | undefined {
603618
for (let messageIndex = messages.length - 1; messageIndex >= 0; messageIndex -= 1) {
604619
const message = messages[messageIndex]
@@ -623,13 +638,15 @@ function isToolPart(part: UIMessage['parts'][number]): part is ToolPart {
623638
return part.type.startsWith('tool-')
624639
}
625640

626-
function isDataChunk(chunk: UIMessageChunk): chunk is Extract<UIMessageChunk, { type: `data-${string}` }> {
641+
function isDataChunk(
642+
chunk: UIMessageChunk,
643+
): chunk is Extract<UIMessageChunk, { type: `data-${string}` }> {
627644
return chunk.type.startsWith('data-')
628645
}
629646

630647
function dataPartFromChunk<METADATA>(
631648
message: UIMessage<METADATA>,
632-
chunk: Extract<UIMessageChunk, { type: `data-${string}` }>
649+
chunk: Extract<UIMessageChunk, { type: `data-${string}` }>,
633650
): DataPart {
634651
if (chunk.transient) {
635652
return {
@@ -642,17 +659,17 @@ function dataPartFromChunk<METADATA>(
642659
}
643660
const part = message.parts.find(
644661
(item): item is DataPart =>
645-
item.type === chunk.type &&
646-
item.type.startsWith('data-') &&
647-
item.id === chunk.id
662+
item.type === chunk.type && item.type.startsWith('data-') && item.id === chunk.id,
663+
)
664+
return (
665+
part ?? {
666+
type: chunk.type,
667+
id: chunk.id,
668+
name: chunk.name,
669+
data: chunk.data,
670+
transientData: false,
671+
}
648672
)
649-
return part ?? {
650-
type: chunk.type,
651-
id: chunk.id,
652-
name: chunk.name,
653-
data: chunk.data,
654-
transientData: false,
655-
}
656673
}
657674

658675
export function lastAssistantMessageIsCompleteWithApprovalResponses<METADATA = unknown>({
@@ -666,10 +683,10 @@ export function lastAssistantMessageIsCompleteWithApprovalResponses<METADATA = u
666683
}
667684
const approvalParts = assistant.parts.filter(
668685
(part): part is ToolPart =>
669-
isToolPart(part) && (part.state === 'approval-requested' || part.state === 'approval-responded')
686+
isToolPart(part) &&
687+
(part.state === 'approval-requested' || part.state === 'approval-responded'),
670688
)
671689
return (
672-
approvalParts.length > 0 &&
673-
approvalParts.every((part) => part.state === 'approval-responded')
690+
approvalParts.length > 0 && approvalParts.every((part) => part.state === 'approval-responded')
674691
)
675692
}

ui/packages/sdk/src/composables.test.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@ import { experimental_useObject } from './use-object'
1111
describe('useChat', () => {
1212
it('shares state by id', async () => {
1313
const fetch = async () =>
14-
new Response(streamFromText('data: {"type":"text-delta","id":"t","delta":"Hello"}\n\ndata: [DONE]\n\n'), {
15-
headers: { 'X-Halo-AI-UI-Message-Stream': 'v1' },
16-
})
14+
new Response(
15+
streamFromText('data: {"type":"text-delta","id":"t","delta":"Hello"}\n\ndata: [DONE]\n\n'),
16+
{
17+
headers: { 'X-Halo-AI-UI-Message-Stream': 'v1' },
18+
},
19+
)
1720

1821
const scope = effectScope()
1922
await scope.run(async () => {
@@ -33,9 +36,14 @@ describe('useChat', () => {
3336
id: 'external-chat',
3437
transport: new DefaultChatTransport({
3538
fetch: async () =>
36-
new Response(streamFromText('data: {"type":"text-delta","id":"t","delta":"Hello"}\n\ndata: [DONE]\n\n'), {
37-
headers: { 'X-Halo-AI-UI-Message-Stream': 'v1' },
38-
}),
39+
new Response(
40+
streamFromText(
41+
'data: {"type":"text-delta","id":"t","delta":"Hello"}\n\ndata: [DONE]\n\n',
42+
),
43+
{
44+
headers: { 'X-Halo-AI-UI-Message-Stream': 'v1' },
45+
},
46+
),
3947
}),
4048
})
4149

@@ -92,7 +100,7 @@ describe('useChat', () => {
92100
expect(() =>
93101
scope.run(() => {
94102
useChat({ chat, id: 'other-chat' })
95-
})
103+
}),
96104
).toThrow('useChat({ chat }) cannot be mixed with creation options: id.')
97105
scope.stop()
98106
})
@@ -138,17 +146,20 @@ describe('useChat', () => {
138146
type: 'tool-search',
139147
toolCallId: 'call-1',
140148
state: 'input-available',
141-
})
149+
}),
142150
)
143151
})
144152
scope.stop()
145153
})
146154

147155
it('accepts object throttle options', async () => {
148156
const fetch = async () =>
149-
new Response(streamFromText('data: {"type":"text-delta","id":"t","delta":"Hello"}\n\ndata: [DONE]\n\n'), {
150-
headers: { 'X-Halo-AI-UI-Message-Stream': 'v1' },
151-
})
157+
new Response(
158+
streamFromText('data: {"type":"text-delta","id":"t","delta":"Hello"}\n\ndata: [DONE]\n\n'),
159+
{
160+
headers: { 'X-Halo-AI-UI-Message-Stream': 'v1' },
161+
},
162+
)
152163

153164
const scope = effectScope()
154165
await scope.run(async () => {
@@ -348,7 +359,7 @@ describe('experimental_useObject', () => {
348359
expect(object.object.value).toEqual({ title: 'Draft' })
349360
await object.submit(
350361
{ prompt: 'Summarize' },
351-
{ body: { requestId: 'object-1' }, headers: { 'X-Object-Call': 'yes' } }
362+
{ body: { requestId: 'object-1' }, headers: { 'X-Object-Call': 'yes' } },
352363
)
353364

354365
expect(body).toMatchObject({

0 commit comments

Comments
 (0)