@codex-app-sdk/core 0.16.9 → 0.17.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/dist/chunks/prompt-content-BCcHFqCj.js +85 -0
- package/dist/chunks/prompt-content-BCcHFqCj.js.map +1 -0
- package/dist/chunks/{surface-bridge-CUuIfmG5.js → surface-bridge-DThrFjJl.js} +216 -208
- package/dist/chunks/surface-bridge-DThrFjJl.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/prompt-content.d.ts +25 -0
- package/dist/prompt-content.d.ts.map +1 -0
- package/dist/surface-bridge.d.ts +6 -6
- package/dist/surface-bridge.d.ts.map +1 -1
- package/dist/surface-bridge.js +1 -1
- package/dist/surface.d.ts +11 -5
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +2 -0
- package/package.json +1 -1
- package/dist/chunks/surface-bridge-CUuIfmG5.js.map +0 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
//#region src/prompt-content.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
return e.map((e) => e.type === "text" ? e.text : e.label).join("");
|
|
4
|
+
}
|
|
5
|
+
function t(e) {
|
|
6
|
+
return `[$${e.value.replace(/[\\[\]]/g, "\\$&")}](${encodeURI(e.id).replace(/[()#?]/g, (e) => `%${e.charCodeAt(0).toString(16).toUpperCase()}`)})`;
|
|
7
|
+
}
|
|
8
|
+
function n(n, r) {
|
|
9
|
+
let i = n.map((e) => e.type === "text" ? e.text : e.kind === "skill" ? t(e) : e.kind === "file" ? `@${e.id}` : `@${e.value}`).join("");
|
|
10
|
+
if (r === void 0) return i;
|
|
11
|
+
let a = e(n);
|
|
12
|
+
return r.startsWith(i) || !r.startsWith(a) ? r : i + r.slice(a.length);
|
|
13
|
+
}
|
|
14
|
+
function r(t, n, r = e(t).length) {
|
|
15
|
+
let i = 0;
|
|
16
|
+
return a(t).flatMap((e) => {
|
|
17
|
+
let t = e.type === "text" ? e.text : e.label, a = Math.max(0, n - i), o = Math.min(t.length, r - i);
|
|
18
|
+
return i += t.length, a >= o ? [] : e.type === "mention" && a === 0 && o === t.length ? [e] : [{
|
|
19
|
+
type: "text",
|
|
20
|
+
text: t.slice(a, o)
|
|
21
|
+
}];
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function i(e, t, n, i) {
|
|
25
|
+
return a([
|
|
26
|
+
...r(e, 0, t),
|
|
27
|
+
...a(i),
|
|
28
|
+
...r(e, Math.max(t, n))
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
function a(e) {
|
|
32
|
+
if (!Array.isArray(e)) throw Error("Prompt content must be an array");
|
|
33
|
+
let t = e.map((e) => {
|
|
34
|
+
if (!e || typeof e != "object") throw Error("Invalid prompt content part");
|
|
35
|
+
let t = e;
|
|
36
|
+
if (t.type === "text" && typeof t.text == "string") return {
|
|
37
|
+
type: "text",
|
|
38
|
+
text: t.text
|
|
39
|
+
};
|
|
40
|
+
if (t.type !== "mention" || ![
|
|
41
|
+
"skill",
|
|
42
|
+
"plugin",
|
|
43
|
+
"file",
|
|
44
|
+
"custom"
|
|
45
|
+
].includes(t.kind) || ![
|
|
46
|
+
"id",
|
|
47
|
+
"label",
|
|
48
|
+
"value"
|
|
49
|
+
].every((e) => typeof t[e] == "string" && t[e] !== "") || t.groupId !== void 0 && typeof t.groupId != "string") throw Error("Invalid prompt mention");
|
|
50
|
+
return {
|
|
51
|
+
type: "mention",
|
|
52
|
+
kind: t.kind,
|
|
53
|
+
id: t.id,
|
|
54
|
+
label: t.label,
|
|
55
|
+
value: t.value,
|
|
56
|
+
...t.groupId === void 0 ? {} : { groupId: t.groupId }
|
|
57
|
+
};
|
|
58
|
+
}), n = [];
|
|
59
|
+
for (let e of t) {
|
|
60
|
+
let t = n.at(-1);
|
|
61
|
+
if (e.type === "text") {
|
|
62
|
+
if (!e.text) continue;
|
|
63
|
+
if (t?.type === "text") {
|
|
64
|
+
t.text += e.text;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
n.push(e);
|
|
69
|
+
}
|
|
70
|
+
return n;
|
|
71
|
+
}
|
|
72
|
+
function o(e) {
|
|
73
|
+
let t = a(e);
|
|
74
|
+
for (; t[0]?.type === "text" && (t[0].text = t[0].text.trimStart(), !t[0].text);) t.shift();
|
|
75
|
+
for (; t.at(-1)?.type === "text";) {
|
|
76
|
+
let e = t.at(-1);
|
|
77
|
+
if (e.text = e.text.trimEnd(), e.text) break;
|
|
78
|
+
t.pop();
|
|
79
|
+
}
|
|
80
|
+
return t;
|
|
81
|
+
}
|
|
82
|
+
//#endregion
|
|
83
|
+
export { r as a, i, n, o, e as r, a as t };
|
|
84
|
+
|
|
85
|
+
//# sourceMappingURL=prompt-content-BCcHFqCj.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-content-BCcHFqCj.js","names":[],"sources":["../../src/prompt-content.ts"],"sourcesContent":["/** Serializable authored content. Mentions exist only after explicit selection. */\nexport type CodexPromptMention = {\n type: 'mention';\n kind: 'skill' | 'plugin' | 'file' | 'custom';\n id: string;\n /** Exact visible chip label, without an added $ or @ prefix. */\n label: string;\n /** Selected catalog name/value; never inferred from surrounding text. */\n value: string;\n groupId?: string;\n};\n\nexport type CodexPromptPart = { type: 'text'; text: string } | CodexPromptMention;\n\nexport function promptContentText(content: readonly CodexPromptPart[]): string {\n return content.map(part => part.type === 'text' ? part.text : part.label).join('');\n}\n\nfunction skillReference(part: CodexPromptMention): string {\n const name = part.value.replace(/[\\\\[\\]]/g, '\\\\$&');\n const path = encodeURI(part.id).replace(/[()#?]/g, char => `%${char.charCodeAt(0).toString(16).toUpperCase()}`);\n return `[$${name}](${path})`;\n}\n\n/** Model-facing references. An optional prompt retains context after its authored prefix. */\nexport function promptContentDispatchText(content: readonly CodexPromptPart[], prompt?: string): string {\n const text = content.map(part => part.type === 'text' ? part.text\n : part.kind === 'skill' ? skillReference(part)\n : part.kind === 'file' ? `@${part.id}` : `@${part.value}`).join('');\n if (prompt === undefined) return text;\n const visible = promptContentText(content);\n if (prompt.startsWith(text) || !prompt.startsWith(visible)) return prompt;\n return text + prompt.slice(visible.length);\n}\n\n/** Offsets are UTF-16 visible-text offsets, as in JavaScript strings and DOM selections. */\nexport function slicePromptContent(content: readonly CodexPromptPart[], start: number, end = promptContentText(content).length): CodexPromptPart[] {\n let offset = 0;\n return normalizePromptContent(content).flatMap((part): CodexPromptPart[] => {\n const text = part.type === 'text' ? part.text : part.label;\n const from = Math.max(0, start - offset);\n const to = Math.min(text.length, end - offset);\n offset += text.length;\n if (from >= to) return [];\n return part.type === 'mention' && from === 0 && to === text.length\n ? [part] : [{ type: 'text', text: text.slice(from, to) }];\n });\n}\n\nexport function replacePromptContentRange(\n content: readonly CodexPromptPart[], start: number, end: number, replacement: readonly CodexPromptPart[],\n): CodexPromptPart[] {\n return normalizePromptContent([...slicePromptContent(content, 0, start), ...normalizePromptContent(replacement), ...slicePromptContent(content, Math.max(start, end))]);\n}\n\n/** Validate and copy content at transport and persisted-message boundaries. */\nexport function normalizePromptContent(content: unknown): CodexPromptPart[] {\n if (!Array.isArray(content)) throw new Error('Prompt content must be an array');\n const parts = content.map((part: unknown): CodexPromptPart => {\n if (!part || typeof part !== 'object') throw new Error('Invalid prompt content part');\n const value = part as Record<string, unknown>;\n if (value.type === 'text' && typeof value.text === 'string') return { type: 'text', text: value.text };\n if (value.type !== 'mention' || !['skill', 'plugin', 'file', 'custom'].includes(value.kind as string)\n || !['id', 'label', 'value'].every(key => typeof value[key] === 'string' && value[key] !== '')\n || (value.groupId !== undefined && typeof value.groupId !== 'string')) {\n throw new Error('Invalid prompt mention');\n }\n return {\n type: 'mention', kind: value.kind as CodexPromptMention['kind'],\n id: value.id as string, label: value.label as string, value: value.value as string,\n ...(value.groupId === undefined ? {} : { groupId: value.groupId as string }),\n };\n });\n const normalized: CodexPromptPart[] = [];\n for (const part of parts) {\n const previous = normalized.at(-1);\n if (part.type === 'text') {\n if (!part.text) continue;\n if (previous?.type === 'text') { previous.text += part.text; continue; }\n }\n normalized.push(part);\n }\n return normalized;\n}\n\nexport function trimPromptContent(content: readonly CodexPromptPart[]): CodexPromptPart[] {\n const parts = normalizePromptContent(content);\n while (parts[0]?.type === 'text') {\n parts[0].text = parts[0].text.trimStart();\n if (parts[0].text) break;\n parts.shift();\n }\n while (parts.at(-1)?.type === 'text') {\n const last = parts.at(-1) as Extract<CodexPromptPart, { type: 'text' }>;\n last.text = last.text.trimEnd();\n if (last.text) break;\n parts.pop();\n }\n return parts;\n}\n"],"mappings":";AAcA,SAAgB,EAAkB,GAA6C;CAC7E,OAAO,EAAQ,KAAI,MAAQ,EAAK,SAAS,SAAS,EAAK,OAAO,EAAK,KAAK,CAAC,CAAC,KAAK,EAAE;AACnF;AAEA,SAAS,EAAe,GAAkC;CAGxD,OAAO,KAFM,EAAK,MAAM,QAAQ,YAAY,MAEhC,EAAK,IADJ,UAAU,EAAK,EAAE,CAAC,CAAC,QAAQ,YAAW,MAAQ,IAAI,EAAK,WAAW,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,YAAY,GACtF,EAAK;AAC5B;AAGA,SAAgB,EAA0B,GAAqC,GAAyB;CACtG,IAAM,IAAO,EAAQ,KAAI,MAAQ,EAAK,SAAS,SAAS,EAAK,OACzD,EAAK,SAAS,UAAU,EAAe,CAAI,IACzC,EAAK,SAAS,SAAS,IAAI,EAAK,OAAO,IAAI,EAAK,OAAO,CAAC,CAAC,KAAK,EAAE;CACtE,IAAI,MAAW,KAAA,GAAW,OAAO;CACjC,IAAM,IAAU,EAAkB,CAAO;CAEzC,OADI,EAAO,WAAW,CAAI,KAAK,CAAC,EAAO,WAAW,CAAO,IAAU,IAC5D,IAAO,EAAO,MAAM,EAAQ,MAAM;AAC3C;AAGA,SAAgB,EAAmB,GAAqC,GAAe,IAAM,EAAkB,CAAO,CAAC,CAAC,QAA2B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