@transcend-io/cli 8.36.0 → 8.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/dist/{api-keys-C3yVviFj.cjs → api-keys-eh_rPCV_.cjs} +2 -2
- package/dist/{api-keys-C3yVviFj.cjs.map → api-keys-eh_rPCV_.cjs.map} +1 -1
- package/dist/app-D0ewaGAn.cjs +131 -0
- package/dist/app-D0ewaGAn.cjs.map +1 -0
- package/dist/bin/bash-complete.cjs +1 -1
- package/dist/bin/bash-complete.cjs.map +1 -1
- package/dist/bin/cli.cjs +1 -1
- package/dist/bin/cli.cjs.map +1 -1
- package/dist/bin/deprecated-command.cjs +1 -1
- package/dist/bin/deprecated-command.cjs.map +1 -1
- package/dist/buildAIIntegrationType-BwuCYR-o.cjs +2 -0
- package/dist/{buildAIIntegrationType-n_Qlv8wG.cjs.map → buildAIIntegrationType-BwuCYR-o.cjs.map} +1 -1
- package/dist/chunk-Bmb41Sf3.cjs +1 -0
- package/dist/{code-scanning-Cp3rJ0-7.cjs → code-scanning-BB6Ncuzh.cjs} +2 -2
- package/dist/{code-scanning-Cp3rJ0-7.cjs.map → code-scanning-BB6Ncuzh.cjs.map} +1 -1
- package/dist/codecs-Bvmb8o9R.cjs +2 -0
- package/dist/{codecs-JSDJgtyL.cjs.map → codecs-Bvmb8o9R.cjs.map} +1 -1
- package/dist/command-BUkTNNIa.cjs +9 -0
- package/dist/{command-FrwAB8R3.cjs.map → command-BUkTNNIa.cjs.map} +1 -1
- package/dist/{consent-manager-Dpgb-BKQ.cjs → consent-manager-Df8gw2Qh.cjs} +2 -2
- package/dist/{consent-manager-Dpgb-BKQ.cjs.map → consent-manager-Df8gw2Qh.cjs.map} +1 -1
- package/dist/constants-7qBywLgI.cjs +2 -0
- package/dist/{constants-CmHjougS.cjs.map → constants-7qBywLgI.cjs.map} +1 -1
- package/dist/context-_8xfl0dt.cjs +2 -0
- package/dist/{context-Bw1xk9Q_.cjs.map → context-_8xfl0dt.cjs.map} +1 -1
- package/dist/{cron-Cug8byEO.cjs → cron-BhfbISdy.cjs} +2 -2
- package/dist/{cron-Cug8byEO.cjs.map → cron-BhfbISdy.cjs.map} +1 -1
- package/dist/{data-inventory-oLLOqkbm.cjs → data-inventory-D36n1YAJ.cjs} +2 -2
- package/dist/{data-inventory-oLLOqkbm.cjs.map → data-inventory-D36n1YAJ.cjs.map} +1 -1
- package/dist/{dataFlowsToDataSilos-BjIfea8i.cjs → dataFlowsToDataSilos-BLNhWeOw.cjs} +2 -2
- package/dist/{dataFlowsToDataSilos-BjIfea8i.cjs.map → dataFlowsToDataSilos-BLNhWeOw.cjs.map} +1 -1
- package/dist/{done-input-validation-Cgk5kNBs.cjs → done-input-validation-DGckEJ5a.cjs} +1 -1
- package/dist/{done-input-validation-Cgk5kNBs.cjs.map → done-input-validation-DGckEJ5a.cjs.map} +1 -1
- package/dist/enums-BZulhPFa.cjs +2 -0
- package/dist/{enums-CBXlBJii.cjs.map → enums-BZulhPFa.cjs.map} +1 -1
- package/dist/impl--CgaKM4x.cjs +2 -0
- package/dist/{impl-C4VIGK1G.cjs.map → impl--CgaKM4x.cjs.map} +1 -1
- package/dist/impl--PmMYd1g.cjs +2 -0
- package/dist/{impl-cFJaGYul.cjs.map → impl--PmMYd1g.cjs.map} +1 -1
- package/dist/impl-47WGWxyj.cjs +2 -0
- package/dist/{impl-CKCV2er8.cjs.map → impl-47WGWxyj.cjs.map} +1 -1
- package/dist/impl-4NCrJ_Y6.cjs +2 -0
- package/dist/{impl-Dwd8vWoq.cjs.map → impl-4NCrJ_Y6.cjs.map} +1 -1
- package/dist/impl-5AfPlpzA.cjs +2 -0
- package/dist/{impl-Emn0jZNk.cjs.map → impl-5AfPlpzA.cjs.map} +1 -1
- package/dist/impl-73q3K0b_.cjs +2 -0
- package/dist/{impl-BN61r-PG.cjs.map → impl-73q3K0b_.cjs.map} +1 -1
- package/dist/impl-8Basu9U-.cjs +2 -0
- package/dist/{impl-Ij4ebiVO.cjs.map → impl-8Basu9U-.cjs.map} +1 -1
- package/dist/impl-BC1mCUl1.cjs +2 -0
- package/dist/{impl-C1jpyDxO.cjs.map → impl-BC1mCUl1.cjs.map} +1 -1
- package/dist/impl-BNEgHNz7.cjs +4 -0
- package/dist/{impl-B4f6W0BP.cjs.map → impl-BNEgHNz7.cjs.map} +1 -1
- package/dist/impl-BPq8EyHn.cjs +2 -0
- package/dist/{impl-BABdXCjW.cjs.map → impl-BPq8EyHn.cjs.map} +1 -1
- package/dist/impl-BfN9XMNM.cjs +2 -0
- package/dist/{impl-BqwFuOOo.cjs.map → impl-BfN9XMNM.cjs.map} +1 -1
- package/dist/impl-Boa1Uuzk.cjs +2 -0
- package/dist/{impl-DuVC84LE.cjs.map → impl-Boa1Uuzk.cjs.map} +1 -1
- package/dist/impl-Bv2mYf1w.cjs +2 -0
- package/dist/{impl-CCPd6sqk.cjs.map → impl-Bv2mYf1w.cjs.map} +1 -1
- package/dist/impl-BxOeeF35.cjs +2 -0
- package/dist/{impl-TTDhp7Hu.cjs.map → impl-BxOeeF35.cjs.map} +1 -1
- package/dist/impl-ByQI5s4b.cjs +2 -0
- package/dist/{impl-D9_MKLLL.cjs.map → impl-ByQI5s4b.cjs.map} +1 -1
- package/dist/impl-C1IjDv1N.cjs +2 -0
- package/dist/{impl-Bm8T2x0z.cjs.map → impl-C1IjDv1N.cjs.map} +1 -1
- package/dist/impl-CVsXgVaf.cjs +2 -0
- package/dist/{impl-DLeBB5Zk.cjs.map → impl-CVsXgVaf.cjs.map} +1 -1
- package/dist/impl-CdXk78ar.cjs +2 -0
- package/dist/{impl-CXnE8Ev7.cjs.map → impl-CdXk78ar.cjs.map} +1 -1
- package/dist/impl-CfsKuglq.cjs +2 -0
- package/dist/{impl-BtfHdJB-.cjs.map → impl-CfsKuglq.cjs.map} +1 -1
- package/dist/impl-CkkD_smS.cjs +2 -0
- package/dist/{impl-D1MnxAqp.cjs.map → impl-CkkD_smS.cjs.map} +1 -1
- package/dist/impl-Cotrjytz.cjs +2 -0
- package/dist/{impl-TDjUVCrV.cjs.map → impl-Cotrjytz.cjs.map} +1 -1
- package/dist/impl-Crhm9eFe.cjs +2 -0
- package/dist/{impl-CeoJtFk7.cjs.map → impl-Crhm9eFe.cjs.map} +1 -1
- package/dist/impl-Cru4riTc.cjs +5 -0
- package/dist/impl-Cru4riTc.cjs.map +1 -0
- package/dist/impl-D2P_gDE8.cjs +2 -0
- package/dist/{impl-JkokB3Un.cjs.map → impl-D2P_gDE8.cjs.map} +1 -1
- package/dist/{impl-BnkpDlXg.cjs → impl-DDHduv-X.cjs} +2 -2
- package/dist/{impl-BnkpDlXg.cjs.map → impl-DDHduv-X.cjs.map} +1 -1
- package/dist/impl-DEULjxRp.cjs +2 -0
- package/dist/{impl-Dsj6D_fG.cjs.map → impl-DEULjxRp.cjs.map} +1 -1
- package/dist/impl-DHUnZ-Qx.cjs +2 -0
- package/dist/{impl-Ym65hOwf.cjs.map → impl-DHUnZ-Qx.cjs.map} +1 -1
- package/dist/impl-DI3lTLCy.cjs +2 -0
- package/dist/{impl-DJMqsQ7L.cjs.map → impl-DI3lTLCy.cjs.map} +1 -1
- package/dist/impl-DKMxd5Wy.cjs +2 -0
- package/dist/{impl-DEsdC5Z4.cjs.map → impl-DKMxd5Wy.cjs.map} +1 -1
- package/dist/impl-DNDs3FFG.cjs +2 -0
- package/dist/{impl-rYMBoT4c.cjs.map → impl-DNDs3FFG.cjs.map} +1 -1
- package/dist/impl-DQTfX_qq.cjs +4 -0
- package/dist/{impl-Cq9g8eCi.cjs.map → impl-DQTfX_qq.cjs.map} +1 -1
- package/dist/impl-DS2IlxS3.cjs +2 -0
- package/dist/{impl-BYBww_ic.cjs.map → impl-DS2IlxS3.cjs.map} +1 -1
- package/dist/impl-DVCUGrVY.cjs +2 -0
- package/dist/{impl-CA649Byw.cjs.map → impl-DVCUGrVY.cjs.map} +1 -1
- package/dist/{impl-B19iyoiR.cjs → impl-DZbi3AkB.cjs} +2 -2
- package/dist/{impl-B19iyoiR.cjs.map → impl-DZbi3AkB.cjs.map} +1 -1
- package/dist/impl-DcMkDhXY.cjs +2 -0
- package/dist/{impl-9qObj_On.cjs.map → impl-DcMkDhXY.cjs.map} +1 -1
- package/dist/impl-DlB56v12.cjs +2 -0
- package/dist/{impl--0AUtPOO.cjs.map → impl-DlB56v12.cjs.map} +1 -1
- package/dist/impl-Du1Ty4JE.cjs +2 -0
- package/dist/{impl-CWLtV0NB.cjs.map → impl-Du1Ty4JE.cjs.map} +1 -1
- package/dist/{impl-BzfO2Fr-.cjs → impl-DxDGyjMI.cjs} +2 -2
- package/dist/{impl-BzfO2Fr-.cjs.map → impl-DxDGyjMI.cjs.map} +1 -1
- package/dist/impl-Dxgw6Xfk.cjs +2 -0
- package/dist/{impl-3XEvFo-7.cjs.map → impl-Dxgw6Xfk.cjs.map} +1 -1
- package/dist/impl-IQ7JOZxt.cjs +2 -0
- package/dist/{impl-DbD3dI7B.cjs.map → impl-IQ7JOZxt.cjs.map} +1 -1
- package/dist/impl-bgI-lF8x.cjs +2 -0
- package/dist/{impl-1ibTRBn4.cjs.map → impl-bgI-lF8x.cjs.map} +1 -1
- package/dist/impl-feFIqpBO.cjs +2 -0
- package/dist/{impl-CCuP7d9d.cjs.map → impl-feFIqpBO.cjs.map} +1 -1
- package/dist/impl-orpaJd8b.cjs +12 -0
- package/dist/{impl-CKASqgZA.cjs.map → impl-orpaJd8b.cjs.map} +1 -1
- package/dist/{impl-Bd239j4R.cjs → impl-xUzH7vUF.cjs} +2 -2
- package/dist/{impl-Bd239j4R.cjs.map → impl-xUzH7vUF.cjs.map} +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -9
- package/dist/{logger-BaHHbWVd.cjs → logger-DQwEYtSS.cjs} +2 -2
- package/dist/{logger-BaHHbWVd.cjs.map → logger-DQwEYtSS.cjs.map} +1 -1
- package/dist/{manual-enrichment-Cz9Cb_fJ.cjs → manual-enrichment-CzRiIFev.cjs} +2 -2
- package/dist/{manual-enrichment-Cz9Cb_fJ.cjs.map → manual-enrichment-CzRiIFev.cjs.map} +1 -1
- package/dist/{mergeTranscendInputs-PPpGbYgG.cjs → mergeTranscendInputs-BIBCYbug.cjs} +2 -2
- package/dist/{mergeTranscendInputs-PPpGbYgG.cjs.map → mergeTranscendInputs-BIBCYbug.cjs.map} +1 -1
- package/dist/{pooling-C9Q0E6d3.cjs → pooling-BJAPXDiq.cjs} +2 -2
- package/dist/{pooling-C9Q0E6d3.cjs.map → pooling-BJAPXDiq.cjs.map} +1 -1
- package/dist/{preference-management-DhMwul_r.cjs → preference-management-DV6NIcXt.cjs} +4 -4
- package/dist/preference-management-DV6NIcXt.cjs.map +1 -0
- package/dist/{readTranscendYaml-CL9nujUr.cjs → readTranscendYaml-Cycz6RxW.cjs} +2 -2
- package/dist/{readTranscendYaml-CL9nujUr.cjs.map → readTranscendYaml-Cycz6RxW.cjs.map} +1 -1
- package/dist/syncConfigurationToTranscend-Bd0ZTIm1.cjs +2994 -0
- package/dist/{syncConfigurationToTranscend-Drb8I8lD.cjs.map → syncConfigurationToTranscend-Bd0ZTIm1.cjs.map} +1 -1
- package/dist/{uploadConsents-Y2WZFgxP.cjs → uploadConsents-XYRco1_L.cjs} +2 -2
- package/dist/{uploadConsents-Y2WZFgxP.cjs.map → uploadConsents-XYRco1_L.cjs.map} +1 -1
- package/package.json +1 -1
- package/dist/app-CnSMU1Jq.cjs +0 -118
- package/dist/app-CnSMU1Jq.cjs.map +0 -1
- package/dist/buildAIIntegrationType-n_Qlv8wG.cjs +0 -2
- package/dist/codecs-JSDJgtyL.cjs +0 -2
- package/dist/command-FrwAB8R3.cjs +0 -9
- package/dist/constants-CmHjougS.cjs +0 -2
- package/dist/context-Bw1xk9Q_.cjs +0 -2
- package/dist/enums-CBXlBJii.cjs +0 -2
- package/dist/impl--0AUtPOO.cjs +0 -2
- package/dist/impl-1ibTRBn4.cjs +0 -2
- package/dist/impl-3XEvFo-7.cjs +0 -2
- package/dist/impl-9qObj_On.cjs +0 -2
- package/dist/impl-B4f6W0BP.cjs +0 -4
- package/dist/impl-BABdXCjW.cjs +0 -2
- package/dist/impl-BN61r-PG.cjs +0 -2
- package/dist/impl-BYBww_ic.cjs +0 -2
- package/dist/impl-Bm8T2x0z.cjs +0 -2
- package/dist/impl-BqwFuOOo.cjs +0 -2
- package/dist/impl-BtfHdJB-.cjs +0 -2
- package/dist/impl-C1jpyDxO.cjs +0 -2
- package/dist/impl-C4VIGK1G.cjs +0 -2
- package/dist/impl-CA649Byw.cjs +0 -2
- package/dist/impl-CCPd6sqk.cjs +0 -2
- package/dist/impl-CCuP7d9d.cjs +0 -2
- package/dist/impl-CKASqgZA.cjs +0 -12
- package/dist/impl-CKCV2er8.cjs +0 -2
- package/dist/impl-CWLtV0NB.cjs +0 -2
- package/dist/impl-CXnE8Ev7.cjs +0 -2
- package/dist/impl-CeoJtFk7.cjs +0 -2
- package/dist/impl-Cq9g8eCi.cjs +0 -4
- package/dist/impl-D1MnxAqp.cjs +0 -2
- package/dist/impl-D9_MKLLL.cjs +0 -2
- package/dist/impl-DEsdC5Z4.cjs +0 -2
- package/dist/impl-DJMqsQ7L.cjs +0 -2
- package/dist/impl-DLeBB5Zk.cjs +0 -2
- package/dist/impl-DbD3dI7B.cjs +0 -2
- package/dist/impl-Dsj6D_fG.cjs +0 -2
- package/dist/impl-DuVC84LE.cjs +0 -2
- package/dist/impl-Dwd8vWoq.cjs +0 -2
- package/dist/impl-Emn0jZNk.cjs +0 -2
- package/dist/impl-Ij4ebiVO.cjs +0 -2
- package/dist/impl-JkokB3Un.cjs +0 -2
- package/dist/impl-TDjUVCrV.cjs +0 -2
- package/dist/impl-TTDhp7Hu.cjs +0 -2
- package/dist/impl-Ym65hOwf.cjs +0 -2
- package/dist/impl-cFJaGYul.cjs +0 -2
- package/dist/impl-rYMBoT4c.cjs +0 -2
- package/dist/preference-management-DhMwul_r.cjs.map +0 -1
- package/dist/syncConfigurationToTranscend-Drb8I8lD.cjs +0 -2994
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["makeGraphQLRequest","LARGE_LANGUAGE_MODELS","DEFAULT_TRANSCEND_API","buildTranscendGraphQLClient","uniq","agentNames","fetchPromptsWithVariables","fetchAllAgents","keyBy","name","fetchAllPromptThreads","groupBy","chunk","mapSeries","fetchAllAgentFiles","PromptStatus","ChatCompletionRole","reportPromptRun","PromptRunProductArea","QueueStatus","difference","fastGlob"],"sources":["../src/lib/graphql/fetchLargeLanguageModels.ts","../src/lib/ai/TranscendPromptManager.ts","../src/lib/ai/removeLinks.ts","../src/lib/ai/filterNullishValuesFromObject.ts","../src/lib/ai/getGitFilesThatChanged.ts"],"sourcesContent":["import { GraphQLClient } from 'graphql-request';\nimport { LargeLanguageModelClient } from '@transcend-io/privacy-types';\nimport { LARGE_LANGUAGE_MODELS } from './gqls';\nimport { makeGraphQLRequest } from './makeGraphQLRequest';\n\nexport interface LargeLanguageModel {\n /** ID of prompts */\n id: string;\n /** The name of the large language model. */\n name: string;\n /** The content of the prompt template. */\n client: LargeLanguageModelClient;\n /** Whether hosted by Transcend or not */\n isTranscendHosted: boolean;\n}\n\nconst PAGE_SIZE = 20;\n\n/**\n * Fetch all LargeLanguageModels in the organization\n *\n * @param client - GraphQL client\n * @returns All LargeLanguageModels in the organization\n */\nexport async function fetchAllLargeLanguageModels(\n client: GraphQLClient,\n): Promise<LargeLanguageModel[]> {\n const largeLanguageModels: LargeLanguageModel[] = [];\n let offset = 0;\n\n // Whether to continue looping\n let shouldContinue = false;\n do {\n const {\n largeLanguageModels: { nodes },\n } = await makeGraphQLRequest<{\n /** LargeLanguageModels */\n largeLanguageModels: {\n /** List */\n nodes: LargeLanguageModel[];\n };\n }>(client, LARGE_LANGUAGE_MODELS, {\n first: PAGE_SIZE,\n offset,\n });\n largeLanguageModels.push(...nodes);\n offset += PAGE_SIZE;\n shouldContinue = nodes.length === PAGE_SIZE;\n } while (shouldContinue);\n\n return largeLanguageModels.sort((a, b) => a.name.localeCompare(b.name));\n}\n","/* eslint-disable max-lines */\nimport {\n Optionalize,\n Requirize,\n apply,\n decodeCodec,\n getValues,\n} from '@transcend-io/type-utils';\nimport type { Handlebars } from '@transcend-io/handlebars-utils';\nimport { Secret } from '@transcend-io/secret-value';\nimport * as t from 'io-ts';\nimport { DEFAULT_TRANSCEND_API } from '../../constants';\nimport {\n Agent,\n AgentFile,\n AgentFileFilterBy,\n ReportPromptRunInput,\n buildTranscendGraphQLClient,\n fetchAllAgentFiles,\n fetchAllAgents,\n reportPromptRun,\n} from '../graphql';\nimport {\n HandlebarsInput,\n createHandlebarsWithHelpers,\n} from '@transcend-io/handlebars-utils';\nimport {\n TranscendPromptTemplated,\n TranscendPromptsAndVariables,\n fetchPromptsWithVariables,\n} from '../graphql/fetchPrompts';\nimport { GraphQLClient } from 'graphql-request';\nimport {\n PromptStatus,\n ChatCompletionRole,\n PromptRunProductArea,\n QueueStatus,\n LargeLanguageModelClient,\n} from '@transcend-io/privacy-types';\nimport {\n LargeLanguageModel,\n fetchAllLargeLanguageModels,\n} from '../graphql/fetchLargeLanguageModels';\nimport { groupBy, keyBy, uniq, chunk } from 'lodash-es';\nimport { mapSeries } from '../bluebird';\nimport {\n PromptThread,\n fetchAllPromptThreads,\n} from '../graphql/fetchPromptThreads';\n\n/**\n * An LLM Prompt definition\n */\nexport type TranscendPrompt<\n TInputParams extends t.Any,\n TOutputCodec extends t.Any,\n> = (\n | {\n /** ID of the prompt */\n id: string;\n /** Title of the prompt */\n title?: string;\n }\n | {\n /** ID of the prompt */\n id?: string;\n /** Title of the prompt */\n title: string;\n }\n) & {\n /** The names of the agents that should be loaded along with the prompt */\n agentNames?: string[];\n /** Codec to validate runtime input shape */\n paramCodec: TInputParams;\n /** Codec to validate output response */\n outputCodec: TOutputCodec;\n /**\n * If the output that needs to be parsed is returned within a tag\n * e.g. <tag> or <json> - this is the name of the tag\n */\n extractFromTag?: string;\n};\n\nexport interface PromptRunResult {\n /** The ID of the prompt run created on Transcend */\n promptRunId: string;\n /** The URL of the prompt run on Transcend */\n promptRunUrl: string;\n}\n\n/**\n * Create a regex to extract data from a tag\n *\n * Input:\n * \"here is some data <tag>Data</tag>...\"\n *\n * @param tagName - Name of tag\n * @returns Data within the tag\n */\nexport function createRegexForTag(tagName: string): RegExp {\n return new RegExp(`<${tagName}>([\\\\s\\\\S]+?)<\\\\/${tagName}>`);\n}\n\n/**\n * Helper function to declare prompts\n *\n * @param prompts - Prompt config\n * @returns Prompts as identity function - but type enforced\n */\nexport function defineTranscendPrompts<\n TPromptNames extends string,\n TPrompts extends { [k in TPromptNames]: TranscendPrompt<t.Any, t.Any> },\n>(prompts: TPrompts): TPrompts {\n return prompts;\n}\n\n/**\n * Helper to get the type of the parameter for a given prompt\n */\nexport type GetPromptParamType<\n TPromptName extends keyof TPrompts,\n TPrompts extends { [k in TPromptName]: TranscendPrompt<t.Any, t.Any> },\n> = t.TypeOf<TPrompts[TPromptName]['paramCodec']>;\n\n/**\n * Helper to get the type of the parameter for a given prompt\n */\nexport type GetPromptResponseType<\n TPromptName extends keyof TPrompts,\n TPrompts extends { [k in TPromptName]: TranscendPrompt<t.Any, t.Any> },\n> = t.TypeOf<TPrompts[TPromptName]['outputCodec']>;\n\n/**\n * Input for reporting a prompt run\n */\nexport interface ReportPromptRunOptions\n extends Optionalize<\n Omit<ReportPromptRunInput, 'status' | 'promptId' | 'largeLanguageModelId'>,\n 'name' | 'productArea'\n > {\n /** The large language model being run. Either the ID of the LLM or the client/name pairing */\n largeLanguageModel:\n | string\n | {\n /** Name of client */\n client: LargeLanguageModelClient;\n /** Name of the model */\n name: string;\n };\n}\n\nconst jsonParseSafe = (obj: string): unknown => {\n try {\n return JSON.parse(obj);\n } catch (e) {\n return obj;\n }\n};\n\n/**\n * A class that is capable of loading and insert variables into prompts from\n * Transcend's Prompt Manager\n */\nexport class TranscendPromptManager<\n TPromptNames extends string,\n TPrompts extends { [k in TPromptNames]: TranscendPrompt<t.Any, t.Any> },\n> {\n /** Prompt definitions */\n public prompts: TPrompts;\n\n /** Options for configuring handlebars */\n public handlebarsOptions!: HandlebarsInput;\n\n /** Prompt name -> content map, populated by call to Transcend API */\n public promptContentMap?: { [k in TPromptNames]: TranscendPromptTemplated };\n\n /** The large language models that are registered to this organization for reporting */\n public largeLanguageModels: LargeLanguageModel[] = [];\n\n /** The agent definitions registered to this organization */\n private agentsByName: { [name in string]: Agent } = {};\n\n /** The agent definitions registered to this organization */\n private agentsByAgentId: { [id in string]: Agent } = {};\n\n /** The GraphQL client that can be used to call Transcend */\n public graphQLClient: GraphQLClient;\n\n /** The set of variables to expose in handlebars context specified at class initiation */\n public defaultVariables: { [k in string]: unknown };\n\n /**\n * The set of variables to expose in handlebars context,\n * merges defaults with calculated variables from the inventory\n */\n public variables: { [k in string]: unknown };\n\n /** Handlebars compiler */\n public handlebars: typeof Handlebars;\n\n /** The Transcend API key */\n public transcendApiKey: string | Secret<string>;\n\n /** API of Transcend to call */\n public transcendUrl: string;\n\n /** When true, throw an error if the prompt is not approved */\n public requireApproval: boolean;\n\n /**\n * The cache duration in ms for how long prompts and associated metadata should be cached\n * When undefined - prompts are cached indefinitely unless explicitly re-requested\n * When 0, prompts and metadata are fetched every time (not recommended)\n * Setting this to be an hour is a good rate that optimizes for performance and keeping up to date\n */\n public cacheDuration?: number;\n\n /**\n * The last time the metadata was fetched\n */\n public lastUpdatedAt?: Date;\n\n /**\n * Constructor\n *\n * @param options - Options\n */\n constructor({\n prompts,\n handlebarsOptions = {},\n transcendUrl = DEFAULT_TRANSCEND_API,\n transcendApiKey,\n requireApproval = true,\n cacheDuration,\n defaultVariables = {},\n }: {\n /** Prompt definitions to load */\n prompts: TPrompts;\n /** Options for configuring handlebars */\n handlebarsOptions?: HandlebarsInput;\n /** The Transcend API key */\n transcendApiKey: string | Secret<string>;\n /** API of Transcend to call */\n transcendUrl?: string;\n /** When true, throw an error if the prompt is not approved */\n requireApproval?: boolean;\n /** The set of variables to expose in handlebars context specified at class initiation */\n defaultVariables?: { [k in string]: unknown };\n /**\n * The cache duration in ms for how long prompts and associated metadata should be cached\n * When undefined - prompts are cached indefinitely unless explicitly re-requested\n * When 0, prompts and metadata are fetched every time (not recommended)\n * Setting this to be an hour is a good rate that optimizes for performance and keeping up to date\n */\n cacheDuration?: number;\n }) {\n this.prompts = prompts;\n this.transcendUrl = transcendUrl;\n this.transcendApiKey = transcendApiKey;\n this.variables = defaultVariables;\n this.defaultVariables = defaultVariables;\n this.graphQLClient = buildTranscendGraphQLClient(\n transcendUrl,\n typeof transcendApiKey === 'object'\n ? transcendApiKey.release()\n : transcendApiKey,\n );\n this.requireApproval = requireApproval;\n this.cacheDuration = cacheDuration;\n this.handlebarsOptions = handlebarsOptions;\n this.handlebars = createHandlebarsWithHelpers(handlebarsOptions);\n }\n\n /**\n * Fetch prompt metadata from Transcend and cache to the class definition\n *\n * @returns A function that can be used to call the prompt\n */\n async fetchPromptsAndMetadata(): Promise<TranscendPromptsAndVariables> {\n // Determine what to fetch\n const promptDefinitions = getValues(this.prompts) as TranscendPrompt<\n t.Any,\n t.Any\n >[];\n const promptIds = promptDefinitions\n .map(({ id }) => id)\n .filter((x): x is string => !!x);\n const promptTitles = promptDefinitions\n .map(({ title }) => title)\n .filter((x): x is string => !!x);\n const agentNames = uniq(\n promptDefinitions.map(({ agentNames }) => agentNames || []).flat(),\n );\n\n // Fetch prompts and data\n const [response, largeLanguageModels, agents] = await Promise.all([\n fetchPromptsWithVariables(this.graphQLClient, {\n promptIds,\n promptTitles,\n }),\n fetchAllLargeLanguageModels(this.graphQLClient),\n fetchAllAgents(this.graphQLClient, { names: agentNames }),\n ]);\n this.agentsByName = keyBy(agents, 'name');\n this.agentsByAgentId = keyBy(agents, 'agentId');\n this.largeLanguageModels = largeLanguageModels.filter(\n (model) => model.isTranscendHosted === false,\n );\n\n // Lookup prompts by id/title\n const promptByTitle = keyBy(response.prompts, 'title');\n const promptById = keyBy(response.prompts, 'id');\n\n // Update variables\n this.variables = {\n ...response.calculatedVariables.reduce(\n (acc, v) =>\n Object.assign(acc, {\n [v.name]: v.data ? JSON.parse(v.data) : v.data,\n }),\n {},\n ),\n ...this.defaultVariables,\n };\n\n // Update partials\n this.handlebars = createHandlebarsWithHelpers({\n ...this.handlebarsOptions,\n templates: [\n ...(this.handlebarsOptions.templates || []),\n ...response.promptPartials.map((partial) => ({\n name: partial.slug,\n content: partial.content,\n })),\n ],\n });\n\n // Create mapping from prompt to content\n this.promptContentMap = apply(this.prompts, ({ id, title }) => {\n const result = id\n ? promptById[id]\n : title\n ? promptByTitle[title]\n : undefined;\n if (!result) {\n throw new Error(\n `Failed to find prompt with title: \"${title}\" and id: \"${id}\"`,\n );\n }\n return result;\n });\n\n // For cache\n this.lastUpdatedAt = new Date();\n\n return response;\n }\n\n /**\n * Get an agent definition by name\n *\n * @param name - Name of the agent to grab\n * @returns Large language model configuration\n */\n async getAgentByName(name: string): Promise<Agent | undefined> {\n const agent = this.agentsByName[name];\n if (agent) {\n return agent;\n }\n const [remoteAgent] = await fetchAllAgents(this.graphQLClient, {\n names: [name],\n });\n if (!remoteAgent) {\n return undefined;\n }\n this.agentsByName[remoteAgent.name] = remoteAgent;\n this.agentsByAgentId[remoteAgent.agentId] = remoteAgent;\n return remoteAgent;\n }\n\n /**\n * Get a prompt thread by ts\n *\n * @param ts - the slack message timestamp to look up thread for\n * @returns Large language model configuration\n */\n async getPromptThreadBySlackTs(\n ts: string,\n ): Promise<PromptThread | undefined> {\n const [thread] = await fetchAllPromptThreads(this.graphQLClient, {\n slackMessageTs: [ts],\n });\n return thread;\n }\n\n /**\n * Get a list of agent definitions by name.\n * Pulls from cache and may return less agents\n * than requested if some are not found\n *\n * @param names - Names of agents to fetch\n * @returns The agents that were found matching the names\n */\n async getAgentsByName(names: string[]): Promise<Agent[]> {\n if (names.length < 1) {\n throw new Error('Expected at least one name to be provided');\n }\n const { hasCache = [], missingCache = [] } = groupBy(names, (name) =>\n this.agentsByName[name] ? 'hasCache' : 'missingCache',\n );\n const cachedAgents = hasCache.map((name) => this.agentsByName[name]);\n if (missingCache.length === 0) {\n return cachedAgents;\n }\n const chunkedNames = chunk(missingCache, 50);\n const remoteAgents: Agent[] = [];\n await mapSeries(chunkedNames, async (chunkedName) => {\n const pageOfAgents = await fetchAllAgents(this.graphQLClient, {\n names: chunkedName,\n });\n pageOfAgents.forEach((agent) => {\n this.agentsByName[agent.name] = agent;\n this.agentsByAgentId[agent.agentId] = agent;\n });\n remoteAgents.push(...pageOfAgents);\n });\n return [...cachedAgents, ...remoteAgents];\n }\n\n /**\n * Fetch metadata on agent files\n *\n * @param filterBy - Filter by parameters\n * @returns The files found matching the filter\n */\n getAgentFiles(filterBy: AgentFileFilterBy): Promise<AgentFile[]> {\n return fetchAllAgentFiles(this.graphQLClient, filterBy);\n }\n\n /**\n * Look up the large language model to report on\n *\n * @param largeLanguageModel - Input\n * @returns Large language model configuration\n */\n getLargeLanguageModel(\n largeLanguageModel: ReportPromptRunOptions['largeLanguageModel'],\n ): LargeLanguageModel {\n const matching = this.largeLanguageModels.find((model) =>\n typeof largeLanguageModel === 'string'\n ? model.id === largeLanguageModel\n : model.name === largeLanguageModel.name &&\n model.client === largeLanguageModel.client,\n );\n if (!matching) {\n throw new Error(\n `Failed to find model matching: ${\n typeof largeLanguageModel === 'string'\n ? largeLanguageModel\n : JSON.stringify(largeLanguageModel)\n }`,\n );\n }\n return matching;\n }\n\n /**\n * Get a prompt definition by name\n *\n * @param promptName - Prompt to compile\n * @returns Parsed content\n */\n async getPromptDefinition<TPromptName extends TPromptNames>(\n promptName: TPromptName,\n ): Promise<TranscendPromptTemplated> {\n // Determine if prompts need to be fetched\n if (\n // never been fetched\n !this.lastUpdatedAt ||\n // fetch every run\n this.cacheDuration === 0 ||\n // If cache duration met\n (this.cacheDuration &&\n Date.now() - this.lastUpdatedAt.getTime() > this.cacheDuration)\n ) {\n await this.fetchPromptsAndMetadata();\n }\n\n // Lookup prompt\n const { promptContentMap } = this;\n if (!promptContentMap) {\n throw new Error('Expected this.promptContentMap to be defined');\n }\n const promptTemplate = promptContentMap[promptName];\n if (!promptTemplate) {\n throw new Error(\n `Expected this.promptContentMap[${promptName}] to be defined`,\n );\n }\n return promptTemplate;\n }\n\n /**\n * Validate the shape of the response from AI\n *\n * @param promptName - Prompt to compile\n * @param params - Runtime parameters\n * @returns Parsed content\n */\n async compilePrompt<TPromptName extends TPromptNames>(\n promptName: TPromptName,\n params: t.TypeOf<TPrompts[TPromptName]['paramCodec']>,\n ): Promise<string> {\n // Grab the prompt\n const promptTemplate = await this.getPromptDefinition(promptName);\n const promptInput = this.prompts[promptName];\n if (!promptInput) {\n throw new Error(`Expected this.prompts[${promptName}] to be defined`);\n }\n\n // Ensure prompt is approved\n if (\n this.requireApproval &&\n promptTemplate.status !== PromptStatus.Approved\n ) {\n throw new Error(\n `Assessment \"${promptTemplate.title}\" cannot be used because its in status: \"${promptTemplate.status}\"`,\n );\n }\n\n // If prompt is rejected, throw error\n if (promptTemplate.status === PromptStatus.Rejected) {\n throw new Error(\n `Assessment \"${promptTemplate.title}\" cannot be used because it's in status: \"${promptTemplate.status}\"`,\n );\n }\n\n // Validate params\n decodeCodec(promptInput.paramCodec, params);\n\n // Compile prompt and template\n return this.handlebars.compile(promptTemplate.content)({\n // template in currentDate by default\n currentDate: new Date().toISOString(),\n ...this.variables,\n ...params,\n });\n }\n\n /**\n * Validate the shape of the response from AI\n *\n * @param promptName - Prompt to parse\n * @param response - AI response as string\n * @returns Parsed content\n */\n parseAiResponse<TPromptName extends TPromptNames>(\n promptName: TPromptName,\n response: string,\n ): t.TypeOf<TPrompts[TPromptName]['outputCodec']> {\n // Look up prompt info\n const promptInput = this.prompts[promptName];\n if (!promptInput) {\n throw new Error(`Expected this.prompts[${promptName}] to be defined`);\n }\n\n // Extract from tag if needed\n const extracted = promptInput.extractFromTag\n ? (createRegexForTag(promptInput.extractFromTag).exec(response) ||\n [])[1] || response\n : response;\n\n // Parse via codec\n return decodeCodec(\n promptInput.outputCodec,\n jsonParseSafe(extracted),\n false,\n );\n }\n\n /**\n * Parse the AI response and report back to Transcend\n *\n * @param promptName - Prompt to parse\n * @param options - Options for reporting\n * @returns Parsed content\n */\n async reportAndParsePromptRun<TPromptName extends TPromptNames>(\n promptName: TPromptName,\n { largeLanguageModel, ...options }: ReportPromptRunOptions,\n ): Promise<\n PromptRunResult & {\n /** Resulting prompt run */\n result: t.TypeOf<TPrompts[TPromptName]['outputCodec']>;\n }\n > {\n // Determine if prompts need to be fetched\n if (\n // never been fetched\n !this.lastUpdatedAt ||\n // fetch every run\n this.cacheDuration === 0 ||\n // If cache duration met\n (this.cacheDuration &&\n Date.now() - this.lastUpdatedAt.getTime() > this.cacheDuration)\n ) {\n await this.fetchPromptsAndMetadata();\n }\n\n const name =\n options.name ||\n `@transcend-io/cli-prompt-run-${new Date().toISOString()}`;\n\n if (!this.promptContentMap) {\n throw new Error('Expected this.promptContentMap to be defined');\n }\n // Look up prompt info\n const promptInput = this.promptContentMap[promptName];\n if (!promptInput) {\n throw new Error(`Expected this.prompts[${promptName}] to be defined`);\n }\n\n // Ensure the first message in `promptRunMessages` is of type=system\n if (options.promptRunMessages.length === 0) {\n throw new Error('promptRunMessages is expected to have length > 0');\n }\n if (options.promptRunMessages[0].role !== ChatCompletionRole.System) {\n throw new Error(\n `promptRunMessages[0].role is expected to be = ${ChatCompletionRole.System}`,\n );\n }\n if (\n options.promptRunMessages[options.promptRunMessages.length - 1].role !==\n ChatCompletionRole.Assistant\n ) {\n throw new Error(\n `promptRunMessages[${\n options.promptRunMessages.length - 1\n }].role is expected to be = ${ChatCompletionRole.Assistant}`,\n );\n }\n const response =\n options.promptRunMessages[options.promptRunMessages.length - 1].content;\n\n let parsed: t.TypeOf<TPrompts[TPromptName]['outputCodec']>;\n try {\n // Parse the response\n parsed = this.parseAiResponse(promptName, response);\n } catch (err) {\n await reportPromptRun(this.graphQLClient, {\n productArea: PromptRunProductArea.PromptManager,\n ...options,\n name,\n error: err.message,\n status: QueueStatus.Error,\n ...(typeof largeLanguageModel === 'string'\n ? { largeLanguageModelId: largeLanguageModel }\n : {\n largeLanguageModelName: largeLanguageModel.name,\n largeLanguageModelClient: largeLanguageModel.client,\n }),\n promptId: promptInput.id,\n promptRunMessages: options.promptRunMessages.map((message, ind) => ({\n ...message,\n ...(ind === 0 ? { template: promptInput.content } : {}),\n })),\n });\n throw err;\n }\n\n // report successful run\n const promptRunId = await reportPromptRun(this.graphQLClient, {\n productArea: PromptRunProductArea.PromptManager,\n ...options,\n name,\n status: QueueStatus.Resolved,\n ...(typeof largeLanguageModel === 'string'\n ? { largeLanguageModelId: largeLanguageModel }\n : {\n largeLanguageModelName: largeLanguageModel.name,\n largeLanguageModelClient: largeLanguageModel.client,\n }),\n promptId: promptInput.id,\n promptRunMessages: options.promptRunMessages.map((message, ind) => ({\n ...message,\n ...(ind === 0 ? { template: promptInput.content } : {}),\n })),\n });\n\n return {\n result: parsed,\n promptRunId,\n promptRunUrl: `https://app.transcend.io/prompts/runs/${promptRunId}`,\n };\n }\n\n /**\n * Report an error for a particular prompt\n *\n * @param promptName - Prompt to parse\n * @param options - Options for reporting\n * @returns Parsed content\n */\n async reportPromptRunError<TPromptName extends TPromptNames>(\n promptName: TPromptName,\n {\n largeLanguageModel,\n ...options\n }: Requirize<ReportPromptRunOptions, 'error'>,\n ): Promise<PromptRunResult> {\n // Determine if prompts need to be fetched\n if (\n // never been fetched\n !this.lastUpdatedAt ||\n // fetch every run\n this.cacheDuration === 0 ||\n // If cache duration met\n (this.cacheDuration &&\n Date.now() - this.lastUpdatedAt.getTime() > this.cacheDuration)\n ) {\n await this.fetchPromptsAndMetadata();\n }\n\n const name =\n options.name ||\n `@transcend-io/cli-prompt-run-${new Date().toISOString()}`;\n\n if (!this.promptContentMap) {\n throw new Error('Expected this.promptContentMap to be defined');\n }\n // Look up prompt info\n const promptInput = this.promptContentMap[promptName];\n if (!promptInput) {\n throw new Error(`Expected this.prompts[${promptName}] to be defined`);\n }\n\n // Ensure the first message in `promptRunMessages` is of type=system\n if (options.promptRunMessages.length === 0) {\n throw new Error('promptRunMessages is expected to have length > 0');\n }\n if (options.promptRunMessages[0].role !== ChatCompletionRole.System) {\n throw new Error(\n `promptRunMessages[0].role is expected to be = ${ChatCompletionRole.System}`,\n );\n }\n\n const promptRunId = await reportPromptRun(this.graphQLClient, {\n productArea: PromptRunProductArea.PromptManager,\n ...options,\n name,\n status: QueueStatus.Error,\n ...(typeof largeLanguageModel === 'string'\n ? { largeLanguageModelId: largeLanguageModel }\n : {\n largeLanguageModelName: largeLanguageModel.name,\n largeLanguageModelClient: largeLanguageModel.client,\n }),\n promptId: promptInput.id,\n promptRunMessages: options.promptRunMessages.map((message, ind) => ({\n ...message,\n ...(ind === 0 ? { template: promptInput.content } : {}),\n })),\n });\n\n return {\n promptRunId,\n promptRunUrl: `https://app.transcend.io/prompts/runs/${promptRunId}`,\n };\n }\n}\n/* eslint-enable max-lines */\n","/**\n * Remove links from a string\n *\n * @param inputString - String\n * @returns String without links\n */\nexport function removeLinks(inputString: string): string {\n const regex = /(https?:\\/\\/[^\\s]+)/g;\n return inputString.replace(regex, '<link-omitted>');\n}\n","import { ObjByString } from '@transcend-io/type-utils';\n\n/**\n * Given an object, remove all keys that are null-ish\n *\n * @param obj - Object\n * @returns Object with null-ish values removed\n */\nexport function filterNullishValuesFromObject<T extends ObjByString>(\n obj: T,\n): T {\n return Object.entries(obj).reduce(\n (acc, [k, v]) =>\n v !== null &&\n v !== undefined &&\n v !== '' &&\n !(Array.isArray(v) && v.length === 0) &&\n !(typeof v === 'object' && Object.keys(v).length === 0)\n ? Object.assign(acc, { [k]: v })\n : acc,\n {} as T,\n );\n}\n","import { difference } from 'lodash-es';\nimport fastGlob from 'fast-glob';\nimport { execSync } from 'child_process';\n\n/**\n * Function thats gets the git files that have changed\n * and returns the code\n *\n * @param options - Options\n * @returns Changes files and diffs\n */\nexport function getGitFilesThatChanged({\n baseBranch,\n rootDirectory,\n githubRepo,\n excludedGlob = [],\n fileBlockList = [],\n}: {\n /** Base branch */\n baseBranch: string;\n /** Github repo name */\n githubRepo: string;\n /** Root directory */\n rootDirectory: string;\n /** A glob that excludes files */\n excludedGlob?: string[];\n /** Block list of files to not process */\n fileBlockList?: string[];\n}): {\n /** The list of files that changed */\n changedFiles: string[];\n /** Github repo name */\n repoName: string;\n /** Current commit */\n commit: string;\n /** File diffs */\n fileDiffs: { [k in string]: string };\n} {\n // Pull base branch\n execSync(`git fetch origin ${baseBranch}`);\n\n // Latest commit on base branch. If we are on the base branch, we take the prior commit\n const latestBasedCommit = execSync(\n `git ls-remote ${githubRepo} \"refs/heads/${baseBranch}\" | cut -f 1`,\n { encoding: 'utf-8' },\n ).split('\\n')[0];\n\n // This commit\n const latestThisCommit = execSync('git rev-parse HEAD', {\n encoding: 'utf-8',\n }).split('\\n')[0];\n\n // Ensure commits are present\n if (!latestBasedCommit || !latestThisCommit) {\n throw new Error('FAILED TO FIND COMMIT RANGE');\n }\n\n // Get the diff between the given branch and base branch\n const diff = execSync(\n `git fetch && git diff --name-only \"${\n baseBranch || latestBasedCommit\n }...${latestThisCommit}\" -- ${rootDirectory}`,\n { encoding: 'utf-8' },\n );\n\n // Filter out block list\n const changedFiles = difference(\n diff.split('\\n').filter((f) => f),\n fileBlockList,\n );\n\n // Filter out globs\n const filteredChanges =\n excludedGlob.length > 0\n ? fastGlob.sync(changedFiles, { ignore: excludedGlob })\n : changedFiles;\n\n // Get the contents of only the changed files\n const fileDiffs: { [k in string]: string } = {};\n filteredChanges.forEach((file) => {\n const contents = execSync(`git show ${latestThisCommit}:${file}`, {\n encoding: 'utf-8',\n });\n fileDiffs[file] = contents;\n });\n\n // Pull the github repo name\n const repoName = githubRepo.split('/').pop()!.split('.')[0];\n\n return {\n changedFiles,\n fileDiffs,\n repoName,\n commit: latestThisCommit,\n };\n}\n"],"mappings":"uxBA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AO,IAC9B,CAAE,SAAU,QAAS,CACtB,CAIM,MAAM;EAAK,CAAC,OAAQ,GAAM,EAAE,CACjC,EACD,CAGK,EACJ,EAAa,OAAS,EAClBC,EAAAA,QAAS,KAAK,EAAc,CAAE,OAAQ,EAAc,CAAC,CACrD,EAGA,EAAuC,EAAE,CAW/C,OAVA,EAAgB,QAAS,GAAS,CAIhC,EAAU,IAAA,EAAA,EAAA,UAHgB,YAAY,EAAiB,GAAG,IAAQ,CAChE,SAAU,QACX,CAAC,EAEF,CAKK,CACL,eACA,YACA,SALe,EAAW,MAAM,IAAI,CAAC,KAAK,CAAE,MAAM,IAAI,CAAC,GAMvD,OAAQ,EACT"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["makeGraphQLRequest","LARGE_LANGUAGE_MODELS","DEFAULT_TRANSCEND_API","buildTranscendGraphQLClient","uniq","agentNames","fetchPromptsWithVariables","fetchAllAgents","keyBy","name","fetchAllPromptThreads","groupBy","chunk","mapSeries","fetchAllAgentFiles","PromptStatus","ChatCompletionRole","reportPromptRun","PromptRunProductArea","QueueStatus","difference","fastGlob"],"sources":["../src/lib/graphql/fetchLargeLanguageModels.ts","../src/lib/ai/TranscendPromptManager.ts","../src/lib/ai/removeLinks.ts","../src/lib/ai/filterNullishValuesFromObject.ts","../src/lib/ai/getGitFilesThatChanged.ts"],"sourcesContent":["import { GraphQLClient } from 'graphql-request';\nimport { LargeLanguageModelClient } from '@transcend-io/privacy-types';\nimport { LARGE_LANGUAGE_MODELS } from './gqls';\nimport { makeGraphQLRequest } from './makeGraphQLRequest';\n\nexport interface LargeLanguageModel {\n /** ID of prompts */\n id: string;\n /** The name of the large language model. */\n name: string;\n /** The content of the prompt template. */\n client: LargeLanguageModelClient;\n /** Whether hosted by Transcend or not */\n isTranscendHosted: boolean;\n}\n\nconst PAGE_SIZE = 20;\n\n/**\n * Fetch all LargeLanguageModels in the organization\n *\n * @param client - GraphQL client\n * @returns All LargeLanguageModels in the organization\n */\nexport async function fetchAllLargeLanguageModels(\n client: GraphQLClient,\n): Promise<LargeLanguageModel[]> {\n const largeLanguageModels: LargeLanguageModel[] = [];\n let offset = 0;\n\n // Whether to continue looping\n let shouldContinue = false;\n do {\n const {\n largeLanguageModels: { nodes },\n } = await makeGraphQLRequest<{\n /** LargeLanguageModels */\n largeLanguageModels: {\n /** List */\n nodes: LargeLanguageModel[];\n };\n }>(client, LARGE_LANGUAGE_MODELS, {\n first: PAGE_SIZE,\n offset,\n });\n largeLanguageModels.push(...nodes);\n offset += PAGE_SIZE;\n shouldContinue = nodes.length === PAGE_SIZE;\n } while (shouldContinue);\n\n return largeLanguageModels.sort((a, b) => a.name.localeCompare(b.name));\n}\n","/* eslint-disable max-lines */\nimport {\n Optionalize,\n Requirize,\n apply,\n decodeCodec,\n getValues,\n} from '@transcend-io/type-utils';\nimport type { Handlebars } from '@transcend-io/handlebars-utils';\nimport { Secret } from '@transcend-io/secret-value';\nimport * as t from 'io-ts';\nimport { DEFAULT_TRANSCEND_API } from '../../constants';\nimport {\n Agent,\n AgentFile,\n AgentFileFilterBy,\n ReportPromptRunInput,\n buildTranscendGraphQLClient,\n fetchAllAgentFiles,\n fetchAllAgents,\n reportPromptRun,\n} from '../graphql';\nimport {\n HandlebarsInput,\n createHandlebarsWithHelpers,\n} from '@transcend-io/handlebars-utils';\nimport {\n TranscendPromptTemplated,\n TranscendPromptsAndVariables,\n fetchPromptsWithVariables,\n} from '../graphql/fetchPrompts';\nimport { GraphQLClient } from 'graphql-request';\nimport {\n PromptStatus,\n ChatCompletionRole,\n PromptRunProductArea,\n QueueStatus,\n LargeLanguageModelClient,\n} from '@transcend-io/privacy-types';\nimport {\n LargeLanguageModel,\n fetchAllLargeLanguageModels,\n} from '../graphql/fetchLargeLanguageModels';\nimport { groupBy, keyBy, uniq, chunk } from 'lodash-es';\nimport { mapSeries } from '../bluebird';\nimport {\n PromptThread,\n fetchAllPromptThreads,\n} from '../graphql/fetchPromptThreads';\n\n/**\n * An LLM Prompt definition\n */\nexport type TranscendPrompt<\n TInputParams extends t.Any,\n TOutputCodec extends t.Any,\n> = (\n | {\n /** ID of the prompt */\n id: string;\n /** Title of the prompt */\n title?: string;\n }\n | {\n /** ID of the prompt */\n id?: string;\n /** Title of the prompt */\n title: string;\n }\n) & {\n /** The names of the agents that should be loaded along with the prompt */\n agentNames?: string[];\n /** Codec to validate runtime input shape */\n paramCodec: TInputParams;\n /** Codec to validate output response */\n outputCodec: TOutputCodec;\n /**\n * If the output that needs to be parsed is returned within a tag\n * e.g. <tag> or <json> - this is the name of the tag\n */\n extractFromTag?: string;\n};\n\nexport interface PromptRunResult {\n /** The ID of the prompt run created on Transcend */\n promptRunId: string;\n /** The URL of the prompt run on Transcend */\n promptRunUrl: string;\n}\n\n/**\n * Create a regex to extract data from a tag\n *\n * Input:\n * \"here is some data <tag>Data</tag>...\"\n *\n * @param tagName - Name of tag\n * @returns Data within the tag\n */\nexport function createRegexForTag(tagName: string): RegExp {\n return new RegExp(`<${tagName}>([\\\\s\\\\S]+?)<\\\\/${tagName}>`);\n}\n\n/**\n * Helper function to declare prompts\n *\n * @param prompts - Prompt config\n * @returns Prompts as identity function - but type enforced\n */\nexport function defineTranscendPrompts<\n TPromptNames extends string,\n TPrompts extends { [k in TPromptNames]: TranscendPrompt<t.Any, t.Any> },\n>(prompts: TPrompts): TPrompts {\n return prompts;\n}\n\n/**\n * Helper to get the type of the parameter for a given prompt\n */\nexport type GetPromptParamType<\n TPromptName extends keyof TPrompts,\n TPrompts extends { [k in TPromptName]: TranscendPrompt<t.Any, t.Any> },\n> = t.TypeOf<TPrompts[TPromptName]['paramCodec']>;\n\n/**\n * Helper to get the type of the parameter for a given prompt\n */\nexport type GetPromptResponseType<\n TPromptName extends keyof TPrompts,\n TPrompts extends { [k in TPromptName]: TranscendPrompt<t.Any, t.Any> },\n> = t.TypeOf<TPrompts[TPromptName]['outputCodec']>;\n\n/**\n * Input for reporting a prompt run\n */\nexport interface ReportPromptRunOptions\n extends Optionalize<\n Omit<ReportPromptRunInput, 'status' | 'promptId' | 'largeLanguageModelId'>,\n 'name' | 'productArea'\n > {\n /** The large language model being run. Either the ID of the LLM or the client/name pairing */\n largeLanguageModel:\n | string\n | {\n /** Name of client */\n client: LargeLanguageModelClient;\n /** Name of the model */\n name: string;\n };\n}\n\nconst jsonParseSafe = (obj: string): unknown => {\n try {\n return JSON.parse(obj);\n } catch (e) {\n return obj;\n }\n};\n\n/**\n * A class that is capable of loading and insert variables into prompts from\n * Transcend's Prompt Manager\n */\nexport class TranscendPromptManager<\n TPromptNames extends string,\n TPrompts extends { [k in TPromptNames]: TranscendPrompt<t.Any, t.Any> },\n> {\n /** Prompt definitions */\n public prompts: TPrompts;\n\n /** Options for configuring handlebars */\n public handlebarsOptions!: HandlebarsInput;\n\n /** Prompt name -> content map, populated by call to Transcend API */\n public promptContentMap?: { [k in TPromptNames]: TranscendPromptTemplated };\n\n /** The large language models that are registered to this organization for reporting */\n public largeLanguageModels: LargeLanguageModel[] = [];\n\n /** The agent definitions registered to this organization */\n private agentsByName: { [name in string]: Agent } = {};\n\n /** The agent definitions registered to this organization */\n private agentsByAgentId: { [id in string]: Agent } = {};\n\n /** The GraphQL client that can be used to call Transcend */\n public graphQLClient: GraphQLClient;\n\n /** The set of variables to expose in handlebars context specified at class initiation */\n public defaultVariables: { [k in string]: unknown };\n\n /**\n * The set of variables to expose in handlebars context,\n * merges defaults with calculated variables from the inventory\n */\n public variables: { [k in string]: unknown };\n\n /** Handlebars compiler */\n public handlebars: typeof Handlebars;\n\n /** The Transcend API key */\n public transcendApiKey: string | Secret<string>;\n\n /** API of Transcend to call */\n public transcendUrl: string;\n\n /** When true, throw an error if the prompt is not approved */\n public requireApproval: boolean;\n\n /**\n * The cache duration in ms for how long prompts and associated metadata should be cached\n * When undefined - prompts are cached indefinitely unless explicitly re-requested\n * When 0, prompts and metadata are fetched every time (not recommended)\n * Setting this to be an hour is a good rate that optimizes for performance and keeping up to date\n */\n public cacheDuration?: number;\n\n /**\n * The last time the metadata was fetched\n */\n public lastUpdatedAt?: Date;\n\n /**\n * Constructor\n *\n * @param options - Options\n */\n constructor({\n prompts,\n handlebarsOptions = {},\n transcendUrl = DEFAULT_TRANSCEND_API,\n transcendApiKey,\n requireApproval = true,\n cacheDuration,\n defaultVariables = {},\n }: {\n /** Prompt definitions to load */\n prompts: TPrompts;\n /** Options for configuring handlebars */\n handlebarsOptions?: HandlebarsInput;\n /** The Transcend API key */\n transcendApiKey: string | Secret<string>;\n /** API of Transcend to call */\n transcendUrl?: string;\n /** When true, throw an error if the prompt is not approved */\n requireApproval?: boolean;\n /** The set of variables to expose in handlebars context specified at class initiation */\n defaultVariables?: { [k in string]: unknown };\n /**\n * The cache duration in ms for how long prompts and associated metadata should be cached\n * When undefined - prompts are cached indefinitely unless explicitly re-requested\n * When 0, prompts and metadata are fetched every time (not recommended)\n * Setting this to be an hour is a good rate that optimizes for performance and keeping up to date\n */\n cacheDuration?: number;\n }) {\n this.prompts = prompts;\n this.transcendUrl = transcendUrl;\n this.transcendApiKey = transcendApiKey;\n this.variables = defaultVariables;\n this.defaultVariables = defaultVariables;\n this.graphQLClient = buildTranscendGraphQLClient(\n transcendUrl,\n typeof transcendApiKey === 'object'\n ? transcendApiKey.release()\n : transcendApiKey,\n );\n this.requireApproval = requireApproval;\n this.cacheDuration = cacheDuration;\n this.handlebarsOptions = handlebarsOptions;\n this.handlebars = createHandlebarsWithHelpers(handlebarsOptions);\n }\n\n /**\n * Fetch prompt metadata from Transcend and cache to the class definition\n *\n * @returns A function that can be used to call the prompt\n */\n async fetchPromptsAndMetadata(): Promise<TranscendPromptsAndVariables> {\n // Determine what to fetch\n const promptDefinitions = getValues(this.prompts) as TranscendPrompt<\n t.Any,\n t.Any\n >[];\n const promptIds = promptDefinitions\n .map(({ id }) => id)\n .filter((x): x is string => !!x);\n const promptTitles = promptDefinitions\n .map(({ title }) => title)\n .filter((x): x is string => !!x);\n const agentNames = uniq(\n promptDefinitions.map(({ agentNames }) => agentNames || []).flat(),\n );\n\n // Fetch prompts and data\n const [response, largeLanguageModels, agents] = await Promise.all([\n fetchPromptsWithVariables(this.graphQLClient, {\n promptIds,\n promptTitles,\n }),\n fetchAllLargeLanguageModels(this.graphQLClient),\n fetchAllAgents(this.graphQLClient, { names: agentNames }),\n ]);\n this.agentsByName = keyBy(agents, 'name');\n this.agentsByAgentId = keyBy(agents, 'agentId');\n this.largeLanguageModels = largeLanguageModels.filter(\n (model) => model.isTranscendHosted === false,\n );\n\n // Lookup prompts by id/title\n const promptByTitle = keyBy(response.prompts, 'title');\n const promptById = keyBy(response.prompts, 'id');\n\n // Update variables\n this.variables = {\n ...response.calculatedVariables.reduce(\n (acc, v) =>\n Object.assign(acc, {\n [v.name]: v.data ? JSON.parse(v.data) : v.data,\n }),\n {},\n ),\n ...this.defaultVariables,\n };\n\n // Update partials\n this.handlebars = createHandlebarsWithHelpers({\n ...this.handlebarsOptions,\n templates: [\n ...(this.handlebarsOptions.templates || []),\n ...response.promptPartials.map((partial) => ({\n name: partial.slug,\n content: partial.content,\n })),\n ],\n });\n\n // Create mapping from prompt to content\n this.promptContentMap = apply(this.prompts, ({ id, title }) => {\n const result = id\n ? promptById[id]\n : title\n ? promptByTitle[title]\n : undefined;\n if (!result) {\n throw new Error(\n `Failed to find prompt with title: \"${title}\" and id: \"${id}\"`,\n );\n }\n return result;\n });\n\n // For cache\n this.lastUpdatedAt = new Date();\n\n return response;\n }\n\n /**\n * Get an agent definition by name\n *\n * @param name - Name of the agent to grab\n * @returns Large language model configuration\n */\n async getAgentByName(name: string): Promise<Agent | undefined> {\n const agent = this.agentsByName[name];\n if (agent) {\n return agent;\n }\n const [remoteAgent] = await fetchAllAgents(this.graphQLClient, {\n names: [name],\n });\n if (!remoteAgent) {\n return undefined;\n }\n this.agentsByName[remoteAgent.name] = remoteAgent;\n this.agentsByAgentId[remoteAgent.agentId] = remoteAgent;\n return remoteAgent;\n }\n\n /**\n * Get a prompt thread by ts\n *\n * @param ts - the slack message timestamp to look up thread for\n * @returns Large language model configuration\n */\n async getPromptThreadBySlackTs(\n ts: string,\n ): Promise<PromptThread | undefined> {\n const [thread] = await fetchAllPromptThreads(this.graphQLClient, {\n slackMessageTs: [ts],\n });\n return thread;\n }\n\n /**\n * Get a list of agent definitions by name.\n * Pulls from cache and may return less agents\n * than requested if some are not found\n *\n * @param names - Names of agents to fetch\n * @returns The agents that were found matching the names\n */\n async getAgentsByName(names: string[]): Promise<Agent[]> {\n if (names.length < 1) {\n throw new Error('Expected at least one name to be provided');\n }\n const { hasCache = [], missingCache = [] } = groupBy(names, (name) =>\n this.agentsByName[name] ? 'hasCache' : 'missingCache',\n );\n const cachedAgents = hasCache.map((name) => this.agentsByName[name]);\n if (missingCache.length === 0) {\n return cachedAgents;\n }\n const chunkedNames = chunk(missingCache, 50);\n const remoteAgents: Agent[] = [];\n await mapSeries(chunkedNames, async (chunkedName) => {\n const pageOfAgents = await fetchAllAgents(this.graphQLClient, {\n names: chunkedName,\n });\n pageOfAgents.forEach((agent) => {\n this.agentsByName[agent.name] = agent;\n this.agentsByAgentId[agent.agentId] = agent;\n });\n remoteAgents.push(...pageOfAgents);\n });\n return [...cachedAgents, ...remoteAgents];\n }\n\n /**\n * Fetch metadata on agent files\n *\n * @param filterBy - Filter by parameters\n * @returns The files found matching the filter\n */\n getAgentFiles(filterBy: AgentFileFilterBy): Promise<AgentFile[]> {\n return fetchAllAgentFiles(this.graphQLClient, filterBy);\n }\n\n /**\n * Look up the large language model to report on\n *\n * @param largeLanguageModel - Input\n * @returns Large language model configuration\n */\n getLargeLanguageModel(\n largeLanguageModel: ReportPromptRunOptions['largeLanguageModel'],\n ): LargeLanguageModel {\n const matching = this.largeLanguageModels.find((model) =>\n typeof largeLanguageModel === 'string'\n ? model.id === largeLanguageModel\n : model.name === largeLanguageModel.name &&\n model.client === largeLanguageModel.client,\n );\n if (!matching) {\n throw new Error(\n `Failed to find model matching: ${\n typeof largeLanguageModel === 'string'\n ? largeLanguageModel\n : JSON.stringify(largeLanguageModel)\n }`,\n );\n }\n return matching;\n }\n\n /**\n * Get a prompt definition by name\n *\n * @param promptName - Prompt to compile\n * @returns Parsed content\n */\n async getPromptDefinition<TPromptName extends TPromptNames>(\n promptName: TPromptName,\n ): Promise<TranscendPromptTemplated> {\n // Determine if prompts need to be fetched\n if (\n // never been fetched\n !this.lastUpdatedAt ||\n // fetch every run\n this.cacheDuration === 0 ||\n // If cache duration met\n (this.cacheDuration &&\n Date.now() - this.lastUpdatedAt.getTime() > this.cacheDuration)\n ) {\n await this.fetchPromptsAndMetadata();\n }\n\n // Lookup prompt\n const { promptContentMap } = this;\n if (!promptContentMap) {\n throw new Error('Expected this.promptContentMap to be defined');\n }\n const promptTemplate = promptContentMap[promptName];\n if (!promptTemplate) {\n throw new Error(\n `Expected this.promptContentMap[${promptName}] to be defined`,\n );\n }\n return promptTemplate;\n }\n\n /**\n * Validate the shape of the response from AI\n *\n * @param promptName - Prompt to compile\n * @param params - Runtime parameters\n * @returns Parsed content\n */\n async compilePrompt<TPromptName extends TPromptNames>(\n promptName: TPromptName,\n params: t.TypeOf<TPrompts[TPromptName]['paramCodec']>,\n ): Promise<string> {\n // Grab the prompt\n const promptTemplate = await this.getPromptDefinition(promptName);\n const promptInput = this.prompts[promptName];\n if (!promptInput) {\n throw new Error(`Expected this.prompts[${promptName}] to be defined`);\n }\n\n // Ensure prompt is approved\n if (\n this.requireApproval &&\n promptTemplate.status !== PromptStatus.Approved\n ) {\n throw new Error(\n `Assessment \"${promptTemplate.title}\" cannot be used because its in status: \"${promptTemplate.status}\"`,\n );\n }\n\n // If prompt is rejected, throw error\n if (promptTemplate.status === PromptStatus.Rejected) {\n throw new Error(\n `Assessment \"${promptTemplate.title}\" cannot be used because it's in status: \"${promptTemplate.status}\"`,\n );\n }\n\n // Validate params\n decodeCodec(promptInput.paramCodec, params);\n\n // Compile prompt and template\n return this.handlebars.compile(promptTemplate.content)({\n // template in currentDate by default\n currentDate: new Date().toISOString(),\n ...this.variables,\n ...params,\n });\n }\n\n /**\n * Validate the shape of the response from AI\n *\n * @param promptName - Prompt to parse\n * @param response - AI response as string\n * @returns Parsed content\n */\n parseAiResponse<TPromptName extends TPromptNames>(\n promptName: TPromptName,\n response: string,\n ): t.TypeOf<TPrompts[TPromptName]['outputCodec']> {\n // Look up prompt info\n const promptInput = this.prompts[promptName];\n if (!promptInput) {\n throw new Error(`Expected this.prompts[${promptName}] to be defined`);\n }\n\n // Extract from tag if needed\n const extracted = promptInput.extractFromTag\n ? (createRegexForTag(promptInput.extractFromTag).exec(response) ||\n [])[1] || response\n : response;\n\n // Parse via codec\n return decodeCodec(\n promptInput.outputCodec,\n jsonParseSafe(extracted),\n false,\n );\n }\n\n /**\n * Parse the AI response and report back to Transcend\n *\n * @param promptName - Prompt to parse\n * @param options - Options for reporting\n * @returns Parsed content\n */\n async reportAndParsePromptRun<TPromptName extends TPromptNames>(\n promptName: TPromptName,\n { largeLanguageModel, ...options }: ReportPromptRunOptions,\n ): Promise<\n PromptRunResult & {\n /** Resulting prompt run */\n result: t.TypeOf<TPrompts[TPromptName]['outputCodec']>;\n }\n > {\n // Determine if prompts need to be fetched\n if (\n // never been fetched\n !this.lastUpdatedAt ||\n // fetch every run\n this.cacheDuration === 0 ||\n // If cache duration met\n (this.cacheDuration &&\n Date.now() - this.lastUpdatedAt.getTime() > this.cacheDuration)\n ) {\n await this.fetchPromptsAndMetadata();\n }\n\n const name =\n options.name ||\n `@transcend-io/cli-prompt-run-${new Date().toISOString()}`;\n\n if (!this.promptContentMap) {\n throw new Error('Expected this.promptContentMap to be defined');\n }\n // Look up prompt info\n const promptInput = this.promptContentMap[promptName];\n if (!promptInput) {\n throw new Error(`Expected this.prompts[${promptName}] to be defined`);\n }\n\n // Ensure the first message in `promptRunMessages` is of type=system\n if (options.promptRunMessages.length === 0) {\n throw new Error('promptRunMessages is expected to have length > 0');\n }\n if (options.promptRunMessages[0].role !== ChatCompletionRole.System) {\n throw new Error(\n `promptRunMessages[0].role is expected to be = ${ChatCompletionRole.System}`,\n );\n }\n if (\n options.promptRunMessages[options.promptRunMessages.length - 1].role !==\n ChatCompletionRole.Assistant\n ) {\n throw new Error(\n `promptRunMessages[${\n options.promptRunMessages.length - 1\n }].role is expected to be = ${ChatCompletionRole.Assistant}`,\n );\n }\n const response =\n options.promptRunMessages[options.promptRunMessages.length - 1].content;\n\n let parsed: t.TypeOf<TPrompts[TPromptName]['outputCodec']>;\n try {\n // Parse the response\n parsed = this.parseAiResponse(promptName, response);\n } catch (err) {\n await reportPromptRun(this.graphQLClient, {\n productArea: PromptRunProductArea.PromptManager,\n ...options,\n name,\n error: err.message,\n status: QueueStatus.Error,\n ...(typeof largeLanguageModel === 'string'\n ? { largeLanguageModelId: largeLanguageModel }\n : {\n largeLanguageModelName: largeLanguageModel.name,\n largeLanguageModelClient: largeLanguageModel.client,\n }),\n promptId: promptInput.id,\n promptRunMessages: options.promptRunMessages.map((message, ind) => ({\n ...message,\n ...(ind === 0 ? { template: promptInput.content } : {}),\n })),\n });\n throw err;\n }\n\n // report successful run\n const promptRunId = await reportPromptRun(this.graphQLClient, {\n productArea: PromptRunProductArea.PromptManager,\n ...options,\n name,\n status: QueueStatus.Resolved,\n ...(typeof largeLanguageModel === 'string'\n ? { largeLanguageModelId: largeLanguageModel }\n : {\n largeLanguageModelName: largeLanguageModel.name,\n largeLanguageModelClient: largeLanguageModel.client,\n }),\n promptId: promptInput.id,\n promptRunMessages: options.promptRunMessages.map((message, ind) => ({\n ...message,\n ...(ind === 0 ? { template: promptInput.content } : {}),\n })),\n });\n\n return {\n result: parsed,\n promptRunId,\n promptRunUrl: `https://app.transcend.io/prompts/runs/${promptRunId}`,\n };\n }\n\n /**\n * Report an error for a particular prompt\n *\n * @param promptName - Prompt to parse\n * @param options - Options for reporting\n * @returns Parsed content\n */\n async reportPromptRunError<TPromptName extends TPromptNames>(\n promptName: TPromptName,\n {\n largeLanguageModel,\n ...options\n }: Requirize<ReportPromptRunOptions, 'error'>,\n ): Promise<PromptRunResult> {\n // Determine if prompts need to be fetched\n if (\n // never been fetched\n !this.lastUpdatedAt ||\n // fetch every run\n this.cacheDuration === 0 ||\n // If cache duration met\n (this.cacheDuration &&\n Date.now() - this.lastUpdatedAt.getTime() > this.cacheDuration)\n ) {\n await this.fetchPromptsAndMetadata();\n }\n\n const name =\n options.name ||\n `@transcend-io/cli-prompt-run-${new Date().toISOString()}`;\n\n if (!this.promptContentMap) {\n throw new Error('Expected this.promptContentMap to be defined');\n }\n // Look up prompt info\n const promptInput = this.promptContentMap[promptName];\n if (!promptInput) {\n throw new Error(`Expected this.prompts[${promptName}] to be defined`);\n }\n\n // Ensure the first message in `promptRunMessages` is of type=system\n if (options.promptRunMessages.length === 0) {\n throw new Error('promptRunMessages is expected to have length > 0');\n }\n if (options.promptRunMessages[0].role !== ChatCompletionRole.System) {\n throw new Error(\n `promptRunMessages[0].role is expected to be = ${ChatCompletionRole.System}`,\n );\n }\n\n const promptRunId = await reportPromptRun(this.graphQLClient, {\n productArea: PromptRunProductArea.PromptManager,\n ...options,\n name,\n status: QueueStatus.Error,\n ...(typeof largeLanguageModel === 'string'\n ? { largeLanguageModelId: largeLanguageModel }\n : {\n largeLanguageModelName: largeLanguageModel.name,\n largeLanguageModelClient: largeLanguageModel.client,\n }),\n promptId: promptInput.id,\n promptRunMessages: options.promptRunMessages.map((message, ind) => ({\n ...message,\n ...(ind === 0 ? { template: promptInput.content } : {}),\n })),\n });\n\n return {\n promptRunId,\n promptRunUrl: `https://app.transcend.io/prompts/runs/${promptRunId}`,\n };\n }\n}\n/* eslint-enable max-lines */\n","/**\n * Remove links from a string\n *\n * @param inputString - String\n * @returns String without links\n */\nexport function removeLinks(inputString: string): string {\n const regex = /(https?:\\/\\/[^\\s]+)/g;\n return inputString.replace(regex, '<link-omitted>');\n}\n","import { ObjByString } from '@transcend-io/type-utils';\n\n/**\n * Given an object, remove all keys that are null-ish\n *\n * @param obj - Object\n * @returns Object with null-ish values removed\n */\nexport function filterNullishValuesFromObject<T extends ObjByString>(\n obj: T,\n): T {\n return Object.entries(obj).reduce(\n (acc, [k, v]) =>\n v !== null &&\n v !== undefined &&\n v !== '' &&\n !(Array.isArray(v) && v.length === 0) &&\n !(typeof v === 'object' && Object.keys(v).length === 0)\n ? Object.assign(acc, { [k]: v })\n : acc,\n {} as T,\n );\n}\n","import { difference } from 'lodash-es';\nimport fastGlob from 'fast-glob';\nimport { execSync } from 'child_process';\n\n/**\n * Function thats gets the git files that have changed\n * and returns the code\n *\n * @param options - Options\n * @returns Changes files and diffs\n */\nexport function getGitFilesThatChanged({\n baseBranch,\n rootDirectory,\n githubRepo,\n excludedGlob = [],\n fileBlockList = [],\n}: {\n /** Base branch */\n baseBranch: string;\n /** Github repo name */\n githubRepo: string;\n /** Root directory */\n rootDirectory: string;\n /** A glob that excludes files */\n excludedGlob?: string[];\n /** Block list of files to not process */\n fileBlockList?: string[];\n}): {\n /** The list of files that changed */\n changedFiles: string[];\n /** Github repo name */\n repoName: string;\n /** Current commit */\n commit: string;\n /** File diffs */\n fileDiffs: { [k in string]: string };\n} {\n // Pull base branch\n execSync(`git fetch origin ${baseBranch}`);\n\n // Latest commit on base branch. If we are on the base branch, we take the prior commit\n const latestBasedCommit = execSync(\n `git ls-remote ${githubRepo} \"refs/heads/${baseBranch}\" | cut -f 1`,\n { encoding: 'utf-8' },\n ).split('\\n')[0];\n\n // This commit\n const latestThisCommit = execSync('git rev-parse HEAD', {\n encoding: 'utf-8',\n }).split('\\n')[0];\n\n // Ensure commits are present\n if (!latestBasedCommit || !latestThisCommit) {\n throw new Error('FAILED TO FIND COMMIT RANGE');\n }\n\n // Get the diff between the given branch and base branch\n const diff = execSync(\n `git fetch && git diff --name-only \"${\n baseBranch || latestBasedCommit\n }...${latestThisCommit}\" -- ${rootDirectory}`,\n { encoding: 'utf-8' },\n );\n\n // Filter out block list\n const changedFiles = difference(\n diff.split('\\n').filter((f) => f),\n fileBlockList,\n );\n\n // Filter out globs\n const filteredChanges =\n excludedGlob.length > 0\n ? fastGlob.sync(changedFiles, { ignore: excludedGlob })\n : changedFiles;\n\n // Get the contents of only the changed files\n const fileDiffs: { [k in string]: string } = {};\n filteredChanges.forEach((file) => {\n const contents = execSync(`git show ${latestThisCommit}:${file}`, {\n encoding: 'utf-8',\n });\n fileDiffs[file] = contents;\n });\n\n // Pull the github repo name\n const repoName = githubRepo.split('/').pop()!.split('.')[0];\n\n return {\n changedFiles,\n fileDiffs,\n repoName,\n commit: latestThisCommit,\n };\n}\n"],"mappings":"yzBAgBA,MAAM,EAAY,GAQlB,eAAsB,EACpB,EAC+B,CAC/B,IAAM,EAA4C,EAAE,CAChD,EAAS,EAGT,EAAiB,GACrB,EAAG,CACD,GAAM,CACJ,oBAAqB,CAAE,UACrB,MAAMA,EAAAA,EAMP,EAAQC,EAAAA,GAAuB,CAChC,MAAO,GACP,SACD,CAAC,CACF,EAAoB,KAAK,GAAG,EAAM,CAClC,GAAU,GACV,EAAiB,EAAM,SAAW,SAC3B,GAET,OAAO,EAAoB,MAAM,EAAG,IAAM,EAAE,KAAK,cAAc,EAAE,KAAK,CAAC,CCiDzE,SAAgB,EAAkB,EAAyB,CACzD,OAAW,OAAO,IAAI,EAAQ,mBAAmB,EAAQ,GAAG,CAS9D,SAAgB,EAGd,EAA6B,CAC7B,OAAO,EAsCT,MAAM,EAAiB,GAAyB,CAC9C,GAAI,CACF,OAAO,KAAK,MAAM,EAAI,MACZ,CACV,OAAO,IAQX,IAAa,EAAb,KAGE,CAEA,QAGA,kBAGA,iBAGA,oBAAmD,EAAE,CAGrD,aAAoD,EAAE,CAGtD,gBAAqD,EAAE,CAGvD,cAGA,iBAMA,UAGA,WAGA,gBAGA,aAGA,gBAQA,cAKA,cAOA,YAAY,CACV,UACA,oBAAoB,EAAE,CACtB,eAAeC,EAAAA,EACf,kBACA,kBAAkB,GAClB,gBACA,mBAAmB,EAAE,EAqBpB,CACD,KAAK,QAAU,EACf,KAAK,aAAe,EACpB,KAAK,gBAAkB,EAC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,EAAA,UACJ,iBAAiB,EAAW,eAAe,EAAW,cACtD,CAAE,SAAU,QAAS,CACtB,CAAC,MAAM;EAAK,CAAC,GAGR,GAAA,EAAA,EAAA,UAA4B,qBAAsB,CACtD,SAAU,QACX,CAAC,CAAC,MAAM;EAAK,CAAC,GAGf,GAAI,CAAC,GAAqB,CAAC,EACzB,MAAU,MAAM,8BAA8B,CAYhD,IAAM,EAAeC,EAAAA,IAAAA,EAAAA,EAAAA,UAPnB,sCACE,GAAc,EACf,KAAK,EAAiB,OAAO,IAC9B,CAAE,SAAU,QAAS,CACtB,CAIM,MAAM;EAAK,CAAC,OAAQ,GAAM,EAAE,CACjC,EACD,CAGK,EACJ,EAAa,OAAS,EAClBC,EAAAA,QAAS,KAAK,EAAc,CAAE,OAAQ,EAAc,CAAC,CACrD,EAGA,EAAuC,EAAE,CAW/C,OAVA,EAAgB,QAAS,GAAS,CAIhC,EAAU,IAAA,EAAA,EAAA,UAHgB,YAAY,EAAiB,GAAG,IAAQ,CAChE,SAAU,QACX,CAAC,EAEF,CAKK,CACL,eACA,YACA,SALe,EAAW,MAAM,IAAI,CAAC,KAAK,CAAE,MAAM,IAAI,CAAC,GAMvD,OAAQ,EACT"}
|
package/dist/index.d.cts
CHANGED
|
@@ -134744,11 +134744,11 @@ declare const CachedFileState: t.TypeC<{
|
|
|
134744
134744
|
/** Mapping between request status in import to Transcend request status */
|
|
134745
134745
|
statusToRequestStatus: t.RecordC<t.StringC, t.KeyofC<{
|
|
134746
134746
|
CANCELED: unknown;
|
|
134747
|
+
"[NONE]": unknown;
|
|
134747
134748
|
FAILED_VERIFICATION: unknown;
|
|
134748
134749
|
COMPLETED: unknown;
|
|
134749
134750
|
SECONDARY_COMPLETED: unknown;
|
|
134750
134751
|
REVOKED: unknown;
|
|
134751
|
-
"[NONE]": unknown;
|
|
134752
134752
|
}>>;
|
|
134753
134753
|
}>;
|
|
134754
134754
|
/** Type override */
|
|
@@ -137191,20 +137191,20 @@ declare const PrivacyRequest: t.IntersectionC<[t.TypeC<{
|
|
|
137191
137191
|
status: t.KeyofC<{
|
|
137192
137192
|
CANCELED: unknown;
|
|
137193
137193
|
ON_HOLD: unknown;
|
|
137194
|
-
REQUEST_MADE: unknown;
|
|
137195
137194
|
FAILED_VERIFICATION: unknown;
|
|
137195
|
+
COMPLETED: unknown;
|
|
137196
|
+
SECONDARY_COMPLETED: unknown;
|
|
137197
|
+
REVOKED: unknown;
|
|
137198
|
+
REQUEST_MADE: unknown;
|
|
137196
137199
|
ENRICHING: unknown;
|
|
137197
137200
|
WAITING: unknown;
|
|
137198
137201
|
COMPILING: unknown;
|
|
137199
137202
|
APPROVING: unknown;
|
|
137200
137203
|
DELAYED: unknown;
|
|
137201
|
-
COMPLETED: unknown;
|
|
137202
137204
|
DOWNLOADABLE: unknown;
|
|
137203
137205
|
VIEW_CATEGORIES: unknown;
|
|
137204
137206
|
SECONDARY: unknown;
|
|
137205
|
-
SECONDARY_COMPLETED: unknown;
|
|
137206
137207
|
SECONDARY_APPROVING: unknown;
|
|
137207
|
-
REVOKED: unknown;
|
|
137208
137208
|
}>;
|
|
137209
137209
|
/** Type of data subject */
|
|
137210
137210
|
subjectType: t.StringC;
|
|
@@ -150748,20 +150748,20 @@ declare const PrivacyRequestResponse: t.TypeC<{
|
|
|
150748
150748
|
status: t.KeyofC<{
|
|
150749
150749
|
CANCELED: unknown;
|
|
150750
150750
|
ON_HOLD: unknown;
|
|
150751
|
-
REQUEST_MADE: unknown;
|
|
150752
150751
|
FAILED_VERIFICATION: unknown;
|
|
150752
|
+
COMPLETED: unknown;
|
|
150753
|
+
SECONDARY_COMPLETED: unknown;
|
|
150754
|
+
REVOKED: unknown;
|
|
150755
|
+
REQUEST_MADE: unknown;
|
|
150753
150756
|
ENRICHING: unknown;
|
|
150754
150757
|
WAITING: unknown;
|
|
150755
150758
|
COMPILING: unknown;
|
|
150756
150759
|
APPROVING: unknown;
|
|
150757
150760
|
DELAYED: unknown;
|
|
150758
|
-
COMPLETED: unknown;
|
|
150759
150761
|
DOWNLOADABLE: unknown;
|
|
150760
150762
|
VIEW_CATEGORIES: unknown;
|
|
150761
150763
|
SECONDARY: unknown;
|
|
150762
|
-
SECONDARY_COMPLETED: unknown;
|
|
150763
150764
|
SECONDARY_APPROVING: unknown;
|
|
150764
|
-
REVOKED: unknown;
|
|
150765
150765
|
}>;
|
|
150766
150766
|
type: t.KeyofC<{
|
|
150767
150767
|
ACCESS: unknown;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require(`./
|
|
2
|
-
//# sourceMappingURL=logger-
|
|
1
|
+
const e=require(`./chunk-Bmb41Sf3.cjs`);let t=require(`colors`);t=e.t(t);let n=require(`global-agent`),r=require(`undici`),i=require(`yargs-parser`);i=e.t(i);const a=console,{httpProxy:o=process.env.http_proxy}=(0,i.default)(process.argv.slice(2));o&&(a.info(t.default.green(`Initializing proxy: ${o}`)),process.env.GLOBAL_AGENT_HTTP_PROXY=o,(0,n.bootstrap)(),(0,r.setGlobalDispatcher)(new r.ProxyAgent(o))),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return a}});
|
|
2
|
+
//# sourceMappingURL=logger-DQwEYtSS.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger-
|
|
1
|
+
{"version":3,"file":"logger-DQwEYtSS.cjs","names":["ProxyAgent"],"sources":["../src/logger.ts"],"sourcesContent":["import colors from 'colors';\nimport { bootstrap } from 'global-agent';\nimport { ProxyAgent, setGlobalDispatcher } from 'undici';\nimport yargs from 'yargs-parser';\n\nexport const logger = console;\n\n// When the proxy env var of flag is specified, initiate the proxy\nconst { httpProxy = process.env.http_proxy } = yargs(process.argv.slice(2));\nif (httpProxy) {\n logger.info(colors.green(`Initializing proxy: ${httpProxy}`));\n\n // Use global-agent, which overrides `request` based requests\n process.env.GLOBAL_AGENT_HTTP_PROXY = httpProxy;\n bootstrap();\n\n // Use undici, which overrides `fetch` based requests\n setGlobalDispatcher(new ProxyAgent(httpProxy));\n}\n"],"mappings":"8JAKA,MAAa,EAAS,QAGhB,CAAE,YAAY,QAAQ,IAAI,aAAA,EAAA,EAAA,SAAqB,QAAQ,KAAK,MAAM,EAAE,CAAC,CACvE,IACF,EAAO,KAAK,EAAA,QAAO,MAAM,uBAAuB,IAAY,CAAC,CAG7D,QAAQ,IAAI,wBAA0B,GACtC,EAAA,EAAA,YAAW,EAGX,EAAA,EAAA,qBAAoB,IAAIA,EAAAA,WAAW,EAAU,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require(`./
|
|
2
|
-
//# sourceMappingURL=manual-enrichment-
|
|
1
|
+
const e=require(`./chunk-Bmb41Sf3.cjs`),t=require(`./constants-7qBywLgI.cjs`),n=require(`./syncConfigurationToTranscend-Bd0ZTIm1.cjs`),r=require(`./logger-DQwEYtSS.cjs`);let i=require(`@transcend-io/privacy-types`),a=require(`colors`);a=e.t(a);let o=require(`io-ts`);o=e.t(o);async function s({file:e,auth:o,sombraAuth:s,requestActions:c=[],concurrency:l=100,transcendUrl:u=t.a}){let d=n.ti(u,o),f=await n.ei(u,o,s);r.t.info(a.default.magenta(`Pulling manual enrichment requests, filtered for actions: ${c.join(`,`)}`));let p=await n.fr(d,{actions:c,statuses:[i.RequestStatus.Enriching]}),m=[];await n.Ts(p,async e=>{let t=await n.gr(d,{requestId:e.id});if(t.filter(({status:e})=>e===`ACTION_REQUIRED`)){let r=await n.mr(d,f,{requestId:e.id});m.push({...e,requestIdentifiers:r,requestEnrichers:t})}},{concurrency:l});let h=m.map(({attributeValues:e,requestIdentifiers:t,requestEnrichers:r,...i})=>({...i,...Object.entries(n.As(t,`name`)).reduce((e,[t,n])=>Object.assign(e,{[t]:n.map(({value:e})=>e).join(`,`)}),{}),...Object.entries(n.As(e,`attributeKey.name`)).reduce((e,[t,n])=>Object.assign(e,{[t]:n.map(({name:e})=>e).join(`,`)}),{})}));return await n.l(e,h,n.Ds(h.map(e=>Object.keys(e)).flat())),r.t.info(a.default.green(`Successfully wrote ${m.length} requests to file "${e}"`)),m}const c=`https://app.transcend.io/privacy-requests/incoming-requests/`,l=o.record(o.string,o.string);async function u(e,{id:t,...i},o,s){if(!t){let e=`Request ID must be provided to enricher request.${s?` Found error in row: ${s}`:``}`;throw r.t.error(a.default.red(e)),Error(e)}let l=t.toLowerCase(),u=Object.entries(i).reduce((e,[t,r])=>n.Ds(n.li(r)).length===0?e:Object.assign(e,{[t]:n.Ds(n.li(r)).map(e=>({value:t===`email`?e.toLowerCase():e}))}),{});try{return await e.post(`v1/enrich-identifiers`,{headers:{"x-transcend-request-id":l,"x-transcend-enricher-id":o},json:{enrichedIdentifiers:u}}).json(),r.t.error(a.default.green(`Successfully enriched request: ${c}${l}`)),!0}catch(e){if(typeof e.response.body==`string`&&e.response.body.includes(`Cannot update a resolved RequestEnricher`))return r.t.warn(a.default.magenta(`Skipped enrichment for request: ${c}${l}, request is no longer in the enriching phase.`)),!1;throw r.t.error(a.default.red(`Failed to enricher identifiers for request with id: ${c}${l} - ${e.message} - ${e.response.body}`)),e}}async function d({file:e,auth:i,sombraAuth:o,enricherId:s,markSilent:c,concurrency:d=100,transcendUrl:f=t.a}){let p=await n.ei(f,i,o),m=n.ti(f,i);r.t.info(a.default.magenta(`Reading "${e}" from disk`));let h=n.oi(e,l);r.t.info(a.default.magenta(`Enriching "${h.length}" privacy requests.`));let g=0,_=0,v=0;if(await n.Ts(h,async(e,t)=>{try{c&&(await n.i(m,n.Ao,{input:{id:e.id,isSilent:!0}}),r.t.info(a.default.magenta(`Mark request as silent mode - ${e.id}`))),await u(p,e,s,t)?g+=1:_+=1}catch{v+=1}},{concurrency:d}),r.t.info(a.default.green(`Successfully notified Transcend! \n Success count: ${g}.`)),_>0&&r.t.info(a.default.magenta(`Skipped count: ${_}.`)),v>0)throw r.t.info(a.default.red(`Error Count: ${v}.`)),Error(`Failed to enrich: ${v} requests.`);return h.length}Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return d}});
|
|
2
|
+
//# sourceMappingURL=manual-enrichment-CzRiIFev.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manual-enrichment-Cz9Cb_fJ.cjs","names":["DEFAULT_TRANSCEND_API","buildTranscendGraphQLClient","createSombraGotInstance","fetchAllRequests","RequestStatus","map","fetchAllRequestEnrichers","fetchAllRequestIdentifiers","groupBy","writeCsv","uniq","t","uniq","splitCsvToList","DEFAULT_TRANSCEND_API","createSombraGotInstance","buildTranscendGraphQLClient","readCsv","map","makeGraphQLRequest","UPDATE_PRIVACY_REQUEST"],"sources":["../src/lib/manual-enrichment/pullManualEnrichmentIdentifiersToCsv.ts","../src/lib/manual-enrichment/enrichPrivacyRequest.ts","../src/lib/manual-enrichment/pushManualEnrichmentIdentifiersFromCsv.ts"],"sourcesContent":["import { RequestAction, RequestStatus } from '@transcend-io/privacy-types';\nimport { map } from '../bluebird';\nimport colors from 'colors';\nimport { groupBy, uniq } from 'lodash-es';\nimport { DEFAULT_TRANSCEND_API } from '../../constants';\nimport { writeCsv } from '../helpers/writeCsv';\nimport {\n PrivacyRequest,\n RequestEnricher,\n RequestIdentifier,\n buildTranscendGraphQLClient,\n createSombraGotInstance,\n fetchAllRequestEnrichers,\n fetchAllRequestIdentifiers,\n fetchAllRequests,\n} from '../graphql';\nimport { logger } from '../../logger';\n\nexport interface PrivacyRequestWithIdentifiers extends PrivacyRequest {\n /** Request Enrichers */\n requestEnrichers: RequestEnricher[];\n /** Request Identifiers */\n requestIdentifiers: RequestIdentifier[];\n}\n\n/**\n * Pull the set of manual enrichment jobs to CSV\n *\n * @param options - Options\n * @returns List of requests with identifiers\n */\nexport async function pullManualEnrichmentIdentifiersToCsv({\n file,\n auth,\n sombraAuth,\n requestActions = [],\n concurrency = 100,\n transcendUrl = DEFAULT_TRANSCEND_API,\n}: {\n /** CSV file path */\n file: string;\n /** Transcend API key authentication */\n auth: string;\n /** Sombra API key */\n sombraAuth?: string;\n /** Concurrency */\n concurrency?: number;\n /** The request actions to fetch */\n requestActions?: RequestAction[];\n /** API URL for Transcend backend */\n transcendUrl?: string;\n}): Promise<PrivacyRequestWithIdentifiers[]> {\n // Find all requests made before createdAt that are in a removing data state\n const client = buildTranscendGraphQLClient(transcendUrl, auth);\n const sombra = await createSombraGotInstance(transcendUrl, auth, sombraAuth);\n\n logger.info(\n colors.magenta(\n `Pulling manual enrichment requests, filtered for actions: ${requestActions.join(\n ',',\n )}`,\n ),\n );\n\n // Pull all privacy requests\n const allRequests = await fetchAllRequests(client, {\n actions: requestActions,\n statuses: [RequestStatus.Enriching],\n });\n\n // Requests to save\n const savedRequests: PrivacyRequestWithIdentifiers[] = [];\n\n // Filter down requests to what is needed\n await map(\n allRequests,\n async (request) => {\n // Fetch enrichers\n const requestEnrichers = await fetchAllRequestEnrichers(client, {\n requestId: request.id,\n });\n\n // Check if manual enrichment exists for that request\n const hasManualEnrichment = requestEnrichers.filter(\n ({ status }) => status === 'ACTION_REQUIRED',\n );\n\n // Save request to queue\n if (hasManualEnrichment) {\n const requestIdentifiers = await fetchAllRequestIdentifiers(\n client,\n sombra,\n {\n requestId: request.id,\n },\n );\n savedRequests.push({\n ...request,\n requestIdentifiers,\n requestEnrichers,\n });\n }\n },\n {\n concurrency,\n },\n );\n\n const data = savedRequests.map(\n ({\n attributeValues,\n requestIdentifiers,\n requestEnrichers, // eslint-disable-line @typescript-eslint/no-unused-vars\n ...request\n }) => ({\n ...request,\n // flatten identifiers\n ...Object.entries(groupBy(requestIdentifiers, 'name')).reduce(\n (acc, [key, values]) =>\n Object.assign(acc, {\n [key]: values.map(({ value }) => value).join(','),\n }),\n {},\n ),\n // flatten attributes\n ...Object.entries(groupBy(attributeValues, 'attributeKey.name')).reduce(\n (acc, [key, values]) =>\n Object.assign(acc, {\n [key]: values.map(({ name }) => name).join(','),\n }),\n {},\n ),\n }),\n );\n\n // Write out to CSV\n const headers = uniq(data.map((d) => Object.keys(d)).flat());\n await writeCsv(file, data, headers);\n\n logger.info(\n colors.green(\n `Successfully wrote ${savedRequests.length} requests to file \"${file}\"`,\n ),\n );\n\n return savedRequests;\n}\n","import type { Got } from 'got';\nimport * as t from 'io-ts';\nimport { logger } from '../../logger';\nimport { uniq } from 'lodash-es';\nimport colors from 'colors';\nimport { splitCsvToList } from '../requests/splitCsvToList';\n\nconst ADMIN_URL =\n 'https://app.transcend.io/privacy-requests/incoming-requests/';\n/**\n * Minimal set required to mark as completed\n */\nexport const EnrichPrivacyRequest = t.record(t.string, t.string);\n\n/** Type override */\nexport type EnrichPrivacyRequest = t.TypeOf<typeof EnrichPrivacyRequest>;\n\n/**\n * Upload identifiers to a privacy request or mark request as\n *\n * @param sombra - Sombra instance configured to make requests\n * @param request - Request to enricher\n * @param enricherId - The ID of the enricher being uploaded to\n * @param index - Index of request ID\n * @returns True if enriched successfully, false if skipped, throws error if failed\n */\nexport async function enrichPrivacyRequest(\n sombra: Got,\n { id: rawId, ...rest }: EnrichPrivacyRequest,\n enricherId: string,\n index?: number,\n): Promise<boolean> {\n if (!rawId) {\n // error\n const msg = `Request ID must be provided to enricher request.${\n index ? ` Found error in row: ${index}` : ''\n }`;\n logger.error(colors.red(msg));\n throw new Error(msg);\n }\n\n const id = rawId.toLowerCase();\n\n // Pull out the identifiers\n const enrichedIdentifiers = Object.entries(rest).reduce(\n (acc, [key, value]) => {\n const values = uniq(splitCsvToList(value));\n return values.length === 0\n ? acc\n : Object.assign(acc, {\n [key]: uniq(splitCsvToList(value)).map((val) => ({\n value: key === 'email' ? val.toLowerCase() : val,\n })),\n });\n },\n {} as Record<string, string[]>,\n );\n\n // Make the GraphQL request\n try {\n await sombra\n .post('v1/enrich-identifiers', {\n headers: {\n 'x-transcend-request-id': id,\n 'x-transcend-enricher-id': enricherId,\n },\n json: {\n enrichedIdentifiers,\n },\n })\n .json();\n\n logger.error(\n colors.green(`Successfully enriched request: ${ADMIN_URL}${id}`),\n );\n return true;\n } catch (err) {\n // skip if already enriched\n if (\n typeof err.response.body === 'string' &&\n err.response.body.includes('Cannot update a resolved RequestEnricher')\n ) {\n logger.warn(\n colors.magenta(\n `Skipped enrichment for request: ${ADMIN_URL}${id}, request is no longer in the enriching phase.`,\n ),\n );\n return false;\n }\n\n // error\n logger.error(\n colors.red(\n `Failed to enricher identifiers for request with id: ${ADMIN_URL}${id} - ${err.message} - ${err.response.body}`,\n ),\n );\n throw err;\n }\n}\n","import colors from 'colors';\nimport { map } from '../bluebird';\nimport { logger } from '../../logger';\nimport {\n UPDATE_PRIVACY_REQUEST,\n buildTranscendGraphQLClient,\n createSombraGotInstance,\n makeGraphQLRequest,\n} from '../graphql';\nimport {\n enrichPrivacyRequest,\n EnrichPrivacyRequest,\n} from './enrichPrivacyRequest';\nimport { readCsv } from '../requests';\nimport { DEFAULT_TRANSCEND_API } from '../../constants';\n\n/**\n * Push a CSV of enriched requests back into Transcend\n *\n * @param options - Options\n * @returns Number of items processed\n */\nexport async function pushManualEnrichmentIdentifiersFromCsv({\n file,\n auth,\n sombraAuth,\n enricherId,\n markSilent,\n concurrency = 100,\n transcendUrl = DEFAULT_TRANSCEND_API,\n}: {\n /** CSV file path */\n file: string;\n /** Transcend API key authentication */\n auth: string;\n /** ID of enricher being uploaded to */\n enricherId: string;\n /** Sombra API key authentication */\n sombraAuth?: string;\n /** Concurrency */\n concurrency?: number;\n /** API URL for Transcend backend */\n transcendUrl?: string;\n /** Mark requests in silent mode before enriching */\n markSilent?: boolean;\n}): Promise<number> {\n // Create sombra instance to communicate with\n const sombra = await createSombraGotInstance(transcendUrl, auth, sombraAuth);\n const client = buildTranscendGraphQLClient(transcendUrl, auth);\n\n // Read from CSV\n logger.info(colors.magenta(`Reading \"${file}\" from disk`));\n const activeResults = readCsv(file, EnrichPrivacyRequest);\n\n // Notify Transcend\n logger.info(\n colors.magenta(`Enriching \"${activeResults.length}\" privacy requests.`),\n );\n\n let successCount = 0;\n let skippedCount = 0;\n let errorCount = 0;\n\n await map(\n activeResults,\n async (request, index) => {\n try {\n // Mark requests in silent mode before a certain date\n if (markSilent) {\n await makeGraphQLRequest(client, UPDATE_PRIVACY_REQUEST, {\n input: {\n id: request.id,\n isSilent: true,\n },\n });\n\n logger.info(\n colors.magenta(`Mark request as silent mode - ${request.id}`),\n );\n }\n\n const result = await enrichPrivacyRequest(\n sombra,\n request,\n enricherId,\n index,\n );\n if (result) {\n successCount += 1;\n } else {\n skippedCount += 1;\n }\n } catch (err) {\n errorCount += 1;\n }\n },\n { concurrency },\n );\n\n logger.info(\n colors.green(\n `Successfully notified Transcend! \\n Success count: ${successCount}.`,\n ),\n );\n\n if (skippedCount > 0) {\n logger.info(colors.magenta(`Skipped count: ${skippedCount}.`));\n }\n\n if (errorCount > 0) {\n logger.info(colors.red(`Error Count: ${errorCount}.`));\n throw new Error(`Failed to enrich: ${errorCount} requests.`);\n }\n\n return activeResults.length;\n}\n"],"mappings":"oRA+BA,eAAsB,EAAqC,CACzD,OACA,OACA,aACA,iBAAiB,EAAE,CACnB,cAAc,IACd,eAAeA,EAAAA,GAc4B,CAE3C,IAAM,EAASC,EAAAA,GAA4B,EAAc,EAAK,CACxD,EAAS,MAAMC,EAAAA,GAAwB,EAAc,EAAM,EAAW,CAE5E,EAAA,EAAO,KACL,EAAA,QAAO,QACL,6DAA6D,EAAe,KAC1E,IACD,GACF,CACF,CAGD,IAAM,EAAc,MAAMC,EAAAA,GAAiB,EAAQ,CACjD,QAAS,EACT,SAAU,CAACC,EAAAA,cAAc,UAAU,CACpC,CAAC,CAGI,EAAiD,EAAE,CAGzD,MAAMC,EAAAA,GACJ,EACA,KAAO,IAAY,CAEjB,IAAM,EAAmB,MAAMC,EAAAA,GAAyB,EAAQ,CAC9D,UAAW,EAAQ,GACpB,CAAC,CAQF,GAL4B,EAAiB,QAC1C,CAAE,YAAa,IAAW,kBAC5B,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CACxB,GAAI,CAEE,IACF,MAAMC,EAAAA,EAAmB,EAAQC,EAAAA,GAAwB,CACvD,MAAO,CACL,GAAI,EAAQ,GACZ,SAAU,GACX,CACF,CAAC,CAEF,EAAA,EAAO,KACL,EAAA,QAAO,QAAQ,iCAAiC,EAAQ,KAAK,CAC9D,EAGY,MAAM,EACnB,EACA,EACA,EACA,EACD,CAEC,GAAgB,EAEhB,GAAgB,OAEN,CACZ,GAAc,IAGlB,CAAE,cAAa,CAChB,CAED,EAAA,EAAO,KACL,EAAA,QAAO,MACL,sDAAsD,EAAa,GACpE,CACF,CAEG,EAAe,GACjB,EAAA,EAAO,KAAK,EAAA,QAAO,QAAQ,kBAAkB,EAAa,GAAG,CAAC,CAG5D,EAAa,EAEf,MADA,EAAA,EAAO,KAAK,EAAA,QAAO,IAAI,gBAAgB,EAAW,GAAG,CAAC,CAC5C,MAAM,qBAAqB,EAAW,YAAY,CAG9D,OAAO,EAAc"}
|
|
1
|
+
{"version":3,"file":"manual-enrichment-CzRiIFev.cjs","names":["DEFAULT_TRANSCEND_API","buildTranscendGraphQLClient","createSombraGotInstance","fetchAllRequests","RequestStatus","map","fetchAllRequestEnrichers","fetchAllRequestIdentifiers","groupBy","writeCsv","uniq","t","uniq","splitCsvToList","DEFAULT_TRANSCEND_API","createSombraGotInstance","buildTranscendGraphQLClient","readCsv","map","makeGraphQLRequest","UPDATE_PRIVACY_REQUEST"],"sources":["../src/lib/manual-enrichment/pullManualEnrichmentIdentifiersToCsv.ts","../src/lib/manual-enrichment/enrichPrivacyRequest.ts","../src/lib/manual-enrichment/pushManualEnrichmentIdentifiersFromCsv.ts"],"sourcesContent":["import { RequestAction, RequestStatus } from '@transcend-io/privacy-types';\nimport { map } from '../bluebird';\nimport colors from 'colors';\nimport { groupBy, uniq } from 'lodash-es';\nimport { DEFAULT_TRANSCEND_API } from '../../constants';\nimport { writeCsv } from '../helpers/writeCsv';\nimport {\n PrivacyRequest,\n RequestEnricher,\n RequestIdentifier,\n buildTranscendGraphQLClient,\n createSombraGotInstance,\n fetchAllRequestEnrichers,\n fetchAllRequestIdentifiers,\n fetchAllRequests,\n} from '../graphql';\nimport { logger } from '../../logger';\n\nexport interface PrivacyRequestWithIdentifiers extends PrivacyRequest {\n /** Request Enrichers */\n requestEnrichers: RequestEnricher[];\n /** Request Identifiers */\n requestIdentifiers: RequestIdentifier[];\n}\n\n/**\n * Pull the set of manual enrichment jobs to CSV\n *\n * @param options - Options\n * @returns List of requests with identifiers\n */\nexport async function pullManualEnrichmentIdentifiersToCsv({\n file,\n auth,\n sombraAuth,\n requestActions = [],\n concurrency = 100,\n transcendUrl = DEFAULT_TRANSCEND_API,\n}: {\n /** CSV file path */\n file: string;\n /** Transcend API key authentication */\n auth: string;\n /** Sombra API key */\n sombraAuth?: string;\n /** Concurrency */\n concurrency?: number;\n /** The request actions to fetch */\n requestActions?: RequestAction[];\n /** API URL for Transcend backend */\n transcendUrl?: string;\n}): Promise<PrivacyRequestWithIdentifiers[]> {\n // Find all requests made before createdAt that are in a removing data state\n const client = buildTranscendGraphQLClient(transcendUrl, auth);\n const sombra = await createSombraGotInstance(transcendUrl, auth, sombraAuth);\n\n logger.info(\n colors.magenta(\n `Pulling manual enrichment requests, filtered for actions: ${requestActions.join(\n ',',\n )}`,\n ),\n );\n\n // Pull all privacy requests\n const allRequests = await fetchAllRequests(client, {\n actions: requestActions,\n statuses: [RequestStatus.Enriching],\n });\n\n // Requests to save\n const savedRequests: PrivacyRequestWithIdentifiers[] = [];\n\n // Filter down requests to what is needed\n await map(\n allRequests,\n async (request) => {\n // Fetch enrichers\n const requestEnrichers = await fetchAllRequestEnrichers(client, {\n requestId: request.id,\n });\n\n // Check if manual enrichment exists for that request\n const hasManualEnrichment = requestEnrichers.filter(\n ({ status }) => status === 'ACTION_REQUIRED',\n );\n\n // Save request to queue\n if (hasManualEnrichment) {\n const requestIdentifiers = await fetchAllRequestIdentifiers(\n client,\n sombra,\n {\n requestId: request.id,\n },\n );\n savedRequests.push({\n ...request,\n requestIdentifiers,\n requestEnrichers,\n });\n }\n },\n {\n concurrency,\n },\n );\n\n const data = savedRequests.map(\n ({\n attributeValues,\n requestIdentifiers,\n requestEnrichers, // eslint-disable-line @typescript-eslint/no-unused-vars\n ...request\n }) => ({\n ...request,\n // flatten identifiers\n ...Object.entries(groupBy(requestIdentifiers, 'name')).reduce(\n (acc, [key, values]) =>\n Object.assign(acc, {\n [key]: values.map(({ value }) => value).join(','),\n }),\n {},\n ),\n // flatten attributes\n ...Object.entries(groupBy(attributeValues, 'attributeKey.name')).reduce(\n (acc, [key, values]) =>\n Object.assign(acc, {\n [key]: values.map(({ name }) => name).join(','),\n }),\n {},\n ),\n }),\n );\n\n // Write out to CSV\n const headers = uniq(data.map((d) => Object.keys(d)).flat());\n await writeCsv(file, data, headers);\n\n logger.info(\n colors.green(\n `Successfully wrote ${savedRequests.length} requests to file \"${file}\"`,\n ),\n );\n\n return savedRequests;\n}\n","import type { Got } from 'got';\nimport * as t from 'io-ts';\nimport { logger } from '../../logger';\nimport { uniq } from 'lodash-es';\nimport colors from 'colors';\nimport { splitCsvToList } from '../requests/splitCsvToList';\n\nconst ADMIN_URL =\n 'https://app.transcend.io/privacy-requests/incoming-requests/';\n/**\n * Minimal set required to mark as completed\n */\nexport const EnrichPrivacyRequest = t.record(t.string, t.string);\n\n/** Type override */\nexport type EnrichPrivacyRequest = t.TypeOf<typeof EnrichPrivacyRequest>;\n\n/**\n * Upload identifiers to a privacy request or mark request as\n *\n * @param sombra - Sombra instance configured to make requests\n * @param request - Request to enricher\n * @param enricherId - The ID of the enricher being uploaded to\n * @param index - Index of request ID\n * @returns True if enriched successfully, false if skipped, throws error if failed\n */\nexport async function enrichPrivacyRequest(\n sombra: Got,\n { id: rawId, ...rest }: EnrichPrivacyRequest,\n enricherId: string,\n index?: number,\n): Promise<boolean> {\n if (!rawId) {\n // error\n const msg = `Request ID must be provided to enricher request.${\n index ? ` Found error in row: ${index}` : ''\n }`;\n logger.error(colors.red(msg));\n throw new Error(msg);\n }\n\n const id = rawId.toLowerCase();\n\n // Pull out the identifiers\n const enrichedIdentifiers = Object.entries(rest).reduce(\n (acc, [key, value]) => {\n const values = uniq(splitCsvToList(value));\n return values.length === 0\n ? acc\n : Object.assign(acc, {\n [key]: uniq(splitCsvToList(value)).map((val) => ({\n value: key === 'email' ? val.toLowerCase() : val,\n })),\n });\n },\n {} as Record<string, string[]>,\n );\n\n // Make the GraphQL request\n try {\n await sombra\n .post('v1/enrich-identifiers', {\n headers: {\n 'x-transcend-request-id': id,\n 'x-transcend-enricher-id': enricherId,\n },\n json: {\n enrichedIdentifiers,\n },\n })\n .json();\n\n logger.error(\n colors.green(`Successfully enriched request: ${ADMIN_URL}${id}`),\n );\n return true;\n } catch (err) {\n // skip if already enriched\n if (\n typeof err.response.body === 'string' &&\n err.response.body.includes('Cannot update a resolved RequestEnricher')\n ) {\n logger.warn(\n colors.magenta(\n `Skipped enrichment for request: ${ADMIN_URL}${id}, request is no longer in the enriching phase.`,\n ),\n );\n return false;\n }\n\n // error\n logger.error(\n colors.red(\n `Failed to enricher identifiers for request with id: ${ADMIN_URL}${id} - ${err.message} - ${err.response.body}`,\n ),\n );\n throw err;\n }\n}\n","import colors from 'colors';\nimport { map } from '../bluebird';\nimport { logger } from '../../logger';\nimport {\n UPDATE_PRIVACY_REQUEST,\n buildTranscendGraphQLClient,\n createSombraGotInstance,\n makeGraphQLRequest,\n} from '../graphql';\nimport {\n enrichPrivacyRequest,\n EnrichPrivacyRequest,\n} from './enrichPrivacyRequest';\nimport { readCsv } from '../requests';\nimport { DEFAULT_TRANSCEND_API } from '../../constants';\n\n/**\n * Push a CSV of enriched requests back into Transcend\n *\n * @param options - Options\n * @returns Number of items processed\n */\nexport async function pushManualEnrichmentIdentifiersFromCsv({\n file,\n auth,\n sombraAuth,\n enricherId,\n markSilent,\n concurrency = 100,\n transcendUrl = DEFAULT_TRANSCEND_API,\n}: {\n /** CSV file path */\n file: string;\n /** Transcend API key authentication */\n auth: string;\n /** ID of enricher being uploaded to */\n enricherId: string;\n /** Sombra API key authentication */\n sombraAuth?: string;\n /** Concurrency */\n concurrency?: number;\n /** API URL for Transcend backend */\n transcendUrl?: string;\n /** Mark requests in silent mode before enriching */\n markSilent?: boolean;\n}): Promise<number> {\n // Create sombra instance to communicate with\n const sombra = await createSombraGotInstance(transcendUrl, auth, sombraAuth);\n const client = buildTranscendGraphQLClient(transcendUrl, auth);\n\n // Read from CSV\n logger.info(colors.magenta(`Reading \"${file}\" from disk`));\n const activeResults = readCsv(file, EnrichPrivacyRequest);\n\n // Notify Transcend\n logger.info(\n colors.magenta(`Enriching \"${activeResults.length}\" privacy requests.`),\n );\n\n let successCount = 0;\n let skippedCount = 0;\n let errorCount = 0;\n\n await map(\n activeResults,\n async (request, index) => {\n try {\n // Mark requests in silent mode before a certain date\n if (markSilent) {\n await makeGraphQLRequest(client, UPDATE_PRIVACY_REQUEST, {\n input: {\n id: request.id,\n isSilent: true,\n },\n });\n\n logger.info(\n colors.magenta(`Mark request as silent mode - ${request.id}`),\n );\n }\n\n const result = await enrichPrivacyRequest(\n sombra,\n request,\n enricherId,\n index,\n );\n if (result) {\n successCount += 1;\n } else {\n skippedCount += 1;\n }\n } catch (err) {\n errorCount += 1;\n }\n },\n { concurrency },\n );\n\n logger.info(\n colors.green(\n `Successfully notified Transcend! \\n Success count: ${successCount}.`,\n ),\n );\n\n if (skippedCount > 0) {\n logger.info(colors.magenta(`Skipped count: ${skippedCount}.`));\n }\n\n if (errorCount > 0) {\n logger.info(colors.red(`Error Count: ${errorCount}.`));\n throw new Error(`Failed to enrich: ${errorCount} requests.`);\n }\n\n return activeResults.length;\n}\n"],"mappings":"oRA+BA,eAAsB,EAAqC,CACzD,OACA,OACA,aACA,iBAAiB,EAAE,CACnB,cAAc,IACd,eAAeA,EAAAA,GAc4B,CAE3C,IAAM,EAASC,EAAAA,GAA4B,EAAc,EAAK,CACxD,EAAS,MAAMC,EAAAA,GAAwB,EAAc,EAAM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BG,CAElB,IAAM,EAAS,MAAMC,EAAAA,GAAwB,EAAc,EAAM,EAAW,CACtE,EAASC,EAAAA,GAA4B,EAAc,EAAK,CAG9D,EAAA,EAAO,KAAK,EAAA,QAAO,QAAQ,YAAY,EAAK,aAAa,CAAC,CAC1D,IAAM,EAAgBC,EAAAA,GAAQ,EAAM,EAAqB,CAGzD,EAAA,EAAO,KACL,EAAA,QAAO,QAAQ,cAAc,EAAc,OAAO,qBAAqB,CACxE,CAED,IAAI,EAAe,EACf,EAAe,EACf,EAAa,EAgDjB,GA9CA,MAAMC,EAAAA,GACJ,EACA,MAAO,EAAS,IAAU,CACxB,GAAI,CAEE,IACF,MAAMC,EAAAA,EAAmB,EAAQC,EAAAA,GAAwB,CACvD,MAAO,CACL,GAAI,EAAQ,GACZ,SAAU,GACX,CACF,CAAC,CAEF,EAAA,EAAO,KACL,EAAA,QAAO,QAAQ,iCAAiC,EAAQ,KAAK,CAC9D,EAGY,MAAM,EACnB,EACA,EACA,EACA,EACD,CAEC,GAAgB,EAEhB,GAAgB,OAEN,CACZ,GAAc,IAGlB,CAAE,cAAa,CAChB,CAED,EAAA,EAAO,KACL,EAAA,QAAO,MACL,sDAAsD,EAAa,GACpE,CACF,CAEG,EAAe,GACjB,EAAA,EAAO,KAAK,EAAA,QAAO,QAAQ,kBAAkB,EAAa,GAAG,CAAC,CAG5D,EAAa,EAEf,MADA,EAAA,EAAO,KAAK,EAAA,QAAO,IAAI,gBAAgB,EAAW,GAAG,CAAC,CAC5C,MAAM,qBAAqB,EAAW,YAAY,CAG9D,OAAO,EAAc"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require(`./
|
|
2
|
-
//# sourceMappingURL=mergeTranscendInputs-
|
|
1
|
+
const e=require(`./chunk-Bmb41Sf3.cjs`);let t=require(`@transcend-io/type-utils`);function n(e,...n){let r=JSON.parse(JSON.stringify(e));return n.forEach(e=>{(0,t.getEntries)(e).forEach(([e,t])=>{r[e]===void 0?r[e]=t:Array.isArray(t)?r[e]=[...r[e],...t]:r[e]=t})}),r}Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return n}});
|
|
2
|
+
//# sourceMappingURL=mergeTranscendInputs-BIBCYbug.cjs.map
|
package/dist/{mergeTranscendInputs-PPpGbYgG.cjs.map → mergeTranscendInputs-BIBCYbug.cjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeTranscendInputs-
|
|
1
|
+
{"version":3,"file":"mergeTranscendInputs-BIBCYbug.cjs","names":[],"sources":["../src/lib/mergeTranscendInputs.ts"],"sourcesContent":["import { TranscendInput } from '../codecs';\nimport { getEntries } from '@transcend-io/type-utils';\n\n/**\n * Combine a set of TranscendInput yaml files into a single yaml\n *\n * @param base - Base input\n * @param inputs - The list of inputs\n * @returns Merged input\n */\nexport function mergeTranscendInputs(\n base: TranscendInput,\n ...inputs: TranscendInput[]\n): TranscendInput {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const cloned: any = JSON.parse(JSON.stringify(base));\n inputs.forEach((input) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n getEntries(input).forEach(([key, value]: [any, any]) => {\n if (cloned[key] === undefined) {\n cloned[key] = value;\n } else if (Array.isArray(value)) {\n cloned[key] = [...cloned[key], ...value];\n } else {\n cloned[key] = value;\n }\n });\n });\n return cloned;\n}\n"],"mappings":"kFAUA,SAAgB,EACd,EACA,GAAG,EACa,CAEhB,IAAM,EAAc,KAAK,MAAM,KAAK,UAAU,EAAK,CAAC,CAapD,OAZA,EAAO,QAAS,GAAU,EAExB,EAAA,EAAA,YAAW,EAAM,CAAC,SAAS,CAAC,EAAK,KAAuB,CAClD,EAAO,KAAS,IAAA,GAClB,EAAO,GAAO,EACL,MAAM,QAAQ,EAAM,CAC7B,EAAO,GAAO,CAAC,GAAG,EAAO,GAAM,GAAG,EAAM,CAExC,EAAO,GAAO,GAEhB,EACF,CACK"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const e=require(`./
|
|
1
|
+
const e=require(`./chunk-Bmb41Sf3.cjs`),t=require(`./constants-7qBywLgI.cjs`),n=require(`./syncConfigurationToTranscend-Bd0ZTIm1.cjs`),r=require(`./logger-DQwEYtSS.cjs`);let i=require(`node:fs`),a=require(`node:os`),o=require(`node:path`),s=require(`colors`);s=e.t(s);let c=require(`node:child_process`),l=require(`node:readline`);l=e.t(l);function u(e,t){let n=Math.max(1,a.availableParallelism?.()??1);return{poolSize:typeof e==`number`&&e>0?Math.min(e,t):Math.min(n,t),cpuCount:n}}function d(e){return`'${String(e).replace(/'/g,`'\\''`)}'`}function f(e,t,n=!1){if(n)return;let i=(0,a.platform)();try{if(i===`darwin`){(0,c.spawn)(`osascript`,[`-e`,`
|
|
2
2
|
tell application "Terminal"
|
|
3
3
|
activate
|
|
4
4
|
do script "printf '\\e]0;${t}\\a'; tail -n +1 -f ${e.map(d).join(` -f `)}"
|
|
@@ -20,4 +20,4 @@ Stopping workers...
|
|
|
20
20
|
`))}process.stdin.resume()}B=k({workers:w,onAttach:U,onDetach:W,onCtrlC:H,getLogPaths:e=>N(e,w,E),replayBytes:200*1024,replayWhich:[`out`,`err`],onEnterAttachScreen:U}),e.extraKeyHandler&&(L=e.extraKeyHandler({logsBySlot:E,repaint:()=>R(),setPaused:e=>{I=e}}),process.stdin.on(`data`,L))}await new Promise(e=>{let t=setInterval(async()=>{if(A===0){if(clearInterval(t),P&&clearInterval(P),B(),L)try{process.stdin.off(`data`,L)}catch{}V();let n=Date.now();try{await l.postProcess?.({slots:T,totals:O,logDir:y,logsBySlot:E,startedAt:v,finishedAt:n,viewerMode:f,getLogPathsForSlot:e=>N(e,w,E)})}catch(e){let t=e?.stack??String(e);process.stdout.write(s.default.red(`postProcess error: ${t}\n`))}e()}},300)})}function B(e){let{logsBySlot:t,repaint:n,setPaused:r,exportMgr:i,exportStatus:a,custom:o}=e,s=e=>{process.stdout.write(`${e}\n`)},c=(e,t)=>{let r=Date.now(),i=a?.[e]??{path:t};a&&(a[e]={path:t||i.path,savedAt:r,exported:!0},n())},l=!1,u=(e,i)=>{l||(l=!0,r(!0),process.stdout.write(`\x1B[2J\x1B[H`),process.stdout.write(`Combined logs viewer (press Esc or Ctrl+] to return)
|
|
21
21
|
|
|
22
22
|
`),(async()=>{try{await w(t,e,i)}catch{l=!1,r(!1),n()}})())},d=(e,n)=>{if(i)try{let r=i.exportCombinedLogs(t,e);s(`\nWrote combined ${n} logs to: ${r}`),c(e,r)}catch{s(`\nFailed to write combined ${n} logs`)}};return e=>{let t=e.toString(`utf8`);if(t===`e`){u([`err`],`error`);return}if(t===`w`){u([`warn`,`err`],`warn`);return}if(t===`i`){u([`info`],`all`);return}if(t===`l`){u([`out`,`err`,`structured`],`all`);return}if(t===`E`){d(`error`,`error`);return}if(t===`W`){d(`warn`,`warn`);return}if(t===`I`){d(`info`,`info`);return}if(t===`A`){d(`all`,`ALL`);return}let i=o?.[t];if(i){i({noteExport:c,say:s});return}(t===`\x1B`||t===``)&&(l=!1,r(!1),n())}}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return B}});
|
|
23
|
-
//# sourceMappingURL=pooling-
|
|
23
|
+
//# sourceMappingURL=pooling-BJAPXDiq.cjs.map
|