@ably/ai-transport 0.0.1

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.
Files changed (118) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +426 -0
  3. package/dist/ably-ai-transport.js +1388 -0
  4. package/dist/ably-ai-transport.js.map +1 -0
  5. package/dist/ably-ai-transport.umd.cjs +2 -0
  6. package/dist/ably-ai-transport.umd.cjs.map +1 -0
  7. package/dist/constants.d.ts +50 -0
  8. package/dist/core/codec/decoder.d.ts +62 -0
  9. package/dist/core/codec/encoder.d.ts +56 -0
  10. package/dist/core/codec/index.d.ts +8 -0
  11. package/dist/core/codec/lifecycle-tracker.d.ts +74 -0
  12. package/dist/core/codec/types.d.ts +188 -0
  13. package/dist/core/transport/client-transport.d.ts +10 -0
  14. package/dist/core/transport/conversation-tree.d.ts +9 -0
  15. package/dist/core/transport/decode-history.d.ts +41 -0
  16. package/dist/core/transport/headers.d.ts +26 -0
  17. package/dist/core/transport/index.d.ts +4 -0
  18. package/dist/core/transport/pipe-stream.d.ts +16 -0
  19. package/dist/core/transport/server-transport.d.ts +7 -0
  20. package/dist/core/transport/stream-router.d.ts +19 -0
  21. package/dist/core/transport/turn-manager.d.ts +34 -0
  22. package/dist/core/transport/types.d.ts +407 -0
  23. package/dist/errors.d.ts +46 -0
  24. package/dist/event-emitter.d.ts +65 -0
  25. package/dist/index.d.ts +11 -0
  26. package/dist/logger.d.ts +103 -0
  27. package/dist/react/ably-ai-transport-react.js +823 -0
  28. package/dist/react/ably-ai-transport-react.js.map +1 -0
  29. package/dist/react/ably-ai-transport-react.umd.cjs +2 -0
  30. package/dist/react/ably-ai-transport-react.umd.cjs.map +1 -0
  31. package/dist/react/index.d.ts +11 -0
  32. package/dist/react/use-ably-messages.d.ts +18 -0
  33. package/dist/react/use-active-turns.d.ts +8 -0
  34. package/dist/react/use-client-transport.d.ts +7 -0
  35. package/dist/react/use-conversation-tree.d.ts +20 -0
  36. package/dist/react/use-edit.d.ts +7 -0
  37. package/dist/react/use-history.d.ts +19 -0
  38. package/dist/react/use-messages.d.ts +7 -0
  39. package/dist/react/use-regenerate.d.ts +7 -0
  40. package/dist/react/use-send.d.ts +7 -0
  41. package/dist/utils.d.ts +127 -0
  42. package/dist/vercel/ably-ai-transport-vercel.js +2331 -0
  43. package/dist/vercel/ably-ai-transport-vercel.js.map +1 -0
  44. package/dist/vercel/ably-ai-transport-vercel.umd.cjs +2 -0
  45. package/dist/vercel/ably-ai-transport-vercel.umd.cjs.map +1 -0
  46. package/dist/vercel/codec/accumulator.d.ts +21 -0
  47. package/dist/vercel/codec/decoder.d.ts +22 -0
  48. package/dist/vercel/codec/encoder.d.ts +41 -0
  49. package/dist/vercel/codec/index.d.ts +22 -0
  50. package/dist/vercel/index.d.ts +3 -0
  51. package/dist/vercel/react/ably-ai-transport-vercel-react.js +2082 -0
  52. package/dist/vercel/react/ably-ai-transport-vercel-react.js.map +1 -0
  53. package/dist/vercel/react/ably-ai-transport-vercel-react.umd.cjs +2 -0
  54. package/dist/vercel/react/ably-ai-transport-vercel-react.umd.cjs.map +1 -0
  55. package/dist/vercel/react/index.d.ts +3 -0
  56. package/dist/vercel/react/use-chat-transport.d.ts +29 -0
  57. package/dist/vercel/react/use-message-sync.d.ts +19 -0
  58. package/dist/vercel/transport/chat-transport.d.ts +118 -0
  59. package/dist/vercel/transport/index.d.ts +36 -0
  60. package/package.json +123 -0
  61. package/react/README.md +3 -0
  62. package/react/index.d.ts +1 -0
  63. package/react/index.js +1 -0
  64. package/react/index.umd.cjs +1 -0
  65. package/src/constants.ts +98 -0
  66. package/src/core/codec/decoder.ts +402 -0
  67. package/src/core/codec/encoder.ts +470 -0
  68. package/src/core/codec/index.ts +28 -0
  69. package/src/core/codec/lifecycle-tracker.ts +140 -0
  70. package/src/core/codec/types.ts +249 -0
  71. package/src/core/transport/client-transport.ts +959 -0
  72. package/src/core/transport/conversation-tree.ts +434 -0
  73. package/src/core/transport/decode-history.ts +337 -0
  74. package/src/core/transport/headers.ts +46 -0
  75. package/src/core/transport/index.ts +34 -0
  76. package/src/core/transport/pipe-stream.ts +95 -0
  77. package/src/core/transport/server-transport.ts +458 -0
  78. package/src/core/transport/stream-router.ts +118 -0
  79. package/src/core/transport/turn-manager.ts +147 -0
  80. package/src/core/transport/types.ts +533 -0
  81. package/src/errors.ts +58 -0
  82. package/src/event-emitter.ts +103 -0
  83. package/src/index.ts +89 -0
  84. package/src/logger.ts +241 -0
  85. package/src/react/index.ts +11 -0
  86. package/src/react/use-ably-messages.ts +37 -0
  87. package/src/react/use-active-turns.ts +61 -0
  88. package/src/react/use-client-transport.ts +37 -0
  89. package/src/react/use-conversation-tree.ts +71 -0
  90. package/src/react/use-edit.ts +24 -0
  91. package/src/react/use-history.ts +111 -0
  92. package/src/react/use-messages.ts +32 -0
  93. package/src/react/use-regenerate.ts +24 -0
  94. package/src/react/use-send.ts +25 -0
  95. package/src/react/vite.config.ts +32 -0
  96. package/src/tsconfig.json +25 -0
  97. package/src/utils.ts +230 -0
  98. package/src/vercel/codec/accumulator.ts +603 -0
  99. package/src/vercel/codec/decoder.ts +615 -0
  100. package/src/vercel/codec/encoder.ts +396 -0
  101. package/src/vercel/codec/index.ts +37 -0
  102. package/src/vercel/index.ts +12 -0
  103. package/src/vercel/react/index.ts +4 -0
  104. package/src/vercel/react/use-chat-transport.ts +60 -0
  105. package/src/vercel/react/use-message-sync.ts +34 -0
  106. package/src/vercel/react/vite.config.ts +33 -0
  107. package/src/vercel/transport/chat-transport.ts +278 -0
  108. package/src/vercel/transport/index.ts +56 -0
  109. package/src/vercel/vite.config.ts +33 -0
  110. package/src/vite.config.ts +31 -0
  111. package/vercel/README.md +3 -0
  112. package/vercel/index.d.ts +1 -0
  113. package/vercel/index.js +1 -0
  114. package/vercel/index.umd.cjs +1 -0
  115. package/vercel/react/README.md +3 -0
  116. package/vercel/react/index.d.ts +1 -0
  117. package/vercel/react/index.js +1 -0
  118. package/vercel/react/index.umd.cjs +1 -0
