foliko 1.1.7 → 1.1.9
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/.agent/agents/poster-expert.md +228 -0
- package/.agent/data/default.json +10 -0
- package/.agent/data/plugins-state.json +1 -1
- package/.agent/mcp_config.json +0 -6
- package/.agent/plugins/test-plugin.py +15 -0
- package/.agent/plugins/test_nested_plugin.py +85 -0
- package/.agent/sessions/cli_default.json +83 -803
- package/.agent/sessions/weixin_o9cq80zgZqKPA2-s59PN43GdDy1w@im.wechat.json +189 -0
- package/.claude/settings.local.json +8 -1
- package/cli/src/ui/chat-ui.js +32 -21
- package/foliko_poster.png +0 -0
- package/output/business_poster_final.png +0 -0
- package/output/emoji_test_v2.png +0 -0
- package/output/foliko-ai-launch-poster.png +0 -0
- package/output/foliko-poster.png +0 -0
- package/output/muji_style_poster.png +0 -0
- package/output/new_product_launch.png +0 -0
- package/output/news_poster_625yi_subsidy.png +0 -0
- package/output/tech_future_2026.png +0 -0
- package/output/tech_future_poster.png +0 -0
- package/package.json +2 -2
- package/plugins/default-plugins.js +60 -7
- package/plugins/extension-executor-plugin.js +32 -22
- package/plugins/feishu-plugin.js +2 -2
- package/plugins/python-plugin-loader.js +461 -40
- package/plugins/python-plugin-loader.js.bak +856 -0
- package/plugins/subagent-plugin.js +0 -121
- package/plugins/telegram-plugin.js +2 -2
- package/plugins/weixin-plugin.js +40 -31
- package/poster.png +0 -0
- package/skills/foliko-dev/SKILL.md +6 -0
- package/skills/python-plugin-dev/SKILL.md +124 -2
- package/src/core/agent-chat.js +220 -281
- package/src/core/agent.js +127 -29
- package/src/executors/mcp-executor.js +282 -26
- package/src/utils/plugin-helpers.js +22 -4
- package/system.md +362 -109
- package/test-scan.js +18 -0
- package/.agent/memory/feedback/mnt7jrlt-d67qs7.md +0 -15
- package/.agent/memory/feedback/mnt88ja3-al4fuy.md +0 -9
- package/.agent/plugins/poster-plugin/README.md +0 -304
- package/.agent/plugins/poster-plugin/emojis/rocket.png +0 -1
- package/.agent/plugins/poster-plugin/fonts/PatuaOne-Regular.ttf +0 -0
- package/.agent/plugins/poster-plugin/fonts/SegoeUI Emoji.ttf +0 -0
- package/.agent/plugins/poster-plugin/fonts//345/276/256/350/275/257/351/233/205/351/273/221.ttf +0 -0
- package/.agent/plugins/poster-plugin/fonts//345/276/256/350/275/257/351/233/205/351/273/221/347/262/227/344/275/223.ttf +0 -0
- package/.agent/plugins/poster-plugin/index.js +0 -13
- package/.agent/plugins/poster-plugin/package.json +0 -29
- package/.agent/plugins/poster-plugin/src/canvas.js +0 -224
- package/.agent/plugins/poster-plugin/src/components/arrow.js +0 -84
- package/.agent/plugins/poster-plugin/src/components/avatar.js +0 -71
- package/.agent/plugins/poster-plugin/src/components/badge.js +0 -85
- package/.agent/plugins/poster-plugin/src/components/barcode.js +0 -120
- package/.agent/plugins/poster-plugin/src/components/bubble.js +0 -153
- package/.agent/plugins/poster-plugin/src/components/button.js +0 -124
- package/.agent/plugins/poster-plugin/src/components/card.js +0 -88
- package/.agent/plugins/poster-plugin/src/components/chart.js +0 -127
- package/.agent/plugins/poster-plugin/src/components/chip.js +0 -88
- package/.agent/plugins/poster-plugin/src/components/columns.js +0 -107
- package/.agent/plugins/poster-plugin/src/components/cta.js +0 -87
- package/.agent/plugins/poster-plugin/src/components/divider.js +0 -55
- package/.agent/plugins/poster-plugin/src/components/feature.js +0 -85
- package/.agent/plugins/poster-plugin/src/components/featureGrid.js +0 -117
- package/.agent/plugins/poster-plugin/src/components/frame.js +0 -230
- package/.agent/plugins/poster-plugin/src/components/grid.js +0 -118
- package/.agent/plugins/poster-plugin/src/components/highlightText.js +0 -144
- package/.agent/plugins/poster-plugin/src/components/icon.js +0 -94
- package/.agent/plugins/poster-plugin/src/components/imageFrame.js +0 -155
- package/.agent/plugins/poster-plugin/src/components/index.js +0 -81
- package/.agent/plugins/poster-plugin/src/components/listItem.js +0 -147
- package/.agent/plugins/poster-plugin/src/components/notification.js +0 -123
- package/.agent/plugins/poster-plugin/src/components/progress.js +0 -79
- package/.agent/plugins/poster-plugin/src/components/progressCircle.js +0 -117
- package/.agent/plugins/poster-plugin/src/components/qrcode.js +0 -74
- package/.agent/plugins/poster-plugin/src/components/quote.js +0 -97
- package/.agent/plugins/poster-plugin/src/components/rating.js +0 -85
- package/.agent/plugins/poster-plugin/src/components/ribbon.js +0 -193
- package/.agent/plugins/poster-plugin/src/components/seal.js +0 -146
- package/.agent/plugins/poster-plugin/src/components/star.js +0 -70
- package/.agent/plugins/poster-plugin/src/components/statCard.js +0 -105
- package/.agent/plugins/poster-plugin/src/components/stepper.js +0 -118
- package/.agent/plugins/poster-plugin/src/components/table.js +0 -167
- package/.agent/plugins/poster-plugin/src/components/tagCloud.js +0 -85
- package/.agent/plugins/poster-plugin/src/components/timeline.js +0 -117
- package/.agent/plugins/poster-plugin/src/components/watermark.js +0 -52
- package/.agent/plugins/poster-plugin/src/composer.js +0 -2146
- package/.agent/plugins/poster-plugin/src/elements/artText.js +0 -60
- package/.agent/plugins/poster-plugin/src/elements/background.js +0 -84
- package/.agent/plugins/poster-plugin/src/elements/circle.js +0 -31
- package/.agent/plugins/poster-plugin/src/elements/image.js +0 -28
- package/.agent/plugins/poster-plugin/src/elements/index.js +0 -28
- package/.agent/plugins/poster-plugin/src/elements/line.js +0 -23
- package/.agent/plugins/poster-plugin/src/elements/polygon.js +0 -63
- package/.agent/plugins/poster-plugin/src/elements/rectangle.js +0 -32
- package/.agent/plugins/poster-plugin/src/elements/richText.js +0 -230
- package/.agent/plugins/poster-plugin/src/elements/svg.js +0 -108
- package/.agent/plugins/poster-plugin/src/elements/text.js +0 -109
- package/.agent/plugins/poster-plugin/src/fonts.js +0 -243
- package/.agent/plugins/poster-plugin/src/index.js +0 -2081
- package/.agent/plugins/poster-plugin/src/presets.js +0 -36
- package/.agent/plugins/poster-plugin/src/templates/business.js +0 -60
- package/.agent/plugins/poster-plugin/src/templates/gradient.js +0 -64
- package/.agent/plugins/poster-plugin/src/templates/index.js +0 -43
- package/.agent/plugins/poster-plugin/src/templates/modern.js +0 -69
- package/.agent/plugins/poster-plugin/src/templates/simple.js +0 -58
- package/.agent/plugins/poster-plugin/src/templates/social.js +0 -62
- package/.agent/plugins/poster-plugin/src/templates/tech.js +0 -84
- package/.agent/plugins/poster-plugin/src/utils/imageLoader.js +0 -84
- package/.agent/plugins/poster-plugin/test-background.svg +0 -1
- package/.agent/plugins/poster-plugin/test-full-poster.svg +0 -2
- package/.agent/plugins/poster-plugin/test-image.png +0 -0
- package/.agent/plugins/poster-plugin/yarn.lock +0 -1007
- package/output/zen_silence.png +0 -0
package/src/core/agent.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
const { EventEmitter } = require('../utils/event-emitter');
|
|
7
7
|
const { AgentChatHandler } = require('./agent-chat');
|
|
8
8
|
const { SystemPromptBuilder } = require('./system-prompt-builder');
|
|
9
|
-
const { zodSchemaToMarkdown } = require('@chnak/zod-to-markdown');
|
|
9
|
+
const { zodSchemaToMarkdown, zodSchemaToTable } = require('@chnak/zod-to-markdown');
|
|
10
10
|
const { zodSchema } = require('ai');
|
|
11
11
|
const os = require('os');
|
|
12
12
|
|
|
@@ -145,7 +145,18 @@ class Agent extends EventEmitter {
|
|
|
145
145
|
return null;
|
|
146
146
|
});
|
|
147
147
|
|
|
148
|
-
// 3.
|
|
148
|
+
// 3. 日期时间(每次构建时都重新获取)
|
|
149
|
+
this._systemPromptBuilder.register('datetime', 50, () => {
|
|
150
|
+
const now = new Date();
|
|
151
|
+
const timeStr = now.toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai' });
|
|
152
|
+
const dateStr = now.toLocaleDateString('zh-CN', {
|
|
153
|
+
timeZone: 'Asia/Shanghai',
|
|
154
|
+
weekday: 'long',
|
|
155
|
+
});
|
|
156
|
+
return `【当前时间】${timeStr}(${dateStr})`;
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// 4. 元数据
|
|
149
160
|
this._systemPromptBuilder.register('metadata', PROMPT_PRIORITY.METADATA, () => {
|
|
150
161
|
if (this._metadata.size === 0) {
|
|
151
162
|
return null;
|
|
@@ -179,9 +190,9 @@ class Agent extends EventEmitter {
|
|
|
179
190
|
this._buildCapabilitiesDescription()
|
|
180
191
|
);
|
|
181
192
|
// 8. MCP 工具列表
|
|
182
|
-
this._systemPromptBuilder.register('mcp-tools', PROMPT_PRIORITY.MCP_TOOLS, () =>
|
|
183
|
-
|
|
184
|
-
);
|
|
193
|
+
// this._systemPromptBuilder.register('mcp-tools', PROMPT_PRIORITY.MCP_TOOLS, () =>
|
|
194
|
+
// this._buildMcpToolsDescription()
|
|
195
|
+
// );
|
|
185
196
|
// 9. 扩展工具列表
|
|
186
197
|
this._systemPromptBuilder.register('extension-tools', PROMPT_PRIORITY.EXTENSION_TOOLS, () =>
|
|
187
198
|
this._buildExtensionToolsDescription()
|
|
@@ -338,6 +349,7 @@ class Agent extends EventEmitter {
|
|
|
338
349
|
if (!extensions || extensions.length === 0) {
|
|
339
350
|
return '';
|
|
340
351
|
}
|
|
352
|
+
const mcp = this.framework.pluginManager.get('mcp');
|
|
341
353
|
|
|
342
354
|
const sections = [
|
|
343
355
|
'## Extensions 扩展工具',
|
|
@@ -363,26 +375,31 @@ class Agent extends EventEmitter {
|
|
|
363
375
|
for (const tool of ext.tools) {
|
|
364
376
|
sections.push(`#### \`${tool.name}\``, '');
|
|
365
377
|
sections.push(tool.description || '无描述', '');
|
|
366
|
-
|
|
367
378
|
// 使用 zodSchemaToMarkdown 解析参数
|
|
368
|
-
if (
|
|
379
|
+
if (ext.name === 'mcp' && mcp) {
|
|
380
|
+
const mcp_desc = mcp._bindMcpParamsDesc(tool.inputSchema);
|
|
381
|
+
sections.push(mcp_desc, '');
|
|
382
|
+
} else if (tool.inputSchema) {
|
|
369
383
|
try {
|
|
370
384
|
const schemaMarkdown = zodSchemaToMarkdown(tool.inputSchema);
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
} else {
|
|
385
|
+
sections.push('**参数:**', ' ');
|
|
386
|
+
sections.push(schemaMarkdown || '无', ' ');
|
|
387
|
+
} catch (e) {
|
|
388
|
+
// 降级处理:尝试 zodSchemaToTable
|
|
389
|
+
try {
|
|
390
|
+
const schemaTable = zodSchemaToTable(tool.inputSchema);
|
|
378
391
|
sections.push('**参数:**', ' ');
|
|
379
|
-
sections.push(
|
|
392
|
+
sections.push(schemaTable || '无', ' ');
|
|
393
|
+
} catch (e2) {
|
|
394
|
+
// 最后降级:尝试简单解析
|
|
395
|
+
try {
|
|
396
|
+
const simpleParams = this._simpleParamsDesc(tool.inputSchema);
|
|
397
|
+
sections.push('**参数:**', ' ');
|
|
398
|
+
sections.push(simpleParams, ' ');
|
|
399
|
+
} catch (e3) {
|
|
400
|
+
sections.push('**参数:** 无可用描述', ' ');
|
|
401
|
+
}
|
|
380
402
|
}
|
|
381
|
-
} catch (e) {
|
|
382
|
-
logger.warn('Agent', `转换工具 ${tool.name} 的参数描述失败`, e.message);
|
|
383
|
-
// 降级处理:手动解析常见 Zod 类型
|
|
384
|
-
sections.push('**参数:**', ' ');
|
|
385
|
-
sections.push(this._fallbackSchemaToText(tool.inputSchema), ' ');
|
|
386
403
|
}
|
|
387
404
|
}
|
|
388
405
|
|
|
@@ -421,12 +438,31 @@ class Agent extends EventEmitter {
|
|
|
421
438
|
* @returns {string} 参数描述文本
|
|
422
439
|
*/
|
|
423
440
|
_fallbackSchemaToText(schema) {
|
|
424
|
-
if (!schema
|
|
441
|
+
if (!schema) {
|
|
442
|
+
return '- (参数描述不可用)';
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// 尝试获取 shape(标准 Zod schema)
|
|
446
|
+
const shape = typeof schema.shape === 'function' ? schema.shape() : schema.shape;
|
|
447
|
+
if (!shape || typeof shape !== 'object') {
|
|
448
|
+
// schema 没有标准 shape,可能是 MCP 的简化 schema
|
|
449
|
+
// 尝试从 properties 构建描述
|
|
450
|
+
if (schema.properties) {
|
|
451
|
+
const lines = [];
|
|
452
|
+
for (const [name, field] of Object.entries(schema.properties)) {
|
|
453
|
+
const type = field.type || 'any';
|
|
454
|
+
const desc = field.description || '';
|
|
455
|
+
const required = schema.required?.includes(name);
|
|
456
|
+
const isOptional = required ? '' : '(可选)';
|
|
457
|
+
lines.push(`- ${name} (${type}) ${isOptional}${desc ? `: ${desc}` : ''}`);
|
|
458
|
+
}
|
|
459
|
+
return lines.join('\n') || '- (参数描述不可用)';
|
|
460
|
+
}
|
|
425
461
|
return '- (参数描述不可用)';
|
|
426
462
|
}
|
|
427
463
|
|
|
428
464
|
const lines = [];
|
|
429
|
-
for (const [name, field] of Object.entries(
|
|
465
|
+
for (const [name, field] of Object.entries(shape)) {
|
|
430
466
|
const typeInfo = this._extractFieldType(field);
|
|
431
467
|
const desc = typeInfo.description || '';
|
|
432
468
|
const isOptional = typeInfo.isOptional ? '(可选)' : '(必填)';
|
|
@@ -436,6 +472,43 @@ class Agent extends EventEmitter {
|
|
|
436
472
|
return lines.join('\n') || '- (参数描述不可用)';
|
|
437
473
|
}
|
|
438
474
|
|
|
475
|
+
/**
|
|
476
|
+
* 简单的参数描述(当 zodSchemaToMarkdown 和 zodSchemaToTable 都失败时)
|
|
477
|
+
* 直接从 schema 的 properties 提取信息
|
|
478
|
+
*/
|
|
479
|
+
_simpleParamsDesc(schema) {
|
|
480
|
+
if (!schema) return '无';
|
|
481
|
+
|
|
482
|
+
// 尝试 properties 格式
|
|
483
|
+
if (schema.properties) {
|
|
484
|
+
const lines = [];
|
|
485
|
+
const required = schema.required || [];
|
|
486
|
+
for (const [name, prop] of Object.entries(schema.properties)) {
|
|
487
|
+
const type = prop.type || 'any';
|
|
488
|
+
const desc = prop.description || '';
|
|
489
|
+
const isRequired = required.includes(name);
|
|
490
|
+
lines.push(`- ${name} (${type})${isRequired ? '' : '(可选)'}${desc ? `: ${desc}` : ''}`);
|
|
491
|
+
}
|
|
492
|
+
return lines.join('\n') || '无';
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// 尝试直接从 schema 提取
|
|
496
|
+
if (schema.jsonSchema?.properties) {
|
|
497
|
+
const props = schema.jsonSchema.properties;
|
|
498
|
+
const required = schema.jsonSchema.required || [];
|
|
499
|
+
const lines = [];
|
|
500
|
+
for (const [name, prop] of Object.entries(props)) {
|
|
501
|
+
const type = prop.type || 'any';
|
|
502
|
+
const desc = prop.description || '';
|
|
503
|
+
const isRequired = required.includes(name);
|
|
504
|
+
lines.push(`- ${name} (${type})${isRequired ? '' : '(可选)'}${desc ? `: ${desc}` : ''}`);
|
|
505
|
+
}
|
|
506
|
+
return lines.join('\n') || '无';
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
return '无';
|
|
510
|
+
}
|
|
511
|
+
|
|
439
512
|
/**
|
|
440
513
|
* 递归提取字段类型信息
|
|
441
514
|
* 处理 ZodOptional、ZodUnion、ZodArray 等复杂类型
|
|
@@ -443,12 +516,17 @@ class Agent extends EventEmitter {
|
|
|
443
516
|
* @returns {{ type: string, isOptional: boolean, description: string }}
|
|
444
517
|
*/
|
|
445
518
|
_extractFieldType(field) {
|
|
519
|
+
if (!field) {
|
|
520
|
+
return { type: 'unknown', isOptional: false, description: '' };
|
|
521
|
+
}
|
|
522
|
+
|
|
446
523
|
const typeName = field._def?.typeName || field.constructor?.name || '';
|
|
447
524
|
let description = field.description || field._def?.description || '';
|
|
448
525
|
|
|
449
526
|
switch (typeName) {
|
|
450
527
|
case 'ZodOptional': {
|
|
451
|
-
const inner = field._def
|
|
528
|
+
const inner = field._def?.innerType;
|
|
529
|
+
if (!inner) return { type: 'optional', isOptional: true, description };
|
|
452
530
|
const innerInfo = this._extractFieldType(inner);
|
|
453
531
|
return {
|
|
454
532
|
type: innerInfo.type,
|
|
@@ -457,14 +535,17 @@ class Agent extends EventEmitter {
|
|
|
457
535
|
};
|
|
458
536
|
}
|
|
459
537
|
case 'ZodUnion': {
|
|
538
|
+
if (!field._def?.options) return { type: 'union', isOptional: false, description };
|
|
460
539
|
const types = field._def.options.map((opt) => this._extractFieldType(opt).type);
|
|
461
540
|
return { type: `union(${types.join(' | ')})`, isOptional: false, description };
|
|
462
541
|
}
|
|
463
542
|
case 'ZodArray': {
|
|
543
|
+
if (!field._def?.type) return { type: 'array', isOptional: false, description };
|
|
464
544
|
const innerInfo = this._extractFieldType(field._def.type);
|
|
465
545
|
return { type: `${innerInfo.type}[]`, isOptional: false, description };
|
|
466
546
|
}
|
|
467
547
|
case 'ZodObject': {
|
|
548
|
+
if (!field._def?.shape) return { type: 'object', isOptional: false, description };
|
|
468
549
|
const props = Object.keys(field._def.shape()).join(', ');
|
|
469
550
|
return { type: `object{${props}}`, isOptional: false, description };
|
|
470
551
|
}
|
|
@@ -474,21 +555,28 @@ class Agent extends EventEmitter {
|
|
|
474
555
|
return { type: 'number', isOptional: false, description };
|
|
475
556
|
case 'ZodBoolean':
|
|
476
557
|
return { type: 'boolean', isOptional: false, description };
|
|
477
|
-
case 'ZodEnum':
|
|
558
|
+
case 'ZodEnum': {
|
|
559
|
+
const values = field._def?.values;
|
|
560
|
+
if (!values) return { type: 'enum', isOptional: false, description };
|
|
478
561
|
return {
|
|
479
|
-
type:
|
|
562
|
+
type: values.map((v) => `"${v}"`).join(' | '),
|
|
480
563
|
isOptional: false,
|
|
481
564
|
description,
|
|
482
565
|
};
|
|
566
|
+
}
|
|
483
567
|
case 'ZodRecord': {
|
|
484
|
-
const keyType = this._extractFieldType(field._def
|
|
485
|
-
const valueType = this._extractFieldType(field._def
|
|
486
|
-
return {
|
|
568
|
+
const keyType = this._extractFieldType(field._def?.keyType);
|
|
569
|
+
const valueType = this._extractFieldType(field._def?.valueType);
|
|
570
|
+
return {
|
|
571
|
+
type: `record<${keyType?.type || 'any'}, ${valueType?.type || 'any'}>`,
|
|
572
|
+
isOptional: false,
|
|
573
|
+
description,
|
|
574
|
+
};
|
|
487
575
|
}
|
|
488
576
|
case 'ZodIntersection':
|
|
489
577
|
return { type: 'intersection', isOptional: false, description };
|
|
490
578
|
case 'ZodLiteral':
|
|
491
|
-
return { type: JSON.stringify(field._def
|
|
579
|
+
return { type: JSON.stringify(field._def?.value), isOptional: false, description };
|
|
492
580
|
default:
|
|
493
581
|
return {
|
|
494
582
|
type: typeName.replace('Zod', '').toLowerCase() || 'any',
|
|
@@ -1058,6 +1146,16 @@ class Agent extends EventEmitter {
|
|
|
1058
1146
|
}
|
|
1059
1147
|
}
|
|
1060
1148
|
|
|
1149
|
+
/**
|
|
1150
|
+
* 继续对话(使用队列机制)
|
|
1151
|
+
* @param {string} prompt - 继续提示
|
|
1152
|
+
* @param {string} sessionId - 会话ID
|
|
1153
|
+
* @param {Object} options - 选项 { onChunk, onComplete, onError }
|
|
1154
|
+
*/
|
|
1155
|
+
continue(prompt, sessionId, options = {}) {
|
|
1156
|
+
return this._chatHandler.continue(prompt, sessionId, options);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1061
1159
|
/**
|
|
1062
1160
|
* 设置元数据
|
|
1063
1161
|
*/
|