@anthropic-ai/sdk 0.20.8 → 0.21.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/_vendor/partial-json-parser/parser.d.ts +3 -0
  3. package/_vendor/partial-json-parser/parser.d.ts.map +1 -0
  4. package/_vendor/partial-json-parser/parser.js +224 -0
  5. package/_vendor/partial-json-parser/parser.js.map +1 -0
  6. package/_vendor/partial-json-parser/parser.mjs +221 -0
  7. package/_vendor/partial-json-parser/parser.mjs.map +1 -0
  8. package/lib/ToolsBetaMessageStream.d.ts +95 -0
  9. package/lib/ToolsBetaMessageStream.d.ts.map +1 -0
  10. package/lib/ToolsBetaMessageStream.js +459 -0
  11. package/lib/ToolsBetaMessageStream.js.map +1 -0
  12. package/lib/ToolsBetaMessageStream.mjs +455 -0
  13. package/lib/ToolsBetaMessageStream.mjs.map +1 -0
  14. package/package.json +3 -3
  15. package/resources/beta/tools/index.d.ts +1 -1
  16. package/resources/beta/tools/index.d.ts.map +1 -1
  17. package/resources/beta/tools/index.js.map +1 -1
  18. package/resources/beta/tools/index.mjs.map +1 -1
  19. package/resources/beta/tools/messages.d.ts +349 -18
  20. package/resources/beta/tools/messages.d.ts.map +1 -1
  21. package/resources/beta/tools/messages.js +11 -2
  22. package/resources/beta/tools/messages.js.map +1 -1
  23. package/resources/beta/tools/messages.mjs +9 -1
  24. package/resources/beta/tools/messages.mjs.map +1 -1
  25. package/resources/beta/tools/tools.d.ts +5 -0
  26. package/resources/beta/tools/tools.d.ts.map +1 -1
  27. package/resources/beta/tools/tools.js.map +1 -1
  28. package/resources/beta/tools/tools.mjs.map +1 -1
  29. package/resources/completions.d.ts +11 -19
  30. package/resources/completions.d.ts.map +1 -1
  31. package/resources/completions.js.map +1 -1
  32. package/resources/completions.mjs.map +1 -1
  33. package/resources/messages.d.ts +22 -22
  34. package/src/_vendor/partial-json-parser/README.md +3 -0
  35. package/src/_vendor/partial-json-parser/parser.ts +262 -0
  36. package/src/lib/ToolsBetaMessageStream.ts +561 -0
  37. package/src/resources/beta/tools/index.ts +5 -0
  38. package/src/resources/beta/tools/messages.ts +397 -21
  39. package/src/resources/beta/tools/tools.ts +5 -0
  40. package/src/resources/completions.ts +11 -19
  41. package/src/resources/messages.ts +22 -22
  42. package/src/version.ts +1 -1
  43. package/version.d.ts +1 -1
  44. package/version.js +1 -1
  45. package/version.mjs +1 -1
