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(servlets): add obsidian plugin #29

Merged
merged 4 commits into from
Dec 23, 2024
Merged
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
5 changes: 5 additions & 0 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ jobs:
run: |
curl -L https://raw.githubusercontent.com/extism/js-pdk/main/install.sh | bash

- name: Install extism-py and uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
curl -Ls https://raw.githubusercontent.com/extism/python-pdk/main/install.sh | bash

- name: Install xtp CLI
run: |
curl -L https://static.dylibso.com/cli/install.sh -s | bash
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ jobs:
run: |
curl -L https://raw.githubusercontent.com/extism/js-pdk/main/install.sh | bash

- name: Install extism-py and uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
curl -Ls https://raw.githubusercontent.com/extism/python-pdk/main/install.sh | bash

- name: Install xtp CLI
run: |
curl -L https://static.dylibso.com/cli/install.sh -s | bash
Expand Down
45 changes: 45 additions & 0 deletions servlets/obsidian/plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# THIS FILE WAS GENERATED BY `xtp-python-bindgen`. DO NOT EDIT.

from typing import Optional, List # noqa: F401
from datetime import datetime # noqa: F401
import extism # pyright: ignore
import plugin
import json

from pdk_types import (
BlobResourceContents,
CallToolRequest,
CallToolResult,
Content,
ContentType,
ListToolsResult,
Params,
Role,
TextAnnotation,
TextResourceContents,
ToolDescription,
) # noqa: F401


# Imports

# Exports
# The implementations for these functions is in `plugin.py`


# Called when the tool is invoked.
# If you support multiple tools, you must switch on the input.params.name to detect which tool is being called.
@extism.plugin_fn
def call():
data = json.loads(extism.input_str())
res = plugin.call(data)
extism.output(res)


# Called by mcpx to understand how and why to use this tool.
# Note: Your servlet configs will not be set when this function is called,
# so do not rely on config in this function
@extism.plugin_fn
def describe():
res = plugin.describe()
extism.output(res)
20 changes: 20 additions & 0 deletions servlets/obsidian/plugin/pdk_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# THIS FILE WAS GENERATED BY `xtp-python-bindgen`. DO NOT EDIT.

from typing import Optional, List # noqa: F401
from datetime import datetime # noqa: F401
import extism # noqa: F401 # pyright: ignore


from pdk_types import (
BlobResourceContents,
CallToolRequest,
CallToolResult,
Content,
ContentType,
ListToolsResult,
Params,
Role,
TextAnnotation,
TextResourceContents,
ToolDescription,
) # noqa: F401
117 changes: 117 additions & 0 deletions servlets/obsidian/plugin/pdk_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# THIS FILE WAS GENERATED BY `xtp-python-bindgen`. DO NOT EDIT.

from __future__ import annotations
from enum import Enum # noqa: F401
from typing import Optional, List # noqa: F401
from datetime import datetime # noqa: F401
from dataclasses import dataclass # noqa: F401

import extism # noqa: F401 # pyright: ignore


@dataclass
class BlobResourceContents(extism.Json):
# A base64-encoded string representing the binary data of the item.
blob: str

# The MIME type of this resource, if known.
mimeType: str

# The URI of this resource.
uri: str


@dataclass
class CallToolRequest(extism.Json):
method: str

params: Params


@dataclass
class CallToolResult(extism.Json):
content: List[Content]

# Whether the tool call ended in an error.
#
# If not set, this is assumed to be false (the call was successful).
isError: bool


@dataclass
class Content(extism.Json):
annotations: TextAnnotation

# The base64-encoded image data.
data: str

# The MIME type of the image. Different providers may support different image types.
mimeType: str

# The text content of the message.
text: str

type: ContentType


class ContentType(Enum):
Text = "text"
Image = "image"
Resource = "resource"


@dataclass
class ListToolsResult(extism.Json):
# The list of ToolDescription objects provided by this servlet.
tools: List[ToolDescription]


@dataclass
class Params(extism.Json):
arguments: dict

name: str


class Role(Enum):
Assistant = "assistant"
User = "user"


@dataclass
class TextAnnotation(extism.Json):
# Describes who the intended customer of this object or data is.
#
# It can include multiple entries to indicate content useful for multiple audiences (e.g., `["user", "assistant"]`).
audience: List[Role]

# Describes how important this data is for operating the server.
#
# A value of 1 means "most important," and indicates that the data is
# effectively required, while 0 means "least important," and indicates that
# the data is entirely optional.
priority: float


@dataclass
class TextResourceContents(extism.Json):
# The MIME type of this resource, if known.
mimeType: str

# The text of the item. This must only be set if the item can actually be represented as text (not binary data).
text: str

# The URI of this resource.
uri: str


@dataclass
class ToolDescription(extism.Json):
# A description of the tool
description: str

# The JSON schema describing the argument input
inputSchema: dict

# The name of the tool. It should match the plugin / binding name.
name: str
Loading
Loading