Skip to content

Commit

Permalink
Merge branch 'main' into project_secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
xjacka authored Jan 31, 2025
2 parents 5e9a3b5 + 6962b9f commit ab3a382
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 38 deletions.
3 changes: 0 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
node_modules

# Package DB is created during docker build
static/package-db.sqlite
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## [0.0.23](https://github.com/i-am-bee/bee-api/compare/v0.0.22...v0.0.23) (2025-01-29)

### Features

* chat streaming and embeddings support ([#156](https://github.com/i-am-bee/bee-api/issues/156)) ([2a8f729](https://github.com/i-am-bee/bee-api/commit/2a8f7297dd6ce959cbb77e1fc731d62b4257d060))
* **tools:** update OpenAPI tools ([#157](https://github.com/i-am-bee/bee-api/issues/157)) ([1feb69e](https://github.com/i-am-bee/bee-api/commit/1feb69e42ab544b5008a1ff517cfc47a0f5c2e6a))

### Bug Fixes

* **metadata:** add nulability to schema for openai compatibility ([#158](https://github.com/i-am-bee/bee-api/issues/158)) ([e7b8eab](https://github.com/i-am-bee/bee-api/commit/e7b8eab2e1d7438bf30d8729724deea110995187))
* **tool:** fix update api tool api key ([#161](https://github.com/i-am-bee/bee-api/issues/161)) ([9d93ba1](https://github.com/i-am-bee/bee-api/commit/9d93ba1bf5fcb1b3e6a4fc78ea63ca0bb86f45cc))
* **tools:** encrypt updated api keys ([#160](https://github.com/i-am-bee/bee-api/issues/160)) ([1d561d6](https://github.com/i-am-bee/bee-api/commit/1d561d69477f03ba378b936ea29fcdda74e252f6))

## [0.0.22](https://github.com/i-am-bee/bee-api/compare/v0.0.21...v0.0.22) (2025-01-15)

### Features
Expand Down
23 changes: 4 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
ARG ALPINE_VERSION="3.20"
ARG GO_VERSION="1.23"
ARG UPM_VERSION="2.5.2"

FROM docker.io/golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS build-upm
ARG UPM_VERSION
WORKDIR /workdir
RUN apk add --no-cache git make gcc g++ musl-dev sqlite && \
git clone --depth 1 --branch "v${UPM_VERSION}" https://github.com/replit/upm.git && \
cd ./upm && \
export CGO_CFLAGS="-D_LARGEFILE64_SOURCE" && \
make internal/backends/python/pypi_map.sqlite

FROM node:22.2-alpine AS base

# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
Expand Down Expand Up @@ -44,20 +31,18 @@ RUN corepack enable pnpm && pnpm run build;
# Production image, copy all the files and run next
FROM base AS runner

ENV NODE_ENV production
ENV NODE_ENV=production

# https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md
RUN deluser --remove-home node \
&& addgroup -S node -g 1001 \
&& adduser -S -G node -u 1001 node

# UPM
COPY --from=build-upm /workdir/upm/internal/backends/python/pypi_map.sqlite ./static/package-db.sqlite

COPY --chown=node:node --from=deps ${APP_DIR}/package.json ./
COPY --chown=node:node --from=deps ${APP_DIR}/node_modules ./node_modules
COPY --chown=node:node --from=builder ${APP_DIR}/tsconfig.json ./
COPY --chown=node:node --from=builder ${APP_DIR}/dist ./dist
COPY --chown=node:node --from=builder ${APP_DIR}/static/package-db.sqlite ./static/

RUN chown -R 1001:0 ${APP_DIR} &&\
chmod -R g+w ${APP_DIR}
Expand All @@ -66,7 +51,7 @@ USER node

EXPOSE 4000

ENV PORT 4000
ENV BEE_FRAMEWORK_INSTRUMENTATION_ENABLED true
ENV PORT=4000
ENV BEE_FRAMEWORK_INSTRUMENTATION_ENABLED=true

CMD [ "node", "--enable-source-maps", "--experimental-loader=@opentelemetry/instrumentation/hook.mjs", "--import", "./dist/opentelemetry.js", "./dist/server.js" ]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bee-api",
"version": "0.0.22",
"version": "0.0.23",
"license": "Apache-2.0",
"author": "IBM Corp.",
"type": "module",
Expand Down
4 changes: 2 additions & 2 deletions src/tools/dtos/tool-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export const toolUpdateBodySchema = {
},
{
additionalProperties: false,
required: ['open_api_schema'],
properties: {
name: {
type: 'string'
Expand All @@ -56,7 +55,8 @@ export const toolUpdateBodySchema = {
},
api_key: {
type: 'string',
nullable: true
nullable: true,
minLength: 1
},
metadata: metadataSchema,
user_description: { type: 'string' }
Expand Down
41 changes: 28 additions & 13 deletions src/tools/tools.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { Loaded, ref } from '@mikro-orm/core';
import { Loaded, ref, UniqueConstraintViolationException } from '@mikro-orm/core';
import { CustomTool, CustomToolCreateError } from 'bee-agent-framework/tools/custom';
import dayjs from 'dayjs';
import mime from 'mime/lite';
Expand Down Expand Up @@ -716,31 +716,35 @@ async function createCodeInterpreterTool(
}
}

async function createOpenApiTool(
body: Extract<ToolCreateBody, { open_api_schema: string }>
): Promise<ToolCreateResponse> {
const schema = parse(body.open_api_schema);

if (!schema.info.title && !body.name) {
function validateOpenApiSchema(schema: any, name?: string) {
if (!schema.info.title && !name) {
throw new APIError({
message: 'Body name or OpenAPI info.name is requred.',
message: 'Body name or OpenAPI info.name is required.',
code: APIErrorCode.INVALID_INPUT
});
}

if (!schema.info.description) {
throw new APIError({
message: 'OpenAPI info.description is requred.',
message: 'OpenAPI info.description is required.',
code: APIErrorCode.INVALID_INPUT
});
}

if (!schema.servers || schema.servers.length === 0 || !schema.servers[0].url) {
throw new APIError({
message: 'OpenAPI servers is requred.',
message: 'OpenAPI servers is required.',
code: APIErrorCode.INVALID_INPUT
});
}
}

async function createOpenApiTool(
body: Extract<ToolCreateBody, { open_api_schema: string }>
): Promise<ToolCreateResponse> {
const schema = parse(body.open_api_schema);

validateOpenApiSchema(schema, body.name);

const tool = new ApiTool({
openApiSchema: body.open_api_schema,
Expand All @@ -751,7 +755,17 @@ async function createOpenApiTool(
userDescription: body.user_description
});

await ORM.em.persistAndFlush(tool);
try {
await ORM.em.persistAndFlush(tool);
} catch (e) {
if (e instanceof UniqueConstraintViolationException)
throw new APIError({
message: 'Tool name must be unique. Change the title in the openapi schema.',
code: APIErrorCode.INVALID_INPUT
});

throw e;
}

return toDto(tool);
}
Expand Down Expand Up @@ -833,18 +847,19 @@ export async function updateTool({
}
}

if ('open_api_schema' in body) {
if ('open_api_schema' in body && body.open_api_schema) {
if (!('openApiSchema' in tool)) {
throw new APIError({
message: 'Can not change tool executor',
code: APIErrorCode.INVALID_INPUT
});
}
validateOpenApiSchema(parse(body.open_api_schema), tool.name);
tool.openApiSchema = getUpdatedValue(body.open_api_schema, tool.openApiSchema);
}

if ('api_key' in body) {
if (!('apiKey' in tool)) {
if (!('openApiSchema' in tool)) {
throw new APIError({
message: 'Can not change tool executor',
code: APIErrorCode.INVALID_INPUT
Expand Down

0 comments on commit ab3a382

Please sign in to comment.