@kuralle-agents/hono-server 0.3.20 → 0.4.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/index.d.ts CHANGED
@@ -7,7 +7,8 @@ export { createKuralleSseChatRouter, type KuralleSseChatRouterOptions } from './
7
7
  import { type StreamEventFilter } from './streamFilter.js';
8
8
  type FlowStreamPart = {
9
9
  type: string;
10
- text?: string;
10
+ id?: string;
11
+ delta?: string;
11
12
  error?: string;
12
13
  };
13
14
  type FlowRouterManager = {
package/dist/index.js CHANGED
@@ -56,7 +56,7 @@ const collectResponse = async (runtime, message, sessionId, userId) => {
56
56
  let resolvedSessionId = sessionId ?? '';
57
57
  for await (const part of iterateRuntimeParts(runtime, { input: message, sessionId, userId })) {
58
58
  if (part.type === 'text-delta') {
59
- response += part.text;
59
+ response += part.delta;
60
60
  }
61
61
  if (part.type === 'error') {
62
62
  throw new Error(part.error);
@@ -183,7 +183,7 @@ export const createKuralleChatRouter = ({ runtime, upgradeWebSocket, widgetWelco
183
183
  userId: body.userId,
184
184
  })) {
185
185
  if (part.type === 'text-delta') {
186
- controller.enqueue(encoder.encode(part.text));
186
+ controller.enqueue(encoder.encode(part.delta));
187
187
  }
188
188
  }
189
189
  }
@@ -409,10 +409,14 @@ export const createKuralleChatRouter = ({ runtime, upgradeWebSocket, widgetWelco
409
409
  if (effectiveWelcomeMode !== 'off') {
410
410
  const staticWelcome = widgetWelcomeMessage?.trim();
411
411
  if (effectiveWelcomeMode === 'static') {
412
+ const welcomeId = crypto.randomUUID();
413
+ ws.send(JSON.stringify({ type: 'text-start', id: welcomeId }));
412
414
  ws.send(JSON.stringify({
413
415
  type: 'text-delta',
414
- text: staticWelcome || 'Hello! How can I help you today?',
416
+ id: welcomeId,
417
+ delta: staticWelcome || 'Hello! How can I help you today?',
415
418
  }));
419
+ ws.send(JSON.stringify({ type: 'text-end', id: welcomeId }));
416
420
  const suggestions = (widgetWelcomeSuggestions ?? [])
417
421
  .filter((item) => typeof item === 'string')
418
422
  .map((item) => item.trim())
@@ -446,10 +450,14 @@ export const createKuralleChatRouter = ({ runtime, upgradeWebSocket, widgetWelco
446
450
  catch (error) {
447
451
  console.error(`[Kuralle] Failed to send greeting for session ${sessionId}:`, error);
448
452
  // Send a simple greeting if streaming fails
453
+ const fallbackId = crypto.randomUUID();
454
+ ws.send(JSON.stringify({ type: 'text-start', id: fallbackId }));
449
455
  ws.send(JSON.stringify({
450
456
  type: 'text-delta',
451
- text: 'Hello! How can I help you today?',
457
+ id: fallbackId,
458
+ delta: 'Hello! How can I help you today?',
452
459
  }));
460
+ ws.send(JSON.stringify({ type: 'text-end', id: fallbackId }));
453
461
  ws.send(JSON.stringify({
454
462
  type: 'done',
455
463
  sessionId,
@@ -557,7 +565,7 @@ const collectFlowResponse = async (flowManager, message) => {
557
565
  let response = '';
558
566
  for await (const part of flowManager.process(message)) {
559
567
  if (part.type === 'text-delta') {
560
- response += part.text;
568
+ response += part.delta;
561
569
  }
562
570
  if (part.type === 'error') {
563
571
  throw new Error(part.error);
@@ -620,7 +628,7 @@ export const createKuralleRouter = ({ flowManager, sessionId, upgradeWebSocket,
620
628
  try {
621
629
  for await (const part of flowManager.process(input)) {
622
630
  if (part.type === 'text-delta') {
623
- controller.enqueue(encoder.encode(part.text));
631
+ controller.enqueue(encoder.encode(part.delta));
624
632
  }
625
633
  }
626
634
  }
@@ -175,7 +175,7 @@ async function collectTurn(handle, clientTools) {
175
175
  if (stopEarly)
176
176
  continue;
177
177
  if (part.type === 'text-delta') {
178
- text += part.text;
178
+ text += part.delta;
179
179
  }
180
180
  else if (part.type === 'tool-call') {
181
181
  if (!clientTools.has(part.toolName))
@@ -283,10 +283,10 @@ async function handleChatCompletions(c, body, opts) {
283
283
  if (stopEarly)
284
284
  continue;
285
285
  if (part.type === 'text-delta') {
286
- if (!part.text)
286
+ if (!part.delta)
287
287
  continue;
288
- completionText += part.text;
289
- await writeChunk({ content: part.text });
288
+ completionText += part.delta;
289
+ await writeChunk({ content: part.delta });
290
290
  }
291
291
  else if (part.type === 'tool-call') {
292
292
  if (!clientToolSet.has(part.toolName))
@@ -1,5 +1,8 @@
1
1
  const SAFE_EVENT_TYPES = new Set([
2
+ 'text-start',
2
3
  'text-delta',
4
+ 'text-end',
5
+ 'text-cancel',
3
6
  'text-clear',
4
7
  'done',
5
8
  'error',
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "url": "git+https://github.com/kuralle/kuralle-agents.git",
7
7
  "directory": "packages/kuralle-hono-server"
8
8
  },
9
- "version": "0.3.20",
9
+ "version": "0.4.0",
10
10
  "description": "Hono router for hosting Kuralle createRuntime() over HTTP, SSE, and WebSocket",
11
11
  "type": "module",
12
12
  "main": "dist/index.js",
@@ -20,10 +20,10 @@
20
20
  "dependencies": {
21
21
  "ai": "^6.0.0",
22
22
  "hono": "^4.0.0",
23
- "@kuralle-agents/core": "0.3.20"
23
+ "@kuralle-agents/core": "0.4.0"
24
24
  },
25
25
  "peerDependencies": {
26
- "@kuralle-agents/core": "0.3.20"
26
+ "@kuralle-agents/core": "0.4.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@ai-sdk/openai": "^3.0.0",