@llmtune/cli 0.1.0 → 0.1.2
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 +1 -1
- package/dist/agent/conversation.d.ts +42 -0
- package/dist/agent/conversation.js +105 -0
- package/dist/agent/loop.d.ts +19 -0
- package/dist/agent/loop.js +185 -0
- package/dist/agent/planner.d.ts +8 -0
- package/dist/agent/planner.js +43 -0
- package/dist/auth/client.d.ts +4 -0
- package/dist/auth/client.js +24 -0
- package/dist/auth/config.d.ts +21 -0
- package/dist/auth/config.js +83 -0
- package/dist/commands/chat.d.ts +5 -0
- package/dist/commands/chat.js +27 -0
- package/dist/commands/config.d.ts +2 -0
- package/dist/commands/config.js +37 -0
- package/dist/commands/login.d.ts +2 -0
- package/dist/commands/login.js +93 -0
- package/dist/commands/marketplace.d.ts +6 -0
- package/dist/commands/marketplace.js +213 -0
- package/dist/commands/models.d.ts +2 -0
- package/dist/commands/models.js +53 -0
- package/dist/compact/history-store.d.ts +29 -0
- package/dist/compact/history-store.js +110 -0
- package/dist/compact/microcompact.d.ts +10 -0
- package/dist/compact/microcompact.js +43 -0
- package/dist/compact/service.d.ts +13 -0
- package/dist/compact/service.js +156 -0
- package/dist/context/analyzer.d.ts +26 -0
- package/dist/context/analyzer.js +99 -0
- package/dist/context/builder.d.ts +13 -0
- package/dist/context/builder.js +144 -0
- package/dist/context/cache.d.ts +6 -0
- package/dist/context/cache.js +8 -0
- package/dist/context/git-context.d.ts +9 -0
- package/dist/context/git-context.js +39 -0
- package/dist/context/llmtune-md.d.ts +6 -0
- package/dist/context/llmtune-md.js +73 -0
- package/dist/context/workspace.d.ts +11 -0
- package/dist/context/workspace.js +115 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -2
- package/dist/marketplace/client.d.ts +52 -0
- package/dist/marketplace/client.js +86 -0
- package/dist/memory/files.d.ts +14 -0
- package/dist/memory/files.js +116 -0
- package/dist/memory/service.d.ts +22 -0
- package/dist/memory/service.js +146 -0
- package/dist/repl/repl.d.ts +8 -0
- package/dist/repl/repl.js +375 -0
- package/dist/skills/args.d.ts +10 -0
- package/dist/skills/args.js +37 -0
- package/dist/skills/frontmatter.d.ts +6 -0
- package/dist/skills/frontmatter.js +44 -0
- package/dist/skills/loader.d.ts +5 -0
- package/dist/skills/loader.js +59 -0
- package/dist/skills/registry.d.ts +27 -0
- package/dist/skills/registry.js +162 -0
- package/dist/skills/signing/signer.d.ts +19 -0
- package/dist/skills/signing/signer.js +110 -0
- package/dist/skills/trust.d.ts +11 -0
- package/dist/skills/trust.js +42 -0
- package/dist/telemetry/logger.d.ts +51 -0
- package/dist/telemetry/logger.js +135 -0
- package/dist/tools/permissions.d.ts +20 -0
- package/dist/tools/permissions.js +58 -0
- package/dist/tools/protocol.d.ts +22 -0
- package/dist/tools/protocol.js +3 -0
- package/dist/tools/registry.d.ts +20 -0
- package/dist/tools/registry.js +77 -0
- package/dist/tools/sandbox/docker.d.ts +16 -0
- package/dist/tools/sandbox/docker.js +240 -0
- package/dist/tools/sandbox/index.d.ts +18 -0
- package/dist/tools/sandbox/index.js +80 -0
- package/dist/tools/tools/ask-user.d.ts +3 -0
- package/dist/tools/tools/ask-user.js +56 -0
- package/dist/tools/tools/bash.d.ts +3 -0
- package/dist/tools/tools/bash.js +85 -0
- package/dist/tools/tools/edit.d.ts +3 -0
- package/dist/tools/tools/edit.js +138 -0
- package/dist/tools/tools/glob.d.ts +3 -0
- package/dist/tools/tools/glob.js +63 -0
- package/dist/tools/tools/grep.d.ts +3 -0
- package/dist/tools/tools/grep.js +148 -0
- package/dist/tools/tools/read.d.ts +3 -0
- package/dist/tools/tools/read.js +85 -0
- package/dist/tools/tools/web-fetch.d.ts +3 -0
- package/dist/tools/tools/web-fetch.js +143 -0
- package/dist/tools/tools/write.d.ts +3 -0
- package/dist/tools/tools/write.js +84 -0
- package/dist/tools/validation.d.ts +13 -0
- package/dist/tools/validation.js +142 -0
- package/dist/utils/markdown.d.ts +9 -0
- package/dist/utils/markdown.js +89 -0
- package/dist/utils/streaming.d.ts +10 -0
- package/dist/utils/streaming.js +63 -0
- package/dist/utils/tokens.d.ts +12 -0
- package/dist/utils/tokens.js +44 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +9 -0
- package/package.json +2 -2
- package/dist/agent/conversation.d.ts.map +0 -1
- package/dist/agent/loop.d.ts.map +0 -1
- package/dist/agent/planner.d.ts.map +0 -1
- package/dist/auth/client.d.ts.map +0 -1
- package/dist/auth/config.d.ts.map +0 -1
- package/dist/commands/chat.d.ts.map +0 -1
- package/dist/commands/config.d.ts.map +0 -1
- package/dist/commands/login.d.ts.map +0 -1
- package/dist/commands/marketplace.d.ts.map +0 -1
- package/dist/commands/models.d.ts.map +0 -1
- package/dist/compact/history-store.d.ts.map +0 -1
- package/dist/compact/microcompact.d.ts.map +0 -1
- package/dist/compact/service.d.ts.map +0 -1
- package/dist/context/analyzer.d.ts.map +0 -1
- package/dist/context/builder.d.ts.map +0 -1
- package/dist/context/cache.d.ts.map +0 -1
- package/dist/context/git-context.d.ts.map +0 -1
- package/dist/context/llmtune-md.d.ts.map +0 -1
- package/dist/context/workspace.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/marketplace/client.d.ts.map +0 -1
- package/dist/memory/files.d.ts.map +0 -1
- package/dist/memory/service.d.ts.map +0 -1
- package/dist/repl/repl.d.ts.map +0 -1
- package/dist/skills/args.d.ts.map +0 -1
- package/dist/skills/frontmatter.d.ts.map +0 -1
- package/dist/skills/loader.d.ts.map +0 -1
- package/dist/skills/registry.d.ts.map +0 -1
- package/dist/skills/signing/signer.d.ts.map +0 -1
- package/dist/skills/trust.d.ts.map +0 -1
- package/dist/telemetry/logger.d.ts.map +0 -1
- package/dist/tools/permissions.d.ts.map +0 -1
- package/dist/tools/protocol.d.ts.map +0 -1
- package/dist/tools/registry.d.ts.map +0 -1
- package/dist/tools/sandbox/docker.d.ts.map +0 -1
- package/dist/tools/sandbox/index.d.ts.map +0 -1
- package/dist/tools/tools/ask-user.d.ts.map +0 -1
- package/dist/tools/tools/bash.d.ts.map +0 -1
- package/dist/tools/tools/edit.d.ts.map +0 -1
- package/dist/tools/tools/glob.d.ts.map +0 -1
- package/dist/tools/tools/grep.d.ts.map +0 -1
- package/dist/tools/tools/read.d.ts.map +0 -1
- package/dist/tools/tools/web-fetch.d.ts.map +0 -1
- package/dist/tools/tools/write.d.ts.map +0 -1
- package/dist/tools/validation.d.ts.map +0 -1
- package/dist/utils/markdown.d.ts.map +0 -1
- package/dist/utils/streaming.d.ts.map +0 -1
- package/dist/utils/tokens.d.ts.map +0 -1
- package/src/agent/conversation.ts +0 -140
- package/src/agent/loop.ts +0 -215
- package/src/agent/planner.ts +0 -55
- package/src/auth/client.ts +0 -19
- package/src/auth/config.ts +0 -89
- package/src/commands/chat.ts +0 -28
- package/src/commands/config.ts +0 -36
- package/src/commands/login.ts +0 -63
- package/src/commands/marketplace.ts +0 -190
- package/src/commands/models.ts +0 -74
- package/src/compact/history-store.ts +0 -101
- package/src/compact/microcompact.ts +0 -49
- package/src/compact/service.ts +0 -154
- package/src/context/analyzer.ts +0 -127
- package/src/context/builder.ts +0 -123
- package/src/context/cache.ts +0 -11
- package/src/context/git-context.ts +0 -58
- package/src/context/llmtune-md.ts +0 -48
- package/src/context/workspace.ts +0 -139
- package/src/index.ts +0 -100
- package/src/marketplace/client.ts +0 -118
- package/src/memory/files.ts +0 -81
- package/src/memory/service.ts +0 -124
- package/src/repl/repl.ts +0 -400
- package/src/skills/args.ts +0 -35
- package/src/skills/builtin/explain-code/SKILL.md +0 -30
- package/src/skills/frontmatter.ts +0 -47
- package/src/skills/loader.ts +0 -25
- package/src/skills/registry.ts +0 -155
- package/src/skills/signing/signer.ts +0 -101
- package/src/skills/trust.ts +0 -50
- package/src/telemetry/logger.ts +0 -108
- package/src/tools/permissions.ts +0 -83
- package/src/tools/protocol.ts +0 -24
- package/src/tools/registry.ts +0 -93
- package/src/tools/sandbox/docker.ts +0 -225
- package/src/tools/sandbox/index.ts +0 -91
- package/src/tools/tools/ask-user.ts +0 -60
- package/src/tools/tools/bash.ts +0 -97
- package/src/tools/tools/edit.ts +0 -111
- package/src/tools/tools/glob.ts +0 -68
- package/src/tools/tools/grep.ts +0 -121
- package/src/tools/tools/read.ts +0 -57
- package/src/tools/tools/web-fetch.ts +0 -158
- package/src/tools/tools/write.ts +0 -52
- package/src/tools/validation.ts +0 -164
- package/src/utils/markdown.ts +0 -96
- package/src/utils/streaming.ts +0 -63
- package/src/utils/tokens.ts +0 -41
- package/tsconfig.json +0 -20
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/tools/protocol.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,OAAO,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAA;IACX,aAAa,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,IAAI;IACnB,IAAI,IAAI,QAAQ,CAAA;IAChB,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,WAAW,GAAG,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;CACxF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAGzE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,CAAA;AAEvD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,WAAW,KAAK,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;CAC5F;AAmBD,wBAAgB,UAAU,CAAC,GAAG,EAAE,cAAc,GAAG,IAAI,CAEpD;AAED,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAA+B;IAE5C,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IAS1B,SAAS,IAAI,QAAQ,EAAE;IAIvB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAInC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,WAAW,GAAG,UAAU;IAqB9E,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;CAgBzG"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"docker.d.ts","sourceRoot":"","sources":["../../../src/tools/sandbox/docker.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAS7C,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,OAAO,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,EAAE,MAAM,EAAE,CAAA;IACvB,WAAW,EAAE,MAAM,CAAA;CACpB;AAED,eAAO,MAAM,sBAAsB,EAAE,aAMpC,CAAA;AAID,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAErE;AAED,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C;AAED,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC,CAS1D;AAED,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC,CAgB3D;AAED,wBAAsB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAgFpF;AAED,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,UAAU,CAAC,CAyDrB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/sandbox/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAG7C,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,WAAW,GAAG,UAAU,CAAA;AAK1D,wBAAgB,cAAc,IAAI,WAAW,CAE5C;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAGtD;AAED,wBAAgB,iBAAiB,IAAI,OAAO,CAW3C;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,UAAU,CAAC,CAoBrB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ask-user.d.ts","sourceRoot":"","sources":["../../../src/tools/tools/ask-user.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAqC,MAAM,aAAa,CAAA;AAE1E,eAAO,MAAM,WAAW,EAAE,IAwDzB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../src/tools/tools/bash.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAqC,MAAM,aAAa,CAAA;AAO1E,eAAO,MAAM,QAAQ,EAAE,IAuFtB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../src/tools/tools/edit.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAA2B,MAAM,aAAa,CAAA;AAEhE,eAAO,MAAM,QAAQ,EAAE,IA0GtB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../../../src/tools/tools/glob.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAqC,MAAM,aAAa,CAAA;AAE1E,eAAO,MAAM,QAAQ,EAAE,IA8DtB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"grep.d.ts","sourceRoot":"","sources":["../../../src/tools/tools/grep.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAqC,MAAM,aAAa,CAAA;AAE1E,eAAO,MAAM,QAAQ,EAAE,IA+GtB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../../src/tools/tools/read.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAqC,MAAM,aAAa,CAAA;AAE1E,eAAO,MAAM,QAAQ,EAAE,IAoDtB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"web-fetch.d.ts","sourceRoot":"","sources":["../../../src/tools/tools/web-fetch.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAqC,MAAM,aAAa,CAAA;AAK1E,eAAO,MAAM,YAAY,EAAE,IAsJ1B,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/tools/tools/write.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAqC,MAAM,aAAa,CAAA;AAE1E,eAAO,MAAM,SAAS,EAAE,IA+CvB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/tools/validation.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;CAChB;AAeD,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAI5B;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,QAAQ,SAAU,GACjB,IAAI,CAWN"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../src/utils/markdown.ts"],"names":[],"mappings":"AAMA,UAAU,aAAa;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,CAS5E;AAqDD,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAOvE;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,MAAM,CAavE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../../src/utils/streaming.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAEzB,wBAAgB,sBAAsB;mBAMnB,MAAM,GAAG,IAAI;aAQnB,IAAI;iBAMA,MAAM;EAItB;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAG7C;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAGnF;AAqBD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,CAKtE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../src/utils/tokens.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGnD;AAED,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,GAClD,MAAM,CAYR;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAQxF;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAIvD"}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import crypto from "crypto"
|
|
2
|
-
import fs from "fs"
|
|
3
|
-
import path from "path"
|
|
4
|
-
import os from "os"
|
|
5
|
-
|
|
6
|
-
export interface Message {
|
|
7
|
-
role: "system" | "user" | "assistant" | "tool"
|
|
8
|
-
content: string
|
|
9
|
-
toolCalls?: ToolCallMessage[]
|
|
10
|
-
toolCallId?: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface ToolCallMessage {
|
|
14
|
-
id: string
|
|
15
|
-
type: "function"
|
|
16
|
-
function: {
|
|
17
|
-
name: string
|
|
18
|
-
arguments: string
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface ConversationMeta {
|
|
23
|
-
id: string
|
|
24
|
-
createdAt: string
|
|
25
|
-
updatedAt: string
|
|
26
|
-
model: string
|
|
27
|
-
messageCount: number
|
|
28
|
-
totalTokens?: number
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export class Conversation {
|
|
32
|
-
messages: Message[] = []
|
|
33
|
-
id: string
|
|
34
|
-
model: string
|
|
35
|
-
createdAt: Date
|
|
36
|
-
totalTokens = 0
|
|
37
|
-
|
|
38
|
-
constructor(model: string) {
|
|
39
|
-
this.id = crypto.randomUUID()
|
|
40
|
-
this.model = model
|
|
41
|
-
this.createdAt = new Date()
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
addSystemMessage(content: string): void {
|
|
45
|
-
this.messages.push({ role: "system", content })
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
addUserMessage(content: string): void {
|
|
49
|
-
this.messages.push({ role: "user", content })
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
addAssistantMessage(content: string, toolCalls?: ToolCallMessage[]): void {
|
|
53
|
-
this.messages.push({ role: "assistant", content, toolCalls })
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
addToolResult(toolCallId: string, content: string | Record<string, unknown>, isError?: boolean): void {
|
|
57
|
-
const text = typeof content === "string" ? content : JSON.stringify(content)
|
|
58
|
-
this.messages.push({
|
|
59
|
-
role: "tool",
|
|
60
|
-
content: isError ? `Error: ${text}` : text,
|
|
61
|
-
toolCallId,
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
clear(): void {
|
|
66
|
-
this.messages = []
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
getApiMessages(): Message[] {
|
|
70
|
-
return [...this.messages]
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
getTokenEstimate(): number {
|
|
74
|
-
return this.messages.reduce((total, msg) => {
|
|
75
|
-
const content =
|
|
76
|
-
typeof msg.content === "string"
|
|
77
|
-
? msg.content
|
|
78
|
-
: JSON.stringify(msg.content)
|
|
79
|
-
return total + Math.ceil(content.length / 4)
|
|
80
|
-
}, 0)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
getMeta(): ConversationMeta {
|
|
84
|
-
return {
|
|
85
|
-
id: this.id,
|
|
86
|
-
createdAt: this.createdAt.toISOString(),
|
|
87
|
-
updatedAt: new Date().toISOString(),
|
|
88
|
-
model: this.model,
|
|
89
|
-
messageCount: this.messages.length,
|
|
90
|
-
totalTokens: this.totalTokens || undefined,
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
save(sessionsDir?: string): string {
|
|
95
|
-
const dir = sessionsDir || path.join(os.homedir(), ".llmtune", "sessions")
|
|
96
|
-
fs.mkdirSync(dir, { recursive: true })
|
|
97
|
-
const filePath = path.join(dir, `${this.id}.json`)
|
|
98
|
-
const data = {
|
|
99
|
-
meta: this.getMeta(),
|
|
100
|
-
messages: this.messages,
|
|
101
|
-
}
|
|
102
|
-
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), "utf-8")
|
|
103
|
-
return filePath
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
static load(filePath: string): Conversation {
|
|
107
|
-
const raw = fs.readFileSync(filePath, "utf-8")
|
|
108
|
-
const data = JSON.parse(raw) as {
|
|
109
|
-
meta: ConversationMeta
|
|
110
|
-
messages: Message[]
|
|
111
|
-
}
|
|
112
|
-
const conv = new Conversation(data.meta.model)
|
|
113
|
-
conv.id = data.meta.id
|
|
114
|
-
conv.createdAt = new Date(data.meta.createdAt)
|
|
115
|
-
conv.messages = data.messages
|
|
116
|
-
conv.totalTokens = data.meta.totalTokens || 0
|
|
117
|
-
return conv
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
static listSessions(sessionsDir?: string): ConversationMeta[] {
|
|
121
|
-
const dir = sessionsDir || path.join(os.homedir(), ".llmtune", "sessions")
|
|
122
|
-
if (!fs.existsSync(dir)) return []
|
|
123
|
-
return fs
|
|
124
|
-
.readdirSync(dir)
|
|
125
|
-
.filter((f) => f.endsWith(".json"))
|
|
126
|
-
.map((f) => {
|
|
127
|
-
try {
|
|
128
|
-
const raw = fs.readFileSync(path.join(dir, f), "utf-8")
|
|
129
|
-
return (JSON.parse(raw) as { meta: ConversationMeta }).meta
|
|
130
|
-
} catch {
|
|
131
|
-
return null
|
|
132
|
-
}
|
|
133
|
-
})
|
|
134
|
-
.filter((m): m is ConversationMeta => m !== null)
|
|
135
|
-
.sort(
|
|
136
|
-
(a, b) =>
|
|
137
|
-
new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime()
|
|
138
|
-
)
|
|
139
|
-
}
|
|
140
|
-
}
|
package/src/agent/loop.ts
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import OpenAI from "openai"
|
|
2
|
-
import { ToolRegistry, type ToolContext } from "../tools/registry"
|
|
3
|
-
import { Conversation, type ToolCallMessage } from "./conversation"
|
|
4
|
-
import { buildContextPrompt } from "../context/builder"
|
|
5
|
-
import chalk from "chalk"
|
|
6
|
-
|
|
7
|
-
export interface AgentLoopConfig {
|
|
8
|
-
model?: string
|
|
9
|
-
maxTurns?: number
|
|
10
|
-
verbose?: boolean
|
|
11
|
-
cwd: string
|
|
12
|
-
workspaceRoot: string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface AgentLoopResult {
|
|
16
|
-
finalText: string
|
|
17
|
-
totalToolCalls: number
|
|
18
|
-
totalTokensIn: number
|
|
19
|
-
totalTokensOut: number
|
|
20
|
-
turns: number
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export async function runAgentLoop(
|
|
24
|
-
client: OpenAI,
|
|
25
|
-
conversation: Conversation,
|
|
26
|
-
registry: ToolRegistry,
|
|
27
|
-
userInput: string,
|
|
28
|
-
config: AgentLoopConfig,
|
|
29
|
-
onTextChunk?: (text: string) => void
|
|
30
|
-
): Promise<AgentLoopResult> {
|
|
31
|
-
const model = config.model ?? "z-ai/GLM-5.1"
|
|
32
|
-
const maxTurns = config.maxTurns ?? 20
|
|
33
|
-
|
|
34
|
-
conversation.addUserMessage(userInput)
|
|
35
|
-
|
|
36
|
-
const toolSpecs = registry.listSpecs()
|
|
37
|
-
const openaiTools: OpenAI.ChatCompletionTool[] = toolSpecs.map((spec) => ({
|
|
38
|
-
type: "function" as const,
|
|
39
|
-
function: {
|
|
40
|
-
name: spec.name,
|
|
41
|
-
description: spec.description,
|
|
42
|
-
parameters: spec.inputSchema as OpenAI.FunctionParameters,
|
|
43
|
-
},
|
|
44
|
-
}))
|
|
45
|
-
|
|
46
|
-
const contextResult = await buildContextPrompt(config.workspaceRoot, config.cwd)
|
|
47
|
-
const contextPrompt = contextResult.prompt
|
|
48
|
-
|
|
49
|
-
let totalToolCalls = 0
|
|
50
|
-
let totalTokensIn = 0
|
|
51
|
-
let totalTokensOut = 0
|
|
52
|
-
let turns = 0
|
|
53
|
-
let finalText = ""
|
|
54
|
-
|
|
55
|
-
for (let turn = 0; turn < maxTurns; turn++) {
|
|
56
|
-
const apiMessages = conversation.getApiMessages()
|
|
57
|
-
const systemMessage: OpenAI.ChatCompletionSystemMessageParam = {
|
|
58
|
-
role: "system",
|
|
59
|
-
content: contextPrompt,
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const allMessages: OpenAI.ChatCompletionMessageParam[] = [
|
|
63
|
-
systemMessage,
|
|
64
|
-
...apiMessages.map((msg): OpenAI.ChatCompletionMessageParam => {
|
|
65
|
-
if (msg.role === "system") return { role: "system", content: msg.content }
|
|
66
|
-
if (msg.role === "user") return { role: "user", content: msg.content }
|
|
67
|
-
if (msg.role === "assistant") {
|
|
68
|
-
const m: OpenAI.ChatCompletionAssistantMessageParam = {
|
|
69
|
-
role: "assistant",
|
|
70
|
-
content: msg.content || null,
|
|
71
|
-
}
|
|
72
|
-
if (msg.toolCalls && msg.toolCalls.length > 0) {
|
|
73
|
-
m.tool_calls = msg.toolCalls.map((tc): OpenAI.ChatCompletionMessageToolCall => ({
|
|
74
|
-
id: tc.id,
|
|
75
|
-
type: "function",
|
|
76
|
-
function: { name: tc.function.name, arguments: tc.function.arguments },
|
|
77
|
-
}))
|
|
78
|
-
}
|
|
79
|
-
return m
|
|
80
|
-
}
|
|
81
|
-
if (msg.role === "tool") {
|
|
82
|
-
return {
|
|
83
|
-
role: "tool",
|
|
84
|
-
tool_call_id: msg.toolCallId ?? "",
|
|
85
|
-
content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content),
|
|
86
|
-
} as OpenAI.ChatCompletionToolMessageParam
|
|
87
|
-
}
|
|
88
|
-
return { role: "user", content: msg.content }
|
|
89
|
-
}),
|
|
90
|
-
]
|
|
91
|
-
|
|
92
|
-
const stream = await client.chat.completions.create({
|
|
93
|
-
model,
|
|
94
|
-
messages: allMessages,
|
|
95
|
-
tools: openaiTools.length > 0 ? openaiTools : undefined,
|
|
96
|
-
stream: true,
|
|
97
|
-
temperature: 0.7,
|
|
98
|
-
max_tokens: 16384,
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
let assistantContent = ""
|
|
102
|
-
const toolCalls: ToolCallMessage[] = []
|
|
103
|
-
let currentToolCall: { id: string; name: string; arguments: string } | null = null
|
|
104
|
-
|
|
105
|
-
for await (const chunk of stream) {
|
|
106
|
-
const delta = chunk.choices[0]?.delta
|
|
107
|
-
if (!delta) continue
|
|
108
|
-
|
|
109
|
-
if (delta.content) {
|
|
110
|
-
assistantContent += delta.content
|
|
111
|
-
if (onTextChunk) onTextChunk(delta.content)
|
|
112
|
-
else process.stdout.write(delta.content)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (delta.tool_calls) {
|
|
116
|
-
for (const tc of delta.tool_calls) {
|
|
117
|
-
if (tc.id && tc.function?.name) {
|
|
118
|
-
currentToolCall = {
|
|
119
|
-
id: tc.id,
|
|
120
|
-
name: tc.function.name,
|
|
121
|
-
arguments: tc.function.arguments ?? "",
|
|
122
|
-
}
|
|
123
|
-
toolCalls.push({
|
|
124
|
-
id: tc.id,
|
|
125
|
-
type: "function",
|
|
126
|
-
function: { name: tc.function.name, arguments: tc.function.arguments ?? "" },
|
|
127
|
-
})
|
|
128
|
-
} else if (currentToolCall && tc.function?.arguments) {
|
|
129
|
-
currentToolCall.arguments += tc.function.arguments
|
|
130
|
-
const last = toolCalls[toolCalls.length - 1]
|
|
131
|
-
if (last) last.function.arguments = currentToolCall.arguments
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (chunk.usage) {
|
|
137
|
-
totalTokensIn += chunk.usage.prompt_tokens ?? 0
|
|
138
|
-
totalTokensOut += chunk.usage.completion_tokens ?? 0
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (!onTextChunk) console.log()
|
|
143
|
-
turns++
|
|
144
|
-
|
|
145
|
-
if (toolCalls.length === 0) {
|
|
146
|
-
conversation.addAssistantMessage(assistantContent)
|
|
147
|
-
finalText = assistantContent
|
|
148
|
-
break
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
conversation.addAssistantMessage(assistantContent, toolCalls)
|
|
152
|
-
|
|
153
|
-
for (const tc of toolCalls) {
|
|
154
|
-
totalToolCalls++
|
|
155
|
-
let toolInput: Record<string, unknown>
|
|
156
|
-
try {
|
|
157
|
-
toolInput = JSON.parse(tc.function.arguments)
|
|
158
|
-
} catch {
|
|
159
|
-
toolInput = { raw: tc.function.arguments }
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const summary = summarizeToolInput(tc.function.name, toolInput)
|
|
163
|
-
console.log(chalk.cyan(` ▶ ${tc.function.name}`) + chalk.dim(` ${summary}`))
|
|
164
|
-
|
|
165
|
-
const toolCtx: ToolContext = {
|
|
166
|
-
workspaceRoot: config.workspaceRoot,
|
|
167
|
-
cwd: config.cwd,
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
const result = await registry.dispatch(tc.function.name, toolInput, toolCtx)
|
|
171
|
-
|
|
172
|
-
if (result.isError) {
|
|
173
|
-
console.log(chalk.red(` ✗ ${tc.function.name}: ${String(result.output).slice(0, 200)}`))
|
|
174
|
-
} else {
|
|
175
|
-
console.log(chalk.green(` ✓ ${summarizeToolResult(tc.function.name, result.output)}`))
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const resultStr = typeof result.output === "string" ? result.output : JSON.stringify(result.output)
|
|
179
|
-
conversation.addToolResult(tc.id, resultStr)
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (turn === maxTurns - 1) {
|
|
183
|
-
finalText = "[Max tool turns reached]"
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return { finalText, totalToolCalls, totalTokensIn, totalTokensOut, turns }
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function summarizeToolInput(name: string, input: Record<string, unknown>): string {
|
|
191
|
-
const n = name.toLowerCase()
|
|
192
|
-
if (n === "bash") {
|
|
193
|
-
const cmd = String(input.command ?? "").replace(/\n/g, " ")
|
|
194
|
-
return cmd.length > 60 ? cmd.slice(0, 57) + "..." : cmd
|
|
195
|
-
}
|
|
196
|
-
if (n === "read" || n === "write" || n === "edit") {
|
|
197
|
-
return String(input.file_path ?? input.path ?? "")
|
|
198
|
-
}
|
|
199
|
-
if (n === "glob") return String(input.pattern ?? "")
|
|
200
|
-
if (n === "grep") return String(input.pattern ?? "")
|
|
201
|
-
return ""
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
function summarizeToolResult(name: string, output: unknown): string {
|
|
205
|
-
if (typeof output === "string") {
|
|
206
|
-
return output.length > 100 ? output.slice(0, 97) + "..." : output
|
|
207
|
-
}
|
|
208
|
-
if (typeof output === "object" && output !== null) {
|
|
209
|
-
const obj = output as Record<string, unknown>
|
|
210
|
-
if (obj.error) return `error: ${String(obj.error).slice(0, 80)}`
|
|
211
|
-
if (obj.numFiles !== undefined) return `${name} · ${obj.numFiles} results`
|
|
212
|
-
if (obj.exit_code !== undefined) return `${name} · exit ${obj.exit_code}`
|
|
213
|
-
}
|
|
214
|
-
return `${name} completed`
|
|
215
|
-
}
|
package/src/agent/planner.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import OpenAI from "openai";
|
|
2
|
-
import type { ChatCompletionMessageParam } from "openai/resources/chat/completions";
|
|
3
|
-
|
|
4
|
-
const PLANNER_SYSTEM_PROMPT = `You are a tool-use planner. Given a user message and available tools, decide:
|
|
5
|
-
1. Does this request need any tools? (simple questions like "what is 2+2" do not)
|
|
6
|
-
2. If yes, which specific tools are needed?
|
|
7
|
-
3. What is the execution plan?
|
|
8
|
-
|
|
9
|
-
Respond in this exact JSON format:
|
|
10
|
-
{"needs_tools": boolean, "tools_needed": ["tool_name", ...], "plan": "brief description"}
|
|
11
|
-
|
|
12
|
-
Only include tools that are actually necessary. Do not over-plan.`;
|
|
13
|
-
|
|
14
|
-
export interface PlanResult {
|
|
15
|
-
needsTools: boolean;
|
|
16
|
-
toolsNeeded: string[];
|
|
17
|
-
plan: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export async function planToolUsage(
|
|
21
|
-
client: OpenAI,
|
|
22
|
-
model: string,
|
|
23
|
-
userMessage: string,
|
|
24
|
-
availableTools: string[]
|
|
25
|
-
): Promise<PlanResult> {
|
|
26
|
-
try {
|
|
27
|
-
const response = await client.chat.completions.create({
|
|
28
|
-
model,
|
|
29
|
-
messages: [
|
|
30
|
-
{ role: "system", content: PLANNER_SYSTEM_PROMPT },
|
|
31
|
-
{
|
|
32
|
-
role: "user",
|
|
33
|
-
content: `Available tools: ${availableTools.join(", ")}\n\nUser message: ${userMessage}`,
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
max_tokens: 200,
|
|
37
|
-
temperature: 0,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
const content = response.choices[0]?.message?.content?.trim() ?? "";
|
|
41
|
-
const jsonMatch = content.match(/\{[\s\S]*\}/);
|
|
42
|
-
if (!jsonMatch) {
|
|
43
|
-
return { needsTools: true, toolsNeeded: [], plan: "proceed with all tools" };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const parsed = JSON.parse(jsonMatch[0]);
|
|
47
|
-
return {
|
|
48
|
-
needsTools: parsed.needs_tools ?? true,
|
|
49
|
-
toolsNeeded: parsed.tools_needed ?? [],
|
|
50
|
-
plan: parsed.plan ?? "",
|
|
51
|
-
};
|
|
52
|
-
} catch {
|
|
53
|
-
return { needsTools: true, toolsNeeded: [], plan: "" };
|
|
54
|
-
}
|
|
55
|
-
}
|
package/src/auth/client.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import OpenAI from "openai"
|
|
2
|
-
import { loadConfig, getApiBase, getDefaultModel as getDefaultModelConfig } from "./config"
|
|
3
|
-
|
|
4
|
-
export function createClient(): OpenAI {
|
|
5
|
-
const apiKey = loadConfig().apiKey as string | undefined
|
|
6
|
-
if (!apiKey) {
|
|
7
|
-
console.error("Not logged in. Run: llmtune login")
|
|
8
|
-
process.exit(1)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return new OpenAI({
|
|
12
|
-
apiKey,
|
|
13
|
-
baseURL: getApiBase(),
|
|
14
|
-
})
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function getDefaultModel(): string {
|
|
18
|
-
return getDefaultModelConfig()
|
|
19
|
-
}
|
package/src/auth/config.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import fs from "fs"
|
|
2
|
-
import path from "path"
|
|
3
|
-
import os from "os"
|
|
4
|
-
|
|
5
|
-
const CONFIG_DIR = path.join(os.homedir(), ".llmtune")
|
|
6
|
-
const CONFIG_FILE = path.join(CONFIG_DIR, "config.json")
|
|
7
|
-
|
|
8
|
-
export interface AuthConfig {
|
|
9
|
-
apiKey: string
|
|
10
|
-
apiBase: string
|
|
11
|
-
defaultModel?: string
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface AppConfig {
|
|
15
|
-
defaultProvider?: string
|
|
16
|
-
providers?: Record<string, AuthConfig>
|
|
17
|
-
[key: string]: unknown
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function ensureConfigDir(): void {
|
|
21
|
-
if (!fs.existsSync(CONFIG_DIR)) {
|
|
22
|
-
fs.mkdirSync(CONFIG_DIR, { recursive: true })
|
|
23
|
-
}
|
|
24
|
-
const memDir = path.join(CONFIG_DIR, "memory")
|
|
25
|
-
if (!fs.existsSync(memDir)) {
|
|
26
|
-
fs.mkdirSync(memDir, { recursive: true })
|
|
27
|
-
}
|
|
28
|
-
const sessionsDir = path.join(CONFIG_DIR, "sessions")
|
|
29
|
-
if (!fs.existsSync(sessionsDir)) {
|
|
30
|
-
fs.mkdirSync(sessionsDir, { recursive: true })
|
|
31
|
-
}
|
|
32
|
-
const logsDir = path.join(CONFIG_DIR, "logs")
|
|
33
|
-
if (!fs.existsSync(logsDir)) {
|
|
34
|
-
fs.mkdirSync(logsDir, { recursive: true })
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function loadConfig(): AppConfig {
|
|
39
|
-
ensureConfigDir()
|
|
40
|
-
if (!fs.existsSync(CONFIG_FILE)) {
|
|
41
|
-
return {}
|
|
42
|
-
}
|
|
43
|
-
try {
|
|
44
|
-
const raw = fs.readFileSync(CONFIG_FILE, "utf-8")
|
|
45
|
-
return JSON.parse(raw) as AppConfig
|
|
46
|
-
} catch {
|
|
47
|
-
return {}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export function saveConfig(config: AppConfig): void {
|
|
52
|
-
ensureConfigDir()
|
|
53
|
-
fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2), "utf-8")
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function getApiKey(): string | null {
|
|
57
|
-
const config = loadConfig()
|
|
58
|
-
return (config.apiKey as string) ?? null
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function getApiBase(): string {
|
|
62
|
-
const config = loadConfig()
|
|
63
|
-
return (config.apiBase as string) ?? "https://api.llmtune.io/api/agent/v1"
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function getDefaultModel(): string {
|
|
67
|
-
const config = loadConfig()
|
|
68
|
-
return (config.defaultModel as string) ?? "z-ai/GLM-5.1"
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function isLoggedIn(): boolean {
|
|
72
|
-
return getApiKey() !== null
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function logout(): void {
|
|
76
|
-
const config = loadConfig()
|
|
77
|
-
delete config.apiKey
|
|
78
|
-
delete config.apiBase
|
|
79
|
-
delete config.defaultModel
|
|
80
|
-
saveConfig(config)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function getConfigPath(): string {
|
|
84
|
-
return CONFIG_FILE
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function getConfigDir(): string {
|
|
88
|
-
return CONFIG_DIR
|
|
89
|
-
}
|
package/src/commands/chat.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
|
-
import { loadConfig, getApiBase } from "../auth/config.js";
|
|
3
|
-
import { createClient } from "../auth/client.js";
|
|
4
|
-
import { startRepl } from "../repl/repl.js";
|
|
5
|
-
|
|
6
|
-
export async function chatCommand(options: {
|
|
7
|
-
model?: string;
|
|
8
|
-
stream?: boolean;
|
|
9
|
-
}) {
|
|
10
|
-
const config = loadConfig();
|
|
11
|
-
|
|
12
|
-
if (!config.apiKey) {
|
|
13
|
-
console.log(chalk.red('No API key configured. Run "llmtune login" first.'));
|
|
14
|
-
process.exit(1);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const client = createClient();
|
|
18
|
-
const model = options.model || (config.defaultModel as string) || "z-ai/GLM-5.1";
|
|
19
|
-
const stream = options.stream !== false;
|
|
20
|
-
|
|
21
|
-
console.log(chalk.cyan(`\nLLMTune CLI`));
|
|
22
|
-
console.log(chalk.dim(`Connected to ${getApiBase()}`));
|
|
23
|
-
console.log(chalk.dim(`Model: ${model}`));
|
|
24
|
-
console.log(chalk.dim(`Stream: ${stream}`));
|
|
25
|
-
console.log(chalk.dim(`Type /help for commands, /exit to quit\n`));
|
|
26
|
-
|
|
27
|
-
await startRepl({ client, model, stream });
|
|
28
|
-
}
|
package/src/commands/config.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
|
-
import { loadConfig, getConfigPath } from "../auth/config";
|
|
3
|
-
|
|
4
|
-
export function showConfig(): void {
|
|
5
|
-
const configPath = getConfigPath();
|
|
6
|
-
|
|
7
|
-
try {
|
|
8
|
-
const config = loadConfig();
|
|
9
|
-
console.log(chalk.bold("\nConfiguration\n"));
|
|
10
|
-
console.log(` Config file: ${chalk.cyan(configPath)}`);
|
|
11
|
-
const apiKey = config.apiKey as string | undefined
|
|
12
|
-
const apiBase = config.apiBase as string | undefined
|
|
13
|
-
const defaultModel = config.defaultModel as string | undefined
|
|
14
|
-
console.log(` API base: ${chalk.cyan(apiBase ?? "(not set)")}`);
|
|
15
|
-
console.log(` Default model: ${chalk.cyan(defaultModel || "(not set)")}`);
|
|
16
|
-
|
|
17
|
-
if (apiKey) {
|
|
18
|
-
const masked =
|
|
19
|
-
apiKey.length > 12
|
|
20
|
-
? `${apiKey.slice(0, 6)}...${apiKey.slice(-4)}`
|
|
21
|
-
: "(set)";
|
|
22
|
-
console.log(` API key: ${chalk.green(masked)}`);
|
|
23
|
-
} else {
|
|
24
|
-
console.log(` API key: ${chalk.red("(not set)")}`);
|
|
25
|
-
console.log(
|
|
26
|
-
chalk.dim(`\n Run ${chalk.bold("llmtune login")} to configure your API key.`)
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
console.log();
|
|
30
|
-
} catch {
|
|
31
|
-
console.log(chalk.dim(`\n No config found at ${configPath}`));
|
|
32
|
-
console.log(
|
|
33
|
-
chalk.dim(` Run ${chalk.bold("llmtune login")} to get started.\n`)
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
}
|