Skip to content

Commit 5e98567

Browse files
Copilothotlong
andcommitted
Fix all remaining TypeScript errors in example files
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 2493882 commit 5e98567

4 files changed

Lines changed: 215 additions & 611 deletions

File tree

examples/basic/ai-rag-example.ts

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ export const knowledgeBaseRAG: AI.RAGPipelineConfig = {
3636
namespace: 'production',
3737
dimensions: 1536,
3838
metric: 'cosine',
39+
batchSize: 100,
40+
connectionPoolSize: 10,
41+
timeout: 30000,
3942
},
4043

4144
// Chunking strategy
@@ -69,6 +72,10 @@ export const knowledgeBaseRAG: AI.RAGPipelineConfig = {
6972
metadataFilters: {
7073
status: 'published',
7174
},
75+
76+
// Cache Configuration
77+
enableCache: true,
78+
cacheTTL: 3600,
7279
};
7380

7481
/**
@@ -144,6 +151,8 @@ export const sampleQueries: AI.RAGQueryRequest[] = [
144151
query: 'What is ObjectStack?',
145152
pipelineName: 'knowledge_base_rag',
146153
topK: 5,
154+
includeMetadata: true,
155+
includeSources: true,
147156
},
148157
{
149158
// Question with metadata filtering
@@ -153,6 +162,8 @@ export const sampleQueries: AI.RAGQueryRequest[] = [
153162
metadataFilters: {
154163
category: 'Tutorial',
155164
},
165+
includeMetadata: true,
166+
includeSources: true,
156167
},
157168
{
158169
// Advanced query
@@ -207,10 +218,6 @@ It uses a three-layer architecture: ObjectQL for data, ObjectUI for presentation
207218
208219
[Source: https://docs.objectstack.dev/architecture]
209220
The platform supports multiple databases and provides built-in AI capabilities.`,
210-
211-
// Metadata
212-
processingTimeMs: 150,
213-
totalResults: 2,
214221
};
215222

216223
/**
@@ -220,20 +227,12 @@ The platform supports multiple databases and provides built-in AI capabilities.`
220227
*/
221228
export const ragEnabledAgent: AI.Agent = {
222229
name: 'documentation_assistant',
223-
type: 'conversational',
224230
label: 'Documentation Assistant',
225-
description: 'AI assistant powered by RAG for answering questions about ObjectStack',
226-
227-
// Agent capabilities
228-
capabilities: {
229-
objectAccess: [],
230-
canCreate: false,
231-
canUpdate: false,
232-
canAnalyze: true,
233-
},
234-
231+
role: 'Documentation Support Specialist',
232+
active: true,
233+
235234
// System prompt with RAG instructions
236-
systemPrompt: `You are a helpful documentation assistant for ObjectStack.
235+
instructions: `You are a helpful documentation assistant for ObjectStack.
237236
238237
You have access to the knowledge base through RAG (Retrieval-Augmented Generation).
239238
When answering questions:
@@ -245,18 +244,9 @@ When answering questions:
245244
Always format your responses in a clear, structured way.`,
246245

247246
// RAG Configuration
248-
rag: {
249-
pipeline: 'knowledge_base_rag',
250-
enabled: true,
251-
252-
// When to trigger RAG
253-
trigger: 'always', // or 'auto', 'manual'
254-
255-
// Number of chunks to retrieve
256-
topK: 5,
257-
258-
// Include source attribution
259-
includeSources: true,
247+
knowledge: {
248+
indexes: ['knowledge-base'],
249+
topics: ['ObjectStack', 'documentation'],
260250
},
261251

262252
// Model configuration
@@ -270,12 +260,9 @@ Always format your responses in a clear, structured way.`,
270260
// Tools (optional - for function calling)
271261
tools: [
272262
{
263+
type: 'query',
273264
name: 'search_documentation',
274265
description: 'Search the ObjectStack documentation for specific topics',
275-
parameters: {
276-
query: 'string',
277-
category: 'string?',
278-
},
279266
},
280267
],
281268
};
@@ -297,7 +284,7 @@ export function demonstrateRAGUsage() {
297284
console.log('- Embedding query...');
298285
console.log('- Searching vector database...');
299286
console.log(`- Retrieved ${sampleResults.results.length} relevant chunks`);
300-
console.log(`- Processing time: ${sampleResults.processingTimeMs}ms\n`);
287+
console.log('- Processing complete\n');
301288

302289
// Step 3: Context is assembled
303290
console.log('Assembled Context:');

examples/basic/auth-permission-example.ts

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ export const rowLevelSecurityRules: Permission.RowLevelSecurityPolicy[] = [
218218
object: 'opportunity',
219219
description: 'Users can only access their own opportunities',
220220
operation: 'select',
221+
priority: 100,
221222

222223
// USING clause - Filter condition
223224
using: `owner_id = current_user.id OR territory IN (SELECT id FROM territories WHERE user_id = current_user.id) OR owner_manager_id = current_user.id`,
@@ -233,6 +234,7 @@ export const rowLevelSecurityRules: Permission.RowLevelSecurityPolicy[] = [
233234
object: 'account',
234235
description: 'Territory-based account access',
235236
operation: 'select',
237+
priority: 100,
236238

237239
using: `territory IN (SELECT id FROM territories WHERE user_id = current_user.id) AND status = 'active'`,
238240

@@ -318,50 +320,35 @@ export const territories: Permission.Territory[] = [
318320
{
319321
name: 'north_america',
320322
label: 'North America',
321-
description: 'North American sales territory',
323+
modelId: 'global_sales_territories',
324+
type: 'geography',
322325

323-
// Territory definition
324-
criteria: {
325-
operator: 'OR',
326-
conditions: [
327-
{
328-
field: 'billing_country',
329-
operator: 'in',
330-
value: ['USA', 'Canada', 'Mexico'],
331-
},
332-
],
333-
},
326+
// Territory assignment rule
327+
assignmentRule: `billing_country IN ('USA', 'Canada', 'Mexico')`,
334328

335329
// Assigned users
336-
members: ['user_002', 'user_003'],
330+
assignedUsers: ['user_002', 'user_003'],
337331

338-
// Parent territory (for hierarchy)
339-
parentTerritory: undefined,
332+
// Access levels
333+
accountAccess: 'edit',
334+
opportunityAccess: 'edit',
335+
caseAccess: 'read',
340336
},
341337

342338
{
343339
name: 'west_coast',
344340
label: 'West Coast',
345-
description: 'US West Coast territory',
341+
modelId: 'global_sales_territories',
342+
type: 'geography',
343+
parent: 'north_america',
346344

347-
criteria: {
348-
operator: 'AND',
349-
conditions: [
350-
{
351-
field: 'billing_country',
352-
operator: 'equals',
353-
value: 'USA',
354-
},
355-
{
356-
field: 'billing_state',
357-
operator: 'in',
358-
value: ['CA', 'OR', 'WA', 'NV', 'AZ'],
359-
},
360-
],
361-
},
345+
assignmentRule: `billing_country = 'USA' AND billing_state IN ('CA', 'OR', 'WA', 'NV', 'AZ')`,
346+
347+
assignedUsers: ['user_003'],
362348

363-
members: ['user_003'],
364-
parentTerritory: 'north_america',
349+
accountAccess: 'edit',
350+
opportunityAccess: 'edit',
351+
caseAccess: 'read',
365352
},
366353
];
367354

@@ -404,11 +391,11 @@ export class PermissionChecker {
404391
/**
405392
* Check if user can access a specific record (RLS)
406393
*/
407-
canAccessRecord(user: Auth.User, object: string, record: any): boolean {
394+
canAccessRecord(user: Auth.User & { roles?: string[] }, object: string, record: any): boolean {
408395
// Apply RLS rules for user's roles
409396
const userRoles = user.roles || [];
410397
const applicableRules = rowLevelSecurityRules.filter(
411-
(rls) => rls.object === object && rls.roles?.some((r) => userRoles.includes(r))
398+
(rls) => rls.object === object && rls.roles?.some((r: string) => userRoles.includes(r))
412399
);
413400

414401
// If no RLS rules, check base permissions
@@ -418,7 +405,7 @@ export class PermissionChecker {
418405

419406
// Evaluate RLS rules
420407
for (const rule of applicableRules) {
421-
if (this.evaluateRule(rule.rule, record, user)) {
408+
if (this.evaluateRule(rule.using, record, user)) {
422409
return true;
423410
}
424411
}
@@ -429,7 +416,7 @@ export class PermissionChecker {
429416
/**
430417
* Evaluate a rule against a record
431418
*/
432-
private evaluateRule(rule: any, record: any, user: Auth.User): boolean {
419+
private evaluateRule(rule: any, record: any, user: Auth.User & { roles?: string[] }): boolean {
433420
// Simplified evaluation logic
434421
// In real implementation, evaluate all conditions with operators
435422
return true;
@@ -440,7 +427,7 @@ export class PermissionChecker {
440427
* Example 8: Usage Demonstration
441428
*/
442429
export function demonstratePermissions() {
443-
const user = sampleUsers[2]; // Sales Rep
430+
const user = { ...sampleUsers[2], roles: ['sales_rep'] }; // Sales Rep with role
444431
const checker = new PermissionChecker();
445432

446433
console.log('=== Permission Check Demo ===\n');

0 commit comments

Comments
 (0)