@agent-commons/sdk 0.2.0 → 0.2.1
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/index.cjs +368 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +144 -3
- package/dist/index.d.ts +144 -3
- package/dist/index.mjs +365 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -21,14 +21,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
CommonsClient: () => CommonsClient,
|
|
24
|
-
CommonsError: () => CommonsError
|
|
24
|
+
CommonsError: () => CommonsError,
|
|
25
|
+
buildWorkflowTemplate: () => buildWorkflowTemplate,
|
|
26
|
+
listWorkflowTemplates: () => listWorkflowTemplates
|
|
25
27
|
});
|
|
26
28
|
module.exports = __toCommonJS(index_exports);
|
|
27
29
|
|
|
28
30
|
// src/client.ts
|
|
29
31
|
var CommonsClient = class {
|
|
30
32
|
constructor(config) {
|
|
31
|
-
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
33
|
+
this.baseUrl = (config.baseUrl ?? "https://api.agentcommons.io").replace(/\/$/, "");
|
|
32
34
|
this.apiKey = config.apiKey;
|
|
33
35
|
this.initiator = config.initiator;
|
|
34
36
|
this._fetch = config.fetch ?? fetch;
|
|
@@ -457,6 +459,28 @@ var CommonsClient = class {
|
|
|
457
459
|
getSessionUsage: (sessionId) => this.request("GET", `/v1/usage/sessions/${sessionId}`)
|
|
458
460
|
};
|
|
459
461
|
}
|
|
462
|
+
// ── Credits ──────────────────────────────────────────────────────────────
|
|
463
|
+
get credits() {
|
|
464
|
+
return {
|
|
465
|
+
balance: (filter) => {
|
|
466
|
+
const params = new URLSearchParams();
|
|
467
|
+
if (filter?.principalId) params.set("principalId", filter.principalId);
|
|
468
|
+
if (filter?.workspaceId) params.set("workspaceId", filter.workspaceId);
|
|
469
|
+
const qs = params.toString();
|
|
470
|
+
return this.request("GET", `/v1/credits/balance${qs ? `?${qs}` : ""}`);
|
|
471
|
+
},
|
|
472
|
+
ledger: (filter) => {
|
|
473
|
+
const params = new URLSearchParams();
|
|
474
|
+
if (filter?.principalId) params.set("principalId", filter.principalId);
|
|
475
|
+
if (filter?.workspaceId) params.set("workspaceId", filter.workspaceId);
|
|
476
|
+
if (filter?.limit) params.set("limit", String(filter.limit));
|
|
477
|
+
const qs = params.toString();
|
|
478
|
+
return this.request("GET", `/v1/credits/ledger${qs ? `?${qs}` : ""}`);
|
|
479
|
+
},
|
|
480
|
+
grant: (params) => this.request("POST", "/v1/credits/grants", params),
|
|
481
|
+
debit: (params) => this.request("POST", "/v1/credits/debits", params)
|
|
482
|
+
};
|
|
483
|
+
}
|
|
460
484
|
};
|
|
461
485
|
var CommonsError = class extends Error {
|
|
462
486
|
constructor(message, status, data) {
|
|
@@ -466,9 +490,350 @@ var CommonsError = class extends Error {
|
|
|
466
490
|
this.name = "CommonsError";
|
|
467
491
|
}
|
|
468
492
|
};
|
|
493
|
+
|
|
494
|
+
// src/workflow-templates.ts
|
|
495
|
+
function toolName(prefix, name) {
|
|
496
|
+
return `${prefix}_${name}`.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
497
|
+
}
|
|
498
|
+
function functionTool(params) {
|
|
499
|
+
return {
|
|
500
|
+
name: params.name,
|
|
501
|
+
displayName: params.displayName,
|
|
502
|
+
description: params.description,
|
|
503
|
+
visibility: "private",
|
|
504
|
+
ownerType: "user",
|
|
505
|
+
category: "public-api",
|
|
506
|
+
tags: params.tags,
|
|
507
|
+
schema: {
|
|
508
|
+
type: "function",
|
|
509
|
+
function: {
|
|
510
|
+
name: params.name,
|
|
511
|
+
description: params.description,
|
|
512
|
+
parameters: {
|
|
513
|
+
type: "object",
|
|
514
|
+
properties: params.properties,
|
|
515
|
+
required: params.required ?? []
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
},
|
|
519
|
+
apiSpec: params.apiSpec
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
function listWorkflowTemplates() {
|
|
523
|
+
return [
|
|
524
|
+
{
|
|
525
|
+
name: "country-weather-brief",
|
|
526
|
+
description: "Tool-only workflow using countries.dev and Open-Meteo."
|
|
527
|
+
},
|
|
528
|
+
{
|
|
529
|
+
name: "agent-research-summary",
|
|
530
|
+
description: "Multi-tool workflow with an agent_processor summarization step."
|
|
531
|
+
},
|
|
532
|
+
{
|
|
533
|
+
name: "multi-agent-field-report",
|
|
534
|
+
description: "Multi-tool workflow with two agent_processor nodes."
|
|
535
|
+
},
|
|
536
|
+
{
|
|
537
|
+
name: "workflow-invocation-smoke",
|
|
538
|
+
description: "Parent workflow that invokes another workflow as a workflow node."
|
|
539
|
+
}
|
|
540
|
+
];
|
|
541
|
+
}
|
|
542
|
+
function buildWorkflowTemplate(templateName, ctx) {
|
|
543
|
+
switch (templateName) {
|
|
544
|
+
case "country-weather-brief":
|
|
545
|
+
return countryWeatherBrief(ctx);
|
|
546
|
+
case "agent-research-summary":
|
|
547
|
+
return agentResearchSummary(ctx);
|
|
548
|
+
case "multi-agent-field-report":
|
|
549
|
+
return multiAgentFieldReport(ctx);
|
|
550
|
+
case "workflow-invocation-smoke":
|
|
551
|
+
return workflowInvocationSmoke(ctx);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
function sharedTools(ctx) {
|
|
555
|
+
const countryLookup = functionTool({
|
|
556
|
+
name: toolName(ctx.prefix, "country_lookup"),
|
|
557
|
+
displayName: "countries.dev country search",
|
|
558
|
+
description: "Look up country metadata by country name using countries.dev.",
|
|
559
|
+
tags: ["template", "countries-dev", "public-api"],
|
|
560
|
+
properties: {
|
|
561
|
+
country: {
|
|
562
|
+
type: "string",
|
|
563
|
+
description: 'Country name, for example "Finland" or "Kenya".'
|
|
564
|
+
}
|
|
565
|
+
},
|
|
566
|
+
required: ["country"],
|
|
567
|
+
apiSpec: {
|
|
568
|
+
method: "GET",
|
|
569
|
+
baseUrl: "https://countries.dev",
|
|
570
|
+
path: "/name/{country}",
|
|
571
|
+
authType: "none"
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
const weatherForecast = functionTool({
|
|
575
|
+
name: toolName(ctx.prefix, "open_meteo_weather"),
|
|
576
|
+
displayName: "Open-Meteo current weather",
|
|
577
|
+
description: "Get current weather for latitude and longitude using Open-Meteo.",
|
|
578
|
+
tags: ["template", "open-meteo", "public-api", "weather"],
|
|
579
|
+
properties: {
|
|
580
|
+
latitude: { type: "number", description: "Latitude in decimal degrees." },
|
|
581
|
+
longitude: { type: "number", description: "Longitude in decimal degrees." }
|
|
582
|
+
},
|
|
583
|
+
required: ["latitude", "longitude"],
|
|
584
|
+
apiSpec: {
|
|
585
|
+
method: "GET",
|
|
586
|
+
baseUrl: "https://api.open-meteo.com",
|
|
587
|
+
path: "/v1/forecast",
|
|
588
|
+
queryParams: {
|
|
589
|
+
latitude: "{latitude}",
|
|
590
|
+
longitude: "{longitude}",
|
|
591
|
+
current: "temperature_2m,relative_humidity_2m,wind_speed_10m",
|
|
592
|
+
timezone: "auto"
|
|
593
|
+
},
|
|
594
|
+
authType: "none"
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
const openLibrarySearch = functionTool({
|
|
598
|
+
name: toolName(ctx.prefix, "open_library_search"),
|
|
599
|
+
displayName: "Open Library search",
|
|
600
|
+
description: "Search books and authors using Open Library.",
|
|
601
|
+
tags: ["template", "open-library", "public-api", "books"],
|
|
602
|
+
properties: {
|
|
603
|
+
query: { type: "string", description: "Book, author, or topic search query." },
|
|
604
|
+
limit: { type: "number", description: "Maximum result count." }
|
|
605
|
+
},
|
|
606
|
+
required: ["query"],
|
|
607
|
+
apiSpec: {
|
|
608
|
+
method: "GET",
|
|
609
|
+
baseUrl: "https://openlibrary.org",
|
|
610
|
+
path: "/search.json",
|
|
611
|
+
queryParams: {
|
|
612
|
+
q: "{query}",
|
|
613
|
+
limit: "{limit}",
|
|
614
|
+
fields: "key,title,author_name,first_publish_year"
|
|
615
|
+
},
|
|
616
|
+
authType: "none"
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
const exchangeRate = functionTool({
|
|
620
|
+
name: toolName(ctx.prefix, "frankfurter_exchange_rate"),
|
|
621
|
+
displayName: "Frankfurter exchange rate",
|
|
622
|
+
description: "Get a current exchange rate from USD to another currency using Frankfurter.",
|
|
623
|
+
tags: ["template", "frankfurter", "public-api", "exchange-rate"],
|
|
624
|
+
properties: {
|
|
625
|
+
to: { type: "string", description: 'Target ISO 4217 currency code, for example "JPY".' }
|
|
626
|
+
},
|
|
627
|
+
required: ["to"],
|
|
628
|
+
apiSpec: {
|
|
629
|
+
method: "GET",
|
|
630
|
+
baseUrl: "https://api.frankfurter.dev",
|
|
631
|
+
path: "/v2/rates",
|
|
632
|
+
queryParams: {
|
|
633
|
+
base: "USD",
|
|
634
|
+
quotes: "{to}"
|
|
635
|
+
},
|
|
636
|
+
authType: "none"
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
return { countryLookup, weatherForecast, openLibrarySearch, exchangeRate };
|
|
640
|
+
}
|
|
641
|
+
function countryWeatherDefinition(toolIds) {
|
|
642
|
+
return {
|
|
643
|
+
nodes: [
|
|
644
|
+
{ id: "input", type: "input", position: { x: 0, y: 80 } },
|
|
645
|
+
{ id: "country", type: "tool", toolId: toolIds.countryLookup, position: { x: 240, y: 20 } },
|
|
646
|
+
{ id: "weather", type: "tool", toolId: toolIds.weatherForecast, position: { x: 520, y: 20 } },
|
|
647
|
+
{ id: "output", type: "output", position: { x: 820, y: 80 } }
|
|
648
|
+
],
|
|
649
|
+
edges: [
|
|
650
|
+
{
|
|
651
|
+
id: "input-country",
|
|
652
|
+
source: "input",
|
|
653
|
+
target: "country",
|
|
654
|
+
mapping: { country: "country" }
|
|
655
|
+
},
|
|
656
|
+
{
|
|
657
|
+
id: "country-weather",
|
|
658
|
+
source: "country",
|
|
659
|
+
target: "weather",
|
|
660
|
+
mapping: {
|
|
661
|
+
"0.latlng.0": "latitude",
|
|
662
|
+
"0.latlng.1": "longitude"
|
|
663
|
+
}
|
|
664
|
+
},
|
|
665
|
+
{
|
|
666
|
+
id: "country-output",
|
|
667
|
+
source: "country",
|
|
668
|
+
target: "output",
|
|
669
|
+
mapping: {
|
|
670
|
+
"0.name": "country",
|
|
671
|
+
"0.capital": "capital",
|
|
672
|
+
"0.region": "region",
|
|
673
|
+
"0.population": "population"
|
|
674
|
+
}
|
|
675
|
+
},
|
|
676
|
+
{
|
|
677
|
+
id: "weather-output",
|
|
678
|
+
source: "weather",
|
|
679
|
+
target: "output",
|
|
680
|
+
mapping: {
|
|
681
|
+
"current.temperature_2m": "temperatureC",
|
|
682
|
+
"current.relative_humidity_2m": "humidityPercent",
|
|
683
|
+
"current.wind_speed_10m": "windSpeedKph",
|
|
684
|
+
timezone: "timezone"
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
],
|
|
688
|
+
startNodeId: "input",
|
|
689
|
+
endNodeId: "output"
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
function countryWeatherBrief(ctx) {
|
|
693
|
+
const tools = sharedTools(ctx);
|
|
694
|
+
return {
|
|
695
|
+
name: `${ctx.prefix} Country Weather Brief`,
|
|
696
|
+
description: "Tool-only workflow: country metadata plus current Open-Meteo weather.",
|
|
697
|
+
category: "template",
|
|
698
|
+
tags: ["template", "tool-workflow", "public-api"],
|
|
699
|
+
tools: [
|
|
700
|
+
{ key: "countryLookup", payload: tools.countryLookup },
|
|
701
|
+
{ key: "weatherForecast", payload: tools.weatherForecast }
|
|
702
|
+
],
|
|
703
|
+
buildDefinition: (toolIds) => countryWeatherDefinition(toolIds),
|
|
704
|
+
sampleInput: { country: "Finland" }
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
function agentResearchSummary(ctx) {
|
|
708
|
+
const tools = sharedTools(ctx);
|
|
709
|
+
return {
|
|
710
|
+
name: `${ctx.prefix} Agent Research Summary`,
|
|
711
|
+
description: "Multi-tool workflow with an agent_processor that summarizes country and book-search data.",
|
|
712
|
+
category: "template",
|
|
713
|
+
tags: ["template", "agent-processor", "public-api"],
|
|
714
|
+
tools: [
|
|
715
|
+
{ key: "countryLookup", payload: tools.countryLookup },
|
|
716
|
+
{ key: "openLibrarySearch", payload: tools.openLibrarySearch }
|
|
717
|
+
],
|
|
718
|
+
buildDefinition: (toolIds, buildCtx) => ({
|
|
719
|
+
nodes: [
|
|
720
|
+
{ id: "input", type: "input", position: { x: 0, y: 100 } },
|
|
721
|
+
{ id: "country", type: "tool", toolId: toolIds.countryLookup, position: { x: 240, y: 20 } },
|
|
722
|
+
{ id: "books", type: "tool", toolId: toolIds.openLibrarySearch, position: { x: 240, y: 180 } },
|
|
723
|
+
{
|
|
724
|
+
id: "analyst",
|
|
725
|
+
type: "agent_processor",
|
|
726
|
+
position: { x: 560, y: 100 },
|
|
727
|
+
config: {
|
|
728
|
+
agentId: buildCtx.agentId,
|
|
729
|
+
prompt: "Create a concise research note from the country metadata and book search results. Include practical context and cite only the data available in the input."
|
|
730
|
+
}
|
|
731
|
+
},
|
|
732
|
+
{ id: "output", type: "output", position: { x: 860, y: 100 } }
|
|
733
|
+
],
|
|
734
|
+
edges: [
|
|
735
|
+
{ id: "input-country", source: "input", target: "country", mapping: { country: "country" } },
|
|
736
|
+
{ id: "input-books", source: "input", target: "books", mapping: { query: "query", limit: "limit" } },
|
|
737
|
+
{ id: "country-analyst", source: "country", target: "analyst", mapping: { "0": "countryData" } },
|
|
738
|
+
{ id: "books-analyst", source: "books", target: "analyst", mapping: { docs: "books" } },
|
|
739
|
+
{ id: "analyst-output", source: "analyst", target: "output", mapping: { result: "summary" } }
|
|
740
|
+
],
|
|
741
|
+
startNodeId: "input",
|
|
742
|
+
endNodeId: "output"
|
|
743
|
+
}),
|
|
744
|
+
sampleInput: { country: "Kenya", query: "Kenyan history", limit: 5 }
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
function multiAgentFieldReport(ctx) {
|
|
748
|
+
const tools = sharedTools(ctx);
|
|
749
|
+
return {
|
|
750
|
+
name: `${ctx.prefix} Multi-Agent Field Report`,
|
|
751
|
+
description: "Multi-agent, multi-tool workflow with a researcher agent and reviewer agent.",
|
|
752
|
+
category: "template",
|
|
753
|
+
tags: ["template", "multi-agent", "multi-tool", "public-api"],
|
|
754
|
+
tools: [
|
|
755
|
+
{ key: "countryLookup", payload: tools.countryLookup },
|
|
756
|
+
{ key: "weatherForecast", payload: tools.weatherForecast },
|
|
757
|
+
{ key: "exchangeRate", payload: tools.exchangeRate }
|
|
758
|
+
],
|
|
759
|
+
buildDefinition: (toolIds, buildCtx) => ({
|
|
760
|
+
nodes: [
|
|
761
|
+
{ id: "input", type: "input", position: { x: 0, y: 120 } },
|
|
762
|
+
{ id: "country", type: "tool", toolId: toolIds.countryLookup, position: { x: 230, y: 20 } },
|
|
763
|
+
{ id: "weather", type: "tool", toolId: toolIds.weatherForecast, position: { x: 500, y: 20 } },
|
|
764
|
+
{ id: "exchange-rate", type: "tool", toolId: toolIds.exchangeRate, position: { x: 230, y: 240 } },
|
|
765
|
+
{
|
|
766
|
+
id: "researcher",
|
|
767
|
+
type: "agent_processor",
|
|
768
|
+
position: { x: 760, y: 80 },
|
|
769
|
+
config: {
|
|
770
|
+
agentId: buildCtx.agentId,
|
|
771
|
+
prompt: "Draft a compact field report from the country, weather, and exchange-rate data. Use clear sections and do not invent facts."
|
|
772
|
+
}
|
|
773
|
+
},
|
|
774
|
+
{
|
|
775
|
+
id: "reviewer",
|
|
776
|
+
type: "agent_processor",
|
|
777
|
+
position: { x: 1060, y: 80 },
|
|
778
|
+
config: {
|
|
779
|
+
agentId: buildCtx.reviewerAgentId ?? buildCtx.agentId,
|
|
780
|
+
prompt: "Review the draft field report for clarity, unsupported claims, and operational usefulness. Return the improved final report."
|
|
781
|
+
}
|
|
782
|
+
},
|
|
783
|
+
{ id: "output", type: "output", position: { x: 1360, y: 120 } }
|
|
784
|
+
],
|
|
785
|
+
edges: [
|
|
786
|
+
{ id: "input-country", source: "input", target: "country", mapping: { country: "country" } },
|
|
787
|
+
{ id: "country-weather", source: "country", target: "weather", mapping: { "0.latlng.0": "latitude", "0.latlng.1": "longitude" } },
|
|
788
|
+
{ id: "country-exchange-rate", source: "country", target: "exchange-rate", mapping: { "0.currencies.0.code": "to" } },
|
|
789
|
+
{ id: "country-researcher", source: "country", target: "researcher", mapping: { "0": "countryData" } },
|
|
790
|
+
{ id: "weather-researcher", source: "weather", target: "researcher", mapping: { current: "weather" } },
|
|
791
|
+
{ id: "exchange-rate-researcher", source: "exchange-rate", target: "researcher", mapping: { "0": "exchangeRate" } },
|
|
792
|
+
{ id: "researcher-reviewer", source: "researcher", target: "reviewer", mapping: { result: "draftReport" } },
|
|
793
|
+
{ id: "reviewer-output", source: "reviewer", target: "output", mapping: { result: "finalReport" } }
|
|
794
|
+
],
|
|
795
|
+
startNodeId: "input",
|
|
796
|
+
endNodeId: "output"
|
|
797
|
+
}),
|
|
798
|
+
sampleInput: { country: "Japan" }
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
function workflowInvocationSmoke(ctx) {
|
|
802
|
+
return {
|
|
803
|
+
name: `${ctx.prefix} Workflow Invocation Smoke`,
|
|
804
|
+
description: "Parent workflow template that expects a child workflowId and invokes it as a workflow node.",
|
|
805
|
+
category: "template",
|
|
806
|
+
tags: ["template", "workflow-invocation"],
|
|
807
|
+
tools: [],
|
|
808
|
+
buildDefinition: (_toolIds, buildCtx) => ({
|
|
809
|
+
nodes: [
|
|
810
|
+
{ id: "input", type: "input", position: { x: 0, y: 80 } },
|
|
811
|
+
{
|
|
812
|
+
id: "child-workflow",
|
|
813
|
+
type: "workflow",
|
|
814
|
+
position: { x: 280, y: 80 },
|
|
815
|
+
config: {
|
|
816
|
+
workflowId: buildCtx.childWorkflowId,
|
|
817
|
+
timeoutMs: 9e4
|
|
818
|
+
}
|
|
819
|
+
},
|
|
820
|
+
{ id: "output", type: "output", position: { x: 620, y: 80 } }
|
|
821
|
+
],
|
|
822
|
+
edges: [
|
|
823
|
+
{ id: "input-child", source: "input", target: "child-workflow" },
|
|
824
|
+
{ id: "child-output", source: "child-workflow", target: "output", mapping: { result: "childResult", executionId: "childExecutionId" } }
|
|
825
|
+
],
|
|
826
|
+
startNodeId: "input",
|
|
827
|
+
endNodeId: "output"
|
|
828
|
+
}),
|
|
829
|
+
sampleInput: { country: "Finland" }
|
|
830
|
+
};
|
|
831
|
+
}
|
|
469
832
|
// Annotate the CommonJS export names for ESM import in node:
|
|
470
833
|
0 && (module.exports = {
|
|
471
834
|
CommonsClient,
|
|
472
|
-
CommonsError
|
|
835
|
+
CommonsError,
|
|
836
|
+
buildWorkflowTemplate,
|
|
837
|
+
listWorkflowTemplates
|
|
473
838
|
});
|
|
474
839
|
//# sourceMappingURL=index.cjs.map
|