@alquimia-ai/tools 1.0.14 → 1.0.16

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/package.json CHANGED
@@ -1,59 +1,45 @@
1
1
  {
2
2
  "name": "@alquimia-ai/tools",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "author": "Alquimia AI",
5
5
  "description": "tools for Alquimia SDK",
6
6
  "private": false,
7
7
  "license": "MIT",
8
8
  "exports": {
9
9
  "./sdk": {
10
- "types": "./src/sdk/index.ts",
11
- "import": "./src/sdk/index.ts",
12
- "require": "./dist/sdk/index.js",
13
- "development": "./src/sdk/index.ts",
14
- "production": "./dist/sdk/index.js"
10
+ "types": "./dist/sdk/index.d.ts",
11
+ "import": "./dist/sdk/index.mjs",
12
+ "require": "./dist/sdk/index.js"
15
13
  },
16
14
  "./hooks": {
17
- "types": "./src/hooks/index.ts",
18
- "import": "./src/hooks/index.ts",
19
- "require": "./dist/hooks/index.js",
20
- "development": "./src/hooks/index.ts",
21
- "production": "./dist/hooks/index.js"
15
+ "types": "./dist/hooks/index.d.ts",
16
+ "import": "./dist/hooks/index.mjs",
17
+ "require": "./dist/hooks/index.js"
22
18
  },
23
19
  "./actions": {
24
- "types": "./src/actions/index.ts",
25
- "import": "./src/actions/index.ts",
26
- "require": "./dist/actions/index.js",
27
- "development": "./src/actions/index.ts",
28
- "production": "./dist/actions/index.js"
20
+ "types": "./dist/actions/index.d.ts",
21
+ "import": "./dist/actions/index.mjs",
22
+ "require": "./dist/actions/index.cjs"
29
23
  },
30
24
  "./providers": {
31
- "types": "./src/providers/index.ts",
32
- "import": "./src/providers/index.ts",
33
- "require": "./dist/providers/index.js",
34
- "development": "./src/providers/index.ts",
35
- "production": "./dist/providers/index.js"
25
+ "types": "./dist/providers/index.d.ts",
26
+ "import": "./dist/providers/index.mjs",
27
+ "require": "./dist/providers/index.js"
36
28
  },
37
29
  "./utils": {
38
- "types": "./src/utils/index.ts",
39
- "import": "./src/utils/index.ts",
40
- "require": "./dist/utils/index.js",
41
- "development": "./src/utils/index.ts",
42
- "production": "./dist/utils/index.js"
30
+ "types": "./dist/utils/index.d.ts",
31
+ "import": "./dist/utils/index.mjs",
32
+ "require": "./dist/utils/index.js"
43
33
  },
44
34
  "./types": {
45
- "types": "./src/types/index.ts",
46
- "import": "./src/types/index.ts",
47
- "require": "./dist/types/index.js",
48
- "development": "./src/types/index.ts",
49
- "production": "./dist/types/index.js"
35
+ "types": "./dist/types/index.d.ts",
36
+ "import": "./dist/types/index.mjs",
37
+ "require": "./dist/types/index.js"
50
38
  },
51
39
  "./services": {
52
- "types": "./src/services/index.ts",
53
- "import": "./src/services/index.ts",
54
- "require": "./dist/services/index.js",
55
- "development": "./src/services/index.ts",
56
- "production": "./dist/services/index.js"
40
+ "types": "./dist/services/index.d.ts",
41
+ "import": "./dist/services/index.mjs",
42
+ "require": "./dist/services/index.js"
57
43
  },
58
44
  "./package.json": "./package.json"
59
45
  },
@@ -61,11 +47,11 @@
61
47
  "lint": "eslint . --max-warnings 0",
62
48
  "generate:component": "turbo gen react-component",
63
49
  "build": "tsup src/index.ts src/**/index.ts --format esm,cjs --target es2020",
64
- "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
50
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
51
+ "dev": "tsup src/index.ts src/**/index.ts --format esm,cjs --target es2020 --watch"
65
52
  },
66
53
  "files": [
67
54
  "dist/**",
68
- "src/**",
69
55
  "README.md",
70
56
  "package.json"
71
57
  ],
@@ -100,4 +86,4 @@
100
86
  "react": ">=18.0.0",
101
87
  "react-dom": ">=18.0.0"
102
88
  }
