@akanjs/cli 3.0.0-beta.9 → 3.0.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/.build-stamp +1 -1
- package/CodeAgent-2vmp9qe0.js +9 -0
- package/CodeAgentRpcHost-p7h6n2hp.js +7 -0
- package/CodeAgentRpcListener-7p7z5dd7.js +97 -0
- package/CodeTui-5ed6bg2a.js +1457 -0
- package/README.ko.md +83 -28
- package/README.md +70 -27
- package/TunnelShare-cwh9ezsm.js +9 -0
- package/{agent.command-0q17pnrs.js → agent.command-gn73rhe7.js} +8 -9
- package/akanCode.js +102 -0
- package/application.command-e968t0hw.js +246 -0
- package/{applicationBuildRunner-kxwbssgn.js → applicationBuildRunner-64taxseg.js} +121 -77
- package/buildBatch.proc.js +120 -32
- package/cloud.command-0jm301rr.js +95 -0
- package/cloud.script-nemnzjpv.js +20 -0
- package/code.command-18kcm7hq.js +154 -0
- package/commandManifest.json +1 -1
- package/consoleToStderr-h5bryj94.js +7 -0
- package/context.command-trd9bn18.js +48 -0
- package/context.runner-y5hwh673.js +21 -0
- package/{dependencyScanner-shs82ynp.js → dependencyScanner-06z2dmrr.js} +2 -2
- package/{devTui-m1atgkc9.js → devTui-q7k7bakd.js} +122 -40
- package/fileSys-wzzrntkw.js +9 -0
- package/guideline.command-bdmdn2de.js +42 -0
- package/guidelines/agentRule/agentRule.instruction.md +154 -26
- package/guidelines/conventions/conventions.instruction.md +134 -48
- package/guidelines/mcpRule/mcpRule.instruction.md +7 -5
- package/guidelines/queryRule/queryRule.instruction.md +21 -7
- package/guidelines/runtimeRule/runtimeRule.instruction.md +291 -6
- package/guidelines/ssrRule/ssrRule.instruction.md +4 -2
- package/guidelines/transportRule/transportRule.instruction.md +10 -8
- package/guidelines/workspaceOnboarding/workspaceOnboarding.instruction.md +20 -0
- package/guidelines/workspaceRecipes/workspaceRecipes.instruction.md +66 -3
- package/incrementalBuilder.proc.js +564 -109
- package/index-0wpybxtr.js +2729 -0
- package/{index-kcxmv48c.js → index-2ahj896a.js} +45 -79
- package/index-2wc41k5w.js +49 -0
- package/index-3hx1z96c.js +87 -0
- package/{index-2tv3fdx4.js → index-3w94e7n3.js} +1228 -1458
- package/{index-hwkygn9s.js → index-48k96p55.js} +325 -36
- package/index-4npz05nm.js +187 -0
- package/{index-q0y2jq9j.js → index-52w0fvh8.js} +21 -4
- package/index-6he6gvfg.js +4300 -0
- package/index-7md2g9vw.js +6 -0
- package/{index-04bk599g.js → index-93j60em0.js} +10 -17
- package/index-94s080qm.js +266 -0
- package/index-9dp031by.js +12 -0
- package/{index-ktb5njgy.js → index-9z771ptz.js} +49 -99
- package/{index-y6n8nmny.js → index-abxpehf8.js} +75 -203
- package/{index-3d9y066c.js → index-bjwxs904.js} +9 -8
- package/{index-9077wzd2.js → index-by9pxkr0.js} +43 -26
- package/index-c6eggbee.js +123 -0
- package/index-d2242ksy.js +99 -0
- package/index-drehwpdt.js +1119 -0
- package/{index-92zztqy1.js → index-dy0jx9ay.js} +2 -17
- package/{index-ffvk10zz.js → index-f3c78nd6.js} +107 -241
- package/index-gbggbqcp.js +1058 -0
- package/{index-by5gpp8x.js → index-hj6w4ka1.js} +2 -1
- package/index-hsmtysz4.js +53 -0
- package/{index-j9yhg404.js → index-jmrn54tt.js} +4 -7
- package/{index-a64esmtb.js → index-kcdj1z5v.js} +523 -1022
- package/{index-d43r08tf.js → index-kqabytj7.js} +77 -150
- package/{index-vyvre9en.js → index-mbxbhay5.js} +6 -2
- package/{index-vxtad5bd.js → index-mgxpx3f2.js} +5 -8
- package/index-p6pbz9n5.js +25 -0
- package/{index-sj5vxr8f.js → index-p993efkq.js} +981 -897
- package/{index-2xp0kfkt.js → index-pmhqttv3.js} +37 -25
- package/index-tqm7jjcn.js +700 -0
- package/{index-0g7r8xz3.js → index-vpj42xwt.js} +114 -232
- package/index-wa5jbxj1.js +760 -0
- package/{index-k2j1hc4r.js → index-wprnsjms.js} +12 -12
- package/{index-gyd220p2.js → index-y3mphr1m.js} +554 -577
- package/index-yg7jhz8x.js +69 -0
- package/{index-h7yw2z9n.js → index-zzvvc845.js} +8 -14
- package/index.js +23 -22
- package/{library.command-qzzbj6d8.js → library.command-9h749a1x.js} +4 -5
- package/{localRegistry.command-vyrgg4xw.js → localRegistry.command-2bqqhxyz.js} +23 -43
- package/{module.command-rq5hq3ax.js → module.command-nv8nzgft.js} +8 -12
- package/{package.command-d9hd6v9n.js → package.command-mq4bggp6.js} +6 -7
- package/package.json +15 -7
- package/{page.command-126d56te.js → page.command-j639n707.js} +4 -5
- package/{primitive.command-taxd1538.js → primitive.command-kz6849th.js} +9 -23
- package/prompter-76k56b37.js +8 -0
- package/{quality.command-6gsna0a3.js → quality.command-4hyabwkb.js} +205 -377
- package/{recipeScanner-fpagtgc1.js → recipeScanner-4b69ybe0.js} +1 -1
- package/{repair.command-tq2dgy72.js → repair.command-a9awpbqr.js} +11 -35
- package/{routeSourceValidator-apyqw7wk.js → routeSourceValidator-7ycnfz0e.js} +0 -6
- package/{scalar.command-3bcmrrkv.js → scalar.command-ma4fpm9m.js} +7 -11
- package/skills/akan-code/SKILL.md +130 -0
- package/skills/akan-debug/SKILL.md +42 -0
- package/skills/akan-deps/SKILL.md +50 -0
- package/skills/akan-err/SKILL.md +39 -0
- package/skills/akan-module/SKILL.md +45 -0
- package/skills/akan-scaffold/SKILL.md +76 -0
- package/skills/akan-scalar/SKILL.md +52 -0
- package/skills/akan-service/SKILL.md +34 -0
- package/skills/akan-store/SKILL.md +67 -0
- package/skills/akan-ui/SKILL.md +63 -0
- package/skills/akan-validate/SKILL.md +44 -0
- package/{subspace.command-eddzqpx3.js → subspace.command-3k2pmrs4.js} +53 -62
- package/templates/__scalar/__model__/__model__.abstract.md.template +8 -0
- package/templates/app/page/_index.tsx +257 -258
- package/templates/app/page/_layout.tsx +5 -1
- package/templates/app/page/_overrides.tsx +12 -0
- package/templates/app/page/styles.css.template +316 -14
- package/templates/app/public/apple-touch-icon.png +0 -0
- package/templates/app/public/favicon.ico +0 -0
- package/templates/app/public/jelly/cloud.webp +0 -0
- package/templates/app/public/jelly/comet.webp +0 -0
- package/templates/app/public/jelly/moon.webp +0 -0
- package/templates/app/public/jelly/planet.webp +0 -0
- package/templates/app/public/jelly/rocket.webp +0 -0
- package/templates/app/public/jelly/star.webp +0 -0
- package/templates/app/public/jelly/sugar.webp +0 -0
- package/templates/app/public/logo.png +0 -0
- package/templates/app/ui/Recipe/index.ts +9 -0
- package/templates/app/ui/Recipe/jellyButton.ts +63 -0
- package/templates/appSample/lib/__scalar/workHistory/workHistory.abstract.ts +8 -39
- package/templates/appSample/lib/_noti/noti.abstract.ts +6 -29
- package/templates/appSample/lib/task/Task.Unit.tsx +1 -1
- package/templates/appSample/lib/task/Task.Util.tsx +10 -13
- package/templates/appSample/lib/task/Task.View.tsx +2 -2
- package/templates/appSample/lib/task/Task.Zone.tsx +5 -2
- package/templates/appSample/lib/task/task.abstract.ts +12 -32
- package/templates/appSample/lib/task/task.signal.spec.ts +1 -15
- package/templates/appSample/lib/task/task.signal.test.ts +15 -1
- package/templates/appSample/lib/task/task.signal.ts +10 -8
- package/templates/appSample/page/task/[taskId]/_index.tsx +6 -6
- package/templates/appSample/page/task/[taskId]/edit.tsx +5 -4
- package/templates/appSample/page/task/_index.tsx +4 -3
- package/templates/appSample/page/task/_layout.tsx +1 -1
- package/templates/appSample/page/task/new.tsx +5 -4
- package/templates/appSample/srvkit/{AuthGuard.ts → guards.ts} +7 -4
- package/templates/appSample/srvkit/{SessionInternalArg.ts → internalArgs.ts} +6 -4
- package/templates/appSample/ui/GlobalLoading.tsx +2 -1
- package/templates/appSample/ui/QuantityControl.tsx +3 -3
- package/templates/client.ts +7 -30
- package/templates/crudPages/[__model__Id]/edit/page.tsx +2 -1
- package/templates/crudPages/[__model__Id]/page.tsx +2 -1
- package/templates/crudPages/new/page.tsx +2 -1
- package/templates/crudPages/page.tsx +2 -1
- package/templates/crudSinglePage/page.tsx +2 -1
- package/templates/lib/__lib/lib.dictionary.ts +0 -2
- package/templates/lib/__lib/lib.document.ts +0 -2
- package/templates/lib/sig.ts +8 -30
- package/templates/localDev/docker-compose.yaml.template +3 -14
- package/templates/module/__model__.signal.ts +12 -4
- package/templates/pkgRoot/tsconfig.json.template +2 -7
- package/templates/server.ts +1 -3
- package/templates/service/__model__.abstract.md.template +8 -0
- package/templates/workspaceRoot/.gitignore.template +0 -1
- package/templates/workspaceRoot/AGENTS.md.template +6 -0
- package/templates/workspaceRoot/package.json.template +1 -3
- package/tunnel.command-xwr46b66.js +129 -0
- package/{typeChecker-3xgrzc2v.js → typeChecker-px49mezc.js} +1 -1
- package/typecheck.proc.js +1 -1
- package/workflow.command-t7wqe4h7.js +79 -0
- package/{workspace.command-06wvstgr.js → workspace.command-4derhzrh.js} +79 -109
- package/abstractCompactor-gmkc0z8j.js +0 -102
- package/application.command-18y0s485.js +0 -204
- package/applicationReleasePackager-4yasxwv9.js +0 -244
- package/capacitorApp-36rbr858.js +0 -12
- package/cloud.command-av97ndh6.js +0 -94
- package/cloud.script-cm11xjdz.js +0 -20
- package/context.command-5v37ef3n.js +0 -81
- package/devTuiView-0hc2emhe.js +0 -9
- package/getDirname-dr3jz1xg.js +0 -7
- package/guideline.command-4pz9g1rt.js +0 -360
- package/guidelines/agentRule/agentRule.generate.json +0 -31
- package/guidelines/componentRule/componentRule.generate.json +0 -31
- package/guidelines/conventions/conventions.generate.json +0 -25
- package/guidelines/cssRule/cssRule.generate.json +0 -31
- package/guidelines/docPageRule/docPageRule.generate.json +0 -31
- package/guidelines/docPageRule/docPageRule.instruction.md +0 -25
- package/guidelines/docSyncRule/docSyncRule.generate.json +0 -31
- package/guidelines/docSyncRule/docSyncRule.instruction.md +0 -25
- package/guidelines/enumConstant/enumConstant.generate.json +0 -31
- package/guidelines/enumConstant/enumConstant.instruction.md +0 -28
- package/guidelines/fieldRule/fieldRule.generate.json +0 -31
- package/guidelines/framework/framework.generate.json +0 -32
- package/guidelines/mcpRule/mcpRule.generate.json +0 -35
- package/guidelines/modelConstant/modelConstant.generate.json +0 -32
- package/guidelines/modelDictionary/modelDictionary.generate.json +0 -32
- package/guidelines/modelDocument/modelDocument.generate.json +0 -31
- package/guidelines/modelService/modelService.generate.json +0 -31
- package/guidelines/modelSignal/modelSignal.generate.json +0 -31
- package/guidelines/modelStore/modelStore.generate.json +0 -31
- package/guidelines/modelTemplate/modelTemplate.generate.json +0 -31
- package/guidelines/modelUnit/modelUnit.generate.json +0 -31
- package/guidelines/modelUtil/modelUtil.generate.json +0 -31
- package/guidelines/modelView/modelView.generate.json +0 -31
- package/guidelines/modelZone/modelZone.generate.json +0 -31
- package/guidelines/moduleCodegen/moduleCodegen.generate.json +0 -31
- package/guidelines/moduleCodegen/moduleCodegen.instruction.md +0 -28
- package/guidelines/moduleOverview/moduleOverview.generate.json +0 -31
- package/guidelines/queryRule/queryRule.generate.json +0 -31
- package/guidelines/recipeRule/recipeRule.generate.json +0 -31
- package/guidelines/runtimeRule/runtimeRule.generate.json +0 -25
- package/guidelines/scalarConstant/scalarConstant.generate.json +0 -32
- package/guidelines/scalarDictionary/scalarDictionary.generate.json +0 -32
- package/guidelines/scalarModule/scalarModule.generate.json +0 -31
- package/guidelines/sharedUiUsage/sharedUiUsage.generate.json +0 -31
- package/guidelines/sharedUiUsage/sharedUiUsage.instruction.md +0 -25
- package/guidelines/ssrRule/ssrRule.generate.json +0 -31
- package/guidelines/transportRule/transportRule.generate.json +0 -31
- package/guidelines/utilUiUsage/utilUiUsage.generate.json +0 -31
- package/guidelines/utilUiUsage/utilUiUsage.instruction.md +0 -25
- package/guidelines/workspaceOnboarding/workspaceOnboarding.generate.json +0 -24
- package/guidelines/workspaceRecipes/workspaceRecipes.generate.json +0 -33
- package/index-47pj3aee.js +0 -76
- package/index-5ystnsd5.js +0 -841
- package/index-6wwzs1bc.js +0 -7
- package/index-a17x49vg.js +0 -229
- package/index-m0xccmmm.js +0 -228
- package/index-meh558jy.js +0 -65
- package/index-rtxxan88.js +0 -471
- package/index-te54x9zm.js +0 -338
- package/index-w8kmx1b6.js +0 -2176
- package/index-wt7qrtd4.js +0 -1516
- package/templates/__scalar/__model__/__model__.abstract.md +0 -28
- package/templates/module/__model__.abstract.md +0 -28
- package/templates/service/__model__.abstract.md +0 -28
- package/templates/workspaceRoot/patches/react-dom@19.2.7.patch.template +0 -62
- package/workflow.command-gtdnzvbz.js +0 -108
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// pkgs/@akanjs/devkit/codeAgent/agent/akanCodeModel.ts
|
|
3
|
+
var akanCodeDefaultModel2 = { provider: "deepseek", id: "deepseek-flash" };
|
|
4
|
+
var catalogueMissesImages = new Set(["deepseek/deepseek-v4-flash"]);
|
|
5
|
+
var correctInputs = (model) => {
|
|
6
|
+
if (!model || model.input.includes("image"))
|
|
7
|
+
return model;
|
|
8
|
+
if (!catalogueMissesImages.has(`${model.provider}/${model.id}`))
|
|
9
|
+
return model;
|
|
10
|
+
return { ...model, input: [...model.input, "image"] };
|
|
11
|
+
};
|
|
12
|
+
var akanCodeModel2 = async (runtime, ref) => {
|
|
13
|
+
if (ref) {
|
|
14
|
+
const requested = runtime.getModel(ref.provider, ref.id);
|
|
15
|
+
if (!requested)
|
|
16
|
+
throw new Error(`Unknown model: ${ref.provider}/${ref.id}`);
|
|
17
|
+
if (!runtime.hasConfiguredAuth(ref.provider))
|
|
18
|
+
throw new Error(`No API key configured for ${ref.provider}. Set ${ref.provider.toUpperCase()}_API_KEY.`);
|
|
19
|
+
return correctInputs(requested);
|
|
20
|
+
}
|
|
21
|
+
const fallback = runtime.getModel(akanCodeDefaultModel2.provider, akanCodeDefaultModel2.id);
|
|
22
|
+
if (fallback && runtime.hasConfiguredAuth(fallback.provider))
|
|
23
|
+
return correctInputs(fallback);
|
|
24
|
+
return correctInputs((await runtime.getAvailable())[0]);
|
|
25
|
+
};
|
|
26
|
+
var akanCodeModelSupportsImages2 = (model) => !!model?.input.includes("image");
|
|
27
|
+
var akanCodeModelWarnings2 = (model, compactionFloor) => {
|
|
28
|
+
if (!model)
|
|
29
|
+
return [];
|
|
30
|
+
if (model.contextWindow >= compactionFloor)
|
|
31
|
+
return [];
|
|
32
|
+
return [
|
|
33
|
+
`${model.provider}/${model.id} declares a ${model.contextWindow}-token context window, below the ${compactionFloor} the compaction policy needs, so every turn will compact immediately. Check the model entry in ~/.akan/code/models.json.`
|
|
34
|
+
];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// pkgs/@akanjs/devkit/codeAgent/agent/CodeAgentStreamPrinter.ts
|
|
38
|
+
import { codeAgentEventLabel } from "akanjs/common";
|
|
39
|
+
import chalk from "chalk";
|
|
40
|
+
|
|
41
|
+
class CodeAgentStreamPrinter2 {
|
|
42
|
+
#options;
|
|
43
|
+
#write;
|
|
44
|
+
#streaming = false;
|
|
45
|
+
constructor(options = {}) {
|
|
46
|
+
this.#options = options;
|
|
47
|
+
this.#write = options.write ?? ((text) => process.stdout.write(text));
|
|
48
|
+
}
|
|
49
|
+
print(event) {
|
|
50
|
+
if (this.#options.json)
|
|
51
|
+
return this.#write(`${JSON.stringify(event)}
|
|
52
|
+
`);
|
|
53
|
+
switch (event.type) {
|
|
54
|
+
case "text_delta":
|
|
55
|
+
this.#streaming = true;
|
|
56
|
+
return this.#write(event.text);
|
|
57
|
+
case "thinking_delta":
|
|
58
|
+
if (!this.#options.thinking)
|
|
59
|
+
return;
|
|
60
|
+
this.#streaming = true;
|
|
61
|
+
return this.#write(chalk.dim(event.text));
|
|
62
|
+
case "tool_start":
|
|
63
|
+
return this.#line(chalk.cyan(`\u2192 ${event.tool.title}`));
|
|
64
|
+
case "tool_end":
|
|
65
|
+
return this.#line(CodeAgentStreamPrinter2.#toolEnd(event));
|
|
66
|
+
case "session":
|
|
67
|
+
return this.#line(chalk.dim(codeAgentEventLabel(event)));
|
|
68
|
+
case "turn_end":
|
|
69
|
+
if (event.stopReason === "truncated")
|
|
70
|
+
return this.#line(chalk.yellow(codeAgentEventLabel(event)));
|
|
71
|
+
return;
|
|
72
|
+
case "message":
|
|
73
|
+
case "tool_progress":
|
|
74
|
+
case "turn_start":
|
|
75
|
+
case "idle":
|
|
76
|
+
case "queue":
|
|
77
|
+
case "context":
|
|
78
|
+
case "subagent":
|
|
79
|
+
return;
|
|
80
|
+
case "question":
|
|
81
|
+
return this.#line(chalk.yellow(`? ${event.question.prompt}`));
|
|
82
|
+
case "approval":
|
|
83
|
+
return this.#line(chalk.yellow(`approve? ${event.request.summary}`));
|
|
84
|
+
case "notice":
|
|
85
|
+
return this.#line(CodeAgentStreamPrinter2.#notice(event.level, event.message));
|
|
86
|
+
case "error":
|
|
87
|
+
return this.#line(chalk.red(`error: ${event.message}`));
|
|
88
|
+
default:
|
|
89
|
+
return this.#line(chalk.dim(codeAgentEventLabel(event)));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
finish() {
|
|
93
|
+
if (this.#streaming)
|
|
94
|
+
this.#write(`
|
|
95
|
+
`);
|
|
96
|
+
this.#streaming = false;
|
|
97
|
+
}
|
|
98
|
+
#line(text) {
|
|
99
|
+
if (this.#streaming)
|
|
100
|
+
this.#write(`
|
|
101
|
+
`);
|
|
102
|
+
this.#streaming = false;
|
|
103
|
+
this.#write(`${text}
|
|
104
|
+
`);
|
|
105
|
+
}
|
|
106
|
+
static #toolEnd(event) {
|
|
107
|
+
if (event.outcome === "ok")
|
|
108
|
+
return chalk.green(`\u2713 ${event.tool.title}`);
|
|
109
|
+
if (event.outcome === "blocked")
|
|
110
|
+
return chalk.yellow(`\u29B8 ${event.tool.title} \u2014 ${event.output}`);
|
|
111
|
+
return chalk.red(`\u2717 ${event.tool.title} \u2014 ${event.output.split(`
|
|
112
|
+
`)[0] ?? ""}`);
|
|
113
|
+
}
|
|
114
|
+
static #notice(level, message) {
|
|
115
|
+
if (level === "error")
|
|
116
|
+
return chalk.red(message);
|
|
117
|
+
if (level === "warning")
|
|
118
|
+
return chalk.yellow(message);
|
|
119
|
+
return chalk.dim(message);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export { akanCodeDefaultModel2, akanCodeModel2, akanCodeModelSupportsImages2, akanCodeModelWarnings2, CodeAgentStreamPrinter2 };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// pkgs/@akanjs/devkit/codeAgent/agent/CodeAgentRpcHost.ts
|
|
3
|
+
class CodeAgentRpcHost2 {
|
|
4
|
+
#agent;
|
|
5
|
+
#write;
|
|
6
|
+
#buffer = "";
|
|
7
|
+
#started = false;
|
|
8
|
+
#resolveShutdown = () => {};
|
|
9
|
+
shutdown = new Promise((resolve) => {
|
|
10
|
+
this.#resolveShutdown = resolve;
|
|
11
|
+
});
|
|
12
|
+
constructor(agent, write = (line) => process.stdout.write(line)) {
|
|
13
|
+
this.#agent = agent;
|
|
14
|
+
this.#write = write;
|
|
15
|
+
}
|
|
16
|
+
async serve(input = process.stdin) {
|
|
17
|
+
this.start();
|
|
18
|
+
const decoder = new TextDecoder;
|
|
19
|
+
for await (const chunk of input)
|
|
20
|
+
await this.feed(decoder.decode(chunk, { stream: true }));
|
|
21
|
+
await this.#agent.abort().catch(() => {});
|
|
22
|
+
}
|
|
23
|
+
start() {
|
|
24
|
+
if (this.#started)
|
|
25
|
+
return;
|
|
26
|
+
this.#started = true;
|
|
27
|
+
this.#agent.on((event) => this.#emit(event));
|
|
28
|
+
this.#agent.announce();
|
|
29
|
+
}
|
|
30
|
+
attach(write) {
|
|
31
|
+
this.#write = write;
|
|
32
|
+
this.#buffer = "";
|
|
33
|
+
}
|
|
34
|
+
async feed(text) {
|
|
35
|
+
this.#buffer += text;
|
|
36
|
+
let index = this.#buffer.indexOf(`
|
|
37
|
+
`);
|
|
38
|
+
while (index >= 0) {
|
|
39
|
+
const line = this.#buffer.slice(0, index).trim();
|
|
40
|
+
this.#buffer = this.#buffer.slice(index + 1);
|
|
41
|
+
if (line)
|
|
42
|
+
await this.#handle(line);
|
|
43
|
+
index = this.#buffer.indexOf(`
|
|
44
|
+
`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async#handle(line) {
|
|
48
|
+
let request;
|
|
49
|
+
try {
|
|
50
|
+
request = JSON.parse(line);
|
|
51
|
+
} catch {
|
|
52
|
+
return this.#emit({ type: "error", message: "malformed command frame", fatal: false, seq: -1 });
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
this.#reply({ type: "reply", id: request.id, ok: true, data: await this.#run(request.command) });
|
|
56
|
+
} catch (error) {
|
|
57
|
+
this.#reply({ type: "reply", id: request.id, ok: false, error: String(error) });
|
|
58
|
+
}
|
|
59
|
+
if (request.command?.type === "shutdown")
|
|
60
|
+
this.#resolveShutdown();
|
|
61
|
+
}
|
|
62
|
+
async#run(command) {
|
|
63
|
+
switch (command.type) {
|
|
64
|
+
case "prompt":
|
|
65
|
+
this.#agent.prompt(command.message, command.images);
|
|
66
|
+
return { accepted: true };
|
|
67
|
+
case "answer":
|
|
68
|
+
return { handled: await this.#agent.answer(command.questionId, command.answer) };
|
|
69
|
+
case "approve":
|
|
70
|
+
return { handled: await this.#agent.approve(command.approvalId, command.approved) };
|
|
71
|
+
case "abort":
|
|
72
|
+
await this.#agent.abort();
|
|
73
|
+
return { aborted: true };
|
|
74
|
+
case "compact":
|
|
75
|
+
await this.#agent.compact(command.instructions);
|
|
76
|
+
return { compacted: true };
|
|
77
|
+
case "set_model":
|
|
78
|
+
await this.#agent.setModel({ provider: command.provider, id: command.modelId });
|
|
79
|
+
return await this.#agent.state();
|
|
80
|
+
case "get_state":
|
|
81
|
+
return await this.#agent.state(command.sinceSeq === undefined ? {} : { sinceSeq: command.sinceSeq });
|
|
82
|
+
case "shutdown":
|
|
83
|
+
this.#agent.dispose();
|
|
84
|
+
return { shutdown: true };
|
|
85
|
+
default:
|
|
86
|
+
throw new Error(`Unsupported command: ${command.type}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
#emit(event) {
|
|
90
|
+
this.#write?.(`${JSON.stringify({ type: "event", event })}
|
|
91
|
+
`);
|
|
92
|
+
}
|
|
93
|
+
#reply(reply) {
|
|
94
|
+
this.#write?.(`${JSON.stringify(reply)}
|
|
95
|
+
`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export { CodeAgentRpcHost2 };
|