@hraness/sponge 0.3.2 → 0.3.4
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/dist/src/cli/main.js
CHANGED
|
@@ -8,7 +8,7 @@ import { command, usageOf } from './commands.js';
|
|
|
8
8
|
import { openLibrary } from '../store/index.js';
|
|
9
9
|
import { defaultCapturePins } from '../acquisition/index.js';
|
|
10
10
|
import { failure } from '../acquisition/errors.js';
|
|
11
|
-
import { SpongeError, codeOf, publicCode, exitFor, hints, debugChain } from '../errors.js';
|
|
11
|
+
import { SpongeError, codeOf, publicCode, exitFor, hints, detailHints, debugChain, } from '../errors.js';
|
|
12
12
|
/** Failures print one categorical JSON line: the public code, its specific `reason` when narrower, and a fixed hint.
|
|
13
13
|
* Causes, details, paths and upstream messages appear only with --debug or SPONGE_DEBUG=1. */
|
|
14
14
|
function report(error, requestId, debug) {
|
|
@@ -17,7 +17,7 @@ function report(error, requestId, debug) {
|
|
|
17
17
|
process.stderr.write(JSON.stringify({ issues }) + '\n');
|
|
18
18
|
const hint = code === 'invalid-input' && typeof usage === 'string' && command(usage)
|
|
19
19
|
? `Usage: ${usageOf(usage).replace(/\n/g, ' | ')}`
|
|
20
|
-
: hints[code];
|
|
20
|
+
: (detailHints[reason] ?? hints[code]);
|
|
21
21
|
process.stderr.write(JSON.stringify({ ...failure(requestId, code), ...(reason !== code ? { reason } : {}), hint }) + '\n');
|
|
22
22
|
if (debug)
|
|
23
23
|
process.stderr.write(debugChain(error));
|
|
@@ -116,7 +116,7 @@ async function complete(origin, request, model, messages, schema, o) {
|
|
|
116
116
|
});
|
|
117
117
|
if (!response.ok) {
|
|
118
118
|
await response.body?.cancel().catch(() => undefined);
|
|
119
|
-
throw new SpongeError('unavailable');
|
|
119
|
+
throw new SpongeError('model-unavailable', { detail: { status: response.status } });
|
|
120
120
|
}
|
|
121
121
|
let parsed;
|
|
122
122
|
try {
|
|
@@ -125,14 +125,14 @@ async function complete(origin, request, model, messages, schema, o) {
|
|
|
125
125
|
catch (error) {
|
|
126
126
|
if (error instanceof SpongeError)
|
|
127
127
|
throw error;
|
|
128
|
-
throw new SpongeError('unavailable');
|
|
128
|
+
throw new SpongeError('model-unavailable');
|
|
129
129
|
}
|
|
130
130
|
const choice = parsed?.choices?.[0];
|
|
131
131
|
if (choice?.finish_reason === 'length')
|
|
132
132
|
throw new SpongeError('limit-exceeded');
|
|
133
133
|
const content = choice?.message?.content;
|
|
134
134
|
if (typeof content !== 'string' || !content.trim())
|
|
135
|
-
throw new SpongeError('unavailable');
|
|
135
|
+
throw new SpongeError('model-unavailable');
|
|
136
136
|
if (Buffer.byteLength(content) > o.maxOutputBytes)
|
|
137
137
|
throw new SpongeError('limit-exceeded');
|
|
138
138
|
return content;
|
|
@@ -486,7 +486,7 @@ export async function draftDigest(input) {
|
|
|
486
486
|
throw new SpongeError('limit-exceeded');
|
|
487
487
|
if (error instanceof SpongeError)
|
|
488
488
|
throw error;
|
|
489
|
-
throw new SpongeError('unavailable');
|
|
489
|
+
throw new SpongeError('model-unavailable', { cause: error });
|
|
490
490
|
}
|
|
491
491
|
if (userSignal.aborted)
|
|
492
492
|
throw new SpongeError('cancelled');
|
|
@@ -610,7 +610,7 @@ export async function draftDigest(input) {
|
|
|
610
610
|
result = await attempt(await call([...messages, { role: 'assistant', content: first }, { role: 'user', content: repairPrompt(result.issues) }], schema));
|
|
611
611
|
}
|
|
612
612
|
if (!result.draft)
|
|
613
|
-
throw new SpongeError('
|
|
613
|
+
throw new SpongeError('draft-rejected', { issues: result.issues });
|
|
614
614
|
let issues = result.issues;
|
|
615
615
|
if (issues.length) {
|
|
616
616
|
trace.dropped = prune(result.draft, issues, source, options);
|
|
@@ -618,7 +618,7 @@ export async function draftDigest(input) {
|
|
|
618
618
|
if (result.draft.digest.ideas.length < L.minIdeas)
|
|
619
619
|
issues = [...issues.filter((i) => !(i.path === 'ideas' && i.code === 'count')), { path: 'ideas', code: 'count' }];
|
|
620
620
|
if (issues.length)
|
|
621
|
-
throw new SpongeError('
|
|
621
|
+
throw new SpongeError('draft-rejected', { issues });
|
|
622
622
|
}
|
|
623
623
|
const producer = {
|
|
624
624
|
pipeline: 'sponge-digest',
|
package/dist/src/errors.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ declare const parents: {
|
|
|
16
16
|
readonly 'not-digest': "unsupported";
|
|
17
17
|
readonly malformed: "invalid-input";
|
|
18
18
|
readonly 'no-capture': "invalid-input";
|
|
19
|
+
readonly 'draft-rejected': "unavailable";
|
|
20
|
+
readonly 'model-unavailable': "unavailable";
|
|
19
21
|
readonly 'parent-missing': "invalid-input";
|
|
20
22
|
readonly 'target-exists': "invalid-input";
|
|
21
23
|
};
|
|
@@ -27,6 +29,8 @@ export declare const isSpongeCode: (value: unknown) => value is SpongeCode;
|
|
|
27
29
|
export declare const exitStatus: Readonly<Record<ErrorCode, number>>;
|
|
28
30
|
/** The one code→user-facing hint table. Fixed text only: never paths, sources, credentials or upstream prose. */
|
|
29
31
|
export declare const hints: Readonly<Record<ErrorCode, string>>;
|
|
32
|
+
/** Hints for detail codes whose public code's hint would mislead. Fixed text only, like `hints`. */
|
|
33
|
+
export declare const detailHints: Readonly<Partial<Record<DetailCode, string>>>;
|
|
30
34
|
export interface SpongeErrorOptions {
|
|
31
35
|
detail?: Record<string, unknown>;
|
|
32
36
|
cause?: unknown;
|
package/dist/src/errors.js
CHANGED
|
@@ -30,6 +30,8 @@ const parents = {
|
|
|
30
30
|
'not-digest': 'unsupported',
|
|
31
31
|
malformed: 'invalid-input',
|
|
32
32
|
'no-capture': 'invalid-input',
|
|
33
|
+
'draft-rejected': 'unavailable',
|
|
34
|
+
'model-unavailable': 'unavailable',
|
|
33
35
|
'parent-missing': 'invalid-input',
|
|
34
36
|
'target-exists': 'invalid-input',
|
|
35
37
|
};
|
|
@@ -77,6 +79,11 @@ export const hints = {
|
|
|
77
79
|
'schema-newer': 'This library was written by a newer Sponge. Upgrade Sponge.',
|
|
78
80
|
'owner-busy': 'Another Sponge process owns the library. Wait for it, or run `sponge queue recover` after it stops.',
|
|
79
81
|
};
|
|
82
|
+
/** Hints for detail codes whose public code's hint would mislead. Fixed text only, like `hints`. */
|
|
83
|
+
export const detailHints = {
|
|
84
|
+
'draft-rejected': 'The model draft failed the digest checks listed above, even after one repair. Drafting is deterministic, so the same capture and model fail again; refresh the item or use another model.',
|
|
85
|
+
'model-unavailable': 'The model server did not answer or returned an error. Check that it is still running and has free GPU memory (another loaded model can exhaust it), then retry.',
|
|
86
|
+
};
|
|
80
87
|
/** The one error type. `message` is the code, so bare `String(error)` never carries detail, paths or causes. */
|
|
81
88
|
export class SpongeError extends Error {
|
|
82
89
|
code;
|
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
}
|
|
28
28
|
],
|
|
29
29
|
"build": {
|
|
30
|
-
"asrSourceSha256": "
|
|
30
|
+
"asrSourceSha256": "ca98fb111b0d2b26ca697a6c0d55d76f7d2b5b752bff8fc053ae19389d16a52c",
|
|
31
31
|
"clangVersion": "Apple clang version 21.0.0 (clang-2100.1.1.101)",
|
|
32
|
-
"embeddingSourceSha256": "
|
|
32
|
+
"embeddingSourceSha256": "af6d6c01934d64427f2a9cb36f83edaea372f6bf2e522166b9e86e3b15f72784",
|
|
33
33
|
"swiftVersion": "Apple Swift version 6.3.3 (swiftlang-6.3.3.1.3 clang-2100.1.1.101)"
|
|
34
34
|
},
|
|
35
35
|
"minimumMacOS": "26.0",
|
|
36
|
-
"packageVersion": "0.3.
|
|
36
|
+
"packageVersion": "0.3.4",
|
|
37
37
|
"platform": "darwin",
|
|
38
38
|
"schemaVersion": 1,
|
|
39
|
-
"sourceCommit": "
|
|
39
|
+
"sourceCommit": "4e42216e86da07224ec81512c2efa0a710e38500"
|
|
40
40
|
}
|