INTENT RUNTIME · V2

把用户请求,变成
可验证的意图结构。

提取目标、保留约束、追踪变化。在 Node.js 或 MCP 中,使用你自己的模型。

npm install @devcodex/intent-runtime

Node.js ≥20 · JavaScript / TypeScript · MCP

从一句话,看见理解固定示例 · 不调用模型
查询订单000123,不要取消订单

保留用户要做的事,也保留明确的禁止事项。

本例已配置订单号 Schema,并通过 fields 选择 orderId。

参数与条件禁止事项正向要求
查看本例的输入配置

调用方提供这些材料;固定示例不在浏览器调用模型。

{
  "config": {
    "language": "zh-CN",
    "schema": {
      "type": "object",
      "properties": {
        "orderId": {
          "type": "string",
          "pattern": "^[0-9]+$"
        }
      }
    }
  },
  "request": {
    "input": "查询订单000123,不要取消订单",
    "fields": [
      "orderId"
    ]
  }
}
理解完整
  • 查询订单000123intent-2
    • 禁止不要取消订单
    orderId
    "000123"
orderId已验证

完整意图只保留在 effective;摘要不替代完整响应。

查看完整 JSON
{
  "slug": "native",
  "title": "字符串订单编号",
  "config": {
    "language": "zh-CN",
    "schema": {
      "type": "object",
      "properties": {
        "orderId": {
          "type": "string",
          "pattern": "^[0-9]+$"
        }
      }
    }
  },
  "request": {
    "input": "查询订单000123,不要取消订单",
    "fields": [
      "orderId"
    ]
  },
  "result": {
    "schemaVersion": "2.0-draft.6",
    "input": "查询订单000123,不要取消订单",
    "status": "complete",
    "turn": {
      "kind": "request",
      "normalizedInput": "查询订单000123,不要取消订单",
      "intentIds": [
        "intent-2"
      ],
      "changes": [
        {
          "operation": "add",
          "target": {
            "kind": "intent",
            "id": "intent-2"
          },
          "description": "新增本轮明确请求",
          "sourceRefs": [
            {
              "root": "input",
              "pointer": ""
            }
          ],
          "effect": "applied"
        },
        {
          "operation": "add",
          "target": {
            "kind": "constraint",
            "id": "constraint-2"
          },
          "description": "新增本轮明确请求",
          "sourceRefs": [
            {
              "root": "input",
              "pointer": ""
            }
          ],
          "effect": "applied"
        }
      ],
      "facts": {}
    },
    "effective": {
      "schemaVersion": "2.0-draft.6",
      "coverage": "complete",
      "scope": "current_request",
      "intents": [
        {
          "id": "intent-2",
          "domain": null,
          "action": "查询",
          "target": "订单000123",
          "goal": "查询订单000123",
          "understanding": "clear",
          "constraints": [
            {
              "id": "constraint-2",
              "kind": "prohibition",
              "text": "不要取消订单",
              "scope": {
                "type": "intent",
                "intentId": "intent-2"
              }
            }
          ],
          "inputs": {
            "orderId": "000123"
          },
          "references": [],
          "children": [],
          "extensions": {}
        }
      ],
      "constraints": [],
      "relations": [],
      "unresolved": []
    },
    "fieldResults": [
      {
        "container": "inputs",
        "intentId": "intent-2",
        "field": "orderId",
        "path": "/orderId",
        "status": "present",
        "trigger": "selection",
        "sourceRefs": [
          {
            "root": "input",
            "pointer": ""
          }
        ]
      }
    ],
    "issues": [],
    "inferences": []
  }
}
下载 JSON

从一次调用开始

一个模型,一次调用。

接入你的模型,调用 parse,再读取目标与约束。需要业务参数时,再添加 Schema。

intent.js
import { Intent, IntentError } from '@devcodex/intent-runtime';
import { createApiExecutor } from '@devcodex/intent-runtime/adapters/api';
const apiKey = process.env.INTENT_API_KEY;
const model = process.env.INTENT_MODEL;
if (!apiKey || !model)
    throw new Error('Set INTENT_API_KEY and INTENT_MODEL.');
const intent = new Intent({
    language: 'zh-CN',
    executor: createApiExecutor({ provider: 'openai', apiKey, model }),
});
const request = { input: '查询订单000123,不取消订单' };
try {
    const result = await intent.parse(request);
    console.log(JSON.stringify(result, null, 2));
    console.log('目标:', result.effective.intents.map(node => node.goal));
    console.log('需要澄清:', result.issues.map(issue => issue.message));
}
catch (error) {
    if (!(error instanceof IntentError))
        throw error;
    console.error(JSON.stringify(error.toJSON()));
    process.exitCode = 1;
}
finally {
    await intent.dispose();
}

先设置模型名称和 API Key。JS 项目设置 type: module,TS 按 ESM 编译;模型与网关均可自定义。

完整安装与运行步骤 →

沿用你的工作方式

接到你已有的应用里。

应用调用、当前宿主模型、独立服务或已有 MCP Server,选择与你的工程对应的一条路径。

  1. 01

    Node.js 应用

    JavaScript / TypeScript,连接模型与自有网关。

  2. 02

    Codex 当前模型

    保存配置并登记,无需额外模型 API Key。

  3. 03

    独立 MCP 服务

    通过 stdio 或 HTTP 连接,按需指定端口。

  4. 04

    已有 MCP Server

    在原有服务中增加工具,保留原有连接。

Intent Runtime 只理解你提供的材料。消息与历史由你提供,工具、授权和业务执行由应用管理。

如何消费结果 →接续下一轮 →处理问题与失败 →