@lakphy/local-router 0.3.0 → 0.3.1

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.
Files changed (3) hide show
  1. package/dist/cli.js +50 -0
  2. package/package.json +1 -1
  3. package/dist/index.js +0 -13699
package/dist/cli.js CHANGED
@@ -55954,6 +55954,7 @@ Commands:
55954
55954
  logs [--follow] [--lines <n>]
55955
55955
  init [--config <path>] [--force]
55956
55956
  config <subcommand> [...args]
55957
+ get-route --type <route-type> [--model-alias <alias>] [--config <path>]
55957
55958
  health
55958
55959
  version
55959
55960
 
@@ -56119,6 +56120,52 @@ async function cmdInit(args) {
56119
56120
  const result = ensureConfigFile(configPath);
56120
56121
  console.log(result.created ? `\u5DF2\u521D\u59CB\u5316\u914D\u7F6E: ${result.path}` : `\u914D\u7F6E\u5DF2\u5B58\u5728: ${result.path}`);
56121
56122
  }
56123
+ function formatRouteTarget(target) {
56124
+ return `${target.provider} / ${target.model}`;
56125
+ }
56126
+ async function cmdGetRoute(args) {
56127
+ const parsed = parseArgs3({
56128
+ args,
56129
+ options: {
56130
+ type: { type: "string" },
56131
+ "model-alias": { type: "string" },
56132
+ model: { type: "string" },
56133
+ config: { type: "string" }
56134
+ },
56135
+ allowPositionals: true,
56136
+ strict: false
56137
+ });
56138
+ const routeType = parsed.values.type;
56139
+ if (!routeType) {
56140
+ throw new Error("\u7528\u6CD5: local-router get-route --type <route-type> [--model-alias <alias>] [--config <path>]");
56141
+ }
56142
+ const configPath = resolveConfigPath(parsed.values.config);
56143
+ const config2 = loadConfig(configPath);
56144
+ const modelMap = config2.routes[routeType];
56145
+ if (!modelMap) {
56146
+ throw new Error(`route type \u4E0D\u5B58\u5728: ${routeType}`);
56147
+ }
56148
+ const modelAlias = parsed.values["model-alias"] ?? parsed.values.model;
56149
+ if (modelAlias) {
56150
+ const target = modelMap[modelAlias] ?? modelMap["*"];
56151
+ if (!target) {
56152
+ throw new Error(`\u672A\u547D\u4E2D\u8DEF\u7531\u4E14\u7F3A\u5C11\u515C\u5E95: ${routeType}`);
56153
+ }
56154
+ console.log(formatRouteTarget(target));
56155
+ return;
56156
+ }
56157
+ const chunks = [];
56158
+ for (const [alias, target] of Object.entries(modelMap)) {
56159
+ if (alias === "*")
56160
+ continue;
56161
+ chunks.push(`${alias} : ${formatRouteTarget(target)}`);
56162
+ }
56163
+ const fallback = modelMap["*"];
56164
+ if (fallback) {
56165
+ chunks.push(`default : ${formatRouteTarget(fallback)}`);
56166
+ }
56167
+ console.log(chunks.join(" | "));
56168
+ }
56122
56169
  async function cmdHealth() {
56123
56170
  await cleanupIfStale();
56124
56171
  const state = readRuntimeState();
@@ -56184,6 +56231,9 @@ async function main() {
56184
56231
  case "config":
56185
56232
  await cmdConfig(rest);
56186
56233
  return;
56234
+ case "get-route":
56235
+ await cmdGetRoute(rest);
56236
+ return;
56187
56237
  case "version":
56188
56238
  await printVersion();
56189
56239
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lakphy/local-router",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "packageManager": "bun@1.2.0",
5
5
  "workspaces": [
6
6
  "web"