@cat-factory/agents 0.146.6 → 0.147.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/kinds/bug-investigator.d.ts.map +1 -1
- package/dist/agents/kinds/bug-investigator.js +7 -3
- package/dist/agents/kinds/bug-investigator.js.map +1 -1
- package/dist/agents/kinds/traits.d.ts +22 -0
- package/dist/agents/kinds/traits.d.ts.map +1 -1
- package/dist/agents/kinds/traits.js +38 -3
- package/dist/agents/kinds/traits.js.map +1 -1
- package/dist/foundationalServices/FoundationalServiceCatalogService.js +1 -0
- package/dist/foundationalServices/FoundationalServiceCatalogService.js.map +1 -1
- package/dist/foundationalServices/ServiceCatalogSyncService.d.ts +77 -0
- package/dist/foundationalServices/ServiceCatalogSyncService.d.ts.map +1 -0
- package/dist/foundationalServices/ServiceCatalogSyncService.js +384 -0
- package/dist/foundationalServices/ServiceCatalogSyncService.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/providers/endpoints.d.ts +60 -0
- package/dist/providers/endpoints.d.ts.map +1 -1
- package/dist/providers/endpoints.js +39 -0
- package/dist/providers/endpoints.js.map +1 -1
- package/dist/providers/gateway-attribution.d.ts +74 -0
- package/dist/providers/gateway-attribution.d.ts.map +1 -0
- package/dist/providers/gateway-attribution.js +120 -0
- package/dist/providers/gateway-attribution.js.map +1 -0
- package/dist/providers/index.d.ts +3 -2
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +3 -2
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/instrumented.d.ts.map +1 -1
- package/dist/providers/instrumented.js +19 -0
- package/dist/providers/instrumented.js.map +1 -1
- package/dist/providers/resolvers.d.ts +79 -0
- package/dist/providers/resolvers.d.ts.map +1 -1
- package/dist/providers/resolvers.js +91 -8
- package/dist/providers/resolvers.js.map +1 -1
- package/package.json +6 -5
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createAnthropic } from '@ai-sdk/anthropic';
|
|
2
2
|
import { createOpenAI } from '@ai-sdk/openai';
|
|
3
3
|
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
|
|
4
|
-
import {
|
|
4
|
+
import { createOpenRouter } from '@openrouter/ai-sdk-provider';
|
|
5
|
+
import { cloudflareRestBaseUrl, DEFAULT_OPENROUTER_ROUTING, isOperatorHostedGateway, OPENROUTER_BASE_URL, } from './endpoints.js';
|
|
5
6
|
// The base, runtime-neutral resolvers. They depend only on `ai` + the `@ai-sdk/*`
|
|
6
7
|
// vendor packages (no Cloudflare bindings, no Node built-ins), so they run on both
|
|
7
8
|
// the Worker and the Node service. Heavier/optional backends (e.g. AWS Bedrock) ship
|
|
@@ -42,9 +43,51 @@ export function openAiCompatibleResolver(opts) {
|
|
|
42
43
|
apiKey: opts.apiKey,
|
|
43
44
|
baseURL: opts.baseURL,
|
|
44
45
|
...(opts.fetch ? { fetch: opts.fetch } : {}),
|
|
46
|
+
supportsStructuredOutputs: opts.supportsStructuredOutputs ?? false,
|
|
45
47
|
});
|
|
46
48
|
return (ref) => provider(ref.model);
|
|
47
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Resolver for OpenRouter, which is a GATEWAY rather than one more OpenAI-compatible vendor
|
|
52
|
+
* and is therefore not served by {@link openAiCompatibleResolver}.
|
|
53
|
+
*
|
|
54
|
+
* Three things the generic client structurally cannot do, each of which OpenRouter answers:
|
|
55
|
+
*
|
|
56
|
+
* - **It reports what the call actually cost.** `usage: { include: true }` turns on usage
|
|
57
|
+
* accounting, and the reply carries `providerMetadata.openrouter.usage.cost` (real USD, the
|
|
58
|
+
* gateway's own ledger) plus `provider` (which upstream served it). Everywhere else this
|
|
59
|
+
* platform DERIVES cost from a price table; against a passthrough gateway reselling 300+
|
|
60
|
+
* models that derivation is a guess, and this is the one provider that hands over the answer.
|
|
61
|
+
* - **It routes per request.** {@link OpenRouterRouting} states the two constraints a
|
|
62
|
+
* deployment puts on that routing: keeping the request off an upstream that would silently
|
|
63
|
+
* ignore a tool definition, and off one that retains prompts. Both are the deployment's
|
|
64
|
+
* rather than constants here, because both can narrow the pool to nothing.
|
|
65
|
+
*
|
|
66
|
+
* NOT set here: `structuredOutputs.strict`, which this client already defaults to true ("When
|
|
67
|
+
* `strict` is left unset, the SDK defaults to `true` for backward compatibility", its own option
|
|
68
|
+
* doc). The trap runs the OPPOSITE way round from {@link openAiCompatibleResolver}'s, where the
|
|
69
|
+
* default is false and a schema is silently dropped: here the option exists to opt OUT for a
|
|
70
|
+
* model whose upstream does not advertise strict mode, so writing `strict: true` would pin the
|
|
71
|
+
* default while reading like an opt-in nobody may remove.
|
|
72
|
+
*/
|
|
73
|
+
export function openRouterResolver(opts) {
|
|
74
|
+
const routing = opts.routing ?? DEFAULT_OPENROUTER_ROUTING;
|
|
75
|
+
const provider = createOpenRouter({
|
|
76
|
+
apiKey: opts.apiKey,
|
|
77
|
+
baseURL: opts.baseURL ?? OPENROUTER_BASE_URL,
|
|
78
|
+
// `strict` is what OpenRouter's own API expects and what this gateway is reached at, as
|
|
79
|
+
// opposed to a third-party endpoint merely speaking its dialect.
|
|
80
|
+
compatibility: 'strict',
|
|
81
|
+
...(opts.fetch ? { fetch: opts.fetch } : {}),
|
|
82
|
+
});
|
|
83
|
+
return (ref) => provider(ref.model, {
|
|
84
|
+
usage: { include: true },
|
|
85
|
+
provider: {
|
|
86
|
+
require_parameters: routing.requireParameters,
|
|
87
|
+
data_collection: routing.dataCollection,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
}
|
|
48
91
|
/**
|
|
49
92
|
* Resolver for Cloudflare-hosted models reached over HTTP (no Workers `AI` binding):
|
|
50
93
|
* either the Workers AI OpenAI-compatible REST endpoint (account id + API token) or an
|
|
@@ -56,11 +99,52 @@ export function cloudflareRestResolver(opts) {
|
|
|
56
99
|
const baseURL = opts.baseURL ?? cloudflareRestBaseUrl(opts);
|
|
57
100
|
return openAiCompatibleResolver({ name: 'cloudflare', apiKey: opts.apiToken, baseURL });
|
|
58
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Turn ONE key-pooled OpenAI-compatible provider into its resolver, dispatching OpenRouter to
|
|
104
|
+
* {@link openRouterResolver} and everything else to {@link openAiCompatibleResolver}.
|
|
105
|
+
*
|
|
106
|
+
* The single place that dispatch is made. Every entry point that builds a direct provider from a
|
|
107
|
+
* leased key routes through here: the server's `buildDirectResolver`, which is the one this
|
|
108
|
+
* repo's facades run on, and {@link baseProviderRegistry}, the exported deployment-level seam a
|
|
109
|
+
* host assembling its own registry uses. Neither may make the OpenRouter-vs-generic decision
|
|
110
|
+
* itself, because that split is invisible at runtime: the generic client answers correctly, it
|
|
111
|
+
* just answers with no reported cost and no upstream name, which reads downstream as a gateway
|
|
112
|
+
* that reports nothing rather than as a mis-wired resolver.
|
|
113
|
+
*
|
|
114
|
+
* `supportsStructuredOutputs` is claimed for the CLOUD VENDORS only, and withheld from the
|
|
115
|
+
* operator-hosted gateways for the same reason a per-user local runner is left on the SDK's own
|
|
116
|
+
* default: what `bifrost` and `litellm` serve is whatever the operator's `config.yaml` points
|
|
117
|
+
* them at, routinely an Ollama or vLLM model that answers a `json_schema` request with a 400.
|
|
118
|
+
* Claiming it there would turn today's silent downgrade to `json_object` into a hard failure on
|
|
119
|
+
* the first `generateObject` call, and the flag is per PROVIDER, so no caller could exempt them.
|
|
120
|
+
* The set is DERIVED from the endpoint table's own `null` entries ({@link isOperatorHostedGateway})
|
|
121
|
+
* rather than re-listed, so a gateway added there cannot be forgotten here.
|
|
122
|
+
*/
|
|
123
|
+
export function directOpenAiCompatibleResolver(provider, apiKey, opts) {
|
|
124
|
+
if (provider === 'openrouter') {
|
|
125
|
+
return openRouterResolver({
|
|
126
|
+
apiKey,
|
|
127
|
+
baseURL: opts.baseURL,
|
|
128
|
+
...(opts.openRouterRouting ? { routing: opts.openRouterRouting } : {}),
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return openAiCompatibleResolver({
|
|
132
|
+
name: provider,
|
|
133
|
+
apiKey,
|
|
134
|
+
baseURL: opts.baseURL,
|
|
135
|
+
supportsStructuredOutputs: !isOperatorHostedGateway(provider),
|
|
136
|
+
});
|
|
137
|
+
}
|
|
59
138
|
/**
|
|
60
139
|
* Build the base provider registry from a deployment's credentials. Each provider is
|
|
61
140
|
* registered only when its credential is present, so an unconfigured provider resolves
|
|
62
141
|
* to a clear "Unsupported model provider" error rather than a deep SDK failure. Mix
|
|
63
142
|
* extra registries (e.g. Bedrock, the Workers AI binding) in afterwards.
|
|
143
|
+
*
|
|
144
|
+
* The EXPORTED seam, with no caller inside this repo: both facades build their per-scope
|
|
145
|
+
* providers through the server's `buildDirectResolver` instead. It stays because a host
|
|
146
|
+
* assembling a registry from raw credentials is the shape this package publishes, and it takes
|
|
147
|
+
* the same routing option that path does, so the two cannot answer differently.
|
|
64
148
|
*/
|
|
65
149
|
export function baseProviderRegistry(opts) {
|
|
66
150
|
const registry = {
|
|
@@ -72,13 +156,12 @@ export function baseProviderRegistry(opts) {
|
|
|
72
156
|
: undefined,
|
|
73
157
|
};
|
|
74
158
|
for (const [provider, upstream] of Object.entries(opts.openAiCompatible ?? {})) {
|
|
75
|
-
if (upstream?.apiKey)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
159
|
+
if (!upstream?.apiKey)
|
|
160
|
+
continue;
|
|
161
|
+
registry[provider] = directOpenAiCompatibleResolver(provider, upstream.apiKey, {
|
|
162
|
+
baseURL: upstream.baseURL,
|
|
163
|
+
...(opts.openRouterRouting ? { openRouterRouting: opts.openRouterRouting } : {}),
|
|
164
|
+
});
|
|
82
165
|
}
|
|
83
166
|
if (opts.cloudflareRest)
|
|
84
167
|
registry['workers-ai'] = cloudflareRestResolver(opts.cloudflareRest);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolvers.js","sourceRoot":"","sources":["../../src/providers/resolvers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AAClE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"resolvers.js","sourceRoot":"","sources":["../../src/providers/resolvers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAA;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAC9D,OAAO,EACL,qBAAqB,EACrB,0BAA0B,EAC1B,uBAAuB,EACvB,mBAAmB,GAEpB,MAAM,gBAAgB,CAAA;AAGvB,kFAAkF;AAClF,mFAAmF;AACnF,qFAAqF;AACrF,8DAA8D;AAE9D,qFAAqF;AACrF,MAAM,UAAU,cAAc,CAAC,IAA2C;IACxE,MAAM,QAAQ,GAAG,YAAY,CAAC;QAC5B,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACnD,CAAC,CAAA;IACF,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;AACrC,CAAC;AAED,8BAA8B;AAC9B,MAAM,UAAU,iBAAiB,CAAC,IAA2C;IAC3E,MAAM,QAAQ,GAAG,eAAe,CAAC;QAC/B,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,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AC5E,CAAC,CAAC,SAAS;QACb,SAAS,EAAE,IAAI,CAAC,eAAe;YAC7B,CAAC,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,CAAC;YACrD,CAAC,CAAC,SAAS;KACd,CAAA;IACD,KAAK,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,IAAI,EAAE,CAAC,EAAE,CAAC;QAC/E,IAAI,CAAC,QAAQ,EAAE,MAAM;YAAE,SAAQ;QAC/B,QAAQ,CAAC,QAAQ,CAAC,GAAG,8BAA8B,CAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE;YAC7E,OAAO,EAAE,QAAQ,CAAC,OAAO;YACzB,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACjF,CAAC,CAAA;IACJ,CAAC;IACD,IAAI,IAAI,CAAC,cAAc;QAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,sBAAsB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;IAC7F,OAAO,QAAQ,CAAA;AACjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cat-factory/agents",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.147.0",
|
|
4
4
|
"description": "Agent catalog, routing, prompts and fragment library for the Agent Architecture Board.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,16 +28,17 @@
|
|
|
28
28
|
"@ai-sdk/openai": "^4.0.52",
|
|
29
29
|
"@ai-sdk/openai-compatible": "^3.0.41",
|
|
30
30
|
"@ai-sdk/provider": "^4.0.9",
|
|
31
|
-
"@cat-factory/contracts": "0.
|
|
32
|
-
"@cat-factory/kernel": "0.
|
|
33
|
-
"@cat-factory/prompt-fragments": "1.1.
|
|
31
|
+
"@cat-factory/contracts": "0.335.0",
|
|
32
|
+
"@cat-factory/kernel": "0.324.0",
|
|
33
|
+
"@cat-factory/prompt-fragments": "1.1.18",
|
|
34
|
+
"@openrouter/ai-sdk-provider": "^3.0.0",
|
|
34
35
|
"ai": "^7.0.85",
|
|
35
36
|
"handlebars": "^4.7.9",
|
|
36
37
|
"p-map": "^7.0.7",
|
|
37
38
|
"valibot": "^1.4.2"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@cat-factory/caching": "0.20.
|
|
41
|
+
"@cat-factory/caching": "0.20.56",
|
|
41
42
|
"typescript": "7.0.2",
|
|
42
43
|
"vitest": "^4.1.11"
|
|
43
44
|
},
|