-
Notifications
You must be signed in to change notification settings - Fork 1
Various functions #5
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e883f68
functions testing harness with simple-bash. hello-world, and runtime-…
Jovonni 2b544bf
various function prototypes, working on common function contract
Jovonni 014639a
added cicd
Jovonni 9ef3514
updated various functions, with global runner
Jovonni 8672516
twilio, and using new envvars
Jovonni bc73680
added new env vars to the test-runner.ts, can pass all (for now, TODO)
Jovonni 3ea40a7
dotenv dep for .env
Jovonni 4268e7c
updated several functions
Jovonni 880a679
makefile changes and scripts and lock
Jovonni f4a6de2
chore: ignore opencode binary artifact
Jovonni 60356b5
warn on gql fallback
Jovonni 6c335aa
added matrix
Jovonni d976edd
calvin api a envvar
Jovonni 8a1c52e
Merge pull request #6 from constructive-io/dev/testing-strategy
Jovonni cc82394
feat: add pgpm-dump function and standardize k8s test runner to v4
Jovonni 38b3eaa
fix(ci): make kind binary path resolution dynamic in Makefile
Jovonni 9a8ed16
fix(ci): parameterize KIND_CLUSTER_NAME to support CI 'local' cluster
Jovonni 5128f2f
fix(ci): remove unconfigured submodule _calvincode_build from git index
Jovonni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| node_modules | ||
| packages | ||
| dist | ||
| .git | ||
| .env |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| # Python runtime for LLM API inference (OpenAI & Claude) | ||
| # This module makes API calls to OpenAI and Anthropic for LLM inference | ||
| # For the full fat container with Ollama & local models, see Dockerfile.ollama | ||
| # Based on: /Users/0xj0/Documents/projects/LQL/CONSTRUCTIVE/agentic-foundation | ||
|
|
||
| ##################### heres what is had inside of (/Users/0xj0/Documents/projects/LQL/CONSTRUCTIVE/agentic-foundation) -- GO VERIFY YOURSELF | ||
|
|
||
| # Builder Stage | ||
| FROM rust:latest as builder | ||
| WORKDIR /app | ||
| COPY . . | ||
| # Build agent_core | ||
| RUN cargo build --release --bin agent_core | ||
|
|
||
| # Runtime Stage - "Fat Container" | ||
| FROM ubuntu:22.04 | ||
| WORKDIR /app | ||
|
|
||
| # Set non-interactive install | ||
| ENV DEBIAN_FRONTEND=noninteractive | ||
|
|
||
| # 1. Install Basic Tools & Runtimes (Python, Node, System Utils) | ||
| RUN apt-get update && apt-get install -y \ | ||
| curl wget git build-essential \ | ||
| python3 python3-pip python3-venv \ | ||
| nodejs npm \ | ||
| postgresql-14 postgresql-client-14 \ | ||
| sudo \ | ||
| libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libxkbcommon0 \ | ||
| libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libasound2 \ | ||
| chromium-browser \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # 2. Install Rust in Runtime (for the agent to use `cargo`) | ||
| RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | ||
| ENV PATH="/root/.cargo/bin:${PATH}" | ||
|
|
||
| # 3. Install PostGraphile | ||
| # 3. Install PostGraphile | ||
| RUN npm install -g pnpm && pnpm add -g postgraphile @graphile-contrib/pg-simplify-inflector | ||
|
|
||
| # 4. Install Ollama & Bake Models | ||
| # We install Ollama, then start it in the background to pull models into the image layers. | ||
| RUN curl -fsSL https://ollama.com/install.sh | sh | ||
|
|
||
| # Pre-pull Models (Using available equivalents for the '2025' spec models) | ||
| # GPT-OSS -> llama3.2 (Small, open, robust) | ||
| # Qwen3-VL -> llava (Vision model standard in Ollama) | ||
| # Devstral -> qwen2.5-coder (Excellent coding model) | ||
| # Nemotron -> mistral (Strong reasoning) | ||
| RUN nohup bash -c "ollama serve" & \ | ||
| sleep 10 && \ | ||
| ollama pull llama3.2 && \ | ||
| ollama pull llava && \ | ||
| ollama pull qwen2.5-coder && \ | ||
| ollama pull mistral && \ | ||
| pkill ollama | ||
|
|
||
| # 5. Setup Data & Permissions | ||
| RUN mkdir -p /var/lib/postgresql/data && chown -R postgres:postgres /var/lib/postgresql/data | ||
|
|
||
| # 6. Copy Binaries & Scripts | ||
| COPY --from=builder /app/target/release/agent_core /app/agent_core | ||
| COPY scripts/entrypoint.sh /app/entrypoint.sh | ||
| RUN chmod +x /app/entrypoint.sh | ||
|
|
||
| # 7. Config | ||
| ENV DATABASE_URL=postgres://agent:agent@localhost:5432/agentic | ||
| ENV OLLAMA_HOST=0.0.0.0:11434 | ||
|
|
||
| EXPOSE 3000 5432 11434 5000 | ||
|
|
||
| ENTRYPOINT ["/app/entrypoint.sh"] | ||
| CMD ["./agent_core"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| FROM node:22-alpine | ||
|
|
||
| WORKDIR /usr/src/app | ||
|
|
||
| COPY package.json ./ | ||
|
|
||
| RUN npm install -g pnpm@10.12.2 && pnpm install --prod | ||
|
|
||
| COPY dist ./dist | ||
| COPY runner.js ./runner.js | ||
|
|
||
| ENV NODE_ENV=production | ||
| ENV PORT=8080 | ||
|
|
||
| USER node | ||
|
|
||
| CMD ["node", "runner.js", "dist/index.js"] | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| FROM node:20-alpine | ||
|
|
||
| # Install Postgres Client and Build Tools | ||
| RUN apk add --no-cache postgresql-client bash make g++ python3 kubectl | ||
|
|
||
| COPY . /app | ||
| WORKDIR /app | ||
|
|
||
| # Ensure clean slate | ||
| RUN rm -rf node_modules | ||
|
|
||
| # 3. Install Dependencies from NPM | ||
| RUN npm install -g pnpm@9 && pnpm install --no-frozen-lockfile | ||
|
|
||
| # 4. Build | ||
| # 5. Install PGPM from NPM | ||
| RUN pnpm add -g pgpm | ||
|
|
||
| # Run as postgres user to avoid 'role root does not exist' in pgsql-test | ||
| # handle existing user/group if created by apk | ||
| RUN (getent group postgres || addgroup -S postgres) && (getent passwd postgres || adduser -S postgres -G postgres) | ||
| RUN chown -R postgres:postgres /app | ||
| USER postgres | ||
| ENV USER=postgres | ||
| ENV PGUSER=postgres | ||
|
|
||
| # 6. Setup Entrypoint (Inlined for Minimalism) | ||
| ENV NODE_ENV=test | ||
| CMD ["/bin/bash", "-c", "set -e; \ | ||
| echo \"Waiting for Postgres at $PGHOST:$PGPORT...\"; \ | ||
| until pg_isready -h \"$PGHOST\" -p \"$PGPORT\" -U \"$PGUSER\"; do echo \"Waiting...\"; sleep 2; done; \ | ||
| echo \"Deploying Schema...\"; \ | ||
| pgpm deploy --package pgpm-database-jobs --database template1 --yes 2>/dev/null || echo \"Deploy continued...\"; \ | ||
| unset PGDATABASE; \ | ||
| pnpm test"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| const path = require('path'); | ||
| const fs = require('fs'); | ||
|
|
||
| const run = async () => { | ||
| // 1. Resolve Dependencies from CWD (User's Function Context) | ||
| // This logic ensures we find express/graphql-request in the function's node_modules, | ||
| // regardless of where runner.js is located (Local Dev vs Docker). | ||
| const resolveDep = (name) => { | ||
| try { | ||
| return require(require.resolve(name, { paths: [process.cwd()] })); | ||
| } catch (e) { | ||
| console.error(`[runner] Failed to resolve dependency '${name}' from ${process.cwd()}`); | ||
| console.error(e.message); | ||
| process.exit(1); | ||
| } | ||
| }; | ||
|
|
||
| const express = resolveDep('express'); | ||
| const bodyParser = resolveDep('body-parser'); | ||
| const { GraphQLClient } = resolveDep('graphql-request'); | ||
| const http = require('http'); | ||
| const https = require('https'); | ||
| const { URL } = require('url'); | ||
|
|
||
| // 2. Resolve User Handler | ||
| const relativePath = process.argv[2] || 'dist/index.js'; | ||
| const absolutePath = path.resolve(process.cwd(), relativePath); | ||
|
|
||
| let userModule; | ||
| try { | ||
| userModule = require(absolutePath); | ||
| } catch (e) { | ||
| console.error(`[runner] Failed to load function at ${absolutePath}`); | ||
| console.error(e.message); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const handler = userModule.default || userModule; | ||
|
|
||
| if (typeof handler !== 'function') { | ||
| console.error(`[runner] Export at ${absolutePath} is not a function.`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| // 3. Setup App & Helper Functions (Ported from knative-job-fn/src/index.ts) | ||
| // We implement a simplified version of the logic to avoid needing deep imports. | ||
| // However, since we are replacing the shim which used `express` directly usually, | ||
| // or `knative-job-fn` library... | ||
| // Correct approach: The shim used `app` from `@constructive-io/knative-job-fn`. | ||
| // We should try to use THAT if available, to preserve exact behavior (headers, logging). | ||
|
|
||
| let app; | ||
| try { | ||
| // Try to load the standard wrapper if present | ||
| const jobFn = resolveDep('@constructive-io/knative-job-fn'); | ||
| // The library usually exports { default: { post: ..., listen: ... } } or similar? | ||
| // Let's check how functions imported it: "import app from '@constructive-io/knative-job-fn';" | ||
| // It exports 'default'. | ||
| const lib = jobFn.default || jobFn; | ||
|
|
||
| // The library exposes an 'app' like object but 'listen' is the main entry. | ||
| // But we want to inject our handler into a route. | ||
| // Library usage in shim: `app.post('/', ...)` | ||
| // Library implementation: `app` IS express() basically, but wrapped. | ||
|
|
||
| // Actually the library exports an object: { post: ..., listen: ... } | ||
| // We can use it directly. | ||
| app = lib; | ||
| } catch (e) { | ||
| // Fallback to raw express if wrapper missing (unlikely given package.json) | ||
| console.warn('[runner] @constructive-io/knative-job-fn not found, falling back to raw express'); | ||
| app = express(); | ||
| app.use(bodyParser.json()); | ||
| } | ||
|
|
||
| // 4. Setup GraphQL Client | ||
| const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT || 'http://constructive-server:3000/graphql'); | ||
|
|
||
| // 5. Setup Route | ||
| app.post('/', async (req, res) => { | ||
| try { | ||
| const result = await handler(req.body, { client, headers: req.headers }); | ||
|
|
||
| // Standard Shim Error Handling Heuristics | ||
| if (result && result.error) { | ||
| // Heuristics for 400 vs 500 | ||
| if (['Missing prompt', 'Unsupported provider', 'Missing "query" in payload', | ||
| 'Missing repoName or githubToken', 'Missing X-Database-Id header or DEFAULT_DATABASE_ID', | ||
| 'Missing required field', "Either 'html' or 'text' must be provided", | ||
| "Missing address, message, or signature"].some(s => result.error.includes(s) || s === result.error)) { | ||
| return res.status(400).json(result); | ||
| } | ||
| return res.status(500).json(result); | ||
| } | ||
|
|
||
| res.status(200).json(result); | ||
| } catch (e) { | ||
| console.error(e); | ||
| res.status(500).json({ error: e.message }); | ||
| } | ||
| }); | ||
|
|
||
| // 6. Start Server | ||
| const port = Number(process.env.PORT ?? 8080); | ||
| app.listen(port, () => { | ||
| console.log(`[runner] Function '${relativePath}' listening on port ${port}`); | ||
| }); | ||
| }; | ||
|
|
||
| run().catch(e => { | ||
| console.error('[runner] Fatal:', e); | ||
| process.exit(1); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # TODO: create a standard python function here that can run pytorch for me |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # Multi-stage build for Rust functions | ||
| FROM rust:1.83-alpine AS builder | ||
|
|
||
| WORKDIR /build | ||
|
|
||
| # Install build dependencies | ||
| RUN apk add --no-cache musl-dev | ||
|
|
||
| # Copy dependency manifests first (for layer caching) | ||
| COPY Cargo.toml Cargo.lock ./ | ||
|
|
||
| # Create dummy src to build dependencies | ||
| RUN mkdir src && echo "fn main() {}" > src/main.rs | ||
| RUN cargo build --release --target x86_64-unknown-linux-musl | ||
| RUN rm -rf src | ||
|
|
||
| # Copy actual source code | ||
| COPY src ./src | ||
|
|
||
| # Build the actual binary | ||
| RUN touch src/main.rs && cargo build --release --target x86_64-unknown-linux-musl | ||
|
|
||
| # Runtime stage - minimal Alpine image | ||
| FROM alpine:3.19 | ||
|
|
||
| WORKDIR /usr/src/app | ||
|
|
||
| # Copy the compiled binary from builder | ||
| COPY --from=builder /build/target/x86_64-unknown-linux-musl/release/app ./app | ||
|
|
||
| # Create non-root user | ||
| RUN addgroup -g 1000 appuser && \ | ||
| adduser -D -u 1000 -G appuser appuser && \ | ||
| chown -R appuser:appuser /usr/src/app | ||
|
|
||
| ENV PORT=8080 | ||
|
|
||
| USER appuser | ||
|
|
||
| EXPOSE 8080 | ||
|
|
||
| CMD ["./app"] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hardcoded fallback URL 'http://constructive-server:3000/graphql' may not be appropriate for all environments. Consider making this required or using a more environment-agnostic default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should prob stay the domain via kns