@blod-nm/1kuan-act-01-cli 0.2.1 → 0.2.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blod-nm/1kuan-act-01-cli",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "type": "module",
5
5
  "description": "Internal operations CLI: invoke preset database functions via a gateway. Zero dependencies, MCP (stdio) support.",
6
6
  "license": "MIT",
package/src/main.js CHANGED
@@ -557,9 +557,11 @@ async function cmdCreate(argv) {
557
557
  console.log('about to deduct from account and create:')
558
558
  for (const line of confirmSummary(input)) console.log(` ${line}`)
559
559
  process.stdout.write('确认执行? [y/N] ')
560
- const chunks = []
561
- for await (const chunk of process.stdin) chunks.push(chunk)
562
- const answer = Buffer.concat(chunks).toString('utf8').trim().toLowerCase()
560
+ // 只读一行:TTY 的 stdin 不会 EOF,for-await 会永远等下一个字节
561
+ const readline = await import('node:readline')
562
+ const rl = readline.createInterface({ input: process.stdin, output: process.stderr })
563
+ const answer = await new Promise((resolve) => rl.question('', (a) => resolve(String(a).trim().toLowerCase())))
564
+ rl.close()
563
565
  if (answer !== 'y' && answer !== 'yes') {
564
566
  console.log('已取消')
565
567
  return 130
package/src/mcp.js CHANGED
@@ -13,7 +13,7 @@
13
13
 
14
14
  import { VERSION } from './version.js'
15
15
  import { loadConfig } from './store.js'
16
- import { resolveApikey, execPgsql, gatewayBase } from './tcb.js'
16
+ import { ACCOUNT_SQL, resolveApikey, execPgsql, gatewayBase } from './tcb.js'
17
17
  import { normalizeCreateRedpacket, buildCreateSql, claimTarget } from './redpacket.js'
18
18
 
19
19
  const SERVER_INFO = { name: 'act-01', version: VERSION }
@@ -96,7 +96,8 @@ function withClaimTarget(raw) {
96
96
  return packetNo ? { ...result, qr: { content: claimTarget(packetNo) } } : result
97
97
  }
98
98
 
99
- async function callTool(name, args) {
99
+ /** 导出仅为测试:mock tcb 后可以直接断言工具返回形状 */
100
+ export async function callTool(name, args) {
100
101
  if (name === 'redpacket_create' || name === 'redpacket_check') {
101
102
  const checkOnly = name === 'redpacket_check'
102
103
  const input = normalizeCreateRedpacket(args) // 校验失败抛 ValidationError
package/src/tcb.js CHANGED
@@ -39,6 +39,8 @@ export const ACCOUNT_SQL = `
39
39
  export async function execPgsql(config, apikey, sql) {
40
40
  const base = gatewayBase(config)
41
41
  let res
42
+ const abort = new AbortController()
43
+ const timer = setTimeout(() => abort.abort(), 45000)
42
44
  try {
43
45
  res = await fetch(`${base}/v1/rdb/exec-pgsql`, {
44
46
  method: 'POST',
@@ -47,9 +49,13 @@ export async function execPgsql(config, apikey, sql) {
47
49
  Authorization: `Bearer ${apikey}`,
48
50
  },
49
51
  body: JSON.stringify({ sql, role: PG_ROLE }),
52
+ signal: abort.signal,
50
53
  })
51
54
  } catch (err) {
52
- throw new Error(`网关连接失败:${err instanceof Error ? err.message : String(err)}`)
55
+ const timedOut = err instanceof Error && err.name === 'AbortError'
56
+ throw new Error(timedOut ? '网关请求超时(45s)' : `网关连接失败:${err instanceof Error ? err.message : String(err)}`)
57
+ } finally {
58
+ clearTimeout(timer)
53
59
  }
54
60
 
55
61
  const text = await res.text()
package/src/version.js CHANGED
@@ -3,4 +3,4 @@
3
3
  * (test/version.test.js 会断言两者一致,防止再漏升)。
4
4
  */
5
5
 
6
- export const VERSION = '0.2.1'
6
+ export const VERSION = '0.2.3'