Skip to content
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
Binary file modified examples/cloudflare-hono/bun.lockb
Binary file not shown.
6 changes: 6 additions & 0 deletions examples/cloudflare-hono/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ const app = new Hono()
const result = await Resource.MyBucket.get(first.key);
c.header("content-type", result.httpMetadata.contentType);
return c.body(result.body);
})
.get("/ai", async (c) => {
const result = await Resource.ai.run("@cf/meta/llama-3-8b-instruct", {
prompt: "What is the origin of the phrase 'Hello, World'",
});
return c.json(result.response);
});

export default app;
4 changes: 2 additions & 2 deletions examples/cloudflare-hono/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"author": "",
"license": "ISC",
"dependencies": {
"hono": "^4.2.3",
"hono": "^4.11.4",
"sst": "latest"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240405.0"
"@cloudflare/workers-types": "^4.20260114.0"
}
}
2 changes: 2 additions & 0 deletions examples/cloudflare-hono/sst-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* tslint:disable */
/* eslint-disable */
/* deno-fmt-ignore-file */
/* biome-ignore-all lint: auto-generated */

import "sst"
declare module "sst" {
Expand All @@ -14,6 +15,7 @@ declare module "sst" {
export interface Resource {
"Hono": cloudflare.Service
"MyBucket": cloudflare.R2Bucket
"ai": cloudflare.Ai
}
}

Expand Down
5 changes: 3 additions & 2 deletions examples/cloudflare-hono/sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
export default $config({
app(input) {
return {
name: "cloudflare-hono",
name: "cloudflare-hono-example",
home: "cloudflare",
removal: input?.stage === "production" ? "retain" : "remove",
};
},
async run() {
const ai = new sst.cloudflare.Ai("ai");
const bucket = new sst.cloudflare.Bucket("MyBucket");
const hono = new sst.cloudflare.Worker("Hono", {
url: true,
link: [bucket],
link: [bucket, ai],
handler: "index.ts",
});

Expand Down
1 change: 1 addition & 0 deletions pkg/types/typescript/typescript.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
)

var mapping = map[string]string{
"aiBinding": "Ai",
"r2BucketBindings": "R2Bucket",
"d1DatabaseBindings": "D1Database",
"kvNamespaceBindings": "KVNamespace",
Expand Down
37 changes: 37 additions & 0 deletions platform/src/components/cloudflare/ai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ComponentResourceOptions } from "@pulumi/pulumi";
import { Component, Transform } from "../component";
import { Link } from "../link";
import { binding } from "./binding";

export interface AiArgs {
transform?: {
binding?: Transform<{ name: string }>;
};
}

export class Ai extends Component implements Link.Linkable {
constructor(name: string, args?: AiArgs, opts?: ComponentResourceOptions) {
super(__pulumiType, name, args, opts);
this.name = name;
}

getSSTLink() {
return {
properties: {},
include: [
binding({
type: "aiBinding",
properties: {
name: this.name,
},
}),
],
};
}

name: string;
}

const __pulumiType = "sst:cloudflare:Ai";
// @ts-expect-error
Ai.__pulumiType = __pulumiType;
8 changes: 8 additions & 0 deletions platform/src/components/cloudflare/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@

import { Input } from "../input";

export interface AiBinding {
type: "aiBinding";
properties: {
name: Input<string>;
};
}

export interface KvBinding {
type: "kvNamespaceBindings";
properties: {
Expand Down Expand Up @@ -63,6 +70,7 @@ export interface D1DatabaseBinding {
}

export type Binding =
| AiBinding
| KvBinding
| SecretTextBinding
| ServiceBinding
Expand Down
1 change: 1 addition & 0 deletions platform/src/components/cloudflare/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export * from "./account-id";
export * from "./auth";
export * from "./queue";
export * from "./cron";
export * from "./ai";
export { binding } from "./binding.js";

/**
Expand Down
1 change: 1 addition & 0 deletions platform/src/components/cloudflare/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ export class Worker extends Component implements Link.Linkable {
b
? {
type: {
aiBinding: "ai",
plainTextBindings: "plain_text",
secretTextBindings: "secret_text",
queueBindings: "queue",
Expand Down