arcie 0.1.3 → 0.1.4
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/README.md +34 -6
- package/dist/agent/index.d.ts +6 -3
- package/dist/agent/index.js +6 -6
- package/dist/agent/index.js.map +1 -1
- package/dist/auth/index.d.ts +6 -5
- package/dist/auth/index.js +8 -17
- package/dist/auth/index.js.map +1 -1
- package/dist/channels/index.d.ts +8 -5
- package/dist/channels/index.js +10 -12
- package/dist/channels/index.js.map +1 -1
- package/dist/chunk-2ZSKZYWK.js +1901 -0
- package/dist/chunk-2ZSKZYWK.js.map +1 -0
- package/dist/chunk-3CNQ6HQV.js +12 -0
- package/dist/chunk-3CNQ6HQV.js.map +1 -0
- package/dist/chunk-4L7WVCTU.js +12 -0
- package/dist/chunk-4L7WVCTU.js.map +1 -0
- package/dist/chunk-6XETPLIF.js +176 -0
- package/dist/chunk-6XETPLIF.js.map +1 -0
- package/dist/chunk-CKHBEZCT.js +24 -0
- package/dist/chunk-CKHBEZCT.js.map +1 -0
- package/dist/chunk-FQ7KDNV5.js +12 -0
- package/dist/chunk-FQ7KDNV5.js.map +1 -0
- package/dist/chunk-L3BTL5FM.js +39 -0
- package/dist/chunk-L3BTL5FM.js.map +1 -0
- package/dist/chunk-LQC65UHE.js +34 -0
- package/dist/chunk-LQC65UHE.js.map +1 -0
- package/dist/chunk-PHTJLJOV.js +25 -0
- package/dist/chunk-PHTJLJOV.js.map +1 -0
- package/dist/chunk-QE46QFID.js +92 -0
- package/dist/chunk-QE46QFID.js.map +1 -0
- package/dist/chunk-WAD7VLNI.js +51 -0
- package/dist/chunk-WAD7VLNI.js.map +1 -0
- package/dist/chunk-ZJNHQXMO.js +20 -0
- package/dist/chunk-ZJNHQXMO.js.map +1 -0
- package/dist/cli/index.d.ts +0 -2
- package/dist/cli/index.js +252 -36
- package/dist/cli/index.js.map +1 -1
- package/dist/context/index.d.ts +14 -11
- package/dist/context/index.js +22 -37
- package/dist/context/index.js.map +1 -1
- package/dist/discover/index.d.ts +17 -7
- package/dist/discover/index.js +6 -132
- package/dist/discover/index.js.map +1 -1
- package/dist/hooks/index.d.ts +6 -3
- package/dist/hooks/index.js +6 -6
- package/dist/hooks/index.js.map +1 -1
- package/dist/index-b4NcDl3m.d.ts +136 -0
- package/dist/index.d.ts +297 -18
- package/dist/index.js +158 -13
- package/dist/index.js.map +1 -1
- package/dist/instructions/index.d.ts +7 -4
- package/dist/instructions/index.js +8 -32
- package/dist/instructions/index.js.map +1 -1
- package/dist/protocol/events.d.ts +47 -39
- package/dist/protocol/events.js +46 -45
- package/dist/protocol/events.js.map +1 -1
- package/dist/runner/index.d.ts +4 -18
- package/dist/runner/index.js +10 -277
- package/dist/runner/index.js.map +1 -1
- package/dist/schedules/index.d.ts +6 -3
- package/dist/schedules/index.js +6 -6
- package/dist/schedules/index.js.map +1 -1
- package/dist/skills/index.d.ts +7 -4
- package/dist/skills/index.js +8 -27
- package/dist/skills/index.js.map +1 -1
- package/dist/tools/index.d.ts +13 -3
- package/dist/tools/index.js +8 -9
- package/dist/tools/index.js.map +1 -1
- package/dist/types-BxOQTzx1.d.ts +151 -0
- package/docs/getting-started.md +2 -2
- package/docs/index.md +3 -2
- package/docs/project-layout.md +2 -2
- package/docs/subagents.md +95 -0
- package/package.json +15 -10
- package/templates/default/agent/agent.ts +2 -2
- package/templates/default/package.json +3 -3
- package/dist/agent/index.d.ts.map +0 -1
- package/dist/auth/index.d.ts.map +0 -1
- package/dist/channels/index.d.ts.map +0 -1
- package/dist/cli/banner.d.ts +0 -2
- package/dist/cli/banner.d.ts.map +0 -1
- package/dist/cli/banner.js +0 -10
- package/dist/cli/banner.js.map +0 -1
- package/dist/cli/build.d.ts +0 -5
- package/dist/cli/build.d.ts.map +0 -1
- package/dist/cli/build.js +0 -54
- package/dist/cli/build.js.map +0 -1
- package/dist/cli/dev.d.ts +0 -5
- package/dist/cli/dev.d.ts.map +0 -1
- package/dist/cli/dev.js +0 -74
- package/dist/cli/dev.js.map +0 -1
- package/dist/cli/index.d.ts.map +0 -1
- package/dist/cli/init.d.ts +0 -4
- package/dist/cli/init.d.ts.map +0 -1
- package/dist/cli/init.js +0 -75
- package/dist/cli/init.js.map +0 -1
- package/dist/context/index.d.ts.map +0 -1
- package/dist/discover/index.d.ts.map +0 -1
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/instructions/index.d.ts.map +0 -1
- package/dist/loader.d.ts +0 -7
- package/dist/loader.d.ts.map +0 -1
- package/dist/loader.js +0 -102
- package/dist/loader.js.map +0 -1
- package/dist/protocol/events.d.ts.map +0 -1
- package/dist/runner/index.d.ts.map +0 -1
- package/dist/schedules/index.d.ts.map +0 -1
- package/dist/skills/index.d.ts.map +0 -1
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/types.d.ts +0 -118
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/instructions/index.ts
|
|
2
|
+
import { readFileSync, existsSync } from "fs";
|
|
3
|
+
import { resolve } from "path";
|
|
4
|
+
function defineInstructions(source) {
|
|
5
|
+
if (typeof source === "string") {
|
|
6
|
+
const filePath = resolve(process.cwd(), source);
|
|
7
|
+
if (!existsSync(filePath)) {
|
|
8
|
+
throw new Error(`Instructions file not found: ${filePath}`);
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
content: readFileSync(filePath, "utf-8"),
|
|
12
|
+
filePath
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
return source;
|
|
16
|
+
}
|
|
17
|
+
function loadInstructions(agentDir) {
|
|
18
|
+
const mdPath = resolve(agentDir, "instructions.md");
|
|
19
|
+
const tsPath = resolve(agentDir, "instructions.ts");
|
|
20
|
+
if (existsSync(mdPath)) {
|
|
21
|
+
return {
|
|
22
|
+
content: readFileSync(mdPath, "utf-8"),
|
|
23
|
+
filePath: mdPath
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (existsSync(tsPath)) {
|
|
27
|
+
return {
|
|
28
|
+
content: readFileSync(tsPath, "utf-8"),
|
|
29
|
+
filePath: tsPath
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
defineInstructions,
|
|
37
|
+
loadInstructions
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=chunk-L3BTL5FM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/instructions/index.ts"],"sourcesContent":["import { readFileSync, existsSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { InstructionsConfig } from \"../types\";\n\nexport function defineInstructions(\n source: string | InstructionsConfig\n): InstructionsConfig {\n if (typeof source === \"string\") {\n const filePath = resolve(process.cwd(), source);\n if (!existsSync(filePath)) {\n throw new Error(`Instructions file not found: ${filePath}`);\n }\n return {\n content: readFileSync(filePath, \"utf-8\"),\n filePath,\n };\n }\n return source;\n}\n\nexport function loadInstructions(\n agentDir: string\n): InstructionsConfig | null {\n const mdPath = resolve(agentDir, \"instructions.md\");\n const tsPath = resolve(agentDir, \"instructions.ts\");\n\n if (existsSync(mdPath)) {\n return {\n content: readFileSync(mdPath, \"utf-8\"),\n filePath: mdPath,\n };\n }\n if (existsSync(tsPath)) {\n return {\n content: readFileSync(tsPath, \"utf-8\"),\n filePath: tsPath,\n };\n }\n return null;\n}\n"],"mappings":";AAAA,SAAS,cAAc,kBAAkB;AACzC,SAAS,eAAe;AAGjB,SAAS,mBACd,QACoB;AACpB,MAAI,OAAO,WAAW,UAAU;AAC9B,UAAM,WAAW,QAAQ,QAAQ,IAAI,GAAG,MAAM;AAC9C,QAAI,CAAC,WAAW,QAAQ,GAAG;AACzB,YAAM,IAAI,MAAM,gCAAgC,QAAQ,EAAE;AAAA,IAC5D;AACA,WAAO;AAAA,MACL,SAAS,aAAa,UAAU,OAAO;AAAA,MACvC;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEO,SAAS,iBACd,UAC2B;AAC3B,QAAM,SAAS,QAAQ,UAAU,iBAAiB;AAClD,QAAM,SAAS,QAAQ,UAAU,iBAAiB;AAElD,MAAI,WAAW,MAAM,GAAG;AACtB,WAAO;AAAA,MACL,SAAS,aAAa,QAAQ,OAAO;AAAA,MACrC,UAAU;AAAA,IACZ;AAAA,EACF;AACA,MAAI,WAAW,MAAM,GAAG;AACtB,WAAO;AAAA,MACL,SAAS,aAAa,QAAQ,OAAO;AAAA,MACrC,UAAU;AAAA,IACZ;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// src/skills/index.ts
|
|
2
|
+
import { readFileSync, existsSync } from "fs";
|
|
3
|
+
import { resolve } from "path";
|
|
4
|
+
function defineSkill(config) {
|
|
5
|
+
if (!config.name || !config.content) {
|
|
6
|
+
throw new Error("Skill must have a name and content");
|
|
7
|
+
}
|
|
8
|
+
return config;
|
|
9
|
+
}
|
|
10
|
+
function getSkill(agentDir, name) {
|
|
11
|
+
const mdPath = resolve(agentDir, "knowledge", `${name}.md`);
|
|
12
|
+
const tsPath = resolve(agentDir, "knowledge", `${name}.ts`);
|
|
13
|
+
if (existsSync(mdPath)) {
|
|
14
|
+
return {
|
|
15
|
+
name,
|
|
16
|
+
description: "",
|
|
17
|
+
content: readFileSync(mdPath, "utf-8")
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if (existsSync(tsPath)) {
|
|
21
|
+
return {
|
|
22
|
+
name,
|
|
23
|
+
description: "",
|
|
24
|
+
content: readFileSync(tsPath, "utf-8")
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
defineSkill,
|
|
32
|
+
getSkill
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=chunk-LQC65UHE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/skills/index.ts"],"sourcesContent":["import { readFileSync, existsSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport type { SkillConfig } from \"../types\";\n\nexport function defineSkill(config: SkillConfig): SkillConfig {\n if (!config.name || !config.content) {\n throw new Error(\"Skill must have a name and content\");\n }\n return config;\n}\n\nexport function getSkill(\n agentDir: string,\n name: string\n): SkillConfig | null {\n const mdPath = resolve(agentDir, \"knowledge\", `${name}.md`);\n const tsPath = resolve(agentDir, \"knowledge\", `${name}.ts`);\n\n if (existsSync(mdPath)) {\n return {\n name,\n description: \"\",\n content: readFileSync(mdPath, \"utf-8\"),\n };\n }\n if (existsSync(tsPath)) {\n return {\n name,\n description: \"\",\n content: readFileSync(tsPath, \"utf-8\"),\n };\n }\n return null;\n}\n"],"mappings":";AAAA,SAAS,cAAc,kBAAkB;AACzC,SAAS,eAAe;AAGjB,SAAS,YAAY,QAAkC;AAC5D,MAAI,CAAC,OAAO,QAAQ,CAAC,OAAO,SAAS;AACnC,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AACA,SAAO;AACT;AAEO,SAAS,SACd,UACA,MACoB;AACpB,QAAM,SAAS,QAAQ,UAAU,aAAa,GAAG,IAAI,KAAK;AAC1D,QAAM,SAAS,QAAQ,UAAU,aAAa,GAAG,IAAI,KAAK;AAE1D,MAAI,WAAW,MAAM,GAAG;AACtB,WAAO;AAAA,MACL;AAAA,MACA,aAAa;AAAA,MACb,SAAS,aAAa,QAAQ,OAAO;AAAA,IACvC;AAAA,EACF;AACA,MAAI,WAAW,MAAM,GAAG;AACtB,WAAO;AAAA,MACL;AAAA,MACA,aAAa;AAAA,MACb,SAAS,aAAa,QAAQ,OAAO;AAAA,IACvC;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/tools/index.ts
|
|
2
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
3
|
+
function defineTool(config) {
|
|
4
|
+
if (!config.description) {
|
|
5
|
+
throw new Error("Tool must have a description");
|
|
6
|
+
}
|
|
7
|
+
if (!config.execute) {
|
|
8
|
+
throw new Error("Tool must have an execute function");
|
|
9
|
+
}
|
|
10
|
+
return config;
|
|
11
|
+
}
|
|
12
|
+
function toModelOutput(name, tool) {
|
|
13
|
+
return {
|
|
14
|
+
name,
|
|
15
|
+
description: tool.description,
|
|
16
|
+
input_schema: tool.inputSchema ? zodToJsonSchema(tool.inputSchema, { target: "openApi3" }) : void 0,
|
|
17
|
+
type: "function"
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
defineTool,
|
|
23
|
+
toModelOutput
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=chunk-PHTJLJOV.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/tools/index.ts"],"sourcesContent":["import { zodToJsonSchema } from \"zod-to-json-schema\";\nimport type { ToolConfig } from \"../types\";\n\nexport function defineTool<TInput = unknown, TOutput = unknown>(\n config: ToolConfig<TInput, TOutput>\n): ToolConfig<TInput, TOutput> {\n if (!config.description) {\n throw new Error(\"Tool must have a description\");\n }\n if (!config.execute) {\n throw new Error(\"Tool must have an execute function\");\n }\n return config;\n}\n\nexport interface ModelToolDefinition {\n name: string;\n description: string;\n input_schema?: Record<string, unknown>;\n type: \"function\";\n}\n\nexport function toModelOutput(name: string, tool: ToolConfig): ModelToolDefinition {\n return {\n name,\n description: tool.description,\n input_schema: tool.inputSchema\n ? (zodToJsonSchema(tool.inputSchema, { target: \"openApi3\" }) as Record<string, unknown>)\n : undefined,\n type: \"function\",\n };\n}\n"],"mappings":";AAAA,SAAS,uBAAuB;AAGzB,SAAS,WACd,QAC6B;AAC7B,MAAI,CAAC,OAAO,aAAa;AACvB,UAAM,IAAI,MAAM,8BAA8B;AAAA,EAChD;AACA,MAAI,CAAC,OAAO,SAAS;AACnB,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AACA,SAAO;AACT;AASO,SAAS,cAAc,MAAc,MAAuC;AACjF,SAAO;AAAA,IACL;AAAA,IACA,aAAa,KAAK;AAAA,IAClB,cAAc,KAAK,cACd,gBAAgB,KAAK,aAAa,EAAE,QAAQ,WAAW,CAAC,IACzD;AAAA,IACJ,MAAM;AAAA,EACR;AACF;","names":[]}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// src/protocol/events.ts
|
|
2
|
+
function createSessionStarted(sessionId, runtime) {
|
|
3
|
+
return { type: "session.started", data: { sessionId, ...runtime ? { runtime } : {} } };
|
|
4
|
+
}
|
|
5
|
+
function createTurnStarted(sequence, turnId) {
|
|
6
|
+
return { type: "turn.started", data: { sequence, turnId } };
|
|
7
|
+
}
|
|
8
|
+
function createMessageReceived(message, sequence, turnId) {
|
|
9
|
+
return { type: "message.received", data: { message, sequence, turnId } };
|
|
10
|
+
}
|
|
11
|
+
function createMessageAppended(delta, textSoFar, sequence, stepIndex, turnId) {
|
|
12
|
+
return { type: "message.appended", data: { delta, textSoFar, sequence, stepIndex, turnId } };
|
|
13
|
+
}
|
|
14
|
+
function createMessageCompleted(text, finishReason, sequence, stepIndex, turnId) {
|
|
15
|
+
return { type: "message.completed", data: { text, finishReason, sequence, stepIndex, turnId } };
|
|
16
|
+
}
|
|
17
|
+
function createStepStarted(sequence, stepIndex, turnId) {
|
|
18
|
+
return { type: "step.started", data: { sequence, stepIndex, turnId } };
|
|
19
|
+
}
|
|
20
|
+
function createStepCompleted(finishReason, sequence, stepIndex, turnId, usage) {
|
|
21
|
+
return { type: "step.completed", data: { finishReason, sequence, stepIndex, turnId, usage } };
|
|
22
|
+
}
|
|
23
|
+
function createStepFailed(code, message, sequence, stepIndex, turnId) {
|
|
24
|
+
return { type: "step.failed", data: { code, message, sequence, stepIndex, turnId } };
|
|
25
|
+
}
|
|
26
|
+
function createReasoningAppended(delta, soFar, sequence, stepIndex, turnId) {
|
|
27
|
+
return { type: "reasoning.appended", data: { delta, soFar, sequence, stepIndex, turnId } };
|
|
28
|
+
}
|
|
29
|
+
function createReasoningCompleted(text, sequence, stepIndex, turnId) {
|
|
30
|
+
return { type: "reasoning.completed", data: { text, sequence, stepIndex, turnId } };
|
|
31
|
+
}
|
|
32
|
+
function createTurnCompleted(sequence, turnId) {
|
|
33
|
+
return { type: "turn.completed", data: { sequence, turnId } };
|
|
34
|
+
}
|
|
35
|
+
function createTurnFailed(code, message, sequence, turnId) {
|
|
36
|
+
return { type: "turn.failed", data: { code, message, sequence, turnId } };
|
|
37
|
+
}
|
|
38
|
+
function createSessionFailed(code, message, sessionId) {
|
|
39
|
+
return { type: "session.failed", data: { code, message, sessionId } };
|
|
40
|
+
}
|
|
41
|
+
function createSessionWaiting() {
|
|
42
|
+
return { type: "session.waiting", data: { wait: "next-user-message" } };
|
|
43
|
+
}
|
|
44
|
+
function createSessionCompleted() {
|
|
45
|
+
return { type: "session.completed" };
|
|
46
|
+
}
|
|
47
|
+
function createToolCallStarted(name, input, callId, sequence, stepIndex, turnId) {
|
|
48
|
+
return { type: "tool.started", data: { name, input, callId, sequence, stepIndex, turnId } };
|
|
49
|
+
}
|
|
50
|
+
function createToolCallCompleted(name, output, callId, status, error, sequence, stepIndex, turnId) {
|
|
51
|
+
return {
|
|
52
|
+
type: "tool.completed",
|
|
53
|
+
data: { name, output, callId, status, ...error ? { error } : {}, sequence: sequence ?? 1, stepIndex: stepIndex ?? 0, turnId: turnId ?? "" }
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function createSubagentCalled(name, callId, childSessionId, turnId) {
|
|
57
|
+
return { type: "subagent.called", data: { name, callId, childSessionId, turnId } };
|
|
58
|
+
}
|
|
59
|
+
function createSubagentCompleted(name, callId, output) {
|
|
60
|
+
return { type: "subagent.completed", data: { name, callId, output } };
|
|
61
|
+
}
|
|
62
|
+
function encodeEvent(event) {
|
|
63
|
+
return JSON.stringify(event) + "\n";
|
|
64
|
+
}
|
|
65
|
+
function encodeEvents(events) {
|
|
66
|
+
return events.map(encodeEvent).join("");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export {
|
|
70
|
+
createSessionStarted,
|
|
71
|
+
createTurnStarted,
|
|
72
|
+
createMessageReceived,
|
|
73
|
+
createMessageAppended,
|
|
74
|
+
createMessageCompleted,
|
|
75
|
+
createStepStarted,
|
|
76
|
+
createStepCompleted,
|
|
77
|
+
createStepFailed,
|
|
78
|
+
createReasoningAppended,
|
|
79
|
+
createReasoningCompleted,
|
|
80
|
+
createTurnCompleted,
|
|
81
|
+
createTurnFailed,
|
|
82
|
+
createSessionFailed,
|
|
83
|
+
createSessionWaiting,
|
|
84
|
+
createSessionCompleted,
|
|
85
|
+
createToolCallStarted,
|
|
86
|
+
createToolCallCompleted,
|
|
87
|
+
createSubagentCalled,
|
|
88
|
+
createSubagentCompleted,
|
|
89
|
+
encodeEvent,
|
|
90
|
+
encodeEvents
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=chunk-QE46QFID.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/protocol/events.ts"],"sourcesContent":["export type AssistantStepFinishReason =\n | \"content-filter\"\n | \"error\"\n | \"length\"\n | \"other\"\n | \"stop\"\n | \"tool-calls\";\n\nexport type ActionResultStatus = \"completed\" | \"failed\" | \"rejected\" | \"pending\";\n\nexport interface ActionResultError {\n readonly code: string;\n readonly message: string;\n}\n\nexport interface SessionStartedEvent {\n type: \"session.started\";\n data: {\n sessionId: string;\n runtime?: { agentId: string; modelId: string; arcieVersion: string };\n };\n}\n\nexport interface TurnStartedEvent {\n type: \"turn.started\";\n data: { sequence: number; turnId: string };\n}\n\nexport interface MessageReceivedEvent {\n type: \"message.received\";\n data: { message: string; sequence: number; turnId: string };\n}\n\nexport interface MessageAppendedEvent {\n type: \"message.appended\";\n data: { delta: string; textSoFar: string; sequence: number; stepIndex: number; turnId: string };\n}\n\nexport interface MessageCompletedEvent {\n type: \"message.completed\";\n data: { text: string | null; finishReason: AssistantStepFinishReason; sequence: number; stepIndex: number; turnId: string };\n}\n\nexport interface ReasoningAppendedEvent {\n type: \"reasoning.appended\";\n data: { delta: string; soFar: string; sequence: number; stepIndex: number; turnId: string };\n}\n\nexport interface ReasoningCompletedEvent {\n type: \"reasoning.completed\";\n data: { text: string; sequence: number; stepIndex: number; turnId: string };\n}\n\nexport interface StepStartedEvent {\n type: \"step.started\";\n data: { sequence: number; stepIndex: number; turnId: string };\n}\n\nexport interface StepCompletedEvent {\n type: \"step.completed\";\n data: { finishReason: AssistantStepFinishReason; sequence: number; stepIndex: number; turnId: string; usage?: { inputTokens?: number; outputTokens?: number } };\n}\n\nexport interface StepFailedEvent {\n type: \"step.failed\";\n data: { code: string; message: string; sequence: number; stepIndex: number; turnId: string };\n}\n\nexport interface ToolCallStartedEvent {\n type: \"tool.started\";\n data: { name: string; input: unknown; callId: string; sequence: number; stepIndex: number; turnId: string };\n}\n\nexport interface ToolCallCompletedEvent {\n type: \"tool.completed\";\n data: { name: string; output: unknown; callId: string; status: ActionResultStatus; error?: ActionResultError; sequence: number; stepIndex: number; turnId: string };\n}\n\nexport interface TurnCompletedEvent {\n type: \"turn.completed\";\n data: { sequence: number; turnId: string };\n}\n\nexport interface TurnFailedEvent {\n type: \"turn.failed\";\n data: { code: string; message: string; sequence: number; turnId: string };\n}\n\nexport interface SessionWaitingEvent {\n type: \"session.waiting\";\n data: { wait: \"next-user-message\" };\n}\n\nexport interface SessionCompletedEvent {\n type: \"session.completed\";\n}\n\nexport interface SessionFailedEvent {\n type: \"session.failed\";\n data: { code: string; message: string; sessionId: string };\n}\n\nexport interface SubagentCalledEvent {\n type: \"subagent.called\";\n data: { name: string; callId: string; childSessionId: string; turnId: string };\n}\n\nexport interface SubagentCompletedEvent {\n type: \"subagent.completed\";\n data: { name: string; callId: string; output: string };\n}\n\nexport type StreamEvent =\n | SessionStartedEvent\n | TurnStartedEvent\n | MessageReceivedEvent\n | MessageAppendedEvent\n | MessageCompletedEvent\n | ReasoningAppendedEvent\n | ReasoningCompletedEvent\n | StepStartedEvent\n | StepCompletedEvent\n | StepFailedEvent\n | ToolCallStartedEvent\n | ToolCallCompletedEvent\n | TurnCompletedEvent\n | TurnFailedEvent\n | SessionWaitingEvent\n | SessionCompletedEvent\n | SessionFailedEvent\n | SubagentCalledEvent\n | SubagentCompletedEvent;\n\nexport function createSessionStarted(sessionId: string, runtime?: SessionStartedEvent[\"data\"][\"runtime\"]): SessionStartedEvent {\n return { type: \"session.started\", data: { sessionId, ...(runtime ? { runtime } : {}) } };\n}\n\nexport function createTurnStarted(sequence: number, turnId: string): TurnStartedEvent {\n return { type: \"turn.started\", data: { sequence, turnId } };\n}\n\nexport function createMessageReceived(message: string, sequence: number, turnId: string): MessageReceivedEvent {\n return { type: \"message.received\", data: { message, sequence, turnId } };\n}\n\nexport function createMessageAppended(delta: string, textSoFar: string, sequence: number, stepIndex: number, turnId: string): MessageAppendedEvent {\n return { type: \"message.appended\", data: { delta, textSoFar, sequence, stepIndex, turnId } };\n}\n\nexport function createMessageCompleted(text: string | null, finishReason: AssistantStepFinishReason, sequence: number, stepIndex: number, turnId: string): MessageCompletedEvent {\n return { type: \"message.completed\", data: { text, finishReason, sequence, stepIndex, turnId } };\n}\n\nexport function createStepStarted(sequence: number, stepIndex: number, turnId: string): StepStartedEvent {\n return { type: \"step.started\", data: { sequence, stepIndex, turnId } };\n}\n\nexport function createStepCompleted(finishReason: AssistantStepFinishReason, sequence: number, stepIndex: number, turnId: string, usage?: StepCompletedEvent[\"data\"][\"usage\"]): StepCompletedEvent {\n return { type: \"step.completed\", data: { finishReason, sequence, stepIndex, turnId, usage } };\n}\n\nexport function createStepFailed(code: string, message: string, sequence: number, stepIndex: number, turnId: string): StepFailedEvent {\n return { type: \"step.failed\", data: { code, message, sequence, stepIndex, turnId } };\n}\n\nexport function createReasoningAppended(delta: string, soFar: string, sequence: number, stepIndex: number, turnId: string): ReasoningAppendedEvent {\n return { type: \"reasoning.appended\", data: { delta, soFar, sequence, stepIndex, turnId } };\n}\n\nexport function createReasoningCompleted(text: string, sequence: number, stepIndex: number, turnId: string): ReasoningCompletedEvent {\n return { type: \"reasoning.completed\", data: { text, sequence, stepIndex, turnId } };\n}\n\nexport function createTurnCompleted(sequence: number, turnId: string): TurnCompletedEvent {\n return { type: \"turn.completed\", data: { sequence, turnId } };\n}\n\nexport function createTurnFailed(code: string, message: string, sequence: number, turnId: string): TurnFailedEvent {\n return { type: \"turn.failed\", data: { code, message, sequence, turnId } };\n}\n\nexport function createSessionFailed(code: string, message: string, sessionId: string): SessionFailedEvent {\n return { type: \"session.failed\", data: { code, message, sessionId } };\n}\n\nexport function createSessionWaiting(): SessionWaitingEvent {\n return { type: \"session.waiting\", data: { wait: \"next-user-message\" } };\n}\n\nexport function createSessionCompleted(): SessionCompletedEvent {\n return { type: \"session.completed\" };\n}\n\nexport function createToolCallStarted(\n name: string, input: unknown, callId: string,\n sequence: number, stepIndex: number, turnId: string,\n): ToolCallStartedEvent {\n return { type: \"tool.started\", data: { name, input, callId, sequence, stepIndex, turnId } };\n}\n\nexport function createToolCallCompleted(\n name: string, output: unknown, callId: string, status: ActionResultStatus,\n error?: ActionResultError, sequence?: number, stepIndex?: number, turnId?: string,\n): ToolCallCompletedEvent {\n return {\n type: \"tool.completed\",\n data: { name, output, callId, status, ...(error ? { error } : {}), sequence: sequence ?? 1, stepIndex: stepIndex ?? 0, turnId: turnId ?? \"\" },\n };\n}\n\nexport function createSubagentCalled(\n name: string, callId: string, childSessionId: string, turnId: string,\n): SubagentCalledEvent {\n return { type: \"subagent.called\", data: { name, callId, childSessionId, turnId } };\n}\n\nexport function createSubagentCompleted(\n name: string, callId: string, output: string,\n): SubagentCompletedEvent {\n return { type: \"subagent.completed\", data: { name, callId, output } };\n}\n\nexport function encodeEvent(event: StreamEvent): string {\n return JSON.stringify(event) + \"\\n\";\n}\n\nexport function encodeEvents(events: StreamEvent[]): string {\n return events.map(encodeEvent).join(\"\");\n}\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// src/context/index.ts
|
|
2
|
+
var currentSession = null;
|
|
3
|
+
var currentTurn = null;
|
|
4
|
+
var sharedContext = /* @__PURE__ */ new Map();
|
|
5
|
+
function getSession() {
|
|
6
|
+
return currentSession;
|
|
7
|
+
}
|
|
8
|
+
function getTurn() {
|
|
9
|
+
return currentTurn;
|
|
10
|
+
}
|
|
11
|
+
function setSession(session) {
|
|
12
|
+
currentSession = session;
|
|
13
|
+
}
|
|
14
|
+
function setTurn(turn) {
|
|
15
|
+
currentTurn = turn;
|
|
16
|
+
}
|
|
17
|
+
function getContext(key) {
|
|
18
|
+
return sharedContext.get(key);
|
|
19
|
+
}
|
|
20
|
+
function requireContext(key) {
|
|
21
|
+
const value = sharedContext.get(key);
|
|
22
|
+
if (value === void 0) {
|
|
23
|
+
throw new Error(`Required context key not found: ${key}`);
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
function hasContext(key) {
|
|
28
|
+
return sharedContext.has(key);
|
|
29
|
+
}
|
|
30
|
+
function setContext(key, value) {
|
|
31
|
+
sharedContext.set(key, value);
|
|
32
|
+
}
|
|
33
|
+
function ensureContext(key, factory) {
|
|
34
|
+
if (!sharedContext.has(key)) {
|
|
35
|
+
sharedContext.set(key, factory());
|
|
36
|
+
}
|
|
37
|
+
return sharedContext.get(key);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
getSession,
|
|
42
|
+
getTurn,
|
|
43
|
+
setSession,
|
|
44
|
+
setTurn,
|
|
45
|
+
getContext,
|
|
46
|
+
requireContext,
|
|
47
|
+
hasContext,
|
|
48
|
+
setContext,
|
|
49
|
+
ensureContext
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=chunk-WAD7VLNI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/context/index.ts"],"sourcesContent":["import type { Session, TurnContext } from \"../types\";\n\nlet currentSession: Session | null = null;\nlet currentTurn: TurnContext | null = null;\nconst sharedContext = new Map<string, unknown>();\n\nexport function getSession(): Session | null {\n return currentSession;\n}\n\nexport function getTurn(): TurnContext | null {\n return currentTurn;\n}\n\nexport function setSession(session: Session): void {\n currentSession = session;\n}\n\nexport function setTurn(turn: TurnContext): void {\n currentTurn = turn;\n}\n\nexport function getContext<T = unknown>(key: string): T | undefined {\n return sharedContext.get(key) as T | undefined;\n}\n\nexport function requireContext<T = unknown>(key: string): T {\n const value = sharedContext.get(key);\n if (value === undefined) {\n throw new Error(`Required context key not found: ${key}`);\n }\n return value as T;\n}\n\nexport function hasContext(key: string): boolean {\n return sharedContext.has(key);\n}\n\nexport function setContext(key: string, value: unknown): void {\n sharedContext.set(key, value);\n}\n\nexport function ensureContext<T>(\n key: string,\n factory: () => T\n): T {\n if (!sharedContext.has(key)) {\n sharedContext.set(key, factory());\n }\n return sharedContext.get(key) as T;\n}\n"],"mappings":";AAEA,IAAI,iBAAiC;AACrC,IAAI,cAAkC;AACtC,IAAM,gBAAgB,oBAAI,IAAqB;AAExC,SAAS,aAA6B;AAC3C,SAAO;AACT;AAEO,SAAS,UAA8B;AAC5C,SAAO;AACT;AAEO,SAAS,WAAW,SAAwB;AACjD,mBAAiB;AACnB;AAEO,SAAS,QAAQ,MAAyB;AAC/C,gBAAc;AAChB;AAEO,SAAS,WAAwB,KAA4B;AAClE,SAAO,cAAc,IAAI,GAAG;AAC9B;AAEO,SAAS,eAA4B,KAAgB;AAC1D,QAAM,QAAQ,cAAc,IAAI,GAAG;AACnC,MAAI,UAAU,QAAW;AACvB,UAAM,IAAI,MAAM,mCAAmC,GAAG,EAAE;AAAA,EAC1D;AACA,SAAO;AACT;AAEO,SAAS,WAAW,KAAsB;AAC/C,SAAO,cAAc,IAAI,GAAG;AAC9B;AAEO,SAAS,WAAW,KAAa,OAAsB;AAC5D,gBAAc,IAAI,KAAK,KAAK;AAC9B;AAEO,SAAS,cACd,KACA,SACG;AACH,MAAI,CAAC,cAAc,IAAI,GAAG,GAAG;AAC3B,kBAAc,IAAI,KAAK,QAAQ,CAAC;AAAA,EAClC;AACA,SAAO,cAAc,IAAI,GAAG;AAC9B;","names":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/channels/index.ts
|
|
2
|
+
function defineChannel(config) {
|
|
3
|
+
if (!config.name || !config.handler) {
|
|
4
|
+
throw new Error("Channel must have name and handler");
|
|
5
|
+
}
|
|
6
|
+
return config;
|
|
7
|
+
}
|
|
8
|
+
function POST(handler) {
|
|
9
|
+
return handler;
|
|
10
|
+
}
|
|
11
|
+
function GET(handler) {
|
|
12
|
+
return handler;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
defineChannel,
|
|
17
|
+
POST,
|
|
18
|
+
GET
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=chunk-ZJNHQXMO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/channels/index.ts"],"sourcesContent":["import type { ChannelConfig } from \"../types\";\n\nexport function defineChannel(config: ChannelConfig): ChannelConfig {\n if (!config.name || !config.handler) {\n throw new Error(\"Channel must have name and handler\");\n }\n return config;\n}\n\nexport function POST(handler: ChannelConfig[\"handler\"]): ChannelConfig[\"handler\"] {\n return handler;\n}\n\nexport function GET(handler: ChannelConfig[\"handler\"]): ChannelConfig[\"handler\"] {\n return handler;\n}\n"],"mappings":";AAEO,SAAS,cAAc,QAAsC;AAClE,MAAI,CAAC,OAAO,QAAQ,CAAC,OAAO,SAAS;AACnC,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AACA,SAAO;AACT;AAEO,SAAS,KAAK,SAA6D;AAChF,SAAO;AACT;AAEO,SAAS,IAAI,SAA6D;AAC/E,SAAO;AACT;","names":[]}
|
package/dist/cli/index.d.ts
CHANGED
package/dist/cli/index.js
CHANGED
|
@@ -1,43 +1,259 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
loadAgent,
|
|
4
|
+
streamAgent
|
|
5
|
+
} from "../chunk-2ZSKZYWK.js";
|
|
6
|
+
import {
|
|
7
|
+
discoverAgent
|
|
8
|
+
} from "../chunk-6XETPLIF.js";
|
|
9
|
+
import "../chunk-QE46QFID.js";
|
|
10
|
+
import "../chunk-PHTJLJOV.js";
|
|
11
|
+
|
|
12
|
+
// src/cli/index.ts
|
|
2
13
|
import { Command } from "commander";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
14
|
+
|
|
15
|
+
// src/cli/init.ts
|
|
16
|
+
import { mkdirSync, writeFileSync, existsSync, readFileSync, readdirSync, statSync, copyFileSync } from "fs";
|
|
17
|
+
import { resolve, join, dirname } from "path";
|
|
18
|
+
import { fileURLToPath } from "url";
|
|
19
|
+
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
20
|
+
var TEMPLATES_DIR = resolve(__dirname, "../../templates");
|
|
21
|
+
async function initCommand(name, options) {
|
|
22
|
+
const targetDir = name ? resolve(process.cwd(), name) : resolve(process.cwd(), ".");
|
|
23
|
+
if (existsSync(targetDir) && name) {
|
|
24
|
+
console.error(`Directory already exists: ${targetDir}`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
const templateDir = resolve(TEMPLATES_DIR, options.template);
|
|
28
|
+
if (!existsSync(templateDir)) {
|
|
29
|
+
console.error(`Template not found: ${options.template}`);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
console.log(`
|
|
33
|
+
Scaffolding agent in ${targetDir}...
|
|
34
|
+
`);
|
|
35
|
+
copyTemplate(templateDir, targetDir);
|
|
36
|
+
if (name) {
|
|
37
|
+
updatePackageJson(targetDir, name);
|
|
38
|
+
}
|
|
39
|
+
console.log(` Done! Created agent in ${targetDir}`);
|
|
40
|
+
console.log(`
|
|
41
|
+
Next steps:`);
|
|
42
|
+
console.log(` cd ${name || "."}`);
|
|
43
|
+
console.log(` npm install`);
|
|
44
|
+
console.log(` npm run dev`);
|
|
45
|
+
console.log();
|
|
46
|
+
}
|
|
47
|
+
function copyTemplate(src, dest) {
|
|
48
|
+
const entries = collectFiles(src);
|
|
49
|
+
for (const entry of entries) {
|
|
50
|
+
const relative = entry.replace(src, "").replace(/^\//, "");
|
|
51
|
+
const destPath = join(dest, relative);
|
|
52
|
+
if (entry.endsWith(".gitkeep")) {
|
|
53
|
+
const parentDir = destPath.replace("/.gitkeep", "");
|
|
54
|
+
mkdirSync(parentDir, { recursive: true });
|
|
55
|
+
writeFileSync(join(parentDir, ".gitkeep"), "");
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
mkdirSync(dirname(destPath), { recursive: true });
|
|
59
|
+
if (entry.endsWith(".ts") || entry.endsWith(".md") || entry.endsWith(".json")) {
|
|
60
|
+
const content = readFileSync(entry, "utf-8");
|
|
61
|
+
writeFileSync(destPath, content);
|
|
62
|
+
} else {
|
|
63
|
+
copyFileSync(entry, destPath);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function collectFiles(dir) {
|
|
68
|
+
const files = [];
|
|
69
|
+
const entries = readdirSync(dir);
|
|
70
|
+
for (const entry of entries) {
|
|
71
|
+
const fullPath = join(dir, entry);
|
|
72
|
+
const stat = statSync(fullPath);
|
|
73
|
+
if (stat.isDirectory()) {
|
|
74
|
+
files.push(...collectFiles(fullPath));
|
|
75
|
+
} else {
|
|
76
|
+
files.push(fullPath);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return files;
|
|
80
|
+
}
|
|
81
|
+
function updatePackageJson(targetDir, projectName) {
|
|
82
|
+
const pkgPath2 = join(targetDir, "package.json");
|
|
83
|
+
if (existsSync(pkgPath2)) {
|
|
84
|
+
const pkg = JSON.parse(readFileSync(pkgPath2, "utf-8"));
|
|
85
|
+
pkg.name = projectName;
|
|
86
|
+
writeFileSync(pkgPath2, JSON.stringify(pkg, null, 2) + "\n");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/cli/dev.ts
|
|
91
|
+
import { createServer } from "http";
|
|
92
|
+
import { resolve as resolve2 } from "path";
|
|
93
|
+
|
|
94
|
+
// src/cli/banner.ts
|
|
95
|
+
function showBanner() {
|
|
96
|
+
console.log();
|
|
97
|
+
console.log(" \u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557");
|
|
98
|
+
console.log(" \u2551 Arcie \u2551");
|
|
99
|
+
console.log(" \u2551 The electronic line \u2014 build \u2551");
|
|
100
|
+
console.log(" \u2551 agents at the speed of light. \u2551");
|
|
101
|
+
console.log(" \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D");
|
|
102
|
+
console.log();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/cli/dev.ts
|
|
106
|
+
async function devCommand(options) {
|
|
107
|
+
const port = parseInt(options.port, 10);
|
|
108
|
+
const agentDirPath = resolve2(process.cwd(), options.agentDir);
|
|
109
|
+
showBanner();
|
|
110
|
+
const { agent: discovered, diagnostics } = discoverAgent(agentDirPath);
|
|
111
|
+
if (diagnostics.some((d) => d.severity === "error")) {
|
|
112
|
+
for (const d of diagnostics) {
|
|
113
|
+
console.error(` \u2716 ${d.code}: ${d.message}`);
|
|
114
|
+
}
|
|
115
|
+
process.exit(1);
|
|
116
|
+
}
|
|
117
|
+
for (const d of diagnostics) {
|
|
118
|
+
console.warn(` \u26A0 ${d.code}: ${d.message}`);
|
|
119
|
+
}
|
|
120
|
+
console.log(` Agent: ${agentDirPath}`);
|
|
121
|
+
console.log(` Server: http://localhost:${port}`);
|
|
122
|
+
console.log();
|
|
123
|
+
if (discovered.agentConfig) {
|
|
124
|
+
try {
|
|
125
|
+
const agent = await loadAgent(agentDirPath);
|
|
126
|
+
console.log(` Model: ${agent.manifest.config.model}`);
|
|
127
|
+
console.log(` Tools: ${Object.keys(agent.manifest.tools).length}`);
|
|
128
|
+
console.log();
|
|
129
|
+
} catch {
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const server = createServer(async (req, res) => {
|
|
133
|
+
if (req.method === "POST" && req.url === "/") {
|
|
134
|
+
let body = "";
|
|
135
|
+
for await (const chunk of req) body += chunk;
|
|
136
|
+
try {
|
|
137
|
+
const { message, stream } = JSON.parse(body);
|
|
138
|
+
if (stream) {
|
|
139
|
+
res.writeHead(200, {
|
|
140
|
+
"Content-Type": "application/x-ndjson",
|
|
141
|
+
"Cache-Control": "no-cache",
|
|
142
|
+
Connection: "keep-alive"
|
|
143
|
+
});
|
|
144
|
+
for await (const event of streamAgent(agentDirPath, message)) {
|
|
145
|
+
res.write(JSON.stringify(event) + "\n");
|
|
146
|
+
}
|
|
147
|
+
res.end();
|
|
148
|
+
} else {
|
|
149
|
+
res.writeHead(200, { "Content-Type": "application/json" });
|
|
150
|
+
for await (const _event of streamAgent(agentDirPath, message)) {
|
|
151
|
+
}
|
|
152
|
+
res.end(JSON.stringify({ status: "ok" }));
|
|
153
|
+
}
|
|
154
|
+
} catch (err) {
|
|
155
|
+
res.writeHead(500, { "Content-Type": "application/json" });
|
|
156
|
+
res.end(JSON.stringify({ error: String(err) }));
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
res.writeHead(404);
|
|
160
|
+
res.end("Not found");
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
server.listen(port, () => {
|
|
164
|
+
console.log(` Listening on http://localhost:${port}`);
|
|
165
|
+
console.log(` POST / with { "message": "hello" }`);
|
|
166
|
+
console.log();
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// src/cli/build.ts
|
|
171
|
+
import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync2, existsSync as existsSync2 } from "fs";
|
|
172
|
+
import { resolve as resolve3, join as join2 } from "path";
|
|
173
|
+
async function buildCommand(options) {
|
|
174
|
+
const agentDirPath = resolve3(process.cwd(), options.agentDir);
|
|
175
|
+
const outDir = resolve3(process.cwd(), options.outDir);
|
|
176
|
+
console.log(`
|
|
177
|
+
Building agent...
|
|
178
|
+
`);
|
|
179
|
+
if (!existsSync2(agentDirPath)) {
|
|
180
|
+
console.error(` Agent directory not found: ${agentDirPath}`);
|
|
181
|
+
process.exit(1);
|
|
182
|
+
}
|
|
183
|
+
const { agent: discovered, diagnostics } = discoverAgent(agentDirPath);
|
|
184
|
+
if (diagnostics.some((d) => d.severity === "error")) {
|
|
185
|
+
for (const d of diagnostics) {
|
|
186
|
+
console.error(` \u2716 ${d.code}: ${d.message}`);
|
|
187
|
+
}
|
|
188
|
+
process.exit(1);
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
const agent = await loadAgent(agentDirPath);
|
|
192
|
+
mkdirSync2(outDir, { recursive: true });
|
|
193
|
+
const manifest = {
|
|
194
|
+
config: agent.manifest.config,
|
|
195
|
+
instructions: agent.manifest.instructions,
|
|
196
|
+
tools: Object.keys(agent.manifest.tools),
|
|
197
|
+
skills: Object.keys(agent.manifest.skills),
|
|
198
|
+
hooks: Object.keys(agent.manifest.hooks),
|
|
199
|
+
channels: Object.keys(agent.manifest.channels),
|
|
200
|
+
connections: Object.keys(agent.manifest.connections),
|
|
201
|
+
schedules: Object.keys(agent.manifest.schedules),
|
|
202
|
+
subagents: Object.fromEntries(
|
|
203
|
+
Object.entries(agent.manifest.subagents).map(([id, sub]) => [
|
|
204
|
+
id,
|
|
205
|
+
{ description: sub.config.description, tools: Object.keys(sub.tools) }
|
|
206
|
+
])
|
|
207
|
+
),
|
|
208
|
+
discovered: {
|
|
209
|
+
tools: discovered.tools.map((t) => t.name),
|
|
210
|
+
skills: discovered.skills.map((s) => s.name),
|
|
211
|
+
hooks: discovered.hooks.map((h) => h.name),
|
|
212
|
+
channels: discovered.channels.map((c) => c.name),
|
|
213
|
+
connections: discovered.connections.map((c) => c.name),
|
|
214
|
+
schedules: discovered.schedules.map((s) => s.name),
|
|
215
|
+
subagents: discovered.subagents.map((s) => s.id)
|
|
216
|
+
},
|
|
217
|
+
session: agent.manifest.session,
|
|
218
|
+
policy: agent.manifest.policy
|
|
219
|
+
};
|
|
220
|
+
writeFileSync2(
|
|
221
|
+
join2(outDir, "manifest.json"),
|
|
222
|
+
JSON.stringify(manifest, null, 2)
|
|
223
|
+
);
|
|
224
|
+
console.log(` Written to ${outDir}/manifest.json`);
|
|
225
|
+
console.log(` Tools: ${manifest.tools.length}`);
|
|
226
|
+
console.log(` Skills: ${manifest.skills.length}`);
|
|
227
|
+
console.log(` Channels: ${manifest.channels.length}`);
|
|
228
|
+
console.log(` Connections: ${manifest.connections.length}`);
|
|
229
|
+
console.log(` Schedules: ${manifest.schedules.length}`);
|
|
230
|
+
console.log(` Subagents: ${Object.keys(manifest.subagents).length}`);
|
|
231
|
+
console.log(`
|
|
232
|
+
Done.
|
|
233
|
+
`);
|
|
234
|
+
} catch (err) {
|
|
235
|
+
console.error(` Build failed:`, err);
|
|
236
|
+
process.exit(1);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// src/cli/index.ts
|
|
241
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
242
|
+
import { resolve as resolve4, dirname as dirname2 } from "path";
|
|
243
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
244
|
+
var __dirname2 = dirname2(fileURLToPath2(import.meta.url));
|
|
245
|
+
var pkgPath = resolve4(__dirname2, "../../package.json");
|
|
246
|
+
var version = "0.1.0";
|
|
13
247
|
try {
|
|
14
|
-
|
|
15
|
-
|
|
248
|
+
const pkg = JSON.parse(readFileSync2(pkgPath, "utf-8"));
|
|
249
|
+
version = pkg.version;
|
|
250
|
+
} catch {
|
|
16
251
|
}
|
|
17
|
-
catch { }
|
|
18
252
|
showBanner();
|
|
19
|
-
|
|
20
|
-
program
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
program
|
|
25
|
-
.command("init")
|
|
26
|
-
.description("Scaffold a new agent project")
|
|
27
|
-
.argument("[name]", "Project directory name")
|
|
28
|
-
.option("--template <name>", "Template to use (default, agent-only)", "default")
|
|
29
|
-
.action(initCommand);
|
|
30
|
-
program
|
|
31
|
-
.command("dev")
|
|
32
|
-
.description("Run the agent locally")
|
|
33
|
-
.option("-p, --port <port>", "Port to listen on", "3000")
|
|
34
|
-
.option("--agent-dir <path>", "Path to agent directory", "agent")
|
|
35
|
-
.action(devCommand);
|
|
36
|
-
program
|
|
37
|
-
.command("build")
|
|
38
|
-
.description("Compile the agent for production")
|
|
39
|
-
.option("--agent-dir <path>", "Path to agent directory", "agent")
|
|
40
|
-
.option("--out-dir <path>", "Output directory", ".eline")
|
|
41
|
-
.action(buildCommand);
|
|
253
|
+
var program = new Command();
|
|
254
|
+
program.name("arcie").description("Arcie \u2014 the electronic line, build agents at the speed of light").version(version);
|
|
255
|
+
program.command("init").description("Scaffold a new agent project").argument("[name]", "Project directory name").option("--template <name>", "Template to use (default, agent-only)", "default").action(initCommand);
|
|
256
|
+
program.command("dev").description("Run the agent locally").option("-p, --port <port>", "Port to listen on", "3000").option("--agent-dir <path>", "Path to agent directory", "agent").action(devCommand);
|
|
257
|
+
program.command("build").description("Compile the agent for production").option("--agent-dir <path>", "Path to agent directory", "agent").option("--out-dir <path>", "Output directory", ".arcie").action(buildCommand);
|
|
42
258
|
program.parse(process.argv);
|
|
43
259
|
//# sourceMappingURL=index.js.map
|