@meshagent/meshagent 0.5.18 → 0.6.0

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.
Files changed (62) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/browser/agent-client.d.ts +15 -7
  3. package/dist/browser/agent-client.js +52 -14
  4. package/dist/browser/api_keys.d.ts +13 -0
  5. package/dist/browser/api_keys.js +185 -0
  6. package/dist/browser/data-types.d.ts +6 -0
  7. package/dist/browser/data-types.js +20 -1
  8. package/dist/browser/entrypoint.d.ts +1423 -1464
  9. package/dist/browser/helpers.d.ts +9 -7
  10. package/dist/browser/helpers.js +18 -5
  11. package/dist/browser/index.d.ts +3 -0
  12. package/dist/browser/index.js +3 -0
  13. package/dist/browser/lk-client.d.ts +18 -0
  14. package/dist/browser/lk-client.js +24 -0
  15. package/dist/browser/lk-protocol.d.ts +22 -0
  16. package/dist/browser/lk-protocol.js +37 -0
  17. package/dist/browser/meshagent-client.d.ts +392 -0
  18. package/dist/browser/meshagent-client.js +1051 -0
  19. package/dist/browser/participant-token.d.ts +179 -7
  20. package/dist/browser/participant-token.js +373 -21
  21. package/dist/browser/stream-controller.js +3 -14
  22. package/dist/esm/agent-client.d.ts +15 -7
  23. package/dist/esm/agent-client.js +52 -14
  24. package/dist/esm/api_keys.d.ts +13 -0
  25. package/dist/esm/api_keys.js +175 -0
  26. package/dist/esm/data-types.d.ts +6 -0
  27. package/dist/esm/data-types.js +18 -0
  28. package/dist/esm/entrypoint.d.ts +1423 -1464
  29. package/dist/esm/helpers.d.ts +9 -7
  30. package/dist/esm/helpers.js +19 -6
  31. package/dist/esm/index.d.ts +3 -0
  32. package/dist/esm/index.js +3 -0
  33. package/dist/esm/lk-client.d.ts +18 -0
  34. package/dist/esm/lk-client.js +19 -0
  35. package/dist/esm/lk-protocol.d.ts +22 -0
  36. package/dist/esm/lk-protocol.js +33 -0
  37. package/dist/esm/meshagent-client.d.ts +392 -0
  38. package/dist/esm/meshagent-client.js +1047 -0
  39. package/dist/esm/participant-token.d.ts +179 -7
  40. package/dist/esm/participant-token.js +357 -20
  41. package/dist/esm/stream-controller.js +3 -14
  42. package/dist/node/agent-client.d.ts +15 -7
  43. package/dist/node/agent-client.js +52 -14
  44. package/dist/node/api_keys.d.ts +13 -0
  45. package/dist/node/api_keys.js +185 -0
  46. package/dist/node/data-types.d.ts +6 -0
  47. package/dist/node/data-types.js +20 -1
  48. package/dist/node/entrypoint.d.ts +1423 -1464
  49. package/dist/node/helpers.d.ts +9 -7
  50. package/dist/node/helpers.js +18 -5
  51. package/dist/node/index.d.ts +3 -0
  52. package/dist/node/index.js +3 -0
  53. package/dist/node/lk-client.d.ts +18 -0
  54. package/dist/node/lk-client.js +24 -0
  55. package/dist/node/lk-protocol.d.ts +22 -0
  56. package/dist/node/lk-protocol.js +37 -0
  57. package/dist/node/meshagent-client.d.ts +392 -0
  58. package/dist/node/meshagent-client.js +1051 -0
  59. package/dist/node/participant-token.d.ts +179 -7
  60. package/dist/node/participant-token.js +373 -21
  61. package/dist/node/stream-controller.js +3 -14
  62. package/package.json +6 -3
@@ -1,5 +1,6 @@
1
1
  import { RoomClient } from "./room-client";
2
- import { Response } from "./response";
2
+ import { Response, JsonResponse } from "./response";
3
+ import { RemoteParticipant } from "./participant";
3
4
  import { Requirement } from "./requirement";
