@mcoda/agent-setup 0.1.66

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 (52) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/LICENSE +21 -0
  3. package/README.md +14 -0
  4. package/dist/client.d.ts +20 -0
  5. package/dist/client.d.ts.map +1 -0
  6. package/dist/client.js +83 -0
  7. package/dist/defaultStages.d.ts +18 -0
  8. package/dist/defaultStages.d.ts.map +1 -0
  9. package/dist/defaultStages.js +56 -0
  10. package/dist/headless/catalog.d.ts +24 -0
  11. package/dist/headless/catalog.d.ts.map +1 -0
  12. package/dist/headless/catalog.js +231 -0
  13. package/dist/headless/index.d.ts +4 -0
  14. package/dist/headless/index.d.ts.map +1 -0
  15. package/dist/headless/index.js +2 -0
  16. package/dist/headless/normalization.d.ts +12 -0
  17. package/dist/headless/normalization.d.ts.map +1 -0
  18. package/dist/headless/normalization.js +105 -0
  19. package/dist/index.d.ts +5 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +4 -0
  22. package/dist/react/index.d.ts +68 -0
  23. package/dist/react/index.d.ts.map +1 -0
  24. package/dist/react/index.js +295 -0
  25. package/dist/server/cliRuntime.d.ts +12 -0
  26. package/dist/server/cliRuntime.d.ts.map +1 -0
  27. package/dist/server/cliRuntime.js +130 -0
  28. package/dist/server/httpHandlers.d.ts +13 -0
  29. package/dist/server/httpHandlers.d.ts.map +1 -0
  30. package/dist/server/httpHandlers.js +130 -0
  31. package/dist/server/inMemoryRuntime.d.ts +8 -0
  32. package/dist/server/inMemoryRuntime.d.ts.map +1 -0
  33. package/dist/server/inMemoryRuntime.js +89 -0
  34. package/dist/server/index.d.ts +8 -0
  35. package/dist/server/index.d.ts.map +1 -0
  36. package/dist/server/index.js +6 -0
  37. package/dist/server/programmaticRuntime.d.ts +15 -0
  38. package/dist/server/programmaticRuntime.d.ts.map +1 -0
  39. package/dist/server/programmaticRuntime.js +136 -0
  40. package/dist/server/service.d.ts +3 -0
  41. package/dist/server/service.d.ts.map +1 -0
  42. package/dist/server/service.js +143 -0
  43. package/dist/server/settingsStore.d.ts +3 -0
  44. package/dist/server/settingsStore.d.ts.map +1 -0
  45. package/dist/server/settingsStore.js +34 -0
  46. package/dist/types.d.ts +207 -0
  47. package/dist/types.d.ts.map +1 -0
  48. package/dist/types.js +1 -0
  49. package/examples/express-server/README.md +34 -0
  50. package/examples/nextjs-mcoda-agent-setup/README.md +63 -0
  51. package/examples/vite-react-mcoda-agent-setup/README.md +26 -0
  52. package/package.json +84 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inMemoryRuntime.d.ts","sourceRoot":"","sources":["../../src/server/inMemoryRuntime.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,sBAAsB,EAItB,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,gCAAgC;IAC/C,WAAW,CAAC,EAAE,sBAAsB,EAAE,CAAC;IACvC,gBAAgB,CAAC,EAAE,sBAAsB,EAAE,CAAC;IAC5C,WAAW,CAAC,EAAE,sBAAsB,EAAE,CAAC;CACxC;AAED,wBAAgB,iCAAiC,CAC/C,KAAK,GAAE,gCAAqC,GAC3C,mBAAmB,CAqGrB"}
