@oxy.so/contracts 4.8.0 → 4.9.1

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 (60) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/accountGraph.js +13 -5
  3. package/dist/cjs/accountSubject.js +189 -0
  4. package/dist/cjs/agency.js +56 -4
  5. package/dist/cjs/agentKeys.js +67 -0
  6. package/dist/cjs/capabilityBindings.js +72 -0
  7. package/dist/cjs/index.js +60 -13
  8. package/dist/cjs/inference/decisions.js +41 -0
  9. package/dist/cjs/inference/economics.js +135 -0
  10. package/dist/cjs/products/access.js +60 -0
  11. package/dist/cjs/products/billing.js +32 -0
  12. package/dist/cjs/signIn.js +1 -1
  13. package/dist/esm/.tsbuildinfo +1 -1
  14. package/dist/esm/accountGraph.js +13 -5
  15. package/dist/esm/accountSubject.js +182 -0
  16. package/dist/esm/agency.js +55 -3
  17. package/dist/esm/agentKeys.js +63 -0
  18. package/dist/esm/capabilityBindings.js +67 -0
  19. package/dist/esm/index.js +10 -1
  20. package/dist/esm/inference/decisions.js +41 -0
  21. package/dist/esm/inference/economics.js +132 -0
  22. package/dist/esm/products/access.js +57 -0
  23. package/dist/esm/products/billing.js +29 -0
  24. package/dist/esm/signIn.js +1 -1
  25. package/dist/types/.tsbuildinfo +1 -1
  26. package/dist/types/accountGraph.d.ts +23 -8
  27. package/dist/types/accountSubject.d.ts +210 -0
  28. package/dist/types/agency.d.ts +956 -190
  29. package/dist/types/agentKeys.d.ts +525 -0
  30. package/dist/types/capabilityBindings.d.ts +6 -0
  31. package/dist/types/deviceDirectory.d.ts +50 -50
  32. package/dist/types/deviceSession.d.ts +14 -14
  33. package/dist/types/externalIdentity.d.ts +4 -4
  34. package/dist/types/identity.d.ts +2 -2
  35. package/dist/types/index.d.ts +12 -2
  36. package/dist/types/inference/accountBilling.d.ts +30 -30
  37. package/dist/types/inference/aliaModelRelease.d.ts +83 -83
  38. package/dist/types/inference/catalogue.d.ts +180 -180
  39. package/dist/types/inference/economics.d.ts +376 -0
  40. package/dist/types/inference/entitlement.d.ts +47 -47
  41. package/dist/types/inference/inbox.d.ts +12 -12
  42. package/dist/types/inference/modelDocumentation.d.ts +231 -231
  43. package/dist/types/inference/priceVersion.d.ts +4 -4
  44. package/dist/types/inference/providerConnection.d.ts +38 -38
  45. package/dist/types/inference/realtime.d.ts +802 -802
  46. package/dist/types/inference/request.d.ts +844 -844
  47. package/dist/types/inference/routingPolicy.d.ts +4 -4
  48. package/dist/types/inference/scopedExecution.d.ts +38 -38
  49. package/dist/types/inference/streamEvents.d.ts +4 -4
  50. package/dist/types/inference/usage.d.ts +12 -12
  51. package/dist/types/keyRotation.d.ts +2 -2
  52. package/dist/types/notifications.d.ts +4 -4
  53. package/dist/types/oauth.d.ts +30 -30
  54. package/dist/types/products/access.d.ts +487 -0
  55. package/dist/types/products/billing.d.ts +563 -0
  56. package/dist/types/recommendations.d.ts +2 -2
  57. package/dist/types/sessionStatus.d.ts +10 -10
  58. package/dist/types/signIn.d.ts +6 -6
  59. package/dist/types/transparency.d.ts +2 -2
  60. package/package.json +1 -1
@@ -10,11 +10,18 @@ import { z } from 'zod';
10
10
  /**
11
11
  * Account-graph classification — the ONE authority for the kind vocabulary.
12
12
  *
13
- * `personal` is the only kind minted by signup and the only one that carries
14
- * its own credentials; every other kind is a child account created under a
15
- * parent and operated through `account_members`. The API schema, the Drizzle
13
+ * `personal` is the only kind minted by signup and the only one that signs in
14
+ * as a device principal; every other kind is a child account created under a
15
+ * parent and reached through `account_members`. The API schema, the Drizzle
16
16
  * table and the SDK all derive from this list rather than restating it, so a
17
17
  * new kind is one edit here instead of four literals that can drift.
18
+ *
19
+ * The kind names what an account IS. It does not, on its own, answer who may
20
+ * switch into it, who may act as it, who the actor is, or anything commercial —
21
+ * each of those has its own predicate or contract, tabulated at the top of
22
+ * `accountSubject.ts`. In particular a `bot` is a COMPLETE account (issue
23
+ * #1520): it owns resources, holds roles, plans and a balance, receives funds
24
+ * and pays for itself under the same rules as a person, and is its own actor.
18
25
  */
