@felan-ai/ext-ask-user

中文文档
0.12.1发布于 2026/11/13MITTypeScriptES Module构建来源已验证近 30 天下载 2845

Portable Felan ask-user extension with a rich Pi TUI adapter

原始使用文档
文档目录9 节
  1. Usage
  2. Tool input
  3. Generic form adapter
  4. Browser-safe form codec
  5. Client rendering
  6. Attribution
  7. Package boundary and requirements
  8. Development
  9. Related documentation

@felan-ai/ext-ask-user

Portable Felan ask_user extension using generic UI forms. Optional native rendering belongs to the client, not this package.

Usage

import askUser from '@felan-ai/ext-ask-user';

const extension = askUser;

The default root uses the always-present pi.ui.request API. It declares no service requirements. The host supplies generic form delivery, answer eligibility, cancellation, and deferred delivery. The extension does not inspect client kind or hasUI. The optional ask-user.wizard version 2 hint carries normalized questions in data.questions for client rendering without changing form fields or outcomes.

For an explicitly chosen host, the named factory remains available:

import { createAskUserExtension } from '@felan-ai/ext-ask-user';
const extension = createAskUserExtension(deliveryHost);

Cloud or remote hosts implement AskUserHost. The core extension owns the tool schema, normalization, response validation, sequential tool execution, progress details, and agent-facing result text. The host owns presentation and delivery. Host outcomes are answered, cancelled, or deferred; deferred outcomes carry a required interaction ID so a remote host can correlate the next user turn. Each host call also receives the Pi tool-call ID and session ID.

Tool input

ask_user supports:

  • one question or a 1-4 question wizard
  • provider-safe { title, description? } option objects in the tool schema, with runtime compatibility for legacy string options and common proxy aliases
  • single-select, multi-select, and freeform answers
  • optional comments on structured selections
  • optional local-adapter overlay/inline modes, single-select layouts, and shortcuts
  • prompt timeout

Top-level question fields provide defaults to entries in questions[]. Questions receive stable q1 through q4 IDs in normalized requests and structured result details.

Generic form adapter

A single call produces one form, including all wizard questions. Questions, headers, context, option titles, and descriptions appear without truncation. Display Markdown is escaped so HTML, links, and formatting supplied as text remain literal; control characters are displayed as escape sequences. Option labels are plain text.

Fields use stable question IDs (q1–q4) and suffixes .mode, .selection, .text, and .comment where applicable. Choice values are option1, option2, and so on, mapped back to the original option titles only after validation. When both choice and freeform answers are available, an explicit answer type is required. Wizards also offer an explicit skip type; at least one question must be answered. There are no default answers. Inactive fields may be omitted; empty text and multi-select fields are also allowed. Conflicting non-empty fields, missing answers, unknown options, duplicate choices, excessive selections, and comments on freeform answers are rejected.

Forms declare submit and cancel actions. Display modes, layouts, and shortcuts do not alter generic form behavior. The tool's abort signal and optional timeout are forwarded to pi.ui.request; deferred interaction IDs are retained. Unsupported UI maps to an unavailable cancellation. Host drain and restart map to abort cancellation with the original cause in the message.

The form hint's encoded JSON data must fit 128 KiB. Written answers and comments each have a 32 KiB UTF-8 limit. Multi-select questions support at most 64 options.

Requests that exceed the form limits return an explicit tool error before delivery; oversized answers are also rejected. Content and option lists are never shortened to fit. These bounds apply to the generic adapter, not to custom named hosts.

Browser-safe form codec

@felan-ai/ext-ask-user/data exports the question and answer contracts, normalizeAskUserOption, and:

const ASK_USER_FORM_HINT = { id: 'ask-user.wizard', version: '2' };
readAskUserForm(form: UiForm): AskUserQuestion[] | null;
encodeAskUserFormAnswer(form: UiForm, answers: readonly AskUserQuestionAnswer[] | null): UiFormAnswer;
decodeAskUserFormAnswer(questions: readonly AskUserQuestion[], answer: UiFormAnswer): AskUserQuestionAnswer[] | null;

readAskUserForm validates the hint, questions, matching field definitions and submit/cancel actions. It returns null for unsupported hints (including version 1), invalid payloads or inconsistent forms; clients should render those forms generically rather than parse their Markdown. Question context and option descriptions are plain text, not trusted HTML or Markdown.

