@fluxyte/sdk 0.0.1 → 0.2.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.
- package/LICENSE.md +20 -0
- package/README.md +148 -5
- package/dist/core/client.d.ts +17 -0
- package/dist/core/client.d.ts.map +1 -0
- package/dist/core/client.js +47 -0
- package/dist/core/client.js.map +1 -0
- package/dist/core/errors.d.ts +16 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +37 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/sse.d.ts +18 -0
- package/dist/core/sse.d.ts.map +1 -0
- package/dist/core/sse.js +47 -0
- package/dist/core/sse.js.map +1 -0
- package/dist/core/utils.d.ts +2 -0
- package/dist/core/utils.d.ts.map +1 -0
- package/dist/core/utils.js +17 -0
- package/dist/core/utils.js.map +1 -0
- package/dist/generated/openapi.d.ts +186 -0
- package/dist/generated/openapi.d.ts.map +1 -0
- package/dist/generated/openapi.js +6 -0
- package/dist/generated/openapi.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/node/index.d.ts +5 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +14 -0
- package/dist/node/index.js.map +1 -0
- package/dist/react/OnboardingAIProvider.d.ts +7 -0
- package/dist/react/OnboardingAIProvider.d.ts.map +1 -0
- package/dist/react/OnboardingAIProvider.js +15 -0
- package/dist/react/OnboardingAIProvider.js.map +1 -0
- package/dist/react/index.d.ts +7 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +8 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/useChat.d.ts +24 -0
- package/dist/react/useChat.d.ts.map +1 -0
- package/dist/react/useChat.js +27 -0
- package/dist/react/useChat.js.map +1 -0
- package/dist/react/useFeedback.d.ts +10 -0
- package/dist/react/useFeedback.d.ts.map +1 -0
- package/dist/react/useFeedback.js +31 -0
- package/dist/react/useFeedback.js.map +1 -0
- package/dist/react/useOnboardingEvents.d.ts +9 -0
- package/dist/react/useOnboardingEvents.d.ts.map +1 -0
- package/dist/react/useOnboardingEvents.js +24 -0
- package/dist/react/useOnboardingEvents.js.map +1 -0
- package/dist/react/useStreamingChat.d.ts +12 -0
- package/dist/react/useStreamingChat.d.ts.map +1 -0
- package/dist/react/useStreamingChat.js +35 -0
- package/dist/react/useStreamingChat.js.map +1 -0
- package/dist/vanilla/index.d.ts +4 -0
- package/dist/vanilla/index.d.ts.map +1 -0
- package/dist/vanilla/index.js +3 -0
- package/dist/vanilla/index.js.map +1 -0
- package/package.json +50 -8
- package/index.d.ts +0 -1
- package/index.js +0 -1
package/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Fluxyte SDK License (Proprietary)
|
|
2
|
+
|
|
3
|
+
Copyright (c) Fluxyte.
|
|
4
|
+
|
|
5
|
+
This SDK is proprietary software provided under a commercial license.
|
|
6
|
+
|
|
7
|
+
## Permitted use
|
|
8
|
+
|
|
9
|
+
You may download, install, and use the **unmodified** SDK solely for integrating with
|
|
10
|
+
Fluxyte services and operating your own applications.
|
|
11
|
+
|
|
12
|
+
## Restrictions
|
|
13
|
+
|
|
14
|
+
Except as expressly permitted by Fluxyte in a separate written agreement, you may not:
|
|
15
|
+
|
|
16
|
+
- modify, adapt, or create derivative works of the SDK
|
|
17
|
+
- redistribute, publish, or otherwise make the SDK available to third parties
|
|
18
|
+
- sublicense, sell, or transfer the SDK
|
|
19
|
+
|
|
20
|
+
For licensing questions, contact: support@fluxyte.com
|
package/README.md
CHANGED
|
@@ -1,5 +1,148 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
# Fluxyte SDK (TypeScript)
|
|
2
|
+
|
|
3
|
+
A TypeScript SDK for the Fluxyte Onboarding AI API.
|
|
4
|
+
|
|
5
|
+
Includes:
|
|
6
|
+
- HTTP client (fetch-based) with strong typing generated from OpenAPI
|
|
7
|
+
- Streaming (SSE) and non-streaming chat
|
|
8
|
+
- React provider + hooks
|
|
9
|
+
- Node and browser entrypoints
|
|
10
|
+
- Onboarding events and answer feedback
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @fluxyte/sdk
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Requirements
|
|
19
|
+
|
|
20
|
+
- Browser or Node.js 18+ (global `fetch` available)
|
|
21
|
+
- A valid API key (sent as `X-API-Key`)
|
|
22
|
+
|
|
23
|
+
## Create A Client
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { OnboardingAIClient } from "@fluxyte/sdk";
|
|
27
|
+
|
|
28
|
+
const client = new OnboardingAIClient("YOUR_API_KEY");
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Basic Chat (Non-Streaming)
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
const res = await client.chat({
|
|
35
|
+
message: "How do I connect my database?",
|
|
36
|
+
sessionId: "sess_123",
|
|
37
|
+
context: {
|
|
38
|
+
product: "analytics-dashboard",
|
|
39
|
+
userTarget: "admin",
|
|
40
|
+
stepSlug: "connect_database",
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
console.log(res.answerId);
|
|
45
|
+
console.log(res.reply);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Streaming Chat (SSE)
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
const stop = client.streamChat(
|
|
52
|
+
{
|
|
53
|
+
message: "What's the next step?",
|
|
54
|
+
sessionId: "sess_123",
|
|
55
|
+
context: { product: "analytics-dashboard", userTarget: "admin" },
|
|
56
|
+
},
|
|
57
|
+
(event) => {
|
|
58
|
+
if (event.type === "meta") console.log("Answer ID:", event.answerId);
|
|
59
|
+
if (event.type === "delta") process.stdout.write(event.replyDelta);
|
|
60
|
+
if (event.type === "done") console.log("\nConfidence:", event.confidence);
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
// stop() cancels streaming
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Onboarding Events
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
await client.sendEvent({
|
|
71
|
+
type: "STEP_COMPLETED",
|
|
72
|
+
context: {
|
|
73
|
+
product: "analytics",
|
|
74
|
+
userTarget: "admin",
|
|
75
|
+
stepSlug: "connect_database",
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Feedback
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
await client.submitFeedback({
|
|
84
|
+
answerId: "ans_7xk9p2m",
|
|
85
|
+
rating: "GOOD",
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## React Usage
|
|
90
|
+
|
|
91
|
+
```tsx
|
|
92
|
+
import { OnboardingAIClient } from "@fluxyte/sdk";
|
|
93
|
+
import { OnboardingAIProvider } from "@fluxyte/sdk/react";
|
|
94
|
+
|
|
95
|
+
const client = new OnboardingAIClient(import.meta.env.VITE_FLUXYTE_API_KEY);
|
|
96
|
+
|
|
97
|
+
export function App() {
|
|
98
|
+
return (
|
|
99
|
+
<OnboardingAIProvider client={client}>
|
|
100
|
+
{/* your app */}
|
|
101
|
+
</OnboardingAIProvider>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### React Chat Hook
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
import { useChat } from "@fluxyte/sdk/react";
|
|
110
|
+
|
|
111
|
+
const { send, data, loading, error } = useChat();
|
|
112
|
+
|
|
113
|
+
await send({
|
|
114
|
+
message: "How do I connect my database?",
|
|
115
|
+
sessionId: "sess_123",
|
|
116
|
+
context: { product: "analytics", userTarget: "admin" },
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Node Entry
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
import { OnboardingAIClient } from "@fluxyte/sdk/node";
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Browser Entry
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import { OnboardingAIClient } from "@fluxyte/sdk/vanilla";
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Error Handling
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
import { APIError } from "@fluxyte/sdk";
|
|
136
|
+
|
|
137
|
+
try {
|
|
138
|
+
await client.chat(/* ... */);
|
|
139
|
+
} catch (err) {
|
|
140
|
+
if (err instanceof APIError) {
|
|
141
|
+
console.error(err.status, err.message);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## License
|
|
147
|
+
|
|
148
|
+
Commercial. See `LICENSE.md`.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { components } from "../generated/openapi";
|
|
2
|
+
import type { ChatSSEEvent } from "./sse.js";
|
|
3
|
+
type ChatCompletionRequest = components["schemas"]["ChatCompletionRequest"];
|
|
4
|
+
type ChatCompletionResponse = components["schemas"]["ChatCompletionResponse"];
|
|
5
|
+
type FeedbackRequest = components["schemas"]["FeedbackRequest"];
|
|
6
|
+
type OnboardingEventRequest = components["schemas"]["OnboardingEventRequest"];
|
|
7
|
+
export declare class OnboardingAIClient {
|
|
8
|
+
private readonly apiKey;
|
|
9
|
+
private readonly baseUrl;
|
|
10
|
+
constructor(apiKey: string);
|
|
11
|
+
chat(payload: ChatCompletionRequest): Promise<ChatCompletionResponse>;
|
|
12
|
+
streamChat(payload: Omit<ChatCompletionRequest, "stream">, onEvent: (event: ChatSSEEvent) => void): () => void;
|
|
13
|
+
sendEvent(payload: OnboardingEventRequest): Promise<void>;
|
|
14
|
+
submitFeedback(payload: FeedbackRequest): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/core/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,KAAK,qBAAqB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,uBAAuB,CAAC,CAAC;AAC5E,KAAK,sBAAsB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,wBAAwB,CAAC,CAAC;AAC9E,KAAK,eAAe,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,iBAAiB,CAAC,CAAC;AAChE,KAAK,sBAAsB,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,wBAAwB,CAAC,CAAC;AAI9E,qBAAa,kBAAkB;IAGjB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;gBAEf,MAAM,EAAE,MAAM;IAErC,IAAI,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAc3E,UAAU,CACR,OAAO,EAAE,IAAI,CAAC,qBAAqB,EAAE,QAAQ,CAAC,EAC9C,OAAO,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GACrC,MAAM,IAAI;IASP,SAAS,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAazD,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAY9D"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { handleResponse } from "./utils.js";
|
|
2
|
+
import { streamSSE } from "./sse.js";
|
|
3
|
+
const DEFAULT_BASE_URL = "https://api.fluxyte.com/v1";
|
|
4
|
+
export class OnboardingAIClient {
|
|
5
|
+
constructor(apiKey) {
|
|
6
|
+
this.apiKey = apiKey;
|
|
7
|
+
this.baseUrl = DEFAULT_BASE_URL;
|
|
8
|
+
}
|
|
9
|
+
async chat(payload) {
|
|
10
|
+
const res = await fetch(`${this.baseUrl}/chat/completions`, {
|
|
11
|
+
method: "POST",
|
|
12
|
+
headers: {
|
|
13
|
+
"Content-Type": "application/json",
|
|
14
|
+
"X-API-Key": this.apiKey,
|
|
15
|
+
},
|
|
16
|
+
body: JSON.stringify({ ...payload, stream: false }),
|
|
17
|
+
});
|
|
18
|
+
await handleResponse(res);
|
|
19
|
+
return res.json();
|
|
20
|
+
}
|
|
21
|
+
streamChat(payload, onEvent) {
|
|
22
|
+
return streamSSE(`${this.baseUrl}/chat/completions`, this.apiKey, { ...payload, stream: true }, onEvent);
|
|
23
|
+
}
|
|
24
|
+
async sendEvent(payload) {
|
|
25
|
+
const res = await fetch(`${this.baseUrl}/events`, {
|
|
26
|
+
method: "POST",
|
|
27
|
+
headers: {
|
|
28
|
+
"Content-Type": "application/json",
|
|
29
|
+
"X-API-Key": this.apiKey,
|
|
30
|
+
},
|
|
31
|
+
body: JSON.stringify(payload),
|
|
32
|
+
});
|
|
33
|
+
await handleResponse(res);
|
|
34
|
+
}
|
|
35
|
+
async submitFeedback(payload) {
|
|
36
|
+
const res = await fetch(`${this.baseUrl}/feedback`, {
|
|
37
|
+
method: "POST",
|
|
38
|
+
headers: {
|
|
39
|
+
"Content-Type": "application/json",
|
|
40
|
+
"X-API-Key": this.apiKey,
|
|
41
|
+
},
|
|
42
|
+
body: JSON.stringify(payload),
|
|
43
|
+
});
|
|
44
|
+
await handleResponse(res);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/core/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,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AK,CAAC,cAAc,CAAC,OAAwB;QAC3C,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,WAAW,EAAE;YAClD,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,WAAW,EAAE,IAAI,CAAC,MAAM;aACzB;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;SAC9B,CAAC,CAAC;QAEH,MAAM,cAAc,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare class APIError extends Error {
|
|
2
|
+
readonly status: number;
|
|
3
|
+
readonly payload?: unknown;
|
|
4
|
+
constructor(message: string, status: number, payload?: unknown);
|
|
5
|
+
}
|
|
6
|
+
export declare class UnauthorizedError extends APIError {
|
|
7
|
+
constructor(message?: string, payload?: unknown);
|
|
8
|
+
}
|
|
9
|
+
export declare class RateLimitError extends APIError {
|
|
10
|
+
constructor(message?: string, payload?: unknown);
|
|
11
|
+
}
|
|
12
|
+
export declare class ValidationError extends APIError {
|
|
13
|
+
constructor(message?: string, payload?: unknown);
|
|
14
|
+
}
|
|
15
|
+
export declare function apiErrorFromResponse(status: number, message: string, payload?: unknown): APIError;
|
|
16
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/core/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAS,SAAQ,KAAK;IACjC,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,OAAO,CAAC,EAAE,OAAO,CAAC;gBAEtB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;CAO/D;AAED,qBAAa,iBAAkB,SAAQ,QAAQ;gBACjC,OAAO,SAAiB,EAAE,OAAO,CAAC,EAAE,OAAO;CAGxD;AAED,qBAAa,cAAe,SAAQ,QAAQ;gBAC9B,OAAO,SAAsB,EAAE,OAAO,CAAC,EAAE,OAAO;CAG7D;AAED,qBAAa,eAAgB,SAAQ,QAAQ;gBAC/B,OAAO,SAAoB,EAAE,OAAO,CAAC,EAAE,OAAO;CAG3D;AAED,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,OAAO,GAChB,QAAQ,CAWV"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export class APIError extends Error {
|
|
2
|
+
constructor(message, status, payload) {
|
|
3
|
+
super(message);
|
|
4
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
5
|
+
this.name = new.target.name;
|
|
6
|
+
this.status = status;
|
|
7
|
+
this.payload = payload;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export class UnauthorizedError extends APIError {
|
|
11
|
+
constructor(message = "Unauthorized", payload) {
|
|
12
|
+
super(message, 401, payload);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class RateLimitError extends APIError {
|
|
16
|
+
constructor(message = "Too many requests", payload) {
|
|
17
|
+
super(message, 429, payload);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export class ValidationError extends APIError {
|
|
21
|
+
constructor(message = "Invalid request", payload) {
|
|
22
|
+
super(message, 400, payload);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function apiErrorFromResponse(status, message, payload) {
|
|
26
|
+
switch (status) {
|
|
27
|
+
case 400:
|
|
28
|
+
return new ValidationError(message, payload);
|
|
29
|
+
case 401:
|
|
30
|
+
return new UnauthorizedError(message, payload);
|
|
31
|
+
case 429:
|
|
32
|
+
return new RateLimitError(message, payload);
|
|
33
|
+
default:
|
|
34
|
+
return new APIError(message, status, payload);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 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AAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC9C;YACE,OAAO,IAAI,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { components } from "../generated/openapi";
|
|
2
|
+
type AdminAIIntent = components["schemas"]["AdminAIIntent"];
|
|
3
|
+
type EvidenceItem = components["schemas"]["EvidenceItem"];
|
|
4
|
+
export type ChatSSEEvent = {
|
|
5
|
+
type: "meta";
|
|
6
|
+
answerId: string;
|
|
7
|
+
} | {
|
|
8
|
+
type: "delta";
|
|
9
|
+
replyDelta: string;
|
|
10
|
+
} | {
|
|
11
|
+
type: "done";
|
|
12
|
+
confidence?: number | null;
|
|
13
|
+
kind?: AdminAIIntent;
|
|
14
|
+
sources?: EvidenceItem[];
|
|
15
|
+
};
|
|
16
|
+
export declare function streamSSE(url: string, apiKey: string, body: unknown, onEvent: (event: ChatSSEEvent) => void): () => void;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=sse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../../src/core/sse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,KAAK,aAAa,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,eAAe,CAAC,CAAC;AAC5D,KAAK,YAAY,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC,CAAC;AAE1D,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAClC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACrC;IACE,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;CAC1B,CAAC;AAEN,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,GACrC,MAAM,IAAI,CAmDZ"}
|
package/dist/core/sse.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export function streamSSE(url, apiKey, body, onEvent) {
|
|
2
|
+
const controller = new AbortController();
|
|
3
|
+
fetch(url, {
|
|
4
|
+
method: "POST",
|
|
5
|
+
headers: {
|
|
6
|
+
"Content-Type": "application/json",
|
|
7
|
+
"X-API-Key": apiKey,
|
|
8
|
+
},
|
|
9
|
+
body: JSON.stringify(body),
|
|
10
|
+
signal: controller.signal,
|
|
11
|
+
}).then(async (res) => {
|
|
12
|
+
if (!res.ok || !res.body) {
|
|
13
|
+
throw new Error(`SSE connection failed (${res.status})`);
|
|
14
|
+
}
|
|
15
|
+
const reader = res.body.getReader();
|
|
16
|
+
const decoder = new TextDecoder();
|
|
17
|
+
let buffer = "";
|
|
18
|
+
while (true) {
|
|
19
|
+
const { done, value } = await reader.read();
|
|
20
|
+
if (done)
|
|
21
|
+
break;
|
|
22
|
+
buffer += decoder.decode(value, { stream: true });
|
|
23
|
+
let idx;
|
|
24
|
+
while ((idx = buffer.indexOf("\n\n")) !== -1) {
|
|
25
|
+
const frame = buffer.slice(0, idx);
|
|
26
|
+
buffer = buffer.slice(idx + 2);
|
|
27
|
+
if (frame.startsWith("event: ping"))
|
|
28
|
+
continue;
|
|
29
|
+
const dataLines = frame
|
|
30
|
+
.split("\n")
|
|
31
|
+
.filter((l) => l.startsWith("data:"))
|
|
32
|
+
.map((l) => l.replace(/^data:\s*/, ""));
|
|
33
|
+
if (!dataLines.length)
|
|
34
|
+
continue;
|
|
35
|
+
const data = dataLines.join("\n");
|
|
36
|
+
if (data === "[DONE]")
|
|
37
|
+
return;
|
|
38
|
+
try {
|
|
39
|
+
onEvent(JSON.parse(data));
|
|
40
|
+
}
|
|
41
|
+
catch { }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return () => controller.abort();
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=sse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse.js","sourceRoot":"","sources":["../../src/core/sse.ts"],"names":[],"mappings":"AAeA,MAAM,UAAU,SAAS,CACvB,GAAW,EACX,MAAc,EACd,IAAa,EACb,OAAsC;IAEtC,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IAEzC,KAAK,CAAC,GAAG,EAAE;QACT,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,WAAW,EAAE,MAAM;SACpB;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;QAC1B,MAAM,EAAE,UAAU,CAAC,MAAM;KAC1B,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACpB,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,0BAA0B,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;QAC3D,CAAC;QAED,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;QACpC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;QAClC,IAAI,MAAM,GAAG,EAAE,CAAC;QAEhB,OAAO,IAAI,EAAE,CAAC;YACZ,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YAC5C,IAAI,IAAI;gBAAE,MAAM;YAEhB,MAAM,IAAI,OAAO,C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AAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBjE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { apiErrorFromResponse } from "./errors.js";
|
|
2
|
+
export async function handleResponse(res) {
|
|
3
|
+
if (res.ok)
|
|
4
|
+
return;
|
|
5
|
+
let payload;
|
|
6
|
+
try {
|
|
7
|
+
payload = await res.clone().json();
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
payload = undefined;
|
|
11
|
+
}
|
|
12
|
+
const message = payload && typeof payload === "object" && "error" in payload
|
|
13
|
+
? String(payload.error)
|
|
14
|
+
: res.statusText;
|
|
15
|
+
throw apiErrorFromResponse(res.status, message, payload);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/core/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,GAAa;IAChD,IAAI,GAAG,CAAC,EAAE;QAAE,OAAO;IAEnB,IAAI,OAAgB,CAAC;IACrB,IAAI,CAAC;QACH,OAAO,GAAG,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC;IACrC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,GAAG,SAAS,CAAC;IACtB,CAAC;IAED,MAAM,OAAO,GACX,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,IAAI,OAAO;QAC1D,CAAC,CAAC,MAAM,CAAE,OAAe,CAAC,KAAK,CAAC;QAChC,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC;IAErB,MAAM,oBAAoB,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was auto-generated by openapi-typescript.
|
|
3
|
+
* Do not make direct changes to the file.
|
|
4
|
+
*/
|
|
5
|
+
export interface paths {
|
|
6
|
+
"/chat/completions": {
|
|
7
|
+
post: operations["createChatCompletion"];
|
|
8
|
+
};
|
|
9
|
+
"/events": {
|
|
10
|
+
post: operations["trackOnboardingEvent"];
|
|
11
|
+
};
|
|
12
|
+
"/feedback": {
|
|
13
|
+
post: operations["submitFeedback"];
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export type webhooks = Record<string, never>;
|
|
17
|
+
export interface components {
|
|
18
|
+
schemas: {
|
|
19
|
+
Error: {
|
|
20
|
+
error: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* @default text
|
|
24
|
+
* @enum {string}
|
|
25
|
+
*/
|
|
26
|
+
ResponseFormat: "text" | "markdown" | "html" | "json";
|
|
27
|
+
/** @enum {string} */
|
|
28
|
+
TrustLevel: "LOW" | "MEDIUM" | "HIGH" | "VERIFIED";
|
|
29
|
+
/** @enum {string} */
|
|
30
|
+
AdminAIIntent: "GENERIC" | "NARRATIVE" | "DECISION" | "REFERENCE" | "MIXED" | "CLARIFICATION";
|
|
31
|
+
/**
|
|
32
|
+
* @description Context that grounds the AI response.
|
|
33
|
+
*
|
|
34
|
+
* `product` represents the onboarding target, which may be:
|
|
35
|
+
* - an application
|
|
36
|
+
* - a feature
|
|
37
|
+
* - an API
|
|
38
|
+
* - a service
|
|
39
|
+
*/
|
|
40
|
+
OnboardingContext: {
|
|
41
|
+
/**
|
|
42
|
+
* @description Onboarding target identifier.
|
|
43
|
+
* Examples:
|
|
44
|
+
* - analytics-app
|
|
45
|
+
* - alerts-feature
|
|
46
|
+
* - payments-api
|
|
47
|
+
*/
|
|
48
|
+
product: string;
|
|
49
|
+
/**
|
|
50
|
+
* @description Target user role or persona for the onboarding flow.
|
|
51
|
+
* Examples:
|
|
52
|
+
* - developer
|
|
53
|
+
* - admin
|
|
54
|
+
* - marketer
|
|
55
|
+
*/
|
|
56
|
+
userTarget: string;
|
|
57
|
+
/** @description Human-readable onboarding flow identifier */
|
|
58
|
+
flowSlug?: string;
|
|
59
|
+
/** @description Human-readable onboarding step identifier */
|
|
60
|
+
stepSlug?: string;
|
|
61
|
+
endpoint?: string;
|
|
62
|
+
/** Format: uri */
|
|
63
|
+
pageUrl?: string;
|
|
64
|
+
errorCode?: string;
|
|
65
|
+
version?: string;
|
|
66
|
+
sdk?: string;
|
|
67
|
+
language?: string;
|
|
68
|
+
userId?: string;
|
|
69
|
+
[key: string]: unknown;
|
|
70
|
+
};
|
|
71
|
+
ChatCompletionRequest: {
|
|
72
|
+
message: string;
|
|
73
|
+
/** @description Optional session identifier for conversational context */
|
|
74
|
+
sessionId?: string;
|
|
75
|
+
context: components["schemas"]["OnboardingContext"];
|
|
76
|
+
/** @default false */
|
|
77
|
+
stream?: boolean;
|
|
78
|
+
format?: components["schemas"]["ResponseFormat"];
|
|
79
|
+
};
|
|
80
|
+
EvidenceItem: {
|
|
81
|
+
sourceId: string;
|
|
82
|
+
excerpt: string;
|
|
83
|
+
trustLevel: components["schemas"]["TrustLevel"];
|
|
84
|
+
};
|
|
85
|
+
ChatCompletionResponse: {
|
|
86
|
+
/** @description Persisted AI answer ID */
|
|
87
|
+
answerId: string;
|
|
88
|
+
/** @description Final AI response shown to the user */
|
|
89
|
+
reply: string;
|
|
90
|
+
format: components["schemas"]["ResponseFormat"];
|
|
91
|
+
kind?: components["schemas"]["AdminAIIntent"];
|
|
92
|
+
confidence?: number | null;
|
|
93
|
+
sources?: components["schemas"]["EvidenceItem"][];
|
|
94
|
+
};
|
|
95
|
+
ChatStreamMeta: {
|
|
96
|
+
/** @enum {string} */
|
|
97
|
+
type: "meta";
|
|
98
|
+
answerId: string;
|
|
99
|
+
};
|
|
100
|
+
ChatStreamDelta: {
|
|
101
|
+
/** @enum {string} */
|
|
102
|
+
type: "delta";
|
|
103
|
+
replyDelta: string;
|
|
104
|
+
};
|
|
105
|
+
ChatStreamDone: {
|
|
106
|
+
/** @enum {string} */
|
|
107
|
+
type: "done";
|
|
108
|
+
confidence?: number | null;
|
|
109
|
+
kind?: components["schemas"]["AdminAIIntent"];
|
|
110
|
+
sources?: components["schemas"]["EvidenceItem"][];
|
|
111
|
+
};
|
|
112
|
+
ChatStreamEvent: components["schemas"]["ChatStreamMeta"] | components["schemas"]["ChatStreamDelta"] | components["schemas"]["ChatStreamDone"];
|
|
113
|
+
/** @enum {string} */
|
|
114
|
+
OnboardingEventType: "FLOW_STARTED" | "STEP_VIEWED" | "STEP_COMPLETED" | "FLOW_COMPLETED" | "ABANDONED";
|
|
115
|
+
OnboardingEventRequest: {
|
|
116
|
+
type: components["schemas"]["OnboardingEventType"];
|
|
117
|
+
context: components["schemas"]["OnboardingContext"];
|
|
118
|
+
meta?: {
|
|
119
|
+
[key: string]: unknown;
|
|
120
|
+
} | null;
|
|
121
|
+
};
|
|
122
|
+
/** @enum {string} */
|
|
123
|
+
FeedbackRating: "VERY_BAD" | "BAD" | "OK" | "GOOD" | "EXCELLENT";
|
|
124
|
+
FeedbackRequest: {
|
|
125
|
+
answerId: string;
|
|
126
|
+
rating: components["schemas"]["FeedbackRating"];
|
|
127
|
+
comment?: string | null;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
responses: never;
|
|
131
|
+
parameters: never;
|
|
132
|
+
requestBodies: never;
|
|
133
|
+
headers: never;
|
|
134
|
+
pathItems: never;
|
|
135
|
+
}
|
|
136
|
+
export type $defs = Record<string, never>;
|
|
137
|
+
export type external = Record<string, never>;
|
|
138
|
+
export interface operations {
|
|
139
|
+
createChatCompletion: {
|
|
140
|
+
requestBody: {
|
|
141
|
+
content: {
|
|
142
|
+
"application/json": components["schemas"]["ChatCompletionRequest"];
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
responses: {
|
|
146
|
+
/** @description OK */
|
|
147
|
+
200: {
|
|
148
|
+
content: {
|
|
149
|
+
"application/json": components["schemas"]["ChatCompletionResponse"];
|
|
150
|
+
"text/event-stream": string;
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
trackOnboardingEvent: {
|
|
156
|
+
requestBody: {
|
|
157
|
+
content: {
|
|
158
|
+
"application/json": components["schemas"]["OnboardingEventRequest"];
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
responses: {
|
|
162
|
+
/** @description No Content */
|
|
163
|
+
204: {
|
|
164
|
+
content: never;
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
submitFeedback: {
|
|
169
|
+
requestBody: {
|
|
170
|
+
content: {
|
|
171
|
+
"application/json": components["schemas"]["FeedbackRequest"];
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
responses: {
|
|
175
|
+
/** @description OK */
|
|
176
|
+
200: {
|
|
177
|
+
content: never;
|
|
178
|
+
};
|
|
179
|
+
/** @description Conflict */
|
|
180
|
+
409: {
|
|
181
|
+
content: never;
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=openapi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi.d.ts","sourceRoot":"","sources":["../../src/generated/openapi.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,MAAM,WAAW,KAAK;IACpB,mBAAmB,EAAE;QACnB,IAAI,EAAE,UAAU,CAAC,sBAAsB,CAAC,CAAC;KAC1C,CAAC;IACF,SAAS,EAAE;QACT,IAAI,EAAE,UAAU,CAAC,sBAAsB,CAAC,CAAC;KAC1C,CAAC;IACF,WAAW,EAAE;QACX,IAAI,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAC;KACpC,CAAC;CACH;AAED,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAE7C,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE;Q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,CAAC;SACH,CAAC;KACH,CAAC;IACF,oBAAoB,EAAE;QACpB,WAAW,EAAE;YACX,OAAO,EAAE;gBACP,kBAAkB,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC,wBAAwB,CAAC,CAAC;aACrE,CAAC;SACH,CAAC;QACF,SAAS,EAAE;YACT,8BAA8B;YAC9B,GAAG,EAAE;gBACH,OAAO,EAAE,KAAK,CAAC;aAChB,CAAC;SACH,CAAC;KACH,CAAC;IACF,cAAc,EAAE;QACd,WAAW,EAAE;YACX,OAAO,EAAE;gBACP,kBAAkB,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC,iBAAiB,CAAC,CAAC;aAC9D,CAAC;SACH,CAAC;QACF,SAAS,EAAE;YACT,sBAAsB;YACtB,GAAG,EAAE;gBACH,OAAO,EAAE,KAAK,CAAC;aAChB,CAAC;YACF,4BAA4B;YAC5B,GAAG,EAAE;gBACH,OAAO,EAAE,KAAK,CAAC;aAChB,CAAC;SACH,CAAC;KACH,CAAC;CACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openapi.js","sourceRoot":"","sources":["../../src/generated/openapi.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { OnboardingAIClient } from "./core/client.js";
|
|
2
|
+
export { APIError, RateLimitError, UnauthorizedError, ValidationError, } from "./core/errors.js";
|
|
3
|
+
export * from "./vanilla/index.js";
|
|
4
|
+
export * from "./react/index.js";
|
|
5
|
+
export * from "./node/index.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EACL,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAE1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
export { OnboardingAIClient } from "./core/client.js";
|
|
3
|
+
export { APIError, RateLimitError, UnauthorizedError, ValidationError, } from "./core/errors.js";
|
|
4
|
+
export * from "./vanilla/index.js";
|
|
5
|
+
export * from "./react/index.js";
|
|
6
|
+
export * from "./node/index.js";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAe;AAEf,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EACL,QAAQ,EACR,cAAc,EACd,iBAAiB,EACjB,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAE1B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAgBvD,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAM9B,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAMvD,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/node/index.ts
|
|
2
|
+
import { OnboardingAIClient } from "../core/client.js";
|
|
3
|
+
/*
|
|
4
|
+
Node.js environment guard.
|
|
5
|
+
|
|
6
|
+
- Node 18+ has global fetch
|
|
7
|
+
- Node <18 requires a fetch polyfill (undici or node-fetch)
|
|
8
|
+
*/
|
|
9
|
+
if (typeof fetch === "undefined") {
|
|
10
|
+
throw new Error("Global fetch is not available. " +
|
|
11
|
+
"For Node <18, install a fetch polyfill (e.g. undici) and set globalThis.fetch.");
|
|
12
|
+
}
|
|
13
|
+
export { OnboardingAIClient };
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,oBAAoB;AAEpB,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD;;;;;EAKE;AAEF,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE,CAAC;IACjC,MAAM,IAAI,KAAK,CACb,iCAAiC;QAC/B,gFAAgF,CACnF,CAAC;AACJ,CAAC;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { OnboardingAIClient } from "../core/client.js";
|
|
2
|
+
export declare function OnboardingAIProvider({ client, children, }: {
|
|
3
|
+
client: OnboardingAIClient;
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export declare function useOnboardingAIClient(): OnboardingAIClient;
|
|
7
|
+
//# sourceMappingURL=OnboardingAIProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OnboardingAIProvider.d.ts","sourceRoot":"","sources":["../../src/react/OnboardingAIProvider.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAIvD,wBAAgB,oBAAoB,CAAC,EACnC,MAAM,EACN,QAAQ,GACT,EAAE;IACD,MAAM,EAAE,kBAAkB,CAAC;IAC3B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,2CAEA;AAED,wBAAgB,qBAAqB,uBAIpC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { createContext, useContext } from "react";
|
|
4
|
+
import { OnboardingAIClient } from "../core/client.js";
|
|
5
|
+
const Ctx = createContext(null);
|
|
6
|
+
export function OnboardingAIProvider({ client, children, }) {
|
|
7
|
+
return _jsx(Ctx.Provider, { value: client, children: children });
|
|
8
|
+
}
|
|
9
|
+
export function useOnboardingAIClient() {
|
|
10
|
+
const ctx = useContext(Ctx);
|
|
11
|
+
if (!ctx)
|
|
12
|
+
throw new Error("OnboardingAIProvider missing");
|
|
13
|
+
return ctx;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=OnboardingAIProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OnboardingAIProvider.js","sourceRoot":"","sources":["../../src/react/OnboardingAIProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,MAAM,GAAG,GAAG,aAAa,CAA4B,IAAI,CAAC,CAAC;AAE3D,MAAM,UAAU,oBAAoB,CAAC,EACnC,MAAM,EACN,QAAQ,GAIT;IACC,OAAO,KAAC,GAAG,CAAC,QAAQ,IAAC,KAAK,EAAE,MAAM,YAAG,QAAQ,GAAgB,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,qBAAqB;IACnC,MAAM,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;IAC5B,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAC1D,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { OnboardingAIProvider } from "./OnboardingAIProvider.js";
|
|
2
|
+
export { useOnboardingAIClient } from "./OnboardingAIProvider.js";
|
|
3
|
+
export { useChat } from "./useChat.js";
|
|
4
|
+
export { useStreamingChat } from "./useStreamingChat.js";
|
|
5
|
+
export { useFeedback } from "./useFeedback.js";
|
|
6
|
+
export { useOnboardingEvents } from "./useOnboardingEvents.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// react/index.ts
|
|
2
|
+
export { OnboardingAIProvider } from "./OnboardingAIProvider.js";
|
|
3
|
+
export { useOnboardingAIClient } from "./OnboardingAIProvider.js";
|
|
4
|
+
export { useChat } from "./useChat.js";
|
|
5
|
+
export { useStreamingChat } from "./useStreamingChat.js";
|
|
6
|
+
export { useFeedback } from "./useFeedback.js";
|
|
7
|
+
export { useOnboardingEvents } from "./useOnboardingEvents.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,iBAAiB;AACjB,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { components } from "../generated/openapi";
|
|
2
|
+
type ChatRequest = Omit<components["schemas"]["ChatCompletionRequest"], "stream">;
|
|
3
|
+
export declare function useChat(): {
|
|
4
|
+
send: (payload: ChatRequest) => Promise<{
|
|
5
|
+
answerId: string;
|
|
6
|
+
reply: string;
|
|
7
|
+
format: components["schemas"]["ResponseFormat"];
|
|
8
|
+
kind?: components["schemas"]["AdminAIIntent"];
|
|
9
|
+
confidence?: number | null;
|
|
10
|
+
sources?: components["schemas"]["EvidenceItem"][];
|
|
11
|
+
}>;
|
|
12
|
+
data: {
|
|
13
|
+
answerId: string;
|
|
14
|
+
reply: string;
|
|
15
|
+
format: components["schemas"]["ResponseFormat"];
|
|
16
|
+
kind?: components["schemas"]["AdminAIIntent"];
|
|
17
|
+
confidence?: number | null;
|
|
18
|
+
sources?: components["schemas"]["EvidenceItem"][];
|
|
19
|
+
} | null;
|
|
20
|
+
loading: boolean;
|
|
21
|
+
error: Error | null;
|
|
22
|
+
};
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=useChat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChat.d.ts","sourceRoot":"","sources":["../../src/react/useChat.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGvD,KAAK,WAAW,GAAG,IAAI,CACrB,UAAU,CAAC,SAAS,CAAC,CAAC,uBAAuB,CAAC,EAC9C,QAAQ,CACT,CAAC;AAGF,wBAAgB,OAAO;oBAOH,WAAW;;;gBAmB08C,qBAAsB;eAAgC,qBAAsB;;kBAAoE,qBAAsB;;;;;gBAAtK,qBAAsB;eAAgC,qBAAsB;;kBAAoE,qBAAsB;;;;EAD9oD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useState } from "react";
|
|
3
|
+
import { useOnboardingAIClient } from "./OnboardingAIProvider.js";
|
|
4
|
+
export function useChat() {
|
|
5
|
+
const client = useOnboardingAIClient();
|
|
6
|
+
const [data, setData] = useState(null);
|
|
7
|
+
const [loading, setLoading] = useState(false);
|
|
8
|
+
const [error, setError] = useState(null);
|
|
9
|
+
const send = useCallback(async (payload) => {
|
|
10
|
+
setLoading(true);
|
|
11
|
+
setError(null);
|
|
12
|
+
try {
|
|
13
|
+
const res = await client.chat(payload);
|
|
14
|
+
setData(res);
|
|
15
|
+
return res;
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
setError(err);
|
|
19
|
+
throw err;
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
setLoading(false);
|
|
23
|
+
}
|
|
24
|
+
}, [client]);
|
|
25
|
+
return { send, data, loading, error };
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=useChat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChat.js","sourceRoot":"","sources":["../../src/react/useChat.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAQlE,MAAM,UAAU,OAAO;IACrB,MAAM,MAAM,GAAG,qBAAqB,EAAE,CAAC;IACvC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAsB,IAAI,CAAC,CAAC;IAC5D,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAe,IAAI,CAAC,CAAC;IAEvD,MAAM,IAAI,GAAG,WAAW,CACtB,KAAK,EAAE,OAAoB,EAAE,EAAE;QAC7B,UAAU,CAAC,IAAI,CAAC,CAAC;QACjB,QAAQ,CAAC,IAAI,CAAC,CAAC;QACf,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACvC,OAAO,CAAC,GAAG,CAAC,CAAC;YACb,OAAO,GAAG,CAAC;QACb,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,QAAQ,CAAC,GAAY,CAAC,CAAC;YACvB,MAAM,GAAG,CAAC;QACZ,CAAC;gBAAS,CAAC;YACT,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC,EACD,CAAC,MAAM,CAAC,CACT,CAAC;IAEF,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { components } from "../generated/openapi";
|
|
2
|
+
import type { APIError } from "../core/errors";
|
|
3
|
+
type FeedbackRequest = components["schemas"]["FeedbackRequest"];
|
|
4
|
+
export declare function useFeedback(): {
|
|
5
|
+
submit: (payload: FeedbackRequest) => Promise<void>;
|
|
6
|
+
loading: boolean;
|
|
7
|
+
error: APIError | null;
|
|
8
|
+
};
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=useFeedback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFeedback.d.ts","sourceRoot":"","sources":["../../src/react/useFeedback.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAO/C,KAAK,eAAe,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,iBAAiB,CAAC,CAAC;AAMhE,wBAAgB,WAAW;sBAOP,eAAe,KAAG,OAAO,CAAC,IAAI,CAAC;;;EAqBlD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useState } from "react";
|
|
3
|
+
import { useOnboardingAIClient } from "./OnboardingAIProvider.js";
|
|
4
|
+
/* =========================
|
|
5
|
+
Hook
|
|
6
|
+
========================= */
|
|
7
|
+
export function useFeedback() {
|
|
8
|
+
const client = useOnboardingAIClient();
|
|
9
|
+
const [loading, setLoading] = useState(false);
|
|
10
|
+
const [error, setError] = useState(null);
|
|
11
|
+
const submit = useCallback(async (payload) => {
|
|
12
|
+
setLoading(true);
|
|
13
|
+
setError(null);
|
|
14
|
+
try {
|
|
15
|
+
await client.submitFeedback(payload);
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
setError(err);
|
|
19
|
+
throw err;
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
setLoading(false);
|
|
23
|
+
}
|
|
24
|
+
}, [client]);
|
|
25
|
+
return {
|
|
26
|
+
submit,
|
|
27
|
+
loading,
|
|
28
|
+
error,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=useFeedback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFeedback.js","sourceRoot":"","sources":["../../src/react/useFeedback.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAG9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAQlE;;4BAE4B;AAE5B,MAAM,UAAU,WAAW;IACzB,MAAM,MAAM,GAAG,qBAAqB,EAAE,CAAC;IAEvC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAkB,IAAI,CAAC,CAAC;IAE1D,MAAM,MAAM,GAAG,WAAW,CACxB,KAAK,EAAE,OAAwB,EAAiB,EAAE;QAChD,UAAU,CAAC,IAAI,CAAC,CAAC;QACjB,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEf,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;QACvC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,QAAQ,CAAC,GAAe,CAAC,CAAC;YAC1B,MAAM,GAAG,CAAC;QACZ,CAAC;gBAAS,CAAC;YACT,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC,EACD,CAAC,MAAM,CAAC,CACT,CAAC;IAEF,OAAO;QACL,MAAM;QACN,OAAO;QACP,KAAK;KACN,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { components } from "../generated/openapi";
|
|
2
|
+
type EventRequest = components["schemas"]["OnboardingEventRequest"];
|
|
3
|
+
export declare function useOnboardingEvents(): {
|
|
4
|
+
track: (payload: EventRequest) => Promise<void>;
|
|
5
|
+
loading: boolean;
|
|
6
|
+
error: Error | null;
|
|
7
|
+
};
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=useOnboardingEvents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOnboardingEvents.d.ts","sourceRoot":"","sources":["../../src/react/useOnboardingEvents.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGvD,KAAK,YAAY,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,wBAAwB,CAAC,CAAC;AAEpE,wBAAgB,mBAAmB;qBAMf,YAAY;;;EAgB/B"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useState } from "react";
|
|
3
|
+
import { useOnboardingAIClient } from "./OnboardingAIProvider.js";
|
|
4
|
+
export function useOnboardingEvents() {
|
|
5
|
+
const client = useOnboardingAIClient();
|
|
6
|
+
const [loading, setLoading] = useState(false);
|
|
7
|
+
const [error, setError] = useState(null);
|
|
8
|
+
const track = useCallback(async (payload) => {
|
|
9
|
+
setLoading(true);
|
|
10
|
+
setError(null);
|
|
11
|
+
try {
|
|
12
|
+
await client.sendEvent(payload);
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
setError(err);
|
|
16
|
+
throw err;
|
|
17
|
+
}
|
|
18
|
+
finally {
|
|
19
|
+
setLoading(false);
|
|
20
|
+
}
|
|
21
|
+
}, [client]);
|
|
22
|
+
return { track, loading, error };
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=useOnboardingEvents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOnboardingEvents.js","sourceRoot":"","sources":["../../src/react/useOnboardingEvents.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAIlE,MAAM,UAAU,mBAAmB;IACjC,MAAM,MAAM,GAAG,qBAAqB,EAAE,CAAC;IACvC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAe,IAAI,CAAC,CAAC;IAEvD,MAAM,KAAK,GAAG,WAAW,CACvB,KAAK,EAAE,OAAqB,EAAE,EAAE;QAC9B,UAAU,CAAC,IAAI,CAAC,CAAC;QACjB,QAAQ,CAAC,IAAI,CAAC,CAAC;QACf,IAAI,CAAC;YACH,MAAM,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,QAAQ,CAAC,GAAY,CAAC,CAAC;YACvB,MAAM,GAAG,CAAC;QACZ,CAAC;gBAAS,CAAC;YACT,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC,EACD,CAAC,MAAM,CAAC,CACT,CAAC;IAEF,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { components } from "../generated/openapi";
|
|
2
|
+
type StreamingRequest = Omit<components["schemas"]["ChatCompletionRequest"], "stream">;
|
|
3
|
+
export declare function useStreamingChat(): {
|
|
4
|
+
text: string;
|
|
5
|
+
answerId: string | null;
|
|
6
|
+
confidence: number | null;
|
|
7
|
+
streaming: boolean;
|
|
8
|
+
start: (payload: StreamingRequest) => void;
|
|
9
|
+
stop: () => void;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=useStreamingChat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStreamingChat.d.ts","sourceRoot":"","sources":["../../src/react/useStreamingChat.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIvD,KAAK,gBAAgB,GAAG,IAAI,CAC1B,UAAU,CAAC,SAAS,CAAC,CAAC,uBAAuB,CAAC,EAC9C,QAAQ,CACT,CAAC;AAEF,wBAAgB,gBAAgB;;;;;qBASlB,gBAAgB;;EA0B7B"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useRef, useState } from "react";
|
|
3
|
+
import { useOnboardingAIClient } from "./OnboardingAIProvider.js";
|
|
4
|
+
export function useStreamingChat() {
|
|
5
|
+
const client = useOnboardingAIClient();
|
|
6
|
+
const [text, setText] = useState("");
|
|
7
|
+
const [answerId, setAnswerId] = useState(null);
|
|
8
|
+
const [confidence, setConfidence] = useState(null);
|
|
9
|
+
const [streaming, setStreaming] = useState(false);
|
|
10
|
+
const abortRef = useRef(null);
|
|
11
|
+
const start = useCallback((payload) => {
|
|
12
|
+
setText("");
|
|
13
|
+
setAnswerId(null);
|
|
14
|
+
setConfidence(null);
|
|
15
|
+
setStreaming(true);
|
|
16
|
+
abortRef.current = client.streamChat(payload, (event) => {
|
|
17
|
+
if (event.type === "meta")
|
|
18
|
+
setAnswerId(event.answerId);
|
|
19
|
+
if (event.type === "delta")
|
|
20
|
+
setText((prev) => prev + event.replyDelta);
|
|
21
|
+
if (event.type === "done") {
|
|
22
|
+
setConfidence(event.confidence ?? null);
|
|
23
|
+
setStreaming(false);
|
|
24
|
+
abortRef.current = null;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}, [client]);
|
|
28
|
+
const stop = useCallback(() => {
|
|
29
|
+
abortRef.current?.();
|
|
30
|
+
abortRef.current = null;
|
|
31
|
+
setStreaming(false);
|
|
32
|
+
}, []);
|
|
33
|
+
return { text, answerId, confidence, streaming, start, stop };
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=useStreamingChat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useStreamingChat.js","sourceRoot":"","sources":["../../src/react/useStreamingChat.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAOlE,MAAM,UAAU,gBAAgB;IAC9B,MAAM,MAAM,GAAG,qBAAqB,EAAE,CAAC;IACvC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IACrC,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC,CAAC;IAC9D,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAgB,IAAI,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AAK,EAAE,IAAI,EAAE,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vanilla/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAOvD,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAOvD,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/vanilla/index.ts"],"names":[],"mappings":"AAAA,uBAAuB;AAEvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluxyte/sdk",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "Official Fluxyte SDK (
|
|
5
|
-
"
|
|
6
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Official Fluxyte SDK (TypeScript) for the Fluxyte Onboarding AI API",
|
|
5
|
+
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
7
8
|
"files": [
|
|
8
|
-
"
|
|
9
|
-
"index.d.ts",
|
|
10
|
-
"README.md"
|
|
9
|
+
"dist"
|
|
11
10
|
],
|
|
12
|
-
"license": "MIT",
|
|
13
11
|
"publishConfig": {
|
|
14
12
|
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/fluxyte/ai-onboarding-sdk.git"
|
|
17
|
+
},
|
|
18
|
+
"main": "dist/index.js",
|
|
19
|
+
"types": "dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./react": {
|
|
26
|
+
"types": "./dist/react/index.d.ts",
|
|
27
|
+
"import": "./dist/react/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./vanilla": {
|
|
30
|
+
"types": "./dist/vanilla/index.d.ts",
|
|
31
|
+
"import": "./dist/vanilla/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./node": {
|
|
34
|
+
"types": "./dist/node/index.d.ts",
|
|
35
|
+
"import": "./dist/node/index.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"clean": "rimraf dist",
|
|
40
|
+
"gen:types": "openapi-typescript openapi/public.v1.yaml -o src/generated/openapi.ts",
|
|
41
|
+
"prebuild": "npm run gen:types",
|
|
42
|
+
"build": "npm run clean && tsc",
|
|
43
|
+
"test": "npm run build && node --test",
|
|
44
|
+
"changeset": "changeset",
|
|
45
|
+
"version-packages": "changeset version",
|
|
46
|
+
"release": "changeset publish"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"react": ">=17"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@changesets/cli": "^2.28.1",
|
|
53
|
+
"@types/react": "^19.2.7",
|
|
54
|
+
"openapi-typescript": "^6.7.4",
|
|
55
|
+
"rimraf": "^6.1.2",
|
|
56
|
+
"typescript": "^5.4.0"
|
|
15
57
|
}
|
|
16
58
|
}
|
package/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {}
|
package/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = {}
|