@kuralle-agents/messaging 0.12.0 → 0.14.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/README.md CHANGED
@@ -15,7 +15,7 @@ Provides the `PlatformClient` interface that every messaging vendor package impl
15
15
  - **`createMessagingRouter`** — creates a Hono router with webhook endpoints for each platform. Routes inbound messages to a `Runtime` turn, streams responses back as text or interactive messages, and handles deduplication and messaging window tracking automatically.
16
16
  - **`PlatformClient`** — interface that normalizes sending, receiving, media, webhooks, and format conversion across vendors. Implement this to add any messaging platform.
17
17
  - **`SessionResolver`** — maps inbound messages to Kuralle session IDs. Default: `{platform}:{threadId}`. Swap in `ThreadIdResolver`, `PhoneLookupResolver`, or a custom `SessionResolverChain`.
18
- - **`StreamMapper`** — consumes `AsyncIterable<HarnessStreamPart>`, sends typing indicators during streaming, delegates final output to a `ResponseMapper`.
18
+ - **`StreamMapper`** — consumes `AsyncIterable<StreamPart>`, sends typing indicators during streaming, delegates final output to a `ResponseMapper`.
19
19
  - **`InboundLedger`** — async claim/append/complete ledger for tenant-scoped inbound idempotency and ordering.
20
20
  - **`WindowTracker`** / **`WindowStore`** — tracks 24-hour messaging windows per thread; used by `createMessagingRouter` to detect expired windows.
21
21
  - **`OutboundPipeline`** + **`windowGuard`** — window-safe outbound path (see below).
