@aippy/runtime 0.2.6-dev.0 → 0.2.7-dev.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.
@@ -5,68 +5,24 @@ export { hasNativeBridge };
5
5
  * Check if device motion is supported
6
6
  */
7
7
  export declare function isMotionSupported(): boolean;
8
- /**
9
- * Check if device orientation is supported
10
- */
11
8
  export declare function isOrientationSupported(): boolean;
12
- /**
13
- * Request permission for motion sensors (iOS 13+)
14
- * @returns Promise<boolean> - true if permission granted
15
- */
9
+ /** Request motion sensor permission (iOS 13+) */
16
10
  export declare function requestMotionPermission(): Promise<boolean>;
17
- /**
18
- * Watch device motion changes with full motion data
19
- * Automatically uses native bridge if available, otherwise falls back to Web API
20
- *
21
- * @param callback - Function to call with motion data
22
- * @param autoRequestPermission - Automatically request permission on iOS (default: true, only for Web API)
23
- * @returns Cleanup function to stop watching
24
- */
11
+ /** Watch device motion (auto selects native bridge or Web API) */
25
12
  export declare function watchMotion(callback: (data: MotionData) => void, autoRequestPermission?: boolean): () => void;
26
- /**
27
- * Watch device orientation changes
28
- * @param callback - Function to call with orientation data
29
- * @returns Cleanup function to stop watching
30
- */
13
+ /** Watch device orientation changes */
31
14
  export declare function watchOrientation(callback: (data: OrientationData) => void): () => void;
32
- /**
33
- * Legacy SensorsAPI class for backward compatibility
34
- * @deprecated Use watchMotion() and watchOrientation() functions instead
35
- */
15
+ /** @deprecated Use watchMotion() and watchOrientation() instead */
36
16
  export declare class SensorsAPI {
37
- /**
38
- * Check if device orientation is supported
39
- */
40
17
  isOrientationSupported(): boolean;
41
- /**
42
- * Check if device motion is supported
43
- */
44
18
  isMotionSupported(): boolean;
45
- /**
46
- * Get device orientation data
47
- */
48
19
  getOrientation(): Promise<SensorData>;
49
- /**
50
- * Watch device orientation changes
51
- * @deprecated Use watchOrientation() function instead
52
- */
20
+ /** @deprecated Use watchOrientation() instead */
53
21
  watchOrientation(callback: (data: SensorData) => void): () => void;
54
- /**
55
- * Get device motion data
56
- */
57
22
  getMotion(): Promise<SensorData>;
58
- /**
59
- * Watch device motion changes
60
- * @deprecated Use watchMotion() function instead
61
- */
23
+ /** @deprecated Use watchMotion() instead */
62
24
  watchMotion(callback: (data: SensorData) => void): () => void;
63
- /**
64
- * Request permission for motion sensors (iOS 13+)
65
- */
66
25
  requestPermission(): Promise<boolean>;
67
26
  }
68
- /**
69
- * Sensors API instance (for backward compatibility)
70
- * @deprecated Use watchMotion() and watchOrientation() functions instead
71
- */
27
+ /** @deprecated Use watchMotion() and watchOrientation() instead */
72
28
  export declare const sensors: SensorsAPI;
