@warmdrift/kgauto-compiler 2.0.0-alpha.25 → 2.0.0-alpha.27
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/{chunk-7MTHFSNY.mjs → chunk-JQGRWJZO.mjs} +181 -48
- package/dist/{chunk-NUTC7NUC.mjs → chunk-NBO4R5PC.mjs} +122 -107
- package/dist/chunk-RO22VFIF.mjs +29 -0
- package/dist/glassbox/index.d.mts +20 -3
- package/dist/glassbox/index.d.ts +20 -3
- package/dist/glassbox/index.js +42 -30
- package/dist/glassbox/index.mjs +6 -4
- package/dist/glassbox-routes/index.d.mts +12 -3
- package/dist/glassbox-routes/index.d.ts +12 -3
- package/dist/glassbox-routes/index.js +44 -42
- package/dist/glassbox-routes/index.mjs +10 -17
- package/dist/index.js +236 -90
- package/dist/index.mjs +8 -8
- package/dist/profiles.js +181 -48
- package/dist/profiles.mjs +1 -1
- package/dist/{types-DiWBWvxg.d.ts → types-bt0aVJb8.d.ts} +19 -10
- package/dist/{types-D9WndxeD.d.mts → types-o9etg93a.d.mts} +19 -10
- package/package.json +1 -1
- package/dist/chunk-VZGMWKRT.mjs +0 -19
package/dist/glassbox/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { G as GlassboxEvent } from '../types-
|
|
2
|
-
export { A as AdvisoryFiredData, C as CompileDoneData, a as CompileStartData, E as ExecuteAttemptData, b as ExecuteSuccessData, F as FallbackWalkedData, c as GLASSBOX_STREAM_TTL_MS, d as GlassboxEventKind, e as GlassboxPubSub } from '../types-
|
|
1
|
+
import { G as GlassboxEvent } from '../types-bt0aVJb8.js';
|
|
2
|
+
export { A as AdvisoryFiredData, C as CompileDoneData, a as CompileStartData, E as ExecuteAttemptData, b as ExecuteSuccessData, F as FallbackWalkedData, c as GLASSBOX_STREAM_TTL_MS, d as GlassboxEventKind, e as GlassboxPubSub } from '../types-bt0aVJb8.js';
|
|
3
3
|
import '../ir-B_XX2LAO.js';
|
|
4
4
|
import '../dialect.js';
|
|
5
5
|
|
|
@@ -38,5 +38,22 @@ import '../dialect.js';
|
|
|
38
38
|
* down the subscription cleanly via the underlying adapter.
|
|
39
39
|
*/
|
|
40
40
|
declare function subscribe(traceId: string): ReadableStream<GlassboxEvent>;
|
|
41
|
+
/**
|
|
42
|
+
* Subscribe to Glass-Box events for ALL traces under an appId — the
|
|
43
|
+
* "tail-all" surface (alpha.26). Backs the extension's default Live mode:
|
|
44
|
+
* rather than needing a specific traceId ahead of time, the panel sees
|
|
45
|
+
* every event for the configured consumer as calls happen.
|
|
46
|
+
*
|
|
47
|
+
* Per-app routing fires only when emit call-sites pass `appId` (the typed
|
|
48
|
+
* builders thread `ir.appId` automatically). Per-trace channel continues to
|
|
49
|
+
* fire for `subscribe(traceId)` callers — both arms are independent.
|
|
50
|
+
*
|
|
51
|
+
* Cross-tenant isolation: the consumer's `/api/glassbox/stream` uses the
|
|
52
|
+
* factory's configured appId — no caller-supplied `?appId=` URL parameter,
|
|
53
|
+
* so a consumer cannot subscribe to another consumer's stream.
|
|
54
|
+
*/
|
|
55
|
+
declare function subscribeApp({ appId, }: {
|
|
56
|
+
appId: string;
|
|
57
|
+
}): ReadableStream<GlassboxEvent>;
|
|
41
58
|
|
|
42
|
-
export { GlassboxEvent, subscribe };
|
|
59
|
+
export { GlassboxEvent, subscribe, subscribeApp };
|
package/dist/glassbox/index.js
CHANGED
|
@@ -21,7 +21,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var glassbox_exports = {};
|
|
22
22
|
__export(glassbox_exports, {
|
|
23
23
|
GLASSBOX_STREAM_TTL_MS: () => GLASSBOX_STREAM_TTL_MS,
|
|
24
|
-
subscribe: () => subscribe
|
|
24
|
+
subscribe: () => subscribe,
|
|
25
|
+
subscribeApp: () => subscribeApp
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(glassbox_exports);
|
|
27
28
|
|
|
@@ -31,8 +32,8 @@ var GLASSBOX_STREAM_TTL_MS = 6e4;
|
|
|
31
32
|
// src/glassbox/pubsub-memory.ts
|
|
32
33
|
var MemoryPubSub = class {
|
|
33
34
|
subscribers = /* @__PURE__ */ new Map();
|
|
34
|
-
async publish(
|
|
35
|
-
const subs = this.subscribers.get(
|
|
35
|
+
async publish(channelKey, event) {
|
|
36
|
+
const subs = this.subscribers.get(channelKey);
|
|
36
37
|
if (!subs || subs.size === 0) return;
|
|
37
38
|
for (const sub of subs) {
|
|
38
39
|
if (sub.closed) continue;
|
|
@@ -42,10 +43,10 @@ var MemoryPubSub = class {
|
|
|
42
43
|
sub.closed = true;
|
|
43
44
|
continue;
|
|
44
45
|
}
|
|
45
|
-
this.refreshTtl(
|
|
46
|
+
this.refreshTtl(channelKey, sub);
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
|
-
subscribe(
|
|
49
|
+
subscribe(channelKey) {
|
|
49
50
|
const self = this;
|
|
50
51
|
let sub;
|
|
51
52
|
return new ReadableStream({
|
|
@@ -53,19 +54,19 @@ var MemoryPubSub = class {
|
|
|
53
54
|
sub = {
|
|
54
55
|
controller,
|
|
55
56
|
ttlTimer: setTimeout(() => {
|
|
56
|
-
self.closeSubscriber(
|
|
57
|
+
self.closeSubscriber(channelKey, sub);
|
|
57
58
|
}, GLASSBOX_STREAM_TTL_MS),
|
|
58
59
|
closed: false
|
|
59
60
|
};
|
|
60
|
-
let set = self.subscribers.get(
|
|
61
|
+
let set = self.subscribers.get(channelKey);
|
|
61
62
|
if (!set) {
|
|
62
63
|
set = /* @__PURE__ */ new Set();
|
|
63
|
-
self.subscribers.set(
|
|
64
|
+
self.subscribers.set(channelKey, set);
|
|
64
65
|
}
|
|
65
66
|
set.add(sub);
|
|
66
67
|
},
|
|
67
68
|
cancel() {
|
|
68
|
-
if (sub) self.removeSubscriber(
|
|
69
|
+
if (sub) self.removeSubscriber(channelKey, sub);
|
|
69
70
|
}
|
|
70
71
|
});
|
|
71
72
|
}
|
|
@@ -73,17 +74,17 @@ var MemoryPubSub = class {
|
|
|
73
74
|
* Refresh the rolling TTL for a subscriber after an event lands. Replaces
|
|
74
75
|
* the existing timer with a fresh 60s one.
|
|
75
76
|
*/
|
|
76
|
-
refreshTtl(
|
|
77
|
+
refreshTtl(channelKey, sub) {
|
|
77
78
|
clearTimeout(sub.ttlTimer);
|
|
78
79
|
sub.ttlTimer = setTimeout(() => {
|
|
79
|
-
this.closeSubscriber(
|
|
80
|
+
this.closeSubscriber(channelKey, sub);
|
|
80
81
|
}, GLASSBOX_STREAM_TTL_MS);
|
|
81
82
|
}
|
|
82
83
|
/**
|
|
83
84
|
* Close the subscriber's stream cleanly and remove from the fan-out set.
|
|
84
85
|
* Idempotent — safe to call multiple times.
|
|
85
86
|
*/
|
|
86
|
-
closeSubscriber(
|
|
87
|
+
closeSubscriber(channelKey, sub) {
|
|
87
88
|
if (sub.closed) return;
|
|
88
89
|
sub.closed = true;
|
|
89
90
|
clearTimeout(sub.ttlTimer);
|
|
@@ -91,14 +92,14 @@ var MemoryPubSub = class {
|
|
|
91
92
|
sub.controller.close();
|
|
92
93
|
} catch {
|
|
93
94
|
}
|
|
94
|
-
this.removeSubscriber(
|
|
95
|
+
this.removeSubscriber(channelKey, sub);
|
|
95
96
|
}
|
|
96
|
-
removeSubscriber(
|
|
97
|
+
removeSubscriber(channelKey, sub) {
|
|
97
98
|
clearTimeout(sub.ttlTimer);
|
|
98
|
-
const set = this.subscribers.get(
|
|
99
|
+
const set = this.subscribers.get(channelKey);
|
|
99
100
|
if (!set) return;
|
|
100
101
|
set.delete(sub);
|
|
101
|
-
if (set.size === 0) this.subscribers.delete(
|
|
102
|
+
if (set.size === 0) this.subscribers.delete(channelKey);
|
|
102
103
|
}
|
|
103
104
|
/**
|
|
104
105
|
* Test-only reset. Tears down all subscribers, clears all state. Calling
|
|
@@ -128,8 +129,8 @@ var UpstashPubSub = class {
|
|
|
128
129
|
this.blockMs = cfg.blockMs ?? 100;
|
|
129
130
|
this.maxLen = cfg.maxLen ?? 100;
|
|
130
131
|
}
|
|
131
|
-
async publish(
|
|
132
|
-
const key =
|
|
132
|
+
async publish(channelKey, event) {
|
|
133
|
+
const key = channelKey;
|
|
133
134
|
const payload = JSON.stringify(event);
|
|
134
135
|
await this.cmd([
|
|
135
136
|
"XADD",
|
|
@@ -143,8 +144,8 @@ var UpstashPubSub = class {
|
|
|
143
144
|
]);
|
|
144
145
|
await this.cmd(["EXPIRE", key, String(Math.ceil(GLASSBOX_STREAM_TTL_MS / 1e3))]);
|
|
145
146
|
}
|
|
146
|
-
subscribe(
|
|
147
|
-
const key =
|
|
147
|
+
subscribe(channelKey) {
|
|
148
|
+
const key = channelKey;
|
|
148
149
|
const self = this;
|
|
149
150
|
let cursor = "$";
|
|
150
151
|
let cancelled = false;
|
|
@@ -218,9 +219,12 @@ var UpstashPubSub = class {
|
|
|
218
219
|
return json;
|
|
219
220
|
}
|
|
220
221
|
};
|
|
221
|
-
function
|
|
222
|
+
function traceChannel(traceId) {
|
|
222
223
|
return `glassbox:trace:${traceId}`;
|
|
223
224
|
}
|
|
225
|
+
function appChannel(appId) {
|
|
226
|
+
return `glassbox:app:${appId}`;
|
|
227
|
+
}
|
|
224
228
|
function decodeEvent(fields) {
|
|
225
229
|
const raw = fields["event"];
|
|
226
230
|
if (!raw) return void 0;
|
|
@@ -283,18 +287,26 @@ function readEnv(key) {
|
|
|
283
287
|
}
|
|
284
288
|
|
|
285
289
|
// src/glassbox/subscribe.ts
|
|
290
|
+
function emptyStream() {
|
|
291
|
+
return new ReadableStream({
|
|
292
|
+
start(controller) {
|
|
293
|
+
controller.close();
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}
|
|
286
297
|
function subscribe(traceId) {
|
|
287
|
-
if (!traceId)
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
return getPubSub().subscribe(
|
|
298
|
+
if (!traceId) return emptyStream();
|
|
299
|
+
return getPubSub().subscribe(traceChannel(traceId));
|
|
300
|
+
}
|
|
301
|
+
function subscribeApp({
|
|
302
|
+
appId
|
|
303
|
+
}) {
|
|
304
|
+
if (!appId) return emptyStream();
|
|
305
|
+
return getPubSub().subscribe(appChannel(appId));
|
|
295
306
|
}
|
|
296
307
|
// Annotate the CommonJS export names for ESM import in node:
|
|
297
308
|
0 && (module.exports = {
|
|
298
309
|
GLASSBOX_STREAM_TTL_MS,
|
|
299
|
-
subscribe
|
|
310
|
+
subscribe,
|
|
311
|
+
subscribeApp
|
|
300
312
|
});
|
package/dist/glassbox/index.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
subscribe
|
|
3
|
-
|
|
2
|
+
subscribe,
|
|
3
|
+
subscribeApp
|
|
4
|
+
} from "../chunk-RO22VFIF.mjs";
|
|
4
5
|
import {
|
|
5
6
|
GLASSBOX_STREAM_TTL_MS
|
|
6
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-NBO4R5PC.mjs";
|
|
7
8
|
export {
|
|
8
9
|
GLASSBOX_STREAM_TTL_MS,
|
|
9
|
-
subscribe
|
|
10
|
+
subscribe,
|
|
11
|
+
subscribeApp
|
|
10
12
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { G as GlassboxEvent } from '../types-
|
|
1
|
+
import { G as GlassboxEvent } from '../types-o9etg93a.mjs';
|
|
2
2
|
import '../ir-B9zqlwjH.mjs';
|
|
3
3
|
import '../dialect.mjs';
|
|
4
4
|
|
|
@@ -105,11 +105,20 @@ interface GlassboxRoutesConfig {
|
|
|
105
105
|
*/
|
|
106
106
|
fetch?: typeof fetch;
|
|
107
107
|
/**
|
|
108
|
-
* Test-only seam: override the live-stream subscriber. Production
|
|
109
|
-
* resolves to the alpha.17 `subscribe()` export; tests inject a fake
|
|
108
|
+
* Test-only seam: override the per-trace live-stream subscriber. Production
|
|
109
|
+
* code resolves to the alpha.17 `subscribe()` export; tests inject a fake
|
|
110
110
|
* source ReadableStream<GlassboxEvent>.
|
|
111
111
|
*/
|
|
112
112
|
subscribe?: (traceId: string) => ReadableStream<GlassboxEvent>;
|
|
113
|
+
/**
|
|
114
|
+
* Test-only seam: override the per-app "tail-all" subscriber (alpha.26).
|
|
115
|
+
* Production code resolves to the `subscribeApp()` export; tests inject
|
|
116
|
+
* a fake source. Backs the extension's default Live tab mode when no
|
|
117
|
+
* traceId is supplied in the URL.
|
|
118
|
+
*/
|
|
119
|
+
subscribeApp?: (args: {
|
|
120
|
+
appId: string;
|
|
121
|
+
}) => ReadableStream<GlassboxEvent>;
|
|
113
122
|
}
|
|
114
123
|
interface GlassboxRoutes {
|
|
115
124
|
/** GET /api/glassbox/proxy?traceId=<id> OR ?limit=20 (recent traces) */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { G as GlassboxEvent } from '../types-
|
|
1
|
+
import { G as GlassboxEvent } from '../types-bt0aVJb8.js';
|
|
2
2
|
import '../ir-B_XX2LAO.js';
|
|
3
3
|
import '../dialect.js';
|
|
4
4
|
|
|
@@ -105,11 +105,20 @@ interface GlassboxRoutesConfig {
|
|
|
105
105
|
*/
|
|
106
106
|
fetch?: typeof fetch;
|
|
107
107
|
/**
|
|
108
|
-
* Test-only seam: override the live-stream subscriber. Production
|
|
109
|
-
* resolves to the alpha.17 `subscribe()` export; tests inject a fake
|
|
108
|
+
* Test-only seam: override the per-trace live-stream subscriber. Production
|
|
109
|
+
* code resolves to the alpha.17 `subscribe()` export; tests inject a fake
|
|
110
110
|
* source ReadableStream<GlassboxEvent>.
|
|
111
111
|
*/
|
|
112
112
|
subscribe?: (traceId: string) => ReadableStream<GlassboxEvent>;
|
|
113
|
+
/**
|
|
114
|
+
* Test-only seam: override the per-app "tail-all" subscriber (alpha.26).
|
|
115
|
+
* Production code resolves to the `subscribeApp()` export; tests inject
|
|
116
|
+
* a fake source. Backs the extension's default Live tab mode when no
|
|
117
|
+
* traceId is supplied in the URL.
|
|
118
|
+
*/
|
|
119
|
+
subscribeApp?: (args: {
|
|
120
|
+
appId: string;
|
|
121
|
+
}) => ReadableStream<GlassboxEvent>;
|
|
113
122
|
}
|
|
114
123
|
interface GlassboxRoutes {
|
|
115
124
|
/** GET /api/glassbox/proxy?traceId=<id> OR ?limit=20 (recent traces) */
|
|
@@ -190,13 +190,6 @@ var SSE_HEADERS = {
|
|
|
190
190
|
Connection: "keep-alive",
|
|
191
191
|
"X-Accel-Buffering": "no"
|
|
192
192
|
};
|
|
193
|
-
var JSON_HEADERS3 = { "Content-Type": "application/json" };
|
|
194
|
-
function jsonError3(status, code) {
|
|
195
|
-
return new Response(JSON.stringify({ error: code }), {
|
|
196
|
-
status,
|
|
197
|
-
headers: JSON_HEADERS3
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
193
|
function applyScrub2(event, scrub) {
|
|
201
194
|
if (!scrub) return event;
|
|
202
195
|
try {
|
|
@@ -216,17 +209,14 @@ data: ${JSON.stringify(data)}
|
|
|
216
209
|
|
|
217
210
|
`;
|
|
218
211
|
}
|
|
219
|
-
function createStreamHandler(config, subscribe2) {
|
|
220
|
-
const { installToken, extensionId, scrub } = config;
|
|
212
|
+
function createStreamHandler(config, subscribe2, subscribeApp2) {
|
|
213
|
+
const { installToken, extensionId, appId, scrub } = config;
|
|
221
214
|
return async function stream(req) {
|
|
222
215
|
const authFail = checkAuth(req, { installToken, extensionId });
|
|
223
216
|
if (authFail) return authFail;
|
|
224
217
|
const url = new URL(req.url);
|
|
225
218
|
const traceId = url.searchParams.get("traceId");
|
|
226
|
-
|
|
227
|
-
return jsonError3(400, "missing_trace_id");
|
|
228
|
-
}
|
|
229
|
-
const source = subscribe2(traceId);
|
|
219
|
+
const source = traceId ? subscribe2(traceId) : subscribeApp2({ appId });
|
|
230
220
|
const encoder = new TextEncoder();
|
|
231
221
|
let sourceReader;
|
|
232
222
|
let cancelled = false;
|
|
@@ -296,8 +286,8 @@ var GLASSBOX_STREAM_TTL_MS = 6e4;
|
|
|
296
286
|
// src/glassbox/pubsub-memory.ts
|
|
297
287
|
var MemoryPubSub = class {
|
|
298
288
|
subscribers = /* @__PURE__ */ new Map();
|
|
299
|
-
async publish(
|
|
300
|
-
const subs = this.subscribers.get(
|
|
289
|
+
async publish(channelKey, event) {
|
|
290
|
+
const subs = this.subscribers.get(channelKey);
|
|
301
291
|
if (!subs || subs.size === 0) return;
|
|
302
292
|
for (const sub of subs) {
|
|
303
293
|
if (sub.closed) continue;
|
|
@@ -307,10 +297,10 @@ var MemoryPubSub = class {
|
|
|
307
297
|
sub.closed = true;
|
|
308
298
|
continue;
|
|
309
299
|
}
|
|
310
|
-
this.refreshTtl(
|
|
300
|
+
this.refreshTtl(channelKey, sub);
|
|
311
301
|
}
|
|
312
302
|
}
|
|
313
|
-
subscribe(
|
|
303
|
+
subscribe(channelKey) {
|
|
314
304
|
const self = this;
|
|
315
305
|
let sub;
|
|
316
306
|
return new ReadableStream({
|
|
@@ -318,19 +308,19 @@ var MemoryPubSub = class {
|
|
|
318
308
|
sub = {
|
|
319
309
|
controller,
|
|
320
310
|
ttlTimer: setTimeout(() => {
|
|
321
|
-
self.closeSubscriber(
|
|
311
|
+
self.closeSubscriber(channelKey, sub);
|
|
322
312
|
}, GLASSBOX_STREAM_TTL_MS),
|
|
323
313
|
closed: false
|
|
324
314
|
};
|
|
325
|
-
let set = self.subscribers.get(
|
|
315
|
+
let set = self.subscribers.get(channelKey);
|
|
326
316
|
if (!set) {
|
|
327
317
|
set = /* @__PURE__ */ new Set();
|
|
328
|
-
self.subscribers.set(
|
|
318
|
+
self.subscribers.set(channelKey, set);
|
|
329
319
|
}
|
|
330
320
|
set.add(sub);
|
|
331
321
|
},
|
|
332
322
|
cancel() {
|
|
333
|
-
if (sub) self.removeSubscriber(
|
|
323
|
+
if (sub) self.removeSubscriber(channelKey, sub);
|
|
334
324
|
}
|
|
335
325
|
});
|
|
336
326
|
}
|
|
@@ -338,17 +328,17 @@ var MemoryPubSub = class {
|
|
|
338
328
|
* Refresh the rolling TTL for a subscriber after an event lands. Replaces
|
|
339
329
|
* the existing timer with a fresh 60s one.
|
|
340
330
|
*/
|
|
341
|
-
refreshTtl(
|
|
331
|
+
refreshTtl(channelKey, sub) {
|
|
342
332
|
clearTimeout(sub.ttlTimer);
|
|
343
333
|
sub.ttlTimer = setTimeout(() => {
|
|
344
|
-
this.closeSubscriber(
|
|
334
|
+
this.closeSubscriber(channelKey, sub);
|
|
345
335
|
}, GLASSBOX_STREAM_TTL_MS);
|
|
346
336
|
}
|
|
347
337
|
/**
|
|
348
338
|
* Close the subscriber's stream cleanly and remove from the fan-out set.
|
|
349
339
|
* Idempotent — safe to call multiple times.
|
|
350
340
|
*/
|
|
351
|
-
closeSubscriber(
|
|
341
|
+
closeSubscriber(channelKey, sub) {
|
|
352
342
|
if (sub.closed) return;
|
|
353
343
|
sub.closed = true;
|
|
354
344
|
clearTimeout(sub.ttlTimer);
|
|
@@ -356,14 +346,14 @@ var MemoryPubSub = class {
|
|
|
356
346
|
sub.controller.close();
|
|
357
347
|
} catch {
|
|
358
348
|
}
|
|
359
|
-
this.removeSubscriber(
|
|
349
|
+
this.removeSubscriber(channelKey, sub);
|
|
360
350
|
}
|
|
361
|
-
removeSubscriber(
|
|
351
|
+
removeSubscriber(channelKey, sub) {
|
|
362
352
|
clearTimeout(sub.ttlTimer);
|
|
363
|
-
const set = this.subscribers.get(
|
|
353
|
+
const set = this.subscribers.get(channelKey);
|
|
364
354
|
if (!set) return;
|
|
365
355
|
set.delete(sub);
|
|
366
|
-
if (set.size === 0) this.subscribers.delete(
|
|
356
|
+
if (set.size === 0) this.subscribers.delete(channelKey);
|
|
367
357
|
}
|
|
368
358
|
/**
|
|
369
359
|
* Test-only reset. Tears down all subscribers, clears all state. Calling
|
|
@@ -393,8 +383,8 @@ var UpstashPubSub = class {
|
|
|
393
383
|
this.blockMs = cfg.blockMs ?? 100;
|
|
394
384
|
this.maxLen = cfg.maxLen ?? 100;
|
|
395
385
|
}
|
|
396
|
-
async publish(
|
|
397
|
-
const key =
|
|
386
|
+
async publish(channelKey, event) {
|
|
387
|
+
const key = channelKey;
|
|
398
388
|
const payload = JSON.stringify(event);
|
|
399
389
|
await this.cmd([
|
|
400
390
|
"XADD",
|
|
@@ -408,8 +398,8 @@ var UpstashPubSub = class {
|
|
|
408
398
|
]);
|
|
409
399
|
await this.cmd(["EXPIRE", key, String(Math.ceil(GLASSBOX_STREAM_TTL_MS / 1e3))]);
|
|
410
400
|
}
|
|
411
|
-
subscribe(
|
|
412
|
-
const key =
|
|
401
|
+
subscribe(channelKey) {
|
|
402
|
+
const key = channelKey;
|
|
413
403
|
const self = this;
|
|
414
404
|
let cursor = "$";
|
|
415
405
|
let cancelled = false;
|
|
@@ -483,9 +473,12 @@ var UpstashPubSub = class {
|
|
|
483
473
|
return json;
|
|
484
474
|
}
|
|
485
475
|
};
|
|
486
|
-
function
|
|
476
|
+
function traceChannel(traceId) {
|
|
487
477
|
return `glassbox:trace:${traceId}`;
|
|
488
478
|
}
|
|
479
|
+
function appChannel(appId) {
|
|
480
|
+
return `glassbox:app:${appId}`;
|
|
481
|
+
}
|
|
489
482
|
function decodeEvent(fields) {
|
|
490
483
|
const raw = fields["event"];
|
|
491
484
|
if (!raw) return void 0;
|
|
@@ -548,15 +541,22 @@ function readEnv(key) {
|
|
|
548
541
|
}
|
|
549
542
|
|
|
550
543
|
// src/glassbox/subscribe.ts
|
|
544
|
+
function emptyStream() {
|
|
545
|
+
return new ReadableStream({
|
|
546
|
+
start(controller) {
|
|
547
|
+
controller.close();
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
551
|
function subscribe(traceId) {
|
|
552
|
-
if (!traceId)
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
return getPubSub().subscribe(
|
|
552
|
+
if (!traceId) return emptyStream();
|
|
553
|
+
return getPubSub().subscribe(traceChannel(traceId));
|
|
554
|
+
}
|
|
555
|
+
function subscribeApp({
|
|
556
|
+
appId
|
|
557
|
+
}) {
|
|
558
|
+
if (!appId) return emptyStream();
|
|
559
|
+
return getPubSub().subscribe(appChannel(appId));
|
|
560
560
|
}
|
|
561
561
|
|
|
562
562
|
// src/glassbox-routes/index.ts
|
|
@@ -587,9 +587,11 @@ function createGlassboxRoutes(config) {
|
|
|
587
587
|
{
|
|
588
588
|
installToken,
|
|
589
589
|
extensionId,
|
|
590
|
+
appId,
|
|
590
591
|
scrub: config.scrub
|
|
591
592
|
},
|
|
592
|
-
config.subscribe ?? subscribe
|
|
593
|
+
config.subscribe ?? subscribe,
|
|
594
|
+
config.subscribeApp ?? subscribeApp
|
|
593
595
|
);
|
|
594
596
|
return { proxy, stream };
|
|
595
597
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
subscribe
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
subscribe,
|
|
3
|
+
subscribeApp
|
|
4
|
+
} from "../chunk-RO22VFIF.mjs";
|
|
5
|
+
import "../chunk-NBO4R5PC.mjs";
|
|
5
6
|
|
|
6
7
|
// src/glassbox-routes/auth.ts
|
|
7
8
|
var JSON_HEADERS = { "Content-Type": "application/json" };
|
|
@@ -169,13 +170,6 @@ var SSE_HEADERS = {
|
|
|
169
170
|
Connection: "keep-alive",
|
|
170
171
|
"X-Accel-Buffering": "no"
|
|
171
172
|
};
|
|
172
|
-
var JSON_HEADERS3 = { "Content-Type": "application/json" };
|
|
173
|
-
function jsonError3(status, code) {
|
|
174
|
-
return new Response(JSON.stringify({ error: code }), {
|
|
175
|
-
status,
|
|
176
|
-
headers: JSON_HEADERS3
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
173
|
function applyScrub2(event, scrub) {
|
|
180
174
|
if (!scrub) return event;
|
|
181
175
|
try {
|
|
@@ -195,17 +189,14 @@ data: ${JSON.stringify(data)}
|
|
|
195
189
|
|
|
196
190
|
`;
|
|
197
191
|
}
|
|
198
|
-
function createStreamHandler(config, subscribe2) {
|
|
199
|
-
const { installToken, extensionId, scrub } = config;
|
|
192
|
+
function createStreamHandler(config, subscribe2, subscribeApp2) {
|
|
193
|
+
const { installToken, extensionId, appId, scrub } = config;
|
|
200
194
|
return async function stream(req) {
|
|
201
195
|
const authFail = checkAuth(req, { installToken, extensionId });
|
|
202
196
|
if (authFail) return authFail;
|
|
203
197
|
const url = new URL(req.url);
|
|
204
198
|
const traceId = url.searchParams.get("traceId");
|
|
205
|
-
|
|
206
|
-
return jsonError3(400, "missing_trace_id");
|
|
207
|
-
}
|
|
208
|
-
const source = subscribe2(traceId);
|
|
199
|
+
const source = traceId ? subscribe2(traceId) : subscribeApp2({ appId });
|
|
209
200
|
const encoder = new TextEncoder();
|
|
210
201
|
let sourceReader;
|
|
211
202
|
let cancelled = false;
|
|
@@ -297,9 +288,11 @@ function createGlassboxRoutes(config) {
|
|
|
297
288
|
{
|
|
298
289
|
installToken,
|
|
299
290
|
extensionId,
|
|
291
|
+
appId,
|
|
300
292
|
scrub: config.scrub
|
|
301
293
|
},
|
|
302
|
-
config.subscribe ?? subscribe
|
|
294
|
+
config.subscribe ?? subscribe,
|
|
295
|
+
config.subscribeApp ?? subscribeApp
|
|
303
296
|
);
|
|
304
297
|
return { proxy, stream };
|
|
305
298
|
}
|