@assistant-ui/mcp-docs-server 0.1.33 → 0.1.34
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/.docs/organized/code-examples/waterfall.md +5 -5
- package/.docs/organized/code-examples/with-a2a.md +5 -5
- package/.docs/organized/code-examples/with-ag-ui.md +9 -9
- package/.docs/organized/code-examples/with-ai-sdk-v6.md +7 -7
- package/.docs/organized/code-examples/with-artifacts.md +37 -31
- package/.docs/organized/code-examples/with-assistant-transport.md +8 -8
- package/.docs/organized/code-examples/with-browser-extension.md +5 -5
- package/.docs/organized/code-examples/with-chain-of-thought.md +68 -47
- package/.docs/organized/code-examples/with-cloud-standalone.md +7 -7
- package/.docs/organized/code-examples/with-cloud.md +7 -7
- package/.docs/organized/code-examples/with-custom-thread-list.md +7 -7
- package/.docs/organized/code-examples/with-elevenlabs-conversational.md +8 -8
- package/.docs/organized/code-examples/with-elevenlabs-scribe.md +8 -8
- package/.docs/organized/code-examples/with-expo.md +33 -24
- package/.docs/organized/code-examples/with-external-store.md +5 -5
- package/.docs/organized/code-examples/with-ffmpeg.md +10 -10
- package/.docs/organized/code-examples/with-generative-ui.md +70 -64
- package/.docs/organized/code-examples/with-google-adk.md +6 -6
- package/.docs/organized/code-examples/with-heat-graph.md +5 -5
- package/.docs/organized/code-examples/with-image-generation.md +7 -7
- package/.docs/organized/code-examples/with-interactables.md +7 -7
- package/.docs/organized/code-examples/with-langchain.md +7 -7
- package/.docs/organized/code-examples/with-langgraph.md +30 -26
- package/.docs/organized/code-examples/with-livekit.md +8 -8
- package/.docs/organized/code-examples/with-mcp.md +8 -8
- package/.docs/organized/code-examples/with-opencode.md +6 -6
- package/.docs/organized/code-examples/with-react-hook-form.md +7 -7
- package/.docs/organized/code-examples/with-react-ink.md +295 -100
- package/.docs/organized/code-examples/with-react-router.md +11 -11
- package/.docs/organized/code-examples/with-resumable-stream.md +8 -8
- package/.docs/organized/code-examples/with-store.md +64 -64
- package/.docs/organized/code-examples/with-tanstack.md +8 -8
- package/.docs/organized/code-examples/with-tap-runtime.md +5 -5
- package/.docs/raw/docs/(docs)/architecture.mdx +52 -41
- package/.docs/raw/docs/(reference)/api-reference/external-store/message-conversion.mdx +1 -1
- package/.docs/raw/docs/(reference)/api-reference/external-store/runtime.mdx +3 -0
- package/.docs/raw/docs/(reference)/api-reference/integrations/react-ai-sdk.mdx +14 -3
- package/.docs/raw/docs/(reference)/api-reference/tools/toolkits.mdx +94 -3
- package/.docs/raw/docs/(reference)/api-reference/utilities/miscellaneous.mdx +5 -69
- package/.docs/raw/docs/ink/adapters.mdx +23 -1
- package/.docs/raw/docs/ink/hooks.mdx +20 -17
- package/.docs/raw/docs/migrations/toolkit-tools.mdx +14 -8
- package/.docs/raw/docs/react-native/hooks.mdx +25 -17
- package/.docs/raw/docs/runtimes/ag-ui/runtime-options.mdx +41 -0
- package/.docs/raw/docs/runtimes/ai-sdk/v6.mdx +3 -3
- package/.docs/raw/docs/runtimes/concepts/architecture.mdx +46 -4
- package/.docs/raw/docs/runtimes/custom/assistant-transport.mdx +54 -12
- package/.docs/raw/docs/runtimes/custom/external-store.mdx +62 -4
- package/.docs/raw/docs/runtimes/custom/local-runtime.mdx +12 -0
- package/.docs/raw/docs/runtimes/google-adk/hooks.mdx +9 -9
- package/.docs/raw/docs/runtimes/langgraph/streaming.mdx +13 -0
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-2.mdx +5 -5
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-3.mdx +3 -3
- package/.docs/raw/docs/tools/backend.mdx +19 -11
- package/.docs/raw/docs/tools/defining-tools.mdx +177 -52
- package/.docs/raw/docs/tools/index.mdx +7 -12
- package/.docs/raw/docs/tools/mcp.mdx +83 -15
- package/.docs/raw/docs/tools/multi-agent.mdx +5 -5
- package/.docs/raw/docs/tools/tool-ui.mdx +27 -27
- package/.docs/raw/docs/tools/user-managed-mcp.mdx +4 -4
- package/.docs/raw/docs/ui/mermaid.mdx +16 -9
- package/.docs/raw/docs/ui/part-grouping.mdx +2 -2
- package/.docs/raw/docs/ui/tool-fallback.mdx +16 -0
- package/.docs/raw/docs/utilities/react-o11y.mdx +2 -2
- package/dist/constants.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/prepare-docs/code-examples.js.map +1 -1
- package/dist/prepare-docs/copy-raw.js.map +1 -1
- package/dist/prepare-docs/prepare.js.map +1 -1
- package/dist/stdio.js.map +1 -1
- package/dist/tools/docs.js.map +1 -1
- package/dist/tools/examples.js.map +1 -1
- package/dist/tools/tests/test-setup.js.map +1 -1
- package/dist/utils/mdx.js.map +1 -1
- package/dist/utils/paths.js.map +1 -1
- package/package.json +4 -4
- /package/.docs/raw/docs/{(docs)/copilots → copilots}/assistant-frame.mdx +0 -0
- /package/.docs/raw/docs/{(docs)/copilots → copilots}/make-assistant-visible.mdx +0 -0
- /package/.docs/raw/docs/{(docs)/copilots → copilots}/model-context.mdx +0 -0
- /package/.docs/raw/docs/{(docs)/copilots → copilots}/motivation.mdx +0 -0
- /package/.docs/raw/docs/{(docs)/copilots → copilots}/use-assistant-instructions.mdx +0 -0
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
"@assistant-ui/react-ink": "workspace:*",
|
|
18
18
|
"@assistant-ui/react-ink-markdown": "workspace:*",
|
|
19
19
|
"ink": "^7.0.5",
|
|
20
|
-
"react": "^19.2.
|
|
20
|
+
"react": "^19.2.7"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@types/react": "^19.2.
|
|
23
|
+
"@types/react": "^19.2.17",
|
|
24
24
|
"esbuild": "^0.28.0",
|
|
25
25
|
"tsx": "^4.22.4",
|
|
26
26
|
"typescript": "^6.0.3"
|
|
@@ -37,74 +37,36 @@ import { Box, Text } from "ink";
|
|
|
37
37
|
import {
|
|
38
38
|
AssistantRuntimeProvider,
|
|
39
39
|
useLocalRuntime,
|
|
40
|
-
|
|
40
|
+
StatusBarPrimitive,
|
|
41
41
|
} from "@assistant-ui/react-ink";
|
|
42
42
|
import { Thread } from "./components/thread.js";
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// Simulate streaming with a markdown-rich response
|
|
55
|
-
const response = `## Response to your question
|
|
56
|
-
|
|
57
|
-
You asked: **"${userText}"**
|
|
58
|
-
|
|
59
|
-
Here's a quick example in JavaScript:
|
|
60
|
-
|
|
61
|
-
\`\`\`js
|
|
62
|
-
const promise = new Promise((resolve, reject) => {
|
|
63
|
-
setTimeout(() => resolve("done!"), 1000);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
promise.then(result => console.log(result));
|
|
67
|
-
\`\`\`
|
|
68
|
-
|
|
69
|
-
### Key points
|
|
70
|
-
|
|
71
|
-
- A \`Promise\` represents an **async operation**
|
|
72
|
-
- It can be *pending*, *fulfilled*, or *rejected*
|
|
73
|
-
- Use \`.then()\` and \`.catch()\` to handle results
|
|
74
|
-
|
|
75
|
-
> Promises are the foundation of modern async JavaScript.
|
|
76
|
-
|
|
77
|
-
| Method | Purpose |
|
|
78
|
-
|--------|---------|
|
|
79
|
-
| \`.then()\` | Handle success |
|
|
80
|
-
| \`.catch()\` | Handle errors |
|
|
81
|
-
| \`.finally()\` | Run cleanup |
|
|
82
|
-
|
|
83
|
-
Learn more at [MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).`;
|
|
84
|
-
const words = response.split(" ");
|
|
85
|
-
|
|
86
|
-
let accumulated = "";
|
|
87
|
-
for (const word of words) {
|
|
88
|
-
accumulated += (accumulated ? " " : "") + word;
|
|
89
|
-
yield { content: [{ type: "text" as const, text: accumulated }] };
|
|
90
|
-
await new Promise((r) => setTimeout(r, 50));
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
});
|
|
43
|
+
import { createScriptedAdapter, MODEL_NAME } from "./scripted-adapter.js";
|
|
44
|
+
import { ApplyPatchToolUI } from "./tools.js";
|
|
45
|
+
|
|
46
|
+
const StatusBar = () => (
|
|
47
|
+
<StatusBarPrimitive.Root>
|
|
48
|
+
<Text dimColor>
|
|
49
|
+
model: <StatusBarPrimitive.ModelName name={MODEL_NAME} /> ·{" "}
|
|
50
|
+
<StatusBarPrimitive.MessageCount /> · <StatusBarPrimitive.Status />
|
|
51
|
+
</Text>
|
|
52
|
+
</StatusBarPrimitive.Root>
|
|
53
|
+
);
|
|
94
54
|
|
|
95
55
|
export const App = () => {
|
|
96
|
-
const adapter = useMemo(() =>
|
|
56
|
+
const adapter = useMemo(() => createScriptedAdapter(), []);
|
|
97
57
|
const runtime = useLocalRuntime(adapter);
|
|
98
58
|
|
|
99
59
|
return (
|
|
100
60
|
<AssistantRuntimeProvider runtime={runtime}>
|
|
61
|
+
<ApplyPatchToolUI />
|
|
101
62
|
<Box flexDirection="column" padding={1}>
|
|
102
|
-
<
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
</
|
|
63
|
+
<Box>
|
|
64
|
+
<Text bold color="cyan">
|
|
65
|
+
demo-agent
|
|
66
|
+
</Text>
|
|
67
|
+
<Text dimColor>{" ~/acme-app"}</Text>
|
|
68
|
+
</Box>
|
|
69
|
+
<StatusBar />
|
|
108
70
|
<Box marginTop={1}>
|
|
109
71
|
<Thread />
|
|
110
72
|
</Box>
|
|
@@ -122,62 +84,68 @@ import { Box, Text } from "ink";
|
|
|
122
84
|
import {
|
|
123
85
|
ThreadPrimitive,
|
|
124
86
|
ComposerPrimitive,
|
|
125
|
-
|
|
87
|
+
MessagePrimitive,
|
|
88
|
+
ErrorPrimitive,
|
|
89
|
+
LoadingPrimitive,
|
|
90
|
+
LiveChecklist,
|
|
126
91
|
} from "@assistant-ui/react-ink";
|
|
127
92
|
import { MarkdownText } from "@assistant-ui/react-ink-markdown";
|
|
128
93
|
|
|
129
|
-
const UserMessage = () =>
|
|
130
|
-
|
|
131
|
-
s.message.parts
|
|
132
|
-
.filter((p) => p.type === "text")
|
|
133
|
-
.map((p) => ("text" in p ? p.text : ""))
|
|
134
|
-
.join(""),
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
return (
|
|
94
|
+
const UserMessage = () => (
|
|
95
|
+
<MessagePrimitive.Root>
|
|
138
96
|
<Box marginBottom={1}>
|
|
139
97
|
<Text bold color="green">
|
|
140
98
|
You:{" "}
|
|
141
99
|
</Text>
|
|
142
|
-
<
|
|
100
|
+
<MessagePrimitive.Content
|
|
101
|
+
renderText={({ part }) => <Text wrap="wrap">{part.text}</Text>}
|
|
102
|
+
/>
|
|
143
103
|
</Box>
|
|
144
|
-
|
|
145
|
-
|
|
104
|
+
</MessagePrimitive.Root>
|
|
105
|
+
);
|
|
146
106
|
|
|
147
|
-
const AssistantMessage = () =>
|
|
148
|
-
|
|
149
|
-
s.message.parts
|
|
150
|
-
.filter((p) => p.type === "text")
|
|
151
|
-
.map((p) => ("text" in p ? p.text : ""))
|
|
152
|
-
.join(""),
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
return (
|
|
107
|
+
const AssistantMessage = () => (
|
|
108
|
+
<MessagePrimitive.Root>
|
|
156
109
|
<Box flexDirection="column" marginBottom={1}>
|
|
157
110
|
<Text bold color="blue">
|
|
158
111
|
AI:
|
|
159
112
|
</Text>
|
|
160
|
-
<
|
|
113
|
+
<MessagePrimitive.Content
|
|
114
|
+
renderText={({ part }) => <MarkdownText text={part.text} />}
|
|
115
|
+
renderReasoning={({ part }) => (
|
|
116
|
+
<Text dimColor italic>
|
|
117
|
+
{part.text}
|
|
118
|
+
</Text>
|
|
119
|
+
)}
|
|
120
|
+
/>
|
|
121
|
+
<LiveChecklist title="Plan" showProgress marginTop={1} />
|
|
122
|
+
<ErrorPrimitive.Root>
|
|
123
|
+
<ErrorPrimitive.Message />
|
|
124
|
+
</ErrorPrimitive.Root>
|
|
161
125
|
</Box>
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
<
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
126
|
+
</MessagePrimitive.Root>
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const Loading = () => (
|
|
130
|
+
<LoadingPrimitive.Root marginBottom={1}>
|
|
131
|
+
<LoadingPrimitive.Spinner />
|
|
132
|
+
<Text> </Text>
|
|
133
|
+
<LoadingPrimitive.Text>Working</LoadingPrimitive.Text>
|
|
134
|
+
<Text> </Text>
|
|
135
|
+
<LoadingPrimitive.ElapsedTime />
|
|
136
|
+
</LoadingPrimitive.Root>
|
|
137
|
+
);
|
|
174
138
|
|
|
175
139
|
export const Thread = () => {
|
|
176
140
|
return (
|
|
177
141
|
<ThreadPrimitive.Root>
|
|
178
142
|
<ThreadPrimitive.Empty>
|
|
179
|
-
<Box marginBottom={1}>
|
|
180
|
-
<Text
|
|
143
|
+
<Box flexDirection="column" marginBottom={1}>
|
|
144
|
+
<Text>
|
|
145
|
+
Working in this project. <Text color="yellow">fetchUser()</Text> is
|
|
146
|
+
flaky in prod and has no retry logic.
|
|
147
|
+
</Text>
|
|
148
|
+
<Text dimColor>{' try: "make fetchUser retry on failure"'}</Text>
|
|
181
149
|
</Box>
|
|
182
150
|
</ThreadPrimitive.Empty>
|
|
183
151
|
|
|
@@ -187,13 +155,14 @@ export const Thread = () => {
|
|
|
187
155
|
}
|
|
188
156
|
</ThreadPrimitive.Messages>
|
|
189
157
|
|
|
190
|
-
<
|
|
158
|
+
<Loading />
|
|
191
159
|
|
|
192
160
|
<Box borderStyle="round" borderColor="gray" paddingX={1}>
|
|
193
161
|
<Text color="gray">{"> "}</Text>
|
|
194
162
|
<ComposerPrimitive.Input
|
|
195
163
|
submitOnEnter
|
|
196
|
-
|
|
164
|
+
multiLine
|
|
165
|
+
placeholder="Type a message... (Enter to send)"
|
|
197
166
|
autoFocus
|
|
198
167
|
/>
|
|
199
168
|
</Box>
|
|
@@ -242,6 +211,232 @@ render(<App />);
|
|
|
242
211
|
|
|
243
212
|
```
|
|
244
213
|
|
|
214
|
+
## src/scripted-adapter.ts
|
|
215
|
+
|
|
216
|
+
```typescript
|
|
217
|
+
import type {
|
|
218
|
+
ChatModelAdapter,
|
|
219
|
+
ThreadAssistantMessagePart,
|
|
220
|
+
} from "@assistant-ui/react-ink";
|
|
221
|
+
|
|
222
|
+
export const MODEL_NAME = "demo-agent";
|
|
223
|
+
|
|
224
|
+
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
225
|
+
|
|
226
|
+
const RETRY_PATCH = `--- a/src/retry.ts
|
|
227
|
+
+++ b/src/retry.ts
|
|
228
|
+
@@ -1,6 +1,18 @@
|
|
229
|
+
export async function fetchUser(id: string) {
|
|
230
|
+
- const res = await fetch(\`/api/users/\${id}\`);
|
|
231
|
+
- return res.json();
|
|
232
|
+
+ return retry(() => fetch(\`/api/users/\${id}\`).then((r) => r.json()));
|
|
233
|
+
+}
|
|
234
|
+
+
|
|
235
|
+
+export async function retry<T>(fn: () => Promise<T>, attempts = 3): Promise<T> {
|
|
236
|
+
+ let lastError: unknown;
|
|
237
|
+
+ for (let i = 0; i <= attempts; i++) {
|
|
238
|
+
+ try {
|
|
239
|
+
+ return await fn();
|
|
240
|
+
+ } catch (err) {
|
|
241
|
+
+ lastError = err;
|
|
242
|
+
+ await new Promise((r) => setTimeout(r, 2 ** i * 100));
|
|
243
|
+
+ }
|
|
244
|
+
+ }
|
|
245
|
+
+ throw lastError;
|
|
246
|
+
}
|
|
247
|
+
`;
|
|
248
|
+
|
|
249
|
+
const RETRY_PATCH_FIX = `--- a/src/retry.ts
|
|
250
|
+
+++ b/src/retry.ts
|
|
251
|
+
@@ -6,7 +6,7 @@ export async function retry<T>(fn: () => Promise<T>, attempts = 3): Promise<T> {
|
|
252
|
+
let lastError: unknown;
|
|
253
|
+
- for (let i = 0; i <= attempts; i++) {
|
|
254
|
+
+ for (let i = 0; i < attempts; i++) {
|
|
255
|
+
try {
|
|
256
|
+
return await fn();
|
|
257
|
+
} catch (err) {
|
|
258
|
+
`;
|
|
259
|
+
|
|
260
|
+
const isTaskRequest = (text: string) =>
|
|
261
|
+
/fetch|retry|resilient|flaky|backoff|robust|network|\byes\b|sure|\bok\b|go ahead|do it|please/i.test(
|
|
262
|
+
text,
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
const lastUserText = (
|
|
266
|
+
messages: readonly { role: string; content: readonly { type: string }[] }[],
|
|
267
|
+
) => {
|
|
268
|
+
const last = messages.filter((m) => m.role === "user").at(-1);
|
|
269
|
+
return (
|
|
270
|
+
last?.content
|
|
271
|
+
.filter((p): p is { type: "text"; text: string } => p.type === "text")
|
|
272
|
+
.map((p) => p.text)
|
|
273
|
+
.join("") ?? ""
|
|
274
|
+
);
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
async function* streamText(
|
|
278
|
+
parts: ThreadAssistantMessagePart[],
|
|
279
|
+
index: number,
|
|
280
|
+
text: string,
|
|
281
|
+
delay: number,
|
|
282
|
+
): AsyncGenerator<{ content: ThreadAssistantMessagePart[] }> {
|
|
283
|
+
for (const word of text.split(" ")) {
|
|
284
|
+
const p = parts[index] as Extract<
|
|
285
|
+
ThreadAssistantMessagePart,
|
|
286
|
+
{ type: "text" | "reasoning" }
|
|
287
|
+
>;
|
|
288
|
+
parts[index] = { ...p, text: p.text ? `${p.text} ${word}` : word };
|
|
289
|
+
yield { content: [...parts] };
|
|
290
|
+
await sleep(delay);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
async function* runAgentScript(): AsyncGenerator<{
|
|
295
|
+
content: ThreadAssistantMessagePart[];
|
|
296
|
+
}> {
|
|
297
|
+
const parts: ThreadAssistantMessagePart[] = [];
|
|
298
|
+
const emit = () => ({ content: [...parts] });
|
|
299
|
+
const setResult = (result: unknown, isError = false) => {
|
|
300
|
+
parts[parts.length - 1] = {
|
|
301
|
+
...parts[parts.length - 1],
|
|
302
|
+
result,
|
|
303
|
+
...(isError ? { isError: true } : {}),
|
|
304
|
+
} as ThreadAssistantMessagePart;
|
|
305
|
+
};
|
|
306
|
+
const pushToolCall = (
|
|
307
|
+
toolCallId: string,
|
|
308
|
+
toolName: string,
|
|
309
|
+
args: Record<string, string>,
|
|
310
|
+
) =>
|
|
311
|
+
parts.push({
|
|
312
|
+
type: "tool-call",
|
|
313
|
+
toolCallId,
|
|
314
|
+
toolName,
|
|
315
|
+
args,
|
|
316
|
+
argsText: JSON.stringify(args),
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
const reasoningIdx = parts.push({ type: "reasoning", text: "" }) - 1;
|
|
320
|
+
yield* streamText(
|
|
321
|
+
parts,
|
|
322
|
+
reasoningIdx,
|
|
323
|
+
"Let me look at how fetchUser is implemented, wrap it in retry-with-backoff, and run the tests to make sure it holds up.",
|
|
324
|
+
20,
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
pushToolCall("read-1", "read_file", { path: "src/retry.ts" });
|
|
328
|
+
yield emit();
|
|
329
|
+
await sleep(500);
|
|
330
|
+
setResult("12 lines read");
|
|
331
|
+
yield emit();
|
|
332
|
+
await sleep(300);
|
|
333
|
+
|
|
334
|
+
pushToolCall("patch-1", "apply_patch", {
|
|
335
|
+
path: "src/retry.ts",
|
|
336
|
+
patch: RETRY_PATCH,
|
|
337
|
+
});
|
|
338
|
+
yield emit();
|
|
339
|
+
await sleep(600);
|
|
340
|
+
setResult({ applied: true });
|
|
341
|
+
yield emit();
|
|
342
|
+
await sleep(300);
|
|
343
|
+
|
|
344
|
+
pushToolCall("test-1", "run_tests", { command: "pnpm test retry" });
|
|
345
|
+
yield emit();
|
|
346
|
+
await sleep(700);
|
|
347
|
+
setResult(
|
|
348
|
+
"FAIL src/retry.test.ts - retry() ran 4 times, expected 3 (off-by-one in loop bound)",
|
|
349
|
+
true,
|
|
350
|
+
);
|
|
351
|
+
yield emit();
|
|
352
|
+
await sleep(400);
|
|
353
|
+
|
|
354
|
+
const noteIdx = parts.push({ type: "text", text: "" }) - 1;
|
|
355
|
+
yield* streamText(
|
|
356
|
+
parts,
|
|
357
|
+
noteIdx,
|
|
358
|
+
"The loop bound was off by one. Tightening it and re-running.",
|
|
359
|
+
20,
|
|
360
|
+
);
|
|
361
|
+
|
|
362
|
+
pushToolCall("patch-2", "apply_patch", {
|
|
363
|
+
path: "src/retry.ts",
|
|
364
|
+
patch: RETRY_PATCH_FIX,
|
|
365
|
+
});
|
|
366
|
+
yield emit();
|
|
367
|
+
await sleep(500);
|
|
368
|
+
setResult({ applied: true });
|
|
369
|
+
yield emit();
|
|
370
|
+
await sleep(300);
|
|
371
|
+
|
|
372
|
+
pushToolCall("test-2", "run_tests", { command: "pnpm test retry" });
|
|
373
|
+
yield emit();
|
|
374
|
+
await sleep(600);
|
|
375
|
+
setResult("PASS src/retry.test.ts (3 passed)");
|
|
376
|
+
yield emit();
|
|
377
|
+
await sleep(300);
|
|
378
|
+
|
|
379
|
+
const summary = `### Done
|
|
380
|
+
|
|
381
|
+
Added a \`retry()\` helper and routed \`fetchUser\` through it:
|
|
382
|
+
|
|
383
|
+
- exponential backoff (\`100ms\`, \`200ms\`, \`400ms\`)
|
|
384
|
+
- rethrows the **last error** after exhausting attempts
|
|
385
|
+
- fixed an off-by-one that ran one extra attempt
|
|
386
|
+
|
|
387
|
+
Tests are green.`;
|
|
388
|
+
const summaryIdx = parts.push({ type: "text", text: "" }) - 1;
|
|
389
|
+
yield* streamText(parts, summaryIdx, summary, 15);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
async function* runProposalReply(): AsyncGenerator<{
|
|
393
|
+
content: ThreadAssistantMessagePart[];
|
|
394
|
+
}> {
|
|
395
|
+
const response = `I'm set up to work in this repo. The obvious thing to fix is the flaky \`fetchUser()\` call in \`src/retry.ts\` — it has no retry logic, so a single network blip fails the request.
|
|
396
|
+
|
|
397
|
+
Want me to wrap it in retry-with-backoff? Just say *make fetchUser retry on failure*.`;
|
|
398
|
+
let acc = "";
|
|
399
|
+
for (const word of response.split(" ")) {
|
|
400
|
+
acc += (acc ? " " : "") + word;
|
|
401
|
+
yield { content: [{ type: "text", text: acc }] };
|
|
402
|
+
await sleep(20);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export const createScriptedAdapter = (): ChatModelAdapter => ({
|
|
407
|
+
run({ messages }) {
|
|
408
|
+
return isTaskRequest(lastUserText(messages))
|
|
409
|
+
? runAgentScript()
|
|
410
|
+
: runProposalReply();
|
|
411
|
+
},
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
## src/tools.tsx
|
|
417
|
+
|
|
418
|
+
```tsx
|
|
419
|
+
import { Box, Text } from "ink";
|
|
420
|
+
import { makeAssistantToolUI, DiffView } from "@assistant-ui/react-ink";
|
|
421
|
+
|
|
422
|
+
export const ApplyPatchToolUI = makeAssistantToolUI<
|
|
423
|
+
{ path: string; patch: string },
|
|
424
|
+
unknown
|
|
425
|
+
>({
|
|
426
|
+
toolName: "apply_patch",
|
|
427
|
+
render: ({ args }) => {
|
|
428
|
+
if (!args?.patch) return null;
|
|
429
|
+
return (
|
|
430
|
+
<Box flexDirection="column" marginBottom={1}>
|
|
431
|
+
<Text color="cyan">edit {args.path}</Text>
|
|
432
|
+
<DiffView patch={args.patch} showLineNumbers />
|
|
433
|
+
</Box>
|
|
434
|
+
);
|
|
435
|
+
},
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
```
|
|
439
|
+
|
|
245
440
|
## tsconfig.json
|
|
246
441
|
|
|
247
442
|
```json
|
|
@@ -773,30 +773,30 @@ export default function Home() {
|
|
|
773
773
|
"dependencies": {
|
|
774
774
|
"@assistant-ui/react": "workspace:*",
|
|
775
775
|
"@assistant-ui/react-markdown": "workspace:*",
|
|
776
|
-
"@react-router/node": "^7.
|
|
777
|
-
"@react-router/serve": "^7.
|
|
776
|
+
"@react-router/node": "^7.17.0",
|
|
777
|
+
"@react-router/serve": "^7.17.0",
|
|
778
778
|
"class-variance-authority": "^0.7.1",
|
|
779
779
|
"clsx": "^2.1.1",
|
|
780
780
|
"eventsource-parser": "^3.1.0",
|
|
781
|
-
"isbot": "^5.1.
|
|
781
|
+
"isbot": "^5.1.41",
|
|
782
782
|
"lucide-react": "^1.17.0",
|
|
783
|
-
"openai": "^6.
|
|
784
|
-
"react": "^19.2.
|
|
785
|
-
"react-dom": "^19.2.
|
|
786
|
-
"react-router": "^7.
|
|
783
|
+
"openai": "^6.42.0",
|
|
784
|
+
"react": "^19.2.7",
|
|
785
|
+
"react-dom": "^19.2.7",
|
|
786
|
+
"react-router": "^7.17.0",
|
|
787
787
|
"remark-gfm": "^4.0.1",
|
|
788
788
|
"tailwind-merge": "^3.6.0"
|
|
789
789
|
},
|
|
790
790
|
"devDependencies": {
|
|
791
|
-
"@react-router/dev": "^7.
|
|
791
|
+
"@react-router/dev": "^7.17.0",
|
|
792
792
|
"@tailwindcss/vite": "^4.3.0",
|
|
793
|
-
"@types/node": "^25.9.
|
|
794
|
-
"@types/react": "^19.2.
|
|
793
|
+
"@types/node": "^25.9.2",
|
|
794
|
+
"@types/react": "^19.2.17",
|
|
795
795
|
"@types/react-dom": "^19.2.3",
|
|
796
796
|
"tailwindcss": "^4.3.0",
|
|
797
797
|
"tw-animate-css": "^1.4.0",
|
|
798
798
|
"typescript": "^6.0.3",
|
|
799
|
-
"vite": "^8.0.
|
|
799
|
+
"vite": "^8.0.16",
|
|
800
800
|
"vite-tsconfig-paths": "^6.1.1"
|
|
801
801
|
}
|
|
802
802
|
}
|
|
@@ -514,22 +514,22 @@ export default withAui(nextConfig);
|
|
|
514
514
|
"start": "next start"
|
|
515
515
|
},
|
|
516
516
|
"dependencies": {
|
|
517
|
-
"@ai-sdk/openai": "^3.0.
|
|
518
|
-
"@ai-sdk/react": "^3.0.
|
|
517
|
+
"@ai-sdk/openai": "^3.0.68",
|
|
518
|
+
"@ai-sdk/react": "^3.0.199",
|
|
519
519
|
"@assistant-ui/react": "workspace:*",
|
|
520
520
|
"@assistant-ui/react-ai-sdk": "workspace:*",
|
|
521
521
|
"@assistant-ui/react-markdown": "workspace:*",
|
|
522
522
|
"@assistant-ui/store": "workspace:*",
|
|
523
523
|
"@assistant-ui/tap": "workspace:*",
|
|
524
524
|
"@assistant-ui/ui": "workspace:*",
|
|
525
|
-
"ai": "^6.0.
|
|
525
|
+
"ai": "^6.0.197",
|
|
526
526
|
"assistant-stream": "workspace:*",
|
|
527
527
|
"class-variance-authority": "^0.7.1",
|
|
528
528
|
"clsx": "^2.1.1",
|
|
529
529
|
"lucide-react": "^1.17.0",
|
|
530
|
-
"next": "^16.2.
|
|
531
|
-
"react": "^19.2.
|
|
532
|
-
"react-dom": "^19.2.
|
|
530
|
+
"next": "^16.2.7",
|
|
531
|
+
"react": "^19.2.7",
|
|
532
|
+
"react-dom": "^19.2.7",
|
|
533
533
|
"redis": "^6.0.0",
|
|
534
534
|
"tailwind-merge": "^3.6.0",
|
|
535
535
|
"zod": "^4.4.3"
|
|
@@ -538,8 +538,8 @@ export default withAui(nextConfig);
|
|
|
538
538
|
"@assistant-ui/next": "workspace:*",
|
|
539
539
|
"@assistant-ui/x-buildutils": "workspace:*",
|
|
540
540
|
"@tailwindcss/postcss": "^4.3.0",
|
|
541
|
-
"@types/node": "^25.9.
|
|
542
|
-
"@types/react": "^19.2.
|
|
541
|
+
"@types/node": "^25.9.2",
|
|
542
|
+
"@types/react": "^19.2.17",
|
|
543
543
|
"@types/react-dom": "^19.2.3",
|
|
544
544
|
"postcss": "^8.5.15",
|
|
545
545
|
"tailwindcss": "^4.3.0",
|