@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,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the text of a message's `content`, dropping any image parts —
|
|
3
|
+
* used wherever a vendor's wire format only ever accepts a string (tool
|
|
4
|
+
* results, function responses). Every existing caller passes a plain
|
|
5
|
+
* string here already, so this is the identity function for them; an
|
|
6
|
+
* array of `ChatContentPart` (not something the runtime produces for a
|
|
7
|
+
* `tool`-role message today) degrades to its text parts joined together
|
|
8
|
+
* rather than failing to compile or throwing.
|
|
9
|
+
*/
|
|
10
|
+
export function textOnlyContent(content) {
|
|
11
|
+
if (content === undefined || typeof content === 'string')
|
|
12
|
+
return content;
|
|
13
|
+
return content
|
|
14
|
+
.filter((part) => part.type === 'text')
|
|
15
|
+
.map((part) => part.text)
|
|
16
|
+
.join('');
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=content-parts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-parts.js","sourceRoot":"","sources":["../../src/providers/content-parts.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC7B,OAAwD;IAExD,IAAI,OAAO,KAAK,SAAS,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,OAAO,CAAA;IACxE,OAAO,OAAO;SACX,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC;SACtC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC;SACxB,IAAI,CAAC,EAAE,CAAC,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type SiteSettingsStore } from '@cogenta/schema';
|
|
2
|
+
/**
|
|
3
|
+
* The site-wide floor every resolved provider client's
|
|
4
|
+
* `maxOutputTokens`/`requestTimeoutMs`/`maxCorrectionAttempts` falls back to
|
|
5
|
+
* when an admin has not set a per-provider override — always a concrete
|
|
6
|
+
* number, resolved once from `assistant.defaultMaxOutputTokens`/
|
|
7
|
+
* `assistant.defaultRequestTimeoutSeconds`/
|
|
8
|
+
* `assistant.defaultMaxCorrectionAttempts` (`SITE_SETTINGS_REGISTRY` in
|
|
9
|
+
* `@cogenta/schema`) by whoever builds the provider registry (`cogenta
|
|
10
|
+
* serve`'s wiring — see `resolveProviderTuningDefaults` below), never a
|
|
11
|
+
* TypeScript constant baked into this package.
|
|
12
|
+
*
|
|
13
|
+
* Fiche feedback: `FALLBACK_MAX_OUTPUT_TOKENS = 8000` and
|
|
14
|
+
* `FALLBACK_MAX_CORRECTION_ATTEMPTS = 3` used to live here as plain
|
|
15
|
+
* exported numbers — invisible and unreachable from the admin, only ever
|
|
16
|
+
* mentioned as static hint text on `/admin/providers`. This file now only
|
|
17
|
+
* declares the *shape* those three numbers travel in between the settings
|
|
18
|
+
* store and `createProviderRegistry` — it holds no value of its own.
|
|
19
|
+
*/
|
|
20
|
+
export interface ProviderTuningDefaults {
|
|
21
|
+
readonly maxOutputTokens: number;
|
|
22
|
+
readonly requestTimeoutMs: number;
|
|
23
|
+
readonly maxCorrectionAttempts: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Reads the three `assistant.*` site settings and turns them into the shape
|
|
27
|
+
* every resolved provider client needs — the CLI wiring layer's own
|
|
28
|
+
* responsibility (`cogenta serve`, `packages/cli/src/commands/agent-runtime
|
|
29
|
+
* .ts`), exposed here so it never has to re-derive the key names or the
|
|
30
|
+
* seconds-to-milliseconds conversion itself.
|
|
31
|
+
*/
|
|
32
|
+
export declare function resolveProviderTuningDefaults(store: SiteSettingsStore): Promise<ProviderTuningDefaults>;
|
|
33
|
+
/**
|
|
34
|
+
* The registry's own defaults with no live per-site override consulted at
|
|
35
|
+
* all — for the one caller with no `SiteSettingsStore` to read from in the
|
|
36
|
+
* first place: `cogenta skin generate`, a one-shot CLI command that works
|
|
37
|
+
* straight off `cogenta.config.mjs` and already bypasses every other
|
|
38
|
+
* admin-configured override (`ProviderConfigStore`'s own per-provider
|
|
39
|
+
* tuning included) rather than a running site's database. Still the single
|
|
40
|
+
* declared number (`SITE_SETTINGS_REGISTRY`'s own `defaultValue`), never a
|
|
41
|
+
* second constant duplicated for this one caller.
|
|
42
|
+
*/
|
|
43
|
+
export declare function staticProviderTuningDefaults(): ProviderTuningDefaults;
|
|
44
|
+
//# sourceMappingURL=defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/providers/defaults.ts"],"names":[],"mappings":"AACA,OAAO,EAA4B,KAAK,iBAAiB,EAAoB,MAAM,iBAAiB,CAAA;AAEpG;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAA;IACjC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAA;CACvC;AAsCD;;;;;;GAMG;AACH,wBAAsB,6BAA6B,CACjD,KAAK,EAAE,iBAAiB,GACvB,OAAO,CAAC,sBAAsB,CAAC,CAWjC;AAED;;;;;;;;;GASG;AACH,wBAAgB,4BAA4B,IAAI,sBAAsB,CAMrE"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { CogentaError } from '@cogenta/core';
|
|
2
|
+
import { SITE_SETTINGS_SITE_SCOPE, siteSettingByKey } from '@cogenta/schema';
|
|
3
|
+
const MAX_OUTPUT_TOKENS_KEY = 'assistant.defaultMaxOutputTokens';
|
|
4
|
+
const REQUEST_TIMEOUT_SECONDS_KEY = 'assistant.defaultRequestTimeoutSeconds';
|
|
5
|
+
const MAX_CORRECTION_ATTEMPTS_KEY = 'assistant.defaultMaxCorrectionAttempts';
|
|
6
|
+
/**
|
|
7
|
+
* The registry's own declared default for a numeric setting
|
|
8
|
+
* (`SITE_SETTINGS_REGISTRY`'s own `defaultValue`) — the single place either
|
|
9
|
+
* reader below gets a fallback number from, never a second copy kept in this
|
|
10
|
+
* package. Throwing here is not reachable in practice (the three keys this
|
|
11
|
+
* file reads are declared with a numeric `defaultValue` in
|
|
12
|
+
* `site-settings-registry.ts`); it exists because neither caller has any way
|
|
13
|
+
* to prove that from its own call site, and a silent fallback to some other
|
|
14
|
+
* literal here would be exactly the hardcoding this file exists to avoid.
|
|
15
|
+
*/
|
|
16
|
+
function registryDefaultValue(key) {
|
|
17
|
+
const definition = siteSettingByKey(key);
|
|
18
|
+
if (definition !== undefined && typeof definition.defaultValue === 'number') {
|
|
19
|
+
return definition.defaultValue;
|
|
20
|
+
}
|
|
21
|
+
throw new CogentaError({
|
|
22
|
+
code: 'SITE_SETTING_INVALID',
|
|
23
|
+
message: `Site setting "${key}" has no numeric default registered.`,
|
|
24
|
+
hint: 'This is a registry bug — check the entry in SITE_SETTINGS_REGISTRY.',
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A row exists only once an admin has actually written this key
|
|
29
|
+
* (`SiteSettingsStore`'s own contract) — absent means "use the registry's
|
|
30
|
+
* own `defaultValue`" (`registryDefaultValue` above).
|
|
31
|
+
*/
|
|
32
|
+
async function resolveNumberSetting(store, key) {
|
|
33
|
+
const row = await store.get(key, SITE_SETTINGS_SITE_SCOPE);
|
|
34
|
+
return row !== null && typeof row.value === 'number' ? row.value : registryDefaultValue(key);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Reads the three `assistant.*` site settings and turns them into the shape
|
|
38
|
+
* every resolved provider client needs — the CLI wiring layer's own
|
|
39
|
+
* responsibility (`cogenta serve`, `packages/cli/src/commands/agent-runtime
|
|
40
|
+
* .ts`), exposed here so it never has to re-derive the key names or the
|
|
41
|
+
* seconds-to-milliseconds conversion itself.
|
|
42
|
+
*/
|
|
43
|
+
export async function resolveProviderTuningDefaults(store) {
|
|
44
|
+
const [maxOutputTokens, requestTimeoutSeconds, maxCorrectionAttempts] = await Promise.all([
|
|
45
|
+
resolveNumberSetting(store, MAX_OUTPUT_TOKENS_KEY),
|
|
46
|
+
resolveNumberSetting(store, REQUEST_TIMEOUT_SECONDS_KEY),
|
|
47
|
+
resolveNumberSetting(store, MAX_CORRECTION_ATTEMPTS_KEY),
|
|
48
|
+
]);
|
|
49
|
+
return {
|
|
50
|
+
maxOutputTokens,
|
|
51
|
+
requestTimeoutMs: requestTimeoutSeconds * 1000,
|
|
52
|
+
maxCorrectionAttempts,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The registry's own defaults with no live per-site override consulted at
|
|
57
|
+
* all — for the one caller with no `SiteSettingsStore` to read from in the
|
|
58
|
+
* first place: `cogenta skin generate`, a one-shot CLI command that works
|
|
59
|
+
* straight off `cogenta.config.mjs` and already bypasses every other
|
|
60
|
+
* admin-configured override (`ProviderConfigStore`'s own per-provider
|
|
61
|
+
* tuning included) rather than a running site's database. Still the single
|
|
62
|
+
* declared number (`SITE_SETTINGS_REGISTRY`'s own `defaultValue`), never a
|
|
63
|
+
* second constant duplicated for this one caller.
|
|
64
|
+
*/
|
|
65
|
+
export function staticProviderTuningDefaults() {
|
|
66
|
+
return {
|
|
67
|
+
maxOutputTokens: registryDefaultValue(MAX_OUTPUT_TOKENS_KEY),
|
|
68
|
+
requestTimeoutMs: registryDefaultValue(REQUEST_TIMEOUT_SECONDS_KEY) * 1000,
|
|
69
|
+
maxCorrectionAttempts: registryDefaultValue(MAX_CORRECTION_ATTEMPTS_KEY),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=defaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/providers/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAC5C,OAAO,EAAE,wBAAwB,EAA0B,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AA0BpG,MAAM,qBAAqB,GAAG,kCAAkC,CAAA;AAChE,MAAM,2BAA2B,GAAG,wCAAwC,CAAA;AAC5E,MAAM,2BAA2B,GAAG,wCAAwC,CAAA;AAE5E;;;;;;;;;GASG;AACH,SAAS,oBAAoB,CAAC,GAAW;IACvC,MAAM,UAAU,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAA;IACxC,IAAI,UAAU,KAAK,SAAS,IAAI,OAAO,UAAU,CAAC,YAAY,KAAK,QAAQ,EAAE,CAAC;QAC5E,OAAO,UAAU,CAAC,YAAY,CAAA;IAChC,CAAC;IACD,MAAM,IAAI,YAAY,CAAC;QACrB,IAAI,EAAE,sBAAsB;QAC5B,OAAO,EAAE,iBAAiB,GAAG,sCAAsC;QACnE,IAAI,EAAE,qEAAqE;KAC5E,CAAC,CAAA;AACJ,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,oBAAoB,CAAC,KAAwB,EAAE,GAAW;IACvE,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,wBAAwB,CAAC,CAAA;IAC1D,OAAO,GAAG,KAAK,IAAI,IAAI,OAAO,GAAG,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAA;AAC9F,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,KAAwB;IAExB,MAAM,CAAC,eAAe,EAAE,qBAAqB,EAAE,qBAAqB,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QACxF,oBAAoB,CAAC,KAAK,EAAE,qBAAqB,CAAC;QAClD,oBAAoB,CAAC,KAAK,EAAE,2BAA2B,CAAC;QACxD,oBAAoB,CAAC,KAAK,EAAE,2BAA2B,CAAC;KACzD,CAAC,CAAA;IACF,OAAO;QACL,eAAe;QACf,gBAAgB,EAAE,qBAAqB,GAAG,IAAI;QAC9C,qBAAqB;KACtB,CAAA;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,4BAA4B;IAC1C,OAAO;QACL,eAAe,EAAE,oBAAoB,CAAC,qBAAqB,CAAC;QAC5D,gBAAgB,EAAE,oBAAoB,CAAC,2BAA2B,CAAC,GAAG,IAAI;QAC1E,qBAAqB,EAAE,oBAAoB,CAAC,2BAA2B,CAAC;KACzE,CAAA;AACH,CAAC"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
import type { ProviderTuningDefaults } from './defaults.js';
|
|
1
2
|
import type { ChatRequest, ChatResponse, ProviderClient } from './types.js';
|
|
2
3
|
type GooglePart = {
|
|
3
4
|
readonly text: string;
|
|
5
|
+
} | {
|
|
6
|
+
readonly inlineData: {
|
|
7
|
+
readonly mimeType: string;
|
|
8
|
+
readonly data: string;
|
|
9
|
+
};
|
|
4
10
|
} | {
|
|
5
11
|
readonly functionCall: {
|
|
6
12
|
readonly name: string;
|
|
@@ -47,15 +53,26 @@ interface GoogleResponseBody {
|
|
|
47
53
|
readonly candidatesTokenCount: number;
|
|
48
54
|
};
|
|
49
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Pure — no network. `fallbackMaxTokens` is the client's own resolved
|
|
58
|
+
* `maxOutputTokens` (the admin's per-provider value, or the site-wide
|
|
59
|
+
* default) — applied only when `request.maxTokens` itself is absent.
|
|
60
|
+
* Required, not defaulted — see `buildAnthropicRequest`'s own doc comment.
|
|
61
|
+
*/
|
|
62
|
+
export declare function buildGoogleRequest(request: ChatRequest, fallbackMaxTokens: number): GoogleRequestBody;
|
|
50
63
|
/** Pure — no network. */
|
|
51
|
-
export declare function
|
|
52
|
-
/** Pure — no network. */
|
|
53
|
-
export declare function parseGoogleResponse(body: GoogleResponseBody): ChatResponse;
|
|
64
|
+
export declare function parseGoogleResponse(body: GoogleResponseBody, decodeToolName?: (wire: string) => string): ChatResponse;
|
|
54
65
|
export interface GoogleClientConfig {
|
|
55
66
|
readonly apiKey: string;
|
|
56
67
|
readonly model: string;
|
|
57
68
|
readonly baseUrl?: string;
|
|
58
69
|
readonly fetchImpl?: typeof fetch;
|
|
70
|
+
/** See `ProviderClient.maxOutputTokens`/`requestTimeoutMs`/`maxCorrectionAttempts`. */
|
|
71
|
+
readonly maxOutputTokens?: number;
|
|
72
|
+
readonly requestTimeoutMs?: number;
|
|
73
|
+
readonly maxCorrectionAttempts?: number;
|
|
74
|
+
/** The site-wide floor (`resolveProviderTuningDefaults`, `assistant.*` site settings) — always required, never a built-in constant. */
|
|
75
|
+
readonly defaults: ProviderTuningDefaults;
|
|
59
76
|
}
|
|
60
77
|
/** API key injected at the runtime boundary — never in a prompt or tool input (rule R7). */
|
|
61
78
|
export declare function createGoogleClient(config: GoogleClientConfig): ProviderClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../src/providers/google.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../src/providers/google.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;AAInB,KAAK,UAAU,GACX;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACzB;IAAE,QAAQ,CAAC,UAAU,EAAE;QAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GAC7E;IACE,QAAQ,CAAC,YAAY,EAAE;QACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;QACrB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;KACjD,CAAA;CACF,GACD;IACE,QAAQ,CAAC,gBAAgB,EAAE;QACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;QACrB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;KACrD,CAAA;CACF,CAAA;AAEL,UAAU,aAAa;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;IAC/B,QAAQ,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,CAAA;CACtC;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,CAAA;IAC3C,QAAQ,CAAC,iBAAiB,CAAC,EAAE;QAAE,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;YAAE,QAAQ,CAAC,IAAI,EA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C,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,KAAK,CAAA;IACjC,uFAAuF;IACvF,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,4FAA4F;AAC5F,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,cAAc,CA4D7E"}
|
package/dist/providers/google.js
CHANGED
|
@@ -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 DEFAULT_BASE_URL = 'https://generativelanguage.googleapis.com/v1beta/models';
|
|
3
6
|
const STOP_REASON = {
|
|
4
7
|
STOP: 'end_turn',
|
|
@@ -26,20 +29,42 @@ function toGoogleContent(message) {
|
|
|
26
29
|
}
|
|
27
30
|
return {
|
|
28
31
|
role: 'user',
|
|
29
|
-
|
|
32
|
+
// Encoded like the declaration Gemini matched the call against —
|
|
33
|
+
// idempotent on a toolCallId that already is the wire name.
|
|
34
|
+
parts: [
|
|
35
|
+
{
|
|
36
|
+
functionResponse: {
|
|
37
|
+
name: encodeToolName(name),
|
|
38
|
+
response: { result: textOnlyContent(message.content) ?? '' },
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
],
|
|
30
42
|
};
|
|
31
43
|
}
|
|
32
44
|
const role = message.role === 'assistant' ? 'model' : 'user';
|
|
33
45
|
const parts = [];
|
|
34
|
-
if (message.content
|
|
46
|
+
if (typeof message.content === 'string') {
|
|
35
47
|
parts.push({ text: message.content });
|
|
48
|
+
}
|
|
49
|
+
else if (message.content !== undefined) {
|
|
50
|
+
for (const part of message.content) {
|
|
51
|
+
parts.push(part.type === 'text'
|
|
52
|
+
? { text: part.text }
|
|
53
|
+
: { inlineData: { mimeType: part.mediaType, data: part.data } });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
36
56
|
for (const call of message.toolCalls ?? []) {
|
|
37
|
-
parts.push({ functionCall: { name: call.name, args: call.input } });
|
|
57
|
+
parts.push({ functionCall: { name: encodeToolName(call.name), args: call.input } });
|
|
38
58
|
}
|
|
39
59
|
return { role, parts };
|
|
40
60
|
}
|
|
41
|
-
/**
|
|
42
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Pure — no network. `fallbackMaxTokens` is the client's own resolved
|
|
63
|
+
* `maxOutputTokens` (the admin's per-provider value, or the site-wide
|
|
64
|
+
* default) — applied only when `request.maxTokens` itself is absent.
|
|
65
|
+
* Required, not defaulted — see `buildAnthropicRequest`'s own doc comment.
|
|
66
|
+
*/
|
|
67
|
+
export function buildGoogleRequest(request, fallbackMaxTokens) {
|
|
43
68
|
return {
|
|
44
69
|
contents: request.messages.map(toGoogleContent),
|
|
45
70
|
...(request.system === undefined
|
|
@@ -51,7 +76,7 @@ export function buildGoogleRequest(request) {
|
|
|
51
76
|
tools: [
|
|
52
77
|
{
|
|
53
78
|
functionDeclarations: request.tools.map((tool) => ({
|
|
54
|
-
name: tool.name,
|
|
79
|
+
name: encodeToolName(tool.name),
|
|
55
80
|
description: tool.description,
|
|
56
81
|
parameters: tool.inputSchema,
|
|
57
82
|
})),
|
|
@@ -59,13 +84,13 @@ export function buildGoogleRequest(request) {
|
|
|
59
84
|
],
|
|
60
85
|
}),
|
|
61
86
|
generationConfig: {
|
|
62
|
-
maxOutputTokens: request.maxTokens,
|
|
87
|
+
maxOutputTokens: request.maxTokens ?? fallbackMaxTokens,
|
|
63
88
|
...(request.temperature === undefined ? {} : { temperature: request.temperature }),
|
|
64
89
|
},
|
|
65
90
|
};
|
|
66
91
|
}
|
|
67
92
|
/** Pure — no network. */
|
|
68
|
-
export function parseGoogleResponse(body) {
|
|
93
|
+
export function parseGoogleResponse(body, decodeToolName = (wire) => wire) {
|
|
69
94
|
const candidate = body.candidates[0];
|
|
70
95
|
if (candidate === undefined) {
|
|
71
96
|
throw new CogentaError({
|
|
@@ -84,7 +109,7 @@ export function parseGoogleResponse(body) {
|
|
|
84
109
|
// so the name is the closest stable handle the rest of the runtime has.
|
|
85
110
|
toolCalls.push({
|
|
86
111
|
id: part.functionCall.name,
|
|
87
|
-
name: part.functionCall.name,
|
|
112
|
+
name: decodeToolName(part.functionCall.name),
|
|
88
113
|
input: part.functionCall.args,
|
|
89
114
|
});
|
|
90
115
|
}
|
|
@@ -104,16 +129,32 @@ export function createGoogleClient(config) {
|
|
|
104
129
|
const doFetch = config.fetchImpl ?? fetch;
|
|
105
130
|
const base = config.baseUrl ?? DEFAULT_BASE_URL;
|
|
106
131
|
const url = `${base}/${config.model}:generateContent?key=${config.apiKey}`;
|
|
132
|
+
const maxOutputTokens = config.maxOutputTokens ?? config.defaults.maxOutputTokens;
|
|
133
|
+
const requestTimeoutMs = config.requestTimeoutMs ?? config.defaults.requestTimeoutMs;
|
|
134
|
+
const maxCorrectionAttempts = config.maxCorrectionAttempts ?? config.defaults.maxCorrectionAttempts;
|
|
107
135
|
return {
|
|
108
136
|
name: 'google',
|
|
109
137
|
model: config.model,
|
|
138
|
+
supportsVision: true,
|
|
139
|
+
maxOutputTokens,
|
|
140
|
+
requestTimeoutMs,
|
|
141
|
+
maxCorrectionAttempts,
|
|
110
142
|
async chat(request, options) {
|
|
143
|
+
const signal = requestSignalWithTimeout(options?.signal, requestTimeoutMs);
|
|
111
144
|
const response = await doFetch(url, {
|
|
112
145
|
method: 'POST',
|
|
113
146
|
headers: { 'content-type': 'application/json' },
|
|
114
|
-
body: JSON.stringify(buildGoogleRequest(request)),
|
|
115
|
-
|
|
147
|
+
body: JSON.stringify(buildGoogleRequest(request, maxOutputTokens)),
|
|
148
|
+
signal,
|
|
116
149
|
}).catch((cause) => {
|
|
150
|
+
if (signal.aborted && options?.signal?.aborted !== true) {
|
|
151
|
+
throw new CogentaError({
|
|
152
|
+
code: 'PROVIDER_REQUEST_FAILED',
|
|
153
|
+
message: 'Google did not answer in time.',
|
|
154
|
+
hint: 'The vendor may be slow or unreachable right now; retry, or check its status page.',
|
|
155
|
+
cause,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
117
158
|
throw new CogentaError({
|
|
118
159
|
code: 'PROVIDER_REQUEST_FAILED',
|
|
119
160
|
message: 'The request to Google could not be sent.',
|
|
@@ -137,7 +178,7 @@ export function createGoogleClient(config) {
|
|
|
137
178
|
});
|
|
138
179
|
}
|
|
139
180
|
const body = (await response.json());
|
|
140
|
-
return parseGoogleResponse(body);
|
|
181
|
+
return parseGoogleResponse(body, createToolNameDecoder(request));
|
|
141
182
|
},
|
|
142
183
|
};
|
|
143
184
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google.js","sourceRoot":"","sources":["../../src/providers/google.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"google.js","sourceRoot":"","sources":["../../src/providers/google.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,gBAAgB,GAAG,yDAAyD,CAAA;AAkDlF,MAAM,WAAW,GAAiF;IAChG,IAAI,EAAE,UAAU;IAChB,UAAU,EAAE,YAAY;IACxB,MAAM,EAAE,eAAe;IACvB,UAA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
|
|
|
1
|
+
import type { ProviderTuningDefaults } from './defaults.js';
|
|
1
2
|
import type { ChatRequest, ChatResponse, ProviderClient } from './types.js';
|
|
2
3
|
interface OpenAiToolCall {
|
|
3
4
|
readonly id: string;
|
|
@@ -7,9 +8,18 @@ interface OpenAiToolCall {
|
|
|
7
8
|
readonly arguments: string;
|
|
8
9
|
};
|
|
9
10
|
}
|
|
11
|
+
type OpenAiContentPart = {
|
|
12
|
+
readonly type: 'text';
|
|
13
|
+
readonly text: string;
|
|
14
|
+
} | {
|
|
15
|
+
readonly type: 'image_url';
|
|
16
|
+
readonly image_url: {
|
|
17
|
+
readonly url: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
10
20
|
interface OpenAiMessage {
|
|
11
21
|
readonly role: 'system' | 'user' | 'assistant' | 'tool';
|
|
12
|
-
readonly content: string | null;
|
|
22
|
+
readonly content: string | readonly OpenAiContentPart[] | null;
|
|
13
23
|
readonly tool_calls?: readonly OpenAiToolCall[];
|
|
14
24
|
readonly tool_call_id?: string;
|
|
15
25
|
}
|
|
@@ -40,15 +50,37 @@ interface OpenAiResponseBody {
|
|
|
40
50
|
readonly completion_tokens: number;
|
|
41
51
|
};
|
|
42
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Pure — no network. `fallbackMaxTokens` is the client's own resolved
|
|
55
|
+
* `maxOutputTokens` (the admin's per-provider value, or the site-wide
|
|
56
|
+
* default) — applied only when `request.maxTokens` itself is absent.
|
|
57
|
+
* Required, not defaulted — see `buildAnthropicRequest`'s own doc comment.
|
|
58
|
+
*/
|
|
59
|
+
export declare function buildOpenAiRequest(request: ChatRequest, fallbackMaxTokens: number): OpenAiRequestBody;
|
|
43
60
|
/** Pure — no network. */
|
|
44
|
-
export declare function
|
|
45
|
-
/** Pure — no network. */
|
|
46
|
-
export declare function parseOpenAiResponse(body: OpenAiResponseBody): ChatResponse;
|
|
61
|
+
export declare function parseOpenAiResponse(body: OpenAiResponseBody, decodeToolName?: (wire: string) => string): ChatResponse;
|
|
47
62
|
export interface OpenAiClientConfig {
|
|
48
63
|
readonly apiKey: string;
|
|
49
64
|
readonly model: string;
|
|
50
65
|
readonly baseUrl?: string;
|
|
51
66
|
readonly fetchImpl?: typeof fetch;
|
|
67
|
+
/**
|
|
68
|
+
* The provider id this client reports itself as — `client.name`, used by
|
|
69
|
+
* the privacy allowlist (`assertProviderAllowed`) and by anything logging
|
|
70
|
+
* or citing "which provider answered". Defaults to `'openai'`, but every
|
|
71
|
+
* `wireFormat: 'openai-compatible'` catalog entry (fiche 56: OpenRouter,
|
|
72
|
+
* DeepSeek, Qwen, GLM, or an operator's custom endpoint) passes its own
|
|
73
|
+
* catalog id here — without this, every one of them would misreport
|
|
74
|
+
* itself as literally `'openai'`, silently defeating a "no data leaves
|
|
75
|
+
* this machine" policy scoped to a different vendor.
|
|
76
|
+
*/
|
|
77
|
+
readonly name?: string;
|
|
78
|
+
/** See `ProviderClient.maxOutputTokens`/`requestTimeoutMs`/`maxCorrectionAttempts`. */
|
|
79
|
+
readonly maxOutputTokens?: number;
|
|
80
|
+
readonly requestTimeoutMs?: number;
|
|
81
|
+
readonly maxCorrectionAttempts?: number;
|
|
82
|
+
/** The site-wide floor (`resolveProviderTuningDefaults`, `assistant.*` site settings) — always required, never a built-in constant. */
|
|
83
|
+
readonly defaults: ProviderTuningDefaults;
|
|
52
84
|
}
|
|
53
85
|
/** API key injected at the runtime boundary — never in a prompt or tool input (rule R7). */
|
|
54
86
|
export declare function createOpenAiClient(config: OpenAiClientConfig): ProviderClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/providers/openai.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AAG3D,OAAO,KAAK,EAGV,WAAW,EACX,YAAY,E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