Skip to content

Commit bf09b4c

Browse files
Copilothuangyiirene
andcommitted
fix: Make schema fields with defaults optional and fix AI example TypeScript errors
Co-authored-by: huangyiirene <7665279+huangyiirene@users.noreply.github.com>
1 parent cdf4bdc commit bf09b4c

78 files changed

Lines changed: 20814 additions & 19 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Agent, NLQModelConfig, QueryTemplate } from '@objectstack/spec';
2+
/**
3+
* AI Data Analyst Agent
4+
*/
5+
export declare const DataAnalystAgent: Agent;
6+
/**
7+
* NLQ Configuration for Business Intelligence
8+
*/
9+
export declare const AnalystNLQConfig: NLQModelConfig;
10+
/**
11+
* Common Query Templates
12+
*/
13+
export declare const AnalystQueryTemplates: QueryTemplate[];
14+
//# sourceMappingURL=ai-config.d.ts.map

examples/ai-analyst/src/ai-config.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.AnalystQueryTemplates = exports.AnalystNLQConfig = exports.DataAnalystAgent = void 0;
4+
/**
5+
* AI Data Analyst Agent
6+
*/
7+
exports.DataAnalystAgent = {
8+
name: 'data_analyst_ai',
9+
label: 'AI Data Analyst',
10+
role: 'Business Intelligence Analyst',
11+
instructions: `You are a data analyst helping users understand their business metrics.
12+
13+
Skills:
14+
- Interpret natural language questions about data
15+
- Generate ObjectQL queries
16+
- Create visualizations
17+
- Provide actionable insights
18+
19+
Be precise, data-driven, and clear in explanations.`,
20+
model: {
21+
provider: 'openai',
22+
model: 'gpt-4',
23+
temperature: 0.3,
24+
maxTokens: 4096,
25+
},
26+
tools: [
27+
{
28+
type: 'query',
29+
name: 'execute_objectql',
30+
description: 'Execute ObjectQL queries on data',
31+
},
32+
{
33+
type: 'action',
34+
name: 'create_dashboard',
35+
description: 'Generate dashboard from metrics',
36+
},
37+
{
38+
type: 'action',
39+
name: 'generate_chart',
40+
description: 'Create charts and visualizations',
41+
},
42+
{
43+
type: 'query',
44+
name: 'get_schema',
45+
description: 'Get object schema information',
46+
},
47+
],
48+
access: ['analysts', 'executives', 'managers'],
49+
active: true,
50+
};
51+
/**
52+
* NLQ Configuration for Business Intelligence
53+
*/
54+
exports.AnalystNLQConfig = {
55+
modelId: 'gpt-4',
56+
systemPrompt: `You are an expert at converting business questions into ObjectQL queries.
57+
58+
Available objects: account, opportunity, task, product, order
59+
Be precise with field names and support timeframes like "last quarter", "this year".`,
60+
includeSchema: true,
61+
includeExamples: true,
62+
enableIntentDetection: true,
63+
intentThreshold: 0.75,
64+
enableEntityRecognition: true,
65+
enableFuzzyMatching: true,
66+
fuzzyMatchThreshold: 0.85,
67+
enableTimeframeDetection: true,
68+
defaultTimeframe: 'current_month',
69+
enableCaching: true,
70+
cacheTTL: 3600,
71+
};
72+
/**
73+
* Common Query Templates
74+
*/
75+
exports.AnalystQueryTemplates = [
76+
{
77+
id: 'top-n-by-field',
78+
name: 'top_n_by_field',
79+
label: 'Top N Records by Field',
80+
pattern: 'top {n} {object} by {field}',
81+
variables: [
82+
{ name: 'n', type: 'value', required: true },
83+
{ name: 'object', type: 'object', required: true },
84+
{ name: 'field', type: 'field', required: true },
85+
],
86+
astTemplate: {
87+
object: '{object}',
88+
sort: [{ field: '{field}', order: 'desc' }],
89+
limit: '{n}',
90+
},
91+
category: 'ranking',
92+
examples: [
93+
'top 10 accounts by revenue',
94+
'top 5 products by sales',
95+
],
96+
},
97+
{
98+
id: 'aggregate-by-group',
99+
name: 'aggregate_by_group',
100+
label: 'Aggregate by Group',
101+
pattern: 'total {field} by {group_field}',
102+
variables: [
103+
{ name: 'field', type: 'field', required: true },
104+
{ name: 'group_field', type: 'field', required: true },
105+
],
106+
astTemplate: {
107+
fields: [
108+
'{group_field}',
109+
{ function: 'sum', field: '{field}', alias: 'total' },
110+
],
111+
groupBy: ['{group_field}'],
112+
},
113+
category: 'aggregation',
114+
examples: [
115+
'total revenue by region',
116+
'total orders by product',
117+
],
118+
},
119+
{
120+
id: 'time-comparison',
121+
name: 'time_comparison',
122+
label: 'Time Period Comparison',
123+
pattern: 'compare {metric} for {period1} vs {period2}',
124+
variables: [
125+
{ name: 'metric', type: 'field', required: true },
126+
{ name: 'period1', type: 'timeframe', required: true },
127+
{ name: 'period2', type: 'timeframe', required: true },
128+
],
129+
astTemplate: {
130+
// Complex comparison logic
131+
},
132+
category: 'comparison',
133+
examples: [
134+
'compare revenue for this month vs last month',
135+
'compare sales for Q1 vs Q2',
136+
],
137+
},
138+
];

