@supa-media/tex-contract 0.3.1 → 0.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.
- package/README.md +9 -17
- package/package.json +1 -1
- package/texContract/staffData.cjs +56 -0
- package/texContract/staffData.d.cts +72 -0
package/README.md
CHANGED
|
@@ -9,33 +9,25 @@ It is plain CommonJS with no dependencies, and it holds no secrets and no vault
|
|
|
9
9
|
|
|
10
10
|
## What 0.3.0 replaces
|
|
11
11
|
|
|
12
|
-
Since 0.3.0 the contract holds everything Context
|
|
13
|
-
|
|
14
|
-
| Was | Now |
|
|
15
|
-
| --- | --- |
|
|
16
|
-
| `packages/tex/src/texNumber.cjs` (`TEX_NUMBER`, `formatNumber`) | `texContract/texNumber.cjs`: `formatNumber`, and `readTexNumber(env.TEX_NUMBER)`; the number is each deployment's `TEX_NUMBER` setting, so this public repository holds no real line |
|
|
17
|
-
| `packages/tex/src/aiKeys.cjs` | `texShared/models/aiKeys.cjs` (it already re-exported it) |
|
|
18
|
-
| `packages/tex/src/texSteps.cjs` (`TEX_STEPS`, `texStepForModel`) | `texContract/texSteps.cjs`, from `texSteps.generated.json` |
|
|
19
|
-
| `packages/tex/src/texSettings.cjs` | `texContract/texSettings.cjs`, from `texSettings.generated.json`: the rows as data (key, section, where, byText, via, appPath), without their titles and lines |
|
|
20
|
-
| `packages/tex/src/toolRules.cjs` `TEX_STATE_FILES`, `stateFileOf` | `texContract/texStateFiles.cjs` (file and action) |
|
|
21
|
-
| `packages/tex/src/textDecide.cjs` `REACT_EMOJI` | `texContract/reactEmoji.cjs`: name to `{ emoji }`, without when each fits |
|
|
22
|
-
| `packages/tex/gateway/agent/capabilities.js` (the agent-first rule's list) | `texContract/capabilities.cjs`, from `capabilities.generated.json`: names, actions, app routes and can'ts, without the words Tex is told |
|
|
12
|
+
Since 0.3.0 the contract holds everything Context needs from Tex's source, so no Context file imports Tex's code (the clean split, 2026-11-29). In Context, import from `packages/shared/src/texContract/` (`@context/shared/src/texContract/...`); in Tex, from `@supa-media/tex-contract/texContract/...`.
|
|
23
13
|
|
|
24
14
|
Since 0.3.1:
|
|
25
15
|
|
|
26
|
-
- `texShared/searchConfig.cjs` (with its `.json` and types) is a copy of `apps/mcp/src/search/config/searchConfig.cjs
|
|
16
|
+
- `texShared/searchConfig.cjs` (with its `.json` and types) is a copy of `apps/mcp/src/search/config/searchConfig.cjs`.
|
|
27
17
|
- `texShared/displayText.cjs` is a copy of `packages/shared/src/displayText.cjs`.
|
|
28
18
|
- `parity.test.mjs` keeps both copies equal to their sources, so a search config change in Context bumps the contract.
|
|
29
|
-
- `texShared/githubOidc.ts` lets each OIDC door take its workflow from
|
|
19
|
+
- `texShared/githubOidc.ts` lets each OIDC door take its workflow from Tex's repository's main as well as Context's. It still refuses a token whose repository and workflow disagree (`githubOidc.test.mjs`).
|
|
30
20
|
|
|
31
|
-
|
|
21
|
+
Since 0.4.0:
|
|
32
22
|
|
|
33
|
-
|
|
23
|
+
- `texContract/staffData.cjs` (with its types) holds the calls Context's staff console and Settings → Feedback make of Tex's Worker, through the gateway: `STAFF_DATA_PATH` (`stats`, `spend`, `review_scores`, on the person's own control-plane sign-in, which Tex checks is staff) and `FEEDBACK_SHARING_PATH` (on the console's grant). Tex's figures and each person's sharing yes are Tex's data and leave Context's control plane.
|
|
34
24
|
|
|
35
|
-
The
|
|
25
|
+
The contract carries facts, never Tex's wording, and Tex's titles, lines and judge questions stay in Tex.
|
|
26
|
+
|
|
27
|
+
The snapshots are written by `node scripts/tex-contract/snapshot.mjs [--tex <Tex checkout>]`, and `--check` fails when they are stale. When Tex adds a model step or changes what a person can get it to do, it runs the snapshot against its checkout and a Context pull request bumps the contract.
|
|
36
28
|
|
|
37
29
|
## How each side reads it
|
|
38
30
|
|
|
39
|
-
Context's gateway imports the same files from its own source (`packages/shared/src/`). Tex pins a version of this package. A contract change keeps working with the previous release, and Tex bumps the version when it is ready.
|
|
31
|
+
Context's gateway imports the same files from its own source (`packages/shared/src/`). Tex pins a version of this package. A contract change keeps working with the previous release, and Tex bumps the version when it is ready.
|
|
40
32
|
|
|
41
33
|
MIT licensed.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@supa-media/tex-contract",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "The contract Context's gateway and Tex both keep: tool names, the MCP catalog snapshot, wire formats and the shared readings Tex takes with it",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TEX'S STAFF FIGURES AND THE FEEDBACK SWITCH, ASKED OF TEX'S OWN WORKER (the Tex/Context split, 2026-11-30).
|
|
3
|
+
*
|
|
4
|
+
* Tex's figures (texts in and out, people and chats, notes made, spend, conversation scores) and each person's yes to
|
|
5
|
+
* sharing their finished conversations with the team used to be answered by Context's control plane. They are Tex's
|
|
6
|
+
* data, so Tex's Worker answers them, and Context's staff console and Settings → Feedback ask it through the gateway,
|
|
7
|
+
* which hands each call to Tex over its `TEXTING` binding:
|
|
8
|
+
*
|
|
9
|
+
* - `POST STAFF_DATA_PATH` `{ op, ...args }`, the bearer the person's own control-plane sign-in token (the console's
|
|
10
|
+
* session token). The gateway passes the token on untouched and decides nothing; Tex's Worker asks the control
|
|
11
|
+
* plane whether that sign-in is staff (`functions/admin:amIAdmin`, a public query, answered for its caller alone)
|
|
12
|
+
* and answers only when it is. Ops: `stats` `{ from?, to? }`, `spend` `{ days? }`, `review_scores` `{ days? }`.
|
|
13
|
+
* - `POST FEEDBACK_SHARING_PATH` `{ share? }` on the console's own grant (`context_console`, a personal workspace's
|
|
14
|
+
* owner). The gateway hands Tex the grant's person and nothing from the body but `share`; absent only asks.
|
|
15
|
+
*
|
|
16
|
+
* Answers are `{ status: "ok", data }`, `{ status: "refused" }` (not staff, or not the console's own grant) or
|
|
17
|
+
* `{ status: "unavailable" }` (Tex's Worker unreachable). Facts and numbers only, never a person, a chat or a word.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const STAFF_DATA_PATH = "/tex/staff-data";
|
|
21
|
+
const FEEDBACK_SHARING_PATH = "/tex/feedback-sharing";
|
|
22
|
+
const STAFF_DATA_OPS = Object.freeze(["stats", "spend", "review_scores"]);
|
|
23
|
+
/** The longest bearer passed on; a control-plane sign-in token is far shorter. */
|
|
24
|
+
const MAX_TOKEN_CHARS = 4096;
|
|
25
|
+
|
|
26
|
+
const finiteOrUndefined = (value) => (typeof value === "number" && Number.isFinite(value) ? value : undefined);
|
|
27
|
+
|
|
28
|
+
/** A staff call read strictly: `{ op, from?, to?, days? }` with only the fields its op takes, or null. */
|
|
29
|
+
function staffDataRequest(body) {
|
|
30
|
+
if (body === null || typeof body !== "object" || Array.isArray(body)) return null;
|
|
31
|
+
const op = body.op;
|
|
32
|
+
if (!STAFF_DATA_OPS.includes(op)) return null;
|
|
33
|
+
if (op === "stats") {
|
|
34
|
+
const from = finiteOrUndefined(body.from);
|
|
35
|
+
const to = finiteOrUndefined(body.to);
|
|
36
|
+
return { op, ...(from === undefined ? {} : { from }), ...(to === undefined ? {} : { to }) };
|
|
37
|
+
}
|
|
38
|
+
const days = finiteOrUndefined(body.days);
|
|
39
|
+
return { op, ...(days === undefined ? {} : { days }) };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The Feedback switch's call: `{ share? }`, or null for anything else. */
|
|
43
|
+
function sharingRequest(body) {
|
|
44
|
+
if (body === null || typeof body !== "object" || Array.isArray(body)) return null;
|
|
45
|
+
if (body.share === undefined) return {};
|
|
46
|
+
return typeof body.share === "boolean" ? { share: body.share } : null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The bearer of an `Authorization` header, when it is one plausible token; otherwise null. */
|
|
50
|
+
function bearerOf(header) {
|
|
51
|
+
if (typeof header !== "string") return null;
|
|
52
|
+
const match = /^Bearer ([A-Za-z0-9._~+/=-]+)$/.exec(header.trim());
|
|
53
|
+
return match !== null && match[1].length <= MAX_TOKEN_CHARS ? match[1] : null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = { STAFF_DATA_PATH, FEEDBACK_SHARING_PATH, STAFF_DATA_OPS, MAX_TOKEN_CHARS, staffDataRequest, sharingRequest, bearerOf };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/** Types for `staffData.cjs`; see that file for the reasons. The answer shapes are Tex's Worker's (`worker/stats`). */
|
|
2
|
+
|
|
3
|
+
export declare const STAFF_DATA_PATH: "/tex/staff-data";
|
|
4
|
+
export declare const FEEDBACK_SHARING_PATH: "/tex/feedback-sharing";
|
|
5
|
+
export declare const STAFF_DATA_OPS: readonly ["stats", "spend", "review_scores"];
|
|
6
|
+
export declare const MAX_TOKEN_CHARS: number;
|
|
7
|
+
|
|
8
|
+
export type StaffDataOp = (typeof STAFF_DATA_OPS)[number];
|
|
9
|
+
export type StaffDataRequest = { op: "stats"; from?: number; to?: number } | { op: "spend"; days?: number } | { op: "review_scores"; days?: number };
|
|
10
|
+
export declare function staffDataRequest(body: unknown): StaffDataRequest | null;
|
|
11
|
+
export declare function sharingRequest(body: unknown): { share?: boolean } | null;
|
|
12
|
+
export declare function bearerOf(header: unknown): string | null;
|
|
13
|
+
|
|
14
|
+
export type TexDataAnswer<T> = { status: "ok"; data: T } | { status: "refused" } | { status: "unavailable" };
|
|
15
|
+
|
|
16
|
+
export type TexStatsPoint = { at: number; people: number; textsIn: number; textsOut: number; usd: number; notesCreated: number; notesEdited: number };
|
|
17
|
+
|
|
18
|
+
/** `op: "stats"`: the staff console's basics for a window. */
|
|
19
|
+
export type TexStats =
|
|
20
|
+
| { configured: false }
|
|
21
|
+
| {
|
|
22
|
+
configured: true;
|
|
23
|
+
from: number;
|
|
24
|
+
to: number;
|
|
25
|
+
bucket: "hour" | "day";
|
|
26
|
+
errors: { texts: string | null; notes: string | null; cost: string | null };
|
|
27
|
+
people: { one: number; group: number; any: number };
|
|
28
|
+
dailyActive: number;
|
|
29
|
+
texts: { inOne: number; inGroup: number; heardGroup: number; outOne: number; outGroup: number };
|
|
30
|
+
chats?: { one: number; group: number; groupAsked: number; groupHeardOnly: number; any: number; countedSince: number };
|
|
31
|
+
notes: { created: number; edited: number; saves: number };
|
|
32
|
+
cost: { totalUsd: number; testsUsd: number };
|
|
33
|
+
costPerTextUsd: number | null;
|
|
34
|
+
countedSince: number;
|
|
35
|
+
series: TexStatsPoint[];
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** `op: "spend"`: Tex's spend by day, model and job, as Cloudflare's AI gateway priced it. */
|
|
39
|
+
export type TexSpend =
|
|
40
|
+
| { configured: false }
|
|
41
|
+
| {
|
|
42
|
+
configured: true;
|
|
43
|
+
error: string | null;
|
|
44
|
+
totalUsd: number;
|
|
45
|
+
testsUsd: number;
|
|
46
|
+
keptFrom: string;
|
|
47
|
+
days: Array<{ day: string; usd: number; requests: number }>;
|
|
48
|
+
models: Array<{ model: string; requests: number; usd: number; freshInputTokens: number; cacheReadTokens: number; cacheWriteTokens: number; outputTokens: number }>;
|
|
49
|
+
jobs: Array<{ job: string; usd: number; requests: number }>;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/** One finished conversation's scores (`op: "review_scores"`), naming nobody. */
|
|
53
|
+
export type TexReviewScore = {
|
|
54
|
+
at: number;
|
|
55
|
+
kind: "one" | "group";
|
|
56
|
+
reason: string;
|
|
57
|
+
goal: number;
|
|
58
|
+
independence: number;
|
|
59
|
+
turns: number;
|
|
60
|
+
friendly: number;
|
|
61
|
+
calm: number;
|
|
62
|
+
task: string | null;
|
|
63
|
+
signals: string[];
|
|
64
|
+
texts: number | null;
|
|
65
|
+
who: "staff" | "new" | "other" | null;
|
|
66
|
+
costMicroUsd: number | null;
|
|
67
|
+
thought: boolean | null;
|
|
68
|
+
};
|
|
69
|
+
export type TexReviewScores = { truncated: boolean; reviews: TexReviewScore[] };
|
|
70
|
+
|
|
71
|
+
/** The Feedback switch's answer: whether the person shares, and whether this call changed it. */
|
|
72
|
+
export type FeedbackSharing = { sharing: boolean; changed: boolean };
|