@xyz17711/emoji-match 0.1.0 → 0.1.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/README.md +8 -5
- package/dist/index.d.ts +10 -1
- package/dist/index.js +9 -1
- package/dist/langchain.js +1 -1
- package/package.json +30 -2
- package/src/index.ts +0 -27
- package/src/langchain.ts +0 -28
- package/test/index.test.mjs +0 -24
- package/test/langchain.test.mjs +0 -16
- package/tsconfig.json +0 -16
package/README.md
CHANGED
|
@@ -18,17 +18,20 @@ npm install @xyz17711/emoji-match
|
|
|
18
18
|
|
|
19
19
|
| Method | Description |
|
|
20
20
|
| --- | --- |
|
|
21
|
-
| `suggestEmojis` |
|
|
21
|
+
| `suggestEmojis` | Emoji suggestion API: text in 18 languages in, the 1 to 5 best matching emoji out, deterministic and fast ($0.002, x402) |
|
|
22
22
|
|
|
23
23
|
## Quickstart
|
|
24
24
|
|
|
25
25
|
```typescript
|
|
26
26
|
import { Client } from "@xyz17711/emoji-match";
|
|
27
27
|
|
|
28
|
-
const client = new Client(
|
|
28
|
+
const client = new Client(); // talks to https://api.17711.xyz/registry/emoji-match-service by default
|
|
29
29
|
// see the Methods table above for every available call and its request/response type
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
+
Pass another base URL (self-hosted instance, test server) as the first argument:
|
|
33
|
+
`new Client("https://my-host.example/registry/emoji-match-service")`.
|
|
34
|
+
|
|
32
35
|
## Paying past the free quota
|
|
33
36
|
|
|
34
37
|
Every gated tool allows a small number of free calls per day; beyond that it returns a 402
|
|
@@ -38,7 +41,7 @@ network, and payee address attached:
|
|
|
38
41
|
```typescript
|
|
39
42
|
import { Client, PaymentRequiredError } from "@xyz17711/emoji-match";
|
|
40
43
|
|
|
41
|
-
const client = new Client(
|
|
44
|
+
const client = new Client();
|
|
42
45
|
try {
|
|
43
46
|
await client.suggestEmojis(/* ... */);
|
|
44
47
|
} catch (e) {
|
|
@@ -54,7 +57,7 @@ own environment/secrets manager, never a literal string in source code:
|
|
|
54
57
|
```typescript
|
|
55
58
|
import { Client } from "@xyz17711/emoji-match";
|
|
56
59
|
|
|
57
|
-
const client = new Client(
|
|
60
|
+
const client = new Client({
|
|
58
61
|
x402PrivateKey: process.env.X402_PRIVATE_KEY,
|
|
59
62
|
x402ExpectedNetwork: "eip155:8453", // Base mainnet; use eip155:84532 for Base Sepolia testnet
|
|
60
63
|
x402MaxPaymentUsdc: 0.01, // refuse any single call above this
|
|
@@ -73,7 +76,7 @@ with that same key in this process.
|
|
|
73
76
|
import { Client } from "@xyz17711/emoji-match";
|
|
74
77
|
import { EmojiMatchToolkit } from "@xyz17711/emoji-match/langchain";
|
|
75
78
|
|
|
76
|
-
const client = new Client(
|
|
79
|
+
const client = new Client({ /* ...wallet options... */ });
|
|
77
80
|
const tools = new EmojiMatchToolkit(client).getTools();
|
|
78
81
|
```
|
|
79
82
|
|
package/dist/index.d.ts
CHANGED
|
@@ -12,9 +12,18 @@ export interface SuggestEmojisRequest {
|
|
|
12
12
|
/** The text to analyze. Works best in English or French; best-effort for 16 other languages (see the tool's own description). Truncated to a reasonable length before analysis if very long -- the response reflects the truncated text, not the full input. */
|
|
13
13
|
text: string;
|
|
14
14
|
}
|
|
15
|
+
/** Production base URL of this service; pass another to self-host or test. */
|
|
16
|
+
export declare const DEFAULT_BASE_URL = "https://api.17711.xyz/registry/emoji-match-service";
|
|
15
17
|
/** Typed client for emoji-match-service, e.g. `client.suggestEmojis(...)`. */
|
|
16
18
|
export declare class Client extends BaseClient {
|
|
17
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* `new Client()` talks to the production service. Pass a base URL to target another
|
|
21
|
+
* instance, and/or wallet options (`new Client({ x402PrivateKey, ... })`) to pay past the
|
|
22
|
+
* free quota automatically.
|
|
23
|
+
*/
|
|
24
|
+
constructor(options?: ClientOptions);
|
|
25
|
+
constructor(baseUrl?: string, options?: ClientOptions);
|
|
26
|
+
/** Emoji suggestion API: text in 18 languages in, the 1 to 5 best matching emoji out, deterministic and fast ($0.002, x402) */
|
|
18
27
|
suggestEmojis(request: SuggestEmojisRequest): Promise<SuggestEmojisResponse>;
|
|
19
28
|
}
|
|
20
29
|
export { ClientOptions };
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,17 @@
|
|
|
2
2
|
* Typed HTTP client and request/response interfaces for emoji-match-service.
|
|
3
3
|
*/
|
|
4
4
|
import { Client as BaseClient } from "@xyz17711/core";
|
|
5
|
+
/** Production base URL of this service; pass another to self-host or test. */
|
|
6
|
+
export const DEFAULT_BASE_URL = "https://api.17711.xyz/registry/emoji-match-service";
|
|
5
7
|
/** Typed client for emoji-match-service, e.g. `client.suggestEmojis(...)`. */
|
|
6
8
|
export class Client extends BaseClient {
|
|
7
|
-
|
|
9
|
+
constructor(baseUrlOrOptions, options = {}) {
|
|
10
|
+
const [url, opts] = typeof baseUrlOrOptions === "object"
|
|
11
|
+
? [DEFAULT_BASE_URL, baseUrlOrOptions]
|
|
12
|
+
: [baseUrlOrOptions ?? DEFAULT_BASE_URL, options];
|
|
13
|
+
super(url, opts);
|
|
14
|
+
}
|
|
15
|
+
/** Emoji suggestion API: text in 18 languages in, the 1 to 5 best matching emoji out, deterministic and fast ($0.002, x402) */
|
|
8
16
|
async suggestEmojis(request) {
|
|
9
17
|
return this.post("/v1/emoji-match/suggest_emojis", request);
|
|
10
18
|
}
|
package/dist/langchain.js
CHANGED
|
@@ -11,7 +11,7 @@ export class EmojiMatchToolkit {
|
|
|
11
11
|
return [
|
|
12
12
|
tool(async (input) => this.client.suggestEmojis(input), {
|
|
13
13
|
name: "suggestEmojis",
|
|
14
|
-
description: "
|
|
14
|
+
description: "Emoji suggestion API: text in 18 languages in, the 1 to 5 best matching emoji out, deterministic and fast ($0.002, x402)",
|
|
15
15
|
schema: z.object({ text: z.string() }),
|
|
16
16
|
}),
|
|
17
17
|
];
|
package/package.json
CHANGED
|
@@ -1,7 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xyz17711/emoji-match",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Typed TypeScript client for the 17711.xyz Emoji Match API: pay-per-call, settled in USDC via x402.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "17711 Services",
|
|
7
|
+
"homepage": "https://api.17711.xyz",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/17711-services/clients.git",
|
|
11
|
+
"directory": "node/packages/emoji-match"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/17711-services/clients/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"x402",
|
|
18
|
+
"usdc",
|
|
19
|
+
"api-client",
|
|
20
|
+
"pay-per-call",
|
|
21
|
+
"ai-agents",
|
|
22
|
+
"mcp",
|
|
23
|
+
"langchain",
|
|
24
|
+
"emoji-match"
|
|
25
|
+
],
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
5
33
|
"type": "module",
|
|
6
34
|
"main": "dist/index.js",
|
|
7
35
|
"types": "dist/index.d.ts",
|
package/src/index.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Typed HTTP client and request/response interfaces for emoji-match-service.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { Client as BaseClient, type ClientOptions } from "@xyz17711/core";
|
|
6
|
-
|
|
7
|
-
export interface SuggestEmojisResponse {
|
|
8
|
-
/** 1 to 5 emoji matching the text's lexicon/meaning, most relevant first. */
|
|
9
|
-
emojis: string[];
|
|
10
|
-
/** Which language (ISO 639-1 code, e.g. "en"/"fr") the best match was found in -- the input is stemmed and scored against every supported language, and this reports which one actually produced the result, useful to gauge match confidence for an unfamiliar language. */
|
|
11
|
-
matched_language: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface SuggestEmojisRequest {
|
|
15
|
-
/** The text to analyze. Works best in English or French; best-effort for 16 other languages (see the tool's own description). Truncated to a reasonable length before analysis if very long -- the response reflects the truncated text, not the full input. */
|
|
16
|
-
text: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** Typed client for emoji-match-service, e.g. `client.suggestEmojis(...)`. */
|
|
20
|
-
export class Client extends BaseClient {
|
|
21
|
-
/** Suggests 1-5 emoji matching a text's lexicon, English/French best-supported ($0.001, x402) */
|
|
22
|
-
async suggestEmojis(request: SuggestEmojisRequest): Promise<SuggestEmojisResponse> {
|
|
23
|
-
return this.post<SuggestEmojisResponse>("/v1/emoji-match/suggest_emojis", request);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export { ClientOptions };
|
package/src/langchain.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LangChain.js tools for emoji-match-service, grouped in one Toolkit -- one tool per operation, each just an async function (JS has no separate sync form to generate). Requires the `@langchain/core`+`zod` peer dependencies declared in this package's own package.json -- imported from `emoji-match/langchain`, never from the package root, so importing the base client never requires them installed.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { tool } from "@langchain/core/tools";
|
|
6
|
-
import { z } from "zod";
|
|
7
|
-
import { Client } from "./index.js";
|
|
8
|
-
|
|
9
|
-
export class EmojiMatchToolkit {
|
|
10
|
-
private client: Client;
|
|
11
|
-
|
|
12
|
-
constructor(client: Client) {
|
|
13
|
-
this.client = client;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
getTools() {
|
|
17
|
-
return [
|
|
18
|
-
tool(
|
|
19
|
-
async (input) => this.client.suggestEmojis(input),
|
|
20
|
-
{
|
|
21
|
-
name: "suggestEmojis",
|
|
22
|
-
description: "Suggests 1-5 emoji matching a text's lexicon, English/French best-supported ($0.001, x402)",
|
|
23
|
-
schema: z.object({ text: z.string() }),
|
|
24
|
-
},
|
|
25
|
-
),
|
|
26
|
-
];
|
|
27
|
-
}
|
|
28
|
-
}
|
package/test/index.test.mjs
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Verifies every emoji-match client method sends a request to the expected path/HTTP verb and parses a well-formed response -- one test per operation, real fetch mocked via a plain reassignment of `globalThis.fetch` (no extra test/mocking dependency). Runs against the COMPILED package (`../dist/index.js`) -- build before testing.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { test } from "node:test";
|
|
6
|
-
import assert from "node:assert/strict";
|
|
7
|
-
import { Client } from "../dist/index.js";
|
|
8
|
-
|
|
9
|
-
test("suggestEmojis calls the expected path", async () => {
|
|
10
|
-
const originalFetch = globalThis.fetch;
|
|
11
|
-
globalThis.fetch = async (url, init = {}) => {
|
|
12
|
-
const parsed = new URL(url);
|
|
13
|
-
assert.equal((init.method ?? "GET").toUpperCase(), "POST");
|
|
14
|
-
assert.equal(parsed.pathname, "/v1/emoji-match/suggest_emojis");
|
|
15
|
-
return new Response(JSON.stringify({ emojis: [], matched_language: "test" }), { status: 200 });
|
|
16
|
-
};
|
|
17
|
-
try {
|
|
18
|
-
const client = new Client("https://example.test");
|
|
19
|
-
const result = await client.suggestEmojis({ text: "test" });
|
|
20
|
-
assert.ok(result !== undefined);
|
|
21
|
-
} finally {
|
|
22
|
-
globalThis.fetch = originalFetch;
|
|
23
|
-
}
|
|
24
|
-
});
|
package/test/langchain.test.mjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Verifies every emoji-match LangChain tool through the real StructuredTool (`.invoke()`), not just the underlying client method -- catches schema-shape bugs a plain client-method test would miss. Requires the `langchain`/`zod` dev dependencies.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { test } from "node:test";
|
|
6
|
-
import assert from "node:assert/strict";
|
|
7
|
-
import { Client } from "../dist/index.js";
|
|
8
|
-
import { EmojiMatchToolkit } from "../dist/langchain.js";
|
|
9
|
-
|
|
10
|
-
test("suggestEmojis tool invoke", async () => {
|
|
11
|
-
globalThis.fetch = async () => new Response(JSON.stringify({ emojis: [], matched_language: "test" }), { status: 200 });
|
|
12
|
-
const toolkit = new EmojiMatchToolkit(new Client("https://example.test"));
|
|
13
|
-
const t = toolkit.getTools().find((x) => x.name === "suggestEmojis");
|
|
14
|
-
const result = await t.invoke({ text: "test" });
|
|
15
|
-
assert.ok(result !== undefined);
|
|
16
|
-
});
|
package/tsconfig.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "ES2020",
|
|
5
|
-
"moduleResolution": "bundler",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"outDir": "dist",
|
|
8
|
-
"rootDir": "src",
|
|
9
|
-
"strict": true,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"skipLibCheck": true
|
|
12
|
-
},
|
|
13
|
-
"include": [
|
|
14
|
-
"src"
|
|
15
|
-
]
|
|
16
|
-
}
|