Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 8 additions & 29 deletions src/agent/runtime/project-skill-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,21 +176,6 @@ function isAccessDeniedError(
return options.isAccessDeniedError?.(error) ?? false;
}

function assertRuntimeSkillContent(content: string, label: string): void {
if (content.length > SKILL_DOCUMENT_MAX_CHARACTERS) {
throw new RangeError(
`${label} may contain at most ${SKILL_DOCUMENT_MAX_CHARACTERS} characters`,
);
}
}

async function readProjectSkillValue<T>(
budget: SkillOperationBudget,
read: () => Promise<T>,
): Promise<T> {
return await budget.run(() => read());
}

function getProjectSkillCancellationOptions(
budget: SkillOperationBudget,
): Pick<RuntimeProjectFilesApiOptions, "abortSignal" | "timeoutMs"> & {
Expand Down Expand Up @@ -251,13 +236,11 @@ async function getExpectedProjectFile(
request: RuntimeGetProjectFileOptions & RuntimeProjectSkillReadContext,
): Promise<RuntimeProjectFile | null> {
const { budget, ...fileRequest } = request;
const file = await readProjectSkillValue(
budget,
() =>
options.getProjectFile({
...fileRequest,
...getBoundedProjectSkillFileOptions(budget),
}),
const file = await budget.run(() =>
options.getProjectFile({
...fileRequest,
...getBoundedProjectSkillFileOptions(budget),
})
);
if (
file !== null &&
Expand Down Expand Up @@ -444,15 +427,16 @@ async function listProjectSkillReferences(
}

const allFiles = snapshotProjectFileList(
await readProjectSkillValue(input.budget, () =>
await input.budget.run(() =>
input.options.getProjectFiles({
projectId,
authToken: input.context.authToken,
branchId: input.context.branchId,
pathPrefix: skillDir,
maximumEntries: SKILL_LOADABLE_REFERENCE_LISTING_MAX_ENTRIES,
...getProjectSkillCancellationOptions(input.budget),
})),
})
),
);

return collectProjectSkillReferences({
Expand Down Expand Up @@ -532,7 +516,6 @@ async function loadProjectSkill(
content: catalogSkill.content,
})
) {
assertRuntimeSkillContent(catalogSkill.content, "Skill document");
return { instructions: catalogSkill.content, references: [] };
}
return null;
Expand All @@ -554,7 +537,6 @@ async function loadProjectSkill(
content: catalogSkill.content,
})
) {
assertRuntimeSkillContent(catalogSkill.content, "Skill document");
return {
instructions: catalogSkill.content,
references: await listProjectSkillReferences(input),
Expand Down Expand Up @@ -584,7 +566,6 @@ async function loadProjectSkill(
) {
return null;
}
assertRuntimeSkillContent(directorySkill.content, "Skill document");
return {
instructions: directorySkill.content,
references: await listProjectSkillReferences({ ...input, skillsPath }),
Expand All @@ -611,7 +592,6 @@ async function loadProjectSkill(
) {
return null;
}
assertRuntimeSkillContent(flatSkill.content, "Skill document");
return {
instructions: flatSkill.content,
references: [],
Expand Down Expand Up @@ -676,7 +656,6 @@ async function loadProjectSkillReference(
budget: input.budget,
});
if (projectFile !== null) {
assertRuntimeSkillContent(projectFile.content, "Skill reference");
return projectFile.content;
}
} catch (error) {
Expand Down
Loading