@@ -8,11 +8,10 @@ export declare class Completions extends APIResource {
8
8
  * [Legacy] Create a Text Completion.
9
9
  *
10
10
  * The Text Completions API is a legacy API. We recommend using the
11
- * [Messages API](https://docs.anthropic.com/claude/reference/messages_post) going
12
- * forward.
11
+ * [Messages API](https://docs.anthropic.com/en/api/messages) going forward.
13
12
  *
14
13
  * Future models and features will not be compatible with Text Completions. See our
15
- * [migration guide](https://docs.anthropic.com/claude/reference/migrating-from-text-completions-to-messages)
14
+ * [migration guide](https://docs.anthropic.com/en/api/migrating-from-text-completions-to-messages)
16
15
  * for guidance in migrating from Text Completions to Messages.
17
16
  */
18
17
  create(body: CompletionCreateParamsNonStreaming, options?: Core.RequestOptions): APIPromise<Completion>;
@@ -63,8 +62,8 @@ export interface CompletionCreateParamsBase {
63
62
  /**
64
63
  * The model that will complete your prompt.
65
64
  *
66
- * See [models](https://docs.anthropic.com/claude/docs/models-overview) for
67
- * additional details and options.
65
+ * See [models](https://docs.anthropic.com/en/docs/models-overview) for additional
66
+ * details and options.
68
67
  */
69
68
  model: (string & {}) | 'claude-2.0' | 'claude-2.1' | 'claude-instant-1.2';
70
69
  /**
@@ -77,11 +76,10 @@ export interface CompletionCreateParamsBase {
77
76
  * "\n\nHuman: {userQuestion}\n\nAssistant:"
78
77
  * ```
79
78
  *
80
- * See
81
- * [prompt validation](https://anthropic.readme.io/claude/reference/prompt-validation)
82
- * and our guide to
83
- * [prompt design](https://docs.anthropic.com/claude/docs/introduction-to-prompt-design)
84
- * for more details.
79
+ * See [prompt validation](https://docs.anthropic.com/en/api/prompt-validation) and
80
+ * our guide to
81
+ * [prompt design](https://docs.anthropic.com/en/docs/intro-to-prompting) for more
82
+ * details.
85
83
  */
86
84
  prompt: string;
87
85
  /**
@@ -99,9 +97,7 @@ export interface CompletionCreateParamsBase {
99
97
  /**
100
98
  * Whether to incrementally stream the response using server-sent events.
101
99
  *
102
- * See
103
- * [streaming](https://docs.anthropic.com/claude/reference/text-completions-streaming)
104
- * for details.
100
+ * See [streaming](https://docs.anthropic.com/en/api/streaming) for details.
105
101
  */
106
102
  stream?: boolean;
107
103
  /**
@@ -159,9 +155,7 @@ export interface CompletionCreateParamsNonStreaming extends CompletionCreatePara
159
155
  /**
160
156
  * Whether to incrementally stream the response using server-sent events.
161
157
  *
162
- * See
163
- * [streaming](https://docs.anthropic.com/claude/reference/text-completions-streaming)
164
- * for details.
158
+ * See [streaming](https://docs.anthropic.com/en/api/streaming) for details.
165
159
  */
166
160
  stream?: false;
167
161
  }
@@ -169,9 +163,7 @@ export interface CompletionCreateParamsStreaming extends CompletionCreateParamsB
169
163
  /**
170
164
  * Whether to incrementally stream the response using server-sent events.
171
165
  *
172
- * See
173
- * [streaming](https://docs.anthropic.com/claude/reference/text-completions-streaming)
174
- * for details.
166
+ * See [streaming](https://docs.anthropic.com/en/api/streaming) for details.
175
167
  */
176
168
  stream: true;
177
169
  }
@@ -1 +1 @@
1
- {"version":3,"file":"completions.d.ts","sourceRoot":"","sources":["../src/resources/completions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,IAAI,MAAM,wBAAwB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,KAAK,cAAc,MAAM,yCAAyC,CAAC;AAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAErD,qBAAa,WAAY,SAAQ,WAAW;IAC1C;;;;;;;;;;OAUG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AAC,EAAE,MAAM,CAAC;CAChB;AAED,yBAAiB,sBAAsB,CAAC;IACtC;;OAEG;IACH,UAAiB,QAAQ;QACvB;;;;;;WAMG;QACH,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KACzB;IAED,KAAY,kCAAkC,GAAG,cAAc,CAAC,kCAAkC,CAAC;IACnG,KAAY,+BAA+B,GAAG,cAAc,CAAC,+BAA+B,CAAC;CAC9F;AAED,MAAM,WAAW,kCAAmC,SAAQ,0BAA0B;IACpF;;;;OAIG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC;CAChB;AAED,MAAM,WAAW,+BAAgC,SAAQ,0BAA0B;IACjF;;;;OAIG;IACH,MAAM,EAAE,IAAI,CAAC;CACd;AAED,yBAAiB,WAAW,CAAC;IAC3B,MAAM,QAAQ,UAAU,GAAG,cAAc,CAAC,UAAU,CAAC;IACrD,MAAM,QAAQ,sBAAsB,GAAG,cAAc,CAAC,sBAAsB,CAAC;IAC7E,MAAM,QAAQ,kCAAkC,GAAG,cAAc,CAAC,kCAAkC,CAAC;IACrG,MAAM,QAAQ,+BAA+B,GAAG,cAAc,CAAC,+BAA+B,CAAC;CAChG"}
@@ -1 +1 @@
1
- {"version":3,"file":"completions.js","sourceRoot":"","sources":["../src/resources/completions.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAItF,yDAAyD;AAIzD,MAAa,WAAY,SAAQ,sBAAW;IAqB1C,MAAM,CACJ,IAA4B,EAC5B,OAA6B;QAE7B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE;YACvC,IAAI;YACJ,OAAO,EAAE,MAAM;YACf,GAAG,OAAO;YACV,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,KAAK;SAC7B,CAA4D,CAAC;IAChE,CAAC;CACF;AAhCD,kCAgCC;AAiLD,WAAiB,WAAW;AAK5B,CAAC,EALgB,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAK3B"}
1
+ {"version":3,"file":"completions.js","sourceRoot":"","sources":["../src/resources/completions.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAItF,yDAAyD;AAIzD,MAAa,WAAY,SAAQ,sBAAW;IAoB1C,MAAM,CACJ,IAA4B,EAC5B,OAA6B;QAE7B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE;YACvC,IAAI;YACJ,OAAO,EAAE,MAAM;YACf,GAAG,OAAO;YACV,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,KAAK;SAC7B,CAA4D,CAAC;IAChE,CAAC;CACF;AA/BD,kCA+BC;AA0KD,WAAiB,WAAW;AAK5B,CAAC,EALgB,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAK3B"}
@@ -1 +1 @@
1
- {"version":3,"file":"completions.mjs","sourceRoot":"","sources":["../src/resources/completions.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAI/E,EAAE,WAAW,EAAE,MAAM,4BAA4B;AAIxD,MAAM,OAAO,WAAY,SAAQ,WAAW;IAqB1C,MAAM,CACJ,IAA4B,EAC5B,OAA6B;QAE7B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE;YACvC,IAAI;YACJ,OAAO,EAAE,MAAM;YACf,GAAG,OAAO;YACV,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,KAAK;SAC7B,CAA4D,CAAC;IAChE,CAAC;CACF;AAiLD,WAAiB,WAAW;AAK5B,CAAC,EALgB,WAAW,KAAX,WAAW,QAK3B"}
1
+ {"version":3,"file":"completions.mjs","sourceRoot":"","sources":["../src/resources/completions.ts"],"names":[],"mappings":"AAAA,sFAAsF;OAI/E,EAAE,WAAW,EAAE,MAAM,4BAA4B;AAIxD,MAAM,OAAO,WAAY,SAAQ,WAAW;IAoB1C,MAAM,CACJ,IAA4B,EAC5B,OAA6B;QAE7B,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE;YACvC,IAAI;YACJ,OAAO,EAAE,MAAM;YACf,GAAG,OAAO;YACV,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,KAAK;SAC7B,CAA4D,CAAC;IAChE,CAAC;CACF;AA0KD,WAAiB,WAAW;AAK5B,CAAC,EALgB,WAAW,KAAX,WAAW,QAK3B"}
@@ -217,7 +217,7 @@ export interface MessageCreateParamsBase {
217
217
  * only specifies the absolute maximum number of tokens to generate.
218
218
  *
219
219
  * Different models have different maximum values for this parameter. See
220
- * [models](https://docs.anthropic.com/claude/docs/models-overview) for details.
220
+ * [models](https://docs.anthropic.com/en/docs/models-overview) for details.
221
221
  */
222
222
  max_tokens: number;
223
223
  /**
@@ -299,20 +299,20 @@ export interface MessageCreateParamsBase {
299
299
  * We currently support the `base64` source type for images, and the `image/jpeg`,
300
300
  * `image/png`, `image/gif`, and `image/webp` media types.
301
301
  *
302
- * See [examples](https://docs.anthropic.com/claude/reference/messages-examples)
303
- * for more input examples.
302
+ * See [examples](https://docs.anthropic.com/en/api/messages-examples) for more
303
+ * input examples.
304
304
  *
305
305
  * Note that if you want to include a
306
- * [system prompt](https://docs.anthropic.com/claude/docs/system-prompts), you can
307
- * use the top-level `system` parameter — there is no `"system"` role for input
306
+ * [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
307
+ * the top-level `system` parameter — there is no `"system"` role for input
308
308
  * messages in the Messages API.
309
309
  */
310
310
  messages: Array<MessageParam>;
311
311
  /**
312
312
  * The model that will complete your prompt.
313
313
  *
314
- * See [models](https://docs.anthropic.com/claude/docs/models-overview) for
315
- * additional details and options.
314
+ * See [models](https://docs.anthropic.com/en/docs/models-overview) for additional
315
+ * details and options.
316
316
  */
317
317
  model: (string & {}) | 'claude-3-opus-20240229' | 'claude-3-sonnet-20240229' | 'claude-3-haiku-20240307' | 'claude-2.1' | 'claude-2.0' | 'claude-instant-1.2';
318
318
  /**
@@ -334,8 +334,8 @@ export interface MessageCreateParamsBase {
334
334
  /**
335
335
  * Whether to incrementally stream the response using server-sent events.
336
336
  *
337
- * See [streaming](https://docs.anthropic.com/claude/reference/messages-streaming)
338
- * for details.
337
+ * See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
338
+ * details.
339
339
  */
340
340
  stream?: boolean;
341
341
  /**
@@ -343,7 +343,7 @@ export interface MessageCreateParamsBase {
343
343
  *
344
344
  * A system prompt is a way of providing context and instructions to Claude, such
345
345
  * as specifying a particular goal or role. See our
346
- * [guide to system prompts](https://docs.anthropic.com/claude/docs/system-prompts).
346
+ * [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
347
347
  */
348
348
  system?: string;
349
349
  /**
@@ -401,8 +401,8 @@ export interface MessageCreateParamsNonStreaming extends MessageCreateParamsBase
401
401
  /**
402
402
  * Whether to incrementally stream the response using server-sent events.
403
403
  *
404
- * See [streaming](https://docs.anthropic.com/claude/reference/messages-streaming)
405
- * for details.
404
+ * See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
405
+ * details.
406
406
  */
407
407
  stream?: false;
408
408
  }
@@ -410,8 +410,8 @@ export interface MessageCreateParamsStreaming extends MessageCreateParamsBase {
410
410
  /**
411
411
  * Whether to incrementally stream the response using server-sent events.
412
412
  *
413
- * See [streaming](https://docs.anthropic.com/claude/reference/messages-streaming)
414
- * for details.
413
+ * See [streaming](https://docs.anthropic.com/en/api/messages-streaming) for
414
+ * details.
415
415
  */
416
416
  stream: true;
417
417
  }
@@ -423,7 +423,7 @@ export interface MessageStreamParams {
423
423
  * only specifies the absolute maximum number of tokens to generate.
424
424
  *
425
425
  * Different models have different maximum values for this parameter. See
426
- * [models](https://docs.anthropic.com/claude/docs/models-overview) for details.
426
+ * [models](https://docs.anthropic.com/en/docs/models-overview) for details.
427
427
  */
428
428
  max_tokens: number;
429
429
  /**
@@ -505,20 +505,20 @@ export interface MessageStreamParams {
505
505
  * We currently support the `base64` source type for images, and the `image/jpeg`,
506
506
  * `image/png`, `image/gif`, and `image/webp` media types.
507
507
  *
508
- * See [examples](https://docs.anthropic.com/claude/reference/messages-examples)
509
- * for more input examples.
508
+ * See [examples](https://docs.anthropic.com/en/api/messages-examples) for more
509
+ * input examples.
510
510
  *
511
511
  * Note that if you want to include a
512
- * [system prompt](https://docs.anthropic.com/claude/docs/system-prompts), you can
513
- * use the top-level `system` parameter — there is no `"system"` role for input
512
+ * [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use
513
+ * the top-level `system` parameter — there is no `"system"` role for input
514
514
  * messages in the Messages API.
515
515
  */
516
516
  messages: Array<MessageParam>;
517
517
  /**
518
518
  * The model that will complete your prompt.
519
519
  *
520
- * See [models](https://docs.anthropic.com/claude/docs/models-overview) for
521
- * additional details and options.
520
+ * See [models](https://docs.anthropic.com/en/docs/models-overview) for additional
521
+ * details and options.
522
522
  */
523
523
  model: (string & {}) | 'claude-3-opus-20240229' | 'claude-3-sonnet-20240229' | 'claude-3-haiku-20240307' | 'claude-2.1' | 'claude-2.0' | 'claude-instant-1.2';
524
524
  /**
@@ -542,7 +542,7 @@ export interface MessageStreamParams {
542
542
  *
543
543
  * A system prompt is a way of providing context and instructions to Claude, such
544
544
  * as specifying a particular goal or role. See our
545
- * [guide to system prompts](https://docs.anthropic.com/claude/docs/system-prompts).
545
+ * [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts).
546
546
  */
547
547
  system?: string;
548
548
  /**
@@ -0,0 +1,3 @@
1
+ # Partial JSON Parser
2
+
3
+ Vendored from https://www.npmjs.com/package/partial-json-parser and updated to use TypeScript.
@@ -0,0 +1,262 @@
1
+ type Token = {
2
+ type: string;
3
+ value: string;
4
+ };
5
+
6
+ const tokenize = (input: string) => {
7
+ let current = 0;
8
+ let tokens = [];
9
+
10
+ while (current < input.length) {
11
+ let char = input[current];
12
+
13
+ if (char === '\\') {
14
+ current++;
15
+ continue;
16
+ }
17
+
18
+ if (char === '{') {
19
+ tokens.push({
20
+ type: 'brace',
21
+ value: '{',
22
+ });
23
+
24
+ current++;
25
+ continue;
26
+ }
27
+
28
+ if (char === '}') {
29
+ tokens.push({
30
+ type: 'brace',
31
+ value: '}',
32
+ });
33
+
34
+ current++;
35
+ continue;
36
+ }
37
+
38
+ if (char === '[') {
39
+ tokens.push({
40
+ type: 'paren',
41
+ value: '[',
42
+ });
43
+
44
+ current++;
45
+ continue;
46
+ }
47
+
48
+ if (char === ']') {
49
+ tokens.push({
50
+ type: 'paren',
51
+ value: ']',
52
+ });
53
+
54
+ current++;
55
+ continue;
56
+ }
57
+
58
+ if (char === ':') {
59
+ tokens.push({
60
+ type: 'separator',
61
+ value: ':',
62
+ });
63
+
64
+ current++;
65
+ continue;
66
+ }
67
+
68
+ if (char === ',') {
69
+ tokens.push({
70
+ type: 'delimiter',
71
+ value: ',',
72
+ });
73
+
74
+ current++;
75
+ continue;
76
+ }
77
+
78
+ if (char === '"') {
79
+ let value = '';
80
+ let danglingQuote = false;
81
+
82
+ char = input[++current];
83
+
84
+ while (char !== '"') {
85
+ if (current === input.length) {
86
+ danglingQuote = true;
87
+ break;
88
+ }
89
+
90
+ if (char === '\\') {
91
+ current++;
92
+ if (current === input.length) {
93
+ danglingQuote = true;
94
+ break;
95
+ }
96
+ value += char + input[current];
97
+ char = input[++current];
98
+ } else {
99
+ value += char;
100
+ char = input[++current];
101
+ }
102
+ }
103
+
104
+ char = input[++current];
105
+
106
+ if (!danglingQuote) {
107
+ tokens.push({
108
+ type: 'string',
109
+ value,
110
+ });
111
+ }
112
+ continue;
113
+ }
114
+
115
+ let WHITESPACE = /\s/;
116
+ if (char && WHITESPACE.test(char)) {
117
+ current++;
118
+ continue;
119
+ }
120
+
121
+ let NUMBERS = /[0-9]/;
122
+ if ((char && NUMBERS.test(char)) || char === '-' || char === '.') {
123
+ let value = '';
124
+
125
+ if (char === '-') {
126
+ value += char;
127
+ char = input[++current];
128
+ }
129
+
130
+ while ((char && NUMBERS.test(char)) || char === '.') {
131
+ value += char;
132
+ char = input[++current];
133
+ }
134
+
135
+ tokens.push({
136
+ type: 'number',
137
+ value,
138
+ });
139
+ continue;
140
+ }
141
+
142
+ let LETTERS = /[a-z]/i;
143
+ if (char && LETTERS.test(char)) {
144
+ let value = '';
145
+
146
+ while (char && LETTERS.test(char)) {
147
+ if (current === input.length) {
148
+ break;
149
+ }
150
+ value += char;
151
+ char = input[++current];
152
+ }
153
+
154
+ if (value == 'true' || value == 'false') {
155
+ tokens.push({
156
+ type: 'name',
157
+ value,
158
+ });
159
+ } else {
160
+ throw new Error(`Invalid token: ${value} is not a valid token!`);
161
+ }
162
+ continue;
163
+ }
164
+
165
+ current++;
166
+ }
167
+
168
+ return tokens;
169
+ },
170
+ strip = (tokens: Token[]): Token[] => {
171
+ if (tokens.length === 0) {
172
+ return tokens;
173
+ }
174
+
175
+ let lastToken = tokens[tokens.length - 1]!;
176
+
177
+ switch (lastToken.type) {
178
+ case 'separator':
179
+ tokens = tokens.slice(0, tokens.length - 1);
180
+ return strip(tokens);
181
+ break;
182
+ case 'number':
183
+ let lastCharacterOfLastToken = lastToken.value[lastToken.value.length - 1];
184
+ if (lastCharacterOfLastToken === '.' || lastCharacterOfLastToken === '-') {
185
+ tokens = tokens.slice(0, tokens.length - 1);
186
+ return strip(tokens);
187
+ }
188
+ case 'string':
189
+ let tokenBeforeTheLastToken = tokens[tokens.length - 2];
190
+ if (tokenBeforeTheLastToken?.type === 'delimiter') {
191
+ tokens = tokens.slice(0, tokens.length - 1);
192
+ return strip(tokens);
193
+ } else if (tokenBeforeTheLastToken?.type === 'brace' && tokenBeforeTheLastToken.value === '{') {
194
+ tokens = tokens.slice(0, tokens.length - 1);
195
+ return strip(tokens);
196
+ }
197
+ break;
198
+ case 'delimiter':
199
+ tokens = tokens.slice(0, tokens.length - 1);
200
+ return strip(tokens);
201
+ break;
202
+ }
203
+
204
+ return tokens;
205
+ },
206
+ unstrip = (tokens: Token[]): Token[] => {
207
+ let tail: string[] = [];
208
+
209
+ tokens.map((token) => {
210
+ if (token.type === 'brace') {
211
+ if (token.value === '{') {
212
+ tail.push('}');
213
+ } else {
214
+ tail.splice(tail.lastIndexOf('}'), 1);
215
+ }
216
+ }
217
+ if (token.type === 'paren') {
218
+ if (token.value === '[') {
219
+ tail.push(']');
220
+ } else {
221
+ tail.splice(tail.lastIndexOf(']'), 1);
222
+ }
223
+ }
224
+ });
225
+
226
+ if (tail.length > 0) {
227
+ tail.reverse().map((item) => {
228
+ if (item === '}') {
229
+ tokens.push({
230
+ type: 'brace',
231
+ value: '}',
232
+ });
233
+ } else if (item === ']') {
234
+ tokens.push({
235
+ type: 'paren',
236
+ value: ']',
237
+ });
238
+ }
239
+ });
240
+ }
241
+
242
+ return tokens;
243
+ },
244
+ generate = (tokens: Token[]): string => {
245
+ let output = '';
246
+
247
+ tokens.map((token) => {
248
+ switch (token.type) {
249
+ case 'string':
250
+ output += '"' + token.value + '"';
251
+ break;
252
+ default:
253
+ output += token.value;
254
+ break;
255
+ }
256
+ });
257
+
258
+ return output;
259
+ },
260
+ partialParse = (input: string): unknown => JSON.parse(generate(unstrip(strip(tokenize(input)))));
261
+
262
+ export { partialParse };