Skip to content

Global: add linting and update type names #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Mar 6, 2025
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@
"build:samples": "npx turbo build --filter=./samples/*",
"dev": "npx turbo dev",
"lint": "npx turbo lint",
"lint:fix": "npx turbo lint:fix",
"test": "npx turbo test --concurrency=100%",
"fmt": "npx prettier --write \"**/*.{js,ts,tsx,md,json}\"",
"docs:build": "mdbook build book",
1 change: 1 addition & 0 deletions packages/ai/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@microsoft/spark.config/eslint.config');
2 changes: 2 additions & 0 deletions packages/ai/package.json
Original file line number Diff line number Diff line change
@@ -25,6 +25,8 @@
],
"scripts": {
"clean": "npx rimraf ./dist",
"lint": "npx eslint",
"lint:fix": "npx eslint --fix",
"build": "npx tsup",
"test": "npx jest"
},
8 changes: 4 additions & 4 deletions packages/ai/src/function.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
export type FunctionHandler<T = any> = (args: T) => any | Promise<any>;

export interface Function {
export type Function = {
readonly name: string;
readonly description: string;
readonly parameters: { [key: string]: any };
readonly handler: FunctionHandler;
}
};

export interface FunctionCall {
export type FunctionCall = {
readonly id: string;
readonly name: string;
readonly arguments: { [key: string]: any };
}
};
14 changes: 7 additions & 7 deletions packages/ai/src/local-memory.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Memory } from './memory';
import { IMemory } from './memory';
import { Message } from './message';
import { ChatModel } from './models';
import { IChatModel } from './models';

export interface LocalMemoryOptions {
export type LocalMemoryOptions = {
readonly max?: number;
readonly messages?: Message[];
readonly collapse?: {
readonly strategy: 'half' | 'full';
readonly model: ChatModel;
readonly model: IChatModel;
};
}
};

