@oh-my-pi/pi-ai 18.3.4 → 18.4.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.
Files changed (62) hide show
  1. package/CHANGELOG.md +35 -48
  2. package/dist/types/auth/blocks.d.ts +10 -19
  3. package/dist/types/auth/cascade.d.ts +1 -1
  4. package/dist/types/auth/rotation.d.ts +6 -3
  5. package/dist/types/auth/types.d.ts +23 -3
  6. package/dist/types/auth/usage-cache.d.ts +14 -2
  7. package/dist/types/auth/usage.d.ts +2 -2
  8. package/dist/types/auth-broker/client.d.ts +2 -1
  9. package/dist/types/auth-broker/remote-store.d.ts +5 -6
  10. package/dist/types/auth-broker/types.d.ts +3 -1
  11. package/dist/types/auth-broker/wire-schemas.d.ts +2 -1
  12. package/dist/types/auth-retry.d.ts +22 -13
  13. package/dist/types/images/types.d.ts +9 -0
  14. package/dist/types/index.d.ts +1 -0
  15. package/dist/types/judgment/types.d.ts +3 -2
  16. package/dist/types/providers/cursor/exec-modern.d.ts +1 -1
  17. package/dist/types/providers/cursor-pi-args.d.ts +10 -0
  18. package/dist/types/providers/cursor.d.ts +6 -2
  19. package/dist/types/providers/google-shared.d.ts +13 -2
  20. package/dist/types/types.d.ts +0 -10
  21. package/dist/types/usage/claude-reset.d.ts +6 -0
  22. package/dist/types/usage/claude.d.ts +6 -0
  23. package/dist/types/usage.d.ts +2 -0
  24. package/dist/types/utils/proxy.d.ts +2 -2
  25. package/package.json +6 -6
  26. package/src/auth/blocks.ts +79 -37
  27. package/src/auth/cascade.ts +5 -4
  28. package/src/auth/resets.ts +104 -40
  29. package/src/auth/rotation.ts +62 -21
  30. package/src/auth/select.ts +9 -2
  31. package/src/auth/types.ts +28 -3
  32. package/src/auth/usage-cache.ts +45 -2
  33. package/src/auth/usage.ts +52 -25
  34. package/src/auth-broker/client.ts +13 -0
  35. package/src/auth-broker/remote-store.ts +128 -27
  36. package/src/auth-broker/server.ts +20 -0
  37. package/src/auth-broker/types.ts +4 -1
  38. package/src/auth-broker/wire-schemas.ts +7 -0
  39. package/src/auth-retry.ts +50 -28
  40. package/src/images/openai-hosted.ts +18 -3
  41. package/src/images/types.ts +9 -0
  42. package/src/index.ts +1 -0
  43. package/src/judgment/types.ts +10 -6
  44. package/src/judgment/typesafe.ts +2 -2
  45. package/src/providers/anthropic.ts +54 -123
  46. package/src/providers/cursor/exec-modern.ts +1 -0
  47. package/src/providers/cursor/proto/agent.proto +5 -0
  48. package/src/providers/cursor-pi-args.ts +14 -0
  49. package/src/providers/cursor.ts +66 -28
  50. package/src/providers/google-gemini-cli.ts +2 -19
  51. package/src/providers/google-shared.ts +30 -22
  52. package/src/providers/ollama.ts +2 -0
  53. package/src/registry/oauth/oauth.html +206 -185
  54. package/src/stream.ts +2 -284
  55. package/src/types.ts +0 -10
  56. package/src/usage/claude-reset.ts +45 -11
  57. package/src/usage/claude.ts +79 -49
  58. package/src/usage.ts +2 -0
  59. package/src/utils/proxy.ts +3 -3
  60. package/src/utils/schema/CONSTRAINTS.md +30 -28
  61. package/src/utils/schema/normalize.ts +1 -1
  62. package/src/utils/schema/wire.ts +3 -3
@@ -5,10 +5,11 @@ This document is the operational contract for schema normalization/strictness in
5
5
  ## Scope
6
6
 
7
7
  - Applies to provider-facing tool schemas produced by:
8
- - `normalize.ts` — Google, CCA, MCP, OpenAI Responses, and OpenAI strict-mode (sanitize + enforce) sanitization. All schema walkers live here.
9
- - `adapt.ts` — thin composer wrapping `tryEnforceStrictSchema` for provider call sites, plus the `PI_NO_STRICT` env flag callers consult to opt out of strict mode.
10
- - `fields.ts` — keyword classification sets used by the walkers.
8
+ - `normalize.ts` — Google, CCA, MCP, OpenAI Responses, and OpenAI strict-mode (sanitize + enforce) sanitization. All schema walkers live here.
9
+ - `adapt.ts` — thin composer wrapping `tryEnforceStrictSchema` for provider call sites, plus the `PI_NO_STRICT` env flag callers consult to opt out of strict mode.
10
+ - `fields.ts` — keyword classification sets used by the walkers.
11
11
  - Covers OpenAI-style strict mode, OpenAI Responses `oneOf` rejection, Google schema constraints, and Cloud Code Assist Claude constraints.
