@agentuity/runtime 0.0.51 → 0.0.53
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/_config.js +99 -0
- package/dist/_config.js.map +1 -0
- package/dist/_context.d.ts +11 -11
- package/dist/_context.d.ts.map +1 -1
- package/dist/_context.js +84 -0
- package/dist/_context.js.map +1 -0
- package/dist/_idle.js +24 -0
- package/dist/_idle.js.map +1 -0
- package/dist/_server.js +489 -0
- package/dist/_server.js.map +1 -0
- package/dist/_services.js +258 -0
- package/dist/_services.js.map +1 -0
- package/dist/_tokens.js +98 -0
- package/dist/_tokens.js.map +1 -0
- package/dist/_util.js +54 -0
- package/dist/_util.js.map +1 -0
- package/dist/_waituntil.js +87 -0
- package/dist/_waituntil.js.map +1 -0
- package/dist/agent.d.ts +24 -15
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +507 -0
- package/dist/agent.js.map +1 -0
- package/dist/app.d.ts +6 -1
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +72 -0
- package/dist/app.js.map +1 -0
- package/dist/eval.d.ts +1 -1
- package/dist/eval.d.ts.map +1 -1
- package/dist/eval.js +2 -0
- package/dist/eval.js.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/io/email.js +154 -0
- package/dist/io/email.js.map +1 -0
- package/dist/logger/console.js +274 -0
- package/dist/logger/console.js.map +1 -0
- package/dist/logger/index.js +3 -0
- package/dist/logger/index.js.map +1 -0
- package/dist/logger/internal.js +133 -0
- package/dist/logger/internal.js.map +1 -0
- package/dist/logger/logger.js +2 -0
- package/dist/logger/logger.js.map +1 -0
- package/dist/logger/user.js +7 -0
- package/dist/logger/user.js.map +1 -0
- package/dist/logger/util.js +77 -0
- package/dist/logger/util.js.map +1 -0
- package/dist/otel/config.js +23 -0
- package/dist/otel/config.js.map +1 -0
- package/dist/otel/console.js +52 -0
- package/dist/otel/console.js.map +1 -0
- package/dist/otel/exporters/index.js +4 -0
- package/dist/otel/exporters/index.js.map +1 -0
- package/dist/otel/exporters/jsonl-log-exporter.js +103 -0
- package/dist/otel/exporters/jsonl-log-exporter.js.map +1 -0
- package/dist/otel/exporters/jsonl-metric-exporter.js +104 -0
- package/dist/otel/exporters/jsonl-metric-exporter.js.map +1 -0
- package/dist/otel/exporters/jsonl-trace-exporter.js +111 -0
- package/dist/otel/exporters/jsonl-trace-exporter.js.map +1 -0
- package/dist/otel/fetch.js +81 -0
- package/dist/otel/fetch.js.map +1 -0
- package/dist/otel/http.js +44 -0
- package/dist/otel/http.js.map +1 -0
- package/dist/otel/logger.js +278 -0
- package/dist/otel/logger.js.map +1 -0
- package/dist/otel/otel.js +233 -0
- package/dist/otel/otel.js.map +1 -0
- package/dist/router.js +350 -0
- package/dist/router.js.map +1 -0
- package/dist/services/evalrun/composite.js +26 -0
- package/dist/services/evalrun/composite.js.map +1 -0
- package/dist/services/evalrun/http.js +74 -0
- package/dist/services/evalrun/http.js.map +1 -0
- package/dist/services/evalrun/index.js +5 -0
- package/dist/services/evalrun/index.js.map +1 -0
- package/dist/services/evalrun/json.js +38 -0
- package/dist/services/evalrun/json.js.map +1 -0
- package/dist/services/evalrun/local.js +22 -0
- package/dist/services/evalrun/local.js.map +1 -0
- package/dist/services/local/_db.js +144 -0
- package/dist/services/local/_db.js.map +1 -0
- package/dist/services/local/_router.js +60 -0
- package/dist/services/local/_router.js.map +1 -0
- package/dist/services/local/_util.js +42 -0
- package/dist/services/local/_util.js.map +1 -0
- package/dist/services/local/index.js +8 -0
- package/dist/services/local/index.js.map +1 -0
- package/dist/services/local/keyvalue.js +114 -0
- package/dist/services/local/keyvalue.js.map +1 -0
- package/dist/services/local/objectstore.js +117 -0
- package/dist/services/local/objectstore.js.map +1 -0
- package/dist/services/local/stream.js +218 -0
- package/dist/services/local/stream.js.map +1 -0
- package/dist/services/local/vector.js +183 -0
- package/dist/services/local/vector.js.map +1 -0
- package/dist/services/session/composite.js +26 -0
- package/dist/services/session/composite.js.map +1 -0
- package/dist/services/session/http.js +42 -0
- package/dist/services/session/http.js.map +1 -0
- package/dist/services/session/index.js +5 -0
- package/dist/services/session/index.js.map +1 -0
- package/dist/services/session/json.js +35 -0
- package/dist/services/session/json.js.map +1 -0
- package/dist/services/session/local.js +22 -0
- package/dist/services/session/local.js.map +1 -0
- package/dist/session.js +199 -0
- package/dist/session.js.map +1 -0
- package/dist/workbench.js +38 -0
- package/dist/workbench.js.map +1 -0
- package/package.json +5 -5
- package/src/_context.ts +34 -13
- package/src/agent.ts +76 -40
- package/src/app.ts +6 -1
- package/src/eval.ts +1 -1
package/dist/_config.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
let appName;
|
|
2
|
+
let appVersion;
|
|
3
|
+
(async () => {
|
|
4
|
+
const f = Bun.file('./package.json');
|
|
5
|
+
if (await f.exists()) {
|
|
6
|
+
const pkg = JSON.parse(await f.text());
|
|
7
|
+
appName = pkg.name;
|
|
8
|
+
appVersion = pkg.version;
|
|
9
|
+
}
|
|
10
|
+
})();
|
|
11
|
+
/**
|
|
12
|
+
* Returns the SDK Version that was used to build this app
|
|
13
|
+
*
|
|
14
|
+
* @returns string
|
|
15
|
+
*/
|
|
16
|
+
export function getSDKVersion() {
|
|
17
|
+
return process.env.AGENTUITY_CLOUD_SDK_VERSION ?? 'unknown';
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Returns the App Name that was used when this app was built
|
|
21
|
+
*
|
|
22
|
+
* @returns string
|
|
23
|
+
*/
|
|
24
|
+
export function getAppName() {
|
|
25
|
+
return appName ?? 'unknown';
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Returns the App Version that was used when this app was built
|
|
29
|
+
*
|
|
30
|
+
* @returns string
|
|
31
|
+
*/
|
|
32
|
+
export function getAppVersion() {
|
|
33
|
+
return appVersion ?? 'unknown';
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns the Organization ID for this app
|
|
37
|
+
*
|
|
38
|
+
* @returns string
|
|
39
|
+
*/
|
|
40
|
+
export function getOrganizationId() {
|
|
41
|
+
return process.env.AGENTUITY_CLOUD_ORG_ID;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Returns the Project ID for this app
|
|
45
|
+
*
|
|
46
|
+
* @returns string
|
|
47
|
+
*/
|
|
48
|
+
export function getProjectId() {
|
|
49
|
+
return process.env.AGENTUITY_CLOUD_PROJECT_ID;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Returns the Deployment ID for this app that was deployed
|
|
53
|
+
*
|
|
54
|
+
* @returns string | undefined
|
|
55
|
+
*/
|
|
56
|
+
export function getDeploymentId() {
|
|
57
|
+
return process.env.AGENTUITY_CLOUD_DEPLOYMENT_ID;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Returns true if the app is running in dev mode
|
|
61
|
+
*
|
|
62
|
+
* @returns boolean
|
|
63
|
+
*/
|
|
64
|
+
export function isDevMode() {
|
|
65
|
+
return process.env.AGENTUITY_SDK_DEV_MODE === 'true';
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Returns true if the app is running in production mode
|
|
69
|
+
*
|
|
70
|
+
* @returns boolean
|
|
71
|
+
*/
|
|
72
|
+
export function isProduction() {
|
|
73
|
+
return process.env.NODE_ENV === 'production' && !isDevMode();
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Returns the CLI version that was used when this app was built
|
|
77
|
+
*
|
|
78
|
+
* @returns string
|
|
79
|
+
*/
|
|
80
|
+
export function getCLIVersion() {
|
|
81
|
+
return process.env.AGENTUITY_CLI_VERSION ?? 'unknown';
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns the environment setting for this app
|
|
85
|
+
*
|
|
86
|
+
* @returns string
|
|
87
|
+
*/
|
|
88
|
+
export function getEnvironment() {
|
|
89
|
+
return process.env.AGENTUITY_ENVIRONMENT || process.env.NODE_ENV || 'development';
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Returns true if the AGENTUITY_SDK_KEY is set
|
|
93
|
+
*
|
|
94
|
+
* @returns boolean
|
|
95
|
+
*/
|
|
96
|
+
export function isAuthenticated() {
|
|
97
|
+
return !!process.env.AGENTUITY_SDK_KEY;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=_config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_config.js","sourceRoot":"","sources":["../src/_config.ts"],"names":[],"mappings":"AAAA,IAAI,OAA2B,CAAC;AAChC,IAAI,UAA8B,CAAC;AAEnC,CAAC,KAAK,IAAI,EAAE;IACX,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACrC,IAAI,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;QACtB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QACvC,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC;QACnB,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC;IAC1B,CAAC;AACF,CAAC,CAAC,EAAE,CAAC;AAEL;;;;GAIG;AACH,MAAM,UAAU,aAAa;IAC5B,OAAO,OAAO,CAAC,GAAG,CAAC,2BAA2B,IAAI,SAAS,CAAC;AAC7D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU;IACzB,OAAO,OAAO,IAAI,SAAS,CAAC;AAC7B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa;IAC5B,OAAO,UAAU,IAAI,SAAS,CAAC;AAChC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB;IAChC,OAAO,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC;AAC3C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY;IAC3B,OAAO,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC;AAC/C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe;IAC9B,OAAO,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC;AAClD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS;IACxB,OAAO,OAAO,CAAC,GAAG,CAAC,sBAAsB,KAAK,MAAM,CAAC;AACtD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY;IAC3B,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,IAAI,CAAC,SAAS,EAAE,CAAC;AAC9D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa;IAC5B,OAAO,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,SAAS,CAAC;AACvD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc;IAC7B,OAAO,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC;AACnF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe;IAC9B,OAAO,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;AACxC,CAAC"}
|
package/dist/_context.d.ts
CHANGED
|
@@ -2,15 +2,15 @@ import { AsyncLocalStorage } from 'node:async_hooks';
|
|
|
2
2
|
import type { Context as HonoContext } from 'hono';
|
|
3
3
|
import type { Tracer } from '@opentelemetry/api';
|
|
4
4
|
import type { KeyValueStorage, ObjectStorage, StreamStorage, VectorStorage } from '@agentuity/core';
|
|
5
|
-
import type { AgentContext, AgentName } from './agent';
|
|
5
|
+
import type { AgentContext, AgentName, AgentRegistry, AgentRunner } from './agent';
|
|
6
6
|
import type { Logger } from './logger';
|
|
7
7
|
import type WaitUntilHandler from './_waituntil';
|
|
8
8
|
import type { Thread, Session } from './session';
|
|
9
|
-
export interface RequestAgentContextArgs<TAgentMap,
|
|
9
|
+
export interface RequestAgentContextArgs<TAgentMap extends AgentRegistry = AgentRegistry, TCurrent extends AgentRunner<any, any, any> | undefined = AgentRunner<any, any, any> | undefined, TParent extends AgentRunner<any, any, any> | undefined = AgentRunner<any, any, any> | undefined> {
|
|
10
10
|
sessionId: string;
|
|
11
11
|
agent: TAgentMap;
|
|
12
|
-
current:
|
|
13
|
-
parent
|
|
12
|
+
current: TCurrent;
|
|
13
|
+
parent: TParent;
|
|
14
14
|
agentName: AgentName;
|
|
15
15
|
logger: Logger;
|
|
16
16
|
tracer: Tracer;
|
|
@@ -18,10 +18,10 @@ export interface RequestAgentContextArgs<TAgentMap, TAgent> {
|
|
|
18
18
|
thread: Thread;
|
|
19
19
|
handler: WaitUntilHandler;
|
|
20
20
|
}
|
|
21
|
-
export declare class RequestAgentContext<TAgentMap,
|
|
21
|
+
export declare class RequestAgentContext<TAgentMap extends AgentRegistry = AgentRegistry, TCurrent extends AgentRunner<any, any, any> | undefined = AgentRunner<any, any, any> | undefined, TParent extends AgentRunner<any, any, any> | undefined = AgentRunner<any, any, any> | undefined> implements AgentContext<TAgentMap, TCurrent, TParent> {
|
|
22
22
|
agent: TAgentMap;
|
|
23
|
-
current:
|
|
24
|
-
parent
|
|
23
|
+
current: TCurrent;
|
|
24
|
+
parent: TParent;
|
|
25
25
|
agentName: AgentName;
|
|
26
26
|
logger: Logger;
|
|
27
27
|
sessionId: string;
|
|
@@ -34,15 +34,15 @@ export declare class RequestAgentContext<TAgentMap, TAgent> implements AgentCont
|
|
|
34
34
|
session: Session;
|
|
35
35
|
thread: Thread;
|
|
36
36
|
private handler;
|
|
37
|
-
constructor(args: RequestAgentContextArgs<TAgentMap,
|
|
37
|
+
constructor(args: RequestAgentContextArgs<TAgentMap, TCurrent, TParent>);
|
|
38
38
|
waitUntil(callback: Promise<void> | (() => void | Promise<void>)): void;
|
|
39
39
|
}
|
|
40
40
|
export declare const inAgentContext: () => boolean;
|
|
41
41
|
export declare const inHTTPContext: () => boolean;
|
|
42
|
-
export declare const getAgentContext: () => AgentContext
|
|
42
|
+
export declare const getAgentContext: () => AgentContext<any, any, any>;
|
|
43
43
|
export declare const getHTTPContext: () => HonoContext;
|
|
44
|
-
export declare const getAgentAsyncLocalStorage: () => AsyncLocalStorage<AgentContext
|
|
44
|
+
export declare const getAgentAsyncLocalStorage: () => AsyncLocalStorage<AgentContext<any, any, any>>;
|
|
45
45
|
export declare const getHTTPAsyncLocalStorage: () => AsyncLocalStorage<HonoContext<any, any, {}>>;
|
|
46
|
-
export declare const runInAgentContext: <TAgentMap,
|
|
46
|
+
export declare const runInAgentContext: <TAgentMap extends AgentRegistry = AgentRegistry, TCurrent extends AgentRunner<any, any, any> | undefined = AgentRunner<any, any, any> | undefined, TParent extends AgentRunner<any, any, any> | undefined = AgentRunner<any, any, any> | undefined>(ctxObject: Record<string, unknown>, args: RequestAgentContextArgs<TAgentMap, TCurrent, TParent>, next: () => Promise<void>) => Promise<void>;
|
|
47
47
|
export declare const runInHTTPContext: <HonoContext>(ctx: HonoContext, next: () => Promise<void>) => Promise<void>;
|
|
48
48
|
//# sourceMappingURL=_context.d.ts.map
|
package/dist/_context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_context.d.ts","sourceRoot":"","sources":["../src/_context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,MAAM,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACpG,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"_context.d.ts","sourceRoot":"","sources":["../src/_context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,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CAAC;AAEF,eAAO,MAAM,yBAAyB,sDAA+B,CAAC;AACtE,eAAO,MAAM,wBAAwB,oDAA8B,CAAC;AAEpE,eAAO,MAAM,iBAAiB,GAC7B,SAAS,SAAS,aAAa,GAAG,aAAa,EAE/C,QAAQ,SAAS,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,SAAS,EAEhG,OAAO,SAAS,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,SAAS,EAE/F,WAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,MAAM,uBAAuB,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,CAAC,EAC3D,MAAM,MAAM,OAAO,CAAC,IAAI,CAAC,kBAezB,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAU,WAAW,EACjD,KAAK,WAAW,EAChB,MAAM,MAAM,OAAO,CAAC,IAAI,CAAC,kBAIzB,CAAC"}
|
package/dist/_context.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { registerServices } from './_services';
|
|
3
|
+
export class RequestAgentContext {
|
|
4
|
+
agent;
|
|
5
|
+
current;
|
|
6
|
+
parent;
|
|
7
|
+
agentName;
|
|
8
|
+
logger;
|
|
9
|
+
sessionId;
|
|
10
|
+
tracer;
|
|
11
|
+
kv;
|
|
12
|
+
objectstore;
|
|
13
|
+
stream;
|
|
14
|
+
vector;
|
|
15
|
+
state;
|
|
16
|
+
session;
|
|
17
|
+
thread;
|
|
18
|
+
handler;
|
|
19
|
+
constructor(args) {
|
|
20
|
+
this.agent = args.agent;
|
|
21
|
+
this.current = args.current;
|
|
22
|
+
this.parent = args.parent;
|
|
23
|
+
this.agentName = args.agentName;
|
|
24
|
+
this.logger = args.logger;
|
|
25
|
+
this.sessionId = args.sessionId;
|
|
26
|
+
this.tracer = args.tracer;
|
|
27
|
+
this.thread = args.thread;
|
|
28
|
+
this.session = args.session;
|
|
29
|
+
this.state = new Map();
|
|
30
|
+
this.handler = args.handler;
|
|
31
|
+
registerServices(this, false); // agents already populated via args.agent
|
|
32
|
+
}
|
|
33
|
+
waitUntil(callback) {
|
|
34
|
+
this.handler.waitUntil(callback);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
const agentAsyncLocalStorage = new AsyncLocalStorage();
|
|
39
|
+
const httpAsyncLocalStorage = new AsyncLocalStorage();
|
|
40
|
+
export const inAgentContext = () => {
|
|
41
|
+
const context = agentAsyncLocalStorage.getStore();
|
|
42
|
+
return !!context;
|
|
43
|
+
};
|
|
44
|
+
export const inHTTPContext = () => {
|
|
45
|
+
const context = httpAsyncLocalStorage.getStore();
|
|
46
|
+
return !!context;
|
|
47
|
+
};
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
+
export const getAgentContext = () => {
|
|
50
|
+
const context = agentAsyncLocalStorage.getStore();
|
|
51
|
+
if (!context) {
|
|
52
|
+
throw new Error('AgentContext is not available');
|
|
53
|
+
}
|
|
54
|
+
return context;
|
|
55
|
+
};
|
|
56
|
+
export const getHTTPContext = () => {
|
|
57
|
+
const context = httpAsyncLocalStorage.getStore();
|
|
58
|
+
if (!context) {
|
|
59
|
+
throw new Error('HTTPContext is not available');
|
|
60
|
+
}
|
|
61
|
+
return context;
|
|
62
|
+
};
|
|
63
|
+
export const getAgentAsyncLocalStorage = () => agentAsyncLocalStorage;
|
|
64
|
+
export const getHTTPAsyncLocalStorage = () => httpAsyncLocalStorage;
|
|
65
|
+
export const runInAgentContext = (ctxObject, args, next) => {
|
|
66
|
+
const ctx = new RequestAgentContext(args);
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
68
|
+
const _ctx = ctx;
|
|
69
|
+
Object.getOwnPropertyNames(ctx).forEach((k) => {
|
|
70
|
+
ctxObject[k] = _ctx[k];
|
|
71
|
+
});
|
|
72
|
+
for (const k of ['waitUntil']) {
|
|
73
|
+
ctxObject[k] = _ctx[k];
|
|
74
|
+
}
|
|
75
|
+
return agentAsyncLocalStorage.run(ctx, async () => {
|
|
76
|
+
const result = await next();
|
|
77
|
+
return result;
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
export const runInHTTPContext = async (ctx, next) => {
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
82
|
+
return httpAsyncLocalStorage.run(ctx, next);
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=_context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_context.js","sourceRoot":"","sources":["../src/_context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAOrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAsB/C,MAAM,OAAO,mBAAmB;IAQ/B,KAAK,CAAY;IACjB,OAAO,CAAW;IAClB,MAAM,CAAU;IAChB,SAAS,CAAY;IACrB,MAAM,CAAS;IACf,SAAS,CAAS;IAClB,MAAM,CAAS;IACf,EAAE,CAAmB;IACrB,WAAW,CAAiB;IAC5B,MAAM,CAAiB;IACvB,MAAM,CAAiB;IACvB,KAAK,CAAuB;IAC5B,OAAO,CAAU;IACjB,MAAM,CAAS;IACP,OAAO,CAAmB;IAElC,YAAY,IAA2D;QACtE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,SAAS,GAAG,IA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xB,EAAE;IACH,8DAA8D;IAC9D,OAAO,qBAAqB,CAAC,GAAG,CAAC,GAAU,EAAE,IAAI,CAAC,CAAC;AACpD,CAAC,CAAC"}
|
package/dist/_idle.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { getServer } from './_server';
|
|
2
|
+
import { hasWaitUntilPending } from './_waituntil';
|
|
3
|
+
/**
|
|
4
|
+
* returns true if the server is idle (no pending requests, websockets, or waitUntil tasks)
|
|
5
|
+
*
|
|
6
|
+
* @returns true if idle
|
|
7
|
+
*/
|
|
8
|
+
export function isIdle() {
|
|
9
|
+
if (hasWaitUntilPending()) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
const _server = getServer();
|
|
13
|
+
if (_server) {
|
|
14
|
+
// we have to check >1 since the idle request itself will show up as a pending request
|
|
15
|
+
if (_server.pendingRequests > 1) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
if (_server.pendingWebSockets > 0) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=_idle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_idle.js","sourceRoot":"","sources":["../src/_idle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAEnD;;;;GAIG;AACH,MAAM,UAAU,MAAM;IACrB,IAAI,mBAAmB,EAAE,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACd,CAAC;IAED,MAAM,OAAO,GAAG,SAAS,EAAE,CAAC;IAC5B,IAAI,OAAO,EAAE,CAAC;QACb,sFAAsF;QACtF,IAAI,OAAO,CAAC,eAAe,GAAG,CAAC,EAAE,CAAC;YACjC,OAAO,KAAK,CAAC;QACd,CAAC;QACD,IAAI,OAAO,CAAC,iBAAiB,GAAG,CAAC,EAAE,CAAC;YACnC,OAAO,KAAK,CAAC;QACd,CAAC;IACF,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC"}
|