@enterstellar-ai/cloud 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 +196 -0
- package/NOTICE +17 -0
- package/README.md +297 -0
- package/dist/index.cjs +1433 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1359 -0
- package/dist/index.d.ts +1359 -0
- package/dist/index.js +1428 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and derivative works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
51
|
+
or written communication sent to the Licensor or its representatives,
|
|
52
|
+
including but not limited to communication on electronic mailing lists,
|
|
53
|
+
source code control systems, and issue tracking systems that are managed
|
|
54
|
+
by, or on behalf of, the Licensor for the purpose of discussing and
|
|
55
|
+
improving the Work, but excluding communication that is conspicuously
|
|
56
|
+
marked or designated in writing by the copyright owner as "Not a
|
|
57
|
+
Contribution."
|
|
58
|
+
|
|
59
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
60
|
+
whom a Contribution has been received by the Licensor and included
|
|
61
|
+
within the Work.
|
|
62
|
+
|
|
63
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
64
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
65
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
66
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
67
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
68
|
+
Work and such Derivative Works in Source or Object form.
|
|
69
|
+
|
|
70
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
71
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
+
(except as stated in this section) patent license to make, have made,
|
|
74
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
75
|
+
where such license applies only to those patent claims licensable
|
|
76
|
+
by such Contributor that are necessarily infringed by their
|
|
77
|
+
Contribution(s) alone or by the combination of their Contribution(s)
|
|
78
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
79
|
+
institute patent litigation against any entity (including a cross-claim
|
|
80
|
+
or counterclaim in a lawsuit) alleging that the Work or any
|
|
81
|
+
Contribution embodied within the Work constitutes direct or contributory
|
|
82
|
+
patent infringement, then any patent licenses granted to You under
|
|
83
|
+
this License for that Work shall terminate as of the date such
|
|
84
|
+
litigation is filed.
|
|
85
|
+
|
|
86
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
87
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
88
|
+
modifications, and in Source or Object form, provided that You
|
|
89
|
+
meet the following conditions:
|
|
90
|
+
|
|
91
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
92
|
+
Works a copy of this License; and
|
|
93
|
+
|
|
94
|
+
(b) You must cause any modified files to carry prominent notices
|
|
95
|
+
stating that You changed the files; and
|
|
96
|
+
|
|
97
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
98
|
+
that You distribute, all copyright, patent, trademark, and
|
|
99
|
+
attribution notices from the Source form of the Work,
|
|
100
|
+
excluding those notices that do not pertain to any part of
|
|
101
|
+
the Derivative Works; and
|
|
102
|
+
|
|
103
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
104
|
+
distribution, You must include a readable copy of the
|
|
105
|
+
attribution notices contained within such NOTICE file, in
|
|
106
|
+
at least one of the following places: within a NOTICE text
|
|
107
|
+
file distributed as part of the Derivative Works; within
|
|
108
|
+
the Source form or documentation, if provided along with the
|
|
109
|
+
Derivative Works; or, within a display generated by the
|
|
110
|
+
Derivative Works, if and wherever such third-party notices
|
|
111
|
+
normally appear. The contents of the NOTICE file are for
|
|
112
|
+
informational purposes only and do not modify the License.
|
|
113
|
+
You may add Your own attribution notices within Derivative
|
|
114
|
+
Works that You distribute, alongside or as an addendum to
|
|
115
|
+
the NOTICE text from the Work, provided that such additional
|
|
116
|
+
attribution notices cannot be construed as modifying the
|
|
117
|
+
License.
|
|
118
|
+
|
|
119
|
+
You may add Your own license statement to Your modifications and
|
|
120
|
+
may provide additional grant of rights to use, copy, modify, merge,
|
|
121
|
+
publish, distribute, sublicense, and/or sell copies of the
|
|
122
|
+
Modifications or such Derivative Works, and to permit recipients
|
|
123
|
+
of the Modifications to such Derivative Works to do so, subject to
|
|
124
|
+
the terms of the License.
|
|
125
|
+
|
|
126
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
127
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
128
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
129
|
+
this License, without any additional terms or conditions.
|
|
130
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
131
|
+
the terms of any separate license agreement you may have executed
|
|
132
|
+
with Licensor regarding such Contributions.
|
|
133
|
+
|
|
134
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
135
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
136
|
+
except as required for reasonable and customary use in describing the
|
|
137
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
138
|
+
|
|
139
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
140
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
141
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
142
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
143
|
+
implied, including, without limitation, any warranties or conditions
|
|
144
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
145
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
146
|
+
appropriateness of using or reproducing the Work and assume any
|
|
147
|
+
risks associated with Your exercise of permissions under this License.
|
|
148
|
+
|
|
149
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
150
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
151
|
+
unless required by applicable law (such as deliberate and grossly
|
|
152
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
153
|
+
liable to You for damages, including any direct, indirect, special,
|
|
154
|
+
incidental, or exemplary damages of any character arising as a
|
|
155
|
+
result of this License or out of the use or inability to use the
|
|
156
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
157
|
+
work stoppage, computer failure or malfunction, or all other
|
|
158
|
+
commercial damages or losses), even if such Contributor has been
|
|
159
|
+
advised of the possibility of such damages.
|
|
160
|
+
|
|
161
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
162
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
163
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
164
|
+
or other liability obligations and/or rights consistent with this
|
|
165
|
+
License. However, in accepting such obligations, You may offer such
|
|
166
|
+
obligations only on Your own behalf and on Your sole responsibility,
|
|
167
|
+
not on behalf of any other Contributor, and only if You agree to
|
|
168
|
+
indemnify, defend, and hold each Contributor harmless for any
|
|
169
|
+
liability incurred by, or claims asserted against, such Contributor
|
|
170
|
+
by reason of your accepting any such warranty or additional liability.
|
|
171
|
+
|
|
172
|
+
END OF TERMS AND CONDITIONS
|
|
173
|
+
|
|
174
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
175
|
+
|
|
176
|
+
To apply the Apache License to your work, attach the following
|
|
177
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
178
|
+
replaced with your own identifying information. (Do not include
|
|
179
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
180
|
+
comment syntax for the file format in question. Please also
|
|
181
|
+
make a list of the licenses used in the work and ask the
|
|
182
|
+
maintainers for clarification if needed.
|
|
183
|
+
|
|
184
|
+
Copyright 2026 LifeOS Frameworks, Inc. (DBA Enterstellar) and A. Yassin
|
|
185
|
+
|
|
186
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
187
|
+
you may not use this file except in compliance with the License.
|
|
188
|
+
You may obtain a copy of the License at
|
|
189
|
+
|
|
190
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
191
|
+
|
|
192
|
+
Unless required by applicable law or agreed to in writing, software
|
|
193
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
194
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
195
|
+
See the License for the specific language governing permissions and
|
|
196
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Enterstellar
|
|
2
|
+
Copyright 2026 LifeOS Frameworks, Inc. (DBA Enterstellar) and A. Yassin
|
|
3
|
+
|
|
4
|
+
This product is licensed under the Apache License, Version 2.0 (the "License").
|
|
5
|
+
You may not use this product except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at:
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
11
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
12
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
13
|
+
specific language governing permissions and limitations under the License.
|
|
14
|
+
|
|
15
|
+
For licensing inquiries, contact: legal@enterstellar.dev
|
|
16
|
+
Homepage: https://enterstellar.dev
|
|
17
|
+
Repository: https://github.com/enterstellar-ai/enterstellar
|
package/README.md
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
# @enterstellar-ai/cloud
|
|
2
|
+
|
|
3
|
+
> Enterstellar Cloud SDK — typed, universal client for `api.enterstellar.dev`. 13 methods + SSE streaming. Throw-on-error. Zero framework dependencies.
|
|
4
|
+
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
`@enterstellar-ai/cloud` provides `createEnterstellarCloudClient()` — the client-side SDK for all Enterstellar Cloud API interactions. Every method returns `CloudResult<T>` with `{ data, ipu }` — a universal wrapper that carries the response data and server-authoritative IPU metering in a single, predictable shape. Operational errors (429, 4xx, retries exhausted) throw `CloudError` with structured metadata (`upgradeUrl`, `retryAfterMs`, `requestId`) — callers never receive degraded or partial results.
|
|
8
|
+
|
|
9
|
+
**Key properties:**
|
|
10
|
+
|
|
11
|
+
- **SD3:** Throw-on-error — `CloudError` thrown on 429/4xx/5xx. No degraded returns.
|
|
12
|
+
- **SD5:** Blanket retry — 3 attempts with 1s/2s/4s exponential backoff on 5xx and network errors. Same `X-Idempotency-Key` across retries (AM10).
|
|
13
|
+
- **SD6:** Dual forge API — `forge()` returns a `Promise<CloudResult<ComponentContract>>`. `forge.stream()` returns `AsyncGenerator<ForgeFragment>` for real-time SSE streaming.
|
|
14
|
+
- **SD7:** Universal return type — all methods return `CloudResult<T>` with `{ data: T, ipu: CloudIPU | null }`.
|
|
15
|
+
- **SD1:** Anonymous mode — `pk_anon_*` API keys auto-detected. Only `submitSignal()` is available; all other methods throw `ENS-5004`.
|
|
16
|
+
- **SD9:** Single runtime dependency — `eventsource-parser` (2KB, MIT) for SSE parsing.
|
|
17
|
+
- **CL1:** Hybrid metering — `X-IPU-Used` / `X-IPU-Remaining` / `X-IPU-Cost` headers parsed on every response. Local tracker reconciles with server.
|
|
18
|
+
- **TA2:** Consent-gated traces — dual gate: `config.traceConsent` AND `trace.consent.anonymizedAggregation` must both be `true`.
|
|
19
|
+
- **L15:** Zero framework dependencies — works in Node.js, Deno, browsers, and SSR.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { createEnterstellarCloudClient } from '@enterstellar-ai/cloud';
|
|
27
|
+
|
|
28
|
+
const cloud = createEnterstellarCloudClient({
|
|
29
|
+
apiKey: process.env['ENTERSTELLAR_API_KEY']!,
|
|
30
|
+
traceConsent: true,
|
|
31
|
+
sessionType: 'app',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Generate via Cloud Forge (10 IPU):
|
|
35
|
+
const { data: contract, ipu } = await cloud.forge({ intent: 'show patient vitals' });
|
|
36
|
+
console.log(`Cost: ${ipu?.cost} IPU, Remaining: ${ipu?.remaining}`);
|
|
37
|
+
|
|
38
|
+
// Stream via Cloud Forge SSE (10 IPU):
|
|
39
|
+
for await (const fragment of cloud.forge.stream({ intent: 'show patient vitals' })) {
|
|
40
|
+
if (fragment.type === 'node') console.log('Partial:', fragment.data);
|
|
41
|
+
if (fragment.type === 'complete') console.log('Done:', fragment.data);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Search via Cloud Semantic Index (1 IPU):
|
|
45
|
+
const { data: results } = await cloud.search('patient vitals display', 5);
|
|
46
|
+
|
|
47
|
+
// Route via Intent Router (1 IPU):
|
|
48
|
+
const { data: prediction } = await cloud.route('sha256_intent_hash');
|
|
49
|
+
|
|
50
|
+
// Submit trace (0 IPU, consent-gated):
|
|
51
|
+
const {
|
|
52
|
+
data: { accepted },
|
|
53
|
+
} = await cloud.submitTrace(agentTrace);
|
|
54
|
+
|
|
55
|
+
// Check usage (0 IPU):
|
|
56
|
+
const { data: usage } = await cloud.getUsage();
|
|
57
|
+
console.log(`${usage.used}/${usage.limit} IPU used (${usage.tier})`);
|
|
58
|
+
|
|
59
|
+
// Shutdown:
|
|
60
|
+
cloud.dispose();
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Anonymous Mode (`pk_anon_*`)
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
const anonCloud = createEnterstellarCloudClient({ apiKey: 'pk_anon_<install_id>' });
|
|
67
|
+
|
|
68
|
+
// Only submitSignal() is available:
|
|
69
|
+
await anonCloud.submitSignal(signal); // ✅ Works
|
|
70
|
+
|
|
71
|
+
await anonCloud.forge({ intent: 'x' }); // ❌ Throws ENS-5004
|
|
72
|
+
await anonCloud.search('x'); // ❌ Throws ENS-5004
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## API Reference
|
|
78
|
+
|
|
79
|
+
### `createEnterstellarCloudClient(config): EnterstellarCloudClient`
|
|
80
|
+
|
|
81
|
+
Factory function. Validates config, initializes HTTP + SSE transports with bearer auth, creates IPU tracker, and wires all cloud proxy modules. Auto-detects anonymous mode from `pk_anon_` API key prefix.
|
|
82
|
+
|
|
83
|
+
**Throws:** `CloudError` `ENS-5001` if `apiKey` is empty, whitespace-only, or missing.
|
|
84
|
+
|
|
85
|
+
### `EnterstellarCloudClient` Methods
|
|
86
|
+
|
|
87
|
+
| Method | Signature | IPU | Description |
|
|
88
|
+
| :----------------------------- | :----------------------------------------------------------------- | :-: | :-------------------------------------------------------------------------------------------------------------------------------- |
|
|
89
|
+
| `forge(options)` | `(ForgeOptions) → Promise<CloudResult<ComponentContract>>` | 10 | Generate a `ComponentContract` via Cloud Forge (SD6). |
|
|
90
|
+
| `forge.stream(options)` | `(ForgeOptions) → AsyncGenerator<ForgeFragment>` | 10 | Stream forge via SSE. Yields `meta → node* → property* → complete` (CF6). |
|
|
91
|
+
| `search(query, topK?)` | `(string, number?) → Promise<CloudResult<SemanticSearchResult[]>>` | 1 | Search for components via Cloud Semantic Index. Default `topK: 5` (SI5). |
|
|
92
|
+
| `route(intentHash)` | `(string) → Promise<CloudResult<RouterPrediction>>` | 1 | Route an intent hash to predicted components (IR2). |
|
|
93
|
+
| `routeBatch(intentHashes)` | `(string[]) → Promise<CloudResult<RouterPrediction[]>>` | 1×N | Batch routing. `result.data[i]` corresponds to `intentHashes[i]` (F19). |
|
|
94
|
+
| `submitSignal(signal)` | `(ForgeSignal) → Promise<CloudResult<{ accepted }>>` | 0 | Submit a forge signal. **Only method available in anonymous mode** (SD1, SD4). |
|
|
95
|
+
| `submitTrace(trace)` | `(AgentTrace) → Promise<CloudResult<{ accepted }>>` | 0 | Submit an `AgentTrace`. Consent-gated (TA2): both `config.traceConsent` AND `trace.consent.anonymizedAggregation` must be `true`. |
|
|
96
|
+
| `analytics(query)` | `(AnalyticsQuery) → Promise<CloudResult<AnalyticsResult>>` | 5 | Query trace analytics. POST to `/v1/traces/analytics` (F17). 30s timeout. |
|
|
97
|
+
| `businessAnalytics(query)` | `(AnalyticsQuery) → Promise<CloudResult<AnalyticsResult>>` | 5 | Query business analytics. POST to `/v1/analytics/query` (TA10). 30s timeout. |
|
|
98
|
+
| `getUsage()` | `() → Promise<CloudResult<CloudUsage>>` | 0 | Query IPU usage for the current billing period. |
|
|
99
|
+
| `getTraces(options?)` | `(TraceListOptions?) → Promise<CloudResult<TracePage>>` | 0 | List traces with cursor-based pagination (TA7). |
|
|
100
|
+
| `getLedger(options?)` | `(LedgerListOptions?) → Promise<CloudResult<LedgerPage>>` | 0 | List IPU ledger entries with cursor-based pagination (AM13). |
|
|
101
|
+
| `certify(contractId)` | `(string) → Promise<CloudResult<CertifyResult>>` | 20 | Start certification. Returns `{ status: 'pending', pollUrl }` (GI5). 90s timeout. |
|
|
102
|
+
| `deleteProjectData(projectId)` | `(string) → Promise<CloudResult<{ accepted }>>` | 0 | GDPR soft-delete. Returns `202 Accepted` (AG9). |
|
|
103
|
+
| `dispose()` | `() → void` | — | Release all resources. Post-dispose calls throw `ENS-5002`. Idempotent. |
|
|
104
|
+
|
|
105
|
+
### Types
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
/** Configuration for createEnterstellarCloudClient(). */
|
|
109
|
+
type CloudConfig = {
|
|
110
|
+
readonly apiKey: string; // Bearer token (CL4)
|
|
111
|
+
readonly baseUrl?: string | undefined; // Default: 'https://api.enterstellar.dev' (SD8)
|
|
112
|
+
readonly timeoutMs?: number | undefined; // Default: 10_000 (per-operation overrides)
|
|
113
|
+
readonly traceConsent?: boolean | undefined; // Default: false (TA2)
|
|
114
|
+
readonly sessionType?: SessionType | undefined; // Default: 'app' (D111)
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/** Universal return wrapper for all SDK methods (SD7). */
|
|
118
|
+
type CloudResult<T> = {
|
|
119
|
+
readonly data: T;
|
|
120
|
+
readonly ipu: CloudIPU | null; // null in anonymous mode or absent headers
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/** IPU metering data from server response headers. */
|
|
124
|
+
type CloudIPU = {
|
|
125
|
+
readonly used: number; // X-IPU-Used
|
|
126
|
+
readonly remaining: number; // X-IPU-Remaining
|
|
127
|
+
readonly cost: number; // X-IPU-Cost
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/** 5-variant discriminated union for SSE streaming (CF6). */
|
|
131
|
+
type ForgeFragment =
|
|
132
|
+
| ForgeMetaFragment // { type: 'meta', data: { provider, model }, ipu }
|
|
133
|
+
| ForgeNodeFragment // { type: 'node', data: Partial<ComponentContract> }
|
|
134
|
+
| ForgePropertyFragment // { type: 'property', data: { path, value } }
|
|
135
|
+
| ForgeCompleteFragment // { type: 'complete', data: ComponentContract, ipu }
|
|
136
|
+
| ForgeErrorFragment; // { type: 'error', data: { code, message } }
|
|
137
|
+
|
|
138
|
+
/** Session type for ClickHouse analytics (D111). */
|
|
139
|
+
type SessionType = 'app' | 'browser' | 'os' | 'connect' | 'agent' | 'other';
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Exports
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
// Factory
|
|
146
|
+
export { createEnterstellarCloudClient } from './create-cloud-client.js';
|
|
147
|
+
|
|
148
|
+
// Error class (for instanceof checks)
|
|
149
|
+
export { CloudError } from './errors.js';
|
|
150
|
+
|
|
151
|
+
// Constants
|
|
152
|
+
export { CLOUD_SDK_VERSION } from './version.js';
|
|
153
|
+
export { IPU_COSTS } from './metering/ipu-costs.js';
|
|
154
|
+
|
|
155
|
+
// Types (re-exported for consumer use)
|
|
156
|
+
export type {
|
|
157
|
+
EnterstellarCloudClient,
|
|
158
|
+
CloudConfig,
|
|
159
|
+
CloudIPU,
|
|
160
|
+
CloudResult,
|
|
161
|
+
CloudUsage,
|
|
162
|
+
SessionType,
|
|
163
|
+
ForgeOptions,
|
|
164
|
+
ForgeFragment,
|
|
165
|
+
ForgeFunction,
|
|
166
|
+
ForgeMetaFragment,
|
|
167
|
+
ForgeNodeFragment,
|
|
168
|
+
ForgePropertyFragment,
|
|
169
|
+
ForgeCompleteFragment,
|
|
170
|
+
ForgeErrorFragment,
|
|
171
|
+
RouterPrediction,
|
|
172
|
+
AnalyticsQuery,
|
|
173
|
+
AnalyticsResult,
|
|
174
|
+
TraceListOptions,
|
|
175
|
+
LedgerListOptions,
|
|
176
|
+
TracePage,
|
|
177
|
+
LedgerPage,
|
|
178
|
+
CertifyResult,
|
|
179
|
+
} from './types.js';
|
|
180
|
+
|
|
181
|
+
export type { CloudErrorBody } from './errors.js';
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## Configuration
|
|
187
|
+
|
|
188
|
+
### `CloudConfig`
|
|
189
|
+
|
|
190
|
+
| Option | Type | Default | Description |
|
|
191
|
+
| :------------- | :------------ | :------------------------------- | :---------------------------------------------------------------------------------- |
|
|
192
|
+
| `apiKey` | `string` | _(required)_ | Bearer token for `api.enterstellar.dev`. `pk_anon_*` prefix → anonymous mode (SD1). |
|
|
193
|
+
| `baseUrl` | `string` | `'https://api.enterstellar.dev'` | Cloud API base URL. Override for staging/self-hosted (SD8). |
|
|
194
|
+
| `timeoutMs` | `number` | `10_000` | Default per-request HTTP timeout. Per-operation overrides apply (F21). |
|
|
195
|
+
| `traceConsent` | `boolean` | `false` | Client-level trace consent flag (TA2). Must also have per-trace consent. |
|
|
196
|
+
| `sessionType` | `SessionType` | `'app'` | Session type for ClickHouse analytics (D111). |
|
|
197
|
+
|
|
198
|
+
### IPU Cost Schedule (§9.1)
|
|
199
|
+
|
|
200
|
+
| Operation | Cost | API Endpoint | Timeout |
|
|
201
|
+
| :------------------ | :-----: | :------------------------------- | :-----: |
|
|
202
|
+
| Cloud Forge | 10 IPU | `POST /v1/forge` | 30s |
|
|
203
|
+
| Semantic Search | 1 IPU | `POST /v1/semantic-search` | 10s |
|
|
204
|
+
| Route | 1 IPU | `POST /v1/route` | 10s |
|
|
205
|
+
| Route Batch | 1×N IPU | `POST /v1/route/batch` | 10s |
|
|
206
|
+
| Trace Analytics | 5 IPU | `POST /v1/traces/analytics` | 30s |
|
|
207
|
+
| Business Analytics | 5 IPU | `POST /v1/analytics/query` | 30s |
|
|
208
|
+
| Certify | 20 IPU | `POST /v1/contracts/:id/certify` | 90s |
|
|
209
|
+
| Signal Submit | 0 IPU | `POST /v1/signals` | 10s |
|
|
210
|
+
| Trace Submit | 0 IPU | `POST /v1/traces` | 10s |
|
|
211
|
+
| Get Traces | 0 IPU | `GET /v1/traces` | 10s |
|
|
212
|
+
| Ledger Query | 0 IPU | `GET /v1/usage/ledger` | 10s |
|
|
213
|
+
| Usage Query | 0 IPU | `GET /v1/usage` | 10s |
|
|
214
|
+
| Delete Project Data | 0 IPU | `DELETE /v1/project/:id/data` | 10s |
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## Error Handling (SD3)
|
|
219
|
+
|
|
220
|
+
All operational errors throw `CloudError` with structured metadata:
|
|
221
|
+
|
|
222
|
+
```ts
|
|
223
|
+
try {
|
|
224
|
+
await cloud.forge({ intent: 'show vitals' });
|
|
225
|
+
} catch (error) {
|
|
226
|
+
if (error instanceof CloudError) {
|
|
227
|
+
console.log(error.code); // 'ENS-5003' (base code)
|
|
228
|
+
console.log(error.cloudCode); // 'ENS-C4290' (server code)
|
|
229
|
+
console.log(error.upgradeUrl); // 'https://cloud.enterstellar.dev/billing/upgrade'
|
|
230
|
+
console.log(error.retryAfterMs); // 3600000
|
|
231
|
+
console.log(error.requestId); // 'req_01HYX...'
|
|
232
|
+
console.log(error.recoverable); // true (429 is recoverable)
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Error Codes
|
|
238
|
+
|
|
239
|
+
| Code | Module | Recoverable | Description |
|
|
240
|
+
| :---------- | :----- | :---------- | :-------------------------------------------------------------------------------- |
|
|
241
|
+
| `ENS-5001` | cloud | No | `apiKey` is empty or missing — configuration error. |
|
|
242
|
+
| `ENS-5002` | cloud | No | Method called after `dispose()` — logic error. |
|
|
243
|
+
| `ENS-5003` | cloud | Yes | Server request failed — network/server error, can retry. |
|
|
244
|
+
| `ENS-5004` | cloud | No | Method called in anonymous mode — `pk_anon_*` key only supports `submitSignal()`. |
|
|
245
|
+
| `ENS-5005` | cloud | Yes | All 3 retry attempts exhausted — 5xx/network persistent failure. |
|
|
246
|
+
| `ENS-C4290` | cloud | Yes | IPU quota exceeded — carries `upgradeUrl` and `retryAfterMs`. |
|
|
247
|
+
|
|
248
|
+
### Retry Strategy (SD5)
|
|
249
|
+
|
|
250
|
+
```
|
|
251
|
+
Transport: fetch POST /v1/{endpoint}
|
|
252
|
+
│
|
|
253
|
+
├── Attempt 1
|
|
254
|
+
│ 5xx/network → wait 1s → Attempt 2
|
|
255
|
+
│ 429 → throw CloudError (ENS-C4290) immediately
|
|
256
|
+
│ 4xx → throw CloudError immediately (no retry)
|
|
257
|
+
│ 2xx → parse response → return CloudResult<T>
|
|
258
|
+
│
|
|
259
|
+
├── Attempt 2
|
|
260
|
+
│ 5xx/network → wait 2s → Attempt 3
|
|
261
|
+
│ Same X-Idempotency-Key as Attempt 1 (AM10)
|
|
262
|
+
│
|
|
263
|
+
└── Attempt 3
|
|
264
|
+
5xx/network → throw CloudError (ENS-5005)
|
|
265
|
+
2xx → parse response → return CloudResult<T>
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## Consent Model (TA2)
|
|
271
|
+
|
|
272
|
+
Trace submission requires dual consent:
|
|
273
|
+
|
|
274
|
+
```
|
|
275
|
+
client.submitTrace(trace)
|
|
276
|
+
│
|
|
277
|
+
├── Gate 1: config.traceConsent === true?
|
|
278
|
+
│ false → return { data: { accepted: false }, ipu: null } (zero network)
|
|
279
|
+
│
|
|
280
|
+
├── Gate 2: trace.consent.anonymizedAggregation === true?
|
|
281
|
+
│ false → return { data: { accepted: false }, ipu: null } (zero network)
|
|
282
|
+
│
|
|
283
|
+
└── Both true → POST /v1/traces → return { data: { accepted }, ipu }
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## Design Choices Applied
|
|
289
|
+
|
|
290
|
+
SD1 (anonymous mode auto-detection), SD2 (additive semver), SD3 (throw-on-error), SD4 (transparent telemetry), SD5 (blanket retry with backoff), SD6 (dual forge API), SD7 (universal `CloudResult<T>`), SD8 (default `baseUrl`), SD9 (`eventsource-parser` only dep), SD10 (`@enterstellar-cloud/types`), CL1 (hybrid IPU tracking), AM10 (universal idempotency), CF6 (SSE event types), D111 (`sessionType`), TA2 (consent-gated traces), F17 (POST for analytics), F18 (IPU on meta+complete), F19 (batch ordering), F21 (per-operation timeouts), F22 (User-Agent header), L15 (framework-agnostic).
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## Bible Reference
|
|
295
|
+
|
|
296
|
+
See [Implementation Bible §9.1–§9.4](../../archive/CLOUD/02-enterstellar-cloud-implementation-bible.md) for the canonical API surface, endpoint mapping, header contract, and error body format.
|
|
297
|
+
See [Locked Design Choices SD1–SD10](../../archive/CLOUD/03-enterstellar-cloud-design-choices.md) for all SDK design decisions.
|