export class LocalMemory implements Memory {
export class LocalMemory implements IMemory {
protected readonly messages: Message[];
protected readonly options: LocalMemoryOptions;

@@ -59,7 +59,7 @@ export class LocalMemory implements Memory {
async collapse() {
if (!this.options.collapse) return;

let start = 0;
const start = 0;
let end = this.length() - 1;

if (this.options.collapse.strategy === 'half') {
2 changes: 1 addition & 1 deletion packages/ai/src/memory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Message } from './message';

export interface Memory {
export interface IMemory {
push(message: Message): void | Promise<void>;
pop(): (Message | undefined) | Promise<Message | undefined>;
values(): Message[] | Promise<Message[]>;
24 changes: 12 additions & 12 deletions packages/ai/src/message.ts
Original file line number Diff line number Diff line change
@@ -2,36 +2,36 @@ import { FunctionCall } from './function';

export type Message = UserMessage | ModelMessage | SystemMessage | FunctionMessage;

export interface UserMessage {
export type UserMessage = {
role: 'user';
content: string | ContentPart[];
}
};

export interface ModelMessage {
export type ModelMessage = {
role: 'model';
content?: string;
function_calls?: FunctionCall[];
}
};

export interface SystemMessage {
export type SystemMessage = {
role: 'system';
content: string;
}
};

export interface FunctionMessage {
export type FunctionMessage = {
role: 'function';
content?: string;
function_id: string;
}
};

export type ContentPart = TextContentPart | ImageContentPart;

export interface TextContentPart {
export type TextContentPart = {
type: 'text';
text: string;
}
};

export interface ImageContentPart {
export type ImageContentPart = {
type: 'image_url';
image_url: string;
}
};
10 changes: 5 additions & 5 deletions packages/ai/src/models/audio.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
export interface TextToAudioParams {
export type TextToAudioParams = {
readonly type: string;
readonly text: string;
readonly voice: string;
}
};

export interface AudioToTextParams {
export type AudioToTextParams = {
readonly type: string;
readonly data: Buffer;
readonly prompt?: string;
readonly lang?: string;
}
};

export interface AudioModel {
export interface IAudioModel {
textToAudio?(params: TextToAudioParams): Promise<Buffer>;
audioToText?(params: AudioToTextParams): Promise<string>;
}
10 changes: 5 additions & 5 deletions packages/ai/src/models/chat.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Function } from '../function';
import { Memory } from '../memory';
import { IMemory } from '../memory';
import { Message, ModelMessage, SystemMessage, UserMessage } from '../message';

export interface ChatParams {
export type ChatParams = {
readonly system?: SystemMessage | UserMessage;
readonly input: Message;
readonly messages?: Memory;
readonly messages?: IMemory;
readonly functions?: Record<string, Function>;
}
};

export interface ChatModel {
export interface IChatModel {
chat(
params: ChatParams,
onChunk?: (chunk: ModelMessage) => void | Promise<void>
6 changes: 3 additions & 3 deletions packages/ai/src/models/image.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export interface TextToImageParams {
export type TextToImageParams = {
readonly prompt?: string;
readonly size?: string;
}
};

export interface ImageModel {
export interface IImageModel {
textToImage?(params?: TextToImageParams): Promise<string>;
}
8 changes: 4 additions & 4 deletions packages/ai/src/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AudioModel } from './audio';
import { ImageModel } from './image';
import { ChatModel } from './chat';
import { IAudioModel } from './audio';
import { IImageModel } from './image';
import { IChatModel } from './chat';

export type Model = ChatModel | AudioModel | ImageModel;
export type Model = IChatModel | IAudioModel | IImageModel;

export * from './chat';
export * from './audio';
10 changes: 5 additions & 5 deletions packages/ai/src/prompts/audio.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AudioModel, AudioToTextParams, TextToAudioParams } from '../models';
import { IAudioModel, AudioToTextParams, TextToAudioParams } from '../models';

export interface AudioPromptOptions {
readonly model: AudioModel;
}
export type AudioPromptOptions = {
readonly model: IAudioModel;
};

export class AudioPrompt {
protected readonly _model: AudioModel;
protected readonly _model: IAudioModel;

constructor(options: AudioPromptOptions) {
this._model = options.model;
22 changes: 11 additions & 11 deletions packages/ai/src/prompts/chat.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { Function, FunctionHandler } from '../function';
import { LocalMemory } from '../local-memory';
import { Memory } from '../memory';
import { IMemory } from '../memory';
import { ContentPart, Message, SystemMessage, UserMessage } from '../message';
import { ChatModel } from '../models';
import { IChatModel } from '../models';
import { Schema } from '../schema';
import { Template } from '../template';
import { ITemplate } from '../template';
import { StringTemplate } from '../templates';

export interface ChatPromptOptions {
readonly model: ChatModel;
readonly instructions?: string | Template;
export type ChatPromptOptions = {
readonly model: IChatModel;
readonly instructions?: string | ITemplate;
readonly role?: 'system' | 'user';
readonly messages?: Message[] | Memory;
}
readonly messages?: Message[] | IMemory;
};

export class ChatPrompt {
readonly messages: Memory;
readonly messages: IMemory;

protected readonly _role: 'system' | 'user';
protected readonly _model: ChatModel;
protected readonly _template: Template;
protected readonly _model: IChatModel;
protected readonly _template: ITemplate;
protected readonly _functions: Record<string, Function> = {};

constructor(options: ChatPromptOptions) {
32 changes: 16 additions & 16 deletions packages/ai/src/schema.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
interface BaseSchema {
type BaseSchema = {
readonly $schema?: string;
readonly $ref?: string;
readonly id?: string;
readonly title?: string;
readonly description?: string;
readonly type?: 'object' | 'array' | 'string' | 'number' | 'integer' | 'null' | 'boolean';
readonly enum?: any[];
}
};

export type Schema =
| StringSchema
@@ -17,43 +17,43 @@ export type Schema =
| NullSchema
| AnySchema;

export interface StringSchema extends BaseSchema {
export type StringSchema = BaseSchema & {
readonly type: 'string';
readonly pattern?: string;
readonly format?: string;
readonly minLength?: number;
readonly maxLength?: number;
}
};

export interface NumberSchema extends BaseSchema {
export type NumberSchema = BaseSchema & {
readonly type: 'number' | 'integer';
readonly min?: number;
readonly max?: number;
readonly multipleOf?: number;
}
};

export interface BooleanSchema extends BaseSchema {
export type BooleanSchema = BaseSchema & {
readonly type: 'boolean';
}
};

export interface ObjectSchema extends BaseSchema {
export type ObjectSchema = BaseSchema & {
readonly type: 'object';
readonly properties?: {
[key: string]: Schema;
};
readonly required?: string[] | boolean;
}
};

export interface ArraySchema extends BaseSchema {
export type ArraySchema = BaseSchema & {
readonly type: 'array';
readonly items: Schema | Schema[];
readonly additionalItems?: Schema | Schema[];
}
};

export interface NullSchema extends BaseSchema {
export type NullSchema = BaseSchema & {
readonly type: 'null';
}
};

export interface AnySchema extends BaseSchema {
export type AnySchema = BaseSchema & {
readonly type: undefined;
}
};
2 changes: 1 addition & 1 deletion packages/ai/src/template.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export interface Template {
export interface ITemplate {
render(params?: Record<string, any>): string | Promise<string>;
}
4 changes: 2 additions & 2 deletions packages/ai/src/templates/string.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Template } from '../template';
import { ITemplate } from '../template';

export class StringTemplate implements Template {
export class StringTemplate implements ITemplate {
constructor(readonly src?: string) {}

render() {
1 change: 1 addition & 0 deletions packages/api/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@microsoft/spark.config/eslint.config');
2 changes: 2 additions & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
@@ -26,6 +26,8 @@
],
"scripts": {
"clean": "npx rimraf ./dist",
"lint": "npx eslint",
"lint:fix": "npx eslint --fix",
"build": "npx tsup",
"test": "npx jest"
},
Loading