@hyorman/copilot-proxy-core 1.0.0
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/out/assistants/index.d.ts +15 -0
- package/out/assistants/index.js +16 -0
- package/out/assistants/index.js.map +1 -0
- package/out/assistants/routes.d.ts +16 -0
- package/out/assistants/routes.js +597 -0
- package/out/assistants/routes.js.map +1 -0
- package/out/assistants/runner.d.ts +48 -0
- package/out/assistants/runner.js +851 -0
- package/out/assistants/runner.js.map +1 -0
- package/out/assistants/state.d.ts +81 -0
- package/out/assistants/state.js +351 -0
- package/out/assistants/state.js.map +1 -0
- package/out/assistants/tools.d.ts +4 -0
- package/out/assistants/tools.js +8 -0
- package/out/assistants/tools.js.map +1 -0
- package/out/assistants/types.d.ts +254 -0
- package/out/assistants/types.js +5 -0
- package/out/assistants/types.js.map +1 -0
- package/out/backend.d.ts +24 -0
- package/out/backend.js +12 -0
- package/out/backend.js.map +1 -0
- package/out/index.d.ts +13 -0
- package/out/index.js +21 -0
- package/out/index.js.map +1 -0
- package/out/server.d.ts +12 -0
- package/out/server.js +504 -0
- package/out/server.js.map +1 -0
- package/out/skills/index.d.ts +3 -0
- package/out/skills/index.js +4 -0
- package/out/skills/index.js.map +1 -0
- package/out/skills/manifest.d.ts +25 -0
- package/out/skills/manifest.js +96 -0
- package/out/skills/manifest.js.map +1 -0
- package/out/skills/resolver.d.ts +22 -0
- package/out/skills/resolver.js +66 -0
- package/out/skills/resolver.js.map +1 -0
- package/out/skills/routes.d.ts +3 -0
- package/out/skills/routes.js +191 -0
- package/out/skills/routes.js.map +1 -0
- package/out/skills/state.d.ts +35 -0
- package/out/skills/state.js +155 -0
- package/out/skills/state.js.map +1 -0
- package/out/skills/storage.d.ts +30 -0
- package/out/skills/storage.js +171 -0
- package/out/skills/storage.js.map +1 -0
- package/out/skills/types.d.ts +141 -0
- package/out/skills/types.js +8 -0
- package/out/skills/types.js.map +1 -0
- package/out/toolConvert.d.ts +24 -0
- package/out/toolConvert.js +56 -0
- package/out/toolConvert.js.map +1 -0
- package/out/types.d.ts +291 -0
- package/out/types.js +2 -0
- package/out/types.js.map +1 -0
- package/out/utils.d.ts +28 -0
- package/out/utils.js +81 -0
- package/out/utils.js.map +1 -0
- package/package.json +36 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as zlib from 'zlib';
|
|
4
|
+
/**
|
|
5
|
+
* Process multipart files from multer into SkillFile array
|
|
6
|
+
*/
|
|
7
|
+
export function processMultipartFiles(files) {
|
|
8
|
+
return files.map(file => ({
|
|
9
|
+
path: file.originalname,
|
|
10
|
+
content: file.buffer,
|
|
11
|
+
size: file.size,
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Parse zip buffer and extract files
|
|
16
|
+
* Implements minimal zip format reader using Node.js built-ins
|
|
17
|
+
*/
|
|
18
|
+
export async function processZipUpload(zipBuffer) {
|
|
19
|
+
const files = [];
|
|
20
|
+
// Find End of Central Directory record (EOCD)
|
|
21
|
+
// EOCD signature: 0x06054b50, located at end of file
|
|
22
|
+
const endPos = zipBuffer.length;
|
|
23
|
+
let eocdOffset = -1;
|
|
24
|
+
const searchStart = Math.max(0, endPos - 0xffff - 22);
|
|
25
|
+
for (let i = endPos - 22; i >= searchStart; i--) {
|
|
26
|
+
if (zipBuffer[i] === 0x50 &&
|
|
27
|
+
zipBuffer[i + 1] === 0x4b &&
|
|
28
|
+
zipBuffer[i + 2] === 0x05 &&
|
|
29
|
+
zipBuffer[i + 3] === 0x06) {
|
|
30
|
+
eocdOffset = i;
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (eocdOffset === -1) {
|
|
35
|
+
throw new Error('Invalid zip file: End of Central Directory record not found');
|
|
36
|
+
}
|
|
37
|
+
// Parse EOCD
|
|
38
|
+
const diskNumber = zipBuffer.readUInt16LE(eocdOffset + 4);
|
|
39
|
+
const centralDirDisk = zipBuffer.readUInt16LE(eocdOffset + 6);
|
|
40
|
+
const totalEntries = zipBuffer.readUInt16LE(eocdOffset + 10);
|
|
41
|
+
const centralDirOffset = zipBuffer.readUInt32LE(eocdOffset + 16);
|
|
42
|
+
if (diskNumber !== 0 || centralDirDisk !== 0) {
|
|
43
|
+
throw new Error('Invalid zip file: multi-disk archives not supported');
|
|
44
|
+
}
|
|
45
|
+
// Parse central directory entries
|
|
46
|
+
let currentOffset = centralDirOffset;
|
|
47
|
+
for (let i = 0; i < totalEntries; i++) {
|
|
48
|
+
if (currentOffset + 46 > zipBuffer.length) {
|
|
49
|
+
throw new Error('Invalid zip file: corrupted central directory');
|
|
50
|
+
}
|
|
51
|
+
const signature = zipBuffer.readUInt32LE(currentOffset);
|
|
52
|
+
if (signature !== 0x02014b50) {
|
|
53
|
+
throw new Error('Invalid zip file: central directory entry signature mismatch');
|
|
54
|
+
}
|
|
55
|
+
const compressionMethod = zipBuffer.readUInt16LE(currentOffset + 10);
|
|
56
|
+
const compressedSize = zipBuffer.readUInt32LE(currentOffset + 20);
|
|
57
|
+
const filenameLength = zipBuffer.readUInt16LE(currentOffset + 28);
|
|
58
|
+
const extraFieldLength = zipBuffer.readUInt16LE(currentOffset + 30);
|
|
59
|
+
const fileCommentLength = zipBuffer.readUInt16LE(currentOffset + 32);
|
|
60
|
+
const localHeaderOffset = zipBuffer.readUInt32LE(currentOffset + 42);
|
|
61
|
+
// Read filename
|
|
62
|
+
const filename = zipBuffer
|
|
63
|
+
.slice(currentOffset + 46, currentOffset + 46 + filenameLength)
|
|
64
|
+
.toString('utf-8');
|
|
65
|
+
// Skip directory entries
|
|
66
|
+
if (!filename.endsWith('/')) {
|
|
67
|
+
// Read local file header to get actual file data offset
|
|
68
|
+
if (localHeaderOffset + 30 > zipBuffer.length) {
|
|
69
|
+
throw new Error('Invalid zip file: corrupted local file header');
|
|
70
|
+
}
|
|
71
|
+
const localHeaderSig = zipBuffer.readUInt32LE(localHeaderOffset);
|
|
72
|
+
if (localHeaderSig !== 0x04034b50) {
|
|
73
|
+
throw new Error('Invalid zip file: local file header signature mismatch');
|
|
74
|
+
}
|
|
75
|
+
const localFilenameLength = zipBuffer.readUInt16LE(localHeaderOffset + 26);
|
|
76
|
+
const localExtraFieldLength = zipBuffer.readUInt16LE(localHeaderOffset + 28);
|
|
77
|
+
const fileDataOffset = localHeaderOffset + 30 + localFilenameLength + localExtraFieldLength;
|
|
78
|
+
const fileDataEnd = fileDataOffset + compressedSize;
|
|
79
|
+
if (fileDataEnd > zipBuffer.length) {
|
|
80
|
+
throw new Error('Invalid zip file: file data extends beyond archive');
|
|
81
|
+
}
|
|
82
|
+
let fileContent;
|
|
83
|
+
const compressedData = zipBuffer.slice(fileDataOffset, fileDataEnd);
|
|
84
|
+
if (compressionMethod === 0) {
|
|
85
|
+
// Stored (no compression)
|
|
86
|
+
fileContent = compressedData;
|
|
87
|
+
}
|
|
88
|
+
else if (compressionMethod === 8) {
|
|
89
|
+
// Deflated
|
|
90
|
+
try {
|
|
91
|
+
fileContent = zlib.inflateRawSync(compressedData);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
throw new Error(`Failed to decompress file '${filename}': ${error instanceof Error ? error.message : String(error)}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
throw new Error(`Unsupported compression method ${compressionMethod} for file '${filename}'`);
|
|
99
|
+
}
|
|
100
|
+
files.push({
|
|
101
|
+
path: filename,
|
|
102
|
+
content: fileContent,
|
|
103
|
+
size: fileContent.length,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
// Move to next central directory entry
|
|
107
|
+
currentOffset += 46 + filenameLength + extraFieldLength + fileCommentLength;
|
|
108
|
+
}
|
|
109
|
+
return files;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Get the skill storage directory
|
|
113
|
+
*/
|
|
114
|
+
export function getSkillStorageDir(extensionPath) {
|
|
115
|
+
const storageDir = path.join(extensionPath, 'skill-bundles');
|
|
116
|
+
fs.mkdirSync(storageDir, { recursive: true });
|
|
117
|
+
return storageDir;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Save a skill version to disk
|
|
121
|
+
*/
|
|
122
|
+
export function saveSkillVersion(storageDir, skillId, version, files) {
|
|
123
|
+
const baseDir = path.resolve(storageDir, skillId, `v${version}`);
|
|
124
|
+
for (const file of files) {
|
|
125
|
+
// Validate file path to prevent path traversal (zip-slip)
|
|
126
|
+
const filePath = path.resolve(baseDir, file.path);
|
|
127
|
+
if (!filePath.startsWith(baseDir + path.sep) && filePath !== baseDir) {
|
|
128
|
+
throw new Error(`Invalid file path: ${file.path}`);
|
|
129
|
+
}
|
|
130
|
+
const fileDir = path.dirname(filePath);
|
|
131
|
+
fs.mkdirSync(fileDir, { recursive: true });
|
|
132
|
+
fs.writeFileSync(filePath, file.content);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Delete a specific skill version
|
|
137
|
+
*/
|
|
138
|
+
export function deleteSkillVersion(storageDir, skillId, version) {
|
|
139
|
+
const versionDir = path.join(storageDir, skillId, `v${version}`);
|
|
140
|
+
fs.rmSync(versionDir, { recursive: true, force: true });
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Delete all versions of a skill
|
|
144
|
+
*/
|
|
145
|
+
export function deleteSkillStorage(storageDir, skillId) {
|
|
146
|
+
const skillDir = path.join(storageDir, skillId);
|
|
147
|
+
fs.rmSync(skillDir, { recursive: true, force: true });
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Guess MIME type based on file extension
|
|
151
|
+
*/
|
|
152
|
+
export function guessContentType(filePath) {
|
|
153
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
154
|
+
const mimeTypes = {
|
|
155
|
+
'.md': 'text/markdown',
|
|
156
|
+
'.py': 'text/x-python',
|
|
157
|
+
'.js': 'application/javascript',
|
|
158
|
+
'.ts': 'text/typescript',
|
|
159
|
+
'.json': 'application/json',
|
|
160
|
+
'.txt': 'text/plain',
|
|
161
|
+
'.csv': 'text/csv',
|
|
162
|
+
'.zip': 'application/zip',
|
|
163
|
+
'.yaml': 'text/yaml',
|
|
164
|
+
'.yml': 'text/yaml',
|
|
165
|
+
'.html': 'text/html',
|
|
166
|
+
'.css': 'text/css',
|
|
167
|
+
'.sh': 'application/x-sh',
|
|
168
|
+
};
|
|
169
|
+
return mimeTypes[ext] || 'application/octet-stream';
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/skills/storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAG7B;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,KAA4B;IAChE,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACxB,IAAI,EAAE,IAAI,CAAC,YAAY;QACvB,OAAO,EAAE,IAAI,CAAC,MAAM;QACpB,IAAI,EAAE,IAAI,CAAC,IAAI;KAChB,CAAC,CAAC,CAAC;AACN,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,SAAiB;IACtD,MAAM,KAAK,GAAgB,EAAE,CAAC;IAE9B,8CAA8C;IAC9C,qDAAqD;IACrD,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;IAChC,IAAI,UAAU,GAAG,CAAC,CAAC,CAAC;IAEpB,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,EAAE,CAAC,CAAC;IACtD,KAAK,IAAI,CAAC,GA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AAU,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE,IAAI,OAAO,EAAE,CAAC,CAAC;IACjE,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC1D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAAkB,EAAE,OAAe;IACpE,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAChD,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AACxD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC/C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;IAEjD,MAAM,SAAS,GAA2B;QACxC,KAAK,EAAE,eAAe;QACtB,KAAK,EAAE,eAAe;QACtB,KAAK,EAAE,wBAAwB;QAC/B,KAAK,EAAE,iBAAiB;QACxB,OAAO,EAAE,kBAAkB;QAC3B,MAAM,EAAE,YAAY;QACpB,MAAM,EAAE,UAAU;QAClB,MAAM,EAAE,iBAAiB;QACzB,OAAO,EAAE,WAAW;QACpB,MAAM,EAAE,WAAW;QACnB,OAAO,EAAE,WAAW;QACpB,MAAM,EAAE,UAAU;QAClB,KAAK,EAAE,kBAAkB;KAC1B,CAAC;IAEF,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,0BAA0B,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI-Compatible Skills API Types
|
|
3
|
+
*
|
|
4
|
+
* Skills are versioned file bundles anchored by a SKILL.md manifest.
|
|
5
|
+
* They are NOT function tools — they are reusable instruction + code bundles.
|
|
6
|
+
*/
|
|
7
|
+
export { OpenAIListResponse, PaginationParams } from '../assistants/types.js';
|
|
8
|
+
/**
|
|
9
|
+
* A single file within a skill bundle.
|
|
10
|
+
*/
|
|
11
|
+
export interface SkillFile {
|
|
12
|
+
/** Relative path within the bundle (e.g., "my_skill/SKILL.md") */
|
|
13
|
+
path: string;
|
|
14
|
+
/** Raw file content */
|
|
15
|
+
content: Buffer;
|
|
16
|
+
/** File size in bytes */
|
|
17
|
+
size: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Parsed SKILL.md manifest metadata and body.
|
|
21
|
+
*/
|
|
22
|
+
export interface SkillManifest {
|
|
23
|
+
/** Skill name from SKILL.md frontmatter */
|
|
24
|
+
name: string;
|
|
25
|
+
/** Skill description from SKILL.md frontmatter */
|
|
26
|
+
description: string;
|
|
27
|
+
/** Markdown body content after frontmatter */
|
|
28
|
+
body: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Metadata about a file stored in a skill version.
|
|
32
|
+
*/
|
|
33
|
+
export interface SkillVersionFile {
|
|
34
|
+
/** Relative path within the bundle */
|
|
35
|
+
path: string;
|
|
36
|
+
/** File size in bytes */
|
|
37
|
+
size: number;
|
|
38
|
+
/** MIME type (guessed from file extension) */
|
|
39
|
+
content_type: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A specific version of a skill with its complete manifest and file manifest.
|
|
43
|
+
*/
|
|
44
|
+
export interface SkillVersion {
|
|
45
|
+
/** Version number (integer, starts at 1) */
|
|
46
|
+
version: number;
|
|
47
|
+
/** Creation timestamp (Unix seconds) */
|
|
48
|
+
created_at: number;
|
|
49
|
+
/** File manifest for this version */
|
|
50
|
+
files: SkillVersionFile[];
|
|
51
|
+
/** Parsed manifest from SKILL.md */
|
|
52
|
+
manifest: SkillManifest;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A complete skill object with full versioning history.
|
|
56
|
+
*/
|
|
57
|
+
export interface Skill {
|
|
58
|
+
/** Skill ID (e.g., "skill_abc123") */
|
|
59
|
+
id: string;
|
|
60
|
+
/** Object type identifier */
|
|
61
|
+
object: 'skill';
|
|
62
|
+
/** Creation timestamp (Unix seconds) */
|
|
63
|
+
created_at: number;
|
|
64
|
+
/** Skill name from manifest */
|
|
65
|
+
name: string;
|
|
66
|
+
/** Skill description from manifest */
|
|
67
|
+
description: string;
|
|
68
|
+
/** Default version number */
|
|
69
|
+
default_version: number;
|
|
70
|
+
/** Latest version number */
|
|
71
|
+
latest_version: number;
|
|
72
|
+
/** All versions of this skill */
|
|
73
|
+
versions: SkillVersion[];
|
|
74
|
+
/** User-defined metadata as key-value pairs */
|
|
75
|
+
metadata: Record<string, string>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* API response for a skill (summary without versions array).
|
|
79
|
+
*/
|
|
80
|
+
export interface SkillResponse {
|
|
81
|
+
/** Skill ID (e.g., "skill_abc123") */
|
|
82
|
+
id: string;
|
|
83
|
+
/** Object type identifier */
|
|
84
|
+
object: 'skill';
|
|
85
|
+
/** Creation timestamp (Unix seconds) */
|
|
86
|
+
created_at: number;
|
|
87
|
+
/** Skill name from manifest */
|
|
88
|
+
name: string;
|
|
89
|
+
/** Skill description from manifest */
|
|
90
|
+
description: string;
|
|
91
|
+
/** Default version number */
|
|
92
|
+
default_version: number;
|
|
93
|
+
/** Latest version number */
|
|
94
|
+
latest_version: number;
|
|
95
|
+
/** User-defined metadata as key-value pairs */
|
|
96
|
+
metadata: Record<string, string>;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Request payload for updating a skill.
|
|
100
|
+
*/
|
|
101
|
+
export interface UpdateSkillRequest {
|
|
102
|
+
/** Set the default version */
|
|
103
|
+
default_version?: number;
|
|
104
|
+
/** Update user-defined metadata */
|
|
105
|
+
metadata?: Record<string, string>;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Reference to an existing skill by ID and optional version.
|
|
109
|
+
*/
|
|
110
|
+
export interface SkillReference {
|
|
111
|
+
/** Attachment type identifier */
|
|
112
|
+
type: 'skill_reference';
|
|
113
|
+
/** Skill ID to reference */
|
|
114
|
+
skill_id: string;
|
|
115
|
+
/** Version number or 'latest' (defaults to default_version if omitted) */
|
|
116
|
+
version?: number | 'latest';
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Inline skill definition embedded directly in a request.
|
|
120
|
+
*/
|
|
121
|
+
export interface InlineSkill {
|
|
122
|
+
/** Attachment type identifier */
|
|
123
|
+
type: 'inline';
|
|
124
|
+
/** Skill name */
|
|
125
|
+
name: string;
|
|
126
|
+
/** Skill description */
|
|
127
|
+
description: string;
|
|
128
|
+
/** Source material as base64-encoded data */
|
|
129
|
+
source: {
|
|
130
|
+
/** Source encoding type */
|
|
131
|
+
type: 'base64';
|
|
132
|
+
/** MIME type of the data (e.g., "application/zip") */
|
|
133
|
+
media_type: string;
|
|
134
|
+
/** Base64-encoded content */
|
|
135
|
+
data: string;
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Union type for skill attachments — either a reference or an inline definition.
|
|
140
|
+
*/
|
|
141
|
+
export type SkillAttachment = SkillReference | InlineSkill;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/skills/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Conversion Utilities (Core / Platform-Independent)
|
|
3
|
+
*
|
|
4
|
+
* Converts between different OpenAI tool formats.
|
|
5
|
+
* Platform-specific conversions (e.g., to VS Code LanguageModelChatTool)
|
|
6
|
+
* live in their respective packages.
|
|
7
|
+
*/
|
|
8
|
+
import { FunctionTool, ChatCompletionRequest } from './types.js';
|
|
9
|
+
import { AssistantTool } from './assistants/types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Convert Assistants API AssistantTool[] to OpenAI FunctionTool[] for chat requests
|
|
12
|
+
*/
|
|
13
|
+
export declare function assistantToolsToFunctionTools(tools: AssistantTool[]): FunctionTool[];
|
|
14
|
+
/**
|
|
15
|
+
* Convert Responses API tools (flat format) to OpenAI FunctionTool[] (nested format).
|
|
16
|
+
* Responses API: { type: "function", name, description, parameters }
|
|
17
|
+
* Chat Completions: { type: "function", function: { name, description, parameters } }
|
|
18
|
+
*/
|
|
19
|
+
export declare function responsesToolsToFunctionTools(tools: any[]): FunctionTool[];
|
|
20
|
+
/**
|
|
21
|
+
* Map OpenAI tool_choice to a simplified mode string.
|
|
22
|
+
* Returns 'none' when tools should be omitted, 'auto' for default, 'required' for forced.
|
|
23
|
+
*/
|
|
24
|
+
export declare function toToolMode(choice?: ChatCompletionRequest['tool_choice']): 'none' | 'auto' | 'required';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool Conversion Utilities (Core / Platform-Independent)
|
|
3
|
+
*
|
|
4
|
+
* Converts between different OpenAI tool formats.
|
|
5
|
+
* Platform-specific conversions (e.g., to VS Code LanguageModelChatTool)
|
|
6
|
+
* live in their respective packages.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Convert Assistants API AssistantTool[] to OpenAI FunctionTool[] for chat requests
|
|
10
|
+
*/
|
|
11
|
+
export function assistantToolsToFunctionTools(tools) {
|
|
12
|
+
return tools
|
|
13
|
+
.filter(t => t.type === 'function' && t.function)
|
|
14
|
+
.map(t => ({
|
|
15
|
+
type: 'function',
|
|
16
|
+
function: {
|
|
17
|
+
name: t.function.name,
|
|
18
|
+
description: t.function.description,
|
|
19
|
+
parameters: t.function.parameters,
|
|
20
|
+
},
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Convert Responses API tools (flat format) to OpenAI FunctionTool[] (nested format).
|
|
25
|
+
* Responses API: { type: "function", name, description, parameters }
|
|
26
|
+
* Chat Completions: { type: "function", function: { name, description, parameters } }
|
|
27
|
+
*/
|
|
28
|
+
export function responsesToolsToFunctionTools(tools) {
|
|
29
|
+
return tools.map(tool => {
|
|
30
|
+
if (tool.type === 'function' && tool.function) {
|
|
31
|
+
return tool;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
type: 'function',
|
|
35
|
+
function: {
|
|
36
|
+
name: tool.name,
|
|
37
|
+
description: tool.description,
|
|
38
|
+
parameters: tool.parameters,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Map OpenAI tool_choice to a simplified mode string.
|
|
45
|
+
* Returns 'none' when tools should be omitted, 'auto' for default, 'required' for forced.
|
|
46
|
+
*/
|
|
47
|
+
export function toToolMode(choice) {
|
|
48
|
+
if (choice === 'none') {
|
|
49
|
+
return 'none';
|
|
50
|
+
}
|
|
51
|
+
if (typeof choice === 'object') {
|
|
52
|
+
return 'required';
|
|
53
|
+
}
|
|
54
|
+
return 'auto';
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=toolConvert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolConvert.js","sourceRoot":"","sources":["../src/toolConvert.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH;;GAEG;AACH,MAAM,UAAU,6BAA6B,CAAC,KAAsB;IAClE,OAAO,KAAK;SACT,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,IAAI,CAAC,CAAC,QAAQ,CAAC;SAChD,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACT,IAAI,EAAE,UAAmB;QACzB,QAAQ,EAAE;YACR,IAAI,EAAE,CAAC,CAAC,QAAS,CAAC,IAAI;YACtB,WAAW,EAAE,CAAC,CAAC,QAAS,CAAC,WAAW;YACpC,UAAU,EAAE,CAAC,CAAC,QAAS,CAAC,UAAU;SACnC;KACF,CAAC,CAAC,CAAC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