
import { __decorate, __param } from '../../../../../../../../../external/tslib/tslib.es6.js';
import { URI } from '../../../../../../base/common/uri.js';
import { localize } from '../../../../../../nls.js';
import { IFileService } from '../../../../../../platform/files/common/files.service.js';
import { ToolDataSource, ToolInvocationPresentation } from '../languageModelToolsService.js';
import { IChatArtifactsService } from '../chatArtifactsService.service.js';
import { MarkdownString } from '../../../../../../base/common/htmlContent.js';

const SetArtifactsToolId = "setArtifacts";
const inputSchema = {
    type: "object",
    properties: {
        artifacts: {
            type: "array",
            description: "The complete list of artifacts for this session. Overwrites any existing artifacts.",
            items: {
                type: "object",
                properties: {
                    label: {
                        type: "string",
                        description: "Display label for the artifact."
                    },
                    uri: {
                        type: "string",
                        description: "Fully qualified URI of the artifact (e.g. https://localhost:3000 or file:///path/to/file). Must include the scheme."
                    },
                    type: {
                        type: "string",
                        enum: ["devServer", "screenshot", "plan"],
                        description: "The type of artifact."
                    }
                },
                required: ["label"]
            }
        }
    },
    required: ["artifacts"]
};
const SetArtifactsToolData = {
    id: SetArtifactsToolId,
    toolReferenceName: "artifacts",
    legacyToolReferenceFullNames: ["Set Session Artifacts"],
    displayName: ( localize(7598, "Set Session Artifacts")),
    modelDescription: "Set the list of artifacts for the current session. Each artifact has a label and either a uri or a toolCallId+dataPartIndex reference, plus an optional type (devServer, screenshot, plan). This overwrites the entire artifact list. Use this to surface important links, screenshots, plans, drafts, or temporary markdown documents to the user. URIs must be fully qualified with a scheme (e.g. https://localhost:3000, file:///tmp/plan.md). To reference a screenshot or image from a previous tool result, use toolCallId and dataPartIndex instead of uri.",
    canBeReferencedInPrompt: true,
    source: ToolDataSource.Internal,
    inputSchema
};
let SetArtifactsTool = class SetArtifactsTool {
    constructor(_chatArtifactsService, _fileService) {
        this._chatArtifactsService = _chatArtifactsService;
        this._fileService = _fileService;
    }
    async prepareToolInvocation(_context, _token) {
        return {
            pastTenseMessage: ( new MarkdownString(( localize(7599, "Updated session artifacts")))),
            presentation: ToolInvocationPresentation.Hidden
        };
    }
    async invoke(invocation, _countTokens, _progress, _token) {
        const args = invocation.parameters;
        const chatSessionResource = invocation.context?.sessionResource;
        if (!chatSessionResource) {
            return {
                content: [{
                    kind: "text",
                    value: "Error: No session resource available"
                }]
            };
        }
        const artifacts = [];
        for (const a of args.artifacts ?? []) {
            let uri = a.uri;
            if (!uri) {
                uri = "";
            }
            if (uri) {
                const parsed = ( URI.parse(uri));
                if (parsed.scheme !== "http" && parsed.scheme !== "https") {
                    if (!(await this._fileService.exists(parsed))) {
                        throw ( new Error(( localize(7600, "Artifact URI does not exist: {0}", uri))));
                    }
                }
            }
            artifacts.push({
                label: a.label,
                uri,
                type: a.type
            });
        }
        this._chatArtifactsService.setArtifacts(chatSessionResource, artifacts);
        return {
            content: [{
                kind: "text",
                value: ( localize(7601, "Set {0} artifact(s)", artifacts.length))
            }]
        };
    }
};
SetArtifactsTool = ( __decorate([( __param(0, IChatArtifactsService)), ( __param(1, IFileService))], SetArtifactsTool));

export { SetArtifactsTool, SetArtifactsToolData, SetArtifactsToolId };
