needle-cloud 1.10.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/cli.esm.js +1 -1
  3. package/dist/index.d.ts +465 -1
  4. package/dist/index.esm.js +1 -2
  5. package/package.json +19 -16
  6. package/dist/index.esm.js.map +0 -1
  7. package/dist/needle-share-cli/src/cli.d.ts +0 -1
  8. package/dist/needle-share-cli/src/index.d.ts +0 -1
  9. package/dist/needle-share-cli/src/web/auth.config.d.ts +0 -9
  10. package/dist/needle-share-cli/src/web/auth.d.ts +0 -79
  11. package/dist/needle-share-cli/src/web/functions/checkout.d.ts +0 -10
  12. package/dist/needle-share-cli/src/web/functions/get.d.ts +0 -59
  13. package/dist/needle-share-cli/src/web/functions/index.d.ts +0 -3
  14. package/dist/needle-share-cli/src/web/functions/upload.d.ts +0 -28
  15. package/dist/needle-share-cli/src/web/functions/utils.d.ts +0 -5
  16. package/dist/needle-share-cli/src/web/index.d.ts +0 -4
  17. package/dist/needle-share-cli/src/web/polyfill.d.ts +0 -1
  18. package/dist/needle-share-cli/src/web/utils.d.ts +0 -1
  19. package/dist/needle-share-cli/src/web/web-components/LoginButton.d.ts +0 -9
  20. package/dist/needle-share-cli/src/web/web-components/index.d.ts +0 -1
  21. package/dist/pako.esm-01431bd2.js.map +0 -1
  22. package/dist/web/auth.config.d.ts +0 -9
  23. package/dist/web/auth.d.ts +0 -79
  24. package/dist/web/functions/checkout.d.ts +0 -10
  25. package/dist/web/functions/get.d.ts +0 -59
  26. package/dist/web/functions/index.d.ts +0 -3
  27. package/dist/web/functions/upload.d.ts +0 -28
  28. package/dist/web/functions/utils.d.ts +0 -5
  29. package/dist/web/index.d.ts +0 -4
  30. package/dist/web/polyfill.d.ts +0 -1
  31. package/dist/web/utils.d.ts +0 -1
  32. package/dist/web/web-components/LoginButton.d.ts +0 -9
  33. package/dist/web/web-components/index.d.ts +0 -1