The encoder maps option titles to form option IDs and omitted wizard questions to explicit skips. It rejects empty or conflicting answers and validates the result against the form. Passing null encodes cancellation. The decoder validates the generic answer and returns null for cancellation; at least one wizard question must otherwise be answered. The data entry has no runtime dependency on Agent Core or Node APIs and can be used in browser bundles.

Client rendering

Felan's TUI renders the optional wizard hint. Inline questions use two full-width horizontal separators; overlay questions use a complete four-edge frame. TUI mode provides searchable option descriptions, split-pane previews on wide terminals, multi-select, freeform and comment editors, wizard navigation and review, overlay hiding, abort handling, and timeout handling. Long context starts collapsed so choices remain visible; press ctrl+e to expand or collapse it. Multi-select viewports are bounded by rendered rows and keep the active choice visible. Other clients use the same generic form; a client without interactive form support returns an unavailable outcome.

For compatibility with older transcripts and schema-mangling proxies, runtime option normalization also accepts string, number, and boolean entries and the object keys label, text, value, name, and option. Unusable entries return a validation error instead of silently falling back to a freeform prompt.

Felan TUI defaults live under presentation.askUser in $FELAN_AGENT_DIR/tui/settings.json, through /settings, or through TUI-only CLI options:

{
  "presentation": {
    "askUser": {
      "displayMode": "inline",
      "singleSelectLayout": "auto",
      "overlayToggleKey": "alt+o",
      "commentToggleKey": "ctrl+g"
    }
  }
}

The defaults are inline, auto, alt+o, and ctrl+g, respectively. Use off, none, disabled, or an empty value to disable either shortcut. Per-call tool hints remain optional and pass unchanged to named hosts. The generic form adapter ignores them; Felan TUI uses its own preferences. Legacy extensionConfig.askUser values are read only when a local preference is absent. Generated CLI names are --ask-user-display-mode, --ask-user-single-select-layout, --ask-user-overlay-toggle-key, and --ask-user-comment-toggle-key.

Attribution

The local interface is adapted from pi-ask-user by Enzo Lucchesi. See NOTICE and LICENSE for source and license details.

Package boundary and requirements

The portable package owns the tool schema, normalization, validation, generic form mapping, progress, and result text. Hosts own delivery through pi.ui or an explicit AskUserHost. The package requires a compatible @felan-ai/agent-core peer, Session Protocol and TypeBox. It exports no TUI entrypoint.

Development

Source: packages/ext-ask-user in https://github.com/felan-ai/felan.

corepack enable
pnpm install --frozen-lockfile
pnpm --filter @felan-ai/ext-ask-user build
pnpm --filter @felan-ai/ext-ask-user type-check
pnpm --filter @felan-ai/ext-ask-user test

版本与发布记录

@felan-ai/ext-ask-user 共发布 33 个版本,首次发布于 2026/08/06;过去 12 个月发布了 33 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.12.1latest2026/11/131 天前
0.12.02026/11/059 天前
0.11.52026/11/0212 天前
0.11.42026/10/3015 天前
0.11.32026/10/3015 天前
0.11.22026/10/2322 天前

其他发布通道:bootstrap → 0.0.0。

关于 @felan-ai/ext-ask-user 的常见问题

@felan-ai/ext-ask-user 是什么?

Portable Felan ask-user extension with a rich Pi TUI adapter

如何安装 @felan-ai/ext-ask-user?

在项目目录运行 npm install @felan-ai/ext-ask-user,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@felan-ai/agent-core(^0.15.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@felan-ai/ext-ask-user 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@felan-ai/ext-ask-user 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@felan-ai/ext-ask-user 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.19.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@felan-ai/ext-ask-user 可以商用吗?

@felan-ai/ext-ask-user 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@felan-ai/ext-ask-user 的下载量有多少?

根据 npm 官方下载统计,@felan-ai/ext-ask-user 在 2026/10/15 – 2026/11/13 这 30 天内被下载 2,845 次,日均约 95 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@felan-ai/ext-ask-user 还在维护吗?

最新版本 0.12.1 发布于 2026/11/13(1 天前);至今共发布 33 个版本,其中过去 12 个月发布了 33 个;首次发布于 2026/08/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。