-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add action versioning support #1241
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -27,6 +27,8 @@ import { Triggers } from "./models/triggers"; | |||||||||||||||||||||||||
import { getUserDataJson } from "./utils/config"; | ||||||||||||||||||||||||||
import { CEG } from "./utils/error"; | ||||||||||||||||||||||||||
import { COMPOSIO_SDK_ERROR_CODES } from "./utils/errors/src/constants"; | ||||||||||||||||||||||||||
import { getVersionsFromLockFileAsJson } from "./utils/lockFile"; | ||||||||||||||||||||||||||
import { actionLockProcessor } from "./utils/processor/action_lock"; | ||||||||||||||||||||||||||
import { | ||||||||||||||||||||||||||
fileInputProcessor, | ||||||||||||||||||||||||||
fileResponseProcessor, | ||||||||||||||||||||||||||
|
@@ -54,6 +56,12 @@ export class ComposioToolSet { | |||||||||||||||||||||||||
activeTriggers: ActiveTriggers; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
userActionRegistry: ActionRegistry; | ||||||||||||||||||||||||||
actionVersionMap: Record<string, string>; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
lockFile: { | ||||||||||||||||||||||||||
path: string | null; | ||||||||||||||||||||||||||
save: boolean; | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
private internalProcessors: { | ||||||||||||||||||||||||||
pre: TPreProcessor[]; | ||||||||||||||||||||||||||
|
@@ -79,19 +87,27 @@ export class ComposioToolSet { | |||||||||||||||||||||||||
* @param {string|null} config.runtime - Runtime environment | ||||||||||||||||||||||||||
* @param {string} config.entityId - Entity ID for operations | ||||||||||||||||||||||||||
* @param {Record<string, string>} config.connectedAccountIds - Map of app names to their connected account IDs | ||||||||||||||||||||||||||
* @param {Object} config.lockFile - Lock file configuration | ||||||||||||||||||||||||||
* @param {string} config.lockFile.path - Path to the lock file, Default: .composio.lock | ||||||||||||||||||||||||||
* @param {boolean} config.lockFile.lock - Whether to lock the file | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The lock file configuration in the constructor's JSDoc is incorrect. The parameter is documented as * @param {Object} config.lockFile - Lock file configuration
* @param {string} config.lockFile.path - Path to the lock file, Default: .composio.lock
* @param {boolean} config.lockFile.save - Whether to save version information to the lock file |
||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||
constructor({ | ||||||||||||||||||||||||||
apiKey, | ||||||||||||||||||||||||||
baseUrl, | ||||||||||||||||||||||||||
runtime, | ||||||||||||||||||||||||||
entityId, | ||||||||||||||||||||||||||
connectedAccountIds, | ||||||||||||||||||||||||||
lockFile, | ||||||||||||||||||||||||||
}: { | ||||||||||||||||||||||||||
apiKey?: string | null; | ||||||||||||||||||||||||||
baseUrl?: string | null; | ||||||||||||||||||||||||||
runtime?: string | null; | ||||||||||||||||||||||||||
entityId?: string; | ||||||||||||||||||||||||||
connectedAccountIds?: Record<string, string>; | ||||||||||||||||||||||||||
lockFile?: { | ||||||||||||||||||||||||||
path: string; | ||||||||||||||||||||||||||
save: boolean; | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
} = {}) { | ||||||||||||||||||||||||||
const clientApiKey: string | undefined = | ||||||||||||||||||||||||||
apiKey || | ||||||||||||||||||||||||||
|
@@ -113,6 +129,23 @@ export class ComposioToolSet { | |||||||||||||||||||||||||
this.integrations = this.client.integrations; | ||||||||||||||||||||||||||
this.activeTriggers = this.client.activeTriggers; | ||||||||||||||||||||||||||
this.connectedAccountIds = connectedAccountIds || {}; | ||||||||||||||||||||||||||
this.actionVersionMap = {}; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
this.lockFile = lockFile || { | ||||||||||||||||||||||||||
path: ".composio.lock", | ||||||||||||||||||||||||||
save: false, | ||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
if (this.lockFile.save) { | ||||||||||||||||||||||||||
if (!this.lockFile.path) { | ||||||||||||||||||||||||||
CEG.getCustomError(COMPOSIO_SDK_ERROR_CODES.SDK.INVALID_PARAMETER, { | ||||||||||||||||||||||||||
message: "Lock file path is required when save is true", | ||||||||||||||||||||||||||
description: "Lock file path is required when save is true", | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error handling here is incorrect. The error is created but not thrown, which means the code will continue executing with an invalid state. You should either throw the error or handle it appropriately: if (!this.lockFile.path) {
throw CEG.getCustomError(COMPOSIO_SDK_ERROR_CODES.SDK.INVALID_PARAMETER, {
message: "Lock file path is required when save is true",
description: "Lock file path is required when save is true",
});
} |
||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
Comment on lines
+140
to
+145
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing error throw after generating error with 📝 Committable Code Suggestion
Suggested change
|
||||||||||||||||||||||||||
const actionLock = actionLockProcessor.bind(this, this.lockFile.path); | ||||||||||||||||||||||||||
this.internalProcessors.schema.push(actionLock); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
this.userActionRegistry = new ActionRegistry(this.client); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
@@ -149,13 +182,17 @@ export class ComposioToolSet { | |||||||||||||||||||||||||
): Promise<RawActionData[]> { | ||||||||||||||||||||||||||
const parsedFilters = ZToolSchemaFilter.parse(filters); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const apps = await this.client.actions.list({ | ||||||||||||||||||||||||||
const actionVersions = this.lockFile.path | ||||||||||||||||||||||||||
? getVersionsFromLockFileAsJson(this.lockFile.path) | ||||||||||||||||||||||||||
: {}; | ||||||||||||||||||||||||||
const actions = await this.client.actions.list({ | ||||||||||||||||||||||||||
apps: parsedFilters.apps?.join(","), | ||||||||||||||||||||||||||
tags: parsedFilters.tags?.join(","), | ||||||||||||||||||||||||||
useCase: parsedFilters.useCase, | ||||||||||||||||||||||||||
actions: parsedFilters.actions?.join(","), | ||||||||||||||||||||||||||
usecaseLimit: parsedFilters.useCaseLimit, | ||||||||||||||||||||||||||
filterByAvailableApps: parsedFilters.filterByAvailableApps, | ||||||||||||||||||||||||||
actionVersions: actionVersions, | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const customActions = await this.userActionRegistry.getAllActions(); | ||||||||||||||||||||||||||
|
@@ -171,7 +208,7 @@ export class ComposioToolSet { | |||||||||||||||||||||||||
); | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const toolsActions = [...(apps?.items || []), ...toolsWithCustomActions]; | ||||||||||||||||||||||||||
const toolsActions = [...(actions?.items || []), ...toolsWithCustomActions]; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const allSchemaProcessor = [ | ||||||||||||||||||||||||||
...this.internalProcessors.schema, | ||||||||||||||||||||||||||
|
@@ -182,6 +219,10 @@ export class ComposioToolSet { | |||||||||||||||||||||||||
|
||||||||||||||||||||||||||
return toolsActions.map((tool) => { | ||||||||||||||||||||||||||
let schema = tool as RawActionData; | ||||||||||||||||||||||||||
if (schema?.version) { | ||||||||||||||||||||||||||
// store the version in the map for execution | ||||||||||||||||||||||||||
this.actionVersionMap[schema?.name.toUpperCase()] = schema?.version; | ||||||||||||||||||||||||||
Comment on lines
+222
to
+224
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Potential runtime error if 📝 Committable Code Suggestion
Suggested change
|
||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
allSchemaProcessor.forEach((processor) => { | ||||||||||||||||||||||||||
schema = processor({ | ||||||||||||||||||||||||||
actionName: schema?.name, | ||||||||||||||||||||||||||
|
@@ -277,11 +318,13 @@ export class ComposioToolSet { | |||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
const version = this.actionVersionMap[action.toUpperCase()]; | ||||||||||||||||||||||||||
const data = await this.client.getEntity(entityId).execute({ | ||||||||||||||||||||||||||
actionName: action, | ||||||||||||||||||||||||||
params: params, | ||||||||||||||||||||||||||
text: nlaText, | ||||||||||||||||||||||||||
connectedAccountId: connectedAccountId, | ||||||||||||||||||||||||||
version: version, | ||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
return this.processResponse(data, { | ||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -79,6 +79,7 @@ export class Entity { | |||||||||||||||||||||
params, | ||||||||||||||||||||||
text, | ||||||||||||||||||||||
connectedAccountId, | ||||||||||||||||||||||
version, | ||||||||||||||||||||||
}: ExecuteActionParams): Promise<ActionExecuteResponse> { | ||||||||||||||||||||||
Comment on lines
79
to
83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 📝 Committable Code Suggestion
Suggested change
|
||||||||||||||||||||||
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, { | ||||||||||||||||||||||
method: "execute", | ||||||||||||||||||||||
|
@@ -91,6 +92,7 @@ export class Entity { | |||||||||||||||||||||
params, | ||||||||||||||||||||||
text, | ||||||||||||||||||||||
connectedAccountId, | ||||||||||||||||||||||
version, | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
const action = await this.actionsModel.get({ | ||||||||||||||||||||||
actionName: actionName, | ||||||||||||||||||||||
|
@@ -104,6 +106,7 @@ export class Entity { | |||||||||||||||||||||
if (app.no_auth) { | ||||||||||||||||||||||
return this.actionsModel.execute({ | ||||||||||||||||||||||
actionName: actionName, | ||||||||||||||||||||||
version: version, | ||||||||||||||||||||||
requestBody: { | ||||||||||||||||||||||
input: params, | ||||||||||||||||||||||
appName: action.appKey, | ||||||||||||||||||||||
|
@@ -126,6 +129,7 @@ export class Entity { | |||||||||||||||||||||
} | ||||||||||||||||||||||
return this.actionsModel.execute({ | ||||||||||||||||||||||
actionName: actionName, | ||||||||||||||||||||||
version: version, | ||||||||||||||||||||||
requestBody: { | ||||||||||||||||||||||
// @ts-ignore | ||||||||||||||||||||||
connectedAccountId: connectedAccount?.id as unknown as string, | ||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,14 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import fs from "fs"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export const loadLockFile = (filePath: string) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const fileContent = fs.readFileSync(filePath, "utf8"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return JSON.parse(fileContent); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export const saveLockFile = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
filePath: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
actionName: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
version: string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fs.writeFileSync(filePath, JSON.stringify({ actionName, version }, null, 2)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+3
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing error handling for file operations. Wrap fs.readFileSync(), fs.writeFileSync(), and JSON.parse() in try-catch blocks to handle errors gracefully 📝 Committable Code Suggestion
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,60 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import logger from "../../utils/logger"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export const updateLockFileWithActionVersion = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
filePath: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
actionName: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
version: string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const actionVersions = getVersionsFromLockFileAsJson(filePath); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
actionVersions[actionName] = version; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
saveLockFile(filePath, actionVersions); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+3
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing input validation for 📝 Committable Code Suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export const getVersionsFromLockFileAsJson = (filePath: string) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const lockFileContent = require("fs").readFileSync(filePath, "utf8"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check warning on line 15 in js/src/sdk/utils/lockFile.ts
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using import fs from 'fs'; This makes the code more maintainable and follows better module import practices. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const actionVersions: Record<string, string> = {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const lines = lockFileContent.split("\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for (const line of lines) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (line) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const [actionName, version] = line.split("="); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
actionVersions[actionName] = version; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return actionVersions; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} catch (e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const error = e as NodeJS.ErrnoException; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (error.code === "ENOENT") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
logger.warn("Lock file does not exist, creating new one"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else if (error.code === "EACCES" || error.code === "EPERM") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
logger.error("Permission denied accessing lock file", e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
logger.warn("Error reading lock file", e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
export const saveLockFile = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
filePath: string, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
actionVersions: Record<string, string> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const lockFileContent = Object.entries(actionVersions) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.map(([actionName, version]) => `${actionName}=${version}`) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.join("\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
require("fs").writeFileSync(filePath, lockFileContent); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Check warning on line 46 in js/src/sdk/utils/lockFile.ts
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+15
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lock file read/write operations use dynamic 📝 Committable Code Suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} catch (e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const error = e as NodeJS.ErrnoException; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (error.code === "EACCES" || error.code === "EPERM") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
logger.error("Permission denied writing to lock file", e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
throw new Error("Permission denied writing to lock file"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else if (error.code === "ENOENT") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
logger.error("Directory does not exist for lock file", e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
throw new Error("Directory does not exist for lock file"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
logger.error("Error writing to lock file", e); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
throw new Error("Error writing to lock file"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { RawActionData } from "../../../types/base_toolset"; | ||
import { updateLockFileWithActionVersion } from "../lockFile"; | ||
|
||
export const actionLockProcessor = ( | ||
filePath: string, | ||
{ | ||
actionName, | ||
toolSchema, | ||
}: { | ||
actionName: string; | ||
toolSchema: RawActionData; | ||
} | ||
): RawActionData => { | ||
const version = toolSchema.version; | ||
|
||
updateLockFileWithActionVersion(filePath, actionName, version); | ||
|
||
return toolSchema; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The actionLockProcessor currently returns the toolSchema without any modification. If this is intended to be a placeholder for future version locking logic, it should be documented: export const actionLockProcessor = (
filePath: string,
{
actionName,
toolSchema,
}: {
actionName: string;
toolSchema: RawActionData;
}
): RawActionData => {
// TODO: Implement version locking logic
return toolSchema;
}; |
||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
lockFile.lock
parameter in JSDoc doesn't match the actual parameter namelockFile.save
in the code, causing incorrect documentation📝 Committable Code Suggestion