メインコンテンツまでスキップ

Quickstart

ログインや会員登録なしで、無料で Thinkfree Office をインストールしてドキュメントを編集してみましょう。Editor SDK を使って、ブラウザーで開いているドキュメントを JavaScript から直接制御できます。 AI エージェントを開発していますか?Editor AI SDK を使うと、AI エージェントにドキュメント編集機能を追加できます。

Thinkfree Office を準備する​

1. コンテナーを起動する​

Docker をインストールし、CPU 2 コア以上とメモリー 4 GB 以上を確保します。 ターミナルで次のコマンドを実行し、30 日間有効な Trial ライセンスを含む Thinkfree Office コンテナーを起動します。

商用利用できる無料ライセンス

商用目的で使用できる Free Commercial ライセンスも無料で提供しています。 詳しくは Free Commercial ライセンスの案内を参照してください。

docker run --name thinkfree-office-trial \
-p 8080:8070 \
thinkfree/office-single-node-trial:latest

Thinkfree Office の初期化には約 2 分かかります。所要時間は実行環境によって異なります。 実行ログが表示されているターミナルは開いたまま、ブラウザーで次の手順に進みます。

2. サンプルを開く​

コンテナー内には、サンプルドキュメントとあらかじめ接続された host-storage アダプターが用意されています。Thinkfree Office の初期化が完了すると、すぐにドキュメントを開けます。

次のアドレスをブラウザーで開きます。リンクをクリックすると、新しいタブでサンプルドキュメントが開きます。

http://localhost:8080/cloud-office/api/host-storage/sample.docx/open?app=WORD_EDITOR&user_id=local-user&docId=quickstart01 ↗

Word エディターが開いたら、サンプルドキュメントの内容を編集できます。

3. ドキュメントディレクトリを接続する​

実行中のコンテナーを停止します。次のコマンドのように -v オプションで、コンピューター上のドキュメントディレクトリをコンテナーの /home/thinkfree/docs に接続します。

docker run --name thinkfree-office-documents \
-p 8080:8070 \
-v "/absolute/path/to/documents:/home/thinkfree/docs" \
thinkfree/office-single-node-trial:latest

ドキュメントを開く URL は次の形式です。{relative-file-path} には、ドキュメントディレクトリを基準としたファイルの相対パスを指定します。

http://localhost:8080/cloud-office/api/host-storage/{relative-file-path}/open?app=WORD_EDITOR&user_id=local-user&docId=quickstart01

たとえば、コンピューター上の /absolute/path/to/documents/reports/proposal.docx を開くには、相対パス reports/proposal.docx を指定して次の URL を作成します。

http://localhost:8080/cloud-office/api/host-storage/reports/proposal.docx/open?app=WORD_EDITOR&user_id=local-user&docId=quickstart01 ↗

ファイル名やフォルダー名に空白や URL エンコードが必要な文字が含まれている場合は、/ で区切られた各名前をエンコードします。

Editor SDK​

Editor SDK を使うと、ブラウザーで開いているドキュメントを制御できます。

この例では、localhost の HTTP Thinkfree Office を使用します。お客様のサービスのページも localhost の HTTP アドレスで提供し、HTTP 用の Cookie 設定を適用してください。別のドメイン・IP アドレスや HTTPS を使用する場合は、例を適用する前に iframe・新しいタブの使用条件を確認してください。

アプリケーションのページに次の iframe を追加します。

<iframe
id="office-frame"
title="Thinkfree Office document"
src="http://localhost:8080/cloud-office/api/host-storage/sample.docx/open?app=WORD_EDITOR&user_id=local-user&docId=quickstart01"
style="width: 100%; height: 600px; border: 0;"
></iframe>

Editor SDK は、npm で公開されている @thinkfree.dev/tfo-sdk パッケージとして提供されます。プロジェクトディレクトリで次のコマンドを実行してインストールします。

npm install @thinkfree.dev/tfo-sdk

インストールが完了したら、上記の iframe を追加したページで次の JavaScript コードを実行します。

import { Office } from "@thinkfree.dev/tfo-sdk";

// Connect to the already-open Word editor.
const word = Office.word(document.querySelector("#office-frame"));
await word.whenReady();

// Read the document body.
const doc = word.getDocument();
const body = await doc.getBody();
console.log(await body.getText());

ブラウザーのコンソールにドキュメントの本文が出力されれば、SDK の接続と Editor SDK の関数呼び出しは正常に動作しています。 続いて、次のコードで段落を追加できます。

// Append a paragraph without replacing existing text.
await body.insertParagraph("Hello from Editor SDK", { position: "end" });

アプリケーションを終了するときや編集画面を離れるときは、word.disconnect() を呼び出して SDK の接続を解除してください。

