@gobing-ai/ts-decision-fm 0.8.0 → 0.8.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"fm-process.d.ts","sourceRoot":"","sources":["../src/fm-process.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AASH,OAAO,KAAK,EAAE,eAAe,EAAiB,MAAM,uBAAuB,CAAC;AAE5E,6EAA6E;AAC7E,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,oCAAoC,CAAC;AAE5E;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAE9E;AAED,mJAAmJ;AACnJ,wBAAgB,WAAW,CAAC,OAAO,EAAE;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,sDAAsD;IACtD,UAAU,CAAC,EAAE,YAAY,CAAC;CAC7B,GAAG,MAAM,EAAE,CAYX;AAED,kFAAkF;AAClF,wBAAgB,aAAa,IAAI,MAAM,EAAE,CAExC;AAaD;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CACrC,QAAQ,EAAE,eAAe,EACzB,MAAM,EAAE,MAAM,EACd,SAAS,SAAS,GACnB,OAAO,CAAC,IAAI,CAAC,CAWf;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACnC,QAAQ,EAAE,eAAe,EACzB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,SAAS,SAAS,GACnB,OAAO,CAAC,MAAM,CAAC,CA0BjB;AAMD;;;;GAIG;AACH,wBAAsB,YAAY,CAC9B,QAAQ,EAAE,eAAe,EACzB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,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EAAE,eAAe,EACzB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,SAAS,SAAS,GACnB,OAAO,CAAC,MAAM,CAAC,CA2BjB;AAuBD;;;;GAIG;AACH,wBAAsB,YAAY,CAC9B,QAAQ,EAAE,eAAe,EACzB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EAAE,EACd,gBAAgB,EAAE,MAAM,GACzB,OAAO,CAAC,MAAM,CAAC,CAyBjB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAoBrE;AAED,4FAA4F;AAC5F,wBAAgB,gBAAgB,CAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC9B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,KAAK,SAAO,GACb,MAAM,CAER"}
@@ -81,6 +81,7 @@ export async function countPromptTokens(executor, fmPath, instructions, prompt,
81
81
  throw new DecisionConfigError(`fm not found: '${fmPath}' could not be spawned`, 'fmPath');
82
82
  }
83
83
  if (result.exitCode !== 0) {
84
+ throwIfModelServiceDenied(fmText(result));
84
85
  throw new DecisionBackendError(`fm count-tokens failed (exit ${result.exitCode}): ${fmText(result)}`, undefined);
85
86
  }
86
87
  const tokens = Number.parseInt(result.stdout.trim(), 10);
@@ -92,6 +93,19 @@ export async function countPromptTokens(executor, fmPath, instructions, prompt,
92
93
  /** Stable substrings of fm's failure text (design § Errors discrimination). */
93
94
  const CONTEXT_SIZE_MARKER = "exceeded the model's context size";
94
95
  const GUARDRAILS_MARKER = 'safety guardrails were triggered';
96
+ /**
97
+ * modelmanagerd refuses the caller outright (observed ~60–150 ms, no inference)
98
+ * when fm runs inside a restricted context such as a coding agent's Seatbelt
99
+ * sandbox, while `fm available --model system` still exits 0. It is an
100
+ * environment fault, so it maps to `DecisionConfigError` (hub reason
101
+ * `no-backend`, which a maker chain advances past) instead of a backend error.
102
+ */
103
+ const MODEL_SERVICE_DENIED_MARKER = 'ModelManagerError error 1008';
104
+ function throwIfModelServiceDenied(text) {
105
+ if (text.includes(MODEL_SERVICE_DENIED_MARKER)) {
106
+ throw new DecisionConfigError(`fm cannot reach the on-device model service (is the caller running inside a sandbox?): ${text}`, 'fm-model-service');
107
+ }
108
+ }
95
109
  /**
96
110
  * One `fm respond` sample: run with the per-sample timeout, map every failure
97
111
  * row of the error table, return stdout on success (parsing happens in
@@ -108,6 +122,7 @@ export async function runFmRespond(executor, fmPath, args, requestTimeoutMs) {
108
122
  }
109
123
  if (result.exitCode !== 0) {
110
124
  const text = fmText(result);
125
+ throwIfModelServiceDenied(text);
111
126
  if (text.includes(CONTEXT_SIZE_MARKER)) {
112
127
  throw new DecisionRequestError(`fm prompt exceeded the model context size: ${text}`, undefined, undefined);
113
128
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gobing-ai/ts-decision-fm",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "@gobing-ai/ts-decision-fm — Apple on-device Foundation Model decision backend driving the macOS `fm` CLI over a one-shot process bridge.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -51,8 +51,8 @@
51
51
  "release": "echo 'Manual publish is disabled. Releases go through GitHub Actions via Trusted Publishing — push a tag: git tag @gobing-ai/ts-decision-fm-v<version> && git push --tags' && exit 1"
52
52
  },
53
53
  "dependencies": {
54
- "@gobing-ai/ts-ai-runner": "^0.8.0",
55
- "@gobing-ai/ts-runtime": "^0.8.0"
54
+ "@gobing-ai/ts-ai-runner": "^0.8.2",
55
+ "@gobing-ai/ts-runtime": "^0.8.2"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/bun": "1.4.3"
package/src/fm-process.ts CHANGED
@@ -117,6 +117,7 @@ export async function countPromptTokens(
117
117
  throw new DecisionConfigError(`fm not found: '${fmPath}' could not be spawned`, 'fmPath');
118
118
  }
119
119
  if (result.exitCode !== 0) {
120
+ throwIfModelServiceDenied(fmText(result));
120
121
  throw new DecisionBackendError(
121
122
  `fm count-tokens failed (exit ${result.exitCode}): ${fmText(result)}`,
122
123
  undefined,
@@ -135,6 +136,23 @@ export async function countPromptTokens(
135
136
  /** Stable substrings of fm's failure text (design § Errors discrimination). */
136
137
  const CONTEXT_SIZE_MARKER = "exceeded the model's context size";
137
138
  const GUARDRAILS_MARKER = 'safety guardrails were triggered';
139
+ /**
140
+ * modelmanagerd refuses the caller outright (observed ~60–150 ms, no inference)
141
+ * when fm runs inside a restricted context such as a coding agent's Seatbelt
142
+ * sandbox, while `fm available --model system` still exits 0. It is an
143
+ * environment fault, so it maps to `DecisionConfigError` (hub reason
144
+ * `no-backend`, which a maker chain advances past) instead of a backend error.
145
+ */
146
+ const MODEL_SERVICE_DENIED_MARKER = 'ModelManagerError error 1008';
147
+
148
+ function throwIfModelServiceDenied(text: string): void {
149
+ if (text.includes(MODEL_SERVICE_DENIED_MARKER)) {
150
+ throw new DecisionConfigError(
151
+ `fm cannot reach the on-device model service (is the caller running inside a sandbox?): ${text}`,
152
+ 'fm-model-service',
153
+ );
154
+ }
155
+ }
138
156
 
139
157
  /**
140
158
  * One `fm respond` sample: run with the per-sample timeout, map every failure
@@ -160,6 +178,7 @@ export async function runFmRespond(
160
178
  }
161
179
  if (result.exitCode !== 0) {
162
180
  const text = fmText(result);
181
+ throwIfModelServiceDenied(text);
163
182
  if (text.includes(CONTEXT_SIZE_MARKER)) {
164
183
  throw new DecisionRequestError(`fm prompt exceeded the model context size: ${text}`, undefined, undefined);
165
184
  }