simple-ai-sdk 1.0.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.
@@ -0,0 +1,30 @@
1
+ import eslint from "@eslint/js";
2
+ import tseslint from "typescript-eslint";
3
+ import reactHooks from "eslint-plugin-react-hooks";
4
+ import globals from "globals";
5
+
6
+ export default tseslint.config(
7
+ eslint.configs.recommended,
8
+ ...tseslint.configs.recommended,
9
+ {
10
+ plugins: {
11
+ "react-hooks": reactHooks,
12
+ },
13
+ rules: {
14
+ "react-hooks/rules-of-hooks": "error",
15
+ "react-hooks/exhaustive-deps": "warn",
16
+ },
17
+ },
18
+ {
19
+ files: ["src/**/*.{ts,tsx}"],
20
+ languageOptions: {
21
+ globals: {
22
+ ...globals.browser,
23
+ ...globals.node,
24
+ },
25
+ },
26
+ },
27
+ {
28
+ ignores: ["dist", "node_modules", "eslint.config.js"],
29
+ }
30
+ );
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "simple-ai-sdk",
3
+ "version": "1.0.0",
4
+ "private": false,
5
+ "description": "Simple AI SDK for Hono / React19+ / OpenAI",
6
+ "type": "module",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ "./client": {
11
+ "types": "./dist/client/index.d.ts",
12
+ "import": "./dist/client/index.js"
13
+ },
14
+ "./server": {
15
+ "types": "./dist/server/index.d.ts",
16
+ "import": "./dist/server/index.js"
17
+ },
18
+ "./shared": {
19
+ "types": "./dist/shared/index.d.ts",
20
+ "import": "./dist/shared/index.js"
21
+ }
22
+ },
23
+ "devDependencies": {
24
+ "@eslint/js": "^9.34.0",
25
+ "@hono/node-server": "^1.14.1",
26
+ "@types/node": "^22.0.0",
27
+ "@types/react": "^19.0.0",
28
+ "concurrently": "^9.1.2",
29
+ "eslint": "^9.34.0",
30
+ "eslint-plugin-react-hooks": "^5.2.0",
31
+ "globals": "^16.3.0",
32
+ "hono": "^4.9.4",
33
+ "openai": "^4.76.0",
34
+ "react": "^19.1.1",
35
+ "typescript": "^5.7.0",
36
+ "typescript-eslint": "^8.40.0"
37
+ },
38
+ "peerDependencies": {
39
+ "hono": "^4.9.4",
40
+ "openai": "^4.76.0",
41
+ "react": ">=19.0.0"
42
+ },
43
+ "keywords": [],
44
+ "author": "catnose <hello@catnose.me> (https://catnose.me)",
45
+ "license": "MIT",
46
+ "scripts": {
47
+ "build": "rm -rf dist && tsc",
48
+ "dev": "tsc --watch",
49
+ "typecheck": "tsc --noEmit",
50
+ "lint": "eslint .",
51
+ "prepublish": "pnpm typecheck && pnpm lint",
52
+ "publish-sdk": "pnpm build && pnpm publish --no-git-checks --access public",
53
+ "test": "echo \"Error: no test specified\" && exit 1"
54
+ }
55
+ }
@@ -0,0 +1,45 @@
1
+ import React, { createContext, use, useMemo } from "react";
2
+ import { StreamManager, type IStreamManager } from "./manager.js";
3
+
4
+ const StreamContext = createContext<IStreamManager | null>(null);
5
+
6
+ export type SimpleAIProviderProps = {
7
+ children: React.ReactNode;
8
+ maxSessions?: number;
9
+ debug?: boolean;
10
+ /**
11
+ * TTL(ミリ秒)。アクセスのない ready/error セッションを定期的に破棄する。
12
+ * 未指定の場合は破棄しない。
13
+ */
14
+ ttlMs?: number;
15
+ };
16
+
17
+ export function SimpleAIProvider({
18
+ children,
19
+ maxSessions,
20
+ debug,
21
+ ttlMs,
22
+ }: SimpleAIProviderProps) {
23
+ // Create StreamManager instance with custom options
24
+ const manager = useMemo(() => {
25
+ return new StreamManager({ maxSessions, debug, ttlMs });
26
+ }, [maxSessions, debug, ttlMs]);
27
+
28
+ // Provider がアンマウントされる際に、内部タイマーなどをクリーンアップする
29
+ // (メモリリーク防止のため)
30
+ React.useEffect(() => {
31
+ return () => {
32
+ manager.dispose();
33
+ };
34
+ }, [manager]);
35
+
36
+ return <StreamContext value={manager}>{children}</StreamContext>;
37
+ }
38
+
39
+ export function useAIStreamManager() {
40
+ const manager = use(StreamContext);
41
+ if (!manager) {
42
+ throw new Error("useAIStreamManager must be used within SimpleAIProvider");
43
+ }
44
+ return manager;
45
+ }
@@ -0,0 +1,9 @@
1
+ export { SimpleAIProvider, useAIStreamManager } from "./context.js";
2
+ export { useChatSession } from "./useChatSession.js";
3
+ export { streamManager, type IStreamManager } from "./manager.js";
4
+ export type {
5
+ ChatStatus,
6
+ ChatSession,
7
+ UseChatSessionOptions,
8
+ UseChatSessionReturn,
9
+ } from "./types.js";