@almadar/agent 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +72 -0
- package/dist/agent/index.d.ts +2 -2
- package/dist/agent/index.js +83 -278
- package/dist/agent/index.js.map +1 -1
- package/dist/{index-D-Ahuo6F.d.ts → index-DNe7JzkE.d.ts} +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +84 -281
- package/dist/index.js.map +1 -1
- package/dist/{orbital-subagent-cNfTLdXQ.d.ts → orbital-subagent-CiOIu9Ax.d.ts} +25 -25
- package/dist/tools/index.d.ts +28 -257
- package/dist/tools/index.js +84 -282
- package/dist/tools/index.js.map +1 -1
- package/package.json +15 -17
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LLMProvider } from '@almadar/llm';
|
|
2
|
-
import { S as SubagentEventCallback, O as OrbitalCompleteCallback,
|
|
2
|
+
import { S as SubagentEventCallback, O as OrbitalCompleteCallback, a as DomainOrbitalCompleteCallback } from './orbital-subagent-CiOIu9Ax.js';
|
|
3
3
|
import { BaseCheckpointSaver } from '@langchain/langgraph-checkpoint';
|
|
4
4
|
import { P as PersistenceMode, b as FirestoreDb$1, S as SessionMetadata, e as SessionRecord } from './firestore-checkpointer-CkNKXoun.js';
|
|
5
5
|
import { OrbitalSchema } from '@almadar/core';
|
package/dist/index.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ import { DomainContext, OrbitalSchema, Orbital, OrbitalDefinition, FullOrbitalUn
|
|
|
6
6
|
export { DomainDocument, DomainToSchemaResult, ParseError, SchemaToDomainResult, SectionMapping, applySectionUpdate, convertDomainToSchema, convertSchemaToDomain, deleteSection } from '@almadar/core/domain-language';
|
|
7
7
|
import { LLMClient } from '@almadar/llm';
|
|
8
8
|
export { createCompactSystemPrompt, createSystemPrompt } from './prompts/index.js';
|
|
9
|
-
import { U as UserPreference, M as MemoryManager, G as GenerationSession } from './index-
|
|
10
|
-
export { C as CheckpointRecord, a as ContextCompactionConfig, D as DEFAULT_COMPACTION_CONFIG, E as EVENT_BUDGETS, I as InterruptRecord, b as MemoryManagerOptions, c as MemoryOrbitalSchema, P as PatternAffinity, d as ProjectContext, S as SessionManager, e as SessionManagerOptions, f as Skill, g as SkillAgentOptions, h as SkillAgentResult, i as SkillLoader, j as SkillMeta, k as SkillRefLoader, T as ToolApprovalPreference, l as UserFeedback, m as createSkillAgent, n as createSummaryPrompt, o as estimateTokens, p as getBudgetWarningMessage, q as getEventBudget, r as getInterruptConfig, s as needsCompaction, t as resumeSkillAgent } from './index-
|
|
9
|
+
import { U as UserPreference, M as MemoryManager, G as GenerationSession } from './index-DNe7JzkE.js';
|
|
10
|
+
export { C as CheckpointRecord, a as ContextCompactionConfig, D as DEFAULT_COMPACTION_CONFIG, E as EVENT_BUDGETS, I as InterruptRecord, b as MemoryManagerOptions, c as MemoryOrbitalSchema, P as PatternAffinity, d as ProjectContext, S as SessionManager, e as SessionManagerOptions, f as Skill, g as SkillAgentOptions, h as SkillAgentResult, i as SkillLoader, j as SkillMeta, k as SkillRefLoader, T as ToolApprovalPreference, l as UserFeedback, m as createSkillAgent, n as createSummaryPrompt, o as estimateTokens, p as getBudgetWarningMessage, q as getEventBudget, r as getInterruptConfig, s as needsCompaction, t as resumeSkillAgent } from './index-DNe7JzkE.js';
|
|
11
11
|
import { S as SessionMetadata } from './firestore-checkpointer-CkNKXoun.js';
|
|
12
12
|
export { F as FirestoreCheckpointer, a as FirestoreCheckpointerOptions, b as FirestoreDb, c as FirestoreTimestamp, P as PersistenceMode, d as Session, e as SessionRecord } from './firestore-checkpointer-CkNKXoun.js';
|
|
13
13
|
export { FirestoreSessionStore, FirestoreSessionStoreOptions, FirestoreStore, FirestoreStoreOptions, MemorySessionBackend } from './persistence/index.js';
|
|
@@ -15,7 +15,7 @@ export { RawAgentEvent, extractFileOperation, extractInterruptData, hasInterrupt
|
|
|
15
15
|
import { EventEmitter } from 'events';
|
|
16
16
|
import { Checkpoint } from '@langchain/langgraph-checkpoint';
|
|
17
17
|
export { Command } from '@langchain/langgraph';
|
|
18
|
-
export {
|
|
18
|
+
export { a as DomainOrbitalCompleteCallback, D as DomainOrbitalEventCallback, b as DomainOrbitalSpec, c as DomainOrbitalToolOptions, O as OrbitalCompleteCallback, d as OrbitalRequirements, e as OrbitalSubagentToolOptions, S as SubagentEventCallback, f as createConstructCombinedDomainTool, g as createDomainOrbitalTools, h as createGenerateOrbitalDomainTool, i as createOrbitalSubagentTool, j as createSubagentEventWrapper } from './orbital-subagent-CiOIu9Ax.js';
|
|
19
19
|
import 'zod';
|
|
20
20
|
import '@langchain/core/tools';
|
|
21
21
|
import '@almadar/core';
|
package/dist/index.js
CHANGED
|
@@ -9,8 +9,7 @@ import { isStructuredOutputAvailable, getStructuredOutputClient, LLMClient, crea
|
|
|
9
9
|
import * as domain_language_star from '@almadar/core/domain-language';
|
|
10
10
|
import * as fs3 from 'fs';
|
|
11
11
|
import crypto, { randomUUID } from 'crypto';
|
|
12
|
-
import { getFullOrbitalPrompt, getRequirementsTraitPrompt, getKeyBehaviorsReference, getSExprQuickRef, getCommonErrorsSection, getArchitectureSection, getMinimalTypeReference
|
|
13
|
-
import { formatRecommendationsForPrompt, buildRecommendationContext, recommendPatterns } from '@almadar/patterns';
|
|
12
|
+
import { getFullOrbitalPrompt, getRequirementsTraitPrompt, getKeyBehaviorsReference, getSExprQuickRef, getCommonErrorsSection, getArchitectureSection, getMinimalTypeReference } from '@almadar/skills';
|
|
14
13
|
import { GitHubIntegration } from '@almadar/integrations';
|
|
15
14
|
import '@langchain/core/messages';
|
|
16
15
|
import { FilesystemBackend, createDeepAgent } from 'deepagents';
|
|
@@ -1341,6 +1340,77 @@ npx kflow domain:validate input.orb --verbose
|
|
|
1341
1340
|
|
|
1342
1341
|
// src/tools/finish-task.ts
|
|
1343
1342
|
var execAsync2 = promisify(exec);
|
|
1343
|
+
var PROP_CORRECTIONS = {
|
|
1344
|
+
onSubmit: "submitEvent",
|
|
1345
|
+
onCancel: "cancelEvent",
|
|
1346
|
+
headerActions: "actions",
|
|
1347
|
+
loading: "isLoading",
|
|
1348
|
+
fieldNames: "fields"
|
|
1349
|
+
};
|
|
1350
|
+
function autoCorrectProps(schema) {
|
|
1351
|
+
let corrections = 0;
|
|
1352
|
+
JSON.stringify(schema);
|
|
1353
|
+
function walkAndFix(obj) {
|
|
1354
|
+
if (Array.isArray(obj)) {
|
|
1355
|
+
return obj.map(walkAndFix);
|
|
1356
|
+
}
|
|
1357
|
+
if (obj && typeof obj === "object") {
|
|
1358
|
+
const result = {};
|
|
1359
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
1360
|
+
if (key in PROP_CORRECTIONS) {
|
|
1361
|
+
result[PROP_CORRECTIONS[key]] = walkAndFix(value);
|
|
1362
|
+
corrections++;
|
|
1363
|
+
} else {
|
|
1364
|
+
result[key] = walkAndFix(value);
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
return result;
|
|
1368
|
+
}
|
|
1369
|
+
return obj;
|
|
1370
|
+
}
|
|
1371
|
+
const fixed = walkAndFix(schema);
|
|
1372
|
+
Object.assign(schema, fixed);
|
|
1373
|
+
return corrections;
|
|
1374
|
+
}
|
|
1375
|
+
function checkCompositionQuality(schema) {
|
|
1376
|
+
const warnings = [];
|
|
1377
|
+
const orbitals = schema.orbitals;
|
|
1378
|
+
if (!Array.isArray(orbitals)) return warnings;
|
|
1379
|
+
for (const orbital of orbitals) {
|
|
1380
|
+
const orbObj = orbital;
|
|
1381
|
+
const traits = orbObj.traits;
|
|
1382
|
+
if (!Array.isArray(traits)) continue;
|
|
1383
|
+
for (const trait of traits) {
|
|
1384
|
+
const traitObj = trait;
|
|
1385
|
+
const transitions = traitObj.stateMachine?.transitions;
|
|
1386
|
+
if (!Array.isArray(transitions)) continue;
|
|
1387
|
+
for (const transition of transitions) {
|
|
1388
|
+
const trans = transition;
|
|
1389
|
+
if (trans.event !== "INIT") continue;
|
|
1390
|
+
const effects = trans.effects;
|
|
1391
|
+
if (!Array.isArray(effects)) continue;
|
|
1392
|
+
const mainRenderUIs = effects.filter(
|
|
1393
|
+
(e) => Array.isArray(e) && e[0] === "render-ui" && e[1] === "main"
|
|
1394
|
+
);
|
|
1395
|
+
if (mainRenderUIs.length > 1) {
|
|
1396
|
+
warnings.push(
|
|
1397
|
+
`\u26A0\uFE0F ${orbObj.name}/${traitObj.name} INIT has ${mainRenderUIs.length} flat render-ui calls to main. Should be a single composed stack with children.`
|
|
1398
|
+
);
|
|
1399
|
+
}
|
|
1400
|
+
if (mainRenderUIs.length === 1) {
|
|
1401
|
+
const renderPayload = mainRenderUIs[0];
|
|
1402
|
+
const payload = renderPayload[2];
|
|
1403
|
+
if (payload && payload.type !== "stack" && !payload.children) {
|
|
1404
|
+
warnings.push(
|
|
1405
|
+
`\u26A0\uFE0F ${orbObj.name}/${traitObj.name} INIT renders a single flat ${payload.type} to main. Should be a composed stack with header, metrics, and data sections.`
|
|
1406
|
+
);
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
return warnings;
|
|
1413
|
+
}
|
|
1344
1414
|
async function collectOrbitalsFromDir(workDir) {
|
|
1345
1415
|
const orbitalsDir = path.join(workDir, ".orbitals");
|
|
1346
1416
|
try {
|
|
@@ -1395,6 +1465,8 @@ function createFinishTaskTool(workDir) {
|
|
|
1395
1465
|
let stats = null;
|
|
1396
1466
|
let validationResult = null;
|
|
1397
1467
|
let source = null;
|
|
1468
|
+
let propCorrections = 0;
|
|
1469
|
+
let compositionWarnings = [];
|
|
1398
1470
|
if (workDir) {
|
|
1399
1471
|
const orbitals = await collectOrbitalsFromDir(workDir);
|
|
1400
1472
|
if (orbitals.length > 0) {
|
|
@@ -1439,6 +1511,10 @@ function createFinishTaskTool(workDir) {
|
|
|
1439
1511
|
} catch {
|
|
1440
1512
|
}
|
|
1441
1513
|
}
|
|
1514
|
+
if (combinedSchema) {
|
|
1515
|
+
propCorrections = autoCorrectProps(combinedSchema);
|
|
1516
|
+
compositionWarnings = checkCompositionQuality(combinedSchema);
|
|
1517
|
+
}
|
|
1442
1518
|
if (combinedSchema) {
|
|
1443
1519
|
const schemaPath = path.join(workDir, "schema.json");
|
|
1444
1520
|
await fs4.writeFile(schemaPath, JSON.stringify(combinedSchema, null, 2));
|
|
@@ -1458,6 +1534,10 @@ function createFinishTaskTool(workDir) {
|
|
|
1458
1534
|
errorCount: validationResult.errors?.length || 0,
|
|
1459
1535
|
warningCount: validationResult.warnings?.length || 0
|
|
1460
1536
|
} : void 0,
|
|
1537
|
+
designQuality: {
|
|
1538
|
+
propCorrections: propCorrections || 0,
|
|
1539
|
+
compositionWarnings: compositionWarnings || []
|
|
1540
|
+
},
|
|
1461
1541
|
schemaPath: combinedSchema ? path.join(workDir, "schema.json") : input.schemaPath,
|
|
1462
1542
|
nextAction: "NONE - Task is complete. Output a brief success message to the user."
|
|
1463
1543
|
};
|
|
@@ -3016,273 +3096,6 @@ function createSchemaChunkingTools(workDir) {
|
|
|
3016
3096
|
applyChunk: createApplyChunkTool(workDir)
|
|
3017
3097
|
};
|
|
3018
3098
|
}
|
|
3019
|
-
var designCache = /* @__PURE__ */ new Map();
|
|
3020
|
-
var CACHE_TTL_MS2 = 24 * 60 * 60 * 1e3;
|
|
3021
|
-
var CACHE_VERSION2 = 1;
|
|
3022
|
-
function generateFingerprint2(input) {
|
|
3023
|
-
const normalized = JSON.stringify({
|
|
3024
|
-
version: CACHE_VERSION2,
|
|
3025
|
-
...input
|
|
3026
|
-
});
|
|
3027
|
-
return crypto.createHash("sha256").update(normalized).digest("hex").slice(0, 16);
|
|
3028
|
-
}
|
|
3029
|
-
function getCached2(fingerprint) {
|
|
3030
|
-
const entry = designCache.get(fingerprint);
|
|
3031
|
-
if (!entry) return null;
|
|
3032
|
-
if (Date.now() - entry.timestamp > CACHE_TTL_MS2) {
|
|
3033
|
-
designCache.delete(fingerprint);
|
|
3034
|
-
return null;
|
|
3035
|
-
}
|
|
3036
|
-
return entry;
|
|
3037
|
-
}
|
|
3038
|
-
var STATIC_DESIGN_PROMPT = null;
|
|
3039
|
-
function getDesignSystemPrompt() {
|
|
3040
|
-
if (!STATIC_DESIGN_PROMPT) {
|
|
3041
|
-
const skill = generateKflowDesignSkill();
|
|
3042
|
-
STATIC_DESIGN_PROMPT = skill.content;
|
|
3043
|
-
}
|
|
3044
|
-
return STATIC_DESIGN_PROMPT;
|
|
3045
|
-
}
|
|
3046
|
-
function getPatternRecommendations(input) {
|
|
3047
|
-
const recContext = buildRecommendationContext({
|
|
3048
|
-
state: input.from,
|
|
3049
|
-
event: input.event,
|
|
3050
|
-
slot: input.slot,
|
|
3051
|
-
domainCategory: input.domainCategory,
|
|
3052
|
-
entityFields: input.entityFields
|
|
3053
|
-
});
|
|
3054
|
-
return recommendPatterns(recContext, 8);
|
|
3055
|
-
}
|
|
3056
|
-
function buildDesignUserPrompt(input) {
|
|
3057
|
-
const fieldList = input.entityFields.map((f) => {
|
|
3058
|
-
let desc = ` - ${f.name}: ${f.type}`;
|
|
3059
|
-
if (f.values) desc += ` (values: ${f.values.join(", ")})`;
|
|
3060
|
-
return desc;
|
|
3061
|
-
}).join("\n");
|
|
3062
|
-
const hints = [];
|
|
3063
|
-
if (input.designStyle) hints.push(`Style: ${input.designStyle}`);
|
|
3064
|
-
if (input.flowPattern) hints.push(`Flow: ${input.flowPattern}`);
|
|
3065
|
-
if (input.listPattern) hints.push(`List: ${input.listPattern}`);
|
|
3066
|
-
if (input.formPattern) hints.push(`Form: ${input.formPattern}`);
|
|
3067
|
-
if (input.detailPattern) hints.push(`Detail: ${input.detailPattern}`);
|
|
3068
|
-
const vocab = input.vocabulary ? Object.entries(input.vocabulary).map(([k, v]) => ` ${k} \u2192 "${v}"`).join("\n") : "";
|
|
3069
|
-
return `Design render-ui effects for this transition:
|
|
3070
|
-
|
|
3071
|
-
## Transition
|
|
3072
|
-
- **From**: ${input.from}
|
|
3073
|
-
- **To**: ${input.to}
|
|
3074
|
-
- **Event**: ${input.event}
|
|
3075
|
-
- **Slot**: ${input.slot}
|
|
3076
|
-
|
|
3077
|
-
## Entity: ${input.entityName}
|
|
3078
|
-
${fieldList}
|
|
3079
|
-
|
|
3080
|
-
## Domain
|
|
3081
|
-
- **Category**: ${input.domainCategory || "business"}
|
|
3082
|
-
${vocab ? `- **Vocabulary**:
|
|
3083
|
-
${vocab}` : ""}
|
|
3084
|
-
${hints.length > 0 ? `- **Design Hints**: ${hints.join(", ")}` : ""}
|
|
3085
|
-
|
|
3086
|
-
${input.recommendationsSection || ""}
|
|
3087
|
-
|
|
3088
|
-
${input.existingEffects ? `## Existing Effects (enhance these)
|
|
3089
|
-
\`\`\`json
|
|
3090
|
-
${JSON.stringify(input.existingEffects, null, 2)}
|
|
3091
|
-
\`\`\`` : ""}
|
|
3092
|
-
|
|
3093
|
-
Return ONLY the JSON array of render-ui effect tuples.`;
|
|
3094
|
-
}
|
|
3095
|
-
var DesignTransitionSchema = z.object({
|
|
3096
|
-
from: z.string().describe('Source state name (e.g., "Browsing")'),
|
|
3097
|
-
to: z.string().describe('Target state name (e.g., "Browsing" for self-loop, "Creating" for transition)'),
|
|
3098
|
-
event: z.string().describe('Event name (e.g., "INIT", "CREATE", "VIEW", "EDIT", "DELETE", "SAVE", "CANCEL")'),
|
|
3099
|
-
slot: z.string().describe('UI slot to render into: "main", "modal", "drawer", "sidebar", "overlay"'),
|
|
3100
|
-
entityName: z.string().describe('Entity name (e.g., "Task", "Order")'),
|
|
3101
|
-
entityFields: z.array(z.object({
|
|
3102
|
-
name: z.string(),
|
|
3103
|
-
type: z.string(),
|
|
3104
|
-
values: z.array(z.string()).optional()
|
|
3105
|
-
})).describe("Entity fields with types and optional enum values"),
|
|
3106
|
-
domainCategory: AgentDomainCategorySchema.optional().describe("Domain category for pattern selection"),
|
|
3107
|
-
vocabulary: z.record(z.string(), z.string()).optional().describe('Domain vocabulary mapping (e.g., { "create": "Place Order", "item": "Order" })'),
|
|
3108
|
-
designStyle: z.enum(["minimal", "modern", "playful", "data-driven", "immersive"]).optional().describe("Visual style hint"),
|
|
3109
|
-
flowPattern: z.enum(["hub-spoke", "master-detail", "crud-cycle", "linear", "role-based"]).optional().describe("Application flow pattern"),
|
|
3110
|
-
listPattern: z.enum(["entity-table", "entity-cards", "entity-list"]).optional().describe("Preferred list pattern"),
|
|
3111
|
-
formPattern: z.enum(["modal", "drawer", "page"]).optional().describe("Preferred form pattern"),
|
|
3112
|
-
detailPattern: z.enum(["drawer", "page", "split"]).optional().describe("Preferred detail view pattern"),
|
|
3113
|
-
existingEffects: z.array(z.any()).optional().describe("Existing render-ui effects to enhance (for refinement passes)")
|
|
3114
|
-
});
|
|
3115
|
-
function createDesignTransitionTool(options = {}) {
|
|
3116
|
-
let eventCallback = options.onEvent;
|
|
3117
|
-
const setEventCallback = (callback) => {
|
|
3118
|
-
eventCallback = callback;
|
|
3119
|
-
};
|
|
3120
|
-
const emitEvent = (transitionId, type, data) => {
|
|
3121
|
-
if (eventCallback) {
|
|
3122
|
-
eventCallback(transitionId, {
|
|
3123
|
-
type,
|
|
3124
|
-
data,
|
|
3125
|
-
timestamp: Date.now()
|
|
3126
|
-
});
|
|
3127
|
-
}
|
|
3128
|
-
};
|
|
3129
|
-
const designTransitionTool = tool(
|
|
3130
|
-
async (input) => {
|
|
3131
|
-
const transitionId = `${input.entityName}:${input.from}->${input.to}:${input.event}`;
|
|
3132
|
-
const fingerprint = generateFingerprint2({
|
|
3133
|
-
from: input.from,
|
|
3134
|
-
to: input.to,
|
|
3135
|
-
event: input.event,
|
|
3136
|
-
slot: input.slot,
|
|
3137
|
-
entityName: input.entityName,
|
|
3138
|
-
entityFields: input.entityFields,
|
|
3139
|
-
domainCategory: input.domainCategory,
|
|
3140
|
-
designStyle: input.designStyle,
|
|
3141
|
-
flowPattern: input.flowPattern,
|
|
3142
|
-
listPattern: input.listPattern
|
|
3143
|
-
});
|
|
3144
|
-
try {
|
|
3145
|
-
emitEvent(transitionId, "message", {
|
|
3146
|
-
content: `Designing UI for ${transitionId}`,
|
|
3147
|
-
role: "assistant",
|
|
3148
|
-
isComplete: false
|
|
3149
|
-
});
|
|
3150
|
-
const cached = getCached2(fingerprint);
|
|
3151
|
-
if (cached) {
|
|
3152
|
-
emitEvent(transitionId, "generation_log", {
|
|
3153
|
-
level: "info",
|
|
3154
|
-
message: `Design cache HIT for ${transitionId}`,
|
|
3155
|
-
data: { fingerprint }
|
|
3156
|
-
});
|
|
3157
|
-
return JSON.stringify({
|
|
3158
|
-
success: true,
|
|
3159
|
-
transitionId,
|
|
3160
|
-
effects: cached.effects,
|
|
3161
|
-
cached: true,
|
|
3162
|
-
usage: cached.usage
|
|
3163
|
-
});
|
|
3164
|
-
}
|
|
3165
|
-
const recommendations = getPatternRecommendations(input);
|
|
3166
|
-
const recommendationsSection = formatRecommendationsForPrompt(recommendations);
|
|
3167
|
-
const systemPrompt = getDesignSystemPrompt();
|
|
3168
|
-
const userPrompt = buildDesignUserPrompt({
|
|
3169
|
-
...input,
|
|
3170
|
-
recommendationsSection
|
|
3171
|
-
});
|
|
3172
|
-
emitEvent(transitionId, "tool_call", {
|
|
3173
|
-
tool: "llm_design_transition",
|
|
3174
|
-
args: {
|
|
3175
|
-
transition: transitionId,
|
|
3176
|
-
slot: input.slot,
|
|
3177
|
-
domain: input.domainCategory
|
|
3178
|
-
}
|
|
3179
|
-
});
|
|
3180
|
-
const client = new LLMClient({
|
|
3181
|
-
provider: "anthropic",
|
|
3182
|
-
model: "claude-sonnet-4-20250514",
|
|
3183
|
-
temperature: 0.1
|
|
3184
|
-
// Slight creativity for design
|
|
3185
|
-
});
|
|
3186
|
-
const response = await client.callWithCache({
|
|
3187
|
-
systemPrompt: "",
|
|
3188
|
-
systemBlocks: [{
|
|
3189
|
-
type: "text",
|
|
3190
|
-
text: systemPrompt,
|
|
3191
|
-
cache_control: { type: "ephemeral" }
|
|
3192
|
-
}],
|
|
3193
|
-
userPrompt,
|
|
3194
|
-
maxTokens: 4096,
|
|
3195
|
-
rawText: true
|
|
3196
|
-
});
|
|
3197
|
-
const rawText = (response.raw || String(response.data) || "").trim();
|
|
3198
|
-
let effects;
|
|
3199
|
-
try {
|
|
3200
|
-
const jsonText = rawText.replace(/^```(?:json)?\n?/m, "").replace(/\n?```$/m, "").trim();
|
|
3201
|
-
effects = JSON.parse(jsonText);
|
|
3202
|
-
if (!Array.isArray(effects)) {
|
|
3203
|
-
effects = [effects];
|
|
3204
|
-
}
|
|
3205
|
-
} catch {
|
|
3206
|
-
return JSON.stringify({
|
|
3207
|
-
success: false,
|
|
3208
|
-
transitionId,
|
|
3209
|
-
error: "Failed to parse design output as JSON",
|
|
3210
|
-
rawOutput: rawText
|
|
3211
|
-
});
|
|
3212
|
-
}
|
|
3213
|
-
const usage = {
|
|
3214
|
-
inputTokens: response.usage?.promptTokens || 0,
|
|
3215
|
-
outputTokens: response.usage?.completionTokens || 0,
|
|
3216
|
-
totalTokens: response.usage?.totalTokens || 0
|
|
3217
|
-
};
|
|
3218
|
-
designCache.set(fingerprint, {
|
|
3219
|
-
effects,
|
|
3220
|
-
timestamp: Date.now(),
|
|
3221
|
-
usage
|
|
3222
|
-
});
|
|
3223
|
-
emitEvent(transitionId, "tool_result", {
|
|
3224
|
-
tool: "llm_design_transition",
|
|
3225
|
-
result: { fingerprint, effectCount: effects.length, usage },
|
|
3226
|
-
success: true
|
|
3227
|
-
});
|
|
3228
|
-
emitEvent(transitionId, "message", {
|
|
3229
|
-
content: `Designed ${effects.length} effect(s) for ${transitionId} (${usage.totalTokens} tokens)`,
|
|
3230
|
-
role: "assistant",
|
|
3231
|
-
isComplete: true
|
|
3232
|
-
});
|
|
3233
|
-
return JSON.stringify({
|
|
3234
|
-
success: true,
|
|
3235
|
-
transitionId,
|
|
3236
|
-
effects,
|
|
3237
|
-
cached: false,
|
|
3238
|
-
usage,
|
|
3239
|
-
recommendedPatterns: recommendations.map((r) => r.pattern)
|
|
3240
|
-
});
|
|
3241
|
-
} catch (error) {
|
|
3242
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3243
|
-
emitEvent(transitionId, "error", {
|
|
3244
|
-
error: errorMessage,
|
|
3245
|
-
code: "DESIGN_TRANSITION_ERROR"
|
|
3246
|
-
});
|
|
3247
|
-
return JSON.stringify({
|
|
3248
|
-
success: false,
|
|
3249
|
-
transitionId,
|
|
3250
|
-
error: errorMessage
|
|
3251
|
-
});
|
|
3252
|
-
}
|
|
3253
|
-
},
|
|
3254
|
-
{
|
|
3255
|
-
name: "design_transition",
|
|
3256
|
-
description: `Design rich render-ui effects for a single orbital transition.
|
|
3257
|
-
|
|
3258
|
-
Takes the transition context (from/to state, event, entity, domain) and produces
|
|
3259
|
-
polished render-ui effects using the full pattern catalog.
|
|
3260
|
-
|
|
3261
|
-
USE THIS TOOL WHEN:
|
|
3262
|
-
- Generating INIT transitions (always compose header + stats + content)
|
|
3263
|
-
- Generating CREATE/EDIT transitions (form with proper fields)
|
|
3264
|
-
- Generating VIEW transitions (detail with tabs for related entities)
|
|
3265
|
-
- Enhancing existing render-ui effects that are too basic
|
|
3266
|
-
|
|
3267
|
-
The tool uses a specialized design skill with pattern catalog, layout composition,
|
|
3268
|
-
and domain-aware pattern selection to produce rich UI.
|
|
3269
|
-
|
|
3270
|
-
RETURNS: { success, effects: [["render-ui", slot, config], ...], transitionId, usage }
|
|
3271
|
-
|
|
3272
|
-
The effects array contains ONLY render-ui tuples. Non-UI effects (persist, emit, set)
|
|
3273
|
-
are NOT included \u2014 you must preserve those from the original transition.
|
|
3274
|
-
|
|
3275
|
-
INTEGRATION: After calling this tool, use extract_chunk to get the orbital,
|
|
3276
|
-
replace the render-ui effects in the target transition (keep persist/emit/set effects),
|
|
3277
|
-
then apply_chunk to merge back into schema.json.`,
|
|
3278
|
-
schema: DesignTransitionSchema
|
|
3279
|
-
}
|
|
3280
|
-
);
|
|
3281
|
-
return {
|
|
3282
|
-
tool: designTransitionTool,
|
|
3283
|
-
setEventCallback
|
|
3284
|
-
};
|
|
3285
|
-
}
|
|
3286
3099
|
function createGitHubTools(config) {
|
|
3287
3100
|
const { token, owner = "", repo = "", workDir } = config;
|
|
3288
3101
|
const integrationConfig = {
|
|
@@ -3652,9 +3465,7 @@ function createAgentTools(workDir) {
|
|
|
3652
3465
|
// Domain tools (now use internal functions)
|
|
3653
3466
|
domainOrbitalTools: createDomainOrbitalTools({ workDir }),
|
|
3654
3467
|
// Chunking tools
|
|
3655
|
-
schemaChunking: createSchemaChunkingTools(workDir)
|
|
3656
|
-
// Design tool
|
|
3657
|
-
designTransition: createDesignTransitionTool()
|
|
3468
|
+
schemaChunking: createSchemaChunkingTools(workDir)
|
|
3658
3469
|
};
|
|
3659
3470
|
}
|
|
3660
3471
|
function getSchemaReference() {
|
|
@@ -4988,11 +4799,9 @@ ${skillContents}`;
|
|
|
4988
4799
|
const validateSchemaTool = createValidateSchemaTool(workDir);
|
|
4989
4800
|
const ORBITAL_SKILLS = ["kflow-orbitals", "kflow-orbital-games", "kflow-orbital-fixing"];
|
|
4990
4801
|
const LEAN_SKILLS = ["kflow-lean-orbitals", "kflow-lean-fixing"];
|
|
4991
|
-
const DESIGN_SKILLS = ["kflow-design", "kflow-lean-design"];
|
|
4992
4802
|
const isOrbitalSkill = primarySkill.name === "kflow-orbitals";
|
|
4993
4803
|
const isLeanSkill = LEAN_SKILLS.includes(primarySkill.name);
|
|
4994
|
-
const
|
|
4995
|
-
const needsChunkingTools = ORBITAL_SKILLS.includes(primarySkill.name) || isDesignSkill;
|
|
4804
|
+
const needsChunkingTools = ORBITAL_SKILLS.includes(primarySkill.name);
|
|
4996
4805
|
let orbitalTool;
|
|
4997
4806
|
let setOrbitalEventCallback;
|
|
4998
4807
|
let setOrbitalCompleteCallback;
|
|
@@ -5018,11 +4827,6 @@ ${skillContents}`;
|
|
|
5018
4827
|
console.log(`[SkillAgent] Domain orbital tools enabled for ${primarySkill.name} skill`);
|
|
5019
4828
|
}
|
|
5020
4829
|
}
|
|
5021
|
-
const needsDesignTool = isDesignSkill || ORBITAL_SKILLS.includes(primarySkill.name);
|
|
5022
|
-
const designTool = needsDesignTool ? createDesignTransitionTool() : null;
|
|
5023
|
-
if (designTool && verbose) {
|
|
5024
|
-
console.log(`[SkillAgent] Design transition tool enabled for ${primarySkill.name} skill`);
|
|
5025
|
-
}
|
|
5026
4830
|
const githubTools = options.githubConfig ? createGitHubToolsArray({
|
|
5027
4831
|
token: options.githubConfig.token,
|
|
5028
4832
|
owner: options.githubConfig.owner,
|
|
@@ -5046,7 +4850,6 @@ ${skillContents}`;
|
|
|
5046
4850
|
chunkingTools.extractChunk,
|
|
5047
4851
|
chunkingTools.applyChunk
|
|
5048
4852
|
] : [],
|
|
5049
|
-
...designTool ? [designTool.tool] : [],
|
|
5050
4853
|
...githubTools || []
|
|
5051
4854
|
];
|
|
5052
4855
|
const checkpointer = sessions.getCheckpointer(threadId);
|