@rork-ai/toolkit-sdk 0.2.42 → 0.2.43
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/{src/metro → metro}/index.js +2 -1
- package/{src/metro → metro}/transformer.js +1 -0
- package/package.json +4 -8
- package/lib/module/metro/index.js +0 -79
- package/lib/module/metro/index.js.map +0 -1
- package/lib/module/metro/transformer.js +0 -111
- package/lib/module/metro/transformer.js.map +0 -1
- package/src/agent.ts +0 -173
- package/src/analytics.tsx +0 -70
- package/src/api.ts +0 -8
- package/src/bridge.ts +0 -47
- package/src/dev/error-boundary.tsx +0 -161
- package/src/dev/safe-insets-content.tsx +0 -7
- package/src/dev/safe-insets-content.web.tsx +0 -57
- package/src/dev/sdk53/index.tsx +0 -13
- package/src/dev/sdk53/inspector.tsx +0 -467
- package/src/dev/sdk53/inspector.web.tsx +0 -3
- package/src/dev/sdk54/index.tsx +0 -13
- package/src/dev/sdk54/inspector.tsx +0 -345
- package/src/dev/sdk54/inspector.web.tsx +0 -3
- package/src/index.tsx +0 -3
- package/src/integrations.ts +0 -74
- package/src/polyfills/alert.web.ts +0 -3
- package/src/polyfills/fetch.ts +0 -16
- package/src/polyfills/fetch.web.ts +0 -1
- package/src/polyfills/haptics.web.ts +0 -68
- package/src/polyfills/maps.web.tsx +0 -42
- package/src/polyfills/refresh-control-component.tsx +0 -215
- package/src/polyfills/secure-store.web.ts +0 -111
- package/src/utils.ts +0 -3
|
@@ -6,7 +6,7 @@ const path = require("path");
|
|
|
6
6
|
* and redirects expo-haptics to web polyfill on web platform
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
const libPath = path.resolve(__dirname, "
|
|
9
|
+
const libPath = path.resolve(__dirname, "../lib/module/");
|
|
10
10
|
|
|
11
11
|
function withRorkMetro(config) {
|
|
12
12
|
const originalResolveRequest = config.resolver?.resolveRequest;
|
|
@@ -89,3 +89,4 @@ function withRorkMetro(config) {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
module.exports = { withRorkMetro };
|
|
92
|
+
|
package/package.json
CHANGED
|
@@ -1,36 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rork-ai/toolkit-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.43",
|
|
4
4
|
"description": "toolkit-sdk",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
-
"source": "./src/index.tsx",
|
|
10
9
|
"types": "./lib/typescript/src/index.d.ts",
|
|
11
10
|
"default": "./lib/module/index.js"
|
|
12
11
|
},
|
|
13
12
|
"./package.json": "./package.json",
|
|
14
13
|
"./metro": {
|
|
15
|
-
"default": "./
|
|
14
|
+
"default": "./metro/index.js"
|
|
16
15
|
},
|
|
17
16
|
"./metro-transformer": {
|
|
18
|
-
"default": "./
|
|
17
|
+
"default": "./metro/transformer.js"
|
|
19
18
|
},
|
|
20
19
|
"./v53": {
|
|
21
|
-
"source": "./src/dev/sdk53/index.tsx",
|
|
22
20
|
"types": "./lib/typescript/src/dev/sdk53/index.d.ts",
|
|
23
21
|
"default": "./lib/module/dev/sdk53/index.js"
|
|
24
22
|
},
|
|
25
23
|
"./v54": {
|
|
26
|
-
"source": "./src/dev/sdk54/index.tsx",
|
|
27
24
|
"types": "./lib/typescript/src/dev/sdk54/index.d.ts",
|
|
28
25
|
"default": "./lib/module/dev/sdk54/index.js"
|
|
29
26
|
}
|
|
30
27
|
},
|
|
31
28
|
"files": [
|
|
32
|
-
"src",
|
|
33
29
|
"lib",
|
|
30
|
+
"metro",
|
|
34
31
|
"android",
|
|
35
32
|
"ios",
|
|
36
33
|
"cpp",
|
|
@@ -157,7 +154,6 @@
|
|
|
157
154
|
"@teovilla/react-native-web-maps": "^0.9.5",
|
|
158
155
|
"@ungap/structured-clone": "^1.3.0",
|
|
159
156
|
"ai": "5.0.93",
|
|
160
|
-
"assert": "^2.1.0",
|
|
161
157
|
"posthog-react-native": "4.13.0"
|
|
162
158
|
},
|
|
163
159
|
"scripts": {
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const path = require("path");
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Metro configuration helper for Rork
|
|
7
|
-
* Automatically wraps _layout.tsx with Rork providers
|
|
8
|
-
* and redirects expo-haptics to web polyfill on web platform
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const libPath = path.resolve(__dirname, "../../lib/module/");
|
|
12
|
-
function withRorkMetro(config) {
|
|
13
|
-
const originalResolveRequest = config.resolver?.resolveRequest;
|
|
14
|
-
return {
|
|
15
|
-
...config,
|
|
16
|
-
transformer: {
|
|
17
|
-
...config.transformer,
|
|
18
|
-
babelTransformerPath: require.resolve("@rork-ai/toolkit-sdk/metro-transformer")
|
|
19
|
-
},
|
|
20
|
-
resolver: {
|
|
21
|
-
...config.resolver,
|
|
22
|
-
extraNodeModules: {
|
|
23
|
-
// whenever some lib does `require("assert")`
|
|
24
|
-
// it will get this package
|
|
25
|
-
assert: require.resolve("assert"),
|
|
26
|
-
...config.resolver?.extraNodeModules
|
|
27
|
-
},
|
|
28
|
-
resolveRequest: (context, moduleName, platform) => {
|
|
29
|
-
// Redirect expo-haptics to our web polyfill on web platform
|
|
30
|
-
if (moduleName === "expo-haptics" && platform === "web") {
|
|
31
|
-
return {
|
|
32
|
-
filePath: path.resolve(libPath, "polyfills/haptics.web.js"),
|
|
33
|
-
type: "sourceFile"
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
if (moduleName === "expo-secure-store" && platform === "web") {
|
|
37
|
-
return {
|
|
38
|
-
filePath: path.resolve(libPath, "polyfills/secure-store.web.js"),
|
|
39
|
-
type: "sourceFile"
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Redirect react-native-maps to our web polyfill on web platform
|
|
44
|
-
if (moduleName === "react-native-maps" && platform === "web") {
|
|
45
|
-
return {
|
|
46
|
-
filePath: path.resolve(libPath, "polyfills/maps.web.js"),
|
|
47
|
-
type: "sourceFile"
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Redirect react-native to our web polyfill on web platform
|
|
52
|
-
// This replaces RefreshControl with our web implementation
|
|
53
|
-
if (moduleName === "react-native-web/dist/exports/RefreshControl" && platform === "web") {
|
|
54
|
-
return {
|
|
55
|
-
filePath: path.resolve(libPath, "polyfills/refresh-control-component.js"),
|
|
56
|
-
type: "sourceFile"
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Redirect react-native to our web polyfill on web platform
|
|
61
|
-
// This replaces RefreshControl with our web implementation
|
|
62
|
-
if (moduleName === "react-native-web/dist/exports/Alert" && platform === "web") {
|
|
63
|
-
return {
|
|
64
|
-
filePath: path.resolve(libPath, "polyfills/alert.web.js"),
|
|
65
|
-
type: "sourceFile"
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
if (originalResolveRequest) {
|
|
69
|
-
return originalResolveRequest(context, moduleName, platform);
|
|
70
|
-
}
|
|
71
|
-
return context.resolveRequest(context, moduleName, platform);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
module.exports = {
|
|
77
|
-
withRorkMetro
|
|
78
|
-
};
|
|
79
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["path","require","libPath","resolve","__dirname","withRorkMetro","config","originalResolveRequest","resolver","resolveRequest","transformer","babelTransformerPath","extraNodeModules","assert","context","moduleName","platform","filePath","type","module","exports"],"sourceRoot":"../../../src","sources":["metro/index.js"],"mappings":";;AAAA,MAAMA,IAAI,GAAGC,OAAO,CAAC,MAAM,CAAC;;AAE5B;AACA;AACA;AACA;AACA;;AAEA,MAAMC,OAAO,GAAGF,IA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AAI,CAACG,OAAO,CACpBD,OAAO,EACP,wCACF,CAAC;YACDgB,IAAI,EAAE;UACR,CAAC;QACH;;QAEA;QACA;QACA,IACEH,UAAU,KAAK,qCAAqC,IACpDC,QAAQ,KAAK,KAAK,EAClB;UACA,OAAO;YACLC,QAAQ,EAAEjB,IAAI,CAACG,OAAO,CAACD,OAAO,EAAE,wBAAwB,CAAC;YACzDgB,IAAI,EAAE;UACR,CAAC;QACH;QAEA,IAAIX,sBAAsB,EAAE;UAC1B,OAAOA,sBAAsB,CAACO,OAAO,EAAEC,UAAU,EAAEC,QAAQ,CAAC;QAC9D;QAEA,OAAOF,OAAO,CAACL,cAAc,CAACK,OAAO,EAAEC,UAAU,EAAEC,QAAQ,CAAC;MAC9D;IACF;EACF,CAAC;AACH;AAEAG,MAAM,CAACC,OAAO,GAAG;EAAEf;AAAc,CAAC","ignoreList":[]}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Metro transformer that automatically wraps _layout.tsx with Rork providers
|
|
5
|
-
* Uses simple string transformations to inject wrappers
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const fs = require("fs");
|
|
9
|
-
const path = require("path");
|
|
10
|
-
const upstreamTransformer = require("@expo/metro-config/babel-transformer");
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Detects the Expo SDK version from the installed expo package
|
|
14
|
-
* This approach works with all package managers (npm, yarn, pnpm)
|
|
15
|
-
*/
|
|
16
|
-
function detectExpoVersion() {
|
|
17
|
-
try {
|
|
18
|
-
// Read version from installed expo package (works with pnpm, npm, yarn)
|
|
19
|
-
const expoPackagePath = path.join(process.cwd(), "node_modules", "expo", "package.json");
|
|
20
|
-
if (fs.existsSync(expoPackagePath)) {
|
|
21
|
-
const expoPackage = JSON.parse(fs.readFileSync(expoPackagePath, "utf8"));
|
|
22
|
-
const version = expoPackage.version;
|
|
23
|
-
if (version) {
|
|
24
|
-
if (version.startsWith("54.")) return "54";
|
|
25
|
-
if (version.startsWith("53.")) return "53";
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
} catch {
|
|
29
|
-
// Ignore parsing errors
|
|
30
|
-
}
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Checks if the file is the root _layout.tsx
|
|
36
|
-
*/
|
|
37
|
-
function isRootLayout(filename) {
|
|
38
|
-
return (filename.includes("app/_layout.tsx") || filename.includes("app/_layout.js")) && !filename.includes("app/(") // Exclude grouped layouts
|
|
39
|
-
;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Wraps the layout component with Rork providers
|
|
44
|
-
*/
|
|
45
|
-
function wrapLayoutWithProviders(src, environment) {
|
|
46
|
-
// Find the default export function
|
|
47
|
-
const defaultExportPattern = /export\s+default\s+function\s+(\w+)/;
|
|
48
|
-
const match = src.match(defaultExportPattern);
|
|
49
|
-
if (!match) {
|
|
50
|
-
return src; // Can't transform, return as-is
|
|
51
|
-
}
|
|
52
|
-
const originalFunctionName = match[1];
|
|
53
|
-
|
|
54
|
-
// Remove the default keyword from the original function
|
|
55
|
-
let transformed = src.replace(defaultExportPattern, `function ${originalFunctionName}`);
|
|
56
|
-
const wrappers = [];
|
|
57
|
-
|
|
58
|
-
// Add RorkDevWrapper for development environment
|
|
59
|
-
if (environment === "development") {
|
|
60
|
-
// Detect Expo SDK version - default to v53 if not detected
|
|
61
|
-
const version = detectExpoVersion() || "53";
|
|
62
|
-
const devImport = version === "54" ? "import { RorkDevWrapper } from '@rork-ai/toolkit-sdk/v54';" : "import { RorkDevWrapper } from '@rork-ai/toolkit-sdk/v53';";
|
|
63
|
-
wrappers.push({
|
|
64
|
-
import: devImport,
|
|
65
|
-
name: "RorkDevWrapper"
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Always add AnalyticsProvider
|
|
70
|
-
wrappers.push({
|
|
71
|
-
import: "import { AnalyticsProvider } from '@rork-ai/toolkit-sdk';",
|
|
72
|
-
name: "AnalyticsProvider"
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
// Add wrapper imports at the top
|
|
76
|
-
for (const wrapper of wrappers) {
|
|
77
|
-
transformed = `${wrapper.import}\n${transformed}`;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Create the wrapped component JSX
|
|
81
|
-
let wrappedComponent = `<${originalFunctionName} />`;
|
|
82
|
-
for (const wrapper of wrappers) {
|
|
83
|
-
wrappedComponent = `<${wrapper.name}>${wrappedComponent}</${wrapper.name}>`;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Add new default export that wraps the original function
|
|
87
|
-
const newDefaultExport = `
|
|
88
|
-
export default function RorkRootLayoutWrapper() {
|
|
89
|
-
return (
|
|
90
|
-
${wrappedComponent}
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
`;
|
|
94
|
-
transformed = transformed + "\n" + newDefaultExport;
|
|
95
|
-
return transformed;
|
|
96
|
-
}
|
|
97
|
-
async function transform(props) {
|
|
98
|
-
const environment = props.options?.dev ?? process.env.NODE_ENV === "development" ? "development" : "production";
|
|
99
|
-
if (isRootLayout(props.filename)) {
|
|
100
|
-
const transformedSrc = wrapLayoutWithProviders(props.src, environment);
|
|
101
|
-
return upstreamTransformer.transform({
|
|
102
|
-
...props,
|
|
103
|
-
src: transformedSrc
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
return upstreamTransformer.transform(props);
|
|
107
|
-
}
|
|
108
|
-
module.exports = {
|
|
109
|
-
transform
|
|
110
|
-
};
|
|
111
|
-
//# sourceMappingURL=transformer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["fs","require","path","upstreamTransformer","detectExpoVersion","expoPackagePath","join","process","cwd","existsSync","expoPackage","JSON","parse","readFileSync","version","startsWith","isRootLayout","filename","includes","wrapLayoutWithProviders","src","environment","defaultExportPattern","match","originalFunctionName","transformed","replace","wrappers","devImport","push","import","name","wrapper","wrappedComponent","newDefaultExport","transform","props","options","dev","env","NODE_ENV","transformedSrc","module","exports"],"sourceRoot":"../../../src","sources":["metro/transformer.js"],"mappings":";;AAAA;AACA;AACA;AACA;;AAEA,MAAMA,EAAE,GAAGC,OAAO,CAAC,IAAI,CAAC;AACxB,MAAMC,IAAI,GAAGD,OAAO,CAAC,MAAM,CAAC;AAE5B,MAAME,mBAAmB,GAAGF,OAAO,CAAC,sCAAsC,CAAC;;AAE3E;AACA;AACA;AACA;AACA,SAASG,iBAAiBA,CAAA,EAAG;EAC3B,IAAI;IACF;IACA,MAAMC,eAAe,GAAGH,IAAI,CAACI,IAAI,CAC/BC,OAAO,CAACC,GAAG,CAAC,CAAC,EACb,cAAc,EACd,MAAM,EACN,cACF,CAAC;IACD,IAAIR,EAAE,CAACS,UAAU,CAACJ,eAAe,CAAC,EAAE;MAClC,MAAMK,WAAW,GAAGC,IAAI,CAACC,KAAK,CAACZ,EAAE,CAACa,YAAY,CAACR,eAAe,EAAE,MAAM,CAAC,CAAC;MACxE,MAAMS,OAAO,GAAGJ,WAAW,CAACI,OAAO;MACnC,IAAIA,OAAO,EAAE;QACX,IAAIA,OAAO,CAACC,UAAU,CAAC,KAAK,CAAC,EAAE,OAAO,IAAI;QAC1C,IAAID,OAAO,CAACC,UAAU,CAAC,KAAK,CAAC,EAAE,OAAO,IAAI;MAC5C;IACF;EACF,CAAC,CAAC,MAAM;IACN;EAAA;EAEF,OAAO,IAAI;AACb;;AAEA;AACA;AACA;AACA,SAASC,YAAYA,CAACC,QAAQ,EAAE;EAC9B,OACE,CAACA,QAAQ,CAACC,QAAQ,CAAC,iBAAiB,CAAC,IACnCD,QAAQ,CAACC,QAAQ,CAAC,gBAAgB,CAAC,KACrC,CAACD,QAAQ,CAACC,QAAQ,CAAC,OAAO,CAAC,CAAC;EAAA;AAEhC;;AAEA;AACA;AACA;AACA,SAASC,uBAAuBA,CAACC,G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AgB;EAEnD,OAAOT,WAAW;AACpB;AAEA,eAAeU,SAASA,CAACC,KAAK,EAAE;EAC9B,MAAMf,WAAW,GACde,KAAK,CAACC,OAAO,EAAEC,GAAG,IAAI/B,OAAO,CAACgC,GAAG,CAACC,QAAQ,KAAK,aAAa,GACzD,aAAa,GACb,YAAY;EAElB,IAAIxB,YAAY,CAACoB,KAAK,CAACnB,QAAQ,CAAC,EAAE;IAChC,MAAMwB,cAAc,GAAGtB,uBAAuB,CAACiB,KAAK,CAAChB,GAAG,EAAEC,WAAW,CAAC;IACtE,OAAOlB,mBAAmB,CAACgC,SAAS,CAAC;MAAE,GAAGC,KAAK;MAAEhB,GAAG,EAAEqB;IAAe,CAAC,CAAC;EACzE;EAEA,OAAOtC,mBAAmB,CAACgC,SAAS,CAACC,KAAK,CAAC;AAC7C;AAEAM,MAAM,CAACC,OAAO,GAAG;EAAER;AAAU,CAAC","ignoreList":[]}
|
package/src/agent.ts
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { useChat, type UseChatOptions } from "@ai-sdk/react";
|
|
2
|
-
import {
|
|
3
|
-
DefaultChatTransport,
|
|
4
|
-
lastAssistantMessageIsCompleteWithToolCalls,
|
|
5
|
-
type ToolUIPart,
|
|
6
|
-
type UIMessage,
|
|
7
|
-
} from "ai";
|
|
8
|
-
import { fetch as expoFetch } from "expo/fetch";
|
|
9
|
-
import { useCallback, useMemo } from "react";
|
|
10
|
-
import * as z from "zod/v4";
|
|
11
|
-
|
|
12
|
-
import { BASE_URL, withBaseUrl } from "./api";
|
|
13
|
-
|
|
14
|
-
import "./polyfills/fetch";
|
|
15
|
-
|
|
16
|
-
import { getPostHogClient } from "./analytics";
|
|
17
|
-
|
|
18
|
-
const AGENT_URL = withBaseUrl("/agent/chat");
|
|
19
|
-
|
|
20
|
-
type Tool<T extends z.ZodType = z.ZodType> = {
|
|
21
|
-
description: string;
|
|
22
|
-
zodSchema: T;
|
|
23
|
-
execute?: (input: z.infer<T>) => Promise<string> | string;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export function createRorkTool<T extends z.ZodType>(tool: Tool<T>): Tool<T> {
|
|
27
|
-
return tool;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
type TextPart = { type: "text"; text: string };
|
|
31
|
-
type ImagePart = { type: "image"; image: string };
|
|
32
|
-
type UserMessage = { role: "user"; content: string | (TextPart | ImagePart)[] };
|
|
33
|
-
type AssistantMessage = { role: "assistant"; content: string | TextPart[] };
|
|
34
|
-
|
|
35
|
-
// use generateObject and generate text only if you need a single generation.
|
|
36
|
-
// When the chat history and agentic flows are not needed
|
|
37
|
-
// For example, parsing image to text in mutation.
|
|
38
|
-
// or generating a caption for image, or a summary
|
|
39
|
-
|
|
40
|
-
export async function generateObject<T extends z.ZodType>(params: {
|
|
41
|
-
messages: (UserMessage | AssistantMessage)[];
|
|
42
|
-
schema: T;
|
|
43
|
-
}): Promise<z.infer<T>> {
|
|
44
|
-
getPostHogClient()?.capture("RORK/GENERATE_OBJECT", {});
|
|
45
|
-
const GENERATE_OBJECT_URL = new URL("/llm/object", BASE_URL).toString();
|
|
46
|
-
const result = await fetch(GENERATE_OBJECT_URL, {
|
|
47
|
-
method: "POST",
|
|
48
|
-
body: JSON.stringify({
|
|
49
|
-
messages: params.messages,
|
|
50
|
-
schema: z.toJSONSchema(params.schema),
|
|
51
|
-
}),
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const data = await result.json();
|
|
55
|
-
|
|
56
|
-
return params.schema.parse(data.object);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export async function generateText(
|
|
60
|
-
params: string | { messages: (UserMessage | AssistantMessage)[] },
|
|
61
|
-
): Promise<string> {
|
|
62
|
-
getPostHogClient()?.capture("RORK/GENERATE_TEXT", {});
|
|
63
|
-
const GENERATE_TEXT_URL = new URL("/llm/text", BASE_URL).toString();
|
|
64
|
-
const messages =
|
|
65
|
-
typeof params === "string"
|
|
66
|
-
? [{ role: "user", content: params }]
|
|
67
|
-
: params.messages;
|
|
68
|
-
const result = await fetch(GENERATE_TEXT_URL, {
|
|
69
|
-
method: "POST",
|
|
70
|
-
body: JSON.stringify({ messages }),
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const data = await result.json();
|
|
74
|
-
|
|
75
|
-
return data.completion;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function useRorkAgent<T extends Record<string, Tool<z.ZodType>>>(
|
|
79
|
-
options: Omit<UseChatOptions<UIMessage>, "transport"> & {
|
|
80
|
-
tools: T;
|
|
81
|
-
},
|
|
82
|
-
) {
|
|
83
|
-
const { addToolResult, ...rest } = useChat({
|
|
84
|
-
...options,
|
|
85
|
-
sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithToolCalls,
|
|
86
|
-
transport: new DefaultChatTransport({
|
|
87
|
-
fetch: expoFetch as unknown as typeof globalThis.fetch,
|
|
88
|
-
api: AGENT_URL,
|
|
89
|
-
body: () => {
|
|
90
|
-
const toolsEntries = Object.entries(options.tools).map(
|
|
91
|
-
([name, tool]) => [
|
|
92
|
-
name,
|
|
93
|
-
{
|
|
94
|
-
description: tool.description,
|
|
95
|
-
jsonSchema: z.toJSONSchema(tool.zodSchema),
|
|
96
|
-
},
|
|
97
|
-
],
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
return {
|
|
101
|
-
tools: Object.fromEntries(toolsEntries),
|
|
102
|
-
};
|
|
103
|
-
},
|
|
104
|
-
}),
|
|
105
|
-
onToolCall: async ({ toolCall }) => {
|
|
106
|
-
getPostHogClient()?.capture("RORK/USE_AGENT/TOOL_CALL", {
|
|
107
|
-
toolName: toolCall.toolName,
|
|
108
|
-
});
|
|
109
|
-
const tool = options.tools[toolCall.toolName];
|
|
110
|
-
|
|
111
|
-
if (!tool) {
|
|
112
|
-
throw new Error(`Tool ${toolCall.dynamic} not found`);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (!tool.execute) return;
|
|
116
|
-
|
|
117
|
-
const result = await tool.execute(toolCall.input);
|
|
118
|
-
addToolResult({
|
|
119
|
-
toolCallId: toolCall.toolCallId,
|
|
120
|
-
tool: toolCall.toolName,
|
|
121
|
-
output: result,
|
|
122
|
-
});
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
const messages = useMemo(() => {
|
|
127
|
-
return rest.messages.map((m) => {
|
|
128
|
-
const parts = m.parts
|
|
129
|
-
.map((p) => {
|
|
130
|
-
if (p.type === "text") return p;
|
|
131
|
-
if (p.type.startsWith("tool")) {
|
|
132
|
-
const toolPart = p as ToolUIPart;
|
|
133
|
-
const toolName = toolPart.type.replace(/^tool-/, "");
|
|
134
|
-
|
|
135
|
-
return {
|
|
136
|
-
...(p as ToolUIPart),
|
|
137
|
-
type: "tool",
|
|
138
|
-
toolName,
|
|
139
|
-
} satisfies Omit<ToolUIPart, "type"> & {
|
|
140
|
-
type: "tool";
|
|
141
|
-
toolName: string;
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return undefined;
|
|
146
|
-
})
|
|
147
|
-
.filter((p) => p !== undefined);
|
|
148
|
-
|
|
149
|
-
return { ...m, parts };
|
|
150
|
-
});
|
|
151
|
-
}, [rest.messages]);
|
|
152
|
-
|
|
153
|
-
const sendMessage = useCallback(
|
|
154
|
-
(message: string | Parameters<typeof rest.sendMessage>[0]) => {
|
|
155
|
-
getPostHogClient()?.capture("RORK/USE_AGENT/SEND_MESSAGE", {});
|
|
156
|
-
if (typeof message === "string") {
|
|
157
|
-
rest.sendMessage({
|
|
158
|
-
text: message,
|
|
159
|
-
});
|
|
160
|
-
} else {
|
|
161
|
-
rest.sendMessage(message);
|
|
162
|
-
}
|
|
163
|
-
},
|
|
164
|
-
[rest],
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
return {
|
|
168
|
-
...rest,
|
|
169
|
-
sendMessage,
|
|
170
|
-
messages,
|
|
171
|
-
addToolResult,
|
|
172
|
-
};
|
|
173
|
-
}
|
package/src/analytics.tsx
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { useGlobalSearchParams, usePathname } from "expo-router";
|
|
2
|
-
import PostHog, { PostHogProvider } from "posthog-react-native";
|
|
3
|
-
import { useEffect } from "react";
|
|
4
|
-
import { Platform } from "react-native";
|
|
5
|
-
|
|
6
|
-
import { isExpoGo } from "./utils";
|
|
7
|
-
|
|
8
|
-
const projectId = process.env.EXPO_PUBLIC_PROJECT_ID;
|
|
9
|
-
const teamId = process.env.EXPO_PUBLIC_TEAM_ID;
|
|
10
|
-
|
|
11
|
-
const isWeb = Platform.OS === "web";
|
|
12
|
-
|
|
13
|
-
const analyticsDisabled = !projectId || !teamId || isExpoGo() || isWeb;
|
|
14
|
-
|
|
15
|
-
const $groups = { project: projectId, team: teamId };
|
|
16
|
-
|
|
17
|
-
let posthog: PostHog | null = null;
|
|
18
|
-
|
|
19
|
-
// TODO
|
|
20
|
-
type Source =
|
|
21
|
-
| "expo-go"
|
|
22
|
-
| "share-link"
|
|
23
|
-
| "rork-explore"
|
|
24
|
-
| "test-flight"
|
|
25
|
-
| "store"
|
|
26
|
-
| undefined;
|
|
27
|
-
|
|
28
|
-
export function getPostHogClient() {
|
|
29
|
-
if (analyticsDisabled) return null;
|
|
30
|
-
|
|
31
|
-
if (!posthog) {
|
|
32
|
-
posthog = new PostHog("phc_H2a6BKmqSmQJBp2iC6WcAFrRrZdeGX1c6YOiMh9qalF", {
|
|
33
|
-
host: "https://toolkit.rork.com/relay-GnBZ/",
|
|
34
|
-
captureAppLifecycleEvents: true,
|
|
35
|
-
disableCompression: true,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
Object.entries($groups).forEach(([key, value]) => {
|
|
39
|
-
posthog?.group(key, value, {});
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return posthog;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function trackEvent(name: string, properties: Record<string, any>) {
|
|
47
|
-
getPostHogClient()?.capture(name, { user_properties: properties, $groups });
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function AnalyticsProvider({ children }: { children: React.ReactNode }) {
|
|
51
|
-
const pathname = usePathname();
|
|
52
|
-
const params = useGlobalSearchParams();
|
|
53
|
-
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
getPostHogClient()?.screen(pathname, { user_params: params, $groups });
|
|
56
|
-
}, [pathname, params]);
|
|
57
|
-
|
|
58
|
-
const posthogClient = getPostHogClient();
|
|
59
|
-
|
|
60
|
-
if (!posthogClient) return children;
|
|
61
|
-
|
|
62
|
-
return (
|
|
63
|
-
<PostHogProvider
|
|
64
|
-
client={posthogClient}
|
|
65
|
-
autocapture={{ captureTouches: false }}
|
|
66
|
-
>
|
|
67
|
-
{children}
|
|
68
|
-
</PostHogProvider>
|
|
69
|
-
);
|
|
70
|
-
}
|
package/src/api.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export const BASE_URL =
|
|
2
|
-
process.env["EXPO_PUBLIC_TOOLKIT_URL"] ?? "http://localhost:3005";
|
|
3
|
-
|
|
4
|
-
export function withBaseUrl(path: string) {
|
|
5
|
-
const cleanBaseUrl = BASE_URL.replace(/\/$/, "");
|
|
6
|
-
const cleanPath = path.replace(/^\//, "");
|
|
7
|
-
return `${cleanBaseUrl}/${cleanPath}`;
|
|
8
|
-
}
|
package/src/bridge.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
requireOptionalNativeModule,
|
|
3
|
-
type EventSubscription,
|
|
4
|
-
} from "expo-modules-core";
|
|
5
|
-
import { useEffect, useRef } from "react";
|
|
6
|
-
|
|
7
|
-
const BridgeModule = requireOptionalNativeModule("Bridge");
|
|
8
|
-
|
|
9
|
-
export function sendBridgeMessage(
|
|
10
|
-
type:
|
|
11
|
-
| "inspector-element"
|
|
12
|
-
| "merge-inspector-state"
|
|
13
|
-
| "runtime-ready"
|
|
14
|
-
| "runtime-error",
|
|
15
|
-
data?: Record<string, any>,
|
|
16
|
-
) {
|
|
17
|
-
if (data) {
|
|
18
|
-
return BridgeModule?.sendMessage({ type, data: JSON.stringify(data) });
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return BridgeModule?.sendMessage({ type });
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function addBridgeListener(
|
|
25
|
-
listener: (data: Record<string, any>) => void,
|
|
26
|
-
): EventSubscription {
|
|
27
|
-
return BridgeModule?.addListener("onMessage", (data: any) => {
|
|
28
|
-
if (typeof data !== "object") return;
|
|
29
|
-
if (data.data) {
|
|
30
|
-
listener({ ...data, data: JSON.parse(data.data) });
|
|
31
|
-
} else {
|
|
32
|
-
listener(data);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function useBridgeListener(
|
|
38
|
-
listener: (data: Record<string, any>) => void,
|
|
39
|
-
) {
|
|
40
|
-
const listenerRef = useRef(listener);
|
|
41
|
-
listenerRef.current = listener;
|
|
42
|
-
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
const subscription = addBridgeListener(listenerRef.current);
|
|
45
|
-
return () => subscription.remove();
|
|
46
|
-
}, [listenerRef.current]);
|
|
47
|
-
}
|