@dromney/mapthis 0.1.0 → 0.2.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 +108 -27
- package/dist/ai/index.cjs +105 -1
- package/dist/ai/index.cjs.map +1 -1
- package/dist/ai/index.d.cts +9 -9
- package/dist/ai/index.d.ts +9 -9
- package/dist/ai/index.js +101 -2
- package/dist/ai/index.js.map +1 -1
- package/dist/{domain-Dc1wSTkf.d.cts → domain-CL4ro2YW.d.cts} +1 -1
- package/dist/{domain-CZ-L-ntu.d.ts → domain-Dh8cPBVp.d.ts} +1 -1
- package/dist/generate/index.cjs +1 -1
- package/dist/generate/index.cjs.map +1 -1
- package/dist/generate/index.d.cts +4 -4
- package/dist/generate/index.d.ts +4 -4
- package/dist/generate/index.js +1 -1
- package/dist/generate/index.js.map +1 -1
- package/dist/geocoding/index.d.cts +3 -3
- package/dist/geocoding/index.d.ts +3 -3
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/parser-CrG1A6dD.d.ts +176 -0
- package/dist/parser-DsIwIsHK.d.cts +176 -0
- package/dist/react/index.d.cts +197 -0
- package/dist/react/index.d.ts +197 -0
- package/dist/{schemas-Dy5coqXo.d.cts → schemas-CZao45EU.d.cts} +1 -1
- package/dist/{schemas-Dy5coqXo.d.ts → schemas-CZao45EU.d.ts} +1 -1
- package/dist/types/index.cjs +1 -1
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.js +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/{types-BhqKlq0k.d.ts → types-BhPqZwOj.d.ts} +2 -2
- package/dist/{types-rFjK5YcJ.d.cts → types-C-xqh9Sh.d.cts} +2 -2
- package/dist/utils/index.d.cts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/package.json +10 -6
- package/dist/parser-CzXzpmVv.d.cts +0 -111
- package/dist/parser-N7-fNxeu.d.ts +0 -111
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dromney/mapthis",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Open-source location intelligence: parse freeform text, HTML, and URLs into geocoded locations, with types and React components.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Dallin Romney",
|
|
@@ -91,19 +91,21 @@
|
|
|
91
91
|
"clean": "rm -rf dist",
|
|
92
92
|
"prepublishOnly": "npm run clean && npm run typecheck && npm test && npm run build"
|
|
93
93
|
},
|
|
94
|
-
"dependencies": {
|
|
95
|
-
"zod": "^3.22.4"
|
|
96
|
-
},
|
|
97
94
|
"peerDependencies": {
|
|
95
|
+
"@anthropic-ai/sdk": "^0.30.0",
|
|
98
96
|
"@googlemaps/google-maps-services-js": "^3.3.42",
|
|
99
97
|
"@vis.gl/react-google-maps": "^0.5.0",
|
|
100
98
|
"html-to-text": "^9.0.5",
|
|
101
99
|
"js-tiktoken": "^1.0.19",
|
|
102
100
|
"openai": "^4.26.0",
|
|
103
101
|
"react": "^18.2.0 || ^19.0.0",
|
|
104
|
-
"react-dom": "^18.2.0 || ^19.0.0"
|
|
102
|
+
"react-dom": "^18.2.0 || ^19.0.0",
|
|
103
|
+
"zod": "^3.22.4"
|
|
105
104
|
},
|
|
106
105
|
"peerDependenciesMeta": {
|
|
106
|
+
"@anthropic-ai/sdk": {
|
|
107
|
+
"optional": true
|
|
108
|
+
},
|
|
107
109
|
"@googlemaps/google-maps-services-js": {
|
|
108
110
|
"optional": true
|
|
109
111
|
},
|
|
@@ -127,6 +129,7 @@
|
|
|
127
129
|
}
|
|
128
130
|
},
|
|
129
131
|
"devDependencies": {
|
|
132
|
+
"@anthropic-ai/sdk": "^0.30.1",
|
|
130
133
|
"@googlemaps/google-maps-services-js": "^3.3.42",
|
|
131
134
|
"@types/google.maps": "^3.55.1",
|
|
132
135
|
"@types/html-to-text": "^9.0.4",
|
|
@@ -142,7 +145,8 @@
|
|
|
142
145
|
"react-dom": "^18.2.0",
|
|
143
146
|
"tsup": "^8.0.0",
|
|
144
147
|
"typescript": "^5.3.3",
|
|
145
|
-
"vitest": "^1.2.0"
|
|
148
|
+
"vitest": "^1.2.0",
|
|
149
|
+
"zod": "3.25.76"
|
|
146
150
|
},
|
|
147
151
|
"engines": {
|
|
148
152
|
"node": ">=18"
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { JSONSchema7Object } from 'json-schema';
|
|
2
|
-
import { a as ParsedLocations } from './domain-Dc1wSTkf.cjs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Generic LLM output envelope with token accounting.
|
|
6
|
-
*/
|
|
7
|
-
interface OpenAIOutput<T> {
|
|
8
|
-
output: T;
|
|
9
|
-
inputTokens: number;
|
|
10
|
-
outputTokens: number;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Request shape for a function-calling JSON completion.
|
|
14
|
-
*/
|
|
15
|
-
interface GenericAIJsonRequest {
|
|
16
|
-
schema: JSONSchema7Object;
|
|
17
|
-
systemMessage: string;
|
|
18
|
-
userMessage: string;
|
|
19
|
-
functionName: string;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Result of summarizing a text blob prior to a final extraction call.
|
|
23
|
-
*/
|
|
24
|
-
interface SummarizedText {
|
|
25
|
-
text: string;
|
|
26
|
-
textTokens: number;
|
|
27
|
-
summarized: string;
|
|
28
|
-
summarizedTokens: number;
|
|
29
|
-
chunks: number;
|
|
30
|
-
inputTokens: number;
|
|
31
|
-
outputTokens: number;
|
|
32
|
-
summarizePromptVersion: string;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Result of parsing locations from any source. Includes full token
|
|
36
|
-
* accounting so callers can bill usage to their own users.
|
|
37
|
-
*/
|
|
38
|
-
interface GetLocationsResponse {
|
|
39
|
-
output: ParsedLocations;
|
|
40
|
-
textTokens: number;
|
|
41
|
-
summarizedTokens: number;
|
|
42
|
-
summaryInputTokens: number;
|
|
43
|
-
summaryOutputTokens: number;
|
|
44
|
-
locationInputTokens: number;
|
|
45
|
-
locationOutputTokens: number;
|
|
46
|
-
inputTokens: number;
|
|
47
|
-
outputTokens: number;
|
|
48
|
-
summaryPromptVersion: string;
|
|
49
|
-
locationPromptVersion: string;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
declare const DEFAULT_MODEL = "gpt-4o-mini";
|
|
53
|
-
declare const DEFAULT_TOKEN_LIMIT = 128000;
|
|
54
|
-
/**
|
|
55
|
-
* An OpenAI-backed inference context shared by the summarizer and location
|
|
56
|
-
* parser. Instances are produced by {@link createOpenAiBackend} so API keys
|
|
57
|
-
* and model choices live in the consumer's code, never in module-level state.
|
|
58
|
-
*/
|
|
59
|
-
interface OpenAiBackend {
|
|
60
|
-
readonly model: string;
|
|
61
|
-
readonly tokenLimit: number;
|
|
62
|
-
countTokens(text: string): number;
|
|
63
|
-
chatCompletion(content: string): Promise<OpenAIOutput<string>>;
|
|
64
|
-
chatFunctionJson<T>(systemMessage: string, userMessage: string, schema: JSONSchema7Object, functionName: string): Promise<OpenAIOutput<T>>;
|
|
65
|
-
}
|
|
66
|
-
interface OpenAiBackendConfig {
|
|
67
|
-
/** OpenAI API key. Passed directly to the SDK. */
|
|
68
|
-
apiKey: string;
|
|
69
|
-
/** Model name passed to the completions API. Defaults to `gpt-4o-mini`. */
|
|
70
|
-
model?: string;
|
|
71
|
-
/** Context-window budget used by the summarizer. Defaults to 128k. */
|
|
72
|
-
tokenLimit?: number;
|
|
73
|
-
/**
|
|
74
|
-
* Optional base URL for the OpenAI API. Use this to route through an
|
|
75
|
-
* OpenAI-compatible gateway (Azure, Together, etc.).
|
|
76
|
-
*/
|
|
77
|
-
baseURL?: string;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Construct an {@link OpenAiBackend} bound to a specific API key and model.
|
|
81
|
-
*/
|
|
82
|
-
declare function createOpenAiBackend(config: OpenAiBackendConfig): OpenAiBackend;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* A configured location-extraction pipeline. Hold onto one of these for the
|
|
86
|
-
* lifetime of your app — it wraps an OpenAI client and a tiktoken encoder.
|
|
87
|
-
*/
|
|
88
|
-
interface LocationParser {
|
|
89
|
-
parseLocationsFromText(text: string): Promise<GetLocationsResponse>;
|
|
90
|
-
parseLocationsFromHtml(html: string): Promise<GetLocationsResponse>;
|
|
91
|
-
parseLocationsFromUrl(url: string): Promise<GetLocationsResponse>;
|
|
92
|
-
}
|
|
93
|
-
type LocationParserConfig = OpenAiBackendConfig;
|
|
94
|
-
/**
|
|
95
|
-
* Create a {@link LocationParser} bound to an OpenAI API key.
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* ```ts
|
|
99
|
-
* const parser = createLocationParser({
|
|
100
|
-
* apiKey: process.env.OPENAI_API_KEY!,
|
|
101
|
-
* model: "gpt-4o-mini",
|
|
102
|
-
* })
|
|
103
|
-
* const { output } = await parser.parseLocationsFromUrl(
|
|
104
|
-
* "https://example.com/best-restaurants-tokyo",
|
|
105
|
-
* )
|
|
106
|
-
* console.log(output.title, output.locations)
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
declare function createLocationParser(config: LocationParserConfig): LocationParser;
|
|
110
|
-
|
|
111
|
-
export { DEFAULT_MODEL as D, type GetLocationsResponse as G, type LocationParser as L, type OpenAiBackend as O, type SummarizedText as S, DEFAULT_TOKEN_LIMIT as a, type GenericAIJsonRequest as b, type LocationParserConfig as c, type OpenAIOutput as d, type OpenAiBackendConfig as e, createLocationParser as f, createOpenAiBackend as g };
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { JSONSchema7Object } from 'json-schema';
|
|
2
|
-
import { a as ParsedLocations } from './domain-CZ-L-ntu.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Generic LLM output envelope with token accounting.
|
|
6
|
-
*/
|
|
7
|
-
interface OpenAIOutput<T> {
|
|
8
|
-
output: T;
|
|
9
|
-
inputTokens: number;
|
|
10
|
-
outputTokens: number;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Request shape for a function-calling JSON completion.
|
|
14
|
-
*/
|
|
15
|
-
interface GenericAIJsonRequest {
|
|
16
|
-
schema: JSONSchema7Object;
|
|
17
|
-
systemMessage: string;
|
|
18
|
-
userMessage: string;
|
|
19
|
-
functionName: string;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Result of summarizing a text blob prior to a final extraction call.
|
|
23
|
-
*/
|
|
24
|
-
interface SummarizedText {
|
|
25
|
-
text: string;
|
|
26
|
-
textTokens: number;
|
|
27
|
-
summarized: string;
|
|
28
|
-
summarizedTokens: number;
|
|
29
|
-
chunks: number;
|
|
30
|
-
inputTokens: number;
|
|
31
|
-
outputTokens: number;
|
|
32
|
-
summarizePromptVersion: string;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Result of parsing locations from any source. Includes full token
|
|
36
|
-
* accounting so callers can bill usage to their own users.
|
|
37
|
-
*/
|
|
38
|
-
interface GetLocationsResponse {
|
|
39
|
-
output: ParsedLocations;
|
|
40
|
-
textTokens: number;
|
|
41
|
-
summarizedTokens: number;
|
|
42
|
-
summaryInputTokens: number;
|
|
43
|
-
summaryOutputTokens: number;
|
|
44
|
-
locationInputTokens: number;
|
|
45
|
-
locationOutputTokens: number;
|
|
46
|
-
inputTokens: number;
|
|
47
|
-
outputTokens: number;
|
|
48
|
-
summaryPromptVersion: string;
|
|
49
|
-
locationPromptVersion: string;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
declare const DEFAULT_MODEL = "gpt-4o-mini";
|
|
53
|
-
declare const DEFAULT_TOKEN_LIMIT = 128000;
|
|
54
|
-
/**
|
|
55
|
-
* An OpenAI-backed inference context shared by the summarizer and location
|
|
56
|
-
* parser. Instances are produced by {@link createOpenAiBackend} so API keys
|
|
57
|
-
* and model choices live in the consumer's code, never in module-level state.
|
|
58
|
-
*/
|
|
59
|
-
interface OpenAiBackend {
|
|
60
|
-
readonly model: string;
|
|
61
|
-
readonly tokenLimit: number;
|
|
62
|
-
countTokens(text: string): number;
|
|
63
|
-
chatCompletion(content: string): Promise<OpenAIOutput<string>>;
|
|
64
|
-
chatFunctionJson<T>(systemMessage: string, userMessage: string, schema: JSONSchema7Object, functionName: string): Promise<OpenAIOutput<T>>;
|
|
65
|
-
}
|
|
66
|
-
interface OpenAiBackendConfig {
|
|
67
|
-
/** OpenAI API key. Passed directly to the SDK. */
|
|
68
|
-
apiKey: string;
|
|
69
|
-
/** Model name passed to the completions API. Defaults to `gpt-4o-mini`. */
|
|
70
|
-
model?: string;
|
|
71
|
-
/** Context-window budget used by the summarizer. Defaults to 128k. */
|
|
72
|
-
tokenLimit?: number;
|
|
73
|
-
/**
|
|
74
|
-
* Optional base URL for the OpenAI API. Use this to route through an
|
|
75
|
-
* OpenAI-compatible gateway (Azure, Together, etc.).
|
|
76
|
-
*/
|
|
77
|
-
baseURL?: string;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Construct an {@link OpenAiBackend} bound to a specific API key and model.
|
|
81
|
-
*/
|
|
82
|
-
declare function createOpenAiBackend(config: OpenAiBackendConfig): OpenAiBackend;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* A configured location-extraction pipeline. Hold onto one of these for the
|
|
86
|
-
* lifetime of your app — it wraps an OpenAI client and a tiktoken encoder.
|
|
87
|
-
*/
|
|
88
|
-
interface LocationParser {
|
|
89
|
-
parseLocationsFromText(text: string): Promise<GetLocationsResponse>;
|
|
90
|
-
parseLocationsFromHtml(html: string): Promise<GetLocationsResponse>;
|
|
91
|
-
parseLocationsFromUrl(url: string): Promise<GetLocationsResponse>;
|
|
92
|
-
}
|
|
93
|
-
type LocationParserConfig = OpenAiBackendConfig;
|
|
94
|
-
/**
|
|
95
|
-
* Create a {@link LocationParser} bound to an OpenAI API key.
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* ```ts
|
|
99
|
-
* const parser = createLocationParser({
|
|
100
|
-
* apiKey: process.env.OPENAI_API_KEY!,
|
|
101
|
-
* model: "gpt-4o-mini",
|
|
102
|
-
* })
|
|
103
|
-
* const { output } = await parser.parseLocationsFromUrl(
|
|
104
|
-
* "https://example.com/best-restaurants-tokyo",
|
|
105
|
-
* )
|
|
106
|
-
* console.log(output.title, output.locations)
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
declare function createLocationParser(config: LocationParserConfig): LocationParser;
|
|
110
|
-
|
|
111
|
-
export { DEFAULT_MODEL as D, type GetLocationsResponse as G, type LocationParser as L, type OpenAiBackend as O, type SummarizedText as S, DEFAULT_TOKEN_LIMIT as a, type GenericAIJsonRequest as b, type LocationParserConfig as c, type OpenAIOutput as d, type OpenAiBackendConfig as e, createLocationParser as f, createOpenAiBackend as g };
|