marona 0.5.2 → 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.
- package/CHANGELOG.md +8 -0
- package/README.md +106 -117
- package/dist/index.d.ts +98 -85
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +158 -39
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export const packageVersion = "0.
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export const packageVersion = "0.6.0";
|
|
2
|
+
const standardInterfaces = ["api", "web", "mobile_app", "desktop", "whatsapp"];
|
|
3
|
+
const interfaceNamePattern = "^[a-z][a-z0-9_-]{0,63}$";
|
|
4
|
+
const standardExecutionModes = ["online", "hybrid", "offline"];
|
|
5
5
|
const localExecutionTargetTypes = new Set(["python_package", "wasm", "static_cache", "builtin"]);
|
|
6
6
|
const remoteExecutionTargetTypes = new Set(["remote_mcp", "marona_hosted"]);
|
|
7
7
|
const providerDefaultEndpoints = {
|
|
@@ -23,7 +23,7 @@ const providerEndpointEnvironment = {
|
|
|
23
23
|
ollama: "OLLAMA_API_BASE",
|
|
24
24
|
litellm: "LITELLM_API_BASE",
|
|
25
25
|
};
|
|
26
|
-
|
|
26
|
+
function normalizeExecutionModes(value) {
|
|
27
27
|
const rawModes = Array.isArray(value) ? value : ["online"];
|
|
28
28
|
const modes = [];
|
|
29
29
|
for (const raw of rawModes) {
|
|
@@ -39,7 +39,7 @@ export function normalizeExecutionModes(value) {
|
|
|
39
39
|
}
|
|
40
40
|
return [modes[0]];
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
function supportsExecutionMode(value, mode) {
|
|
43
43
|
const requested = mode.trim().toLowerCase();
|
|
44
44
|
const modes = new Set(normalizeExecutionModes(value));
|
|
45
45
|
if (modes.has("hybrid"))
|
|
@@ -48,7 +48,7 @@ export function supportsExecutionMode(value, mode) {
|
|
|
48
48
|
return modes.has("online") || modes.has("offline");
|
|
49
49
|
return modes.has(requested);
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
function executionModeLabel(value) {
|
|
52
52
|
const modes = normalizeExecutionModes(value);
|
|
53
53
|
if (modes.includes("hybrid"))
|
|
54
54
|
return "Hybrid";
|
|
@@ -85,7 +85,7 @@ export class MaronaModelError extends EdgeRuntimeError {
|
|
|
85
85
|
this.name = "MaronaModelError";
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
|
-
|
|
88
|
+
class MaronaCache {
|
|
89
89
|
syncPayload;
|
|
90
90
|
privateContext;
|
|
91
91
|
apps = new Map();
|
|
@@ -260,7 +260,7 @@ export class MaronaCache {
|
|
|
260
260
|
this.defaultModelName = undefined;
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
|
-
|
|
263
|
+
class ModelManager {
|
|
264
264
|
cache;
|
|
265
265
|
fetchImpl;
|
|
266
266
|
executors = new Map();
|
|
@@ -305,10 +305,6 @@ export class ModelManager {
|
|
|
305
305
|
this.cache.saveModel(detected, { makeDefault: input.makeDefault ?? false });
|
|
306
306
|
return detected;
|
|
307
307
|
}
|
|
308
|
-
use(name) {
|
|
309
|
-
console.warn("models.use() is deprecated; pass model to client() or message().");
|
|
310
|
-
return this.cache.useModel(name);
|
|
311
|
-
}
|
|
312
308
|
get(name) {
|
|
313
309
|
return this.cache.getModel(name);
|
|
314
310
|
}
|
|
@@ -367,11 +363,79 @@ export class ModelManager {
|
|
|
367
363
|
};
|
|
368
364
|
}
|
|
369
365
|
}
|
|
370
|
-
export class
|
|
366
|
+
export class MCPConnection {
|
|
367
|
+
payload;
|
|
368
|
+
executor;
|
|
369
|
+
constructor(payload, executor) {
|
|
370
|
+
this.payload = payload;
|
|
371
|
+
this.executor = executor;
|
|
372
|
+
}
|
|
373
|
+
listTools() {
|
|
374
|
+
return normalizeConnectedTools(this.descriptors()).map((descriptor) => {
|
|
375
|
+
const fn = asRecord(descriptor.function) ?? {};
|
|
376
|
+
return {
|
|
377
|
+
name: stringValue(fn.name) ?? "marona_tool",
|
|
378
|
+
description: stringValue(fn.description) ?? stringValue(fn.name) ?? "Marona tool",
|
|
379
|
+
inputSchema: asRecord(fn.parameters) ?? { type: "object", properties: {} },
|
|
380
|
+
annotations: asRecord(descriptor.marona) ?? {},
|
|
381
|
+
};
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
async callTool(name, argumentsValue = {}) {
|
|
385
|
+
const descriptor = this.descriptors().find((candidate) => {
|
|
386
|
+
const normalized = normalizeConnectedTools([candidate])[0];
|
|
387
|
+
return stringValue(asRecord(normalized?.function)?.name) === name;
|
|
388
|
+
});
|
|
389
|
+
if (!descriptor)
|
|
390
|
+
throw new EdgeRuntimeError(`Connected MCP tool '${name}' was not found.`);
|
|
391
|
+
if (!this.executor) {
|
|
392
|
+
throw new EdgeRuntimeError("This Hub connection can list tools but cannot execute them. Create it through Marona.hub.");
|
|
393
|
+
}
|
|
394
|
+
return this.executor.execute(descriptor, argumentsValue, {
|
|
395
|
+
interfaceName: "api",
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
get serverUrls() {
|
|
399
|
+
const urls = [];
|
|
400
|
+
for (const value of Array.isArray(this.payload.apps) ? this.payload.apps : []) {
|
|
401
|
+
const app = asRecord(value);
|
|
402
|
+
const server = asRecord(app?.mcp_server ?? app?.mcpServer);
|
|
403
|
+
const url = stringValue(server?.server_url ?? server?.serverUrl ?? server?.url);
|
|
404
|
+
if (url)
|
|
405
|
+
urls.push(url);
|
|
406
|
+
}
|
|
407
|
+
for (const descriptor of this.descriptors()) {
|
|
408
|
+
const metadata = asRecord(descriptor.marona ?? descriptor.x_marona) ?? {};
|
|
409
|
+
const url = stringValue(metadata.mcp_server_url ?? metadata.server_url);
|
|
410
|
+
if (url)
|
|
411
|
+
urls.push(url);
|
|
412
|
+
}
|
|
413
|
+
return [...new Set(urls)];
|
|
414
|
+
}
|
|
415
|
+
get serverUrl() {
|
|
416
|
+
return this.serverUrls.length === 1 ? this.serverUrls[0] : undefined;
|
|
417
|
+
}
|
|
418
|
+
get session() {
|
|
419
|
+
return {
|
|
420
|
+
status: this.payload.status,
|
|
421
|
+
execution: this.payload.execution,
|
|
422
|
+
apps: Array.isArray(this.payload.apps) ? this.payload.apps : [],
|
|
423
|
+
skills: Array.isArray(this.payload.skills) ? this.payload.skills : [],
|
|
424
|
+
server_urls: this.serverUrls,
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
descriptors() {
|
|
428
|
+
return Array.isArray(this.payload.connections)
|
|
429
|
+
? this.payload.connections.map(asRecord).filter(Boolean)
|
|
430
|
+
: [];
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
class HubClient {
|
|
371
434
|
baseUrl;
|
|
372
435
|
defaultHeaders;
|
|
373
436
|
timeoutMs;
|
|
374
437
|
fetchImpl;
|
|
438
|
+
toolExecutor;
|
|
375
439
|
constructor(baseUrl = "https://hub.marona.ai", options = {}) {
|
|
376
440
|
this.baseUrl = baseUrl.replace(/\/+$/, "");
|
|
377
441
|
this.timeoutMs = options.timeoutMs ?? 60_000;
|
|
@@ -380,21 +444,22 @@ export class HubClient {
|
|
|
380
444
|
this.defaultHeaders.Authorization = `Bearer ${options.apiKey}`;
|
|
381
445
|
}
|
|
382
446
|
this.fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
447
|
+
this.toolExecutor = options.toolExecutor;
|
|
383
448
|
if (!this.fetchImpl) {
|
|
384
449
|
throw new EdgeRuntimeError("A fetch implementation is required.");
|
|
385
450
|
}
|
|
386
451
|
}
|
|
387
|
-
async connect(
|
|
388
|
-
const payload = await this.connectResult(
|
|
389
|
-
|
|
390
|
-
return Array.isArray(connections) ? connections.map(asRecord).filter(Boolean) : [];
|
|
452
|
+
async connect(options = {}) {
|
|
453
|
+
const payload = await this.connectResult(options);
|
|
454
|
+
return new MCPConnection(payload, this.toolExecutor);
|
|
391
455
|
}
|
|
392
|
-
async connectResult(
|
|
456
|
+
async connectResult(options = {}) {
|
|
393
457
|
const payload = await this.requestJson("POST", "/hub/connect", {
|
|
394
458
|
body: {
|
|
395
|
-
apps,
|
|
459
|
+
...(options.apps ? { apps: options.apps } : {}),
|
|
396
460
|
...(options.skills?.length ? { skills: options.skills } : {}),
|
|
397
|
-
adapter:
|
|
461
|
+
adapter: "tools",
|
|
462
|
+
interface: "api",
|
|
398
463
|
},
|
|
399
464
|
});
|
|
400
465
|
const record = asRecord(payload);
|
|
@@ -439,7 +504,7 @@ export class HubClient {
|
|
|
439
504
|
}
|
|
440
505
|
}
|
|
441
506
|
}
|
|
442
|
-
|
|
507
|
+
class SkillStep {
|
|
443
508
|
definition;
|
|
444
509
|
constructor(definition) {
|
|
445
510
|
this.definition = definition;
|
|
@@ -458,7 +523,7 @@ export class SkillStep {
|
|
|
458
523
|
return { ...this.definition };
|
|
459
524
|
}
|
|
460
525
|
}
|
|
461
|
-
|
|
526
|
+
function step(input) {
|
|
462
527
|
const id = input.id.trim();
|
|
463
528
|
if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(id)) {
|
|
464
529
|
throw new EdgeRuntimeError("Skill step ids must use lowercase kebab-case.");
|
|
@@ -549,7 +614,7 @@ function skillReferences(value) {
|
|
|
549
614
|
...(match[2] ? { path: match[2] } : {}),
|
|
550
615
|
}));
|
|
551
616
|
}
|
|
552
|
-
|
|
617
|
+
class SkillDefinition {
|
|
553
618
|
definition;
|
|
554
619
|
constructor(definition) {
|
|
555
620
|
this.definition = definition;
|
|
@@ -624,7 +689,7 @@ export class SkillDefinition {
|
|
|
624
689
|
});
|
|
625
690
|
}
|
|
626
691
|
}
|
|
627
|
-
|
|
692
|
+
class SkillsClient extends HubClient {
|
|
628
693
|
async publish(definition, options) {
|
|
629
694
|
const payload = await this.requestJson('POST', '/hub/skills/publish', {
|
|
630
695
|
body: { manifest: definition.manifest(options.version) },
|
|
@@ -647,9 +712,9 @@ class MaronaHubClient extends HubClient {
|
|
|
647
712
|
}
|
|
648
713
|
mode;
|
|
649
714
|
cache;
|
|
650
|
-
async connectResult(
|
|
651
|
-
const
|
|
652
|
-
const cached = connectFromCache(this.cache, apps, options.skills ?? [],
|
|
715
|
+
async connectResult(options = {}) {
|
|
716
|
+
const apps = options.apps ?? [];
|
|
717
|
+
const cached = connectFromCache(this.cache, apps, options.skills ?? [], "tools", this.mode);
|
|
653
718
|
if (cached.connections.length > 0 && (this.mode === "offline" || this.mode === "hybrid")) {
|
|
654
719
|
return cached;
|
|
655
720
|
}
|
|
@@ -658,10 +723,10 @@ class MaronaHubClient extends HubClient {
|
|
|
658
723
|
payload: { missing_apps: apps },
|
|
659
724
|
});
|
|
660
725
|
}
|
|
661
|
-
return super.connectResult(
|
|
726
|
+
return super.connectResult(options);
|
|
662
727
|
}
|
|
663
728
|
}
|
|
664
|
-
|
|
729
|
+
class RuntimeAttachment {
|
|
665
730
|
id;
|
|
666
731
|
filename;
|
|
667
732
|
mimeType;
|
|
@@ -909,7 +974,7 @@ function utf8Base64(value) {
|
|
|
909
974
|
function isObject(value) {
|
|
910
975
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
911
976
|
}
|
|
912
|
-
|
|
977
|
+
class RuntimeMessageRequest {
|
|
913
978
|
text;
|
|
914
979
|
model;
|
|
915
980
|
interfaceName;
|
|
@@ -953,7 +1018,7 @@ export class RuntimeMessageRequest {
|
|
|
953
1018
|
});
|
|
954
1019
|
}
|
|
955
1020
|
}
|
|
956
|
-
|
|
1021
|
+
class RealtimeSessionRequest {
|
|
957
1022
|
interfaceName;
|
|
958
1023
|
userId;
|
|
959
1024
|
identityToken;
|
|
@@ -1258,7 +1323,7 @@ class RuntimeTransport {
|
|
|
1258
1323
|
return url.toString();
|
|
1259
1324
|
}
|
|
1260
1325
|
}
|
|
1261
|
-
|
|
1326
|
+
class ToolExecutor {
|
|
1262
1327
|
baseUrl;
|
|
1263
1328
|
headers;
|
|
1264
1329
|
fetchImpl;
|
|
@@ -1316,12 +1381,29 @@ export class ToolExecutor {
|
|
|
1316
1381
|
});
|
|
1317
1382
|
}
|
|
1318
1383
|
}
|
|
1319
|
-
|
|
1384
|
+
class ResponsesClient {
|
|
1385
|
+
runtime;
|
|
1386
|
+
constructor(runtime) {
|
|
1387
|
+
this.runtime = runtime;
|
|
1388
|
+
}
|
|
1389
|
+
async create(options) {
|
|
1390
|
+
const tools = options.tools
|
|
1391
|
+
? normalizeConnectedTools(options.tools.descriptors())
|
|
1392
|
+
: [];
|
|
1393
|
+
return this.runtime.client({
|
|
1394
|
+
...options,
|
|
1395
|
+
model: options.model ?? "marona/default",
|
|
1396
|
+
tools,
|
|
1397
|
+
});
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
class RuntimeEngine extends RuntimeTransport {
|
|
1320
1401
|
hub;
|
|
1321
1402
|
cache;
|
|
1322
1403
|
models;
|
|
1323
1404
|
skills;
|
|
1324
1405
|
tools;
|
|
1406
|
+
responses;
|
|
1325
1407
|
mode;
|
|
1326
1408
|
modelFetchImpl;
|
|
1327
1409
|
developerInstructions;
|
|
@@ -1336,12 +1418,13 @@ export class Marona extends RuntimeTransport {
|
|
|
1336
1418
|
super(options.baseUrl ?? "https://edge.marona.ai", options);
|
|
1337
1419
|
this.mode = mode;
|
|
1338
1420
|
this.cache = options.cache ?? new MaronaCache();
|
|
1339
|
-
this.developerInstructions =
|
|
1340
|
-
this.defaultModelRoute =
|
|
1421
|
+
this.developerInstructions = undefined;
|
|
1422
|
+
this.defaultModelRoute = undefined;
|
|
1341
1423
|
this.providerCredentials = Object.fromEntries(Object.entries(options.providerCredentials ?? {}).map(([key, value]) => [key.toLowerCase(), value]));
|
|
1342
1424
|
this.providerEndpoints = Object.fromEntries(Object.entries(options.providerEndpoints ?? {}).map(([key, value]) => [key.toLowerCase(), value.replace(/\/+$/, "")]));
|
|
1343
1425
|
this.modelFetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
1344
1426
|
this.models = new ModelManager(this.cache, this.modelFetchImpl);
|
|
1427
|
+
this.tools = new ToolExecutor(this.baseUrl, this.defaultHeaders, this.modelFetchImpl);
|
|
1345
1428
|
this.hub = new MaronaHubClient(options.hubUrl ?? "https://hub.marona.ai", {
|
|
1346
1429
|
apiKey: options.apiKey,
|
|
1347
1430
|
timeoutMs: options.timeoutMs,
|
|
@@ -1349,6 +1432,7 @@ export class Marona extends RuntimeTransport {
|
|
|
1349
1432
|
fetchImpl: options.hubFetchImpl ?? options.fetchImpl,
|
|
1350
1433
|
mode,
|
|
1351
1434
|
cache: this.cache,
|
|
1435
|
+
toolExecutor: this.tools,
|
|
1352
1436
|
});
|
|
1353
1437
|
this.skills = new SkillsClient(options.hubUrl ?? 'https://hub.marona.ai', {
|
|
1354
1438
|
apiKey: options.apiKey,
|
|
@@ -1356,7 +1440,7 @@ export class Marona extends RuntimeTransport {
|
|
|
1356
1440
|
headers: options.headers,
|
|
1357
1441
|
fetchImpl: options.hubFetchImpl ?? options.fetchImpl,
|
|
1358
1442
|
});
|
|
1359
|
-
this.
|
|
1443
|
+
this.responses = new ResponsesClient(this);
|
|
1360
1444
|
}
|
|
1361
1445
|
setMode(mode) {
|
|
1362
1446
|
if (!['online', 'offline', 'hybrid'].includes(mode)) {
|
|
@@ -1429,10 +1513,13 @@ export class Marona extends RuntimeTransport {
|
|
|
1429
1513
|
return registered;
|
|
1430
1514
|
const slash = reference.indexOf("/");
|
|
1431
1515
|
if (slash <= 0 || slash === reference.length - 1) {
|
|
1432
|
-
|
|
1516
|
+
return undefined;
|
|
1433
1517
|
}
|
|
1434
|
-
const
|
|
1518
|
+
const routeProvider = reference.slice(0, slash).toLowerCase();
|
|
1519
|
+
const provider = routeProvider === "google" ? "gemini" : routeProvider;
|
|
1435
1520
|
const providerModel = reference.slice(slash + 1);
|
|
1521
|
+
if (provider === "marona")
|
|
1522
|
+
return undefined;
|
|
1436
1523
|
if (provider === "local") {
|
|
1437
1524
|
throw new MaronaModelError(`Local model '${reference}' must be registered with an executor.`);
|
|
1438
1525
|
}
|
|
@@ -1620,6 +1707,7 @@ export class Marona extends RuntimeTransport {
|
|
|
1620
1707
|
status: "completed",
|
|
1621
1708
|
reply: reply || "Done.",
|
|
1622
1709
|
text: reply || "Done.",
|
|
1710
|
+
outputText: reply || "Done.",
|
|
1623
1711
|
interfaceName: options.interfaceName ?? options.interface ?? "api",
|
|
1624
1712
|
conversationId: options.conversationId ?? options.conversation_id,
|
|
1625
1713
|
artifacts: [],
|
|
@@ -1826,6 +1914,36 @@ export class Marona extends RuntimeTransport {
|
|
|
1826
1914
|
});
|
|
1827
1915
|
}
|
|
1828
1916
|
}
|
|
1917
|
+
export class Hub {
|
|
1918
|
+
hub;
|
|
1919
|
+
constructor(hub) {
|
|
1920
|
+
this.hub = hub;
|
|
1921
|
+
}
|
|
1922
|
+
connect(options = {}) {
|
|
1923
|
+
return this.hub.connect(options);
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
export class Models {
|
|
1927
|
+
models;
|
|
1928
|
+
constructor(models) {
|
|
1929
|
+
this.models = models;
|
|
1930
|
+
}
|
|
1931
|
+
register(input) {
|
|
1932
|
+
return this.models.register({ ...input, makeDefault: false });
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
export class Marona {
|
|
1936
|
+
hub;
|
|
1937
|
+
responses;
|
|
1938
|
+
models;
|
|
1939
|
+
runtime;
|
|
1940
|
+
constructor(options = {}) {
|
|
1941
|
+
this.runtime = new RuntimeEngine(options);
|
|
1942
|
+
this.hub = new Hub(this.runtime.hub);
|
|
1943
|
+
this.responses = new ResponsesClient(this.runtime);
|
|
1944
|
+
this.models = new Models(this.runtime.models);
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1829
1947
|
function parseRuntimeMessageResponse(payload) {
|
|
1830
1948
|
const ui = asRecord(payload.ui);
|
|
1831
1949
|
const reply = stringValue(payload.reply) || "";
|
|
@@ -1833,6 +1951,7 @@ function parseRuntimeMessageResponse(payload) {
|
|
|
1833
1951
|
status: stringValue(payload.status) || "unknown",
|
|
1834
1952
|
reply,
|
|
1835
1953
|
text: reply,
|
|
1954
|
+
outputText: reply,
|
|
1836
1955
|
interfaceName: stringValue(payload.interface) || "api",
|
|
1837
1956
|
conversationId: stringValue(payload.conversation_id),
|
|
1838
1957
|
ui: ui ? parseRuntimeUI(ui) : undefined,
|