@chances-ai/cli 2.0.0 → 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/dist/boot/create-app.d.ts +3 -1
- package/dist/boot/create-app.d.ts.map +1 -1
- package/dist/boot/create-app.js +4 -3
- package/dist/boot/create-app.js.map +1 -1
- package/dist/boot/load-runtime.d.ts +5 -1
- package/dist/boot/load-runtime.d.ts.map +1 -1
- package/dist/boot/load-runtime.js +17 -2
- package/dist/boot/load-runtime.js.map +1 -1
- package/dist/commands/chat.d.ts +9 -1
- package/dist/commands/chat.d.ts.map +1 -1
- package/dist/commands/chat.js +95 -39
- package/dist/commands/chat.js.map +1 -1
- package/dist/commands/prompt.d.ts.map +1 -1
- package/dist/commands/prompt.js +30 -5
- package/dist/commands/prompt.js.map +1 -1
- package/dist/slash/clear.d.ts +13 -0
- package/dist/slash/clear.d.ts.map +1 -0
- package/dist/slash/clear.js +28 -0
- package/dist/slash/clear.js.map +1 -0
- package/dist/slash/compact.d.ts +4 -0
- package/dist/slash/compact.d.ts.map +1 -0
- package/dist/slash/compact.js +68 -0
- package/dist/slash/compact.js.map +1 -0
- package/dist/slash/help.d.ts +13 -0
- package/dist/slash/help.d.ts.map +1 -0
- package/dist/slash/help.js +34 -0
- package/dist/slash/help.js.map +1 -0
- package/dist/slash/index.d.ts +22 -0
- package/dist/slash/index.d.ts.map +1 -0
- package/dist/slash/index.js +20 -0
- package/dist/slash/index.js.map +1 -0
- package/dist/slash/logout.d.ts +15 -0
- package/dist/slash/logout.d.ts.map +1 -0
- package/dist/slash/logout.js +44 -0
- package/dist/slash/logout.js.map +1 -0
- package/dist/slash/model.d.ts +14 -0
- package/dist/slash/model.d.ts.map +1 -0
- package/dist/slash/model.js +87 -0
- package/dist/slash/model.js.map +1 -0
- package/dist/slash/persist.d.ts +16 -0
- package/dist/slash/persist.d.ts.map +1 -0
- package/dist/slash/persist.js +46 -0
- package/dist/slash/persist.js.map +1 -0
- package/dist/slash/provider.d.ts +17 -0
- package/dist/slash/provider.d.ts.map +1 -0
- package/dist/slash/provider.js +98 -0
- package/dist/slash/provider.js.map +1 -0
- package/dist/slash/resume.d.ts +15 -0
- package/dist/slash/resume.d.ts.map +1 -0
- package/dist/slash/resume.js +76 -0
- package/dist/slash/resume.js.map +1 -0
- package/package.json +13 -13
|
@@ -2,7 +2,9 @@ import { AgentEngine } from "@chances-ai/core";
|
|
|
2
2
|
import { type PermissionResolver } from "@chances-ai/tools";
|
|
3
3
|
import type { SessionManager } from "@chances-ai/session";
|
|
4
4
|
import type { AppContext } from "./load-runtime.js";
|
|
5
|
-
/** Wires an AgentEngine for a given session and permission resolver.
|
|
5
|
+
/** Wires an AgentEngine for a given session and permission resolver. Passes
|
|
6
|
+
* the AppContext's `selection` (mutable model preference) through so a later
|
|
7
|
+
* `/model` slash command can mutate it without rebuilding the engine. */
|
|
6
8
|
export declare function buildEngine(ctx: AppContext, session: SessionManager, resolver: PermissionResolver): AgentEngine;
|
|
7
9
|
/** Auto-resolver for non-interactive modes: approve only when --yes was passed. */
|
|
8
10
|
export declare function autoResolver(approve: boolean): PermissionResolver;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-app.d.ts","sourceRoot":"","sources":["../../src/boot/create-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAkB,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD
|
|
1
|
+
{"version":3,"file":"create-app.d.ts","sourceRoot":"","sources":["../../src/boot/create-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAkB,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEpD;;yEAEyE;AACzE,wBAAgB,WAAW,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,kBAAkB,GAAG,WAAW,CAa/G;AAED,mFAAmF;AACnF,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,kBAAkB,CAEjE"}
|
package/dist/boot/create-app.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { AgentEngine } from "@chances-ai/core";
|
|
2
2
|
import { PermissionGate } from "@chances-ai/tools";
|
|
3
|
-
/** Wires an AgentEngine for a given session and permission resolver.
|
|
3
|
+
/** Wires an AgentEngine for a given session and permission resolver. Passes
|
|
4
|
+
* the AppContext's `selection` (mutable model preference) through so a later
|
|
5
|
+
* `/model` slash command can mutate it without rebuilding the engine. */
|
|
4
6
|
export function buildEngine(ctx, session, resolver) {
|
|
5
7
|
const gate = new PermissionGate(ctx.config.permissions, resolver);
|
|
6
8
|
return new AgentEngine({
|
|
@@ -12,8 +14,7 @@ export function buildEngine(ctx, session, resolver) {
|
|
|
12
14
|
memory: ctx.memory,
|
|
13
15
|
plugins: ctx.plugins,
|
|
14
16
|
workspaceRoot: ctx.workspaceRoot,
|
|
15
|
-
|
|
16
|
-
preferredProvider: ctx.config.provider,
|
|
17
|
+
selection: ctx.selection,
|
|
17
18
|
});
|
|
18
19
|
}
|
|
19
20
|
/** Auto-resolver for non-interactive modes: approve only when --yes was passed. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-app.js","sourceRoot":"","sources":["../../src/boot/create-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAA2B,MAAM,mBAAmB,CAAC;AAI5E
|
|
1
|
+
{"version":3,"file":"create-app.js","sourceRoot":"","sources":["../../src/boot/create-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAA2B,MAAM,mBAAmB,CAAC;AAI5E;;yEAEyE;AACzE,MAAM,UAAU,WAAW,CAAC,GAAe,EAAE,OAAuB,EAAE,QAA4B;IAChG,MAAM,IAAI,GAAG,IAAI,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAClE,OAAO,IAAI,WAAW,CAAC;QACrB,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,IAAI;QACJ,OAAO;QACP,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,OAAO,EAAE,GAAG,CAAC,OAAO;QACpB,aAAa,EAAE,GAAG,CAAC,aAAa;QAChC,SAAS,EAAE,GAAG,CAAC,SAAS;KACzB,CAAC,CAAC;AACL,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,YAAY,CAAC,OAAgB;IAC3C,OAAO,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC;AAC7B,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EventBus, FeatureFlags, Logger, type LogLevel } from "@chances-ai/runtime";
|
|
1
|
+
import { EventBus, FeatureFlags, Logger, ModelSelection, type LogLevel } from "@chances-ai/runtime";
|
|
2
2
|
import { AuthStore, type ChancesConfig, type ExternalPluginEntry } from "@chances-ai/config";
|
|
3
3
|
import { ModelRegistry, ModelRouter } from "@chances-ai/ai";
|
|
4
4
|
import { ToolRegistry } from "@chances-ai/tools";
|
|
@@ -18,6 +18,10 @@ export interface AppContext {
|
|
|
18
18
|
telemetry: TelemetrySink;
|
|
19
19
|
plugins: PluginHost | undefined;
|
|
20
20
|
workspaceRoot: string;
|
|
21
|
+
/** Mutable model preference seeded from config; `/model` mutates this so the
|
|
22
|
+
* next turn picks up the choice without rebuilding the engine. Built-in
|
|
23
|
+
* slash commands receive the same instance via closure capture. */
|
|
24
|
+
selection: ModelSelection;
|
|
21
25
|
}
|
|
22
26
|
export interface RuntimeOverrides {
|
|
23
27
|
provider?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-runtime.d.ts","sourceRoot":"","sources":["../../src/boot/load-runtime.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,KAAK,QAAQ,EACd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,SAAS,EAET,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACzB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAEL,aAAa,EACb,WAAW,EAGZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAgB,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAe,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,KAAK,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAGjE,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,QAAQ,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,EAAE,aAAa,CAAC;IACtB,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,EAAE,aAAa,CAAC;IACxB,MAAM,EAAE,WAAW,CAAC;IACpB,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,EAAE,WAAW,CAAC;IACpB,SAAS,EAAE,aAAa,CAAC;IACzB,OAAO,EAAE,UAAU,GAAG,SAAS,CAAC;IAChC,aAAa,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"load-runtime.d.ts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AGyB;AACzB,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,mBAAmB,EAC1B,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,CAAC,CAsBjB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { homedir } from "node:os";
|
|
2
2
|
import { isAbsolute, join, relative, resolve } from "node:path";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
|
-
import { EventBus, FeatureFlags, Logger, } from "@chances-ai/runtime";
|
|
4
|
+
import { EventBus, FeatureFlags, Logger, ModelSelection, } from "@chances-ai/runtime";
|
|
5
5
|
import { AuthStore, loadConfig, } from "@chances-ai/config";
|
|
6
6
|
import { KNOWN_MODELS, ModelRegistry, ModelRouter, buildRegistry, envByProviderFrom, } from "@chances-ai/ai";
|
|
7
7
|
import { ToolRegistry, builtinTools } from "@chances-ai/tools";
|
|
@@ -31,7 +31,22 @@ export async function loadRuntime(overrides = {}) {
|
|
|
31
31
|
const telemetry = new TelemetrySink(config.workspaceRoot);
|
|
32
32
|
telemetry.attach(bus);
|
|
33
33
|
const plugins = await loadPlugins(config, bus, logger, tools);
|
|
34
|
-
|
|
34
|
+
const selection = new ModelSelection({ provider: config.provider, model: config.model });
|
|
35
|
+
return {
|
|
36
|
+
bus,
|
|
37
|
+
logger,
|
|
38
|
+
flags,
|
|
39
|
+
config,
|
|
40
|
+
auth,
|
|
41
|
+
registry,
|
|
42
|
+
router,
|
|
43
|
+
tools,
|
|
44
|
+
memory,
|
|
45
|
+
telemetry,
|
|
46
|
+
plugins,
|
|
47
|
+
workspaceRoot: config.workspaceRoot,
|
|
48
|
+
selection,
|
|
49
|
+
};
|
|
35
50
|
}
|
|
36
51
|
/**
|
|
37
52
|
* Builds and loads the plugin host. Returns `undefined` when no plugin is
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-runtime.js","sourceRoot":"","sources":["../../src/boot/load-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EA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C,MAAM,KAAK,UAAU,EAC/C,CAAC;QACD,MAAM,IAAI,KAAK,CACb,WAAW,KAAK,CAAC,IAAI,MAAM,SAAS,yDAAyD,CAC9F,CAAC;IACJ,CAAC;IACD,OAAO,MAAgB,CAAC;AAC1B,CAAC;AAED;;;0CAG0C;AAC1C,SAAS,gBAAgB,CAAC,IAAY,EAAE,aAAqB;IAC3D,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QACpD,MAAM,GAAG,GAAG,OAAO,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;QACzC,MAAM,GAAG,GAAG,QAAQ,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC;QACzC,IAAI,GAAG,KAAK,EAAE,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1D,MAAM,IAAI,KAAK,CAAC,2CAA2C,IAAI,EAAE,CAAC,CAAC;QACrE,CAAC;QACD,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;IACjC,CAAC;IACD,IAAI,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;IACtD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/commands/chat.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import type { AppContext } from "../boot/load-runtime.js";
|
|
2
2
|
import type { CliCommand } from "./registry.js";
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Interactive Ink chat with respawn-loop semantics. A slash command like
|
|
5
|
+
* `/resume <id>` requests a respawn; the outer loop tears down the current
|
|
6
|
+
* engine + TUI instance and re-enters with the chosen session. `/clear`
|
|
7
|
+
* stays in-session (no respawn) — see slash/clear.ts.
|
|
8
|
+
*
|
|
9
|
+
* One ChatViewModel and one ModalController are recreated per session so
|
|
10
|
+
* scrollback and any in-flight modal cleanly reset on respawn.
|
|
11
|
+
*/
|
|
4
12
|
export declare function runInteractive(ctx: AppContext): Promise<number>;
|
|
5
13
|
export declare const chatCommand: CliCommand;
|
|
6
14
|
//# sourceMappingURL=chat.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/commands/chat.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"chat.d.ts","sourceRoot":"","sources":["../../src/commands/chat.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAIhD;;;;;;;;GAQG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CA6FrE;AAED,eAAO,MAAM,WAAW,EAAE,UAczB,CAAC"}
|
package/dist/commands/chat.js
CHANGED
|
@@ -1,48 +1,104 @@
|
|
|
1
1
|
import { CancellationTokenSource } from "@chances-ai/runtime";
|
|
2
2
|
import { SessionManager, SessionStore } from "@chances-ai/session";
|
|
3
|
-
import { parseSlashInput } from "@chances-ai/plugin-api";
|
|
4
|
-
import { ChatViewModel, renderChat } from "@chances-ai/tui";
|
|
3
|
+
import { parseSlashInput, PluginHost } from "@chances-ai/plugin-api";
|
|
4
|
+
import { ChatViewModel, ModalController, renderChat } from "@chances-ai/tui";
|
|
5
5
|
import { buildEngine } from "../boot/create-app.js";
|
|
6
6
|
import { runPrompt } from "./prompt.js";
|
|
7
|
-
|
|
7
|
+
import { registerBuiltinSlashCommands } from "../slash/index.js";
|
|
8
|
+
/**
|
|
9
|
+
* Interactive Ink chat with respawn-loop semantics. A slash command like
|
|
10
|
+
* `/resume <id>` requests a respawn; the outer loop tears down the current
|
|
11
|
+
* engine + TUI instance and re-enters with the chosen session. `/clear`
|
|
12
|
+
* stays in-session (no respawn) — see slash/clear.ts.
|
|
13
|
+
*
|
|
14
|
+
* One ChatViewModel and one ModalController are recreated per session so
|
|
15
|
+
* scrollback and any in-flight modal cleanly reset on respawn.
|
|
16
|
+
*/
|
|
8
17
|
export async function runInteractive(ctx) {
|
|
9
18
|
const store = new SessionStore(ctx.workspaceRoot);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
19
|
+
let resumeFromId;
|
|
20
|
+
while (true) {
|
|
21
|
+
const session = resumeFromId
|
|
22
|
+
? SessionManager.resume(resumeFromId, store) ?? SessionManager.create("interactive", store)
|
|
23
|
+
: SessionManager.create("interactive", store);
|
|
24
|
+
// Restore session-saved model choice on respawn so `/resume` lands on the
|
|
25
|
+
// model the user was using when they last touched this session.
|
|
26
|
+
const savedChoice = session.modelChoice();
|
|
27
|
+
if (savedChoice)
|
|
28
|
+
ctx.selection.set(savedChoice);
|
|
29
|
+
const vm = new ChatViewModel();
|
|
30
|
+
vm.attach(ctx.bus);
|
|
31
|
+
const modal = new ModalController();
|
|
32
|
+
const engine = buildEngine(ctx, session, vm.requestPermission);
|
|
33
|
+
// Built-in slash commands need their own per-respawn PluginHost so a
|
|
34
|
+
// session swap (re-enter) doesn't carry stale captured deps. External
|
|
35
|
+
// plugin hooks/tools (loaded via config) live on ctx.plugins and are
|
|
36
|
+
// shared across respawns — keep them, layer builtins on top.
|
|
37
|
+
const builtinHost = new PluginHost(ctx.bus, ctx.logger, ctx.tools);
|
|
38
|
+
let respawnRequest = undefined;
|
|
39
|
+
await registerBuiltinSlashCommands(builtinHost, {
|
|
40
|
+
ctx,
|
|
41
|
+
vm,
|
|
42
|
+
session,
|
|
43
|
+
store,
|
|
44
|
+
respawn: (id) => {
|
|
45
|
+
respawnRequest = id;
|
|
46
|
+
// Unmount on the next macrotask so dispatchSlash can return and the
|
|
47
|
+
// caller can append the slash command's output line before teardown.
|
|
48
|
+
setTimeout(() => handle.unmount(), 0);
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
// Snapshot the dispatchable command list for the autocomplete hint —
|
|
52
|
+
// covers builtins + externally-loaded plugin commands. Recomputed per
|
|
53
|
+
// respawn; if a plugin registers a command mid-session the hint won't
|
|
54
|
+
// update until the next respawn, which is fine (plugins shouldn't be
|
|
55
|
+
// hot-swapping their command set).
|
|
56
|
+
const availableSlashCommands = [
|
|
57
|
+
...builtinHost.slashCommands(),
|
|
58
|
+
...(ctx.plugins ? ctx.plugins.slashCommands() : []),
|
|
59
|
+
].map((c) => ({ name: c.name, description: c.description }));
|
|
60
|
+
const handle = renderChat(vm, async (prompt) => {
|
|
61
|
+
const cts = new CancellationTokenSource();
|
|
62
|
+
try {
|
|
63
|
+
await engine.runTurn(prompt, cts.token);
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
ctx.bus.emit({
|
|
67
|
+
type: "error",
|
|
68
|
+
code: "UNKNOWN",
|
|
69
|
+
message: err instanceof Error ? err.message : String(err),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}, async (line) => {
|
|
73
|
+
const { name, args } = parseSlashInput(line);
|
|
74
|
+
if (!name) {
|
|
75
|
+
vm.pushError("Unknown command: /");
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
// Built-in first; external plugins second. Both can register the
|
|
79
|
+
// same name, but built-ins win — keep this dispatch path simple.
|
|
80
|
+
let result = await builtinHost.dispatchSlash(name, args, { openModal: modal.open });
|
|
81
|
+
if (!result.ok && ctx.plugins) {
|
|
82
|
+
result = await ctx.plugins.dispatchSlash(name, args, { openModal: modal.open });
|
|
83
|
+
}
|
|
84
|
+
if (!result.ok) {
|
|
85
|
+
vm.pushError(`Unknown command: /${name}`);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (result.output) {
|
|
89
|
+
if (result.isError)
|
|
90
|
+
vm.pushError(result.output);
|
|
91
|
+
else
|
|
92
|
+
vm.pushInfo(result.output);
|
|
93
|
+
}
|
|
94
|
+
}, modal, availableSlashCommands);
|
|
95
|
+
await handle.waitUntilExit();
|
|
96
|
+
vm.detach();
|
|
97
|
+
await builtinHost.dispose();
|
|
98
|
+
if (respawnRequest === undefined || respawnRequest === "exit")
|
|
99
|
+
return 0;
|
|
100
|
+
resumeFromId = respawnRequest;
|
|
101
|
+
}
|
|
46
102
|
}
|
|
47
103
|
export const chatCommand = {
|
|
48
104
|
name: "chat",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../../src/commands/chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"chat.js","sourceRoot":"","sources":["../../src/commands/chat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EA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I,cAAc,KAAK,SAAS,IAAI,cAAc,KAAK,MAAM;YAAE,OAAO,CAAC,CAAC;QACxE,YAAY,GAAG,cAAc,CAAC;IAChC,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,WAAW,GAAe;IACrC,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE,8DAA8D;IAC3E,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI;QACjB,IAAI,CAAC,GAAG;YAAE,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QAC7D,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC9B,OAAO,SAAS,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QAC5D,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YAC1B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,kFAAkF,CAAC,CAAC;YACzG,OAAO,CAAC,CAAC;QACX,CAAC;QACD,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;CACF,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/commands/prompt.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/commands/prompt.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AAEtD,6DAA6D;AAC7D,wBAAsB,SAAS,CAC7B,GAAG,EAAE,UAAU,EACf,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,YAAY,EACpB,WAAW,EAAE,OAAO,GACnB,OAAO,CAAC,MAAM,CAAC,CAqBjB"}
|
package/dist/commands/prompt.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { CancellationTokenSource, ErrorCode, exitCodeFor } from "@chances-ai/runtime";
|
|
2
|
-
import { SessionManager } from "@chances-ai/session";
|
|
3
|
-
import { parseSlashInput } from "@chances-ai/plugin-api";
|
|
2
|
+
import { SessionManager, SessionStore } from "@chances-ai/session";
|
|
3
|
+
import { parseSlashInput, PluginHost } from "@chances-ai/plugin-api";
|
|
4
|
+
import { ChatViewModel } from "@chances-ai/tui";
|
|
4
5
|
import { autoResolver, buildEngine } from "../boot/create-app.js";
|
|
5
6
|
import { attachJson } from "../modes/json.js";
|
|
6
7
|
import { attachNdjson } from "../modes/ndjson.js";
|
|
7
8
|
import { attachText } from "../modes/text.js";
|
|
9
|
+
import { registerBuiltinSlashCommands } from "../slash/index.js";
|
|
8
10
|
/** Single-shot, non-interactive execution for scripts/CI. */
|
|
9
11
|
export async function runPrompt(ctx, prompt, format, autoApprove) {
|
|
10
12
|
if (prompt.startsWith("/")) {
|
|
@@ -30,10 +32,33 @@ async function runSlashPrompt(ctx, line, format) {
|
|
|
30
32
|
if (!name) {
|
|
31
33
|
return emitSlashError(`Unknown command: /`, format);
|
|
32
34
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
// Stand up a builtin host for this one-shot — same registration that the
|
|
36
|
+
// chat loop uses, but with stubs for vm + respawn that would otherwise be
|
|
37
|
+
// chat-loop-only. Commands that need real chat state (e.g. `/clear`,
|
|
38
|
+
// `/resume`) still register; they degrade silently (or print a meaningful
|
|
39
|
+
// status) in -p mode rather than throwing.
|
|
40
|
+
const builtinHost = new PluginHost(ctx.bus, ctx.logger, ctx.tools);
|
|
41
|
+
const store = new SessionStore(ctx.workspaceRoot);
|
|
42
|
+
const session = SessionManager.create("prompt");
|
|
43
|
+
const vm = new ChatViewModel();
|
|
44
|
+
await registerBuiltinSlashCommands(builtinHost, {
|
|
45
|
+
ctx,
|
|
46
|
+
vm,
|
|
47
|
+
session,
|
|
48
|
+
store,
|
|
49
|
+
respawn: () => {
|
|
50
|
+
// No-op in -p mode — a one-shot can't loop into a new session. The
|
|
51
|
+
// `/resume` command's user-facing output ("resuming …") still prints
|
|
52
|
+
// so scripts that grep on it stay stable; the actual respawn is
|
|
53
|
+
// silently dropped.
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
// Built-in first (so users can rely on the slash names always working);
|
|
57
|
+
// external plugins second (so `chances -p "/<plugin-cmd>"` still routes).
|
|
58
|
+
let result = await builtinHost.dispatchSlash(name, args);
|
|
59
|
+
if (!result.ok && ctx.plugins) {
|
|
60
|
+
result = await ctx.plugins.dispatchSlash(name, args);
|
|
35
61
|
}
|
|
36
|
-
const result = await ctx.plugins.dispatchSlash(name, args);
|
|
37
62
|
if (!result.ok) {
|
|
38
63
|
return emitSlashError(`Unknown command: /${name}`, format);
|
|
39
64
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/commands/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,SAAS,EAAmC,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../../src/commands/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,SAAS,EAAmC,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvH,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAA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AAE,IAAI,EAAE,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;QACpH,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC;QACtE,OAAO;IACT,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,cAAc,CAAC,OAAe,EAAE,MAAoB;IAC3D,eAAe,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IACvC,OAAO,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Plugin } from "@chances-ai/plugin-api";
|
|
2
|
+
import type { BuiltinSlashDeps } from "./index.js";
|
|
3
|
+
/**
|
|
4
|
+
* `/clear` — empties the current session's turn list and the rendered
|
|
5
|
+
* scrollback. The session keeps its id/title (so `/resume` can come back to
|
|
6
|
+
* it later if desired). The model selection is untouched.
|
|
7
|
+
*
|
|
8
|
+
* Implemented in-place via SessionManager.clearTurns + ChatViewModel.clearLines
|
|
9
|
+
* rather than a respawn — there's no architecture-level reason to tear down
|
|
10
|
+
* the engine and rebuild, and pi/oh-my-pi take the same path.
|
|
11
|
+
*/
|
|
12
|
+
export declare function makeClearPlugin(deps: BuiltinSlashDeps): Plugin;
|
|
13
|
+
//# sourceMappingURL=clear.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clear.d.ts","sourceRoot":"","sources":["../../src/slash/clear.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,MAAM,EAAqB,MAAM,wBAAwB,CAAC;AACtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,gBAAgB,GAAG,MAAM,CAgB9D"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { definePlugin } from "@chances-ai/plugin-api";
|
|
2
|
+
/**
|
|
3
|
+
* `/clear` — empties the current session's turn list and the rendered
|
|
4
|
+
* scrollback. The session keeps its id/title (so `/resume` can come back to
|
|
5
|
+
* it later if desired). The model selection is untouched.
|
|
6
|
+
*
|
|
7
|
+
* Implemented in-place via SessionManager.clearTurns + ChatViewModel.clearLines
|
|
8
|
+
* rather than a respawn — there's no architecture-level reason to tear down
|
|
9
|
+
* the engine and rebuild, and pi/oh-my-pi take the same path.
|
|
10
|
+
*/
|
|
11
|
+
export function makeClearPlugin(deps) {
|
|
12
|
+
const command = {
|
|
13
|
+
name: "clear",
|
|
14
|
+
description: "Clear the current conversation (keeps the session file).",
|
|
15
|
+
run: () => {
|
|
16
|
+
deps.session.clearTurns();
|
|
17
|
+
deps.vm.clearLines();
|
|
18
|
+
return "conversation cleared";
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
return definePlugin({
|
|
22
|
+
name: "builtin/clear",
|
|
23
|
+
onLoad(ctx) {
|
|
24
|
+
ctx.registerSlashCommand(command);
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=clear.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clear.js","sourceRoot":"","sources":["../../src/slash/clear.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAkC,MAAM,wBAAwB,CAAC;AAGtF;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,IAAsB;IACpD,MAAM,OAAO,GAAiB;QAC5B,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,0DAA0D;QACvE,GAAG,EAAE,GAAG,EAAE;YACR,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;YAC1B,IAAI,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC;YACrB,OAAO,sBAAsB,CAAC;QAChC,CAAC;KACF,CAAC;IACF,OAAO,YAAY,CAAC;QAClB,IAAI,EAAE,eAAe;QACrB,MAAM,CAAC,GAAG;YACR,GAAG,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QACpC,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compact.d.ts","sourceRoot":"","sources":["../../src/slash/compact.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,MAAM,EAAqB,MAAM,wBAAwB,CAAC;AAGtF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAcnD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,gBAAgB,GAAG,MAAM,CA0DhE"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { definePlugin } from "@chances-ai/plugin-api";
|
|
2
|
+
import { AppError, ErrorCode } from "@chances-ai/runtime";
|
|
3
|
+
import { summarizeConversation } from "@chances-ai/ai";
|
|
4
|
+
/**
|
|
5
|
+
* `/compact` — summarizes the current conversation with the current model
|
|
6
|
+
* (the design call: "use current model, not a separate cheap one"). The
|
|
7
|
+
* summarized text replaces all but the last 5 turns.
|
|
8
|
+
*
|
|
9
|
+
* Failure modes — all surface as user-readable strings, never throws:
|
|
10
|
+
* - 0 turns to compact → no-op message
|
|
11
|
+
* - router refuses → "no model available"
|
|
12
|
+
* - summarizer returns empty / errors → conversation untouched
|
|
13
|
+
*/
|
|
14
|
+
const KEEP_LAST_N = 5;
|
|
15
|
+
export function makeCompactPlugin(deps) {
|
|
16
|
+
const command = {
|
|
17
|
+
name: "compact",
|
|
18
|
+
description: "Summarize and shrink the current conversation.",
|
|
19
|
+
run: async () => {
|
|
20
|
+
const totalTurns = deps.session.snapshot().turns.length;
|
|
21
|
+
if (totalTurns === 0)
|
|
22
|
+
return "nothing to compact — the conversation is empty";
|
|
23
|
+
if (totalTurns <= KEEP_LAST_N) {
|
|
24
|
+
return `nothing to compact — conversation has ${totalTurns} turn(s), keeping last ${KEEP_LAST_N}`;
|
|
25
|
+
}
|
|
26
|
+
let route;
|
|
27
|
+
try {
|
|
28
|
+
const choice = deps.ctx.selection.get();
|
|
29
|
+
route = deps.ctx.router.pick({
|
|
30
|
+
preferredModel: choice.model,
|
|
31
|
+
preferredProvider: choice.provider,
|
|
32
|
+
needsTools: false,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
if (e instanceof AppError && e.code === ErrorCode.Provider) {
|
|
37
|
+
return `cannot compact: ${e.message}`;
|
|
38
|
+
}
|
|
39
|
+
throw e;
|
|
40
|
+
}
|
|
41
|
+
let summary;
|
|
42
|
+
try {
|
|
43
|
+
summary = await summarizeConversation(route.adapter, route.model.id, deps.session.messages(), new AbortController().signal);
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
// try/catch (rather than a sentinel string) keeps the success path
|
|
47
|
+
// unambiguous — a real LLM summary that happens to start with the
|
|
48
|
+
// sentinel marker would have been mis-classified otherwise.
|
|
49
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
50
|
+
return `summarization failed — conversation untouched. ${msg}`;
|
|
51
|
+
}
|
|
52
|
+
if (!summary || summary.trim().length === 0) {
|
|
53
|
+
return "summarizer returned empty text — conversation untouched";
|
|
54
|
+
}
|
|
55
|
+
const beforeTurns = totalTurns;
|
|
56
|
+
deps.session.compactTurns(summary, KEEP_LAST_N);
|
|
57
|
+
const afterTurns = deps.session.snapshot().turns.length;
|
|
58
|
+
return `compacted ${beforeTurns} → ${afterTurns} turns using ${route.model.provider}/${route.model.id}`;
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
return definePlugin({
|
|
62
|
+
name: "builtin/compact",
|
|
63
|
+
onLoad(ctx) {
|
|
64
|
+
ctx.registerSlashCommand(command);
|
|
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F,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Plugin, type PluginHost } from "@chances-ai/plugin-api";
|
|
2
|
+
/**
|
|
3
|
+
* Lists every registered slash command — built-ins and plugin-provided alike.
|
|
4
|
+
* Sorted alphabetically; the active command itself is included for symmetry.
|
|
5
|
+
* The output is a single multi-line string that the dispatcher renders as an
|
|
6
|
+
* info line.
|
|
7
|
+
*
|
|
8
|
+
* `host` is captured by closure so the listing reflects what's actually
|
|
9
|
+
* loaded — adding a new built-in or a plugin command at any time updates the
|
|
10
|
+
* `/help` output without changing this file.
|
|
11
|
+
*/
|
|
12
|
+
export declare function makeHelpPlugin(host: PluginHost): Plugin;
|
|
13
|
+
//# sourceMappingURL=help.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../../src/slash/help.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,MAAM,EAAE,KAAK,UAAU,EAAqB,MAAM,wBAAwB,CAAC;AAEvG;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAoBvD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { definePlugin } from "@chances-ai/plugin-api";
|
|
2
|
+
/**
|
|
3
|
+
* Lists every registered slash command — built-ins and plugin-provided alike.
|
|
4
|
+
* Sorted alphabetically; the active command itself is included for symmetry.
|
|
5
|
+
* The output is a single multi-line string that the dispatcher renders as an
|
|
6
|
+
* info line.
|
|
7
|
+
*
|
|
8
|
+
* `host` is captured by closure so the listing reflects what's actually
|
|
9
|
+
* loaded — adding a new built-in or a plugin command at any time updates the
|
|
10
|
+
* `/help` output without changing this file.
|
|
11
|
+
*/
|
|
12
|
+
export function makeHelpPlugin(host) {
|
|
13
|
+
const command = {
|
|
14
|
+
name: "help",
|
|
15
|
+
description: "List all slash commands.",
|
|
16
|
+
run: () => {
|
|
17
|
+
const commands = host.slashCommands();
|
|
18
|
+
if (commands.length === 0)
|
|
19
|
+
return "no slash commands registered";
|
|
20
|
+
const padTo = Math.max(...commands.map((c) => c.name.length));
|
|
21
|
+
const lines = [...commands]
|
|
22
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
23
|
+
.map((c) => ` /${c.name.padEnd(padTo)} ${c.description}`);
|
|
24
|
+
return ["Slash commands:", ...lines].join("\n");
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
return definePlugin({
|
|
28
|
+
name: "builtin/help",
|
|
29
|
+
onLoad(ctx) {
|
|
30
|
+
ctx.registerSlashCommand(command);
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=help.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"help.js","sourceRoot":"","sources":["../../src/slash/help.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAmD,MAAM,wBAAwB,CAAC;AAEvG;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAAC,IAAgB;IAC7C,MAAM,OAAO,GAAiB;QAC5B,IAAI,EAAE,MAAM;QACZ,WAAW,EAAE,0BAA0B;QACvC,GAAG,EAAE,GAAG,EAAE;YACR,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;YACtC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;gBAAE,OAAO,8BAA8B,CAAC;YACjE,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;YAC9D,MAAM,KAAK,GAAG,CAAC,GAAG,QAAQ,CAAC;iBACxB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;iBAC5C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;YAC9D,OAAO,CAAC,iBAAiB,EAAE,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClD,CAAC;KACF,CAAC;IACF,OAAO,YAAY,CAAC;QAClB,IAAI,EAAE,cAAc;QACpB,MAAM,CAAC,GAAG;YACR,GAAG,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QACpC,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PluginHost } from "@chances-ai/plugin-api";
|
|
2
|
+
import type { ChatViewModel } from "@chances-ai/tui";
|
|
3
|
+
import type { SessionManager, SessionStore } from "@chances-ai/session";
|
|
4
|
+
import type { AppContext } from "../boot/load-runtime.js";
|
|
5
|
+
/**
|
|
6
|
+
* Bundle of deps every built-in slash command may need. Kept as one object
|
|
7
|
+
* so adding a new built-in doesn't require threading another arg through
|
|
8
|
+
* every factory; commands ignore fields they don't use.
|
|
9
|
+
*
|
|
10
|
+
* `respawn` is the chat loop's "tear down + re-enter" hook. `/resume`
|
|
11
|
+
* triggers it with a target session id; `/clear` doesn't use it (it mutates
|
|
12
|
+
* the current session in place via SessionManager.clearTurns + vm.clearLines).
|
|
13
|
+
*/
|
|
14
|
+
export interface BuiltinSlashDeps {
|
|
15
|
+
ctx: AppContext;
|
|
16
|
+
vm: ChatViewModel;
|
|
17
|
+
session: SessionManager;
|
|
18
|
+
store: SessionStore;
|
|
19
|
+
respawn: (resumeSessionId?: string) => void;
|
|
20
|
+
}
|
|
21
|
+
export declare function registerBuiltinSlashCommands(host: PluginHost, deps: BuiltinSlashDeps): Promise<void>;
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/slash/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAS1D;;;;;;;;GAQG;AACH,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,UAAU,CAAC;IAChB,EAAE,EAAE,aAAa,CAAC;IAClB,OAAO,EAAE,cAAc,CAAC;IACxB,KAAK,EAAE,YAAY,CAAC;IACpB,OAAO,EAAE,CAAC,eAAe,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7C;AAED,wBAAsB,4BAA4B,CAChD,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,gBAAgB,GACrB,OAAO,CAAC,IAAI,CAAC,CAWf"}
|