@pellux/goodvibes-sdk 0.18.48 → 0.18.49
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 +15 -13
- package/dist/_internal/errors/index.d.ts +86 -0
- package/dist/_internal/errors/index.d.ts.map +1 -1
- package/dist/_internal/errors/index.js +86 -0
- package/dist/_internal/platform/version.js +1 -1
- package/dist/_internal/transport-http/http-core.d.ts +2 -0
- package/dist/_internal/transport-http/http-core.d.ts.map +1 -1
- package/dist/_internal/transport-http/http-core.js +29 -2
- package/dist/_internal/transport-http/http.d.ts.map +1 -1
- package/dist/_internal/transport-http/http.js +50 -2
- package/dist/auth.d.ts +49 -0
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +49 -0
- package/dist/browser.d.ts +23 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +23 -0
- package/dist/client.d.ts +108 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +20 -0
- package/dist/expo.d.ts +14 -0
- package/dist/expo.d.ts.map +1 -1
- package/dist/expo.js +14 -0
- package/dist/node.d.ts +22 -0
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +22 -0
- package/dist/react-native.d.ts +26 -0
- package/dist/react-native.d.ts.map +1 -1
- package/dist/react-native.js +26 -0
- package/dist/web.d.ts +12 -0
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +12 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,34 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
Umbrella GoodVibes SDK with Node, browser, web UI, React Native, and Expo integration helpers.
|
|
4
4
|
|
|
5
|
+
> **What this SDK is:** a client for the GoodVibes daemon. Not a direct provider SDK.
|
|
6
|
+
> See [Getting Started](../../docs/getting-started.md) for the full walkthrough.
|
|
7
|
+
|
|
5
8
|
Install:
|
|
6
9
|
|
|
7
10
|
```bash
|
|
8
11
|
npm install @pellux/goodvibes-sdk
|
|
9
12
|
```
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Entry points:
|
|
14
|
-
- `@pellux/goodvibes-sdk`
|
|
15
|
-
- `@pellux/goodvibes-sdk/auth`
|
|
16
|
-
- `@pellux/goodvibes-sdk/node`
|
|
17
|
-
- `@pellux/goodvibes-sdk/browser`
|
|
18
|
-
- `@pellux/goodvibes-sdk/web`
|
|
19
|
-
- `@pellux/goodvibes-sdk/react-native`
|
|
20
|
-
- `@pellux/goodvibes-sdk/expo`
|
|
21
|
-
|
|
22
|
-
Example:
|
|
14
|
+
Quick example (Node / Bun):
|
|
23
15
|
|
|
24
16
|
```ts
|
|
25
17
|
import { createNodeGoodVibesSdk } from '@pellux/goodvibes-sdk/node';
|
|
18
|
+
import { createMemoryTokenStore } from '@pellux/goodvibes-sdk/auth';
|
|
26
19
|
|
|
27
20
|
const sdk = createNodeGoodVibesSdk({
|
|
28
21
|
baseUrl: 'http://127.0.0.1:3210',
|
|
29
|
-
|
|
22
|
+
tokenStore: createMemoryTokenStore(process.env.GOODVIBES_TOKEN ?? null),
|
|
30
23
|
});
|
|
31
24
|
|
|
32
25
|
console.log(await sdk.operator.control.snapshot());
|
|
33
26
|
```
|
|
34
27
|
|
|
28
|
+
Entry points:
|
|
29
|
+
- `@pellux/goodvibes-sdk`
|
|
30
|
+
- `@pellux/goodvibes-sdk/auth`
|
|
31
|
+
- `@pellux/goodvibes-sdk/node`
|
|
32
|
+
- `@pellux/goodvibes-sdk/browser`
|
|
33
|
+
- `@pellux/goodvibes-sdk/web`
|
|
34
|
+
- `@pellux/goodvibes-sdk/react-native`
|
|
35
|
+
- `@pellux/goodvibes-sdk/expo`
|
|
36
|
+
|
|
35
37
|
Use this package when you want the main consumer-facing GoodVibes TypeScript SDK rather than lower-level pieces.
|
|
@@ -21,6 +21,29 @@ export interface GoodVibesSdkErrorOptions {
|
|
|
21
21
|
readonly retryAfterMs?: number;
|
|
22
22
|
}
|
|
23
23
|
export declare const RETRYABLE_STATUS_CODES: readonly number[];
|
|
24
|
+
/**
|
|
25
|
+
* Base error class for all errors thrown by the GoodVibes SDK.
|
|
26
|
+
*
|
|
27
|
+
* Every error carries a structured `category` and `source` that allow
|
|
28
|
+
* callers to handle specific failure modes without string-matching messages.
|
|
29
|
+
*
|
|
30
|
+
* ### Narrowing pattern
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { GoodVibesSdkError, HttpStatusError, ConfigurationError } from '@pellux/goodvibes-sdk';
|
|
33
|
+
*
|
|
34
|
+
* try {
|
|
35
|
+
* await sdk.operator.agents.list();
|
|
36
|
+
* } catch (err) {
|
|
37
|
+
* if (err instanceof HttpStatusError && err.category === 'rate_limit') {
|
|
38
|
+
* // Back off and retry after err.retryAfterMs
|
|
39
|
+
* } else if (err instanceof ConfigurationError) {
|
|
40
|
+
* // Invalid SDK setup — not recoverable
|
|
41
|
+
* } else if (err instanceof GoodVibesSdkError) {
|
|
42
|
+
* console.error(err.category, err.hint);
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
24
47
|
export declare class GoodVibesSdkError extends Error {
|
|
25
48
|
readonly code?: string;
|
|
26
49
|
readonly category: ErrorCategory;
|
|
@@ -40,12 +63,75 @@ export declare class GoodVibesSdkError extends Error {
|
|
|
40
63
|
readonly retryAfterMs?: number;
|
|
41
64
|
constructor(message: string, options?: GoodVibesSdkErrorOptions);
|
|
42
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Thrown when the SDK is misconfigured (e.g. missing `baseUrl`, no fetch
|
|
68
|
+
* implementation available, or calling a mutation on a read-only auth resolver).
|
|
69
|
+
*
|
|
70
|
+
* Always non-recoverable (`recoverable: false`).
|
|
71
|
+
* Category: `'config'`.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* import { ConfigurationError } from '@pellux/goodvibes-sdk';
|
|
75
|
+
*
|
|
76
|
+
* try {
|
|
77
|
+
* await sdk.auth.setToken('x');
|
|
78
|
+
* } catch (err) {
|
|
79
|
+
* if (err instanceof ConfigurationError) {
|
|
80
|
+
* // SDK was constructed with getAuthToken — token mutation not supported
|
|
81
|
+
* }
|
|
82
|
+
* }
|
|
83
|
+
*/
|
|
43
84
|
export declare class ConfigurationError extends GoodVibesSdkError {
|
|
44
85
|
constructor(message: string, options?: GoodVibesSdkErrorOptions);
|
|
45
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Thrown when a response from the daemon violates the expected contract
|
|
89
|
+
* (unexpected shape, missing required fields, etc.).
|
|
90
|
+
*
|
|
91
|
+
* Always non-recoverable (`recoverable: false`).
|
|
92
|
+
* Category: `'contract'`.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* import { ContractError } from '@pellux/goodvibes-sdk';
|
|
96
|
+
*
|
|
97
|
+
* try {
|
|
98
|
+
* const result = await sdk.operator.agents.get({ id: agentId });
|
|
99
|
+
* } catch (err) {
|
|
100
|
+
* if (err instanceof ContractError) {
|
|
101
|
+
* // Daemon returned an unexpected shape — SDK version mismatch?
|
|
102
|
+
* console.error('Contract violation:', err.message);
|
|
103
|
+
* }
|
|
104
|
+
* }
|
|
105
|
+
*/
|
|
46
106
|
export declare class ContractError extends GoodVibesSdkError {
|
|
47
107
|
constructor(message: string, options?: GoodVibesSdkErrorOptions);
|
|
48
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Thrown when the daemon returns a non-2xx HTTP status code.
|
|
111
|
+
*
|
|
112
|
+
* The `category` field is inferred from the status code:
|
|
113
|
+
* - `401` → `'authentication'` `402` → `'billing'` `403` → `'authorization'`
|
|
114
|
+
* - `404` → `'not_found'` `408` → `'timeout'` `429` → `'rate_limit'`
|
|
115
|
+
* - `5xx` → `'service'`
|
|
116
|
+
*
|
|
117
|
+
* Use `recoverable` to decide whether to retry, and `retryAfterMs` for
|
|
118
|
+
* the backoff hint on rate-limit responses.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* import { HttpStatusError } from '@pellux/goodvibes-sdk';
|
|
122
|
+
*
|
|
123
|
+
* try {
|
|
124
|
+
* await sdk.operator.agents.list();
|
|
125
|
+
* } catch (err) {
|
|
126
|
+
* if (err instanceof HttpStatusError) {
|
|
127
|
+
* if (err.category === 'rate_limit') {
|
|
128
|
+
* await delay(err.retryAfterMs ?? 1000);
|
|
129
|
+
* } else if (!err.recoverable) {
|
|
130
|
+
* throw err; // Surface non-retryable errors immediately
|
|
131
|
+
* }
|
|
132
|
+
* }
|
|
133
|
+
* }
|
|
134
|
+
*/
|
|
49
135
|
export declare class HttpStatusError extends GoodVibesSdkError {
|
|
50
136
|
constructor(message: string, options?: GoodVibesSdkErrorOptions);
|
|
51
137
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/_internal/errors/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,mBAAmB,EACnB,iBAAiB,EACjB,yBAAyB,EAC1B,MAAM,4BAA4B,CAAC;AAEpC,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,4BAA4B,CAAC;AAEpC,MAAM,MAAM,aAAa,GAAG,mBAAmB,GAAG,UAAU,CAAC;AAE7D,MAAM,MAAM,WAAW,GAAG,iBAAiB,GAAG,UAAU,CAAC;AAEzD,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAC;IAClC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC;IAC9B,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,C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,CAAC,EAAE,MAAM,CAAC;IACtC,SAAgB,YAAY,CAAC,EAAE,MAAM,CAAC;gBAE1B,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,wBAA6B;CAoBpE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,kBAAmB,SAAQ,iBAAiB;gBAC3C,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,wBAA6B;CASpE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,aAAc,SAAQ,iBAAiB;gBACtC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,wBAA6B;CASpE;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,eAAgB,SAAQ,iBAAiB;gBACxC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,wBAA6B;CAOpE;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,yBAAyB,CAE9F;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,GACZ,eAAe,CAgCjB"}
|
|
@@ -18,6 +18,29 @@ function inferCategory(status) {
|
|
|
18
18
|
return 'service';
|
|
19
19
|
return 'unknown';
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Base error class for all errors thrown by the GoodVibes SDK.
|
|
23
|
+
*
|
|
24
|
+
* Every error carries a structured `category` and `source` that allow
|
|
25
|
+
* callers to handle specific failure modes without string-matching messages.
|
|
26
|
+
*
|
|
27
|
+
* ### Narrowing pattern
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { GoodVibesSdkError, HttpStatusError, ConfigurationError } from '@pellux/goodvibes-sdk';
|
|
30
|
+
*
|
|
31
|
+
* try {
|
|
32
|
+
* await sdk.operator.agents.list();
|
|
33
|
+
* } catch (err) {
|
|
34
|
+
* if (err instanceof HttpStatusError && err.category === 'rate_limit') {
|
|
35
|
+
* // Back off and retry after err.retryAfterMs
|
|
36
|
+
* } else if (err instanceof ConfigurationError) {
|
|
37
|
+
* // Invalid SDK setup — not recoverable
|
|
38
|
+
* } else if (err instanceof GoodVibesSdkError) {
|
|
39
|
+
* console.error(err.category, err.hint);
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
21
44
|
export class GoodVibesSdkError extends Error {
|
|
22
45
|
code;
|
|
23
46
|
category;
|
|
@@ -56,6 +79,24 @@ export class GoodVibesSdkError extends Error {
|
|
|
56
79
|
this.retryAfterMs = options.retryAfterMs;
|
|
57
80
|
}
|
|
58
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Thrown when the SDK is misconfigured (e.g. missing `baseUrl`, no fetch
|
|
84
|
+
* implementation available, or calling a mutation on a read-only auth resolver).
|
|
85
|
+
*
|
|
86
|
+
* Always non-recoverable (`recoverable: false`).
|
|
87
|
+
* Category: `'config'`.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* import { ConfigurationError } from '@pellux/goodvibes-sdk';
|
|
91
|
+
*
|
|
92
|
+
* try {
|
|
93
|
+
* await sdk.auth.setToken('x');
|
|
94
|
+
* } catch (err) {
|
|
95
|
+
* if (err instanceof ConfigurationError) {
|
|
96
|
+
* // SDK was constructed with getAuthToken — token mutation not supported
|
|
97
|
+
* }
|
|
98
|
+
* }
|
|
99
|
+
*/
|
|
59
100
|
export class ConfigurationError extends GoodVibesSdkError {
|
|
60
101
|
constructor(message, options = {}) {
|
|
61
102
|
super(message, {
|
|
@@ -67,6 +108,25 @@ export class ConfigurationError extends GoodVibesSdkError {
|
|
|
67
108
|
});
|
|
68
109
|
}
|
|
69
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Thrown when a response from the daemon violates the expected contract
|
|
113
|
+
* (unexpected shape, missing required fields, etc.).
|
|
114
|
+
*
|
|
115
|
+
* Always non-recoverable (`recoverable: false`).
|
|
116
|
+
* Category: `'contract'`.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* import { ContractError } from '@pellux/goodvibes-sdk';
|
|
120
|
+
*
|
|
121
|
+
* try {
|
|
122
|
+
* const result = await sdk.operator.agents.get({ id: agentId });
|
|
123
|
+
* } catch (err) {
|
|
124
|
+
* if (err instanceof ContractError) {
|
|
125
|
+
* // Daemon returned an unexpected shape — SDK version mismatch?
|
|
126
|
+
* console.error('Contract violation:', err.message);
|
|
127
|
+
* }
|
|
128
|
+
* }
|
|
129
|
+
*/
|
|
70
130
|
export class ContractError extends GoodVibesSdkError {
|
|
71
131
|
constructor(message, options = {}) {
|
|
72
132
|
super(message, {
|
|
@@ -78,6 +138,32 @@ export class ContractError extends GoodVibesSdkError {
|
|
|
78
138
|
});
|
|
79
139
|
}
|
|
80
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Thrown when the daemon returns a non-2xx HTTP status code.
|
|
143
|
+
*
|
|
144
|
+
* The `category` field is inferred from the status code:
|
|
145
|
+
* - `401` → `'authentication'` `402` → `'billing'` `403` → `'authorization'`
|
|
146
|
+
* - `404` → `'not_found'` `408` → `'timeout'` `429` → `'rate_limit'`
|
|
147
|
+
* - `5xx` → `'service'`
|
|
148
|
+
*
|
|
149
|
+
* Use `recoverable` to decide whether to retry, and `retryAfterMs` for
|
|
150
|
+
* the backoff hint on rate-limit responses.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* import { HttpStatusError } from '@pellux/goodvibes-sdk';
|
|
154
|
+
*
|
|
155
|
+
* try {
|
|
156
|
+
* await sdk.operator.agents.list();
|
|
157
|
+
* } catch (err) {
|
|
158
|
+
* if (err instanceof HttpStatusError) {
|
|
159
|
+
* if (err.category === 'rate_limit') {
|
|
160
|
+
* await delay(err.retryAfterMs ?? 1000);
|
|
161
|
+
* } else if (!err.recoverable) {
|
|
162
|
+
* throw err; // Surface non-retryable errors immediately
|
|
163
|
+
* }
|
|
164
|
+
* }
|
|
165
|
+
* }
|
|
166
|
+
*/
|
|
81
167
|
export class HttpStatusError extends GoodVibesSdkError {
|
|
82
168
|
constructor(message, options = {}) {
|
|
83
169
|
super(message, {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
|
-
let version = '0.18.
|
|
3
|
+
let version = '0.18.49';
|
|
4
4
|
try {
|
|
5
5
|
const pkg = JSON.parse(readFileSync(join(import.meta.dir, '..', '..', 'package.json'), 'utf-8'));
|
|
6
6
|
version = pkg.version ?? version;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-core.d.ts","sourceRoot":"","sources":["../../../src/_internal/transport-http/http-core.ts"],"names":[],"mappings":"AAGA,OAAO,EAAsE,KAAK,iBAAiB,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAC5I,OAAO,EAKL,KAAK,eAAe,EACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAkC,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjF,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GACrC,SAAS,SAAS,EAAE,CAAC;AAEzB,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,CAAC;AAE/D,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACnC,QAAQ,CAAC,YAAY,CAAC,EAAE,iBAAiB,CAAC;IAC1C,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IAC9B,QAAQ,CAAC,SAAS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AAmBD,wBAAsB,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,CAQvE;AAED,wBAAsB,WAAW,CAAC,CAAC,EACjC,SAAS,EAAE,OAAO,KAAK,EACvB,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,WAAgB,GACrB,OAAO,CAAC,CAAC,CAAC,CAaZ;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,wBAAwB,GAAG,iBAAiB,CAqF5F"}
|
|
@@ -47,16 +47,24 @@ function readErrorMessage(status, url, body) {
|
|
|
47
47
|
}
|
|
48
48
|
return `Transport request failed with status ${status} for ${url}`;
|
|
49
49
|
}
|
|
50
|
-
function createTransportError(status, url, method, body) {
|
|
50
|
+
function createTransportError(status, url, method, body, retryAfterMs) {
|
|
51
51
|
return Object.assign(new Error(readErrorMessage(status, url, body)), {
|
|
52
52
|
transport: {
|
|
53
53
|
status,
|
|
54
54
|
body,
|
|
55
55
|
url,
|
|
56
56
|
method,
|
|
57
|
+
...(retryAfterMs !== undefined ? { retryAfterMs } : {}),
|
|
57
58
|
},
|
|
58
59
|
});
|
|
59
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Creates a transport error representing a network-level failure (no HTTP response received).
|
|
63
|
+
*
|
|
64
|
+
* Note: `Error.cause` (set via `Object.assign`) is the authoritative standard-compliant
|
|
65
|
+
* cause field. The inner `transport.cause` mirrors it for callers that inspect the raw
|
|
66
|
+
* transport payload — treat `Error.cause` as the source of truth.
|
|
67
|
+
*/
|
|
60
68
|
function createNetworkTransportError(error, url, method) {
|
|
61
69
|
const message = error instanceof Error && error.message.trim()
|
|
62
70
|
? error.message.trim()
|
|
@@ -68,6 +76,7 @@ function createNetworkTransportError(error, url, method) {
|
|
|
68
76
|
body: { error: message },
|
|
69
77
|
url,
|
|
70
78
|
method,
|
|
79
|
+
cause: error,
|
|
71
80
|
},
|
|
72
81
|
});
|
|
73
82
|
}
|
|
@@ -122,6 +131,23 @@ export function createFetch(fetchImpl, fallbackFetch) {
|
|
|
122
131
|
}
|
|
123
132
|
return resolved.bind(globalThis);
|
|
124
133
|
}
|
|
134
|
+
function parseRetryAfterMs(headers) {
|
|
135
|
+
const retryAfter = headers.get('retry-after');
|
|
136
|
+
if (!retryAfter)
|
|
137
|
+
return undefined;
|
|
138
|
+
// Numeric seconds
|
|
139
|
+
const seconds = Number(retryAfter);
|
|
140
|
+
if (!Number.isNaN(seconds) && seconds >= 0) {
|
|
141
|
+
return Math.ceil(seconds * 1000);
|
|
142
|
+
}
|
|
143
|
+
// HTTP-date
|
|
144
|
+
const date = new Date(retryAfter);
|
|
145
|
+
if (!Number.isNaN(date.getTime())) {
|
|
146
|
+
const ms = date.getTime() - Date.now();
|
|
147
|
+
return ms > 0 ? ms : 0;
|
|
148
|
+
}
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
125
151
|
export async function readJsonBody(response) {
|
|
126
152
|
const text = await response.text();
|
|
127
153
|
if (!text.trim())
|
|
@@ -143,7 +169,8 @@ export async function requestJson(fetchImpl, url, init = {}) {
|
|
|
143
169
|
}
|
|
144
170
|
const body = await readJsonBody(response);
|
|
145
171
|
if (!response.ok) {
|
|
146
|
-
|
|
172
|
+
const retryAfterMs = parseRetryAfterMs(response.headers);
|
|
173
|
+
throw createTransportError(response.status, url, init.method ?? 'GET', body, retryAfterMs);
|
|
147
174
|
}
|
|
148
175
|
return body;
|
|
149
176
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/_internal/transport-http/http.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACf,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,mBAAmB,EACnB,sBAAsB,EACtB,eAAe,EAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,uBAAuB,EAC5B,yBAAyB,EACzB,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,EACvB,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,KAAK,6BAA6B,EAClC,KAAK,qBAAqB,EAC1B,+BAA+B,EAC/B,uBAAuB,EACvB,8BAA8B,EAC/B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,WAAW,EAEX,cAAc,EACd,qBAAqB,EACrB,YAAY,EACZ,WAAW,EACX,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,uBAAuB,EAC5B,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAExB,YAAY,EACV,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,sBAAsB,EACtB,eAAe,EACf,UAAU,EACV,SAAS,EACT,YAAY,EACZ,qBAAqB,EACrB,uBAAuB,EACvB,uBAAuB,EACvB,6BAA6B,EAC7B,qBAAqB,EACrB,kBAAkB,GACnB,CAAC;AACF,MAAM,MAAM,oBAAoB,GAAG,wBAAwB,CAAC;AAC5D,MAAM,MAAM,aAAa,GAAG,iBAAiB,CAAC;AAC9C,OAAO,EACL,WAAW,EACX,cAAc,EACd,qBAAqB,EACrB,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,sBAAsB,EACtB,eAAe,EACf,yBAAyB,EACzB,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,EACvB,wBAAwB,EACxB,sBAAsB,EACtB,+BAA+B,EAC/B,uBAAuB,EACvB,8BAA8B,GAC/B,CAAC;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/_internal/transport-http/http.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,iB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ACrB,uBAAuB,EACvB,wBAAwB,EACxB,sBAAsB,EACtB,+BAA+B,EAC/B,uBAAuB,EACvB,8BAA8B,GAC/B,CAAC;AA2CF,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAiD7D;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAmBhF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Synced from packages/transport-http/src/http.ts
|
|
2
|
-
import { ConfigurationError, ContractError, createHttpStatusError } from '../errors/index.js';
|
|
2
|
+
import { ConfigurationError, ContractError, HttpStatusError, createHttpStatusError } from '../errors/index.js';
|
|
3
3
|
import { mergeHeaders, resolveAuthToken, resolveHeaders, } from './auth.js';
|
|
4
4
|
import { computeBackoffDelay, normalizeBackoffPolicy, sleepWithSignal, } from './backoff.js';
|
|
5
5
|
import { DEFAULT_HTTP_RETRY_POLICY, getHttpRetryDelay, isRetryableHttpStatus, isRetryableNetworkError, normalizeHttpRetryPolicy, resolveHttpRetryPolicy, } from './retry.js';
|
|
@@ -14,9 +14,57 @@ function isTransportError(error) {
|
|
|
14
14
|
&& typeof error.transport.status === 'number'
|
|
15
15
|
&& typeof error.transport.url === 'string');
|
|
16
16
|
}
|
|
17
|
+
function inferTransportHint(status, url, retryAfterMs) {
|
|
18
|
+
if (status === 0)
|
|
19
|
+
return `Transport could not reach ${url}. Verify the baseUrl is reachable.`;
|
|
20
|
+
if (status === 401)
|
|
21
|
+
return 'Check your authentication token or credentials.';
|
|
22
|
+
if (status === 403)
|
|
23
|
+
return 'Valid credentials but insufficient permissions for this operation.';
|
|
24
|
+
if (status === 404)
|
|
25
|
+
return 'The requested resource was not found.';
|
|
26
|
+
if (status === 408)
|
|
27
|
+
return 'The request timed out. Consider retrying.';
|
|
28
|
+
if (status === 429) {
|
|
29
|
+
return retryAfterMs !== undefined
|
|
30
|
+
? `Rate limit exceeded. Retry after ${retryAfterMs}ms.`
|
|
31
|
+
: 'Rate limit exceeded. Back off and retry.';
|
|
32
|
+
}
|
|
33
|
+
if (status >= 500)
|
|
34
|
+
return 'Remote server error. The service may be temporarily unavailable.';
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
17
37
|
export function normalizeTransportError(error) {
|
|
18
38
|
if (isTransportError(error)) {
|
|
19
|
-
|
|
39
|
+
const { status, url, body, method, retryAfterMs, cause } = error.transport;
|
|
40
|
+
const resolvedMethod = typeof method === 'string' ? method : 'GET';
|
|
41
|
+
const hint = inferTransportHint(status, url, retryAfterMs);
|
|
42
|
+
if (status === 0) {
|
|
43
|
+
// Network-level failure: no HTTP response received
|
|
44
|
+
const networkError = new HttpStatusError(error instanceof Error ? error.message : `Transport could not reach ${url}`, {
|
|
45
|
+
status: undefined,
|
|
46
|
+
url,
|
|
47
|
+
method: resolvedMethod,
|
|
48
|
+
body,
|
|
49
|
+
category: 'network',
|
|
50
|
+
source: 'transport',
|
|
51
|
+
recoverable: true,
|
|
52
|
+
hint,
|
|
53
|
+
...(retryAfterMs !== undefined ? { retryAfterMs } : {}),
|
|
54
|
+
});
|
|
55
|
+
if (cause !== undefined) {
|
|
56
|
+
Object.defineProperty(networkError, 'cause', { value: cause, writable: true, configurable: true });
|
|
57
|
+
}
|
|
58
|
+
return Object.assign(networkError, { transport: error.transport });
|
|
59
|
+
}
|
|
60
|
+
const baseError = createHttpStatusError(status, url, resolvedMethod, body);
|
|
61
|
+
// Only apply inferred hint if the daemon body didn't supply one already
|
|
62
|
+
const effectiveHint = baseError.hint ?? hint;
|
|
63
|
+
return Object.assign(baseError, {
|
|
64
|
+
transport: error.transport,
|
|
65
|
+
...(effectiveHint !== undefined ? { hint: effectiveHint } : {}),
|
|
66
|
+
...(retryAfterMs !== undefined ? { retryAfterMs } : {}),
|
|
67
|
+
});
|
|
20
68
|
}
|
|
21
69
|
if (error instanceof Error) {
|
|
22
70
|
if (error.message === 'Fetch implementation is required' || error.message === 'Transport baseUrl is required') {
|
package/dist/auth.d.ts
CHANGED
|
@@ -24,7 +24,56 @@ export interface GoodVibesAuthClient {
|
|
|
24
24
|
setToken(token: string | null): Promise<void>;
|
|
25
25
|
clearToken(): Promise<void>;
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Create a simple in-memory token store.
|
|
29
|
+
*
|
|
30
|
+
* The token is held in a closure variable — it does not survive page
|
|
31
|
+
* refreshes or process restarts. Suitable for server-side scripts and tests.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* import { createMemoryTokenStore } from '@pellux/goodvibes-sdk';
|
|
35
|
+
*
|
|
36
|
+
* const store = createMemoryTokenStore('initial-token');
|
|
37
|
+
* const sdk = createGoodVibesSdk({ baseUrl: '...', tokenStore: store });
|
|
38
|
+
* await sdk.auth.clearToken(); // clears only in-memory
|
|
39
|
+
*/
|
|
27
40
|
export declare function createMemoryTokenStore(initialToken?: string | null): GoodVibesTokenStore;
|
|
41
|
+
/**
|
|
42
|
+
* Create a token store backed by `localStorage` (or a custom `Storage`).
|
|
43
|
+
*
|
|
44
|
+
* The token is persisted across page refreshes under the key
|
|
45
|
+
* `'goodvibes.token'` (overridable via `options.key`).
|
|
46
|
+
* Pass `options.storage` to use `sessionStorage` or a custom adapter.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* import { createBrowserTokenStore, createBrowserGoodVibesSdk } from '@pellux/goodvibes-sdk/browser';
|
|
50
|
+
*
|
|
51
|
+
* const tokenStore = createBrowserTokenStore({ storage: sessionStorage });
|
|
52
|
+
* const sdk = createBrowserGoodVibesSdk({ tokenStore });
|
|
53
|
+
* await sdk.auth.login({ username: 'alice', password: 's3cr3t' });
|
|
54
|
+
* // token is now stored in sessionStorage
|
|
55
|
+
*/
|
|
28
56
|
export declare function createBrowserTokenStore(options?: BrowserTokenStoreOptions): GoodVibesTokenStore;
|
|
57
|
+
/**
|
|
58
|
+
* Create the auth client attached to an SDK instance.
|
|
59
|
+
*
|
|
60
|
+
* Normally called internally by `createGoodVibesSdk`. Access the result via
|
|
61
|
+
* `sdk.auth`.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* import { createGoodVibesSdk, createBrowserTokenStore } from '@pellux/goodvibes-sdk';
|
|
65
|
+
*
|
|
66
|
+
* const sdk = createGoodVibesSdk({
|
|
67
|
+
* baseUrl: 'https://daemon.example.com',
|
|
68
|
+
* tokenStore: createBrowserTokenStore(),
|
|
69
|
+
* });
|
|
70
|
+
*
|
|
71
|
+
* // Login and persist the token automatically:
|
|
72
|
+
* const { token } = await sdk.auth.login({ username: 'alice', password: 's3cr3t' });
|
|
73
|
+
* console.log('logged in, token stored:', token.slice(0, 8) + '...');
|
|
74
|
+
*
|
|
75
|
+
* // Later: clear the session
|
|
76
|
+
* await sdk.auth.clearToken();
|
|
77
|
+
*/
|
|
29
78
|
export declare function createGoodVibesAuthClient(operator: OperatorSdk, tokenStore: GoodVibesTokenStore | null, getAuthToken?: AuthTokenResolver): GoodVibesAuthClient;
|
|
30
79
|
//# sourceMappingURL=auth.d.ts.map
|
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AAC7E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAEjE,MAAM,MAAM,oBAAoB,GAAG,oBAAoB,CAAC,sBAAsB,CAAC,CAAC;AAChF,MAAM,MAAM,mBAAmB,GAAG,mBAAmB,CAAC,oBAAoB,CAAC,CAAC;AAC5E,MAAM,MAAM,oBAAoB,GAAG,oBAAoB,CAAC,oBAAoB,CAAC,CAAC;AAE9E,MAAM,WAAW,mBAAmB;IAClC,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,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AG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B;AAYD;;;;;;;;;;;;GAYG;AACH,wBAAgB,sBAAsB,CAAC,YAAY,GAAE,MAAM,GAAG,IAAW,GAAG,mBAAmB,CAa9F;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,GAAE,wBAA6B,GAAG,mBAAmB,CAmBnG;AAwBD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,WAAW,EACrB,UAAU,EAAE,mBAAmB,GAAG,IAAI,EACtC,YAAY,CAAC,EAAE,iBAAiB,GAC/B,mBAAmB,CA0BrB"}
|
package/dist/auth.js
CHANGED
|
@@ -6,6 +6,19 @@ function requireStorage(storage) {
|
|
|
6
6
|
}
|
|
7
7
|
return resolved;
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Create a simple in-memory token store.
|
|
11
|
+
*
|
|
12
|
+
* The token is held in a closure variable — it does not survive page
|
|
13
|
+
* refreshes or process restarts. Suitable for server-side scripts and tests.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* import { createMemoryTokenStore } from '@pellux/goodvibes-sdk';
|
|
17
|
+
*
|
|
18
|
+
* const store = createMemoryTokenStore('initial-token');
|
|
19
|
+
* const sdk = createGoodVibesSdk({ baseUrl: '...', tokenStore: store });
|
|
20
|
+
* await sdk.auth.clearToken(); // clears only in-memory
|
|
21
|
+
*/
|
|
9
22
|
export function createMemoryTokenStore(initialToken = null) {
|
|
10
23
|
let token = initialToken;
|
|
11
24
|
return {
|
|
@@ -20,6 +33,21 @@ export function createMemoryTokenStore(initialToken = null) {
|
|
|
20
33
|
},
|
|
21
34
|
};
|
|
22
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Create a token store backed by `localStorage` (or a custom `Storage`).
|
|
38
|
+
*
|
|
39
|
+
* The token is persisted across page refreshes under the key
|
|
40
|
+
* `'goodvibes.token'` (overridable via `options.key`).
|
|
41
|
+
* Pass `options.storage` to use `sessionStorage` or a custom adapter.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* import { createBrowserTokenStore, createBrowserGoodVibesSdk } from '@pellux/goodvibes-sdk/browser';
|
|
45
|
+
*
|
|
46
|
+
* const tokenStore = createBrowserTokenStore({ storage: sessionStorage });
|
|
47
|
+
* const sdk = createBrowserGoodVibesSdk({ tokenStore });
|
|
48
|
+
* await sdk.auth.login({ username: 'alice', password: 's3cr3t' });
|
|
49
|
+
* // token is now stored in sessionStorage
|
|
50
|
+
*/
|
|
23
51
|
export function createBrowserTokenStore(options = {}) {
|
|
24
52
|
const storage = requireStorage(options.storage);
|
|
25
53
|
const key = options.key?.trim() || 'goodvibes.token';
|
|
@@ -55,6 +83,27 @@ function assertWritableTokenStore(tokenStore) {
|
|
|
55
83
|
}
|
|
56
84
|
return tokenStore;
|
|
57
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Create the auth client attached to an SDK instance.
|
|
88
|
+
*
|
|
89
|
+
* Normally called internally by `createGoodVibesSdk`. Access the result via
|
|
90
|
+
* `sdk.auth`.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* import { createGoodVibesSdk, createBrowserTokenStore } from '@pellux/goodvibes-sdk';
|
|
94
|
+
*
|
|
95
|
+
* const sdk = createGoodVibesSdk({
|
|
96
|
+
* baseUrl: 'https://daemon.example.com',
|
|
97
|
+
* tokenStore: createBrowserTokenStore(),
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* // Login and persist the token automatically:
|
|
101
|
+
* const { token } = await sdk.auth.login({ username: 'alice', password: 's3cr3t' });
|
|
102
|
+
* console.log('logged in, token stored:', token.slice(0, 8) + '...');
|
|
103
|
+
*
|
|
104
|
+
* // Later: clear the session
|
|
105
|
+
* await sdk.auth.clearToken();
|
|
106
|
+
*/
|
|
58
107
|
export function createGoodVibesAuthClient(operator, tokenStore, getAuthToken) {
|
|
59
108
|
return {
|
|
60
109
|
writable: tokenStore !== null,
|
package/dist/browser.d.ts
CHANGED
|
@@ -4,5 +4,28 @@ export interface BrowserGoodVibesSdkOptions extends Omit<GoodVibesSdkOptions, 'b
|
|
|
4
4
|
readonly fetch?: typeof fetch;
|
|
5
5
|
readonly WebSocketImpl?: typeof WebSocket;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Create a GoodVibes SDK instance for browser environments.
|
|
9
|
+
*
|
|
10
|
+
* Differences from `createGoodVibesSdk`:
|
|
11
|
+
* - `baseUrl` defaults to `location.origin` when omitted.
|
|
12
|
+
* - HTTP retry and realtime reconnect are pre-configured with
|
|
13
|
+
* browser-appropriate defaults.
|
|
14
|
+
* - Relies on the native browser `fetch` and `WebSocket` globals; pass
|
|
15
|
+
* `options.fetch` / `options.WebSocketImpl` to override.
|
|
16
|
+
*
|
|
17
|
+
* `createWebGoodVibesSdk` is an alias for this function — use whichever name
|
|
18
|
+
* reads more naturally in your project.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Example only: baseUrl defaults to location.origin in a real browser app.
|
|
22
|
+
* import { createBrowserGoodVibesSdk } from '@pellux/goodvibes-sdk/browser';
|
|
23
|
+
*
|
|
24
|
+
* const sdk = createBrowserGoodVibesSdk({
|
|
25
|
+
* authToken: sessionStorage.getItem('gv-token') ?? undefined,
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* const agents = await sdk.operator.agents.list();
|
|
29
|
+
*/
|
|
7
30
|
export declare function createBrowserGoodVibesSdk(options?: BrowserGoodVibesSdkOptions): GoodVibesSdk;
|
|
8
31
|
//# sourceMappingURL=browser.d.ts.map
|
package/dist/browser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,YAAY,EAClB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,0BACf,SAAQ,IAAI,CAAC,mBAAmB,EAAE,SAAS,GAAG,OAAO,GAAG,eAAe,CAAC;IACxE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IAC9B,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,SAAS,CAAC;CAC3C;AAaD,wBAAgB,yBAAyB,CACvC,OAAO,GAAE,0BAA+B,GACvC,YAAY,CAiCd"}
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,YAAY,EAClB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,0BACf,SAAQ,IAAI,CAAC,mBAAmB,EAAE,SAAS,GAAG,OAAO,GAAG,eAAe,CAAC;IACxE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IAC9B,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,SAAS,CAAC;CAC3C;AAaD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,GAAE,0BAA+B,GACvC,YAAY,CAiCd"}
|
package/dist/browser.js
CHANGED
|
@@ -9,6 +9,29 @@ function resolveBrowserBaseUrl(baseUrl) {
|
|
|
9
9
|
}
|
|
10
10
|
throw new ConfigurationError('Browser baseUrl is required when location.origin is unavailable.');
|
|
11
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Create a GoodVibes SDK instance for browser environments.
|
|
14
|
+
*
|
|
15
|
+
* Differences from `createGoodVibesSdk`:
|
|
16
|
+
* - `baseUrl` defaults to `location.origin` when omitted.
|
|
17
|
+
* - HTTP retry and realtime reconnect are pre-configured with
|
|
18
|
+
* browser-appropriate defaults.
|
|
19
|
+
* - Relies on the native browser `fetch` and `WebSocket` globals; pass
|
|
20
|
+
* `options.fetch` / `options.WebSocketImpl` to override.
|
|
21
|
+
*
|
|
22
|
+
* `createWebGoodVibesSdk` is an alias for this function — use whichever name
|
|
23
|
+
* reads more naturally in your project.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Example only: baseUrl defaults to location.origin in a real browser app.
|
|
27
|
+
* import { createBrowserGoodVibesSdk } from '@pellux/goodvibes-sdk/browser';
|
|
28
|
+
*
|
|
29
|
+
* const sdk = createBrowserGoodVibesSdk({
|
|
30
|
+
* authToken: sessionStorage.getItem('gv-token') ?? undefined,
|
|
31
|
+
* });
|
|
32
|
+
*
|
|
33
|
+
* const agents = await sdk.operator.agents.list();
|
|
34
|
+
*/
|
|
12
35
|
export function createBrowserGoodVibesSdk(options = {}) {
|
|
13
36
|
return createGoodVibesSdk({
|
|
14
37
|
baseUrl: resolveBrowserBaseUrl(options.baseUrl),
|
package/dist/client.d.ts
CHANGED
|
@@ -22,32 +22,140 @@ import { type GoodVibesAuthClient, type GoodVibesTokenStore } from './auth.js';
|
|
|
22
22
|
* @see AnyRuntimeEvent for the full discriminated union type.
|
|
23
23
|
*/
|
|
24
24
|
export type RuntimeEventRecord = AnyRuntimeEvent;
|
|
25
|
+
/**
|
|
26
|
+
* Options for constructing a GoodVibes SDK instance.
|
|
27
|
+
*
|
|
28
|
+
* ### Auth token precedence (highest → lowest)
|
|
29
|
+
* 1. **`tokenStore`** — when present, `getToken()` is called on every request.
|
|
30
|
+
* Mutations (`login`, `setToken`, `clearToken`) persist back to the store.
|
|
31
|
+
* 2. **`getAuthToken`** — a read-only async resolver. No persistence; mutations
|
|
32
|
+
* throw `ConfigurationError`.
|
|
33
|
+
* 3. **`authToken`** — a static string (or `null`). Wrapped in a
|
|
34
|
+
* `createMemoryTokenStore` internally so mutations work in-process.
|
|
35
|
+
*
|
|
36
|
+
* Only provide one of the three. If none are supplied the SDK operates without
|
|
37
|
+
* credentials (useful for public endpoints).
|
|
38
|
+
*/
|
|
25
39
|
export interface GoodVibesSdkOptions {
|
|
40
|
+
/**
|
|
41
|
+
* Base URL of the GoodVibes daemon, e.g. `'https://my-daemon.example.com'`.
|
|
42
|
+
* Must be a non-empty string. A trailing slash is trimmed automatically.
|
|
43
|
+
*/
|
|
26
44
|
readonly baseUrl: string;
|
|
45
|
+
/**
|
|
46
|
+
* Static auth token string. Internally wrapped in an in-memory token store,
|
|
47
|
+
* so `sdk.auth.setToken()` / `sdk.auth.clearToken()` work.
|
|
48
|
+
*
|
|
49
|
+
* Lowest-precedence auth option — ignored when `tokenStore` or `getAuthToken`
|
|
50
|
+
* is also provided.
|
|
51
|
+
*/
|
|
27
52
|
readonly authToken?: string | null;
|
|
53
|
+
/**
|
|
54
|
+
* Async token resolver called before every authenticated request.
|
|
55
|
+
* Use this when your token lives outside the SDK (e.g. retrieved from a
|
|
56
|
+
* framework session or an external secret store).
|
|
57
|
+
*
|
|
58
|
+
* When this option is set, `sdk.auth.writable` is `false` — calling
|
|
59
|
+
* `setToken` / `clearToken` throws a `ConfigurationError`.
|
|
60
|
+
*
|
|
61
|
+
* Takes precedence over `authToken`; ignored when `tokenStore` is provided.
|
|
62
|
+
*/
|
|
28
63
|
readonly getAuthToken?: AuthTokenResolver;
|
|
64
|
+
/**
|
|
65
|
+
* A mutable token store implementing `getToken / setToken / clearToken`.
|
|
66
|
+
* The SDK calls `getToken()` before every request and writes back via
|
|
67
|
+
* `setToken()` after a successful `sdk.auth.login()`.
|
|
68
|
+
*
|
|
69
|
+
* Highest-precedence auth option — overrides both `getAuthToken` and
|
|
70
|
+
* `authToken`. Use `createBrowserTokenStore()` (localStorage) or
|
|
71
|
+
* `createMemoryTokenStore()` for common cases.
|
|
72
|
+
*/
|
|
29
73
|
readonly tokenStore?: GoodVibesTokenStore;
|
|
74
|
+
/**
|
|
75
|
+
* Custom `fetch` implementation. Falls back to `globalThis.fetch`.
|
|
76
|
+
* Required in environments without a native fetch (e.g. older Node.js).
|
|
77
|
+
*/
|
|
30
78
|
readonly fetch?: typeof fetch;
|
|
79
|
+
/**
|
|
80
|
+
* Static extra headers sent on every request, e.g.
|
|
81
|
+
* `{ 'X-Tenant-Id': 'acme' }`.
|
|
82
|
+
*/
|
|
31
83
|
readonly headers?: HeadersInit;
|
|
84
|
+
/**
|
|
85
|
+
* Async resolver for per-request headers. Called on each request after the
|
|
86
|
+
* auth header is set. Useful for adding request-scoped tracing headers.
|
|
87
|
+
*/
|
|
32
88
|
readonly getHeaders?: HeaderResolver;
|
|
89
|
+
/**
|
|
90
|
+
* HTTP retry policy for transient failures (408, 429, 5xx).
|
|
91
|
+
* Runtime-specific factories (e.g. `createNodeGoodVibesSdk`) apply
|
|
92
|
+
* sensible defaults; pass this to override.
|
|
93
|
+
*/
|
|
33
94
|
readonly retry?: HttpRetryPolicy;
|
|
95
|
+
/**
|
|
96
|
+
* Custom `WebSocket` constructor. Falls back to `globalThis.WebSocket`.
|
|
97
|
+
* Required in Node.js < 21 or when using a polyfill.
|
|
98
|
+
*/
|
|
34
99
|
readonly WebSocketImpl?: typeof WebSocket;
|
|
100
|
+
/**
|
|
101
|
+
* Options that control realtime transport behaviour (SSE and WebSocket
|
|
102
|
+
* reconnect policies, error callback).
|
|
103
|
+
*/
|
|
35
104
|
readonly realtime?: GoodVibesRealtimeOptions;
|
|
36
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Options controlling realtime transport behaviour.
|
|
108
|
+
*/
|
|
37
109
|
export interface GoodVibesRealtimeOptions {
|
|
38
110
|
readonly sseReconnect?: StreamReconnectPolicy;
|
|
39
111
|
readonly webSocketReconnect?: StreamReconnectPolicy;
|
|
40
112
|
readonly onError?: (error: unknown) => void;
|
|
41
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Realtime event subscriptions for the GoodVibes daemon.
|
|
116
|
+
* Choose SSE for read-only event streams or WebSocket for bidirectional use.
|
|
117
|
+
*/
|
|
42
118
|
export interface GoodVibesRealtime {
|
|
43
119
|
viaSse(): RemoteRuntimeEvents<RuntimeEventRecord>;
|
|
44
120
|
viaWebSocket(webSocketImpl?: typeof WebSocket): RemoteRuntimeEvents<RuntimeEventRecord>;
|
|
45
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* The GoodVibes SDK instance returned by `createGoodVibesSdk` (and its
|
|
124
|
+
* runtime-specific wrappers).
|
|
125
|
+
*
|
|
126
|
+
* Three primary namespaces:
|
|
127
|
+
* - **`operator`** — full control-plane API (daemon admin, agent management,
|
|
128
|
+
* session lifecycle, config). Requires an operator-level auth token.
|
|
129
|
+
* - **`peer`** — peer-to-peer and collaboration APIs (pairing, channels,
|
|
130
|
+
* shared sessions). May be used with peer-scoped tokens.
|
|
131
|
+
* - **`realtime`** — subscribe to live daemon events via SSE or WebSocket.
|
|
132
|
+
* - **`auth`** — login, logout, and token management helpers.
|
|
133
|
+
*/
|
|
46
134
|
export interface GoodVibesSdk {
|
|
47
135
|
readonly operator: OperatorSdk;
|
|
48
136
|
readonly peer: PeerSdk;
|
|
49
137
|
readonly auth: GoodVibesAuthClient;
|
|
50
138
|
readonly realtime: GoodVibesRealtime;
|
|
51
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Create a GoodVibes SDK instance.
|
|
142
|
+
*
|
|
143
|
+
* This is the runtime-agnostic constructor. For environments with sensible
|
|
144
|
+
* defaults already configured, prefer the platform-specific wrappers:
|
|
145
|
+
* `createNodeGoodVibesSdk`, `createBrowserGoodVibesSdk`,
|
|
146
|
+
* `createReactNativeGoodVibesSdk`.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* // Example only: replace baseUrl and authToken with your own values.
|
|
150
|
+
* import { createGoodVibesSdk } from '@pellux/goodvibes-sdk';
|
|
151
|
+
*
|
|
152
|
+
* const sdk = createGoodVibesSdk({
|
|
153
|
+
* baseUrl: 'https://daemon.example.com',
|
|
154
|
+
* authToken: process.env.GV_TOKEN,
|
|
155
|
+
* });
|
|
156
|
+
*
|
|
157
|
+
* const agents = await sdk.operator.agents.list();
|
|
158
|
+
* console.log(agents);
|
|
159
|
+
*/
|
|
52
160
|
export declare function createGoodVibesSdk(options: GoodVibesSdkOptions): GoodVibesSdk;
|
|
53
161
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,WAAW,EAEjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAEL,KAAK,OAAO,EAEb,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,qBAAqB,EACtB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAIL,KAAK,mBAAmB,EACzB,MAAM,yCAAyC,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8CAA8C,CAAC;AACpF,OAAO,EAGL,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACzB,MAAM,WAAW,CAAC;AAEnB;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAEjD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,WAAW,EAEjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAEL,KAAK,OAAO,EAEb,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,qBAAqB,EACtB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAIL,KAAK,mBAAmB,EACzB,MAAM,yCAAyC,CAAC;AACjD,OAAO,KAAK,E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BAAkB,CAAC,CAAC;IAClD,YAAY,CAAC,aAAa,CAAC,EAAE,OAAO,SAAS,GAAG,mBAAmB,CAAC,kBAAkB,CAAC,CAAC;CACzF;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;IACnC,QAAQ,CAAC,QAAQ,EAAE,iBAAiB,CAAC;CACtC;AA4DD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,mBAAmB,GAC3B,YAAY,CA+Cd"}
|
package/dist/client.js
CHANGED
|
@@ -53,6 +53,26 @@ function createPeerOptions(options) {
|
|
|
53
53
|
...(options.retry ? { retry: options.retry } : {}),
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Create a GoodVibes SDK instance.
|
|
58
|
+
*
|
|
59
|
+
* This is the runtime-agnostic constructor. For environments with sensible
|
|
60
|
+
* defaults already configured, prefer the platform-specific wrappers:
|
|
61
|
+
* `createNodeGoodVibesSdk`, `createBrowserGoodVibesSdk`,
|
|
62
|
+
* `createReactNativeGoodVibesSdk`.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* // Example only: replace baseUrl and authToken with your own values.
|
|
66
|
+
* import { createGoodVibesSdk } from '@pellux/goodvibes-sdk';
|
|
67
|
+
*
|
|
68
|
+
* const sdk = createGoodVibesSdk({
|
|
69
|
+
* baseUrl: 'https://daemon.example.com',
|
|
70
|
+
* authToken: process.env.GV_TOKEN,
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* const agents = await sdk.operator.agents.list();
|
|
74
|
+
* console.log(agents);
|
|
75
|
+
*/
|
|
56
76
|
export function createGoodVibesSdk(options) {
|
|
57
77
|
const baseUrl = requireBaseUrl(options.baseUrl);
|
|
58
78
|
const tokenStore = options.tokenStore ?? (options.getAuthToken ? null : createMemoryTokenStore(options.authToken ?? null));
|
package/dist/expo.d.ts
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import { type ReactNativeGoodVibesSdk, type ReactNativeGoodVibesSdkOptions } from './react-native.js';
|
|
2
2
|
export interface ExpoGoodVibesSdkOptions extends ReactNativeGoodVibesSdkOptions {
|
|
3
3
|
}
|
|
4
|
+
/**
|
|
5
|
+
* Alias for `createReactNativeGoodVibesSdk`. Use this entry-point when
|
|
6
|
+
* importing from `@pellux/goodvibes-sdk/expo`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* // Example only: uses expo-secure-store; replace with your own storage.
|
|
10
|
+
* import { createExpoGoodVibesSdk } from '@pellux/goodvibes-sdk/expo';
|
|
11
|
+
* import * as SecureStore from 'expo-secure-store';
|
|
12
|
+
*
|
|
13
|
+
* const sdk = createExpoGoodVibesSdk({
|
|
14
|
+
* baseUrl: process.env.EXPO_PUBLIC_GV_URL!,
|
|
15
|
+
* authToken: await SecureStore.getItemAsync('gv-token'),
|
|
16
|
+
* });
|
|
17
|
+
*/
|
|
4
18
|
export declare function createExpoGoodVibesSdk(options: ExpoGoodVibesSdkOptions): ReactNativeGoodVibesSdk;
|
|
5
19
|
//# sourceMappingURL=expo.d.ts.map
|
package/dist/expo.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expo.d.ts","sourceRoot":"","sources":["../src/expo.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,uBAAuB,EAC5B,KAAK,8BAA8B,EACpC,MAAM,mBAAmB,CAAC;AAE3B,MAAM,WAAW,uBAAwB,SAAQ,8BAA8B;CAAG;AAElF,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,uBAAuB,CAEhG"}
|
|
1
|
+
{"version":3,"file":"expo.d.ts","sourceRoot":"","sources":["../src/expo.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,uBAAuB,EAC5B,KAAK,8BAA8B,EACpC,MAAM,mBAAmB,CAAC;AAE3B,MAAM,WAAW,uBAAwB,SAAQ,8BAA8B;CAAG;AAElF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,uBAAuB,CAEhG"}
|
package/dist/expo.js
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import { createReactNativeGoodVibesSdk, } from './react-native.js';
|
|
2
|
+
/**
|
|
3
|
+
* Alias for `createReactNativeGoodVibesSdk`. Use this entry-point when
|
|
4
|
+
* importing from `@pellux/goodvibes-sdk/expo`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // Example only: uses expo-secure-store; replace with your own storage.
|
|
8
|
+
* import { createExpoGoodVibesSdk } from '@pellux/goodvibes-sdk/expo';
|
|
9
|
+
* import * as SecureStore from 'expo-secure-store';
|
|
10
|
+
*
|
|
11
|
+
* const sdk = createExpoGoodVibesSdk({
|
|
12
|
+
* baseUrl: process.env.EXPO_PUBLIC_GV_URL!,
|
|
13
|
+
* authToken: await SecureStore.getItemAsync('gv-token'),
|
|
14
|
+
* });
|
|
15
|
+
*/
|
|
2
16
|
export function createExpoGoodVibesSdk(options) {
|
|
3
17
|
return createReactNativeGoodVibesSdk(options);
|
|
4
18
|
}
|
package/dist/node.d.ts
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
import { type GoodVibesSdkOptions, type GoodVibesSdk } from './client.js';
|
|
2
2
|
export interface NodeGoodVibesSdkOptions extends GoodVibesSdkOptions {
|
|
3
3
|
}
|
|
4
|
+
/**
|
|
5
|
+
* Create a GoodVibes SDK instance configured for Node.js.
|
|
6
|
+
*
|
|
7
|
+
* Applies Node-friendly defaults on top of `createGoodVibesSdk`:
|
|
8
|
+
* - HTTP retry: 3 attempts, 200 ms base delay, 2 s max.
|
|
9
|
+
* - SSE and WebSocket reconnect enabled (500 ms base, 5 s max).
|
|
10
|
+
*
|
|
11
|
+
* Uses `globalThis.fetch` (available in Node 18+). For older runtimes pass
|
|
12
|
+
* `options.fetch` explicitly.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* // Example only: replace baseUrl and authToken with your own values.
|
|
16
|
+
* import { createNodeGoodVibesSdk } from '@pellux/goodvibes-sdk/node';
|
|
17
|
+
*
|
|
18
|
+
* const sdk = createNodeGoodVibesSdk({
|
|
19
|
+
* baseUrl: process.env.GV_BASE_URL!,
|
|
20
|
+
* authToken: process.env.GV_TOKEN,
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* const session = await sdk.operator.sessions.create({ name: 'my-session' });
|
|
24
|
+
* console.log(session.id);
|
|
25
|
+
*/
|
|
4
26
|
export declare function createNodeGoodVibesSdk(options: NodeGoodVibesSdkOptions): GoodVibesSdk;
|
|
5
27
|
//# sourceMappingURL=node.d.ts.map
|
package/dist/node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,YAAY,EAClB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,uBAAwB,SAAQ,mBAAmB;CAAG;AAEvE,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,uBAAuB,GAC/B,YAAY,CAwBd"}
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,YAAY,EAClB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,uBAAwB,SAAQ,mBAAmB;CAAG;AAEvE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,uBAAuB,GAC/B,YAAY,CAwBd"}
|
package/dist/node.js
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
import { createGoodVibesSdk, } from './client.js';
|
|
2
|
+
/**
|
|
3
|
+
* Create a GoodVibes SDK instance configured for Node.js.
|
|
4
|
+
*
|
|
5
|
+
* Applies Node-friendly defaults on top of `createGoodVibesSdk`:
|
|
6
|
+
* - HTTP retry: 3 attempts, 200 ms base delay, 2 s max.
|
|
7
|
+
* - SSE and WebSocket reconnect enabled (500 ms base, 5 s max).
|
|
8
|
+
*
|
|
9
|
+
* Uses `globalThis.fetch` (available in Node 18+). For older runtimes pass
|
|
10
|
+
* `options.fetch` explicitly.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Example only: replace baseUrl and authToken with your own values.
|
|
14
|
+
* import { createNodeGoodVibesSdk } from '@pellux/goodvibes-sdk/node';
|
|
15
|
+
*
|
|
16
|
+
* const sdk = createNodeGoodVibesSdk({
|
|
17
|
+
* baseUrl: process.env.GV_BASE_URL!,
|
|
18
|
+
* authToken: process.env.GV_TOKEN,
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* const session = await sdk.operator.sessions.create({ name: 'my-session' });
|
|
22
|
+
* console.log(session.id);
|
|
23
|
+
*/
|
|
2
24
|
export function createNodeGoodVibesSdk(options) {
|
|
3
25
|
return createGoodVibesSdk({
|
|
4
26
|
...options,
|
package/dist/react-native.d.ts
CHANGED
|
@@ -10,5 +10,31 @@ export interface ReactNativeGoodVibesRealtime {
|
|
|
10
10
|
export type ReactNativeGoodVibesSdk = Omit<GoodVibesSdk, 'realtime'> & {
|
|
11
11
|
readonly realtime: ReactNativeGoodVibesRealtime;
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Create a GoodVibes SDK instance for React Native.
|
|
15
|
+
*
|
|
16
|
+
* Key differences from the browser factory:
|
|
17
|
+
* - Realtime is WebSocket-only (`realtime.runtime()` / `realtime.viaWebSocket()`).
|
|
18
|
+
* SSE is not available in React Native.
|
|
19
|
+
* - Requires a `WebSocket` implementation (e.g. the global provided by the
|
|
20
|
+
* React Native runtime or the `react-native` package). Pass
|
|
21
|
+
* `options.WebSocketImpl` when the global is not available.
|
|
22
|
+
* - Returns `ReactNativeGoodVibesSdk` (extends `GoodVibesSdk` with a
|
|
23
|
+
* React-Native-specific `realtime` namespace).
|
|
24
|
+
*
|
|
25
|
+
* `createExpoGoodVibesSdk` is an alias for this function.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // Example only: replace baseUrl and authToken with your own values.
|
|
29
|
+
* import { createReactNativeGoodVibesSdk } from '@pellux/goodvibes-sdk/react-native';
|
|
30
|
+
*
|
|
31
|
+
* const sdk = createReactNativeGoodVibesSdk({
|
|
32
|
+
* baseUrl: 'https://daemon.example.com',
|
|
33
|
+
* authToken: await SecureStore.getItemAsync('token'),
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* const events = sdk.realtime.runtime();
|
|
37
|
+
* events.agents.on('AGENT_SPAWNING', ({ agentId }) => console.log(agentId));
|
|
38
|
+
*/
|
|
13
39
|
export declare function createReactNativeGoodVibesSdk(options: ReactNativeGoodVibesSdkOptions): ReactNativeGoodVibesSdk;
|
|
14
40
|
//# sourceMappingURL=react-native.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-native.d.ts","sourceRoot":"","sources":["../src/react-native.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACxB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,8BACf,SAAQ,IAAI,CAAC,mBAAmB,EAAE,eAAe,CAAC;IAClD,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,SAAS,CAAC;CAC3C;AAED,MAAM,WAAW,4BAA4B;IAC3C,OAAO,IAAI,mBAAmB,CAAC,kBAAkB,CAAC,CAAC;IACnD,YAAY,CAAC,aAAa,CAAC,EAAE,OAAO,SAAS,GAAG,mBAAmB,CAAC,kBAAkB,CAAC,CAAC;CACzF;AAED,MAAM,MAAM,uBAAuB,GACjC,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,GAAG;IAC/B,QAAQ,CAAC,QAAQ,EAAE,4BAA4B,CAAC;CACjD,CAAC;AAYJ,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,8BAA8B,GACtC,uBAAuB,CA0DzB"}
|
|
1
|
+
{"version":3,"file":"react-native.d.ts","sourceRoot":"","sources":["../src/react-native.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,mBAAmB,EACzB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACxB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,8BACf,SAAQ,IAAI,CAAC,mBAAmB,EAAE,eAAe,CAAC;IAClD,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,SAAS,CAAC;CAC3C;AAED,MAAM,WAAW,4BAA4B;IAC3C,OAAO,IAAI,mBAAmB,CAAC,kBAAkB,CAAC,CAAC;IACnD,YAAY,CAAC,aAAa,CAAC,EAAE,OAAO,SAAS,GAAG,mBAAmB,CAAC,kBAAkB,CAAC,CAAC;CACzF;AAED,MAAM,MAAM,uBAAuB,GACjC,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,GAAG;IAC/B,QAAQ,CAAC,QAAQ,EAAE,4BAA4B,CAAC;CACjD,CAAC;AAYJ;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,8BAA8B,GACtC,uBAAuB,CA0DzB"}
|
package/dist/react-native.js
CHANGED
|
@@ -8,6 +8,32 @@ function requireReactNativeWebSocket(webSocketImpl) {
|
|
|
8
8
|
}
|
|
9
9
|
return resolved;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Create a GoodVibes SDK instance for React Native.
|
|
13
|
+
*
|
|
14
|
+
* Key differences from the browser factory:
|
|
15
|
+
* - Realtime is WebSocket-only (`realtime.runtime()` / `realtime.viaWebSocket()`).
|
|
16
|
+
* SSE is not available in React Native.
|
|
17
|
+
* - Requires a `WebSocket` implementation (e.g. the global provided by the
|
|
18
|
+
* React Native runtime or the `react-native` package). Pass
|
|
19
|
+
* `options.WebSocketImpl` when the global is not available.
|
|
20
|
+
* - Returns `ReactNativeGoodVibesSdk` (extends `GoodVibesSdk` with a
|
|
21
|
+
* React-Native-specific `realtime` namespace).
|
|
22
|
+
*
|
|
23
|
+
* `createExpoGoodVibesSdk` is an alias for this function.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Example only: replace baseUrl and authToken with your own values.
|
|
27
|
+
* import { createReactNativeGoodVibesSdk } from '@pellux/goodvibes-sdk/react-native';
|
|
28
|
+
*
|
|
29
|
+
* const sdk = createReactNativeGoodVibesSdk({
|
|
30
|
+
* baseUrl: 'https://daemon.example.com',
|
|
31
|
+
* authToken: await SecureStore.getItemAsync('token'),
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* const events = sdk.realtime.runtime();
|
|
35
|
+
* events.agents.on('AGENT_SPAWNING', ({ agentId }) => console.log(agentId));
|
|
36
|
+
*/
|
|
11
37
|
export function createReactNativeGoodVibesSdk(options) {
|
|
12
38
|
const base = createGoodVibesSdk({
|
|
13
39
|
...options,
|
package/dist/web.d.ts
CHANGED
|
@@ -2,5 +2,17 @@ import { type BrowserGoodVibesSdkOptions } from './browser.js';
|
|
|
2
2
|
import type { GoodVibesSdk } from './client.js';
|
|
3
3
|
export interface WebGoodVibesSdkOptions extends BrowserGoodVibesSdkOptions {
|
|
4
4
|
}
|
|
5
|
+
/**
|
|
6
|
+
* Alias for `createBrowserGoodVibesSdk`. Use this entry-point when importing
|
|
7
|
+
* from `@pellux/goodvibes-sdk/web`.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* // Example only: replace with your own auth strategy.
|
|
11
|
+
* import { createWebGoodVibesSdk } from '@pellux/goodvibes-sdk/web';
|
|
12
|
+
*
|
|
13
|
+
* const sdk = createWebGoodVibesSdk({ authToken: myToken });
|
|
14
|
+
* const events = sdk.realtime.viaSse();
|
|
15
|
+
* events.agents.on('AGENT_SPAWNING', ({ agentId }) => console.log(agentId));
|
|
16
|
+
*/
|
|
5
17
|
export declare function createWebGoodVibesSdk(options?: WebGoodVibesSdkOptions): GoodVibesSdk;
|
|
6
18
|
//# sourceMappingURL=web.d.ts.map
|
package/dist/web.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,0BAA0B,EAChC,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,WAAW,sBAAuB,SAAQ,0BAA0B;CAAG;AAE7E,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,sBAA2B,GAAG,YAAY,CAExF"}
|
|
1
|
+
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,0BAA0B,EAChC,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,WAAW,sBAAuB,SAAQ,0BAA0B;CAAG;AAE7E;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,sBAA2B,GAAG,YAAY,CAExF"}
|
package/dist/web.js
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import { createBrowserGoodVibesSdk, } from './browser.js';
|
|
2
|
+
/**
|
|
3
|
+
* Alias for `createBrowserGoodVibesSdk`. Use this entry-point when importing
|
|
4
|
+
* from `@pellux/goodvibes-sdk/web`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // Example only: replace with your own auth strategy.
|
|
8
|
+
* import { createWebGoodVibesSdk } from '@pellux/goodvibes-sdk/web';
|
|
9
|
+
*
|
|
10
|
+
* const sdk = createWebGoodVibesSdk({ authToken: myToken });
|
|
11
|
+
* const events = sdk.realtime.viaSse();
|
|
12
|
+
* events.agents.on('AGENT_SPAWNING', ({ agentId }) => console.log(agentId));
|
|
13
|
+
*/
|
|
2
14
|
export function createWebGoodVibesSdk(options = {}) {
|
|
3
15
|
return createBrowserGoodVibesSdk(options);
|
|
4
16
|
}
|