Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add devin debug message #3192

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions weave-js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions weave-js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "weave",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"devDependencies": {
"@types/node": "^22.10.1",
"typescript": "^5.7.2"
},
"dependencies": {
"isomorphic-unfetch": "^4.0.2"
}
}
152 changes: 152 additions & 0 deletions weave-js/src/core/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import type Fetch from 'isomorphic-unfetch';

import {GlobalCGEventTracker} from './analytics/tracker';
import {InMemoryCache} from './cache';
import {BasicClient, CachedClient, Client} from './client';
import {supportedEngineForNode} from './hl';
import {nodeToString} from './language/js/print';
import {MemoizedHasher} from './model/graph/editing/hash';
import {Node} from './model/graph/types';
import {makePerformanceMixedOpStore} from './opStore/mixedOpStore';
import {OpStore} from './opStore/types';
import {
LocalServer,
RemoteHttpServer,
Server,
ServerWithShadow,
} from './server';
import {RoutedServer, Router} from './server/routed';
import {ServerAPI} from './serverApi';
import {
DEBUG_ATTACH_TO_GLOBAL_THIS,
LOG_DEBUG_MESSAGES,
} from './util/constants';

if (LOG_DEBUG_MESSAGES) {
console.debug("hello, world! i'm devin");
}

// Useful for console debugging
export function bindClientToGlobalThis(client: Client) {
if (typeof globalThis !== 'undefined' && DEBUG_ATTACH_TO_GLOBAL_THIS) {
(globalThis as any).cgquery = client.query.bind(client);
}
}

export function createLocalServer(backend: ServerAPI): Server {
const hashing = new MemoizedHasher();
const cache = new InMemoryCache({keyFn: hashing.typedNodeId});
return new LocalServer(cache, backend);
}

export function createLocalClient(backend: ServerAPI): Client {
const client = new BasicClient(createLocalServer(backend));

bindClientToGlobalThis(client);
return client;
}

export function createRemoteServer(
weaveUrl: string,
tokenFunc: () => Promise<string | undefined>,
opStore: OpStore,
isAdmin = false,
isShadow = false,
anonApiKey?: string,
fetch?: typeof Fetch
): Server {
return new RemoteHttpServer(
{
weaveUrl,
tokenFunc,
anonApiKey,
useAdminPrivileges: isAdmin,
isShadow,
fetch,
},
opStore
);
}

export function createRemoteClient(
weaveUrl: string,
tokenFunc: () => Promise<string | undefined>,
isAdmin = false,
opStore: OpStore,
anonApiKey?: string,
fetch?: typeof Fetch
): Client {
const remoteServer = createRemoteServer(
weaveUrl,
tokenFunc,
opStore,
isAdmin,
false,
anonApiKey,
fetch
);
const client = new CachedClient(new BasicClient(remoteServer));

bindClientToGlobalThis(client);
return client;
}

export function createServerWithShadow(
mainServer: Server,
shadowServer: Server
): Server {
return new ServerWithShadow(mainServer, shadowServer);
}

export function createdRoutedPerformanceServer(
localServer: Server,
pythonServer: Server
): Server {
const {routingFunc, opStore} = performanceRouter(localServer, pythonServer);
const router = new Router([localServer, pythonServer], opStore, routingFunc);
return new RoutedServer(router, opStore);
}

function performanceRouter(
localServer: Server,
pythonServer: Server
): {routingFunc: (node: Node) => Server; opStore: OpStore} {
const opStore = makePerformanceMixedOpStore(
localServer.opStore,
pythonServer.opStore
);
const routingFunc = (node: Node) => {
const supportedEngines = supportedEngineForNode(node, opStore);
if (supportedEngines.size === 0) {
if (LOG_DEBUG_MESSAGES) {
console.warn(
`No allowed engines for node, ${JSON.stringify(
node
)}, using TS backend`
);
}
GlobalCGEventTracker.routedServerLocal++;
return localServer;
} else if (supportedEngines.has('py')) {
if (LOG_DEBUG_MESSAGES) {
console.log(
'RoutingFunc: Using Python backend \n',
nodeToString(node, opStore)
);
}
GlobalCGEventTracker.routedServerRemote++;
return pythonServer;
} else {
if (LOG_DEBUG_MESSAGES) {
console.log(
'RoutingFunc: Using Typescript backend \n',
nodeToString(node, opStore)
);
}
GlobalCGEventTracker.routedServerLocal++;
return localServer;
}
};

return {opStore, routingFunc};
}
2 changes: 2 additions & 0 deletions weave-js/src/util/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const DEBUG_ATTACH_TO_GLOBAL_THIS = true;
export const LOG_DEBUG_MESSAGES = true;
17 changes: 17 additions & 0 deletions weave-js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "es2018",
"module": "commonjs",
"lib": ["es2018", "dom"],
"declaration": true,
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}