mirror of
https://github.com/stablyai/orca.git
synced 2026-11-13 17:37:40 +00:00
* refactor(mobile): group native chat modules by feature owner * refactor(mobile): consolidate concrete owner imports * test(mobile): preserve pinned release source addresses * refactor(mobile): import the recorded launch function type directly
60 lines
2.1 KiB
TypeScript
60 lines
2.1 KiB
TypeScript
import { build } from 'esbuild'
|
|
import { mkdtemp, writeFile, unlink, rmdir } from 'node:fs/promises'
|
|
import { tmpdir } from 'node:os'
|
|
import { join, resolve } from 'node:path'
|
|
import { createRequire } from 'node:module'
|
|
import type { useMobileStructuredAgentOptions } from '../../../mobile/src/session/native-chat/input/use-mobile-structured-agent-options'
|
|
|
|
/** Execute the real phone hook in root-only workers, which do not install Expo. */
|
|
export async function loadMobileStructuredOptions(): Promise<
|
|
typeof useMobileStructuredAgentOptions
|
|
> {
|
|
const result = await build({
|
|
entryPoints: [
|
|
resolve('mobile/src/session/native-chat/input/use-mobile-structured-agent-options.ts')
|
|
],
|
|
bundle: true,
|
|
platform: 'node',
|
|
format: 'cjs',
|
|
write: false,
|
|
tsconfigRaw: {},
|
|
plugins: [
|
|
{
|
|
name: 'root-unit-phone-platform',
|
|
setup(builder) {
|
|
builder.onResolve({ filter: /^react$/ }, () => ({
|
|
path: resolve('node_modules/react/index.js'),
|
|
external: true
|
|
}))
|
|
builder.onResolve({ filter: /\/random-v4-uuid$/ }, () => ({
|
|
path: 'uuid',
|
|
namespace: 'unit-phone'
|
|
}))
|
|
builder.onLoad({ filter: /^uuid$/, namespace: 'unit-phone' }, () => ({
|
|
resolveDir: process.cwd(),
|
|
contents: `export { createNonSecureContextUuid as randomV4Uuid } from ${JSON.stringify(resolve('src/shared/non-secure-context-uuid.ts'))}`
|
|
}))
|
|
}
|
|
}
|
|
]
|
|
})
|
|
const source = result.outputFiles[0]?.text
|
|
if (!source) {
|
|
throw new Error('Phone hook source was not compiled')
|
|
}
|
|
const dir = await mkdtemp(join(tmpdir(), 'orca-pr32334-phone-options-'))
|
|
const file = join(dir, 'phone-options.cjs')
|
|
try {
|
|
await writeFile(file, source)
|
|
const loaded: { useMobileStructuredAgentOptions: typeof useMobileStructuredAgentOptions } =
|
|
createRequire(resolve('package.json'))(file)
|
|
if (typeof loaded.useMobileStructuredAgentOptions !== 'function') {
|
|
throw new Error('Phone hook export is unavailable')
|
|
}
|
|
return loaded.useMobileStructuredAgentOptions
|
|
} finally {
|
|
await unlink(file)
|
|
await rmdir(dir)
|
|
}
|
|
}
|