12
+
12
13
  ---
13
14
 
14
15
  ## 1) OpenAI-style strict mode (`adaptSchemaForStrict` / `tryEnforceStrictSchema`)
@@ -18,17 +19,17 @@ When strict mode is requested (`strict=true` at call site), the schema MUST sati
18
19
  1. **Non-structural keywords are removed before strict enforcement**
19
20
  - Sanitization uses `sanitizeSchemaForStrictMode`.
20
21
  - Removed keys include formatting/validation/decorative keywords and unsupported structural extras:
21
- - `format`, `pattern`, `minLength`, `maxLength`, `minimum`, `maximum`, `exclusiveMinimum`, `exclusiveMaximum`
22
- - `minItems`, `maxItems`, `uniqueItems`, `multipleOf`
23
- - `$schema`, `examples`, `default`, `title`, `$comment`
24
- - `if`, `then`, `else`, `not`
25
- - `unevaluatedProperties`, `unevaluatedItems`, `patternProperties`
26
- - `propertyNames`, `contains`, `minContains`, `maxContains`
27
- - `dependentRequired`, `dependentSchemas`
28
- - `contentEncoding`, `contentMediaType`, `contentSchema`
29
- - `deprecated`, `readOnly`, `writeOnly`
30
- - `minProperties`, `maxProperties`
31
- - `$dynamicRef`, `$dynamicAnchor`
22
+ - `format`, `pattern`, `minLength`, `maxLength`, `minimum`, `maximum`, `exclusiveMinimum`, `exclusiveMaximum`
23
+ - `minItems`, `maxItems`, `uniqueItems`, `multipleOf`
24
+ - `$schema`, `examples`, `default`, `title`, `$comment`
25
+ - `if`, `then`, `else`, `not`
26
+ - `unevaluatedProperties`, `unevaluatedItems`, `patternProperties`
27
+ - `propertyNames`, `contains`, `minContains`, `maxContains`
28
+ - `dependentRequired`, `dependentSchemas`
29
+ - `contentEncoding`, `contentMediaType`, `contentSchema`
30
+ - `deprecated`, `readOnly`, `writeOnly`
31
+ - `minProperties`, `maxProperties`
32
+ - `$dynamicRef`, `$dynamicAnchor`
32
33
  - Before stripping `default`, its value is inlined into the sibling `description` as ` (default: X)` so that strict-mode providers retain the default hint in free-form text. Inlining is skipped when `description` already contains `(default:` or when no sibling `description` is present.
33
34
 
34
35
  2. **`const` is normalized to `enum`**
@@ -38,8 +39,8 @@ When strict mode is requested (`strict=true` at call site), the schema MUST sati
38
39
  - Every object node gets `additionalProperties: false`.
39
40
  - Every property key is included in `required`.
40
41
  - Optional properties are made nullable:
41
- - Pure union nodes (only `anyOf` plus optional `description`) get a `{ "type": "null" }` branch appended in place — never a nested wrapper.
42
- - All other nodes are wrapped as `anyOf: [<original schema>, { "type": "null" }]`. Nodes with constraining siblings next to `anyOf` MUST keep the wrapper: sibling keywords are conjunctive with `anyOf`, so appending a null branch would not make the node nullable.
42
+ - Pure union nodes (only `anyOf` plus optional `description`) get a `{ "type": "null" }` branch appended in place — never a nested wrapper.
43
+ - All other nodes are wrapped as `anyOf: [<original schema>, { "type": "null" }]`. Nodes with constraining siblings next to `anyOf` MUST keep the wrapper: sibling keywords are conjunctive with `anyOf`, so appending a null branch would not make the node nullable.
43
44
  - Nested pure unions are spliced into the parent `anyOf` (`(A ∨ B) ∨ C` → `A ∨ B ∨ C`); an inner `description` is hoisted to the parent when the parent has none. Strict output MUST NOT contain an `anyOf` branch that is itself a pure union — some upstream validators (OpenRouter DeepSeek) reject branches without `type`.
44
45
  - Tuple entries in `prefixItems` are strictified recursively.
45
46
 
@@ -63,14 +64,14 @@ Schemas sent on the Google JSON Schema path MUST follow:
63
64
 
64
65
  1. **Unsupported JSON Schema keywords are stripped (except property names under `properties`)**
65
66
  - Unsupported keys (`UNSUPPORTED_SCHEMA_FIELDS`):
