telescope-ai 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/LICENSE +21 -0
- package/README.md +280 -0
- package/dist/client-DSHwf_Ni.cjs +1226 -0
- package/dist/client-DSHwf_Ni.cjs.map +1 -0
- package/dist/client-DlnWfnqA.d.mts +651 -0
- package/dist/client-DlnWfnqA.d.mts.map +1 -0
- package/dist/client-QPIC24Zs.mjs +1112 -0
- package/dist/client-QPIC24Zs.mjs.map +1 -0
- package/dist/client-tVaTVBno.d.cts +651 -0
- package/dist/client-tVaTVBno.d.cts.map +1 -0
- package/dist/index.cjs +25 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +22 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +22 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +10 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react.cjs +376 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +223 -0
- package/dist/react.d.cts.map +1 -0
- package/dist/react.d.mts +223 -0
- package/dist/react.d.mts.map +1 -0
- package/dist/react.mjs +369 -0
- package/dist/react.mjs.map +1 -0
- package/package.json +78 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Telescope AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
# telescope-ai
|
|
2
|
+
|
|
3
|
+
Official JavaScript/TypeScript client for the [Telescope API](https://docs.telescope.co/sdk).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Full TypeScript support with strict typing
|
|
8
|
+
- Supports Telescope's v2 SSE streaming format
|
|
9
|
+
- React hooks with automatic re-render batching
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install -S telescope-ai
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
### Basic Usage
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { TelescopeClient } from "telescope-ai";
|
|
23
|
+
|
|
24
|
+
const client = new TelescopeClient({
|
|
25
|
+
apiKey: "your-api-key", // defaults to TELESCOPE_API_KEY in backend environments
|
|
26
|
+
connectTimeout: 30000, // optional, max ms to wait for server response (default: 30s)
|
|
27
|
+
debug: false, // optional, enables console logging
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Use namespaced product APIs
|
|
31
|
+
const data = await client.insights.instrument.generate({
|
|
32
|
+
instrument_reference_id1: "AAPL_US",
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Streaming Example
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { TelescopeClient } from "telescope-ai";
|
|
40
|
+
|
|
41
|
+
const client = new TelescopeClient({ apiKey: "your-api-key" });
|
|
42
|
+
|
|
43
|
+
// Start a streaming request
|
|
44
|
+
const session = client.insights.instrument.stream({
|
|
45
|
+
instrument_reference_id1: "AAPL_US",
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Subscribe to updates
|
|
49
|
+
session.subscribe({
|
|
50
|
+
onPatch: (data) => {
|
|
51
|
+
console.log("Progress:", data.groups?.length, "groups loaded");
|
|
52
|
+
},
|
|
53
|
+
onComplete: (data) => {
|
|
54
|
+
console.log("Complete:", data);
|
|
55
|
+
},
|
|
56
|
+
onError: (error) => {
|
|
57
|
+
console.error("Stream error:", error);
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// Or await the final result
|
|
62
|
+
const result = await session.complete();
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### React Integration
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
import { useInstrumentInsights } from "telescope-ai/react";
|
|
69
|
+
|
|
70
|
+
function InstrumentView({ instrumentId }: { instrumentId: string }) {
|
|
71
|
+
const { data, isStreaming, isComplete, stream } = useInstrumentInsights({
|
|
72
|
+
clientToken: "your-client-token", // or apiKey: "your-api-key" for backend usage
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
stream({ instrument_id: instrumentId });
|
|
77
|
+
}, [instrumentId, stream]);
|
|
78
|
+
|
|
79
|
+
if (isStreaming) {
|
|
80
|
+
return <div>Loading insights...</div>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<div>
|
|
85
|
+
<h1>{data.instrument?.title}</h1>
|
|
86
|
+
{data.groups?.map((group, i) => (
|
|
87
|
+
<section key={i}>
|
|
88
|
+
<h2>{group.title}</h2>
|
|
89
|
+
<p>{group.content}</p>
|
|
90
|
+
</section>
|
|
91
|
+
))}
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## API Reference
|
|
98
|
+
|
|
99
|
+
Full documentation is available at [docs.telescope.co/sdk](https://docs.telescope.co/sdk).
|
|
100
|
+
|
|
101
|
+
### TelescopeClient
|
|
102
|
+
|
|
103
|
+
The main client class for interacting with the Telescope API.
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
const client = new TelescopeClient({
|
|
107
|
+
apiKey?: string; // Organization API key (starts with `tsk_`). Defaults to TELESCOPE_API_KEY env var.
|
|
108
|
+
clientToken?: string; // Client token for frontend use (starts with `tsc_`). Cannot be used with apiKey.
|
|
109
|
+
baseUrl?: string; // API base URL (default: https://api.telescope.co)
|
|
110
|
+
connectTimeout?: number; // Max ms to wait for server to start responding (default: 30000)
|
|
111
|
+
debug?: boolean; // Enable debug logging (default: false)
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### Properties
|
|
116
|
+
|
|
117
|
+
- `TelescopeClient.VERSION` - Static property containing the SDK version
|
|
118
|
+
- `client.insights` - Namespaced access to Insights API
|
|
119
|
+
- `client.atlas` - Namespaced access to Atlas API
|
|
120
|
+
|
|
121
|
+
#### Methods
|
|
122
|
+
|
|
123
|
+
| Method | Description |
|
|
124
|
+
|--------|-------------|
|
|
125
|
+
| `get<T>(path, options?)` | Make a GET request |
|
|
126
|
+
| `post<T>(path, body?, options?)` | Make a POST request |
|
|
127
|
+
| `request<T>(path, options?)` | Make a generic HTTP request |
|
|
128
|
+
| `stream<T>(path, body, options?)` | Start an SSE streaming request |
|
|
129
|
+
| `streamFromResponse<T>(source)` | Create a StreamSession from a pre-existing SSE response |
|
|
130
|
+
| `generateClientToken()` | Generate a client token for frontend use |
|
|
131
|
+
|
|
132
|
+
### Insights API
|
|
133
|
+
|
|
134
|
+
Access via `client.insights`. Uses a nested sub-client pattern with `instrument` and `portfolio` namespaces.
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
// Streaming
|
|
138
|
+
const session = client.insights.instrument.stream({ instrument_reference_id1: "AAPL_US" });
|
|
139
|
+
const session = client.insights.portfolio.stream({ instrument_reference_id1s: ["AAPL_US", "GOOGL_US"] });
|
|
140
|
+
|
|
141
|
+
// Non-streaming
|
|
142
|
+
const data = await client.insights.instrument.generate({ instrument_reference_id1: "AAPL_US" });
|
|
143
|
+
const data = await client.insights.portfolio.generate({ instrument_reference_id1s: ["AAPL_US", "GOOGL_US"] });
|
|
144
|
+
|
|
145
|
+
// From proxy/custom fetch responses
|
|
146
|
+
const session = client.insights.instrument.streamFromResponse(response);
|
|
147
|
+
const data = await client.insights.portfolio.generateFromResponse(response);
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Atlas API
|
|
151
|
+
|
|
152
|
+
Access via `client.atlas`:
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
// Streaming
|
|
156
|
+
const session = client.atlas.streamAdvice({
|
|
157
|
+
advisor_environment_id: "...",
|
|
158
|
+
client_details: "...",
|
|
159
|
+
// ... other required fields
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// Non-streaming
|
|
163
|
+
const advice = await client.atlas.getAdvice("advice-id");
|
|
164
|
+
const recent = await client.atlas.getLatestAdvice(30);
|
|
165
|
+
await client.atlas.archiveAdvice(["id1", "id2"], true);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
> **Note:** Ripple and Guardrails clients are coming in a future release once their backends support the V2 SSE format.
|
|
169
|
+
|
|
170
|
+
### StreamSession
|
|
171
|
+
|
|
172
|
+
Returned by streaming methods. Provides real-time access to streaming data.
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
const session = client.insights.instrument.stream({ instrument_reference_id1: "AAPL_US" });
|
|
176
|
+
|
|
177
|
+
// Current data (updates in real-time)
|
|
178
|
+
console.log(session.data);
|
|
179
|
+
|
|
180
|
+
// Current status
|
|
181
|
+
console.log(session.status); // { phase: 'streaming', startedAt: 1234567890 }
|
|
182
|
+
|
|
183
|
+
// Subscribe to events
|
|
184
|
+
const unsubscribe = session.subscribe({
|
|
185
|
+
onPatch: (data, event) => { /* called on each update */ },
|
|
186
|
+
onPathComplete: (path, data) => { /* called when a path finishes */ },
|
|
187
|
+
onComplete: (data) => { /* called when stream completes */ },
|
|
188
|
+
onError: (error) => { /* called on SSE errors */ },
|
|
189
|
+
onTransportError: (error) => { /* called on connection errors */ },
|
|
190
|
+
onHeartbeat: () => { /* called on heartbeat events */ },
|
|
191
|
+
onStatusChange: (status) => { /* called on any status change */ },
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// Wait for completion
|
|
195
|
+
const finalData = await session.complete();
|
|
196
|
+
|
|
197
|
+
// Cleanup
|
|
198
|
+
unsubscribe();
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Error Handling
|
|
202
|
+
|
|
203
|
+
The SDK provides a typed error hierarchy. All errors extend `TelescopeClientError`.
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
import {
|
|
207
|
+
TelescopeClientError,
|
|
208
|
+
ApiError,
|
|
209
|
+
NetworkError,
|
|
210
|
+
StreamingError,
|
|
211
|
+
SSEError,
|
|
212
|
+
} from "telescope-ai";
|
|
213
|
+
|
|
214
|
+
try {
|
|
215
|
+
const data = await client.get("/v2/endpoint");
|
|
216
|
+
} catch (error) {
|
|
217
|
+
if (error instanceof ApiError) {
|
|
218
|
+
console.log(error.status, error.body);
|
|
219
|
+
} else if (error instanceof NetworkError) {
|
|
220
|
+
console.log(error.message);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
| Error | Description |
|
|
226
|
+
|-------|-------------|
|
|
227
|
+
| `ApiError` | HTTP errors from the API (4xx, 5xx). Has `status` and `body` properties. |
|
|
228
|
+
| `NetworkError` | Connection failures, timeouts, DNS errors. |
|
|
229
|
+
| `StreamingError` | Transport-level streaming failures (connection dropped, bad content-type). Has an optional `status` property. |
|
|
230
|
+
| `SSEError` | Application-level errors received via SSE error events. Has `code`, `httpStatus`, and optional `path` properties. |
|
|
231
|
+
|
|
232
|
+
## Security Warning
|
|
233
|
+
|
|
234
|
+
**Do not expose your API key in client-side code.**
|
|
235
|
+
|
|
236
|
+
For browser applications, use client tokens:
|
|
237
|
+
|
|
238
|
+
```typescript
|
|
239
|
+
// Backend: Generate a client token
|
|
240
|
+
const serverClient = new TelescopeClient({ apiKey: process.env.TELESCOPE_API_KEY });
|
|
241
|
+
const clientToken = await serverClient.generateClientToken();
|
|
242
|
+
|
|
243
|
+
// Frontend: Use the client token
|
|
244
|
+
const browserClient = new TelescopeClient({ clientToken });
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Client tokens have limited permissions and expire after a short time, making them safe for frontend use.
|
|
248
|
+
|
|
249
|
+
## TypeScript
|
|
250
|
+
|
|
251
|
+
This package includes TypeScript declarations. No additional `@types` package is needed.
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
import type {
|
|
255
|
+
TelescopeClientOptions,
|
|
256
|
+
StreamSession,
|
|
257
|
+
StreamStatus,
|
|
258
|
+
StreamPhase,
|
|
259
|
+
InstrumentInsightsResponse,
|
|
260
|
+
AtlasAdviceResponse,
|
|
261
|
+
} from "telescope-ai";
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Browser Support
|
|
265
|
+
|
|
266
|
+
This SDK supports modern browsers (ES2022+) and Node.js 18+.
|
|
267
|
+
|
|
268
|
+
For older environments, you may need to polyfill:
|
|
269
|
+
- `AbortSignal.timeout()`
|
|
270
|
+
- `fetch()`
|
|
271
|
+
|
|
272
|
+
## License
|
|
273
|
+
|
|
274
|
+
MIT - see [LICENSE](./LICENSE) for details.
|
|
275
|
+
|
|
276
|
+
## Links
|
|
277
|
+
|
|
278
|
+
- [Documentation](https://docs.telescope.co/sdk)
|
|
279
|
+
- [npm](https://www.npmjs.com/package/telescope-ai)
|
|
280
|
+
- [Changelog](./CHANGELOG.md)
|