@oh-my-pi/pi-catalog 18.4.4 → 18.4.6

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/types/compat/auth-ids.d.ts +2 -2
  3. package/dist/types/compat/axes.d.ts +3 -1
  4. package/dist/types/compat/factory-droid.d.ts +65 -0
  5. package/dist/types/compat/provider-ids.d.ts +1 -1
  6. package/dist/types/compat/resolve.d.ts +8 -2
  7. package/dist/types/compat/types.d.ts +26 -1
  8. package/dist/types/discovery/cursor-proto.d.ts +284 -0
  9. package/dist/types/discovery/cursor.d.ts +12 -6
  10. package/dist/types/discovery/factory-droid.d.ts +28 -0
  11. package/dist/types/discovery/index.d.ts +1 -0
  12. package/dist/types/discovery/protobuf.d.ts +3 -3
  13. package/dist/types/model-manager.d.ts +10 -0
  14. package/dist/types/models.d.ts +5 -1
  15. package/dist/types/provider-models/cache-provider-id.d.ts +2 -1
  16. package/dist/types/provider-models/descriptor-types.d.ts +2 -1
  17. package/dist/types/provider-models/openai-compat.d.ts +21 -0
  18. package/dist/types/provider-models/special.d.ts +2 -0
  19. package/dist/types/types.d.ts +100 -3
  20. package/dist/types/wire/cursor.d.ts +20 -0
  21. package/dist/types/wire/factory-droid.d.ts +45 -0
  22. package/package.json +4 -4
  23. package/src/build.ts +21 -0
  24. package/src/compat/auth-ids.ts +4 -0
  25. package/src/compat/axes.ts +113 -2
  26. package/src/compat/cascade.ts +8 -1
  27. package/src/compat/collapse.ts +3 -0
  28. package/src/compat/factory-droid.ts +170 -0
  29. package/src/compat/provider-ids.ts +2 -0
  30. package/src/compat/resolve.ts +47 -5
  31. package/src/compat/rules/README.md +18 -8
  32. package/src/compat/rules/auth/_order.kdl +2 -2
  33. package/src/compat/rules/auth/factory-droid.kdl +28 -0
  34. package/src/compat/rules/auth/helmcode.kdl +9 -0
  35. package/src/compat/rules/classes/anthropic.kdl +195 -80
  36. package/src/compat/rules/providers/commandcode.kdl +21 -5
  37. package/src/compat/rules/providers/cursor.kdl +29 -17
  38. package/src/compat/rules/providers/factory-droid.kdl +1166 -0
  39. package/src/compat/rules/providers/helmcode.kdl +120 -0
  40. package/src/compat/rules/runtime/behavior.kdl +65 -4
  41. package/src/compat/rules/taxonomy/_collapse.kdl +36 -14
  42. package/src/compat/rules.json +1 -1
  43. package/src/compat/types.ts +27 -1
  44. package/src/discovery/cursor-models.proto +261 -0
  45. package/src/discovery/cursor-proto.ts +471 -0
  46. package/src/discovery/cursor.ts +817 -88
  47. package/src/discovery/devin.ts +1 -3
  48. package/src/discovery/factory-droid.ts +296 -0
  49. package/src/discovery/index.ts +1 -0
  50. package/src/discovery/protobuf.ts +16 -7
  51. package/src/model-manager.ts +13 -0
  52. package/src/models.json +1 -1
  53. package/src/models.ts +13 -0
  54. package/src/provider-models/cache-provider-id.ts +37 -6
  55. package/src/provider-models/descriptor-types.ts +2 -1
  56. package/src/provider-models/descriptors.ts +4 -0
  57. package/src/provider-models/openai-compat.ts +83 -17
  58. package/src/provider-models/special.ts +26 -2
  59. package/src/types.ts +112 -1
  60. package/src/wire/cursor.ts +32 -0
  61. package/src/wire/factory-droid.ts +130 -0
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Factory Droid wire constants shared by catalog discovery, the pi-ai
3
+ * provider, OAuth login and account usage: client identity, upstream/region
4
+ * vocabulary, API hosts and the account-scoped model-cache namespace.
5
+ */
6
+ import { isRecord } from "../utils";
7
+
8
+ /**
9
+ * Client version reported to Factory's API. When bumping it, recapture the
10
+ * native request corpus with `packages/ai/scripts/capture-factory-droid-native.ts`
11
+ * against the matching CLI binary and make `factory-droid-native-parity.test.ts` pass.
12
+ */
13
+ export const FACTORY_DROID_CLIENT_VERSION = "0.230.0";
14
+
15
+ /** Wire protocols the Factory proxy multiplexes; `api-routes provider="factory-droid"` picks one per model. */
16
+ export const FACTORY_DROID_WIRES = [
17
+ "openai-completions",
18
+ "openai-responses",
19
+ "anthropic-messages",
20
+ "google-generate",
21
+ ] as const;
22
+
23
+ /** Wire protocol used by the Factory proxy for each model. */
24
+ export type FactoryDroidWire = (typeof FACTORY_DROID_WIRES)[number];
25
+
26
+ /**
27
+ * Upstream routers the proxy dispatches to, sent as the `x-api-provider`
28
+ * header. The KDL compiler validates the rotation and region axes against it.
29
+ */
30
+ export const FACTORY_DROID_UPSTREAMS = [
31
+ "fireworks",
32
+ "baseten",
33
+ "mistral",
34
+ "anthropic",
35
+ "azure_anthropic",
36
+ "vertex_anthropic",
37
+ "bedrock_anthropic",
38
+ "openai",
39
+ "azure_openai",
40
+ "bedrock_openai",
41
+ "google",
42
+ "xai",
43
+ "snowflake",
44
+ "databricks",
45
+ ] as const;
46
+
47
+ /** Inference serving region; independent from account/API-host residency. */
48
+ export type FactoryDroidRegion = "global" | "us" | "eu";
49
+
50
+ /**
51
+ * Account scope a Factory credential resolves to. Residency (`region`) selects
52
+ * the API host; `inferenceRegion` selects eligible upstreams and capacities.
53
+ * An EU-host account can legitimately have global inference.
54
+ */
55
+ export interface AccountScope {
56
+ region?: string;
57
+ inferenceRegion?: FactoryDroidRegion;
58
+ orgId?: string;
59
+ }
60
+
61
+ /** Inference region for an account: explicit scope wins, else EU residency infers EU, else global. */
62
+ export function resolveFactoryDroidInferenceRegion(scope: {
63
+ region?: string;
64
+ inferenceRegion?: FactoryDroidRegion;
65
+ }): FactoryDroidRegion {
66
+ return scope.inferenceRegion ?? (scope.region === "eu" ? "eu" : "global");
67
+ }
68
+
69
+ /** Factory API host per residency region; EU accounts are served from the EU region. */
70
+ export function factoryDroidApiBaseUrl(region: string | undefined): string {
71
+ return region === "eu" ? "https://api.eu.factory.ai" : "https://api.factory.ai";
72
+ }
73
+
74
+ /** Per-wire base URL for an account region; the stream layer appends the path suffix. */
75
+ export function factoryDroidWireBaseUrl(wire: FactoryDroidWire, region: string | undefined): string {
76
+ const host = factoryDroidApiBaseUrl(region);
77
+ switch (wire) {
78
+ case "openai-completions":
79
+ case "openai-responses":
80
+ return `${host}/api/llm/o/v1`;
81
+ case "anthropic-messages":
82
+ return `${host}/api/llm/a`;
83
+ case "google-generate":
84
+ return `${host}/api/llm/g/v1`;
85
+ }
86
+ }
87
+
88
+ /**
89
+ * Client identity headers shared by discovery, usage and inference requests.
90
+ * Callers add their own auth, `Accept`, routing and SDK headers.
91
+ */
92
+ export function factoryDroidClientHeaders(orgId: string | undefined): Record<string, string> {
93
+ return {
94
+ "X-Client-Version": FACTORY_DROID_CLIENT_VERSION,
95
+ "X-Factory-Client": "cli",
96
+ ...(orgId ? { "X-Factory-Org-Id": orgId } : {}),
97
+ };
98
+ }
99
+
100
+ /** Model-cache namespace for a Factory credential and its account scope. */
101
+ export function factoryDroidModelCacheProviderId(options: { apiKey?: string } & AccountScope): string {
102
+ // WorkOS access tokens rotate, but the proxy roster belongs to the
103
+ // external organization and user. Keep residency in the namespace too.
104
+ // Opaque credentials (including test keys) retain credential isolation.
105
+ const token = options.apiKey ?? "";
106
+ let credentialScope = `bearer\u0000${token}`;
107
+ const parts = token.split(".");
108
+ if (parts.length === 3 && parts.every(Boolean)) {
109
+ try {
110
+ const claims: unknown = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
111
+ if (
112
+ isRecord(claims) &&
113
+ !Array.isArray(claims) &&
114
+ typeof claims.external_org_id === "string" &&
115
+ claims.external_org_id.trim() &&
116
+ typeof claims.sub === "string" &&
117
+ claims.sub.trim()
118
+ ) {
119
+ credentialScope = `account\u0000${claims.external_org_id}\u0000${claims.sub}`;
120
+ }
121
+ } catch {
122
+ // Non-JWT credentials continue to hash the opaque bearer.
123
+ }
124
+ }
125
+ const region = options.region === "eu" ? "eu" : "global";
126
+ const scope = `${credentialScope}\u0000${options.orgId ?? ""}\u0000${region}\u0000${options.inferenceRegion ?? region}`;
127
+ // v4: rows cached before credits became a scalar base rate carry the old
128
+ // `{ input, output, cacheRead }` object and must be refetched.
129
+ return `factory-droid:models-v4:${Bun.hash(scope).toString(36)}`;
130
+ }