4
5
  export declare class AgentDescription {
5
6
  readonly name: string;
@@ -16,10 +17,11 @@ export declare class AgentDescription {
16
17
  description: string;
17
18
  outputSchema?: Record<string, any>;
18
19
  inputSchema?: Record<string, any>;
19
- requires: Requirement[];
20
- labels: string[];
20
+ requires?: Requirement[];
21
+ labels?: string[];
21
22
  supportsTools: boolean;
22
23
  });
24
+ toJson(): Record<string, any>;
23
25
  static fromJson(a: Record<string, any>): AgentDescription;
24
26
  }
25
27
  export declare class ToolDescription {
@@ -29,13 +31,17 @@ export declare class ToolDescription {
29
31
  inputSchema: Record<string, any>;
30
32
  defs?: Record<string, any>;
31
33
  thumbnailUrl?: string;
32
- constructor({ title, name, description, inputSchema, thumbnailUrl, defs }: {
34
+ pricing?: string;
35
+ supportsContext?: boolean;
36
+ constructor({ title, name, description, inputSchema, thumbnailUrl, defs, pricing, supportsContext }: {
33
37
  title: string;
34
38
  name: string;
35
39
  description: string;
36
40
  inputSchema: Record<string, any>;
37
41
  thumbnailUrl?: string;
38
42
  defs?: Record<string, any>;
43
+ pricing?: string;
44
+ supportsContext?: boolean;
39
45
  });
40
46
  }
41
47
  export declare class ToolkitDescription {
@@ -53,6 +59,7 @@ export declare class ToolkitDescription {
53
59
  thumbnailUrl?: string;
54
60
  });
55
61
  getTool(name: string): ToolDescription | undefined;
62
+ toJson(): Record<string, any>;
56
63
  static fromJson(json: Record<string, any>, opts?: {
57
64
  name?: string;
58
65
  }): ToolkitDescription;
@@ -74,10 +81,11 @@ export declare class AgentsClient {
74
81
  arguments: Record<string, any>;
75
82
  }): Promise<void>;
76
83
  ask(params: {
77
- agentName: string;
78
- toolkits?: ToolkitConfiguration[];
84
+ agent: string;
79
85
  arguments: Record<string, any>;
80
- }): Promise<Record<string, any>>;
86
+ onBehalfOf?: RemoteParticipant;
87
+ requires?: Requirement[];
88
+ }): Promise<JsonResponse>;
81
89
  listToolkits(): Promise<ToolkitDescription[]>;
82
90
  listAgents(): Promise<AgentDescription[]>;