examples/ai-analyst/tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "dist",
5+
"rootDir": "src"
6+
},
7+
"include": ["src/**/*"],
8+
"exclude": ["node_modules", "dist"]
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Agent, ModelRegistry, RAGPipelineConfig } from '@objectstack/spec';
2+
/**
3+
* ObjectStack Code Generator Agent
4+
*/
5+
export declare const CodeGenAgent: Agent;
6+
/**
7+
* Code Generation Model Registry
8+
*/
9+
export declare const CodeGenModelRegistry: ModelRegistry;
10+
/**
11+
* RAG for ObjectStack Documentation
12+
*/
13+
export declare const ObjectStackDocsRAG: RAGPipelineConfig;
14+
//# sourceMappingURL=ai-config.d.ts.map

examples/ai-codegen/src/ai-config.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.ObjectStackDocsRAG = exports.CodeGenModelRegistry = exports.CodeGenAgent = void 0;
4+
/**
5+
* ObjectStack Code Generator Agent
6+
*/
7+
exports.CodeGenAgent = {
8+
name: 'objectstack_code_generator',
9+
label: 'ObjectStack Code Generator',
10+
role: 'Senior ObjectStack Developer',
11+
instructions: `You are an expert ObjectStack developer who generates high-quality applications.
12+
13+
Rules:
14+
1. Follow ObjectStack naming conventions (camelCase for props, snake_case for names)
15+
2. Generate complete, production-ready code
16+
3. Include validation rules and indexes
17+
4. Create appropriate views and forms
18+
5. Follow best practices from the knowledge base
19+
20+
Always validate generated code before returning.`,
21+
model: {
22+
provider: 'openai',
23+
model: 'gpt-4-turbo-preview',
24+
temperature: 0.3,
25+
maxTokens: 8192,
26+
},
27+
tools: [
28+
{
29+
type: 'action',
30+
name: 'generate_object',
31+
description: 'Generate ObjectStack object definition',
32+
},
33+
{
34+
type: 'action',
35+
name: 'generate_field',
36+
description: 'Generate field definition',
37+
},
38+
{
39+
type: 'action',
40+
name: 'generate_view',
41+
description: 'Generate view configuration',
42+
},
43+
{
44+
type: 'action',
45+
name: 'validate_schema',
46+
description: 'Validate generated schema',
47+
},
48+
{
49+
type: 'vector_search',
50+
name: 'search_examples',
51+
description: 'Search example applications',
52+
},
53+
],
54+
knowledge: {
55+
topics: [
56+
'objectstack_protocol',
57+
'best_practices',
58+
'code_examples',
59+
'design_patterns',
60+
],
61+
indexes: ['objectstack_knowledge'],
62+
},
63+
active: true,
64+
};
65+
/**
66+
* Code Generation Model Registry
67+
*/
68+
exports.CodeGenModelRegistry = {
69+
name: 'code_generation_registry',
70+
models: {
71+
'gpt-4-turbo': {
72+
model: {
73+
id: 'gpt-4-turbo',
74+
name: 'GPT-4 Turbo',
75+
version: 'gpt-4-turbo-2024-04-09',
76+
provider: 'openai',
77+
capabilities: {
78+
textGeneration: true,
79+
textEmbedding: false,
80+
imageGeneration: false,
81+
imageUnderstanding: false,
82+
functionCalling: false,
83+
codeGeneration: true,
84+
reasoning: true,
85+
},
86+
limits: {
87+
maxTokens: 8192,
88+
contextWindow: 128000,
89+
},
90+
recommendedFor: ['code_generation', 'complex_reasoning'],
91+
deprecated: false,
92+
},
93+
status: 'active',
94+
priority: 10,
95+
},
96+
},
97+
promptTemplates: {
98+
object_generator: {
99+
id: 'object-gen-v1',
100+
name: 'object_generator',
101+
label: 'Object Generator',
102+
version: '1.0.0',
103+
system: `You are an expert at generating ObjectStack object definitions.
104+
105+
Generate valid TypeScript code following ObjectStack Protocol.
106+
Use camelCase for configuration properties, snake_case for name identifiers.`,
107+
user: `Generate an ObjectStack object for: {{description}}
108+
109+
Requirements:
110+
{{requirements}}
111+
112+
Include:
113+
- Field definitions with proper types
114+
- Validation rules if needed
115+
- Indexes for performance
116+
- Enable appropriate features`,
117+
variables: [
118+
{ name: 'description', type: 'string', required: true },
119+
{ name: 'requirements', type: 'string', required: false },
120+
],
121+
modelId: 'gpt-4-turbo',
122+
temperature: 0.3,
123+
category: 'code_generation',
124+
},
125+
},
126+
defaultModel: 'gpt-4-turbo',
127+
enableAutoFallback: true,
128+
};
129+
/**
130+
* RAG for ObjectStack Documentation
131+
*/
132+
exports.ObjectStackDocsRAG = {
133+
name: 'objectstack_documentation',
134+
label: 'ObjectStack Documentation RAG',
135+
description: 'RAG pipeline for ObjectStack protocol docs and examples',
136+
embedding: {
137+
provider: 'openai',
138+
model: 'text-embedding-3-large',
139+
dimensions: 3072,
140+
batchSize: 100,
141+
},
142+
vectorStore: {
143+
provider: 'pinecone',
144+
indexName: 'objectstack-docs',
145+
dimensions: 3072,
146+
metric: 'cosine',
147+
batchSize: 100,
148+
connectionPoolSize: 10,
149+
timeout: 30000,
150+
},
151+
chunking: {
152+
type: 'markdown',
153+
maxChunkSize: 1500,
154+
respectHeaders: true,
155+
respectCodeBlocks: true,
156+
},
157+
retrieval: {
158+
type: 'similarity',
159+
topK: 5,
160+
scoreThreshold: 0.7,
161+
},
162+
maxContextTokens: 8000,
163+
enableCache: true,
164+
cacheTTL: 7200,
165+
};

0 commit comments

Comments
 (0)