@vercel/geistdocs 1.14.2 → 1.15.0
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/cli/index.js +1 -1
- package/dist/config.d.ts +16 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/internal/chat/message-metadata.d.ts.map +1 -1
- package/dist/internal/chat/message-metadata.js +17 -2
- package/dist/internal/chat/shell.js +1 -1
- package/dist/internal/cn.d.ts.map +1 -1
- package/dist/internal/cn.js +45 -1
- package/dist/internal/eve-agent.d.ts +76 -0
- package/dist/internal/eve-agent.d.ts.map +1 -0
- package/dist/internal/eve-agent.js +541 -0
- package/dist/internal/sidebar.js +5 -5
- package/dist/pages/docs.js +1 -1
- package/dist/routes/chat.d.ts +20 -3
- package/dist/routes/chat.d.ts.map +1 -1
- package/dist/routes/chat.js +95 -1
- package/docs/agents.md +1 -1
- package/docs/llms.txt +46 -2
- package/docs/manifest.json +1 -1
- package/docs/pages/ask-ai.md +35 -1
- package/docs/pages/configuration.md +10 -0
- package/package.json +2 -1
- package/template/AGENTS.md +2 -1
- package/template/content/docs/ask-ai.mdx +35 -1
- package/template/content/docs/configuration.mdx +10 -0
- package/template/package.json +1 -1
- package/theme.css +35 -15
|
@@ -0,0 +1,541 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client for the eve framework's session HTTP API, translating eve's NDJSON
|
|
3
|
+
* event stream into AI SDK UI message chunks.
|
|
4
|
+
*
|
|
5
|
+
* Wire contract (stable across eve deployments):
|
|
6
|
+
* - `POST {url}/eve/v1/session` starts a session; responds
|
|
7
|
+
* `{ ok, sessionId, continuationToken }`.
|
|
8
|
+
* - `POST {url}/eve/v1/session/:sessionId` sends a follow-up with
|
|
9
|
+
* `{ continuationToken, message }`; responds `{ ok, sessionId }`. A stale
|
|
10
|
+
* token silently starts a new session (the response `sessionId` changes).
|
|
11
|
+
* - `GET {url}/eve/v1/session/:sessionId/stream?startIndex=N` streams
|
|
12
|
+
* newline-delimited JSON events. The stream stays open after
|
|
13
|
+
* `session.waiting`, so the client disconnects at turn boundaries and
|
|
14
|
+
* counts consumed lines to resume from an absolute cursor.
|
|
15
|
+
* - `POST {url}/eve/v1/session/:sessionId/cancel` cancels the in-flight turn.
|
|
16
|
+
*/
|
|
17
|
+
const EVE_SESSION_PATH = "/eve/v1/session";
|
|
18
|
+
const CANCEL_TIMEOUT_MS = 5000;
|
|
19
|
+
const MAX_TRANSCRIPT_TURN_CHARS = 2000;
|
|
20
|
+
const MAX_TRANSCRIPT_TOTAL_CHARS = 8000;
|
|
21
|
+
const MAX_SOURCES_PER_ACTION = 5;
|
|
22
|
+
const TRAILING_SLASH_PATTERN = /\/+$/;
|
|
23
|
+
const HTTP_URL_PATTERN = /^https?:\/\//;
|
|
24
|
+
const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25
|
+
const normalizeAgentUrl = (url) => url.replace(TRAILING_SLASH_PATTERN, "");
|
|
26
|
+
const getMessageText = (message) => message.parts
|
|
27
|
+
.filter((part) => part.type === "text")
|
|
28
|
+
.map((part) => part.text)
|
|
29
|
+
.join("\n");
|
|
30
|
+
const isSessionHandle = (value) => isRecord(value) &&
|
|
31
|
+
typeof value.sessionId === "string" &&
|
|
32
|
+
value.sessionId.length > 0 &&
|
|
33
|
+
typeof value.continuationToken === "string" &&
|
|
34
|
+
value.continuationToken.length > 0 &&
|
|
35
|
+
typeof value.streamIndex === "number" &&
|
|
36
|
+
Number.isInteger(value.streamIndex) &&
|
|
37
|
+
value.streamIndex >= 0;
|
|
38
|
+
/**
|
|
39
|
+
* Read the eve session handle persisted on the most recent assistant
|
|
40
|
+
* message. The handle round-trips through the client: it is written to
|
|
41
|
+
* message metadata by the `finish` chunk and sent back with the full
|
|
42
|
+
* message history on the next request.
|
|
43
|
+
*/
|
|
44
|
+
export const getEveAgentSessionHandle = (messages) => {
|
|
45
|
+
for (let index = messages.length - 1; index >= 0; index--) {
|
|
46
|
+
const message = messages[index];
|
|
47
|
+
if (message?.role !== "assistant") {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const handle = message.metadata
|
|
51
|
+
?.eveAgent;
|
|
52
|
+
return isSessionHandle(handle) ? handle : null;
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
};
|
|
56
|
+
const truncate = (value, limit) => value.length > limit ? `${value.slice(0, limit)}...` : value;
|
|
57
|
+
/**
|
|
58
|
+
* Resolve the eve agent URL from the route option and site config, and
|
|
59
|
+
* reject ambiguous responder configuration. Pure so the fail-fast contract
|
|
60
|
+
* stays unit-testable outside a bundler.
|
|
61
|
+
*/
|
|
62
|
+
export const resolveEveAgentUrl = ({ configUrl, hasProxy, optionUrl, }) => {
|
|
63
|
+
const url = optionUrl ?? configUrl ?? null;
|
|
64
|
+
if (url && hasProxy) {
|
|
65
|
+
throw new Error("createChatRoute received both proxy and an eve agent (ai.eveAgent in geistdocs.tsx or the eveAgent option). Configure exactly one responder.");
|
|
66
|
+
}
|
|
67
|
+
return url;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Cap the text of the trailing user message. The chat client limits input
|
|
71
|
+
* to 1000 characters, but the route is publicly reachable and must not
|
|
72
|
+
* forward arbitrarily large payloads to the agent.
|
|
73
|
+
*/
|
|
74
|
+
export const capLastUserMessageText = (messages, limit) => {
|
|
75
|
+
const lastMessage = messages.at(-1);
|
|
76
|
+
if (lastMessage?.role !== "user") {
|
|
77
|
+
return messages;
|
|
78
|
+
}
|
|
79
|
+
const text = getMessageText(lastMessage);
|
|
80
|
+
if (text.length <= limit) {
|
|
81
|
+
return messages;
|
|
82
|
+
}
|
|
83
|
+
return [
|
|
84
|
+
...messages.slice(0, -1),
|
|
85
|
+
{
|
|
86
|
+
...lastMessage,
|
|
87
|
+
parts: [{ type: "text", text: truncate(text, limit) }],
|
|
88
|
+
},
|
|
89
|
+
];
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Inline prior conversation turns into a single message for a fresh eve
|
|
93
|
+
* session. Used when history exists but no (valid) session handle does —
|
|
94
|
+
* for example after the client's daily history reset.
|
|
95
|
+
*/
|
|
96
|
+
export const buildEveAgentTranscript = (messages, currentMessage) => {
|
|
97
|
+
const priorMessages = messages.slice(0, -1);
|
|
98
|
+
if (priorMessages.length === 0) {
|
|
99
|
+
return currentMessage;
|
|
100
|
+
}
|
|
101
|
+
const lines = [];
|
|
102
|
+
let total = 0;
|
|
103
|
+
for (const message of priorMessages) {
|
|
104
|
+
if (message.role !== "user" && message.role !== "assistant") {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const text = getMessageText(message).trim();
|
|
108
|
+
if (!text) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const label = message.role === "user" ? "User" : "Assistant";
|
|
112
|
+
const line = `${label}: ${truncate(text, MAX_TRANSCRIPT_TURN_CHARS)}`;
|
|
113
|
+
if (total + line.length > MAX_TRANSCRIPT_TOTAL_CHARS) {
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
lines.push(line);
|
|
117
|
+
total += line.length;
|
|
118
|
+
}
|
|
119
|
+
if (lines.length === 0) {
|
|
120
|
+
return currentMessage;
|
|
121
|
+
}
|
|
122
|
+
return `Previous conversation (for context):\n\n${lines.join("\n\n")}\n\n---\n\nCurrent message: ${currentMessage}`;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Extract http(s) URLs from a tool result so agent-side retrieval can
|
|
126
|
+
* surface citations. Conservative by design: only string values under
|
|
127
|
+
* keys named `url` (or `href`) are considered.
|
|
128
|
+
*/
|
|
129
|
+
export const extractSourceUrls = (value, limit = MAX_SOURCES_PER_ACTION) => {
|
|
130
|
+
const sources = [];
|
|
131
|
+
const seen = new Set();
|
|
132
|
+
const visit = (node) => {
|
|
133
|
+
if (sources.length >= limit) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (Array.isArray(node)) {
|
|
137
|
+
for (const item of node) {
|
|
138
|
+
visit(item);
|
|
139
|
+
}
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (!isRecord(node)) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const url = node.url ?? node.href;
|
|
146
|
+
if (typeof url === "string" &&
|
|
147
|
+
HTTP_URL_PATTERN.test(url) &&
|
|
148
|
+
!seen.has(url)) {
|
|
149
|
+
seen.add(url);
|
|
150
|
+
sources.push({
|
|
151
|
+
url,
|
|
152
|
+
title: typeof node.title === "string" ? node.title : undefined,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
for (const child of Object.values(node)) {
|
|
156
|
+
visit(child);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
visit(value);
|
|
160
|
+
return sources;
|
|
161
|
+
};
|
|
162
|
+
const parseSessionResponse = async (response) => {
|
|
163
|
+
const body = await response.json();
|
|
164
|
+
if (!isRecord(body) || typeof body.sessionId !== "string") {
|
|
165
|
+
throw new Error("eve agent returned an invalid session response.");
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
continuationToken: typeof body.continuationToken === "string"
|
|
169
|
+
? body.continuationToken
|
|
170
|
+
: null,
|
|
171
|
+
sessionId: body.sessionId,
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
const isTurnBoundaryEvent = (type) => type === "session.waiting" ||
|
|
175
|
+
type === "session.completed" ||
|
|
176
|
+
type === "session.failed";
|
|
177
|
+
const createEveEventTranslator = (writer) => {
|
|
178
|
+
let blockCounter = 0;
|
|
179
|
+
let openTextId = null;
|
|
180
|
+
let openReasoningId = null;
|
|
181
|
+
let continuationToken = null;
|
|
182
|
+
const knownToolCalls = new Map();
|
|
183
|
+
const emittedSourceUrls = new Set();
|
|
184
|
+
const closeTextBlock = () => {
|
|
185
|
+
if (openTextId) {
|
|
186
|
+
writer.write({ type: "text-end", id: openTextId });
|
|
187
|
+
openTextId = null;
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
const closeReasoningBlock = () => {
|
|
191
|
+
if (openReasoningId) {
|
|
192
|
+
writer.write({ type: "reasoning-end", id: openReasoningId });
|
|
193
|
+
openReasoningId = null;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
const writeTextDelta = (delta) => {
|
|
197
|
+
closeReasoningBlock();
|
|
198
|
+
if (!openTextId) {
|
|
199
|
+
blockCounter += 1;
|
|
200
|
+
openTextId = `eve-text-${blockCounter}`;
|
|
201
|
+
writer.write({ type: "text-start", id: openTextId });
|
|
202
|
+
}
|
|
203
|
+
if (delta) {
|
|
204
|
+
writer.write({ type: "text-delta", id: openTextId, delta });
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
const writeReasoningDelta = (delta) => {
|
|
208
|
+
closeTextBlock();
|
|
209
|
+
if (!openReasoningId) {
|
|
210
|
+
blockCounter += 1;
|
|
211
|
+
openReasoningId = `eve-reasoning-${blockCounter}`;
|
|
212
|
+
writer.write({ type: "reasoning-start", id: openReasoningId });
|
|
213
|
+
}
|
|
214
|
+
if (delta) {
|
|
215
|
+
writer.write({ type: "reasoning-delta", id: openReasoningId, delta });
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
const getActionName = (action) => action.toolName ??
|
|
219
|
+
action.subagentName ??
|
|
220
|
+
action.name ??
|
|
221
|
+
action.kind ??
|
|
222
|
+
"action";
|
|
223
|
+
const handleActionsRequested = (data) => {
|
|
224
|
+
if (!Array.isArray(data.actions)) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
closeTextBlock();
|
|
228
|
+
closeReasoningBlock();
|
|
229
|
+
for (const action of data.actions) {
|
|
230
|
+
if (!isRecord(action) || typeof action.callId !== "string") {
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
const toolName = getActionName(action);
|
|
234
|
+
knownToolCalls.set(action.callId, toolName);
|
|
235
|
+
writer.write({
|
|
236
|
+
type: "tool-input-available",
|
|
237
|
+
toolCallId: action.callId,
|
|
238
|
+
toolName,
|
|
239
|
+
input: action.input ?? {},
|
|
240
|
+
dynamic: true,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
const writeSourceChunks = (output) => {
|
|
245
|
+
for (const source of extractSourceUrls(output)) {
|
|
246
|
+
if (emittedSourceUrls.has(source.url)) {
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
emittedSourceUrls.add(source.url);
|
|
250
|
+
writer.write({
|
|
251
|
+
type: "source-url",
|
|
252
|
+
sourceId: `eve-source-${emittedSourceUrls.size}`,
|
|
253
|
+
url: source.url,
|
|
254
|
+
title: source.title,
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
const handleActionResult = (data) => {
|
|
259
|
+
const result = data.result;
|
|
260
|
+
if (!(isRecord(result) && typeof result.callId === "string")) {
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
if (!knownToolCalls.has(result.callId)) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const failed = data.status === "failed" ||
|
|
267
|
+
data.status === "rejected" ||
|
|
268
|
+
result.isError === true;
|
|
269
|
+
if (failed) {
|
|
270
|
+
const error = data.error;
|
|
271
|
+
const fallbackErrorText = data.status === "rejected"
|
|
272
|
+
? "The action was rejected."
|
|
273
|
+
: "The action failed.";
|
|
274
|
+
writer.write({
|
|
275
|
+
type: "tool-output-error",
|
|
276
|
+
toolCallId: result.callId,
|
|
277
|
+
errorText: isRecord(error) && typeof error.message === "string"
|
|
278
|
+
? error.message
|
|
279
|
+
: fallbackErrorText,
|
|
280
|
+
dynamic: true,
|
|
281
|
+
});
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
writer.write({
|
|
285
|
+
type: "tool-output-available",
|
|
286
|
+
toolCallId: result.callId,
|
|
287
|
+
output: result.output ?? null,
|
|
288
|
+
dynamic: true,
|
|
289
|
+
});
|
|
290
|
+
writeSourceChunks(result.output);
|
|
291
|
+
};
|
|
292
|
+
const handleInputRequested = (data) => {
|
|
293
|
+
if (!Array.isArray(data.requests)) {
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
for (const request of data.requests) {
|
|
297
|
+
if (isRecord(request) && typeof request.prompt === "string") {
|
|
298
|
+
writeTextDelta(`${request.prompt}\n`);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
const handleFailure = (data) => {
|
|
303
|
+
closeTextBlock();
|
|
304
|
+
closeReasoningBlock();
|
|
305
|
+
writer.write({
|
|
306
|
+
type: "error",
|
|
307
|
+
errorText: data && typeof data.message === "string"
|
|
308
|
+
? data.message
|
|
309
|
+
: "The agent failed to answer.",
|
|
310
|
+
});
|
|
311
|
+
};
|
|
312
|
+
const eventHandlers = {
|
|
313
|
+
"message.appended": (data) => {
|
|
314
|
+
if (typeof data?.messageDelta === "string") {
|
|
315
|
+
writeTextDelta(data.messageDelta);
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
"message.completed": () => closeTextBlock(),
|
|
319
|
+
"reasoning.appended": (data) => {
|
|
320
|
+
if (typeof data?.reasoningDelta === "string") {
|
|
321
|
+
writeReasoningDelta(data.reasoningDelta);
|
|
322
|
+
}
|
|
323
|
+
},
|
|
324
|
+
"reasoning.completed": () => closeReasoningBlock(),
|
|
325
|
+
"actions.requested": (data) => {
|
|
326
|
+
if (data) {
|
|
327
|
+
handleActionsRequested(data);
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
"action.result": (data) => {
|
|
331
|
+
if (data) {
|
|
332
|
+
handleActionResult(data);
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
"input.requested": (data) => {
|
|
336
|
+
if (data) {
|
|
337
|
+
handleInputRequested(data);
|
|
338
|
+
}
|
|
339
|
+
},
|
|
340
|
+
"session.waiting": (data) => {
|
|
341
|
+
if (typeof data?.continuationToken === "string") {
|
|
342
|
+
continuationToken = data.continuationToken;
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
"turn.failed": handleFailure,
|
|
346
|
+
"session.failed": handleFailure,
|
|
347
|
+
};
|
|
348
|
+
// Unknown event types (step.*, subagent.*, compaction.*, ...) are
|
|
349
|
+
// intentionally ignored for forward compatibility.
|
|
350
|
+
const handleEvent = (event) => {
|
|
351
|
+
eventHandlers[event.type]?.(isRecord(event.data) ? event.data : undefined);
|
|
352
|
+
};
|
|
353
|
+
return {
|
|
354
|
+
handleEvent,
|
|
355
|
+
finalize: () => {
|
|
356
|
+
closeTextBlock();
|
|
357
|
+
closeReasoningBlock();
|
|
358
|
+
},
|
|
359
|
+
getContinuationToken: () => continuationToken,
|
|
360
|
+
};
|
|
361
|
+
};
|
|
362
|
+
const startOrContinueSession = async ({ agentUrl, fallbackMessage, fetchImpl, handle, headers, message, signal, }) => {
|
|
363
|
+
if (handle) {
|
|
364
|
+
const response = await fetchImpl(`${agentUrl}${EVE_SESSION_PATH}/${encodeURIComponent(handle.sessionId)}`, {
|
|
365
|
+
method: "POST",
|
|
366
|
+
body: JSON.stringify({
|
|
367
|
+
continuationToken: handle.continuationToken,
|
|
368
|
+
message,
|
|
369
|
+
}),
|
|
370
|
+
headers,
|
|
371
|
+
signal,
|
|
372
|
+
});
|
|
373
|
+
if (response.ok) {
|
|
374
|
+
const session = await parseSessionResponse(response);
|
|
375
|
+
// A stale continuation token silently starts a new session; detect
|
|
376
|
+
// it via the changed sessionId and restart the stream cursor. The
|
|
377
|
+
// message was already delivered to the forked session, so context
|
|
378
|
+
// from prior turns cannot be re-inlined at this point.
|
|
379
|
+
return session.sessionId === handle.sessionId
|
|
380
|
+
? { sessionId: session.sessionId, startIndex: handle.streamIndex }
|
|
381
|
+
: { sessionId: session.sessionId, startIndex: 0 };
|
|
382
|
+
}
|
|
383
|
+
// The session was reaped: fall back to a fresh session that carries
|
|
384
|
+
// the inlined conversation context. Any other failure (including 5xx
|
|
385
|
+
// transient outages) surfaces as an error so a still-valid session is
|
|
386
|
+
// not silently discarded.
|
|
387
|
+
if (response.status !== 404) {
|
|
388
|
+
throw new Error(`eve agent follow-up failed with status ${response.status}.`);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
const response = await fetchImpl(`${agentUrl}${EVE_SESSION_PATH}`, {
|
|
392
|
+
method: "POST",
|
|
393
|
+
body: JSON.stringify({ message: handle ? fallbackMessage : message }),
|
|
394
|
+
headers,
|
|
395
|
+
signal,
|
|
396
|
+
});
|
|
397
|
+
if (!response.ok) {
|
|
398
|
+
throw new Error(`eve agent session create failed with status ${response.status}.`);
|
|
399
|
+
}
|
|
400
|
+
const session = await parseSessionResponse(response);
|
|
401
|
+
return { sessionId: session.sessionId, startIndex: 0 };
|
|
402
|
+
};
|
|
403
|
+
const streamSessionEvents = async ({ agentUrl, fetchImpl, headers, onEvent, sessionId, signal, startIndex, }) => {
|
|
404
|
+
const query = startIndex > 0 ? `?startIndex=${startIndex}` : "";
|
|
405
|
+
const response = await fetchImpl(`${agentUrl}${EVE_SESSION_PATH}/${encodeURIComponent(sessionId)}/stream${query}`, { headers, signal });
|
|
406
|
+
if (!response.ok) {
|
|
407
|
+
throw new Error(`eve agent stream failed with status ${response.status}.`);
|
|
408
|
+
}
|
|
409
|
+
if (!response.body) {
|
|
410
|
+
throw new Error("eve agent stream returned an empty response body.");
|
|
411
|
+
}
|
|
412
|
+
const reader = response.body.getReader();
|
|
413
|
+
const decoder = new TextDecoder();
|
|
414
|
+
let buffer = "";
|
|
415
|
+
let consumed = 0;
|
|
416
|
+
const processLine = (line) => {
|
|
417
|
+
const trimmed = line.trim();
|
|
418
|
+
if (!trimmed) {
|
|
419
|
+
return false;
|
|
420
|
+
}
|
|
421
|
+
consumed += 1;
|
|
422
|
+
let event;
|
|
423
|
+
try {
|
|
424
|
+
event = JSON.parse(trimmed);
|
|
425
|
+
}
|
|
426
|
+
catch {
|
|
427
|
+
// Skip malformed lines instead of failing the whole turn.
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
if (!isRecord(event) || typeof event.type !== "string") {
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
return onEvent(event);
|
|
434
|
+
};
|
|
435
|
+
try {
|
|
436
|
+
while (true) {
|
|
437
|
+
const { done, value } = await reader.read();
|
|
438
|
+
buffer += decoder.decode(value, { stream: !done });
|
|
439
|
+
let newlineIndex = buffer.indexOf("\n");
|
|
440
|
+
while (newlineIndex !== -1) {
|
|
441
|
+
const line = buffer.slice(0, newlineIndex);
|
|
442
|
+
buffer = buffer.slice(newlineIndex + 1);
|
|
443
|
+
if (processLine(line)) {
|
|
444
|
+
return consumed;
|
|
445
|
+
}
|
|
446
|
+
newlineIndex = buffer.indexOf("\n");
|
|
447
|
+
}
|
|
448
|
+
if (done) {
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
if (buffer.trim()) {
|
|
453
|
+
processLine(buffer);
|
|
454
|
+
}
|
|
455
|
+
return consumed;
|
|
456
|
+
}
|
|
457
|
+
finally {
|
|
458
|
+
// The eve stream stays open after `session.waiting`; release the
|
|
459
|
+
// connection once the turn boundary is reached.
|
|
460
|
+
await reader.cancel().catch(() => {
|
|
461
|
+
// The reader may already be released or errored.
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
const cancelSession = ({ agentUrl, fetchImpl, headers, sessionId, }) => fetchImpl(`${agentUrl}${EVE_SESSION_PATH}/${encodeURIComponent(sessionId)}/cancel`, {
|
|
466
|
+
method: "POST",
|
|
467
|
+
body: JSON.stringify({}),
|
|
468
|
+
headers,
|
|
469
|
+
// Bound the cancel call so an unresponsive agent cannot hold the
|
|
470
|
+
// (already aborted) invocation open until maxDuration.
|
|
471
|
+
signal: AbortSignal.timeout(CANCEL_TIMEOUT_MS),
|
|
472
|
+
}).catch(() => {
|
|
473
|
+
// Cancellation is fire-and-forget; the turn ends client-side even if
|
|
474
|
+
// the cancel request fails.
|
|
475
|
+
});
|
|
476
|
+
/**
|
|
477
|
+
* Run a single Ask AI turn against a hosted eve agent, writing AI SDK UI
|
|
478
|
+
* message chunks to the provided writer.
|
|
479
|
+
*/
|
|
480
|
+
export const runEveAgentTurn = async ({ agentUrl, fallbackMessage, fetchImpl = fetch, handle = null, headers, initialChunks = [], message, signal, writer, }) => {
|
|
481
|
+
const normalizedUrl = normalizeAgentUrl(agentUrl);
|
|
482
|
+
writer.write({ type: "start" });
|
|
483
|
+
for (const chunk of initialChunks) {
|
|
484
|
+
writer.write(chunk);
|
|
485
|
+
}
|
|
486
|
+
const { sessionId, startIndex } = await startOrContinueSession({
|
|
487
|
+
agentUrl: normalizedUrl,
|
|
488
|
+
fallbackMessage: fallbackMessage ?? message,
|
|
489
|
+
fetchImpl,
|
|
490
|
+
handle,
|
|
491
|
+
headers,
|
|
492
|
+
message,
|
|
493
|
+
signal,
|
|
494
|
+
});
|
|
495
|
+
const translator = createEveEventTranslator(writer);
|
|
496
|
+
let consumed = 0;
|
|
497
|
+
try {
|
|
498
|
+
consumed = await streamSessionEvents({
|
|
499
|
+
agentUrl: normalizedUrl,
|
|
500
|
+
fetchImpl,
|
|
501
|
+
headers,
|
|
502
|
+
sessionId,
|
|
503
|
+
signal,
|
|
504
|
+
startIndex,
|
|
505
|
+
onEvent: (event) => {
|
|
506
|
+
translator.handleEvent(event);
|
|
507
|
+
return isTurnBoundaryEvent(event.type);
|
|
508
|
+
},
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
catch (error) {
|
|
512
|
+
if (signal?.aborted) {
|
|
513
|
+
// The user stopped the response; ask the agent to stop working too.
|
|
514
|
+
await cancelSession({
|
|
515
|
+
agentUrl: normalizedUrl,
|
|
516
|
+
fetchImpl,
|
|
517
|
+
headers,
|
|
518
|
+
sessionId,
|
|
519
|
+
});
|
|
520
|
+
translator.finalize();
|
|
521
|
+
writer.write({ type: "finish" });
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
throw error;
|
|
525
|
+
}
|
|
526
|
+
translator.finalize();
|
|
527
|
+
const continuationToken = translator.getContinuationToken();
|
|
528
|
+
if (continuationToken) {
|
|
529
|
+
const nextHandle = {
|
|
530
|
+
continuationToken,
|
|
531
|
+
sessionId,
|
|
532
|
+
streamIndex: startIndex + consumed,
|
|
533
|
+
};
|
|
534
|
+
writer.write({
|
|
535
|
+
type: "finish",
|
|
536
|
+
messageMetadata: { eveAgent: nextHandle },
|
|
537
|
+
});
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
writer.write({ type: "finish" });
|
|
541
|
+
};
|
package/dist/internal/sidebar.js
CHANGED
|
@@ -149,7 +149,7 @@ const SidebarTreeNode = ({ depth, node, path, state, }) => {
|
|
|
149
149
|
const isGroup = depth === 0;
|
|
150
150
|
const menuId = getDomId(state.idPrefix, nodeId);
|
|
151
151
|
const labelId = `${menuId}-label`;
|
|
152
|
-
const rowClassName = cn("flex h-9 origin-left touch-manipulation flex-row items-center rounded-md pr-1 pl-2.5
|
|
152
|
+
const rowClassName = cn("flex h-9 origin-left touch-manipulation flex-row items-center rounded-md pr-1 pl-2.5 motion-reduce:transition-none", getSidebarRowTone(isSelected, isGroup));
|
|
153
153
|
const content = (_jsxs(_Fragment, { children: [node.icon ? (_jsx("span", { className: "shrink-0 [&_svg]:size-4", children: node.icon })) : null, _jsxs("span", { className: "flex min-w-0 flex-1 items-center gap-1.5 truncate text-button-14", children: [_jsx("span", { className: "min-w-0 flex-1 truncate", id: labelId, children: node.name }), _jsx(SidebarBadge, { label: badge }), isExternalSidebarItem(item) ? (_jsx(ArrowUpRightIcon, { className: "ml-auto size-4 shrink-0 text-gray-900" })) : null] })] }));
|
|
154
154
|
const handleLinkClick = (event) => {
|
|
155
155
|
state.onNavigate?.();
|
|
@@ -169,7 +169,7 @@ const SidebarTreeNode = ({ depth, node, path, state, }) => {
|
|
|
169
169
|
else {
|
|
170
170
|
primaryControl = (_jsx("span", { className: cn(rowClassName, "min-w-0 flex-1"), children: content }));
|
|
171
171
|
}
|
|
172
|
-
return (_jsxs("li", { className: cn("relative flex w-full select-none flex-col items-stretch", depth > 0 && "pl-3"), children: [_jsxs("div", { className: "relative flex w-full items-center gap-px", children: [primaryControl, item && folder && hasChildren ? (_jsx("button", { "aria-controls": menuId, "aria-expanded": isExpanded, "aria-labelledby": labelId, className: "grid size-8 flex-none cursor-pointer touch-manipulation place-content-center rounded-md bg-transparent p-0 text-gray-900
|
|
172
|
+
return (_jsxs("li", { className: cn("relative flex w-full select-none flex-col items-stretch", depth > 0 && "pl-3"), children: [_jsxs("div", { className: "relative flex w-full items-center gap-px", children: [primaryControl, item && folder && hasChildren ? (_jsx("button", { "aria-controls": menuId, "aria-expanded": isExpanded, "aria-labelledby": labelId, className: "grid size-8 flex-none cursor-pointer touch-manipulation place-content-center rounded-md bg-transparent p-0 text-gray-900 hover:bg-gray-alpha-100 focus-visible:shadow-[var(--ds-focus-ring)] focus-visible:outline-none active:bg-gray-alpha-300 motion-reduce:transition-none", onClick: () => state.toggleFolder(folder, path), type: "button", children: _jsx(SidebarDisclosureIcon, { expanded: isExpanded }) })) : null] }), folder && hasChildren && isExpanded ? (_jsx("ul", { className: "relative mt-px mb-1 flex w-full list-none flex-col gap-px p-0", id: menuId, children: _jsx(SidebarTreeItems, { depth: depth + 1, nodes: folder.children, parentPath: path, state: state }) })) : null] }));
|
|
173
173
|
};
|
|
174
174
|
const SidebarTree = ({ activeUrl, idScope, nodes, onNavigate, openFirstLevel = false, scrollActive = false, visible = true, }) => {
|
|
175
175
|
const generatedId = useId().replace(UNSAFE_ID_CHARACTERS, "");
|
|
@@ -200,7 +200,7 @@ const SidebarRootItem = ({ activeSection, activeUrl, item, onSelect, }) => {
|
|
|
200
200
|
const separateDisclosure = hasSeparateRootDisclosure(item);
|
|
201
201
|
const isCurrentPage = linkItem?.url === activeUrl;
|
|
202
202
|
const isActive = item === activeSection || isCurrentPage;
|
|
203
|
-
const className = cn("flex h-9 touch-manipulation items-center gap-2 rounded-md pr-2 pl-2.5 no-underline outline-none
|
|
203
|
+
const className = cn("flex h-9 touch-manipulation items-center gap-2 rounded-md pr-2 pl-2.5 no-underline outline-none focus-visible:shadow-[var(--ds-focus-ring)] motion-reduce:transition-none", isActive
|
|
204
204
|
? "bg-gray-200 text-gray-1000 active:bg-gray-300"
|
|
205
205
|
: "text-gray-900 hover:bg-gray-alpha-100 hover:text-gray-1000 active:bg-gray-alpha-300");
|
|
206
206
|
const content = (_jsxs(_Fragment, { children: [item.icon ? (_jsx("span", { className: "shrink-0 [&_svg]:size-4", children: item.icon })) : null, _jsx("span", { className: "min-w-0 flex-1 truncate text-button-14", children: item.name }), _jsx(SidebarBadge, { label: badge }), isExternalSidebarItem(linkItem) ? (_jsx(ArrowUpRightIcon, { className: "size-4 shrink-0 text-gray-900" })) : null, opensSection && !separateDisclosure ? (_jsx(IconChevronRight, { className: "shrink-0 text-gray-900", size: 16 })) : null] }));
|
|
@@ -220,9 +220,9 @@ const SidebarRootItem = ({ activeSection, activeUrl, item, onSelect, }) => {
|
|
|
220
220
|
else {
|
|
221
221
|
renderedItem = _jsx("span", { className: className, children: content });
|
|
222
222
|
}
|
|
223
|
-
return (_jsxs("li", { className: cn(separateDisclosure && "flex items-center gap-px"), children: [renderedItem, separateDisclosure ? (_jsx("button", { "aria-label": getRootDisclosureLabel(item.name), className: "grid size-8 flex-none cursor-pointer touch-manipulation place-content-center rounded-md bg-transparent p-0 text-gray-900
|
|
223
|
+
return (_jsxs("li", { className: cn(separateDisclosure && "flex items-center gap-px"), children: [renderedItem, separateDisclosure ? (_jsx("button", { "aria-label": getRootDisclosureLabel(item.name), className: "grid size-8 flex-none cursor-pointer touch-manipulation place-content-center rounded-md bg-transparent p-0 text-gray-900 hover:bg-gray-alpha-100 focus-visible:shadow-[var(--ds-focus-ring)] focus-visible:outline-none active:bg-gray-alpha-300 motion-reduce:transition-none", onClick: (event) => onSelect(item, event.currentTarget), type: "button", children: _jsx(IconChevronRight, { size: 16 }) })) : null] }));
|
|
224
224
|
};
|
|
225
|
-
const SidebarSectionHeader = ({ buttonRef, onBack, section, }) => (_jsx("div", { className: "mb-2 px-2 pt-1", children: _jsxs("button", { "aria-label": "Back to all documentation sections", className: "flex w-full cursor-pointer touch-manipulation flex-row items-center justify-between gap-1 rounded-md border-0 bg-transparent p-0 text-gray-900
|
|
225
|
+
const SidebarSectionHeader = ({ buttonRef, onBack, section, }) => (_jsx("div", { className: "mb-2 px-2 pt-1", children: _jsxs("button", { "aria-label": "Back to all documentation sections", className: "flex w-full cursor-pointer touch-manipulation flex-row items-center justify-between gap-1 rounded-md border-0 bg-transparent p-0 text-gray-900 hover:bg-gray-alpha-100 hover:text-gray-1000 focus-visible:bg-gray-alpha-100 focus-visible:text-gray-1000 focus-visible:shadow-[var(--ds-focus-ring)] focus-visible:outline-none active:bg-gray-alpha-300 motion-reduce:transition-none", onClick: onBack, ref: buttonRef, type: "button", children: [_jsx("span", { className: "grid size-9 flex-none place-content-center", children: _jsx(IconChevronRight, { className: "rotate-180", size: 16 }) }), _jsx("span", { className: "flex min-w-0 flex-1 items-center justify-center text-button-14", children: _jsx("span", { className: "truncate", children: section.name }) }), _jsx("span", { className: "size-9 flex-none" })] }) }));
|
|
226
226
|
const DesktopSidebar = ({ activeUrl, nodes, rootScope, top, }) => {
|
|
227
227
|
const groups = useMemo(() => getSidebarRootGroups(nodes), [nodes]);
|
|
228
228
|
const currentSection = useMemo(() => findActiveRootSection(nodes, activeUrl), [activeUrl, nodes]);
|
package/dist/pages/docs.js
CHANGED
|
@@ -19,7 +19,7 @@ export const resolvePageMarkdownUrl = ({ basePath, pageUrl, isRootMountedPage =
|
|
|
19
19
|
}
|
|
20
20
|
return `${normalizedPublicPageUrl}.md`;
|
|
21
21
|
};
|
|
22
|
-
const DocsTitle = ({ className, ...props }) => (_jsx(FumadocsDocsTitle, { className: cn("mb-4 text-balance
|
|
22
|
+
const DocsTitle = ({ className, ...props }) => (_jsx(FumadocsDocsTitle, { className: cn("mb-4 text-balance", className), ...props }));
|
|
23
23
|
const DocsDescription = (props) => _jsx(FumadocsDocsDescription, { ...props });
|
|
24
24
|
const DocsBody = ({ className, ...props }) => (_jsx(FumadocsDocsBody, { className: cn("mx-auto w-full", className), ...props }));
|
|
25
25
|
const hasTableOfContentsActions = (config, extraActions) => config.pageActions?.scrollTop !== false ||
|
package/dist/routes/chat.d.ts
CHANGED
|
@@ -6,20 +6,37 @@ interface ChatProxyConfig {
|
|
|
6
6
|
headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
|
|
7
7
|
url: string;
|
|
8
8
|
}
|
|
9
|
+
interface ChatEveAgentOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Extra headers for requests to the eve agent, replacing the default
|
|
12
|
+
* `Authorization: Bearer <Vercel OIDC token>` when an `authorization`
|
|
13
|
+
* header is provided. Accepts an async function for per-request tokens.
|
|
14
|
+
* Server-only: never expose auth material through `geistdocs.tsx`.
|
|
15
|
+
*/
|
|
16
|
+
headers?: HeadersInit | (() => HeadersInit | Promise<HeadersInit>);
|
|
17
|
+
/** Overrides `config.ai.eveAgent.url` (e.g. for a staging agent). */
|
|
18
|
+
url?: string;
|
|
19
|
+
}
|
|
9
20
|
interface CreateChatRouteOptions {
|
|
10
21
|
config: Pick<GeistdocsConfig, "ai" | "basePath" | "defaultLanguage" | "translations">;
|
|
22
|
+
/**
|
|
23
|
+
* Server-side options for the eve agent responder configured through
|
|
24
|
+
* `config.ai.eveAgent`. Mutually exclusive with `proxy`.
|
|
25
|
+
*/
|
|
26
|
+
eveAgent?: ChatEveAgentOptions;
|
|
11
27
|
/**
|
|
12
28
|
* Model used to answer Ask AI requests in the default AI Gateway mode.
|
|
13
29
|
* Accepts any AI SDK `LanguageModel`, including AI Gateway model strings
|
|
14
|
-
* such as `"xai/grok-4.5"`. Ignored in proxy
|
|
15
|
-
* service selects the model. Defaults to
|
|
30
|
+
* such as `"xai/grok-4.5"`. Ignored in proxy and eve agent modes, where
|
|
31
|
+
* the external service selects the model. Defaults to
|
|
32
|
+
* `"openai/gpt-4.1-mini"`.
|
|
16
33
|
*/
|
|
17
34
|
model?: LanguageModel;
|
|
18
35
|
proxy?: ChatProxyConfig;
|
|
19
36
|
source?: SourceBundle;
|
|
20
37
|
sources?: SourceBundle[];
|
|
21
38
|
}
|
|
22
|
-
export declare const createChatRoute: ({ config, model, proxy, source, sources, }: CreateChatRouteOptions) => {
|
|
39
|
+
export declare const createChatRoute: ({ config, eveAgent, model, proxy, source, sources, }: CreateChatRouteOptions) => {
|
|
23
40
|
POST: (req: Request) => Promise<Response>;
|
|
24
41
|
maxDuration: 800;
|
|
25
42
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/routes/chat.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/routes/chat.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,aAAa,EAQnB,MAAM,IAAI,CAAC;AAGZ,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,WAAW,CAAC;AAShE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEvD,KAAK,YAAY,GAAG,qBAAqB,CAAC;AAyB1C,UAAU,eAAe;IACvB,OAAO,CAAC,EAAE,WAAW,GAAG,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IACnE,GAAG,EAAE,MAAM,CAAC;CACb;AAED,UAAU,mBAAmB;IAC3B;;;;;OAKG;IACH,OAAO,CAAC,EAAE,WAAW,GAAG,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IACnE,qEAAqE;IACrE,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,UAAU,sBAAsB;IAC9B,MAAM,EAAE,IAAI,CACV,eAAe,EACf,IAAI,GAAG,UAAU,GAAG,iBAAiB,GAAG,cAAc,CACvD,CAAC;IACF;;;OAGG;IACH,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IAC/B;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;CAC1B;AAozBD,eAAO,MAAM,eAAe,GAAI,sDAO7B,sBAAsB;gBASE,OAAO;;CA0JjC,CAAC"}
|