@agentuity/runtime 2.0.11 → 3.0.0-alpha.1
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/index.d.ts +37 -65
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +59 -61
- package/dist/index.js.map +1 -1
- package/package.json +9 -38
- package/src/index.ts +58 -259
- package/AGENTS.md +0 -116
- package/dist/_config.d.ts +0 -100
- package/dist/_config.d.ts.map +0 -1
- package/dist/_config.js +0 -147
- package/dist/_config.js.map +0 -1
- package/dist/_context.d.ts +0 -80
- package/dist/_context.d.ts.map +0 -1
- package/dist/_context.js +0 -160
- package/dist/_context.js.map +0 -1
- package/dist/_events.d.ts +0 -64
- package/dist/_events.d.ts.map +0 -1
- package/dist/_events.js +0 -92
- package/dist/_events.js.map +0 -1
- package/dist/_globals.d.ts +0 -58
- package/dist/_globals.d.ts.map +0 -1
- package/dist/_globals.js +0 -71
- package/dist/_globals.js.map +0 -1
- package/dist/_idle.d.ts +0 -7
- package/dist/_idle.d.ts.map +0 -1
- package/dist/_idle.js +0 -10
- package/dist/_idle.js.map +0 -1
- package/dist/_metadata.d.ts +0 -117
- package/dist/_metadata.d.ts.map +0 -1
- package/dist/_metadata.js +0 -268
- package/dist/_metadata.js.map +0 -1
- package/dist/_process-protection.d.ts +0 -27
- package/dist/_process-protection.d.ts.map +0 -1
- package/dist/_process-protection.js +0 -56
- package/dist/_process-protection.js.map +0 -1
- package/dist/_server.d.ts +0 -50
- package/dist/_server.d.ts.map +0 -1
- package/dist/_server.js +0 -89
- package/dist/_server.js.map +0 -1
- package/dist/_services.d.ts +0 -25
- package/dist/_services.d.ts.map +0 -1
- package/dist/_services.js +0 -286
- package/dist/_services.js.map +0 -1
- package/dist/_standalone.d.ts +0 -212
- package/dist/_standalone.d.ts.map +0 -1
- package/dist/_standalone.js +0 -556
- package/dist/_standalone.js.map +0 -1
- package/dist/_tokens.d.ts +0 -12
- package/dist/_tokens.d.ts.map +0 -1
- package/dist/_tokens.js +0 -97
- package/dist/_tokens.js.map +0 -1
- package/dist/_util.d.ts +0 -16
- package/dist/_util.d.ts.map +0 -1
- package/dist/_util.js +0 -54
- package/dist/_util.js.map +0 -1
- package/dist/_validation.d.ts +0 -89
- package/dist/_validation.d.ts.map +0 -1
- package/dist/_validation.js +0 -29
- package/dist/_validation.js.map +0 -1
- package/dist/_waituntil.d.ts +0 -32
- package/dist/_waituntil.d.ts.map +0 -1
- package/dist/_waituntil.js +0 -156
- package/dist/_waituntil.js.map +0 -1
- package/dist/agent.d.ts +0 -1262
- package/dist/agent.d.ts.map +0 -1
- package/dist/agent.js +0 -981
- package/dist/agent.js.map +0 -1
- package/dist/app.d.ts +0 -514
- package/dist/app.d.ts.map +0 -1
- package/dist/app.js +0 -228
- package/dist/app.js.map +0 -1
- package/dist/bootstrap.d.ts +0 -44
- package/dist/bootstrap.d.ts.map +0 -1
- package/dist/bootstrap.js +0 -259
- package/dist/bootstrap.js.map +0 -1
- package/dist/bun-s3-patch.d.ts +0 -37
- package/dist/bun-s3-patch.d.ts.map +0 -1
- package/dist/bun-s3-patch.js +0 -142
- package/dist/bun-s3-patch.js.map +0 -1
- package/dist/cors.d.ts +0 -42
- package/dist/cors.d.ts.map +0 -1
- package/dist/cors.js +0 -117
- package/dist/cors.js.map +0 -1
- package/dist/dev-patches/aisdk.d.ts +0 -17
- package/dist/dev-patches/aisdk.d.ts.map +0 -1
- package/dist/dev-patches/aisdk.js +0 -160
- package/dist/dev-patches/aisdk.js.map +0 -1
- package/dist/dev-patches/gateway.d.ts +0 -16
- package/dist/dev-patches/gateway.d.ts.map +0 -1
- package/dist/dev-patches/gateway.js +0 -54
- package/dist/dev-patches/gateway.js.map +0 -1
- package/dist/dev-patches/index.d.ts +0 -21
- package/dist/dev-patches/index.d.ts.map +0 -1
- package/dist/dev-patches/index.js +0 -33
- package/dist/dev-patches/index.js.map +0 -1
- package/dist/dev-patches/otel-llm.d.ts +0 -12
- package/dist/dev-patches/otel-llm.d.ts.map +0 -1
- package/dist/dev-patches/otel-llm.js +0 -352
- package/dist/dev-patches/otel-llm.js.map +0 -1
- package/dist/devmode.d.ts +0 -3
- package/dist/devmode.d.ts.map +0 -1
- package/dist/devmode.js +0 -167
- package/dist/devmode.js.map +0 -1
- package/dist/eval.d.ts +0 -91
- package/dist/eval.d.ts.map +0 -1
- package/dist/eval.js +0 -16
- package/dist/eval.js.map +0 -1
- package/dist/handlers/_route-meta.d.ts +0 -22
- package/dist/handlers/_route-meta.d.ts.map +0 -1
- package/dist/handlers/_route-meta.js +0 -25
- package/dist/handlers/_route-meta.js.map +0 -1
- package/dist/handlers/cron.d.ts +0 -73
- package/dist/handlers/cron.d.ts.map +0 -1
- package/dist/handlers/cron.js +0 -43
- package/dist/handlers/cron.js.map +0 -1
- package/dist/handlers/index.d.ts +0 -6
- package/dist/handlers/index.d.ts.map +0 -1
- package/dist/handlers/index.js +0 -6
- package/dist/handlers/index.js.map +0 -1
- package/dist/handlers/sse.d.ts +0 -163
- package/dist/handlers/sse.d.ts.map +0 -1
- package/dist/handlers/sse.js +0 -175
- package/dist/handlers/sse.js.map +0 -1
- package/dist/handlers/stream.d.ts +0 -52
- package/dist/handlers/stream.d.ts.map +0 -1
- package/dist/handlers/stream.js +0 -108
- package/dist/handlers/stream.js.map +0 -1
- package/dist/handlers/webrtc.d.ts +0 -49
- package/dist/handlers/webrtc.d.ts.map +0 -1
- package/dist/handlers/webrtc.js +0 -109
- package/dist/handlers/webrtc.js.map +0 -1
- package/dist/handlers/websocket.d.ts +0 -88
- package/dist/handlers/websocket.d.ts.map +0 -1
- package/dist/handlers/websocket.js +0 -161
- package/dist/handlers/websocket.js.map +0 -1
- package/dist/logger/console.d.ts +0 -70
- package/dist/logger/console.d.ts.map +0 -1
- package/dist/logger/console.js +0 -278
- package/dist/logger/console.js.map +0 -1
- package/dist/logger/index.d.ts +0 -3
- package/dist/logger/index.d.ts.map +0 -1
- package/dist/logger/index.js +0 -3
- package/dist/logger/index.js.map +0 -1
- package/dist/logger/internal.d.ts +0 -79
- package/dist/logger/internal.d.ts.map +0 -1
- package/dist/logger/internal.js +0 -133
- package/dist/logger/internal.js.map +0 -1
- package/dist/logger/logger.d.ts +0 -41
- package/dist/logger/logger.d.ts.map +0 -1
- package/dist/logger/logger.js +0 -2
- package/dist/logger/logger.js.map +0 -1
- package/dist/logger/user.d.ts +0 -8
- package/dist/logger/user.d.ts.map +0 -1
- package/dist/logger/user.js +0 -7
- package/dist/logger/user.js.map +0 -1
- package/dist/logger/util.d.ts +0 -11
- package/dist/logger/util.d.ts.map +0 -1
- package/dist/logger/util.js +0 -77
- package/dist/logger/util.js.map +0 -1
- package/dist/middleware.d.ts +0 -105
- package/dist/middleware.d.ts.map +0 -1
- package/dist/middleware.js +0 -763
- package/dist/middleware.js.map +0 -1
- package/dist/otel/config.d.ts +0 -19
- package/dist/otel/config.d.ts.map +0 -1
- package/dist/otel/config.js +0 -26
- package/dist/otel/config.js.map +0 -1
- package/dist/otel/console.d.ts +0 -33
- package/dist/otel/console.d.ts.map +0 -1
- package/dist/otel/console.js +0 -86
- package/dist/otel/console.js.map +0 -1
- package/dist/otel/exporters/index.d.ts +0 -4
- package/dist/otel/exporters/index.d.ts.map +0 -1
- package/dist/otel/exporters/index.js +0 -4
- package/dist/otel/exporters/index.js.map +0 -1
- package/dist/otel/exporters/jsonl-log-exporter.d.ts +0 -36
- package/dist/otel/exporters/jsonl-log-exporter.d.ts.map +0 -1
- package/dist/otel/exporters/jsonl-log-exporter.js +0 -103
- package/dist/otel/exporters/jsonl-log-exporter.js.map +0 -1
- package/dist/otel/exporters/jsonl-metric-exporter.d.ts +0 -40
- package/dist/otel/exporters/jsonl-metric-exporter.d.ts.map +0 -1
- package/dist/otel/exporters/jsonl-metric-exporter.js +0 -104
- package/dist/otel/exporters/jsonl-metric-exporter.js.map +0 -1
- package/dist/otel/exporters/jsonl-trace-exporter.d.ts +0 -36
- package/dist/otel/exporters/jsonl-trace-exporter.d.ts.map +0 -1
- package/dist/otel/exporters/jsonl-trace-exporter.js +0 -111
- package/dist/otel/exporters/jsonl-trace-exporter.js.map +0 -1
- package/dist/otel/fetch.d.ts +0 -12
- package/dist/otel/fetch.d.ts.map +0 -1
- package/dist/otel/fetch.js +0 -82
- package/dist/otel/fetch.js.map +0 -1
- package/dist/otel/http.d.ts +0 -16
- package/dist/otel/http.d.ts.map +0 -1
- package/dist/otel/http.js +0 -44
- package/dist/otel/http.js.map +0 -1
- package/dist/otel/logger.d.ts +0 -37
- package/dist/otel/logger.d.ts.map +0 -1
- package/dist/otel/logger.js +0 -265
- package/dist/otel/logger.js.map +0 -1
- package/dist/otel/otel.d.ts +0 -68
- package/dist/otel/otel.d.ts.map +0 -1
- package/dist/otel/otel.js +0 -245
- package/dist/otel/otel.js.map +0 -1
- package/dist/otel/tracestate.d.ts +0 -44
- package/dist/otel/tracestate.d.ts.map +0 -1
- package/dist/otel/tracestate.js +0 -84
- package/dist/otel/tracestate.js.map +0 -1
- package/dist/router.d.ts +0 -66
- package/dist/router.d.ts.map +0 -1
- package/dist/router.js +0 -44
- package/dist/router.js.map +0 -1
- package/dist/services/evalrun/composite.d.ts +0 -21
- package/dist/services/evalrun/composite.d.ts.map +0 -1
- package/dist/services/evalrun/composite.js +0 -26
- package/dist/services/evalrun/composite.js.map +0 -1
- package/dist/services/evalrun/http.d.ts +0 -24
- package/dist/services/evalrun/http.d.ts.map +0 -1
- package/dist/services/evalrun/http.js +0 -115
- package/dist/services/evalrun/http.js.map +0 -1
- package/dist/services/evalrun/index.d.ts +0 -5
- package/dist/services/evalrun/index.d.ts.map +0 -1
- package/dist/services/evalrun/index.js +0 -5
- package/dist/services/evalrun/index.js.map +0 -1
- package/dist/services/evalrun/json.d.ts +0 -21
- package/dist/services/evalrun/json.d.ts.map +0 -1
- package/dist/services/evalrun/json.js +0 -38
- package/dist/services/evalrun/json.js.map +0 -1
- package/dist/services/evalrun/local.d.ts +0 -19
- package/dist/services/evalrun/local.d.ts.map +0 -1
- package/dist/services/evalrun/local.js +0 -22
- package/dist/services/evalrun/local.js.map +0 -1
- package/dist/services/local/_db.d.ts +0 -4
- package/dist/services/local/_db.d.ts.map +0 -1
- package/dist/services/local/_db.js +0 -281
- package/dist/services/local/_db.js.map +0 -1
- package/dist/services/local/_router.d.ts +0 -3
- package/dist/services/local/_router.d.ts.map +0 -1
- package/dist/services/local/_router.js +0 -28
- package/dist/services/local/_router.js.map +0 -1
- package/dist/services/local/_util.d.ts +0 -18
- package/dist/services/local/_util.d.ts.map +0 -1
- package/dist/services/local/_util.js +0 -44
- package/dist/services/local/_util.js.map +0 -1
- package/dist/services/local/email.d.ts +0 -24
- package/dist/services/local/email.d.ts.map +0 -1
- package/dist/services/local/email.js +0 -58
- package/dist/services/local/email.js.map +0 -1
- package/dist/services/local/index.d.ts +0 -10
- package/dist/services/local/index.d.ts.map +0 -1
- package/dist/services/local/index.js +0 -10
- package/dist/services/local/index.js.map +0 -1
- package/dist/services/local/keyvalue.d.ts +0 -17
- package/dist/services/local/keyvalue.d.ts.map +0 -1
- package/dist/services/local/keyvalue.js +0 -133
- package/dist/services/local/keyvalue.js.map +0 -1
- package/dist/services/local/queue.d.ts +0 -10
- package/dist/services/local/queue.d.ts.map +0 -1
- package/dist/services/local/queue.js +0 -96
- package/dist/services/local/queue.js.map +0 -1
- package/dist/services/local/stream.d.ts +0 -12
- package/dist/services/local/stream.d.ts.map +0 -1
- package/dist/services/local/stream.js +0 -266
- package/dist/services/local/stream.js.map +0 -1
- package/dist/services/local/task.d.ts +0 -55
- package/dist/services/local/task.d.ts.map +0 -1
- package/dist/services/local/task.js +0 -1248
- package/dist/services/local/task.js.map +0 -1
- package/dist/services/local/vector.d.ts +0 -17
- package/dist/services/local/vector.d.ts.map +0 -1
- package/dist/services/local/vector.js +0 -303
- package/dist/services/local/vector.js.map +0 -1
- package/dist/services/sandbox/http.d.ts +0 -23
- package/dist/services/sandbox/http.d.ts.map +0 -1
- package/dist/services/sandbox/http.js +0 -327
- package/dist/services/sandbox/http.js.map +0 -1
- package/dist/services/sandbox/index.d.ts +0 -2
- package/dist/services/sandbox/index.d.ts.map +0 -1
- package/dist/services/sandbox/index.js +0 -2
- package/dist/services/sandbox/index.js.map +0 -1
- package/dist/services/session/composite.d.ts +0 -21
- package/dist/services/session/composite.d.ts.map +0 -1
- package/dist/services/session/composite.js +0 -26
- package/dist/services/session/composite.js.map +0 -1
- package/dist/services/session/http.d.ts +0 -34
- package/dist/services/session/http.d.ts.map +0 -1
- package/dist/services/session/http.js +0 -124
- package/dist/services/session/http.js.map +0 -1
- package/dist/services/session/index.d.ts +0 -5
- package/dist/services/session/index.d.ts.map +0 -1
- package/dist/services/session/index.js +0 -5
- package/dist/services/session/index.js.map +0 -1
- package/dist/services/session/json.d.ts +0 -22
- package/dist/services/session/json.d.ts.map +0 -1
- package/dist/services/session/json.js +0 -35
- package/dist/services/session/json.js.map +0 -1
- package/dist/services/session/local.d.ts +0 -19
- package/dist/services/session/local.d.ts.map +0 -1
- package/dist/services/session/local.js +0 -23
- package/dist/services/session/local.js.map +0 -1
- package/dist/services/thread/local.d.ts +0 -20
- package/dist/services/thread/local.d.ts.map +0 -1
- package/dist/services/thread/local.js +0 -158
- package/dist/services/thread/local.js.map +0 -1
- package/dist/session.d.ts +0 -734
- package/dist/session.d.ts.map +0 -1
- package/dist/session.js +0 -1140
- package/dist/session.js.map +0 -1
- package/dist/signature.d.ts +0 -22
- package/dist/signature.d.ts.map +0 -1
- package/dist/signature.js +0 -63
- package/dist/signature.js.map +0 -1
- package/dist/validator.d.ts +0 -142
- package/dist/validator.d.ts.map +0 -1
- package/dist/validator.js +0 -149
- package/dist/validator.js.map +0 -1
- package/dist/version-check.d.ts +0 -20
- package/dist/version-check.d.ts.map +0 -1
- package/dist/version-check.js +0 -157
- package/dist/version-check.js.map +0 -1
- package/dist/web.d.ts +0 -8
- package/dist/web.d.ts.map +0 -1
- package/dist/web.js +0 -67
- package/dist/web.js.map +0 -1
- package/dist/webrtc-signaling.d.ts +0 -80
- package/dist/webrtc-signaling.d.ts.map +0 -1
- package/dist/webrtc-signaling.js +0 -237
- package/dist/webrtc-signaling.js.map +0 -1
- package/dist/workbench.d.ts +0 -17
- package/dist/workbench.d.ts.map +0 -1
- package/dist/workbench.js +0 -605
- package/dist/workbench.js.map +0 -1
- package/src/_config.ts +0 -163
- package/src/_context.ts +0 -240
- package/src/_events.ts +0 -142
- package/src/_globals.ts +0 -92
- package/src/_idle.ts +0 -10
- package/src/_metadata.ts +0 -407
- package/src/_process-protection.ts +0 -71
- package/src/_server.ts +0 -109
- package/src/_services.ts +0 -379
- package/src/_standalone.ts +0 -710
- package/src/_tokens.ts +0 -114
- package/src/_util.ts +0 -62
- package/src/_validation.ts +0 -119
- package/src/_waituntil.ts +0 -188
- package/src/agent.ts +0 -2739
- package/src/app.ts +0 -769
- package/src/bootstrap.ts +0 -321
- package/src/bun-s3-patch.ts +0 -224
- package/src/cors.ts +0 -137
- package/src/dev-patches/aisdk.ts +0 -169
- package/src/dev-patches/gateway.ts +0 -68
- package/src/dev-patches/index.ts +0 -37
- package/src/dev-patches/otel-llm.ts +0 -405
- package/src/devmode.ts +0 -171
- package/src/eval.ts +0 -109
- package/src/globals.d.ts +0 -28
- package/src/handlers/_route-meta.ts +0 -33
- package/src/handlers/cron.ts +0 -141
- package/src/handlers/index.ts +0 -18
- package/src/handlers/sse.ts +0 -358
- package/src/handlers/stream.ts +0 -121
- package/src/handlers/webrtc.ts +0 -125
- package/src/handlers/websocket.ts +0 -203
- package/src/logger/console.ts +0 -323
- package/src/logger/index.ts +0 -2
- package/src/logger/internal.ts +0 -165
- package/src/logger/logger.ts +0 -44
- package/src/logger/user.ts +0 -15
- package/src/logger/util.ts +0 -80
- package/src/middleware.ts +0 -1095
- package/src/otel/config.ts +0 -47
- package/src/otel/console.ts +0 -91
- package/src/otel/exporters/README.md +0 -217
- package/src/otel/exporters/index.ts +0 -3
- package/src/otel/exporters/jsonl-log-exporter.ts +0 -113
- package/src/otel/exporters/jsonl-metric-exporter.ts +0 -120
- package/src/otel/exporters/jsonl-trace-exporter.ts +0 -121
- package/src/otel/fetch.ts +0 -105
- package/src/otel/http.ts +0 -53
- package/src/otel/logger.ts +0 -293
- package/src/otel/otel.ts +0 -354
- package/src/otel/tracestate.ts +0 -108
- package/src/router.ts +0 -75
- package/src/services/evalrun/composite.ts +0 -34
- package/src/services/evalrun/http.ts +0 -167
- package/src/services/evalrun/index.ts +0 -4
- package/src/services/evalrun/json.ts +0 -46
- package/src/services/evalrun/local.ts +0 -28
- package/src/services/local/README.md +0 -1576
- package/src/services/local/_db.ts +0 -353
- package/src/services/local/_router.ts +0 -40
- package/src/services/local/_util.ts +0 -55
- package/src/services/local/email.ts +0 -91
- package/src/services/local/index.ts +0 -9
- package/src/services/local/keyvalue.ts +0 -174
- package/src/services/local/queue.ts +0 -145
- package/src/services/local/stream.ts +0 -358
- package/src/services/local/task.ts +0 -1711
- package/src/services/local/vector.ts +0 -438
- package/src/services/sandbox/http.ts +0 -522
- package/src/services/sandbox/index.ts +0 -1
- package/src/services/session/composite.ts +0 -33
- package/src/services/session/http.ts +0 -167
- package/src/services/session/index.ts +0 -4
- package/src/services/session/json.ts +0 -42
- package/src/services/session/local.ts +0 -33
- package/src/services/thread/local.ts +0 -199
- package/src/session.ts +0 -1960
- package/src/signature.ts +0 -82
- package/src/validator.ts +0 -283
- package/src/version-check.ts +0 -184
- package/src/web.ts +0 -76
- package/src/webrtc-signaling.ts +0 -288
- package/src/workbench.ts +0 -725
package/src/_config.ts
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import { readFileSync, existsSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
|
|
4
|
-
let appName: string | undefined;
|
|
5
|
-
let appVersion: string | undefined;
|
|
6
|
-
let inited = false;
|
|
7
|
-
|
|
8
|
-
export function init() {
|
|
9
|
-
if (inited) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
const f = join(import.meta.dir, isProduction() ? 'package.json' : '/../package.json');
|
|
13
|
-
if (existsSync(f)) {
|
|
14
|
-
try {
|
|
15
|
-
const pkg = JSON.parse(readFileSync(f, 'utf-8'));
|
|
16
|
-
appName = pkg.name;
|
|
17
|
-
appVersion = pkg.version;
|
|
18
|
-
} catch {
|
|
19
|
-
// Fallback to defaults if parsing fails
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
inited = true;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Returns the SDK Version that was used to build this app
|
|
27
|
-
*
|
|
28
|
-
* @returns string
|
|
29
|
-
*/
|
|
30
|
-
export function getSDKVersion(): string {
|
|
31
|
-
return process.env.AGENTUITY_CLOUD_SDK_VERSION ?? 'unknown';
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Returns the App Name that was used when this app was built
|
|
36
|
-
*
|
|
37
|
-
* @returns string
|
|
38
|
-
*/
|
|
39
|
-
export function getAppName(): string {
|
|
40
|
-
init();
|
|
41
|
-
return appName ?? 'unknown';
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Returns the App Version that was used when this app was built
|
|
46
|
-
*
|
|
47
|
-
* @returns string
|
|
48
|
-
*/
|
|
49
|
-
export function getAppVersion(): string {
|
|
50
|
-
init();
|
|
51
|
-
return appVersion ?? 'unknown';
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Returns the Organization ID for this app
|
|
56
|
-
*
|
|
57
|
-
* @returns string
|
|
58
|
-
*/
|
|
59
|
-
export function getOrganizationId(): string | undefined {
|
|
60
|
-
return process.env.AGENTUITY_CLOUD_ORG_ID;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Returns the Project ID for this app
|
|
65
|
-
*
|
|
66
|
-
* @returns string
|
|
67
|
-
*/
|
|
68
|
-
export function getProjectId(): string | undefined {
|
|
69
|
-
return process.env.AGENTUITY_CLOUD_PROJECT_ID;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Returns the Deployment ID for this app that was deployed
|
|
74
|
-
*
|
|
75
|
-
* @returns string | undefined
|
|
76
|
-
*/
|
|
77
|
-
export function getDeploymentId(): string | undefined {
|
|
78
|
-
return process.env.AGENTUITY_CLOUD_DEPLOYMENT_ID;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Returns true if the app is running in dev mode
|
|
83
|
-
*
|
|
84
|
-
* @returns boolean
|
|
85
|
-
*/
|
|
86
|
-
export function isDevMode(): boolean {
|
|
87
|
-
return process.env.AGENTUITY_SDK_DEV_MODE === 'true';
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Returns true if the app is running in production mode
|
|
92
|
-
*
|
|
93
|
-
* @returns boolean
|
|
94
|
-
*/
|
|
95
|
-
export function isProduction(): boolean {
|
|
96
|
-
return getEnvironment() === 'production' && !isDevMode();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Returns the CLI version that was used when this app was built
|
|
101
|
-
*
|
|
102
|
-
* @returns string
|
|
103
|
-
*/
|
|
104
|
-
export function getCLIVersion(): string {
|
|
105
|
-
return process.env.AGENTUITY_CLI_VERSION ?? 'unknown';
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Returns the environment setting for this app
|
|
110
|
-
*
|
|
111
|
-
* @returns string
|
|
112
|
-
*/
|
|
113
|
-
export function getEnvironment(): string {
|
|
114
|
-
return process.env.AGENTUITY_ENVIRONMENT || process.env.NODE_ENV || 'development';
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Returns true if the AGENTUITY_SDK_KEY is set
|
|
119
|
-
*
|
|
120
|
-
* @returns boolean
|
|
121
|
-
*/
|
|
122
|
-
export function isAuthenticated(): boolean {
|
|
123
|
-
return !!process.env.AGENTUITY_SDK_KEY;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Symbol for accessing internal runtime state.
|
|
128
|
-
* Defined here to avoid circular dependency.
|
|
129
|
-
*/
|
|
130
|
-
export const AGENT_RUNTIME = Symbol('AGENT_RUNTIME');
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Symbol for accessing internal agent from AgentRunner.
|
|
134
|
-
* @internal
|
|
135
|
-
*/
|
|
136
|
-
export const INTERNAL_AGENT = Symbol('INTERNAL_AGENT');
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Symbol for tracking the current executing agent (for telemetry).
|
|
140
|
-
* Not exposed on public AgentContext interface.
|
|
141
|
-
* @internal
|
|
142
|
-
*/
|
|
143
|
-
export const CURRENT_AGENT = Symbol('CURRENT_AGENT');
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Symbol for tracking agent IDs that have executed in this session.
|
|
147
|
-
* Used in standalone contexts to track agents for session events.
|
|
148
|
-
* @internal
|
|
149
|
-
*/
|
|
150
|
-
export const AGENT_IDS = Symbol('AGENT_IDS');
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Returns true if running inside the Agentuity agent runtime (dev server or cloud).
|
|
154
|
-
*
|
|
155
|
-
* This is used to determine whether global state (logger, tracer, services) should
|
|
156
|
-
* already be initialized. When running standalone (scripts, Discord bots, cron jobs),
|
|
157
|
-
* this returns false and the runtime will auto-initialize minimal defaults.
|
|
158
|
-
*
|
|
159
|
-
* @returns boolean - true if AGENTUITY_SDK_DEV_MODE=true or AGENTUITY_RUNTIME=yes
|
|
160
|
-
*/
|
|
161
|
-
export function isInsideAgentRuntime(): boolean {
|
|
162
|
-
return process.env.AGENTUITY_SDK_DEV_MODE === 'true' || process.env.AGENTUITY_RUNTIME === 'yes';
|
|
163
|
-
}
|
package/src/_context.ts
DELETED
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
-
import type { Context as HonoContext } from 'hono';
|
|
3
|
-
import type { Tracer } from '@opentelemetry/api';
|
|
4
|
-
import {
|
|
5
|
-
StructuredError,
|
|
6
|
-
type KeyValueStorage,
|
|
7
|
-
type StreamStorage,
|
|
8
|
-
type VectorStorage,
|
|
9
|
-
type SandboxService,
|
|
10
|
-
type QueueService,
|
|
11
|
-
type EmailService,
|
|
12
|
-
type ScheduleService,
|
|
13
|
-
type TaskStorage,
|
|
14
|
-
} from '@agentuity/core';
|
|
15
|
-
import type { AuthInterface } from '@agentuity/core';
|
|
16
|
-
import type {
|
|
17
|
-
AgentContext,
|
|
18
|
-
AgentRegistry,
|
|
19
|
-
AgentRunner,
|
|
20
|
-
AgentRuntimeState,
|
|
21
|
-
AgentMetadata,
|
|
22
|
-
} from './agent';
|
|
23
|
-
import { AGENT_RUNTIME, CURRENT_AGENT } from './_config';
|
|
24
|
-
import type { Logger } from './logger';
|
|
25
|
-
import type WaitUntilHandler from './_waituntil';
|
|
26
|
-
import { registerServices } from './_services';
|
|
27
|
-
import type { Thread, Session } from './session';
|
|
28
|
-
|
|
29
|
-
export interface RequestAgentContextArgs<
|
|
30
|
-
TAgentMap extends AgentRegistry = AgentRegistry,
|
|
31
|
-
TConfig = unknown,
|
|
32
|
-
TAppState = Record<string, never>,
|
|
33
|
-
> {
|
|
34
|
-
sessionId: string;
|
|
35
|
-
agent: TAgentMap;
|
|
36
|
-
logger: Logger;
|
|
37
|
-
tracer: Tracer;
|
|
38
|
-
session: Session;
|
|
39
|
-
thread: Thread;
|
|
40
|
-
handler: WaitUntilHandler;
|
|
41
|
-
config: TConfig;
|
|
42
|
-
app: TAppState;
|
|
43
|
-
runtime: AgentRuntimeState;
|
|
44
|
-
auth?: AuthInterface | null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export class RequestAgentContext<
|
|
48
|
-
TAgentMap extends AgentRegistry = AgentRegistry,
|
|
49
|
-
TConfig = unknown,
|
|
50
|
-
TAppState = Record<string, never>,
|
|
51
|
-
> implements AgentContext<TAgentMap, TConfig, TAppState>
|
|
52
|
-
{
|
|
53
|
-
agent: TAgentMap;
|
|
54
|
-
logger: Logger;
|
|
55
|
-
sessionId: string;
|
|
56
|
-
tracer: Tracer;
|
|
57
|
-
kv!: KeyValueStorage;
|
|
58
|
-
stream!: StreamStorage;
|
|
59
|
-
vector!: VectorStorage;
|
|
60
|
-
sandbox!: SandboxService;
|
|
61
|
-
queue!: QueueService;
|
|
62
|
-
email!: EmailService;
|
|
63
|
-
schedule!: ScheduleService;
|
|
64
|
-
task!: TaskStorage;
|
|
65
|
-
state: Map<string, unknown>;
|
|
66
|
-
session: Session;
|
|
67
|
-
thread: Thread;
|
|
68
|
-
config: TConfig;
|
|
69
|
-
app: TAppState;
|
|
70
|
-
current!: AgentMetadata;
|
|
71
|
-
[AGENT_RUNTIME]: AgentRuntimeState;
|
|
72
|
-
private handler: WaitUntilHandler;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Fallback auth value for non-HTTP contexts (standalone, tests, etc.)
|
|
76
|
-
* @internal
|
|
77
|
-
*/
|
|
78
|
-
private _initialAuth: AuthInterface | null;
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Authentication context - lazily reads from HTTP context if available.
|
|
82
|
-
*
|
|
83
|
-
* This is a getter that prefers the current HTTP context's `c.var.auth`,
|
|
84
|
-
* allowing auth middleware that runs after the agent middleware to still
|
|
85
|
-
* propagate auth to agents.
|
|
86
|
-
*/
|
|
87
|
-
get auth(): AuthInterface | null {
|
|
88
|
-
// Prefer HTTP context var.auth if available (allows late-binding from route middleware)
|
|
89
|
-
if (inHTTPContext()) {
|
|
90
|
-
try {
|
|
91
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
92
|
-
const httpCtx = httpAsyncLocalStorage.getStore() as any;
|
|
93
|
-
if (httpCtx?.var && 'auth' in httpCtx.var) {
|
|
94
|
-
return httpCtx.var.auth ?? null;
|
|
95
|
-
}
|
|
96
|
-
} catch {
|
|
97
|
-
// If HTTP context not available, fall through
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
// Fallback: whatever was passed in at creation time (for standalone/test contexts)
|
|
101
|
-
return this._initialAuth;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Set auth for non-HTTP contexts (standalone, tests).
|
|
106
|
-
* @internal
|
|
107
|
-
*/
|
|
108
|
-
set auth(value: AuthInterface | null) {
|
|
109
|
-
this._initialAuth = value;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
constructor(args: RequestAgentContextArgs<TAgentMap, TConfig, TAppState>) {
|
|
113
|
-
this.agent = args.agent;
|
|
114
|
-
this.logger = args.logger;
|
|
115
|
-
this.sessionId = args.sessionId;
|
|
116
|
-
this.tracer = args.tracer;
|
|
117
|
-
this.thread = args.thread;
|
|
118
|
-
this.session = args.session;
|
|
119
|
-
this.config = args.config;
|
|
120
|
-
this.app = args.app;
|
|
121
|
-
this._initialAuth = args.auth ?? null;
|
|
122
|
-
this[AGENT_RUNTIME] = args.runtime;
|
|
123
|
-
this.state = new Map<string, unknown>();
|
|
124
|
-
this.handler = args.handler;
|
|
125
|
-
registerServices(this, false); // agents already populated via args.agent
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
waitUntil(callback: Promise<void> | (() => void | Promise<void>)): void {
|
|
129
|
-
this.handler.waitUntil(callback);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
134
|
-
const agentAsyncLocalStorage = new AsyncLocalStorage<AgentContext<any, any, any>>();
|
|
135
|
-
const httpAsyncLocalStorage = new AsyncLocalStorage<HonoContext>();
|
|
136
|
-
|
|
137
|
-
export const inAgentContext = (): boolean => {
|
|
138
|
-
const context = agentAsyncLocalStorage.getStore();
|
|
139
|
-
return !!context;
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
export const inHTTPContext = (): boolean => {
|
|
143
|
-
const context = httpAsyncLocalStorage.getStore();
|
|
144
|
-
return !!context;
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
const AgentContextNotAvailableError = StructuredError(
|
|
148
|
-
'AgentContextNotAvailableError',
|
|
149
|
-
'AgentContext is not available'
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
153
|
-
export const getAgentContext = (): AgentContext<any, any, any> => {
|
|
154
|
-
const context = agentAsyncLocalStorage.getStore();
|
|
155
|
-
if (!context) {
|
|
156
|
-
throw new AgentContextNotAvailableError();
|
|
157
|
-
}
|
|
158
|
-
return context;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
const HTTPContextNotAvailableError = StructuredError(
|
|
162
|
-
'HTTPContextNotAvailableError',
|
|
163
|
-
'HTTPContext is not available'
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
export const getHTTPContext = (): HonoContext => {
|
|
167
|
-
const context = httpAsyncLocalStorage.getStore();
|
|
168
|
-
if (!context) {
|
|
169
|
-
throw new HTTPContextNotAvailableError();
|
|
170
|
-
}
|
|
171
|
-
return context;
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
export const getAgentAsyncLocalStorage = () => agentAsyncLocalStorage;
|
|
175
|
-
export const getHTTPAsyncLocalStorage = () => httpAsyncLocalStorage;
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Get the current executing agent's metadata (for internal telemetry use only).
|
|
179
|
-
* Returns undefined if not in an agent context or no agent is executing.
|
|
180
|
-
* @internal
|
|
181
|
-
*/
|
|
182
|
-
export const getCurrentAgentMetadata = (): AgentRunner['metadata'] | undefined => {
|
|
183
|
-
const context = agentAsyncLocalStorage.getStore();
|
|
184
|
-
if (!context) return undefined;
|
|
185
|
-
// Access internal symbol property
|
|
186
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
187
|
-
return (context as any)[CURRENT_AGENT]?.metadata;
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
export const setupRequestAgentContext = <
|
|
191
|
-
TAgentMap extends AgentRegistry = AgentRegistry,
|
|
192
|
-
TConfig = unknown,
|
|
193
|
-
TAppState = Record<string, never>,
|
|
194
|
-
>(
|
|
195
|
-
ctxObject: Record<string, unknown>,
|
|
196
|
-
args: RequestAgentContextArgs<TAgentMap, TConfig, TAppState>,
|
|
197
|
-
next: () => Promise<void>
|
|
198
|
-
) => {
|
|
199
|
-
const ctx = new RequestAgentContext<TAgentMap, TConfig, TAppState>(args);
|
|
200
|
-
|
|
201
|
-
// Note: All Hono context variables are set via c.set() in _server.ts middleware.
|
|
202
|
-
// RequestAgentContext is only used within agents via AsyncLocalStorage.
|
|
203
|
-
// No properties need to be copied between them.
|
|
204
|
-
|
|
205
|
-
// Provide c.waitUntil() directly on route context for consistency with AgentContext
|
|
206
|
-
if (!('waitUntil' in ctxObject)) {
|
|
207
|
-
Object.defineProperty(ctxObject, 'waitUntil', {
|
|
208
|
-
value: (callback: Promise<void> | (() => void | Promise<void>)) => {
|
|
209
|
-
args.handler.waitUntil(callback);
|
|
210
|
-
},
|
|
211
|
-
configurable: true,
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// Provide executionCtx.waitUntil for compatibility with Cloudflare Workers API
|
|
216
|
-
Object.defineProperty(ctxObject, 'executionCtx', {
|
|
217
|
-
get() {
|
|
218
|
-
return {
|
|
219
|
-
waitUntil: (promise: Promise<unknown>) => {
|
|
220
|
-
args.handler.waitUntil(promise as Promise<void>);
|
|
221
|
-
},
|
|
222
|
-
passThroughOnException: () => {},
|
|
223
|
-
props: {},
|
|
224
|
-
};
|
|
225
|
-
},
|
|
226
|
-
configurable: true,
|
|
227
|
-
});
|
|
228
|
-
return agentAsyncLocalStorage.run(ctx, async () => {
|
|
229
|
-
const result = await next();
|
|
230
|
-
return result;
|
|
231
|
-
});
|
|
232
|
-
};
|
|
233
|
-
|
|
234
|
-
export const runInHTTPContext = async <HonoContext>(
|
|
235
|
-
ctx: HonoContext,
|
|
236
|
-
next: () => Promise<void>
|
|
237
|
-
) => {
|
|
238
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
239
|
-
return httpAsyncLocalStorage.run(ctx as any, next);
|
|
240
|
-
};
|
package/src/_events.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Global event bus for Vite-native architecture
|
|
3
|
-
* Replaces the App class event system
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { Agent, AgentContext } from './agent';
|
|
7
|
-
import type { Session, Thread } from './session';
|
|
8
|
-
import { internal } from './logger/internal';
|
|
9
|
-
|
|
10
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
11
|
-
// Note: Generic event system requires 'any' for proper type inference with unknown app states
|
|
12
|
-
|
|
13
|
-
export type AppEventMap<TAppState = Record<string, never>> = {
|
|
14
|
-
'agent.started': [Agent<any, any, any, any, TAppState>, AgentContext<any, any, TAppState>];
|
|
15
|
-
'agent.completed': [Agent<any, any, any, any, TAppState>, AgentContext<any, any, TAppState>];
|
|
16
|
-
'agent.errored': [
|
|
17
|
-
Agent<any, any, any, any, TAppState>,
|
|
18
|
-
AgentContext<any, any, TAppState>,
|
|
19
|
-
Error,
|
|
20
|
-
];
|
|
21
|
-
'session.started': [Session];
|
|
22
|
-
'session.completed': [Session];
|
|
23
|
-
'thread.created': [Thread];
|
|
24
|
-
'thread.destroyed': [Thread];
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
type AppEventCallback<K extends keyof AppEventMap<any>, TAppState = Record<string, never>> = (
|
|
28
|
-
eventName: K,
|
|
29
|
-
...args: AppEventMap<TAppState>[K]
|
|
30
|
-
) => void | Promise<void>;
|
|
31
|
-
|
|
32
|
-
class GlobalEventBus {
|
|
33
|
-
private eventListeners = new Map<keyof AppEventMap<any>, Set<AppEventCallback<any, any>>>();
|
|
34
|
-
|
|
35
|
-
addEventListener<K extends keyof AppEventMap<any>>(
|
|
36
|
-
eventName: K,
|
|
37
|
-
callback: AppEventCallback<K, any>
|
|
38
|
-
): void {
|
|
39
|
-
let callbacks = this.eventListeners.get(eventName);
|
|
40
|
-
if (!callbacks) {
|
|
41
|
-
callbacks = new Set();
|
|
42
|
-
this.eventListeners.set(eventName, callbacks);
|
|
43
|
-
}
|
|
44
|
-
callbacks.add(callback);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
removeEventListener<K extends keyof AppEventMap<any>>(
|
|
48
|
-
eventName: K,
|
|
49
|
-
callback: AppEventCallback<K, any>
|
|
50
|
-
): void {
|
|
51
|
-
const callbacks = this.eventListeners.get(eventName);
|
|
52
|
-
if (!callbacks) return;
|
|
53
|
-
callbacks.delete(callback);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async fireEvent<K extends keyof AppEventMap<any>>(
|
|
57
|
-
eventName: K,
|
|
58
|
-
...args: AppEventMap<any>[K]
|
|
59
|
-
): Promise<void> {
|
|
60
|
-
const callbacks = this.eventListeners.get(eventName);
|
|
61
|
-
if (!callbacks || callbacks.size === 0) return;
|
|
62
|
-
|
|
63
|
-
for (const callback of callbacks) {
|
|
64
|
-
try {
|
|
65
|
-
await callback(eventName, ...args);
|
|
66
|
-
} catch (error) {
|
|
67
|
-
// Log but don't re-throw - event listener errors should not crash the server
|
|
68
|
-
internal.error(`Error in event listener for '${eventName}':`, error);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
clearAllListeners(): void {
|
|
74
|
-
this.eventListeners.clear();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Global singleton instance
|
|
79
|
-
const globalEventBus = new GlobalEventBus();
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Register an event listener for application lifecycle events.
|
|
83
|
-
*
|
|
84
|
-
* Available events:
|
|
85
|
-
* - `agent.started` - Fired when an agent begins execution
|
|
86
|
-
* - `agent.completed` - Fired when an agent completes successfully
|
|
87
|
-
* - `agent.errored` - Fired when an agent throws an error
|
|
88
|
-
* - `session.started` - Fired when a new session starts
|
|
89
|
-
* - `session.completed` - Fired when a session completes
|
|
90
|
-
* - `thread.created` - Fired when a thread is created
|
|
91
|
-
* - `thread.destroyed` - Fired when a thread is destroyed
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* ```typescript
|
|
95
|
-
* import { addEventListener } from '@agentuity/runtime';
|
|
96
|
-
*
|
|
97
|
-
* addEventListener('agent.started', (eventName, agent, ctx) => {
|
|
98
|
-
* console.log(`${agent.metadata.name} started for session ${ctx.sessionId}`);
|
|
99
|
-
* });
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
export function addEventListener<K extends keyof AppEventMap<any>>(
|
|
103
|
-
eventName: K,
|
|
104
|
-
callback: AppEventCallback<K, any>
|
|
105
|
-
): void {
|
|
106
|
-
globalEventBus.addEventListener(eventName, callback);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Remove a previously registered event listener.
|
|
111
|
-
*/
|
|
112
|
-
export function removeEventListener<K extends keyof AppEventMap<any>>(
|
|
113
|
-
eventName: K,
|
|
114
|
-
callback: AppEventCallback<K, any>
|
|
115
|
-
): void {
|
|
116
|
-
globalEventBus.removeEventListener(eventName, callback);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Fire a global application event.
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
* ```typescript
|
|
124
|
-
* import { fireEvent } from '@agentuity/runtime';
|
|
125
|
-
*
|
|
126
|
-
* await fireEvent('session.started', session);
|
|
127
|
-
* await fireEvent('agent.completed', agent, ctx);
|
|
128
|
-
* ```
|
|
129
|
-
*/
|
|
130
|
-
export async function fireEvent<K extends keyof AppEventMap<any>>(
|
|
131
|
-
eventName: K,
|
|
132
|
-
...args: AppEventMap<any>[K]
|
|
133
|
-
): Promise<void> {
|
|
134
|
-
await globalEventBus.fireEvent(eventName, ...args);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Clear all event listeners (useful for testing)
|
|
139
|
-
*/
|
|
140
|
-
export function clearAllEventListeners(): void {
|
|
141
|
-
globalEventBus.clearAllListeners();
|
|
142
|
-
}
|
package/src/_globals.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Type-safe accessors for Symbol.for() global state.
|
|
3
|
-
*
|
|
4
|
-
* These symbols survive bun --hot reloads because globalThis persists
|
|
5
|
-
* across module re-evaluations. Using Symbol.for() ensures the same
|
|
6
|
-
* symbol is returned regardless of which module instance creates it.
|
|
7
|
-
*
|
|
8
|
-
* Each symbol key maps to a specific type — this module centralises
|
|
9
|
-
* the definitions so call-sites don't need casts.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import type { OtelResponse } from './otel/otel';
|
|
13
|
-
|
|
14
|
-
/** Shutdown hook function type (duplicated here to avoid circular dep with app.ts) */
|
|
15
|
-
type ShutdownHook = () => Promise<void> | void;
|
|
16
|
-
|
|
17
|
-
// ── Symbol keys ──────────────────────────────────────────────
|
|
18
|
-
|
|
19
|
-
const keys = {
|
|
20
|
-
originalProcessExit: Symbol.for('@agentuity/runtime:original-process-exit'),
|
|
21
|
-
processExitProtected: Symbol.for('@agentuity/runtime:process-exit-protected'),
|
|
22
|
-
otelInstance: Symbol.for('@agentuity/runtime:otel-instance'),
|
|
23
|
-
originalConsole: Symbol.for('agentuity.originalConsole'),
|
|
24
|
-
serverStarted: Symbol.for('@agentuity/runtime:server-started'),
|
|
25
|
-
localServicesLogged: Symbol.for('@agentuity/runtime:local-services-logged'),
|
|
26
|
-
shutdownHooks: Symbol.for('@agentuity/runtime:shutdown-hooks'),
|
|
27
|
-
s3Patched: Symbol.for('agentuity.s3.patched'),
|
|
28
|
-
} as const;
|
|
29
|
-
|
|
30
|
-
export { keys };
|
|
31
|
-
|
|
32
|
-
// ── Typed getter / setter ────────────────────────────────────
|
|
33
|
-
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
-
const g = globalThis as any;
|
|
36
|
-
|
|
37
|
-
export function getGlobal<T>(key: symbol): T | undefined {
|
|
38
|
-
return g[key] as T | undefined;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function setGlobal<T>(key: symbol, value: T): void {
|
|
42
|
-
g[key] = value;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// ── Convenience accessors for commonly used globals ──────────
|
|
46
|
-
|
|
47
|
-
export const otel = {
|
|
48
|
-
get: (): OtelResponse | undefined => getGlobal<OtelResponse>(keys.otelInstance),
|
|
49
|
-
set: (v: OtelResponse) => setGlobal(keys.otelInstance, v),
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export const originalProcessExit = {
|
|
53
|
-
get: (): ((code?: number) => never) | undefined =>
|
|
54
|
-
getGlobal<(code?: number) => never>(keys.originalProcessExit),
|
|
55
|
-
set: (v: (code?: number) => never) => setGlobal(keys.originalProcessExit, v),
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export const processExitProtected = {
|
|
59
|
-
get: (): boolean => getGlobal<boolean>(keys.processExitProtected) ?? false,
|
|
60
|
-
set: (v: boolean) => setGlobal(keys.processExitProtected, v),
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export const originalConsole = {
|
|
64
|
-
get: (): Console | undefined => getGlobal<Console>(keys.originalConsole),
|
|
65
|
-
set: (v: Console) => setGlobal(keys.originalConsole, v),
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export const serverStarted = {
|
|
69
|
-
get: (): boolean => getGlobal<boolean>(keys.serverStarted) ?? false,
|
|
70
|
-
set: (v: boolean) => setGlobal(keys.serverStarted, v),
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export const localServicesLogged = {
|
|
74
|
-
get: (): boolean => getGlobal<boolean>(keys.localServicesLogged) ?? false,
|
|
75
|
-
set: (v: boolean) => setGlobal(keys.localServicesLogged, v),
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export const shutdownHooks = {
|
|
79
|
-
get: (): ShutdownHook[] => {
|
|
80
|
-
let hooks = getGlobal<ShutdownHook[]>(keys.shutdownHooks);
|
|
81
|
-
if (!hooks) {
|
|
82
|
-
hooks = [];
|
|
83
|
-
setGlobal(keys.shutdownHooks, hooks);
|
|
84
|
-
}
|
|
85
|
-
return hooks;
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
export const s3Patched = {
|
|
90
|
-
get: (): boolean => getGlobal<boolean>(keys.s3Patched) ?? false,
|
|
91
|
-
set: (v: boolean) => setGlobal(keys.s3Patched, v),
|
|
92
|
-
};
|