@osdk/vite-plugin-superrepo 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.
@@ -0,0 +1,33 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /**
18
+ * Vite plugin that transparently wraps the OSDK client with smartClient
19
+ * during development. Any import of `client` from `src/client.ts`
20
+ * automatically gets the local-function-routing wrapper applied.
21
+ * Production builds are completely untouched.
22
+ */
23
+ export function smartClientPlugin() {
24
+ return {
25
+ name: "vite-plugin-smart-client",
26
+ apply: "serve",
27
+ transform(code, id) {
28
+ if (!id.endsWith("/src/client.ts")) return null;
29
+ return code.replace(/export const client\b/, "const __rawClient").replace(/export default client\b/, "export default __rawClient") + `\nimport { smartClient as __sc } from "@osdk/vite-plugin-superrepo/smartClient";\n` + `export const client = __sc(__rawClient);\n`;
30
+ }
31
+ };
32
+ }
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["smartClientPlugin","name","apply","transform","code","id","endsWith","replace"],"sources":["index.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Plugin } from \"vite\";\n\n/**\n * Vite plugin that transparently wraps the OSDK client with smartClient\n * during development. Any import of `client` from `src/client.ts`\n * automatically gets the local-function-routing wrapper applied.\n * Production builds are completely untouched.\n */\nexport function smartClientPlugin(): Plugin {\n return {\n name: \"vite-plugin-smart-client\",\n apply: \"serve\",\n\n transform(code, id) {\n if (!id.endsWith(\"/src/client.ts\")) return null;\n\n return (\n code\n .replace(/export const client\\b/, \"const __rawClient\")\n .replace(/export default client\\b/, \"export default __rawClient\")\n + `\\nimport { smartClient as __sc } from \"@osdk/vite-plugin-superrepo/smartClient\";\\n`\n + `export const client = __sc(__rawClient);\\n`\n );\n },\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,iBAAiBA,CAAA,EAAW;EAC1C,OAAO;IACLC,IAAI,EAAE,0BAA0B;IAChCC,KAAK,EAAE,OAAO;IAEdC,SAASA,CAACC,IAAI,EAAEC,EAAE,EAAE;MAClB,IAAI,CAACA,EAAE,CAACC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,IAAI;MAE/C,OACEF,IAAI,CACDG,OAAO,CAAC,uBAAuB,EAAE,mBAAmB,CAAC,CACrDA,OAAO,CAAC,yBAAyB,EAAE,4BAA4B,CAAC,GACjE,oFAAoF,GACpF,4CAA4C;IAElD;EACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,300 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ const TS_RUNTIME = {
18
+ name: "TypeScript",
19
+ specsEndpoint: "/local-functions/functions-typescript-runtime/api/functions/preview/specs",
20
+ executeEndpoint: "/local-functions/functions-typescript-runtime/api/functions/runtime/execute"
21
+ };
22
+ const PY_RUNTIME = {
23
+ name: "Python",
24
+ specsEndpoint: "/local-python-functions/api/functions/preview/specs",
25
+ executeEndpoint: "/local-python-functions/api/functions/runtime/execute"
26
+ };
27
+ const LOCAL_RUNTIME_TOKEN = "Bearer fake-local-dev-token";
28
+
29
+ // Queue for serializing Python calls — the runtime can only handle one at a time
30
+ let pythonQueue = Promise.resolve();
31
+ function enqueue(fn) {
32
+ const result = pythonQueue.then(fn, fn);
33
+ pythonQueue = result.then(() => {}, () => {});
34
+ return result;
35
+ }
36
+ function camelToSnakeCase(str) {
37
+ return str.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);
38
+ }
39
+ function hasEntries(o) {
40
+ return o != null && typeof o === "object" && Object.keys(o).length > 0;
41
+ }
42
+ function isOsdkObject(value) {
43
+ return value != null && typeof value === "object" && "$apiName" in value && "$primaryKey" in value;
44
+ }
45
+ async function fetchPkPropertyNames() {
46
+ const response = await fetch("/api/v2/ontologies/ontology/objectTypes", {
47
+ headers: {
48
+ "Authorization": LOCAL_RUNTIME_TOKEN
49
+ }
50
+ });
51
+ if (!response.ok) {
52
+ throw new Error(`Failed to fetch object types: ${response.status}`);
53
+ }
54
+ const data = await response.json();
55
+ const objectTypes = data.data ?? data.objectTypes;
56
+ if (!Array.isArray(objectTypes)) {
57
+ throw new Error("Unexpected response format from object types endpoint");
58
+ }
59
+ const map = new Map();
60
+ for (const ot of objectTypes) {
61
+ const pkProp = ot.primaryKeyPropertyApiName ?? ot.primaryKey;
62
+ if (ot.apiName && pkProp) {
63
+ map.set(ot.apiName, pkProp);
64
+ }
65
+ }
66
+ return map;
67
+ }
68
+ function wrapObjectLocator(obj, pkNames) {
69
+ const apiName = obj.$apiName;
70
+ const pkProperty = pkNames.get(apiName);
71
+ if (!pkProperty) {
72
+ throw new Error(`No primary key property found for object type "${apiName}"`);
73
+ }
74
+ return {
75
+ type: "objectLocator",
76
+ objectLocator: {
77
+ typeId: apiName,
78
+ primaryKey: {
79
+ [pkProperty]: obj.$primaryKey
80
+ }
81
+ }
82
+ };
83
+ }
84
+ function wrapPrimitive(value) {
85
+ if (typeof value === "number") {
86
+ const type = Number.isInteger(value) ? "integer" : "double";
87
+ return {
88
+ type,
89
+ [type]: value
90
+ };
91
+ }
92
+ return {
93
+ type: typeof value,
94
+ [typeof value]: value
95
+ };
96
+ }
97
+ function wrapValue(value, pkNames) {
98
+ if (typeof value === "number" || typeof value === "string" || typeof value === "boolean") {
99
+ return wrapPrimitive(value);
100
+ }
101
+ if (isOsdkObject(value)) {
102
+ return wrapObjectLocator(value, pkNames);
103
+ }
104
+ if (Array.isArray(value) && value.length > 0 && value.every(isOsdkObject)) {
105
+ return {
106
+ type: "list",
107
+ list: {
108
+ values: value.map(item => wrapObjectLocator(item, pkNames))
109
+ }
110
+ };
111
+ }
112
+ return value;
113
+ }
114
+ function transformParametersToLocal(parameters, isPython, pkNames) {
115
+ const transformed = {};
116
+ for (const [key, value] of Object.entries(parameters)) {
117
+ const paramName = isPython ? camelToSnakeCase(key) : key;
118
+ transformed[paramName] = wrapValue(value, pkNames);
119
+ }
120
+ return transformed;
121
+ }
122
+ function transformResponseFromLocal(response) {
123
+ const resp = response;
124
+ if (resp?.executionResult?.type === "success") {
125
+ const returnValue = resp.executionResult.success?.returnValue;
126
+ if (returnValue?.type != null && returnValue.type in returnValue) {
127
+ return returnValue[returnValue.type];
128
+ }
129
+ return returnValue;
130
+ }
131
+ if (resp?.executionResult?.type === "failed") {
132
+ const msg = resp.executionResult.failed?.runtimeError?.message;
133
+ if (!msg) {
134
+ throw new Error("Function execution failed with no error message");
135
+ }
136
+ throw new Error(msg);
137
+ }
138
+ throw new Error("Unexpected response format from local runtime");
139
+ }
140
+ function createFunctionLocator(functionName, specs) {
141
+ const funcSpec = specs?.functions?.find(f => {
142
+ const locator = f.locator;
143
+ if (locator?.type === "typescript") {
144
+ return locator.typescript?.functionName === functionName;
145
+ }
146
+ if (locator?.type === "python") {
147
+ return locator.python?.functionName === functionName;
148
+ }
149
+ return false;
150
+ });
151
+ if (!funcSpec?.locator) {
152
+ throw new Error(`Function "${functionName}" not found in specs`);
153
+ }
154
+ const locator = funcSpec.locator;
155
+ if (locator.type === "python" && locator.python) {
156
+ return {
157
+ type: "python",
158
+ python: {
159
+ moduleName: locator.python.moduleName,
160
+ functionName: locator.python.functionName
161
+ }
162
+ };
163
+ }
164
+ if (locator.type === "typescript" && locator.typescript) {
165
+ const filePath = locator.typescript.sourceProvenance?.stemma?.filePath;
166
+ if (filePath) {
167
+ return {
168
+ type: "typescript",
169
+ typescript: {
170
+ filePath
171
+ }
172
+ };
173
+ }
174
+ }
175
+ throw new Error(`Could not create locator for function "${functionName}"`);
176
+ }
177
+ const SPECS_TIMEOUT_MS = 30_000;
178
+ async function fetchSpecs(runtime) {
179
+ try {
180
+ const response = await fetch(runtime.specsEndpoint, {
181
+ method: "GET",
182
+ headers: {
183
+ "Authorization": LOCAL_RUNTIME_TOKEN
184
+ },
185
+ signal: AbortSignal.timeout(SPECS_TIMEOUT_MS)
186
+ });
187
+ if (!response.ok) return null;
188
+ return await response.json();
189
+ } catch {
190
+ return null;
191
+ }
192
+ }
193
+ async function discoverFunctions() {
194
+ const map = new Map();
195
+ const tsSpecs = await fetchSpecs(TS_RUNTIME);
196
+ if (tsSpecs?.functions) {
197
+ for (const func of tsSpecs.functions) {
198
+ const functionName = func.locator?.typescript?.functionName;
199
+ if (functionName) {
200
+ const prov = func.ontologyProvenance;
201
+ const isEditFunction = hasEntries(prov?.editedObjects) || hasEntries(prov?.editedLinks) || hasEntries(prov?.editedInterfaces);
202
+ map.set(functionName, {
203
+ runtime: TS_RUNTIME,
204
+ specs: tsSpecs,
205
+ isEditFunction
206
+ });
207
+ }
208
+ }
209
+ }
210
+ const pySpecs = await enqueue(() => fetchSpecs(PY_RUNTIME));
211
+ if (pySpecs?.functions) {
212
+ for (const func of pySpecs.functions) {
213
+ const functionName = func.locator?.python?.functionName;
214
+ if (functionName) {
215
+ map.set(functionName, {
216
+ runtime: PY_RUNTIME,
217
+ specs: pySpecs,
218
+ isEditFunction: false
219
+ });
220
+ }
221
+ }
222
+ }
223
+ return map;
224
+ }
225
+ async function postJsonToLocalRuntime(url, body) {
226
+ const response = await fetch(url, {
227
+ method: "POST",
228
+ headers: {
229
+ "Content-Type": "application/json",
230
+ "Authorization": LOCAL_RUNTIME_TOKEN
231
+ },
232
+ body: JSON.stringify(body)
233
+ });
234
+ if (!response.ok) {
235
+ const errorText = await response.text();
236
+ throw new Error(`Request to ${url} failed: ${response.status} - ${errorText}`);
237
+ }
238
+ return response;
239
+ }
240
+ async function executeLocalFunction(functionDefinition, parameters) {
241
+ const functionName = functionDefinition.apiName ?? functionDefinition.__DefinitionMetadata?.apiName;
242
+ if (!functionName) {
243
+ throw new Error("Unable to determine function name from definition");
244
+ }
245
+ const functions = await discoverFunctions();
246
+ const info = functions.get(functionName);
247
+ if (!info) {
248
+ throw new Error(`Function "${functionName}" not found in any local runtime`);
249
+ }
250
+ const isPython = info.runtime === PY_RUNTIME;
251
+ const pkNames = await fetchPkPropertyNames();
252
+ const transformedParams = transformParametersToLocal(parameters, isPython, pkNames);
253
+
254
+ // Edit functions are routed through the action endpoint
255
+ // so edits are applied to the store by the FunctionBackedActionHandler
256
+ if (info.isEditFunction) {
257
+ await postJsonToLocalRuntime(`/api/v2/ontologies/ontology/actions/${functionName}/apply`, {
258
+ parameters: transformedParams
259
+ });
260
+ return undefined;
261
+ }
262
+ const locator = createFunctionLocator(functionName, info.specs);
263
+ const requestBody = {
264
+ locator,
265
+ parameters: transformedParams,
266
+ requestContext: {
267
+ type: "interactive",
268
+ interactive: {}
269
+ }
270
+ };
271
+ const execute = async () => {
272
+ const response = await postJsonToLocalRuntime(info.runtime.executeEndpoint, requestBody);
273
+ return transformResponseFromLocal(await response.json());
274
+ };
275
+ return isPython ? enqueue(execute) : execute();
276
+ }
277
+
278
+ /**
279
+ * Wraps an OSDK client to route function calls to local runtimes in development.
280
+ */
281
+ export function smartClient(client) {
282
+ return new Proxy(client, {
283
+ apply(_target, _thisArg, args) {
284
+ const [definition] = args;
285
+ const result = client(...args);
286
+ if (result && typeof result === "object" && typeof result.executeFunction === "function") {
287
+ return new Proxy(result, {
288
+ get(target, prop, receiver) {
289
+ if (prop === "executeFunction") {
290
+ return parameters => executeLocalFunction(definition, parameters);
291
+ }
292
+ return Reflect.get(target, prop, receiver);
293
+ }
294
+ });
295
+ }
296
+ return result;
297
+ }
298
+ });
299
+ }
300
+ //# sourceMappingURL=smartClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smartClient.js","names":["TS_RUNTIME","name","specsEndpoint","executeEndpoint","PY_RUNTIME","LOCAL_RUNTIME_TOKEN","pythonQueue","Promise","resolve","enqueue","fn","result","then","camelToSnakeCase","str","replace","letter","toLowerCase","hasEntries","o","Object","keys","length","isOsdkObject","value","fetchPkPropertyNames","response","fetch","headers","ok","Error","status","data","json","objectTypes","Array","isArray","map","Map","ot","pkProp","primaryKeyPropertyApiName","primaryKey","apiName","set","wrapObjectLocator","obj","pkNames","$apiName","pkProperty","get","type","objectLocator","typeId","$primaryKey","wrapPrimitive","Number","isInteger","wrapValue","every","list","values","item","transformParametersToLocal","parameters","isPython","transformed","key","entries","paramName","transformResponseFromLocal","resp","executionResult","returnValue","success","msg","failed","runtimeError","message","createFunctionLocator","functionName","specs","funcSpec","functions","find","f","locator","typescript","python","moduleName","filePath","sourceProvenance","stemma","SPECS_TIMEOUT_MS","fetchSpecs","runtime","method","signal","AbortSignal","timeout","discoverFunctions","tsSpecs","func","prov","ontologyProvenance","isEditFunction","editedObjects","editedLinks","editedInterfaces","pySpecs","postJsonToLocalRuntime","url","body","JSON","stringify","errorText","text","executeLocalFunction","functionDefinition","__DefinitionMetadata","info","transformedParams","undefined","requestBody","requestContext","interactive","execute","smartClient","client","Proxy","apply","_target","_thisArg","args","definition","executeFunction","target","prop","receiver","Reflect"],"sources":["smartClient.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Client } from \"@osdk/client\";\n\ninterface RuntimeConfig {\n name: \"TypeScript\" | \"Python\";\n specsEndpoint: string;\n executeEndpoint: string;\n}\n\nconst TS_RUNTIME: RuntimeConfig = {\n name: \"TypeScript\",\n specsEndpoint:\n \"/local-functions/functions-typescript-runtime/api/functions/preview/specs\",\n executeEndpoint:\n \"/local-functions/functions-typescript-runtime/api/functions/runtime/execute\",\n};\n\nconst PY_RUNTIME: RuntimeConfig = {\n name: \"Python\",\n specsEndpoint: \"/local-python-functions/api/functions/preview/specs\",\n executeEndpoint: \"/local-python-functions/api/functions/runtime/execute\",\n};\n\nconst LOCAL_RUNTIME_TOKEN = \"Bearer fake-local-dev-token\";\n\n// Queue for serializing Python calls — the runtime can only handle one at a time\nlet pythonQueue: Promise<unknown> = Promise.resolve();\n\nfunction enqueue<T>(fn: () => Promise<T>): Promise<T> {\n const result = pythonQueue.then(fn, fn);\n pythonQueue = result.then(() => {}, () => {});\n return result;\n}\n\nfunction camelToSnakeCase(str: string): string {\n return str.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);\n}\n\nfunction hasEntries(o: unknown): boolean {\n return o != null && typeof o === \"object\"\n && Object.keys(o as Record<string, unknown>).length > 0;\n}\n\nfunction isOsdkObject(\n value: unknown,\n): value is { $apiName: string; $primaryKey: unknown } {\n return value != null && typeof value === \"object\"\n && \"$apiName\" in value && \"$primaryKey\" in value;\n}\n\nasync function fetchPkPropertyNames(): Promise<Map<string, string>> {\n const response = await fetch(\"/api/v2/ontologies/ontology/objectTypes\", {\n headers: { \"Authorization\": LOCAL_RUNTIME_TOKEN },\n });\n if (!response.ok) {\n throw new Error(\n `Failed to fetch object types: ${response.status}`,\n );\n }\n const data = await response.json() as Record<string, unknown>;\n const objectTypes = data.data ?? data.objectTypes;\n if (!Array.isArray(objectTypes)) {\n throw new Error(\n \"Unexpected response format from object types endpoint\",\n );\n }\n const map = new Map<string, string>();\n for (const ot of objectTypes as Record<string, string>[]) {\n const pkProp = ot.primaryKeyPropertyApiName ?? ot.primaryKey;\n if (ot.apiName && pkProp) {\n map.set(ot.apiName, pkProp);\n }\n }\n return map;\n}\n\nfunction wrapObjectLocator(\n obj: { $apiName: string; $primaryKey: unknown },\n pkNames: Map<string, string>,\n): unknown {\n const apiName = obj.$apiName;\n const pkProperty = pkNames.get(apiName);\n if (!pkProperty) {\n throw new Error(\n `No primary key property found for object type \"${apiName}\"`,\n );\n }\n return {\n type: \"objectLocator\",\n objectLocator: {\n typeId: apiName,\n primaryKey: { [pkProperty]: obj.$primaryKey },\n },\n };\n}\n\nfunction wrapPrimitive(\n value: number | string | boolean,\n): { type: string; [key: string]: number | string | boolean } {\n if (typeof value === \"number\") {\n const type = Number.isInteger(value) ? \"integer\" : \"double\";\n return { type, [type]: value };\n }\n return { type: typeof value, [typeof value]: value };\n}\n\nfunction wrapValue(\n value: unknown,\n pkNames: Map<string, string>,\n): unknown {\n if (\n typeof value === \"number\" || typeof value === \"string\"\n || typeof value === \"boolean\"\n ) {\n return wrapPrimitive(value);\n }\n if (isOsdkObject(value)) {\n return wrapObjectLocator(value, pkNames);\n }\n if (\n Array.isArray(value) && value.length > 0 && value.every(isOsdkObject)\n ) {\n return {\n type: \"list\",\n list: {\n values: value.map(item => wrapObjectLocator(item, pkNames)),\n },\n };\n }\n return value;\n}\n\nfunction transformParametersToLocal(\n parameters: Record<string, unknown>,\n isPython: boolean,\n pkNames: Map<string, string>,\n): Record<string, unknown> {\n const transformed: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(parameters)) {\n const paramName = isPython ? camelToSnakeCase(key) : key;\n transformed[paramName] = wrapValue(value, pkNames);\n }\n return transformed;\n}\n\ninterface TypedValue {\n type: string;\n double?: number;\n integer?: number;\n string?: string;\n boolean?: boolean;\n}\n\ninterface ExecutionResult {\n executionResult?: {\n type: string;\n success?: { returnValue?: TypedValue };\n failed?: { runtimeError?: { message?: string } };\n };\n}\n\nfunction transformResponseFromLocal(response: unknown): unknown {\n const resp = response as ExecutionResult;\n\n if (resp?.executionResult?.type === \"success\") {\n const returnValue = resp.executionResult.success?.returnValue;\n if (returnValue?.type != null && returnValue.type in returnValue) {\n return returnValue[returnValue.type as keyof TypedValue];\n }\n return returnValue;\n }\n\n if (resp?.executionResult?.type === \"failed\") {\n const msg = resp.executionResult.failed?.runtimeError?.message;\n if (!msg) {\n throw new Error(\"Function execution failed with no error message\");\n }\n throw new Error(msg);\n }\n\n throw new Error(\"Unexpected response format from local runtime\");\n}\n\ninterface FunctionLocator {\n type: \"typescript\" | \"python\";\n typescript?: { filePath: string };\n python?: { moduleName: string; functionName: string };\n}\n\ninterface FunctionSpec {\n locator: {\n type: \"typescript\" | \"python\";\n typescript?: {\n functionName: string;\n sourceProvenance?: { stemma?: { filePath: string } };\n };\n python?: {\n moduleName: string;\n functionName: string;\n };\n };\n ontologyProvenance?: {\n editedObjects?: Record<string, unknown>;\n editedLinks?: Record<string, unknown>;\n editedInterfaces?: Record<string, unknown>;\n };\n}\n\ninterface RuntimeSpecs {\n functions?: FunctionSpec[];\n}\n\nfunction createFunctionLocator(\n functionName: string,\n specs: RuntimeSpecs,\n): FunctionLocator {\n const funcSpec = specs?.functions?.find((f) => {\n const locator = f.locator;\n if (locator?.type === \"typescript\") {\n return locator.typescript?.functionName === functionName;\n }\n if (locator?.type === \"python\") {\n return locator.python?.functionName === functionName;\n }\n return false;\n });\n\n if (!funcSpec?.locator) {\n throw new Error(`Function \"${functionName}\" not found in specs`);\n }\n\n const locator = funcSpec.locator;\n\n if (locator.type === \"python\" && locator.python) {\n return {\n type: \"python\",\n python: {\n moduleName: locator.python.moduleName,\n functionName: locator.python.functionName,\n },\n };\n }\n\n if (locator.type === \"typescript\" && locator.typescript) {\n const filePath = locator.typescript.sourceProvenance?.stemma?.filePath;\n if (filePath) {\n return {\n type: \"typescript\",\n typescript: { filePath },\n };\n }\n }\n\n throw new Error(\n `Could not create locator for function \"${functionName}\"`,\n );\n}\n\nconst SPECS_TIMEOUT_MS = 30_000;\n\nasync function fetchSpecs(\n runtime: RuntimeConfig,\n): Promise<RuntimeSpecs | null> {\n try {\n const response = await fetch(runtime.specsEndpoint, {\n method: \"GET\",\n headers: { \"Authorization\": LOCAL_RUNTIME_TOKEN },\n signal: AbortSignal.timeout(SPECS_TIMEOUT_MS),\n });\n if (!response.ok) return null;\n return await response.json() as RuntimeSpecs;\n } catch {\n return null;\n }\n}\n\ninterface FunctionInfo {\n runtime: RuntimeConfig;\n specs: RuntimeSpecs;\n isEditFunction: boolean;\n}\n\nasync function discoverFunctions(): Promise<Map<string, FunctionInfo>> {\n const map = new Map<string, FunctionInfo>();\n\n const tsSpecs = await fetchSpecs(TS_RUNTIME);\n if (tsSpecs?.functions) {\n for (const func of tsSpecs.functions) {\n const functionName = func.locator?.typescript?.functionName;\n if (functionName) {\n const prov = func.ontologyProvenance;\n const isEditFunction = hasEntries(prov?.editedObjects)\n || hasEntries(prov?.editedLinks)\n || hasEntries(prov?.editedInterfaces);\n map.set(functionName, {\n runtime: TS_RUNTIME,\n specs: tsSpecs,\n isEditFunction,\n });\n }\n }\n }\n\n const pySpecs = await enqueue(() => fetchSpecs(PY_RUNTIME));\n if (pySpecs?.functions) {\n for (const func of pySpecs.functions) {\n const functionName = func.locator?.python?.functionName;\n if (functionName) {\n map.set(functionName, {\n runtime: PY_RUNTIME,\n specs: pySpecs,\n isEditFunction: false,\n });\n }\n }\n }\n\n return map;\n}\n\nasync function postJsonToLocalRuntime(\n url: string,\n body: unknown,\n): Promise<Response> {\n const response = await fetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"Authorization\": LOCAL_RUNTIME_TOKEN,\n },\n body: JSON.stringify(body),\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(\n `Request to ${url} failed: ${response.status} - ${errorText}`,\n );\n }\n\n return response;\n}\n\ninterface FunctionDefinition {\n apiName?: string;\n __DefinitionMetadata?: { apiName?: string };\n}\n\nasync function executeLocalFunction(\n functionDefinition: FunctionDefinition,\n parameters: Record<string, unknown>,\n): Promise<unknown> {\n const functionName = functionDefinition.apiName\n ?? functionDefinition.__DefinitionMetadata?.apiName;\n if (!functionName) {\n throw new Error(\"Unable to determine function name from definition\");\n }\n\n const functions = await discoverFunctions();\n const info = functions.get(functionName);\n\n if (!info) {\n throw new Error(\n `Function \"${functionName}\" not found in any local runtime`,\n );\n }\n\n const isPython = info.runtime === PY_RUNTIME;\n const pkNames = await fetchPkPropertyNames();\n const transformedParams = transformParametersToLocal(\n parameters,\n isPython,\n pkNames,\n );\n\n // Edit functions are routed through the action endpoint\n // so edits are applied to the store by the FunctionBackedActionHandler\n if (info.isEditFunction) {\n await postJsonToLocalRuntime(\n `/api/v2/ontologies/ontology/actions/${functionName}/apply`,\n { parameters: transformedParams },\n );\n return undefined;\n }\n\n const locator = createFunctionLocator(functionName, info.specs);\n const requestBody = {\n locator,\n parameters: transformedParams,\n requestContext: { type: \"interactive\", interactive: {} },\n };\n\n const execute = async () => {\n const response = await postJsonToLocalRuntime(\n info.runtime.executeEndpoint,\n requestBody,\n );\n return transformResponseFromLocal(await response.json());\n };\n\n return isPython ? enqueue(execute) : execute();\n}\n\n/**\n * Wraps an OSDK client to route function calls to local runtimes in development.\n */\nexport function smartClient<T extends Client>(client: T): T {\n return new Proxy(client as unknown as Function, {\n apply(_target, _thisArg, args) {\n const [definition] = args as [FunctionDefinition];\n const result = (client as unknown as Function)(...args);\n\n if (\n result && typeof result === \"object\"\n && typeof (result as Record<string, unknown>).executeFunction\n === \"function\"\n ) {\n return new Proxy(result as object, {\n get(target, prop, receiver) {\n if (prop === \"executeFunction\") {\n return (parameters: Record<string, unknown>) =>\n executeLocalFunction(definition, parameters);\n }\n return Reflect.get(target, prop, receiver);\n },\n });\n }\n\n return result;\n },\n }) as unknown as T;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA,MAAMA,UAAyB,GAAG;EAChCC,IAAI,EAAE,YAAY;EAClBC,aAAa,EACX,2EAA2E;EAC7EC,eAAe,EACb;AACJ,CAAC;AAED,MAAMC,UAAyB,GAAG;EAChCH,IAAI,EAAE,QAAQ;EACdC,aAAa,EAAE,qDAAqD;EACpEC,eAAe,EAAE;AACnB,CAAC;AAED,MAAME,mBAAmB,GAAG,6BAA6B;;AAEzD;AACA,IAAIC,WAA6B,GAAGC,OAAO,CAACC,OAAO,CAAC,CAAC;AAErD,SAASC,OAAOA,CAAIC,EAAoB,EAAc;EACpD,MAAMC,MAAM,GAAGL,WAAW,CAACM,IAAI,CAACF,EAAE,EAAEA,EAAE,CAAC;EACvCJ,WAAW,GAAGK,MAAM,CAACC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;EAC7C,OAAOD,MAAM;AACf;AAEA,SAASE,gBAAgBA,CAACC,GAAW,EAAU;EAC7C,OAAOA,GAAG,CAACC,OAAO,CAAC,QAAQ,EAAEC,MAAM,IAAI,IAAIA,MAAM,CAACC,WAAW,CAAC,C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AmBC,MAAS,EAAK;EAC1D,OAAO,IAAIC,KAAK,CAACD,MAAM,EAAyB;IAC9CE,KAAKA,CAACC,OAAO,EAAEC,QAAQ,EAAEC,IAAI,EAAE;MAC7B,MAAM,CAACC,UAAU,CAAC,GAAGD,IAA4B;MACjD,MAAM1H,MAAM,GAAIqH,MAAM,CAAyB,GAAGK,IAAI,CAAC;MAEvD,IACE1H,MAAM,IAAI,OAAOA,MAAM,KAAK,QAAQ,IACjC,OAAQA,MAAM,CAA6B4H,eAAe,KACvD,UAAU,EAChB;QACA,OAAO,IAAIN,KAAK,CAACtH,MAAM,EAAY;UACjCuC,GAAGA,CAACsF,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAE;YAC1B,IAAID,IAAI,KAAK,iBAAiB,EAAE;cAC9B,OAAQzE,UAAmC,IACzCqD,oBAAoB,CAACiB,UAAU,EAAEtE,UAAU,CAAC;YAChD;YACA,OAAO2E,OAAO,CAACzF,GAAG,CAACsF,MAAM,EAAEC,IAAI,EAAEC,QAAQ,CAAC;UAC5C;QACF,CAAC,CAAC;MACJ;MAEA,OAAO/H,MAAM;IACf;EACF,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -0,0 +1,20 @@
1
+ 'use strict';
2
+
3
+ // src/index.ts
4
+ function smartClientPlugin() {
5
+ return {
6
+ name: "vite-plugin-smart-client",
7
+ apply: "serve",
8
+ transform(code, id) {
9
+ if (!id.endsWith("/src/client.ts")) return null;
10
+ return code.replace(/export const client\b/, "const __rawClient").replace(/export default client\b/, "export default __rawClient") + `
11
+ import { smartClient as __sc } from "@osdk/vite-plugin-superrepo/smartClient";
12
+ export const client = __sc(__rawClient);
13
+ `;
14
+ }
15
+ };
16
+ }
17
+
18
+ exports.smartClientPlugin = smartClientPlugin;
19
+ //# sourceMappingURL=index.cjs.map
20
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;AAsBO,SAAS,iBAAoB,GAAA;AAClC,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,0BAAA;AAAA,IACN,KAAO,EAAA,OAAA;AAAA,IACP,SAAA,CAAU,MAAM,EAAI,EAAA;AAClB,MAAA,IAAI,CAAC,EAAA,CAAG,QAAS,CAAA,gBAAgB,GAAU,OAAA,IAAA;AAC3C,MAAO,OAAA,IAAA,CAAK,QAAQ,uBAAyB,EAAA,mBAAmB,EAAE,OAAQ,CAAA,yBAAA,EAA2B,4BAA4B,CAAI,GAAA;AAAA;AAAA;AAAA,CAAA;AAAA;AACvI,GACF;AACF","file":"index.cjs","sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Vite plugin that transparently wraps the OSDK client with smartClient\n * during development. Any import of `client` from `src/client.ts`\n * automatically gets the local-function-routing wrapper applied.\n * Production builds are completely untouched.\n */\nexport function smartClientPlugin() {\n return {\n name: \"vite-plugin-smart-client\",\n apply: \"serve\",\n transform(code, id) {\n if (!id.endsWith(\"/src/client.ts\")) return null;\n return code.replace(/export const client\\b/, \"const __rawClient\").replace(/export default client\\b/, \"export default __rawClient\") + `\\nimport { smartClient as __sc } from \"@osdk/vite-plugin-superrepo/smartClient\";\\n` + `export const client = __sc(__rawClient);\\n`;\n }\n };\n}"]}
@@ -0,0 +1,11 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ /**
4
+ * Vite plugin that transparently wraps the OSDK client with smartClient
5
+ * during development. Any import of `client` from `src/client.ts`
6
+ * automatically gets the local-function-routing wrapper applied.
7
+ * Production builds are completely untouched.
8
+ */
9
+ declare function smartClientPlugin(): Plugin;
10
+
11
+ export { smartClientPlugin };
@@ -0,0 +1,283 @@
1
+ 'use strict';
2
+
3
+ // src/public/smartClient.ts
4
+ var TS_RUNTIME = {
5
+ name: "TypeScript",
6
+ specsEndpoint: "/local-functions/functions-typescript-runtime/api/functions/preview/specs",
7
+ executeEndpoint: "/local-functions/functions-typescript-runtime/api/functions/runtime/execute"
8
+ };
9
+ var PY_RUNTIME = {
10
+ name: "Python",
11
+ specsEndpoint: "/local-python-functions/api/functions/preview/specs",
12
+ executeEndpoint: "/local-python-functions/api/functions/runtime/execute"
13
+ };
14
+ var LOCAL_RUNTIME_TOKEN = "Bearer fake-local-dev-token";
15
+ var pythonQueue = Promise.resolve();
16
+ function enqueue(fn) {
17
+ const result = pythonQueue.then(fn, fn);
18
+ pythonQueue = result.then(() => {
19
+ }, () => {
20
+ });
21
+ return result;
22
+ }
23
+ function camelToSnakeCase(str) {
24
+ return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
25
+ }
26
+ function hasEntries(o) {
27
+ return o != null && typeof o === "object" && Object.keys(o).length > 0;
28
+ }
29
+ function isOsdkObject(value) {
30
+ return value != null && typeof value === "object" && "$apiName" in value && "$primaryKey" in value;
31
+ }
32
+ async function fetchPkPropertyNames() {
33
+ const response = await fetch("/api/v2/ontologies/ontology/objectTypes", {
34
+ headers: {
35
+ "Authorization": LOCAL_RUNTIME_TOKEN
36
+ }
37
+ });
38
+ if (!response.ok) {
39
+ throw new Error(`Failed to fetch object types: ${response.status}`);
40
+ }
41
+ const data = await response.json();
42
+ const objectTypes = data.data ?? data.objectTypes;
43
+ if (!Array.isArray(objectTypes)) {
44
+ throw new Error("Unexpected response format from object types endpoint");
45
+ }
46
+ const map = /* @__PURE__ */ new Map();
47
+ for (const ot of objectTypes) {
48
+ const pkProp = ot.primaryKeyPropertyApiName ?? ot.primaryKey;
49
+ if (ot.apiName && pkProp) {
50
+ map.set(ot.apiName, pkProp);
51
+ }
52
+ }
53
+ return map;
54
+ }
55
+ function wrapObjectLocator(obj, pkNames) {
56
+ const apiName = obj.$apiName;
57
+ const pkProperty = pkNames.get(apiName);
58
+ if (!pkProperty) {
59
+ throw new Error(`No primary key property found for object type "${apiName}"`);
60
+ }
61
+ return {
62
+ type: "objectLocator",
63
+ objectLocator: {
64
+ typeId: apiName,
65
+ primaryKey: {
66
+ [pkProperty]: obj.$primaryKey
67
+ }
68
+ }
69
+ };
70
+ }
71
+ function wrapPrimitive(value) {
72
+ if (typeof value === "number") {
73
+ const type = Number.isInteger(value) ? "integer" : "double";
74
+ return {
75
+ type,
76
+ [type]: value
77
+ };
78
+ }
79
+ return {
80
+ type: typeof value,
81
+ [typeof value]: value
82
+ };
83
+ }
84
+ function wrapValue(value, pkNames) {
85
+ if (typeof value === "number" || typeof value === "string" || typeof value === "boolean") {
86
+ return wrapPrimitive(value);
87
+ }
88
+ if (isOsdkObject(value)) {
89
+ return wrapObjectLocator(value, pkNames);
90
+ }
91
+ if (Array.isArray(value) && value.length > 0 && value.every(isOsdkObject)) {
92
+ return {
93
+ type: "list",
94
+ list: {
95
+ values: value.map((item) => wrapObjectLocator(item, pkNames))
96
+ }
97
+ };
98
+ }
99
+ return value;
100
+ }
101
+ function transformParametersToLocal(parameters, isPython, pkNames) {
102
+ const transformed = {};
103
+ for (const [key, value] of Object.entries(parameters)) {
104
+ const paramName = isPython ? camelToSnakeCase(key) : key;
105
+ transformed[paramName] = wrapValue(value, pkNames);
106
+ }
107
+ return transformed;
108
+ }
109
+ function transformResponseFromLocal(response) {
110
+ const resp = response;
111
+ if (resp?.executionResult?.type === "success") {
112
+ const returnValue = resp.executionResult.success?.returnValue;
113
+ if (returnValue?.type != null && returnValue.type in returnValue) {
114
+ return returnValue[returnValue.type];
115
+ }
116
+ return returnValue;
117
+ }
118
+ if (resp?.executionResult?.type === "failed") {
119
+ const msg = resp.executionResult.failed?.runtimeError?.message;
120
+ if (!msg) {
121
+ throw new Error("Function execution failed with no error message");
122
+ }
123
+ throw new Error(msg);
124
+ }
125
+ throw new Error("Unexpected response format from local runtime");
126
+ }
127
+ function createFunctionLocator(functionName, specs) {
128
+ const funcSpec = specs?.functions?.find((f) => {
129
+ const locator2 = f.locator;
130
+ if (locator2?.type === "typescript") {
131
+ return locator2.typescript?.functionName === functionName;
132
+ }
133
+ if (locator2?.type === "python") {
134
+ return locator2.python?.functionName === functionName;
135
+ }
136
+ return false;
137
+ });
138
+ if (!funcSpec?.locator) {
139
+ throw new Error(`Function "${functionName}" not found in specs`);
140
+ }
141
+ const locator = funcSpec.locator;
142
+ if (locator.type === "python" && locator.python) {
143
+ return {
144
+ type: "python",
145
+ python: {
146
+ moduleName: locator.python.moduleName,
147
+ functionName: locator.python.functionName
148
+ }
149
+ };
150
+ }
151
+ if (locator.type === "typescript" && locator.typescript) {
152
+ const filePath = locator.typescript.sourceProvenance?.stemma?.filePath;
153
+ if (filePath) {
154
+ return {
155
+ type: "typescript",
156
+ typescript: {
157
+ filePath
158
+ }
159
+ };
160
+ }
161
+ }
162
+ throw new Error(`Could not create locator for function "${functionName}"`);
163
+ }
164
+ var SPECS_TIMEOUT_MS = 3e4;
165
+ async function fetchSpecs(runtime) {
166
+ try {
167
+ const response = await fetch(runtime.specsEndpoint, {
168
+ method: "GET",
169
+ headers: {
170
+ "Authorization": LOCAL_RUNTIME_TOKEN
171
+ },
172
+ signal: AbortSignal.timeout(SPECS_TIMEOUT_MS)
173
+ });
174
+ if (!response.ok) return null;
175
+ return await response.json();
176
+ } catch {
177
+ return null;
178
+ }
179
+ }
180
+ async function discoverFunctions() {
181
+ const map = /* @__PURE__ */ new Map();
182
+ const tsSpecs = await fetchSpecs(TS_RUNTIME);
183
+ if (tsSpecs?.functions) {
184
+ for (const func of tsSpecs.functions) {
185
+ const functionName = func.locator?.typescript?.functionName;
186
+ if (functionName) {
187
+ const prov = func.ontologyProvenance;
188
+ const isEditFunction = hasEntries(prov?.editedObjects) || hasEntries(prov?.editedLinks) || hasEntries(prov?.editedInterfaces);
189
+ map.set(functionName, {
190
+ runtime: TS_RUNTIME,
191
+ specs: tsSpecs,
192
+ isEditFunction
193
+ });
194
+ }
195
+ }
196
+ }
197
+ const pySpecs = await enqueue(() => fetchSpecs(PY_RUNTIME));
198
+ if (pySpecs?.functions) {
199
+ for (const func of pySpecs.functions) {
200
+ const functionName = func.locator?.python?.functionName;
201
+ if (functionName) {
202
+ map.set(functionName, {
203
+ runtime: PY_RUNTIME,
204
+ specs: pySpecs,
205
+ isEditFunction: false
206
+ });
207
+ }
208
+ }
209
+ }
210
+ return map;
211
+ }
212
+ async function postJsonToLocalRuntime(url, body) {
213
+ const response = await fetch(url, {
214
+ method: "POST",
215
+ headers: {
216
+ "Content-Type": "application/json",
217
+ "Authorization": LOCAL_RUNTIME_TOKEN
218
+ },
219
+ body: JSON.stringify(body)
220
+ });
221
+ if (!response.ok) {
222
+ const errorText = await response.text();
223
+ throw new Error(`Request to ${url} failed: ${response.status} - ${errorText}`);
224
+ }
225
+ return response;
226
+ }
227
+ async function executeLocalFunction(functionDefinition, parameters) {
228
+ const functionName = functionDefinition.apiName ?? functionDefinition.__DefinitionMetadata?.apiName;
229
+ if (!functionName) {
230
+ throw new Error("Unable to determine function name from definition");
231
+ }
232
+ const functions = await discoverFunctions();
233
+ const info = functions.get(functionName);
234
+ if (!info) {
235
+ throw new Error(`Function "${functionName}" not found in any local runtime`);
236
+ }
237
+ const isPython = info.runtime === PY_RUNTIME;
238
+ const pkNames = await fetchPkPropertyNames();
239
+ const transformedParams = transformParametersToLocal(parameters, isPython, pkNames);
240
+ if (info.isEditFunction) {
241
+ await postJsonToLocalRuntime(`/api/v2/ontologies/ontology/actions/${functionName}/apply`, {
242
+ parameters: transformedParams
243
+ });
244
+ return void 0;
245
+ }
246
+ const locator = createFunctionLocator(functionName, info.specs);
247
+ const requestBody = {
248
+ locator,
249
+ parameters: transformedParams,
250
+ requestContext: {
251
+ type: "interactive",
252
+ interactive: {}
253
+ }
254
+ };
255
+ const execute = async () => {
256
+ const response = await postJsonToLocalRuntime(info.runtime.executeEndpoint, requestBody);
257
+ return transformResponseFromLocal(await response.json());
258
+ };
259
+ return isPython ? enqueue(execute) : execute();
260
+ }
261
+ function smartClient(client) {
262
+ return new Proxy(client, {
263
+ apply(_target, _thisArg, args) {
264
+ const [definition] = args;
265
+ const result = client(...args);
266
+ if (result && typeof result === "object" && typeof result.executeFunction === "function") {
267
+ return new Proxy(result, {
268
+ get(target, prop, receiver) {
269
+ if (prop === "executeFunction") {
270
+ return (parameters) => executeLocalFunction(definition, parameters);
271
+ }
272
+ return Reflect.get(target, prop, receiver);
273
+ }
274
+ });
275
+ }
276
+ return result;
277
+ }
278
+ });
279
+ }
280
+
281
+ exports.smartClient = smartClient;
282
+ //# sourceMappingURL=smartClient.cjs.map
283
+ //# sourceMappingURL=smartClient.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/public/smartClient.ts"],"names":["locator"],"mappings":";;;AAgBA,IAAM,UAAa,GAAA;AAAA,EACjB,IAAM,EAAA,YAAA;AAAA,EACN,aAAe,EAAA,2EAAA;AAAA,EACf,eAAiB,EAAA;AACnB,CAAA;AACA,IAAM,UAAa,GAAA;AAAA,EACjB,IAAM,EAAA,QAAA;AAAA,EACN,aAAe,EAAA,qDAAA;AAAA,EACf,eAAiB,EAAA;AACnB,CAAA;AACA,IAAM,mBAAsB,GAAA,6BAAA;AAG5B,IAAI,WAAA,GAAc,QAAQ,OAAQ,EAAA;AAClC,SAAS,QAAQ,EAAI,EAAA;AACnB,EAAA,MAAM,MAAS,GAAA,WAAA,CAAY,IAAK,CAAA,EAAA,EAAI,EAAE,CAAA;AACtC,EAAc,WAAA,GAAA,MAAA,CAAO,KAAK,MAAM;AAAA,KAAI,MAAM;AAAA,GAAE,CAAA;AAC5C,EAAO,OAAA,MAAA;AACT;AACA,SAAS,iBAAiB,GAAK,EAAA;AAC7B,EAAO,OAAA,GAAA,CAAI,QAAQ,QAAU,EAAA,CAAA,MAA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C;AAKO,SAAS,YAAY,MAAQ,EAAA;AAClC,EAAO,OAAA,IAAI,MAAM,MAAQ,EAAA;AAAA,IACvB,KAAA,CAAM,OAAS,EAAA,QAAA,EAAU,IAAM,EAAA;AAC7B,MAAM,MAAA,CAAC,UAAU,CAAI,GAAA,IAAA;AACrB,MAAM,MAAA,MAAA,GAAS,MAAO,CAAA,GAAG,IAAI,CAAA;AAC7B,MAAA,IAAI,UAAU,OAAO,MAAA,KAAW,YAAY,OAAO,MAAA,CAAO,oBAAoB,UAAY,EAAA;AACxF,QAAO,OAAA,IAAI,MAAM,MAAQ,EAAA;AAAA,UACvB,GAAA,CAAI,MAAQ,EAAA,IAAA,EAAM,QAAU,EAAA;AAC1B,YAAA,IAAI,SAAS,iBAAmB,EAAA;AAC9B,cAAO,OAAA,CAAA,UAAA,KAAc,oBAAqB,CAAA,UAAA,EAAY,UAAU,CAAA;AAAA;AAElE,YAAA,OAAO,OAAQ,CAAA,GAAA,CAAI,MAAQ,EAAA,IAAA,EAAM,QAAQ,CAAA;AAAA;AAC3C,SACD,CAAA;AAAA;AAEH,MAAO,OAAA,MAAA;AAAA;AACT,GACD,CAAA;AACH","file":"smartClient.cjs","sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nconst TS_RUNTIME = {\n name: \"TypeScript\",\n specsEndpoint: \"/local-functions/functions-typescript-runtime/api/functions/preview/specs\",\n executeEndpoint: \"/local-functions/functions-typescript-runtime/api/functions/runtime/execute\"\n};\nconst PY_RUNTIME = {\n name: \"Python\",\n specsEndpoint: \"/local-python-functions/api/functions/preview/specs\",\n executeEndpoint: \"/local-python-functions/api/functions/runtime/execute\"\n};\nconst LOCAL_RUNTIME_TOKEN = \"Bearer fake-local-dev-token\";\n\n// Queue for serializing Python calls — the runtime can only handle one at a time\nlet pythonQueue = Promise.resolve();\nfunction enqueue(fn) {\n const result = pythonQueue.then(fn, fn);\n pythonQueue = result.then(() => {}, () => {});\n return result;\n}\nfunction camelToSnakeCase(str) {\n return str.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);\n}\nfunction hasEntries(o) {\n return o != null && typeof o === \"object\" && Object.keys(o).length > 0;\n}\nfunction isOsdkObject(value) {\n return value != null && typeof value === \"object\" && \"$apiName\" in value && \"$primaryKey\" in value;\n}\nasync function fetchPkPropertyNames() {\n const response = await fetch(\"/api/v2/ontologies/ontology/objectTypes\", {\n headers: {\n \"Authorization\": LOCAL_RUNTIME_TOKEN\n }\n });\n if (!response.ok) {\n throw new Error(`Failed to fetch object types: ${response.status}`);\n }\n const data = await response.json();\n const objectTypes = data.data ?? data.objectTypes;\n if (!Array.isArray(objectTypes)) {\n throw new Error(\"Unexpected response format from object types endpoint\");\n }\n const map = new Map();\n for (const ot of objectTypes) {\n const pkProp = ot.primaryKeyPropertyApiName ?? ot.primaryKey;\n if (ot.apiName && pkProp) {\n map.set(ot.apiName, pkProp);\n }\n }\n return map;\n}\nfunction wrapObjectLocator(obj, pkNames) {\n const apiName = obj.$apiName;\n const pkProperty = pkNames.get(apiName);\n if (!pkProperty) {\n throw new Error(`No primary key property found for object type \"${apiName}\"`);\n }\n return {\n type: \"objectLocator\",\n objectLocator: {\n typeId: apiName,\n primaryKey: {\n [pkProperty]: obj.$primaryKey\n }\n }\n };\n}\nfunction wrapPrimitive(value) {\n if (typeof value === \"number\") {\n const type = Number.isInteger(value) ? \"integer\" : \"double\";\n return {\n type,\n [type]: value\n };\n }\n return {\n type: typeof value,\n [typeof value]: value\n };\n}\nfunction wrapValue(value, pkNames) {\n if (typeof value === \"number\" || typeof value === \"string\" || typeof value === \"boolean\") {\n return wrapPrimitive(value);\n }\n if (isOsdkObject(value)) {\n return wrapObjectLocator(value, pkNames);\n }\n if (Array.isArray(value) && value.length > 0 && value.every(isOsdkObject)) {\n return {\n type: \"list\",\n list: {\n values: value.map(item => wrapObjectLocator(item, pkNames))\n }\n };\n }\n return value;\n}\nfunction transformParametersToLocal(parameters, isPython, pkNames) {\n const transformed = {};\n for (const [key, value] of Object.entries(parameters)) {\n const paramName = isPython ? camelToSnakeCase(key) : key;\n transformed[paramName] = wrapValue(value, pkNames);\n }\n return transformed;\n}\nfunction transformResponseFromLocal(response) {\n const resp = response;\n if (resp?.executionResult?.type === \"success\") {\n const returnValue = resp.executionResult.success?.returnValue;\n if (returnValue?.type != null && returnValue.type in returnValue) {\n return returnValue[returnValue.type];\n }\n return returnValue;\n }\n if (resp?.executionResult?.type === \"failed\") {\n const msg = resp.executionResult.failed?.runtimeError?.message;\n if (!msg) {\n throw new Error(\"Function execution failed with no error message\");\n }\n throw new Error(msg);\n }\n throw new Error(\"Unexpected response format from local runtime\");\n}\nfunction createFunctionLocator(functionName, specs) {\n const funcSpec = specs?.functions?.find(f => {\n const locator = f.locator;\n if (locator?.type === \"typescript\") {\n return locator.typescript?.functionName === functionName;\n }\n if (locator?.type === \"python\") {\n return locator.python?.functionName === functionName;\n }\n return false;\n });\n if (!funcSpec?.locator) {\n throw new Error(`Function \"${functionName}\" not found in specs`);\n }\n const locator = funcSpec.locator;\n if (locator.type === \"python\" && locator.python) {\n return {\n type: \"python\",\n python: {\n moduleName: locator.python.moduleName,\n functionName: locator.python.functionName\n }\n };\n }\n if (locator.type === \"typescript\" && locator.typescript) {\n const filePath = locator.typescript.sourceProvenance?.stemma?.filePath;\n if (filePath) {\n return {\n type: \"typescript\",\n typescript: {\n filePath\n }\n };\n }\n }\n throw new Error(`Could not create locator for function \"${functionName}\"`);\n}\nconst SPECS_TIMEOUT_MS = 30_000;\nasync function fetchSpecs(runtime) {\n try {\n const response = await fetch(runtime.specsEndpoint, {\n method: \"GET\",\n headers: {\n \"Authorization\": LOCAL_RUNTIME_TOKEN\n },\n signal: AbortSignal.timeout(SPECS_TIMEOUT_MS)\n });\n if (!response.ok) return null;\n return await response.json();\n } catch {\n return null;\n }\n}\nasync function discoverFunctions() {\n const map = new Map();\n const tsSpecs = await fetchSpecs(TS_RUNTIME);\n if (tsSpecs?.functions) {\n for (const func of tsSpecs.functions) {\n const functionName = func.locator?.typescript?.functionName;\n if (functionName) {\n const prov = func.ontologyProvenance;\n const isEditFunction = hasEntries(prov?.editedObjects) || hasEntries(prov?.editedLinks) || hasEntries(prov?.editedInterfaces);\n map.set(functionName, {\n runtime: TS_RUNTIME,\n specs: tsSpecs,\n isEditFunction\n });\n }\n }\n }\n const pySpecs = await enqueue(() => fetchSpecs(PY_RUNTIME));\n if (pySpecs?.functions) {\n for (const func of pySpecs.functions) {\n const functionName = func.locator?.python?.functionName;\n if (functionName) {\n map.set(functionName, {\n runtime: PY_RUNTIME,\n specs: pySpecs,\n isEditFunction: false\n });\n }\n }\n }\n return map;\n}\nasync function postJsonToLocalRuntime(url, body) {\n const response = await fetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"Authorization\": LOCAL_RUNTIME_TOKEN\n },\n body: JSON.stringify(body)\n });\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(`Request to ${url} failed: ${response.status} - ${errorText}`);\n }\n return response;\n}\nasync function executeLocalFunction(functionDefinition, parameters) {\n const functionName = functionDefinition.apiName ?? functionDefinition.__DefinitionMetadata?.apiName;\n if (!functionName) {\n throw new Error(\"Unable to determine function name from definition\");\n }\n const functions = await discoverFunctions();\n const info = functions.get(functionName);\n if (!info) {\n throw new Error(`Function \"${functionName}\" not found in any local runtime`);\n }\n const isPython = info.runtime === PY_RUNTIME;\n const pkNames = await fetchPkPropertyNames();\n const transformedParams = transformParametersToLocal(parameters, isPython, pkNames);\n\n // Edit functions are routed through the action endpoint\n // so edits are applied to the store by the FunctionBackedActionHandler\n if (info.isEditFunction) {\n await postJsonToLocalRuntime(`/api/v2/ontologies/ontology/actions/${functionName}/apply`, {\n parameters: transformedParams\n });\n return undefined;\n }\n const locator = createFunctionLocator(functionName, info.specs);\n const requestBody = {\n locator,\n parameters: transformedParams,\n requestContext: {\n type: \"interactive\",\n interactive: {}\n }\n };\n const execute = async () => {\n const response = await postJsonToLocalRuntime(info.runtime.executeEndpoint, requestBody);\n return transformResponseFromLocal(await response.json());\n };\n return isPython ? enqueue(execute) : execute();\n}\n\n/**\n * Wraps an OSDK client to route function calls to local runtimes in development.\n */\nexport function smartClient(client) {\n return new Proxy(client, {\n apply(_target, _thisArg, args) {\n const [definition] = args;\n const result = client(...args);\n if (result && typeof result === \"object\" && typeof result.executeFunction === \"function\") {\n return new Proxy(result, {\n get(target, prop, receiver) {\n if (prop === \"executeFunction\") {\n return parameters => executeLocalFunction(definition, parameters);\n }\n return Reflect.get(target, prop, receiver);\n }\n });\n }\n return result;\n }\n });\n}"]}
@@ -0,0 +1,8 @@
1
+ import { Client } from '@osdk/client';
2
+
3
+ /**
4
+ * Wraps an OSDK client to route function calls to local runtimes in development.
5
+ */
6
+ declare function smartClient<T extends Client>(client: T): T;
7
+
8
+ export { smartClient };
@@ -0,0 +1,33 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /**
18
+ * Vite plugin that transparently wraps the OSDK client with smartClient
19
+ * during development. Any import of `client` from `src/client.ts`
20
+ * automatically gets the local-function-routing wrapper applied.
21
+ * Production builds are completely untouched.
22
+ */
23
+ export function smartClientPlugin() {
24
+ return {
25
+ name: "vite-plugin-smart-client",
26
+ apply: "serve",
27
+ transform(code, id) {
28
+ if (!id.endsWith("/src/client.ts")) return null;
29
+ return code.replace(/export const client\b/, "const __rawClient").replace(/export default client\b/, "export default __rawClient") + `\nimport { smartClient as __sc } from "@osdk/vite-plugin-superrepo/smartClient";\n` + `export const client = __sc(__rawClient);\n`;
30
+ }
31
+ };
32
+ }
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["smartClientPlugin","name","apply","transform","code","id","endsWith","replace"],"sources":["index.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Plugin } from \"vite\";\n\n/**\n * Vite plugin that transparently wraps the OSDK client with smartClient\n * during development. Any import of `client` from `src/client.ts`\n * automatically gets the local-function-routing wrapper applied.\n * Production builds are completely untouched.\n */\nexport function smartClientPlugin(): Plugin {\n return {\n name: \"vite-plugin-smart-client\",\n apply: \"serve\",\n\n transform(code, id) {\n if (!id.endsWith(\"/src/client.ts\")) return null;\n\n return (\n code\n .replace(/export const client\\b/, \"const __rawClient\")\n .replace(/export default client\\b/, \"export default __rawClient\")\n + `\\nimport { smartClient as __sc } from \"@osdk/vite-plugin-superrepo/smartClient\";\\n`\n + `export const client = __sc(__rawClient);\\n`\n );\n },\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,iBAAiBA,CAAA,EAAW;EAC1C,OAAO;IACLC,IAAI,EAAE,0BAA0B;IAChCC,KAAK,EAAE,OAAO;IAEdC,SAASA,CAACC,IAAI,EAAEC,EAAE,EAAE;MAClB,IAAI,CAACA,EAAE,CAACC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,IAAI;MAE/C,OACEF,IAAI,CACDG,OAAO,CAAC,uBAAuB,EAAE,mBAAmB,CAAC,CACrDA,OAAO,CAAC,yBAAyB,EAAE,4BAA4B,CAAC,GACjE,oFAAoF,GACpF,4CAA4C;IAElD;EACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,300 @@
1
+ /*
2
+ * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ const TS_RUNTIME = {
18
+ name: "TypeScript",
19
+ specsEndpoint: "/local-functions/functions-typescript-runtime/api/functions/preview/specs",
20
+ executeEndpoint: "/local-functions/functions-typescript-runtime/api/functions/runtime/execute"
21
+ };
22
+ const PY_RUNTIME = {
23
+ name: "Python",
24
+ specsEndpoint: "/local-python-functions/api/functions/preview/specs",
25
+ executeEndpoint: "/local-python-functions/api/functions/runtime/execute"
26
+ };
27
+ const LOCAL_RUNTIME_TOKEN = "Bearer fake-local-dev-token";
28
+
29
+ // Queue for serializing Python calls — the runtime can only handle one at a time
30
+ let pythonQueue = Promise.resolve();
31
+ function enqueue(fn) {
32
+ const result = pythonQueue.then(fn, fn);
33
+ pythonQueue = result.then(() => {}, () => {});
34
+ return result;
35
+ }
36
+ function camelToSnakeCase(str) {
37
+ return str.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);
38
+ }
39
+ function hasEntries(o) {
40
+ return o != null && typeof o === "object" && Object.keys(o).length > 0;
41
+ }
42
+ function isOsdkObject(value) {
43
+ return value != null && typeof value === "object" && "$apiName" in value && "$primaryKey" in value;
44
+ }
45
+ async function fetchPkPropertyNames() {
46
+ const response = await fetch("/api/v2/ontologies/ontology/objectTypes", {
47
+ headers: {
48
+ "Authorization": LOCAL_RUNTIME_TOKEN
49
+ }
50
+ });
51
+ if (!response.ok) {
52
+ throw new Error(`Failed to fetch object types: ${response.status}`);
53
+ }
54
+ const data = await response.json();
55
+ const objectTypes = data.data ?? data.objectTypes;
56
+ if (!Array.isArray(objectTypes)) {
57
+ throw new Error("Unexpected response format from object types endpoint");
58
+ }
59
+ const map = new Map();
60
+ for (const ot of objectTypes) {
61
+ const pkProp = ot.primaryKeyPropertyApiName ?? ot.primaryKey;
62
+ if (ot.apiName && pkProp) {
63
+ map.set(ot.apiName, pkProp);
64
+ }
65
+ }
66
+ return map;
67
+ }
68
+ function wrapObjectLocator(obj, pkNames) {
69
+ const apiName = obj.$apiName;
70
+ const pkProperty = pkNames.get(apiName);
71
+ if (!pkProperty) {
72
+ throw new Error(`No primary key property found for object type "${apiName}"`);
73
+ }
74
+ return {
75
+ type: "objectLocator",
76
+ objectLocator: {
77
+ typeId: apiName,
78
+ primaryKey: {
79
+ [pkProperty]: obj.$primaryKey
80
+ }
81
+ }
82
+ };
83
+ }
84
+ function wrapPrimitive(value) {
85
+ if (typeof value === "number") {
86
+ const type = Number.isInteger(value) ? "integer" : "double";
87
+ return {
88
+ type,
89
+ [type]: value
90
+ };
91
+ }
92
+ return {
93
+ type: typeof value,
94
+ [typeof value]: value
95
+ };
96
+ }
97
+ function wrapValue(value, pkNames) {
98
+ if (typeof value === "number" || typeof value === "string" || typeof value === "boolean") {
99
+ return wrapPrimitive(value);
100
+ }
101
+ if (isOsdkObject(value)) {
102
+ return wrapObjectLocator(value, pkNames);
103
+ }
104
+ if (Array.isArray(value) && value.length > 0 && value.every(isOsdkObject)) {
105
+ return {
106
+ type: "list",
107
+ list: {
108
+ values: value.map(item => wrapObjectLocator(item, pkNames))
109
+ }
110
+ };
111
+ }
112
+ return value;
113
+ }
114
+ function transformParametersToLocal(parameters, isPython, pkNames) {
115
+ const transformed = {};
116
+ for (const [key, value] of Object.entries(parameters)) {
117
+ const paramName = isPython ? camelToSnakeCase(key) : key;
118
+ transformed[paramName] = wrapValue(value, pkNames);
119
+ }
120
+ return transformed;
121
+ }
122
+ function transformResponseFromLocal(response) {
123
+ const resp = response;
124
+ if (resp?.executionResult?.type === "success") {
125
+ const returnValue = resp.executionResult.success?.returnValue;
126
+ if (returnValue?.type != null && returnValue.type in returnValue) {
127
+ return returnValue[returnValue.type];
128
+ }
129
+ return returnValue;
130
+ }
131
+ if (resp?.executionResult?.type === "failed") {
132
+ const msg = resp.executionResult.failed?.runtimeError?.message;
133
+ if (!msg) {
134
+ throw new Error("Function execution failed with no error message");
135
+ }
136
+ throw new Error(msg);
137
+ }
138
+ throw new Error("Unexpected response format from local runtime");
139
+ }
140
+ function createFunctionLocator(functionName, specs) {
141
+ const funcSpec = specs?.functions?.find(f => {
142
+ const locator = f.locator;
143
+ if (locator?.type === "typescript") {
144
+ return locator.typescript?.functionName === functionName;
145
+ }
146
+ if (locator?.type === "python") {
147
+ return locator.python?.functionName === functionName;
148
+ }
149
+ return false;
150
+ });
151
+ if (!funcSpec?.locator) {
152
+ throw new Error(`Function "${functionName}" not found in specs`);
153
+ }
154
+ const locator = funcSpec.locator;
155
+ if (locator.type === "python" && locator.python) {
156
+ return {
157
+ type: "python",
158
+ python: {
159
+ moduleName: locator.python.moduleName,
160
+ functionName: locator.python.functionName
161
+ }
162
+ };
163
+ }
164
+ if (locator.type === "typescript" && locator.typescript) {
165
+ const filePath = locator.typescript.sourceProvenance?.stemma?.filePath;
166
+ if (filePath) {
167
+ return {
168
+ type: "typescript",
169
+ typescript: {
170
+ filePath
171
+ }
172
+ };
173
+ }
174
+ }
175
+ throw new Error(`Could not create locator for function "${functionName}"`);
176
+ }
177
+ const SPECS_TIMEOUT_MS = 30_000;
178
+ async function fetchSpecs(runtime) {
179
+ try {
180
+ const response = await fetch(runtime.specsEndpoint, {
181
+ method: "GET",
182
+ headers: {
183
+ "Authorization": LOCAL_RUNTIME_TOKEN
184
+ },
185
+ signal: AbortSignal.timeout(SPECS_TIMEOUT_MS)
186
+ });
187
+ if (!response.ok) return null;
188
+ return await response.json();
189
+ } catch {
190
+ return null;
191
+ }
192
+ }
193
+ async function discoverFunctions() {
194
+ const map = new Map();
195
+ const tsSpecs = await fetchSpecs(TS_RUNTIME);
196
+ if (tsSpecs?.functions) {
197
+ for (const func of tsSpecs.functions) {
198
+ const functionName = func.locator?.typescript?.functionName;
199
+ if (functionName) {
200
+ const prov = func.ontologyProvenance;
201
+ const isEditFunction = hasEntries(prov?.editedObjects) || hasEntries(prov?.editedLinks) || hasEntries(prov?.editedInterfaces);
202
+ map.set(functionName, {
203
+ runtime: TS_RUNTIME,
204
+ specs: tsSpecs,
205
+ isEditFunction
206
+ });
207
+ }
208
+ }
209
+ }
210
+ const pySpecs = await enqueue(() => fetchSpecs(PY_RUNTIME));
211
+ if (pySpecs?.functions) {
212
+ for (const func of pySpecs.functions) {
213
+ const functionName = func.locator?.python?.functionName;
214
+ if (functionName) {
215
+ map.set(functionName, {
216
+ runtime: PY_RUNTIME,
217
+ specs: pySpecs,
218
+ isEditFunction: false
219
+ });
220
+ }
221
+ }
222
+ }
223
+ return map;
224
+ }
225
+ async function postJsonToLocalRuntime(url, body) {
226
+ const response = await fetch(url, {
227
+ method: "POST",
228
+ headers: {
229
+ "Content-Type": "application/json",
230
+ "Authorization": LOCAL_RUNTIME_TOKEN
231
+ },
232
+ body: JSON.stringify(body)
233
+ });
234
+ if (!response.ok) {
235
+ const errorText = await response.text();
236
+ throw new Error(`Request to ${url} failed: ${response.status} - ${errorText}`);
237
+ }
238
+ return response;
239
+ }
240
+ async function executeLocalFunction(functionDefinition, parameters) {
241
+ const functionName = functionDefinition.apiName ?? functionDefinition.__DefinitionMetadata?.apiName;
242
+ if (!functionName) {
243
+ throw new Error("Unable to determine function name from definition");
244
+ }
245
+ const functions = await discoverFunctions();
246
+ const info = functions.get(functionName);
247
+ if (!info) {
248
+ throw new Error(`Function "${functionName}" not found in any local runtime`);
249
+ }
250
+ const isPython = info.runtime === PY_RUNTIME;
251
+ const pkNames = await fetchPkPropertyNames();
252
+ const transformedParams = transformParametersToLocal(parameters, isPython, pkNames);
253
+
254
+ // Edit functions are routed through the action endpoint
255
+ // so edits are applied to the store by the FunctionBackedActionHandler
256
+ if (info.isEditFunction) {
257
+ await postJsonToLocalRuntime(`/api/v2/ontologies/ontology/actions/${functionName}/apply`, {
258
+ parameters: transformedParams
259
+ });
260
+ return undefined;
261
+ }
262
+ const locator = createFunctionLocator(functionName, info.specs);
263
+ const requestBody = {
264
+ locator,
265
+ parameters: transformedParams,
266
+ requestContext: {
267
+ type: "interactive",
268
+ interactive: {}
269
+ }
270
+ };
271
+ const execute = async () => {
272
+ const response = await postJsonToLocalRuntime(info.runtime.executeEndpoint, requestBody);
273
+ return transformResponseFromLocal(await response.json());
274
+ };
275
+ return isPython ? enqueue(execute) : execute();
276
+ }
277
+
278
+ /**
279
+ * Wraps an OSDK client to route function calls to local runtimes in development.
280
+ */
281
+ export function smartClient(client) {
282
+ return new Proxy(client, {
283
+ apply(_target, _thisArg, args) {
284
+ const [definition] = args;
285
+ const result = client(...args);
286
+ if (result && typeof result === "object" && typeof result.executeFunction === "function") {
287
+ return new Proxy(result, {
288
+ get(target, prop, receiver) {
289
+ if (prop === "executeFunction") {
290
+ return parameters => executeLocalFunction(definition, parameters);
291
+ }
292
+ return Reflect.get(target, prop, receiver);
293
+ }
294
+ });
295
+ }
296
+ return result;
297
+ }
298
+ });
299
+ }
300
+ //# sourceMappingURL=smartClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"smartClient.js","names":["TS_RUNTIME","name","specsEndpoint","executeEndpoint","PY_RUNTIME","LOCAL_RUNTIME_TOKEN","pythonQueue","Promise","resolve","enqueue","fn","result","then","camelToSnakeCase","str","replace","letter","toLowerCase","hasEntries","o","Object","keys","length","isOsdkObject","value","fetchPkPropertyNames","response","fetch","headers","ok","Error","status","data","json","objectTypes","Array","isArray","map","Map","ot","pkProp","primaryKeyPropertyApiName","primaryKey","apiName","set","wrapObjectLocator","obj","pkNames","$apiName","pkProperty","get","type","objectLocator","typeId","$primaryKey","wrapPrimitive","Number","isInteger","wrapValue","every","list","values","item","transformParametersToLocal","parameters","isPython","transformed","key","entries","paramName","transformResponseFromLocal","resp","executionResult","returnValue","success","msg","failed","runtimeError","message","createFunctionLocator","functionName","specs","funcSpec","functions","find","f","locator","typescript","python","moduleName","filePath","sourceProvenance","stemma","SPECS_TIMEOUT_MS","fetchSpecs","runtime","method","signal","AbortSignal","timeout","discoverFunctions","tsSpecs","func","prov","ontologyProvenance","isEditFunction","editedObjects","editedLinks","editedInterfaces","pySpecs","postJsonToLocalRuntime","url","body","JSON","stringify","errorText","text","executeLocalFunction","functionDefinition","__DefinitionMetadata","info","transformedParams","undefined","requestBody","requestContext","interactive","execute","smartClient","client","Proxy","apply","_target","_thisArg","args","definition","executeFunction","target","prop","receiver","Reflect"],"sources":["smartClient.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { Client } from \"@osdk/client\";\n\ninterface RuntimeConfig {\n name: \"TypeScript\" | \"Python\";\n specsEndpoint: string;\n executeEndpoint: string;\n}\n\nconst TS_RUNTIME: RuntimeConfig = {\n name: \"TypeScript\",\n specsEndpoint:\n \"/local-functions/functions-typescript-runtime/api/functions/preview/specs\",\n executeEndpoint:\n \"/local-functions/functions-typescript-runtime/api/functions/runtime/execute\",\n};\n\nconst PY_RUNTIME: RuntimeConfig = {\n name: \"Python\",\n specsEndpoint: \"/local-python-functions/api/functions/preview/specs\",\n executeEndpoint: \"/local-python-functions/api/functions/runtime/execute\",\n};\n\nconst LOCAL_RUNTIME_TOKEN = \"Bearer fake-local-dev-token\";\n\n// Queue for serializing Python calls — the runtime can only handle one at a time\nlet pythonQueue: Promise<unknown> = Promise.resolve();\n\nfunction enqueue<T>(fn: () => Promise<T>): Promise<T> {\n const result = pythonQueue.then(fn, fn);\n pythonQueue = result.then(() => {}, () => {});\n return result;\n}\n\nfunction camelToSnakeCase(str: string): string {\n return str.replace(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);\n}\n\nfunction hasEntries(o: unknown): boolean {\n return o != null && typeof o === \"object\"\n && Object.keys(o as Record<string, unknown>).length > 0;\n}\n\nfunction isOsdkObject(\n value: unknown,\n): value is { $apiName: string; $primaryKey: unknown } {\n return value != null && typeof value === \"object\"\n && \"$apiName\" in value && \"$primaryKey\" in value;\n}\n\nasync function fetchPkPropertyNames(): Promise<Map<string, string>> {\n const response = await fetch(\"/api/v2/ontologies/ontology/objectTypes\", {\n headers: { \"Authorization\": LOCAL_RUNTIME_TOKEN },\n });\n if (!response.ok) {\n throw new Error(\n `Failed to fetch object types: ${response.status}`,\n );\n }\n const data = await response.json() as Record<string, unknown>;\n const objectTypes = data.data ?? data.objectTypes;\n if (!Array.isArray(objectTypes)) {\n throw new Error(\n \"Unexpected response format from object types endpoint\",\n );\n }\n const map = new Map<string, string>();\n for (const ot of objectTypes as Record<string, string>[]) {\n const pkProp = ot.primaryKeyPropertyApiName ?? ot.primaryKey;\n if (ot.apiName && pkProp) {\n map.set(ot.apiName, pkProp);\n }\n }\n return map;\n}\n\nfunction wrapObjectLocator(\n obj: { $apiName: string; $primaryKey: unknown },\n pkNames: Map<string, string>,\n): unknown {\n const apiName = obj.$apiName;\n const pkProperty = pkNames.get(apiName);\n if (!pkProperty) {\n throw new Error(\n `No primary key property found for object type \"${apiName}\"`,\n );\n }\n return {\n type: \"objectLocator\",\n objectLocator: {\n typeId: apiName,\n primaryKey: { [pkProperty]: obj.$primaryKey },\n },\n };\n}\n\nfunction wrapPrimitive(\n value: number | string | boolean,\n): { type: string; [key: string]: number | string | boolean } {\n if (typeof value === \"number\") {\n const type = Number.isInteger(value) ? \"integer\" : \"double\";\n return { type, [type]: value };\n }\n return { type: typeof value, [typeof value]: value };\n}\n\nfunction wrapValue(\n value: unknown,\n pkNames: Map<string, string>,\n): unknown {\n if (\n typeof value === \"number\" || typeof value === \"string\"\n || typeof value === \"boolean\"\n ) {\n return wrapPrimitive(value);\n }\n if (isOsdkObject(value)) {\n return wrapObjectLocator(value, pkNames);\n }\n if (\n Array.isArray(value) && value.length > 0 && value.every(isOsdkObject)\n ) {\n return {\n type: \"list\",\n list: {\n values: value.map(item => wrapObjectLocator(item, pkNames)),\n },\n };\n }\n return value;\n}\n\nfunction transformParametersToLocal(\n parameters: Record<string, unknown>,\n isPython: boolean,\n pkNames: Map<string, string>,\n): Record<string, unknown> {\n const transformed: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(parameters)) {\n const paramName = isPython ? camelToSnakeCase(key) : key;\n transformed[paramName] = wrapValue(value, pkNames);\n }\n return transformed;\n}\n\ninterface TypedValue {\n type: string;\n double?: number;\n integer?: number;\n string?: string;\n boolean?: boolean;\n}\n\ninterface ExecutionResult {\n executionResult?: {\n type: string;\n success?: { returnValue?: TypedValue };\n failed?: { runtimeError?: { message?: string } };\n };\n}\n\nfunction transformResponseFromLocal(response: unknown): unknown {\n const resp = response as ExecutionResult;\n\n if (resp?.executionResult?.type === \"success\") {\n const returnValue = resp.executionResult.success?.returnValue;\n if (returnValue?.type != null && returnValue.type in returnValue) {\n return returnValue[returnValue.type as keyof TypedValue];\n }\n return returnValue;\n }\n\n if (resp?.executionResult?.type === \"failed\") {\n const msg = resp.executionResult.failed?.runtimeError?.message;\n if (!msg) {\n throw new Error(\"Function execution failed with no error message\");\n }\n throw new Error(msg);\n }\n\n throw new Error(\"Unexpected response format from local runtime\");\n}\n\ninterface FunctionLocator {\n type: \"typescript\" | \"python\";\n typescript?: { filePath: string };\n python?: { moduleName: string; functionName: string };\n}\n\ninterface FunctionSpec {\n locator: {\n type: \"typescript\" | \"python\";\n typescript?: {\n functionName: string;\n sourceProvenance?: { stemma?: { filePath: string } };\n };\n python?: {\n moduleName: string;\n functionName: string;\n };\n };\n ontologyProvenance?: {\n editedObjects?: Record<string, unknown>;\n editedLinks?: Record<string, unknown>;\n editedInterfaces?: Record<string, unknown>;\n };\n}\n\ninterface RuntimeSpecs {\n functions?: FunctionSpec[];\n}\n\nfunction createFunctionLocator(\n functionName: string,\n specs: RuntimeSpecs,\n): FunctionLocator {\n const funcSpec = specs?.functions?.find((f) => {\n const locator = f.locator;\n if (locator?.type === \"typescript\") {\n return locator.typescript?.functionName === functionName;\n }\n if (locator?.type === \"python\") {\n return locator.python?.functionName === functionName;\n }\n return false;\n });\n\n if (!funcSpec?.locator) {\n throw new Error(`Function \"${functionName}\" not found in specs`);\n }\n\n const locator = funcSpec.locator;\n\n if (locator.type === \"python\" && locator.python) {\n return {\n type: \"python\",\n python: {\n moduleName: locator.python.moduleName,\n functionName: locator.python.functionName,\n },\n };\n }\n\n if (locator.type === \"typescript\" && locator.typescript) {\n const filePath = locator.typescript.sourceProvenance?.stemma?.filePath;\n if (filePath) {\n return {\n type: \"typescript\",\n typescript: { filePath },\n };\n }\n }\n\n throw new Error(\n `Could not create locator for function \"${functionName}\"`,\n );\n}\n\nconst SPECS_TIMEOUT_MS = 30_000;\n\nasync function fetchSpecs(\n runtime: RuntimeConfig,\n): Promise<RuntimeSpecs | null> {\n try {\n const response = await fetch(runtime.specsEndpoint, {\n method: \"GET\",\n headers: { \"Authorization\": LOCAL_RUNTIME_TOKEN },\n signal: AbortSignal.timeout(SPECS_TIMEOUT_MS),\n });\n if (!response.ok) return null;\n return await response.json() as RuntimeSpecs;\n } catch {\n return null;\n }\n}\n\ninterface FunctionInfo {\n runtime: RuntimeConfig;\n specs: RuntimeSpecs;\n isEditFunction: boolean;\n}\n\nasync function discoverFunctions(): Promise<Map<string, FunctionInfo>> {\n const map = new Map<string, FunctionInfo>();\n\n const tsSpecs = await fetchSpecs(TS_RUNTIME);\n if (tsSpecs?.functions) {\n for (const func of tsSpecs.functions) {\n const functionName = func.locator?.typescript?.functionName;\n if (functionName) {\n const prov = func.ontologyProvenance;\n const isEditFunction = hasEntries(prov?.editedObjects)\n || hasEntries(prov?.editedLinks)\n || hasEntries(prov?.editedInterfaces);\n map.set(functionName, {\n runtime: TS_RUNTIME,\n specs: tsSpecs,\n isEditFunction,\n });\n }\n }\n }\n\n const pySpecs = await enqueue(() => fetchSpecs(PY_RUNTIME));\n if (pySpecs?.functions) {\n for (const func of pySpecs.functions) {\n const functionName = func.locator?.python?.functionName;\n if (functionName) {\n map.set(functionName, {\n runtime: PY_RUNTIME,\n specs: pySpecs,\n isEditFunction: false,\n });\n }\n }\n }\n\n return map;\n}\n\nasync function postJsonToLocalRuntime(\n url: string,\n body: unknown,\n): Promise<Response> {\n const response = await fetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"Authorization\": LOCAL_RUNTIME_TOKEN,\n },\n body: JSON.stringify(body),\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(\n `Request to ${url} failed: ${response.status} - ${errorText}`,\n );\n }\n\n return response;\n}\n\ninterface FunctionDefinition {\n apiName?: string;\n __DefinitionMetadata?: { apiName?: string };\n}\n\nasync function executeLocalFunction(\n functionDefinition: FunctionDefinition,\n parameters: Record<string, unknown>,\n): Promise<unknown> {\n const functionName = functionDefinition.apiName\n ?? functionDefinition.__DefinitionMetadata?.apiName;\n if (!functionName) {\n throw new Error(\"Unable to determine function name from definition\");\n }\n\n const functions = await discoverFunctions();\n const info = functions.get(functionName);\n\n if (!info) {\n throw new Error(\n `Function \"${functionName}\" not found in any local runtime`,\n );\n }\n\n const isPython = info.runtime === PY_RUNTIME;\n const pkNames = await fetchPkPropertyNames();\n const transformedParams = transformParametersToLocal(\n parameters,\n isPython,\n pkNames,\n );\n\n // Edit functions are routed through the action endpoint\n // so edits are applied to the store by the FunctionBackedActionHandler\n if (info.isEditFunction) {\n await postJsonToLocalRuntime(\n `/api/v2/ontologies/ontology/actions/${functionName}/apply`,\n { parameters: transformedParams },\n );\n return undefined;\n }\n\n const locator = createFunctionLocator(functionName, info.specs);\n const requestBody = {\n locator,\n parameters: transformedParams,\n requestContext: { type: \"interactive\", interactive: {} },\n };\n\n const execute = async () => {\n const response = await postJsonToLocalRuntime(\n info.runtime.executeEndpoint,\n requestBody,\n );\n return transformResponseFromLocal(await response.json());\n };\n\n return isPython ? enqueue(execute) : execute();\n}\n\n/**\n * Wraps an OSDK client to route function calls to local runtimes in development.\n */\nexport function smartClient<T extends Client>(client: T): T {\n return new Proxy(client as unknown as Function, {\n apply(_target, _thisArg, args) {\n const [definition] = args as [FunctionDefinition];\n const result = (client as unknown as Function)(...args);\n\n if (\n result && typeof result === \"object\"\n && typeof (result as Record<string, unknown>).executeFunction\n === \"function\"\n ) {\n return new Proxy(result as object, {\n get(target, prop, receiver) {\n if (prop === \"executeFunction\") {\n return (parameters: Record<string, unknown>) =>\n executeLocalFunction(definition, parameters);\n }\n return Reflect.get(target, prop, receiver);\n },\n });\n }\n\n return result;\n },\n }) as unknown as T;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAUA,MAAMA,UAAyB,GAA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,OAAO2E,OAAO,CAACzF,GAAG,CAACsF,MAAM,EAAEC,IAAI,EAAEC,QAAQ,CAAC;UAC5C;QACF,CAAC,CAAC;MACJ;MAEA,OAAO/H,MAAM;IACf;EACF,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -0,0 +1,8 @@
1
+ import type { Plugin } from "vite";
2
+ /**
3
+ * Vite plugin that transparently wraps the OSDK client with smartClient
4
+ * during development. Any import of `client` from `src/client.ts`
5
+ * automatically gets the local-function-routing wrapper applied.
6
+ * Production builds are completely untouched.
7
+ */
8
+ export declare function smartClientPlugin(): Plugin;
@@ -0,0 +1 @@
1
+ {"mappings":"AAgBA,cAAc,cAAc,MAAO;;;;;;;AAQnC,OAAO,iBAAS,qBAAqB","names":[],"sources":["../../src/index.ts"],"version":3,"file":"index.d.ts"}
@@ -0,0 +1,5 @@
1
+ import type { Client } from "@osdk/client";
2
+ /**
3
+ * Wraps an OSDK client to route function calls to local runtimes in development.
4
+ */
5
+ export declare function smartClient<T extends Client>(client: T): T;
@@ -0,0 +1 @@
1
+ {"mappings":"AAgBA,cAAc,cAAc,cAAe;;;;AAqZ3C,OAAO,iBAAS,YAAY,UAAU,QAAQA,QAAQ,IAAI","names":["client: T"],"sources":["../../../src/public/smartClient.ts"],"version":3,"file":"smartClient.d.ts"}
package/package.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "name": "@osdk/vite-plugin-superrepo",
3
+ "version": "0.1.0",
4
+ "license": "Apache-2.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/palantir/osdk-ts.git"
8
+ },
9
+ "exports": {
10
+ ".": {
11
+ "browser": "./build/browser/index.js",
12
+ "import": {
13
+ "types": "./build/types/index.d.ts",
14
+ "default": "./build/esm/index.js"
15
+ },
16
+ "require": "./build/cjs/index.cjs",
17
+ "default": "./build/browser/index.js"
18
+ },
19
+ "./smartClient": {
20
+ "browser": "./build/browser/public/smartClient.js",
21
+ "import": {
22
+ "types": "./build/types/public/smartClient.d.ts",
23
+ "default": "./build/esm/public/smartClient.js"
24
+ },
25
+ "require": "./build/cjs/public/smartClient.cjs",
26
+ "default": "./build/browser/public/smartClient.js"
27
+ },
28
+ "./*": {
29
+ "browser": "./build/browser/public/*.js",
30
+ "import": {
31
+ "types": "./build/types/public/*.d.ts",
32
+ "default": "./build/esm/public/*.js"
33
+ },
34
+ "require": "./build/cjs/public/*.cjs",
35
+ "default": "./build/browser/public/*.js"
36
+ }
37
+ },
38
+ "peerDependencies": {
39
+ "@osdk/client": "*",
40
+ "vite": "*"
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "^20.19.13",
44
+ "typescript": "~5.5.4",
45
+ "@osdk/monorepo.tsconfig": "~0.7.0-beta.1",
46
+ "@osdk/monorepo.api-extractor": "~0.7.0-beta.1"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "files": [
52
+ "build/cjs",
53
+ "build/esm",
54
+ "build/browser",
55
+ "build/types",
56
+ "CHANGELOG.md",
57
+ "package.json",
58
+ "templates",
59
+ "*.d.ts"
60
+ ],
61
+ "main": "./build/cjs/index.cjs",
62
+ "module": "./build/esm/index.js",
63
+ "types": "./build/cjs/index.d.cts",
64
+ "type": "module",
65
+ "scripts": {
66
+ "check-attw": "attw --pack .",
67
+ "check-spelling": "cspell --quiet .",
68
+ "clean": "rm -rf lib dist types build tsconfig.tsbuildinfo",
69
+ "fix-lint": "eslint . --fix && dprint fmt --config $(find-up dprint.json)",
70
+ "lint": "eslint . && dprint check --config $(find-up dprint.json)",
71
+ "transpileBrowser": "monorepo.tool.transpile -f esm -m normal -t browser",
72
+ "transpileCjs": "monorepo.tool.transpile -f cjs -m bundle -t node",
73
+ "transpileEsm": "monorepo.tool.transpile -f esm -m normal -t node",
74
+ "transpileTypes": "monorepo.tool.transpile -f esm -m types -t node",
75
+ "typecheck": "tsc --noEmit --emitDeclarationOnly false"
76
+ }
77
+ }
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright 2024 Palantir Technologies, Inc. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ export * from "./build/cjs/public/smartClient.cjs";