Skip to content

Commit

Permalink
refactor: move internal utils to @assistant-ui/react/internal (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Jul 30, 2024
1 parent 1e5ddee commit 3cc67f2
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 23 deletions.
10 changes: 10 additions & 0 deletions .changeset/nine-experts-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@assistant-ui/react-syntax-highlighter": patch
"@assistant-ui/react-playground": patch
"@assistant-ui/react-hook-form": patch
"@assistant-ui/react-markdown": patch
"@assistant-ui/react-ai-sdk": patch
"@assistant-ui/react": patch
---

refactor: move internal utilities to @assistant-ui/react/internal
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { type ThreadMessage, INTERNAL } from "@assistant-ui/react";
import { ModelConfigProvider } from "@assistant-ui/react";
import { type ThreadMessage, ModelConfigProvider } from "@assistant-ui/react";
import { useAssistant } from "ai/react";
import {
ProxyConfigProvider,
BaseAssistantRuntime,
} from "@assistant-ui/react/internal";
import { VercelUseAssistantThreadRuntime } from "./VercelUseAssistantThreadRuntime";

const { ProxyConfigProvider, BaseAssistantRuntime } = INTERNAL;

export const hasUpcomingMessage = (
isRunning: boolean,
messages: ThreadMessage[],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { INTERNAL } from "@assistant-ui/react";
import {
ProxyConfigProvider,
BaseAssistantRuntime,
} from "@assistant-ui/react/internal";
import { ModelConfigProvider } from "@assistant-ui/react";
import { useChat } from "ai/react";
import { VercelUseChatThreadRuntime } from "./VercelUseChatThreadRuntime";

const { ProxyConfigProvider, BaseAssistantRuntime } = INTERNAL;

export class VercelUseChatRuntime extends BaseAssistantRuntime<VercelUseChatThreadRuntime> {
private readonly _proxyConfigProvider = new ProxyConfigProvider();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ import {
type Unsubscribe,
type AppendMessage,
type ThreadMessage,
INTERNAL,
AddToolResultOptions,
} from "@assistant-ui/react";
import { MessageRepository } from "@assistant-ui/react/internal";
import type { Message } from "ai";
import { type StoreApi, type UseBoundStore, create } from "zustand";
import { useChat } from "ai/react";
import { getVercelAIMessage } from "../getVercelAIMessage";
import { sliceMessagesUntil } from "../utils/sliceMessagesUntil";
import { useVercelAIComposerSync } from "../utils/useVercelAIComposerSync";
import { useVercelAIThreadSync } from "../utils/useVercelAIThreadSync";
import { useChat } from "ai/react";

const { MessageRepository } = INTERNAL;

export const hasUpcomingMessage = (
isRunning: boolean,
Expand Down
5 changes: 2 additions & 3 deletions packages/react-markdown/src/primitives/MarkdownText.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import { INTERNAL, useContentPartText } from "@assistant-ui/react";
import { useContentPartText } from "@assistant-ui/react";
import { useSmooth } from "@assistant-ui/react/internal";
import type { ComponentType, FC } from "react";
import ReactMarkdown, { type Options } from "react-markdown";
import { SyntaxHighlighterProps, CodeHeaderProps } from "../overrides/types";
Expand All @@ -14,8 +15,6 @@ import {
import { useCallbackRef } from "@radix-ui/react-use-callback-ref";
import { CodeOverride } from "../overrides/CodeOverride";

const { useSmooth } = INTERNAL;

export type MarkdownTextPrimitiveProps = Omit<
Options,
"components" | "children"
Expand Down
5 changes: 2 additions & 3 deletions packages/react-markdown/src/ui/code-header.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { FC } from "react";
import { CheckIcon, CopyIcon } from "lucide-react";
import { useThreadConfig, INTERNAL } from "@assistant-ui/react";
import { useThreadConfig } from "@assistant-ui/react";
import { TooltipIconButton } from "@assistant-ui/react/internal";

import { CodeHeaderProps } from "../overrides/types";
import { useCopyToClipboard } from "./useCopyToClipboard";

const { TooltipIconButton } = INTERNAL;

export const CodeHeader: FC<CodeHeaderProps> = ({ language, code }) => {
const {
strings: {
Expand Down
12 changes: 7 additions & 5 deletions packages/react-playground/src/lib/playground-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@ import {
ThreadAssistantMessage,
ChatModelAdapter,
Unsubscribe,
INTERNAL,
AssistantRuntime,
ChatModelRunResult,
CoreMessage,
fromCoreMessage,
} from "@assistant-ui/react";
import {
BaseAssistantRuntime,
ProxyConfigProvider,
generateId,
} from "@assistant-ui/react/internal";
import { LanguageModelV1FunctionTool } from "@ai-sdk/provider";
import { useState } from "react";
import { create } from "zustand";
import { LanguageModelV1FunctionTool } from "@ai-sdk/provider";
import { fromCoreMessage } from "@assistant-ui/react";

const { BaseAssistantRuntime, ProxyConfigProvider, generateId } = INTERNAL;

const makeModelConfigStore = () =>
create<ModelConfig>(() => ({
Expand Down
1 change: 1 addition & 0 deletions packages/react/internal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory exists to support subpath imports for TypeScript projects using --moduleResolution node.
5 changes: 5 additions & 0 deletions packages/react/internal/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"main": "../dist/internal.js",
"module": "../dist/internal.mjs",
"types": "../dist/internal.d.ts"
}
2 changes: 1 addition & 1 deletion packages/react/scripts/build.mts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ await build({
});

await build({
entry: ["src/edge.ts", "src/tailwindcss/index.ts"],
entry: ["src/edge.ts", "src/tailwindcss/index.ts", "src/internal.ts"],
format: ["cjs", "esm"],
dts: true,
sourcemap: true,
Expand Down
3 changes: 3 additions & 0 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ export * from "./runtimes";
export * from "./types";
export * from "./ui";

/**
* @deprecated Use `@assistant-ui/react/internal` instead. This will be removed in 0.6.0.
*/
export * as INTERNAL from "./internal";

0 comments on commit 3cc67f2

Please sign in to comment.