@mappa-ai/mappa-node 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Plus Five Five, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,85 @@
1
+ # Mappa Node SDK
2
+
3
+ A lightweight JavaScript/TypeScript client for the Mappa API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install mappa-node
9
+ # or
10
+ yarn add mappa-node
11
+ # or
12
+ pnpm install mappa-node
13
+ # or
14
+ bun add mappa-node
15
+ ```
16
+
17
+ ## Requirements
18
+
19
+ - A valid Mappa API key.
20
+
21
+ ## Authentication
22
+
23
+ Set the `MAPPA_API_KEY` environment variable or pass the key directly:
24
+
25
+ ```bash
26
+ export MAPPA_API_KEY="your-api-key"
27
+ ```
28
+
29
+ ```ts
30
+ import { Mappa } from "mappa-node";
31
+
32
+ const client = new Mappa("your-api-key");
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ ### Instantiate the client
38
+
39
+ ```ts
40
+ import { Mappa } from "mappa-node";
41
+
42
+ const mappa = new Mappa(); // Reads MAPPA_API_KEY by default
43
+ ```
44
+
45
+ ### Generate a behavior profile from a remote URL
46
+
47
+ ```ts
48
+ await mappa.generateTextReport({
49
+ inputMedia: {
50
+ kind: "url",
51
+ url: "https://example.com/media.mp3",
52
+ },
53
+ targetSpeaker: { strategy: "dominant" },
54
+ });
55
+ ```
56
+
57
+ ### Generate a behavior profile from an uploaded file
58
+
59
+ ```ts
60
+ const file = new File([buffer], "sample.wav", { type: "audio/wav" });
61
+
62
+ await mappa.generateTextReport({
63
+ inputMedia: {
64
+ kind: "file",
65
+ file,
66
+ },
67
+ targetSpeaker: {
68
+ strategy: "magic_hint",
69
+ hint: "the person being interviewed",
70
+ },
71
+ });
72
+ ```
73
+
74
+ The method returns:
75
+
76
+ ```ts
77
+ {
78
+ behaviorProfile: string;
79
+ entityId: string;
80
+ }
81
+ ```
82
+
83
+ ## License
84
+
85
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ let e=require(`zod`);var t=class{async generateReport(){return``}};async function n(e,t=3){let n;for(let r=0;r<t;r++)try{return await e()}catch(e){console.warn(`Attempt ${r+1} failed. Retrying...`),n=e}throw n}let r;(function(t){t.availablePresetsSchema=e.z.enum([`base`])})(r||={});let i;(function(t){t.generateReportInputSchema=e.z.object({inputMedia:e.z.discriminatedUnion(`kind`,[e.z.object({kind:e.z.literal(`file`),file:e.z.file().mime([`video/*`,`audio/*`],{message:`Invalid file type, only audio and video files are allowed`}).describe(`The audio file to be processed`)}),e.z.object({kind:e.z.literal(`url`),url:e.z.url().describe(`The URL of the audio or video file to be processed`)})]),targetSpeaker:e.z.discriminatedUnion(`strategy`,[e.z.object({strategy:e.z.literal(`dominant`).describe(`Select the speaker who speaks the most in the audio`)}),e.z.object({strategy:e.z.literal(`magic_hint`).describe(`Use a hint to identify the target speaker`),hint:e.z.string().describe(`A hint to help identify the target speaker, e.g., 'the interviewer', 'the CEO', 'the person being interviewed`)})]).default({strategy:`dominant`}).describe(`Strategy for target extraction, this is useful when there are multiple speakers in the audio`),template:r.availablePresetsSchema}),t.generateReportOutputSchema=e.z.object({outputs:e.z.object({entity_id:e.z.string().describe(`The unique identifier for the analyzed entity`),behavior_profile:e.z.string().describe(`The generated behavior profile report`)}).array().transform(e=>e[0]??null)})})(i||={});var a=class{apiKey;apiBaseUrl=`https://api.mappa.ai`;apiVersion=`v1`;presets=new t;constructor(e){if(!e&&typeof process<`u`&&process.env&&process.env.MAPPA_API_KEY?.trim()!==``&&(this.apiKey=process.env.MAPPA_API_KEY||``),this.apiKey=e||``,this.apiKey.trim()===``)throw Error(`Mappa API key is required`)}async generateTextReport(e){let t;if(e.inputMedia.kind===`file`){let r=new FormData;r.append(`file`,e.inputMedia.file),r.append(`metadata`,JSON.stringify({mode:`sync`,output:`behavior_profile`,target:e.targetSpeaker})),t=await n(()=>fetch(`${this.apiBaseUrl}/${this.apiVersion}/analyze/file`,{method:`POST`,headers:{"Mappa-Api-Key":this.apiKey},body:r}))}else{let r=new URL(e.inputMedia.url);t=await n(()=>fetch(`${this.apiBaseUrl}/${this.apiVersion}/analyze/url`,{method:`POST`,headers:{"Content-Type":`application/json`,"Mappa-Api-Key":this.apiKey},body:JSON.stringify({url:r.href,mode:`sync`,output:`behavior_profile`,target:e.targetSpeaker})}))}if(!t.ok){let e=`Mappa API request failed with status ${t.status}: ${await t.text().catch(()=>`Unable to retrieve error message`)}`;throw console.error(e),Error(e)}let r=await t.json(),a=i.generateReportOutputSchema.parse(r).outputs;if(!a)throw Error(`No outputs found in the response, error occurred during analysis.`);return{behaviorProfile:a.behavior_profile,entityId:a.entity_id}}};exports.Mappa=a;
@@ -0,0 +1,67 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/presets.d.ts
4
+ declare class Presets {
5
+ generateReport(): Promise<string>;
6
+ }
7
+ //#endregion
8
+ //#region src/mappa/model.d.ts
9
+ declare namespace MappaModel {
10
+ const generateReportInputSchema: z.ZodObject<{
11
+ inputMedia: z.ZodDiscriminatedUnion<[z.ZodObject<{
12
+ kind: z.ZodLiteral<"file">;
13
+ file: z.ZodFile;
14
+ }, z.core.$strip>, z.ZodObject<{
15
+ kind: z.ZodLiteral<"url">;
16
+ url: z.ZodURL;
17
+ }, z.core.$strip>], "kind">;
18
+ targetSpeaker: z.ZodDefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
19
+ strategy: z.ZodLiteral<"dominant">;
20
+ }, z.core.$strip>, z.ZodObject<{
21
+ strategy: z.ZodLiteral<"magic_hint">;
22
+ hint: z.ZodString;
23
+ }, z.core.$strip>], "strategy">>;
24
+ template: z.ZodEnum<{
25
+ base: "base";
26
+ }>;
27
+ }, z.core.$strip>;
28
+ type GenerateReportInput = z.infer<typeof generateReportInputSchema>;
29
+ const generateReportOutputSchema: z.ZodObject<{
30
+ outputs: z.ZodPipe<z.ZodArray<z.ZodObject<{
31
+ entity_id: z.ZodString;
32
+ behavior_profile: z.ZodString;
33
+ }, z.core.$strip>>, z.ZodTransform<{
34
+ entity_id: string;
35
+ behavior_profile: string;
36
+ } | null, {
37
+ entity_id: string;
38
+ behavior_profile: string;
39
+ }[]>>;
40
+ }, z.core.$strip>;
41
+ type GenerateReportOutput = z.infer<typeof generateReportOutputSchema>;
42
+ }
43
+ //#endregion
44
+ //#region src/mappa/index.d.ts
45
+ /**
46
+ * Client for the Mappa API that provides access to presets and can generate a synchronous behavior profile report
47
+ * from either an uploaded media file or a remote media URL.
48
+ */
49
+ declare class Mappa {
50
+ private readonly apiKey;
51
+ private readonly apiBaseUrl;
52
+ private readonly apiVersion;
53
+ readonly presets: Presets;
54
+ /**
55
+ * Initializes the client with an API key sourced from arguments or the environment.
56
+ */
57
+ constructor(apiKey?: string);
58
+ /**
59
+ * Generates a synchronous behavior profile report from either an uploaded media file or a remote media URL.
60
+ */
61
+ generateTextReport(body: MappaModel.GenerateReportInput): Promise<{
62
+ behaviorProfile: string;
63
+ entityId: string;
64
+ }>;
65
+ }
66
+ //#endregion
67
+ export { Mappa };
@@ -0,0 +1,67 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/presets.d.ts
4
+ declare class Presets {
5
+ generateReport(): Promise<string>;
6
+ }
7
+ //#endregion
8
+ //#region src/mappa/model.d.ts
9
+ declare namespace MappaModel {
10
+ const generateReportInputSchema: z.ZodObject<{
11
+ inputMedia: z.ZodDiscriminatedUnion<[z.ZodObject<{
12
+ kind: z.ZodLiteral<"file">;
13
+ file: z.ZodFile;
14
+ }, z.core.$strip>, z.ZodObject<{
15
+ kind: z.ZodLiteral<"url">;
16
+ url: z.ZodURL;
17
+ }, z.core.$strip>], "kind">;
18
+ targetSpeaker: z.ZodDefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
19
+ strategy: z.ZodLiteral<"dominant">;
20
+ }, z.core.$strip>, z.ZodObject<{
21
+ strategy: z.ZodLiteral<"magic_hint">;
22
+ hint: z.ZodString;
23
+ }, z.core.$strip>], "strategy">>;
24
+ template: z.ZodEnum<{
25
+ base: "base";
26
+ }>;
27
+ }, z.core.$strip>;
28
+ type GenerateReportInput = z.infer<typeof generateReportInputSchema>;
29
+ const generateReportOutputSchema: z.ZodObject<{
30
+ outputs: z.ZodPipe<z.ZodArray<z.ZodObject<{
31
+ entity_id: z.ZodString;
32
+ behavior_profile: z.ZodString;
33
+ }, z.core.$strip>>, z.ZodTransform<{
34
+ entity_id: string;
35
+ behavior_profile: string;
36
+ } | null, {
37
+ entity_id: string;
38
+ behavior_profile: string;
39
+ }[]>>;
40
+ }, z.core.$strip>;
41
+ type GenerateReportOutput = z.infer<typeof generateReportOutputSchema>;
42
+ }
43
+ //#endregion
44
+ //#region src/mappa/index.d.ts
45
+ /**
46
+ * Client for the Mappa API that provides access to presets and can generate a synchronous behavior profile report
47
+ * from either an uploaded media file or a remote media URL.
48
+ */
49
+ declare class Mappa {
50
+ private readonly apiKey;
51
+ private readonly apiBaseUrl;
52
+ private readonly apiVersion;
53
+ readonly presets: Presets;
54
+ /**
55
+ * Initializes the client with an API key sourced from arguments or the environment.
56
+ */
57
+ constructor(apiKey?: string);
58
+ /**
59
+ * Generates a synchronous behavior profile report from either an uploaded media file or a remote media URL.
60
+ */
61
+ generateTextReport(body: MappaModel.GenerateReportInput): Promise<{
62
+ behaviorProfile: string;
63
+ entityId: string;
64
+ }>;
65
+ }
66
+ //#endregion
67
+ export { Mappa };
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ import{z as e}from"zod";var t=class{async generateReport(){return``}};async function n(e,t=3){let n;for(let r=0;r<t;r++)try{return await e()}catch(e){console.warn(`Attempt ${r+1} failed. Retrying...`),n=e}throw n}let r;(function(t){t.availablePresetsSchema=e.enum([`base`])})(r||={});let i;(function(t){t.generateReportInputSchema=e.object({inputMedia:e.discriminatedUnion(`kind`,[e.object({kind:e.literal(`file`),file:e.file().mime([`video/*`,`audio/*`],{message:`Invalid file type, only audio and video files are allowed`}).describe(`The audio file to be processed`)}),e.object({kind:e.literal(`url`),url:e.url().describe(`The URL of the audio or video file to be processed`)})]),targetSpeaker:e.discriminatedUnion(`strategy`,[e.object({strategy:e.literal(`dominant`).describe(`Select the speaker who speaks the most in the audio`)}),e.object({strategy:e.literal(`magic_hint`).describe(`Use a hint to identify the target speaker`),hint:e.string().describe(`A hint to help identify the target speaker, e.g., 'the interviewer', 'the CEO', 'the person being interviewed`)})]).default({strategy:`dominant`}).describe(`Strategy for target extraction, this is useful when there are multiple speakers in the audio`),template:r.availablePresetsSchema}),t.generateReportOutputSchema=e.object({outputs:e.object({entity_id:e.string().describe(`The unique identifier for the analyzed entity`),behavior_profile:e.string().describe(`The generated behavior profile report`)}).array().transform(e=>e[0]??null)})})(i||={});var a=class{apiKey;apiBaseUrl=`https://api.mappa.ai`;apiVersion=`v1`;presets=new t;constructor(e){if(!e&&typeof process<`u`&&process.env&&process.env.MAPPA_API_KEY?.trim()!==``&&(this.apiKey=process.env.MAPPA_API_KEY||``),this.apiKey=e||``,this.apiKey.trim()===``)throw Error(`Mappa API key is required`)}async generateTextReport(e){let t;if(e.inputMedia.kind===`file`){let r=new FormData;r.append(`file`,e.inputMedia.file),r.append(`metadata`,JSON.stringify({mode:`sync`,output:`behavior_profile`,target:e.targetSpeaker})),t=await n(()=>fetch(`${this.apiBaseUrl}/${this.apiVersion}/analyze/file`,{method:`POST`,headers:{"Mappa-Api-Key":this.apiKey},body:r}))}else{let r=new URL(e.inputMedia.url);t=await n(()=>fetch(`${this.apiBaseUrl}/${this.apiVersion}/analyze/url`,{method:`POST`,headers:{"Content-Type":`application/json`,"Mappa-Api-Key":this.apiKey},body:JSON.stringify({url:r.href,mode:`sync`,output:`behavior_profile`,target:e.targetSpeaker})}))}if(!t.ok){let e=`Mappa API request failed with status ${t.status}: ${await t.text().catch(()=>`Unable to retrieve error message`)}`;throw console.error(e),Error(e)}let r=await t.json(),a=i.generateReportOutputSchema.parse(r).outputs;if(!a)throw Error(`No outputs found in the response, error occurred during analysis.`);return{behaviorProfile:a.behavior_profile,entityId:a.entity_id}}};export{a as Mappa};
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@mappa-ai/mappa-node",
3
+ "module": "src/index.ts",
4
+ "type": "module",
5
+ "version": "0.1.0",
6
+ "license": "MIT",
7
+ "private": false,
8
+ "files": [
9
+ "dist/**"
10
+ ],
11
+ "exports": {
12
+ ".": {
13
+ "import": {
14
+ "types": "./dist/index.d.mts",
15
+ "default": "./dist/index.mjs"
16
+ },
17
+ "require": {
18
+ "types": "./dist/index.d.cts",
19
+ "default": "./dist/index.cjs"
20
+ }
21
+ }
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/mappa-ai/mappa-node.git"
26
+ },
27
+ "scripts": {
28
+ "build": "tsdown",
29
+ "typecheck": "tsc --noEmit",
30
+ "test": "bun test",
31
+ "check": "biome check",
32
+ "check:fix": "biome check --fix",
33
+ "lazycheck": "bun run check && bun run typecheck"
34
+ },
35
+ "devDependencies": {
36
+ "@biomejs/biome": "^2.3.11",
37
+ "@types/bun": "latest",
38
+ "tsdown": "^0.19.0",
39
+ "typescript": "^5.9.3"
40
+ },
41
+ "dependencies": {
42
+ "zod": "^4.3.5"
43
+ }
44
+ }