Skip to content

Commit 2aea3c7

Browse files
committed
feat: add ai-based project type detection and workflow support
- Implemented AI-powered project type prediction (app/workflow/presentation) with confidence scoring and auto-detection when projectType is 'auto' - Enhanced template selection to filter by project type and skip AI selection for single-template scenarios in workflow/presentation types - Added GitHub token caching in CodeGeneratorAgent for persistent OAuth sessions across exports - Updated commitlint config to allow longer commit messages (
1 parent 5685c7d commit 2aea3c7

File tree

12 files changed

+230
-64
lines changed

12 files changed

+230
-64
lines changed

commitlint.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ export default {
2222
'type-empty': [2, 'never'],
2323
'subject-empty': [2, 'never'],
2424
'subject-full-stop': [2, 'never', '.'],
25-
'header-max-length': [2, 'always', 100],
25+
'header-max-length': [2, 'always', 150],
2626
'body-leading-blank': [1, 'always'],
27-
'body-max-line-length': [2, 'always', 100],
27+
'body-max-line-length': [2, 'always', 200],
2828
'footer-leading-blank': [1, 'always'],
29-
'footer-max-line-length': [2, 'always', 100],
29+
'footer-max-line-length': [2, 'always', 200],
3030
},
3131
};

worker/agents/core/behaviors/agentic.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,10 @@ export class AgenticCodingBehavior extends BaseCodingBehavior<AgenticState> impl
184184
);
185185

186186
// Create build session for tools
187-
// Note: AgenticCodingBehavior is currently used for 'app' type projects
188187
const session: BuildSession = {
189188
agent: this,
190189
filesIndex: Object.values(this.state.generatedFilesMap),
191-
projectType: 'app'
190+
projectType: this.state.projectType || 'app'
192191
};
193192

194193
// Create tool renderer for UI feedback

worker/agents/core/behaviors/base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from '../../schemas';
77
import { ExecuteCommandsResponse, PreviewType, RuntimeError, StaticAnalysisResponse, TemplateDetails } from '../../../services/sandbox/sandboxTypes';
88
import { AgentState, BaseProjectState } from '../state';
9-
import { AllIssues, AgentSummary, AgentInitArgs, BehaviorType, DeploymentTarget } from '../types';
9+
import { AllIssues, AgentSummary, AgentInitArgs, BehaviorType, DeploymentTarget, ProjectType } from '../types';
1010
import { ModelConfig } from '../../inferutils/config.types';
1111
import { PREVIEW_EXPIRED_ERROR, WebSocketMessageResponses } from '../../constants';
1212
import { ProjectSetupAssistant } from '../../assistants/projectsetup';
@@ -73,7 +73,7 @@ export abstract class BaseCodingBehavior<TState extends BaseProjectState>
7373
return this.state.behaviorType;
7474
}
7575

