@easynet-run/node 0.27.14
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/README.md +135 -0
- package/native/dendrite-bridge-manifest.json +38 -0
- package/native/dendrite-bridge.json +15 -0
- package/native/include/axon_dendrite_bridge.h +460 -0
- package/native/libaxon_dendrite_bridge.so +0 -0
- package/package.json +67 -0
- package/runtime/easynet-runtime-rs-0.27.14-x86_64-unknown-linux-gnu.tar.gz +0 -0
- package/runtime/runtime-bridge-manifest.json +20 -0
- package/runtime/runtime-bridge.json +9 -0
- package/src/ability_lifecycle.d.ts +140 -0
- package/src/ability_lifecycle.js +525 -0
- package/src/capability_request.d.ts +14 -0
- package/src/capability_request.js +247 -0
- package/src/dendrite_bridge/bridge.d.ts +98 -0
- package/src/dendrite_bridge/bridge.js +712 -0
- package/src/dendrite_bridge/ffi.d.ts +60 -0
- package/src/dendrite_bridge/ffi.js +139 -0
- package/src/dendrite_bridge/index.d.ts +3 -0
- package/src/dendrite_bridge/index.js +25 -0
- package/src/dendrite_bridge/types.d.ts +179 -0
- package/src/dendrite_bridge/types.js +23 -0
- package/src/dendrite_bridge.d.ts +1 -0
- package/src/dendrite_bridge.js +27 -0
- package/src/errors.d.ts +83 -0
- package/src/errors.js +146 -0
- package/src/index.d.ts +55 -0
- package/src/index.js +164 -0
- package/src/koffi.d.ts +34 -0
- package/src/mcp/server.d.ts +29 -0
- package/src/mcp/server.js +190 -0
- package/src/presets/ability_dispatch/args.d.ts +5 -0
- package/src/presets/ability_dispatch/args.js +36 -0
- package/src/presets/ability_dispatch/bundle.d.ts +7 -0
- package/src/presets/ability_dispatch/bundle.js +102 -0
- package/src/presets/ability_dispatch/media.d.ts +6 -0
- package/src/presets/ability_dispatch/media.js +48 -0
- package/src/presets/ability_dispatch/orchestrator.d.ts +21 -0
- package/src/presets/ability_dispatch/orchestrator.js +117 -0
- package/src/presets/ability_dispatch/workflow.d.ts +50 -0
- package/src/presets/ability_dispatch/workflow.js +333 -0
- package/src/presets/ability_dispatch.d.ts +1 -0
- package/src/presets/ability_dispatch.js +2 -0
- package/src/presets/remote_control/config.d.ts +16 -0
- package/src/presets/remote_control/config.js +63 -0
- package/src/presets/remote_control/descriptor.d.ts +34 -0
- package/src/presets/remote_control/descriptor.js +183 -0
- package/src/presets/remote_control/handlers.d.ts +12 -0
- package/src/presets/remote_control/handlers.js +279 -0
- package/src/presets/remote_control/kit.d.ts +22 -0
- package/src/presets/remote_control/kit.js +72 -0
- package/src/presets/remote_control/kit.test.js +87 -0
- package/src/presets/remote_control/orchestrator.d.ts +28 -0
- package/src/presets/remote_control/orchestrator.js +118 -0
- package/src/presets/remote_control/specs.d.ts +2 -0
- package/src/presets/remote_control/specs.js +152 -0
- package/src/presets/remote_control_case.d.ts +7 -0
- package/src/presets/remote_control_case.js +3 -0
- package/src/receipt.d.ts +46 -0
- package/src/receipt.js +98 -0
- package/src/tool_adapter.d.ts +90 -0
- package/src/tool_adapter.js +169 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { Transport, JsonValue } from "./index.js";
|
|
2
|
+
export interface ToolParameters {
|
|
3
|
+
type: "object";
|
|
4
|
+
properties: Record<string, JsonValue>;
|
|
5
|
+
required?: string[];
|
|
6
|
+
[key: string]: JsonValue | undefined;
|
|
7
|
+
}
|
|
8
|
+
export interface ToolSpec {
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
resourceUri: string;
|
|
12
|
+
parameters: ToolParameters;
|
|
13
|
+
}
|
|
14
|
+
export interface OpenAITool {
|
|
15
|
+
type: "function";
|
|
16
|
+
name: string;
|
|
17
|
+
description: string;
|
|
18
|
+
parameters: ToolParameters;
|
|
19
|
+
}
|
|
20
|
+
export interface OpenAIChatTool {
|
|
21
|
+
type: "function";
|
|
22
|
+
function: {
|
|
23
|
+
name: string;
|
|
24
|
+
description: string;
|
|
25
|
+
parameters: ToolParameters;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export interface AnthropicTool {
|
|
29
|
+
name: string;
|
|
30
|
+
description: string;
|
|
31
|
+
input_schema: ToolParameters;
|
|
32
|
+
}
|
|
33
|
+
export interface ToolDict {
|
|
34
|
+
name: string;
|
|
35
|
+
description: string;
|
|
36
|
+
resource_uri: string;
|
|
37
|
+
parameters: ToolParameters;
|
|
38
|
+
}
|
|
39
|
+
export type LocalHandler = (args: Record<string, JsonValue>) => JsonValue | Promise<JsonValue>;
|
|
40
|
+
export interface RegisterOptions {
|
|
41
|
+
description?: string;
|
|
42
|
+
resourceUri?: string;
|
|
43
|
+
parameters?: ToolParameters;
|
|
44
|
+
}
|
|
45
|
+
export interface AbilityToolAdapterOptions {
|
|
46
|
+
principalId?: string;
|
|
47
|
+
}
|
|
48
|
+
export declare class AbilityToolAdapter {
|
|
49
|
+
readonly tenantId: string;
|
|
50
|
+
private readonly transport;
|
|
51
|
+
private readonly principalId;
|
|
52
|
+
private readonly _specs;
|
|
53
|
+
private readonly localHandlers;
|
|
54
|
+
private fallbackTransport;
|
|
55
|
+
constructor(tenantId: string, transport?: Transport, options?: AbilityToolAdapterOptions);
|
|
56
|
+
/**
|
|
57
|
+
* Register a local handler function as both a tool definition and executor.
|
|
58
|
+
* When {@link execute} is called, the local handler runs directly (no network round-trip).
|
|
59
|
+
*/
|
|
60
|
+
register(name: string, handler: LocalHandler, options?: RegisterOptions): this;
|
|
61
|
+
/**
|
|
62
|
+
* Register a remote ability as a tool (no local handler — calls go over the network).
|
|
63
|
+
*/
|
|
64
|
+
registerAbility(name: string, resourceUri: string, options?: {
|
|
65
|
+
description?: string;
|
|
66
|
+
parameters?: ToolParameters;
|
|
67
|
+
}): this;
|
|
68
|
+
specs(): ToolSpec[];
|
|
69
|
+
asOpenAITools(names?: string[]): OpenAITool[];
|
|
70
|
+
asOpenAIChatTools(names?: string[]): OpenAIChatTool[];
|
|
71
|
+
asAnthropicTools(names?: string[]): AnthropicTool[];
|
|
72
|
+
asDicts(names?: string[]): ToolDict[];
|
|
73
|
+
private iterSpecs;
|
|
74
|
+
/**
|
|
75
|
+
* Execute a tool call by name.
|
|
76
|
+
*
|
|
77
|
+
* If a local handler was registered, it is called directly.
|
|
78
|
+
* Otherwise the call is dispatched to the remote ability via the transport.
|
|
79
|
+
*/
|
|
80
|
+
execute(name: string, args: Record<string, JsonValue> | string): Promise<JsonValue>;
|
|
81
|
+
/**
|
|
82
|
+
* Execute and return the result as a JSON string (convenience for LLM output construction).
|
|
83
|
+
*/
|
|
84
|
+
executeToJson(name: string, args: Record<string, JsonValue> | string): Promise<string>;
|
|
85
|
+
/**
|
|
86
|
+
* Close the internally cached fallback transport (if any).
|
|
87
|
+
* Call this when the adapter is no longer needed to release native resources.
|
|
88
|
+
*/
|
|
89
|
+
close(): void;
|
|
90
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// EasyNet Axon for AgentNet
|
|
2
|
+
// =========================
|
|
3
|
+
//
|
|
4
|
+
// File: sdk/node/src/tool_adapter.ts
|
|
5
|
+
// Description: Tool adapter that bridges LLM tool-call interfaces (OpenAI, Anthropic, etc.) with Axon ability invocations; enables abilities to be used as native LLM tools without protocol knowledge.
|
|
6
|
+
//
|
|
7
|
+
// Protocol Responsibility:
|
|
8
|
+
// - Converts between LLM tool-call schemas (OpenAI function-calling, Anthropic tool-use) and Axon ability request/response envelopes.
|
|
9
|
+
// - Preserves ability identity via resource URI mapping and invocation semantics.
|
|
10
|
+
//
|
|
11
|
+
// Implementation Approach:
|
|
12
|
+
// - Uses explicit ToolSpec registration with JSON Schema parameters.
|
|
13
|
+
// - Provides format-specific output (OpenAI, Anthropic, generic) from a unified ToolSpec model.
|
|
14
|
+
// - Delegates execution to the existing Client/Transport layer.
|
|
15
|
+
//
|
|
16
|
+
// Usage Contract:
|
|
17
|
+
// - Callers register abilities with schema metadata, then export tool definitions for their LLM of choice.
|
|
18
|
+
// - Execution dispatch routes tool calls back through the Axon ability invoke path.
|
|
19
|
+
//
|
|
20
|
+
// Architectural Position:
|
|
21
|
+
// - Sits above the Client/Transport facade; does not touch DendriteBridge directly.
|
|
22
|
+
// - Should not embed LLM-specific conversation logic beyond schema translation.
|
|
23
|
+
//
|
|
24
|
+
// Author: Silan.Hu
|
|
25
|
+
// Email: silan.hu@u.nus.edu
|
|
26
|
+
// Copyright (c) 2026-2027 easynet. All rights reserved.
|
|
27
|
+
function specToOpenAI(spec) {
|
|
28
|
+
return {
|
|
29
|
+
type: "function",
|
|
30
|
+
name: spec.name,
|
|
31
|
+
description: spec.description,
|
|
32
|
+
parameters: spec.parameters,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function specToOpenAIChat(spec) {
|
|
36
|
+
return {
|
|
37
|
+
type: "function",
|
|
38
|
+
function: {
|
|
39
|
+
name: spec.name,
|
|
40
|
+
description: spec.description,
|
|
41
|
+
parameters: spec.parameters,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function specToAnthropic(spec) {
|
|
46
|
+
return {
|
|
47
|
+
name: spec.name,
|
|
48
|
+
description: spec.description,
|
|
49
|
+
input_schema: spec.parameters,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function specToDict(spec) {
|
|
53
|
+
return {
|
|
54
|
+
name: spec.name,
|
|
55
|
+
description: spec.description,
|
|
56
|
+
resource_uri: spec.resourceUri,
|
|
57
|
+
parameters: spec.parameters,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export class AbilityToolAdapter {
|
|
61
|
+
tenantId;
|
|
62
|
+
transport;
|
|
63
|
+
principalId;
|
|
64
|
+
_specs = new Map();
|
|
65
|
+
localHandlers = new Map();
|
|
66
|
+
fallbackTransport;
|
|
67
|
+
constructor(tenantId, transport, options = {}) {
|
|
68
|
+
this.tenantId = tenantId;
|
|
69
|
+
this.transport = transport;
|
|
70
|
+
this.principalId = options.principalId;
|
|
71
|
+
}
|
|
72
|
+
// -- Registration -------------------------------------------------------
|
|
73
|
+
/**
|
|
74
|
+
* Register a local handler function as both a tool definition and executor.
|
|
75
|
+
* When {@link execute} is called, the local handler runs directly (no network round-trip).
|
|
76
|
+
*/
|
|
77
|
+
register(name, handler, options = {}) {
|
|
78
|
+
const spec = {
|
|
79
|
+
name,
|
|
80
|
+
description: options.description ?? "",
|
|
81
|
+
resourceUri: options.resourceUri ?? `easynet:///r/org/${name}`,
|
|
82
|
+
parameters: options.parameters ?? { type: "object", properties: {} },
|
|
83
|
+
};
|
|
84
|
+
this._specs.set(name, spec);
|
|
85
|
+
this.localHandlers.set(name, handler);
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Register a remote ability as a tool (no local handler — calls go over the network).
|
|
90
|
+
*/
|
|
91
|
+
registerAbility(name, resourceUri, options = {}) {
|
|
92
|
+
const spec = {
|
|
93
|
+
name,
|
|
94
|
+
description: options.description ?? "",
|
|
95
|
+
resourceUri,
|
|
96
|
+
parameters: options.parameters ?? { type: "object", properties: {} },
|
|
97
|
+
};
|
|
98
|
+
this._specs.set(name, spec);
|
|
99
|
+
this.localHandlers.delete(name);
|
|
100
|
+
return this;
|
|
101
|
+
}
|
|
102
|
+
// -- Export --------------------------------------------------------------
|
|
103
|
+
specs() {
|
|
104
|
+
return [...this._specs.values()];
|
|
105
|
+
}
|
|
106
|
+
asOpenAITools(names) {
|
|
107
|
+
return this.iterSpecs(names).map(specToOpenAI);
|
|
108
|
+
}
|
|
109
|
+
asOpenAIChatTools(names) {
|
|
110
|
+
return this.iterSpecs(names).map(specToOpenAIChat);
|
|
111
|
+
}
|
|
112
|
+
asAnthropicTools(names) {
|
|
113
|
+
return this.iterSpecs(names).map(specToAnthropic);
|
|
114
|
+
}
|
|
115
|
+
asDicts(names) {
|
|
116
|
+
return this.iterSpecs(names).map(specToDict);
|
|
117
|
+
}
|
|
118
|
+
iterSpecs(names) {
|
|
119
|
+
if (!names)
|
|
120
|
+
return [...this._specs.values()];
|
|
121
|
+
return names.filter((n) => this._specs.has(n)).map((n) => this._specs.get(n));
|
|
122
|
+
}
|
|
123
|
+
// -- Execution -----------------------------------------------------------
|
|
124
|
+
/**
|
|
125
|
+
* Execute a tool call by name.
|
|
126
|
+
*
|
|
127
|
+
* If a local handler was registered, it is called directly.
|
|
128
|
+
* Otherwise the call is dispatched to the remote ability via the transport.
|
|
129
|
+
*/
|
|
130
|
+
async execute(name, args) {
|
|
131
|
+
const parsed = typeof args === "string" ? JSON.parse(args) : args;
|
|
132
|
+
// Local handler path
|
|
133
|
+
const handler = this.localHandlers.get(name);
|
|
134
|
+
if (handler) {
|
|
135
|
+
return handler(parsed);
|
|
136
|
+
}
|
|
137
|
+
// Remote ability path
|
|
138
|
+
const spec = this._specs.get(name);
|
|
139
|
+
if (!spec) {
|
|
140
|
+
throw new Error(`unknown tool: ${name}`);
|
|
141
|
+
}
|
|
142
|
+
// Lazy import to avoid loading koffi/DendriteBridge when only using local handlers
|
|
143
|
+
if (!this.transport && !this.fallbackTransport) {
|
|
144
|
+
const { SidecarTransport } = await import("./index.js");
|
|
145
|
+
this.fallbackTransport = new SidecarTransport();
|
|
146
|
+
}
|
|
147
|
+
const transport = this.transport ?? this.fallbackTransport;
|
|
148
|
+
const { Client } = await import("./index.js");
|
|
149
|
+
const client = new Client(transport, this.tenantId, spec.resourceUri, this.principalId ?? "");
|
|
150
|
+
return client.call(parsed);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Execute and return the result as a JSON string (convenience for LLM output construction).
|
|
154
|
+
*/
|
|
155
|
+
async executeToJson(name, args) {
|
|
156
|
+
const result = await this.execute(name, args);
|
|
157
|
+
return JSON.stringify(result);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Close the internally cached fallback transport (if any).
|
|
161
|
+
* Call this when the adapter is no longer needed to release native resources.
|
|
162
|
+
*/
|
|
163
|
+
close() {
|
|
164
|
+
if (this.fallbackTransport && "close" in this.fallbackTransport) {
|
|
165
|
+
this.fallbackTransport.close();
|
|
166
|
+
this.fallbackTransport = undefined;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|