@agentproto/runtime 0.1.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/LICENSE +21 -0
- package/README.md +88 -0
- package/dist/config.d.ts +144 -0
- package/dist/config.mjs +76 -0
- package/dist/config.mjs.map +1 -0
- package/dist/conversations.d.ts +60 -0
- package/dist/conversations.mjs +146 -0
- package/dist/conversations.mjs.map +1 -0
- package/dist/heartbeat-COGpMrJS.d.ts +120 -0
- package/dist/heartbeat.d.ts +2 -0
- package/dist/heartbeat.mjs +185 -0
- package/dist/heartbeat.mjs.map +1 -0
- package/dist/index.d.ts +546 -0
- package/dist/index.mjs +4350 -0
- package/dist/index.mjs.map +1 -0
- package/dist/mcp-imports.d.ts +117 -0
- package/dist/mcp-imports.mjs +82 -0
- package/dist/mcp-imports.mjs.map +1 -0
- package/dist/resume-strategies.d.ts +66 -0
- package/dist/resume-strategies.mjs +64 -0
- package/dist/resume-strategies.mjs.map +1 -0
- package/dist/workspace-fs.d.ts +26 -0
- package/dist/workspace-fs.mjs +60 -0
- package/dist/workspace-fs.mjs.map +1 -0
- package/dist/workspaces-config.d.ts +81 -0
- package/dist/workspaces-config.mjs +136 -0
- package/dist/workspaces-config.mjs.map +1 -0
- package/package.json +103 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { promises } from 'fs';
|
|
2
|
+
import { homedir } from 'os';
|
|
3
|
+
import { resolve, dirname, isAbsolute } from 'path';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @agentproto/runtime v0.1.0-alpha
|
|
7
|
+
* Long-running gateway: MCP server + HTTP transport + HEARTBEAT autonomy + conversation persistence over a workspace dir.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var WORKSPACES_CONFIG_VERSION = 1;
|
|
11
|
+
var DEFAULT_CONFIG_DIR = () => resolve(homedir(), ".agentproto");
|
|
12
|
+
var DEFAULT_CONFIG_PATH = () => resolve(DEFAULT_CONFIG_DIR(), "workspaces.json");
|
|
13
|
+
function sanitizeSlug(input) {
|
|
14
|
+
const trimmed = input.trim().toLowerCase();
|
|
15
|
+
const cleaned = trimmed.replace(/[^a-z0-9_-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 64);
|
|
16
|
+
return cleaned || "workspace";
|
|
17
|
+
}
|
|
18
|
+
async function loadWorkspacesConfig(path = DEFAULT_CONFIG_PATH()) {
|
|
19
|
+
let raw;
|
|
20
|
+
try {
|
|
21
|
+
raw = await promises.readFile(path, "utf8");
|
|
22
|
+
} catch (err) {
|
|
23
|
+
if (err.code === "ENOENT") {
|
|
24
|
+
return { version: WORKSPACES_CONFIG_VERSION, workspaces: [] };
|
|
25
|
+
}
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
let parsed;
|
|
29
|
+
try {
|
|
30
|
+
parsed = JSON.parse(raw);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`agentproto: ${path} is not valid JSON (${err instanceof Error ? err.message : String(err)}). Delete the file or fix it manually.`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
return normalizeConfig(parsed);
|
|
37
|
+
}
|
|
38
|
+
async function saveWorkspacesConfig(config, path = DEFAULT_CONFIG_PATH()) {
|
|
39
|
+
const normalized = normalizeConfig(config);
|
|
40
|
+
await promises.mkdir(dirname(path), { recursive: true });
|
|
41
|
+
const tmp = `${path}.tmp.${process.pid}`;
|
|
42
|
+
await promises.writeFile(tmp, JSON.stringify(normalized, null, 2) + "\n", "utf8");
|
|
43
|
+
await promises.rename(tmp, path);
|
|
44
|
+
}
|
|
45
|
+
function addWorkspace(config, input) {
|
|
46
|
+
if (!isAbsolute(input.path)) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`addWorkspace: path must be absolute, got "${input.path}".`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
const slug = sanitizeSlug(input.slug);
|
|
52
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
53
|
+
const existingIdx = config.workspaces.findIndex((w) => w.slug === slug);
|
|
54
|
+
const next = existingIdx >= 0 ? {
|
|
55
|
+
...config.workspaces[existingIdx],
|
|
56
|
+
path: input.path,
|
|
57
|
+
...input.label !== void 0 ? { label: input.label } : {},
|
|
58
|
+
updatedAt: now
|
|
59
|
+
} : {
|
|
60
|
+
slug,
|
|
61
|
+
path: input.path,
|
|
62
|
+
...input.label ? { label: input.label } : {},
|
|
63
|
+
addedAt: now,
|
|
64
|
+
updatedAt: now
|
|
65
|
+
};
|
|
66
|
+
const workspaces = [...config.workspaces];
|
|
67
|
+
if (existingIdx >= 0) workspaces[existingIdx] = next;
|
|
68
|
+
else workspaces.push(next);
|
|
69
|
+
const active = config.active ?? slug;
|
|
70
|
+
return { ...config, workspaces, active };
|
|
71
|
+
}
|
|
72
|
+
function removeWorkspace(config, slug) {
|
|
73
|
+
const sanitised = sanitizeSlug(slug);
|
|
74
|
+
const workspaces = config.workspaces.filter((w) => w.slug !== sanitised);
|
|
75
|
+
let active = config.active;
|
|
76
|
+
if (active === sanitised) {
|
|
77
|
+
active = workspaces[0]?.slug;
|
|
78
|
+
}
|
|
79
|
+
const next = { ...config, workspaces };
|
|
80
|
+
if (active !== void 0) next.active = active;
|
|
81
|
+
else delete next.active;
|
|
82
|
+
return next;
|
|
83
|
+
}
|
|
84
|
+
function setActiveWorkspace(config, slug) {
|
|
85
|
+
const sanitised = sanitizeSlug(slug);
|
|
86
|
+
if (!config.workspaces.some((w) => w.slug === sanitised)) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
`setActiveWorkspace: no workspace registered with slug "${sanitised}". Run \`agentproto workspace add <path> --slug ${sanitised}\` first.`
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
return { ...config, active: sanitised };
|
|
92
|
+
}
|
|
93
|
+
function findWorkspace(config, slug) {
|
|
94
|
+
return config.workspaces.find((w) => w.slug === sanitizeSlug(slug));
|
|
95
|
+
}
|
|
96
|
+
function getActiveWorkspace(config) {
|
|
97
|
+
if (!config.active) return config.workspaces[0];
|
|
98
|
+
return findWorkspace(config, config.active) ?? config.workspaces[0];
|
|
99
|
+
}
|
|
100
|
+
function normalizeConfig(parsed) {
|
|
101
|
+
if (!parsed || typeof parsed !== "object") {
|
|
102
|
+
return { version: WORKSPACES_CONFIG_VERSION, workspaces: [] };
|
|
103
|
+
}
|
|
104
|
+
const obj = parsed;
|
|
105
|
+
const workspaces = [];
|
|
106
|
+
if (Array.isArray(obj.workspaces)) {
|
|
107
|
+
for (const entry of obj.workspaces) {
|
|
108
|
+
if (!entry || typeof entry !== "object") continue;
|
|
109
|
+
const e = entry;
|
|
110
|
+
const slug = typeof e.slug === "string" ? sanitizeSlug(e.slug) : "";
|
|
111
|
+
const path = typeof e.path === "string" ? e.path : "";
|
|
112
|
+
if (!slug || !path) continue;
|
|
113
|
+
const addedAt = typeof e.addedAt === "string" ? e.addedAt : (/* @__PURE__ */ new Date()).toISOString();
|
|
114
|
+
const updatedAt = typeof e.updatedAt === "string" ? e.updatedAt : addedAt;
|
|
115
|
+
const we = { slug, path, addedAt, updatedAt };
|
|
116
|
+
if (typeof e.label === "string" && e.label.trim()) {
|
|
117
|
+
we.label = e.label.trim();
|
|
118
|
+
}
|
|
119
|
+
workspaces.push(we);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const dedup = /* @__PURE__ */ new Map();
|
|
123
|
+
for (const w of workspaces) dedup.set(w.slug, w);
|
|
124
|
+
const finalList = Array.from(dedup.values());
|
|
125
|
+
const active = typeof obj.active === "string" && finalList.some((w) => w.slug === obj.active) ? obj.active : finalList[0]?.slug;
|
|
126
|
+
const out = {
|
|
127
|
+
version: WORKSPACES_CONFIG_VERSION,
|
|
128
|
+
workspaces: finalList
|
|
129
|
+
};
|
|
130
|
+
if (active !== void 0) out.active = active;
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export { DEFAULT_CONFIG_DIR, DEFAULT_CONFIG_PATH, WORKSPACES_CONFIG_VERSION, addWorkspace, findWorkspace, getActiveWorkspace, loadWorkspacesConfig, removeWorkspace, sanitizeSlug, saveWorkspacesConfig, setActiveWorkspace };
|
|
135
|
+
//# sourceMappingURL=workspaces-config.mjs.map
|
|
136
|
+
//# sourceMappingURL=workspaces-config.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/workspaces-config.ts"],"names":["fs"],"mappings":";;;;;;;;;AA0BO,IAAM,yBAAA,GAA4B;AA8BlC,IAAM,kBAAA,GAAqB,MAChC,OAAA,CAAQ,OAAA,IAAW,aAAa;AAC3B,IAAM,mBAAA,GAAsB,MACjC,OAAA,CAAQ,kBAAA,IAAsB,iBAAiB;AAK1C,SAAS,aAAa,KAAA,EAAuB;AAClD,EAAA,MAAM,OAAA,GAAU,KAAA,CAAM,IAAA,EAAK,CAAE,WAAA,EAAY;AACzC,EAAA,MAAM,OAAA,GAAU,OAAA,CACb,OAAA,CAAQ,eAAA,EAAiB,GAAG,CAAA,CAC5B,OAAA,CAAQ,UAAA,EAAY,EAAE,CAAA,CACtB,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA;AAGd,EAAA,OAAO,OAAA,IAAW,WAAA;AACpB;AAKA,eAAsB,oBAAA,CACpB,IAAA,GAAe,mBAAA,EAAoB,EACR;AAC3B,EAAA,IAAI,GAAA;AACJ,EAAA,IAAI;AACF,IAAA,GAAA,GAAM,MAAMA,QAAA,CAAG,QAAA,CAAS,IAAA,EAAM,MAAM,CAAA;AAAA,EACtC,SAAS,GAAA,EAAK;AACZ,IAAA,IAAK,GAAA,CAA8B,SAAS,QAAA,EAAU;AACpD,MAAA,OAAO,EAAE,OAAA,EAAS,yBAAA,EAA2B,UAAA,EAAY,EAAC,EAAE;AAAA,IAC9D;AACA,IAAA,MAAM,GAAA;AAAA,EACR;AACA,EAAA,IAAI,MAAA;AACJ,EAAA,IAAI;AACF,IAAA,MAAA,GAAS,IAAA,CAAK,MA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AAW,QAAA,IAAY,UAAU,IAAA,CAAK,CAAA,CAAA,KAAK,CAAA,CAAE,IAAA,KAAS,IAAI,MAAM,CAAA,GACtE,IAAI,MAAA,GACL,SAAA,CAAU,CAAC,CAAA,EAAG,IAAA;AACpB,EAAA,MAAM,GAAA,GAAwB;AAAA,IAC5B,OAAA,EAAS,yBAAA;AAAA,IACT,UAAA,EAAY;AAAA,GACd;AACA,EAAA,IAAI,MAAA,KAAW,MAAA,EAAW,GAAA,CAAI,MAAA,GAAS,MAAA;AACvC,EAAA,OAAO,GAAA;AACT","file":"workspaces-config.mjs","sourcesContent":["/**\n * `~/.agentproto/workspaces.json` — single source of truth for the\n * local agentproto control plane. Tracks which directories the user\n * has opted into as agentproto workspaces, plus which one is \"active\"\n * (the daemon's default working set when no workspace is named in\n * a tool call).\n *\n * Why a config file instead of recreating an MCP entry per workspace:\n * - One daemon = one MCP entry in the user's IDE (clean to read in\n * `claude mcp list`, no `dapper_willow` / `noble_lantern` spam).\n * - The daemon walks `workspaces[]` at boot and exposes them all;\n * tools that need a target take an optional `workspace` arg and\n * fall back to `active` when omitted.\n * - The CLI (`agentproto workspace add/list/remove/use`), the daemon,\n * and the guilde-web onboarding dialog all read+write the same\n * file, so changes from one surface are immediately visible to\n * the others.\n *\n * File layout is intentionally boring (small, hand-editable JSON) —\n * future fields go on top, never break v1 readers.\n */\n\nimport { promises as fs } from \"node:fs\"\nimport { homedir } from \"node:os\"\nimport { dirname, isAbsolute, resolve } from \"node:path\"\n\nexport const WORKSPACES_CONFIG_VERSION = 1 as const\n\nexport interface WorkspaceEntry {\n /** Stable handle — what tools accept as `workspace`. Lowercase\n * ASCII, hyphen-only. The CLI sanitises arbitrary names down to\n * this shape so paste-from-finder Just Works. */\n slug: string\n /** Absolute filesystem path. Required absolute so the daemon can\n * serve the workspace regardless of its own cwd. */\n path: string\n /** ISO-8601 — first time the entry was added. Pure metadata, no\n * behavioural impact. */\n addedAt: string\n /** Last time the entry was touched (renamed, path edited, used as\n * active). Lets the CLI sort by recency without an N+1 stat. */\n updatedAt: string\n /** Free-text label the user can attach so workspaces with similar\n * slugs stay distinguishable in `agentproto workspace list`. */\n label?: string\n}\n\nexport interface WorkspacesConfig {\n version: typeof WORKSPACES_CONFIG_VERSION\n /** Active workspace slug — daemon defaults to this when no\n * `workspace` arg is passed. May be undefined when no workspaces\n * are registered yet. */\n active?: string\n workspaces: WorkspaceEntry[]\n}\n\nexport const DEFAULT_CONFIG_DIR = (): string =>\n resolve(homedir(), \".agentproto\")\nexport const DEFAULT_CONFIG_PATH = (): string =>\n resolve(DEFAULT_CONFIG_DIR(), \"workspaces.json\")\n\n/** Reduce arbitrary user input to a safe slug. Aligns with what most\n * tooling validates against (`/^[a-z0-9][a-z0-9-]{0,63}$/`) so the\n * daemon never has to encode it for URLs or filesystem paths. */\nexport function sanitizeSlug(input: string): string {\n const trimmed = input.trim().toLowerCase()\n const cleaned = trimmed\n .replace(/[^a-z0-9_-]+/g, \"-\")\n .replace(/^-+|-+$/g, \"\")\n .slice(0, 64)\n // Edge case: input was entirely non-conforming — fall back to a\n // generic so we never return an empty string.\n return cleaned || \"workspace\"\n}\n\n/** Read the config from disk. Returns an empty config (no workspaces,\n * no active) when the file is missing — this is the legitimate\n * first-boot state, not an error. */\nexport async function loadWorkspacesConfig(\n path: string = DEFAULT_CONFIG_PATH()\n): Promise<WorkspacesConfig> {\n let raw: string\n try {\n raw = await fs.readFile(path, \"utf8\")\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === \"ENOENT\") {\n return { version: WORKSPACES_CONFIG_VERSION, workspaces: [] }\n }\n throw err\n }\n let parsed: unknown\n try {\n parsed = JSON.parse(raw)\n } catch (err) {\n throw new Error(\n `agentproto: ${path} is not valid JSON (${\n err instanceof Error ? err.message : String(err)\n }). Delete the file or fix it manually.`\n )\n }\n return normalizeConfig(parsed)\n}\n\n/** Write the config back. Creates the parent directory if missing.\n * Atomic-ish: writes to a temp file first, then renames over the\n * target — avoids the partial-write window where a concurrent reader\n * sees half a JSON object. */\nexport async function saveWorkspacesConfig(\n config: WorkspacesConfig,\n path: string = DEFAULT_CONFIG_PATH()\n): Promise<void> {\n const normalized = normalizeConfig(config)\n await fs.mkdir(dirname(path), { recursive: true })\n const tmp = `${path}.tmp.${process.pid}`\n await fs.writeFile(tmp, JSON.stringify(normalized, null, 2) + \"\\n\", \"utf8\")\n await fs.rename(tmp, path)\n}\n\n/**\n * Pure helpers — caller manages persistence. Returns a NEW config\n * (never mutates) so callers can compose multiple updates before\n * a single save.\n */\nexport function addWorkspace(\n config: WorkspacesConfig,\n input: { slug: string; path: string; label?: string }\n): WorkspacesConfig {\n if (!isAbsolute(input.path)) {\n throw new Error(\n `addWorkspace: path must be absolute, got \"${input.path}\".`\n )\n }\n const slug = sanitizeSlug(input.slug)\n const now = new Date().toISOString()\n const existingIdx = config.workspaces.findIndex(w => w.slug === slug)\n const next: WorkspaceEntry = existingIdx >= 0\n ? {\n ...config.workspaces[existingIdx]!,\n path: input.path,\n ...(input.label !== undefined ? { label: input.label } : {}),\n updatedAt: now,\n }\n : {\n slug,\n path: input.path,\n ...(input.label ? { label: input.label } : {}),\n addedAt: now,\n updatedAt: now,\n }\n const workspaces = [...config.workspaces]\n if (existingIdx >= 0) workspaces[existingIdx] = next\n else workspaces.push(next)\n // First-add becomes active automatically — saves the user a\n // separate `workspace use` call right after a fresh `add`.\n const active = config.active ?? slug\n return { ...config, workspaces, active }\n}\n\nexport function removeWorkspace(\n config: WorkspacesConfig,\n slug: string\n): WorkspacesConfig {\n const sanitised = sanitizeSlug(slug)\n const workspaces = config.workspaces.filter(w => w.slug !== sanitised)\n // If the removed workspace was active, hand off to whatever's\n // first — predictable and avoids leaving the daemon in an\n // unreachable state when the user removes the only one.\n let active = config.active\n if (active === sanitised) {\n active = workspaces[0]?.slug\n }\n const next: WorkspacesConfig = { ...config, workspaces }\n if (active !== undefined) next.active = active\n else delete next.active\n return next\n}\n\nexport function setActiveWorkspace(\n config: WorkspacesConfig,\n slug: string\n): WorkspacesConfig {\n const sanitised = sanitizeSlug(slug)\n if (!config.workspaces.some(w => w.slug === sanitised)) {\n throw new Error(\n `setActiveWorkspace: no workspace registered with slug \"${sanitised}\". ` +\n `Run \\`agentproto workspace add <path> --slug ${sanitised}\\` first.`\n )\n }\n return { ...config, active: sanitised }\n}\n\nexport function findWorkspace(\n config: WorkspacesConfig,\n slug: string\n): WorkspaceEntry | undefined {\n return config.workspaces.find(w => w.slug === sanitizeSlug(slug))\n}\n\n/** The active workspace, or undefined when none is registered. Pure\n * convenience to avoid re-implementing the lookup at every caller. */\nexport function getActiveWorkspace(\n config: WorkspacesConfig\n): WorkspaceEntry | undefined {\n if (!config.active) return config.workspaces[0]\n return findWorkspace(config, config.active) ?? config.workspaces[0]\n}\n\n/**\n * Coerce arbitrary parsed JSON into a valid config. Skips entries\n * with missing required fields rather than throwing — partial recovery\n * is friendlier than \"your config file is corrupted, here's a stack\n * trace\". Logs nothing here; the CLI shells that consume this should\n * decide whether to surface a warning.\n */\nfunction normalizeConfig(parsed: unknown): WorkspacesConfig {\n if (!parsed || typeof parsed !== \"object\") {\n return { version: WORKSPACES_CONFIG_VERSION, workspaces: [] }\n }\n const obj = parsed as Record<string, unknown>\n const workspaces: WorkspaceEntry[] = []\n if (Array.isArray(obj.workspaces)) {\n for (const entry of obj.workspaces) {\n if (!entry || typeof entry !== \"object\") continue\n const e = entry as Record<string, unknown>\n const slug = typeof e.slug === \"string\" ? sanitizeSlug(e.slug) : \"\"\n const path = typeof e.path === \"string\" ? e.path : \"\"\n if (!slug || !path) continue\n const addedAt =\n typeof e.addedAt === \"string\" ? e.addedAt : new Date().toISOString()\n const updatedAt = typeof e.updatedAt === \"string\" ? e.updatedAt : addedAt\n const we: WorkspaceEntry = { slug, path, addedAt, updatedAt }\n if (typeof e.label === \"string\" && e.label.trim()) {\n we.label = e.label.trim()\n }\n workspaces.push(we)\n }\n }\n // De-dupe by slug (last wins) — the file is hand-editable so a\n // typo could have produced two entries with the same slug.\n const dedup = new Map<string, WorkspaceEntry>()\n for (const w of workspaces) dedup.set(w.slug, w)\n const finalList = Array.from(dedup.values())\n const active =\n typeof obj.active === \"string\" && finalList.some(w => w.slug === obj.active)\n ? (obj.active as string)\n : finalList[0]?.slug\n const out: WorkspacesConfig = {\n version: WORKSPACES_CONFIG_VERSION,\n workspaces: finalList,\n }\n if (active !== undefined) out.active = active\n return out\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentproto/runtime",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "@agentproto/runtime — long-running gateway that turns an agentproto workspace into a live runtime. Composes @agentproto/mcp-server (CRUD verbs) with HTTP transport, HEARTBEAT.md autonomy loop, and append-only conversation persistence. Drop a workspace dir, point your MCP client at it, and the agent ticks on its own.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"agentproto",
|
|
7
|
+
"runtime",
|
|
8
|
+
"gateway",
|
|
9
|
+
"mcp",
|
|
10
|
+
"heartbeat",
|
|
11
|
+
"autonomy"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://agentproto.sh",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/agentproto/ts",
|
|
17
|
+
"directory": "packages/runtime"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/agentproto/ts/issues"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "dist/index.mjs",
|
|
25
|
+
"module": "dist/index.mjs",
|
|
26
|
+
"types": "dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.mjs",
|
|
31
|
+
"default": "./dist/index.mjs"
|
|
32
|
+
},
|
|
33
|
+
"./conversations": {
|
|
34
|
+
"types": "./dist/conversations.d.ts",
|
|
35
|
+
"import": "./dist/conversations.mjs",
|
|
36
|
+
"default": "./dist/conversations.mjs"
|
|
37
|
+
},
|
|
38
|
+
"./heartbeat": {
|
|
39
|
+
"types": "./dist/heartbeat.d.ts",
|
|
40
|
+
"import": "./dist/heartbeat.mjs",
|
|
41
|
+
"default": "./dist/heartbeat.mjs"
|
|
42
|
+
},
|
|
43
|
+
"./workspace-fs": {
|
|
44
|
+
"types": "./dist/workspace-fs.d.ts",
|
|
45
|
+
"import": "./dist/workspace-fs.mjs",
|
|
46
|
+
"default": "./dist/workspace-fs.mjs"
|
|
47
|
+
},
|
|
48
|
+
"./package.json": "./package.json",
|
|
49
|
+
"./workspaces-config": {
|
|
50
|
+
"types": "./dist/workspaces-config.d.ts",
|
|
51
|
+
"import": "./dist/workspaces-config.mjs",
|
|
52
|
+
"default": "./dist/workspaces-config.mjs"
|
|
53
|
+
},
|
|
54
|
+
"./config": {
|
|
55
|
+
"types": "./dist/config.d.ts",
|
|
56
|
+
"import": "./dist/config.mjs",
|
|
57
|
+
"default": "./dist/config.mjs"
|
|
58
|
+
},
|
|
59
|
+
"./mcp-imports": {
|
|
60
|
+
"types": "./dist/mcp-imports.d.ts",
|
|
61
|
+
"import": "./dist/mcp-imports.mjs",
|
|
62
|
+
"default": "./dist/mcp-imports.mjs"
|
|
63
|
+
},
|
|
64
|
+
"./resume-strategies": {
|
|
65
|
+
"types": "./dist/resume-strategies.d.ts",
|
|
66
|
+
"import": "./dist/resume-strategies.mjs",
|
|
67
|
+
"default": "./dist/resume-strategies.mjs"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"files": [
|
|
71
|
+
"dist",
|
|
72
|
+
"README.md",
|
|
73
|
+
"LICENSE"
|
|
74
|
+
],
|
|
75
|
+
"publishConfig": {
|
|
76
|
+
"access": "public"
|
|
77
|
+
},
|
|
78
|
+
"dependencies": {
|
|
79
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
80
|
+
"gray-matter": "^4.0.3",
|
|
81
|
+
"ws": "^8.18.0",
|
|
82
|
+
"zod": "^4.4.3",
|
|
83
|
+
"@agentproto/agent": "0.1.0",
|
|
84
|
+
"@agentproto/manifest": "0.1.0",
|
|
85
|
+
"@agentproto/mcp-server": "0.1.0"
|
|
86
|
+
},
|
|
87
|
+
"devDependencies": {
|
|
88
|
+
"@types/node": "^25.6.2",
|
|
89
|
+
"@types/ws": "^8.5.13",
|
|
90
|
+
"tsup": "^8.5.1",
|
|
91
|
+
"typescript": "^5.9.3",
|
|
92
|
+
"vitest": "^3.2.4",
|
|
93
|
+
"@agentproto/tooling": "0.1.0-alpha.0"
|
|
94
|
+
},
|
|
95
|
+
"scripts": {
|
|
96
|
+
"dev": "tsup --watch",
|
|
97
|
+
"build": "tsup",
|
|
98
|
+
"clean": "rm -rf dist",
|
|
99
|
+
"check-types": "tsc --noEmit",
|
|
100
|
+
"test": "vitest run --passWithNoTests",
|
|
101
|
+
"test:watch": "vitest"
|
|
102
|
+
}
|
|
103
|
+
}
|