Skip to content

Commit

Permalink
fix: revert
Browse files Browse the repository at this point in the history
  • Loading branch information
ytkimirti committed Sep 30, 2024
1 parent 35c6ac8 commit 1d2c853
Show file tree
Hide file tree
Showing 19 changed files with 390 additions and 16 deletions.
22 changes: 22 additions & 0 deletions nextjs/index.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { JSONValue, StreamingTextResponse } from 'ai';
import { StreamableValue } from 'ai/rsc';

/**
* Converts a ReadableStream response from the chat() function into a StreamingTextResponse
* suitable for use with the ai-sdk's useChat Next.js hook.
*
* @param response - The response object containing:
* - output: A ReadableStream of LangChainAIMessageChunk from the chat function.
* - isStream: A boolean indicating if the response is a stream.
* @returns StreamingTextResponse - The adapted response for use with the useChat hook.
*/
declare const aiUseChatAdapter: (response: {
output: ReadableStream<string>;
isStream: true;
}, metadata?: JSONValue) => StreamingTextResponse;

declare const readServerActionStream: (stream: StreamableValue<string>) => AsyncIterable<string | undefined>;

declare const createServerActionStream: (stream: ReadableStream<string>) => StreamableValue<string>;

export { aiUseChatAdapter, createServerActionStream, readServerActionStream };
22 changes: 22 additions & 0 deletions nextjs/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { JSONValue, StreamingTextResponse } from 'ai';
import { StreamableValue } from 'ai/rsc';

/**
* Converts a ReadableStream response from the chat() function into a StreamingTextResponse
* suitable for use with the ai-sdk's useChat Next.js hook.
*
* @param response - The response object containing:
* - output: A ReadableStream of LangChainAIMessageChunk from the chat function.
* - isStream: A boolean indicating if the response is a stream.
* @returns StreamingTextResponse - The adapted response for use with the useChat hook.
*/
declare const aiUseChatAdapter: (response: {
output: ReadableStream<string>;
isStream: true;
}, metadata?: JSONValue) => StreamingTextResponse;

declare const readServerActionStream: (stream: StreamableValue<string>) => AsyncIterable<string | undefined>;

declare const createServerActionStream: (stream: ReadableStream<string>) => StreamableValue<string>;

export { aiUseChatAdapter, createServerActionStream, readServerActionStream };
54 changes: 54 additions & 0 deletions nextjs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/nextjs/index.ts
var nextjs_exports = {};
__export(nextjs_exports, {
aiUseChatAdapter: () => aiUseChatAdapter,
readServerActionStream: () => readServerActionStream
});
module.exports = __toCommonJS(nextjs_exports);

// src/nextjs/chat-adapter.ts
var import_ai = require("ai");
var aiUseChatAdapter = (response, metadata) => {
const streamData = new import_ai.StreamData();
const wrappedStream = import_ai.LangChainAdapter.toAIStream(response.output, {
onStart() {
if (metadata) {
streamData.append(metadata);
}
},
onFinal() {
void streamData.close();
}
});
return new import_ai.StreamingTextResponse(wrappedStream, {}, streamData);
};

// src/nextjs/server-action-read-adapter.ts
var import_rsc = require("ai/rsc");
var readServerActionStream = (stream) => {
return (0, import_rsc.readStreamableValue)(stream);
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
aiUseChatAdapter,
readServerActionStream
});
26 changes: 26 additions & 0 deletions nextjs/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// src/nextjs/chat-adapter.ts
import { LangChainAdapter, StreamData, StreamingTextResponse } from "ai";
var aiUseChatAdapter = (response, metadata) => {
const streamData = new StreamData();
const wrappedStream = LangChainAdapter.toAIStream(response.output, {
onStart() {
if (metadata) {
streamData.append(metadata);
}
},
onFinal() {
void streamData.close();
}
});
return new StreamingTextResponse(wrappedStream, {}, streamData);
};

// src/nextjs/server-action-read-adapter.ts
import { readStreamableValue } from "ai/rsc";
var readServerActionStream = (stream) => {
return readStreamableValue(stream);
};
export {
aiUseChatAdapter,
readServerActionStream
};
20 changes: 20 additions & 0 deletions nextjs/rsc-server.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { StreamableValue } from 'ai/rsc';
import { JSONValue, StreamingTextResponse } from 'ai';