@@ -97,5 +97,5 @@ try {
97
97
 
98
98
  ## Related
99
99
 
100
- - [`@kuralle-agents/messaging-meta`](../kuralle-messaging-meta) — WhatsApp, Messenger, and Instagram clients
101
- - [`@kuralle-agents/core`](../kuralle-core) — runtime, agents, flows
100
+ - [`@kuralle-agents/messaging-meta`](../messaging-meta) — WhatsApp, Messenger, and Instagram clients
101
+ - [`@kuralle-agents/core`](../core) — runtime, agents, flows
@@ -210,12 +210,12 @@ function turnResult(parts) {
210
210
  return {
211
211
  parts,
212
212
  suspended: suspendedPart(parts),
213
- handoffToHuman: parts.some((part) => part.type === 'handoff' && part.targetAgent === 'human'),
213
+ handoffToHuman: parts.some((part) => part.type === 'handoff' && part.payload.targetAgent === 'human'),
214
214
  };
215
215
  }
216
216
  function suspendedPart(parts) {
217
217
  const paused = parts.find((part) => part.type === 'paused');
218
- return paused ? { signalId: paused.waitingFor } : undefined;
218
+ return paused ? { signalId: paused.payload.waitingFor } : undefined;
219
219
  }
220
220
  async function sendFallback(args) {
221
221
  const resolved = await (args.config.sessionResolver ?? defaultSessionResolver).resolve(args.message);
@@ -1,8 +1,8 @@
1
- import type { HarnessStreamPart } from '@kuralle-agents/core';
1
+ import type { StreamPart } from '@kuralle-agents/core';
2
2
  import type { PlatformClient, StreamMapperOptions } from '../types.js';
3
3
  export declare class StreamMapper {
4
- mapStream(stream: AsyncIterable<HarnessStreamPart>, platform: PlatformClient, threadId: string, options: StreamMapperOptions): Promise<HarnessStreamPart[]>;
5
- mapParts(parts: HarnessStreamPart[], platform: PlatformClient, threadId: string, options: StreamMapperOptions, textOverride?: string): Promise<void>;
4
+ mapStream(stream: AsyncIterable<StreamPart>, platform: PlatformClient, threadId: string, options: StreamMapperOptions): Promise<StreamPart[]>;
5
+ mapParts(parts: StreamPart[], platform: PlatformClient, threadId: string, options: StreamMapperOptions, textOverride?: string): Promise<void>;
6
6
  private buildMeta;
7
7
  private sendFreeform;
8
8
  private defaultMapResponse;
@@ -33,7 +33,7 @@ export class StreamMapper {
33
33
  for await (const part of stream) {
34
34
  parts.push(part);
35
35
  if (part.type === 'text-delta') {
36
- textBuffer += part.delta;
36
+ textBuffer += part.payload.delta;
37
37
  }
38
38
  }
39
39
  typingActive = false;
@@ -50,7 +50,7 @@ export class StreamMapper {
50
50
  const text = textOverride ??
51
51
  parts
52
52
  .filter((part) => part.type === 'text-delta')
53
- .map((part) => part.delta)
53
+ .map((part) => part.payload.delta)
54
54
  .join('');
55
55
  const meta = await this.buildMeta(options.windowStore, threadId, parts, options.sessionId, options.userId);
56
56
  if (options.responseMapper) {
@@ -93,7 +93,7 @@ export class StreamMapper {
93
93
  .find((part) => part.type === 'interactive');
94
94
  if (interactivePart) {
95
95
  const trimmed = text.trim();
96
- if (trimmed.length > 0 && trimmed !== interactivePart.prompt.trim()) {
96
+ if (trimmed.length > 0 && trimmed !== interactivePart.payload.prompt.trim()) {
97
97
  await pipeline.send({
98
98
  threadId,
99
99
  platform: platform.platform,
@@ -106,7 +106,7 @@ export class StreamMapper {
106
106
  platform: platform.platform,
107
107
  payload: {
108
108
  kind: 'interactive',
109
- interactive: renderChoices(interactivePart.options, interactivePart.prompt),
109
+ interactive: renderChoices(interactivePart.payload.options, interactivePart.payload.prompt),
110
110
  },
111
111
  meta,
112
112
  });
@@ -1,4 +1,4 @@
1
- import type { HarnessStreamPart, ResolvedSelection, SignalDelivery, UserInputContent } from '@kuralle-agents/core';
1
+ import type { StreamPart, ResolvedSelection, SignalDelivery, UserInputContent } from '@kuralle-agents/core';
2
2
  import type { ConsentStore } from '../adapter/consent-store.js';
3
3
  import type { MediaResolver } from './ports.js';
4
4
  import type { OwnershipStore } from '../adapter/ownership-store.js';
@@ -43,7 +43,7 @@ export type InboundEvent = {
43
43
  };
44
44
  };
45
45
  export interface TurnResult {
46
- parts: HarnessStreamPart[];
46
+ parts: StreamPart[];
47
47
  suspended?: {
48
48
  signalId: string;
49
49
  };
@@ -88,7 +88,7 @@ export interface InboundRuntime {
88
88
  }
89
89
  export type InboundOutcome = {
90
90
  kind: 'ran';
91
- parts: HarnessStreamPart[];
91
+ parts: StreamPart[];
92
92
  } | {
93
93
  kind: 'suspended';
94
94
  signalId: string;
@@ -1,22 +1,22 @@
1
- import type { HarnessStreamPart } from '@kuralle-agents/core';
2
- type Part<T extends HarnessStreamPart['type']> = Extract<HarnessStreamPart, {
1
+ import type { StreamPart } from '@kuralle-agents/core';
2
+ type Part<T extends StreamPart['type']> = Extract<StreamPart, {
3
3
  type: T;
4
4
  }>;
5
5
  export declare const filterStreamParts: {
6
- readonly textDelta: (p: HarnessStreamPart) => p is Part<"text-delta">;
7
- readonly toolCall: (p: HarnessStreamPart) => p is Part<"tool-call">;
8
- readonly toolResult: (p: HarnessStreamPart) => p is Part<"tool-result">;
9
- readonly handoff: (p: HarnessStreamPart) => p is Part<"handoff">;
10
- readonly nodeEnter: (p: HarnessStreamPart) => p is Part<"node-enter">;
11
- readonly nodeExit: (p: HarnessStreamPart) => p is Part<"node-exit">;
12
- readonly flowEnter: (p: HarnessStreamPart) => p is Part<"flow-enter">;
13
- readonly flowTransition: (p: HarnessStreamPart) => p is Part<"flow-transition">;
14
- readonly flowEnd: (p: HarnessStreamPart) => p is Part<"flow-end">;
15
- readonly turnEnd: (p: HarnessStreamPart) => p is Part<"turn-end">;
16
- readonly done: (p: HarnessStreamPart) => p is Part<"done">;
17
- readonly errorEvent: (p: HarnessStreamPart) => p is Part<"error">;
18
- readonly interrupted: (p: HarnessStreamPart) => p is Part<"interrupted">;
19
- readonly paused: (p: HarnessStreamPart) => p is Part<"paused">;
20
- readonly conversationOutcome: (p: HarnessStreamPart) => p is Part<"conversation-outcome">;
6
+ readonly textDelta: (p: StreamPart) => p is Part<"text-delta">;
7
+ readonly toolCall: (p: StreamPart) => p is Part<"tool-call">;
8
+ readonly toolResult: (p: StreamPart) => p is Part<"tool-result">;
9
+ readonly handoff: (p: StreamPart) => p is Part<"handoff">;
10
+ readonly nodeEnter: (p: StreamPart) => p is Part<"node-enter">;
11
+ readonly nodeExit: (p: StreamPart) => p is Part<"node-exit">;
12
+ readonly flowEnter: (p: StreamPart) => p is Part<"flow-enter">;
13
+ readonly flowTransition: (p: StreamPart) => p is Part<"flow-transition">;
14
+ readonly flowEnd: (p: StreamPart) => p is Part<"flow-end">;
15
+ readonly turnEnd: (p: StreamPart) => p is Part<"turn-end">;
16
+ readonly done: (p: StreamPart) => p is Part<"done">;
17
+ readonly errorEvent: (p: StreamPart) => p is Part<"error">;
18
+ readonly interrupted: (p: StreamPart) => p is Part<"interrupted">;
19
+ readonly paused: (p: StreamPart) => p is Part<"paused">;
20
+ readonly conversationOutcome: (p: StreamPart) => p is Part<"conversation-outcome">;
21
21
  };
22
22
  export {};
@@ -4,7 +4,7 @@
4
4
  * Adapter types: session resolution, response mapping, error context,
5
5
  * router config, and stream mapper options.
6
6
  */
7
- import type { RuntimeLike, HarnessStreamPart, ResolvedSelection, UserInputContent, InjectableTimer } from '@kuralle-agents/core';
7
+ import type { RuntimeLike, StreamPart, ResolvedSelection, UserInputContent, InjectableTimer } from '@kuralle-agents/core';
8
8
  import type { OutboundPipeline } from '../adapter/outbound-pipeline.js';
9
9
  import type { WindowStore } from '../adapter/window-store.js';
10
10
  import type { ConsentStore } from '../adapter/consent-store.js';
@@ -37,7 +37,7 @@ export interface ResponseContext {
37
37
  * Custom mapper that controls how Kuralle stream output is sent to the platform.
38
38
  */
39
39
  export interface ResponseMapper {
40
- mapResponse(parts: HarnessStreamPart[], context: ResponseContext): Promise<void>;
40
+ mapResponse(parts: StreamPart[], context: ResponseContext): Promise<void>;
41
41
  }
42
42
  /** Error context provided to the onError callback. */
43
43
  export interface ErrorContext {
@@ -1,4 +1,4 @@
1
- import type { HarnessStreamPart } from '@kuralle-agents/core';
1
+ import type { StreamPart } from '@kuralle-agents/core';
2
2
  import type { WindowState } from '../adapter/window-store.js';
3
3
  import type { InteractiveMessage, MediaPayload } from './messages.js';
4
4
  import type { SendResult } from './responses.js';
@@ -50,7 +50,7 @@ export type OutboundPayload = {
50
50
  };
51
51
  export interface OutboundMeta {
52
52
  window: WindowState;
53
- parts: HarnessStreamPart[];
53
+ parts: StreamPart[];
54
54
  sessionId: string;
55
55
  userId?: string;
56
56
  }
package/package.json CHANGED
@@ -4,9 +4,9 @@
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/kuralle/kuralle-agents.git",
7
- "directory": "packages/kuralle-messaging"
7
+ "directory": "packages/messaging"
8
8
  },
9
- "version": "0.12.0",
9
+ "version": "0.14.0",
10
10
  "description": "Core interfaces and Kuralle adapter for messaging platforms",
11
11
  "type": "module",
12
12
  "main": "dist/index.js",
@@ -26,7 +26,7 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "hono": "^4.7.4",
29
- "@kuralle-agents/core": "0.12.0"
29
+ "@kuralle-agents/core": "0.14.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "typescript": "^5.8.2",