83
91
  invokeTool(params: {
@@ -1,3 +1,4 @@
1
+ import { JsonResponse } from "./response";
1
2
  import { RequiredToolkit, RequiredSchema } from "./requirement";
2
3
  export class AgentDescription {
3
4
  constructor({ name, title, description, outputSchema, inputSchema, requires, labels, supportsTools, }) {
@@ -6,9 +7,21 @@ export class AgentDescription {
6
7
  this.description = description;
7
8
  this.outputSchema = outputSchema;
8
9
  this.inputSchema = inputSchema;
9
- this.requires = requires;
10
- this.labels = labels;
11
- this.supportsTools = supportsTools;
10
+ this.requires = Array.isArray(requires) ? requires : [];
11
+ this.labels = Array.isArray(labels) ? labels : [];
12
+ this.supportsTools = supportsTools ?? false;
13
+ }
14
+ toJson() {
15
+ return {
16
+ name: this.name,
17
+ title: this.title,
18
+ description: this.description,
19
+ input_schema: this.inputSchema,
20
+ output_schema: this.outputSchema,
21
+ labels: this.labels,
22
+ supports_tools: this.supportsTools,
23
+ requires: this.requires.map((requirement) => requirement.toJson()),
24
+ };
12
25
  }
13
26
  static fromJson(a) {
14
27
  let requires = [];
@@ -40,13 +53,15 @@ export class AgentDescription {
40
53
  }
41
54
  }
42
55
  export class ToolDescription {
43
- constructor({ title, name, description, inputSchema, thumbnailUrl, defs }) {
56
+ constructor({ title, name, description, inputSchema, thumbnailUrl, defs, pricing, supportsContext }) {
44
57
  this.title = title;
45
58
  this.name = name;
46
59
  this.description = description;
47
60
  this.inputSchema = inputSchema;
48
61
  this.thumbnailUrl = thumbnailUrl;
49
62
  this.defs = defs;
63
+ this.pricing = pricing;
64
+ this.supportsContext = supportsContext ?? false;
50
65
  }
51
66
  }
52
67
  export class ToolkitDescription {
@@ -61,6 +76,22 @@ export class ToolkitDescription {
61
76
  getTool(name) {
62
77
  return this._byName.get(name);
63
78
  }
79
+ toJson() {
80
+ return {
81
+ name: this.name,
82
+ description: this.description,
83
+ title: this.title,
84
+ thumbnail_url: this.thumbnailUrl,
85
+ tools: this.tools.map((tool) => ({
86
+ name: tool.name,
87
+ title: tool.title,
88
+ description: tool.description,
89
+ input_schema: tool.inputSchema,
90
+ thumbnail_url: tool.thumbnailUrl,
91
+ defs: tool.defs,
92
+ })),
93
+ };
94
+ }
64
95
  static fromJson(json, opts) {
65
96
  const { name } = opts ?? {};
66
97
  const title = json["title"] ?? "";
@@ -77,6 +108,8 @@ export class ToolkitDescription {
77
108
  inputSchema: tool["input_schema"],
78
109
  thumbnailUrl: tool["thumbnail_url"],
79
110
  defs: tool["defs"],
111
+ pricing: tool["pricing"],
112
+ supportsContext: tool["supportsContext"],
80
113
  }));
81
114
  }
82
115
  }
@@ -91,6 +124,8 @@ export class ToolkitDescription {
91
124
  inputSchema: tool["input_schema"],
92
125
  thumbnailUrl: tool["thumbnail_url"],
93
126
  defs: tool["defs"],
127
+ pricing: tool["pricing"],
128
+ supportsContext: tool["supportsContext"],
94
129
  }));
95
130
  }
96
131
  }
@@ -134,17 +169,20 @@ export class AgentsClient {
134
169
  await this.client.sendRequest("agent.call", params);
135
170
  }
136
171
  async ask(params) {
137
- const { agentName, toolkits = [], arguments: args } = params;
138
- const usedToolkits = {};
139
- for (const t of toolkits) {
140
- Object.assign(usedToolkits, t.toJson());
141
- }
142
- const result = (await this.client.sendRequest("agent.ask", {
143
- agent: agentName,
172
+ const { agent, arguments: args, onBehalfOf, requires } = params;
173
+ const payload = {
174
+ agent,
144
175
  arguments: args,
145
- toolkits: usedToolkits,
146
- }));
147
- return result.json["answer"];
176
+ };
177
+ if (onBehalfOf) {
178
+ payload["on_behalf_of_id"] = onBehalfOf.id;
179
+ }
180
+ if (requires && requires.length > 0) {
181
+ payload["requires"] = requires.map((req) => req.toJson());
182
+ }
183
+ const result = (await this.client.sendRequest("agent.ask", payload));
184
+ const answer = (result.json["answer"] ?? {});
185
+ return new JsonResponse({ json: answer });
148
186
  }