76-
constructor(infrastructure: AgentInfrastructure<TState>) {
76+
constructor(infrastructure: AgentInfrastructure<TState>, protected projectType: ProjectType) {
7777
super(infrastructure);
7878
}
7979

worker/agents/core/behaviors/phasic.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export class PhasicCodingBehavior extends BaseCodingBehavior<PhasicState> implem
7171
): Promise<PhasicState> {
7272
await super.initialize(initArgs);
7373
const { query, language, frameworks, hostname, inferenceContext, templateInfo, sandboxSessionId } = initArgs;
74-
const projectType = initArgs.projectType || this.state.projectType || 'app';
7574

7675
// Generate a blueprint
7776
this.logger.info('Generating blueprint', { query, queryLength: query.length, imagesCount: initArgs.images?.length || 0 });
@@ -86,7 +85,7 @@ export class PhasicCodingBehavior extends BaseCodingBehavior<PhasicState> implem
8685
templateDetails: templateInfo?.templateDetails,
8786
templateMetaInfo: templateInfo?.selection,
8887
images: initArgs.images,
89-
projectType,
88+
projectType: this.projectType,
9089
stream: {
9190
chunk_size: 256,
9291
onChunk: (chunk) => {
@@ -118,7 +117,7 @@ export class PhasicCodingBehavior extends BaseCodingBehavior<PhasicState> implem
118117
sessionId: sandboxSessionId!,
119118
hostname,
120119
inferenceContext,
121-
projectType,
120+
projectType: this.projectType,
122121
};
123122
this.setState(nextState);
124123
// Customize template files (package.json, wrangler.jsonc, .bootstrap.js, .gitignore)

worker/agents/core/codingAgent.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ export class CodeGeneratorAgent extends Agent<Env, AgentState> implements AgentI
122122
}
123123

124124
if (behaviorType === 'phasic') {
125-
this.behavior = new PhasicCodingBehavior(this as AgentInfrastructure<PhasicState>);
125+
this.behavior = new PhasicCodingBehavior(this as AgentInfrastructure<PhasicState>, projectType);
126126
} else {
127-
this.behavior = new AgenticCodingBehavior(this as AgentInfrastructure<AgenticState>);
127+
this.behavior = new AgenticCodingBehavior(this as AgentInfrastructure<AgenticState>, projectType);
128128
}
129129

130130
// Create objective based on project type
@@ -563,4 +563,26 @@ export class CodeGeneratorAgent extends Agent<Env, AgentState> implements AgentI
563563
throw error;
564564
}
565565
}
566+
567+
/**
568+
* Cache GitHub OAuth token in memory for subsequent exports
569+
* Token is ephemeral - lost on DO eviction
570+
*/
571+
setGitHubToken(token: string, username: string, ttl: number = 3600000): void {
572+
this.objective.setGitHubToken(token, username, ttl);
573+
}
574+
575+
/**
576+
* Get cached GitHub token if available and not expired
577+
*/
578+
getGitHubToken(): { token: string; username: string } | null {
579+
return this.objective.getGitHubToken();
580+
}
581+
582+
/**
583+
* Clear cached GitHub token
584+
*/
585+
clearGitHubToken(): void {
586+
this.objective.clearGitHubToken();
587+
}
566588
}

worker/agents/core/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ interface BaseAgentInitArgs {
3030
images?: ProcessedImageAttachment[];
3131
onBlueprintChunk: (chunk: string) => void;
3232
sandboxSessionId?: string; // Generated by CodeGeneratorAgent, passed to behavior
33-
behaviorType?: BehaviorType;
34-
projectType?: ProjectType;
3533
}
3634

3735
/** Phasic agent initialization arguments */

worker/agents/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ export async function getTemplateForQuery(
7474
env: Env,
7575
inferenceContext: InferenceContext,
7676
query: string,
77+
projectType: ProjectType | 'auto',
7778
images: ImageAttachment[] | undefined,
7879
logger: StructuredLogger,
79-
) : Promise<{templateDetails: TemplateDetails, selection: TemplateSelection}> {
80+
) : Promise<{templateDetails: TemplateDetails, selection: TemplateSelection, projectType: ProjectType}> {
8081
// Fetch available templates
8182
const templatesResponse = await SandboxSdkClient.listTemplates();
8283
if (!templatesResponse || !templatesResponse.success) {
@@ -87,6 +88,7 @@ export async function getTemplateForQuery(
8788
env,
8889
inferenceContext,
8990
query,
91+
projectType,
9092
availableTemplates: templatesResponse.templates,
9193
images,
9294
});
@@ -110,5 +112,5 @@ export async function getTemplateForQuery(
110112
}
111113

112114
const templateDetails = templateDetailsResponse.templateDetails;
113-
return { templateDetails, selection: analyzeQueryResponse };
115+
return { templateDetails, selection: analyzeQueryResponse, projectType: analyzeQueryResponse.projectType };
114116
}

0 commit comments

Comments
 (0)