package/dist/index.d.ts CHANGED
@@ -1 +1,465 @@
1
- export * from "./web/index.js";
1
+ import * as _logto_browser from '@logto/browser';
2
+ import { UserScope } from '@logto/browser';
3
+ import Stripe from 'stripe';
4
+
5
+ type LogtoUserCustomData$1 = {
6
+ default_org?: string;
7
+ machines?: Array<{ id: string, name: string, first_login_at: string, login_expiration_time?: string }>;
8
+ preferences?: {
9
+ allow_marketing_emails?: boolean;
10
+ }
11
+ ai?: {
12
+ cli_tools?: "bypass_permissions" | "disabled";
13
+ }
14
+ }
15
+
16
+ declare namespace Auth {
17
+ /** @param {boolean} _debug */
18
+ function setDebug(_debug: boolean): void;
19
+ let baseUrl: string;
20
+ let redirectUri: string;
21
+ let postSignOutRedirectUri: string;
22
+ /**
23
+ * Register a callback to be called when the authentication state changes
24
+ * @param {Function} callback - The callback to register
25
+ * @returns {Function} - A function to unregister the callback
26
+ */
27
+ function onChanged(callback: Function): Function;
28
+ /**
29
+ * Returns a promise that resolves when Auth is initialized
30
+ * @returns {Promise<boolean>}
31
+ */
32
+ function ready(): Promise<boolean>;
33
+ /**
34
+ * Initialize the Auth system
35
+ * @internal
36
+ * @param {AuthInitOpts} [opts] - Initialization options
37
+ * @returns {Promise<boolean>}
38
+ */
39
+ function init(opts?: AuthInitOpts): Promise<boolean>;
40
+ /**
41
+ * Check if the user is currently authenticated
42
+ * @returns {boolean}
43
+ */
44
+ function isAuthenticated(): boolean;
45
+ /**
46
+ * Check authentication status with the server
47
+ * @returns {Promise<boolean>}
48
+ */
49
+ function checkIsAuthenticated(): Promise<boolean>;
50
+ /**
51
+ * Get the current user information (if fetched previously)
52
+ * @returns {UserInfoResponse|null}
53
+ */
54
+ function getUserInfo(): UserInfoResponse | null;
55
+ /**
56
+ * Get the current user ID (sub)
57
+ * @returns {string|null}
58
+ */
59
+ function getUserId(): string | null;
60
+ /**
61
+ * Get the user's name or username (if available)
62
+ * @returns {string|null}
63
+ */
64
+ function getName(): string | null;
65
+ /**
66
+ * Request user information from the server
67
+ * @returns {Promise<UserInfoResponse|null>}
68
+ */
69
+ function requestUserInfo(): Promise<UserInfoResponse | null>;
70
+ /**
71
+ * Request an access token for the configured resource
72
+ * @param {string | undefined | null} [org_id] - The organization ID (optional). If none is provided the user access token will be requested.
73
+ * @returns {Promise<string>}
74
+ */
75
+ function requestAccessToken(org_id?: string | undefined | null): Promise<string>;
76
+ /**
77
+ * Initiate the sign-in process
78
+ */
79
+ function signIn(): Promise<void>;
80
+ /**
81
+ * Get the user's default team/org ID from their Logto custom_data.
82
+ * @returns {string | undefined}
83
+ */
84
+ function getDefaultTeamId(): string | undefined;
85
+ /**
86
+ * Sign out the current user
87
+ */
88
+ function signOut(): Promise<void>;
89
+ }
90
+ type UserInfoResponse = _logto_browser.UserInfoResponse;
91
+ type LogtoUserCustomData = LogtoUserCustomData$1;
92
+ type ResourceUrl = "https://cloud.needle.tools/api" | ({} & string);
93
+ type AuthInitOpts = {
94
+ appId?: string;
95
+ /**
96
+ * User scopes. If an empty array is passed
97
+ */
98
+ scopes?: string[] | "payment" | "all";
99
+ debug?: boolean;
100
+ };
101
+
102
+ /**
103
+ * Basic web component for login/logout
104
+ */
105
+ declare class NeedleLoginButton extends HTMLButtonElement {
106
+ connectedCallback(): void;
107
+ __unsubscribeOnChange: Function;
108
+ disconnectedCallback(): void;
109
+ __update(): void;
110
+ }
111
+
112
+ /**
113
+ * The authentication token
114
+ */
115
+ declare type AuthData$1 = {
116
+ authToken: string;
117
+ org?: string | null | undefined;
118
+ /** @deprecated */
119
+ roles?: Array<string>;
120
+ /** @deprecated */
121
+ roles_org?: Array<string>;
122
+ }
123
+
124
+ type NeedleLicense = "basic" | "indie" | "pro" | "enterprise" | "edu"
125
+
126
+ type AiTokenUsageInfo = {
127
+ /** Total tokens available */
128
+ max_available: number,
129
+ /** Tokens used so far */
130
+ used: number,
131
+ /** Tokens remaining */
132
+ remaining: number,
133
+ /** Usage from 0 to 1, where 1 is all tokens used. */
134
+ usage01: number,
135
+ /** The license used for this chat session, or null if no license is used. */
136
+ license_used: NeedleLicense | null,
137
+ }
138
+
139
+
140
+ type RecentChatsResponse$1 = {
141
+ data: Array<{
142
+ slug: string,
143
+ topic: string,
144
+ created_at: string,
145
+ updated_at?: string,
146
+ }>
147
+ }
148
+
149
+
150
+ /** Tool definition provided by the client for client-side execution. */
151
+ type ClientToolDefinition$1 = {
152
+ name: string,
153
+ description: string,
154
+ parameters?: Record<string, any>,
155
+ }
156
+
157
+ /** Context block sent by the client (e.g. page metadata, scene hierarchy). */
158
+ type ClientContext$1 = {
159
+ type: "text",
160
+ text: string,
161
+ }
162
+
163
+
164
+ type ChatMessageToolCall = {
165
+ name: string,
166
+ args: Record<string, any>,
167
+ result_length?: number,
168
+ duration_ms?: number,
169
+ }
170
+
171
+ type ChatMessage = {
172
+ created_at: string,
173
+ id: string,
174
+ role: "assistant" | "tool" | "user",
175
+ content: string,
176
+ tool_calls?: ChatMessageToolCall[],
177
+ metadata?: {
178
+ tokens?: { input: number, output: number },
179
+ model?: string,
180
+ /** True while the AI is still streaming a response. Absent or false when the message is complete. */
181
+ is_partial?: boolean,
182
+ /** True when the user stopped generation mid-stream. */
183
+ interrupted?: boolean,
184
+ } | null,
185
+ }
186
+ type AIChatGETResponse$1 = {
187
+ chat_id: string,
188
+ messages: Array<ChatMessage>,
189
+ token_usage: AiTokenUsageInfo | null,
190
+ cli_connected?: boolean,
191
+ cli_tools_enabled?: boolean,
192
+ }
193
+
194
+ /** Response type when using stream: false in the request body. */
195
+ type AIChatSyncResponse$1 = {
196
+ chat_id: string,
197
+ message_id: string,
198
+ role: "assistant",
199
+ content: string,
200
+ tool_calls?: ChatMessageToolCall[],
201
+ metadata?: ChatMessage["metadata"],
202
+ token_usage?: AiTokenUsageInfo | null,
203
+ }
204
+
205
+ /** Discriminated union for events yielded by the SSE chat stream. */
206
+ type ChatStreamEvent$1 = { /** SSE event id for position tracking. */ id?: number } & (
207
+ | { type: "delta", content: string }
208
+ | { type: "message", content: string }
209
+ | { type: "message_id", message_id: string }
210
+ | { type: "tool_call", name: string, args: Record<string, any> }
211
+ | { type: "tool_result", name: string }
212
+ | { type: "client_tool_request", request_id: string, name: string, args: Record<string, any> }
213
+ | { type: "error", message: string }
214
+ | { type: "stopped" }
215
+ | { type: "status", message: string }
216
+ | { type: "done", token_usage: AiTokenUsageInfo }
217
+ | { type: "chat_id", chat_id: string }
218
+ )
219
+
220
+ /**
221
+ * @typedef {{ name: string, mimetype: string, buffer:Buffer }} Filelike
222
+ * @typedef {import("../web.types.js").AuthData} AuthData
223
+ */
224
+ /**
225
+ * @param {Array<Filelike>} files
226
+ * @param {{org?:string|null} & { name?:string, abort?:AbortSignal, }} opts
227
+ * @returns {Promise<{error:string} | {job_id:string, content_id:string, url?:string | null, skipped?:boolean}>}
228
+ */
229
+ declare function uploadFiles(files: Array<Filelike>, opts: {
230
+ org?: string | null;
231
+ } & {
232
+ name?: string;
233
+ abort?: AbortSignal;
234
+ }): Promise<{
235
+ error: string;
236
+ } | {
237
+ job_id: string;
238
+ content_id: string;
239
+ url?: string | null;
240
+ skipped?: boolean;
241
+ }>;
242
+ type Filelike = {
243
+ name: string;
244
+ mimetype: string;
245
+ buffer: Buffer;
246
+ };
247
+ type AuthData = AuthData$1;
248
+
249
+ type BaseLicense = {
250
+ id: string,
251
+ valid: boolean,
252
+ }
253
+
254
+ type BaseSubscription = BaseLicense & {
255
+ /** ISO timestamp */
256
+ current_period_start: number,
257
+ /** ISO timestamp */
258
+ current_period_end: number,
259
+ renews_at: number | undefined | null,
260
+ cancels_at: number | undefined | null,
261
+ status: Stripe.Subscription.Status,
262
+ recurring?: {
263
+ interval: "day" | "week" | "month" | "year",
264
+ interval_count: number | undefined,
265
+ }
266
+ }
267
+
268
+ type SeatBasedLicense = BaseSubscription & {
269
+ mode: "seat-based",
270
+
271
+ /** Total available seats */
272
+ seats: number,
273
+
274
+ activated_count?: number,
275
+ /**
276
+ * User ids that have activated this license
277
+ */
278
+ activated_by?: string[],
279
+
280
+ /** Is the license activated by this user? */
281
+ user_activated?: boolean,
282
+ /** Is this activation valid */
283
+ user_activated_valid?: boolean,
284
+
285
+ /** This is a user or org name */
286
+ granted_by?: "self" | "ORG" | (string & {}),
287
+ granted_by_id?: string,
288
+ }
289
+
290
+ type UsageBasedLicense = BaseSubscription & {
291
+ mode: "usage-based",
292
+ }
293
+
294
+
295
+ type NeedleEngineLicense = SeatBasedLicense & {
296
+ type: "Needle Engine",
297
+ license: NeedleLicense,
298
+ }
299
+
300
+
301
+ type NeedleCloudLicense = UsageBasedLicense & {
302
+ type: "Needle Cloud",
303
+ }
304
+
305
+ type OneTimePurchase = BaseLicense & {
306
+ mode: "one-time-purchase",
307
+ type: string,
308
+ created_at: string,
309
+ license?: string,
310
+ seats?: number,
311
+ };
312
+
313
+ type License = NeedleEngineLicense | NeedleCloudLicense | OneTimePurchase;
314
+
315
+ /**
316
+ * @param {{ org?:string } & { offset?:number, limit?: number }} opts
317
+ * @returns {Promise<Array<Deployment>>}
318
+ * @typedef {{ name: string, url: string }} Deployment
319
+ */
320
+ declare function getDeployments(opts: {
321
+ org?: string;
322
+ } & {
323
+ offset?: number;
324
+ limit?: number;
325
+ }): Promise<Array<Deployment>>;
326
+ /**
327
+ * Get licenses for a specific user. A product type is optional.
328
+ * Only valid licenses are returned
329
+ * @param {{product?:string | string[], includeInvalid?: boolean}} opts
330
+ * @returns {Promise<null | import("../../../../needle-share/types/stripe.js").License[]>}
331
+ */
332
+ declare function getUserLicenses(opts: {
333
+ product?: string | string[];
334
+ includeInvalid?: boolean;
335
+ }): Promise<null | License[]>;
336
+ /**
337
+ * Checks if the current user owns a specific product. A product type is optional
338
+ * @param {{product?:string | string[]}} opts
339
+ * @returns {Promise<boolean>}
340
+ */
341
+ declare function ownsProduct(opts: {
342
+ product?: string | string[];
343
+ }): Promise<boolean>;
344
+ type Deployment = {
345
+ name: string;
346
+ url: string;
347
+ };
348
+
349
+ /**
350
+ * List recent AI chats for the authenticated user.
351
+ * @param {ChatAuthOpts} [opts]
352
+ * @returns {Promise<RecentChatsResponse>}
353
+ */
354
+ declare function listChats(opts?: ChatAuthOpts): Promise<RecentChatsResponse>;
355
+ /**
356
+ * Read an AI chat by slug. Returns JSON with messages by default.
357
+ * When `reconnect: true`, attempts to reconnect to an active SSE stream.
358
+ * @overload
359
+ * @param {string} slug
360
+ * @param {ChatAuthOpts & { offset?: number, limit?: number, personal?: boolean, reconnect?: false }} [opts]
361
+ * @returns {Promise<AIChatGETResponse>}
362
+ */
363
+ declare function readChat(slug: string, opts?: ChatAuthOpts & {
364
+ offset?: number;
365
+ limit?: number;
366
+ personal?: boolean;
367
+ reconnect?: false;
368
+ }): Promise<AIChatGETResponse>;
369
+ /**
370
+ * @overload
371
+ * @param {string} slug
372
+ * @param {ChatAuthOpts & { personal?: boolean, reconnect: true, signal?: AbortSignal }} opts
373
+ * @returns {Promise<AsyncGenerator<ChatStreamEvent> | null>}
374
+ */
375
+ declare function readChat(slug: string, opts: ChatAuthOpts & {
376
+ personal?: boolean;
377
+ reconnect: true;
378
+ signal?: AbortSignal;
379
+ }): Promise<AsyncGenerator<ChatStreamEvent> | null>;
380
+ /**
381
+ * Send a message to an AI chat.
382
+ * @overload
383
+ * @param {string} slug
384
+ * @param {string} message
385
+ * @param {ChatAuthOpts & { stream?: false, source?: string, personal?: boolean, full_url?: string, pathname?: string, client_tools?: ClientToolDefinition[], context?: ClientContext[] }} [opts]
386
+ * @returns {Promise<AIChatSyncResponse>}
387
+ */
388
+ declare function sendChatMessage(slug: string, message: string, opts?: ChatAuthOpts & {
389
+ stream?: false;
390
+ source?: string;
391
+ personal?: boolean;
392
+ full_url?: string;
393
+ pathname?: string;
394
+ client_tools?: ClientToolDefinition[];
395
+ context?: ClientContext[];
396
+ }): Promise<AIChatSyncResponse>;
397
+ /**
398
+ * @overload
399
+ * @param {string} slug
400
+ * @param {string} message
401
+ * @param {ChatAuthOpts & { stream: true, source?: string, personal?: boolean, full_url?: string, pathname?: string, client_tools?: ClientToolDefinition[], context?: ClientContext[] }} opts
402
+ * @returns {Promise<AsyncGenerator<ChatStreamEvent>>}
403
+ */
404
+ declare function sendChatMessage(slug: string, message: string, opts: ChatAuthOpts & {
405
+ stream: true;
406
+ source?: string;
407
+ personal?: boolean;
408
+ full_url?: string;
409
+ pathname?: string;
410
+ client_tools?: ClientToolDefinition[];
411
+ context?: ClientContext[];
412
+ }): Promise<AsyncGenerator<ChatStreamEvent>>;
413
+ /**
414
+ * Interrupt an active AI generation for the given chat slug.
415
+ * @param {string} slug
416
+ * @param {ChatAuthOpts & { personal?: boolean }} [opts]
417
+ * @returns {Promise<void>}
418
+ */
419
+ declare function interruptChat(slug: string, opts?: ChatAuthOpts & {
420
+ personal?: boolean;
421
+ }): Promise<void>;
422
+ /**
423
+ * Submit a client-side tool execution result back to the server.
424
+ * Call this when you receive a `client_tool_request` event from the SSE stream.
425
+ * @param {string} requestId - The `request_id` from the `client_tool_request` event
426
+ * @param {{ result?: any, error?: string }} outcome - The tool result or error
427
+ * @param {ChatAuthOpts & { personal?: boolean }} [opts]
428
+ * @returns {Promise<void>}
429
+ */
430
+ declare function submitToolResult(requestId: string, outcome: {
431
+ result?: any;
432
+ error?: string;
433
+ }, opts?: ChatAuthOpts & {
434
+ personal?: boolean;
435
+ }): Promise<void>;
436
+ type ChatAuthOpts = {
437
+ org?: string;
438
+ authToken?: string;
439
+ };
440
+ type RecentChatsResponse = RecentChatsResponse$1;
441
+ type AIChatGETResponse = AIChatGETResponse$1;
442
+ type ChatStreamEvent = ChatStreamEvent$1;
443
+ type ClientToolDefinition = ClientToolDefinition$1;
444
+ type ClientContext = ClientContext$1;
445
+ type AIChatSyncResponse = AIChatSyncResponse$1;
446
+
447
+ /**
448
+ * Start the checkout process
449
+ * @param {{ price_id:string }} args
450
+ */
451
+ declare function startCheckoutSession(args: {
452
+ price_id: string;
453
+ }): Promise<{
454
+ ok: boolean;
455
+ status: number;
456
+ }>;
457
+
458
+ declare namespace AuthScopes {
459
+ let Basic: UserScope[];
460
+ let Payment: string[];
461
+ let All: string[];
462
+ }
463
+
464
+ export { Auth, AuthScopes, NeedleLoginButton, getDeployments, getUserLicenses, interruptChat, listChats, ownsProduct, readChat, sendChatMessage, startCheckoutSession, submitToolResult, uploadFiles };
465
+ export type { AIChatGETResponse, AIChatSyncResponse, AuthData, AuthInitOpts, ChatAuthOpts, ChatStreamEvent, ClientContext, ClientToolDefinition, Deployment, Filelike, LogtoUserCustomData, RecentChatsResponse, ResourceUrl, UserInfoResponse };