@gui-chat-plugin/tictactoe 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ [![npm version](https://badge.fury.io/js/%40gui-chat-plugin%2Ftictactoe.svg)](https://badge.fury.io/js/%40gui-chat-plugin%2Ftictactoe)
1
2
  # GUIChatPluginTicTacToe
2
3
 
3
4
  Tic-Tac-Toe game plugin for GUI Chat.
@@ -97,4 +98,4 @@ yarn run dev
97
98
  | `yarn lint` | ESLintチェック |
98
99
  | `./check-plugin-structure.sh` | ファイル構成チェック |
99
100
  | `./check-mulmochat-integration.sh` | MulmoChat統合チェック |
100
- | `./refresh-in-mulmochat.sh` | MulmoChatに反映 |
101
+ | `./refresh-in-mulmochat.sh` | MulmoChatに反映 |
package/dist/core.cjs CHANGED
@@ -1,9 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y="playTicTacToe",T={type:"function",name:y,description:"Play Tic-Tac-Toe (Noughts and Crosses) game with the user. You can start a new game or make moves on the 3x3 board.",parameters:{type:"object",properties:{action:{type:"string",enum:["new_game","move"],description:"The action to perform: start a new game or make a move"},col:{type:"number",description:"Column position for the move (0-2, required for 'move' action). Left=0, Center=1, Right=2",minimum:0,maximum:2},row:{type:"number",description:"Row position for the move (0-2, required for 'move' action). Top=0, Middle=1, Bottom=2",minimum:0,maximum:2},board:{type:"array",description:"Current 3x3 board state BEFORE the move (required for 'move' action). Pass the current board state as-is.",items:{type:"array",items:{type:"string",enum:[".","X","O"]}}},currentSide:{type:"string",enum:["X","O"],description:"Current player's side (required for 'move' action). X always goes first."},playerNames:{type:"object",description:"Player assignments (required for 'move' action)",properties:{X:{type:"string",enum:["user","computer"]},O:{type:"string",enum:["user","computer"]}},required:["X","O"]},firstPlayer:{type:"string",enum:["user","computer"],description:"Optional: Which player should play as X (goes first) for 'new_game' action. If not specified, will be chosen randomly."}},required:["action"],additionalProperties:!1}},f=`You can play Tic-Tac-Toe with users using the playTicTacToe tool.
2
-
3
- IMPORTANT: When the user specifies a move (e.g., "I want to play at top-left, which is row=0, col=0"), you MUST call the playTicTacToe tool with action="move", NOT respond with text.
4
-
5
- Game rules:
6
- 1. Start a new game with action="new_game"
7
- 2. For moves, use action="move" with row (0-2) and col (0-2), plus the current board state
8
- 3. X always goes first. Win by getting 3 in a row (horizontal, vertical, or diagonal)
9
- 4. Positions: row=0 is top, row=2 is bottom; col=0 is left, col=2 is right`,M=[[{row:0,col:0},{row:0,col:1},{row:0,col:2}],[{row:1,col:0},{row:1,col:1},{row:1,col:2}],[{row:2,col:0},{row:2,col:1},{row:2,col:2}],[{row:0,col:0},{row:1,col:0},{row:2,col:0}],[{row:0,col:1},{row:1,col:1},{row:2,col:1}],[{row:0,col:2},{row:1,col:2},{row:2,col:2}],[{row:0,col:0},{row:1,col:1},{row:2,col:2}],[{row:0,col:2},{row:1,col:1},{row:2,col:0}]];function P(){const r=[];for(let o=0;o<3;o++)r[o]=new Array(3).fill(".");return r}function S(r){return r.map(o=>[...o])}function I(r){return r==="X"?"O":"X"}function p(r){const o=[];for(let t=0;t<3;t++)for(let e=0;e<3;e++)r[t][e]==="."&&o.push({row:t,col:e});return o}function L(r,o,t,e){const n=S(r);return n[o][t]=e,n}function u(r){let o=0,t=0,e=0;for(let n=0;n<3;n++)for(let i=0;i<3;i++){const s=r[n][i];s==="X"?o++:s==="O"?t++:e++}return{X:o,O:t,empty:e}}function _(r){for(const o of M){const t=o.map(e=>r[e.row][e.col]);if(t[0]!=="."&&t[0]===t[1]&&t[1]===t[2])return{winner:t[0],winningLine:o}}return{winner:null,winningLine:null}}function X(r){const{winner:o,winningLine:t}=_(r);return o?{isTerminal:!0,winner:o,winningLine:t}:u(r).empty===0?{isTerminal:!0,winner:"draw",winningLine:null}:{isTerminal:!1,winner:null,winningLine:null}}function g(r){if(r.action==="new_game"){const{playerNames:m}=r,c=P(),N=p(c),O=u(c);return{board:c,currentSide:"X",playerNames:m,legalMoves:N,counts:O,isTerminal:!1,winner:null,winningLine:null,lastAction:{type:"new_game"}}}const{row:o,col:t,board:e,currentSide:n,playerNames:i}=r;if(o<0||o>2||t<0||t>2){const m=p(e),c=u(e);return{board:e,currentSide:n,playerNames:i,legalMoves:m,counts:c,isTerminal:!1,winner:null,winningLine:null,lastAction:{type:"move",row:o,col:t},error:`Invalid move: (${o}, ${t}) is out of bounds. Row and column must be 0-2.`}}if(e[o][t]!=="."){const m=p(e),c=u(e);return{board:e,currentSide:n,playerNames:i,legalMoves:m,counts:c,isTerminal:!1,winner:null,winningLine:null,lastAction:{type:"move",row:o,col:t},error:`Invalid move: (${o}, ${t}) is already occupied by ${e[o][t]}.`}}const s=L(e,o,t,n),a=I(n),l=p(s),d=u(s),{isTerminal:w,winner:h,winningLine:b}=X(s);return{board:s,currentSide:a,playerNames:i,legalMoves:l,counts:d,isTerminal:w,winner:h,winningLine:b,lastAction:{type:"move",row:o,col:t}}}const v=async(r,o)=>{try{let t;if(o.action==="new_game"){let a;o.firstPlayer?a=o.firstPlayer:a=Math.random()<.5?"computer":"user",t={action:"new_game",playerNames:{X:a,O:a==="user"?"computer":"user"}}}else if(o.action==="move"){if(typeof o.row!="number"||typeof o.col!="number"||!o.board||!o.currentSide||!o.playerNames)throw new Error("Move action requires row, col, board, currentSide, and playerNames parameters");t={action:"move",row:o.row,col:o.col,board:o.board,currentSide:o.currentSide,playerNames:o.playerNames}}else throw new Error(`Unknown action: ${o.action}`);const e=g(t);if(e.error){const a=e.playerNames[e.currentSide]==="computer",l=e.legalMoves.map(w=>`(row=${w.row}, col=${w.col})`).join(", "),d=a?`Invalid move attempted. You must make a valid move. Legal moves are: ${l}. Choose one of these moves.`:`Invalid move attempted. Tell the user they must make a valid move. Legal moves are: ${l}.`;return{message:e.error,jsonData:e,instructions:d,updating:!0}}let n="";if(e.lastAction.type==="new_game")n="Started a new Tic-Tac-Toe game! X goes first.";else if(e.lastAction.type==="move"){const a=$(e.lastAction.row,e.lastAction.col);n=`Played ${e.board[e.lastAction.row][e.lastAction.col]==="X"?"O":"X"} at ${a} (row=${e.lastAction.row}, col=${e.lastAction.col}).`}e.isTerminal&&(e.winner==="draw"?n+=" Game over - it's a draw!":e.winner&&(n+=` Game over - ${e.winner} wins!`));const i=e.playerNames[e.currentSide]==="computer",s=e.isTerminal?"The game is over. Briefly announce the result. Do NOT draw the board - the user can see it in the GUI.":i?"It is your turn. You MUST call playTicTacToe with action='move' immediately. Do NOT describe the board or explain - just make your move.":"It is the user's turn. Do NOT draw or describe the board - the user can see it in the GUI. Just say it's their turn briefly. When they specify a move, call playTicTacToe with action='move'.";return{message:n,jsonData:e,instructions:s,instructionsRequired:e.isTerminal||i,updating:o.action!=="new_game"}}catch(t){return console.error("ERR: TicTacToe game error",t),{message:`TicTacToe game error: ${t instanceof Error?t.message:"Unknown error"}`,instructions:"Acknowledge that there was an error with the TicTacToe game and suggest trying again."}}};function $(r,o){const t=["Top","Middle","Bottom"],e=["Left","Center","Right"];return`${t[r]}-${e[o]}`}const A={toolDefinition:T,execute:v,generatingMessage:"Processing TicTacToe move...",isEnabled:()=>!0,systemPrompt:f},E=[{name:"New Game (User plays X)",args:{action:"new_game",firstPlayer:"user"}},{name:"New Game (Computer plays X)",args:{action:"new_game",firstPlayer:"computer"}}];exports.SYSTEM_PROMPT=f;exports.TOOL_DEFINITION=T;exports.TOOL_NAME=y;exports.executeTicTacToe=v;exports.playTicTacToe=g;exports.pluginCore=A;exports.samples=E;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./samples-5nF6v9m_.cjs`);exports.SYSTEM_PROMPT=e.a,exports.TOOL_DEFINITION=e.o,exports.TOOL_NAME=e.s,exports.executeTicTacToe=e.n,exports.playTicTacToe=e.i,exports.pluginCore=e.r,exports.samples=e.t;
package/dist/core.js CHANGED
@@ -1,281 +1,2 @@
1
- const h = "playTicTacToe", v = {
2
- type: "function",
3
- name: h,
4
- description: "Play Tic-Tac-Toe (Noughts and Crosses) game with the user. You can start a new game or make moves on the 3x3 board.",
5
- parameters: {
6
- type: "object",
7
- properties: {
8
- action: {
9
- type: "string",
10
- enum: ["new_game", "move"],
11
- description: "The action to perform: start a new game or make a move"
12
- },
13
- col: {
14
- type: "number",
15
- description: "Column position for the move (0-2, required for 'move' action). Left=0, Center=1, Right=2",
16
- minimum: 0,
17
- maximum: 2
18
- },
19
- row: {
20
- type: "number",
21
- description: "Row position for the move (0-2, required for 'move' action). Top=0, Middle=1, Bottom=2",
22
- minimum: 0,
23
- maximum: 2
24
- },
25
- board: {
26
- type: "array",
27
- description: "Current 3x3 board state BEFORE the move (required for 'move' action). Pass the current board state as-is.",
28
- items: {
29
- type: "array",
30
- items: {
31
- type: "string",
32
- enum: [".", "X", "O"]
33
- }
34
- }
35
- },
36
- currentSide: {
37
- type: "string",
38
- enum: ["X", "O"],
39
- description: "Current player's side (required for 'move' action). X always goes first."
40
- },
41
- playerNames: {
42
- type: "object",
43
- description: "Player assignments (required for 'move' action)",
44
- properties: {
45
- X: {
46
- type: "string",
47
- enum: ["user", "computer"]
48
- },
49
- O: {
50
- type: "string",
51
- enum: ["user", "computer"]
52
- }
53
- },
54
- required: ["X", "O"]
55
- },
56
- firstPlayer: {
57
- type: "string",
58
- enum: ["user", "computer"],
59
- description: "Optional: Which player should play as X (goes first) for 'new_game' action. If not specified, will be chosen randomly."
60
- }
61
- },
62
- required: ["action"],
63
- additionalProperties: !1
64
- }
65
- }, b = `You can play Tic-Tac-Toe with users using the playTicTacToe tool.
66
-
67
- IMPORTANT: When the user specifies a move (e.g., "I want to play at top-left, which is row=0, col=0"), you MUST call the playTicTacToe tool with action="move", NOT respond with text.
68
-
69
- Game rules:
70
- 1. Start a new game with action="new_game"
71
- 2. For moves, use action="move" with row (0-2) and col (0-2), plus the current board state
72
- 3. X always goes first. Win by getting 3 in a row (horizontal, vertical, or diagonal)
73
- 4. Positions: row=0 is top, row=2 is bottom; col=0 is left, col=2 is right`, N = [
74
- // Rows
75
- [{ row: 0, col: 0 }, { row: 0, col: 1 }, { row: 0, col: 2 }],
76
- [{ row: 1, col: 0 }, { row: 1, col: 1 }, { row: 1, col: 2 }],
77
- [{ row: 2, col: 0 }, { row: 2, col: 1 }, { row: 2, col: 2 }],
78
- // Columns
79
- [{ row: 0, col: 0 }, { row: 1, col: 0 }, { row: 2, col: 0 }],
80
- [{ row: 0, col: 1 }, { row: 1, col: 1 }, { row: 2, col: 1 }],
81
- [{ row: 0, col: 2 }, { row: 1, col: 2 }, { row: 2, col: 2 }],
82
- // Diagonals
83
- [{ row: 0, col: 0 }, { row: 1, col: 1 }, { row: 2, col: 2 }],
84
- [{ row: 0, col: 2 }, { row: 1, col: 1 }, { row: 2, col: 0 }]
85
- ];
86
- function O() {
87
- const n = [];
88
- for (let o = 0; o < 3; o++)
89
- n[o] = new Array(3).fill(".");
90
- return n;
91
- }
92
- function M(n) {
93
- return n.map((o) => [...o]);
94
- }
95
- function P(n) {
96
- return n === "X" ? "O" : "X";
97
- }
98
- function p(n) {
99
- const o = [];
100
- for (let t = 0; t < 3; t++)
101
- for (let e = 0; e < 3; e++)
102
- n[t][e] === "." && o.push({ row: t, col: e });
103
- return o;
104
- }
105
- function S(n, o, t, e) {
106
- const r = M(n);
107
- return r[o][t] = e, r;
108
- }
109
- function u(n) {
110
- let o = 0, t = 0, e = 0;
111
- for (let r = 0; r < 3; r++)
112
- for (let i = 0; i < 3; i++) {
113
- const s = n[r][i];
114
- s === "X" ? o++ : s === "O" ? t++ : e++;
115
- }
116
- return { X: o, O: t, empty: e };
117
- }
118
- function X(n) {
119
- for (const o of N) {
120
- const t = o.map((e) => n[e.row][e.col]);
121
- if (t[0] !== "." && t[0] === t[1] && t[1] === t[2])
122
- return { winner: t[0], winningLine: o };
123
- }
124
- return { winner: null, winningLine: null };
125
- }
126
- function $(n) {
127
- const { winner: o, winningLine: t } = X(n);
128
- return o ? { isTerminal: !0, winner: o, winningLine: t } : u(n).empty === 0 ? { isTerminal: !0, winner: "draw", winningLine: null } : { isTerminal: !1, winner: null, winningLine: null };
129
- }
130
- function I(n) {
131
- if (n.action === "new_game") {
132
- const { playerNames: m } = n, c = O(), T = p(c), g = u(c);
133
- return {
134
- board: c,
135
- currentSide: "X",
136
- // X always goes first
137
- playerNames: m,
138
- legalMoves: T,
139
- counts: g,
140
- isTerminal: !1,
141
- winner: null,
142
- winningLine: null,
143
- lastAction: { type: "new_game" }
144
- };
145
- }
146
- const { row: o, col: t, board: e, currentSide: r, playerNames: i } = n;
147
- if (o < 0 || o > 2 || t < 0 || t > 2) {
148
- const m = p(e), c = u(e);
149
- return {
150
- board: e,
151
- currentSide: r,
152
- playerNames: i,
153
- legalMoves: m,
154
- counts: c,
155
- isTerminal: !1,
156
- winner: null,
157
- winningLine: null,
158
- lastAction: { type: "move", row: o, col: t },
159
- error: `Invalid move: (${o}, ${t}) is out of bounds. Row and column must be 0-2.`
160
- };
161
- }
162
- if (e[o][t] !== ".") {
163
- const m = p(e), c = u(e);
164
- return {
165
- board: e,
166
- currentSide: r,
167
- playerNames: i,
168
- legalMoves: m,
169
- counts: c,
170
- isTerminal: !1,
171
- winner: null,
172
- winningLine: null,
173
- lastAction: { type: "move", row: o, col: t },
174
- error: `Invalid move: (${o}, ${t}) is already occupied by ${e[o][t]}.`
175
- };
176
- }
177
- const s = S(e, o, t, r), a = P(r), l = p(s), d = u(s), { isTerminal: w, winner: y, winningLine: f } = $(s);
178
- return {
179
- board: s,
180
- currentSide: a,
181
- playerNames: i,
182
- legalMoves: l,
183
- counts: d,
184
- isTerminal: w,
185
- winner: y,
186
- winningLine: f,
187
- lastAction: { type: "move", row: o, col: t }
188
- };
189
- }
190
- const L = async (n, o) => {
191
- try {
192
- let t;
193
- if (o.action === "new_game") {
194
- let a;
195
- o.firstPlayer ? a = o.firstPlayer : a = Math.random() < 0.5 ? "computer" : "user", t = {
196
- action: "new_game",
197
- playerNames: { X: a, O: a === "user" ? "computer" : "user" }
198
- };
199
- } else if (o.action === "move") {
200
- if (typeof o.row != "number" || typeof o.col != "number" || !o.board || !o.currentSide || !o.playerNames)
201
- throw new Error(
202
- "Move action requires row, col, board, currentSide, and playerNames parameters"
203
- );
204
- t = {
205
- action: "move",
206
- row: o.row,
207
- col: o.col,
208
- board: o.board,
209
- currentSide: o.currentSide,
210
- playerNames: o.playerNames
211
- };
212
- } else
213
- throw new Error(`Unknown action: ${o.action}`);
214
- const e = I(t);
215
- if (e.error) {
216
- const a = e.playerNames[e.currentSide] === "computer", l = e.legalMoves.map((w) => `(row=${w.row}, col=${w.col})`).join(", "), d = a ? `Invalid move attempted. You must make a valid move. Legal moves are: ${l}. Choose one of these moves.` : `Invalid move attempted. Tell the user they must make a valid move. Legal moves are: ${l}.`;
217
- return {
218
- message: e.error,
219
- jsonData: e,
220
- instructions: d,
221
- updating: !0
222
- };
223
- }
224
- let r = "";
225
- if (e.lastAction.type === "new_game")
226
- r = "Started a new Tic-Tac-Toe game! X goes first.";
227
- else if (e.lastAction.type === "move") {
228
- const a = A(e.lastAction.row, e.lastAction.col);
229
- r = `Played ${e.board[e.lastAction.row][e.lastAction.col] === "X" ? "O" : "X"} at ${a} (row=${e.lastAction.row}, col=${e.lastAction.col}).`;
230
- }
231
- e.isTerminal && (e.winner === "draw" ? r += " Game over - it's a draw!" : e.winner && (r += ` Game over - ${e.winner} wins!`));
232
- const i = e.playerNames[e.currentSide] === "computer", s = e.isTerminal ? "The game is over. Briefly announce the result. Do NOT draw the board - the user can see it in the GUI." : i ? "It is your turn. You MUST call playTicTacToe with action='move' immediately. Do NOT describe the board or explain - just make your move." : "It is the user's turn. Do NOT draw or describe the board - the user can see it in the GUI. Just say it's their turn briefly. When they specify a move, call playTicTacToe with action='move'.";
233
- return {
234
- message: r,
235
- jsonData: e,
236
- instructions: s,
237
- instructionsRequired: e.isTerminal || i,
238
- updating: o.action !== "new_game"
239
- };
240
- } catch (t) {
241
- return console.error("ERR: TicTacToe game error", t), {
242
- message: `TicTacToe game error: ${t instanceof Error ? t.message : "Unknown error"}`,
243
- instructions: "Acknowledge that there was an error with the TicTacToe game and suggest trying again."
244
- };
245
- }
246
- };
247
- function A(n, o) {
248
- const t = ["Top", "Middle", "Bottom"], e = ["Left", "Center", "Right"];
249
- return `${t[n]}-${e[o]}`;
250
- }
251
- const _ = {
252
- toolDefinition: v,
253
- execute: L,
254
- generatingMessage: "Processing TicTacToe move...",
255
- isEnabled: () => !0,
256
- systemPrompt: b
257
- }, E = [
258
- {
259
- name: "New Game (User plays X)",
260
- args: {
261
- action: "new_game",
262
- firstPlayer: "user"
263
- }
264
- },
265
- {
266
- name: "New Game (Computer plays X)",
267
- args: {
268
- action: "new_game",
269
- firstPlayer: "computer"
270
- }
271
- }
272
- ];
273
- export {
274
- b as SYSTEM_PROMPT,
275
- v as TOOL_DEFINITION,
276
- h as TOOL_NAME,
277
- L as executeTicTacToe,
278
- I as playTicTacToe,
279
- _ as pluginCore,
280
- E as samples
281
- };
1
+ import { a as e, i as t, n, o as r, r as i, s as a, t as o } from "./samples-C6NC1xAK.js";
2
+ export { e as SYSTEM_PROMPT, r as TOOL_DEFINITION, a as TOOL_NAME, n as executeTicTacToe, t as playTicTacToe, i as pluginCore, o as samples };
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./core.cjs");exports.SYSTEM_PROMPT=e.SYSTEM_PROMPT;exports.TOOL_DEFINITION=e.TOOL_DEFINITION;exports.TOOL_NAME=e.TOOL_NAME;exports.executeTicTacToe=e.executeTicTacToe;exports.playTicTacToe=e.playTicTacToe;exports.pluginCore=e.pluginCore;exports.samples=e.samples;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./samples-5nF6v9m_.cjs`);require(`./core.cjs`),exports.SYSTEM_PROMPT=e.a,exports.TOOL_DEFINITION=e.o,exports.TOOL_NAME=e.s,exports.executeTicTacToe=e.n,exports.playTicTacToe=e.i,exports.pluginCore=e.r,exports.samples=e.t;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * TicTacToe Plugin - Main Entry Point
3
3
  */
4
- export * from "./core";
4
+ export * from "./core/index";
package/dist/index.js CHANGED
@@ -1,10 +1,3 @@
1
- import { SYSTEM_PROMPT as O, TOOL_DEFINITION as c, TOOL_NAME as o, executeTicTacToe as a, playTicTacToe as p, pluginCore as i, samples as l } from "./core.js";
2
- export {
3
- O as SYSTEM_PROMPT,
4
- c as TOOL_DEFINITION,
5
- o as TOOL_NAME,
6
- a as executeTicTacToe,
7
- p as playTicTacToe,
8
- i as pluginCore,
9
- l as samples
10
- };
1
+ import { a as e, i as t, n, o as r, r as i, s as a, t as o } from "./samples-C6NC1xAK.js";
2
+ import "./core.js";
3
+ export { e as SYSTEM_PROMPT, r as TOOL_DEFINITION, a as TOOL_NAME, n as executeTicTacToe, t as playTicTacToe, i as pluginCore, o as samples };
@@ -0,0 +1,9 @@
1
+ var e=`playTicTacToe`,t={type:`function`,name:e,description:`Play Tic-Tac-Toe (Noughts and Crosses) game with the user. You can start a new game or make moves on the 3x3 board.`,parameters:{type:`object`,properties:{action:{type:`string`,enum:[`new_game`,`move`],description:`The action to perform: start a new game or make a move`},col:{type:`number`,description:`Column position for the move (0-2, required for 'move' action). Left=0, Center=1, Right=2`,minimum:0,maximum:2},row:{type:`number`,description:`Row position for the move (0-2, required for 'move' action). Top=0, Middle=1, Bottom=2`,minimum:0,maximum:2},board:{type:`array`,description:`Current 3x3 board state BEFORE the move (required for 'move' action). Pass the current board state as-is.`,items:{type:`array`,items:{type:`string`,enum:[`.`,`X`,`O`]}}},currentSide:{type:`string`,enum:[`X`,`O`],description:`Current player's side (required for 'move' action). X always goes first.`},playerNames:{type:`object`,description:`Player assignments (required for 'move' action)`,properties:{X:{type:`string`,enum:[`user`,`computer`]},O:{type:`string`,enum:[`user`,`computer`]}},required:[`X`,`O`]},firstPlayer:{type:`string`,enum:[`user`,`computer`],description:`Optional: Which player should play as X (goes first) for 'new_game' action. If not specified, will be chosen randomly.`}},required:[`action`],additionalProperties:!1}},n=`You can play Tic-Tac-Toe with users using the playTicTacToe tool.
2
+
3
+ IMPORTANT: When the user specifies a move (e.g., "I want to play at top-left, which is row=0, col=0"), you MUST call the playTicTacToe tool with action="move", NOT respond with text.
4
+
5
+ Game rules:
6
+ 1. Start a new game with action="new_game"
7
+ 2. For moves, use action="move" with row (0-2) and col (0-2), plus the current board state
8
+ 3. X always goes first. Win by getting 3 in a row (horizontal, vertical, or diagonal)
9
+ 4. Positions: row=0 is top, row=2 is bottom; col=0 is left, col=2 is right`,r=[[{row:0,col:0},{row:0,col:1},{row:0,col:2}],[{row:1,col:0},{row:1,col:1},{row:1,col:2}],[{row:2,col:0},{row:2,col:1},{row:2,col:2}],[{row:0,col:0},{row:1,col:0},{row:2,col:0}],[{row:0,col:1},{row:1,col:1},{row:2,col:1}],[{row:0,col:2},{row:1,col:2},{row:2,col:2}],[{row:0,col:0},{row:1,col:1},{row:2,col:2}],[{row:0,col:2},{row:1,col:1},{row:2,col:0}]];function i(){let e=[];for(let t=0;t<3;t++)e[t]=[,,,].fill(`.`);return e}function a(e){return e.map(e=>[...e])}function o(e){return e===`X`?`O`:`X`}function s(e){let t=[];for(let n=0;n<3;n++)for(let r=0;r<3;r++)e[n][r]===`.`&&t.push({row:n,col:r});return t}function c(e,t,n,r){let i=a(e);return i[t][n]=r,i}function l(e){let t=0,n=0,r=0;for(let i=0;i<3;i++)for(let a=0;a<3;a++){let o=e[i][a];o===`X`?t++:o===`O`?n++:r++}return{X:t,O:n,empty:r}}function u(e){for(let t of r){let n=t.map(t=>e[t.row][t.col]);if(n[0]!==`.`&&n[0]===n[1]&&n[1]===n[2])return{winner:n[0],winningLine:t}}return{winner:null,winningLine:null}}function d(e){let{winner:t,winningLine:n}=u(e);return t?{isTerminal:!0,winner:t,winningLine:n}:l(e).empty===0?{isTerminal:!0,winner:`draw`,winningLine:null}:{isTerminal:!1,winner:null,winningLine:null}}function f(e){if(e.action===`new_game`){let{playerNames:t}=e,n=i();return{board:n,currentSide:`X`,playerNames:t,legalMoves:s(n),counts:l(n),isTerminal:!1,winner:null,winningLine:null,lastAction:{type:`new_game`}}}let{row:t,col:n,board:r,currentSide:a,playerNames:u}=e;if(t<0||t>2||n<0||n>2)return{board:r,currentSide:a,playerNames:u,legalMoves:s(r),counts:l(r),isTerminal:!1,winner:null,winningLine:null,lastAction:{type:`move`,row:t,col:n},error:`Invalid move: (${t}, ${n}) is out of bounds. Row and column must be 0-2.`};if(r[t][n]!==`.`)return{board:r,currentSide:a,playerNames:u,legalMoves:s(r),counts:l(r),isTerminal:!1,winner:null,winningLine:null,lastAction:{type:`move`,row:t,col:n},error:`Invalid move: (${t}, ${n}) is already occupied by ${r[t][n]}.`};let f=c(r,t,n,a),p=o(a),m=s(f),h=l(f),{isTerminal:g,winner:_,winningLine:v}=d(f);return{board:f,currentSide:p,playerNames:u,legalMoves:m,counts:h,isTerminal:g,winner:_,winningLine:v,lastAction:{type:`move`,row:t,col:n}}}var p=async(e,t)=>{try{let e;if(t.action===`new_game`){let n;n=t.firstPlayer?t.firstPlayer:Math.random()<.5?`computer`:`user`,e={action:`new_game`,playerNames:{X:n,O:n===`user`?`computer`:`user`}}}else if(t.action===`move`){if(typeof t.row!=`number`||typeof t.col!=`number`||!t.board||!t.currentSide||!t.playerNames)throw Error(`Move action requires row, col, board, currentSide, and playerNames parameters`);e={action:`move`,row:t.row,col:t.col,board:t.board,currentSide:t.currentSide,playerNames:t.playerNames}}else throw Error(`Unknown action: ${t.action}`);let n=f(e);if(n.error){let e=n.playerNames[n.currentSide]===`computer`,t=n.legalMoves.map(e=>`(row=${e.row}, col=${e.col})`).join(`, `),r=e?`Invalid move attempted. You must make a valid move. Legal moves are: ${t}. Choose one of these moves.`:`Invalid move attempted. Tell the user they must make a valid move. Legal moves are: ${t}.`;return{message:n.error,jsonData:n,instructions:r,updating:!0}}let r=``;if(n.lastAction.type===`new_game`)r=`Started a new Tic-Tac-Toe game! X goes first.`;else if(n.lastAction.type===`move`){let e=m(n.lastAction.row,n.lastAction.col);r=`Played ${n.board[n.lastAction.row][n.lastAction.col]===`X`?`O`:`X`} at ${e} (row=${n.lastAction.row}, col=${n.lastAction.col}).`}n.isTerminal&&(n.winner===`draw`?r+=` Game over - it's a draw!`:n.winner&&(r+=` Game over - ${n.winner} wins!`));let i=n.playerNames[n.currentSide]===`computer`,a=n.isTerminal?`The game is over. Briefly announce the result. Do NOT draw the board - the user can see it in the GUI.`:i?`It is your turn. You MUST call playTicTacToe with action='move' immediately. Do NOT describe the board or explain - just make your move.`:`It is the user's turn. Do NOT draw or describe the board - the user can see it in the GUI. Just say it's their turn briefly. When they specify a move, call playTicTacToe with action='move'.`;return{message:r,jsonData:n,instructions:a,instructionsRequired:n.isTerminal||i,updating:t.action!==`new_game`}}catch(e){return console.error(`ERR: TicTacToe game error`,e),{message:`TicTacToe game error: ${e instanceof Error?e.message:`Unknown error`}`,instructions:`Acknowledge that there was an error with the TicTacToe game and suggest trying again.`}}};function m(e,t){return`${[`Top`,`Middle`,`Bottom`][e]}-${[`Left`,`Center`,`Right`][t]}`}var h={toolDefinition:t,execute:p,generatingMessage:`Processing TicTacToe move...`,isEnabled:()=>!0,systemPrompt:n},g=[{name:`New Game (User plays X)`,args:{action:`new_game`,firstPlayer:`user`}},{name:`New Game (Computer plays X)`,args:{action:`new_game`,firstPlayer:`computer`}}];Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return g}});