@concord-consortium/lara-interactive-api

中文文档
1.15.0发布于 2026/10/08MITTypeScriptCommonJS近 30 天下载 1985

LARA Interactive API client and types

原始使用文档
文档目录5 节
  1. API documentation
  2. Installation
  3. Usage
  4. API functions
  5. Hooks

API documentation

A TypeScript-based API for the LARA Interactive API. This also includes all the types for the API which are shared with the server-side Typescript files that implement the LARA-side of the API.

NOTE: this file (in /docs) is auto-generated as part of the lara-typescript build using TypeDoc by combining the API client's readme file with auto-generated output. If you wish to edit this document please edit lara-typescript/src/interactive-api-client/README.md.

Installation

First install the package:

npm i --save @concord-consortium/lara-interactive-api

Then import it into your code:

import * as interactiveApi from "@concord-consortium/lara-interactive-api" or import just necessary functions: import { setHeight, useInteractiveState } from "@concord-consortium/lara-interactive-api"

the API is compiled TypeScript and includes the typings in .d.ts files in the package. These typings are automatically loaded by the TypeScript compiler so you do now need to install a separate @types/... package.

Usage

API functions

All the Interactive API helpers are exported as single functions. For example;

import { setHeight, setHint, getAuthInfo } from "@concord-consortium/lara-interactive-api"

Some functions might accept types, e.g. getInteractiveState<InteractiveState>(). When there are more types accepted, the order of the type variables is important, it is InteractiveState, AuthoredState, DialogState, and IGlobalInteractiveState. If you do wish to skip a type variable just use {} in its place and any type variable left off on the end defaults to {}, eg:

const getInitInteractiveMessage<IInteractiveState, {}, {}, IGlobalInteractiveState>();

Hooks

If you are using React you will instead want to the use the hooks which wrap the API functions in a more easily used form. All the hooks start with use prefix. To use the hook first import it:

import { useInteractiveState } from "@concord-consortium/lara-interactive-api"

and then call the hook using your type variables in your React component.

Here is a minimal example of a useInteractiveState hook:

const { interactiveState, setInteractiveState } = useInteractiveState<IInteractiveState>();
...
const handleButtonClick = () => {
  // Functional update, usually safer option:
  setInteractiveState((prevState: InteractiveState) => ({ numButtonPresses: prevState.numButtonPresses + 1 }));
  // Or regular update that can cause troubles when new state is based on the previous one:
  // setInteractiveState({ numButtonPresses: interactiveState.numButtonPresses + 1 });
}
...
<button onClick={handleButtonClick}>{interactiveState.numButtonPresses}</button>

Calling the setInteractiveState method returned by the hook will both update the state held inside the hook and also send the message to LARA. This means that calling setInteractiveState will trigger a new React render of your components that use the useInteractiveState hook.

The same applies to other state-based hooks and their setters:

  • useAuthoredState
  • useGlobalInteractiveState

版本与发布记录

@concord-consortium/lara-interactive-api 共发布 99 个版本,首次发布于 2020/05/21;过去 12 个月发布了 16 个版本。

版本发布日期距今
1.15.0latest2026/10/081 个月前
1.15.0-pre.0beta2026/10/081 个月前
1.14.02026/07/024 个月前
1.14.0-pre.02026/06/264 个月前
1.13.02026/03/168 个月前
1.13.0-pre.22026/03/108 个月前

关于 @concord-consortium/lara-interactive-api 的常见问题

@concord-consortium/lara-interactive-api 是什么?

LARA Interactive API client and types

如何安装 @concord-consortium/lara-interactive-api?

在项目目录运行 npm install @concord-consortium/lara-interactive-api,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=16.9.0)、react-dom(>=16.9.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@concord-consortium/lara-interactive-api 支持 TypeScript 吗?

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

@concord-consortium/lara-interactive-api 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@concord-consortium/lara-interactive-api 可以商用吗?

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

@concord-consortium/lara-interactive-api 的下载量有多少?

根据 npm 官方下载统计,@concord-consortium/lara-interactive-api 在 2026/10/11 – 2026/11/09 这 30 天内被下载 1,985 次,日均约 66 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@concord-consortium/lara-interactive-api 还在维护吗?

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