@creature-ai/sdk 0.1.14 → 0.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server/index.d.ts +36 -33
- package/dist/server/index.js +27 -28
- package/dist/server/index.js.map +1 -1
- package/package.json +1 -1
package/dist/server/index.d.ts
CHANGED
|
@@ -207,13 +207,13 @@ interface ToolContext {
|
|
|
207
207
|
*/
|
|
208
208
|
instanceId: string;
|
|
209
209
|
/**
|
|
210
|
-
* Creature App Token for identity
|
|
210
|
+
* Creature App Token for identity retrieval.
|
|
211
211
|
* ONLY present when:
|
|
212
212
|
* 1. App opted into Creature-managed auth (`auth: { creatureManaged: true }`)
|
|
213
213
|
* 2. Tool call originated from Creature host
|
|
214
214
|
*
|
|
215
|
-
* Use `
|
|
216
|
-
*
|
|
215
|
+
* Use `getIdentity(context.creatureToken)` to retrieve user identity
|
|
216
|
+
* for multi-tenant data access.
|
|
217
217
|
*
|
|
218
218
|
* @example
|
|
219
219
|
* ```typescript
|
|
@@ -221,7 +221,7 @@ interface ToolContext {
|
|
|
221
221
|
* if (!context.creatureToken) {
|
|
222
222
|
* return { error: "Authentication required" };
|
|
223
223
|
* }
|
|
224
|
-
* const identity = await
|
|
224
|
+
* const identity = await getIdentity(context.creatureToken);
|
|
225
225
|
* await db.notes.insert({
|
|
226
226
|
* user_id: identity.user.id,
|
|
227
227
|
* content,
|
|
@@ -715,7 +715,7 @@ declare function htmlLoader(htmlOrPath: string, basePath?: string): () => string
|
|
|
715
715
|
declare function wrapServer<T extends McpServer>(server: T): T;
|
|
716
716
|
|
|
717
717
|
/**
|
|
718
|
-
* User identity from a
|
|
718
|
+
* User identity from a Creature token.
|
|
719
719
|
*/
|
|
720
720
|
interface CreatureUser {
|
|
721
721
|
/** Unique, stable user identifier */
|
|
@@ -726,7 +726,7 @@ interface CreatureUser {
|
|
|
726
726
|
name?: string;
|
|
727
727
|
}
|
|
728
728
|
/**
|
|
729
|
-
* Organization context from a
|
|
729
|
+
* Organization context from a Creature token.
|
|
730
730
|
*/
|
|
731
731
|
interface CreatureOrganization {
|
|
732
732
|
/** Unique organization identifier */
|
|
@@ -737,7 +737,7 @@ interface CreatureOrganization {
|
|
|
737
737
|
slug: string;
|
|
738
738
|
}
|
|
739
739
|
/**
|
|
740
|
-
* Project context from a
|
|
740
|
+
* Project context from a Creature token.
|
|
741
741
|
*/
|
|
742
742
|
interface CreatureProject {
|
|
743
743
|
/** Unique project identifier */
|
|
@@ -746,15 +746,15 @@ interface CreatureProject {
|
|
|
746
746
|
name: string;
|
|
747
747
|
}
|
|
748
748
|
/**
|
|
749
|
-
* Session context from a
|
|
749
|
+
* Session context from a Creature token.
|
|
750
750
|
*/
|
|
751
751
|
interface CreatureSession {
|
|
752
752
|
/** Unique session identifier */
|
|
753
753
|
id: string;
|
|
754
754
|
}
|
|
755
755
|
/**
|
|
756
|
-
*
|
|
757
|
-
* Returned by
|
|
756
|
+
* Identity claims from a Creature App Token.
|
|
757
|
+
* Returned by getIdentity() on successful retrieval.
|
|
758
758
|
*/
|
|
759
759
|
interface CreatureIdentity {
|
|
760
760
|
/** User identity (always present for valid tokens) */
|
|
@@ -769,10 +769,10 @@ interface CreatureIdentity {
|
|
|
769
769
|
expiresAt: string;
|
|
770
770
|
}
|
|
771
771
|
/**
|
|
772
|
-
* Error thrown when
|
|
772
|
+
* Error thrown when identity retrieval fails.
|
|
773
773
|
*/
|
|
774
|
-
declare class
|
|
775
|
-
/** Error code from the
|
|
774
|
+
declare class CreatureIdentityError extends Error {
|
|
775
|
+
/** Error code from the identity API */
|
|
776
776
|
code: string;
|
|
777
777
|
constructor({ code, message }: {
|
|
778
778
|
code: string;
|
|
@@ -780,9 +780,9 @@ declare class CreatureTokenError extends Error {
|
|
|
780
780
|
});
|
|
781
781
|
}
|
|
782
782
|
/**
|
|
783
|
-
* Configuration for the Creature
|
|
783
|
+
* Configuration for the Creature identity API.
|
|
784
784
|
*/
|
|
785
|
-
interface
|
|
785
|
+
interface IdentityConfig {
|
|
786
786
|
/**
|
|
787
787
|
* Base URL for the Creature API.
|
|
788
788
|
* Defaults to https://api.creature.run
|
|
@@ -791,43 +791,46 @@ interface VerifyConfig {
|
|
|
791
791
|
apiUrl?: string;
|
|
792
792
|
}
|
|
793
793
|
/**
|
|
794
|
-
*
|
|
794
|
+
* Retrieves user identity from a Creature App Token.
|
|
795
795
|
*
|
|
796
|
-
* Use this in your
|
|
797
|
-
* The token is provided
|
|
796
|
+
* Use this in your MCP App tool handlers to get the authenticated user's
|
|
797
|
+
* identity. The token is provided via `context.creatureToken` when you
|
|
798
798
|
* opt into Creature-managed auth.
|
|
799
799
|
*
|
|
800
|
-
* @param
|
|
800
|
+
* @param creatureToken - The App Token from context.creatureToken
|
|
801
801
|
* @param config - Optional configuration (e.g., custom API URL)
|
|
802
|
-
* @returns The
|
|
803
|
-
* @throws {
|
|
802
|
+
* @returns The identity claims (user, organization, project, session)
|
|
803
|
+
* @throws {CreatureIdentityError} If the token is invalid, expired, or malformed
|
|
804
804
|
*
|
|
805
805
|
* @example
|
|
806
806
|
* ```typescript
|
|
807
|
-
* import {
|
|
807
|
+
* import { getIdentity } from "@creature-ai/sdk/server";
|
|
808
|
+
*
|
|
809
|
+
* app.tool("save_note", { ... }, async ({ content }, context) => {
|
|
810
|
+
* if (!context.creatureToken) {
|
|
811
|
+
* return { text: "Authentication required", isError: true };
|
|
812
|
+
* }
|
|
808
813
|
*
|
|
809
|
-
* // In your Express/Hono/etc. API handler:
|
|
810
|
-
* app.post("/api/notes", async (req, res) => {
|
|
811
814
|
* try {
|
|
812
|
-
* const identity = await
|
|
815
|
+
* const identity = await getIdentity(context.creatureToken);
|
|
813
816
|
*
|
|
814
817
|
* // Use identity to scope data access
|
|
815
|
-
*
|
|
818
|
+
* await db.notes.insert({
|
|
816
819
|
* user_id: identity.user.id,
|
|
817
820
|
* org_id: identity.organization?.id,
|
|
821
|
+
* content,
|
|
818
822
|
* });
|
|
819
823
|
*
|
|
820
|
-
*
|
|
824
|
+
* return { text: "Note saved" };
|
|
821
825
|
* } catch (err) {
|
|
822
|
-
* if (err instanceof
|
|
823
|
-
*
|
|
824
|
-
* } else {
|
|
825
|
-
* res.status(500).json({ error: "internal_error" });
|
|
826
|
+
* if (err instanceof CreatureIdentityError) {
|
|
827
|
+
* return { text: err.message, isError: true };
|
|
826
828
|
* }
|
|
829
|
+
* throw err;
|
|
827
830
|
* }
|
|
828
831
|
* });
|
|
829
832
|
* ```
|
|
830
833
|
*/
|
|
831
|
-
declare const
|
|
834
|
+
declare const getIdentity: (creatureToken: string | undefined | null, config?: IdentityConfig) => Promise<CreatureIdentity>;
|
|
832
835
|
|
|
833
|
-
export { type AdapterOptions, App, type AppConfig, type AwsLambdaOptions, type CreatureIdentity, type CreatureOrganization, type CreatureProject, type CreatureSession,
|
|
836
|
+
export { type AdapterOptions, App, type AppConfig, type AwsLambdaOptions, type CreatureIdentity, CreatureIdentityError, type CreatureOrganization, type CreatureProject, type CreatureSession, type CreatureUser, type DisplayMode, type IconConfig, type InstanceDestroyContext, MIME_TYPES, type RealtimeAdapter, type ResourceConfig, type StateAdapter, type ToolConfig, type ToolContext, type ToolHandler, type ToolResult, type ToolVisibility, type TransportSessionInfo, type TransportType, type VercelMcpOptions, type WebSocketConnection, createApp, getIdentity, htmlLoader, isHtmlContent, loadHtml, svgToDataUri, wrapServer };
|
package/dist/server/index.js
CHANGED
|
@@ -14892,12 +14892,12 @@ function wrapServer(server) {
|
|
|
14892
14892
|
}
|
|
14893
14893
|
|
|
14894
14894
|
// src/server/auth.ts
|
|
14895
|
-
var
|
|
14896
|
-
/** Error code from the
|
|
14895
|
+
var CreatureIdentityError = class extends Error {
|
|
14896
|
+
/** Error code from the identity API */
|
|
14897
14897
|
code;
|
|
14898
14898
|
constructor({ code, message }) {
|
|
14899
14899
|
super(message);
|
|
14900
|
-
this.name = "
|
|
14900
|
+
this.name = "CreatureIdentityError";
|
|
14901
14901
|
this.code = code;
|
|
14902
14902
|
}
|
|
14903
14903
|
};
|
|
@@ -14909,33 +14909,32 @@ var extractToken = (tokenOrHeader) => {
|
|
|
14909
14909
|
}
|
|
14910
14910
|
return trimmed;
|
|
14911
14911
|
};
|
|
14912
|
-
var
|
|
14913
|
-
if (!
|
|
14914
|
-
throw new
|
|
14912
|
+
var getIdentity = async (creatureToken, config) => {
|
|
14913
|
+
if (!creatureToken) {
|
|
14914
|
+
throw new CreatureIdentityError({
|
|
14915
14915
|
code: "missing_token",
|
|
14916
|
-
message: "No token provided.
|
|
14916
|
+
message: "No token provided. Pass context.creatureToken to getIdentity()."
|
|
14917
14917
|
});
|
|
14918
14918
|
}
|
|
14919
|
-
const token = extractToken(
|
|
14919
|
+
const token = extractToken(creatureToken);
|
|
14920
14920
|
if (!token) {
|
|
14921
|
-
throw new
|
|
14921
|
+
throw new CreatureIdentityError({
|
|
14922
14922
|
code: "missing_token",
|
|
14923
|
-
message: "Empty token after extraction
|
|
14923
|
+
message: "Empty token after extraction."
|
|
14924
14924
|
});
|
|
14925
14925
|
}
|
|
14926
14926
|
const apiUrl = config?.apiUrl || DEFAULT_API_URL;
|
|
14927
|
-
const
|
|
14927
|
+
const identityUrl = `${apiUrl}/apps/v1/identity`;
|
|
14928
14928
|
let response;
|
|
14929
14929
|
try {
|
|
14930
|
-
response = await fetch(
|
|
14931
|
-
method: "
|
|
14930
|
+
response = await fetch(identityUrl, {
|
|
14931
|
+
method: "GET",
|
|
14932
14932
|
headers: {
|
|
14933
|
-
Authorization: `Bearer ${token}
|
|
14934
|
-
"Content-Type": "application/json"
|
|
14933
|
+
Authorization: `Bearer ${token}`
|
|
14935
14934
|
}
|
|
14936
14935
|
});
|
|
14937
14936
|
} catch (err) {
|
|
14938
|
-
throw new
|
|
14937
|
+
throw new CreatureIdentityError({
|
|
14939
14938
|
code: "network_error",
|
|
14940
14939
|
message: `Failed to reach Creature API: ${err instanceof Error ? err.message : "Unknown error"}`
|
|
14941
14940
|
});
|
|
@@ -14946,44 +14945,44 @@ var verifyCreatureToken = async (tokenOrHeader, config) => {
|
|
|
14946
14945
|
errorData = await response.json();
|
|
14947
14946
|
} catch {
|
|
14948
14947
|
}
|
|
14949
|
-
throw new
|
|
14950
|
-
code: errorData.error || "
|
|
14951
|
-
message: errorData.error_description || `
|
|
14948
|
+
throw new CreatureIdentityError({
|
|
14949
|
+
code: errorData.error || "identity_error",
|
|
14950
|
+
message: errorData.error_description || `Identity request failed (HTTP ${response.status})`
|
|
14952
14951
|
});
|
|
14953
14952
|
}
|
|
14954
14953
|
let data;
|
|
14955
14954
|
try {
|
|
14956
14955
|
data = await response.json();
|
|
14957
14956
|
} catch {
|
|
14958
|
-
throw new
|
|
14957
|
+
throw new CreatureIdentityError({
|
|
14959
14958
|
code: "invalid_response",
|
|
14960
14959
|
message: "Invalid JSON response from Creature API"
|
|
14961
14960
|
});
|
|
14962
14961
|
}
|
|
14963
|
-
if (!data.
|
|
14964
|
-
throw new
|
|
14962
|
+
if (!data.user) {
|
|
14963
|
+
throw new CreatureIdentityError({
|
|
14965
14964
|
code: "invalid_token",
|
|
14966
14965
|
message: "Token is not valid"
|
|
14967
14966
|
});
|
|
14968
14967
|
}
|
|
14969
14968
|
return {
|
|
14970
|
-
user: data.
|
|
14971
|
-
organization: data.
|
|
14972
|
-
project: data.
|
|
14973
|
-
session: data.
|
|
14969
|
+
user: data.user,
|
|
14970
|
+
organization: data.organization,
|
|
14971
|
+
project: data.project,
|
|
14972
|
+
session: data.session,
|
|
14974
14973
|
expiresAt: data.expires_at
|
|
14975
14974
|
};
|
|
14976
14975
|
};
|
|
14977
14976
|
export {
|
|
14978
14977
|
App,
|
|
14979
|
-
|
|
14978
|
+
CreatureIdentityError,
|
|
14980
14979
|
MIME_TYPES,
|
|
14981
14980
|
createApp,
|
|
14981
|
+
getIdentity,
|
|
14982
14982
|
htmlLoader,
|
|
14983
14983
|
isHtmlContent,
|
|
14984
14984
|
loadHtml,
|
|
14985
14985
|
svgToDataUri,
|
|
14986
|
-
verifyCreatureToken,
|
|
14987
14986
|
wrapServer
|
|
14988
14987
|
};
|
|
14989
14988
|
//# sourceMappingURL=index.js.map
|