@moondeck/station 1.0.6 → 1.0.8

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.
@@ -0,0 +1,103 @@
1
+ /**
2
+ * ADR-168: an AI account's allowed models. One module for the cloud (which
3
+ * stores and checks the list) and the runner (which picks and rotates
4
+ * accounts by it), so the two can never disagree about what "this account
5
+ * allows that model" means. Pure: no runtime imports.
6
+ *
7
+ * Ids are the roster's: what an agent's `model` field holds for its engine
8
+ * kind (`supportedModels` in lib/agent-catalog.ts, mirrored from
9
+ * ./engine-models.ts). Before any comparison both sides go through
10
+ * `canonicalAccountModel`:
11
+ *
12
+ * - every kind: surrounding whitespace is dropped;
13
+ * - `claude`: case-folded, a context suffix (`opus[1m]`) dropped, and a full
14
+ * Claude model id (`claude-sonnet-5-5`, `claude-opus-4-8-20260101`) read as
15
+ * its family alias (`sonnet`, `opus`) — the only ids the Claude roster uses;
16
+ * - `codex`, `grok`: case-folded (their CLIs treat slugs case-insensitively);
17
+ * - any other kind (`cursor`, `kimi`, `opencode`, …): kept verbatim, since
18
+ * their ids are free-form `provider/model` strings.
19
+ *
20
+ * Null (or an empty list) means every model, so an untouched account behaves
21
+ * exactly as before. A limited account runs only the models it lists: an
22
+ * agent with no model set runs on it only when the caller resolves that blank
23
+ * to a concrete default first (the cloud uses the catalog default of a
24
+ * `required` kind; a blank `optional` model is the CLI's own choice, which a
25
+ * limited account cannot vouch for).
26
+ */
27
+
28
+ const CLAUDE_FAMILIES = ["fable", "opus", "sonnet", "haiku"] as const;
29
+ const CASE_FOLDED_KINDS = new Set(["claude", "codex", "grok"]);
30
+
31
+ /** Most models a single account may list. */
32
+ export const MAX_ALLOWED_MODELS = 200;
33
+ /** Longest model id kept. */
34
+ export const MAX_ALLOWED_MODEL_CHARS = 200;
35
+
36
+ /** The id a model is compared by, for one engine kind. */
37
+ export function canonicalAccountModel(kind: string, model: string): string {
38
+ let id = model.trim();
39
+ if (CASE_FOLDED_KINDS.has(kind)) id = id.toLowerCase();
40
+ if (kind !== "claude") return id;
41
+ id = id.replace(/\[[^\]]*\]$/, "");
42
+ const full = /^claude-([a-z]+)(?:-|$)/.exec(id);
43
+ if (full && (CLAUDE_FAMILIES as readonly string[]).includes(full[1]!)) return full[1]!;
44
+ return id;
45
+ }
46
+
47
+ /**
48
+ * The stored form of a list: canonical, de-duplicated, in the order given;
49
+ * null for "every model" (null, undefined or nothing left).
50
+ */
51
+ export function normalizeAllowedModels(
52
+ kind: string,
53
+ models: readonly string[] | null | undefined,
54
+ ): string[] | null {
55
+ if (!models) return null;
56
+ const out: string[] = [];
57
+ for (const model of models) {
58
+ const id = canonicalAccountModel(kind, model);
59
+ if (id && !out.includes(id)) out.push(id);
60
+ }
61
+ return out.length ? out : null;
62
+ }
63
+
64
+ /** Whether an account with this list may run `model` for `kind`. A blank
65
+ * model is allowed only on an account that allows every model. */
66
+ export function accountAllowsModel(
67
+ allowed: readonly string[] | null | undefined,
68
+ kind: string,
69
+ model: string | null | undefined,
70
+ ): boolean {
71
+ if (!allowed || allowed.length === 0) return true;
72
+ const id = model ? canonicalAccountModel(kind, model) : "";
73
+ if (!id) return false;
74
+ return allowed.some((entry) => canonicalAccountModel(kind, entry) === id);
75
+ }
76
+
77
+ /** Parse the stored JSON (`uai_credentials.allowed_models`). Anything
78
+ * unreadable reads as an empty list — no model — never as "every model":
79
+ * a value this code cannot read must fail closed. */
80
+ export function parseAllowedModels(raw: string | null | undefined): string[] | null {
81
+ if (raw === null || raw === undefined || raw === "") return null;
82
+ try {
83
+ const value: unknown = JSON.parse(raw);
84
+ if (value === null) return null;
85
+ if (!Array.isArray(value) || !value.every((m) => typeof m === "string")) return [];
86
+ return value.length ? (value as string[]) : null;
87
+ } catch {
88
+ return [];
89
+ }
90
+ }
91
+
92
+ /** True when a manifest's `allowedModels` value is well-formed. */
93
+ export function isAllowedModelsWire(value: unknown): value is string[] {
94
+ return (
95
+ Array.isArray(value) &&
96
+ value.length > 0 &&
97
+ value.length <= MAX_ALLOWED_MODELS &&
98
+ value.every(
99
+ (m) => typeof m === "string" && m.length > 0 && m.length <= MAX_ALLOWED_MODEL_CHARS,
100
+ ) &&
101
+ new Set(value).size === value.length
102
+ );
103
+ }
package/src/protocol.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { InitialAttachmentWriteInput } from "./initial-attachments";
1
2
  export * from "./custom-connections";
2
3
  export * from "./preview-upstream";
3
4
  import type { PreviewUpstream } from "./preview-upstream";
@@ -53,6 +54,7 @@ export enum HostErrorCode {
53
54
  NoSuchAgent = "no_such_agent",
54
55
  NoSuchPermission = "no_such_permission",
55
56
  HostUnavailable = "host_unavailable",
57
+ InitialAttachmentsUnsupported = "initial_attachments_unsupported",
56
58
  Internal = "internal",
57
59
  PayloadTooLarge = "payload_too_large",
58
60
  }
@@ -4123,6 +4125,9 @@ export function isHostConfigAckFrame(
4123
4125
  */
4124
4126
  export interface HostCapabilities {
4125
4127
  customConnections?: boolean;
4128
+ /** ADR-168: this runner reads a leased account's `allowedModels` and picks
4129
+ * and rotates accounts by the agent's model. */
4130
+ accountModelLimits?: boolean;
4126
4131
  engineConnectCustom?: boolean;
4127
4132
  engineConnectCustomManual?: boolean;
4128
4133
  internalConnections?: boolean;
@@ -4955,6 +4960,7 @@ export interface HostCommands {
4955
4960
  ctx: CommandContext,
4956
4961
  input: TaskProjectStatusInput,
4957
4962
  ): Promise<HostCommandResult<TaskProjectStatusResult>>;
4963
+ initialAttachmentWrite(ctx: CommandContext, input: InitialAttachmentWriteInput): Promise<HostCommandResult<{ exists: boolean } | undefined>>;
4958
4964
  attachmentWrite(
4959
4965
  ctx: CommandContext,
4960
4966
  input: { taskId: string; filename: string; dataBase64: string },