149
187
  async listToolkits() {
150
188
  const result = (await this.client.sendRequest("agent.list_toolkits", {}));
@@ -0,0 +1,13 @@
1
+ export declare function base36Encode(value: bigint | number): string;
2
+ export declare function base36Decode(numberStr: string): bigint;
3
+ export declare function compressUuid(guidString: string): string;
4
+ export declare function decompressUuid(compressedUuid: string): string;
5
+ export declare function base64CompressUuid(id: string): string;
6
+ export declare function base64DecompressUuid(id: string): string;
7
+ export interface ApiKey {
8
+ id: string;
9
+ projectId: string;
10
+ secret: string;
11
+ }
12
+ export declare function parseApiKey(key: string): ApiKey;
13
+ export declare function encodeApiKey(key: ApiKey): string;
@@ -0,0 +1,175 @@
1
+ import { encode as base64Encode, decode as base64Decode } from "base-64";
2
+ const BASE36_ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz";
3
+ const BASE36 = 36n;
4
+ const UUID_HEX_REGEX = /^[0-9a-f]{32}$/;
5
+ function toBigInt(value) {
6
+ if (typeof value === "bigint") {
7
+ return value;
8
+ }
9
+ if (typeof value === "number") {
10
+ if (!Number.isInteger(value)) {
11
+ throw new TypeError("number must be an integer");
12
+ }
13
+ return BigInt(value);
14
+ }
15
+ throw new TypeError("number must be an integer");
16
+ }
17
+ export function base36Encode(value) {
18
+ const number = toBigInt(value);
19
+ if (number < 0n) {
20
+ throw new RangeError("number must be non-negative");
21
+ }
22
+ if (number === 0n) {
23
+ return "0";
24
+ }
25
+ let current = number;
26
+ let base36 = "";
27
+ while (current > 0n) {
28
+ const remainder = Number(current % BASE36);
29
+ base36 = BASE36_ALPHABET[remainder] + base36;
30
+ current /= BASE36;
31
+ }
32
+ return base36;
33
+ }
34
+ export function base36Decode(numberStr) {
35
+ const sanitized = numberStr.trim().toLowerCase();
36
+ if (sanitized === "") {
37
+ return 0n;
38
+ }
39
+ let result = 0n;
40
+ for (const char of sanitized) {
41
+ const value = BASE36_ALPHABET.indexOf(char);
42
+ if (value === -1) {
43
+ throw new RangeError(`Invalid character '${char}' for base36 encoding`);
44
+ }
45
+ result = result * BASE36 + BigInt(value);
46
+ }
47
+ return result;
48
+ }
49
+ function normalizeUuidHex(id) {
50
+ const trimmed = id.trim().toLowerCase().replace(/-/g, "");
51
+ if (!UUID_HEX_REGEX.test(trimmed)) {
52
+ throw new Error("invalid uuid format");
53
+ }
54
+ return trimmed;
55
+ }
56
+ function formatUuidFromHex(hex) {
57
+ return (`${hex.substring(0, 8)}-` +
58
+ `${hex.substring(8, 12)}-` +
59
+ `${hex.substring(12, 16)}-` +
60
+ `${hex.substring(16, 20)}-` +
61
+ `${hex.substring(20)}`);
62
+ }
63
+ function hexToBytes(hex) {
64
+ if (hex.length % 2 !== 0) {
65
+ throw new Error("invalid hex string length");
66
+ }
67
+ const bytes = new Uint8Array(hex.length / 2);
68
+ for (let i = 0; i < hex.length; i += 2) {
69
+ bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);
70
+ }
71
+ return bytes;
72
+ }
73
+ function bytesToHex(bytes) {
74
+ return Array.from(bytes, byte => byte.toString(16).padStart(2, "0")).join("");
75
+ }
76
+ const globalScope = globalThis;
77
+ function bytesToBase64(bytes) {
78
+ if (globalScope.Buffer) {
79
+ return globalScope.Buffer.from(bytes).toString("base64");
80
+ }
81
+ let binary = "";
82
+ for (const byte of bytes) {
83
+ binary += String.fromCharCode(byte);
84
+ }
85
+ if (globalScope.btoa) {
86
+ return globalScope.btoa(binary);
87
+ }
88
+ return base64Encode(binary);
89
+ }
90
+ function base64ToBytes(base64) {
91
+ if (globalScope.Buffer) {
92
+ const buffer = globalScope.Buffer.from(base64, "base64");
93
+ return Uint8Array.from(buffer);
94
+ }
95
+ let binary;
96
+ if (globalScope.atob) {
97
+ binary = globalScope.atob(base64);
98
+ }
99
+ else {
100
+ binary = base64Decode(base64);
101
+ }
102
+ const bytes = new Uint8Array(binary.length);
103
+ for (let i = 0; i < binary.length; i += 1) {
104
+ bytes[i] = binary.charCodeAt(i);
105
+ }
106
+ return bytes;
107
+ }
108
+ export function compressUuid(guidString) {
109
+ const hex = normalizeUuidHex(guidString);
110
+ const guidInt = BigInt(`0x${hex}`);
111
+ return base36Encode(guidInt);
112
+ }
113
+ export function decompressUuid(compressedUuid) {
114
+ const guidInt = base36Decode(compressedUuid);
115
+ const hex = guidInt.toString(16).padStart(32, "0");
116
+ return formatUuidFromHex(hex);
117
+ }
118
+ export function base64CompressUuid(id) {
119
+ const hex = normalizeUuidHex(id);
120
+ const bytes = hexToBytes(hex);
121
+ const base64 = bytesToBase64(bytes)
122
+ .replace(/\+/g, "-")
123
+ .replace(/\//g, "_");
124
+ return base64.replace(/-/g, ".").replace(/=+$/g, "");
125
+ }
126
+ export function base64DecompressUuid(id) {
127
+ let base64 = id.replace(/\./g, "-");
128
+ const paddingNeeded = base64.length % 4;
129
+ if (paddingNeeded !== 0) {
130
+ base64 += "=".repeat(4 - paddingNeeded);
131
+ }
132
+ base64 = base64.replace(/-/g, "+").replace(/_/g, "/");
133
+ const bytes = base64ToBytes(base64);
134
+ if (bytes.length !== 16) {
135
+ throw new Error("invalid uuid length");
136
+ }
137
+ return formatUuidFromHex(bytesToHex(bytes));
138
+ }
139
+ function splitApiKey(key) {
140
+ const rest = key.slice(3);
141
+ const firstSeparator = rest.indexOf("-");
142
+ if (firstSeparator === -1) {
143
+ throw new Error("invalid api key");
144
+ }
145
+ const secondSeparator = rest.indexOf("-", firstSeparator + 1);
146
+ if (secondSeparator === -1) {
147
+ throw new Error("invalid api key");
148
+ }
149
+ const idPart = rest.slice(0, firstSeparator);
150
+ const projectPart = rest.slice(firstSeparator + 1, secondSeparator);
151
+ const secret = rest.slice(secondSeparator + 1);
152
+ if (!idPart || !projectPart || secret === undefined) {
153
+ throw new Error("invalid api key");
154
+ }
155
+ return { idPart, projectPart, secret };
156
+ }
157
+ export function parseApiKey(key) {
158
+ if (!key.startsWith("ma-")) {
159
+ throw new Error("invalid api key");
160
+ }
161
+ const { idPart, projectPart, secret } = splitApiKey(key);
162
+ return {
163
+ id: base64DecompressUuid(idPart),
164
+ projectId: base64DecompressUuid(projectPart),
165
+ secret,
166
+ };
167
+ }
168
+ export function encodeApiKey(key) {
169
+ return ("ma-" +
170
+ base64CompressUuid(key.id) +
171
+ "-" +
172
+ base64CompressUuid(key.projectId) +
173
+ "-" +
174
+ key.secret);
175
+ }
@@ -11,6 +11,7 @@ export declare abstract class DataType {
11
11
  elementType: DataType;
12
12
  }): VectorDataType;