@@ -0,0 +1,152 @@
1
+ import { createOpenAICompatible as A } from "@ai-sdk/openai-compatible";
2
+ import "react";
3
+ import { h as p } from "./bridge-DdAH4txB.js";
4
+ import { DefaultChatTransport as l, AISDKError as a } from "ai";
5
+ const E = "https://api.aippy.dev", d = `${E}/api/aisdk/v1/`, h = `${E}/api/aisdk/v1/ui/`, g = "gpt-5-nano", _ = "";
6
+ function U(e = {}) {
7
+ return {
8
+ baseUrl: e.baseUrl ?? d
9
+ };
10
+ }
11
+ function i(e = {}) {
12
+ return {
13
+ baseUrl: e.baseUrl ?? h
14
+ };
15
+ }
16
+ function c(e, r) {
17
+ const t = e.endsWith("/") ? e : `${e}/`, n = r.startsWith("/") ? r.slice(1) : r;
18
+ return new URL(n, t).href;
19
+ }
20
+ function u() {
21
+ return async (e, r) => {
22
+ const t = await p(), n = new Headers(r?.headers);
23
+ return n.set("Authorization", `Bearer ${t}`), globalThis.fetch(e, { ...r, headers: n });
24
+ };
25
+ }
26
+ const y = [
27
+ "gpt-image-1",
28
+ "gpt-image-1-mini",
29
+ "gpt-image-1.5"
30
+ ];
31
+ function I(e) {
32
+ try {
33
+ const r = JSON.parse(e);
34
+ if (r.model && y.some((t) => r.model.startsWith(t))) {
35
+ const { response_format: t, ...n } = r;
36
+ return JSON.stringify(n);
37
+ }
38
+ } catch {
39
+ }
40
+ return e;
41
+ }
42
+ function w(e = {}) {
43
+ const { baseUrl: r } = U(e), t = u();
44
+ return A({
45
+ name: "aippy",
46
+ baseURL: r,
47
+ fetch: async (s, o) => s.toString().includes("/images/generations") && o?.method?.toUpperCase() === "POST" && o?.body ? t(s, {
48
+ ...o,
49
+ body: I(o.body)
50
+ }) : t(s, o)
51
+ });
52
+ }
53
+ const T = "/chat", O = "/completion", f = "/object";
54
+ function N(e = {}) {
55
+ const { baseUrl: r } = i(e), t = e.model ?? g, n = e.system ?? _, s = e.api ?? c(r, T), o = { model: t, system: n }, m = u();
56
+ return {
57
+ transport: new l({
58
+ api: s,
59
+ body: o,
60
+ // Ensure token is fetched fresh for every request
61
+ fetch: m
62
+ })
63
+ };
64
+ }
65
+ function D(e = {}) {
66
+ const { baseUrl: r } = i(e), t = u();
67
+ return {
68
+ api: c(r, O),
69
+ // Ensure token is fetched fresh for every request
70
+ fetch: t
71
+ };
72
+ }
73
+ async function B(e) {
74
+ const { schemaId: r, ...t } = e, { baseUrl: n } = i(t), s = await p();
75
+ return {
76
+ api: c(n, f),
77
+ headers: { Authorization: `Bearer ${s}` },
78
+ schemaId: r
79
+ };
80
+ }
81
+ async function L(e = {}) {
82
+ const { baseUrl: r } = i(e), t = await p();
83
+ return {
84
+ api: c(r, f),
85
+ headers: { Authorization: `Bearer ${t}` }
86
+ };
87
+ }
88
+ function k(e, r) {
89
+ const t = e.status;
90
+ if (r && typeof r == "object" && "error" in r) {
91
+ const n = r, s = n.error.code, o = s != null ? `AippyAIError_${s}` : `AippyAIError_${t}`;
92
+ return new a({
93
+ name: o,
94
+ message: n.error.message,
95
+ cause: {
96
+ type: n.error.type ?? void 0,
97
+ param: n.error.param ?? void 0,
98
+ status: t
99
+ }
100
+ });
101
+ }
102
+ return new a({
103
+ name: `AippyAIError_${t}`,
104
+ message: `Request failed with status ${t}`,
105
+ cause: { status: t }
106
+ });
107
+ }
108
+ function $() {
109
+ return new a({
110
+ name: "AippyAIError_MISSING_TOKEN",
111
+ message: "User token is required. Ensure user credentials are available via initUserBridge()."
112
+ });
113
+ }
114
+ function F() {
115
+ return new a({
116
+ name: "AippyAIError_REQUEST_ABORTED",
117
+ message: "Request was aborted"
118
+ });
119
+ }
120
+ function v(e) {
121
+ const r = e instanceof Error ? e.message : "Network request failed";
122
+ return new a({
123
+ name: "AippyAIError_NETWORK_ERROR",
124
+ message: r,
125
+ cause: e instanceof Error ? e : String(e)
126
+ });
127
+ }
128
+ function P(e) {
129
+ return new a({
130
+ name: "AippyAIError_PARSE_ERROR",
131
+ message: `Failed to parse response: ${e}`
132
+ });
133
+ }
134
+ export {
135
+ d as D,
136
+ T as U,
137
+ w as a,
138
+ N as b,
139
+ D as c,
140
+ B as d,
141
+ L as e,
142
+ O as f,
143
+ f as g,
144
+ h,
145
+ g as i,
146
+ _ as j,
147
+ F as k,
148
+ v as l,
149
+ $ as m,
150
+ k as n,
151
+ P as p
152
+ };
@@ -6,7 +6,7 @@ import { c as F, a as N, P as L, b as B, p as v, d as w } from "../pwa-8DGmPqLV.
6
6
  import { a as H, b as j } from "../useTweaks-QxMRmg7i.js";
7
7
  import { c as Q, a as V, b as J, i as z, p as K, u as W } from "../useAudioContext-CNQQSTab.js";
8
8
  import { reportScore as X, sendEvent as Z, updateScore as $ } from "../leaderboard/index.js";
