@naylence/agent-sdk 0.3.13 → 0.3.15
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/browser/index.js +3344 -60377
- package/dist/browser/index.js.map +1 -1
- package/dist/cjs/agent-isomorphic.d.ts +11 -0
- package/dist/cjs/agent-isomorphic.js +30 -0
- package/dist/cjs/agent-isomorphic.js.map +1 -0
- package/dist/cjs/browser.d.ts +3 -1
- package/dist/cjs/browser.js +17 -1
- package/dist/cjs/browser.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -3
- package/dist/cjs/index.js +1 -32
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/naylence/agent/factory-manifest.browser.d.ts +5 -0
- package/dist/cjs/naylence/agent/factory-manifest.browser.js +7 -0
- package/dist/cjs/naylence/agent/factory-manifest.browser.js.map +1 -0
- package/dist/cjs/naylence/agent/factory-manifest.d.ts +5 -0
- package/dist/cjs/naylence/agent/factory-manifest.js +46 -0
- package/dist/cjs/naylence/agent/factory-manifest.js.map +1 -0
- package/dist/cjs/naylence/agent/gateway/agent-http-gateway-listener-factory.d.ts +23 -0
- package/dist/cjs/naylence/agent/gateway/agent-http-gateway-listener-factory.js +144 -0
- package/dist/cjs/naylence/agent/gateway/agent-http-gateway-listener-factory.js.map +1 -0
- package/dist/cjs/naylence/agent/gateway/agent-http-gateway-listener.d.ts +40 -0
- package/dist/cjs/naylence/agent/gateway/agent-http-gateway-listener.js +347 -0
- package/dist/cjs/naylence/agent/gateway/agent-http-gateway-listener.js.map +1 -0
- package/dist/cjs/naylence/agent/index.d.ts +1 -0
- package/dist/cjs/naylence/agent/index.js +1 -0
- package/dist/cjs/naylence/agent/index.js.map +1 -1
- package/dist/cjs/naylence/agent/util/register-agent-factories.d.ts +4 -0
- package/dist/cjs/naylence/agent/util/register-agent-factories.js +132 -0
- package/dist/cjs/naylence/agent/util/register-agent-factories.js.map +1 -0
- package/dist/cjs/node.d.ts +5 -0
- package/dist/cjs/node.js +46 -0
- package/dist/cjs/node.js.map +1 -0
- package/dist/cjs/plugin.js +2 -0
- package/dist/cjs/plugin.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agent-isomorphic.d.ts +18 -0
- package/dist/esm/agent-isomorphic.js +21 -0
- package/dist/esm/agent-isomorphic.js.map +1 -0
- package/dist/esm/browser.d.ts +9 -1
- package/dist/esm/browser.js +21 -3
- package/dist/esm/browser.js.map +1 -1
- package/dist/esm/index.d.ts +7 -3
- package/dist/esm/index.js +7 -34
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/naylence/agent/factory-manifest.browser.d.ts +11 -0
- package/dist/esm/naylence/agent/factory-manifest.browser.js +11 -0
- package/dist/esm/naylence/agent/factory-manifest.browser.js.map +1 -0
- package/dist/esm/naylence/agent/factory-manifest.d.ts +11 -0
- package/dist/esm/naylence/agent/factory-manifest.js +17 -0
- package/dist/esm/naylence/agent/factory-manifest.js.map +1 -0
- package/dist/esm/naylence/agent/gateway/agent-http-gateway-listener-factory.d.ts +37 -0
- package/dist/esm/naylence/agent/gateway/agent-http-gateway-listener-factory.js +128 -0
- package/dist/esm/naylence/agent/gateway/agent-http-gateway-listener-factory.js.map +1 -0
- package/dist/esm/naylence/agent/gateway/agent-http-gateway-listener.d.ts +50 -0
- package/dist/esm/naylence/agent/gateway/agent-http-gateway-listener.js +350 -0
- package/dist/esm/naylence/agent/gateway/agent-http-gateway-listener.js.map +1 -0
- package/dist/esm/naylence/agent/index.d.ts +5 -0
- package/dist/esm/naylence/agent/index.js +5 -0
- package/dist/esm/naylence/agent/index.js.map +1 -1
- package/dist/esm/naylence/agent/util/register-agent-factories.d.ts +4 -0
- package/dist/esm/naylence/agent/util/register-agent-factories.js +103 -0
- package/dist/esm/naylence/agent/util/register-agent-factories.js.map +1 -0
- package/dist/esm/node.d.ts +11 -0
- package/dist/esm/node.js +37 -0
- package/dist/esm/node.js.map +1 -0
- package/dist/esm/plugin.js +2 -4
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +2 -2
- package/dist/types/agent-isomorphic.d.ts +19 -0
- package/dist/types/agent-isomorphic.d.ts.map +1 -0
- package/dist/types/browser.d.ts +9 -1
- package/dist/types/browser.d.ts.map +1 -1
- package/dist/types/index.d.ts +7 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/naylence/agent/factory-manifest.browser.d.ts +12 -0
- package/dist/types/naylence/agent/factory-manifest.browser.d.ts.map +1 -0
- package/dist/types/naylence/agent/factory-manifest.d.ts +12 -0
- package/dist/types/naylence/agent/factory-manifest.d.ts.map +1 -0
- package/dist/types/naylence/agent/gateway/agent-http-gateway-listener-factory.d.ts +38 -0
- package/dist/types/naylence/agent/gateway/agent-http-gateway-listener-factory.d.ts.map +1 -0
- package/dist/types/naylence/agent/gateway/agent-http-gateway-listener.d.ts +51 -0
- package/dist/types/naylence/agent/gateway/agent-http-gateway-listener.d.ts.map +1 -0
- package/dist/types/naylence/agent/index.d.ts +5 -0
- package/dist/types/naylence/agent/index.d.ts.map +1 -1
- package/dist/types/naylence/agent/util/register-agent-factories.d.ts +5 -0
- package/dist/types/naylence/agent/util/register-agent-factories.d.ts.map +1 -0
- package/dist/types/node.d.ts +12 -0
- package/dist/types/node.d.ts.map +1 -0
- package/dist/types/plugin.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +26 -15
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Isomorphic entry point for Naylence Agent SDK.
|
|
3
|
+
*
|
|
4
|
+
* Exports utilities, agent base classes, and cross-platform helpers that
|
|
5
|
+
* do not rely on Node.js-only dependencies. This file purposefully excludes
|
|
6
|
+
* node-only modules such as the HTTP gateway listener.
|
|
7
|
+
*/
|
|
8
|
+
// Agent core exports (all browser-safe)
|
|
9
|
+
export * from './naylence/agent/a2a-types.js';
|
|
10
|
+
export * from './naylence/agent/agent.js';
|
|
11
|
+
export * from './naylence/agent/base-agent.js';
|
|
12
|
+
export * from './naylence/agent/background-task-agent.js';
|
|
13
|
+
export { AgentProxy } from './naylence/agent/agent-proxy.js';
|
|
14
|
+
export * from './naylence/agent/errors.js';
|
|
15
|
+
export * from './naylence/agent/rpc-adapter.js';
|
|
16
|
+
export * from './naylence/agent/util.js';
|
|
17
|
+
export * from './naylence/agent/configs.js';
|
|
18
|
+
export * from './naylence/agent/util/register-agent-factories.js';
|
|
19
|
+
// Register default agent proxy factory (side-effect)
|
|
20
|
+
import './naylence/agent/agent-proxy-default.js';
|
|
21
|
+
//# sourceMappingURL=agent-isomorphic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-isomorphic.js","sourceRoot":"","sources":["../../src/agent-isomorphic.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,wCAAwC;AACxC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,2CAA2C,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iCAAiC,CAAC;AAChD,cAAc,0BAA0B,CAAC;AACzC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mDAAmD,CAAC;AAElE,qDAAqD;AACrD,OAAO,yCAAyC,CAAC"}
|
package/dist/esm/browser.d.ts
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Browser entry point for Naylence Agent SDK.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports isomorphic components and registers the plugin in browser environments.
|
|
5
|
+
* Does NOT include Node.js-specific components like the HTTP gateway listener.
|
|
6
|
+
*/
|
|
7
|
+
import '@naylence/runtime';
|
|
8
|
+
export * from './agent-isomorphic.js';
|
|
9
|
+
export { default } from './plugin.js';
|
package/dist/esm/browser.js
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Browser entry point for Naylence Agent SDK.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports isomorphic components and registers the plugin in browser environments.
|
|
5
|
+
* Does NOT include Node.js-specific components like the HTTP gateway listener.
|
|
6
|
+
*/
|
|
7
|
+
import '@naylence/runtime';
|
|
8
|
+
import plugin from './plugin.js';
|
|
9
|
+
// Auto-register the plugin in browser environments
|
|
10
|
+
(async () => {
|
|
11
|
+
try {
|
|
12
|
+
await plugin.register();
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
console.error('[naylence-agent-sdk] Failed to auto-register plugin:', err);
|
|
16
|
+
}
|
|
17
|
+
})();
|
|
18
|
+
// Re-export all isomorphic components
|
|
19
|
+
export * from './agent-isomorphic.js';
|
|
20
|
+
// Export plugin as default for naylence-factory plugin system
|
|
21
|
+
export { default } from './plugin.js';
|
|
4
22
|
//# sourceMappingURL=browser.js.map
|
package/dist/esm/browser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/browser.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/browser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,mBAAmB,CAAC;AAC3B,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,mDAAmD;AACnD,CAAC,KAAK,IAAI,EAAE;IACV,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,QAAQ,EAAE,CAAC;IAC1B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,sDAAsD,EAAE,GAAG,CAAC,CAAC;IAC7E,CAAC;AACH,CAAC,CAAC,EAAE,CAAC;AAEL,sCAAsC;AACtC,cAAc,uBAAuB,CAAC;AAEtC,8DAA8D;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Isomorphic entry point for Naylence Agent SDK.
|
|
3
|
+
*
|
|
4
|
+
* This is the default entry point and contains only cross-platform components.
|
|
5
|
+
* For Node.js-specific components (HTTP gateway listener), use '@naylence/agent-sdk/node'.
|
|
6
|
+
*/
|
|
7
|
+
export * from './agent-isomorphic.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,35 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
try {
|
|
9
|
-
await plugin.register();
|
|
10
|
-
}
|
|
11
|
-
catch (err) {
|
|
12
|
-
console.error('[naylence-agent-sdk] Failed to auto-register plugin:', err);
|
|
13
|
-
}
|
|
14
|
-
})();
|
|
15
|
-
const g = (typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {});
|
|
16
|
-
const proc = g.process || (typeof process !== 'undefined' ? process : undefined);
|
|
17
|
-
const isNode = typeof process !== 'undefined' &&
|
|
18
|
-
process.versions != null &&
|
|
19
|
-
process.versions.node != null;
|
|
20
|
-
// Only in Node.js: populate FAME_PLUGINS so child processes inherit it.
|
|
21
|
-
// In the browser, we rely on the direct registration above.
|
|
22
|
-
if (isNode && proc && proc.env) {
|
|
23
|
-
const pluginName = '@naylence/agent-sdk';
|
|
24
|
-
const current = proc.env.FAME_PLUGINS || '';
|
|
25
|
-
const plugins = current.split(',').map((p) => p.trim());
|
|
26
|
-
if (!plugins.includes(pluginName)) {
|
|
27
|
-
proc.env.FAME_PLUGINS = current
|
|
28
|
-
? `${current},${pluginName}`
|
|
29
|
-
: pluginName;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
export * from './naylence/agent/index.js';
|
|
33
|
-
// Export plugin as default for naylence-factory plugin system
|
|
34
|
-
export { default } from './plugin.js';
|
|
1
|
+
/**
|
|
2
|
+
* Isomorphic entry point for Naylence Agent SDK.
|
|
3
|
+
*
|
|
4
|
+
* This is the default entry point and contains only cross-platform components.
|
|
5
|
+
* For Node.js-specific components (HTTP gateway listener), use '@naylence/agent-sdk/node'.
|
|
6
|
+
*/
|
|
7
|
+
export * from './agent-isomorphic.js';
|
|
35
8
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AUTO-GENERATED FILE. DO NOT EDIT DIRECTLY.
|
|
3
|
+
* Generated by scripts/generate-factory-manifest.mjs
|
|
4
|
+
*
|
|
5
|
+
* Provides the list of agent-sdk factory modules for registration.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MODULES: readonly [];
|
|
8
|
+
export type FactoryModuleSpec = (typeof MODULES)[number];
|
|
9
|
+
export type FactoryModuleLoader = () => Promise<Record<string, unknown>>;
|
|
10
|
+
export declare const MODULE_LOADERS: Record<FactoryModuleSpec, FactoryModuleLoader>;
|
|
11
|
+
export declare const NODE_ONLY_FACTORY_MODULES: Set<never>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AUTO-GENERATED FILE. DO NOT EDIT DIRECTLY.
|
|
3
|
+
* Generated by scripts/generate-factory-manifest.mjs
|
|
4
|
+
*
|
|
5
|
+
* Provides the list of agent-sdk factory modules for registration.
|
|
6
|
+
*/
|
|
7
|
+
export const MODULES = [];
|
|
8
|
+
export const MODULE_LOADERS = {};
|
|
9
|
+
// Node-only factory modules - skipped at runtime in browser environments
|
|
10
|
+
export const NODE_ONLY_FACTORY_MODULES = new Set([]);
|
|
11
|
+
//# sourceMappingURL=factory-manifest.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory-manifest.browser.js","sourceRoot":"","sources":["../../../../src/naylence/agent/factory-manifest.browser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,EAAW,CAAC;AAKnC,MAAM,CAAC,MAAM,cAAc,GAAmD,EAE7E,CAAC;AAEF,yEAAyE;AACzE,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAI,GAAG,CAAoB,EAEnE,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AUTO-GENERATED FILE. DO NOT EDIT DIRECTLY.
|
|
3
|
+
* Generated by scripts/generate-factory-manifest.mjs
|
|
4
|
+
*
|
|
5
|
+
* Provides the list of agent-sdk factory modules for registration.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MODULES: readonly ["./gateway/agent-http-gateway-listener-factory.js"];
|
|
8
|
+
export type FactoryModuleSpec = (typeof MODULES)[number];
|
|
9
|
+
export type FactoryModuleLoader = () => Promise<Record<string, unknown>>;
|
|
10
|
+
export declare const MODULE_LOADERS: Record<FactoryModuleSpec, FactoryModuleLoader>;
|
|
11
|
+
export declare const NODE_ONLY_FACTORY_MODULES: Set<"./gateway/agent-http-gateway-listener-factory.js">;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AUTO-GENERATED FILE. DO NOT EDIT DIRECTLY.
|
|
3
|
+
* Generated by scripts/generate-factory-manifest.mjs
|
|
4
|
+
*
|
|
5
|
+
* Provides the list of agent-sdk factory modules for registration.
|
|
6
|
+
*/
|
|
7
|
+
export const MODULES = [
|
|
8
|
+
"./gateway/agent-http-gateway-listener-factory.js"
|
|
9
|
+
];
|
|
10
|
+
export const MODULE_LOADERS = {
|
|
11
|
+
"./gateway/agent-http-gateway-listener-factory.js": () => import(/* webpackIgnore: true */ /* @vite-ignore */ "./gateway/agent-http-gateway-listener-factory.js"),
|
|
12
|
+
};
|
|
13
|
+
// Node-only factory modules - skipped at runtime in browser environments
|
|
14
|
+
export const NODE_ONLY_FACTORY_MODULES = new Set([
|
|
15
|
+
"./gateway/agent-http-gateway-listener-factory.js",
|
|
16
|
+
]);
|
|
17
|
+
//# sourceMappingURL=factory-manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factory-manifest.js","sourceRoot":"","sources":["../../../../src/naylence/agent/factory-manifest.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,kDAAkD;CAC1C,CAAC;AAKX,MAAM,CAAC,MAAM,cAAc,GAAmD;IAC5E,kDAAkD,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,yBAAyB,CAAC,kBAAkB,CAAC,kDAAkD,CAAC;CAClK,CAAC;AAEF,yEAAyE;AACzE,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAI,GAAG,CAAoB;IAClE,kDAAkD;CACnD,CAAC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory for creating AgentHttpGatewayListener instances.
|
|
3
|
+
*
|
|
4
|
+
* This file is Node.js-only but is structured to avoid static value imports from
|
|
5
|
+
* @naylence/runtime/node so that bundlers don't fail when analyzing the module graph.
|
|
6
|
+
* Type imports are safe (erased at compile time). Actual runtime values are loaded dynamically.
|
|
7
|
+
*/
|
|
8
|
+
import type { GatewayLimits } from './agent-http-gateway-listener.js';
|
|
9
|
+
import type { Authorizer, HttpServer, TransportListener, TransportListenerConfig } from '@naylence/runtime/node';
|
|
10
|
+
export interface AgentHttpGatewayListenerFactoryConfig extends TransportListenerConfig {
|
|
11
|
+
type: 'AgentHttpGatewayListener';
|
|
12
|
+
basePath?: string;
|
|
13
|
+
authorizer?: Record<string, unknown> | null;
|
|
14
|
+
/** Structural limits for routing/envelope fields */
|
|
15
|
+
limits?: GatewayLimits;
|
|
16
|
+
}
|
|
17
|
+
export interface CreateAgentHttpGatewayListenerOptions {
|
|
18
|
+
httpServer?: HttpServer;
|
|
19
|
+
authorizer?: Authorizer | null;
|
|
20
|
+
}
|
|
21
|
+
export declare const FACTORY_META: {
|
|
22
|
+
readonly base: "TransportListenerFactory";
|
|
23
|
+
readonly key: "AgentHttpGatewayListener";
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Factory for creating AgentHttpGatewayListener instances.
|
|
27
|
+
*
|
|
28
|
+
* This factory does not extend BaseTransportListenerFactory to avoid static imports
|
|
29
|
+
* from @naylence/runtime/node. Instead, it implements the factory interface directly.
|
|
30
|
+
*/
|
|
31
|
+
export declare class AgentHttpGatewayListenerFactory {
|
|
32
|
+
readonly type = "AgentHttpGatewayListener";
|
|
33
|
+
readonly priority = 1000;
|
|
34
|
+
create(config?: AgentHttpGatewayListenerFactoryConfig | Record<string, unknown> | null, ...factoryArgs: unknown[]): Promise<TransportListener>;
|
|
35
|
+
private _createDefaultHttpServer;
|
|
36
|
+
}
|
|
37
|
+
export default AgentHttpGatewayListenerFactory;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory for creating AgentHttpGatewayListener instances.
|
|
3
|
+
*
|
|
4
|
+
* This file is Node.js-only but is structured to avoid static value imports from
|
|
5
|
+
* @naylence/runtime/node so that bundlers don't fail when analyzing the module graph.
|
|
6
|
+
* Type imports are safe (erased at compile time). Actual runtime values are loaded dynamically.
|
|
7
|
+
*/
|
|
8
|
+
// Factory base type constant - matches @naylence/runtime value
|
|
9
|
+
const TRANSPORT_LISTENER_FACTORY_BASE_TYPE = 'TransportListenerFactory';
|
|
10
|
+
// Cached module promises for lazy loading
|
|
11
|
+
let runtimeNodeModulePromise = null;
|
|
12
|
+
/**
|
|
13
|
+
* Dynamically load @naylence/runtime/node module.
|
|
14
|
+
* Uses dynamic import with @vite-ignore to prevent bundler from following this path.
|
|
15
|
+
*/
|
|
16
|
+
async function getRuntimeNodeModule() {
|
|
17
|
+
if (!runtimeNodeModulePromise) {
|
|
18
|
+
// Dynamic import with @vite-ignore to prevent bundler from following this path
|
|
19
|
+
runtimeNodeModulePromise = import(/* webpackIgnore: true */ /* @vite-ignore */ '@naylence/runtime/node');
|
|
20
|
+
}
|
|
21
|
+
return runtimeNodeModulePromise;
|
|
22
|
+
}
|
|
23
|
+
let gatewayListenerModulePromise = null;
|
|
24
|
+
async function getGatewayListenerModule() {
|
|
25
|
+
if (!gatewayListenerModulePromise) {
|
|
26
|
+
// Dynamic import with @vite-ignore to prevent bundler from following this path
|
|
27
|
+
gatewayListenerModulePromise = import(/* webpackIgnore: true */ /* @vite-ignore */ './agent-http-gateway-listener.js');
|
|
28
|
+
}
|
|
29
|
+
return gatewayListenerModulePromise;
|
|
30
|
+
}
|
|
31
|
+
function addServerEventListener(server, listeners) {
|
|
32
|
+
if (!server || !Array.isArray(listeners)) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const candidate = server;
|
|
36
|
+
if (!candidate || typeof candidate !== 'object') {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const listener = candidate;
|
|
40
|
+
if (typeof listener.priority === 'number' && !listeners.includes(listener)) {
|
|
41
|
+
listeners.push(listener);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function normalizeConfig(config) {
|
|
45
|
+
const record = (config ?? {});
|
|
46
|
+
const hostValue = typeof record.host === 'string' && record.host.trim().length > 0 ? record.host.trim() : '0.0.0.0';
|
|
47
|
+
const rawPort = record.port;
|
|
48
|
+
let portValue = 0;
|
|
49
|
+
if (typeof rawPort === 'number' && Number.isFinite(rawPort)) {
|
|
50
|
+
portValue = rawPort;
|
|
51
|
+
}
|
|
52
|
+
else if (typeof rawPort === 'string') {
|
|
53
|
+
const parsed = Number.parseInt(rawPort.trim(), 10);
|
|
54
|
+
if (Number.isFinite(parsed)) {
|
|
55
|
+
portValue = parsed;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const basePathValue = typeof record.basePath === 'string' && record.basePath.trim().length > 0
|
|
59
|
+
? record.basePath.trim()
|
|
60
|
+
: '/fame/v1/gateway';
|
|
61
|
+
const rawAuthorizer = record.authorizer ?? null;
|
|
62
|
+
const authorizerValue = rawAuthorizer && typeof rawAuthorizer === 'object' && !Array.isArray(rawAuthorizer)
|
|
63
|
+
? rawAuthorizer
|
|
64
|
+
: null;
|
|
65
|
+
const rawLimits = record.limits ?? null;
|
|
66
|
+
const limitsValue = rawLimits && typeof rawLimits === 'object' && !Array.isArray(rawLimits)
|
|
67
|
+
? rawLimits
|
|
68
|
+
: null;
|
|
69
|
+
return {
|
|
70
|
+
type: 'AgentHttpGatewayListener',
|
|
71
|
+
host: hostValue,
|
|
72
|
+
port: portValue,
|
|
73
|
+
basePath: basePathValue,
|
|
74
|
+
authorizer: authorizerValue,
|
|
75
|
+
limits: limitsValue,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export const FACTORY_META = {
|
|
79
|
+
base: TRANSPORT_LISTENER_FACTORY_BASE_TYPE,
|
|
80
|
+
key: 'AgentHttpGatewayListener',
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Factory for creating AgentHttpGatewayListener instances.
|
|
84
|
+
*
|
|
85
|
+
* This factory does not extend BaseTransportListenerFactory to avoid static imports
|
|
86
|
+
* from @naylence/runtime/node. Instead, it implements the factory interface directly.
|
|
87
|
+
*/
|
|
88
|
+
export class AgentHttpGatewayListenerFactory {
|
|
89
|
+
constructor() {
|
|
90
|
+
this.type = 'AgentHttpGatewayListener';
|
|
91
|
+
this.priority = 1000;
|
|
92
|
+
}
|
|
93
|
+
async create(config, ...factoryArgs) {
|
|
94
|
+
const normalized = normalizeConfig(config);
|
|
95
|
+
const [firstArg, ...remainingArgs] = factoryArgs;
|
|
96
|
+
const eventListeners = Array.isArray(firstArg) ? firstArg : [];
|
|
97
|
+
const optionsSource = Array.isArray(firstArg) ? (remainingArgs[0] ?? null) : firstArg;
|
|
98
|
+
const options = optionsSource;
|
|
99
|
+
const { AgentHttpGatewayListener } = await getGatewayListenerModule();
|
|
100
|
+
const httpServer = options?.httpServer ?? (await this._createDefaultHttpServer(normalized));
|
|
101
|
+
addServerEventListener(httpServer, eventListeners);
|
|
102
|
+
let authorizer = options?.authorizer ?? null;
|
|
103
|
+
if (!authorizer && normalized.authorizer) {
|
|
104
|
+
const runtimeNode = await getRuntimeNodeModule();
|
|
105
|
+
const AuthorizerFactory = runtimeNode.AuthorizerFactory;
|
|
106
|
+
authorizer =
|
|
107
|
+
(await AuthorizerFactory.createAuthorizer(normalized.authorizer, {
|
|
108
|
+
validate: false,
|
|
109
|
+
})) ?? null;
|
|
110
|
+
}
|
|
111
|
+
return new AgentHttpGatewayListener({
|
|
112
|
+
httpServer,
|
|
113
|
+
basePath: normalized.basePath,
|
|
114
|
+
...(authorizer ? { authorizer } : {}),
|
|
115
|
+
...(normalized.limits ? { limits: normalized.limits } : {}),
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
async _createDefaultHttpServer(normalized) {
|
|
119
|
+
const runtimeNode = await getRuntimeNodeModule();
|
|
120
|
+
const DefaultHttpServer = runtimeNode.DefaultHttpServer;
|
|
121
|
+
return await DefaultHttpServer.getOrCreate({
|
|
122
|
+
host: normalized.host,
|
|
123
|
+
port: normalized.port,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export default AgentHttpGatewayListenerFactory;
|
|
128
|
+
//# sourceMappingURL=agent-http-gateway-listener-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-http-gateway-listener-factory.js","sourceRoot":"","sources":["../../../../../src/naylence/agent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QAC5F,sBAAsB,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC;QAEnD,IAAI,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,IAAI,CAAC;QAC7C,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;YACzC,MAAM,WAAW,GAAG,MAAM,oBAAoB,EAAE,CAAC;YACjD,MAAM,iBAAiB,GAAG,WAAW,CAAC,iBAAiB,CAAC;YACxD,UAAU;gBACR,CAAC,MAAM,iBAAiB,CAAC,gBAAgB,CAAC,UAAU,CAAC,UAAU,EAAE;oBAC/D,QAAQ,EAAE,KAAK;iBAChB,CAAC,CAAC,IAAI,IAAI,CAAC;QAChB,CAAC;QAED,OAAO,IAAI,wBAAwB,CAAC;YAClC,UAAU;YACV,QAAQ,EAAE,UAAU,CAAC,QAAQ;YAC7B,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACrC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC5D,CAAC,CAAC;IACL,CAAC;IAEO,KAAK,CAAC,wBAAwB,CAAC,UAA4B;QACjE,MAAM,WAAW,GAAG,MAAM,oBAAoB,EAAE,CAAC;QACjD,MAAM,iBAAiB,GAAG,WAAW,CAAC,iBAAiB,CAAC;QACxD,OAAO,MAAM,iBAAiB,CAAC,WAAW,CAAC;YACzC,IAAI,EAAE,UAAU,CAAC,IAAI;YACrB,IAAI,EAAE,UAAU,CAAC,IAAI;SACtB,CAAC,CAAC;IACL,CAAC;CACF;AAED,eAAe,+BAA+B,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { TransportListener, type Authorizer, type HttpRouter, type HttpServer, type NodeLike } from '@naylence/runtime/node';
|
|
2
|
+
/**
|
|
3
|
+
* Structural limits for gateway request fields.
|
|
4
|
+
* These protect against abuse in routing/envelope fields, not payload content.
|
|
5
|
+
*/
|
|
6
|
+
export interface GatewayLimits {
|
|
7
|
+
/** Maximum length of the `method` field (default: 256) */
|
|
8
|
+
maxMethodLength?: number;
|
|
9
|
+
/** Maximum length of the `targetAddr` field (default: 512) */
|
|
10
|
+
maxTargetAddrLength?: number;
|
|
11
|
+
/** Maximum length of the `type` field for messages (default: 256) */
|
|
12
|
+
maxTypeLength?: number;
|
|
13
|
+
/** Maximum number of capabilities in the array (default: 16) */
|
|
14
|
+
maxCapabilities?: number;
|
|
15
|
+
/** Maximum length of each capability string (default: 256) */
|
|
16
|
+
maxCapabilityLength?: number;
|
|
17
|
+
/** Maximum request body size in bytes (default: 1MB). Applied per-route. */
|
|
18
|
+
bodyLimitBytes?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface AgentHttpGatewayListenerParams {
|
|
21
|
+
httpServer: HttpServer;
|
|
22
|
+
basePath?: string;
|
|
23
|
+
authorizer?: Authorizer | null;
|
|
24
|
+
limits?: GatewayLimits;
|
|
25
|
+
}
|
|
26
|
+
export declare class AgentHttpGatewayListener extends TransportListener {
|
|
27
|
+
private readonly _httpServer;
|
|
28
|
+
private readonly _authorizer;
|
|
29
|
+
private readonly _basePath;
|
|
30
|
+
private readonly _limits;
|
|
31
|
+
private _node;
|
|
32
|
+
private _routerRegistered;
|
|
33
|
+
constructor(params: AgentHttpGatewayListenerParams);
|
|
34
|
+
get httpServer(): HttpServer;
|
|
35
|
+
onNodeInitialized(node: NodeLike): Promise<void>;
|
|
36
|
+
onNodeStarted(): Promise<void>;
|
|
37
|
+
onNodeStopped(): Promise<void>;
|
|
38
|
+
createRouter(): Promise<HttpRouter>;
|
|
39
|
+
private _handleRpc;
|
|
40
|
+
private _handleMessage;
|
|
41
|
+
private _parseRpcRequest;
|
|
42
|
+
private _parseMessageRequest;
|
|
43
|
+
private _parseTimeoutValue;
|
|
44
|
+
private _normalizeTimeout;
|
|
45
|
+
private _invokeRpc;
|
|
46
|
+
private _sendMessage;
|
|
47
|
+
private _authenticateRequest;
|
|
48
|
+
private _resolveAuthorizer;
|
|
49
|
+
private _mapError;
|
|
50
|
+
}
|