@graphext/cuery 0.4.0 → 0.5.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.
- package/esm/browser.d.ts +1 -1
- package/esm/browser.d.ts.map +1 -1
- package/esm/browser.js +1 -1
- package/esm/mod.d.ts +5 -2
- package/esm/mod.d.ts.map +1 -1
- package/esm/mod.js +7 -2
- package/esm/src/api.d.ts +36 -5
- package/esm/src/api.d.ts.map +1 -1
- package/esm/src/api.js +84 -37
- package/esm/src/apis/chatgptScraper/brightdata.js +1 -1
- package/esm/src/apis/chatgptScraper/oxy.js +1 -1
- package/esm/src/apis/chatgptScraper/scraper.js +2 -2
- package/esm/src/apis/hasdata/aim.js +1 -1
- package/esm/src/apis/hasdata/aio.js +1 -1
- package/esm/src/apis/hasdata/helpers.d.ts +1 -1
- package/esm/src/apis/hasdata/helpers.d.ts.map +1 -1
- package/esm/src/apis/hasdata/helpers.js +2 -2
- package/esm/src/assets/models.d.ts +60725 -0
- package/esm/src/assets/models.d.ts.map +1 -0
- package/esm/src/assets/models.js +71915 -0
- package/esm/src/helpers/async.d.ts.map +1 -0
- package/esm/src/{async.js → helpers/async.js} +1 -1
- package/esm/src/helpers/seedKeywords.d.ts.map +1 -0
- package/esm/src/helpers/urls.d.ts.map +1 -0
- package/esm/src/helpers/utils.d.ts.map +1 -0
- package/esm/src/llm.d.ts +35 -0
- package/esm/src/llm.d.ts.map +1 -0
- package/esm/src/llm.js +59 -0
- package/esm/src/providers/google.d.ts +12 -0
- package/esm/src/providers/google.d.ts.map +1 -0
- package/esm/src/providers/google.js +111 -0
- package/esm/src/providers/index.d.ts +13 -0
- package/esm/src/providers/index.d.ts.map +1 -0
- package/esm/src/providers/index.js +14 -0
- package/esm/src/providers/openai.d.ts +12 -0
- package/esm/src/providers/openai.d.ts.map +1 -0
- package/esm/src/providers/openai.js +141 -0
- package/esm/src/providers/pricing.d.ts +72 -0
- package/esm/src/providers/pricing.d.ts.map +1 -0
- package/esm/src/providers/pricing.js +88 -0
- package/esm/src/providers/registry.d.ts +20 -0
- package/esm/src/providers/registry.d.ts.map +1 -0
- package/esm/src/providers/registry.js +35 -0
- package/esm/src/providers/types.d.ts +49 -0
- package/esm/src/providers/types.d.ts.map +1 -0
- package/esm/src/providers/types.js +7 -0
- package/esm/src/response.d.ts +74 -0
- package/esm/src/response.d.ts.map +1 -0
- package/esm/src/response.js +110 -0
- package/esm/src/tool.d.ts +58 -0
- package/esm/src/tool.d.ts.map +1 -0
- package/esm/src/tool.js +91 -0
- package/esm/src/tools/brands.js +6 -6
- package/esm/src/tools/classifier.d.ts +80 -17
- package/esm/src/tools/classifier.d.ts.map +1 -1
- package/esm/src/tools/classifier.js +68 -80
- package/esm/src/tools/entities.d.ts +23 -12
- package/esm/src/tools/entities.d.ts.map +1 -1
- package/esm/src/tools/entities.js +27 -47
- package/esm/src/tools/funnel.js +7 -7
- package/esm/src/tools/generic.d.ts +17 -4
- package/esm/src/tools/generic.d.ts.map +1 -1
- package/esm/src/tools/generic.js +39 -14
- package/esm/src/tools/keywords.js +5 -5
- package/esm/src/tools/personas.d.ts +49 -2
- package/esm/src/tools/personas.d.ts.map +1 -1
- package/esm/src/tools/personas.js +59 -35
- package/esm/src/tools/scorer.d.ts +24 -6
- package/esm/src/tools/scorer.d.ts.map +1 -1
- package/esm/src/tools/scorer.js +27 -22
- package/esm/src/tools/search.d.ts.map +1 -1
- package/esm/src/tools/search.js +33 -9
- package/esm/src/tools/sentiment.d.ts +30 -8
- package/esm/src/tools/sentiment.d.ts.map +1 -1
- package/esm/src/tools/sentiment.js +33 -28
- package/esm/src/tools/sources.d.ts +5 -5
- package/esm/src/tools/sources.d.ts.map +1 -1
- package/esm/src/tools/sources.js +5 -6
- package/esm/src/tools/topics.d.ts +44 -16
- package/esm/src/tools/topics.d.ts.map +1 -1
- package/esm/src/tools/topics.js +77 -68
- package/esm/src/tools/translate.d.ts +22 -31
- package/esm/src/tools/translate.d.ts.map +1 -1
- package/esm/src/tools/translate.js +40 -36
- package/package.json +2 -1
- package/script/browser.d.ts +1 -1
- package/script/browser.d.ts.map +1 -1
- package/script/browser.js +1 -1
- package/script/mod.d.ts +5 -2
- package/script/mod.d.ts.map +1 -1
- package/script/mod.js +14 -2
- package/script/src/api.d.ts +36 -5
- package/script/src/api.d.ts.map +1 -1
- package/script/src/api.js +84 -35
- package/script/src/apis/chatgptScraper/brightdata.js +1 -1
- package/script/src/apis/chatgptScraper/oxy.js +1 -1
- package/script/src/apis/chatgptScraper/scraper.js +2 -2
- package/script/src/apis/hasdata/aim.js +1 -1
- package/script/src/apis/hasdata/aio.js +1 -1
- package/script/src/apis/hasdata/helpers.d.ts +1 -1
- package/script/src/apis/hasdata/helpers.d.ts.map +1 -1
- package/script/src/apis/hasdata/helpers.js +2 -2
- package/script/src/assets/models.d.ts +60725 -0
- package/script/src/assets/models.d.ts.map +1 -0
- package/script/src/assets/models.js +71917 -0
- package/script/src/helpers/async.d.ts.map +1 -0
- package/script/src/{async.js → helpers/async.js} +1 -1
- package/script/src/helpers/seedKeywords.d.ts.map +1 -0
- package/script/src/helpers/urls.d.ts.map +1 -0
- package/script/src/helpers/utils.d.ts.map +1 -0
- package/script/src/llm.d.ts +35 -0
- package/script/src/llm.d.ts.map +1 -0
- package/script/src/llm.js +65 -0
- package/script/src/providers/google.d.ts +12 -0
- package/script/src/providers/google.d.ts.map +1 -0
- package/script/src/providers/google.js +148 -0
- package/script/src/providers/index.d.ts +13 -0
- package/script/src/providers/index.d.ts.map +1 -0
- package/script/src/providers/index.js +24 -0
- package/script/src/providers/openai.d.ts +12 -0
- package/script/src/providers/openai.d.ts.map +1 -0
- package/script/src/providers/openai.js +181 -0
- package/script/src/providers/pricing.d.ts +72 -0
- package/script/src/providers/pricing.d.ts.map +1 -0
- package/script/src/providers/pricing.js +97 -0
- package/script/src/providers/registry.d.ts +20 -0
- package/script/src/providers/registry.d.ts.map +1 -0
- package/script/src/providers/registry.js +39 -0
- package/script/src/providers/types.d.ts +49 -0
- package/script/src/providers/types.d.ts.map +1 -0
- package/script/src/providers/types.js +8 -0
- package/script/src/response.d.ts +74 -0
- package/script/src/response.d.ts.map +1 -0
- package/script/src/response.js +114 -0
- package/script/src/tool.d.ts +58 -0
- package/script/src/tool.d.ts.map +1 -0
- package/script/src/tool.js +95 -0
- package/script/src/tools/brands.js +6 -6
- package/script/src/tools/classifier.d.ts +80 -17
- package/script/src/tools/classifier.d.ts.map +1 -1
- package/script/src/tools/classifier.js +72 -85
- package/script/src/tools/entities.d.ts +23 -12
- package/script/src/tools/entities.d.ts.map +1 -1
- package/script/src/tools/entities.js +29 -51
- package/script/src/tools/funnel.js +7 -7
- package/script/src/tools/generic.d.ts +17 -4
- package/script/src/tools/generic.d.ts.map +1 -1
- package/script/src/tools/generic.js +39 -14
- package/script/src/tools/keywords.js +5 -5
- package/script/src/tools/personas.d.ts +49 -2
- package/script/src/tools/personas.d.ts.map +1 -1
- package/script/src/tools/personas.js +63 -36
- package/script/src/tools/scorer.d.ts +24 -6
- package/script/src/tools/scorer.d.ts.map +1 -1
- package/script/src/tools/scorer.js +28 -24
- package/script/src/tools/search.d.ts.map +1 -1
- package/script/src/tools/search.js +69 -9
- package/script/src/tools/sentiment.d.ts +30 -8
- package/script/src/tools/sentiment.d.ts.map +1 -1
- package/script/src/tools/sentiment.js +37 -30
- package/script/src/tools/sources.d.ts +5 -5
- package/script/src/tools/sources.d.ts.map +1 -1
- package/script/src/tools/sources.js +4 -5
- package/script/src/tools/topics.d.ts +44 -16
- package/script/src/tools/topics.d.ts.map +1 -1
- package/script/src/tools/topics.js +80 -72
- package/script/src/tools/translate.d.ts +22 -31
- package/script/src/tools/translate.d.ts.map +1 -1
- package/script/src/tools/translate.js +43 -40
- package/esm/src/async.d.ts.map +0 -1
- package/esm/src/models.d.ts +0 -18
- package/esm/src/models.d.ts.map +0 -1
- package/esm/src/models.js +0 -48
- package/esm/src/openai.d.ts +0 -17
- package/esm/src/openai.d.ts.map +0 -1
- package/esm/src/openai.js +0 -136
- package/esm/src/tools/seedKeywords.d.ts.map +0 -1
- package/esm/src/urls.d.ts.map +0 -1
- package/esm/src/utils.d.ts.map +0 -1
- package/script/src/async.d.ts.map +0 -1
- package/script/src/models.d.ts +0 -18
- package/script/src/models.d.ts.map +0 -1
- package/script/src/models.js +0 -52
- package/script/src/openai.d.ts +0 -17
- package/script/src/openai.d.ts.map +0 -1
- package/script/src/openai.js +0 -175
- package/script/src/tools/seedKeywords.d.ts.map +0 -1
- package/script/src/urls.d.ts.map +0 -1
- package/script/src/utils.d.ts.map +0 -1
- /package/esm/src/{async.d.ts → helpers/async.d.ts} +0 -0
- /package/esm/src/{tools → helpers}/seedKeywords.d.ts +0 -0
- /package/esm/src/{tools → helpers}/seedKeywords.js +0 -0
- /package/esm/src/{urls.d.ts → helpers/urls.d.ts} +0 -0
- /package/esm/src/{urls.js → helpers/urls.js} +0 -0
- /package/esm/src/{utils.d.ts → helpers/utils.d.ts} +0 -0
- /package/esm/src/{utils.js → helpers/utils.js} +0 -0
- /package/script/src/{async.d.ts → helpers/async.d.ts} +0 -0
- /package/script/src/{tools → helpers}/seedKeywords.d.ts +0 -0
- /package/script/src/{tools → helpers}/seedKeywords.js +0 -0
- /package/script/src/{urls.d.ts → helpers/urls.d.ts} +0 -0
- /package/script/src/{urls.js → helpers/urls.js} +0 -0
- /package/script/src/{utils.d.ts → helpers/utils.d.ts} +0 -0
- /package/script/src/{utils.js → helpers/utils.js} +0 -0
package/esm/src/async.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"async.d.ts","sourceRoot":"","sources":["../../src/src/async.ts"],"names":[],"mappings":"AAAA;;GAEG;AAYH,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAyB1E;AAMD,MAAM,WAAW,WAAW;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,WAAW,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CAC5B;AAED,eAAO,MAAM,cAAc;;;;;;CAM1B,CAAC;AAEF;;;GAGG;AACH,wBAAsB,WAAW,CAChC,EAAE,EAAE,MAAM,OAAO,CAAC,QAAQ,CAAC,EAC3B,EACC,UAAsC,EACtC,YAA0C,EAC1C,QAAkC,EAClC,iBAAoD,EACpD,WAAwC,EACxC,GAAE,WAAgB,GACjB,OAAO,CAAC,QAAQ,CAAC,CA+CnB;AAMD;;;GAGG;AACH,wBAAsB,WAAW,CAAC,CAAC,EAAE,CAAC,EACrC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,EACzC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GAC/C,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CA0BnB"}
|
package/esm/src/models.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { ModelIdentifier } from './schemas/models.schema.js';
|
|
2
|
-
/**
|
|
3
|
-
* Will eventually contain helpers to get metadata about models, e.g. pricing.
|
|
4
|
-
*
|
|
5
|
-
* Represents a model identifier with optional provider and model name.
|
|
6
|
-
* Can parse strings like "openai/gpt-4" or just "gpt-4".
|
|
7
|
-
*/
|
|
8
|
-
export declare class ModelId {
|
|
9
|
-
readonly name: string;
|
|
10
|
-
readonly provider: string | null;
|
|
11
|
-
constructor(name: ModelIdentifier);
|
|
12
|
-
toString(): string;
|
|
13
|
-
toJSON(): string;
|
|
14
|
-
inspect(): string;
|
|
15
|
-
equals(other: ModelId | string): boolean;
|
|
16
|
-
columnName(includeProvider?: boolean): string;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=models.d.ts.map
|
package/esm/src/models.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/src/models.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAGlE;;;;;GAKG;AACH,qBAAa,OAAO;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;gBAErB,IAAI,EAAE,eAAe;IAYjC,QAAQ,IAAI,MAAM;IAOlB,MAAM,IAAI,MAAM;IAIhB,OAAO,IAAI,MAAM;IAIjB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO;IAUxC,UAAU,CAAC,eAAe,GAAE,OAAe,GAAG,MAAM;CAMpD"}
|
package/esm/src/models.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { cleanColumnName } from './utils.js';
|
|
2
|
-
/**
|
|
3
|
-
* Will eventually contain helpers to get metadata about models, e.g. pricing.
|
|
4
|
-
*
|
|
5
|
-
* Represents a model identifier with optional provider and model name.
|
|
6
|
-
* Can parse strings like "openai/gpt-4" or just "gpt-4".
|
|
7
|
-
*/
|
|
8
|
-
export class ModelId {
|
|
9
|
-
name;
|
|
10
|
-
provider;
|
|
11
|
-
constructor(name) {
|
|
12
|
-
if (!name.includes('/')) {
|
|
13
|
-
this.provider = null;
|
|
14
|
-
this.name = name.toLowerCase();
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
const parts = name.split('/', 2);
|
|
18
|
-
this.provider = parts[0];
|
|
19
|
-
this.name = parts[1];
|
|
20
|
-
}
|
|
21
|
-
toString() {
|
|
22
|
-
if (this.provider) {
|
|
23
|
-
return `${this.provider}/${this.name}`;
|
|
24
|
-
}
|
|
25
|
-
return this.name;
|
|
26
|
-
}
|
|
27
|
-
toJSON() {
|
|
28
|
-
return this.toString();
|
|
29
|
-
}
|
|
30
|
-
inspect() {
|
|
31
|
-
return `ModelId(provider=${JSON.stringify(this.provider)}, name=${JSON.stringify(this.name)})`;
|
|
32
|
-
}
|
|
33
|
-
equals(other) {
|
|
34
|
-
if (typeof other === 'string') {
|
|
35
|
-
return this.toString() === other;
|
|
36
|
-
}
|
|
37
|
-
if (other instanceof ModelId) {
|
|
38
|
-
return this.provider === other.provider && this.name === other.name;
|
|
39
|
-
}
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
columnName(includeProvider = false) {
|
|
43
|
-
if (includeProvider && this.provider) {
|
|
44
|
-
return cleanColumnName(`${this.provider}_${this.name}`);
|
|
45
|
-
}
|
|
46
|
-
return cleanColumnName(this.name);
|
|
47
|
-
}
|
|
48
|
-
}
|
package/esm/src/openai.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import OpenAI from 'openai';
|
|
2
|
-
import { z } from '../deps/jsr.io/@zod/zod/4.3.6/src/index.js';
|
|
3
|
-
export type AIConversation = Array<OpenAI.Responses.EasyInputMessage>;
|
|
4
|
-
export type AIParams = Omit<OpenAI.Responses.ResponseCreateParams, 'model' | 'input' | 'text'>;
|
|
5
|
-
export type AIOutput = Array<OpenAI.Responses.ResponseOutputItem>;
|
|
6
|
-
export type AIResult<T = string> = {
|
|
7
|
-
parsed: T | null;
|
|
8
|
-
output_text: string | null;
|
|
9
|
-
output: AIOutput | null;
|
|
10
|
-
error: Error | null;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Safely calls askOpenAI with retry logic.
|
|
14
|
-
* On each retry, prefixes the prompt with context about the previous failure.
|
|
15
|
-
*/
|
|
16
|
-
export declare function askOpenAISafe<T = string>(prompt: string | AIConversation, model: string, schema?: z.ZodType<T> | null, extraParams?: AIParams, maxRetries?: number, onError?: 'throw' | 'return'): Promise<AIResult<T>>;
|
|
17
|
-
//# sourceMappingURL=openai.d.ts.map
|
package/esm/src/openai.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/src/openai.ts"],"names":[],"mappings":"AAGA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,CAAC,EAAE,MAAM,4CAA4C,CAAC;AAE/D,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;AACtE,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,oBAAoB,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC,CAAC;AAC/F,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;AAElE,MAAM,MAAM,QAAQ,CAAC,CAAC,GAAG,MAAM,IAAI;IAClC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;IACjB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,MAAM,EAAE,QAAQ,GAAG,IAAI,CAAC;IACxB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACpB,CAAC;AAoFF;;;GAGG;AACH,wBAAsB,aAAa,CAAC,CAAC,GAAG,MAAM,EAC7C,MAAM,EAAE,MAAM,GAAG,cAAc,EAC/B,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,EAC5B,WAAW,CAAC,EAAE,QAAQ,EACtB,UAAU,GAAE,MAAU,EACtB,OAAO,GAAE,OAAO,GAAG,QAAkB,GACnC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAkEtB"}
|
package/esm/src/openai.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
/* eslint no-console: ["warn", { allow: ["log", "warn", "error"] }] */
|
|
2
|
-
import * as dntShim from "../_dnt.shims.js";
|
|
3
|
-
import OpenAI from 'openai';
|
|
4
|
-
import { z } from '../deps/jsr.io/@zod/zod/4.3.6/src/index.js';
|
|
5
|
-
async function askOpenAI(prompt, model, schema, extraParams, onError = 'throw') {
|
|
6
|
-
const openAIClient = new OpenAI({
|
|
7
|
-
apiKey: dntShim.Deno.env.get('OPENAI_API_KEY'),
|
|
8
|
-
fetchOptions: {
|
|
9
|
-
signal: dntShim.dntGlobalThis.abortSignal // Pass through abort signal if available
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
const { output_parsed, output_text, output } = await openAIClient.responses.parse({
|
|
13
|
-
...extraParams,
|
|
14
|
-
model,
|
|
15
|
-
input: Array.isArray(prompt) ? prompt : [{
|
|
16
|
-
role: 'user',
|
|
17
|
-
content: prompt
|
|
18
|
-
}],
|
|
19
|
-
...(schema != null ? {
|
|
20
|
-
text: {
|
|
21
|
-
format: getCachedZodTextFormat(schema, 'response')
|
|
22
|
-
}
|
|
23
|
-
} : {})
|
|
24
|
-
});
|
|
25
|
-
if (schema == null) {
|
|
26
|
-
return {
|
|
27
|
-
parsed: output_text,
|
|
28
|
-
output_text,
|
|
29
|
-
output
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
if (output_parsed instanceof Error && onError === 'throw') {
|
|
33
|
-
throw output_parsed;
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
parsed: output_parsed,
|
|
37
|
-
output_text,
|
|
38
|
-
output
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
class ZodValidationError extends Error {
|
|
42
|
-
}
|
|
43
|
-
;
|
|
44
|
-
/**
|
|
45
|
-
* Safely calls askOpenAI with retry logic.
|
|
46
|
-
* On each retry, prefixes the prompt with context about the previous failure.
|
|
47
|
-
*/
|
|
48
|
-
export async function askOpenAISafe(prompt, model, schema, extraParams, maxRetries = 3, onError = 'throw') {
|
|
49
|
-
let lastResult = null;
|
|
50
|
-
let currentPrompt = Array.isArray(prompt) ? prompt : [{
|
|
51
|
-
role: 'user',
|
|
52
|
-
content: prompt
|
|
53
|
-
}];
|
|
54
|
-
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
55
|
-
try {
|
|
56
|
-
const result = await askOpenAI(currentPrompt, model, schema, extraParams, 'return');
|
|
57
|
-
if (result.parsed instanceof Error) {
|
|
58
|
-
lastResult = {
|
|
59
|
-
parsed: null,
|
|
60
|
-
output_text: result.output_text,
|
|
61
|
-
output: result.output,
|
|
62
|
-
error: result.parsed
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
return {
|
|
67
|
-
parsed: result.parsed,
|
|
68
|
-
output_text: result.output_text,
|
|
69
|
-
output: result.output,
|
|
70
|
-
error: null
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
lastResult = {
|
|
76
|
-
parsed: null,
|
|
77
|
-
output_text: null,
|
|
78
|
-
output: null,
|
|
79
|
-
error: error instanceof Error ? error : new Error(JSON.stringify(error))
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
lastResult = lastResult;
|
|
83
|
-
if (attempt < maxRetries) {
|
|
84
|
-
let errorMessage;
|
|
85
|
-
if (lastResult.error instanceof ZodValidationError) {
|
|
86
|
-
errorMessage = `Previous attempt failed with Zod parsing error:\n${lastResult.error.message}.\nYour raw response was:\n${lastResult.output_text}.`;
|
|
87
|
-
currentPrompt = [
|
|
88
|
-
...currentPrompt,
|
|
89
|
-
{
|
|
90
|
-
role: 'system',
|
|
91
|
-
content: errorMessage
|
|
92
|
-
}
|
|
93
|
-
];
|
|
94
|
-
}
|
|
95
|
-
else if (lastResult.error instanceof Error) {
|
|
96
|
-
errorMessage = `Previous attempt failed with error: ${lastResult.error.message}`;
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
errorMessage = 'Previous attempt failed with an unknown error.';
|
|
100
|
-
}
|
|
101
|
-
console.log(`askOpenAISafe retrying! Previous attempt ${attempt + 1} failed with: ${errorMessage}`);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (onError === 'return') {
|
|
105
|
-
return lastResult;
|
|
106
|
-
}
|
|
107
|
-
throw lastResult.error;
|
|
108
|
-
}
|
|
109
|
-
const zodTextFormatCache = new Map();
|
|
110
|
-
function getCachedZodTextFormat(zodObject, name) {
|
|
111
|
-
const cached = zodTextFormatCache.get(zodObject);
|
|
112
|
-
if (cached && cached.name === name) {
|
|
113
|
-
return cached;
|
|
114
|
-
}
|
|
115
|
-
const format = zodTextFormat(zodObject, name);
|
|
116
|
-
zodTextFormatCache.set(zodObject, format);
|
|
117
|
-
return format;
|
|
118
|
-
}
|
|
119
|
-
function zodTextFormat(zodObject, name) {
|
|
120
|
-
return {
|
|
121
|
-
type: 'json_schema',
|
|
122
|
-
name,
|
|
123
|
-
strict: true,
|
|
124
|
-
schema: z.toJSONSchema(zodObject, { target: 'draft-7' }),
|
|
125
|
-
$brand: 'auto-parseable-response-format',
|
|
126
|
-
$parseRaw: (content) => {
|
|
127
|
-
try {
|
|
128
|
-
return zodObject.parse(JSON.parse(content));
|
|
129
|
-
}
|
|
130
|
-
catch (error) {
|
|
131
|
-
return new ZodValidationError(error instanceof Error ? error.message : String(error));
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
__output: undefined
|
|
135
|
-
};
|
|
136
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"seedKeywords.d.ts","sourceRoot":"","sources":["../../../src/src/tools/seedKeywords.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAGvF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAOpE,UAAU,iBAAiB;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,YA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OAAc,GACpC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAS/B;AAED;;;;;;;;GAQG;AACH,wBAAgB,6BAA6B,CAC5C,MAAM,EAAE,yBAAyB,EACjC,sBAAsB,GAAE,OAAc,GACpC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAG/B"}
|
package/esm/src/urls.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"urls.d.ts","sourceRoot":"","sources":["../../src/src/urls.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAQzC;AAaD;;;GAGG;AACH,wBAAgB,aAAa,CAC5B,GAAG,EAAE,MAAM,EACX,aAAa,GAAE,OAAe,EAC9B,sBAAsB,GAAE,OAAc,GACpC,MAAM,CA6BR"}
|
package/esm/src/utils.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH;;;GAGG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA8B3C;AAwCD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMpD;AAMD;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAoCrF;AAMD;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAYnE;AAMD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,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ChB,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GAC/C,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CA0BnB"}
|
package/script/src/models.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { ModelIdentifier } from './schemas/models.schema.js';
|
|
2
|
-
/**
|
|
3
|
-
* Will eventually contain helpers to get metadata about models, e.g. pricing.
|
|
4
|
-
*
|
|
5
|
-
* Represents a model identifier with optional provider and model name.
|
|
6
|
-
* Can parse strings like "openai/gpt-4" or just "gpt-4".
|
|
7
|
-
*/
|
|
8
|
-
export declare class ModelId {
|
|
9
|
-
readonly name: string;
|
|
10
|
-
readonly provider: string | null;
|
|
11
|
-
constructor(name: ModelIdentifier);
|
|
12
|
-
toString(): string;
|
|
13
|
-
toJSON(): string;
|
|
14
|
-
inspect(): string;
|
|
15
|
-
equals(other: ModelId | string): boolean;
|
|
16
|
-
columnName(includeProvider?: boolean): string;
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=models.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../src/src/models.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAGlE;;;;;GAKG;AACH,qBAAa,OAAO;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;gBAErB,IAAI,EAAE,eAAe;IAYjC,QAAQ,IAAI,MAAM;IAOlB,MAAM,IAAI,MAAM;IAIhB,OAAO,IAAI,MAAM;IAIjB,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO;IAUxC,UAAU,CAAC,eAAe,GAAE,OAAe,GAAG,MAAM;CAMpD"}
|
package/script/src/models.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModelId = void 0;
|
|
4
|
-
const utils_js_1 = require("./utils.js");
|
|
5
|
-
/**
|
|
6
|
-
* Will eventually contain helpers to get metadata about models, e.g. pricing.
|
|
7
|
-
*
|
|
8
|
-
* Represents a model identifier with optional provider and model name.
|
|
9
|
-
* Can parse strings like "openai/gpt-4" or just "gpt-4".
|
|
10
|
-
*/
|
|
11
|
-
class ModelId {
|
|
12
|
-
name;
|
|
13
|
-
provider;
|
|
14
|
-
constructor(name) {
|
|
15
|
-
if (!name.includes('/')) {
|
|
16
|
-
this.provider = null;
|
|
17
|
-
this.name = name.toLowerCase();
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const parts = name.split('/', 2);
|
|
21
|
-
this.provider = parts[0];
|
|
22
|
-
this.name = parts[1];
|
|
23
|
-
}
|
|
24
|
-
toString() {
|
|
25
|
-
if (this.provider) {
|
|
26
|
-
return `${this.provider}/${this.name}`;
|
|
27
|
-
}
|
|
28
|
-
return this.name;
|
|
29
|
-
}
|
|
30
|
-
toJSON() {
|
|
31
|
-
return this.toString();
|
|
32
|
-
}
|
|
33
|
-
inspect() {
|
|
34
|
-
return `ModelId(provider=${JSON.stringify(this.provider)}, name=${JSON.stringify(this.name)})`;
|
|
35
|
-
}
|
|
36
|
-
equals(other) {
|
|
37
|
-
if (typeof other === 'string') {
|
|
38
|
-
return this.toString() === other;
|
|
39
|
-
}
|
|
40
|
-
if (other instanceof ModelId) {
|
|
41
|
-
return this.provider === other.provider && this.name === other.name;
|
|
42
|
-
}
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
columnName(includeProvider = false) {
|
|
46
|
-
if (includeProvider && this.provider) {
|
|
47
|
-
return (0, utils_js_1.cleanColumnName)(`${this.provider}_${this.name}`);
|
|
48
|
-
}
|
|
49
|
-
return (0, utils_js_1.cleanColumnName)(this.name);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.ModelId = ModelId;
|
package/script/src/openai.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import OpenAI from 'openai';
|
|
2
|
-
import { z } from '../deps/jsr.io/@zod/zod/4.3.6/src/index.js';
|
|
3
|
-
export type AIConversation = Array<OpenAI.Responses.EasyInputMessage>;
|
|
4
|
-
export type AIParams = Omit<OpenAI.Responses.ResponseCreateParams, 'model' | 'input' | 'text'>;
|
|
5
|
-
export type AIOutput = Array<OpenAI.Responses.ResponseOutputItem>;
|
|
6
|
-
export type AIResult<T = string> = {
|
|
7
|
-
parsed: T | null;
|
|
8
|
-
output_text: string | null;
|
|
9
|
-
output: AIOutput | null;
|
|
10
|
-
error: Error | null;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Safely calls askOpenAI with retry logic.
|
|
14
|
-
* On each retry, prefixes the prompt with context about the previous failure.
|
|
15
|
-
*/
|
|
16
|
-
export declare function askOpenAISafe<T = string>(prompt: string | AIConversation, model: string, schema?: z.ZodType<T> | null, extraParams?: AIParams, maxRetries?: number, onError?: 'throw' | 'return'): Promise<AIResult<T>>;
|
|
17
|
-
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/src/openai.ts"],"names":[],"mappings":"AAGA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,CAAC,EAAE,MAAM,4CAA4C,CAAC;AAE/D,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;AACtE,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,oBAAoB,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC,CAAC;AAC/F,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC;AAElE,MAAM,MAAM,QAAQ,CAAC,CAAC,GAAG,MAAM,IAAI;IAClC,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC;IACjB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,MAAM,EAAE,QAAQ,GAAG,IAAI,CAAC;IACxB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACpB,CAAC;AAoFF;;;GAGG;AACH,wBAAsB,aAAa,CAAC,CAAC,GAAG,MAAM,EAC7C,MAAM,EAAE,MAAM,GAAG,cAAc,EAC/B,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,EAC5B,WAAW,CAAC,EAAE,QAAQ,EACtB,UAAU,GAAE,MAAU,EACtB,OAAO,GAAE,OAAO,GAAG,QAAkB,GACnC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAkEtB"}
|
package/script/src/openai.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.askOpenAISafe = askOpenAISafe;
|
|
40
|
-
/* eslint no-console: ["warn", { allow: ["log", "warn", "error"] }] */
|
|
41
|
-
const dntShim = __importStar(require("../_dnt.shims.js"));
|
|
42
|
-
const openai_1 = __importDefault(require("openai"));
|
|
43
|
-
const index_js_1 = require("../deps/jsr.io/@zod/zod/4.3.6/src/index.js");
|
|
44
|
-
async function askOpenAI(prompt, model, schema, extraParams, onError = 'throw') {
|
|
45
|
-
const openAIClient = new openai_1.default({
|
|
46
|
-
apiKey: dntShim.Deno.env.get('OPENAI_API_KEY'),
|
|
47
|
-
fetchOptions: {
|
|
48
|
-
signal: dntShim.dntGlobalThis.abortSignal // Pass through abort signal if available
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
const { output_parsed, output_text, output } = await openAIClient.responses.parse({
|
|
52
|
-
...extraParams,
|
|
53
|
-
model,
|
|
54
|
-
input: Array.isArray(prompt) ? prompt : [{
|
|
55
|
-
role: 'user',
|
|
56
|
-
content: prompt
|
|
57
|
-
}],
|
|
58
|
-
...(schema != null ? {
|
|
59
|
-
text: {
|
|
60
|
-
format: getCachedZodTextFormat(schema, 'response')
|
|
61
|
-
}
|
|
62
|
-
} : {})
|
|
63
|
-
});
|
|
64
|
-
if (schema == null) {
|
|
65
|
-
return {
|
|
66
|
-
parsed: output_text,
|
|
67
|
-
output_text,
|
|
68
|
-
output
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
if (output_parsed instanceof Error && onError === 'throw') {
|
|
72
|
-
throw output_parsed;
|
|
73
|
-
}
|
|
74
|
-
return {
|
|
75
|
-
parsed: output_parsed,
|
|
76
|
-
output_text,
|
|
77
|
-
output
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
class ZodValidationError extends Error {
|
|
81
|
-
}
|
|
82
|
-
;
|
|
83
|
-
/**
|
|
84
|
-
* Safely calls askOpenAI with retry logic.
|
|
85
|
-
* On each retry, prefixes the prompt with context about the previous failure.
|
|
86
|
-
*/
|
|
87
|
-
async function askOpenAISafe(prompt, model, schema, extraParams, maxRetries = 3, onError = 'throw') {
|
|
88
|
-
let lastResult = null;
|
|
89
|
-
let currentPrompt = Array.isArray(prompt) ? prompt : [{
|
|
90
|
-
role: 'user',
|
|
91
|
-
content: prompt
|
|
92
|
-
}];
|
|
93
|
-
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
94
|
-
try {
|
|
95
|
-
const result = await askOpenAI(currentPrompt, model, schema, extraParams, 'return');
|
|
96
|
-
if (result.parsed instanceof Error) {
|
|
97
|
-
lastResult = {
|
|
98
|
-
parsed: null,
|
|
99
|
-
output_text: result.output_text,
|
|
100
|
-
output: result.output,
|
|
101
|
-
error: result.parsed
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
return {
|
|
106
|
-
parsed: result.parsed,
|
|
107
|
-
output_text: result.output_text,
|
|
108
|
-
output: result.output,
|
|
109
|
-
error: null
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
catch (error) {
|
|
114
|
-
lastResult = {
|
|
115
|
-
parsed: null,
|
|
116
|
-
output_text: null,
|
|
117
|
-
output: null,
|
|
118
|
-
error: error instanceof Error ? error : new Error(JSON.stringify(error))
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
lastResult = lastResult;
|
|
122
|
-
if (attempt < maxRetries) {
|
|
123
|
-
let errorMessage;
|
|
124
|
-
if (lastResult.error instanceof ZodValidationError) {
|
|
125
|
-
errorMessage = `Previous attempt failed with Zod parsing error:\n${lastResult.error.message}.\nYour raw response was:\n${lastResult.output_text}.`;
|
|
126
|
-
currentPrompt = [
|
|
127
|
-
...currentPrompt,
|
|
128
|
-
{
|
|
129
|
-
role: 'system',
|
|
130
|
-
content: errorMessage
|
|
131
|
-
}
|
|
132
|
-
];
|
|
133
|
-
}
|
|
134
|
-
else if (lastResult.error instanceof Error) {
|
|
135
|
-
errorMessage = `Previous attempt failed with error: ${lastResult.error.message}`;
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
errorMessage = 'Previous attempt failed with an unknown error.';
|
|
139
|
-
}
|
|
140
|
-
console.log(`askOpenAISafe retrying! Previous attempt ${attempt + 1} failed with: ${errorMessage}`);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (onError === 'return') {
|
|
144
|
-
return lastResult;
|
|
145
|
-
}
|
|
146
|
-
throw lastResult.error;
|
|
147
|
-
}
|
|
148
|
-
const zodTextFormatCache = new Map();
|
|
149
|
-
function getCachedZodTextFormat(zodObject, name) {
|
|
150
|
-
const cached = zodTextFormatCache.get(zodObject);
|
|
151
|
-
if (cached && cached.name === name) {
|
|
152
|
-
return cached;
|
|
153
|
-
}
|
|
154
|
-
const format = zodTextFormat(zodObject, name);
|
|
155
|
-
zodTextFormatCache.set(zodObject, format);
|
|
156
|
-
return format;
|
|
157
|
-
}
|
|
158
|
-
function zodTextFormat(zodObject, name) {
|
|
159
|
-
return {
|
|
160
|
-
type: 'json_schema',
|
|
161
|
-
name,
|
|
162
|
-
strict: true,
|
|
163
|
-
schema: index_js_1.z.toJSONSchema(zodObject, { target: 'draft-7' }),
|
|
164
|
-
$brand: 'auto-parseable-response-format',
|
|
165
|
-
$parseRaw: (content) => {
|
|
166
|
-
try {
|
|
167
|
-
return zodObject.parse(JSON.parse(content));
|
|
168
|
-
}
|
|
169
|
-
catch (error) {
|
|
170
|
-
return new ZodValidationError(error instanceof Error ? error.message : String(error));
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
__output: undefined
|
|
174
|
-
};
|
|
175
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"seedKeywords.d.ts","sourceRoot":"","sources":["../../../src/src/tools/seedKeywords.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAGvF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAOpE,UAAU,iBAAiB;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CAC7B;AAED,UAAU,WAAW;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CAC7B;AAED,UAAU,kBAAkB;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CAC7B;AAED,UAAU,eAAe;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,KAAK,CAAC,kBAAkB,CAAC,CAAC;CACvC;AAED,UAAU,cAAc;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAA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Aa,CAC5B,GAAG,EAAE,MAAM,EACX,aAAa,GAAE,OAAe,EAC9B,sBAAsB,GAAE,OAAc,GACpC,MAAM,CA6BR"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/src/utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH;;;GAGG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA8B3C;AAwCD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMpD;AAMD;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAoCrF;AAMD;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAYnE;AAMD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5D,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,EACjB,KAAK,EAAE,MAAM,CAAC,GACZ,KAAK,CAAC,CAAC,CAAC,CAoBV;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,EACjB,KAAK,EAAE,MAAM,CAAC,GACZ,KAAK,CAAC,CAAC,CAAC,CAgBV"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|