@sourcegraph/amp 0.0.1748937736-gb61f9e → 0.0.1748966487-g086dc5
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/dist/amp.js +3 -3
- package/dist/client-Bj6KpOk2.js +55 -0
- package/dist/client-Bj6KpOk2.js.map +1 -0
- package/dist/{console-Dok1Wcwn.js → console-WZBKa2_s.js} +1158 -1124
- package/dist/console-WZBKa2_s.js.map +1 -0
- package/dist/{create_file.node-C-YeOXhP.js → create_file.node-D6oKdiaK.js} +2 -2
- package/dist/{create_file.node-C-YeOXhP.js.map → create_file.node-D6oKdiaK.js.map} +1 -1
- package/dist/{edit_file.node-Cvsfx7pt.js → edit_file.node-C3lbpZSk.js} +3 -3
- package/dist/{edit_file.node-Cvsfx7pt.js.map → edit_file.node-C3lbpZSk.js.map} +1 -1
- package/dist/{executable-DmtB95BF.js → executable-D4y8sKV4.js} +2 -2
- package/dist/{executable-DmtB95BF.js.map → executable-D4y8sKV4.js.map} +1 -1
- package/dist/{files-4uCbUmV7.js → files-CEnW8Te5.js} +2 -2
- package/dist/{files-4uCbUmV7.js.map → files-CEnW8Te5.js.map} +1 -1
- package/dist/{glob.node-RP059oWX.js → glob.node-DtAAWKuk.js} +4 -4
- package/dist/{glob.node-RP059oWX.js.map → glob.node-DtAAWKuk.js.map} +1 -1
- package/dist/{index-CPC32RPi.js → index-yLJ51JrQ.js} +2 -2
- package/dist/{index-CPC32RPi.js.map → index-yLJ51JrQ.js.map} +1 -1
- package/dist/{list_directory.node-JfCvF09W.js → list_directory.node-DuXkBPp1.js} +2 -2
- package/dist/{list_directory.node-JfCvF09W.js.map → list_directory.node-DuXkBPp1.js.map} +1 -1
- package/dist/{load-profile-CLxEjyWl.js → load-profile-DUN0D9h6.js} +2 -2
- package/dist/{load-profile-CLxEjyWl.js.map → load-profile-DUN0D9h6.js.map} +1 -1
- package/dist/{main-DpQQJHE4.js → main-DNwFD-Er.js} +1229 -1248
- package/dist/main-DNwFD-Er.js.map +1 -0
- package/dist/{node-Bjgpi_MV.js → node-C8blWycG.js} +3 -3
- package/dist/{node-Bjgpi_MV.js.map → node-C8blWycG.js.map} +1 -1
- package/dist/node-CQuCHRDF.js +43 -0
- package/dist/node-CQuCHRDF.js.map +1 -0
- package/dist/{node-D2BIeojc.js → node-CSv3f7ne.js} +2 -2
- package/dist/{node-D2BIeojc.js.map → node-CSv3f7ne.js.map} +1 -1
- package/dist/{node-CHXrHmHR.js → node-CtPLPXha.js} +2 -2
- package/dist/{node-CHXrHmHR.js.map → node-CtPLPXha.js.map} +1 -1
- package/dist/{node-CdCbaOgJ.js → node-DJUqAtoc.js} +3 -3
- package/dist/{node-CdCbaOgJ.js.map → node-DJUqAtoc.js.map} +1 -1
- package/dist/{node-3gS1o4eu.js → node-nwKa5RmL.js} +4 -4
- package/dist/{node-3gS1o4eu.js.map → node-nwKa5RmL.js.map} +1 -1
- package/dist/{read_file.node-BEjFBYF8.js → read_file.node-KOcMNCMh.js} +2 -2
- package/dist/{read_file.node-BEjFBYF8.js.map → read_file.node-KOcMNCMh.js.map} +1 -1
- package/dist/{stdio-h4IgaI9t.js → stdio-hr3iIXJ9.js} +3 -3
- package/dist/{stdio-h4IgaI9t.js.map → stdio-hr3iIXJ9.js.map} +1 -1
- package/dist/storybook.js +1 -1
- package/dist/{undo_edit.node-DnT_lcaR.js → undo_edit.node-DaZlFIHb.js} +2 -2
- package/dist/{undo_edit.node-DnT_lcaR.js.map → undo_edit.node-DaZlFIHb.js.map} +1 -1
- package/package.json +1 -1
- package/dist/client-TG0TgWWB.js +0 -35
- package/dist/client-TG0TgWWB.js.map +0 -1
- package/dist/console-Dok1Wcwn.js.map +0 -1
- package/dist/main-DpQQJHE4.js.map +0 -1
- package/dist/node-B0o5uOa2.js +0 -26
- package/dist/node-B0o5uOa2.js.map +0 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"undo_edit.node-
|
1
|
+
{"version":3,"file":"undo_edit.node-DaZlFIHb.js","sources":["../../core/src/tools/builtin/filesystem/undo_edit.node.ts"],"sourcesContent":["import { promiseFactoryToObservable } from '@sourcegraph/observable'\nimport crypto from 'node:crypto'\nimport fs, { writeFile } from 'node:fs/promises'\nimport os from 'node:os'\nimport path from 'path'\nimport logger from '../../../common/logger'\nimport { checkDirURIIsFile } from '../node-helpers'\nimport { createUnifiedDiff, formatDiffAsMarkdown } from './edit_file.common'\nimport type { UndoEditToolDef, undoEditToolReg } from './undo_edit.common'\n\nconst MAX_FILES = 50\nconst editQueue: string[] = []\n\nexport async function recordEdit(\n\tfilePath: string,\n\toldContent: string,\n\tnewContent: string,\n): Promise<void> {\n\ttry {\n\t\tconst hashedFilename = getHashedFilename(filePath)\n\t\tconst tempDir = await getTempDir()\n\t\tconst editFile = path.join(tempDir, hashedFilename)\n\n\t\tconst editData = { filePath, oldContent, newContent }\n\t\tawait fs.writeFile(editFile, JSON.stringify(editData), 'utf-8')\n\n\t\t// Update the FIFO queue\n\t\t// Remove if already in queue (to add it to the end)\n\t\tconst existingIndex = editQueue.indexOf(hashedFilename)\n\t\tif (existingIndex >= 0) {\n\t\t\teditQueue.splice(existingIndex, 1)\n\t\t}\n\n\t\t// Add to end of queue (most recent)\n\t\teditQueue.push(hashedFilename)\n\n\t\t// If we exceed the limit, remove the oldest edit\n\t\tif (editQueue.length > MAX_FILES) {\n\t\t\tconst oldestFile = editQueue.shift()\n\t\t\tif (oldestFile) {\n\t\t\t\tconst oldestPath = path.join(tempDir, oldestFile)\n\t\t\t\tawait fs.unlink(oldestPath).catch(() => {})\n\t\t\t}\n\t\t}\n\t} catch (error) {\n\t\tlogger.error('Failed to record edit:', error)\n\t}\n}\n\n// Function to get and remove the most recent edit for a file\nexport async function getLastEdit(\n\tfilePath: string,\n): Promise<{ oldContent: string; newContent: string } | undefined> {\n\ttry {\n\t\tconst hashedFilename = getHashedFilename(filePath)\n\t\tconst tempDir = await getTempDir()\n\t\tconst editFile = path.join(tempDir, hashedFilename)\n\n\t\ttry {\n\t\t\tawait fs.access(editFile)\n\t\t} catch {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst editDataStr = await fs.readFile(editFile, 'utf-8')\n\t\tconst editData = JSON.parse(editDataStr) as {\n\t\t\tfilePath: string\n\t\t\toldContent: string\n\t\t\tnewContent: string\n\t\t}\n\n\t\t// Remove from queue and delete file\n\t\tconst queueIndex = editQueue.indexOf(hashedFilename)\n\t\tif (queueIndex >= 0) {\n\t\t\teditQueue.splice(queueIndex, 1)\n\t\t}\n\t\tawait fs.unlink(editFile).catch(() => {})\n\n\t\treturn { oldContent: editData.oldContent, newContent: editData.newContent }\n\t} catch (error) {\n\t\tlogger.error('Failed to get last edit:', error)\n\t\treturn undefined\n\t}\n}\n\nexport const nodeUndoEditTool: NonNullable<(typeof undoEditToolReg)['fn']> = (\n\t{ args },\n\t{ dir, threadID, trackFileChange },\n) => {\n\treturn promiseFactoryToObservable(async (signal) => {\n\t\tcheckDirURIIsFile(dir)\n\t\tcheckUndoEditArgs(args)\n\n\t\tconst filePath = path.resolve(dir.fsPath, args.path)\n\n\t\t// Get the last edit from history (now async)\n\t\tconst lastEdit = await getLastEdit(args.path)\n\t\tif (!lastEdit) {\n\t\t\treturn {\n\t\t\t\tstatus: 'error' as const,\n\t\t\t\tprogress: {},\n\t\t\t\terror: {\n\t\t\t\t\tmessage: `No edit history found for file '${args.path}'.`,\n\t\t\t\t},\n\t\t\t}\n\t\t}\n\n\t\tconst diff = createUnifiedDiff(lastEdit.newContent, lastEdit.oldContent, args.path)\n\t\tconst formattedDiff = formatDiffAsMarkdown(diff)\n\n\t\tawait trackFileChange(filePath, async (path) => {\n\t\t\tawait writeFile(path, lastEdit.oldContent, {\n\t\t\t\tencoding: 'utf-8',\n\t\t\t\tsignal,\n\t\t\t})\n\t\t})\n\n\t\treturn { status: 'done', progress: {}, result: formattedDiff }\n\t})\n}\n\nfunction checkUndoEditArgs(args: UndoEditToolDef['args']): asserts args is UndoEditToolDef['args'] {\n\tif (typeof args !== 'object' || args === null) {\n\t\tthrow new Error('args must be an object. received instead: `' + JSON.stringify(args) + '`')\n\t}\n\tif (typeof args.path !== 'string') {\n\t\tthrow new Error(\n\t\t\t'path must be a string. received instead: `' + JSON.stringify(args.path) + '`',\n\t\t)\n\t}\n}\n\nlet tempDir = ''\nlet tempDirPromise: Promise<string> | null = null\n\nasync function getTempDir(): Promise<string> {\n\tif (tempDir) return tempDir\n\tif (!tempDirPromise) {\n\t\ttempDirPromise = fs\n\t\t\t.mkdtemp(path.join(os.tmpdir(), 'amp-edits-'))\n\t\t\t.then((dir) => {\n\t\t\t\ttempDir = dir\n\t\t\t\treturn dir\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tlogger.error('Failed to create edit history directory:', error)\n\t\t\t\tthrow error\n\t\t\t})\n\t}\n\treturn tempDirPromise\n}\n\nfunction getHashedFilename(filePath: string): string {\n\tconst hash = crypto.createHash('sha256').update(filePath).digest('hex').slice(0, 16)\n\treturn `${hash}-${path.basename(filePath)}`\n}\n"],"names":["MAX_FILES","editQueue","recordEdit","filePath","oldContent","newContent","hashedFilename","getHashedFilename","tempDir","getTempDir","editFile","path","editData","fs","existingIndex","oldestFile","oldestPath","error","logger","getLastEdit","editDataStr","queueIndex","nodeUndoEditTool","args","dir","threadID","trackFileChange","promiseFactoryToObservable","signal","checkDirURIIsFile","checkUndoEditArgs","lastEdit","diff","createUnifiedDiff","formattedDiff","formatDiffAsMarkdown","writeFile","tempDirPromise","os","crypto"],"mappings":";;;;;;AAUA,MAAMA,IAAY,IACZC,IAAsB,CAAC;AAEP,eAAAC,EACrBC,GACAC,GACAC,GACgB;AACZ,MAAA;AACG,UAAAC,IAAiBC,EAAkBJ,CAAQ,GAC3CK,IAAU,MAAMC,EAAW,GAC3BC,IAAWC,EAAK,KAAKH,GAASF,CAAc,GAE5CM,IAAW,EAAE,UAAAT,GAAU,YAAAC,GAAY,YAAAC,EAAW;AACpD,UAAMQ,EAAG,UAAUH,GAAU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AAE,MAAM,GAAG,EAAE,CACrE,IAAIQ,EAAK,SAASR,CAAQ,CAAC;AAC1C;"}
|
package/package.json
CHANGED
package/dist/client-TG0TgWWB.js
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
#!/usr/bin/env node
|
2
|
-
import { f as i, E as o, aR as n, s as p, p as c } from "./console-Dok1Wcwn.js";
|
3
|
-
const u = o.pipe(
|
4
|
-
p(({ settings: e, secrets: t }) => c(async () => await t.getToken("apiKey", e.url) !== void 0))
|
5
|
-
);
|
6
|
-
async function w(e, t) {
|
7
|
-
const r = await i(o, t?.signal ?? void 0);
|
8
|
-
return f(r, e, t);
|
9
|
-
}
|
10
|
-
async function f(e, t, r) {
|
11
|
-
if (t.startsWith("http:") || t.startsWith("https:"))
|
12
|
-
throw new Error("input must be a path, not an absolute URL");
|
13
|
-
if (!t.startsWith("/"))
|
14
|
-
throw new Error("pathAndQuery must start with /");
|
15
|
-
const s = e.settings.url;
|
16
|
-
if (!s)
|
17
|
-
throw new Error("amp.url is not set");
|
18
|
-
const a = await e.secrets.getToken("apiKey", s);
|
19
|
-
if (!a)
|
20
|
-
throw new Error("Amp API key is not set");
|
21
|
-
return fetch(new URL(t, s), {
|
22
|
-
...r,
|
23
|
-
headers: {
|
24
|
-
...r?.headers,
|
25
|
-
...n(),
|
26
|
-
"Content-Type": "application/json",
|
27
|
-
Authorization: `Bearer ${a}`
|
28
|
-
}
|
29
|
-
});
|
30
|
-
}
|
31
|
-
export {
|
32
|
-
w as f,
|
33
|
-
u as i
|
34
|
-
};
|
35
|
-
//# sourceMappingURL=client-TG0TgWWB.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"client-TG0TgWWB.js","sources":["../../core/src/server-api/client.ts"],"sourcesContent":["import type { ThreadOperatorShare } from '@sourcegraph/amp-api-types'\nimport type { Observable } from '@sourcegraph/observable'\nimport {\n\tdistinctUntilChanged,\n\tfirstValueFrom,\n\tmap,\n\ttype pendingOperation,\n\tpromiseFactoryToObservable,\n\tswitchMap,\n\tswitchMapReplayOperation,\n} from '@sourcegraph/observable'\nimport { isEqualJSON } from '../common/isEqualJSON'\nimport { type PickResolvedConfiguration, resolvedConfig } from '../configuration/resolver'\nimport { clientIdentificationHeaders } from '../misc/known-clients'\nimport type { ThreadID } from '../threads/thread'\nimport type { ThreadService } from '../threads/thread-service'\nimport { FALLBACK_TO_OLD_INTERNAL_API, internalAPIClient } from './internal-api-client'\n\nexport const isAmpServerConfigured = resolvedConfig.pipe(\n\tswitchMap(({ settings, secrets }) => {\n\t\treturn promiseFactoryToObservable(async () => {\n\t\t\tconst apiKey = await secrets.getToken('apiKey', settings.url)\n\t\t\treturn apiKey !== undefined\n\t\t})\n\t}),\n)\n\n/**\n * Returns the URL to a thread on the Amp server.\n */\nexport function threadURL(ampURL: URL, threadID: ThreadID): URL {\n\treturn new URL(`/threads/${threadID}`, ampURL)\n}\n\n/**\n * Makes a request to the Amp API with the proper configuration\n */\nexport async function fetchFromAmpServer(\n\tpathAndQuery: string,\n\tinit?: RequestInit,\n): Promise<Response> {\n\tconst config = await firstValueFrom(resolvedConfig, init?.signal ?? undefined)\n\treturn fetchFromAmpServerWithConfig(config, pathAndQuery, init)\n}\n\nexport function watchOnAmpServer<T>(\n\tpathAndQuery: string,\n\tinit?: Omit<RequestInit, 'signal'>,\n): Observable<T | typeof pendingOperation | Error> {\n\treturn resolvedConfig.pipe(\n\t\tmap(\n\t\t\t({ settings, secrets }) =>\n\t\t\t\t({\n\t\t\t\t\tsettings: {\n\t\t\t\t\t\turl: settings.url,\n\t\t\t\t\t},\n\t\t\t\t\tsecrets,\n\t\t\t\t}) satisfies PickResolvedConfiguration<{\n\t\t\t\t\tsettings: 'url'\n\t\t\t\t\tsecrets: true\n\t\t\t\t}>,\n\t\t),\n\t\tdistinctUntilChanged(\n\t\t\t(a, b) => isEqualJSON(a.settings, b.settings) && a.secrets === b.secrets,\n\t\t),\n\t\tswitchMapReplayOperation((config) =>\n\t\t\tpromiseFactoryToObservable(async (signal) => {\n\t\t\t\tconst resp = await fetchFromAmpServerWithConfig(config, pathAndQuery, {\n\t\t\t\t\t...init,\n\t\t\t\t\tsignal,\n\t\t\t\t})\n\t\t\t\tif (!resp.ok) {\n\t\t\t\t\tconst text = await resp.text()\n\t\t\t\t\tif (text) {\n\t\t\t\t\t\tthrow new Error(`HTTP ${resp.status}: ${text}`)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthrow new Error(`HTTP ${resp.status}`)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn (await resp.json()) as T\n\t\t\t}),\n\t\t),\n\t)\n}\n\n/**\n * Share a thread with the operator (i.e., the Amp team).\n */\nexport async function shareThreadWithOperator(\n\tthreadService: ThreadService,\n\tthreadID: ThreadID,\n): Promise<void> {\n\tconst thread = await firstValueFrom(threadService.observe(threadID))\n\tif (!thread) {\n\t\tthrow new Error(`Thread not found: ${threadID}`)\n\t}\n\n\ttry {\n\t\tconst resp = await internalAPIClient.shareThreadWithOperator({ threadData: thread })\n\t\tif (!resp.ok) {\n\t\t\tthrow new Error(`Failed to share thread: ${resp.error.message}`)\n\t\t}\n\t} catch (error) {\n\t\tif (FALLBACK_TO_OLD_INTERNAL_API) {\n\t\t\tconst response = await fetchFromAmpServer('/api/internal/share-thread-with-operator', {\n\t\t\t\tmethod: 'POST',\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t},\n\t\t\t\tbody: JSON.stringify({ threadData: thread } as Pick<\n\t\t\t\t\tThreadOperatorShare,\n\t\t\t\t\t'threadData'\n\t\t\t\t>),\n\t\t\t})\n\t\t\tif (!response.ok) {\n\t\t\t\tconst text = await response.text()\n\t\t\t\tthrow new Error(`Failed to share thread: ${response.status} ${text}`)\n\t\t\t}\n\t\t} else {\n\t\t\tthrow error\n\t\t}\n\t}\n}\n\n/**\n * Submit autoedit feedback to the server.\n */\nexport async function submitAutoeditFeedback(feedbackData: {\n\tfile_path: string\n\tprefix: string\n\tsuffix: string\n\tcode_to_replace_prefix: string\n\tcode_to_replace_suffix: string\n\tcontext: Array<{\n\t\tidentifier: string\n\t\tcontent: string\n\t\tfile_path: string\n\t\tstart_line?: number\n\t\tend_line?: number\n\t\tmetadata?: {\n\t\t\ttime_since_action_ms?: number\n\t\t\tretriever_metadata?: Record<string, number | string>\n\t\t}\n\t}>\n\tchosen: string\n\trejected: string\n\tassertions: string\n}): Promise<void> {\n\tconst response = await fetchFromAmpServer('/api/tab/feedback', {\n\t\tmethod: 'POST',\n\t\theaders: {\n\t\t\t'Content-Type': 'application/json',\n\t\t},\n\t\tbody: JSON.stringify(feedbackData),\n\t})\n\n\tif (!response.ok) {\n\t\tconst text = await response.text()\n\t\tlet errorMessage: string\n\t\ttry {\n\t\t\tconst errorData = JSON.parse(text)\n\t\t\terrorMessage = errorData.error || `HTTP ${response.status}`\n\t\t} catch {\n\t\t\terrorMessage = text || `HTTP ${response.status}`\n\t\t}\n\t\tthrow new Error(`Failed to submit feedback: ${errorMessage}`)\n\t}\n}\n\nasync function fetchFromAmpServerWithConfig(\n\tconfig: PickResolvedConfiguration<{\n\t\tsettings: 'url'\n\t\tsecrets: true\n\t}>,\n\tpathAndQuery: string,\n\tinit?: RequestInit,\n): Promise<Response> {\n\tif (pathAndQuery.startsWith('http:') || pathAndQuery.startsWith('https:')) {\n\t\tthrow new Error('input must be a path, not an absolute URL')\n\t}\n\tif (!pathAndQuery.startsWith('/')) {\n\t\tthrow new Error('pathAndQuery must start with /')\n\t}\n\n\tconst baseURL = config.settings.url\n\tif (!baseURL) {\n\t\tthrow new Error('amp.url is not set')\n\t}\n\n\tconst apiKey = await config.secrets.getToken('apiKey', baseURL)\n\tif (!apiKey) {\n\t\tthrow new Error('Amp API key is not set')\n\t}\n\n\treturn fetch(new URL(pathAndQuery, baseURL), {\n\t\t...init,\n\t\theaders: {\n\t\t\t...init?.headers,\n\t\t\t...clientIdentificationHeaders(),\n\t\t\t'Content-Type': 'application/json',\n\t\t\tAuthorization: `Bearer ${apiKey}`,\n\t\t},\n\t})\n}\n"],"names":["isAmpServerConfigured","resolvedConfig","switchMap","settings","secrets","promiseFactoryToObservable","fetchFromAmpServer","pathAndQuery","init","config","firstValueFrom","fetchFromAmpServerWithConfig","baseURL","apiKey","clientIdentificationHeaders"],"mappings":";;AAkBO,MAAMA,IAAwBC,EAAe;AAAA,EACnDC,EAAU,CAAC,EAAE,UAAAC,GAAU,SAAAC,QACfC,EAA2B,YAClB,MAAMD,EAAQ,SAAS,UAAUD,EAAS,GAAG,MAC1C,MAClB,CACD;AACF;AAYsB,eAAAG,EACrBC,GACAC,GACoB;AACpB,QAAMC,IAAS,MAAMC,EAAeT,GAAgBO,GAAM,UAAU,MAAS;AACtE,SAAAG,EAA6BF,GAAQF,GAAcC,CAAI;AAC/D;AA8HA,eAAeG,EACdF,GAIAF,GACAC,GACoB;AACpB,MAAID,EAAa,WAAW,OAAO,KAAKA,EAAa,WAAW,QAAQ;AACjE,UAAA,IAAI,MAAM,2CAA2C;AAE5D,MAAI,CAACA,EAAa,WAAW,GAAG;AACzB,UAAA,IAAI,MAAM,gCAAgC;AAG3C,QAAAK,IAAUH,EAAO,SAAS;AAChC,MAAI,CAACG;AACE,UAAA,IAAI,MAAM,oBAAoB;AAGrC,QAAMC,IAAS,MAAMJ,EAAO,QAAQ,SAAS,UAAUG,CAAO;AAC9D,MAAI,CAACC;AACE,UAAA,IAAI,MAAM,wBAAwB;AAGzC,SAAO,MAAM,IAAI,IAAIN,GAAcK,CAAO,GAAG;AAAA,IAC5C,GAAGJ;AAAA,IACH,SAAS;AAAA,MACR,GAAGA,GAAM;AAAA,MACT,GAAGM,EAA4B;AAAA,MAC/B,gBAAgB;AAAA,MAChB,eAAe,UAAUD,CAAM;AAAA,IAAA;AAAA,EAChC,CACA;AACF;"}
|