103
- }
89
+ }
@@ -1,42 +0,0 @@
1
- 'use server'
2
- import { randomUUID } from "crypto";
3
- import { cookies } from "next/headers";
4
- import { ConversationsMap } from "../types/type";
5
-
6
- export async function initConversation(reset?: boolean, topicId?: string) {
7
- const cookieStore = await cookies();
8
-
9
- if (!topicId) {
10
- let conversationId = randomUUID().toString();
11
- const alquimia_session = cookieStore.get("alquimia-session");
12
-
13
- if (!alquimia_session || reset) {
14
- cookieStore.set("alquimia-session", conversationId);
15
- } else {
16
- conversationId = alquimia_session.value;
17
- }
18
-
19
- return conversationId;
20
- }
21
-
22
- let conversationsMap: ConversationsMap = {};
23
- const existingConversations = cookieStore.get("alquimia-sessions");
24
-
25
- if (existingConversations) {
26
- try {
27
- const decodedValue = decodeURIComponent(existingConversations.value);
28
- conversationsMap = JSON.parse(decodedValue) as ConversationsMap;
29
- } catch (e) {
30
- console.error('Error parsing conversations cookie:', e);
31
- conversationsMap = {};
32
- }
33
- }
34
-
35
- if (!conversationsMap[topicId] || reset) {
36
- conversationsMap[topicId] = randomUUID().toString();
37
- }
38
-
39
- cookieStore.set("alquimia-sessions", JSON.stringify(conversationsMap));
40
-
41
- return conversationsMap[topicId];
42
- }
@@ -1,56 +0,0 @@
1
- "use server";
2
- import { headers } from "next/headers";
3
-
4
- export type ApmRequestConfig = {
5
- apmServerUrl: string;
6
- };
7
-
8
- export async function handleApmRequest(
9
- request: Request,
10
- config: ApmRequestConfig
11
- ): Promise<Response> {
12
- try {
13
- const headersList = await headers();
14
- const body = await request.arrayBuffer();
15
-
16
- const apmUrl = `${config.apmServerUrl}/intake/v2/rum/events`;
17
-
18
- const response = await fetch(apmUrl, {
19
- method: "POST",
20
- headers: {
21
- "Content-Type": "application/x-ndjson",
22
- Accept: "*/*",
23
- "Content-Encoding": "gzip",
24
- "User-Agent": "elastic-apm-rum/5.15.0",
25
- },
26
- body: body,
27
- });
28
-
29
- if (!response.ok) {
30
- const errorText = await response.text();
31
- console.error("APM server error:", {
32
- status: response.status,
33
- statusText: response.statusText,
34
- body: errorText,
35
- });
36
- throw new Error(
37
- `APM server responded with ${response.status}: ${errorText}`
38
- );
39
- }
40
-
41
- return new Response(null, {
42
- status: 200,
43
- headers: {
44
- "Access-Control-Allow-Origin": "*",
45
- "Access-Control-Allow-Methods": "POST, OPTIONS",
46
- "Access-Control-Allow-Headers": "Content-Type, Content-Encoding",
47
- },
48
- });
49
- } catch (error) {
50
- console.error("APM proxy error:", error);
51
- return new Response(
52
- JSON.stringify({ error: "Failed to forward APM data" }),
53
- { status: 500 }
54
- );
55
- }
56
- }
@@ -1,187 +0,0 @@
1
- "use server";
2
- import { BaseAPIConfig } from "../types/type";
3
- import { generateHeaders, isTextContent } from "../utils";
4
-
5
- interface ActionResponse<T = void> {
6
- success: boolean;
7
- data?: T;
8
- contentType?: string;
9
- error?: {
10
- message: string;
11
- code?: string;
12
- details?: any;
13
- };
14
- }
15
-
16
- export async function createResource<TResponse, TPayload>(
17
- config: BaseAPIConfig,
18
- payload: TPayload
19
- ): Promise<ActionResponse<TResponse>> {
20
- try {
21
- const headers = generateHeaders(config);
22
-
23
- const response = await fetch(`${config.baseUrl}${config.route}`, {
24
- method: "POST",
25
- headers,
26
- body: JSON.stringify(payload),
27
- cache: "default",
28
- });
29
-
30
- if (!response.ok) {
31
- const error = await response.json();
32
- return {
33
- success: false,
34
- error: {
35
- message: error.message || `Server returned ${response.status}`,
36
- code: response.status.toString(),
37
- details: {
38
- status: response.status,
39
- statusText: response.statusText,
40
- },
41
- },
42
- };
43
- }
44
-
45
- return {
46
- success: true,
47
- data: await response.json(),
48
- };
49
- } catch (error) {
50
- throw new Error("Failed to create resource");
51
- }
52
- }
53
-
54
- export async function readResource<T>(
55
- config: BaseAPIConfig,
56
- id?: string
57
- ): Promise<ActionResponse<T>> {
58
- try {
59
- const headers = generateHeaders(config);
60
- const url = id
61
- ? `${config.baseUrl}${config.route}/${id}`
62
- : `${config.baseUrl}${config.route}`;
63
-
64
- const response = await fetch(url, {
65
- method: "GET",
66
- headers,
67
- cache: "default",
68
- });
69
-
70
- if (!response.ok) {
71
- const error = await response.json();
72
- return {
73
- success: false,
74
- error: {
75
- message: error.message || `Server returned ${response.status}`,
76
- code: response.status.toString(),
77
- details: {
78
- status: response.status,
79
- statusText: response.statusText,
80
- },
81
- },
82
- };
83
- }
84
-
85
- const contentType = response.headers.get("content-type");
86
- if (contentType?.includes("application/json")) {
87
- return {
88
- success: true,
89
- data: await response.json(),
90
- contentType: contentType || undefined,
91
- };
92
- }
93
-
94
- const arrayBuffer = await response.arrayBuffer();
95
-
96
- if (contentType?.includes("octet-stream") && isTextContent(arrayBuffer)) {
97
- return {
98
- success: true,
99
- data: arrayBuffer as T,
100
- contentType: "text/plain",
101
- };
102
- }
103
-
104
- return {
105
- success: true,
106
- data: await response.json(),
107
- contentType: contentType || undefined,
108
- };
109
- } catch (error) {
110
- throw new Error("Failed to read resource");
111
- }
112
- }
113
-
114
- export async function updateResource<T>(
115
- config: BaseAPIConfig,
116
- id: string,
117
- data: T
118
- ): Promise<ActionResponse<T>> {
119
- try {
120
- const headers = generateHeaders(config);
121
-
122
- const response = await fetch(`${config.baseUrl}${config.route}/${id}`, {
123
- method: "PUT",
124
- headers,
125
- body: JSON.stringify(data),
126
- cache: "default",
127
- });
128
-
129
- if (!response.ok) {
130
- const error = await response.json();
131
- return {
132
- success: false,
133
- error: {
134
- message: error.message || `Server returned ${response.status}`,
135
- code: response.status.toString(),
136
- details: {
137
- status: response.status,
138
- statusText: response.statusText,
139
- },
140
- },
141
- };
142
- }
143
-
144
- return {
145
- success: true,
146
- data: await response.json(),
147
- };
148
- } catch (error) {
149
- throw new Error("Failed to update resource");
150
- }
151
- }
152
-
153
- export async function deleteResource(
154
- config: BaseAPIConfig,
155
- id: string
156
- ): Promise<ActionResponse<void>> {
157
- try {
158
- const headers = generateHeaders(config);
159
-
160
- const response = await fetch(`${config.baseUrl}${config.route}/${id}`, {
161
- method: "DELETE",
162
- headers,
163
- cache: "default",
164
- });
165
-
166
- if (!response.ok) {
167
- const error = await response.json();
168
- return {
169
- success: false,
170
- error: {
171
- message: error.message || `Server returned ${response.status}`,
172
- code: response.status.toString(),
173
- details: {
174
- status: response.status,
175
- statusText: response.statusText,
176
- },
177
- },
178
- };
179
- }
180
-
181
- return {
182
- success: true,
183
- };
184
- } catch (error) {
185
- throw new Error("Failed to delete resource");
186
- }
187
- }
@@ -1,134 +0,0 @@
1
- "use server";
2
- import { NextResponse } from "next/server";
3
- import { headers } from "next/headers";
4
-
5
- export type ChatRouteContext = {
6
- params: {
7
- path: string[];
8
- };
9
- };
10
-
11
- export type ChatRequestConfig = {
12
- assistantBaseUrl: string;
13
- assistantRoute?: string;
14
- apiKey: string;
15
- };
16
-
17
- export type ChatResponse = Response | any;
18
-
19
- export async function handleChatRequest(
20
- request: Request,
21
- context: ChatRouteContext,
22
- config: ChatRequestConfig
23
- ): Promise<ChatResponse> {
24
- try {
25
- const headersList = await headers();
26
- const body = await request.json();
27
- const routeParams = await context.params;
28
- const routePath = routeParams.path.join("/");
29
- const assistantRoute = config.assistantRoute || "infer";
30
-
31
- const assistantUrl = `${config.assistantBaseUrl}/${assistantRoute}/${routePath}`;
32
-
33
- const response = await fetch(assistantUrl, {
34
- method: "POST",
35
- headers: {
36
- "Content-Type": "application/json",
37
- Authorization: `Bearer ${config.apiKey}`,
38
- ...headersList,
39
- },
40
- body: JSON.stringify(body),
41
- });
42
-
43
- if (!response.ok) {
44
- const errorJson = await response.json();
45
- console.error("Chat inference server error:", {
46
- status: response.status,
47
- statusText: response.statusText,
48
- body: errorJson,
49
- });
50
-
51
- return NextResponse.json(
52
- {
53
- error:
54
- errorJson.message ||
55
- response.statusText ||
56
- "Failed to forward Chat data",
57
- },
58
- { status: response.status }
59
- );
60
- }
61
-
62
- return new NextResponse(response.body, {
63
- status: 200,
64
- headers: {
65
- "Access-Control-Allow-Origin": "*",
66
- "Access-Control-Allow-Methods": "POST, OPTIONS",
67
- "Access-Control-Allow-Headers": "Content-Type, Content-Encoding",
68
- },
69
- });
70
- } catch (error) {
71
- return NextResponse.json(
72
- { error: "Failed to forward Chat data" },
73
- { status: 500 }
74
- );
75
- }
76
- }
77
-
78
- export async function handleStreamRequest(
79
- request: Request,
80
- context: ChatRouteContext,
81
- config: ChatRequestConfig
82
- ): Promise<Response> {
83
- try {
84
- const headersList = await headers();
85
- const routeParams = context.params;
86
- const path = routeParams.path.join("/");
87
- const assistantRoute = config.assistantRoute || "stream";
88
-
89
- const streamUrl = `${config.assistantBaseUrl}/${assistantRoute}/${path}`;
90
-
91
- const response = await fetch(streamUrl, {
92
- headers: {
93
- "Content-Type": "application/json",
94
- Authorization: `Bearer ${config.apiKey}`,
95
- ...Object.fromEntries(headersList.entries()),
96
- },
97
- });
98
-
99
- if (!response.ok) {
100
- const errorJson = await response.json();
101
- console.error("Stream server error:", {
102
- status: response.status,
103
- statusText: response.statusText,
104
- body: errorJson,
105
- });
106
-
107
- return new Response(
108
- JSON.stringify({
109
- error:
110
- errorJson.message ||
111
- response.statusText ||
112
- "Failed to forward Stream data",
113
- }),
114
- { status: response.status }
115
- );
116
- }
117
-
118
- return new Response(response.body, {
119
- status: 200,
120
- headers: {
121
- "Content-Type": "text/event-stream",
122
- "Cache-Control": "no-cache",
123
- Connection: "keep-alive",
124
- },
125
- });
126
- } catch (error) {
127
- console.error("Stream error:", error);
128
- return new Response(
129
- JSON.stringify({ error: "Failed to forward stream data" }),
130
- { status: 500 }
131
- );
132
- }
133
- }
134
-
@@ -1,4 +0,0 @@
1
- export * from './alquimia.action'
2
- export * from './baseApi.action'
3
- export * from './chat.action'
4
- export * from './apm.action'
package/src/button.tsx DELETED
@@ -1,20 +0,0 @@
1
- "use client";
2
-
3
- import { ReactNode } from "react";
4
-
5
- interface ButtonProps {
6
- children: ReactNode;
7
- className?: string;
8
- appName: string;
9
- }
10
-
11
- export const Button = ({ children, className, appName }: ButtonProps) => {
12
- return (
13
- <button
14
- className={className}
15
- onClick={() => alert(`Hello from your ${appName} app!`)}
16
- >
17
- {children}
18
- </button>
19
- );
20
- };
package/src/card.tsx DELETED
@@ -1,25 +0,0 @@
1
- export function Card({
2
- className,
3
- title,
4
- children,
5
- href,
6
- }: {
7
- className?: string;
8
- title: string;
9
- children: React.ReactNode;
10
- href: string;
11
- }): JSX.Element {
12
- return (
13
- <a
14
- className={className}
15
- href={`${href}?utm_source=create-turbo&utm_medium=basic&utm_campaign=create-turbo"`}
16
- rel="noopener noreferrer"
17
- target="_blank"
18
- >
19
- <h2>
20
- {title} <span>-&gt;</span>
21
- </h2>
22
- <p>{children}</p>
23
- </a>
24
- );
25
- }
package/src/code.tsx DELETED
@@ -1,9 +0,0 @@
1
- export function Code({
2
- children,
3
- className,
4
- }: {
5
- children: React.ReactNode;
6
- className?: string;
7
- }): JSX.Element {
8
- return <code className={className}>{children}</code>;
9
- }