@cloudbase/agent-examples-agkit-agents-manga-creator 0.0.2 → 0.0.6

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/src/agent.ts CHANGED
@@ -100,23 +100,7 @@ export function createMangaCreatorAgent(): Agent<MangaCreationState> {
100
100
  - Maintain a consistent comic style throughout based on confirmed parameters
101
101
  - Dialogue and narrative text should complement the images naturally
102
102
  - Follow comic book conventions: panel layout, dialogue bubbles, sound effects, etc.
103
-
104
- **Output Format:**
105
- - During generation: Show each panel as it's created (image + story paragraph)
106
- - Final output: Use Markdown format with all images and story text combined into a complete picture book, like:
107
- \`\`\`markdown
108
- # Story Title
109
-
110
- ![Panel 1](image_url_1)
111
-
112
- Story paragraph for panel 1...
113
-
114
- ![Panel 2](image_url_2)
115
-
116
- Story paragraph for panel 2...
117
-
118
- ...
119
- \`\`\``,
103
+ `,
120
104
  modelSettings: {
121
105
  temperature: 0.8,
122
106
  maxTokens: 16000,
@@ -174,9 +158,64 @@ export function createMangaCreatorAgent(): Agent<MangaCreationState> {
174
158
  }
175
159
 
176
160
  // If user message contains confirmed character design parameters, update state
177
- if (userMessage && characterDesignParams && !characterDesignParams.userConfirmed) {
161
+ // Also check state.userResponse in case userMessage is not provided
162
+ const confirmationMessage = userMessage || (state.userResponse && typeof state.userResponse === 'string' ? state.userResponse : JSON.stringify(state.userResponse || {}));
163
+
164
+ // Check if this is a character design confirmation
165
+ // IMPORTANT: Even if characterDesignParams doesn't exist (e.g., after state restore),
166
+ // we should still update state.characters if userResponse contains confirmation
167
+ if (confirmationMessage) {
178
168
  try {
179
- const confirmedParams = JSON.parse(userMessage);
169
+ const confirmedParams = typeof confirmationMessage === 'string' ? JSON.parse(confirmationMessage) : confirmationMessage;
170
+ if (confirmedParams.userConfirmed && confirmedParams.type === "character_design" && confirmedParams.characters) {
171
+ // Update characters in state with confirmed designs
172
+ // This works even if characterDesignParams doesn't exist
173
+ for (const char of confirmedParams.characters) {
174
+ const existingIndex = state.characters.findIndex((c) => c.name === char.name);
175
+ if (existingIndex >= 0) {
176
+ state.characters[existingIndex].description = char.description;
177
+ } else {
178
+ state.characters.push({
179
+ name: char.name,
180
+ description: char.description,
181
+ });
182
+ }
183
+ }
184
+
185
+ // Update characterDesignParams if it exists
186
+ if (state.characterDesignParams) {
187
+ state.characterDesignParams.userConfirmed = true;
188
+ } else {
189
+ // Create characterDesignParams if it doesn't exist (for consistency)
190
+ state.characterDesignParams = {
191
+ characters: confirmedParams.characters.map((c: any) => ({
192
+ name: c.name,
193
+ description: c.description,
194
+ })),
195
+ userConfirmed: true,
196
+ };
197
+ }
198
+
199
+ console.log("=== Character Design Confirmed in handleNextStep ===");
200
+ console.log("Updated state.characters:", state.characters);
201
+ console.log("Character count:", state.characters.length);
202
+ console.log("===================================================");
203
+
204
+ // Clear userResponse after processing
205
+ state.userResponse = undefined;
206
+ // Continue execution
207
+ return { action: "continue", nextStep: null } as const;
208
+ }
209
+ } catch (error) {
210
+ // If parsing fails, treat as regular message and continue
211
+ console.error("Failed to parse character design confirmation:", error);
212
+ }
213
+ }
214
+
215
+ // Legacy check: if characterDesignParams exists and is not confirmed
216
+ if (confirmationMessage && characterDesignParams && !characterDesignParams.userConfirmed) {
217
+ try {
218
+ const confirmedParams = typeof confirmationMessage === 'string' ? JSON.parse(confirmationMessage) : confirmationMessage;
180
219
  if (confirmedParams.userConfirmed && confirmedParams.type === "character_design") {
181
220
  // Update state with confirmed character designs
182
221
  if (state.characterDesignParams && confirmedParams.characters) {
@@ -193,12 +232,18 @@ export function createMangaCreatorAgent(): Agent<MangaCreationState> {
193
232
  });
194
233
  }
195
234
  }
235
+ console.log("=== Character Design Confirmed in handleNextStep (legacy) ===");
236
+ console.log("Updated state.characters:", state.characters);
237
+ console.log("===================================================");
196
238
  }
239
+ // Clear userResponse after processing
240
+ state.userResponse = undefined;
197
241
  // Continue execution
198
242
  return { action: "continue", nextStep: null } as const;
199
243
  }
200
- } catch {
244
+ } catch (error) {
201
245
  // If parsing fails, treat as regular message and continue
246
+ console.error("Failed to parse character design confirmation:", error);
202
247
  }
203
248
  }
204
249
 
package/src/tools.ts CHANGED
@@ -101,7 +101,7 @@ export const generateCharacterDesignTool = tool(
101
101
 
102
102
  console.log("=== Character Design Tool Called ===");
103
103
  console.log("Characters proposed:", characters.map(c => c.name));
104
- console.log("State.characters updated:", state.characters.map(c => ({ name: c.name, hasDescription: !!c.description })));
104
+ console.log("State.characters updated:", state.characters);
105
105
  console.log("===================================");
106
106
  }
107
107
 
@@ -218,6 +218,10 @@ export const generateComicPageTool = tool(
218
218
  async ({ pageNumber, panels, styleGuide }, context) => {
219
219
  try {
220
220
  const state = context?.state as MangaCreationState | undefined;
221
+
222
+ console.log("=== Generate Comic Page Tool Called ===");
223
+ console.log("State:", state);
224
+ console.log("===================================");
221
225
 
222
226
  if (!panels || panels.length === 0) {
223
227
  throw new Error("No panels provided for page generation");