npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@aishift/widget-sdk

v2.2.2

Published

# 使用例

Readme

AI-Shift widget SDK

使用例

import { createClient, Client, MesaageFormat } from '@aishift/widget-sdk'
async function asyncFunction() {
  // SDK クライアント作成
  const client = await createClient({
        tenantId: 'tenantId',
        projectId: 'projectId',
        tenantSubDomain: 'tenantSubDomain',
        updateMessageCallback: (type, messageId, message, isEnd) => {
          // メッセージが更新されたときのコールバック
        },
        addMessageCallback: message => {
          // メッセージが追加されたときのコールバック
        },
      })


  // メッセージ送信
  client.send({message: "こんにちは"}, onError: () => {
    console.error(error)
  })

  // promptId つきでメッセージ送信
  client.sendWithPrompt({
                  promptId: 'promptId',
                  scenarioVersion: '1',
                  message: "こんにちは",
                  errorCallback: error => {
                    console.error(error);
                  },
                });


  // 過去のメッセージ取得
  const pastMessages: MessageFormat[] = await client.getPastMessages({limit: 20, at: 1608623909884})

  // ウェルカムメッセージ取得
  const { welcomeMessage, recommendations } = client.getWelcomeMessage();

  // 初めてログインしたユーザかどうか
  client.isLoggedIn()

  // シナリオjson取得
  const scenario = await client.getScenarioJson()

  // シナリオ遷移状態保存
  client.storeScenarioState({ version: '1', sceneId: 'sceneId' });

  // シナリオ遷移状態取得
  const scenarioState = client.getScenarioState()
}

APIs

createClient

SDK クライアントを作成する

インターフェース

createClient: ({
  tenantId,
  tenantSubDomain,
  projectId,
  updateMessageCallback,
  addMessageCallback,
}: {
  tenantId: string;
  tenantSubDomain: string;
  projectId: string;
  updateMessageCallback: (
    type: string,
    messageId: string,
    message: MessageFormt,
    isEnd: boolean
  ) => void;
  addMessageCallback: (message: MessageFormat) => void;
}) => Promise<Client>;

引数

  • tenantId: テナント ID
  • tenantSubDomain: テナントサブドメイン
  • projectId: プロジェクト ID
  • updateMessageCallback: LLM による回答メッセージに変更があった時に呼ばれるコールバック
  • addMessageCallback: LLM による回答メッセージが新規作成された時に呼ばれるコールバック

返り値

  • Client: SDK クライアント

MessageFromat 型

{
  at: number,
  type: "message",
  messages: [
    {
      attachment: {
        mediaType: "plainText",
        payload: string,
        referenceUrls: {title: string, link: string}[],
        followUpUrls: {title: string, link: string}[]
      }
    }
  ],
  sender: {
    id: string,
    name: string,
    type: 'Bot' | 'Customer' | 'Operator'
  },
  isWelcome: boolean,
  referer: string,
  senderMessageId: string
  isEnd: boolean
}
  • at: メッセージが送信された時間 (unixtime)
  • messages[index].attachment.payload: メッセージ本文
  • messages[index].attachment.referenceUrls: LLM が回答に使用したリソースの URL のリスト
  • messages[index].attachment.followUpUrls: LLM 提案する回答をフォローするリソースの URL のリスト
  • sender.type: ボット or カスタマー (チャットユーザー) or オペレーター
  • senderMessageId: メッセージごとの一意な ID
  • isEnd: メッセージの更新が終わったかを判定するフラグ

getPastMessages

at より前のメッセージを最大 limit だけ取得する

インターフェース

getPastMessages: ({ limit, at }: { limit: number; at: number }) => Promise<MessageFormat[]>;

引数

  • limit: 取得するメッセージの最大数
  • at: 取得したいメッセージの最新時刻 (unixtime)

返り値

  • messages: MessageFormat型オブジェクトの配列

send

LLM にメッセージを送信する

インターフェース

send: ({ message, errorCallback }: { message: string; errorCallback: (error: Error) => void }) =>
  string;

引数

  • message: LLM に送信するメッセージ
  • errorCallback: エラーが発生したときに呼ばれるコールバック

返り値

  • senderMessageId: メッセージごとの一意な ID

sendWithPrompt

LLM にプロンプトを指定してメッセージを送信する

インターフェース

sendWithPrompt: ({
  message,
  promptId,
  scenarioVersion,
  errorCallback,
}: {
  message: string;
  promptId: string;
  scenarioVersion: string;
  errorCallback: (error: Error) => void;
}) => string;

引数

  • message: LLM に送信するメッセージ
  • promptId: プロンプトの ID
  • scenarioVersion: 固定シナリオのバージョン
  • errorCallback: エラーが発生したときに呼ばれるコールバック

返り値

  • senderMessageId: メッセージごとの一意な ID

getWelcomeMessage

ウェルカムメッセージ取得

インターフェース

getWelcomeMessage: () => {welcomeMessage: string; recommendations: string[]};

返り値

  • welcomeMessage: ウェルカムメッセージ
  • recommendations: オススメ質問の配列

isLoggedIn

ログイン済みかどうかを返す

isLoggedIn: () => Promise<boolean>;

返り値

  • isLoggedIn: ログイン済み -> true  未ログイン -> false

getCustomerInfo

カスタマー情報の取得をする

getCustomerInfo: () => Promise<{ customerId: string }>;

返り値

  • customerId: チャットユーザーの ID

unsubscribeMessageCallback

メッセージ更新コールバックの解除する

unsubscribeMessageCallback: () => void;

getScenarioJson

固定シナリオ JSON を返す

getScenarioJson: () => Promise<ScenarioJson>;

返り値

  • scenarioJson: 固定シナリオ JSON

ScenarioJson 型

type ScenarioJson = {
  scenario: Scene;
  version: string;
};

type Scene = {
  id: string;
  title: string;
  content: string;
  imagePath: string;
  children: Scene[];
  mainMessage?: string;
  promptId?: string;
  messageOptions?: {
    label: string;
    value: string;
  }[];
};

getScenarioState

固定シナリオの遷移状態を取得する

getScenarioState: () => { version: string; sceneId: string } | undefined;

返り値

  • version: 固定シナリオのバージョン
  • sceneId: 固定シナリオのシーン ID

storeScenarioState

固定シナリオの遷移状態を保存する

storeScenarioState: ({ version, sceneId }: { version: string; sceneId: string }) => void;

引数

  • version: 固定シナリオのバージョン
  • sceneId: 固定シナリオのシーン ID

getVersion

SDK のバージョンを返す

getVersion: () => string;

返り値

  • version: SDK のバージョン