Skip to content

Commit c04c6ff

Browse files
committed
feat: Refactor API contract schemas and tests
- Updated contract test to use StandardApiContracts. - Added create contract to StandardApiContracts in contract.zod.ts. - Modified SpaceResponse and ListSpacesResponse in hub.test.ts to include success and data fields. - Updated PublishPluginRequest and SearchPluginsResponse schemas in hub.test.ts. - Refactored IssueLicenseRequest and ValidateLicenseResponse schemas in hub.test.ts. - Enhanced HubHealthResponse and HubMetricsResponse schemas in hub.test.ts. - Consolidated action schemas in workflow.test.ts, replacing specific schemas with ConnectorActionRefSchema. - Removed deprecated SMS, Slack, and Teams message schemas from workflow.test.ts. - Updated connector tests to use shared authentication schemas from connector-auth.zod.ts. - Adjusted AuthConfigSchema to make secret and baseUrl optional. - Changed job handler to reference a file instead of an inline function.
1 parent 34e6afc commit c04c6ff

9 files changed

Lines changed: 260 additions & 973 deletions

File tree

packages/spec/src/ai/conversation.test.ts

Lines changed: 22 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,21 @@ describe('MessageContentSchema', () => {
6060
};
6161
expect(() => MessageContentSchema.parse(content)).not.toThrow();
6262
});
63-
64-
it('should default to text type', () => {
65-
const content = {
66-
text: 'Hello',
67-
};
68-
const result = MessageContentSchema.parse(content);
69-
expect(result.type).toBe('text');
70-
});
7163
});
7264

