New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@arc-dev/examples

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arc-dev/examples - npm Package Compare versions

Comparing version
0.0.2-alpha.3
to
0.0.2-alpha.4
+4
dist/arcs/tic-tac-toe/actions/apply-ai-move.d.ts
import { State } from "../tic-tac-toe.arc";
declare const applyAIMoveAction: <AState extends State, AContext extends Record<string, any>>(arc: import("@arc-dev/core").ArcBuilder<AState, AContext>) => import("@arc-dev/core").NodeRef<string>;
export default applyAIMoveAction;
//# sourceMappingURL=apply-ai-move.d.ts.map
{"version":3,"file":"apply-ai-move.d.ts","sourceRoot":"","sources":["../../../../src/arcs/tic-tac-toe/actions/apply-ai-move.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,QAAA,MAAM,iBAAiB,oKAqCtB,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
import { State } from "../tic-tac-toe.arc";
declare const playerMoveAction: <AState extends State, AContext extends Record<string, any>>(arc: import("@arc-dev/core").ArcBuilder<AState, AContext>) => import("@arc-dev/core").NodeRef<string>;
export default playerMoveAction;
//# sourceMappingURL=player-move.d.ts.map
{"version":3,"file":"player-move.d.ts","sourceRoot":"","sources":["../../../../src/arcs/tic-tac-toe/actions/player-move.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAE3C,QAAA,MAAM,gBAAgB,oKAkBrB,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
import { State } from "../tic-tac-toe.arc";
import { z } from "zod";
export declare const aiMoveSchema: z.ZodObject<{
row: z.ZodNumber;
col: z.ZodNumber;
}, z.core.$strip>;
declare const aiMoveAgent: <AState extends State, AContext extends import("@arc-dev/core").InferOutputContext<{
"ai-move": typeof aiMoveSchema;
}>>(arc: import("@arc-dev/core").ArcBuilder<AState, AContext>) => import("@arc-dev/core").NodeRef<string>;
export default aiMoveAgent;
//# sourceMappingURL=ai-move.d.ts.map
{"version":3,"file":"ai-move.d.ts","sourceRoot":"","sources":["../../../../src/arcs/tic-tac-toe/agents/ai-move.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,YAAY;;;iBAGvB,CAAC;AAEH,QAAA,MAAM,WAAW;;yGAwBf,CAAC;AAEH,eAAe,WAAW,CAAC"}
import { State } from "../tone.arc";
declare const finalizeAction: <AState extends State, AContext extends import("@arc-dev/core").InferOutputContext<{
"plan-style": typeof import("../agents/plan").planStyleSchema;
"verify-style": typeof import("../agents/verify").verifyStyleSchema;
}>>(arc: import("@arc-dev/core").ArcBuilder<AState, AContext>) => import("@arc-dev/core").NodeRef<string>;
export default finalizeAction;
//# sourceMappingURL=finalize.d.ts.map
{"version":3,"file":"finalize.d.ts","sourceRoot":"","sources":["../../../../src/arcs/tone/actions/finalize.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAiB,MAAM,aAAa,CAAC;AAEnD,QAAA,MAAM,cAAc;;;yGAUnB,CAAC;AAEF,eAAe,cAAc,CAAC"}
import { z } from "zod";
import { State } from "../tone.arc";
export declare const planStyleSchema: z.ZodObject<{
text: z.ZodString;
}, z.core.$strip>;
declare const planAgent: <AState extends State, AContext extends import("@arc-dev/core").InferOutputContext<{
"plan-style": typeof planStyleSchema;
"verify-style": typeof import("./verify").verifyStyleSchema;
}>>(arc: import("@arc-dev/core").ArcBuilder<AState, AContext>) => import("@arc-dev/core").NodeRef<string>;
export default planAgent;
//# sourceMappingURL=plan.d.ts.map
{"version":3,"file":"plan.d.ts","sourceRoot":"","sources":["../../../../src/arcs/tone/agents/plan.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,KAAK,EAAiB,MAAM,aAAa,CAAC;AAEnD,eAAO,MAAM,eAAe;;iBAE1B,CAAC;AAEH,QAAA,MAAM,SAAS;;;yGAyBb,CAAC;AAEH,eAAe,SAAS,CAAC"}
import { z } from "zod";
import { State } from "../tone.arc";
export declare const verifyStyleSchema: z.ZodObject<{
quality: z.ZodNumber;
}, z.core.$strip>;
declare const verifyAgent: <AState extends State, AContext extends import("@arc-dev/core").InferOutputContext<{
"plan-style": typeof import("./plan").planStyleSchema;
"verify-style": typeof verifyStyleSchema;
}>>(arc: import("@arc-dev/core").ArcBuilder<AState, AContext>) => import("@arc-dev/core").NodeRef<string>;
export default verifyAgent;
//# sourceMappingURL=verify.d.ts.map
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../../../src/arcs/tone/agents/verify.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,KAAK,EAAiB,MAAM,aAAa,CAAC;AAEnD,eAAO,MAAM,iBAAiB;;iBAE5B,CAAC;AAEH,QAAA,MAAM,WAAW;;;yGA2Bf,CAAC;AAEH,eAAe,WAAW,CAAC"}
import { ArcRuntime, ArcEvent, LogVerbosity } from "@arc-dev/core";
export declare class TerminalChannel {
private readonly verbosity?;
private currentNode;
constructor(verbosity?: LogVerbosity | undefined);
consume<State extends Record<string, any>, Context extends Record<string, any>>(runtime: ArcRuntime, events: AsyncIterable<ArcEvent<State, Context>>): Promise<{
finalState: State;
finalContext: Context;
}>;
private streamEvent;
private printNodeHeader;
private printLog;
private shouldLog;
private printSuccess;
private printError;
private printObject;
private askUser;
}
//# sourceMappingURL=terminal.d.ts.map
{"version":3,"file":"terminal.d.ts","sourceRoot":"","sources":["../../../../src/arcs/tone/channel/terminal.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EACV,QAAQ,EACR,YAAY,EAEb,MAAM,eAAe,CAAC;AAEvB,qBAAa,eAAe;IAGd,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC;IAFvC,OAAO,CAAC,WAAW,CAAqB;gBAEX,SAAS,CAAC,EAAE,YAAY,YAAA;IAI/C,OAAO,CACX,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACjC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAEnC,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,GAC9C,OAAO,CAAC;QAAE,UAAU,EAAE,KAAK,CAAC;QAAC,YAAY,EAAE,OAAO,CAAA;KAAE,CAAC;IA+GxD,OAAO,CAAC,WAAW;IAQnB,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,QAAQ;IAmBhB,OAAO,CAAC,SAAS;IAuBjB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,WAAW;YA0CL,OAAO;CAatB"}
+2
-6
import { State } from "../tic-tac-toe.arc";
import { ArcStateContext, TypedImmutableMap } from "@arc-dev/core";
export declare const checkWinner: (board: State["board"]) => {
gameOver: boolean;
winner: "You Win!" | "You Lose!" | "It's a Draw!" | null;
};
export declare const winnerAction: ({ state, }: ArcStateContext<State, any>) => Promise<TypedImmutableMap<State>>;
declare const checkWinnerAction: <AState extends State, AContext extends Record<string, any>>(arc: import("@arc-dev/core").ArcBuilder<AState, AContext>) => import("@arc-dev/core").NodeRef<string>;
export default checkWinnerAction;
//# sourceMappingURL=check-winner.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"check-winner.d.ts","sourceRoot":"","sources":["../../../../src/arcs/tic-tac-toe/actions/check-winner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEnE,eAAO,MAAM,WAAW,GACtB,OAAO,KAAK,CAAC,OAAO,CAAC,KACpB;IACD,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,UAAU,GAAG,WAAW,GAAG,cAAc,GAAG,IAAI,CAAC;CA+D1D,CAAC;AAEF,eAAO,MAAM,YAAY,GAAU,YAEhC,eAAe,CAAC,KAAK,EAAE,GAAG,CAAC,KAAG,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAOhE,CAAC"}
{"version":3,"file":"check-winner.d.ts","sourceRoot":"","sources":["../../../../src/arcs/tic-tac-toe/actions/check-winner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAuE3C,QAAA,MAAM,iBAAiB,oKAQtB,CAAC;AAEF,eAAe,iBAAiB,CAAC"}

@@ -1,3 +0,10 @@

import { Arc } from "@arc-dev/core";
export declare const TicTacToeGameLoopArc: Arc;
import { InferOutputContext } from "@arc-dev/core";
import { State } from "./tic-tac-toe.arc";
import { aiMoveSchema } from "./agents/ai-move";
export type OutputContext = InferOutputContext<{
"ai-move": typeof aiMoveSchema;
}>;
export declare const GameLoopArc: import("@arc-dev/core").Arc<State, InferOutputContext<{
"ai-move": typeof aiMoveSchema;
}>>;
//# sourceMappingURL=game-loop.arc.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"game-loop.arc.d.ts","sourceRoot":"","sources":["../../../src/arcs/tic-tac-toe/game-loop.arc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,GAAG,EAAE,MAAM,eAAe,CAAC;AAe/C,eAAO,MAAM,oBAAoB,EAAE,GAsJlC,CAAC"}
{"version":3,"file":"game-loop.arc.d.ts","sourceRoot":"","sources":["../../../src/arcs/tic-tac-toe/game-loop.arc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,OAAoB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAI7D,MAAM,MAAM,aAAa,GAAG,kBAAkB,CAAC;IAC7C,SAAS,EAAE,OAAO,YAAY,CAAC;CAChC,CAAC,CAAC;AAEH,eAAO,MAAM,WAAW;eAHX,OAAO,YAAY;GAa/B,CAAC"}

@@ -1,2 +0,1 @@

import { Arc } from "@arc-dev/core";
type BoardState = string[][];

@@ -9,4 +8,4 @@ export type State = {

};
export declare const TicTacToeArc: Arc;
export declare const TicTacToeArc: import("@arc-dev/core").Arc<State, any>;
export {};
//# sourceMappingURL=tic-tac-toe.arc.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"tic-tac-toe.arc.d.ts","sourceRoot":"","sources":["../../../src/arcs/tic-tac-toe/tic-tac-toe.arc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,GAAG,EAAE,MAAM,eAAe,CAAC;AAO/C,KAAK,UAAU,GAAG,MAAM,EAAE,EAAE,CAAC;AAE7B,MAAM,MAAM,KAAK,GAAG;IAClB,KAAK,EAAE,UAAU,CAAC;IAClB,aAAa,EAAE,GAAG,GAAG,GAAG,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,UAAU,GAAG,WAAW,GAAG,cAAc,GAAG,IAAI,CAAC;CAC1D,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,GAW1B,CAAC"}
{"version":3,"file":"tic-tac-toe.arc.d.ts","sourceRoot":"","sources":["../../../src/arcs/tic-tac-toe/tic-tac-toe.arc.ts"],"names":[],"mappings":"AAGA,KAAK,UAAU,GAAG,MAAM,EAAE,EAAE,CAAC;AAE7B,MAAM,MAAM,KAAK,GAAG;IAClB,KAAK,EAAE,UAAU,CAAC;IAClB,aAAa,EAAE,GAAG,GAAG,GAAG,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,UAAU,GAAG,WAAW,GAAG,cAAc,GAAG,IAAI,CAAC;CAC1D,CAAC;AAEF,eAAO,MAAM,YAAY,yCAOvB,CAAC"}

@@ -1,3 +0,17 @@

import { Arc } from "@arc-dev/core";
export declare const ToneRewriterArc: Arc;
import { InferOutputContext } from "@arc-dev/core";
import { planStyleSchema } from "./agents/plan";
import { verifyStyleSchema } from "./agents/verify";
export type State = {
examples: string[];
text: string;
result?: string;
};
export type OutputContext = InferOutputContext<{
"plan-style": typeof planStyleSchema;
"verify-style": typeof verifyStyleSchema;
}>;
export declare const ToneRewriterArc: import("@arc-dev/core").Arc<State, InferOutputContext<{
"plan-style": typeof planStyleSchema;
"verify-style": typeof verifyStyleSchema;
}>>;
//# sourceMappingURL=tone.arc.d.ts.map

@@ -1,1 +0,1 @@

{"version":3,"file":"tone.arc.d.ts","sourceRoot":"","sources":["../../../src/arcs/tone/tone.arc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,GAAG,EAAE,MAAM,eAAe,CAAC;AAmB/C,eAAO,MAAM,eAAe,EAAE,GA6E7B,CAAC"}
{"version":3,"file":"tone.arc.d.ts","sourceRoot":"","sources":["../../../src/arcs/tone/tone.arc.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAkB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAoB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAKjE,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,kBAAkB,CAAC;IAC7C,YAAY,EAAE,OAAO,eAAe,CAAC;IACrC,cAAc,EAAE,OAAO,iBAAiB,CAAC;CAC1C,CAAC,CAAC;AAEH,eAAO,MAAM,eAAe;kBAJZ,OAAO,eAAe;oBACpB,OAAO,iBAAiB;GAkBzC,CAAC"}

@@ -6,30 +6,19 @@ 'use strict';

var NodeId$1;
(function (NodeId) {
NodeId["Plan"] = "plan-style";
NodeId["Verify"] = "verify-style";
NodeId["Finalize"] = "finalize-rewrite";
})(NodeId$1 || (NodeId$1 = {}));
var ConditionId;
(function (ConditionId) {
ConditionId["HighQuality"] = "high-quality";
})(ConditionId || (ConditionId = {}));
const QUALITY_THRESHOLD = 0.7;
const ToneRewriterArc = core.createArc("tone-rewriter", ({ node, edge }) => {
node.agent(NodeId$1.Plan, {
model: "openai/gpt-4o-mini",
output: zod.z.object({
text: zod.z.string(),
}),
messages: ({ state }) => {
const examples = state.get("examples");
const text = state.get("text");
return [
{
role: "system",
content: "You are a helpful assistant that rewrites text in different tones and styles that is based on the provided examples of the users writing styles.",
},
{
role: "user",
content: `
const planStyleSchema = zod.z.object({
text: zod.z.string(),
});
const planAgent = core.createAgent("plan-style", {
model: "openai/gpt-4o-mini",
output: planStyleSchema,
messages: ({ state }) => {
const examples = state.get("examples");
const text = state.get("text");
return [
{
role: "system",
content: "You are a helpful assistant that rewrites text in different tones and styles that is based on the provided examples of the users writing styles.",
},
{
role: "user",
content: `
My typically writing style is as follows:

@@ -41,19 +30,24 @@ ${examples.join("\n\n")}.

`,
},
];
},
});
node.agent(NodeId$1.Verify, {
model: "openai/gpt-4o-mini",
messages: ({ state, context }) => {
const examples = state.get("examples");
const rewrittenText = context.get(NodeId$1.Plan).get("text");
return [
{
role: "system",
content: "You are a style critic that evaluates text rewrites. Respond with ONLY a number between 0.0 and 1.0 representing the quality score.",
},
{
role: "user",
content: `Evaluate how well this text matches the users style of writing:
},
];
},
});
const verifyStyleSchema = zod.z.object({
quality: zod.z.number(),
});
const verifyAgent = core.createAgent("verify-style", {
model: "openai/gpt-4o-mini",
output: verifyStyleSchema,
messages: ({ state, context }) => {
const examples = state.get("examples");
const rewrittenText = context.get("plan-style").get("text");
return [
{
role: "system",
content: "You are a style critic that evaluates text rewrites. Respond with ONLY a number between 0.0 and 1.0 representing the quality score.",
},
{
role: "user",
content: `Evaluate how well this text matches the users style of writing:

@@ -67,26 +61,42 @@ My writing style examples are:

Provide an overall quality score between 0.0 (poor) and 1.0 (excellent).`,
},
];
},
output: zod.z.object({
quality: zod.z.number(),
}),
});
node.action(NodeId$1.Finalize, ({ state, context, render }) => {
const text = context.get(NodeId$1.Plan).get("text");
render(text);
return state.set("result", context.get(NodeId$1.Plan).get("text"));
});
edge.condition(ConditionId.HighQuality, ({ context }) => context.get(NodeId$1.Verify).get("quality") >= QUALITY_THRESHOLD);
edge.from(NodeId$1.Plan).to(NodeId$1.Verify);
edge.from(NodeId$1.Verify).to(NodeId$1.Finalize).when(ConditionId.HighQuality);
},
];
},
});
const moveAgent = {
const finalizeAction = core.createAction("finalize-rewrite", async ({ state, context }) => {
// Now context.get("plan-style") is strongly typed!
// TypeScript knows it returns TypedImmutableMap<PlanStyleOutput> with a "text" property
const planStyleOutput = context.get("plan-style");
const text = planStyleOutput.get("text");
return state.set("result", text);
});
const QUALITY_THRESHOLD = 0.7;
const ToneRewriterArc = core.defineArc("tone-rewriter", (arc) => {
arc
.from(planAgent)
.to(verifyAgent)
.to(finalizeAction)
.when(arc.condition("high-quality", ({ context }) => context.get("verify-style").get("quality") >= QUALITY_THRESHOLD));
});
const playerMoveAction = core.createAction("player-move", async ({ state, edgeContext }) => {
const answer = edgeContext.get("player-move") ?? "";
const [rowStr, colStr] = answer.split(",");
const row = parseInt(rowStr?.trim() || "0");
const col = parseInt(colStr?.trim() || "0");
const updatedBoard = state
.get("board")
.map((r, rIdx) => r.map((cell, cIdx) => rIdx === row && cIdx === col ? "X" : cell));
return state.set("board", updatedBoard).set("currentPlayer", "O");
});
const aiMoveSchema = zod.z.object({
row: zod.z.number(),
col: zod.z.number(),
});
const aiMoveAgent = core.createAgent("ai-move", {
output: aiMoveSchema,
model: "openai/gpt-4o",
output: zod.z.object({
row: zod.z.number(),
col: zod.z.number(),
}),
when: ({ state }) => !state.get("gameOver"),
messages: ({ state }) => {

@@ -112,5 +122,31 @@ const board = state.get("board");

},
};
});
const checkWinner = (board) => {
const applyAIMoveAction = core.createAction("apply-ai-move", async ({ state, context }) => {
const moveAgentResult = context.get("ai-move-agent");
const row = moveAgentResult.get("row");
const col = moveAgentResult.get("col");
const board = state.get("board");
let finalRow = row;
let finalCol = col;
if (row < 0 ||
row >= board.length ||
col < 0 ||
col >= board[0].length ||
board[row][col]) {
outerLoop: for (let r = 0; r < board.length; r++) {
for (let c = 0; c < board[r].length; c++) {
if (!board[r][c]) {
finalRow = r;
finalCol = c;
break outerLoop;
}
}
}
}
const updatedBoard = board.map((r, rIdx) => r.map((cell, cIdx) => rIdx === finalRow && cIdx === finalCol ? "O" : cell));
return state.set("board", updatedBoard).set("currentPlayer", "X");
});
const check = (board) => {
for (let row = 0; row < 3; row++) {

@@ -164,135 +200,23 @@ if (board[row][0] &&

};
const checkWinnerAction = core.createAction("check-winner", async ({ state }) => {
const board = state.get("board");
const result = check(board);
return state.set("gameOver", result.gameOver).set("winner", result.winner);
});
var NodeId;
(function (NodeId) {
NodeId["ShowBoard"] = "show-board";
NodeId["PlayerMove"] = "player-move";
NodeId["CheckWinner"] = "check-winner";
NodeId["GetAIMove"] = "get-ai-move";
NodeId["ApplyAIMove"] = "apply-ai-move";
})(NodeId || (NodeId = {}));
const Id = "game-loop-body";
const TicTacToeGameLoopArc = core.createArc(Id, ({ node, edge }) => {
node.action(NodeId.ShowBoard, async ({ state, render }) => {
const board = state.get("board");
let output = "\nBoard:\n";
board.forEach((row, idx) => {
const formattedRow = row.map((cell) => cell || " ").join(" | ");
output += `${idx}: ${formattedRow}\n`;
});
render(output);
return state;
});
node.action(NodeId.PlayerMove, async ({ state, edgeContext, render }) => {
const answer = edgeContext.get(NodeId.PlayerMove) ?? "";
const [rowStr, colStr] = answer.split(",");
const row = parseInt(rowStr?.trim() || "0");
const col = parseInt(colStr?.trim() || "0");
const updatedBoard = state
.get("board")
.map((r, rIdx) => r.map((cell, cIdx) => rIdx === row && cIdx === col ? "X" : cell));
let output = "";
updatedBoard.forEach((row, idx) => {
const formattedRow = row.map((cell) => cell || " ").join(" | ");
output += `${idx}: ${formattedRow}\n`;
});
render(output);
return state
.set("board", updatedBoard)
.set("currentPlayer", "O");
});
node.action(NodeId.CheckWinner, async ({ state, render }) => {
const board = state.get("board");
const result = checkWinner(board);
if (result.gameOver) {
render(`🎮 Game Over: ${result.winner}`);
}
return state
.set("gameOver", result.gameOver)
.set("winner", result.winner);
});
node.agent(NodeId.GetAIMove, moveAgent);
node.action(NodeId.ApplyAIMove, async ({ state, context, render }) => {
const moveAgentResult = context.get(NodeId.GetAIMove);
const row = moveAgentResult.get("row");
const col = moveAgentResult.get("col");
const board = state.get("board");
let finalRow = row;
let finalCol = col;
if (row < 0 ||
row >= board.length ||
col < 0 ||
col >= board[0].length ||
board[row][col]) {
outerLoop: for (let r = 0; r < board.length; r++) {
for (let c = 0; c < board[r].length; c++) {
if (!board[r][c]) {
finalRow = r;
finalCol = c;
break outerLoop;
}
}
}
}
const updatedBoard = board.map((r, rIdx) => r.map((cell, cIdx) => rIdx === finalRow && cIdx === finalCol ? "O" : cell));
let output = "";
updatedBoard.forEach((row, idx) => {
const formattedRow = row.map((cell) => cell || " ").join(" | ");
output += `${idx}: ${formattedRow}\n`;
});
render(output);
return state
.set("board", updatedBoard)
.set("currentPlayer", "X");
});
edge
.from(NodeId.ShowBoard)
.waitForInput({
message: "Enter your move (row, col): ",
validator: (input, { state }) => {
const [rowStr, colStr] = input.split(",");
const row = parseInt(rowStr?.trim() || "");
const col = parseInt(colStr?.trim() || "");
if (isNaN(row) || isNaN(col)) {
return {
valid: false,
message: "Invalid format. Use: row,col (e.g., 0,1)",
};
}
const board = state.get("board");
if (row < 0 ||
row >= board.length ||
col < 0 ||
col >= board[0].length) {
return {
valid: false,
message: "Out of bounds. Try again.",
};
}
if (board[row][col]) {
return {
valid: false,
message: "Space taken. Choose an empty space.",
};
}
return { valid: true };
},
})
.to(NodeId.PlayerMove);
edge.from(NodeId.PlayerMove).to(NodeId.GetAIMove);
edge.from(NodeId.GetAIMove).to(NodeId.ApplyAIMove);
edge.from(NodeId.ApplyAIMove).to(NodeId.CheckWinner);
const GameLoopArc = core.defineArc("game-loop", (arc) => {
arc
.waitForInput("player")
.to("player-move", playerMoveAction)
.to("ai-move", aiMoveAgent)
.to("apply-ai-move", applyAIMoveAction)
.to("check-winner", checkWinnerAction);
});
var ArcId;
(function (ArcId) {
ArcId["GameLoop"] = "game-loop";
})(ArcId || (ArcId = {}));
const TicTacToeArc = core.createArc("tic-tac-toe", ({ node, edge }) => {
node.arc(ArcId.GameLoop, TicTacToeGameLoopArc);
edge
.from(ArcId.GameLoop)
.to(ArcId.GameLoop)
.when(({ state }) => !state.get("gameOver"))
.maxIterations(9);
const TicTacToeArc = core.defineArc("tic-tac-toe", (arc) => {
const loop = arc.use("game-loop", GameLoopArc);
arc.loop(loop, {
while: ({ state }) => !state.get("gameOver"),
max: 9,
});
});

@@ -299,0 +223,0 @@

@@ -1,1 +0,1 @@

{"version":3,"file":"index.cjs","sources":["../src/arcs/tone/tone.arc.ts","../src/arcs/tic-tac-toe/agents/move.agent.ts","../src/arcs/tic-tac-toe/actions/check-winner.ts","../src/arcs/tic-tac-toe/game-loop.arc.ts","../src/arcs/tic-tac-toe/tic-tac-toe.arc.ts"],"sourcesContent":["import { createArc, Arc } from \"@arc-dev/core\";\nimport { z } from \"zod\";\n\nenum NodeId {\n Plan = \"plan-style\",\n Verify = \"verify-style\",\n Finalize = \"finalize-rewrite\",\n}\n\nenum ConditionId {\n HighQuality = \"high-quality\",\n}\nconst QUALITY_THRESHOLD = 0.7;\n\ntype State = {\n examples: string[];\n text: string;\n};\n\nexport const ToneRewriterArc: Arc = createArc<State>(\n \"tone-rewriter\",\n ({ node, edge }) => {\n node.agent(NodeId.Plan, {\n model: \"openai/gpt-4o-mini\",\n output: z.object({\n text: z.string(),\n }),\n messages: ({ state }) => {\n const examples = state.get(\"examples\");\n const text = state.get(\"text\");\n\n return [\n {\n role: \"system\",\n content:\n \"You are a helpful assistant that rewrites text in different tones and styles that is based on the provided examples of the users writing styles.\",\n },\n {\n role: \"user\",\n content: `\n My typically writing style is as follows:\n ${examples.join(\"\\n\\n\")}.\n \n You must rewrite the following text to match my writing style as closely as possible, do not changing the meaning of the text:\n \"${text}\"\n `,\n },\n ];\n },\n });\n node.agent(NodeId.Verify, {\n model: \"openai/gpt-4o-mini\",\n messages: ({ state, context }) => {\n const examples = state.get(\"examples\");\n const rewrittenText = context.get(NodeId.Plan).get(\"text\");\n\n return [\n {\n role: \"system\",\n content:\n \"You are a style critic that evaluates text rewrites. Respond with ONLY a number between 0.0 and 1.0 representing the quality score.\",\n },\n {\n role: \"user\",\n content: `Evaluate how well this text matches the users style of writing:\n \n My writing style examples are:\n ${examples.join(\"\\n\\n\")}.\n \n Text:\n \"${rewrittenText}\"\n \n Provide an overall quality score between 0.0 (poor) and 1.0 (excellent).`,\n },\n ];\n },\n output: z.object({\n quality: z.number(),\n }),\n });\n node.action(NodeId.Finalize, ({ state, context, render }) => {\n const text = context.get(NodeId.Plan).get(\"text\");\n\n render(text);\n\n return state.set(\"result\", context.get(NodeId.Plan).get(\"text\"));\n });\n\n edge.condition(\n ConditionId.HighQuality,\n ({ context }) =>\n context.get(NodeId.Verify).get(\"quality\") >= QUALITY_THRESHOLD\n );\n edge.from(NodeId.Plan).to(NodeId.Verify);\n edge.from(NodeId.Verify).to(NodeId.Finalize).when(ConditionId.HighQuality);\n }\n);\n","import { ArcStateContext } from \"@arc-dev/core\";\nimport { State } from \"../tic-tac-toe.arc\";\nimport { z } from \"zod\";\n\nexport const moveAgent = {\n model: \"openai/gpt-4o\" as const,\n output: z.object({\n row: z.number(),\n col: z.number(),\n }),\n when: ({ state }: ArcStateContext<State, Record<string, never>>) =>\n !state.get(\"gameOver\"),\n messages: ({ state }: ArcStateContext<State, Record<string, never>>) => {\n const board = state.get(\"board\");\n\n return [\n {\n role: \"system\" as const,\n content: `\n You are playing tic-tac-toe as 'O' against 'X'. Empty cells are \"\" (empty strings).\n Play strategically: win if possible, block opponent wins, prefer center/corners over edges.\n Only play in empty (\"\") cells.\n `,\n },\n {\n role: \"user\" as const,\n content: `\n Board state: ${JSON.stringify(board)}\n Return the row and col indices of your move (must be an empty cell).\n `,\n },\n ];\n },\n};\n","import { State } from \"../tic-tac-toe.arc\";\nimport { ArcStateContext, TypedImmutableMap } from \"@arc-dev/core\";\n\nexport const checkWinner = (\n board: State[\"board\"]\n): {\n gameOver: boolean;\n winner: \"You Win!\" | \"You Lose!\" | \"It's a Draw!\" | null;\n} => {\n for (let row = 0; row < 3; row++) {\n if (\n board[row]![0] &&\n board[row]![0] === board[row]![1] &&\n board[row]![1] === board[row]![2]\n ) {\n return {\n gameOver: true,\n winner: board[row]![0] === \"X\" ? \"You Win!\" : \"You Lose!\",\n };\n }\n }\n\n for (let col = 0; col < 3; col++) {\n if (\n board[0]![col] &&\n board[0]![col] === board[1]![col] &&\n board[1]![col] === board[2]![col]\n ) {\n return {\n gameOver: true,\n winner: board[0]![col] === \"X\" ? \"You Win!\" : \"You Lose!\",\n };\n }\n }\n\n if (\n board[0]![0] &&\n board[0]![0] === board[1]![1] &&\n board[1]![1] === board[2]![2]\n ) {\n return {\n gameOver: true,\n winner: board[0]![0] === \"X\" ? \"You Win!\" : \"You Lose!\",\n };\n }\n\n if (\n board[0]![2] &&\n board[0]![2] === board[1]![1] &&\n board[1]![1] === board[2]![0]\n ) {\n return {\n gameOver: true,\n winner: board[0]![2] === \"X\" ? \"You Win!\" : \"You Lose!\",\n };\n }\n\n const allFilled = board.every((row) => row.every((cell) => cell !== \"\"));\n\n if (allFilled) {\n return {\n gameOver: true,\n winner: \"It's a Draw!\",\n };\n }\n\n return {\n gameOver: false,\n winner: null,\n };\n};\n\nexport const winnerAction = async ({\n state,\n}: ArcStateContext<State, any>): Promise<TypedImmutableMap<State>> => {\n const board = state.get(\"board\");\n const winnerOrNot = checkWinner(board);\n\n return state\n .set(\"gameOver\", winnerOrNot.gameOver)\n .set(\"winner\", winnerOrNot.winner);\n};\n","import { createArc, Arc } from \"@arc-dev/core\";\nimport { State } from \"./tic-tac-toe.arc\";\nimport { moveAgent } from \"./agents/move.agent\";\nimport { checkWinner } from \"./actions/check-winner\";\n\nenum NodeId {\n ShowBoard = \"show-board\",\n PlayerMove = \"player-move\",\n CheckWinner = \"check-winner\",\n GetAIMove = \"get-ai-move\",\n ApplyAIMove = \"apply-ai-move\",\n}\n\nconst Id = \"game-loop-body\";\n\nexport const TicTacToeGameLoopArc: Arc = createArc<State>(\n Id,\n ({ node, edge }) => {\n node.action(NodeId.ShowBoard, async ({ state, render }) => {\n const board = state.get(\"board\");\n\n let output = \"\\nBoard:\\n\";\n\n board.forEach((row: string[], idx: number) => {\n const formattedRow = row.map((cell) => cell || \" \").join(\" | \");\n output += `${idx}: ${formattedRow}\\n`;\n });\n\n render(output);\n\n return state;\n });\n\n node.action(NodeId.PlayerMove, async ({ state, edgeContext, render }) => {\n const answer = edgeContext.get(NodeId.PlayerMove) ?? \"\";\n const [rowStr, colStr] = answer.split(\",\");\n const row = parseInt(rowStr?.trim() || \"0\");\n const col = parseInt(colStr?.trim() || \"0\");\n\n const updatedBoard = state\n .get(\"board\")\n .map((r: string[], rIdx: number) =>\n r.map((cell: string, cIdx: number) =>\n rIdx === row && cIdx === col ? \"X\" : cell\n )\n );\n\n let output = \"\";\n updatedBoard.forEach((row: string[], idx: number) => {\n const formattedRow = row.map((cell: string) => cell || \" \").join(\" | \");\n output += `${idx}: ${formattedRow}\\n`;\n });\n\n render(output);\n\n return state\n .set(\"board\", updatedBoard)\n .set(\"currentPlayer\", \"O\" as const);\n });\n\n node.action(NodeId.CheckWinner, async ({ state, render }) => {\n const board = state.get(\"board\");\n const result = checkWinner(board);\n\n if (result.gameOver) {\n render(`🎮 Game Over: ${result.winner}`);\n }\n\n return state\n .set(\"gameOver\", result.gameOver)\n .set(\"winner\", result.winner);\n });\n\n node.agent(NodeId.GetAIMove, moveAgent);\n\n node.action(NodeId.ApplyAIMove, async ({ state, context, render }) => {\n const moveAgentResult = context.get(NodeId.GetAIMove);\n const row = moveAgentResult.get(\"row\");\n const col = moveAgentResult.get(\"col\");\n const board = state.get(\"board\");\n\n let finalRow = row;\n let finalCol = col;\n\n if (\n row < 0 ||\n row >= board.length ||\n col < 0 ||\n col >= board[0]!.length ||\n board[row]![col]\n ) {\n outerLoop: for (let r = 0; r < board.length; r++) {\n for (let c = 0; c < board[r]!.length; c++) {\n if (!board[r]![c]) {\n finalRow = r;\n finalCol = c;\n break outerLoop;\n }\n }\n }\n }\n\n const updatedBoard = board.map((r: string[], rIdx: number) =>\n r.map((cell: string, cIdx: number) =>\n rIdx === finalRow && cIdx === finalCol ? \"O\" : cell\n )\n );\n\n let output = \"\";\n updatedBoard.forEach((row: string[], idx: number) => {\n const formattedRow = row.map((cell: string) => cell || \" \").join(\" | \");\n output += `${idx}: ${formattedRow}\\n`;\n });\n\n render(output);\n\n return state\n .set(\"board\", updatedBoard)\n .set(\"currentPlayer\", \"X\" as const);\n });\n\n edge\n .from(NodeId.ShowBoard)\n .waitForInput({\n message: \"Enter your move (row, col): \",\n validator: (input: string, { state }) => {\n const [rowStr, colStr] = input.split(\",\");\n const row = parseInt(rowStr?.trim() || \"\");\n const col = parseInt(colStr?.trim() || \"\");\n\n if (isNaN(row) || isNaN(col)) {\n return {\n valid: false,\n message: \"Invalid format. Use: row,col (e.g., 0,1)\",\n };\n }\n\n const board = state.get(\"board\");\n if (\n row < 0 ||\n row >= board.length ||\n col < 0 ||\n col >= board[0]!.length\n ) {\n return {\n valid: false,\n message: \"Out of bounds. Try again.\",\n };\n }\n\n if (board[row]![col]) {\n return {\n valid: false,\n message: \"Space taken. Choose an empty space.\",\n };\n }\n\n return { valid: true };\n },\n })\n .to(NodeId.PlayerMove);\n edge.from(NodeId.PlayerMove).to(NodeId.GetAIMove);\n edge.from(NodeId.GetAIMove).to(NodeId.ApplyAIMove);\n edge.from(NodeId.ApplyAIMove).to(NodeId.CheckWinner);\n }\n);\n","import { createArc, Arc } from \"@arc-dev/core\";\nimport { TicTacToeGameLoopArc } from \"./game-loop.arc\";\n\nenum ArcId {\n GameLoop = \"game-loop\",\n}\n\ntype BoardState = string[][];\n\nexport type State = {\n board: BoardState;\n currentPlayer: \"X\" | \"O\";\n gameOver: boolean;\n winner: \"You Win!\" | \"You Lose!\" | \"It's a Draw!\" | null;\n};\n\nexport const TicTacToeArc: Arc = createArc<State>(\n \"tic-tac-toe\",\n ({ node, edge }) => {\n node.arc(ArcId.GameLoop, TicTacToeGameLoopArc);\n\n edge\n .from(ArcId.GameLoop)\n .to(ArcId.GameLoop)\n .when(({ state }) => !state.get(\"gameOver\"))\n .maxIterations(9);\n }\n);\n"],"names":["NodeId","createArc","z"],"mappings":";;;;;AAGA,IAAKA,QAIJ;AAJD,CAAA,UAAK,MAAM,EAAA;AACT,IAAA,MAAA,CAAA,MAAA,CAAA,GAAA,YAAmB;AACnB,IAAA,MAAA,CAAA,QAAA,CAAA,GAAA,cAAuB;AACvB,IAAA,MAAA,CAAA,UAAA,CAAA,GAAA,kBAA6B;AAC/B,CAAC,EAJIA,QAAM,KAANA,QAAM,GAAA,EAAA,CAAA,CAAA;AAMX,IAAK,WAEJ;AAFD,CAAA,UAAK,WAAW,EAAA;AACd,IAAA,WAAA,CAAA,aAAA,CAAA,GAAA,cAA4B;AAC9B,CAAC,EAFI,WAAW,KAAX,WAAW,GAAA,EAAA,CAAA,CAAA;AAGhB,MAAM,iBAAiB,GAAG,GAAG;AAOtB,MAAM,eAAe,GAAQC,cAAS,CAC3C,eAAe,EACf,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAI;AACjB,IAAA,IAAI,CAAC,KAAK,CAACD,QAAM,CAAC,IAAI,EAAE;AACtB,QAAA,KAAK,EAAE,oBAAoB;AAC3B,QAAA,MAAM,EAAEE,KAAC,CAAC,MAAM,CAAC;AACf,YAAA,IAAI,EAAEA,KAAC,CAAC,MAAM,EAAE;SACjB,CAAC;AACF,QAA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K,KAAK,EAAA;AACR,IAAA,KAAA,CAAA,UAAA,CAAA,GAAA,WAAsB;AACxB,CAAC,EAFI,KAAK,KAAL,KAAK,GAAA,EAAA,CAAA,CAAA;AAaH,MAAM,YAAY,GAAQA,cAAS,CACxC,aAAa,EACb,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAI;IACjB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,oBAAoB,CAAC;IAE9C;AACG,SAAA,IAAI,CAAC,KAAK,CAAC,QAAQ;AACnB,SAAA,EAAE,CAAC,KAAK,CAAC,QAAQ;AACjB,SAAA,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC;SAC1C,aAAa,CAAC,CAAC,CAAC;AACrB,CAAC;;;;;"}
{"version":3,"file":"index.cjs","sources":["../src/arcs/tone/agents/plan.ts","../src/arcs/tone/agents/verify.ts","../src/arcs/tone/actions/finalize.ts","../src/arcs/tone/tone.arc.ts","../src/arcs/tic-tac-toe/actions/player-move.ts","../src/arcs/tic-tac-toe/agents/ai-move.ts","../src/arcs/tic-tac-toe/actions/apply-ai-move.ts","../src/arcs/tic-tac-toe/actions/check-winner.ts","../src/arcs/tic-tac-toe/game-loop.arc.ts","../src/arcs/tic-tac-toe/tic-tac-toe.arc.ts"],"sourcesContent":["import { createAgent } from \"@arc-dev/core\";\nimport { z } from \"zod\";\nimport { State, OutputContext } from \"../tone.arc\";\n\nexport const planStyleSchema = z.object({\n text: z.string(),\n});\n\nconst planAgent = createAgent<State, OutputContext>(\"plan-style\", {\n model: \"openai/gpt-4o-mini\",\n output: planStyleSchema,\n messages: ({ state }) => {\n const examples = state.get(\"examples\");\n const text = state.get(\"text\");\n\n return [\n {\n role: \"system\",\n content:\n \"You are a helpful assistant that rewrites text in different tones and styles that is based on the provided examples of the users writing styles.\",\n },\n {\n role: \"user\",\n content: `\n My typically writing style is as follows:\n ${examples.join(\"\\n\\n\")}.\n \n You must rewrite the following text to match my writing style as closely as possible, do not changing the meaning of the text:\n \"${text}\"\n `,\n },\n ];\n },\n});\n\nexport default planAgent;\n","import { createAgent } from \"@arc-dev/core\";\nimport { z } from \"zod\";\nimport { State, OutputContext } from \"../tone.arc\";\n\nexport const verifyStyleSchema = z.object({\n quality: z.number(),\n});\n\nconst verifyAgent = createAgent<State, OutputContext>(\"verify-style\", {\n model: \"openai/gpt-4o-mini\",\n output: verifyStyleSchema,\n messages: ({ state, context }) => {\n const examples = state.get(\"examples\");\n const rewrittenText = context.get(\"plan-style\").get(\"text\");\n\n return [\n {\n role: \"system\",\n content:\n \"You are a style critic that evaluates text rewrites. Respond with ONLY a number between 0.0 and 1.0 representing the quality score.\",\n },\n {\n role: \"user\",\n content: `Evaluate how well this text matches the users style of writing:\n \n My writing style examples are:\n ${examples.join(\"\\n\\n\")}.\n \n Text:\n \"${rewrittenText}\"\n \n Provide an overall quality score between 0.0 (poor) and 1.0 (excellent).`,\n },\n ];\n },\n});\n\nexport default verifyAgent;\n","import { createAction, ArcStateContext } from \"@arc-dev/core\";\nimport { State, OutputContext } from \"../tone.arc\";\n\nconst finalizeAction = createAction<State, OutputContext>(\n \"finalize-rewrite\",\n async ({ state, context }) => {\n // Now context.get(\"plan-style\") is strongly typed!\n // TypeScript knows it returns TypedImmutableMap<PlanStyleOutput> with a \"text\" property\n const planStyleOutput = context.get(\"plan-style\");\n const text = planStyleOutput.get(\"text\");\n\n return state.set(\"result\", text);\n }\n);\n\nexport default finalizeAction;\n","import { defineArc, InferOutputContext } from \"@arc-dev/core\";\nimport planAgent, { planStyleSchema } from \"./agents/plan\";\nimport verifyAgent, { verifyStyleSchema } from \"./agents/verify\";\nimport finalizeAction from \"./actions/finalize\";\n\nconst QUALITY_THRESHOLD = 0.7;\n\nexport type State = {\n examples: string[];\n text: string;\n result?: string;\n};\n\nexport type OutputContext = InferOutputContext<{\n \"plan-style\": typeof planStyleSchema;\n \"verify-style\": typeof verifyStyleSchema;\n}>;\n\nexport const ToneRewriterArc = defineArc<State, OutputContext>(\n \"tone-rewriter\",\n (arc) => {\n arc\n .from(planAgent)\n .to(verifyAgent)\n .to(finalizeAction)\n .when(\n arc.condition(\n \"high-quality\",\n ({ context }) =>\n context.get(\"verify-style\").get(\"quality\") >= QUALITY_THRESHOLD\n )\n );\n }\n);\n","import { createAction, ArcStateContext } from \"@arc-dev/core\";\nimport { State } from \"../tic-tac-toe.arc\";\n\nconst playerMoveAction = createAction<State>(\n \"player-move\",\n async ({ state, edgeContext }: ArcStateContext<State>) => {\n const answer = edgeContext.get(\"player-move\") ?? \"\";\n const [rowStr, colStr] = answer.split(\",\");\n const row = parseInt(rowStr?.trim() || \"0\");\n const col = parseInt(colStr?.trim() || \"0\");\n\n const updatedBoard = state\n .get(\"board\")\n .map((r: string[], rIdx: number) =>\n r.map((cell: string, cIdx: number) =>\n rIdx === row && cIdx === col ? \"X\" : cell\n )\n );\n\n return state.set(\"board\", updatedBoard).set(\"currentPlayer\", \"O\" as const);\n }\n);\n\nexport default playerMoveAction;\n","import { ArcStateContext, createAgent } from \"@arc-dev/core\";\nimport { State } from \"../tic-tac-toe.arc\";\nimport { z } from \"zod\";\nimport { OutputContext } from \"../game-loop.arc\";\n\nexport const aiMoveSchema = z.object({\n row: z.number(),\n col: z.number(),\n});\n\nconst aiMoveAgent = createAgent<State, OutputContext>(\"ai-move\", {\n output: aiMoveSchema,\n model: \"openai/gpt-4o\" as const,\n messages: ({ state }: ArcStateContext<State>) => {\n const board = state.get(\"board\");\n\n return [\n {\n role: \"system\" as const,\n content: `\n You are playing tic-tac-toe as 'O' against 'X'. Empty cells are \"\" (empty strings).\n Play strategically: win if possible, block opponent wins, prefer center/corners over edges.\n Only play in empty (\"\") cells.\n `,\n },\n {\n role: \"user\" as const,\n content: `\n Board state: ${JSON.stringify(board)}\n Return the row and col indices of your move (must be an empty cell).\n `,\n },\n ];\n },\n});\n\nexport default aiMoveAgent;\n","import { createAction, ArcStateContext } from \"@arc-dev/core\";\nimport { State } from \"../tic-tac-toe.arc\";\n\nconst applyAIMoveAction = createAction<State>(\n \"apply-ai-move\",\n async ({ state, context }: ArcStateContext<State>) => {\n const moveAgentResult = context.get(\"ai-move-agent\");\n const row = moveAgentResult.get(\"row\");\n const col = moveAgentResult.get(\"col\");\n const board = state.get(\"board\");\n\n let finalRow = row;\n let finalCol = col;\n\n if (\n row < 0 ||\n row >= board.length ||\n col < 0 ||\n col >= board[0]!.length ||\n board[row]![col]\n ) {\n outerLoop: for (let r = 0; r < board.length; r++) {\n for (let c = 0; c < board[r]!.length; c++) {\n if (!board[r]![c]) {\n finalRow = r;\n finalCol = c;\n break outerLoop;\n }\n }\n }\n }\n\n const updatedBoard = board.map((r: string[], rIdx: number) =>\n r.map((cell: string, cIdx: number) =>\n rIdx === finalRow && cIdx === finalCol ? \"O\" : cell\n )\n );\n\n return state.set(\"board\", updatedBoard).set(\"currentPlayer\", \"X\" as const);\n }\n);\n\nexport default applyAIMoveAction;\n","import { createAction, ArcStateContext } from \"@arc-dev/core\";\nimport { State } from \"../tic-tac-toe.arc\";\n\nconst check = (\n board: State[\"board\"]\n): {\n gameOver: boolean;\n winner: \"You Win!\" | \"You Lose!\" | \"It's a Draw!\" | null;\n} => {\n for (let row = 0; row < 3; row++) {\n if (\n board[row]![0] &&\n board[row]![0] === board[row]![1] &&\n board[row]![1] === board[row]![2]\n ) {\n return {\n gameOver: true,\n winner: board[row]![0] === \"X\" ? \"You Win!\" : \"You Lose!\",\n };\n }\n }\n\n for (let col = 0; col < 3; col++) {\n if (\n board[0]![col] &&\n board[0]![col] === board[1]![col] &&\n board[1]![col] === board[2]![col]\n ) {\n return {\n gameOver: true,\n winner: board[0]![col] === \"X\" ? \"You Win!\" : \"You Lose!\",\n };\n }\n }\n\n if (\n board[0]![0] &&\n board[0]![0] === board[1]![1] &&\n board[1]![1] === board[2]![2]\n ) {\n return {\n gameOver: true,\n winner: board[0]![0] === \"X\" ? \"You Win!\" : \"You Lose!\",\n };\n }\n\n if (\n board[0]![2] &&\n board[0]![2] === board[1]![1] &&\n board[1]![1] === board[2]![0]\n ) {\n return {\n gameOver: true,\n winner: board[0]![2] === \"X\" ? \"You Win!\" : \"You Lose!\",\n };\n }\n\n const allFilled = board.every((row) => row.every((cell) => cell !== \"\"));\n\n if (allFilled) {\n return {\n gameOver: true,\n winner: \"It's a Draw!\",\n };\n }\n\n return {\n gameOver: false,\n winner: null,\n };\n};\n\nconst checkWinnerAction = createAction<State>(\n \"check-winner\",\n async ({ state }: ArcStateContext<State>) => {\n const board = state.get(\"board\");\n const result = check(board);\n\n return state.set(\"gameOver\", result.gameOver).set(\"winner\", result.winner);\n }\n);\n\nexport default checkWinnerAction;\n","import { defineArc, InferOutputContext } from \"@arc-dev/core\";\nimport { State } from \"./tic-tac-toe.arc\";\nimport playerMoveAction from \"./actions/player-move\";\nimport aiMoveAgent, { aiMoveSchema } from \"./agents/ai-move\";\nimport applyAIMoveAction from \"./actions/apply-ai-move\";\nimport checkWinnerAction from \"./actions/check-winner\";\n\nexport type OutputContext = InferOutputContext<{\n \"ai-move\": typeof aiMoveSchema;\n}>;\n\nexport const GameLoopArc = defineArc<State, OutputContext>(\n \"game-loop\",\n (arc) => {\n arc\n .waitForInput(\"player\")\n .to(\"player-move\", playerMoveAction)\n .to(\"ai-move\", aiMoveAgent)\n .to(\"apply-ai-move\", applyAIMoveAction)\n .to(\"check-winner\", checkWinnerAction);\n }\n);\n","import { defineArc } from \"@arc-dev/core\";\nimport { GameLoopArc } from \"./game-loop.arc\";\n\ntype BoardState = string[][];\n\nexport type State = {\n board: BoardState;\n currentPlayer: \"X\" | \"O\";\n gameOver: boolean;\n winner: \"You Win!\" | \"You Lose!\" | \"It's a Draw!\" | null;\n};\n\nexport const TicTacToeArc = defineArc<State>(\"tic-tac-toe\", (arc) => {\n const loop = arc.use(\"game-loop\", GameLoopArc);\n\n arc.loop(loop, {\n while: ({ state }) => !state.get(\"gameOver\"),\n max: 9,\n });\n});\n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C1C,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;AAChC,IAAA,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC;AAE3B,IAAA,OAAO,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC;AAC5E,CAAC,CACF;;ACrEM,MAAM,WAAW,GAAGC,cAAS,CAClC,WAAW,EACX,CAAC,GAAG,KAAI;IACN;SACG,YAAY,CAAC,QAAQ;AACrB,SAAA,EAAE,CAAC,aAAa,EAAE,gBAAgB;AAClC,SAAA,EAAE,CAAC,SAAS,EAAE,WAAW;AACzB,SAAA,EAAE,CAAC,eAAe,EAAE,iBAAiB;AACrC,SAAA,EAAE,CAAC,cAAc,EAAE,iBAAiB,CAAC;AAC1C,CAAC,CACF;;ACTM,MAAM,YAAY,GAAGA,cAAS,CAAQ,aAAa,EAAE,CAAC,GAAG,KAAI;IAClE,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC;AAE9C,IAAA,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE;AACb,QAAA,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC;AAC5C,QAAA,GAAG,EAAE,CAAC;AACP,KAAA,CAAC;AACJ,CAAC;;;;;"}

@@ -1,7 +0,32 @@

import { Arc } from '@arc-dev/core';
import * as _arc_dev_core from '@arc-dev/core';
import { InferOutputContext } from '@arc-dev/core';
import { z } from 'zod';
declare const ToneRewriterArc: Arc;
declare const verifyStyleSchema: z.ZodObject<{
quality: z.ZodNumber;
}, z.core.$strip>;
declare const TicTacToeArc: Arc;
declare const planStyleSchema: z.ZodObject<{
text: z.ZodString;
}, z.core.$strip>;
type State$1 = {
examples: string[];
text: string;
result?: string;
};
declare const ToneRewriterArc: _arc_dev_core.Arc<State$1, InferOutputContext<{
"plan-style": typeof planStyleSchema;
"verify-style": typeof verifyStyleSchema;
}>>;
type BoardState = string[][];
type State = {
board: BoardState;
currentPlayer: "X" | "O";
gameOver: boolean;
winner: "You Win!" | "You Lose!" | "It's a Draw!" | null;
};
declare const TicTacToeArc: _arc_dev_core.Arc<State, any>;
export { TicTacToeArc, ToneRewriterArc };

@@ -1,32 +0,21 @@

import { createArc } from '@arc-dev/core';
import { createAgent, createAction, defineArc } from '@arc-dev/core';
import { z } from 'zod';
var NodeId$1;
(function (NodeId) {
NodeId["Plan"] = "plan-style";
NodeId["Verify"] = "verify-style";
NodeId["Finalize"] = "finalize-rewrite";
})(NodeId$1 || (NodeId$1 = {}));
var ConditionId;
(function (ConditionId) {
ConditionId["HighQuality"] = "high-quality";
})(ConditionId || (ConditionId = {}));
const QUALITY_THRESHOLD = 0.7;
const ToneRewriterArc = createArc("tone-rewriter", ({ node, edge }) => {
node.agent(NodeId$1.Plan, {
model: "openai/gpt-4o-mini",
output: z.object({
text: z.string(),
}),
messages: ({ state }) => {
const examples = state.get("examples");
const text = state.get("text");
return [
{
role: "system",
content: "You are a helpful assistant that rewrites text in different tones and styles that is based on the provided examples of the users writing styles.",
},
{
role: "user",
content: `
const planStyleSchema = z.object({
text: z.string(),
});
const planAgent = createAgent("plan-style", {
model: "openai/gpt-4o-mini",
output: planStyleSchema,
messages: ({ state }) => {
const examples = state.get("examples");
const text = state.get("text");
return [
{
role: "system",
content: "You are a helpful assistant that rewrites text in different tones and styles that is based on the provided examples of the users writing styles.",
},
{
role: "user",
content: `
My typically writing style is as follows:

@@ -38,19 +27,24 @@ ${examples.join("\n\n")}.

`,
},
];
},
});
node.agent(NodeId$1.Verify, {
model: "openai/gpt-4o-mini",
messages: ({ state, context }) => {
const examples = state.get("examples");
const rewrittenText = context.get(NodeId$1.Plan).get("text");
return [
{
role: "system",
content: "You are a style critic that evaluates text rewrites. Respond with ONLY a number between 0.0 and 1.0 representing the quality score.",
},
{
role: "user",
content: `Evaluate how well this text matches the users style of writing:
},
];
},
});
const verifyStyleSchema = z.object({
quality: z.number(),
});
const verifyAgent = createAgent("verify-style", {
model: "openai/gpt-4o-mini",
output: verifyStyleSchema,
messages: ({ state, context }) => {
const examples = state.get("examples");
const rewrittenText = context.get("plan-style").get("text");
return [
{
role: "system",
content: "You are a style critic that evaluates text rewrites. Respond with ONLY a number between 0.0 and 1.0 representing the quality score.",
},
{
role: "user",
content: `Evaluate how well this text matches the users style of writing:

@@ -64,26 +58,42 @@ My writing style examples are:

Provide an overall quality score between 0.0 (poor) and 1.0 (excellent).`,
},
];
},
output: z.object({
quality: z.number(),
}),
});
node.action(NodeId$1.Finalize, ({ state, context, render }) => {
const text = context.get(NodeId$1.Plan).get("text");
render(text);
return state.set("result", context.get(NodeId$1.Plan).get("text"));
});
edge.condition(ConditionId.HighQuality, ({ context }) => context.get(NodeId$1.Verify).get("quality") >= QUALITY_THRESHOLD);
edge.from(NodeId$1.Plan).to(NodeId$1.Verify);
edge.from(NodeId$1.Verify).to(NodeId$1.Finalize).when(ConditionId.HighQuality);
},
];
},
});
const moveAgent = {
const finalizeAction = createAction("finalize-rewrite", async ({ state, context }) => {
// Now context.get("plan-style") is strongly typed!
// TypeScript knows it returns TypedImmutableMap<PlanStyleOutput> with a "text" property
const planStyleOutput = context.get("plan-style");
const text = planStyleOutput.get("text");
return state.set("result", text);
});
const QUALITY_THRESHOLD = 0.7;
const ToneRewriterArc = defineArc("tone-rewriter", (arc) => {
arc
.from(planAgent)
.to(verifyAgent)
.to(finalizeAction)
.when(arc.condition("high-quality", ({ context }) => context.get("verify-style").get("quality") >= QUALITY_THRESHOLD));
});
const playerMoveAction = createAction("player-move", async ({ state, edgeContext }) => {
const answer = edgeContext.get("player-move") ?? "";
const [rowStr, colStr] = answer.split(",");
const row = parseInt(rowStr?.trim() || "0");
const col = parseInt(colStr?.trim() || "0");
const updatedBoard = state
.get("board")
.map((r, rIdx) => r.map((cell, cIdx) => rIdx === row && cIdx === col ? "X" : cell));
return state.set("board", updatedBoard).set("currentPlayer", "O");
});
const aiMoveSchema = z.object({
row: z.number(),
col: z.number(),
});
const aiMoveAgent = createAgent("ai-move", {
output: aiMoveSchema,
model: "openai/gpt-4o",
output: z.object({
row: z.number(),
col: z.number(),
}),
when: ({ state }) => !state.get("gameOver"),
messages: ({ state }) => {

@@ -109,5 +119,31 @@ const board = state.get("board");

},
};
});
const checkWinner = (board) => {
const applyAIMoveAction = createAction("apply-ai-move", async ({ state, context }) => {
const moveAgentResult = context.get("ai-move-agent");
const row = moveAgentResult.get("row");
const col = moveAgentResult.get("col");
const board = state.get("board");
let finalRow = row;
let finalCol = col;
if (row < 0 ||
row >= board.length ||
col < 0 ||
col >= board[0].length ||
board[row][col]) {
outerLoop: for (let r = 0; r < board.length; r++) {
for (let c = 0; c < board[r].length; c++) {
if (!board[r][c]) {
finalRow = r;
finalCol = c;
break outerLoop;
}
}
}
}
const updatedBoard = board.map((r, rIdx) => r.map((cell, cIdx) => rIdx === finalRow && cIdx === finalCol ? "O" : cell));
return state.set("board", updatedBoard).set("currentPlayer", "X");
});
const check = (board) => {
for (let row = 0; row < 3; row++) {

@@ -161,135 +197,23 @@ if (board[row][0] &&

};
const checkWinnerAction = createAction("check-winner", async ({ state }) => {
const board = state.get("board");
const result = check(board);
return state.set("gameOver", result.gameOver).set("winner", result.winner);
});
var NodeId;
(function (NodeId) {
NodeId["ShowBoard"] = "show-board";
NodeId["PlayerMove"] = "player-move";
NodeId["CheckWinner"] = "check-winner";
NodeId["GetAIMove"] = "get-ai-move";
NodeId["ApplyAIMove"] = "apply-ai-move";
})(NodeId || (NodeId = {}));
const Id = "game-loop-body";
const TicTacToeGameLoopArc = createArc(Id, ({ node, edge }) => {
node.action(NodeId.ShowBoard, async ({ state, render }) => {
const board = state.get("board");
let output = "\nBoard:\n";
board.forEach((row, idx) => {
const formattedRow = row.map((cell) => cell || " ").join(" | ");
output += `${idx}: ${formattedRow}\n`;
});
render(output);
return state;
});
node.action(NodeId.PlayerMove, async ({ state, edgeContext, render }) => {
const answer = edgeContext.get(NodeId.PlayerMove) ?? "";
const [rowStr, colStr] = answer.split(",");
const row = parseInt(rowStr?.trim() || "0");
const col = parseInt(colStr?.trim() || "0");
const updatedBoard = state
.get("board")
.map((r, rIdx) => r.map((cell, cIdx) => rIdx === row && cIdx === col ? "X" : cell));
let output = "";
updatedBoard.forEach((row, idx) => {
const formattedRow = row.map((cell) => cell || " ").join(" | ");
output += `${idx}: ${formattedRow}\n`;
});
render(output);
return state
.set("board", updatedBoard)
.set("currentPlayer", "O");
});
node.action(NodeId.CheckWinner, async ({ state, render }) => {
const board = state.get("board");
const result = checkWinner(board);
if (result.gameOver) {
render(`🎮 Game Over: ${result.winner}`);
}
return state
.set("gameOver", result.gameOver)
.set("winner", result.winner);
});
node.agent(NodeId.GetAIMove, moveAgent);
node.action(NodeId.ApplyAIMove, async ({ state, context, render }) => {
const moveAgentResult = context.get(NodeId.GetAIMove);
const row = moveAgentResult.get("row");
const col = moveAgentResult.get("col");
const board = state.get("board");
let finalRow = row;
let finalCol = col;
if (row < 0 ||
row >= board.length ||
col < 0 ||
col >= board[0].length ||
board[row][col]) {
outerLoop: for (let r = 0; r < board.length; r++) {
for (let c = 0; c < board[r].length; c++) {
if (!board[r][c]) {
finalRow = r;
finalCol = c;
break outerLoop;
}
}
}
}
const updatedBoard = board.map((r, rIdx) => r.map((cell, cIdx) => rIdx === finalRow && cIdx === finalCol ? "O" : cell));
let output = "";
updatedBoard.forEach((row, idx) => {
const formattedRow = row.map((cell) => cell || " ").join(" | ");
output += `${idx}: ${formattedRow}\n`;
});
render(output);
return state
.set("board", updatedBoard)
.set("currentPlayer", "X");
});
edge
.from(NodeId.ShowBoard)
.waitForInput({
message: "Enter your move (row, col): ",
validator: (input, { state }) => {
const [rowStr, colStr] = input.split(",");
const row = parseInt(rowStr?.trim() || "");
const col = parseInt(colStr?.trim() || "");
if (isNaN(row) || isNaN(col)) {
return {
valid: false,
message: "Invalid format. Use: row,col (e.g., 0,1)",
};
}
const board = state.get("board");
if (row < 0 ||
row >= board.length ||
col < 0 ||
col >= board[0].length) {
return {
valid: false,
message: "Out of bounds. Try again.",
};
}
if (board[row][col]) {
return {
valid: false,
message: "Space taken. Choose an empty space.",
};
}
return { valid: true };
},
})
.to(NodeId.PlayerMove);
edge.from(NodeId.PlayerMove).to(NodeId.GetAIMove);
edge.from(NodeId.GetAIMove).to(NodeId.ApplyAIMove);
edge.from(NodeId.ApplyAIMove).to(NodeId.CheckWinner);
const GameLoopArc = defineArc("game-loop", (arc) => {
arc
.waitForInput("player")
.to("player-move", playerMoveAction)
.to("ai-move", aiMoveAgent)
.to("apply-ai-move", applyAIMoveAction)
.to("check-winner", checkWinnerAction);
});
var ArcId;
(function (ArcId) {
ArcId["GameLoop"] = "game-loop";
})(ArcId || (ArcId = {}));
const TicTacToeArc = createArc("tic-tac-toe", ({ node, edge }) => {
node.arc(ArcId.GameLoop, TicTacToeGameLoopArc);
edge
.from(ArcId.GameLoop)
.to(ArcId.GameLoop)
.when(({ state }) => !state.get("gameOver"))
.maxIterations(9);
const TicTacToeArc = defineArc("tic-tac-toe", (arc) => {
const loop = arc.use("game-loop", GameLoopArc);
arc.loop(loop, {
while: ({ state }) => !state.get("gameOver"),
max: 9,
});
});

@@ -296,0 +220,0 @@

@@ -1,1 +0,1 @@

{"version":3,"file":"index.js","sources":["../src/arcs/tone/tone.arc.ts","../src/arcs/tic-tac-toe/agents/move.agent.ts","../src/arcs/tic-tac-toe/actions/check-winner.ts","../src/arcs/tic-tac-toe/game-loop.arc.ts","../src/arcs/tic-tac-toe/tic-tac-toe.arc.ts"],"sourcesContent":["import { createArc, Arc } from \"@arc-dev/core\";\nimport { z } from \"zod\";\n\nenum NodeId {\n Plan = \"plan-style\",\n Verify = \"verify-style\",\n Finalize = \"finalize-rewrite\",\n}\n\nenum ConditionId {\n HighQuality = \"high-quality\",\n}\nconst QUALITY_THRESHOLD = 0.7;\n\ntype State = {\n examples: string[];\n text: string;\n};\n\nexport const ToneRewriterArc: Arc = createArc<State>(\n \"tone-rewriter\",\n ({ node, edge }) => {\n node.agent(NodeId.Plan, {\n model: \"openai/gpt-4o-mini\",\n output: z.object({\n text: z.string(),\n }),\n messages: ({ state }) => {\n const examples = state.get(\"examples\");\n const text = state.get(\"text\");\n\n return [\n {\n role: \"system\",\n content:\n \"You are a helpful assistant that rewrites text in different tones and styles that is based on the provided examples of the users writing styles.\",\n },\n {\n role: \"user\",\n content: `\n My typically writing style is as follows:\n ${examples.join(\"\\n\\n\")}.\n \n You must rewrite the following text to match my writing style as closely as possible, do not changing the meaning of the text:\n \"${text}\"\n `,\n },\n ];\n },\n });\n node.agent(NodeId.Verify, {\n model: \"openai/gpt-4o-mini\",\n messages: ({ state, context }) => {\n const examples = state.get(\"examples\");\n const rewrittenText = context.get(NodeId.Plan).get(\"text\");\n\n return [\n {\n role: \"system\",\n content:\n \"You are a style critic that evaluates text rewrites. Respond with ONLY a number between 0.0 and 1.0 representing the quality score.\",\n },\n {\n role: \"user\",\n content: `Evaluate how well this text matches the users style of writing:\n \n My writing style examples are:\n ${examples.join(\"\\n\\n\")}.\n \n Text:\n \"${rewrittenText}\"\n \n Provide an overall quality score between 0.0 (poor) and 1.0 (excellent).`,\n },\n ];\n },\n output: z.object({\n quality: z.number(),\n }),\n });\n node.action(NodeId.Finalize, ({ state, context, render }) => {\n const text = context.get(NodeId.Plan).get(\"text\");\n\n render(text);\n\n return state.set(\"result\", context.get(NodeId.Plan).get(\"text\"));\n });\n\n edge.condition(\n ConditionId.HighQuality,\n ({ context }) =>\n context.get(NodeId.Verify).get(\"quality\") >= QUALITY_THRESHOLD\n );\n edge.from(NodeId.Plan).to(NodeId.Verify);\n edge.from(NodeId.Verify).to(NodeId.Finalize).when(ConditionId.HighQuality);\n }\n);\n","import { ArcStateContext } from \"@arc-dev/core\";\nimport { State } from \"../tic-tac-toe.arc\";\nimport { z } from \"zod\";\n\nexport const moveAgent = {\n model: \"openai/gpt-4o\" as const,\n output: z.object({\n row: z.number(),\n col: z.number(),\n }),\n when: ({ state }: ArcStateContext<State, Record<string, never>>) =>\n !state.get(\"gameOver\"),\n messages: ({ state }: ArcStateContext<State, Record<string, never>>) => {\n const board = state.get(\"board\");\n\n return [\n {\n role: \"system\" as const,\n content: `\n You are playing tic-tac-toe as 'O' against 'X'. Empty cells are \"\" (empty strings).\n Play strategically: win if possible, block opponent wins, prefer center/corners over edges.\n Only play in empty (\"\") cells.\n `,\n },\n {\n role: \"user\" as const,\n content: `\n Board state: ${JSON.stringify(board)}\n Return the row and col indices of your move (must be an empty cell).\n `,\n },\n ];\n },\n};\n","import { State } from \"../tic-tac-toe.arc\";\nimport { ArcStateContext, TypedImmutableMap } from \"@arc-dev/core\";\n\nexport const checkWinner = (\n board: State[\"board\"]\n): {\n gameOver: boolean;\n winner: \"You Win!\" | \"You Lose!\" | \"It's a Draw!\" | null;\n} => {\n for (let row = 0; row < 3; row++) {\n if (\n board[row]![0] &&\n board[row]![0] === board[row]![1] &&\n board[row]![1] === board[row]![2]\n ) {\n return {\n gameOver: true,\n winner: board[row]![0] === \"X\" ? \"You Win!\" : \"You Lose!\",\n };\n }\n }\n\n for (let col = 0; col < 3; col++) {\n if (\n board[0]![col] &&\n board[0]![col] === board[1]![col] &&\n board[1]![col] === board[2]![col]\n ) {\n return {\n gameOver: true,\n winner: board[0]![col] === \"X\" ? \"You Win!\" : \"You Lose!\",\n };\n }\n }\n\n if (\n board[0]![0] &&\n board[0]![0] === board[1]![1] &&\n board[1]![1] === board[2]![2]\n ) {\n return {\n gameOver: true,\n winner: board[0]![0] === \"X\" ? \"You Win!\" : \"You Lose!\",\n };\n }\n\n if (\n board[0]![2] &&\n board[0]![2] === board[1]![1] &&\n board[1]![1] === board[2]![0]\n ) {\n return {\n gameOver: true,\n winner: board[0]![2] === \"X\" ? \"You Win!\" : \"You Lose!\",\n };\n }\n\n const allFilled = board.every((row) => row.every((cell) => cell !== \"\"));\n\n if (allFilled) {\n return {\n gameOver: true,\n winner: \"It's a Draw!\",\n };\n }\n\n return {\n gameOver: false,\n winner: null,\n };\n};\n\nexport const winnerAction = async ({\n state,\n}: ArcStateContext<State, any>): Promise<TypedImmutableMap<State>> => {\n const board = state.get(\"board\");\n const winnerOrNot = checkWinner(board);\n\n return state\n .set(\"gameOver\", winnerOrNot.gameOver)\n .set(\"winner\", winnerOrNot.winner);\n};\n","import { createArc, Arc } from \"@arc-dev/core\";\nimport { State } from \"./tic-tac-toe.arc\";\nimport { moveAgent } from \"./agents/move.agent\";\nimport { checkWinner } from \"./actions/check-winner\";\n\nenum NodeId {\n ShowBoard = \"show-board\",\n PlayerMove = \"player-move\",\n CheckWinner = \"check-winner\",\n GetAIMove = \"get-ai-move\",\n ApplyAIMove = \"apply-ai-move\",\n}\n\nconst Id = \"game-loop-body\";\n\nexport const TicTacToeGameLoopArc: Arc = createArc<State>(\n Id,\n ({ node, edge }) => {\n node.action(NodeId.ShowBoard, async ({ state, render }) => {\n const board = state.get(\"board\");\n\n let output = \"\\nBoard:\\n\";\n\n board.forEach((row: string[], idx: number) => {\n const formattedRow = row.map((cell) => cell || \" \").join(\" | \");\n output += `${idx}: ${formattedRow}\\n`;\n });\n\n render(output);\n\n return state;\n });\n\n node.action(NodeId.PlayerMove, async ({ state, edgeContext, render }) => {\n const answer = edgeContext.get(NodeId.PlayerMove) ?? \"\";\n const [rowStr, colStr] = answer.split(\",\");\n const row = parseInt(rowStr?.trim() || \"0\");\n const col = parseInt(colStr?.trim() || \"0\");\n\n const updatedBoard = state\n .get(\"board\")\n .map((r: string[], rIdx: number) =>\n r.map((cell: string, cIdx: number) =>\n rIdx === row && cIdx === col ? \"X\" : cell\n )\n );\n\n let output = \"\";\n updatedBoard.forEach((row: string[], idx: number) => {\n const formattedRow = row.map((cell: string) => cell || \" \").join(\" | \");\n output += `${idx}: ${formattedRow}\\n`;\n });\n\n render(output);\n\n return state\n .set(\"board\", updatedBoard)\n .set(\"currentPlayer\", \"O\" as const);\n });\n\n node.action(NodeId.CheckWinner, async ({ state, render }) => {\n const board = state.get(\"board\");\n const result = checkWinner(board);\n\n if (result.gameOver) {\n render(`🎮 Game Over: ${result.winner}`);\n }\n\n return state\n .set(\"gameOver\", result.gameOver)\n .set(\"winner\", result.winner);\n });\n\n node.agent(NodeId.GetAIMove, moveAgent);\n\n node.action(NodeId.ApplyAIMove, async ({ state, context, render }) => {\n const moveAgentResult = context.get(NodeId.GetAIMove);\n const row = moveAgentResult.get(\"row\");\n const col = moveAgentResult.get(\"col\");\n const board = state.get(\"board\");\n\n let finalRow = row;\n let finalCol = col;\n\n if (\n row < 0 ||\n row >= board.length ||\n col < 0 ||\n col >= board[0]!.length ||\n board[row]![col]\n ) {\n outerLoop: for (let r = 0; r < board.length; r++) {\n for (let c = 0; c < board[r]!.length; c++) {\n if (!board[r]![c]) {\n finalRow = r;\n finalCol = c;\n break outerLoop;\n }\n }\n }\n }\n\n const updatedBoard = board.map((r: string[], rIdx: number) =>\n r.map((cell: string, cIdx: number) =>\n rIdx === finalRow && cIdx === finalCol ? \"O\" : cell\n )\n );\n\n let output = \"\";\n updatedBoard.forEach((row: string[], idx: number) => {\n const formattedRow = row.map((cell: string) => cell || \" \").join(\" | \");\n output += `${idx}: ${formattedRow}\\n`;\n });\n\n render(output);\n\n return state\n .set(\"board\", updatedBoard)\n .set(\"currentPlayer\", \"X\" as const);\n });\n\n edge\n .from(NodeId.ShowBoard)\n .waitForInput({\n message: \"Enter your move (row, col): \",\n validator: (input: string, { state }) => {\n const [rowStr, colStr] = input.split(\",\");\n const row = parseInt(rowStr?.trim() || \"\");\n const col = parseInt(colStr?.trim() || \"\");\n\n if (isNaN(row) || isNaN(col)) {\n return {\n valid: false,\n message: \"Invalid format. Use: row,col (e.g., 0,1)\",\n };\n }\n\n const board = state.get(\"board\");\n if (\n row < 0 ||\n row >= board.length ||\n col < 0 ||\n col >= board[0]!.length\n ) {\n return {\n valid: false,\n message: \"Out of bounds. Try again.\",\n };\n }\n\n if (board[row]![col]) {\n return {\n valid: false,\n message: \"Space taken. Choose an empty space.\",\n };\n }\n\n return { valid: true };\n },\n })\n .to(NodeId.PlayerMove);\n edge.from(NodeId.PlayerMove).to(NodeId.GetAIMove);\n edge.from(NodeId.GetAIMove).to(NodeId.ApplyAIMove);\n edge.from(NodeId.ApplyAIMove).to(NodeId.CheckWinner);\n }\n);\n","import { createArc, Arc } from \"@arc-dev/core\";\nimport { TicTacToeGameLoopArc } from \"./game-loop.arc\";\n\nenum ArcId {\n GameLoop = \"game-loop\",\n}\n\ntype BoardState = string[][];\n\nexport type State = {\n board: BoardState;\n currentPlayer: \"X\" | \"O\";\n gameOver: boolean;\n winner: \"You Win!\" | \"You Lose!\" | \"It's a Draw!\" | null;\n};\n\nexport const TicTacToeArc: Arc = createArc<State>(\n \"tic-tac-toe\",\n ({ node, edge }) => {\n node.arc(ArcId.GameLoop, TicTacToeGameLoopArc);\n\n edge\n .from(ArcId.GameLoop)\n .to(ArcId.GameLoop)\n .when(({ state }) => !state.get(\"gameOver\"))\n .maxIterations(9);\n }\n);\n"],"names":["NodeId"],"mappings":";;;AAGA,IAAKA,QAIJ;AAJD,CAAA,UAAK,MAAM,EAAA;AACT,IAAA,MAAA,CAAA,MAAA,CAAA,GAAA,YAAmB;AACnB,IAAA,MAAA,CAAA,QAAA,CAAA,GAAA,cAAuB;AACvB,IAAA,MAAA,CAAA,UAAA,CAAA,GAAA,kBAA6B;AAC/B,CAAC,EAJIA,QAAM,KAANA,QAAM,GAAA,EAAA,CAAA,CAAA;AAMX,IAAK,WAEJ;AAFD,CAAA,UAAK,WAAW,EAAA;AACd,IAAA,WAAA,CAAA,aAAA,CAAA,GAAA,cAA4B;AAC9B,CAAC,EAFI,WAAW,KAAX,WAAW,GAAA,EAAA,CAAA,CAAA;AAGhB,MAAM,iBAAiB,GAAG,GAAG;AAOtB,MAAM,eAAe,GAAQ,SAAS,CAC3C,eAAe,EACf,CAAC,EAAE,IAAI,EAAE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,MAAM,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC;AAClD,IAAA,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC;AACtD,CAAC,CACF;;AClKD,IAAK,KAEJ;AAFD,CAAA,UAAK,KAAK,EAAA;AACR,IAAA,KAAA,CAAA,UAAA,CAAA,GAAA,WAAsB;AACxB,CAAC,EAFI,KAAK,KAAL,KAAK,GAAA,EAAA,CAAA,CAAA;AAaH,MAAM,YAAY,GAAQ,SAAS,CACxC,aAAa,EACb,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAI;IACjB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,oBAAoB,CAAC;IAE9C;AACG,SAAA,IAAI,CAAC,KAAK,CAAC,QAAQ;AACnB,SAAA,EAAE,CAAC,KAAK,CAAC,QAAQ;AACjB,SAAA,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC;SAC1C,aAAa,CAAC,CAAC,CAAC;AACrB,CAAC;;;;"}
{"version":3,"file":"index.js","sources":["../src/arcs/tone/agents/plan.ts","../src/arcs/tone/agents/verify.ts","../src/arcs/tone/actions/finalize.ts","../src/arcs/tone/tone.arc.ts","../src/arcs/tic-tac-toe/actions/player-move.ts","../src/arcs/tic-tac-toe/agents/ai-move.ts","../src/arcs/tic-tac-toe/actions/apply-ai-move.ts","../src/arcs/tic-tac-toe/actions/check-winner.ts","../src/arcs/tic-tac-toe/game-loop.arc.ts","../src/arcs/tic-tac-toe/tic-tac-toe.arc.ts"],"sourcesContent":["import { createAgent } from \"@arc-dev/core\";\nimport { z } from \"zod\";\nimport { State, OutputContext } from \"../tone.arc\";\n\nexport const planStyleSchema = z.object({\n text: z.string(),\n});\n\nconst planAgent = createAgent<State, OutputContext>(\"plan-style\", {\n model: \"openai/gpt-4o-mini\",\n output: planStyleSchema,\n messages: ({ state }) => {\n const examples = state.get(\"examples\");\n const text = state.get(\"text\");\n\n return [\n {\n role: \"system\",\n content:\n \"You are a helpful assistant that rewrites text in different tones and styles that is based on the provided examples of the users writing styles.\",\n },\n {\n role: \"user\",\n content: `\n My typically writing style is as follows:\n ${examples.join(\"\\n\\n\")}.\n \n You must rewrite the following text to match my writing style as closely as possible, do not changing the meaning of the text:\n \"${text}\"\n `,\n },\n ];\n },\n});\n\nexport default planAgent;\n","import { createAgent } from \"@arc-dev/core\";\nimport { z } from \"zod\";\nimport { State, OutputContext } from \"../tone.arc\";\n\nexport const verifyStyleSchema = z.object({\n quality: z.number(),\n});\n\nconst verifyAgent = createAgent<State, OutputContext>(\"verify-style\", {\n model: \"openai/gpt-4o-mini\",\n output: verifyStyleSchema,\n messages: ({ state, context }) => {\n const examples = state.get(\"examples\");\n const rewrittenText = context.get(\"plan-style\").get(\"text\");\n\n return [\n {\n role: \"system\",\n content:\n \"You are a style critic that evaluates text rewrites. Respond with ONLY a number between 0.0 and 1.0 representing the quality score.\",\n },\n {\n role: \"user\",\n content: `Evaluate how well this text matches the users style of writing:\n \n My writing style examples are:\n ${examples.join(\"\\n\\n\")}.\n \n Text:\n \"${rewrittenText}\"\n \n Provide an overall quality score between 0.0 (poor) and 1.0 (excellent).`,\n },\n ];\n },\n});\n\nexport default verifyAgent;\n","import { createAction, ArcStateContext } from \"@arc-dev/core\";\nimport { State, OutputContext } from \"../tone.arc\";\n\nconst finalizeAction = createAction<State, OutputContext>(\n \"finalize-rewrite\",\n async ({ state, context }) => {\n // Now context.get(\"plan-style\") is strongly typed!\n // TypeScript knows it returns TypedImmutableMap<PlanStyleOutput> with a \"text\" property\n const planStyleOutput = context.get(\"plan-style\");\n const text = planStyleOutput.get(\"text\");\n\n return state.set(\"result\", text);\n }\n);\n\nexport default finalizeAction;\n","import { defineArc, InferOutputContext } from \"@arc-dev/core\";\nimport planAgent, { planStyleSchema } from \"./agents/plan\";\nimport verifyAgent, { verifyStyleSchema } from \"./agents/verify\";\nimport finalizeAction from \"./actions/finalize\";\n\nconst QUALITY_THRESHOLD = 0.7;\n\nexport type State = {\n examples: string[];\n text: string;\n result?: string;\n};\n\nexport type OutputContext = InferOutputContext<{\n \"plan-style\": typeof planStyleSchema;\n \"verify-style\": typeof verifyStyleSchema;\n}>;\n\nexport const ToneRewriterArc = defineArc<State, OutputContext>(\n \"tone-rewriter\",\n (arc) => {\n arc\n .from(planAgent)\n .to(verifyAgent)\n .to(finalizeAction)\n .when(\n arc.condition(\n \"high-quality\",\n ({ context }) =>\n context.get(\"verify-style\").get(\"quality\") >= QUALITY_THRESHOLD\n )\n );\n }\n);\n","import { createAction, ArcStateContext } from \"@arc-dev/core\";\nimport { State } from \"../tic-tac-toe.arc\";\n\nconst playerMoveAction = createAction<State>(\n \"player-move\",\n async ({ state, edgeContext }: ArcStateContext<State>) => {\n const answer = edgeContext.get(\"player-move\") ?? \"\";\n const [rowStr, colStr] = answer.split(\",\");\n const row = parseInt(rowStr?.trim() || \"0\");\n const col = parseInt(colStr?.trim() || \"0\");\n\n const updatedBoard = state\n .get(\"board\")\n .map((r: string[], rIdx: number) =>\n r.map((cell: string, cIdx: number) =>\n rIdx === row && cIdx === col ? \"X\" : cell\n )\n );\n\n return state.set(\"board\", updatedBoard).set(\"currentPlayer\", \"O\" as const);\n }\n);\n\nexport default playerMoveAction;\n","import { ArcStateContext, createAgent } from \"@arc-dev/core\";\nimport { State } from \"../tic-tac-toe.arc\";\nimport { z } from \"zod\";\nimport { OutputContext } from \"../game-loop.arc\";\n\nexport const aiMoveSchema = z.object({\n row: z.number(),\n col: z.number(),\n});\n\nconst aiMoveAgent = createAgent<State, OutputContext>(\"ai-move\", {\n output: aiMoveSchema,\n model: \"openai/gpt-4o\" as const,\n messages: ({ state }: ArcStateContext<State>) => {\n const board = state.get(\"board\");\n\n return [\n {\n role: \"system\" as const,\n content: `\n You are playing tic-tac-toe as 'O' against 'X'. Empty cells are \"\" (empty strings).\n Play strategically: win if possible, block opponent wins, prefer center/corners over edges.\n Only play in empty (\"\") cells.\n `,\n },\n {\n role: \"user\" as const,\n content: `\n Board state: ${JSON.stringify(board)}\n Return the row and col indices of your move (must be an empty cell).\n `,\n },\n ];\n },\n});\n\nexport default aiMoveAgent;\n","import { createAction, ArcStateContext } from \"@arc-dev/core\";\nimport { State } from \"../tic-tac-toe.arc\";\n\nconst applyAIMoveAction = createAction<State>(\n \"apply-ai-move\",\n async ({ state, context }: ArcStateContext<State>) => {\n const moveAgentResult = context.get(\"ai-move-agent\");\n const row = moveAgentResult.get(\"row\");\n const col = moveAgentResult.get(\"col\");\n const board = state.get(\"board\");\n\n let finalRow = row;\n let finalCol = col;\n\n if (\n row < 0 ||\n row >= board.length ||\n col < 0 ||\n col >= board[0]!.length ||\n board[row]![col]\n ) {\n outerLoop: for (let r = 0; r < board.length; r++) {\n for (let c = 0; c < board[r]!.length; c++) {\n if (!board[r]![c]) {\n finalRow = r;\n finalCol = c;\n break outerLoop;\n }\n }\n }\n }\n\n const updatedBoard = board.map((r: string[], rIdx: number) =>\n r.map((cell: string, cIdx: number) =>\n rIdx === finalRow && cIdx === finalCol ? \"O\" : cell\n )\n );\n\n return state.set(\"board\", updatedBoard).set(\"currentPlayer\", \"X\" as const);\n }\n);\n\nexport default applyAIMoveAction;\n","import { createAction, ArcStateContext } from \"@arc-dev/core\";\nimport { State } from \"../tic-tac-toe.arc\";\n\nconst check = (\n board: State[\"board\"]\n): {\n gameOver: boolean;\n winner: \"You Win!\" | \"You Lose!\" | \"It's a Draw!\" | null;\n} => {\n for (let row = 0; row < 3; row++) {\n if (\n board[row]![0] &&\n board[row]![0] === board[row]![1] &&\n board[row]![1] === board[row]![2]\n ) {\n return {\n gameOver: true,\n winner: board[row]![0] === \"X\" ? \"You Win!\" : \"You Lose!\",\n };\n }\n }\n\n for (let col = 0; col < 3; col++) {\n if (\n board[0]![col] &&\n board[0]![col] === board[1]![col] &&\n board[1]![col] === board[2]![col]\n ) {\n return {\n gameOver: true,\n winner: board[0]![col] === \"X\" ? \"You Win!\" : \"You Lose!\",\n };\n }\n }\n\n if (\n board[0]![0] &&\n board[0]![0] === board[1]![1] &&\n board[1]![1] === board[2]![2]\n ) {\n return {\n gameOver: true,\n winner: board[0]![0] === \"X\" ? \"You Win!\" : \"You Lose!\",\n };\n }\n\n if (\n board[0]![2] &&\n board[0]![2] === board[1]![1] &&\n board[1]![1] === board[2]![0]\n ) {\n return {\n gameOver: true,\n winner: board[0]![2] === \"X\" ? \"You Win!\" : \"You Lose!\",\n };\n }\n\n const allFilled = board.every((row) => row.every((cell) => cell !== \"\"));\n\n if (allFilled) {\n return {\n gameOver: true,\n winner: \"It's a Draw!\",\n };\n }\n\n return {\n gameOver: false,\n winner: null,\n };\n};\n\nconst checkWinnerAction = createAction<State>(\n \"check-winner\",\n async ({ state }: ArcStateContext<State>) => {\n const board = state.get(\"board\");\n const result = check(board);\n\n return state.set(\"gameOver\", result.gameOver).set(\"winner\", result.winner);\n }\n);\n\nexport default checkWinnerAction;\n","import { defineArc, InferOutputContext } from \"@arc-dev/core\";\nimport { State } from \"./tic-tac-toe.arc\";\nimport playerMoveAction from \"./actions/player-move\";\nimport aiMoveAgent, { aiMoveSchema } from \"./agents/ai-move\";\nimport applyAIMoveAction from \"./actions/apply-ai-move\";\nimport checkWinnerAction from \"./actions/check-winner\";\n\nexport type OutputContext = InferOutputContext<{\n \"ai-move\": typeof aiMoveSchema;\n}>;\n\nexport const GameLoopArc = defineArc<State, OutputContext>(\n \"game-loop\",\n (arc) => {\n arc\n .waitForInput(\"player\")\n .to(\"player-move\", playerMoveAction)\n .to(\"ai-move\", aiMoveAgent)\n .to(\"apply-ai-move\", applyAIMoveAction)\n .to(\"check-winner\", checkWinnerAction);\n }\n);\n","import { defineArc } from \"@arc-dev/core\";\nimport { GameLoopArc } from \"./game-loop.arc\";\n\ntype BoardState = string[][];\n\nexport type State = {\n board: BoardState;\n currentPlayer: \"X\" | \"O\";\n gameOver: boolean;\n winner: \"You Win!\" | \"You Lose!\" | \"It's a Draw!\" | null;\n};\n\nexport const TicTacToeArc = defineArc<State>(\"tic-tac-toe\", (arc) => {\n const loop = arc.use(\"game-loop\", GameLoopArc);\n\n arc.loop(loop, {\n while: ({ state }) => !state.get(\"gameOver\"),\n max: 9,\n });\n});\n"],"names":[],"mappings":";;;AAIO,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC;AACtC,IAAA,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;AACjB,CAAA,CAAC;AAEF,MAAM,SAAS,GAAG,WAAW,CAAuB,YAAY,EAAE;AAChE,IAAA,KAAK,EAAE,oBAAoB;AAC3B,IAAA,MAAM,EAAE,eAAe;AACvB,IAAA,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,KAAI;QACtB,MAAM,QAAQ,GAAG,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC;QACtC,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC;QAE9B,OAAO;AACL,YAAA;AACE,gBAAA,IAAI,EAAE,QAAQ;AACd,gBAAA,OAAO,EACL,kJAAkJ;AACrJ,aAAA;AACD,YAAA;AACE,gBAAA,IAAI,EAAE,MAAM;AACZ,gBAAA,OAAO,EAAE;;AAEH,YAAA,EAAA,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;;;eAGpB,IAAI,CAAA;AACR,UAAA,CAAA;AACJ,aAAA;SACF;IACH,CAAC;AACF,CAAA,CAAC;;AC7BK,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;AACxC,IAAA,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;AACpB,CAAA,CAAC;AAEF,MAAM,WAAW,GAAG,WAAW,CAAuB,cAAc,EAAE;AACpE,IAAA,KAAK,EAAE,oBAAoB;AAC3B,IAAA,MAAM,EAAE,iBAAiB;IACzB,QAAQ,EAAE,CAAC,EAAE,KAAK,EAAE,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H;IAEA,OAAO;AACL,QAAA,QAAQ,EAAE,KAAK;AACf,QAAA,MAAM,EAAE,IAAI;KACb;AACH,CAAC;AAED,MAAM,iBAAiB,GAAG,YAAY,CACpC,cAAc,EACd,OAAO,EAAE,KAAK,EAA0B,KAAI;IAC1C,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC;AAChC,IAAA,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC;AAE3B,IAAA,OAAO,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC;AAC5E,CAAC,CACF;;ACrEM,MAAM,WAAW,GAAG,SAAS,CAClC,WAAW,EACX,CAAC,GAAG,KAAI;IACN;SACG,YAAY,CAAC,QAAQ;AACrB,SAAA,EAAE,CAAC,aAAa,EAAE,gBAAgB;AAClC,SAAA,EAAE,CAAC,SAAS,EAAE,WAAW;AACzB,SAAA,EAAE,CAAC,eAAe,EAAE,iBAAiB;AACrC,SAAA,EAAE,CAAC,cAAc,EAAE,iBAAiB,CAAC;AAC1C,CAAC,CACF;;ACTM,MAAM,YAAY,GAAG,SAAS,CAAQ,aAAa,EAAE,CAAC,GAAG,KAAI;IAClE,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,WAAW,CAAC;AAE9C,IAAA,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE;AACb,QAAA,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC;AAC5C,QAAA,GAAG,EAAE,CAAC;AACP,KAAA,CAAC;AACJ,CAAC;;;;"}
{
"name": "@arc-dev/examples",
"description": "Runnable ARC runtime examples",
"version": "0.0.2-alpha.3",
"version": "0.0.2-alpha.4",
"type": "module",

@@ -28,4 +28,4 @@ "license": "Apache-2.0",

"zod": "^4.1.13",
"@arc-dev/core": "0.0.2-alpha.3",
"@arc-dev/runtime": "0.0.2-alpha.3"
"@arc-dev/core": "0.0.2-alpha.4",
"@arc-dev/runtime": "0.0.2-alpha.4"
},

@@ -32,0 +32,0 @@ "devDependencies": {

import { ArcStateContext } from "@arc-dev/core";
import { State } from "../tic-tac-toe.arc";
import { z } from "zod";
export declare const moveAgent: {
model: "openai/gpt-4o";
output: z.ZodObject<{
row: z.ZodNumber;
col: z.ZodNumber;
}, z.core.$strip>;
when: ({ state }: ArcStateContext<State, Record<string, never>>) => boolean;
messages: ({ state }: ArcStateContext<State, Record<string, never>>) => ({
role: "system";
content: string;
} | {
role: "user";
content: string;
})[];
};
//# sourceMappingURL=move.agent.d.ts.map
{"version":3,"file":"move.agent.d.ts","sourceRoot":"","sources":["../../../../src/arcs/tic-tac-toe/agents/move.agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,SAAS;;;;;;sBAMF,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;0BAEzC,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;;;;;;;CAqBpE,CAAC"}