@reverbia/sdk 1.0.0 → 1.1.0-next.20251230221037
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 +290 -45
- package/dist/expo/index.cjs +3428 -0
- package/dist/expo/index.d.mts +1217 -0
- package/dist/expo/index.d.ts +1217 -0
- package/dist/expo/index.mjs +3395 -0
- package/dist/index.cjs +972 -0
- package/dist/index.d.mts +1514 -0
- package/dist/index.d.ts +1514 -0
- package/dist/index.mjs +934 -0
- package/dist/next/index.cjs +64 -0
- package/dist/next/index.d.mts +23 -0
- package/dist/next/index.d.ts +23 -0
- package/dist/next/index.mjs +39 -0
- package/dist/polyfills/index.cjs +61 -0
- package/dist/polyfills/index.d.mts +9 -0
- package/dist/polyfills/index.d.ts +9 -0
- package/dist/polyfills/index.mjs +34 -0
- package/dist/react/chunk-KUFGQF6E.mjs +290 -0
- package/dist/react/chunk-T56Y62G7.mjs +410 -0
- package/dist/react/index.cjs +7982 -0
- package/dist/react/index.d.mts +3139 -0
- package/dist/react/index.d.ts +3139 -0
- package/dist/react/index.mjs +7209 -0
- package/dist/react/storage-Z2NBANCK.mjs +29 -0
- package/dist/react/useEncryption-5RTXKDNZ.mjs +31 -0
- package/dist/vercel/index.cjs +86 -0
- package/dist/vercel/index.d.mts +119 -0
- package/dist/vercel/index.d.ts +119 -0
- package/dist/vercel/index.mjs +57 -0
- package/package.json +91 -16
- package/dist/cjs/client/client/client.gen.d.ts +0 -2
- package/dist/cjs/client/client/client.gen.js +0 -203
- package/dist/cjs/client/client/index.d.ts +0 -8
- package/dist/cjs/client/client/index.js +0 -16
- package/dist/cjs/client/client/types.gen.d.ts +0 -99
- package/dist/cjs/client/client/types.gen.js +0 -3
- package/dist/cjs/client/client/utils.gen.d.ts +0 -40
- package/dist/cjs/client/client/utils.gen.js +0 -314
- package/dist/cjs/client/client.gen.d.ts +0 -12
- package/dist/cjs/client/client.gen.js +0 -6
- package/dist/cjs/client/core/auth.gen.d.ts +0 -18
- package/dist/cjs/client/core/auth.gen.js +0 -18
- package/dist/cjs/client/core/bodySerializer.gen.d.ts +0 -25
- package/dist/cjs/client/core/bodySerializer.gen.js +0 -60
- package/dist/cjs/client/core/params.gen.d.ts +0 -43
- package/dist/cjs/client/core/params.gen.js +0 -104
- package/dist/cjs/client/core/pathSerializer.gen.d.ts +0 -33
- package/dist/cjs/client/core/pathSerializer.gen.js +0 -123
- package/dist/cjs/client/core/queryKeySerializer.gen.d.ts +0 -18
- package/dist/cjs/client/core/queryKeySerializer.gen.js +0 -105
- package/dist/cjs/client/core/serverSentEvents.gen.d.ts +0 -71
- package/dist/cjs/client/core/serverSentEvents.gen.js +0 -139
- package/dist/cjs/client/core/types.gen.d.ts +0 -78
- package/dist/cjs/client/core/types.gen.js +0 -3
- package/dist/cjs/client/core/utils.gen.d.ts +0 -19
- package/dist/cjs/client/core/utils.gen.js +0 -93
- package/dist/cjs/client/index.d.ts +0 -2
- package/dist/cjs/client/index.js +0 -18
- package/dist/cjs/client/sdk.gen.d.ts +0 -27
- package/dist/cjs/client/sdk.gen.js +0 -33
- package/dist/cjs/client/types.gen.d.ts +0 -120
- package/dist/cjs/client/types.gen.js +0 -3
- package/dist/esm/client/client/client.gen.d.ts +0 -2
- package/dist/esm/client/client/client.gen.js +0 -199
- package/dist/esm/client/client/index.d.ts +0 -8
- package/dist/esm/client/client/index.js +0 -6
- package/dist/esm/client/client/types.gen.d.ts +0 -99
- package/dist/esm/client/client/types.gen.js +0 -2
- package/dist/esm/client/client/utils.gen.d.ts +0 -40
- package/dist/esm/client/client/utils.gen.js +0 -302
- package/dist/esm/client/client.gen.d.ts +0 -12
- package/dist/esm/client/client.gen.js +0 -3
- package/dist/esm/client/core/auth.gen.d.ts +0 -18
- package/dist/esm/client/core/auth.gen.js +0 -14
- package/dist/esm/client/core/bodySerializer.gen.d.ts +0 -25
- package/dist/esm/client/core/bodySerializer.gen.js +0 -57
- package/dist/esm/client/core/params.gen.d.ts +0 -43
- package/dist/esm/client/core/params.gen.js +0 -100
- package/dist/esm/client/core/pathSerializer.gen.d.ts +0 -33
- package/dist/esm/client/core/pathSerializer.gen.js +0 -114
- package/dist/esm/client/core/queryKeySerializer.gen.d.ts +0 -18
- package/dist/esm/client/core/queryKeySerializer.gen.js +0 -99
- package/dist/esm/client/core/serverSentEvents.gen.d.ts +0 -71
- package/dist/esm/client/core/serverSentEvents.gen.js +0 -135
- package/dist/esm/client/core/types.gen.d.ts +0 -78
- package/dist/esm/client/core/types.gen.js +0 -2
- package/dist/esm/client/core/utils.gen.d.ts +0 -19
- package/dist/esm/client/core/utils.gen.js +0 -87
- package/dist/esm/client/index.d.ts +0 -2
- package/dist/esm/client/index.js +0 -2
- package/dist/esm/client/sdk.gen.d.ts +0 -27
- package/dist/esm/client/sdk.gen.js +0 -28
- package/dist/esm/client/types.gen.d.ts +0 -120
- package/dist/esm/client/types.gen.js +0 -2
- package/dist/types/client/client/client.gen.d.ts +0 -2
- package/dist/types/client/client/index.d.ts +0 -8
- package/dist/types/client/client/types.gen.d.ts +0 -99
- package/dist/types/client/client/utils.gen.d.ts +0 -40
- package/dist/types/client/client.gen.d.ts +0 -12
- package/dist/types/client/core/auth.gen.d.ts +0 -18
- package/dist/types/client/core/bodySerializer.gen.d.ts +0 -25
- package/dist/types/client/core/params.gen.d.ts +0 -43
- package/dist/types/client/core/pathSerializer.gen.d.ts +0 -33
- package/dist/types/client/core/queryKeySerializer.gen.d.ts +0 -18
- package/dist/types/client/core/serverSentEvents.gen.d.ts +0 -71
- package/dist/types/client/core/types.gen.d.ts +0 -78
- package/dist/types/client/core/utils.gen.d.ts +0 -19
- package/dist/types/client/index.d.ts +0 -2
- package/dist/types/client/sdk.gen.d.ts +0 -27
- package/dist/types/client/types.gen.d.ts +0 -120
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
clearTokenData,
|
|
3
|
+
getRefreshToken,
|
|
4
|
+
getRefreshTokenSync,
|
|
5
|
+
getStoredTokenData,
|
|
6
|
+
getStoredTokenDataSync,
|
|
7
|
+
getValidAccessToken,
|
|
8
|
+
getValidAccessTokenSync,
|
|
9
|
+
hasStoredCredentialsSync,
|
|
10
|
+
isTokenExpired,
|
|
11
|
+
reEncryptUnencryptedTokens,
|
|
12
|
+
storeTokenData,
|
|
13
|
+
tokenResponseToStoredData
|
|
14
|
+
} from "./chunk-KUFGQF6E.mjs";
|
|
15
|
+
import "./chunk-T56Y62G7.mjs";
|
|
16
|
+
export {
|
|
17
|
+
clearTokenData,
|
|
18
|
+
getRefreshToken,
|
|
19
|
+
getRefreshTokenSync,
|
|
20
|
+
getStoredTokenData,
|
|
21
|
+
getStoredTokenDataSync,
|
|
22
|
+
getValidAccessToken,
|
|
23
|
+
getValidAccessTokenSync,
|
|
24
|
+
hasStoredCredentialsSync,
|
|
25
|
+
isTokenExpired,
|
|
26
|
+
reEncryptUnencryptedTokens,
|
|
27
|
+
storeTokenData,
|
|
28
|
+
tokenResponseToStoredData
|
|
29
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
clearAllEncryptionKeys,
|
|
4
|
+
clearAllKeyPairs,
|
|
5
|
+
clearEncryptionKey,
|
|
6
|
+
clearKeyPair,
|
|
7
|
+
decryptData,
|
|
8
|
+
decryptDataBytes,
|
|
9
|
+
encryptData,
|
|
10
|
+
exportPublicKey,
|
|
11
|
+
hasEncryptionKey,
|
|
12
|
+
hasKeyPair,
|
|
13
|
+
requestEncryptionKey,
|
|
14
|
+
requestKeyPair,
|
|
15
|
+
useEncryption
|
|
16
|
+
} from "./chunk-T56Y62G7.mjs";
|
|
17
|
+
export {
|
|
18
|
+
clearAllEncryptionKeys,
|
|
19
|
+
clearAllKeyPairs,
|
|
20
|
+
clearEncryptionKey,
|
|
21
|
+
clearKeyPair,
|
|
22
|
+
decryptData,
|
|
23
|
+
decryptDataBytes,
|
|
24
|
+
encryptData,
|
|
25
|
+
exportPublicKey,
|
|
26
|
+
hasEncryptionKey,
|
|
27
|
+
hasKeyPair,
|
|
28
|
+
requestEncryptionKey,
|
|
29
|
+
requestKeyPair,
|
|
30
|
+
useEncryption
|
|
31
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/vercel/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
createAssistantStream: () => createAssistantStream,
|
|
24
|
+
createErrorStream: () => createErrorStream,
|
|
25
|
+
mapMessagesToCompletionPayload: () => mapMessagesToCompletionPayload
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
|
|
29
|
+
// src/vercel/messages.ts
|
|
30
|
+
function mapMessagesToCompletionPayload(messages) {
|
|
31
|
+
return messages.map((message) => {
|
|
32
|
+
if (message.role !== "user" && message.role !== "assistant" && message.role !== "system") {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
const textParts = message.parts.map((part) => part.type === "text" ? part.text : void 0).filter((part) => Boolean(part && part.trim()));
|
|
36
|
+
const content = textParts.join("\n\n").trim();
|
|
37
|
+
if (!content.length) return null;
|
|
38
|
+
const llmMessage = {
|
|
39
|
+
role: message.role,
|
|
40
|
+
content: [{ type: "text", text: content }]
|
|
41
|
+
};
|
|
42
|
+
return llmMessage;
|
|
43
|
+
}).filter((m) => m !== null);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// src/vercel/streams.ts
|
|
47
|
+
function createAssistantStream(text) {
|
|
48
|
+
const messageId = crypto.randomUUID();
|
|
49
|
+
return new ReadableStream({
|
|
50
|
+
start(controller) {
|
|
51
|
+
controller.enqueue({
|
|
52
|
+
type: "text-start",
|
|
53
|
+
id: messageId
|
|
54
|
+
});
|
|
55
|
+
if (text.length > 0) {
|
|
56
|
+
controller.enqueue({
|
|
57
|
+
type: "text-delta",
|
|
58
|
+
id: messageId,
|
|
59
|
+
delta: text
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
controller.enqueue({
|
|
63
|
+
type: "text-end",
|
|
64
|
+
id: messageId
|
|
65
|
+
});
|
|
66
|
+
controller.close();
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function createErrorStream(errorText) {
|
|
71
|
+
return new ReadableStream({
|
|
72
|
+
start(controller) {
|
|
73
|
+
controller.enqueue({
|
|
74
|
+
type: "error",
|
|
75
|
+
errorText
|
|
76
|
+
});
|
|
77
|
+
controller.close();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
createAssistantStream,
|
|
84
|
+
createErrorStream,
|
|
85
|
+
mapMessagesToCompletionPayload
|
|
86
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { UIMessage } from 'ai';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Message is the generated message
|
|
5
|
+
*/
|
|
6
|
+
type LlmapiMessage = {
|
|
7
|
+
/**
|
|
8
|
+
* Content is the message content
|
|
9
|
+
*/
|
|
10
|
+
content?: Array<LlmapiMessageContentPart>;
|
|
11
|
+
role?: LlmapiRole;
|
|
12
|
+
/**
|
|
13
|
+
* ToolCalls contains tool/function calls made by the assistant (only for assistant role)
|
|
14
|
+
*/
|
|
15
|
+
tool_calls?: Array<LlmapiToolCall>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* ImageURL is used when Type=image_url
|
|
19
|
+
*/
|
|
20
|
+
type LlmapiMessageContentImage = {
|
|
21
|
+
/**
|
|
22
|
+
* Detail is the OpenAI detail hint (auto|low|high)
|
|
23
|
+
*/
|
|
24
|
+
detail?: string;
|
|
25
|
+
/**
|
|
26
|
+
* URL is the image URL or data URI
|
|
27
|
+
*/
|
|
28
|
+
url?: string;
|
|
29
|
+
};
|
|
30
|
+
type LlmapiMessageContentPart = {
|
|
31
|
+
image_url?: LlmapiMessageContentImage;
|
|
32
|
+
/**
|
|
33
|
+
* Text holds the text content when Type=text
|
|
34
|
+
*/
|
|
35
|
+
text?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Type is the block type (`text` or `image_url`)
|
|
38
|
+
*/
|
|
39
|
+
type?: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Role is the message role (system, user, assistant)
|
|
43
|
+
*/
|
|
44
|
+
type LlmapiRole = string;
|
|
45
|
+
type LlmapiToolCall = {
|
|
46
|
+
function?: LlmapiToolCallFunction;
|
|
47
|
+
/**
|
|
48
|
+
* ID is the unique identifier for this tool call
|
|
49
|
+
*/
|
|
50
|
+
id?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Type is the type of tool call (always "function" for now)
|
|
53
|
+
*/
|
|
54
|
+
type?: string;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Function contains the function call details
|
|
58
|
+
*/
|
|
59
|
+
type LlmapiToolCallFunction = {
|
|
60
|
+
/**
|
|
61
|
+
* Arguments is the JSON string of arguments to pass to the function
|
|
62
|
+
*/
|
|
63
|
+
arguments?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Name is the name of the function to call
|
|
66
|
+
*/
|
|
67
|
+
name?: string;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Converts an array of Vercel AI {@link UIMessage} objects into the
|
|
72
|
+
* `LlmapiMessage` format that the Portal API expects.
|
|
73
|
+
*
|
|
74
|
+
* - Non text-only parts and unsupported roles are ignored.
|
|
75
|
+
* - Text parts are merged with double newlines, matching the structure that
|
|
76
|
+
* `postApiV1ChatCompletions` accepts.
|
|
77
|
+
*
|
|
78
|
+
* @param messages The UI layer conversation history received from `createUIMessageStreamResponse`.
|
|
79
|
+
* @returns A clean array of Portal-ready messages, filtered to user, assistant, and system roles.
|
|
80
|
+
*/
|
|
81
|
+
declare function mapMessagesToCompletionPayload(messages: UIMessage[]): LlmapiMessage[];
|
|
82
|
+
|
|
83
|
+
type AssistantStreamEvent = {
|
|
84
|
+
type: "text-start";
|
|
85
|
+
id: string;
|
|
86
|
+
} | {
|
|
87
|
+
type: "text-delta";
|
|
88
|
+
id: string;
|
|
89
|
+
delta: string;
|
|
90
|
+
} | {
|
|
91
|
+
type: "text-end";
|
|
92
|
+
id: string;
|
|
93
|
+
} | {
|
|
94
|
+
type: "error";
|
|
95
|
+
errorText: string;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Creates a `ReadableStream` that emits the sequence of events expected by
|
|
99
|
+
* Vercel's `createUIMessageStreamResponse` helper for a successful assistant reply.
|
|
100
|
+
*
|
|
101
|
+
* The stream emits `text-start`, an optional `text-delta` containing the
|
|
102
|
+
* provided `text`, and finally `text-end`, allowing Portal completions to be
|
|
103
|
+
* piped directly into UI components that consume the AI SDK stream contract.
|
|
104
|
+
*
|
|
105
|
+
* @param text The assistant response text returned by the Portal API.
|
|
106
|
+
* @returns A stream ready to be passed to `createUIMessageStreamResponse`.
|
|
107
|
+
*/
|
|
108
|
+
declare function createAssistantStream(text: string): ReadableStream<AssistantStreamEvent>;
|
|
109
|
+
/**
|
|
110
|
+
* Creates a `ReadableStream` that emits a single `error` event compatible
|
|
111
|
+
* with the Vercel AI stream contract. This allows Portal API errors to be
|
|
112
|
+
* surfaced directly in UI components that expect streamed assistant output.
|
|
113
|
+
*
|
|
114
|
+
* @param errorText A human-readable error message to display in the UI.
|
|
115
|
+
* @returns A stream that, when consumed, immediately emits the error event.
|
|
116
|
+
*/
|
|
117
|
+
declare function createErrorStream(errorText: string): ReadableStream<AssistantStreamEvent>;
|
|
118
|
+
|
|
119
|
+
export { createAssistantStream, createErrorStream, mapMessagesToCompletionPayload };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { UIMessage } from 'ai';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Message is the generated message
|
|
5
|
+
*/
|
|
6
|
+
type LlmapiMessage = {
|
|
7
|
+
/**
|
|
8
|
+
* Content is the message content
|
|
9
|
+
*/
|
|
10
|
+
content?: Array<LlmapiMessageContentPart>;
|
|
11
|
+
role?: LlmapiRole;
|
|
12
|
+
/**
|
|
13
|
+
* ToolCalls contains tool/function calls made by the assistant (only for assistant role)
|
|
14
|
+
*/
|
|
15
|
+
tool_calls?: Array<LlmapiToolCall>;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* ImageURL is used when Type=image_url
|
|
19
|
+
*/
|
|
20
|
+
type LlmapiMessageContentImage = {
|
|
21
|
+
/**
|
|
22
|
+
* Detail is the OpenAI detail hint (auto|low|high)
|
|
23
|
+
*/
|
|
24
|
+
detail?: string;
|
|
25
|
+
/**
|
|
26
|
+
* URL is the image URL or data URI
|
|
27
|
+
*/
|
|
28
|
+
url?: string;
|
|
29
|
+
};
|
|
30
|
+
type LlmapiMessageContentPart = {
|
|
31
|
+
image_url?: LlmapiMessageContentImage;
|
|
32
|
+
/**
|
|
33
|
+
* Text holds the text content when Type=text
|
|
34
|
+
*/
|
|
35
|
+
text?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Type is the block type (`text` or `image_url`)
|
|
38
|
+
*/
|
|
39
|
+
type?: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Role is the message role (system, user, assistant)
|
|
43
|
+
*/
|
|
44
|
+
type LlmapiRole = string;
|
|
45
|
+
type LlmapiToolCall = {
|
|
46
|
+
function?: LlmapiToolCallFunction;
|
|
47
|
+
/**
|
|
48
|
+
* ID is the unique identifier for this tool call
|
|
49
|
+
*/
|
|
50
|
+
id?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Type is the type of tool call (always "function" for now)
|
|
53
|
+
*/
|
|
54
|
+
type?: string;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Function contains the function call details
|
|
58
|
+
*/
|
|
59
|
+
type LlmapiToolCallFunction = {
|
|
60
|
+
/**
|
|
61
|
+
* Arguments is the JSON string of arguments to pass to the function
|
|
62
|
+
*/
|
|
63
|
+
arguments?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Name is the name of the function to call
|
|
66
|
+
*/
|
|
67
|
+
name?: string;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Converts an array of Vercel AI {@link UIMessage} objects into the
|
|
72
|
+
* `LlmapiMessage` format that the Portal API expects.
|
|
73
|
+
*
|
|
74
|
+
* - Non text-only parts and unsupported roles are ignored.
|
|
75
|
+
* - Text parts are merged with double newlines, matching the structure that
|
|
76
|
+
* `postApiV1ChatCompletions` accepts.
|
|
77
|
+
*
|
|
78
|
+
* @param messages The UI layer conversation history received from `createUIMessageStreamResponse`.
|
|
79
|
+
* @returns A clean array of Portal-ready messages, filtered to user, assistant, and system roles.
|
|
80
|
+
*/
|
|
81
|
+
declare function mapMessagesToCompletionPayload(messages: UIMessage[]): LlmapiMessage[];
|
|
82
|
+
|
|
83
|
+
type AssistantStreamEvent = {
|
|
84
|
+
type: "text-start";
|
|
85
|
+
id: string;
|
|
86
|
+
} | {
|
|
87
|
+
type: "text-delta";
|
|
88
|
+
id: string;
|
|
89
|
+
delta: string;
|
|
90
|
+
} | {
|
|
91
|
+
type: "text-end";
|
|
92
|
+
id: string;
|
|
93
|
+
} | {
|
|
94
|
+
type: "error";
|
|
95
|
+
errorText: string;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Creates a `ReadableStream` that emits the sequence of events expected by
|
|
99
|
+
* Vercel's `createUIMessageStreamResponse` helper for a successful assistant reply.
|
|
100
|
+
*
|
|
101
|
+
* The stream emits `text-start`, an optional `text-delta` containing the
|
|
102
|
+
* provided `text`, and finally `text-end`, allowing Portal completions to be
|
|
103
|
+
* piped directly into UI components that consume the AI SDK stream contract.
|
|
104
|
+
*
|
|
105
|
+
* @param text The assistant response text returned by the Portal API.
|
|
106
|
+
* @returns A stream ready to be passed to `createUIMessageStreamResponse`.
|
|
107
|
+
*/
|
|
108
|
+
declare function createAssistantStream(text: string): ReadableStream<AssistantStreamEvent>;
|
|
109
|
+
/**
|
|
110
|
+
* Creates a `ReadableStream` that emits a single `error` event compatible
|
|
111
|
+
* with the Vercel AI stream contract. This allows Portal API errors to be
|
|
112
|
+
* surfaced directly in UI components that expect streamed assistant output.
|
|
113
|
+
*
|
|
114
|
+
* @param errorText A human-readable error message to display in the UI.
|
|
115
|
+
* @returns A stream that, when consumed, immediately emits the error event.
|
|
116
|
+
*/
|
|
117
|
+
declare function createErrorStream(errorText: string): ReadableStream<AssistantStreamEvent>;
|
|
118
|
+
|
|
119
|
+
export { createAssistantStream, createErrorStream, mapMessagesToCompletionPayload };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/vercel/messages.ts
|
|
2
|
+
function mapMessagesToCompletionPayload(messages) {
|
|
3
|
+
return messages.map((message) => {
|
|
4
|
+
if (message.role !== "user" && message.role !== "assistant" && message.role !== "system") {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
const textParts = message.parts.map((part) => part.type === "text" ? part.text : void 0).filter((part) => Boolean(part && part.trim()));
|
|
8
|
+
const content = textParts.join("\n\n").trim();
|
|
9
|
+
if (!content.length) return null;
|
|
10
|
+
const llmMessage = {
|
|
11
|
+
role: message.role,
|
|
12
|
+
content: [{ type: "text", text: content }]
|
|
13
|
+
};
|
|
14
|
+
return llmMessage;
|
|
15
|
+
}).filter((m) => m !== null);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// src/vercel/streams.ts
|
|
19
|
+
function createAssistantStream(text) {
|
|
20
|
+
const messageId = crypto.randomUUID();
|
|
21
|
+
return new ReadableStream({
|
|
22
|
+
start(controller) {
|
|
23
|
+
controller.enqueue({
|
|
24
|
+
type: "text-start",
|
|
25
|
+
id: messageId
|
|
26
|
+
});
|
|
27
|
+
if (text.length > 0) {
|
|
28
|
+
controller.enqueue({
|
|
29
|
+
type: "text-delta",
|
|
30
|
+
id: messageId,
|
|
31
|
+
delta: text
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
controller.enqueue({
|
|
35
|
+
type: "text-end",
|
|
36
|
+
id: messageId
|
|
37
|
+
});
|
|
38
|
+
controller.close();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function createErrorStream(errorText) {
|
|
43
|
+
return new ReadableStream({
|
|
44
|
+
start(controller) {
|
|
45
|
+
controller.enqueue({
|
|
46
|
+
type: "error",
|
|
47
|
+
errorText
|
|
48
|
+
});
|
|
49
|
+
controller.close();
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
createAssistantStream,
|
|
55
|
+
createErrorStream,
|
|
56
|
+
mapMessagesToCompletionPayload
|
|
57
|
+
};
|
package/package.json
CHANGED
|
@@ -1,26 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reverbia/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.1.0-next.20251230221037",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "dist/
|
|
6
|
-
"module": "dist/
|
|
7
|
-
"types": "dist/
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"types": "./dist/
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"react-server": "./dist/index.mjs",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.cjs",
|
|
14
|
+
"default": "./dist/index.cjs"
|
|
15
|
+
},
|
|
16
|
+
"./react": {
|
|
17
|
+
"types": "./dist/react/index.d.ts",
|
|
18
|
+
"react-native": "./dist/react/index.mjs",
|
|
19
|
+
"import": "./dist/react/index.mjs",
|
|
20
|
+
"require": "./dist/react/index.cjs",
|
|
21
|
+
"default": "./dist/react/index.cjs"
|
|
22
|
+
},
|
|
23
|
+
"./expo": {
|
|
24
|
+
"types": "./dist/expo/index.d.ts",
|
|
25
|
+
"react-native": "./dist/expo/index.mjs",
|
|
26
|
+
"import": "./dist/expo/index.mjs",
|
|
27
|
+
"require": "./dist/expo/index.cjs",
|
|
28
|
+
"default": "./dist/expo/index.cjs"
|
|
29
|
+
},
|
|
30
|
+
"./polyfills": {
|
|
31
|
+
"types": "./dist/polyfills/index.d.ts",
|
|
32
|
+
"react-native": "./dist/polyfills/index.mjs",
|
|
33
|
+
"import": "./dist/polyfills/index.mjs",
|
|
34
|
+
"require": "./dist/polyfills/index.cjs",
|
|
35
|
+
"default": "./dist/polyfills/index.cjs"
|
|
36
|
+
},
|
|
37
|
+
"./vercel": {
|
|
38
|
+
"types": "./dist/vercel/index.d.ts",
|
|
39
|
+
"react-server": "./dist/vercel/index.mjs",
|
|
40
|
+
"import": "./dist/vercel/index.mjs",
|
|
41
|
+
"require": "./dist/vercel/index.cjs",
|
|
42
|
+
"default": "./dist/vercel/index.cjs"
|
|
43
|
+
},
|
|
44
|
+
"./next": {
|
|
45
|
+
"types": "./dist/next/index.d.ts",
|
|
46
|
+
"import": "./dist/next/index.mjs",
|
|
47
|
+
"require": "./dist/next/index.cjs",
|
|
48
|
+
"default": "./dist/next/index.cjs"
|
|
14
49
|
}
|
|
15
50
|
},
|
|
16
51
|
"files": [
|
|
17
52
|
"dist"
|
|
18
53
|
],
|
|
19
54
|
"scripts": {
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
55
|
+
"spec": "openapi-ts",
|
|
56
|
+
"test": "vitest run",
|
|
57
|
+
"build": "tsup",
|
|
58
|
+
"prepublishOnly": "pnpm build",
|
|
59
|
+
"docs": "typedoc",
|
|
60
|
+
"generate": "pnpm run spec && pnpm run docs"
|
|
24
61
|
},
|
|
25
62
|
"repository": {
|
|
26
63
|
"type": "git",
|
|
@@ -29,20 +66,58 @@
|
|
|
29
66
|
"keywords": [],
|
|
30
67
|
"author": "",
|
|
31
68
|
"license": "ISC",
|
|
32
|
-
"type": "commonjs",
|
|
33
69
|
"bugs": {
|
|
34
70
|
"url": "https://github.com/zeta-chain/ai-sdk/issues"
|
|
35
71
|
},
|
|
36
72
|
"homepage": "https://github.com/zeta-chain/ai-sdk#readme",
|
|
37
73
|
"dependencies": {
|
|
38
|
-
"@reverbia/portal": "1.0.0-next.
|
|
74
|
+
"@reverbia/portal": "1.0.0-next.20251226114748",
|
|
75
|
+
"ai": "5.0.93",
|
|
76
|
+
"pdfjs-dist": "^4.10.38",
|
|
77
|
+
"tesseract.js": "^6.0.1"
|
|
39
78
|
},
|
|
40
79
|
"devDependencies": {
|
|
41
80
|
"@hey-api/openapi-ts": "0.87.2",
|
|
42
|
-
"
|
|
81
|
+
"@nozbe/watermelondb": "^0.28.0",
|
|
82
|
+
"@privy-io/react-auth": "^3.7.0",
|
|
83
|
+
"@testing-library/react": "^16.3.0",
|
|
84
|
+
"@types/node": "^22.0.0",
|
|
85
|
+
"@types/react": "^19.2.6",
|
|
86
|
+
"happy-dom": "^20.0.11",
|
|
87
|
+
"react": "^19.2.1",
|
|
88
|
+
"react-dom": "^19.2.1",
|
|
89
|
+
"tsup": "^8.5.1",
|
|
43
90
|
"typedoc": "^0.28.14",
|
|
44
91
|
"typedoc-plugin-frontmatter": "^1.3.0",
|
|
45
92
|
"typedoc-plugin-markdown": "^4.9.0",
|
|
46
|
-
"typescript": "^5.9.3"
|
|
93
|
+
"typescript": "^5.9.3",
|
|
94
|
+
"vitest": "^4.0.14"
|
|
95
|
+
},
|
|
96
|
+
"peerDependencies": {
|
|
97
|
+
"@nozbe/watermelondb": "^0.28.0",
|
|
98
|
+
"@privy-io/react-auth": "^3.7.0",
|
|
99
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
100
|
+
"react-dom": "^18.0.0 || ^19.0.0",
|
|
101
|
+
"react-native": ">=0.70.0"
|
|
102
|
+
},
|
|
103
|
+
"peerDependenciesMeta": {
|
|
104
|
+
"@nozbe/watermelondb": {
|
|
105
|
+
"optional": true
|
|
106
|
+
},
|
|
107
|
+
"react-dom": {
|
|
108
|
+
"optional": true
|
|
109
|
+
},
|
|
110
|
+
"react-native": {
|
|
111
|
+
"optional": true
|
|
112
|
+
},
|
|
113
|
+
"@privy-io/react-auth": {
|
|
114
|
+
"optional": true
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
"pnpm": {
|
|
118
|
+
"overrides": {
|
|
119
|
+
"react": ">=19.0.1 <19.1.0 || >=19.1.2 <19.2.0 || >=19.2.1",
|
|
120
|
+
"react-dom": ">=19.0.1 <19.1.0 || >=19.1.2 <19.2.0 || >=19.2.1"
|
|
121
|
+
}
|
|
47
122
|
}
|
|
48
123
|
}
|