Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
chore: remove some unused utils (#458)
teoc1d45a631872
diff --git a/js/app/packages/core/util/getOrDefineGlobal.ts b/js/app/packages/core/util/getOrDefineGlobal.tsdeleted file mode 100644index e69de29bb2..0000000000diff --git a/js/app/packages/core/util/navigation.ts b/js/app/packages/core/util/navigation.tsdeleted file mode 100644index fea6970be1..0000000000--- a/js/app/packages/core/util/navigation.ts+++ /dev/null@@ -1,29 +0,0 @@-import { refetchHistory } from '@service-storage/history';-import { useNavigate } from '@solidjs/router';-import { isErr } from './maybeResult';-import { propsToHref } from './url';--export function useOpenLastItem() {- const navigate = useNavigate();-- return async () => {- const maybeHistory = await refetchHistory(true);- if (!maybeHistory || isErr(maybeHistory)) return;- const lastItem = maybeHistory[1].data[0];- if (!lastItem) return;-- let href;- if (lastItem.type === 'document') {- href = propsToHref({- fileType: lastItem.fileType,- id: lastItem.id,- });- } else if (lastItem.type === 'chat') {- href = `/chat/${lastItem.id}`;- }-- if (href) {- navigate(href);- }- };-}diff --git a/js/app/packages/core/util/serviceToVertexAi.ts b/js/app/packages/core/util/serviceToVertexAi.tsdeleted file mode 100644index 958039281a..0000000000--- a/js/app/packages/core/util/serviceToVertexAi.ts+++ /dev/null@@ -1,153 +0,0 @@-import { z } from 'zod';-import type { Access, Svc } from '../service';--export enum SchemaType {- STRING = 'STRING',- NUMBER = 'NUMBER',- INTEGER = 'INTEGER',- BOOLEAN = 'BOOLEAN',- ARRAY = 'ARRAY',- OBJECT = 'OBJECT',-}--export interface Schema {- type?: SchemaType;- format?: string;- description?: string;- nullable?: boolean;- items?: Schema;- enum?: string[];- properties?: { [k: string]: Schema };- required?: string[];- example?: unknown;-}--export function convertSvcToVertexAI(- svc: Svc<any, any, any>-): Record<string, any> {- const result: Record<string, any> = {};-- if (!hasAIAccess(svc.state.def.access)) {- return result;- }-- for (const [fnName, fnDef] of Object.entries(svc.state.functions)) {- if (!hasAIAccess(fnDef.access)) {- continue;- }-- result[fnName] = {- name: fnName,- description: fnDef.description,- parameters: convertZodToVertexSchema(fnDef.args),- };-- if (fnDef.result) {- result[fnName].returns = convertZodToVertexSchema(fnDef.result);- }-- if (fnDef.modifies) {- result[fnName].modifies = true;- }- }-- for (const [subServiceName, subService] of Object.entries(- svc.state.services- )) {- const subServiceResult = convertSvcToVertexAI(subService);- if (Object.keys(subServiceResult).length > 0) {- result[subServiceName] = subServiceResult;- }- }-- return result;-}--function convertZodToVertexSchema(zodSchema?: z.ZodTypeAny): Schema {- if (!zodSchema) return {};-- if (zodSchema instanceof z.ZodObject) {- const properties: { [k: string]: Schema } = {};- const required: string[] = [];-- for (const [key, value] of Object.entries<z.ZodTypeAny>(zodSchema.shape)) {- const fieldSchema = zodTypeToVertexSchema(value);- properties[key] = fieldSchema;-- if (!(value instanceof z.ZodOptional) && !isNullable(value)) {- required.push(key);- }- }-- return {- type: SchemaType.OBJECT,- properties,- required: required.length > 0 ? required : undefined,- };- }-- return zodTypeToVertexSchema(zodSchema);-}--function zodTypeToVertexSchema(zodType: z.ZodTypeAny): Schema {- let schema: Schema = {- type: getVertexSchemaType(zodType),- };-- if (zodType.description) {- schema.description = zodType.description;- }-- if (zodType instanceof z.ZodEnum) {- schema.enum = zodType.options;- } else if (zodType instanceof z.ZodArray) {- schema.items = zodTypeToVertexSchema(zodType.element);- } else if (zodType instanceof z.ZodObject) {- const { properties, required } = convertZodToVertexSchema(- zodType- ) as Schema;- schema.properties = properties;- schema.required = required;- } else if (zodType instanceof z.ZodUnion) {- schema.type = SchemaType.STRING;- schema.description = 'Union of multiple types';- } else if (zodType instanceof z.ZodOptional) {- schema = zodTypeToVertexSchema(zodType.unwrap());- schema.nullable = true;- } else if (zodType instanceof z.ZodNullable) {- schema = zodTypeToVertexSchema(zodType.unwrap());- schema.nullable = true;- }-- return schema;-}--function getVertexSchemaType(zodType: z.ZodTypeAny): SchemaType {- if (zodType instanceof z.ZodString) return SchemaType.STRING;- if (zodType instanceof z.ZodNumber) return SchemaType.NUMBER;- if (zodType instanceof z.ZodBoolean) return SchemaType.BOOLEAN;- if (zodType instanceof z.ZodArray) return SchemaType.ARRAY;- if (zodType instanceof z.ZodObject) return SchemaType.OBJECT;- if (zodType instanceof z.ZodEnum) return SchemaType.STRING;- if (zodType instanceof z.ZodOptional)- return getVertexSchemaType(zodType.unwrap());- if (zodType instanceof z.ZodNullable)- return getVertexSchemaType(zodType.unwrap());-- throw new Error(`Unhandled Zod type: ${zodType.constructor.name}`);-}--function isNullable(zodType: z.ZodTypeAny): boolean {- return zodType instanceof z.ZodNullable || zodType.isNullable();-}--function hasAIAccess(access?: Access): boolean {- if (!access) return true;- if ('exclude' in access) {- return !access.exclude?.includes('ai');- }- if ('only' in access) {- return access.only?.includes('ai') ?? false;- }- return true;-}diff --git a/js/app/packages/core/util/withValidation.ts b/js/app/packages/core/util/withValidation.tsdeleted file mode 100644index 7feeedcd36..0000000000--- a/js/app/packages/core/util/withValidation.ts+++ /dev/null@@ -1,106 +0,0 @@-import type { z } from 'zod';-import { type FunctionDefinition, type ServiceClient, Svc } from '../service';-import type { MaybeResult, ResultError } from './maybeResult';--type WithInvalidError<T extends Svc<any, any, any>> = T extends Svc<- infer ErrorCodes,- infer Functions,- infer Services->- ? Svc<- ErrorCodes | 'invalid',- {- [K in keyof Functions]: Functions[K] extends FunctionDefinition<- infer E,- infer Args,- infer Result,- infer Throws- >- ? FunctionDefinition<- E | 'invalid',- Args,- Result,- Throws extends Array<E> ? Array<E | 'invalid'> : ['invalid']- >- : Functions[K];- },- Services- >- : never;--function zodErrorToInvalidErrors(- zodError: z.ZodError-): ResultError<'invalid'>[] {- return zodError.errors.map((err) => ({- code: 'invalid',- message: err.message,- arg: err.path.join('.'),- fatal: true,- }));-}--export function withValidation<T extends Svc<any, any, any>>(- service: T,- client: ServiceClient<T>-): ServiceClient<WithInvalidError<T>> {- const newService = new Svc(service.state.def.description, service.state.def);-- // Add 'invalid' error to the service- newService.err('invalid', { description: 'Invalid input', fatal: true });-- // Copy existing error codes- Object.entries(service.state.errors).forEach(([code, options]) => {- newService.err(code as any, options);- });-- // Add 'invalid' error to all functions and update their throws- Object.entries(service.state.functions).forEach(([name, funcDef]) => {- const newThrows = funcDef.throws- ? [...funcDef.throws, 'invalid']- : ['invalid'];- const newFuncDef = {- ...funcDef,- throws: newThrows,- };- newService.fn(name as any, newFuncDef as any);- });-- // Create a new client with Zod validation- const validatedClient = {} as ServiceClient<WithInvalidError<T>>;- Object.entries<unknown>(client).forEach(([key, originalFunc]) => {- if (typeof originalFunc === 'function') {- (validatedClient as any)[key] = async (args: any) => {- const funcDef = service.state.functions[key];- if (funcDef && funcDef.args) {- const parseResult = funcDef.args.safeParse(args);- if (!parseResult.success) {- return [zodErrorToInvalidErrors(parseResult.error), null];- }- args = parseResult.data;- }-- try {- const result = await originalFunc(args);- if (Array.isArray(result) && result.length === 2) {- return result as MaybeResult<any, any>;- }- return [null, result] as MaybeResult<any, any>;- } catch (error) {- const invalidError: ResultError<'invalid'> = {- code: 'invalid',- message:- error instanceof Error- ? error.message- : 'Unexpected error occurred',- fatal: true,- };- return [[invalidError], null];- }- };- } else {- (validatedClient as any)[key] = originalFunc;- }- });-- return validatedClient;-}diff --git a/js/app/packages/core/util/writer.ts b/js/app/packages/core/util/writer.tsdeleted file mode 100644index f88d3e2ceb..0000000000--- a/js/app/packages/core/util/writer.ts+++ /dev/null@@ -1,74 +0,0 @@-import type {- DocxExpandedPart,- DocxExpandedPartWithoutSha,-} from '@service-storage/util/getDocxFile';--export async function zipDocxExpandedParts(- parts: Array<DocxExpandedPart | DocxExpandedPartWithoutSha>-): Promise<Blob> {- const { default: JsZip } = await import('jszip');- const zip = new JsZip();-- parts.forEach(({ path, content }) => {- zip.file(path, content as ArrayBuffer);- });-- return zip.generateAsync({ type: 'blob' });-}--export function processRTF(rtfData: string): string {- return removeUnnecessaryMetadata(rtfData);-}--function removeUnnecessaryMetadata(rtfContent: string): string {- // Split the RTF content into sections- const sections = rtfContent.split(/(?=\{\\)/);-- const processedSections = sections.filter((section) => {- // Keep the RTF header- if (section.startsWith('{\\rtf1')) {- return true;- }- // Keep revision table- if (section.includes('{\\*\\revtbl')) {- return true;- }- // Remove font table- if (section.includes('{\\fonttbl')) {- return false;- }- // Remove color table- if (section.includes('{\\colortbl')) {- return false;- }- // Remove only stylesheet definition tables, not styled text- if (section.match(/^\{\\stylesheet/)) {- return false;- }- // Remove generator info- if (section.includes('{\\*\\generator')) {- return false;- }- // Keep headers and footers- if (section.includes('\\header') || section.includes('\\footer')) {- return true;- }- // Keep body text and revisions- if (- section.includes('\\loch') ||- section.includes('\\revised') ||- section.includes('\\deleted')- ) {- return true;- }- // Remove other metadata- if (section.match(/\{\\[\w*]+/)) {- return false;- }- // Keep other sections by default- return true;- });-- // Join the processed sections back into a single string- return processedSections.join('');-}