@@ -0,0 +1,89 @@
1
+ import { syncedCloudSlug, syncedSelfHostedSlug, } from "../headless/catalog.js";
2
+ export function createInMemoryMcodaRuntimeAdapter(input = {}) {
3
+ let cloudAgents = input.cloudAgents?.map((agent) => ({ ...agent })) ?? [];
4
+ let selfHostedAgents = input.selfHostedAgents?.map((agent) => ({ ...agent })) ?? [];
5
+ let localAgents = input.localAgents?.map((agent) => ({ ...agent })) ?? [];
6
+ let configuredApiKey = false;
7
+ const syncRemote = (remoteAgents, slugFor, managedKind) => {
8
+ const remoteLocalSlugs = new Set(remoteAgents.map(slugFor));
9
+ localAgents = localAgents.filter((agent) => {
10
+ if (agent.managedKind !== managedKind)
11
+ return true;
12
+ return remoteLocalSlugs.has(agent.slug);
13
+ });
14
+ for (const remote of remoteAgents) {
15
+ const localSlug = slugFor(remote);
16
+ const next = {
17
+ ...remote,
18
+ slug: localSlug,
19
+ source: "local_registry",
20
+ synced: true,
21
+ managedKind,
22
+ remoteSlug: remote.remoteSlug ?? remote.slug,
23
+ };
24
+ const index = localAgents.findIndex((agent) => agent.slug === localSlug);
25
+ if (index >= 0) {
26
+ localAgents[index] = next;
27
+ }
28
+ else {
29
+ localAgents.push(next);
30
+ }
31
+ }
32
+ return localAgents.filter((agent) => agent.managedKind === managedKind);
33
+ };
34
+ const filterProvider = (agents, options) => options?.provider
35
+ ? agents.filter((agent) => agent.provider === options.provider)
36
+ : agents;
37
+ return {
38
+ runtime: {
39
+ mode: "programmatic",
40
+ requiresMcodaCli: false,
41
+ },
42
+ async configureMswarmApiKey(input) {
43
+ if (!input.apiKey.trim()) {
44
+ throw new Error("mswarm api key is required");
45
+ }
46
+ configuredApiKey = true;
47
+ },
48
+ async listCloudAgents(options) {
49
+ return filterProvider(cloudAgents, options).map((agent) => ({ ...agent }));
50
+ },
51
+ async syncCloudAgents(options) {
52
+ if (!configuredApiKey) {
53
+ throw new Error("mswarm api key is required");
54
+ }
55
+ return syncRemote(filterProvider(cloudAgents, options), syncedCloudSlug, "cloud");
56
+ },
57
+ async listSelfHostedAgents(options) {
58
+ return filterProvider(selfHostedAgents, options).map((agent) => ({
59
+ ...agent,
60
+ }));
61
+ },
62
+ async syncSelfHostedAgents(options) {
63
+ if (!configuredApiKey) {
64
+ throw new Error("mswarm api key is required");
65
+ }
66
+ return syncRemote(filterProvider(selfHostedAgents, options), syncedSelfHostedSlug, "self_hosted");
67
+ },
68
+ async listLocalAgents(options) {
69
+ return filterProvider(localAgents, options).map((agent) => ({ ...agent }));
70
+ },
71
+ async testAgent(input) {
72
+ const agent = localAgents.find((candidate) => candidate.slug === input.slug);
73
+ if (!agent) {
74
+ return {
75
+ slug: input.slug,
76
+ ok: false,
77
+ error: "agent not found",
78
+ };
79
+ }
80
+ return {
81
+ slug: input.slug,
82
+ ok: true,
83
+ output: `ok:${input.prompt ?? ""}`,
84
+ model: agent.defaultModel ?? agent.model ?? undefined,
85
+ adapter: agent.adapter ?? undefined,
86
+ };
87
+ },
88
+ };
89
+ }
@@ -0,0 +1,8 @@
1
+ export * from "./settingsStore.js";
2
+ export * from "./inMemoryRuntime.js";
3
+ export * from "./programmaticRuntime.js";
4
+ export * from "./cliRuntime.js";
5
+ export * from "./service.js";
6
+ export * from "./httpHandlers.js";
7
+ export type * from "../types.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,mBAAmB,aAAa,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from "./settingsStore.js";
2
+ export * from "./inMemoryRuntime.js";
3
+ export * from "./programmaticRuntime.js";
4
+ export * from "./cliRuntime.js";
5
+ export * from "./service.js";
6
+ export * from "./httpHandlers.js";
@@ -0,0 +1,15 @@
1
+ import { MswarmConfigStore } from "@mcoda/core";
2
+ import type { McodaRuntimeAdapter } from "../types.js";
3
+ export interface ProgrammaticMcodaRuntimeAdapterInput {
4
+ mswarm?: {
5
+ baseUrl?: string;
6
+ openAiBaseUrl?: string;
7
+ apiKey?: string;
8
+ timeoutMs?: number;
9
+ agentSlugPrefix?: string;
10
+ selfHostedAgentSlugPrefix?: string;
11
+ };
12
+ store?: MswarmConfigStore;
13
+ }
14
+ export declare function createProgrammaticMcodaRuntimeAdapter(input?: ProgrammaticMcodaRuntimeAdapterInput): McodaRuntimeAdapter;
15
+ //# sourceMappingURL=programmaticRuntime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"programmaticRuntime.d.ts","sourceRoot":"","sources":["../../src/server/programmaticRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,iBAAiB,EAIlB,MAAM,aAAa,CAAC;AAGrB,OAAO,KAAK,EAIV,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,oCAAoC;IACnD,MAAM,CAAC,EAAE;QACP,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,yBAAyB,CAAC,EAAE,MAAM,CAAC;KACpC,CAAC;IACF,KAAK,CAAC,EAAE,iBAAiB,CAAC;CAC3B;AAED,wBAAgB,qCAAqC,CACnD,KAAK,GAAE,oCAAyC,GAC/C,mBAAmB,CAqHrB"}
@@ -0,0 +1,136 @@
1
+ import { AgentsApi, MswarmApi, MswarmConfigStore, } from "@mcoda/core";
2
+ import { normalizeAgentCatalogEntry } from "../headless/normalization.js";
3
+ import { isCloudAgent, isSelfHostedAgent } from "../headless/catalog.js";
4
+ export function createProgrammaticMcodaRuntimeAdapter(input = {}) {
5
+ const createMswarmApi = async () => {
6
+ if (!input.store)
7
+ return MswarmApi.create(input.mswarm ?? {});
8
+ const stored = await input.store.readState();
9
+ return MswarmApi.create({
10
+ baseUrl: input.mswarm?.baseUrl ?? stored.baseUrl,
11
+ openAiBaseUrl: input.mswarm?.openAiBaseUrl,
12
+ apiKey: input.mswarm?.apiKey ?? stored.apiKey,
13
+ timeoutMs: input.mswarm?.timeoutMs ?? stored.timeoutMs,
14
+ agentSlugPrefix: input.mswarm?.agentSlugPrefix ?? stored.agentSlugPrefix,
15
+ selfHostedAgentSlugPrefix: input.mswarm?.selfHostedAgentSlugPrefix,
16
+ });
17
+ };
18
+ const withMswarmApi = async (fn) => {
19
+ const api = await createMswarmApi();
20
+ try {
21
+ return await fn(api);
22
+ }
23
+ finally {
24
+ await api.close();
25
+ }
26
+ };
27
+ const withAgentsApi = async (fn) => {
28
+ const api = await AgentsApi.create();
29
+ try {
30
+ return await fn(api);
31
+ }
32
+ finally {
33
+ await api.close();
34
+ }
35
+ };
36
+ const listLocal = async (options) => withAgentsApi(async (api) => {
37
+ const agents = await api.listAgents({
38
+ refreshHealth: options?.refreshHealth,
39
+ });
40
+ return agents.map(normalizeLocalAgent);
41
+ });
42
+ return {
43
+ runtime: {
44
+ mode: "programmatic",
45
+ requiresMcodaCli: false,
46
+ },
47
+ async configureMswarmApiKey(request) {
48
+ const store = input.store ?? new MswarmConfigStore();
49
+ await store.saveApiKey(request.apiKey);
50
+ await MswarmApi.refreshManagedAgentAuth(request.apiKey);
51
+ },
52
+ async listCloudAgents(options) {
53
+ return withMswarmApi(async (api) => {
54
+ const agents = await api.listCloudAgents(toCloudOptions(options));
55
+ return agents.map((agent) => normalizeAgentCatalogEntry(agent, {
56
+ source: "cloud_catalog",
57
+ synced: false,
58
+ managedKind: "cloud",
59
+ }));
60
+ });
61
+ },
62
+ async syncCloudAgents(options) {
63
+ await withMswarmApi((api) => api.syncCloudAgents(toCloudSyncOptions(options)));
64
+ return (await listLocal(options)).filter(isCloudAgent);
65
+ },
66
+ async listSelfHostedAgents(options) {
67
+ return withMswarmApi(async (api) => {
68
+ const agents = await api.listSelfHostedAgents(toSelfHostedOptions(options));
69
+ return agents.map((agent) => normalizeAgentCatalogEntry(agent, {
70
+ source: "self_hosted_catalog",
71
+ synced: false,
72
+ managedKind: "self_hosted",
73
+ }));
74
+ });
75
+ },
76
+ async syncSelfHostedAgents(options) {
77
+ await withMswarmApi((api) => api.syncSelfHostedAgents(toSelfHostedSyncOptions(options)));
78
+ return (await listLocal(options)).filter(isSelfHostedAgent);
79
+ },
80
+ listLocalAgents: listLocal,
81
+ async testAgent(input) {
82
+ try {
83
+ const result = await withAgentsApi((api) => api.runAgent(input.slug, [input.prompt ?? "Hello from mcoda agent setup test."], {
84
+ command: "mcoda-agent-setup-test",
85
+ timeoutMs: input.timeoutMs,
86
+ }));
87
+ const first = result.responses[0];
88
+ return {
89
+ slug: result.agent.slug,
90
+ ok: true,
91
+ output: first?.output,
92
+ model: first?.model,
93
+ adapter: first?.adapter,
94
+ metadata: first?.metadata,
95
+ };
96
+ }
97
+ catch (error) {
98
+ return {
99
+ slug: input.slug,
100
+ ok: false,
101
+ error: error instanceof Error ? error.message : String(error),
102
+ };
103
+ }
104
+ },
105
+ };
106
+ }
107
+ function normalizeLocalAgent(agent) {
108
+ return normalizeAgentCatalogEntry(agent, {
109
+ source: "local_registry",
110
+ synced: true,
111
+ });
112
+ }
113
+ function toCloudOptions(options) {
114
+ return {
115
+ provider: options?.provider,
116
+ };
117
+ }
118
+ function toCloudSyncOptions(options) {
119
+ return {
120
+ provider: options?.provider,
121
+ pruneMissing: options?.pruneMissing ?? true,
122
+ };
123
+ }
124
+ function toSelfHostedOptions(options) {
125
+ return {
126
+ provider: options?.provider,
127
+ includeUnreachable: options?.includeUnreachable ?? true,
128
+ };
129
+ }
130
+ function toSelfHostedSyncOptions(options) {
131
+ return {
132
+ provider: options?.provider,
133
+ includeUnreachable: options?.includeUnreachable ?? true,
134
+ pruneMissing: options?.pruneMissing ?? true,
135
+ };
136
+ }
@@ -0,0 +1,3 @@
1
+ import type { McodaAgentSetupServerOptions, McodaAgentSetupService } from "../types.js";
2
+ export declare function createMcodaAgentSetupService(options: McodaAgentSetupServerOptions): McodaAgentSetupService;
3
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../src/server/service.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAGV,4BAA4B,EAC5B,sBAAsB,EAGvB,MAAM,aAAa,CAAC;AAErB,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,4BAA4B,GACpC,sBAAsB,CAqJxB"}
@@ -0,0 +1,143 @@
1
+ import { defaultMcodaStageDefinitions } from "../defaultStages.js";
2
+ import { buildCloudAgentOptions, buildSelfHostedServerOptions, } from "../headless/catalog.js";
3
+ import { createProgrammaticMcodaRuntimeAdapter } from "./programmaticRuntime.js";
4
+ export function createMcodaAgentSetupService(options) {
5
+ const runtime = options.mcoda ?? createProgrammaticMcodaRuntimeAdapter();
6
+ const stages = options.defaultStages ?? defaultMcodaStageDefinitions;
7
+ const provider = options.provider ?? "mcoda_mswarm";
8
+ const authorize = async (request) => {
9
+ await options.authorize?.(request);
10
+ };
11
+ const capture = async (errors, key, fn, fallback) => {
12
+ try {
13
+ return await fn();
14
+ }
15
+ catch (error) {
16
+ const message = error instanceof Error ? error.message : String(error);
17
+ errors[key] = message;
18
+ options.logger?.warn?.(`mcoda agent setup ${key} failed`, {
19
+ error: message,
20
+ });
21
+ return fallback;
22
+ }
23
+ };
24
+ const buildSnapshot = async (extraErrors = {}) => {
25
+ const settings = await options.settingsStore.load();
26
+ const errors = { ...extraErrors };
27
+ const [localAgents, cloudCatalogAgents, selfHostedCatalogAgents] = await Promise.all([
28
+ capture(errors, "local_agents", () => runtime.listLocalAgents({ refreshHealth: true }), []),
29
+ capture(errors, "cloud_agents", () => runtime.listCloudAgents(), []),
30
+ capture(errors, "self_hosted_agents", () => runtime.listSelfHostedAgents({ includeUnreachable: true }), []),
31
+ ]);
32
+ const cloudAgents = buildCloudAgentOptions(localAgents, cloudCatalogAgents);
33
+ const selfHostedServers = buildSelfHostedServerOptions(localAgents, selfHostedCatalogAgents);
34
+ const catalog = {
35
+ localAgents,
36
+ cloudAgents,
37
+ selfHostedAgents: selfHostedCatalogAgents,
38
+ selfHostedServers,
39
+ errors,
40
+ generatedAt: new Date().toISOString(),
41
+ };
42
+ return {
43
+ provider,
44
+ runtime: runtime.runtime,
45
+ mswarmApiKeyConfigured: settings.mswarmApiKeyConfigured,
46
+ mswarmApiKeyLast4: settings.mswarmApiKeyLast4,
47
+ mswarmConfiguredAt: settings.mswarmConfiguredAt,
48
+ stages,
49
+ assignments: {
50
+ ...initialAssignments(stages),
51
+ ...settings.assignments,
52
+ },
53
+ catalog,
54
+ updatedAt: settings.updatedAt,
55
+ fetchedAt: new Date().toISOString(),
56
+ };
57
+ };
58
+ return {
59
+ async fetchSnapshot(request) {
60
+ await authorize(request);
61
+ return buildSnapshot();
62
+ },
63
+ async configureMswarmApiKey(input, request) {
64
+ await authorize(request);
65
+ const apiKey = input.apiKey.trim();
66
+ if (!apiKey) {
67
+ throw new Error("mswarm api key is required");
68
+ }
69
+ await runtime.configureMswarmApiKey(input);
70
+ const configuredAt = new Date().toISOString();
71
+ await options.settingsStore.saveMswarmKeyMetadata({
72
+ configured: true,
73
+ last4: apiKey.slice(-4),
74
+ configuredAt,
75
+ actor: input.actor,
76
+ reasonCode: input.reasonCode,
77
+ });
78
+ const errors = await syncCatalogs();
79
+ return buildSnapshot(errors);
80
+ },
81
+ async syncAgents(input = {}, request) {
82
+ await authorize(request);
83
+ const errors = await syncCatalogs();
84
+ options.logger?.info?.("mcoda agent setup sync completed", {
85
+ reasonCode: input.reasonCode,
86
+ errors,
87
+ });
88
+ return buildSnapshot(errors);
89
+ },
90
+ async updateAssignments(input, request) {
91
+ await authorize(request);
92
+ const localAgents = await runtime.listLocalAgents({ refreshHealth: true });
93
+ const nextAssignments = {
94
+ ...initialAssignments(stages),
95
+ ...input.assignments,
96
+ };
97
+ validateAssignments(nextAssignments, stages, localAgents);
98
+ await options.settingsStore.saveAssignments({
99
+ assignments: nextAssignments,
100
+ actor: input.actor,
101
+ reasonCode: input.reasonCode,
102
+ });
103
+ return buildSnapshot();
104
+ },
105
+ async testAgent(input, request) {
106
+ await authorize(request);
107
+ if (!runtime.testAgent) {
108
+ throw new Error("The configured mcoda runtime adapter does not support agent tests");
109
+ }
110
+ return runtime.testAgent(input);
111
+ },
112
+ };
113
+ async function syncCatalogs() {
114
+ const errors = {};
115
+ await capture(errors, "cloud_agent_sync", () => runtime.syncCloudAgents({ pruneMissing: true }), []);
116
+ await capture(errors, "self_hosted_agent_sync", () => runtime.syncSelfHostedAgents({
117
+ pruneMissing: true,
118
+ includeUnreachable: true,
119
+ }), []);
120
+ return errors;
121
+ }
122
+ }
123
+ function initialAssignments(stages) {
124
+ return Object.fromEntries(stages.map((stage) => [stage.stageKey, stage.defaultAgentSlug ?? null]));
125
+ }
126
+ function validateAssignments(assignments, stages, localAgents) {
127
+ const stageByKey = new Map(stages.map((stage) => [stage.stageKey, stage]));
128
+ const validSlugs = new Set(localAgents.map((agent) => agent.slug));
129
+ for (const [stageKey, slug] of Object.entries(assignments)) {
130
+ const stage = stageByKey.get(stageKey);
131
+ if (!stage) {
132
+ throw new Error(`Unknown mcoda stage: ${stageKey}`);
133
+ }
134
+ if (!slug) {
135
+ if (stage.nullable || stage.fallbackStageKey)
136
+ continue;
137
+ throw new Error(`Stage ${stageKey} requires an agent assignment`);
138
+ }
139
+ if (!validSlugs.has(slug)) {
140
+ throw new Error(`Selected agent ${slug} is not present in the local registry`);
141
+ }
142
+ }
143
+ }
@@ -0,0 +1,3 @@
1
+ import type { McodaAgentSettingsSnapshot, McodaAgentSettingsStore } from "../types.js";
2
+ export declare function createInMemoryMcodaAgentSettingsStore(initial?: Partial<McodaAgentSettingsSnapshot>): McodaAgentSettingsStore;
3
+ //# sourceMappingURL=settingsStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settingsStore.d.ts","sourceRoot":"","sources":["../../src/server/settingsStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,uBAAuB,EACxB,MAAM,aAAa,CAAC;AAErB,wBAAgB,qCAAqC,CACnD,OAAO,GAAE,OAAO,CAAC,0BAA0B,CAAM,GAChD,uBAAuB,CAkCzB"}
@@ -0,0 +1,34 @@
1
+ export function createInMemoryMcodaAgentSettingsStore(initial = {}) {
2
+ let state = {
3
+ assignments: { ...(initial.assignments ?? {}) },
4
+ mswarmApiKeyConfigured: initial.mswarmApiKeyConfigured ?? false,
5
+ mswarmApiKeyLast4: initial.mswarmApiKeyLast4 ?? null,
6
+ mswarmConfiguredAt: initial.mswarmConfiguredAt ?? null,
7
+ updatedAt: initial.updatedAt ?? null,
8
+ };
9
+ return {
10
+ async load() {
11
+ return {
12
+ ...state,
13
+ assignments: { ...state.assignments },
14
+ };
15
+ },
16
+ async saveMswarmKeyMetadata(input) {
17
+ const updatedAt = new Date().toISOString();
18
+ state = {
19
+ ...state,
20
+ mswarmApiKeyConfigured: input.configured,
21
+ mswarmApiKeyLast4: input.last4,
22
+ mswarmConfiguredAt: input.configuredAt,
23
+ updatedAt,
24
+ };
25
+ },
26
+ async saveAssignments(input) {
27
+ state = {
28
+ ...state,
29
+ assignments: { ...input.assignments },
30
+ updatedAt: new Date().toISOString(),
31
+ };
32
+ },
33
+ };
34
+ }
@@ -0,0 +1,207 @@
1
+ export type McodaRuntimeMode = "programmatic" | "cli_fallback" | "custom";
2
+ export interface McodaRuntimeInfo {
3
+ mode: McodaRuntimeMode;
4
+ requiresMcodaCli: boolean;
5
+ }
6
+ export type McodaAgentSource = "local_registry" | "cloud_catalog" | "self_hosted_catalog";
7
+ export type McodaAgentManagedKind = "cloud" | "self_hosted" | null;
8
+ export type McodaPreferredSource = "cloud" | "self_hosted" | "cloud_or_self_hosted" | null;
9
+ export interface McodaStageDefinition {
10
+ stageKey: string;
11
+ displayName: string;
12
+ description?: string;
13
+ defaultAgentSlug?: string | null;
14
+ recommendedUsage?: string | null;
15
+ preferredSource?: McodaPreferredSource;
16
+ fallbackStageKey?: string | null;
17
+ nullable?: boolean;
18
+ }
19
+ export interface McodaAgentCatalogEntry {
20
+ slug: string;
21
+ source: McodaAgentSource;
22
+ synced: boolean;
23
+ remoteSlug: string | null;
24
+ managedKind?: McodaAgentManagedKind;
25
+ nodeId?: string | null;
26
+ serverName?: string | null;
27
+ serverId?: string | null;
28
+ serverLabel?: string | null;
29
+ displayName: string | null;
30
+ provider: string | null;
31
+ adapter: string | null;
32
+ model: string | null;
33
+ defaultModel: string | null;
34
+ healthStatus: string | null;
35
+ supportsTools: boolean | null;
36
+ rating: number | null;
37
+ reasoningRating: number | null;
38
+ maxComplexity: number | null;
39
+ costPerMillion: number | null;
40
+ contextWindow?: number | null;
41
+ maxOutputTokens?: number | null;
42
+ bestUsage?: string | null;
43
+ capabilities?: string[];
44
+ metadata?: Record<string, unknown>;
45
+ }
46
+ export interface McodaSelfHostedServer {
47
+ id: string;
48
+ label: string;
49
+ nodeId?: string | null;
50
+ serverName?: string | null;
51
+ status?: string | null;
52
+ remoteSlugPrefix?: string | null;
53
+ agentCount: number;
54
+ agents: McodaAgentCatalogEntry[];
55
+ }
56
+ export interface McodaAgentCatalog {
57
+ localAgents: McodaAgentCatalogEntry[];
58
+ cloudAgents: McodaAgentCatalogEntry[];
59
+ selfHostedAgents: McodaAgentCatalogEntry[];
60
+ selfHostedServers: McodaSelfHostedServer[];
61
+ errors: Record<string, string>;
62
+ generatedAt: string;
63
+ }
64
+ export interface McodaAgentSetupSnapshot {
65
+ provider: "mcoda_mswarm" | string;
66
+ runtime: McodaRuntimeInfo;
67
+ mswarmApiKeyConfigured: boolean;
68
+ mswarmApiKeyLast4: string | null;
69
+ mswarmConfiguredAt: string | null;
70
+ stages: McodaStageDefinition[];
71
+ assignments: Record<string, string | null>;
72
+ catalog: McodaAgentCatalog;
73
+ updatedAt: string | null;
74
+ fetchedAt: string;
75
+ }
76
+ export interface McodaAgentTestResult {
77
+ slug: string;
78
+ ok: boolean;
79
+ output?: string;
80
+ model?: string;
81
+ adapter?: string;
82
+ metadata?: Record<string, unknown>;
83
+ error?: string;
84
+ }
85
+ export interface McodaAgentSetupClient {
86
+ fetchSnapshot(): Promise<McodaAgentSetupSnapshot>;
87
+ configureMswarmApiKey(input: {
88
+ apiKey: string;
89
+ reasonCode?: string;
90
+ metadata?: Record<string, unknown>;
91
+ }): Promise<McodaAgentSetupSnapshot>;
92
+ syncAgents(input?: {
93
+ reasonCode?: string;
94
+ metadata?: Record<string, unknown>;
95
+ }): Promise<McodaAgentSetupSnapshot>;
96
+ updateAssignments(input: {
97
+ assignments: Record<string, string | null>;
98
+ reasonCode?: string;
99
+ metadata?: Record<string, unknown>;
100
+ }): Promise<McodaAgentSetupSnapshot>;
101
+ testAgent?(input: {
102
+ slug: string;
103
+ prompt?: string;
104
+ timeoutMs?: number;
105
+ }): Promise<McodaAgentTestResult>;
106
+ }
107
+ export interface McodaAgentListInput {
108
+ provider?: string;
109
+ refreshHealth?: boolean;
110
+ includeUnreachable?: boolean;
111
+ }
112
+ export interface McodaAgentSyncInput extends McodaAgentListInput {
113
+ pruneMissing?: boolean;
114
+ }
115
+ export interface McodaRuntimeAdapter {
116
+ runtime: McodaRuntimeInfo;
117
+ configureMswarmApiKey(input: {
118
+ apiKey: string;
119
+ actor?: string;
120
+ reasonCode?: string;
121
+ metadata?: Record<string, unknown>;
122
+ }): Promise<void>;
123
+ listCloudAgents(input?: McodaAgentListInput): Promise<McodaAgentCatalogEntry[]>;
124
+ syncCloudAgents(input?: McodaAgentSyncInput): Promise<McodaAgentCatalogEntry[]>;
125
+ listSelfHostedAgents(input?: McodaAgentListInput): Promise<McodaAgentCatalogEntry[]>;
126
+ syncSelfHostedAgents(input?: McodaAgentSyncInput): Promise<McodaAgentCatalogEntry[]>;
127
+ listLocalAgents(input?: McodaAgentListInput): Promise<McodaAgentCatalogEntry[]>;
128
+ testAgent?(input: {
129
+ slug: string;
130
+ prompt?: string;
131
+ timeoutMs?: number;
132
+ }): Promise<McodaAgentTestResult>;
133
+ }
134
+ export interface McodaAgentSettingsSnapshot {
135
+ assignments: Record<string, string | null>;
136
+ mswarmApiKeyConfigured: boolean;
137
+ mswarmApiKeyLast4: string | null;
138
+ mswarmConfiguredAt: string | null;
139
+ updatedAt: string | null;
140
+ }
141
+ export interface McodaAgentSettingsStore {
142
+ load(): Promise<McodaAgentSettingsSnapshot>;
143
+ saveMswarmKeyMetadata(input: {
144
+ configured: boolean;
145
+ last4: string | null;
146
+ configuredAt: string;
147
+ actor?: string;
148
+ reasonCode?: string;
149
+ }): Promise<void>;
150
+ saveAssignments(input: {
151
+ assignments: Record<string, string | null>;
152
+ actor?: string;
153
+ reasonCode?: string;
154
+ }): Promise<void>;
155
+ }
156
+ export interface McodaSetupLogger {
157
+ info?(message: string, metadata?: Record<string, unknown>): void;
158
+ warn?(message: string, metadata?: Record<string, unknown>): void;
159
+ error?(message: string, metadata?: Record<string, unknown>): void;
160
+ }
161
+ export interface McodaAgentSetupServerOptions {
162
+ settingsStore: McodaAgentSettingsStore;
163
+ authorize?: (request: unknown) => Promise<void> | void;
164
+ mcoda?: McodaRuntimeAdapter;
165
+ logger?: McodaSetupLogger;
166
+ defaultStages?: McodaStageDefinition[];
167
+ operationTimeoutMs?: number;
168
+ provider?: string;
169
+ }
170
+ export interface McodaAgentSetupService {
171
+ fetchSnapshot(request?: unknown): Promise<McodaAgentSetupSnapshot>;
172
+ configureMswarmApiKey(input: {
173
+ apiKey: string;
174
+ actor?: string;
175
+ reasonCode?: string;
176
+ metadata?: Record<string, unknown>;
177
+ }, request?: unknown): Promise<McodaAgentSetupSnapshot>;
178
+ syncAgents(input?: {
179
+ actor?: string;
180
+ reasonCode?: string;
181
+ metadata?: Record<string, unknown>;
182
+ }, request?: unknown): Promise<McodaAgentSetupSnapshot>;
183
+ updateAssignments(input: {
184
+ assignments: Record<string, string | null>;
185
+ actor?: string;
186
+ reasonCode?: string;
187
+ metadata?: Record<string, unknown>;
188
+ }, request?: unknown): Promise<McodaAgentSetupSnapshot>;
189
+ testAgent(input: {
190
+ slug: string;
191
+ prompt?: string;
192
+ timeoutMs?: number;
193
+ }, request?: unknown): Promise<McodaAgentTestResult>;
194
+ }
195
+ export interface McodaAgentSetupHttpRequest {
196
+ method: string;
197
+ path?: string;
198
+ url?: string;
199
+ body?: unknown;
200
+ raw?: unknown;
201
+ }
202
+ export interface McodaAgentSetupHttpResponse {
203
+ status: number;
204
+ headers: Record<string, string>;
205
+ body: unknown;
206
+ }
207
+ //# sourceMappingURL=types.d.ts.map