19
26
  export type AccountKind = 'personal' | 'organization' | 'project' | 'bot' | 'channel';
20
27
  /**
@@ -65,6 +72,12 @@ export declare const childAccountKindSchema: z.ZodEnum<["organization", "project
65
72
  *
66
73
  * Consumers must gate on this predicate rather than testing `kind === 'personal'`,
67
74
  * which silently admits every kind added after it was written.
75
+ *
76
+ * Being act-as-eligible is NOT being without an identity of one's own. A bot is
77
+ * act-as-eligible AND its own actor (`accountKindActorNature` → `'agent'` in
78
+ * `accountSubject.ts`): an application acting as it on a person's authority
79
+ * records that person as the actor, and the bot acting with nobody operating it
80
+ * records the bot. Neither ever records the bot's owner in the bot's place.
68
81
  */
69
82
  export declare function isDelegatedActAsEligibleKind(kind: AccountKind | null | undefined): boolean;
70
83
  /**
@@ -76,11 +89,13 @@ export declare function isDelegatedActAsEligibleKind(kind: AccountKind | null |
76
89
  * The two differ on exactly one kind, `bot`, and that difference is the whole
77
90
  * reason both exist.
78
91
  *
79
- * **A bot is not something you become. It is something that operates on your
80
- * behalf.** Its whole purpose is to act while nobody is present: an application
81
- * holds a credential, names the human whose authority it borrows, and speaks as
82
- * the bot. That is delegation, and it is what
83
- * {@link isDelegatedActAsEligibleKind} admits it for.
92
+ * **A bot is not something you become. It is somebody of its own.** It is an
93
+ * agent's identity, with its own resources, roles, plan and balance, and it is
94
+ * the actor of what it does unoperated. A person may still act AS it on their
95
+ * own authority — that is delegation, recorded with the person as actor, and it
96
+ * is what {@link isDelegatedActAsEligibleKind} admits it for. What a person
97
+ * never does is occupy its seat. This is a refusal of a SEAT, not a capability
98
+ * restriction: nothing a bot may do depends on this predicate.
84
99
  *
85
100
  * Handing a person the bot's seat instead inverts that. It puts a human inside
86
101
  * the identity that exists to act without one, and it does so on the human's own
@@ -0,0 +1,210 @@
1
+ /**
2
+ * Account subject contract — what an account IS, kept apart from how it proves
3
+ * itself, who may become it, who may act as it, who acted, and whose money moves.
4
+ *
5
+ * `AccountKind` (`accountGraph.ts`) names the nature of an account. Five other
6
+ * questions are routinely asked of an account, and each has its own answer here
7
+ * or in `accountGraph.ts`. None of them may be answered by testing `kind`
8
+ * directly at a call site:
9
+ *
10
+ * | question | answered by |
11
+ * |-------------------------------------------|------------------------------------------|
12
+ * | may a PERSON switch into it? | `isOperatorSwitchTargetKind` |
13
+ * | may someone act AS it on their authority? | `isDelegatedActAsEligibleKind` |
14
+ * | who is the ACTOR when it acts unoperated? | {@link accountKindActorNature} |
15
+ * | who acted, and as whom, on this request? | {@link AccountActorChain} |
16
+ * | whose money / receipt is an effect? | {@link attributeFinancialEffect} |
17
+ * | roles, resources, plan, balance, payer | NOT kind — {@link KIND_INDEPENDENT_ACCOUNT_DIMENSIONS} |
18
+ *
19
+ * ## A bot is a complete account (issue #1520, I01)
20
+ *
21
+ * A `bot` is an AI agent's own identity. It owns resources, holds roles, has a
22
+ * plan, holds a balance, receives funds and pays for itself under exactly the
23
+ * rules a personal account does. Nothing commercial derives from it being a bot,
24
+ * and nothing about it requires its owner's approval merely because it is one.
25
+ *
26
+ * Two things DO differ, and both are about seats, not capability:
27
+ *
28
+ * - a person never switches INTO a bot (`isOperatorSwitchTargetKind`): a bot is
29
+ * somebody, not a seat a human occupies;
30
+ * - when a bot acts with nobody operating it, the actor recorded is the BOT
31
+ * ({@link accountKindActorNature} `'agent'`), never its owner.
32
+ */
33
+ import { z } from 'zod';
34
+ import type { AccountKind } from './accountGraph';
35
+ /** Bumped when any shape in this module changes incompatibly. */
36
+ export declare const ACCOUNT_SUBJECT_CONTRACT_VERSION: 1;
37
+ /**
38
+ * Who is recorded as the ACTOR when an account of this kind acts and no other
39
+ * account is operating it.
40
+ *
41
+ * - `person` — a human; a personal account is its own actor.
42
+ * - `agent` — an AI agent; a bot is its own actor (ADR 0018 `ActorRef`
43
+ * `{type:'agent'}`), and audit records the bot, never the human who owns it.
44
+ * - `operated` — never its own actor. An organization, project or channel only
45
+ * acts through a member, and that member is the actor.
46
+ */
47
+ export declare const ACCOUNT_ACTOR_NATURES: readonly ["person", "agent", "operated"];
48
+ export type AccountActorNature = (typeof ACCOUNT_ACTOR_NATURES)[number];
49
+ export declare const accountActorNatureSchema: z.ZodEnum<["person", "agent", "operated"]>;
50
+ /** `null` for a value that is not an account kind. Never a guess. */
51
+ export declare function accountKindActorNature(kind: AccountKind | null | undefined): AccountActorNature | null;
52
+ /** Whether an account of this kind can be the actor of its own actions. */
53
+ export declare function accountKindActsAsItself(kind: AccountKind | null | undefined): boolean;
54
+ /**
55
+ * What an account's KIND never decides.
56
+ *
57
+ * There is deliberately no predicate taking a kind for any of these. A member's
58
+ * role grants the same permissions whatever kind the member is; a plan, a
59
+ * balance, the payer and the beneficiary are resolved from billing state and
60
+ * membership, never from `kind`. A bot and a person with the same role and plan
61
+ * get the same action and the same commercial treatment.
62
+ *
63
+ * Listed so a consumer can cite the rule, and so the API's static guard
64
+ * (`commercialTreatmentIgnoresAccountKind.test.ts`) has a single source.
65
+ */
66
+ export declare const KIND_INDEPENDENT_ACCOUNT_DIMENSIONS: readonly ["roles", "resources", "plan", "balance", "payer", "beneficiary"];
67
+ export type KindIndependentAccountDimension = (typeof KIND_INDEPENDENT_ACCOUNT_DIMENSIONS)[number];
68
+ /**
69
+ * Who acted, and as whom, for one authenticated request.
70
+ *
71
+ * - `effectiveAccountId` — the account the request speaks AS (token `sub`).
72
+ * - `actorAccountId` — who actually acted (token `act.sub`): the human operating
73
+ * a managed account, or the account itself when nobody operates it.
74
+ * - `delegated` — exactly `actorAccountId !== effectiveAccountId`. Carried as
75
+ * its own field so a consumer reads a fact instead of re-deriving it, and
76
+ * refined so the two can never disagree.
77
+ *
78
+ * Produced ONLY by the session authority (Oxy's `/session/validate*`) from the
79
+ * session ROW. A header or an unverified token claim never produces one: that is
80
+ * what keeps a modified header from changing the actor.
81
+ */
82
+ export declare const accountActorChainSchema: z.ZodEffects<z.ZodObject<{
83
+ schemaVersion: z.ZodLiteral<1>;
84
+ effectiveAccountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
85
+ actorAccountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
86
+ delegated: z.ZodBoolean;
87
+ }, "strict", z.ZodTypeAny, {
88
+ schemaVersion: 1;
89
+ effectiveAccountId: string & z.BRAND<"OxyAccountId">;
90
+ actorAccountId: string & z.BRAND<"OxyAccountId">;
91
+ delegated: boolean;
92
+ }, {
93
+ schemaVersion: 1;
94
+ effectiveAccountId: string;
95
+ actorAccountId: string;
96
+ delegated: boolean;
97
+ }>, {
98
+ schemaVersion: 1;
99
+ effectiveAccountId: string & z.BRAND<"OxyAccountId">;
100
+ actorAccountId: string & z.BRAND<"OxyAccountId">;
101
+ delegated: boolean;
102
+ }, {
103
+ schemaVersion: 1;
104
+ effectiveAccountId: string;
105
+ actorAccountId: string;
106
+ delegated: boolean;
107
+ }>;
108
+ export type AccountActorChain = z.infer<typeof accountActorChainSchema>;
109
+ /**
110
+ * Build the chain from a session's binding: its subject and the operator
111
+ * recorded on it (`sessions.operated_by_user_id`), if any.
112
+ *
113
+ * The one constructor, so producers cannot each invent a rule. An operator equal
114
+ * to the subject is not a delegation.
115
+ */
116
+ export declare function accountActorChainFromSession(binding: {
117
+ readonly subjectAccountId: string;
118
+ readonly operatedByAccountId?: string | null;
119
+ }): AccountActorChain;
120
+ /** `debit` — the subject pays; `credit` — the subject receives. */
121
+ export declare const FINANCIAL_EFFECT_DIRECTIONS: readonly ["debit", "credit"];
122
+ export type FinancialEffectDirection = (typeof FINANCIAL_EFFECT_DIRECTIONS)[number];
123
+ /**
124
+ * Whose money a financial effect is, and who caused it.
125
+ *
126
+ * `subjectAccountId` is the account the effect BELONGS to — the payer of a
127
+ * debit, the beneficiary of a credit — and it is always the EFFECTIVE account of
128
+ * the actor chain. Never the operator: a person paying from the bot they operate
129
+ * spends the bot's money, and the receipt names the bot as payer and the person
130
+ * as actor. Never the owner: a bot paying for itself is recorded as the bot.
131
+ *
132
+ * What this does NOT decide is which balance row FUNDS a debit. That is the
133
+ * billing walk's answer (ADR 0014: the account's own active profile, else its
134
+ * nearest ancestor's) and it is kind-independent; this contract only fixes the
135
+ * subject and the actor the receipt must carry. Moving money is not done here.
136
+ */
137
+ export declare const financialEffectAttributionSchema: z.ZodEffects<z.ZodObject<{
138
+ schemaVersion: z.ZodLiteral<1>;
139
+ direction: z.ZodEnum<["debit", "credit"]>;
140
+ subjectAccountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
141
+ actor: z.ZodEffects<z.ZodObject<{
142
+ schemaVersion: z.ZodLiteral<1>;
143
+ effectiveAccountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
144
+ actorAccountId: z.ZodBranded<z.ZodString, "OxyAccountId">;
145
+ delegated: z.ZodBoolean;
146
+ }, "strict", z.ZodTypeAny, {
147
+ schemaVersion: 1;
148
+ effectiveAccountId: string & z.BRAND<"OxyAccountId">;
149
+ actorAccountId: string & z.BRAND<"OxyAccountId">;
150
+ delegated: boolean;
151
+ }, {
152
+ schemaVersion: 1;
153
+ effectiveAccountId: string;
154
+ actorAccountId: string;
155
+ delegated: boolean;
156
+ }>, {
157
+ schemaVersion: 1;
158
+ effectiveAccountId: string & z.BRAND<"OxyAccountId">;
159
+ actorAccountId: string & z.BRAND<"OxyAccountId">;
160
+ delegated: boolean;
161
+ }, {
162
+ schemaVersion: 1;
163
+ effectiveAccountId: string;
164
+ actorAccountId: string;
165
+ delegated: boolean;
166
+ }>;
167
+ }, "strict", z.ZodTypeAny, {
168
+ schemaVersion: 1;
169
+ direction: "debit" | "credit";
170
+ subjectAccountId: string & z.BRAND<"OxyAccountId">;
171
+ actor: {
172
+ schemaVersion: 1;
173
+ effectiveAccountId: string & z.BRAND<"OxyAccountId">;
174
+ actorAccountId: string & z.BRAND<"OxyAccountId">;
175
+ delegated: boolean;
176
+ };
177
+ }, {
178
+ schemaVersion: 1;
179
+ direction: "debit" | "credit";
180
+ subjectAccountId: string;
181
+ actor: {
182
+ schemaVersion: 1;
183
+ effectiveAccountId: string;
184
+ actorAccountId: string;
185
+ delegated: boolean;
186
+ };
187
+ }>, {
188
+ schemaVersion: 1;
189
+ direction: "debit" | "credit";
190
+ subjectAccountId: string & z.BRAND<"OxyAccountId">;
191
+ actor: {
192
+ schemaVersion: 1;
193
+ effectiveAccountId: string & z.BRAND<"OxyAccountId">;
194
+ actorAccountId: string & z.BRAND<"OxyAccountId">;
195
+ delegated: boolean;
196
+ };
197
+ }, {
198
+ schemaVersion: 1;
199
+ direction: "debit" | "credit";
200
+ subjectAccountId: string;
201
+ actor: {
202
+ schemaVersion: 1;
203
+ effectiveAccountId: string;
204
+ actorAccountId: string;
205
+ delegated: boolean;
206
+ };
207
+ }>;
208
+ export type FinancialEffectAttribution = z.infer<typeof financialEffectAttributionSchema>;
209
+ /** Attribute a payment or a receipt to the subject the actor chain speaks as. */
210
+ export declare function attributeFinancialEffect(direction: FinancialEffectDirection, actor: AccountActorChain): FinancialEffectAttribution;