declare const createServerActionStream: (stream: ReadableStream<string>) => StreamableValue<string>;

/**
* Converts a ReadableStream response from the chat() function into a StreamingTextResponse
* suitable for use with the ai-sdk's useChat Next.js hook.
*
* @param response - The response object containing:
* - output: A ReadableStream of LangChainAIMessageChunk from the chat function.
* - isStream: A boolean indicating if the response is a stream.
* @returns StreamingTextResponse - The adapted response for use with the useChat hook.
*/
declare const aiUseChatAdapter: (response: {
output: ReadableStream<string>;
isStream: true;
}, metadata?: JSONValue) => StreamingTextResponse;

export { aiUseChatAdapter, createServerActionStream };
43 changes: 43 additions & 0 deletions nextjs/rsc-server.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// src/nextjs/server-action-write-adapter.ts
import { createStreamableValue } from "ai/rsc";
var createServerActionStream = (stream) => {
const streamableValue = createStreamableValue("");
const reader = stream.getReader();
(async () => {
try {
while (true) {
const { done, value } = await reader.read();
if (done) break;
if (typeof value === "string") {
streamableValue.update(value);
}
}
streamableValue.done();
} catch (error) {
console.error("Error while reading stream:", error);
streamableValue.error("An error occurred while processing the stream");
}
})();
return streamableValue.value;
};

// src/nextjs/chat-adapter.ts
import { LangChainAdapter, StreamData, StreamingTextResponse } from "ai";
var aiUseChatAdapter = (response, metadata) => {
const streamData = new StreamData();
const wrappedStream = LangChainAdapter.toAIStream(response.output, {
onStart() {
if (metadata) {
streamData.append(metadata);
}
},
onFinal() {
void streamData.close();
}
});
return new StreamingTextResponse(wrappedStream, {}, streamData);
};
export {
aiUseChatAdapter,
createServerActionStream
};
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"name": "@upstash/rag-chat",
"version": "1.0.5",
"main": "./dist/index.mjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"main": "./index.mjs",
"module": "./index.mjs",
"types": "./index.d.ts",
"sideEffects": false,
"scripts": {
"test": "bun test",
"fmt": "prettier --write .",
"lint": "eslint \"src/**/*.{js,ts,tsx}\" --quiet --fix",
"build": "tsup",
"build": "tsup && cp package.json README.md LICENSE dist/",
"prepare": "husky",
"check-types": "tsc --noEmit"
"check-types": "tsc --noEmit",
"check-exports": "bun run build && cd dist && attw -P"
},
"lint-staged": {
"*": [
Expand All @@ -24,18 +25,17 @@
},
"description": "Simple RAG Chat using Upstash",
"files": [
"dist",
"nextjs/dist"
"./*"
],
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js"
"import": "./index.mjs",
"require": "./index.js"
},
"./nextjs": {
"react-server": "./nextjs/dist/rsc-server.mjs",
"import": "./nextjs/dist/index.mjs",
"require": "./nextjs/dist/index.js"
"react-server": "./nextjs/rsc-server.mjs",
"import": "./nextjs/index.mjs",
"require": "./nextjs/index.js"
}
},
"homepage": "https://upstash.com/docs/vector/sdks/rag-chat",
Expand Down
File renamed without changes.
22 changes: 22 additions & 0 deletions src/nextjs/index.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { JSONValue, StreamingTextResponse } from 'ai';
import { StreamableValue } from 'ai/rsc';

/**
* Converts a ReadableStream response from the chat() function into a StreamingTextResponse
* suitable for use with the ai-sdk's useChat Next.js hook.
*
* @param response - The response object containing:
* - output: A ReadableStream of LangChainAIMessageChunk from the chat function.
* - isStream: A boolean indicating if the response is a stream.
* @returns StreamingTextResponse - The adapted response for use with the useChat hook.
*/
declare const aiUseChatAdapter: (response: {
output: ReadableStream<string>;
isStream: true;
}, metadata?: JSONValue) => StreamingTextResponse;