9
- import { D as ae, i as re, j as se, h as oe, U as te, f as ie, g as ne, k as pe, a as me, b as de, c as ue, e as fe, d as Ce, m as ce, l as Ee, n as le, p as Ae } from "../errors-3xwlPAB-.js";
9
+ import { D as ae, i as re, j as se, h as oe, U as te, f as ie, g as ne, k as pe, a as me, b as de, c as ue, e as fe, d as Ce, m as ce, l as Ee, n as le, p as Ae } from "../errors-DWRVLkVz.js";
10
10
  import { f as Ie, b as Ue, h as Se, l as Te, j as Pe, g as ye, k as he, e as _e, i as Oe, c as De, d as xe, r as Re, s as ke, a as Me, t as be } from "../bridge-DdAH4txB.js";
11
11
  import { e as Ne, f as Le, g as Be, a as ve, u as we, b as Ge, d as He, c as je, h as qe } from "../userSessionInfo-CBk9ywXi.js";
12
12
  import { h as Ve } from "../native-bridge-JAmH-zTN.js";
@@ -1,42 +1,46 @@
1
1
  function r(e, o) {
2
2
  try {
3
3
  if (window.parent && window.parent !== window) {
4
- const n = {
4
+ const a = {
5
5
  __aippyGame: !0,
6
6
  payload: e
7
7
  };
8
- window.parent.postMessage(n, "*");
8
+ window.parent.postMessage(a, "*");
9
9
  }
10
- const a = window.webkit?.messageHandlers?.aippyListener;
11
- a && a.postMessage({
10
+ const n = window.webkit?.messageHandlers?.aippyListener;
11
+ n && n.postMessage({
12
12
  command: o,
13
13
  parameters: JSON.stringify(e)
14
14
  });
15
- } catch (a) {
16
- console.warn("[Aippy Leaderboard] Failed to send game event:", a);
15
+ } catch (n) {
16
+ console.warn("[Aippy Leaderboard] Failed to send game event:", n);
17
17
  }
18
18
  }
19
19
  function t(e) {
20
- r({
20
+ const o = {
21
21
  type: "score",
22
- score: e
23
- }, "leaderboard.reportScore"), console.log(`[Aippy Leaderboard] Score reported: ${e}`);
22
+ score: e,
23
+ url: window.location.href
24
+ };
25
+ r(o, "leaderboard.reportScore"), console.log(`[Aippy Leaderboard] Score reported: ${e}, URL: ${window.location.href}`);
24
26
  }
25
- function p(e) {
26
- r({
27
+ function d(e) {
28
+ const o = {
27
29
  type: "score",
28
- score: e
29
- }, "leaderboard.updateScore"), console.log(`[Aippy Leaderboard] Score updated: ${e}`);
30
+ score: e,
31
+ url: window.location.href
32
+ };
33
+ r(o, "leaderboard.updateScore"), console.log(`[Aippy Leaderboard] Score updated: ${e}, URL: ${window.location.href}`);
30
34
  }
31
- function d(e, o) {
32
- const a = {
35
+ function i(e, o) {
36
+ const n = {
33
37
  type: e,
34
38
  ...o
35
39
  };
36
- r(a, "leaderboard.event"), console.log(`[Aippy Leaderboard] Event sent: ${e}`, o);
40
+ r(n, "leaderboard.event"), console.log(`[Aippy Leaderboard] Event sent: ${e}`, o);
37
41
  }
38
42
  export {
39
43
  t as reportScore,
40
- d as sendEvent,
41
- p as updateScore
44
+ i as sendEvent,
45
+ d as updateScore
42
46
  };
@@ -9,6 +9,8 @@ export interface ScorePayload {
9
9
  type: 'score';
10
10
  /** The score value */
11
11
  score: number;
12
+ /** The URL of the current H5 application */
13
+ url?: string;
12
14
  /** Score unit (e.g., 'points', 'coins') */
13
15
  unit?: string;
14
16
  /** Whether bigger score is better for leaderboard ranking */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aippy/runtime",
3
- "version": "0.2.6-dev.0",
3
+ "version": "0.2.7-dev.0",
4
4
  "description": "Aippy Runtime SDK - Runtime SDK for Aippy projects",
5
5
  "private": false,
6
6
  "type": "module",
@@ -1,148 +0,0 @@
1
- import { createOpenAICompatible as A } from "@ai-sdk/openai-compatible";
2
- import "react";
3
- import { h as i } from "./bridge-DdAH4txB.js";
4
- import { DefaultChatTransport as f, AISDKError as n } from "ai";
5
- const m = "https://api.aippy.dev", l = `${m}/api/aisdk/v1/`, d = `${m}/api/aisdk/v1/ui/`, g = "gpt-5", _ = "";
6
- function h(e = {}) {
7
- return {
8
- baseUrl: e.baseUrl ?? l
9
- };
10
- }
11
- function u(e = {}) {
12
- return {
13
- baseUrl: e.baseUrl ?? d
14
- };
15
- }
16
- const y = [
17
- "gpt-image-1",
18
- "gpt-image-1-mini",
19
- "gpt-image-1.5"
20
- ];
21
- function U(e) {
22
- try {
23
- const r = JSON.parse(e);
24
- if (r.model && y.some((t) => r.model.startsWith(t))) {
25
- const { response_format: t, ...s } = r;
26
- return JSON.stringify(s);
27
- }
28
- } catch {
29
- }
30
- return e;
31
- }
32
- function w(e = {}) {
33
- const { baseUrl: r } = h(e);
34
- return A({
35
- name: "aippy",
36
- baseURL: r,
37
- fetch: async (s, a) => {
38
- const o = await i(), c = new Headers(a?.headers);
39
- c.set("Authorization", `Bearer ${o}`);
40
- let p = a;
41
- return s.toString().includes("/images/generations") && a?.method?.toUpperCase() === "POST" && a?.body && (p = {
42
- ...a,
43
- body: U(a.body)
44
- }), globalThis.fetch(s, {
45
- ...p,
46
- headers: c
47
- });
48
- }
49
- });
50
- }
51
- const I = "/chat", T = "/completion", E = "/object";
52
- async function C(e = {}) {
53
- const { baseUrl: r } = u(e), t = await i(), s = e.model ?? g, a = e.system ?? _, o = e.api ?? `${r}${I}`, c = { Authorization: `Bearer ${t}` }, p = { model: s, system: a };
54
- return {
55
- transport: new f({
56
- api: o,
57
- headers: c,
58
- body: p
59
- })
60
- };
61
- }
62
- async function N(e = {}) {
63
- const { baseUrl: r } = u(e), t = await i();
64
- return {
65
- api: `${r}${T}`,
66
- headers: { Authorization: `Bearer ${t}` }
67
- };
68
- }
69
- async function k(e) {
70
- const { schemaId: r, ...t } = e, { baseUrl: s } = u(t), a = await i();
71
- return {
72
- api: `${s}${E}`,
73
- headers: { Authorization: `Bearer ${a}` },
74
- schemaId: r
75
- };
76
- }
77
- async function B(e = {}) {
78
- const { baseUrl: r } = u(e), t = await i();
79
- return {
80
- api: `${r}${E}`,
81
- headers: { Authorization: `Bearer ${t}` }
82
- };
83
- }
84
- function D(e, r) {
85
- const t = e.status;
86
- if (r && typeof r == "object" && "error" in r) {
87
- const s = r, a = s.error.code, o = a != null ? `AippyAIError_${a}` : `AippyAIError_${t}`;
88
- return new n({
89
- name: o,
90
- message: s.error.message,
91
- cause: {
92
- type: s.error.type ?? void 0,
93
- param: s.error.param ?? void 0,
94
- status: t
95
- }
96
- });
97
- }
98
- return new n({
99
- name: `AippyAIError_${t}`,
100
- message: `Request failed with status ${t}`,
101
- cause: { status: t }
102
- });
103
- }
104
- function L() {
105
- return new n({
106
- name: "AippyAIError_MISSING_TOKEN",
107
- message: "User token is required. Ensure user credentials are available via initUserBridge()."
108
- });
109
- }
110
- function v() {
111
- return new n({
112
- name: "AippyAIError_REQUEST_ABORTED",
113
- message: "Request was aborted"
114
- });
115
- }
116
- function F(e) {
117
- const r = e instanceof Error ? e.message : "Network request failed";
118
- return new n({
119
- name: "AippyAIError_NETWORK_ERROR",
120
- message: r,
121
- cause: e instanceof Error ? e : String(e)
122
- });
123
- }
124
- function P(e) {
125
- return new n({
126
- name: "AippyAIError_PARSE_ERROR",
127
- message: `Failed to parse response: ${e}`
128
- });
129
- }
130
- export {
131
- l as D,
132
- I as U,
133
- w as a,
134
- C as b,
135
- N as c,
136
- k as d,
137
- B as e,
138
- T as f,
139
- E as g,
140
- d as h,
141
- g as i,
142
- _ as j,
143
- v as k,
144
- F as l,
145
- L as m,
146
- D as n,
147
- P as p
148
- };