@aippy/runtime 0.2.4 → 0.2.5-dev.1
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 +34 -0
- package/dist/ai/errors.d.ts +21 -0
- package/dist/ai/index.d.ts +45 -0
- package/dist/ai/index.js +20 -0
- package/dist/ai/openai/index.d.ts +11 -0
- package/dist/ai/openai/provider.d.ts +51 -0
- package/dist/ai/shared/config.d.ts +50 -0
- package/dist/ai/shared/index.d.ts +5 -0
- package/dist/ai/ui/config.d.ts +81 -0
- package/dist/ai/ui/endpoints.d.ts +16 -0
- package/dist/ai/ui/index.d.ts +15 -0
- package/dist/ai/ui/types.d.ts +46 -0
- package/dist/ai.d.ts +2 -0
- package/dist/bridge-DdAH4txB.js +222 -0
- package/dist/core/index.js +15 -14
- package/dist/core/native-bridge.d.ts +9 -0
- package/dist/device/index.js +108 -116
- package/dist/device/sensors.d.ts +2 -4
- package/dist/errors-CDEBaBxB.js +26 -0
- package/dist/errors-D29z-Qus.js +148 -0
- package/dist/index/index.js +93 -47
- package/dist/index.d.ts +2 -0
- package/dist/native-bridge-JAmH-zTN.js +6 -0
- package/dist/{runtime-DjBdOttl.js → runtime-CmoG3v2m.js} +55 -76
- package/dist/user/api.d.ts +9 -0
- package/dist/user/bridge.d.ts +80 -0
- package/dist/user/config.d.ts +21 -0
- package/dist/user/hooks.d.ts +38 -0
- package/dist/user/index.d.ts +11 -0
- package/dist/user/index.js +28 -0
- package/dist/user/types.d.ts +111 -0
- package/dist/user/userSessionInfo.d.ts +6 -0
- package/dist/user.d.ts +2 -0
- package/dist/userSessionInfo-CBk9ywXi.js +186 -0
- package/package.json +25 -12
package/README.md
CHANGED
|
@@ -87,12 +87,46 @@ button.onclick = async () => {
|
|
|
87
87
|
};
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
+
### AI (Backend Proxy Adapter)
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
// Default base URL: https://api.aippy.dev/api/aisdk/v1
|
|
94
|
+
|
|
95
|
+
import { streamText, experimental_generateImage as generateImage } from 'ai';
|
|
96
|
+
import { aippy } from '@aippy/runtime/ai';
|
|
97
|
+
|
|
98
|
+
// Create provider (reads from env vars automatically)
|
|
99
|
+
const provider = aippy();
|
|
100
|
+
|
|
101
|
+
// Or override with config
|
|
102
|
+
// const provider = aippy({ baseUrl: '...', userToken: '...' });
|
|
103
|
+
|
|
104
|
+
// Streaming text generation (uses Vercel AI SDK)
|
|
105
|
+
const result = await streamText({
|
|
106
|
+
model: provider('gpt'),
|
|
107
|
+
prompt: 'Write a haiku about TypeScript.',
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
for await (const chunk of result.textStream) {
|
|
111
|
+
console.log(chunk);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Image generation
|
|
115
|
+
const image = await generateImage({
|
|
116
|
+
model: provider.image('dall-e-3'),
|
|
117
|
+
prompt: 'A sunset over mountains',
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
console.log(image.image?.base64);
|
|
121
|
+
```
|
|
122
|
+
|
|
90
123
|
## Packages
|
|
91
124
|
|
|
92
125
|
- `@aippy/runtime/core` - Core types and configuration
|
|
93
126
|
- `@aippy/runtime/device` - Device APIs (camera, geolocation, sensors, file system)
|
|
94
127
|
- `@aippy/runtime/utils` - Platform detection, performance monitoring, PWA utilities
|
|
95
128
|
- `@aippy/runtime/audio` - iOS-compatible Web Audio API wrapper
|
|
129
|
+
- `@aippy/runtime/ai` - AI SDK adapter wrapping `ai` package, routes through backend proxy
|
|
96
130
|
|
|
97
131
|
## Publishing
|
|
98
132
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AISDKError } from 'ai';
|
|
2
|
+
/**
|
|
3
|
+
* Normalizes a backend error response into an AISDKError.
|
|
4
|
+
*/
|
|
5
|
+
export declare function normalizeError(response: Response, body?: unknown): AISDKError;
|
|
6
|
+
/**
|
|
7
|
+
* Creates an error for missing user token.
|
|
8
|
+
*/
|
|
9
|
+
export declare function missingTokenError(): AISDKError;
|
|
10
|
+
/**
|
|
11
|
+
* Creates an error for aborted requests.
|
|
12
|
+
*/
|
|
13
|
+
export declare function abortedError(): AISDKError;
|
|
14
|
+
/**
|
|
15
|
+
* Creates an error for network failures.
|
|
16
|
+
*/
|
|
17
|
+
export declare function networkError(cause?: unknown): AISDKError;
|
|
18
|
+
/**
|
|
19
|
+
* Creates an error for parse failures.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseError(message: string): AISDKError;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @aippy/runtime/ai - AI module for Aippy Runtime SDK
|
|
3
|
+
*
|
|
4
|
+
* This module provides two integration paths with Vercel AI SDK:
|
|
5
|
+
*
|
|
6
|
+
* ## Path 1: OpenAI-Compatible Provider (AI SDK Core)
|
|
7
|
+
*
|
|
8
|
+
* Use `aippy()` provider with AI SDK Core functions:
|
|
9
|
+
* - generateText / streamText
|
|
10
|
+
* - generateObject / streamObject
|
|
11
|
+
* - embed / embedMany
|
|
12
|
+
* - generateImage
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { streamText } from 'ai';
|
|
16
|
+
* import { aippy } from '@aippy/runtime/ai';
|
|
17
|
+
*
|
|
18
|
+
* const provider = aippy();
|
|
19
|
+
* const result = await streamText({
|
|
20
|
+
* model: provider('gpt-5'),
|
|
21
|
+
* prompt: 'Hello!',
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* ## Path 2: Data Stream Protocol (AI SDK UI / @ai-sdk/react)
|
|
26
|
+
*
|
|
27
|
+
* Use config builders with @ai-sdk/react hooks:
|
|
28
|
+
* - useChat → aippyChatConfig()
|
|
29
|
+
* - useCompletion → aippyCompletionConfig()
|
|
30
|
+
* - useObject → aippyObjectConfig()
|
|
31
|
+
*
|
|
32
|
+
* ```tsx
|
|
33
|
+
* import { useChat } from '@ai-sdk/react';
|
|
34
|
+
* import { aippyChatConfig } from '@aippy/runtime/ai';
|
|
35
|
+
*
|
|
36
|
+
* const { messages, handleSubmit } = useChat(aippyChatConfig());
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @module
|
|
40
|
+
*/
|
|
41
|
+
export { aippy, type AippyProvider } from './openai';
|
|
42
|
+
export type { AippyOpenAIConfig } from './openai';
|
|
43
|
+
export { aippyChatConfig, aippyCompletionConfig, aippyObjectConfig, aippyObjectBaseConfig, type AippyObjectConfigOptions, type AippyUseChatOptions, type UseObjectOptions, type UseObjectConfigWithSchema, type AippyUIConfig, type AippyChatConfig, UI_CHAT_ENDPOINT, UI_COMPLETION_ENDPOINT, UI_OBJECT_ENDPOINT, } from './ui';
|
|
44
|
+
export { DEFAULT_BASE_URL, DEFAULT_UI_BASE_URL, DEFAULT_CHAT_MODEL, DEFAULT_CHAT_SYSTEM, } from './shared';
|
|
45
|
+
export { normalizeError, missingTokenError, abortedError, networkError, parseError, } from './errors';
|
package/dist/ai/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { D as s, i as E, j as o, h as _, U as i, f as p, g as T, k as e, a as C, b as U, c as n, e as A, d as D, m as O, l as I, n as L, p as t } from "../errors-D29z-Qus.js";
|
|
2
|
+
export {
|
|
3
|
+
s as DEFAULT_BASE_URL,
|
|
4
|
+
E as DEFAULT_CHAT_MODEL,
|
|
5
|
+
o as DEFAULT_CHAT_SYSTEM,
|
|
6
|
+
_ as DEFAULT_UI_BASE_URL,
|
|
7
|
+
i as UI_CHAT_ENDPOINT,
|
|
8
|
+
p as UI_COMPLETION_ENDPOINT,
|
|
9
|
+
T as UI_OBJECT_ENDPOINT,
|
|
10
|
+
e as abortedError,
|
|
11
|
+
C as aippy,
|
|
12
|
+
U as aippyChatConfig,
|
|
13
|
+
n as aippyCompletionConfig,
|
|
14
|
+
A as aippyObjectBaseConfig,
|
|
15
|
+
D as aippyObjectConfig,
|
|
16
|
+
O as missingTokenError,
|
|
17
|
+
I as networkError,
|
|
18
|
+
L as normalizeError,
|
|
19
|
+
t as parseError
|
|
20
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI-compatible module for Aippy AI SDK.
|
|
3
|
+
*
|
|
4
|
+
* Provides the `aippy()` provider factory for use with AI SDK Core functions:
|
|
5
|
+
* - generateText / streamText
|
|
6
|
+
* - generateObject / streamObject
|
|
7
|
+
* - embed / embedMany
|
|
8
|
+
* - generateImage
|
|
9
|
+
*/
|
|
10
|
+
export { aippy, type AippyProvider } from './provider';
|
|
11
|
+
export type { AippyOpenAIConfig } from '../shared/config';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { OpenAICompatibleProvider } from '@ai-sdk/openai-compatible';
|
|
2
|
+
import { AippyOpenAIConfig } from '../shared/config';
|
|
3
|
+
/**
|
|
4
|
+
* The Aippy provider type - an OpenAI-compatible provider.
|
|
5
|
+
*/
|
|
6
|
+
export type AippyProvider = OpenAICompatibleProvider<string, string, string, string>;
|
|
7
|
+
/**
|
|
8
|
+
* Creates an Aippy AI provider that routes requests through the backend proxy.
|
|
9
|
+
*
|
|
10
|
+
* This provider is for use with AI SDK Core functions:
|
|
11
|
+
* - `generateText` / `streamText` - Text generation
|
|
12
|
+
* - `generateObject` / `streamObject` - Structured object generation
|
|
13
|
+
* - `embed` / `embedMany` - Text embeddings
|
|
14
|
+
* - `generateImage` - Image generation
|
|
15
|
+
*
|
|
16
|
+
* @param config - Optional configuration to override defaults
|
|
17
|
+
* @returns An AI SDK Core compatible provider
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { generateText, streamText, embed, generateImage } from 'ai';
|
|
22
|
+
* import { aippy } from '@aippy/runtime/ai';
|
|
23
|
+
*
|
|
24
|
+
* const provider = aippy();
|
|
25
|
+
*
|
|
26
|
+
* // Text generation
|
|
27
|
+
* const text = await generateText({
|
|
28
|
+
* model: provider('gpt-5'),
|
|
29
|
+
* prompt: 'Hello!',
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // Streaming
|
|
33
|
+
* const stream = await streamText({
|
|
34
|
+
* model: provider('gpt-5'),
|
|
35
|
+
* prompt: 'Tell me a story.',
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* // Embeddings
|
|
39
|
+
* const embedding = await embed({
|
|
40
|
+
* model: provider.embedding('text-embedding-3-small'),
|
|
41
|
+
* value: 'Hello world',
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Image generation
|
|
45
|
+
* const image = await generateImage({
|
|
46
|
+
* model: provider.imageModel('gpt-image-1.5'),
|
|
47
|
+
* prompt: 'A cat',
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function aippy(config?: AippyOpenAIConfig): AippyProvider;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared configuration for Aippy AI SDK.
|
|
3
|
+
* Used by both OpenAI-compatible (Core) and Data Stream Protocol (UI) paths.
|
|
4
|
+
*/
|
|
5
|
+
/** Default backend base URL for OpenAI-compatible endpoints */
|
|
6
|
+
export declare const DEFAULT_BASE_URL: string;
|
|
7
|
+
/** Default backend base URL for UI (Data Stream Protocol) endpoints */
|
|
8
|
+
export declare const DEFAULT_UI_BASE_URL: string;
|
|
9
|
+
/**
|
|
10
|
+
* Configuration for OpenAI-compatible provider (AI SDK Core).
|
|
11
|
+
*/
|
|
12
|
+
export interface AippyOpenAIConfig {
|
|
13
|
+
/** Backend proxy URL for OpenAI-compatible endpoints (defaults to DEFAULT_BASE_URL) */
|
|
14
|
+
baseUrl?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Configuration for Data Stream Protocol endpoints (AI SDK UI).
|
|
18
|
+
*/
|
|
19
|
+
export interface AippyUIConfig {
|
|
20
|
+
/** Backend proxy URL for UI endpoints (defaults to DEFAULT_UI_BASE_URL) */
|
|
21
|
+
baseUrl?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Configuration for useChat hook with model and system prompt.
|
|
25
|
+
*/
|
|
26
|
+
export interface AippyChatConfig extends AippyUIConfig {
|
|
27
|
+
/**
|
|
28
|
+
* Optional API endpoint override for useChat.
|
|
29
|
+
* Useful for local dev proxies (e.g. Vite) to avoid cross-origin streaming.
|
|
30
|
+
*
|
|
31
|
+
* If not provided, we use `${baseUrl}/chat`.
|
|
32
|
+
*/
|
|
33
|
+
api?: string;
|
|
34
|
+
/** Model identifier (defaults to 'gpt-5') */
|
|
35
|
+
model?: string;
|
|
36
|
+
/** System prompt for the conversation (defaults to empty string) */
|
|
37
|
+
system?: string;
|
|
38
|
+
}
|
|
39
|
+
/** Default model for chat */
|
|
40
|
+
export declare const DEFAULT_CHAT_MODEL = "gpt-5";
|
|
41
|
+
/** Default system prompt for chat */
|
|
42
|
+
export declare const DEFAULT_CHAT_SYSTEM = "";
|
|
43
|
+
/**
|
|
44
|
+
* Resolves OpenAI-compatible configuration with defaults.
|
|
45
|
+
*/
|
|
46
|
+
export declare function resolveOpenAIConfig(config?: AippyOpenAIConfig): Required<AippyOpenAIConfig>;
|
|
47
|
+
/**
|
|
48
|
+
* Resolves UI (Data Stream Protocol) configuration with defaults.
|
|
49
|
+
*/
|
|
50
|
+
export declare function resolveUIConfig(config?: AippyUIConfig): Required<AippyUIConfig>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities for Aippy AI SDK.
|
|
3
|
+
* Re-exports config utilities used by both protocol paths.
|
|
4
|
+
*/
|
|
5
|
+
export { DEFAULT_BASE_URL, DEFAULT_UI_BASE_URL, DEFAULT_CHAT_MODEL, DEFAULT_CHAT_SYSTEM, resolveOpenAIConfig, resolveUIConfig, type AippyOpenAIConfig, type AippyUIConfig, type AippyChatConfig, } from './config';
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { AippyUIConfig, AippyChatConfig } from '../shared/config';
|
|
2
|
+
import { UseCompletionOptions } from 'ai';
|
|
3
|
+
import { AippyUseChatOptions, UseObjectOptions, UseObjectConfigWithSchema } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Creates configuration for the useChat hook.
|
|
6
|
+
*
|
|
7
|
+
* @param config - Optional configuration to override defaults
|
|
8
|
+
* @returns Promise resolving to configuration object to spread into useChat()
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* import { useChat } from '@ai-sdk/react';
|
|
13
|
+
* import { aippyChatConfig } from '@aippy/runtime/ai';
|
|
14
|
+
*
|
|
15
|
+
* const chatConfig = await aippyChatConfig();
|
|
16
|
+
* const { messages, input, handleSubmit } = useChat(chatConfig);
|
|
17
|
+
*
|
|
18
|
+
* // With custom model and system prompt
|
|
19
|
+
* const config = await aippyChatConfig({
|
|
20
|
+
* model: 'claude-3',
|
|
21
|
+
* system: 'You are a helpful assistant.',
|
|
22
|
+
* });
|
|
23
|
+
* const { messages } = useChat(config);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function aippyChatConfig(config?: AippyChatConfig): Promise<AippyUseChatOptions>;
|
|
27
|
+
/**
|
|
28
|
+
* Creates configuration for the useCompletion hook.
|
|
29
|
+
*
|
|
30
|
+
* @param config - Optional configuration to override defaults
|
|
31
|
+
* @returns Promise resolving to configuration object to spread into useCompletion()
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* import { useCompletion } from '@ai-sdk/react';
|
|
36
|
+
* import { aippyCompletionConfig } from '@aippy/runtime/ai';
|
|
37
|
+
*
|
|
38
|
+
* const config = await aippyCompletionConfig();
|
|
39
|
+
* const { completion, input, handleSubmit } = useCompletion(config);
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function aippyCompletionConfig(config?: AippyUIConfig): Promise<UseCompletionOptions>;
|
|
43
|
+
/**
|
|
44
|
+
* Configuration options for aippyObjectConfig.
|
|
45
|
+
*/
|
|
46
|
+
export interface AippyObjectConfigOptions extends AippyUIConfig {
|
|
47
|
+
/**
|
|
48
|
+
* Schema identifier registered on the backend.
|
|
49
|
+
* Required for useObject to work with the Aippy backend.
|
|
50
|
+
*/
|
|
51
|
+
schemaId: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Creates configuration for the useObject hook.
|
|
55
|
+
*
|
|
56
|
+
* Note: Unlike useChat/useCompletion, useObject requires a schema.
|
|
57
|
+
* With the Aippy backend, we use schemaId to reference a pre-registered
|
|
58
|
+
* schema on the server (instead of passing the schema directly).
|
|
59
|
+
*
|
|
60
|
+
* @param options - Configuration including required schemaId
|
|
61
|
+
* @returns Promise resolving to configuration object to spread into useObject()
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```tsx
|
|
65
|
+
* import { useObject } from '@ai-sdk/react';
|
|
66
|
+
* import { aippyObjectConfig } from '@aippy/runtime/ai';
|
|
67
|
+
*
|
|
68
|
+
* // The schemaId must match a schema registered on your backend
|
|
69
|
+
* const config = await aippyObjectConfig({ schemaId: 'user-profile' });
|
|
70
|
+
* const { object, submit } = useObject(config);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare function aippyObjectConfig(options: AippyObjectConfigOptions): Promise<UseObjectConfigWithSchema>;
|
|
74
|
+
/**
|
|
75
|
+
* Creates base configuration for useObject without schemaId.
|
|
76
|
+
* Use this when you want to pass schemaId separately.
|
|
77
|
+
*
|
|
78
|
+
* @param config - Optional configuration to override defaults
|
|
79
|
+
* @returns Promise resolving to base configuration object (api + headers only)
|
|
80
|
+
*/
|
|
81
|
+
export declare function aippyObjectBaseConfig(config?: AippyUIConfig): Promise<UseObjectOptions>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UI endpoint path constants for Data Stream Protocol.
|
|
3
|
+
*
|
|
4
|
+
* These endpoints are served by the Aippy backend and return
|
|
5
|
+
* responses in AI SDK Data Stream Protocol format.
|
|
6
|
+
*
|
|
7
|
+
* Required response headers from backend:
|
|
8
|
+
* - Content-Type: text/event-stream
|
|
9
|
+
* - x-vercel-ai-ui-message-stream: v1
|
|
10
|
+
*/
|
|
11
|
+
/** Endpoint for useChat hook */
|
|
12
|
+
export declare const UI_CHAT_ENDPOINT = "/chat";
|
|
13
|
+
/** Endpoint for useCompletion hook */
|
|
14
|
+
export declare const UI_COMPLETION_ENDPOINT = "/completion";
|
|
15
|
+
/** Endpoint for useObject hook */
|
|
16
|
+
export declare const UI_OBJECT_ENDPOINT = "/object";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI SDK UI module for Aippy AI SDK.
|
|
3
|
+
*
|
|
4
|
+
* Provides configuration builders for @ai-sdk/react hooks:
|
|
5
|
+
* - useChat → aippyChatConfig()
|
|
6
|
+
* - useCompletion → aippyCompletionConfig()
|
|
7
|
+
* - useObject → aippyObjectConfig()
|
|
8
|
+
*
|
|
9
|
+
* These hooks communicate with the Aippy backend using
|
|
10
|
+
* AI SDK Data Stream Protocol (SSE with x-vercel-ai-ui-message-stream: v1).
|
|
11
|
+
*/
|
|
12
|
+
export { aippyChatConfig, aippyCompletionConfig, aippyObjectConfig, aippyObjectBaseConfig, type AippyObjectConfigOptions, } from './config';
|
|
13
|
+
export type { AippyUseChatOptions, UseObjectOptions, UseObjectConfigWithSchema, } from './types';
|
|
14
|
+
export { UI_CHAT_ENDPOINT, UI_COMPLETION_ENDPOINT, UI_OBJECT_ENDPOINT, } from './endpoints';
|
|
15
|
+
export type { AippyUIConfig, AippyChatConfig } from '../shared/config';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ChatTransport, UIMessage } from 'ai';
|
|
2
|
+
/**
|
|
3
|
+
* Body parameters for useChat requests (internal use).
|
|
4
|
+
*/
|
|
5
|
+
interface UseChatBody {
|
|
6
|
+
/** Model identifier (e.g., 'gpt-5', 'claude-3') */
|
|
7
|
+
model: string;
|
|
8
|
+
/** System prompt for the conversation */
|
|
9
|
+
system: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Configuration options for useChat hook with Aippy transport.
|
|
13
|
+
*
|
|
14
|
+
* This is a minimal wrapper around ChatTransport for type safety.
|
|
15
|
+
* Users can also directly use ChatTransport from 'ai' package.
|
|
16
|
+
*/
|
|
17
|
+
export interface AippyUseChatOptions<UI_MESSAGE extends UIMessage = UIMessage> {
|
|
18
|
+
/** Transport for custom API communication */
|
|
19
|
+
transport: ChatTransport<UI_MESSAGE>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Base configuration for useObject hook.
|
|
23
|
+
*
|
|
24
|
+
* Similar to UseCompletionOptions but for useObject hook.
|
|
25
|
+
* We define this separately since useObject is from @ai-sdk/react, not 'ai'.
|
|
26
|
+
*/
|
|
27
|
+
export interface UseObjectOptions {
|
|
28
|
+
/** API endpoint URL */
|
|
29
|
+
api: string;
|
|
30
|
+
/** Headers to include in requests */
|
|
31
|
+
headers: Record<string, string>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Extended configuration for useObject with schemaId.
|
|
35
|
+
*
|
|
36
|
+
* This is Aippy-specific: we use schemaId to reference a pre-registered
|
|
37
|
+
* schema on the backend instead of passing the schema directly.
|
|
38
|
+
*/
|
|
39
|
+
export interface UseObjectConfigWithSchema extends UseObjectOptions {
|
|
40
|
+
/**
|
|
41
|
+
* Schema identifier registered on the backend.
|
|
42
|
+
* This will be included in the request body.
|
|
43
|
+
*/
|
|
44
|
+
schemaId: string;
|
|
45
|
+
}
|
|
46
|
+
export type { UseChatBody };
|
package/dist/ai.d.ts
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { a as K } from "./runtime-CmoG3v2m.js";
|
|
2
|
+
import { h as y } from "./native-bridge-JAmH-zTN.js";
|
|
3
|
+
const U = {
|
|
4
|
+
apiBaseUrl: "https://api.aippy.dev/api",
|
|
5
|
+
authToken: "",
|
|
6
|
+
// 默认为空,由 iOS 桥接填充
|
|
7
|
+
currentUserId: null,
|
|
8
|
+
// 默认为空,由 iOS 桥接填充
|
|
9
|
+
cacheTime: 300 * 1e3
|
|
10
|
+
// 5 minutes
|
|
11
|
+
};
|
|
12
|
+
let u = { ...U };
|
|
13
|
+
function h(r) {
|
|
14
|
+
u = {
|
|
15
|
+
...U,
|
|
16
|
+
...r
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function R() {
|
|
20
|
+
return u;
|
|
21
|
+
}
|
|
22
|
+
function w(r) {
|
|
23
|
+
u.authToken = r;
|
|
24
|
+
}
|
|
25
|
+
function B(r) {
|
|
26
|
+
u.currentUserId = r;
|
|
27
|
+
}
|
|
28
|
+
function P() {
|
|
29
|
+
return u.authToken;
|
|
30
|
+
}
|
|
31
|
+
const a = {
|
|
32
|
+
uid: "",
|
|
33
|
+
token: "",
|
|
34
|
+
apiBaseUrl: void 0
|
|
35
|
+
}, D = 5e3;
|
|
36
|
+
let d = !1, m = !1, l = null, o = null;
|
|
37
|
+
function g() {
|
|
38
|
+
try {
|
|
39
|
+
return typeof window < "u" && window.parent !== window;
|
|
40
|
+
} catch {
|
|
41
|
+
return !0;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function k(r = D) {
|
|
45
|
+
return new Promise((e) => {
|
|
46
|
+
if (!g()) {
|
|
47
|
+
console.log("ℹ️ [UserSDK Bridge] Not in iframe, skipping parent request"), e(a);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
console.log("📤 [UserSDK Bridge] Requesting credentials from parent window");
|
|
51
|
+
const i = setTimeout(() => {
|
|
52
|
+
console.warn(`⚠️ [UserSDK Bridge] Parent request timeout (${r}ms)`), window.removeEventListener("message", n), e(a);
|
|
53
|
+
}, r), n = (t) => {
|
|
54
|
+
if (t.data && t.data.type === "user-credentials-response") {
|
|
55
|
+
console.log("📩 [UserSDK Bridge] Received credentials from parent:", t.data), clearTimeout(i), window.removeEventListener("message", n);
|
|
56
|
+
const s = f(t.data);
|
|
57
|
+
e(s || a);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
window.addEventListener("message", n);
|
|
61
|
+
try {
|
|
62
|
+
window.parent.postMessage({
|
|
63
|
+
type: "user-credentials-request",
|
|
64
|
+
timestamp: Date.now()
|
|
65
|
+
}, "*");
|
|
66
|
+
} catch (t) {
|
|
67
|
+
console.error("❌ [UserSDK Bridge] Failed to send request to parent:", t), clearTimeout(i), window.removeEventListener("message", n), e(a);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function C() {
|
|
72
|
+
if (!g())
|
|
73
|
+
return null;
|
|
74
|
+
try {
|
|
75
|
+
const r = window.parent.localStorage.getItem("token"), e = window.parent.localStorage.getItem("user");
|
|
76
|
+
if (!r || !e)
|
|
77
|
+
return console.log("ℹ️ [UserSDK Bridge] Parent localStorage credentials not found"), null;
|
|
78
|
+
const i = JSON.parse(e), n = i.uid || i.userId || i.id || "";
|
|
79
|
+
if (!n)
|
|
80
|
+
return console.warn("⚠️ [UserSDK Bridge] Parent user data missing uid"), null;
|
|
81
|
+
const t = {
|
|
82
|
+
uid: String(n),
|
|
83
|
+
token: r,
|
|
84
|
+
apiBaseUrl: void 0
|
|
85
|
+
};
|
|
86
|
+
return B(t.uid), w(t.token), console.log("✅ [UserSDK Bridge] Got credentials from parent localStorage:", t.uid), l = t, d = !0, t;
|
|
87
|
+
} catch {
|
|
88
|
+
return console.log("ℹ️ [UserSDK Bridge] Cannot access parent localStorage (cross-origin), will use postMessage"), null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function v(r = D) {
|
|
92
|
+
return d && l ? (console.log("✅ [UserSDK Bridge] Returning cached credentials"), Promise.resolve(l)) : m && !d ? (console.log("ℹ️ [UserSDK Bridge] Previous request failed, returning empty credentials"), Promise.resolve(a)) : o ? (console.log("⏳ [UserSDK Bridge] Request already pending, waiting..."), new Promise((e) => {
|
|
93
|
+
const i = o.resolve;
|
|
94
|
+
o.resolve = (n) => {
|
|
95
|
+
i(n), e(n);
|
|
96
|
+
};
|
|
97
|
+
})) : new Promise((e) => {
|
|
98
|
+
m = !0;
|
|
99
|
+
const i = window.webkit?.messageHandlers?.aippyListener;
|
|
100
|
+
if (!i) {
|
|
101
|
+
console.warn("⚠️ [UserSDK Bridge] Native bridge not available, returning empty credentials"), e(a);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const n = setTimeout(() => {
|
|
105
|
+
console.warn(`⚠️ [UserSDK Bridge] Request timeout (${r}ms), returning empty credentials`), o = null, e(a);
|
|
106
|
+
}, r);
|
|
107
|
+
o = { resolve: e, reject: () => {
|
|
108
|
+
} };
|
|
109
|
+
const t = K.receiveChannel.once("user.credentials", (s) => {
|
|
110
|
+
console.log("📩 [UserSDK Bridge] Received credentials via receiveChannel:", s), clearTimeout(n);
|
|
111
|
+
const c = f(s);
|
|
112
|
+
c ? o?.resolve(c) : o?.resolve(a), o = null;
|
|
113
|
+
});
|
|
114
|
+
try {
|
|
115
|
+
const s = {
|
|
116
|
+
command: "user.getCredentials",
|
|
117
|
+
parameters: JSON.stringify({
|
|
118
|
+
timestamp: Date.now(),
|
|
119
|
+
endpoint: "user.credentials"
|
|
120
|
+
// Tell iOS which endpoint to respond to
|
|
121
|
+
})
|
|
122
|
+
};
|
|
123
|
+
console.log("📤 [UserSDK Bridge] Requesting credentials from iOS:", s), i.postMessage(s);
|
|
124
|
+
} catch (s) {
|
|
125
|
+
console.error("❌ [UserSDK Bridge] Failed to send request to iOS:", s), clearTimeout(n), t.cancel(), o = null, e(a);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function f(r) {
|
|
130
|
+
if (!r || typeof r != "object")
|
|
131
|
+
return console.warn("⚠️ [UserSDK Bridge] Invalid credentials data:", r), null;
|
|
132
|
+
let e = r;
|
|
133
|
+
if (e.credentials && typeof e.credentials == "object" && (console.log("📦 [UserSDK Bridge] Detected nested credentials format"), e = e.credentials), e.user && typeof e.user == "object" && e.token) {
|
|
134
|
+
console.log("📦 [UserSDK Bridge] Detected parent window format");
|
|
135
|
+
const c = e.user;
|
|
136
|
+
e = {
|
|
137
|
+
uid: c.uid || c.userId || c.id,
|
|
138
|
+
token: e.token,
|
|
139
|
+
apiBaseUrl: e.apiBaseUrl
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
const i = e.uid || e.userId || e.id || "", n = e.token || e.authToken || "", t = e.apiBaseUrl || e.baseUrl;
|
|
143
|
+
if (!i || !n)
|
|
144
|
+
return console.warn("⚠️ [UserSDK Bridge] Missing uid or token in credentials:", r), null;
|
|
145
|
+
const s = { uid: String(i), token: n, apiBaseUrl: t };
|
|
146
|
+
return B(s.uid), w(n), t && h({ apiBaseUrl: t }), console.log("✅ [UserSDK Bridge] Config updated with credentials:", s.uid), l = s, d = !0, s;
|
|
147
|
+
}
|
|
148
|
+
function S(r) {
|
|
149
|
+
console.log("📩 [UserSDK Bridge] processUserCredentials called with:", r);
|
|
150
|
+
const e = f(r);
|
|
151
|
+
e && o && (o.resolve(e), o = null);
|
|
152
|
+
}
|
|
153
|
+
function T() {
|
|
154
|
+
typeof window > "u" || (window.processUserCredentials = S, window.addEventListener("message", (r) => {
|
|
155
|
+
r.data && r.data.type === "user-credentials" && (console.log("📩 [UserSDK Bridge] Received credentials via postMessage:", r.data), S(r.data));
|
|
156
|
+
}), console.log("✅ [UserSDK Bridge] Bridge initialized"));
|
|
157
|
+
}
|
|
158
|
+
async function p() {
|
|
159
|
+
if (d && l) {
|
|
160
|
+
console.log("✅ [UserSDK Bridge] Already have cached credentials");
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (y()) {
|
|
164
|
+
console.log("🔍 [UserSDK Bridge] Detected iOS environment, requesting from native");
|
|
165
|
+
try {
|
|
166
|
+
if (await v(), d) {
|
|
167
|
+
console.log("✅ [UserSDK Bridge] Got credentials from iOS");
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
} catch (r) {
|
|
171
|
+
console.warn("⚠️ [UserSDK Bridge] iOS request failed:", r);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (g()) {
|
|
175
|
+
if (console.log("🔍 [UserSDK Bridge] Detected iframe environment"), C()) {
|
|
176
|
+
console.log("✅ [UserSDK Bridge] Got credentials from parent localStorage");
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
console.log("🔍 [UserSDK Bridge] Trying postMessage to parent");
|
|
180
|
+
try {
|
|
181
|
+
const e = await k();
|
|
182
|
+
if (e.uid && e.token) {
|
|
183
|
+
console.log("✅ [UserSDK Bridge] Got credentials from parent postMessage");
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
} catch (e) {
|
|
187
|
+
console.warn("⚠️ [UserSDK Bridge] Parent postMessage request failed:", e);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
console.log("ℹ️ [UserSDK Bridge] No credentials source available");
|
|
191
|
+
}
|
|
192
|
+
async function b() {
|
|
193
|
+
return await p(), l?.token || "";
|
|
194
|
+
}
|
|
195
|
+
async function E() {
|
|
196
|
+
return await p(), l?.uid || "";
|
|
197
|
+
}
|
|
198
|
+
function O() {
|
|
199
|
+
return d;
|
|
200
|
+
}
|
|
201
|
+
function A() {
|
|
202
|
+
return l;
|
|
203
|
+
}
|
|
204
|
+
T();
|
|
205
|
+
p();
|
|
206
|
+
export {
|
|
207
|
+
B as a,
|
|
208
|
+
P as b,
|
|
209
|
+
g as c,
|
|
210
|
+
k as d,
|
|
211
|
+
T as e,
|
|
212
|
+
p as f,
|
|
213
|
+
R as g,
|
|
214
|
+
b as h,
|
|
215
|
+
h as i,
|
|
216
|
+
E as j,
|
|
217
|
+
O as k,
|
|
218
|
+
A as l,
|
|
219
|
+
v as r,
|
|
220
|
+
w as s,
|
|
221
|
+
C as t
|
|
222
|
+
};
|