Editor SDK Playground では、Thinkfree Office をインストールしなくても SDK の機能を直接実行できます。 SDK の詳細は Editor SDK ガイドをご確認ください。

Editor AI SDK​

Editor AI SDK は、npm で公開されている @thinkfree.dev/tfo-ai-sdk パッケージとして提供されます。Editor SDK が含まれているため、このパッケージだけをインストールします。ルートのエントリーポイントから Office も import できます。

npm install @thinkfree.dev/tfo-ai-sdk

Editor AI SDK は、AI エージェントが Thinkfree Office のエディターを簡単に使用できるように、さまざまな機能を提供します。 bridgeToolsViaSdk() で、Editor SDK の Tool を AI エージェントの連携部に登録できます。各 Tool には、名前、説明、入力スキーマと execute(args) が含まれます。 AI エージェントが状況に合った Tool を選択し、その Tool の execute(args) を呼び出すと、Editor SDK で接続された Thinkfree Office のドキュメントを読み取ったり編集したりできます。

AI エージェントはモデルとの接続、会話履歴の管理、Tool の選択、権限の検証などを行い、 Editor AI SDK は Thinkfree Office ドキュメントの機能を照会・実行する部分を担当します。

次のコードの askAgent、validateAndApprove、returnToolResult は、AI エージェント側で実装する必要がある関数です。 AI エージェントのフローに合わせて Editor AI SDK の関数を接続できます。 次の連携部は、登録された Tool のうち insert_text だけを保持して AI エージェントに提供します。Tool の定義とレスポンスの形式はコードのコメントを参照してください。

import { bridgeToolsViaSdk } from "@thinkfree.dev/tfo-ai-sdk";

// Continue with the connected word handle from the Editor SDK section.
await word.whenReady();

const agentTools = new Map();
const toolBridge = await bridgeToolsViaSdk(word, {
registerTool(tool) {
// Expose only the tool approved for this task.
if (tool.name === "insert_text") agentTools.set(tool.name, tool);
},
unregisterTool(name) { agentTools.delete(name); },
});
window.addEventListener("pagehide", () => toolBridge.unregisterAll());

// Customer-owned integration hooks, NOT Editor AI SDK methods:
// askAgent: send tools to your agent/model in its required schema format;
// normalize its response to { toolCalls: [{ id, name, args }] }.
// validateAndApprove: validate args against inputSchema, check permissions,
// and obtain any required user confirmation; reject by throwing an error.
// returnToolResult: return the result to the same agent conversation by call ID.
async function runAgentTurn({ askAgent, validateAndApprove, returnToolResult }) {
const tools = [...agentTools.values()];
const definitions = tools.map(({ name, description, inputSchema }) => ({
name, description, inputSchema,
}));

// Your agent receives schemas, not JavaScript execute functions.
// Its model chooses a tool and arguments; the SDK does not choose them.
const response = await askAgent({
instruction: "Insert a paragraph saying Hello from the agent.",
tools: definitions,
});

for (const call of response.toolCalls ?? []) {
const tool = tools.find((item) => item.name === call.name);
if (!tool) throw new Error("Tool is not allowed: " + call.name);
await validateAndApprove({ call, inputSchema: tool.inputSchema });

// For an insert_text selection, this is that tool object's execute(args).
// Editor AI SDK dispatches the call to the connected Office editor.
const result = await tool.execute(call.args);

// Preserve content/isError and the call ID so your agent can continue.
await returnToolResult({ toolCallId: call.id, result });
}
}
// Call runAgentTurn with your own three implementations.
// This example defines one turn; it does not create or run an AI agent.

たとえば AI エージェントが insert_text と引数を返した場合は、許可された Tool かどうかを確認して引数を検証してから、その Tool の execute(args) を呼び出します。結果に isError がある場合は成功として扱わず、そのまま AI エージェントに渡します。 結果のテキストは ToolResult({ success, data } または { success: false, failure: { code, message } })なので、AI エージェントは文章を解釈する代わりに failure.code で分岐できます。チャット UI やエージェントループまで Thinkfree が提供する方法については、連携方法の選択を参照してください。

Editor AI SDK を接続した AI エージェントの動作を直接確認できるように、 Editor AI SDK Playground を用意しました。今すぐ試してみてください。 詳しくは Editor AI SDK ガイドを参照してください。

Free Commercial ライセンスの案内​

Free Commercial ライセンスを使用すると、Thinkfree Office を商用サービスで無料で使用できます。 同時接続数 20(MCC 20)をサポートします。ライセンスは 180 日間有効で、継続して延長することもできます。 申請・ダウンロード・インストールの方法は、Thinkfree Office の準備をご確認ください。