@intutic/clawde 2.2.0 → 2.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 +5 -3
- package/dist/client.d.ts +26 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +104 -15
- package/dist/client.js.map +1 -1
- package/dist/control-plane.d.ts +314 -13
- package/dist/control-plane.d.ts.map +1 -1
- package/dist/control-plane.js +665 -20
- package/dist/control-plane.js.map +1 -1
- package/dist/errors.d.ts +13 -3
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +15 -3
- package/dist/errors.js.map +1 -1
- package/dist/evidence.d.ts +22 -0
- package/dist/evidence.d.ts.map +1 -0
- package/dist/evidence.js +114 -0
- package/dist/evidence.js.map +1 -0
- package/dist/git-context.d.ts +27 -0
- package/dist/git-context.d.ts.map +1 -0
- package/dist/git-context.js +114 -0
- package/dist/git-context.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -1
- package/dist/index.js.map +1 -1
- package/dist/integrity.d.ts +23 -0
- package/dist/integrity.d.ts.map +1 -0
- package/dist/integrity.js +89 -0
- package/dist/integrity.js.map +1 -0
- package/dist/refusals.d.ts +39 -15
- package/dist/refusals.d.ts.map +1 -1
- package/dist/refusals.js +69 -16
- package/dist/refusals.js.map +1 -1
- package/dist/toon.d.ts +22 -0
- package/dist/toon.d.ts.map +1 -0
- package/dist/toon.js +115 -0
- package/dist/toon.js.map +1 -0
- package/dist/types.d.ts +1182 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/upstream.d.ts +8 -0
- package/dist/upstream.d.ts.map +1 -0
- package/dist/upstream.js +17 -0
- package/dist/upstream.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integrity.js","sourceRoot":"","sources":["../src/integrity.ts"],"names":[],"mappings":";;AAsCA,sDAeC;AAeD,kDAmBC;AAvFD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A;IAC9D,IAAI,CAAC,IAAI;QAAE,OAAO,kBAAkB,CAAA;IACpC,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,cAAc,CAAC,CAAA;IACnE,IAAI,CAAC,GAAG;QAAE,OAAO,cAAc,CAAA;IAC/B,IAAI,IAAI,CAAC,aAAa,KAAK,OAAO;QAAE,OAAO,cAAc,CAAA;IACzD,IAAI,WAAW,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,KAAK,SAAS;QAAE,OAAO,cAAc,CAAA;IAC7E,IAAI,CAAC;QACH,MAAM,EAAE,GAAG,IAAA,eAAY,EACrB,IAAI,EACJ,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,EAChD,IAAA,wBAAe,EAAC,EAAE,GAAG,EAAE,GAAiB,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAC1D,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CACtC,CAAA;QACD,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAA;IACjC,CAAC;IAAC,MAAM,CAAC;QACP,8EAA8E;QAC9E,OAAO,cAAc,CAAA;IACvB,CAAC;AACH,CAAC"}
|
package/dist/refusals.d.ts
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import type { RefusalVerdict } from './types';
|
|
2
2
|
/**
|
|
3
|
-
* The proxy's governance refusals
|
|
4
|
-
*
|
|
5
|
-
* the status it always pairs that type with, and the verdict it represents.
|
|
3
|
+
* The proxy's governance refusals, by code, with the status the proxy sends
|
|
4
|
+
* each with and the verdict it represents.
|
|
6
5
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* Most arrive as an error: the code is the `error.type` of the proxy's JSON
|
|
7
|
+
* error body (`{"error": {"type", "message"}}`, `json_error` in
|
|
8
|
+
* packages/proxy/src/proxy.rs). Matching on the status and the code together
|
|
9
|
+
* matters because the same statuses also carry errors that are not decisions:
|
|
10
|
+
* a provider's own 429 rate limit, a 403 for a key used against the wrong
|
|
11
|
+
* workspace, a 400 for a malformed body. Those are not refusals and must not
|
|
12
|
+
* be reported as one.
|
|
11
13
|
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
14
|
+
* The rest (status 200, and `COST_GATE_EXCEEDED` on a non-streaming request)
|
|
15
|
+
* arrive in band: an assistant turn explaining the refusal, named by
|
|
16
|
+
* `REFUSAL_HEADER`, or on a stream by the `STREAM_REFUSAL_MARKER` comment line.
|
|
17
|
+
*
|
|
18
|
+
* `__tests__/refusals.test.ts` holds this table to
|
|
19
|
+
* packages/shared-types/fixtures/refusal-codes.json, the one list the proxy
|
|
20
|
+
* and the Python SDK are held to as well, so a refusal the proxy adds or
|
|
21
|
+
* renames fails the build instead of silently turning back into an `allow` or
|
|
22
|
+
* a retried connection error.
|
|
15
23
|
*/
|
|
16
24
|
export declare const PROXY_REFUSALS: Readonly<Record<string, {
|
|
17
25
|
status: number;
|
|
@@ -21,16 +29,32 @@ export interface ProxyRefusal {
|
|
|
21
29
|
verdict: RefusalVerdict;
|
|
22
30
|
code: string;
|
|
23
31
|
message: string;
|
|
32
|
+
/** The rule that decided, for a refusal the proxy answered in band. */
|
|
33
|
+
ruleId?: string;
|
|
24
34
|
}
|
|
25
35
|
/** The refusal an error response carries, or `null` when it is any other kind of failure. */
|
|
26
36
|
export declare function parseRefusal(status: number, body: string): ProxyRefusal | null;
|
|
27
37
|
/**
|
|
28
|
-
* The
|
|
29
|
-
* answer: the
|
|
30
|
-
*
|
|
31
|
-
*
|
|
38
|
+
* The headers the proxy sets on a 200 that is a refusal in the shape of an
|
|
39
|
+
* answer: the response gate withheld a tool call the model made, output DLP
|
|
40
|
+
* withheld the body, or the cost-prediction gate answered instead of the
|
|
41
|
+
* model. The first names the refusal's code, the second the rule that decided.
|
|
32
42
|
*/
|
|
33
43
|
export declare const REFUSAL_HEADER = "x-intutic-refusal";
|
|
44
|
+
export declare const REFUSAL_RULE_HEADER = "x-intutic-refusal-rule";
|
|
34
45
|
/** The refusal a 2xx response names in `REFUSAL_HEADER`, or `null` for a real answer. */
|
|
35
|
-
export declare function headerRefusal(code: string | null, message: string): ProxyRefusal | null;
|
|
46
|
+
export declare function headerRefusal(code: string | null, ruleId: string | null, message: string): ProxyRefusal | null;
|
|
47
|
+
/**
|
|
48
|
+
* The prefix of the SSE comment line that names a refusal on a stream:
|
|
49
|
+
* `: intutic-refusal {"code", "rule", "message"}`. The response headers went
|
|
50
|
+
* out before the refusal happened, so a stream says it in band; every SSE
|
|
51
|
+
* parser skips comment lines, so clients that do not look for it are
|
|
52
|
+
* unaffected.
|
|
53
|
+
*/
|
|
54
|
+
export declare const STREAM_REFUSAL_MARKER = ": intutic-refusal ";
|
|
55
|
+
/**
|
|
56
|
+
* The refusal named anywhere in a stream's text, or `null` when there is
|
|
57
|
+
* none. Pass the whole body, or each line as it arrives.
|
|
58
|
+
*/
|
|
59
|
+
export declare function streamRefusal(text: string): ProxyRefusal | null;
|
|
36
60
|
//# sourceMappingURL=refusals.d.ts.map
|
package/dist/refusals.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refusals.d.ts","sourceRoot":"","sources":["../src/refusals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C
|
|
1
|
+
{"version":3,"file":"refusals.d.ts","sourceRoot":"","sources":["../src/refusals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,cAAc,CAAA;CAAE,CAAC,CAkBhG,CAAA;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,cAAc,CAAA;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,uEAAuE;IACvE,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,6FAA6F;AAC7F,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAe9E;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,sBAAsB,CAAA;AACjD,eAAO,MAAM,mBAAmB,2BAA2B,CAAA;AAE3D,yFAAyF;AACzF,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAG9G;AAED;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,uBAAuB,CAAA;AAEzD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAiB/D"}
|
package/dist/refusals.js
CHANGED
|
@@ -1,32 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.REFUSAL_HEADER = exports.PROXY_REFUSALS = void 0;
|
|
3
|
+
exports.STREAM_REFUSAL_MARKER = exports.REFUSAL_RULE_HEADER = exports.REFUSAL_HEADER = exports.PROXY_REFUSALS = void 0;
|
|
4
4
|
exports.parseRefusal = parseRefusal;
|
|
5
5
|
exports.headerRefusal = headerRefusal;
|
|
6
|
+
exports.streamRefusal = streamRefusal;
|
|
6
7
|
/**
|
|
7
|
-
* The proxy's governance refusals
|
|
8
|
-
*
|
|
9
|
-
* the status it always pairs that type with, and the verdict it represents.
|
|
8
|
+
* The proxy's governance refusals, by code, with the status the proxy sends
|
|
9
|
+
* each with and the verdict it represents.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
11
|
+
* Most arrive as an error: the code is the `error.type` of the proxy's JSON
|
|
12
|
+
* error body (`{"error": {"type", "message"}}`, `json_error` in
|
|
13
|
+
* packages/proxy/src/proxy.rs). Matching on the status and the code together
|
|
14
|
+
* matters because the same statuses also carry errors that are not decisions:
|
|
15
|
+
* a provider's own 429 rate limit, a 403 for a key used against the wrong
|
|
16
|
+
* workspace, a 400 for a malformed body. Those are not refusals and must not
|
|
17
|
+
* be reported as one.
|
|
15
18
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
+
* The rest (status 200, and `COST_GATE_EXCEEDED` on a non-streaming request)
|
|
20
|
+
* arrive in band: an assistant turn explaining the refusal, named by
|
|
21
|
+
* `REFUSAL_HEADER`, or on a stream by the `STREAM_REFUSAL_MARKER` comment line.
|
|
22
|
+
*
|
|
23
|
+
* `__tests__/refusals.test.ts` holds this table to
|
|
24
|
+
* packages/shared-types/fixtures/refusal-codes.json, the one list the proxy
|
|
25
|
+
* and the Python SDK are held to as well, so a refusal the proxy adds or
|
|
26
|
+
* renames fails the build instead of silently turning back into an `allow` or
|
|
27
|
+
* a retried connection error.
|
|
19
28
|
*/
|
|
20
29
|
exports.PROXY_REFUSALS = {
|
|
21
30
|
policy_denied: { status: 403, verdict: 'kill' },
|
|
22
31
|
model_not_allowed: { status: 403, verdict: 'kill' },
|
|
23
32
|
LOOP_RUN_TERMINATED: { status: 403, verdict: 'kill' },
|
|
24
33
|
LOOP_RUN_PENDING_REVIEW: { status: 403, verdict: 'hold' },
|
|
34
|
+
policy_held: { status: 403, verdict: 'hold' },
|
|
25
35
|
policy_reask: { status: 409, verdict: 'reask' },
|
|
36
|
+
GOVERNANCE_UNAVAILABLE: { status: 403, verdict: 'kill' },
|
|
26
37
|
BUDGET_EXCEEDED: { status: 429, verdict: 'kill' },
|
|
27
38
|
OVERAGE_HARD_CAP_EXCEEDED: { status: 429, verdict: 'kill' },
|
|
39
|
+
RATE_LIMITED: { status: 429, verdict: 'kill' },
|
|
28
40
|
COST_GATE_EXCEEDED: { status: 402, verdict: 'kill' },
|
|
29
41
|
dlp_policy_violation: { status: 400, verdict: 'kill' },
|
|
42
|
+
TOOL_DENIED: { status: 200, verdict: 'kill' },
|
|
43
|
+
SSO_GROUP: { status: 200, verdict: 'kill' },
|
|
44
|
+
SQL_GUARD: { status: 200, verdict: 'kill' },
|
|
45
|
+
RESPONSE_UNPARSEABLE: { status: 200, verdict: 'kill' },
|
|
46
|
+
OUTPUT_DLP: { status: 200, verdict: 'kill' },
|
|
30
47
|
};
|
|
31
48
|
/** The refusal an error response carries, or `null` when it is any other kind of failure. */
|
|
32
49
|
function parseRefusal(status, body) {
|
|
@@ -49,21 +66,57 @@ function parseRefusal(status, body) {
|
|
|
49
66
|
};
|
|
50
67
|
}
|
|
51
68
|
/**
|
|
52
|
-
* The
|
|
53
|
-
* answer: the
|
|
54
|
-
*
|
|
55
|
-
*
|
|
69
|
+
* The headers the proxy sets on a 200 that is a refusal in the shape of an
|
|
70
|
+
* answer: the response gate withheld a tool call the model made, output DLP
|
|
71
|
+
* withheld the body, or the cost-prediction gate answered instead of the
|
|
72
|
+
* model. The first names the refusal's code, the second the rule that decided.
|
|
56
73
|
*/
|
|
57
74
|
exports.REFUSAL_HEADER = 'x-intutic-refusal';
|
|
75
|
+
exports.REFUSAL_RULE_HEADER = 'x-intutic-refusal-rule';
|
|
58
76
|
/** The refusal a 2xx response names in `REFUSAL_HEADER`, or `null` for a real answer. */
|
|
59
|
-
function headerRefusal(code, message) {
|
|
77
|
+
function headerRefusal(code, ruleId, message) {
|
|
60
78
|
if (!code)
|
|
61
79
|
return null;
|
|
80
|
+
return named(code, ruleId || undefined, message);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The prefix of the SSE comment line that names a refusal on a stream:
|
|
84
|
+
* `: intutic-refusal {"code", "rule", "message"}`. The response headers went
|
|
85
|
+
* out before the refusal happened, so a stream says it in band; every SSE
|
|
86
|
+
* parser skips comment lines, so clients that do not look for it are
|
|
87
|
+
* unaffected.
|
|
88
|
+
*/
|
|
89
|
+
exports.STREAM_REFUSAL_MARKER = ': intutic-refusal ';
|
|
90
|
+
/**
|
|
91
|
+
* The refusal named anywhere in a stream's text, or `null` when there is
|
|
92
|
+
* none. Pass the whole body, or each line as it arrives.
|
|
93
|
+
*/
|
|
94
|
+
function streamRefusal(text) {
|
|
95
|
+
for (const line of text.split('\n')) {
|
|
96
|
+
if (!line.startsWith(exports.STREAM_REFUSAL_MARKER))
|
|
97
|
+
continue;
|
|
98
|
+
let payload;
|
|
99
|
+
try {
|
|
100
|
+
payload = JSON.parse(line.slice(exports.STREAM_REFUSAL_MARKER.length));
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (typeof payload?.code !== 'string')
|
|
106
|
+
continue;
|
|
107
|
+
return named(payload.code, typeof payload.rule === 'string' ? payload.rule : undefined, typeof payload.message === 'string' ? payload.message : '');
|
|
108
|
+
}
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
function named(code, ruleId, message) {
|
|
112
|
+
// A code this SDK version does not know is still a refusal: the proxy only
|
|
113
|
+
// names a response it did not let through.
|
|
62
114
|
const known = exports.PROXY_REFUSALS[code];
|
|
63
115
|
return {
|
|
64
116
|
verdict: known?.verdict ?? 'kill',
|
|
65
117
|
code,
|
|
66
118
|
message: message || code,
|
|
119
|
+
...(ruleId ? { ruleId } : {}),
|
|
67
120
|
};
|
|
68
121
|
}
|
|
69
122
|
//# sourceMappingURL=refusals.js.map
|
package/dist/refusals.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refusals.js","sourceRoot":"","s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on.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The control plane's TOON list encoding, decoded.
|
|
3
|
+
*
|
|
4
|
+
* A list endpoint answering with 20 rows or more (`GET /api/v1/traces`) may
|
|
5
|
+
* send them as one pipe-separated string under `data`, with `format: 'toon'`
|
|
6
|
+
* and `listProperty` naming the key the rows belong under. This is a copy of
|
|
7
|
+
* `toonDecode` in `@intutic/shared-types` (this package has no dependencies),
|
|
8
|
+
* applied to every control-plane response the way the CLI applies it.
|
|
9
|
+
*
|
|
10
|
+
* Cells longer than the encoder's limit arrive cut, ending in `…`: TOON trades
|
|
11
|
+
* that for size, and nothing here can restore them.
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
/** Rows from a TOON string, or null when it is not one. */
|
|
16
|
+
export declare function toonDecode(toon: string): Record<string, unknown>[] | null;
|
|
17
|
+
/**
|
|
18
|
+
* Moves a TOON-encoded list out of its envelope onto `listProperty`, so the
|
|
19
|
+
* body has the shape a shorter list arrives in; any other body passes through.
|
|
20
|
+
*/
|
|
21
|
+
export declare function unwrapToonEnvelope(data: unknown): unknown;
|
|
22
|
+
//# sourceMappingURL=toon.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toon.d.ts","sourceRoot":"","sources":["../src/toon.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAsBH,2DAA2D;AAC3D,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,IAAI,CAkBzE;AAkBD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAUzD"}
|
package/dist/toon.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The control plane's TOON list encoding, decoded.
|
|
4
|
+
*
|
|
5
|
+
* A list endpoint answering with 20 rows or more (`GET /api/v1/traces`) may
|
|
6
|
+
* send them as one pipe-separated string under `data`, with `format: 'toon'`
|
|
7
|
+
* and `listProperty` naming the key the rows belong under. This is a copy of
|
|
8
|
+
* `toonDecode` in `@intutic/shared-types` (this package has no dependencies),
|
|
9
|
+
* applied to every control-plane response the way the CLI applies it.
|
|
10
|
+
*
|
|
11
|
+
* Cells longer than the encoder's limit arrive cut, ending in `…`: TOON trades
|
|
12
|
+
* that for size, and nothing here can restore them.
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.toonDecode = toonDecode;
|
|
18
|
+
exports.unwrapToonEnvelope = unwrapToonEnvelope;
|
|
19
|
+
function splitCells(line) {
|
|
20
|
+
const cells = [];
|
|
21
|
+
let cur = '';
|
|
22
|
+
for (let i = 0; i < line.length; i++) {
|
|
23
|
+
const ch = line[i];
|
|
24
|
+
if (ch === '\\') {
|
|
25
|
+
const next = line[i + 1];
|
|
26
|
+
if (next === '\\') {
|
|
27
|
+
cur += '\\';
|
|
28
|
+
i++;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (next === '|') {
|
|
32
|
+
cur += '|';
|
|
33
|
+
i++;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (next === 'n') {
|
|
37
|
+
cur += '\n';
|
|
38
|
+
i++;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
cur += '\\';
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (ch === '|') {
|
|
45
|
+
cells.push(cur);
|
|
46
|
+
cur = '';
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
cur += ch;
|
|
50
|
+
}
|
|
51
|
+
cells.push(cur);
|
|
52
|
+
return cells;
|
|
53
|
+
}
|
|
54
|
+
/** Rows from a TOON string, or null when it is not one. */
|
|
55
|
+
function toonDecode(toon) {
|
|
56
|
+
const lines = toon.trimEnd().split('\n');
|
|
57
|
+
const header = lines[0] ?? '';
|
|
58
|
+
if (!header.startsWith('TOON|'))
|
|
59
|
+
return null;
|
|
60
|
+
const colsStr = header.slice('TOON|'.length);
|
|
61
|
+
if (colsStr === '(empty)')
|
|
62
|
+
return [];
|
|
63
|
+
const cols = colsStr.split(',');
|
|
64
|
+
const rows = [];
|
|
65
|
+
for (const line of lines.slice(1)) {
|
|
66
|
+
if (!line.trim())
|
|
67
|
+
continue;
|
|
68
|
+
const cells = splitCells(line);
|
|
69
|
+
const row = {};
|
|
70
|
+
cols.forEach((key, i) => {
|
|
71
|
+
row[key] = decodeCell(cells[i] ?? '-');
|
|
72
|
+
});
|
|
73
|
+
rows.push(row);
|
|
74
|
+
}
|
|
75
|
+
return rows;
|
|
76
|
+
}
|
|
77
|
+
function decodeCell(raw) {
|
|
78
|
+
if (raw === '-')
|
|
79
|
+
return null;
|
|
80
|
+
if (raw === 't')
|
|
81
|
+
return true;
|
|
82
|
+
if (raw === 'f')
|
|
83
|
+
return false;
|
|
84
|
+
const num = Number(raw);
|
|
85
|
+
if (!isNaN(num) && raw !== '')
|
|
86
|
+
return num;
|
|
87
|
+
if (raw.startsWith('{') || raw.startsWith('[')) {
|
|
88
|
+
try {
|
|
89
|
+
return JSON.parse(raw);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
// Not JSON after all: the text itself.
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return raw;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Moves a TOON-encoded list out of its envelope onto `listProperty`, so the
|
|
99
|
+
* body has the shape a shorter list arrives in; any other body passes through.
|
|
100
|
+
*/
|
|
101
|
+
function unwrapToonEnvelope(data) {
|
|
102
|
+
if (!data || typeof data !== 'object')
|
|
103
|
+
return data;
|
|
104
|
+
const body = data;
|
|
105
|
+
if (body['format'] !== 'toon' || typeof body['data'] !== 'string' || typeof body['listProperty'] !== 'string')
|
|
106
|
+
return data;
|
|
107
|
+
const unwrapped = {};
|
|
108
|
+
for (const [key, value] of Object.entries(body)) {
|
|
109
|
+
if (key !== 'format' && key !== 'data')
|
|
110
|
+
unwrapped[key] = value;
|
|
111
|
+
}
|
|
112
|
+
unwrapped[body['listProperty']] = toonDecode(body['data']) ?? [];
|
|
113
|
+
return unwrapped;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=toon.js.map
|
package/dist/toon.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toon.js","sourceRoot":"","sources":["../src/toon.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;AAuBH,gCAkBC;AAsBD,gDAUC;AAvED,SAAS,UAAU,CAAC,IAAY;IAC9B,MAAM,KAAK,GAAa,EAAE,CAAA;IAC1B,IAAI,GAAG,GAAG,EAAE,CAAA;IACZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;QAClB,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC;YAChB,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;YACxB,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;gBAAC,GAAG,IAAI,IAAI,CAAC;gBAAC,CAAC,EAAE,CAAC;gBAAC,SAAQ;YAAC,CAAC;YACjD,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;gBAAC,GAAG,IAAI,GAAG,CAAC;gBAAC,CAAC,EAAE,CAAC;gBAAC,SAAQ;YAAC,CAAC;YAC/C,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;gBAAC,GAAG,IAAI,IAAI,CAAC;gBAAC,CAAC,EAAE,CAAC;gBAAC,SAAQ;YAAC,CAAC;YAChD,GAAG,IAAI,IAAI,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