7365
describe('ConversationMessageSchema', () => {
7466
it('should accept minimal message', () => {
75-
const message: ConversationMessage = {
67+
const message = {
7668
id: 'msg-1',
7769
timestamp: '2024-01-15T10:00:00Z',
7870
role: 'user',
79-
content: 'Hello, how are you?',
71+
content: [{ type: 'text', text: 'Hello, how are you?' }],
8072
};
8173
expect(() => ConversationMessageSchema.parse(message)).not.toThrow();
8274
});
8375

8476
it('should accept message with multimodal content', () => {
85-
const message: ConversationMessage = {
77+
const message = {
8678
id: 'msg-2',
8779
timestamp: '2024-01-15T10:01:00Z',
8880
role: 'user',
@@ -95,11 +87,11 @@ describe('ConversationMessageSchema', () => {
9587
});
9688

9789
it('should accept assistant message with token stats', () => {
98-
const message: ConversationMessage = {
90+
const message = {
9991
id: 'msg-3',
10092
timestamp: '2024-01-15T10:02:00Z',
10193
role: 'assistant',
102-
content: 'I am doing well, thank you!',
94+
content: [{ type: 'text', text: 'I am doing well, thank you!' }],
10395
tokens: {
10496
prompt: 15,
10597
completion: 8,
@@ -110,11 +102,11 @@ describe('ConversationMessageSchema', () => {
110102
});
111103

112104
it('should accept message with tool calls', () => {
113-
const message: ConversationMessage = {
105+
const message = {
114106
id: 'msg-4',
115107
timestamp: '2024-01-15T10:03:00Z',
116108
role: 'assistant',
117-
content: '',
109+
content: [],
118110
toolCalls: [
119111
{
120112
id: 'call-1',
@@ -130,11 +122,11 @@ describe('ConversationMessageSchema', () => {
130122
});
131123

132124
it('should accept pinned message with importance', () => {
133-
const message: ConversationMessage = {
125+
const message = {
134126
id: 'msg-5',
135127
timestamp: '2024-01-15T10:04:00Z',
136128
role: 'system',
137-
content: 'You are a helpful assistant.',
129+
content: [{ type: 'text', text: 'You are a helpful assistant.' }],
138130
pinned: true,
139131
importance: 1.0,
140132
};
@@ -144,11 +136,11 @@ describe('ConversationMessageSchema', () => {
144136
});
145137

146138
it('should accept message with embedding', () => {
147-
const message: ConversationMessage = {
139+
const message = {
148140
id: 'msg-6',
149141
timestamp: '2024-01-15T10:05:00Z',
150142
role: 'user',
151-
content: 'Important information',
143+
content: [{ type: 'text', text: 'Important information' }],
152144
embedding: [0.1, 0.2, 0.3, 0.4, 0.5],
153145
};
154146
expect(() => ConversationMessageSchema.parse(message)).not.toThrow();
@@ -174,7 +166,6 @@ describe('TokenBudgetConfigSchema', () => {
174166
expect(result.strategy).toBe('sliding_window');
175167
expect(result.reserveTokens).toBe(500);
176168
expect(result.bufferPercentage).toBe(0.1);
177-
expect(result.warnThreshold).toBe(0.8);
178169
});
179170

180171
it('should accept full budget config with sliding window', () => {
@@ -186,7 +177,6 @@ describe('TokenBudgetConfigSchema', () => {
186177
bufferPercentage: 0.15,
187178
strategy: 'sliding_window',
188179
slidingWindowSize: 10,
189-
warnThreshold: 0.9,
190180
enableSummarization: false,
191181
};
192182
expect(() => TokenBudgetConfigSchema.parse(config)).not.toThrow();
@@ -282,7 +272,7 @@ describe('ConversationContextSchema', () => {
282272

283273
describe('ConversationSessionSchema', () => {
284274
it('should accept minimal session', () => {
285-
const session: ConversationSession = {
275+
const session = {
286276
id: 'session-1',
287277
context: {
288278
sessionId: 'session-1',
@@ -299,7 +289,7 @@ describe('ConversationSessionSchema', () => {
299289
});
300290

301291
it('should accept full session with messages', () => {
302-
const session: ConversationSession = {
292+
const session = {
303293
id: 'session-1',
304294
name: 'Support Chat - Case #123',
305295
context: {
@@ -313,7 +303,7 @@ describe('ConversationSessionSchema', () => {
313303
modelId: 'gpt-4-turbo',
314304
tokenBudget: {
315305
maxTokens: 8192,
316-
strategy: 'sliding_window',
306+
strategy: 'sliding_window' as const,
317307
slidingWindowSize: 20,
318308
enableSummarization: true,
319309
},
@@ -322,13 +312,13 @@ describe('ConversationSessionSchema', () => {
322312
id: 'msg-1',
323313
timestamp: '2024-01-15T10:00:00Z',
324314
role: 'user',
325-
content: 'I need help with my order',
315+
content: [{ type: 'text', text: 'I need help with my order' }],
326316
},
327317
{
328318
id: 'msg-2',
329319
timestamp: '2024-01-15T10:01:00Z',
330320
role: 'assistant',
331-
content: 'I\'d be happy to help! What\'s your order number?',
321+
content: [{ type: 'text', text: 'I\'d be happy to help! What\'s your order number?' }],
332322
},
333323
],
334324
tokens: {
@@ -355,7 +345,7 @@ describe('ConversationSessionSchema', () => {
355345
});
356346

357347
it('should accept session with expiry', () => {
358-
const session: ConversationSession = {
348+
const session = {
359349
id: 'session-1',
360350
context: {
361351
sessionId: 'session-1',
@@ -495,22 +485,22 @@ describe('Real-World Conversation Examples', () => {
495485
id: 'msg-system',
496486
timestamp: '2024-01-15T09:00:00Z',
497487
role: 'system',
498-
content: 'You are a helpful customer support agent specialized in order management.',
488+
content: [{ type: 'text', text: 'You are a helpful customer support agent specialized in order management.' }],
499489
pinned: true,
500490
importance: 1.0,
501491
},
502492
{
503493
id: 'msg-1',
504494
timestamp: '2024-01-15T09:00:05Z',
505495
role: 'user',
506-
content: 'Hi, I have an issue with my order #ORD-2024-001',
496+
content: [{ type: 'text', text: 'Hi, I have an issue with my order #ORD-2024-001' }],
507497
tokens: { prompt: 15, completion: 0, total: 15 },
508498
},
509499
{
510500
id: 'msg-2',
511501
timestamp: '2024-01-15T09:00:15Z',
512502
role: 'assistant',
513-
content: 'Hello! I\'d be happy to help you with your order. Let me look up the details for order #ORD-2024-001.',
503+
content: [{ type: 'text', text: 'Hello! I\'d be happy to help you with your order. Let me look up the details for order #ORD-2024-001.' }],
514504
tokens: { prompt: 30, completion: 25, total: 55 },
515505
},
516506
],
@@ -561,14 +551,14 @@ describe('Real-World Conversation Examples', () => {
561551
id: 'msg-1',
562552
timestamp: '2024-01-15T14:00:00Z',
563553
role: 'user',
564-
content: 'Write a Python function to calculate fibonacci numbers',
554+
content: [{ type: 'text', text: 'Write a Python function to calculate fibonacci numbers' }],
565555
importance: 0.9,
566556
},
567557
{
568558
id: 'msg-2',
569559
timestamp: '2024-01-15T14:00:10Z',
570560
role: 'assistant',
571-
content: '',
561+
content: [],
572562
toolCalls: [
573563
{
574564
id: 'call-1',

packages/spec/src/api/contract.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
BulkResponseSchema,
1313
DeleteResponseSchema,
1414
RecordDataSchema,
15-
ApiContracts,
15+
StandardApiContracts as ApiContracts,
1616
} from './contract.zod';
1717

1818
describe('ApiErrorSchema', () => {

packages/spec/src/api/contract.zod.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ export const DeleteResponseSchema = BaseResponseSchema.extend({
126126
* Used for generating SDKs and Documentation
127127
*/
128128
export const StandardApiContracts = {
129+
create: {
130+
input: CreateRequestSchema,
131+
output: SingleRecordResponseSchema
132+
},
129133
delete: {
130134
input: IdRequestSchema,
131135
output: DeleteResponseSchema

0 commit comments

Comments
 (0)