13
13
  static text(): TextDataType;
14
+ static binary(): BinaryDataType;
14
15
  }
15
16
  export declare class IntDataType extends DataType {
16
17
  constructor();
@@ -42,3 +43,8 @@ export declare class TextDataType extends DataType {
42
43
  static fromJson(data: any): TextDataType;
43
44
  toJson(): Record<string, unknown>;
44
45
  }
46
+ export declare class BinaryDataType extends DataType {
47
+ constructor();
48
+ static fromJson(data: any): BinaryDataType;
49
+ toJson(): Record<string, unknown>;
50
+ }
@@ -23,6 +23,9 @@ export class DataType {
23
23
  static text() {
24
24
  return new TextDataType();
25
25
  }
26
+ static binary() {
27
+ return new BinaryDataType();
28
+ }
26
29
  }
27
30
  export class IntDataType extends DataType {
28
31
  constructor() {
@@ -108,3 +111,18 @@ export class TextDataType extends DataType {
108
111
  }
109
112
  }
110
113
  _dataTypes["text"] = TextDataType;
114
+ export class BinaryDataType extends DataType {
115
+ constructor() {
116
+ super();
117
+ }
118
+ static fromJson(data) {
119
+ if (data.type !== "binary") {
120
+ throw new Error(`Expected type 'binary', got '${data.type}'`);
121
+ }
122
+ return new BinaryDataType();
123
+ }
124
+ toJson() {
125
+ return { type: "binary" };
126
+ }
127
+ }
128
+ _dataTypes["binary"] = BinaryDataType;