@band-ai/sdk 0.1.2
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/CodexAdapter-A1k_LMdZ.d.ts +1278 -0
- package/dist/CodexAdapter-BbZD-nBd.d.cts +1278 -0
- package/dist/adapters.cjs +10643 -0
- package/dist/adapters.d.cts +217 -0
- package/dist/adapters.d.ts +217 -0
- package/dist/adapters.js +92 -0
- package/dist/backends-BnOLsG7w.d.cts +20 -0
- package/dist/backends-C4n6cKOf.d.ts +20 -0
- package/dist/chunk-3BKAC4OZ.js +44 -0
- package/dist/chunk-5CXIMAH2.js +52 -0
- package/dist/chunk-6AJA2OPC.js +3682 -0
- package/dist/chunk-A3TDK6GP.js +6674 -0
- package/dist/chunk-AVVDPXP4.js +39 -0
- package/dist/chunk-EDPKUUJL.js +177 -0
- package/dist/chunk-FUODYQRE.js +2562 -0
- package/dist/chunk-GVEQ3RAH.js +373 -0
- package/dist/chunk-INA6YZTZ.js +88 -0
- package/dist/chunk-IZPV6QS6.js +115 -0
- package/dist/chunk-LY55KYVI.js +0 -0
- package/dist/chunk-NIAQBANR.js +577 -0
- package/dist/chunk-OD2G5LFQ.js +78 -0
- package/dist/chunk-SFVKOEQH.js +103 -0
- package/dist/chunk-SG4WLD2H.js +1093 -0
- package/dist/chunk-YR3BOQNW.js +39 -0
- package/dist/chunk-ZZJRRBPQ.js +82 -0
- package/dist/claude-CcnQ5OUC.d.ts +53 -0
- package/dist/claude-CwTAxhwI.d.cts +53 -0
- package/dist/config.cjs +164 -0
- package/dist/config.d.cts +19 -0
- package/dist/config.d.ts +19 -0
- package/dist/config.js +9 -0
- package/dist/converters.cjs +1086 -0
- package/dist/converters.d.cts +143 -0
- package/dist/converters.d.ts +143 -0
- package/dist/converters.js +468 -0
- package/dist/core.cjs +185 -0
- package/dist/core.d.cts +22 -0
- package/dist/core.d.ts +22 -0
- package/dist/core.js +24 -0
- package/dist/customTools-BzF0IISO.d.cts +10 -0
- package/dist/customTools-BzF0IISO.d.ts +10 -0
- package/dist/dtos-DUpbIu8k.d.cts +163 -0
- package/dist/dtos-DUpbIu8k.d.ts +163 -0
- package/dist/history-ByessXNq.d.ts +24 -0
- package/dist/history-i6yN7neC.d.cts +24 -0
- package/dist/index.cjs +13914 -0
- package/dist/index.d.cts +63 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +198 -0
- package/dist/linear.cjs +2207 -0
- package/dist/linear.d.cts +167 -0
- package/dist/linear.d.ts +167 -0
- package/dist/linear.js +2139 -0
- package/dist/logger-CABQOnlR.d.cts +21 -0
- package/dist/logger-CABQOnlR.d.ts +21 -0
- package/dist/mcp-claude.cjs +584 -0
- package/dist/mcp-claude.d.cts +4 -0
- package/dist/mcp-claude.d.ts +4 -0
- package/dist/mcp-claude.js +11 -0
- package/dist/mcp.cjs +1247 -0
- package/dist/mcp.d.cts +97 -0
- package/dist/mcp.d.ts +97 -0
- package/dist/mcp.js +27 -0
- package/dist/opencode-BBcDchcN.d.cts +159 -0
- package/dist/opencode-DthQQUsZ.d.ts +159 -0
- package/dist/pagination-BPiys10t.d.cts +25 -0
- package/dist/pagination-CcDkVFxK.d.ts +25 -0
- package/dist/protocols-CInhtFpA.d.cts +116 -0
- package/dist/protocols-DrhzOH6K.d.ts +116 -0
- package/dist/rest.cjs +1159 -0
- package/dist/rest.d.cts +144 -0
- package/dist/rest.d.ts +144 -0
- package/dist/rest.js +18 -0
- package/dist/runtime.cjs +5353 -0
- package/dist/runtime.d.cts +276 -0
- package/dist/runtime.d.ts +276 -0
- package/dist/runtime.js +274 -0
- package/dist/schemas-BpEBkq5V.d.cts +592 -0
- package/dist/schemas-vos1AaBc.d.ts +592 -0
- package/dist/sdk-HJUVSSWA.js +10 -0
- package/dist/simpleAdapter-9OE_p6QW.d.ts +29 -0
- package/dist/simpleAdapter-DqhvjsGr.d.cts +29 -0
- package/dist/testing.cjs +217 -0
- package/dist/testing.d.cts +126 -0
- package/dist/testing.d.ts +126 -0
- package/dist/testing.js +186 -0
- package/dist/types-7jVzOeOP.d.ts +446 -0
- package/dist/types-CSHFipIc.d.cts +331 -0
- package/dist/types-CovcHpYf.d.cts +446 -0
- package/dist/types-CxII3XkA.d.ts +331 -0
- package/package.json +189 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/core/errors.ts
|
|
2
|
+
var ThenvoiSdkError = class extends Error {
|
|
3
|
+
constructor(message, cause) {
|
|
4
|
+
super(message, cause !== void 0 ? { cause } : void 0);
|
|
5
|
+
this.name = "ThenvoiSdkError";
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
var UnsupportedFeatureError = class extends ThenvoiSdkError {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "UnsupportedFeatureError";
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var ValidationError = class extends ThenvoiSdkError {
|
|
15
|
+
constructor(message, cause) {
|
|
16
|
+
super(message, cause);
|
|
17
|
+
this.name = "ValidationError";
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
var TransportError = class extends ThenvoiSdkError {
|
|
21
|
+
constructor(message, cause) {
|
|
22
|
+
super(message, cause);
|
|
23
|
+
this.name = "TransportError";
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var RuntimeStateError = class extends ThenvoiSdkError {
|
|
27
|
+
constructor(message) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.name = "RuntimeStateError";
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export {
|
|
34
|
+
ThenvoiSdkError,
|
|
35
|
+
UnsupportedFeatureError,
|
|
36
|
+
ValidationError,
|
|
37
|
+
TransportError,
|
|
38
|
+
RuntimeStateError
|
|
39
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {
|
|
2
|
+
toLegacyToolExecutorErrorMessage
|
|
3
|
+
} from "./chunk-3BKAC4OZ.js";
|
|
4
|
+
|
|
5
|
+
// src/adapters/shared/coercion.ts
|
|
6
|
+
function asOptionalRecord(value) {
|
|
7
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
8
|
+
return void 0;
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
function asRecord(value, context = "value") {
|
|
13
|
+
const record = asOptionalRecord(value);
|
|
14
|
+
if (!record) {
|
|
15
|
+
throw new TypeError(`Expected ${context} to be an object record.`);
|
|
16
|
+
}
|
|
17
|
+
return record;
|
|
18
|
+
}
|
|
19
|
+
function asNonEmptyString(value) {
|
|
20
|
+
if (typeof value !== "string") {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
const trimmed = value.trim();
|
|
24
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
25
|
+
}
|
|
26
|
+
function asString(value) {
|
|
27
|
+
return typeof value === "string" ? value : void 0;
|
|
28
|
+
}
|
|
29
|
+
function asNullableString(value) {
|
|
30
|
+
if (value === void 0) {
|
|
31
|
+
return void 0;
|
|
32
|
+
}
|
|
33
|
+
if (value === null) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
return asString(value);
|
|
37
|
+
}
|
|
38
|
+
function toDisplayText(value) {
|
|
39
|
+
if (typeof value === "string") {
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
if (value == null) {
|
|
43
|
+
return "";
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
return JSON.stringify(value);
|
|
47
|
+
} catch {
|
|
48
|
+
return String(value);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function toWireString(value) {
|
|
52
|
+
const legacyErrorMessage = toLegacyToolExecutorErrorMessage(value);
|
|
53
|
+
if (legacyErrorMessage !== null) {
|
|
54
|
+
return legacyErrorMessage;
|
|
55
|
+
}
|
|
56
|
+
if (value === void 0 || value === null) {
|
|
57
|
+
return "";
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const json = JSON.stringify(value);
|
|
61
|
+
return typeof json === "string" ? json : String(value);
|
|
62
|
+
} catch {
|
|
63
|
+
return String(value);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function asErrorMessage(error) {
|
|
67
|
+
if (error instanceof Error) {
|
|
68
|
+
return error.message;
|
|
69
|
+
}
|
|
70
|
+
return String(error);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export {
|
|
74
|
+
asOptionalRecord,
|
|
75
|
+
asRecord,
|
|
76
|
+
asNonEmptyString,
|
|
77
|
+
asString,
|
|
78
|
+
asNullableString,
|
|
79
|
+
toDisplayText,
|
|
80
|
+
toWireString,
|
|
81
|
+
asErrorMessage
|
|
82
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { McpSdkServerConfigWithInstance, SdkMcpToolDefinition } from '@anthropic-ai/claude-agent-sdk';
|
|
2
|
+
import { A as AdapterToolsProtocol } from './protocols-DrhzOH6K.js';
|
|
3
|
+
|
|
4
|
+
interface McpToolRegistration {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
inputSchema: McpToolInputSchema;
|
|
8
|
+
execute: (args: Record<string, unknown>) => Promise<McpToolResult>;
|
|
9
|
+
}
|
|
10
|
+
interface McpToolInputSchema {
|
|
11
|
+
type: "object";
|
|
12
|
+
properties: Record<string, unknown>;
|
|
13
|
+
required: string[];
|
|
14
|
+
}
|
|
15
|
+
interface McpToolResult {
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
content: Array<{
|
|
18
|
+
type: "text";
|
|
19
|
+
text: string;
|
|
20
|
+
}>;
|
|
21
|
+
isError?: true;
|
|
22
|
+
}
|
|
23
|
+
interface BuildRegistrationsOptions {
|
|
24
|
+
enableMemoryTools?: boolean;
|
|
25
|
+
enableContactTools?: boolean;
|
|
26
|
+
additionalTools?: McpToolRegistration[];
|
|
27
|
+
}
|
|
28
|
+
type ToolResolver = (roomId: string) => AdapterToolsProtocol | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Build MCP tool registrations with room-scoped tool resolution.
|
|
31
|
+
* Each tool call requires a `room_id` argument to look up the correct tools instance.
|
|
32
|
+
*/
|
|
33
|
+
declare function buildRoomScopedRegistrations(resolver: ToolResolver, options?: BuildRegistrationsOptions): McpToolRegistration[];
|
|
34
|
+
/**
|
|
35
|
+
* Build MCP tool registrations for a single tools instance (no room_id needed).
|
|
36
|
+
*/
|
|
37
|
+
declare function buildSingleContextRegistrations(tools: AdapterToolsProtocol, options?: BuildRegistrationsOptions): McpToolRegistration[];
|
|
38
|
+
declare function successResult(value: unknown): McpToolResult;
|
|
39
|
+
declare function errorResult(message: string): McpToolResult;
|
|
40
|
+
|
|
41
|
+
interface CreateThenvoiSdkMcpServerOptions {
|
|
42
|
+
enableMemoryTools: boolean;
|
|
43
|
+
getToolsForRoom: (roomId: string) => AdapterToolsProtocol | undefined;
|
|
44
|
+
additionalTools?: McpToolRegistration[];
|
|
45
|
+
}
|
|
46
|
+
interface ThenvoiSdkMcpServer {
|
|
47
|
+
serverConfig: McpSdkServerConfigWithInstance;
|
|
48
|
+
allowedTools: string[];
|
|
49
|
+
toolDefinitions: Array<SdkMcpToolDefinition<any>>;
|
|
50
|
+
}
|
|
51
|
+
declare function createThenvoiSdkMcpServer(options: CreateThenvoiSdkMcpServerOptions): ThenvoiSdkMcpServer;
|
|
52
|
+
|
|
53
|
+
export { type BuildRegistrationsOptions as B, type CreateThenvoiSdkMcpServerOptions as C, type McpToolRegistration as M, type ThenvoiSdkMcpServer as T, type McpToolInputSchema as a, type McpToolResult as b, buildRoomScopedRegistrations as c, buildSingleContextRegistrations as d, errorResult as e, createThenvoiSdkMcpServer as f, successResult as s };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { McpSdkServerConfigWithInstance, SdkMcpToolDefinition } from '@anthropic-ai/claude-agent-sdk';
|
|
2
|
+
import { A as AdapterToolsProtocol } from './protocols-CInhtFpA.cjs';
|
|
3
|
+
|
|
4
|
+
interface McpToolRegistration {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
inputSchema: McpToolInputSchema;
|
|
8
|
+
execute: (args: Record<string, unknown>) => Promise<McpToolResult>;
|
|
9
|
+
}
|
|
10
|
+
interface McpToolInputSchema {
|
|
11
|
+
type: "object";
|
|
12
|
+
properties: Record<string, unknown>;
|
|
13
|
+
required: string[];
|
|
14
|
+
}
|
|
15
|
+
interface McpToolResult {
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
content: Array<{
|
|
18
|
+
type: "text";
|
|
19
|
+
text: string;
|
|
20
|
+
}>;
|
|
21
|
+
isError?: true;
|
|
22
|
+
}
|
|
23
|
+
interface BuildRegistrationsOptions {
|
|
24
|
+
enableMemoryTools?: boolean;
|
|
25
|
+
enableContactTools?: boolean;
|
|
26
|
+
additionalTools?: McpToolRegistration[];
|
|
27
|
+
}
|
|
28
|
+
type ToolResolver = (roomId: string) => AdapterToolsProtocol | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Build MCP tool registrations with room-scoped tool resolution.
|
|
31
|
+
* Each tool call requires a `room_id` argument to look up the correct tools instance.
|
|
32
|
+
*/
|
|
33
|
+
declare function buildRoomScopedRegistrations(resolver: ToolResolver, options?: BuildRegistrationsOptions): McpToolRegistration[];
|
|
34
|
+
/**
|
|
35
|
+
* Build MCP tool registrations for a single tools instance (no room_id needed).
|
|
36
|
+
*/
|
|
37
|
+
declare function buildSingleContextRegistrations(tools: AdapterToolsProtocol, options?: BuildRegistrationsOptions): McpToolRegistration[];
|
|
38
|
+
declare function successResult(value: unknown): McpToolResult;
|
|
39
|
+
declare function errorResult(message: string): McpToolResult;
|
|
40
|
+
|
|
41
|
+
interface CreateThenvoiSdkMcpServerOptions {
|
|
42
|
+
enableMemoryTools: boolean;
|
|
43
|
+
getToolsForRoom: (roomId: string) => AdapterToolsProtocol | undefined;
|
|
44
|
+
additionalTools?: McpToolRegistration[];
|
|
45
|
+
}
|
|
46
|
+
interface ThenvoiSdkMcpServer {
|
|
47
|
+
serverConfig: McpSdkServerConfigWithInstance;
|
|
48
|
+
allowedTools: string[];
|
|
49
|
+
toolDefinitions: Array<SdkMcpToolDefinition<any>>;
|
|
50
|
+
}
|
|
51
|
+
declare function createThenvoiSdkMcpServer(options: CreateThenvoiSdkMcpServerOptions): ThenvoiSdkMcpServer;
|
|
52
|
+
|
|
53
|
+
export { type BuildRegistrationsOptions as B, type CreateThenvoiSdkMcpServerOptions as C, type McpToolRegistration as M, type ThenvoiSdkMcpServer as T, type McpToolInputSchema as a, type McpToolResult as b, buildRoomScopedRegistrations as c, buildSingleContextRegistrations as d, errorResult as e, createThenvoiSdkMcpServer as f, successResult as s };
|
package/dist/config.cjs
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/config/index.ts
|
|
31
|
+
var config_exports = {};
|
|
32
|
+
__export(config_exports, {
|
|
33
|
+
loadAgentConfig: () => loadAgentConfig,
|
|
34
|
+
loadAgentConfigFromEnv: () => loadAgentConfigFromEnv
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(config_exports);
|
|
37
|
+
|
|
38
|
+
// src/config/loader.ts
|
|
39
|
+
var import_node_fs = require("fs");
|
|
40
|
+
var import_js_yaml = __toESM(require("js-yaml"), 1);
|
|
41
|
+
|
|
42
|
+
// src/core/errors.ts
|
|
43
|
+
var ThenvoiSdkError = class extends Error {
|
|
44
|
+
constructor(message, cause) {
|
|
45
|
+
super(message, cause !== void 0 ? { cause } : void 0);
|
|
46
|
+
this.name = "ThenvoiSdkError";
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var ValidationError = class extends ThenvoiSdkError {
|
|
50
|
+
constructor(message, cause) {
|
|
51
|
+
super(message, cause);
|
|
52
|
+
this.name = "ValidationError";
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// src/config/loader.ts
|
|
57
|
+
var DEFAULT_CONFIG_PATH = "./agent_config.yaml";
|
|
58
|
+
var DEFAULT_ENV_PREFIX = "THENVOI_";
|
|
59
|
+
var REQUIRED_FIELDS = ["agent_id", "api_key"];
|
|
60
|
+
var UNSAFE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype", "toString", "valueOf"]);
|
|
61
|
+
function toSnakeCase(key) {
|
|
62
|
+
return key.replace(/([A-Z])/g, "_$1").toLowerCase();
|
|
63
|
+
}
|
|
64
|
+
function normalizeKeys(obj) {
|
|
65
|
+
const result = {};
|
|
66
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
67
|
+
result[toSnakeCase(key)] = value;
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
function toAgentConfigResult(section, sourceLabel) {
|
|
72
|
+
const missing = REQUIRED_FIELDS.filter((field) => !section[field]);
|
|
73
|
+
if (missing.length > 0) {
|
|
74
|
+
throw new ValidationError(
|
|
75
|
+
`Missing required fields in ${sourceLabel}: ${missing.join(", ")}`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
const invalid = REQUIRED_FIELDS.filter(
|
|
79
|
+
(field) => {
|
|
80
|
+
const value = section[field];
|
|
81
|
+
return typeof value !== "string" || value.trim() === "";
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
if (invalid.length > 0) {
|
|
85
|
+
throw new ValidationError(
|
|
86
|
+
`Invalid fields in ${sourceLabel}: ${invalid.join(", ")} must be non-empty strings`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
const { agent_id, api_key, ws_url, rest_url, ...rest } = section;
|
|
90
|
+
if (ws_url !== void 0 && typeof ws_url !== "string") {
|
|
91
|
+
throw new ValidationError(`ws_url in ${sourceLabel} must be a string`);
|
|
92
|
+
}
|
|
93
|
+
if (rest_url !== void 0 && typeof rest_url !== "string") {
|
|
94
|
+
throw new ValidationError(`rest_url in ${sourceLabel} must be a string`);
|
|
95
|
+
}
|
|
96
|
+
const safeRest = {};
|
|
97
|
+
for (const [key, value] of Object.entries(rest)) {
|
|
98
|
+
if (!UNSAFE_KEYS.has(key)) {
|
|
99
|
+
safeRest[key] = value;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
agentId: agent_id.trim(),
|
|
104
|
+
apiKey: api_key.trim(),
|
|
105
|
+
...typeof ws_url === "string" && ws_url.trim() !== "" ? { wsUrl: ws_url.trim() } : {},
|
|
106
|
+
...typeof rest_url === "string" && rest_url.trim() !== "" ? { restUrl: rest_url.trim() } : {},
|
|
107
|
+
...safeRest
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function loadAgentConfig(agentKey, configPath) {
|
|
111
|
+
const filePath = configPath ?? DEFAULT_CONFIG_PATH;
|
|
112
|
+
let raw;
|
|
113
|
+
try {
|
|
114
|
+
raw = (0, import_node_fs.readFileSync)(filePath, "utf-8");
|
|
115
|
+
} catch {
|
|
116
|
+
throw new ValidationError(
|
|
117
|
+
`Config file not found: ${filePath}. Copy agent_config.yaml.example to agent_config.yaml and configure your agents.`
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
const parsed = import_js_yaml.default.load(raw, { schema: import_js_yaml.default.JSON_SCHEMA });
|
|
121
|
+
if (!parsed || typeof parsed !== "object") {
|
|
122
|
+
throw new ValidationError(`Invalid config file: ${filePath}. Expected a YAML object.`);
|
|
123
|
+
}
|
|
124
|
+
const config = parsed;
|
|
125
|
+
let section;
|
|
126
|
+
if (agentKey && agentKey in config) {
|
|
127
|
+
const keyed = config[agentKey];
|
|
128
|
+
if (!keyed || typeof keyed !== "object") {
|
|
129
|
+
throw new ValidationError(
|
|
130
|
+
`Config key "${agentKey}" in ${filePath} must be an object with agent_id and api_key.`
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
section = normalizeKeys(keyed);
|
|
134
|
+
} else {
|
|
135
|
+
section = normalizeKeys(config);
|
|
136
|
+
}
|
|
137
|
+
const sourceLabel = agentKey && agentKey in config ? `${filePath} under key "${agentKey}"` : filePath;
|
|
138
|
+
return toAgentConfigResult(section, sourceLabel);
|
|
139
|
+
}
|
|
140
|
+
function loadAgentConfigFromEnv(options) {
|
|
141
|
+
const env = options?.env ?? process.env;
|
|
142
|
+
const prefix = options?.prefix === void 0 ? DEFAULT_ENV_PREFIX : options.prefix === "" || options.prefix.endsWith("_") ? options.prefix : `${options.prefix}_`;
|
|
143
|
+
const section = normalizeKeys({
|
|
144
|
+
agent_id: env[`${prefix}AGENT_ID`],
|
|
145
|
+
api_key: env[`${prefix}API_KEY`],
|
|
146
|
+
ws_url: env[`${prefix}WS_URL`],
|
|
147
|
+
rest_url: env[`${prefix}REST_URL`]
|
|
148
|
+
});
|
|
149
|
+
try {
|
|
150
|
+
return toAgentConfigResult(section, `environment variables (${prefix}AGENT_ID, ${prefix}API_KEY)`);
|
|
151
|
+
} catch (error) {
|
|
152
|
+
if (error instanceof ValidationError) {
|
|
153
|
+
throw new ValidationError(
|
|
154
|
+
`${error.message}. Set ${prefix}AGENT_ID and ${prefix}API_KEY, or use loadAgentConfig() for agent_config.yaml.`
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
161
|
+
0 && (module.exports = {
|
|
162
|
+
loadAgentConfig,
|
|
163
|
+
loadAgentConfigFromEnv
|
|
164
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
interface AgentCredentials {
|
|
2
|
+
agentId: string;
|
|
3
|
+
apiKey: string;
|
|
4
|
+
wsUrl?: string;
|
|
5
|
+
restUrl?: string;
|
|
6
|
+
}
|
|
7
|
+
interface AgentConfigResult extends AgentCredentials {
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
interface LoadAgentConfigFromEnvOptions {
|
|
11
|
+
env?: Record<string, string | undefined>;
|
|
12
|
+
prefix?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Load agent credentials from a YAML config file (defaults to `./agent_config.yaml`). */
|
|
15
|
+
declare function loadAgentConfig(agentKey?: string, configPath?: string): AgentConfigResult;
|
|
16
|
+
/** Load agent credentials from environment variables (prefix defaults to `THENVOI_`). */
|
|
17
|
+
declare function loadAgentConfigFromEnv(options?: LoadAgentConfigFromEnvOptions): AgentCredentials;
|
|
18
|
+
|
|
19
|
+
export { type AgentConfigResult, type AgentCredentials, type LoadAgentConfigFromEnvOptions, loadAgentConfig, loadAgentConfigFromEnv };
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
interface AgentCredentials {
|
|
2
|
+
agentId: string;
|
|
3
|
+
apiKey: string;
|
|
4
|
+
wsUrl?: string;
|
|
5
|
+
restUrl?: string;
|
|
6
|
+
}
|
|
7
|
+
interface AgentConfigResult extends AgentCredentials {
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
interface LoadAgentConfigFromEnvOptions {
|
|
11
|
+
env?: Record<string, string | undefined>;
|
|
12
|
+
prefix?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Load agent credentials from a YAML config file (defaults to `./agent_config.yaml`). */
|
|
15
|
+
declare function loadAgentConfig(agentKey?: string, configPath?: string): AgentConfigResult;
|
|
16
|
+
/** Load agent credentials from environment variables (prefix defaults to `THENVOI_`). */
|
|
17
|
+
declare function loadAgentConfigFromEnv(options?: LoadAgentConfigFromEnvOptions): AgentCredentials;
|
|
18
|
+
|
|
19
|
+
export { type AgentConfigResult, type AgentCredentials, type LoadAgentConfigFromEnvOptions, loadAgentConfig, loadAgentConfigFromEnv };
|