Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sqs committed Dec 28, 2023
1 parent bf1eeee commit 99d390f
Show file tree
Hide file tree
Showing 57 changed files with 2,438 additions and 209 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ _Status: alpha_

## TODOs

- rename opencodegraphdata -> something shorter
- item.ui and item.ai
- add support for resolving annotations (because )
1 change: 1 addition & 0 deletions client/web-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@codemirror/lint": "^6.4.2",
"@opencodegraph/client": "workspace:*",
"@opencodegraph/codemirror-extension": "workspace:*",
"@opencodegraph/provider-docs": "workspace:*",
"@opencodegraph/provider-links": "workspace:*",
"@opencodegraph/provider-storybook": "workspace:*",
"@opencodegraph/ui-react": "workspace:*",
Expand Down
21 changes: 19 additions & 2 deletions client/web-playground/src/demo/settings.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
import { type ProviderSettings } from '@opencodegraph/client'

const USE_STORED_CORPUS = true

async function getProviders(): Promise<Record<string, ProviderSettings | boolean>> {
const providerSettings: Record<string, ProviderSettings | boolean> = {
'../../../../provider/hello-world/index.ts': true,
'../../../../provider/hello-world/index.ts': false,
'../../../../provider/docs/src/provider/provider.ts': {
corpus: USE_STORED_CORPUS
? {
url: new URL(
'tmp-ocg-provider-docs/sourcegraph-docs-old-web-corpus.json',
import.meta.url
).toString(),
}
: {
entryPage: 'http://localhost:5800/docs/start',
prefix: 'http://localhost:5800/docs',
},
} satisfies import('@opencodegraph/provider-docs').Settings,
'../../../../provider/links/index.ts': {
links: [
{
Expand Down Expand Up @@ -38,7 +53,9 @@ async function getProviders(): Promise<Record<string, ProviderSettings | boolean
} satisfies import('@opencodegraph/provider-storybook').Settings,
}

const providerModules = import.meta.glob('../../../../provider/*/index.ts', { as: 'url' })
const providerModules = import.meta.glob('../../../../provider/{*/index.ts,docs/src/provider/provider.ts}', {
as: 'url',
})
for (const [path, url] of Object.entries(providerModules)) {
const providerUri = new URL(await url(), import.meta.url).toString()
const settings = providerSettings[path] ?? true
Expand Down
20 changes: 16 additions & 4 deletions client/web-playground/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { resolve } from 'path'
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
import { defineConfig, searchForWorkspaceRoot } from 'vite'

// TODO(sqs): un-hardcode
const docsProviderDataDir = resolve('/Users/sqs/tmp/ocg-provider-docs')

export default defineConfig(({ mode }) => ({
plugins: [react()],
resolve: {
alias:
mode === 'development'
alias: [
...(mode === 'development'
? [
// In dev mode, build from TypeScript sources so we don't need to run `tsc -b`
// in the background.
Expand All @@ -17,8 +20,14 @@ export default defineConfig(({ mode }) => ({
replacement: '$1/src/index',
},
]
: [],
: []),
{
find: 'tmp-ocg-provider-docs',
replacement: docsProviderDataDir,
},
],
},
define: {},
css: {
devSourcemap: true,
modules: {
Expand All @@ -27,6 +36,9 @@ export default defineConfig(({ mode }) => ({
},
server: {
port: 5900,
fs: {
allow: [searchForWorkspaceRoot(process.cwd()), docsProviderDataDir],
},
},
build: {
emptyOutDir: false,
Expand Down
1 change: 1 addition & 0 deletions lib/client/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export function observeAnnotations<R extends Range>(
emitPartial ? startWith(null) : tap(),
catchError(error => {
logger?.(`failed to get annotations: ${error}`)
console.error(error)
return of(null)
})
)
Expand Down
2 changes: 1 addition & 1 deletion lib/protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"sideEffects": false,
"scripts": {
"generate": "node --no-warnings=ExperimentalWarning --loader ts-node/esm/transpile-only ../schema/dev/generateJsonSchemaTypes.ts src/opencodegraph-protocol.schema.json \"import { Item, Annotation } from '@opencodegraph/schema'\" > src/opencodegraph-protocol.schema.ts && pnpm -w run format \"$PNPM_SCRIPT_SRC_DIR/src/opencodegraph-protocol.schema.ts\"",
"generate": "node --no-warnings=ExperimentalWarning --loader ts-node/esm/transpile-only ../schema/dev/generateJsonSchemaTypes.ts src/opencodegraph-protocol.schema.json \"import { Annotation } from '@opencodegraph/schema'\" > src/opencodegraph-protocol.schema.ts && pnpm -w run format \"$PNPM_SCRIPT_SRC_DIR/src/opencodegraph-protocol.schema.ts\"",
"build": "pnpm run --silent generate && tsc --build",
"test": "vitest",
"prepublishOnly": "tsc --build --clean && pnpm run build"
Expand Down
58 changes: 41 additions & 17 deletions lib/schema/src/opencodegraph.schema.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "opencodegraph.schema.json#",
"title": "Data",
"title": "Schema",
"description": "Metadata about code",
"allowComments": true,
"type": "object",
Expand All @@ -14,35 +14,59 @@
},
"definitions": {
"Annotation": {
"description": "An annotation describes information relevant to a specific range in a file.",
"description": "An annotation describes information relevant to a file (or a range within a file).",
"type": "object",
"additionalProperties": false,
"required": ["item", "range"],
"required": [],
"properties": {
"item": { "$ref": "#/definitions/Item" },
"range": { "$ref": "#/definitions/Range" }
"title": {
"description": "A descriptive title of the annotation.",
"type": "string"
},
"url": {
"description": "An external URL with more information about the annotation.",
"type": "string",
"format": "uri"
},
"ui": {
"description": "The human user interface of the annotation, with information for human consumption.",
"$ref": "#/definitions/AnnotationUI"
},
"ai": {
"description": "Information from the annotation intended for consumption by AI, not humans.222",
"$ref": "#/definitions/AssistantInfo"
},
"range": {
"description": "The range in the file that this annotation applies to. If not set, the annotation applies to the entire file.",
"$ref": "#/definitions/Range"
}
}
},
"Item": {
"AnnotationUI": {
"description": "The human user interface of an annotation, with information for human consumption.",
"type": "object",
"additionalProperties": false,
"required": ["title"],
"properties": {
"title": { "type": "string" },
"detail": { "type": "string" },
"url": { "description": "An external URL with more information.", "type": "string", "format": "uri" },
"image": { "$ref": "#/definitions/ItemImage" }
"detail": {
"description": "Text containing additional details for the human, shown when they interact with the annotation.",
"type": "string"
},
"format": {
"description": "The format of the title and description (Markdown or plain text).",
"type": "string",
"enum": ["markdown", "plaintext"]
}
}
},
"ItemImage": {
"AssistantInfo": {
"description": "Information from an annotation intended for consumption by AI, not humans.",
"type": "object",
"additionalProperties": false,
"required": ["url"],
"properties": {
"url": { "type": "string", "format": "uri" },
"width": { "type": "number" },
"height": { "type": "number" },
"alt": { "type": "string" }
"content": {
"description": "Text content for AI to consume.",
"type": "string"
}
}
},
"Range": {
Expand Down
47 changes: 33 additions & 14 deletions lib/schema/src/opencodegraph.schema.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,50 @@
/**
* Metadata about code
*/
export interface Data {
export interface Schema {
annotations?: Annotation[]
}
/**
* An annotation describes information relevant to a specific range in a file.
* An annotation describes information relevant to a file (or a range within a file).
*/
export interface Annotation {
item: Item
range: Range
/**
* A descriptive title of the annotation.
*/
title?: string
/**
* An external URL with more information about the annotation.
*/
url?: string
ui?: AnnotationUI
ai?: AssistantInfo
range?: Range
}
export interface Item {
title: string
/**
* The human user interface of the annotation, with information for human consumption.
*/
export interface AnnotationUI {
/**
* Text containing additional details for the human, shown when they interact with the annotation.
*/
detail?: string
/**
* An external URL with more information.
* The format of the title and description (Markdown or plain text).
*/
url?: string
image?: ItemImage
format?: 'markdown' | 'plaintext'
}
export interface ItemImage {
url: string
width?: number
height?: number
alt?: string
/**
* Information from the annotation intended for consumption by AI, not humans.222
*/
export interface AssistantInfo {
/**
* Text content for AI to consume.
*/
content?: string
}
/**
* The range in the file that this annotation applies to. If not set, the annotation applies to the entire file.
*/
export interface Range {
start: Position
end: Position
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"ts-node": "^10.9.2",
"typescript": "^5.3.3",
"vite": "^5",
"vitest": "^0"
"vitest": "^1.1.0"
},
"eslintConfig": {
"extends": "./.config/eslintrc.js"
Expand Down
Loading

0 comments on commit 99d390f

Please sign in to comment.