66
- - `$schema`, `$ref`, `$defs`, `$dynamicRef`, `$dynamicAnchor`
67
- - `examples`, `prefixItems`, `unevaluatedProperties`, `unevaluatedItems`
68
- - `patternProperties`, `additionalProperties`
69
- - `minItems`, `maxItems`, `minLength`, `maxLength`
70
- - `minimum`, `maximum`, `exclusiveMinimum`, `exclusiveMaximum`
71
- - `pattern`, `format`
72
- - `dependencies`, `dependentSchemas`, `dependentRequired`
73
- - `deprecated`, `readOnly`, `writeOnly`, `$comment`
67
+ - `$schema`, `$ref`, `$defs`, `$dynamicRef`, `$dynamicAnchor`
68
+ - `examples`, `prefixItems`, `unevaluatedProperties`, `unevaluatedItems`
69
+ - `patternProperties`, `additionalProperties`
70
+ - `minItems`, `maxItems`, `minLength`, `maxLength`
71
+ - `minimum`, `maximum`, `exclusiveMinimum`, `exclusiveMaximum`
72
+ - `pattern`, `format`
73
+ - `dependencies`, `dependentSchemas`, `dependentRequired`
74
+ - `deprecated`, `readOnly`, `writeOnly`, `$comment`
74
75
  - Important: keys inside a `properties` object are treated as property names and MUST NOT be stripped by keyword match.
75
76
  - Human-meaningful stripped keys (`pattern`, `format`, min/max constraints, `default`, `examples`, etc.) are appended to the sibling `description` as an Anthropic-style spill block: `{pattern: "^foo$", minimum: 0}`. Structural/meta keys such as `$ref`, `$defs`, and `additionalProperties` are not spilled.
76
77
 
@@ -83,6 +84,7 @@ Schemas sent on the Google JSON Schema path MUST follow:
83
84
 
84
85
  4. **Object schemas get an explicit properties map**
85
86
  - `{ "type": "object" }` becomes `{ "type": "object", "properties": {} }`.
87
+
86
88
  ---
87
89
 
88
90
  ## 3) Claude via Cloud Code Assist (`normalizeSchemaForCCA`)
@@ -144,14 +146,14 @@ If any remain, schema is incompatible.
144
146
  ## 4) Practical provider mapping
145
147
 
146
148
  - **OpenAI-compatible strict paths** (`openai-completions`, `openai-responses`, `openai-codex-responses`):
147
- - Use `adaptSchemaForStrict`.
148
- - Emit `strict: true` only when effective strict enforcement succeeded.
149
+ - Use `adaptSchemaForStrict`.
150
+ - Emit `strict: true` only when effective strict enforcement succeeded.
149
151
 
150
152
  - **Google Gemini/Vertex/Gemini CLI (non-CCA Claude)**:
151
- - Use `normalizeSchemaForGoogle` and send schema on `parametersJsonSchema` path.
153
+ - Use `normalizeSchemaForGoogle` and send schema on `parametersJsonSchema` path.
152
154
 
153
155
  - **Cloud Code Assist Claude models (`model.id` starts with `claude-`)**:
154
- - Use `normalizeSchemaForCCA` and send sanitized normalized schema in `parameters`.
156
+ - Use `normalizeSchemaForCCA` and send sanitized normalized schema in `parameters`.
155
157
 
156
158
  ---
157
159
 
@@ -1882,7 +1882,7 @@ function inferStrictPrimitiveTypeFromEnumOrConst(node: Record<string, unknown>):
1882
1882
  * repeated calls (different providers, retries, batching) reuse the same
1883
1883
  * computed pair without re-walking the tree.
1884
1884
  */
1885
- const kStrictSchema = Symbol("pi.schema.strict");
1885
+ const kStrictSchema = Symbol("omp.schema.strict");
1886
1886
 
1887
1887
  /**
1888
1888
  * A boolean schema (`true`/`false`) or the empty object schema `{}`: an
@@ -109,9 +109,9 @@ function arkJsonAstToWire(value: unknown): unknown {
109
109
  }
110
110
 
111
111
  /** `stamp` cache keys; the entries themselves live in a weak side table keyed by schema identity. */
112
- const kJsonWireSchema = Symbol("pi.schema.json.wire");
113
- const kArkWireSchema = Symbol("pi.schema.ark.wire");
114
- const kStrippedSchema = Symbol("pi.schema.descriptions.stripped");
112
+ const kJsonWireSchema = Symbol("omp.schema.json.wire");
113
+ const kArkWireSchema = Symbol("omp.schema.ark.wire");
114
+ const kStrippedSchema = Symbol("omp.schema.descriptions.stripped");
115
115
 
116
116
  function postProcessJsonSchema(schema: Record<string, unknown>): Record<string, unknown> {
117
117
  walk(schema);