@cogenta/agents 0.2.1 → 0.5.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/agents/builtins.d.ts +51 -0
- package/dist/agents/builtins.d.ts.map +1 -0
- package/dist/agents/builtins.js +190 -0
- package/dist/agents/builtins.js.map +1 -0
- package/dist/agents/orchestrator.d.ts +98 -0
- package/dist/agents/orchestrator.d.ts.map +1 -0
- package/dist/agents/orchestrator.js +286 -0
- package/dist/agents/orchestrator.js.map +1 -0
- package/dist/agents/store.d.ts +71 -0
- package/dist/agents/store.d.ts.map +1 -0
- package/dist/agents/store.js +211 -0
- package/dist/agents/store.js.map +1 -0
- package/dist/agents/types.d.ts +10 -0
- package/dist/agents/types.d.ts.map +1 -1
- package/dist/assist/agent-identity.d.ts +44 -0
- package/dist/assist/agent-identity.d.ts.map +1 -0
- package/dist/assist/agent-identity.js +136 -0
- package/dist/assist/agent-identity.js.map +1 -0
- package/dist/assist/chat.d.ts +2 -0
- package/dist/assist/chat.d.ts.map +1 -1
- package/dist/assist/chat.js +14 -5
- package/dist/assist/chat.js.map +1 -1
- package/dist/assist/classify.d.ts +3 -2
- package/dist/assist/classify.d.ts.map +1 -1
- package/dist/assist/classify.js +30 -11
- package/dist/assist/classify.js.map +1 -1
- package/dist/assist/faq.d.ts +3 -2
- package/dist/assist/faq.d.ts.map +1 -1
- package/dist/assist/faq.js +31 -13
- package/dist/assist/faq.js.map +1 -1
- package/dist/assist/runtime.d.ts +8 -2
- package/dist/assist/runtime.d.ts.map +1 -1
- package/dist/assist/runtime.js +2 -2
- package/dist/assist/runtime.js.map +1 -1
- package/dist/assist/toolset.d.ts +10 -0
- package/dist/assist/toolset.d.ts.map +1 -1
- package/dist/assist/toolset.js +36 -8
- package/dist/assist/toolset.js.map +1 -1
- package/dist/assist/usage.d.ts +58 -0
- package/dist/assist/usage.d.ts.map +1 -0
- package/dist/assist/usage.js +53 -0
- package/dist/assist/usage.js.map +1 -0
- package/dist/assist/writing.d.ts +10 -9
- package/dist/assist/writing.d.ts.map +1 -1
- package/dist/assist/writing.js +126 -58
- package/dist/assist/writing.js.map +1 -1
- package/dist/audit/with-audit.d.ts +13 -0
- package/dist/audit/with-audit.d.ts.map +1 -1
- package/dist/audit/with-audit.js +6 -0
- package/dist/audit/with-audit.js.map +1 -1
- package/dist/autonomy/levels.d.ts +37 -0
- package/dist/autonomy/levels.d.ts.map +1 -0
- package/dist/autonomy/levels.js +51 -0
- package/dist/autonomy/levels.js.map +1 -0
- package/dist/conversations/store.d.ts +62 -0
- package/dist/conversations/store.d.ts.map +1 -0
- package/dist/conversations/store.js +0 -0
- package/dist/conversations/store.js.map +1 -0
- package/dist/identity/context.d.ts +8 -0
- package/dist/identity/context.d.ts.map +1 -1
- package/dist/identity/context.js +19 -4
- package/dist/identity/context.js.map +1 -1
- package/dist/identity/markdown.d.ts +38 -0
- package/dist/identity/markdown.d.ts.map +1 -0
- package/dist/identity/markdown.js +85 -0
- package/dist/identity/markdown.js.map +1 -0
- package/dist/index.d.ts +62 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -3
- package/dist/index.js.map +1 -1
- package/dist/progress/job-store.d.ts +41 -0
- package/dist/progress/job-store.d.ts.map +1 -0
- package/dist/progress/job-store.js +44 -0
- package/dist/progress/job-store.js.map +1 -0
- package/dist/progress/types.d.ts +21 -0
- package/dist/progress/types.d.ts.map +1 -0
- package/dist/progress/types.js +3 -0
- package/dist/progress/types.js.map +1 -0
- package/dist/prompts/render.d.ts +23 -0
- package/dist/prompts/render.d.ts.map +1 -0
- package/dist/prompts/render.js +35 -0
- package/dist/prompts/render.js.map +1 -0
- package/dist/prompts/seeds.d.ts +34 -0
- package/dist/prompts/seeds.d.ts.map +1 -0
- package/dist/prompts/seeds.js +166 -0
- package/dist/prompts/seeds.js.map +1 -0
- package/dist/prompts/store.d.ts +8 -0
- package/dist/prompts/store.d.ts.map +1 -0
- package/dist/prompts/store.js +153 -0
- package/dist/prompts/store.js.map +1 -0
- package/dist/prompts/types.d.ts +51 -0
- package/dist/prompts/types.d.ts.map +1 -0
- package/dist/prompts/types.js +24 -0
- package/dist/prompts/types.js.map +1 -0
- package/dist/providers/anthropic.d.ts +26 -3
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +60 -12
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/catalog.d.ts +41 -0
- package/dist/providers/catalog.d.ts.map +1 -0
- package/dist/providers/catalog.js +85 -0
- package/dist/providers/catalog.js.map +1 -0
- package/dist/providers/content-parts.d.ts +12 -0
- package/dist/providers/content-parts.d.ts.map +1 -0
- package/dist/providers/content-parts.js +18 -0
- package/dist/providers/content-parts.js.map +1 -0
- package/dist/providers/defaults.d.ts +44 -0
- package/dist/providers/defaults.d.ts.map +1 -0
- package/dist/providers/defaults.js +72 -0
- package/dist/providers/defaults.js.map +1 -0
- package/dist/providers/google.d.ts +20 -3
- package/dist/providers/google.d.ts.map +1 -1
- package/dist/providers/google.js +53 -12
- package/dist/providers/google.js.map +1 -1
- package/dist/providers/openai.d.ts +36 -4
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +113 -21
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/registry.d.ts +38 -21
- package/dist/providers/registry.d.ts.map +1 -1
- package/dist/providers/registry.js +64 -8
- package/dist/providers/registry.js.map +1 -1
- package/dist/providers/request-signal.d.ts +18 -0
- package/dist/providers/request-signal.d.ts.map +1 -0
- package/dist/providers/request-signal.js +21 -0
- package/dist/providers/request-signal.js.map +1 -0
- package/dist/providers/resolve.d.ts +13 -0
- package/dist/providers/resolve.d.ts.map +1 -0
- package/dist/providers/resolve.js +30 -0
- package/dist/providers/resolve.js.map +1 -0
- package/dist/providers/store.d.ts +70 -0
- package/dist/providers/store.d.ts.map +1 -0
- package/dist/providers/store.js +308 -0
- package/dist/providers/store.js.map +1 -0
- package/dist/providers/tool-names.d.ts +9 -0
- package/dist/providers/tool-names.d.ts.map +1 -0
- package/dist/providers/tool-names.js +56 -0
- package/dist/providers/tool-names.js.map +1 -0
- package/dist/providers/types.d.ts +87 -3
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/rag/reference-documents/ingest.d.ts +22 -0
- package/dist/rag/reference-documents/ingest.d.ts.map +1 -0
- package/dist/rag/reference-documents/ingest.js +69 -0
- package/dist/rag/reference-documents/ingest.js.map +1 -0
- package/dist/rag/reference-documents/store.d.ts +23 -0
- package/dist/rag/reference-documents/store.d.ts.map +1 -0
- package/dist/rag/reference-documents/store.js +140 -0
- package/dist/rag/reference-documents/store.js.map +1 -0
- package/dist/rag/reference-documents/types.d.ts +52 -0
- package/dist/rag/reference-documents/types.d.ts.map +1 -0
- package/dist/rag/reference-documents/types.js +32 -0
- package/dist/rag/reference-documents/types.js.map +1 -0
- package/dist/runtime/loop.d.ts +29 -7
- package/dist/runtime/loop.d.ts.map +1 -1
- package/dist/runtime/loop.js +209 -44
- package/dist/runtime/loop.js.map +1 -1
- package/dist/runtime/retry.d.ts +2 -0
- package/dist/runtime/retry.d.ts.map +1 -1
- package/dist/runtime/retry.js +1 -0
- package/dist/runtime/retry.js.map +1 -1
- package/dist/runtime/types.d.ts +14 -3
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/site-plan/analyse-brief.d.ts +8 -0
- package/dist/site-plan/analyse-brief.d.ts.map +1 -1
- package/dist/site-plan/analyse-brief.js +17 -8
- package/dist/site-plan/analyse-brief.js.map +1 -1
- package/dist/site-plan/approval.d.ts +2 -2
- package/dist/site-plan/approval.d.ts.map +1 -1
- package/dist/site-plan/approval.js +34 -4
- package/dist/site-plan/approval.js.map +1 -1
- package/dist/site-plan/content-model.d.ts +14 -0
- package/dist/site-plan/content-model.d.ts.map +1 -1
- package/dist/site-plan/content-model.js +51 -9
- package/dist/site-plan/content-model.js.map +1 -1
- package/dist/site-plan/demo-content.d.ts.map +1 -1
- package/dist/site-plan/demo-content.js +1 -4
- package/dist/site-plan/demo-content.js.map +1 -1
- package/dist/site-plan/propose-plan.d.ts +10 -0
- package/dist/site-plan/propose-plan.d.ts.map +1 -1
- package/dist/site-plan/propose-plan.js +25 -1
- package/dist/site-plan/propose-plan.js.map +1 -1
- package/dist/site-plan/site-context.d.ts +81 -0
- package/dist/site-plan/site-context.d.ts.map +1 -0
- package/dist/site-plan/site-context.js +76 -0
- package/dist/site-plan/site-context.js.map +1 -0
- package/dist/site-plan/skin-candidates.d.ts +13 -1
- package/dist/site-plan/skin-candidates.d.ts.map +1 -1
- package/dist/site-plan/skin-candidates.js +15 -0
- package/dist/site-plan/skin-candidates.js.map +1 -1
- package/dist/site-plan/structural-gaps.d.ts +32 -0
- package/dist/site-plan/structural-gaps.d.ts.map +1 -0
- package/dist/site-plan/structural-gaps.js +77 -0
- package/dist/site-plan/structural-gaps.js.map +1 -0
- package/dist/site-plan/types.d.ts +7 -0
- package/dist/site-plan/types.d.ts.map +1 -1
- package/dist/skills/frontmatter.d.ts +19 -1
- package/dist/skills/frontmatter.d.ts.map +1 -1
- package/dist/skills/frontmatter.js +29 -5
- package/dist/skills/frontmatter.js.map +1 -1
- package/dist/skills/library.d.ts +133 -0
- package/dist/skills/library.d.ts.map +1 -0
- package/dist/skills/library.js +332 -0
- package/dist/skills/library.js.map +1 -0
- package/dist/skills/types.d.ts +8 -1
- package/dist/skills/types.d.ts.map +1 -1
- package/dist/skin/generate.d.ts +22 -1
- package/dist/skin/generate.d.ts.map +1 -1
- package/dist/skin/generate.js +60 -5
- package/dist/skin/generate.js.map +1 -1
- package/dist/theme-creator/propose-theme.d.ts +83 -0
- package/dist/theme-creator/propose-theme.d.ts.map +1 -0
- package/dist/theme-creator/propose-theme.js +234 -0
- package/dist/theme-creator/propose-theme.js.map +1 -0
- package/dist/tools/core/agent-delegate.d.ts +8 -5
- package/dist/tools/core/agent-delegate.d.ts.map +1 -1
- package/dist/tools/core/agent-delegate.js +16 -6
- package/dist/tools/core/agent-delegate.js.map +1 -1
- package/dist/tools/core/content-browse.d.ts +74 -0
- package/dist/tools/core/content-browse.d.ts.map +1 -0
- package/dist/tools/core/content-browse.js +63 -0
- package/dist/tools/core/content-browse.js.map +1 -0
- package/dist/tools/core/content-schema.d.ts +86 -0
- package/dist/tools/core/content-schema.d.ts.map +1 -0
- package/dist/tools/core/content-schema.js +83 -0
- package/dist/tools/core/content-schema.js.map +1 -0
- package/dist/tools/core/deps-scan.d.ts +25 -0
- package/dist/tools/core/deps-scan.d.ts.map +1 -0
- package/dist/tools/core/deps-scan.js +85 -0
- package/dist/tools/core/deps-scan.js.map +1 -0
- package/dist/tools/core/media.d.ts +18 -2
- package/dist/tools/core/media.d.ts.map +1 -1
- package/dist/tools/core/media.js +8 -2
- package/dist/tools/core/media.js.map +1 -1
- package/dist/tools/core/not-found-log.d.ts +44 -0
- package/dist/tools/core/not-found-log.d.ts.map +1 -0
- package/dist/tools/core/not-found-log.js +32 -0
- package/dist/tools/core/not-found-log.js.map +1 -0
- package/dist/tools/core/redirects.d.ts +51 -0
- package/dist/tools/core/redirects.d.ts.map +1 -0
- package/dist/tools/core/redirects.js +50 -0
- package/dist/tools/core/redirects.js.map +1 -0
- package/package.json +6 -4
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { mkdir, readdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { CogentaError } from '@cogenta/core';
|
|
4
|
+
/**
|
|
5
|
+
* One JSON file per template under `options.dir` — the same "real but
|
|
6
|
+
* local" tier `agents/store.ts` and (pre-L24) `skills/library.ts` already
|
|
7
|
+
* use (R1). Unlike `AgentSkillStore` (which persists a portable `SKILL.md`
|
|
8
|
+
* because a skill is meant to travel between agents), a prompt template has
|
|
9
|
+
* no portable format anyone else defines — it is Cogenta-specific data with
|
|
10
|
+
* a `category`/`builtin` this store owns outright, so plain JSON is the
|
|
11
|
+
* honest choice rather than inventing a frontmatter format nobody else reads.
|
|
12
|
+
*/
|
|
13
|
+
const FILE_SUFFIX = '.json';
|
|
14
|
+
/** Every Unicode combining mark — what NFKD decomposition splits an accented letter into. */
|
|
15
|
+
const COMBINING_DIACRITICS = /\p{Mn}/gu;
|
|
16
|
+
function slugify(name) {
|
|
17
|
+
const slug = name
|
|
18
|
+
.toLowerCase()
|
|
19
|
+
.normalize('NFKD')
|
|
20
|
+
.replace(COMBINING_DIACRITICS, '')
|
|
21
|
+
.replace(/[^a-z0-9]+/gu, '-')
|
|
22
|
+
.replace(/^-+|-+$/gu, '');
|
|
23
|
+
return slug.length > 0 ? slug : 'prompt';
|
|
24
|
+
}
|
|
25
|
+
function templateUnknown(id) {
|
|
26
|
+
return new CogentaError({
|
|
27
|
+
code: 'PROMPT_TEMPLATE_UNKNOWN',
|
|
28
|
+
message: `No prompt template with id "${id}".`,
|
|
29
|
+
hint: 'Check the id against `list()`, or create it first.',
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export function createFilePromptTemplateStore(options) {
|
|
33
|
+
const now = options.now ?? (() => new Date());
|
|
34
|
+
const ready = mkdir(options.dir, { recursive: true });
|
|
35
|
+
function fileFor(id) {
|
|
36
|
+
return join(options.dir, `${id}${FILE_SUFFIX}`);
|
|
37
|
+
}
|
|
38
|
+
async function readRecord(id) {
|
|
39
|
+
let raw;
|
|
40
|
+
try {
|
|
41
|
+
raw = await readFile(fileFor(id), 'utf8');
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (error.code === 'ENOENT')
|
|
45
|
+
return null;
|
|
46
|
+
throw new CogentaError({
|
|
47
|
+
code: 'INTERNAL',
|
|
48
|
+
message: `Could not read prompt template "${id}".`,
|
|
49
|
+
hint: 'The file may be corrupted; consider removing it.',
|
|
50
|
+
cause: error,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
let parsed;
|
|
54
|
+
try {
|
|
55
|
+
parsed = JSON.parse(raw);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
throw new CogentaError({
|
|
59
|
+
code: 'INTERNAL',
|
|
60
|
+
message: `Could not parse prompt template "${id}".`,
|
|
61
|
+
hint: 'The file is not valid JSON; consider removing it.',
|
|
62
|
+
cause: error,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return parsed;
|
|
66
|
+
}
|
|
67
|
+
async function writeRecord(record) {
|
|
68
|
+
await writeFile(fileFor(record.id), JSON.stringify(record, null, 2), 'utf8');
|
|
69
|
+
return record;
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
async list() {
|
|
73
|
+
await ready;
|
|
74
|
+
const entries = await readdir(options.dir, { withFileTypes: true }).catch(() => []);
|
|
75
|
+
const templates = [];
|
|
76
|
+
for (const entry of entries) {
|
|
77
|
+
if (!entry.isFile() || !entry.name.endsWith(FILE_SUFFIX))
|
|
78
|
+
continue;
|
|
79
|
+
const id = entry.name.slice(0, -FILE_SUFFIX.length);
|
|
80
|
+
try {
|
|
81
|
+
const record = await readRecord(id);
|
|
82
|
+
if (record !== null)
|
|
83
|
+
templates.push(record);
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
// A corrupted file is not a template this store can serve — skip
|
|
87
|
+
// it rather than fail the whole listing (same posture as the
|
|
88
|
+
// agent-skill and marketplace file stores).
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return templates.sort((a, b) => a.name.localeCompare(b.name));
|
|
92
|
+
},
|
|
93
|
+
async get(id) {
|
|
94
|
+
await ready;
|
|
95
|
+
const record = await readRecord(id);
|
|
96
|
+
return record ?? undefined;
|
|
97
|
+
},
|
|
98
|
+
async create(input, builtin = false) {
|
|
99
|
+
await ready;
|
|
100
|
+
const id = slugify(input.name);
|
|
101
|
+
const existing = await readRecord(id);
|
|
102
|
+
if (existing !== null) {
|
|
103
|
+
throw new CogentaError({
|
|
104
|
+
code: 'PROMPT_TEMPLATE_DUPLICATE',
|
|
105
|
+
message: `A prompt template named "${input.name}" already exists.`,
|
|
106
|
+
hint: 'Choose a different name, or edit the existing template instead.',
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
const at = now().toISOString();
|
|
110
|
+
return writeRecord({
|
|
111
|
+
id,
|
|
112
|
+
name: input.name,
|
|
113
|
+
description: input.description,
|
|
114
|
+
category: input.category,
|
|
115
|
+
template: input.template,
|
|
116
|
+
builtin,
|
|
117
|
+
createdAt: at,
|
|
118
|
+
updatedAt: at,
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
async update(id, patch) {
|
|
122
|
+
await ready;
|
|
123
|
+
const existing = await readRecord(id);
|
|
124
|
+
if (existing === null)
|
|
125
|
+
throw templateUnknown(id);
|
|
126
|
+
return writeRecord({
|
|
127
|
+
id,
|
|
128
|
+
name: patch.name ?? existing.name,
|
|
129
|
+
description: patch.description ?? existing.description,
|
|
130
|
+
category: patch.category ?? existing.category,
|
|
131
|
+
template: patch.template ?? existing.template,
|
|
132
|
+
builtin: existing.builtin,
|
|
133
|
+
createdAt: existing.createdAt,
|
|
134
|
+
updatedAt: now().toISOString(),
|
|
135
|
+
});
|
|
136
|
+
},
|
|
137
|
+
async remove(id) {
|
|
138
|
+
await ready;
|
|
139
|
+
const existing = await readRecord(id);
|
|
140
|
+
if (existing === null)
|
|
141
|
+
throw templateUnknown(id);
|
|
142
|
+
if (existing.builtin) {
|
|
143
|
+
throw new CogentaError({
|
|
144
|
+
code: 'PROMPT_TEMPLATE_BUILTIN_UNDELETABLE',
|
|
145
|
+
message: `"${existing.name}" is a built-in prompt template and cannot be removed.`,
|
|
146
|
+
hint: 'Edit its text instead — a builtin can always be edited, only never deleted.',
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
await rm(fileFor(id), { force: true });
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/prompts/store.ts"],"names":[],"mappings":"AAAA,OAAO,EA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AQ,KAAK,IAAI;gBAAE,MAAM,eAAe,CAAC,EAAE,CAAC,CAAA;YAChD,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;gBACrB,MAAM,IAAI,YAAY,CAAC;oBACrB,IAAI,EAAE,qCAAqC;oBAC3C,OAAO,EAAE,IAAI,QAAQ,CAAC,IAAI,wDAAwD;oBAClF,IAAI,EAAE,6EAA6E;iBACpF,CAAC,CAAA;YACJ,CAAC;YACD,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;QACxC,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fiche 45 — Prompt Settings, the shared template library every utility
|
|
3
|
+
* prompt in `@cogenta/agents` reads from. Same "real but local" tier as
|
|
4
|
+
* `agents/store.ts`/`skills/library.ts` (R1): a file on disk, no external
|
|
5
|
+
* service, no new dependency.
|
|
6
|
+
*
|
|
7
|
+
* A `PromptTemplate` is deliberately **not** a `SkillMetadata`/`AgentSkill`:
|
|
8
|
+
* a skill is a whole piece of context an agent loads ("how this site wants
|
|
9
|
+
* content written"); a prompt template is the single instruction line one
|
|
10
|
+
* specific tool call sends the model, with `{{placeholder}}` slots the tool
|
|
11
|
+
* fills in at call time (see `render.ts`). Different shape, different
|
|
12
|
+
* lifecycle, so a different store rather than overloading one interface for
|
|
13
|
+
* both.
|
|
14
|
+
*/
|
|
15
|
+
/** Suggested vocabulary for the admin's category picker. The field itself stays a plain string — an open list, not a closed taxonomy (fiche 45 §3 task 1: "texte/traduction/agent/image/…"). */
|
|
16
|
+
export declare const PROMPT_TEMPLATE_CATEGORIES: readonly ['text', 'translation', 'seo', 'moderation', 'agent', 'image'];
|
|
17
|
+
export type PromptTemplateCategory = (typeof PROMPT_TEMPLATE_CATEGORIES)[number];
|
|
18
|
+
export interface PromptTemplate {
|
|
19
|
+
readonly id: string;
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly description: string;
|
|
22
|
+
/** Free text — see `PROMPT_TEMPLATE_CATEGORIES` for the suggested vocabulary, not an enforced one. */
|
|
23
|
+
readonly category: string;
|
|
24
|
+
/** The instruction text a tool sends the model, with `{{field}}` placeholders the caller resolves — see `render.ts`'s `renderPromptTemplate`. */
|
|
25
|
+
readonly template: string;
|
|
26
|
+
readonly builtin: boolean;
|
|
27
|
+
readonly createdAt: string;
|
|
28
|
+
readonly updatedAt: string;
|
|
29
|
+
}
|
|
30
|
+
export interface PromptTemplateInput {
|
|
31
|
+
readonly name: string;
|
|
32
|
+
readonly description: string;
|
|
33
|
+
readonly category: string;
|
|
34
|
+
readonly template: string;
|
|
35
|
+
}
|
|
36
|
+
export type PromptTemplatePatch = Partial<PromptTemplateInput>;
|
|
37
|
+
/**
|
|
38
|
+
* Same contract shape as `AgentSkillStore` (`skills/library.ts`) — list/get/
|
|
39
|
+
* create/update/remove — deliberately, so the two stores share one test
|
|
40
|
+
* suite pattern (fiche 45 §5's own criterion) even though what they store
|
|
41
|
+
* differs.
|
|
42
|
+
*/
|
|
43
|
+
export interface PromptTemplateStore {
|
|
44
|
+
list(): Promise<readonly PromptTemplate[]>;
|
|
45
|
+
get(id: string): Promise<PromptTemplate | undefined>;
|
|
46
|
+
create(input: PromptTemplateInput, builtin?: boolean): Promise<PromptTemplate>;
|
|
47
|
+
update(id: string, patch: PromptTemplatePatch): Promise<PromptTemplate>;
|
|
48
|
+
/** Refuses to remove a builtin (`PROMPT_TEMPLATE_BUILTIN_UNDELETABLE`). */
|
|
49
|
+
remove(id: string): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/prompts/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,gMAAgM;AAChM,eAAO,MAAM,0BAA0B,YACrC,M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AA;IACvE,2EAA2E;IAC3E,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAClC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fiche 45 — Prompt Settings, the shared template library every utility
|
|
3
|
+
* prompt in `@cogenta/agents` reads from. Same "real but local" tier as
|
|
4
|
+
* `agents/store.ts`/`skills/library.ts` (R1): a file on disk, no external
|
|
5
|
+
* service, no new dependency.
|
|
6
|
+
*
|
|
7
|
+
* A `PromptTemplate` is deliberately **not** a `SkillMetadata`/`AgentSkill`:
|
|
8
|
+
* a skill is a whole piece of context an agent loads ("how this site wants
|
|
9
|
+
* content written"); a prompt template is the single instruction line one
|
|
10
|
+
* specific tool call sends the model, with `{{placeholder}}` slots the tool
|
|
11
|
+
* fills in at call time (see `render.ts`). Different shape, different
|
|
12
|
+
* lifecycle, so a different store rather than overloading one interface for
|
|
13
|
+
* both.
|
|
14
|
+
*/
|
|
15
|
+
/** Suggested vocabulary for the admin's category picker. The field itself stays a plain string — an open list, not a closed taxonomy (fiche 45 §3 task 1: "texte/traduction/agent/image/…"). */
|
|
16
|
+
export const PROMPT_TEMPLATE_CATEGORIES = [
|
|
17
|
+
'text',
|
|
18
|
+
'translation',
|
|
19
|
+
'seo',
|
|
20
|
+
'moderation',
|
|
21
|
+
'agent',
|
|
22
|
+
'image',
|
|
23
|
+
];
|
|
24
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/prompts/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,gMAAgM;AAChM,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,MAAM;IACN,aAAa;IACb,KAAK;IACL,YAAY;IACZ,OAAO;IACP,OAAO;CACC,CAAA"}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
import type { ProviderTuningDefaults } from './defaults.js';
|
|
1
2
|
import type { ChatRequest, ChatResponse, ProviderClient } from './types.js';
|
|
2
3
|
type AnthropicContentBlock = {
|
|
3
4
|
readonly type: 'text';
|
|
4
5
|
readonly text: string;
|
|
6
|
+
} | {
|
|
7
|
+
readonly type: 'image';
|
|
8
|
+
readonly source: {
|
|
9
|
+
readonly type: 'base64';
|
|
10
|
+
readonly media_type: string;
|
|
11
|
+
readonly data: string;
|
|
12
|
+
};
|
|
5
13
|
} | {
|
|
6
14
|
readonly type: 'tool_use';
|
|
7
15
|
readonly id: string;
|
|
@@ -36,16 +44,31 @@ interface AnthropicResponseBody {
|
|
|
36
44
|
readonly output_tokens: number;
|
|
37
45
|
};
|
|
38
46
|
}
|
|
39
|
-
/**
|
|
40
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Pure — no network. The whole reason this is separate from
|
|
49
|
+
* `createAnthropicClient` is to unit-test the mapping without a live call.
|
|
50
|
+
* `fallbackMaxTokens` is the client's own resolved `maxOutputTokens` (the
|
|
51
|
+
* admin's per-provider value, or the site-wide default) — applied only when
|
|
52
|
+
* `request.maxTokens` itself is absent, never overriding an explicit
|
|
53
|
+
* per-call value. Required, not defaulted: the one caller that matters
|
|
54
|
+
* (`createAnthropicClient`'s own `chat()`) always has a concrete number by
|
|
55
|
+
* the time it calls this; a test wanting a specific budget passes its own.
|
|
56
|
+
*/
|
|
57
|
+
export declare function buildAnthropicRequest(request: ChatRequest, fallbackMaxTokens: number): AnthropicRequestBody;
|
|
41
58
|
/** Pure — no network. */
|
|
42
|
-
export declare function parseAnthropicResponse(body: AnthropicResponseBody): ChatResponse;
|
|
59
|
+
export declare function parseAnthropicResponse(body: AnthropicResponseBody, decodeToolName?: (wire: string) => string): ChatResponse;
|
|
43
60
|
export interface AnthropicClientConfig {
|
|
44
61
|
readonly apiKey: string;
|
|
45
62
|
readonly model: string;
|
|
46
63
|
/** Overridable for tests — never for anything else. */
|
|
47
64
|
readonly baseUrl?: string;
|
|
48
65
|
readonly fetchImpl?: typeof fetch;
|
|
66
|
+
/** See `ProviderClient.maxOutputTokens`/`requestTimeoutMs`/`maxCorrectionAttempts` — the admin's per-provider override, absent meaning "use `defaults`". */
|
|
67
|
+
readonly maxOutputTokens?: number;
|
|
68
|
+
readonly requestTimeoutMs?: number;
|
|
69
|
+
readonly maxCorrectionAttempts?: number;
|
|
70
|
+
/** The site-wide floor (`resolveProviderTuningDefaults`, `assistant.*` site settings) — always required, never a built-in constant. */
|
|
71
|
+
readonly defaults: ProviderTuningDefaults;
|
|
49
72
|
}
|
|
50
73
|
/**
|
|
51
74
|
* The API key is injected here, at the runtime boundary, from
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAG3D,OAAO,KAAK,EAGV,WAAW,EACX,YAAY,EACZ,cAAc,EAGf,MAAM,YAAY,CAAA;AAKnB,KAAK,qBAAqB,GACtB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAChD;IACE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,MAAM,EAAE;QACf,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;QACvB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;QAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KACtB,CAAA;CACF,GACD;IACE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAA;IACzB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,KAAK,EAAE,O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oBAAoB,CAiBtB;AAED,yBAAyB;AACzB,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,qBAAqB,EAC3B,cAAc,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAuB,GACxD,YAAY,CAmBd;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,uDAAuD;IACvD,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,KAAK,CAAA;IACjC,4JAA4J;IAC5J,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAA;IACjC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;IAClC,QAAQ,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAA;IACvC,uIAAuI;IACvI,QAAQ,CAAC,QAAQ,EAAE,sBAAsB,CAAA;CAC1C;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,qBAAqB,GAAG,cAAc,CA+DnF"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { CogentaError } from '@cogenta/core';
|
|
2
|
+
import { textOnlyContent } from './content-parts.js';
|
|
3
|
+
import { requestSignalWithTimeout } from './request-signal.js';
|
|
4
|
+
import { createToolNameDecoder, encodeToolName } from './tool-names.js';
|
|
2
5
|
const API_VERSION = '2023-06-01';
|
|
3
6
|
const DEFAULT_BASE_URL = 'https://api.anthropic.com/v1/messages';
|
|
4
7
|
const STOP_REASON = {
|
|
@@ -19,16 +22,36 @@ function toAnthropicMessage(message) {
|
|
|
19
22
|
return {
|
|
20
23
|
role: 'user',
|
|
21
24
|
content: [
|
|
22
|
-
{
|
|
25
|
+
{
|
|
26
|
+
type: 'tool_result',
|
|
27
|
+
tool_use_id: message.toolCallId,
|
|
28
|
+
content: textOnlyContent(message.content) ?? '',
|
|
29
|
+
},
|
|
23
30
|
],
|
|
24
31
|
};
|
|
25
32
|
}
|
|
26
33
|
const role = message.role === 'assistant' ? 'assistant' : 'user';
|
|
27
34
|
const blocks = [];
|
|
28
|
-
if (message.content
|
|
35
|
+
if (typeof message.content === 'string') {
|
|
29
36
|
blocks.push({ type: 'text', text: message.content });
|
|
37
|
+
}
|
|
38
|
+
else if (message.content !== undefined) {
|
|
39
|
+
for (const part of message.content) {
|
|
40
|
+
blocks.push(part.type === 'text'
|
|
41
|
+
? { type: 'text', text: part.text }
|
|
42
|
+
: {
|
|
43
|
+
type: 'image',
|
|
44
|
+
source: { type: 'base64', media_type: part.mediaType, data: part.data },
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
30
48
|
for (const call of message.toolCalls ?? []) {
|
|
31
|
-
blocks.push({
|
|
49
|
+
blocks.push({
|
|
50
|
+
type: 'tool_use',
|
|
51
|
+
id: call.id,
|
|
52
|
+
name: encodeToolName(call.name),
|
|
53
|
+
input: call.input,
|
|
54
|
+
});
|
|
32
55
|
}
|
|
33
56
|
// A plain string is equivalent to a single text block and reads better in
|
|
34
57
|
// request logs — only messages that carry tool content need the array form.
|
|
@@ -37,18 +60,27 @@ function toAnthropicMessage(message) {
|
|
|
37
60
|
}
|
|
38
61
|
return { role, content: blocks };
|
|
39
62
|
}
|
|
40
|
-
/**
|
|
41
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Pure — no network. The whole reason this is separate from
|
|
65
|
+
* `createAnthropicClient` is to unit-test the mapping without a live call.
|
|
66
|
+
* `fallbackMaxTokens` is the client's own resolved `maxOutputTokens` (the
|
|
67
|
+
* admin's per-provider value, or the site-wide default) — applied only when
|
|
68
|
+
* `request.maxTokens` itself is absent, never overriding an explicit
|
|
69
|
+
* per-call value. Required, not defaulted: the one caller that matters
|
|
70
|
+
* (`createAnthropicClient`'s own `chat()`) always has a concrete number by
|
|
71
|
+
* the time it calls this; a test wanting a specific budget passes its own.
|
|
72
|
+
*/
|
|
73
|
+
export function buildAnthropicRequest(request, fallbackMaxTokens) {
|
|
42
74
|
return {
|
|
43
75
|
model: request.model,
|
|
44
|
-
max_tokens: request.maxTokens,
|
|
76
|
+
max_tokens: request.maxTokens ?? fallbackMaxTokens,
|
|
45
77
|
...(request.system === undefined ? {} : { system: request.system }),
|
|
46
78
|
messages: request.messages.map(toAnthropicMessage),
|
|
47
79
|
...(request.tools === undefined
|
|
48
80
|
? {}
|
|
49
81
|
: {
|
|
50
82
|
tools: request.tools.map((tool) => ({
|
|
51
|
-
name: tool.name,
|
|
83
|
+
name: encodeToolName(tool.name),
|
|
52
84
|
description: tool.description,
|
|
53
85
|
input_schema: tool.inputSchema,
|
|
54
86
|
})),
|
|
@@ -57,7 +89,7 @@ export function buildAnthropicRequest(request) {
|
|
|
57
89
|
};
|
|
58
90
|
}
|
|
59
91
|
/** Pure — no network. */
|
|
60
|
-
export function parseAnthropicResponse(body) {
|
|
92
|
+
export function parseAnthropicResponse(body, decodeToolName = (wire) => wire) {
|
|
61
93
|
const textParts = [];
|
|
62
94
|
const toolCalls = [];
|
|
63
95
|
for (const block of body.content) {
|
|
@@ -66,7 +98,7 @@ export function parseAnthropicResponse(body) {
|
|
|
66
98
|
else if (block.type === 'tool_use') {
|
|
67
99
|
toolCalls.push({
|
|
68
100
|
id: block.id,
|
|
69
|
-
name: block.name,
|
|
101
|
+
name: decodeToolName(block.name),
|
|
70
102
|
input: (block.input ?? {}),
|
|
71
103
|
});
|
|
72
104
|
}
|
|
@@ -86,10 +118,18 @@ export function parseAnthropicResponse(body) {
|
|
|
86
118
|
export function createAnthropicClient(config) {
|
|
87
119
|
const doFetch = config.fetchImpl ?? fetch;
|
|
88
120
|
const url = config.baseUrl ?? DEFAULT_BASE_URL;
|
|
121
|
+
const maxOutputTokens = config.maxOutputTokens ?? config.defaults.maxOutputTokens;
|
|
122
|
+
const requestTimeoutMs = config.requestTimeoutMs ?? config.defaults.requestTimeoutMs;
|
|
123
|
+
const maxCorrectionAttempts = config.maxCorrectionAttempts ?? config.defaults.maxCorrectionAttempts;
|
|
89
124
|
return {
|
|
90
125
|
name: 'anthropic',
|
|
91
126
|
model: config.model,
|
|
127
|
+
supportsVision: true,
|
|
128
|
+
maxOutputTokens,
|
|
129
|
+
requestTimeoutMs,
|
|
130
|
+
maxCorrectionAttempts,
|
|
92
131
|
async chat(request, options) {
|
|
132
|
+
const signal = requestSignalWithTimeout(options?.signal, requestTimeoutMs);
|
|
93
133
|
const response = await doFetch(url, {
|
|
94
134
|
method: 'POST',
|
|
95
135
|
headers: {
|
|
@@ -97,9 +137,17 @@ export function createAnthropicClient(config) {
|
|
|
97
137
|
'x-api-key': config.apiKey,
|
|
98
138
|
'anthropic-version': API_VERSION,
|
|
99
139
|
},
|
|
100
|
-
body: JSON.stringify(buildAnthropicRequest(request)),
|
|
101
|
-
|
|
140
|
+
body: JSON.stringify(buildAnthropicRequest(request, maxOutputTokens)),
|
|
141
|
+
signal,
|
|
102
142
|
}).catch((cause) => {
|
|
143
|
+
if (signal.aborted && options?.signal?.aborted !== true) {
|
|
144
|
+
throw new CogentaError({
|
|
145
|
+
code: 'PROVIDER_REQUEST_FAILED',
|
|
146
|
+
message: 'Anthropic did not answer in time.',
|
|
147
|
+
hint: 'The vendor may be slow or unreachable right now; retry, or check its status page.',
|
|
148
|
+
cause,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
103
151
|
throw new CogentaError({
|
|
104
152
|
code: 'PROVIDER_REQUEST_FAILED',
|
|
105
153
|
message: 'The request to Anthropic could not be sent.',
|
|
@@ -123,7 +171,7 @@ export function createAnthropicClient(config) {
|
|
|
123
171
|
});
|
|
124
172
|
}
|
|
125
173
|
const body = (await response.json());
|
|
126
|
-
return parseAnthropicResponse(body);
|
|
174
|
+
return parseAnthropicResponse(body, createToolNameDecoder(request));
|
|
127
175
|
},
|
|
128
176
|
};
|
|
129
177
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAEpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAC9D,OAAO,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAWvE,MAAM,WAAW,GAAG,YAAY,CAAA;AAChC,MAAM,gBAAgB,GAAG,uCAAuC,CAAA;AA4ChE,MAAM,WAAW,GAA6D;IAC5E,QAAQ,EAAE,UAAU;IACpB,UAAU,EAAE,YAAY;IACxB,aAAa,EAAE,eAAe;IAC9B,QAAQ,EAAE,UAAU;CACrB,CAAA;AAED,SAAS,kBAAkB,CAAC,OAAoB;IAC9C,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QAC5B,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;YACrC,MAAM,IAAI,YAAY,CAAC;gBACrB,IAAI,EAAE,2BAA2B;gBACjC,OAAO,EAAE,gDAAgD;gBACzD,IAAI,EAAE,6DAA6D;aACpE,CAAC,CAAA;QACJ,CAAC;QACD,OAAO;YACL,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,aAAa;oBACnB,WAAW,EAAE,OAAO,CAAC,UAAU;oBAC/B,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE;iBAChD;aACF;SACF,CAAA;IACH,CAAC;IAED,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAA;IAChE,MAAM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AyB;oBAC/B,OAAO,EAAE,6BAA6B,QAAQ,CAAC,MAAM,GAAG;oBACxD,IAAI,EAAE,kDAAkD;oBACxD,OAAO,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,EAAE;iBACrC,CAAC,CAAA;YACJ,CAAC;YAED,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAA0B,CAAA;YAC7D,OAAO,sBAAsB,CAAC,IAAI,EAAE,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAA;QACrE,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fiche 56 — the catalog of LLM providers this build knows how to talk to,
|
|
3
|
+
* as pure data. `registry.ts`'s `createProviderRegistry` is the only reader
|
|
4
|
+
* that matters functionally: an entry with `wireFormat: 'openai-compatible'`
|
|
5
|
+
* reuses `createOpenAiClient` completely unmodified, only pointed at a
|
|
6
|
+
* different `defaultBaseUrl` — this is the "zero new network code" the fiche
|
|
7
|
+
* asks for. OpenRouter, DeepSeek, Qwen (DashScope's compatible mode) and GLM
|
|
8
|
+
* (Zhipu/Z.ai) all speak the OpenAI Chat Completions wire format at their own
|
|
9
|
+
* URL; Anthropic and Google keep their own native adapters (different wire
|
|
10
|
+
* formats), listed here only so the admin's catalog screen has one list to
|
|
11
|
+
* render rather than three built-ins plus four extras.
|
|
12
|
+
*
|
|
13
|
+
* `knownModels` is a curated starting point for the admin's model picker,
|
|
14
|
+
* not an exhaustive or authoritative list — every vendor adds and retires
|
|
15
|
+
* models on its own schedule, and this list will drift the moment it is
|
|
16
|
+
* written (verified against each vendor's docs as of 2026-08, the ids most
|
|
17
|
+
* likely to still resolve at read time). The "custom model" text field
|
|
18
|
+
* (`ProviderConfigInput.model` — already free text before this fiche) is
|
|
19
|
+
* what actually lets an operator use anything a vendor ships tomorrow
|
|
20
|
+
* without a code change here.
|
|
21
|
+
*/
|
|
22
|
+
export type ProviderWireFormat = 'openai-compatible' | 'anthropic' | 'google';
|
|
23
|
+
export interface ProviderCatalogEntry {
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly label: string;
|
|
26
|
+
readonly wireFormat: ProviderWireFormat;
|
|
27
|
+
/**
|
|
28
|
+
* The full chat-completions URL this vendor's endpoint answers at — this
|
|
29
|
+
* codebase's `baseUrl` is always a complete URL, never a prefix a client
|
|
30
|
+
* appends to (see `openai.ts`'s own `DEFAULT_BASE_URL`). Present on every
|
|
31
|
+
* entry, including the native Anthropic/Google ones, purely as
|
|
32
|
+
* admin-facing documentation of where a request actually goes; only the
|
|
33
|
+
* `openai-compatible` entries feed it to `createOpenAiClient` when an
|
|
34
|
+
* operator has not overridden `baseUrl` themselves.
|
|
35
|
+
*/
|
|
36
|
+
readonly defaultBaseUrl: string;
|
|
37
|
+
readonly knownModels: readonly string[];
|
|
38
|
+
}
|
|
39
|
+
export declare const KNOWN_PROVIDER_CATALOG: readonly ProviderCatalogEntry[];
|
|
40
|
+
export declare function findProviderCatalogEntry(id: string): ProviderCatalogEntry | undefined;
|
|
41
|
+
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/providers/catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,MAAM,kBAAkB,GAAG,mBAAmB,GAAG,WAAW,GAAG,QAAQ,CAAA;AAE7E,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,UAAU,EAAE,kBAAkB,CAAA;IACvC;;;;;;;;OAQG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAA;CACxC;AAED,eAAO,MAAM,sBAAsB,EAAE,SAAS,oBAAoB,EA2DjE,CAAA;AAED,wBAAgB,wBAAwB,CAAC,EAAE,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS,CAErF"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fiche 56 — the catalog of LLM providers this build knows how to talk to,
|
|
3
|
+
* as pure data. `registry.ts`'s `createProviderRegistry` is the only reader
|
|
4
|
+
* that matters functionally: an entry with `wireFormat: 'openai-compatible'`
|
|
5
|
+
* reuses `createOpenAiClient` completely unmodified, only pointed at a
|
|
6
|
+
* different `defaultBaseUrl` — this is the "zero new network code" the fiche
|
|
7
|
+
* asks for. OpenRouter, DeepSeek, Qwen (DashScope's compatible mode) and GLM
|
|
8
|
+
* (Zhipu/Z.ai) all speak the OpenAI Chat Completions wire format at their own
|
|
9
|
+
* URL; Anthropic and Google keep their own native adapters (different wire
|
|
10
|
+
* formats), listed here only so the admin's catalog screen has one list to
|
|
11
|
+
* render rather than three built-ins plus four extras.
|
|
12
|
+
*
|
|
13
|
+
* `knownModels` is a curated starting point for the admin's model picker,
|
|
14
|
+
* not an exhaustive or authoritative list — every vendor adds and retires
|
|
15
|
+
* models on its own schedule, and this list will drift the moment it is
|
|
16
|
+
* written (verified against each vendor's docs as of 2026-08, the ids most
|
|
17
|
+
* likely to still resolve at read time). The "custom model" text field
|
|
18
|
+
* (`ProviderConfigInput.model` — already free text before this fiche) is
|
|
19
|
+
* what actually lets an operator use anything a vendor ships tomorrow
|
|
20
|
+
* without a code change here.
|
|
21
|
+
*/
|
|
22
|
+
export const KNOWN_PROVIDER_CATALOG = [
|
|
23
|
+
{
|
|
24
|
+
id: 'anthropic',
|
|
25
|
+
label: 'Anthropic',
|
|
26
|
+
wireFormat: 'anthropic',
|
|
27
|
+
defaultBaseUrl: 'https://api.anthropic.com/v1/messages',
|
|
28
|
+
knownModels: ['claude-opus-5', 'claude-sonnet-5', 'claude-haiku-4-5'],
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: 'openai',
|
|
32
|
+
label: 'OpenAI',
|
|
33
|
+
wireFormat: 'openai-compatible',
|
|
34
|
+
defaultBaseUrl: 'https://api.openai.com/v1/chat/completions',
|
|
35
|
+
knownModels: ['gpt-5.2-chat-latest', 'gpt-5', 'gpt-5-mini'],
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: 'google',
|
|
39
|
+
label: 'Google',
|
|
40
|
+
wireFormat: 'google',
|
|
41
|
+
defaultBaseUrl: 'https://generativelanguage.googleapis.com/v1beta/models',
|
|
42
|
+
knownModels: ['gemini-3.1-pro', 'gemini-3.7-flash', 'gemini-2.5-flash-lite'],
|
|
43
|
+
},
|
|
44
|
+
// The four below are what fiche 56 actually adds: no new adapter, only a
|
|
45
|
+
// catalog entry pointing `openai-compatible` at a different vendor.
|
|
46
|
+
{
|
|
47
|
+
id: 'openrouter',
|
|
48
|
+
label: 'OpenRouter',
|
|
49
|
+
wireFormat: 'openai-compatible',
|
|
50
|
+
defaultBaseUrl: 'https://openrouter.ai/api/v1/chat/completions',
|
|
51
|
+
knownModels: [
|
|
52
|
+
'openai/gpt-5.2-chat-latest',
|
|
53
|
+
'anthropic/claude-sonnet-5',
|
|
54
|
+
'google/gemini-3.1-pro',
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: 'deepseek',
|
|
59
|
+
label: 'DeepSeek',
|
|
60
|
+
wireFormat: 'openai-compatible',
|
|
61
|
+
defaultBaseUrl: 'https://api.deepseek.com/chat/completions',
|
|
62
|
+
knownModels: ['deepseek-v4-pro', 'deepseek-v4-flash'],
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
id: 'qwen',
|
|
66
|
+
label: 'Qwen (DashScope)',
|
|
67
|
+
wireFormat: 'openai-compatible',
|
|
68
|
+
// The international (Singapore) region — the one DashScope's own docs
|
|
69
|
+
// lead with. An operator on the China or US region overrides `baseUrl`
|
|
70
|
+
// from the admin form, the same way any custom endpoint does.
|
|
71
|
+
defaultBaseUrl: 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions',
|
|
72
|
+
knownModels: ['qwen3-max', 'qwen-plus', 'qwen-turbo'],
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
id: 'glm',
|
|
76
|
+
label: 'GLM (Zhipu / Z.ai)',
|
|
77
|
+
wireFormat: 'openai-compatible',
|
|
78
|
+
defaultBaseUrl: 'https://api.z.ai/api/openai/v1/chat/completions',
|
|
79
|
+
knownModels: ['glm-4.7', 'glm-4.6', 'glm-4.5-flash'],
|
|
80
|
+
},
|
|
81
|
+
];
|
|
82
|
+
export function findProviderCatalogEntry(id) {
|
|
83
|
+
return KNOWN_PROVIDER_CATALOG.find((entry) => entry.id === id);
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.js","sourceRoot":"","sources":["../../src/providers/catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAqBH,MAAM,CAAC,MAAM,sBAAsB,GAAoC;IACrE;QACE,EAAE,EAAE,WAAW;QACf,KAAK,EAAE,WAAW;QAClB,UAAU,EAAE,WAAW;QACvB,cAAc,EAAE,uCAAuC;QACvD,WAAW,EAAE,CAAC,eAAe,EAAE,iBAAiB,EAAE,kBAAkB,CAAC;KACtE;IACD;QACE,EAAE,EAAE,QAAQ;QACZ,KAAK,EAAE,QAAQ;QACf,UAAU,EAAE,mBAAmB;QAC/B,cAAc,EAAE,4CAA4C;QAC5D,WAAW,EAAE,CAAC,qBAAqB,EAAE,OAAO,EAAE,YAAY,CAAC;KAC5D;IACD;QACE,EAAE,EAAE,QAAQ;QACZ,KAAK,EAAE,QAAQ;QACf,UAAU,EAAE,QAAQ;QACpB,cAAc,EAAE,yDAAyD;QACzE,WAAW,EAAE,CAAC,gBAAgB,EAAE,kBAAkB,EAAE,uBAAuB,CAAC;KAC7E;IACD,yEAAyE;IACzE,oEAAoE;IACpE;QACE,EAAE,EAAE,YAAY;QAChB,KAAK,EAAE,YAAY;QACnB,UAAU,EAAE,mBAAmB;QAC/B,cAAc,EAAE,+CAA+C;QAC/D,WAAW,EAAE;YACX,4BAA4B;YAC5B,2BAA2B;YAC3B,uBAAuB;SACxB;KACF;IACD;QACE,EAAE,EAAE,UAAU;QACd,KAAK,EAAE,UAAU;QACjB,UAAU,EAAE,mBAAmB;QAC/B,cAAc,EAAE,2CAA2C;QAC3D,WAAW,EAAE,CAAC,iBAAiB,EAAE,mBAAmB,CAAC;KACtD;IACD;QACE,EAAE,EAAE,MAAM;QACV,KAAK,EAAE,kBAAkB;QACzB,UAAU,EAAE,mBAAmB;QAC/B,sEAAsE;QACtE,uEAAuE;QACvE,8DAA8D;QAC9D,cAAc,EAAE,yEAAyE;QACzF,WAAW,EAAE,CAAC,WAAW,EAAE,WAAW,EAAE,YAAY,CAAC;KACtD;IACD;QACE,EAAE,EAAE,KAAK;QACT,KAAK,EAAE,oBAAoB;QAC3B,UAAU,EAAE,mBAAmB;QAC/B,cAAc,EAAE,iDAAiD;QACjE,WAAW,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,eAAe,CAAC;KACrD;CACF,CAAA;AAED,MAAM,UAAU,wBAAwB,CAAC,EAAU;IACjD,OAAO,sBAAsB,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,CAAC,CAAA;AAChE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ChatContentPart } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts the text of a message's `content`, dropping any image parts —
|
|
4
|
+
* used wherever a vendor's wire format only ever accepts a string (tool
|
|
5
|
+
* results, function responses). Every existing caller passes a plain
|
|
6
|
+
* string here already, so this is the identity function for them; an
|
|
7
|
+
* array of `ChatContentPart` (not something the runtime produces for a
|
|
8
|
+
* `tool`-role message today) degrades to its text parts joined together
|
|
9
|
+
* rather than failing to compile or throwing.
|
|
10
|
+
*/
|
|
11
|
+
export declare function textOnlyContent(content: string | readonly ChatContentPart[] | undefined): string | undefined;
|
|
12
|
+
//# sourceMappingURL=content-parts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-parts.d.ts","sourceRoot":"","sources":["../../src/providers/content-parts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,GAAG,SAAS,eAAe,EAAE,GAAG,SAAS,GACvD,MAAM,GAAG,SAAS,CAMpB"}
|