@anduril-industries/lattice-sdk 4.13.0 → 4.14.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/dist/cjs/BaseClient.js +2 -2
- package/dist/cjs/core/stream/Stream.d.ts +7 -0
- package/dist/cjs/core/stream/Stream.js +54 -10
- package/dist/cjs/core/stream/index.d.ts +1 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/BaseClient.mjs +2 -2
- package/dist/esm/core/stream/Stream.d.mts +7 -0
- package/dist/esm/core/stream/Stream.mjs +54 -10
- package/dist/esm/core/stream/index.d.mts +1 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/package.json +1 -1
package/dist/cjs/BaseClient.js
CHANGED
|
@@ -43,8 +43,8 @@ function normalizeClientOptions(options) {
|
|
|
43
43
|
const headers = (0, headers_js_1.mergeHeaders)({
|
|
44
44
|
"X-Fern-Language": "JavaScript",
|
|
45
45
|
"X-Fern-SDK-Name": "@anduril-industries/lattice-sdk",
|
|
46
|
-
"X-Fern-SDK-Version": "4.
|
|
47
|
-
"User-Agent": "@anduril-industries/lattice-sdk/4.
|
|
46
|
+
"X-Fern-SDK-Version": "4.14.0",
|
|
47
|
+
"User-Agent": "@anduril-industries/lattice-sdk/4.14.0",
|
|
48
48
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
49
49
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
50
50
|
}, options === null || options === void 0 ? void 0 : options.headers);
|
|
@@ -23,6 +23,12 @@ export declare namespace Stream {
|
|
|
23
23
|
eventDiscriminator?: string;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
+
export interface ServerSentEvent<T> {
|
|
27
|
+
data: T;
|
|
28
|
+
id?: string;
|
|
29
|
+
retry?: number;
|
|
30
|
+
event?: string;
|
|
31
|
+
}
|
|
26
32
|
export declare class Stream<T> implements AsyncIterable<T> {
|
|
27
33
|
private stream;
|
|
28
34
|
private parse;
|
|
@@ -46,6 +52,7 @@ export declare class Stream<T> implements AsyncIterable<T> {
|
|
|
46
52
|
* Parses and returns a single SSE event, or returns null if the event is a stream terminator.
|
|
47
53
|
*/
|
|
48
54
|
private dispatchSseEvent;
|
|
55
|
+
withMetadata(): AsyncIterable<ServerSentEvent<T>>;
|
|
49
56
|
private injectDiscriminator;
|
|
50
57
|
[Symbol.asyncIterator](): AsyncIterator<T, void, unknown>;
|
|
51
58
|
private decodeChunk;
|
|
@@ -40,6 +40,8 @@ const json_js_1 = require("../json.js");
|
|
|
40
40
|
const index_js_1 = require("../runtime/index.js");
|
|
41
41
|
const DATA_PREFIX = "data:";
|
|
42
42
|
const EVENT_PREFIX = "event:";
|
|
43
|
+
const ID_PREFIX = "id:";
|
|
44
|
+
const RETRY_PREFIX = "retry:";
|
|
43
45
|
class Stream {
|
|
44
46
|
constructor({ stream, parse, eventShape, signal }) {
|
|
45
47
|
this.controller = new AbortController();
|
|
@@ -76,6 +78,8 @@ class Stream {
|
|
|
76
78
|
const stream = readableStreamAsyncIterable(this.stream);
|
|
77
79
|
let buf = "";
|
|
78
80
|
let prefixSeen = false;
|
|
81
|
+
let lastId;
|
|
82
|
+
let lastRetry;
|
|
79
83
|
try {
|
|
80
84
|
for (var _d = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield __await(stream_1.next()), _a = stream_1_1.done, !_a; _d = true) {
|
|
81
85
|
_c = stream_1_1.value;
|
|
@@ -89,6 +93,21 @@ class Stream {
|
|
|
89
93
|
if (!line.trim()) {
|
|
90
94
|
continue;
|
|
91
95
|
}
|
|
96
|
+
if (line.startsWith(ID_PREFIX)) {
|
|
97
|
+
const idValue = line.slice(ID_PREFIX.length).trim();
|
|
98
|
+
if (!idValue.includes("\0")) {
|
|
99
|
+
lastId = idValue;
|
|
100
|
+
}
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (line.startsWith(RETRY_PREFIX)) {
|
|
104
|
+
const retryValue = line.slice(RETRY_PREFIX.length).trim();
|
|
105
|
+
const parsed = parseInt(retryValue, 10);
|
|
106
|
+
if (!Number.isNaN(parsed) && String(parsed) === retryValue) {
|
|
107
|
+
lastRetry = parsed;
|
|
108
|
+
}
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
92
111
|
if (!prefixSeen && this.prefix != null) {
|
|
93
112
|
const prefixIndex = line.indexOf(this.prefix);
|
|
94
113
|
if (prefixIndex === -1) {
|
|
@@ -100,8 +119,8 @@ class Stream {
|
|
|
100
119
|
if (this.streamTerminator != null && line.includes(this.streamTerminator)) {
|
|
101
120
|
return yield __await(void 0);
|
|
102
121
|
}
|
|
103
|
-
const
|
|
104
|
-
yield yield __await(
|
|
122
|
+
const data = yield __await(this.parse((0, json_js_1.fromJson)(line)));
|
|
123
|
+
yield yield __await({ data, id: lastId, retry: lastRetry, event: undefined });
|
|
105
124
|
prefixSeen = false;
|
|
106
125
|
}
|
|
107
126
|
}
|
|
@@ -122,6 +141,8 @@ class Stream {
|
|
|
122
141
|
let buf = "";
|
|
123
142
|
let eventType;
|
|
124
143
|
let dataValue;
|
|
144
|
+
let lastId;
|
|
145
|
+
let lastRetry;
|
|
125
146
|
try {
|
|
126
147
|
for (var _d = true, stream_2 = __asyncValues(stream), stream_2_1; stream_2_1 = yield __await(stream_2.next()), _a = stream_2_1.done, !_a; _d = true) {
|
|
127
148
|
_c = stream_2_1.value;
|
|
@@ -134,11 +155,11 @@ class Stream {
|
|
|
134
155
|
buf = buf.slice(terminatorIndex + 1);
|
|
135
156
|
if (!line.trim()) {
|
|
136
157
|
if (dataValue != null) {
|
|
137
|
-
const
|
|
138
|
-
if (
|
|
158
|
+
const data = yield __await(this.dispatchSseEvent(dataValue, eventType));
|
|
159
|
+
if (data == null) {
|
|
139
160
|
return yield __await(void 0);
|
|
140
161
|
}
|
|
141
|
-
yield yield __await(
|
|
162
|
+
yield yield __await({ data, id: lastId, retry: lastRetry, event: eventType });
|
|
142
163
|
}
|
|
143
164
|
eventType = undefined;
|
|
144
165
|
dataValue = undefined;
|
|
@@ -151,6 +172,19 @@ class Stream {
|
|
|
151
172
|
const val = line.slice(DATA_PREFIX.length).trim();
|
|
152
173
|
dataValue = dataValue != null ? `${dataValue}\n${val}` : val;
|
|
153
174
|
}
|
|
175
|
+
else if (line.startsWith(ID_PREFIX)) {
|
|
176
|
+
const idValue = line.slice(ID_PREFIX.length).trim();
|
|
177
|
+
if (!idValue.includes("\0")) {
|
|
178
|
+
lastId = idValue;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else if (line.startsWith(RETRY_PREFIX)) {
|
|
182
|
+
const retryValue = line.slice(RETRY_PREFIX.length).trim();
|
|
183
|
+
const parsed = parseInt(retryValue, 10);
|
|
184
|
+
if (!Number.isNaN(parsed) && String(parsed) === retryValue) {
|
|
185
|
+
lastRetry = parsed;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
154
188
|
}
|
|
155
189
|
}
|
|
156
190
|
}
|
|
@@ -162,9 +196,9 @@ class Stream {
|
|
|
162
196
|
finally { if (e_2) throw e_2.error; }
|
|
163
197
|
}
|
|
164
198
|
if (dataValue != null) {
|
|
165
|
-
const
|
|
166
|
-
if (
|
|
167
|
-
yield yield __await(
|
|
199
|
+
const data = yield __await(this.dispatchSseEvent(dataValue, eventType));
|
|
200
|
+
if (data != null) {
|
|
201
|
+
yield yield __await({ data, id: lastId, retry: lastRetry, event: eventType });
|
|
168
202
|
}
|
|
169
203
|
}
|
|
170
204
|
});
|
|
@@ -180,6 +214,16 @@ class Stream {
|
|
|
180
214
|
return this.parse(this.injectDiscriminator((0, json_js_1.fromJson)(dataValue), eventType));
|
|
181
215
|
});
|
|
182
216
|
}
|
|
217
|
+
withMetadata() {
|
|
218
|
+
const self = this;
|
|
219
|
+
return {
|
|
220
|
+
[Symbol.asyncIterator]() {
|
|
221
|
+
return __asyncGenerator(this, arguments, function* _a() {
|
|
222
|
+
yield __await(yield* __asyncDelegator(__asyncValues(self.iterMessages())));
|
|
223
|
+
});
|
|
224
|
+
},
|
|
225
|
+
};
|
|
226
|
+
}
|
|
183
227
|
injectDiscriminator(parsed, eventType) {
|
|
184
228
|
if (this.eventDiscriminator == null || eventType == null) {
|
|
185
229
|
return parsed;
|
|
@@ -200,8 +244,8 @@ class Stream {
|
|
|
200
244
|
for (var _e = true, _f = __asyncValues(this.iterMessages()), _g; _g = yield __await(_f.next()), _b = _g.done, !_b; _e = true) {
|
|
201
245
|
_d = _g.value;
|
|
202
246
|
_e = false;
|
|
203
|
-
const
|
|
204
|
-
yield yield __await(
|
|
247
|
+
const event = _d;
|
|
248
|
+
yield yield __await(event.data);
|
|
205
249
|
}
|
|
206
250
|
}
|
|
207
251
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "4.
|
|
1
|
+
export declare const SDK_VERSION = "4.14.0";
|
package/dist/cjs/version.js
CHANGED
package/dist/esm/BaseClient.mjs
CHANGED
|
@@ -6,8 +6,8 @@ export function normalizeClientOptions(options) {
|
|
|
6
6
|
const headers = mergeHeaders({
|
|
7
7
|
"X-Fern-Language": "JavaScript",
|
|
8
8
|
"X-Fern-SDK-Name": "@anduril-industries/lattice-sdk",
|
|
9
|
-
"X-Fern-SDK-Version": "4.
|
|
10
|
-
"User-Agent": "@anduril-industries/lattice-sdk/4.
|
|
9
|
+
"X-Fern-SDK-Version": "4.14.0",
|
|
10
|
+
"User-Agent": "@anduril-industries/lattice-sdk/4.14.0",
|
|
11
11
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
12
12
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
13
13
|
}, options === null || options === void 0 ? void 0 : options.headers);
|
|
@@ -23,6 +23,12 @@ export declare namespace Stream {
|
|
|
23
23
|
eventDiscriminator?: string;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
+
export interface ServerSentEvent<T> {
|
|
27
|
+
data: T;
|
|
28
|
+
id?: string;
|
|
29
|
+
retry?: number;
|
|
30
|
+
event?: string;
|
|
31
|
+
}
|
|
26
32
|
export declare class Stream<T> implements AsyncIterable<T> {
|
|
27
33
|
private stream;
|
|
28
34
|
private parse;
|
|
@@ -46,6 +52,7 @@ export declare class Stream<T> implements AsyncIterable<T> {
|
|
|
46
52
|
* Parses and returns a single SSE event, or returns null if the event is a stream terminator.
|
|
47
53
|
*/
|
|
48
54
|
private dispatchSseEvent;
|
|
55
|
+
withMetadata(): AsyncIterable<ServerSentEvent<T>>;
|
|
49
56
|
private injectDiscriminator;
|
|
50
57
|
[Symbol.asyncIterator](): AsyncIterator<T, void, unknown>;
|
|
51
58
|
private decodeChunk;
|
|
@@ -36,6 +36,8 @@ import { fromJson } from "../json.mjs";
|
|
|
36
36
|
import { RUNTIME } from "../runtime/index.mjs";
|
|
37
37
|
const DATA_PREFIX = "data:";
|
|
38
38
|
const EVENT_PREFIX = "event:";
|
|
39
|
+
const ID_PREFIX = "id:";
|
|
40
|
+
const RETRY_PREFIX = "retry:";
|
|
39
41
|
export class Stream {
|
|
40
42
|
constructor({ stream, parse, eventShape, signal }) {
|
|
41
43
|
this.controller = new AbortController();
|
|
@@ -72,6 +74,8 @@ export class Stream {
|
|
|
72
74
|
const stream = readableStreamAsyncIterable(this.stream);
|
|
73
75
|
let buf = "";
|
|
74
76
|
let prefixSeen = false;
|
|
77
|
+
let lastId;
|
|
78
|
+
let lastRetry;
|
|
75
79
|
try {
|
|
76
80
|
for (var _d = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield __await(stream_1.next()), _a = stream_1_1.done, !_a; _d = true) {
|
|
77
81
|
_c = stream_1_1.value;
|
|
@@ -85,6 +89,21 @@ export class Stream {
|
|
|
85
89
|
if (!line.trim()) {
|
|
86
90
|
continue;
|
|
87
91
|
}
|
|
92
|
+
if (line.startsWith(ID_PREFIX)) {
|
|
93
|
+
const idValue = line.slice(ID_PREFIX.length).trim();
|
|
94
|
+
if (!idValue.includes("\0")) {
|
|
95
|
+
lastId = idValue;
|
|
96
|
+
}
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (line.startsWith(RETRY_PREFIX)) {
|
|
100
|
+
const retryValue = line.slice(RETRY_PREFIX.length).trim();
|
|
101
|
+
const parsed = parseInt(retryValue, 10);
|
|
102
|
+
if (!Number.isNaN(parsed) && String(parsed) === retryValue) {
|
|
103
|
+
lastRetry = parsed;
|
|
104
|
+
}
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
88
107
|
if (!prefixSeen && this.prefix != null) {
|
|
89
108
|
const prefixIndex = line.indexOf(this.prefix);
|
|
90
109
|
if (prefixIndex === -1) {
|
|
@@ -96,8 +115,8 @@ export class Stream {
|
|
|
96
115
|
if (this.streamTerminator != null && line.includes(this.streamTerminator)) {
|
|
97
116
|
return yield __await(void 0);
|
|
98
117
|
}
|
|
99
|
-
const
|
|
100
|
-
yield yield __await(
|
|
118
|
+
const data = yield __await(this.parse(fromJson(line)));
|
|
119
|
+
yield yield __await({ data, id: lastId, retry: lastRetry, event: undefined });
|
|
101
120
|
prefixSeen = false;
|
|
102
121
|
}
|
|
103
122
|
}
|
|
@@ -118,6 +137,8 @@ export class Stream {
|
|
|
118
137
|
let buf = "";
|
|
119
138
|
let eventType;
|
|
120
139
|
let dataValue;
|
|
140
|
+
let lastId;
|
|
141
|
+
let lastRetry;
|
|
121
142
|
try {
|
|
122
143
|
for (var _d = true, stream_2 = __asyncValues(stream), stream_2_1; stream_2_1 = yield __await(stream_2.next()), _a = stream_2_1.done, !_a; _d = true) {
|
|
123
144
|
_c = stream_2_1.value;
|
|
@@ -130,11 +151,11 @@ export class Stream {
|
|
|
130
151
|
buf = buf.slice(terminatorIndex + 1);
|
|
131
152
|
if (!line.trim()) {
|
|
132
153
|
if (dataValue != null) {
|
|
133
|
-
const
|
|
134
|
-
if (
|
|
154
|
+
const data = yield __await(this.dispatchSseEvent(dataValue, eventType));
|
|
155
|
+
if (data == null) {
|
|
135
156
|
return yield __await(void 0);
|
|
136
157
|
}
|
|
137
|
-
yield yield __await(
|
|
158
|
+
yield yield __await({ data, id: lastId, retry: lastRetry, event: eventType });
|
|
138
159
|
}
|
|
139
160
|
eventType = undefined;
|
|
140
161
|
dataValue = undefined;
|
|
@@ -147,6 +168,19 @@ export class Stream {
|
|
|
147
168
|
const val = line.slice(DATA_PREFIX.length).trim();
|
|
148
169
|
dataValue = dataValue != null ? `${dataValue}\n${val}` : val;
|
|
149
170
|
}
|
|
171
|
+
else if (line.startsWith(ID_PREFIX)) {
|
|
172
|
+
const idValue = line.slice(ID_PREFIX.length).trim();
|
|
173
|
+
if (!idValue.includes("\0")) {
|
|
174
|
+
lastId = idValue;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
else if (line.startsWith(RETRY_PREFIX)) {
|
|
178
|
+
const retryValue = line.slice(RETRY_PREFIX.length).trim();
|
|
179
|
+
const parsed = parseInt(retryValue, 10);
|
|
180
|
+
if (!Number.isNaN(parsed) && String(parsed) === retryValue) {
|
|
181
|
+
lastRetry = parsed;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
150
184
|
}
|
|
151
185
|
}
|
|
152
186
|
}
|
|
@@ -158,9 +192,9 @@ export class Stream {
|
|
|
158
192
|
finally { if (e_2) throw e_2.error; }
|
|
159
193
|
}
|
|
160
194
|
if (dataValue != null) {
|
|
161
|
-
const
|
|
162
|
-
if (
|
|
163
|
-
yield yield __await(
|
|
195
|
+
const data = yield __await(this.dispatchSseEvent(dataValue, eventType));
|
|
196
|
+
if (data != null) {
|
|
197
|
+
yield yield __await({ data, id: lastId, retry: lastRetry, event: eventType });
|
|
164
198
|
}
|
|
165
199
|
}
|
|
166
200
|
});
|
|
@@ -176,6 +210,16 @@ export class Stream {
|
|
|
176
210
|
return this.parse(this.injectDiscriminator(fromJson(dataValue), eventType));
|
|
177
211
|
});
|
|
178
212
|
}
|
|
213
|
+
withMetadata() {
|
|
214
|
+
const self = this;
|
|
215
|
+
return {
|
|
216
|
+
[Symbol.asyncIterator]() {
|
|
217
|
+
return __asyncGenerator(this, arguments, function* _a() {
|
|
218
|
+
yield __await(yield* __asyncDelegator(__asyncValues(self.iterMessages())));
|
|
219
|
+
});
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
}
|
|
179
223
|
injectDiscriminator(parsed, eventType) {
|
|
180
224
|
if (this.eventDiscriminator == null || eventType == null) {
|
|
181
225
|
return parsed;
|
|
@@ -196,8 +240,8 @@ export class Stream {
|
|
|
196
240
|
for (var _e = true, _f = __asyncValues(this.iterMessages()), _g; _g = yield __await(_f.next()), _b = _g.done, !_b; _e = true) {
|
|
197
241
|
_d = _g.value;
|
|
198
242
|
_e = false;
|
|
199
|
-
const
|
|
200
|
-
yield yield __await(
|
|
243
|
+
const event = _d;
|
|
244
|
+
yield yield __await(event.data);
|
|
201
245
|
}
|
|
202
246
|
}
|
|
203
247
|
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
package/dist/esm/version.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "4.
|
|
1
|
+
export declare const SDK_VERSION = "4.14.0";
|
package/dist/esm/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "4.
|
|
1
|
+
export const SDK_VERSION = "4.14.0";
|