@@ -0,0 +1,3 @@
1
+ export type { ChatTransport } from '../transport/chat-transport.js';
2
+ export { useChatTransport } from './use-chat-transport.js';
3
+ export { useMessageSync } from './use-message-sync.js';
@@ -0,0 +1,29 @@
1
+ import { ClientTransport } from '../../core/transport/types.js';
2
+ import { ChatTransport, ChatTransportOptions } from '../transport/chat-transport.js';
3
+ import { VercelClientTransportOptions } from '../transport/index.js';
4
+ /**
5
+ * useChatTransport: wraps a core ClientTransport into the ChatTransport
6
+ * shape that Vercel's useChat expects.
7
+ *
8
+ * Accepts either an existing ClientTransport or options to create one:
9
+ * - From an existing ClientTransport — wraps it directly
10
+ * - From options — creates a ClientTransport with UIMessageCodec and wraps it
11
+ *
12
+ * Both forms accept an optional second argument for ChatTransportOptions
13
+ * (e.g. prepareSendMessagesRequest for the persistence pattern).
14
+ *
15
+ * The hook does NOT auto-close the transport on unmount. Channel lifecycle is
16
+ * managed by the Ably provider (useChannel). Auto-closing would break React
17
+ * Strict Mode. Call chatTransport.close() explicitly if needed.
18
+ */
19
+ import type * as AI from 'ai';
20
+ /**
21
+ * Create and memoize a {@link ChatTransport} for Vercel's useChat hook.
22
+ *
23
+ * Pass an existing `ClientTransport` to wrap it, or pass
24
+ * `VercelClientTransportOptions` to create one internally with UIMessageCodec.
25
+ * @param transportOrOptions - An existing ClientTransport, or options to create one.
26
+ * @param chatOptions - Optional hooks for customizing request construction.
27
+ * @returns A {@link ChatTransport} compatible with Vercel's useChat hook.
28
+ */
29
+ export declare const useChatTransport: (transportOrOptions: ClientTransport<AI.UIMessageChunk, AI.UIMessage> | VercelClientTransportOptions, chatOptions?: ChatTransportOptions) => ChatTransport;
@@ -0,0 +1,19 @@
1
+ import { ClientTransport } from '../../core/transport/types.js';
2
+ /**
3
+ * useMessageSync: wires transport message lifecycle events into useChat's setMessages.
4
+ *
5
+ * Subscribes to the transport's 'message' event and replaces messages state
6
+ * with the transport's authoritative message list. Events fire immediately
7
+ * on every store update (including during active streaming), so this hook
8
+ * keeps React state in sync in real time.
9
+ *
10
+ * Returns the unsubscribe function in the useEffect cleanup so handlers
11
+ * are removed on unmount or when dependencies change.
12
+ */
13
+ import type * as AI from 'ai';
14
+ /**
15
+ * Wire transport message updates into useChat's `setMessages` updater.
16
+ * @param transport - The client transport to observe, or null/undefined if not yet available.
17
+ * @param setMessages - The `setMessages` updater function from useChat.
18
+ */
19
+ export declare const useMessageSync: (transport: ClientTransport<unknown, AI.UIMessage> | null | undefined, setMessages: (updater: (prev: AI.UIMessage[]) => AI.UIMessage[]) => void) => void;
@@ -0,0 +1,118 @@
1
+ import { ClientTransport, CloseOptions } from '../../core/transport/types.js';
2
+ /**
3
+ * Vercel chat transport: wraps a core ClientTransport to satisfy the
4
+ * ChatTransport interface that useChat expects.
5
+ *
6
+ * This is a thin adapter — the real logic lives in the core transport.
7
+ * The chat transport maps Vercel's sendMessages/reconnectToStream contract
8
+ * to the core transport's send/cancel methods.
9
+ *
10
+ * useChat manages message state before calling sendMessages:
11
+ * - submit-message: appends the new user message, passes the full array
12
+ * - regenerate-message: truncates after the target, passes the truncated array
13
+ *
14
+ * The adapter uses `trigger` to determine the history/messages split:
15
+ * - submit-message: last message is new (publish to channel), rest is history
16
+ * - regenerate-message: no new messages, entire array is history
17
+ */
18
+ import type * as AI from 'ai';
19
+ /**
20
+ * Context passed to {@link ChatTransportOptions.prepareSendMessagesRequest} for
21
+ * customizing the HTTP POST body and headers.
22
+ */
23
+ export interface SendMessagesRequestContext {
24
+ /** Chat session ID (from useChat's id). */
25
+ id?: string;
26
+ /** What triggered the request: user sent a message, or requested regeneration. */
27
+ trigger: 'submit-message' | 'regenerate-message';
28
+ /**
29
+ * The message ID for regeneration requests. Identifies which assistant
30
+ * message to regenerate. Undefined for submit-message.
31
+ */
32
+ messageId?: string;
33
+ /** Previous messages in the conversation (context for the LLM). */
34
+ history: AI.UIMessage[];
35
+ /** The new message(s) being sent (to publish to the channel). Empty for regeneration. */
36
+ messages: AI.UIMessage[];
37
+ /** The msg-id of the message being forked (regenerated or edited). */
38
+ forkOf?: string;
39
+ /** The msg-id of the predecessor in the conversation thread. */
40
+ parent?: string | null;
41
+ }
42
+ /** Options for customizing the ChatTransport behavior. */
43
+ export interface ChatTransportOptions {
44
+ /**
45
+ * Customize the POST body before sending. Called by sendMessages()
46
+ * with the conversation context. Return the body and headers for
47
+ * the HTTP POST.
48
+ *
49
+ * Default: sends all previous messages as `history` in the body.
50
+ * @param context - The conversation context for the current request.
51
+ * @returns The body and headers to use for the HTTP POST.
52
+ */
53
+ prepareSendMessagesRequest?: (context: SendMessagesRequestContext) => {
54
+ body?: Record<string, unknown>;
55
+ headers?: Record<string, string>;
56
+ };
57
+ }
58
+ /**
59
+ * Additional options passed through from useChat alongside the core
60
+ * sendMessages/reconnectToStream parameters.
61
+ *
62
+ * Mirrors the AI SDK's internal ChatRequestOptions type, which is not
63
+ * exported from the `ai` package.
64
+ */
65
+ interface ChatRequestOptions {
66
+ /** Additional headers for the request. */
67
+ headers?: Record<string, string> | Headers;
68
+ /** Additional JSON body properties for the request. */
69
+ body?: object;
70
+ /** Custom metadata to attach to the request. */
71
+ metadata?: unknown;
72
+ }
73
+ /**
74
+ * Transport interface for Vercel AI SDK's useChat hook.
75
+ *
76
+ * Structurally compatible with the AI SDK's internal `ChatTransport<UIMessage>`
77
+ * interface. Extended with `close()` for releasing the underlying Ably transport
78
+ * resources.
79
+ */
80
+ export interface ChatTransport {
81
+ /** Send messages and return a streaming response of UIMessageChunk events. */
82
+ sendMessages: (options: {
83
+ /** The type of message submission — new message or regeneration. */
84
+ trigger: 'submit-message' | 'regenerate-message';
85
+ /** Unique identifier for the chat session. */
86
+ chatId: string;
87
+ /** ID of the message to regenerate, or undefined for new messages. */
88
+ messageId: string | undefined;
89
+ /** Array of UI messages representing the conversation history. */
90
+ messages: AI.UIMessage[];
91
+ /** Signal to abort the request if needed. */
92
+ abortSignal: AbortSignal | undefined;
93
+ } & ChatRequestOptions) => Promise<ReadableStream<AI.UIMessageChunk>>;
94
+ /**
95
+ * Reconnect to an existing streaming response. Returns null if no active
96
+ * stream exists for the specified chat session.
97
+ */
98
+ reconnectToStream: (options: {
99
+ /** Unique identifier for the chat session to reconnect to. */
100
+ chatId: string;
101
+ } & ChatRequestOptions) => Promise<ReadableStream<AI.UIMessageChunk> | null>;
102
+ /** Close the underlying transport, releasing all resources. */
103
+ close(options?: CloseOptions): Promise<void>;
104
+ }
105
+ /**
106
+ * Create a Vercel ChatTransport from a core ClientTransport.
107
+ *
108
+ * Maps Vercel's useChat contract to the core transport's methods:
109
+ * - trigger 'submit-message' → transport.send(lastMessage) with history in body
110
+ * - trigger 'regenerate-message' → transport.send([]) with all messages as history
111
+ * - abortSignal → transport.cancel({ all: true })
112
+ * - reconnectToStream → null (observer mode handles in-progress streams)
113
+ * @param transport - The core client transport to wrap.
114
+ * @param chatOptions - Optional hooks for customizing request construction.
115
+ * @returns A {@link ChatTransport} compatible with Vercel's useChat hook.
116
+ */
117
+ export declare const createChatTransport: (transport: ClientTransport<AI.UIMessageChunk, AI.UIMessage>, chatOptions?: ChatTransportOptions) => ChatTransport;
118
+ export {};
@@ -0,0 +1,36 @@
1
+ import { ClientTransport, ClientTransportOptions, ServerTransport, ServerTransportOptions } from '../../core/transport/types.js';
2
+ /**
3
+ * Vercel AI SDK transport wrappers that pre-bind the UIMessageCodec.
4
+ *
5
+ * These are convenience factories so consumers don't need to pass the codec
6
+ * explicitly when using the Vercel AI SDK integration.
7
+ *
8
+ * ```ts
9
+ * import { createClientTransport } from '@ably/ai-transport/vercel';
10
+ *
11
+ * const transport = createClientTransport({ channel });
12
+ * ```
13
+ */
14
+ export type { ChatTransport, ChatTransportOptions, SendMessagesRequestContext } from './chat-transport.js';
15
+ export { createChatTransport } from './chat-transport.js';
16
+ import type * as AI from 'ai';
17
+ /** Options for creating a Vercel client transport. Same as core options but without the codec field. */
18
+ export type VercelClientTransportOptions = Omit<ClientTransportOptions<AI.UIMessageChunk, AI.UIMessage>, 'codec'>;
19
+ /** Options for creating a Vercel server transport. Same as core options but without the codec field. */
20
+ export type VercelServerTransportOptions = Omit<ServerTransportOptions<AI.UIMessageChunk, AI.UIMessage>, 'codec'>;
21
+ /**
22
+ * Create a client-side transport pre-configured with the Vercel AI SDK codec.
23
+ *
24
+ * Equivalent to calling the core `createClientTransport` with `codec: UIMessageCodec`.
25
+ * @param options - Configuration for the client transport (codec is provided automatically).
26
+ * @returns A new {@link ClientTransport} for Vercel AI SDK UIMessage/UIMessageChunk types.
27
+ */
28
+ export declare const createClientTransport: (options: VercelClientTransportOptions) => ClientTransport<AI.UIMessageChunk, AI.UIMessage>;
29
+ /**
30
+ * Create a server-side transport pre-configured with the Vercel AI SDK codec.
31
+ *
32
+ * Equivalent to calling the core `createServerTransport` with `codec: UIMessageCodec`.
33
+ * @param options - Configuration for the server transport (codec is provided automatically).
34
+ * @returns A new {@link ServerTransport} for Vercel AI SDK UIMessage/UIMessageChunk types.
35
+ */
36
+ export declare const createServerTransport: (options: VercelServerTransportOptions) => ServerTransport<AI.UIMessageChunk, AI.UIMessage>;
package/package.json ADDED
@@ -0,0 +1,123 @@
1
+ {
2
+ "name": "@ably/ai-transport",
3
+ "version": "0.0.1",
4
+ "description": "Ably transport and codecs for building AI applications with Ably.",
5
+ "type": "module",
6
+ "main": "dist/ably-ai-transport.umd.cjs",
7
+ "module": "dist/ably-ai-transport.js",
8
+ "browser": "dist/ably-ai-transport.js",
9
+ "types": "dist/index.d.ts",
10
+ "react-native": "dist/ably-ai-transport.umd.cjs",
11
+ "sideEffects": false,
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "react-native": "./dist/ably-ai-transport.umd.cjs",
16
+ "import": "./dist/ably-ai-transport.js",
17
+ "require": "./dist/ably-ai-transport.umd.cjs"
18
+ },
19
+ "./react": {
20
+ "types": "./dist/react/index.d.ts",
21
+ "react-native": "./dist/react/ably-ai-transport-react.umd.cjs",
22
+ "import": "./dist/react/ably-ai-transport-react.js",
23
+ "require": "./dist/react/ably-ai-transport-react.umd.cjs"
24
+ },
25
+ "./vercel": {
26
+ "types": "./dist/vercel/index.d.ts",
27
+ "react-native": "./dist/vercel/ably-ai-transport-vercel.umd.cjs",
28
+ "import": "./dist/vercel/ably-ai-transport-vercel.js",
29
+ "require": "./dist/vercel/ably-ai-transport-vercel.umd.cjs"
30
+ },
31
+ "./vercel/react": {
32
+ "types": "./dist/vercel/react/index.d.ts",
33
+ "react-native": "./dist/vercel/react/ably-ai-transport-vercel-react.umd.cjs",
34
+ "import": "./dist/vercel/react/ably-ai-transport-vercel-react.js",
35
+ "require": "./dist/vercel/react/ably-ai-transport-vercel-react.umd.cjs"
36
+ },
37
+ "./package.json": "./package.json"
38
+ },
39
+ "scripts": {
40
+ "build": "npm run build:clean && npm run build:core && npm run build:react && npm run build:vercel && npm run build:vercel-react",
41
+ "build:clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
42
+ "build:core": "vite build --config ./src/vite.config.ts",
43
+ "build:react": "vite build --config ./src/react/vite.config.ts --emptyOutDir",
44
+ "build:vercel": "vite build --config ./src/vercel/vite.config.ts --emptyOutDir",
45
+ "build:vercel-react": "vite build --config ./src/vercel/react/vite.config.ts --emptyOutDir",
46
+ "prepare": "npm run build",
47
+ "lint": "eslint .",
48
+ "lint:fix": "eslint --fix .; (npm run format > /dev/null)",
49
+ "format": "prettier --list-different --write src demo/vercel/react/*/src",
50
+ "format:check": "prettier --check src demo/vercel/react/*/src",
51
+ "typecheck": "tsc --noEmit",
52
+ "test": "vitest run",
53
+ "test:integration": "vitest run --config vitest.config.integration.ts",
54
+ "check:error-codes": "tsx scripts/validate-error-codes.ts",
55
+ "precommit": "npm run format:check && npm run lint && npm run typecheck"
56
+ },
57
+ "files": [
58
+ "dist/**",
59
+ "src/**",
60
+ "react/**",
61
+ "vercel/**"
62
+ ],
63
+ "repository": {
64
+ "type": "git",
65
+ "url": "git+https://github.com/ably/ably-ai-transport-js.git"
66
+ },
67
+ "keywords": [
68
+ "ai",
69
+ "ably",
70
+ "ably-realtime",
71
+ "transport",
72
+ "websockets"
73
+ ],
74
+ "author": "Ably Realtime",
75
+ "license": "Apache-2.0",
76
+ "bugs": {
77
+ "url": "https://github.com/ably/ably-ai-transport-js/issues"
78
+ },
79
+ "homepage": "https://github.com/ably/ably-ai-transport-js#readme",
80
+ "engines": {
81
+ "node": ">=20.0.0"
82
+ },
83
+ "peerDependencies": {
84
+ "ably": "^2.21.0",
85
+ "ai": "^6",
86
+ "react": "^18.0.0 || ^19.0.0"
87
+ },
88
+ "peerDependenciesMeta": {
89
+ "ai": {
90
+ "optional": true
91
+ },
92
+ "react": {
93
+ "optional": true
94
+ }
95
+ },
96
+ "devDependencies": {
97
+ "@eslint/compat": "^1.2.7",
98
+ "@eslint/eslintrc": "^3.3.0",
99
+ "@eslint/js": "^9.12.0",
100
+ "@testing-library/react": "^16.3.2",
101
+ "@types/react": "^19.2.14",
102
+ "@typescript-eslint/eslint-plugin": "^8.26.1",
103
+ "@typescript-eslint/parser": "^8.26.1",
104
+ "ai": "^6.0.137",
105
+ "eslint": "^9.31.0",
106
+ "eslint-plugin-import": "^2.31.0",
107
+ "eslint-plugin-jsdoc": "^60.7.0",
108
+ "eslint-plugin-prefer-arrow-functions": "^3.6.2",
109
+ "eslint-plugin-security": "^3.0.1",
110
+ "eslint-plugin-simple-import-sort": "^12.1.1",
111
+ "eslint-plugin-unicorn": "^61.0.2",
112
+ "globals": "^16.0.0",
113
+ "jiti": "^2.6.1",
114
+ "jsdom": "^29.0.1",
115
+ "prettier": "^3.5.3",
116
+ "tsx": "^4.21.0",
117
+ "typescript": "^5.8.2",
118
+ "typescript-eslint": "^8.26.1",
119
+ "vite": "^8.0.0",
120
+ "vite-plugin-dts": "^4.5.4",
121
+ "vitest": "^4.1.0"
122
+ }
123
+ }
@@ -0,0 +1,3 @@
1
+ # @ably/ai-transport/react
2
+
3
+ This directory contains re-exports of `dist/react`, allowing bundlers (such as Metro) which don't support the package.json `exports` field to resolve imports from `@ably/ai-transport/react`.
@@ -0,0 +1 @@
1
+ export * from '../dist/react';
package/react/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from '../dist/react/ably-ai-transport-react';
@@ -0,0 +1 @@
1
+ module.exports = require('../dist/react/ably-ai-transport-react.umd');
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Shared constants used by both codec and transport layers.
3
+ *
4
+ * Header constants define the `x-ably-*` wire protocol. Message and event
5
+ * name constants define the transport lifecycle signals on the channel.
6
+ *
7
+ * These live at the top level (not in codec/ or transport/) because both
8
+ * layers need them — the codec core reads/writes stream and status headers,
9
+ * while the transport layer reads/writes turn, cancel, and role headers.
10
+ */
11
+
12
+ // ---------------------------------------------------------------------------
13
+ // Stream headers (used by codec encoder/decoder core)
14
+ // ---------------------------------------------------------------------------
15
+
16
+ /** Header: whether this Ably message uses streaming (message appends) or is discrete. Always "true" or "false". */
17
+ export const HEADER_STREAM = 'x-ably-stream';
18
+
19
+ /** Header: lifecycle status of a streamed message. Only set when x-ably-stream is "true". */
20
+ export const HEADER_STATUS = 'x-ably-status';
21
+
22
+ /** Header: stream identity. Set by the encoder on every streamed message; read by the decoder to correlate streams. */
23
+ export const HEADER_STREAM_ID = 'x-ably-stream-id';
24
+
25
+ // ---------------------------------------------------------------------------
26
+ // Identity headers (used by transport for turn correlation)
27
+ // ---------------------------------------------------------------------------
28
+
29
+ /** Header: turn correlation ID. Set on every message in a turn. */
30
+ export const HEADER_TURN_ID = 'x-ably-turn-id';
31
+
32
+ /** Header: message identity. Assigned per message (user or assistant). Used for optimistic reconciliation on the client. */
33
+ export const HEADER_MSG_ID = 'x-ably-msg-id';
34
+
35
+ /** Header: clientId of the user who initiated the turn. Set by the server on stream messages. */
36
+ export const HEADER_TURN_CLIENT_ID = 'x-ably-turn-client-id';
37
+
38
+ /** Header: message role (e.g. "user", "assistant"). */
39
+ export const HEADER_ROLE = 'x-ably-role';
40
+
41
+ // ---------------------------------------------------------------------------
42
+ // Cancel headers
43
+ // ---------------------------------------------------------------------------
44
+
45
+ /** Header: cancel a specific turn by ID. */
46
+ export const HEADER_CANCEL_TURN_ID = 'x-ably-cancel-turn-id';
47
+
48
+ /** Header: cancel all turns belonging to the sender's clientId. */
49
+ export const HEADER_CANCEL_OWN = 'x-ably-cancel-own';
50
+
51
+ /** Header: cancel all turns on the channel. */
52
+ export const HEADER_CANCEL_ALL = 'x-ably-cancel-all';
53
+
54
+ /** Header: cancel all turns belonging to a specific clientId. */
55
+ export const HEADER_CANCEL_CLIENT_ID = 'x-ably-cancel-client-id';
56
+
57
+ // ---------------------------------------------------------------------------
58
+ // Fork / branching headers
59
+ // ---------------------------------------------------------------------------
60
+
61
+ /** Header: the msg-id of the immediately preceding message in this branch. */
62
+ export const HEADER_PARENT = 'x-ably-parent';
63
+
64
+ /** Header: the msg-id of the message this one replaces (creates a fork). */
65
+ export const HEADER_FORK_OF = 'x-ably-fork-of';
66
+
67
+ // ---------------------------------------------------------------------------
68
+ // Turn lifecycle headers
69
+ // ---------------------------------------------------------------------------
70
+
71
+ /** Header: reason a turn ended (on x-ably-turn-end messages). */
72
+ export const HEADER_TURN_REASON = 'x-ably-turn-reason';
73
+
74
+ // ---------------------------------------------------------------------------
75
+ // Message / event names
76
+ // ---------------------------------------------------------------------------
77
+
78
+ /** Message name: client->server cancel signal. */
79
+ export const EVENT_CANCEL = 'x-ably-cancel';
80
+
81
+ /** Message name: server publishes this to signal a turn has started. */
82
+ export const EVENT_TURN_START = 'x-ably-turn-start';
83
+
84
+ /** Message name: server publishes this to signal a turn has ended. */
85
+ export const EVENT_TURN_END = 'x-ably-turn-end';
86
+
87
+ /** Message name: transport-level abort signal (stream cancelled). */
88
+ export const EVENT_ABORT = 'x-ably-abort';
89
+
90
+ /** Message name: transport-level error signal. */
91
+ export const EVENT_ERROR = 'x-ably-error';
92
+
93
+ // ---------------------------------------------------------------------------
94
+ // Domain header prefix (used by codec implementations)
95
+ // ---------------------------------------------------------------------------
96
+
97
+ /** Prefix for domain-specific headers. Distinguishes codec-layer headers from transport `x-ably-*` headers. */
98
+ export const DOMAIN_HEADER_PREFIX = 'x-domain-';