@felan-ai/ext-codex 0.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/LICENSE +22 -0
- package/NOTICE +18 -0
- package/README.md +63 -0
- package/dist/config.d.ts +11 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +67 -0
- package/dist/config.js.map +1 -0
- package/dist/exec-session-manager.d.ts +34 -0
- package/dist/exec-session-manager.d.ts.map +1 -0
- package/dist/exec-session-manager.js +374 -0
- package/dist/exec-session-manager.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/model-policy.d.ts +5 -0
- package/dist/model-policy.d.ts.map +1 -0
- package/dist/model-policy.js +14 -0
- package/dist/model-policy.js.map +1 -0
- package/dist/patch.d.ts +15 -0
- package/dist/patch.d.ts.map +1 -0
- package/dist/patch.js +350 -0
- package/dist/patch.js.map +1 -0
- package/dist/request-options.d.ts +4 -0
- package/dist/request-options.d.ts.map +1 -0
- package/dist/request-options.js +15 -0
- package/dist/request-options.js.map +1 -0
- package/dist/tools.d.ts +7 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +219 -0
- package/dist/tools.js.map +1 -0
- package/dist/transport.d.ts +6 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +29 -0
- package/dist/transport.js.map +1 -0
- package/package.json +45 -0
package/dist/tools.js
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { resizeImage, } from '@felan-ai/agent-core';
|
|
2
|
+
import { Type } from 'typebox';
|
|
3
|
+
import { ExecSessionManager, formatExecResult } from './exec-session-manager.js';
|
|
4
|
+
import { ApplyPatchError, applyPatch } from './patch.js';
|
|
5
|
+
import { supportsImageInput } from './model-policy.js';
|
|
6
|
+
const ExecCommandParams = Type.Object({
|
|
7
|
+
cmd: Type.String({ description: 'Raw command string interpreted by the current shell; do not quote the entire command' }),
|
|
8
|
+
workdir: Type.Optional(Type.String({ description: 'Cwd' })),
|
|
9
|
+
shell: Type.Optional(Type.String()),
|
|
10
|
+
tty: Type.Optional(Type.Boolean({ description: 'Run the command in a real PTY for ongoing interaction' })),
|
|
11
|
+
yield_time_ms: Type.Optional(Type.Number({ description: 'Wait before yielding output. Defaults to 10000 ms and clamps to 250-30000 ms; Windows uses a 10000 ms minimum.' })),
|
|
12
|
+
max_output_tokens: Type.Optional(Type.Number({ description: 'Output token budget. Defaults to 10000 tokens; larger requests may be capped by policy.' })),
|
|
13
|
+
login: Type.Optional(Type.Boolean({ description: 'Login shell' })),
|
|
14
|
+
}, { additionalProperties: false });
|
|
15
|
+
const WriteStdinParams = Type.Object({
|
|
16
|
+
session_id: Type.Number({ description: 'Session ID' }),
|
|
17
|
+
chars: Type.Optional(Type.String({ description: 'Bytes to write to stdin. Defaults to empty, which polls without writing.' })),
|
|
18
|
+
yield_time_ms: Type.Optional(Type.Number({ description: 'Wait before yielding output. Non-empty writes default to 250 ms and cap at 30000 ms; empty polls wait 5000-300000 ms by default.' })),
|
|
19
|
+
max_output_tokens: Type.Optional(Type.Number({ description: 'Output token budget. Defaults to 10000 tokens; larger requests may be capped by policy.' })),
|
|
20
|
+
}, { additionalProperties: false });
|
|
21
|
+
const ApplyPatchParams = Type.Object({
|
|
22
|
+
input: Type.String({
|
|
23
|
+
description: 'Full patch text. Use *** Begin Patch / *** End Patch with Add/Update/Delete File sections. Order each file\'s hunks top-to-bottom; indentation is literal',
|
|
24
|
+
}),
|
|
25
|
+
}, { additionalProperties: false });
|
|
26
|
+
const ViewImageParams = Type.Object({
|
|
27
|
+
path: Type.String(),
|
|
28
|
+
}, { additionalProperties: false });
|
|
29
|
+
export const CODEX_TOOL_NAMES = [
|
|
30
|
+
'exec_command',
|
|
31
|
+
'write_stdin',
|
|
32
|
+
'apply_patch',
|
|
33
|
+
'view_image',
|
|
34
|
+
];
|
|
35
|
+
export const MAX_VIEW_IMAGE_INPUT_BYTES = 20 * 1024 * 1024;
|
|
36
|
+
const MAX_VIEW_IMAGE_BASE64_BYTES = 4 * 1024 * 1024;
|
|
37
|
+
const MAX_VIEW_IMAGE_DIMENSION = 2_000;
|
|
38
|
+
export function createCodexTools(runtime, sessions) {
|
|
39
|
+
const execCommand = {
|
|
40
|
+
name: 'exec_command',
|
|
41
|
+
label: 'exec_command',
|
|
42
|
+
description: 'Runs a command, returning output or a session ID for ongoing interaction.',
|
|
43
|
+
promptSnippet: 'Run commands; use tty=true for a PTY and write_stdin to poll or interact',
|
|
44
|
+
parameters: ExecCommandParams,
|
|
45
|
+
prepareArguments: (args) => prepareExecArguments(args),
|
|
46
|
+
async execute(_toolCallId, params, signal, onUpdate) {
|
|
47
|
+
const result = await sessions.exec(params, signal, onUpdate
|
|
48
|
+
? (partial) => onUpdate({
|
|
49
|
+
content: [{ type: 'text', text: formatExecResult(partial) }],
|
|
50
|
+
details: partial,
|
|
51
|
+
})
|
|
52
|
+
: undefined);
|
|
53
|
+
return {
|
|
54
|
+
content: [{ type: 'text', text: formatExecResult(result) }],
|
|
55
|
+
details: result,
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
const writeStdin = {
|
|
60
|
+
name: 'write_stdin',
|
|
61
|
+
label: 'write_stdin',
|
|
62
|
+
description: 'Writes characters to an existing exec_command session and returns recent output.',
|
|
63
|
+
promptSnippet: 'Write to or poll a running exec_command session',
|
|
64
|
+
parameters: WriteStdinParams,
|
|
65
|
+
async execute(_toolCallId, params, signal, onUpdate) {
|
|
66
|
+
const result = await sessions.write(params, signal, onUpdate
|
|
67
|
+
? (partial) => onUpdate({
|
|
68
|
+
content: [{ type: 'text', text: formatExecResult(partial) }],
|
|
69
|
+
details: partial,
|
|
70
|
+
})
|
|
71
|
+
: undefined);
|
|
72
|
+
return {
|
|
73
|
+
content: [{ type: 'text', text: formatExecResult(result) }],
|
|
74
|
+
details: result,
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
const applyPatchTool = {
|
|
79
|
+
name: 'apply_patch',
|
|
80
|
+
label: 'apply_patch',
|
|
81
|
+
description: 'Safely apply a structured patch to workspace files',
|
|
82
|
+
promptSnippet: 'Edit files with a structured patch',
|
|
83
|
+
promptGuidelines: ['Order each Update File section\'s hunks from top to bottom and preserve exact indentation.'],
|
|
84
|
+
parameters: ApplyPatchParams,
|
|
85
|
+
executionMode: 'sequential',
|
|
86
|
+
prepareArguments: (args) => preparePatchArguments(args),
|
|
87
|
+
async execute(_toolCallId, params, signal) {
|
|
88
|
+
try {
|
|
89
|
+
const result = await applyPatch(runtime, params.input, signal);
|
|
90
|
+
return { content: [{ type: 'text', text: formatPatchSuccess(result) }], details: { status: 'success', result } };
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
if (!(error instanceof ApplyPatchError) || error.result.changedFiles.length === 0)
|
|
94
|
+
throw error;
|
|
95
|
+
return {
|
|
96
|
+
content: [{
|
|
97
|
+
type: 'text',
|
|
98
|
+
text: `${error.message}\nFailed file: ${error.failedPath}\nEarlier file actions in this patch were already applied`,
|
|
99
|
+
}],
|
|
100
|
+
details: { status: 'partial_failure', result: error.result, failedPath: error.failedPath },
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
const viewImage = {
|
|
106
|
+
name: 'view_image',
|
|
107
|
+
label: 'view_image',
|
|
108
|
+
description: 'View an image from the workspace',
|
|
109
|
+
promptSnippet: 'View an image file',
|
|
110
|
+
parameters: ViewImageParams,
|
|
111
|
+
prepareArguments: (args) => prepareImageArguments(args),
|
|
112
|
+
async execute(_toolCallId, params, signal, _onUpdate, ctx) {
|
|
113
|
+
if (!supportsImageInput(ctx.model)) {
|
|
114
|
+
throw new Error('view_image is unavailable because the selected model does not support image input');
|
|
115
|
+
}
|
|
116
|
+
if (signal?.aborted)
|
|
117
|
+
throw new Error('view_image aborted');
|
|
118
|
+
const path = params.path.startsWith('@') ? params.path.slice(1) : params.path;
|
|
119
|
+
const data = await runtime.readFile(path, { maxBytes: MAX_VIEW_IMAGE_INPUT_BYTES });
|
|
120
|
+
if (signal?.aborted)
|
|
121
|
+
throw new Error('view_image aborted');
|
|
122
|
+
const mimeType = detectImageMimeType(data);
|
|
123
|
+
if (!mimeType)
|
|
124
|
+
throw new Error('view_image expected a PNG, JPEG, GIF, or WebP image');
|
|
125
|
+
const resized = await resizeImage(data, mimeType, {
|
|
126
|
+
maxWidth: MAX_VIEW_IMAGE_DIMENSION,
|
|
127
|
+
maxHeight: MAX_VIEW_IMAGE_DIMENSION,
|
|
128
|
+
maxBytes: MAX_VIEW_IMAGE_BASE64_BYTES,
|
|
129
|
+
});
|
|
130
|
+
if (!resized) {
|
|
131
|
+
throw new Error('view_image could not decode or resize the image within safety limits');
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
content: [{ type: 'image', data: resized.data, mimeType: resized.mimeType }],
|
|
135
|
+
details: {
|
|
136
|
+
path,
|
|
137
|
+
originalWidth: resized.originalWidth,
|
|
138
|
+
originalHeight: resized.originalHeight,
|
|
139
|
+
width: resized.width,
|
|
140
|
+
height: resized.height,
|
|
141
|
+
wasResized: resized.wasResized,
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
return [execCommand, writeStdin, applyPatchTool, viewImage];
|
|
147
|
+
}
|
|
148
|
+
export function registerPatchResultEvent(pi) {
|
|
149
|
+
pi.on('tool_result', (event) => {
|
|
150
|
+
if (event.toolName === 'apply_patch'
|
|
151
|
+
&& typeof event.details === 'object'
|
|
152
|
+
&& event.details !== null
|
|
153
|
+
&& 'status' in event.details
|
|
154
|
+
&& event.details.status === 'partial_failure')
|
|
155
|
+
return { isError: true };
|
|
156
|
+
return undefined;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function prepareExecArguments(args) {
|
|
160
|
+
if (!isRecord(args))
|
|
161
|
+
return args;
|
|
162
|
+
const prepared = { ...args };
|
|
163
|
+
if (!('cmd' in prepared) && typeof prepared.command === 'string')
|
|
164
|
+
prepared.cmd = prepared.command;
|
|
165
|
+
if (!('workdir' in prepared)) {
|
|
166
|
+
if (typeof prepared.cwd === 'string')
|
|
167
|
+
prepared.workdir = prepared.cwd;
|
|
168
|
+
else if (typeof prepared.working_directory === 'string')
|
|
169
|
+
prepared.workdir = prepared.working_directory;
|
|
170
|
+
}
|
|
171
|
+
return prepared;
|
|
172
|
+
}
|
|
173
|
+
function preparePatchArguments(args) {
|
|
174
|
+
if (!isRecord(args) || typeof args.input === 'string')
|
|
175
|
+
return args;
|
|
176
|
+
if (typeof args.patchText === 'string')
|
|
177
|
+
return { input: args.patchText };
|
|
178
|
+
if (typeof args.patch === 'string')
|
|
179
|
+
return { input: args.patch };
|
|
180
|
+
return args;
|
|
181
|
+
}
|
|
182
|
+
function prepareImageArguments(args) {
|
|
183
|
+
if (!isRecord(args) || typeof args.path === 'string')
|
|
184
|
+
return args;
|
|
185
|
+
if (typeof args.file_path === 'string')
|
|
186
|
+
return { path: args.file_path };
|
|
187
|
+
if (typeof args.image_path === 'string')
|
|
188
|
+
return { path: args.image_path };
|
|
189
|
+
return args;
|
|
190
|
+
}
|
|
191
|
+
function detectImageMimeType(data) {
|
|
192
|
+
if (startsWith(data, [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]))
|
|
193
|
+
return 'image/png';
|
|
194
|
+
if (startsWith(data, [0xff, 0xd8, 0xff]))
|
|
195
|
+
return 'image/jpeg';
|
|
196
|
+
const header = new TextDecoder().decode(data.subarray(0, 12));
|
|
197
|
+
if (header.startsWith('GIF87a') || header.startsWith('GIF89a'))
|
|
198
|
+
return 'image/gif';
|
|
199
|
+
if (header.startsWith('RIFF') && header.slice(8, 12) === 'WEBP')
|
|
200
|
+
return 'image/webp';
|
|
201
|
+
return undefined;
|
|
202
|
+
}
|
|
203
|
+
function startsWith(data, prefix) {
|
|
204
|
+
return prefix.every((byte, index) => data[index] === byte);
|
|
205
|
+
}
|
|
206
|
+
function formatPatchSuccess(result) {
|
|
207
|
+
return [
|
|
208
|
+
'Applied patch successfully',
|
|
209
|
+
`Changed files: ${result.changedFiles.length}`,
|
|
210
|
+
`Created files: ${result.createdFiles.length}`,
|
|
211
|
+
`Deleted files: ${result.deletedFiles.length}`,
|
|
212
|
+
`Moved files: ${result.movedFiles.length}`,
|
|
213
|
+
`Fuzz: ${result.fuzz}`,
|
|
214
|
+
].join('\n');
|
|
215
|
+
}
|
|
216
|
+
function isRecord(value) {
|
|
217
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,GAIZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,IAAI,EAAe,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,MAAM,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC;IACpC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,sFAAsF,EAAE,CAAC;IACzH,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;IAC3D,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IACnC,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,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AC,CAAC,EAAE,EAAE,CAAC,KAAK,MAAM;QAAE,OAAO,YAAY,CAAC;IACrF,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,UAAU,CAAC,IAAgB,EAAE,MAAyB;IAC7D,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,CAAC;AAC7D,CAAC;AAED,SAAS,kBAAkB,CAAC,MAA8C;IACxE,OAAO;QACL,4BAA4B;QAC5B,kBAAkB,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE;QAC9C,kBAAkB,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE;QAC9C,kBAAkB,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE;QAC9C,gBAAgB,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE;QAC1C,SAAS,MAAM,CAAC,IAAI,EAAE;KACvB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Api, Model, SimpleStreamOptions, StreamFunction, Transport } from '@felan-ai/agent-core';
|
|
2
|
+
import type { CodexConfig } from './config.js';
|
|
3
|
+
export declare function resolveCodexTransport(transport: Transport | undefined, forceCachedWebSockets: boolean): Transport | undefined;
|
|
4
|
+
export declare function resolveCodexStreamOptions(model: Model<Api>, options: SimpleStreamOptions | undefined, config: CodexConfig): SimpleStreamOptions | undefined;
|
|
5
|
+
export declare function createCodexStreamFunctionWrapper(config: CodexConfig): (original: StreamFunction) => StreamFunction;
|
|
6
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,GAAG,EACH,KAAK,EACL,mBAAmB,EACnB,cAAc,EACd,SAAS,EACV,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAQ/C,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,SAAS,GAAG,SAAS,EAChC,qBAAqB,EAAE,OAAO,GAC7B,SAAS,GAAG,SAAS,CAIvB;AAED,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EACjB,OAAO,EAAE,mBAAmB,GAAG,SAAS,EACxC,MAAM,EAAE,WAAW,GAClB,mBAAmB,GAAG,SAAS,CAkBjC;AAED,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,WAAW,GAClB,CAAC,QAAQ,EAAE,cAAc,KAAK,cAAc,CAM9C"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { supportsCodexModel, supportsCodexResponsesRequest } from './model-policy.js';
|
|
2
|
+
export function resolveCodexTransport(transport, forceCachedWebSockets) {
|
|
3
|
+
return forceCachedWebSockets && transport === 'websocket'
|
|
4
|
+
? 'websocket-cached'
|
|
5
|
+
: transport;
|
|
6
|
+
}
|
|
7
|
+
export function resolveCodexStreamOptions(model, options, config) {
|
|
8
|
+
if (!supportsCodexModel(model))
|
|
9
|
+
return options;
|
|
10
|
+
const transport = model.provider === 'openai-codex' && model.api === 'openai-codex-responses'
|
|
11
|
+
? resolveCodexTransport(options?.transport, config.forceCachedWebSockets)
|
|
12
|
+
: options?.transport;
|
|
13
|
+
const responses = supportsCodexResponsesRequest(model);
|
|
14
|
+
if (!responses && transport === options?.transport)
|
|
15
|
+
return options;
|
|
16
|
+
const prepared = {
|
|
17
|
+
...options,
|
|
18
|
+
...(transport === undefined ? {} : { transport }),
|
|
19
|
+
...(responses && config.fast ? { serviceTier: 'priority' } : {}),
|
|
20
|
+
...(responses && model.api === 'openai-codex-responses'
|
|
21
|
+
? { textVerbosity: config.verbosity }
|
|
22
|
+
: {}),
|
|
23
|
+
};
|
|
24
|
+
return prepared;
|
|
25
|
+
}
|
|
26
|
+
export function createCodexStreamFunctionWrapper(config) {
|
|
27
|
+
return (original) => ((model, context, options) => original(model, context, resolveCodexStreamOptions(model, options, config)));
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAOtF,MAAM,UAAU,qBAAqB,CACnC,SAAgC,EAChC,qBAA8B;IAE9B,OAAO,qBAAqB,IAAI,SAAS,KAAK,WAAW;QACvD,CAAC,CAAC,kBAAkB;QACpB,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,yBAAyB,CACvC,KAAiB,EACjB,OAAwC,EACxC,MAAmB;IAEnB,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IAE/C,MAAM,SAAS,GAAG,KAAK,CAAC,QAAQ,KAAK,cAAc,IAAI,KAAK,CAAC,GAAG,KAAK,wBAAwB;QAC3F,CAAC,CAAC,qBAAqB,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,qBAAqB,CAAC;QACzE,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC;IACvB,MAAM,SAAS,GAAG,6BAA6B,CAAC,KAAK,CAAC,CAAC;IACvD,IAAI,CAAC,SAAS,IAAI,SAAS,KAAK,OAAO,EAAE,SAAS;QAAE,OAAO,OAAO,CAAC;IAEnE,MAAM,QAAQ,GAA6B;QACzC,GAAG,OAAO;QACV,GAAG,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC;QACjD,GAAG,CAAC,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAChE,GAAG,CAAC,SAAS,IAAI,KAAK,CAAC,GAAG,KAAK,wBAAwB;YACrD,CAAC,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,SAAS,EAAE;YACrC,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;IACF,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,gCAAgC,CAC9C,MAAmB;IAEnB,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,QAAQ,CACzD,KAAK,EACL,OAAO,EACP,yBAAyB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAClD,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@felan-ai/ext-codex",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Codex-compatible structured tools and OpenAI request controls for Felan",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/felan-ai/felan.git",
|
|
10
|
+
"directory": "packages/ext-codex"
|
|
11
|
+
},
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=22.19.0"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"NOTICE",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"typebox": "1.1.38"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@felan-ai/agent-core": "^0.4.1"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@felan-ai/agent-core": "0.4.1"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public",
|
|
38
|
+
"provenance": true
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
42
|
+
"type-check": "tsc -p tsconfig.json --noEmit",
|
|
43
|
+
"test": "vitest run"
|
|
44
|
+
}
|
|
45
|
+
}
|