declare const readServerActionStream: (stream: StreamableValue<string>) => AsyncIterable<string | undefined>;

declare const createServerActionStream: (stream: ReadableStream<string>) => StreamableValue<string>;

export { aiUseChatAdapter, createServerActionStream, readServerActionStream };
22 changes: 22 additions & 0 deletions src/nextjs/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { JSONValue, StreamingTextResponse } from 'ai';
import { StreamableValue } from 'ai/rsc';

/**
* Converts a ReadableStream response from the chat() function into a StreamingTextResponse
* suitable for use with the ai-sdk's useChat Next.js hook.
*
* @param response - The response object containing:
* - output: A ReadableStream of LangChainAIMessageChunk from the chat function.
* - isStream: A boolean indicating if the response is a stream.
* @returns StreamingTextResponse - The adapted response for use with the useChat hook.
*/
declare const aiUseChatAdapter: (response: {
output: ReadableStream<string>;
isStream: true;
}, metadata?: JSONValue) => StreamingTextResponse;

declare const readServerActionStream: (stream: StreamableValue<string>) => AsyncIterable<string | undefined>;

declare const createServerActionStream: (stream: ReadableStream<string>) => StreamableValue<string>;

export { aiUseChatAdapter, createServerActionStream, readServerActionStream };
54 changes: 54 additions & 0 deletions src/nextjs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// nextjs/index.ts
var nextjs_exports = {};
__export(nextjs_exports, {
aiUseChatAdapter: () => aiUseChatAdapter,
readServerActionStream: () => readServerActionStream
});
module.exports = __toCommonJS(nextjs_exports);

// nextjs/chat-adapter.ts
var import_ai = require("ai");
var aiUseChatAdapter = (response, metadata) => {
const streamData = new import_ai.StreamData();
const wrappedStream = import_ai.LangChainAdapter.toAIStream(response.output, {
onStart() {
if (metadata) {
streamData.append(metadata);
}
},
onFinal() {
void streamData.close();
}
});
return new import_ai.StreamingTextResponse(wrappedStream, {}, streamData);
};

// nextjs/server-action-read-adapter.ts
var import_rsc = require("ai/rsc");
var readServerActionStream = (stream) => {
return (0, import_rsc.readStreamableValue)(stream);
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
aiUseChatAdapter,
readServerActionStream
});
26 changes: 26 additions & 0 deletions src/nextjs/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// nextjs/chat-adapter.ts
import { LangChainAdapter, StreamData, StreamingTextResponse } from "ai";
var aiUseChatAdapter = (response, metadata) => {
const streamData = new StreamData();
const wrappedStream = LangChainAdapter.toAIStream(response.output, {
onStart() {
if (metadata) {
streamData.append(metadata);
}
},
onFinal() {
void streamData.close();
}
});
return new StreamingTextResponse(wrappedStream, {}, streamData);
};

// nextjs/server-action-read-adapter.ts
import { readStreamableValue } from "ai/rsc";
var readServerActionStream = (stream) => {
return readStreamableValue(stream);
};
export {
aiUseChatAdapter,
readServerActionStream
};
File renamed without changes.
20 changes: 20 additions & 0 deletions src/nextjs/rsc-server.d.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { StreamableValue } from 'ai/rsc';
import { JSONValue, StreamingTextResponse } from 'ai';

declare const createServerActionStream: (stream: ReadableStream<string>) => StreamableValue<string>;

/**
* Converts a ReadableStream response from the chat() function into a StreamingTextResponse
* suitable for use with the ai-sdk's useChat Next.js hook.
*
* @param response - The response object containing:
* - output: A ReadableStream of LangChainAIMessageChunk from the chat function.
* - isStream: A boolean indicating if the response is a stream.
* @returns StreamingTextResponse - The adapted response for use with the useChat hook.
*/
declare const aiUseChatAdapter: (response: {
output: ReadableStream<string>;
isStream: true;
}, metadata?: JSONValue) => StreamingTextResponse;

export { aiUseChatAdapter, createServerActionStream };
Loading

0 comments on commit 1d2c853

Please sign in to comment.