Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions packages/requests-core/src/agents/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ export function documentTools(document: DocumentCapability | null): readonly Ant
const editable = editableDocument(document);
return [
...(editable === 'layout' ? layoutDocumentTools : editable === 'model' ? modelDocumentTools : []),
...(editable && document?.save === 1 ? [defineTool(SAVE_TOOL, 'Save the open document as a new private cloud version, as Save version does, with optional change notes. Returns the version number.', saveSchema)] : []),
// Saving and publishing are loose (not strict) tools: strict tools compile into one grammar per request, and a model tab's
// editing, guidance and clone tools leave no room for more. Their inputs are checked in the browser instead.
...(editable && document?.save === 1 ? [defineLooseTool(SAVE_TOOL, 'Save the open document as a new private cloud version, as Save version does, with optional change notes. Returns the version number.', saveSchema)] : []),
...(editable === 'model' && document?.publish === 1 ? [
defineTool(PUBLISHING_INFO_TOOL, 'Read what publishing this model to Commons needs: whether it can be published, its current publication if any, retained source licenses, the requester\'s collections, and the categories and licenses offered. Changes nothing.', publishingInfoSchema),
defineTool(PUBLISH_TOOL, 'Save a version and show the requester a card proposing a Commons publication of it. Only their click on the card publishes; returns what the card came to.', publishProposalSchema),
defineLooseTool(PUBLISHING_INFO_TOOL, 'Read what publishing this model to Commons needs: whether it can be published, its current publication if any, retained source licenses, the requester\'s collections, and the categories and licenses offered. Changes nothing.', publishingInfoSchema),
defineLooseTool(PUBLISH_TOOL, 'Save a version and show the requester a card proposing a Commons publication of it. Only their click on the card publishes; returns what the card came to.', publishProposalSchema),
] : []),
...(editable && document?.clone === 1 ? [defineTool(CLONE_TOOL, 'Propose a new document that copies the one open now. The requester confirms on a chat card that also offers copying inside this document; returns their choice.', cloneProposalSchema)] : []),
...(document?.guidance === 1 && document.apiVersion === 1 ? [
Expand Down
8 changes: 8 additions & 0 deletions packages/requests-core/src/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ describe('saving and publishing from AI Chat', () => {
expect(names({ type: 'model', apiVersion: 1, guidance: 1, save: 1, publish: 1 })).not.toContain(SAVE_TOOL);
});

it('keeps saving and publishing out of the strict tool grammar, which a model tab\'s other tools already fill', () => {
// The API refuses a request whose strict tools compile into too large a grammar ("The compiled grammar is too large").
const tools = documentTools({ type: 'model', apiVersion: 1, edit: 1, guidance: 1, clone: 1, save: 1, publish: 1 });
for (const name of [SAVE_TOOL, PUBLISHING_INFO_TOOL, PUBLISH_TOOL]) expect(tools.find(tool => tool.name === name)).not.toHaveProperty('strict');
const strict = tools.filter(tool => 'strict' in tool && tool.strict).map(tool => tool.name);
expect(strict).toEqual(documentTools({ type: 'model', apiVersion: 1, edit: 1, guidance: 1, clone: 1 }).filter(tool => 'strict' in tool && tool.strict).map(tool => tool.name));
});

it('ends quietly only after a publication made or a card cancelled', () => {
expect(quietPublishAnswer(publishAnswerOf('{"ok":true,"outcome":"published","title":"Shaker base","url":"https://commons.pushform.io/#models/design-1"}'))).toBe(true);
expect(quietPublishAnswer(publishAnswerOf('{"ok":true,"outcome":"cancel"}'))).toBe(true);
Expand Down