@jazzmine-ui/sdk 0.1.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/README.md +136 -0
- package/dist/client/JazzmineClient.d.ts +41 -0
- package/dist/client/JazzmineClient.d.ts.map +1 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/discovery/endpoints.d.ts +20 -0
- package/dist/discovery/endpoints.d.ts.map +1 -0
- package/dist/discovery/index.d.ts +2 -0
- package/dist/discovery/index.d.ts.map +1 -0
- package/dist/errors/JazzmineClientError.d.ts +11 -0
- package/dist/errors/JazzmineClientError.d.ts.map +1 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/http/abort.d.ts +3 -0
- package/dist/http/abort.d.ts.map +1 -0
- package/dist/http/index.d.ts +4 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/request.d.ts +24 -0
- package/dist/http/request.d.ts.map +1 -0
- package/dist/http/retry.d.ts +10 -0
- package/dist/http/retry.d.ts.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +486 -0
- package/dist/stream/index.d.ts +2 -0
- package/dist/stream/index.d.ts.map +1 -0
- package/dist/stream/parser.d.ts +15 -0
- package/dist/stream/parser.d.ts.map +1 -0
- package/dist/types/chat.d.ts +22 -0
- package/dist/types/chat.d.ts.map +1 -0
- package/dist/types/conversation.d.ts +18 -0
- package/dist/types/conversation.d.ts.map +1 -0
- package/dist/types/health.d.ts +6 -0
- package/dist/types/health.d.ts.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/info.d.ts +11 -0
- package/dist/types/info.d.ts.map +1 -0
- package/dist/types/options.d.ts +15 -0
- package/dist/types/options.d.ts.map +1 -0
- package/dist/types/stream.d.ts +15 -0
- package/dist/types/stream.d.ts.map +1 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/url.d.ts +3 -0
- package/dist/utils/url.d.ts.map +1 -0
- package/dist/utils/validation.d.ts +5 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/package.json +42 -0
package/README.md
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# @jazzmine-ui/sdk
|
|
2
|
+
|
|
3
|
+
Framework-agnostic TypeScript client for Jazzmine agentic backends.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @jazzmine/client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### 1) Basic chat
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import JazzmineClient from "@jazzmine/client";
|
|
17
|
+
|
|
18
|
+
const client = new JazzmineClient("https://your-jazzmine-api.example.com", {
|
|
19
|
+
apiKey: "your-api-key",
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const reply = await client.chat({ message: "Summarize this dataset." });
|
|
23
|
+
console.log(reply.response);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### 2) Streaming chat
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import JazzmineClient from "@jazzmine/client";
|
|
30
|
+
|
|
31
|
+
const client = new JazzmineClient("https://your-jazzmine-api.example.com");
|
|
32
|
+
|
|
33
|
+
const final = await client.chatStream(
|
|
34
|
+
{ message: "Plan a 5-day trip to Tokyo." },
|
|
35
|
+
{
|
|
36
|
+
onIntermediate: (event) => {
|
|
37
|
+
console.log("intermediate", event);
|
|
38
|
+
},
|
|
39
|
+
onDone: (response) => {
|
|
40
|
+
console.log("done", response.response);
|
|
41
|
+
},
|
|
42
|
+
onErrorEvent: (event) => {
|
|
43
|
+
console.error("stream error event", event);
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
console.log(final.conversation_id);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 3) Convenience sendMessage flow
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import JazzmineClient from "@jazzmine/client";
|
|
55
|
+
|
|
56
|
+
const client = new JazzmineClient("https://your-jazzmine-api.example.com", {
|
|
57
|
+
defaultUserId: "alice",
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const { response, conversationId } = await client.sendMessage("Start a new thread", {
|
|
61
|
+
autoCreateConversation: true,
|
|
62
|
+
conversationTitle: "Project planning",
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
console.log(conversationId, response.response);
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Constructor
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
new JazzmineClient(baseEndpoint: string, options?: JazzmineClientOptions)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Constructor options
|
|
75
|
+
|
|
76
|
+
| Option | Type | Default | Description |
|
|
77
|
+
| --- | --- | --- | --- |
|
|
78
|
+
| `apiKey` | `string` | `undefined` | Bearer token added as `Authorization: Bearer <apiKey>`. |
|
|
79
|
+
| `timeoutMs` | `number` | `20000` | Request timeout in milliseconds. |
|
|
80
|
+
| `retries` | `number` | `2` | Default retry attempts for retryable requests. |
|
|
81
|
+
| `retryBackoffMs` | `number` | `350` | Linear backoff base in milliseconds. |
|
|
82
|
+
| `autoDiscoverEndpoints` | `boolean` | `true` | Auto-load endpoint routes from `/info` when available. |
|
|
83
|
+
| `defaultUserId` | `string` | `"user"` | Fallback `user_id` for requests. |
|
|
84
|
+
| `fetchImpl` | `typeof fetch` | runtime `fetch` | Custom fetch implementation for non-browser runtimes. |
|
|
85
|
+
|
|
86
|
+
## Public API
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
getHealth(requestOptions?: RequestOptions): Promise<HealthResponse>
|
|
90
|
+
getInfo(requestOptions?: RequestOptions): Promise<InfoResponse>
|
|
91
|
+
createConversation(payload?: ConversationCreateRequest, requestOptions?: RequestOptions): Promise<ConversationCreateResponse>
|
|
92
|
+
deleteConversation(conversationId: string, requestOptions?: RequestOptions): Promise<ConversationDeleteResponse>
|
|
93
|
+
chat(payload: ChatRequestPayload, requestOptions?: RequestOptions): Promise<ChatResponse>
|
|
94
|
+
chatStream(payload: ChatRequestPayload, handlers?: StreamHandlers, requestOptions?: RequestOptions): Promise<ChatResponse>
|
|
95
|
+
sendMessage(message: string, options?: {
|
|
96
|
+
conversationId?: string;
|
|
97
|
+
userId?: string;
|
|
98
|
+
explicitContext?: string[];
|
|
99
|
+
metadata?: Record<string, unknown>;
|
|
100
|
+
autoCreateConversation?: boolean;
|
|
101
|
+
conversationTitle?: string;
|
|
102
|
+
requestOptions?: RequestOptions;
|
|
103
|
+
}): Promise<{ response: ChatResponse; conversationId: string }>
|
|
104
|
+
resolveServerEndpoints(requestOptions?: RequestOptions): Promise<{
|
|
105
|
+
chat: string;
|
|
106
|
+
stream: string;
|
|
107
|
+
conversations: string;
|
|
108
|
+
health: string;
|
|
109
|
+
info: string;
|
|
110
|
+
}>
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Error Handling
|
|
114
|
+
|
|
115
|
+
Errors thrown by the client are instances of `JazzmineClientError`.
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
class JazzmineClientError extends Error {
|
|
119
|
+
status?: number;
|
|
120
|
+
code?: string;
|
|
121
|
+
details?: unknown;
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
- `status`: HTTP status code when available.
|
|
126
|
+
- `code`: Optional semantic code (for example stream error event codes).
|
|
127
|
+
- `details`: Parsed response payload or low-level details when available.
|
|
128
|
+
|
|
129
|
+
## Framework Compatibility
|
|
130
|
+
|
|
131
|
+
`@jazzmine/client` is framework-agnostic and can be used from React, Vue, Svelte, Next.js, and vanilla JavaScript/TypeScript apps.
|
|
132
|
+
|
|
133
|
+
## Node.js Note
|
|
134
|
+
|
|
135
|
+
- Node.js 18+ includes `fetch` globally and works out of the box.
|
|
136
|
+
- For Node.js versions below 18, provide a fetch implementation via `fetchImpl` (for example from `undici` or `cross-fetch`).
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { JazzmineEndpoints } from '../discovery';
|
|
2
|
+
import { ChatRequestPayload, ChatResponse, ConversationCreateRequest, ConversationCreateResponse, ConversationDeleteResponse, HealthResponse, InfoResponse, JazzmineClientOptions, RequestOptions, StreamHandlers } from '../types';
|
|
3
|
+
export declare class JazzmineClient {
|
|
4
|
+
private readonly baseUrl;
|
|
5
|
+
private readonly apiKey?;
|
|
6
|
+
private readonly timeoutMs;
|
|
7
|
+
private readonly retries;
|
|
8
|
+
private readonly retryBackoffMs;
|
|
9
|
+
private readonly autoDiscoverEndpoints;
|
|
10
|
+
private readonly defaultUserId;
|
|
11
|
+
private readonly fetchFn;
|
|
12
|
+
private endpoints;
|
|
13
|
+
private endpointsResolved;
|
|
14
|
+
constructor(baseEndpoint: string, options?: JazzmineClientOptions);
|
|
15
|
+
getHealth(requestOptions?: RequestOptions): Promise<HealthResponse>;
|
|
16
|
+
getInfo(requestOptions?: RequestOptions): Promise<InfoResponse>;
|
|
17
|
+
createConversation(payload?: ConversationCreateRequest, requestOptions?: RequestOptions): Promise<ConversationCreateResponse>;
|
|
18
|
+
deleteConversation(conversationId: string, requestOptions?: RequestOptions): Promise<ConversationDeleteResponse>;
|
|
19
|
+
chat(payload: ChatRequestPayload, requestOptions?: RequestOptions): Promise<ChatResponse>;
|
|
20
|
+
chatStream(payload: ChatRequestPayload, handlers?: StreamHandlers, requestOptions?: RequestOptions): Promise<ChatResponse>;
|
|
21
|
+
sendMessage(message: string, options?: {
|
|
22
|
+
conversationId?: string;
|
|
23
|
+
userId?: string;
|
|
24
|
+
explicitContext?: string[];
|
|
25
|
+
metadata?: Record<string, unknown>;
|
|
26
|
+
autoCreateConversation?: boolean;
|
|
27
|
+
conversationTitle?: string;
|
|
28
|
+
requestOptions?: RequestOptions;
|
|
29
|
+
}): Promise<{
|
|
30
|
+
response: ChatResponse;
|
|
31
|
+
conversationId: string;
|
|
32
|
+
}>;
|
|
33
|
+
resolveServerEndpoints(requestOptions?: RequestOptions): Promise<JazzmineEndpoints>;
|
|
34
|
+
private ensureEndpoints;
|
|
35
|
+
private requestJson;
|
|
36
|
+
private expectChatResponse;
|
|
37
|
+
private toStreamError;
|
|
38
|
+
private errorMessage;
|
|
39
|
+
}
|
|
40
|
+
export default JazzmineClient;
|
|
41
|
+
//# sourceMappingURL=JazzmineClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JazzmineClient.d.ts","sourceRoot":"","sources":["../../src/client/JazzmineClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,iBAAiB,EACvB,MAAM,cAAc,CAAC;AAYtB,OAAO,KAAK,EACV,kBAAkB,EAClB,YAAY,EACZ,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,EAC1B,cAAc,EACd,YAAY,EACZ,qBAAqB,EACrB,cAAc,EAEd,cAAc,EACf,MAAM,UAAU,CAAC;AAYlB,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAU;IAChD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;IAEvC,OAAO,CAAC,SAAS,CAAoB;IACrC,OAAO,CAAC,iBAAiB,CAAS;gBAEtB,YAAY,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B;IA6B/D,SAAS,CAAC,cAAc,GAAE,cAAmB,GAAG,OAAO,CAAC,cAAc,CAAC;IAYvE,OAAO,CAAC,cAAc,GAAE,cAAmB,GAAG,OAAO,CAAC,YAAY,CAAC;IAYnE,kBAAkB,CACtB,OAAO,GAAE,yBAA8B,EACvC,cAAc,GAAE,cAAmB,GAClC,OAAO,CAAC,0BAA0B,CAAC;IAiBhC,kBAAkB,CACtB,cAAc,EAAE,MAAM,EACtB,cAAc,GAAE,cAAmB,GAClC,OAAO,CAAC,0BAA0B,CAAC;IAiBhC,IAAI,CACR,OAAO,EAAE,kBAAkB,EAC3B,cAAc,GAAE,cAAmB,GAClC,OAAO,CAAC,YAAY,CAAC;IAqBlB,UAAU,CACd,OAAO,EAAE,kBAAkB,EAC3B,QAAQ,GAAE,cAAmB,EAC7B,cAAc,GAAE,cAAmB,GAClC,OAAO,CAAC,YAAY,CAAC;IA0DlB,WAAW,CACf,OAAO,EAAE,MAAM,EACf,OAAO,GAAE;QACP,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;QAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACnC,sBAAsB,CAAC,EAAE,OAAO,CAAC;QACjC,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,cAAc,CAAC,EAAE,cAAc,CAAC;KAC5B,GACL,OAAO,CAAC;QAAE,QAAQ,EAAE,YAAY,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,CAAC;IA0BxD,sBAAsB,CAAC,cAAc,GAAE,cAAmB,GAAG,OAAO,CAAC,iBAAiB,CAAC;YAmB/E,eAAe;IAS7B,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,kBAAkB;IAe1B,OAAO,CAAC,aAAa;IAYrB,OAAO,CAAC,YAAY;CAMrB;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { InfoResponse, RequestOptions } from '../types';
|
|
2
|
+
export interface JazzmineEndpoints {
|
|
3
|
+
chat: string;
|
|
4
|
+
stream: string;
|
|
5
|
+
conversations: string;
|
|
6
|
+
health: string;
|
|
7
|
+
info: string;
|
|
8
|
+
}
|
|
9
|
+
interface EnsureEndpointsConfig {
|
|
10
|
+
endpointsResolved: boolean;
|
|
11
|
+
autoDiscoverEndpoints: boolean;
|
|
12
|
+
requestOptions: RequestOptions;
|
|
13
|
+
resolveServerEndpoints: (requestOptions: RequestOptions) => Promise<JazzmineEndpoints>;
|
|
14
|
+
}
|
|
15
|
+
export declare const DEFAULT_ENDPOINTS: JazzmineEndpoints;
|
|
16
|
+
export declare function ensureEndpoints(config: EnsureEndpointsConfig): Promise<boolean>;
|
|
17
|
+
export declare function extractEndpointsFromInfo(info: InfoResponse, baseUrl: string): Partial<JazzmineEndpoints>;
|
|
18
|
+
export declare function parseEndpointPath(value: unknown, expectedMethod: string, baseUrl: string): string | null;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=endpoints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoints.d.ts","sourceRoot":"","sources":["../../src/discovery/endpoints.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE7D,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,qBAAqB;IAC7B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,qBAAqB,EAAE,OAAO,CAAC;IAC/B,cAAc,EAAE,cAAc,CAAC;IAC/B,sBAAsB,EAAE,CAAC,cAAc,EAAE,cAAc,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACxF;AAED,eAAO,MAAM,iBAAiB,EAAE,iBAM/B,CAAC;AAEF,wBAAsB,eAAe,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,OAAO,CAAC,CAWrF;AAED,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,iBAAiB,CAAC,CAgC5B;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,OAAO,EACd,cAAc,EAAE,MAAM,EACtB,OAAO,EAAE,MAAM,GACd,MAAM,GAAG,IAAI,CAsBf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/discovery/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class JazzmineClientError extends Error {
|
|
2
|
+
status?: number;
|
|
3
|
+
code?: string;
|
|
4
|
+
details?: unknown;
|
|
5
|
+
constructor(message: string, extras?: {
|
|
6
|
+
status?: number;
|
|
7
|
+
code?: string;
|
|
8
|
+
details?: unknown;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=JazzmineClientError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JazzmineClientError.d.ts","sourceRoot":"","sources":["../../src/errors/JazzmineClientError.ts"],"names":[],"mappings":"AAAA,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;gBAEN,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE;CAO5F"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abort.d.ts","sourceRoot":"","sources":["../../src/http/abort.ts"],"names":[],"mappings":"AAAA,wBAAgB,mBAAmB,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CA6B7F;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEpD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/http/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { JazzmineClientError } from '../errors';
|
|
2
|
+
export interface RequestConfig {
|
|
3
|
+
method: string;
|
|
4
|
+
path: string;
|
|
5
|
+
body?: unknown;
|
|
6
|
+
timeoutMs: number;
|
|
7
|
+
retries: number;
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
allowRetry: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface RequestContext {
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
apiKey?: string;
|
|
14
|
+
fetchFn: typeof fetch;
|
|
15
|
+
retryBackoffMs: number;
|
|
16
|
+
}
|
|
17
|
+
export declare function requestJson<T>(context: RequestContext, config: RequestConfig): Promise<T>;
|
|
18
|
+
export declare function toHttpError(response: Response, path: string): Promise<JazzmineClientError>;
|
|
19
|
+
export declare function buildHeaders(apiKey: string | undefined, options: {
|
|
20
|
+
accept?: string;
|
|
21
|
+
contentType?: string;
|
|
22
|
+
}): HeadersInit;
|
|
23
|
+
export declare function resolveUrl(baseUrl: string, path: string): string;
|
|
24
|
+
//# sourceMappingURL=request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/http/request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAKhD,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,KAAK,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;CACxB;AAuBD,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC,CAmF/F;AAED,wBAAsB,WAAW,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAkBhG;AAED,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GACjD,WAAW,CAYb;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface RetryLoopOptions<T> {
|
|
2
|
+
retries: number;
|
|
3
|
+
allowRetry: boolean;
|
|
4
|
+
retryBackoffMs: number;
|
|
5
|
+
runAttempt: (attempt: number) => Promise<T>;
|
|
6
|
+
shouldRetry: (error: unknown) => boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function delayWithBackoff(retryBackoffMs: number, attempt: number): Promise<void>;
|
|
9
|
+
export declare function runWithRetry<T>(options: RetryLoopOptions<T>): Promise<T>;
|
|
10
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/http/retry.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB,CAAC,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5C,WAAW,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;CAC1C;AAED,wBAAsB,gBAAgB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAM7F;AAED,wBAAsB,YAAY,CAAC,CAAC,EAAE,OAAO,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAmB9E"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const x={chat:"/chat",stream:"/chat/stream",conversations:"/conversations",health:"/health",info:"/info"};async function I(r){if(r.endpointsResolved||!r.autoDiscoverEndpoints)return r.endpointsResolved;try{return await r.resolveServerEndpoints(r.requestOptions),!0}catch{return!0}}function A(r,t){const e={},n=r==null?void 0:r.endpoints;if(!n||typeof n!="object")return e;const s=m(n.chat,"POST",t),i=m(n.stream,"POST",t),a=m(n.conversations_create,"POST",t),h=m(n.health,"GET",t),d=m(n.info,"GET",t);return s&&(e.chat=s),i?e.stream=i:s&&(e.stream=`${s.replace(/\/+$/,"")}/stream`),a&&(e.conversations=a),h&&(e.health=h),d&&(e.info=d),e}function m(r,t,e){if(typeof r!="string")return null;const n=r.match(/^([A-Z]+)\s+(.+)$/i);if(!n)return null;const s=n[1].toUpperCase(),i=n[2].trim();if(s!==t.toUpperCase())return null;try{const a=new URL(i,e);return`${a.pathname}${a.search}`}catch{return null}}class o extends Error{constructor(t,e){super(t),this.name="JazzmineClientError",this.status=e==null?void 0:e.status,this.code=e==null?void 0:e.code,this.details=e==null?void 0:e.details}}function b(r,t){if(!r&&!t)return;if(!r)return t;if(!t)return r;const e=AbortSignal.any;if(typeof e=="function")return e([r,t]);const n=new AbortController,s=()=>{n.abort()};return r.aborted||t.aborted?(n.abort(),n.signal):(r.addEventListener("abort",s,{once:!0}),t.addEventListener("abort",s,{once:!0}),n.signal)}function M(r){return r instanceof DOMException&&(r.name==="AbortError"||r.name==="TimeoutError")}function U(r){const t=r.trim().replace(/\/+$/,"");let e;try{e=new URL(t)}catch{throw new o("Invalid baseEndpoint. Provide a full URL like https://api.example.com or http://127.0.0.1:8010.")}if(!e.protocol.startsWith("http"))throw new o("baseEndpoint must use http or https.");return`${e.protocol}//${e.host}${e.pathname.replace(/\/+$/,"")}`}function k(r,t){const e=t.startsWith("/")?t:`/${t}`;return`${r}${e}`}function E(r){const t=r==null?void 0:r.message;if(typeof t!="string"||!t.trim())throw new o("chat payload requires a non-empty message string.");if(r.explicit_context&&!Array.isArray(r.explicit_context))throw new o("explicit_context must be an array of strings.");if(Array.isArray(r.explicit_context)&&r.explicit_context.some(n=>typeof n!="string"))throw new o("explicit_context must contain only strings.");if(r.metadata!==void 0&&(r.metadata===null||typeof r.metadata!="object"))throw new o("metadata must be an object when provided.")}function J(r,t,e){if(r===void 0)return t;if(!Number.isFinite(r)||r<=0)throw new o(`${e} must be a positive number.`);return Math.round(r)}function g(r,t,e,n,s){if(r===void 0)return t;if(!Number.isInteger(r)||r<n||r>s)throw new o(`${e} must be an integer between ${n} and ${s}.`);return r}async function N(r,t){const e=r*(t+1);e<=0||await new Promise(n=>setTimeout(n,e))}async function P(r){let t;for(let e=0;e<=r.retries;e+=1)try{return await r.runAttempt(e)}catch(n){if(t=n,r.allowRetry&&e<r.retries&&r.shouldRetry(n)){await N(r.retryBackoffMs,e);continue}throw n}throw t}class w extends Error{constructor(t){const e=`Request timed out after ${t} ms.`;super(e),this.name="RetryableTimeoutError",this.finalError=new o(e)}}class p extends Error{constructor(t){super(t),this.name="RetryableNetworkError",this.finalError=new o(t)}}async function z(r,t){try{return await P({retries:t.retries,allowRetry:t.allowRetry,retryBackoffMs:r.retryBackoffMs,runAttempt:async()=>{const e=new AbortController,n=setTimeout(()=>{e.abort()},t.timeoutMs),s=b(t.signal,e.signal);try{const i=await r.fetchFn(T(r.baseUrl,t.path),{method:t.method,headers:_(r.apiKey,{accept:"application/json",contentType:t.body!==void 0?"application/json":void 0}),body:t.body!==void 0?JSON.stringify(t.body):void 0,signal:s});if(!i.ok)throw await R(i,t.path);const a=await i.text();if(!a.trim())return{};try{return JSON.parse(a)}catch{throw new o(`Expected JSON response from ${t.path}, but received invalid JSON.`)}}catch(i){throw M(i)?new w(t.timeoutMs):i instanceof o?i:i instanceof TypeError?new p(y(i,"Network request failed.")):new o(y(i,"Network request failed."))}finally{clearTimeout(n)}},shouldRetry:e=>{if(e instanceof w||e instanceof p)return!0;if(e instanceof o){const n=e.status??0;return n===429||n>=500}return!1}})}catch(e){throw e instanceof w||e instanceof p?e.finalError:e instanceof o?e:new o(y(e,"Network request failed."))}}async function R(r,t){const e=await r.text();let n;if(e.trim())try{n=JSON.parse(e)}catch{n=e}const s=D(n),i=`HTTP ${r.status} on ${t}${s?`: ${s}`:""}`;return new o(i,{status:r.status,details:n})}function _(r,t){const e={};return t.accept&&(e.Accept=t.accept),t.contentType&&(e["Content-Type"]=t.contentType),r&&(e.Authorization=`Bearer ${r}`),e}function T(r,t){return k(r,t)}function D(r){if(!r)return"";if(typeof r=="string")return r.slice(0,300);if(typeof r=="object"){const t=r,e=t.detail,n=t.error;if(typeof e=="string")return e.slice(0,300);if(typeof n=="string")return n.slice(0,300)}return""}function y(r,t){return r instanceof Error&&r.message?r.message:t}function j(r){const t=r.split(/\r?\n/).map(i=>i.trimEnd()).filter(i=>i.length>0&&!i.startsWith(":"));if(t.length===0)return null;let e="message";const n=[];for(const i of t){if(i.startsWith("event:")){e=i.slice(6).trim()||"message";continue}i.startsWith("data:")&&n.push(i.slice(5).trim())}const s=n.join(`
|
|
2
|
+
`);if(!s)return{event:e,data:null};try{return{event:e,data:JSON.parse(s)}}catch{return{event:e,data:s}}}async function F(r){var a,h,d,c;const t=r.handlers??{},e=r.body.getReader(),n=new TextDecoder("utf-8");let s="",i=null;for(;;){const{done:l,value:C}=await e.read();if(l)break;s+=n.decode(C,{stream:!0});const v=s.split(/\n\n/);s=v.pop()??"";for(const $ of v){const u=j($);if(u){if((a=t.onRawEvent)==null||a.call(t,u.event,u.data),u.event==="intermediate"){(h=t.onIntermediate)==null||h.call(t,u.data);continue}if(u.event==="done"){i=r.expectChatResponse(u.data),(d=t.onDone)==null||d.call(t,i);continue}if(u.event==="error"){const f=r.toStreamError(u.data);throw(c=t.onErrorEvent)==null||c.call(t,f),new o(f.detail||f.error||"Stream error event received.",{code:f.error,details:f})}}}}if(!i)throw new o("Stream ended without a final done event containing ChatResponse.");return i}const B=2e4,L=2,W=350;class S{constructor(t,e={}){if(this.endpointsResolved=!1,!t||!t.trim())throw new o("baseEndpoint is required.");if(typeof fetch!="function"&&!e.fetchImpl)throw new o("fetch is not available in this runtime. Provide options.fetchImpl.");this.baseUrl=U(t),this.apiKey=e.apiKey,this.timeoutMs=J(e.timeoutMs,B,"timeoutMs"),this.retries=g(e.retries,L,"retries",0,10),this.retryBackoffMs=g(e.retryBackoffMs,W,"retryBackoffMs",0,6e4),this.autoDiscoverEndpoints=e.autoDiscoverEndpoints!==!1,this.defaultUserId=(e.defaultUserId??"user").trim()||"user",this.fetchFn=e.fetchImpl??fetch,this.endpoints={...x}}async getHealth(t={}){return await this.ensureEndpoints(t),this.requestJson({method:"GET",path:this.endpoints.health,timeoutMs:t.timeoutMs??this.timeoutMs,retries:t.retries??this.retries,signal:t.signal,allowRetry:!0})}async getInfo(t={}){return await this.ensureEndpoints(t),this.requestJson({method:"GET",path:this.endpoints.info,timeoutMs:t.timeoutMs??this.timeoutMs,retries:t.retries??this.retries,signal:t.signal,allowRetry:!0})}async createConversation(t={},e={}){return await this.ensureEndpoints(e),this.requestJson({method:"POST",path:this.endpoints.conversations,body:{conversation_id:t.conversation_id??"",user_id:t.user_id??this.defaultUserId,title:t.title??"New conversation"},timeoutMs:e.timeoutMs??this.timeoutMs,retries:e.retries??0,signal:e.signal,allowRetry:!1})}async deleteConversation(t,e={}){const n=t==null?void 0:t.trim();if(!n)throw new o("conversationId is required.");return await this.ensureEndpoints(e),this.requestJson({method:"DELETE",path:`${this.endpoints.conversations}/${encodeURIComponent(n)}`,timeoutMs:e.timeoutMs??this.timeoutMs,retries:e.retries??this.retries,signal:e.signal,allowRetry:!0})}async chat(t,e={}){return E(t),await this.ensureEndpoints(e),this.requestJson({method:"POST",path:this.endpoints.chat,body:{message:t.message,conversation_id:t.conversation_id??"",user_id:t.user_id??this.defaultUserId,explicit_context:t.explicit_context,metadata:t.metadata??{}},timeoutMs:e.timeoutMs??this.timeoutMs,retries:e.retries??0,signal:e.signal,allowRetry:!1})}async chatStream(t,e={},n={}){E(t),await this.ensureEndpoints(n);const s=n.timeoutMs??this.timeoutMs,i=n.signal,a=new AbortController,h=setTimeout(()=>{a.abort()},s),d=b(i,a.signal);try{const c=await this.fetchFn(T(this.baseUrl,this.endpoints.stream),{method:"POST",headers:_(this.apiKey,{accept:"text/event-stream",contentType:"application/json"}),body:JSON.stringify({message:t.message,conversation_id:t.conversation_id??"",user_id:t.user_id??this.defaultUserId,explicit_context:t.explicit_context,metadata:t.metadata??{}}),signal:d});if(!c.ok)throw await R(c,this.endpoints.stream);if(!c.body)throw new o("Streaming response body is missing.");return await F({body:c.body,handlers:e,expectChatResponse:l=>this.expectChatResponse(l),toStreamError:l=>this.toStreamError(l)})}catch(c){throw M(c)?new o(`Streaming request timed out after ${s} ms.`):c instanceof o?c:new o(this.errorMessage(c,"Streaming request failed."))}finally{clearTimeout(h)}}async sendMessage(t,e={}){var a;const n={message:t,conversation_id:e.conversationId,user_id:e.userId,explicit_context:e.explicitContext,metadata:e.metadata};let s=(a=e.conversationId)==null?void 0:a.trim();!s&&e.autoCreateConversation&&(s=(await this.createConversation({user_id:e.userId??this.defaultUserId,title:e.conversationTitle??"New conversation"},e.requestOptions)).conversation_id,n.conversation_id=s);const i=await this.chat(n,e.requestOptions);return{response:i,conversationId:i.conversation_id||s||""}}async resolveServerEndpoints(t={}){const e=await this.requestJson({method:"GET",path:this.endpoints.info,timeoutMs:t.timeoutMs??this.timeoutMs,retries:t.retries??this.retries,signal:t.signal,allowRetry:!0}),n=A(e,this.baseUrl);return this.endpoints={...this.endpoints,...n},this.endpointsResolved=!0,{...this.endpoints}}async ensureEndpoints(t={}){this.endpointsResolved=await I({endpointsResolved:this.endpointsResolved,autoDiscoverEndpoints:this.autoDiscoverEndpoints,requestOptions:t,resolveServerEndpoints:e=>this.resolveServerEndpoints(e)})}requestJson(t){return z({baseUrl:this.baseUrl,apiKey:this.apiKey,fetchFn:this.fetchFn,retryBackoffMs:this.retryBackoffMs},t)}expectChatResponse(t){if(!t||typeof t!="object")throw new o("Invalid stream done payload: expected ChatResponse object.");const e=t;if(typeof e.response!="string"||typeof e.conversation_id!="string")throw new o("Invalid ChatResponse payload: missing required fields response/conversation_id.");return e}toStreamError(t){if(!t||typeof t!="object")return{error:"stream_error",detail:"Unknown stream error payload."};const e=t;return{error:typeof e.error=="string"?e.error:"stream_error",detail:typeof e.detail=="string"?e.detail:void 0}}errorMessage(t,e){return t instanceof Error&&t.message?t.message:e}}exports.JazzmineClient=S;exports.JazzmineClientError=o;exports.default=S;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/C,cAAc,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
const C = {
|
|
2
|
+
chat: "/chat",
|
|
3
|
+
stream: "/chat/stream",
|
|
4
|
+
conversations: "/conversations",
|
|
5
|
+
health: "/health",
|
|
6
|
+
info: "/info"
|
|
7
|
+
};
|
|
8
|
+
async function $(r) {
|
|
9
|
+
if (r.endpointsResolved || !r.autoDiscoverEndpoints)
|
|
10
|
+
return r.endpointsResolved;
|
|
11
|
+
try {
|
|
12
|
+
return await r.resolveServerEndpoints(r.requestOptions), !0;
|
|
13
|
+
} catch {
|
|
14
|
+
return !0;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function I(r, t) {
|
|
18
|
+
const e = {}, n = r == null ? void 0 : r.endpoints;
|
|
19
|
+
if (!n || typeof n != "object")
|
|
20
|
+
return e;
|
|
21
|
+
const i = m(n.chat, "POST", t), s = m(n.stream, "POST", t), a = m(n.conversations_create, "POST", t), h = m(n.health, "GET", t), d = m(n.info, "GET", t);
|
|
22
|
+
return i && (e.chat = i), s ? e.stream = s : i && (e.stream = `${i.replace(/\/+$/, "")}/stream`), a && (e.conversations = a), h && (e.health = h), d && (e.info = d), e;
|
|
23
|
+
}
|
|
24
|
+
function m(r, t, e) {
|
|
25
|
+
if (typeof r != "string")
|
|
26
|
+
return null;
|
|
27
|
+
const n = r.match(/^([A-Z]+)\s+(.+)$/i);
|
|
28
|
+
if (!n)
|
|
29
|
+
return null;
|
|
30
|
+
const i = n[1].toUpperCase(), s = n[2].trim();
|
|
31
|
+
if (i !== t.toUpperCase())
|
|
32
|
+
return null;
|
|
33
|
+
try {
|
|
34
|
+
const a = new URL(s, e);
|
|
35
|
+
return `${a.pathname}${a.search}`;
|
|
36
|
+
} catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
class o extends Error {
|
|
41
|
+
constructor(t, e) {
|
|
42
|
+
super(t), this.name = "JazzmineClientError", this.status = e == null ? void 0 : e.status, this.code = e == null ? void 0 : e.code, this.details = e == null ? void 0 : e.details;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function b(r, t) {
|
|
46
|
+
if (!r && !t)
|
|
47
|
+
return;
|
|
48
|
+
if (!r)
|
|
49
|
+
return t;
|
|
50
|
+
if (!t)
|
|
51
|
+
return r;
|
|
52
|
+
const e = AbortSignal.any;
|
|
53
|
+
if (typeof e == "function")
|
|
54
|
+
return e([r, t]);
|
|
55
|
+
const n = new AbortController(), i = () => {
|
|
56
|
+
n.abort();
|
|
57
|
+
};
|
|
58
|
+
return r.aborted || t.aborted ? (n.abort(), n.signal) : (r.addEventListener("abort", i, { once: !0 }), t.addEventListener("abort", i, { once: !0 }), n.signal);
|
|
59
|
+
}
|
|
60
|
+
function R(r) {
|
|
61
|
+
return r instanceof DOMException && (r.name === "AbortError" || r.name === "TimeoutError");
|
|
62
|
+
}
|
|
63
|
+
function A(r) {
|
|
64
|
+
const t = r.trim().replace(/\/+$/, "");
|
|
65
|
+
let e;
|
|
66
|
+
try {
|
|
67
|
+
e = new URL(t);
|
|
68
|
+
} catch {
|
|
69
|
+
throw new o(
|
|
70
|
+
"Invalid baseEndpoint. Provide a full URL like https://api.example.com or http://127.0.0.1:8010."
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
if (!e.protocol.startsWith("http"))
|
|
74
|
+
throw new o("baseEndpoint must use http or https.");
|
|
75
|
+
return `${e.protocol}//${e.host}${e.pathname.replace(/\/+$/, "")}`;
|
|
76
|
+
}
|
|
77
|
+
function U(r, t) {
|
|
78
|
+
const e = t.startsWith("/") ? t : `/${t}`;
|
|
79
|
+
return `${r}${e}`;
|
|
80
|
+
}
|
|
81
|
+
function E(r) {
|
|
82
|
+
const t = r == null ? void 0 : r.message;
|
|
83
|
+
if (typeof t != "string" || !t.trim())
|
|
84
|
+
throw new o("chat payload requires a non-empty message string.");
|
|
85
|
+
if (r.explicit_context && !Array.isArray(r.explicit_context))
|
|
86
|
+
throw new o("explicit_context must be an array of strings.");
|
|
87
|
+
if (Array.isArray(r.explicit_context) && r.explicit_context.some((n) => typeof n != "string"))
|
|
88
|
+
throw new o("explicit_context must contain only strings.");
|
|
89
|
+
if (r.metadata !== void 0 && (r.metadata === null || typeof r.metadata != "object"))
|
|
90
|
+
throw new o("metadata must be an object when provided.");
|
|
91
|
+
}
|
|
92
|
+
function k(r, t, e) {
|
|
93
|
+
if (r === void 0)
|
|
94
|
+
return t;
|
|
95
|
+
if (!Number.isFinite(r) || r <= 0)
|
|
96
|
+
throw new o(`${e} must be a positive number.`);
|
|
97
|
+
return Math.round(r);
|
|
98
|
+
}
|
|
99
|
+
function g(r, t, e, n, i) {
|
|
100
|
+
if (r === void 0)
|
|
101
|
+
return t;
|
|
102
|
+
if (!Number.isInteger(r) || r < n || r > i)
|
|
103
|
+
throw new o(`${e} must be an integer between ${n} and ${i}.`);
|
|
104
|
+
return r;
|
|
105
|
+
}
|
|
106
|
+
async function J(r, t) {
|
|
107
|
+
const e = r * (t + 1);
|
|
108
|
+
e <= 0 || await new Promise((n) => setTimeout(n, e));
|
|
109
|
+
}
|
|
110
|
+
async function N(r) {
|
|
111
|
+
let t;
|
|
112
|
+
for (let e = 0; e <= r.retries; e += 1)
|
|
113
|
+
try {
|
|
114
|
+
return await r.runAttempt(e);
|
|
115
|
+
} catch (n) {
|
|
116
|
+
if (t = n, r.allowRetry && e < r.retries && r.shouldRetry(n)) {
|
|
117
|
+
await J(r.retryBackoffMs, e);
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
throw n;
|
|
121
|
+
}
|
|
122
|
+
throw t;
|
|
123
|
+
}
|
|
124
|
+
class w extends Error {
|
|
125
|
+
constructor(t) {
|
|
126
|
+
const e = `Request timed out after ${t} ms.`;
|
|
127
|
+
super(e), this.name = "RetryableTimeoutError", this.finalError = new o(e);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
class p extends Error {
|
|
131
|
+
constructor(t) {
|
|
132
|
+
super(t), this.name = "RetryableNetworkError", this.finalError = new o(t);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async function D(r, t) {
|
|
136
|
+
try {
|
|
137
|
+
return await N({
|
|
138
|
+
retries: t.retries,
|
|
139
|
+
allowRetry: t.allowRetry,
|
|
140
|
+
retryBackoffMs: r.retryBackoffMs,
|
|
141
|
+
runAttempt: async () => {
|
|
142
|
+
const e = new AbortController(), n = setTimeout(() => {
|
|
143
|
+
e.abort();
|
|
144
|
+
}, t.timeoutMs), i = b(t.signal, e.signal);
|
|
145
|
+
try {
|
|
146
|
+
const s = await r.fetchFn(_(r.baseUrl, t.path), {
|
|
147
|
+
method: t.method,
|
|
148
|
+
headers: T(r.apiKey, {
|
|
149
|
+
accept: "application/json",
|
|
150
|
+
contentType: t.body !== void 0 ? "application/json" : void 0
|
|
151
|
+
}),
|
|
152
|
+
body: t.body !== void 0 ? JSON.stringify(t.body) : void 0,
|
|
153
|
+
signal: i
|
|
154
|
+
});
|
|
155
|
+
if (!s.ok)
|
|
156
|
+
throw await M(s, t.path);
|
|
157
|
+
const a = await s.text();
|
|
158
|
+
if (!a.trim())
|
|
159
|
+
return {};
|
|
160
|
+
try {
|
|
161
|
+
return JSON.parse(a);
|
|
162
|
+
} catch {
|
|
163
|
+
throw new o(
|
|
164
|
+
`Expected JSON response from ${t.path}, but received invalid JSON.`
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
} catch (s) {
|
|
168
|
+
throw R(s) ? new w(t.timeoutMs) : s instanceof o ? s : s instanceof TypeError ? new p(y(s, "Network request failed.")) : new o(y(s, "Network request failed."));
|
|
169
|
+
} finally {
|
|
170
|
+
clearTimeout(n);
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
shouldRetry: (e) => {
|
|
174
|
+
if (e instanceof w || e instanceof p)
|
|
175
|
+
return !0;
|
|
176
|
+
if (e instanceof o) {
|
|
177
|
+
const n = e.status ?? 0;
|
|
178
|
+
return n === 429 || n >= 500;
|
|
179
|
+
}
|
|
180
|
+
return !1;
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
} catch (e) {
|
|
184
|
+
throw e instanceof w || e instanceof p ? e.finalError : e instanceof o ? e : new o(y(e, "Network request failed."));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
async function M(r, t) {
|
|
188
|
+
const e = await r.text();
|
|
189
|
+
let n;
|
|
190
|
+
if (e.trim())
|
|
191
|
+
try {
|
|
192
|
+
n = JSON.parse(e);
|
|
193
|
+
} catch {
|
|
194
|
+
n = e;
|
|
195
|
+
}
|
|
196
|
+
const i = P(n), s = `HTTP ${r.status} on ${t}${i ? `: ${i}` : ""}`;
|
|
197
|
+
return new o(s, {
|
|
198
|
+
status: r.status,
|
|
199
|
+
details: n
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
function T(r, t) {
|
|
203
|
+
const e = {};
|
|
204
|
+
return t.accept && (e.Accept = t.accept), t.contentType && (e["Content-Type"] = t.contentType), r && (e.Authorization = `Bearer ${r}`), e;
|
|
205
|
+
}
|
|
206
|
+
function _(r, t) {
|
|
207
|
+
return U(r, t);
|
|
208
|
+
}
|
|
209
|
+
function P(r) {
|
|
210
|
+
if (!r)
|
|
211
|
+
return "";
|
|
212
|
+
if (typeof r == "string")
|
|
213
|
+
return r.slice(0, 300);
|
|
214
|
+
if (typeof r == "object") {
|
|
215
|
+
const t = r, e = t.detail, n = t.error;
|
|
216
|
+
if (typeof e == "string")
|
|
217
|
+
return e.slice(0, 300);
|
|
218
|
+
if (typeof n == "string")
|
|
219
|
+
return n.slice(0, 300);
|
|
220
|
+
}
|
|
221
|
+
return "";
|
|
222
|
+
}
|
|
223
|
+
function y(r, t) {
|
|
224
|
+
return r instanceof Error && r.message ? r.message : t;
|
|
225
|
+
}
|
|
226
|
+
function j(r) {
|
|
227
|
+
const t = r.split(/\r?\n/).map((s) => s.trimEnd()).filter((s) => s.length > 0 && !s.startsWith(":"));
|
|
228
|
+
if (t.length === 0)
|
|
229
|
+
return null;
|
|
230
|
+
let e = "message";
|
|
231
|
+
const n = [];
|
|
232
|
+
for (const s of t) {
|
|
233
|
+
if (s.startsWith("event:")) {
|
|
234
|
+
e = s.slice(6).trim() || "message";
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
s.startsWith("data:") && n.push(s.slice(5).trim());
|
|
238
|
+
}
|
|
239
|
+
const i = n.join(`
|
|
240
|
+
`);
|
|
241
|
+
if (!i)
|
|
242
|
+
return { event: e, data: null };
|
|
243
|
+
try {
|
|
244
|
+
return { event: e, data: JSON.parse(i) };
|
|
245
|
+
} catch {
|
|
246
|
+
return { event: e, data: i };
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
async function F(r) {
|
|
250
|
+
var a, h, d, c;
|
|
251
|
+
const t = r.handlers ?? {}, e = r.body.getReader(), n = new TextDecoder("utf-8");
|
|
252
|
+
let i = "", s = null;
|
|
253
|
+
for (; ; ) {
|
|
254
|
+
const { done: l, value: S } = await e.read();
|
|
255
|
+
if (l)
|
|
256
|
+
break;
|
|
257
|
+
i += n.decode(S, { stream: !0 });
|
|
258
|
+
const v = i.split(/\n\n/);
|
|
259
|
+
i = v.pop() ?? "";
|
|
260
|
+
for (const x of v) {
|
|
261
|
+
const u = j(x);
|
|
262
|
+
if (u) {
|
|
263
|
+
if ((a = t.onRawEvent) == null || a.call(t, u.event, u.data), u.event === "intermediate") {
|
|
264
|
+
(h = t.onIntermediate) == null || h.call(t, u.data);
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
if (u.event === "done") {
|
|
268
|
+
s = r.expectChatResponse(u.data), (d = t.onDone) == null || d.call(t, s);
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
if (u.event === "error") {
|
|
272
|
+
const f = r.toStreamError(u.data);
|
|
273
|
+
throw (c = t.onErrorEvent) == null || c.call(t, f), new o(f.detail || f.error || "Stream error event received.", {
|
|
274
|
+
code: f.error,
|
|
275
|
+
details: f
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (!s)
|
|
282
|
+
throw new o(
|
|
283
|
+
"Stream ended without a final done event containing ChatResponse."
|
|
284
|
+
);
|
|
285
|
+
return s;
|
|
286
|
+
}
|
|
287
|
+
const B = 2e4, z = 2, L = 350;
|
|
288
|
+
class W {
|
|
289
|
+
constructor(t, e = {}) {
|
|
290
|
+
if (this.endpointsResolved = !1, !t || !t.trim())
|
|
291
|
+
throw new o("baseEndpoint is required.");
|
|
292
|
+
if (typeof fetch != "function" && !e.fetchImpl)
|
|
293
|
+
throw new o(
|
|
294
|
+
"fetch is not available in this runtime. Provide options.fetchImpl."
|
|
295
|
+
);
|
|
296
|
+
this.baseUrl = A(t), this.apiKey = e.apiKey, this.timeoutMs = k(e.timeoutMs, B, "timeoutMs"), this.retries = g(e.retries, z, "retries", 0, 10), this.retryBackoffMs = g(
|
|
297
|
+
e.retryBackoffMs,
|
|
298
|
+
L,
|
|
299
|
+
"retryBackoffMs",
|
|
300
|
+
0,
|
|
301
|
+
6e4
|
|
302
|
+
), this.autoDiscoverEndpoints = e.autoDiscoverEndpoints !== !1, this.defaultUserId = (e.defaultUserId ?? "user").trim() || "user", this.fetchFn = e.fetchImpl ?? fetch, this.endpoints = { ...C };
|
|
303
|
+
}
|
|
304
|
+
async getHealth(t = {}) {
|
|
305
|
+
return await this.ensureEndpoints(t), this.requestJson({
|
|
306
|
+
method: "GET",
|
|
307
|
+
path: this.endpoints.health,
|
|
308
|
+
timeoutMs: t.timeoutMs ?? this.timeoutMs,
|
|
309
|
+
retries: t.retries ?? this.retries,
|
|
310
|
+
signal: t.signal,
|
|
311
|
+
allowRetry: !0
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
async getInfo(t = {}) {
|
|
315
|
+
return await this.ensureEndpoints(t), this.requestJson({
|
|
316
|
+
method: "GET",
|
|
317
|
+
path: this.endpoints.info,
|
|
318
|
+
timeoutMs: t.timeoutMs ?? this.timeoutMs,
|
|
319
|
+
retries: t.retries ?? this.retries,
|
|
320
|
+
signal: t.signal,
|
|
321
|
+
allowRetry: !0
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
async createConversation(t = {}, e = {}) {
|
|
325
|
+
return await this.ensureEndpoints(e), this.requestJson({
|
|
326
|
+
method: "POST",
|
|
327
|
+
path: this.endpoints.conversations,
|
|
328
|
+
body: {
|
|
329
|
+
conversation_id: t.conversation_id ?? "",
|
|
330
|
+
user_id: t.user_id ?? this.defaultUserId,
|
|
331
|
+
title: t.title ?? "New conversation"
|
|
332
|
+
},
|
|
333
|
+
timeoutMs: e.timeoutMs ?? this.timeoutMs,
|
|
334
|
+
retries: e.retries ?? 0,
|
|
335
|
+
signal: e.signal,
|
|
336
|
+
allowRetry: !1
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
async deleteConversation(t, e = {}) {
|
|
340
|
+
const n = t == null ? void 0 : t.trim();
|
|
341
|
+
if (!n)
|
|
342
|
+
throw new o("conversationId is required.");
|
|
343
|
+
return await this.ensureEndpoints(e), this.requestJson({
|
|
344
|
+
method: "DELETE",
|
|
345
|
+
path: `${this.endpoints.conversations}/${encodeURIComponent(n)}`,
|
|
346
|
+
timeoutMs: e.timeoutMs ?? this.timeoutMs,
|
|
347
|
+
retries: e.retries ?? this.retries,
|
|
348
|
+
signal: e.signal,
|
|
349
|
+
allowRetry: !0
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
async chat(t, e = {}) {
|
|
353
|
+
return E(t), await this.ensureEndpoints(e), this.requestJson({
|
|
354
|
+
method: "POST",
|
|
355
|
+
path: this.endpoints.chat,
|
|
356
|
+
body: {
|
|
357
|
+
message: t.message,
|
|
358
|
+
conversation_id: t.conversation_id ?? "",
|
|
359
|
+
user_id: t.user_id ?? this.defaultUserId,
|
|
360
|
+
explicit_context: t.explicit_context,
|
|
361
|
+
metadata: t.metadata ?? {}
|
|
362
|
+
},
|
|
363
|
+
timeoutMs: e.timeoutMs ?? this.timeoutMs,
|
|
364
|
+
retries: e.retries ?? 0,
|
|
365
|
+
signal: e.signal,
|
|
366
|
+
allowRetry: !1
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
async chatStream(t, e = {}, n = {}) {
|
|
370
|
+
E(t), await this.ensureEndpoints(n);
|
|
371
|
+
const i = n.timeoutMs ?? this.timeoutMs, s = n.signal, a = new AbortController(), h = setTimeout(() => {
|
|
372
|
+
a.abort();
|
|
373
|
+
}, i), d = b(s, a.signal);
|
|
374
|
+
try {
|
|
375
|
+
const c = await this.fetchFn(_(this.baseUrl, this.endpoints.stream), {
|
|
376
|
+
method: "POST",
|
|
377
|
+
headers: T(this.apiKey, {
|
|
378
|
+
accept: "text/event-stream",
|
|
379
|
+
contentType: "application/json"
|
|
380
|
+
}),
|
|
381
|
+
body: JSON.stringify({
|
|
382
|
+
message: t.message,
|
|
383
|
+
conversation_id: t.conversation_id ?? "",
|
|
384
|
+
user_id: t.user_id ?? this.defaultUserId,
|
|
385
|
+
explicit_context: t.explicit_context,
|
|
386
|
+
metadata: t.metadata ?? {}
|
|
387
|
+
}),
|
|
388
|
+
signal: d
|
|
389
|
+
});
|
|
390
|
+
if (!c.ok)
|
|
391
|
+
throw await M(c, this.endpoints.stream);
|
|
392
|
+
if (!c.body)
|
|
393
|
+
throw new o("Streaming response body is missing.");
|
|
394
|
+
return await F({
|
|
395
|
+
body: c.body,
|
|
396
|
+
handlers: e,
|
|
397
|
+
expectChatResponse: (l) => this.expectChatResponse(l),
|
|
398
|
+
toStreamError: (l) => this.toStreamError(l)
|
|
399
|
+
});
|
|
400
|
+
} catch (c) {
|
|
401
|
+
throw R(c) ? new o(`Streaming request timed out after ${i} ms.`) : c instanceof o ? c : new o(this.errorMessage(c, "Streaming request failed."));
|
|
402
|
+
} finally {
|
|
403
|
+
clearTimeout(h);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
async sendMessage(t, e = {}) {
|
|
407
|
+
var a;
|
|
408
|
+
const n = {
|
|
409
|
+
message: t,
|
|
410
|
+
conversation_id: e.conversationId,
|
|
411
|
+
user_id: e.userId,
|
|
412
|
+
explicit_context: e.explicitContext,
|
|
413
|
+
metadata: e.metadata
|
|
414
|
+
};
|
|
415
|
+
let i = (a = e.conversationId) == null ? void 0 : a.trim();
|
|
416
|
+
!i && e.autoCreateConversation && (i = (await this.createConversation(
|
|
417
|
+
{
|
|
418
|
+
user_id: e.userId ?? this.defaultUserId,
|
|
419
|
+
title: e.conversationTitle ?? "New conversation"
|
|
420
|
+
},
|
|
421
|
+
e.requestOptions
|
|
422
|
+
)).conversation_id, n.conversation_id = i);
|
|
423
|
+
const s = await this.chat(n, e.requestOptions);
|
|
424
|
+
return { response: s, conversationId: s.conversation_id || i || "" };
|
|
425
|
+
}
|
|
426
|
+
async resolveServerEndpoints(t = {}) {
|
|
427
|
+
const e = await this.requestJson({
|
|
428
|
+
method: "GET",
|
|
429
|
+
path: this.endpoints.info,
|
|
430
|
+
timeoutMs: t.timeoutMs ?? this.timeoutMs,
|
|
431
|
+
retries: t.retries ?? this.retries,
|
|
432
|
+
signal: t.signal,
|
|
433
|
+
allowRetry: !0
|
|
434
|
+
}), n = I(e, this.baseUrl);
|
|
435
|
+
return this.endpoints = {
|
|
436
|
+
...this.endpoints,
|
|
437
|
+
...n
|
|
438
|
+
}, this.endpointsResolved = !0, { ...this.endpoints };
|
|
439
|
+
}
|
|
440
|
+
async ensureEndpoints(t = {}) {
|
|
441
|
+
this.endpointsResolved = await $({
|
|
442
|
+
endpointsResolved: this.endpointsResolved,
|
|
443
|
+
autoDiscoverEndpoints: this.autoDiscoverEndpoints,
|
|
444
|
+
requestOptions: t,
|
|
445
|
+
resolveServerEndpoints: (e) => this.resolveServerEndpoints(e)
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
requestJson(t) {
|
|
449
|
+
return D(
|
|
450
|
+
{
|
|
451
|
+
baseUrl: this.baseUrl,
|
|
452
|
+
apiKey: this.apiKey,
|
|
453
|
+
fetchFn: this.fetchFn,
|
|
454
|
+
retryBackoffMs: this.retryBackoffMs
|
|
455
|
+
},
|
|
456
|
+
t
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
expectChatResponse(t) {
|
|
460
|
+
if (!t || typeof t != "object")
|
|
461
|
+
throw new o("Invalid stream done payload: expected ChatResponse object.");
|
|
462
|
+
const e = t;
|
|
463
|
+
if (typeof e.response != "string" || typeof e.conversation_id != "string")
|
|
464
|
+
throw new o(
|
|
465
|
+
"Invalid ChatResponse payload: missing required fields response/conversation_id."
|
|
466
|
+
);
|
|
467
|
+
return e;
|
|
468
|
+
}
|
|
469
|
+
toStreamError(t) {
|
|
470
|
+
if (!t || typeof t != "object")
|
|
471
|
+
return { error: "stream_error", detail: "Unknown stream error payload." };
|
|
472
|
+
const e = t;
|
|
473
|
+
return {
|
|
474
|
+
error: typeof e.error == "string" ? e.error : "stream_error",
|
|
475
|
+
detail: typeof e.detail == "string" ? e.detail : void 0
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
errorMessage(t, e) {
|
|
479
|
+
return t instanceof Error && t.message ? t.message : e;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
export {
|
|
483
|
+
W as JazzmineClient,
|
|
484
|
+
o as JazzmineClientError,
|
|
485
|
+
W as default
|
|
486
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stream/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ChatResponse, StreamErrorEvent, StreamHandlers } from '../types';
|
|
2
|
+
interface ParsedSseEvent {
|
|
3
|
+
event: string;
|
|
4
|
+
data: unknown;
|
|
5
|
+
}
|
|
6
|
+
interface ConsumeStreamOptions {
|
|
7
|
+
body: ReadableStream<Uint8Array>;
|
|
8
|
+
handlers?: StreamHandlers;
|
|
9
|
+
expectChatResponse: (value: unknown) => ChatResponse;
|
|
10
|
+
toStreamError: (value: unknown) => StreamErrorEvent;
|
|
11
|
+
}
|
|
12
|
+
export declare function parseSseChunk(chunk: string): ParsedSseEvent | null;
|
|
13
|
+
export declare function consumeStream(options: ConsumeStreamOptions): Promise<ChatResponse>;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/stream/parser.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAA2B,MAAM,UAAU,CAAC;AAExG,UAAU,cAAc;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;CACf;AAED,UAAU,oBAAoB;IAC5B,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IACjC,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,kBAAkB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,YAAY,CAAC;IACrD,aAAa,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,gBAAgB,CAAC;CACrD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,GAAG,IAAI,CAiClE;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,YAAY,CAAC,CAsDxF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface ChatRequestPayload {
|
|
2
|
+
message: string;
|
|
3
|
+
conversation_id?: string;
|
|
4
|
+
user_id?: string;
|
|
5
|
+
explicit_context?: string[];
|
|
6
|
+
metadata?: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
export interface ChatResponse {
|
|
9
|
+
response: string;
|
|
10
|
+
response_markdown: string;
|
|
11
|
+
message_id: string;
|
|
12
|
+
trace_id: string;
|
|
13
|
+
conversation_id: string;
|
|
14
|
+
user_id: string;
|
|
15
|
+
invoked_flows: string[];
|
|
16
|
+
invoked_tools: string[];
|
|
17
|
+
errors: string[];
|
|
18
|
+
turn_number: number;
|
|
19
|
+
is_blocked: boolean;
|
|
20
|
+
latency_ms: number;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=chat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/types/chat.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface ConversationCreateRequest {
|
|
2
|
+
conversation_id?: string;
|
|
3
|
+
user_id?: string;
|
|
4
|
+
title?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ConversationCreateResponse {
|
|
7
|
+
conversation_id: string;
|
|
8
|
+
user_id: string;
|
|
9
|
+
agent_id: string;
|
|
10
|
+
title: string;
|
|
11
|
+
created_at: number;
|
|
12
|
+
last_updated_at: number;
|
|
13
|
+
}
|
|
14
|
+
export interface ConversationDeleteResponse {
|
|
15
|
+
conversation_id: string;
|
|
16
|
+
deleted: boolean;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=conversation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../../src/types/conversation.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,yBAAyB;IACxC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,0BAA0B;IACzC,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,0BAA0B;IACzC,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,OAAO,CAAC;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/types/health.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type InfoEndpointsMap = Record<string, string>;
|
|
2
|
+
export interface InfoResponse {
|
|
3
|
+
agent_name: string;
|
|
4
|
+
agent_id: string;
|
|
5
|
+
version: string;
|
|
6
|
+
api_version: string;
|
|
7
|
+
has_tools: boolean;
|
|
8
|
+
has_memory: boolean;
|
|
9
|
+
endpoints: InfoEndpointsMap;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=info.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"info.d.ts","sourceRoot":"","sources":["../../src/types/info.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEtD,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,gBAAgB,CAAC;CAC7B"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface JazzmineClientOptions {
|
|
2
|
+
apiKey?: string;
|
|
3
|
+
timeoutMs?: number;
|
|
4
|
+
retries?: number;
|
|
5
|
+
retryBackoffMs?: number;
|
|
6
|
+
autoDiscoverEndpoints?: boolean;
|
|
7
|
+
defaultUserId?: string;
|
|
8
|
+
fetchImpl?: typeof fetch;
|
|
9
|
+
}
|
|
10
|
+
export interface RequestOptions {
|
|
11
|
+
timeoutMs?: number;
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
retries?: number;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/types/options.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ChatResponse } from './chat';
|
|
2
|
+
export interface StreamIntermediateEvent {
|
|
3
|
+
[key: string]: unknown;
|
|
4
|
+
}
|
|
5
|
+
export interface StreamErrorEvent {
|
|
6
|
+
error: string;
|
|
7
|
+
detail?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface StreamHandlers {
|
|
10
|
+
onIntermediate?: (event: StreamIntermediateEvent) => void;
|
|
11
|
+
onDone?: (response: ChatResponse) => void;
|
|
12
|
+
onErrorEvent?: (event: StreamErrorEvent) => void;
|
|
13
|
+
onRawEvent?: (eventName: string, data: unknown) => void;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/types/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAE3C,MAAM,WAAW,uBAAuB;IACtC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,IAAI,CAAC;IAC1D,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,YAAY,KAAK,IAAI,CAAC;IAC1C,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,CAAC;IACjD,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;CACzD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/utils/url.ts"],"names":[],"mappings":"AAEA,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAgB7D;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAG9D"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ChatRequestPayload } from '../types';
|
|
2
|
+
export declare function validateChatPayload(payload: ChatRequestPayload): void;
|
|
3
|
+
export declare function normalizePositiveInt(value: number | undefined, fallback: number, field: string): number;
|
|
4
|
+
export declare function normalizeRangeInt(value: number | undefined, fallback: number, field: string, min: number, max: number): number;
|
|
5
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/utils/validation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAoBrE;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAQvG;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,GACV,MAAM,CAQR"}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jazzmine-ui/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Framework-agnostic TypeScript client for Jazzmine agentic backends",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc -p tsconfig.build.json && vite build",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"test:watch": "vitest",
|
|
26
|
+
"lint": "eslint src tests",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"prepublishOnly": "npm run typecheck && npm run test && npm run build"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/node": "^25.5.2",
|
|
32
|
+
"@vitest/coverage-v8": "^2.0.0",
|
|
33
|
+
"eslint": "^9.0.0",
|
|
34
|
+
"happy-dom": "^15.0.0",
|
|
35
|
+
"prettier": "^3.0.0",
|
|
36
|
+
"typescript": "~5.5.0",
|
|
37
|
+
"typescript-eslint": "^8.0.0",
|
|
38
|
+
"vite": "^5.0.0",
|
|
39
|
+
"vite-plugin-dts": "^4.0.0",
|
|
40
|
+
"vitest": "^2.0.0"
|
|
41
|
+
}
|
|
42
|
+
}
|